@modainteract/moda-interact-shared 0.10.0 → 0.11.1
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/dist/billing.d.ts +19 -46
- package/dist/billing.js +5 -7
- package/dist/{chunk-KO4LMZ66.js → chunk-MBIECH3Y.js} +39 -43
- package/dist/chunk-MBIECH3Y.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -7
- package/package.json +1 -1
- package/dist/chunk-KO4LMZ66.js.map +0 -1
package/dist/billing.d.ts
CHANGED
|
@@ -6,6 +6,24 @@ declare const BILLING_SUBSCRIPTION_RECONCILE_SCHEMA_VERSION: 1;
|
|
|
6
6
|
declare const BILLING_SUBSCRIPTION_RECONCILE_QUEUE_NAME = "billing-subscription-reconcile";
|
|
7
7
|
declare const BILLING_SUBSCRIPTION_RECONCILE_JOB_NAME = "reconcile-subscription";
|
|
8
8
|
declare const APP_PRICING_BILLING_PERIOD_DRAIN_WINDOW_MS: 300000;
|
|
9
|
+
type ShopifyProviderContextIdentityInput = Readonly<{
|
|
10
|
+
providerSubscriptionId: string | null;
|
|
11
|
+
planHandle: string;
|
|
12
|
+
currentPeriodStart: Date | string | null;
|
|
13
|
+
currentPeriodEnd: Date | string | null;
|
|
14
|
+
}>;
|
|
15
|
+
type ShopifyPurchaseProviderContext = Readonly<{
|
|
16
|
+
providerContextIdentity: string;
|
|
17
|
+
shopifyPlanHandleSnapshot: string;
|
|
18
|
+
billingPeriodId: string;
|
|
19
|
+
}>;
|
|
20
|
+
type ShopifyCurrentProviderContext = Readonly<{
|
|
21
|
+
providerContextIdentity: string;
|
|
22
|
+
shopifyPlanHandle: string;
|
|
23
|
+
billingPeriodId: string;
|
|
24
|
+
}>;
|
|
25
|
+
declare function deriveShopifyProviderContextIdentity(input: ShopifyProviderContextIdentityInput): string;
|
|
26
|
+
declare function isSameShopifyPurchaseProviderContext(purchase: ShopifyPurchaseProviderContext, current: ShopifyCurrentProviderContext): boolean;
|
|
9
27
|
declare const BILLING_PLAN_KINDS: readonly ["FREE", "PAID_METERED"];
|
|
10
28
|
declare const BillingPlanKindSchema: z.ZodEnum<{
|
|
11
29
|
FREE: "FREE";
|
|
@@ -22,72 +40,27 @@ declare const BillingUsageMetricSchema: z.ZodEnum<{
|
|
|
22
40
|
type BillingUsageMetric = z.infer<typeof BillingUsageMetricSchema>;
|
|
23
41
|
declare const BILLING_SYSTEM_MESSAGE_CODES: {
|
|
24
42
|
readonly FREE_ALLOWANCE_WARNING: "BILLING_FREE_ALLOWANCE_WARNING";
|
|
25
|
-
readonly FREE_ALLOWANCE_EXHAUSTED: "BILLING_FREE_ALLOWANCE_EXHAUSTED";
|
|
26
43
|
readonly RECOVERY_CAPACITY_EXHAUSTED: "BILLING_RECOVERY_CAPACITY_EXHAUSTED";
|
|
27
44
|
readonly PLAN_UPGRADED: "BILLING_PLAN_UPGRADED";
|
|
28
45
|
readonly PLAN_DOWNGRADE_SCHEDULED: "BILLING_PLAN_DOWNGRADE_SCHEDULED";
|
|
29
46
|
readonly SUBSCRIPTION_ENDED: "BILLING_SUBSCRIPTION_ENDED";
|
|
30
47
|
readonly SAFETY_LIMIT_REACHED: "BILLING_SAFETY_LIMIT_REACHED";
|
|
31
|
-
readonly PLAN_CHANGE_ACTION_REQUIRED: "BILLING_PLAN_CHANGE_ACTION_REQUIRED";
|
|
32
|
-
readonly CANCELLATION_REQUEST_RECEIVED: "BILLING_CANCELLATION_REQUEST_RECEIVED";
|
|
33
|
-
readonly CANCELLATION_COMPLETED: "BILLING_CANCELLATION_COMPLETED";
|
|
34
|
-
readonly CANCELLATION_REJECTED: "BILLING_CANCELLATION_REJECTED";
|
|
35
48
|
readonly REFUND_REQUEST_RECEIVED: "BILLING_REFUND_REQUEST_RECEIVED";
|
|
36
49
|
readonly REFUND_COMPLETED: "BILLING_REFUND_COMPLETED";
|
|
37
50
|
readonly REFUND_REJECTED: "BILLING_REFUND_REJECTED";
|
|
38
51
|
};
|
|
39
52
|
declare const BillingSystemMessageCodeSchema: z.ZodEnum<{
|
|
40
53
|
BILLING_FREE_ALLOWANCE_WARNING: "BILLING_FREE_ALLOWANCE_WARNING";
|
|
41
|
-
BILLING_FREE_ALLOWANCE_EXHAUSTED: "BILLING_FREE_ALLOWANCE_EXHAUSTED";
|
|
42
54
|
BILLING_RECOVERY_CAPACITY_EXHAUSTED: "BILLING_RECOVERY_CAPACITY_EXHAUSTED";
|
|
43
55
|
BILLING_PLAN_UPGRADED: "BILLING_PLAN_UPGRADED";
|
|
44
56
|
BILLING_PLAN_DOWNGRADE_SCHEDULED: "BILLING_PLAN_DOWNGRADE_SCHEDULED";
|
|
45
57
|
BILLING_SUBSCRIPTION_ENDED: "BILLING_SUBSCRIPTION_ENDED";
|
|
46
58
|
BILLING_SAFETY_LIMIT_REACHED: "BILLING_SAFETY_LIMIT_REACHED";
|
|
47
|
-
BILLING_PLAN_CHANGE_ACTION_REQUIRED: "BILLING_PLAN_CHANGE_ACTION_REQUIRED";
|
|
48
|
-
BILLING_CANCELLATION_REQUEST_RECEIVED: "BILLING_CANCELLATION_REQUEST_RECEIVED";
|
|
49
|
-
BILLING_CANCELLATION_COMPLETED: "BILLING_CANCELLATION_COMPLETED";
|
|
50
|
-
BILLING_CANCELLATION_REJECTED: "BILLING_CANCELLATION_REJECTED";
|
|
51
59
|
BILLING_REFUND_REQUEST_RECEIVED: "BILLING_REFUND_REQUEST_RECEIVED";
|
|
52
60
|
BILLING_REFUND_COMPLETED: "BILLING_REFUND_COMPLETED";
|
|
53
61
|
BILLING_REFUND_REJECTED: "BILLING_REFUND_REJECTED";
|
|
54
62
|
}>;
|
|
55
63
|
type BillingSystemMessageCode = z.infer<typeof BillingSystemMessageCodeSchema>;
|
|
56
|
-
declare const SUBSCRIPTION_CANCELLATION_MODES: readonly ["END_OF_CYCLE", "IMMEDIATE_NO_PRORATION", "IMMEDIATE_PRORATED", "IMMEDIATE_SKIP_FINAL_USAGE"];
|
|
57
|
-
declare const SubscriptionCancellationModeSchema: z.ZodEnum<{
|
|
58
|
-
END_OF_CYCLE: "END_OF_CYCLE";
|
|
59
|
-
IMMEDIATE_NO_PRORATION: "IMMEDIATE_NO_PRORATION";
|
|
60
|
-
IMMEDIATE_PRORATED: "IMMEDIATE_PRORATED";
|
|
61
|
-
IMMEDIATE_SKIP_FINAL_USAGE: "IMMEDIATE_SKIP_FINAL_USAGE";
|
|
62
|
-
}>;
|
|
63
|
-
type SubscriptionCancellationMode = z.infer<typeof SubscriptionCancellationModeSchema>;
|
|
64
|
-
type ShopifySubscriptionCancellationArgs = Readonly<{
|
|
65
|
-
deferCancellation: boolean;
|
|
66
|
-
prorate: boolean;
|
|
67
|
-
skipFinalUsageCharge: boolean;
|
|
68
|
-
}>;
|
|
69
|
-
declare const SHOPIFY_SUBSCRIPTION_CANCELLATION_ARGS: {
|
|
70
|
-
readonly END_OF_CYCLE: {
|
|
71
|
-
readonly deferCancellation: true;
|
|
72
|
-
readonly prorate: false;
|
|
73
|
-
readonly skipFinalUsageCharge: false;
|
|
74
|
-
};
|
|
75
|
-
readonly IMMEDIATE_NO_PRORATION: {
|
|
76
|
-
readonly deferCancellation: false;
|
|
77
|
-
readonly prorate: false;
|
|
78
|
-
readonly skipFinalUsageCharge: false;
|
|
79
|
-
};
|
|
80
|
-
readonly IMMEDIATE_PRORATED: {
|
|
81
|
-
readonly deferCancellation: false;
|
|
82
|
-
readonly prorate: true;
|
|
83
|
-
readonly skipFinalUsageCharge: false;
|
|
84
|
-
};
|
|
85
|
-
readonly IMMEDIATE_SKIP_FINAL_USAGE: {
|
|
86
|
-
readonly deferCancellation: false;
|
|
87
|
-
readonly prorate: false;
|
|
88
|
-
readonly skipFinalUsageCharge: true;
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
64
|
type PurchasedRecoveryCreditCounterSnapshot = Readonly<{
|
|
92
65
|
grantedQuantity: number;
|
|
93
66
|
committedQuantity: number;
|
|
@@ -161,4 +134,4 @@ declare function createMerchantBillingSystemSourceKey(shopId: string, code: Bill
|
|
|
161
134
|
declare function createRecoveryIdempotencyKey(shopId: string, recoveryId: string): string;
|
|
162
135
|
declare function createShopifyUsageIdempotencyKey(shopId: string, usageEventId: string): string;
|
|
163
136
|
|
|
164
|
-
export { APP_PRICING_BILLING_PERIOD_DRAIN_WINDOW_MS, ARCH007_BILLING_CONTRACT_SCHEMA_VERSION, BILLING_PLAN_KINDS, BILLING_SUBSCRIPTION_RECONCILE_JOB_NAME, BILLING_SUBSCRIPTION_RECONCILE_QUEUE_NAME, BILLING_SUBSCRIPTION_RECONCILE_SCHEMA_VERSION, BILLING_SYSTEM_MESSAGE_CODES, BILLING_USAGE_METRICS, type BillingPlanKind, BillingPlanKindSchema, type BillingSubscriptionReconcileJob, BillingSubscriptionReconcileJobSchema, type BillingSystemMessageCode, BillingSystemMessageCodeSchema, type BillingUsageMetric, BillingUsageMetricSchema, type NormalizedWhatsAppStatus, NormalizedWhatsAppStatusSchema, type PurchasedRecoveryCreditCounterSnapshot,
|
|
137
|
+
export { APP_PRICING_BILLING_PERIOD_DRAIN_WINDOW_MS, ARCH007_BILLING_CONTRACT_SCHEMA_VERSION, BILLING_PLAN_KINDS, BILLING_SUBSCRIPTION_RECONCILE_JOB_NAME, BILLING_SUBSCRIPTION_RECONCILE_QUEUE_NAME, BILLING_SUBSCRIPTION_RECONCILE_SCHEMA_VERSION, BILLING_SYSTEM_MESSAGE_CODES, BILLING_USAGE_METRICS, type BillingPlanKind, BillingPlanKindSchema, type BillingSubscriptionReconcileJob, BillingSubscriptionReconcileJobSchema, type BillingSystemMessageCode, BillingSystemMessageCodeSchema, type BillingUsageMetric, BillingUsageMetricSchema, type NormalizedWhatsAppStatus, NormalizedWhatsAppStatusSchema, type PurchasedRecoveryCreditCounterSnapshot, type ShopifyCurrentProviderContext, type ShopifyProviderContextIdentityInput, type ShopifyPurchaseProviderContext, WHATSAPP_PROVIDER_STATUSES, WHATSAPP_PROVIDER_STATUS_SCHEMA_VERSION, type WhatsAppProviderPricingMetadata, WhatsAppProviderPricingMetadataSchema, type WhatsAppProviderStatus, WhatsAppProviderStatusSchema, availablePurchasedRecoveryCredits, createBillingSubscriptionReconcileJobId, createMerchantBillingSystemSourceKey, createRecoveryIdempotencyKey, createShopifyUsageIdempotencyKey, deriveShopifyProviderContextIdentity, isSameShopifyPurchaseProviderContext, parseBillingSubscriptionReconcileJob, parseNormalizedWhatsAppStatus, safeParseBillingSubscriptionReconcileJob, safeParseNormalizedWhatsAppStatus };
|
package/dist/billing.js
CHANGED
|
@@ -12,9 +12,6 @@ import {
|
|
|
12
12
|
BillingSystemMessageCodeSchema,
|
|
13
13
|
BillingUsageMetricSchema,
|
|
14
14
|
NormalizedWhatsAppStatusSchema,
|
|
15
|
-
SHOPIFY_SUBSCRIPTION_CANCELLATION_ARGS,
|
|
16
|
-
SUBSCRIPTION_CANCELLATION_MODES,
|
|
17
|
-
SubscriptionCancellationModeSchema,
|
|
18
15
|
WHATSAPP_PROVIDER_STATUSES,
|
|
19
16
|
WHATSAPP_PROVIDER_STATUS_SCHEMA_VERSION,
|
|
20
17
|
WhatsAppProviderPricingMetadataSchema,
|
|
@@ -24,11 +21,13 @@ import {
|
|
|
24
21
|
createMerchantBillingSystemSourceKey,
|
|
25
22
|
createRecoveryIdempotencyKey,
|
|
26
23
|
createShopifyUsageIdempotencyKey,
|
|
24
|
+
deriveShopifyProviderContextIdentity,
|
|
25
|
+
isSameShopifyPurchaseProviderContext,
|
|
27
26
|
parseBillingSubscriptionReconcileJob,
|
|
28
27
|
parseNormalizedWhatsAppStatus,
|
|
29
28
|
safeParseBillingSubscriptionReconcileJob,
|
|
30
29
|
safeParseNormalizedWhatsAppStatus
|
|
31
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-MBIECH3Y.js";
|
|
32
31
|
export {
|
|
33
32
|
APP_PRICING_BILLING_PERIOD_DRAIN_WINDOW_MS,
|
|
34
33
|
ARCH007_BILLING_CONTRACT_SCHEMA_VERSION,
|
|
@@ -43,9 +42,6 @@ export {
|
|
|
43
42
|
BillingSystemMessageCodeSchema,
|
|
44
43
|
BillingUsageMetricSchema,
|
|
45
44
|
NormalizedWhatsAppStatusSchema,
|
|
46
|
-
SHOPIFY_SUBSCRIPTION_CANCELLATION_ARGS,
|
|
47
|
-
SUBSCRIPTION_CANCELLATION_MODES,
|
|
48
|
-
SubscriptionCancellationModeSchema,
|
|
49
45
|
WHATSAPP_PROVIDER_STATUSES,
|
|
50
46
|
WHATSAPP_PROVIDER_STATUS_SCHEMA_VERSION,
|
|
51
47
|
WhatsAppProviderPricingMetadataSchema,
|
|
@@ -55,6 +51,8 @@ export {
|
|
|
55
51
|
createMerchantBillingSystemSourceKey,
|
|
56
52
|
createRecoveryIdempotencyKey,
|
|
57
53
|
createShopifyUsageIdempotencyKey,
|
|
54
|
+
deriveShopifyProviderContextIdentity,
|
|
55
|
+
isSameShopifyPurchaseProviderContext,
|
|
58
56
|
parseBillingSubscriptionReconcileJob,
|
|
59
57
|
parseNormalizedWhatsAppStatus,
|
|
60
58
|
safeParseBillingSubscriptionReconcileJob,
|
|
@@ -6,6 +6,42 @@ var BILLING_SUBSCRIPTION_RECONCILE_SCHEMA_VERSION = 1;
|
|
|
6
6
|
var BILLING_SUBSCRIPTION_RECONCILE_QUEUE_NAME = "billing-subscription-reconcile";
|
|
7
7
|
var BILLING_SUBSCRIPTION_RECONCILE_JOB_NAME = "reconcile-subscription";
|
|
8
8
|
var APP_PRICING_BILLING_PERIOD_DRAIN_WINDOW_MS = 3e5;
|
|
9
|
+
var SHOPIFY_PROVIDER_CONTEXT_INVALID_PREFIX = "SHOPIFY_PROVIDER_CONTEXT_INVALID:";
|
|
10
|
+
function invalidShopifyProviderContext(reason) {
|
|
11
|
+
throw new Error(`${SHOPIFY_PROVIDER_CONTEXT_INVALID_PREFIX}${reason}`);
|
|
12
|
+
}
|
|
13
|
+
function normalizeShopifyProviderContextDate(name, value) {
|
|
14
|
+
if (value === null || typeof value !== "string" && !(value instanceof Date)) {
|
|
15
|
+
return invalidShopifyProviderContext(`${name} must be a valid date`);
|
|
16
|
+
}
|
|
17
|
+
const date = value instanceof Date ? new Date(value.getTime()) : new Date(value);
|
|
18
|
+
if (Number.isNaN(date.getTime())) {
|
|
19
|
+
return invalidShopifyProviderContext(`${name} must be a valid date`);
|
|
20
|
+
}
|
|
21
|
+
return date;
|
|
22
|
+
}
|
|
23
|
+
function deriveShopifyProviderContextIdentity(input) {
|
|
24
|
+
const providerSubscriptionId = typeof input.providerSubscriptionId === "string" ? input.providerSubscriptionId.trim() : "";
|
|
25
|
+
if (providerSubscriptionId) return providerSubscriptionId;
|
|
26
|
+
if (typeof input.planHandle !== "string" || input.planHandle.trim().length === 0) {
|
|
27
|
+
return invalidShopifyProviderContext("planHandle must be a non-empty string");
|
|
28
|
+
}
|
|
29
|
+
const start = normalizeShopifyProviderContextDate("currentPeriodStart", input.currentPeriodStart);
|
|
30
|
+
const end = normalizeShopifyProviderContextDate("currentPeriodEnd", input.currentPeriodEnd);
|
|
31
|
+
if (start >= end) {
|
|
32
|
+
return invalidShopifyProviderContext("currentPeriodStart must be before currentPeriodEnd");
|
|
33
|
+
}
|
|
34
|
+
return `app-pricing:v1:${encodeURIComponent(input.planHandle.trim())}:${start.toISOString()}:${end.toISOString()}`;
|
|
35
|
+
}
|
|
36
|
+
function isSameShopifyPurchaseProviderContext(purchase, current) {
|
|
37
|
+
return [
|
|
38
|
+
[purchase.providerContextIdentity, current.providerContextIdentity],
|
|
39
|
+
[purchase.shopifyPlanHandleSnapshot, current.shopifyPlanHandle],
|
|
40
|
+
[purchase.billingPeriodId, current.billingPeriodId]
|
|
41
|
+
].every(
|
|
42
|
+
([purchaseValue, currentValue]) => typeof purchaseValue === "string" && typeof currentValue === "string" && purchaseValue.trim() === currentValue.trim()
|
|
43
|
+
);
|
|
44
|
+
}
|
|
9
45
|
var BILLING_PLAN_KINDS = ["FREE", "PAID_METERED"];
|
|
10
46
|
var BillingPlanKindSchema = z.enum(BILLING_PLAN_KINDS);
|
|
11
47
|
var BILLING_USAGE_METRICS = [
|
|
@@ -17,66 +53,27 @@ var BILLING_USAGE_METRICS = [
|
|
|
17
53
|
var BillingUsageMetricSchema = z.enum(BILLING_USAGE_METRICS);
|
|
18
54
|
var BILLING_SYSTEM_MESSAGE_CODES = {
|
|
19
55
|
FREE_ALLOWANCE_WARNING: "BILLING_FREE_ALLOWANCE_WARNING",
|
|
20
|
-
FREE_ALLOWANCE_EXHAUSTED: "BILLING_FREE_ALLOWANCE_EXHAUSTED",
|
|
21
56
|
RECOVERY_CAPACITY_EXHAUSTED: "BILLING_RECOVERY_CAPACITY_EXHAUSTED",
|
|
22
57
|
PLAN_UPGRADED: "BILLING_PLAN_UPGRADED",
|
|
23
58
|
PLAN_DOWNGRADE_SCHEDULED: "BILLING_PLAN_DOWNGRADE_SCHEDULED",
|
|
24
59
|
SUBSCRIPTION_ENDED: "BILLING_SUBSCRIPTION_ENDED",
|
|
25
60
|
SAFETY_LIMIT_REACHED: "BILLING_SAFETY_LIMIT_REACHED",
|
|
26
|
-
PLAN_CHANGE_ACTION_REQUIRED: "BILLING_PLAN_CHANGE_ACTION_REQUIRED",
|
|
27
|
-
CANCELLATION_REQUEST_RECEIVED: "BILLING_CANCELLATION_REQUEST_RECEIVED",
|
|
28
|
-
CANCELLATION_COMPLETED: "BILLING_CANCELLATION_COMPLETED",
|
|
29
|
-
CANCELLATION_REJECTED: "BILLING_CANCELLATION_REJECTED",
|
|
30
61
|
REFUND_REQUEST_RECEIVED: "BILLING_REFUND_REQUEST_RECEIVED",
|
|
31
62
|
REFUND_COMPLETED: "BILLING_REFUND_COMPLETED",
|
|
32
63
|
REFUND_REJECTED: "BILLING_REFUND_REJECTED"
|
|
33
64
|
};
|
|
34
65
|
var BILLING_SYSTEM_MESSAGE_CODE_VALUES = [
|
|
35
66
|
BILLING_SYSTEM_MESSAGE_CODES.FREE_ALLOWANCE_WARNING,
|
|
36
|
-
BILLING_SYSTEM_MESSAGE_CODES.FREE_ALLOWANCE_EXHAUSTED,
|
|
37
67
|
BILLING_SYSTEM_MESSAGE_CODES.RECOVERY_CAPACITY_EXHAUSTED,
|
|
38
68
|
BILLING_SYSTEM_MESSAGE_CODES.PLAN_UPGRADED,
|
|
39
69
|
BILLING_SYSTEM_MESSAGE_CODES.PLAN_DOWNGRADE_SCHEDULED,
|
|
40
70
|
BILLING_SYSTEM_MESSAGE_CODES.SUBSCRIPTION_ENDED,
|
|
41
71
|
BILLING_SYSTEM_MESSAGE_CODES.SAFETY_LIMIT_REACHED,
|
|
42
|
-
BILLING_SYSTEM_MESSAGE_CODES.PLAN_CHANGE_ACTION_REQUIRED,
|
|
43
|
-
BILLING_SYSTEM_MESSAGE_CODES.CANCELLATION_REQUEST_RECEIVED,
|
|
44
|
-
BILLING_SYSTEM_MESSAGE_CODES.CANCELLATION_COMPLETED,
|
|
45
|
-
BILLING_SYSTEM_MESSAGE_CODES.CANCELLATION_REJECTED,
|
|
46
72
|
BILLING_SYSTEM_MESSAGE_CODES.REFUND_REQUEST_RECEIVED,
|
|
47
73
|
BILLING_SYSTEM_MESSAGE_CODES.REFUND_COMPLETED,
|
|
48
74
|
BILLING_SYSTEM_MESSAGE_CODES.REFUND_REJECTED
|
|
49
75
|
];
|
|
50
76
|
var BillingSystemMessageCodeSchema = z.enum(BILLING_SYSTEM_MESSAGE_CODE_VALUES);
|
|
51
|
-
var SUBSCRIPTION_CANCELLATION_MODES = [
|
|
52
|
-
"END_OF_CYCLE",
|
|
53
|
-
"IMMEDIATE_NO_PRORATION",
|
|
54
|
-
"IMMEDIATE_PRORATED",
|
|
55
|
-
"IMMEDIATE_SKIP_FINAL_USAGE"
|
|
56
|
-
];
|
|
57
|
-
var SubscriptionCancellationModeSchema = z.enum(SUBSCRIPTION_CANCELLATION_MODES);
|
|
58
|
-
var SHOPIFY_SUBSCRIPTION_CANCELLATION_ARGS = {
|
|
59
|
-
END_OF_CYCLE: {
|
|
60
|
-
deferCancellation: true,
|
|
61
|
-
prorate: false,
|
|
62
|
-
skipFinalUsageCharge: false
|
|
63
|
-
},
|
|
64
|
-
IMMEDIATE_NO_PRORATION: {
|
|
65
|
-
deferCancellation: false,
|
|
66
|
-
prorate: false,
|
|
67
|
-
skipFinalUsageCharge: false
|
|
68
|
-
},
|
|
69
|
-
IMMEDIATE_PRORATED: {
|
|
70
|
-
deferCancellation: false,
|
|
71
|
-
prorate: true,
|
|
72
|
-
skipFinalUsageCharge: false
|
|
73
|
-
},
|
|
74
|
-
IMMEDIATE_SKIP_FINAL_USAGE: {
|
|
75
|
-
deferCancellation: false,
|
|
76
|
-
prorate: false,
|
|
77
|
-
skipFinalUsageCharge: true
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
77
|
function availablePurchasedRecoveryCredits(counter) {
|
|
81
78
|
for (const [name, value] of Object.entries(counter)) {
|
|
82
79
|
if (!Number.isInteger(value) || value < 0) {
|
|
@@ -183,15 +180,14 @@ export {
|
|
|
183
180
|
BILLING_SUBSCRIPTION_RECONCILE_QUEUE_NAME,
|
|
184
181
|
BILLING_SUBSCRIPTION_RECONCILE_JOB_NAME,
|
|
185
182
|
APP_PRICING_BILLING_PERIOD_DRAIN_WINDOW_MS,
|
|
183
|
+
deriveShopifyProviderContextIdentity,
|
|
184
|
+
isSameShopifyPurchaseProviderContext,
|
|
186
185
|
BILLING_PLAN_KINDS,
|
|
187
186
|
BillingPlanKindSchema,
|
|
188
187
|
BILLING_USAGE_METRICS,
|
|
189
188
|
BillingUsageMetricSchema,
|
|
190
189
|
BILLING_SYSTEM_MESSAGE_CODES,
|
|
191
190
|
BillingSystemMessageCodeSchema,
|
|
192
|
-
SUBSCRIPTION_CANCELLATION_MODES,
|
|
193
|
-
SubscriptionCancellationModeSchema,
|
|
194
|
-
SHOPIFY_SUBSCRIPTION_CANCELLATION_ARGS,
|
|
195
191
|
availablePurchasedRecoveryCredits,
|
|
196
192
|
WHATSAPP_PROVIDER_STATUSES,
|
|
197
193
|
WhatsAppProviderStatusSchema,
|
|
@@ -207,4 +203,4 @@ export {
|
|
|
207
203
|
createRecoveryIdempotencyKey,
|
|
208
204
|
createShopifyUsageIdempotencyKey
|
|
209
205
|
};
|
|
210
|
-
//# sourceMappingURL=chunk-
|
|
206
|
+
//# sourceMappingURL=chunk-MBIECH3Y.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/billing.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const ARCH007_BILLING_CONTRACT_SCHEMA_VERSION = 1 as const;\nexport const WHATSAPP_PROVIDER_STATUS_SCHEMA_VERSION = 2 as const;\nexport const BILLING_SUBSCRIPTION_RECONCILE_SCHEMA_VERSION = 1 as const;\nexport const BILLING_SUBSCRIPTION_RECONCILE_QUEUE_NAME = \"billing-subscription-reconcile\";\nexport const BILLING_SUBSCRIPTION_RECONCILE_JOB_NAME = \"reconcile-subscription\";\nexport const APP_PRICING_BILLING_PERIOD_DRAIN_WINDOW_MS = 300000 as const;\n\nconst SHOPIFY_PROVIDER_CONTEXT_INVALID_PREFIX = \"SHOPIFY_PROVIDER_CONTEXT_INVALID:\";\n\nexport type ShopifyProviderContextIdentityInput = Readonly<{\n providerSubscriptionId: string | null;\n planHandle: string;\n currentPeriodStart: Date | string | null;\n currentPeriodEnd: Date | string | null;\n}>;\n\nexport type ShopifyPurchaseProviderContext = Readonly<{\n providerContextIdentity: string;\n shopifyPlanHandleSnapshot: string;\n billingPeriodId: string;\n}>;\n\nexport type ShopifyCurrentProviderContext = Readonly<{\n providerContextIdentity: string;\n shopifyPlanHandle: string;\n billingPeriodId: string;\n}>;\n\nfunction invalidShopifyProviderContext(reason: string): never {\n throw new Error(`${SHOPIFY_PROVIDER_CONTEXT_INVALID_PREFIX}${reason}`);\n}\n\nfunction normalizeShopifyProviderContextDate(\n name: string,\n value: Date | string | null,\n): Date {\n if (value === null || (typeof value !== \"string\" && !(value instanceof Date))) {\n return invalidShopifyProviderContext(`${name} must be a valid date`);\n }\n\n const date = value instanceof Date ? new Date(value.getTime()) : new Date(value);\n if (Number.isNaN(date.getTime())) {\n return invalidShopifyProviderContext(`${name} must be a valid date`);\n }\n return date;\n}\n\nexport function deriveShopifyProviderContextIdentity(\n input: ShopifyProviderContextIdentityInput,\n): string {\n const providerSubscriptionId = typeof input.providerSubscriptionId === \"string\"\n ? input.providerSubscriptionId.trim()\n : \"\";\n if (providerSubscriptionId) return providerSubscriptionId;\n\n if (typeof input.planHandle !== \"string\" || input.planHandle.trim().length === 0) {\n return invalidShopifyProviderContext(\"planHandle must be a non-empty string\");\n }\n\n const start = normalizeShopifyProviderContextDate(\"currentPeriodStart\", input.currentPeriodStart);\n const end = normalizeShopifyProviderContextDate(\"currentPeriodEnd\", input.currentPeriodEnd);\n if (start >= end) {\n return invalidShopifyProviderContext(\"currentPeriodStart must be before currentPeriodEnd\");\n }\n\n return `app-pricing:v1:${encodeURIComponent(input.planHandle.trim())}:${start.toISOString()}:${end.toISOString()}`;\n}\n\nexport function isSameShopifyPurchaseProviderContext(\n purchase: ShopifyPurchaseProviderContext,\n current: ShopifyCurrentProviderContext,\n): boolean {\n return [\n [purchase.providerContextIdentity, current.providerContextIdentity],\n [purchase.shopifyPlanHandleSnapshot, current.shopifyPlanHandle],\n [purchase.billingPeriodId, current.billingPeriodId],\n ].every(([purchaseValue, currentValue]) =>\n typeof purchaseValue === \"string\"\n && typeof currentValue === \"string\"\n && purchaseValue.trim() === currentValue.trim(),\n );\n}\n\nexport const BILLING_PLAN_KINDS = [\"FREE\", \"PAID_METERED\"] as const;\nexport const BillingPlanKindSchema = z.enum(BILLING_PLAN_KINDS);\nexport type BillingPlanKind = z.infer<typeof BillingPlanKindSchema>;\n\nexport const BILLING_USAGE_METRICS = [\n \"RECOVERY_CONVERSATION\",\n \"OUTBOUND_AUTOMATED_MESSAGE\",\n \"DELIVERED_WHATSAPP_MESSAGE\",\n \"RECOVERY_CREDIT_PACK_PURCHASE\",\n] as const;\nexport const BillingUsageMetricSchema = z.enum(BILLING_USAGE_METRICS);\nexport type BillingUsageMetric = z.infer<typeof BillingUsageMetricSchema>;\n\nexport const BILLING_SYSTEM_MESSAGE_CODES = {\n FREE_ALLOWANCE_WARNING: \"BILLING_FREE_ALLOWANCE_WARNING\",\n RECOVERY_CAPACITY_EXHAUSTED: \"BILLING_RECOVERY_CAPACITY_EXHAUSTED\",\n PLAN_UPGRADED: \"BILLING_PLAN_UPGRADED\",\n PLAN_DOWNGRADE_SCHEDULED: \"BILLING_PLAN_DOWNGRADE_SCHEDULED\",\n SUBSCRIPTION_ENDED: \"BILLING_SUBSCRIPTION_ENDED\",\n SAFETY_LIMIT_REACHED: \"BILLING_SAFETY_LIMIT_REACHED\",\n REFUND_REQUEST_RECEIVED: \"BILLING_REFUND_REQUEST_RECEIVED\",\n REFUND_COMPLETED: \"BILLING_REFUND_COMPLETED\",\n REFUND_REJECTED: \"BILLING_REFUND_REJECTED\",\n} as const;\n\nconst BILLING_SYSTEM_MESSAGE_CODE_VALUES = [\n BILLING_SYSTEM_MESSAGE_CODES.FREE_ALLOWANCE_WARNING,\n BILLING_SYSTEM_MESSAGE_CODES.RECOVERY_CAPACITY_EXHAUSTED,\n BILLING_SYSTEM_MESSAGE_CODES.PLAN_UPGRADED,\n BILLING_SYSTEM_MESSAGE_CODES.PLAN_DOWNGRADE_SCHEDULED,\n BILLING_SYSTEM_MESSAGE_CODES.SUBSCRIPTION_ENDED,\n BILLING_SYSTEM_MESSAGE_CODES.SAFETY_LIMIT_REACHED,\n BILLING_SYSTEM_MESSAGE_CODES.REFUND_REQUEST_RECEIVED,\n BILLING_SYSTEM_MESSAGE_CODES.REFUND_COMPLETED,\n BILLING_SYSTEM_MESSAGE_CODES.REFUND_REJECTED,\n] as const;\n\nexport const BillingSystemMessageCodeSchema = z.enum(BILLING_SYSTEM_MESSAGE_CODE_VALUES);\nexport type BillingSystemMessageCode = z.infer<typeof BillingSystemMessageCodeSchema>;\n\nexport type PurchasedRecoveryCreditCounterSnapshot = Readonly<{\n grantedQuantity: number;\n committedQuantity: number;\n reservedQuantity: number;\n refundingQuantity: number;\n}>;\n\nexport function availablePurchasedRecoveryCredits(\n counter: PurchasedRecoveryCreditCounterSnapshot,\n): number {\n for (const [name, value] of Object.entries(counter)) {\n if (!Number.isInteger(value) || value < 0) {\n throw new Error(`${name} must be a non-negative integer`);\n }\n }\n\n return Math.max(\n counter.grantedQuantity\n - counter.committedQuantity\n - counter.reservedQuantity\n - counter.refundingQuantity,\n 0,\n );\n}\n\nexport const WHATSAPP_PROVIDER_STATUSES = [\n \"SENT\",\n \"DELIVERED\",\n \"READ\",\n \"FAILED\",\n] as const;\nexport const WhatsAppProviderStatusSchema = z.enum(WHATSAPP_PROVIDER_STATUSES);\nexport type WhatsAppProviderStatus = z.infer<typeof WhatsAppProviderStatusSchema>;\n\nconst MAX_ID_LENGTH = 128;\nconst MAX_SHORT_TEXT_LENGTH = 128;\n\nexport const BillingSubscriptionReconcileJobSchema = z\n .object({\n schemaVersion: z.literal(BILLING_SUBSCRIPTION_RECONCILE_SCHEMA_VERSION),\n shopId: z.string().trim().min(1).max(MAX_ID_LENGTH),\n subscriptionId: z.string().trim().min(1).max(MAX_ID_LENGTH),\n expectedNextReconcileAt: z.iso.datetime({ offset: true }),\n })\n .strict();\n\nexport type BillingSubscriptionReconcileJob = z.infer<\n typeof BillingSubscriptionReconcileJobSchema\n>;\n\nexport function parseBillingSubscriptionReconcileJob(\n input: unknown,\n): BillingSubscriptionReconcileJob {\n return BillingSubscriptionReconcileJobSchema.parse(input);\n}\n\nexport function safeParseBillingSubscriptionReconcileJob(input: unknown) {\n return BillingSubscriptionReconcileJobSchema.safeParse(input);\n}\n\nexport const WhatsAppProviderPricingMetadataSchema = z\n .object({\n billable: z.boolean().optional(),\n category: z.string().trim().min(1).max(MAX_SHORT_TEXT_LENGTH).optional(),\n model: z.string().trim().min(1).max(MAX_SHORT_TEXT_LENGTH).optional(),\n })\n .strict()\n .refine((value) => Object.keys(value).length > 0, \"pricing metadata must not be empty\");\n\nexport type WhatsAppProviderPricingMetadata = z.infer<\n typeof WhatsAppProviderPricingMetadataSchema\n>;\n\nexport const NormalizedWhatsAppStatusSchema = z\n .object({\n schemaVersion: z.literal(WHATSAPP_PROVIDER_STATUS_SCHEMA_VERSION),\n providerAccountId: z.string().trim().min(1).max(MAX_ID_LENGTH),\n providerPhoneNumberId: z.string().trim().min(1).max(MAX_ID_LENGTH),\n providerMessageId: z.string().trim().min(1).max(MAX_ID_LENGTH),\n status: WhatsAppProviderStatusSchema,\n occurredAt: z.iso.datetime({ offset: true }),\n pricing: WhatsAppProviderPricingMetadataSchema.optional(),\n })\n .strict();\n\nexport type NormalizedWhatsAppStatus = z.infer<typeof NormalizedWhatsAppStatusSchema>;\n\nexport function parseNormalizedWhatsAppStatus(input: unknown): NormalizedWhatsAppStatus {\n return NormalizedWhatsAppStatusSchema.parse(input);\n}\n\nexport function safeParseNormalizedWhatsAppStatus(input: unknown) {\n return NormalizedWhatsAppStatusSchema.safeParse(input);\n}\n\nfunction assertKeyPart(name: string, value: string): void {\n if (typeof value !== \"string\" || value.trim().length === 0) {\n throw new Error(`${name} must be a non-empty string`);\n }\n}\n\nfunction fnv1a64(value: string): string {\n let hash = 0xcbf29ce484222325n;\n for (const character of value) {\n hash ^= BigInt(character.codePointAt(0) ?? 0);\n hash = BigInt.asUintN(64, hash * 0x100000001b3n);\n }\n return hash.toString(16).padStart(16, \"0\");\n}\n\nexport function createBillingSubscriptionReconcileJobId(\n subscriptionId: string,\n expectedNextReconcileAt: string,\n): string {\n assertKeyPart(\"subscriptionId\", subscriptionId);\n if (subscriptionId.trim().length > MAX_ID_LENGTH) {\n throw new Error(`subscriptionId must be at most ${MAX_ID_LENGTH} characters`);\n }\n z.iso.datetime({ offset: true }).parse(expectedNextReconcileAt);\n return `billing-subscription-reconcile-${fnv1a64(`${subscriptionId.trim()}\\u0000${expectedNextReconcileAt}`)}`;\n}\n\nfunction boundedKey(prefix: string, parts: string[], maxLength: number): string {\n const canonical = parts.map((part) => part.trim()).join(\":\");\n const readable = `${prefix}:${canonical}`;\n if (readable.length <= maxLength) return readable;\n return `${prefix}:h${fnv1a64(canonical)}`;\n}\n\nexport function createMerchantBillingSystemSourceKey(\n shopId: string,\n code: BillingSystemMessageCode,\n eventIdentity: string,\n version = 1,\n): string {\n assertKeyPart(\"shopId\", shopId);\n assertKeyPart(\"code\", code);\n assertKeyPart(\"eventIdentity\", eventIdentity);\n if (!Number.isInteger(version) || version < 1) {\n throw new Error(\"version must be a positive integer\");\n }\n return boundedKey(\"billing-system\", [shopId, code, eventIdentity, String(version)], 255);\n}\n\nexport function createRecoveryIdempotencyKey(shopId: string, recoveryId: string): string {\n assertKeyPart(\"shopId\", shopId);\n assertKeyPart(\"recoveryId\", recoveryId);\n return boundedKey(\"recovery\", [shopId, recoveryId], 255);\n}\n\nexport function createShopifyUsageIdempotencyKey(\n shopId: string,\n usageEventId: string,\n): string {\n assertKeyPart(\"shopId\", shopId);\n assertKeyPart(\"usageEventId\", usageEventId);\n return boundedKey(\"shopify\", [shopId, usageEventId], 64);\n}"],"mappings":";AAAA,SAAS,SAAS;AAEX,IAAM,0CAA0C;AAChD,IAAM,0CAA0C;AAChD,IAAM,gDAAgD;AACtD,IAAM,4CAA4C;AAClD,IAAM,0CAA0C;AAChD,IAAM,6CAA6C;AAE1D,IAAM,0CAA0C;AAqBhD,SAAS,8BAA8B,QAAuB;AAC5D,QAAM,IAAI,MAAM,GAAG,uCAAuC,GAAG,MAAM,EAAE;AACvE;AAEA,SAAS,oCACP,MACA,OACM;AACN,MAAI,UAAU,QAAS,OAAO,UAAU,YAAY,EAAE,iBAAiB,OAAQ;AAC7E,WAAO,8BAA8B,GAAG,IAAI,uBAAuB;AAAA,EACrE;AAEA,QAAM,OAAO,iBAAiB,OAAO,IAAI,KAAK,MAAM,QAAQ,CAAC,IAAI,IAAI,KAAK,KAAK;AAC/E,MAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,GAAG;AAChC,WAAO,8B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SAAO,WAAW,WAAW,CAAC,QAAQ,YAAY,GAAG,EAAE;AACzD;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { CatalogueValidationOptions, CountryCode, CountryCodeSchema, CurrencyCode, CurrencyCodeSchema, IcuMessageCatalogue, IcuMessageValues, InternationalContext, InternationalContextSchema, InternationalizationRuntime, InternationalizationRuntimeOptions, LanguageSource, LanguageSourceSchema, LanguageTag, LanguageTagSchema, TimeZoneId, TimeZoneIdSchema, canonicaliseLanguageTag, createInternationalizationRuntime, mergeInternationalContext, normalizeCountryCode, normalizeCurrencyCode, normalizeTimeZone, resolveLocaleDirection, validateIcuCatalogue } from './internationalization.js';
|
|
2
|
-
export { APP_PRICING_BILLING_PERIOD_DRAIN_WINDOW_MS, ARCH007_BILLING_CONTRACT_SCHEMA_VERSION, BILLING_PLAN_KINDS, BILLING_SUBSCRIPTION_RECONCILE_JOB_NAME, BILLING_SUBSCRIPTION_RECONCILE_QUEUE_NAME, BILLING_SUBSCRIPTION_RECONCILE_SCHEMA_VERSION, BILLING_SYSTEM_MESSAGE_CODES, BILLING_USAGE_METRICS, BillingPlanKind, BillingPlanKindSchema, BillingSubscriptionReconcileJob, BillingSubscriptionReconcileJobSchema, BillingSystemMessageCode, BillingSystemMessageCodeSchema, BillingUsageMetric, BillingUsageMetricSchema, NormalizedWhatsAppStatus, NormalizedWhatsAppStatusSchema, PurchasedRecoveryCreditCounterSnapshot,
|
|
2
|
+
export { APP_PRICING_BILLING_PERIOD_DRAIN_WINDOW_MS, ARCH007_BILLING_CONTRACT_SCHEMA_VERSION, BILLING_PLAN_KINDS, BILLING_SUBSCRIPTION_RECONCILE_JOB_NAME, BILLING_SUBSCRIPTION_RECONCILE_QUEUE_NAME, BILLING_SUBSCRIPTION_RECONCILE_SCHEMA_VERSION, BILLING_SYSTEM_MESSAGE_CODES, BILLING_USAGE_METRICS, BillingPlanKind, BillingPlanKindSchema, BillingSubscriptionReconcileJob, BillingSubscriptionReconcileJobSchema, BillingSystemMessageCode, BillingSystemMessageCodeSchema, BillingUsageMetric, BillingUsageMetricSchema, NormalizedWhatsAppStatus, NormalizedWhatsAppStatusSchema, PurchasedRecoveryCreditCounterSnapshot, ShopifyCurrentProviderContext, ShopifyProviderContextIdentityInput, ShopifyPurchaseProviderContext, WHATSAPP_PROVIDER_STATUSES, WHATSAPP_PROVIDER_STATUS_SCHEMA_VERSION, WhatsAppProviderPricingMetadata, WhatsAppProviderPricingMetadataSchema, WhatsAppProviderStatus, WhatsAppProviderStatusSchema, availablePurchasedRecoveryCredits, createBillingSubscriptionReconcileJobId, createMerchantBillingSystemSourceKey, createRecoveryIdempotencyKey, createShopifyUsageIdempotencyKey, deriveShopifyProviderContextIdentity, isSameShopifyPurchaseProviderContext, parseBillingSubscriptionReconcileJob, parseNormalizedWhatsAppStatus, safeParseBillingSubscriptionReconcileJob, safeParseNormalizedWhatsAppStatus } from './billing.js';
|
|
3
3
|
export { AuthoredSupportBodySchema, MERCHANT_COMMUNICATIONS_JOB_NAMES, MERCHANT_COMMUNICATIONS_QUEUE_NAME, MERCHANT_COMMUNICATIONS_SCHEMA_VERSION, MerchantMessageTranslationContract, MerchantMessageTranslationContractSchema, MerchantMessageTranslationStatus, MerchantMessageTranslationStatusSchema, MerchantSupportMessageContract, MerchantSupportMessageContractSchema, MerchantSupportMessageKind, MerchantSupportMessageKindSchema, MerchantSupportMessageState, MerchantSupportMessageStateSchema, MerchantTranslationBatchContract, MerchantTranslationBatchContractSchema, MerchantTranslationBatchStatus, MerchantTranslationBatchStatusSchema, MerchantTranslationDirection, MerchantTranslationDirectionSchema, MerchantTranslationReconciliationRequestContract, MerchantTranslationReconciliationRequestContractSchema, MerchantTranslationReconciliationScope, MerchantTranslationReconciliationScopeSchema, MerchantTranslationReconciliationStatus, MerchantTranslationReconciliationStatusSchema, PLATFORM_SUPPORT_LANGUAGE_TAG, TranslatedSupportBodySchema, TranslationBatchPollJob, TranslationBatchPollJobSchema, TranslationBatchResultsJob, TranslationBatchResultsJobSchema, TranslationBatchSubmitJob, TranslationBatchSubmitJobSchema, TranslationDispatchJob, TranslationDispatchJobSchema, TranslationReconcileJob, TranslationReconcileJobSchema, countUnicodeGraphemes, requiresMerchantTranslation } from './merchant-communications.js';
|
|
4
4
|
export { CheckoutCreatedPayloadV2, CheckoutCreatedPayloadV2Schema, CheckoutObservedPayload, CheckoutObservedPayloadSchema, CheckoutUpdatedPayloadV2, CheckoutUpdatedPayloadV2Schema, MAX_LINE_ITEMS, MAX_URL_LENGTH, OrderCompletedPayload, OrderCompletedPayloadSchema, OrderCompletedPayloadV2, OrderCompletedPayloadV2Schema, SHOPIFY_COMMERCE_EVENT_SCHEMA_VERSION, SHOPIFY_COMMERCE_EVENT_SCHEMA_VERSION_V1, SHOPIFY_COMMERCE_EVENT_SCHEMA_VERSION_V2, SHOPIFY_COMMERCE_EVENT_TYPES, SHOPIFY_RECOVERY_EVENT_TYPES_V2, SHOPIFY_WEBHOOK_OUTBOX_DESTINATIONS, SHOPIFY_WEBHOOK_QUEUE_CONTRACTS, ShopifyCartActivityEventV2, ShopifyCartActivityEventV2Schema, ShopifyCartActivityPayloadV2, ShopifyCartActivityPayloadV2Schema, ShopifyCheckoutCreatedEventV2, ShopifyCheckoutCreatedEventV2Schema, ShopifyCheckoutLineItem, ShopifyCheckoutLineItemSchema, ShopifyCheckoutLineItemsSchema, ShopifyCheckoutObservedEvent, ShopifyCheckoutObservedEventSchema, ShopifyCheckoutUpdatedEventV2, ShopifyCheckoutUpdatedEventV2Schema, ShopifyCommerceEvent, ShopifyCommerceEventSchema, ShopifyCommerceEventType, ShopifyCustomerReference, ShopifyCustomerReferenceSchema, ShopifyMoney, ShopifyMoneySchema, ShopifyOrderCompletedEvent, ShopifyOrderCompletedEventSchema, ShopifyOrderCompletedEventV2, ShopifyOrderCompletedEventV2Schema, ShopifyRecoveryEventTypeV2, ShopifyRecoveryEventV2, ShopifyRecoveryEventV2Schema, ShopifyTenant, ShopifyTenantSchema, createShopifyCartActivityOrderingKey, createShopifyCommerceOrderingKey, createShopifyOrderCorrelationOrderingKey, createShopifyOrderOrderingKey, createShopifyPendingRecoveryOrderingKey, isCartActivityEventV2, isCheckoutCreatedEventV2, isCheckoutObservedEvent, isCheckoutUpdatedEventV2, isOrderCompletedEvent, isOrderCompletedEventV2, parseShopifyCommerceEvent, parseShopifyRecoveryEventV2, safeParseShopifyCommerceEvent, safeParseShopifyRecoveryEventV2 } from './shopify/index.js';
|
|
5
5
|
import 'zod';
|
package/dist/index.js
CHANGED
|
@@ -12,9 +12,6 @@ import {
|
|
|
12
12
|
BillingSystemMessageCodeSchema,
|
|
13
13
|
BillingUsageMetricSchema,
|
|
14
14
|
NormalizedWhatsAppStatusSchema,
|
|
15
|
-
SHOPIFY_SUBSCRIPTION_CANCELLATION_ARGS,
|
|
16
|
-
SUBSCRIPTION_CANCELLATION_MODES,
|
|
17
|
-
SubscriptionCancellationModeSchema,
|
|
18
15
|
WHATSAPP_PROVIDER_STATUSES,
|
|
19
16
|
WHATSAPP_PROVIDER_STATUS_SCHEMA_VERSION,
|
|
20
17
|
WhatsAppProviderPricingMetadataSchema,
|
|
@@ -24,11 +21,13 @@ import {
|
|
|
24
21
|
createMerchantBillingSystemSourceKey,
|
|
25
22
|
createRecoveryIdempotencyKey,
|
|
26
23
|
createShopifyUsageIdempotencyKey,
|
|
24
|
+
deriveShopifyProviderContextIdentity,
|
|
25
|
+
isSameShopifyPurchaseProviderContext,
|
|
27
26
|
parseBillingSubscriptionReconcileJob,
|
|
28
27
|
parseNormalizedWhatsAppStatus,
|
|
29
28
|
safeParseBillingSubscriptionReconcileJob,
|
|
30
29
|
safeParseNormalizedWhatsAppStatus
|
|
31
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-MBIECH3Y.js";
|
|
32
31
|
import {
|
|
33
32
|
AuthoredSupportBodySchema,
|
|
34
33
|
MERCHANT_COMMUNICATIONS_JOB_NAMES,
|
|
@@ -163,10 +162,8 @@ export {
|
|
|
163
162
|
SHOPIFY_COMMERCE_EVENT_SCHEMA_VERSION_V2,
|
|
164
163
|
SHOPIFY_COMMERCE_EVENT_TYPES,
|
|
165
164
|
SHOPIFY_RECOVERY_EVENT_TYPES_V2,
|
|
166
|
-
SHOPIFY_SUBSCRIPTION_CANCELLATION_ARGS,
|
|
167
165
|
SHOPIFY_WEBHOOK_OUTBOX_DESTINATIONS,
|
|
168
166
|
SHOPIFY_WEBHOOK_QUEUE_CONTRACTS,
|
|
169
|
-
SUBSCRIPTION_CANCELLATION_MODES,
|
|
170
167
|
ShopifyCartActivityEventV2Schema,
|
|
171
168
|
ShopifyCartActivityPayloadV2Schema,
|
|
172
169
|
ShopifyCheckoutCreatedEventV2Schema,
|
|
@@ -181,7 +178,6 @@ export {
|
|
|
181
178
|
ShopifyOrderCompletedEventV2Schema,
|
|
182
179
|
ShopifyRecoveryEventV2Schema,
|
|
183
180
|
ShopifyTenantSchema,
|
|
184
|
-
SubscriptionCancellationModeSchema,
|
|
185
181
|
TimeZoneIdSchema,
|
|
186
182
|
TranslatedSupportBodySchema,
|
|
187
183
|
TranslationBatchPollJobSchema,
|
|
@@ -206,12 +202,14 @@ export {
|
|
|
206
202
|
createShopifyOrderOrderingKey,
|
|
207
203
|
createShopifyPendingRecoveryOrderingKey,
|
|
208
204
|
createShopifyUsageIdempotencyKey,
|
|
205
|
+
deriveShopifyProviderContextIdentity,
|
|
209
206
|
isCartActivityEventV2,
|
|
210
207
|
isCheckoutCreatedEventV2,
|
|
211
208
|
isCheckoutObservedEvent,
|
|
212
209
|
isCheckoutUpdatedEventV2,
|
|
213
210
|
isOrderCompletedEvent,
|
|
214
211
|
isOrderCompletedEventV2,
|
|
212
|
+
isSameShopifyPurchaseProviderContext,
|
|
215
213
|
mergeInternationalContext,
|
|
216
214
|
normalizeCountryCode,
|
|
217
215
|
normalizeCurrencyCode,
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/billing.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const ARCH007_BILLING_CONTRACT_SCHEMA_VERSION = 1 as const;\nexport const WHATSAPP_PROVIDER_STATUS_SCHEMA_VERSION = 2 as const;\nexport const BILLING_SUBSCRIPTION_RECONCILE_SCHEMA_VERSION = 1 as const;\nexport const BILLING_SUBSCRIPTION_RECONCILE_QUEUE_NAME = \"billing-subscription-reconcile\";\nexport const BILLING_SUBSCRIPTION_RECONCILE_JOB_NAME = \"reconcile-subscription\";\nexport const APP_PRICING_BILLING_PERIOD_DRAIN_WINDOW_MS = 300000 as const;\n\nexport const BILLING_PLAN_KINDS = [\"FREE\", \"PAID_METERED\"] as const;\nexport const BillingPlanKindSchema = z.enum(BILLING_PLAN_KINDS);\nexport type BillingPlanKind = z.infer<typeof BillingPlanKindSchema>;\n\nexport const BILLING_USAGE_METRICS = [\n \"RECOVERY_CONVERSATION\",\n \"OUTBOUND_AUTOMATED_MESSAGE\",\n \"DELIVERED_WHATSAPP_MESSAGE\",\n \"RECOVERY_CREDIT_PACK_PURCHASE\",\n] as const;\nexport const BillingUsageMetricSchema = z.enum(BILLING_USAGE_METRICS);\nexport type BillingUsageMetric = z.infer<typeof BillingUsageMetricSchema>;\n\nexport const BILLING_SYSTEM_MESSAGE_CODES = {\n FREE_ALLOWANCE_WARNING: \"BILLING_FREE_ALLOWANCE_WARNING\",\n FREE_ALLOWANCE_EXHAUSTED: \"BILLING_FREE_ALLOWANCE_EXHAUSTED\",\n RECOVERY_CAPACITY_EXHAUSTED: \"BILLING_RECOVERY_CAPACITY_EXHAUSTED\",\n PLAN_UPGRADED: \"BILLING_PLAN_UPGRADED\",\n PLAN_DOWNGRADE_SCHEDULED: \"BILLING_PLAN_DOWNGRADE_SCHEDULED\",\n SUBSCRIPTION_ENDED: \"BILLING_SUBSCRIPTION_ENDED\",\n SAFETY_LIMIT_REACHED: \"BILLING_SAFETY_LIMIT_REACHED\",\n PLAN_CHANGE_ACTION_REQUIRED: \"BILLING_PLAN_CHANGE_ACTION_REQUIRED\",\n CANCELLATION_REQUEST_RECEIVED: \"BILLING_CANCELLATION_REQUEST_RECEIVED\",\n CANCELLATION_COMPLETED: \"BILLING_CANCELLATION_COMPLETED\",\n CANCELLATION_REJECTED: \"BILLING_CANCELLATION_REJECTED\",\n REFUND_REQUEST_RECEIVED: \"BILLING_REFUND_REQUEST_RECEIVED\",\n REFUND_COMPLETED: \"BILLING_REFUND_COMPLETED\",\n REFUND_REJECTED: \"BILLING_REFUND_REJECTED\",\n} as const;\n\nconst BILLING_SYSTEM_MESSAGE_CODE_VALUES = [\n BILLING_SYSTEM_MESSAGE_CODES.FREE_ALLOWANCE_WARNING,\n BILLING_SYSTEM_MESSAGE_CODES.FREE_ALLOWANCE_EXHAUSTED,\n BILLING_SYSTEM_MESSAGE_CODES.RECOVERY_CAPACITY_EXHAUSTED,\n BILLING_SYSTEM_MESSAGE_CODES.PLAN_UPGRADED,\n BILLING_SYSTEM_MESSAGE_CODES.PLAN_DOWNGRADE_SCHEDULED,\n BILLING_SYSTEM_MESSAGE_CODES.SUBSCRIPTION_ENDED,\n BILLING_SYSTEM_MESSAGE_CODES.SAFETY_LIMIT_REACHED,\n BILLING_SYSTEM_MESSAGE_CODES.PLAN_CHANGE_ACTION_REQUIRED,\n BILLING_SYSTEM_MESSAGE_CODES.CANCELLATION_REQUEST_RECEIVED,\n BILLING_SYSTEM_MESSAGE_CODES.CANCELLATION_COMPLETED,\n BILLING_SYSTEM_MESSAGE_CODES.CANCELLATION_REJECTED,\n BILLING_SYSTEM_MESSAGE_CODES.REFUND_REQUEST_RECEIVED,\n BILLING_SYSTEM_MESSAGE_CODES.REFUND_COMPLETED,\n BILLING_SYSTEM_MESSAGE_CODES.REFUND_REJECTED,\n] as const;\n\nexport const BillingSystemMessageCodeSchema = z.enum(BILLING_SYSTEM_MESSAGE_CODE_VALUES);\nexport type BillingSystemMessageCode = z.infer<typeof BillingSystemMessageCodeSchema>;\n\nexport const SUBSCRIPTION_CANCELLATION_MODES = [\n \"END_OF_CYCLE\",\n \"IMMEDIATE_NO_PRORATION\",\n \"IMMEDIATE_PRORATED\",\n \"IMMEDIATE_SKIP_FINAL_USAGE\",\n] as const;\n\nexport const SubscriptionCancellationModeSchema = z.enum(SUBSCRIPTION_CANCELLATION_MODES);\nexport type SubscriptionCancellationMode = z.infer<typeof SubscriptionCancellationModeSchema>;\n\nexport type ShopifySubscriptionCancellationArgs = Readonly<{\n deferCancellation: boolean;\n prorate: boolean;\n skipFinalUsageCharge: boolean;\n}>;\n\nexport const SHOPIFY_SUBSCRIPTION_CANCELLATION_ARGS = {\n END_OF_CYCLE: {\n deferCancellation: true,\n prorate: false,\n skipFinalUsageCharge: false,\n },\n IMMEDIATE_NO_PRORATION: {\n deferCancellation: false,\n prorate: false,\n skipFinalUsageCharge: false,\n },\n IMMEDIATE_PRORATED: {\n deferCancellation: false,\n prorate: true,\n skipFinalUsageCharge: false,\n },\n IMMEDIATE_SKIP_FINAL_USAGE: {\n deferCancellation: false,\n prorate: false,\n skipFinalUsageCharge: true,\n },\n} as const satisfies Readonly<\n Record<SubscriptionCancellationMode, ShopifySubscriptionCancellationArgs>\n>;\n\nexport type PurchasedRecoveryCreditCounterSnapshot = Readonly<{\n grantedQuantity: number;\n committedQuantity: number;\n reservedQuantity: number;\n refundingQuantity: number;\n}>;\n\nexport function availablePurchasedRecoveryCredits(\n counter: PurchasedRecoveryCreditCounterSnapshot,\n): number {\n for (const [name, value] of Object.entries(counter)) {\n if (!Number.isInteger(value) || value < 0) {\n throw new Error(`${name} must be a non-negative integer`);\n }\n }\n\n return Math.max(\n counter.grantedQuantity\n - counter.committedQuantity\n - counter.reservedQuantity\n - counter.refundingQuantity,\n 0,\n );\n}\n\nexport const WHATSAPP_PROVIDER_STATUSES = [\n \"SENT\",\n \"DELIVERED\",\n \"READ\",\n \"FAILED\",\n] as const;\nexport const WhatsAppProviderStatusSchema = z.enum(WHATSAPP_PROVIDER_STATUSES);\nexport type WhatsAppProviderStatus = z.infer<typeof WhatsAppProviderStatusSchema>;\n\nconst MAX_ID_LENGTH = 128;\nconst MAX_SHORT_TEXT_LENGTH = 128;\n\nexport const BillingSubscriptionReconcileJobSchema = z\n .object({\n schemaVersion: z.literal(BILLING_SUBSCRIPTION_RECONCILE_SCHEMA_VERSION),\n shopId: z.string().trim().min(1).max(MAX_ID_LENGTH),\n subscriptionId: z.string().trim().min(1).max(MAX_ID_LENGTH),\n expectedNextReconcileAt: z.iso.datetime({ offset: true }),\n })\n .strict();\n\nexport type BillingSubscriptionReconcileJob = z.infer<\n typeof BillingSubscriptionReconcileJobSchema\n>;\n\nexport function parseBillingSubscriptionReconcileJob(\n input: unknown,\n): BillingSubscriptionReconcileJob {\n return BillingSubscriptionReconcileJobSchema.parse(input);\n}\n\nexport function safeParseBillingSubscriptionReconcileJob(input: unknown) {\n return BillingSubscriptionReconcileJobSchema.safeParse(input);\n}\n\nexport const WhatsAppProviderPricingMetadataSchema = z\n .object({\n billable: z.boolean().optional(),\n category: z.string().trim().min(1).max(MAX_SHORT_TEXT_LENGTH).optional(),\n model: z.string().trim().min(1).max(MAX_SHORT_TEXT_LENGTH).optional(),\n })\n .strict()\n .refine((value) => Object.keys(value).length > 0, \"pricing metadata must not be empty\");\n\nexport type WhatsAppProviderPricingMetadata = z.infer<\n typeof WhatsAppProviderPricingMetadataSchema\n>;\n\nexport const NormalizedWhatsAppStatusSchema = z\n .object({\n schemaVersion: z.literal(WHATSAPP_PROVIDER_STATUS_SCHEMA_VERSION),\n providerAccountId: z.string().trim().min(1).max(MAX_ID_LENGTH),\n providerPhoneNumberId: z.string().trim().min(1).max(MAX_ID_LENGTH),\n providerMessageId: z.string().trim().min(1).max(MAX_ID_LENGTH),\n status: WhatsAppProviderStatusSchema,\n occurredAt: z.iso.datetime({ offset: true }),\n pricing: WhatsAppProviderPricingMetadataSchema.optional(),\n })\n .strict();\n\nexport type NormalizedWhatsAppStatus = z.infer<typeof NormalizedWhatsAppStatusSchema>;\n\nexport function parseNormalizedWhatsAppStatus(input: unknown): NormalizedWhatsAppStatus {\n return NormalizedWhatsAppStatusSchema.parse(input);\n}\n\nexport function safeParseNormalizedWhatsAppStatus(input: unknown) {\n return NormalizedWhatsAppStatusSchema.safeParse(input);\n}\n\nfunction assertKeyPart(name: string, value: string): void {\n if (typeof value !== \"string\" || value.trim().length === 0) {\n throw new Error(`${name} must be a non-empty string`);\n }\n}\n\nfunction fnv1a64(value: string): string {\n let hash = 0xcbf29ce484222325n;\n for (const character of value) {\n hash ^= BigInt(character.codePointAt(0) ?? 0);\n hash = BigInt.asUintN(64, hash * 0x100000001b3n);\n }\n return hash.toString(16).padStart(16, \"0\");\n}\n\nexport function createBillingSubscriptionReconcileJobId(\n subscriptionId: string,\n expectedNextReconcileAt: string,\n): string {\n assertKeyPart(\"subscriptionId\", subscriptionId);\n if (subscriptionId.trim().length > MAX_ID_LENGTH) {\n throw new Error(`subscriptionId must be at most ${MAX_ID_LENGTH} characters`);\n }\n z.iso.datetime({ offset: true }).parse(expectedNextReconcileAt);\n return `billing-subscription-reconcile-${fnv1a64(`${subscriptionId.trim()}\\u0000${expectedNextReconcileAt}`)}`;\n}\n\nfunction boundedKey(prefix: string, parts: string[], maxLength: number): string {\n const canonical = parts.map((part) => part.trim()).join(\":\");\n const readable = `${prefix}:${canonical}`;\n if (readable.length <= maxLength) return readable;\n return `${prefix}:h${fnv1a64(canonical)}`;\n}\n\nexport function createMerchantBillingSystemSourceKey(\n shopId: string,\n code: BillingSystemMessageCode,\n eventIdentity: string,\n version = 1,\n): string {\n assertKeyPart(\"shopId\", shopId);\n assertKeyPart(\"code\", code);\n assertKeyPart(\"eventIdentity\", eventIdentity);\n if (!Number.isInteger(version) || version < 1) {\n throw new Error(\"version must be a positive integer\");\n }\n return boundedKey(\"billing-system\", [shopId, code, eventIdentity, String(version)], 255);\n}\n\nexport function createRecoveryIdempotencyKey(shopId: string, recoveryId: string): string {\n assertKeyPart(\"shopId\", shopId);\n assertKeyPart(\"recoveryId\", recoveryId);\n return boundedKey(\"recovery\", [shopId, recoveryId], 255);\n}\n\nexport function createShopifyUsageIdempotencyKey(\n shopId: string,\n usageEventId: string,\n): string {\n assertKeyPart(\"shopId\", shopId);\n assertKeyPart(\"usageEventId\", usageEventId);\n return boundedKey(\"shopify\", [shopId, usageEventId], 64);\n}"],"mappings":";AAAA,SAAS,SAAS;AAEX,IAAM,0CAA0C;AAChD,IAAM,0CAA0C;AAChD,IAAM,gDAAgD;AACtD,IAAM,4CAA4C;AAClD,IAAM,0CAA0C;AAChD,IAAM,6CAA6C;AAEnD,IAAM,qBAAqB,CAAC,QAAQ,cAAc;AAClD,IAAM,wBAAwB,EAAE,KAAK,kBAAkB;AAGvD,IAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACO,IAAM,2BAA2B,EAAE,KAAK,qBAAqB;AAG7D,IAAM,+BAA+B;AAAA,EAC1C,wBAAwB;AAAA,EACxB,0BAA0B;AAAA,EAC1B,6BAA6B;AAAA,EAC7B,eAAe;AAAA,EACf,0BAA0B;AAAA,EAC1B,oBAAoB;AAAA,EACpB,sBAAsB;AAAA,EACtB,6BAA6B;AAAA,EAC7B,+BAA+B;AAAA,EAC/B,wBAAwB;AAAA,EACxB,uBAAuB;AAAA,EACvB,yBAAyB;AAAA,EACzB,kBAAkB;AAAA,EAClB,iBAAiB;AACnB;AAEA,IAAM,qCAAqC;AAAA,EACzC,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAC/B;AAEO,IAAM,iCAAiC,EAAE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