@fantastic.dev/better-stripe 0.107.0 → 0.109.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 +12 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts +31 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.js +112 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts +17 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js +191 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts +29 -0
- package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/invocation.js +205 -0
- package/dist/client/billing/renewalAttach/internal/observation/invocation.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/profile.js +5 -1
- package/dist/client/billing/renewalAttach/internal/observation/profile.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/reader.d.ts +10 -0
- package/dist/client/billing/renewalAttach/internal/observation/reader.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/reader.js +30 -0
- package/dist/client/billing/renewalAttach/internal/observation/reader.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.d.ts +44 -0
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.js +145 -0
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts +9 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js +2 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts +2 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +9 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
- package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +107 -0
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/observation/freshActor.integration.test.ts +360 -0
- package/src/client/billing/renewalAttach/internal/observation/freshActor.ts +175 -0
- package/src/client/billing/renewalAttach/internal/observation/freshActorControls.integration.test.ts +442 -0
- package/src/client/billing/renewalAttach/internal/observation/freshTransport.ts +252 -0
- package/src/client/billing/renewalAttach/internal/observation/invocation.ts +299 -0
- package/src/client/billing/renewalAttach/internal/observation/profile.ts +9 -1
- package/src/client/billing/renewalAttach/internal/observation/reader.integration.test.ts +93 -0
- package/src/client/billing/renewalAttach/internal/observation/reader.ts +35 -0
- package/src/client/billing/renewalAttach/internal/observation/readerAuthorization.ts +179 -0
- package/src/client/billing/renewalAttach/internal/observation/readerControls.integration.test.ts +553 -0
- package/src/client/billing/renewalAttach/internal/operations/sourceOperations.ts +11 -0
- package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +12 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/freshObservation.ts +94 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/historySnapshot.ts +5 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationReader.ts +101 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +41 -4
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +5 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { makeFunctionReference, queryGeneric } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import { vi } from "vitest";
|
|
4
|
+
import { historySnapshot } from "./historySnapshot.js";
|
|
5
|
+
import { admissionControls } from "./producerConfigureAdmission.js";
|
|
6
|
+
import {
|
|
7
|
+
captureMaintainedJournalBinding,
|
|
8
|
+
readCheckedJournalActionRPC,
|
|
9
|
+
} from "../producer/classOwnedActionRoot.js";
|
|
10
|
+
export const observerIdentity = {
|
|
11
|
+
subject: "observer",
|
|
12
|
+
issuer: "https://host.test",
|
|
13
|
+
tokenIdentifier: "https://host.test|observer",
|
|
14
|
+
};
|
|
15
|
+
export const readerControls = {
|
|
16
|
+
grant: {} as Record<string, unknown>,
|
|
17
|
+
args: {} as Record<string, unknown>,
|
|
18
|
+
authorizations: 0,
|
|
19
|
+
deny: false,
|
|
20
|
+
reply: null as
|
|
21
|
+
null | ((grant: Record<string, unknown>, count: number) => unknown),
|
|
22
|
+
};
|
|
23
|
+
export const authorizeObservation = queryGeneric({
|
|
24
|
+
args: {
|
|
25
|
+
componentScope: v.string(),
|
|
26
|
+
parentOperationId: v.string(),
|
|
27
|
+
operationId: v.string(),
|
|
28
|
+
},
|
|
29
|
+
handler: async (ctx, args) => {
|
|
30
|
+
readerControls.authorizations++;
|
|
31
|
+
const who = await ctx.auth.getUserIdentity();
|
|
32
|
+
if (
|
|
33
|
+
!who ||
|
|
34
|
+
who.tokenIdentifier !== observerIdentity.tokenIdentifier ||
|
|
35
|
+
readerControls.deny ||
|
|
36
|
+
Object.entries(args).some(
|
|
37
|
+
([key, value]) => readerControls.args[key] !== value,
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
return null;
|
|
41
|
+
const snapshot = structuredClone(readerControls.grant);
|
|
42
|
+
return readerControls.reply
|
|
43
|
+
? readerControls.reply(snapshot, readerControls.authorizations)
|
|
44
|
+
: snapshot;
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
export async function prepareObservationReader(
|
|
48
|
+
h: Parameters<typeof historySnapshot>[0],
|
|
49
|
+
options: NonNullable<Parameters<typeof historySnapshot>[1]> = {},
|
|
50
|
+
) {
|
|
51
|
+
const full = await historySnapshot(h, options);
|
|
52
|
+
const operationId = full.configure.operation.operationId;
|
|
53
|
+
const parentOperationId = full.parent.operation.operationId;
|
|
54
|
+
const binding = await captureMaintainedJournalBinding(h.sdk, {
|
|
55
|
+
actualActionCtx: h.ctx,
|
|
56
|
+
operationId,
|
|
57
|
+
});
|
|
58
|
+
const component = readCheckedJournalActionRPC(binding).component;
|
|
59
|
+
const authorizationQuery = makeFunctionReference<
|
|
60
|
+
"query",
|
|
61
|
+
{ componentScope: string; parentOperationId: string; operationId: string },
|
|
62
|
+
unknown
|
|
63
|
+
>("initialOwner:authorize");
|
|
64
|
+
const entry = Object.freeze({
|
|
65
|
+
component,
|
|
66
|
+
componentScope: "trusted-installation-a",
|
|
67
|
+
authorizationQuery,
|
|
68
|
+
});
|
|
69
|
+
admissionControls.history.splice(0, admissionControls.history.length, entry);
|
|
70
|
+
h.core.owner.retire();
|
|
71
|
+
vi.setSystemTime(
|
|
72
|
+
(JSON.parse(full.configure.operation.recordJSON).configureRecord
|
|
73
|
+
.configuration.preparation.expected.periodEnd +
|
|
74
|
+
1) *
|
|
75
|
+
1000,
|
|
76
|
+
);
|
|
77
|
+
readerControls.args = {
|
|
78
|
+
componentScope: entry.componentScope,
|
|
79
|
+
parentOperationId,
|
|
80
|
+
operationId,
|
|
81
|
+
};
|
|
82
|
+
readerControls.grant = {
|
|
83
|
+
...readerControls.args,
|
|
84
|
+
tokenIdentifier: observerIdentity.tokenIdentifier,
|
|
85
|
+
providerScope: {
|
|
86
|
+
mode: "platform",
|
|
87
|
+
stripeAccount: null,
|
|
88
|
+
livemode: false,
|
|
89
|
+
customerAccountId: "acct_buyer",
|
|
90
|
+
subscriptionId: "sub_original",
|
|
91
|
+
scheduleId: "sub_sched_owned",
|
|
92
|
+
},
|
|
93
|
+
authorizationId: "fresh-observation",
|
|
94
|
+
authorizationRevision: 3,
|
|
95
|
+
expiresAtMs: Date.now() + 60000,
|
|
96
|
+
};
|
|
97
|
+
readerControls.authorizations = 0;
|
|
98
|
+
readerControls.deny = false;
|
|
99
|
+
readerControls.reply = null;
|
|
100
|
+
return { full, operationId, parentOperationId, entry };
|
|
101
|
+
}
|
package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts
CHANGED
|
@@ -30,6 +30,9 @@ const controls = vi.hoisted(() => ({
|
|
|
30
30
|
}[],
|
|
31
31
|
legacy: 0,
|
|
32
32
|
selectors: 0,
|
|
33
|
+
history: [] as unknown[],
|
|
34
|
+
observation: [] as unknown[],
|
|
35
|
+
onSelect: null as null | ((client: object) => void),
|
|
33
36
|
}));
|
|
34
37
|
vi.mock("../operations/sourceOperations.js", () => {
|
|
35
38
|
const poison = () => {
|
|
@@ -41,6 +44,8 @@ vi.mock("../operations/sourceOperations.js", () => {
|
|
|
41
44
|
COMPILED_RECOVERY_ENTRIES: controls.recovery,
|
|
42
45
|
COMPILED_PREFLIGHT_ENTRIES: controls.preflight,
|
|
43
46
|
COMPILED_CONFIGURE_WRITE_ENTRIES: controls.write,
|
|
47
|
+
COMPILED_OBSERVATION_HISTORY_ENTRIES: controls.history,
|
|
48
|
+
COMPILED_FRESH_OBSERVATION_ENTRIES: controls.observation,
|
|
44
49
|
loadConfigureWriteTransportSource: poison,
|
|
45
50
|
loadConfigureReplayTransportSource: poison,
|
|
46
51
|
loadFixedConfigureWriteOperation: poison,
|
|
@@ -78,17 +83,36 @@ vi.mock("../../../../helpers.js", async (original) => {
|
|
|
78
83
|
...actual,
|
|
79
84
|
getStripeClient(...args: Parameters<typeof actual.getStripeClient>) {
|
|
80
85
|
controls.selectors++;
|
|
81
|
-
|
|
86
|
+
const client = actual.getStripeClient(...args);
|
|
87
|
+
controls.onSelect?.(client);
|
|
88
|
+
return client;
|
|
82
89
|
},
|
|
83
90
|
};
|
|
84
91
|
});
|
|
85
92
|
export const admissionControls = controls;
|
|
86
93
|
const canonical = (value: unknown) => JSON.stringify(renewalSnapshot(value));
|
|
94
|
+
function admissionBaseline(targetInterval?: "week") {
|
|
95
|
+
const baseline = makeConfigureReadNativeBaseline();
|
|
96
|
+
if (targetInterval) {
|
|
97
|
+
const target = baseline.original.attachRequest.preparation.targetPrice;
|
|
98
|
+
Object.assign(target.recurring, { interval: targetInterval });
|
|
99
|
+
baseline.original.originalBundle.wireTargetPrice = structuredClone(target);
|
|
100
|
+
const subscription =
|
|
101
|
+
baseline.original.attachRequest.preparation.subscription;
|
|
102
|
+
Object.assign(subscription, { trial_start: null, trial_end: null });
|
|
103
|
+
baseline.original.originalBundle.wireSubscription =
|
|
104
|
+
structuredClone(subscription);
|
|
105
|
+
}
|
|
106
|
+
return baseline;
|
|
107
|
+
}
|
|
87
108
|
beforeEach(() => {
|
|
88
109
|
controls.legacy = 0;
|
|
89
110
|
controls.preflight.splice(0);
|
|
90
111
|
controls.write.splice(0);
|
|
91
112
|
controls.selectors = 0;
|
|
113
|
+
controls.history.splice(0);
|
|
114
|
+
controls.observation.splice(0);
|
|
115
|
+
controls.onSelect = null;
|
|
92
116
|
controls.entries.splice(0, controls.entries.length, {
|
|
93
117
|
coversRetained: () => true,
|
|
94
118
|
coversFresh: () => true,
|
|
@@ -112,12 +136,15 @@ afterEach(() => {
|
|
|
112
136
|
async function setup(
|
|
113
137
|
input: Parameters<Parameters<typeof initialOperations>[0]>[0],
|
|
114
138
|
completion: { mode: string; posts: number },
|
|
115
|
-
hooks: {
|
|
139
|
+
hooks: {
|
|
140
|
+
beforeFetch?: (path: string, method: string) => Promise<void>;
|
|
141
|
+
targetInterval?: "week";
|
|
142
|
+
},
|
|
116
143
|
) {
|
|
117
144
|
const { journal, fresh, sdk, ctx, index } = input;
|
|
118
145
|
assert(fresh.result.disposition === "acquired" && fresh.call);
|
|
119
146
|
const parentReservation = fresh.result.reservation;
|
|
120
|
-
const baseline =
|
|
147
|
+
const baseline = admissionBaseline(hooks.targetInterval);
|
|
121
148
|
const source = captureRetainedInput(baseline.original);
|
|
122
149
|
const calls: {
|
|
123
150
|
method: string;
|
|
@@ -364,11 +391,19 @@ async function setup(
|
|
|
364
391
|
complete,
|
|
365
392
|
eventsFor,
|
|
366
393
|
configureReads,
|
|
394
|
+
setControlledRead(path: string, body: unknown) {
|
|
395
|
+
routes.set(path, body);
|
|
396
|
+
},
|
|
367
397
|
};
|
|
368
398
|
}
|
|
369
399
|
export async function configureAdmissionFixture(
|
|
370
400
|
work: (h: Awaited<ReturnType<typeof setup>>) => Promise<void>,
|
|
371
401
|
options: {
|
|
402
|
+
targetInterval?: "week";
|
|
403
|
+
identity?: NonNullable<Parameters<typeof initialOperations>[2]>["identity"];
|
|
404
|
+
hostQuery?: NonNullable<
|
|
405
|
+
Parameters<typeof initialOperations>[2]
|
|
406
|
+
>["hostQuery"];
|
|
372
407
|
count?: number;
|
|
373
408
|
keys?: readonly string[];
|
|
374
409
|
afterBind?: (reply: unknown) => Promise<void>;
|
|
@@ -383,7 +418,7 @@ export async function configureAdmissionFixture(
|
|
|
383
418
|
beforeFetch?: (path: string, method: string) => Promise<void>;
|
|
384
419
|
} = {},
|
|
385
420
|
) {
|
|
386
|
-
const baseline =
|
|
421
|
+
const baseline = admissionBaseline(options.targetInterval);
|
|
387
422
|
const completion = { mode: "initial", posts: 0, appends: 0 };
|
|
388
423
|
await initialOperations(
|
|
389
424
|
async (input) => {
|
|
@@ -397,6 +432,8 @@ export async function configureAdmissionFixture(
|
|
|
397
432
|
options.count ?? 1,
|
|
398
433
|
{
|
|
399
434
|
keys: options.keys,
|
|
435
|
+
identity: options.identity,
|
|
436
|
+
hostQuery: options.hostQuery,
|
|
400
437
|
source: captureRetainedInput(baseline.original),
|
|
401
438
|
afterBind: options.afterBind,
|
|
402
439
|
afterQuery: options.afterQuery,
|
|
@@ -3,6 +3,7 @@ import { v } from "convex/values";
|
|
|
3
3
|
import { convexTest } from "convex-test";
|
|
4
4
|
import {
|
|
5
5
|
actionGeneric,
|
|
6
|
+
queryGeneric,
|
|
6
7
|
defineSchema,
|
|
7
8
|
makeFunctionReference,
|
|
8
9
|
getFunctionAddress,
|
|
@@ -38,6 +39,8 @@ export async function initialOperations(
|
|
|
38
39
|
}) => Promise<void>,
|
|
39
40
|
count = 1,
|
|
40
41
|
options: {
|
|
42
|
+
identity?: { subject: string; issuer: string; tokenIdentifier: string };
|
|
43
|
+
hostQuery?: ReturnType<typeof queryGeneric>;
|
|
41
44
|
epochMs?: number;
|
|
42
45
|
workEndWallMs?: number;
|
|
43
46
|
endWallMs?: number;
|
|
@@ -176,6 +179,7 @@ export async function initialOperations(
|
|
|
176
179
|
>();
|
|
177
180
|
let secondaryId = 0;
|
|
178
181
|
const host = {
|
|
182
|
+
...(options.hostQuery ? { authorize: options.hostQuery } : {}),
|
|
179
183
|
secondary: actionGeneric({
|
|
180
184
|
args: { id: v.string() },
|
|
181
185
|
handler: async (ctx, args): Promise<null> => {
|
|
@@ -302,7 +306,7 @@ export async function initialOperations(
|
|
|
302
306
|
"./initialOwner.ts": async () => host,
|
|
303
307
|
});
|
|
304
308
|
t.registerComponent("betterStripe", schema, modules);
|
|
305
|
-
await t.action(
|
|
309
|
+
await (options.identity ? t.withIdentity(options.identity) : t).action(
|
|
306
310
|
makeFunctionReference<"action", {}, null>("initialOwner:run"),
|
|
307
311
|
{},
|
|
308
312
|
);
|