@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.
Files changed (78) hide show
  1. package/README.md +2 -2
  2. package/dist/src/db/index.d.ts +64 -130
  3. package/dist/src/db/index.js.map +2 -2
  4. package/dist/src/db/jsonb.d.ts +5 -1
  5. package/dist/src/db/jsonb.js.map +2 -2
  6. package/dist/src/db/queries/account-spend-caps.d.ts +379 -0
  7. package/dist/src/db/queries/account-spend-caps.js +60 -0
  8. package/dist/src/db/queries/account-spend-caps.js.map +10 -0
  9. package/dist/src/db/queries/account-usage.d.ts +403 -0
  10. package/dist/src/db/queries/account-usage.js +222 -0
  11. package/dist/src/db/queries/account-usage.js.map +11 -0
  12. package/dist/src/db/queries/accounts.d.ts +61 -108
  13. package/dist/src/db/queries/accounts.js +15 -1
  14. package/dist/src/db/queries/accounts.js.map +3 -3
  15. package/dist/src/db/queries/integrity.d.ts +47 -107
  16. package/dist/src/db/queries/projects.d.ts +47 -107
  17. package/dist/src/db/queries/{workflows.d.ts → provisioning-audit.d.ts} +70 -142
  18. package/dist/src/db/queries/provisioning-audit.js +40 -0
  19. package/dist/src/db/queries/provisioning-audit.js.map +10 -0
  20. package/dist/src/db/queries/subgraph-gaps.d.ts +47 -107
  21. package/dist/src/db/queries/subgraphs.d.ts +47 -108
  22. package/dist/src/db/queries/subgraphs.js +2 -3
  23. package/dist/src/db/queries/subgraphs.js.map +4 -4
  24. package/dist/src/db/queries/{marketplace.d.ts → tenant-compute-addons.d.ts} +66 -159
  25. package/dist/src/db/queries/tenant-compute-addons.js +47 -0
  26. package/dist/src/db/queries/tenant-compute-addons.js.map +10 -0
  27. package/dist/src/db/queries/tenants.d.ts +67 -110
  28. package/dist/src/db/queries/tenants.js +35 -6
  29. package/dist/src/db/queries/tenants.js.map +3 -3
  30. package/dist/src/db/queries/usage.d.ts +48 -132
  31. package/dist/src/db/queries/usage.js +5 -64
  32. package/dist/src/db/queries/usage.js.map +4 -5
  33. package/dist/src/db/schema.d.ts +59 -129
  34. package/dist/src/errors.d.ts +8 -7
  35. package/dist/src/errors.js +11 -12
  36. package/dist/src/errors.js.map +3 -3
  37. package/dist/src/index.d.ts +98 -212
  38. package/dist/src/index.js +69 -80
  39. package/dist/src/index.js.map +6 -6
  40. package/dist/src/mode.d.ts +4 -5
  41. package/dist/src/mode.js.map +2 -2
  42. package/dist/src/node/local-client.d.ts +47 -107
  43. package/dist/src/pricing.d.ts +20 -1
  44. package/dist/src/pricing.js +58 -1
  45. package/dist/src/pricing.js.map +3 -3
  46. package/dist/src/schemas/accounts.d.ts +14 -0
  47. package/dist/src/schemas/{marketplace.js → accounts.js} +4 -14
  48. package/dist/src/schemas/accounts.js.map +10 -0
  49. package/dist/src/schemas/index.d.ts +28 -77
  50. package/dist/src/schemas/index.js +59 -69
  51. package/dist/src/schemas/index.js.map +4 -4
  52. package/migrations/0043_tenant_usage_monthly.ts +36 -0
  53. package/migrations/0044_provisioning_audit_log.ts +40 -0
  54. package/migrations/0045_drop_marketplace_columns.ts +47 -0
  55. package/migrations/0046_tenant_activity_signal.ts +47 -0
  56. package/migrations/0047_usage_daily_tenant_id.ts +73 -0
  57. package/migrations/0048_tenant_compute_addons.ts +49 -0
  58. package/migrations/0049_accounts_stripe_customer_id.ts +30 -0
  59. package/migrations/0050_account_spend_caps.ts +45 -0
  60. package/migrations/0051_workflow_ai_usage_daily.ts +40 -0
  61. package/migrations/0052_sentries.ts +61 -0
  62. package/migrations/0053_workflow_runtime.ts +88 -0
  63. package/migrations/0054_accounts_plan_hobby.ts +32 -0
  64. package/migrations/0055_ai_usage_account_scope.ts +108 -0
  65. package/migrations/0056_drop_workflow_sentry_residuals.ts +23 -0
  66. package/package.json +33 -21
  67. package/dist/src/db/queries/marketplace.js +0 -139
  68. package/dist/src/db/queries/marketplace.js.map +0 -10
  69. package/dist/src/db/queries/workflows.js +0 -260
  70. package/dist/src/db/queries/workflows.js.map +0 -12
  71. package/dist/src/lib/plans.d.ts +0 -9
  72. package/dist/src/lib/plans.js +0 -37
  73. package/dist/src/lib/plans.js.map +0 -10
  74. package/dist/src/schemas/marketplace.d.ts +0 -63
  75. package/dist/src/schemas/marketplace.js.map +0 -10
  76. package/dist/src/schemas/workflows.d.ts +0 -70
  77. package/dist/src/schemas/workflows.js +0 -43
  78. package/dist/src/schemas/workflows.js.map +0 -10
@@ -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 WorkflowBudgetsTable {
312
+ interface TenantUsageMonthlyTable {
313
+ id: Generated<string>;
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 {
396
327
  id: Generated<string>;
397
- workflow_definition_id: string;
398
- /** Period key: "daily:YYYY-MM-DD" | "weekly:YYYY-Www" | "per-run:<uuid>". */
399
- period: string;
400
- ai_usd_used: Generated<string>;
401
- ai_tokens_used: Generated<string>;
402
- chain_microstx_used: Generated<string>;
403
- chain_tx_count: Generated<number>;
404
- run_count: Generated<number>;
405
- step_count: Generated<number>;
406
- reset_at: Date;
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
- interface WorkflowSignerSecretsTable {
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
- account_id: string;
413
- name: string;
414
- /** AES-GCM ciphertext bytes produced by the runner's KMS on write. */
415
- encrypted_value: Buffer;
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>;
@@ -511,8 +441,12 @@ import { RawBuilder } from "kysely";
511
441
  * Safely encode a JS value as a JSONB literal for Kysely inserts/updates.
512
442
  * Kysely + postgres.js double-encodes JSON when using parameterized queries
513
443
  * with ::jsonb casts. This uses sql.raw to inline a properly escaped literal.
444
+ *
445
+ * Generic parameter lets callers set the RawBuilder's output type so they
446
+ * don't need to cast at the insert site. Default is `unknown` — widen at
447
+ * the call site when the column type is narrower, e.g. `jsonb<MyShape>(...)`.
514
448
  */
515
- declare function jsonb(value: unknown): RawBuilder<unknown>;
449
+ declare function jsonb<T = unknown>(value: T): RawBuilder<T>;
516
450
  /**
517
451
  * Safely parse a JSONB value from the database.
518
452
  * Handles double-encoded strings where postgres.js returns a JSON string
@@ -556,10 +490,10 @@ declare const ErrorCodes: {
556
490
  readonly VERSION_CONFLICT: "VERSION_CONFLICT"
557
491
  readonly NOT_FOUND: "NOT_FOUND"
558
492
  readonly KEY_ROTATED: "KEY_ROTATED"
559
- readonly TRIAL_EXPIRED: "TRIAL_EXPIRED"
560
493
  readonly TENANT_SUSPENDED: "TENANT_SUSPENDED"
561
494
  readonly NO_TENANT_FOR_PROJECT: "NO_TENANT_FOR_PROJECT"
562
495
  readonly INSTANCE_EXISTS: "INSTANCE_EXISTS"
496
+ readonly AI_CAP_REACHED: "AI_CAP_REACHED"
563
497
  };
564
498
  type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
565
499
  /** Base error class for all Secondlayer errors. */
@@ -604,16 +538,17 @@ declare class VersionConflictError extends SecondLayerError {
604
538
  declare class KeyRotatedError extends SecondLayerError {
605
539
  constructor(message?: string);
606
540
  }
607
- declare class TrialExpiredError extends SecondLayerError {
608
- constructor(message: string);
609
- }
610
541
  declare class TenantSuspendedError extends SecondLayerError {
611
542
  constructor(message?: string);
612
543
  }
544
+ /**\\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*/
545
+ declare class AiCapReachedError extends SecondLayerError {
546
+ constructor(message?: string);
547
+ }
613
548
  /** Error code → HTTP status. Used by API middleware for code-based matching
614
549
  * (avoids cross-bundle instanceof failures from bunup class duplication). */
615
- type MappedCode = Extract<ErrorCode, "AUTHENTICATION_ERROR" | "AUTHORIZATION_ERROR" | "RATE_LIMIT_ERROR" | "FORBIDDEN" | "NOT_FOUND" | "VALIDATION_ERROR" | "KEY_ROTATED" | "TRIAL_EXPIRED" | "TENANT_SUSPENDED" | "NO_TENANT_FOR_PROJECT" | "INSTANCE_EXISTS">;
616
- declare const CODE_TO_STATUS: Record<MappedCode, 400 | 401 | 402 | 403 | 404 | 409 | 423 | 429>;
550
+ 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">;
551
+ declare const CODE_TO_STATUS: Record<MappedCode, 400 | 401 | 403 | 404 | 409 | 423 | 429>;
617
552
  declare function getErrorMessage(err: unknown): string;
618
553
  declare class Logger {
619
554
  private _level?;
@@ -631,6 +566,19 @@ declare class Logger {
631
566
  }
632
567
  declare const logger: Logger;
633
568
  import { z as z2 } from "zod/v4";
569
+ /**
570
+ * Account profile shapes. Unrelated to marketplace — previously lived in
571
+ * schemas/marketplace.ts alongside public-directory types. Kept here now
572
+ * that marketplace is gone so the profile fields (display_name, bio, slug)
573
+ * have a stable home.
574
+ */
575
+ interface UpdateProfileRequest {
576
+ display_name?: string;
577
+ bio?: string;
578
+ slug?: string;
579
+ }
580
+ declare const UpdateProfileRequestSchema: z2.ZodType<UpdateProfileRequest>;
581
+ import { z as z3 } from "zod/v4";
634
582
  interface StxTransferFilter {
635
583
  type: "stx_transfer";
636
584
  sender?: string;
@@ -709,82 +657,20 @@ interface PrintEventFilter {
709
657
  contains?: string;
710
658
  }
711
659
  type EventFilter = StxTransferFilter | StxMintFilter | StxBurnFilter | StxLockFilter | FtTransferFilter | FtMintFilter | FtBurnFilter | NftTransferFilter | NftMintFilter | NftBurnFilter | ContractCallFilter | ContractDeployFilter | PrintEventFilter;
712
- declare const StxTransferFilterSchema: z2.ZodType<StxTransferFilter>;
713
- declare const StxMintFilterSchema: z2.ZodType<StxMintFilter>;
714
- declare const StxBurnFilterSchema: z2.ZodType<StxBurnFilter>;
715
- declare const StxLockFilterSchema: z2.ZodType<StxLockFilter>;
716
- declare const FtTransferFilterSchema: z2.ZodType<FtTransferFilter>;
717
- declare const FtMintFilterSchema: z2.ZodType<FtMintFilter>;
718
- declare const FtBurnFilterSchema: z2.ZodType<FtBurnFilter>;
719
- declare const NftTransferFilterSchema: z2.ZodType<NftTransferFilter>;
720
- declare const NftMintFilterSchema: z2.ZodType<NftMintFilter>;
721
- declare const NftBurnFilterSchema: z2.ZodType<NftBurnFilter>;
722
- declare const ContractCallFilterSchema: z2.ZodType<ContractCallFilter>;
723
- declare const ContractDeployFilterSchema: z2.ZodType<ContractDeployFilter>;
724
- declare const PrintEventFilterSchema: z2.ZodType<PrintEventFilter>;
725
- declare const EventFilterSchema: z2.ZodType<EventFilter>;
726
- import { z as z3 } from "zod/v4";
727
- interface PublishSubgraphRequest {
728
- tags?: string[];
729
- description?: string;
730
- }
731
- interface UpdateProfileRequest {
732
- display_name?: string;
733
- bio?: string;
734
- slug?: string;
735
- }
736
- interface ForkSubgraphRequest {
737
- sourceSubgraphName: string;
738
- newName?: string;
739
- }
740
- declare const PublishSubgraphRequestSchema: z3.ZodType<PublishSubgraphRequest>;
741
- declare const UpdateProfileRequestSchema: z3.ZodType<UpdateProfileRequest>;
742
- declare const ForkSubgraphRequestSchema: z3.ZodType<ForkSubgraphRequest>;
743
- interface MarketplaceCreator {
744
- displayName: string | null;
745
- slug: string | null;
746
- }
747
- interface MarketplaceSubgraphSummary {
748
- name: string;
749
- description: string | null;
750
- tags: string[];
751
- creator: MarketplaceCreator;
752
- status: string;
753
- version: string;
754
- tables: string[];
755
- totalQueries7d: number;
756
- progress: number;
757
- createdAt: string;
758
- }
759
- interface MarketplaceSubgraphDetail extends MarketplaceSubgraphSummary {
760
- tableSchemas: Record<string, {
761
- columns: Record<string, {
762
- type: string
763
- nullable?: boolean
764
- }>
765
- rowCount: number
766
- endpoint: string
767
- }>;
768
- sources: Record<string, unknown>;
769
- startBlock: number;
770
- lastProcessedBlock: number;
771
- forkedFrom: string | null;
772
- usage: {
773
- totalQueries7d: number
774
- totalQueries30d: number
775
- daily: Array<{
776
- date: string
777
- count: number
778
- }>
779
- };
780
- }
781
- interface CreatorProfile {
782
- displayName: string | null;
783
- bio: string | null;
784
- avatarUrl: string | null;
785
- slug: string | null;
786
- subgraphs: MarketplaceSubgraphSummary[];
787
- }
660
+ declare const StxTransferFilterSchema: z3.ZodType<StxTransferFilter>;
661
+ declare const StxMintFilterSchema: z3.ZodType<StxMintFilter>;
662
+ declare const StxBurnFilterSchema: z3.ZodType<StxBurnFilter>;
663
+ declare const StxLockFilterSchema: z3.ZodType<StxLockFilter>;
664
+ declare const FtTransferFilterSchema: z3.ZodType<FtTransferFilter>;
665
+ declare const FtMintFilterSchema: z3.ZodType<FtMintFilter>;
666
+ declare const FtBurnFilterSchema: z3.ZodType<FtBurnFilter>;
667
+ declare const NftTransferFilterSchema: z3.ZodType<NftTransferFilter>;
668
+ declare const NftMintFilterSchema: z3.ZodType<NftMintFilter>;
669
+ declare const NftBurnFilterSchema: z3.ZodType<NftBurnFilter>;
670
+ declare const ContractCallFilterSchema: z3.ZodType<ContractCallFilter>;
671
+ declare const ContractDeployFilterSchema: z3.ZodType<ContractDeployFilter>;
672
+ declare const PrintEventFilterSchema: z3.ZodType<PrintEventFilter>;
673
+ declare const EventFilterSchema: z3.ZodType<EventFilter>;
788
674
  import { z as z4 } from "zod/v4";
789
675
  interface DeploySubgraphRequest {
790
676
  name: string;
@@ -928,4 +814,4 @@ declare function createSignatureHeader(payload: string, secret: string, timestam
928
814
  * Returns true if valid, false otherwise
929
815
  */
930
816
  declare function verifySignatureHeader(payload: string, header: string, secret: string, toleranceSeconds?: number): boolean;
931
- export { sql, parseJsonb, logger, jsonb, getTargetDb, getSourceDb, getRawClient, getErrorMessage, getEnv, getDb, exports_hmac as crypto, closeDb, WorkflowStepsTable, WorkflowStep, WorkflowSignerSecretsTable, WorkflowSignerSecret, WorkflowSchedulesTable, WorkflowSchedule, WorkflowRunsTable, WorkflowRun, WorkflowQueueTable, WorkflowQueueItem, WorkflowDefinitionsTable, WorkflowDefinition, WorkflowCursorsTable, WorkflowCursor, WorkflowBudgetsTable, WorkflowBudget, WaitlistTable, VersionConflictError, ValidationError, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateWorkflowStep, UpdateWorkflowSignerSecret, UpdateWorkflowSchedule, UpdateWorkflowRun, UpdateWorkflowDefinition, UpdateWorkflowBudget, UpdateTransaction, UpdateTenant, UpdateSubgraph, UpdateProject, UpdateProfileRequestSchema, UpdateProfileRequest, UpdateIndexProgress, UpdateEvent, UpdateChatSession, UpdateBlock, UpdateApiKey, TrialExpiredError, TransactionsTable, Transaction, TenantsTable, TenantSuspendedError, TenantStatus, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubgraphsTable, SubgraphUsageDailyTable, SubgraphUsageDaily, SubgraphTableSnapshotsTable, SubgraphSyncInfo, SubgraphSummary, SubgraphQueryParams, SubgraphProcessingStatsTable, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGapsResponse, SubgraphGapRange, SubgraphGapEntry, SubgraphGap, SubgraphDetail, Subgraph, StxTransferFilterSchema, StxTransferFilter, StxMintFilterSchema, StxMintFilter, StxLockFilterSchema, StxLockFilter, StxBurnFilterSchema, StxBurnFilter, SessionsTable, Session, SecondLayerError, ReindexResponse, RateLimitError, PublishSubgraphRequestSchema, PublishSubgraphRequest, ProjectsTable, Project, PrintEventFilterSchema, PrintEventFilter, NotFoundError, NftTransferFilterSchema, NftTransferFilter, NftMintFilterSchema, NftMintFilter, NftBurnFilterSchema, NftBurnFilter, MarketplaceSubgraphSummary, MarketplaceSubgraphDetail, MarketplaceCreator, MagicLinksTable, MagicLink, KeyRotatedError, InsertWorkflowStep, InsertWorkflowSignerSecret, InsertWorkflowSchedule, InsertWorkflowRun, InsertWorkflowQueueItem, InsertWorkflowDefinition, InsertWorkflowBudget, InsertTransaction, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubgraphUsageDaily, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertProject, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertChatSession, InsertChatMessage, InsertBlock, InsertApiKey, InsertAccountInsight, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, FtTransferFilterSchema, FtTransferFilter, FtMintFilterSchema, FtMintFilter, FtBurnFilterSchema, FtBurnFilter, ForkSubgraphRequestSchema, ForkSubgraphRequest, ForbiddenError, EventsTable, EventFilterSchema, EventFilter, Event, ErrorCodes, ErrorCode, Env, DeploySubgraphResponse, DeploySubgraphRequestSchema, DeploySubgraphRequest, DatabaseError, Database, CreatorProfile, ContractDeployFilterSchema, ContractDeployFilter, ContractCallFilterSchema, ContractCallFilter, ChatSessionsTable, ChatSession, ChatMessagesTable, ChatMessage, CODE_TO_STATUS, BlocksTable, Block, AuthorizationError, AuthenticationError, ApiKeysTable, ApiKey, AccountsTable, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };
817
+ export { sql, parseJsonb, logger, jsonb, getTargetDb, getSourceDb, getRawClient, getErrorMessage, getEnv, getDb, exports_hmac as crypto, closeDb, WaitlistTable, VersionConflictError, ValidationError, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubgraph, UpdateProject, UpdateProfileRequestSchema, UpdateProfileRequest, UpdateIndexProgress, UpdateEvent, UpdateChatSession, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, TransactionsTable, Transaction, TenantsTable, TenantUsageMonthlyTable, TenantUsageMonthly, TenantSuspendedError, TenantStatus, TenantComputeAddonsTable, TenantComputeAddon, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubgraphsTable, SubgraphUsageDailyTable, SubgraphUsageDaily, SubgraphTableSnapshotsTable, SubgraphSyncInfo, SubgraphSummary, SubgraphQueryParams, SubgraphProcessingStatsTable, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGapsResponse, SubgraphGapRange, SubgraphGapEntry, SubgraphGap, SubgraphDetail, Subgraph, StxTransferFilterSchema, StxTransferFilter, StxMintFilterSchema, StxMintFilter, StxLockFilterSchema, StxLockFilter, StxBurnFilterSchema, StxBurnFilter, SessionsTable, Session, SecondLayerError, ReindexResponse, RateLimitError, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, PrintEventFilterSchema, PrintEventFilter, NotFoundError, NftTransferFilterSchema, NftTransferFilter, NftMintFilterSchema, NftMintFilter, NftBurnFilterSchema, NftBurnFilter, MagicLinksTable, MagicLink, KeyRotatedError, 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, FtTransferFilterSchema, FtTransferFilter, FtMintFilterSchema, FtMintFilter, FtBurnFilterSchema, FtBurnFilter, ForbiddenError, EventsTable, EventFilterSchema, EventFilter, Event, ErrorCodes, ErrorCode, Env, DeploySubgraphResponse, DeploySubgraphRequestSchema, DeploySubgraphRequest, DatabaseError, Database, ContractDeployFilterSchema, ContractDeployFilter, ContractCallFilterSchema, ContractCallFilter, ChatSessionsTable, ChatSession, ChatMessagesTable, ChatMessage, CODE_TO_STATUS, BlocksTable, Block, AuthorizationError, AuthenticationError, ApiKeysTable, ApiKey, AiCapReachedError, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountAgentRunsTable, AccountAgentRun, Account };
package/dist/src/index.js CHANGED
@@ -102,10 +102,10 @@ var ErrorCodes = {
102
102
  VERSION_CONFLICT: "VERSION_CONFLICT",
103
103
  NOT_FOUND: "NOT_FOUND",
104
104
  KEY_ROTATED: "KEY_ROTATED",
105
- TRIAL_EXPIRED: "TRIAL_EXPIRED",
106
105
  TENANT_SUSPENDED: "TENANT_SUSPENDED",
107
106
  NO_TENANT_FOR_PROJECT: "NO_TENANT_FOR_PROJECT",
108
- INSTANCE_EXISTS: "INSTANCE_EXISTS"
107
+ INSTANCE_EXISTS: "INSTANCE_EXISTS",
108
+ AI_CAP_REACHED: "AI_CAP_REACHED"
109
109
  };
110
110
 
111
111
  class SecondLayerError extends Error {
@@ -187,17 +187,17 @@ class KeyRotatedError extends SecondLayerError {
187
187
  }
188
188
  }
189
189
 
190
- class TrialExpiredError extends SecondLayerError {
191
- constructor(message) {
192
- super("TRIAL_EXPIRED", message);
193
- }
194
- }
195
-
196
190
  class TenantSuspendedError extends SecondLayerError {
197
191
  constructor(message = "Instance is suspended") {
198
192
  super("TENANT_SUSPENDED", message);
199
193
  }
200
194
  }
195
+
196
+ class AiCapReachedError extends SecondLayerError {
197
+ constructor(message = "Daily AI eval cap reached for this tenant's plan tier") {
198
+ super("AI_CAP_REACHED", message);
199
+ }
200
+ }
201
201
  var CODE_TO_STATUS = {
202
202
  AUTHENTICATION_ERROR: 401,
203
203
  AUTHORIZATION_ERROR: 403,
@@ -206,7 +206,6 @@ var CODE_TO_STATUS = {
206
206
  NOT_FOUND: 404,
207
207
  VALIDATION_ERROR: 400,
208
208
  KEY_ROTATED: 401,
209
- TRIAL_EXPIRED: 402,
210
209
  TENANT_SUSPENDED: 423,
211
210
  NO_TENANT_FOR_PROJECT: 404,
212
211
  INSTANCE_EXISTS: 409
@@ -330,11 +329,19 @@ class Logger {
330
329
  }
331
330
  var logger = new Logger;
332
331
 
332
+ // src/schemas/accounts.ts
333
+ import { z as z2 } from "zod/v4";
334
+ var UpdateProfileRequestSchema = z2.object({
335
+ display_name: z2.string().max(50).optional(),
336
+ bio: z2.string().max(300).optional(),
337
+ slug: z2.string().regex(/^[a-z0-9-]+$/, "lowercase alphanumeric + hyphens only").min(3).max(30).optional()
338
+ });
339
+
333
340
  // src/schemas/filters.ts
334
341
  import { isValidAddress as _isValidAddress } from "@secondlayer/stacks";
335
- import { z as z2 } from "zod/v4";
342
+ import { z as z3 } from "zod/v4";
336
343
  var isValidAddress = _isValidAddress;
337
- var stacksPrincipal = z2.string().refine((val) => {
344
+ var stacksPrincipal = z3.string().refine((val) => {
338
345
  const parts = val.split(".");
339
346
  if (parts.length > 2)
340
347
  return false;
@@ -344,81 +351,81 @@ var baseFilter = {
344
351
  sender: stacksPrincipal.optional(),
345
352
  recipient: stacksPrincipal.optional()
346
353
  };
347
- var StxTransferFilterSchema = z2.object({
348
- type: z2.literal("stx_transfer"),
354
+ var StxTransferFilterSchema = z3.object({
355
+ type: z3.literal("stx_transfer"),
349
356
  ...baseFilter,
350
- minAmount: z2.coerce.number().int().positive().optional(),
351
- maxAmount: z2.coerce.number().int().positive().optional()
357
+ minAmount: z3.coerce.number().int().positive().optional(),
358
+ maxAmount: z3.coerce.number().int().positive().optional()
352
359
  });
353
- var StxMintFilterSchema = z2.object({
354
- type: z2.literal("stx_mint"),
360
+ var StxMintFilterSchema = z3.object({
361
+ type: z3.literal("stx_mint"),
355
362
  recipient: stacksPrincipal.optional(),
356
- minAmount: z2.coerce.number().int().positive().optional()
363
+ minAmount: z3.coerce.number().int().positive().optional()
357
364
  });
358
- var StxBurnFilterSchema = z2.object({
359
- type: z2.literal("stx_burn"),
365
+ var StxBurnFilterSchema = z3.object({
366
+ type: z3.literal("stx_burn"),
360
367
  sender: stacksPrincipal.optional(),
361
- minAmount: z2.coerce.number().int().positive().optional()
368
+ minAmount: z3.coerce.number().int().positive().optional()
362
369
  });
363
- var StxLockFilterSchema = z2.object({
364
- type: z2.literal("stx_lock"),
370
+ var StxLockFilterSchema = z3.object({
371
+ type: z3.literal("stx_lock"),
365
372
  lockedAddress: stacksPrincipal.optional(),
366
- minAmount: z2.coerce.number().int().positive().optional()
373
+ minAmount: z3.coerce.number().int().positive().optional()
367
374
  });
368
- var FtTransferFilterSchema = z2.object({
369
- type: z2.literal("ft_transfer"),
375
+ var FtTransferFilterSchema = z3.object({
376
+ type: z3.literal("ft_transfer"),
370
377
  ...baseFilter,
371
- assetIdentifier: z2.string().optional(),
372
- minAmount: z2.coerce.number().int().positive().optional()
378
+ assetIdentifier: z3.string().optional(),
379
+ minAmount: z3.coerce.number().int().positive().optional()
373
380
  });
374
- var FtMintFilterSchema = z2.object({
375
- type: z2.literal("ft_mint"),
381
+ var FtMintFilterSchema = z3.object({
382
+ type: z3.literal("ft_mint"),
376
383
  recipient: stacksPrincipal.optional(),
377
- assetIdentifier: z2.string().optional(),
378
- minAmount: z2.coerce.number().int().positive().optional()
384
+ assetIdentifier: z3.string().optional(),
385
+ minAmount: z3.coerce.number().int().positive().optional()
379
386
  });
380
- var FtBurnFilterSchema = z2.object({
381
- type: z2.literal("ft_burn"),
387
+ var FtBurnFilterSchema = z3.object({
388
+ type: z3.literal("ft_burn"),
382
389
  sender: stacksPrincipal.optional(),
383
- assetIdentifier: z2.string().optional(),
384
- minAmount: z2.coerce.number().int().positive().optional()
390
+ assetIdentifier: z3.string().optional(),
391
+ minAmount: z3.coerce.number().int().positive().optional()
385
392
  });
386
- var NftTransferFilterSchema = z2.object({
387
- type: z2.literal("nft_transfer"),
393
+ var NftTransferFilterSchema = z3.object({
394
+ type: z3.literal("nft_transfer"),
388
395
  ...baseFilter,
389
- assetIdentifier: z2.string().optional(),
390
- tokenId: z2.string().optional()
396
+ assetIdentifier: z3.string().optional(),
397
+ tokenId: z3.string().optional()
391
398
  });
392
- var NftMintFilterSchema = z2.object({
393
- type: z2.literal("nft_mint"),
399
+ var NftMintFilterSchema = z3.object({
400
+ type: z3.literal("nft_mint"),
394
401
  recipient: stacksPrincipal.optional(),
395
- assetIdentifier: z2.string().optional(),
396
- tokenId: z2.string().optional()
402
+ assetIdentifier: z3.string().optional(),
403
+ tokenId: z3.string().optional()
397
404
  });
398
- var NftBurnFilterSchema = z2.object({
399
- type: z2.literal("nft_burn"),
405
+ var NftBurnFilterSchema = z3.object({
406
+ type: z3.literal("nft_burn"),
400
407
  sender: stacksPrincipal.optional(),
401
- assetIdentifier: z2.string().optional(),
402
- tokenId: z2.string().optional()
408
+ assetIdentifier: z3.string().optional(),
409
+ tokenId: z3.string().optional()
403
410
  });
404
- var ContractCallFilterSchema = z2.object({
405
- type: z2.literal("contract_call"),
411
+ var ContractCallFilterSchema = z3.object({
412
+ type: z3.literal("contract_call"),
406
413
  contractId: stacksPrincipal.optional(),
407
- functionName: z2.string().optional(),
414
+ functionName: z3.string().optional(),
408
415
  caller: stacksPrincipal.optional()
409
416
  });
410
- var ContractDeployFilterSchema = z2.object({
411
- type: z2.literal("contract_deploy"),
417
+ var ContractDeployFilterSchema = z3.object({
418
+ type: z3.literal("contract_deploy"),
412
419
  deployer: stacksPrincipal.optional(),
413
- contractName: z2.string().optional()
420
+ contractName: z3.string().optional()
414
421
  });
415
- var PrintEventFilterSchema = z2.object({
416
- type: z2.literal("print_event"),
422
+ var PrintEventFilterSchema = z3.object({
423
+ type: z3.literal("print_event"),
417
424
  contractId: stacksPrincipal.optional(),
418
- topic: z2.string().optional(),
419
- contains: z2.string().optional()
425
+ topic: z3.string().optional(),
426
+ contains: z3.string().optional()
420
427
  });
421
- var EventFilterSchema = z2.discriminatedUnion("type", [
428
+ var EventFilterSchema = z3.discriminatedUnion("type", [
422
429
  StxTransferFilterSchema,
423
430
  StxMintFilterSchema,
424
431
  StxBurnFilterSchema,
@@ -434,22 +441,6 @@ var EventFilterSchema = z2.discriminatedUnion("type", [
434
441
  PrintEventFilterSchema
435
442
  ]);
436
443
 
437
- // src/schemas/marketplace.ts
438
- import { z as z3 } from "zod/v4";
439
- var PublishSubgraphRequestSchema = z3.object({
440
- tags: z3.array(z3.string().max(30)).max(5).optional(),
441
- description: z3.string().max(500).optional()
442
- });
443
- var UpdateProfileRequestSchema = z3.object({
444
- display_name: z3.string().max(50).optional(),
445
- bio: z3.string().max(300).optional(),
446
- slug: z3.string().regex(/^[a-z0-9-]+$/, "lowercase alphanumeric + hyphens only").min(3).max(30).optional()
447
- });
448
- var ForkSubgraphRequestSchema = z3.object({
449
- sourceSubgraphName: z3.string(),
450
- newName: z3.string().regex(/^[a-z0-9-]+$/, "lowercase alphanumeric + hyphens only").max(63).optional()
451
- });
452
-
453
444
  // src/schemas/subgraphs.ts
454
445
  import { z as z4 } from "zod/v4";
455
446
  var DeploySubgraphRequestSchema = z4.object({
@@ -531,7 +522,6 @@ export {
531
522
  VersionConflictError,
532
523
  ValidationError,
533
524
  UpdateProfileRequestSchema,
534
- TrialExpiredError,
535
525
  TenantSuspendedError,
536
526
  StxTransferFilterSchema,
537
527
  StxMintFilterSchema,
@@ -539,7 +529,6 @@ export {
539
529
  StxBurnFilterSchema,
540
530
  SecondLayerError,
541
531
  RateLimitError,
542
- PublishSubgraphRequestSchema,
543
532
  PrintEventFilterSchema,
544
533
  NotFoundError,
545
534
  NftTransferFilterSchema,
@@ -549,7 +538,6 @@ export {
549
538
  FtTransferFilterSchema,
550
539
  FtMintFilterSchema,
551
540
  FtBurnFilterSchema,
552
- ForkSubgraphRequestSchema,
553
541
  ForbiddenError,
554
542
  EventFilterSchema,
555
543
  ErrorCodes,
@@ -559,8 +547,9 @@ export {
559
547
  ContractCallFilterSchema,
560
548
  CODE_TO_STATUS,
561
549
  AuthorizationError,
562
- AuthenticationError
550
+ AuthenticationError,
551
+ AiCapReachedError
563
552
  };
564
553
 
565
- //# debugId=C27B5257F4D1169564756E2164756E21
554
+ //# debugId=F8EF00979875546E64756E2164756E21
566
555
  //# sourceMappingURL=index.js.map