@shopify/shopify-api 3.0.0 → 3.1.2

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 (115) hide show
  1. package/CHANGELOG.md +26 -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 +1 -0
  5. package/dist/__tests__/fake-resource.d.ts.map +1 -1
  6. package/dist/__tests__/fake-resource.js +16 -13
  7. package/dist/auth/oauth/oauth.d.ts.map +1 -1
  8. package/dist/auth/oauth/oauth.js +12 -15
  9. package/dist/auth/scopes/index.js +5 -5
  10. package/dist/auth/session/index.d.ts +11 -1
  11. package/dist/auth/session/index.d.ts.map +1 -1
  12. package/dist/auth/session/index.js +16 -1
  13. package/dist/auth/session/session-utils.d.ts +8 -0
  14. package/dist/auth/session/session-utils.d.ts.map +1 -0
  15. package/dist/auth/session/session-utils.js +104 -0
  16. package/dist/auth/session/storage/__tests__/battery-of-tests.d.ts +3 -0
  17. package/dist/auth/session/storage/__tests__/battery-of-tests.d.ts.map +1 -0
  18. package/dist/auth/session/storage/__tests__/battery-of-tests.js +180 -0
  19. package/dist/auth/session/storage/__tests__/utils.d.ts +10 -0
  20. package/dist/auth/session/storage/__tests__/utils.d.ts.map +1 -0
  21. package/dist/auth/session/storage/__tests__/utils.js +87 -0
  22. package/dist/auth/session/storage/custom.js +4 -4
  23. package/dist/auth/session/storage/mongodb.d.ts +23 -0
  24. package/dist/auth/session/storage/mongodb.d.ts.map +1 -0
  25. package/dist/auth/session/storage/mongodb.js +150 -0
  26. package/dist/auth/session/storage/mysql.d.ts +22 -0
  27. package/dist/auth/session/storage/mysql.d.ts.map +1 -0
  28. package/dist/auth/session/storage/mysql.js +154 -0
  29. package/dist/auth/session/storage/postgresql.d.ts +24 -0
  30. package/dist/auth/session/storage/postgresql.d.ts.map +1 -0
  31. package/dist/auth/session/storage/postgresql.js +172 -0
  32. package/dist/auth/session/storage/redis.d.ts +20 -0
  33. package/dist/auth/session/storage/redis.d.ts.map +1 -0
  34. package/dist/auth/session/storage/redis.js +105 -0
  35. package/dist/auth/session/storage/sqlite.d.ts +19 -0
  36. package/dist/auth/session/storage/sqlite.d.ts.map +1 -0
  37. package/dist/auth/session/storage/sqlite.js +128 -0
  38. package/dist/base-rest-resource.d.ts +3 -1
  39. package/dist/base-rest-resource.d.ts.map +1 -1
  40. package/dist/base-rest-resource.js +31 -19
  41. package/dist/base-types.d.ts +1 -0
  42. package/dist/base-types.d.ts.map +1 -1
  43. package/dist/clients/graphql/graphql_client.js +1 -1
  44. package/dist/clients/http_client/http_client.d.ts +1 -2
  45. package/dist/clients/http_client/http_client.d.ts.map +1 -1
  46. package/dist/clients/http_client/http_client.js +100 -103
  47. package/dist/clients/rest/rest_client.js +5 -3
  48. package/dist/context.d.ts +1 -0
  49. package/dist/context.d.ts.map +1 -1
  50. package/dist/context.js +13 -5
  51. package/dist/error.js +4 -3
  52. package/dist/index.d.ts +5 -0
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/rest-resources/2021-07/abandoned_checkout.d.ts +2 -2
  55. package/dist/rest-resources/2021-07/abandoned_checkout.d.ts.map +1 -1
  56. package/dist/rest-resources/2021-07/abandoned_checkout.js +2 -3
  57. package/dist/rest-resources/2021-07/article.d.ts +4 -1
  58. package/dist/rest-resources/2021-07/article.d.ts.map +1 -1
  59. package/dist/rest-resources/2021-07/article.js +7 -6
  60. package/dist/rest-resources/2021-07/gift_card_adjustment.js +1 -1
  61. package/dist/rest-resources/2021-07/index.js +2 -0
  62. package/dist/rest-resources/2021-07/variant.d.ts +1 -0
  63. package/dist/rest-resources/2021-07/variant.d.ts.map +1 -1
  64. package/dist/rest-resources/2021-07/variant.js +4 -0
  65. package/dist/rest-resources/2021-10/abandoned_checkout.d.ts +2 -2
  66. package/dist/rest-resources/2021-10/abandoned_checkout.d.ts.map +1 -1
  67. package/dist/rest-resources/2021-10/abandoned_checkout.js +2 -3
  68. package/dist/rest-resources/2021-10/article.d.ts +4 -1
  69. package/dist/rest-resources/2021-10/article.d.ts.map +1 -1
  70. package/dist/rest-resources/2021-10/article.js +7 -6
  71. package/dist/rest-resources/2021-10/gift_card_adjustment.js +1 -1
  72. package/dist/rest-resources/2021-10/index.js +2 -0
  73. package/dist/rest-resources/2021-10/variant.d.ts +1 -0
  74. package/dist/rest-resources/2021-10/variant.d.ts.map +1 -1
  75. package/dist/rest-resources/2021-10/variant.js +4 -0
  76. package/dist/rest-resources/2022-01/abandoned_checkout.d.ts +2 -2
  77. package/dist/rest-resources/2022-01/abandoned_checkout.d.ts.map +1 -1
  78. package/dist/rest-resources/2022-01/abandoned_checkout.js +2 -3
  79. package/dist/rest-resources/2022-01/article.d.ts +4 -1
  80. package/dist/rest-resources/2022-01/article.d.ts.map +1 -1
  81. package/dist/rest-resources/2022-01/article.js +7 -6
  82. package/dist/rest-resources/2022-01/gift_card_adjustment.js +1 -1
  83. package/dist/rest-resources/2022-01/index.js +2 -0
  84. package/dist/rest-resources/2022-01/variant.d.ts +1 -0
  85. package/dist/rest-resources/2022-01/variant.d.ts.map +1 -1
  86. package/dist/rest-resources/2022-01/variant.js +4 -0
  87. package/dist/rest-resources/2022-04/abandoned_checkout.d.ts +2 -2
  88. package/dist/rest-resources/2022-04/abandoned_checkout.d.ts.map +1 -1
  89. package/dist/rest-resources/2022-04/abandoned_checkout.js +2 -3
  90. package/dist/rest-resources/2022-04/article.d.ts +4 -1
  91. package/dist/rest-resources/2022-04/article.d.ts.map +1 -1
  92. package/dist/rest-resources/2022-04/article.js +7 -6
  93. package/dist/rest-resources/2022-04/gift_card_adjustment.js +1 -1
  94. package/dist/rest-resources/2022-04/index.js +2 -0
  95. package/dist/rest-resources/2022-04/variant.d.ts +1 -0
  96. package/dist/rest-resources/2022-04/variant.d.ts.map +1 -1
  97. package/dist/rest-resources/2022-04/variant.js +4 -0
  98. package/dist/utils/decode-session-token.d.ts.map +1 -1
  99. package/dist/utils/decode-session-token.js +1 -5
  100. package/dist/utils/graphql_proxy.js +1 -1
  101. package/dist/utils/hmac-validator.js +2 -5
  102. package/dist/utils/processed-query.js +3 -3
  103. package/dist/utils/safe-compare.d.ts.map +1 -1
  104. package/dist/utils/safe-compare.js +17 -15
  105. package/dist/utils/setup-jest.d.ts.map +1 -1
  106. package/dist/utils/setup-jest.js +4 -3
  107. package/dist/utils/shop-validator.d.ts.map +1 -1
  108. package/dist/utils/shop-validator.js +1 -0
  109. package/dist/utils/with-session.js +3 -3
  110. package/dist/version.d.ts +1 -1
  111. package/dist/version.js +1 -1
  112. package/dist/webhooks/registry.d.ts +2 -1
  113. package/dist/webhooks/registry.d.ts.map +1 -1
  114. package/dist/webhooks/registry.js +39 -13
  115. package/package.json +12 -4
@@ -1 +1 @@
1
- {"version":3,"file":"base-rest-resource.d.ts","sourceRoot":"","sources":["../src/base-rest-resource.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAW,gBAAgB,EAAC,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAGxC,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CACtC;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,IAAI;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WA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CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,IAAI,CAAA;KAAC,CAAM;IAEnE,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,CAAM;qBAErB,QAAQ,CAAC,EAC9B,OAAO,EACP,MAAM,EACN,MAAM,GACP,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;qBAeV,OAAO,CAAC,EAC7B,OAAO,EACP,WAAW,EACX,SAAS,EACT,MAAM,EACN,MAAM,EACN,IAAI,EACJ,MAAM,GACP,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA4C3C,SAAS,CAAC,MAAM,CAAC,eAAe,IAAI,MAAM;IAI1C,OAAO,CAAC,MAAM,CAAC,OAAO;IA+DtB,OAAO,CAAC,MAAM,CAAC,2BAA2B;IAmB1C,OAAO,CAAC,MAAM,CAAC,cAAc;IAgBtB,OAAO,EAAE,gBAAgB,CAAC;gBAErB,EAAC,OAAO,EAAE,QAAQ,EAAC,EAAE,mBAAmB;IAQvC,IAAI,CAAC,EAAC,MAAc,EAAC;;KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAsB1C,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAU7B,SAAS,CAAC,MAAM,UAAQ,GAAG,IAAI;IA0BtC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAwBnC,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,qBAAqB;CAO9B;AAED,eAAe,IAAI,CAAC"}
@@ -42,7 +42,7 @@ var Base = /** @class */ (function () {
42
42
  var client, path, cleanParams, key;
43
43
  return tslib_1.__generator(this, function (_b) {
44
44
  if (context_1.Context.API_VERSION !== this.API_VERSION) {
45
- throw new error_1.RestResourceError("Current Context.API_VERSION '" + context_1.Context.API_VERSION + "' does not match resource version " + this.API_VERSION);
45
+ throw new error_1.RestResourceError("Current Context.API_VERSION '".concat(context_1.Context.API_VERSION, "' does not match resource version ").concat(this.API_VERSION));
46
46
  }
47
47
  client = new rest_1.RestClient(session.shop, session.accessToken);
48
48
  path = this.getPath({ http_method: http_method, operation: operation, urlIds: urlIds, entity: entity });
@@ -74,7 +74,7 @@ var Base = /** @class */ (function () {
74
74
  case 'delete':
75
75
  return [2 /*return*/, client.delete({ path: path, query: cleanParams })];
76
76
  default:
77
- throw new Error("Unrecognized HTTP method \"" + http_method + "\"");
77
+ throw new Error("Unrecognized HTTP method \"".concat(http_method, "\""));
78
78
  }
79
79
  return [2 /*return*/];
80
80
  });
@@ -114,13 +114,13 @@ var Base = /** @class */ (function () {
114
114
  specificity = path.ids.length;
115
115
  match = path.path.replace(/(<([^>]+)>)/g,
116
116
  // eslint-disable-next-line @typescript-eslint/naming-convention
117
- function (_m1, _m2, id) { return "" + pathUrlIds[id]; });
117
+ function (_m1, _m2, id) { return "".concat(pathUrlIds[id]); });
118
118
  });
119
119
  if (!match) {
120
120
  throw new error_1.RestResourceError('Could not find a path for request');
121
121
  }
122
122
  if (this.CUSTOM_PREFIX) {
123
- return this.CUSTOM_PREFIX + "/" + match;
123
+ return "".concat(this.CUSTOM_PREFIX, "/").concat(match);
124
124
  }
125
125
  else {
126
126
  return match;
@@ -148,26 +148,26 @@ var Base = /** @class */ (function () {
148
148
  return instance;
149
149
  };
150
150
  Base.prototype.save = function (_a) {
151
- var _b = (_a === void 0 ? {} : _a).update, update = _b === void 0 ? false : _b;
151
+ var _b = _a === void 0 ? {} : _a, _c = _b.update, update = _c === void 0 ? false : _c;
152
152
  return tslib_1.__awaiter(this, void 0, void 0, function () {
153
- var _c, PRIMARY_KEY, NAME, method, data, response, body;
154
- var _d;
155
- return tslib_1.__generator(this, function (_e) {
156
- switch (_e.label) {
153
+ var _d, PRIMARY_KEY, NAME, method, data, response, body;
154
+ var _e;
155
+ return tslib_1.__generator(this, function (_f) {
156
+ switch (_f.label) {
157
157
  case 0:
158
- _c = this.resource(), PRIMARY_KEY = _c.PRIMARY_KEY, NAME = _c.NAME;
158
+ _d = this.resource(), PRIMARY_KEY = _d.PRIMARY_KEY, NAME = _d.NAME;
159
159
  method = this[PRIMARY_KEY] ? 'put' : 'post';
160
- data = this.serialize();
160
+ data = this.serialize(true);
161
161
  return [4 /*yield*/, this.resource().request({
162
162
  http_method: method,
163
163
  operation: method,
164
164
  session: this.session,
165
165
  urlIds: {},
166
- body: (_d = {}, _d[this.resource().getJsonBodyName()] = data, _d),
166
+ body: (_e = {}, _e[this.resource().getJsonBodyName()] = data, _e),
167
167
  entity: this,
168
168
  })];
169
169
  case 1:
170
- response = _e.sent();
170
+ response = _f.sent();
171
171
  body = response.body[NAME];
172
172
  if (update && body) {
173
173
  this.setData(body);
@@ -207,20 +207,24 @@ var Base = /** @class */ (function () {
207
207
  });
208
208
  });
209
209
  };
210
- Base.prototype.serialize = function () {
211
- var _a = this.resource(), HAS_MANY = _a.HAS_MANY, HAS_ONE = _a.HAS_ONE;
210
+ Base.prototype.serialize = function (saving) {
211
+ var _this = this;
212
+ if (saving === void 0) { saving = false; }
213
+ var _a = this.resource(), HAS_MANY = _a.HAS_MANY, HAS_ONE = _a.HAS_ONE, READ_ONLY_ATTRIBUTES = _a.READ_ONLY_ATTRIBUTES;
212
214
  return Object.entries(this).reduce(function (acc, _a) {
213
215
  var _b = tslib_1.__read(_a, 2), attribute = _b[0], value = _b[1];
214
- if (['session'].includes(attribute)) {
216
+ if (saving &&
217
+ (['session'].includes(attribute) ||
218
+ READ_ONLY_ATTRIBUTES.includes(attribute))) {
215
219
  return acc;
216
220
  }
217
221
  if (attribute in HAS_MANY && value) {
218
222
  acc[attribute] = value.reduce(function (attrAcc, entry) {
219
- return attrAcc.concat(entry.serialize ? entry.serialize() : entry);
223
+ return attrAcc.concat(_this.serializeSubAttribute(entry, saving));
220
224
  }, []);
221
225
  }
222
- else if (attribute in HAS_ONE && value && value.serialize) {
223
- acc[attribute] = value.serialize();
226
+ else if (attribute in HAS_ONE && value) {
227
+ acc[attribute] = _this.serializeSubAttribute(value, saving);
224
228
  }
225
229
  else {
226
230
  acc[attribute] = value;
@@ -255,10 +259,18 @@ var Base = /** @class */ (function () {
255
259
  Base.prototype.resource = function () {
256
260
  return this.constructor;
257
261
  };
262
+ Base.prototype.serializeSubAttribute = function (attribute, saving) {
263
+ return attribute.serialize
264
+ ? attribute.serialize(saving)
265
+ : this.resource()
266
+ .createInstance(this.session, attribute)
267
+ .serialize(saving);
268
+ };
258
269
  Base.NAME = '';
259
270
  Base.PLURAL_NAME = '';
260
271
  Base.PRIMARY_KEY = 'id';
261
272
  Base.CUSTOM_PREFIX = null;
273
+ Base.READ_ONLY_ATTRIBUTES = [];
262
274
  Base.HAS_ONE = {};
263
275
  Base.HAS_MANY = {};
264
276
  Base.PATHS = [];
@@ -5,6 +5,7 @@ export interface ContextParams {
5
5
  API_SECRET_KEY: string;
6
6
  SCOPES: string[] | AuthScopes;
7
7
  HOST_NAME: string;
8
+ HOST_SCHEME?: string;
8
9
  API_VERSION: ApiVersion;
9
10
  IS_EMBEDDED_APP: boolean;
10
11
  IS_PRIVATE_APP?: boolean;
@@ -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,EAAE,UAAU,CAAC;IACxB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mCAAmC,CAAC,EAAE,MAAM,CAAC;CAC9C;AAED,oBAAY,UAAU;IACpB,MAAM,YAAY;IAClB,SAAS,YAAY;IACrB,SAAS,YAAY;IACrB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED,oBAAY,aAAa;IACvB,WAAW,2BAA2B;IACtC,qBAAqB,sCAAsC;IAC3D,IAAI,0BAA0B;IAC9B,KAAK,oBAAoB;IACzB,MAAM,0BAA0B;CACjC"}
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;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mCAAmC,CAAC,EAAE,MAAM,CAAC;CAC9C;AAED,oBAAY,UAAU;IACpB,MAAM,YAAY;IAClB,SAAS,YAAY;IACrB,SAAS,YAAY;IACrB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED,oBAAY,aAAa;IACvB,WAAW,2BAA2B;IACtC,qBAAqB,sCAAsC;IAC3D,IAAI,0BAA0B;IAC9B,KAAK,oBAAoB;IACzB,MAAM,0BAA0B;CACjC"}
@@ -28,7 +28,7 @@ var GraphqlClient = /** @class */ (function () {
28
28
  }
29
29
  accessTokenHeader = this.getAccessTokenHeader();
30
30
  params.extraHeaders = tslib_1.__assign((_a = {}, _a[accessTokenHeader.header] = accessTokenHeader.value, _a), params.extraHeaders);
31
- path = this.baseApiPath + "/" + context_1.Context.API_VERSION + "/graphql.json";
31
+ path = "".concat(this.baseApiPath, "/").concat(context_1.Context.API_VERSION, "/graphql.json");
32
32
  if (typeof params.data === 'object') {
33
33
  dataType = types_1.DataType.JSON;
34
34
  }
@@ -1,5 +1,5 @@
1
1
  import { DeleteRequestParams, GetRequestParams, PostRequestParams, PutRequestParams, RequestParams, RequestReturn } from './types';
2
- declare class HttpClient {
2
+ export declare class HttpClient {
3
3
  private domain;
4
4
  static readonly RETRY_WAIT_TIME = 1000;
5
5
  static readonly DEPRECATION_ALERT_DELAY = 300000;
@@ -25,5 +25,4 @@ declare class HttpClient {
25
25
  protected getRequestPath(path: string): string;
26
26
  private doRequest;
27
27
  }
28
- export { HttpClient };
29
28
  //# sourceMappingURL=http_client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"http_client.d.ts","sourceRoot":"","sources":["../../../src/clients/http_client/http_client.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB,cAAM,UAAU;IAOK,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;IAQzC;;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,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.__importDefault(require("node-fetch"));
9
9
  var network_1 = require("@shopify/network");
10
10
  var ShopifyErrors = tslib_1.__importStar(require("../../error"));
11
11
  var version_1 = require("../../version");
12
- var shop_validator_1 = tslib_1.__importDefault(require("../../utils/shop-validator"));
13
12
  var context_1 = require("../../context");
14
13
  var processed_query_1 = tslib_1.__importDefault(require("../../utils/processed-query"));
15
14
  var types_1 = require("./types");
@@ -17,9 +16,6 @@ var HttpClient = /** @class */ (function () {
17
16
  function HttpClient(domain) {
18
17
  this.domain = domain;
19
18
  this.LOGGED_DEPRECATIONS = {};
20
- if (!shop_validator_1.default(domain)) {
21
- throw new ShopifyErrors.InvalidShopError("Domain " + domain + " is not valid");
22
- }
23
19
  this.domain = domain;
24
20
  }
25
21
  /**
@@ -77,19 +73,19 @@ var HttpClient = /** @class */ (function () {
77
73
  case 0:
78
74
  maxTries = params.tries ? params.tries : 1;
79
75
  if (maxTries <= 0) {
80
- throw new ShopifyErrors.HttpRequestError("Number of tries must be >= 0, got " + maxTries);
76
+ throw new ShopifyErrors.HttpRequestError("Number of tries must be >= 0, got ".concat(maxTries));
81
77
  }
82
- userAgent = "Shopify API Library v" + version_1.SHOPIFY_API_LIBRARY_VERSION + " | Node " + process.version;
78
+ userAgent = "Shopify API Library v".concat(version_1.SHOPIFY_API_LIBRARY_VERSION, " | Node ").concat(process.version);
83
79
  if (context_1.Context.USER_AGENT_PREFIX) {
84
- userAgent = context_1.Context.USER_AGENT_PREFIX + " | " + userAgent;
80
+ userAgent = "".concat(context_1.Context.USER_AGENT_PREFIX, " | ").concat(userAgent);
85
81
  }
86
82
  if (params.extraHeaders) {
87
83
  if (params.extraHeaders['user-agent']) {
88
- userAgent = params.extraHeaders['user-agent'] + " | " + userAgent;
84
+ userAgent = "".concat(params.extraHeaders['user-agent'], " | ").concat(userAgent);
89
85
  delete params.extraHeaders['user-agent'];
90
86
  }
91
87
  else if (params.extraHeaders['User-Agent']) {
92
- userAgent = params.extraHeaders['User-Agent'] + " | " + userAgent;
88
+ userAgent = "".concat(params.extraHeaders['User-Agent'], " | ").concat(userAgent);
93
89
  }
94
90
  }
95
91
  headers = tslib_1.__assign(tslib_1.__assign({}, params.extraHeaders), { 'User-Agent': userAgent });
@@ -114,7 +110,7 @@ var HttpClient = /** @class */ (function () {
114
110
  headers = tslib_1.__assign({ 'Content-Type': type, 'Content-Length': Buffer.byteLength(body) }, params.extraHeaders);
115
111
  }
116
112
  }
117
- url = "https://" + this.domain + this.getRequestPath(params.path) + processed_query_1.default.stringify(params.query);
113
+ url = "https://".concat(this.domain).concat(this.getRequestPath(params.path)).concat(processed_query_1.default.stringify(params.query));
118
114
  options = {
119
115
  method: params.method.toString(),
120
116
  headers: headers,
@@ -146,7 +142,7 @@ var HttpClient = /** @class */ (function () {
146
142
  case 6:
147
143
  // We're set to multiple tries but ran out
148
144
  if (maxTries > 1) {
149
- throw new ShopifyErrors.HttpMaxRetriesError("Exceeded maximum retry count of " + maxTries + ". Last message: " + error_1.message);
145
+ throw new ShopifyErrors.HttpMaxRetriesError("Exceeded maximum retry count of ".concat(maxTries, ". Last message: ").concat(error_1.message));
150
146
  }
151
147
  _b.label = 7;
152
148
  case 7:
@@ -162,109 +158,110 @@ var HttpClient = /** @class */ (function () {
162
158
  });
163
159
  };
164
160
  HttpClient.prototype.getRequestPath = function (path) {
165
- return "/" + path.replace(/^\//, '');
161
+ return "/".concat(path.replace(/^\//, ''));
166
162
  };
167
163
  HttpClient.prototype.doRequest = function (url, options) {
168
164
  return tslib_1.__awaiter(this, void 0, void 0, function () {
169
- var _this = this;
165
+ var response, body, deprecation, depHash, stack, log, errorMessages, errorMessage, headers, code, statusText, retryAfter, error_2;
170
166
  return tslib_1.__generator(this, function (_a) {
171
- return [2 /*return*/, node_fetch_1.default(url, options)
172
- .then(function (response) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
173
- var body, deprecation, depHash, stack, log, errorMessages, errorMessage, headers, code, statusText, retryAfter;
174
- return tslib_1.__generator(this, function (_a) {
175
- switch (_a.label) {
176
- case 0: return [4 /*yield*/, response.json()];
177
- case 1:
178
- body = _a.sent();
179
- if (response.ok) {
180
- if (response.headers &&
181
- response.headers.has('X-Shopify-API-Deprecated-Reason')) {
182
- deprecation = {
183
- message: response.headers.get('X-Shopify-API-Deprecated-Reason'),
184
- path: url,
185
- };
186
- depHash = crypto_1.default
187
- .createHash('md5')
188
- .update(JSON.stringify(deprecation))
189
- .digest('hex');
190
- if (!Object.keys(this.LOGGED_DEPRECATIONS).includes(depHash) ||
191
- Date.now() - this.LOGGED_DEPRECATIONS[depHash] >=
192
- HttpClient.DEPRECATION_ALERT_DELAY) {
193
- this.LOGGED_DEPRECATIONS[depHash] = Date.now();
194
- if (context_1.Context.LOG_FILE) {
195
- stack = new Error().stack;
196
- log = "API Deprecation Notice " + new Date().toLocaleString() + " : " + JSON.stringify(deprecation) + "\n Stack Trace: " + stack + "\n";
197
- fs_1.default.writeFileSync(context_1.Context.LOG_FILE, log, {
198
- flag: 'a',
199
- encoding: 'utf-8',
200
- });
201
- }
202
- else {
203
- console.warn('API Deprecation Notice:', deprecation);
204
- }
205
- }
206
- }
207
- return [2 /*return*/, {
208
- body: body,
209
- headers: response.headers,
210
- }];
167
+ switch (_a.label) {
168
+ case 0:
169
+ _a.trys.push([0, 3, , 4]);
170
+ return [4 /*yield*/, (0, node_fetch_1.default)(url, options)];
171
+ case 1:
172
+ response = _a.sent();
173
+ return [4 /*yield*/, response.json().catch(function () { return ({}); })];
174
+ case 2:
175
+ body = _a.sent();
176
+ if (response.ok) {
177
+ if (response.headers &&
178
+ response.headers.has('X-Shopify-API-Deprecated-Reason')) {
179
+ deprecation = {
180
+ message: response.headers.get('X-Shopify-API-Deprecated-Reason'),
181
+ path: url,
182
+ };
183
+ depHash = crypto_1.default
184
+ .createHash('md5')
185
+ .update(JSON.stringify(deprecation))
186
+ .digest('hex');
187
+ if (!Object.keys(this.LOGGED_DEPRECATIONS).includes(depHash) ||
188
+ Date.now() - this.LOGGED_DEPRECATIONS[depHash] >=
189
+ HttpClient.DEPRECATION_ALERT_DELAY) {
190
+ this.LOGGED_DEPRECATIONS[depHash] = Date.now();
191
+ if (context_1.Context.LOG_FILE) {
192
+ stack = new Error().stack;
193
+ log = "API Deprecation Notice ".concat(new Date().toLocaleString(), " : ").concat(JSON.stringify(deprecation), "\n Stack Trace: ").concat(stack, "\n");
194
+ fs_1.default.writeFileSync(context_1.Context.LOG_FILE, log, {
195
+ flag: 'a',
196
+ encoding: 'utf-8',
197
+ });
211
198
  }
212
199
  else {
213
- errorMessages = [];
214
- if (body.errors) {
215
- errorMessages.push(JSON.stringify(body.errors, null, 2));
216
- }
217
- if (response.headers && response.headers.get('x-request-id')) {
218
- errorMessages.push("If you report this error, please include this id: " + response.headers.get('x-request-id'));
219
- }
220
- errorMessage = errorMessages.length
221
- ? ":\n" + errorMessages.join('\n')
222
- : '';
223
- headers = response.headers.raw();
224
- code = response.status;
225
- statusText = response.statusText;
226
- switch (true) {
227
- case response.status === network_1.StatusCode.TooManyRequests: {
228
- retryAfter = response.headers.get('Retry-After');
229
- throw new ShopifyErrors.HttpThrottlingError({
230
- message: "Shopify is throttling requests" + errorMessage,
231
- code: code,
232
- statusText: statusText,
233
- body: body,
234
- headers: headers,
235
- retryAfter: retryAfter ? parseFloat(retryAfter) : undefined,
236
- });
237
- }
238
- case response.status >= network_1.StatusCode.InternalServerError:
239
- throw new ShopifyErrors.HttpInternalError({
240
- message: "Shopify internal error" + errorMessage,
241
- code: code,
242
- statusText: statusText,
243
- body: body,
244
- headers: headers,
245
- });
246
- default:
247
- throw new ShopifyErrors.HttpResponseError({
248
- message: "Received an error response (" + response.status + " " + response.statusText + ") from Shopify" + errorMessage,
249
- code: code,
250
- statusText: statusText,
251
- body: body,
252
- headers: headers,
253
- });
254
- }
200
+ console.warn('API Deprecation Notice:', deprecation);
255
201
  }
256
- return [2 /*return*/];
202
+ }
203
+ }
204
+ return [2 /*return*/, {
205
+ body: body,
206
+ headers: response.headers,
207
+ }];
208
+ }
209
+ else {
210
+ errorMessages = [];
211
+ if (body.errors) {
212
+ errorMessages.push(JSON.stringify(body.errors, null, 2));
213
+ }
214
+ if (response.headers && response.headers.get('x-request-id')) {
215
+ errorMessages.push("If you report this error, please include this id: ".concat(response.headers.get('x-request-id')));
216
+ }
217
+ errorMessage = errorMessages.length
218
+ ? ":\n".concat(errorMessages.join('\n'))
219
+ : '';
220
+ headers = response.headers.raw();
221
+ code = response.status;
222
+ statusText = response.statusText;
223
+ switch (true) {
224
+ case response.status === network_1.StatusCode.TooManyRequests: {
225
+ retryAfter = response.headers.get('Retry-After');
226
+ throw new ShopifyErrors.HttpThrottlingError({
227
+ message: "Shopify is throttling requests".concat(errorMessage),
228
+ code: code,
229
+ statusText: statusText,
230
+ body: body,
231
+ headers: headers,
232
+ retryAfter: retryAfter ? parseFloat(retryAfter) : undefined,
233
+ });
234
+ }
235
+ case response.status >= network_1.StatusCode.InternalServerError:
236
+ throw new ShopifyErrors.HttpInternalError({
237
+ message: "Shopify internal error".concat(errorMessage),
238
+ code: code,
239
+ statusText: statusText,
240
+ body: body,
241
+ headers: headers,
242
+ });
243
+ default:
244
+ throw new ShopifyErrors.HttpResponseError({
245
+ message: "Received an error response (".concat(response.status, " ").concat(response.statusText, ") from Shopify").concat(errorMessage),
246
+ code: code,
247
+ statusText: statusText,
248
+ body: body,
249
+ headers: headers,
250
+ });
257
251
  }
258
- });
259
- }); })
260
- .catch(function (error) {
261
- if (error instanceof ShopifyErrors.ShopifyError) {
262
- throw error;
252
+ }
253
+ return [3 /*break*/, 4];
254
+ case 3:
255
+ error_2 = _a.sent();
256
+ if (error_2 instanceof ShopifyErrors.ShopifyError) {
257
+ throw error_2;
263
258
  }
264
259
  else {
265
- throw new ShopifyErrors.HttpRequestError("Failed to make Shopify HTTP request: " + error);
260
+ throw new ShopifyErrors.HttpRequestError("Failed to make Shopify HTTP request: ".concat(error_2));
266
261
  }
267
- })];
262
+ return [3 /*break*/, 4];
263
+ case 4: return [2 /*return*/];
264
+ }
268
265
  });
269
266
  });
270
267
  };
@@ -34,7 +34,9 @@ var RestClient = /** @class */ (function (_super) {
34
34
  link = ret.headers.get('link');
35
35
  if (link !== undefined) {
36
36
  pageInfo = {
37
- limit: ((_a = params.query) === null || _a === void 0 ? void 0 : _a.limit) ? (_b = params.query) === null || _b === void 0 ? void 0 : _b.limit.toString() : RestClient.DEFAULT_LIMIT,
37
+ limit: ((_a = params.query) === null || _a === void 0 ? void 0 : _a.limit)
38
+ ? (_b = params.query) === null || _b === void 0 ? void 0 : _b.limit.toString()
39
+ : RestClient.DEFAULT_LIMIT,
38
40
  };
39
41
  if (link) {
40
42
  links = link.split(', ');
@@ -84,10 +86,10 @@ var RestClient = /** @class */ (function (_super) {
84
86
  RestClient.prototype.getRequestPath = function (path) {
85
87
  var cleanPath = _super.prototype.getRequestPath.call(this, path);
86
88
  if (cleanPath.startsWith('/admin')) {
87
- return cleanPath.replace(/\.json$/, '') + ".json";
89
+ return "".concat(cleanPath.replace(/\.json$/, ''), ".json");
88
90
  }
89
91
  else {
90
- return "/admin/api/" + context_1.Context.API_VERSION + cleanPath.replace(/\.json$/, '') + ".json";
92
+ return "/admin/api/".concat(context_1.Context.API_VERSION).concat(cleanPath.replace(/\.json$/, ''), ".json");
91
93
  }
92
94
  };
93
95
  RestClient.prototype.buildRequestParams = function (newPageUrl) {
package/dist/context.d.ts CHANGED
@@ -2,6 +2,7 @@ import { SessionStorage } from './auth/session/session_storage';
2
2
  import { ContextParams } from './base-types';
3
3
  import { AuthScopes } from './auth/scopes';
4
4
  interface ContextInterface extends ContextParams {
5
+ HOST_SCHEME: string;
5
6
  SESSION_STORAGE: SessionStorage;
6
7
  SCOPES: AuthScopes;
7
8
  /**
@@ -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,gBAgFd,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,gBAqFd,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,gBAAgB,EAAC,CAAC"}
package/dist/context.js CHANGED
@@ -2,20 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Context = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ var path_1 = tslib_1.__importDefault(require("path"));
5
6
  var ShopifyErrors = tslib_1.__importStar(require("./error"));
6
- var memory_1 = require("./auth/session/storage/memory");
7
+ var sqlite_1 = require("./auth/session/storage/sqlite");
7
8
  var base_types_1 = require("./base-types");
8
9
  var scopes_1 = require("./auth/scopes");
10
+ var dbFile = path_1.default.join(require.main ? path_1.default.dirname(require.main.filename) : process.cwd(), 'database.sqlite');
9
11
  var Context = {
10
12
  API_KEY: '',
11
13
  API_SECRET_KEY: '',
12
14
  SCOPES: new scopes_1.AuthScopes([]),
13
15
  HOST_NAME: '',
16
+ HOST_SCHEME: 'https',
14
17
  API_VERSION: base_types_1.ApiVersion.Unstable,
15
18
  IS_EMBEDDED_APP: true,
16
19
  IS_PRIVATE_APP: false,
17
- SESSION_STORAGE: new memory_1.MemorySessionStorage(),
20
+ // TS hack as SESSION_STORAGE is guaranteed to be set
21
+ // to a correct value in `initialize()`.
22
+ SESSION_STORAGE: null,
18
23
  initialize: function (params) {
24
+ var _a;
19
25
  var scopes;
20
26
  if (params.SCOPES instanceof scopes_1.AuthScopes) {
21
27
  scopes = params.SCOPES;
@@ -38,7 +44,7 @@ var Context = {
38
44
  missing.push('HOST_NAME');
39
45
  }
40
46
  if (missing.length) {
41
- throw new ShopifyErrors.ShopifyError("Cannot initialize Shopify API Library. Missing values for: " + missing.join(', '));
47
+ throw new ShopifyErrors.ShopifyError("Cannot initialize Shopify API Library. Missing values for: ".concat(missing.join(', ')));
42
48
  }
43
49
  this.API_KEY = params.API_KEY;
44
50
  this.API_SECRET_KEY = params.API_SECRET_KEY;
@@ -47,8 +53,10 @@ var Context = {
47
53
  this.API_VERSION = params.API_VERSION;
48
54
  this.IS_EMBEDDED_APP = params.IS_EMBEDDED_APP;
49
55
  this.IS_PRIVATE_APP = params.IS_PRIVATE_APP;
50
- if (params.SESSION_STORAGE) {
51
- this.SESSION_STORAGE = params.SESSION_STORAGE;
56
+ this.SESSION_STORAGE =
57
+ (_a = params.SESSION_STORAGE) !== null && _a !== void 0 ? _a : new sqlite_1.SQLiteSessionStorage(dbFile);
58
+ if (params.HOST_SCHEME) {
59
+ this.HOST_SCHEME = params.HOST_SCHEME;
52
60
  }
53
61
  if (params.USER_AGENT_PREFIX) {
54
62
  this.USER_AGENT_PREFIX = params.USER_AGENT_PREFIX;
package/dist/error.js CHANGED
@@ -5,12 +5,12 @@ var tslib_1 = require("tslib");
5
5
  var ShopifyError = /** @class */ (function (_super) {
6
6
  tslib_1.__extends(ShopifyError, _super);
7
7
  function ShopifyError() {
8
- var _newTarget = this.constructor;
9
8
  var args = [];
10
9
  for (var _i = 0; _i < arguments.length; _i++) {
11
10
  args[_i] = arguments[_i];
12
11
  }
13
- var _this = _super.apply(this, tslib_1.__spread(args)) || this;
12
+ var _newTarget = this.constructor;
13
+ var _this = _super.apply(this, tslib_1.__spreadArray([], tslib_1.__read(args), false)) || this;
14
14
  Object.setPrototypeOf(_this, _newTarget.prototype);
15
15
  return _this;
16
16
  }
@@ -124,8 +124,9 @@ exports.HttpInternalError = HttpInternalError;
124
124
  var HttpThrottlingError = /** @class */ (function (_super) {
125
125
  tslib_1.__extends(HttpThrottlingError, _super);
126
126
  function HttpThrottlingError(_a) {
127
+ var _this = this;
127
128
  var retryAfter = _a.retryAfter, params = tslib_1.__rest(_a, ["retryAfter"]);
128
- var _this = _super.call(this, params) || this;
129
+ _this = _super.call(this, params) || this;
129
130
  _this.response.retryAfter = retryAfter;
130
131
  return _this;
131
132
  }
package/dist/index.d.ts CHANGED
@@ -15,6 +15,11 @@ export declare const Shopify: {
15
15
  Session: typeof import("./auth/session/session").Session;
16
16
  MemorySessionStorage: typeof import("./auth/session").MemorySessionStorage;
17
17
  CustomSessionStorage: typeof import("./auth/session").CustomSessionStorage;
18
+ MySQLSessionStorage: typeof import("./auth/session").MySQLSessionStorage;
19
+ MongoDBSessionStorage: typeof import("./auth/session").MongoDBSessionStorage;
20
+ PostgreSQLSessionStorage: typeof import("./auth/session").PostgreSQLSessionStorage;
21
+ RedisSessionStorage: typeof import("./auth/session").RedisSessionStorage;
22
+ SQLiteSessionStorage: typeof import("./auth/session").SQLiteSessionStorage;
18
23
  };
19
24
  Clients: {
20
25
  Rest: typeof import("./clients/rest/rest_client").RestClient;
@@ -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"}
@@ -7,13 +7,13 @@ import { DiscountCode } from './discount_code';
7
7
  interface CheckoutsArgs {
8
8
  [key: string]: unknown;
9
9
  session: SessionInterface;
10
+ limit?: unknown;
10
11
  since_id?: unknown;
11
12
  created_at_min?: unknown;
12
13
  created_at_max?: unknown;
13
14
  updated_at_min?: unknown;
14
15
  updated_at_max?: unknown;
15
16
  status?: unknown;
16
- limit?: unknown;
17
17
  }
18
18
  export declare class AbandonedCheckout extends Base {
19
19
  static API_VERSION: ApiVersion;
@@ -26,7 +26,7 @@ export declare class AbandonedCheckout extends Base {
26
26
  [key: string]: typeof Base;
27
27
  };
28
28
  protected static PATHS: ResourcePath[];
29
- static checkouts({ session, since_id, created_at_min, created_at_max, updated_at_min, updated_at_max, status, limit, ...otherArgs }: CheckoutsArgs): Promise<unknown>;
29
+ static checkouts({ session, limit, since_id, created_at_min, created_at_max, updated_at_min, updated_at_max, status, ...otherArgs }: CheckoutsArgs): Promise<unknown>;
30
30
  abandoned_checkout_url: string | null;
31
31
  billing_address: {
32
32
  [key: string]: unknown;