@shopify/shopify-api 4.1.0 → 5.0.1

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 (70) hide show
  1. package/CHANGELOG.md +26 -5
  2. package/dist/auth/oauth/oauth.d.ts.map +1 -1
  3. package/dist/auth/oauth/oauth.js +7 -5
  4. package/dist/auth/session/session_storage.d.ts +12 -0
  5. package/dist/auth/session/session_storage.d.ts.map +1 -1
  6. package/dist/auth/session/storage/custom.d.ts +5 -1
  7. package/dist/auth/session/storage/custom.d.ts.map +1 -1
  8. package/dist/auth/session/storage/custom.js +59 -1
  9. package/dist/auth/session/storage/memory.d.ts +2 -0
  10. package/dist/auth/session/storage/memory.d.ts.map +1 -1
  11. package/dist/auth/session/storage/memory.js +20 -0
  12. package/dist/auth/session/storage/mongodb.d.ts +2 -0
  13. package/dist/auth/session/storage/mongodb.d.ts.map +1 -1
  14. package/dist/auth/session/storage/mongodb.js +41 -6
  15. package/dist/auth/session/storage/mysql.d.ts +2 -0
  16. package/dist/auth/session/storage/mysql.d.ts.map +1 -1
  17. package/dist/auth/session/storage/mysql.js +41 -0
  18. package/dist/auth/session/storage/postgresql.d.ts +2 -0
  19. package/dist/auth/session/storage/postgresql.d.ts.map +1 -1
  20. package/dist/auth/session/storage/postgresql.js +41 -0
  21. package/dist/auth/session/storage/redis.d.ts +4 -1
  22. package/dist/auth/session/storage/redis.d.ts.map +1 -1
  23. package/dist/auth/session/storage/redis.js +68 -3
  24. package/dist/auth/session/storage/sqlite.d.ts +2 -0
  25. package/dist/auth/session/storage/sqlite.d.ts.map +1 -1
  26. package/dist/auth/session/storage/sqlite.js +42 -0
  27. package/dist/base-types.d.ts +1 -0
  28. package/dist/base-types.d.ts.map +1 -1
  29. package/dist/clients/graphql/graphql_client.d.ts.map +1 -1
  30. package/dist/clients/graphql/graphql_client.js +25 -14
  31. package/dist/clients/http_client/http_client.d.ts.map +1 -1
  32. package/dist/clients/http_client/http_client.js +5 -1
  33. package/dist/context.d.ts.map +1 -1
  34. package/dist/context.js +3 -0
  35. package/dist/error.d.ts +13 -0
  36. package/dist/error.d.ts.map +1 -1
  37. package/dist/error.js +20 -1
  38. package/dist/index.d.ts +2 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/utils/delete-offline-session.d.ts.map +1 -1
  41. package/dist/utils/delete-offline-session.js +4 -2
  42. package/dist/utils/get-embedded-app-url.d.ts.map +1 -1
  43. package/dist/utils/get-embedded-app-url.js +2 -1
  44. package/dist/utils/index.d.ts +3 -2
  45. package/dist/utils/index.d.ts.map +1 -1
  46. package/dist/utils/index.js +3 -2
  47. package/dist/utils/load-offline-session.d.ts.map +1 -1
  48. package/dist/utils/load-offline-session.js +4 -2
  49. package/dist/utils/setup-jest.d.ts.map +1 -1
  50. package/dist/utils/setup-jest.js +1 -0
  51. package/dist/utils/shop-validator.d.ts +12 -3
  52. package/dist/utils/shop-validator.d.ts.map +1 -1
  53. package/dist/utils/shop-validator.js +39 -7
  54. package/dist/version.d.ts +1 -1
  55. package/dist/version.js +1 -1
  56. package/dist/webhooks/registry.d.ts.map +1 -1
  57. package/dist/webhooks/registry.js +23 -20
  58. package/package.json +1 -1
  59. package/dist/__tests__/fake-resource-with-custom-prefix.d.ts +0 -21
  60. package/dist/__tests__/fake-resource-with-custom-prefix.d.ts.map +0 -1
  61. package/dist/__tests__/fake-resource-with-custom-prefix.js +0 -46
  62. package/dist/__tests__/fake-resource.d.ts +0 -41
  63. package/dist/__tests__/fake-resource.d.ts.map +0 -1
  64. package/dist/__tests__/fake-resource.js +0 -122
  65. package/dist/auth/session/storage/__tests__/battery-of-tests.d.ts +0 -3
  66. package/dist/auth/session/storage/__tests__/battery-of-tests.d.ts.map +0 -1
  67. package/dist/auth/session/storage/__tests__/battery-of-tests.js +0 -191
  68. package/dist/auth/session/storage/__tests__/utils.d.ts +0 -10
  69. package/dist/auth/session/storage/__tests__/utils.d.ts.map +0 -1
  70. package/dist/auth/session/storage/__tests__/utils.js +0 -87
@@ -4,6 +4,7 @@ exports.RedisSessionStorage = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var redis_1 = require("redis");
6
6
  var session_utils_1 = require("../session-utils");
7
+ var shop_validator_1 = require("../../../utils/shop-validator");
7
8
  var defaultRedisSessionStorageOptions = {
8
9
  sessionKeyPrefix: 'shopify_sessions',
9
10
  };
@@ -69,6 +70,72 @@ var RedisSessionStorage = /** @class */ (function () {
69
70
  });
70
71
  });
71
72
  };
73
+ RedisSessionStorage.prototype.deleteSessions = function (ids) {
74
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
75
+ var _this = this;
76
+ return tslib_1.__generator(this, function (_a) {
77
+ switch (_a.label) {
78
+ case 0: return [4 /*yield*/, this.ready];
79
+ case 1:
80
+ _a.sent();
81
+ return [4 /*yield*/, this.client.del(ids.map(function (id) { return _this.fullKey(id); }))];
82
+ case 2:
83
+ _a.sent();
84
+ return [2 /*return*/, true];
85
+ }
86
+ });
87
+ });
88
+ };
89
+ RedisSessionStorage.prototype.findSessionsByShop = function (shop) {
90
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
91
+ var cleanShop, keys, results, keys_1, keys_1_1, key, rawResult, session, e_1_1;
92
+ var e_1, _a;
93
+ return tslib_1.__generator(this, function (_b) {
94
+ switch (_b.label) {
95
+ case 0: return [4 /*yield*/, this.ready];
96
+ case 1:
97
+ _b.sent();
98
+ cleanShop = (0, shop_validator_1.sanitizeShop)(shop, true);
99
+ return [4 /*yield*/, this.client.keys('*')];
100
+ case 2:
101
+ keys = _b.sent();
102
+ results = [];
103
+ _b.label = 3;
104
+ case 3:
105
+ _b.trys.push([3, 8, 9, 10]);
106
+ keys_1 = tslib_1.__values(keys), keys_1_1 = keys_1.next();
107
+ _b.label = 4;
108
+ case 4:
109
+ if (!!keys_1_1.done) return [3 /*break*/, 7];
110
+ key = keys_1_1.value;
111
+ return [4 /*yield*/, this.client.get(key)];
112
+ case 5:
113
+ rawResult = _b.sent();
114
+ if (!rawResult)
115
+ return [3 /*break*/, 6];
116
+ session = (0, session_utils_1.sessionFromEntries)(JSON.parse(rawResult));
117
+ if (session.shop === cleanShop)
118
+ results.push(session);
119
+ _b.label = 6;
120
+ case 6:
121
+ keys_1_1 = keys_1.next();
122
+ return [3 /*break*/, 4];
123
+ case 7: return [3 /*break*/, 10];
124
+ case 8:
125
+ e_1_1 = _b.sent();
126
+ e_1 = { error: e_1_1 };
127
+ return [3 /*break*/, 10];
128
+ case 9:
129
+ try {
130
+ if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
131
+ }
132
+ finally { if (e_1) throw e_1.error; }
133
+ return [7 /*endfinally*/];
134
+ case 10: return [2 /*return*/, results];
135
+ }
136
+ });
137
+ });
138
+ };
72
139
  RedisSessionStorage.prototype.disconnect = function () {
73
140
  return tslib_1.__awaiter(this, void 0, void 0, function () {
74
141
  return tslib_1.__generator(this, function (_a) {
@@ -89,9 +156,7 @@ var RedisSessionStorage = /** @class */ (function () {
89
156
  return tslib_1.__generator(this, function (_a) {
90
157
  switch (_a.label) {
91
158
  case 0:
92
- this.client = (0, redis_1.createClient)({
93
- url: this.dbUrl.toString(),
94
- });
159
+ this.client = (0, redis_1.createClient)(tslib_1.__assign(tslib_1.__assign({}, this.options), { url: this.dbUrl.toString() }));
95
160
  return [4 /*yield*/, this.client.connect()];
96
161
  case 1:
97
162
  _a.sent();
@@ -12,6 +12,8 @@ export declare class SQLiteSessionStorage implements SessionStorage {
12
12
  storeSession(session: SessionInterface): Promise<boolean>;
13
13
  loadSession(id: string): Promise<SessionInterface | undefined>;
14
14
  deleteSession(id: string): Promise<boolean>;
15
+ deleteSessions(ids: string[]): Promise<boolean>;
16
+ findSessionsByShop(shop: string): Promise<SessionInterface[]>;
15
17
  private hasSessionTable;
16
18
  private init;
17
19
  private query;
@@ -1 +1 @@
1
- {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../../../src/auth/session/storage/sqlite.ts"],"names":[],"mappings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AAC;IAkBzD,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAa9D,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAU3C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAU/C,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAiB5D,eAAe;YAWf,IAAI;IAmBlB,OAAO,CAAC,KAAK;CAWd"}
@@ -4,6 +4,7 @@ exports.SQLiteSessionStorage = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var sqlite3_1 = tslib_1.__importDefault(require("sqlite3"));
6
6
  var session_utils_1 = require("../session-utils");
7
+ var shop_validator_1 = require("../../../utils/shop-validator");
7
8
  var defaultSQLiteSessionStorageOptions = {
8
9
  sessionTableName: 'shopify_sessions',
9
10
  };
@@ -76,6 +77,47 @@ var SQLiteSessionStorage = /** @class */ (function () {
76
77
  });
77
78
  });
78
79
  };
80
+ SQLiteSessionStorage.prototype.deleteSessions = function (ids) {
81
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
82
+ var query;
83
+ return tslib_1.__generator(this, function (_a) {
84
+ switch (_a.label) {
85
+ case 0: return [4 /*yield*/, this.ready];
86
+ case 1:
87
+ _a.sent();
88
+ query = "\n DELETE FROM ".concat(this.options.sessionTableName, "\n WHERE id IN (").concat(ids.map(function () { return '?'; }).join(','), ");\n ");
89
+ return [4 /*yield*/, this.query(query, ids)];
90
+ case 2:
91
+ _a.sent();
92
+ return [2 /*return*/, true];
93
+ }
94
+ });
95
+ });
96
+ };
97
+ SQLiteSessionStorage.prototype.findSessionsByShop = function (shop) {
98
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
99
+ var cleanShop, query, rows, results;
100
+ return tslib_1.__generator(this, function (_a) {
101
+ switch (_a.label) {
102
+ case 0:
103
+ cleanShop = (0, shop_validator_1.sanitizeShop)(shop, true);
104
+ return [4 /*yield*/, this.ready];
105
+ case 1:
106
+ _a.sent();
107
+ query = "\n SELECT * FROM ".concat(this.options.sessionTableName, "\n WHERE shop = ?;\n ");
108
+ return [4 /*yield*/, this.query(query, [cleanShop])];
109
+ case 2:
110
+ rows = _a.sent();
111
+ if (!Array.isArray(rows) || (rows === null || rows === void 0 ? void 0 : rows.length) === 0)
112
+ return [2 /*return*/, []];
113
+ results = rows.map(function (row) {
114
+ return (0, session_utils_1.sessionFromEntries)(Object.entries(row));
115
+ });
116
+ return [2 /*return*/, results];
117
+ }
118
+ });
119
+ });
120
+ };
79
121
  SQLiteSessionStorage.prototype.hasSessionTable = function () {
80
122
  return tslib_1.__awaiter(this, void 0, void 0, function () {
81
123
  var query, rows;
@@ -13,6 +13,7 @@ export interface ContextParams {
13
13
  LOG_FILE?: string;
14
14
  USER_AGENT_PREFIX?: string;
15
15
  PRIVATE_APP_STOREFRONT_ACCESS_TOKEN?: string;
16
+ CUSTOM_SHOP_DOMAINS?: (RegExp | string)[];
16
17
  }
17
18
  export declare enum ApiVersion {
18
19
  October21 = "2021-10",
@@ -1 +1 @@
1
- {"version":3,"file":"base-types.d.ts","sourceRoot":"","sources":["../src/base-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,cAAc,EAAC,MAAM,gCAAgC,CAAC;AAE9D,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,UAAU,CAAC;IACxB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,cAAc,CAAC;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AO,MAAM,kBAAkB,oBAAoB,CAAC;AAEpD,oBAAY,aAAa;IACvB,WAAW,2BAA2B;IACtC,qBAAqB,sCAAsC;IAC3D,IAAI,0BAA0B;IAC9B,KAAK,oBAAoB;IACzB,MAAM,0BAA0B;CACjC"}
@@ -1 +1 @@
1
- {"version":3,"file":"graphql_client.d.ts","sourceRoot":"","sources":["../../../src/clients/graphql/graphql_client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAW,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAG7D,OAAO,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAEtC,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,aAAa;IAKZ,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAE,QAAQ,CAAC,WAAW,CAAC;IAJ1D,SAAS,CAAC,WAAW,SAAgB;IAErC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;gBAEf,MAAM,EAAE,MAAM,EAAW,WAAW,CAAC,oBAAQ;IAU5D,KAAK,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAwB1D,SAAS,CAAC,oBAAoB,IAAI,iBAAiB;CAQpD"}
1
+ {"version":3,"file":"graphql_client.d.ts","sourceRoot":"","sources":["../../../src/clients/graphql/graphql_client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAG7D,OAAO,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAEtC,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,aAAa;IAKZ,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAE,QAAQ,CAAC,WAAW,CAAC;IAJ1D,SAAS,CAAC,WAAW,SAAgB;IAErC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;gBAEf,MAAM,EAAE,MAAM,EAAW,WAAW,CAAC,oBAAQ;IAU5D,KAAK,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAgC1D,SAAS,CAAC,oBAAoB,IAAI,iBAAiB;CAQpD"}
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GraphqlClient = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var error_1 = require("../../error");
6
5
  var context_1 = require("../../context");
7
6
  var base_types_1 = require("../../base-types");
8
7
  var http_client_1 = require("../http_client/http_client");
@@ -20,22 +19,34 @@ var GraphqlClient = /** @class */ (function () {
20
19
  }
21
20
  GraphqlClient.prototype.query = function (params) {
22
21
  return tslib_1.__awaiter(this, void 0, void 0, function () {
23
- var accessTokenHeader, path, dataType;
22
+ var accessTokenHeader, path, dataType, result;
24
23
  var _a;
25
24
  return tslib_1.__generator(this, function (_b) {
26
- if (params.data.length === 0) {
27
- throw new error_1.MissingRequiredArgument('Query missing.');
25
+ switch (_b.label) {
26
+ case 0:
27
+ if (params.data.length === 0) {
28
+ throw new ShopifyErrors.MissingRequiredArgument('Query missing.');
29
+ }
30
+ accessTokenHeader = this.getAccessTokenHeader();
31
+ params.extraHeaders = tslib_1.__assign((_a = {}, _a[accessTokenHeader.header] = accessTokenHeader.value, _a), params.extraHeaders);
32
+ path = "".concat(this.baseApiPath, "/").concat(context_1.Context.API_VERSION, "/graphql.json");
33
+ if (typeof params.data === 'object') {
34
+ dataType = types_1.DataType.JSON;
35
+ }
36
+ else {
37
+ dataType = types_1.DataType.GraphQL;
38
+ }
39
+ return [4 /*yield*/, this.client.post(tslib_1.__assign({ path: path, type: dataType }, params))];
40
+ case 1:
41
+ result = _b.sent();
42
+ if (result.body.errors) {
43
+ throw new ShopifyErrors.GraphqlQueryError({
44
+ message: 'GraphQL query returned errors',
45
+ response: result.body,
46
+ });
47
+ }
48
+ return [2 /*return*/, result];
28
49
  }
29
- accessTokenHeader = this.getAccessTokenHeader();
30
- params.extraHeaders = tslib_1.__assign((_a = {}, _a[accessTokenHeader.header] = accessTokenHeader.value, _a), params.extraHeaders);
31
- path = "".concat(this.baseApiPath, "/").concat(context_1.Context.API_VERSION, "/graphql.json");
32
- if (typeof params.data === 'object') {
33
- dataType = types_1.DataType.JSON;
34
- }
35
- else {
36
- dataType = types_1.DataType.GraphQL;
37
- }
38
- return [2 /*return*/, this.client.post(tslib_1.__assign({ path: path, type: dataType }, params))];
39
50
  });
40
51
  });
41
52
  };
@@ -1 +1 @@
1
- {"version":3,"file":"http_client.d.ts","sourceRoot":"","sources":["../../../src/clients/http_client/http_client.ts"],"names":[],"mappings":"AAYA,OAAO,EAEL,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB,qBAAa,UAAU;IAOF,OAAO,CAAC,MAAM;IALjC,MAAM,CAAC,QAAQ,CAAC,eAAe,QAAQ;IAEvC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,UAAU;IACjD,OAAO,CAAC,mBAAmB,CAA+B;gBAE/B,MAAM,EAAE,MAAM;IAIzC;;OAEG;IACU,GAAG,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAIlE;;OAEG;IACU,IAAI,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC;IAIpE;;OAEG;IACU,GAAG,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAIlE;;OAEG;IACU,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;cAIxD,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IA0GtE,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;YAIhC,SAAS;CA6GxB"}
1
+ {"version":3,"file":"http_client.d.ts","sourceRoot":"","sources":["../../../src/clients/http_client/http_client.ts"],"names":[],"mappings":"AAYA,OAAO,EAEL,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACd,MAAM,SAAS,CAAC;AAQjB,qBAAa,UAAU;IAOF,OAAO,CAAC,MAAM;IALjC,MAAM,CAAC,QAAQ,CAAC,eAAe,QAAQ;IAEvC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,UAAU;IACjD,OAAO,CAAC,mBAAmB,CAA+B;gBAE/B,MAAM,EAAE,MAAM;IAIzC;;OAEG;IACU,GAAG,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAIlE;;OAEG;IACU,IAAI,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC;IAIpE;;OAEG;IACU,GAAG,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAIlE;;OAEG;IACU,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;cAIxD,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IA0GtE,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;YAIhC,SAAS;CAqHxB"}
@@ -107,7 +107,7 @@ var HttpClient = /** @class */ (function () {
107
107
  body = data;
108
108
  break;
109
109
  }
110
- headers = tslib_1.__assign({ 'Content-Type': type, 'Content-Length': Buffer.byteLength(body) }, params.extraHeaders);
110
+ headers = tslib_1.__assign(tslib_1.__assign({}, headers), { 'Content-Type': type, 'Content-Length': Buffer.byteLength(body) });
111
111
  }
112
112
  }
113
113
  url = "https://".concat(this.domain).concat(this.getRequestPath(params.path)).concat(processed_query_1.default.stringify(params.query));
@@ -180,6 +180,10 @@ var HttpClient = /** @class */ (function () {
180
180
  message: response.headers.get('X-Shopify-API-Deprecated-Reason'),
181
181
  path: url,
182
182
  };
183
+ if (options.body) {
184
+ // This can only be a string, since we're always converting the body before calling this method
185
+ deprecation.body = "".concat(options.body.substring(0, 100), "...");
186
+ }
183
187
  depHash = crypto_1.default
184
188
  .createHash('md5')
185
189
  .update(JSON.stringify(deprecation))
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAGA,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,WAAW,EAAE,MAAM,CAAC;IACpB,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;AAOD,QAAA,MAAM,OAAO,EAAE,gBAqFd,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,gBAAgB,EAAC,CAAC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAGA,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,WAAW,EAAE,MAAM,CAAC;IACpB,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;AAOD,QAAA,MAAM,OAAO,EAAE,gBAyFd,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,gBAAgB,EAAC,CAAC"}
package/dist/context.js CHANGED
@@ -68,6 +68,9 @@ var Context = {
68
68
  this.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN =
69
69
  params.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN;
70
70
  }
71
+ if (params.CUSTOM_SHOP_DOMAINS) {
72
+ this.CUSTOM_SHOP_DOMAINS = params.CUSTOM_SHOP_DOMAINS;
73
+ }
71
74
  },
72
75
  throwIfUninitialized: function () {
73
76
  if (!this.API_KEY || this.API_KEY.length === 0) {
package/dist/error.d.ts CHANGED
@@ -5,6 +5,8 @@ export declare class InvalidHmacError extends ShopifyError {
5
5
  }
6
6
  export declare class InvalidShopError extends ShopifyError {
7
7
  }
8
+ export declare class InvalidHostError extends ShopifyError {
9
+ }
8
10
  export declare class InvalidJwtError extends ShopifyError {
9
11
  }
10
12
  export declare class MissingJwtTokenError extends ShopifyError {
@@ -52,6 +54,17 @@ export declare class HttpThrottlingError extends HttpRetriableError {
52
54
  }
53
55
  export declare class RestResourceError extends ShopifyError {
54
56
  }
57
+ export declare class GraphqlQueryError extends ShopifyError {
58
+ readonly response: {
59
+ [key: string]: unknown;
60
+ };
61
+ constructor({ message, response, }: {
62
+ message: string;
63
+ response: {
64
+ [key: string]: unknown;
65
+ };
66
+ });
67
+ }
55
68
  export declare class InvalidOAuthError extends ShopifyError {
56
69
  }
57
70
  export declare class SessionNotFound extends ShopifyError {
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa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,YAAY;CAAG;AAExD,qBAAa,uBAAwB,SAAQ,YAAY;CAAG;AAC5D,qBAAa,qBAAsB,SAAQ,YAAY;CAAG;AAE1D,qBAAa,mBAAoB,SAAQ,YAAY;CAAG"}
package/dist/error.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidRequestError = exports.UnsupportedClientType = exports.MissingRequiredArgument = exports.SessionStorageError = exports.InvalidWebhookError = exports.InvalidSession = exports.CookieNotFound = exports.SessionNotFound = exports.InvalidOAuthError = exports.RestResourceError = exports.HttpThrottlingError = exports.HttpInternalError = exports.HttpRetriableError = exports.HttpResponseError = exports.HttpMaxRetriesError = exports.HttpRequestError = exports.PrivateAppError = exports.UninitializedContextError = exports.SafeCompareError = exports.MissingJwtTokenError = exports.InvalidJwtError = exports.InvalidShopError = exports.InvalidHmacError = exports.ShopifyError = void 0;
3
+ exports.InvalidRequestError = exports.UnsupportedClientType = exports.MissingRequiredArgument = exports.SessionStorageError = exports.InvalidWebhookError = exports.InvalidSession = exports.CookieNotFound = exports.SessionNotFound = exports.InvalidOAuthError = exports.GraphqlQueryError = exports.RestResourceError = exports.HttpThrottlingError = exports.HttpInternalError = exports.HttpRetriableError = exports.HttpResponseError = exports.HttpMaxRetriesError = exports.HttpRequestError = exports.PrivateAppError = exports.UninitializedContextError = exports.SafeCompareError = exports.MissingJwtTokenError = exports.InvalidJwtError = exports.InvalidHostError = exports.InvalidShopError = exports.InvalidHmacError = exports.ShopifyError = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var ShopifyError = /** @class */ (function (_super) {
6
6
  tslib_1.__extends(ShopifyError, _super);
@@ -33,6 +33,14 @@ var InvalidShopError = /** @class */ (function (_super) {
33
33
  return InvalidShopError;
34
34
  }(ShopifyError));
35
35
  exports.InvalidShopError = InvalidShopError;
36
+ var InvalidHostError = /** @class */ (function (_super) {
37
+ tslib_1.__extends(InvalidHostError, _super);
38
+ function InvalidHostError() {
39
+ return _super !== null && _super.apply(this, arguments) || this;
40
+ }
41
+ return InvalidHostError;
42
+ }(ShopifyError));
43
+ exports.InvalidHostError = InvalidHostError;
36
44
  var InvalidJwtError = /** @class */ (function (_super) {
37
45
  tslib_1.__extends(InvalidJwtError, _super);
38
46
  function InvalidJwtError() {
@@ -141,6 +149,17 @@ var RestResourceError = /** @class */ (function (_super) {
141
149
  return RestResourceError;
142
150
  }(ShopifyError));
143
151
  exports.RestResourceError = RestResourceError;
152
+ var GraphqlQueryError = /** @class */ (function (_super) {
153
+ tslib_1.__extends(GraphqlQueryError, _super);
154
+ function GraphqlQueryError(_a) {
155
+ var message = _a.message, response = _a.response;
156
+ var _this = _super.call(this, message) || this;
157
+ _this.response = response;
158
+ return _this;
159
+ }
160
+ return GraphqlQueryError;
161
+ }(ShopifyError));
162
+ exports.GraphqlQueryError = GraphqlQueryError;
144
163
  var InvalidOAuthError = /** @class */ (function (_super) {
145
164
  tslib_1.__extends(InvalidOAuthError, _super);
146
165
  function InvalidOAuthError() {
package/dist/index.d.ts CHANGED
@@ -37,7 +37,8 @@ export declare const Shopify: {
37
37
  safeCompare: typeof import("./utils/safe-compare").default;
38
38
  storeSession: typeof import("./utils/store-session").default;
39
39
  validateHmac: typeof import("./utils/hmac-validator").default;
40
- validateShop: typeof import("./utils/shop-validator").default;
40
+ sanitizeShop: typeof import("./utils/shop-validator").sanitizeShop;
41
+ sanitizeHost: typeof import("./utils/shop-validator").sanitizeHost;
41
42
  versionCompatible: typeof import("./utils/version-compatible").default;
42
43
  withSession: typeof import("./utils/with-session").default;
43
44
  getEmbeddedAppUrl: typeof import("./utils/get-embedded-app-url").default;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,aAAa,MAAM,SAAS,CAAC;AAOzC,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQnB,CAAC;AAEF,eAAe,OAAO,CAAC;AACvB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,aAAa,MAAM,SAAS,CAAC;AAOzC,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQnB,CAAC;AAEF,eAAe,OAAO,CAAC;AACvB,cAAc,SAAS,CAAC"}
@@ -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,CAChD,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,OAAO,CAAC,CAMlB"}
1
+ {"version":3,"file":"delete-offline-session.d.ts","sourceRoot":"","sources":["../../src/utils/delete-offline-session.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,wBAA8B,oBAAoB,CAChD,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,OAAO,CAAC,CAOlB"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
4
  var context_1 = require("../context");
5
5
  var oauth_1 = tslib_1.__importDefault(require("../auth/oauth"));
6
+ var shop_validator_1 = require("./shop-validator");
6
7
  /**
7
8
  * Helper method to find and delete offline sessions by shop url.
8
9
  *
@@ -10,10 +11,11 @@ var oauth_1 = tslib_1.__importDefault(require("../auth/oauth"));
10
11
  */
11
12
  function deleteOfflineSession(shop) {
12
13
  return tslib_1.__awaiter(this, void 0, void 0, function () {
13
- var sessionId;
14
+ var cleanShop, sessionId;
14
15
  return tslib_1.__generator(this, function (_a) {
15
16
  context_1.Context.throwIfUninitialized();
16
- sessionId = oauth_1.default.getOfflineSessionId(shop);
17
+ cleanShop = (0, shop_validator_1.sanitizeShop)(shop, true);
18
+ sessionId = oauth_1.default.getOfflineSessionId(cleanShop);
17
19
  return [2 /*return*/, context_1.Context.SESSION_STORAGE.deleteSession(sessionId)];
18
20
  });
19
21
  });
@@ -1 +1 @@
1
- {"version":3,"file":"get-embedded-app-url.d.ts","sourceRoot":"","sources":["../../src/utils/get-embedded-app-url.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAKxB;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,OAAO,EAAE,IAAI,CAAC,eAAe,GAC5B,MAAM,CAyBR"}
1
+ {"version":3,"file":"get-embedded-app-url.d.ts","sourceRoot":"","sources":["../../src/utils/get-embedded-app-url.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAOxB;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,OAAO,EAAE,IAAI,CAAC,eAAe,GAC5B,MAAM,CAyBR"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
4
  var ShopifyErrors = tslib_1.__importStar(require("../error"));
5
5
  var context_1 = require("../context");
6
+ var shop_validator_1 = require("./shop-validator");
6
7
  /**
7
8
  * Helper method to get the host URL for the app.
8
9
  *
@@ -17,7 +18,7 @@ function getEmbeddedAppUrl(request) {
17
18
  }
18
19
  var url = new URL(request.url, "https://".concat(request.headers.host));
19
20
  var host = url.searchParams.get('host');
20
- if (typeof host !== 'string') {
21
+ if (typeof host !== 'string' || !(0, shop_validator_1.sanitizeHost)(host)) {
21
22
  throw new ShopifyErrors.InvalidRequestError('Request does not contain a host query parameter');
22
23
  }
23
24
  var decodedHost = Buffer.from(host, 'base64').toString();
@@ -8,7 +8,7 @@ import graphqlProxy from './graphql_proxy';
8
8
  import safeCompare from './safe-compare';
9
9
  import storeSession from './store-session';
10
10
  import validateHmac from './hmac-validator';
11
- import validateShop from './shop-validator';
11
+ import { sanitizeShop, sanitizeHost } from './shop-validator';
12
12
  import versionCompatible from './version-compatible';
13
13
  import withSession from './with-session';
14
14
  import getEmbeddedAppUrl from './get-embedded-app-url';
@@ -23,7 +23,8 @@ declare const ShopifyUtils: {
23
23
  safeCompare: typeof safeCompare;
24
24
  storeSession: typeof storeSession;
25
25
  validateHmac: typeof validateHmac;
26
- validateShop: typeof validateShop;
26
+ sanitizeShop: typeof sanitizeShop;
27
+ sanitizeHost: typeof sanitizeHost;
27
28
  versionCompatible: typeof versionCompatible;
28
29
  withSession: typeof withSession;
29
30
  getEmbeddedAppUrl: typeof getEmbeddedAppUrl;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,wBAAwB,CAAC;AACxD,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAC5D,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAC5D,OAAO,kBAAkB,MAAM,wBAAwB,CAAC;AACxD,OAAO,kBAAkB,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,WAAW,MAAM,gBAAgB,CAAC;AACzC,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,iBAAiB,MAAM,sBAAsB,CAAC;AACrD,OAAO,WAAW,MAAM,gBAAgB,CAAC;AACzC,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AAEvD,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;CAejB,CAAC;AAEF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,wBAAwB,CAAC;AACxD,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAC5D,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAC5D,OAAO,kBAAkB,MAAM,wBAAwB,CAAC;AACxD,OAAO,kBAAkB,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,WAAW,MAAM,gBAAgB,CAAC;AACzC,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC5D,OAAO,iBAAiB,MAAM,sBAAsB,CAAC;AACrD,OAAO,WAAW,MAAM,gBAAgB,CAAC;AACzC,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AAEvD,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;CAgBjB,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -11,7 +11,7 @@ var graphql_proxy_1 = tslib_1.__importDefault(require("./graphql_proxy"));
11
11
  var safe_compare_1 = tslib_1.__importDefault(require("./safe-compare"));
12
12
  var store_session_1 = tslib_1.__importDefault(require("./store-session"));
13
13
  var hmac_validator_1 = tslib_1.__importDefault(require("./hmac-validator"));
14
- var shop_validator_1 = tslib_1.__importDefault(require("./shop-validator"));
14
+ var shop_validator_1 = require("./shop-validator");
15
15
  var version_compatible_1 = tslib_1.__importDefault(require("./version-compatible"));
16
16
  var with_session_1 = tslib_1.__importDefault(require("./with-session"));
17
17
  var get_embedded_app_url_1 = tslib_1.__importDefault(require("./get-embedded-app-url"));
@@ -26,7 +26,8 @@ var ShopifyUtils = {
26
26
  safeCompare: safe_compare_1.default,
27
27
  storeSession: store_session_1.default,
28
28
  validateHmac: hmac_validator_1.default,
29
- validateShop: shop_validator_1.default,
29
+ sanitizeShop: shop_validator_1.sanitizeShop,
30
+ sanitizeHost: shop_validator_1.sanitizeHost,
30
31
  versionCompatible: version_compatible_1.default,
31
32
  withSession: with_session_1.default,
32
33
  getEmbeddedAppUrl: get_embedded_app_url_1.default,
@@ -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,CAC9C,IAAI,EAAE,MAAM,EACZ,cAAc,UAAQ,GACrB,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAkB9B"}
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;AAMhD;;;;;;;GAOG;AACH,wBAA8B,kBAAkB,CAC9C,IAAI,EAAE,MAAM,EACZ,cAAc,UAAQ,GACrB,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAmB9B"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
4
  var context_1 = require("../context");
5
5
  var oauth_1 = tslib_1.__importDefault(require("../auth/oauth"));
6
+ var shop_validator_1 = require("./shop-validator");
6
7
  /**
7
8
  * Helper method for quickly loading offline sessions by shop url.
8
9
  * By default, returns undefined if there is no session, or the session found is expired.
@@ -14,12 +15,13 @@ var oauth_1 = tslib_1.__importDefault(require("../auth/oauth"));
14
15
  function loadOfflineSession(shop, includeExpired) {
15
16
  if (includeExpired === void 0) { includeExpired = false; }
16
17
  return tslib_1.__awaiter(this, void 0, void 0, function () {
17
- var sessionId, session, now;
18
+ var cleanShop, sessionId, session, now;
18
19
  return tslib_1.__generator(this, function (_a) {
19
20
  switch (_a.label) {
20
21
  case 0:
21
22
  context_1.Context.throwIfUninitialized();
22
- sessionId = oauth_1.default.getOfflineSessionId(shop);
23
+ cleanShop = (0, shop_validator_1.sanitizeShop)(shop, true);
24
+ sessionId = oauth_1.default.getOfflineSessionId(cleanShop);
23
25
  return [4 /*yield*/, context_1.Context.SESSION_STORAGE.loadSession(sessionId)];
24
26
  case 1:
25
27
  session = _a.sent();
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"setup-jest.d.ts","sourceRoot":"","sources":["../../src/utils/setup-jest.ts"],"names":[],"mappings":"AAuCA,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"}
@@ -19,6 +19,7 @@ beforeEach(function () {
19
19
  IS_EMBEDDED_APP: false,
20
20
  IS_PRIVATE_APP: false,
21
21
  SESSION_STORAGE: new session_1.MemorySessionStorage(),
22
+ CUSTOM_SHOP_DOMAINS: undefined,
22
23
  });
23
24
  jest_fetch_mock_1.default.mockReset();
24
25
  currentCall = 0;
@@ -1,7 +1,16 @@
1
1
  /**
2
- * Validates myshopify.com urls
2
+ * Validates and sanitizes shop domain urls. If Context.CUSTOM_SHOP_DOMAINS is set, shops ending in those domains are
3
+ * allowed. Accepts myshopify.com and myshopify.io by default.
3
4
  *
4
- * @param shop Shop url: {shop}.myshopify.com
5
+ * @param shop Shop url: {shop}.{domain}
6
+ * @param throwOnInvalid Whether to raise an exception if the shop is invalid
5
7
  */
6
- export default function validateShop(shop: string): boolean;
8
+ export declare function sanitizeShop(shop: string, throwOnInvalid?: boolean): string | null;
9
+ /**
10
+ * Validates and sanitizes Shopify host arguments.
11
+ *
12
+ * @param host Host address
13
+ * @param throwOnInvalid Whether to raise an exception if the host is invalid
14
+ */
15
+ export declare function sanitizeHost(host: string, throwOnInvalid?: boolean): string | null;
7
16
  //# sourceMappingURL=shop-validator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shop-validator.d.ts","sourceRoot":"","sources":["../../src/utils/shop-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAM1D"}
1
+ {"version":3,"file":"shop-validator.d.ts","sourceRoot":"","sources":["../../src/utils/shop-validator.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,cAAc,UAAQ,GACrB,MAAM,GAAG,IAAI,CAoBf;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,cAAc,UAAQ,GACrB,MAAM,GAAG,IAAI,CASf"}
@@ -1,13 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sanitizeHost = exports.sanitizeShop = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var error_1 = require("../error");
6
+ var context_1 = require("../context");
3
7
  /**
4
- * Validates myshopify.com urls
8
+ * Validates and sanitizes shop domain urls. If Context.CUSTOM_SHOP_DOMAINS is set, shops ending in those domains are
9
+ * allowed. Accepts myshopify.com and myshopify.io by default.
5
10
  *
6
- * @param shop Shop url: {shop}.myshopify.com
11
+ * @param shop Shop url: {shop}.{domain}
12
+ * @param throwOnInvalid Whether to raise an exception if the shop is invalid
7
13
  */
8
- function validateShop(shop) {
9
- console.warn('Deprecation notice: validateShop will be removed in the next major release.');
10
- var shopUrlRegex = /^[a-zA-Z0-9][a-zA-Z0-9-]*\.myshopify\.(com|io)[/]*$/;
11
- return shopUrlRegex.test(shop);
14
+ function sanitizeShop(shop, throwOnInvalid) {
15
+ if (throwOnInvalid === void 0) { throwOnInvalid = false; }
16
+ var domainsRegex = ['myshopify\\.com', 'myshopify\\.io'];
17
+ if (context_1.Context.CUSTOM_SHOP_DOMAINS) {
18
+ domainsRegex.push.apply(domainsRegex, tslib_1.__spreadArray([], tslib_1.__read(context_1.Context.CUSTOM_SHOP_DOMAINS.map(function (regex) {
19
+ return typeof regex === 'string' ? regex : regex.source;
20
+ })), false));
21
+ }
22
+ var shopUrlRegex = new RegExp("^[a-zA-Z0-9][a-zA-Z0-9-_]*\\.(".concat(domainsRegex.join('|'), ")[/]*$"));
23
+ var sanitizedShop = shopUrlRegex.test(shop) ? shop : null;
24
+ if (!sanitizedShop && throwOnInvalid) {
25
+ throw new error_1.InvalidShopError('Received invalid shop argument');
26
+ }
27
+ return sanitizedShop;
12
28
  }
13
- exports.default = validateShop;
29
+ exports.sanitizeShop = sanitizeShop;
30
+ /**
31
+ * Validates and sanitizes Shopify host arguments.
32
+ *
33
+ * @param host Host address
34
+ * @param throwOnInvalid Whether to raise an exception if the host is invalid
35
+ */
36
+ function sanitizeHost(host, throwOnInvalid) {
37
+ if (throwOnInvalid === void 0) { throwOnInvalid = false; }
38
+ var base64regex = /^[0-9a-zA-Z+/]+={0,2}$/;
39
+ var sanitizedHost = base64regex.test(host) ? host : null;
40
+ if (!sanitizedHost && throwOnInvalid) {
41
+ throw new error_1.InvalidHostError('Received invalid host argument');
42
+ }
43
+ return sanitizedHost;
44
+ }
45
+ exports.sanitizeHost = sanitizeHost;
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const SHOPIFY_API_LIBRARY_VERSION = "4.1.0";
1
+ export declare const SHOPIFY_API_LIBRARY_VERSION = "5.0.1";
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 = '4.1.0';
4
+ exports.SHOPIFY_API_LIBRARY_VERSION = '5.0.1';