@modainteract/moda-interact-shared 0.1.0 → 0.2.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/README.md +438 -58
- package/dist/chunk-T6DNWLWW.js +303 -0
- package/dist/chunk-T6DNWLWW.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +43 -7
- package/dist/logging/index.d.ts +45 -0
- package/dist/logging/index.js +199 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/shopify/index.d.ts +266 -10
- package/dist/shopify/index.js +43 -7
- package/dist/shopify/node.d.ts +6 -3
- package/dist/shopify/node.js +22 -7
- package/dist/shopify/node.js.map +1 -1
- package/package.json +5 -1
- package/dist/chunk-NE5RMNXU.js +0 -142
- package/dist/chunk-NE5RMNXU.js.map +0 -1
package/dist/shopify/node.js
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
// src/shopify/node.ts
|
|
2
2
|
import { createHash } from "crypto";
|
|
3
|
-
function
|
|
4
|
-
if (typeof
|
|
5
|
-
throw new Error(
|
|
3
|
+
function createShopifyWebhookJobDigest(prefix, first, second) {
|
|
4
|
+
if (typeof first !== "string" || first.length === 0) {
|
|
5
|
+
throw new Error(`${prefix}: first input must be a non-empty string`);
|
|
6
6
|
}
|
|
7
|
-
if (typeof
|
|
8
|
-
throw new Error(
|
|
7
|
+
if (typeof second !== "string" || second.length === 0) {
|
|
8
|
+
throw new Error(`${prefix}: second input must be a non-empty string`);
|
|
9
9
|
}
|
|
10
|
-
const digest = createHash("sha256").update(`${
|
|
11
|
-
return
|
|
10
|
+
const digest = createHash("sha256").update(`${first}:${second}`).digest("hex");
|
|
11
|
+
return `${prefix}-${digest}`;
|
|
12
|
+
}
|
|
13
|
+
function createShopifyWebhookJobId(appKey, deliveryId) {
|
|
14
|
+
return createShopifyWebhookJobDigest("shopify", appKey, deliveryId);
|
|
15
|
+
}
|
|
16
|
+
function createShopifyCheckoutJobId(shopId, checkoutToken) {
|
|
17
|
+
return createShopifyWebhookJobDigest("checkout", shopId, checkoutToken);
|
|
18
|
+
}
|
|
19
|
+
function createShopifyOrderJobId(shopId, orderGid) {
|
|
20
|
+
return createShopifyWebhookJobDigest("order-created", shopId, orderGid);
|
|
21
|
+
}
|
|
22
|
+
function createPendingRecoveryCandidateJobId(shopId, checkoutToken) {
|
|
23
|
+
return createShopifyWebhookJobDigest("pending-recovery", shopId, checkoutToken);
|
|
12
24
|
}
|
|
13
25
|
export {
|
|
26
|
+
createPendingRecoveryCandidateJobId,
|
|
27
|
+
createShopifyCheckoutJobId,
|
|
28
|
+
createShopifyOrderJobId,
|
|
14
29
|
createShopifyWebhookJobId
|
|
15
30
|
};
|
|
16
31
|
//# sourceMappingURL=node.js.map
|
package/dist/shopify/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/shopify/node.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\n\
|
|
1
|
+
{"version":3,"sources":["../../src/shopify/node.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\n\nfunction createShopifyWebhookJobDigest(prefix: string, first: string, second: string): string {\n if (typeof first !== \"string\" || first.length === 0) {\n throw new Error(`${prefix}: first input must be a non-empty string`);\n }\n\n if (typeof second !== \"string\" || second.length === 0) {\n throw new Error(`${prefix}: second input must be a non-empty string`);\n }\n\n const digest = createHash(\"sha256\").update(`${first}:${second}`).digest(\"hex\");\n return `${prefix}-${digest}`;\n}\n\n/**\n * Legacy webhook delivery job id used by earlier receipt/outbox flows.\n * Prefer the resource-scoped helpers below for current queue publication.\n */\nexport function createShopifyWebhookJobId(appKey: string, deliveryId: string): string {\n return createShopifyWebhookJobDigest(\"shopify\", appKey, deliveryId);\n}\n\nexport function createShopifyCheckoutJobId(shopId: string, checkoutToken: string): string {\n return createShopifyWebhookJobDigest(\"checkout\", shopId, checkoutToken);\n}\n\nexport function createShopifyOrderJobId(shopId: string, orderGid: string): string {\n return createShopifyWebhookJobDigest(\"order-created\", shopId, orderGid);\n}\n\nexport function createPendingRecoveryCandidateJobId(\n shopId: string,\n checkoutToken: string,\n): string {\n return createShopifyWebhookJobDigest(\"pending-recovery\", shopId, checkoutToken);\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAE3B,SAAS,8BAA8B,QAAgB,OAAe,QAAwB;AAC5F,MAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAAG;AACnD,UAAM,IAAI,MAAM,GAAG,MAAM,0CAA0C;AAAA,EACrE;AAEA,MAAI,OAAO,WAAW,YAAY,OAAO,WAAW,GAAG;AACrD,UAAM,IAAI,MAAM,GAAG,MAAM,2CAA2C;AAAA,EACtE;AAEA,QAAM,SAAS,WAAW,QAAQ,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,EAAE,EAAE,OAAO,KAAK;AAC7E,SAAO,GAAG,MAAM,IAAI,MAAM;AAC5B;AAMO,SAAS,0BAA0B,QAAgB,YAA4B;AACpF,SAAO,8BAA8B,WAAW,QAAQ,UAAU;AACpE;AAEO,SAAS,2BAA2B,QAAgB,eAA+B;AACxF,SAAO,8BAA8B,YAAY,QAAQ,aAAa;AACxE;AAEO,SAAS,wBAAwB,QAAgB,UAA0B;AAChF,SAAO,8BAA8B,iBAAiB,QAAQ,QAAQ;AACxE;AAEO,SAAS,oCACd,QACA,eACQ;AACR,SAAO,8BAA8B,oBAAoB,QAAQ,aAAa;AAChF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modainteract/moda-interact-shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"./shopify/node": {
|
|
20
20
|
"types": "./dist/shopify/node.d.ts",
|
|
21
21
|
"import": "./dist/shopify/node.js"
|
|
22
|
+
},
|
|
23
|
+
"./logging": {
|
|
24
|
+
"types": "./dist/logging/index.d.ts",
|
|
25
|
+
"import": "./dist/logging/index.js"
|
|
22
26
|
}
|
|
23
27
|
},
|
|
24
28
|
"files": [
|
package/dist/chunk-NE5RMNXU.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
// src/shopify/constants.ts
|
|
2
|
-
var SHOPIFY_COMMERCE_EVENT_SCHEMA_VERSION = 1;
|
|
3
|
-
var SHOPIFY_COMMERCE_QUEUE = "commerce-events";
|
|
4
|
-
var SHOPIFY_COMMERCE_JOB = "shopify-commerce-event";
|
|
5
|
-
var SHOPIFY_COMMERCE_EVENT_TYPES = {
|
|
6
|
-
CHECKOUT_OBSERVED: "checkout.observed",
|
|
7
|
-
ORDER_COMPLETED: "order.completed"
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
// src/shopify/common.schema.ts
|
|
11
|
-
import { z } from "zod";
|
|
12
|
-
var MAX_ID_LENGTH = 100;
|
|
13
|
-
var MAX_SHORT_TEXT_LENGTH = 320;
|
|
14
|
-
var MAX_TITLE_LENGTH = 500;
|
|
15
|
-
var MAX_URL_LENGTH = 2048;
|
|
16
|
-
var MAX_LINE_ITEMS = 250;
|
|
17
|
-
var decimalStringPattern = /^-?\d+(\.\d+)?$/;
|
|
18
|
-
var DecimalStringSchema = z.string().min(1).max(32).regex(decimalStringPattern, 'must be a decimal string, e.g. "12.34"');
|
|
19
|
-
var ShopifyTenantSchema = z.object({
|
|
20
|
-
shopId: z.string().min(1).max(MAX_ID_LENGTH),
|
|
21
|
-
shopDomain: z.string().min(1).max(MAX_SHORT_TEXT_LENGTH).toLowerCase().trim()
|
|
22
|
-
}).strict();
|
|
23
|
-
var ShopifyCustomerReferenceSchema = z.object({
|
|
24
|
-
shopifyCustomerId: z.string().min(1).max(MAX_ID_LENGTH).nullable(),
|
|
25
|
-
email: z.string().email().max(MAX_SHORT_TEXT_LENGTH).nullable(),
|
|
26
|
-
phone: z.string().min(1).max(64).nullable(),
|
|
27
|
-
firstName: z.string().min(1).max(MAX_TITLE_LENGTH).nullable(),
|
|
28
|
-
lastName: z.string().min(1).max(MAX_TITLE_LENGTH).nullable()
|
|
29
|
-
}).strict();
|
|
30
|
-
var ShopifyMoneySchema = z.object({
|
|
31
|
-
amount: DecimalStringSchema,
|
|
32
|
-
currencyCode: z.string().regex(/^[A-Z]{3}$/, "must be an uppercase three-letter currency code")
|
|
33
|
-
}).strict();
|
|
34
|
-
var ShopifyCheckoutLineItemSchema = z.object({
|
|
35
|
-
lineItemId: z.string().min(1).max(MAX_ID_LENGTH).nullable(),
|
|
36
|
-
variantId: z.string().min(1).max(MAX_ID_LENGTH).nullable(),
|
|
37
|
-
productId: z.string().min(1).max(MAX_ID_LENGTH).nullable(),
|
|
38
|
-
title: z.string().min(1).max(MAX_TITLE_LENGTH),
|
|
39
|
-
variantTitle: z.string().min(1).max(MAX_TITLE_LENGTH).nullable(),
|
|
40
|
-
quantity: z.number().int().positive(),
|
|
41
|
-
unitPrice: DecimalStringSchema.nullable(),
|
|
42
|
-
sku: z.string().min(1).max(MAX_ID_LENGTH).nullable()
|
|
43
|
-
}).strict();
|
|
44
|
-
var ShopifyCheckoutLineItemsSchema = z.array(ShopifyCheckoutLineItemSchema).max(MAX_LINE_ITEMS);
|
|
45
|
-
|
|
46
|
-
// src/shopify/checkout-observed.schema.ts
|
|
47
|
-
import { z as z2 } from "zod";
|
|
48
|
-
var CheckoutObservedPayloadSchema = z2.object({
|
|
49
|
-
checkoutToken: z2.string().min(1),
|
|
50
|
-
cartToken: z2.string().min(1).nullable(),
|
|
51
|
-
checkoutUrl: z2.url().max(MAX_URL_LENGTH).nullable(),
|
|
52
|
-
customer: ShopifyCustomerReferenceSchema.nullable(),
|
|
53
|
-
total: ShopifyMoneySchema.nullable(),
|
|
54
|
-
lineItems: ShopifyCheckoutLineItemsSchema,
|
|
55
|
-
checkoutCreatedAt: z2.iso.datetime().nullable(),
|
|
56
|
-
checkoutUpdatedAt: z2.iso.datetime().nullable(),
|
|
57
|
-
completedAt: z2.iso.datetime().nullable()
|
|
58
|
-
}).strict();
|
|
59
|
-
|
|
60
|
-
// src/shopify/order-completed.schema.ts
|
|
61
|
-
import { z as z3 } from "zod";
|
|
62
|
-
var OrderCompletedPayloadSchema = z3.object({
|
|
63
|
-
orderId: z3.string().min(1),
|
|
64
|
-
checkoutToken: z3.string().min(1),
|
|
65
|
-
shopifyCustomerId: z3.string().min(1).nullable(),
|
|
66
|
-
total: ShopifyMoneySchema.nullable(),
|
|
67
|
-
completedAt: z3.iso.datetime()
|
|
68
|
-
}).strict();
|
|
69
|
-
|
|
70
|
-
// src/shopify/commerce-event.schema.ts
|
|
71
|
-
import { z as z4 } from "zod";
|
|
72
|
-
var ShopifyCommerceEventBaseSchema = z4.object({
|
|
73
|
-
schemaVersion: z4.literal(SHOPIFY_COMMERCE_EVENT_SCHEMA_VERSION),
|
|
74
|
-
receiptId: z4.string().min(1),
|
|
75
|
-
deliveryId: z4.string().min(1),
|
|
76
|
-
eventId: z4.string().min(1).nullable(),
|
|
77
|
-
source: z4.literal("shopify"),
|
|
78
|
-
providerTopic: z4.string().min(1),
|
|
79
|
-
tenant: ShopifyTenantSchema,
|
|
80
|
-
occurredAt: z4.iso.datetime().nullable(),
|
|
81
|
-
receivedAt: z4.iso.datetime(),
|
|
82
|
-
traceId: z4.string().min(1),
|
|
83
|
-
orderingKey: z4.string().min(1)
|
|
84
|
-
});
|
|
85
|
-
var ShopifyCheckoutObservedEventSchema = ShopifyCommerceEventBaseSchema.extend({
|
|
86
|
-
eventType: z4.literal(SHOPIFY_COMMERCE_EVENT_TYPES.CHECKOUT_OBSERVED),
|
|
87
|
-
payload: CheckoutObservedPayloadSchema
|
|
88
|
-
}).strict();
|
|
89
|
-
var ShopifyOrderCompletedEventSchema = ShopifyCommerceEventBaseSchema.extend({
|
|
90
|
-
eventType: z4.literal(SHOPIFY_COMMERCE_EVENT_TYPES.ORDER_COMPLETED),
|
|
91
|
-
payload: OrderCompletedPayloadSchema
|
|
92
|
-
}).strict();
|
|
93
|
-
var ShopifyCommerceEventSchema = z4.discriminatedUnion("eventType", [
|
|
94
|
-
ShopifyCheckoutObservedEventSchema,
|
|
95
|
-
ShopifyOrderCompletedEventSchema
|
|
96
|
-
]);
|
|
97
|
-
function parseShopifyCommerceEvent(input) {
|
|
98
|
-
return ShopifyCommerceEventSchema.parse(input);
|
|
99
|
-
}
|
|
100
|
-
function safeParseShopifyCommerceEvent(input) {
|
|
101
|
-
return ShopifyCommerceEventSchema.safeParse(input);
|
|
102
|
-
}
|
|
103
|
-
function isCheckoutObservedEvent(event) {
|
|
104
|
-
return event.eventType === SHOPIFY_COMMERCE_EVENT_TYPES.CHECKOUT_OBSERVED;
|
|
105
|
-
}
|
|
106
|
-
function isOrderCompletedEvent(event) {
|
|
107
|
-
return event.eventType === SHOPIFY_COMMERCE_EVENT_TYPES.ORDER_COMPLETED;
|
|
108
|
-
}
|
|
109
|
-
function createShopifyCommerceOrderingKey(shopId, checkoutToken) {
|
|
110
|
-
if (typeof shopId !== "string" || shopId.length === 0) {
|
|
111
|
-
throw new Error("createShopifyCommerceOrderingKey: shopId must be a non-empty string");
|
|
112
|
-
}
|
|
113
|
-
if (typeof checkoutToken !== "string" || checkoutToken.length === 0) {
|
|
114
|
-
throw new Error("createShopifyCommerceOrderingKey: checkoutToken must be a non-empty string");
|
|
115
|
-
}
|
|
116
|
-
return `shopify:${shopId.length}:${shopId}:${checkoutToken.length}:${checkoutToken}`;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export {
|
|
120
|
-
SHOPIFY_COMMERCE_EVENT_SCHEMA_VERSION,
|
|
121
|
-
SHOPIFY_COMMERCE_QUEUE,
|
|
122
|
-
SHOPIFY_COMMERCE_JOB,
|
|
123
|
-
SHOPIFY_COMMERCE_EVENT_TYPES,
|
|
124
|
-
MAX_URL_LENGTH,
|
|
125
|
-
MAX_LINE_ITEMS,
|
|
126
|
-
ShopifyTenantSchema,
|
|
127
|
-
ShopifyCustomerReferenceSchema,
|
|
128
|
-
ShopifyMoneySchema,
|
|
129
|
-
ShopifyCheckoutLineItemSchema,
|
|
130
|
-
ShopifyCheckoutLineItemsSchema,
|
|
131
|
-
CheckoutObservedPayloadSchema,
|
|
132
|
-
OrderCompletedPayloadSchema,
|
|
133
|
-
ShopifyCheckoutObservedEventSchema,
|
|
134
|
-
ShopifyOrderCompletedEventSchema,
|
|
135
|
-
ShopifyCommerceEventSchema,
|
|
136
|
-
parseShopifyCommerceEvent,
|
|
137
|
-
safeParseShopifyCommerceEvent,
|
|
138
|
-
isCheckoutObservedEvent,
|
|
139
|
-
isOrderCompletedEvent,
|
|
140
|
-
createShopifyCommerceOrderingKey
|
|
141
|
-
};
|
|
142
|
-
//# sourceMappingURL=chunk-NE5RMNXU.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/shopify/constants.ts","../src/shopify/common.schema.ts","../src/shopify/checkout-observed.schema.ts","../src/shopify/order-completed.schema.ts","../src/shopify/commerce-event.schema.ts"],"sourcesContent":["export const SHOPIFY_COMMERCE_EVENT_SCHEMA_VERSION = 1 as const;\n\nexport const SHOPIFY_COMMERCE_QUEUE = \"commerce-events\" as const;\nexport const SHOPIFY_COMMERCE_JOB = \"shopify-commerce-event\" as const;\n\nexport const SHOPIFY_COMMERCE_EVENT_TYPES = {\n CHECKOUT_OBSERVED: \"checkout.observed\",\n ORDER_COMPLETED: \"order.completed\",\n} as const;\n","import { z } from \"zod\";\n\n/**\n * Reasonable upper bounds for externally controlled (Shopify-originated) strings.\n * These exist to keep queue messages small and predictable, not to validate business rules.\n */\nconst MAX_ID_LENGTH = 100;\nconst MAX_SHORT_TEXT_LENGTH = 320;\nconst MAX_TITLE_LENGTH = 500;\nconst MAX_URL_LENGTH = 2048;\nconst MAX_LINE_ITEMS = 250;\n\nconst decimalStringPattern = /^-?\\d+(\\.\\d+)?$/;\n\n/** Decimal amount encoded as a string; never a JS number to avoid float precision loss. */\nconst DecimalStringSchema = z\n .string()\n .min(1)\n .max(32)\n .regex(decimalStringPattern, \"must be a decimal string, e.g. \\\"12.34\\\"\");\n\nexport const ShopifyTenantSchema = z\n .object({\n shopId: z.string().min(1).max(MAX_ID_LENGTH),\n shopDomain: z\n .string()\n .min(1)\n .max(MAX_SHORT_TEXT_LENGTH)\n .toLowerCase()\n .trim(),\n })\n .strict();\n\nexport type ShopifyTenant = z.infer<typeof ShopifyTenantSchema>;\n\nexport const ShopifyCustomerReferenceSchema = z\n .object({\n shopifyCustomerId: z.string().min(1).max(MAX_ID_LENGTH).nullable(),\n email: z.string().email().max(MAX_SHORT_TEXT_LENGTH).nullable(),\n phone: z.string().min(1).max(64).nullable(),\n firstName: z.string().min(1).max(MAX_TITLE_LENGTH).nullable(),\n lastName: z.string().min(1).max(MAX_TITLE_LENGTH).nullable(),\n })\n .strict();\n\nexport type ShopifyCustomerReference = z.infer<typeof ShopifyCustomerReferenceSchema>;\n\nexport const ShopifyMoneySchema = z\n .object({\n amount: DecimalStringSchema,\n currencyCode: z\n .string()\n .regex(/^[A-Z]{3}$/, \"must be an uppercase three-letter currency code\"),\n })\n .strict();\n\nexport type ShopifyMoney = z.infer<typeof ShopifyMoneySchema>;\n\n/**\n * Fields limited to what checkout recovery and customer-facing basket context require.\n * Line-item arrays are bounded (see MAX_LINE_ITEMS) to prevent unexpectedly large queue messages.\n */\nexport const ShopifyCheckoutLineItemSchema = z\n .object({\n lineItemId: z.string().min(1).max(MAX_ID_LENGTH).nullable(),\n variantId: z.string().min(1).max(MAX_ID_LENGTH).nullable(),\n productId: z.string().min(1).max(MAX_ID_LENGTH).nullable(),\n title: z.string().min(1).max(MAX_TITLE_LENGTH),\n variantTitle: z.string().min(1).max(MAX_TITLE_LENGTH).nullable(),\n quantity: z.number().int().positive(),\n unitPrice: DecimalStringSchema.nullable(),\n sku: z.string().min(1).max(MAX_ID_LENGTH).nullable(),\n })\n .strict();\n\nexport type ShopifyCheckoutLineItem = z.infer<typeof ShopifyCheckoutLineItemSchema>;\n\nexport const ShopifyCheckoutLineItemsSchema = z\n .array(ShopifyCheckoutLineItemSchema)\n .max(MAX_LINE_ITEMS);\n\nexport { MAX_URL_LENGTH, MAX_LINE_ITEMS };\n","import { z } from \"zod\";\nimport {\n MAX_URL_LENGTH,\n ShopifyCheckoutLineItemsSchema,\n ShopifyCustomerReferenceSchema,\n ShopifyMoneySchema,\n} from \"./common.schema.js\";\n\nexport const CheckoutObservedPayloadSchema = z\n .object({\n checkoutToken: z.string().min(1),\n cartToken: z.string().min(1).nullable(),\n checkoutUrl: z.url().max(MAX_URL_LENGTH).nullable(),\n customer: ShopifyCustomerReferenceSchema.nullable(),\n total: ShopifyMoneySchema.nullable(),\n lineItems: ShopifyCheckoutLineItemsSchema,\n checkoutCreatedAt: z.iso.datetime().nullable(),\n checkoutUpdatedAt: z.iso.datetime().nullable(),\n completedAt: z.iso.datetime().nullable(),\n })\n .strict();\n\nexport type CheckoutObservedPayload = z.infer<typeof CheckoutObservedPayloadSchema>;\n","import { z } from \"zod\";\nimport { ShopifyMoneySchema } from \"./common.schema.js\";\n\nexport const OrderCompletedPayloadSchema = z\n .object({\n orderId: z.string().min(1),\n checkoutToken: z.string().min(1),\n shopifyCustomerId: z.string().min(1).nullable(),\n total: ShopifyMoneySchema.nullable(),\n completedAt: z.iso.datetime(),\n })\n .strict();\n\nexport type OrderCompletedPayload = z.infer<typeof OrderCompletedPayloadSchema>;\n","import { z } from \"zod\";\nimport { SHOPIFY_COMMERCE_EVENT_SCHEMA_VERSION, SHOPIFY_COMMERCE_EVENT_TYPES } from \"./constants.js\";\nimport { ShopifyTenantSchema } from \"./common.schema.js\";\nimport { CheckoutObservedPayloadSchema } from \"./checkout-observed.schema.js\";\nimport { OrderCompletedPayloadSchema } from \"./order-completed.schema.js\";\n\nconst ShopifyCommerceEventBaseSchema = z.object({\n schemaVersion: z.literal(SHOPIFY_COMMERCE_EVENT_SCHEMA_VERSION),\n receiptId: z.string().min(1),\n deliveryId: z.string().min(1),\n eventId: z.string().min(1).nullable(),\n source: z.literal(\"shopify\"),\n providerTopic: z.string().min(1),\n tenant: ShopifyTenantSchema,\n occurredAt: z.iso.datetime().nullable(),\n receivedAt: z.iso.datetime(),\n traceId: z.string().min(1),\n orderingKey: z.string().min(1),\n});\n\nexport const ShopifyCheckoutObservedEventSchema = ShopifyCommerceEventBaseSchema.extend({\n eventType: z.literal(SHOPIFY_COMMERCE_EVENT_TYPES.CHECKOUT_OBSERVED),\n payload: CheckoutObservedPayloadSchema,\n}).strict();\n\nexport type ShopifyCheckoutObservedEvent = z.infer<typeof ShopifyCheckoutObservedEventSchema>;\n\nexport const ShopifyOrderCompletedEventSchema = ShopifyCommerceEventBaseSchema.extend({\n eventType: z.literal(SHOPIFY_COMMERCE_EVENT_TYPES.ORDER_COMPLETED),\n payload: OrderCompletedPayloadSchema,\n}).strict();\n\nexport type ShopifyOrderCompletedEvent = z.infer<typeof ShopifyOrderCompletedEventSchema>;\n\nexport const ShopifyCommerceEventSchema = z.discriminatedUnion(\"eventType\", [\n ShopifyCheckoutObservedEventSchema,\n ShopifyOrderCompletedEventSchema,\n]);\n\nexport type ShopifyCommerceEvent = z.infer<typeof ShopifyCommerceEventSchema>;\nexport type ShopifyCommerceEventType = ShopifyCommerceEvent[\"eventType\"];\n\nexport function parseShopifyCommerceEvent(input: unknown): ShopifyCommerceEvent {\n return ShopifyCommerceEventSchema.parse(input);\n}\n\nexport function safeParseShopifyCommerceEvent(input: unknown) {\n return ShopifyCommerceEventSchema.safeParse(input);\n}\n\nexport function isCheckoutObservedEvent(\n event: ShopifyCommerceEvent,\n): event is ShopifyCheckoutObservedEvent {\n return event.eventType === SHOPIFY_COMMERCE_EVENT_TYPES.CHECKOUT_OBSERVED;\n}\n\nexport function isOrderCompletedEvent(\n event: ShopifyCommerceEvent,\n): event is ShopifyOrderCompletedEvent {\n return event.eventType === SHOPIFY_COMMERCE_EVENT_TYPES.ORDER_COMPLETED;\n}\n\n/**\n * Stable ordering key for a shop/checkout pair. Checkout and order events for the\n * same checkout must share this key, so deliveryId is intentionally excluded.\n * Values are length-prefixed to avoid ambiguous concatenation (e.g. \"1\" + \"23\" vs \"12\" + \"3\").\n */\nexport function createShopifyCommerceOrderingKey(shopId: string, checkoutToken: string): string {\n if (typeof shopId !== \"string\" || shopId.length === 0) {\n throw new Error(\"createShopifyCommerceOrderingKey: shopId must be a non-empty string\");\n }\n if (typeof checkoutToken !== \"string\" || checkoutToken.length === 0) {\n throw new Error(\"createShopifyCommerceOrderingKey: checkoutToken must be a non-empty string\");\n }\n\n return `shopify:${shopId.length}:${shopId}:${checkoutToken.length}:${checkoutToken}`;\n}\n"],"mappings":";AAAO,IAAM,wCAAwC;AAE9C,IAAM,yBAAyB;AAC/B,IAAM,uBAAuB;AAE7B,IAAM,+BAA+B;AAAA,EAC1C,mBAAmB;AAAA,EACnB,iBAAiB;AACnB;;;ACRA,SAAS,SAAS;AAMlB,IAAM,gBAAgB;AACtB,IAAM,wBAAwB;AAC9B,IAAM,mBAAmB;AACzB,IAAM,iBAAiB;AACvB,IAAM,iBAAiB;AAEvB,IAAM,uBAAuB;AAG7B,IAAM,sBAAsB,EACzB,OAAO,EACP,IAAI,CAAC,EACL,IAAI,EAAE,EACN,MAAM,sBAAsB,wCAA0C;AAElE,IAAM,sBAAsB,EAChC,OAAO;AAAA,EACN,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,aAAa;AAAA,EAC3C,YAAY,EACT,OAAO,EACP,IAAI,CAAC,EACL,IAAI,qBAAqB,EACzB,YAAY,EACZ,KAAK;AACV,CAAC,EACA,OAAO;AAIH,IAAM,iCAAiC,EAC3C,OAAO;AAAA,EACN,mBAAmB,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,aAAa,EAAE,SAAS;AAAA,EACjE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,qBAAqB,EAAE,SAAS;AAAA,EAC9D,OAAO,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