@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
package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts
CHANGED
|
@@ -32,6 +32,7 @@ const controls = vi.hoisted(() => ({
|
|
|
32
32
|
selectors: 0,
|
|
33
33
|
history: [] as unknown[],
|
|
34
34
|
observation: [] as unknown[],
|
|
35
|
+
invoices: [] as unknown[],
|
|
35
36
|
onSelect: null as null | ((client: object) => void),
|
|
36
37
|
}));
|
|
37
38
|
vi.mock("../operations/sourceOperations.js", () => {
|
|
@@ -46,6 +47,7 @@ vi.mock("../operations/sourceOperations.js", () => {
|
|
|
46
47
|
COMPILED_CONFIGURE_WRITE_ENTRIES: controls.write,
|
|
47
48
|
COMPILED_OBSERVATION_HISTORY_ENTRIES: controls.history,
|
|
48
49
|
COMPILED_FRESH_OBSERVATION_ENTRIES: controls.observation,
|
|
50
|
+
COMPILED_INVOICE_OBSERVATION_ENTRIES: controls.invoices,
|
|
49
51
|
loadConfigureWriteTransportSource: poison,
|
|
50
52
|
loadConfigureReplayTransportSource: poison,
|
|
51
53
|
loadFixedConfigureWriteOperation: poison,
|
|
@@ -112,6 +114,7 @@ beforeEach(() => {
|
|
|
112
114
|
controls.selectors = 0;
|
|
113
115
|
controls.history.splice(0);
|
|
114
116
|
controls.observation.splice(0);
|
|
117
|
+
controls.invoices.splice(0);
|
|
115
118
|
controls.onSelect = null;
|
|
116
119
|
controls.entries.splice(0, controls.entries.length, {
|
|
117
120
|
coversRetained: () => true,
|
|
@@ -181,7 +184,10 @@ async function setup(
|
|
|
181
184
|
if (completion.mode === "replay" && completion.posts === 1)
|
|
182
185
|
throw Error("CONTROLLED_LOST_RESPONSE");
|
|
183
186
|
}
|
|
184
|
-
const body =
|
|
187
|
+
const body =
|
|
188
|
+
method === "POST"
|
|
189
|
+
? baseline.schedule
|
|
190
|
+
: (routes.get(path + parsed.search) ?? routes.get(path));
|
|
185
191
|
assert(body);
|
|
186
192
|
assert(
|
|
187
193
|
method === "GET" ||
|
|
@@ -404,6 +410,9 @@ export async function configureAdmissionFixture(
|
|
|
404
410
|
hostQuery?: NonNullable<
|
|
405
411
|
Parameters<typeof initialOperations>[2]
|
|
406
412
|
>["hostQuery"];
|
|
413
|
+
hostInvoiceQuery?: NonNullable<
|
|
414
|
+
Parameters<typeof initialOperations>[2]
|
|
415
|
+
>["hostQuery"];
|
|
407
416
|
count?: number;
|
|
408
417
|
keys?: readonly string[];
|
|
409
418
|
afterBind?: (reply: unknown) => Promise<void>;
|
|
@@ -434,6 +443,7 @@ export async function configureAdmissionFixture(
|
|
|
434
443
|
keys: options.keys,
|
|
435
444
|
identity: options.identity,
|
|
436
445
|
hostQuery: options.hostQuery,
|
|
446
|
+
hostInvoiceQuery: options.hostInvoiceQuery,
|
|
437
447
|
source: captureRetainedInput(baseline.original),
|
|
438
448
|
afterBind: options.afterBind,
|
|
439
449
|
afterQuery: options.afterQuery,
|
|
@@ -41,6 +41,7 @@ export async function initialOperations(
|
|
|
41
41
|
options: {
|
|
42
42
|
identity?: { subject: string; issuer: string; tokenIdentifier: string };
|
|
43
43
|
hostQuery?: ReturnType<typeof queryGeneric>;
|
|
44
|
+
hostInvoiceQuery?: ReturnType<typeof queryGeneric>;
|
|
44
45
|
epochMs?: number;
|
|
45
46
|
workEndWallMs?: number;
|
|
46
47
|
endWallMs?: number;
|
|
@@ -180,6 +181,9 @@ export async function initialOperations(
|
|
|
180
181
|
let secondaryId = 0;
|
|
181
182
|
const host = {
|
|
182
183
|
...(options.hostQuery ? { authorize: options.hostQuery } : {}),
|
|
184
|
+
...(options.hostInvoiceQuery
|
|
185
|
+
? { authorizeInvoices: options.hostInvoiceQuery }
|
|
186
|
+
: {}),
|
|
183
187
|
secondary: actionGeneric({
|
|
184
188
|
args: { id: v.string() },
|
|
185
189
|
handler: async (ctx, args): Promise<null> => {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import { inspectRenewalEvidenceV1 } from "./evidence-v1.js";
|
|
3
|
+
import { object } from "./common.js";
|
|
4
|
+
import {
|
|
5
|
+
invoiceRecipe,
|
|
6
|
+
prerequisites,
|
|
7
|
+
bounded,
|
|
8
|
+
set,
|
|
9
|
+
} from "../../../../tests/renewalObservation/evidenceFixtures.js";
|
|
10
|
+
|
|
11
|
+
it.each(["string", "minimal-expanded", "full-expanded"] as const)(
|
|
12
|
+
"one invoice ID cannot prove two renewal invoices with %s pointers",
|
|
13
|
+
async (pointer) => {
|
|
14
|
+
const f = invoiceRecipe("subscription_cycle", "open");
|
|
15
|
+
await prerequisites(f.h);
|
|
16
|
+
const positive = await inspectRenewalEvidenceV1(f.h.input);
|
|
17
|
+
expect(positive.invoiceEvidence.predicate).toBe("invoice_lines_correlated");
|
|
18
|
+
|
|
19
|
+
// Keep two otherwise valid period/item inventories. Every current relation
|
|
20
|
+
// now names I0, so a foreign-ID refusal cannot mask the missing invariant.
|
|
21
|
+
const id = f.originalInvoice.id;
|
|
22
|
+
set(f.currentInvoice, "id", id);
|
|
23
|
+
set(f.currentLine, "invoice", id);
|
|
24
|
+
set(f.currentPages[0], "url", `/v1/invoices/${id}/lines`);
|
|
25
|
+
set(
|
|
26
|
+
object(f.h.input.reads.subscription),
|
|
27
|
+
"latest_invoice",
|
|
28
|
+
pointer === "string"
|
|
29
|
+
? id
|
|
30
|
+
: pointer === "minimal-expanded"
|
|
31
|
+
? { id, object: "invoice" }
|
|
32
|
+
: structuredClone(f.currentInvoice),
|
|
33
|
+
);
|
|
34
|
+
const before = bounded(f.h.input);
|
|
35
|
+
const result = await inspectRenewalEvidenceV1(f.h.input);
|
|
36
|
+
expect(result.invoiceEvidence).toEqual({
|
|
37
|
+
predicate: "conflict",
|
|
38
|
+
original: null,
|
|
39
|
+
current: null,
|
|
40
|
+
reason: "invoice_relation_mismatch",
|
|
41
|
+
});
|
|
42
|
+
expect(result.operationalAuthority).toBe(false);
|
|
43
|
+
expect(result.authenticationEstablished).toBe(false);
|
|
44
|
+
expect(result.acknowledgementEstablished).toBe(false);
|
|
45
|
+
expect(Reflect.ownKeys(result)).toHaveLength(12);
|
|
46
|
+
expect(f.h.input).toEqual(before);
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
it("distinct invoices cannot reuse one line ID for incompatible period inventories", async () => {
|
|
51
|
+
const f = invoiceRecipe("subscription_cycle", "open");
|
|
52
|
+
await prerequisites(f.h);
|
|
53
|
+
set(f.currentLine, "id", f.originalLine.id);
|
|
54
|
+
const result = await inspectRenewalEvidenceV1(f.h.input);
|
|
55
|
+
expect(result.invoiceEvidence).toEqual({
|
|
56
|
+
predicate: "conflict",
|
|
57
|
+
original: null,
|
|
58
|
+
current: null,
|
|
59
|
+
reason: "invoice_relation_mismatch",
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -184,6 +184,7 @@ export async function inspectInvoiceEvidenceV1(
|
|
|
184
184
|
};
|
|
185
185
|
const originalInvoiceId = invoiceId(originalSub.latest_invoice),
|
|
186
186
|
currentInvoiceId = invoiceId(sub.latest_invoice);
|
|
187
|
+
relation(originalInvoiceId !== currentInvoiceId);
|
|
187
188
|
const examine = (role: "original" | "current") => {
|
|
188
189
|
const row = closed(inventory[role], ["invoice", "linePages"]);
|
|
189
190
|
const invoice = invoiceRecordV1(row.invoice);
|
|
@@ -250,6 +251,14 @@ export async function inspectInvoiceEvidenceV1(
|
|
|
250
251
|
};
|
|
251
252
|
const original = examine("original"),
|
|
252
253
|
current = examine("current");
|
|
254
|
+
const lineIds = (role: "original" | "current") =>
|
|
255
|
+
array(invoiceRecordV1(inventory[role]).linePages).flatMap((page) =>
|
|
256
|
+
array(invoiceRecordV1(page).data).map(
|
|
257
|
+
(line) => invoiceRecordV1(line).id,
|
|
258
|
+
),
|
|
259
|
+
);
|
|
260
|
+
const originalIds = new Set(lineIds("original"));
|
|
261
|
+
relation(lineIds("current").every((id) => !originalIds.has(id)));
|
|
253
262
|
return {
|
|
254
263
|
predicate: "invoice_lines_correlated",
|
|
255
264
|
original,
|