@fantastic.dev/better-stripe 0.81.0 → 0.83.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/renewalAggregate/configure.d.ts +35 -0
- package/dist/client/billing/renewalAggregate/configure.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/configure.js +96 -0
- package/dist/client/billing/renewalAggregate/configure.js.map +1 -0
- package/dist/client/billing/renewalAggregate/index.d.ts +3 -0
- package/dist/client/billing/renewalAggregate/index.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/index.js +3 -0
- package/dist/client/billing/renewalAggregate/index.js.map +1 -0
- package/dist/client/billing/renewalAggregate/phaseContext.d.ts +176 -0
- package/dist/client/billing/renewalAggregate/phaseContext.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/phaseContext.js +112 -0
- package/dist/client/billing/renewalAggregate/phaseContext.js.map +1 -0
- package/dist/client/billing/renewalAggregate/phases.d.ts +7 -0
- package/dist/client/billing/renewalAggregate/phases.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/phases.js +192 -0
- package/dist/client/billing/renewalAggregate/phases.js.map +1 -0
- package/dist/client/billing/renewalAggregate/preflight.d.ts +594 -0
- package/dist/client/billing/renewalAggregate/preflight.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/preflight.js +164 -0
- package/dist/client/billing/renewalAggregate/preflight.js.map +1 -0
- package/dist/client/billing/renewalAggregate/profile.d.ts +8 -0
- package/dist/client/billing/renewalAggregate/profile.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/profile.js +60 -0
- package/dist/client/billing/renewalAggregate/profile.js.map +1 -0
- package/dist/client/billing/renewalAggregate/receipt.d.ts +40 -0
- package/dist/client/billing/renewalAggregate/receipt.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/receipt.js +62 -0
- package/dist/client/billing/renewalAggregate/receipt.js.map +1 -0
- package/dist/client/billing/renewalAggregate/shared.d.ts +51 -0
- package/dist/client/billing/renewalAggregate/shared.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/shared.js +87 -0
- package/dist/client/billing/renewalAggregate/shared.js.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.d.ts +42 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.js +90 -0
- package/dist/client/billing/renewalAggregate/sourceDiscounts.js.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.d.ts +136 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.js +82 -0
- package/dist/client/billing/renewalAggregate/sourceSettings.js.map +1 -0
- package/dist/client/billing/renewalAggregate/taxRetention.d.ts +8 -0
- package/dist/client/billing/renewalAggregate/taxRetention.d.ts.map +1 -0
- package/dist/client/billing/renewalAggregate/taxRetention.js +23 -0
- package/dist/client/billing/renewalAggregate/taxRetention.js.map +1 -0
- package/dist/client/billing/renewalAttach/couponJoins.d.ts +23 -0
- package/dist/client/billing/renewalAttach/couponJoins.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/couponJoins.js +76 -0
- package/dist/client/billing/renewalAttach/couponJoins.js.map +1 -0
- package/dist/client/billing/renewalAttach/index.d.ts +3 -0
- package/dist/client/billing/renewalAttach/index.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/index.js +3 -0
- package/dist/client/billing/renewalAttach/index.js.map +1 -0
- package/dist/client/billing/renewalAttach/reader.d.ts +141 -0
- package/dist/client/billing/renewalAttach/reader.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/reader.js +80 -0
- package/dist/client/billing/renewalAttach/reader.js.map +1 -0
- package/dist/client/billing/renewalAttach/request.d.ts +30 -0
- package/dist/client/billing/renewalAttach/request.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/request.js +39 -0
- package/dist/client/billing/renewalAttach/request.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- package/dist/client/index.d.ts +3 -5
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -3
- package/dist/client/index.js.map +1 -1
- package/dist/client/renewal.d.ts +8 -0
- package/dist/client/renewal.d.ts.map +1 -0
- package/dist/client/renewal.js +4 -0
- package/dist/client/renewal.js.map +1 -0
- package/dist/client/renewalContextClient.d.ts +130 -0
- package/dist/client/renewalContextClient.d.ts.map +1 -0
- package/dist/client/renewalContextClient.js +10 -0
- package/dist/client/renewalContextClient.js.map +1 -0
- 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 +43 -43
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/earnings/triggers.d.ts +16 -16
- package/docs/renewal-context-reads.md +113 -0
- package/docs/renewal-phase-assembly.md +180 -0
- package/docs/renewal-price-replacements.md +57 -16
- package/package.json +1 -1
- package/src/client/billing/renewalAggregate/configure.test.ts +372 -0
- package/src/client/billing/renewalAggregate/configure.ts +164 -0
- package/src/client/billing/renewalAggregate/index.ts +2 -0
- package/src/client/billing/renewalAggregate/phaseContext.ts +144 -0
- package/src/client/billing/renewalAggregate/phases.ts +247 -0
- package/src/client/billing/renewalAggregate/preflight.test.ts +233 -0
- package/src/client/billing/renewalAggregate/preflight.ts +211 -0
- package/src/client/billing/renewalAggregate/profile.ts +76 -0
- package/src/client/billing/renewalAggregate/receipt.ts +76 -0
- package/src/client/billing/renewalAggregate/shared.ts +106 -0
- package/src/client/billing/renewalAggregate/sourceAndTaxRetention.test.ts +247 -0
- package/src/client/billing/renewalAggregate/sourceDiscounts.ts +112 -0
- package/src/client/billing/renewalAggregate/sourceSettings.ts +88 -0
- package/src/client/billing/renewalAggregate/taxRetention.ts +28 -0
- package/src/client/billing/renewalAttach/couponEvidence.test.ts +104 -0
- package/src/client/billing/renewalAttach/couponJoins.ts +95 -0
- package/src/client/billing/renewalAttach/index.ts +9 -0
- package/src/client/billing/renewalAttach/reader.test.ts +409 -0
- package/src/client/billing/renewalAttach/reader.ts +131 -0
- package/src/client/billing/renewalAttach/request.ts +49 -0
- package/src/client/index.ts +3 -8
- package/src/client/renewal.ts +13 -0
- package/src/client/renewalContextClient.ts +23 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { settingsInput } from "../renewalProjection/settingsSchema.js";
|
|
2
|
+
import { projectRenewalPhaseSettings } from "../renewalProjection/settings.js";
|
|
3
|
+
import { projectRenewalItemSettings } from "../renewalProjection/itemSettings.js";
|
|
4
|
+
import { explicitTaxIds } from "./taxRetention.js";
|
|
5
|
+
import { unsupported } from "./shared.js";
|
|
6
|
+
|
|
7
|
+
const invoiceSchema = settingsInput.shape.settings.shape.invoice_settings
|
|
8
|
+
.unwrap()
|
|
9
|
+
.omit({ days_until_due: true })
|
|
10
|
+
.extend({
|
|
11
|
+
issuer: settingsInput.shape.context.shape.effectiveInvoiceIssuer,
|
|
12
|
+
})
|
|
13
|
+
.strict();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Classify actual original subscription/item fields before any attachment.
|
|
17
|
+
* The field projections below are validation views, not fabricated phase reads
|
|
18
|
+
* or provider acknowledgement. Their output is never dispatched or adopted.
|
|
19
|
+
*/
|
|
20
|
+
export function qualifyOriginalSettings(
|
|
21
|
+
subscription: Record<string, unknown>,
|
|
22
|
+
item: Record<string, unknown>,
|
|
23
|
+
customer: { id: string; customer_account: string; livemode: boolean },
|
|
24
|
+
) {
|
|
25
|
+
const invoice = invoiceSchema.safeParse(subscription.invoice_settings);
|
|
26
|
+
if (!invoice.success) unsupported("unsupported_original_invoice_settings");
|
|
27
|
+
const automaticTax = settingsInput.shape.settings.shape.automatic_tax
|
|
28
|
+
.unwrap()
|
|
29
|
+
.safeParse(subscription.automatic_tax);
|
|
30
|
+
if (!automaticTax.success) unsupported("unsupported_original_automatic_tax");
|
|
31
|
+
const parsedContext = settingsInput.shape.context.safeParse({
|
|
32
|
+
customerId: customer.id,
|
|
33
|
+
customerAccountId: customer.customer_account,
|
|
34
|
+
livemode: customer.livemode,
|
|
35
|
+
effectiveCollectionMethod: subscription.collection_method,
|
|
36
|
+
effectiveAutomaticTax: automaticTax.data.enabled,
|
|
37
|
+
effectiveInvoiceIssuer: invoice.data.issuer,
|
|
38
|
+
});
|
|
39
|
+
if (!parsedContext.success)
|
|
40
|
+
unsupported("unsupported_original_billing_context");
|
|
41
|
+
const context = parsedContext.data;
|
|
42
|
+
const taxLevels = {
|
|
43
|
+
subscription: explicitTaxIds(
|
|
44
|
+
subscription.default_tax_rates,
|
|
45
|
+
"original_subscription",
|
|
46
|
+
),
|
|
47
|
+
item: explicitTaxIds(item.tax_rates, "original_item"),
|
|
48
|
+
};
|
|
49
|
+
const projection = projectRenewalPhaseSettings({
|
|
50
|
+
context,
|
|
51
|
+
settings: {
|
|
52
|
+
application_fee_percent: subscription.application_fee_percent,
|
|
53
|
+
billing_thresholds: subscription.billing_thresholds,
|
|
54
|
+
collection_method: subscription.collection_method,
|
|
55
|
+
default_payment_method: subscription.default_payment_method,
|
|
56
|
+
on_behalf_of: subscription.on_behalf_of,
|
|
57
|
+
transfer_data: subscription.transfer_data,
|
|
58
|
+
automatic_tax: automaticTax.data,
|
|
59
|
+
default_tax_rates: subscription.default_tax_rates,
|
|
60
|
+
// days_until_due is a top-level Subscription field in Stripe 23.
|
|
61
|
+
invoice_settings: {
|
|
62
|
+
...invoice.data,
|
|
63
|
+
days_until_due: subscription.days_until_due,
|
|
64
|
+
},
|
|
65
|
+
description: subscription.description,
|
|
66
|
+
metadata: null,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
if (projection.status !== "projected")
|
|
70
|
+
unsupported(`unsupported_original_settings_${projection.reason}`);
|
|
71
|
+
const itemProjection = projectRenewalItemSettings({
|
|
72
|
+
effectiveAutomaticTax: context.effectiveAutomaticTax,
|
|
73
|
+
livemode: context.livemode,
|
|
74
|
+
settings: {
|
|
75
|
+
billing_thresholds: item.billing_thresholds,
|
|
76
|
+
tax_rates: item.tax_rates,
|
|
77
|
+
metadata: item.metadata,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
if (itemProjection.status !== "projected")
|
|
81
|
+
unsupported(`unsupported_original_${itemProjection.reason}`);
|
|
82
|
+
return {
|
|
83
|
+
context,
|
|
84
|
+
invoice: invoice.data,
|
|
85
|
+
automaticTax: automaticTax.data,
|
|
86
|
+
taxLevels,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { taxRate } from "../renewalProjection/settingsSchema.js";
|
|
3
|
+
import { equal, unsupported } from "./shared.js";
|
|
4
|
+
|
|
5
|
+
/** Null/absent read hierarchies are not evidence of an explicit empty list. */
|
|
6
|
+
export function explicitTaxIds(value: unknown, level: string): string[] {
|
|
7
|
+
const parsed = z.array(taxRate).max(20).safeParse(value);
|
|
8
|
+
if (!parsed.success) unsupported(`unproven_${level}_tax_hierarchy`);
|
|
9
|
+
return parsed.data.map((tax) => tax.id);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type OriginalTaxLevels = { subscription: string[]; item: string[] };
|
|
13
|
+
|
|
14
|
+
export function preserveTaxLevels(
|
|
15
|
+
original: OriginalTaxLevels,
|
|
16
|
+
phaseTax: unknown,
|
|
17
|
+
phaseItemTax: unknown,
|
|
18
|
+
) {
|
|
19
|
+
const phase = explicitTaxIds(phaseTax, "phase_default");
|
|
20
|
+
const item = explicitTaxIds(phaseItemTax, "phase_item");
|
|
21
|
+
if (!equal(original.subscription, phase))
|
|
22
|
+
unsupported("phase_default_tax_retention_mismatch");
|
|
23
|
+
// An empty item array means no item override. Its subscription/phase default
|
|
24
|
+
// applies instead. Equal current totals cannot authorize changing that level.
|
|
25
|
+
if (original.item.length > 0 !== item.length > 0)
|
|
26
|
+
unsupported("item_tax_override_level_changed");
|
|
27
|
+
if (!equal(original.item, item)) unsupported("item_tax_retention_mismatch");
|
|
28
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import Stripe from "stripe";
|
|
3
|
+
import { joinRenewalCoupons } from "./couponJoins.js";
|
|
4
|
+
const apiVersion = "2026-09-30.endive";
|
|
5
|
+
const baseline = {
|
|
6
|
+
id: "custom-offer",
|
|
7
|
+
object: "coupon",
|
|
8
|
+
livemode: false,
|
|
9
|
+
duration: "forever",
|
|
10
|
+
applies_to: { products: ["current", "target"] },
|
|
11
|
+
};
|
|
12
|
+
const expanded = (coupon: unknown, id = "di_original") => ({
|
|
13
|
+
discounts: [{ id, object: "discount", source: { type: "coupon", coupon } }],
|
|
14
|
+
});
|
|
15
|
+
function controlled(value: unknown) {
|
|
16
|
+
const calls: string[] = [];
|
|
17
|
+
const stripe = new Stripe("sk_test_SYNTHETIC", {
|
|
18
|
+
apiVersion,
|
|
19
|
+
maxNetworkRetries: 0,
|
|
20
|
+
httpClient: {
|
|
21
|
+
getClientName: () => "controlled-coupon-evidence",
|
|
22
|
+
async makeRequest(_host, _port, path, method) {
|
|
23
|
+
calls.push(`${method} ${path}`);
|
|
24
|
+
return {
|
|
25
|
+
getStatusCode: () => 200,
|
|
26
|
+
getHeaders: () => ({
|
|
27
|
+
"request-id": "req_synthetic",
|
|
28
|
+
"stripe-version": apiVersion,
|
|
29
|
+
}),
|
|
30
|
+
toJSON: async () => structuredClone(value),
|
|
31
|
+
getRawResponse: () => ({}),
|
|
32
|
+
toStream: () => null,
|
|
33
|
+
} as unknown as Stripe.HttpClientResponse;
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
calls,
|
|
39
|
+
join: (source: unknown, item: unknown = { discounts: [] }) =>
|
|
40
|
+
joinRenewalCoupons(
|
|
41
|
+
stripe,
|
|
42
|
+
source as Record<string, unknown>,
|
|
43
|
+
item as Record<string, unknown>,
|
|
44
|
+
false,
|
|
45
|
+
{ apiVersion, maxNetworkRetries: 0 },
|
|
46
|
+
),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
describe("expanded coupon full evidence equality", () => {
|
|
50
|
+
it.each([
|
|
51
|
+
["duration", { ...baseline, duration: "once" }, baseline],
|
|
52
|
+
[
|
|
53
|
+
"applicability",
|
|
54
|
+
{ ...baseline, applies_to: { products: ["current"] } },
|
|
55
|
+
baseline,
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
"original-only unknown fact",
|
|
59
|
+
{ ...baseline, unknown_provider_fact: { retained: "original" } },
|
|
60
|
+
baseline,
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
"minimal expanded reference",
|
|
64
|
+
{ id: baseline.id, object: "coupon" },
|
|
65
|
+
baseline,
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
"fresh-only unknown fact",
|
|
69
|
+
baseline,
|
|
70
|
+
{ ...baseline, unknown_provider_fact: "fresh" },
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
"ordered applicability",
|
|
74
|
+
{ ...baseline, applies_to: { products: ["target", "current"] } },
|
|
75
|
+
baseline,
|
|
76
|
+
],
|
|
77
|
+
])(
|
|
78
|
+
"rejects %s drift instead of replacing original facts",
|
|
79
|
+
async (_label, original, fetched) => {
|
|
80
|
+
const h = controlled(fetched);
|
|
81
|
+
await expect(h.join(expanded(original))).rejects.toThrow();
|
|
82
|
+
expect(h.calls).toEqual(["GET /v1/coupons/custom-offer"]);
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
it("retains full equal unknown facts and tolerates object-key order", async () => {
|
|
86
|
+
const extra = { nested: ["retained", 0] };
|
|
87
|
+
const original = { ...baseline, unknown_provider_fact: extra };
|
|
88
|
+
const fetched = { unknown_provider_fact: extra, ...baseline };
|
|
89
|
+
const h = controlled(fetched);
|
|
90
|
+
const result = await h.join(expanded(original));
|
|
91
|
+
expect(result.subscriptionDiscounts[0].source.coupon).toEqual(original);
|
|
92
|
+
expect(h.calls).toHaveLength(1);
|
|
93
|
+
});
|
|
94
|
+
it("checks every expanded reference even when the coupon GET is deduplicated", async () => {
|
|
95
|
+
const h = controlled(baseline);
|
|
96
|
+
await expect(
|
|
97
|
+
h.join(
|
|
98
|
+
expanded(baseline),
|
|
99
|
+
expanded({ ...baseline, duration: "once" }, "di_item"),
|
|
100
|
+
),
|
|
101
|
+
).rejects.toThrow();
|
|
102
|
+
expect(h.calls).toHaveLength(1);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type Stripe from "stripe";
|
|
3
|
+
import { equal, object, unsupported } from "../renewalAggregate/shared.js";
|
|
4
|
+
import { renewalSnapshot } from "../renewalReplacementSnapshot.js";
|
|
5
|
+
|
|
6
|
+
const id = z.string().min(1).max(255).regex(/\S/);
|
|
7
|
+
const discount = z
|
|
8
|
+
.object({
|
|
9
|
+
id: z.string().regex(/^di_[A-Za-z0-9_]+$/),
|
|
10
|
+
object: z.literal("discount"),
|
|
11
|
+
deleted: z.literal(false).optional(),
|
|
12
|
+
source: z
|
|
13
|
+
.object({
|
|
14
|
+
type: z.literal("coupon"),
|
|
15
|
+
coupon: z.union([
|
|
16
|
+
id,
|
|
17
|
+
z
|
|
18
|
+
.object({
|
|
19
|
+
id,
|
|
20
|
+
object: z.literal("coupon"),
|
|
21
|
+
deleted: z.literal(false).optional(),
|
|
22
|
+
})
|
|
23
|
+
.passthrough(),
|
|
24
|
+
]),
|
|
25
|
+
})
|
|
26
|
+
.passthrough(),
|
|
27
|
+
})
|
|
28
|
+
.passthrough();
|
|
29
|
+
/** Explicit bounded joins, never a fallback for failed or over-depth expansion. */
|
|
30
|
+
export async function joinRenewalCoupons(
|
|
31
|
+
stripe: Stripe,
|
|
32
|
+
subscription: Record<string, unknown>,
|
|
33
|
+
item: Record<string, unknown>,
|
|
34
|
+
livemode: boolean,
|
|
35
|
+
options: Stripe.RequestOptions,
|
|
36
|
+
) {
|
|
37
|
+
const lists = [subscription.discounts, item.discounts].map((value) => {
|
|
38
|
+
const parsed = z.array(discount).max(20).safeParse(value);
|
|
39
|
+
if (!parsed.success)
|
|
40
|
+
unsupported("incomplete_or_unsupported_discount_evidence");
|
|
41
|
+
return parsed.data;
|
|
42
|
+
});
|
|
43
|
+
for (const list of lists)
|
|
44
|
+
for (const redemption of list) {
|
|
45
|
+
const ref = redemption.source.coupon;
|
|
46
|
+
if (
|
|
47
|
+
typeof ref !== "string" &&
|
|
48
|
+
ref.livemode !== undefined &&
|
|
49
|
+
ref.livemode !== livemode
|
|
50
|
+
)
|
|
51
|
+
unsupported("expanded_coupon_mode_mismatch");
|
|
52
|
+
}
|
|
53
|
+
const coupons = new Map<string, Record<string, unknown>>();
|
|
54
|
+
for (const list of lists)
|
|
55
|
+
for (const redemption of list) {
|
|
56
|
+
const couponId =
|
|
57
|
+
typeof redemption.source.coupon === "string"
|
|
58
|
+
? redemption.source.coupon
|
|
59
|
+
: redemption.source.coupon.id;
|
|
60
|
+
let coupon = coupons.get(couponId);
|
|
61
|
+
if (!coupon) {
|
|
62
|
+
coupon = object(
|
|
63
|
+
renewalSnapshot(await stripe.coupons.retrieve(couponId, {}, options)),
|
|
64
|
+
);
|
|
65
|
+
if (
|
|
66
|
+
coupon.id !== couponId ||
|
|
67
|
+
coupon.object !== "coupon" ||
|
|
68
|
+
coupon.deleted === true ||
|
|
69
|
+
(coupon.livemode !== undefined && coupon.livemode !== livemode)
|
|
70
|
+
)
|
|
71
|
+
unsupported("coupon_join_identity_mismatch");
|
|
72
|
+
coupons.set(couponId, coupon);
|
|
73
|
+
}
|
|
74
|
+
// A join may expand a string reference, but must never replace facts
|
|
75
|
+
// already present in a full read. Shape drift is conservatively rejected.
|
|
76
|
+
if (
|
|
77
|
+
typeof redemption.source.coupon !== "string" &&
|
|
78
|
+
!equal(redemption.source.coupon, coupon)
|
|
79
|
+
)
|
|
80
|
+
unsupported("expanded_coupon_read_drift");
|
|
81
|
+
}
|
|
82
|
+
const joined = lists.map((list) =>
|
|
83
|
+
list.map((redemption) => {
|
|
84
|
+
const couponId =
|
|
85
|
+
typeof redemption.source.coupon === "string"
|
|
86
|
+
? redemption.source.coupon
|
|
87
|
+
: redemption.source.coupon.id;
|
|
88
|
+
return {
|
|
89
|
+
...redemption,
|
|
90
|
+
source: { ...redemption.source, coupon: coupons.get(couponId)! },
|
|
91
|
+
};
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
return { subscriptionDiscounts: joined[0], itemDiscounts: joined[1] };
|
|
95
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export {
|
|
2
|
+
readRenewalPriceReplacementContext,
|
|
3
|
+
type ReadRenewalPriceReplacementContextOptions,
|
|
4
|
+
} from "./reader.js";
|
|
5
|
+
export {
|
|
6
|
+
prepareRenewalScheduleAttachment,
|
|
7
|
+
type PrepareRenewalScheduleAttachmentOptions,
|
|
8
|
+
type PreparedRenewalScheduleAttachment,
|
|
9
|
+
} from "./request.js";
|