@shopify/shopify-api 4.0.0 → 5.0.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 +80 -55
- package/dist/auth/oauth/oauth.d.ts.map +1 -1
- package/dist/auth/oauth/oauth.js +7 -5
- package/dist/auth/session/session_storage.d.ts +12 -0
- package/dist/auth/session/session_storage.d.ts.map +1 -1
- package/dist/auth/session/storage/custom.d.ts +5 -1
- package/dist/auth/session/storage/custom.d.ts.map +1 -1
- package/dist/auth/session/storage/custom.js +59 -1
- package/dist/auth/session/storage/memory.d.ts +2 -0
- package/dist/auth/session/storage/memory.d.ts.map +1 -1
- package/dist/auth/session/storage/memory.js +20 -0
- package/dist/auth/session/storage/mongodb.d.ts +2 -0
- package/dist/auth/session/storage/mongodb.d.ts.map +1 -1
- package/dist/auth/session/storage/mongodb.js +41 -6
- package/dist/auth/session/storage/mysql.d.ts +2 -0
- package/dist/auth/session/storage/mysql.d.ts.map +1 -1
- package/dist/auth/session/storage/mysql.js +41 -0
- package/dist/auth/session/storage/postgresql.d.ts +2 -0
- package/dist/auth/session/storage/postgresql.d.ts.map +1 -1
- package/dist/auth/session/storage/postgresql.js +45 -4
- package/dist/auth/session/storage/redis.d.ts +4 -1
- package/dist/auth/session/storage/redis.d.ts.map +1 -1
- package/dist/auth/session/storage/redis.js +68 -3
- package/dist/auth/session/storage/sqlite.d.ts +2 -0
- package/dist/auth/session/storage/sqlite.d.ts.map +1 -1
- package/dist/auth/session/storage/sqlite.js +42 -0
- package/dist/base-types.d.ts +1 -0
- package/dist/base-types.d.ts.map +1 -1
- package/dist/clients/graphql/graphql_client.d.ts.map +1 -1
- package/dist/clients/graphql/graphql_client.js +25 -14
- package/dist/clients/http_client/http_client.d.ts.map +1 -1
- package/dist/clients/http_client/http_client.js +5 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +3 -0
- package/dist/error.d.ts +15 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +28 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/utils/delete-offline-session.d.ts.map +1 -1
- package/dist/utils/delete-offline-session.js +4 -2
- package/dist/utils/get-embedded-app-url.d.ts +9 -0
- package/dist/utils/get-embedded-app-url.d.ts.map +1 -0
- package/dist/utils/get-embedded-app-url.js +27 -0
- package/dist/utils/index.d.ts +5 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +5 -2
- package/dist/utils/load-offline-session.d.ts.map +1 -1
- package/dist/utils/load-offline-session.js +4 -2
- package/dist/utils/setup-jest.d.ts.map +1 -1
- package/dist/utils/setup-jest.js +1 -0
- package/dist/utils/shop-validator.d.ts +12 -3
- package/dist/utils/shop-validator.d.ts.map +1 -1
- package/dist/utils/shop-validator.js +39 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/webhooks/registry.d.ts.map +1 -1
- package/dist/webhooks/registry.js +23 -20
- package/package.json +4 -4
- package/dist/__tests__/fake-resource-with-custom-prefix.d.ts +0 -21
- package/dist/__tests__/fake-resource-with-custom-prefix.d.ts.map +0 -1
- package/dist/__tests__/fake-resource-with-custom-prefix.js +0 -46
- package/dist/__tests__/fake-resource.d.ts +0 -41
- package/dist/__tests__/fake-resource.d.ts.map +0 -1
- package/dist/__tests__/fake-resource.js +0 -122
- package/dist/auth/session/storage/__tests__/battery-of-tests.d.ts +0 -3
- package/dist/auth/session/storage/__tests__/battery-of-tests.d.ts.map +0 -1
- package/dist/auth/session/storage/__tests__/battery-of-tests.js +0 -191
- package/dist/auth/session/storage/__tests__/utils.d.ts +0 -10
- package/dist/auth/session/storage/__tests__/utils.d.ts.map +0 -1
- package/dist/auth/session/storage/__tests__/utils.js +0 -87
package/CHANGELOG.md
CHANGED
|
@@ -7,34 +7,59 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
|
7
7
|
|
|
8
8
|
## Unreleased
|
|
9
9
|
|
|
10
|
+
## [5.0.0] - 2022-07-28
|
|
11
|
+
|
|
12
|
+
- ⚠️ [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)
|
|
13
|
+
- ⚠️ [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)
|
|
14
|
+
- Allow passing in options for the Redis client used by the session storage strategy [#430](https://github.com/Shopify/shopify-api-node/pull/430)
|
|
15
|
+
- Fix User-Agent header sent in PUT / POST requests [#435](https://github.com/Shopify/shopify-api-node/pull/435)
|
|
16
|
+
|
|
17
|
+
## [4.2.0] - 2022-07-20
|
|
18
|
+
|
|
19
|
+
- Return a 401 instead of 403 when webhooks fail validation [#425](https://github.com/Shopify/shopify-api-node/pull/425)
|
|
20
|
+
- 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)
|
|
21
|
+
- Include subset of query body in API deprecation logs [#426](https://github.com/Shopify/shopify-api-node/pull/426)
|
|
22
|
+
|
|
23
|
+
## [4.1.0] - 2022-07-14
|
|
24
|
+
|
|
25
|
+
- Add new method to construct the host app URL [#419](https://github.com/Shopify/shopify-api-node/pull/419)
|
|
26
|
+
|
|
10
27
|
## [4.0.0] - 2022-07-04
|
|
11
28
|
|
|
12
|
-
- ⚠️ [Breaking] Add REST resources for July 2022 API version, add `LATEST_API_VERSION` constant, remove support and REST resources for July 2021 (`2021-07`) API version [#415](https://github.com/Shopify/shopify-node
|
|
13
|
-
- Add support for July 2022 API version [#409](https://github.com/Shopify/shopify-node
|
|
29
|
+
- ⚠️ [Breaking] Add REST resources for July 2022 API version, add `LATEST_API_VERSION` constant, remove support and REST resources for July 2021 (`2021-07`) API version [#415](https://github.com/Shopify/shopify-api-node/pull/415)
|
|
30
|
+
- Add support for July 2022 API version [#409](https://github.com/Shopify/shopify-api-node/pull/409)
|
|
31
|
+
|
|
32
|
+
### Fixes
|
|
33
|
+
|
|
34
|
+
- Fix a bug where the PostgreSQL session storage always attempted to create the sessions table [#413](https://github.com/Shopify/shopify-api-node/pull/413)
|
|
14
35
|
|
|
15
36
|
## [3.1.3] - 2022-06-08
|
|
16
37
|
|
|
17
38
|
### Fixes
|
|
39
|
+
|
|
18
40
|
- Return instances of `Session` from session storages, not POJOs.
|
|
19
41
|
|
|
20
42
|
## [3.1.2] - 2022-06-07
|
|
21
43
|
|
|
22
44
|
### Added
|
|
45
|
+
|
|
23
46
|
- Store user id and expiration date of online tokens
|
|
24
47
|
|
|
25
48
|
### Fixes
|
|
26
|
-
- Properly parse a non-json HTTP response [#257](https://github.com/Shopify/shopify-node-api/issues/257)
|
|
27
|
-
- Don’t create a SQLite DB file if the SQLite storage is not used.
|
|
28
49
|
|
|
50
|
+
- Properly parse a non-json HTTP response [#257](https://github.com/Shopify/shopify-api-node/issues/257)
|
|
51
|
+
- Don’t create a SQLite DB file if the SQLite storage is not used.
|
|
29
52
|
|
|
30
53
|
## [3.1.0] - 2022-05-16
|
|
31
54
|
|
|
32
55
|
### Added
|
|
33
|
-
|
|
56
|
+
|
|
57
|
+
- Support for specifying the URI scheme of the host [#385](https://github.com/Shopify/shopify-api-node/pull/385)
|
|
34
58
|
- 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.
|
|
35
59
|
|
|
36
60
|
### Fixed
|
|
37
|
-
|
|
61
|
+
|
|
62
|
+
- Fixes [#363](https://github.com/Shopify/shopify-api-node/issues/363)
|
|
38
63
|
- 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
|
|
39
64
|
- For topics that don't exist, `register` checks the response from the initial API call for an `errors` field and returns accordingly
|
|
40
65
|
|
|
@@ -42,22 +67,22 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
|
42
67
|
|
|
43
68
|
### Added
|
|
44
69
|
|
|
45
|
-
- Allow REST resources to configure a deny list of attributes to be excluded when saving [#355](https://github.com/Shopify/shopify-node
|
|
70
|
+
- Allow REST resources to configure a deny list of attributes to be excluded when saving [#355](https://github.com/Shopify/shopify-api-node/pull/355)
|
|
46
71
|
|
|
47
72
|
## [3.0.0] - 2022-04-04
|
|
48
73
|
|
|
49
74
|
### Added
|
|
50
75
|
|
|
51
|
-
- ⚠️ [Breaking] Removing API version `2021-04` [#343](https://github.com/Shopify/shopify-node
|
|
76
|
+
- ⚠️ [Breaking] Removing API version `2021-04` [#343](https://github.com/Shopify/shopify-api-node/pull/343)
|
|
52
77
|
- ⚠️ [Breaking] The `HttpResponseError` error and its flavours (all returned from HTTP requests) have been slightly altered:
|
|
53
78
|
- They now take in a hash of values, and will always include the response code, body (as a string if the response is not JSON), and headers
|
|
54
79
|
- All response fields are now contained within a `response` object, to make it easier to access them
|
|
55
|
-
- ⚠️ [Breaking] Update supported Admin API versions [#310](https://github.com/Shopify/shopify-node
|
|
56
|
-
- Allow full paths in REST requests [#301](https://github.com/Shopify/shopify-node
|
|
80
|
+
- ⚠️ [Breaking] Update supported Admin API versions [#310](https://github.com/Shopify/shopify-api-node/pull/310)
|
|
81
|
+
- Allow full paths in REST requests [#301](https://github.com/Shopify/shopify-api-node/pull/301)
|
|
57
82
|
|
|
58
83
|
### Fixed
|
|
59
84
|
|
|
60
|
-
- ⚠️ [Breaking] Stop responding to the request in the GraphQL Proxy function, returning Shopify's response instead [#312](https://github.com/Shopify/shopify-node
|
|
85
|
+
- ⚠️ [Breaking] Stop responding to the request in the GraphQL Proxy function, returning Shopify's response instead [#312](https://github.com/Shopify/shopify-api-node/pull/312)
|
|
61
86
|
|
|
62
87
|
The examples below are in [express](https://expressjs.com/); you will now need to handle the response yourself.
|
|
63
88
|
|
|
@@ -82,76 +107,76 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
|
82
107
|
|
|
83
108
|
### Added
|
|
84
109
|
|
|
85
|
-
- Add support for January 2022 API version [#285](https://github.com/Shopify/shopify-node
|
|
110
|
+
- Add support for January 2022 API version [#285](https://github.com/Shopify/shopify-api-node/pull/285)
|
|
86
111
|
|
|
87
112
|
## [2.0.0] - 2021-10-28
|
|
88
113
|
|
|
89
114
|
### Added
|
|
90
115
|
|
|
91
|
-
- Add a 5 second `clockTolerance` to fix `jwt not active` error [#227](https://github.com/Shopify/shopify-node
|
|
92
|
-
- [Breaking] Change default for OAuth.beginAuth to online sessions [#203](https://github.com/Shopify/shopify-node
|
|
93
|
-
- see [oauth.md](https://github.com/Shopify/shopify-node
|
|
94
|
-
- [Breaking] Return and delete session in `validateAuthCallback` [#217](https://github.com/Shopify/shopify-node
|
|
95
|
-
- see [oauth.md](https://github.com/Shopify/shopify-node
|
|
96
|
-
- [Breaking] Extract `addHandler` and `getHandler` methods for webhooks out of `register` [#205](https://github.com/Shopify/shopify-node
|
|
97
|
-
- [Breaking] Sessions no longer default to `false` for `isOnline` [#169](https://github.com/Shopify/shopify-node
|
|
98
|
-
- Required `Session` arguments must be passed to the constructor [#169](https://github.com/Shopify/shopify-node
|
|
99
|
-
- Allow `undefined` in `AuthScopes` [#169](https://github.com/Shopify/shopify-node
|
|
116
|
+
- Add a 5 second `clockTolerance` to fix `jwt not active` error [#227](https://github.com/Shopify/shopify-api-node/pull/227)
|
|
117
|
+
- ⚠️ [Breaking] Change default for OAuth.beginAuth to online sessions [#203](https://github.com/Shopify/shopify-api-node/pull/203)
|
|
118
|
+
- see [oauth.md](https://github.com/Shopify/shopify-api-node/blob/main/docs/usage/oauth.md) for updated docs
|
|
119
|
+
- ⚠️ [Breaking] Return and delete session in `validateAuthCallback` [#217](https://github.com/Shopify/shopify-api-node/pull/217)
|
|
120
|
+
- see [oauth.md](https://github.com/Shopify/shopify-api-node/blob/main/docs/usage/oauth.md) for updated usage
|
|
121
|
+
- ⚠️ [Breaking] Extract `addHandler` and `getHandler` methods for webhooks out of `register` [#205](https://github.com/Shopify/shopify-api-node/pull/205)
|
|
122
|
+
- ⚠️ [Breaking] Sessions no longer default to `false` for `isOnline` [#169](https://github.com/Shopify/shopify-api-node/pull/169)
|
|
123
|
+
- Required `Session` arguments must be passed to the constructor [#169](https://github.com/Shopify/shopify-api-node/pull/169)
|
|
124
|
+
- Allow `undefined` in `AuthScopes` [#169](https://github.com/Shopify/shopify-api-node/pull/169)
|
|
100
125
|
|
|
101
126
|
## [1.4.3] - 2021-10-22
|
|
102
127
|
|
|
103
128
|
### Fixed
|
|
104
129
|
|
|
105
|
-
- Fixed the HTTP client error messages to expand objects [#252](https://github.com/Shopify/shopify-node
|
|
130
|
+
- Fixed the HTTP client error messages to expand objects [#252](https://github.com/Shopify/shopify-api-node/pull/252)
|
|
106
131
|
|
|
107
132
|
## [1.4.2] - 2021-10-20
|
|
108
133
|
|
|
109
|
-
- Added `October21` to `ApiVersion` [#247](https://github.com/Shopify/shopify-node
|
|
134
|
+
- Added `October21` to `ApiVersion` [#247](https://github.com/Shopify/shopify-api-node/pull/247)
|
|
110
135
|
|
|
111
136
|
## [1.4.1] - 2021-06-11
|
|
112
137
|
|
|
113
|
-
- Don't include extra params when calculating local hmac [#196](https://github.com/Shopify/shopify-node
|
|
138
|
+
- Don't include extra params when calculating local hmac [#196](https://github.com/Shopify/shopify-api-node/pull/196)
|
|
114
139
|
|
|
115
140
|
## [1.4.0] - 2021-05-21
|
|
116
141
|
|
|
117
142
|
### Added
|
|
118
143
|
|
|
119
|
-
- Add support for registering Google Pub/Sub webhooks [#181](https://github.com/Shopify/shopify-node
|
|
120
|
-
- Added `July21` to `ApiVersion` [#181](https://github.com/Shopify/shopify-node
|
|
144
|
+
- Add support for registering Google Pub/Sub webhooks [#181](https://github.com/Shopify/shopify-api-node/pull/181)
|
|
145
|
+
- Added `July21` to `ApiVersion` [#181](https://github.com/Shopify/shopify-api-node/pull/181)
|
|
121
146
|
|
|
122
147
|
## [1.3.0] - 2021-05-12
|
|
123
148
|
|
|
124
149
|
### Added
|
|
125
150
|
|
|
126
151
|
- Added Storefront API client under `Shopify.Clients.Storefront`
|
|
127
|
-
- 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
|
|
152
|
+
- 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-api-node/pull/153)
|
|
128
153
|
|
|
129
154
|
## [1.2.1] - 2021-03-26
|
|
130
155
|
|
|
131
156
|
### Added
|
|
132
157
|
|
|
133
|
-
- Added `April21` to `ApiVersion` [#149](https://github.com/Shopify/shopify-node
|
|
158
|
+
- Added `April21` to `ApiVersion` [#149](https://github.com/Shopify/shopify-api-node/pull/149)
|
|
134
159
|
|
|
135
160
|
## [1.2.0] - 2021-03-16
|
|
136
161
|
|
|
137
162
|
### Added
|
|
138
163
|
|
|
139
|
-
- Allow plain objects to be returned from the `loadCallback` on `CustomSessionStorage` [#126](https://github.com/
|
|
140
|
-
- Documentation and example code for `CustomSessionStorage` [#129](https://github.com/
|
|
164
|
+
- Allow plain objects to be returned from the `loadCallback` on `CustomSessionStorage` [#126](https://github.com/Shopify/shopify-api-node/pull/126)
|
|
165
|
+
- Documentation and example code for `CustomSessionStorage` [#129](https://github.com/Shopify/shopify-api-node/pull/129)
|
|
141
166
|
|
|
142
167
|
### Fixed
|
|
143
168
|
|
|
144
|
-
- Throw a different error for a missing cookie upon OAuth return [#131](https://github.com/
|
|
145
|
-
- Improved documentation for GraphQL and Rest Clients. [#123](https://github.com/Shopify/shopify-node
|
|
146
|
-
- Made Docs directory more browseable in GitHub. [#136](https://github.com/Shopify/shopify-node
|
|
147
|
-
- Make sure `CustomSessionStorage` converts the `expires` field from a string to `Date`. [#132](https://github.com/Shopify/shopify-node
|
|
148
|
-
- Made `limit` optional for get-requests with query [#135](https://github.com/Shopify/shopify-node
|
|
169
|
+
- Throw a different error for a missing cookie upon OAuth return [#131](https://github.com/Shopify/shopify-api-node/pull/131)
|
|
170
|
+
- Improved documentation for GraphQL and Rest Clients. [#123](https://github.com/Shopify/shopify-api-node/pull/123)
|
|
171
|
+
- Made Docs directory more browseable in GitHub. [#136](https://github.com/Shopify/shopify-api-node/pull/136)
|
|
172
|
+
- Make sure `CustomSessionStorage` converts the `expires` field from a string to `Date`. [#132](https://github.com/Shopify/shopify-api-node/pull/132)
|
|
173
|
+
- Made `limit` optional for get-requests with query [#135](https://github.com/Shopify/shopify-api-node/pull/135)
|
|
149
174
|
|
|
150
175
|
## [1.1.0] - 2021-03-02
|
|
151
176
|
|
|
152
177
|
- Minor text/doc changes
|
|
153
|
-
- Added `2021-01` API version to enum. [#117](https://github.com/
|
|
154
|
-
- Allow retrieving offline sessions using `loadCurrentSession`. [#119](https://github.com/
|
|
178
|
+
- Added `2021-01` API version to enum. [#117](https://github.com/Shopify/shopify-api-node/pull/117)
|
|
179
|
+
- Allow retrieving offline sessions using `loadCurrentSession`. [#119](https://github.com/Shopify/shopify-api-node/pull/119)
|
|
155
180
|
|
|
156
181
|
## [1.0.0]
|
|
157
182
|
|
|
@@ -161,56 +186,56 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
|
161
186
|
|
|
162
187
|
### Added
|
|
163
188
|
|
|
164
|
-
- Added `AuthScopes` value object to allow apps to easily check whether scopes have been updated. [#110](https://github.com/
|
|
189
|
+
- Added `AuthScopes` value object to allow apps to easily check whether scopes have been updated. [#110](https://github.com/Shopify/shopify-api-node/pull/110)
|
|
165
190
|
|
|
166
191
|
### Fixed
|
|
167
192
|
|
|
168
|
-
- GraphQL Proxy attempts to parse the request body as JSON before passing it to the client. [#106](https://github.com/
|
|
193
|
+
- GraphQL Proxy attempts to parse the request body as JSON before passing it to the client. [#106](https://github.com/Shopify/shopify-api-node/pull/106)
|
|
169
194
|
|
|
170
195
|
## [0.4.0] - 2021-02-10
|
|
171
196
|
|
|
172
197
|
### Added
|
|
173
198
|
|
|
174
|
-
- Webhooks types are now exported outside the library [#91](https://github.com/
|
|
175
|
-
- Added support for private apps [#99](https://github.com/Shopify/shopify-node
|
|
176
|
-
- `USER_AGENT_PREFIX` added to Context, to add agent to all requests [#101](https://github.com/Shopify/shopify-node
|
|
177
|
-
- Add link to tutorial on how to rotate credentials if neccesary [#107](https://github.com/Shopify/shopify-node
|
|
199
|
+
- Webhooks types are now exported outside the library [#91](https://github.com/Shopify/shopify-api-node/pull/91)
|
|
200
|
+
- Added support for private apps [#99](https://github.com/Shopify/shopify-api-node/pull/99)
|
|
201
|
+
- `USER_AGENT_PREFIX` added to Context, to add agent to all requests [#101](https://github.com/Shopify/shopify-api-node/pull/101)
|
|
202
|
+
- Add link to tutorial on how to rotate credentials if neccesary [#107](https://github.com/Shopify/shopify-api-node/pull/107)
|
|
178
203
|
|
|
179
204
|
### Fixed
|
|
180
205
|
|
|
181
|
-
- Export `withSession` utility method [#96](https://github.com/Shopify/shopify-node
|
|
182
|
-
- GraphQL Client appropriately handles queries with variables [#97](https://github.com/Shopify/shopify-node
|
|
183
|
-
- Use cryptographically random bytes to generate nonce [#98](https://github.com/Shopify/shopify-node
|
|
184
|
-
- Stop using `SameSite=none` cookies for OAuth, using `lax` instead [#100](https://github.com/Shopify/shopify-node
|
|
206
|
+
- Export `withSession` utility method [#96](https://github.com/Shopify/shopify-api-node/pull/96)
|
|
207
|
+
- GraphQL Client appropriately handles queries with variables [#97](https://github.com/Shopify/shopify-api-node/pull/97)
|
|
208
|
+
- Use cryptographically random bytes to generate nonce [#98](https://github.com/Shopify/shopify-api-node/pull/98)
|
|
209
|
+
- Stop using `SameSite=none` cookies for OAuth, using `lax` instead [#100](https://github.com/Shopify/shopify-api-node/pull/100)
|
|
185
210
|
|
|
186
211
|
## [0.3.1] - 2021-02-03
|
|
187
212
|
|
|
188
213
|
### Fixed
|
|
189
214
|
|
|
190
|
-
- Fixed an issue when deleting the current session for embedded apps [#88](https://github.com/
|
|
215
|
+
- Fixed an issue when deleting the current session for embedded apps [#88](https://github.com/Shopify/shopify-api-node/pull/88)
|
|
191
216
|
|
|
192
217
|
## [0.3.0] - 2021-01-27
|
|
193
218
|
|
|
194
219
|
### Added
|
|
195
220
|
|
|
196
|
-
- Add `withSession` utility method [#83](https://github.com/
|
|
221
|
+
- Add `withSession` utility method [#83](https://github.com/Shopify/shopify-api-node/pull/83)
|
|
197
222
|
|
|
198
223
|
### Fixed
|
|
199
224
|
|
|
200
|
-
- Refactor library public interface [#87](https://github.com/
|
|
201
|
-
- Check if a webhook is registered before calling Shopify [#82](https://github.com/
|
|
225
|
+
- Refactor library public interface [#87](https://github.com/Shopify/shopify-api-node/pull/87)
|
|
226
|
+
- Check if a webhook is registered before calling Shopify [#82](https://github.com/Shopify/shopify-api-node/pull/82)
|
|
202
227
|
|
|
203
228
|
## [0.2.2] - 2021-01-14
|
|
204
229
|
|
|
205
230
|
### Fixed
|
|
206
231
|
|
|
207
|
-
- Ensure that the OAuth session expiration matches the cookie expiration [#72](https://github.com/
|
|
232
|
+
- Ensure that the OAuth session expiration matches the cookie expiration [#72](https://github.com/Shopify/shopify-api-node/pull/72) / [#73](https://github.com/Shopify/shopify-api-node/pull/73)
|
|
208
233
|
|
|
209
234
|
## [0.2.0] - 2021-01-13
|
|
210
235
|
|
|
211
|
-
- Preserve the OAuth cookie session for a few seconds so SPA can perform their initial load using it [#70](https://github.com/
|
|
212
|
-
- Session fetches now return `undefined` when a session is not available [#64](https://github.com/
|
|
213
|
-
- Add `deleteCurrentSession` utils method [#60](https://github.com/
|
|
236
|
+
- Preserve the OAuth cookie session for a few seconds so SPA can perform their initial load using it [#70](https://github.com/Shopify/shopify-api-node/pull/70)
|
|
237
|
+
- Session fetches now return `undefined` when a session is not available [#64](https://github.com/Shopify/shopify-api-node/pull/64)
|
|
238
|
+
- Add `deleteCurrentSession` utils method [#60](https://github.com/Shopify/shopify-api-node/pull/60)
|
|
214
239
|
|
|
215
240
|
## [0.1.0] - 2020-12-17
|
|
216
241
|
|
|
@@ -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;
|
|
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"}
|
package/dist/auth/oauth/oauth.js
CHANGED
|
@@ -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(
|
|
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(
|
|
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;
|
|
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;
|
|
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;AAIlD,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;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,GAAG,SAAS,CAAC;IACrE,QAAQ,CAAC,cAAc,EAAE,CAAC,EAAE,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;
|
|
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;
|
|
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;AAIlD,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,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,CAAC,4BAA4B,CAAC;IAa7C,SAAgB,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,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 },
|
|
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
|
|
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
|
-
|
|
52
|
-
|
|
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) {
|