@shopify/shopify-api 14.0.0 → 15.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/cjs/lib/clients/common.js +64 -8
  2. package/dist/cjs/lib/clients/common.js.map +1 -1
  3. package/dist/cjs/lib/types.js +0 -2
  4. package/dist/cjs/lib/types.js.map +1 -1
  5. package/dist/cjs/lib/utils/fetch-request.js +12 -1
  6. package/dist/cjs/lib/utils/fetch-request.js.map +1 -1
  7. package/dist/cjs/lib/version.js +1 -1
  8. package/dist/cjs/lib/version.js.map +1 -1
  9. package/dist/cjs/lib/webhooks/types.js +0 -2
  10. package/dist/cjs/lib/webhooks/types.js.map +1 -1
  11. package/dist/cjs/lib/webhooks/validate.js +0 -5
  12. package/dist/cjs/lib/webhooks/validate.js.map +1 -1
  13. package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
  14. package/dist/esm/lib/clients/common.mjs +64 -8
  15. package/dist/esm/lib/clients/common.mjs.map +1 -1
  16. package/dist/esm/lib/types.mjs +0 -2
  17. package/dist/esm/lib/types.mjs.map +1 -1
  18. package/dist/esm/lib/utils/fetch-request.mjs +12 -1
  19. package/dist/esm/lib/utils/fetch-request.mjs.map +1 -1
  20. package/dist/esm/lib/version.mjs +1 -1
  21. package/dist/esm/lib/version.mjs.map +1 -1
  22. package/dist/esm/lib/webhooks/types.mjs +0 -2
  23. package/dist/esm/lib/webhooks/types.mjs.map +1 -1
  24. package/dist/esm/lib/webhooks/validate.mjs +0 -5
  25. package/dist/esm/lib/webhooks/validate.mjs.map +1 -1
  26. package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
  27. package/dist/ts/lib/clients/common.d.ts.map +1 -1
  28. package/dist/ts/lib/types.d.ts +0 -2
  29. package/dist/ts/lib/types.d.ts.map +1 -1
  30. package/dist/ts/lib/utils/fetch-request.d.ts.map +1 -1
  31. package/dist/ts/lib/version.d.ts +1 -1
  32. package/dist/ts/lib/webhooks/types.d.ts +0 -4
  33. package/dist/ts/lib/webhooks/types.d.ts.map +1 -1
  34. package/dist/ts/tsconfig.build.tsbuildinfo +1 -1
  35. package/lib/clients/common.ts +91 -7
  36. package/lib/types.ts +0 -2
  37. package/lib/utils/fetch-request.ts +13 -1
  38. package/lib/version.ts +1 -1
  39. package/lib/webhooks/types.ts +0 -4
  40. package/lib/webhooks/validate.ts +0 -9
  41. package/package.json +1 -1
@@ -12,6 +12,65 @@ function getUserAgent(config) {
12
12
  }
13
13
  return userAgentPrefix;
14
14
  }
15
+ const REDACTED_LOG_VALUE = '****';
16
+ // These headers carry reusable credentials and must not reach the logs.
17
+ const SENSITIVE_LOG_HEADERS = new Set([
18
+ 'authorization',
19
+ 'cookie',
20
+ 'set-cookie',
21
+ 'shopify-storefront-private-token',
22
+ 'x-shopify-access-token',
23
+ 'x-shopify-storefront-access-token',
24
+ ]);
25
+ function sanitizeHeaderValue(name, value) {
26
+ return SENSITIVE_LOG_HEADERS.has(name.toLowerCase())
27
+ ? REDACTED_LOG_VALUE
28
+ : value;
29
+ }
30
+ // Keep the original serialized shape of request headers. A Headers instance
31
+ // has no own enumerable properties, so it stays opaque here, the same as
32
+ // JSON.stringify shows it.
33
+ function sanitizeHeaders(headers) {
34
+ if (!headers || typeof headers !== 'object') {
35
+ return headers;
36
+ }
37
+ if (Array.isArray(headers)) {
38
+ return headers.map((header) => Array.isArray(header)
39
+ ? [header[0], sanitizeHeaderValue(header[0], header[1])]
40
+ : header);
41
+ }
42
+ return Object.fromEntries(Object.entries(headers).map(([name, value]) => [
43
+ name,
44
+ sanitizeHeaderValue(name, value),
45
+ ]));
46
+ }
47
+ // Response headers were always enumerated in the log, so keep that and
48
+ // redact the credential values.
49
+ function sanitizeEnumerableHeaders(headers) {
50
+ if (typeof headers?.entries === 'function' && !Array.isArray(headers)) {
51
+ return Object.fromEntries([...headers.entries()].map(([name, value]) => [
52
+ name,
53
+ sanitizeHeaderValue(name, value),
54
+ ]));
55
+ }
56
+ return sanitizeHeaders(headers);
57
+ }
58
+ function sanitizeRequestParams(requestParams) {
59
+ if (Array.isArray(requestParams)) {
60
+ return requestParams.map((param) => param && typeof param === 'object' && 'headers' in param
61
+ ? { ...param, headers: sanitizeHeaders(param.headers) }
62
+ : param);
63
+ }
64
+ if (requestParams &&
65
+ typeof requestParams === 'object' &&
66
+ 'headers' in requestParams) {
67
+ return {
68
+ ...requestParams,
69
+ headers: sanitizeHeaders(requestParams.headers),
70
+ };
71
+ }
72
+ return requestParams;
73
+ }
15
74
  function serializeResponse(response) {
16
75
  if (!response) {
17
76
  return { error: 'No response object provided' };
@@ -26,11 +85,8 @@ function serializeResponse(response) {
26
85
  type,
27
86
  url,
28
87
  };
29
- if (headers?.entries) {
30
- serialized.headers = Object.fromEntries(headers.entries());
31
- }
32
- else if (headers) {
33
- serialized.headers = headers;
88
+ if (headers) {
89
+ serialized.headers = sanitizeEnumerableHeaders(headers);
34
90
  }
35
91
  return serialized;
36
92
  }
@@ -45,7 +101,7 @@ function clientLoggerFactory(config) {
45
101
  case 'HTTP-Response': {
46
102
  const responseLog = logContent.content;
47
103
  logger(config).debug('Received response for HTTP request', {
48
- requestParams: JSON.stringify(responseLog.requestParams),
104
+ requestParams: JSON.stringify(sanitizeRequestParams(responseLog.requestParams)),
49
105
  response: JSON.stringify(serializeResponse(responseLog.response)),
50
106
  });
51
107
  break;
@@ -53,7 +109,7 @@ function clientLoggerFactory(config) {
53
109
  case 'HTTP-Retry': {
54
110
  const responseLog = logContent.content;
55
111
  logger(config).debug('Retrying HTTP request', {
56
- requestParams: JSON.stringify(responseLog.requestParams),
112
+ requestParams: JSON.stringify(sanitizeRequestParams(responseLog.requestParams)),
57
113
  retryAttempt: responseLog.retryAttempt,
58
114
  maxRetries: responseLog.maxRetries,
59
115
  response: responseLog.lastResponse
@@ -65,7 +121,7 @@ function clientLoggerFactory(config) {
65
121
  case 'HTTP-Response-GraphQL-Deprecation-Notice': {
66
122
  const responseLog = logContent.content;
67
123
  logger(config).debug('Received response containing Deprecated GraphQL Notice', {
68
- requestParams: JSON.stringify(responseLog.requestParams),
124
+ requestParams: JSON.stringify(sanitizeRequestParams(responseLog.requestParams)),
69
125
  deprecationNotice: responseLog.deprecationNotice,
70
126
  });
71
127
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"common.mjs","sources":["../../../../../../lib/clients/common.ts"],"sourcesContent":["import {\n HTTPResponseLog,\n HTTPRetryLog,\n HTTPResponseGraphQLDeprecationNotice,\n LogContent,\n} from '@shopify/admin-api-client';\n\nimport * as ShopifyErrors from '../error';\nimport {LIBRARY_NAME, StatusCode} from '../types';\nimport {ConfigInterface} from '../base-types';\nimport {SHOPIFY_API_LIBRARY_VERSION} from '../version';\nimport {\n abstractRuntimeString,\n canonicalizeHeaders,\n getHeader,\n} from '../../runtime';\nimport {logger} from '../logger';\n\nexport function getUserAgent(config: ConfigInterface): string {\n let userAgentPrefix = `${LIBRARY_NAME} v${SHOPIFY_API_LIBRARY_VERSION} | ${abstractRuntimeString()}`;\n if (config.userAgentPrefix) {\n userAgentPrefix = `${config.userAgentPrefix} | ${userAgentPrefix}`;\n }\n\n return userAgentPrefix;\n}\n\nfunction serializeResponse(response: Response | any) {\n if (!response) {\n return {error: 'No response object provided'};\n }\n\n try {\n const {status, statusText, ok, redirected, type, url, headers} = response;\n\n const serialized: any = {\n status,\n statusText,\n ok,\n redirected,\n type,\n url,\n };\n\n if (headers?.entries) {\n serialized.headers = Object.fromEntries(headers.entries());\n } else if (headers) {\n serialized.headers = headers;\n }\n\n return serialized;\n } catch {\n return response;\n }\n}\n\nexport function clientLoggerFactory(config: ConfigInterface) {\n return (logContent: LogContent) => {\n if (config.logger.httpRequests) {\n switch (logContent.type) {\n case 'HTTP-Response': {\n const responseLog: HTTPResponseLog['content'] = logContent.content;\n logger(config).debug('Received response for HTTP request', {\n requestParams: JSON.stringify(responseLog.requestParams),\n response: JSON.stringify(serializeResponse(responseLog.response)),\n });\n break;\n }\n case 'HTTP-Retry': {\n const responseLog: HTTPRetryLog['content'] = logContent.content;\n logger(config).debug('Retrying HTTP request', {\n requestParams: JSON.stringify(responseLog.requestParams),\n retryAttempt: responseLog.retryAttempt,\n maxRetries: responseLog.maxRetries,\n response: responseLog.lastResponse\n ? JSON.stringify(serializeResponse(responseLog.lastResponse))\n : 'undefined',\n });\n break;\n }\n case 'HTTP-Response-GraphQL-Deprecation-Notice': {\n const responseLog: HTTPResponseGraphQLDeprecationNotice['content'] =\n logContent.content;\n logger(config).debug(\n 'Received response containing Deprecated GraphQL Notice',\n {\n requestParams: JSON.stringify(responseLog.requestParams),\n deprecationNotice: responseLog.deprecationNotice,\n },\n );\n break;\n }\n default: {\n logger(config).debug(`HTTP request event: ${logContent.content}`);\n break;\n }\n }\n }\n };\n}\n\nexport function throwFailedRequest(\n body: any,\n atMaxRetries: boolean,\n response?: Response,\n): never {\n if (typeof response === 'undefined') {\n const message = body?.errors?.message ?? '';\n throw new ShopifyErrors.HttpRequestError(\n `Http request error, no response available: ${message}`,\n );\n }\n\n const responseHeaders = canonicalizeHeaders(\n Object.fromEntries(response.headers.entries() ?? []),\n );\n\n if (response.status === StatusCode.Ok && body.errors.graphQLErrors) {\n throw new ShopifyErrors.GraphqlQueryError({\n message:\n body.errors.graphQLErrors?.[0].message ?? 'GraphQL operation failed',\n response: response as Record<string, any>,\n headers: responseHeaders,\n body: body as Record<string, any>,\n });\n }\n\n const errorMessages: string[] = [];\n if (body.errors) {\n errorMessages.push(JSON.stringify(body.errors, null, 2));\n }\n const xRequestId = getHeader(responseHeaders, 'x-request-id');\n if (xRequestId) {\n errorMessages.push(\n `If you report this error, please include this id: ${xRequestId}`,\n );\n }\n\n const errorMessage = errorMessages.length\n ? `:\\n${errorMessages.join('\\n')}`\n : '';\n const code = response.status;\n const statusText = response.statusText;\n\n switch (true) {\n case response.status === StatusCode.TooManyRequests: {\n if (atMaxRetries) {\n throw new ShopifyErrors.HttpMaxRetriesError(\n 'Attempted the maximum number of retries for HTTP request.',\n );\n } else {\n const retryAfter = getHeader(responseHeaders, 'Retry-After');\n throw new ShopifyErrors.HttpThrottlingError({\n message: `Shopify is throttling requests ${errorMessage}`,\n code,\n statusText,\n body,\n headers: responseHeaders,\n retryAfter: retryAfter ? parseFloat(retryAfter) : undefined,\n });\n }\n }\n case response.status >= StatusCode.InternalServerError:\n if (atMaxRetries) {\n throw new ShopifyErrors.HttpMaxRetriesError(\n 'Attempted the maximum number of retries for HTTP request.',\n );\n } else {\n throw new ShopifyErrors.HttpInternalError({\n message: `Shopify internal error${errorMessage}`,\n code,\n statusText,\n body,\n headers: responseHeaders,\n });\n }\n default:\n throw new ShopifyErrors.HttpResponseError({\n message: `Received an error response (${response.status} ${response.statusText}) from Shopify${errorMessage}`,\n code,\n statusText,\n body,\n headers: responseHeaders,\n });\n }\n}\n"],"names":["ShopifyErrors.HttpRequestError","ShopifyErrors.GraphqlQueryError","ShopifyErrors.HttpMaxRetriesError","ShopifyErrors.HttpThrottlingError","ShopifyErrors.HttpInternalError","ShopifyErrors.HttpResponseError"],"mappings":";;;;;;;AAkBM,SAAU,YAAY,CAAC,MAAuB,EAAA;IAClD,IAAI,eAAe,GAAG,CAAA,EAAG,YAAY,CAAA,EAAA,EAAK,2BAA2B,CAAA,GAAA,EAAM,qBAAqB,EAAE,CAAA,CAAE;AACpG,IAAA,IAAI,MAAM,CAAC,eAAe,EAAE;QAC1B,eAAe,GAAG,GAAG,MAAM,CAAC,eAAe,CAAA,GAAA,EAAM,eAAe,EAAE;IACpE;AAEA,IAAA,OAAO,eAAe;AACxB;AAEA,SAAS,iBAAiB,CAAC,QAAwB,EAAA;IACjD,IAAI,CAAC,QAAQ,EAAE;AACb,QAAA,OAAO,EAAC,KAAK,EAAE,6BAA6B,EAAC;IAC/C;AAEA,IAAA,IAAI;AACF,QAAA,MAAM,EAAC,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAC,GAAG,QAA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AAChB,gBAAA,MAAM,IAAID,mBAAiC,CACzC,2DAA2D,CAC5D;YACH;iBAAO;AACL,gBAAA,MAAM,IAAIE,iBAA+B,CAAC;oBACxC,OAAO,EAAE,CAAA,sBAAA,EAAyB,YAAY,CAAA,CAAE;oBAChD,IAAI;oBACJ,UAAU;oBACV,IAAI;AACJ,oBAAA,OAAO,EAAE,eAAe;AACzB,iBAAA,CAAC;YACJ;AACF,QAAA;AACE,YAAA,MAAM,IAAIC,iBAA+B,CAAC;gBACxC,OAAO,EAAE,CAAA,4BAAA,EAA+B,QAAQ,CAAC,MAAM,CAAA,CAAA,EAAI,QAAQ,CAAC,UAAU,CAAA,cAAA,EAAiB,YAAY,CAAA,CAAE;gBAC7G,IAAI;gBACJ,UAAU;gBACV,IAAI;AACJ,gBAAA,OAAO,EAAE,eAAe;AACzB,aAAA,CAAC;;AAER;;;;"}
1
+ {"version":3,"file":"common.mjs","sources":["../../../../../../lib/clients/common.ts"],"sourcesContent":["import {\n HTTPResponseLog,\n HTTPRetryLog,\n HTTPResponseGraphQLDeprecationNotice,\n LogContent,\n} from '@shopify/admin-api-client';\n\nimport * as ShopifyErrors from '../error';\nimport {LIBRARY_NAME, StatusCode} from '../types';\nimport {ConfigInterface} from '../base-types';\nimport {SHOPIFY_API_LIBRARY_VERSION} from '../version';\nimport {\n abstractRuntimeString,\n canonicalizeHeaders,\n getHeader,\n} from '../../runtime';\nimport {logger} from '../logger';\n\nexport function getUserAgent(config: ConfigInterface): string {\n let userAgentPrefix = `${LIBRARY_NAME} v${SHOPIFY_API_LIBRARY_VERSION} | ${abstractRuntimeString()}`;\n if (config.userAgentPrefix) {\n userAgentPrefix = `${config.userAgentPrefix} | ${userAgentPrefix}`;\n }\n\n return userAgentPrefix;\n}\n\nconst REDACTED_LOG_VALUE = '****';\n\n// These headers carry reusable credentials and must not reach the logs.\nconst SENSITIVE_LOG_HEADERS = new Set([\n 'authorization',\n 'cookie',\n 'set-cookie',\n 'shopify-storefront-private-token',\n 'x-shopify-access-token',\n 'x-shopify-storefront-access-token',\n]);\n\nfunction sanitizeHeaderValue(name: string, value: unknown): unknown {\n return SENSITIVE_LOG_HEADERS.has(name.toLowerCase())\n ? REDACTED_LOG_VALUE\n : value;\n}\n\n// Keep the original serialized shape of request headers. A Headers instance\n// has no own enumerable properties, so it stays opaque here, the same as\n// JSON.stringify shows it.\nfunction sanitizeHeaders(headers: any): any {\n if (!headers || typeof headers !== 'object') {\n return headers;\n }\n\n if (Array.isArray(headers)) {\n return headers.map((header) =>\n Array.isArray(header)\n ? [header[0], sanitizeHeaderValue(header[0], header[1])]\n : header,\n );\n }\n\n return Object.fromEntries(\n Object.entries(headers).map(([name, value]) => [\n name,\n sanitizeHeaderValue(name, value),\n ]),\n );\n}\n\n// Response headers were always enumerated in the log, so keep that and\n// redact the credential values.\nfunction sanitizeEnumerableHeaders(headers: any): any {\n if (typeof headers?.entries === 'function' && !Array.isArray(headers)) {\n return Object.fromEntries(\n [...headers.entries()].map(([name, value]: [string, string]) => [\n name,\n sanitizeHeaderValue(name, value),\n ]),\n );\n }\n\n return sanitizeHeaders(headers);\n}\n\nfunction sanitizeRequestParams<T>(requestParams: T): T {\n if (Array.isArray(requestParams)) {\n return requestParams.map((param) =>\n param && typeof param === 'object' && 'headers' in param\n ? {...param, headers: sanitizeHeaders(param.headers)}\n : param,\n ) as T;\n }\n\n if (\n requestParams &&\n typeof requestParams === 'object' &&\n 'headers' in requestParams\n ) {\n return {\n ...requestParams,\n headers: sanitizeHeaders((requestParams as {headers: any}).headers),\n };\n }\n\n return requestParams;\n}\n\nfunction serializeResponse(response: Response | any) {\n if (!response) {\n return {error: 'No response object provided'};\n }\n\n try {\n const {status, statusText, ok, redirected, type, url, headers} = response;\n\n const serialized: any = {\n status,\n statusText,\n ok,\n redirected,\n type,\n url,\n };\n\n if (headers) {\n serialized.headers = sanitizeEnumerableHeaders(headers);\n }\n\n return serialized;\n } catch {\n return response;\n }\n}\n\nexport function clientLoggerFactory(config: ConfigInterface) {\n return (logContent: LogContent) => {\n if (config.logger.httpRequests) {\n switch (logContent.type) {\n case 'HTTP-Response': {\n const responseLog: HTTPResponseLog['content'] = logContent.content;\n logger(config).debug('Received response for HTTP request', {\n requestParams: JSON.stringify(\n sanitizeRequestParams(responseLog.requestParams),\n ),\n response: JSON.stringify(serializeResponse(responseLog.response)),\n });\n break;\n }\n case 'HTTP-Retry': {\n const responseLog: HTTPRetryLog['content'] = logContent.content;\n logger(config).debug('Retrying HTTP request', {\n requestParams: JSON.stringify(\n sanitizeRequestParams(responseLog.requestParams),\n ),\n retryAttempt: responseLog.retryAttempt,\n maxRetries: responseLog.maxRetries,\n response: responseLog.lastResponse\n ? JSON.stringify(serializeResponse(responseLog.lastResponse))\n : 'undefined',\n });\n break;\n }\n case 'HTTP-Response-GraphQL-Deprecation-Notice': {\n const responseLog: HTTPResponseGraphQLDeprecationNotice['content'] =\n logContent.content;\n logger(config).debug(\n 'Received response containing Deprecated GraphQL Notice',\n {\n requestParams: JSON.stringify(\n sanitizeRequestParams(responseLog.requestParams),\n ),\n deprecationNotice: responseLog.deprecationNotice,\n },\n );\n break;\n }\n default: {\n logger(config).debug(`HTTP request event: ${logContent.content}`);\n break;\n }\n }\n }\n };\n}\n\nexport function throwFailedRequest(\n body: any,\n atMaxRetries: boolean,\n response?: Response,\n): never {\n if (typeof response === 'undefined') {\n const message = body?.errors?.message ?? '';\n throw new ShopifyErrors.HttpRequestError(\n `Http request error, no response available: ${message}`,\n );\n }\n\n const responseHeaders = canonicalizeHeaders(\n Object.fromEntries(response.headers.entries() ?? []),\n );\n\n if (response.status === StatusCode.Ok && body.errors.graphQLErrors) {\n throw new ShopifyErrors.GraphqlQueryError({\n message:\n body.errors.graphQLErrors?.[0].message ?? 'GraphQL operation failed',\n response: response as Record<string, any>,\n headers: responseHeaders,\n body: body as Record<string, any>,\n });\n }\n\n const errorMessages: string[] = [];\n if (body.errors) {\n errorMessages.push(JSON.stringify(body.errors, null, 2));\n }\n const xRequestId = getHeader(responseHeaders, 'x-request-id');\n if (xRequestId) {\n errorMessages.push(\n `If you report this error, please include this id: ${xRequestId}`,\n );\n }\n\n const errorMessage = errorMessages.length\n ? `:\\n${errorMessages.join('\\n')}`\n : '';\n const code = response.status;\n const statusText = response.statusText;\n\n switch (true) {\n case response.status === StatusCode.TooManyRequests: {\n if (atMaxRetries) {\n throw new ShopifyErrors.HttpMaxRetriesError(\n 'Attempted the maximum number of retries for HTTP request.',\n );\n } else {\n const retryAfter = getHeader(responseHeaders, 'Retry-After');\n throw new ShopifyErrors.HttpThrottlingError({\n message: `Shopify is throttling requests ${errorMessage}`,\n code,\n statusText,\n body,\n headers: responseHeaders,\n retryAfter: retryAfter ? parseFloat(retryAfter) : undefined,\n });\n }\n }\n case response.status >= StatusCode.InternalServerError:\n if (atMaxRetries) {\n throw new ShopifyErrors.HttpMaxRetriesError(\n 'Attempted the maximum number of retries for HTTP request.',\n );\n } else {\n throw new ShopifyErrors.HttpInternalError({\n message: `Shopify internal error${errorMessage}`,\n code,\n statusText,\n body,\n headers: responseHeaders,\n });\n }\n default:\n throw new ShopifyErrors.HttpResponseError({\n message: `Received an error response (${response.status} ${response.statusText}) from Shopify${errorMessage}`,\n code,\n statusText,\n body,\n headers: responseHeaders,\n });\n }\n}\n"],"names":["ShopifyErrors.HttpRequestError","ShopifyErrors.GraphqlQueryError","ShopifyErrors.HttpMaxRetriesError","ShopifyErrors.HttpThrottlingError","ShopifyErrors.HttpInternalError","ShopifyErrors.HttpResponseError"],"mappings":";;;;;;;AAkBM,SAAU,YAAY,CAAC,MAAuB,EAAA;IAClD,IAAI,eAAe,GAAG,CAAA,EAAG,YAAY,CAAA,EAAA,EAAK,2BAA2B,CAAA,GAAA,EAAM,qBAAqB,EAAE,CAAA,CAAE;AACpG,IAAA,IAAI,MAAM,CAAC,eAAe,EAAE;QAC1B,eAAe,GAAG,GAAG,MAAM,CAAC,eAAe,CAAA,GAAA,EAAM,eAAe,EAAE;IACpE;AAEA,IAAA,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MAAM,IAAIC,iBAA+B,CAAC;gBACxC,OAAO,EAAE,CAAA,4BAAA,EAA+B,QAAQ,CAAC,MAAM,CAAA,CAAA,EAAI,QAAQ,CAAC,UAAU,CAAA,cAAA,EAAiB,YAAY,CAAA,CAAE;gBAC7G,IAAI;gBACJ,UAAU;gBACV,IAAI;AACJ,gBAAA,OAAO,EAAE,eAAe;AACzB,aAAA,CAAC;;AAER;;;;"}
@@ -41,11 +41,9 @@ const ShopifyEventsHeader = {
41
41
  Topic: 'shopify-topic',
42
42
  Domain: 'shopify-shop-domain',
43
43
  ApiVersion: 'shopify-api-version',
44
- EventId: 'shopify-event-id',
45
44
  WebhookId: 'shopify-webhook-id',
46
45
  Handle: 'shopify-handle',
47
46
  Action: 'shopify-action',
48
- ResourceId: 'shopify-resource-id',
49
47
  TriggeredAt: 'shopify-triggered-at',
50
48
  };
51
49
  var ClientType;
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sources":["../../../../../lib/types.ts"],"sourcesContent":["export enum LogSeverity {\n Error,\n Warning,\n Info,\n Debug,\n}\n\nexport enum ApiVersion {\n October24 = '2024-10',\n January25 = '2025-01',\n April25 = '2025-04',\n July25 = '2025-07',\n October25 = '2025-10',\n January26 = '2026-01',\n April26 = '2026-04',\n July26 = '2026-07',\n October26 = '2026-10',\n Unstable = 'unstable',\n}\n\nexport const LIBRARY_NAME = 'Shopify API Library';\n\n/* eslint-disable @shopify/typescript-prefer-pascal-case-enums */\nexport enum ShopifyHeader {\n AccessToken = 'X-Shopify-Access-Token',\n ApiVersion = 'X-Shopify-API-Version',\n Domain = 'X-Shopify-Shop-Domain',\n Hmac = 'X-Shopify-Hmac-Sha256',\n Topic = 'X-Shopify-Topic',\n WebhookId = 'X-Shopify-Webhook-Id',\n Name = 'X-Shopify-Name',\n TriggeredAt = 'X-Shopify-Triggered-At',\n EventId = 'X-Shopify-Event-Id',\n StorefrontPrivateToken = 'Shopify-Storefront-Private-Token',\n StorefrontSDKVariant = 'X-SDK-Variant',\n StorefrontSDKVersion = 'X-SDK-Version',\n}\n/* eslint-enable @shopify/typescript-prefer-pascal-case-enums */\n\nexport const ShopifyEventsHeader = {\n Hmac: 'shopify-hmac-sha256',\n Topic: 'shopify-topic',\n Domain: 'shopify-shop-domain',\n ApiVersion: 'shopify-api-version',\n EventId: 'shopify-event-id',\n WebhookId: 'shopify-webhook-id',\n Handle: 'shopify-handle',\n Action: 'shopify-action',\n ResourceId: 'shopify-resource-id',\n TriggeredAt: 'shopify-triggered-at',\n} as const;\n\nexport enum ClientType {\n Rest = 'rest',\n Graphql = 'graphql',\n}\n\nexport const privacyTopics: string[] = [\n 'CUSTOMERS_DATA_REQUEST',\n 'CUSTOMERS_REDACT',\n 'SHOP_REDACT',\n];\n\nexport enum BillingInterval {\n OneTime = 'ONE_TIME',\n Every30Days = 'EVERY_30_DAYS',\n Annual = 'ANNUAL',\n Usage = 'USAGE',\n}\n\nexport type RecurringBillingIntervals = Exclude<\n BillingInterval,\n BillingInterval.OneTime\n>;\n\nexport enum BillingReplacementBehavior {\n ApplyImmediately = 'APPLY_IMMEDIATELY',\n ApplyOnNextBillingCycle = 'APPLY_ON_NEXT_BILLING_CYCLE',\n Standard = 'STANDARD',\n}\n\nexport enum StatusCode {\n Continue = 100,\n SwitchingProtocols = 101,\n Ok = 200,\n Created = 201,\n Accepted = 202,\n NonAuthoritativeInformation = 203,\n NoContent = 204,\n ResetContent = 205,\n PartialContent = 206,\n MultipleChoices = 300,\n MovedPermanently = 301,\n Found = 302,\n SeeOther = 303,\n NotModified = 304,\n UseProxy = 305,\n TemporaryRedirect = 307,\n BadRequest = 400,\n Unauthorized = 401,\n PaymentRequired = 402,\n Forbidden = 403,\n NotFound = 404,\n MethodNotAllowed = 405,\n NotAcceptable = 406,\n ProxyAuthenticationRequired = 407,\n RequestTimeout = 408,\n Conflict = 409,\n Gone = 410,\n LengthRequired = 411,\n PreconditionFailed = 412,\n RequestEntityTooLarge = 413,\n RequestUriTooLong = 414,\n UnsupportedMediaType = 415,\n RequestedRangeNotSatisfiable = 416,\n ExpectationFailed = 417,\n ImATeapot = 418,\n UnprocessableEntity = 422,\n TooManyRequests = 429,\n InternalServerError = 500,\n NotImplemented = 501,\n BadGateway = 502,\n ServiceUnavailable = 503,\n GatewayTimeout = 504,\n HttpVersionNotSupported = 505,\n}\n\nexport enum Method {\n Get = 'GET',\n Post = 'POST',\n Put = 'PUT',\n Patch = 'PATCH',\n Delete = 'DELETE',\n Head = 'HEAD',\n Options = 'OPTIONS',\n Connect = 'CONNECT',\n}\n\n/**\n * Configuration for transforming shop domains in split-domain architectures.\n *\n * @example\n * // Template-based transformation\n * {\n * match: /^([a-zA-Z0-9][a-zA-Z0-9-_]*)\\.my\\.shop\\.dev$/,\n * transform: '$1.dev-api.shop.dev'\n * }\n *\n * @example\n * // Function-based transformation\n * {\n * match: /^([^.]+)\\.ui\\.example\\.com$/,\n * transform: (matches) => `${matches[1]}.api.example.com`\n * }\n */\nexport interface DomainTransformation {\n /**\n * Pattern to match against shop domains (source domain).\n * Can be a RegExp or string (converted to RegExp internally).\n */\n match: RegExp | string;\n\n /**\n * Transformation function or template string.\n * - Template string: Uses $1, $2, etc. for capture group substitution\n * - Function: Receives regex match groups and returns transformed domain\n */\n transform: ((matches: RegExpMatchArray) => string | null) | string;\n\n /**\n * Whether this transformation should also apply to host validation.\n * @default true\n */\n includeHost?: boolean;\n}\n"],"names":[],"mappings":"IAAY;AAAZ,CAAA,UAAY,WAAW,EAAA;AACrB,IAAA,WAAA,CAAA,WAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAK;AACL,IAAA,WAAA,CAAA,WAAA,CAAA,SAAA,CAAA,GAAA,CAAA,CAAA,GAAA,SAAO;AACP,IAAA,WAAA,CAAA,WAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI;AACJ,IAAA,WAAA,CAAA,WAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAK;AACP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AA,CAAA,KAAA,CAAA,GAAA,KAAW;AACX,IAAA,MAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,MAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACX,IAAA,MAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACf,IAAA,MAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACjB,IAAA,MAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,MAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,MAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACrB,CAAC,EATW,MAAM,KAAN,MAAM,GAAA,EAAA,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"types.mjs","sources":["../../../../../lib/types.ts"],"sourcesContent":["export enum LogSeverity {\n Error,\n Warning,\n Info,\n Debug,\n}\n\nexport enum ApiVersion {\n October24 = '2024-10',\n January25 = '2025-01',\n April25 = '2025-04',\n July25 = '2025-07',\n October25 = '2025-10',\n January26 = '2026-01',\n April26 = '2026-04',\n July26 = '2026-07',\n October26 = '2026-10',\n Unstable = 'unstable',\n}\n\nexport const LIBRARY_NAME = 'Shopify API Library';\n\n/* eslint-disable @shopify/typescript-prefer-pascal-case-enums */\nexport enum ShopifyHeader {\n AccessToken = 'X-Shopify-Access-Token',\n ApiVersion = 'X-Shopify-API-Version',\n Domain = 'X-Shopify-Shop-Domain',\n Hmac = 'X-Shopify-Hmac-Sha256',\n Topic = 'X-Shopify-Topic',\n WebhookId = 'X-Shopify-Webhook-Id',\n Name = 'X-Shopify-Name',\n TriggeredAt = 'X-Shopify-Triggered-At',\n EventId = 'X-Shopify-Event-Id',\n StorefrontPrivateToken = 'Shopify-Storefront-Private-Token',\n StorefrontSDKVariant = 'X-SDK-Variant',\n StorefrontSDKVersion = 'X-SDK-Version',\n}\n/* eslint-enable @shopify/typescript-prefer-pascal-case-enums */\n\nexport const ShopifyEventsHeader = {\n Hmac: 'shopify-hmac-sha256',\n Topic: 'shopify-topic',\n Domain: 'shopify-shop-domain',\n ApiVersion: 'shopify-api-version',\n WebhookId: 'shopify-webhook-id',\n Handle: 'shopify-handle',\n Action: 'shopify-action',\n TriggeredAt: 'shopify-triggered-at',\n} as const;\n\nexport enum ClientType {\n Rest = 'rest',\n Graphql = 'graphql',\n}\n\nexport const privacyTopics: string[] = [\n 'CUSTOMERS_DATA_REQUEST',\n 'CUSTOMERS_REDACT',\n 'SHOP_REDACT',\n];\n\nexport enum BillingInterval {\n OneTime = 'ONE_TIME',\n Every30Days = 'EVERY_30_DAYS',\n Annual = 'ANNUAL',\n Usage = 'USAGE',\n}\n\nexport type RecurringBillingIntervals = Exclude<\n BillingInterval,\n BillingInterval.OneTime\n>;\n\nexport enum BillingReplacementBehavior {\n ApplyImmediately = 'APPLY_IMMEDIATELY',\n ApplyOnNextBillingCycle = 'APPLY_ON_NEXT_BILLING_CYCLE',\n Standard = 'STANDARD',\n}\n\nexport enum StatusCode {\n Continue = 100,\n SwitchingProtocols = 101,\n Ok = 200,\n Created = 201,\n Accepted = 202,\n NonAuthoritativeInformation = 203,\n NoContent = 204,\n ResetContent = 205,\n PartialContent = 206,\n MultipleChoices = 300,\n MovedPermanently = 301,\n Found = 302,\n SeeOther = 303,\n NotModified = 304,\n UseProxy = 305,\n TemporaryRedirect = 307,\n BadRequest = 400,\n Unauthorized = 401,\n PaymentRequired = 402,\n Forbidden = 403,\n NotFound = 404,\n MethodNotAllowed = 405,\n NotAcceptable = 406,\n ProxyAuthenticationRequired = 407,\n RequestTimeout = 408,\n Conflict = 409,\n Gone = 410,\n LengthRequired = 411,\n PreconditionFailed = 412,\n RequestEntityTooLarge = 413,\n RequestUriTooLong = 414,\n UnsupportedMediaType = 415,\n RequestedRangeNotSatisfiable = 416,\n ExpectationFailed = 417,\n ImATeapot = 418,\n UnprocessableEntity = 422,\n TooManyRequests = 429,\n InternalServerError = 500,\n NotImplemented = 501,\n BadGateway = 502,\n ServiceUnavailable = 503,\n GatewayTimeout = 504,\n HttpVersionNotSupported = 505,\n}\n\nexport enum Method {\n Get = 'GET',\n Post = 'POST',\n Put = 'PUT',\n Patch = 'PATCH',\n Delete = 'DELETE',\n Head = 'HEAD',\n Options = 'OPTIONS',\n Connect = 'CONNECT',\n}\n\n/**\n * Configuration for transforming shop domains in split-domain architectures.\n *\n * @example\n * // Template-based transformation\n * {\n * match: /^([a-zA-Z0-9][a-zA-Z0-9-_]*)\\.my\\.shop\\.dev$/,\n * transform: '$1.dev-api.shop.dev'\n * }\n *\n * @example\n * // Function-based transformation\n * {\n * match: /^([^.]+)\\.ui\\.example\\.com$/,\n * transform: (matches) => `${matches[1]}.api.example.com`\n * }\n */\nexport interface DomainTransformation {\n /**\n * Pattern to match against shop domains (source domain).\n * Can be a RegExp or string (converted to RegExp internally).\n */\n match: RegExp | string;\n\n /**\n * Transformation function or template string.\n * - Template string: Uses $1, $2, etc. for capture group substitution\n * - Function: Receives regex match groups and returns transformed domain\n */\n transform: ((matches: RegExpMatchArray) => string | null) | string;\n\n /**\n * Whether this transformation should also apply to host validation.\n * @default true\n */\n includeHost?: boolean;\n}\n"],"names":[],"mappings":"IAAY;AAAZ,CAAA,UAAY,WAAW,EAAA;AACrB,IAAA,WAAA,CAAA,WAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAK;AACL,IAAA,WAAA,CAAA,WAAA,CAAA,SAAA,CAAA,GAAA,CAAA,CAAA,GAAA,SAAO;AACP,IAAA,WAAA,CAAA,WAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI;AACJ,IAAA,WAAA,CAAA,WAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAK;AACP,CAAC,EALW,WAAW,KAAX,WAAW,GAAA,EAAA,CAAA,CAAA;IAOX;AAAZ,CAAA,UAAY,UAAU,EAAA;AACpB,IAAA,UAAA,CAAA,WAAA,CAAA,GAAA,SAAqB;AACrB,IAAA,UAAA,CAAA,WAAA,C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A,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,MAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,MAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACrB,CAAC,EATW,MAAM,KAAN,MAAM,GAAA,EAAA,CAAA,CAAA;;;;"}
@@ -2,6 +2,17 @@ import { logger } from '../logger/index.mjs';
2
2
  import { LogSeverity } from '../types.mjs';
3
3
  import { abstractFetch } from '../../runtime/http/index.mjs';
4
4
 
5
+ const OAUTH_TOKEN_ENDPOINT_PATH = '/admin/oauth/access_token';
6
+ // Token endpoint bodies carry OAuth secrets, so they must not reach the logs.
7
+ // When the URL does not parse, fail closed and keep the body out of the logs.
8
+ function canLogRequestBody(url) {
9
+ try {
10
+ return new URL(url).pathname !== OAUTH_TOKEN_ENDPOINT_PATH;
11
+ }
12
+ catch {
13
+ return false;
14
+ }
15
+ }
5
16
  function fetchRequestFactory(config) {
6
17
  return async function fetchRequest(url, options) {
7
18
  const log = logger(config);
@@ -10,7 +21,7 @@ function fetchRequestFactory(config) {
10
21
  log.debug('Making HTTP request', {
11
22
  method: options?.method || 'GET',
12
23
  url,
13
- ...(options?.body && { body: options?.body }),
24
+ ...(options?.body && canLogRequestBody(url) && { body: options.body }),
14
25
  });
15
26
  }
16
27
  const response = await abstractFetch(url, options);
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-request.mjs","sources":["../../../../../../lib/utils/fetch-request.ts"],"sourcesContent":["import {logger} from '../logger';\nimport {LogSeverity} from '../types';\nimport {abstractFetch} from '../../runtime';\nimport {ConfigInterface} from '../base-types';\n\nexport function fetchRequestFactory(config: ConfigInterface) {\n return async function fetchRequest(\n url: string,\n options?: RequestInit,\n ): Promise<Response> {\n const log = logger(config);\n const doLog =\n config.logger.httpRequests && config.logger.level === LogSeverity.Debug;\n\n if (doLog) {\n log.debug('Making HTTP request', {\n method: options?.method || 'GET',\n url,\n ...(options?.body && {body: options?.body}),\n });\n }\n\n const response = await abstractFetch(url, options);\n\n if (doLog) {\n log.debug('HTTP request completed', {\n method: options?.method || 'GET',\n url,\n status: response.status,\n });\n }\n\n return response;\n };\n}\n"],"names":[],"mappings":";;;;AAKM,SAAU,mBAAmB,CAAC,MAAuB,EAAA;AACzD,IAAA,OAAO,eAAe,YAAY,CAChC,GAAW,EACX,OAAqB,EAAA;AAErB,QAAA,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;AAC1B,QAAA,MAAM,KAAK,GACT,MAAM,CAAC,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,KAAK,WAAW,CAAC,KAAK;QAEzE,IAAI,KAAK,EAAE;AACT,YAAA,GAAG,CAAC,KAAK,CAAC,qBAAqB,EAAE;AAC/B,gBAAA,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,KAAK;gBAChC,GAAG;AACH,gBAAA,IAAI,OAAO,EAAE,IAAI,IAAI,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;AAC5C,aAAA,CAAC;QACJ;QAEA,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC;QAElD,IAAI,KAAK,EAAE;AACT,YAAA,GAAG,CAAC,KAAK,CAAC,wBAAwB,EAAE;AAClC,gBAAA,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,KAAK;gBAChC,GAAG;gBACH,MAAM,EAAE,QAAQ,CAAC,MAAM;AACxB,aAAA,CAAC;QACJ;AAEA,QAAA,OAAO,QAAQ;AACjB,IAAA,CAAC;AACH;;;;"}
1
+ {"version":3,"file":"fetch-request.mjs","sources":["../../../../../../lib/utils/fetch-request.ts"],"sourcesContent":["import {logger} from '../logger';\nimport {LogSeverity} from '../types';\nimport {abstractFetch} from '../../runtime';\nimport {ConfigInterface} from '../base-types';\n\nconst OAUTH_TOKEN_ENDPOINT_PATH = '/admin/oauth/access_token';\n\n// Token endpoint bodies carry OAuth secrets, so they must not reach the logs.\n// When the URL does not parse, fail closed and keep the body out of the logs.\nfunction canLogRequestBody(url: string): boolean {\n try {\n return new URL(url).pathname !== OAUTH_TOKEN_ENDPOINT_PATH;\n } catch {\n return false;\n }\n}\n\nexport function fetchRequestFactory(config: ConfigInterface) {\n return async function fetchRequest(\n url: string,\n options?: RequestInit,\n ): Promise<Response> {\n const log = logger(config);\n const doLog =\n config.logger.httpRequests && config.logger.level === LogSeverity.Debug;\n\n if (doLog) {\n log.debug('Making HTTP request', {\n method: options?.method || 'GET',\n url,\n ...(options?.body && canLogRequestBody(url) && {body: options.body}),\n });\n }\n\n const response = await abstractFetch(url, options);\n\n if (doLog) {\n log.debug('HTTP request completed', {\n method: options?.method || 'GET',\n url,\n status: response.status,\n });\n }\n\n return response;\n };\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,yBAAyB,GAAG,2BAA2B;AAE7D;AACA;AACA,SAAS,iBAAiB,CAAC,GAAW,EAAA;AACpC,IAAA,IAAI;QACF,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAK,yBAAyB;IAC5D;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,KAAK;IACd;AACF;AAEM,SAAU,mBAAmB,CAAC,MAAuB,EAAA;AACzD,IAAA,OAAO,eAAe,YAAY,CAChC,GAAW,EACX,OAAqB,EAAA;AAErB,QAAA,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;AAC1B,QAAA,MAAM,KAAK,GACT,MAAM,CAAC,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,KAAK,WAAW,CAAC,KAAK;QAEzE,IAAI,KAAK,EAAE;AACT,YAAA,GAAG,CAAC,KAAK,CAAC,qBAAqB,EAAE;AAC/B,gBAAA,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,KAAK;gBAChC,GAAG;AACH,gBAAA,IAAI,OAAO,EAAE,IAAI,IAAI,iBAAiB,CAAC,GAAG,CAAC,IAAI,EAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAC,CAAC;AACrE,aAAA,CAAC;QACJ;QAEA,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC;QAElD,IAAI,KAAK,EAAE;AACT,YAAA,GAAG,CAAC,KAAK,CAAC,wBAAwB,EAAE;AAClC,gBAAA,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,KAAK;gBAChC,GAAG;gBACH,MAAM,EAAE,QAAQ,CAAC,MAAM;AACxB,aAAA,CAAC;QACJ;AAEA,QAAA,OAAO,QAAQ;AACjB,IAAA,CAAC;AACH;;;;"}
@@ -1,4 +1,4 @@
1
- const SHOPIFY_API_LIBRARY_VERSION = '14.0.0';
1
+ const SHOPIFY_API_LIBRARY_VERSION = '15.0.0';
2
2
 
3
3
  export { SHOPIFY_API_LIBRARY_VERSION };
4
4
  //# sourceMappingURL=version.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.mjs","sources":["../../../../../lib/version.ts"],"sourcesContent":["export const SHOPIFY_API_LIBRARY_VERSION = '14.0.0';\n"],"names":[],"mappings":"AAAO,MAAM,2BAA2B,GAAG;;;;"}
1
+ {"version":3,"file":"version.mjs","sources":["../../../../../lib/version.ts"],"sourcesContent":["export const SHOPIFY_API_LIBRARY_VERSION = '15.0.0';\n"],"names":[],"mappings":"AAAO,MAAM,2BAA2B,GAAG;;;;"}
@@ -22,10 +22,8 @@ const WEBHOOK_HEADER_NAMES = {
22
22
  domain: ShopifyEventsHeader.Domain,
23
23
  apiVersion: ShopifyEventsHeader.ApiVersion,
24
24
  webhookId: ShopifyEventsHeader.WebhookId,
25
- eventId: ShopifyEventsHeader.EventId,
26
25
  handle: ShopifyEventsHeader.Handle,
27
26
  action: ShopifyEventsHeader.Action,
28
- resourceId: ShopifyEventsHeader.ResourceId,
29
27
  triggeredAt: ShopifyEventsHeader.TriggeredAt,
30
28
  },
31
29
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sources":["../../../../../../lib/webhooks/types.ts"],"sourcesContent":["import {ValidationErrorReason, ValidationInvalid} from '../utils/types';\nimport {AdapterArgs} from '../../runtime/types';\nimport {Session} from '../session/session';\nimport {ShopifyEventsHeader, ShopifyHeader} from '../types';\n\nexport const WebhookType = {\n Webhooks: 'webhooks',\n Events: 'events',\n} as const;\n\nexport type WebhookTypeValue = (typeof WebhookType)[keyof typeof WebhookType];\n\nexport const WEBHOOK_HEADER_NAMES = {\n [WebhookType.Webhooks]: {\n hmac: ShopifyHeader.Hmac,\n topic: ShopifyHeader.Topic,\n domain: ShopifyHeader.Domain,\n apiVersion: ShopifyHeader.ApiVersion,\n webhookId: ShopifyHeader.WebhookId,\n name: ShopifyHeader.Name,\n triggeredAt: ShopifyHeader.TriggeredAt,\n eventId: ShopifyHeader.EventId,\n },\n [WebhookType.Events]: {\n hmac: ShopifyEventsHeader.Hmac,\n topic: ShopifyEventsHeader.Topic,\n domain: ShopifyEventsHeader.Domain,\n apiVersion: ShopifyEventsHeader.ApiVersion,\n webhookId: ShopifyEventsHeader.WebhookId,\n eventId: ShopifyEventsHeader.EventId,\n handle: ShopifyEventsHeader.Handle,\n action: ShopifyEventsHeader.Action,\n resourceId: ShopifyEventsHeader.ResourceId,\n triggeredAt: ShopifyEventsHeader.TriggeredAt,\n },\n} as const;\n\nexport enum DeliveryMethod {\n Http = 'http',\n EventBridge = 'eventbridge',\n PubSub = 'pubsub',\n}\n\nexport type WebhookHandlerFunction = (\n topic: string,\n shop_domain: string,\n body: string,\n webhookId: string,\n apiVersion?: string,\n context?: any,\n) => Promise<void>;\n\ninterface BaseWebhookHandler {\n id?: string;\n includeFields?: string[];\n metafieldNamespaces?: string[];\n context?: any;\n}\n\nexport interface HttpWebhookHandler extends BaseWebhookHandler {\n deliveryMethod: DeliveryMethod.Http;\n callbackUrl: string;\n}\n\nexport interface HttpWebhookHandlerWithCallback extends HttpWebhookHandler {\n callback: WebhookHandlerFunction;\n}\n\nexport interface EventBridgeWebhookHandler extends BaseWebhookHandler {\n deliveryMethod: DeliveryMethod.EventBridge;\n arn: string;\n}\n\nexport interface PubSubWebhookHandler extends BaseWebhookHandler {\n deliveryMethod: DeliveryMethod.PubSub;\n pubSubProject: string;\n pubSubTopic: string;\n}\n\nexport type WebhookHandler =\n | HttpWebhookHandler\n | HttpWebhookHandlerWithCallback\n | EventBridgeWebhookHandler\n | PubSubWebhookHandler;\n\n// See https://shopify.dev/docs/api/admin-graphql/latest/enums/webhooksubscriptiontopic for available topics\nexport type WebhookRegistry<Handler extends WebhookHandler = WebhookHandler> =\n Record<string, Handler[]>;\n\n// eslint-disable-next-line no-warning-comments\n// TODO Rethink the wording for this enum - the operations we're doing are actually \"subscribing\" and \"unsubscribing\"\n// Consider changing the values when releasing v12.0.0 when it can be safely deprecated\nexport enum WebhookOperation {\n Create = 'create',\n Update = 'update',\n Delete = 'delete',\n}\n\nexport interface RegisterParams {\n session: Session;\n}\n\nexport interface RegisterResult {\n success: boolean;\n deliveryMethod: DeliveryMethod;\n result: unknown;\n operation: WebhookOperation;\n}\n\nexport type RegisterReturn = Record<string, RegisterResult[]>;\n\ninterface WebhookHttpEndpoint {\n __typename: 'WebhookHttpEndpoint';\n callbackUrl: string;\n}\ninterface WebhookEventBridgeEndpoint {\n __typename: 'WebhookEventBridgeEndpoint';\n arn: string;\n}\ninterface WebhookPubSubEndpoint {\n __typename: 'WebhookPubSubEndpoint';\n pubSubProject: string;\n pubSubTopic: string;\n}\n\ntype WebhookEndpoint =\n WebhookHttpEndpoint | WebhookEventBridgeEndpoint | WebhookPubSubEndpoint;\n\nexport interface WebhookCheckResponseNode<\n T = {\n endpoint: WebhookEndpoint;\n },\n> {\n node: {\n id: string;\n topic: string;\n includeFields: string[];\n metafieldNamespaces: string[];\n } & T;\n}\n\nexport interface WebhookCheckResponse<T = WebhookCheckResponseNode> {\n webhookSubscriptions: {\n edges: T[];\n pageInfo: {\n endCursor: string;\n hasNextPage: boolean;\n };\n };\n}\n\nexport type AddHandlersParams = Record<\n string,\n WebhookHandler | WebhookHandler[]\n>;\n\nexport interface WebhookProcessParams extends AdapterArgs {\n rawBody: string;\n context?: any;\n}\n\nexport interface WebhookValidateParams extends WebhookProcessParams {}\n\nexport const WebhookValidationErrorReason = {\n ...ValidationErrorReason,\n MissingHeaders: 'missing_headers',\n} as const;\n\nexport type WebhookValidationErrorReasonType =\n (typeof WebhookValidationErrorReason)[keyof typeof WebhookValidationErrorReason];\n\ninterface BaseWebhookFields {\n apiVersion: string;\n domain: string;\n hmac: string;\n topic: string;\n triggeredAt?: string;\n}\n\nexport interface WebhooksWebhookFields extends BaseWebhookFields {\n webhookType: typeof WebhookType.Webhooks;\n webhookId: string;\n name?: string;\n eventId?: string;\n}\n\nexport interface EventsWebhookFields extends BaseWebhookFields {\n webhookType: typeof WebhookType.Events;\n webhookId: string;\n eventId: string;\n handle?: string;\n action?: string;\n resourceId?: string;\n}\n\nexport type WebhookFields = WebhooksWebhookFields | EventsWebhookFields;\n\nexport interface WebhookValidationInvalid extends Omit<\n ValidationInvalid,\n 'reason'\n> {\n valid: false;\n reason: WebhookValidationErrorReasonType;\n}\n\nexport interface WebhookValidationMissingHeaders extends WebhookValidationInvalid {\n reason: typeof WebhookValidationErrorReason.MissingHeaders;\n missingHeaders: string[];\n}\n\nexport type WebhookValidationValid = WebhookFields & {valid: true};\n\nexport type WebhookValidation =\n | WebhookValidationValid\n | WebhookValidationInvalid\n | WebhookValidationMissingHeaders;\n"],"names":[],"mappings":";;;AAKO,MAAM,WAAW,GAAG;AACzB,IAAA,QAAQ,EAAE,UAAU;AACpB,IAAA,MAAM,EAAE,QAAQ;;AAKX,MAAM,oBAAoB,GAAG;AAClC,IAAA,CAAC,WAAW,CAAC,QAAQ,GAAG;QACtB,IAAI,EAAE,aAAa,CAAC,IAAI;QACxB,KAAK,EAAE,aAAa,CAAC,KAAK;QAC1B,MAAM,EAAE,aAAa,CAAC,MAAM;QAC5B,UAAU,EAAE,aAAa,CAAC,UAAU;QACpC,SAAS,EAAE,a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../../lib/webhooks/types.ts"],"sourcesContent":["import {ValidationErrorReason, ValidationInvalid} from '../utils/types';\nimport {AdapterArgs} from '../../runtime/types';\nimport {Session} from '../session/session';\nimport {ShopifyEventsHeader, ShopifyHeader} from '../types';\n\nexport const WebhookType = {\n Webhooks: 'webhooks',\n Events: 'events',\n} as const;\n\nexport type WebhookTypeValue = (typeof WebhookType)[keyof typeof WebhookType];\n\nexport const WEBHOOK_HEADER_NAMES = {\n [WebhookType.Webhooks]: {\n hmac: ShopifyHeader.Hmac,\n topic: ShopifyHeader.Topic,\n domain: ShopifyHeader.Domain,\n apiVersion: ShopifyHeader.ApiVersion,\n webhookId: ShopifyHeader.WebhookId,\n name: ShopifyHeader.Name,\n triggeredAt: ShopifyHeader.TriggeredAt,\n eventId: ShopifyHeader.EventId,\n },\n [WebhookType.Events]: {\n hmac: ShopifyEventsHeader.Hmac,\n topic: ShopifyEventsHeader.Topic,\n domain: ShopifyEventsHeader.Domain,\n apiVersion: ShopifyEventsHeader.ApiVersion,\n webhookId: ShopifyEventsHeader.WebhookId,\n handle: ShopifyEventsHeader.Handle,\n action: ShopifyEventsHeader.Action,\n triggeredAt: ShopifyEventsHeader.TriggeredAt,\n },\n} as const;\n\nexport enum DeliveryMethod {\n Http = 'http',\n EventBridge = 'eventbridge',\n PubSub = 'pubsub',\n}\n\nexport type WebhookHandlerFunction = (\n topic: string,\n shop_domain: string,\n body: string,\n webhookId: string,\n apiVersion?: string,\n context?: any,\n) => Promise<void>;\n\ninterface BaseWebhookHandler {\n id?: string;\n includeFields?: string[];\n metafieldNamespaces?: string[];\n context?: any;\n}\n\nexport interface HttpWebhookHandler extends BaseWebhookHandler {\n deliveryMethod: DeliveryMethod.Http;\n callbackUrl: string;\n}\n\nexport interface HttpWebhookHandlerWithCallback extends HttpWebhookHandler {\n callback: WebhookHandlerFunction;\n}\n\nexport interface EventBridgeWebhookHandler extends BaseWebhookHandler {\n deliveryMethod: DeliveryMethod.EventBridge;\n arn: string;\n}\n\nexport interface PubSubWebhookHandler extends BaseWebhookHandler {\n deliveryMethod: DeliveryMethod.PubSub;\n pubSubProject: string;\n pubSubTopic: string;\n}\n\nexport type WebhookHandler =\n | HttpWebhookHandler\n | HttpWebhookHandlerWithCallback\n | EventBridgeWebhookHandler\n | PubSubWebhookHandler;\n\n// See https://shopify.dev/docs/api/admin-graphql/latest/enums/webhooksubscriptiontopic for available topics\nexport type WebhookRegistry<Handler extends WebhookHandler = WebhookHandler> =\n Record<string, Handler[]>;\n\n// eslint-disable-next-line no-warning-comments\n// TODO Rethink the wording for this enum - the operations we're doing are actually \"subscribing\" and \"unsubscribing\"\n// Consider changing the values when releasing v12.0.0 when it can be safely deprecated\nexport enum WebhookOperation {\n Create = 'create',\n Update = 'update',\n Delete = 'delete',\n}\n\nexport interface RegisterParams {\n session: Session;\n}\n\nexport interface RegisterResult {\n success: boolean;\n deliveryMethod: DeliveryMethod;\n result: unknown;\n operation: WebhookOperation;\n}\n\nexport type RegisterReturn = Record<string, RegisterResult[]>;\n\ninterface WebhookHttpEndpoint {\n __typename: 'WebhookHttpEndpoint';\n callbackUrl: string;\n}\ninterface WebhookEventBridgeEndpoint {\n __typename: 'WebhookEventBridgeEndpoint';\n arn: string;\n}\ninterface WebhookPubSubEndpoint {\n __typename: 'WebhookPubSubEndpoint';\n pubSubProject: string;\n pubSubTopic: string;\n}\n\ntype WebhookEndpoint =\n WebhookHttpEndpoint | WebhookEventBridgeEndpoint | WebhookPubSubEndpoint;\n\nexport interface WebhookCheckResponseNode<\n T = {\n endpoint: WebhookEndpoint;\n },\n> {\n node: {\n id: string;\n topic: string;\n includeFields: string[];\n metafieldNamespaces: string[];\n } & T;\n}\n\nexport interface WebhookCheckResponse<T = WebhookCheckResponseNode> {\n webhookSubscriptions: {\n edges: T[];\n pageInfo: {\n endCursor: string;\n hasNextPage: boolean;\n };\n };\n}\n\nexport type AddHandlersParams = Record<\n string,\n WebhookHandler | WebhookHandler[]\n>;\n\nexport interface WebhookProcessParams extends AdapterArgs {\n rawBody: string;\n context?: any;\n}\n\nexport interface WebhookValidateParams extends WebhookProcessParams {}\n\nexport const WebhookValidationErrorReason = {\n ...ValidationErrorReason,\n MissingHeaders: 'missing_headers',\n} as const;\n\nexport type WebhookValidationErrorReasonType =\n (typeof WebhookValidationErrorReason)[keyof typeof WebhookValidationErrorReason];\n\ninterface BaseWebhookFields {\n apiVersion: string;\n domain: string;\n hmac: string;\n topic: string;\n triggeredAt?: string;\n}\n\nexport interface WebhooksWebhookFields extends BaseWebhookFields {\n webhookType: typeof WebhookType.Webhooks;\n webhookId: string;\n name?: string;\n eventId?: string;\n}\n\nexport interface EventsWebhookFields extends BaseWebhookFields {\n webhookType: typeof WebhookType.Events;\n webhookId: string;\n handle?: string;\n action?: string;\n}\n\nexport type WebhookFields = WebhooksWebhookFields | EventsWebhookFields;\n\nexport interface WebhookValidationInvalid extends Omit<\n ValidationInvalid,\n 'reason'\n> {\n valid: false;\n reason: WebhookValidationErrorReasonType;\n}\n\nexport interface WebhookValidationMissingHeaders extends WebhookValidationInvalid {\n reason: typeof WebhookValidationErrorReason.MissingHeaders;\n missingHeaders: string[];\n}\n\nexport type WebhookValidationValid = WebhookFields & {valid: true};\n\nexport type WebhookValidation =\n | WebhookValidationValid\n | WebhookValidationInvalid\n | WebhookValidationMissingHeaders;\n"],"names":[],"mappings":";;;AAKO,MAAM,WAAW,GAAG;AACzB,IAAA,QAAQ,EAAE,UAAU;AACpB,IAAA,MAAM,EAAE,QAAQ;;AAKX,MAAM,oBAAoB,GAAG;AAClC,IAAA,CAAC,WAAW,CAAC,QAAQ,GAAG;QACtB,IAAI,EAAE,aAAa,CAAC,IAAI;QACxB,KAAK,EAAE,aAAa,CAAC,KAAK;QAC1B,MAAM,EAAE,aAAa,CAAC,MAAM;QAC5B,UAAU,EAAE,aAAa,CAAC,UAAU;QACpC,SAAS,EAAE,aAAa,CAAC,SAAS;QAClC,IAAI,EAAE,aAAa,CAAC,IAAI;QACxB,WAAW,EAAE,aAAa,CAAC,WAAW;QACtC,OAAO,EAAE,aAAa,CAAC,OAAO;AAC/B,KAAA;AACD,IAAA,CAAC,WAAW,CAAC,MAAM,GAAG;QACpB,IAAI,EAAE,mBAAmB,CAAC,IAAI;QAC9B,KAAK,EAAE,mBAAmB,CAAC,KAAK;QAChC,MAAM,EAAE,mBAAmB,CAAC,MAAM;QAClC,UAAU,EAAE,mBAAmB,CAAC,UAAU;QAC1C,SAAS,EAAE,mBAAmB,CAAC,SAAS;QACxC,MAAM,EAAE,mBAAmB,CAAC,MAAM;QAClC,MAAM,EAAE,mBAAmB,CAAC,MAAM;QAClC,WAAW,EAAE,mBAAmB,CAAC,WAAW;AAC7C,KAAA;;IAGS;AAAZ,CAAA,UAAY,cAAc,EAAA;AACxB,IAAA,cAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,cAAA,CAAA,aAAA,CAAA,GAAA,aAA2B;AAC3B,IAAA,cAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACnB,CAAC,EAJW,cAAc,KAAd,cAAc,GAAA,EAAA,CAAA,CAAA;AAoD1B;AACA;AACA;IACY;AAAZ,CAAA,UAAY,gBAAgB,EAAA;AAC1B,IAAA,gBAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACjB,IAAA,gBAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACjB,IAAA,gBAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACnB,CAAC,EAJW,gBAAgB,KAAhB,gBAAgB,GAAA,EAAA,CAAA,CAAA;AAuErB,MAAM,4BAA4B,GAAG;AAC1C,IAAA,GAAG,qBAAqB;AACxB,IAAA,cAAc,EAAE,iBAAiB;;;;;"}
@@ -92,7 +92,6 @@ function checkEventsHeaders(headers) {
92
92
  const domain = getRequiredHeader(headers, headerNames.domain, missingHeaders);
93
93
  const apiVersion = getRequiredHeader(headers, headerNames.apiVersion, missingHeaders);
94
94
  const webhookId = getRequiredHeader(headers, headerNames.webhookId, missingHeaders);
95
- const eventId = getRequiredHeader(headers, headerNames.eventId, missingHeaders);
96
95
  if (missingHeaders.length) {
97
96
  return {
98
97
  valid: false,
@@ -107,7 +106,6 @@ function checkEventsHeaders(headers) {
107
106
  domain: domain,
108
107
  apiVersion: apiVersion,
109
108
  webhookId: webhookId,
110
- eventId: eventId,
111
109
  };
112
110
  const handle = getHeader(headers, headerNames.handle);
113
111
  if (handle)
@@ -115,9 +113,6 @@ function checkEventsHeaders(headers) {
115
113
  const action = getHeader(headers, headerNames.action);
116
114
  if (action)
117
115
  fields.action = action;
118
- const resourceId = getHeader(headers, headerNames.resourceId);
119
- if (resourceId)
120
- fields.resourceId = resourceId;
121
116
  const triggeredAt = getHeader(headers, headerNames.triggeredAt);
122
117
  if (triggeredAt)
123
118
  fields.triggeredAt = triggeredAt;
@@ -1 +1 @@
1
- {"version":3,"file":"validate.mjs","sources":["../../../../../../lib/webhooks/validate.ts"],"sourcesContent":["import {logger} from '../logger';\nimport {validateHmacFromRequestFactory} from '../utils/hmac-validator';\nimport {HmacValidationType, ValidationErrorReason} from '../utils/types';\nimport {\n abstractConvertRequest,\n getHeader,\n Headers,\n NormalizedRequest,\n} from '../../runtime/http';\nimport {ConfigInterface} from '../base-types';\n\nimport {\n EventsWebhookFields,\n WEBHOOK_HEADER_NAMES,\n WebhooksWebhookFields,\n WebhookType,\n WebhookTypeValue,\n WebhookValidateParams,\n WebhookValidation,\n WebhookValidationErrorReason,\n WebhookValidationMissingHeaders,\n WebhookValidationValid,\n} from './types';\nimport {topicForStorage} from './registry';\n\nfunction detectWebhookType(headers: Headers): WebhookTypeValue {\n const eventsHmac = getHeader(\n headers,\n WEBHOOK_HEADER_NAMES[WebhookType.Events].hmac,\n );\n if (eventsHmac) {\n return WebhookType.Events;\n }\n\n const webhooksHmac = getHeader(\n headers,\n WEBHOOK_HEADER_NAMES[WebhookType.Webhooks].hmac,\n );\n if (webhooksHmac) {\n return WebhookType.Webhooks;\n }\n\n return WebhookType.Webhooks;\n}\n\nexport function validateFactory(config: ConfigInterface) {\n return async function validate({\n rawBody,\n ...adapterArgs\n }: WebhookValidateParams): Promise<WebhookValidation> {\n const request: NormalizedRequest =\n await abstractConvertRequest(adapterArgs);\n\n const webhookType = detectWebhookType(request.headers);\n\n const validHmacResult = await validateHmacFromRequestFactory(config)({\n type: HmacValidationType.Webhook,\n rawBody,\n webhookType,\n ...adapterArgs,\n });\n\n if (!validHmacResult.valid) {\n if (validHmacResult.reason === ValidationErrorReason.InvalidHmac) {\n const log = logger(config);\n await log.debug(\n \"Webhook HMAC validation failed. Please note that events manually triggered from a store's Notifications settings will fail this validation. To test this, please use the CLI or trigger the actual event in a development store.\",\n );\n }\n return validHmacResult;\n }\n\n return checkWebhookHeaders(request.headers, webhookType);\n };\n}\n\nfunction getRequiredHeader(\n headers: Headers,\n headerName: string,\n missingHeaders: string[],\n): string | undefined {\n const value = getHeader(headers, headerName);\n if (!value) {\n missingHeaders.push(headerName);\n }\n return value;\n}\n\nfunction checkWebhookHeaders(\n headers: Headers,\n webhookType: WebhookTypeValue,\n): WebhookValidationMissingHeaders | WebhookValidationValid {\n if (webhookType === WebhookType.Webhooks) {\n return checkWebhooksHeaders(headers);\n }\n return checkEventsHeaders(headers);\n}\n\nfunction checkWebhooksHeaders(\n headers: Headers,\n): WebhookValidationMissingHeaders | WebhookValidationValid {\n const headerNames = WEBHOOK_HEADER_NAMES[WebhookType.Webhooks];\n const missingHeaders: string[] = [];\n\n const hmac = getRequiredHeader(headers, headerNames.hmac, missingHeaders);\n const topic = getRequiredHeader(headers, headerNames.topic, missingHeaders);\n const domain = getRequiredHeader(headers, headerNames.domain, missingHeaders);\n const apiVersion = getRequiredHeader(\n headers,\n headerNames.apiVersion,\n missingHeaders,\n );\n const webhookId = getRequiredHeader(\n headers,\n headerNames.webhookId,\n missingHeaders,\n );\n\n if (missingHeaders.length) {\n return {\n valid: false,\n reason: WebhookValidationErrorReason.MissingHeaders,\n missingHeaders,\n };\n }\n\n const fields: WebhooksWebhookFields = {\n webhookType: WebhookType.Webhooks,\n hmac: hmac!,\n topic: topicForStorage(topic!),\n domain: domain!,\n apiVersion: apiVersion!,\n webhookId: webhookId!,\n };\n\n const name = getHeader(headers, headerNames.name);\n if (name) fields.name = name;\n\n const triggeredAt = getHeader(headers, headerNames.triggeredAt);\n if (triggeredAt) fields.triggeredAt = triggeredAt;\n\n const eventId = getHeader(headers, headerNames.eventId);\n if (eventId) fields.eventId = eventId;\n\n return {valid: true, ...fields};\n}\n\nfunction checkEventsHeaders(\n headers: Headers,\n): WebhookValidationMissingHeaders | WebhookValidationValid {\n const headerNames = WEBHOOK_HEADER_NAMES[WebhookType.Events];\n const missingHeaders: string[] = [];\n\n const hmac = getRequiredHeader(headers, headerNames.hmac, missingHeaders);\n const topic = getRequiredHeader(headers, headerNames.topic, missingHeaders);\n const domain = getRequiredHeader(headers, headerNames.domain, missingHeaders);\n const apiVersion = getRequiredHeader(\n headers,\n headerNames.apiVersion,\n missingHeaders,\n );\n const webhookId = getRequiredHeader(\n headers,\n headerNames.webhookId,\n missingHeaders,\n );\n const eventId = getRequiredHeader(\n headers,\n headerNames.eventId,\n missingHeaders,\n );\n\n if (missingHeaders.length) {\n return {\n valid: false,\n reason: WebhookValidationErrorReason.MissingHeaders,\n missingHeaders,\n };\n }\n\n const fields: EventsWebhookFields = {\n webhookType: WebhookType.Events,\n hmac: hmac!,\n topic: topicForStorage(topic!),\n domain: domain!,\n apiVersion: apiVersion!,\n webhookId: webhookId!,\n eventId: eventId!,\n };\n\n const handle = getHeader(headers, headerNames.handle);\n if (handle) fields.handle = handle;\n\n const action = getHeader(headers, headerNames.action);\n if (action) fields.action = action;\n\n const resourceId = getHeader(headers, headerNames.resourceId);\n if (resourceId) fields.resourceId = resourceId;\n\n const triggeredAt = getHeader(headers, headerNames.triggeredAt);\n if (triggeredAt) fields.triggeredAt = triggeredAt;\n\n return {valid: true, ...fields};\n}\n"],"names":[],"mappings":";;;;;;;;AAyBA,SAAS,iBAAiB,CAAC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CAC/B,OAAO,EACP,WAAW,CAAC,OAAO,EACnB,cAAc,CACf;AAED,IAAA,IAAI,cAAc,CAAC,MAAM,EAAE;QACzB,OAAO;AACL,YAAA,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,4BAA4B,CAAC,cAAc;YACnD,cAAc;SACf;IACH;AAEA,IAAA,MAAM,MAAM,GAAwB;QAClC,WAAW,EAAE,WAAW,CAAC,MAAM;AAC/B,QAAA,IAAI,EAAE,IAAK;AACX,QAAA,KAAK,EAAE,eAAe,CAAC,KAAM,CAAC;AAC9B,QAAA,MAAM,EAAE,MAAO;AACf,QAAA,UAAU,EAAE,UAAW;AACvB,QAAA,SAAS,EAAE,SAAU;AACrB,QAAA,OAAO,EAAE,OAAQ;KAClB;IAED,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC;AACrD,IAAA,IAAI,MAAM;AAAE,QAAA,MAAM,CAAC,MAAM,GAAG,MAAM;IAElC,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC;AACrD,IAAA,IAAI,MAAM;AAAE,QAAA,MAAM,CAAC,MAAM,GAAG,MAAM;IAElC,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,UAAU,CAAC;AAC7D,IAAA,IAAI,UAAU;AAAE,QAAA,MAAM,CAAC,UAAU,GAAG,UAAU;IAE9C,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC;AAC/D,IAAA,IAAI,WAAW;AAAE,QAAA,MAAM,CAAC,WAAW,GAAG,WAAW;IAEjD,OAAO,EAAC,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,EAAC;AACjC;;;;"}
1
+ {"version":3,"file":"validate.mjs","sources":["../../../../../../lib/webhooks/validate.ts"],"sourcesContent":["import {logger} from '../logger';\nimport {validateHmacFromRequestFactory} from '../utils/hmac-validator';\nimport {HmacValidationType, ValidationErrorReason} from '../utils/types';\nimport {\n abstractConvertRequest,\n getHeader,\n Headers,\n NormalizedRequest,\n} from '../../runtime/http';\nimport {ConfigInterface} from '../base-types';\n\nimport {\n EventsWebhookFields,\n WEBHOOK_HEADER_NAMES,\n WebhooksWebhookFields,\n WebhookType,\n WebhookTypeValue,\n WebhookValidateParams,\n WebhookValidation,\n WebhookValidationErrorReason,\n WebhookValidationMissingHeaders,\n WebhookValidationValid,\n} from './types';\nimport {topicForStorage} from './registry';\n\nfunction detectWebhookType(headers: Headers): WebhookTypeValue {\n const eventsHmac = getHeader(\n headers,\n WEBHOOK_HEADER_NAMES[WebhookType.Events].hmac,\n );\n if (eventsHmac) {\n return WebhookType.Events;\n }\n\n const webhooksHmac = getHeader(\n headers,\n WEBHOOK_HEADER_NAMES[WebhookType.Webhooks].hmac,\n );\n if (webhooksHmac) {\n return WebhookType.Webhooks;\n }\n\n return WebhookType.Webhooks;\n}\n\nexport function validateFactory(config: ConfigInterface) {\n return async function validate({\n rawBody,\n ...adapterArgs\n }: WebhookValidateParams): Promise<WebhookValidation> {\n const request: NormalizedRequest =\n await abstractConvertRequest(adapterArgs);\n\n const webhookType = detectWebhookType(request.headers);\n\n const validHmacResult = await validateHmacFromRequestFactory(config)({\n type: HmacValidationType.Webhook,\n rawBody,\n webhookType,\n ...adapterArgs,\n });\n\n if (!validHmacResult.valid) {\n if (validHmacResult.reason === ValidationErrorReason.InvalidHmac) {\n const log = logger(config);\n await log.debug(\n \"Webhook HMAC validation failed. Please note that events manually triggered from a store's Notifications settings will fail this validation. To test this, please use the CLI or trigger the actual event in a development store.\",\n );\n }\n return validHmacResult;\n }\n\n return checkWebhookHeaders(request.headers, webhookType);\n };\n}\n\nfunction getRequiredHeader(\n headers: Headers,\n headerName: string,\n missingHeaders: string[],\n): string | undefined {\n const value = getHeader(headers, headerName);\n if (!value) {\n missingHeaders.push(headerName);\n }\n return value;\n}\n\nfunction checkWebhookHeaders(\n headers: Headers,\n webhookType: WebhookTypeValue,\n): WebhookValidationMissingHeaders | WebhookValidationValid {\n if (webhookType === WebhookType.Webhooks) {\n return checkWebhooksHeaders(headers);\n }\n return checkEventsHeaders(headers);\n}\n\nfunction checkWebhooksHeaders(\n headers: Headers,\n): WebhookValidationMissingHeaders | WebhookValidationValid {\n const headerNames = WEBHOOK_HEADER_NAMES[WebhookType.Webhooks];\n const missingHeaders: string[] = [];\n\n const hmac = getRequiredHeader(headers, headerNames.hmac, missingHeaders);\n const topic = getRequiredHeader(headers, headerNames.topic, missingHeaders);\n const domain = getRequiredHeader(headers, headerNames.domain, missingHeaders);\n const apiVersion = getRequiredHeader(\n headers,\n headerNames.apiVersion,\n missingHeaders,\n );\n const webhookId = getRequiredHeader(\n headers,\n headerNames.webhookId,\n missingHeaders,\n );\n\n if (missingHeaders.length) {\n return {\n valid: false,\n reason: WebhookValidationErrorReason.MissingHeaders,\n missingHeaders,\n };\n }\n\n const fields: WebhooksWebhookFields = {\n webhookType: WebhookType.Webhooks,\n hmac: hmac!,\n topic: topicForStorage(topic!),\n domain: domain!,\n apiVersion: apiVersion!,\n webhookId: webhookId!,\n };\n\n const name = getHeader(headers, headerNames.name);\n if (name) fields.name = name;\n\n const triggeredAt = getHeader(headers, headerNames.triggeredAt);\n if (triggeredAt) fields.triggeredAt = triggeredAt;\n\n const eventId = getHeader(headers, headerNames.eventId);\n if (eventId) fields.eventId = eventId;\n\n return {valid: true, ...fields};\n}\n\nfunction checkEventsHeaders(\n headers: Headers,\n): WebhookValidationMissingHeaders | WebhookValidationValid {\n const headerNames = WEBHOOK_HEADER_NAMES[WebhookType.Events];\n const missingHeaders: string[] = [];\n\n const hmac = getRequiredHeader(headers, headerNames.hmac, missingHeaders);\n const topic = getRequiredHeader(headers, headerNames.topic, missingHeaders);\n const domain = getRequiredHeader(headers, headerNames.domain, missingHeaders);\n const apiVersion = getRequiredHeader(\n headers,\n headerNames.apiVersion,\n missingHeaders,\n );\n const webhookId = getRequiredHeader(\n headers,\n headerNames.webhookId,\n missingHeaders,\n );\n\n if (missingHeaders.length) {\n return {\n valid: false,\n reason: WebhookValidationErrorReason.MissingHeaders,\n missingHeaders,\n };\n }\n\n const fields: EventsWebhookFields = {\n webhookType: WebhookType.Events,\n hmac: hmac!,\n topic: topicForStorage(topic!),\n domain: domain!,\n apiVersion: apiVersion!,\n webhookId: webhookId!,\n };\n\n const handle = getHeader(headers, headerNames.handle);\n if (handle) fields.handle = handle;\n\n const action = getHeader(headers, headerNames.action);\n if (action) fields.action = action;\n\n const triggeredAt = getHeader(headers, headerNames.triggeredAt);\n if (triggeredAt) fields.triggeredAt = triggeredAt;\n\n return {valid: true, ...fields};\n}\n"],"names":[],"mappings":";;;;;;;;AAyBA,SAAS,iBAAiB,CAAC,OAAgB,EAAA;AACzC,IAAA,MAAM,UAAU,GAAG,SAAS,CAC1B,OAAO,EACP,oBAAoB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,CAC9C;IACD,IAAI,UAAU,EAAE;QACd,OAAO,WAAW,CAAC,MAAM;IAC3B;AAEA,IAAA,MAAM,YAAY,GAAG,SAAS,CAC5B,OAAO,EACP,oBAAoB,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,IAAI,CAChD;IACD,IAAI,YAAY,EAAE;QAChB,OAAO,WAAW,CAAC,QAAQ;IAC7B;IAEA,OAAO,WAAW,CAAC,QAAQ;AAC7B;AAEM,SAAU,eAAe,CAAC,MAAuB,EAAA;IACrD,OAAO,eAAe,QAAQ,CAAC,EAC7B,OAAO,EACP,GAAG,WAAW,EACQ,EAAA;AACtB,QAAA,MAAM,OAAO,GACX,MAAM,sBAAsB,CAAC,WAAW,CAAC;QAE3C,MAAM,WAAW,GAAG,iBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC;AAEtD,QAAA,MAAM,eAAe,GAAG,MAAM,8BAA8B,CAAC,MAAM,CAAC,CAAC;YACnE,IAAI,EAAE,kBAAkB,CAAC,OAAO;YAChC,OAAO;YACP,WAAW;AACX,YAA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