@fantastic.dev/better-stripe 0.86.0 → 0.88.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/renewalObservation/active-scheduled.d.ts +6 -0
- package/dist/client/billing/renewalObservation/active-scheduled.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/active-scheduled.js +37 -0
- package/dist/client/billing/renewalObservation/active-scheduled.js.map +1 -0
- package/dist/client/billing/renewalObservation/common.d.ts +47 -0
- package/dist/client/billing/renewalObservation/common.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/common.js +39 -0
- package/dist/client/billing/renewalObservation/common.js.map +1 -0
- package/dist/client/billing/renewalObservation/configured-baseline.d.ts +76 -0
- package/dist/client/billing/renewalObservation/configured-baseline.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/configured-baseline.js +26 -0
- package/dist/client/billing/renewalObservation/configured-baseline.js.map +1 -0
- package/dist/client/billing/renewalObservation/coupon-discount-joins.d.ts +53 -0
- package/dist/client/billing/renewalObservation/coupon-discount-joins.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/coupon-discount-joins.js +103 -0
- package/dist/client/billing/renewalObservation/coupon-discount-joins.js.map +1 -0
- package/dist/client/billing/renewalObservation/invoice-tax-identity.d.ts +52 -0
- package/dist/client/billing/renewalObservation/invoice-tax-identity.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/invoice-tax-identity.js +49 -0
- package/dist/client/billing/renewalObservation/invoice-tax-identity.js.map +1 -0
- package/dist/client/billing/renewalObservation/pending-and-stage.d.ts +76 -0
- package/dist/client/billing/renewalObservation/pending-and-stage.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/pending-and-stage.js +36 -0
- package/dist/client/billing/renewalObservation/pending-and-stage.js.map +1 -0
- package/dist/client/billing/renewalObservation/phase-price-normalization.d.ts +57 -0
- package/dist/client/billing/renewalObservation/phase-price-normalization.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/phase-price-normalization.js +70 -0
- package/dist/client/billing/renewalObservation/phase-price-normalization.js.map +1 -0
- package/dist/client/billing/renewalObservation/planProjection.d.ts +8 -0
- package/dist/client/billing/renewalObservation/planProjection.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/planProjection.js +150 -0
- package/dist/client/billing/renewalObservation/planProjection.js.map +1 -0
- package/dist/client/billing/renewalObservation/reference-catalog.d.ts +37 -0
- package/dist/client/billing/renewalObservation/reference-catalog.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/reference-catalog.js +109 -0
- package/dist/client/billing/renewalObservation/reference-catalog.js.map +1 -0
- package/dist/client/billing/renewalObservation/schedule-templates.d.ts +74 -0
- package/dist/client/billing/renewalObservation/schedule-templates.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/schedule-templates.js +72 -0
- package/dist/client/billing/renewalObservation/schedule-templates.js.map +1 -0
- package/dist/client/billing/renewalObservation/scheduled-context.d.ts +44 -0
- package/dist/client/billing/renewalObservation/scheduled-context.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/scheduled-context.js +64 -0
- package/dist/client/billing/renewalObservation/scheduled-context.js.map +1 -0
- package/dist/client/billing/renewalObservation/scheduled-identity.d.ts +53 -0
- package/dist/client/billing/renewalObservation/scheduled-identity.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/scheduled-identity.js +95 -0
- package/dist/client/billing/renewalObservation/scheduled-identity.js.map +1 -0
- package/dist/client/billing/renewalObservation/scheduled-normalization.d.ts +59 -0
- package/dist/client/billing/renewalObservation/scheduled-normalization.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/scheduled-normalization.js +29 -0
- package/dist/client/billing/renewalObservation/scheduled-normalization.js.map +1 -0
- package/dist/client/billing/renewalObservation/settings-normalization.d.ts +54 -0
- package/dist/client/billing/renewalObservation/settings-normalization.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/settings-normalization.js +53 -0
- package/dist/client/billing/renewalObservation/settings-normalization.js.map +1 -0
- package/dist/client/billing/renewalObservation/stage-runner.d.ts +4 -0
- package/dist/client/billing/renewalObservation/stage-runner.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/stage-runner.js +34 -0
- package/dist/client/billing/renewalObservation/stage-runner.js.map +1 -0
- package/dist/client/billing/renewalObservation/weeklyPending.d.ts +13 -0
- package/dist/client/billing/renewalObservation/weeklyPending.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/weeklyPending.js +55 -0
- package/dist/client/billing/renewalObservation/weeklyPending.js.map +1 -0
- package/dist/client/billing/renewalV2/binding.d.ts +1 -1
- package/dist/client/billing/renewalV2/binding.d.ts.map +1 -1
- package/dist/client/billing/renewalV2/binding.js.map +1 -1
- package/dist/client/billing/renewalV2/configureInput.d.ts +1 -0
- package/dist/client/billing/renewalV2/configureInput.d.ts.map +1 -1
- package/dist/client/billing/renewalV2/configureInput.js +3 -3
- package/dist/client/billing/renewalV2/configureInput.js.map +1 -1
- package/dist/client/billing/renewalV2/configureReceipt.d.ts +19 -0
- package/dist/client/billing/renewalV2/configureReceipt.d.ts.map +1 -0
- package/dist/client/billing/renewalV2/configureReceipt.js +91 -0
- package/dist/client/billing/renewalV2/configureReceipt.js.map +1 -0
- package/dist/client/billing/renewalV2/index.d.ts +417 -0
- package/dist/client/billing/renewalV2/index.d.ts.map +1 -1
- package/dist/client/billing/renewalV2/index.js +73 -3
- package/dist/client/billing/renewalV2/index.js.map +1 -1
- package/dist/client/billing/renewalV2/observation.d.ts +19 -0
- package/dist/client/billing/renewalV2/observation.d.ts.map +1 -0
- package/dist/client/billing/renewalV2/observation.js +95 -0
- package/dist/client/billing/renewalV2/observation.js.map +1 -0
- package/dist/client/billing/renewalV2/observationInput.d.ts +77 -0
- package/dist/client/billing/renewalV2/observationInput.d.ts.map +1 -0
- package/dist/client/billing/renewalV2/observationInput.js +140 -0
- package/dist/client/billing/renewalV2/observationInput.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
- package/dist/client/renewal.d.ts +4 -2
- package/dist/client/renewal.d.ts.map +1 -1
- package/dist/client/renewal.js +2 -1
- package/dist/client/renewal.js.map +1 -1
- package/dist/client/usage/observationClient.d.ts +2 -2
- package/dist/client/usage/observationClient.d.ts.map +1 -1
- 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/usage/allowance.fixtures.d.ts +16 -16
- package/docs/client-api.md +26 -0
- package/docs/renewal-context-reads.md +5 -1
- package/docs/renewal-material-observation.md +124 -0
- package/docs/renewal-phase-assembly.md +68 -0
- package/docs/renewal-price-replacements.md +3 -0
- package/package.json +1 -1
- package/src/client/billing/renewalObservation/active-scheduled.ts +67 -0
- package/src/client/billing/renewalObservation/common.ts +83 -0
- package/src/client/billing/renewalObservation/configured-baseline.ts +55 -0
- package/src/client/billing/renewalObservation/coupon-discount-joins.ts +163 -0
- package/src/client/billing/renewalObservation/invoice-tax-identity.ts +65 -0
- package/src/client/billing/renewalObservation/pending-and-stage.ts +89 -0
- package/src/client/billing/renewalObservation/phase-price-normalization.ts +106 -0
- package/src/client/billing/renewalObservation/planProjection.ts +177 -0
- package/src/client/billing/renewalObservation/reference-catalog.ts +150 -0
- package/src/client/billing/renewalObservation/schedule-templates.ts +118 -0
- package/src/client/billing/renewalObservation/scheduled-context.ts +98 -0
- package/src/client/billing/renewalObservation/scheduled-identity.ts +175 -0
- package/src/client/billing/renewalObservation/scheduled-normalization.ts +49 -0
- package/src/client/billing/renewalObservation/settings-normalization.ts +60 -0
- package/src/client/billing/renewalObservation/stage-runner.ts +30 -0
- package/src/client/billing/renewalObservation/weeklyPending.ts +81 -0
- package/src/client/billing/renewalV2/binding.ts +4 -1
- package/src/client/billing/renewalV2/configureInput.ts +3 -3
- package/src/client/billing/renewalV2/configureReceipt.test.ts +558 -0
- package/src/client/billing/renewalV2/configureReceipt.ts +96 -0
- package/src/client/billing/renewalV2/index.ts +131 -6
- package/src/client/billing/renewalV2/observation.boundary-review.test.ts +49 -0
- package/src/client/billing/renewalV2/observation.test.ts +334 -0
- package/src/client/billing/renewalV2/observation.ts +149 -0
- package/src/client/billing/renewalV2/observationInput.ts +167 -0
- package/src/client/renewal.ts +10 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {
|
|
2
|
+
captureObservation,
|
|
3
|
+
type InspectRenewalScheduleMaterialV2Options,
|
|
4
|
+
} from "./observationInput.js";
|
|
5
|
+
import {
|
|
6
|
+
reconstructConfigurationV2,
|
|
7
|
+
constructRenewalConfigurationReceiptV2,
|
|
8
|
+
type ProjectRenewalConfigurationV2Options,
|
|
9
|
+
type ConstructRenewalConfigurationReceiptV2Options,
|
|
10
|
+
} from "./index.js";
|
|
11
|
+
import { createContext } from "../renewalObservation/scheduled-context.js";
|
|
12
|
+
import { runStages } from "../renewalObservation/stage-runner.js";
|
|
13
|
+
import {
|
|
14
|
+
Stop,
|
|
15
|
+
object,
|
|
16
|
+
array,
|
|
17
|
+
get,
|
|
18
|
+
equal,
|
|
19
|
+
type ObserverCandidateResult,
|
|
20
|
+
type Evidence,
|
|
21
|
+
} from "../renewalObservation/common.js";
|
|
22
|
+
export type {
|
|
23
|
+
InspectRenewalScheduleMaterialV2Options,
|
|
24
|
+
RenewalScheduleMaterialReads,
|
|
25
|
+
} from "./observationInput.js";
|
|
26
|
+
export type RenewalScheduleMaterialObservationV2 = {
|
|
27
|
+
predicate:
|
|
28
|
+
| "attached_unconfigured_match"
|
|
29
|
+
| "pending_material_match"
|
|
30
|
+
| "current_target_material_match"
|
|
31
|
+
| "terminal_facts_only"
|
|
32
|
+
| "unknown"
|
|
33
|
+
| "conflict";
|
|
34
|
+
reason?: string;
|
|
35
|
+
observedItemId?: string;
|
|
36
|
+
nativePeriod?: { start: number; end: number };
|
|
37
|
+
providerStatus?: unknown;
|
|
38
|
+
effectiveness?: "unknown";
|
|
39
|
+
acknowledgementEstablished: false;
|
|
40
|
+
authenticationEstablished: false;
|
|
41
|
+
providerQualificationRequired: true;
|
|
42
|
+
};
|
|
43
|
+
const base = {
|
|
44
|
+
acknowledgementEstablished: false,
|
|
45
|
+
authenticationEstablished: false,
|
|
46
|
+
providerQualificationRequired: true,
|
|
47
|
+
} as const;
|
|
48
|
+
function result(
|
|
49
|
+
r: ObserverCandidateResult,
|
|
50
|
+
): RenewalScheduleMaterialObservationV2 {
|
|
51
|
+
const predicate =
|
|
52
|
+
r.predicate === "confirmed_pending"
|
|
53
|
+
? "pending_material_match"
|
|
54
|
+
: r.predicate === "active_effective_match"
|
|
55
|
+
? "current_target_material_match"
|
|
56
|
+
: r.predicate === "configured_baseline_material_match"
|
|
57
|
+
? "unknown"
|
|
58
|
+
: r.predicate;
|
|
59
|
+
return {
|
|
60
|
+
...base,
|
|
61
|
+
predicate,
|
|
62
|
+
...(r.reason ? { reason: r.reason } : {}),
|
|
63
|
+
...(r.observedItemId ? { observedItemId: r.observedItemId } : {}),
|
|
64
|
+
...(r.nativePeriod ? { nativePeriod: r.nativePeriod } : {}),
|
|
65
|
+
...(r.providerStatus !== undefined
|
|
66
|
+
? { providerStatus: r.providerStatus }
|
|
67
|
+
: {}),
|
|
68
|
+
...(r.effectiveness ? { effectiveness: r.effectiveness } : {}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Unsigned full-material comparison only. No HTTP, trusted-store or entitlement authority. */
|
|
72
|
+
export async function inspectRenewalScheduleMaterialV2(
|
|
73
|
+
options: InspectRenewalScheduleMaterialV2Options,
|
|
74
|
+
): Promise<RenewalScheduleMaterialObservationV2> {
|
|
75
|
+
const captured = captureObservation(options);
|
|
76
|
+
try {
|
|
77
|
+
const reconstruction = await reconstructConfigurationV2(
|
|
78
|
+
captured.configuration as ProjectRenewalConfigurationV2Options,
|
|
79
|
+
);
|
|
80
|
+
if (!reconstruction.material)
|
|
81
|
+
return {
|
|
82
|
+
...base,
|
|
83
|
+
predicate:
|
|
84
|
+
reconstruction.result.status === "conflict" ? "conflict" : "unknown",
|
|
85
|
+
reason: reconstruction.result.reason,
|
|
86
|
+
};
|
|
87
|
+
const { material, result: request } = reconstruction;
|
|
88
|
+
const owned = { ...material, request };
|
|
89
|
+
let evidence: Evidence | undefined;
|
|
90
|
+
if (captured.configureReceipt) {
|
|
91
|
+
if (
|
|
92
|
+
!equal(captured.configureReceipt.configuration, captured.configuration)
|
|
93
|
+
)
|
|
94
|
+
return {
|
|
95
|
+
...base,
|
|
96
|
+
predicate: "conflict",
|
|
97
|
+
reason: "invalid_repeated_configuration",
|
|
98
|
+
};
|
|
99
|
+
const receipt = await constructRenewalConfigurationReceiptV2(
|
|
100
|
+
captured.configureReceipt as ConstructRenewalConfigurationReceiptV2Options,
|
|
101
|
+
);
|
|
102
|
+
const sub = get(material.prepared.providerSnapshot, "subscription"),
|
|
103
|
+
item = object(array(get(sub, "items").data)[0]);
|
|
104
|
+
const coupons = new Map<string, Record<string, unknown>>();
|
|
105
|
+
for (const raw of [...array(sub.discounts), ...array(item.discounts)]) {
|
|
106
|
+
const coupon = get(get(object(raw), "source"), "coupon"),
|
|
107
|
+
id = String(coupon.id);
|
|
108
|
+
if (coupons.has(id) && !equal(coupons.get(id), coupon))
|
|
109
|
+
throw new Stop("historical_coupon_conflict");
|
|
110
|
+
coupons.set(id, coupon);
|
|
111
|
+
}
|
|
112
|
+
const historical = {
|
|
113
|
+
schedule: receipt.providerSnapshot,
|
|
114
|
+
subscription: material.args.freshSubscription,
|
|
115
|
+
targetPrice: material.args.targetPrice,
|
|
116
|
+
billingCustomer: material.args.billingCustomer,
|
|
117
|
+
coupons: [...coupons.values()],
|
|
118
|
+
};
|
|
119
|
+
const proof = runStages(createContext(owned, historical, "baseline"));
|
|
120
|
+
if (
|
|
121
|
+
proof.predicate !== "configured_baseline_material_match" ||
|
|
122
|
+
typeof proof.proofTargetEnd !== "number" ||
|
|
123
|
+
!proof.proofStage
|
|
124
|
+
)
|
|
125
|
+
return {
|
|
126
|
+
...base,
|
|
127
|
+
predicate: proof.predicate === "conflict" ? "conflict" : "unknown",
|
|
128
|
+
reason: proof.reason ?? "configured_baseline_material_unproven",
|
|
129
|
+
};
|
|
130
|
+
evidence = {
|
|
131
|
+
targetEnd: proof.proofTargetEnd,
|
|
132
|
+
comparable: proof.comparableSchedule,
|
|
133
|
+
stage: proof.proofStage,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return result(
|
|
137
|
+
runStages(createContext(owned, captured.reads, "live", evidence)),
|
|
138
|
+
);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
return {
|
|
141
|
+
...base,
|
|
142
|
+
predicate: error instanceof Stop ? error.kind : "unknown",
|
|
143
|
+
reason:
|
|
144
|
+
error instanceof Stop
|
|
145
|
+
? error.reason
|
|
146
|
+
: "incomplete_or_unsupported_schema",
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { renewalSnapshot } from "../renewalReplacementSnapshot.js";
|
|
2
|
+
import { captureConfiguration } from "./configureInput.js";
|
|
3
|
+
import { captureConfigurationReceipt } from "./configureReceipt.js";
|
|
4
|
+
import type {
|
|
5
|
+
ProjectRenewalConfigurationV2Options,
|
|
6
|
+
ConstructRenewalConfigurationReceiptV2Options,
|
|
7
|
+
} from "./index.js";
|
|
8
|
+
export type RenewalScheduleMaterialReads = {
|
|
9
|
+
schedule: unknown;
|
|
10
|
+
subscription: unknown;
|
|
11
|
+
targetPrice: unknown;
|
|
12
|
+
billingCustomer: unknown;
|
|
13
|
+
coupons: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type InspectRenewalScheduleMaterialV2Options = {
|
|
16
|
+
configuration: ProjectRenewalConfigurationV2Options;
|
|
17
|
+
reads: RenewalScheduleMaterialReads;
|
|
18
|
+
configureReceipt?: ConstructRenewalConfigurationReceiptV2Options;
|
|
19
|
+
};
|
|
20
|
+
function stop(): never {
|
|
21
|
+
throw Error("Invalid raw renewal observation.");
|
|
22
|
+
}
|
|
23
|
+
function fields(
|
|
24
|
+
raw: unknown,
|
|
25
|
+
required: string[],
|
|
26
|
+
optional: string[] = [],
|
|
27
|
+
): Record<string, unknown> {
|
|
28
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) stop();
|
|
29
|
+
const p = Object.getPrototypeOf(raw);
|
|
30
|
+
if (p !== Object.prototype && p !== null) stop();
|
|
31
|
+
const keys = Reflect.ownKeys(raw);
|
|
32
|
+
if (
|
|
33
|
+
keys.some(
|
|
34
|
+
(k) => typeof k !== "string" || ![...required, ...optional].includes(k),
|
|
35
|
+
) ||
|
|
36
|
+
required.some((k) => !keys.includes(k))
|
|
37
|
+
)
|
|
38
|
+
stop();
|
|
39
|
+
return Object.fromEntries(
|
|
40
|
+
keys.map((k) => {
|
|
41
|
+
const d = Object.getOwnPropertyDescriptor(raw, k);
|
|
42
|
+
if (!d || !d.enumerable || !("value" in d)) stop();
|
|
43
|
+
return [k, d.value];
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
/** No getters, toJSON, symbols or hidden properties are stripped on this new raw API. */
|
|
48
|
+
function strictCopy(raw: unknown) {
|
|
49
|
+
let nodes = 0,
|
|
50
|
+
characters = 0;
|
|
51
|
+
const seen = new Set<object>();
|
|
52
|
+
function copy(x: unknown, depth: number): unknown {
|
|
53
|
+
if (++nodes > 10000 || depth > 40) stop();
|
|
54
|
+
if (typeof x === "string") {
|
|
55
|
+
characters += x.length;
|
|
56
|
+
if (characters > 500000) stop();
|
|
57
|
+
return x;
|
|
58
|
+
}
|
|
59
|
+
if (x === null || typeof x === "boolean") return x;
|
|
60
|
+
if (typeof x === "number" && Number.isFinite(x)) return x;
|
|
61
|
+
if (!x || typeof x !== "object" || seen.has(x)) stop();
|
|
62
|
+
const array = Array.isArray(x);
|
|
63
|
+
if (!array) {
|
|
64
|
+
const p = Object.getPrototypeOf(x);
|
|
65
|
+
if (p !== Object.prototype && p !== null) stop();
|
|
66
|
+
}
|
|
67
|
+
seen.add(x);
|
|
68
|
+
const keys = Reflect.ownKeys(x);
|
|
69
|
+
const entries: [string, unknown][] = [];
|
|
70
|
+
const selected = new Map<PropertyKey, unknown>();
|
|
71
|
+
let length = 0;
|
|
72
|
+
if (array) {
|
|
73
|
+
const d = Object.getOwnPropertyDescriptor(x, "length");
|
|
74
|
+
if (
|
|
75
|
+
!d ||
|
|
76
|
+
!("value" in d) ||
|
|
77
|
+
!Number.isSafeInteger(d.value) ||
|
|
78
|
+
d.value < 0 ||
|
|
79
|
+
d.value > 10000
|
|
80
|
+
)
|
|
81
|
+
stop();
|
|
82
|
+
length = d.value;
|
|
83
|
+
}
|
|
84
|
+
for (const k of keys) {
|
|
85
|
+
if (array && k === "length") continue;
|
|
86
|
+
if (typeof k !== "string") stop();
|
|
87
|
+
const d = Object.getOwnPropertyDescriptor(x, k);
|
|
88
|
+
if (!d || !d.enumerable || !("value" in d)) stop();
|
|
89
|
+
characters += k.length;
|
|
90
|
+
if (characters > 500000) stop();
|
|
91
|
+
if (array && (!/^(0|[1-9][0-9]*)$/.test(k) || Number(k) >= length))
|
|
92
|
+
stop();
|
|
93
|
+
selected.set(k, d.value);
|
|
94
|
+
entries.push([k, copy(d.value, depth + 1)]);
|
|
95
|
+
}
|
|
96
|
+
const after = Reflect.ownKeys(x);
|
|
97
|
+
if (after.length !== keys.length || after.some((k, i) => k !== keys[i]))
|
|
98
|
+
stop();
|
|
99
|
+
for (const [k, value] of selected) {
|
|
100
|
+
const d = Object.getOwnPropertyDescriptor(x, k);
|
|
101
|
+
if (!d || !d.enumerable || !("value" in d) || !Object.is(d.value, value))
|
|
102
|
+
stop();
|
|
103
|
+
}
|
|
104
|
+
seen.delete(x);
|
|
105
|
+
if (array) {
|
|
106
|
+
if (entries.length !== length) stop();
|
|
107
|
+
const map = new Map(entries);
|
|
108
|
+
return Array.from({ length }, (_, i) => {
|
|
109
|
+
if (!map.has(String(i))) stop();
|
|
110
|
+
return map.get(String(i));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return Object.fromEntries(entries);
|
|
114
|
+
}
|
|
115
|
+
return copy(raw, 0);
|
|
116
|
+
}
|
|
117
|
+
function capture(raw: unknown) {
|
|
118
|
+
const original = fields(
|
|
119
|
+
raw,
|
|
120
|
+
["configuration", "reads"],
|
|
121
|
+
["configureReceipt"],
|
|
122
|
+
);
|
|
123
|
+
const captured = renewalSnapshot(strictCopy(original));
|
|
124
|
+
const root = fields(
|
|
125
|
+
captured,
|
|
126
|
+
["configuration", "reads"],
|
|
127
|
+
["configureReceipt"],
|
|
128
|
+
);
|
|
129
|
+
if (new TextEncoder().encode(JSON.stringify(captured)).byteLength > 500000)
|
|
130
|
+
stop();
|
|
131
|
+
const configuration = captureConfiguration(root.configuration),
|
|
132
|
+
reads = fields(root.reads, [
|
|
133
|
+
"schedule",
|
|
134
|
+
"subscription",
|
|
135
|
+
"targetPrice",
|
|
136
|
+
"billingCustomer",
|
|
137
|
+
"coupons",
|
|
138
|
+
]);
|
|
139
|
+
for (const body of [
|
|
140
|
+
reads.schedule,
|
|
141
|
+
reads.subscription,
|
|
142
|
+
reads.targetPrice,
|
|
143
|
+
reads.billingCustomer,
|
|
144
|
+
...(Array.isArray(reads.coupons) ? reads.coupons : []),
|
|
145
|
+
])
|
|
146
|
+
if (
|
|
147
|
+
body &&
|
|
148
|
+
typeof body === "object" &&
|
|
149
|
+
Object.prototype.hasOwnProperty.call(body, "lastResponse")
|
|
150
|
+
)
|
|
151
|
+
stop();
|
|
152
|
+
const configureReceipt = Object.prototype.hasOwnProperty.call(
|
|
153
|
+
root,
|
|
154
|
+
"configureReceipt",
|
|
155
|
+
)
|
|
156
|
+
? captureConfigurationReceipt(root.configureReceipt)
|
|
157
|
+
: undefined;
|
|
158
|
+
return { configuration, reads, configureReceipt };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function captureObservation(raw: unknown) {
|
|
162
|
+
try {
|
|
163
|
+
return capture(raw);
|
|
164
|
+
} catch {
|
|
165
|
+
stop();
|
|
166
|
+
}
|
|
167
|
+
}
|
package/src/client/renewal.ts
CHANGED
|
@@ -16,6 +16,7 @@ export {
|
|
|
16
16
|
prepareRenewalScheduleAttachmentV2,
|
|
17
17
|
constructRenewalScheduleAttachmentReceiptV2,
|
|
18
18
|
projectRenewalConfigurationV2,
|
|
19
|
+
constructRenewalConfigurationReceiptV2,
|
|
19
20
|
} from "./billing/renewalV2/index.js";
|
|
20
21
|
export type {
|
|
21
22
|
PrepareRenewalPriceReplacementV2Options,
|
|
@@ -27,4 +28,13 @@ export type {
|
|
|
27
28
|
ProjectRenewalConfigurationV2Options,
|
|
28
29
|
ProjectedRenewalConfigurationV2,
|
|
29
30
|
RenewalConfigurationProjectionFailure,
|
|
31
|
+
ConstructRenewalConfigurationReceiptV2Options,
|
|
32
|
+
RenewalConfigurationReceiptV2,
|
|
30
33
|
} from "./billing/renewalV2/index.js";
|
|
34
|
+
|
|
35
|
+
export { inspectRenewalScheduleMaterialV2 } from "./billing/renewalV2/observation.js";
|
|
36
|
+
export type {
|
|
37
|
+
InspectRenewalScheduleMaterialV2Options,
|
|
38
|
+
RenewalScheduleMaterialReads,
|
|
39
|
+
RenewalScheduleMaterialObservationV2,
|
|
40
|
+
} from "./billing/renewalV2/observation.js";
|