pryv 3.7.1 → 3.8.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/README.md CHANGED
@@ -651,7 +651,7 @@ There is a possibility that you would like to register the user in another page.
651
651
 
652
652
  You can find HTML examples in the [`./examples`](https://github.com/pryv/lib-js/blob/master/examples) directory. You can run them in two ways:
653
653
 
654
- 1. With [backloop.dev](https://github.com/pryv/backloop.dev), which allows to run local code with a valid SSL certificate (you must have run `just build` beforehand):
654
+ 1. With [backloop.dev](https://backloop.dev), which allows to run local code with a valid SSL certificate (you must have run `just build` beforehand):
655
655
  ```
656
656
  just serve
657
657
  ```
@@ -702,7 +702,7 @@ just test <component> [...params]
702
702
  - Extra parameters at the end are passed on to [Mocha](https://mochajs.org/) (default settings are defined in `.mocharc.js` files)
703
703
  - Replace `test` with `test-debug`, `test-cover` for common presets
704
704
 
705
- By default, tests are run against [Pryv Lab](https://www.pryv.com/pryvlab/) with service information URL `https://reg.pryv.me/service/info`.
705
+ By default, tests are run against Pryv Lab with service information URL `https://reg.pryv.me/service/info`.
706
706
 
707
707
  To run the tests against another Pryv.io platform, set the `TEST_PRYVLIB_SERVICEINFO_URL` environment variable; for example:
708
708
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pryv",
3
- "version": "3.7.1",
3
+ "version": "3.8.0",
4
4
  "description": "Pryv JavaScript library",
5
5
  "keywords": [
6
6
  "Pryv",
@@ -15,7 +15,7 @@
15
15
  "url": "git://github.com/pryv/lib-js.git"
16
16
  },
17
17
  "license": "BSD-3-Clause",
18
- "author": "Pryv S.A. <info@pryv.com> (https://pryv.com)",
18
+ "author": "Pryv <info@pryv.com> (https://pryv.com)",
19
19
  "main": "src/index.js",
20
20
  "types": "src/index.d.ts",
21
21
  "dependencies": {},
@@ -112,7 +112,8 @@ class LoginButton {
112
112
  // this step should be applied only for the browser
113
113
  if (!utils.isBrowser()) return;
114
114
 
115
- // 3. Check if there is a prYvkey as result of "out of page login"
115
+ // 3. Check if there is a pryvKey / pryvPoll (or legacy prYvkey /
116
+ // prYvpoll) as result of "out of page login"
116
117
  const url = window.location.href;
117
118
  const pollUrl = retrievePollUrl(url);
118
119
  if (pollUrl !== null) {
@@ -126,21 +127,27 @@ class LoginButton {
126
127
  error: e
127
128
  };
128
129
  }
129
- // The prYv* params are one-shot; leaving them in the visible URL
130
- // puts stale auth state into bookmarks / copied links.
130
+ // These params are one-shot; leaving them in the visible URL puts
131
+ // stale auth state into bookmarks / copied links.
131
132
  if (window.history && typeof window.history.replaceState === 'function') {
132
133
  window.history.replaceState(null, '', utils.cleanURLFromPrYvParams(url));
133
134
  }
134
135
  }
135
136
 
136
137
  function retrievePollUrl (url) {
138
+ // Modern lowercase form (pryvKey / pryvPoll) is preferred; the
139
+ // capital-Y form (prYvkey / prYvpoll) is accepted for back-compat
140
+ // with apps emitting the legacy URL contract — see
141
+ // [DEPRECATED] notes on cleanURLFromPrYvParams.
137
142
  const params = utils.getQueryParamsFromURL(url);
138
143
  let pollUrl = null;
139
- if (params.prYvkey) { // deprecated method - To be removed
140
- pollUrl = authController.serviceInfo.access + params.prYvkey;
144
+ const key = params.pryvKey || params.prYvkey;
145
+ if (key) {
146
+ pollUrl = authController.serviceInfo.access + key;
141
147
  }
142
- if (params.prYvpoll) {
143
- pollUrl = params.prYvpoll;
148
+ const poll = params.pryvPoll || params.prYvpoll;
149
+ if (poll) {
150
+ pollUrl = poll;
144
151
  }
145
152
  return pollUrl;
146
153
  }
package/src/index.d.ts CHANGED
@@ -1132,15 +1132,11 @@ declare module 'pryv' {
1132
1132
  setupAuth: SetupAuth;
1133
1133
  serviceInfoFromUrl: getServiceInfoFromURL;
1134
1134
  };
1135
- utils: {
1136
- isBrowser(): boolean;
1137
- extractTokenAndAPIEndpoint(apiEndpoint: string): TokenAndAPIEndpoint;
1138
- buildAPIEndpoint(tokenAndAPI: TokenAndAPIEndpoint): string;
1139
- decomposeAPIEndpoint(apiEndpoint: string, serviceInfoApi: string): DecomposedAPIEndpoint;
1140
- browserIsMobileOrTablet(navigator?: string | Navigator): boolean;
1141
- cleanURLFromPrYvParams(url: string): string;
1142
- getQueryParamsFromURL(url: string): KeyValue;
1143
- };
1135
+ // Reference the named export's type — a duplicated inline shape here
1136
+ // drifted from it once already (the deprecated aliases were missing),
1137
+ // which broke structural typing for add-ons taking the default export
1138
+ // (e.g. @pryv/socket.io's PryvLibrary).
1139
+ utils: typeof utils;
1144
1140
  PryvError: typeof PryvError;
1145
1141
  MfaRequiredError: typeof MfaRequiredError;
1146
1142
  ERRORS: typeof ERRORS;
package/src/utils.js CHANGED
@@ -215,14 +215,29 @@ const utils = module.exports = {
215
215
  },
216
216
 
217
217
  /**
218
- * Remove Pryv-specific query parameters from URL
218
+ * Remove the one-shot Pryv auth-completion query parameters from a URL,
219
+ * keeping any long-lived `pryv*` params intact.
220
+ *
221
+ * Both casings are stripped:
222
+ * - Modern lowercase: `pryvKey`, `pryvPoll`
223
+ * - Legacy capital-Y: `prYv<anything>` (anything starting with `prYv`)
224
+ *
225
+ * `pryv*` params that are NOT in the modern allowlist (e.g.
226
+ * `pryvServiceInfoUrl`, `pryvApiEndpoint`) are intentionally preserved —
227
+ * they are not one-shot.
228
+ *
219
229
  * @memberof pryv.utils
220
230
  * @param {string} url - URL to clean
221
- * @returns {string} URL without prYv* parameters
231
+ * @returns {string} URL without the one-shot auth-completion params
222
232
  */
223
233
  cleanURLFromPrYvParams: function (url) {
224
- const PRYV_REGEXP = /[?#&]+prYv([^=&]+)=([^&]*)/g;
225
- return url.replace(PRYV_REGEXP, '');
234
+ // Legacy form: kept for back-compat with apps still emitting
235
+ // `prYv<anything>=...` (notably app-web-auth3's close_or_redirect).
236
+ const LEGACY = /[?#&]+prYv([^=&]+)=([^&]*)/g;
237
+ // Modern form: an explicit allowlist of one-shot params so we never
238
+ // wipe long-lived camelCase `pryv*` params by accident.
239
+ const MODERN = /[?#&]+(pryvKey|pryvPoll)=([^&]*)/g;
240
+ return url.replace(LEGACY, '').replace(MODERN, '');
226
241
  },
227
242
 
228
243
  /**
@@ -104,6 +104,36 @@ describe('[UTLX] utils', function () {
104
104
  expect(err.name).to.equal('StaleAccessIdError');
105
105
  });
106
106
 
107
+ describe('[UTLN] cleanURLFromPrYvParams', function () {
108
+ it('[UTLNA] strips legacy capital-Y prYv* params', function () {
109
+ const out = pryv.utils.cleanURLFromPrYvParams(
110
+ 'http://example.com/page?keep=1&prYvkey=abc&prYvpoll=http%3A%2F%2Fpoll&prYvstatus=ACCEPTED'
111
+ );
112
+ expect(out).to.equal('http://example.com/page?keep=1');
113
+ });
114
+ it('[UTLNB] strips modern lowercase one-shot params (pryvKey, pryvPoll)', function () {
115
+ const out = pryv.utils.cleanURLFromPrYvParams(
116
+ 'http://example.com/page?keep=1&pryvKey=abc&pryvPoll=http%3A%2F%2Fpoll'
117
+ );
118
+ expect(out).to.equal('http://example.com/page?keep=1');
119
+ });
120
+ it('[UTLNC] PRESERVES long-lived modern params (pryvServiceInfoUrl, pryvApiEndpoint)', function () {
121
+ const out = pryv.utils.cleanURLFromPrYvParams(
122
+ 'http://example.com/page?pryvServiceInfoUrl=https%3A%2F%2Freg.pryv.me%2Fservice%2Finfo&pryvApiEndpoint=https%3A%2F%2Fuser.pryv.me%2F&pryvKey=abc'
123
+ );
124
+ // pryvKey is stripped (one-shot), the other two stay (long-lived).
125
+ expect(out).to.contain('pryvServiceInfoUrl=');
126
+ expect(out).to.contain('pryvApiEndpoint=');
127
+ expect(out).not.to.contain('pryvKey=');
128
+ });
129
+ it('[UTLND] strips both forms in a single URL', function () {
130
+ const out = pryv.utils.cleanURLFromPrYvParams(
131
+ 'http://example.com/page?keep=1&prYvkey=legacy&pryvKey=modern&prYvpoll=oldpoll&pryvPoll=newpoll'
132
+ );
133
+ expect(out).to.equal('http://example.com/page?keep=1');
134
+ });
135
+ });
136
+
107
137
  describe('[UTLM] decomposeAPIEndpoint', function () {
108
138
  it('[UTLMA] subdomain template — host strips the {username}. prefix', function () {
109
139
  const r = pryv.utils.decomposeAPIEndpoint(