@shopify/shopify-api 3.0.1 → 3.1.3

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 (71) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/dist/__tests__/fake-resource-with-custom-prefix.d.ts.map +1 -1
  3. package/dist/__tests__/fake-resource-with-custom-prefix.js +7 -5
  4. package/dist/__tests__/fake-resource.d.ts.map +1 -1
  5. package/dist/__tests__/fake-resource.js +15 -13
  6. package/dist/auth/oauth/oauth.d.ts.map +1 -1
  7. package/dist/auth/oauth/oauth.js +11 -11
  8. package/dist/auth/scopes/index.js +5 -5
  9. package/dist/auth/session/index.d.ts +11 -1
  10. package/dist/auth/session/index.d.ts.map +1 -1
  11. package/dist/auth/session/index.js +16 -1
  12. package/dist/auth/session/session-utils.d.ts +8 -0
  13. package/dist/auth/session/session-utils.d.ts.map +1 -0
  14. package/dist/auth/session/session-utils.js +116 -0
  15. package/dist/auth/session/storage/__tests__/battery-of-tests.d.ts +3 -0
  16. package/dist/auth/session/storage/__tests__/battery-of-tests.d.ts.map +1 -0
  17. package/dist/auth/session/storage/__tests__/battery-of-tests.js +191 -0
  18. package/dist/auth/session/storage/__tests__/utils.d.ts +10 -0
  19. package/dist/auth/session/storage/__tests__/utils.d.ts.map +1 -0
  20. package/dist/auth/session/storage/__tests__/utils.js +87 -0
  21. package/dist/auth/session/storage/custom.js +4 -4
  22. package/dist/auth/session/storage/mongodb.d.ts +23 -0
  23. package/dist/auth/session/storage/mongodb.d.ts.map +1 -0
  24. package/dist/auth/session/storage/mongodb.js +150 -0
  25. package/dist/auth/session/storage/mysql.d.ts +22 -0
  26. package/dist/auth/session/storage/mysql.d.ts.map +1 -0
  27. package/dist/auth/session/storage/mysql.js +154 -0
  28. package/dist/auth/session/storage/postgresql.d.ts +24 -0
  29. package/dist/auth/session/storage/postgresql.d.ts.map +1 -0
  30. package/dist/auth/session/storage/postgresql.js +172 -0
  31. package/dist/auth/session/storage/redis.d.ts +20 -0
  32. package/dist/auth/session/storage/redis.d.ts.map +1 -0
  33. package/dist/auth/session/storage/redis.js +105 -0
  34. package/dist/auth/session/storage/sqlite.d.ts +19 -0
  35. package/dist/auth/session/storage/sqlite.d.ts.map +1 -0
  36. package/dist/auth/session/storage/sqlite.js +128 -0
  37. package/dist/base-rest-resource.d.ts +2 -1
  38. package/dist/base-rest-resource.d.ts.map +1 -1
  39. package/dist/base-rest-resource.js +29 -19
  40. package/dist/base-types.d.ts +1 -0
  41. package/dist/base-types.d.ts.map +1 -1
  42. package/dist/clients/graphql/graphql_client.js +1 -1
  43. package/dist/clients/http_client/http_client.d.ts +1 -2
  44. package/dist/clients/http_client/http_client.d.ts.map +1 -1
  45. package/dist/clients/http_client/http_client.js +100 -99
  46. package/dist/clients/rest/rest_client.js +5 -3
  47. package/dist/context.d.ts +1 -0
  48. package/dist/context.d.ts.map +1 -1
  49. package/dist/context.js +13 -5
  50. package/dist/error.js +4 -3
  51. package/dist/index.d.ts +5 -0
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/rest-resources/2021-07/index.js +2 -0
  54. package/dist/rest-resources/2021-10/index.js +2 -0
  55. package/dist/rest-resources/2022-01/index.js +2 -0
  56. package/dist/rest-resources/2022-04/index.js +2 -0
  57. package/dist/utils/decode-session-token.js +1 -1
  58. package/dist/utils/graphql_proxy.js +1 -1
  59. package/dist/utils/hmac-validator.js +2 -5
  60. package/dist/utils/processed-query.js +3 -3
  61. package/dist/utils/safe-compare.d.ts.map +1 -1
  62. package/dist/utils/safe-compare.js +17 -15
  63. package/dist/utils/setup-jest.d.ts.map +1 -1
  64. package/dist/utils/setup-jest.js +4 -3
  65. package/dist/utils/with-session.js +3 -3
  66. package/dist/version.d.ts +1 -1
  67. package/dist/version.js +1 -1
  68. package/dist/webhooks/registry.d.ts +2 -1
  69. package/dist/webhooks/registry.d.ts.map +1 -1
  70. package/dist/webhooks/registry.js +39 -13
  71. package/package.json +12 -4
@@ -19,10 +19,7 @@ function stringifyQuery(query) {
19
19
  exports.stringifyQuery = stringifyQuery;
20
20
  function generateLocalHmac(_a) {
21
21
  var code = _a.code, timestamp = _a.timestamp, state = _a.state, shop = _a.shop, host = _a.host;
22
- var queryString = stringifyQuery(tslib_1.__assign({ code: code,
23
- timestamp: timestamp,
24
- state: state,
25
- shop: shop }, (host && { host: host })));
22
+ var queryString = stringifyQuery(tslib_1.__assign({ code: code, timestamp: timestamp, state: state, shop: shop }, (host && { host: host })));
26
23
  return crypto_1.default
27
24
  .createHmac('sha256', context_1.Context.API_SECRET_KEY)
28
25
  .update(queryString)
@@ -40,6 +37,6 @@ function validateHmac(query) {
40
37
  }
41
38
  var hmac = query.hmac;
42
39
  var localHmac = generateLocalHmac(query);
43
- return safe_compare_1.default(hmac, localHmac);
40
+ return (0, safe_compare_1.default)(hmac, localHmac);
44
41
  }
45
42
  exports.default = validateHmac;
@@ -31,20 +31,20 @@ var ProcessedQuery = /** @class */ (function () {
31
31
  }
32
32
  };
33
33
  ProcessedQuery.prototype.putArray = function (key, value) {
34
- this.processedQuery[key + "[]"] = value;
34
+ this.processedQuery["".concat(key, "[]")] = value;
35
35
  };
36
36
  ProcessedQuery.prototype.putObject = function (key, value) {
37
37
  var _this = this;
38
38
  Object.entries(value).forEach(function (_a) {
39
39
  var _b = tslib_1.__read(_a, 2), entry = _b[0], entryValue = _b[1];
40
- _this.processedQuery[key + "[" + entry + "]"] = entryValue;
40
+ _this.processedQuery["".concat(key, "[").concat(entry, "]")] = entryValue;
41
41
  });
42
42
  };
43
43
  ProcessedQuery.prototype.putSimple = function (key, value) {
44
44
  this.processedQuery[key] = value;
45
45
  };
46
46
  ProcessedQuery.prototype.stringify = function () {
47
- return "?" + querystring_1.default.stringify(this.processedQuery);
47
+ return "?".concat(querystring_1.default.stringify(this.processedQuery));
48
48
  };
49
49
  return ProcessedQuery;
50
50
  }());
@@ -1 +1 @@
1
- {"version":3,"file":"safe-compare.d.ts","sourceRoot":"","sources":["../../src/utils/safe-compare.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,IAAI,EAAE,MAAM,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,EAC5D,IAAI,EAAE,MAAM,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAC3D,OAAO,CAsBT"}
1
+ {"version":3,"file":"safe-compare.d.ts","sourceRoot":"","sources":["../../src/utils/safe-compare.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,IAAI,EAAE,MAAM,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,EAC5D,IAAI,EAAE,MAAM,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAC3D,OAAO,CAyBT"}
@@ -10,23 +10,25 @@ var ShopifyErrors = tslib_1.__importStar(require("../error"));
10
10
  * @param strB any string, array of strings, or object with string values
11
11
  */
12
12
  function safeCompare(strA, strB) {
13
- if (typeof strA === typeof strB) {
14
- var buffA = void 0;
15
- var buffB = void 0;
16
- if (typeof strA === 'object' && typeof strB === 'object') {
17
- buffA = Buffer.from(JSON.stringify(strA));
18
- buffB = Buffer.from(JSON.stringify(strB));
19
- }
20
- else {
21
- buffA = Buffer.from(strA);
22
- buffB = Buffer.from(strB);
23
- }
24
- if (buffA.length === buffB.length) {
25
- return crypto_1.default.timingSafeEqual(buffA, buffB);
26
- }
13
+ var buffA;
14
+ var buffB;
15
+ if (typeof strA !== typeof strB) {
16
+ throw new ShopifyErrors.SafeCompareError("Mismatched data types provided: ".concat(typeof strA, " and ").concat(typeof strB));
17
+ }
18
+ if (typeof strA === 'object') {
19
+ buffA = Buffer.from(JSON.stringify(strA));
27
20
  }
28
21
  else {
29
- throw new ShopifyErrors.SafeCompareError("Mismatched data types provided: " + typeof strA + " and " + typeof strB);
22
+ buffA = Buffer.from(strA);
23
+ }
24
+ if (typeof strB === 'object') {
25
+ buffB = Buffer.from(JSON.stringify(strB));
26
+ }
27
+ else {
28
+ buffB = Buffer.from(strB);
29
+ }
30
+ if (buffA.length === buffB.length) {
31
+ return crypto_1.default.timingSafeEqual(buffA, buffB);
30
32
  }
31
33
  return false;
32
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setup-jest.d.ts","sourceRoot":"","sources":["../../src/utils/setup-jest.ts"],"names":[],"mappings":"AAqCA,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,IAAI,CAAC;QAEb,UAAU,QAAQ,CAAC,CAAC;YAClB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC;YAC7D,sBAAsB,IAAI,CAAC,CAAC;SAC7B;KAEF;CACF"}
1
+ {"version":3,"file":"setup-jest.d.ts","sourceRoot":"","sources":["../../src/utils/setup-jest.ts"],"names":[],"mappings":"AAsCA,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,IAAI,CAAC;QAEb,UAAU,QAAQ,CAAC,CAAC;YAClB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC;YAC7D,sBAAsB,IAAI,CAAC,CAAC;SAC7B;KAEF;CACF"}
@@ -14,6 +14,7 @@ beforeEach(function () {
14
14
  API_SECRET_KEY: 'test_secret_key',
15
15
  SCOPES: ['test_scope'],
16
16
  HOST_NAME: 'test_host_name',
17
+ HOST_SCHEME: 'https',
17
18
  API_VERSION: base_types_1.ApiVersion.Unstable,
18
19
  IS_EMBEDDED_APP: false,
19
20
  IS_PRIVATE_APP: false,
@@ -36,7 +37,7 @@ expect.extend({
36
37
  Math.abs(received - compareDate) <= seconds * 1000) {
37
38
  return {
38
39
  message: function () {
39
- return "expected " + received + " not to be within " + seconds + " seconds of " + compareDate;
40
+ return "expected ".concat(received, " not to be within ").concat(seconds, " seconds of ").concat(compareDate);
40
41
  },
41
42
  pass: true,
42
43
  };
@@ -44,7 +45,7 @@ expect.extend({
44
45
  else {
45
46
  return {
46
47
  message: function () {
47
- return "expected " + received + " to be within " + seconds + " seconds of " + compareDate;
48
+ return "expected ".concat(received, " to be within ").concat(seconds, " seconds of ").concat(compareDate);
48
49
  },
49
50
  pass: false,
50
51
  };
@@ -61,7 +62,7 @@ expect.extend({
61
62
  if (bodyObject && mockCall[1]) {
62
63
  mockCall[1].body = JSON.parse(mockCall[1].body);
63
64
  }
64
- expect(mockCall[0]).toEqual("https://" + domain + path + (query ? "?" + query.replace(/\+/g, '%20') : ''));
65
+ expect(mockCall[0]).toEqual("https://".concat(domain).concat(path).concat(query ? "?".concat(query.replace(/\+/g, '%20')) : ''));
65
66
  expect(mockCall[1]).toMatchObject({ method: method, headers: headers, body: data });
66
67
  }
67
68
  return {
@@ -19,7 +19,7 @@ function withSession(_a) {
19
19
  if (!req || !res) {
20
20
  throw new ShopifyErrors.MissingRequiredArgument('Please pass in both the "request" and "response" objects.');
21
21
  }
22
- return [4 /*yield*/, load_current_session_1.default(req, res)];
22
+ return [4 /*yield*/, (0, load_current_session_1.default)(req, res)];
23
23
  case 1:
24
24
  session = _b.sent();
25
25
  return [3 /*break*/, 4];
@@ -27,7 +27,7 @@ function withSession(_a) {
27
27
  if (!shop) {
28
28
  throw new ShopifyErrors.MissingRequiredArgument('Please pass in a value for "shop"');
29
29
  }
30
- return [4 /*yield*/, load_offline_session_1.default(shop)];
30
+ return [4 /*yield*/, (0, load_offline_session_1.default)(shop)];
31
31
  case 3:
32
32
  session = _b.sent();
33
33
  _b.label = 4;
@@ -52,7 +52,7 @@ function withSession(_a) {
52
52
  session: session,
53
53
  }];
54
54
  default:
55
- throw new ShopifyErrors.UnsupportedClientType("\"" + clientType + "\" is an unsupported clientType. Please use \"rest\" or \"graphql\".");
55
+ throw new ShopifyErrors.UnsupportedClientType("\"".concat(clientType, "\" is an unsupported clientType. Please use \"rest\" or \"graphql\"."));
56
56
  }
57
57
  return [2 /*return*/];
58
58
  }
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const SHOPIFY_API_LIBRARY_VERSION = "3.0.1";
1
+ export declare const SHOPIFY_API_LIBRARY_VERSION = "3.1.3";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SHOPIFY_API_LIBRARY_VERSION = void 0;
4
- exports.SHOPIFY_API_LIBRARY_VERSION = '3.0.1';
4
+ exports.SHOPIFY_API_LIBRARY_VERSION = '3.1.3';
@@ -59,6 +59,7 @@ interface RegistryInterface {
59
59
  }
60
60
  declare function buildCheckQuery(topic: string): string;
61
61
  declare function buildQuery(topic: string, address: string, deliveryMethod?: DeliveryMethod, webhookId?: string): string;
62
+ declare const gdprTopics: string[];
62
63
  declare const WebhooksRegistry: RegistryInterface;
63
- export { WebhooksRegistry, RegistryInterface, buildCheckQuery, buildQuery };
64
+ export { WebhooksRegistry, RegistryInterface, buildCheckQuery, buildQuery, gdprTopics, };
64
65
  //# sourceMappingURL=registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/webhooks/registry.ts"],"names":[],"mappings":";AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAUxB,OAAO,EACL,cAAc,EACd,eAAe,EACf,cAAc,EACd,oBAAoB,EAEpB,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB,UAAU,gBAAgB;IACxB,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB,CAAC;CACvC;AAED,UAAU,iBAAiB;IACzB,eAAe,EAA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0PvB,CAAC;AAEF,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,UAAU,EACV,UAAU,GACX,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildQuery = exports.buildCheckQuery = exports.WebhooksRegistry = void 0;
3
+ exports.gdprTopics = exports.buildQuery = exports.buildCheckQuery = exports.WebhooksRegistry = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var crypto_1 = require("crypto");
6
6
  var network_1 = require("@shopify/network");
@@ -34,7 +34,7 @@ function validateDeliveryMethod(_deliveryMethod) {
34
34
  return true;
35
35
  }
36
36
  function buildCheckQuery(topic) {
37
- return "{\n webhookSubscriptions(first: 1, topics: " + topic + ") {\n edges {\n node {\n id\n endpoint {\n __typename\n ... on WebhookHttpEndpoint {\n callbackUrl\n }\n ... on WebhookEventBridgeEndpoint {\n arn\n }\n ... on WebhookPubSubEndpoint {\n pubSubProject\n pubSubTopic\n }\n }\n }\n }\n }\n }";
37
+ return "{\n webhookSubscriptions(first: 1, topics: ".concat(topic, ") {\n edges {\n node {\n id\n endpoint {\n __typename\n ... on WebhookHttpEndpoint {\n callbackUrl\n }\n ... on WebhookEventBridgeEndpoint {\n arn\n }\n ... on WebhookPubSubEndpoint {\n pubSubProject\n pubSubTopic\n }\n }\n }\n }\n }\n }");
38
38
  }
39
39
  exports.buildCheckQuery = buildCheckQuery;
40
40
  function buildQuery(topic, address, deliveryMethod, webhookId) {
@@ -43,10 +43,10 @@ function buildQuery(topic, address, deliveryMethod, webhookId) {
43
43
  validateDeliveryMethod(deliveryMethod);
44
44
  var identifier;
45
45
  if (webhookId) {
46
- identifier = "id: \"" + webhookId + "\"";
46
+ identifier = "id: \"".concat(webhookId, "\"");
47
47
  }
48
48
  else {
49
- identifier = "topic: " + topic;
49
+ identifier = "topic: ".concat(topic);
50
50
  }
51
51
  var mutationName;
52
52
  var webhookSubscriptionArgs;
@@ -57,13 +57,13 @@ function buildQuery(topic, address, deliveryMethod, webhookId) {
57
57
  mutationName = webhookId
58
58
  ? 'webhookSubscriptionUpdate'
59
59
  : 'webhookSubscriptionCreate';
60
- webhookSubscriptionArgs = "{callbackUrl: \"" + address + "\"}";
60
+ webhookSubscriptionArgs = "{callbackUrl: \"".concat(address, "\"}");
61
61
  break;
62
62
  case types_1.DeliveryMethod.EventBridge:
63
63
  mutationName = webhookId
64
64
  ? 'eventBridgeWebhookSubscriptionUpdate'
65
65
  : 'eventBridgeWebhookSubscriptionCreate';
66
- webhookSubscriptionArgs = "{arn: \"" + address + "\"}";
66
+ webhookSubscriptionArgs = "{arn: \"".concat(address, "\"}");
67
67
  break;
68
68
  case types_1.DeliveryMethod.PubSub:
69
69
  mutationName = webhookId
@@ -72,12 +72,18 @@ function buildQuery(topic, address, deliveryMethod, webhookId) {
72
72
  _a = tslib_1.__read(address
73
73
  .replace(/^pubsub:\/\//, '')
74
74
  .split(':'), 2), pubSubProject = _a[0], pubSubTopic = _a[1];
75
- webhookSubscriptionArgs = "{pubSubProject: \"" + pubSubProject + "\",\n pubSubTopic: \"" + pubSubTopic + "\"}";
75
+ webhookSubscriptionArgs = "{pubSubProject: \"".concat(pubSubProject, "\",\n pubSubTopic: \"").concat(pubSubTopic, "\"}");
76
76
  break;
77
77
  }
78
- return "\n mutation webhookSubscription {\n " + mutationName + "(" + identifier + ", webhookSubscription: " + webhookSubscriptionArgs + ") {\n userErrors {\n field\n message\n }\n webhookSubscription {\n id\n }\n }\n }\n ";
78
+ return "\n mutation webhookSubscription {\n ".concat(mutationName, "(").concat(identifier, ", webhookSubscription: ").concat(webhookSubscriptionArgs, ") {\n userErrors {\n field\n message\n }\n webhookSubscription {\n id\n }\n }\n }\n ");
79
79
  }
80
80
  exports.buildQuery = buildQuery;
81
+ var gdprTopics = [
82
+ 'CUSTOMERS_DATA_REQUEST',
83
+ 'CUSTOMERS_REDACT',
84
+ 'SHOP_REDACT',
85
+ ];
86
+ exports.gdprTopics = gdprTopics;
81
87
  var WebhooksRegistry = {
82
88
  webhookRegistry: {},
83
89
  addHandler: function (topic, _a) {
@@ -106,10 +112,23 @@ var WebhooksRegistry = {
106
112
  switch (_c.label) {
107
113
  case 0:
108
114
  registerReturn = {};
115
+ if (gdprTopics.includes(topic)) {
116
+ registerReturn[topic] = {
117
+ success: false,
118
+ result: {
119
+ errors: [
120
+ {
121
+ message: "GDPR topic '".concat(topic, "' cannot be registered here. Please set the appropriate webhook endpoint in the 'GDPR mandatory webhooks' section of 'App setup' in the Partners Dashboard"),
122
+ },
123
+ ],
124
+ },
125
+ };
126
+ return [2 /*return*/, registerReturn];
127
+ }
109
128
  validateDeliveryMethod(deliveryMethod);
110
129
  client = new graphql_client_1.GraphqlClient(shop, accessToken);
111
130
  address = deliveryMethod === types_1.DeliveryMethod.Http
112
- ? "https://" + context_1.Context.HOST_NAME + path
131
+ ? "".concat(context_1.Context.HOST_SCHEME, "://").concat(context_1.Context.HOST_NAME).concat(path)
113
132
  : path;
114
133
  return [4 /*yield*/, client.query({
115
134
  data: buildCheckQuery(topic),
@@ -117,6 +136,13 @@ var WebhooksRegistry = {
117
136
  case 1:
118
137
  checkResult = (_c.sent());
119
138
  mustRegister = true;
139
+ if ('errors' in checkResult.body) {
140
+ registerReturn[topic] = {
141
+ success: false,
142
+ result: checkResult.body,
143
+ };
144
+ return [2 /*return*/, registerReturn];
145
+ }
120
146
  if (checkResult.body.data.webhookSubscriptions.edges.length) {
121
147
  node = checkResult.body.data.webhookSubscriptions.edges[0].node;
122
148
  endpointAddress = '';
@@ -252,10 +278,10 @@ var WebhooksRegistry = {
252
278
  if (missingHeaders.length) {
253
279
  response.writeHead(network_1.StatusCode.BadRequest);
254
280
  response.end();
255
- return [2 /*return*/, reject(new ShopifyErrors.InvalidWebhookError("Missing one or more of the required HTTP headers to process webhooks: [" + missingHeaders.join(', ') + "]"))];
281
+ return [2 /*return*/, reject(new ShopifyErrors.InvalidWebhookError("Missing one or more of the required HTTP headers to process webhooks: [".concat(missingHeaders.join(', '), "]")))];
256
282
  }
257
283
  headers = {};
258
- generatedHash = crypto_1.createHmac('sha256', context_1.Context.API_SECRET_KEY)
284
+ generatedHash = (0, crypto_1.createHmac)('sha256', context_1.Context.API_SECRET_KEY)
259
285
  .update(reqBody, 'utf8')
260
286
  .digest('base64');
261
287
  if (!utils_1.default.safeCompare(generatedHash, hmac)) return [3 /*break*/, 7];
@@ -280,12 +306,12 @@ var WebhooksRegistry = {
280
306
  case 4: return [3 /*break*/, 6];
281
307
  case 5:
282
308
  statusCode = network_1.StatusCode.Forbidden;
283
- responseError = new ShopifyErrors.InvalidWebhookError("No webhook is registered for topic " + topic);
309
+ responseError = new ShopifyErrors.InvalidWebhookError("No webhook is registered for topic ".concat(topic));
284
310
  _a.label = 6;
285
311
  case 6: return [3 /*break*/, 8];
286
312
  case 7:
287
313
  statusCode = network_1.StatusCode.Forbidden;
288
- responseError = new ShopifyErrors.InvalidWebhookError("Could not validate request for topic " + topic);
314
+ responseError = new ShopifyErrors.InvalidWebhookError("Could not validate request for topic ".concat(topic));
289
315
  _a.label = 8;
290
316
  case 8:
291
317
  response.writeHead(statusCode, headers);
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@shopify/shopify-api",
3
- "version": "3.0.1",
3
+ "version": "3.1.3",
4
4
  "description": "Shopify API Library for Node - accelerate development with support for authentication, graphql proxy, webhooks",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "prettier": "@shopify/prettier-config",
8
8
  "scripts": {
9
- "test": "jest --testPathIgnorePatterns=src/rest-resources/__tests__",
9
+ "test": "jest --testPathIgnorePatterns=src/rest-resources/__tests__ --testPathIgnorePatterns=src/auth/session/storage",
10
+ "test_sessionstorage": "jest src/auth/session/storage",
10
11
  "test_rest_resources": "ls src/rest-resources/__tests__ | xargs -I \"{}\" sh -c 'yarn jest --no-coverage --testPathPattern=\\\"{}\\\" || exit 255'",
11
12
  "build": "tsc",
12
13
  "lint": "eslint '**/*.{ts,tsx}' --max-warnings 0",
@@ -49,7 +50,12 @@
49
50
  "@types/supertest": "^2.0.10",
50
51
  "cookies": "^0.8.0",
51
52
  "jsonwebtoken": "^8.5.1",
53
+ "mongodb": "^4.5.0",
54
+ "mysql2": "^2.3.3",
52
55
  "node-fetch": "^2.6.1",
56
+ "pg": "^8.7.3",
57
+ "redis": "^4.0.6",
58
+ "sqlite3": "^5.0.8",
53
59
  "tslib": "^2.0.3",
54
60
  "uuid": "^8.3.1"
55
61
  },
@@ -58,7 +64,9 @@
58
64
  "@shopify/prettier-config": "^1.1.2",
59
65
  "@types/cookies": "^0.7.5",
60
66
  "@types/jest": "^26.0.15",
61
- "@types/node": "^14.14.1",
67
+ "@types/node": "^14.18.12",
68
+ "@types/pg": "^8.6.5",
69
+ "@types/sqlite3": "^3.1.8",
62
70
  "@types/uuid": "^8.3.0",
63
71
  "eslint": "^7.30.0",
64
72
  "eslint-plugin-prettier": "^4.0.0",
@@ -69,7 +77,7 @@
69
77
  "rimraf": "^3.0.2",
70
78
  "supertest": "^6.1.3",
71
79
  "ts-jest": "^27.1.1",
72
- "typescript": "^3.8.0"
80
+ "typescript": "^4.6.3"
73
81
  },
74
82
  "files": [
75
83
  "dist/*",