@openlup/core 0.0.0 → 0.6.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 +184 -0
- package/CODE_OF_CONDUCT.md +39 -0
- package/CONTRIBUTING.md +34 -0
- package/LICENSE +204 -0
- package/MAINTAINERS.md +33 -0
- package/README.md +64 -3
- package/SECURITY.md +29 -0
- package/dist/bundle/contracts.d.ts +9 -0
- package/dist/bundle/contracts.js +1 -0
- package/dist/bundle/ports.d.ts +41 -0
- package/dist/bundle/ports.js +1 -0
- package/dist/catalog/identifiers.d.ts +31 -0
- package/dist/catalog/identifiers.js +46 -0
- package/dist/catalog/index.d.ts +2 -0
- package/dist/catalog/index.js +2 -0
- package/dist/checkout/idempotency.d.ts +29 -0
- package/dist/checkout/idempotency.js +37 -0
- package/dist/checkout/index.d.ts +2 -0
- package/dist/checkout/index.js +2 -0
- package/dist/company-identity/contracts.d.ts +220 -0
- package/dist/company-identity/contracts.js +168 -0
- package/dist/company-identity/index.d.ts +6 -0
- package/dist/company-identity/index.js +2 -0
- package/dist/company-identity/ports.d.ts +13 -0
- package/dist/company-identity/ports.js +1 -0
- package/dist/fulfillment/facts.d.ts +103 -0
- package/dist/fulfillment/facts.js +195 -0
- package/dist/fulfillment/index.d.ts +4 -0
- package/dist/fulfillment/index.js +2 -0
- package/dist/inventory/atp.d.ts +172 -0
- package/dist/inventory/atp.js +211 -0
- package/dist/inventory/index.d.ts +2 -0
- package/dist/inventory/index.js +2 -0
- package/dist/marketing/research/contracts.d.ts +75 -0
- package/dist/marketing/research/contracts.js +60 -0
- package/dist/marketing/research/index.d.ts +4 -0
- package/dist/marketing/research/index.js +4 -0
- package/dist/marketing/research/ports.d.ts +15 -0
- package/dist/marketing/research/ports.js +1 -0
- package/dist/partners/index.d.ts +4 -0
- package/dist/partners/index.js +4 -0
- package/dist/partners/ports.d.ts +12 -0
- package/dist/partners/ports.js +1 -0
- package/dist/partners/status.d.ts +48 -0
- package/dist/partners/status.js +35 -0
- package/dist/payment/executionBaseContracts.d.ts +81 -0
- package/dist/payment/executionBaseContracts.js +8 -0
- package/dist/payment/index.d.ts +36 -0
- package/dist/payment/index.js +18 -0
- package/dist/payment/methodLifecycle.d.ts +91 -0
- package/dist/payment/methodLifecycle.js +76 -0
- package/dist/payment/paymentControlTypes.d.ts +135 -0
- package/dist/payment/paymentControlTypes.js +110 -0
- package/dist/payment/paymentFailureTaxonomy.d.ts +80 -0
- package/dist/payment/paymentFailureTaxonomy.js +155 -0
- package/dist/payment/paymentFailureTaxonomyContracts.d.ts +106 -0
- package/dist/payment/paymentFailureTaxonomyContracts.js +177 -0
- package/dist/payment/paymentRecovery.d.ts +26 -0
- package/dist/payment/paymentRecovery.js +73 -0
- package/dist/payment/paymentRecoveryContracts.d.ts +53 -0
- package/dist/payment/paymentRecoveryContracts.js +10 -0
- package/dist/payment/paymentStateMachine.d.ts +28 -0
- package/dist/payment/paymentStateMachine.js +184 -0
- package/dist/payment/providerAttemptIdempotency.d.ts +23 -0
- package/dist/payment/providerAttemptIdempotency.js +31 -0
- package/dist/payment/providerCapability.d.ts +148 -0
- package/dist/payment/providerCapability.js +13 -0
- package/dist/platform-runtime/contracts.d.ts +9 -0
- package/dist/platform-runtime/contracts.js +13 -0
- package/dist/platform-runtime/index.d.ts +10 -0
- package/dist/platform-runtime/index.js +4 -0
- package/dist/platform-runtime/platformKernel.d.ts +44 -0
- package/dist/platform-runtime/platformKernel.js +39 -0
- package/dist/platform-runtime/ports.d.ts +100 -0
- package/dist/platform-runtime/ports.js +1 -0
- package/dist/pricing/index.d.ts +8 -0
- package/dist/pricing/index.js +8 -0
- package/dist/pricing/ports.d.ts +22 -0
- package/dist/pricing/ports.js +7 -0
- package/dist/pricing/pricingBreakdown.d.ts +86 -0
- package/dist/pricing/pricingBreakdown.js +155 -0
- package/dist/pricing/targetPriceAllocation.d.ts +97 -0
- package/dist/pricing/targetPriceAllocation.js +202 -0
- package/dist/pricing/types.d.ts +32 -0
- package/dist/pricing/types.js +4 -0
- package/dist/promo/adjustmentEngine.d.ts +4 -0
- package/dist/promo/adjustmentEngine.js +194 -0
- package/dist/promo/adjustmentTypes.d.ts +103 -0
- package/dist/promo/adjustmentTypes.js +13 -0
- package/dist/promo/index.d.ts +8 -0
- package/dist/promo/index.js +8 -0
- package/dist/promo/promoEvaluator.d.ts +25 -0
- package/dist/promo/promoEvaluator.js +135 -0
- package/dist/promo/types.d.ts +86 -0
- package/dist/promo/types.js +12 -0
- package/dist/risk/core/evaluator.d.ts +3 -0
- package/dist/risk/core/evaluator.js +32 -0
- package/dist/risk/core/rules.d.ts +3 -0
- package/dist/risk/core/rules.js +118 -0
- package/dist/risk/core/types.d.ts +65 -0
- package/dist/risk/core/types.js +1 -0
- package/dist/risk/index.d.ts +8 -0
- package/dist/risk/index.js +8 -0
- package/dist/risk/types.d.ts +32 -0
- package/dist/risk/types.js +43 -0
- package/dist/shipping/index.d.ts +4 -0
- package/dist/shipping/index.js +4 -0
- package/dist/shipping/shippingResolver.d.ts +26 -0
- package/dist/shipping/shippingResolver.js +88 -0
- package/dist/shipping/types.d.ts +45 -0
- package/dist/shipping/types.js +4 -0
- package/dist/subscription/cycleHardening.d.ts +72 -0
- package/dist/subscription/cycleHardening.js +95 -0
- package/dist/subscription/index.d.ts +14 -0
- package/dist/subscription/index.js +14 -0
- package/dist/subscription/subscriptionEngineCore.d.ts +13 -0
- package/dist/subscription/subscriptionEngineCore.js +145 -0
- package/dist/subscription/subscriptionEngineLifecycle.d.ts +52 -0
- package/dist/subscription/subscriptionEngineLifecycle.js +196 -0
- package/dist/subscription/subscriptionEnginePayment.d.ts +19 -0
- package/dist/subscription/subscriptionEnginePayment.js +127 -0
- package/dist/subscription/subscriptionEngineTypes.d.ts +94 -0
- package/dist/subscription/subscriptionEngineTypes.js +4 -0
- package/dist/subscription/subscriptionEngineUtils.d.ts +32 -0
- package/dist/subscription/subscriptionEngineUtils.js +74 -0
- package/dist/subscription/types.d.ts +58 -0
- package/dist/subscription/types.js +47 -0
- package/dist/testing.d.ts +48 -0
- package/dist/testing.js +105 -0
- package/package.json +215 -4
- package/release-gates.json +232 -0
- package/src/bundle/contracts.ts +15 -0
- package/src/bundle/ports.ts +32 -0
- package/src/catalog/identifiers.ts +50 -0
- package/src/catalog/index.ts +2 -0
- package/src/checkout/idempotency.ts +49 -0
- package/src/checkout/index.ts +2 -0
- package/src/company-identity/contracts.ts +209 -0
- package/src/company-identity/index.ts +27 -0
- package/src/company-identity/ports.ts +19 -0
- package/src/fulfillment/facts.ts +300 -0
- package/src/fulfillment/index.ts +34 -0
- package/src/inventory/atp.ts +249 -0
- package/src/inventory/index.ts +2 -0
- package/src/marketing/research/contracts.ts +91 -0
- package/src/marketing/research/index.ts +4 -0
- package/src/marketing/research/ports.ts +26 -0
- package/src/partners/index.ts +4 -0
- package/src/partners/ports.ts +18 -0
- package/src/partners/status.ts +49 -0
- package/src/payment/executionBaseContracts.ts +93 -0
- package/src/payment/index.ts +128 -0
- package/src/payment/methodLifecycle.ts +130 -0
- package/src/payment/paymentControlTypes.ts +197 -0
- package/src/payment/paymentFailureTaxonomy.ts +201 -0
- package/src/payment/paymentFailureTaxonomyContracts.ts +228 -0
- package/src/payment/paymentRecovery.ts +95 -0
- package/src/payment/paymentRecoveryContracts.ts +61 -0
- package/src/payment/paymentStateMachine.ts +263 -0
- package/src/payment/providerAttemptIdempotency.ts +57 -0
- package/src/payment/providerCapability.ts +172 -0
- package/src/platform-runtime/contracts.ts +33 -0
- package/src/platform-runtime/index.ts +36 -0
- package/src/platform-runtime/platformKernel.ts +86 -0
- package/src/platform-runtime/ports.ts +88 -0
- package/src/pricing/index.ts +8 -0
- package/src/pricing/ports.ts +27 -0
- package/src/pricing/pricingBreakdown.ts +243 -0
- package/src/pricing/targetPriceAllocation.ts +293 -0
- package/src/pricing/types.ts +36 -0
- package/src/promo/adjustmentEngine.ts +253 -0
- package/src/promo/adjustmentTypes.ts +94 -0
- package/src/promo/index.ts +8 -0
- package/src/promo/promoEvaluator.ts +137 -0
- package/src/promo/types.ts +97 -0
- package/src/risk/core/evaluator.ts +41 -0
- package/src/risk/core/rules.ts +128 -0
- package/src/risk/core/types.ts +73 -0
- package/src/risk/index.ts +8 -0
- package/src/risk/types.ts +60 -0
- package/src/shipping/index.ts +4 -0
- package/src/shipping/shippingResolver.ts +101 -0
- package/src/shipping/types.ts +49 -0
- package/src/subscription/cycleHardening.ts +141 -0
- package/src/subscription/index.ts +14 -0
- package/src/subscription/subscriptionEngineCore.ts +181 -0
- package/src/subscription/subscriptionEngineLifecycle.ts +282 -0
- package/src/subscription/subscriptionEnginePayment.ts +174 -0
- package/src/subscription/subscriptionEngineTypes.ts +112 -0
- package/src/subscription/subscriptionEngineUtils.ts +110 -0
- package/src/subscription/types.ts +104 -0
- package/src/testing.ts +169 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CreateInitialSubscriptionCheckoutInput, CycleMutationResult, EngineSubscription, InitialSubscriptionCheckoutModel, PlanCycleInput, SubscriptionEngineResult } from "./subscriptionEngineTypes.js";
|
|
2
|
+
/** @beta */
|
|
3
|
+
export declare function createInitialSubscriptionCheckoutModel(input: CreateInitialSubscriptionCheckoutInput): SubscriptionEngineResult<InitialSubscriptionCheckoutModel>;
|
|
4
|
+
/** @beta */
|
|
5
|
+
export declare function planSubscriptionCycle(input: PlanCycleInput): SubscriptionEngineResult<CycleMutationResult>;
|
|
6
|
+
/** @beta */
|
|
7
|
+
export declare function findDueSubscriptions(subscriptions: EngineSubscription[], nowIso: string): EngineSubscription[];
|
|
8
|
+
/** @beta */
|
|
9
|
+
export declare function isRenewalDue(subscription: EngineSubscription, nowIso: string): boolean;
|
|
10
|
+
/** @beta */
|
|
11
|
+
export declare function editCutoffAt(subscription: EngineSubscription): string | null;
|
|
12
|
+
/** @beta */
|
|
13
|
+
export declare function isEditWindowOpen(subscription: EngineSubscription, nowIso: string): boolean;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { DEFAULT_EDIT_WINDOW_HOURS, DEFAULT_TIMEZONE } from "./subscriptionEngineTypes.js";
|
|
2
|
+
import { cloneRecord, cloneTemplate, failure, makeEvent, parseIso, success, validateTemplate, } from "./subscriptionEngineUtils.js";
|
|
3
|
+
/** @beta */
|
|
4
|
+
export function createInitialSubscriptionCheckoutModel(input) {
|
|
5
|
+
const now = parseIso(input.now);
|
|
6
|
+
const firstCycleAt = parseIso(input.firstCycleAt);
|
|
7
|
+
if (!now || !firstCycleAt) {
|
|
8
|
+
return failure("invalid_timestamp", "now and firstCycleAt must be valid ISO timestamps");
|
|
9
|
+
}
|
|
10
|
+
const template = cloneTemplate(input.template);
|
|
11
|
+
const templateError = validateTemplate(template);
|
|
12
|
+
if (templateError)
|
|
13
|
+
return templateError;
|
|
14
|
+
const subscription = {
|
|
15
|
+
id: input.subscriptionId,
|
|
16
|
+
clientRef: input.clientRef,
|
|
17
|
+
status: "active",
|
|
18
|
+
template,
|
|
19
|
+
templateVersion: 1,
|
|
20
|
+
nextCycleAt: firstCycleAt.toISOString(),
|
|
21
|
+
paymentMethodRef: input.paymentMethodRef ?? null,
|
|
22
|
+
paymentMethodKind: input.paymentMethodKind ?? null,
|
|
23
|
+
timezone: input.timezone ?? DEFAULT_TIMEZONE,
|
|
24
|
+
createdAt: now.toISOString(),
|
|
25
|
+
updatedAt: now.toISOString(),
|
|
26
|
+
};
|
|
27
|
+
const planned = planSubscriptionCycle({
|
|
28
|
+
subscription,
|
|
29
|
+
cycleNumber: 1,
|
|
30
|
+
now: now.toISOString(),
|
|
31
|
+
pricingSnapshot: input.pricingSnapshot,
|
|
32
|
+
idempotencyKey: input.idempotencyKey,
|
|
33
|
+
});
|
|
34
|
+
if (planned.ok === false) {
|
|
35
|
+
return failure(planned.error.code, planned.error.message);
|
|
36
|
+
}
|
|
37
|
+
return success({
|
|
38
|
+
subscription,
|
|
39
|
+
cycle: planned.value.cycle,
|
|
40
|
+
events: [
|
|
41
|
+
makeEvent({
|
|
42
|
+
eventType: "subscription.created",
|
|
43
|
+
subscription,
|
|
44
|
+
idempotencyKey: `${input.idempotencyKey}:subscription.created`,
|
|
45
|
+
occurredAt: now.toISOString(),
|
|
46
|
+
payload: { clientRef: input.clientRef, templateVersion: 1 },
|
|
47
|
+
}),
|
|
48
|
+
...planned.value.events,
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** @beta */
|
|
53
|
+
export function planSubscriptionCycle(input) {
|
|
54
|
+
const now = parseIso(input.now);
|
|
55
|
+
const scheduledAt = parseIso(input.subscription.nextCycleAt);
|
|
56
|
+
if (!now || !scheduledAt) {
|
|
57
|
+
return failure("invalid_timestamp", "now and subscription.nextCycleAt must be valid ISO timestamps");
|
|
58
|
+
}
|
|
59
|
+
if (input.subscription.status !== "active") {
|
|
60
|
+
return failure("inactive_subscription", "only active subscriptions can generate cycles");
|
|
61
|
+
}
|
|
62
|
+
const templateSnapshot = cloneTemplate(input.subscription.template);
|
|
63
|
+
const hasPaymentMethod = Boolean(input.subscription.paymentMethodRef);
|
|
64
|
+
const status = hasPaymentMethod ? "payment_pending" : "payment_failed";
|
|
65
|
+
const failureReason = hasPaymentMethod ? null : "missing_payment_method";
|
|
66
|
+
const cycle = {
|
|
67
|
+
subscriptionId: input.subscription.id,
|
|
68
|
+
cycleNumber: input.cycleNumber,
|
|
69
|
+
status,
|
|
70
|
+
scheduledAt: scheduledAt.toISOString(),
|
|
71
|
+
paidAt: null,
|
|
72
|
+
templateVersion: input.subscription.templateVersion,
|
|
73
|
+
templateSnapshot,
|
|
74
|
+
pricingSnapshot: cloneRecord(input.pricingSnapshot),
|
|
75
|
+
paymentMethodRef: input.subscription.paymentMethodRef,
|
|
76
|
+
retryAttempt: 0,
|
|
77
|
+
nextRetryAt: null,
|
|
78
|
+
failureReason,
|
|
79
|
+
engineIdempotencyKey: input.idempotencyKey,
|
|
80
|
+
};
|
|
81
|
+
const events = [
|
|
82
|
+
makeEvent({
|
|
83
|
+
eventType: "subscription.cycle_planned",
|
|
84
|
+
subscription: input.subscription,
|
|
85
|
+
cycleNumber: input.cycleNumber,
|
|
86
|
+
idempotencyKey: `${input.idempotencyKey}:cycle_planned`,
|
|
87
|
+
occurredAt: now.toISOString(),
|
|
88
|
+
payload: {
|
|
89
|
+
scheduledAt: cycle.scheduledAt,
|
|
90
|
+
templateVersion: cycle.templateVersion,
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
];
|
|
94
|
+
events.push(hasPaymentMethod
|
|
95
|
+
? makeEvent({
|
|
96
|
+
eventType: "subscription.payment_requested",
|
|
97
|
+
subscription: input.subscription,
|
|
98
|
+
cycleNumber: input.cycleNumber,
|
|
99
|
+
idempotencyKey: `${input.idempotencyKey}:payment_requested`,
|
|
100
|
+
occurredAt: now.toISOString(),
|
|
101
|
+
payload: { paymentMethodRef: input.subscription.paymentMethodRef },
|
|
102
|
+
})
|
|
103
|
+
: makeEvent({
|
|
104
|
+
eventType: "subscription.payment_failed",
|
|
105
|
+
subscription: input.subscription,
|
|
106
|
+
cycleNumber: input.cycleNumber,
|
|
107
|
+
idempotencyKey: `${input.idempotencyKey}:missing_payment_method`,
|
|
108
|
+
occurredAt: now.toISOString(),
|
|
109
|
+
payload: { reason: failureReason },
|
|
110
|
+
}));
|
|
111
|
+
return success({ cycle, events });
|
|
112
|
+
}
|
|
113
|
+
/** @beta */
|
|
114
|
+
export function findDueSubscriptions(subscriptions, nowIso) {
|
|
115
|
+
return subscriptions.filter((subscription) => isRenewalDue(subscription, nowIso));
|
|
116
|
+
}
|
|
117
|
+
/** @beta */
|
|
118
|
+
export function isRenewalDue(subscription, nowIso) {
|
|
119
|
+
if (subscription.status !== "active")
|
|
120
|
+
return false;
|
|
121
|
+
const now = parseIso(nowIso);
|
|
122
|
+
const nextCycleAt = parseIso(subscription.nextCycleAt);
|
|
123
|
+
if (!now || !nextCycleAt)
|
|
124
|
+
return false;
|
|
125
|
+
return nextCycleAt.getTime() <= now.getTime();
|
|
126
|
+
}
|
|
127
|
+
/** @beta */
|
|
128
|
+
export function editCutoffAt(subscription) {
|
|
129
|
+
const nextCycleAt = parseIso(subscription.nextCycleAt);
|
|
130
|
+
if (!nextCycleAt)
|
|
131
|
+
return null;
|
|
132
|
+
const editWindowHours = subscription.template.edit_window_hours ?? DEFAULT_EDIT_WINDOW_HOURS;
|
|
133
|
+
return new Date(nextCycleAt.getTime() - editWindowHours * 60 * 60 * 1000).toISOString();
|
|
134
|
+
}
|
|
135
|
+
/** @beta */
|
|
136
|
+
export function isEditWindowOpen(subscription, nowIso) {
|
|
137
|
+
if (subscription.status !== "active")
|
|
138
|
+
return false;
|
|
139
|
+
const now = parseIso(nowIso);
|
|
140
|
+
const cutoff = editCutoffAt(subscription);
|
|
141
|
+
const cutoffAt = cutoff ? parseIso(cutoff) : null;
|
|
142
|
+
if (!now || !cutoffAt)
|
|
143
|
+
return false;
|
|
144
|
+
return now.getTime() < cutoffAt.getTime();
|
|
145
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { SubscriptionLineSnapshot } from "./types.js";
|
|
2
|
+
import type { EngineSubscription, SubscriptionEngineResult, SubscriptionMutationResult } from "./subscriptionEngineTypes.js";
|
|
3
|
+
/** @beta */
|
|
4
|
+
export declare function swapTemplateLine(input: {
|
|
5
|
+
subscription: EngineSubscription;
|
|
6
|
+
fromVariantId: string;
|
|
7
|
+
toVariantId: string;
|
|
8
|
+
now: string;
|
|
9
|
+
}): SubscriptionEngineResult<SubscriptionMutationResult>;
|
|
10
|
+
/** @beta */
|
|
11
|
+
export declare function addPermanentAddon(input: {
|
|
12
|
+
subscription: EngineSubscription;
|
|
13
|
+
line: Omit<SubscriptionLineSnapshot, "is_addon" | "sort_order"> & {
|
|
14
|
+
sort_order?: number;
|
|
15
|
+
};
|
|
16
|
+
now: string;
|
|
17
|
+
}): SubscriptionEngineResult<SubscriptionMutationResult>;
|
|
18
|
+
/** @beta */
|
|
19
|
+
export declare function skipNextCycle(input: {
|
|
20
|
+
subscription: EngineSubscription;
|
|
21
|
+
now: string;
|
|
22
|
+
reason?: string;
|
|
23
|
+
}): SubscriptionEngineResult<SubscriptionMutationResult>;
|
|
24
|
+
/** @beta */
|
|
25
|
+
export declare function slideNextCycle(input: {
|
|
26
|
+
subscription: EngineSubscription;
|
|
27
|
+
newNextCycleAt: string;
|
|
28
|
+
now: string;
|
|
29
|
+
reason?: string;
|
|
30
|
+
}): SubscriptionEngineResult<SubscriptionMutationResult>;
|
|
31
|
+
/** @beta */
|
|
32
|
+
export declare function pauseSubscription(input: {
|
|
33
|
+
subscription: EngineSubscription;
|
|
34
|
+
now: string;
|
|
35
|
+
reason?: string;
|
|
36
|
+
}): SubscriptionEngineResult<SubscriptionMutationResult>;
|
|
37
|
+
/** @beta */
|
|
38
|
+
export declare function resumeSubscription(input: {
|
|
39
|
+
subscription: EngineSubscription;
|
|
40
|
+
now: string;
|
|
41
|
+
}): SubscriptionEngineResult<SubscriptionMutationResult>;
|
|
42
|
+
/** @beta */
|
|
43
|
+
export declare function cancelSubscription(input: {
|
|
44
|
+
subscription: EngineSubscription;
|
|
45
|
+
now: string;
|
|
46
|
+
reason?: string;
|
|
47
|
+
}): SubscriptionEngineResult<SubscriptionMutationResult>;
|
|
48
|
+
/** @beta */
|
|
49
|
+
export declare function completeSubscription(input: {
|
|
50
|
+
subscription: EngineSubscription;
|
|
51
|
+
now: string;
|
|
52
|
+
}): SubscriptionEngineResult<SubscriptionMutationResult>;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { isEditWindowOpen } from "./subscriptionEngineCore.js";
|
|
2
|
+
import { addCadenceDays, cloneTemplate, failure, makeEvent, parseIso, statusPatch, success, touchSubscription, validateTemplate, } from "./subscriptionEngineUtils.js";
|
|
3
|
+
/** @beta */
|
|
4
|
+
export function swapTemplateLine(input) {
|
|
5
|
+
if (!isEditWindowOpen(input.subscription, input.now)) {
|
|
6
|
+
return failure("edit_window_closed", "template swaps are locked after the edit cutoff");
|
|
7
|
+
}
|
|
8
|
+
if (input.subscription.template.lines.some((line) => line.variant_id === input.toVariantId)) {
|
|
9
|
+
return failure("duplicate_line", "target variant is already present in the template");
|
|
10
|
+
}
|
|
11
|
+
let replaced = false;
|
|
12
|
+
const lines = input.subscription.template.lines.map((line) => {
|
|
13
|
+
if (line.variant_id !== input.fromVariantId)
|
|
14
|
+
return { ...line };
|
|
15
|
+
replaced = true;
|
|
16
|
+
return { ...line, variant_id: input.toVariantId };
|
|
17
|
+
});
|
|
18
|
+
if (!replaced) {
|
|
19
|
+
return failure("line_not_found", "source variant is not present in the template");
|
|
20
|
+
}
|
|
21
|
+
return updateTemplate({
|
|
22
|
+
subscription: input.subscription,
|
|
23
|
+
template: { ...cloneTemplate(input.subscription.template), lines },
|
|
24
|
+
now: input.now,
|
|
25
|
+
eventType: "subscription.template_updated",
|
|
26
|
+
payload: { operation: "swap", fromVariantId: input.fromVariantId, toVariantId: input.toVariantId },
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** @beta */
|
|
30
|
+
export function addPermanentAddon(input) {
|
|
31
|
+
if (!isEditWindowOpen(input.subscription, input.now)) {
|
|
32
|
+
return failure("edit_window_closed", "template add-ons are locked after the edit cutoff");
|
|
33
|
+
}
|
|
34
|
+
if (input.subscription.template.lines.some((line) => line.variant_id === input.line.variant_id)) {
|
|
35
|
+
return failure("duplicate_line", "add-on variant is already present in the template");
|
|
36
|
+
}
|
|
37
|
+
const nextSortOrder = input.line.sort_order ??
|
|
38
|
+
Math.max(0, ...input.subscription.template.lines.map((line) => line.sort_order)) + 1;
|
|
39
|
+
const template = cloneTemplate(input.subscription.template);
|
|
40
|
+
template.lines = [
|
|
41
|
+
...template.lines,
|
|
42
|
+
{
|
|
43
|
+
variant_id: input.line.variant_id,
|
|
44
|
+
qty: input.line.qty,
|
|
45
|
+
sort_order: nextSortOrder,
|
|
46
|
+
is_addon: true,
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
return updateTemplate({
|
|
50
|
+
subscription: input.subscription,
|
|
51
|
+
template,
|
|
52
|
+
now: input.now,
|
|
53
|
+
eventType: "subscription.template_updated",
|
|
54
|
+
payload: { operation: "add_permanent_addon", variantId: input.line.variant_id },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** @beta */
|
|
58
|
+
export function skipNextCycle(input) {
|
|
59
|
+
const now = parseIso(input.now);
|
|
60
|
+
if (!now)
|
|
61
|
+
return failure("invalid_timestamp", "now must be a valid ISO timestamp");
|
|
62
|
+
if (input.subscription.status !== "active") {
|
|
63
|
+
return failure("inactive_subscription", "only active subscriptions can skip cycles");
|
|
64
|
+
}
|
|
65
|
+
const nextCycleAt = addCadenceDays(input.subscription.nextCycleAt, input.subscription.template.cadence_days);
|
|
66
|
+
if (!nextCycleAt)
|
|
67
|
+
return failure("invalid_timestamp", "subscription.nextCycleAt must be a valid ISO timestamp");
|
|
68
|
+
const subscription = touchSubscription(input.subscription, input.now, { nextCycleAt });
|
|
69
|
+
return success({
|
|
70
|
+
subscription,
|
|
71
|
+
events: [
|
|
72
|
+
makeEvent({
|
|
73
|
+
eventType: "subscription.cycle_skipped",
|
|
74
|
+
subscription: input.subscription,
|
|
75
|
+
idempotencyKey: `${input.subscription.id}:${input.subscription.nextCycleAt}:cycle_skipped`,
|
|
76
|
+
occurredAt: now.toISOString(),
|
|
77
|
+
payload: { skippedScheduledAt: input.subscription.nextCycleAt, reason: input.reason ?? null },
|
|
78
|
+
}),
|
|
79
|
+
makeEvent({
|
|
80
|
+
eventType: "subscription.next_cycle_at_updated",
|
|
81
|
+
subscription,
|
|
82
|
+
idempotencyKey: `${subscription.id}:${subscription.nextCycleAt}:next_cycle_at_updated`,
|
|
83
|
+
occurredAt: now.toISOString(),
|
|
84
|
+
payload: { nextCycleAt },
|
|
85
|
+
}),
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** @beta */
|
|
90
|
+
export function slideNextCycle(input) {
|
|
91
|
+
const now = parseIso(input.now);
|
|
92
|
+
const newNextCycleAt = parseIso(input.newNextCycleAt);
|
|
93
|
+
if (!now || !newNextCycleAt) {
|
|
94
|
+
return failure("invalid_timestamp", "now and newNextCycleAt must be valid ISO timestamps");
|
|
95
|
+
}
|
|
96
|
+
if (input.subscription.status !== "active") {
|
|
97
|
+
return failure("inactive_subscription", "only active subscriptions can slide cycles");
|
|
98
|
+
}
|
|
99
|
+
if (newNextCycleAt.getTime() <= now.getTime()) {
|
|
100
|
+
return failure("invalid_slide_target", "newNextCycleAt must be in the future");
|
|
101
|
+
}
|
|
102
|
+
const subscription = touchSubscription(input.subscription, now.toISOString(), {
|
|
103
|
+
nextCycleAt: newNextCycleAt.toISOString(),
|
|
104
|
+
});
|
|
105
|
+
return success({
|
|
106
|
+
subscription,
|
|
107
|
+
events: [
|
|
108
|
+
makeEvent({
|
|
109
|
+
eventType: "subscription.next_cycle_at_updated",
|
|
110
|
+
subscription,
|
|
111
|
+
idempotencyKey: `${subscription.id}:${subscription.nextCycleAt}:slide`,
|
|
112
|
+
occurredAt: now.toISOString(),
|
|
113
|
+
payload: {
|
|
114
|
+
previousNextCycleAt: input.subscription.nextCycleAt,
|
|
115
|
+
nextCycleAt: subscription.nextCycleAt,
|
|
116
|
+
reason: input.reason ?? null,
|
|
117
|
+
},
|
|
118
|
+
}),
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/** @beta */
|
|
123
|
+
export function pauseSubscription(input) {
|
|
124
|
+
return changeSubscriptionStatus(input.subscription, "paused", input.now, "subscription.paused", {
|
|
125
|
+
reason: input.reason ?? null,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/** @beta */
|
|
129
|
+
export function resumeSubscription(input) {
|
|
130
|
+
return changeSubscriptionStatus(input.subscription, "active", input.now, "subscription.resumed", {});
|
|
131
|
+
}
|
|
132
|
+
/** @beta */
|
|
133
|
+
export function cancelSubscription(input) {
|
|
134
|
+
return changeSubscriptionStatus(input.subscription, "cancelled", input.now, "subscription.cancelled", {
|
|
135
|
+
reason: input.reason ?? null,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/** @beta */
|
|
139
|
+
export function completeSubscription(input) {
|
|
140
|
+
return changeSubscriptionStatus(input.subscription, "completed", input.now, "subscription.completed", {});
|
|
141
|
+
}
|
|
142
|
+
function updateTemplate(input) {
|
|
143
|
+
const now = parseIso(input.now);
|
|
144
|
+
if (!now)
|
|
145
|
+
return failure("invalid_timestamp", "now must be a valid ISO timestamp");
|
|
146
|
+
const template = cloneTemplate(input.template);
|
|
147
|
+
const templateError = validateTemplate(template);
|
|
148
|
+
if (templateError)
|
|
149
|
+
return templateError;
|
|
150
|
+
const subscription = touchSubscription(input.subscription, now.toISOString(), {
|
|
151
|
+
template,
|
|
152
|
+
templateVersion: input.subscription.templateVersion + 1,
|
|
153
|
+
});
|
|
154
|
+
return success({
|
|
155
|
+
subscription,
|
|
156
|
+
events: [
|
|
157
|
+
makeEvent({
|
|
158
|
+
eventType: input.eventType,
|
|
159
|
+
subscription,
|
|
160
|
+
idempotencyKey: `${subscription.id}:template:${subscription.templateVersion}`,
|
|
161
|
+
occurredAt: now.toISOString(),
|
|
162
|
+
payload: { ...input.payload, templateVersion: subscription.templateVersion },
|
|
163
|
+
}),
|
|
164
|
+
],
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function changeSubscriptionStatus(subscription, status, nowIso, eventType, payload) {
|
|
168
|
+
const now = parseIso(nowIso);
|
|
169
|
+
if (!now)
|
|
170
|
+
return failure("invalid_timestamp", "now must be a valid ISO timestamp");
|
|
171
|
+
if (!canTransitionSubscriptionStatus(subscription.status, status)) {
|
|
172
|
+
return failure("invalid_transition", `Cannot move subscription from ${subscription.status} to ${status}`);
|
|
173
|
+
}
|
|
174
|
+
const next = touchSubscription(subscription, now.toISOString(), statusPatch(status));
|
|
175
|
+
return success({
|
|
176
|
+
subscription: next,
|
|
177
|
+
events: [
|
|
178
|
+
makeEvent({
|
|
179
|
+
eventType,
|
|
180
|
+
subscription: next,
|
|
181
|
+
idempotencyKey: `${next.id}:${eventType}:${now.toISOString()}`,
|
|
182
|
+
occurredAt: now.toISOString(),
|
|
183
|
+
payload,
|
|
184
|
+
}),
|
|
185
|
+
],
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function canTransitionSubscriptionStatus(from, to) {
|
|
189
|
+
const transitions = {
|
|
190
|
+
active: ["paused", "cancelled", "completed"],
|
|
191
|
+
paused: ["active", "cancelled"],
|
|
192
|
+
cancelled: [],
|
|
193
|
+
completed: [],
|
|
194
|
+
};
|
|
195
|
+
return transitions[from].includes(to);
|
|
196
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CycleMutationResult, EngineCycle, EngineEvent, EngineSubscription, SubscriptionEngineResult } from "./subscriptionEngineTypes.js";
|
|
2
|
+
/** @beta */
|
|
3
|
+
export declare function recordPaymentSuccess(input: {
|
|
4
|
+
subscription: EngineSubscription;
|
|
5
|
+
cycle: EngineCycle;
|
|
6
|
+
paidAt: string;
|
|
7
|
+
recordedAt: string;
|
|
8
|
+
}): SubscriptionEngineResult<{
|
|
9
|
+
subscription: EngineSubscription;
|
|
10
|
+
cycle: EngineCycle;
|
|
11
|
+
events: EngineEvent[];
|
|
12
|
+
}>;
|
|
13
|
+
/** @beta */
|
|
14
|
+
export declare function recordPaymentFailure(input: {
|
|
15
|
+
cycle: EngineCycle;
|
|
16
|
+
failedAt: string;
|
|
17
|
+
reason: string;
|
|
18
|
+
failureClass?: string | null;
|
|
19
|
+
}): SubscriptionEngineResult<CycleMutationResult>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { nextRetryAttemptAt } from "./cycleHardening.js";
|
|
2
|
+
import { addCadenceDays, failure, isTerminalCycle, makeEvent, parseIso, success, touchSubscription, } from "./subscriptionEngineUtils.js";
|
|
3
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
4
|
+
/** @beta */
|
|
5
|
+
export function recordPaymentSuccess(input) {
|
|
6
|
+
const paidAt = parseIso(input.paidAt);
|
|
7
|
+
if (!paidAt)
|
|
8
|
+
return failure("invalid_timestamp", "paidAt must be a valid ISO timestamp");
|
|
9
|
+
const recordedAt = parseIso(input.recordedAt);
|
|
10
|
+
if (!recordedAt)
|
|
11
|
+
return failure("invalid_timestamp", "recordedAt must be a valid ISO timestamp");
|
|
12
|
+
if (isTerminalCycle(input.cycle)) {
|
|
13
|
+
return failure("terminal_cycle", "terminal cycles cannot be paid");
|
|
14
|
+
}
|
|
15
|
+
// The next cycle is one cadence past the CYCLE'S OWN scheduled instant, not past
|
|
16
|
+
// the moment the money arrived: a late payment must not silently shorten the
|
|
17
|
+
// interval the customer bought. The whole days the payment was late are then
|
|
18
|
+
// ADDED, because a delivery that arrives late shifts the whole subscription
|
|
19
|
+
// later rather than letting the next one stack up behind it.
|
|
20
|
+
//
|
|
21
|
+
// Lateness is measured to the EARLIER of the payment instant and the instant we
|
|
22
|
+
// recorded it, so a provider timestamp from the future cannot inflate the shift
|
|
23
|
+
// and push the next charge out past what the customer actually owes.
|
|
24
|
+
//
|
|
25
|
+
// ⛔ The outer Math.max is the load-bearing part and is NOT an optimisation.
|
|
26
|
+
// It is a monotonic clamp: `nextCycleAt` may only ever move LATER, never
|
|
27
|
+
// earlier. Without it, a replayed webhook, an out-of-order settlement, or a
|
|
28
|
+
// manual correction applied against an older cycle could compute an EARLIER
|
|
29
|
+
// instant and pull a charge forward into a window the subscriber has already
|
|
30
|
+
// been billed for — the one failure mode this rail must never have. The same
|
|
31
|
+
// clamp is spelled `GREATEST` in the SQL delivery-alignment rail for exactly
|
|
32
|
+
// this reason; the two are one rule with two spellings.
|
|
33
|
+
//
|
|
34
|
+
// `Date.parse(...) || 0` is deliberate rather than defensive noise: a
|
|
35
|
+
// subscription whose stored instant is unreadable clamps against the epoch,
|
|
36
|
+
// which yields the computed instant, instead of poisoning the whole expression
|
|
37
|
+
// with NaN and returning an invalid date. Cadence keeps its own call so its own
|
|
38
|
+
// validity guard still fires and still reports the right error, and `toJSON()`
|
|
39
|
+
// answers null past the representable range rather than throwing, which is why
|
|
40
|
+
// the shift is range-checked below instead of trusted.
|
|
41
|
+
const onTimeNextCycleAt = addCadenceDays(input.cycle.scheduledAt, input.cycle.templateSnapshot.cadence_days);
|
|
42
|
+
if (!onTimeNextCycleAt)
|
|
43
|
+
return failure("invalid_timestamp", "cycle.scheduledAt must be a valid ISO timestamp");
|
|
44
|
+
const shiftedByDays = Math.max(0, Math.floor((Math.min(paidAt.getTime(), recordedAt.getTime()) - Date.parse(input.cycle.scheduledAt)) / DAY_MS));
|
|
45
|
+
const nextCycleAt = new Date(Math.max(Date.parse(input.subscription.nextCycleAt) || 0, Date.parse(onTimeNextCycleAt) + shiftedByDays * DAY_MS)).toJSON();
|
|
46
|
+
if (!nextCycleAt) {
|
|
47
|
+
return failure("invalid_timestamp", "payment shift exceeds the supported timestamp range");
|
|
48
|
+
}
|
|
49
|
+
const paidAtIso = paidAt.toISOString();
|
|
50
|
+
const cycle = {
|
|
51
|
+
...input.cycle,
|
|
52
|
+
status: "paid",
|
|
53
|
+
paidAt: paidAtIso,
|
|
54
|
+
retryAttempt: input.cycle.retryAttempt,
|
|
55
|
+
nextRetryAt: null,
|
|
56
|
+
failureReason: null,
|
|
57
|
+
};
|
|
58
|
+
const subscription = touchSubscription(input.subscription, recordedAt.toISOString(), { nextCycleAt });
|
|
59
|
+
return success({
|
|
60
|
+
subscription,
|
|
61
|
+
cycle,
|
|
62
|
+
events: [
|
|
63
|
+
makeEvent({
|
|
64
|
+
eventType: "subscription.cycle_paid",
|
|
65
|
+
subscription,
|
|
66
|
+
cycleNumber: cycle.cycleNumber,
|
|
67
|
+
idempotencyKey: `${cycle.engineIdempotencyKey}:cycle_paid`,
|
|
68
|
+
occurredAt: paidAtIso,
|
|
69
|
+
payload: { paidAt: cycle.paidAt, nextCycleAt },
|
|
70
|
+
}),
|
|
71
|
+
makeEvent({
|
|
72
|
+
eventType: "subscription.next_cycle_at_updated",
|
|
73
|
+
subscription,
|
|
74
|
+
cycleNumber: cycle.cycleNumber,
|
|
75
|
+
idempotencyKey: `${cycle.engineIdempotencyKey}:next_cycle_at_updated`,
|
|
76
|
+
occurredAt: paidAtIso,
|
|
77
|
+
payload: {
|
|
78
|
+
nextCycleAt,
|
|
79
|
+
basedOnScheduledAt: cycle.scheduledAt,
|
|
80
|
+
basedOnPaidAt: cycle.paidAt,
|
|
81
|
+
shiftedByDays,
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/** @beta */
|
|
88
|
+
export function recordPaymentFailure(input) {
|
|
89
|
+
const failedAt = parseIso(input.failedAt);
|
|
90
|
+
if (!failedAt)
|
|
91
|
+
return failure("invalid_timestamp", "failedAt must be a valid ISO timestamp");
|
|
92
|
+
if (isTerminalCycle(input.cycle)) {
|
|
93
|
+
return failure("terminal_cycle", "terminal cycles cannot be retried");
|
|
94
|
+
}
|
|
95
|
+
const retryAttempt = input.cycle.retryAttempt + 1;
|
|
96
|
+
// The ladder owns its terminal decision.
|
|
97
|
+
const nextRetryAt = nextRetryAttemptAt(failedAt.toISOString(), retryAttempt, undefined, input.failureClass);
|
|
98
|
+
const status = nextRetryAt ? "retry_scheduled" : "payment_failed";
|
|
99
|
+
const cycle = {
|
|
100
|
+
...input.cycle,
|
|
101
|
+
status,
|
|
102
|
+
retryAttempt,
|
|
103
|
+
nextRetryAt,
|
|
104
|
+
failureReason: input.reason,
|
|
105
|
+
};
|
|
106
|
+
const events = [
|
|
107
|
+
{
|
|
108
|
+
eventType: "subscription.payment_failed",
|
|
109
|
+
subscriptionId: cycle.subscriptionId,
|
|
110
|
+
cycleNumber: cycle.cycleNumber,
|
|
111
|
+
idempotencyKey: `${cycle.engineIdempotencyKey}:payment_failed:${retryAttempt}`,
|
|
112
|
+
occurredAt: failedAt.toISOString(),
|
|
113
|
+
payload: { reason: input.reason, retryAttempt },
|
|
114
|
+
},
|
|
115
|
+
];
|
|
116
|
+
if (nextRetryAt) {
|
|
117
|
+
events.push({
|
|
118
|
+
eventType: "subscription.retry_scheduled",
|
|
119
|
+
subscriptionId: cycle.subscriptionId,
|
|
120
|
+
cycleNumber: cycle.cycleNumber,
|
|
121
|
+
idempotencyKey: `${cycle.engineIdempotencyKey}:retry_scheduled:${retryAttempt}`,
|
|
122
|
+
occurredAt: failedAt.toISOString(),
|
|
123
|
+
payload: { nextRetryAt, retryAttempt },
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return success({ cycle, events });
|
|
127
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { SubscriptionCycleStatus, SubscriptionEngineEventType, SubscriptionStatus, SubscriptionTemplateSnapshot } from "./types.js";
|
|
2
|
+
/** @beta */
|
|
3
|
+
export declare const DEFAULT_EDIT_WINDOW_HOURS = 72;
|
|
4
|
+
/** @beta */
|
|
5
|
+
export declare const DEFAULT_TIMEZONE = "UTC";
|
|
6
|
+
/** @beta */
|
|
7
|
+
export type SubscriptionEngineErrorCode = "invalid_timestamp" | "invalid_template" | "inactive_subscription" | "edit_window_closed" | "line_not_found" | "duplicate_line" | "invalid_slide_target" | "invalid_transition" | "terminal_cycle";
|
|
8
|
+
/** @beta */
|
|
9
|
+
export type SubscriptionEngineResult<T> = {
|
|
10
|
+
ok: true;
|
|
11
|
+
value: T;
|
|
12
|
+
} | {
|
|
13
|
+
ok: false;
|
|
14
|
+
error: {
|
|
15
|
+
code: SubscriptionEngineErrorCode;
|
|
16
|
+
message: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/** @beta */
|
|
20
|
+
export interface EngineSubscription {
|
|
21
|
+
id: string;
|
|
22
|
+
clientRef: string;
|
|
23
|
+
status: SubscriptionStatus;
|
|
24
|
+
template: SubscriptionTemplateSnapshot;
|
|
25
|
+
templateVersion: number;
|
|
26
|
+
nextCycleAt: string;
|
|
27
|
+
paymentMethodRef: string | null;
|
|
28
|
+
paymentMethodKind: string | null;
|
|
29
|
+
timezone: string;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
updatedAt: string;
|
|
32
|
+
}
|
|
33
|
+
/** @beta */
|
|
34
|
+
export interface EngineCycle {
|
|
35
|
+
subscriptionId: string;
|
|
36
|
+
cycleNumber: number;
|
|
37
|
+
status: SubscriptionCycleStatus;
|
|
38
|
+
scheduledAt: string;
|
|
39
|
+
paidAt: string | null;
|
|
40
|
+
templateVersion: number;
|
|
41
|
+
templateSnapshot: SubscriptionTemplateSnapshot;
|
|
42
|
+
pricingSnapshot: Record<string, unknown>;
|
|
43
|
+
paymentMethodRef: string | null;
|
|
44
|
+
retryAttempt: number;
|
|
45
|
+
nextRetryAt: string | null;
|
|
46
|
+
failureReason: string | null;
|
|
47
|
+
engineIdempotencyKey: string;
|
|
48
|
+
}
|
|
49
|
+
/** @beta */
|
|
50
|
+
export interface EngineEvent {
|
|
51
|
+
eventType: SubscriptionEngineEventType;
|
|
52
|
+
subscriptionId: string;
|
|
53
|
+
cycleNumber?: number;
|
|
54
|
+
idempotencyKey: string;
|
|
55
|
+
occurredAt: string;
|
|
56
|
+
payload: Record<string, unknown>;
|
|
57
|
+
}
|
|
58
|
+
/** @beta */
|
|
59
|
+
export interface CreateInitialSubscriptionCheckoutInput {
|
|
60
|
+
subscriptionId: string;
|
|
61
|
+
clientRef: string;
|
|
62
|
+
template: SubscriptionTemplateSnapshot;
|
|
63
|
+
paymentMethodRef?: string | null;
|
|
64
|
+
paymentMethodKind?: string | null;
|
|
65
|
+
firstCycleAt: string;
|
|
66
|
+
now: string;
|
|
67
|
+
pricingSnapshot: Record<string, unknown>;
|
|
68
|
+
idempotencyKey: string;
|
|
69
|
+
timezone?: string | null;
|
|
70
|
+
}
|
|
71
|
+
/** @beta */
|
|
72
|
+
export interface PlanCycleInput {
|
|
73
|
+
subscription: EngineSubscription;
|
|
74
|
+
cycleNumber: number;
|
|
75
|
+
now: string;
|
|
76
|
+
pricingSnapshot: Record<string, unknown>;
|
|
77
|
+
idempotencyKey: string;
|
|
78
|
+
}
|
|
79
|
+
/** @beta */
|
|
80
|
+
export interface SubscriptionMutationResult {
|
|
81
|
+
subscription: EngineSubscription;
|
|
82
|
+
events: EngineEvent[];
|
|
83
|
+
}
|
|
84
|
+
/** @beta */
|
|
85
|
+
export interface CycleMutationResult {
|
|
86
|
+
cycle: EngineCycle;
|
|
87
|
+
events: EngineEvent[];
|
|
88
|
+
}
|
|
89
|
+
/** @beta */
|
|
90
|
+
export interface InitialSubscriptionCheckoutModel {
|
|
91
|
+
subscription: EngineSubscription;
|
|
92
|
+
cycle: EngineCycle;
|
|
93
|
+
events: EngineEvent[];
|
|
94
|
+
}
|