@fantastic.dev/better-stripe 0.40.0 → 0.42.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/CHANGELOG.md +20 -0
- package/README.md +1 -1
- package/dist/client/balanceFundingWorkflow/client.d.ts +172 -0
- package/dist/client/balanceFundingWorkflow/client.d.ts.map +1 -0
- package/dist/client/balanceFundingWorkflow/client.js +289 -0
- package/dist/client/balanceFundingWorkflow/client.js.map +1 -0
- package/dist/client/billing/balanceFunding.d.ts +5 -0
- package/dist/client/billing/balanceFunding.d.ts.map +1 -1
- package/dist/client/billing/balanceFunding.js +30 -0
- package/dist/client/billing/balanceFunding.js.map +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +808 -2
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +404 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +808 -2
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +404 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/costRecovery-invoices.d.ts +2 -2
- package/dist/client/costRecovery-invoices.d.ts.map +1 -1
- package/dist/client/costRecovery-invoices.js +4 -1
- package/dist/client/costRecovery-invoices.js.map +1 -1
- package/dist/client/costRecovery.d.ts +5 -2
- package/dist/client/costRecovery.d.ts.map +1 -1
- package/dist/client/costRecovery.js +3 -1
- package/dist/client/costRecovery.js.map +1 -1
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +4 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/recoveryWorkflow/client.d.ts +14 -0
- package/dist/client/recoveryWorkflow/client.d.ts.map +1 -0
- package/dist/client/recoveryWorkflow/client.js +34 -0
- package/dist/client/recoveryWorkflow/client.js.map +1 -0
- package/dist/client/recoveryWorkflow/contracts.d.ts +63 -0
- package/dist/client/recoveryWorkflow/contracts.d.ts.map +1 -0
- package/dist/client/recoveryWorkflow/contracts.js +11 -0
- package/dist/client/recoveryWorkflow/contracts.js.map +1 -0
- package/dist/client/recoveryWorkflow/provider.d.ts +10 -0
- package/dist/client/recoveryWorkflow/provider.d.ts.map +1 -0
- package/dist/client/recoveryWorkflow/provider.js +80 -0
- package/dist/client/recoveryWorkflow/provider.js.map +1 -0
- package/dist/client/recoveryWorkflow/settlement.d.ts +6 -0
- package/dist/client/recoveryWorkflow/settlement.d.ts.map +1 -0
- package/dist/client/recoveryWorkflow/settlement.js +43 -0
- package/dist/client/recoveryWorkflow/settlement.js.map +1 -0
- package/dist/component/_generated/api.d.ts +30 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +637 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/balanceFunding/helpers.d.ts +42 -0
- package/dist/component/balanceFunding/helpers.d.ts.map +1 -1
- package/dist/component/balanceFunding/internal/actions.d.ts +39 -0
- package/dist/component/balanceFunding/internal/actions.d.ts.map +1 -0
- package/dist/component/balanceFunding/internal/actions.js +80 -0
- package/dist/component/balanceFunding/internal/actions.js.map +1 -0
- package/dist/component/balanceFunding/internal/mutations.d.ts +55 -0
- package/dist/component/balanceFunding/internal/mutations.d.ts.map +1 -0
- package/dist/component/balanceFunding/internal/mutations.js +54 -0
- package/dist/component/balanceFunding/internal/mutations.js.map +1 -0
- package/dist/component/balanceFunding/internal/queries.d.ts +116 -0
- package/dist/component/balanceFunding/internal/queries.d.ts.map +1 -0
- package/dist/component/balanceFunding/internal/queries.js +35 -0
- package/dist/component/balanceFunding/internal/queries.js.map +1 -0
- package/dist/component/balanceFunding/internal/workflow.d.ts +10 -0
- package/dist/component/balanceFunding/internal/workflow.d.ts.map +1 -0
- package/dist/component/balanceFunding/internal/workflow.js +31 -0
- package/dist/component/balanceFunding/internal/workflow.js.map +1 -0
- package/dist/component/balanceFunding/lifecycleHandlers.d.ts +126 -0
- package/dist/component/balanceFunding/lifecycleHandlers.d.ts.map +1 -1
- package/dist/component/balanceFunding/mutations.d.ts +419 -16
- package/dist/component/balanceFunding/mutations.d.ts.map +1 -1
- package/dist/component/balanceFunding/mutations.js +24 -0
- package/dist/component/balanceFunding/mutations.js.map +1 -1
- package/dist/component/balanceFunding/preparationHandlers.d.ts +42 -0
- package/dist/component/balanceFunding/preparationHandlers.d.ts.map +1 -1
- package/dist/component/balanceFunding/queries.d.ts +78 -0
- package/dist/component/balanceFunding/queries.d.ts.map +1 -1
- package/dist/component/balanceFunding/queries.js +35 -0
- package/dist/component/balanceFunding/queries.js.map +1 -1
- package/dist/component/balanceFunding/receipt.d.ts +5 -0
- package/dist/component/balanceFunding/receipt.d.ts.map +1 -0
- package/dist/component/balanceFunding/receipt.js +37 -0
- package/dist/component/balanceFunding/receipt.js.map +1 -0
- package/dist/component/balanceFunding/schema.d.ts +506 -2
- package/dist/component/balanceFunding/schema.d.ts.map +1 -1
- package/dist/component/balanceFunding/schema.js +2 -0
- package/dist/component/balanceFunding/schema.js.map +1 -1
- package/dist/component/balanceFunding/stateHandlers.d.ts +42 -0
- package/dist/component/balanceFunding/stateHandlers.d.ts.map +1 -1
- package/dist/component/balanceFunding/workflowControl.d.ts +19 -0
- package/dist/component/balanceFunding/workflowControl.d.ts.map +1 -0
- package/dist/component/balanceFunding/workflowControl.js +149 -0
- package/dist/component/balanceFunding/workflowControl.js.map +1 -0
- package/dist/component/balanceFunding/workflowSchema.d.ts +356 -0
- package/dist/component/balanceFunding/workflowSchema.d.ts.map +1 -0
- package/dist/component/balanceFunding/workflowSchema.js +48 -0
- package/dist/component/balanceFunding/workflowSchema.js.map +1 -0
- package/dist/component/balanceFunding/workflowState.d.ts +157 -0
- package/dist/component/balanceFunding/workflowState.d.ts.map +1 -0
- package/dist/component/balanceFunding/workflowState.js +194 -0
- package/dist/component/balanceFunding/workflowState.js.map +1 -0
- package/dist/component/balanceFunding/workflowValidators.d.ts +306 -0
- package/dist/component/balanceFunding/workflowValidators.d.ts.map +1 -0
- package/dist/component/balanceFunding/workflowValidators.js +27 -0
- package/dist/component/balanceFunding/workflowValidators.js.map +1 -0
- package/dist/component/earnings/triggers.d.ts +280 -2
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/recoveryWorkflow/bridge.d.ts +21 -0
- package/dist/component/recoveryWorkflow/bridge.d.ts.map +1 -0
- package/dist/component/recoveryWorkflow/bridge.js +52 -0
- package/dist/component/recoveryWorkflow/bridge.js.map +1 -0
- package/dist/component/recoveryWorkflow/helpers.d.ts +83 -0
- package/dist/component/recoveryWorkflow/helpers.d.ts.map +1 -0
- package/dist/component/recoveryWorkflow/helpers.js +48 -0
- package/dist/component/recoveryWorkflow/helpers.js.map +1 -0
- package/dist/component/recoveryWorkflow/mutations.d.ts +91 -0
- package/dist/component/recoveryWorkflow/mutations.d.ts.map +1 -0
- package/dist/component/recoveryWorkflow/mutations.js +177 -0
- package/dist/component/recoveryWorkflow/mutations.js.map +1 -0
- package/dist/component/recoveryWorkflow/queries.d.ts +118 -0
- package/dist/component/recoveryWorkflow/queries.d.ts.map +1 -0
- package/dist/component/recoveryWorkflow/queries.js +20 -0
- package/dist/component/recoveryWorkflow/queries.js.map +1 -0
- package/dist/component/recoveryWorkflow/schema.d.ts +653 -0
- package/dist/component/recoveryWorkflow/schema.d.ts.map +1 -0
- package/dist/component/recoveryWorkflow/schema.js +81 -0
- package/dist/component/recoveryWorkflow/schema.js.map +1 -0
- package/dist/component/recoveryWorkflow/steps.d.ts +70 -0
- package/dist/component/recoveryWorkflow/steps.d.ts.map +1 -0
- package/dist/component/recoveryWorkflow/steps.js +94 -0
- package/dist/component/recoveryWorkflow/steps.js.map +1 -0
- package/dist/component/recoveryWorkflow/workflow.d.ts +22 -0
- package/dist/component/recoveryWorkflow/workflow.d.ts.map +1 -0
- package/dist/component/recoveryWorkflow/workflow.js +56 -0
- package/dist/component/recoveryWorkflow/workflow.js.map +1 -0
- package/dist/component/schema.d.ts +404 -1
- package/dist/component/schema.js +3 -0
- package/dist/component/schema.js.map +1 -1
- package/package.json +1 -1
- package/src/client/balanceFundingWorkflow/capture.test.ts +144 -0
- package/src/client/balanceFundingWorkflow/client.ts +419 -0
- package/src/client/billing/balanceFunding.ts +50 -0
- package/src/client/costRecovery-invoices.ts +6 -0
- package/src/client/costRecovery.ts +8 -3
- package/src/client/index.ts +15 -0
- package/src/client/recoveryWorkflow/client.test.ts +37 -0
- package/src/client/recoveryWorkflow/client.ts +76 -0
- package/src/client/recoveryWorkflow/contracts.ts +72 -0
- package/src/client/recoveryWorkflow/provider.test.ts +424 -0
- package/src/client/recoveryWorkflow/provider.ts +119 -0
- package/src/client/recoveryWorkflow/settlement.ts +67 -0
- package/src/component/_generated/api.ts +30 -0
- package/src/component/_generated/component.ts +746 -0
- package/src/component/balanceFunding/internal/actions.ts +107 -0
- package/src/component/balanceFunding/internal/mutations.ts +66 -0
- package/src/component/balanceFunding/internal/queries.ts +34 -0
- package/src/component/balanceFunding/internal/workflow.ts +49 -0
- package/src/component/balanceFunding/mutations.ts +34 -0
- package/src/component/balanceFunding/queries.ts +38 -0
- package/src/component/balanceFunding/receipt.ts +48 -0
- package/src/component/balanceFunding/schema.ts +2 -0
- package/src/component/balanceFunding/scopeLookup.test.ts +94 -0
- package/src/component/balanceFunding/workflow.fixtures.ts +366 -0
- package/src/component/balanceFunding/workflow.test.ts +552 -0
- package/src/component/balanceFunding/workflowControl.ts +198 -0
- package/src/component/balanceFunding/workflowSchema.ts +78 -0
- package/src/component/balanceFunding/workflowState.ts +285 -0
- package/src/component/balanceFunding/workflowValidators.ts +40 -0
- package/src/component/recoveryWorkflow/bridge.test.ts +481 -0
- package/src/component/recoveryWorkflow/bridge.ts +66 -0
- package/src/component/recoveryWorkflow/helpers.ts +58 -0
- package/src/component/recoveryWorkflow/journal.test.ts +104 -0
- package/src/component/recoveryWorkflow/mutations.ts +224 -0
- package/src/component/recoveryWorkflow/queries.ts +19 -0
- package/src/component/recoveryWorkflow/schema.ts +92 -0
- package/src/component/recoveryWorkflow/state.test.ts +191 -0
- package/src/component/recoveryWorkflow/steps.ts +97 -0
- package/src/component/recoveryWorkflow/workflow.ts +73 -0
- package/src/component/schema.ts +6 -0
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
// @vitest-environment edge-runtime
|
|
2
|
+
import { anyApi } from "convex/server";
|
|
3
|
+
import { expect, it, vi } from "vitest";
|
|
4
|
+
import {
|
|
5
|
+
nested,
|
|
6
|
+
scope,
|
|
7
|
+
stripeSubscriptionId,
|
|
8
|
+
original,
|
|
9
|
+
setup,
|
|
10
|
+
fixture,
|
|
11
|
+
} from "./workflow.fixtures.js";
|
|
12
|
+
import { STRIPE_CUSTOMER_PREVIEW_API_VERSION as version } from "../../client/apiVersion.js";
|
|
13
|
+
it("persists original restoration before nested workflow provisioning and finishes only from verified receipts", async () => {
|
|
14
|
+
const t = setup();
|
|
15
|
+
const started = await t.action(anyApi.host.prepare, {
|
|
16
|
+
requestKey: "prepare-once",
|
|
17
|
+
});
|
|
18
|
+
expect(started.status).toBe("accepted");
|
|
19
|
+
expect(started.workflowId).toEqual(expect.any(String));
|
|
20
|
+
const lookup = {
|
|
21
|
+
...scope,
|
|
22
|
+
stripeSubscriptionId,
|
|
23
|
+
providerApiVersion: version,
|
|
24
|
+
};
|
|
25
|
+
const before = await t.query(
|
|
26
|
+
nested.betterStripe.balanceFunding.queries.readScopePreparation,
|
|
27
|
+
lookup,
|
|
28
|
+
);
|
|
29
|
+
expect(before).toMatchObject({
|
|
30
|
+
preparation: original,
|
|
31
|
+
verified: false,
|
|
32
|
+
consentReference: "original-consent",
|
|
33
|
+
activeOperationId: started.operation.operationId,
|
|
34
|
+
});
|
|
35
|
+
expect(fixture.requests.every((r) => r.method === "GET")).toBe(true);
|
|
36
|
+
const operation = await t.query(
|
|
37
|
+
nested.betterStripe.balanceFunding.queries.inspectOperation,
|
|
38
|
+
{ ...started.operation, stripeSubscriptionId },
|
|
39
|
+
);
|
|
40
|
+
expect(operation.providerKeys.create).toEqual(expect.any(String));
|
|
41
|
+
expect(operation.providerKeys.attach).toEqual(expect.any(String));
|
|
42
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
43
|
+
expect(
|
|
44
|
+
await t.query(nested.betterStripe.balanceFunding.queries.getPreparation, {
|
|
45
|
+
...started.operation,
|
|
46
|
+
stripeSubscriptionId,
|
|
47
|
+
}),
|
|
48
|
+
).toMatchObject({
|
|
49
|
+
status: "prepared",
|
|
50
|
+
operation: started.operation,
|
|
51
|
+
preparationId: before._id,
|
|
52
|
+
});
|
|
53
|
+
const after = await t.query(
|
|
54
|
+
nested.betterStripe.balanceFunding.queries.readScopePreparation,
|
|
55
|
+
lookup,
|
|
56
|
+
);
|
|
57
|
+
expect(after.preparation).toEqual({
|
|
58
|
+
...original,
|
|
59
|
+
paymentMethodId: "pm_balance",
|
|
60
|
+
});
|
|
61
|
+
expect(after.verified).toBe(true);
|
|
62
|
+
const writes = fixture.requests.filter((r) => r.method === "POST");
|
|
63
|
+
expect(writes).toEqual([
|
|
64
|
+
{
|
|
65
|
+
method: "POST",
|
|
66
|
+
path: "/v1/payment_methods",
|
|
67
|
+
version,
|
|
68
|
+
key: operation.providerKeys.create,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
method: "POST",
|
|
72
|
+
path: "/v1/payment_methods/pm_balance/attach",
|
|
73
|
+
version,
|
|
74
|
+
key: operation.providerKeys.attach,
|
|
75
|
+
},
|
|
76
|
+
]);
|
|
77
|
+
expect(fixture.requests.every((r) => r.version === version)).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("joins duplicate public fixture.requests without recapturing settings or creating another workflow", async () => {
|
|
81
|
+
const t = setup();
|
|
82
|
+
const first = await t.action(anyApi.host.prepare, {
|
|
83
|
+
requestKey: "prepare-once",
|
|
84
|
+
});
|
|
85
|
+
const reads = fixture.requests.length;
|
|
86
|
+
expect(
|
|
87
|
+
await t.action(anyApi.host.prepare, { requestKey: "prepare-once" }),
|
|
88
|
+
).toEqual(first);
|
|
89
|
+
expect(fixture.requests).toHaveLength(reads);
|
|
90
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
91
|
+
expect(
|
|
92
|
+
fixture.requests.filter(
|
|
93
|
+
(r) => r.method === "POST" && r.path === "/v1/payment_methods",
|
|
94
|
+
),
|
|
95
|
+
).toHaveLength(1);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("holds a lost create ID across resume and cancellation without reissuing the effect", async () => {
|
|
99
|
+
fixture.unknownPhase = "create";
|
|
100
|
+
const t = setup();
|
|
101
|
+
const first = await t.action(anyApi.host.prepare, {
|
|
102
|
+
requestKey: "lost-create",
|
|
103
|
+
});
|
|
104
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
105
|
+
const ref = { ...first.operation, stripeSubscriptionId };
|
|
106
|
+
expect(
|
|
107
|
+
await t.query(
|
|
108
|
+
nested.betterStripe.balanceFunding.queries.getPreparation,
|
|
109
|
+
ref,
|
|
110
|
+
),
|
|
111
|
+
).toMatchObject({ status: "unknown" });
|
|
112
|
+
const control = {
|
|
113
|
+
operationId: first.operation.operationId,
|
|
114
|
+
version: first.operation.version,
|
|
115
|
+
};
|
|
116
|
+
await t.action(anyApi.host.resume, control);
|
|
117
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
118
|
+
await t.action(anyApi.host.cancel, control);
|
|
119
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
120
|
+
const saved = await t.query(
|
|
121
|
+
nested.betterStripe.balanceFunding.queries.readScopePreparation,
|
|
122
|
+
{ ...scope, stripeSubscriptionId, providerApiVersion: version },
|
|
123
|
+
);
|
|
124
|
+
expect(saved).toMatchObject({
|
|
125
|
+
preparation: original,
|
|
126
|
+
verified: false,
|
|
127
|
+
activeOperationId: first.operation.operationId,
|
|
128
|
+
});
|
|
129
|
+
expect(
|
|
130
|
+
fixture.requests.filter(
|
|
131
|
+
(r) => r.method === "POST" && r.path === "/v1/payment_methods",
|
|
132
|
+
),
|
|
133
|
+
).toHaveLength(1);
|
|
134
|
+
const history = await t.query(
|
|
135
|
+
nested.betterStripe.fundingWorkflowFixture.history,
|
|
136
|
+
{ id: first.workflowId },
|
|
137
|
+
);
|
|
138
|
+
expect(JSON.stringify(history)).not.toContain("raw_provider_private_failure");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("reconciles a lost attachment response by known-ID readback without another attach", async () => {
|
|
142
|
+
fixture.unknownPhase = "attach";
|
|
143
|
+
const t = setup();
|
|
144
|
+
const first = await t.action(anyApi.host.prepare, {
|
|
145
|
+
requestKey: "lost-attach",
|
|
146
|
+
});
|
|
147
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
148
|
+
const ref = { ...first.operation, stripeSubscriptionId };
|
|
149
|
+
expect(
|
|
150
|
+
await t.query(
|
|
151
|
+
nested.betterStripe.balanceFunding.queries.getPreparation,
|
|
152
|
+
ref,
|
|
153
|
+
),
|
|
154
|
+
).toMatchObject({ status: "unknown" });
|
|
155
|
+
await t.action(anyApi.host.resume, {
|
|
156
|
+
operationId: first.operation.operationId,
|
|
157
|
+
version: first.operation.version,
|
|
158
|
+
});
|
|
159
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
160
|
+
expect(
|
|
161
|
+
await t.query(
|
|
162
|
+
nested.betterStripe.balanceFunding.queries.getPreparation,
|
|
163
|
+
ref,
|
|
164
|
+
),
|
|
165
|
+
).toMatchObject({ status: "prepared" });
|
|
166
|
+
expect(fixture.requests.filter((r) => r.method === "POST")).toHaveLength(2);
|
|
167
|
+
expect(
|
|
168
|
+
fixture.requests.filter(
|
|
169
|
+
(r) => r.path.endsWith("/attach") && r.method === "POST",
|
|
170
|
+
),
|
|
171
|
+
).toHaveLength(1);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("allowlists host receipts before they reach the durable workflow journal", async () => {
|
|
175
|
+
fixture.extraFields = true;
|
|
176
|
+
const t = setup();
|
|
177
|
+
const first = await t.action(anyApi.host.prepare, {
|
|
178
|
+
requestKey: "sanitized",
|
|
179
|
+
});
|
|
180
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
181
|
+
expect(
|
|
182
|
+
await t.query(nested.betterStripe.balanceFunding.queries.getPreparation, {
|
|
183
|
+
...first.operation,
|
|
184
|
+
stripeSubscriptionId,
|
|
185
|
+
}),
|
|
186
|
+
).toMatchObject({ status: "prepared" });
|
|
187
|
+
const history = await t.query(
|
|
188
|
+
nested.betterStripe.fundingWorkflowFixture.history,
|
|
189
|
+
{ id: first.workflowId },
|
|
190
|
+
);
|
|
191
|
+
expect(JSON.stringify(history)).not.toContain("raw_provider_private_field");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("resumes a failed database finish from retained receipts without replaying provider writes", async () => {
|
|
195
|
+
const t = setup(true);
|
|
196
|
+
const first = await t.action(anyApi.host.prepare, {
|
|
197
|
+
requestKey: "finish-retry",
|
|
198
|
+
});
|
|
199
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
200
|
+
expect(
|
|
201
|
+
await t.query(nested.betterStripe.fundingWorkflowFixture.status, {
|
|
202
|
+
id: first.workflowId,
|
|
203
|
+
}),
|
|
204
|
+
).toMatchObject({ type: "failed" });
|
|
205
|
+
expect(fixture.requests.filter((r) => r.method === "POST")).toHaveLength(2);
|
|
206
|
+
await t.action(anyApi.host.resume, {
|
|
207
|
+
operationId: first.operation.operationId,
|
|
208
|
+
version: first.operation.version,
|
|
209
|
+
});
|
|
210
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
211
|
+
expect(
|
|
212
|
+
await t.query(nested.betterStripe.balanceFunding.queries.getPreparation, {
|
|
213
|
+
...first.operation,
|
|
214
|
+
stripeSubscriptionId,
|
|
215
|
+
}),
|
|
216
|
+
).toMatchObject({ status: "prepared" });
|
|
217
|
+
expect(
|
|
218
|
+
await t.query(nested.betterStripe.fundingWorkflowFixture.status, {
|
|
219
|
+
id: first.workflowId,
|
|
220
|
+
}),
|
|
221
|
+
).toMatchObject({ type: "completed" });
|
|
222
|
+
expect(fixture.requests.filter((r) => r.method === "POST")).toHaveLength(2);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("enables and restores the exact original settings using separate durable operation versions", async () => {
|
|
226
|
+
const t = setup();
|
|
227
|
+
const prepared = await t.action(anyApi.host.prepare, {
|
|
228
|
+
requestKey: "apply-prepare",
|
|
229
|
+
});
|
|
230
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
231
|
+
const saved = await t.query(
|
|
232
|
+
nested.betterStripe.balanceFunding.queries.getPreparation,
|
|
233
|
+
{ ...prepared.operation, stripeSubscriptionId },
|
|
234
|
+
);
|
|
235
|
+
const first = await t.action(anyApi.host.apply, {
|
|
236
|
+
preparationId: saved.preparationId,
|
|
237
|
+
enabled: true,
|
|
238
|
+
requestKey: "enable",
|
|
239
|
+
});
|
|
240
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
241
|
+
expect(fixture.enabled).toBe(true);
|
|
242
|
+
expect(
|
|
243
|
+
await t.query(nested.betterStripe.balanceFunding.queries.getOperation, {
|
|
244
|
+
...first.operation,
|
|
245
|
+
stripeSubscriptionId,
|
|
246
|
+
}),
|
|
247
|
+
).toMatchObject({ state: "succeeded" });
|
|
248
|
+
const second = await t.action(anyApi.host.apply, {
|
|
249
|
+
preparationId: saved.preparationId,
|
|
250
|
+
enabled: false,
|
|
251
|
+
requestKey: "disable",
|
|
252
|
+
});
|
|
253
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
254
|
+
expect(fixture.enabled).toBe(false);
|
|
255
|
+
expect(second.operation.version).toBeGreaterThan(first.operation.version);
|
|
256
|
+
expect(
|
|
257
|
+
fixture.requests
|
|
258
|
+
.filter((r) => r.path.includes("subscriptions") && r.method === "POST")
|
|
259
|
+
.map((r) => r.key),
|
|
260
|
+
).toEqual([
|
|
261
|
+
expect.stringContaining(":enable"),
|
|
262
|
+
expect.stringContaining(":disable"),
|
|
263
|
+
]);
|
|
264
|
+
});
|
|
265
|
+
it("reconciles an unknown apply by readback without another provider update", async () => {
|
|
266
|
+
const t = setup();
|
|
267
|
+
const prepared = await t.action(anyApi.host.prepare, {
|
|
268
|
+
requestKey: "unknown-apply-prepare",
|
|
269
|
+
});
|
|
270
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
271
|
+
const saved = await t.query(
|
|
272
|
+
nested.betterStripe.balanceFunding.queries.getPreparation,
|
|
273
|
+
{ ...prepared.operation, stripeSubscriptionId },
|
|
274
|
+
);
|
|
275
|
+
fixture.lostApply = true;
|
|
276
|
+
const first = await t.action(anyApi.host.apply, {
|
|
277
|
+
preparationId: saved.preparationId,
|
|
278
|
+
enabled: true,
|
|
279
|
+
requestKey: "unknown-enable",
|
|
280
|
+
});
|
|
281
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
282
|
+
expect(
|
|
283
|
+
await t.query(nested.betterStripe.balanceFunding.queries.getOperation, {
|
|
284
|
+
...first.operation,
|
|
285
|
+
stripeSubscriptionId,
|
|
286
|
+
}),
|
|
287
|
+
).toMatchObject({ state: "unknown" });
|
|
288
|
+
await t.action(anyApi.host.resume, {
|
|
289
|
+
operationId: first.operation.operationId,
|
|
290
|
+
version: first.operation.version,
|
|
291
|
+
});
|
|
292
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
293
|
+
expect(
|
|
294
|
+
await t.query(nested.betterStripe.balanceFunding.queries.getOperation, {
|
|
295
|
+
...first.operation,
|
|
296
|
+
stripeSubscriptionId,
|
|
297
|
+
}),
|
|
298
|
+
).toMatchObject({ state: "succeeded" });
|
|
299
|
+
expect(
|
|
300
|
+
fixture.requests.filter(
|
|
301
|
+
(r) => r.path.includes("subscriptions") && r.method === "POST",
|
|
302
|
+
),
|
|
303
|
+
).toHaveLength(1);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it("holds in-flight cancellation without releasing original restoration or starting an attach", async () => {
|
|
307
|
+
const t = setup();
|
|
308
|
+
fixture.cancelPhase = "create";
|
|
309
|
+
const first = await t.action(anyApi.host.prepare, {
|
|
310
|
+
requestKey: "cancel-inflight",
|
|
311
|
+
});
|
|
312
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
313
|
+
expect(
|
|
314
|
+
await t.action(anyApi.host.inspect, {
|
|
315
|
+
operationId: first.operation.operationId,
|
|
316
|
+
version: first.operation.version,
|
|
317
|
+
}),
|
|
318
|
+
).toMatchObject({ state: "unknown", cancelRequested: true });
|
|
319
|
+
await t.action(anyApi.host.resume, {
|
|
320
|
+
operationId: first.operation.operationId,
|
|
321
|
+
version: first.operation.version,
|
|
322
|
+
});
|
|
323
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
324
|
+
expect(fixture.requests.filter((r) => r.method === "POST")).toHaveLength(1);
|
|
325
|
+
const saved = await t.query(
|
|
326
|
+
nested.betterStripe.balanceFunding.queries.readScopePreparation,
|
|
327
|
+
{ ...scope, stripeSubscriptionId, providerApiVersion: version },
|
|
328
|
+
);
|
|
329
|
+
expect(saved).toMatchObject({
|
|
330
|
+
preparation: original,
|
|
331
|
+
verified: false,
|
|
332
|
+
activeOperationId: first.operation.operationId,
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
it("finishes from a retained positive attachment receipt after cancellation races its response", async () => {
|
|
336
|
+
const t = setup();
|
|
337
|
+
fixture.cancelPhase = "attach";
|
|
338
|
+
const first = await t.action(anyApi.host.prepare, {
|
|
339
|
+
requestKey: "cancel-after-attach",
|
|
340
|
+
});
|
|
341
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
342
|
+
await t.action(anyApi.host.resume, {
|
|
343
|
+
operationId: first.operation.operationId,
|
|
344
|
+
version: first.operation.version,
|
|
345
|
+
});
|
|
346
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
347
|
+
expect(
|
|
348
|
+
await t.query(nested.betterStripe.balanceFunding.queries.getPreparation, {
|
|
349
|
+
...first.operation,
|
|
350
|
+
stripeSubscriptionId,
|
|
351
|
+
}),
|
|
352
|
+
).toMatchObject({ status: "prepared" });
|
|
353
|
+
expect(fixture.requests.filter((r) => r.method === "POST")).toHaveLength(2);
|
|
354
|
+
});
|
|
355
|
+
it("rejects changed definition and stale version before provider replay", async () => {
|
|
356
|
+
const t = setup();
|
|
357
|
+
fixture.unknownPhase = "create";
|
|
358
|
+
const first = await t.action(anyApi.host.prepare, {
|
|
359
|
+
requestKey: "changed-definition",
|
|
360
|
+
});
|
|
361
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
362
|
+
const args = {
|
|
363
|
+
...first.operation,
|
|
364
|
+
stripeSubscriptionId,
|
|
365
|
+
providerApiVersion: version,
|
|
366
|
+
definitionVersion: "balance-funding/v2",
|
|
367
|
+
};
|
|
368
|
+
expect(
|
|
369
|
+
await t.mutation(
|
|
370
|
+
nested.betterStripe.balanceFunding.mutations.resumeWorkflow,
|
|
371
|
+
args,
|
|
372
|
+
),
|
|
373
|
+
).toMatchObject({ status: "conflict", reason: "revision_changed" });
|
|
374
|
+
expect(
|
|
375
|
+
await t.mutation(
|
|
376
|
+
nested.betterStripe.balanceFunding.mutations.resumeWorkflow,
|
|
377
|
+
{
|
|
378
|
+
...args,
|
|
379
|
+
definitionVersion: "balance-funding/v1",
|
|
380
|
+
version: first.operation.version + 1,
|
|
381
|
+
},
|
|
382
|
+
),
|
|
383
|
+
).toMatchObject({ status: "conflict" });
|
|
384
|
+
expect(fixture.requests.filter((r) => r.method === "POST")).toHaveLength(1);
|
|
385
|
+
});
|
|
386
|
+
it("keeps an unknown effect held after workflow retention is cleaned", async () => {
|
|
387
|
+
const t = setup();
|
|
388
|
+
fixture.unknownPhase = "create";
|
|
389
|
+
const first = await t.action(anyApi.host.prepare, {
|
|
390
|
+
requestKey: "expired-history",
|
|
391
|
+
});
|
|
392
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
393
|
+
await t.mutation(nested.betterStripe.fundingWorkflowFixture.cleanup, {
|
|
394
|
+
id: first.workflowId,
|
|
395
|
+
});
|
|
396
|
+
expect(
|
|
397
|
+
await t.action(anyApi.host.resume, {
|
|
398
|
+
operationId: first.operation.operationId,
|
|
399
|
+
version: first.operation.version,
|
|
400
|
+
}),
|
|
401
|
+
).toMatchObject({
|
|
402
|
+
status: "unknown",
|
|
403
|
+
reason: "history_incomplete",
|
|
404
|
+
retryable: false,
|
|
405
|
+
});
|
|
406
|
+
expect(fixture.requests.filter((r) => r.method === "POST")).toHaveLength(1);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it("rolls back a failed workflow start so retry can bind the persisted intent", async () => {
|
|
410
|
+
const { executionWorkflow } = await import("../durableExecution/runtime.js");
|
|
411
|
+
const start = vi
|
|
412
|
+
.spyOn(executionWorkflow, "start")
|
|
413
|
+
.mockRejectedValueOnce(new Error("controlled scheduling failure"));
|
|
414
|
+
const t = setup();
|
|
415
|
+
try {
|
|
416
|
+
await expect(
|
|
417
|
+
t.action(anyApi.host.prepare, { requestKey: "failed-start" }),
|
|
418
|
+
).rejects.toThrow();
|
|
419
|
+
const saved = await t.query(
|
|
420
|
+
nested.betterStripe.balanceFunding.queries.readScopePreparation,
|
|
421
|
+
{ ...scope, stripeSubscriptionId, providerApiVersion: version },
|
|
422
|
+
);
|
|
423
|
+
const prior = await t.query(
|
|
424
|
+
nested.betterStripe.balanceFunding.queries.inspectOperation,
|
|
425
|
+
{
|
|
426
|
+
...scope,
|
|
427
|
+
operationId: saved.activeOperationId,
|
|
428
|
+
version: saved.operationVersion,
|
|
429
|
+
stripeSubscriptionId,
|
|
430
|
+
},
|
|
431
|
+
);
|
|
432
|
+
expect(prior.execution).toBeUndefined();
|
|
433
|
+
const reads = fixture.requests.length;
|
|
434
|
+
const retried = await t.action(anyApi.host.prepare, {
|
|
435
|
+
requestKey: "failed-start",
|
|
436
|
+
});
|
|
437
|
+
expect(retried.workflowId).toEqual(expect.any(String));
|
|
438
|
+
expect(fixture.requests).toHaveLength(reads);
|
|
439
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
440
|
+
expect(
|
|
441
|
+
await t.query(nested.betterStripe.balanceFunding.queries.getPreparation, {
|
|
442
|
+
...retried.operation,
|
|
443
|
+
stripeSubscriptionId,
|
|
444
|
+
}),
|
|
445
|
+
).toMatchObject({ status: "prepared" });
|
|
446
|
+
} finally {
|
|
447
|
+
start.mockRestore();
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it("resumes a paused pre-dispatch phase after unpause without inventing an unknown provider effect", async () => {
|
|
452
|
+
const t = setup();
|
|
453
|
+
const first = await t.action(anyApi.host.prepare, {
|
|
454
|
+
requestKey: "paused-before-create",
|
|
455
|
+
});
|
|
456
|
+
const saved = await t.query(
|
|
457
|
+
nested.betterStripe.balanceFunding.queries.readScopePreparation,
|
|
458
|
+
{ ...scope, stripeSubscriptionId, providerApiVersion: version },
|
|
459
|
+
);
|
|
460
|
+
const control = { ...scope, stripeSubscriptionId, preparationId: saved._id };
|
|
461
|
+
await t.mutation(
|
|
462
|
+
nested.betterStripe.balanceFunding.mutations.setStartsPaused,
|
|
463
|
+
{ ...control, paused: true },
|
|
464
|
+
);
|
|
465
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
466
|
+
expect(fixture.requests.filter((r) => r.method === "POST")).toHaveLength(0);
|
|
467
|
+
const blocked = await t.query(
|
|
468
|
+
nested.betterStripe.balanceFunding.queries.inspectOperation,
|
|
469
|
+
{ ...first.operation, stripeSubscriptionId },
|
|
470
|
+
);
|
|
471
|
+
expect(blocked.execution.create).toBeUndefined();
|
|
472
|
+
await t.mutation(
|
|
473
|
+
nested.betterStripe.balanceFunding.mutations.setStartsPaused,
|
|
474
|
+
{ ...control, paused: false },
|
|
475
|
+
);
|
|
476
|
+
await t.action(anyApi.host.resume, {
|
|
477
|
+
operationId: first.operation.operationId,
|
|
478
|
+
version: first.operation.version,
|
|
479
|
+
});
|
|
480
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
481
|
+
expect(
|
|
482
|
+
await t.query(nested.betterStripe.balanceFunding.queries.getPreparation, {
|
|
483
|
+
...first.operation,
|
|
484
|
+
stripeSubscriptionId,
|
|
485
|
+
}),
|
|
486
|
+
).toMatchObject({ status: "prepared" });
|
|
487
|
+
expect(fixture.requests.filter((r) => r.method === "POST")).toHaveLength(2);
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
it("recovers a positive journal receipt when cancellation races a failed receipt write", async () => {
|
|
491
|
+
const t = setup(false, true);
|
|
492
|
+
const first = await t.action(anyApi.host.prepare, {
|
|
493
|
+
requestKey: "cancel-receipt-store-outage",
|
|
494
|
+
});
|
|
495
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
496
|
+
await t.action(anyApi.host.cancel, {
|
|
497
|
+
operationId: first.operation.operationId,
|
|
498
|
+
version: first.operation.version,
|
|
499
|
+
});
|
|
500
|
+
await t.action(anyApi.host.resume, {
|
|
501
|
+
operationId: first.operation.operationId,
|
|
502
|
+
version: first.operation.version,
|
|
503
|
+
});
|
|
504
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
505
|
+
expect(
|
|
506
|
+
await t.query(nested.betterStripe.balanceFunding.queries.getPreparation, {
|
|
507
|
+
...first.operation,
|
|
508
|
+
stripeSubscriptionId,
|
|
509
|
+
}),
|
|
510
|
+
).toMatchObject({ status: "prepared" });
|
|
511
|
+
expect(fixture.requests.filter((r) => r.method === "POST")).toHaveLength(2);
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it("finishes apply from a restored positive journal when no record step was scheduled", async () => {
|
|
515
|
+
const t = setup(false, true, true);
|
|
516
|
+
const prepared = await t.action(anyApi.host.prepare, {
|
|
517
|
+
requestKey: "checkpoint-prepare",
|
|
518
|
+
});
|
|
519
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
520
|
+
const saved = await t.query(
|
|
521
|
+
nested.betterStripe.balanceFunding.queries.getPreparation,
|
|
522
|
+
{ ...prepared.operation, stripeSubscriptionId },
|
|
523
|
+
);
|
|
524
|
+
fixture.checkpointFault = true;
|
|
525
|
+
const applied = await t.action(anyApi.host.apply, {
|
|
526
|
+
preparationId: saved.preparationId,
|
|
527
|
+
enabled: true,
|
|
528
|
+
requestKey: "checkpoint-enable",
|
|
529
|
+
});
|
|
530
|
+
await t.finishAllScheduledFunctions(vi.runAllTimers);
|
|
531
|
+
await t.action(anyApi.host.cancel, {
|
|
532
|
+
operationId: applied.operation.operationId,
|
|
533
|
+
version: applied.operation.version,
|
|
534
|
+
});
|
|
535
|
+
expect(
|
|
536
|
+
await t.action(anyApi.host.resume, {
|
|
537
|
+
operationId: applied.operation.operationId,
|
|
538
|
+
version: applied.operation.version,
|
|
539
|
+
}),
|
|
540
|
+
).toMatchObject({ status: "accepted" });
|
|
541
|
+
expect(
|
|
542
|
+
await t.action(anyApi.host.inspect, {
|
|
543
|
+
operationId: applied.operation.operationId,
|
|
544
|
+
version: applied.operation.version,
|
|
545
|
+
}),
|
|
546
|
+
).toMatchObject({ state: "succeeded" });
|
|
547
|
+
expect(
|
|
548
|
+
fixture.requests.filter(
|
|
549
|
+
(r) => r.path.includes("subscriptions") && r.method === "POST",
|
|
550
|
+
),
|
|
551
|
+
).toHaveLength(1);
|
|
552
|
+
});
|