@fantastic.dev/better-stripe 0.90.0 → 0.91.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 +6 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts +41 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +187 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.d.ts +2 -23
- package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.js +1 -112
- package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.d.ts +8 -3
- package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.js +1 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/test-fixtures/sourcePort.d.mts +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts +8 -0
- package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/actor.js +454 -0
- package/dist/client/billing/renewalAttach/internal/configure/actor.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/capture.d.ts +12 -0
- package/dist/client/billing/renewalAttach/internal/configure/capture.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/capture.js +99 -0
- package/dist/client/billing/renewalAttach/internal/configure/capture.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/output.d.ts +16 -0
- package/dist/client/billing/renewalAttach/internal/configure/output.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/output.js +274 -0
- package/dist/client/billing/renewalAttach/internal/configure/output.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/replay.d.ts +3 -0
- package/dist/client/billing/renewalAttach/internal/configure/replay.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/replay.js +9 -0
- package/dist/client/billing/renewalAttach/internal/configure/replay.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/request.d.ts +39 -0
- package/dist/client/billing/renewalAttach/internal/configure/request.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/request.js +245 -0
- package/dist/client/billing/renewalAttach/internal/configure/request.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts +88 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.js +289 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts +16 -0
- package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/actor.js +362 -0
- package/dist/client/billing/renewalAttach/internal/observation/actor.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts +9 -0
- package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/capture.js +215 -0
- package/dist/client/billing/renewalAttach/internal/observation/capture.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts +7 -0
- package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/profile.js +190 -0
- package/dist/client/billing/renewalAttach/internal/observation/profile.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/record.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/observation/record.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/record.js +317 -0
- package/dist/client/billing/renewalAttach/internal/observation/record.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.d.ts +79 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.js +27 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts +18 -0
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js +229 -0
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +163 -0
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +443 -0
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +8 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +467 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +6 -0
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +59 -0
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/providerFailure.d.ts +10 -0
- package/dist/client/billing/renewalAttach/internal/operations/providerFailure.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/providerFailure.js +48 -0
- package/dist/client/billing/renewalAttach/internal/operations/providerFailure.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts +20 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js +44 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/types.d.ts +42 -0
- package/dist/client/billing/renewalAttach/internal/operations/types.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/types.js +158 -0
- package/dist/client/billing/renewalAttach/internal/operations/types.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.js +214 -0
- package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/grammar.d.ts +33 -0
- package/dist/client/billing/renewalAttach/internal/preflight/grammar.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/grammar.js +208 -0
- package/dist/client/billing/renewalAttach/internal/preflight/grammar.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts +4 -0
- package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/output.js +25 -0
- package/dist/client/billing/renewalAttach/internal/preflight/output.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts +16 -0
- package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/record.js +93 -0
- package/dist/client/billing/renewalAttach/internal/preflight/record.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts +7 -0
- package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/relations.js +153 -0
- package/dist/client/billing/renewalAttach/internal/preflight/relations.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/material.d.ts +22 -0
- package/dist/client/billing/renewalAttach/internal/recovery/material.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/material.js +221 -0
- package/dist/client/billing/renewalAttach/internal/recovery/material.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts +8 -0
- package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/output.js +101 -0
- package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +12 -0
- package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/record.js +186 -0
- package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +498 -0
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +21 -0
- package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/relation.js +119 -0
- package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -0
- 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/mutations.d.ts +16 -16
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
- package/dist/component/usage/allowance.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +26 -8
- package/docs/renewal-material-observation.md +37 -0
- package/docs/renewal-phase-assembly.md +68 -0
- package/docs/renewal-raw-acquisition.md +19 -5
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +304 -0
- package/src/client/billing/renewalAttach/internal/acquisition/rawAcquisition.ts +2 -160
- package/src/client/billing/renewalAttach/internal/acquisition/rawWireSource.ts +15 -3
- package/src/client/billing/renewalAttach/internal/configure/actor.ts +575 -0
- package/src/client/billing/renewalAttach/internal/configure/capture.ts +117 -0
- package/src/client/billing/renewalAttach/internal/configure/dispatch.integration.test.ts +32 -0
- package/src/client/billing/renewalAttach/internal/configure/limits.test.ts +510 -0
- package/src/client/billing/renewalAttach/internal/configure/order.integration.test.ts +207 -0
- package/src/client/billing/renewalAttach/internal/configure/output.ts +372 -0
- package/src/client/billing/renewalAttach/internal/configure/ownership.integration.test.ts +148 -0
- package/src/client/billing/renewalAttach/internal/configure/replay.integration.test.ts +173 -0
- package/src/client/billing/renewalAttach/internal/configure/replay.ts +13 -0
- package/src/client/billing/renewalAttach/internal/configure/request.ts +312 -0
- package/src/client/billing/renewalAttach/internal/configure/transport.integration.test.ts +507 -0
- package/src/client/billing/renewalAttach/internal/configure/transport.ts +348 -0
- package/src/client/billing/renewalAttach/internal/observation/actor.ts +444 -0
- package/src/client/billing/renewalAttach/internal/observation/capture.ts +250 -0
- package/src/client/billing/renewalAttach/internal/observation/observation.integration.test.ts +220 -0
- package/src/client/billing/renewalAttach/internal/observation/observationRetirement.integration.test.ts +60 -0
- package/src/client/billing/renewalAttach/internal/observation/profile.ts +264 -0
- package/src/client/billing/renewalAttach/internal/observation/record.ts +408 -0
- package/src/client/billing/renewalAttach/internal/observation/types.ts +102 -0
- package/src/client/billing/renewalAttach/internal/operations/configureReadTransport.ts +285 -0
- package/src/client/billing/renewalAttach/internal/operations/defaultBindings.test.ts +69 -0
- package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +574 -0
- package/src/client/billing/renewalAttach/internal/operations/initialAttach.integration.test.ts +34 -0
- package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +535 -0
- package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +63 -0
- package/src/client/billing/renewalAttach/internal/operations/providerFailure.integration.test.ts +61 -0
- package/src/client/billing/renewalAttach/internal/operations/providerFailure.ts +66 -0
- package/src/client/billing/renewalAttach/internal/operations/sourceOperations.ts +50 -0
- package/src/client/billing/renewalAttach/internal/operations/transport.integration.test.ts +116 -0
- package/src/client/billing/renewalAttach/internal/operations/types.ts +223 -0
- package/src/client/billing/renewalAttach/internal/preflight/configurePreflight.integration.test.ts +285 -0
- package/src/client/billing/renewalAttach/internal/preflight/configurePreflight.ts +258 -0
- package/src/client/billing/renewalAttach/internal/preflight/configureReads.integration.test.ts +139 -0
- package/src/client/billing/renewalAttach/internal/preflight/grammar.ts +257 -0
- package/src/client/billing/renewalAttach/internal/preflight/output.ts +42 -0
- package/src/client/billing/renewalAttach/internal/preflight/owner.integration.test.ts +82 -0
- package/src/client/billing/renewalAttach/internal/preflight/preflight.integration.test.ts +354 -0
- package/src/client/billing/renewalAttach/internal/preflight/record.ts +127 -0
- package/src/client/billing/renewalAttach/internal/preflight/relations.ts +209 -0
- package/src/client/billing/renewalAttach/internal/recovery/material.ts +311 -0
- package/src/client/billing/renewalAttach/internal/recovery/output.ts +136 -0
- package/src/client/billing/renewalAttach/internal/recovery/record.ts +230 -0
- package/src/client/billing/renewalAttach/internal/recovery/recovery.integration.test.ts +463 -0
- package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +599 -0
- package/src/client/billing/renewalAttach/internal/recovery/relation.ts +175 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/attachEntries.ts +217 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/attachObservations.ts +226 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenario.ts +556 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenarioAssertions.ts +180 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenarioBarriers.ts +144 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightAssertions.ts +122 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightBarriers.ts +330 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightControls.ts +139 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightOperation.ts +513 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadNativeBaseline.ts +344 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadOperation.ts +278 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadPort.ts +17 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteAssertions.ts +533 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteBarriers.ts +125 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDeclarations.ts +314 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteHistory.ts +463 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteObservations.ts +515 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteOperation.ts +600 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationAssertions.ts +211 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationDeclarations.ts +192 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationHTTP.ts +197 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationObservations.ts +269 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationOperation.ts +262 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationProbe.ts +319 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/ownedOperations.ts +94 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/sourceOperationPort.ts +16 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/stockHttp.ts +21 -0
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { data, deepFreeze } from "./configurePreflightControls.js";
|
|
4
|
+
import { assertFit } from "./configurePreflightAssertions.js";
|
|
5
|
+
import type { declareConfigureWriteCase } from "./configureWriteDeclarations.js";
|
|
6
|
+
import type { WriteObservations } from "./configureWriteObservations.js";
|
|
7
|
+
import { assertActualWriteCounters } from "./configureWriteObservations.js";
|
|
8
|
+
import type { configureWriteBarriers } from "./configureWriteBarriers.js";
|
|
9
|
+
import type { ConfigureWriteFixture } from "./configureWriteOperation.js";
|
|
10
|
+
import type { ProjectedRenewalConfigurationV2 } from "../../../renewalV2/index.js";
|
|
11
|
+
|
|
12
|
+
/** Independent form oracle: compare every encoded leaf, including numeric array positions. */
|
|
13
|
+
function formLeaves(value: unknown, path = ""): [string, string][] {
|
|
14
|
+
if (value === null) return [[path, ""]];
|
|
15
|
+
if (typeof value !== "object") return [[path, String(value)]];
|
|
16
|
+
return Object.entries(value).flatMap(([key, child]) =>
|
|
17
|
+
formLeaves(child, path ? path + "[" + key + "]" : key),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
export function createWriteHTTPAndSink(
|
|
21
|
+
declared: ReturnType<typeof declareConfigureWriteCase>,
|
|
22
|
+
s: WriteObservations,
|
|
23
|
+
gates: ReturnType<typeof configureWriteBarriers>,
|
|
24
|
+
request: ProjectedRenewalConfigurationV2,
|
|
25
|
+
owner: typeof import("../originalOwner.js").OWNER,
|
|
26
|
+
advanceSchedule: () => void,
|
|
27
|
+
) {
|
|
28
|
+
const b = declared.currentBundle;
|
|
29
|
+
const query = new URLSearchParams(
|
|
30
|
+
["discounts", "items.data.discounts", "items.data.price"].map((v, i) => [
|
|
31
|
+
"expand[" + i + "]",
|
|
32
|
+
v,
|
|
33
|
+
]),
|
|
34
|
+
);
|
|
35
|
+
const rows = deepFreeze([
|
|
36
|
+
{
|
|
37
|
+
method: "GET",
|
|
38
|
+
path:
|
|
39
|
+
"/v1/subscriptions/" +
|
|
40
|
+
encodeURIComponent(b.wireSubscription.id) +
|
|
41
|
+
"?" +
|
|
42
|
+
query,
|
|
43
|
+
body: b.wireSubscription,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
method: "GET",
|
|
47
|
+
path: "/v1/prices/" + encodeURIComponent(b.wireTargetPrice.id),
|
|
48
|
+
body: b.wireTargetPrice,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
method: "GET",
|
|
52
|
+
path: "/v1/customers/" + encodeURIComponent(b.wireBillingCustomer.id),
|
|
53
|
+
body: b.wireBillingCustomer,
|
|
54
|
+
},
|
|
55
|
+
...b.couponReads.map((row) => ({
|
|
56
|
+
method: "GET",
|
|
57
|
+
path: "/v1/coupons/" + encodeURIComponent(row.couponId),
|
|
58
|
+
body: row.wireCoupon,
|
|
59
|
+
})),
|
|
60
|
+
{ method: "GET", path: request.path, body: declared.currentSchedule },
|
|
61
|
+
{ method: "POST", path: request.path, body: declared.response },
|
|
62
|
+
]);
|
|
63
|
+
const fetch = async (input: unknown, init: RequestInit) => {
|
|
64
|
+
const row = rows[s.calls.length],
|
|
65
|
+
url = new URL(String(input));
|
|
66
|
+
assert(row, "UNDECLARED_CONFIGURE_WRITE_HTTP");
|
|
67
|
+
assert.equal(url.origin, "https://api.stripe.com");
|
|
68
|
+
assert.equal(url.pathname + url.search, row.path);
|
|
69
|
+
assert.equal(init.method, row.method);
|
|
70
|
+
assert.equal(init.redirect, "error");
|
|
71
|
+
const headers = new Headers(init.headers);
|
|
72
|
+
assert.equal(headers.get("stripe-version"), request.apiVersion);
|
|
73
|
+
assert.equal(headers.get("stripe-account"), null);
|
|
74
|
+
if (row.method === "POST") {
|
|
75
|
+
assert.equal(headers.get("idempotency-key"), request.key);
|
|
76
|
+
const received = [
|
|
77
|
+
...new URLSearchParams(String(init.body)).entries(),
|
|
78
|
+
].sort();
|
|
79
|
+
assert.deepEqual(received, formLeaves(request.payload).sort());
|
|
80
|
+
assert.equal(s.records.length, 1, "POST_REQUIRES_DISPATCH_SEND_AND_ACK");
|
|
81
|
+
}
|
|
82
|
+
s.calls.push({
|
|
83
|
+
method: row.method,
|
|
84
|
+
path: row.path,
|
|
85
|
+
body: init.body ?? null,
|
|
86
|
+
key: headers.get("idempotency-key"),
|
|
87
|
+
});
|
|
88
|
+
s.trace.push("http:" + row.method);
|
|
89
|
+
if (
|
|
90
|
+
(declared.name === "get-reject" && row.method === "GET") ||
|
|
91
|
+
(declared.name === "post-reject" && row.method === "POST")
|
|
92
|
+
)
|
|
93
|
+
throw declared.providerRejection;
|
|
94
|
+
if (declared.name === "retire-get" && row.method === "GET")
|
|
95
|
+
await gates.hold("get");
|
|
96
|
+
if (
|
|
97
|
+
(declared.name === "retire-post" || declared.name === "pending-prior") &&
|
|
98
|
+
row.method === "POST"
|
|
99
|
+
)
|
|
100
|
+
await gates.hold("post");
|
|
101
|
+
if (row.method === "GET" && row.path === request.path) advanceSchedule();
|
|
102
|
+
const status = row.method === "POST" ? declared.status : 200;
|
|
103
|
+
return new Response(
|
|
104
|
+
JSON.stringify(status >= 400 ? declared.errorBody : row.body),
|
|
105
|
+
{
|
|
106
|
+
status,
|
|
107
|
+
headers: {
|
|
108
|
+
"content-type": "application/json",
|
|
109
|
+
...(declared.requestId === null
|
|
110
|
+
? {}
|
|
111
|
+
: { "request-id": declared.requestId }),
|
|
112
|
+
...(status === 307 || status === 308
|
|
113
|
+
? { location: "https://api.stripe.com/v1/forbidden-retry" }
|
|
114
|
+
: {}),
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
const sink = Object.freeze({
|
|
120
|
+
send(value: unknown, acknowledge: (value: unknown) => void) {
|
|
121
|
+
owner.check();
|
|
122
|
+
const record = data(value),
|
|
123
|
+
sequence = record.sequence;
|
|
124
|
+
assert.equal(sequence, s.records.length + 1);
|
|
125
|
+
assertFit(record);
|
|
126
|
+
s.records.push(record);
|
|
127
|
+
s.trace.push("sink:" + String(sequence));
|
|
128
|
+
const ack = { sequence, binding: record.binding };
|
|
129
|
+
if (declared.name === "wrong-ack") {
|
|
130
|
+
acknowledge({ ...ack, binding: "wrong" });
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (declared.name === "duplicate-ack") {
|
|
134
|
+
acknowledge(ack);
|
|
135
|
+
acknowledge(ack);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const stage =
|
|
139
|
+
sequence === 1 ? "dispatch" : sequence === 2 ? "response" : "receipt";
|
|
140
|
+
if (declared.name === stage + "-ack") {
|
|
141
|
+
const task = gates.hold(stage + "-ack").then(() => {
|
|
142
|
+
acknowledge(ack);
|
|
143
|
+
s.trace.push("ack:" + String(sequence));
|
|
144
|
+
});
|
|
145
|
+
gates.pending.push(task);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
acknowledge(ack);
|
|
149
|
+
s.trace.push("ack:" + String(sequence));
|
|
150
|
+
if (declared.name === stage + "-send") return gates.hold(stage + "-send");
|
|
151
|
+
if (declared.name === "retire-" + stage) return gates.hold(stage);
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
return Object.freeze({ fetch, sink });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const requestSlots = [
|
|
158
|
+
["logicalBinding"],
|
|
159
|
+
["attachReceiptBinding"],
|
|
160
|
+
["baselineBinding"],
|
|
161
|
+
["defaultSettingsBinding"],
|
|
162
|
+
["requestIdentity", "binding"],
|
|
163
|
+
] as const;
|
|
164
|
+
export function ackSlots(h: ConfigureWriteFixture) {
|
|
165
|
+
const record = [
|
|
166
|
+
...requestSlots.map((path) => ["originalRecord", "request", ...path]),
|
|
167
|
+
["originalRecord", "attachReceipt", "logicalBinding"],
|
|
168
|
+
["originalRecord", "attachReceipt", "request", "logicalBinding"],
|
|
169
|
+
[
|
|
170
|
+
"originalRecord",
|
|
171
|
+
"attachReceipt",
|
|
172
|
+
"request",
|
|
173
|
+
"requestIdentity",
|
|
174
|
+
"binding",
|
|
175
|
+
],
|
|
176
|
+
["originalRecord", "attachReceipt", "binding"],
|
|
177
|
+
];
|
|
178
|
+
return [
|
|
179
|
+
...record,
|
|
180
|
+
["receipt", "logicalBinding"],
|
|
181
|
+
...requestSlots.map((path) => ["receipt", "request", ...path]),
|
|
182
|
+
["receipt", "attachReceiptBinding"],
|
|
183
|
+
["receipt", "providerSnapshotBinding"],
|
|
184
|
+
["receipt", "binding"],
|
|
185
|
+
...(Object.prototype.hasOwnProperty.call(
|
|
186
|
+
h.expectedReceipt,
|
|
187
|
+
"defaultSettingsBinding",
|
|
188
|
+
)
|
|
189
|
+
? [["receipt", "defaultSettingsBinding"]]
|
|
190
|
+
: []),
|
|
191
|
+
];
|
|
192
|
+
}
|
|
193
|
+
export function assertConfigureACK(h: ConfigureWriteFixture, output: unknown) {
|
|
194
|
+
assert.deepEqual(output, h.expectedACK);
|
|
195
|
+
const out = data(output);
|
|
196
|
+
assert.deepEqual(Object.keys(out).sort(), [
|
|
197
|
+
"operationalAuthority",
|
|
198
|
+
"originalRecord",
|
|
199
|
+
"rawReceipt",
|
|
200
|
+
"receipt",
|
|
201
|
+
"status",
|
|
202
|
+
]);
|
|
203
|
+
assert(Object.isFrozen(out));
|
|
204
|
+
assert.equal(out.operationalAuthority, false);
|
|
205
|
+
assert.deepEqual(data(out.receipt).providerSnapshot, h.write.response);
|
|
206
|
+
assert.deepEqual(data(out.receipt).request, h.projected);
|
|
207
|
+
const slots = ackSlots(h);
|
|
208
|
+
assert.equal(
|
|
209
|
+
slots.length,
|
|
210
|
+
h.write.name === "defaults-null" || h.write.name === "defaults-object"
|
|
211
|
+
? 19
|
|
212
|
+
: 18,
|
|
213
|
+
);
|
|
214
|
+
for (const path of slots) {
|
|
215
|
+
let actual: unknown = output,
|
|
216
|
+
expected: unknown = h.expectedACK;
|
|
217
|
+
for (const key of path) {
|
|
218
|
+
actual = data(actual)[key];
|
|
219
|
+
expected = data(expected)[key];
|
|
220
|
+
}
|
|
221
|
+
assert.equal(actual, expected);
|
|
222
|
+
}
|
|
223
|
+
assertActualWriteCounters(h.writeState);
|
|
224
|
+
assert.equal(
|
|
225
|
+
h.writeState.calls.length,
|
|
226
|
+
5 + h.write.currentBundle.couponReads.length,
|
|
227
|
+
);
|
|
228
|
+
assert(h.writeState.calls.filter((row) => row.method === "GET").length <= 44);
|
|
229
|
+
for (const [part, value] of [
|
|
230
|
+
["record", h.expectedRecord],
|
|
231
|
+
["rawReceipt", h.rawReceipt],
|
|
232
|
+
["receipt", h.expectedReceipt],
|
|
233
|
+
["ACK", output],
|
|
234
|
+
] as const)
|
|
235
|
+
console.log(
|
|
236
|
+
JSON.stringify({
|
|
237
|
+
kind: "CONFIGURE_WRITER_WHOLE_METRICS",
|
|
238
|
+
part,
|
|
239
|
+
...assertFit(value),
|
|
240
|
+
}),
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function assertProviderFailure(
|
|
245
|
+
h: ConfigureWriteFixture,
|
|
246
|
+
error: unknown,
|
|
247
|
+
phase: "read" | "post",
|
|
248
|
+
) {
|
|
249
|
+
assert(error instanceof Error);
|
|
250
|
+
assert.equal(error.message, "OWNED_CONFIGURE_PROVIDER_REJECTED");
|
|
251
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, "failure");
|
|
252
|
+
assert(descriptor && "value" in descriptor);
|
|
253
|
+
assert.equal(descriptor.enumerable, false);
|
|
254
|
+
assert.equal(descriptor.configurable, false);
|
|
255
|
+
assert.equal(descriptor.writable, false);
|
|
256
|
+
const failure = data(descriptor.value);
|
|
257
|
+
assert.deepEqual(Object.keys(failure).sort(), [
|
|
258
|
+
"category",
|
|
259
|
+
"diagnostics",
|
|
260
|
+
"operationalAuthority",
|
|
261
|
+
"ordinal",
|
|
262
|
+
"outcome",
|
|
263
|
+
"phase",
|
|
264
|
+
"request",
|
|
265
|
+
"resource",
|
|
266
|
+
]);
|
|
267
|
+
assert.equal(failure.category, "provider_rejected");
|
|
268
|
+
assert.equal(failure.phase, phase);
|
|
269
|
+
assert.equal(
|
|
270
|
+
failure.resource,
|
|
271
|
+
phase === "read" ? "subscription" : "configure",
|
|
272
|
+
);
|
|
273
|
+
assert.equal(
|
|
274
|
+
failure.ordinal,
|
|
275
|
+
phase === "read" ? 1 : 5 + h.write.currentBundle.couponReads.length,
|
|
276
|
+
);
|
|
277
|
+
const diagnostics = data(failure.diagnostics);
|
|
278
|
+
assert(Object.isFrozen(diagnostics));
|
|
279
|
+
assert(
|
|
280
|
+
Object.keys(diagnostics).every((key) =>
|
|
281
|
+
["type", "code", "requestId", "statusCode"].includes(key),
|
|
282
|
+
),
|
|
283
|
+
);
|
|
284
|
+
for (const value of Object.values(diagnostics))
|
|
285
|
+
if (typeof value === "string") {
|
|
286
|
+
assert(value.length > 0 && value.length <= 255);
|
|
287
|
+
assert(!value.includes("sk_live_"));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
assert.equal(failure.outcome, "unknown");
|
|
291
|
+
assert.equal(failure.operationalAuthority, false);
|
|
292
|
+
assert.deepEqual(failure.request, h.projected);
|
|
293
|
+
assert(Object.isFrozen(failure));
|
|
294
|
+
assertFit(failure);
|
|
295
|
+
assert.equal(Object.prototype.hasOwnProperty.call(error, "cause"), false);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Actual unchanged C9 and all whole DATA metrics must qualify before the target. */
|
|
299
|
+
export async function establishWriteOracle(
|
|
300
|
+
active: typeof import("../../../renewalV2/index.js"),
|
|
301
|
+
owner: typeof import("../originalOwner.js").OWNER,
|
|
302
|
+
configuration: Parameters<typeof active.projectRenewalConfigurationV2>[0],
|
|
303
|
+
projected: ProjectedRenewalConfigurationV2,
|
|
304
|
+
write: ReturnType<typeof declareConfigureWriteCase>,
|
|
305
|
+
expectedRecord: unknown,
|
|
306
|
+
) {
|
|
307
|
+
const dispatch = {
|
|
308
|
+
scope: projected.scope,
|
|
309
|
+
apiVersion: projected.apiVersion,
|
|
310
|
+
method: projected.method,
|
|
311
|
+
path: projected.path,
|
|
312
|
+
payload: projected.payload,
|
|
313
|
+
key: projected.key,
|
|
314
|
+
firstDispatchedAt: projected.firstDispatchedAt,
|
|
315
|
+
};
|
|
316
|
+
const rawReceipt = deepFreeze({
|
|
317
|
+
configuration: configuration,
|
|
318
|
+
actualDispatch: dispatch,
|
|
319
|
+
providerSnapshot: write.oracleResponse,
|
|
320
|
+
transport: {
|
|
321
|
+
status: 200,
|
|
322
|
+
...(write.oracleRequestId === null
|
|
323
|
+
? {}
|
|
324
|
+
: { requestId: write.oracleRequestId }),
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
const expectedReceipt =
|
|
328
|
+
await active.constructRenewalConfigurationReceiptV2(rawReceipt);
|
|
329
|
+
owner.check();
|
|
330
|
+
assert.equal(
|
|
331
|
+
expectedReceipt.stage,
|
|
332
|
+
"configure_acknowledged",
|
|
333
|
+
"ACTUAL_C9_PREREQUISITE",
|
|
334
|
+
);
|
|
335
|
+
assertFit(rawReceipt);
|
|
336
|
+
assertFit(expectedReceipt);
|
|
337
|
+
const expectedACK = deepFreeze({
|
|
338
|
+
status: "configure_acknowledged",
|
|
339
|
+
originalRecord: expectedRecord,
|
|
340
|
+
rawReceipt,
|
|
341
|
+
receipt: expectedReceipt,
|
|
342
|
+
operationalAuthority: false,
|
|
343
|
+
});
|
|
344
|
+
assertFit(expectedACK);
|
|
345
|
+
return { rawReceipt, expectedReceipt, expectedACK };
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** Independent Node hash oracle uses the documented exact V2 JSON preimage. */
|
|
349
|
+
function expectedBinding(family: string, preimage: unknown) {
|
|
350
|
+
const canonical = (value: unknown): unknown =>
|
|
351
|
+
Array.isArray(value)
|
|
352
|
+
? value.map(canonical)
|
|
353
|
+
: value !== null && typeof value === "object"
|
|
354
|
+
? Object.fromEntries(
|
|
355
|
+
Object.entries(value)
|
|
356
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
357
|
+
.map(([key, child]) => [key, canonical(child)]),
|
|
358
|
+
)
|
|
359
|
+
: value;
|
|
360
|
+
const text = JSON.stringify(
|
|
361
|
+
canonical(["betterstripe-renewal-binding", 2, family, preimage]),
|
|
362
|
+
);
|
|
363
|
+
assert(Buffer.byteLength(text, "utf8") <= 500000);
|
|
364
|
+
return (
|
|
365
|
+
family +
|
|
366
|
+
":v2:sha256:" +
|
|
367
|
+
createHash("sha256").update(text, "utf8").digest("hex")
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
export function assertWriteTokenPreimages(
|
|
371
|
+
preparedValue: unknown,
|
|
372
|
+
recordValue: unknown,
|
|
373
|
+
receiptValue: unknown,
|
|
374
|
+
) {
|
|
375
|
+
const prepared = data(preparedValue),
|
|
376
|
+
record = data(recordValue),
|
|
377
|
+
request = data(record.request),
|
|
378
|
+
attach = data(record.attachReceipt),
|
|
379
|
+
receipt = data(receiptValue);
|
|
380
|
+
const {
|
|
381
|
+
status: _status,
|
|
382
|
+
preservation: _preservation,
|
|
383
|
+
requestIdentity: _identity,
|
|
384
|
+
...C1
|
|
385
|
+
} = prepared;
|
|
386
|
+
const logical = expectedBinding("renewal", C1);
|
|
387
|
+
assert.equal(request.logicalBinding, logical);
|
|
388
|
+
assert.equal(attach.logicalBinding, logical);
|
|
389
|
+
const attachRequest = data(attach.request),
|
|
390
|
+
{ requestIdentity: attachIdentity, ...C2 } = attachRequest;
|
|
391
|
+
assert.equal(attachRequest.logicalBinding, logical);
|
|
392
|
+
assert.equal(
|
|
393
|
+
data(attachIdentity).binding,
|
|
394
|
+
expectedBinding("renewal-attach", C2),
|
|
395
|
+
);
|
|
396
|
+
const { binding: attachBinding, ...C3 } = attach;
|
|
397
|
+
assert.equal(attachBinding, expectedBinding("renewal-attach-receipt", C3));
|
|
398
|
+
assert.equal(request.attachReceiptBinding, attachBinding);
|
|
399
|
+
assert.equal(
|
|
400
|
+
request.baselineBinding,
|
|
401
|
+
expectedBinding("renewal-baseline", attach.providerSnapshot),
|
|
402
|
+
);
|
|
403
|
+
const configuration = data(record.configuration),
|
|
404
|
+
schedule = data(configuration.schedule);
|
|
405
|
+
assert.equal(
|
|
406
|
+
request.defaultSettingsBinding,
|
|
407
|
+
expectedBinding("renewal-defaults", schedule.default_settings),
|
|
408
|
+
);
|
|
409
|
+
const {
|
|
410
|
+
status: _s,
|
|
411
|
+
providerQualification: _q,
|
|
412
|
+
profile: _p,
|
|
413
|
+
requestIdentity,
|
|
414
|
+
...C6
|
|
415
|
+
} = request;
|
|
416
|
+
assert.equal(Object.keys(C6).length, 14);
|
|
417
|
+
assert.equal(
|
|
418
|
+
data(requestIdentity).binding,
|
|
419
|
+
expectedBinding("renewal-configure", C6),
|
|
420
|
+
);
|
|
421
|
+
assert.deepEqual(receipt.request, request);
|
|
422
|
+
assert.equal(receipt.logicalBinding, logical);
|
|
423
|
+
assert.equal(receipt.attachReceiptBinding, attachBinding);
|
|
424
|
+
assert.equal(
|
|
425
|
+
receipt.providerSnapshotBinding,
|
|
426
|
+
expectedBinding("renewal-configured-baseline", receipt.providerSnapshot),
|
|
427
|
+
);
|
|
428
|
+
const response = data(receipt.providerSnapshot);
|
|
429
|
+
assert.equal(
|
|
430
|
+
Object.prototype.hasOwnProperty.call(receipt, "defaultSettingsBinding"),
|
|
431
|
+
Object.prototype.hasOwnProperty.call(response, "default_settings"),
|
|
432
|
+
);
|
|
433
|
+
if (Object.prototype.hasOwnProperty.call(response, "default_settings"))
|
|
434
|
+
assert.equal(
|
|
435
|
+
receipt.defaultSettingsBinding,
|
|
436
|
+
expectedBinding("renewal-configured-defaults", response.default_settings),
|
|
437
|
+
);
|
|
438
|
+
const { binding, ...C9 } = receipt;
|
|
439
|
+
assert.equal(binding, expectedBinding("renewal-configure-receipt", C9));
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export function logWritePrerequisites(values: {
|
|
443
|
+
initialOutput: unknown;
|
|
444
|
+
preflightOutput: unknown;
|
|
445
|
+
expectedRecord: unknown;
|
|
446
|
+
rawReceipt: unknown;
|
|
447
|
+
expectedReceipt: unknown;
|
|
448
|
+
expectedACK: unknown;
|
|
449
|
+
request: ProjectedRenewalConfigurationV2;
|
|
450
|
+
state: WriteObservations;
|
|
451
|
+
}) {
|
|
452
|
+
const { request, state } = values;
|
|
453
|
+
assert.equal(Object.keys(request).length, 18);
|
|
454
|
+
assert.equal(data(values.initialOutput).status, "attach_acknowledged");
|
|
455
|
+
assert.equal(
|
|
456
|
+
data(values.preflightOutput).status,
|
|
457
|
+
"configure_preflight_consistent",
|
|
458
|
+
);
|
|
459
|
+
assert.equal(data(values.expectedReceipt).stage, "configure_acknowledged");
|
|
460
|
+
assert.deepEqual(
|
|
461
|
+
[
|
|
462
|
+
state.calls.length,
|
|
463
|
+
state.records.length,
|
|
464
|
+
state.sourceLoads,
|
|
465
|
+
state.pairLoads,
|
|
466
|
+
state.reserves,
|
|
467
|
+
state.coverage,
|
|
468
|
+
state.targetCalls,
|
|
469
|
+
],
|
|
470
|
+
[0, 0, 0, 0, 0, 0, 0],
|
|
471
|
+
);
|
|
472
|
+
const raw = data(values.rawReceipt);
|
|
473
|
+
const events = [
|
|
474
|
+
{ event: "dispatch", stage: "configure", request },
|
|
475
|
+
{
|
|
476
|
+
event: "response",
|
|
477
|
+
stage: "configure",
|
|
478
|
+
request,
|
|
479
|
+
body: raw.providerSnapshot,
|
|
480
|
+
transport: raw.transport,
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
event: "receipt",
|
|
484
|
+
stage: "configure",
|
|
485
|
+
request,
|
|
486
|
+
receipt: values.expectedReceipt,
|
|
487
|
+
},
|
|
488
|
+
];
|
|
489
|
+
for (const [index, event] of events.entries()) {
|
|
490
|
+
const envelope = { sequence: index + 1, data: event };
|
|
491
|
+
const template = {
|
|
492
|
+
...envelope,
|
|
493
|
+
binding: expectedBinding("unbound-qualification-event", envelope),
|
|
494
|
+
};
|
|
495
|
+
console.log(
|
|
496
|
+
JSON.stringify({
|
|
497
|
+
kind: "CONFIGURE_WRITER_PREREQUISITE_METRICS",
|
|
498
|
+
part: "C10-DATA-template-" + String(index + 1),
|
|
499
|
+
...assertFit(template),
|
|
500
|
+
}),
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
for (const [part, value] of Object.entries(values))
|
|
504
|
+
if (!["request", "state"].includes(part))
|
|
505
|
+
console.log(
|
|
506
|
+
JSON.stringify({
|
|
507
|
+
kind: "CONFIGURE_WRITER_PREREQUISITE_METRICS",
|
|
508
|
+
part,
|
|
509
|
+
...assertFit(value),
|
|
510
|
+
}),
|
|
511
|
+
);
|
|
512
|
+
console.log(
|
|
513
|
+
JSON.stringify({
|
|
514
|
+
kind: "CONFIGURE_WRITER_PREREQUISITES",
|
|
515
|
+
actualInitialACK: true,
|
|
516
|
+
actualOwnedPreflight: true,
|
|
517
|
+
actualDirectC9: true,
|
|
518
|
+
requestFields: 18,
|
|
519
|
+
generatedACKSlots: Object.prototype.hasOwnProperty.call(
|
|
520
|
+
values.expectedReceipt,
|
|
521
|
+
"defaultSettingsBinding",
|
|
522
|
+
)
|
|
523
|
+
? 19
|
|
524
|
+
: 18,
|
|
525
|
+
preimageOracle: "independent-Node-C1-through-C9",
|
|
526
|
+
writeHTTP: 0,
|
|
527
|
+
writeRecords: 0,
|
|
528
|
+
targetCalls: 0,
|
|
529
|
+
C10TemplatesAreActualSinkEvidence: false,
|
|
530
|
+
operationalAuthority: false,
|
|
531
|
+
}),
|
|
532
|
+
);
|
|
533
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { webcrypto } from "node:crypto";
|
|
3
|
+
import { vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
export function configureWriteBarriers() {
|
|
6
|
+
const pending: Promise<unknown>[] = [];
|
|
7
|
+
const waiting = new Map<
|
|
8
|
+
string,
|
|
9
|
+
{
|
|
10
|
+
entered: Promise<void>;
|
|
11
|
+
signal: () => void;
|
|
12
|
+
release: () => void;
|
|
13
|
+
released: Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
>();
|
|
16
|
+
const cell = (key: string) => {
|
|
17
|
+
let value = waiting.get(key);
|
|
18
|
+
if (!value) {
|
|
19
|
+
let signal!: () => void, release!: () => void;
|
|
20
|
+
const entered = new Promise<void>((r) => {
|
|
21
|
+
signal = r;
|
|
22
|
+
});
|
|
23
|
+
const released = new Promise<void>((r) => {
|
|
24
|
+
release = r;
|
|
25
|
+
});
|
|
26
|
+
value = { entered, signal, release, released };
|
|
27
|
+
waiting.set(key, value);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
};
|
|
31
|
+
const activeDigests = new Set<Promise<unknown>>();
|
|
32
|
+
return {
|
|
33
|
+
pending,
|
|
34
|
+
activeDigests,
|
|
35
|
+
async hold(key: string) {
|
|
36
|
+
const c = cell(key);
|
|
37
|
+
c.signal();
|
|
38
|
+
await c.released;
|
|
39
|
+
},
|
|
40
|
+
async entered(key: string, operation: Promise<unknown>) {
|
|
41
|
+
const settled = operation.then(
|
|
42
|
+
() => false,
|
|
43
|
+
() => false,
|
|
44
|
+
);
|
|
45
|
+
assert.equal(
|
|
46
|
+
await Promise.race([cell(key).entered.then(() => true), settled]),
|
|
47
|
+
true,
|
|
48
|
+
"WRITE_SETTLED_BEFORE_DECLARED_BARRIER",
|
|
49
|
+
);
|
|
50
|
+
},
|
|
51
|
+
release(key: string) {
|
|
52
|
+
cell(key).release();
|
|
53
|
+
},
|
|
54
|
+
async cleanup() {
|
|
55
|
+
try {
|
|
56
|
+
for (const c of waiting.values()) c.release();
|
|
57
|
+
await Promise.allSettled(pending);
|
|
58
|
+
assert.equal(activeDigests.size, 0);
|
|
59
|
+
} finally {
|
|
60
|
+
vi.doUnmock("../configure/transport.js");
|
|
61
|
+
vi.doUnmock("../acquisition/ownedAcquisition.js");
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Real native digest receiver and arguments; observed continuations are all joined. */
|
|
68
|
+
export function installWriteDigestAccounting(
|
|
69
|
+
gates: ReturnType<typeof configureWriteBarriers>,
|
|
70
|
+
) {
|
|
71
|
+
vi.stubGlobal("crypto", {
|
|
72
|
+
subtle: {
|
|
73
|
+
digest(...args: Parameters<typeof webcrypto.subtle.digest>) {
|
|
74
|
+
const [algorithm, input] = args;
|
|
75
|
+
assert.equal(
|
|
76
|
+
typeof algorithm === "string" ? algorithm : algorithm.name,
|
|
77
|
+
"SHA-256",
|
|
78
|
+
);
|
|
79
|
+
assert(ArrayBuffer.isView(input));
|
|
80
|
+
const tuple: unknown = JSON.parse(
|
|
81
|
+
new TextDecoder().decode(
|
|
82
|
+
new Uint8Array(input.buffer, input.byteOffset, input.byteLength),
|
|
83
|
+
),
|
|
84
|
+
);
|
|
85
|
+
assert(Array.isArray(tuple));
|
|
86
|
+
// Public renewal bindings and C10 event digests use distinct fixed domains.
|
|
87
|
+
assert.equal(tuple.length, 4);
|
|
88
|
+
assert.equal(tuple[0], "betterstripe-renewal-binding");
|
|
89
|
+
assert.equal(tuple[1], 2);
|
|
90
|
+
assert.equal(typeof tuple[2], "string");
|
|
91
|
+
assert(
|
|
92
|
+
new Set([
|
|
93
|
+
"renewal",
|
|
94
|
+
"renewal-attach",
|
|
95
|
+
"renewal-attach-receipt",
|
|
96
|
+
"renewal-baseline",
|
|
97
|
+
"renewal-defaults",
|
|
98
|
+
"renewal-configure",
|
|
99
|
+
"renewal-configured-baseline",
|
|
100
|
+
"renewal-configured-defaults",
|
|
101
|
+
"renewal-configure-receipt",
|
|
102
|
+
"unbound-qualification-event",
|
|
103
|
+
]).has(tuple[2]),
|
|
104
|
+
);
|
|
105
|
+
const actual = Reflect.apply(
|
|
106
|
+
webcrypto.subtle.digest,
|
|
107
|
+
webcrypto.subtle,
|
|
108
|
+
args,
|
|
109
|
+
) as ReturnType<typeof webcrypto.subtle.digest>;
|
|
110
|
+
gates.activeDigests.add(actual);
|
|
111
|
+
gates.pending.push(
|
|
112
|
+
actual.then(
|
|
113
|
+
() => {
|
|
114
|
+
gates.activeDigests.delete(actual);
|
|
115
|
+
},
|
|
116
|
+
() => {
|
|
117
|
+
gates.activeDigests.delete(actual);
|
|
118
|
+
},
|
|
119
|
+
),
|
|
120
|
+
);
|
|
121
|
+
return actual;
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
}
|