@anatta.io/tva 0.0.0-stage → 0.1.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 +50 -2
- package/dist/actions/action-consumer.d.ts +45 -0
- package/dist/actions/action-consumer.js +90 -0
- package/dist/actions/action.d.ts +67 -0
- package/dist/actions/action.js +12 -0
- package/dist/actions/index.d.ts +3 -0
- package/dist/actions/index.js +4 -0
- package/dist/actions/run-action.d.ts +31 -0
- package/dist/actions/run-action.js +113 -0
- package/dist/adapters/cloudflare/bindings.d.ts +10 -0
- package/dist/adapters/cloudflare/bindings.js +1 -0
- package/dist/adapters/cloudflare/blob-store.d.ts +39 -0
- package/dist/adapters/cloudflare/blob-store.js +95 -0
- package/dist/adapters/cloudflare/cache.d.ts +14 -0
- package/dist/adapters/cloudflare/cache.js +48 -0
- package/dist/adapters/cloudflare/faults.d.ts +7 -0
- package/dist/adapters/cloudflare/faults.js +39 -0
- package/dist/adapters/cloudflare/index.d.ts +15 -0
- package/dist/adapters/cloudflare/index.js +16 -0
- package/dist/adapters/cloudflare/jobs.d.ts +97 -0
- package/dist/adapters/cloudflare/jobs.js +218 -0
- package/dist/adapters/cloudflare/journal.d.ts +107 -0
- package/dist/adapters/cloudflare/journal.js +305 -0
- package/dist/adapters/cloudflare/ledger.d.ts +14 -0
- package/dist/adapters/cloudflare/ledger.js +108 -0
- package/dist/adapters/cloudflare/logger.d.ts +22 -0
- package/dist/adapters/cloudflare/logger.js +49 -0
- package/dist/adapters/cloudflare/manifest.d.ts +81 -0
- package/dist/adapters/cloudflare/manifest.js +81 -0
- package/dist/adapters/cloudflare/queue.d.ts +80 -0
- package/dist/adapters/cloudflare/queue.js +177 -0
- package/dist/adapters/cloudflare/retention.d.ts +24 -0
- package/dist/adapters/cloudflare/retention.js +103 -0
- package/dist/adapters/cloudflare/session-storage.d.ts +27 -0
- package/dist/adapters/cloudflare/session-storage.js +78 -0
- package/dist/adapters/cloudflare/toolkit.d.ts +16 -0
- package/dist/adapters/cloudflare/toolkit.js +57 -0
- package/dist/adapters/cloudflare/workflow-jobs.d.ts +57 -0
- package/dist/adapters/cloudflare/workflow-jobs.js +319 -0
- package/dist/adapters/journal-records.d.ts +79 -0
- package/dist/adapters/journal-records.js +74 -0
- package/dist/adapters/memory/blob-store.d.ts +9 -0
- package/dist/adapters/memory/blob-store.js +19 -0
- package/dist/adapters/memory/cache.d.ts +13 -0
- package/dist/adapters/memory/cache.js +36 -0
- package/dist/adapters/memory/clock.d.ts +1 -0
- package/dist/adapters/memory/clock.js +4 -0
- package/dist/adapters/memory/index.d.ts +11 -0
- package/dist/adapters/memory/index.js +11 -0
- package/dist/adapters/memory/jobs.d.ts +62 -0
- package/dist/adapters/memory/jobs.js +219 -0
- package/dist/adapters/memory/journal.d.ts +34 -0
- package/dist/adapters/memory/journal.js +135 -0
- package/dist/adapters/memory/ledger.d.ts +9 -0
- package/dist/adapters/memory/ledger.js +33 -0
- package/dist/adapters/memory/logger.d.ts +16 -0
- package/dist/adapters/memory/logger.js +21 -0
- package/dist/adapters/memory/manifest.d.ts +59 -0
- package/dist/adapters/memory/manifest.js +59 -0
- package/dist/adapters/memory/queue.d.ts +20 -0
- package/dist/adapters/memory/queue.js +102 -0
- package/dist/adapters/memory/session-storage.d.ts +20 -0
- package/dist/adapters/memory/session-storage.js +33 -0
- package/dist/adapters/memory/toolkit.d.ts +8 -0
- package/dist/adapters/memory/toolkit.js +31 -0
- package/dist/adapters/postgres/cache.d.ts +17 -0
- package/dist/adapters/postgres/cache.js +69 -0
- package/dist/adapters/postgres/config.d.ts +27 -0
- package/dist/adapters/postgres/config.js +45 -0
- package/dist/adapters/postgres/faults.d.ts +14 -0
- package/dist/adapters/postgres/faults.js +47 -0
- package/dist/adapters/postgres/index.d.ts +12 -0
- package/dist/adapters/postgres/index.js +12 -0
- package/dist/adapters/postgres/journal.d.ts +83 -0
- package/dist/adapters/postgres/journal.js +314 -0
- package/dist/adapters/postgres/ledger.d.ts +16 -0
- package/dist/adapters/postgres/ledger.js +97 -0
- package/dist/adapters/postgres/logger.d.ts +19 -0
- package/dist/adapters/postgres/logger.js +37 -0
- package/dist/adapters/postgres/manifest.d.ts +52 -0
- package/dist/adapters/postgres/manifest.js +53 -0
- package/dist/adapters/postgres/migrate.d.ts +20 -0
- package/dist/adapters/postgres/migrate.js +96 -0
- package/dist/adapters/postgres/queue.d.ts +64 -0
- package/dist/adapters/postgres/queue.js +333 -0
- package/dist/adapters/postgres/retention.d.ts +18 -0
- package/dist/adapters/postgres/retention.js +104 -0
- package/dist/adapters/postgres/session-storage.d.ts +20 -0
- package/dist/adapters/postgres/session-storage.js +71 -0
- package/dist/adapters/postgres/toolkit.d.ts +25 -0
- package/dist/adapters/postgres/toolkit.js +58 -0
- package/dist/adapters/postgres/with-client.d.ts +11 -0
- package/dist/adapters/postgres/with-client.js +29 -0
- package/dist/adapters/reference-executor.d.ts +171 -0
- package/dist/adapters/reference-executor.js +564 -0
- package/dist/adapters/retention.d.ts +18 -0
- package/dist/adapters/retention.js +13 -0
- package/dist/adapters/s3/blob-store.d.ts +35 -0
- package/dist/adapters/s3/blob-store.js +92 -0
- package/dist/adapters/s3/faults.d.ts +8 -0
- package/dist/adapters/s3/faults.js +34 -0
- package/dist/adapters/s3/index.d.ts +2 -0
- package/dist/adapters/s3/index.js +2 -0
- package/dist/adapters/session-envelope.d.ts +21 -0
- package/dist/adapters/session-envelope.js +122 -0
- package/dist/adapters/system-clock.d.ts +8 -0
- package/dist/adapters/system-clock.js +8 -0
- package/dist/contracts/blob-store.d.ts +11 -0
- package/dist/contracts/blob-store.js +1 -0
- package/dist/contracts/cache.d.ts +27 -0
- package/dist/contracts/cache.js +1 -0
- package/dist/contracts/duration.d.ts +23 -0
- package/dist/contracts/duration.js +27 -0
- package/dist/contracts/faults.d.ts +28 -0
- package/dist/contracts/faults.js +29 -0
- package/dist/contracts/identity.d.ts +12 -0
- package/dist/contracts/identity.js +1 -0
- package/dist/contracts/index.d.ts +14 -0
- package/dist/contracts/index.js +15 -0
- package/dist/contracts/instant.d.ts +17 -0
- package/dist/contracts/instant.js +12 -0
- package/dist/contracts/jobs.d.ts +335 -0
- package/dist/contracts/jobs.js +1 -0
- package/dist/contracts/journal.d.ts +186 -0
- package/dist/contracts/journal.js +10 -0
- package/dist/contracts/ledger.d.ts +34 -0
- package/dist/contracts/ledger.js +1 -0
- package/dist/contracts/logger.d.ts +11 -0
- package/dist/contracts/logger.js +1 -0
- package/dist/contracts/manifest.d.ts +37 -0
- package/dist/contracts/manifest.js +30 -0
- package/dist/contracts/queue.d.ts +55 -0
- package/dist/contracts/queue.js +1 -0
- package/dist/contracts/session-storage.d.ts +18 -0
- package/dist/contracts/session-storage.js +1 -0
- package/dist/contracts/toolkit.d.ts +21 -0
- package/dist/contracts/toolkit.js +1 -0
- package/dist/schedule/schedule.d.ts +40 -0
- package/dist/schedule/schedule.js +135 -0
- package/dist/webhooks/create-webhook-handler.d.ts +63 -0
- package/dist/webhooks/create-webhook-handler.js +246 -0
- package/dist/webhooks/dead-letter-consumer.d.ts +14 -0
- package/dist/webhooks/dead-letter-consumer.js +42 -0
- package/dist/webhooks/define-registry.d.ts +42 -0
- package/dist/webhooks/define-registry.js +56 -0
- package/dist/webhooks/once.d.ts +15 -0
- package/dist/webhooks/once.js +29 -0
- package/dist/webhooks/redact-customer-bodies.d.ts +29 -0
- package/dist/webhooks/redact-customer-bodies.js +45 -0
- package/dist/webhooks/replay-webhooks.d.ts +39 -0
- package/dist/webhooks/replay-webhooks.js +79 -0
- package/dist/webhooks/sign-shopify-webhook.d.ts +14 -0
- package/dist/webhooks/sign-shopify-webhook.js +31 -0
- package/dist/webhooks/webhook-consumer.d.ts +51 -0
- package/dist/webhooks/webhook-consumer.js +127 -0
- package/migrations/0001_create_ledger_claims.sql +23 -0
- package/migrations/0002_create_journal.sql +76 -0
- package/migrations/0003_create_shopify_sessions.sql +30 -0
- package/migrations/0004_create_journal_steps.sql +34 -0
- package/migrations/0007_create_job_tables.sql +71 -0
- package/migrations/0008_add_ledger_completed_at.sql +7 -0
- package/migrations/0009_create_webhook_receipts.sql +34 -0
- package/migrations/0010_index_webhook_deliveries_received_at.sql +2 -0
- package/migrations/0011_add_webhook_task_reason_code.sql +4 -0
- package/migrations/postgres/0001_create_ledger_claims.sql +13 -0
- package/migrations/postgres/0002_create_journal.sql +48 -0
- package/migrations/postgres/0003_create_shopify_sessions.sql +12 -0
- package/migrations/postgres/0004_create_journal_steps.sql +19 -0
- package/migrations/postgres/0005_create_cache_entries.sql +14 -0
- package/migrations/postgres/0006_create_queue.sql +42 -0
- package/migrations/postgres/0007_create_job_tables.sql +40 -0
- package/migrations/postgres/0008_add_ledger_completed_at.sql +3 -0
- package/migrations/postgres/0009_create_webhook_receipts.sql +23 -0
- package/migrations/postgres/0010_index_webhook_deliveries_received_at.sql +2 -0
- package/migrations/postgres/0011_add_webhook_task_reason_code.sql +3 -0
- package/package.json +137 -4
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { WebhookAction } from './webhook-consumer.js';
|
|
2
|
+
/**
|
|
3
|
+
* The most Actions one topic may have: the edge sends one pointer per Action
|
|
4
|
+
* in one `sendBatch`, which Cloudflare caps at 100 messages (#127,
|
|
5
|
+
* docs/platform-facts.md "`sendBatch` cap").
|
|
6
|
+
*/
|
|
7
|
+
export declare const WEBHOOK_MAX_ACTIONS_PER_TOPIC = 100;
|
|
8
|
+
/** One Action for one `(source, topic)`, with its own retry settings. */
|
|
9
|
+
export type WebhookRegistration<Deps> = {
|
|
10
|
+
readonly source: string;
|
|
11
|
+
/** As Shopify sends it, for example `orders/create`. */
|
|
12
|
+
readonly topic: string;
|
|
13
|
+
readonly action: WebhookAction<Deps>;
|
|
14
|
+
/** Overrides the consumer's `retryDelaySeconds` for this Action. */
|
|
15
|
+
readonly retryDelaySeconds?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Overrides the consumer's `maxAttempts`, which it must not exceed. Below
|
|
18
|
+
* it, a task that runs out is `dead` and its message is acked: replay reads
|
|
19
|
+
* the journal, not the dead-letter queue.
|
|
20
|
+
*/
|
|
21
|
+
readonly maxAttempts?: number;
|
|
22
|
+
};
|
|
23
|
+
/** What only the domain knows about a topic. */
|
|
24
|
+
export type WebhookTopicSettings = {
|
|
25
|
+
readonly source: string;
|
|
26
|
+
readonly topic: string;
|
|
27
|
+
/** The longest normal gap between deliveries, for the silence alarm (design §7.4). */
|
|
28
|
+
readonly quietPeriodSeconds: number;
|
|
29
|
+
};
|
|
30
|
+
export type WebhookRegistry<Deps> = {
|
|
31
|
+
readonly actions: readonly WebhookRegistration<Deps>[];
|
|
32
|
+
readonly topics: readonly WebhookTopicSettings[];
|
|
33
|
+
/** The topic's Actions, in registration order; none for an unknown topic. */
|
|
34
|
+
actionsFor(source: string, topic: string): readonly WebhookRegistration<Deps>[];
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The `(source, topic, action)` table the edge and the consumer share, as
|
|
38
|
+
* data. Throws on a duplicate, on more than `WEBHOOK_MAX_ACTIONS_PER_TOPIC`
|
|
39
|
+
* Actions for a topic, on settings for a topic with no Action and on a bad
|
|
40
|
+
* duration, so a misconfigured app fails at start-up.
|
|
41
|
+
*/
|
|
42
|
+
export declare function defineRegistry<Deps>(actions: readonly WebhookRegistration<Deps>[], topics?: readonly WebhookTopicSettings[]): WebhookRegistry<Deps>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { checkDuration } from '../contracts/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The most Actions one topic may have: the edge sends one pointer per Action
|
|
4
|
+
* in one `sendBatch`, which Cloudflare caps at 100 messages (#127,
|
|
5
|
+
* docs/platform-facts.md "`sendBatch` cap").
|
|
6
|
+
*/
|
|
7
|
+
export const WEBHOOK_MAX_ACTIONS_PER_TOPIC = 100;
|
|
8
|
+
/**
|
|
9
|
+
* The `(source, topic, action)` table the edge and the consumer share, as
|
|
10
|
+
* data. Throws on a duplicate, on more than `WEBHOOK_MAX_ACTIONS_PER_TOPIC`
|
|
11
|
+
* Actions for a topic, on settings for a topic with no Action and on a bad
|
|
12
|
+
* duration, so a misconfigured app fails at start-up.
|
|
13
|
+
*/
|
|
14
|
+
export function defineRegistry(actions, topics = []) {
|
|
15
|
+
const byTopic = new Map();
|
|
16
|
+
for (const registration of actions) {
|
|
17
|
+
const { source, topic, action } = registration;
|
|
18
|
+
const label = `${source} ${topic} ${action.name}`;
|
|
19
|
+
const key = topicKey(source, topic);
|
|
20
|
+
const registered = byTopic.get(key) ?? [];
|
|
21
|
+
if (registered.some((other) => other.action.name === action.name)) {
|
|
22
|
+
throw new TypeError(`webhook registry: ${label} is registered twice`);
|
|
23
|
+
}
|
|
24
|
+
if (registered.length === WEBHOOK_MAX_ACTIONS_PER_TOPIC) {
|
|
25
|
+
throw new TypeError(`webhook registry: ${source} ${topic} has more than ${WEBHOOK_MAX_ACTIONS_PER_TOPIC} Actions`);
|
|
26
|
+
}
|
|
27
|
+
if (registration.retryDelaySeconds !== undefined) {
|
|
28
|
+
checkDuration(label, 'retryDelaySeconds', registration.retryDelaySeconds);
|
|
29
|
+
}
|
|
30
|
+
if (registration.maxAttempts !== undefined &&
|
|
31
|
+
!(Number.isInteger(registration.maxAttempts) &&
|
|
32
|
+
registration.maxAttempts >= 1)) {
|
|
33
|
+
throw new TypeError(`webhook registry: ${label} maxAttempts must be a whole number ≥ 1`);
|
|
34
|
+
}
|
|
35
|
+
byTopic.set(key, [...registered, registration]);
|
|
36
|
+
}
|
|
37
|
+
const settled = new Set();
|
|
38
|
+
for (const { source, topic, quietPeriodSeconds } of topics) {
|
|
39
|
+
const key = topicKey(source, topic);
|
|
40
|
+
if (!byTopic.has(key)) {
|
|
41
|
+
throw new TypeError(`webhook registry: ${source} ${topic} has settings but no Action`);
|
|
42
|
+
}
|
|
43
|
+
if (settled.has(key)) {
|
|
44
|
+
throw new TypeError(`webhook registry: ${source} ${topic} has settings twice`);
|
|
45
|
+
}
|
|
46
|
+
settled.add(key);
|
|
47
|
+
checkDuration(`${source} ${topic}`, 'quietPeriodSeconds', quietPeriodSeconds);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
actions,
|
|
51
|
+
topics,
|
|
52
|
+
actionsFor: (source, topic) => byTopic.get(topicKey(source, topic)) ?? [],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// JSON, so no source or topic can collide with another through a separator.
|
|
56
|
+
const topicKey = (source, topic) => JSON.stringify([source, topic]);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Ledger } from '../contracts/index.js';
|
|
2
|
+
export interface OnceOptions {
|
|
3
|
+
readonly ledger: Ledger;
|
|
4
|
+
readonly source: string;
|
|
5
|
+
readonly action: string;
|
|
6
|
+
/** How long a run may take before another attempt can claim the key. */
|
|
7
|
+
readonly leaseSeconds: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Runs an Action's side effect once per key: claim, run, complete.
|
|
11
|
+
* `'already-done'` does not carry the first run's result; it is not stored.
|
|
12
|
+
* `'in-progress'` means another run holds the lease; retry the task later.
|
|
13
|
+
*/
|
|
14
|
+
export type Once = <T>(key: string, ttlSeconds: number, fn: () => Promise<T>) => Promise<T | 'already-done' | 'in-progress'>;
|
|
15
|
+
export declare function createOnce({ ledger, source, action, leaseSeconds, }: OnceOptions): Once;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function createOnce({ ledger, source, action, leaseSeconds, }) {
|
|
2
|
+
// A ':' in either would let two Actions build the same ledger key.
|
|
3
|
+
if (`${source}${action}`.includes(':')) {
|
|
4
|
+
throw new TypeError(`source and action must not contain ':'`);
|
|
5
|
+
}
|
|
6
|
+
return async (key, ttlSeconds, fn) => {
|
|
7
|
+
const ledgerKey = `${source}:${action}:${key}`;
|
|
8
|
+
const claim = await ledger.claim(ledgerKey, leaseSeconds);
|
|
9
|
+
if (claim.status === 'completed') {
|
|
10
|
+
return 'already-done';
|
|
11
|
+
}
|
|
12
|
+
if (claim.status === 'in-progress') {
|
|
13
|
+
return 'in-progress';
|
|
14
|
+
}
|
|
15
|
+
let result;
|
|
16
|
+
try {
|
|
17
|
+
result = await fn();
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
// shortcut: claims carry no owner token, so a run that outlives its lease
|
|
21
|
+
// and then throws releases the next holder's claim; add a token to Ledger if that matters.
|
|
22
|
+
// The lease frees the key if release fails; keep fn's error.
|
|
23
|
+
await ledger.release(ledgerKey).catch(() => { });
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
await ledger.complete(ledgerKey, ttlSeconds);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BlobStore } from '../contracts/index.js';
|
|
2
|
+
/** The fields of a `customers/redact` body this reads. */
|
|
3
|
+
export type CustomersRedactPayload = {
|
|
4
|
+
readonly shop_domain: string;
|
|
5
|
+
readonly customer: {
|
|
6
|
+
readonly id: number | string;
|
|
7
|
+
readonly email?: string | null;
|
|
8
|
+
};
|
|
9
|
+
readonly orders_to_redact?: readonly (number | string)[];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Decision 0010: a handled `customers/redact` deletes, at once, each raw body
|
|
13
|
+
* of that shop that names the customer: its customer id or one of
|
|
14
|
+
* `orders_to_redact` as a whole number, or its email in any case. A false match
|
|
15
|
+
* deletes a body early, never keeps one.
|
|
16
|
+
*
|
|
17
|
+
* It wins over the retention sweep's rule that a task not yet final keeps its
|
|
18
|
+
* body: that task's retry then finds no body, a fault, and goes dead. `keepKey`
|
|
19
|
+
* spares the redact delivery's own body, so its own retry can still read it;
|
|
20
|
+
* the retention sweep deletes it later. Returns how many bodies it deleted.
|
|
21
|
+
*
|
|
22
|
+
* shortcut: reads every body the shop has in one call, which on Workers can
|
|
23
|
+
* pass the per-invocation operation limit for a very busy shop; make it a paged
|
|
24
|
+
* Job when one does.
|
|
25
|
+
*/
|
|
26
|
+
export declare function redactCustomerBodies(blobStore: BlobStore, payload: CustomersRedactPayload, options: {
|
|
27
|
+
readonly source: string;
|
|
28
|
+
readonly keepKey?: string;
|
|
29
|
+
}): Promise<number>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const numericId = (id) => {
|
|
2
|
+
const s = String(id);
|
|
3
|
+
if (!/^\d+$/.test(s)) {
|
|
4
|
+
throw new TypeError(`redactCustomerBodies: id ${s} is not numeric`);
|
|
5
|
+
}
|
|
6
|
+
return s;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Decision 0010: a handled `customers/redact` deletes, at once, each raw body
|
|
10
|
+
* of that shop that names the customer: its customer id or one of
|
|
11
|
+
* `orders_to_redact` as a whole number, or its email in any case. A false match
|
|
12
|
+
* deletes a body early, never keeps one.
|
|
13
|
+
*
|
|
14
|
+
* It wins over the retention sweep's rule that a task not yet final keeps its
|
|
15
|
+
* body: that task's retry then finds no body, a fault, and goes dead. `keepKey`
|
|
16
|
+
* spares the redact delivery's own body, so its own retry can still read it;
|
|
17
|
+
* the retention sweep deletes it later. Returns how many bodies it deleted.
|
|
18
|
+
*
|
|
19
|
+
* shortcut: reads every body the shop has in one call, which on Workers can
|
|
20
|
+
* pass the per-invocation operation limit for a very busy shop; make it a paged
|
|
21
|
+
* Job when one does.
|
|
22
|
+
*/
|
|
23
|
+
export async function redactCustomerBodies(blobStore, payload, options) {
|
|
24
|
+
const shop = payload.shop_domain;
|
|
25
|
+
if (shop === '' || shop.includes('/')) {
|
|
26
|
+
throw new TypeError(`redactCustomerBodies: shop ${shop} is not a domain`);
|
|
27
|
+
}
|
|
28
|
+
const ids = [payload.customer.id, ...(payload.orders_to_redact ?? [])].map(numericId);
|
|
29
|
+
const id = new RegExp(`(?<!\\d)(?:${ids.join('|')})(?!\\d)`);
|
|
30
|
+
const email = payload.customer.email?.toLowerCase() || undefined;
|
|
31
|
+
const names = (body) => id.test(body) || (email !== undefined && body.toLowerCase().includes(email));
|
|
32
|
+
const keys = await blobStore.list(`webhooks/${options.source}/${shop}/`);
|
|
33
|
+
let deleted = 0;
|
|
34
|
+
for (const key of keys) {
|
|
35
|
+
if (key === options.keepKey) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const body = await blobStore.getText(key);
|
|
39
|
+
if (body !== undefined && names(body)) {
|
|
40
|
+
await blobStore.delete(key);
|
|
41
|
+
deleted++;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return deleted;
|
|
45
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Toolkit } from '../contracts/index.js';
|
|
2
|
+
import type { WebhookMessage } from './create-webhook-handler.js';
|
|
3
|
+
import type { WebhookRegistry } from './define-registry.js';
|
|
4
|
+
/** What replay did with one task. Anything but `replayed` left it as it was. */
|
|
5
|
+
export type ReplayOutcome = 'replayed'
|
|
6
|
+
/** The raw body is gone: swept past retention, or redacted. */
|
|
7
|
+
| 'body-missing'
|
|
8
|
+
/** The registry has no such Action for the delivery's topic. */
|
|
9
|
+
| 'not-registered'
|
|
10
|
+
/** Not `dead` or `replayed`: done, or still in flight. */
|
|
11
|
+
| 'not-replayable';
|
|
12
|
+
export type ReplayResult = {
|
|
13
|
+
readonly found: false;
|
|
14
|
+
} | {
|
|
15
|
+
readonly found: true;
|
|
16
|
+
readonly tasks: readonly {
|
|
17
|
+
readonly action: string;
|
|
18
|
+
readonly outcome: ReplayOutcome;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
export type ReplayDeps = Pick<Toolkit<unknown, WebhookMessage>, 'journal' | 'clock' | 'logger' | 'blobStore' | 'webhookQueue'>;
|
|
22
|
+
/**
|
|
23
|
+
* Re-queues a delivery's tasks: each `dead` one moves to `replayed`, and an
|
|
24
|
+
* Action registered since the delivery arrived gets its task, which backfills
|
|
25
|
+
* it. Each sends one message, and the consumer reads the raw body again from
|
|
26
|
+
* the blob store. `actions` narrows it, `[name]` to one task; the default is
|
|
27
|
+
* every Action the registry has for the delivery's topic.
|
|
28
|
+
*
|
|
29
|
+
* Journaled as a `replay` run with one unit per task, `actor` in its
|
|
30
|
+
* `externalIds` (docs/operator-ledger.md §4). An Action that already did its
|
|
31
|
+
* work is kept from doing it twice by its own `once()` keys, not by replay.
|
|
32
|
+
*
|
|
33
|
+
* A send that rejects leaves the task `replayed` and rejects; replaying it
|
|
34
|
+
* again sends it again.
|
|
35
|
+
*/
|
|
36
|
+
export declare function replayWebhooks<Deps>(deps: ReplayDeps, registry: WebhookRegistry<Deps>, deliveryId: string, options: {
|
|
37
|
+
readonly actions?: readonly string[];
|
|
38
|
+
readonly actor: string;
|
|
39
|
+
}): Promise<ReplayResult>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { runAction, withRun } from '../actions/run-action.js';
|
|
2
|
+
import { skipped, written } from '../actions/action.js';
|
|
3
|
+
/**
|
|
4
|
+
* Re-queues a delivery's tasks: each `dead` one moves to `replayed`, and an
|
|
5
|
+
* Action registered since the delivery arrived gets its task, which backfills
|
|
6
|
+
* it. Each sends one message, and the consumer reads the raw body again from
|
|
7
|
+
* the blob store. `actions` narrows it, `[name]` to one task; the default is
|
|
8
|
+
* every Action the registry has for the delivery's topic.
|
|
9
|
+
*
|
|
10
|
+
* Journaled as a `replay` run with one unit per task, `actor` in its
|
|
11
|
+
* `externalIds` (docs/operator-ledger.md §4). An Action that already did its
|
|
12
|
+
* work is kept from doing it twice by its own `once()` keys, not by replay.
|
|
13
|
+
*
|
|
14
|
+
* A send that rejects leaves the task `replayed` and rejects; replaying it
|
|
15
|
+
* again sends it again.
|
|
16
|
+
*/
|
|
17
|
+
export async function replayWebhooks(deps, registry, deliveryId, options) {
|
|
18
|
+
const { journal, clock, blobStore, webhookQueue } = deps;
|
|
19
|
+
const found = await journal.delivery(deliveryId);
|
|
20
|
+
const externalIds = { actor: options.actor };
|
|
21
|
+
return withRun(deps, { job: 'webhooks.replay', trigger: 'replay', mode: 'live' }, async (scope) => {
|
|
22
|
+
if (found === undefined) {
|
|
23
|
+
await runAction(unit(deliveryId, async () => skipped('not-found', { externalIds })), deliveryId, scope, null);
|
|
24
|
+
return { found: false };
|
|
25
|
+
}
|
|
26
|
+
const { delivery, tasks } = found;
|
|
27
|
+
const registered = registry
|
|
28
|
+
.actionsFor(delivery.source, delivery.topic)
|
|
29
|
+
.map((r) => r.action.name);
|
|
30
|
+
// Checked before any task moves, so a swept body moves none. A sweep
|
|
31
|
+
// racing this leaves a replayed task whose run fails visibly (#141).
|
|
32
|
+
const hasBody = (await blobStore.get(delivery.bodyKey)) !== undefined;
|
|
33
|
+
const results = [];
|
|
34
|
+
for (const action of options.actions ?? registered) {
|
|
35
|
+
const outcome = await replayOne(action);
|
|
36
|
+
results.push({ action, outcome });
|
|
37
|
+
await runAction(unit(`${deliveryId}:${action}`, async () => outcome === 'replayed'
|
|
38
|
+
? written({ externalIds })
|
|
39
|
+
: skipped(outcome, { externalIds })), action, scope, null);
|
|
40
|
+
}
|
|
41
|
+
return { found: true, tasks: results };
|
|
42
|
+
async function replayOne(action) {
|
|
43
|
+
if (!registered.includes(action)) {
|
|
44
|
+
return 'not-registered';
|
|
45
|
+
}
|
|
46
|
+
if (!hasBody) {
|
|
47
|
+
return 'body-missing';
|
|
48
|
+
}
|
|
49
|
+
const task = tasks.find((t) => t.action === action);
|
|
50
|
+
if (task === undefined) {
|
|
51
|
+
await journal.recordDelivery(delivery, [action]);
|
|
52
|
+
}
|
|
53
|
+
else if (
|
|
54
|
+
// Already `replayed`: an earlier replay's send may have failed, and
|
|
55
|
+
// nothing else re-sends it. A second message is safe: once() keys.
|
|
56
|
+
task.state !== 'replayed' &&
|
|
57
|
+
!(await journal.moveTask(deliveryId, action, 'replayed', clock.now()))) {
|
|
58
|
+
return 'not-replayable';
|
|
59
|
+
}
|
|
60
|
+
const { source, topic, shop, webhookId, bodyKey } = delivery;
|
|
61
|
+
await webhookQueue.send({
|
|
62
|
+
source,
|
|
63
|
+
topic,
|
|
64
|
+
shop,
|
|
65
|
+
webhookId,
|
|
66
|
+
bodyKey,
|
|
67
|
+
action,
|
|
68
|
+
});
|
|
69
|
+
return 'replayed';
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** One replay unit, keyed by its task, whose decision was made before it runs. */
|
|
74
|
+
const unit = (key, decide) => ({
|
|
75
|
+
name: 'webhooks.replay',
|
|
76
|
+
unitType: 'webhook-task',
|
|
77
|
+
key: () => key,
|
|
78
|
+
run: decide,
|
|
79
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface SignShopifyWebhookOptions {
|
|
2
|
+
url: string | URL;
|
|
3
|
+
secret: string;
|
|
4
|
+
topic: string;
|
|
5
|
+
shop: string;
|
|
6
|
+
/** An object is serialized once; the signature covers the bytes sent. */
|
|
7
|
+
body: string | Uint8Array<ArrayBuffer> | ArrayBuffer | object;
|
|
8
|
+
deliveryId?: string;
|
|
9
|
+
/** Omitted when unset, because only `Clock` reads the time. */
|
|
10
|
+
triggeredAt?: string;
|
|
11
|
+
apiVersion?: string;
|
|
12
|
+
}
|
|
13
|
+
/** A POST signed the way Shopify signs a webhook delivery: base64 HMAC-SHA256 of the raw body. */
|
|
14
|
+
export declare function signShopifyWebhook({ url, secret, topic, shop, body, deliveryId, triggeredAt, apiVersion, }: SignShopifyWebhookOptions): Promise<Request>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Self-contained, with no relative imports, so plain `.mjs` scripts can load
|
|
2
|
+
// it through Node's type stripping (#129).
|
|
3
|
+
/** A POST signed the way Shopify signs a webhook delivery: base64 HMAC-SHA256 of the raw body. */
|
|
4
|
+
export async function signShopifyWebhook({ url, secret, topic, shop, body, deliveryId = crypto.randomUUID(), triggeredAt, apiVersion = '2026-10', }) {
|
|
5
|
+
// JSON.stringify turns these into "{}", which would be signed and sent silently.
|
|
6
|
+
if (body instanceof Blob || body instanceof ReadableStream) {
|
|
7
|
+
throw new TypeError('body must be a string, bytes or a JSON object');
|
|
8
|
+
}
|
|
9
|
+
const encoder = new TextEncoder();
|
|
10
|
+
const bytes = typeof body === 'string'
|
|
11
|
+
? encoder.encode(body)
|
|
12
|
+
: body instanceof Uint8Array
|
|
13
|
+
? body
|
|
14
|
+
: body instanceof ArrayBuffer
|
|
15
|
+
? new Uint8Array(body)
|
|
16
|
+
: encoder.encode(JSON.stringify(body));
|
|
17
|
+
const key = await crypto.subtle.importKey('raw', encoder.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
|
|
18
|
+
const mac = new Uint8Array(await crypto.subtle.sign('HMAC', key, bytes));
|
|
19
|
+
const headers = new Headers({
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
'X-Shopify-Hmac-Sha256': btoa(String.fromCharCode(...mac)),
|
|
22
|
+
'X-Shopify-Topic': topic,
|
|
23
|
+
'X-Shopify-Shop-Domain': shop,
|
|
24
|
+
'X-Shopify-API-Version': apiVersion,
|
|
25
|
+
'X-Shopify-Webhook-Id': deliveryId,
|
|
26
|
+
});
|
|
27
|
+
if (triggeredAt !== undefined) {
|
|
28
|
+
headers.set('X-Shopify-Triggered-At', triggeredAt);
|
|
29
|
+
}
|
|
30
|
+
return new Request(url, { method: 'POST', headers, body: bytes });
|
|
31
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { QueueBatch, QueueConsumer, QueueMessage, Toolkit } from '../contracts/index.js';
|
|
2
|
+
import type { Action } from '../actions/action.js';
|
|
3
|
+
import type { JournalDeps } from '../actions/run-action.js';
|
|
4
|
+
import { type ActionConsumerOptions } from '../actions/action-consumer.js';
|
|
5
|
+
import { type WebhookMessage } from './create-webhook-handler.js';
|
|
6
|
+
import type { WebhookRegistry } from './define-registry.js';
|
|
7
|
+
export type WebhookConsumerOptions<Deps> = Omit<ActionConsumerOptions<Deps>, 'job' | 'toolkit'> & {
|
|
8
|
+
/** Also reads each raw body from `blobStore`, where the edge wrote it. */
|
|
9
|
+
readonly toolkit: JournalDeps & Pick<Toolkit, 'blobStore'>;
|
|
10
|
+
/** The same registry the edge takes. Its entries may override `retryDelaySeconds` and `maxAttempts`. */
|
|
11
|
+
readonly registry: WebhookRegistry<Deps>;
|
|
12
|
+
};
|
|
13
|
+
/** The consumer's options, with one Action's retry settings applied. */
|
|
14
|
+
export type WebhookSettleOptions<Deps> = Omit<WebhookConsumerOptions<Deps>, 'registry'> & {
|
|
15
|
+
/** The queue's own limit; `maxAttempts` is the Action's, at most this. */
|
|
16
|
+
readonly queueMaxAttempts: number;
|
|
17
|
+
};
|
|
18
|
+
/** One topic's Action, with the parse that turns a raw body into its input. */
|
|
19
|
+
export type WebhookAction<Deps> = {
|
|
20
|
+
/** The Action's name, which names its task in the delivery's receipt. */
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly settle: (batch: QueueBatch<WebhookMessage>, message: QueueMessage<WebhookMessage>, options: WebhookSettleOptions<Deps>) => Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Binds `action` to its `parse`. A missing body or a throw from `parse` is a
|
|
26
|
+
* fault: the message is retried and, after the last attempt, dead-lettered
|
|
27
|
+
* with no unit.
|
|
28
|
+
*
|
|
29
|
+
* Moves the delivery's task in the journal around the run: `processing`
|
|
30
|
+
* first, then `done` when the message is acked, `failed` when it is retried,
|
|
31
|
+
* or `dead` on the Action's last attempt, the latter two with the reason:
|
|
32
|
+
* the last retryable reason code, or `fault` for a throw. A dead task's message is retried
|
|
33
|
+
* only on the queue's last attempt too, so the queue dead-letters it, and is
|
|
34
|
+
* acked before that. These are required writes, so one
|
|
35
|
+
* that throws retries the message rather than ack it. A task that cannot move
|
|
36
|
+
* to `processing`, because it is already `done` or was never receipted, is
|
|
37
|
+
* logged and acked without running.
|
|
38
|
+
*/
|
|
39
|
+
export declare function webhookAction<Input, Reason extends string, Deps>(action: Action<Input, Reason, Deps>, parse: (body: string, message: WebhookMessage) => Input): WebhookAction<Deps>;
|
|
40
|
+
/**
|
|
41
|
+
* The consumer of `toolkit.webhookQueue`: each message runs the one Action it
|
|
42
|
+
* names and is acked or retried on its own (`settleActionMessage`), so one
|
|
43
|
+
* Action failing does not hold back another for the same delivery. A message
|
|
44
|
+
* whose Action is not registered is logged and acked, never retried: design
|
|
45
|
+
* §7.1. Throws when an Action's `maxAttempts` is above the queue's.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createWebhookConsumer<Deps>({ registry, ...options }: WebhookConsumerOptions<Deps>): QueueConsumer<WebhookMessage>;
|
|
48
|
+
export type { WebhookMessage } from './create-webhook-handler.js';
|
|
49
|
+
export { defineRegistry, WEBHOOK_MAX_ACTIONS_PER_TOPIC, type WebhookRegistration, type WebhookRegistry, type WebhookTopicSettings, } from './define-registry.js';
|
|
50
|
+
export { createDeadLetterConsumer } from './dead-letter-consumer.js';
|
|
51
|
+
export { replayWebhooks, type ReplayDeps, type ReplayOutcome, type ReplayResult, } from './replay-webhooks.js';
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { retryDelayFor, settleActionMessage, } from '../actions/action-consumer.js';
|
|
2
|
+
import { webhookDeliveryId, } from './create-webhook-handler.js';
|
|
3
|
+
/**
|
|
4
|
+
* Binds `action` to its `parse`. A missing body or a throw from `parse` is a
|
|
5
|
+
* fault: the message is retried and, after the last attempt, dead-lettered
|
|
6
|
+
* with no unit.
|
|
7
|
+
*
|
|
8
|
+
* Moves the delivery's task in the journal around the run: `processing`
|
|
9
|
+
* first, then `done` when the message is acked, `failed` when it is retried,
|
|
10
|
+
* or `dead` on the Action's last attempt, the latter two with the reason:
|
|
11
|
+
* the last retryable reason code, or `fault` for a throw. A dead task's message is retried
|
|
12
|
+
* only on the queue's last attempt too, so the queue dead-letters it, and is
|
|
13
|
+
* acked before that. These are required writes, so one
|
|
14
|
+
* that throws retries the message rather than ack it. A task that cannot move
|
|
15
|
+
* to `processing`, because it is already `done` or was never receipted, is
|
|
16
|
+
* logged and acked without running.
|
|
17
|
+
*/
|
|
18
|
+
export function webhookAction(action, parse) {
|
|
19
|
+
return {
|
|
20
|
+
name: action.name,
|
|
21
|
+
settle: async (batch, message, options) => {
|
|
22
|
+
const { journal, clock, logger } = options.toolkit;
|
|
23
|
+
const deliveryId = webhookDeliveryId(message.body);
|
|
24
|
+
const context = { deliveryId, action: action.name, messageId: message.id };
|
|
25
|
+
const move = async (to, reasonCode) => journal.moveTask(deliveryId, action.name, to, clock.now(), reasonCode);
|
|
26
|
+
const retry = () => {
|
|
27
|
+
batch.retry(message.id, {
|
|
28
|
+
delaySeconds: retryDelayFor(message.attempt, options.retryDelaySeconds),
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
try {
|
|
32
|
+
if (!(await move('processing'))) {
|
|
33
|
+
logger.warn('webhook task not runnable', context);
|
|
34
|
+
batch.ack(message.id);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
logger.error('webhook receipt failed', {
|
|
40
|
+
...context,
|
|
41
|
+
error: String(error),
|
|
42
|
+
});
|
|
43
|
+
retry();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// Held until the receipt says how the message was settled.
|
|
47
|
+
let settled;
|
|
48
|
+
const reason = await settleActionMessage({
|
|
49
|
+
messages: batch.messages,
|
|
50
|
+
ack: () => {
|
|
51
|
+
settled = {};
|
|
52
|
+
},
|
|
53
|
+
retry: (_id, retryOptions) => {
|
|
54
|
+
settled = { retry: retryOptions };
|
|
55
|
+
},
|
|
56
|
+
}, message, action, async (body) => {
|
|
57
|
+
const bytes = await options.toolkit.blobStore.get(body.bodyKey);
|
|
58
|
+
if (bytes === undefined) {
|
|
59
|
+
throw new Error(`webhook body missing: ${body.bodyKey}`);
|
|
60
|
+
}
|
|
61
|
+
return parse(new TextDecoder().decode(bytes), body);
|
|
62
|
+
}, { ...options, job: `queue.${action.name}` });
|
|
63
|
+
const acked = settled !== undefined && !('retry' in settled);
|
|
64
|
+
const dead = !acked && message.attempt >= options.maxAttempts;
|
|
65
|
+
try {
|
|
66
|
+
await move(acked ? 'done' : dead ? 'dead' : 'failed', reason);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
logger.error('webhook receipt failed', {
|
|
70
|
+
...context,
|
|
71
|
+
error: String(error),
|
|
72
|
+
});
|
|
73
|
+
retry();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (acked || (dead && message.attempt < options.queueMaxAttempts)) {
|
|
77
|
+
batch.ack(message.id);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
batch.retry(message.id, settled?.retry);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The consumer of `toolkit.webhookQueue`: each message runs the one Action it
|
|
87
|
+
* names and is acked or retried on its own (`settleActionMessage`), so one
|
|
88
|
+
* Action failing does not hold back another for the same delivery. A message
|
|
89
|
+
* whose Action is not registered is logged and acked, never retried: design
|
|
90
|
+
* §7.1. Throws when an Action's `maxAttempts` is above the queue's.
|
|
91
|
+
*/
|
|
92
|
+
export function createWebhookConsumer({ registry, ...options }) {
|
|
93
|
+
for (const { source, topic, action, maxAttempts } of registry.actions) {
|
|
94
|
+
if (maxAttempts !== undefined && maxAttempts > options.maxAttempts) {
|
|
95
|
+
throw new TypeError(`webhooks: ${source} ${topic} ${action.name} maxAttempts (${maxAttempts}) is above the queue's (${options.maxAttempts})`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return async (batch) => {
|
|
99
|
+
for (const message of batch.messages) {
|
|
100
|
+
const { source, topic, shop, webhookId, action } = message.body;
|
|
101
|
+
const registration = registry
|
|
102
|
+
.actionsFor(source, topic)
|
|
103
|
+
.find((entry) => entry.action.name === action);
|
|
104
|
+
if (registration !== undefined) {
|
|
105
|
+
await registration.action.settle(batch, message, {
|
|
106
|
+
...options,
|
|
107
|
+
retryDelaySeconds: registration.retryDelaySeconds ?? options.retryDelaySeconds,
|
|
108
|
+
maxAttempts: registration.maxAttempts ?? options.maxAttempts,
|
|
109
|
+
queueMaxAttempts: options.maxAttempts,
|
|
110
|
+
});
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
options.toolkit.logger.warn('webhook action not registered', {
|
|
114
|
+
source,
|
|
115
|
+
topic,
|
|
116
|
+
action,
|
|
117
|
+
shop,
|
|
118
|
+
webhookId,
|
|
119
|
+
messageId: message.id,
|
|
120
|
+
});
|
|
121
|
+
batch.ack(message.id);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export { defineRegistry, WEBHOOK_MAX_ACTIONS_PER_TOPIC, } from './define-registry.js';
|
|
126
|
+
export { createDeadLetterConsumer } from './dead-letter-consumer.js';
|
|
127
|
+
export { replayWebhooks, } from './replay-webhooks.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- The idempotency ledger. One row per claimed key, and nothing else: there is
|
|
2
|
+
-- no get(), no list() and no query surface, because adding one turns this into
|
|
3
|
+
-- the run journal. See src/contracts/ledger.ts.
|
|
4
|
+
--
|
|
5
|
+
-- `key` is the PRIMARY KEY, and that is the whole concurrency story. Two
|
|
6
|
+
-- concurrent claims on one key cannot both insert, so the winner is decided by
|
|
7
|
+
-- the schema rather than by anything the adapter remembers to do.
|
|
8
|
+
--
|
|
9
|
+
-- Both timestamps are epoch milliseconds, written by the caller from the
|
|
10
|
+
-- injected Clock. Deliberately NOT `DEFAULT CURRENT_TIMESTAMP`: the conformance
|
|
11
|
+
-- suite advances a test clock by 11 seconds and expects a reclaim, and a
|
|
12
|
+
-- schema-side clock cannot be advanced.
|
|
13
|
+
CREATE TABLE ledger_claims (
|
|
14
|
+
key TEXT PRIMARY KEY,
|
|
15
|
+
claimed_at INTEGER NOT NULL,
|
|
16
|
+
expires_at INTEGER NOT NULL
|
|
17
|
+
) STRICT;
|
|
18
|
+
|
|
19
|
+
-- Serves nothing the Ledger interface exposes — there is no query that reads by
|
|
20
|
+
-- expiry. It exists for the operational sweep of rows whose lease ended long
|
|
21
|
+
-- ago, which is not part of this interface and should not need a table scan
|
|
22
|
+
-- when somebody writes it.
|
|
23
|
+
CREATE INDEX ledger_claims_expires_at ON ledger_claims (expires_at);
|