@shopify/shopify-api 1.4.1 → 2.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.
- package/CHANGELOG.md +43 -0
- package/README.md +3 -0
- package/dist/auth/oauth/oauth.d.ts +4 -2
- package/dist/auth/oauth/oauth.d.ts.map +1 -1
- package/dist/auth/oauth/oauth.js +34 -38
- package/dist/auth/scopes/index.d.ts +3 -3
- package/dist/auth/scopes/index.d.ts.map +1 -1
- package/dist/auth/scopes/index.js +5 -3
- package/dist/auth/session/index.d.ts +1 -1
- package/dist/auth/session/index.d.ts.map +1 -1
- package/dist/auth/session/session.d.ts +4 -4
- package/dist/auth/session/session.d.ts.map +1 -1
- package/dist/auth/session/session.js +8 -6
- package/dist/auth/session/storage/custom.d.ts.map +1 -1
- package/dist/auth/session/storage/custom.js +1 -1
- package/dist/auth/session/storage/memory.d.ts.map +1 -1
- package/dist/auth/session/types.d.ts +2 -2
- package/dist/auth/session/types.d.ts.map +1 -1
- package/dist/base_types.d.ts +2 -0
- package/dist/base_types.d.ts.map +1 -1
- package/dist/base_types.js +2 -0
- package/dist/clients/graphql/graphql_client.d.ts.map +1 -1
- package/dist/clients/graphql/graphql_client.js +3 -1
- package/dist/clients/graphql/index.d.ts +1 -1
- package/dist/clients/graphql/index.d.ts.map +1 -1
- package/dist/clients/graphql/storefront_client.js +3 -1
- package/dist/clients/http_client/http_client.d.ts.map +1 -1
- package/dist/clients/http_client/http_client.js +25 -9
- package/dist/clients/http_client/types.d.ts.map +1 -1
- package/dist/clients/rest/rest_client.d.ts.map +1 -1
- package/dist/clients/rest/rest_client.js +6 -2
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +2 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/utils/decode-session-token.d.ts +1 -1
- package/dist/utils/decode-session-token.d.ts.map +1 -1
- package/dist/utils/decode-session-token.js +5 -1
- package/dist/utils/delete-current-session.d.ts.map +1 -1
- package/dist/utils/delete-offline-session.d.ts.map +1 -1
- package/dist/utils/graphql_proxy.d.ts.map +1 -1
- package/dist/utils/hmac-validator.d.ts +1 -1
- package/dist/utils/hmac-validator.d.ts.map +1 -1
- package/dist/utils/hmac-validator.js +4 -1
- package/dist/utils/load-current-session.d.ts.map +1 -1
- package/dist/utils/load-offline-session.d.ts.map +1 -1
- package/dist/utils/load-offline-session.js +4 -1
- package/dist/utils/version-compatible.d.ts.map +1 -1
- package/dist/utils/version-compatible.js +5 -2
- package/dist/utils/with-session.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/webhooks/registry.d.ts +37 -3
- package/dist/webhooks/registry.d.ts.map +1 -1
- package/dist/webhooks/registry.js +107 -24
- package/dist/webhooks/types.d.ts +9 -4
- package/dist/webhooks/types.d.ts.map +1 -1
- package/package.json +7 -5
package/CHANGELOG.md
CHANGED
|
@@ -6,30 +6,73 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
|
6
6
|
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
8
|
## Unreleased
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
## [2.1.0] - 2022-02-03
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- Add support for January 2022 API version [#285](https://github.com/Shopify/shopify-node-api/pull/285)
|
|
18
|
+
|
|
19
|
+
## [2.0.0] - 2021-10-28
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- Add a 5 second `clockTolerance` to fix `jwt not active` error [#227](https://github.com/Shopify/shopify-node-api/pull/227)
|
|
24
|
+
- [Breaking] Change default for OAuth.beginAuth to online sessions [#203](https://github.com/Shopify/shopify-node-api/pull/203)
|
|
25
|
+
- see [oauth.md](https://github.com/Shopify/shopify-node-api/blob/main/docs/usage/oauth.md) for updated docs
|
|
26
|
+
- [Breaking] Return and delete session in `validateAuthCallback` [#217](https://github.com/Shopify/shopify-node-api/pull/217)
|
|
27
|
+
- see [oauth.md](https://github.com/Shopify/shopify-node-api/blob/main/docs/usage/oauth.md) for updated usage
|
|
28
|
+
- [Breaking] Extract `addHandler` and `getHandler` methods for webhooks out of `register` [#205](https://github.com/Shopify/shopify-node-api/pull/205)
|
|
29
|
+
- [Breaking] Sessions no longer default to `false` for `isOnline` [#169](https://github.com/Shopify/shopify-node-api/pull/169)
|
|
30
|
+
- Required `Session` arguments must be passed to the constructor [#169](https://github.com/Shopify/shopify-node-api/pull/169)
|
|
31
|
+
- Allow `undefined` in `AuthScopes` [#169](https://github.com/Shopify/shopify-node-api/pull/169)
|
|
32
|
+
|
|
33
|
+
## [1.4.3] - 2021-10-22
|
|
34
|
+
|
|
9
35
|
### Fixed
|
|
36
|
+
|
|
37
|
+
- Fixed the HTTP client error messages to expand objects [#252](https://github.com/Shopify/shopify-node-api/pull/252)
|
|
38
|
+
|
|
39
|
+
## [1.4.2] - 2021-10-20
|
|
40
|
+
|
|
41
|
+
- Added `October21` to `ApiVersion` [#247](https://github.com/Shopify/shopify-node-api/pull/247)
|
|
42
|
+
|
|
43
|
+
## [1.4.1] - 2021-06-11
|
|
44
|
+
|
|
10
45
|
- Don't include extra params when calculating local hmac [#196](https://github.com/Shopify/shopify-node-api/pull/196)
|
|
11
46
|
|
|
12
47
|
## [1.4.0] - 2021-05-21
|
|
48
|
+
|
|
13
49
|
### Added
|
|
50
|
+
|
|
14
51
|
- Add support for registering Google Pub/Sub webhooks [#181](https://github.com/Shopify/shopify-node-api/pull/181)
|
|
15
52
|
- Added `July21` to `ApiVersion` [#181](https://github.com/Shopify/shopify-node-api/pull/181)
|
|
16
53
|
|
|
17
54
|
## [1.3.0] - 2021-05-12
|
|
55
|
+
|
|
18
56
|
### Added
|
|
57
|
+
|
|
19
58
|
- Added Storefront API client under `Shopify.Clients.Storefront`
|
|
20
59
|
- Add `isActive()` method to `Session` class to check if session is active, replace `Session` with `SessionInterface` when used as a type [#153](https://github.com/Shopify/shopify-node-api/pull/153)
|
|
21
60
|
|
|
22
61
|
## [1.2.1] - 2021-03-26
|
|
62
|
+
|
|
23
63
|
### Added
|
|
64
|
+
|
|
24
65
|
- Added `April21` to `ApiVersion` [#149](https://github.com/Shopify/shopify-node-api/pull/149)
|
|
25
66
|
|
|
26
67
|
## [1.2.0] - 2021-03-16
|
|
27
68
|
|
|
28
69
|
### Added
|
|
70
|
+
|
|
29
71
|
- Allow plain objects to be returned from the `loadCallback` on `CustomSessionStorage` [#126](https://github.com/shopify/shopify-node-api/pull/126)
|
|
30
72
|
- Documentation and example code for `CustomSessionStorage` [#129](https://github.com/shopify/shopify-node-api/pull/129)
|
|
31
73
|
|
|
32
74
|
### Fixed
|
|
75
|
+
|
|
33
76
|
- Throw a different error for a missing cookie upon OAuth return [#131](https://github.com/shopify/shopify-node-api/pull/131)
|
|
34
77
|
- Improved documentation for GraphQL and Rest Clients. [#123](https://github.com/Shopify/shopify-node-api/pull/123)
|
|
35
78
|
- Made Docs directory more browseable in GitHub. [#136](https://github.com/Shopify/shopify-node-api/pull/136)
|
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# `@shopify/shopify-api`
|
|
2
2
|
|
|
3
3
|
<!-- ![Build Status]() -->
|
|
4
|
+
|
|
4
5
|
[](LICENSE.md)
|
|
5
6
|
[](https://badge.fury.io/js/%40shopify%2Fshopify-api)
|
|
6
7
|
|
|
@@ -18,6 +19,7 @@ This library can be used in any application that has a Node.js backend, since it
|
|
|
18
19
|
# Requirements
|
|
19
20
|
|
|
20
21
|
To follow these usage guides, you will need to:
|
|
22
|
+
|
|
21
23
|
- have a basic understanding of [Node.js](https://nodejs.org)
|
|
22
24
|
- have a Shopify Partner account and development store
|
|
23
25
|
- _OR_ have a test store where you can create a private app
|
|
@@ -27,6 +29,7 @@ To follow these usage guides, you will need to:
|
|
|
27
29
|
- have [yarn](https://yarnpkg.com) installed
|
|
28
30
|
|
|
29
31
|
<!-- Make sure this section is in sync with docs/README.md -->
|
|
32
|
+
|
|
30
33
|
# Getting started
|
|
31
34
|
|
|
32
35
|
You can follow our [getting started guide](docs/), which will provide instructions on how to create an app using plain Node.js code, or the [Express](https://expressjs.com/) framework. Both examples are written in Typescript.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
|
+
import { SessionInterface } from '../session/types';
|
|
2
3
|
import { AuthQuery } from './types';
|
|
3
4
|
declare const ShopifyOAuth: {
|
|
4
5
|
SESSION_COOKIE_NAME: string;
|
|
@@ -11,7 +12,7 @@ declare const ShopifyOAuth: {
|
|
|
11
12
|
* @param redirect Redirect url for callback
|
|
12
13
|
* @param isOnline Boolean value. If true, appends 'per-user' grant options to authorization url to receive online access token.
|
|
13
14
|
* During final oauth request, will receive back the online access token and current online session information.
|
|
14
|
-
* Defaults to
|
|
15
|
+
* Defaults to online access.
|
|
15
16
|
*/
|
|
16
17
|
beginAuth(request: http.IncomingMessage, response: http.ServerResponse, shop: string, redirectPath: string, isOnline?: boolean): Promise<string>;
|
|
17
18
|
/**
|
|
@@ -23,8 +24,9 @@ declare const ShopifyOAuth: {
|
|
|
23
24
|
* @param response Current HTTP Response
|
|
24
25
|
* @param query Current HTTP Request Query, containing the information to be validated.
|
|
25
26
|
* Depending on framework, this may need to be cast as "unknown" before being passed.
|
|
27
|
+
* @returns SessionInterface
|
|
26
28
|
*/
|
|
27
|
-
validateAuthCallback(request: http.IncomingMessage, response: http.ServerResponse, query: AuthQuery): Promise<
|
|
29
|
+
validateAuthCallback(request: http.IncomingMessage, response: http.ServerResponse, query: AuthQuery): Promise<SessionInterface>;
|
|
28
30
|
/**
|
|
29
31
|
* Loads the current session id from the session cookie.
|
|
30
32
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../src/auth/oauth/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../src/auth/oauth/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAgBxB,OAAO,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAElD,OAAO,EACL,SAAS,EAIV,MAAM,SAAS,CAAC;AAEjB,QAAA,MAAM,YAAY;;IAGhB;;;;;;;;;;OAUG;uBAEQ,IAAI,CAAC,eAAe,YACnB,IAAI,CAAC,cAAc,QACvB,MAAM,gBACE,MAAM,uBAEnB,OAAO,CAAC,MAAM,CAAC;IAgDlB;;;;;;;;;;OAUG;kCAEQ,IAAI,CAAC,eAAe,YACnB,IAAI,CAAC,cAAc,SACtB,SAAS,GACf,OAAO,CAAC,gBAAgB,CAAC;IAmG5B;;;;;OAKG;gCAEQ,IAAI,CAAC,eAAe,YACnB,IAAI,CAAC,cAAc,GAC5B,MAAM,GAAG,SAAS;IAQrB;;;;;OAKG;0BACmB,MAAM,UAAU,MAAM,GAAG,MAAM;IAIrD;;;;OAIG;8BACuB,MAAM,GAAG,MAAM;IAIzC;;;;;;OAMG;iCAEQ,IAAI,CAAC,eAAe,YACnB,IAAI,CAAC,cAAc,uBAE5B,MAAM,GAAG,SAAS;CAiCtB,CAAC;AAgBF,OAAO,EAAC,YAAY,EAAC,CAAC"}
|
package/dist/auth/oauth/oauth.js
CHANGED
|
@@ -26,10 +26,10 @@ var ShopifyOAuth = {
|
|
|
26
26
|
* @param redirect Redirect url for callback
|
|
27
27
|
* @param isOnline Boolean value. If true, appends 'per-user' grant options to authorization url to receive online access token.
|
|
28
28
|
* During final oauth request, will receive back the online access token and current online session information.
|
|
29
|
-
* Defaults to
|
|
29
|
+
* Defaults to online access.
|
|
30
30
|
*/
|
|
31
31
|
beginAuth: function (request, response, shop, redirectPath, isOnline) {
|
|
32
|
-
if (isOnline === void 0) { isOnline =
|
|
32
|
+
if (isOnline === void 0) { isOnline = true; }
|
|
33
33
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
34
34
|
var cookies, state, session, sessionStored, query, queryString;
|
|
35
35
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -42,10 +42,7 @@ var ShopifyOAuth = {
|
|
|
42
42
|
secure: true,
|
|
43
43
|
});
|
|
44
44
|
state = nonce_1.default();
|
|
45
|
-
session = new session_1.Session(isOnline ? uuid_1.v4() : this.getOfflineSessionId(shop));
|
|
46
|
-
session.shop = shop;
|
|
47
|
-
session.state = state;
|
|
48
|
-
session.isOnline = isOnline;
|
|
45
|
+
session = new session_1.Session(isOnline ? uuid_1.v4() : this.getOfflineSessionId(shop), shop, state, isOnline);
|
|
49
46
|
return [4 /*yield*/, context_1.Context.SESSION_STORAGE.storeSession(session)];
|
|
50
47
|
case 1:
|
|
51
48
|
sessionStored = _a.sent();
|
|
@@ -80,10 +77,11 @@ var ShopifyOAuth = {
|
|
|
80
77
|
* @param response Current HTTP Response
|
|
81
78
|
* @param query Current HTTP Request Query, containing the information to be validated.
|
|
82
79
|
* Depending on framework, this may need to be cast as "unknown" before being passed.
|
|
80
|
+
* @returns SessionInterface
|
|
83
81
|
*/
|
|
84
82
|
validateAuthCallback: function (request, response, query) {
|
|
85
83
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
86
|
-
var cookies, sessionCookie, currentSession, body, postParams, client, postResponse, responseBody, access_token, scope, rest, sessionExpiration,
|
|
84
|
+
var cookies, sessionCookie, currentSession, body, postParams, client, postResponse, responseBody, access_token, scope, rest, sessionExpiration, onlineInfo, jwtSessionId, jwtSession, sessionDeleted, responseBody, sessionStored;
|
|
87
85
|
return tslib_1.__generator(this, function (_a) {
|
|
88
86
|
switch (_a.label) {
|
|
89
87
|
case 0:
|
|
@@ -120,50 +118,46 @@ var ShopifyOAuth = {
|
|
|
120
118
|
return [4 /*yield*/, client.post(postParams)];
|
|
121
119
|
case 2:
|
|
122
120
|
postResponse = _a.sent();
|
|
123
|
-
if (currentSession.isOnline)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
else {
|
|
133
|
-
responseBody = postResponse.body;
|
|
134
|
-
currentSession.accessToken = responseBody.access_token;
|
|
135
|
-
currentSession.scope = responseBody.scope;
|
|
136
|
-
}
|
|
137
|
-
oauthSessionExpiration = currentSession.expires;
|
|
138
|
-
if (!!currentSession.isOnline) return [3 /*break*/, 3];
|
|
139
|
-
oauthSessionExpiration = new Date();
|
|
140
|
-
return [3 /*break*/, 5];
|
|
141
|
-
case 3:
|
|
142
|
-
if (!context_1.Context.IS_EMBEDDED_APP) return [3 /*break*/, 5];
|
|
121
|
+
if (!currentSession.isOnline) return [3 /*break*/, 5];
|
|
122
|
+
responseBody = postResponse.body;
|
|
123
|
+
access_token = responseBody.access_token, scope = responseBody.scope, rest = tslib_1.__rest(responseBody, ["access_token", "scope"]);
|
|
124
|
+
sessionExpiration = new Date(Date.now() + responseBody.expires_in * 1000);
|
|
125
|
+
currentSession.accessToken = access_token;
|
|
126
|
+
currentSession.expires = sessionExpiration;
|
|
127
|
+
currentSession.scope = scope;
|
|
128
|
+
currentSession.onlineAccessInfo = rest;
|
|
129
|
+
if (!context_1.Context.IS_EMBEDDED_APP) return [3 /*break*/, 4];
|
|
143
130
|
onlineInfo = currentSession.onlineAccessInfo;
|
|
144
131
|
jwtSessionId = this.getJwtSessionId(currentSession.shop, "" + onlineInfo.associated_user.id);
|
|
145
132
|
jwtSession = session_1.Session.cloneSession(currentSession, jwtSessionId);
|
|
146
|
-
return [4 /*yield*/, context_1.Context.SESSION_STORAGE.
|
|
147
|
-
case
|
|
148
|
-
_a.sent();
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
133
|
+
return [4 /*yield*/, context_1.Context.SESSION_STORAGE.deleteSession(currentSession.id)];
|
|
134
|
+
case 3:
|
|
135
|
+
sessionDeleted = _a.sent();
|
|
136
|
+
if (!sessionDeleted) {
|
|
137
|
+
throw new ShopifyErrors.SessionStorageError('OAuth Session could not be deleted. Please check your session storage functionality.');
|
|
138
|
+
}
|
|
139
|
+
currentSession = jwtSession;
|
|
140
|
+
_a.label = 4;
|
|
141
|
+
case 4: return [3 /*break*/, 6];
|
|
153
142
|
case 5:
|
|
143
|
+
responseBody = postResponse.body;
|
|
144
|
+
currentSession.accessToken = responseBody.access_token;
|
|
145
|
+
currentSession.scope = responseBody.scope;
|
|
146
|
+
_a.label = 6;
|
|
147
|
+
case 6:
|
|
154
148
|
cookies.set(ShopifyOAuth.SESSION_COOKIE_NAME, currentSession.id, {
|
|
155
149
|
signed: true,
|
|
156
|
-
expires:
|
|
150
|
+
expires: context_1.Context.IS_EMBEDDED_APP ? new Date() : currentSession.expires,
|
|
157
151
|
sameSite: 'lax',
|
|
158
152
|
secure: true,
|
|
159
153
|
});
|
|
160
154
|
return [4 /*yield*/, context_1.Context.SESSION_STORAGE.storeSession(currentSession)];
|
|
161
|
-
case
|
|
155
|
+
case 7:
|
|
162
156
|
sessionStored = _a.sent();
|
|
163
157
|
if (!sessionStored) {
|
|
164
158
|
throw new ShopifyErrors.SessionStorageError('OAuth Session could not be saved. Please check your session storage functionality.');
|
|
165
159
|
}
|
|
166
|
-
return [2 /*return
|
|
160
|
+
return [2 /*return*/, currentSession];
|
|
167
161
|
}
|
|
168
162
|
});
|
|
169
163
|
});
|
|
@@ -243,5 +237,7 @@ exports.ShopifyOAuth = ShopifyOAuth;
|
|
|
243
237
|
* @param session Current session
|
|
244
238
|
*/
|
|
245
239
|
function validQuery(query, session) {
|
|
246
|
-
return hmac_validator_1.default(query) &&
|
|
240
|
+
return (hmac_validator_1.default(query) &&
|
|
241
|
+
shop_validator_1.default(query.shop) &&
|
|
242
|
+
safe_compare_1.default(query.state, session.state));
|
|
247
243
|
}
|
|
@@ -2,9 +2,9 @@ declare class AuthScopes {
|
|
|
2
2
|
static SCOPE_DELIMITER: string;
|
|
3
3
|
private compressedScopes;
|
|
4
4
|
private expandedScopes;
|
|
5
|
-
constructor(scopes: string | string[]);
|
|
6
|
-
has(scope: string | string[] | AuthScopes): boolean;
|
|
7
|
-
equals(otherScopes: string | string[] | AuthScopes): boolean;
|
|
5
|
+
constructor(scopes: string | string[] | undefined);
|
|
6
|
+
has(scope: string | string[] | AuthScopes | undefined): boolean;
|
|
7
|
+
equals(otherScopes: string | string[] | AuthScopes | undefined): boolean;
|
|
8
8
|
toString(): string;
|
|
9
9
|
toArray(): string[];
|
|
10
10
|
private getImpliedScopes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/scopes/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/scopes/index.ts"],"names":[],"mappings":"AACA,cAAM,UAAU;IACd,OAAc,eAAe,SAAO;IAEpC,OAAO,CAAC,gBAAgB,CAAc;IACtC,OAAO,CAAC,cAAc,CAAc;gBAExB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS;IAyB1C,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU,GAAG,SAAS;IAcrD,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU,GAAG,SAAS;IAe9D,QAAQ;IAIR,OAAO;IAId,OAAO,CAAC,gBAAgB;CAUzB;AAED,OAAO,EAAC,UAAU,EAAC,CAAC"}
|
|
@@ -8,10 +8,12 @@ var AuthScopes = /** @class */ (function () {
|
|
|
8
8
|
if (typeof scopes === 'string') {
|
|
9
9
|
scopesArray = scopes.split(new RegExp(AuthScopes.SCOPE_DELIMITER + "\\s*"));
|
|
10
10
|
}
|
|
11
|
-
else {
|
|
11
|
+
else if (scopes) {
|
|
12
12
|
scopesArray = scopes;
|
|
13
13
|
}
|
|
14
|
-
scopesArray = scopesArray
|
|
14
|
+
scopesArray = scopesArray
|
|
15
|
+
.map(function (scope) { return scope.trim(); })
|
|
16
|
+
.filter(function (scope) { return scope.length; });
|
|
15
17
|
var impliedScopes = this.getImpliedScopes(scopesArray);
|
|
16
18
|
var scopeSet = new Set(scopesArray);
|
|
17
19
|
var impliedSet = new Set(impliedScopes);
|
|
@@ -27,7 +29,7 @@ var AuthScopes = /** @class */ (function () {
|
|
|
27
29
|
else {
|
|
28
30
|
other = new AuthScopes(scope);
|
|
29
31
|
}
|
|
30
|
-
return other.toArray().filter(function (x) { return !_this.expandedScopes.has(x); }).length === 0;
|
|
32
|
+
return (other.toArray().filter(function (x) { return !_this.expandedScopes.has(x); }).length === 0);
|
|
31
33
|
};
|
|
32
34
|
AuthScopes.prototype.equals = function (otherScopes) {
|
|
33
35
|
var other;
|
|
@@ -8,5 +8,5 @@ declare const ShopifySession: {
|
|
|
8
8
|
CustomSessionStorage: typeof CustomSessionStorage;
|
|
9
9
|
};
|
|
10
10
|
export default ShopifySession;
|
|
11
|
-
export { Session, SessionStorage, MemorySessionStorage, CustomSessionStorage
|
|
11
|
+
export { Session, SessionStorage, MemorySessionStorage, CustomSessionStorage };
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/session/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,oBAAoB,EAAC,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAC,oBAAoB,EAAC,MAAM,kBAAkB,CAAC;AAEtD,QAAA,MAAM,cAAc;;;;CAInB,CAAC;AAEF,eAAe,cAAc,CAAC;AAC9B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/session/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,oBAAoB,EAAC,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAC,oBAAoB,EAAC,MAAM,kBAAkB,CAAC;AAEtD,QAAA,MAAM,cAAc;;;;CAInB,CAAC;AAEF,eAAe,cAAc,CAAC;AAC9B,OAAO,EAAC,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,oBAAoB,EAAC,CAAC"}
|
|
@@ -5,15 +5,15 @@ import { SessionInterface } from './types';
|
|
|
5
5
|
*/
|
|
6
6
|
declare class Session implements SessionInterface {
|
|
7
7
|
readonly id: string;
|
|
8
|
-
static cloneSession(session: Session, newId: string): Session;
|
|
9
8
|
shop: string;
|
|
10
9
|
state: string;
|
|
11
|
-
|
|
10
|
+
isOnline: boolean;
|
|
11
|
+
static cloneSession(session: Session, newId: string): Session;
|
|
12
|
+
scope?: string;
|
|
12
13
|
expires?: Date;
|
|
13
|
-
isOnline?: boolean;
|
|
14
14
|
accessToken?: string;
|
|
15
15
|
onlineAccessInfo?: OnlineAccessInfo;
|
|
16
|
-
constructor(id: string);
|
|
16
|
+
constructor(id: string, shop: string, state: string, isOnline: boolean);
|
|
17
17
|
isActive(): boolean;
|
|
18
18
|
}
|
|
19
19
|
export { Session };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/auth/session/session.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/auth/session/session.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAEzC;;GAEG;AACH,cAAM,OAAQ,YAAW,gBAAgB;IAuBrC,QAAQ,CAAC,EAAE,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,MAAM;IACb,QAAQ,EAAE,OAAO;WAzBZ,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAgB7D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;gBAGhC,EAAE,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,OAAO;IAGnB,QAAQ,IAAI,OAAO;CAW3B;AAED,OAAO,EAAC,OAAO,EAAC,CAAC"}
|
|
@@ -6,23 +6,25 @@ var context_1 = require("../../context");
|
|
|
6
6
|
* Stores App information from logged in merchants so they can make authenticated requests to the Admin API.
|
|
7
7
|
*/
|
|
8
8
|
var Session = /** @class */ (function () {
|
|
9
|
-
function Session(id) {
|
|
9
|
+
function Session(id, shop, state, isOnline) {
|
|
10
10
|
this.id = id;
|
|
11
|
+
this.shop = shop;
|
|
12
|
+
this.state = state;
|
|
13
|
+
this.isOnline = isOnline;
|
|
11
14
|
}
|
|
12
15
|
Session.cloneSession = function (session, newId) {
|
|
13
|
-
var newSession = new Session(newId);
|
|
14
|
-
newSession.shop = session.shop;
|
|
15
|
-
newSession.state = session.state;
|
|
16
|
+
var newSession = new Session(newId, session.shop, session.state, session.isOnline);
|
|
16
17
|
newSession.scope = session.scope;
|
|
17
18
|
newSession.expires = session.expires;
|
|
18
|
-
newSession.isOnline = session.isOnline;
|
|
19
19
|
newSession.accessToken = session.accessToken;
|
|
20
20
|
newSession.onlineAccessInfo = session.onlineAccessInfo;
|
|
21
21
|
return newSession;
|
|
22
22
|
};
|
|
23
23
|
Session.prototype.isActive = function () {
|
|
24
24
|
var scopesUnchanged = context_1.Context.SCOPES.equals(this.scope);
|
|
25
|
-
if (scopesUnchanged &&
|
|
25
|
+
if (scopesUnchanged &&
|
|
26
|
+
this.accessToken &&
|
|
27
|
+
(!this.expires || this.expires >= new Date())) {
|
|
26
28
|
return true;
|
|
27
29
|
}
|
|
28
30
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../../../src/auth/session/storage/custom.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAGlD,qBAAa,oBAAqB,YAAW,cAAc;IAEvD,QAAQ,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC,OAAO,CAAC;IACvE,QAAQ,CAAC,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../../../src/auth/session/storage/custom.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAGlD,qBAAa,oBAAqB,YAAW,cAAc;IAEvD,QAAQ,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC,OAAO,CAAC;IACvE,QAAQ,CAAC,YAAY,EAAE,CACrB,EAAE,EAAE,MAAM,KACP,OAAO,CAAC,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IACpE,QAAQ,CAAC,cAAc,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC;gBAJhD,aAAa,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC,OAAO,CAAC,EAC9D,YAAY,EAAE,CACrB,EAAE,EAAE,MAAM,KACP,OAAO,CAAC,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,EAC3D,cAAc,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC;IAO9C,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAUzD,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IA0C9D,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CASzD"}
|
|
@@ -53,7 +53,7 @@ var CustomSessionStorage = /** @class */ (function () {
|
|
|
53
53
|
return [2 /*return*/, result];
|
|
54
54
|
}
|
|
55
55
|
else if (result instanceof Object && 'id' in result) {
|
|
56
|
-
session = new session_1.Session(result.id);
|
|
56
|
+
session = new session_1.Session(result.id, result.shop, result.state, result.isOnline);
|
|
57
57
|
session = tslib_1.__assign(tslib_1.__assign({}, session), result);
|
|
58
58
|
if (session.expires && typeof session.expires === 'string') {
|
|
59
59
|
session.expires = new Date(session.expires);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../../src/auth/session/storage/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAElD,qBAAa,oBAAqB,YAAW,cAAc;IACzD,OAAO,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../../src/auth/session/storage/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAElD,qBAAa,oBAAqB,YAAW,cAAc;IACzD,OAAO,CAAC,QAAQ,CAAyC;IAE5C,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAKzD,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAI9D,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAMzD"}
|
|
@@ -3,9 +3,9 @@ export interface SessionInterface {
|
|
|
3
3
|
readonly id: string;
|
|
4
4
|
shop: string;
|
|
5
5
|
state: string;
|
|
6
|
-
|
|
6
|
+
isOnline: boolean;
|
|
7
|
+
scope?: string;
|
|
7
8
|
expires?: Date;
|
|
8
|
-
isOnline?: boolean;
|
|
9
9
|
accessToken?: string;
|
|
10
10
|
onlineAccessInfo?: OnlineAccessInfo;
|
|
11
11
|
isActive(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/auth/session/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/auth/session/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,QAAQ,IAAI,OAAO,CAAC;CACrB"}
|
package/dist/base_types.d.ts
CHANGED
package/dist/base_types.d.ts.map
CHANGED
|
@@ -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,OAAO,YAAY;IACnB,MAAM,YAAY;IAClB,SAAS,YAAY;IACrB,SAAS,YAAY;IACrB,OAAO,YAAY;IACnB,MAAM,YAAY;IAClB,SAAS,YAAY;IACrB,SAAS,YAAY;IACrB,OAAO,YAAY;IACnB,MAAM,YAAY;IAClB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;CAC5B;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,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,OAAO,YAAY;IACnB,MAAM,YAAY;IAClB,SAAS,YAAY;IACrB,SAAS,YAAY;IACrB,OAAO,YAAY;IACnB,MAAM,YAAY;IAClB,SAAS,YAAY;IACrB,SAAS,YAAY;IACrB,OAAO,YAAY;IACnB,MAAM,YAAY;IAClB,SAAS,YAAY;IACrB,SAAS,YAAY;IACrB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;CAC5B;AAED,oBAAY,aAAa;IACvB,WAAW,2BAA2B;IACtC,qBAAqB,sCAAsC;IAC3D,IAAI,0BAA0B;IAC9B,KAAK,oBAAoB;IACzB,MAAM,0BAA0B;CACjC"}
|
package/dist/base_types.js
CHANGED
|
@@ -13,6 +13,8 @@ var ApiVersion;
|
|
|
13
13
|
ApiVersion["January21"] = "2021-01";
|
|
14
14
|
ApiVersion["April21"] = "2021-04";
|
|
15
15
|
ApiVersion["July21"] = "2021-07";
|
|
16
|
+
ApiVersion["October21"] = "2021-10";
|
|
17
|
+
ApiVersion["January22"] = "2022-01";
|
|
16
18
|
ApiVersion["Unstable"] = "unstable";
|
|
17
19
|
ApiVersion["Unversioned"] = "unversioned";
|
|
18
20
|
})(ApiVersion = exports.ApiVersion || (exports.ApiVersion = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql_client.d.ts","sourceRoot":"","sources":["../../../src/clients/graphql/graphql_client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAW,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAG7D,OAAO,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAEtC,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,aAAa;IAKZ,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAE,QAAQ,CAAC,WAAW,CAAC;IAJ1D,SAAS,CAAC,WAAW,SAAgB;IAErC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;gBAEf,MAAM,EAAE,MAAM,EAAW,WAAW,CAAC,oBAAQ;
|
|
1
|
+
{"version":3,"file":"graphql_client.d.ts","sourceRoot":"","sources":["../../../src/clients/graphql/graphql_client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAW,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAG7D,OAAO,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAEtC,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,aAAa;IAKZ,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAE,QAAQ,CAAC,WAAW,CAAC;IAJ1D,SAAS,CAAC,WAAW,SAAgB;IAErC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;gBAEf,MAAM,EAAE,MAAM,EAAW,WAAW,CAAC,oBAAQ;IAU5D,KAAK,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAwB1D,SAAS,CAAC,oBAAoB,IAAI,iBAAiB;CAQpD"}
|
|
@@ -42,7 +42,9 @@ var GraphqlClient = /** @class */ (function () {
|
|
|
42
42
|
GraphqlClient.prototype.getAccessTokenHeader = function () {
|
|
43
43
|
return {
|
|
44
44
|
header: base_types_1.ShopifyHeader.AccessToken,
|
|
45
|
-
value: context_1.Context.IS_PRIVATE_APP
|
|
45
|
+
value: context_1.Context.IS_PRIVATE_APP
|
|
46
|
+
? context_1.Context.API_SECRET_KEY
|
|
47
|
+
: this.accessToken,
|
|
46
48
|
};
|
|
47
49
|
};
|
|
48
50
|
return GraphqlClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/clients/graphql/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE/C,QAAA,MAAM,oBAAoB;;CAEzB,CAAC;AAEF,eAAe,oBAAoB,CAAC;AAEpC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/clients/graphql/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE/C,QAAA,MAAM,oBAAoB;;CAEzB,CAAC;AAEF,eAAe,oBAAoB,CAAC;AAEpC,OAAO,EAAC,aAAa,EAAC,CAAC"}
|
|
@@ -15,7 +15,9 @@ var StorefrontClient = /** @class */ (function (_super) {
|
|
|
15
15
|
StorefrontClient.prototype.getAccessTokenHeader = function () {
|
|
16
16
|
return {
|
|
17
17
|
header: base_types_1.ShopifyHeader.StorefrontAccessToken,
|
|
18
|
-
value: (context_1.Context.IS_PRIVATE_APP
|
|
18
|
+
value: (context_1.Context.IS_PRIVATE_APP
|
|
19
|
+
? context_1.Context.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN || this.accessToken
|
|
20
|
+
: this.accessToken),
|
|
19
21
|
};
|
|
20
22
|
};
|
|
21
23
|
return StorefrontClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http_client.d.ts","sourceRoot":"","sources":["../../../src/clients/http_client/http_client.ts"],"names":[],"mappings":"AAYA,OAAO,EAEL,gBAAgB,EACh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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;YA4GxD,SAAS;CAgGxB;AAED,OAAO,EAAC,UAAU,EAAC,CAAC"}
|
|
@@ -101,7 +101,10 @@ var HttpClient = /** @class */ (function () {
|
|
|
101
101
|
body = typeof data === 'string' ? data : JSON.stringify(data);
|
|
102
102
|
break;
|
|
103
103
|
case types_1.DataType.URLEncoded:
|
|
104
|
-
body =
|
|
104
|
+
body =
|
|
105
|
+
typeof data === 'string'
|
|
106
|
+
? data
|
|
107
|
+
: querystring_1.default.stringify(data);
|
|
105
108
|
break;
|
|
106
109
|
case types_1.DataType.GraphQL:
|
|
107
110
|
body = data;
|
|
@@ -110,7 +113,9 @@ var HttpClient = /** @class */ (function () {
|
|
|
110
113
|
headers = tslib_1.__assign({ 'Content-Type': type, 'Content-Length': Buffer.byteLength(body) }, params.extraHeaders);
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
|
-
queryString = params.query
|
|
116
|
+
queryString = params.query
|
|
117
|
+
? "?" + querystring_1.default.stringify(params.query)
|
|
118
|
+
: '';
|
|
114
119
|
url = "https://" + this.domain + params.path + queryString;
|
|
115
120
|
options = {
|
|
116
121
|
method: params.method.toString(),
|
|
@@ -132,7 +137,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
132
137
|
if (!(error_1 instanceof ShopifyErrors.HttpRetriableError)) return [3 /*break*/, 7];
|
|
133
138
|
if (!(tries < maxTries)) return [3 /*break*/, 6];
|
|
134
139
|
waitTime = HttpClient.RETRY_WAIT_TIME;
|
|
135
|
-
if (error_1 instanceof ShopifyErrors.HttpThrottlingError &&
|
|
140
|
+
if (error_1 instanceof ShopifyErrors.HttpThrottlingError &&
|
|
141
|
+
error_1.retryAfter) {
|
|
136
142
|
waitTime = error_1.retryAfter * 1000;
|
|
137
143
|
}
|
|
138
144
|
return [4 /*yield*/, sleep(waitTime)];
|
|
@@ -170,19 +176,27 @@ var HttpClient = /** @class */ (function () {
|
|
|
170
176
|
case 1:
|
|
171
177
|
body = _a.sent();
|
|
172
178
|
if (response.ok) {
|
|
173
|
-
if (response.headers &&
|
|
179
|
+
if (response.headers &&
|
|
180
|
+
response.headers.has('X-Shopify-API-Deprecated-Reason')) {
|
|
174
181
|
deprecation = {
|
|
175
182
|
message: response.headers.get('X-Shopify-API-Deprecated-Reason'),
|
|
176
183
|
path: url,
|
|
177
184
|
};
|
|
178
|
-
depHash = crypto_1.default
|
|
185
|
+
depHash = crypto_1.default
|
|
186
|
+
.createHash('md5')
|
|
187
|
+
.update(JSON.stringify(deprecation))
|
|
188
|
+
.digest('hex');
|
|
179
189
|
if (!Object.keys(this.LOGGED_DEPRECATIONS).includes(depHash) ||
|
|
180
|
-
Date.now() - this.LOGGED_DEPRECATIONS[depHash] >=
|
|
190
|
+
Date.now() - this.LOGGED_DEPRECATIONS[depHash] >=
|
|
191
|
+
HttpClient.DEPRECATION_ALERT_DELAY) {
|
|
181
192
|
this.LOGGED_DEPRECATIONS[depHash] = Date.now();
|
|
182
193
|
if (context_1.Context.LOG_FILE) {
|
|
183
194
|
stack = new Error().stack;
|
|
184
195
|
log = "API Deprecation Notice " + new Date().toLocaleString() + " : " + JSON.stringify(deprecation) + "\n Stack Trace: " + stack + "\n";
|
|
185
|
-
fs_1.default.writeFileSync(context_1.Context.LOG_FILE, log, {
|
|
196
|
+
fs_1.default.writeFileSync(context_1.Context.LOG_FILE, log, {
|
|
197
|
+
flag: 'a',
|
|
198
|
+
encoding: 'utf-8',
|
|
199
|
+
});
|
|
186
200
|
}
|
|
187
201
|
else {
|
|
188
202
|
console.warn('API Deprecation Notice:', deprecation);
|
|
@@ -197,12 +211,14 @@ var HttpClient = /** @class */ (function () {
|
|
|
197
211
|
else {
|
|
198
212
|
errorMessages = [];
|
|
199
213
|
if (body.errors) {
|
|
200
|
-
errorMessages.push(body.errors);
|
|
214
|
+
errorMessages.push(JSON.stringify(body.errors, null, 2));
|
|
201
215
|
}
|
|
202
216
|
if (response.headers && response.headers.get('x-request-id')) {
|
|
203
217
|
errorMessages.push("If you report this error, please include this id: " + response.headers.get('x-request-id'));
|
|
204
218
|
}
|
|
205
|
-
errorMessage = errorMessages.length
|
|
219
|
+
errorMessage = errorMessages.length
|
|
220
|
+
? ":\n" + errorMessages.join('\n')
|
|
221
|
+
: '';
|
|
206
222
|
switch (true) {
|
|
207
223
|
case response.status === network_1.StatusCode.TooManyRequests: {
|
|
208
224
|
retryAfter = response.headers.get('Retry-After');
|
|
@@ -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,oBAAY,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;AAE3D,oBAAY,QAAQ;IAClB,IAAI,qBAAqB;IACzB,OAAO,wBAAwB;IAC/B,UAAU,sCAAsC;CACjD;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IACxC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,oBAAY,iBAAiB,GAAG,gBAAgB,GAAG;IACjD,IAAI,EAAE,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,GAAG;IACnE,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
|
@@ -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;
|
|
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;IA2D1E,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,kBAAkB;CAa3B;AAED,OAAO,EAAC,UAAU,EAAC,CAAC"}
|
|
@@ -24,7 +24,9 @@ var RestClient = /** @class */ (function (_super) {
|
|
|
24
24
|
return tslib_1.__generator(this, function (_c) {
|
|
25
25
|
switch (_c.label) {
|
|
26
26
|
case 0:
|
|
27
|
-
params.extraHeaders = tslib_1.__assign((_a = {}, _a[base_types_1.ShopifyHeader.AccessToken] = context_1.Context.IS_PRIVATE_APP
|
|
27
|
+
params.extraHeaders = tslib_1.__assign((_a = {}, _a[base_types_1.ShopifyHeader.AccessToken] = context_1.Context.IS_PRIVATE_APP
|
|
28
|
+
? context_1.Context.API_SECRET_KEY
|
|
29
|
+
: this.accessToken, _a), params.extraHeaders);
|
|
28
30
|
params.path = this.getRestPath(params.path);
|
|
29
31
|
return [4 /*yield*/, _super.prototype.request.call(this, params)];
|
|
30
32
|
case 1:
|
|
@@ -32,7 +34,9 @@ var RestClient = /** @class */ (function (_super) {
|
|
|
32
34
|
link = ret.headers.get('link');
|
|
33
35
|
if (params.query && link !== undefined) {
|
|
34
36
|
pageInfo = {
|
|
35
|
-
limit: params.query.limit
|
|
37
|
+
limit: params.query.limit
|
|
38
|
+
? params.query.limit.toString()
|
|
39
|
+
: RestClient.DEFAULT_LIMIT,
|
|
36
40
|
};
|
|
37
41
|
if (link) {
|
|
38
42
|
links = link.split(', ');
|
package/dist/context.d.ts.map
CHANGED
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,gCAAgC,CAAC;AAE9D,OAAO,EAAa,aAAa,EAAC,MAAM,cAAc,CAAC;AACvD,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC,UAAU,gBAAiB,SAAQ,aAAa;IAC9C,eAAe,EAAE,cAAc,CAAC;IAChC,MAAM,EAAE,UAAU,CAAC;IAEnB;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IAExC;;OAEG;IACH,oBAAoB,IAAI,IAAI,GAAG,KAAK,CAAC;IAErC;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;CAClD;AAED,QAAA,MAAM,OAAO,EAAE,gBAgFd,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,gBAAgB,EAAC,CAAC"}
|
package/dist/context.js
CHANGED
|
@@ -57,7 +57,8 @@ var Context = {
|
|
|
57
57
|
this.LOG_FILE = params.LOG_FILE;
|
|
58
58
|
}
|
|
59
59
|
if (params.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN) {
|
|
60
|
-
this.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN =
|
|
60
|
+
this.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN =
|
|
61
|
+
params.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN;
|
|
61
62
|
}
|
|
62
63
|
},
|
|
63
64
|
throwIfUninitialized: function () {
|
package/dist/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d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AY;CAAG;AAChD,cAAM,iBAAkB,SAAQ,kBAAkB;CAAG;AACrD,cAAM,mBAAoB,SAAQ,kBAAkB;IACd,QAAQ,CAAC,UAAU,CAAC;gBAArC,OAAO,EAAE,MAAM,EAAW,UAAU,CAAC,oBAAQ;CAGjE;AAED,cAAM,iBAAkB,SAAQ,YAAY;CAAG;AAC/C,cAAM,eAAgB,SAAQ,YAAY;CAAG;AAC7C,cAAM,cAAe,SAAQ,YAAY;CAAG;AAC5C,cAAM,cAAe,SAAQ,YAAY;CAAG;AAE5C,cAAM,mBAAoB,SAAQ,YAAY;CAAG;AACjD,cAAM,mBAAoB,SAAQ,YAAY;CAAG;AAEjD,cAAM,uBAAwB,SAAQ,YAAY;CAAG;AACrD,cAAM,qBAAsB,SAAQ,YAAY;CAAG;AAEnD,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,GAChB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const Shopify: {
|
|
|
5
5
|
Auth: {
|
|
6
6
|
SESSION_COOKIE_NAME: string;
|
|
7
7
|
beginAuth(request: import("http").IncomingMessage, response: import("http").ServerResponse, shop: string, redirectPath: string, isOnline?: boolean): Promise<string>;
|
|
8
|
-
validateAuthCallback(request: import("http").IncomingMessage, response: import("http").ServerResponse, query: import("./types").AuthQuery): Promise<
|
|
8
|
+
validateAuthCallback(request: import("http").IncomingMessage, response: import("http").ServerResponse, query: import("./types").AuthQuery): Promise<import("./types").SessionInterface>;
|
|
9
9
|
getCookieSessionId(request: import("http").IncomingMessage, response: import("http").ServerResponse): string | undefined;
|
|
10
10
|
getJwtSessionId(shop: string, userId: string): string;
|
|
11
11
|
getOfflineSessionId(shop: string): string;
|
|
@@ -16,5 +16,5 @@ interface JwtPayload {
|
|
|
16
16
|
*/
|
|
17
17
|
declare function decodeSessionToken(token: string): JwtPayload;
|
|
18
18
|
export default decodeSessionToken;
|
|
19
|
-
export { decodeSessionToken, JwtPayload
|
|
19
|
+
export { decodeSessionToken, JwtPayload };
|
|
20
20
|
//# sourceMappingURL=decode-session-token.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode-session-token.d.ts","sourceRoot":"","sources":["../../src/utils/decode-session-token.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decode-session-token.d.ts","sourceRoot":"","sources":["../../src/utils/decode-session-token.ts"],"names":[],"mappings":"AASA,UAAU,UAAU;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;GAIG;AACH,iBAAS,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CA0BrD;AAED,eAAe,kBAAkB,CAAC;AAElC,OAAO,EAAC,kBAAkB,EAAE,UAAU,EAAC,CAAC"}
|
|
@@ -6,6 +6,7 @@ var jsonwebtoken_1 = tslib_1.__importDefault(require("jsonwebtoken"));
|
|
|
6
6
|
var context_1 = require("../context");
|
|
7
7
|
var ShopifyErrors = tslib_1.__importStar(require("../error"));
|
|
8
8
|
var shop_validator_1 = tslib_1.__importDefault(require("./shop-validator"));
|
|
9
|
+
var JWT_PERMITTED_CLOCK_TOLERANCE = 5;
|
|
9
10
|
/**
|
|
10
11
|
* Decodes the given session token, and extracts the session information from it
|
|
11
12
|
*
|
|
@@ -14,7 +15,10 @@ var shop_validator_1 = tslib_1.__importDefault(require("./shop-validator"));
|
|
|
14
15
|
function decodeSessionToken(token) {
|
|
15
16
|
var payload;
|
|
16
17
|
try {
|
|
17
|
-
payload = jsonwebtoken_1.default.verify(token, context_1.Context.API_SECRET_KEY, {
|
|
18
|
+
payload = jsonwebtoken_1.default.verify(token, context_1.Context.API_SECRET_KEY, {
|
|
19
|
+
algorithms: ['HS256'],
|
|
20
|
+
clockTolerance: JWT_PERMITTED_CLOCK_TOLERANCE,
|
|
21
|
+
});
|
|
18
22
|
}
|
|
19
23
|
catch (error) {
|
|
20
24
|
throw new ShopifyErrors.InvalidJwtError("Failed to parse session token '" + token + "': " + error.message);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-current-session.d.ts","sourceRoot":"","sources":["../../src/utils/delete-current-session.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAMxB;;;;;;GAMG;AACH,wBAA8B,oBAAoB,CAChD,OAAO,EAAE,IAAI,CAAC,eAAe,EAC7B,QAAQ,EAAE,IAAI,CAAC,cAAc,EAC7B,QAAQ,UAAO,GACd,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"delete-current-session.d.ts","sourceRoot":"","sources":["../../src/utils/delete-current-session.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAMxB;;;;;;GAMG;AACH,wBAA8B,oBAAoB,CAChD,OAAO,EAAE,IAAI,CAAC,eAAe,EAC7B,QAAQ,EAAE,IAAI,CAAC,cAAc,EAC7B,QAAQ,UAAO,GACd,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,CAa1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-offline-session.d.ts","sourceRoot":"","sources":["../../src/utils/delete-offline-session.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAA8B,oBAAoB,
|
|
1
|
+
{"version":3,"file":"delete-offline-session.d.ts","sourceRoot":"","sources":["../../src/utils/delete-offline-session.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAA8B,oBAAoB,CAChD,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,OAAO,CAAC,CAMlB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql_proxy.d.ts","sourceRoot":"","sources":["../../src/utils/graphql_proxy.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAOxB,wBAA8B,YAAY,
|
|
1
|
+
{"version":3,"file":"graphql_proxy.d.ts","sourceRoot":"","sources":["../../src/utils/graphql_proxy.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAOxB,wBAA8B,YAAY,CACxC,OAAO,EAAE,IAAI,CAAC,eAAe,EAC7B,OAAO,EAAE,IAAI,CAAC,cAAc,GAC3B,OAAO,CAAC,IAAI,CAAC,CA+Df"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AuthQuery } from '../auth/oauth/types';
|
|
2
2
|
export declare function stringifyQuery(query: AuthQuery): string;
|
|
3
|
-
export declare function generateLocalHmac({ code, timestamp, state, shop, host }: AuthQuery): string;
|
|
3
|
+
export declare function generateLocalHmac({ code, timestamp, state, shop, host, }: AuthQuery): string;
|
|
4
4
|
/**
|
|
5
5
|
* Uses the received query to validate the contained hmac value against the rest of the query content.
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmac-validator.d.ts","sourceRoot":"","sources":["../../src/utils/hmac-validator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAM9C,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAQvD;AAED,wBAAgB,iBAAiB,CAAC,
|
|
1
|
+
{"version":3,"file":"hmac-validator.d.ts","sourceRoot":"","sources":["../../src/utils/hmac-validator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAM9C,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAQvD;AAED,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,SAAS,EACT,KAAK,EACL,IAAI,EACJ,IAAI,GACL,EAAE,SAAS,GAAG,MAAM,CAYpB;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAU9D"}
|
|
@@ -19,7 +19,10 @@ function stringifyQuery(query) {
|
|
|
19
19
|
exports.stringifyQuery = stringifyQuery;
|
|
20
20
|
function generateLocalHmac(_a) {
|
|
21
21
|
var code = _a.code, timestamp = _a.timestamp, state = _a.state, shop = _a.shop, host = _a.host;
|
|
22
|
-
var queryString = stringifyQuery(tslib_1.__assign({ code: code,
|
|
22
|
+
var queryString = stringifyQuery(tslib_1.__assign({ code: code,
|
|
23
|
+
timestamp: timestamp,
|
|
24
|
+
state: state,
|
|
25
|
+
shop: shop }, host && { host: host }));
|
|
23
26
|
return crypto_1.default
|
|
24
27
|
.createHmac('sha256', context_1.Context.API_SECRET_KEY)
|
|
25
28
|
.update(queryString)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-current-session.d.ts","sourceRoot":"","sources":["../../src/utils/load-current-session.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,OAAO,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAC;AAExC;;;;;;GAMG;AACH,wBAA8B,kBAAkB,CAC9C,OAAO,EAAE,IAAI,CAAC,eAAe,EAC7B,QAAQ,EAAE,IAAI,CAAC,cAAc,EAC7B,QAAQ,UAAO,GACd,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"load-current-session.d.ts","sourceRoot":"","sources":["../../src/utils/load-current-session.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,OAAO,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAC;AAExC;;;;;;GAMG;AACH,wBAA8B,kBAAkB,CAC9C,OAAO,EAAE,IAAI,CAAC,eAAe,EAC7B,QAAQ,EAAE,IAAI,CAAC,cAAc,EAC7B,QAAQ,UAAO,GACd,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAa9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-offline-session.d.ts","sourceRoot":"","sources":["../../src/utils/load-offline-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,yBAAyB,CAAC;AAIhD;;;;;;;GAOG;AACH,wBAA8B,kBAAkB,
|
|
1
|
+
{"version":3,"file":"load-offline-session.d.ts","sourceRoot":"","sources":["../../src/utils/load-offline-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,yBAAyB,CAAC;AAIhD;;;;;;;GAOG;AACH,wBAA8B,kBAAkB,CAC9C,IAAI,EAAE,MAAM,EACZ,cAAc,UAAQ,GACrB,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAkB9B"}
|
|
@@ -24,7 +24,10 @@ function loadOfflineSession(shop, includeExpired) {
|
|
|
24
24
|
case 1:
|
|
25
25
|
session = _a.sent();
|
|
26
26
|
now = new Date();
|
|
27
|
-
if (session &&
|
|
27
|
+
if (session &&
|
|
28
|
+
!includeExpired &&
|
|
29
|
+
session.expires &&
|
|
30
|
+
session.expires.getTime() < now.getTime()) {
|
|
28
31
|
return [2 /*return*/, undefined];
|
|
29
32
|
}
|
|
30
33
|
return [2 /*return*/, session];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-compatible.d.ts","sourceRoot":"","sources":["../../src/utils/version-compatible.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,
|
|
1
|
+
{"version":3,"file":"version-compatible.d.ts","sourceRoot":"","sources":["../../src/utils/version-compatible.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,gBAAgB,EAAE,UAAU,EAC5B,cAAc,GAAE,UAAgC,GAC/C,OAAO,CAaT"}
|
|
@@ -8,10 +8,13 @@ var base_types_1 = require("../base_types");
|
|
|
8
8
|
function versionCompatible(referenceVersion, currentVersion) {
|
|
9
9
|
if (currentVersion === void 0) { currentVersion = context_1.Context.API_VERSION; }
|
|
10
10
|
// Return true if not using a dated version
|
|
11
|
-
if (currentVersion === base_types_1.ApiVersion.Unstable ||
|
|
11
|
+
if (currentVersion === base_types_1.ApiVersion.Unstable ||
|
|
12
|
+
currentVersion === base_types_1.ApiVersion.Unversioned) {
|
|
12
13
|
return true;
|
|
13
14
|
}
|
|
14
|
-
var numericVersion = function (version) {
|
|
15
|
+
var numericVersion = function (version) {
|
|
16
|
+
return parseInt(version.replace('-', ''), 10);
|
|
17
|
+
};
|
|
15
18
|
var current = numericVersion(currentVersion);
|
|
16
19
|
var reference = numericVersion(referenceVersion);
|
|
17
20
|
return current >= reference;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-session.d.ts","sourceRoot":"","sources":["../../src/utils/with-session.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,iBAAiB,EAAE,mBAAmB,EAAC,MAAM,SAAS,CAAC;AAI/D,wBAA8B,WAAW,CAAC,EACxC,UAAU,EACV,QAAQ,EACR,GAAG,EACH,GAAG,EACH,IAAI,GACL,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC,
|
|
1
|
+
{"version":3,"file":"with-session.d.ts","sourceRoot":"","sources":["../../src/utils/with-session.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,iBAAiB,EAAE,mBAAmB,EAAC,MAAM,SAAS,CAAC;AAI/D,wBAA8B,WAAW,CAAC,EACxC,UAAU,EACV,QAAQ,EACR,GAAG,EACH,GAAG,EACH,IAAI,GACL,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAiDlD"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SHOPIFY_API_LIBRARY_VERSION = "1.
|
|
1
|
+
export declare const SHOPIFY_API_LIBRARY_VERSION = "2.1.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -1,14 +1,48 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import http from 'http';
|
|
3
|
-
import { DeliveryMethod, RegisterOptions, RegisterReturn, WebhookRegistryEntry } from './types';
|
|
3
|
+
import { DeliveryMethod, RegisterOptions, RegisterReturn, WebhookRegistryEntry, ShortenedRegisterOptions } from './types';
|
|
4
|
+
interface AddHandlersProps {
|
|
5
|
+
[topic: string]: WebhookRegistryEntry;
|
|
6
|
+
}
|
|
4
7
|
interface RegistryInterface {
|
|
5
|
-
webhookRegistry:
|
|
8
|
+
webhookRegistry: {
|
|
9
|
+
[topic: string]: WebhookRegistryEntry;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Sets the handler for the given topic. If a handler was previously set for the same topic, it will be overridden.
|
|
13
|
+
*
|
|
14
|
+
* @param topic String used to add a handler
|
|
15
|
+
* @param options Paramters to add a handler which are path and webHookHandler
|
|
16
|
+
*/
|
|
17
|
+
addHandler(topic: string, options: WebhookRegistryEntry): void;
|
|
18
|
+
/**
|
|
19
|
+
* Sets a list of handlers for the given topics using the `addHandler` function
|
|
20
|
+
*
|
|
21
|
+
* @param handlers Object in format {topic: WebhookRegistryEntry}
|
|
22
|
+
*/
|
|
23
|
+
addHandlers(handlers: AddHandlersProps): void;
|
|
24
|
+
/**
|
|
25
|
+
* Fetches the handler for the given topic. Returns null if no handler was registered.
|
|
26
|
+
*
|
|
27
|
+
* @param topic The topic to check
|
|
28
|
+
*/
|
|
29
|
+
getHandler(topic: string): WebhookRegistryEntry | null;
|
|
30
|
+
/**
|
|
31
|
+
* Gets all topics
|
|
32
|
+
*/
|
|
33
|
+
getTopics(): string[];
|
|
6
34
|
/**
|
|
7
35
|
* Registers a Webhook Handler function for a given topic.
|
|
8
36
|
*
|
|
9
|
-
* @param options Parameters to register a handler, including topic, listening address,
|
|
37
|
+
* @param options Parameters to register a handler, including topic, listening address, delivery method
|
|
10
38
|
*/
|
|
11
39
|
register(options: RegisterOptions): Promise<RegisterReturn>;
|
|
40
|
+
/**
|
|
41
|
+
* Registers multiple Webhook Handler functions.
|
|
42
|
+
*
|
|
43
|
+
* @param options Parameters to register a handler, including topic, listening address, delivery method
|
|
44
|
+
*/
|
|
45
|
+
registerAll(options: ShortenedRegisterOptions): Promise<RegisterReturn>;
|
|
12
46
|
/**
|
|
13
47
|
* Processes the webhook request received from the Shopify API
|
|
14
48
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/webhooks/registry.ts"],"names":[],"mappings":";AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAUxB,OAAO,EACL,cAAc,EACd,eAAe,EACf,cAAc,EACd,oBAAoB,
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/webhooks/registry.ts"],"names":[],"mappings":";AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAUxB,OAAO,EACL,cAAc,EACd,eAAe,EACf,cAAc,EACd,oBAAoB,EAGpB,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB,UAAU,gBAAgB;IACxB,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB,CAAC;CACvC;A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}
|
|
40
40
|
function validateDeliveryMethod(deliveryMethod) {
|
|
41
|
-
if (deliveryMethod === types_1.DeliveryMethod.EventBridge &&
|
|
41
|
+
if (deliveryMethod === types_1.DeliveryMethod.EventBridge &&
|
|
42
|
+
!versionSupportsEndpointField()) {
|
|
42
43
|
throw new ShopifyErrors.UnsupportedClientType("EventBridge webhooks are not supported in API version \"" + context_1.Context.API_VERSION + "\".");
|
|
43
44
|
}
|
|
44
|
-
else if (deliveryMethod === types_1.DeliveryMethod.PubSub &&
|
|
45
|
+
else if (deliveryMethod === types_1.DeliveryMethod.PubSub &&
|
|
46
|
+
!versionSupportsPubSub()) {
|
|
45
47
|
throw new ShopifyErrors.UnsupportedClientType("Pub/Sub webhooks are not supported in API version \"" + context_1.Context.API_VERSION + "\".");
|
|
46
48
|
}
|
|
47
49
|
}
|
|
@@ -73,16 +75,24 @@ function buildQuery(topic, address, deliveryMethod, webhookId) {
|
|
|
73
75
|
var pubSubTopic;
|
|
74
76
|
switch (deliveryMethod) {
|
|
75
77
|
case types_1.DeliveryMethod.Http:
|
|
76
|
-
mutationName = webhookId
|
|
78
|
+
mutationName = webhookId
|
|
79
|
+
? 'webhookSubscriptionUpdate'
|
|
80
|
+
: 'webhookSubscriptionCreate';
|
|
77
81
|
webhookSubscriptionArgs = "{callbackUrl: \"" + address + "\"}";
|
|
78
82
|
break;
|
|
79
83
|
case types_1.DeliveryMethod.EventBridge:
|
|
80
|
-
mutationName = webhookId
|
|
84
|
+
mutationName = webhookId
|
|
85
|
+
? 'eventBridgeWebhookSubscriptionUpdate'
|
|
86
|
+
: 'eventBridgeWebhookSubscriptionCreate';
|
|
81
87
|
webhookSubscriptionArgs = "{arn: \"" + address + "\"}";
|
|
82
88
|
break;
|
|
83
89
|
case types_1.DeliveryMethod.PubSub:
|
|
84
|
-
mutationName = webhookId
|
|
85
|
-
|
|
90
|
+
mutationName = webhookId
|
|
91
|
+
? 'pubSubWebhookSubscriptionUpdate'
|
|
92
|
+
: 'pubSubWebhookSubscriptionCreate';
|
|
93
|
+
_a = tslib_1.__read(address
|
|
94
|
+
.replace(/^pubsub:\/\//, '')
|
|
95
|
+
.split(':'), 2), pubSubProject = _a[0], pubSubTopic = _a[1];
|
|
86
96
|
webhookSubscriptionArgs = "{pubSubProject: \"" + pubSubProject + "\",\n pubSubTopic: \"" + pubSubTopic + "\"}";
|
|
87
97
|
break;
|
|
88
98
|
}
|
|
@@ -90,14 +100,32 @@ function buildQuery(topic, address, deliveryMethod, webhookId) {
|
|
|
90
100
|
}
|
|
91
101
|
exports.buildQuery = buildQuery;
|
|
92
102
|
var WebhooksRegistry = {
|
|
93
|
-
webhookRegistry:
|
|
103
|
+
webhookRegistry: {},
|
|
104
|
+
addHandler: function (topic, _a) {
|
|
105
|
+
var path = _a.path, webhookHandler = _a.webhookHandler;
|
|
106
|
+
WebhooksRegistry.webhookRegistry[topic] = { path: path, webhookHandler: webhookHandler };
|
|
107
|
+
},
|
|
108
|
+
addHandlers: function (handlers) {
|
|
109
|
+
for (var topic in handlers) {
|
|
110
|
+
if ({}.hasOwnProperty.call(handlers, topic)) {
|
|
111
|
+
WebhooksRegistry.addHandler(topic, handlers[topic]);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
getHandler: function (topic) {
|
|
116
|
+
return topic in WebhooksRegistry.webhookRegistry ? WebhooksRegistry.webhookRegistry[topic] : null;
|
|
117
|
+
},
|
|
118
|
+
getTopics: function () {
|
|
119
|
+
return Object.keys(WebhooksRegistry.webhookRegistry);
|
|
120
|
+
},
|
|
94
121
|
register: function (_a) {
|
|
95
|
-
var path = _a.path, topic = _a.topic, accessToken = _a.accessToken, shop = _a.shop, _b = _a.deliveryMethod, deliveryMethod = _b === void 0 ? types_1.DeliveryMethod.Http : _b
|
|
122
|
+
var path = _a.path, topic = _a.topic, accessToken = _a.accessToken, shop = _a.shop, _b = _a.deliveryMethod, deliveryMethod = _b === void 0 ? types_1.DeliveryMethod.Http : _b;
|
|
96
123
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
97
|
-
var client, address, checkResult, webhookId, mustRegister, node, endpointAddress,
|
|
124
|
+
var registerReturn, client, address, checkResult, webhookId, mustRegister, node, endpointAddress, result;
|
|
98
125
|
return tslib_1.__generator(this, function (_c) {
|
|
99
126
|
switch (_c.label) {
|
|
100
127
|
case 0:
|
|
128
|
+
registerReturn = {};
|
|
101
129
|
validateDeliveryMethod(deliveryMethod);
|
|
102
130
|
client = new graphql_client_1.GraphqlClient(shop, accessToken);
|
|
103
131
|
address = deliveryMethod === types_1.DeliveryMethod.Http
|
|
@@ -107,7 +135,7 @@ var WebhooksRegistry = {
|
|
|
107
135
|
data: buildCheckQuery(topic),
|
|
108
136
|
})];
|
|
109
137
|
case 1:
|
|
110
|
-
checkResult = _c.sent();
|
|
138
|
+
checkResult = (_c.sent());
|
|
111
139
|
mustRegister = true;
|
|
112
140
|
if (checkResult.body.data.webhookSubscriptions.edges.length) {
|
|
113
141
|
node = checkResult.body.data.webhookSubscriptions.edges[0].node;
|
|
@@ -134,20 +162,70 @@ var WebhooksRegistry = {
|
|
|
134
162
|
})];
|
|
135
163
|
case 2:
|
|
136
164
|
result = _c.sent();
|
|
137
|
-
|
|
138
|
-
|
|
165
|
+
registerReturn[topic] = {
|
|
166
|
+
success: isSuccess(result.body, deliveryMethod, webhookId),
|
|
167
|
+
result: result.body,
|
|
168
|
+
};
|
|
139
169
|
return [3 /*break*/, 4];
|
|
140
170
|
case 3:
|
|
141
|
-
|
|
142
|
-
|
|
171
|
+
registerReturn[topic] = {
|
|
172
|
+
success: true,
|
|
173
|
+
result: {},
|
|
174
|
+
};
|
|
143
175
|
_c.label = 4;
|
|
176
|
+
case 4: return [2 /*return*/, registerReturn];
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
registerAll: function (_a) {
|
|
182
|
+
var accessToken = _a.accessToken, shop = _a.shop, _b = _a.deliveryMethod, deliveryMethod = _b === void 0 ? types_1.DeliveryMethod.Http : _b;
|
|
183
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
184
|
+
var registerReturn, topics, topics_1, topics_1_1, topic, handler, path, webhook, returnedRegister, e_1_1;
|
|
185
|
+
var e_1, _c;
|
|
186
|
+
return tslib_1.__generator(this, function (_d) {
|
|
187
|
+
switch (_d.label) {
|
|
188
|
+
case 0:
|
|
189
|
+
registerReturn = {};
|
|
190
|
+
topics = WebhooksRegistry.getTopics();
|
|
191
|
+
_d.label = 1;
|
|
192
|
+
case 1:
|
|
193
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
194
|
+
topics_1 = tslib_1.__values(topics), topics_1_1 = topics_1.next();
|
|
195
|
+
_d.label = 2;
|
|
196
|
+
case 2:
|
|
197
|
+
if (!!topics_1_1.done) return [3 /*break*/, 5];
|
|
198
|
+
topic = topics_1_1.value;
|
|
199
|
+
handler = WebhooksRegistry.getHandler(topic);
|
|
200
|
+
if (!handler) return [3 /*break*/, 4];
|
|
201
|
+
path = handler.path;
|
|
202
|
+
webhook = {
|
|
203
|
+
path: path,
|
|
204
|
+
topic: topic,
|
|
205
|
+
accessToken: accessToken,
|
|
206
|
+
shop: shop,
|
|
207
|
+
deliveryMethod: deliveryMethod,
|
|
208
|
+
};
|
|
209
|
+
return [4 /*yield*/, WebhooksRegistry.register(webhook)];
|
|
210
|
+
case 3:
|
|
211
|
+
returnedRegister = _d.sent();
|
|
212
|
+
registerReturn = tslib_1.__assign(tslib_1.__assign({}, registerReturn), returnedRegister);
|
|
213
|
+
_d.label = 4;
|
|
144
214
|
case 4:
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
215
|
+
topics_1_1 = topics_1.next();
|
|
216
|
+
return [3 /*break*/, 2];
|
|
217
|
+
case 5: return [3 /*break*/, 8];
|
|
218
|
+
case 6:
|
|
219
|
+
e_1_1 = _d.sent();
|
|
220
|
+
e_1 = { error: e_1_1 };
|
|
221
|
+
return [3 /*break*/, 8];
|
|
222
|
+
case 7:
|
|
223
|
+
try {
|
|
224
|
+
if (topics_1_1 && !topics_1_1.done && (_c = topics_1.return)) _c.call(topics_1);
|
|
149
225
|
}
|
|
150
|
-
|
|
226
|
+
finally { if (e_1) throw e_1.error; }
|
|
227
|
+
return [7 /*endfinally*/];
|
|
228
|
+
case 8: return [2 /*return*/, registerReturn];
|
|
151
229
|
}
|
|
152
230
|
});
|
|
153
231
|
});
|
|
@@ -163,7 +241,7 @@ var WebhooksRegistry = {
|
|
|
163
241
|
reqBody += chunk;
|
|
164
242
|
});
|
|
165
243
|
request.on('end', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
166
|
-
var hmac, topic, domain, missingHeaders, statusCode, responseError, headers, generatedHash,
|
|
244
|
+
var hmac, topic, domain, missingHeaders, statusCode, responseError, headers, generatedHash, graphqlTopic, webhookEntry, error_1;
|
|
167
245
|
return tslib_1.__generator(this, function (_a) {
|
|
168
246
|
switch (_a.label) {
|
|
169
247
|
case 0:
|
|
@@ -206,13 +284,13 @@ var WebhooksRegistry = {
|
|
|
206
284
|
.update(reqBody, 'utf8')
|
|
207
285
|
.digest('base64');
|
|
208
286
|
if (!utils_1.default.safeCompare(generatedHash, hmac)) return [3 /*break*/, 7];
|
|
209
|
-
|
|
210
|
-
webhookEntry = WebhooksRegistry.
|
|
287
|
+
graphqlTopic = topic.toUpperCase().replace(/\//g, '_');
|
|
288
|
+
webhookEntry = WebhooksRegistry.getHandler(graphqlTopic);
|
|
211
289
|
if (!webhookEntry) return [3 /*break*/, 5];
|
|
212
290
|
_a.label = 1;
|
|
213
291
|
case 1:
|
|
214
292
|
_a.trys.push([1, 3, , 4]);
|
|
215
|
-
return [4 /*yield*/, webhookEntry.webhookHandler(
|
|
293
|
+
return [4 /*yield*/, webhookEntry.webhookHandler(graphqlTopic, domain, reqBody)];
|
|
216
294
|
case 2:
|
|
217
295
|
_a.sent();
|
|
218
296
|
statusCode = network_1.StatusCode.Ok;
|
|
@@ -251,7 +329,12 @@ var WebhooksRegistry = {
|
|
|
251
329
|
});
|
|
252
330
|
},
|
|
253
331
|
isWebhookPath: function (path) {
|
|
254
|
-
|
|
332
|
+
for (var key in WebhooksRegistry.webhookRegistry) {
|
|
333
|
+
if (WebhooksRegistry.webhookRegistry[key].path === path) {
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return false;
|
|
255
338
|
},
|
|
256
339
|
};
|
|
257
340
|
exports.WebhooksRegistry = WebhooksRegistry;
|
package/dist/webhooks/types.d.ts
CHANGED
|
@@ -9,16 +9,21 @@ export interface RegisterOptions {
|
|
|
9
9
|
path: string;
|
|
10
10
|
shop: string;
|
|
11
11
|
accessToken: string;
|
|
12
|
-
|
|
12
|
+
deliveryMethod?: DeliveryMethod;
|
|
13
|
+
}
|
|
14
|
+
export interface ShortenedRegisterOptions {
|
|
15
|
+
shop: string;
|
|
16
|
+
accessToken: string;
|
|
13
17
|
deliveryMethod?: DeliveryMethod;
|
|
14
18
|
}
|
|
15
19
|
export interface RegisterReturn {
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
[topic: string]: {
|
|
21
|
+
success: boolean;
|
|
22
|
+
result: unknown;
|
|
23
|
+
};
|
|
18
24
|
}
|
|
19
25
|
export interface WebhookRegistryEntry {
|
|
20
26
|
path: string;
|
|
21
|
-
topic: string;
|
|
22
27
|
webhookHandler: WebhookHandlerFunction;
|
|
23
28
|
}
|
|
24
29
|
interface WebhookCheckResponseNode<T = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/webhooks/types.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACxB,IAAI,SAAS;IACb,WAAW,gBAAgB;IAC3B,MAAM,WAAW;CAClB;AAED,aAAK,sBAAsB,GAAG,CAC5B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,KACT,OAAO,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AAE,uBAAuB,CAAC;QACpC,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACP;IAED,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;KACZ,GAAG,CAAC,CAAC;CACP;AAED,aAAK,8BAA8B,GAAG,wBAAwB,CAAC;IAC7D,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CAAC;AAEH,MAAM,WAAW,oBAAoB,CAAC,CAAC,GAAG,wBAAwB;IAChE,IAAI,EAAE;QACJ,oBAAoB,EAAE;YACpB,KAAK,EAAE,CAAC,EAAE,CAAC;SACZ,CAAC;KACH,CAAC;CACH;AAED,oBAAY,0BAA0B,GACpC,oBAAoB,CAAC,8BAA8B,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopify/shopify-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.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",
|
|
7
|
+
"prettier": "@shopify/prettier-config",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"test": "jest",
|
|
9
10
|
"build": "tsc",
|
|
@@ -50,19 +51,20 @@
|
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@shopify/eslint-plugin": "^39.0.3",
|
|
54
|
+
"@shopify/prettier-config": "^1.1.2",
|
|
53
55
|
"@types/cookies": "^0.7.5",
|
|
54
56
|
"@types/jest": "^26.0.15",
|
|
55
57
|
"@types/node": "^14.14.1",
|
|
56
58
|
"@types/uuid": "^8.3.0",
|
|
57
|
-
"eslint": "^7.
|
|
59
|
+
"eslint": "^7.30.0",
|
|
58
60
|
"eslint-plugin-tsdoc": "^0.2.7",
|
|
59
61
|
"express": "^4.17.1",
|
|
60
|
-
"jest": "^
|
|
62
|
+
"jest": "^27.4.3",
|
|
61
63
|
"jest-fetch-mock": "^3.0.3",
|
|
64
|
+
"prettier": "^2.3.2",
|
|
62
65
|
"rimraf": "^3.0.2",
|
|
63
66
|
"supertest": "^6.1.3",
|
|
64
|
-
"ts-jest": "^
|
|
65
|
-
"typedoc": "^0.19.2",
|
|
67
|
+
"ts-jest": "^27.1.1",
|
|
66
68
|
"typescript": "^3.8.0"
|
|
67
69
|
},
|
|
68
70
|
"files": [
|