@shopify/shopify-api 1.4.0 → 2.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 (60) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +3 -0
  3. package/dist/auth/oauth/oauth.d.ts +4 -2
  4. package/dist/auth/oauth/oauth.d.ts.map +1 -1
  5. package/dist/auth/oauth/oauth.js +34 -38
  6. package/dist/auth/oauth/types.d.ts +1 -0
  7. package/dist/auth/oauth/types.d.ts.map +1 -1
  8. package/dist/auth/scopes/index.d.ts +3 -3
  9. package/dist/auth/scopes/index.d.ts.map +1 -1
  10. package/dist/auth/scopes/index.js +5 -3
  11. package/dist/auth/session/index.d.ts +1 -1
  12. package/dist/auth/session/index.d.ts.map +1 -1
  13. package/dist/auth/session/session.d.ts +4 -4
  14. package/dist/auth/session/session.d.ts.map +1 -1
  15. package/dist/auth/session/session.js +8 -6
  16. package/dist/auth/session/storage/custom.d.ts.map +1 -1
  17. package/dist/auth/session/storage/custom.js +1 -1
  18. package/dist/auth/session/storage/memory.d.ts.map +1 -1
  19. package/dist/auth/session/types.d.ts +2 -2
  20. package/dist/auth/session/types.d.ts.map +1 -1
  21. package/dist/base_types.d.ts +1 -0
  22. package/dist/base_types.d.ts.map +1 -1
  23. package/dist/base_types.js +1 -0
  24. package/dist/clients/graphql/graphql_client.d.ts.map +1 -1
  25. package/dist/clients/graphql/graphql_client.js +3 -1
  26. package/dist/clients/graphql/index.d.ts +1 -1
  27. package/dist/clients/graphql/index.d.ts.map +1 -1
  28. package/dist/clients/graphql/storefront_client.js +3 -1
  29. package/dist/clients/http_client/http_client.d.ts.map +1 -1
  30. package/dist/clients/http_client/http_client.js +25 -9
  31. package/dist/clients/http_client/types.d.ts.map +1 -1
  32. package/dist/clients/rest/rest_client.d.ts.map +1 -1
  33. package/dist/clients/rest/rest_client.js +6 -2
  34. package/dist/context.d.ts.map +1 -1
  35. package/dist/context.js +2 -1
  36. package/dist/error.d.ts.map +1 -1
  37. package/dist/index.d.ts +1 -1
  38. package/dist/utils/decode-session-token.d.ts +1 -1
  39. package/dist/utils/decode-session-token.d.ts.map +1 -1
  40. package/dist/utils/decode-session-token.js +5 -1
  41. package/dist/utils/delete-current-session.d.ts.map +1 -1
  42. package/dist/utils/delete-offline-session.d.ts.map +1 -1
  43. package/dist/utils/graphql_proxy.d.ts.map +1 -1
  44. package/dist/utils/hmac-validator.d.ts +1 -1
  45. package/dist/utils/hmac-validator.d.ts.map +1 -1
  46. package/dist/utils/hmac-validator.js +8 -4
  47. package/dist/utils/load-current-session.d.ts.map +1 -1
  48. package/dist/utils/load-offline-session.d.ts.map +1 -1
  49. package/dist/utils/load-offline-session.js +4 -1
  50. package/dist/utils/version-compatible.d.ts.map +1 -1
  51. package/dist/utils/version-compatible.js +5 -2
  52. package/dist/utils/with-session.d.ts.map +1 -1
  53. package/dist/version.d.ts +1 -1
  54. package/dist/version.js +1 -1
  55. package/dist/webhooks/registry.d.ts +37 -3
  56. package/dist/webhooks/registry.d.ts.map +1 -1
  57. package/dist/webhooks/registry.js +107 -24
  58. package/dist/webhooks/types.d.ts +9 -4
  59. package/dist/webhooks/types.d.ts.map +1 -1
  60. package/package.json +5 -2
@@ -24,7 +24,9 @@ var RestClient = /** @class */ (function (_super) {
24
24
  return tslib_1.__generator(this, function (_c) {
25
25
  switch (_c.label) {
26
26
  case 0:
27
- params.extraHeaders = tslib_1.__assign((_a = {}, _a[base_types_1.ShopifyHeader.AccessToken] = context_1.Context.IS_PRIVATE_APP ? context_1.Context.API_SECRET_KEY : this.accessToken, _a), params.extraHeaders);
27
+ params.extraHeaders = tslib_1.__assign((_a = {}, _a[base_types_1.ShopifyHeader.AccessToken] = context_1.Context.IS_PRIVATE_APP
28
+ ? context_1.Context.API_SECRET_KEY
29
+ : this.accessToken, _a), params.extraHeaders);
28
30
  params.path = this.getRestPath(params.path);
29
31
  return [4 /*yield*/, _super.prototype.request.call(this, params)];
30
32
  case 1:
@@ -32,7 +34,9 @@ var RestClient = /** @class */ (function (_super) {
32
34
  link = ret.headers.get('link');
33
35
  if (params.query && link !== undefined) {
34
36
  pageInfo = {
35
- limit: params.query.limit ? params.query.limit.toString() : RestClient.DEFAULT_LIMIT,
37
+ limit: params.query.limit
38
+ ? params.query.limit.toString()
39
+ : RestClient.DEFAULT_LIMIT,
36
40
  };
37
41
  if (link) {
38
42
  links = link.split(', ');
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,gCAAgC,CAAC;AAE9D,OAAO,EAAa,aAAa,EAAC,MAAM,cAAc,CAAC;AACvD,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC,UAAU,gBAAiB,SAAQ,aAAa;IAC9C,eAAe,EAAE,cAAc,CAAC;IAChC,MAAM,EAAE,UAAU,CAAC;IAEnB;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IAExC;;OAEG;IACH,oBAAoB,IAAI,IAAI,GAAG,KAAK,CAAC;IAErC;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;CAClD;AAED,QAAA,MAAM,OAAO,EAAE,gBA6Ed,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,gBAAgB,EAAC,CAAC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,gCAAgC,CAAC;AAE9D,OAAO,EAAa,aAAa,EAAC,MAAM,cAAc,CAAC;AACvD,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC,UAAU,gBAAiB,SAAQ,aAAa;IAC9C,eAAe,EAAE,cAAc,CAAC;IAChC,MAAM,EAAE,UAAU,CAAC;IAEnB;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IAExC;;OAEG;IACH,oBAAoB,IAAI,IAAI,GAAG,KAAK,CAAC;IAErC;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;CAClD;AAED,QAAA,MAAM,OAAO,EAAE,gBAgFd,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,gBAAgB,EAAC,CAAC"}
package/dist/context.js CHANGED
@@ -57,7 +57,8 @@ var Context = {
57
57
  this.LOG_FILE = params.LOG_FILE;
58
58
  }
59
59
  if (params.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN) {
60
- this.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN = params.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN;
60
+ this.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN =
61
+ params.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN;
61
62
  }
62
63
  },
63
64
  throwIfUninitialized: function () {
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,cAAM,YAAa,SAAQ,KAAK;gBAClB,GAAG,IAAI,EAAE,GAAG;CAIzB;AAED,cAAM,gBAAiB,SAAQ,YAAY;CAAG;AAC9C,cAAM,gBAAiB,SAAQ,YAAY;CAAG;AAC9C,cAAM,eAAgB,SAAQ,YAAY;CAAG;AAC7C,cAAM,oBAAqB,SAAQ,YAAY;CAAG;AAElD,cAAM,gBAAiB,SAAQ,YAAY;CAAG;AAC9C,cAAM,yBAA0B,SAAQ,YAAY;CAAG;AACvD,cAAM,eAAgB,SAAQ,YAAY;CAAG;AAE7C,cAAM,gBAAiB,SAAQ,YAAY;CAAG;AAC9C,cAAM,mBAAoB,SAAQ,YAAY;CAAG;AACjD,cAAM,iBAAkB,SAAQ,YAAY;IACN,QAAQ,CAAC,IAAI,EAAE,MAAM;IAAE,QAAQ,CAAC,UAAU,EAA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AC"}
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare const Shopify: {
5
5
  Auth: {
6
6
  SESSION_COOKIE_NAME: string;
7
7
  beginAuth(request: import("http").IncomingMessage, response: import("http").ServerResponse, shop: string, redirectPath: string, isOnline?: boolean): Promise<string>;
8
- validateAuthCallback(request: import("http").IncomingMessage, response: import("http").ServerResponse, query: import("./types").AuthQuery): Promise<void>;
8
+ validateAuthCallback(request: import("http").IncomingMessage, response: import("http").ServerResponse, query: import("./types").AuthQuery): Promise<import("./types").SessionInterface>;
9
9
  getCookieSessionId(request: import("http").IncomingMessage, response: import("http").ServerResponse): string | undefined;
10
10
  getJwtSessionId(shop: string, userId: string): string;
11
11
  getOfflineSessionId(shop: string): string;
@@ -16,5 +16,5 @@ interface JwtPayload {
16
16
  */
17
17
  declare function decodeSessionToken(token: string): JwtPayload;
18
18
  export default decodeSessionToken;
19
- export { decodeSessionToken, JwtPayload, };
19
+ export { decodeSessionToken, JwtPayload };
20
20
  //# sourceMappingURL=decode-session-token.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decode-session-token.d.ts","sourceRoot":"","sources":["../../src/utils/decode-session-token.ts"],"names":[],"mappings":"AAOA,UAAU,UAAU;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;GAIG;AACH,iBAAS,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAmBrD;AAED,eAAe,kBAAkB,CAAC;AAElC,OAAO,EACL,kBAAkB,EAClB,UAAU,GACX,CAAC"}
1
+ {"version":3,"file":"decode-session-token.d.ts","sourceRoot":"","sources":["../../src/utils/decode-session-token.ts"],"names":[],"mappings":"AASA,UAAU,UAAU;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;GAIG;AACH,iBAAS,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CA0BrD;AAED,eAAe,kBAAkB,CAAC;AAElC,OAAO,EAAC,kBAAkB,EAAE,UAAU,EAAC,CAAC"}
@@ -6,6 +6,7 @@ var jsonwebtoken_1 = tslib_1.__importDefault(require("jsonwebtoken"));
6
6
  var context_1 = require("../context");
7
7
  var ShopifyErrors = tslib_1.__importStar(require("../error"));
8
8
  var shop_validator_1 = tslib_1.__importDefault(require("./shop-validator"));
9
+ var JWT_PERMITTED_CLOCK_TOLERANCE = 5;
9
10
  /**
10
11
  * Decodes the given session token, and extracts the session information from it
11
12
  *
@@ -14,7 +15,10 @@ var shop_validator_1 = tslib_1.__importDefault(require("./shop-validator"));
14
15
  function decodeSessionToken(token) {
15
16
  var payload;
16
17
  try {
17
- payload = jsonwebtoken_1.default.verify(token, context_1.Context.API_SECRET_KEY, { algorithms: ['HS256'] });
18
+ payload = jsonwebtoken_1.default.verify(token, context_1.Context.API_SECRET_KEY, {
19
+ algorithms: ['HS256'],
20
+ clockTolerance: JWT_PERMITTED_CLOCK_TOLERANCE,
21
+ });
18
22
  }
19
23
  catch (error) {
20
24
  throw new ShopifyErrors.InvalidJwtError("Failed to parse session token '" + token + "': " + error.message);
@@ -1 +1 @@
1
- {"version":3,"file":"delete-current-session.d.ts","sourceRoot":"","sources":["../../src/utils/delete-current-session.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAMxB;;;;;;GAMG;AACH,wBAA8B,oBAAoB,CAChD,OAAO,EAAE,IAAI,CAAC,eAAe,EAC7B,QAAQ,EAAE,IAAI,CAAC,cAAc,EAC7B,QAAQ,UAAO,GACd,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,CAS1B"}
1
+ {"version":3,"file":"delete-current-session.d.ts","sourceRoot":"","sources":["../../src/utils/delete-current-session.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAMxB;;;;;;GAMG;AACH,wBAA8B,oBAAoB,CAChD,OAAO,EAAE,IAAI,CAAC,eAAe,EAC7B,QAAQ,EAAE,IAAI,CAAC,cAAc,EAC7B,QAAQ,UAAO,GACd,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,CAa1B"}
@@ -1 +1 @@
1
- {"version":3,"file":"delete-offline-session.d.ts","sourceRoot":"","sources":["../../src/utils/delete-offline-session.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAA8B,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMjF"}
1
+ {"version":3,"file":"delete-offline-session.d.ts","sourceRoot":"","sources":["../../src/utils/delete-offline-session.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAA8B,oBAAoB,CAChD,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,OAAO,CAAC,CAMlB"}
@@ -1 +1 @@
1
- {"version":3,"file":"graphql_proxy.d.ts","sourceRoot":"","sources":["../../src/utils/graphql_proxy.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAOxB,wBAA8B,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CA2DrH"}
1
+ {"version":3,"file":"graphql_proxy.d.ts","sourceRoot":"","sources":["../../src/utils/graphql_proxy.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAOxB,wBAA8B,YAAY,CACxC,OAAO,EAAE,IAAI,CAAC,eAAe,EAC7B,OAAO,EAAE,IAAI,CAAC,cAAc,GAC3B,OAAO,CAAC,IAAI,CAAC,CA+Df"}
@@ -1,6 +1,6 @@
1
1
  import { AuthQuery } from '../auth/oauth/types';
2
2
  export declare function stringifyQuery(query: AuthQuery): string;
3
- export declare function generateLocalHmac(query: AuthQuery): string;
3
+ export declare function generateLocalHmac({ code, timestamp, state, shop, host, }: AuthQuery): string;
4
4
  /**
5
5
  * Uses the received query to validate the contained hmac value against the rest of the query content.
6
6
  *
@@ -1 +1 @@
1
- {"version":3,"file":"hmac-validator.d.ts","sourceRoot":"","sources":["../../src/utils/hmac-validator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAM9C,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAQvD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAM1D;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAU9D"}
1
+ {"version":3,"file":"hmac-validator.d.ts","sourceRoot":"","sources":["../../src/utils/hmac-validator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAM9C,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAQvD;AAED,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,SAAS,EACT,KAAK,EACL,IAAI,EACJ,IAAI,GACL,EAAE,SAAS,GAAG,MAAM,CAYpB;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAU9D"}
@@ -17,8 +17,12 @@ function stringifyQuery(query) {
17
17
  return querystring_1.default.stringify(orderedObj);
18
18
  }
19
19
  exports.stringifyQuery = stringifyQuery;
20
- function generateLocalHmac(query) {
21
- var queryString = stringifyQuery(query);
20
+ function generateLocalHmac(_a) {
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
26
  return crypto_1.default
23
27
  .createHmac('sha256', context_1.Context.API_SECRET_KEY)
24
28
  .update(queryString)
@@ -34,8 +38,8 @@ function validateHmac(query) {
34
38
  if (!query.hmac) {
35
39
  throw new ShopifyErrors.InvalidHmacError('Query does not contain an HMAC value.');
36
40
  }
37
- var hmac = query.hmac, rest = tslib_1.__rest(query, ["hmac"]);
38
- var localHmac = generateLocalHmac(rest);
41
+ var hmac = query.hmac;
42
+ var localHmac = generateLocalHmac(query);
39
43
  return safe_compare_1.default(hmac, localHmac);
40
44
  }
41
45
  exports.default = validateHmac;
@@ -1 +1 @@
1
- {"version":3,"file":"load-current-session.d.ts","sourceRoot":"","sources":["../../src/utils/load-current-session.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,OAAO,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAC;AAExC;;;;;;GAMG;AACH,wBAA8B,kBAAkB,CAC9C,OAAO,EAAE,IAAI,CAAC,eAAe,EAC7B,QAAQ,EAAE,IAAI,CAAC,cAAc,EAC7B,QAAQ,UAAO,GACd,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAS9B"}
1
+ {"version":3,"file":"load-current-session.d.ts","sourceRoot":"","sources":["../../src/utils/load-current-session.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,OAAO,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAC;AAExC;;;;;;GAMG;AACH,wBAA8B,kBAAkB,CAC9C,OAAO,EAAE,IAAI,CAAC,eAAe,EAC7B,QAAQ,EAAE,IAAI,CAAC,cAAc,EAC7B,QAAQ,UAAO,GACd,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAa9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"load-offline-session.d.ts","sourceRoot":"","sources":["../../src/utils/load-offline-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,yBAAyB,CAAC;AAIhD;;;;;;;GAOG;AACH,wBAA8B,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,UAAQ,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAanH"}
1
+ {"version":3,"file":"load-offline-session.d.ts","sourceRoot":"","sources":["../../src/utils/load-offline-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,yBAAyB,CAAC;AAIhD;;;;;;;GAOG;AACH,wBAA8B,kBAAkB,CAC9C,IAAI,EAAE,MAAM,EACZ,cAAc,UAAQ,GACrB,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAkB9B"}
@@ -24,7 +24,10 @@ function loadOfflineSession(shop, includeExpired) {
24
24
  case 1:
25
25
  session = _a.sent();
26
26
  now = new Date();
27
- if (session && !includeExpired && session.expires && session.expires.getTime() < now.getTime()) {
27
+ if (session &&
28
+ !includeExpired &&
29
+ session.expires &&
30
+ session.expires.getTime() < now.getTime()) {
28
31
  return [2 /*return*/, undefined];
29
32
  }
30
33
  return [2 /*return*/, session];
@@ -1 +1 @@
1
- {"version":3,"file":"version-compatible.d.ts","sourceRoot":"","sources":["../../src/utils/version-compatible.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,gBAAgB,EAAE,UAAU,EAAE,cAAc,GAAE,UAAgC,GAAG,OAAO,CASjI"}
1
+ {"version":3,"file":"version-compatible.d.ts","sourceRoot":"","sources":["../../src/utils/version-compatible.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,gBAAgB,EAAE,UAAU,EAC5B,cAAc,GAAE,UAAgC,GAC/C,OAAO,CAaT"}
@@ -8,10 +8,13 @@ var base_types_1 = require("../base_types");
8
8
  function versionCompatible(referenceVersion, currentVersion) {
9
9
  if (currentVersion === void 0) { currentVersion = context_1.Context.API_VERSION; }
10
10
  // Return true if not using a dated version
11
- if (currentVersion === base_types_1.ApiVersion.Unstable || currentVersion === base_types_1.ApiVersion.Unversioned) {
11
+ if (currentVersion === base_types_1.ApiVersion.Unstable ||
12
+ currentVersion === base_types_1.ApiVersion.Unversioned) {
12
13
  return true;
13
14
  }
14
- var numericVersion = function (version) { return parseInt(version.replace('-', ''), 10); };
15
+ var numericVersion = function (version) {
16
+ return parseInt(version.replace('-', ''), 10);
17
+ };
15
18
  var current = numericVersion(currentVersion);
16
19
  var reference = numericVersion(referenceVersion);
17
20
  return current >= reference;
@@ -1 +1 @@
1
- {"version":3,"file":"with-session.d.ts","sourceRoot":"","sources":["../../src/utils/with-session.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,iBAAiB,EAAE,mBAAmB,EAAC,MAAM,SAAS,CAAC;AAI/D,wBAA8B,WAAW,CAAC,EACxC,UAAU,EACV,QAAQ,EACR,GAAG,EACH,GAAG,EACH,IAAI,GACL,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA2ClD"}
1
+ {"version":3,"file":"with-session.d.ts","sourceRoot":"","sources":["../../src/utils/with-session.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,iBAAiB,EAAE,mBAAmB,EAAC,MAAM,SAAS,CAAC;AAI/D,wBAA8B,WAAW,CAAC,EACxC,UAAU,EACV,QAAQ,EACR,GAAG,EACH,GAAG,EACH,IAAI,GACL,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAiDlD"}
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const SHOPIFY_API_LIBRARY_VERSION = "1.4.0";
1
+ export declare const SHOPIFY_API_LIBRARY_VERSION = "2.0.0";
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 = '1.4.0';
4
+ exports.SHOPIFY_API_LIBRARY_VERSION = '2.0.0';
@@ -1,14 +1,48 @@
1
1
  /// <reference types="node" />
2
2
  import http from 'http';
3
- import { DeliveryMethod, RegisterOptions, RegisterReturn, WebhookRegistryEntry } from './types';
3
+ import { DeliveryMethod, RegisterOptions, RegisterReturn, WebhookRegistryEntry, ShortenedRegisterOptions } from './types';
4
+ interface AddHandlersProps {
5
+ [topic: string]: WebhookRegistryEntry;
6
+ }
4
7
  interface RegistryInterface {
5
- webhookRegistry: WebhookRegistryEntry[];
8
+ webhookRegistry: {
9
+ [topic: string]: WebhookRegistryEntry;
10
+ };
11
+ /**
12
+ * Sets the handler for the given topic. If a handler was previously set for the same topic, it will be overridden.
13
+ *
14
+ * @param topic String used to add a handler
15
+ * @param options Paramters to add a handler which are path and webHookHandler
16
+ */
17
+ addHandler(topic: string, options: WebhookRegistryEntry): void;
18
+ /**
19
+ * Sets a list of handlers for the given topics using the `addHandler` function
20
+ *
21
+ * @param handlers Object in format {topic: WebhookRegistryEntry}
22
+ */
23
+ addHandlers(handlers: AddHandlersProps): void;
24
+ /**
25
+ * Fetches the handler for the given topic. Returns null if no handler was registered.
26
+ *
27
+ * @param topic The topic to check
28
+ */
29
+ getHandler(topic: string): WebhookRegistryEntry | null;
30
+ /**
31
+ * Gets all topics
32
+ */
33
+ getTopics(): string[];
6
34
  /**
7
35
  * Registers a Webhook Handler function for a given topic.
8
36
  *
9
- * @param options Parameters to register a handler, including topic, listening address, handler function
37
+ * @param options Parameters to register a handler, including topic, listening address, delivery method
10
38
  */
11
39
  register(options: RegisterOptions): Promise<RegisterReturn>;
40
+ /**
41
+ * Registers multiple Webhook Handler functions.
42
+ *
43
+ * @param options Parameters to register a handler, including topic, listening address, delivery method
44
+ */
45
+ registerAll(options: ShortenedRegisterOptions): Promise<RegisterReturn>;
12
46
  /**
13
47
  * Processes the webhook request received from the Shopify API
14
48
  *
@@ -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,EAGrB,MAAM,SAAS,CAAC;AAEjB,UAAU,iBAAiB;IACzB,eAAe,EAAE,oBAAoB,EAAE,CAAC;IAExC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAE5D;;;;;OAKG;IACH,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ,EAAE,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErF;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACtC;AA0CD,iBAAS,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAsC9C;AAED,iBAAS,UAAU,CACjB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,cAAc,GAAE,cAAoC,EACpD,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CA2CR;AAED,QAAA,MAAM,gBAAgB,EAAE,iBA8JvB,CAAC;AAEF,OAAO,EAAC,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,UAAU,EAAC,CA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AAE,cAAoC,EACpD,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAmDR;AAED,QAAA,MAAM,gBAAgB,EAAE,iBA+NvB,CAAC;AAEF,OAAO,EAAC,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,UAAU,EAAC,CAAC"}
@@ -38,10 +38,12 @@ function versionSupportsPubSub() {
38
38
  return utils_1.default.versionCompatible(base_types_1.ApiVersion.July21);
39
39
  }
40
40
  function validateDeliveryMethod(deliveryMethod) {
41
- if (deliveryMethod === types_1.DeliveryMethod.EventBridge && !versionSupportsEndpointField()) {
41
+ if (deliveryMethod === types_1.DeliveryMethod.EventBridge &&
42
+ !versionSupportsEndpointField()) {
42
43
  throw new ShopifyErrors.UnsupportedClientType("EventBridge webhooks are not supported in API version \"" + context_1.Context.API_VERSION + "\".");
43
44
  }
44
- else if (deliveryMethod === types_1.DeliveryMethod.PubSub && !versionSupportsPubSub()) {
45
+ else if (deliveryMethod === types_1.DeliveryMethod.PubSub &&
46
+ !versionSupportsPubSub()) {
45
47
  throw new ShopifyErrors.UnsupportedClientType("Pub/Sub webhooks are not supported in API version \"" + context_1.Context.API_VERSION + "\".");
46
48
  }
47
49
  }
@@ -73,16 +75,24 @@ function buildQuery(topic, address, deliveryMethod, webhookId) {
73
75
  var pubSubTopic;
74
76
  switch (deliveryMethod) {
75
77
  case types_1.DeliveryMethod.Http:
76
- mutationName = webhookId ? 'webhookSubscriptionUpdate' : 'webhookSubscriptionCreate';
78
+ mutationName = webhookId
79
+ ? 'webhookSubscriptionUpdate'
80
+ : 'webhookSubscriptionCreate';
77
81
  webhookSubscriptionArgs = "{callbackUrl: \"" + address + "\"}";
78
82
  break;
79
83
  case types_1.DeliveryMethod.EventBridge:
80
- mutationName = webhookId ? 'eventBridgeWebhookSubscriptionUpdate' : 'eventBridgeWebhookSubscriptionCreate';
84
+ mutationName = webhookId
85
+ ? 'eventBridgeWebhookSubscriptionUpdate'
86
+ : 'eventBridgeWebhookSubscriptionCreate';
81
87
  webhookSubscriptionArgs = "{arn: \"" + address + "\"}";
82
88
  break;
83
89
  case types_1.DeliveryMethod.PubSub:
84
- mutationName = webhookId ? 'pubSubWebhookSubscriptionUpdate' : 'pubSubWebhookSubscriptionCreate';
85
- _a = tslib_1.__read(address.replace(/^pubsub:\/\//, '').split(':'), 2), pubSubProject = _a[0], pubSubTopic = _a[1];
90
+ mutationName = webhookId
91
+ ? 'pubSubWebhookSubscriptionUpdate'
92
+ : 'pubSubWebhookSubscriptionCreate';
93
+ _a = tslib_1.__read(address
94
+ .replace(/^pubsub:\/\//, '')
95
+ .split(':'), 2), pubSubProject = _a[0], pubSubTopic = _a[1];
86
96
  webhookSubscriptionArgs = "{pubSubProject: \"" + pubSubProject + "\",\n pubSubTopic: \"" + pubSubTopic + "\"}";
87
97
  break;
88
98
  }
@@ -90,14 +100,32 @@ function buildQuery(topic, address, deliveryMethod, webhookId) {
90
100
  }
91
101
  exports.buildQuery = buildQuery;
92
102
  var WebhooksRegistry = {
93
- webhookRegistry: [],
103
+ webhookRegistry: {},
104
+ addHandler: function (topic, _a) {
105
+ var path = _a.path, webhookHandler = _a.webhookHandler;
106
+ WebhooksRegistry.webhookRegistry[topic] = { path: path, webhookHandler: webhookHandler };
107
+ },
108
+ addHandlers: function (handlers) {
109
+ for (var topic in handlers) {
110
+ if ({}.hasOwnProperty.call(handlers, topic)) {
111
+ WebhooksRegistry.addHandler(topic, handlers[topic]);
112
+ }
113
+ }
114
+ },
115
+ getHandler: function (topic) {
116
+ return topic in WebhooksRegistry.webhookRegistry ? WebhooksRegistry.webhookRegistry[topic] : null;
117
+ },
118
+ getTopics: function () {
119
+ return Object.keys(WebhooksRegistry.webhookRegistry);
120
+ },
94
121
  register: function (_a) {
95
- var path = _a.path, topic = _a.topic, accessToken = _a.accessToken, shop = _a.shop, _b = _a.deliveryMethod, deliveryMethod = _b === void 0 ? types_1.DeliveryMethod.Http : _b, webhookHandler = _a.webhookHandler;
122
+ var path = _a.path, topic = _a.topic, accessToken = _a.accessToken, shop = _a.shop, _b = _a.deliveryMethod, deliveryMethod = _b === void 0 ? types_1.DeliveryMethod.Http : _b;
96
123
  return tslib_1.__awaiter(this, void 0, void 0, function () {
97
- var client, address, checkResult, webhookId, mustRegister, node, endpointAddress, success, body, result;
124
+ var registerReturn, client, address, checkResult, webhookId, mustRegister, node, endpointAddress, result;
98
125
  return tslib_1.__generator(this, function (_c) {
99
126
  switch (_c.label) {
100
127
  case 0:
128
+ registerReturn = {};
101
129
  validateDeliveryMethod(deliveryMethod);
102
130
  client = new graphql_client_1.GraphqlClient(shop, accessToken);
103
131
  address = deliveryMethod === types_1.DeliveryMethod.Http
@@ -107,7 +135,7 @@ var WebhooksRegistry = {
107
135
  data: buildCheckQuery(topic),
108
136
  })];
109
137
  case 1:
110
- checkResult = _c.sent();
138
+ checkResult = (_c.sent());
111
139
  mustRegister = true;
112
140
  if (checkResult.body.data.webhookSubscriptions.edges.length) {
113
141
  node = checkResult.body.data.webhookSubscriptions.edges[0].node;
@@ -134,20 +162,70 @@ var WebhooksRegistry = {
134
162
  })];
135
163
  case 2:
136
164
  result = _c.sent();
137
- success = isSuccess(result.body, deliveryMethod, webhookId);
138
- body = result.body;
165
+ registerReturn[topic] = {
166
+ success: isSuccess(result.body, deliveryMethod, webhookId),
167
+ result: result.body,
168
+ };
139
169
  return [3 /*break*/, 4];
140
170
  case 3:
141
- success = true;
142
- body = {};
171
+ registerReturn[topic] = {
172
+ success: true,
173
+ result: {},
174
+ };
143
175
  _c.label = 4;
176
+ case 4: return [2 /*return*/, registerReturn];
177
+ }
178
+ });
179
+ });
180
+ },
181
+ registerAll: function (_a) {
182
+ var accessToken = _a.accessToken, shop = _a.shop, _b = _a.deliveryMethod, deliveryMethod = _b === void 0 ? types_1.DeliveryMethod.Http : _b;
183
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
184
+ var registerReturn, topics, topics_1, topics_1_1, topic, handler, path, webhook, returnedRegister, e_1_1;
185
+ var e_1, _c;
186
+ return tslib_1.__generator(this, function (_d) {
187
+ switch (_d.label) {
188
+ case 0:
189
+ registerReturn = {};
190
+ topics = WebhooksRegistry.getTopics();
191
+ _d.label = 1;
192
+ case 1:
193
+ _d.trys.push([1, 6, 7, 8]);
194
+ topics_1 = tslib_1.__values(topics), topics_1_1 = topics_1.next();
195
+ _d.label = 2;
196
+ case 2:
197
+ if (!!topics_1_1.done) return [3 /*break*/, 5];
198
+ topic = topics_1_1.value;
199
+ handler = WebhooksRegistry.getHandler(topic);
200
+ if (!handler) return [3 /*break*/, 4];
201
+ path = handler.path;
202
+ webhook = {
203
+ path: path,
204
+ topic: topic,
205
+ accessToken: accessToken,
206
+ shop: shop,
207
+ deliveryMethod: deliveryMethod,
208
+ };
209
+ return [4 /*yield*/, WebhooksRegistry.register(webhook)];
210
+ case 3:
211
+ returnedRegister = _d.sent();
212
+ registerReturn = tslib_1.__assign(tslib_1.__assign({}, registerReturn), returnedRegister);
213
+ _d.label = 4;
144
214
  case 4:
145
- if (success) {
146
- // Remove this topic from the registry if it is already there
147
- WebhooksRegistry.webhookRegistry = WebhooksRegistry.webhookRegistry.filter(function (item) { return item.topic !== topic; });
148
- WebhooksRegistry.webhookRegistry.push({ path: path, topic: topic, webhookHandler: webhookHandler });
215
+ topics_1_1 = topics_1.next();
216
+ return [3 /*break*/, 2];
217
+ case 5: return [3 /*break*/, 8];
218
+ case 6:
219
+ e_1_1 = _d.sent();
220
+ e_1 = { error: e_1_1 };
221
+ return [3 /*break*/, 8];
222
+ case 7:
223
+ try {
224
+ if (topics_1_1 && !topics_1_1.done && (_c = topics_1.return)) _c.call(topics_1);
149
225
  }
150
- return [2 /*return*/, { success: success, result: body }];
226
+ finally { if (e_1) throw e_1.error; }
227
+ return [7 /*endfinally*/];
228
+ case 8: return [2 /*return*/, registerReturn];
151
229
  }
152
230
  });
153
231
  });
@@ -163,7 +241,7 @@ var WebhooksRegistry = {
163
241
  reqBody += chunk;
164
242
  });
165
243
  request.on('end', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
166
- var hmac, topic, domain, missingHeaders, statusCode, responseError, headers, generatedHash, graphqlTopic_1, webhookEntry, error_1;
244
+ var hmac, topic, domain, missingHeaders, statusCode, responseError, headers, generatedHash, graphqlTopic, webhookEntry, error_1;
167
245
  return tslib_1.__generator(this, function (_a) {
168
246
  switch (_a.label) {
169
247
  case 0:
@@ -206,13 +284,13 @@ var WebhooksRegistry = {
206
284
  .update(reqBody, 'utf8')
207
285
  .digest('base64');
208
286
  if (!utils_1.default.safeCompare(generatedHash, hmac)) return [3 /*break*/, 7];
209
- graphqlTopic_1 = topic.toUpperCase().replace(/\//g, '_');
210
- webhookEntry = WebhooksRegistry.webhookRegistry.find(function (entry) { return entry.topic === graphqlTopic_1; });
287
+ graphqlTopic = topic.toUpperCase().replace(/\//g, '_');
288
+ webhookEntry = WebhooksRegistry.getHandler(graphqlTopic);
211
289
  if (!webhookEntry) return [3 /*break*/, 5];
212
290
  _a.label = 1;
213
291
  case 1:
214
292
  _a.trys.push([1, 3, , 4]);
215
- return [4 /*yield*/, webhookEntry.webhookHandler(graphqlTopic_1, domain, reqBody)];
293
+ return [4 /*yield*/, webhookEntry.webhookHandler(graphqlTopic, domain, reqBody)];
216
294
  case 2:
217
295
  _a.sent();
218
296
  statusCode = network_1.StatusCode.Ok;
@@ -251,7 +329,12 @@ var WebhooksRegistry = {
251
329
  });
252
330
  },
253
331
  isWebhookPath: function (path) {
254
- return Boolean(WebhooksRegistry.webhookRegistry.find(function (entry) { return entry.path === path; }));
332
+ for (var key in WebhooksRegistry.webhookRegistry) {
333
+ if (WebhooksRegistry.webhookRegistry[key].path === path) {
334
+ return true;
335
+ }
336
+ }
337
+ return false;
255
338
  },
256
339
  };
257
340
  exports.WebhooksRegistry = WebhooksRegistry;
@@ -9,16 +9,21 @@ export interface RegisterOptions {
9
9
  path: string;
10
10
  shop: string;
11
11
  accessToken: string;
12
- webhookHandler: WebhookHandlerFunction;
12
+ deliveryMethod?: DeliveryMethod;
13
+ }
14
+ export interface ShortenedRegisterOptions {
15
+ shop: string;
16
+ accessToken: string;
13
17
  deliveryMethod?: DeliveryMethod;
14
18
  }
15
19
  export interface RegisterReturn {
16
- success: boolean;
17
- result: unknown;
20
+ [topic: string]: {
21
+ success: boolean;
22
+ result: unknown;
23
+ };
18
24
  }
19
25
  export interface WebhookRegistryEntry {
20
26
  path: string;
21
- topic: string;
22
27
  webhookHandler: WebhookHandlerFunction;
23
28
  }
24
29
  interface WebhookCheckResponseNode<T = {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/webhooks/types.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACxB,IAAI,SAAS;IACb,WAAW,gBAAgB;IAC3B,MAAM,WAAW;CAClB;AAED,aAAK,sBAAsB,GAAG,CAC5B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,KACT,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,WAAW,eAAe;IAE9B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,sBAAsB,CAAC;IACvC,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,sBAAsB,CAAC;CACxC;AAED,UAAU,wBAAwB,CAAC,CAAC,GAAG;IACrC,QAAQ,EAAE;QACR,UAAU,EAAE,qBAAqB,CAAC;QAClC,WAAW,EAAE,MAAM,CAAC;KACrB,GAAG;QACF,UAAU,EAAE,4BAA4B,CAAC;QACzC,GAAG,EAAE,MA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ACjB,CAAC;CACH;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,sBAAsB,CAAC;CACxC;AAED,UAAU,wBAAwB,CAChC,CAAC,GAAG;IACF,QAAQ,EACJ;QACE,UAAU,EAAE,qBAAqB,CAAC;QAClC,WAAW,EAAE,MAAM,CAAC;KACrB,GACD;QACE,UAAU,EAAE,4BAA4B,CAAC;QACzC,GAAG,EAAE,MAAM,CAAC;KACb,GACD;QACE,UAAU,EAAE,uBAAuB,CAAC;QACpC,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACP;IAED,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;KACZ,GAAG,CAAC,CAAC;CACP;AAED,aAAK,8BAA8B,GAAG,wBAAwB,CAAC;IAC7D,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CAAC;AAEH,MAAM,WAAW,oBAAoB,CAAC,CAAC,GAAG,wBAAwB;IAChE,IAAI,EAAE;QACJ,oBAAoB,EAAE;YACpB,KAAK,EAAE,CAAC,EAAE,CAAC;SACZ,CAAC;KACH,CAAC;CACH;AAED,oBAAY,0BAA0B,GACpC,oBAAoB,CAAC,8BAA8B,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@shopify/shopify-api",
3
- "version": "1.4.0",
3
+ "version": "2.0.0",
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
+ "prettier": "@shopify/prettier-config",
7
8
  "scripts": {
8
9
  "test": "jest",
9
10
  "build": "tsc",
@@ -50,15 +51,17 @@
50
51
  },
51
52
  "devDependencies": {
52
53
  "@shopify/eslint-plugin": "^39.0.3",
54
+ "@shopify/prettier-config": "^1.1.2",
53
55
  "@types/cookies": "^0.7.5",
54
56
  "@types/jest": "^26.0.15",
55
57
  "@types/node": "^14.14.1",
56
58
  "@types/uuid": "^8.3.0",
57
- "eslint": "^7.9.0",
59
+ "eslint": "^7.30.0",
58
60
  "eslint-plugin-tsdoc": "^0.2.7",
59
61
  "express": "^4.17.1",
60
62
  "jest": "^26.4.2",
61
63
  "jest-fetch-mock": "^3.0.3",
64
+ "prettier": "^2.3.2",
62
65
  "rimraf": "^3.0.2",
63
66
  "supertest": "^6.1.3",
64
67
  "ts-jest": "^26.4.1",