@shopify/shopify-api 5.0.1 → 5.1.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 +7 -0
  2. package/README.md +1 -0
  3. package/dist/auth/oauth/oauth.d.ts +2 -0
  4. package/dist/auth/oauth/oauth.d.ts.map +1 -1
  5. package/dist/auth/oauth/oauth.js +120 -95
  6. package/dist/auth/session/storage/redis.d.ts +1 -0
  7. package/dist/auth/session/storage/redis.d.ts.map +1 -1
  8. package/dist/auth/session/storage/redis.js +3 -0
  9. package/dist/base-types.d.ts +2 -0
  10. package/dist/base-types.d.ts.map +1 -1
  11. package/dist/billing/check.d.ts +12 -0
  12. package/dist/billing/check.d.ts.map +1 -0
  13. package/dist/billing/check.js +34 -0
  14. package/dist/billing/has_active_payment.d.ts +3 -0
  15. package/dist/billing/has_active_payment.d.ts.map +1 -0
  16. package/dist/billing/has_active_payment.js +91 -0
  17. package/dist/billing/index.d.ts +7 -0
  18. package/dist/billing/index.d.ts.map +1 -0
  19. package/dist/billing/index.js +9 -0
  20. package/dist/billing/is_recurring.d.ts +2 -0
  21. package/dist/billing/is_recurring.d.ts.map +1 -0
  22. package/dist/billing/is_recurring.js +20 -0
  23. package/dist/billing/request_payment.d.ts +3 -0
  24. package/dist/billing/request_payment.d.ts.map +1 -0
  25. package/dist/billing/request_payment.js +134 -0
  26. package/dist/billing/types.d.ts +57 -0
  27. package/dist/billing/types.d.ts.map +1 -0
  28. package/dist/billing/types.js +9 -0
  29. package/dist/clients/graphql/graphql_client.d.ts +1 -1
  30. package/dist/clients/graphql/graphql_client.d.ts.map +1 -1
  31. package/dist/clients/http_client/http_client.d.ts +5 -5
  32. package/dist/clients/http_client/http_client.d.ts.map +1 -1
  33. package/dist/clients/http_client/types.d.ts +2 -2
  34. package/dist/clients/http_client/types.d.ts.map +1 -1
  35. package/dist/clients/rest/rest_client.d.ts +1 -1
  36. package/dist/clients/rest/rest_client.d.ts.map +1 -1
  37. package/dist/clients/rest/rest_client.js +1 -1
  38. package/dist/clients/rest/types.d.ts +1 -1
  39. package/dist/clients/rest/types.d.ts.map +1 -1
  40. package/dist/context.d.ts.map +1 -1
  41. package/dist/context.js +3 -0
  42. package/dist/error.d.ts +7 -0
  43. package/dist/error.d.ts.map +1 -1
  44. package/dist/error.js +13 -1
  45. package/dist/index.d.ts +4 -0
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +2 -0
  48. package/dist/types.d.ts +1 -0
  49. package/dist/types.d.ts.map +1 -1
  50. package/dist/types.js +1 -0
  51. package/dist/utils/decode-session-token.js +1 -1
  52. package/dist/utils/get-embedded-app-url.d.ts +1 -0
  53. package/dist/utils/get-embedded-app-url.d.ts.map +1 -1
  54. package/dist/utils/get-embedded-app-url.js +8 -2
  55. package/dist/utils/setup-jest.d.ts.map +1 -1
  56. package/dist/utils/setup-jest.js +1 -0
  57. package/dist/version.d.ts +1 -1
  58. package/dist/version.js +1 -1
  59. package/dist/webhooks/registry.js +1 -1
  60. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -7,6 +7,13 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## [5.1.0] - 2022-09-19
11
+
12
+ - Increased tolerance for expired JWT session tokens from 5s to 10s [#462](https://github.com/Shopify/shopify-api-node/pull/462)
13
+ - Add support for billing to the library [#449](https://github.com/Shopify/shopify-api-node/pull/449)
14
+ - Allow dynamically typing the body of REST and GraphQL request responses, so callers don't need to cast it [#447](https://github.com/Shopify/shopify-api-node/pull/447)
15
+ - Rather than create a temporary session in order to store a session id in a cookie for the OAuth transaction, we can store the `state` in the cookie instead, that can then be compared against the `state` provided by Shopify in the callback. [#438](https://github.com/Shopify/shopify-api-node/pull/438)
16
+
10
17
  ## [5.0.1] - 2022-08-03
11
18
 
12
19
  - Make `sanitizeHost` validation more flexible [#446](https://github.com/Shopify/shopify-api-node/pull/446)
package/README.md CHANGED
@@ -51,5 +51,6 @@ You can follow our [getting started guide](docs/), which will provide instructio
51
51
  - [Webhooks](docs/usage/webhooks.md)
52
52
  - [Register a Webhook](docs/usage/webhooks.md#register-a-webhook)
53
53
  - [Process a Webhook](docs/usage/webhooks.md#process-a-webhook)
54
+ - [Billing](docs/usage/billing.md)
54
55
  - [Known issues and caveats](docs/issues.md)
55
56
  - [Notes on session handling](docs/issues.md#notes-on-session-handling)
@@ -3,6 +3,7 @@ import { SessionInterface } from '../session/types';
3
3
  import { AuthQuery } from './types';
4
4
  declare const ShopifyOAuth: {
5
5
  SESSION_COOKIE_NAME: string;
6
+ STATE_COOKIE_NAME: string;
6
7
  /**
7
8
  * Initializes a session and cookie for the OAuth process, and returns the necessary authorization url.
8
9
  *
@@ -24,6 +25,7 @@ declare const ShopifyOAuth: {
24
25
  * @param response Current HTTP Response
25
26
  * @param query Current HTTP Request Query, containing the information to be validated.
26
27
  * Depending on framework, this may need to be cast as "unknown" before being passed.
28
+ * @param isOnline Boolean value. Defaults to true (online access).
27
29
  * @returns SessionInterface
28
30
  */
29
31
  validateAuthCallback(request: http.IncomingMessage, response: http.ServerResponse, query: AuthQuery): Promise<SessionInterface>;
@@ -1 +1 @@
1
- {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../src/auth/oauth/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAexB,OAAO,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EACL,SAAS,EAIV,MAAM,SAAS,CAAC;AAEjB,QAAA,MAAM,YAAY;;IAGhB;;;;;;;;;;OAUG;uBAEQ,KAAK,eAAe,YACnB,KAAK,cAAc,QACvB,MAAM,gBACE,MAAM,uBAEnB,QAAQ,MAAM,CAAC;IAiDlB;;;;;;;;;;OAUG;kCAEQ,KAAK,eAAe,YACnB,KAAK,cAAc,SACtB,SAAS,GACf,QAAQ,gBAAgB,CAAC;IAuG5B;;;;;OAKG;gCAEQ,KAAK,eAAe,YACnB,KAAK,cAAc,GAC5B,MAAM,GAAG,SAAS;IAQrB;;;;;OAKG;0BACmB,MAAM,UAAU,MAAM,GAAG,MAAM;IAIrD;;;;OAIG;8BACuB,MAAM,GAAG,MAAM;IAIzC;;;;;;OAMG;iCAEQ,KAAK,eAAe,YACnB,KAAK,cAAc,uBAE5B,MAAM,GAAG,SAAS;CAiCtB,CAAC;AAcF,OAAO,EAAC,YAAY,EAAC,CAAC"}
1
+ {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../src/auth/oauth/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAexB,OAAO,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EACL,SAAS,EAIV,MAAM,SAAS,CAAC;AAEjB,QAAA,MAAM,YAAY;;;IAIhB;;;;;;;;;;OAUG;uBAEQ,KAAK,eAAe,YACnB,KAAK,cAAc,QACvB,MAAM,gBACE,MAAM,uBAEnB,QAAQ,MAAM,CAAC;IAkClB;;;;;;;;;;;OAWG;kCAEQ,KAAK,eAAe,YACnB,KAAK,cAAc,SACtB,SAAS,GACf,QAAQ,gBAAgB,CAAC;IAwE5B;;;;;OAKG;gCAEQ,KAAK,eAAe,YACnB,KAAK,cAAc,GAC5B,MAAM,GAAG,SAAS;IAIrB;;;;;OAKG;0BACmB,MAAM,UAAU,MAAM,GAAG,MAAM;IAIrD;;;;OAIG;8BACuB,MAAM,GAAG,MAAM;IAIzC;;;;;;OAMG;iCAEQ,KAAK,eAAe,YACnB,KAAK,cAAc,uBAE5B,MAAM,GAAG,SAAS;CAqCtB,CAAC;AAwGF,OAAO,EAAC,YAAY,EAAC,CAAC"}
@@ -17,6 +17,7 @@ var ShopifyErrors = tslib_1.__importStar(require("../../error"));
17
17
  var shop_validator_1 = require("../../utils/shop-validator");
18
18
  var ShopifyOAuth = {
19
19
  SESSION_COOKIE_NAME: 'shopify_app_session',
20
+ STATE_COOKIE_NAME: 'shopify_app_state',
20
21
  /**
21
22
  * Initializes a session and cookie for the OAuth process, and returns the necessary authorization url.
22
23
  *
@@ -31,41 +32,31 @@ var ShopifyOAuth = {
31
32
  beginAuth: function (request, response, shop, redirectPath, isOnline) {
32
33
  if (isOnline === void 0) { isOnline = true; }
33
34
  return tslib_1.__awaiter(this, void 0, void 0, function () {
34
- var cleanShop, cookies, state, session, sessionStored, query, queryString;
35
+ var cleanShop, cookies, state, query, queryString;
35
36
  return tslib_1.__generator(this, function (_a) {
36
- switch (_a.label) {
37
- case 0:
38
- context_1.Context.throwIfUninitialized();
39
- context_1.Context.throwIfPrivateApp('Cannot perform OAuth for private apps');
40
- cleanShop = (0, shop_validator_1.sanitizeShop)(shop, true);
41
- cookies = new cookies_1.default(request, response, {
42
- keys: [context_1.Context.API_SECRET_KEY],
43
- secure: true,
44
- });
45
- state = (0, nonce_1.default)();
46
- session = new session_1.Session(isOnline ? (0, uuid_1.v4)() : this.getOfflineSessionId(cleanShop), cleanShop, state, isOnline);
47
- return [4 /*yield*/, context_1.Context.SESSION_STORAGE.storeSession(session)];
48
- case 1:
49
- sessionStored = _a.sent();
50
- if (!sessionStored) {
51
- throw new ShopifyErrors.SessionStorageError('OAuth Session could not be saved. Please check your session storage functionality.');
52
- }
53
- cookies.set(ShopifyOAuth.SESSION_COOKIE_NAME, session.id, {
54
- signed: true,
55
- expires: new Date(Date.now() + 60000),
56
- sameSite: 'lax',
57
- secure: true,
58
- });
59
- query = {
60
- client_id: context_1.Context.API_KEY,
61
- scope: context_1.Context.SCOPES.toString(),
62
- redirect_uri: "".concat(context_1.Context.HOST_SCHEME, "://").concat(context_1.Context.HOST_NAME).concat(redirectPath),
63
- state: state,
64
- 'grant_options[]': isOnline ? 'per-user' : '',
65
- };
66
- queryString = querystring_1.default.stringify(query);
67
- return [2 /*return*/, "https://".concat(cleanShop, "/admin/oauth/authorize?").concat(queryString)];
68
- }
37
+ context_1.Context.throwIfUninitialized();
38
+ context_1.Context.throwIfPrivateApp('Cannot perform OAuth for private apps');
39
+ cleanShop = (0, shop_validator_1.sanitizeShop)(shop, true);
40
+ cookies = new cookies_1.default(request, response, {
41
+ keys: [context_1.Context.API_SECRET_KEY],
42
+ secure: true,
43
+ });
44
+ state = isOnline ? "online_".concat((0, nonce_1.default)()) : "offline_".concat((0, nonce_1.default)());
45
+ cookies.set(ShopifyOAuth.STATE_COOKIE_NAME, state, {
46
+ signed: true,
47
+ expires: new Date(Date.now() + 60000),
48
+ sameSite: 'lax',
49
+ secure: true,
50
+ });
51
+ query = {
52
+ client_id: context_1.Context.API_KEY,
53
+ scope: context_1.Context.SCOPES.toString(),
54
+ redirect_uri: "".concat(context_1.Context.HOST_SCHEME, "://").concat(context_1.Context.HOST_NAME).concat(redirectPath),
55
+ state: state,
56
+ 'grant_options[]': isOnline ? 'per-user' : '',
57
+ };
58
+ queryString = querystring_1.default.stringify(query);
59
+ return [2 /*return*/, "https://".concat(cleanShop, "/admin/oauth/authorize?").concat(queryString)];
69
60
  });
70
61
  });
71
62
  },
@@ -78,33 +69,26 @@ var ShopifyOAuth = {
78
69
  * @param response Current HTTP Response
79
70
  * @param query Current HTTP Request Query, containing the information to be validated.
80
71
  * Depending on framework, this may need to be cast as "unknown" before being passed.
72
+ * @param isOnline Boolean value. Defaults to true (online access).
81
73
  * @returns SessionInterface
82
74
  */
83
75
  validateAuthCallback: function (request, response, query) {
84
76
  return tslib_1.__awaiter(this, void 0, void 0, function () {
85
- var cookies, sessionCookie, currentSession, body, postParams, client, postResponse, responseBody, access_token, scope, rest, sessionExpiration, onlineInfo, jwtSessionId, jwtSession, sessionDeleted, responseBody, sessionStored;
77
+ var stateFromCookie, isOnline, body, postParams, cleanShop, client, postResponse, session, cookies, sessionStored;
86
78
  return tslib_1.__generator(this, function (_a) {
87
79
  switch (_a.label) {
88
80
  case 0:
89
81
  context_1.Context.throwIfUninitialized();
90
82
  context_1.Context.throwIfPrivateApp('Cannot perform OAuth for private apps');
91
- cookies = new cookies_1.default(request, response, {
92
- keys: [context_1.Context.API_SECRET_KEY],
93
- secure: true,
94
- });
95
- sessionCookie = this.getCookieSessionId(request, response);
96
- if (!sessionCookie) {
83
+ stateFromCookie = getValueFromCookie(request, response, this.STATE_COOKIE_NAME);
84
+ deleteCookie(request, response, this.STATE_COOKIE_NAME);
85
+ if (!stateFromCookie) {
97
86
  throw new ShopifyErrors.CookieNotFound("Cannot complete OAuth process. Could not find an OAuth cookie for shop url: ".concat(query.shop));
98
87
  }
99
- return [4 /*yield*/, context_1.Context.SESSION_STORAGE.loadSession(sessionCookie)];
100
- case 1:
101
- currentSession = _a.sent();
102
- if (!currentSession) {
103
- throw new ShopifyErrors.SessionNotFound("Cannot complete OAuth process. No session found for the specified shop url: ".concat(query.shop));
104
- }
105
- if (!validQuery(query, currentSession)) {
88
+ if (!validQuery(query, stateFromCookie)) {
106
89
  throw new ShopifyErrors.InvalidOAuthError('Invalid OAuth callback.');
107
90
  }
91
+ isOnline = stateFromCookie.startsWith('online_');
108
92
  body = {
109
93
  client_id: context_1.Context.API_KEY,
110
94
  client_secret: context_1.Context.API_SECRET_KEY,
@@ -115,50 +99,31 @@ var ShopifyOAuth = {
115
99
  type: types_1.DataType.JSON,
116
100
  data: body,
117
101
  };
118
- client = new http_client_1.HttpClient(currentSession.shop);
102
+ cleanShop = (0, shop_validator_1.sanitizeShop)(query.shop, true);
103
+ client = new http_client_1.HttpClient(cleanShop);
119
104
  return [4 /*yield*/, client.post(postParams)];
120
- case 2:
105
+ case 1:
121
106
  postResponse = _a.sent();
122
- if (!currentSession.isOnline) return [3 /*break*/, 5];
123
- responseBody = postResponse.body;
124
- access_token = responseBody.access_token, scope = responseBody.scope, rest = tslib_1.__rest(responseBody, ["access_token", "scope"]);
125
- sessionExpiration = new Date(Date.now() + responseBody.expires_in * 1000);
126
- currentSession.accessToken = access_token;
127
- currentSession.expires = sessionExpiration;
128
- currentSession.scope = scope;
129
- currentSession.onlineAccessInfo = rest;
130
- if (!context_1.Context.IS_EMBEDDED_APP) return [3 /*break*/, 4];
131
- onlineInfo = currentSession.onlineAccessInfo;
132
- jwtSessionId = this.getJwtSessionId(currentSession.shop, "".concat(onlineInfo.associated_user.id));
133
- jwtSession = session_1.Session.cloneSession(currentSession, jwtSessionId);
134
- return [4 /*yield*/, context_1.Context.SESSION_STORAGE.deleteSession(currentSession.id)];
135
- case 3:
136
- sessionDeleted = _a.sent();
137
- if (!sessionDeleted) {
138
- throw new ShopifyErrors.SessionStorageError('OAuth Session could not be deleted. Please check your session storage functionality.');
107
+ session = createSession(postResponse, cleanShop, stateFromCookie, isOnline);
108
+ if (!context_1.Context.IS_EMBEDDED_APP) {
109
+ cookies = new cookies_1.default(request, response, {
110
+ keys: [context_1.Context.API_SECRET_KEY],
111
+ secure: true,
112
+ });
113
+ cookies.set(ShopifyOAuth.SESSION_COOKIE_NAME, session.id, {
114
+ signed: true,
115
+ expires: session.expires,
116
+ sameSite: 'lax',
117
+ secure: true,
118
+ });
139
119
  }
140
- currentSession = jwtSession;
141
- _a.label = 4;
142
- case 4: return [3 /*break*/, 6];
143
- case 5:
144
- responseBody = postResponse.body;
145
- currentSession.accessToken = responseBody.access_token;
146
- currentSession.scope = responseBody.scope;
147
- _a.label = 6;
148
- case 6:
149
- cookies.set(ShopifyOAuth.SESSION_COOKIE_NAME, currentSession.id, {
150
- signed: true,
151
- expires: context_1.Context.IS_EMBEDDED_APP ? new Date() : currentSession.expires,
152
- sameSite: 'lax',
153
- secure: true,
154
- });
155
- return [4 /*yield*/, context_1.Context.SESSION_STORAGE.storeSession(currentSession)];
156
- case 7:
120
+ return [4 /*yield*/, context_1.Context.SESSION_STORAGE.storeSession(session)];
121
+ case 2:
157
122
  sessionStored = _a.sent();
158
123
  if (!sessionStored) {
159
- throw new ShopifyErrors.SessionStorageError('OAuth Session could not be saved. Please check your session storage functionality.');
124
+ throw new ShopifyErrors.SessionStorageError('Session could not be saved. Please check your session storage functionality.');
160
125
  }
161
- return [2 /*return*/, currentSession];
126
+ return [2 /*return*/, session];
162
127
  }
163
128
  });
164
129
  });
@@ -170,11 +135,7 @@ var ShopifyOAuth = {
170
135
  * @param response HTTP response object
171
136
  */
172
137
  getCookieSessionId: function (request, response) {
173
- var cookies = new cookies_1.default(request, response, {
174
- secure: true,
175
- keys: [context_1.Context.API_SECRET_KEY],
176
- });
177
- return cookies.get(this.SESSION_COOKIE_NAME, { signed: true });
138
+ return getValueFromCookie(request, response, this.SESSION_COOKIE_NAME);
178
139
  },
179
140
  /**
180
141
  * Builds a JWT session id from the current shop and user.
@@ -225,7 +186,7 @@ var ShopifyOAuth = {
225
186
  // JWT.
226
187
  if (!currentSessionId) {
227
188
  // We still want to get the offline session id from the cookie to make sure it's validated
228
- currentSessionId = this.getCookieSessionId(request, response);
189
+ currentSessionId = getValueFromCookie(request, response, this.SESSION_COOKIE_NAME);
229
190
  }
230
191
  return currentSessionId;
231
192
  },
@@ -235,8 +196,72 @@ exports.ShopifyOAuth = ShopifyOAuth;
235
196
  * Uses the validation utils validateHmac, and safeCompare to assess whether the callback is valid.
236
197
  *
237
198
  * @param query Current HTTP Request Query
238
- * @param session Current session
199
+ * @param stateFromCookie state value from the current cookie
239
200
  */
240
- function validQuery(query, session) {
241
- return ((0, hmac_validator_1.default)(query) && (0, safe_compare_1.default)(query.state, session.state));
201
+ function validQuery(query, stateFromCookie) {
202
+ return (0, hmac_validator_1.default)(query) && (0, safe_compare_1.default)(query.state, stateFromCookie);
203
+ }
204
+ /**
205
+ * Loads a given value from the cookie
206
+ *
207
+ * @param request HTTP request object
208
+ * @param response HTTP response object
209
+ * @param name Name of the cookie to load
210
+ */
211
+ function getValueFromCookie(request, response, name) {
212
+ var cookies = new cookies_1.default(request, response, {
213
+ secure: true,
214
+ keys: [context_1.Context.API_SECRET_KEY],
215
+ });
216
+ return cookies.get(name, { signed: true });
217
+ }
218
+ /**
219
+ * Loads a given value from the cookie
220
+ *
221
+ * @param request HTTP request object
222
+ * @param response HTTP response object
223
+ * @param name Name of the cookie to load
224
+ */
225
+ function deleteCookie(request, response, name) {
226
+ var cookies = new cookies_1.default(request, response, {
227
+ secure: true,
228
+ keys: [context_1.Context.API_SECRET_KEY],
229
+ });
230
+ cookies.set(name);
231
+ }
232
+ /**
233
+ * Creates a new session from the response from the access token request.
234
+ *
235
+ * @param postResponse Response from the access token request
236
+ * @param shop Shop url: {shop}.myshopify.com
237
+ * @param stateFromCookie State from the cookie received by the OAuth callback
238
+ * @param isOnline Boolean indicating if the access token is for online access
239
+ * @returns SessionInterface
240
+ */
241
+ function createSession(postResponse, shop, stateFromCookie, isOnline) {
242
+ var session;
243
+ if (isOnline) {
244
+ var sessionId = void 0;
245
+ var responseBody = postResponse.body;
246
+ var access_token = responseBody.access_token, scope = responseBody.scope, rest = tslib_1.__rest(responseBody, ["access_token", "scope"]); // eslint-disable-line @typescript-eslint/naming-convention
247
+ var sessionExpiration = new Date(Date.now() + responseBody.expires_in * 1000);
248
+ if (context_1.Context.IS_EMBEDDED_APP) {
249
+ sessionId = ShopifyOAuth.getJwtSessionId(shop, "".concat(rest.associated_user.id));
250
+ }
251
+ else {
252
+ sessionId = (0, uuid_1.v4)();
253
+ }
254
+ session = new session_1.Session(sessionId, shop, stateFromCookie, isOnline);
255
+ session.accessToken = access_token;
256
+ session.scope = scope;
257
+ session.expires = sessionExpiration;
258
+ session.onlineAccessInfo = rest;
259
+ }
260
+ else {
261
+ var responseBody = postResponse.body;
262
+ session = new session_1.Session(ShopifyOAuth.getOfflineSessionId(shop), shop, stateFromCookie, isOnline);
263
+ session.accessToken = responseBody.access_token;
264
+ session.scope = responseBody.scope;
265
+ }
266
+ return session;
242
267
  }
@@ -3,6 +3,7 @@ import { SessionInterface } from '../types';
3
3
  import { SessionStorage } from '../session_storage';
4
4
  export interface RedisSessionStorageOptions extends RedisClientOptions {
5
5
  sessionKeyPrefix: string;
6
+ onError?: (...args: any[]) => void;
6
7
  }
7
8
  export declare class RedisSessionStorage implements SessionStorage {
8
9
  private dbUrl;
@@ -1 +1 @@
1
- {"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../../../src/auth/session/storage/redis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,kBAAkB,EAAC,MAAM,OAAO,CAAC;AAExE,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAIlD,MAAM,WAAW,0BAA2B,SAAQ,kBAAkB;IACpE,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAKD,qBAAa,mBAAoB,YAAW,cAAc;IAuBtD,OAAO,CAAC,KAAK;IAtBf,MAAM,CAAC,eAAe,CACpB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,CAAC,0BAA0B,CAAC;IAY3C,SAAgB,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,MAAM,CAAkB;gBAGtB,KAAK,EAAE,GAAG,EAClB,IAAI,GAAE,OAAO,CAAC,0BAA0B,CAAM;IASnC,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAUzD,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAW9D,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM3C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAM/C,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAiB7D,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxC,OAAO,CAAC,OAAO;YAID,IAAI;CAO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IAIxC,OAAO,CAAC,OAAO;YAID,IAAI;CAUnB"}
@@ -157,6 +157,9 @@ var RedisSessionStorage = /** @class */ (function () {
157
157
  switch (_a.label) {
158
158
  case 0:
159
159
  this.client = (0, redis_1.createClient)(tslib_1.__assign(tslib_1.__assign({}, this.options), { url: this.dbUrl.toString() }));
160
+ if (this.options.onError) {
161
+ this.client.on('error', this.options.onError);
162
+ }
160
163
  return [4 /*yield*/, this.client.connect()];
161
164
  case 1:
162
165
  _a.sent();
@@ -1,5 +1,6 @@
1
1
  import { AuthScopes } from './auth/scopes';
2
2
  import { SessionStorage } from './auth/session/session_storage';
3
+ import { BillingSettings } from './billing/types';
3
4
  export interface ContextParams {
4
5
  API_KEY: string;
5
6
  API_SECRET_KEY: string;
@@ -14,6 +15,7 @@ export interface ContextParams {
14
15
  USER_AGENT_PREFIX?: string;
15
16
  PRIVATE_APP_STOREFRONT_ACCESS_TOKEN?: string;
16
17
  CUSTOM_SHOP_DOMAINS?: (RegExp | string)[];
18
+ BILLING?: BillingSettings;
17
19
  }
18
20
  export declare enum ApiVersion {
19
21
  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;IACjC,QAAQ,CAAC,EAAE,M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C;CAC3B;AAED,oBAAY,UAAU;IACpB,SAAS,YAAY;IACrB,SAAS,YAAY;IACrB,OAAO,YAAY;IACnB,MAAM,YAAY;IAClB,QAAQ,aAAa;CACtB;AAED,eAAO,MAAM,kBAAkB,oBAAoB,CAAC;AAEpD,oBAAY,aAAa;IACvB,WAAW,2BAA2B;IACtC,qBAAqB,sCAAsC;IAC3D,IAAI,0BAA0B;IAC9B,KAAK,oBAAoB;IACzB,MAAM,0BAA0B;CACjC"}
@@ -0,0 +1,12 @@
1
+ import { SessionInterface } from '../auth/session/types';
2
+ interface CheckInterface {
3
+ session: SessionInterface;
4
+ isTest?: boolean;
5
+ }
6
+ interface CheckReturn {
7
+ hasPayment: boolean;
8
+ confirmBillingUrl?: string;
9
+ }
10
+ export declare function check({ session, isTest, }: CheckInterface): Promise<CheckReturn>;
11
+ export {};
12
+ //# sourceMappingURL=check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/billing/check.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAKvD,UAAU,cAAc;IACtB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,UAAU,WAAW;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,wBAAsB,KAAK,CAAC,EAC1B,OAAO,EACP,MAAa,GACd,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,CAgBvC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.check = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var context_1 = require("../context");
6
+ var has_active_payment_1 = require("./has_active_payment");
7
+ var request_payment_1 = require("./request_payment");
8
+ function check(_a) {
9
+ var session = _a.session, _b = _a.isTest, isTest = _b === void 0 ? true : _b;
10
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
11
+ var hasPayment, confirmBillingUrl;
12
+ return tslib_1.__generator(this, function (_c) {
13
+ switch (_c.label) {
14
+ case 0:
15
+ if (!context_1.Context.BILLING) {
16
+ return [2 /*return*/, { hasPayment: true, confirmBillingUrl: undefined }];
17
+ }
18
+ return [4 /*yield*/, (0, has_active_payment_1.hasActivePayment)(session, isTest)];
19
+ case 1:
20
+ if (!_c.sent()) return [3 /*break*/, 2];
21
+ hasPayment = true;
22
+ return [3 /*break*/, 4];
23
+ case 2:
24
+ hasPayment = false;
25
+ return [4 /*yield*/, (0, request_payment_1.requestPayment)(session, isTest)];
26
+ case 3:
27
+ confirmBillingUrl = _c.sent();
28
+ _c.label = 4;
29
+ case 4: return [2 /*return*/, { hasPayment: hasPayment, confirmBillingUrl: confirmBillingUrl }];
30
+ }
31
+ });
32
+ });
33
+ }
34
+ exports.check = check;
@@ -0,0 +1,3 @@
1
+ import { SessionInterface } from '../auth/session/types';
2
+ export declare function hasActivePayment(session: SessionInterface, isTest: boolean): Promise<boolean>;
3
+ //# sourceMappingURL=has_active_payment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has_active_payment.d.ts","sourceRoot":"","sources":["../../src/billing/has_active_payment.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AASvD,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,OAAO,CAAC,CAMlB"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasActivePayment = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var context_1 = require("../context");
6
+ var error_1 = require("../error");
7
+ var graphql_1 = require("../clients/graphql");
8
+ var is_recurring_1 = require("./is_recurring");
9
+ function hasActivePayment(session, isTest) {
10
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
11
+ return tslib_1.__generator(this, function (_a) {
12
+ if ((0, is_recurring_1.isRecurring)()) {
13
+ return [2 /*return*/, hasActiveSubscription(session, isTest)];
14
+ }
15
+ else {
16
+ return [2 /*return*/, hasActiveOneTimePurchase(session, isTest)];
17
+ }
18
+ return [2 /*return*/];
19
+ });
20
+ });
21
+ }
22
+ exports.hasActivePayment = hasActivePayment;
23
+ function hasActiveSubscription(session, isTest) {
24
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
25
+ var client, currentInstallations;
26
+ return tslib_1.__generator(this, function (_a) {
27
+ switch (_a.label) {
28
+ case 0:
29
+ if (!context_1.Context.BILLING) {
30
+ throw new error_1.BillingError({
31
+ message: 'Attempted to look for subscriptions without billing configs',
32
+ errorData: [],
33
+ });
34
+ }
35
+ client = new graphql_1.GraphqlClient(session.shop, session.accessToken);
36
+ return [4 /*yield*/, client.query({
37
+ data: RECURRING_PURCHASES_QUERY,
38
+ })];
39
+ case 1:
40
+ currentInstallations = _a.sent();
41
+ return [2 /*return*/, currentInstallations.body.data.currentAppInstallation.activeSubscriptions.some(function (subscription) {
42
+ return subscription.name === context_1.Context.BILLING.chargeName &&
43
+ (isTest || !subscription.test);
44
+ })];
45
+ }
46
+ });
47
+ });
48
+ }
49
+ function hasActiveOneTimePurchase(session, isTest) {
50
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
51
+ var client, installation, endCursor, currentInstallations;
52
+ return tslib_1.__generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0:
55
+ if (!context_1.Context.BILLING) {
56
+ throw new error_1.BillingError({
57
+ message: 'Attempted to look for one time purchases without billing configs',
58
+ errorData: [],
59
+ });
60
+ }
61
+ client = new graphql_1.GraphqlClient(session.shop, session.accessToken);
62
+ endCursor = null;
63
+ _a.label = 1;
64
+ case 1: return [4 /*yield*/, client.query({
65
+ data: {
66
+ query: ONE_TIME_PURCHASES_QUERY,
67
+ variables: { endCursor: endCursor },
68
+ },
69
+ })];
70
+ case 2:
71
+ currentInstallations = _a.sent();
72
+ installation = currentInstallations.body.data.currentAppInstallation;
73
+ if (installation.oneTimePurchases.edges.some(function (purchase) {
74
+ return purchase.node.name === context_1.Context.BILLING.chargeName &&
75
+ (isTest || !purchase.node.test) &&
76
+ purchase.node.status === 'ACTIVE';
77
+ })) {
78
+ return [2 /*return*/, true];
79
+ }
80
+ endCursor = installation.oneTimePurchases.pageInfo.endCursor;
81
+ _a.label = 3;
82
+ case 3:
83
+ if (installation === null || installation === void 0 ? void 0 : installation.oneTimePurchases.pageInfo.hasNextPage) return [3 /*break*/, 1];
84
+ _a.label = 4;
85
+ case 4: return [2 /*return*/, false];
86
+ }
87
+ });
88
+ });
89
+ }
90
+ var RECURRING_PURCHASES_QUERY = "\n query appSubscription {\n currentAppInstallation {\n activeSubscriptions {\n name\n test\n }\n }\n }\n";
91
+ var ONE_TIME_PURCHASES_QUERY = "\n query appPurchases($endCursor: String) {\n currentAppInstallation {\n oneTimePurchases(first: 250, sortKey: CREATED_AT, after: $endCursor) {\n edges {\n node {\n name\n test\n status\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n }\n";
@@ -0,0 +1,7 @@
1
+ import { check } from './check';
2
+ declare const ShopifyBilling: {
3
+ check: typeof check;
4
+ };
5
+ export { ShopifyBilling };
6
+ export default ShopifyBilling;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/billing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B,QAAA,MAAM,cAAc;;CAEnB,CAAC;AAEF,OAAO,EAAC,cAAc,EAAC,CAAC;AACxB,eAAe,cAAc,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShopifyBilling = void 0;
4
+ var check_1 = require("./check");
5
+ var ShopifyBilling = {
6
+ check: check_1.check,
7
+ };
8
+ exports.ShopifyBilling = ShopifyBilling;
9
+ exports.default = ShopifyBilling;
@@ -0,0 +1,2 @@
1
+ export declare function isRecurring(): boolean;
2
+ //# sourceMappingURL=is_recurring.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is_recurring.d.ts","sourceRoot":"","sources":["../../src/billing/is_recurring.ts"],"names":[],"mappings":"AAUA,wBAAgB,WAAW,IAAI,OAAO,CASrC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRecurring = void 0;
4
+ var context_1 = require("../context");
5
+ var error_1 = require("../error");
6
+ var types_1 = require("./types");
7
+ var RECURRING_INTERVALS = [
8
+ types_1.BillingInterval.Every30Days,
9
+ types_1.BillingInterval.Annual,
10
+ ];
11
+ function isRecurring() {
12
+ if (!context_1.Context.BILLING) {
13
+ throw new error_1.BillingError({
14
+ message: 'Attempted to request billing without billing configs',
15
+ errorData: [],
16
+ });
17
+ }
18
+ return RECURRING_INTERVALS.includes(context_1.Context.BILLING.interval);
19
+ }
20
+ exports.isRecurring = isRecurring;
@@ -0,0 +1,3 @@
1
+ import { SessionInterface } from '../auth/session/types';
2
+ export declare function requestPayment(session: SessionInterface, isTest: boolean): Promise<string | undefined>;
3
+ //# sourceMappingURL=request_payment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request_payment.d.ts","sourceRoot":"","sources":["../../src/billing/request_payment.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAYvD,wBAAsB,cAAc,CAClC,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA8B7B"}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requestPayment = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var graphql_1 = require("../clients/graphql");
6
+ var context_1 = require("../context");
7
+ var error_1 = require("../error");
8
+ var get_embedded_app_url_1 = require("../utils/get-embedded-app-url");
9
+ var is_recurring_1 = require("./is_recurring");
10
+ function requestPayment(session, isTest) {
11
+ var _a;
12
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
13
+ var returnUrl, data, mutationResponse, mutationResponse;
14
+ return tslib_1.__generator(this, function (_b) {
15
+ switch (_b.label) {
16
+ case 0:
17
+ returnUrl = (0, get_embedded_app_url_1.buildEmbeddedAppUrl)(Buffer.from("".concat(session.shop, "/admin")).toString('base64'));
18
+ if (!(0, is_recurring_1.isRecurring)()) return [3 /*break*/, 2];
19
+ return [4 /*yield*/, requestRecurringPayment(session, returnUrl, isTest)];
20
+ case 1:
21
+ mutationResponse = _b.sent();
22
+ data = mutationResponse.data.appSubscriptionCreate;
23
+ return [3 /*break*/, 4];
24
+ case 2: return [4 /*yield*/, requestSinglePayment(session, returnUrl, isTest)];
25
+ case 3:
26
+ mutationResponse = _b.sent();
27
+ data = mutationResponse.data.appPurchaseOneTimeCreate;
28
+ _b.label = 4;
29
+ case 4:
30
+ if ((_a = data.userErrors) === null || _a === void 0 ? void 0 : _a.length) {
31
+ throw new error_1.BillingError({
32
+ message: 'Error while billing the store',
33
+ errorData: data.userErrors,
34
+ });
35
+ }
36
+ return [2 /*return*/, data.confirmationUrl];
37
+ }
38
+ });
39
+ });
40
+ }
41
+ exports.requestPayment = requestPayment;
42
+ function requestRecurringPayment(session, returnUrl, isTest) {
43
+ var _a;
44
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
45
+ var client, mutationResponse;
46
+ return tslib_1.__generator(this, function (_b) {
47
+ switch (_b.label) {
48
+ case 0:
49
+ if (!context_1.Context.BILLING) {
50
+ throw new error_1.BillingError({
51
+ message: 'Attempted to request recurring payment without billing configs',
52
+ errorData: [],
53
+ });
54
+ }
55
+ client = new graphql_1.GraphqlClient(session.shop, session.accessToken);
56
+ return [4 /*yield*/, client.query({
57
+ data: {
58
+ query: RECURRING_PURCHASE_MUTATION,
59
+ variables: {
60
+ name: context_1.Context.BILLING.chargeName,
61
+ lineItems: [
62
+ {
63
+ plan: {
64
+ appRecurringPricingDetails: {
65
+ interval: context_1.Context.BILLING.interval,
66
+ price: {
67
+ amount: context_1.Context.BILLING.amount,
68
+ currencyCode: context_1.Context.BILLING.currencyCode,
69
+ },
70
+ },
71
+ },
72
+ },
73
+ ],
74
+ returnUrl: returnUrl,
75
+ test: isTest,
76
+ },
77
+ },
78
+ })];
79
+ case 1:
80
+ mutationResponse = _b.sent();
81
+ if ((_a = mutationResponse.body.errors) === null || _a === void 0 ? void 0 : _a.length) {
82
+ throw new error_1.BillingError({
83
+ message: 'Error while billing the store',
84
+ errorData: mutationResponse.body.errors,
85
+ });
86
+ }
87
+ return [2 /*return*/, mutationResponse.body];
88
+ }
89
+ });
90
+ });
91
+ }
92
+ function requestSinglePayment(session, returnUrl, isTest) {
93
+ var _a;
94
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
95
+ var client, mutationResponse;
96
+ return tslib_1.__generator(this, function (_b) {
97
+ switch (_b.label) {
98
+ case 0:
99
+ if (!context_1.Context.BILLING) {
100
+ throw new error_1.BillingError({
101
+ message: 'Attempted to request single payment without billing configs',
102
+ errorData: [],
103
+ });
104
+ }
105
+ client = new graphql_1.GraphqlClient(session.shop, session.accessToken);
106
+ return [4 /*yield*/, client.query({
107
+ data: {
108
+ query: ONE_TIME_PURCHASE_MUTATION,
109
+ variables: {
110
+ name: context_1.Context.BILLING.chargeName,
111
+ price: {
112
+ amount: context_1.Context.BILLING.amount,
113
+ currencyCode: context_1.Context.BILLING.currencyCode,
114
+ },
115
+ returnUrl: returnUrl,
116
+ test: isTest,
117
+ },
118
+ },
119
+ })];
120
+ case 1:
121
+ mutationResponse = _b.sent();
122
+ if ((_a = mutationResponse.body.errors) === null || _a === void 0 ? void 0 : _a.length) {
123
+ throw new error_1.BillingError({
124
+ message: 'Error while billing the store',
125
+ errorData: mutationResponse.body.errors,
126
+ });
127
+ }
128
+ return [2 /*return*/, mutationResponse.body];
129
+ }
130
+ });
131
+ });
132
+ }
133
+ var RECURRING_PURCHASE_MUTATION = "\n mutation test(\n $name: String!\n $lineItems: [AppSubscriptionLineItemInput!]!\n $returnUrl: URL!\n $test: Boolean\n ) {\n appSubscriptionCreate(\n name: $name\n lineItems: $lineItems\n returnUrl: $returnUrl\n test: $test\n ) {\n confirmationUrl\n userErrors {\n field\n message\n }\n }\n }\n";
134
+ var ONE_TIME_PURCHASE_MUTATION = "\n mutation test(\n $name: String!\n $price: MoneyInput!\n $returnUrl: URL!\n $test: Boolean\n ) {\n appPurchaseOneTimeCreate(\n name: $name\n price: $price\n returnUrl: $returnUrl\n test: $test\n ) {\n confirmationUrl\n userErrors {\n field\n message\n }\n }\n }\n";
@@ -0,0 +1,57 @@
1
+ export declare enum BillingInterval {
2
+ OneTime = "ONE_TIME",
3
+ Every30Days = "EVERY_30_DAYS",
4
+ Annual = "ANNUAL"
5
+ }
6
+ export interface BillingSettings {
7
+ chargeName: string;
8
+ amount: number;
9
+ currencyCode: string;
10
+ interval: BillingInterval;
11
+ }
12
+ export interface ActiveSubscription {
13
+ name: string;
14
+ test: boolean;
15
+ }
16
+ export interface ActiveSubscriptions {
17
+ activeSubscriptions: ActiveSubscription[];
18
+ }
19
+ export interface OneTimePurchase {
20
+ name: string;
21
+ test: boolean;
22
+ status: string;
23
+ }
24
+ export interface OneTimePurchases {
25
+ oneTimePurchases: {
26
+ edges: {
27
+ node: OneTimePurchase;
28
+ }[];
29
+ pageInfo: {
30
+ endCursor: string;
31
+ hasNextPage: boolean;
32
+ };
33
+ };
34
+ }
35
+ export interface CurrentAppInstallations<T> {
36
+ userErrors: string[];
37
+ data: {
38
+ currentAppInstallation: T;
39
+ };
40
+ }
41
+ export interface RequestResponse {
42
+ userErrors: string[];
43
+ confirmationUrl: string;
44
+ }
45
+ export interface RecurringPaymentResponse {
46
+ data: {
47
+ appSubscriptionCreate: RequestResponse;
48
+ };
49
+ errors?: string[];
50
+ }
51
+ export interface SinglePaymentResponse {
52
+ data: {
53
+ appPurchaseOneTimeCreate: RequestResponse;
54
+ };
55
+ errors?: string[];
56
+ }
57
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/billing/types.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe;IACzB,OAAO,aAAa;IACpB,WAAW,kBAAkB;IAC7B,MAAM,WAAW;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,EAAE;QAChB,KAAK,EAAE;YACL,IAAI,EAAE,eAAe,CAAC;SACvB,EAAE,CAAC;QACJ,QAAQ,EAAE;YACR,SAAS,EAAE,MAAM,CAAC;YAClB,WAAW,EAAE,OAAO,CAAC;SACtB,CAAC;KACH,CAAC;CACH;AAED,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACxC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,IAAI,EAAE;QACJ,sBAAsB,EAAE,CAAC,CAAC;KAC3B,CAAC;CACH;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE;QACJ,qBAAqB,EAAE,eAAe,CAAC;KACxC,CAAC;IACF,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE;QACJ,wBAAwB,EAAE,eAAe,CAAC;KAC3C,CAAC;IACF,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BillingInterval = void 0;
4
+ var BillingInterval;
5
+ (function (BillingInterval) {
6
+ BillingInterval["OneTime"] = "ONE_TIME";
7
+ BillingInterval["Every30Days"] = "EVERY_30_DAYS";
8
+ BillingInterval["Annual"] = "ANNUAL";
9
+ })(BillingInterval = exports.BillingInterval || (exports.BillingInterval = {}));
@@ -10,7 +10,7 @@ export declare class GraphqlClient {
10
10
  protected baseApiPath: string;
11
11
  private readonly client;
12
12
  constructor(domain: string, accessToken?: string | undefined);
13
- query(params: GraphqlParams): Promise<RequestReturn>;
13
+ query<T = unknown>(params: GraphqlParams): Promise<RequestReturn<T>>;
14
14
  protected getAccessTokenHeader(): AccessTokenHeader;
15
15
  }
16
16
  //# sourceMappingURL=graphql_client.d.ts.map
@@ -1 +1 @@
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"}
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,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAgC1E,SAAS,CAAC,oBAAoB,IAAI,iBAAiB;CAQpD"}
@@ -8,20 +8,20 @@ export declare class HttpClient {
8
8
  /**
9
9
  * Performs a GET request on the given path.
10
10
  */
11
- get(params: GetRequestParams): Promise<RequestReturn>;
11
+ get<T = unknown>(params: GetRequestParams): Promise<RequestReturn<T>>;
12
12
  /**
13
13
  * Performs a POST request on the given path.
14
14
  */
15
- post(params: PostRequestParams): Promise<RequestReturn>;
15
+ post<T = unknown>(params: PostRequestParams): Promise<RequestReturn<T>>;
16
16
  /**
17
17
  * Performs a PUT request on the given path.
18
18
  */
19
- put(params: PutRequestParams): Promise<RequestReturn>;
19
+ put<T = unknown>(params: PutRequestParams): Promise<RequestReturn<T>>;
20
20
  /**
21
21
  * Performs a DELETE request on the given path.
22
22
  */
23
- delete(params: DeleteRequestParams): Promise<RequestReturn>;
24
- protected request(params: RequestParams): Promise<RequestReturn>;
23
+ delete<T = unknown>(params: DeleteRequestParams): Promise<RequestReturn<T>>;
24
+ protected request<T = unknown>(params: RequestParams): Promise<RequestReturn<T>>;
25
25
  protected getRequestPath(path: string): string;
26
26
  private doRequest;
27
27
  }
@@ -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;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"}
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,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,gBAAgB;IAItD;;OAEG;IACU,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,iBAAiB;IAIxD;;OAEG;IACU,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,gBAAgB;IAItD;;OAEG;IACU,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,mBAAmB;cAI5C,OAAO,CAAC,CAAC,GAAG,OAAO,EACjC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IA0G5B,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;YAIhC,SAAS;CAqHxB"}
@@ -34,8 +34,8 @@ export declare type DeleteRequestParams = GetRequestParams;
34
34
  export declare type RequestParams = (GetRequestParams | PostRequestParams) & {
35
35
  method: Method;
36
36
  };
37
- export interface RequestReturn {
38
- body: unknown;
37
+ export interface RequestReturn<T = unknown> {
38
+ body: T;
39
39
  headers: Headers;
40
40
  }
41
41
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/clients/http_client/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AAEnC,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 -6,7 +6,7 @@ declare class RestClient extends HttpClient {
6
6
  private static LINK_HEADER_REGEXP;
7
7
  private static DEFAULT_LIMIT;
8
8
  constructor(domain: string, accessToken?: string | undefined);
9
- protected request(params: RequestParams): Promise<RestRequestReturn>;
9
+ protected request<T = unknown>(params: RequestParams): Promise<RestRequestReturn<T>>;
10
10
  protected getRequestPath(path: string): string;
11
11
  private buildRequestParams;
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rest_client.d.ts","sourceRoot":"","sources":["../../../src/clients/rest/rest_client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,UAAU,EAAC,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAC,aAAa,EAAmB,MAAM,sBAAsB,CAAC;AAGrE,OAAO,EAAC,iBAAiB,EAAW,MAAM,SAAS,CAAC;AAEpD,cAAM,UAAW,SAAQ,UAAU;IAIE,QAAQ,CAAC,WAAW,CAAC;IAHxD,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAA8B;IAC/D,OAAO,CAAC,MAAM,CAAC,aAAa,CAAQ;gBAEjB,MAAM,EAAE,MAAM,EAAW,WAAW,CAAC,oBAAQ;cAUhD,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAyD1E,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAY9C,OAAO,CAAC,kBAAkB;CAa3B;AAED,OAAO,EAAC,UAAU,EAAC,CAAC"}
1
+ {"version":3,"file":"rest_client.d.ts","sourceRoot":"","sources":["../../../src/clients/rest/rest_client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,UAAU,EAAC,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAC,aAAa,EAAmB,MAAM,sBAAsB,CAAC;AAGrE,OAAO,EAAC,iBAAiB,EAAW,MAAM,SAAS,CAAC;AAEpD,cAAM,UAAW,SAAQ,UAAU;IAIE,QAAQ,CAAC,WAAW,CAAC;IAHxD,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAA8B;IAC/D,OAAO,CAAC,MAAM,CAAC,aAAa,CAAQ;gBAEjB,MAAM,EAAE,MAAM,EAAW,WAAW,CAAC,oBAAQ;cAUhD,OAAO,CAAC,CAAC,GAAG,OAAO,EACjC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAyDhC,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAY9C,OAAO,CAAC,kBAAkB;CAa3B;AAED,OAAO,EAAC,UAAU,EAAC,CAAC"}
@@ -30,7 +30,7 @@ var RestClient = /** @class */ (function (_super) {
30
30
  : this.accessToken, _c), params.extraHeaders);
31
31
  return [4 /*yield*/, _super.prototype.request.call(this, params)];
32
32
  case 1:
33
- ret = (_e.sent());
33
+ ret = _e.sent();
34
34
  link = ret.headers.get('link');
35
35
  if (link !== undefined) {
36
36
  pageInfo = {
@@ -7,7 +7,7 @@ export interface PageInfo {
7
7
  prevPage?: GetRequestParams;
8
8
  nextPage?: GetRequestParams;
9
9
  }
10
- export declare type RestRequestReturn = RequestReturn & {
10
+ export declare type RestRequestReturn<T = unknown> = RequestReturn<T> & {
11
11
  pageInfo?: PageInfo;
12
12
  };
13
13
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/clients/rest/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAErE,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC7B;AAED,oBAAY,iBAAiB,GAAG,aAAa,GAAG;IAC9C,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/clients/rest/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAErE,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC7B;AAED,oBAAY,iBAAiB,CAAC,CAAC,GAAG,OAAO,IAAI,aAAa,CAAC,CAAC,CAAC,GAAG;IAC9D,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC"}
@@ -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,gBAyFd,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,gBA6Fd,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,gBAAgB,EAAC,CAAC"}
package/dist/context.js CHANGED
@@ -71,6 +71,9 @@ var Context = {
71
71
  if (params.CUSTOM_SHOP_DOMAINS) {
72
72
  this.CUSTOM_SHOP_DOMAINS = params.CUSTOM_SHOP_DOMAINS;
73
73
  }
74
+ if (params.BILLING) {
75
+ this.BILLING = params.BILLING;
76
+ }
74
77
  },
75
78
  throwIfUninitialized: function () {
76
79
  if (!this.API_KEY || this.API_KEY.length === 0) {
package/dist/error.d.ts CHANGED
@@ -83,5 +83,12 @@ export declare class UnsupportedClientType extends ShopifyError {
83
83
  }
84
84
  export declare class InvalidRequestError extends ShopifyError {
85
85
  }
86
+ export declare class BillingError extends ShopifyError {
87
+ readonly errorData: any;
88
+ constructor({ message, errorData }: {
89
+ message: string;
90
+ errorData: any;
91
+ });
92
+ }
86
93
  export {};
87
94
  //# sourceMappingURL=error.d.ts.map
@@ -1 +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AG,OAAO,CAAA;KAAC,CAAC;gBAEzB,EACjB,OAAO,EACP,QAAQ,GACT,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;KACpC;CAIF;AAED,qBAAa,iBAAkB,SAAQ,YAAY;CAAG;AACtD,qBAAa,eAAgB,SAAQ,YAAY;CAAG;AACpD,qBAAa,cAAe,SAAQ,YAAY;CAAG;AACnD,qBAAa,cAAe,SAAQ,YAAY;CAAG;AAEnD,qBAAa,mBAAoB,SAAQ,YAAY;CAAG;AACxD,qBAAa,mBAAoB,SAAQ,YAAY;CAAG;AAExD,qBAAa,uBAAwB,SAAQ,YAAY;CAAG;AAC5D,qBAAa,qBAAsB,SAAQ,YAAY;CAAG;AAE1D,qBAAa,mBAAoB,SAAQ,YAAY;CAAG;AAExD,qBAAa,YAAa,SAAQ,YAAY;IAC5C,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC;gBAEL,EAAC,OAAO,EAAE,SAAS,EAAC,EAAE;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,GAAG,CAAA;KAAC;CAM3E"}
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.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;
3
+ exports.BillingError = 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);
@@ -232,3 +232,15 @@ var InvalidRequestError = /** @class */ (function (_super) {
232
232
  return InvalidRequestError;
233
233
  }(ShopifyError));
234
234
  exports.InvalidRequestError = InvalidRequestError;
235
+ var BillingError = /** @class */ (function (_super) {
236
+ tslib_1.__extends(BillingError, _super);
237
+ function BillingError(_a) {
238
+ var message = _a.message, errorData = _a.errorData;
239
+ var _this = _super.call(this, message) || this;
240
+ _this.message = message;
241
+ _this.errorData = errorData;
242
+ return _this;
243
+ }
244
+ return BillingError;
245
+ }(ShopifyError));
246
+ exports.BillingError = BillingError;
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare const Shopify: {
4
4
  Context: import("./context").ContextInterface;
5
5
  Auth: {
6
6
  SESSION_COOKIE_NAME: string;
7
+ STATE_COOKIE_NAME: string;
7
8
  beginAuth(request: import("http").IncomingMessage, response: import("http").ServerResponse, shop: string, redirectPath: string, isOnline?: boolean): Promise<string>;
8
9
  validateAuthCallback(request: import("http").IncomingMessage, response: import("http").ServerResponse, query: import("./types").AuthQuery): Promise<import("./types").SessionInterface>;
9
10
  getCookieSessionId(request: import("http").IncomingMessage, response: import("http").ServerResponse): string | undefined;
@@ -11,6 +12,9 @@ export declare const Shopify: {
11
12
  getOfflineSessionId(shop: string): string;
12
13
  getCurrentSessionId(request: import("http").IncomingMessage, response: import("http").ServerResponse, isOnline?: boolean): string | undefined;
13
14
  };
15
+ Billing: {
16
+ check: typeof import("./billing/check").check;
17
+ };
14
18
  Session: {
15
19
  Session: typeof import("./auth/session/session").Session;
16
20
  MemorySessionStorage: typeof import("./auth/session").MemorySessionStorage;
@@ -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;AAQzC,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CASnB,CAAC;AAEF,eAAe,OAAO,CAAC;AACvB,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ var tslib_1 = require("tslib");
5
5
  var context_1 = require("./context");
6
6
  var ShopifyErrors = tslib_1.__importStar(require("./error"));
7
7
  var oauth_1 = tslib_1.__importDefault(require("./auth/oauth"));
8
+ var billing_1 = tslib_1.__importDefault(require("./billing"));
8
9
  var session_1 = tslib_1.__importDefault(require("./auth/session"));
9
10
  var clients_1 = tslib_1.__importDefault(require("./clients"));
10
11
  var utils_1 = tslib_1.__importDefault(require("./utils"));
@@ -12,6 +13,7 @@ var webhooks_1 = tslib_1.__importDefault(require("./webhooks"));
12
13
  exports.Shopify = {
13
14
  Context: context_1.Context,
14
15
  Auth: oauth_1.default,
16
+ Billing: billing_1.default,
15
17
  Session: session_1.default,
16
18
  Clients: clients_1.default,
17
19
  Utils: utils_1.default,
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './base-types';
2
2
  export * from './auth/types';
3
+ export * from './billing/types';
3
4
  export * from './clients/types';
4
5
  export * from './utils/types';
5
6
  export * from './webhooks/types';
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC"}
package/dist/types.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./base-types"), exports);
5
5
  tslib_1.__exportStar(require("./auth/types"), exports);
6
+ tslib_1.__exportStar(require("./billing/types"), exports);
6
7
  tslib_1.__exportStar(require("./clients/types"), exports);
7
8
  tslib_1.__exportStar(require("./utils/types"), exports);
8
9
  tslib_1.__exportStar(require("./webhooks/types"), exports);
@@ -5,7 +5,7 @@ var tslib_1 = require("tslib");
5
5
  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
- var JWT_PERMITTED_CLOCK_TOLERANCE = 5;
8
+ var JWT_PERMITTED_CLOCK_TOLERANCE = 10;
9
9
  /**
10
10
  * Decodes the given session token, and extracts the session information from it
11
11
  *
@@ -6,4 +6,5 @@ import http from 'http';
6
6
  * @param request Current HTTP request
7
7
  */
8
8
  export default function getEmbeddedAppUrl(request: http.IncomingMessage): string;
9
+ export declare function buildEmbeddedAppUrl(host: string): string;
9
10
  //# sourceMappingURL=get-embedded-app-url.d.ts.map
@@ -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;AAOxB;;;;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,CAuBR;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMxD"}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildEmbeddedAppUrl = void 0;
3
4
  var tslib_1 = require("tslib");
4
5
  var ShopifyErrors = tslib_1.__importStar(require("../error"));
5
6
  var context_1 = require("../context");
@@ -18,10 +19,15 @@ function getEmbeddedAppUrl(request) {
18
19
  }
19
20
  var url = new URL(request.url, "https://".concat(request.headers.host));
20
21
  var host = url.searchParams.get('host');
21
- if (typeof host !== 'string' || !(0, shop_validator_1.sanitizeHost)(host)) {
22
+ if (typeof host !== 'string') {
22
23
  throw new ShopifyErrors.InvalidRequestError('Request does not contain a host query parameter');
23
24
  }
25
+ return buildEmbeddedAppUrl(host);
26
+ }
27
+ exports.default = getEmbeddedAppUrl;
28
+ function buildEmbeddedAppUrl(host) {
29
+ (0, shop_validator_1.sanitizeHost)(host, true);
24
30
  var decodedHost = Buffer.from(host, 'base64').toString();
25
31
  return "https://".concat(decodedHost, "/apps/").concat(context_1.Context.API_KEY);
26
32
  }
27
- exports.default = getEmbeddedAppUrl;
33
+ exports.buildEmbeddedAppUrl = buildEmbeddedAppUrl;
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"setup-jest.d.ts","sourceRoot":"","sources":["../../src/utils/setup-jest.ts"],"names":[],"mappings":"AAwCA,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"}
@@ -20,6 +20,7 @@ beforeEach(function () {
20
20
  IS_PRIVATE_APP: false,
21
21
  SESSION_STORAGE: new session_1.MemorySessionStorage(),
22
22
  CUSTOM_SHOP_DOMAINS: undefined,
23
+ BILLING: undefined,
23
24
  });
24
25
  jest_fetch_mock_1.default.mockReset();
25
26
  currentCall = 0;
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const SHOPIFY_API_LIBRARY_VERSION = "5.0.1";
1
+ export declare const SHOPIFY_API_LIBRARY_VERSION = "5.1.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 = '5.0.1';
4
+ exports.SHOPIFY_API_LIBRARY_VERSION = '5.1.0';
@@ -137,7 +137,7 @@ var WebhooksRegistry = {
137
137
  data: buildCheckQuery(topic),
138
138
  })];
139
139
  case 2:
140
- checkResult = (_c.sent());
140
+ checkResult = _c.sent();
141
141
  return [3 /*break*/, 4];
142
142
  case 3:
143
143
  error_1 = _c.sent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopify/shopify-api",
3
- "version": "5.0.1",
3
+ "version": "5.1.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",
@@ -54,7 +54,7 @@
54
54
  "mysql2": "^2.3.3",
55
55
  "node-fetch": "^2.6.1",
56
56
  "pg": "^8.7.3",
57
- "redis": "^4.0.6",
57
+ "redis": "^4.1.0",
58
58
  "sqlite3": "^5.0.8",
59
59
  "tslib": "^2.0.3",
60
60
  "uuid": "^8.3.1"