@fantastic.dev/better-stripe 0.81.0 → 0.82.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAggregate/configure.d.ts +35 -0
  4. package/dist/client/billing/renewalAggregate/configure.d.ts.map +1 -0
  5. package/dist/client/billing/renewalAggregate/configure.js +96 -0
  6. package/dist/client/billing/renewalAggregate/configure.js.map +1 -0
  7. package/dist/client/billing/renewalAggregate/index.d.ts +3 -0
  8. package/dist/client/billing/renewalAggregate/index.d.ts.map +1 -0
  9. package/dist/client/billing/renewalAggregate/index.js +3 -0
  10. package/dist/client/billing/renewalAggregate/index.js.map +1 -0
  11. package/dist/client/billing/renewalAggregate/phaseContext.d.ts +176 -0
  12. package/dist/client/billing/renewalAggregate/phaseContext.d.ts.map +1 -0
  13. package/dist/client/billing/renewalAggregate/phaseContext.js +112 -0
  14. package/dist/client/billing/renewalAggregate/phaseContext.js.map +1 -0
  15. package/dist/client/billing/renewalAggregate/phases.d.ts +7 -0
  16. package/dist/client/billing/renewalAggregate/phases.d.ts.map +1 -0
  17. package/dist/client/billing/renewalAggregate/phases.js +192 -0
  18. package/dist/client/billing/renewalAggregate/phases.js.map +1 -0
  19. package/dist/client/billing/renewalAggregate/preflight.d.ts +594 -0
  20. package/dist/client/billing/renewalAggregate/preflight.d.ts.map +1 -0
  21. package/dist/client/billing/renewalAggregate/preflight.js +164 -0
  22. package/dist/client/billing/renewalAggregate/preflight.js.map +1 -0
  23. package/dist/client/billing/renewalAggregate/profile.d.ts +8 -0
  24. package/dist/client/billing/renewalAggregate/profile.d.ts.map +1 -0
  25. package/dist/client/billing/renewalAggregate/profile.js +60 -0
  26. package/dist/client/billing/renewalAggregate/profile.js.map +1 -0
  27. package/dist/client/billing/renewalAggregate/receipt.d.ts +40 -0
  28. package/dist/client/billing/renewalAggregate/receipt.d.ts.map +1 -0
  29. package/dist/client/billing/renewalAggregate/receipt.js +62 -0
  30. package/dist/client/billing/renewalAggregate/receipt.js.map +1 -0
  31. package/dist/client/billing/renewalAggregate/shared.d.ts +51 -0
  32. package/dist/client/billing/renewalAggregate/shared.d.ts.map +1 -0
  33. package/dist/client/billing/renewalAggregate/shared.js +87 -0
  34. package/dist/client/billing/renewalAggregate/shared.js.map +1 -0
  35. package/dist/client/billing/renewalAggregate/sourceDiscounts.d.ts +42 -0
  36. package/dist/client/billing/renewalAggregate/sourceDiscounts.d.ts.map +1 -0
  37. package/dist/client/billing/renewalAggregate/sourceDiscounts.js +90 -0
  38. package/dist/client/billing/renewalAggregate/sourceDiscounts.js.map +1 -0
  39. package/dist/client/billing/renewalAggregate/sourceSettings.d.ts +136 -0
  40. package/dist/client/billing/renewalAggregate/sourceSettings.d.ts.map +1 -0
  41. package/dist/client/billing/renewalAggregate/sourceSettings.js +82 -0
  42. package/dist/client/billing/renewalAggregate/sourceSettings.js.map +1 -0
  43. package/dist/client/billing/renewalAggregate/taxRetention.d.ts +8 -0
  44. package/dist/client/billing/renewalAggregate/taxRetention.d.ts.map +1 -0
  45. package/dist/client/billing/renewalAggregate/taxRetention.js +23 -0
  46. package/dist/client/billing/renewalAggregate/taxRetention.js.map +1 -0
  47. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  48. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
  49. package/dist/component/balanceFunding/mutations.d.ts +43 -43
  50. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  51. package/dist/component/payoutRelease/queries.d.ts +2 -2
  52. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  53. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  54. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  55. package/docs/renewal-phase-assembly.md +180 -0
  56. package/docs/renewal-price-replacements.md +2 -0
  57. package/package.json +1 -1
  58. package/src/client/billing/renewalAggregate/configure.test.ts +372 -0
  59. package/src/client/billing/renewalAggregate/configure.ts +164 -0
  60. package/src/client/billing/renewalAggregate/index.ts +2 -0
  61. package/src/client/billing/renewalAggregate/phaseContext.ts +144 -0
  62. package/src/client/billing/renewalAggregate/phases.ts +247 -0
  63. package/src/client/billing/renewalAggregate/preflight.test.ts +233 -0
  64. package/src/client/billing/renewalAggregate/preflight.ts +211 -0
  65. package/src/client/billing/renewalAggregate/profile.ts +76 -0
  66. package/src/client/billing/renewalAggregate/receipt.ts +76 -0
  67. package/src/client/billing/renewalAggregate/shared.ts +106 -0
  68. package/src/client/billing/renewalAggregate/sourceAndTaxRetention.test.ts +247 -0
  69. package/src/client/billing/renewalAggregate/sourceDiscounts.ts +112 -0
  70. package/src/client/billing/renewalAggregate/sourceSettings.ts +88 -0
  71. package/src/client/billing/renewalAggregate/taxRetention.ts +28 -0
@@ -0,0 +1,90 @@
1
+ import { z } from "zod";
2
+ import { resourceId, unsupported } from "./shared.js";
3
+ const customId = z.string().min(1).max(255).regex(/\S/);
4
+ const originalRedemptions = z
5
+ .array(z
6
+ .object({
7
+ id: resourceId("di"),
8
+ object: z.literal("discount"),
9
+ deleted: z.literal(false).optional(),
10
+ customer_account: resourceId("acct"),
11
+ customer: z
12
+ .union([
13
+ resourceId("cus"),
14
+ z
15
+ .object({
16
+ id: resourceId("cus"),
17
+ object: z.literal("customer"),
18
+ deleted: z.literal(false).optional(),
19
+ livemode: z.boolean().optional(),
20
+ customer_account: resourceId("acct").nullable().optional(),
21
+ })
22
+ .passthrough(),
23
+ ])
24
+ .nullable()
25
+ .optional(),
26
+ subscription: resourceId("sub").nullable(),
27
+ subscription_item: resourceId("si").nullable(),
28
+ start: z.number().int().nonnegative(),
29
+ end: z.null(),
30
+ source: z
31
+ .object({
32
+ type: z.literal("coupon"),
33
+ coupon: z
34
+ .object({
35
+ id: customId,
36
+ object: z.literal("coupon"),
37
+ deleted: z.literal(false).optional(),
38
+ livemode: z.boolean().optional(),
39
+ duration: z.literal("forever"),
40
+ applies_to: z
41
+ .object({ products: z.array(customId) })
42
+ .strict()
43
+ .optional(),
44
+ })
45
+ .passthrough(),
46
+ })
47
+ .passthrough(),
48
+ })
49
+ .passthrough())
50
+ .max(20);
51
+ export function qualifySourceDiscounts(value, level, context, customerId, observedAt) {
52
+ const parsed = originalRedemptions.safeParse(value);
53
+ if (!parsed.success)
54
+ unsupported("incomplete_or_unsupported_discount_evidence");
55
+ if (!parsed.data.length)
56
+ unsupported("ambiguous_empty_discount_hierarchy");
57
+ if (new Set(parsed.data.map((discount) => discount.id)).size !==
58
+ parsed.data.length)
59
+ unsupported("duplicate_discount_redemptions");
60
+ for (const discount of parsed.data) {
61
+ const customer = discount.customer;
62
+ if (discount.customer_account !== context.customerAccountId ||
63
+ discount.start > observedAt ||
64
+ (typeof customer === "string" && customer !== customerId) ||
65
+ (typeof customer === "object" &&
66
+ customer !== null &&
67
+ (customer.id !== customerId ||
68
+ (customer.livemode !== undefined &&
69
+ customer.livemode !== context.livemode) ||
70
+ (customer.customer_account !== undefined &&
71
+ customer.customer_account !== context.customerAccountId))) ||
72
+ (level === "subscription" &&
73
+ (discount.subscription !== context.subscriptionId ||
74
+ discount.subscription_item !== null)) ||
75
+ (level === "item" &&
76
+ (discount.subscription_item !== context.itemId ||
77
+ (discount.subscription !== null &&
78
+ discount.subscription !== context.subscriptionId))))
79
+ unsupported("discount_owner_or_start_mismatch");
80
+ const coupon = discount.source.coupon;
81
+ if (coupon.livemode !== undefined && coupon.livemode !== context.livemode)
82
+ unsupported("discount_coupon_mode_mismatch");
83
+ if (coupon.applies_to &&
84
+ (!coupon.applies_to.products.includes(context.currentProductId) ||
85
+ !coupon.applies_to.products.includes(context.targetProductId)))
86
+ unsupported("discount_product_applicability");
87
+ }
88
+ return parsed.data;
89
+ }
90
+ //# sourceMappingURL=sourceDiscounts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sourceDiscounts.js","sourceRoot":"","sources":["../../../../src/client/billing/renewalAggregate/sourceDiscounts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+BAA+B,CAAC,CAAC;QAC/C,IACE,MAAM,CAAC,UAAU;YACjB,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC;gBAC7D,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;YAEhE,WAAW,CAAC,gCAAgC,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Classify actual original subscription/item fields before any attachment.
3
+ * The field projections below are validation views, not fabricated phase reads
4
+ * or provider acknowledgement. Their output is never dispatched or adopted.
5
+ */
6
+ export declare function qualifyOriginalSettings(subscription: Record<string, unknown>, item: Record<string, unknown>, customer: {
7
+ id: string;
8
+ customer_account: string;
9
+ livemode: boolean;
10
+ }): {
11
+ context: {
12
+ customerAccountId: string;
13
+ customerId: string;
14
+ livemode: boolean;
15
+ effectiveCollectionMethod: "charge_automatically" | "send_invoice";
16
+ effectiveAutomaticTax: boolean;
17
+ effectiveInvoiceIssuer: {
18
+ type: "self";
19
+ account?: null | undefined;
20
+ } | {
21
+ type: "account";
22
+ account: string | {
23
+ [x: string]: unknown;
24
+ id: string;
25
+ object: string;
26
+ deleted?: false | undefined;
27
+ livemode?: boolean | undefined;
28
+ customer?: string | {
29
+ [x: string]: unknown;
30
+ id: string;
31
+ object: "customer";
32
+ deleted?: false | undefined;
33
+ livemode?: boolean | undefined;
34
+ customer_account?: string | null | undefined;
35
+ } | null | undefined;
36
+ customer_account?: string | null | undefined;
37
+ };
38
+ };
39
+ };
40
+ invoice: {
41
+ account_tax_ids: (string | {
42
+ [x: string]: unknown;
43
+ id: string;
44
+ object: "tax_id";
45
+ deleted?: false | undefined;
46
+ livemode: boolean;
47
+ customer?: null | undefined;
48
+ customer_account?: null | undefined;
49
+ owner: {
50
+ type: "self";
51
+ customer_account: null;
52
+ account?: null | undefined;
53
+ customer?: null | undefined;
54
+ } | {
55
+ type: "account";
56
+ account: string | {
57
+ [x: string]: unknown;
58
+ id: string;
59
+ object: string;
60
+ deleted?: false | undefined;
61
+ livemode?: boolean | undefined;
62
+ customer?: string | {
63
+ [x: string]: unknown;
64
+ id: string;
65
+ object: "customer";
66
+ deleted?: false | undefined;
67
+ livemode?: boolean | undefined;
68
+ customer_account?: string | null | undefined;
69
+ } | null | undefined;
70
+ customer_account?: string | null | undefined;
71
+ };
72
+ customer_account: null;
73
+ customer?: null | undefined;
74
+ };
75
+ })[] | null;
76
+ custom_fields: {
77
+ name: string;
78
+ value: string;
79
+ }[] | null;
80
+ description: string | null;
81
+ footer: string | null;
82
+ issuer: {
83
+ type: "self";
84
+ account?: null | undefined;
85
+ } | {
86
+ type: "account";
87
+ account: string | {
88
+ [x: string]: unknown;
89
+ id: string;
90
+ object: string;
91
+ deleted?: false | undefined;
92
+ livemode?: boolean | undefined;
93
+ customer?: string | {
94
+ [x: string]: unknown;
95
+ id: string;
96
+ object: "customer";
97
+ deleted?: false | undefined;
98
+ livemode?: boolean | undefined;
99
+ customer_account?: string | null | undefined;
100
+ } | null | undefined;
101
+ customer_account?: string | null | undefined;
102
+ };
103
+ };
104
+ };
105
+ automaticTax: {
106
+ enabled: boolean;
107
+ liability?: {
108
+ type: "self";
109
+ account?: null | undefined;
110
+ } | {
111
+ type: "account";
112
+ account: string | {
113
+ [x: string]: unknown;
114
+ id: string;
115
+ object: string;
116
+ deleted?: false | undefined;
117
+ livemode?: boolean | undefined;
118
+ customer?: string | {
119
+ [x: string]: unknown;
120
+ id: string;
121
+ object: "customer";
122
+ deleted?: false | undefined;
123
+ livemode?: boolean | undefined;
124
+ customer_account?: string | null | undefined;
125
+ } | null | undefined;
126
+ customer_account?: string | null | undefined;
127
+ };
128
+ } | null | undefined;
129
+ disabled_reason?: null | undefined;
130
+ };
131
+ taxLevels: {
132
+ subscription: string[];
133
+ item: string[];
134
+ };
135
+ };
136
+ //# sourceMappingURL=sourceSettings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sourceSettings.d.ts","sourceRoot":"","sources":["../../../../src/client/billing/renewalAggregate/sourceSettings.ts"],"names":[],"mappings":"AAcA;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,QAAQ,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiEtE"}
@@ -0,0 +1,82 @@
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
+ const invoiceSchema = settingsInput.shape.settings.shape.invoice_settings
7
+ .unwrap()
8
+ .omit({ days_until_due: true })
9
+ .extend({
10
+ issuer: settingsInput.shape.context.shape.effectiveInvoiceIssuer,
11
+ })
12
+ .strict();
13
+ /**
14
+ * Classify actual original subscription/item fields before any attachment.
15
+ * The field projections below are validation views, not fabricated phase reads
16
+ * or provider acknowledgement. Their output is never dispatched or adopted.
17
+ */
18
+ export function qualifyOriginalSettings(subscription, item, customer) {
19
+ const invoice = invoiceSchema.safeParse(subscription.invoice_settings);
20
+ if (!invoice.success)
21
+ unsupported("unsupported_original_invoice_settings");
22
+ const automaticTax = settingsInput.shape.settings.shape.automatic_tax
23
+ .unwrap()
24
+ .safeParse(subscription.automatic_tax);
25
+ if (!automaticTax.success)
26
+ unsupported("unsupported_original_automatic_tax");
27
+ const parsedContext = settingsInput.shape.context.safeParse({
28
+ customerId: customer.id,
29
+ customerAccountId: customer.customer_account,
30
+ livemode: customer.livemode,
31
+ effectiveCollectionMethod: subscription.collection_method,
32
+ effectiveAutomaticTax: automaticTax.data.enabled,
33
+ effectiveInvoiceIssuer: invoice.data.issuer,
34
+ });
35
+ if (!parsedContext.success)
36
+ unsupported("unsupported_original_billing_context");
37
+ const context = parsedContext.data;
38
+ const taxLevels = {
39
+ subscription: explicitTaxIds(subscription.default_tax_rates, "original_subscription"),
40
+ item: explicitTaxIds(item.tax_rates, "original_item"),
41
+ };
42
+ const projection = projectRenewalPhaseSettings({
43
+ context,
44
+ settings: {
45
+ application_fee_percent: subscription.application_fee_percent,
46
+ billing_thresholds: subscription.billing_thresholds,
47
+ collection_method: subscription.collection_method,
48
+ default_payment_method: subscription.default_payment_method,
49
+ on_behalf_of: subscription.on_behalf_of,
50
+ transfer_data: subscription.transfer_data,
51
+ automatic_tax: automaticTax.data,
52
+ default_tax_rates: subscription.default_tax_rates,
53
+ // days_until_due is a top-level Subscription field in Stripe 23.
54
+ invoice_settings: {
55
+ ...invoice.data,
56
+ days_until_due: subscription.days_until_due,
57
+ },
58
+ description: subscription.description,
59
+ metadata: null,
60
+ },
61
+ });
62
+ if (projection.status !== "projected")
63
+ unsupported(`unsupported_original_settings_${projection.reason}`);
64
+ const itemProjection = projectRenewalItemSettings({
65
+ effectiveAutomaticTax: context.effectiveAutomaticTax,
66
+ livemode: context.livemode,
67
+ settings: {
68
+ billing_thresholds: item.billing_thresholds,
69
+ tax_rates: item.tax_rates,
70
+ metadata: item.metadata,
71
+ },
72
+ });
73
+ if (itemProjection.status !== "projected")
74
+ unsupported(`unsupported_original_${itemProjection.reason}`);
75
+ return {
76
+ context,
77
+ invoice: invoice.data,
78
+ automaticTax: automaticTax.data,
79
+ taxLevels,
80
+ };
81
+ }
82
+ //# sourceMappingURL=sourceSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sourceSettings.js","sourceRoot":"","sources":["../../../../src/client/billing/renewalAggregate/sourceSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,aAAa,GAAG,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,gBAAgB;KACtE,MAAM,EAAE;KACR,IAAI,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC;KAC9B,MAAM,CAAC;IACN,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,sBAAsB;CACjE,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACrC,YAAqC,EACrC,IAA6B,EAC7B,QAAqE;IAErE,MAAM,OAAO,GAAG,aAAa,CAAC,SAAS,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;IACvE,IAAI,CAAC,OAAO,CAAC,OAAO;QAAE,WAAW,CAAC,uCAAuC,CAAC,CAAC;IAC3E,MAAM,YAAY,GAAG,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,aAAa;SAClE,MAAM,EAAE;SACR,SAAS,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;IACzC,IAAI,CAAC,YAAY,CAAC,OAAO;QAAE,WAAW,CAAC,oCAAoC,CAAC,CAAC;IAC7E,MAAM,aAAa,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;QAC1D,UAAU,EAAE,QAAQ,C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pE,MAAM,cAAc,GAAG,0BAA0B,CAAC;QAChD,qBAAqB,EAAE,OAAO,CAAC,qBAAqB;QACpD,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,QAAQ,EAAE;YACR,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB;KACF,CAAC,CAAC;IACH,IAAI,cAAc,CAAC,MAAM,KAAK,WAAW;QACvC,WAAW,CAAC,wBAAwB,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/D,OAAO;QACL,OAAO;QACP,OAAO,EAAE,OAAO,CAAC,IAAI;QACrB,YAAY,EAAE,YAAY,CAAC,IAAI;QAC/B,SAAS;KACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ /** Null/absent read hierarchies are not evidence of an explicit empty list. */
2
+ export declare function explicitTaxIds(value: unknown, level: string): string[];
3
+ export type OriginalTaxLevels = {
4
+ subscription: string[];
5
+ item: string[];
6
+ };
7
+ export declare function preserveTaxLevels(original: OriginalTaxLevels, phaseTax: unknown, phaseItemTax: unknown): void;
8
+ //# sourceMappingURL=taxRetention.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taxRetention.d.ts","sourceRoot":"","sources":["../../../../src/client/billing/renewalAggregate/taxRetention.ts"],"names":[],"mappings":"AAIA,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAItE;AAED,MAAM,MAAM,iBAAiB,GAAG;IAAE,YAAY,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAE3E,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,OAAO,EACjB,YAAY,EAAE,OAAO,QAWtB"}
@@ -0,0 +1,23 @@
1
+ import { z } from "zod";
2
+ import { taxRate } from "../renewalProjection/settingsSchema.js";
3
+ import { equal, unsupported } from "./shared.js";
4
+ /** Null/absent read hierarchies are not evidence of an explicit empty list. */
5
+ export function explicitTaxIds(value, level) {
6
+ const parsed = z.array(taxRate).max(20).safeParse(value);
7
+ if (!parsed.success)
8
+ unsupported(`unproven_${level}_tax_hierarchy`);
9
+ return parsed.data.map((tax) => tax.id);
10
+ }
11
+ export function preserveTaxLevels(original, phaseTax, phaseItemTax) {
12
+ const phase = explicitTaxIds(phaseTax, "phase_default");
13
+ const item = explicitTaxIds(phaseItemTax, "phase_item");
14
+ if (!equal(original.subscription, phase))
15
+ unsupported("phase_default_tax_retention_mismatch");
16
+ // An empty item array means no item override. Its subscription/phase default
17
+ // applies instead. Equal current totals cannot authorize changing that level.
18
+ if (original.item.length > 0 !== item.length > 0)
19
+ unsupported("item_tax_override_level_changed");
20
+ if (!equal(original.item, item))
21
+ unsupported("item_tax_retention_mismatch");
22
+ }
23
+ //# sourceMappingURL=taxRetention.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taxRetention.js","sourceRoot":"","sources":["../../../../src/client/billing/renewalAggregate/taxRetention.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEjD,+EAA+E;AAC/E,MAAM,UAAU,cAAc,CAAC,KAAc,EAAE,KAAa;IAC1D,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACzD,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,WAAW,CAAC,YAAY,KAAK,gBAAgB,CAAC,CAAC;IACpE,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC1C,CAAC;AAID,MAAM,UAAU,iBAAiB,CAC/B,QAA2B,EAC3B,QAAiB,EACjB,YAAqB;IAErB,MAAM,KAAK,GAAG,cAAc,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,cAAc,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IACxD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC;QACtC,WAAW,CAAC,sCAAsC,CAAC,CAAC;IACtD,6EAA6E;IAC7E,8EAA8E;IAC9E,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC;QAC9C,WAAW,CAAC,iCAAiC,CAAC,CAAC;IACjD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;QAAE,WAAW,CAAC,6BAA6B,CAAC,CAAC;AAC9E,CAAC"}
@@ -2360,14 +2360,6 @@ export declare function setup(amounts?: number[], currency?: string): Promise<{
2360
2360
  preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
2361
2361
  requestKey: string;
2362
2362
  result?: {
2363
- reason: "identity_changed" | "revision_changed" | "scope_busy";
2364
- retryable: false;
2365
- status: "conflict";
2366
- } | {
2367
- reason: "policy_invalid";
2368
- retryable: false;
2369
- status: "rejected";
2370
- } | {
2371
2363
  operation: {
2372
2364
  accountId: string;
2373
2365
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2378,6 +2370,14 @@ export declare function setup(amounts?: number[], currency?: string): Promise<{
2378
2370
  } | {
2379
2371
  enabled: boolean;
2380
2372
  status: "unchanged";
2373
+ } | {
2374
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
2375
+ retryable: false;
2376
+ status: "conflict";
2377
+ } | {
2378
+ reason: "policy_invalid";
2379
+ retryable: false;
2380
+ status: "rejected";
2381
2381
  } | {
2382
2382
  reason: "provider_pending";
2383
2383
  retryable: true;
@@ -2388,14 +2388,6 @@ export declare function setup(amounts?: number[], currency?: string): Promise<{
2388
2388
  payload: import("convex/values").VString<string, "required">;
2389
2389
  preparationId: import("convex/values").VId<import("convex/values").GenericId<"balanceFundingPreparations">, "required">;
2390
2390
  result: import("convex/values").VUnion<{
2391
- reason: "identity_changed" | "revision_changed" | "scope_busy";
2392
- retryable: false;
2393
- status: "conflict";
2394
- } | {
2395
- reason: "policy_invalid";
2396
- retryable: false;
2397
- status: "rejected";
2398
- } | {
2399
2391
  operation: {
2400
2392
  accountId: string;
2401
2393
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2406,6 +2398,14 @@ export declare function setup(amounts?: number[], currency?: string): Promise<{
2406
2398
  } | {
2407
2399
  enabled: boolean;
2408
2400
  status: "unchanged";
2401
+ } | {
2402
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
2403
+ retryable: false;
2404
+ status: "conflict";
2405
+ } | {
2406
+ reason: "policy_invalid";
2407
+ retryable: false;
2408
+ status: "rejected";
2409
2409
  } | {
2410
2410
  reason: "provider_pending";
2411
2411
  retryable: true;
@@ -7215,14 +7215,6 @@ export declare function historical(currency?: string): Promise<{
7215
7215
  preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
7216
7216
  requestKey: string;
7217
7217
  result?: {
7218
- reason: "identity_changed" | "revision_changed" | "scope_busy";
7219
- retryable: false;
7220
- status: "conflict";
7221
- } | {
7222
- reason: "policy_invalid";
7223
- retryable: false;
7224
- status: "rejected";
7225
- } | {
7226
7218
  operation: {
7227
7219
  accountId: string;
7228
7220
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -7233,6 +7225,14 @@ export declare function historical(currency?: string): Promise<{
7233
7225
  } | {
7234
7226
  enabled: boolean;
7235
7227
  status: "unchanged";
7228
+ } | {
7229
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
7230
+ retryable: false;
7231
+ status: "conflict";
7232
+ } | {
7233
+ reason: "policy_invalid";
7234
+ retryable: false;
7235
+ status: "rejected";
7236
7236
  } | {
7237
7237
  reason: "provider_pending";
7238
7238
  retryable: true;
@@ -7243,14 +7243,6 @@ export declare function historical(currency?: string): Promise<{
7243
7243
  payload: import("convex/values").VString<string, "required">;
7244
7244
  preparationId: import("convex/values").VId<import("convex/values").GenericId<"balanceFundingPreparations">, "required">;
7245
7245
  result: import("convex/values").VUnion<{
7246
- reason: "identity_changed" | "revision_changed" | "scope_busy";
7247
- retryable: false;
7248
- status: "conflict";
7249
- } | {
7250
- reason: "policy_invalid";
7251
- retryable: false;
7252
- status: "rejected";
7253
- } | {
7254
7246
  operation: {
7255
7247
  accountId: string;
7256
7248
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -7261,6 +7253,14 @@ export declare function historical(currency?: string): Promise<{
7261
7253
  } | {
7262
7254
  enabled: boolean;
7263
7255
  status: "unchanged";
7256
+ } | {
7257
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
7258
+ retryable: false;
7259
+ status: "conflict";
7260
+ } | {
7261
+ reason: "policy_invalid";
7262
+ retryable: false;
7263
+ status: "rejected";
7264
7264
  } | {
7265
7265
  reason: "provider_pending";
7266
7266
  retryable: true;
@@ -2361,6 +2361,14 @@ export declare function setup(amounts?: number[]): Promise<{
2361
2361
  preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
2362
2362
  requestKey: string;
2363
2363
  result?: {
2364
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
2365
+ retryable: false;
2366
+ status: "conflict";
2367
+ } | {
2368
+ reason: "policy_invalid";
2369
+ retryable: false;
2370
+ status: "rejected";
2371
+ } | {
2364
2372
  operation: {
2365
2373
  accountId: string;
2366
2374
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2371,14 +2379,6 @@ export declare function setup(amounts?: number[]): Promise<{
2371
2379
  } | {
2372
2380
  enabled: boolean;
2373
2381
  status: "unchanged";
2374
- } | {
2375
- reason: "identity_changed" | "revision_changed" | "scope_busy";
2376
- retryable: false;
2377
- status: "conflict";
2378
- } | {
2379
- reason: "policy_invalid";
2380
- retryable: false;
2381
- status: "rejected";
2382
2382
  } | {
2383
2383
  reason: "provider_pending";
2384
2384
  retryable: true;
@@ -2389,6 +2389,14 @@ export declare function setup(amounts?: number[]): Promise<{
2389
2389
  payload: import("convex/values").VString<string, "required">;
2390
2390
  preparationId: import("convex/values").VId<import("convex/values").GenericId<"balanceFundingPreparations">, "required">;
2391
2391
  result: import("convex/values").VUnion<{
2392
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
2393
+ retryable: false;
2394
+ status: "conflict";
2395
+ } | {
2396
+ reason: "policy_invalid";
2397
+ retryable: false;
2398
+ status: "rejected";
2399
+ } | {
2392
2400
  operation: {
2393
2401
  accountId: string;
2394
2402
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2399,14 +2407,6 @@ export declare function setup(amounts?: number[]): Promise<{
2399
2407
  } | {
2400
2408
  enabled: boolean;
2401
2409
  status: "unchanged";
2402
- } | {
2403
- reason: "identity_changed" | "revision_changed" | "scope_busy";
2404
- retryable: false;
2405
- status: "conflict";
2406
- } | {
2407
- reason: "policy_invalid";
2408
- retryable: false;
2409
- status: "rejected";
2410
2410
  } | {
2411
2411
  reason: "provider_pending";
2412
2412
  retryable: true;