@intx/db 0.3.0 → 0.4.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 (71) hide show
  1. package/README.md +11 -0
  2. package/dist/approval-store.d.ts +7 -0
  3. package/dist/approval-store.js +13 -0
  4. package/dist/backfill-principal-keys.d.ts +9 -0
  5. package/dist/backfill-principal-keys.js +51 -0
  6. package/dist/client.d.ts +27 -2
  7. package/dist/client.js +6 -0
  8. package/dist/config.d.ts +1 -0
  9. package/dist/config.js +2 -0
  10. package/dist/connection.js +1 -0
  11. package/dist/credential-resolution.d.ts +54 -5
  12. package/dist/credential-resolution.js +109 -0
  13. package/dist/index.d.ts +11 -5
  14. package/dist/index.js +10 -4
  15. package/dist/model-source-resolution.d.ts +6 -5
  16. package/dist/model-source-resolution.js +42 -13
  17. package/dist/parse-row.d.ts +39 -8
  18. package/dist/parse-row.js +8 -0
  19. package/dist/principal-key-store.d.ts +51 -0
  20. package/dist/principal-key-store.js +82 -0
  21. package/dist/principal-store.d.ts +44 -0
  22. package/dist/principal-store.js +67 -0
  23. package/dist/schema/approvals.js +5 -0
  24. package/dist/schema/git-tokens.js +1 -1
  25. package/dist/schema/index.d.ts +2 -0
  26. package/dist/schema/index.js +2 -0
  27. package/dist/schema/principal-keys.d.ts +126 -0
  28. package/dist/schema/principal-keys.js +28 -0
  29. package/dist/schema/sidecar-allocation.d.ts +19 -40
  30. package/dist/schema/sidecar-allocation.js +4 -8
  31. package/dist/schema/sidecar.d.ts +0 -17
  32. package/dist/schema/sidecar.js +4 -12
  33. package/dist/schema/tenants.js +13 -3
  34. package/dist/schema/workflow-probe.d.ts +358 -0
  35. package/dist/schema/workflow-probe.js +51 -0
  36. package/dist/schema/workflow-run-dispatch.d.ts +17 -0
  37. package/dist/schema/workflow-run-dispatch.js +7 -0
  38. package/dist/schema/workflow-run.d.ts +27 -0
  39. package/dist/schema/workflow-run.js +8 -0
  40. package/dist/sender-key-resolver.d.ts +91 -0
  41. package/dist/sender-key-resolver.js +184 -0
  42. package/dist/sidecar-allocation-store.d.ts +38 -3
  43. package/dist/sidecar-allocation-store.js +224 -22
  44. package/dist/signer-identity.d.ts +12 -0
  45. package/dist/signer-identity.js +15 -0
  46. package/dist/tenant-hierarchy.d.ts +2 -0
  47. package/dist/tenant-hierarchy.js +27 -0
  48. package/dist/workflow-probe-store.d.ts +47 -0
  49. package/dist/workflow-probe-store.js +124 -0
  50. package/dist/workflow-run-dispatch-store.d.ts +3 -0
  51. package/dist/workflow-run-dispatch-store.js +12 -2
  52. package/migrations/0085_add_approval_run_idx.sql +1 -0
  53. package/migrations/0086_cool_human_cannonball.sql +1 -0
  54. package/migrations/0087_drop_sidecar_placement.sql +3 -0
  55. package/migrations/0088_thick_sprite.sql +32 -0
  56. package/migrations/0089_tense_selene.sql +13 -0
  57. package/migrations/0090_tenant_domain_lower_unique.sql +2 -0
  58. package/migrations/0091_workflow_run_dispatch_sender_address.sql +21 -0
  59. package/migrations/0092_sidecar_destroy_failed.sql +4 -0
  60. package/migrations/0093_sidecar_initialization.sql +2 -0
  61. package/migrations/meta/0085_snapshot.json +4111 -0
  62. package/migrations/meta/0086_snapshot.json +4117 -0
  63. package/migrations/meta/0087_snapshot.json +4100 -0
  64. package/migrations/meta/0088_snapshot.json +4286 -0
  65. package/migrations/meta/0089_snapshot.json +4376 -0
  66. package/migrations/meta/0090_snapshot.json +4387 -0
  67. package/migrations/meta/0091_snapshot.json +4397 -0
  68. package/migrations/meta/0092_snapshot.json +4397 -0
  69. package/migrations/meta/0093_snapshot.json +4407 -0
  70. package/migrations/meta/_journal.json +63 -0
  71. package/package.json +6 -5
@@ -8,6 +8,7 @@ export type EnqueueWorkflowRunDispatchArgs = {
8
8
  readonly id: string;
9
9
  readonly anchorRunId: string;
10
10
  readonly messageId: string;
11
+ readonly senderAddress: string;
11
12
  readonly rawMessage: Uint8Array;
12
13
  readonly stepGrants: RunGrantsFrameType["stepGrants"];
13
14
  readonly now?: Date;
@@ -28,6 +29,7 @@ type InsertOrReconcileDispatchArgs = {
28
29
  readonly anchorRunId: string;
29
30
  readonly messageId: string;
30
31
  readonly kind: ParsedDispatch["kind"];
32
+ readonly senderAddress: string | null;
31
33
  readonly rawMessage: Uint8Array;
32
34
  readonly stepGrants: RunGrantsFrameType["stepGrants"];
33
35
  readonly now?: Date;
@@ -38,6 +40,7 @@ export declare class WorkflowRunDispatchPayloadConflictError extends Error {
38
40
  constructor(messageId: string, payloadKind: "message" | "signal", operation: InsertOrReconcileDispatchArgs["operation"]);
39
41
  }
40
42
  export type ClaimWorkflowRunDispatchArgs = {
43
+ readonly excludedDispatchIds?: readonly string[];
41
44
  readonly leaseId: string;
42
45
  readonly leaseDurationMs: number;
43
46
  };
@@ -1,5 +1,5 @@
1
1
  import { isDeepStrictEqual } from "node:util";
2
- import { and, asc, eq, inArray, isNull, lte, or, sql, } from "drizzle-orm";
2
+ import { and, asc, eq, inArray, isNull, lte, notInArray, or, sql, } from "drizzle-orm";
3
3
  import { RunGrantsFrame, SignalDeliverFrame, } from "@intx/types/sidecar";
4
4
  import { parseWorkflowRunDispatchRow } from "./parse-row.js";
5
5
  import { sidecarAllocation, workflowRun, workflowRunDispatch } from "./schema/index.js";
@@ -54,6 +54,7 @@ async function insertOrReconcileDispatch(executor, args) {
54
54
  anchorRunId: args.anchorRunId,
55
55
  messageId: args.messageId,
56
56
  kind: args.kind,
57
+ senderAddress: args.senderAddress,
57
58
  rawMessage: args.rawMessage,
58
59
  stepGrants: args.stepGrants,
59
60
  status: "pending",
@@ -116,6 +117,7 @@ export function createWorkflowRunDispatchStore(db) {
116
117
  anchorRunId: args.anchorRunId,
117
118
  messageId: args.messageId,
118
119
  kind: "mail",
120
+ senderAddress: args.senderAddress,
119
121
  rawMessage: args.rawMessage,
120
122
  stepGrants,
121
123
  ...(args.now !== undefined ? { now: args.now } : {}),
@@ -133,6 +135,7 @@ export function createWorkflowRunDispatchStore(db) {
133
135
  anchorRunId: args.anchorRunId,
134
136
  messageId: signal.signalId,
135
137
  kind: "signal",
138
+ senderAddress: null,
136
139
  rawMessage: encoded,
137
140
  stepGrants: [],
138
141
  ...(args.now !== undefined ? { now: args.now } : {}),
@@ -143,7 +146,14 @@ export function createWorkflowRunDispatchStore(db) {
143
146
  const [candidate] = await tx
144
147
  .select({ id: workflowRunDispatch.id })
145
148
  .from(workflowRunDispatch)
146
- .where(and(eq(workflowRunDispatch.status, "pending"), lte(workflowRunDispatch.nextAttemptAt, sql `now()`), or(isNull(workflowRunDispatch.deliveryLeaseExpiresAt), lte(workflowRunDispatch.deliveryLeaseExpiresAt, sql `now()`))))
149
+ .where(and(eq(workflowRunDispatch.status, "pending"), lte(workflowRunDispatch.nextAttemptAt, sql `now()`), ...(args.excludedDispatchIds !== undefined &&
150
+ args.excludedDispatchIds.length > 0
151
+ ? [
152
+ notInArray(workflowRunDispatch.id, [
153
+ ...args.excludedDispatchIds,
154
+ ]),
155
+ ]
156
+ : []), or(isNull(workflowRunDispatch.deliveryLeaseExpiresAt), lte(workflowRunDispatch.deliveryLeaseExpiresAt, sql `now()`))))
147
157
  .orderBy(asc(workflowRunDispatch.nextAttemptAt), asc(workflowRunDispatch.createdAt))
148
158
  .limit(1)
149
159
  .for("update", { skipLocked: true });
@@ -0,0 +1 @@
1
+ CREATE INDEX "approval_run_idx" ON "approval" USING btree ("run_id");
@@ -0,0 +1 @@
1
+ ALTER TABLE "workflow_run" ADD COLUMN "credential_refs" jsonb;
@@ -0,0 +1,3 @@
1
+ ALTER TABLE "sidecar_allocation" DROP CONSTRAINT "sidecar_allocation_placement_check";--> statement-breakpoint
2
+ ALTER TABLE "sidecar_allocation" DROP COLUMN "placement_sharing";--> statement-breakpoint
3
+ ALTER TABLE "sidecar_allocation" DROP COLUMN "sidecar_reuse";
@@ -0,0 +1,32 @@
1
+ CREATE TABLE "workflow_probe" (
2
+ "id" text PRIMARY KEY NOT NULL,
3
+ "tenant_id" text NOT NULL,
4
+ "definition_asset_id" text NOT NULL,
5
+ "source" jsonb NOT NULL,
6
+ "entry" text NOT NULL,
7
+ "pin" text,
8
+ "status" text DEFAULT 'pending' NOT NULL,
9
+ "provisioner_id" text NOT NULL,
10
+ "provisioner_api_version" integer NOT NULL,
11
+ "provisioner_binding_fingerprint" text NOT NULL,
12
+ "sidecar_id" text,
13
+ "generation" integer DEFAULT 0 NOT NULL,
14
+ "external_ref" text,
15
+ "result" jsonb,
16
+ "failure_code" text,
17
+ "failure_message" text,
18
+ "created_at" timestamp DEFAULT now() NOT NULL,
19
+ "updated_at" timestamp DEFAULT now() NOT NULL,
20
+ CONSTRAINT "workflow_probe_status_check" CHECK ("workflow_probe"."status" in ('pending', 'provisioning', 'probing', 'releasing', 'succeeded', 'failed')),
21
+ CONSTRAINT "workflow_probe_succeeded_result_check" CHECK ("workflow_probe"."status" <> 'succeeded' or "workflow_probe"."result" is not null),
22
+ CONSTRAINT "workflow_probe_generation_check" CHECK ("workflow_probe"."generation" >= 0)
23
+ );
24
+ --> statement-breakpoint
25
+ DELETE FROM "sidecar" WHERE "credential_scope" = 'shared';--> statement-breakpoint
26
+ ALTER TABLE "sidecar" DROP CONSTRAINT "sidecar_credential_scope_check";--> statement-breakpoint
27
+ ALTER TABLE "workflow_probe" ADD CONSTRAINT "workflow_probe_tenant_id_tenant_id_fk" FOREIGN KEY ("tenant_id") REFERENCES "public"."tenant"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
28
+ ALTER TABLE "workflow_probe" ADD CONSTRAINT "workflow_probe_definition_asset_id_asset_id_fk" FOREIGN KEY ("definition_asset_id") REFERENCES "public"."asset"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
29
+ ALTER TABLE "workflow_probe" ADD CONSTRAINT "workflow_probe_sidecar_id_sidecar_id_fk" FOREIGN KEY ("sidecar_id") REFERENCES "public"."sidecar"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
30
+ CREATE INDEX "workflow_probe_active_idx" ON "workflow_probe" USING btree ("created_at") WHERE "workflow_probe"."status" in ('pending', 'provisioning', 'probing', 'releasing');--> statement-breakpoint
31
+ CREATE INDEX "workflow_probe_sidecar_idx" ON "workflow_probe" USING btree ("sidecar_id");--> statement-breakpoint
32
+ ALTER TABLE "sidecar" DROP COLUMN "credential_scope";
@@ -0,0 +1,13 @@
1
+ CREATE TABLE "principal_key" (
2
+ "id" text PRIMARY KEY NOT NULL,
3
+ "principal_id" text NOT NULL,
4
+ "public_key" text NOT NULL,
5
+ "private_key" text NOT NULL,
6
+ "status" text NOT NULL,
7
+ "created_at" timestamp DEFAULT now() NOT NULL,
8
+ "updated_at" timestamp DEFAULT now() NOT NULL,
9
+ CONSTRAINT "principal_key_public_key_unique" UNIQUE("public_key")
10
+ );
11
+ --> statement-breakpoint
12
+ ALTER TABLE "principal_key" ADD CONSTRAINT "principal_key_principal_id_principal_id_fk" FOREIGN KEY ("principal_id") REFERENCES "public"."principal"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
13
+ CREATE UNIQUE INDEX "principal_key_one_active" ON "principal_key" USING btree ("principal_id") WHERE "principal_key"."status" = 'active';
@@ -0,0 +1,2 @@
1
+ ALTER TABLE "tenant" DROP CONSTRAINT "tenant_domain_unique";--> statement-breakpoint
2
+ CREATE UNIQUE INDEX "tenant_domain_lower_idx" ON "tenant" USING btree (lower("domain"));
@@ -0,0 +1,21 @@
1
+ ALTER TABLE "workflow_run_dispatch" ADD COLUMN "sender_address" text;--> statement-breakpoint
2
+ -- Fail in-flight mail dispatches that predate the authenticated-sender
3
+ -- requirement. They carry no persisted hub-verified sender, and neither
4
+ -- fabricating one nor re-reading the signed From is permitted, so they are
5
+ -- failed in place rather than delivered unauthenticated. Only unsettled
6
+ -- (pending/acknowledged) mail rows are ever re-dispatched and reconstruct a
7
+ -- mail.inbound frame; terminal (settled/failed) mail rows never do, so they
8
+ -- keep their NULL sender under the status-scoped check below. On a fresh
9
+ -- database this affects zero rows.
10
+ UPDATE "workflow_run_dispatch"
11
+ SET "status" = 'failed',
12
+ "failure_code" = 'sender_address_migration',
13
+ "failure_message" = 'in-flight mail dispatch predates the authenticated-sender requirement and carries no hub-verified sender',
14
+ "next_attempt_at" = NULL,
15
+ "delivery_lease_id" = NULL,
16
+ "delivery_lease_expires_at" = NULL,
17
+ "updated_at" = now()
18
+ WHERE "kind" = 'mail'
19
+ AND "status" IN ('pending', 'acknowledged')
20
+ AND "sender_address" IS NULL;--> statement-breakpoint
21
+ ALTER TABLE "workflow_run_dispatch" ADD CONSTRAINT "workflow_run_dispatch_mail_sender_check" CHECK ("workflow_run_dispatch"."kind" <> 'mail' or "workflow_run_dispatch"."status" in ('settled', 'failed') or "workflow_run_dispatch"."sender_address" is not null);
@@ -0,0 +1,4 @@
1
+ ALTER TABLE "sidecar_allocation" DROP CONSTRAINT "sidecar_allocation_status_check";--> statement-breakpoint
2
+ DROP INDEX "sidecar_allocation_active_sidecar_idx";--> statement-breakpoint
3
+ CREATE UNIQUE INDEX "sidecar_allocation_active_sidecar_idx" ON "sidecar_allocation" USING btree ("sidecar_id") WHERE "sidecar_allocation"."status" in ('provisioning', 'allocated', 'replacing', 'releasing', 'destroy_failed');--> statement-breakpoint
4
+ ALTER TABLE "sidecar_allocation" ADD CONSTRAINT "sidecar_allocation_status_check" CHECK ("sidecar_allocation"."status" in ('pending', 'provisioning', 'allocated', 'replacing', 'releasing', 'destroy_failed', 'released', 'failed'));
@@ -0,0 +1,2 @@
1
+ ALTER TABLE "sidecar_allocation" ADD COLUMN "initialization_lease_id" text;--> statement-breakpoint
2
+ ALTER TABLE "sidecar_allocation" ADD CONSTRAINT "sidecar_allocation_initialization_check" CHECK ("sidecar_allocation"."initialization_lease_id" is null or ("sidecar_allocation"."status" = 'allocated' and "sidecar_allocation"."ensure_accepted_generation" is not null and "sidecar_allocation"."ensure_accepted_generation" = "sidecar_allocation"."generation"));