oneentry 1.0.176 → 1.0.177

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 (197) hide show
  1. package/README.md +12 -5
  2. package/changelog.md +116 -0
  3. package/dist/admins/adminsApi.js +2 -9
  4. package/dist/admins/adminsInterfaces.d.ts +5 -5
  5. package/dist/admins/adminsSchemas.d.ts +4 -4
  6. package/dist/admins/adminsSchemas.js +2 -2
  7. package/dist/attribute-sets/attributeSetsApi.d.ts +1 -1
  8. package/dist/attribute-sets/attributeSetsApi.js +4 -4
  9. package/dist/attribute-sets/attributeSetsInterfaces.d.ts +65 -14
  10. package/dist/attribute-sets/attributeSetsSchemas.d.ts +8 -6
  11. package/dist/attribute-sets/attributeSetsSchemas.js +6 -9
  12. package/dist/auth-provider/authProviderApi.d.ts +4 -4
  13. package/dist/auth-provider/authProviderApi.js +90 -23
  14. package/dist/auth-provider/authProviderSchemas.d.ts +1 -0
  15. package/dist/auth-provider/authProviderSchemas.js +1 -0
  16. package/dist/auth-provider/authProvidersInterfaces.d.ts +8 -6
  17. package/dist/base/asyncModules.d.ts +62 -1
  18. package/dist/base/asyncModules.js +219 -37
  19. package/dist/base/stateModule.d.ts +2 -0
  20. package/dist/base/stateModule.js +22 -12
  21. package/dist/base/syncModules.d.ts +18 -10
  22. package/dist/base/syncModules.js +100 -29
  23. package/dist/base/utils.d.ts +26 -21
  24. package/dist/base/validation.d.ts +3 -3
  25. package/dist/base/validation.js +6 -7
  26. package/dist/blocks/blocksApi.d.ts +20 -17
  27. package/dist/blocks/blocksApi.js +82 -64
  28. package/dist/blocks/blocksInterfaces.d.ts +8 -8
  29. package/dist/discounts/discountsApi.d.ts +9 -7
  30. package/dist/discounts/discountsApi.js +16 -13
  31. package/dist/discounts/discountsInterfaces.d.ts +14 -10
  32. package/dist/events/eventsApi.d.ts +3 -3
  33. package/dist/events/eventsApi.js +3 -3
  34. package/dist/events/eventsInterfaces.d.ts +10 -14
  35. package/dist/file-uploading/fileUploadingApi.d.ts +4 -4
  36. package/dist/file-uploading/fileUploadingApi.js +13 -5
  37. package/dist/file-uploading/fileUploadingInterfaces.d.ts +5 -6
  38. package/dist/filters/filtersApi.js +2 -2
  39. package/dist/forms/formsApi.js +2 -2
  40. package/dist/forms/formsInterfaces.d.ts +1 -3
  41. package/dist/forms/formsSchemas.d.ts +3 -6
  42. package/dist/forms/formsSchemas.js +2 -4
  43. package/dist/forms-data/formsDataApi.d.ts +16 -0
  44. package/dist/forms-data/formsDataApi.js +32 -5
  45. package/dist/forms-data/formsDataInterfaces.d.ts +17 -13
  46. package/dist/general-types/generalTypesInterfaces.d.ts +1 -1
  47. package/dist/index.d.ts +7 -6
  48. package/dist/index.js +50 -7
  49. package/dist/integration-collections/integrationCollectionsApi.d.ts +15 -4
  50. package/dist/integration-collections/integrationCollectionsApi.js +41 -14
  51. package/dist/integration-collections/integrationCollectionsInterfaces.d.ts +8 -9
  52. package/dist/integration-collections/integrationCollectionsSchemas.d.ts +0 -2
  53. package/dist/integration-collections/integrationCollectionsSchemas.js +0 -1
  54. package/dist/menus/menusApi.js +1 -1
  55. package/dist/orders/ordersApi.d.ts +1 -13
  56. package/dist/orders/ordersApi.js +21 -42
  57. package/dist/orders/ordersInterfaces.d.ts +21 -14
  58. package/dist/pages/pagesApi.d.ts +6 -5
  59. package/dist/pages/pagesApi.js +44 -31
  60. package/dist/pages/pagesInterfaces.d.ts +18 -15
  61. package/dist/pages/pagesSchemas.d.ts +0 -3
  62. package/dist/pages/pagesSchemas.js +0 -1
  63. package/dist/payments/paymentsApi.d.ts +10 -11
  64. package/dist/payments/paymentsApi.js +22 -18
  65. package/dist/payments/paymentsInterfaces.d.ts +12 -14
  66. package/dist/payments/paymentsSchemas.d.ts +21 -20
  67. package/dist/payments/paymentsSchemas.js +5 -8
  68. package/dist/product-statuses/productStatusesApi.d.ts +1 -1
  69. package/dist/product-statuses/productStatusesApi.js +3 -3
  70. package/dist/product-statuses/productStatusesInterfaces.d.ts +1 -4
  71. package/dist/products/productsApi.d.ts +38 -58
  72. package/dist/products/productsApi.js +59 -72
  73. package/dist/products/productsInterfaces.d.ts +48 -85
  74. package/dist/search/searchApi.d.ts +1 -1
  75. package/dist/search/searchApi.js +4 -3
  76. package/dist/sitemap/sitemapInterfaces.d.ts +10 -6
  77. package/dist/subscriptions/subscriptionsApi.d.ts +1 -1
  78. package/dist/subscriptions/subscriptionsApi.js +1 -1
  79. package/dist/subscriptions/subscriptionsInterfaces.d.ts +1 -1
  80. package/dist/system/systemApi.d.ts +2 -0
  81. package/dist/system/systemApi.js +2 -0
  82. package/dist/system/systemInterfaces.d.ts +2 -0
  83. package/dist/templates/templatesApi.d.ts +2 -2
  84. package/dist/templates/templatesApi.js +12 -11
  85. package/dist/templates/templatesInterfaces.d.ts +2 -2
  86. package/dist/templates-preview/templatesPreviewApi.js +2 -2
  87. package/dist/templates-preview/templatesPreviewInterfaces.d.ts +23 -13
  88. package/dist/templates-preview/templatesPreviewSchemas.d.ts +7 -0
  89. package/dist/templates-preview/templatesPreviewSchemas.js +2 -0
  90. package/dist/user-groups/userGroupsApi.js +5 -5
  91. package/dist/user-groups/userGroupsSchemas.d.ts +4 -4
  92. package/dist/users/usersApi.d.ts +1 -1
  93. package/dist/users/usersApi.js +28 -15
  94. package/dist/users/usersInterfaces.d.ts +2 -9
  95. package/dist/web-socket/lazySocket.d.ts +6 -5
  96. package/dist/web-socket/lazySocket.js +212 -15
  97. package/dist/web-socket/wsApi.d.ts +7 -4
  98. package/dist/web-socket/wsApi.js +49 -12
  99. package/dist/web-socket/wsInterfaces.d.ts +41 -4
  100. package/esm/admins/adminsApi.js +2 -9
  101. package/esm/admins/adminsInterfaces.d.ts +5 -5
  102. package/esm/admins/adminsSchemas.d.ts +4 -4
  103. package/esm/admins/adminsSchemas.js +2 -2
  104. package/esm/attribute-sets/attributeSetsApi.d.ts +1 -1
  105. package/esm/attribute-sets/attributeSetsApi.js +4 -4
  106. package/esm/attribute-sets/attributeSetsInterfaces.d.ts +65 -14
  107. package/esm/attribute-sets/attributeSetsSchemas.d.ts +8 -6
  108. package/esm/attribute-sets/attributeSetsSchemas.js +6 -9
  109. package/esm/auth-provider/authProviderApi.d.ts +4 -4
  110. package/esm/auth-provider/authProviderApi.js +90 -23
  111. package/esm/auth-provider/authProviderSchemas.d.ts +1 -0
  112. package/esm/auth-provider/authProviderSchemas.js +1 -0
  113. package/esm/auth-provider/authProvidersInterfaces.d.ts +8 -6
  114. package/esm/base/asyncModules.d.ts +62 -1
  115. package/esm/base/asyncModules.js +219 -37
  116. package/esm/base/stateModule.d.ts +2 -0
  117. package/esm/base/stateModule.js +22 -12
  118. package/esm/base/syncModules.d.ts +18 -10
  119. package/esm/base/syncModules.js +99 -29
  120. package/esm/base/utils.d.ts +26 -21
  121. package/esm/base/validation.d.ts +3 -3
  122. package/esm/base/validation.js +6 -7
  123. package/esm/blocks/blocksApi.d.ts +20 -17
  124. package/esm/blocks/blocksApi.js +82 -64
  125. package/esm/blocks/blocksInterfaces.d.ts +8 -8
  126. package/esm/discounts/discountsApi.d.ts +9 -7
  127. package/esm/discounts/discountsApi.js +16 -13
  128. package/esm/discounts/discountsInterfaces.d.ts +14 -10
  129. package/esm/events/eventsApi.d.ts +3 -3
  130. package/esm/events/eventsApi.js +3 -3
  131. package/esm/events/eventsInterfaces.d.ts +10 -14
  132. package/esm/file-uploading/fileUploadingApi.d.ts +4 -4
  133. package/esm/file-uploading/fileUploadingApi.js +13 -5
  134. package/esm/file-uploading/fileUploadingInterfaces.d.ts +5 -6
  135. package/esm/filters/filtersApi.js +2 -2
  136. package/esm/forms/formsApi.js +2 -2
  137. package/esm/forms/formsInterfaces.d.ts +1 -3
  138. package/esm/forms/formsSchemas.d.ts +3 -6
  139. package/esm/forms/formsSchemas.js +2 -4
  140. package/esm/forms-data/formsDataApi.d.ts +16 -0
  141. package/esm/forms-data/formsDataApi.js +32 -5
  142. package/esm/forms-data/formsDataInterfaces.d.ts +17 -13
  143. package/esm/general-types/generalTypesInterfaces.d.ts +1 -1
  144. package/esm/index.d.ts +7 -6
  145. package/esm/index.js +50 -7
  146. package/esm/integration-collections/integrationCollectionsApi.d.ts +15 -4
  147. package/esm/integration-collections/integrationCollectionsApi.js +41 -14
  148. package/esm/integration-collections/integrationCollectionsInterfaces.d.ts +8 -9
  149. package/esm/integration-collections/integrationCollectionsSchemas.d.ts +0 -2
  150. package/esm/integration-collections/integrationCollectionsSchemas.js +0 -1
  151. package/esm/menus/menusApi.js +1 -1
  152. package/esm/orders/ordersApi.d.ts +1 -13
  153. package/esm/orders/ordersApi.js +21 -42
  154. package/esm/orders/ordersInterfaces.d.ts +21 -14
  155. package/esm/pages/pagesApi.d.ts +6 -5
  156. package/esm/pages/pagesApi.js +44 -31
  157. package/esm/pages/pagesInterfaces.d.ts +18 -15
  158. package/esm/pages/pagesSchemas.d.ts +0 -3
  159. package/esm/pages/pagesSchemas.js +0 -1
  160. package/esm/payments/paymentsApi.d.ts +10 -11
  161. package/esm/payments/paymentsApi.js +22 -18
  162. package/esm/payments/paymentsInterfaces.d.ts +12 -14
  163. package/esm/payments/paymentsSchemas.d.ts +21 -20
  164. package/esm/payments/paymentsSchemas.js +5 -8
  165. package/esm/product-statuses/productStatusesApi.d.ts +1 -1
  166. package/esm/product-statuses/productStatusesApi.js +3 -3
  167. package/esm/product-statuses/productStatusesInterfaces.d.ts +1 -4
  168. package/esm/products/productsApi.d.ts +38 -58
  169. package/esm/products/productsApi.js +59 -72
  170. package/esm/products/productsInterfaces.d.ts +48 -85
  171. package/esm/search/searchApi.d.ts +1 -1
  172. package/esm/search/searchApi.js +4 -3
  173. package/esm/sitemap/sitemapInterfaces.d.ts +10 -6
  174. package/esm/subscriptions/subscriptionsApi.d.ts +1 -1
  175. package/esm/subscriptions/subscriptionsApi.js +1 -1
  176. package/esm/subscriptions/subscriptionsInterfaces.d.ts +1 -1
  177. package/esm/system/systemApi.d.ts +2 -0
  178. package/esm/system/systemApi.js +2 -0
  179. package/esm/system/systemInterfaces.d.ts +2 -0
  180. package/esm/templates/templatesApi.d.ts +2 -2
  181. package/esm/templates/templatesApi.js +11 -10
  182. package/esm/templates/templatesInterfaces.d.ts +2 -2
  183. package/esm/templates-preview/templatesPreviewApi.js +2 -2
  184. package/esm/templates-preview/templatesPreviewInterfaces.d.ts +23 -13
  185. package/esm/templates-preview/templatesPreviewSchemas.d.ts +7 -0
  186. package/esm/templates-preview/templatesPreviewSchemas.js +2 -0
  187. package/esm/user-groups/userGroupsApi.js +5 -5
  188. package/esm/user-groups/userGroupsSchemas.d.ts +4 -4
  189. package/esm/users/usersApi.d.ts +1 -1
  190. package/esm/users/usersApi.js +28 -15
  191. package/esm/users/usersInterfaces.d.ts +2 -9
  192. package/esm/web-socket/lazySocket.d.ts +6 -5
  193. package/esm/web-socket/lazySocket.js +212 -15
  194. package/esm/web-socket/wsApi.d.ts +7 -4
  195. package/esm/web-socket/wsApi.js +49 -12
  196. package/esm/web-socket/wsInterfaces.d.ts +41 -4
  197. package/package.json +2 -2
@@ -90,7 +90,7 @@ export default class AuthProviderApi extends AsyncModules implements IAuthProvid
90
90
  * @handleName generateCode
91
91
  * @param {string} marker - Marker of the auth provider. Example: "email".
92
92
  * @param {string} userIdentifier - Identifier (login) of the user, such as an email address. Example: "example@oneentry.cloud".
93
- * @param {string} eventIdentifier - Marker of the event the code is generated for. Example: "user_registration".
93
+ * @param {string} eventIdentifier - Marker of the event the code is generated for. Example: "reg".
94
94
  * @returns {Promise<void | IError>} Returns void if the code is successfully generated, or an error object if there was an issue.
95
95
  * @throws {IError} When isShell=false and an error occurs during the fetch
96
96
  * @description Obtaining a code to activate the user.
@@ -102,7 +102,7 @@ export default class AuthProviderApi extends AsyncModules implements IAuthProvid
102
102
  * @handleName checkCode
103
103
  * @param {string} marker - Marker of the auth provider. Example: "email".
104
104
  * @param {string} userIdentifier - The text identifier of the user's object (user login). Example: "example@oneentry.cloud".
105
- * @param {string} eventIdentifier - Marker of the event the code is generated for. Example: "user_registration".
105
+ * @param {string} eventIdentifier - Marker of the event the code is generated for. Example: "reg".
106
106
  * @param {string} code - One-time code the user received. Example: "123456".
107
107
  * @returns {Promise<boolean | IError>} Returns true if the code is correct, or an error object if there was an issue.
108
108
  * @throws {IError} When isShell=false and an error occurs during the fetch
@@ -140,7 +140,7 @@ export default class AuthProviderApi extends AsyncModules implements IAuthProvid
140
140
  }
141
141
  ]
142
142
  }
143
- * @param {{ marker: string; value: string | number }[]} body.authData - An array of authentication data objects, each containing a marker and its corresponding value.
143
+ * @param {{ marker: string; value: string }[]} body.authData - An array of authentication data objects, each containing a marker and its corresponding value.
144
144
  * @example
145
145
  [
146
146
  {
@@ -253,7 +253,7 @@ export default class AuthProviderApi extends AsyncModules implements IAuthProvid
253
253
  "redirect_uri": "http://localhost:3000"
254
254
  }
255
255
  * @param {string} [langCode] - Language code. Default: "en_US".
256
- * @returns {Promise<ISignUpEntity | IError>} Returns a user object.
256
+ * @returns {Promise<IAuthEntity | IError>} Returns the tokens of the signed-in user; they are stored in the state like after `auth`.
257
257
  * @throws {IError} When isShell=false and an error occurs during the fetch
258
258
  * @description User registration (authorization) via OAUTH.
259
259
  * @see {@link https://js-sdk.oneentry.cloud/docs/auth-provider/oauth oauth} documentation.
@@ -126,17 +126,19 @@ class AuthProviderApi extends asyncModules_1.default {
126
126
  async signUp(marker, body, langCode = this.state.lang) {
127
127
  // `langCode` goes onto our own copy — the caller's body stays as it was
128
128
  // given, so a retry or a second parallel call sends the same thing (CMS-909).
129
- const result = await this._fetchPost(`/marker/${this._pathSegment(marker)}/users/sign-up`, this._normalizePostBody({ ...body, langCode }, langCode));
129
+ const result = await this._asSignIn()._fetchPost(`/marker/${this._pathSegment(marker)}/users/sign-up`, this._normalizePostBody({ ...body, langCode }, langCode));
130
130
  // Validate response if validation is enabled
131
131
  const validated = await this._validateResponse(result, schema('SignUpResponseSchema'));
132
- return this._normalizeData(validated);
132
+ // The fields went in under `langCode`; without it a sign-up in another language
133
+ // returned `formData` still keyed by that language
134
+ return this._normalizeData(validated, langCode);
133
135
  }
134
136
  /**
135
137
  * Getting a user activation code. The code is returned via the appropriate user notification method.
136
138
  * @handleName generateCode
137
139
  * @param {string} marker - Marker of the auth provider. Example: "email".
138
140
  * @param {string} userIdentifier - Identifier (login) of the user, such as an email address. Example: "example@oneentry.cloud".
139
- * @param {string} eventIdentifier - Marker of the event the code is generated for. Example: "user_registration".
141
+ * @param {string} eventIdentifier - Marker of the event the code is generated for. Example: "reg".
140
142
  * @returns {Promise<void | IError>} Returns void if the code is successfully generated, or an error object if there was an issue.
141
143
  * @throws {IError} When isShell=false and an error occurs during the fetch
142
144
  * @description Obtaining a code to activate the user.
@@ -148,14 +150,15 @@ class AuthProviderApi extends asyncModules_1.default {
148
150
  eventIdentifier,
149
151
  };
150
152
  const result = await this._fetchPost(`/marker/${this._pathSegment(marker)}/users/generate-code`, data);
151
- return result;
153
+ // An empty 2xx body is read as `{}`; the method returns nothing on success
154
+ return this._isErrorResponse(result) ? result : undefined;
152
155
  }
153
156
  /**
154
157
  * User activation code verification. Returns true (if the code is correct) or false (if it is incorrect).
155
158
  * @handleName checkCode
156
159
  * @param {string} marker - Marker of the auth provider. Example: "email".
157
160
  * @param {string} userIdentifier - The text identifier of the user's object (user login). Example: "example@oneentry.cloud".
158
- * @param {string} eventIdentifier - Marker of the event the code is generated for. Example: "user_registration".
161
+ * @param {string} eventIdentifier - Marker of the event the code is generated for. Example: "reg".
159
162
  * @param {string} code - One-time code the user received. Example: "123456".
160
163
  * @returns {Promise<boolean | IError>} Returns true if the code is correct, or an error object if there was an issue.
161
164
  * @throws {IError} When isShell=false and an error occurs during the fetch
@@ -169,7 +172,7 @@ class AuthProviderApi extends asyncModules_1.default {
169
172
  code,
170
173
  };
171
174
  const result = await this._fetchPost(`/marker/${this._pathSegment(marker)}/users/check-code`, data);
172
- return result;
175
+ return this._asBoolean(result);
173
176
  }
174
177
  /**
175
178
  * User activate.
@@ -188,7 +191,7 @@ class AuthProviderApi extends asyncModules_1.default {
188
191
  code: code,
189
192
  };
190
193
  const result = await this._fetchPost(`/marker/${this._pathSegment(marker)}/users/activate`, data);
191
- return result;
194
+ return this._asBoolean(result);
192
195
  }
193
196
  /**
194
197
  * User authorization.
@@ -208,7 +211,7 @@ class AuthProviderApi extends asyncModules_1.default {
208
211
  }
209
212
  ]
210
213
  }
211
- * @param {{ marker: string; value: string | number }[]} body.authData - An array of authentication data objects, each containing a marker and its corresponding value.
214
+ * @param {{ marker: string; value: string }[]} body.authData - An array of authentication data objects, each containing a marker and its corresponding value.
212
215
  * @example
213
216
  [
214
217
  {
@@ -224,12 +227,14 @@ class AuthProviderApi extends asyncModules_1.default {
224
227
  * @see {@link https://js-sdk.oneentry.cloud/docs/auth-provider/auth auth} documentation.
225
228
  */
226
229
  async auth(marker, body) {
227
- const result = await this._fetchPost(`/marker/${this._pathSegment(marker)}/users/auth`, body);
230
+ const result = await this._asSignIn()._fetchPost(`/marker/${this._pathSegment(marker)}/users/auth`, body);
228
231
  // Validate response if validation is enabled
229
232
  const validated = await this._validateResponse(result, schema('AuthResponseSchema'));
230
233
  if (!('statusCode' in validated)) {
231
234
  this.state.accessToken = validated.accessToken;
232
235
  this.state.refreshToken = validated.refreshToken;
236
+ // The automatic refresh has to use the provider the session was opened with
237
+ this.state.providerMarker = marker;
233
238
  if (this.state.saveFunction && validated.refreshToken) {
234
239
  this.state.saveFunction(validated.refreshToken);
235
240
  }
@@ -248,10 +253,17 @@ class AuthProviderApi extends asyncModules_1.default {
248
253
  */
249
254
  async refresh(marker, token) {
250
255
  const data = { refreshToken: token };
251
- const result = await this._fetchPost(`/marker/${this._pathSegment(marker)}/users/refresh`, data);
252
- if (!('statusCode' in result)) {
256
+ // Sent as is: through the regular path a restored session (refresh token, no access
257
+ // token) first refreshed on its own, rotated this very token and the call answered 400
258
+ const result = await this._asSignIn()._fetchPost(`/marker/${this._pathSegment(marker)}/users/refresh`, data);
259
+ // Tokens are stored only when the answer carries them: an empty 2xx body came back
260
+ // as `{}` and wiped the session (`saveFunction(undefined)`)
261
+ if (!this._isErrorResponse(result) &&
262
+ typeof (result === null || result === void 0 ? void 0 : result.refreshToken) === 'string' &&
263
+ typeof (result === null || result === void 0 ? void 0 : result.accessToken) === 'string') {
253
264
  this.state.accessToken = result.accessToken;
254
265
  this.state.refreshToken = result.refreshToken;
266
+ this.state.providerMarker = marker;
255
267
  if (this.state.saveFunction) {
256
268
  this.state.saveFunction(result.refreshToken);
257
269
  }
@@ -270,11 +282,51 @@ class AuthProviderApi extends asyncModules_1.default {
270
282
  * @see {@link https://js-sdk.oneentry.cloud/docs/auth-provider/logout logout} documentation.
271
283
  */
272
284
  async logout(marker, token) {
273
- const data = {
274
- refreshToken: token,
285
+ var _a;
286
+ // Logout needs a bearer, so a restored session refreshes first — and that rotates the
287
+ // token passed in. Refresh up front and log out with the rotated one, or the call
288
+ // answered 400 and the session stayed alive
289
+ const wasCurrent = token === this.state.refreshToken;
290
+ if (!this.state.accessToken &&
291
+ !this.state.customAuth &&
292
+ wasCurrent &&
293
+ this._canRefresh() &&
294
+ (await this.refreshToken())) {
295
+ token = this.state.refreshToken;
296
+ }
297
+ const path = `/marker/${this._pathSegment(marker)}/users/logout`;
298
+ // Sent quietly and without throwing: a 401 mid-session refreshes and rotates the token
299
+ // the body carries, the retry answers 400 — that attempt is not the caller's failure
300
+ const attempt = async (refreshToken) => {
301
+ try {
302
+ return this._asBoolean(await this._asSubRequest()._fetchPost(path, {
303
+ refreshToken,
304
+ }));
305
+ }
306
+ catch (error) {
307
+ return error;
308
+ }
275
309
  };
276
- const result = await this._fetchPost(`/marker/${this._pathSegment(marker)}/users/logout`, data);
277
- if (result) {
310
+ let result = await attempt(token);
311
+ if (this._isErrorResponse(result) &&
312
+ wasCurrent &&
313
+ this.state.refreshToken &&
314
+ this.state.refreshToken !== token) {
315
+ result = await attempt(this.state.refreshToken);
316
+ }
317
+ if (this._isErrorResponse(result)) {
318
+ const handler = (_a = this.state.errorsFunctions) === null || _a === void 0 ? void 0 : _a[result.statusCode];
319
+ if (handler) {
320
+ await handler(result);
321
+ }
322
+ if (!this.state.isShell) {
323
+ throw result;
324
+ }
325
+ return result;
326
+ }
327
+ // An error object is truthy too: a failed logout used to wipe the tokens of a
328
+ // session that is still alive on the server
329
+ if (result && !this._isErrorResponse(result)) {
278
330
  this.state.accessToken = undefined;
279
331
  this.state.refreshToken = undefined;
280
332
  if (this.state.saveFunction) {
@@ -295,14 +347,16 @@ class AuthProviderApi extends asyncModules_1.default {
295
347
  */
296
348
  async logoutAll(marker) {
297
349
  const result = await this._fetchPost(`/marker/${this._pathSegment(marker)}/users/logout-all`);
298
- if (result) {
350
+ // An error object is truthy too: a failed logout used to wipe the tokens of a
351
+ // session that is still alive on the server
352
+ if (result && !this._isErrorResponse(result)) {
299
353
  this.state.accessToken = undefined;
300
354
  this.state.refreshToken = undefined;
301
355
  if (this.state.saveFunction) {
302
356
  this.state.saveFunction('');
303
357
  }
304
358
  }
305
- return result;
359
+ return this._asBoolean(result);
306
360
  }
307
361
  /**
308
362
  * Change password.
@@ -329,7 +383,7 @@ class AuthProviderApi extends asyncModules_1.default {
329
383
  password2: repeatPassword !== null && repeatPassword !== void 0 ? repeatPassword : newPassword,
330
384
  };
331
385
  const result = await this._fetchPost(`/marker/${this._pathSegment(marker)}/users/change-password`, data);
332
- return result;
386
+ return this._asBoolean(result);
333
387
  }
334
388
  /**
335
389
  * Get all auth providers objects.
@@ -343,7 +397,7 @@ class AuthProviderApi extends asyncModules_1.default {
343
397
  * @see {@link https://js-sdk.oneentry.cloud/docs/auth-provider/getAuthProviders getAuthProviders} documentation.
344
398
  */
345
399
  async getAuthProviders(langCode = this.state.lang, offset = 0, limit = 30) {
346
- const result = await this._fetchGet(`?langCode=${langCode}&offset=${offset}&limit=${limit}`);
400
+ const result = await this._fetchGet(`?langCode=${encodeURIComponent(langCode)}&offset=${encodeURIComponent(String(offset))}&limit=${encodeURIComponent(String(limit))}`);
347
401
  // Validate response if validation is enabled
348
402
  const validated = await this._validateResponse(result, schema('AuthProvidersResponseSchema'));
349
403
  return this._normalizeData(validated);
@@ -359,7 +413,7 @@ class AuthProviderApi extends asyncModules_1.default {
359
413
  * @see {@link https://js-sdk.oneentry.cloud/docs/auth-provider/getAuthProviderByMarker getAuthProviderByMarker} documentation.
360
414
  */
361
415
  async getAuthProviderByMarker(marker, langCode = this.state.lang) {
362
- const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}?langCode=${langCode}`);
416
+ const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}?langCode=${encodeURIComponent(langCode)}`);
363
417
  return this._normalizeData(result);
364
418
  }
365
419
  /**
@@ -373,7 +427,9 @@ class AuthProviderApi extends asyncModules_1.default {
373
427
  */
374
428
  async getActiveSessionsByMarker(marker) {
375
429
  const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}/users/sessions`);
376
- return this._normalizeData(result);
430
+ // Validate response if validation is enabled
431
+ const validated = await this._validateResponse(result, schema('ActiveSessionsResponseSchema'));
432
+ return this._normalizeData(validated);
377
433
  }
378
434
  /**
379
435
  * User registration (authorization) via OAUTH.
@@ -389,13 +445,24 @@ class AuthProviderApi extends asyncModules_1.default {
389
445
  "redirect_uri": "http://localhost:3000"
390
446
  }
391
447
  * @param {string} [langCode] - Language code. Default: "en_US".
392
- * @returns {Promise<ISignUpEntity | IError>} Returns a user object.
448
+ * @returns {Promise<IAuthEntity | IError>} Returns the tokens of the signed-in user; they are stored in the state like after `auth`.
393
449
  * @throws {IError} When isShell=false and an error occurs during the fetch
394
450
  * @description User registration (authorization) via OAUTH.
395
451
  * @see {@link https://js-sdk.oneentry.cloud/docs/auth-provider/oauth oauth} documentation.
396
452
  */
397
453
  async oauth(marker, body, langCode = this.state.lang) {
398
- const result = await this._fetchPost(`/marker/${this._pathSegment(marker)}/oauth`, this._normalizePostBody(body, langCode));
454
+ // A sign-in like `auth`: no current session, no refresh on 401, and the issued
455
+ // tokens are kept — they used to stay out of the state
456
+ const result = await this._asSignIn()._fetchPost(`/marker/${this._pathSegment(marker)}/oauth`, this._normalizePostBody(body, langCode));
457
+ if (!this._isErrorResponse(result) &&
458
+ typeof (result === null || result === void 0 ? void 0 : result.accessToken) === 'string') {
459
+ this.state.accessToken = result.accessToken;
460
+ this.state.refreshToken = result.refreshToken;
461
+ this.state.providerMarker = marker;
462
+ if (this.state.saveFunction && result.refreshToken) {
463
+ this.state.saveFunction(result.refreshToken);
464
+ }
465
+ }
399
466
  return result;
400
467
  }
401
468
  }
@@ -24,6 +24,7 @@ export declare const SignUpResponseSchema: z.ZodObject<{
24
24
  importId: z.ZodNullable<z.ZodOptional<z.ZodAny>>;
25
25
  deletedAt: z.ZodNullable<z.ZodOptional<z.ZodString>>;
26
26
  isDeleted: z.ZodOptional<z.ZodBoolean>;
27
+ oauthSub: z.ZodOptional<z.ZodNullable<z.ZodString>>;
27
28
  state: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
28
29
  rating: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
29
30
  attributeSetId: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
@@ -28,6 +28,7 @@ exports.SignUpResponseSchema = zod_1.z.object({
28
28
  importId: zod_1.z.any().optional().nullable(),
29
29
  deletedAt: zod_1.z.string().optional().nullable(),
30
30
  isDeleted: zod_1.z.boolean().optional(),
31
+ oauthSub: zod_1.z.string().nullable().optional(),
31
32
  state: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
32
33
  rating: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
33
34
  attributeSetId: zod_1.z.number().nullable().optional(),
@@ -47,7 +47,7 @@ interface IAuthProvider {
47
47
  * @handleName generateCode
48
48
  * @param {string} marker - The marker identifying the auth provider. Example: "email".
49
49
  * @param {string} userIdentifier - The user's identifier. Example: "example@oneentry.cloud".
50
- * @param {string} eventIdentifier - The event identifier related to the code generation. Example: "user_registration".
50
+ * @param {string} eventIdentifier - The event identifier related to the code generation. Example: "reg".
51
51
  * @returns {void} A promise that resolves to void or an error.
52
52
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
53
53
  * @description This method generates an activation code for a user.
@@ -58,7 +58,7 @@ interface IAuthProvider {
58
58
  * @handleName checkCode
59
59
  * @param {string} marker - The marker identifying the auth provider. Example: "email".
60
60
  * @param {string} userIdentifier - The user's identifier. Example: "example@oneentry.cloud".
61
- * @param {string} eventIdentifier - The event identifier related to the code verification. Example: "user_registration".
61
+ * @param {string} eventIdentifier - The event identifier related to the code verification. Example: "reg".
62
62
  * @param {string} code - The activation code to verify. Example: "123456".
63
63
  * @returns {boolean} A promise that resolves to a boolean indicating success or failure, or an error.
64
64
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
@@ -162,7 +162,7 @@ interface IAuthProvider {
162
162
  getActiveSessionsByMarker(marker: string): Promise<IActiveSession[] | IError>;
163
163
  /**
164
164
  * User registration (authorization) via OAUTH.
165
- * @handleName oauthSignUp
165
+ * @handleName oauth
166
166
  * @param {string} marker - Marker of the auth provider. Example: "email".
167
167
  * @param {IOauthData} body - OAuth data for registration.
168
168
  * @example
@@ -174,7 +174,7 @@ interface IAuthProvider {
174
174
  "redirect_uri": "http://localhost:3000"
175
175
  }
176
176
  * @param {string} [langCode] - Language code. Default: "en_US".
177
- * @returns {ISignUpEntity} Returns a user object.
177
+ * @returns {IAuthEntity} Returns the tokens of the signed-in user; they are stored in the state like after `auth`.
178
178
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
179
179
  * @description User registration (authorization) via OAUTH.
180
180
  */
@@ -267,6 +267,7 @@ interface IOauthData {
267
267
  * @property {unknown} [importId] - Import identifier. Example: null.
268
268
  * @property {string | null} [deletedAt] - Deletion date, or `null`. Example: null.
269
269
  * @property {boolean} [isDeleted] - Whether the user account is deleted. Example: false.
270
+ * @property {string | null} [oauthSub] - Subject of the OAuth account the user is linked to; `null` for a user signed up by e-mail. Example: null.
270
271
  * @property {Record<string, unknown>} [state] - Custom key-value data stored with the user. Example: {}.
271
272
  * @property {IRating} [rating] - Rating data: average value, likes and dislikes, and the calculation method.
272
273
  * @property {number | null} [attributeSetId] - ID of the attribute set attached to the user, or `null` when none is attached. Example: null.
@@ -286,6 +287,7 @@ interface ISignUpEntity {
286
287
  importId?: unknown;
287
288
  deletedAt?: string | null;
288
289
  isDeleted?: boolean;
290
+ oauthSub?: string | null;
289
291
  state?: Record<string, unknown>;
290
292
  rating?: IRating;
291
293
  attributeSetId?: number | null;
@@ -334,7 +336,7 @@ interface IAuthEntity {
334
336
  * @property {number} version - Version number of the auth provider; changes with each update. Example: 1.
335
337
  * @property {string} identifier - Marker of the auth provider. Example: "email".
336
338
  * @property {string} type - Type of the auth provider, for example `"email"`. Example: "email".
337
- * @property {string | null} formIdentifier - Marker of the form linked to the auth provider, or `null` if there is none. Example: "reg_form".
339
+ * @property {string | null} formIdentifier - Marker of the form linked to the auth provider, or `null` if there is none. Example: "reg".
338
340
  * @property {string} userGroupIdentifier - Identifier of the user group linked to the auth provider. Example: "guest".
339
341
  * @property {boolean} isActive - Whether the auth provider is active. Example: true.
340
342
  * @property {boolean} isCheckCode - Whether the auth provider requires a verification code. Example: false.
@@ -428,4 +430,4 @@ interface IDeviceInfo {
428
430
  browser: string;
429
431
  location: string;
430
432
  }
431
- export type { IActiveSession, IAuthData, IAuthEntity, IAuthFormData, IAuthPostBody, IAuthProvider, IAuthProvidersEntity, ICodeEntity, IDeviceInfo, INotificationData, IOauthData, ISignUpData, ISignUpEntity, };
433
+ export type { IActiveSession, IAuthData, IAuthEntity, IAuthFormData, IAuthPostBody, IAuthProvider, IAuthProvidersEntity, IAuthProvidersEntityConfig, ICodeEntity, IDeviceInfo, INotificationData, IOauthData, ISignUpData, ISignUpEntity, };
@@ -22,7 +22,7 @@ export default abstract class AsyncModules extends SyncModules {
22
22
  * body — and a caught exception — instead of throwing, so a failed request
23
23
  * is indistinguishable from a successful one by control flow alone.
24
24
  * @param {unknown} value - Value returned by a request.
25
- * @returns {boolean} True when the value is an API error (statusCode >= 400) or a thrown error object.
25
+ * @returns {boolean} True when the value is an API error (statusCode >= 400), the shell error of a request that got no answer (statusCode 0) or a thrown error object.
26
26
  * @description Recognizes both the OneEntry error body and errors caught by browserResponse (e.g. a network failure).
27
27
  */
28
28
  protected _isErrorResponse(value: unknown): value is IError;
@@ -36,6 +36,58 @@ export default abstract class AsyncModules extends SyncModules {
36
36
  * validation disabled (the default) never pulls Zod into its bundle.
37
37
  */
38
38
  protected _validateResponse<T>(data: unknown, loadSchema?: () => Promise<z.ZodSchema<T>>): Promise<T | IError>;
39
+ /**
40
+ * A view of this module for sign-in and sign-up requests.
41
+ * @returns {this} An object that shares the module's state but sends the request without the current session.
42
+ * @description A sign-in with a wrong password answers `401`, the status of an expired token:
43
+ * with a session open the SDK used to refresh that session and send the same wrong password
44
+ * again — two failed attempts for one, and a rotated refresh token. Such a request carries
45
+ * no `Authorization` header and never triggers a token refresh.
46
+ */
47
+ protected _asSignIn(): this;
48
+ /**
49
+ * Set on the view `_asSignIn` returns: the request is a sign-in or sign-up.
50
+ */
51
+ protected _signIn: boolean;
52
+ /**
53
+ * A view of this module for requests the SDK makes on its own behalf.
54
+ * @returns {this} An object that shares the module's state but does not call `errors.customErrors`.
55
+ * @description The products of page blocks and the templates of pages are loaded by the SDK
56
+ * itself, and a failure there leaves an empty value. A `customErrors` handler (a Next.js
57
+ * `notFound()`) used to fire for them as if the page itself had failed.
58
+ */
59
+ protected _asSubRequest(): this;
60
+ /**
61
+ * Set on the view `_asSubRequest` returns.
62
+ */
63
+ protected _subRequest: boolean;
64
+ /**
65
+ * `_asSubRequest` for another module the SDK calls on its own behalf.
66
+ * @param {T} module - A module created by the SDK for a nested request.
67
+ * @returns {T} Its view that does not call `errors.customErrors`.
68
+ */
69
+ protected static _subRequestOf<T extends AsyncModules>(module: T): T;
70
+ /**
71
+ * Reads the answer of a call that returns `true` on success.
72
+ * @param {T} result - What the request returned.
73
+ * @returns {T | true} `true` for an empty 2xx body (read as `{}`), the value otherwise.
74
+ */
75
+ protected _asBoolean<T>(result: T): T | true;
76
+ /**
77
+ * Whether a refresh may be attempted now.
78
+ * @returns {boolean} False while the device metadata is the one the platform rejected as malformed.
79
+ */
80
+ protected _canRefresh(): boolean;
81
+ /**
82
+ * A view of this module whose requests go to another base URL.
83
+ * @param {string} url - The base URL for the view's requests.
84
+ * @returns {this} An object that shares the module's state and methods but has its own `_url`.
85
+ * @description For the few endpoints that live outside the module's base path. The base URL
86
+ * used to be swapped on the module itself for the duration of the call; two calls in flight
87
+ * at once (`Promise.all`) then sent one of them to the other base path, and the second
88
+ * `finally` restored the swapped URL — every later call of the instance went there too.
89
+ */
90
+ protected _withBaseUrl(url: string): this;
39
91
  /**
40
92
  * Prepares a caller value (a marker) to be one segment of a request path.
41
93
  * @param {string} value - The value to put into the path.
@@ -47,6 +99,15 @@ export default abstract class AsyncModules extends SyncModules {
47
99
  * API gets a marker it rejects as invalid rather than another route.
48
100
  */
49
101
  protected _pathSegment(value: string): string;
102
+ /**
103
+ * Prepares a caller path (a page URL) for a request path, keeping its `/`.
104
+ * @param {string} value - The path to put into the request path.
105
+ * @returns {string} Each `/`-separated part encoded by `_pathSegment`.
106
+ * @description A page URL may hold `/`, so it cannot be one segment; each part is
107
+ * encoded instead. `getProductsByPageUrl('../../all')` resolved to
108
+ * `POST /products/all` — the whole catalogue instead of one page.
109
+ */
110
+ protected _pathSegments(value: string): string;
50
111
  /**
51
112
  * Performs an HTTP GET request.
52
113
  * @param {string} path - The path to append to the base URL.