Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apps/api/src/controllers/v0/admin/autumn-health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { Request, Response } from "express";
import { randomUUID } from "crypto";
import { logger } from "../../../lib/logger";
import { autumnClient } from "../../../services/autumn/client";

const CREDITS_FEATURE_ID = "CREDITS";
const TEAM_FEATURE_ID = "TEAM";
import {
CREDITS_FEATURE_ID,
TEAM_FEATURE_ID,
} from "../../../services/autumn/autumn.service";

type StepStatus = "healthy" | "unhealthy" | "skipped";

Expand Down
4 changes: 1 addition & 3 deletions apps/api/src/controllers/v1/token-usage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Response } from "express";
import { ErrorResponse, RequestWithAuth } from "./types";
import { getTeamBalance } from "../../services/autumn/usage";

const TOKENS_PER_CREDIT = 15;
import { getTeamBalance, TOKENS_PER_CREDIT } from "../../services/autumn/usage";

interface TokenUsageResponse {
success: true;
Expand Down
4 changes: 1 addition & 3 deletions apps/api/src/controllers/v2/token-usage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Response } from "express";
import { ErrorResponse, RequestWithAuth } from "./types";
import { getTeamBalance } from "../../services/autumn/usage";

const TOKENS_PER_CREDIT = 15;
import { getTeamBalance, TOKENS_PER_CREDIT } from "../../services/autumn/usage";

interface TokenUsageResponse {
success: true;
Expand Down
17 changes: 12 additions & 5 deletions apps/api/src/lib/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ export type ExchangeScrapeMetadata = {
integrationId?: string;
};

export type ExchangeTerms = {
type ExchangeTerms = {
key: string;
version: string;
};

export type ExchangeProvider = {
type ExchangeProvider = {
id: string;
creditsCost: number;
terms?: ExchangeTerms;
Expand Down Expand Up @@ -227,7 +227,10 @@ async function getExchangeProviders(): Promise<ExchangeProvider[] | null> {
return providersRequest;
}

function providerMatchesUrl(provider: ExchangeProvider, inputUrl: string): boolean {
function providerMatchesUrl(
provider: ExchangeProvider,
inputUrl: string,
): boolean {
let parsed: URL;
try {
parsed = new URL(inputUrl);
Expand Down Expand Up @@ -265,7 +268,9 @@ export async function resolveExchangeProvider(
return null;
}

return providers.find(provider => providerMatchesUrl(provider, inputUrl)) ?? null;
return (
providers.find(provider => providerMatchesUrl(provider, inputUrl)) ?? null
);
}

export function getExchangeRequestLogContext(inputUrl: string):
Expand Down Expand Up @@ -365,7 +370,9 @@ function getProviderAccessDecision(
const entry = typeof access === "object" && access !== null ? access : null;

if (provider.terms === undefined) {
return entry !== null && entry.status !== "enabled" ? "not_enabled" : "allowed";
return entry !== null && entry.status !== "enabled"
? "not_enabled"
: "allowed";
}

if (entry === null) {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/services/autumn/autumn.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {
TrackParams,
} from "./types";

const TEAM_FEATURE_ID = "TEAM";
export const TEAM_FEATURE_ID = "TEAM";
export const CREDITS_FEATURE_ID = "CREDITS";
export const SEARCH_CREDITS_FEATURE_ID = "SEARCH_CREDITS";

Expand Down
5 changes: 1 addition & 4 deletions apps/api/src/services/autumn/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ import { Autumn } from "autumn-js";
import { config } from "../../config";
import { logger } from "../../lib/logger";

let missingKeyWarned = false;

if (!config.AUTUMN_SECRET_KEY && !missingKeyWarned) {
if (!config.AUTUMN_SECRET_KEY) {
logger.warn(
"AUTUMN_SECRET_KEY is not set - add AUTUMN_SECRET_KEY to enable Autumn",
);
missingKeyWarned = true;
}

export const autumnClient = config.AUTUMN_SECRET_KEY
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/services/autumn/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { eq, inArray } from "drizzle-orm";
import { dbRr } from "../../db/connection";
import * as schema from "../../db/schema";
import { autumnClient } from "./client";
import { CREDITS_FEATURE_ID } from "./autumn.service";

const CREDITS_FEATURE_ID = "CREDITS";
const TOKENS_PER_CREDIT = 15;
export const TOKENS_PER_CREDIT = 15;
const HISTORICAL_RANGE = "90d";
const HISTORICAL_BIN_SIZE = "day";

Expand Down
Loading