@secondlayer/shared 3.0.0-alpha.0 → 3.0.0-beta.1
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/dist/src/crypto/secrets.js +47 -3
- package/dist/src/crypto/secrets.js.map +5 -4
- package/dist/src/db/index.d.ts +74 -1
- package/dist/src/db/queries/account-spend-caps.d.ts +65 -0
- package/dist/src/db/queries/account-usage.d.ts +65 -0
- package/dist/src/db/queries/accounts.d.ts +65 -0
- package/dist/src/db/queries/integrity.d.ts +65 -0
- package/dist/src/db/queries/projects.d.ts +65 -0
- package/dist/src/db/queries/provisioning-audit.d.ts +65 -0
- package/dist/src/db/queries/subgraph-gaps.d.ts +65 -0
- package/dist/src/db/queries/subgraphs.d.ts +65 -0
- package/dist/src/db/queries/tenant-compute-addons.d.ts +65 -0
- package/dist/src/db/queries/tenants.d.ts +65 -0
- package/dist/src/db/queries/tenants.js +47 -3
- package/dist/src/db/queries/tenants.js.map +5 -4
- package/dist/src/db/queries/usage.d.ts +65 -0
- package/dist/src/db/schema.d.ts +74 -1
- package/dist/src/index.d.ts +74 -1
- package/dist/src/node/local-client.d.ts +65 -0
- package/migrations/0057_subscriptions.ts +137 -0
- package/package.json +1 -1
package/dist/src/db/schema.d.ts
CHANGED
|
@@ -276,6 +276,9 @@ interface Database {
|
|
|
276
276
|
tenant_compute_addons: TenantComputeAddonsTable;
|
|
277
277
|
account_spend_caps: AccountSpendCapsTable;
|
|
278
278
|
provisioning_audit_log: ProvisioningAuditLogTable;
|
|
279
|
+
subscriptions: SubscriptionsTable;
|
|
280
|
+
subscription_outbox: SubscriptionOutboxTable;
|
|
281
|
+
subscription_deliveries: SubscriptionDeliveriesTable;
|
|
279
282
|
}
|
|
280
283
|
type TenantStatus = "provisioning" | "active" | "suspended" | "error" | "deleted";
|
|
281
284
|
interface TenantsTable {
|
|
@@ -415,4 +418,74 @@ type InsertChatSession = Insertable<ChatSessionsTable>;
|
|
|
415
418
|
type UpdateChatSession = Updateable<ChatSessionsTable>;
|
|
416
419
|
type ChatMessage = Selectable<ChatMessagesTable>;
|
|
417
420
|
type InsertChatMessage = Insertable<ChatMessagesTable>;
|
|
418
|
-
|
|
421
|
+
type SubscriptionStatus = "active" | "paused" | "error";
|
|
422
|
+
type SubscriptionFormat = "standard-webhooks" | "inngest" | "trigger" | "cloudflare" | "cloudevents" | "raw";
|
|
423
|
+
type SubscriptionRuntime = "inngest" | "trigger" | "cloudflare" | "node";
|
|
424
|
+
interface SubscriptionsTable {
|
|
425
|
+
id: Generated<string>;
|
|
426
|
+
account_id: string;
|
|
427
|
+
project_id: string | null;
|
|
428
|
+
name: string;
|
|
429
|
+
status: ColumnType<SubscriptionStatus, SubscriptionStatus | undefined, SubscriptionStatus>;
|
|
430
|
+
subgraph_name: string;
|
|
431
|
+
table_name: string;
|
|
432
|
+
filter: Generated<unknown>;
|
|
433
|
+
format: ColumnType<SubscriptionFormat, SubscriptionFormat | undefined, SubscriptionFormat>;
|
|
434
|
+
runtime: SubscriptionRuntime | null;
|
|
435
|
+
url: string;
|
|
436
|
+
signing_secret_enc: Buffer;
|
|
437
|
+
auth_config: Generated<unknown>;
|
|
438
|
+
max_retries: Generated<number>;
|
|
439
|
+
timeout_ms: Generated<number>;
|
|
440
|
+
concurrency: Generated<number>;
|
|
441
|
+
circuit_failures: Generated<number>;
|
|
442
|
+
circuit_opened_at: Date | null;
|
|
443
|
+
last_delivery_at: Date | null;
|
|
444
|
+
last_success_at: Date | null;
|
|
445
|
+
last_error: string | null;
|
|
446
|
+
created_at: Generated<Date>;
|
|
447
|
+
updated_at: Generated<Date>;
|
|
448
|
+
}
|
|
449
|
+
type Subscription = Selectable<SubscriptionsTable>;
|
|
450
|
+
type InsertSubscription = Insertable<SubscriptionsTable>;
|
|
451
|
+
type UpdateSubscription = Updateable<SubscriptionsTable>;
|
|
452
|
+
type OutboxStatus = "pending" | "delivered" | "dead";
|
|
453
|
+
interface SubscriptionOutboxTable {
|
|
454
|
+
id: Generated<string>;
|
|
455
|
+
subscription_id: string;
|
|
456
|
+
subgraph_name: string;
|
|
457
|
+
table_name: string;
|
|
458
|
+
block_height: number | bigint;
|
|
459
|
+
tx_id: string | null;
|
|
460
|
+
row_pk: unknown;
|
|
461
|
+
event_type: string;
|
|
462
|
+
payload: unknown;
|
|
463
|
+
dedup_key: string;
|
|
464
|
+
attempt: Generated<number>;
|
|
465
|
+
next_attempt_at: Generated<Date>;
|
|
466
|
+
status: ColumnType<OutboxStatus, OutboxStatus | undefined, OutboxStatus>;
|
|
467
|
+
is_replay: Generated<boolean>;
|
|
468
|
+
delivered_at: Date | null;
|
|
469
|
+
failed_at: Date | null;
|
|
470
|
+
locked_by: string | null;
|
|
471
|
+
locked_until: Date | null;
|
|
472
|
+
created_at: Generated<Date>;
|
|
473
|
+
}
|
|
474
|
+
type SubscriptionOutbox = Selectable<SubscriptionOutboxTable>;
|
|
475
|
+
type InsertSubscriptionOutbox = Insertable<SubscriptionOutboxTable>;
|
|
476
|
+
type UpdateSubscriptionOutbox = Updateable<SubscriptionOutboxTable>;
|
|
477
|
+
interface SubscriptionDeliveriesTable {
|
|
478
|
+
id: Generated<string>;
|
|
479
|
+
outbox_id: string;
|
|
480
|
+
subscription_id: string;
|
|
481
|
+
attempt: number;
|
|
482
|
+
status_code: number | null;
|
|
483
|
+
response_headers: unknown | null;
|
|
484
|
+
response_body: string | null;
|
|
485
|
+
error_message: string | null;
|
|
486
|
+
duration_ms: number | null;
|
|
487
|
+
dispatched_at: Generated<Date>;
|
|
488
|
+
}
|
|
489
|
+
type SubscriptionDelivery = Selectable<SubscriptionDeliveriesTable>;
|
|
490
|
+
type InsertSubscriptionDelivery = Insertable<SubscriptionDeliveriesTable>;
|
|
491
|
+
export { WaitlistTable, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraph, UpdateProject, UpdateIndexProgress, UpdateEvent, UpdateChatSession, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, TransactionsTable, Transaction, TenantsTable, TenantUsageMonthlyTable, TenantUsageMonthly, TenantStatus, TenantComputeAddonsTable, TenantComputeAddon, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubscriptionsTable, SubscriptionStatus, SubscriptionRuntime, SubscriptionOutboxTable, SubscriptionOutbox, SubscriptionFormat, SubscriptionDelivery, SubscriptionDeliveriesTable, Subscription, SubgraphsTable, SubgraphUsageDailyTable, SubgraphUsageDaily, SubgraphTableSnapshotsTable, SubgraphProcessingStatsTable, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGap, Subgraph, SessionsTable, Session, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, OutboxStatus, MagicLinksTable, MagicLink, InsertTransaction, InsertTenantUsageMonthly, InsertTenantComputeAddon, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubscriptionOutbox, InsertSubscriptionDelivery, InsertSubscription, 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/index.d.ts
CHANGED
|
@@ -276,6 +276,9 @@ interface Database {
|
|
|
276
276
|
tenant_compute_addons: TenantComputeAddonsTable;
|
|
277
277
|
account_spend_caps: AccountSpendCapsTable;
|
|
278
278
|
provisioning_audit_log: ProvisioningAuditLogTable;
|
|
279
|
+
subscriptions: SubscriptionsTable;
|
|
280
|
+
subscription_outbox: SubscriptionOutboxTable;
|
|
281
|
+
subscription_deliveries: SubscriptionDeliveriesTable;
|
|
279
282
|
}
|
|
280
283
|
type TenantStatus = "provisioning" | "active" | "suspended" | "error" | "deleted";
|
|
281
284
|
interface TenantsTable {
|
|
@@ -415,6 +418,76 @@ type InsertChatSession = Insertable<ChatSessionsTable>;
|
|
|
415
418
|
type UpdateChatSession = Updateable<ChatSessionsTable>;
|
|
416
419
|
type ChatMessage = Selectable<ChatMessagesTable>;
|
|
417
420
|
type InsertChatMessage = Insertable<ChatMessagesTable>;
|
|
421
|
+
type SubscriptionStatus = "active" | "paused" | "error";
|
|
422
|
+
type SubscriptionFormat = "standard-webhooks" | "inngest" | "trigger" | "cloudflare" | "cloudevents" | "raw";
|
|
423
|
+
type SubscriptionRuntime = "inngest" | "trigger" | "cloudflare" | "node";
|
|
424
|
+
interface SubscriptionsTable {
|
|
425
|
+
id: Generated<string>;
|
|
426
|
+
account_id: string;
|
|
427
|
+
project_id: string | null;
|
|
428
|
+
name: string;
|
|
429
|
+
status: ColumnType<SubscriptionStatus, SubscriptionStatus | undefined, SubscriptionStatus>;
|
|
430
|
+
subgraph_name: string;
|
|
431
|
+
table_name: string;
|
|
432
|
+
filter: Generated<unknown>;
|
|
433
|
+
format: ColumnType<SubscriptionFormat, SubscriptionFormat | undefined, SubscriptionFormat>;
|
|
434
|
+
runtime: SubscriptionRuntime | null;
|
|
435
|
+
url: string;
|
|
436
|
+
signing_secret_enc: Buffer;
|
|
437
|
+
auth_config: Generated<unknown>;
|
|
438
|
+
max_retries: Generated<number>;
|
|
439
|
+
timeout_ms: Generated<number>;
|
|
440
|
+
concurrency: Generated<number>;
|
|
441
|
+
circuit_failures: Generated<number>;
|
|
442
|
+
circuit_opened_at: Date | null;
|
|
443
|
+
last_delivery_at: Date | null;
|
|
444
|
+
last_success_at: Date | null;
|
|
445
|
+
last_error: string | null;
|
|
446
|
+
created_at: Generated<Date>;
|
|
447
|
+
updated_at: Generated<Date>;
|
|
448
|
+
}
|
|
449
|
+
type Subscription = Selectable<SubscriptionsTable>;
|
|
450
|
+
type InsertSubscription = Insertable<SubscriptionsTable>;
|
|
451
|
+
type UpdateSubscription = Updateable<SubscriptionsTable>;
|
|
452
|
+
type OutboxStatus = "pending" | "delivered" | "dead";
|
|
453
|
+
interface SubscriptionOutboxTable {
|
|
454
|
+
id: Generated<string>;
|
|
455
|
+
subscription_id: string;
|
|
456
|
+
subgraph_name: string;
|
|
457
|
+
table_name: string;
|
|
458
|
+
block_height: number | bigint;
|
|
459
|
+
tx_id: string | null;
|
|
460
|
+
row_pk: unknown;
|
|
461
|
+
event_type: string;
|
|
462
|
+
payload: unknown;
|
|
463
|
+
dedup_key: string;
|
|
464
|
+
attempt: Generated<number>;
|
|
465
|
+
next_attempt_at: Generated<Date>;
|
|
466
|
+
status: ColumnType<OutboxStatus, OutboxStatus | undefined, OutboxStatus>;
|
|
467
|
+
is_replay: Generated<boolean>;
|
|
468
|
+
delivered_at: Date | null;
|
|
469
|
+
failed_at: Date | null;
|
|
470
|
+
locked_by: string | null;
|
|
471
|
+
locked_until: Date | null;
|
|
472
|
+
created_at: Generated<Date>;
|
|
473
|
+
}
|
|
474
|
+
type SubscriptionOutbox = Selectable<SubscriptionOutboxTable>;
|
|
475
|
+
type InsertSubscriptionOutbox = Insertable<SubscriptionOutboxTable>;
|
|
476
|
+
type UpdateSubscriptionOutbox = Updateable<SubscriptionOutboxTable>;
|
|
477
|
+
interface SubscriptionDeliveriesTable {
|
|
478
|
+
id: Generated<string>;
|
|
479
|
+
outbox_id: string;
|
|
480
|
+
subscription_id: string;
|
|
481
|
+
attempt: number;
|
|
482
|
+
status_code: number | null;
|
|
483
|
+
response_headers: unknown | null;
|
|
484
|
+
response_body: string | null;
|
|
485
|
+
error_message: string | null;
|
|
486
|
+
duration_ms: number | null;
|
|
487
|
+
dispatched_at: Generated<Date>;
|
|
488
|
+
}
|
|
489
|
+
type SubscriptionDelivery = Selectable<SubscriptionDeliveriesTable>;
|
|
490
|
+
type InsertSubscriptionDelivery = Insertable<SubscriptionDeliveriesTable>;
|
|
418
491
|
interface EnvSchemaOutput {
|
|
419
492
|
DATABASE_URL?: string;
|
|
420
493
|
/**
|
|
@@ -814,4 +887,4 @@ declare function createSignatureHeader(payload: string, secret: string, timestam
|
|
|
814
887
|
* Returns true if valid, false otherwise
|
|
815
888
|
*/
|
|
816
889
|
declare function verifySignatureHeader(payload: string, header: string, secret: string, toleranceSeconds?: number): boolean;
|
|
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 };
|
|
890
|
+
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, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraph, UpdateProject, UpdateProfileRequestSchema, UpdateProfileRequest, UpdateIndexProgress, UpdateEvent, UpdateChatSession, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, TransactionsTable, Transaction, TenantsTable, TenantUsageMonthlyTable, TenantUsageMonthly, TenantSuspendedError, TenantStatus, TenantComputeAddonsTable, TenantComputeAddon, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubscriptionsTable, SubscriptionStatus, SubscriptionRuntime, SubscriptionOutboxTable, SubscriptionOutbox, SubscriptionFormat, SubscriptionDelivery, SubscriptionDeliveriesTable, Subscription, 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, OutboxStatus, NotFoundError, NftTransferFilterSchema, NftTransferFilter, NftMintFilterSchema, NftMintFilter, NftBurnFilterSchema, NftBurnFilter, MagicLinksTable, MagicLink, KeyRotatedError, InsertTransaction, InsertTenantUsageMonthly, InsertTenantComputeAddon, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubscriptionOutbox, InsertSubscriptionDelivery, InsertSubscription, 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 };
|
|
@@ -277,6 +277,9 @@ interface Database {
|
|
|
277
277
|
tenant_compute_addons: TenantComputeAddonsTable;
|
|
278
278
|
account_spend_caps: AccountSpendCapsTable;
|
|
279
279
|
provisioning_audit_log: ProvisioningAuditLogTable;
|
|
280
|
+
subscriptions: SubscriptionsTable;
|
|
281
|
+
subscription_outbox: SubscriptionOutboxTable;
|
|
282
|
+
subscription_deliveries: SubscriptionDeliveriesTable;
|
|
280
283
|
}
|
|
281
284
|
type TenantStatus = "provisioning" | "active" | "suspended" | "error" | "deleted";
|
|
282
285
|
interface TenantsTable {
|
|
@@ -354,6 +357,68 @@ interface ProvisioningAuditLogTable {
|
|
|
354
357
|
error: string | null;
|
|
355
358
|
created_at: Generated<Date>;
|
|
356
359
|
}
|
|
360
|
+
type SubscriptionStatus = "active" | "paused" | "error";
|
|
361
|
+
type SubscriptionFormat = "standard-webhooks" | "inngest" | "trigger" | "cloudflare" | "cloudevents" | "raw";
|
|
362
|
+
type SubscriptionRuntime = "inngest" | "trigger" | "cloudflare" | "node";
|
|
363
|
+
interface SubscriptionsTable {
|
|
364
|
+
id: Generated<string>;
|
|
365
|
+
account_id: string;
|
|
366
|
+
project_id: string | null;
|
|
367
|
+
name: string;
|
|
368
|
+
status: ColumnType<SubscriptionStatus, SubscriptionStatus | undefined, SubscriptionStatus>;
|
|
369
|
+
subgraph_name: string;
|
|
370
|
+
table_name: string;
|
|
371
|
+
filter: Generated<unknown>;
|
|
372
|
+
format: ColumnType<SubscriptionFormat, SubscriptionFormat | undefined, SubscriptionFormat>;
|
|
373
|
+
runtime: SubscriptionRuntime | null;
|
|
374
|
+
url: string;
|
|
375
|
+
signing_secret_enc: Buffer;
|
|
376
|
+
auth_config: Generated<unknown>;
|
|
377
|
+
max_retries: Generated<number>;
|
|
378
|
+
timeout_ms: Generated<number>;
|
|
379
|
+
concurrency: Generated<number>;
|
|
380
|
+
circuit_failures: Generated<number>;
|
|
381
|
+
circuit_opened_at: Date | null;
|
|
382
|
+
last_delivery_at: Date | null;
|
|
383
|
+
last_success_at: Date | null;
|
|
384
|
+
last_error: string | null;
|
|
385
|
+
created_at: Generated<Date>;
|
|
386
|
+
updated_at: Generated<Date>;
|
|
387
|
+
}
|
|
388
|
+
type OutboxStatus = "pending" | "delivered" | "dead";
|
|
389
|
+
interface SubscriptionOutboxTable {
|
|
390
|
+
id: Generated<string>;
|
|
391
|
+
subscription_id: string;
|
|
392
|
+
subgraph_name: string;
|
|
393
|
+
table_name: string;
|
|
394
|
+
block_height: number | bigint;
|
|
395
|
+
tx_id: string | null;
|
|
396
|
+
row_pk: unknown;
|
|
397
|
+
event_type: string;
|
|
398
|
+
payload: unknown;
|
|
399
|
+
dedup_key: string;
|
|
400
|
+
attempt: Generated<number>;
|
|
401
|
+
next_attempt_at: Generated<Date>;
|
|
402
|
+
status: ColumnType<OutboxStatus, OutboxStatus | undefined, OutboxStatus>;
|
|
403
|
+
is_replay: Generated<boolean>;
|
|
404
|
+
delivered_at: Date | null;
|
|
405
|
+
failed_at: Date | null;
|
|
406
|
+
locked_by: string | null;
|
|
407
|
+
locked_until: Date | null;
|
|
408
|
+
created_at: Generated<Date>;
|
|
409
|
+
}
|
|
410
|
+
interface SubscriptionDeliveriesTable {
|
|
411
|
+
id: Generated<string>;
|
|
412
|
+
outbox_id: string;
|
|
413
|
+
subscription_id: string;
|
|
414
|
+
attempt: number;
|
|
415
|
+
status_code: number | null;
|
|
416
|
+
response_headers: unknown | null;
|
|
417
|
+
response_body: string | null;
|
|
418
|
+
error_message: string | null;
|
|
419
|
+
duration_ms: number | null;
|
|
420
|
+
dispatched_at: Generated<Date>;
|
|
421
|
+
}
|
|
357
422
|
/** Matches the NewBlockPayload shape expected by the indexer's /new_block endpoint */
|
|
358
423
|
interface ReplayBlockPayload {
|
|
359
424
|
block_hash: string;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Subgraph event subscriptions — the new core surface after the workflow pivot.
|
|
5
|
+
*
|
|
6
|
+
* Three tables:
|
|
7
|
+
* - `subscriptions`: user-facing configuration. One row per subscription.
|
|
8
|
+
* - `subscription_outbox`: exactly-once emission ledger. Inserted inside the
|
|
9
|
+
* same tx as the row write, drained by the emitter worker.
|
|
10
|
+
* - `subscription_deliveries`: per-attempt HTTP dispatch log. Truncated
|
|
11
|
+
* response bodies + status code for UI + retention.
|
|
12
|
+
*
|
|
13
|
+
* Trigger `subscription_outbox_notify` fires `pg_notify('subscriptions:new_outbox', <sub_id>)`
|
|
14
|
+
* on insert so the emitter can wake without polling.
|
|
15
|
+
*/
|
|
16
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
17
|
+
await sql`
|
|
18
|
+
CREATE TABLE subscriptions (
|
|
19
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
20
|
+
account_id UUID NOT NULL,
|
|
21
|
+
project_id UUID,
|
|
22
|
+
name TEXT NOT NULL,
|
|
23
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
24
|
+
subgraph_name TEXT NOT NULL,
|
|
25
|
+
table_name TEXT NOT NULL,
|
|
26
|
+
filter JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
27
|
+
format TEXT NOT NULL DEFAULT 'standard-webhooks',
|
|
28
|
+
runtime TEXT,
|
|
29
|
+
url TEXT NOT NULL,
|
|
30
|
+
signing_secret_enc BYTEA NOT NULL,
|
|
31
|
+
auth_config JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
32
|
+
max_retries INT NOT NULL DEFAULT 7,
|
|
33
|
+
timeout_ms INT NOT NULL DEFAULT 10000,
|
|
34
|
+
concurrency INT NOT NULL DEFAULT 4,
|
|
35
|
+
circuit_failures INT NOT NULL DEFAULT 0,
|
|
36
|
+
circuit_opened_at TIMESTAMPTZ,
|
|
37
|
+
last_delivery_at TIMESTAMPTZ,
|
|
38
|
+
last_success_at TIMESTAMPTZ,
|
|
39
|
+
last_error TEXT,
|
|
40
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
41
|
+
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
42
|
+
UNIQUE (account_id, name)
|
|
43
|
+
)
|
|
44
|
+
`.execute(db);
|
|
45
|
+
|
|
46
|
+
await sql`
|
|
47
|
+
CREATE INDEX subscriptions_matcher_idx
|
|
48
|
+
ON subscriptions (subgraph_name, table_name, status)
|
|
49
|
+
WHERE status = 'active'
|
|
50
|
+
`.execute(db);
|
|
51
|
+
|
|
52
|
+
await sql`
|
|
53
|
+
CREATE INDEX subscriptions_account_idx ON subscriptions (account_id)
|
|
54
|
+
`.execute(db);
|
|
55
|
+
|
|
56
|
+
await sql`
|
|
57
|
+
CREATE TABLE subscription_outbox (
|
|
58
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
59
|
+
subscription_id UUID NOT NULL REFERENCES subscriptions(id) ON DELETE CASCADE,
|
|
60
|
+
subgraph_name TEXT NOT NULL,
|
|
61
|
+
table_name TEXT NOT NULL,
|
|
62
|
+
block_height BIGINT NOT NULL,
|
|
63
|
+
tx_id TEXT,
|
|
64
|
+
row_pk JSONB NOT NULL,
|
|
65
|
+
event_type TEXT NOT NULL,
|
|
66
|
+
payload JSONB NOT NULL,
|
|
67
|
+
dedup_key TEXT NOT NULL,
|
|
68
|
+
attempt INT NOT NULL DEFAULT 0,
|
|
69
|
+
next_attempt_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
70
|
+
status TEXT NOT NULL DEFAULT 'pending',
|
|
71
|
+
is_replay BOOLEAN NOT NULL DEFAULT FALSE,
|
|
72
|
+
delivered_at TIMESTAMPTZ,
|
|
73
|
+
failed_at TIMESTAMPTZ,
|
|
74
|
+
locked_by TEXT,
|
|
75
|
+
locked_until TIMESTAMPTZ,
|
|
76
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
77
|
+
UNIQUE (subscription_id, dedup_key)
|
|
78
|
+
)
|
|
79
|
+
`.execute(db);
|
|
80
|
+
|
|
81
|
+
await sql`
|
|
82
|
+
CREATE INDEX outbox_dispatch_idx
|
|
83
|
+
ON subscription_outbox (status, next_attempt_at, is_replay)
|
|
84
|
+
WHERE status = 'pending'
|
|
85
|
+
`.execute(db);
|
|
86
|
+
|
|
87
|
+
await sql`
|
|
88
|
+
CREATE INDEX outbox_sub_idx
|
|
89
|
+
ON subscription_outbox (subscription_id, created_at DESC)
|
|
90
|
+
`.execute(db);
|
|
91
|
+
|
|
92
|
+
await sql`
|
|
93
|
+
CREATE TABLE subscription_deliveries (
|
|
94
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
95
|
+
outbox_id UUID NOT NULL REFERENCES subscription_outbox(id) ON DELETE CASCADE,
|
|
96
|
+
subscription_id UUID NOT NULL,
|
|
97
|
+
attempt INT NOT NULL,
|
|
98
|
+
status_code INT,
|
|
99
|
+
response_headers JSONB,
|
|
100
|
+
response_body TEXT,
|
|
101
|
+
error_message TEXT,
|
|
102
|
+
duration_ms INT,
|
|
103
|
+
dispatched_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
104
|
+
)
|
|
105
|
+
`.execute(db);
|
|
106
|
+
|
|
107
|
+
await sql`
|
|
108
|
+
CREATE INDEX deliveries_sub_idx
|
|
109
|
+
ON subscription_deliveries (subscription_id, dispatched_at DESC)
|
|
110
|
+
`.execute(db);
|
|
111
|
+
|
|
112
|
+
await sql`
|
|
113
|
+
CREATE OR REPLACE FUNCTION notify_new_outbox() RETURNS TRIGGER AS $$
|
|
114
|
+
BEGIN
|
|
115
|
+
PERFORM pg_notify('subscriptions:new_outbox', NEW.subscription_id::text);
|
|
116
|
+
RETURN NEW;
|
|
117
|
+
END;
|
|
118
|
+
$$ LANGUAGE plpgsql
|
|
119
|
+
`.execute(db);
|
|
120
|
+
|
|
121
|
+
await sql`
|
|
122
|
+
CREATE TRIGGER subscription_outbox_notify
|
|
123
|
+
AFTER INSERT ON subscription_outbox
|
|
124
|
+
FOR EACH ROW
|
|
125
|
+
EXECUTE FUNCTION notify_new_outbox()
|
|
126
|
+
`.execute(db);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
130
|
+
await sql`DROP TRIGGER IF EXISTS subscription_outbox_notify ON subscription_outbox`.execute(
|
|
131
|
+
db,
|
|
132
|
+
);
|
|
133
|
+
await sql`DROP FUNCTION IF EXISTS notify_new_outbox() CASCADE`.execute(db);
|
|
134
|
+
await sql`DROP TABLE IF EXISTS subscription_deliveries CASCADE`.execute(db);
|
|
135
|
+
await sql`DROP TABLE IF EXISTS subscription_outbox CASCADE`.execute(db);
|
|
136
|
+
await sql`DROP TABLE IF EXISTS subscriptions CASCADE`.execute(db);
|
|
137
|
+
}
|