🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix: fix rate limits for orgs with stripe details (#3164)
Max Deichmann6045324d2bbf
diff --git a/packages/shared/src/interfaces/cloudConfigSchema.ts b/packages/shared/src/interfaces/cloudConfigSchema.tsindex 1159b7d9f8..77742913b9 100644--- a/packages/shared/src/interfaces/cloudConfigSchema.ts+++ b/packages/shared/src/interfaces/cloudConfigSchema.ts@@ -16,7 +16,7 @@ export const CloudConfigSchema = z.object({.optional(),// custom rate limits for an organization- rateLimitOverrides: CloudConfigRateLimit.nullable(),+ rateLimitOverrides: CloudConfigRateLimit.optional(),});export type CloudConfigSchema = z.infer<typeof CloudConfigSchema>;diff --git a/web/src/__tests__/api-auth.servertest.ts b/web/src/__tests__/api-auth.servertest.tsindex 6c75863477..4fbc46f3d9 100644--- a/web/src/__tests__/api-auth.servertest.ts+++ b/web/src/__tests__/api-auth.servertest.ts@@ -66,6 +66,118 @@ describe("Authenticate API calls", () => {expect(auth2.validKey).toBe(true);});+ it("should create new api key with stripe data and succeed with new key", async () => {+ await createAPIKey();++ await prisma.organization.update({+ where: {+ id: "seed-org-id",+ },+ data: {+ cloudConfig: {+ stripe: {+ customerId: "cus_test123",+ activeSubscriptionId: "sub_test123",+ activeProductId: "prod_test123",+ },+ },+ },+ });++ await new ApiAuthService(prisma, null).verifyAuthHeaderAndReturnScope(+ "Basic cGstbGYtMTIzNDU2Nzg5MDpzay1sZi0xMjM0NTY3ODkw",+ );++ const auth = await new ApiAuthService(+ prisma,+ null,+ ).verifyAuthHeaderAndReturnScope(+ "Basic cGstbGYtMTIzNDU2Nzg5MDpzay1sZi0xMjM0NTY3ODkw",+ );+ expect(auth.validKey).toBe(true);++ if (auth.validKey) {+ expect(auth.scope.orgId).toBe("seed-org-id");+ expect(auth.scope.plan).toBe("cloud:hobby");+ expect(auth.scope.rateLimitOverrides).toEqual([]);+ }++ const apiKey = await prisma.apiKey.findUnique({+ where: { publicKey: "pk-lf-1234567890" },+ });+ expect(apiKey).not.toBeNull();+ expect(apiKey?.fastHashedSecretKey).not.toBeNull();++ await prisma.organization.update({+ where: {+ id: "seed-org-id",+ },+ data: {+ cloudConfig: Prisma.JsonNull,+ },+ });+ });++ it("should create new api key with custom rate limits and succeed with new key", async () => {+ await createAPIKey();++ await prisma.organization.update({+ where: {+ id: "seed-org-id",+ },+ data: {+ cloudConfig: {+ rateLimitOverrides: [+ {+ resource: "ingestion",+ points: 100,+ durationInSec: 60,+ },+ ],+ },+ },+ });++ await new ApiAuthService(prisma, null).verifyAuthHeaderAndReturnScope(+ "Basic cGstbGYtMTIzNDU2Nzg5MDpzay1sZi0xMjM0NTY3ODkw",+ );++ const auth = await new ApiAuthService(+ prisma,+ null,+ ).verifyAuthHeaderAndReturnScope(+ "Basic cGstbGYtMTIzNDU2Nzg5MDpzay1sZi0xMjM0NTY3ODkw",+ );+ expect(auth.validKey).toBe(true);++ if (auth.validKey) {+ expect(auth.scope.orgId).toBe("seed-org-id");+ expect(auth.scope.plan).toBe("cloud:hobby");+ expect(auth.scope.rateLimitOverrides).toEqual([+ {+ resource: "ingestion",+ points: 100,+ durationInSec: 60,+ },+ ]);+ }++ const apiKey = await prisma.apiKey.findUnique({+ where: { publicKey: "pk-lf-1234567890" },+ });+ expect(apiKey).not.toBeNull();+ expect(apiKey?.fastHashedSecretKey).not.toBeNull();++ await prisma.organization.update({+ where: {+ id: "seed-org-id",+ },+ data: {+ cloudConfig: Prisma.JsonNull,+ },+ });+ });+it("should fail on wrong api key with new key", async () => {await createAPIKey();const auth = await new ApiAuthService(