@shopify/shopify-api 4.1.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +26 -5
  2. package/dist/auth/oauth/oauth.d.ts.map +1 -1
  3. package/dist/auth/oauth/oauth.js +7 -5
  4. package/dist/auth/session/session_storage.d.ts +12 -0
  5. package/dist/auth/session/session_storage.d.ts.map +1 -1
  6. package/dist/auth/session/storage/custom.d.ts +5 -1
  7. package/dist/auth/session/storage/custom.d.ts.map +1 -1
  8. package/dist/auth/session/storage/custom.js +59 -1
  9. package/dist/auth/session/storage/memory.d.ts +2 -0
  10. package/dist/auth/session/storage/memory.d.ts.map +1 -1
  11. package/dist/auth/session/storage/memory.js +20 -0
  12. package/dist/auth/session/storage/mongodb.d.ts +2 -0
  13. package/dist/auth/session/storage/mongodb.d.ts.map +1 -1
  14. package/dist/auth/session/storage/mongodb.js +41 -6
  15. package/dist/auth/session/storage/mysql.d.ts +2 -0
  16. package/dist/auth/session/storage/mysql.d.ts.map +1 -1
  17. package/dist/auth/session/storage/mysql.js +41 -0
  18. package/dist/auth/session/storage/postgresql.d.ts +2 -0
  19. package/dist/auth/session/storage/postgresql.d.ts.map +1 -1
  20. package/dist/auth/session/storage/postgresql.js +41 -0
  21. package/dist/auth/session/storage/redis.d.ts +4 -1
  22. package/dist/auth/session/storage/redis.d.ts.map +1 -1
  23. package/dist/auth/session/storage/redis.js +68 -3
  24. package/dist/auth/session/storage/sqlite.d.ts +2 -0
  25. package/dist/auth/session/storage/sqlite.d.ts.map +1 -1
  26. package/dist/auth/session/storage/sqlite.js +42 -0
  27. package/dist/base-types.d.ts +1 -0
  28. package/dist/base-types.d.ts.map +1 -1
  29. package/dist/clients/graphql/graphql_client.d.ts.map +1 -1
  30. package/dist/clients/graphql/graphql_client.js +25 -14
  31. package/dist/clients/http_client/http_client.d.ts.map +1 -1
  32. package/dist/clients/http_client/http_client.js +5 -1
  33. package/dist/context.d.ts.map +1 -1
  34. package/dist/context.js +3 -0
  35. package/dist/error.d.ts +13 -0
  36. package/dist/error.d.ts.map +1 -1
  37. package/dist/error.js +20 -1
  38. package/dist/index.d.ts +2 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/utils/delete-offline-session.d.ts.map +1 -1
  41. package/dist/utils/delete-offline-session.js +4 -2
  42. package/dist/utils/get-embedded-app-url.d.ts.map +1 -1
  43. package/dist/utils/get-embedded-app-url.js +2 -1
  44. package/dist/utils/index.d.ts +3 -2
  45. package/dist/utils/index.d.ts.map +1 -1
  46. package/dist/utils/index.js +3 -2
  47. package/dist/utils/load-offline-session.d.ts.map +1 -1
  48. package/dist/utils/load-offline-session.js +4 -2
  49. package/dist/utils/setup-jest.d.ts.map +1 -1
  50. package/dist/utils/setup-jest.js +1 -0
  51. package/dist/utils/shop-validator.d.ts +12 -3
  52. package/dist/utils/shop-validator.d.ts.map +1 -1
  53. package/dist/utils/shop-validator.js +39 -7
  54. package/dist/version.d.ts +1 -1
  55. package/dist/version.js +1 -1
  56. package/dist/webhooks/registry.d.ts.map +1 -1
  57. package/dist/webhooks/registry.js +23 -20
  58. package/package.json +1 -1
  59. package/dist/__tests__/fake-resource-with-custom-prefix.d.ts +0 -21
  60. package/dist/__tests__/fake-resource-with-custom-prefix.d.ts.map +0 -1
  61. package/dist/__tests__/fake-resource-with-custom-prefix.js +0 -46
  62. package/dist/__tests__/fake-resource.d.ts +0 -41
  63. package/dist/__tests__/fake-resource.d.ts.map +0 -1
  64. package/dist/__tests__/fake-resource.js +0 -122
  65. package/dist/auth/session/storage/__tests__/battery-of-tests.d.ts +0 -3
  66. package/dist/auth/session/storage/__tests__/battery-of-tests.d.ts.map +0 -1
  67. package/dist/auth/session/storage/__tests__/battery-of-tests.js +0 -191
  68. package/dist/auth/session/storage/__tests__/utils.d.ts +0 -10
  69. package/dist/auth/session/storage/__tests__/utils.d.ts.map +0 -1
  70. package/dist/auth/session/storage/__tests__/utils.js +0 -87
package/CHANGELOG.md CHANGED
@@ -7,6 +7,23 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## [5.0.1] - 2022-08-03
11
+
12
+ - Make `sanitizeHost` validation more flexible [#446](https://github.com/Shopify/shopify-api-node/pull/446)
13
+
14
+ ## [5.0.0] - 2022-07-28
15
+
16
+ - ⚠️ [Breaking] If a response from a GraphQL query contains an `errors` attribute, `GraphqlClient` will now throw a `GraphqlQueryError`. The caller can check the `error.response` attribute to see what was returned from the GraphQL API. [#431](https://github.com/Shopify/shopify-api-node/pull/431)
17
+ - ⚠️ [Breaking] Add utils functions to sanitize shops and hosts, and remove the `validateShop` utils function [#434](https://github.com/Shopify/shopify-api-node/pull/434)
18
+ - Allow passing in options for the Redis client used by the session storage strategy [#430](https://github.com/Shopify/shopify-api-node/pull/430)
19
+ - Fix User-Agent header sent in PUT / POST requests [#435](https://github.com/Shopify/shopify-api-node/pull/435)
20
+
21
+ ## [4.2.0] - 2022-07-20
22
+
23
+ - Return a 401 instead of 403 when webhooks fail validation [#425](https://github.com/Shopify/shopify-api-node/pull/425)
24
+ - Add optional new methods `deleteSession` and `findSessionsByShop` to `SessionStorage`, with the corresponding implementations for the various session storage adapters [#418](https://github.com/Shopify/shopify-api-node/pull/418)
25
+ - Include subset of query body in API deprecation logs [#426](https://github.com/Shopify/shopify-api-node/pull/426)
26
+
10
27
  ## [4.1.0] - 2022-07-14
11
28
 
12
29
  - Add new method to construct the host app URL [#419](https://github.com/Shopify/shopify-api-node/pull/419)
@@ -23,25 +40,29 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
23
40
  ## [3.1.3] - 2022-06-08
24
41
 
25
42
  ### Fixes
43
+
26
44
  - Return instances of `Session` from session storages, not POJOs.
27
45
 
28
46
  ## [3.1.2] - 2022-06-07
29
47
 
30
48
  ### Added
49
+
31
50
  - Store user id and expiration date of online tokens
32
51
 
33
52
  ### Fixes
53
+
34
54
  - Properly parse a non-json HTTP response [#257](https://github.com/Shopify/shopify-api-node/issues/257)
35
55
  - Don’t create a SQLite DB file if the SQLite storage is not used.
36
56
 
37
-
38
57
  ## [3.1.0] - 2022-05-16
39
58
 
40
59
  ### Added
60
+
41
61
  - Support for specifying the URI scheme of the host [#385](https://github.com/Shopify/shopify-api-node/pull/385)
42
62
  - Add optional `saving` parameter to `serialize` of `Base` class - default is `false` and will include read-only attributes in returned object; `true` used for `save` when committing via API to Shopify.
43
63
 
44
64
  ### Fixed
65
+
45
66
  - Fixes [#363](https://github.com/Shopify/shopify-api-node/issues/363)
46
67
  - Webhooks `register` now checks for any attempt to register a GDPR topic (not done via API but by Partner Dashboard), provides an error message in response
47
68
  - For topics that don't exist, `register` checks the response from the initial API call for an `errors` field and returns accordingly
@@ -97,12 +118,12 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
97
118
  ### Added
98
119
 
99
120
  - Add a 5 second `clockTolerance` to fix `jwt not active` error [#227](https://github.com/Shopify/shopify-api-node/pull/227)
100
- - [Breaking] Change default for OAuth.beginAuth to online sessions [#203](https://github.com/Shopify/shopify-api-node/pull/203)
121
+ - ⚠️ [Breaking] Change default for OAuth.beginAuth to online sessions [#203](https://github.com/Shopify/shopify-api-node/pull/203)
101
122
  - see [oauth.md](https://github.com/Shopify/shopify-api-node/blob/main/docs/usage/oauth.md) for updated docs
102
- - [Breaking] Return and delete session in `validateAuthCallback` [#217](https://github.com/Shopify/shopify-api-node/pull/217)
123
+ - ⚠️ [Breaking] Return and delete session in `validateAuthCallback` [#217](https://github.com/Shopify/shopify-api-node/pull/217)
103
124
  - see [oauth.md](https://github.com/Shopify/shopify-api-node/blob/main/docs/usage/oauth.md) for updated usage
104
- - [Breaking] Extract `addHandler` and `getHandler` methods for webhooks out of `register` [#205](https://github.com/Shopify/shopify-api-node/pull/205)
105
- - [Breaking] Sessions no longer default to `false` for `isOnline` [#169](https://github.com/Shopify/shopify-api-node/pull/169)
125
+ - ⚠️ [Breaking] Extract `addHandler` and `getHandler` methods for webhooks out of `register` [#205](https://github.com/Shopify/shopify-api-node/pull/205)
126
+ - ⚠️ [Breaking] Sessions no longer default to `false` for `isOnline` [#169](https://github.com/Shopify/shopify-api-node/pull/169)
106
127
  - Required `Session` arguments must be passed to the constructor [#169](https://github.com/Shopify/shopify-api-node/pull/169)
107
128
  - Allow `undefined` in `AuthScopes` [#169](https://github.com/Shopify/shopify-api-node/pull/169)
108
129
 
@@ -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;AAElD,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;IAgDlB;;;;;;;;;;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;;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"}
@@ -14,6 +14,7 @@ var session_1 = require("../session");
14
14
  var http_client_1 = require("../../clients/http_client/http_client");
15
15
  var types_1 = require("../../clients/http_client/types");
16
16
  var ShopifyErrors = tslib_1.__importStar(require("../../error"));
17
+ var shop_validator_1 = require("../../utils/shop-validator");
17
18
  var ShopifyOAuth = {
18
19
  SESSION_COOKIE_NAME: 'shopify_app_session',
19
20
  /**
@@ -30,18 +31,19 @@ var ShopifyOAuth = {
30
31
  beginAuth: function (request, response, shop, redirectPath, isOnline) {
31
32
  if (isOnline === void 0) { isOnline = true; }
32
33
  return tslib_1.__awaiter(this, void 0, void 0, function () {
33
- var cookies, state, session, sessionStored, query, queryString;
34
+ var cleanShop, cookies, state, session, sessionStored, query, queryString;
34
35
  return tslib_1.__generator(this, function (_a) {
35
36
  switch (_a.label) {
36
37
  case 0:
37
38
  context_1.Context.throwIfUninitialized();
38
39
  context_1.Context.throwIfPrivateApp('Cannot perform OAuth for private apps');
40
+ cleanShop = (0, shop_validator_1.sanitizeShop)(shop, true);
39
41
  cookies = new cookies_1.default(request, response, {
40
42
  keys: [context_1.Context.API_SECRET_KEY],
41
43
  secure: true,
42
44
  });
43
45
  state = (0, nonce_1.default)();
44
- session = new session_1.Session(isOnline ? (0, uuid_1.v4)() : this.getOfflineSessionId(shop), shop, state, isOnline);
46
+ session = new session_1.Session(isOnline ? (0, uuid_1.v4)() : this.getOfflineSessionId(cleanShop), cleanShop, state, isOnline);
45
47
  return [4 /*yield*/, context_1.Context.SESSION_STORAGE.storeSession(session)];
46
48
  case 1:
47
49
  sessionStored = _a.sent();
@@ -62,7 +64,7 @@ var ShopifyOAuth = {
62
64
  'grant_options[]': isOnline ? 'per-user' : '',
63
65
  };
64
66
  queryString = querystring_1.default.stringify(query);
65
- return [2 /*return*/, "https://".concat(shop, "/admin/oauth/authorize?").concat(queryString)];
67
+ return [2 /*return*/, "https://".concat(cleanShop, "/admin/oauth/authorize?").concat(queryString)];
66
68
  }
67
69
  });
68
70
  });
@@ -181,7 +183,7 @@ var ShopifyOAuth = {
181
183
  * @param userId Current actor id
182
184
  */
183
185
  getJwtSessionId: function (shop, userId) {
184
- return "".concat(shop, "_").concat(userId);
186
+ return "".concat((0, shop_validator_1.sanitizeShop)(shop, true), "_").concat(userId);
185
187
  },
186
188
  /**
187
189
  * Builds an offline session id for the given shop.
@@ -189,7 +191,7 @@ var ShopifyOAuth = {
189
191
  * @param shop Shopify shop domain
190
192
  */
191
193
  getOfflineSessionId: function (shop) {
192
- return "offline_".concat(shop);
194
+ return "offline_".concat((0, shop_validator_1.sanitizeShop)(shop, true));
193
195
  },
194
196
  /**
195
197
  * Extracts the current session id from the request / response pair.
@@ -21,6 +21,18 @@ interface SessionStorage {
21
21
  * @param id Id of the session to delete
22
22
  */
23
23
  deleteSession(id: string): Promise<boolean>;
24
+ /**
25
+ * Deletes an array of sessions from storage.
26
+ *
27
+ * @param ids Array of session id's to delete
28
+ */
29
+ deleteSessions?(ids: string[]): Promise<boolean>;
30
+ /**
31
+ * Return an array of sessions for a given shop (or [] if none found).
32
+ *
33
+ * @param shop shop of the session(s) to return
34
+ */
35
+ findSessionsByShop?(shop: string): Promise<SessionInterface[]>;
24
36
  }
25
37
  export { SessionStorage };
26
38
  //# sourceMappingURL=session_storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session_storage.d.ts","sourceRoot":"","sources":["../../../src/auth/session/session_storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAEzC;;GAEG;AACH,UAAU,cAAc;IACtB;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE1D;;;;OAIG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC;IAE/D;;;;OAIG;IACH,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7C;AAED,OAAO,EAAC,cAAc,EAAC,CAAC"}
1
+ {"version":3,"file":"session_storage.d.ts","sourceRoot":"","sources":["../../../src/auth/session/session_storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAEzC;;GAEG;AACH,UAAU,cAAc;IACtB;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE1D;;;;OAIG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC;IAE/D;;;;OAIG;IACH,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE5C;;;;OAIG;IACH,cAAc,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjD;;;;OAIG;IACH,kBAAkB,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;CAChE;AAED,OAAO,EAAC,cAAc,EAAC,CAAC"}
@@ -6,11 +6,15 @@ export declare class CustomSessionStorage implements SessionStorage {
6
6
  [key: string]: unknown;
7
7
  } | undefined>;
8
8
  readonly deleteCallback: (id: string) => Promise<boolean>;
9
+ readonly deleteSessionsCallback?: ((ids: string[]) => Promise<boolean>) | undefined;
10
+ readonly findSessionsByShopCallback?: ((shop: string) => Promise<SessionInterface[]>) | undefined;
9
11
  constructor(storeCallback: (session: SessionInterface) => Promise<boolean>, loadCallback: (id: string) => Promise<SessionInterface | {
10
12
  [key: string]: unknown;
11
- } | undefined>, deleteCallback: (id: string) => Promise<boolean>);
13
+ } | undefined>, deleteCallback: (id: string) => Promise<boolean>, deleteSessionsCallback?: ((ids: string[]) => Promise<boolean>) | undefined, findSessionsByShopCallback?: ((shop: string) => Promise<SessionInterface[]>) | undefined);
12
14
  storeSession(session: SessionInterface): Promise<boolean>;
13
15
  loadSession(id: string): Promise<SessionInterface | undefined>;
14
16
  deleteSession(id: string): Promise<boolean>;
17
+ deleteSessions(ids: string[]): Promise<boolean>;
18
+ findSessionsByShop(shop: string): Promise<SessionInterface[]>;
15
19
  }
16
20
  //# sourceMappingURL=custom.d.ts.map
@@ -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,CACrB,EAAE,EA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EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC;IACzD,QAAQ,CAAC,sBAAsB,CAAC,SAAQ,MAAM,EAAE,KAAK,QAAQ,OAAO,CAAC;IACrE,QAAQ,CAAC,0BAA0B,CAAC,UAC5B,MAAM,KACT,QAAQ,gBAAgB,EAAE,CAAC;gBARvB,aAAa,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC,OAAO,CAAC,EAC9D,YAAY,EAAE,CACrB,EAAE,EAAE,MAAM,KACP,OAAO,CAAC,gBAAgB,GAAG;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,GAAG,SAAS,CAAC,EAC5D,cAAc,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,EAChD,sBAAsB,CAAC,SAAQ,MAAM,EAAE,KAAK,QAAQ,OAAO,CAAC,aAAA,EAC5D,0BAA0B,CAAC,UAC5B,MAAM,KACT,QAAQ,gBAAgB,EAAE,CAAC,aAAA;IASrB,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAUzD,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IA2C9D,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAU3C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAiB/C,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;CAoB3E"}
@@ -4,14 +4,19 @@ exports.CustomSessionStorage = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var session_1 = require("../session");
6
6
  var ShopifyErrors = tslib_1.__importStar(require("../../../error"));
7
+ var shop_validator_1 = require("../../../utils/shop-validator");
7
8
  var CustomSessionStorage = /** @class */ (function () {
8
- function CustomSessionStorage(storeCallback, loadCallback, deleteCallback) {
9
+ function CustomSessionStorage(storeCallback, loadCallback, deleteCallback, deleteSessionsCallback, findSessionsByShopCallback) {
9
10
  this.storeCallback = storeCallback;
10
11
  this.loadCallback = loadCallback;
11
12
  this.deleteCallback = deleteCallback;
13
+ this.deleteSessionsCallback = deleteSessionsCallback;
14
+ this.findSessionsByShopCallback = findSessionsByShopCallback;
12
15
  this.storeCallback = storeCallback;
13
16
  this.loadCallback = loadCallback;
14
17
  this.deleteCallback = deleteCallback;
18
+ this.deleteSessionsCallback = deleteSessionsCallback;
19
+ this.findSessionsByShopCallback = findSessionsByShopCallback;
15
20
  }
16
21
  CustomSessionStorage.prototype.storeSession = function (session) {
17
22
  return tslib_1.__awaiter(this, void 0, void 0, function () {
@@ -58,6 +63,7 @@ var CustomSessionStorage = /** @class */ (function () {
58
63
  if (session.expires && typeof session.expires === 'string') {
59
64
  session.expires = new Date(session.expires);
60
65
  }
66
+ Object.setPrototypeOf(session, session_1.Session.prototype);
61
67
  return [2 /*return*/, session];
62
68
  }
63
69
  else {
@@ -89,6 +95,58 @@ var CustomSessionStorage = /** @class */ (function () {
89
95
  });
90
96
  });
91
97
  };
98
+ CustomSessionStorage.prototype.deleteSessions = function (ids) {
99
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
100
+ var error_4;
101
+ return tslib_1.__generator(this, function (_a) {
102
+ switch (_a.label) {
103
+ case 0:
104
+ if (!this.deleteSessionsCallback) return [3 /*break*/, 5];
105
+ _a.label = 1;
106
+ case 1:
107
+ _a.trys.push([1, 3, , 4]);
108
+ return [4 /*yield*/, this.deleteSessionsCallback(ids)];
109
+ case 2: return [2 /*return*/, _a.sent()];
110
+ case 3:
111
+ error_4 = _a.sent();
112
+ throw new ShopifyErrors.SessionStorageError("CustomSessionStorage failed to delete array of sessions. Error Details: ".concat(error_4));
113
+ case 4: return [3 /*break*/, 6];
114
+ case 5:
115
+ console.warn("CustomSessionStorage failed to delete array of sessions. Error Details: deleteSessionsCallback not defined.");
116
+ _a.label = 6;
117
+ case 6: return [2 /*return*/, false];
118
+ }
119
+ });
120
+ });
121
+ };
122
+ CustomSessionStorage.prototype.findSessionsByShop = function (shop) {
123
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
124
+ var cleanShop, sessions, error_5;
125
+ return tslib_1.__generator(this, function (_a) {
126
+ switch (_a.label) {
127
+ case 0:
128
+ cleanShop = (0, shop_validator_1.sanitizeShop)(shop, true);
129
+ sessions = [];
130
+ if (!this.findSessionsByShopCallback) return [3 /*break*/, 5];
131
+ _a.label = 1;
132
+ case 1:
133
+ _a.trys.push([1, 3, , 4]);
134
+ return [4 /*yield*/, this.findSessionsByShopCallback(cleanShop)];
135
+ case 2:
136
+ sessions = _a.sent();
137
+ return [3 /*break*/, 4];
138
+ case 3:
139
+ error_5 = _a.sent();
140
+ throw new ShopifyErrors.SessionStorageError("CustomSessionStorage failed to find sessions by shop. Error Details: ".concat(error_5));
141
+ case 4: return [3 /*break*/, 6];
142
+ case 5:
143
+ console.warn("CustomSessionStorage failed to find sessions by shop. Error Details: findSessionsByShopCallback not defined.");
144
+ _a.label = 6;
145
+ case 6: return [2 /*return*/, sessions];
146
+ }
147
+ });
148
+ });
149
+ };
92
150
  return CustomSessionStorage;
93
151
  }());
94
152
  exports.CustomSessionStorage = CustomSessionStorage;
@@ -5,5 +5,7 @@ export declare class MemorySessionStorage implements SessionStorage {
5
5
  storeSession(session: SessionInterface): Promise<boolean>;
6
6
  loadSession(id: string): Promise<SessionInterface | undefined>;
7
7
  deleteSession(id: string): Promise<boolean>;
8
+ deleteSessions(ids: string[]): Promise<boolean>;
9
+ findSessionsByShop(shop: string): Promise<SessionInterface[]>;
8
10
  }
9
11
  //# sourceMappingURL=memory.d.ts.map
@@ -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,CAAwC;IAE3C,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"}
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;AAGlD,qBAAa,oBAAqB,YAAW,cAAc;IACzD,OAAO,CAAC,QAAQ,CAAwC;IAE3C,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;IAO3C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAK/C,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;CAQ3E"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MemorySessionStorage = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ var shop_validator_1 = require("../../../utils/shop-validator");
5
6
  var MemorySessionStorage = /** @class */ (function () {
6
7
  function MemorySessionStorage() {
7
8
  this.sessions = {};
@@ -31,6 +32,25 @@ var MemorySessionStorage = /** @class */ (function () {
31
32
  });
32
33
  });
33
34
  };
35
+ MemorySessionStorage.prototype.deleteSessions = function (ids) {
36
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
37
+ var _this = this;
38
+ return tslib_1.__generator(this, function (_a) {
39
+ ids.forEach(function (id) { return delete _this.sessions[id]; });
40
+ return [2 /*return*/, true];
41
+ });
42
+ });
43
+ };
44
+ MemorySessionStorage.prototype.findSessionsByShop = function (shop) {
45
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
46
+ var cleanShop, results;
47
+ return tslib_1.__generator(this, function (_a) {
48
+ cleanShop = (0, shop_validator_1.sanitizeShop)(shop, true);
49
+ results = Object.values(this.sessions).filter(function (session) { return session.shop === cleanShop; });
50
+ return [2 /*return*/, results];
51
+ });
52
+ });
53
+ };
34
54
  return MemorySessionStorage;
35
55
  }());
36
56
  exports.MemorySessionStorage = MemorySessionStorage;
@@ -14,6 +14,8 @@ export declare class MongoDBSessionStorage implements SessionStorage {
14
14
  storeSession(session: SessionInterface): Promise<boolean>;
15
15
  loadSession(id: string): Promise<SessionInterface | undefined>;
16
16
  deleteSession(id: string): Promise<boolean>;
17
+ deleteSessions(ids: string[]): Promise<boolean>;
18
+ findSessionsByShop(shop: string): Promise<SessionInterface[]>;
17
19
  disconnect(): Promise<void>;
18
20
  private get collection();
19
21
  private init;
@@ -1 +1 @@
1
- {"version":3,"file":"mongodb.d.ts","sourceRoot":"","sources":["../../../../src/auth/session/storage/mongodb.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAGlD,MAAM,WAAW,4BAA4B;IAC3C,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAKD,qBAAa,qBAAsB,YAAW,cAAc;IAyBxD,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,MAAM;IAzBhB,MAAM,CAAC,eAAe,CACpB,IAAI,EAAE,MAAM,EACZ,MAAM,E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OAAO,CAAC,OAAO,CAA+B;IAE9C,OAAO,CAAC,MAAM,CAAM;gBAGV,KAAK,EAAE,GAAG,EACV,MAAM,EAAE,MAAM,EACtB,IAAI,GAAE,OAAO,CAAC,4BAA4B,CAAM;IASrC,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAazD,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAQ9D,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;IAY7D,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxC,OAAO,KAAK,UAAU,GAIrB;YAEa,IAAI;YAOJ,oBAAoB;YAOpB,gBAAgB;CAM/B"}
@@ -4,6 +4,7 @@ exports.MongoDBSessionStorage = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var mongodb = tslib_1.__importStar(require("mongodb"));
6
6
  var session_utils_1 = require("../session-utils");
7
+ var shop_validator_1 = require("../../../utils/shop-validator");
7
8
  var defaultMongoDBSessionStorageOptions = {
8
9
  sessionCollectionName: 'shopify_sessions',
9
10
  };
@@ -28,7 +29,7 @@ var MongoDBSessionStorage = /** @class */ (function () {
28
29
  case 0: return [4 /*yield*/, this.ready];
29
30
  case 1:
30
31
  _a.sent();
31
- return [4 /*yield*/, this.collection.findOneAndReplace({ id: session.id }, { id: session.id, entries: (0, session_utils_1.sessionEntries)(session) }, {
32
+ return [4 /*yield*/, this.collection.findOneAndReplace({ id: session.id }, Object.fromEntries((0, session_utils_1.sessionEntries)(session)), {
32
33
  upsert: true,
33
34
  })];
34
35
  case 2:
@@ -40,7 +41,7 @@ var MongoDBSessionStorage = /** @class */ (function () {
40
41
  };
41
42
  MongoDBSessionStorage.prototype.loadSession = function (id) {
42
43
  return tslib_1.__awaiter(this, void 0, void 0, function () {
43
- var rawResult;
44
+ var result;
44
45
  return tslib_1.__generator(this, function (_a) {
45
46
  switch (_a.label) {
46
47
  case 0: return [4 /*yield*/, this.ready];
@@ -48,10 +49,8 @@ var MongoDBSessionStorage = /** @class */ (function () {
48
49
  _a.sent();
49
50
  return [4 /*yield*/, this.collection.findOne({ id: id })];
50
51
  case 2:
51
- rawResult = _a.sent();
52
- if (!rawResult)
53
- return [2 /*return*/, undefined];
54
- return [2 /*return*/, (0, session_utils_1.sessionFromEntries)(rawResult.entries)];
52
+ result = _a.sent();
53
+ return [2 /*return*/, result ? (0, session_utils_1.sessionFromEntries)(Object.entries(result)) : undefined];
55
54
  }
56
55
  });
57
56
  });
@@ -71,6 +70,42 @@ var MongoDBSessionStorage = /** @class */ (function () {
71
70
  });
72
71
  });
73
72
  };
73
+ MongoDBSessionStorage.prototype.deleteSessions = function (ids) {
74
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
75
+ return tslib_1.__generator(this, function (_a) {
76
+ switch (_a.label) {
77
+ case 0: return [4 /*yield*/, this.ready];
78
+ case 1:
79
+ _a.sent();
80
+ return [4 /*yield*/, this.collection.deleteMany({ id: { $in: ids } })];
81
+ case 2:
82
+ _a.sent();
83
+ return [2 /*return*/, true];
84
+ }
85
+ });
86
+ });
87
+ };
88
+ MongoDBSessionStorage.prototype.findSessionsByShop = function (shop) {
89
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
90
+ var cleanShop, rawResults;
91
+ return tslib_1.__generator(this, function (_a) {
92
+ switch (_a.label) {
93
+ case 0: return [4 /*yield*/, this.ready];
94
+ case 1:
95
+ _a.sent();
96
+ cleanShop = (0, shop_validator_1.sanitizeShop)(shop, true);
97
+ return [4 /*yield*/, this.collection.find({ shop: cleanShop }).toArray()];
98
+ case 2:
99
+ rawResults = _a.sent();
100
+ if (!rawResults || (rawResults === null || rawResults === void 0 ? void 0 : rawResults.length) === 0)
101
+ return [2 /*return*/, []];
102
+ return [2 /*return*/, rawResults.map(function (rawResult) {
103
+ return (0, session_utils_1.sessionFromEntries)(Object.entries(rawResult));
104
+ })];
105
+ }
106
+ });
107
+ });
108
+ };
74
109
  MongoDBSessionStorage.prototype.disconnect = function () {
75
110
  return tslib_1.__awaiter(this, void 0, void 0, function () {
76
111
  return tslib_1.__generator(this, function (_a) {
@@ -13,6 +13,8 @@ export declare class MySQLSessionStorage implements SessionStorage {
13
13
  storeSession(session: SessionInterface): Promise<boolean>;
14
14
  loadSession(id: string): Promise<SessionInterface | undefined>;
15
15
  deleteSession(id: string): Promise<boolean>;
16
+ deleteSessions(ids: string[]): Promise<boolean>;
17
+ findSessionsByShop(shop: string): Promise<SessionInterface[]>;
16
18
  disconnect(): Promise<void>;
17
19
  private init;
18
20
  private hasSessionTable;
@@ -1 +1 @@
1
- {"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../../../src/auth/session/storage/mysql.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAGlD,MAAM,WAAW,0BAA0B;IACzC,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAKD,qBAAa,mBAAoB,YAAW,cAAc;IAuBtD,OAAO,CAAC,KAAK;IAtBf,MAAM,CAAC,eAAe,CACpB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,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,UAAU,CAAmB;gBAG3B,KAAK,EAAE,GAAG,EAClB,IAAI,GAAE,OAAO,CAAC,0BAA0B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;IAU3C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAU/C,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAiB7D,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;YAI1B,IAAI;YAKJ,eAAe;YAQf,WAAW;IAmBzB,OAAO,CAAC,KAAK;CAGd"}
@@ -4,6 +4,7 @@ exports.MySQLSessionStorage = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var promise_1 = tslib_1.__importDefault(require("mysql2/promise"));
6
6
  var session_utils_1 = require("../session-utils");
7
+ var shop_validator_1 = require("../../../utils/shop-validator");
7
8
  var defaultMySQLSessionStorageOptions = {
8
9
  sessionTableName: 'shopify_sessions',
9
10
  };
@@ -81,6 +82,46 @@ var MySQLSessionStorage = /** @class */ (function () {
81
82
  });
82
83
  });
83
84
  };
85
+ MySQLSessionStorage.prototype.deleteSessions = function (ids) {
86
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
87
+ var query;
88
+ return tslib_1.__generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0: return [4 /*yield*/, this.ready];
91
+ case 1:
92
+ _a.sent();
93
+ query = "\n DELETE FROM ".concat(this.options.sessionTableName, "\n WHERE id IN (").concat(ids.map(function () { return '?'; }).join(','), ");\n ");
94
+ return [4 /*yield*/, this.query(query, ids)];
95
+ case 2:
96
+ _a.sent();
97
+ return [2 /*return*/, true];
98
+ }
99
+ });
100
+ });
101
+ };
102
+ MySQLSessionStorage.prototype.findSessionsByShop = function (shop) {
103
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
104
+ var cleanShop, query, _a, rows, results;
105
+ return tslib_1.__generator(this, function (_b) {
106
+ switch (_b.label) {
107
+ case 0: return [4 /*yield*/, this.ready];
108
+ case 1:
109
+ _b.sent();
110
+ cleanShop = (0, shop_validator_1.sanitizeShop)(shop, true);
111
+ query = "\n SELECT * FROM ".concat(this.options.sessionTableName, "\n WHERE shop = ?;\n ");
112
+ return [4 /*yield*/, this.query(query, [cleanShop])];
113
+ case 2:
114
+ _a = tslib_1.__read.apply(void 0, [_b.sent(), 1]), rows = _a[0];
115
+ if (!Array.isArray(rows) || (rows === null || rows === void 0 ? void 0 : rows.length) === 0)
116
+ return [2 /*return*/, []];
117
+ results = rows.map(function (row) {
118
+ return (0, session_utils_1.sessionFromEntries)(Object.entries(row));
119
+ });
120
+ return [2 /*return*/, results];
121
+ }
122
+ });
123
+ });
124
+ };
84
125
  MySQLSessionStorage.prototype.disconnect = function () {
85
126
  return tslib_1.__awaiter(this, void 0, void 0, function () {
86
127
  return tslib_1.__generator(this, function (_a) {
@@ -14,6 +14,8 @@ export declare class PostgreSQLSessionStorage implements SessionStorage {
14
14
  storeSession(session: SessionInterface): Promise<boolean>;
15
15
  loadSession(id: string): Promise<SessionInterface | undefined>;
16
16
  deleteSession(id: string): Promise<boolean>;
17
+ deleteSessions(ids: string[]): Promise<boolean>;
18
+ findSessionsByShop(shop: string): Promise<SessionInterface[]>;
17
19
  disconnect(): Promise<void>;
18
20
  private init;
19
21
  private connectClient;
@@ -1 +1 @@
1
- {"version":3,"file":"postgresql.d.ts","sourceRoot":"","sources":["../../../../src/auth/session/storage/postgresql.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAGlD,MAAM,WAAW,+BAA+B;IAC9C,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;CACd;AAOD,qBAAa,wBAAyB,YAAW,cAAc;IAuB3D,OAAO,CAAC,KAAK;IAtBf,MAAM,CAAC,eAAe,CACpB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,CAAC,+BAA+B,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ASxC,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAmBzD,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAY9D,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAU3C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAU/C,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAiBnE,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;YAIpB,IAAI;YAMJ,aAAa;YAIb,eAAe;YAQf,WAAW;YAmBX,KAAK;CAIpB"}
@@ -4,6 +4,7 @@ exports.PostgreSQLSessionStorage = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var pg_1 = tslib_1.__importDefault(require("pg"));
6
6
  var session_utils_1 = require("../session-utils");
7
+ var shop_validator_1 = require("../../../utils/shop-validator");
7
8
  var defaultPostgreSQLSessionStorageOptions = {
8
9
  sessionTableName: 'shopify_sessions',
9
10
  port: 3211,
@@ -87,6 +88,46 @@ var PostgreSQLSessionStorage = /** @class */ (function () {
87
88
  });
88
89
  });
89
90
  };
91
+ PostgreSQLSessionStorage.prototype.deleteSessions = function (ids) {
92
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
93
+ var query;
94
+ return tslib_1.__generator(this, function (_a) {
95
+ switch (_a.label) {
96
+ case 0: return [4 /*yield*/, this.ready];
97
+ case 1:
98
+ _a.sent();
99
+ query = "\n DELETE FROM ".concat(this.options.sessionTableName, "\n WHERE id IN (").concat(ids.map(function (_, i) { return "$".concat(i + 1); }).join(', '), ");\n ");
100
+ return [4 /*yield*/, this.query(query, ids)];
101
+ case 2:
102
+ _a.sent();
103
+ return [2 /*return*/, true];
104
+ }
105
+ });
106
+ });
107
+ };
108
+ PostgreSQLSessionStorage.prototype.findSessionsByShop = function (shop) {
109
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
110
+ var cleanShop, query, rows, results;
111
+ return tslib_1.__generator(this, function (_a) {
112
+ switch (_a.label) {
113
+ case 0: return [4 /*yield*/, this.ready];
114
+ case 1:
115
+ _a.sent();
116
+ cleanShop = (0, shop_validator_1.sanitizeShop)(shop, true);
117
+ query = "\n SELECT * FROM ".concat(this.options.sessionTableName, "\n WHERE shop = $1;\n ");
118
+ return [4 /*yield*/, this.query(query, [cleanShop])];
119
+ case 2:
120
+ rows = _a.sent();
121
+ if (!Array.isArray(rows) || (rows === null || rows === void 0 ? void 0 : rows.length) === 0)
122
+ return [2 /*return*/, []];
123
+ results = rows.map(function (row) {
124
+ return (0, session_utils_1.sessionFromEntries)(Object.entries(row));
125
+ });
126
+ return [2 /*return*/, results];
127
+ }
128
+ });
129
+ });
130
+ };
90
131
  PostgreSQLSessionStorage.prototype.disconnect = function () {
91
132
  return this.client.end();
92
133
  };
@@ -1,6 +1,7 @@
1
+ import { RedisClientOptions } from 'redis';
1
2
  import { SessionInterface } from '../types';
2
3
  import { SessionStorage } from '../session_storage';
3
- export interface RedisSessionStorageOptions {
4
+ export interface RedisSessionStorageOptions extends RedisClientOptions {
4
5
  sessionKeyPrefix: string;
5
6
  }
6
7
  export declare class RedisSessionStorage implements SessionStorage {
@@ -13,6 +14,8 @@ export declare class RedisSessionStorage implements SessionStorage {
13
14
  storeSession(session: SessionInterface): Promise<boolean>;
14
15
  loadSession(id: string): Promise<SessionInterface | undefined>;
15
16
  deleteSession(id: string): Promise<boolean>;
17
+ deleteSessions(ids: string[]): Promise<boolean>;
18
+ findSessionsByShop(shop: string): Promise<SessionInterface[]>;
16
19
  disconnect(): Promise<void>;
17
20
  private fullKey;
18
21
  private init;
@@ -1 +1 @@
1
- {"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../../../src/auth/session/storage/redis.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,gBAAgB,EAAC,MAAM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