@secondlayer/shared 2.0.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 +64 -130
- 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 +61 -108
- 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 +47 -107
- package/dist/src/db/queries/projects.d.ts +47 -107
- package/dist/src/db/queries/{workflows.d.ts → provisioning-audit.d.ts} +70 -142
- package/dist/src/db/queries/provisioning-audit.js +40 -0
- package/dist/src/db/queries/provisioning-audit.js.map +10 -0
- package/dist/src/db/queries/subgraph-gaps.d.ts +47 -107
- package/dist/src/db/queries/subgraphs.d.ts +47 -108
- package/dist/src/db/queries/subgraphs.js +2 -3
- package/dist/src/db/queries/subgraphs.js.map +4 -4
- package/dist/src/db/queries/{marketplace.d.ts → tenant-compute-addons.d.ts} +66 -159
- 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 +67 -110
- package/dist/src/db/queries/tenants.js +35 -6
- package/dist/src/db/queries/tenants.js.map +3 -3
- package/dist/src/db/queries/usage.d.ts +48 -132
- 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 +59 -129
- 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 +98 -212
- package/dist/src/index.js +69 -80
- package/dist/src/index.js.map +6 -6
- package/dist/src/mode.d.ts +4 -5
- package/dist/src/mode.js.map +2 -2
- package/dist/src/node/local-client.d.ts +47 -107
- package/dist/src/pricing.d.ts +20 -1
- package/dist/src/pricing.js +58 -1
- package/dist/src/pricing.js.map +3 -3
- package/dist/src/schemas/accounts.d.ts +14 -0
- package/dist/src/schemas/{marketplace.js → accounts.js} +4 -14
- package/dist/src/schemas/accounts.js.map +10 -0
- package/dist/src/schemas/index.d.ts +28 -77
- package/dist/src/schemas/index.js +59 -69
- package/dist/src/schemas/index.js.map +4 -4
- package/migrations/0043_tenant_usage_monthly.ts +36 -0
- package/migrations/0044_provisioning_audit_log.ts +40 -0
- 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 +33 -21
- package/dist/src/db/queries/marketplace.js +0 -139
- package/dist/src/db/queries/marketplace.js.map +0 -10
- 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/marketplace.d.ts +0 -63
- package/dist/src/schemas/marketplace.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
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,15 +271,11 @@ 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;
|
|
275
|
+
tenant_usage_monthly: TenantUsageMonthlyTable;
|
|
276
|
+
tenant_compute_addons: TenantComputeAddonsTable;
|
|
277
|
+
account_spend_caps: AccountSpendCapsTable;
|
|
278
|
+
provisioning_audit_log: ProvisioningAuditLogTable;
|
|
362
279
|
}
|
|
363
280
|
type TenantStatus = "provisioning" | "active" | "suspended" | "error" | "deleted";
|
|
364
281
|
interface TenantsTable {
|
|
@@ -380,9 +297,9 @@ interface TenantsTable {
|
|
|
380
297
|
service_key_enc: Buffer;
|
|
381
298
|
api_url_internal: string;
|
|
382
299
|
api_url_public: string;
|
|
383
|
-
trial_ends_at: Date;
|
|
384
300
|
suspended_at: Date | null;
|
|
385
301
|
last_health_check_at: Date | null;
|
|
302
|
+
last_active_at: Generated<Date>;
|
|
386
303
|
service_gen: Generated<number>;
|
|
387
304
|
anon_gen: Generated<number>;
|
|
388
305
|
project_id: string | null;
|
|
@@ -392,30 +309,64 @@ interface TenantsTable {
|
|
|
392
309
|
type Tenant = Selectable<TenantsTable>;
|
|
393
310
|
type InsertTenant = Insertable<TenantsTable>;
|
|
394
311
|
type UpdateTenant = Updateable<TenantsTable>;
|
|
395
|
-
interface
|
|
312
|
+
interface TenantUsageMonthlyTable {
|
|
396
313
|
id: Generated<string>;
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
314
|
+
tenant_id: string;
|
|
315
|
+
period_month: Date;
|
|
316
|
+
storage_peak_mb: Generated<number>;
|
|
317
|
+
storage_avg_mb: Generated<number>;
|
|
318
|
+
storage_last_mb: Generated<number>;
|
|
319
|
+
measurements: Generated<number>;
|
|
320
|
+
first_at: Generated<Date>;
|
|
321
|
+
last_at: Generated<Date>;
|
|
322
|
+
}
|
|
323
|
+
type TenantUsageMonthly = Selectable<TenantUsageMonthlyTable>;
|
|
324
|
+
type InsertTenantUsageMonthly = Insertable<TenantUsageMonthlyTable>;
|
|
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;
|
|
407
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;
|
|
408
349
|
updated_at: Generated<Date>;
|
|
409
350
|
}
|
|
410
|
-
|
|
351
|
+
type AccountSpendCap = Selectable<AccountSpendCapsTable>;
|
|
352
|
+
type InsertAccountSpendCap = Insertable<AccountSpendCapsTable>;
|
|
353
|
+
type UpdateAccountSpendCap = Updateable<AccountSpendCapsTable>;
|
|
354
|
+
type ProvisioningAuditEvent = "provision.start" | "provision.success" | "provision.failure" | "suspend" | "resume" | "resize" | "keys.rotate" | "bastion.key.upload" | "bastion.key.revoke" | "teardown";
|
|
355
|
+
type ProvisioningAuditStatus = "ok" | "error";
|
|
356
|
+
interface ProvisioningAuditLogTable {
|
|
411
357
|
id: Generated<string>;
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
358
|
+
tenant_id: string | null;
|
|
359
|
+
tenant_slug: string | null;
|
|
360
|
+
account_id: string | null;
|
|
361
|
+
actor: string;
|
|
362
|
+
event: ProvisioningAuditEvent;
|
|
363
|
+
status: ProvisioningAuditStatus;
|
|
364
|
+
detail: unknown | null;
|
|
365
|
+
error: string | null;
|
|
416
366
|
created_at: Generated<Date>;
|
|
417
|
-
updated_at: Generated<Date>;
|
|
418
367
|
}
|
|
368
|
+
type ProvisioningAuditLog = Selectable<ProvisioningAuditLogTable>;
|
|
369
|
+
type InsertProvisioningAuditLog = Insertable<ProvisioningAuditLogTable>;
|
|
419
370
|
type Block = Selectable<BlocksTable>;
|
|
420
371
|
type InsertBlock = Insertable<BlocksTable>;
|
|
421
372
|
type UpdateBlock = Updateable<BlocksTable>;
|
|
@@ -452,27 +403,6 @@ type SubgraphGap = Selectable<SubgraphGapsTable>;
|
|
|
452
403
|
type InsertSubgraphGap = Insertable<SubgraphGapsTable>;
|
|
453
404
|
type SubgraphUsageDaily = Selectable<SubgraphUsageDailyTable>;
|
|
454
405
|
type InsertSubgraphUsageDaily = Insertable<SubgraphUsageDailyTable>;
|
|
455
|
-
type WorkflowDefinition = Selectable<WorkflowDefinitionsTable>;
|
|
456
|
-
type InsertWorkflowDefinition = Insertable<WorkflowDefinitionsTable>;
|
|
457
|
-
type UpdateWorkflowDefinition = Updateable<WorkflowDefinitionsTable>;
|
|
458
|
-
type WorkflowRun = Selectable<WorkflowRunsTable>;
|
|
459
|
-
type InsertWorkflowRun = Insertable<WorkflowRunsTable>;
|
|
460
|
-
type UpdateWorkflowRun = Updateable<WorkflowRunsTable>;
|
|
461
|
-
type WorkflowStep = Selectable<WorkflowStepsTable>;
|
|
462
|
-
type InsertWorkflowStep = Insertable<WorkflowStepsTable>;
|
|
463
|
-
type UpdateWorkflowStep = Updateable<WorkflowStepsTable>;
|
|
464
|
-
type WorkflowQueueItem = Selectable<WorkflowQueueTable>;
|
|
465
|
-
type InsertWorkflowQueueItem = Insertable<WorkflowQueueTable>;
|
|
466
|
-
type WorkflowSchedule = Selectable<WorkflowSchedulesTable>;
|
|
467
|
-
type InsertWorkflowSchedule = Insertable<WorkflowSchedulesTable>;
|
|
468
|
-
type UpdateWorkflowSchedule = Updateable<WorkflowSchedulesTable>;
|
|
469
|
-
type WorkflowCursor = Selectable<WorkflowCursorsTable>;
|
|
470
|
-
type WorkflowSignerSecret = Selectable<WorkflowSignerSecretsTable>;
|
|
471
|
-
type InsertWorkflowSignerSecret = Insertable<WorkflowSignerSecretsTable>;
|
|
472
|
-
type UpdateWorkflowSignerSecret = Updateable<WorkflowSignerSecretsTable>;
|
|
473
|
-
type WorkflowBudget = Selectable<WorkflowBudgetsTable>;
|
|
474
|
-
type InsertWorkflowBudget = Insertable<WorkflowBudgetsTable>;
|
|
475
|
-
type UpdateWorkflowBudget = Updateable<WorkflowBudgetsTable>;
|
|
476
406
|
type Project = Selectable<ProjectsTable>;
|
|
477
407
|
type InsertProject = Insertable<ProjectsTable>;
|
|
478
408
|
type UpdateProject = Updateable<ProjectsTable>;
|
|
@@ -485,4 +415,4 @@ type InsertChatSession = Insertable<ChatSessionsTable>;
|
|
|
485
415
|
type UpdateChatSession = Updateable<ChatSessionsTable>;
|
|
486
416
|
type ChatMessage = Selectable<ChatMessagesTable>;
|
|
487
417
|
type InsertChatMessage = Insertable<ChatMessagesTable>;
|
|
488
|
-
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": "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",
|
|
8
|
+
"debugId": "3D5A72D827A8C6D464756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|