pryv 3.7.0 → 3.7.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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/Service.js +12 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pryv",
3
- "version": "3.7.0",
3
+ "version": "3.7.1",
4
4
  "description": "Pryv JavaScript library",
5
5
  "keywords": [
6
6
  "Pryv",
package/src/Service.js CHANGED
@@ -285,6 +285,12 @@ class Service {
285
285
  * Resolve an email address to a username on this service.
286
286
  * One round-trip via `GET <register>/<email>/uid`.
287
287
  *
288
+ * On multi-core services where the platform stores identifiers hashed,
289
+ * the queried node may not host the user and answers `307` with the
290
+ * home node's URL in `{ server }`. `fetch` follows the redirect
291
+ * transparently; for HTTP clients that do not auto-follow, this method
292
+ * also follows the `{ server }` hint once explicitly.
293
+ *
288
294
  * @param {string} email - The email to look up
289
295
  * @returns {Promise<string|null>} The username, or `null` if unknown
290
296
  * @throws {PryvError} on network errors or non-404 API errors
@@ -292,7 +298,12 @@ class Service {
292
298
  async userIdForEmail (email) {
293
299
  const serviceInfo = await this.info();
294
300
  const url = serviceInfo.register + encodeURIComponent(email) + '/uid';
295
- const { response, body } = await utils.fetchGet(url);
301
+ let { response, body } = await utils.fetchGet(url);
302
+ if (response.status === 307 && body && body.server) {
303
+ const home = body.server.endsWith('/') ? body.server : body.server + '/';
304
+ const homeUrl = home + 'reg/' + encodeURIComponent(email) + '/uid';
305
+ ({ response, body } = await utils.fetchGet(homeUrl));
306
+ }
296
307
  if (response.ok) return (body && (body.uid || body.username)) || null;
297
308
  if (response.status === 404) return null;
298
309
  throw PryvError.fromApiResponse(response, body);