@secondlayer/shared 2.1.0 → 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/src/db/index.d.ts +39 -137
- package/dist/src/db/index.js.map +2 -2
- package/dist/src/db/jsonb.d.ts +5 -1
- package/dist/src/db/jsonb.js.map +2 -2
- package/dist/src/db/queries/account-spend-caps.d.ts +379 -0
- package/dist/src/db/queries/account-spend-caps.js +60 -0
- package/dist/src/db/queries/account-spend-caps.js.map +10 -0
- package/dist/src/db/queries/account-usage.d.ts +403 -0
- package/dist/src/db/queries/account-usage.js +222 -0
- package/dist/src/db/queries/account-usage.js.map +11 -0
- package/dist/src/db/queries/accounts.d.ts +41 -115
- package/dist/src/db/queries/accounts.js +15 -1
- package/dist/src/db/queries/accounts.js.map +3 -3
- package/dist/src/db/queries/integrity.d.ts +27 -114
- package/dist/src/db/queries/projects.d.ts +27 -114
- package/dist/src/db/queries/provisioning-audit.d.ts +27 -114
- package/dist/src/db/queries/subgraph-gaps.d.ts +27 -114
- package/dist/src/db/queries/subgraphs.d.ts +27 -115
- package/dist/src/db/queries/subgraphs.js +2 -3
- package/dist/src/db/queries/subgraphs.js.map +4 -4
- package/dist/src/db/queries/{workflows.d.ts → tenant-compute-addons.d.ts} +50 -149
- package/dist/src/db/queries/tenant-compute-addons.js +47 -0
- package/dist/src/db/queries/tenant-compute-addons.js.map +10 -0
- package/dist/src/db/queries/tenants.d.ts +40 -117
- package/dist/src/db/queries/tenants.js +9 -6
- package/dist/src/db/queries/tenants.js.map +3 -3
- package/dist/src/db/queries/usage.d.ts +28 -139
- package/dist/src/db/queries/usage.js +5 -64
- package/dist/src/db/queries/usage.js.map +4 -5
- package/dist/src/db/schema.d.ts +34 -136
- package/dist/src/errors.d.ts +8 -7
- package/dist/src/errors.js +11 -12
- package/dist/src/errors.js.map +3 -3
- package/dist/src/index.d.ts +46 -143
- package/dist/src/index.js +11 -12
- package/dist/src/index.js.map +4 -4
- package/dist/src/node/local-client.d.ts +27 -114
- package/dist/src/pricing.d.ts +20 -1
- package/dist/src/pricing.js +58 -1
- package/dist/src/pricing.js.map +3 -3
- package/migrations/0045_drop_marketplace_columns.ts +47 -0
- package/migrations/0046_tenant_activity_signal.ts +47 -0
- package/migrations/0047_usage_daily_tenant_id.ts +73 -0
- package/migrations/0048_tenant_compute_addons.ts +49 -0
- package/migrations/0049_accounts_stripe_customer_id.ts +30 -0
- package/migrations/0050_account_spend_caps.ts +45 -0
- package/migrations/0051_workflow_ai_usage_daily.ts +40 -0
- package/migrations/0052_sentries.ts +61 -0
- package/migrations/0053_workflow_runtime.ts +88 -0
- package/migrations/0054_accounts_plan_hobby.ts +32 -0
- package/migrations/0055_ai_usage_account_scope.ts +108 -0
- package/migrations/0056_drop_workflow_sentry_residuals.ts +23 -0
- package/package.json +26 -14
- package/dist/src/db/queries/workflows.js +0 -260
- package/dist/src/db/queries/workflows.js.map +0 -12
- package/dist/src/lib/plans.d.ts +0 -9
- package/dist/src/lib/plans.js +0 -37
- package/dist/src/lib/plans.js.map +0 -10
- package/dist/src/schemas/workflows.d.ts +0 -70
- package/dist/src/schemas/workflows.js +0 -43
- package/dist/src/schemas/workflows.js.map +0 -10
|
@@ -14,21 +14,6 @@ var __export = (target, all) => {
|
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
// src/lib/plans.ts
|
|
18
|
-
var FREE_PLAN = {
|
|
19
|
-
subgraphs: 2,
|
|
20
|
-
apiRequestsPerDay: 1000,
|
|
21
|
-
deliveriesPerMonth: 5000,
|
|
22
|
-
storageBytes: 100 * 1024 * 1024
|
|
23
|
-
};
|
|
24
|
-
function getPlanLimits(plan) {
|
|
25
|
-
switch (plan) {
|
|
26
|
-
case "free":
|
|
27
|
-
default:
|
|
28
|
-
return FREE_PLAN;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
17
|
// src/db/queries/usage.ts
|
|
33
18
|
import { sql } from "kysely";
|
|
34
19
|
async function incrementApiRequests(db, accountId) {
|
|
@@ -44,7 +29,7 @@ async function incrementApiRequests(db, accountId) {
|
|
|
44
29
|
}
|
|
45
30
|
async function getUsage(db, accountId) {
|
|
46
31
|
const today = new Date().toISOString().slice(0, 10);
|
|
47
|
-
const monthStart = today.slice(0, 7)
|
|
32
|
+
const monthStart = `${today.slice(0, 7)}-01`;
|
|
48
33
|
const dailyRow = await db.selectFrom("usage_daily").select("api_requests").where("account_id", "=", accountId).where("date", "=", today).executeTakeFirst();
|
|
49
34
|
const monthlyRow = await db.selectFrom("usage_daily").select(sql`COALESCE(SUM(deliveries), 0)`.as("total")).where("account_id", "=", accountId).where("date", ">=", monthStart).executeTakeFirst();
|
|
50
35
|
const storageRow = await db.selectFrom("usage_snapshots").select("storage_bytes").where("account_id", "=", accountId).orderBy("measured_at", "desc").limit(1).executeTakeFirst();
|
|
@@ -54,49 +39,6 @@ async function getUsage(db, accountId) {
|
|
|
54
39
|
storageBytes: Number(storageRow?.storage_bytes ?? 0)
|
|
55
40
|
};
|
|
56
41
|
}
|
|
57
|
-
async function getDailyUsage(db, accountId) {
|
|
58
|
-
const rows = await db.selectFrom("usage_daily").select(["date", "api_requests", "deliveries"]).where("account_id", "=", accountId).where("date", ">=", sql`NOW()::date - 6`).orderBy("date", "asc").execute();
|
|
59
|
-
const byDate = new Map(rows.map((r) => {
|
|
60
|
-
const d = r.date;
|
|
61
|
-
const key = d instanceof Date ? d.toISOString().slice(0, 10) : String(d).slice(0, 10);
|
|
62
|
-
return [key, r];
|
|
63
|
-
}));
|
|
64
|
-
const result = [];
|
|
65
|
-
for (let i = 6;i >= 0; i--) {
|
|
66
|
-
const d = new Date;
|
|
67
|
-
d.setDate(d.getDate() - i);
|
|
68
|
-
const dateStr = d.toISOString().slice(0, 10);
|
|
69
|
-
const row = byDate.get(dateStr);
|
|
70
|
-
result.push({
|
|
71
|
-
date: dateStr,
|
|
72
|
-
apiRequests: row?.api_requests ?? 0,
|
|
73
|
-
deliveries: row?.deliveries ?? 0
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
async function checkLimits(db, accountId, plan) {
|
|
79
|
-
const limits = getPlanLimits(plan);
|
|
80
|
-
const usage = await getUsage(db, accountId);
|
|
81
|
-
const subgraphCount = await db.selectFrom("subgraphs").select(sql`count(*)`.as("count")).where("account_id", "=", accountId).executeTakeFirst();
|
|
82
|
-
const current = {
|
|
83
|
-
...usage,
|
|
84
|
-
subgraphs: Number(subgraphCount?.count ?? 0)
|
|
85
|
-
};
|
|
86
|
-
if (current.subgraphs >= limits.subgraphs) {
|
|
87
|
-
return { allowed: false, limits, current, exceeded: "subgraphs" };
|
|
88
|
-
}
|
|
89
|
-
if (current.apiRequestsToday >= limits.apiRequestsPerDay) {
|
|
90
|
-
return { allowed: false, limits, current, exceeded: "api_requests" };
|
|
91
|
-
}
|
|
92
|
-
if (current.deliveriesThisMonth >= limits.deliveriesPerMonth) {
|
|
93
|
-
return { allowed: false, limits, current, exceeded: "deliveries" };
|
|
94
|
-
}
|
|
95
|
-
if (current.storageBytes >= limits.storageBytes) {
|
|
96
|
-
return { allowed: false, limits, current, exceeded: "storage" };
|
|
97
|
-
}
|
|
98
|
-
return { allowed: true, limits, current };
|
|
99
|
-
}
|
|
100
42
|
async function measureStorage(db) {
|
|
101
43
|
const accountSubgraphs = await db.selectFrom("subgraphs").select(["account_id", "schema_name"]).where("schema_name", "is not", null).execute();
|
|
102
44
|
const byAccount = new Map;
|
|
@@ -114,7 +56,8 @@ async function measureStorage(db) {
|
|
|
114
56
|
SELECT COALESCE(SUM(pg_total_relation_size(quote_ident(schemaname) || '.' || quote_ident(tablename))), 0)::text as size
|
|
115
57
|
FROM pg_tables WHERE schemaname = ${schema}
|
|
116
58
|
`.execute(db);
|
|
117
|
-
|
|
59
|
+
const row = result.rows[0];
|
|
60
|
+
totalBytes += Number(row?.size ?? 0);
|
|
118
61
|
} catch {}
|
|
119
62
|
}
|
|
120
63
|
await db.insertInto("usage_snapshots").values({
|
|
@@ -126,10 +69,8 @@ async function measureStorage(db) {
|
|
|
126
69
|
export {
|
|
127
70
|
measureStorage,
|
|
128
71
|
incrementApiRequests,
|
|
129
|
-
getUsage
|
|
130
|
-
getDailyUsage,
|
|
131
|
-
checkLimits
|
|
72
|
+
getUsage
|
|
132
73
|
};
|
|
133
74
|
|
|
134
|
-
//# debugId=
|
|
75
|
+
//# debugId=93865CC393EF182964756E2164756E21
|
|
135
76
|
//# sourceMappingURL=usage.js.map
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/
|
|
3
|
+
"sources": ["../src/db/queries/usage.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"
|
|
6
|
-
"import { type Kysely, sql } from \"kysely\";\nimport { getPlanLimits } from \"../../lib/plans.ts\";\nimport type { Database } from \"../types.ts\";\n\n/** Increment API request counter for today. Fire-and-forget safe. */\nexport async function incrementApiRequests(\n\tdb: Kysely<Database>,\n\taccountId: string,\n): Promise<void> {\n\tconst today = new Date().toISOString().slice(0, 10);\n\tawait db\n\t\t.insertInto(\"usage_daily\")\n\t\t.values({\n\t\t\taccount_id: accountId,\n\t\t\tdate: today,\n\t\t\tapi_requests: 1,\n\t\t\tdeliveries: 0,\n\t\t})\n\t\t.onConflict((oc) =>\n\t\t\toc.columns([\"account_id\", \"date\"]).doUpdateSet({\n\t\t\t\tapi_requests: sql`usage_daily.api_requests + 1`,\n\t\t\t}),\n\t\t)\n\t\t.execute();\n}\n\nexport interface UsageSummary {\n\tapiRequestsToday: number;\n\tdeliveriesThisMonth: number;\n\tstorageBytes: number;\n}\n\n/** Get current usage for an account. */\nexport async function getUsage(\n\tdb: Kysely<Database>,\n\taccountId: string,\n): Promise<UsageSummary> {\n\tconst today = new Date().toISOString().slice(0, 10);\n\tconst monthStart = today.slice(0, 7) + \"-01\"; // YYYY-MM-01\n\n\t// Today's API requests\n\tconst dailyRow = await db\n\t\t.selectFrom(\"usage_daily\")\n\t\t.select(\"api_requests\")\n\t\t.where(\"account_id\", \"=\", accountId)\n\t\t.where(\"date\", \"=\", today)\n\t\t.executeTakeFirst();\n\n\t// This month's deliveries\n\tconst monthlyRow = await db\n\t\t.selectFrom(\"usage_daily\")\n\t\t.select(sql<number>`COALESCE(SUM(deliveries), 0)`.as(\"total\"))\n\t\t.where(\"account_id\", \"=\", accountId)\n\t\t.where(\"date\", \">=\", monthStart)\n\t\t.executeTakeFirst();\n\n\t// Latest storage snapshot\n\tconst storageRow = await db\n\t\t.selectFrom(\"usage_snapshots\")\n\t\t.select(\"storage_bytes\")\n\t\t.where(\"account_id\", \"=\", accountId)\n\t\t.orderBy(\"measured_at\", \"desc\")\n\t\t.limit(1)\n\t\t.executeTakeFirst();\n\n\treturn {\n\t\tapiRequestsToday: dailyRow?.api_requests ?? 0,\n\t\tdeliveriesThisMonth: Number(monthlyRow?.total ?? 0),\n\t\tstorageBytes: Number(storageRow?.storage_bytes ?? 0),\n\t};\n}\n\nexport interface DailyUsage {\n\tdate: string;\n\tapiRequests: number;\n\tdeliveries: number;\n}\n\n/** Get last 7 days of daily usage, filling missing days with 0. */\nexport async function getDailyUsage(\n\tdb: Kysely<Database>,\n\taccountId: string,\n): Promise<DailyUsage[]> {\n\tconst rows = await db\n\t\t.selectFrom(\"usage_daily\")\n\t\t.select([\"date\", \"api_requests\", \"deliveries\"])\n\t\t.where(\"account_id\", \"=\", accountId)\n\t\t.where(\"date\", \">=\", sql<string>`NOW()::date - 6`)\n\t\t.orderBy(\"date\", \"asc\")\n\t\t.execute();\n\n\t// Fill missing days with 0 (normalize date to YYYY-MM-DD string)\n\tconst byDate = new Map(\n\t\trows.map((r) => {\n\t\t\tconst d = r.date as unknown;\n\t\t\tconst key =\n\t\t\t\td instanceof Date\n\t\t\t\t\t? d.toISOString().slice(0, 10)\n\t\t\t\t\t: String(d).slice(0, 10);\n\t\t\treturn [key, r];\n\t\t}),\n\t);\n\tconst result: DailyUsage[] = [];\n\tfor (let i = 6; i >= 0; i--) {\n\t\tconst d = new Date();\n\t\td.setDate(d.getDate() - i);\n\t\tconst dateStr = d.toISOString().slice(0, 10);\n\t\tconst row = byDate.get(dateStr);\n\t\tresult.push({\n\t\t\tdate: dateStr,\n\t\t\tapiRequests: row?.api_requests ?? 0,\n\t\t\tdeliveries: row?.deliveries ?? 0,\n\t\t});\n\t}\n\treturn result;\n}\n\nexport interface LimitCheck {\n\tallowed: boolean;\n\tlimits: ReturnType<typeof getPlanLimits>;\n\tcurrent: UsageSummary & { subgraphs: number };\n\texceeded?: string;\n}\n\n/** Check if an account is within plan limits. */\nexport async function checkLimits(\n\tdb: Kysely<Database>,\n\taccountId: string,\n\tplan: string,\n): Promise<LimitCheck> {\n\tconst limits = getPlanLimits(plan);\n\tconst usage = await getUsage(db, accountId);\n\n\tconst subgraphCount = await db\n\t\t.selectFrom(\"subgraphs\")\n\t\t.select(sql<number>`count(*)`.as(\"count\"))\n\t\t.where(\"account_id\", \"=\", accountId)\n\t\t.executeTakeFirst();\n\n\tconst current = {\n\t\t...usage,\n\t\tsubgraphs: Number(subgraphCount?.count ?? 0),\n\t};\n\n\tif (current.subgraphs >= limits.subgraphs) {\n\t\treturn { allowed: false, limits, current, exceeded: \"subgraphs\" };\n\t}\n\tif (current.apiRequestsToday >= limits.apiRequestsPerDay) {\n\t\treturn { allowed: false, limits, current, exceeded: \"api_requests\" };\n\t}\n\tif (current.deliveriesThisMonth >= limits.deliveriesPerMonth) {\n\t\treturn { allowed: false, limits, current, exceeded: \"deliveries\" };\n\t}\n\tif (current.storageBytes >= limits.storageBytes) {\n\t\treturn { allowed: false, limits, current, exceeded: \"storage\" };\n\t}\n\n\treturn { allowed: true, limits, current };\n}\n\n/**\n * Measure storage for all accounts by querying pg_total_relation_size\n * for each tenant's subgraph schemas.\n */\nexport async function measureStorage(db: Kysely<Database>): Promise<void> {\n\t// Get all accounts with subgraphs\n\tconst accountSubgraphs = await db\n\t\t.selectFrom(\"subgraphs\")\n\t\t.select([\"account_id\", \"schema_name\"])\n\t\t.where(\"schema_name\", \"is not\", null)\n\t\t.execute();\n\n\t// Group schemas by account\n\tconst byAccount = new Map<string, string[]>();\n\tfor (const row of accountSubgraphs) {\n\t\tconst schemas = byAccount.get(row.account_id) ?? [];\n\t\tif (row.schema_name) schemas.push(row.schema_name);\n\t\tbyAccount.set(row.account_id, schemas);\n\t}\n\n\tfor (const [accountId, schemas] of byAccount) {\n\t\tlet totalBytes = 0;\n\t\tfor (const schema of schemas) {\n\t\t\ttry {\n\t\t\t\tconst result = await sql<{ size: string }>`\n SELECT COALESCE(SUM(pg_total_relation_size(quote_ident(schemaname) || '.' || quote_ident(tablename))), 0)::text as size\n FROM pg_tables WHERE schemaname = ${schema}\n `.execute(db);\n\t\t\t\ttotalBytes += Number((result.rows[0] as any)?.size ?? 0);\n\t\t\t} catch {\n\t\t\t\t// Schema may not exist\n\t\t\t}\n\t\t}\n\n\t\tawait db\n\t\t\t.insertInto(\"usage_snapshots\")\n\t\t\t.values({\n\t\t\t\taccount_id: accountId,\n\t\t\t\tstorage_bytes: totalBytes,\n\t\t\t})\n\t\t\t.execute();\n\t}\n}\n"
|
|
5
|
+
"import { type Kysely, sql } from \"kysely\";\nimport type { Database } from \"../types.ts\";\n\n/** Increment API request counter for today. Fire-and-forget safe. */\nexport async function incrementApiRequests(\n\tdb: Kysely<Database>,\n\taccountId: string,\n): Promise<void> {\n\tconst today = new Date().toISOString().slice(0, 10);\n\tawait db\n\t\t.insertInto(\"usage_daily\")\n\t\t.values({\n\t\t\taccount_id: accountId,\n\t\t\tdate: today,\n\t\t\tapi_requests: 1,\n\t\t\tdeliveries: 0,\n\t\t})\n\t\t.onConflict((oc) =>\n\t\t\toc.columns([\"account_id\", \"date\"]).doUpdateSet({\n\t\t\t\tapi_requests: sql`usage_daily.api_requests + 1`,\n\t\t\t}),\n\t\t)\n\t\t.execute();\n}\n\nexport interface UsageSummary {\n\tapiRequestsToday: number;\n\tdeliveriesThisMonth: number;\n\tstorageBytes: number;\n}\n\n/** Get current usage for an account. */\nexport async function getUsage(\n\tdb: Kysely<Database>,\n\taccountId: string,\n): Promise<UsageSummary> {\n\tconst today = new Date().toISOString().slice(0, 10);\n\tconst monthStart = `${today.slice(0, 7)}-01`; // YYYY-MM-01\n\n\t// Today's API requests\n\tconst dailyRow = await db\n\t\t.selectFrom(\"usage_daily\")\n\t\t.select(\"api_requests\")\n\t\t.where(\"account_id\", \"=\", accountId)\n\t\t.where(\"date\", \"=\", today)\n\t\t.executeTakeFirst();\n\n\t// This month's deliveries\n\tconst monthlyRow = await db\n\t\t.selectFrom(\"usage_daily\")\n\t\t.select(sql<number>`COALESCE(SUM(deliveries), 0)`.as(\"total\"))\n\t\t.where(\"account_id\", \"=\", accountId)\n\t\t.where(\"date\", \">=\", monthStart)\n\t\t.executeTakeFirst();\n\n\t// Latest storage snapshot\n\tconst storageRow = await db\n\t\t.selectFrom(\"usage_snapshots\")\n\t\t.select(\"storage_bytes\")\n\t\t.where(\"account_id\", \"=\", accountId)\n\t\t.orderBy(\"measured_at\", \"desc\")\n\t\t.limit(1)\n\t\t.executeTakeFirst();\n\n\treturn {\n\t\tapiRequestsToday: dailyRow?.api_requests ?? 0,\n\t\tdeliveriesThisMonth: Number(monthlyRow?.total ?? 0),\n\t\tstorageBytes: Number(storageRow?.storage_bytes ?? 0),\n\t};\n}\n\n/**\n * Measure storage for all accounts by querying pg_total_relation_size\n * for each tenant's subgraph schemas.\n */\nexport async function measureStorage(db: Kysely<Database>): Promise<void> {\n\t// Get all accounts with subgraphs\n\tconst accountSubgraphs = await db\n\t\t.selectFrom(\"subgraphs\")\n\t\t.select([\"account_id\", \"schema_name\"])\n\t\t.where(\"schema_name\", \"is not\", null)\n\t\t.execute();\n\n\t// Group schemas by account\n\tconst byAccount = new Map<string, string[]>();\n\tfor (const row of accountSubgraphs) {\n\t\tconst schemas = byAccount.get(row.account_id) ?? [];\n\t\tif (row.schema_name) schemas.push(row.schema_name);\n\t\tbyAccount.set(row.account_id, schemas);\n\t}\n\n\tfor (const [accountId, schemas] of byAccount) {\n\t\tlet totalBytes = 0;\n\t\tfor (const schema of schemas) {\n\t\t\ttry {\n\t\t\t\tconst result = await sql<{ size: string }>`\n SELECT COALESCE(SUM(pg_total_relation_size(quote_ident(schemaname) || '.' || quote_ident(tablename))), 0)::text as size\n FROM pg_tables WHERE schemaname = ${schema}\n `.execute(db);\n\t\t\t\tconst row = result.rows[0] as { size?: string } | undefined;\n\t\t\t\ttotalBytes += Number(row?.size ?? 0);\n\t\t\t} catch {\n\t\t\t\t// Schema may not exist\n\t\t\t}\n\t\t}\n\n\t\tawait db\n\t\t\t.insertInto(\"usage_snapshots\")\n\t\t\t.values({\n\t\t\t\taccount_id: accountId,\n\t\t\t\tstorage_bytes: totalBytes,\n\t\t\t})\n\t\t\t.execute();\n\t}\n}\n"
|
|
7
6
|
],
|
|
8
|
-
"mappings": ";;;;;;;;;;;;;;;;;
|
|
9
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAIA,eAAsB,oBAAoB,CACzC,IACA,WACgB;AAAA,EAChB,MAAM,QAAQ,IAAI,KAAK,EAAE,YAAY,EAAE,MAAM,GAAG,EAAE;AAAA,EAClD,MAAM,GACJ,WAAW,aAAa,EACxB,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,MAAM;AAAA,IACN,cAAc;AAAA,IACd,YAAY;AAAA,EACb,CAAC,EACA,WAAW,CAAC,OACZ,GAAG,QAAQ,CAAC,cAAc,MAAM,CAAC,EAAE,YAAY;AAAA,IAC9C,cAAc;AAAA,EACf,CAAC,CACF,EACC,QAAQ;AAAA;AAUX,eAAsB,QAAQ,CAC7B,IACA,WACwB;AAAA,EACxB,MAAM,QAAQ,IAAI,KAAK,EAAE,YAAY,EAAE,MAAM,GAAG,EAAE;AAAA,EAClD,MAAM,aAA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ACpC,QAAQ,EAAE;AAAA,QAChB,MAAM,MAAM,OAAO,KAAK;AAAA,QACxB,cAAc,OAAO,KAAK,QAAQ,CAAC;AAAA,QAClC,MAAM;AAAA,IAGT;AAAA,IAEA,MAAM,GACJ,WAAW,iBAAiB,EAC5B,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,eAAe;AAAA,IAChB,CAAC,EACA,QAAQ;AAAA,EACX;AAAA;",
|
|
8
|
+
"debugId": "93865CC393EF182964756E2164756E21",
|
|
10
9
|
"names": []
|
|
11
10
|
}
|
package/dist/src/db/schema.d.ts
CHANGED
|
@@ -59,10 +59,6 @@ interface SubgraphsTable {
|
|
|
59
59
|
handler_code: string | null;
|
|
60
60
|
source_code: string | null;
|
|
61
61
|
project_id: string | null;
|
|
62
|
-
is_public: Generated<boolean>;
|
|
63
|
-
tags: Generated<string[]>;
|
|
64
|
-
description: string | null;
|
|
65
|
-
forked_from_id: string | null;
|
|
66
62
|
created_at: Generated<Date>;
|
|
67
63
|
updated_at: Generated<Date>;
|
|
68
64
|
}
|
|
@@ -97,6 +93,7 @@ interface AccountsTable {
|
|
|
97
93
|
bio: string | null;
|
|
98
94
|
avatar_url: string | null;
|
|
99
95
|
slug: string | null;
|
|
96
|
+
stripe_customer_id: string | null;
|
|
100
97
|
created_at: Generated<Date>;
|
|
101
98
|
}
|
|
102
99
|
interface SessionsTable {
|
|
@@ -122,6 +119,7 @@ interface MagicLinksTable {
|
|
|
122
119
|
}
|
|
123
120
|
interface UsageDailyTable {
|
|
124
121
|
account_id: string;
|
|
122
|
+
tenant_id: string | null;
|
|
125
123
|
date: string;
|
|
126
124
|
api_requests: Generated<number>;
|
|
127
125
|
deliveries: Generated<number>;
|
|
@@ -248,83 +246,6 @@ interface ChatMessagesTable {
|
|
|
248
246
|
metadata: unknown | null;
|
|
249
247
|
created_at: Generated<Date>;
|
|
250
248
|
}
|
|
251
|
-
interface WorkflowDefinitionsTable {
|
|
252
|
-
id: Generated<string>;
|
|
253
|
-
name: string;
|
|
254
|
-
version: Generated<string>;
|
|
255
|
-
status: Generated<string>;
|
|
256
|
-
trigger_type: string;
|
|
257
|
-
trigger_config: unknown;
|
|
258
|
-
handler_path: string;
|
|
259
|
-
source_code: string | null;
|
|
260
|
-
retries_config: unknown | null;
|
|
261
|
-
timeout_ms: number | null;
|
|
262
|
-
api_key_id: string;
|
|
263
|
-
project_id: string | null;
|
|
264
|
-
created_at: Generated<Date>;
|
|
265
|
-
updated_at: Generated<Date>;
|
|
266
|
-
}
|
|
267
|
-
interface WorkflowRunsTable {
|
|
268
|
-
id: Generated<string>;
|
|
269
|
-
definition_id: string;
|
|
270
|
-
status: Generated<string>;
|
|
271
|
-
trigger_type: string;
|
|
272
|
-
trigger_data: unknown | null;
|
|
273
|
-
dedup_key: string | null;
|
|
274
|
-
error: string | null;
|
|
275
|
-
started_at: Date | null;
|
|
276
|
-
completed_at: Date | null;
|
|
277
|
-
duration_ms: number | null;
|
|
278
|
-
total_ai_tokens: Generated<number>;
|
|
279
|
-
created_at: Generated<Date>;
|
|
280
|
-
}
|
|
281
|
-
interface WorkflowStepsTable {
|
|
282
|
-
id: Generated<string>;
|
|
283
|
-
run_id: string;
|
|
284
|
-
step_index: number;
|
|
285
|
-
step_id: string;
|
|
286
|
-
step_type: string;
|
|
287
|
-
status: Generated<string>;
|
|
288
|
-
input: unknown | null;
|
|
289
|
-
output: unknown | null;
|
|
290
|
-
error: string | null;
|
|
291
|
-
retry_count: Generated<number>;
|
|
292
|
-
ai_tokens_used: Generated<number>;
|
|
293
|
-
started_at: Date | null;
|
|
294
|
-
completed_at: Date | null;
|
|
295
|
-
duration_ms: number | null;
|
|
296
|
-
memo_key: string | null;
|
|
297
|
-
parent_step_id: string | null;
|
|
298
|
-
created_at: Generated<Date>;
|
|
299
|
-
}
|
|
300
|
-
interface WorkflowQueueTable {
|
|
301
|
-
id: Generated<string>;
|
|
302
|
-
run_id: string;
|
|
303
|
-
status: Generated<string>;
|
|
304
|
-
attempts: Generated<number>;
|
|
305
|
-
max_attempts: Generated<number>;
|
|
306
|
-
scheduled_for: Generated<Date>;
|
|
307
|
-
locked_at: Date | null;
|
|
308
|
-
locked_by: string | null;
|
|
309
|
-
error: string | null;
|
|
310
|
-
created_at: Generated<Date>;
|
|
311
|
-
completed_at: Date | null;
|
|
312
|
-
}
|
|
313
|
-
interface WorkflowSchedulesTable {
|
|
314
|
-
id: Generated<string>;
|
|
315
|
-
definition_id: string;
|
|
316
|
-
cron_expr: string;
|
|
317
|
-
timezone: Generated<string>;
|
|
318
|
-
next_run_at: Date;
|
|
319
|
-
last_run_at: Date | null;
|
|
320
|
-
enabled: Generated<boolean>;
|
|
321
|
-
created_at: Generated<Date>;
|
|
322
|
-
}
|
|
323
|
-
interface WorkflowCursorsTable {
|
|
324
|
-
name: string;
|
|
325
|
-
block_height: Generated<number>;
|
|
326
|
-
updated_at: Generated<Date>;
|
|
327
|
-
}
|
|
328
249
|
interface Database {
|
|
329
250
|
blocks: BlocksTable;
|
|
330
251
|
transactions: TransactionsTable;
|
|
@@ -350,16 +271,10 @@ interface Database {
|
|
|
350
271
|
team_invitations: TeamInvitationsTable;
|
|
351
272
|
chat_sessions: ChatSessionsTable;
|
|
352
273
|
chat_messages: ChatMessagesTable;
|
|
353
|
-
workflow_definitions: WorkflowDefinitionsTable;
|
|
354
|
-
workflow_runs: WorkflowRunsTable;
|
|
355
|
-
workflow_steps: WorkflowStepsTable;
|
|
356
|
-
workflow_queue: WorkflowQueueTable;
|
|
357
|
-
workflow_schedules: WorkflowSchedulesTable;
|
|
358
|
-
workflow_cursors: WorkflowCursorsTable;
|
|
359
|
-
workflow_signer_secrets: WorkflowSignerSecretsTable;
|
|
360
|
-
workflow_budgets: WorkflowBudgetsTable;
|
|
361
274
|
tenants: TenantsTable;
|
|
362
275
|
tenant_usage_monthly: TenantUsageMonthlyTable;
|
|
276
|
+
tenant_compute_addons: TenantComputeAddonsTable;
|
|
277
|
+
account_spend_caps: AccountSpendCapsTable;
|
|
363
278
|
provisioning_audit_log: ProvisioningAuditLogTable;
|
|
364
279
|
}
|
|
365
280
|
type TenantStatus = "provisioning" | "active" | "suspended" | "error" | "deleted";
|
|
@@ -382,9 +297,9 @@ interface TenantsTable {
|
|
|
382
297
|
service_key_enc: Buffer;
|
|
383
298
|
api_url_internal: string;
|
|
384
299
|
api_url_public: string;
|
|
385
|
-
trial_ends_at: Date;
|
|
386
300
|
suspended_at: Date | null;
|
|
387
301
|
last_health_check_at: Date | null;
|
|
302
|
+
last_active_at: Generated<Date>;
|
|
388
303
|
service_gen: Generated<number>;
|
|
389
304
|
anon_gen: Generated<number>;
|
|
390
305
|
project_id: string | null;
|
|
@@ -408,6 +323,34 @@ interface TenantUsageMonthlyTable {
|
|
|
408
323
|
type TenantUsageMonthly = Selectable<TenantUsageMonthlyTable>;
|
|
409
324
|
type InsertTenantUsageMonthly = Insertable<TenantUsageMonthlyTable>;
|
|
410
325
|
type UpdateTenantUsageMonthly = Updateable<TenantUsageMonthlyTable>;
|
|
326
|
+
interface TenantComputeAddonsTable {
|
|
327
|
+
id: Generated<string>;
|
|
328
|
+
tenant_id: string;
|
|
329
|
+
memory_mb_delta: Generated<number>;
|
|
330
|
+
cpu_delta: Generated<number | string>;
|
|
331
|
+
storage_mb_delta: Generated<number>;
|
|
332
|
+
effective_from: Generated<Date>;
|
|
333
|
+
effective_until: Date | null;
|
|
334
|
+
stripe_subscription_item_id: string | null;
|
|
335
|
+
created_at: Generated<Date>;
|
|
336
|
+
}
|
|
337
|
+
type TenantComputeAddon = Selectable<TenantComputeAddonsTable>;
|
|
338
|
+
type InsertTenantComputeAddon = Insertable<TenantComputeAddonsTable>;
|
|
339
|
+
type UpdateTenantComputeAddon = Updateable<TenantComputeAddonsTable>;
|
|
340
|
+
interface AccountSpendCapsTable {
|
|
341
|
+
account_id: string;
|
|
342
|
+
monthly_cap_cents: number | null;
|
|
343
|
+
compute_cap_cents: number | null;
|
|
344
|
+
storage_cap_cents: number | null;
|
|
345
|
+
ai_cap_cents: number | null;
|
|
346
|
+
alert_threshold_pct: Generated<number>;
|
|
347
|
+
alert_sent_at: Date | null;
|
|
348
|
+
frozen_at: Date | null;
|
|
349
|
+
updated_at: Generated<Date>;
|
|
350
|
+
}
|
|
351
|
+
type AccountSpendCap = Selectable<AccountSpendCapsTable>;
|
|
352
|
+
type InsertAccountSpendCap = Insertable<AccountSpendCapsTable>;
|
|
353
|
+
type UpdateAccountSpendCap = Updateable<AccountSpendCapsTable>;
|
|
411
354
|
type ProvisioningAuditEvent = "provision.start" | "provision.success" | "provision.failure" | "suspend" | "resume" | "resize" | "keys.rotate" | "bastion.key.upload" | "bastion.key.revoke" | "teardown";
|
|
412
355
|
type ProvisioningAuditStatus = "ok" | "error";
|
|
413
356
|
interface ProvisioningAuditLogTable {
|
|
@@ -424,30 +367,6 @@ interface ProvisioningAuditLogTable {
|
|
|
424
367
|
}
|
|
425
368
|
type ProvisioningAuditLog = Selectable<ProvisioningAuditLogTable>;
|
|
426
369
|
type InsertProvisioningAuditLog = Insertable<ProvisioningAuditLogTable>;
|
|
427
|
-
interface WorkflowBudgetsTable {
|
|
428
|
-
id: Generated<string>;
|
|
429
|
-
workflow_definition_id: string;
|
|
430
|
-
/** Period key: "daily:YYYY-MM-DD" | "weekly:YYYY-Www" | "per-run:<uuid>". */
|
|
431
|
-
period: string;
|
|
432
|
-
ai_usd_used: Generated<string>;
|
|
433
|
-
ai_tokens_used: Generated<string>;
|
|
434
|
-
chain_microstx_used: Generated<string>;
|
|
435
|
-
chain_tx_count: Generated<number>;
|
|
436
|
-
run_count: Generated<number>;
|
|
437
|
-
step_count: Generated<number>;
|
|
438
|
-
reset_at: Date;
|
|
439
|
-
created_at: Generated<Date>;
|
|
440
|
-
updated_at: Generated<Date>;
|
|
441
|
-
}
|
|
442
|
-
interface WorkflowSignerSecretsTable {
|
|
443
|
-
id: Generated<string>;
|
|
444
|
-
account_id: string;
|
|
445
|
-
name: string;
|
|
446
|
-
/** AES-GCM ciphertext bytes produced by the runner's KMS on write. */
|
|
447
|
-
encrypted_value: Buffer;
|
|
448
|
-
created_at: Generated<Date>;
|
|
449
|
-
updated_at: Generated<Date>;
|
|
450
|
-
}
|
|
451
370
|
type Block = Selectable<BlocksTable>;
|
|
452
371
|
type InsertBlock = Insertable<BlocksTable>;
|
|
453
372
|
type UpdateBlock = Updateable<BlocksTable>;
|
|
@@ -484,27 +403,6 @@ type SubgraphGap = Selectable<SubgraphGapsTable>;
|
|
|
484
403
|
type InsertSubgraphGap = Insertable<SubgraphGapsTable>;
|
|
485
404
|
type SubgraphUsageDaily = Selectable<SubgraphUsageDailyTable>;
|
|
486
405
|
type InsertSubgraphUsageDaily = Insertable<SubgraphUsageDailyTable>;
|
|
487
|
-
type WorkflowDefinition = Selectable<WorkflowDefinitionsTable>;
|
|
488
|
-
type InsertWorkflowDefinition = Insertable<WorkflowDefinitionsTable>;
|
|
489
|
-
type UpdateWorkflowDefinition = Updateable<WorkflowDefinitionsTable>;
|
|
490
|
-
type WorkflowRun = Selectable<WorkflowRunsTable>;
|
|
491
|
-
type InsertWorkflowRun = Insertable<WorkflowRunsTable>;
|
|
492
|
-
type UpdateWorkflowRun = Updateable<WorkflowRunsTable>;
|
|
493
|
-
type WorkflowStep = Selectable<WorkflowStepsTable>;
|
|
494
|
-
type InsertWorkflowStep = Insertable<WorkflowStepsTable>;
|
|
495
|
-
type UpdateWorkflowStep = Updateable<WorkflowStepsTable>;
|
|
496
|
-
type WorkflowQueueItem = Selectable<WorkflowQueueTable>;
|
|
497
|
-
type InsertWorkflowQueueItem = Insertable<WorkflowQueueTable>;
|
|
498
|
-
type WorkflowSchedule = Selectable<WorkflowSchedulesTable>;
|
|
499
|
-
type InsertWorkflowSchedule = Insertable<WorkflowSchedulesTable>;
|
|
500
|
-
type UpdateWorkflowSchedule = Updateable<WorkflowSchedulesTable>;
|
|
501
|
-
type WorkflowCursor = Selectable<WorkflowCursorsTable>;
|
|
502
|
-
type WorkflowSignerSecret = Selectable<WorkflowSignerSecretsTable>;
|
|
503
|
-
type InsertWorkflowSignerSecret = Insertable<WorkflowSignerSecretsTable>;
|
|
504
|
-
type UpdateWorkflowSignerSecret = Updateable<WorkflowSignerSecretsTable>;
|
|
505
|
-
type WorkflowBudget = Selectable<WorkflowBudgetsTable>;
|
|
506
|
-
type InsertWorkflowBudget = Insertable<WorkflowBudgetsTable>;
|
|
507
|
-
type UpdateWorkflowBudget = Updateable<WorkflowBudgetsTable>;
|
|
508
406
|
type Project = Selectable<ProjectsTable>;
|
|
509
407
|
type InsertProject = Insertable<ProjectsTable>;
|
|
510
408
|
type UpdateProject = Updateable<ProjectsTable>;
|
|
@@ -517,4 +415,4 @@ type InsertChatSession = Insertable<ChatSessionsTable>;
|
|
|
517
415
|
type UpdateChatSession = Updateable<ChatSessionsTable>;
|
|
518
416
|
type ChatMessage = Selectable<ChatMessagesTable>;
|
|
519
417
|
type InsertChatMessage = Insertable<ChatMessagesTable>;
|
|
520
|
-
export {
|
|
418
|
+
export { WaitlistTable, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubgraph, UpdateProject, UpdateIndexProgress, UpdateEvent, UpdateChatSession, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, TransactionsTable, Transaction, TenantsTable, TenantUsageMonthlyTable, TenantUsageMonthly, TenantStatus, TenantComputeAddonsTable, TenantComputeAddon, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubgraphsTable, SubgraphUsageDailyTable, SubgraphUsageDaily, SubgraphTableSnapshotsTable, SubgraphProcessingStatsTable, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGap, Subgraph, SessionsTable, Session, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, MagicLinksTable, MagicLink, InsertTransaction, InsertTenantUsageMonthly, InsertTenantComputeAddon, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubgraphUsageDaily, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertProvisioningAuditLog, InsertProject, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertChatSession, InsertChatMessage, InsertBlock, InsertApiKey, InsertAccountSpendCap, InsertAccountInsight, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, EventsTable, Event, Database, ChatSessionsTable, ChatSession, ChatMessagesTable, ChatMessage, BlocksTable, Block, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -8,10 +8,10 @@ declare const ErrorCodes: {
|
|
|
8
8
|
readonly VERSION_CONFLICT: "VERSION_CONFLICT"
|
|
9
9
|
readonly NOT_FOUND: "NOT_FOUND"
|
|
10
10
|
readonly KEY_ROTATED: "KEY_ROTATED"
|
|
11
|
-
readonly TRIAL_EXPIRED: "TRIAL_EXPIRED"
|
|
12
11
|
readonly TENANT_SUSPENDED: "TENANT_SUSPENDED"
|
|
13
12
|
readonly NO_TENANT_FOR_PROJECT: "NO_TENANT_FOR_PROJECT"
|
|
14
13
|
readonly INSTANCE_EXISTS: "INSTANCE_EXISTS"
|
|
14
|
+
readonly AI_CAP_REACHED: "AI_CAP_REACHED"
|
|
15
15
|
};
|
|
16
16
|
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
17
17
|
/** Base error class for all Secondlayer errors. */
|
|
@@ -56,15 +56,16 @@ declare class VersionConflictError extends SecondLayerError {
|
|
|
56
56
|
declare class KeyRotatedError extends SecondLayerError {
|
|
57
57
|
constructor(message?: string);
|
|
58
58
|
}
|
|
59
|
-
declare class TrialExpiredError extends SecondLayerError {
|
|
60
|
-
constructor(message: string);
|
|
61
|
-
}
|
|
62
59
|
declare class TenantSuspendedError extends SecondLayerError {
|
|
63
60
|
constructor(message?: string);
|
|
64
61
|
}
|
|
62
|
+
/**\\n* Thrown by the workflow-runner when a step.ai / generateText /\\n* generateObject call would exceed the tenant's daily AI eval cap.\\n* The step fails cleanly; the workflow's condition-only path (if any)\\n* continues. Surface to users as "AI budget reached — increase tier or\\n* wait for daily reset".\\n*/
|
|
63
|
+
declare class AiCapReachedError extends SecondLayerError {
|
|
64
|
+
constructor(message?: string);
|
|
65
|
+
}
|
|
65
66
|
/** Error code → HTTP status. Used by API middleware for code-based matching
|
|
66
67
|
* (avoids cross-bundle instanceof failures from bunup class duplication). */
|
|
67
|
-
type MappedCode = Extract<ErrorCode, "AUTHENTICATION_ERROR" | "AUTHORIZATION_ERROR" | "RATE_LIMIT_ERROR" | "FORBIDDEN" | "NOT_FOUND" | "VALIDATION_ERROR" | "KEY_ROTATED" | "
|
|
68
|
-
declare const CODE_TO_STATUS: Record<MappedCode, 400 | 401 |
|
|
68
|
+
type MappedCode = Extract<ErrorCode, "AUTHENTICATION_ERROR" | "AUTHORIZATION_ERROR" | "RATE_LIMIT_ERROR" | "FORBIDDEN" | "NOT_FOUND" | "VALIDATION_ERROR" | "KEY_ROTATED" | "TENANT_SUSPENDED" | "NO_TENANT_FOR_PROJECT" | "INSTANCE_EXISTS">;
|
|
69
|
+
declare const CODE_TO_STATUS: Record<MappedCode, 400 | 401 | 403 | 404 | 409 | 423 | 429>;
|
|
69
70
|
declare function getErrorMessage(err: unknown): string;
|
|
70
|
-
export { getErrorMessage, VersionConflictError, ValidationError,
|
|
71
|
+
export { getErrorMessage, VersionConflictError, ValidationError, TenantSuspendedError, SecondLayerError, RateLimitError, NotFoundError, KeyRotatedError, ForbiddenError, ErrorCodes, ErrorCode, DatabaseError, CODE_TO_STATUS, AuthorizationError, AuthenticationError, AiCapReachedError };
|
package/dist/src/errors.js
CHANGED
|
@@ -25,10 +25,10 @@ var ErrorCodes = {
|
|
|
25
25
|
VERSION_CONFLICT: "VERSION_CONFLICT",
|
|
26
26
|
NOT_FOUND: "NOT_FOUND",
|
|
27
27
|
KEY_ROTATED: "KEY_ROTATED",
|
|
28
|
-
TRIAL_EXPIRED: "TRIAL_EXPIRED",
|
|
29
28
|
TENANT_SUSPENDED: "TENANT_SUSPENDED",
|
|
30
29
|
NO_TENANT_FOR_PROJECT: "NO_TENANT_FOR_PROJECT",
|
|
31
|
-
INSTANCE_EXISTS: "INSTANCE_EXISTS"
|
|
30
|
+
INSTANCE_EXISTS: "INSTANCE_EXISTS",
|
|
31
|
+
AI_CAP_REACHED: "AI_CAP_REACHED"
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
class SecondLayerError extends Error {
|
|
@@ -110,17 +110,17 @@ class KeyRotatedError extends SecondLayerError {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
class TrialExpiredError extends SecondLayerError {
|
|
114
|
-
constructor(message) {
|
|
115
|
-
super("TRIAL_EXPIRED", message);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
113
|
class TenantSuspendedError extends SecondLayerError {
|
|
120
114
|
constructor(message = "Instance is suspended") {
|
|
121
115
|
super("TENANT_SUSPENDED", message);
|
|
122
116
|
}
|
|
123
117
|
}
|
|
118
|
+
|
|
119
|
+
class AiCapReachedError extends SecondLayerError {
|
|
120
|
+
constructor(message = "Daily AI eval cap reached for this tenant's plan tier") {
|
|
121
|
+
super("AI_CAP_REACHED", message);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
124
|
var CODE_TO_STATUS = {
|
|
125
125
|
AUTHENTICATION_ERROR: 401,
|
|
126
126
|
AUTHORIZATION_ERROR: 403,
|
|
@@ -129,7 +129,6 @@ var CODE_TO_STATUS = {
|
|
|
129
129
|
NOT_FOUND: 404,
|
|
130
130
|
VALIDATION_ERROR: 400,
|
|
131
131
|
KEY_ROTATED: 401,
|
|
132
|
-
TRIAL_EXPIRED: 402,
|
|
133
132
|
TENANT_SUSPENDED: 423,
|
|
134
133
|
NO_TENANT_FOR_PROJECT: 404,
|
|
135
134
|
INSTANCE_EXISTS: 409
|
|
@@ -141,7 +140,6 @@ export {
|
|
|
141
140
|
getErrorMessage,
|
|
142
141
|
VersionConflictError,
|
|
143
142
|
ValidationError,
|
|
144
|
-
TrialExpiredError,
|
|
145
143
|
TenantSuspendedError,
|
|
146
144
|
SecondLayerError,
|
|
147
145
|
RateLimitError,
|
|
@@ -152,8 +150,9 @@ export {
|
|
|
152
150
|
DatabaseError,
|
|
153
151
|
CODE_TO_STATUS,
|
|
154
152
|
AuthorizationError,
|
|
155
|
-
AuthenticationError
|
|
153
|
+
AuthenticationError,
|
|
154
|
+
AiCapReachedError
|
|
156
155
|
};
|
|
157
156
|
|
|
158
|
-
//# debugId=
|
|
157
|
+
//# debugId=3D5A72D827A8C6D464756E2164756E21
|
|
159
158
|
//# sourceMappingURL=errors.js.map
|
package/dist/src/errors.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/errors.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"export const ErrorCodes = {\n\tVALIDATION_ERROR: \"VALIDATION_ERROR\",\n\tDATABASE_ERROR: \"DATABASE_ERROR\",\n\tAUTHENTICATION_ERROR: \"AUTHENTICATION_ERROR\",\n\tAUTHORIZATION_ERROR: \"AUTHORIZATION_ERROR\",\n\tRATE_LIMIT_ERROR: \"RATE_LIMIT_ERROR\",\n\tFORBIDDEN: \"FORBIDDEN\",\n\tVERSION_CONFLICT: \"VERSION_CONFLICT\",\n\tNOT_FOUND: \"NOT_FOUND\",\n\t// Tenant lifecycle (CLI surfaces these verbatim)\n\tKEY_ROTATED: \"KEY_ROTATED\",\n\
|
|
5
|
+
"export const ErrorCodes = {\n\tVALIDATION_ERROR: \"VALIDATION_ERROR\",\n\tDATABASE_ERROR: \"DATABASE_ERROR\",\n\tAUTHENTICATION_ERROR: \"AUTHENTICATION_ERROR\",\n\tAUTHORIZATION_ERROR: \"AUTHORIZATION_ERROR\",\n\tRATE_LIMIT_ERROR: \"RATE_LIMIT_ERROR\",\n\tFORBIDDEN: \"FORBIDDEN\",\n\tVERSION_CONFLICT: \"VERSION_CONFLICT\",\n\tNOT_FOUND: \"NOT_FOUND\",\n\t// Tenant lifecycle (CLI surfaces these verbatim)\n\tKEY_ROTATED: \"KEY_ROTATED\",\n\tTENANT_SUSPENDED: \"TENANT_SUSPENDED\",\n\tNO_TENANT_FOR_PROJECT: \"NO_TENANT_FOR_PROJECT\",\n\tINSTANCE_EXISTS: \"INSTANCE_EXISTS\",\n\t// Workflow runtime caps (runner throws; step fails cleanly)\n\tAI_CAP_REACHED: \"AI_CAP_REACHED\",\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n\n/** Base error class for all Secondlayer errors. */\nexport class SecondLayerError extends Error {\n\tpublic code: ErrorCode;\n\tpublic override cause?: unknown;\n\n\tconstructor(code: ErrorCode, message: string, cause?: unknown) {\n\t\tsuper(message);\n\t\tthis.code = code;\n\t\tthis.cause = cause;\n\t\tthis.name = this.constructor.name;\n\t\tError.captureStackTrace?.(this, this.constructor);\n\t}\n\n\ttoJSON(): {\n\t\tname: string;\n\t\tcode: string;\n\t\tmessage: string;\n\t\tstack: string | undefined;\n\t\tcause: unknown;\n\t} {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tcode: this.code,\n\t\t\tmessage: this.message,\n\t\t\tstack: this.stack,\n\t\t\tcause: this.cause,\n\t\t};\n\t}\n}\n\nexport class NotFoundError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"NOT_FOUND\", message);\n\t}\n}\n\nexport class ValidationError extends SecondLayerError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"VALIDATION_ERROR\", message, cause);\n\t}\n}\n\nexport class DatabaseError extends SecondLayerError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"DATABASE_ERROR\", message, cause);\n\t}\n}\n\nexport class AuthenticationError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"AUTHENTICATION_ERROR\", message);\n\t}\n}\n\nexport class AuthorizationError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"AUTHORIZATION_ERROR\", message);\n\t}\n}\n\nexport class RateLimitError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"RATE_LIMIT_ERROR\", message);\n\t}\n}\n\nexport class ForbiddenError extends SecondLayerError {\n\tconstructor(message = \"Forbidden\") {\n\t\tsuper(\"FORBIDDEN\", message);\n\t}\n}\n\nexport class VersionConflictError extends SecondLayerError {\n\tpublic currentVersion: string;\n\tpublic expectedVersion: string;\n\n\tconstructor(currentVersion: string, expectedVersion: string) {\n\t\tsuper(\n\t\t\t\"VERSION_CONFLICT\",\n\t\t\t`Version conflict: expected ${expectedVersion}, current ${currentVersion}`,\n\t\t);\n\t\tthis.currentVersion = currentVersion;\n\t\tthis.expectedVersion = expectedVersion;\n\t}\n}\n\nexport class KeyRotatedError extends SecondLayerError {\n\tconstructor(message = \"Token has been rotated\") {\n\t\tsuper(\"KEY_ROTATED\", message);\n\t}\n}\n\nexport class TenantSuspendedError extends SecondLayerError {\n\tconstructor(message = \"Instance is suspended\") {\n\t\tsuper(\"TENANT_SUSPENDED\", message);\n\t}\n}\n\n/**\n * Thrown by the workflow-runner when a step.ai / generateText /\n * generateObject call would exceed the tenant's daily AI eval cap.\n * The step fails cleanly; the workflow's condition-only path (if any)\n * continues. Surface to users as \"AI budget reached — increase tier or\n * wait for daily reset\".\n */\nexport class AiCapReachedError extends SecondLayerError {\n\tconstructor(\n\t\tmessage = \"Daily AI eval cap reached for this tenant's plan tier\",\n\t) {\n\t\tsuper(\"AI_CAP_REACHED\", message);\n\t}\n}\n\n/** Error code → HTTP status. Used by API middleware for code-based matching\n * (avoids cross-bundle instanceof failures from bunup class duplication). */\ntype MappedCode = Extract<\n\tErrorCode,\n\t| \"AUTHENTICATION_ERROR\"\n\t| \"AUTHORIZATION_ERROR\"\n\t| \"RATE_LIMIT_ERROR\"\n\t| \"FORBIDDEN\"\n\t| \"NOT_FOUND\"\n\t| \"VALIDATION_ERROR\"\n\t| \"KEY_ROTATED\"\n\t| \"TENANT_SUSPENDED\"\n\t| \"NO_TENANT_FOR_PROJECT\"\n\t| \"INSTANCE_EXISTS\"\n>;\nexport const CODE_TO_STATUS: Record<\n\tMappedCode,\n\t400 | 401 | 403 | 404 | 409 | 423 | 429\n> = {\n\tAUTHENTICATION_ERROR: 401,\n\tAUTHORIZATION_ERROR: 403,\n\tRATE_LIMIT_ERROR: 429,\n\tFORBIDDEN: 403,\n\tNOT_FOUND: 404,\n\tVALIDATION_ERROR: 400,\n\tKEY_ROTATED: 401,\n\tTENANT_SUSPENDED: 423,\n\tNO_TENANT_FOR_PROJECT: 404,\n\tINSTANCE_EXISTS: 409,\n} as const;\n\nexport function getErrorMessage(err: unknown): string {\n\treturn err instanceof Error ? err.message : String(err);\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAO,IAAM,aAAa;AAAA,EACzB,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,kBAAkB;AAAA,EAClB,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB,WAAW;AAAA,EAEX,aAAa;AAAA,EACb,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAO,IAAM,aAAa;AAAA,EACzB,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,kBAAkB;AAAA,EAClB,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB,WAAW;AAAA,EAEX,aAAa;AAAA,EACb,kBAAkB;AAAA,EAClB,uBAAuB;AAAA,EACvB,iBAAiB;AAAA,EAEjB,gBAAgB;AACjB;AAAA;AAKO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