@fantastic.dev/better-stripe 0.109.0 → 0.110.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 +41 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.js +40 -3
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts +10 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js +162 -57
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/invoiceAuthorization.d.ts +14 -0
- package/dist/client/billing/renewalAttach/internal/observation/invoiceAuthorization.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/invoiceAuthorization.js +109 -0
- package/dist/client/billing/renewalAttach/internal/observation/invoiceAuthorization.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/invoicePlan.d.ts +20 -0
- package/dist/client/billing/renewalAttach/internal/observation/invoicePlan.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/invoicePlan.js +176 -0
- package/dist/client/billing/renewalAttach/internal/observation/invoicePlan.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/profile.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/types.d.ts +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/types.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/types.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts +24 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js.map +1 -1
- package/dist/client/billing/renewalObservation/evidence-invoice.d.ts.map +1 -1
- package/dist/client/billing/renewalObservation/evidence-invoice.js +4 -0
- package/dist/client/billing/renewalObservation/evidence-invoice.js.map +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/queries.d.ts +1 -1
- package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
- package/docs/renewal-invoice-reads.md +85 -0
- package/docs/renewal-material-observation.md +4 -1
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/observation/freshActor.ts +69 -3
- package/src/client/billing/renewalAttach/internal/observation/freshTransport.ts +189 -59
- package/src/client/billing/renewalAttach/internal/observation/invoiceActor.integration.test.ts +142 -0
- package/src/client/billing/renewalAttach/internal/observation/invoiceActorControls.integration.test.ts +495 -0
- package/src/client/billing/renewalAttach/internal/observation/invoiceAuthorization.ts +145 -0
- package/src/client/billing/renewalAttach/internal/observation/invoicePlan.ts +284 -0
- package/src/client/billing/renewalAttach/internal/observation/profile.ts +1 -1
- package/src/client/billing/renewalAttach/internal/observation/types.ts +7 -1
- package/src/client/billing/renewalAttach/internal/operations/sourceOperations.ts +30 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureWriteControls.integration.test.ts +74 -62
- package/src/client/billing/renewalAttach/internal/test-fixtures/invoiceObservation.ts +158 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +11 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +4 -0
- package/src/client/billing/renewalObservation/evidence-invoice-identity.test.ts +61 -0
- package/src/client/billing/renewalObservation/evidence-invoice.ts +9 -0
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { getFunctionAddress } from "convex/server";
|
|
2
|
+
import {
|
|
3
|
+
captureInvoiceObservationProfile,
|
|
4
|
+
invoiceProfileGuard,
|
|
5
|
+
} from "./invoiceAuthorization.js";
|
|
6
|
+
import type { InvoiceObservationProfile } from "../operations/sourceOperations.js";
|
|
1
7
|
import {
|
|
2
8
|
captureObservationInvocation,
|
|
3
9
|
readObservationInvocation,
|
|
@@ -28,10 +34,42 @@ export async function captureFreshRenewalObservation(
|
|
|
28
34
|
raw: unknown,
|
|
29
35
|
) {
|
|
30
36
|
need(arguments.length === 2);
|
|
37
|
+
return captureFreshObservation(root, raw, null);
|
|
38
|
+
}
|
|
39
|
+
/** Separate qualified invoice capability; EMPTY before any input reflection. */
|
|
40
|
+
export async function captureFreshInvoiceRenewalObservation(
|
|
41
|
+
root: object,
|
|
42
|
+
raw: unknown,
|
|
43
|
+
) {
|
|
44
|
+
need(arguments.length === 2);
|
|
45
|
+
const profile = captureInvoiceObservationProfile(root);
|
|
46
|
+
return captureFreshObservation(root, raw, profile);
|
|
47
|
+
}
|
|
48
|
+
async function captureFreshObservation(
|
|
49
|
+
root: object,
|
|
50
|
+
raw: unknown,
|
|
51
|
+
invoiceProfile: InvoiceObservationProfile | null,
|
|
52
|
+
) {
|
|
31
53
|
const profile = captureFreshObservationProfile(root);
|
|
54
|
+
const invoiceAddress =
|
|
55
|
+
invoiceProfile &&
|
|
56
|
+
JSON.stringify(getFunctionAddress(invoiceProfile.authorizationQuery));
|
|
57
|
+
const invoiceGuard = () => {
|
|
58
|
+
if (invoiceProfile) {
|
|
59
|
+
invoiceProfileGuard(invoiceProfile);
|
|
60
|
+
need(
|
|
61
|
+
invoiceProfile.freshProfile === profile &&
|
|
62
|
+
JSON.stringify(
|
|
63
|
+
getFunctionAddress(invoiceProfile.authorizationQuery),
|
|
64
|
+
) === invoiceAddress,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
invoiceGuard();
|
|
32
69
|
const token = await captureObservationInvocation(root, raw);
|
|
33
70
|
let state: ObservationInvocationState;
|
|
34
71
|
try {
|
|
72
|
+
invoiceGuard();
|
|
35
73
|
state = readObservationInvocation(token);
|
|
36
74
|
need(state.historyEntry === profile.historyEntry);
|
|
37
75
|
} catch (error) {
|
|
@@ -44,8 +82,17 @@ export async function captureFreshRenewalObservation(
|
|
|
44
82
|
need(arguments.length === 0 && !used);
|
|
45
83
|
used = true;
|
|
46
84
|
try {
|
|
85
|
+
invoiceGuard();
|
|
47
86
|
const captured = await state.captureHistory();
|
|
48
|
-
|
|
87
|
+
invoiceGuard();
|
|
88
|
+
const transport = captureFreshGetTransport(
|
|
89
|
+
token,
|
|
90
|
+
profile,
|
|
91
|
+
invoiceProfile,
|
|
92
|
+
);
|
|
93
|
+
let invoiceResult: Awaited<
|
|
94
|
+
ReturnType<typeof transport.acquireInvoices>
|
|
95
|
+
> | null = null;
|
|
49
96
|
async function release(
|
|
50
97
|
status:
|
|
51
98
|
| "fresh_observation_data"
|
|
@@ -58,10 +105,17 @@ export async function captureFreshRenewalObservation(
|
|
|
58
105
|
reason: string | null,
|
|
59
106
|
failure: ReadFailure | null = null,
|
|
60
107
|
) {
|
|
61
|
-
await
|
|
108
|
+
await transport.finalizeInvoices();
|
|
62
109
|
transport.guard();
|
|
63
110
|
const output = captureReaderQueryDATA({
|
|
64
111
|
status,
|
|
112
|
+
...(invoiceProfile
|
|
113
|
+
? {
|
|
114
|
+
invoiceContext: invoiceResult?.context ?? null,
|
|
115
|
+
invoiceInventory: invoiceResult?.status ?? "not_acquired",
|
|
116
|
+
invoiceReason: invoiceResult?.reason ?? null,
|
|
117
|
+
}
|
|
118
|
+
: {}),
|
|
65
119
|
...captured,
|
|
66
120
|
reads,
|
|
67
121
|
evidence,
|
|
@@ -119,7 +173,7 @@ export async function captureFreshRenewalObservation(
|
|
|
119
173
|
configuration: captured.history.record.configuration,
|
|
120
174
|
configureReceipt: captured.history.rawConfigureReceipt,
|
|
121
175
|
reads,
|
|
122
|
-
invoiceContext: null,
|
|
176
|
+
invoiceContext: invoiceResult?.context ?? null,
|
|
123
177
|
historicalSnapshot: null,
|
|
124
178
|
});
|
|
125
179
|
} catch {
|
|
@@ -159,6 +213,18 @@ export async function captureFreshRenewalObservation(
|
|
|
159
213
|
validateCoupon(captured.history.record, id, result.body);
|
|
160
214
|
reads.coupons.push(result.body);
|
|
161
215
|
}
|
|
216
|
+
if (invoiceProfile) {
|
|
217
|
+
invoiceResult = await transport.acquireInvoices();
|
|
218
|
+
if (invoiceResult.status === "provider_rejected")
|
|
219
|
+
return await release(
|
|
220
|
+
"observation_provider_rejected",
|
|
221
|
+
null,
|
|
222
|
+
null,
|
|
223
|
+
"complete",
|
|
224
|
+
null,
|
|
225
|
+
invoiceResult.failure,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
162
228
|
const evidence = await analyze();
|
|
163
229
|
return await release(
|
|
164
230
|
"fresh_observation_data",
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import Stripe from "stripe";
|
|
2
|
+
import { getFunctionAddress } from "convex/server";
|
|
3
|
+
import {
|
|
4
|
+
createInvoiceReadPlan,
|
|
5
|
+
InvoiceAcquisitionStop,
|
|
6
|
+
} from "./invoicePlan.js";
|
|
7
|
+
import {
|
|
8
|
+
createInvoiceAuthorization,
|
|
9
|
+
invoiceProfileGuard,
|
|
10
|
+
} from "./invoiceAuthorization.js";
|
|
11
|
+
import type { InvoiceObservationProfile } from "../operations/sourceOperations.js";
|
|
12
|
+
import type { InvoiceContextV1 } from "../../../renewalObservation/evidence-v1-types.js";
|
|
2
13
|
import { types } from "node:util";
|
|
3
14
|
import {
|
|
4
15
|
COMPILED_FRESH_OBSERVATION_ENTRIES,
|
|
@@ -16,6 +27,7 @@ import {
|
|
|
16
27
|
couponReadRow,
|
|
17
28
|
observationCouponIds,
|
|
18
29
|
validateBaseRouting,
|
|
30
|
+
validateCoupon,
|
|
19
31
|
} from "./profile.js";
|
|
20
32
|
import { captureObservationReply, safeReadDiagnostics } from "./capture.js";
|
|
21
33
|
import type {
|
|
@@ -67,13 +79,30 @@ type Settlement = Readonly<{
|
|
|
67
79
|
export function captureFreshGetTransport(
|
|
68
80
|
token: object,
|
|
69
81
|
profile: FreshObservationProfile,
|
|
82
|
+
invoiceProfile: InvoiceObservationProfile | null = null,
|
|
70
83
|
) {
|
|
71
|
-
freshNeed(arguments.length === 2);
|
|
84
|
+
freshNeed(arguments.length === 2 || arguments.length === 3);
|
|
72
85
|
const state = readObservationInvocation(token),
|
|
73
86
|
captured = state.readCaptured();
|
|
74
87
|
freshNeed(state.historyEntry === profile.historyEntry);
|
|
75
88
|
const covers = profile.coversObservation;
|
|
89
|
+
const invoiceAddress =
|
|
90
|
+
invoiceProfile &&
|
|
91
|
+
JSON.stringify(getFunctionAddress(invoiceProfile.authorizationQuery));
|
|
92
|
+
let invoiceAuthorization: ReturnType<
|
|
93
|
+
typeof createInvoiceAuthorization
|
|
94
|
+
> | null = null;
|
|
95
|
+
let invoiceUsed = false;
|
|
76
96
|
function profileGuard() {
|
|
97
|
+
if (invoiceProfile) {
|
|
98
|
+
invoiceProfileGuard(invoiceProfile);
|
|
99
|
+
freshNeed(
|
|
100
|
+
invoiceProfile.freshProfile === profile &&
|
|
101
|
+
JSON.stringify(
|
|
102
|
+
getFunctionAddress(invoiceProfile.authorizationQuery),
|
|
103
|
+
) === invoiceAddress,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
77
106
|
readObservationInvocation(token);
|
|
78
107
|
freshNeed(
|
|
79
108
|
COMPILED_FRESH_OBSERVATION_ENTRIES.includes(profile) &&
|
|
@@ -105,6 +134,7 @@ export function captureFreshGetTransport(
|
|
|
105
134
|
);
|
|
106
135
|
function guard() {
|
|
107
136
|
profileGuard();
|
|
137
|
+
invoiceAuthorization?.guard();
|
|
108
138
|
selection.check();
|
|
109
139
|
freshNeed(
|
|
110
140
|
Object.getPrototypeOf(client) === Stripe.prototype &&
|
|
@@ -136,6 +166,70 @@ export function captureFreshGetTransport(
|
|
|
136
166
|
freshNeed(ordinal - 4 < ids.length);
|
|
137
167
|
return couponReadRow(ids[ordinal - 4], ordinal + 1);
|
|
138
168
|
}
|
|
169
|
+
async function dispatch(row: ObservationReadRow, invoiceRead = false) {
|
|
170
|
+
if (invoiceRead) await invoiceAuthorization!.authorize();
|
|
171
|
+
else await state.authorizeUnchanged();
|
|
172
|
+
guard();
|
|
173
|
+
|
|
174
|
+
let promise: object | null = null;
|
|
175
|
+
const cell: { capsule: Settlement | null } = { capsule: null };
|
|
176
|
+
const result: unknown = await state.owned(() => {
|
|
177
|
+
const actualPromise: unknown = Reflect.apply(method, client, [
|
|
178
|
+
"GET",
|
|
179
|
+
row.path,
|
|
180
|
+
undefined,
|
|
181
|
+
row.options,
|
|
182
|
+
]);
|
|
183
|
+
freshNeed(
|
|
184
|
+
actualPromise &&
|
|
185
|
+
typeof actualPromise === "object" &&
|
|
186
|
+
!types.isProxy(actualPromise) &&
|
|
187
|
+
types.isPromise(actualPromise),
|
|
188
|
+
);
|
|
189
|
+
promise = actualPromise;
|
|
190
|
+
return Reflect.apply(nativeThen, actualPromise, [
|
|
191
|
+
(value: unknown) =>
|
|
192
|
+
(cell.capsule = Object.freeze({
|
|
193
|
+
promise: actualPromise,
|
|
194
|
+
kind: "fulfilled" as const,
|
|
195
|
+
value,
|
|
196
|
+
})),
|
|
197
|
+
(value: unknown) =>
|
|
198
|
+
(cell.capsule = Object.freeze({
|
|
199
|
+
promise: actualPromise,
|
|
200
|
+
kind: "rejected" as const,
|
|
201
|
+
value,
|
|
202
|
+
})),
|
|
203
|
+
]) as Promise<Settlement>;
|
|
204
|
+
}, guard);
|
|
205
|
+
guard();
|
|
206
|
+
const capsule = cell.capsule;
|
|
207
|
+
freshNeed(capsule && result === capsule && capsule.promise === promise);
|
|
208
|
+
const settled: Settlement = capsule;
|
|
209
|
+
if (settled.kind === "rejected") {
|
|
210
|
+
ended = true;
|
|
211
|
+
return Object.freeze({
|
|
212
|
+
kind: "provider_rejected" as const,
|
|
213
|
+
failure: freeze({
|
|
214
|
+
category: "provider_rejected" as const,
|
|
215
|
+
phase: "read" as const,
|
|
216
|
+
resource: row.resource,
|
|
217
|
+
ordinal: row.ordinal,
|
|
218
|
+
request: {
|
|
219
|
+
method: "GET" as const,
|
|
220
|
+
path: row.path,
|
|
221
|
+
apiVersion: row.options.apiVersion,
|
|
222
|
+
},
|
|
223
|
+
diagnostics: safeReadDiagnostics(settled.value),
|
|
224
|
+
outcome: "unknown" as const,
|
|
225
|
+
operationalAuthority: false as const,
|
|
226
|
+
}),
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
const body = captureObservationReply(settled.value);
|
|
230
|
+
guard();
|
|
231
|
+
return Object.freeze({ kind: "fulfilled" as const, body });
|
|
232
|
+
}
|
|
139
233
|
return Object.freeze({
|
|
140
234
|
guard,
|
|
141
235
|
async read(
|
|
@@ -152,7 +246,7 @@ export function captureFreshGetTransport(
|
|
|
152
246
|
busy = true;
|
|
153
247
|
try {
|
|
154
248
|
guard();
|
|
155
|
-
freshNeed(ordinal < 44 && !types.isProxy(raw));
|
|
249
|
+
freshNeed(!invoiceUsed && ordinal < 44 && !types.isProxy(raw));
|
|
156
250
|
const row = expected(),
|
|
157
251
|
actual = closed(raw, [
|
|
158
252
|
"resource",
|
|
@@ -178,68 +272,104 @@ export function captureFreshGetTransport(
|
|
|
178
272
|
options.apiVersion === row.options.apiVersion &&
|
|
179
273
|
options.maxNetworkRetries === 0,
|
|
180
274
|
);
|
|
181
|
-
await
|
|
182
|
-
guard();
|
|
275
|
+
const result = await dispatch(row);
|
|
183
276
|
ordinal++;
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
277
|
+
if (result.kind === "provider_rejected") return result;
|
|
278
|
+
const body = result.body;
|
|
279
|
+
bodies.push(body);
|
|
280
|
+
return Object.freeze({ kind: "fulfilled" as const, body });
|
|
281
|
+
} catch (error) {
|
|
282
|
+
ended = true;
|
|
283
|
+
state.close();
|
|
284
|
+
throw error;
|
|
285
|
+
} finally {
|
|
286
|
+
busy = false;
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
async finalizeInvoices() {
|
|
290
|
+
if (invoiceAuthorization) await invoiceAuthorization.authorize();
|
|
291
|
+
else await state.authorizeUnchanged();
|
|
292
|
+
guard();
|
|
293
|
+
},
|
|
294
|
+
async acquireInvoices(): Promise<
|
|
295
|
+
Readonly<{
|
|
296
|
+
status: "complete" | "unavailable" | "conflict" | "provider_rejected";
|
|
297
|
+
context: InvoiceContextV1 | null;
|
|
298
|
+
reason: string | null;
|
|
299
|
+
failure: ReadFailure | null;
|
|
300
|
+
}>
|
|
301
|
+
> {
|
|
302
|
+
freshNeed(
|
|
303
|
+
arguments.length === 0 &&
|
|
304
|
+
invoiceProfile &&
|
|
305
|
+
!invoiceUsed &&
|
|
306
|
+
!busy &&
|
|
307
|
+
!ended,
|
|
308
|
+
);
|
|
309
|
+
invoiceUsed = true;
|
|
310
|
+
busy = true;
|
|
311
|
+
try {
|
|
215
312
|
guard();
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
313
|
+
const reads: ObservationReads = {
|
|
314
|
+
schedule: bodies[0],
|
|
315
|
+
subscription: bodies[1],
|
|
316
|
+
targetPrice: bodies[2],
|
|
317
|
+
billingCustomer: bodies[3],
|
|
318
|
+
coupons: bodies.slice(4),
|
|
319
|
+
};
|
|
320
|
+
validateBaseRouting(captured.history.record, reads);
|
|
321
|
+
const ids = observationCouponIds(
|
|
322
|
+
captured.history.record,
|
|
323
|
+
reads.subscription,
|
|
324
|
+
);
|
|
325
|
+
freshNeed(ordinal === 4 + ids.length);
|
|
326
|
+
reads.coupons.forEach((body, index) =>
|
|
327
|
+
validateCoupon(captured.history.record, ids[index], body),
|
|
328
|
+
);
|
|
329
|
+
let plan: ReturnType<typeof createInvoiceReadPlan>;
|
|
330
|
+
try {
|
|
331
|
+
plan = createInvoiceReadPlan(captured.history.record, reads, ordinal);
|
|
332
|
+
} catch (error) {
|
|
333
|
+
if (!(error instanceof InvoiceAcquisitionStop)) throw error;
|
|
221
334
|
return Object.freeze({
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
resource: row.resource,
|
|
227
|
-
ordinal: row.ordinal,
|
|
228
|
-
request: {
|
|
229
|
-
method: "GET" as const,
|
|
230
|
-
path: row.path,
|
|
231
|
-
apiVersion: row.options.apiVersion,
|
|
232
|
-
},
|
|
233
|
-
diagnostics: safeReadDiagnostics(settled.value),
|
|
234
|
-
outcome: "unknown" as const,
|
|
235
|
-
operationalAuthority: false as const,
|
|
236
|
-
}),
|
|
335
|
+
status: error.kind,
|
|
336
|
+
context: null,
|
|
337
|
+
reason: error.reason,
|
|
338
|
+
failure: null,
|
|
237
339
|
});
|
|
238
340
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
341
|
+
invoiceAuthorization = createInvoiceAuthorization(
|
|
342
|
+
token,
|
|
343
|
+
invoiceProfile,
|
|
344
|
+
plan.pins,
|
|
345
|
+
);
|
|
346
|
+
while (!plan.done()) {
|
|
347
|
+
const result = await dispatch(plan.row(), true);
|
|
348
|
+
if (result.kind === "provider_rejected")
|
|
349
|
+
return Object.freeze({
|
|
350
|
+
status: "provider_rejected",
|
|
351
|
+
context: null,
|
|
352
|
+
reason: null,
|
|
353
|
+
failure: result.failure,
|
|
354
|
+
});
|
|
355
|
+
try {
|
|
356
|
+
plan.accept(result.body);
|
|
357
|
+
} catch (error) {
|
|
358
|
+
if (!(error instanceof InvoiceAcquisitionStop)) throw error;
|
|
359
|
+
return Object.freeze({
|
|
360
|
+
status: error.kind,
|
|
361
|
+
context: null,
|
|
362
|
+
reason: error.reason,
|
|
363
|
+
failure: null,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return Object.freeze({
|
|
368
|
+
status: "complete",
|
|
369
|
+
context: plan.context(),
|
|
370
|
+
reason: null,
|
|
371
|
+
failure: null,
|
|
372
|
+
});
|
|
243
373
|
} catch (error) {
|
|
244
374
|
ended = true;
|
|
245
375
|
state.close();
|
package/src/client/billing/renewalAttach/internal/observation/invoiceActor.integration.test.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import { anyApi } from "convex/server";
|
|
3
|
+
import {
|
|
4
|
+
configureAdmissionCase,
|
|
5
|
+
admissionControls,
|
|
6
|
+
} from "../test-fixtures/producerConfigureAdmission.js";
|
|
7
|
+
import {
|
|
8
|
+
observerIdentity,
|
|
9
|
+
authorizeObservation,
|
|
10
|
+
} from "../test-fixtures/observationReader.js";
|
|
11
|
+
import {
|
|
12
|
+
prepareInvoiceObservation,
|
|
13
|
+
authorizeInvoices,
|
|
14
|
+
invoiceControls,
|
|
15
|
+
} from "../test-fixtures/invoiceObservation.js";
|
|
16
|
+
|
|
17
|
+
import * as actors from "./freshActor.js";
|
|
18
|
+
|
|
19
|
+
const options = {
|
|
20
|
+
identity: observerIdentity,
|
|
21
|
+
hostQuery: authorizeObservation,
|
|
22
|
+
hostInvoiceQuery: authorizeInvoices,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
it("EMPTY invoice profile refuses before input reflection", async () => {
|
|
26
|
+
admissionControls.invoices.splice(0);
|
|
27
|
+
const capture = Reflect.get(actors, "captureFreshInvoiceRenewalObservation");
|
|
28
|
+
expect(capture).toBeTypeOf("function");
|
|
29
|
+
let traps = 0;
|
|
30
|
+
const poison = new Proxy(
|
|
31
|
+
{},
|
|
32
|
+
{
|
|
33
|
+
get() {
|
|
34
|
+
traps++;
|
|
35
|
+
throw Error("TRAP");
|
|
36
|
+
},
|
|
37
|
+
getPrototypeOf() {
|
|
38
|
+
traps++;
|
|
39
|
+
throw Error("TRAP");
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
await expect(capture(poison, poison)).rejects.toThrow(
|
|
44
|
+
"INVOICE_OBSERVATION_UNBOUND",
|
|
45
|
+
);
|
|
46
|
+
expect(traps).toBe(0);
|
|
47
|
+
});
|
|
48
|
+
configureAdmissionCase(
|
|
49
|
+
"fresh invoice acquisition correlates pinned periods and successor without C9",
|
|
50
|
+
prepareInvoiceObservation,
|
|
51
|
+
async (h, state) => {
|
|
52
|
+
const capture = Reflect.get(
|
|
53
|
+
actors,
|
|
54
|
+
"captureFreshInvoiceRenewalObservation",
|
|
55
|
+
);
|
|
56
|
+
expect(capture).toBeTypeOf("function");
|
|
57
|
+
const before = h.calls.length;
|
|
58
|
+
await h.inAnotherAction(async (ctx) => {
|
|
59
|
+
const actor = await capture(h.sdk, {
|
|
60
|
+
actualActionCtx: ctx,
|
|
61
|
+
operationId: state.operationId,
|
|
62
|
+
parentOperationId: state.parentOperationId,
|
|
63
|
+
});
|
|
64
|
+
const result = await actor.invoke();
|
|
65
|
+
expect(result.invoiceInventory).toBe("complete");
|
|
66
|
+
expect(result.invoiceContext?.original.invoice).toEqual(
|
|
67
|
+
state.inventories[0].invoice,
|
|
68
|
+
);
|
|
69
|
+
expect(result.evidence?.invoiceEvidence.predicate).toBe(
|
|
70
|
+
"invoice_lines_correlated",
|
|
71
|
+
);
|
|
72
|
+
expect(result.evidence?.currentMaterial.predicate).toBe(
|
|
73
|
+
"current_target_material_match",
|
|
74
|
+
);
|
|
75
|
+
expect(result.evidence?.invoiceEvidence.current?.subscriptionItemId).toBe(
|
|
76
|
+
"si_successor",
|
|
77
|
+
);
|
|
78
|
+
expect(result.evidence?.operationalAuthority).toBe(false);
|
|
79
|
+
expect(result.history.configureReceipt).toBeNull();
|
|
80
|
+
await expect(actor.invoke()).rejects.toThrow();
|
|
81
|
+
});
|
|
82
|
+
expect(h.calls.slice(before).map((c) => c.method)).toEqual(
|
|
83
|
+
Array(11).fill("GET"),
|
|
84
|
+
);
|
|
85
|
+
expect(invoiceControls.count).toBe(6);
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
identity: observerIdentity,
|
|
89
|
+
hostQuery: authorizeObservation,
|
|
90
|
+
hostInvoiceQuery: authorizeInvoices,
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
configureAdmissionCase(
|
|
95
|
+
"foreign customer in an expanded pinned pointer refuses before invoice I/O",
|
|
96
|
+
prepareInvoiceObservation,
|
|
97
|
+
async (h, state) => {
|
|
98
|
+
state.reads.subscription.latest_invoice = {
|
|
99
|
+
id: "in_current",
|
|
100
|
+
object: "invoice",
|
|
101
|
+
customer: "cus_foreign",
|
|
102
|
+
};
|
|
103
|
+
const before = h.calls.length;
|
|
104
|
+
await h.inAnotherAction(async (ctx) => {
|
|
105
|
+
const actor = await actors.captureFreshInvoiceRenewalObservation(h.sdk, {
|
|
106
|
+
actualActionCtx: ctx,
|
|
107
|
+
operationId: state.operationId,
|
|
108
|
+
parentOperationId: state.parentOperationId,
|
|
109
|
+
});
|
|
110
|
+
const result = await actor.invoke();
|
|
111
|
+
expect(result.invoiceInventory).toBe("conflict");
|
|
112
|
+
expect(result.invoiceContext).toBeNull();
|
|
113
|
+
});
|
|
114
|
+
expect(h.calls.slice(before)).toHaveLength(6);
|
|
115
|
+
expect(invoiceControls.count).toBe(0);
|
|
116
|
+
},
|
|
117
|
+
options,
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
configureAdmissionCase(
|
|
121
|
+
"the maintained generated API proxy is a usable fixed invoice authorization reference",
|
|
122
|
+
prepareInvoiceObservation,
|
|
123
|
+
async (h, state) => {
|
|
124
|
+
admissionControls.invoices.splice(
|
|
125
|
+
0,
|
|
126
|
+
1,
|
|
127
|
+
Object.freeze({
|
|
128
|
+
...state.invoiceProfile,
|
|
129
|
+
authorizationQuery: anyApi.initialOwner.authorizeInvoices,
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
132
|
+
await h.inAnotherAction(async (ctx) => {
|
|
133
|
+
const actor = await actors.captureFreshInvoiceRenewalObservation(h.sdk, {
|
|
134
|
+
actualActionCtx: ctx,
|
|
135
|
+
operationId: state.operationId,
|
|
136
|
+
parentOperationId: state.parentOperationId,
|
|
137
|
+
});
|
|
138
|
+
expect((await actor.invoke()).invoiceInventory).toBe("complete");
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
options,
|
|
142
|
+
);
|