@pithy-sh/auth 0.10.0 → 0.12.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 +30 -2
- package/dist/admin/users.js +1 -1
- package/dist/audit/actions.d.ts +58 -0
- package/dist/audit/actions.d.ts.map +1 -1
- package/dist/audit/actions.js +59 -1
- package/dist/audit/emit.d.ts +36 -0
- package/dist/audit/emit.d.ts.map +1 -1
- package/dist/audit/emit.js +48 -2
- package/dist/audit/evidence.d.ts +8 -2
- package/dist/audit/evidence.d.ts.map +1 -1
- package/dist/capability.d.ts +47 -8
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +56 -6
- package/dist/client/api.d.ts +55 -12
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +57 -18
- package/dist/client/bearer.d.ts +110 -0
- package/dist/client/bearer.d.ts.map +1 -0
- package/dist/client/bearer.js +265 -0
- package/dist/client/handoff.d.ts +77 -0
- package/dist/client/handoff.d.ts.map +1 -0
- package/dist/client/handoff.js +119 -0
- package/dist/client/mcp.d.ts +70 -0
- package/dist/client/mcp.d.ts.map +1 -0
- package/dist/client/mcp.js +65 -0
- package/dist/data/betterAuth.d.ts +3 -2
- package/dist/data/betterAuth.d.ts.map +1 -1
- package/dist/data/betterAuth.js +5 -3
- package/dist/data/kitFields.d.ts +5 -0
- package/dist/data/kitFields.d.ts.map +1 -1
- package/dist/data/kitFields.js +5 -0
- package/dist/data/tables.d.ts +26 -4
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/tables.js +5 -3
- package/dist/data/userLifecycle.d.ts +10 -0
- package/dist/data/userLifecycle.d.ts.map +1 -1
- package/dist/data/userLifecycle.js +8 -3
- package/dist/data/verificationOutcome.d.ts +53 -0
- package/dist/data/verificationOutcome.d.ts.map +1 -0
- package/dist/data/verificationOutcome.js +50 -0
- package/dist/email/send.js +6 -2
- package/dist/http/adminRoutes.d.ts.map +1 -1
- package/dist/http/adminRoutes.js +319 -8
- package/dist/http/csrf.d.ts.map +1 -1
- package/dist/http/csrf.js +2 -1
- package/dist/http/guards.d.ts +15 -10
- package/dist/http/guards.d.ts.map +1 -1
- package/dist/http/guards.js +76 -10
- package/dist/http/handoff.d.ts +76 -0
- package/dist/http/handoff.d.ts.map +1 -0
- package/dist/http/handoff.js +316 -0
- package/dist/http/middleware.d.ts +37 -1
- package/dist/http/middleware.d.ts.map +1 -1
- package/dist/http/middleware.js +68 -6
- package/dist/http/resolve.d.ts.map +1 -1
- package/dist/http/resolve.js +9 -3
- package/dist/http/responses.d.ts +322 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +202 -5
- package/dist/http/routes.d.ts +3 -0
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +78 -5
- package/dist/http/schemas.d.ts +114 -0
- package/dist/http/schemas.d.ts.map +1 -1
- package/dist/http/schemas.js +94 -1
- package/dist/http/views.d.ts +60 -3
- package/dist/http/views.d.ts.map +1 -1
- package/dist/http/views.js +143 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/instance/auth.d.ts +148 -10
- package/dist/instance/auth.d.ts.map +1 -1
- package/dist/instance/auth.js +87 -42
- package/dist/instance/plugins.d.ts +6 -0
- package/dist/instance/plugins.d.ts.map +1 -1
- package/dist/instance/plugins.js +14 -1
- package/dist/ledger/read.d.ts +53 -0
- package/dist/ledger/read.d.ts.map +1 -0
- package/dist/ledger/read.js +85 -0
- package/dist/ledger/record.d.ts +35 -0
- package/dist/ledger/record.d.ts.map +1 -0
- package/dist/ledger/record.js +98 -0
- package/dist/lifecycle/audited.d.ts +48 -0
- package/dist/lifecycle/audited.d.ts.map +1 -0
- package/dist/lifecycle/audited.js +65 -0
- package/dist/lifecycle/enforce.d.ts +37 -2
- package/dist/lifecycle/enforce.d.ts.map +1 -1
- package/dist/lifecycle/enforce.js +46 -5
- package/dist/lifecycle/erasure.d.ts +9 -0
- package/dist/lifecycle/erasure.d.ts.map +1 -0
- package/dist/lifecycle/erasure.js +96 -0
- package/dist/lifecycle/inactivity.d.ts +19 -0
- package/dist/lifecycle/inactivity.d.ts.map +1 -0
- package/dist/lifecycle/inactivity.js +28 -0
- package/dist/lifecycle/reason.d.ts +11 -0
- package/dist/lifecycle/reason.d.ts.map +1 -0
- package/dist/lifecycle/reason.js +13 -0
- package/dist/lifecycle/request.d.ts +5 -2
- package/dist/lifecycle/request.d.ts.map +1 -1
- package/dist/lifecycle/request.js +6 -2
- package/dist/lifecycle/transitions.d.ts +179 -18
- package/dist/lifecycle/transitions.d.ts.map +1 -1
- package/dist/lifecycle/transitions.js +391 -70
- package/dist/mcp/argumentClass.d.ts +51 -0
- package/dist/mcp/argumentClass.d.ts.map +1 -0
- package/dist/mcp/argumentClass.js +69 -0
- package/dist/mcp/capability.d.ts +50 -0
- package/dist/mcp/capability.d.ts.map +1 -0
- package/dist/mcp/capability.js +140 -0
- package/dist/mcp/clientMetadata.d.ts +40 -0
- package/dist/mcp/clientMetadata.d.ts.map +1 -0
- package/dist/mcp/clientMetadata.js +68 -0
- package/dist/mcp/consent.d.ts +49 -0
- package/dist/mcp/consent.d.ts.map +1 -0
- package/dist/mcp/consent.js +69 -0
- package/dist/mcp/dispatch.d.ts +35 -0
- package/dist/mcp/dispatch.d.ts.map +1 -0
- package/dist/mcp/dispatch.js +135 -0
- package/dist/mcp/floor.d.ts +37 -0
- package/dist/mcp/floor.d.ts.map +1 -0
- package/dist/mcp/floor.js +41 -0
- package/dist/mcp/host.d.ts +34 -0
- package/dist/mcp/host.d.ts.map +1 -0
- package/dist/mcp/host.js +2 -0
- package/dist/mcp/http/redirectList.d.ts +9 -0
- package/dist/mcp/http/redirectList.d.ts.map +1 -0
- package/dist/mcp/http/redirectList.js +24 -0
- package/dist/mcp/http/responses.d.ts +143 -0
- package/dist/mcp/http/responses.d.ts.map +1 -0
- package/dist/mcp/http/responses.js +83 -0
- package/dist/mcp/http/routes.d.ts +28 -0
- package/dist/mcp/http/routes.d.ts.map +1 -0
- package/dist/mcp/http/routes.js +517 -0
- package/dist/mcp/http/schemas.d.ts +24 -0
- package/dist/mcp/http/schemas.d.ts.map +1 -0
- package/dist/mcp/http/schemas.js +18 -0
- package/dist/mcp/marker.d.ts +15 -0
- package/dist/mcp/marker.d.ts.map +1 -0
- package/dist/mcp/marker.js +15 -0
- package/dist/mcp/provider.d.ts +78 -0
- package/dist/mcp/provider.d.ts.map +1 -0
- package/dist/mcp/provider.js +108 -0
- package/dist/mcp/purge.d.ts +15 -0
- package/dist/mcp/purge.d.ts.map +1 -0
- package/dist/mcp/purge.js +31 -0
- package/dist/mcp/rpc.d.ts +79 -0
- package/dist/mcp/rpc.d.ts.map +1 -0
- package/dist/mcp/rpc.js +103 -0
- package/dist/mcp/toolAudit.d.ts +76 -0
- package/dist/mcp/toolAudit.d.ts.map +1 -0
- package/dist/mcp/toolAudit.js +86 -0
- package/dist/migrations/0005_purge_once.d.ts +22 -0
- package/dist/migrations/0005_purge_once.d.ts.map +1 -0
- package/dist/migrations/0005_purge_once.js +35 -0
- package/dist/migrations/0006_verification_outcomes.d.ts +15 -0
- package/dist/migrations/0006_verification_outcomes.d.ts.map +1 -0
- package/dist/migrations/0006_verification_outcomes.js +35 -0
- package/dist/migrations/0007_erasure_record.d.ts +17 -0
- package/dist/migrations/0007_erasure_record.d.ts.map +1 -0
- package/dist/migrations/0007_erasure_record.js +36 -0
- package/dist/migrations/0008_last_active.d.ts +15 -0
- package/dist/migrations/0008_last_active.d.ts.map +1 -0
- package/dist/migrations/0008_last_active.js +29 -0
- package/dist/migrations/pluginTables.d.ts +8 -0
- package/dist/migrations/pluginTables.d.ts.map +1 -1
- package/dist/migrations/pluginTables.js +8 -1
- package/dist/migrations/set.d.ts +5 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +10 -2
- package/dist/peer.d.ts +3 -2
- package/dist/peer.d.ts.map +1 -1
- package/dist/processing/activities.d.ts +6 -0
- package/dist/processing/activities.d.ts.map +1 -0
- package/dist/processing/activities.js +12 -0
- package/dist/purge/contribution.d.ts +62 -0
- package/dist/purge/contribution.d.ts.map +1 -0
- package/dist/purge/contribution.js +155 -0
- package/dist/purge/retryPolicy.d.ts +22 -0
- package/dist/purge/retryPolicy.d.ts.map +1 -0
- package/dist/purge/retryPolicy.js +26 -0
- package/dist/purge/run.d.ts +158 -0
- package/dist/purge/run.d.ts.map +1 -0
- package/dist/purge/run.js +205 -0
- package/dist/purge/specs.d.ts +71 -0
- package/dist/purge/specs.d.ts.map +1 -0
- package/dist/purge/specs.js +72 -0
- package/dist/purge/start.d.ts +42 -0
- package/dist/purge/start.d.ts.map +1 -0
- package/dist/purge/start.js +37 -0
- package/dist/purge/workflow.d.ts +71 -0
- package/dist/purge/workflow.d.ts.map +1 -0
- package/dist/purge/workflow.js +140 -0
- package/dist/test-utils/accountFootprint.d.ts +13 -0
- package/dist/test-utils/accountFootprint.d.ts.map +1 -0
- package/dist/test-utils/accountFootprint.js +49 -0
- package/dist/test-utils/liveApp.d.ts +6 -0
- package/dist/test-utils/liveApp.d.ts.map +1 -1
- package/dist/test-utils/liveApp.js +7 -2
- package/dist/token/handoff.d.ts +80 -0
- package/dist/token/handoff.d.ts.map +1 -0
- package/dist/token/handoff.js +136 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/account-lifecycle.md +176 -12
- package/docs/apple-signin.md +32 -4
- package/docs/facebook-oauth.md +2 -2
- package/docs/github-oauth.md +2 -2
- package/docs/google-oauth.md +9 -7
- package/docs/microsoft-oauth.md +2 -2
- package/package.json +11 -5
- package/pithy.manifest.json +2 -2
- package/pithy.mcp.manifest.json +36 -0
- package/src/audit/actions.ts +58 -0
- package/src/audit/emit.ts +66 -1
- package/src/audit/evidence.ts +8 -4
- package/src/capability.ts +122 -18
- package/src/client/api.ts +69 -19
- package/src/client/bearer.ts +388 -0
- package/src/client/handoff.ts +172 -0
- package/src/client/mcp.ts +140 -0
- package/src/data/betterAuth.ts +8 -4
- package/src/data/kitFields.ts +2 -0
- package/src/data/tables.ts +4 -2
- package/src/data/userLifecycle.ts +19 -4
- package/src/data/verificationOutcome.ts +86 -0
- package/src/email/send.ts +2 -2
- package/src/http/adminRoutes.ts +465 -4
- package/src/http/csrf.ts +4 -1
- package/src/http/guards.ts +79 -10
- package/src/http/handoff.ts +350 -0
- package/src/http/middleware.ts +74 -5
- package/src/http/resolve.ts +25 -25
- package/src/http/responses.ts +374 -3
- package/src/http/routes.ts +116 -5
- package/src/http/schemas.ts +195 -0
- package/src/http/views.ts +192 -3
- package/src/index.ts +2 -0
- package/src/instance/auth.ts +58 -3
- package/src/instance/plugins.ts +20 -2
- package/src/ledger/read.ts +133 -0
- package/src/ledger/record.ts +198 -0
- package/src/lifecycle/audited.ts +104 -0
- package/src/lifecycle/enforce.ts +55 -5
- package/src/lifecycle/erasure.ts +118 -0
- package/src/lifecycle/inactivity.ts +56 -0
- package/src/lifecycle/reason.ts +11 -0
- package/src/lifecycle/request.ts +10 -2
- package/src/lifecycle/transitions.ts +552 -93
- package/src/mcp/argumentClass.ts +112 -0
- package/src/mcp/capability.ts +194 -0
- package/src/mcp/clientMetadata.ts +81 -0
- package/src/mcp/consent.ts +95 -0
- package/src/mcp/dispatch.ts +154 -0
- package/src/mcp/floor.ts +62 -0
- package/src/mcp/host.ts +36 -0
- package/src/mcp/http/redirectList.ts +26 -0
- package/src/mcp/http/responses.ts +157 -0
- package/src/mcp/http/routes.ts +635 -0
- package/src/mcp/http/schemas.ts +37 -0
- package/src/mcp/marker.ts +18 -0
- package/src/mcp/provider.ts +151 -0
- package/src/mcp/purge.ts +39 -0
- package/src/mcp/rpc.ts +135 -0
- package/src/mcp/toolAudit.ts +132 -0
- package/src/migrations/0005_purge_once.ts +42 -0
- package/src/migrations/0006_verification_outcomes.ts +51 -0
- package/src/migrations/0007_erasure_record.ts +43 -0
- package/src/migrations/0008_last_active.ts +30 -0
- package/src/migrations/pluginTables.ts +19 -1
- package/src/migrations/set.ts +9 -1
- package/src/processing/activities.ts +14 -0
- package/src/purge/contribution.ts +218 -0
- package/src/purge/retryPolicy.ts +26 -0
- package/src/purge/run.ts +348 -0
- package/src/purge/specs.ts +95 -0
- package/src/purge/start.ts +79 -0
- package/src/purge/workflow.ts +202 -0
- package/src/seeds/example.ts +2 -2
- package/src/test-utils/accountFootprint.ts +104 -0
- package/src/test-utils/liveApp.ts +10 -1
- package/src/token/handoff.ts +180 -0
- package/src/version.generated.ts +1 -1
package/src/purge/run.ts
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { isRetained, type PurgeContext, type PurgeStep } from "@pithy-sh/core/src/capability/purge";
|
|
5
|
+
import type { LegalHolds } from "@pithy-sh/core/src/retention/holds";
|
|
6
|
+
import {
|
|
7
|
+
classifiedSteps,
|
|
8
|
+
type TerminalErrorConstructor,
|
|
9
|
+
type WorkflowStepLike,
|
|
10
|
+
} from "@pithy-sh/core/src/workflow/faults";
|
|
11
|
+
import {
|
|
12
|
+
completePurge,
|
|
13
|
+
type DuePurge,
|
|
14
|
+
duePurges,
|
|
15
|
+
type LifecycleDeps,
|
|
16
|
+
mailPurgeComplete,
|
|
17
|
+
purgeAddress,
|
|
18
|
+
purgeSubject,
|
|
19
|
+
recordPurgeFailure,
|
|
20
|
+
recordPurgeStep,
|
|
21
|
+
} from "../lifecycle/transitions";
|
|
22
|
+
import { authWorkflowRetry } from "./retryPolicy";
|
|
23
|
+
import { AUTH_CAPABILITY, type AuthPurgeDueParams, type AuthPurgeParams } from "./specs";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The purge, as steps (#622) — the bodies `./workflow.ts` hands a Workflow's step runner to.
|
|
27
|
+
*
|
|
28
|
+
* ## One step per contribution, and the order they run in
|
|
29
|
+
*
|
|
30
|
+
* 1. **`due`** — is the account deleted, and has its window closed? A restored account, one inside its window,
|
|
31
|
+
* and one already erased all end the run here, having erased nothing. This is the one check a cron-started
|
|
32
|
+
* purge and a hard deletion's both pass through, so re-running a purge for the same subject exits cleanly.
|
|
33
|
+
* 2. **`erase <capability>`** — one step per composed contribution, in composition order, each recording that it
|
|
34
|
+
* ran in `pithy_auth_user_lifecycle`. A contribution that **retains** its rows (#814) is a `retain <capability>`
|
|
35
|
+
* step instead: it erases nothing, and records `purge_retained` with the basis it gave. Handed to the platform's retry unclassified: an `erase` is idempotent by
|
|
36
|
+
* contract and runs code the kit did not write, so any fault in it is worth another attempt (`./retryPolicy.ts`).
|
|
37
|
+
* A failing contribution retries alone, and the ones that finished are served from the journal.
|
|
38
|
+
* 3. **`mail`** — the deletion-complete mail, **before the address is erased**: every other capability's rows are
|
|
39
|
+
* gone, and auth's, which hold the address, are not yet. The address is read in the step, never carried out of
|
|
40
|
+
* one, so it is in no Workflow's journal.
|
|
41
|
+
* 4. **`erase auth`** — auth's own contribution, last for that reason.
|
|
42
|
+
* 5. **`complete`** — the `purged` record, the audit event, `onUserPurged`. Once.
|
|
43
|
+
*
|
|
44
|
+
* Every step from 2 on records an audit event as well as its row (#823), which the erasure attestation cites.
|
|
45
|
+
*
|
|
46
|
+
* ## A legal hold stops it
|
|
47
|
+
*
|
|
48
|
+
* Before `due` hands over, and again before every step after it, the purge asks whether a legal hold stands on the
|
|
49
|
+
* account — each ask its own step, `hold <next>`, so a replay serves the answer it got. A hold found ends the run as
|
|
50
|
+
* `held`, having erased nothing more: the steps that finished stay finished, the rest wait. Released, the account is
|
|
51
|
+
* still deleted and still due, so the next daily pass starts a fresh purge, whose idempotent steps find nothing to
|
|
52
|
+
* erase where the first one did and carry on from there. A hold that cannot be read fails its step, which retries:
|
|
53
|
+
* a purge never erases past a hold it could not see.
|
|
54
|
+
*
|
|
55
|
+
* ## A purge that gives up says where (#823)
|
|
56
|
+
*
|
|
57
|
+
* A step that exhausts its retries fails the instance, and the daily pass starts a fresh one tomorrow. Until then the
|
|
58
|
+
* record would read as a purge still running. So the failure is caught once, recorded in its own `fail` step —
|
|
59
|
+
* the step it stopped at, in the history and the trail — and thrown on unchanged, so the instance still fails
|
|
60
|
+
* exactly as it did. A `fail` step that cannot write either is swallowed: the original failure is the one to report.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/** What a purge does with the account's own records — the transitions, over one set of dependencies. */
|
|
64
|
+
export interface PurgeOps {
|
|
65
|
+
/** Whether the account is due: deleted, with its window closed. `gone` when there is no account. */
|
|
66
|
+
due(userId: string): Promise<"due" | "not_due" | "gone">;
|
|
67
|
+
/** Record that one capability's step erased its rows. */
|
|
68
|
+
recordStep(userId: string, step: string, summary: string): Promise<void>;
|
|
69
|
+
/** Record that one capability's step kept its rows, and why (#814). */
|
|
70
|
+
recordRetained(userId: string, step: string, basis: string): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* The account's address, read now, or `null` once it is gone (#814). Handed to each step as
|
|
73
|
+
* `PurgeContext.address`, so a capability holding rows by address reads it inside its own step.
|
|
74
|
+
*/
|
|
75
|
+
address(userId: string): Promise<string | null>;
|
|
76
|
+
/**
|
|
77
|
+
* Send the deletion-complete mail to the account's address, if it is still there to read, unless this purge's
|
|
78
|
+
* `notify` or the deletion's own saved choice is false. Says whether.
|
|
79
|
+
*/
|
|
80
|
+
mailComplete(userId: string, notify: boolean | undefined): Promise<boolean>;
|
|
81
|
+
/** Write the `purged` record, the audit event and the hook. Says whether this call wrote them. */
|
|
82
|
+
complete(userId: string): Promise<boolean>;
|
|
83
|
+
/** Record that the purge gave up at `step`, in the history and the trail (#823). */
|
|
84
|
+
fail(userId: string, step: string): Promise<void>;
|
|
85
|
+
/** Whether a legal hold stands on the account. Throws when it cannot say. */
|
|
86
|
+
held(userId: string): Promise<boolean>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The operations, over the lifecycle transitions. */
|
|
90
|
+
export function purgeOps(deps: LifecycleDeps, holds: LegalHolds): PurgeOps {
|
|
91
|
+
return {
|
|
92
|
+
due: async (userId) => (await purgeSubject(deps, userId)).state,
|
|
93
|
+
recordStep: (userId, step, summary) => recordPurgeStep(deps, { userId, step, summary }),
|
|
94
|
+
recordRetained: (userId, step, basis) => recordPurgeStep(deps, { userId, step, summary: basis, retained: true }),
|
|
95
|
+
address: (userId) => purgeAddress(deps.db, userId),
|
|
96
|
+
mailComplete: async (userId, notify) => {
|
|
97
|
+
const subject = await purgeSubject(deps, userId);
|
|
98
|
+
if (subject.state !== "due") return false;
|
|
99
|
+
// Either can silence it: the parameter a hard deletion started this purge with, or the choice that deletion
|
|
100
|
+
// wrote on its history row — the one a purge the daily pass started still has (#622).
|
|
101
|
+
const silenced = notify === false || subject.notify === false;
|
|
102
|
+
return (await mailPurgeComplete(deps, { recipient: subject.recipient, ...(silenced ? { notify: false } : {}) }))
|
|
103
|
+
.mailed;
|
|
104
|
+
},
|
|
105
|
+
complete: async (userId) => (await completePurge(deps, { userId })).changed,
|
|
106
|
+
fail: (userId, step) => recordPurgeFailure(deps, { userId, step }),
|
|
107
|
+
held: (userId) => holds.held("user", userId),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** What one purge did: the account, how it ended, and the capabilities whose rows it erased. */
|
|
112
|
+
export interface PurgeOutcome {
|
|
113
|
+
/** The account. */
|
|
114
|
+
readonly userId: string;
|
|
115
|
+
/**
|
|
116
|
+
* `purged`; or why nothing was erased: `not_due` (restored, or inside its window) and `gone` (no account); or
|
|
117
|
+
* `held`, a legal hold stopped it before the step it would have run next.
|
|
118
|
+
*/
|
|
119
|
+
readonly state: "purged" | "not_due" | "gone" | "held";
|
|
120
|
+
/** Every step that erased its rows, in the order it ran. Empty when nothing was erased. */
|
|
121
|
+
readonly erased: readonly string[];
|
|
122
|
+
/** Every step that kept its rows under a stated basis (#814), in the order it ran. */
|
|
123
|
+
readonly retained: readonly string[];
|
|
124
|
+
/** Whether the deletion-complete mail was enqueued. */
|
|
125
|
+
readonly mailed: boolean;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** What one purge reads its plan from: the composed contributions, this run's env, and its operations. */
|
|
129
|
+
export interface PurgeRun {
|
|
130
|
+
/** Every composed purge step for `user`, auth's own among them. */
|
|
131
|
+
readonly steps: readonly PurgeStep[];
|
|
132
|
+
/** This run's bindings, handed to each contribution. */
|
|
133
|
+
readonly env: Record<string, unknown>;
|
|
134
|
+
/** The account's own records. */
|
|
135
|
+
readonly ops: PurgeOps;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Run one account's purge, one step per contribution, auth's last. See the file header for the order. */
|
|
139
|
+
export async function purgeUser(
|
|
140
|
+
run: PurgeRun,
|
|
141
|
+
step: WorkflowStepLike,
|
|
142
|
+
terminalError: TerminalErrorConstructor,
|
|
143
|
+
params: AuthPurgeParams,
|
|
144
|
+
): Promise<PurgeOutcome> {
|
|
145
|
+
const own = classifiedSteps(step, authWorkflowRetry, terminalError);
|
|
146
|
+
const userId = params.userId;
|
|
147
|
+
const state = await own.do("due", () => run.ops.due(userId));
|
|
148
|
+
if (state !== "due") return { userId, state, erased: [], retained: [], mailed: false };
|
|
149
|
+
// Asked before every step from here on, each its own step, so a hold placed mid-run stops the next one.
|
|
150
|
+
const stopped = (next: string) => own.do(`hold ${next}`, () => run.ops.held(userId));
|
|
151
|
+
|
|
152
|
+
const context: PurgeContext = {
|
|
153
|
+
subject: { type: "user", id: userId },
|
|
154
|
+
env: run.env,
|
|
155
|
+
address: () => run.ops.address(userId),
|
|
156
|
+
};
|
|
157
|
+
const auth = run.steps.filter((each) => each.step === AUTH_CAPABILITY);
|
|
158
|
+
const others = run.steps.filter((each) => each.step !== AUTH_CAPABILITY);
|
|
159
|
+
const erased: string[] = [];
|
|
160
|
+
const retained: string[] = [];
|
|
161
|
+
// The step running now, so a failure records where it stopped.
|
|
162
|
+
let current = "due";
|
|
163
|
+
const held = { userId, state: "held", erased, retained, mailed: false } as const;
|
|
164
|
+
const runStep = async (each: PurgeStep) => {
|
|
165
|
+
const { contribution } = each;
|
|
166
|
+
current = each.step;
|
|
167
|
+
if (isRetained(contribution))
|
|
168
|
+
retained.push(await retainStep(step, run.ops, each.step, contribution.retain.basis, userId));
|
|
169
|
+
else erased.push(await eraseStep(step, run.ops, each, context));
|
|
170
|
+
};
|
|
171
|
+
try {
|
|
172
|
+
for (const each of others) {
|
|
173
|
+
if (await stopped(each.step)) return held;
|
|
174
|
+
await runStep(each);
|
|
175
|
+
}
|
|
176
|
+
current = "mail";
|
|
177
|
+
if (await stopped("mail")) return held;
|
|
178
|
+
const mailed = await own.do("mail", () => run.ops.mailComplete(userId, params.notify));
|
|
179
|
+
for (const each of auth) {
|
|
180
|
+
if (await stopped(each.step)) return { ...held, mailed };
|
|
181
|
+
await runStep(each);
|
|
182
|
+
}
|
|
183
|
+
current = "complete";
|
|
184
|
+
await own.do("complete", () => run.ops.complete(userId));
|
|
185
|
+
return { userId, state: "purged", erased, retained, mailed };
|
|
186
|
+
} catch (error) {
|
|
187
|
+
await recordFailure(step, run.ops, userId, current);
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Record where a purge gave up, in its own step, and never mask the failure that stopped it: a `fail` step that
|
|
194
|
+
* cannot write is swallowed. See the file header.
|
|
195
|
+
*/
|
|
196
|
+
async function recordFailure(step: WorkflowStepLike, ops: PurgeOps, userId: string, at: string): Promise<void> {
|
|
197
|
+
try {
|
|
198
|
+
await step.do("fail", async () => {
|
|
199
|
+
await ops.fail(userId, at);
|
|
200
|
+
return at;
|
|
201
|
+
});
|
|
202
|
+
} catch {
|
|
203
|
+
// The original failure is the one to report, and the next daily pass starts the purge again.
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* One capability's step: erase, then record that it ran. On the platform's own retry, unclassified — see the
|
|
209
|
+
* file header. Recorded inside the same step, so a step that erased and failed to record is retried whole, and
|
|
210
|
+
* the second erase finds nothing.
|
|
211
|
+
*/
|
|
212
|
+
function eraseStep(step: WorkflowStepLike, ops: PurgeOps, each: PurgeStep, context: PurgeContext): Promise<string> {
|
|
213
|
+
return step.do(`erase ${each.step}`, async () => {
|
|
214
|
+
await each.contribution.erase?.(context);
|
|
215
|
+
await ops.recordStep(context.subject.id, each.step, each.contribution.summary);
|
|
216
|
+
return each.step;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* One capability's retained step (#814): nothing is erased, and the record says the rows were kept and why. Its own
|
|
222
|
+
* step, so the trail names it in the order it would have run, and a replay serves it from the journal.
|
|
223
|
+
*/
|
|
224
|
+
function retainStep(
|
|
225
|
+
step: WorkflowStepLike,
|
|
226
|
+
ops: PurgeOps,
|
|
227
|
+
name: string,
|
|
228
|
+
basis: string,
|
|
229
|
+
userId: string,
|
|
230
|
+
): Promise<string> {
|
|
231
|
+
return step.do(`retain ${name}`, async () => {
|
|
232
|
+
await ops.recordRetained(userId, name, basis);
|
|
233
|
+
return name;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** How many purges one `start` step dispatches — a page, so one pass over a backlog is a bounded number of steps. */
|
|
238
|
+
export const PURGE_START_PAGE = 50;
|
|
239
|
+
|
|
240
|
+
/** The default size of one daily pass. */
|
|
241
|
+
export const PURGE_DUE_DEFAULT_LIMIT = 500;
|
|
242
|
+
|
|
243
|
+
/** What the daily pass reads and starts through. */
|
|
244
|
+
export interface PurgeDueRun {
|
|
245
|
+
/** Every account whose purge is due, oldest first, at most `limit`, with the deletion it is due under. */
|
|
246
|
+
due(limit: number): Promise<DuePurge[]>;
|
|
247
|
+
/**
|
|
248
|
+
* Start one account's purge — under the instance id its deletion names, so a start repeated is the same one.
|
|
249
|
+
* Says whether the purge is running: started now, or found already started. `false` when it could not be
|
|
250
|
+
* started, and the pass does not count it.
|
|
251
|
+
*/
|
|
252
|
+
start(due: DuePurge): Promise<boolean>;
|
|
253
|
+
/**
|
|
254
|
+
* Whether a legal hold stands on the account. A held account is not started; absent, every due account is,
|
|
255
|
+
* and each purge's own hold check stops it before its first step.
|
|
256
|
+
*/
|
|
257
|
+
held?(userId: string): Promise<boolean>;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* The daily pass (#622): list every account past its window, and start a purge for each — in pages, one step
|
|
262
|
+
* each, so a pass that dies part-way resumes after the page it finished rather than starting every purge
|
|
263
|
+
* again. An account still inside its window is not listed, so it is not started.
|
|
264
|
+
*/
|
|
265
|
+
export async function startDuePurges(
|
|
266
|
+
run: PurgeDueRun,
|
|
267
|
+
step: WorkflowStepLike,
|
|
268
|
+
terminalError: TerminalErrorConstructor,
|
|
269
|
+
params: AuthPurgeDueParams,
|
|
270
|
+
): Promise<{ started: number }> {
|
|
271
|
+
const own = classifiedSteps(step, authWorkflowRetry, terminalError);
|
|
272
|
+
const limit = params.limit ?? PURGE_DUE_DEFAULT_LIMIT;
|
|
273
|
+
const due = await own.do("due", () => run.due(limit));
|
|
274
|
+
let started = 0;
|
|
275
|
+
for (let page = 0; page * PURGE_START_PAGE < due.length; page += 1) {
|
|
276
|
+
const ids = due.slice(page * PURGE_START_PAGE, (page + 1) * PURGE_START_PAGE);
|
|
277
|
+
started += await own.do(`start ${page + 1}`, async () => {
|
|
278
|
+
// Counted from what each start answered, never from the page's length: a purge the binding could not start
|
|
279
|
+
// is not running, and `{ started }` is what an operator reads to learn whether they are.
|
|
280
|
+
let running = 0;
|
|
281
|
+
for (const each of ids) {
|
|
282
|
+
if (run.held && (await run.held(each.userId))) continue;
|
|
283
|
+
if (await run.start(each)) running += 1;
|
|
284
|
+
}
|
|
285
|
+
return running;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return { started };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** The daily pass's reads, over the lifecycle transitions. */
|
|
292
|
+
export function duePurgesOf(deps: LifecycleDeps): PurgeDueRun["due"] {
|
|
293
|
+
return (limit) => duePurges(deps, limit);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** How many inactive accounts one pass soft-deletes, at most: a backlog drains over nights, never in one. */
|
|
297
|
+
export const INACTIVE_DEFAULT_LIMIT = 200;
|
|
298
|
+
|
|
299
|
+
/** What the inactivity pass reads and deletes through. */
|
|
300
|
+
export interface InactivityRun {
|
|
301
|
+
/**
|
|
302
|
+
* The longest an account may sit inactive, in days — the strictest class age it holds — or null for no limit.
|
|
303
|
+
* Asked inside a step, so a replay serves the answer it got.
|
|
304
|
+
*/
|
|
305
|
+
days(): Promise<number | null>;
|
|
306
|
+
/** Every account inactive since `cutoff`, oldest first, at most `limit`. */
|
|
307
|
+
inactive(cutoff: Date, limit: number): Promise<string[]>;
|
|
308
|
+
/** Whether a legal hold stands on the account. */
|
|
309
|
+
held(userId: string): Promise<boolean>;
|
|
310
|
+
/** Soft-delete one account through the lifecycle, with its notice mail and window. Says whether it was deleted. */
|
|
311
|
+
remove(userId: string, days: number): Promise<boolean>;
|
|
312
|
+
/** Now. */
|
|
313
|
+
now(): Date;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* The inactivity pass: every account untouched for longer than the strictest class age it holds is
|
|
318
|
+
* soft-deleted through the lifecycle — its deletion-scheduled mail, its window, then the purge the daily pass starts
|
|
319
|
+
* once that window closes. A held account is skipped. With no class age that applies, the pass does nothing.
|
|
320
|
+
*
|
|
321
|
+
* Listed in one step, deleted in pages of steps, so a pass that dies part-way resumes after the page it finished.
|
|
322
|
+
* A deletion is no transition on an account already deleted, so a repeated page deletes nobody twice.
|
|
323
|
+
*/
|
|
324
|
+
export async function deleteInactiveAccounts(
|
|
325
|
+
run: InactivityRun,
|
|
326
|
+
step: WorkflowStepLike,
|
|
327
|
+
terminalError: TerminalErrorConstructor,
|
|
328
|
+
limit = INACTIVE_DEFAULT_LIMIT,
|
|
329
|
+
): Promise<{ deleted: number }> {
|
|
330
|
+
const own = classifiedSteps(step, authWorkflowRetry, terminalError);
|
|
331
|
+
const days = await own.do("class age", () => run.days());
|
|
332
|
+
if (days === null) return { deleted: 0 };
|
|
333
|
+
// The cutoff is read inside the step, so a replay serves the same list rather than one drawn at a later instant.
|
|
334
|
+
const ids = await own.do("inactive", () => run.inactive(new Date(run.now().getTime() - days * 86_400_000), limit));
|
|
335
|
+
let deleted = 0;
|
|
336
|
+
for (let page = 0; page * PURGE_START_PAGE < ids.length; page += 1) {
|
|
337
|
+
const slice = ids.slice(page * PURGE_START_PAGE, (page + 1) * PURGE_START_PAGE);
|
|
338
|
+
deleted += await own.do(`inactive ${page + 1}`, async () => {
|
|
339
|
+
let count = 0;
|
|
340
|
+
for (const userId of slice) {
|
|
341
|
+
if (await run.held(userId)) continue;
|
|
342
|
+
if (await run.remove(userId, days)) count += 1;
|
|
343
|
+
}
|
|
344
|
+
return count;
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
return { deleted };
|
|
348
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { workflowKey } from "@pithy-sh/core/src/workflow/naming";
|
|
5
|
+
import type { WorkflowRegistry, WorkflowSpecMap } from "@pithy-sh/core/src/workflow/spec";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
|
|
8
|
+
/** This capability's name, and the first segment of its workflow dispatch keys. */
|
|
9
|
+
export const AUTH_CAPABILITY = "auth";
|
|
10
|
+
|
|
11
|
+
/** The binding the purge of one account is started on. */
|
|
12
|
+
export const AUTH_PURGE_BINDING = "AUTH_PURGE";
|
|
13
|
+
|
|
14
|
+
/** The binding the daily pass that starts every due purge runs on. */
|
|
15
|
+
export const AUTH_PURGE_DUE_BINDING = "AUTH_PURGE_DUE";
|
|
16
|
+
|
|
17
|
+
/** The dispatch key of the purge of one account. */
|
|
18
|
+
export const AUTH_PURGE_KEY = workflowKey(AUTH_CAPABILITY, "purge");
|
|
19
|
+
|
|
20
|
+
/** One account's purge: which, and whether its last mail is sent. */
|
|
21
|
+
export const AuthPurgeParams = z
|
|
22
|
+
.object({
|
|
23
|
+
userId: z.string().min(1).max(255).describe("The account to erase, as `pithy_auth_users.id` stores it."),
|
|
24
|
+
notify: z
|
|
25
|
+
.boolean()
|
|
26
|
+
.optional()
|
|
27
|
+
.describe(
|
|
28
|
+
"Whether the deletion-complete mail is sent. Absent is true; the config can still turn it off. A hard deletion with `notify: false` passes false.",
|
|
29
|
+
),
|
|
30
|
+
})
|
|
31
|
+
.describe("One account's purge. It erases nothing unless the account is deleted and its window has closed.");
|
|
32
|
+
export type AuthPurgeParams = z.infer<typeof AuthPurgeParams>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The daily pass's parameters. Every field optional, because a cron passes none — `createEntrypoint` starts a
|
|
36
|
+
* scheduled job with `{}`.
|
|
37
|
+
*/
|
|
38
|
+
export const AuthPurgeDueParams = z
|
|
39
|
+
.object({
|
|
40
|
+
limit: z
|
|
41
|
+
.number()
|
|
42
|
+
.int()
|
|
43
|
+
.min(1)
|
|
44
|
+
.max(1000)
|
|
45
|
+
.optional()
|
|
46
|
+
.describe("How many due accounts to start a purge for in this pass, oldest first. Defaults to 500."),
|
|
47
|
+
})
|
|
48
|
+
.describe("One pass that starts a purge for every account past its window. A cron passes no field.");
|
|
49
|
+
export type AuthPurgeDueParams = z.infer<typeof AuthPurgeDueParams>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The two durable jobs auth owns (#622) — **both hosted by the adopter's own Worker**, the one that composes
|
|
53
|
+
* auth, never a prebuilt host.
|
|
54
|
+
*
|
|
55
|
+
* **Why not a host.** A purge runs every composed capability's contribution, the adopter's own `app` among
|
|
56
|
+
* them, and those exist only in the Worker whose `pithy.config.ts` composed them. A prebuilt host composes
|
|
57
|
+
* nothing. So each class is five lines in the adopter's entry, calling `runAuthPurge` and `runAuthPurgeDue` in
|
|
58
|
+
* `./workflow.ts`, exactly as `@pithy-sh/payments`' usage pass is: Cloudflare resolves a `class_name` in the
|
|
59
|
+
* script that binds it, and the body finds the composition the way a Workflow that sends mail finds email.
|
|
60
|
+
* No `className` here, deliberately: the class is the adopter's, and so is its `workflows` entry. The docs
|
|
61
|
+
* give both (`docs/account-lifecycle.md`).
|
|
62
|
+
*
|
|
63
|
+
* **`purge-due` is daily at 02:00 UTC**, ahead of storage's and the secrets rotation at 03:00, payments' 04:00
|
|
64
|
+
* and testers' 05:00. Daily because the window is counted in days: an hourly pass would start the same purge
|
|
65
|
+
* twenty-four times and erase nothing sooner. Both stay dispatchable on demand — a hard deletion starts
|
|
66
|
+
* `purge` directly.
|
|
67
|
+
*
|
|
68
|
+
* `optional: true` for both, so a Worker composing auth still boots before the adopter has bound them. A
|
|
69
|
+
* deletion then reports its purge as `pending`, and nothing is erased until they are.
|
|
70
|
+
*/
|
|
71
|
+
export const authWorkflows = {
|
|
72
|
+
purge: {
|
|
73
|
+
binding: AUTH_PURGE_BINDING,
|
|
74
|
+
params: AuthPurgeParams,
|
|
75
|
+
optional: true,
|
|
76
|
+
},
|
|
77
|
+
"purge-due": {
|
|
78
|
+
binding: AUTH_PURGE_DUE_BINDING,
|
|
79
|
+
params: AuthPurgeDueParams,
|
|
80
|
+
schedule: "0 2 * * *",
|
|
81
|
+
optional: true,
|
|
82
|
+
},
|
|
83
|
+
} as const satisfies WorkflowSpecMap;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The jobs as a dispatch registry, keyed `auth/<job>`, built here for the reason testers builds its own: the key
|
|
87
|
+
* format is core's either way. The daily pass starts each purge on the binding directly, not through this, because
|
|
88
|
+
* it names the instance (`./start.ts`) and dispatch does not.
|
|
89
|
+
*/
|
|
90
|
+
export const authWorkflowRegistry: WorkflowRegistry = Object.fromEntries(
|
|
91
|
+
Object.entries(authWorkflows).map(([job, spec]) => {
|
|
92
|
+
const key = workflowKey(AUTH_CAPABILITY, job);
|
|
93
|
+
return [key, { key, capability: AUTH_CAPABILITY, job, spec }];
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { WorkflowBinding } from "@pithy-sh/core/src/workflow/spec";
|
|
5
|
+
import { AuthPurgeParams } from "./specs";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Starting one account's purge, from either door (#622) — a hard deletion's route and the daily pass.
|
|
9
|
+
*
|
|
10
|
+
* **Under an id the deletion names, so two starts of one purge are one instance.** A hard deletion repeated, a
|
|
11
|
+
* hard deletion the daily pass also finds due, a `start` step the pass retries: each asks for the same
|
|
12
|
+
* instance, and Cloudflare holds one instance per id, so the second `create` is refused and nothing runs
|
|
13
|
+
* twice. Two purges of one account running at once would both pass `due` and both reach the mail.
|
|
14
|
+
*
|
|
15
|
+
* **The id is the account, the deletion's start, and the UTC day of the start.** The account and the deletion,
|
|
16
|
+
* so a restored and re-deleted account is a different purge. The day, because the daily pass is the outer
|
|
17
|
+
* retry (`./retryPolicy.ts`): an instance that failed keeps its id, and a purge started under the same id
|
|
18
|
+
* forever could never be started again. So tomorrow's pass gets a fresh instance for an account still due,
|
|
19
|
+
* and every start within one day is the same one. Two instances of one purge can overlap only across a day
|
|
20
|
+
* boundary, while the first is still retrying; `complete` then records, audits and fires once whatever
|
|
21
|
+
* overlaps (`../lifecycle/transitions.ts`).
|
|
22
|
+
*
|
|
23
|
+
* **Hashed.** An instance id is at most 100 characters of `[A-Za-z0-9_-]`, and a user id is up to 255 of
|
|
24
|
+
* anything. A SHA-256 of the pair keeps the id inside the rule and says nothing about the account.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** What starting a purge needs to know. */
|
|
28
|
+
export interface PurgeStart {
|
|
29
|
+
/** The account. */
|
|
30
|
+
readonly userId: string;
|
|
31
|
+
/** The deletion it is purged under — its start, ms-epoch. */
|
|
32
|
+
readonly deletedAt: number;
|
|
33
|
+
/** A hard deletion's `notify`, when it named one. The deletion's row carries it too. */
|
|
34
|
+
readonly notify?: boolean;
|
|
35
|
+
/** Now, for the day the id is named for. */
|
|
36
|
+
readonly at: Date;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The instance id of one purge, on one day. Deterministic: the same start always names the same instance. */
|
|
40
|
+
export async function purgeInstanceId(start: Pick<PurgeStart, "userId" | "deletedAt" | "at">): Promise<string> {
|
|
41
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${start.userId}\n${start.deletedAt}`));
|
|
42
|
+
const hex = Array.from(new Uint8Array(digest).slice(0, 20), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
43
|
+
const day = start.at.toISOString().slice(0, 10).replaceAll("-", "");
|
|
44
|
+
return `auth-purge-${hex}-${day}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The half of a Workflow binding that looks an instance up — present on the real one, resolving when it exists. */
|
|
48
|
+
interface InstanceLookup {
|
|
49
|
+
get(id: string): Promise<unknown>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function canLookUp(binding: WorkflowBinding): binding is WorkflowBinding & InstanceLookup {
|
|
53
|
+
return typeof (binding as Partial<InstanceLookup>).get === "function";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Start one purge, or find it started. A `create` refused because the id is taken is a purge already started,
|
|
58
|
+
* so this asks the binding for the instance and succeeds when it is there. Any other failure is thrown, for the
|
|
59
|
+
* caller to report as `pending`. The parameters are the job's own schema, parsed.
|
|
60
|
+
*/
|
|
61
|
+
export async function startPurgeInstance(binding: WorkflowBinding, start: PurgeStart): Promise<void> {
|
|
62
|
+
const id = await purgeInstanceId(start);
|
|
63
|
+
const params = AuthPurgeParams.parse({
|
|
64
|
+
userId: start.userId,
|
|
65
|
+
...(start.notify === undefined ? {} : { notify: start.notify }),
|
|
66
|
+
});
|
|
67
|
+
try {
|
|
68
|
+
await binding.create({ id, params });
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (canLookUp(binding)) {
|
|
71
|
+
const found = await binding.get(id).then(
|
|
72
|
+
() => true,
|
|
73
|
+
() => false,
|
|
74
|
+
);
|
|
75
|
+
if (found) return;
|
|
76
|
+
}
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|