@fantastic.dev/better-stripe 0.108.0 → 0.109.1

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts +31 -0
  4. package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts.map +1 -0
  5. package/dist/client/billing/renewalAttach/internal/observation/freshActor.js +112 -0
  6. package/dist/client/billing/renewalAttach/internal/observation/freshActor.js.map +1 -0
  7. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts +17 -0
  8. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts.map +1 -0
  9. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js +191 -0
  10. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js.map +1 -0
  11. package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts +29 -0
  12. package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts.map +1 -0
  13. package/dist/client/billing/renewalAttach/internal/observation/invocation.js +205 -0
  14. package/dist/client/billing/renewalAttach/internal/observation/invocation.js.map +1 -0
  15. package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts +1 -0
  16. package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/observation/profile.js +5 -1
  18. package/dist/client/billing/renewalAttach/internal/observation/profile.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/observation/reader.d.ts +4 -58
  20. package/dist/client/billing/renewalAttach/internal/observation/reader.d.ts.map +1 -1
  21. package/dist/client/billing/renewalAttach/internal/observation/reader.js +12 -152
  22. package/dist/client/billing/renewalAttach/internal/observation/reader.js.map +1 -1
  23. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts +7 -0
  24. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts.map +1 -1
  25. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js +1 -0
  26. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js.map +1 -1
  27. package/dist/client/billing/renewalObservation/evidence-invoice.d.ts.map +1 -1
  28. package/dist/client/billing/renewalObservation/evidence-invoice.js +1 -0
  29. package/dist/client/billing/renewalObservation/evidence-invoice.js.map +1 -1
  30. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  31. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  32. package/dist/component/balanceFunding/mutations.d.ts +27 -27
  33. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  34. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  35. package/dist/component/earnings/triggers.d.ts +16 -16
  36. package/dist/component/payoutRelease/queries.d.ts +2 -2
  37. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  38. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  39. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  40. package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
  41. package/docs/renewal-context-reads.md +55 -0
  42. package/docs/renewal-material-observation.md +4 -1
  43. package/package.json +1 -1
  44. package/src/client/billing/renewalAttach/internal/observation/freshActor.integration.test.ts +360 -0
  45. package/src/client/billing/renewalAttach/internal/observation/freshActor.ts +175 -0
  46. package/src/client/billing/renewalAttach/internal/observation/freshActorControls.integration.test.ts +442 -0
  47. package/src/client/billing/renewalAttach/internal/observation/freshTransport.ts +252 -0
  48. package/src/client/billing/renewalAttach/internal/observation/invocation.ts +299 -0
  49. package/src/client/billing/renewalAttach/internal/observation/profile.ts +9 -1
  50. package/src/client/billing/renewalAttach/internal/observation/reader.ts +15 -221
  51. package/src/client/billing/renewalAttach/internal/operations/sourceOperations.ts +8 -0
  52. package/src/client/billing/renewalAttach/internal/test-fixtures/freshObservation.ts +94 -0
  53. package/src/client/billing/renewalAttach/internal/test-fixtures/historySnapshot.ts +5 -1
  54. package/src/client/billing/renewalAttach/internal/test-fixtures/observationReader.ts +2 -1
  55. package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +32 -4
  56. package/src/client/billing/renewalObservation/evidence-invoice-identity.test.ts +48 -0
  57. package/src/client/billing/renewalObservation/evidence-invoice.ts +1 -0
@@ -0,0 +1,360 @@
1
+ import { expect, it, vi } from "vitest";
2
+ import {
3
+ configureAdmissionCase,
4
+ admissionControls,
5
+ } from "../test-fixtures/producerConfigureAdmission.js";
6
+ import { prepareFreshObservation } from "../test-fixtures/freshObservation.js";
7
+ import {
8
+ observerIdentity,
9
+ authorizeObservation,
10
+ readerControls,
11
+ } from "../test-fixtures/observationReader.js";
12
+ import { captureFreshRenewalObservation } from "./freshActor.js";
13
+ import { inspectRenewalScheduleMaterialV2 } from "../../../renewalV2/observation.js";
14
+ import {
15
+ captureObservationInvocation,
16
+ readObservationInvocation,
17
+ } from "./invocation.js";
18
+ import { captureFreshGetTransport } from "./freshTransport.js";
19
+ import { baseReadRows } from "./profile.js";
20
+
21
+ for (const active of [false, true])
22
+ configureAdmissionCase(
23
+ active
24
+ ? "fresh reads correlate a successor after original periodEnd without C9"
25
+ : "fresh reads establish pending without C9 after original write retirement",
26
+ (h) => prepareFreshObservation(h, { active }),
27
+ async (h, state) => {
28
+ const before = h.calls.length,
29
+ selectors = admissionControls.selectors;
30
+ await h.inAnotherAction(async (ctx) => {
31
+ const mutations = vi.spyOn(ctx, "runMutation");
32
+ const actor = await captureFreshRenewalObservation(h.sdk, {
33
+ actualActionCtx: ctx,
34
+ operationId: state.operationId,
35
+ parentOperationId: state.parentOperationId,
36
+ });
37
+ const output = await actor.invoke();
38
+ expect(output.status).toBe("fresh_observation_data");
39
+ expect(output.history.configureReceipt).toBeNull();
40
+ const detail = await inspectRenewalScheduleMaterialV2({
41
+ configuration: output.history.record.configuration,
42
+ reads: output.reads!,
43
+ });
44
+ expect(
45
+ output.evidence?.currentMaterial.predicate,
46
+ JSON.stringify(detail),
47
+ ).toBe(
48
+ active ? "current_target_material_match" : "pending_material_match",
49
+ );
50
+ expect(output.evidence?.currentMaterial.observedItemId).toBe(
51
+ active ? "si_successor" : null,
52
+ );
53
+ expect(output.evidence?.invoiceEvidence.reason).toBe("not_supplied");
54
+ expect(output.evidence?.historicalMaterial.reason).toBe("not_supplied");
55
+ expect(output.operationalAuthority).toBe(false);
56
+ expect(mutations).not.toHaveBeenCalled();
57
+ await expect(actor.invoke()).rejects.toThrow();
58
+ });
59
+ const calls = h.calls.slice(before);
60
+ expect(calls.map((c) => c.method)).toEqual(Array(6).fill("GET"));
61
+ expect(calls.map((c) => c.path)).toEqual([
62
+ "/v1/subscription_schedules/sub_sched_owned",
63
+ "/v1/subscriptions/sub_original",
64
+ "/v1/prices/price_target",
65
+ "/v1/customers/cus_buyer",
66
+ "/v1/coupons/custom-subscription-offer",
67
+ "/v1/coupons/custom-item-offer",
68
+ ]);
69
+ expect(
70
+ calls.every(
71
+ (c) =>
72
+ !c.hasBody &&
73
+ c.idempotencyKey === null &&
74
+ c.apiVersion === "2026-09-30.endive",
75
+ ),
76
+ ).toBe(true);
77
+ expect(admissionControls.selectors).toBe(selectors + 1);
78
+ expect(readerControls.authorizations).toBe(8);
79
+ expect(admissionControls.legacy).toBe(0);
80
+ },
81
+ {
82
+ identity: observerIdentity,
83
+ hostQuery: authorizeObservation,
84
+ ...(active ? {} : { targetInterval: "week" as const }),
85
+ },
86
+ );
87
+ for (const mode of ["absent", "monthly-retained", "weekly-retained"] as const)
88
+ configureAdmissionCase(
89
+ "retained duration evidence: " + mode,
90
+ (h) => prepareFreshObservation(h, { retained: mode !== "absent" }),
91
+ async (h, state) => {
92
+ await h.inAnotherAction(async (ctx) => {
93
+ const actor = await captureFreshRenewalObservation(h.sdk, {
94
+ actualActionCtx: ctx,
95
+ operationId: state.operationId,
96
+ parentOperationId: state.parentOperationId,
97
+ });
98
+ const result = await actor.invoke();
99
+ expect(result.status).toBe("fresh_observation_data");
100
+ expect(result.history.configureReceipt === null).toBe(
101
+ mode === "absent",
102
+ );
103
+ expect(result.evidence?.currentMaterial.predicate).toBe(
104
+ mode === "weekly-retained" ? "pending_material_match" : "unknown",
105
+ );
106
+ expect(result.evidence?.acknowledgementEstablished).toBe(false);
107
+ });
108
+ },
109
+ {
110
+ identity: observerIdentity,
111
+ hostQuery: authorizeObservation,
112
+ ...(mode === "weekly-retained"
113
+ ? { targetInterval: "week" as const }
114
+ : {}),
115
+ },
116
+ );
117
+ it("EMPTY fresh observer profile refuses before root, input, clocks or selector", async () => {
118
+ admissionControls.observation.splice(0);
119
+ let traps = 0;
120
+ const root = new Proxy(
121
+ {},
122
+ {
123
+ getPrototypeOf() {
124
+ traps++;
125
+ throw Error("TRAP");
126
+ },
127
+ },
128
+ );
129
+ const input = new Proxy(
130
+ {},
131
+ {
132
+ ownKeys() {
133
+ traps++;
134
+ throw Error("TRAP");
135
+ },
136
+ },
137
+ );
138
+ const wall = vi.spyOn(Date, "now"),
139
+ ns = vi.spyOn(process.hrtime, "bigint");
140
+ await expect(captureFreshRenewalObservation(root, input)).rejects.toThrow(
141
+ "FRESH_OBSERVATION_UNBOUND",
142
+ );
143
+ expect(traps).toBe(0);
144
+ expect(wall).not.toHaveBeenCalled();
145
+ expect(ns).not.toHaveBeenCalled();
146
+ });
147
+ configureAdmissionCase(
148
+ "one actor consumes once while distinct fresh invocations remain independent",
149
+ (h) => prepareFreshObservation(h, { active: true }),
150
+ async (h, state) => {
151
+ const before = h.calls.length;
152
+ await h.inAnotherAction(async (ctx) => {
153
+ const input = {
154
+ actualActionCtx: ctx,
155
+ operationId: state.operationId,
156
+ parentOperationId: state.parentOperationId,
157
+ };
158
+ const first = await captureFreshRenewalObservation(h.sdk, input);
159
+ const second = await captureFreshRenewalObservation(h.sdk, input);
160
+ const pending = first.invoke();
161
+ await expect(first.invoke()).rejects.toThrow();
162
+ const [one, two] = await Promise.all([pending, second.invoke()]);
163
+ expect(one.evidence?.currentMaterial.predicate).toBe(
164
+ "current_target_material_match",
165
+ );
166
+ expect(two.evidence?.currentMaterial.predicate).toBe(
167
+ "current_target_material_match",
168
+ );
169
+ expect(one).not.toBe(two);
170
+ expect(one.history).not.toBe(two.history);
171
+ });
172
+ expect(h.calls.slice(before)).toHaveLength(12);
173
+ },
174
+ { identity: observerIdentity, hostQuery: authorizeObservation },
175
+ );
176
+ configureAdmissionCase(
177
+ "the selected read port refuses POST, body, retry, API, path and ordinal substitutions",
178
+ prepareFreshObservation,
179
+ async (h, state) => {
180
+ const before = h.calls.length;
181
+ const changes = [
182
+ { method: "POST" },
183
+ { body: {} },
184
+ { path: "/v1/subscriptions/sub_foreign" },
185
+ { ordinal: 2 },
186
+ { options: { apiVersion: "2026-09-30.endive", maxNetworkRetries: 1 } },
187
+ { options: { apiVersion: "2025-01-01", maxNetworkRetries: 0 } },
188
+ {
189
+ options: {
190
+ apiVersion: "2026-09-30.endive",
191
+ maxNetworkRetries: 0,
192
+ idempotencyKey: "unexpected",
193
+ },
194
+ },
195
+ ];
196
+ for (const change of changes)
197
+ await h.inAnotherAction(async (ctx) => {
198
+ const token = await captureObservationInvocation(h.sdk, {
199
+ actualActionCtx: ctx,
200
+ operationId: state.operationId,
201
+ parentOperationId: state.parentOperationId,
202
+ });
203
+ const cell = readObservationInvocation(token);
204
+ try {
205
+ const captured = await cell.captureHistory();
206
+ const port = captureFreshGetTransport(token, state.profile);
207
+ const row = {
208
+ ...baseReadRows(captured.history.record)[0],
209
+ ...change,
210
+ };
211
+ await expect(Reflect.apply(port.read, port, [row])).rejects.toThrow();
212
+ } finally {
213
+ cell.close();
214
+ }
215
+ });
216
+ expect(h.calls).toHaveLength(before);
217
+ },
218
+ { identity: observerIdentity, hostQuery: authorizeObservation },
219
+ );
220
+ let hold = false,
221
+ releaseHeld = () => {},
222
+ notifyHeld = () => {};
223
+ let held = Promise.resolve();
224
+ configureAdmissionCase(
225
+ "one original timeout closes a hanging GET and late fulfillment cannot authorize release",
226
+ async (h) => {
227
+ hold = false;
228
+ return prepareFreshObservation(h);
229
+ },
230
+ async (h, state) => {
231
+ const before = h.calls.length;
232
+ held = new Promise<void>((resolve) => {
233
+ releaseHeld = resolve;
234
+ });
235
+ const started = new Promise<void>((resolve) => {
236
+ notifyHeld = resolve;
237
+ });
238
+ hold = true;
239
+ await h.inAnotherAction(async (ctx) => {
240
+ const actor = await captureFreshRenewalObservation(h.sdk, {
241
+ actualActionCtx: ctx,
242
+ operationId: state.operationId,
243
+ parentOperationId: state.parentOperationId,
244
+ });
245
+ const pending = actor.invoke();
246
+ const rejected = expect(pending).rejects.toThrow(
247
+ "OBSERVATION_HISTORY_READER_EXPIRED",
248
+ );
249
+ await started;
250
+ await vi.advanceTimersByTimeAsync(30000);
251
+ await rejected;
252
+ hold = false;
253
+ releaseHeld();
254
+ await vi.advanceTimersByTimeAsync(0);
255
+ await expect(actor.invoke()).rejects.toThrow();
256
+ });
257
+ expect(h.calls.slice(before)).toHaveLength(1);
258
+ expect(readerControls.authorizations).toBe(2);
259
+ },
260
+ {
261
+ identity: observerIdentity,
262
+ hostQuery: authorizeObservation,
263
+ beforeFetch: async (_path, method) => {
264
+ if (hold && method === "GET") {
265
+ notifyHeld();
266
+ await held;
267
+ }
268
+ },
269
+ },
270
+ );
271
+ configureAdmissionCase(
272
+ "exact forty-coupon inventory permits forty-four GETs with zero retries",
273
+ prepareFreshObservation,
274
+ async (h, state) => {
275
+ const before = h.calls.length,
276
+ sub = state.reads.subscription,
277
+ item = sub.items.data[0];
278
+ for (const [owner, level] of [
279
+ [sub, "sub"],
280
+ [item, "item"],
281
+ ] as const) {
282
+ const original = owner.discounts[0];
283
+ owner.discounts = Array.from({ length: 19 }, (_, index) => {
284
+ const discount = structuredClone(original);
285
+ discount.id = "di_" + level + index;
286
+ discount.source.coupon.id = "max-" + level + index;
287
+ h.setControlledRead(
288
+ "/v1/coupons/" + discount.source.coupon.id,
289
+ discount.source.coupon,
290
+ );
291
+ return discount;
292
+ });
293
+ }
294
+ await h.inAnotherAction(async (ctx) => {
295
+ const actor = await captureFreshRenewalObservation(h.sdk, {
296
+ actualActionCtx: ctx,
297
+ operationId: state.operationId,
298
+ parentOperationId: state.parentOperationId,
299
+ });
300
+ const result = await actor.invoke();
301
+ expect(result.status).toBe("fresh_observation_data");
302
+ expect(result.couponInventory).toBe("complete");
303
+ expect(result.reads?.coupons).toHaveLength(40);
304
+ });
305
+ expect(h.calls.slice(before)).toHaveLength(44);
306
+ expect(h.calls.slice(before).every((call) => call.method === "GET")).toBe(
307
+ true,
308
+ );
309
+ expect(readerControls.authorizations).toBe(46);
310
+ },
311
+ { identity: observerIdentity, hostQuery: authorizeObservation },
312
+ );
313
+ configureAdmissionCase(
314
+ "a foreign base resource returns conflict after four reads without adopting its DATA",
315
+ prepareFreshObservation,
316
+ async (h, state) => {
317
+ const before = h.calls.length;
318
+ state.reads.targetPrice.id = "price_foreign";
319
+ await h.inAnotherAction(async (ctx) => {
320
+ const actor = await captureFreshRenewalObservation(h.sdk, {
321
+ actualActionCtx: ctx,
322
+ operationId: state.operationId,
323
+ parentOperationId: state.parentOperationId,
324
+ });
325
+ const result = await actor.invoke();
326
+ expect(result.status).toBe("observation_conflict");
327
+ expect(result.reason).toBe("PROVIDER_IDENTITY_CONFLICT");
328
+ expect(result.reads).toBeNull();
329
+ expect(result.failure).toBeNull();
330
+ expect(result.history.attachmentReceipt.scheduleId).toBe(
331
+ "sub_sched_owned",
332
+ );
333
+ });
334
+ expect(h.calls.slice(before)).toHaveLength(4);
335
+ expect(readerControls.authorizations).toBe(6);
336
+ },
337
+ { identity: observerIdentity, hostQuery: authorizeObservation },
338
+ );
339
+ configureAdmissionCase(
340
+ "a provider-looking failure thrown by authorization never becomes provider rejection",
341
+ prepareFreshObservation,
342
+ async (h, state) => {
343
+ const before = h.calls.length;
344
+ readerControls.reply = () => {
345
+ throw Object.assign(Error("CONTROLLED_AUTH_FAILURE"), {
346
+ failure: { category: "provider_rejected", outcome: "unknown" },
347
+ });
348
+ };
349
+ await h.inAnotherAction(async (ctx) => {
350
+ const actor = await captureFreshRenewalObservation(h.sdk, {
351
+ actualActionCtx: ctx,
352
+ operationId: state.operationId,
353
+ parentOperationId: state.parentOperationId,
354
+ });
355
+ await expect(actor.invoke()).rejects.toThrow("CONTROLLED_AUTH_FAILURE");
356
+ });
357
+ expect(h.calls).toHaveLength(before);
358
+ },
359
+ { identity: observerIdentity, hostQuery: authorizeObservation },
360
+ );
@@ -0,0 +1,175 @@
1
+ import {
2
+ captureObservationInvocation,
3
+ readObservationInvocation,
4
+ closeObservationInvocation,
5
+ type ObservationInvocationState,
6
+ } from "./invocation.js";
7
+ import {
8
+ captureFreshObservationProfile,
9
+ captureFreshGetTransport,
10
+ freshNeed as need,
11
+ } from "./freshTransport.js";
12
+ import {
13
+ baseReadRows,
14
+ validateObservationIdentityRouting,
15
+ validateBaseRouting,
16
+ observationCouponIds,
17
+ couponReadRow,
18
+ validateCoupon,
19
+ } from "./profile.js";
20
+ import { inspectRenewalEvidenceV1 } from "../../../renewalObservation/evidence-v1.js";
21
+ import { captureReaderQueryDATA } from "./readerAuthorization.js";
22
+ import type { RenewalEvidenceResultV1 } from "../../../renewalObservation/evidence-v1-types.js";
23
+ import type { ObservationReads, ReadFailure } from "./types.js";
24
+
25
+ /** Fresh authorized bounded current evidence. No caller DATA can create an invocation. */
26
+ export async function captureFreshRenewalObservation(
27
+ root: object,
28
+ raw: unknown,
29
+ ) {
30
+ need(arguments.length === 2);
31
+ const profile = captureFreshObservationProfile(root);
32
+ const token = await captureObservationInvocation(root, raw);
33
+ let state: ObservationInvocationState;
34
+ try {
35
+ state = readObservationInvocation(token);
36
+ need(state.historyEntry === profile.historyEntry);
37
+ } catch (error) {
38
+ closeObservationInvocation(token);
39
+ throw error;
40
+ }
41
+ let used = false;
42
+ return Object.freeze({
43
+ async invoke() {
44
+ need(arguments.length === 0 && !used);
45
+ used = true;
46
+ try {
47
+ const captured = await state.captureHistory();
48
+ const transport = captureFreshGetTransport(token, profile);
49
+ async function release(
50
+ status:
51
+ | "fresh_observation_data"
52
+ | "unsupported_observation_profile"
53
+ | "observation_provider_rejected"
54
+ | "observation_conflict",
55
+ reads: ObservationReads | null,
56
+ evidence: RenewalEvidenceResultV1 | null,
57
+ couponInventory: "complete" | "incomplete" | "not_acquired",
58
+ reason: string | null,
59
+ failure: ReadFailure | null = null,
60
+ ) {
61
+ await state.authorizeUnchanged();
62
+ transport.guard();
63
+ const output = captureReaderQueryDATA({
64
+ status,
65
+ ...captured,
66
+ reads,
67
+ evidence,
68
+ couponInventory,
69
+ observedAt: Math.floor(state.check().wallMs / 1000),
70
+ analysis:
71
+ evidence === null
72
+ ? ("analysis_not_admitted" as const)
73
+ : ("admitted" as const),
74
+ reason,
75
+ failure,
76
+ operationalAuthority: false as const,
77
+ });
78
+ transport.guard();
79
+ return output;
80
+ }
81
+ const base: unknown[] = [];
82
+ for (const row of baseReadRows(captured.history.record)) {
83
+ const result = await transport.read(row);
84
+ if (result.kind === "provider_rejected")
85
+ return await release(
86
+ "observation_provider_rejected",
87
+ null,
88
+ null,
89
+ "not_acquired",
90
+ null,
91
+ result.failure,
92
+ );
93
+ base.push(result.body);
94
+ }
95
+ const reads: ObservationReads = {
96
+ schedule: base[0],
97
+ subscription: base[1],
98
+ targetPrice: base[2],
99
+ billingCustomer: base[3],
100
+ coupons: [],
101
+ };
102
+ try {
103
+ validateObservationIdentityRouting(captured.history.record, reads);
104
+ } catch {
105
+ return await release(
106
+ "observation_conflict",
107
+ null,
108
+ null,
109
+ "incomplete",
110
+ "PROVIDER_IDENTITY_CONFLICT",
111
+ );
112
+ }
113
+ async function analyze() {
114
+ return state.owned(async () => {
115
+ try {
116
+ return await inspectRenewalEvidenceV1({
117
+ version: 1,
118
+ apiVersion: "2026-09-30.endive",
119
+ configuration: captured.history.record.configuration,
120
+ configureReceipt: captured.history.rawConfigureReceipt,
121
+ reads,
122
+ invoiceContext: null,
123
+ historicalSnapshot: null,
124
+ });
125
+ } catch {
126
+ return null;
127
+ }
128
+ }, transport.guard);
129
+ }
130
+ let ids: readonly string[];
131
+ try {
132
+ validateBaseRouting(captured.history.record, reads);
133
+ ids = observationCouponIds(
134
+ captured.history.record,
135
+ reads.subscription,
136
+ );
137
+ } catch {
138
+ const analysis = await analyze();
139
+ return await release(
140
+ "unsupported_observation_profile",
141
+ reads,
142
+ analysis,
143
+ "incomplete",
144
+ "COUPON_INVENTORY_UNSUPPORTED",
145
+ );
146
+ }
147
+ for (const id of ids) {
148
+ const row = couponReadRow(id, 5 + reads.coupons.length);
149
+ const result = await transport.read(row);
150
+ if (result.kind === "provider_rejected")
151
+ return await release(
152
+ "observation_provider_rejected",
153
+ null,
154
+ null,
155
+ "incomplete",
156
+ null,
157
+ result.failure,
158
+ );
159
+ validateCoupon(captured.history.record, id, result.body);
160
+ reads.coupons.push(result.body);
161
+ }
162
+ const evidence = await analyze();
163
+ return await release(
164
+ "fresh_observation_data",
165
+ reads,
166
+ evidence,
167
+ "complete",
168
+ null,
169
+ );
170
+ } finally {
171
+ closeObservationInvocation(token);
172
+ }
173
+ },
174
+ });
175
+ }