@modainteract/moda-interact-shared 5.1.0 → 5.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.
@@ -1,316 +1,15 @@
1
1
  import {
2
- CommerceEnvironmentSchema
3
- } from "../../chunk-FTUTJH7W.js";
4
- import {
5
- canonicalJson
6
- } from "../../chunk-AUS3WQIW.js";
7
-
8
- // src/security/credentials/errors.ts
9
- var MESSAGES = {
10
- INVALID_KEYRING: "Invalid credential keyring configuration",
11
- KEY_UNAVAILABLE: "Credential encryption key is unavailable",
12
- INVALID_CREDENTIAL: "Invalid encrypted credential",
13
- INVALID_COMMAND_HMAC_KEY: "Invalid command authentication key"
14
- };
15
- var CredentialSecurityError = class extends Error {
16
- code;
17
- constructor(code) {
18
- super(MESSAGES[code]);
19
- this.name = "CredentialSecurityError";
20
- this.code = code;
21
- }
22
- };
23
-
24
- // src/security/credentials/aad.ts
25
- var KEY_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
26
- var PURPOSES = /* @__PURE__ */ new Set(["MERCHANT_KNOWLEDGE", "REFERENCE_TAXONOMY"]);
27
- var FORBIDDEN_ID_CHARACTERS = /[\r\n\0]/;
28
- var INVALID_UNICODE = /\p{Surrogate}/u;
29
- var RESERVED_KEY_IDS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
30
- function invalidAad() {
31
- throw new CredentialSecurityError("INVALID_CREDENTIAL");
32
- }
33
- function isBoundedIdentifier(value, limit) {
34
- return typeof value === "string" && value.length >= 1 && value.length <= limit && value.trim().length > 0 && !FORBIDDEN_ID_CHARACTERS.test(value) && !INVALID_UNICODE.test(value);
35
- }
36
- function createCommerceEmbeddingCredentialAad(input) {
37
- if (input === null || typeof input !== "object" || !CommerceEnvironmentSchema.safeParse(input.environment).success || !PURPOSES.has(input.purpose) || !isBoundedIdentifier(input.provider, 128) || typeof input.keyId !== "string" || !KEY_ID_PATTERN.test(input.keyId) || RESERVED_KEY_IDS.has(input.keyId)) {
38
- return invalidAad();
39
- }
40
- return canonicalJson({
41
- credentialType: "EMBEDDING",
42
- environment: input.environment,
43
- purpose: input.purpose,
44
- provider: input.provider,
45
- keyId: input.keyId
46
- });
47
- }
48
- function createWooRestReadGrantAad(input) {
49
- if (input === null || typeof input !== "object" || !isBoundedIdentifier(input.shopId, 128) || !isBoundedIdentifier(input.installationId, 128) || !isBoundedIdentifier(input.authorizationAttemptId, 128) || !Number.isSafeInteger(input.credentialVersionSnapshot) || input.credentialVersionSnapshot < 1) {
50
- return invalidAad();
51
- }
52
- return JSON.stringify([
53
- "moda-woo-rest-read-v1",
54
- input.shopId,
55
- input.installationId,
56
- input.authorizationAttemptId,
57
- input.credentialVersionSnapshot
58
- ]);
59
- }
60
-
61
- // src/security/credentials/keyring.ts
62
- import { Buffer } from "buffer";
63
- var KEY_ID_PATTERN2 = /^[A-Za-z0-9_-]{1,64}$/;
64
- var STANDARD_BASE64_KEY_PATTERN = /^[A-Za-z0-9+/]{43}=$/;
65
- var RESERVED_KEY_IDS2 = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
66
- var MAX_CONFIG_BYTES = 4096;
67
- var MAX_KEYS = 16;
68
- var KEY_BYTES = 32;
69
- var privateKeys = /* @__PURE__ */ new WeakMap();
70
- function invalidKeyring() {
71
- throw new CredentialSecurityError("INVALID_KEYRING");
72
- }
73
- function readJsonString(raw, start) {
74
- if (raw[start] !== '"') invalidKeyring();
75
- let cursor = start + 1;
76
- while (cursor < raw.length) {
77
- const character = raw[cursor];
78
- if (character === "\\") {
79
- cursor += 2;
80
- continue;
81
- }
82
- if (character === '"') {
83
- const decoded = JSON.parse(raw.slice(start, cursor + 1));
84
- if (typeof decoded !== "string") invalidKeyring();
85
- return [decoded, cursor + 1];
86
- }
87
- cursor += 1;
88
- }
89
- return invalidKeyring();
90
- }
91
- function parseUniqueStringObject(raw) {
92
- let decoded;
93
- try {
94
- decoded = JSON.parse(raw);
95
- } catch {
96
- return invalidKeyring();
97
- }
98
- if (decoded === null || typeof decoded !== "object" || Array.isArray(decoded)) {
99
- return invalidKeyring();
100
- }
101
- let index = 0;
102
- const skipWhitespace = () => {
103
- while (index < raw.length && /[ \t\r\n]/.test(raw[index])) index += 1;
104
- };
105
- const entries = /* @__PURE__ */ new Map();
106
- skipWhitespace();
107
- if (raw[index++] !== "{") return invalidKeyring();
108
- skipWhitespace();
109
- if (raw[index] === "}") return invalidKeyring();
110
- while (index < raw.length) {
111
- const [key, afterKey] = readJsonString(raw, index);
112
- if (entries.has(key)) return invalidKeyring();
113
- if (!KEY_ID_PATTERN2.test(key) || RESERVED_KEY_IDS2.has(key)) return invalidKeyring();
114
- index = afterKey;
115
- skipWhitespace();
116
- if (raw[index++] !== ":") return invalidKeyring();
117
- skipWhitespace();
118
- const [value, afterValue] = readJsonString(raw, index);
119
- entries.set(key, value);
120
- if (entries.size > MAX_KEYS) return invalidKeyring();
121
- index = afterValue;
122
- skipWhitespace();
123
- const separator = raw[index++];
124
- if (separator === "}") break;
125
- if (separator !== ",") return invalidKeyring();
126
- skipWhitespace();
127
- }
128
- skipWhitespace();
129
- if (index !== raw.length || entries.size === 0) return invalidKeyring();
130
- return entries;
131
- }
132
- function parseCredentialKeyring(raw) {
133
- if (typeof raw !== "string" || raw.trim().length === 0 || Buffer.byteLength(raw, "utf8") > MAX_CONFIG_BYTES) {
134
- return invalidKeyring();
135
- }
136
- let entries;
137
- try {
138
- entries = parseUniqueStringObject(raw);
139
- } catch {
140
- return invalidKeyring();
141
- }
142
- const keys = /* @__PURE__ */ new Map();
143
- for (const [keyId, encoded] of entries) {
144
- if (!STANDARD_BASE64_KEY_PATTERN.test(encoded)) return invalidKeyring();
145
- const bytes = Buffer.from(encoded, "base64");
146
- if (bytes.length !== KEY_BYTES || bytes.toString("base64") !== encoded) {
147
- return invalidKeyring();
148
- }
149
- keys.set(keyId, Uint8Array.from(bytes));
150
- }
151
- const keyIds = Object.freeze([...keys.keys()].sort());
152
- const descriptor = Object.freeze({
153
- keyIds,
154
- hasKey: (keyId) => typeof keyId === "string" && keys.has(keyId)
155
- });
156
- privateKeys.set(descriptor, keys);
157
- return descriptor;
158
- }
159
- function resolveActiveCredentialKey(keyring, activeKeyId) {
160
- const keys = privateKeys.get(keyring);
161
- if (!keys || typeof activeKeyId !== "string" || !KEY_ID_PATTERN2.test(activeKeyId) || RESERVED_KEY_IDS2.has(activeKeyId) || !keys.has(activeKeyId)) {
162
- throw new CredentialSecurityError("KEY_UNAVAILABLE");
163
- }
164
- return activeKeyId;
165
- }
166
- function getCredentialKeyBytes(keyring, keyId) {
167
- const bytes = privateKeys.get(keyring)?.get(keyId);
168
- if (!bytes) throw new CredentialSecurityError("KEY_UNAVAILABLE");
169
- return Uint8Array.from(bytes);
170
- }
171
-
172
- // src/security/credentials/command-hmac-key.ts
173
- import { Buffer as Buffer2 } from "buffer";
174
- import { timingSafeEqual } from "crypto";
175
- var CANONICAL_BASE64_32_BYTE_KEY = /^[A-Za-z0-9+/]{43}=$/;
176
- function invalidCommandHmacKey() {
177
- throw new CredentialSecurityError("INVALID_COMMAND_HMAC_KEY");
178
- }
179
- function parseCommerceConnectionCommandHmacKey(raw, aesKeyring) {
180
- if (typeof raw !== "string" || !CANONICAL_BASE64_32_BYTE_KEY.test(raw)) {
181
- return invalidCommandHmacKey();
182
- }
183
- const decoded = Buffer2.from(raw, "base64");
184
- if (decoded.length !== 32 || decoded.toString("base64") !== raw) {
185
- return invalidCommandHmacKey();
186
- }
187
- let reusesEncryptionKey = false;
188
- try {
189
- for (const keyId of aesKeyring.keyIds) {
190
- const aesBytes = getCredentialKeyBytes(aesKeyring, keyId);
191
- try {
192
- reusesEncryptionKey = timingSafeEqual(decoded, aesBytes) || reusesEncryptionKey;
193
- } finally {
194
- aesBytes.fill(0);
195
- }
196
- }
197
- if (aesKeyring.keyIds.length === 0) return invalidCommandHmacKey();
198
- } catch {
199
- return invalidCommandHmacKey();
200
- }
201
- if (reusesEncryptionKey) return invalidCommandHmacKey();
202
- return Uint8Array.from(decoded);
203
- }
204
-
205
- // src/security/credentials/aead.ts
206
- import { Buffer as Buffer3 } from "buffer";
207
- import { createCipheriv, createDecipheriv, randomBytes } from "crypto";
208
- import { TextDecoder } from "util";
209
- var NONCE_BYTES = 12;
210
- var AUTH_TAG_BYTES = 16;
211
- var MAX_CREDENTIAL_BYTES = 8192;
212
- var MAX_AAD_BYTES = 4096;
213
- var KEY_ID_PATTERN3 = /^[A-Za-z0-9_-]{1,64}$/;
214
- var RESERVED_KEY_IDS3 = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
215
- function invalidCredential() {
216
- throw new CredentialSecurityError("INVALID_CREDENTIAL");
217
- }
218
- function isValidUnicode(value) {
219
- for (let index = 0; index < value.length; index += 1) {
220
- const unit = value.charCodeAt(index);
221
- if (unit >= 55296 && unit <= 56319) {
222
- if (index + 1 === value.length) return false;
223
- const next = value.charCodeAt(index + 1);
224
- if (next < 56320 || next > 57343) return false;
225
- index += 1;
226
- } else if (unit >= 56320 && unit <= 57343) {
227
- return false;
228
- }
229
- }
230
- return true;
231
- }
232
- function aadBytes(value) {
233
- let bytes;
234
- if (typeof value === "string") {
235
- if (!isValidUnicode(value)) return invalidCredential();
236
- bytes = Buffer3.from(value, "utf8");
237
- } else if (value instanceof Uint8Array) {
238
- bytes = Buffer3.from(value);
239
- } else {
240
- return invalidCredential();
241
- }
242
- if (bytes.length < 1 || bytes.length > MAX_AAD_BYTES) return invalidCredential();
243
- return bytes;
244
- }
245
- function validEnvelope(value) {
246
- if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
247
- const candidate = value;
248
- return typeof candidate.keyId === "string" && KEY_ID_PATTERN3.test(candidate.keyId) && !RESERVED_KEY_IDS3.has(candidate.keyId) && candidate.nonce instanceof Uint8Array && candidate.nonce.byteLength === NONCE_BYTES && candidate.ciphertext instanceof Uint8Array && candidate.ciphertext.byteLength >= 1 && candidate.ciphertext.byteLength <= MAX_CREDENTIAL_BYTES && candidate.authTag instanceof Uint8Array && candidate.authTag.byteLength === AUTH_TAG_BYTES;
249
- }
250
- function protectCredentialOperation(operation) {
251
- try {
252
- return operation();
253
- } catch (error) {
254
- if (error instanceof CredentialSecurityError) throw error;
255
- return invalidCredential();
256
- }
257
- }
258
- function encryptCredential(input) {
259
- return protectCredentialOperation(() => {
260
- if (typeof input !== "object" || input === null || Array.isArray(input)) return invalidCredential();
261
- const { keyring, activeKeyId, plaintext, aad } = input;
262
- if (typeof plaintext !== "string" || !isValidUnicode(plaintext)) return invalidCredential();
263
- const plaintextBytes = Buffer3.from(plaintext, "utf8");
264
- if (plaintextBytes.length < 1 || plaintextBytes.length > MAX_CREDENTIAL_BYTES) {
265
- plaintextBytes.fill(0);
266
- return invalidCredential();
267
- }
268
- let key;
269
- try {
270
- const authenticatedData = aadBytes(aad);
271
- const keyId = resolveActiveCredentialKey(keyring, activeKeyId);
272
- key = getCredentialKeyBytes(keyring, keyId);
273
- const nonce = randomBytes(NONCE_BYTES);
274
- const cipher = createCipheriv("aes-256-gcm", key, nonce, { authTagLength: AUTH_TAG_BYTES });
275
- cipher.setAAD(authenticatedData);
276
- const ciphertext = Buffer3.concat([cipher.update(plaintextBytes), cipher.final()]);
277
- return Object.freeze({
278
- keyId,
279
- nonce: Uint8Array.from(nonce),
280
- ciphertext: Uint8Array.from(ciphertext),
281
- authTag: Uint8Array.from(cipher.getAuthTag())
282
- });
283
- } finally {
284
- key?.fill(0);
285
- plaintextBytes.fill(0);
286
- }
287
- });
288
- }
289
- function decryptCredential(input) {
290
- return protectCredentialOperation(() => {
291
- if (typeof input !== "object" || input === null || Array.isArray(input)) return invalidCredential();
292
- const { keyring, envelope, aad } = input;
293
- if (!validEnvelope(envelope)) return invalidCredential();
294
- const authenticatedData = aadBytes(aad);
295
- const key = getCredentialKeyBytes(keyring, envelope.keyId);
296
- let plaintextBytes;
297
- try {
298
- const decipher = createDecipheriv("aes-256-gcm", key, Buffer3.from(envelope.nonce), {
299
- authTagLength: AUTH_TAG_BYTES
300
- });
301
- decipher.setAAD(authenticatedData);
302
- decipher.setAuthTag(Buffer3.from(envelope.authTag));
303
- plaintextBytes = Buffer3.concat([
304
- decipher.update(Buffer3.from(envelope.ciphertext)),
305
- decipher.final()
306
- ]);
307
- return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(plaintextBytes);
308
- } finally {
309
- plaintextBytes?.fill(0);
310
- key.fill(0);
311
- }
312
- });
313
- }
2
+ CredentialSecurityError,
3
+ createCommerceEmbeddingCredentialAad,
4
+ createWooRestReadGrantAad,
5
+ decryptCredential,
6
+ encryptCredential,
7
+ parseCommerceConnectionCommandHmacKey,
8
+ parseCredentialKeyring,
9
+ resolveActiveCredentialKey
10
+ } from "../../chunk-PZZJFC2L.js";
11
+ import "../../chunk-FTUTJH7W.js";
12
+ import "../../chunk-AUS3WQIW.js";
314
13
  export {
315
14
  CredentialSecurityError,
316
15
  createCommerceEmbeddingCredentialAad,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/security/credentials/errors.ts","../../../src/security/credentials/aad.ts","../../../src/security/credentials/keyring.ts","../../../src/security/credentials/command-hmac-key.ts","../../../src/security/credentials/aead.ts"],"sourcesContent":["/** A stable, secret-free error vocabulary shared by credential-security operations. */\nexport type CredentialSecurityErrorCode =\n | \"INVALID_KEYRING\"\n | \"KEY_UNAVAILABLE\"\n | \"INVALID_CREDENTIAL\"\n | \"INVALID_COMMAND_HMAC_KEY\";\n\nconst MESSAGES: Readonly<Record<CredentialSecurityErrorCode, string>> = {\n INVALID_KEYRING: \"Invalid credential keyring configuration\",\n KEY_UNAVAILABLE: \"Credential encryption key is unavailable\",\n INVALID_CREDENTIAL: \"Invalid encrypted credential\",\n INVALID_COMMAND_HMAC_KEY: \"Invalid command authentication key\",\n};\n\nexport class CredentialSecurityError extends Error {\n readonly code: CredentialSecurityErrorCode;\n\n constructor(code: CredentialSecurityErrorCode) {\n super(MESSAGES[code]);\n this.name = \"CredentialSecurityError\";\n this.code = code;\n }\n}\n","import { canonicalJson } from \"../../commerce/canonical-json.js\";\nimport {\n CommerceEnvironmentSchema,\n type CommerceEnvironment,\n} from \"../../commerce/model/index.js\";\nimport { CredentialSecurityError } from \"./errors.js\";\n\nconst KEY_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;\nconst PURPOSES = new Set([\"MERCHANT_KNOWLEDGE\", \"REFERENCE_TAXONOMY\"]);\nconst FORBIDDEN_ID_CHARACTERS = /[\\r\\n\\0]/;\nconst INVALID_UNICODE = /\\p{Surrogate}/u;\nconst RESERVED_KEY_IDS = new Set([\"__proto__\", \"prototype\", \"constructor\"]);\n\ntype EmbeddingPurpose = \"MERCHANT_KNOWLEDGE\" | \"REFERENCE_TAXONOMY\";\n\nexport type CommerceEmbeddingCredentialAadInput = Readonly<{\n environment: CommerceEnvironment;\n purpose: EmbeddingPurpose;\n provider: string;\n keyId: string;\n}>;\n\nexport type WooRestReadGrantAadInput = Readonly<{\n shopId: string;\n installationId: string;\n authorizationAttemptId: string;\n credentialVersionSnapshot: number;\n}>;\n\nfunction invalidAad(): never {\n // The message/code are constant: never interpolate merchant identifiers or secrets.\n throw new CredentialSecurityError(\"INVALID_CREDENTIAL\");\n}\n\nfunction isBoundedIdentifier(value: unknown, limit: number): value is string {\n return typeof value === \"string\" &&\n value.length >= 1 && value.length <= limit &&\n value.trim().length > 0 &&\n !FORBIDDEN_ID_CHARACTERS.test(value) &&\n !INVALID_UNICODE.test(value);\n}\n\n/** Preserve the existing embedding canonical-JSON AAD bytes across writer/readers. */\nexport function createCommerceEmbeddingCredentialAad(\n input: CommerceEmbeddingCredentialAadInput,\n): string {\n if (\n input === null || typeof input !== \"object\" ||\n !CommerceEnvironmentSchema.safeParse(input.environment).success ||\n !PURPOSES.has(input.purpose) ||\n !isBoundedIdentifier(input.provider, 128) ||\n typeof input.keyId !== \"string\" ||\n !KEY_ID_PATTERN.test(input.keyId) ||\n RESERVED_KEY_IDS.has(input.keyId)\n ) {\n return invalidAad();\n }\n\n return canonicalJson({\n credentialType: \"EMBEDDING\",\n environment: input.environment,\n purpose: input.purpose,\n provider: input.provider,\n keyId: input.keyId,\n });\n}\n\n/** Preserve the existing Woo API/Background JSON-array AAD bytes exactly. */\nexport function createWooRestReadGrantAad(input: WooRestReadGrantAadInput): string {\n if (\n input === null || typeof input !== \"object\" ||\n !isBoundedIdentifier(input.shopId, 128) ||\n !isBoundedIdentifier(input.installationId, 128) ||\n !isBoundedIdentifier(input.authorizationAttemptId, 128) ||\n !Number.isSafeInteger(input.credentialVersionSnapshot) ||\n input.credentialVersionSnapshot < 1\n ) {\n return invalidAad();\n }\n\n return JSON.stringify([\n \"moda-woo-rest-read-v1\",\n input.shopId,\n input.installationId,\n input.authorizationAttemptId,\n input.credentialVersionSnapshot,\n ]);\n}\n","import { Buffer } from \"node:buffer\";\nimport { CredentialSecurityError } from \"./errors.js\";\n\nconst KEY_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;\nconst STANDARD_BASE64_KEY_PATTERN = /^[A-Za-z0-9+/]{43}=$/;\nconst RESERVED_KEY_IDS = new Set([\"__proto__\", \"prototype\", \"constructor\"]);\nconst MAX_CONFIG_BYTES = 4096;\nconst MAX_KEYS = 16;\nconst KEY_BYTES = 32;\n\nexport interface CredentialKeyring {\n readonly keyIds: readonly string[];\n hasKey(keyId: string): boolean;\n}\n\n// The keyring descriptor never contains key material. In particular, consumers cannot\n// obtain a reference to any retained secret through keyIds, hasKey, or object inspection.\nconst privateKeys = new WeakMap<CredentialKeyring, ReadonlyMap<string, Uint8Array>>();\n\nfunction invalidKeyring(): never {\n throw new CredentialSecurityError(\"INVALID_KEYRING\");\n}\n\n/**\n * Read a JSON string token, returning the decoded contents and the next offset.\n * JSON.parse validates escapes (including Unicode escapes) and rejects malformed text.\n * Only decoded property names are compared, preventing escaped duplicate aliases.\n */\nfunction readJsonString(raw: string, start: number): [string, number] {\n if (raw[start] !== '\"') invalidKeyring();\n let cursor = start + 1;\n while (cursor < raw.length) {\n const character = raw[cursor];\n if (character === \"\\\\\") {\n cursor += 2;\n continue;\n }\n if (character === '\"') {\n const decoded: unknown = JSON.parse(raw.slice(start, cursor + 1));\n if (typeof decoded !== \"string\") invalidKeyring();\n return [decoded, cursor + 1];\n }\n cursor += 1;\n }\n return invalidKeyring();\n}\n\n/**\n * A small strict JSON-object scanner: the only supported format is a top-level\n * object mapping JSON string IDs to JSON string key values. Using JSON.parse(raw)\n * alone would silently discard duplicate property names, which we must reject.\n */\nfunction parseUniqueStringObject(raw: string): Map<string, string> {\n // Validate the complete JSON grammar, including escape sequences and trailing data.\n let decoded: unknown;\n try {\n decoded = JSON.parse(raw);\n } catch {\n return invalidKeyring();\n }\n if (decoded === null || typeof decoded !== \"object\" || Array.isArray(decoded)) {\n return invalidKeyring();\n }\n\n let index = 0;\n const skipWhitespace = (): void => {\n while (index < raw.length && /[ \\t\\r\\n]/.test(raw[index]!)) index += 1;\n };\n\n const entries = new Map<string, string>();\n skipWhitespace();\n if (raw[index++] !== \"{\") return invalidKeyring();\n skipWhitespace();\n if (raw[index] === \"}\") return invalidKeyring();\n\n while (index < raw.length) {\n const [key, afterKey] = readJsonString(raw, index);\n if (entries.has(key)) return invalidKeyring();\n if (!KEY_ID_PATTERN.test(key) || RESERVED_KEY_IDS.has(key)) return invalidKeyring();\n index = afterKey;\n skipWhitespace();\n if (raw[index++] !== \":\") return invalidKeyring();\n skipWhitespace();\n const [value, afterValue] = readJsonString(raw, index);\n entries.set(key, value);\n if (entries.size > MAX_KEYS) return invalidKeyring();\n index = afterValue;\n skipWhitespace();\n const separator = raw[index++];\n if (separator === \"}\") break;\n if (separator !== \",\") return invalidKeyring();\n skipWhitespace();\n }\n skipWhitespace();\n if (index !== raw.length || entries.size === 0) return invalidKeyring();\n return entries;\n}\n\n/** Validate and retain canonical 32-byte AES key material without exposing the bytes. */\nexport function parseCredentialKeyring(raw: string | undefined): CredentialKeyring {\n if (typeof raw !== \"string\" || raw.trim().length === 0 || Buffer.byteLength(raw, \"utf8\") > MAX_CONFIG_BYTES) {\n return invalidKeyring();\n }\n\n let entries: Map<string, string>;\n try {\n entries = parseUniqueStringObject(raw);\n } catch {\n // No native JSON parsing error or untrusted data may escape this boundary.\n return invalidKeyring();\n }\n\n const keys = new Map<string, Uint8Array>();\n for (const [keyId, encoded] of entries) {\n if (!STANDARD_BASE64_KEY_PATTERN.test(encoded)) return invalidKeyring();\n const bytes = Buffer.from(encoded, \"base64\");\n if (bytes.length !== KEY_BYTES || bytes.toString(\"base64\") !== encoded) {\n return invalidKeyring();\n }\n keys.set(keyId, Uint8Array.from(bytes));\n }\n\n const keyIds = Object.freeze([...keys.keys()].sort());\n const descriptor: CredentialKeyring = Object.freeze({\n keyIds,\n hasKey: (keyId: string): boolean => typeof keyId === \"string\" && keys.has(keyId),\n });\n privateKeys.set(descriptor, keys);\n return descriptor;\n}\n\n/** An explicit writer selection; never select the first key or trim an input. */\nexport function resolveActiveCredentialKey(\n keyring: CredentialKeyring,\n activeKeyId: string | undefined,\n): string {\n const keys = privateKeys.get(keyring);\n if (\n !keys ||\n typeof activeKeyId !== \"string\" ||\n !KEY_ID_PATTERN.test(activeKeyId) ||\n RESERVED_KEY_IDS.has(activeKeyId) ||\n !keys.has(activeKeyId)\n ) {\n throw new CredentialSecurityError(\"KEY_UNAVAILABLE\");\n }\n return activeKeyId;\n}\n\n/**\n * Package-internal helper for SHARED-002. Never re-export from the public Node\n * entrypoint. Return a defensive copy so an AEAD consumer cannot mutate the\n * retained key material (including after an encryption failure).\n */\nexport function getCredentialKeyBytes(keyring: CredentialKeyring, keyId: string): Uint8Array {\n const bytes = privateKeys.get(keyring)?.get(keyId);\n if (!bytes) throw new CredentialSecurityError(\"KEY_UNAVAILABLE\");\n return Uint8Array.from(bytes);\n}\n","import { Buffer } from \"node:buffer\";\nimport { timingSafeEqual } from \"node:crypto\";\nimport { CredentialSecurityError } from \"./errors.js\";\nimport { getCredentialKeyBytes, type CredentialKeyring } from \"./keyring.js\";\n\nconst CANONICAL_BASE64_32_BYTE_KEY = /^[A-Za-z0-9+/]{43}=$/;\n\nfunction invalidCommandHmacKey(): never {\n throw new CredentialSecurityError(\"INVALID_COMMAND_HMAC_KEY\");\n}\n\n/**\n * Decode the Commerce connection-command HMAC secret, without accessing service\n * configuration or exposing AES key bytes. The caller supplies the configured\n * value and the canonical AES keyring explicitly.\n */\nexport function parseCommerceConnectionCommandHmacKey(\n raw: string | undefined,\n aesKeyring: CredentialKeyring,\n): Uint8Array {\n if (typeof raw !== \"string\" || !CANONICAL_BASE64_32_BYTE_KEY.test(raw)) {\n return invalidCommandHmacKey();\n }\n\n const decoded = Buffer.from(raw, \"base64\");\n if (decoded.length !== 32 || decoded.toString(\"base64\") !== raw) {\n return invalidCommandHmacKey();\n }\n\n // Examine *every* AES key, rather than returning on the first match. A\n // failed or forged keyring must never bypass the separation requirement.\n let reusesEncryptionKey = false;\n try {\n for (const keyId of aesKeyring.keyIds) {\n const aesBytes = getCredentialKeyBytes(aesKeyring, keyId);\n try {\n reusesEncryptionKey = timingSafeEqual(decoded, aesBytes) || reusesEncryptionKey;\n } finally {\n aesBytes.fill(0); // Only wipes the defensive copy, not the keyring.\n }\n }\n // The parser creates a nonempty keyring; reject invalid caller-supplied\n // substitutes rather than treating them as an empty, trusted keyring.\n if (aesKeyring.keyIds.length === 0) return invalidCommandHmacKey();\n } catch {\n return invalidCommandHmacKey();\n }\n\n if (reusesEncryptionKey) return invalidCommandHmacKey();\n return Uint8Array.from(decoded);\n}\n","import { Buffer } from \"node:buffer\";\nimport { createCipheriv, createDecipheriv, randomBytes } from \"node:crypto\";\nimport { TextDecoder } from \"node:util\";\nimport { CredentialSecurityError } from \"./errors.js\";\nimport {\n getCredentialKeyBytes,\n resolveActiveCredentialKey,\n type CredentialKeyring,\n} from \"./keyring.js\";\n\nconst NONCE_BYTES = 12;\nconst AUTH_TAG_BYTES = 16;\nconst MAX_CREDENTIAL_BYTES = 8192;\nconst MAX_AAD_BYTES = 4096;\nconst KEY_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;\nconst RESERVED_KEY_IDS = new Set([\"__proto__\", \"prototype\", \"constructor\"]);\n\n/** Crypto envelope only; persistence and AAD construction belong to the caller. */\nexport type CredentialEnvelope = Readonly<{\n keyId: string;\n nonce: Uint8Array;\n ciphertext: Uint8Array;\n authTag: Uint8Array;\n}>;\n\nfunction invalidCredential(): never {\n throw new CredentialSecurityError(\"INVALID_CREDENTIAL\");\n}\n\n/** Reject UTF-16 strings that Node would otherwise encode with replacement bytes. */\nfunction isValidUnicode(value: string): boolean {\n for (let index = 0; index < value.length; index += 1) {\n const unit = value.charCodeAt(index);\n if (unit >= 0xd800 && unit <= 0xdbff) {\n if (index + 1 === value.length) return false;\n const next = value.charCodeAt(index + 1);\n if (next < 0xdc00 || next > 0xdfff) return false;\n index += 1;\n } else if (unit >= 0xdc00 && unit <= 0xdfff) {\n return false;\n }\n }\n return true;\n}\n\nfunction aadBytes(value: unknown): Buffer {\n let bytes: Buffer;\n if (typeof value === \"string\") {\n if (!isValidUnicode(value)) return invalidCredential();\n bytes = Buffer.from(value, \"utf8\");\n } else if (value instanceof Uint8Array) {\n // Copy the exact view, not its possibly larger underlying ArrayBuffer.\n bytes = Buffer.from(value);\n } else {\n return invalidCredential();\n }\n if (bytes.length < 1 || bytes.length > MAX_AAD_BYTES) return invalidCredential();\n return bytes;\n}\n\nfunction validEnvelope(value: unknown): value is CredentialEnvelope {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) return false;\n const candidate = value as Partial<CredentialEnvelope>;\n return (\n typeof candidate.keyId === \"string\" &&\n KEY_ID_PATTERN.test(candidate.keyId) &&\n !RESERVED_KEY_IDS.has(candidate.keyId) &&\n candidate.nonce instanceof Uint8Array &&\n candidate.nonce.byteLength === NONCE_BYTES &&\n candidate.ciphertext instanceof Uint8Array &&\n candidate.ciphertext.byteLength >= 1 &&\n candidate.ciphertext.byteLength <= MAX_CREDENTIAL_BYTES &&\n candidate.authTag instanceof Uint8Array &&\n candidate.authTag.byteLength === AUTH_TAG_BYTES\n );\n}\n\n/** Keep native crypto and UTF-8 decoding exceptions out of the public error contract. */\nfunction protectCredentialOperation<T>(operation: () => T): T {\n try {\n return operation();\n } catch (error) {\n if (error instanceof CredentialSecurityError) throw error;\n return invalidCredential();\n }\n}\n\n/** Encrypt a UTF-8 credential with caller-provided, mandatory authenticated data. */\nexport function encryptCredential(input: {\n keyring: CredentialKeyring;\n activeKeyId: string;\n plaintext: string;\n aad: string | Uint8Array;\n}): CredentialEnvelope {\n return protectCredentialOperation(() => {\n if (typeof input !== \"object\" || input === null || Array.isArray(input)) return invalidCredential();\n const { keyring, activeKeyId, plaintext, aad } = input;\n if (typeof plaintext !== \"string\" || !isValidUnicode(plaintext)) return invalidCredential();\n const plaintextBytes = Buffer.from(plaintext, \"utf8\");\n if (plaintextBytes.length < 1 || plaintextBytes.length > MAX_CREDENTIAL_BYTES) {\n plaintextBytes.fill(0);\n return invalidCredential();\n }\n let key: Uint8Array | undefined;\n try {\n const authenticatedData = aadBytes(aad);\n const keyId = resolveActiveCredentialKey(keyring, activeKeyId);\n key = getCredentialKeyBytes(keyring, keyId);\n const nonce = randomBytes(NONCE_BYTES);\n const cipher = createCipheriv(\"aes-256-gcm\", key, nonce, { authTagLength: AUTH_TAG_BYTES });\n cipher.setAAD(authenticatedData);\n const ciphertext = Buffer.concat([cipher.update(plaintextBytes), cipher.final()]);\n return Object.freeze({\n keyId,\n nonce: Uint8Array.from(nonce),\n ciphertext: Uint8Array.from(ciphertext),\n authTag: Uint8Array.from(cipher.getAuthTag()),\n });\n } finally {\n key?.fill(0);\n plaintextBytes.fill(0);\n }\n });\n}\n\n/** Decrypt only authenticated UTF-8 text; never return unauthenticated bytes. */\nexport function decryptCredential(input: {\n keyring: CredentialKeyring;\n envelope: CredentialEnvelope;\n aad: string | Uint8Array;\n}): string {\n return protectCredentialOperation(() => {\n if (typeof input !== \"object\" || input === null || Array.isArray(input)) return invalidCredential();\n const { keyring, envelope, aad } = input;\n if (!validEnvelope(envelope)) return invalidCredential();\n const authenticatedData = aadBytes(aad);\n const key = getCredentialKeyBytes(keyring, envelope.keyId);\n let plaintextBytes: Buffer | undefined;\n try {\n const decipher = createDecipheriv(\"aes-256-gcm\", key, Buffer.from(envelope.nonce), {\n authTagLength: AUTH_TAG_BYTES,\n });\n decipher.setAAD(authenticatedData);\n decipher.setAuthTag(Buffer.from(envelope.authTag));\n plaintextBytes = Buffer.concat([\n decipher.update(Buffer.from(envelope.ciphertext)),\n decipher.final(),\n ]);\n // ignoreBOM preserves a leading U+FEFF so decrypt(encrypt(text)) is exact.\n return new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true }).decode(plaintextBytes);\n } finally {\n plaintextBytes?.fill(0);\n key.fill(0);\n }\n });\n}\n"],"mappings":";;;;;;;;AAOA,IAAM,WAAkE;AAAA,EACtE,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,0BAA0B;AAC5B;AAEO,IAAM,0BAAN,cAAsC,MAAM;AAAA,EACxC;AAAA,EAET,YAAY,MAAmC;AAC7C,UAAM,SAAS,IAAI,CAAC;AACpB,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;;;ACfA,IAAM,iBAAiB;AACvB,IAAM,WAAW,oBAAI,IAAI,CAAC,sBAAsB,oBAAoB,CAAC;AACrE,IAAM,0BAA0B;AAChC,IAAM,kBAAkB;AACxB,IAAM,mBAAmB,oBAAI,IAAI,CAAC,aAAa,aAAa,aAAa,CAAC;AAkB1E,SAAS,aAAoB;AAE3B,QAAM,IAAI,wBAAwB,oBAAoB;AACxD;AAEA,SAAS,oBAAoB,OAAgB,OAAgC;AAC3E,SAAO,OAAO,UAAU,YACtB,MAAM,UAAU,KAAK,MAAM,UAAU,SACrC,MAAM,KAAK,EAAE,SAAS,KACtB,CAAC,wBAAwB,KAAK,KAAK,KACnC,CAAC,gBAAgB,KAAK,KAAK;AAC/B;AAGO,SAAS,qCACd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K,KAAK,CAAC;AACX,qBAAe,KAAK,CAAC;AAAA,IACvB;AAAA,EACF,CAAC;AACH;AAGO,SAAS,kBAAkB,OAIvB;AACT,SAAO,2BAA2B,MAAM;AACtC,QAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,EAAG,QAAO,kBAAkB;AAClG,UAAM,EAAE,SAAS,UAAU,IAAI,IAAI;AACnC,QAAI,CAAC,cAAc,QAAQ,EAAG,QAAO,kBAAkB;AACvD,UAAM,oBAAoB,SAAS,GAAG;AACtC,UAAM,MAAM,sBAAsB,SAAS,SAAS,KAAK;AACzD,QAAI;AACJ,QAAI;AACF,YAAM,WAAW,iBAAiB,eAAe,KAAKA,QAAO,KAAK,SAAS,KAAK,GAAG;AAAA,QACjF,eAAe;AAAA,MACjB,CAAC;AACD,eAAS,OAAO,iBAAiB;AACjC,eAAS,WAAWA,QAAO,KAAK,SAAS,OAAO,CAAC;AACjD,uBAAiBA,QAAO,OAAO;AAAA,QAC7B,SAAS,OAAOA,QAAO,KAAK,SAAS,UAAU,CAAC;AAAA,QAChD,SAAS,MAAM;AAAA,MACjB,CAAC;AAED,aAAO,IAAI,YAAY,SAAS,EAAE,OAAO,MAAM,WAAW,KAAK,CAAC,EAAE,OAAO,cAAc;AAAA,IACzF,UAAE;AACA,sBAAgB,KAAK,CAAC;AACtB,UAAI,KAAK,CAAC;AAAA,IACZ;AAAA,EACF,CAAC;AACH;","names":["KEY_ID_PATTERN","RESERVED_KEY_IDS","Buffer","Buffer","Buffer","KEY_ID_PATTERN","RESERVED_KEY_IDS","Buffer"]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -389,9 +389,9 @@ declare const ShopifyCheckoutCreatedEventV2Schema: z.ZodObject<{
389
389
  internationalContext: z.ZodOptional<z.ZodObject<{
390
390
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
391
391
  languageSource: z.ZodNullable<z.ZodEnum<{
392
+ shopify: "shopify";
392
393
  "customer-explicit": "customer-explicit";
393
394
  detected: "detected";
394
- shopify: "shopify";
395
395
  "merchant-default": "merchant-default";
396
396
  "platform-default": "platform-default";
397
397
  }>>;
@@ -426,9 +426,9 @@ declare const ShopifyCartActivityEventV2Schema: z.ZodObject<{
426
426
  internationalContext: z.ZodOptional<z.ZodObject<{
427
427
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
428
428
  languageSource: z.ZodNullable<z.ZodEnum<{
429
+ shopify: "shopify";
429
430
  "customer-explicit": "customer-explicit";
430
431
  detected: "detected";
431
- shopify: "shopify";
432
432
  "merchant-default": "merchant-default";
433
433
  "platform-default": "platform-default";
434
434
  }>>;
@@ -461,9 +461,9 @@ declare const ShopifyCheckoutUpdatedEventV2Schema: z.ZodObject<{
461
461
  internationalContext: z.ZodOptional<z.ZodObject<{
462
462
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
463
463
  languageSource: z.ZodNullable<z.ZodEnum<{
464
+ shopify: "shopify";
464
465
  "customer-explicit": "customer-explicit";
465
466
  detected: "detected";
466
- shopify: "shopify";
467
467
  "merchant-default": "merchant-default";
468
468
  "platform-default": "platform-default";
469
469
  }>>;
@@ -495,9 +495,9 @@ declare const ShopifyOrderCompletedEventV2Schema: z.ZodObject<{
495
495
  internationalContext: z.ZodOptional<z.ZodObject<{
496
496
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
497
497
  languageSource: z.ZodNullable<z.ZodEnum<{
498
+ shopify: "shopify";
498
499
  "customer-explicit": "customer-explicit";
499
500
  detected: "detected";
500
- shopify: "shopify";
501
501
  "merchant-default": "merchant-default";
502
502
  "platform-default": "platform-default";
503
503
  }>>;
@@ -532,9 +532,9 @@ declare const ShopifyRecoveryEventV2Schema: z.ZodDiscriminatedUnion<[z.ZodObject
532
532
  internationalContext: z.ZodOptional<z.ZodObject<{
533
533
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
534
534
  languageSource: z.ZodNullable<z.ZodEnum<{
535
+ shopify: "shopify";
535
536
  "customer-explicit": "customer-explicit";
536
537
  detected: "detected";
537
- shopify: "shopify";
538
538
  "merchant-default": "merchant-default";
539
539
  "platform-default": "platform-default";
540
540
  }>>;
@@ -565,9 +565,9 @@ declare const ShopifyRecoveryEventV2Schema: z.ZodDiscriminatedUnion<[z.ZodObject
565
565
  internationalContext: z.ZodOptional<z.ZodObject<{
566
566
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
567
567
  languageSource: z.ZodNullable<z.ZodEnum<{
568
+ shopify: "shopify";
568
569
  "customer-explicit": "customer-explicit";
569
570
  detected: "detected";
570
- shopify: "shopify";
571
571
  "merchant-default": "merchant-default";
572
572
  "platform-default": "platform-default";
573
573
  }>>;
@@ -600,9 +600,9 @@ declare const ShopifyRecoveryEventV2Schema: z.ZodDiscriminatedUnion<[z.ZodObject
600
600
  internationalContext: z.ZodOptional<z.ZodObject<{
601
601
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
602
602
  languageSource: z.ZodNullable<z.ZodEnum<{
603
+ shopify: "shopify";
603
604
  "customer-explicit": "customer-explicit";
604
605
  detected: "detected";
605
- shopify: "shopify";
606
606
  "merchant-default": "merchant-default";
607
607
  "platform-default": "platform-default";
608
608
  }>>;
@@ -632,9 +632,9 @@ declare const ShopifyRecoveryEventV2Schema: z.ZodDiscriminatedUnion<[z.ZodObject
632
632
  internationalContext: z.ZodOptional<z.ZodObject<{
633
633
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
634
634
  languageSource: z.ZodNullable<z.ZodEnum<{
635
+ shopify: "shopify";
635
636
  "customer-explicit": "customer-explicit";
636
637
  detected: "detected";
637
- shopify: "shopify";
638
638
  "merchant-default": "merchant-default";
639
639
  "platform-default": "platform-default";
640
640
  }>>;
@@ -677,7 +677,7 @@ declare function safeParseShopifyRecoveryEventV2(input: unknown): z.ZodSafeParse
677
677
  };
678
678
  internationalContext?: {
679
679
  languageTag: string | null;
680
- languageSource: "customer-explicit" | "detected" | "shopify" | "merchant-default" | "platform-default" | null;
680
+ languageSource: "shopify" | "customer-explicit" | "detected" | "merchant-default" | "platform-default" | null;
681
681
  countryCode: string | null;
682
682
  currencyCode: string | null;
683
683
  timeZone: string | null;
@@ -704,7 +704,7 @@ declare function safeParseShopifyRecoveryEventV2(input: unknown): z.ZodSafeParse
704
704
  };
705
705
  internationalContext?: {
706
706
  languageTag: string | null;
707
- languageSource: "customer-explicit" | "detected" | "shopify" | "merchant-default" | "platform-default" | null;
707
+ languageSource: "shopify" | "customer-explicit" | "detected" | "merchant-default" | "platform-default" | null;
708
708
  countryCode: string | null;
709
709
  currencyCode: string | null;
710
710
  timeZone: string | null;
@@ -730,7 +730,7 @@ declare function safeParseShopifyRecoveryEventV2(input: unknown): z.ZodSafeParse
730
730
  };
731
731
  internationalContext?: {
732
732
  languageTag: string | null;
733
- languageSource: "customer-explicit" | "detected" | "shopify" | "merchant-default" | "platform-default" | null;
733
+ languageSource: "shopify" | "customer-explicit" | "detected" | "merchant-default" | "platform-default" | null;
734
734
  countryCode: string | null;
735
735
  currencyCode: string | null;
736
736
  timeZone: string | null;
@@ -759,7 +759,7 @@ declare function safeParseShopifyRecoveryEventV2(input: unknown): z.ZodSafeParse
759
759
  };
760
760
  internationalContext?: {
761
761
  languageTag: string | null;
762
- languageSource: "customer-explicit" | "detected" | "shopify" | "merchant-default" | "platform-default" | null;
762
+ languageSource: "shopify" | "customer-explicit" | "detected" | "merchant-default" | "platform-default" | null;
763
763
  countryCode: string | null;
764
764
  currencyCode: string | null;
765
765
  timeZone: string | null;
@@ -803,9 +803,9 @@ declare const ShopifyCheckoutUpdatedEventV3Schema: z.ZodObject<{
803
803
  internationalContext: z.ZodOptional<z.ZodObject<{
804
804
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
805
805
  languageSource: z.ZodNullable<z.ZodEnum<{
806
+ shopify: "shopify";
806
807
  "customer-explicit": "customer-explicit";
807
808
  detected: "detected";
808
- shopify: "shopify";
809
809
  "merchant-default": "merchant-default";
810
810
  "platform-default": "platform-default";
811
811
  }>>;
@@ -841,9 +841,9 @@ declare const ShopifyRecoveryEventSchema: z.ZodUnion<readonly [z.ZodDiscriminate
841
841
  internationalContext: z.ZodOptional<z.ZodObject<{
842
842
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
843
843
  languageSource: z.ZodNullable<z.ZodEnum<{
844
+ shopify: "shopify";
844
845
  "customer-explicit": "customer-explicit";
845
846
  detected: "detected";
846
- shopify: "shopify";
847
847
  "merchant-default": "merchant-default";
848
848
  "platform-default": "platform-default";
849
849
  }>>;
@@ -874,9 +874,9 @@ declare const ShopifyRecoveryEventSchema: z.ZodUnion<readonly [z.ZodDiscriminate
874
874
  internationalContext: z.ZodOptional<z.ZodObject<{
875
875
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
876
876
  languageSource: z.ZodNullable<z.ZodEnum<{
877
+ shopify: "shopify";
877
878
  "customer-explicit": "customer-explicit";
878
879
  detected: "detected";
879
- shopify: "shopify";
880
880
  "merchant-default": "merchant-default";
881
881
  "platform-default": "platform-default";
882
882
  }>>;
@@ -909,9 +909,9 @@ declare const ShopifyRecoveryEventSchema: z.ZodUnion<readonly [z.ZodDiscriminate
909
909
  internationalContext: z.ZodOptional<z.ZodObject<{
910
910
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
911
911
  languageSource: z.ZodNullable<z.ZodEnum<{
912
+ shopify: "shopify";
912
913
  "customer-explicit": "customer-explicit";
913
914
  detected: "detected";
914
- shopify: "shopify";
915
915
  "merchant-default": "merchant-default";
916
916
  "platform-default": "platform-default";
917
917
  }>>;
@@ -941,9 +941,9 @@ declare const ShopifyRecoveryEventSchema: z.ZodUnion<readonly [z.ZodDiscriminate
941
941
  internationalContext: z.ZodOptional<z.ZodObject<{
942
942
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
943
943
  languageSource: z.ZodNullable<z.ZodEnum<{
944
+ shopify: "shopify";
944
945
  "customer-explicit": "customer-explicit";
945
946
  detected: "detected";
946
- shopify: "shopify";
947
947
  "merchant-default": "merchant-default";
948
948
  "platform-default": "platform-default";
949
949
  }>>;
@@ -976,9 +976,9 @@ declare const ShopifyRecoveryEventSchema: z.ZodUnion<readonly [z.ZodDiscriminate
976
976
  internationalContext: z.ZodOptional<z.ZodObject<{
977
977
  languageTag: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
978
978
  languageSource: z.ZodNullable<z.ZodEnum<{
979
+ shopify: "shopify";
979
980
  "customer-explicit": "customer-explicit";
980
981
  detected: "detected";
981
- shopify: "shopify";
982
982
  "merchant-default": "merchant-default";
983
983
  "platform-default": "platform-default";
984
984
  }>>;
@@ -1020,7 +1020,7 @@ declare function safeParseShopifyRecoveryEvent(input: unknown): z.ZodSafeParseRe
1020
1020
  };
1021
1021
  internationalContext?: {
1022
1022
  languageTag: string | null;
1023
- languageSource: "customer-explicit" | "detected" | "shopify" | "merchant-default" | "platform-default" | null;
1023
+ languageSource: "shopify" | "customer-explicit" | "detected" | "merchant-default" | "platform-default" | null;
1024
1024
  countryCode: string | null;
1025
1025
  currencyCode: string | null;
1026
1026
  timeZone: string | null;
@@ -1047,7 +1047,7 @@ declare function safeParseShopifyRecoveryEvent(input: unknown): z.ZodSafeParseRe
1047
1047
  };
1048
1048
  internationalContext?: {
1049
1049
  languageTag: string | null;
1050
- languageSource: "customer-explicit" | "detected" | "shopify" | "merchant-default" | "platform-default" | null;
1050
+ languageSource: "shopify" | "customer-explicit" | "detected" | "merchant-default" | "platform-default" | null;
1051
1051
  countryCode: string | null;
1052
1052
  currencyCode: string | null;
1053
1053
  timeZone: string | null;
@@ -1073,7 +1073,7 @@ declare function safeParseShopifyRecoveryEvent(input: unknown): z.ZodSafeParseRe
1073
1073
  };
1074
1074
  internationalContext?: {
1075
1075
  languageTag: string | null;
1076
- languageSource: "customer-explicit" | "detected" | "shopify" | "merchant-default" | "platform-default" | null;
1076
+ languageSource: "shopify" | "customer-explicit" | "detected" | "merchant-default" | "platform-default" | null;
1077
1077
  countryCode: string | null;
1078
1078
  currencyCode: string | null;
1079
1079
  timeZone: string | null;
@@ -1102,7 +1102,7 @@ declare function safeParseShopifyRecoveryEvent(input: unknown): z.ZodSafeParseRe
1102
1102
  };
1103
1103
  internationalContext?: {
1104
1104
  languageTag: string | null;
1105
- languageSource: "customer-explicit" | "detected" | "shopify" | "merchant-default" | "platform-default" | null;
1105
+ languageSource: "shopify" | "customer-explicit" | "detected" | "merchant-default" | "platform-default" | null;
1106
1106
  countryCode: string | null;
1107
1107
  currencyCode: string | null;
1108
1108
  timeZone: string | null;
@@ -1131,7 +1131,7 @@ declare function safeParseShopifyRecoveryEvent(input: unknown): z.ZodSafeParseRe
1131
1131
  };
1132
1132
  internationalContext?: {
1133
1133
  languageTag: string | null;
1134
- languageSource: "customer-explicit" | "detected" | "shopify" | "merchant-default" | "platform-default" | null;
1134
+ languageSource: "shopify" | "customer-explicit" | "detected" | "merchant-default" | "platform-default" | null;
1135
1135
  countryCode: string | null;
1136
1136
  currencyCode: string | null;
1137
1137
  timeZone: string | null;