pryv 2.3.6 → 2.3.8
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 +18 -2
- package/package.json +1 -1
- package/src/Service.js +19 -0
- package/src/ServiceAssets.js +2 -2
- package/test/Connection.test.js +12 -3
- package/test/Service.test.js +15 -1
- package/test/browser-index.html +1 -1
package/README.md
CHANGED
|
@@ -648,11 +648,11 @@ There is a possibility that you would like to register the user in another page.
|
|
|
648
648
|
|
|
649
649
|
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:
|
|
650
650
|
|
|
651
|
-
1. With [
|
|
651
|
+
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):
|
|
652
652
|
```
|
|
653
653
|
just serve
|
|
654
654
|
```
|
|
655
|
-
then open the desired example page (e.g. [https://l.
|
|
655
|
+
then open the desired example page (e.g. [https://l.backloop.dev:9443/examples/auth.html](https://l.backloop.dev:9443/examples/auth.html)
|
|
656
656
|
2. As a simple HTML file, passing service information as JSON to avoid CORS issues
|
|
657
657
|
|
|
658
658
|
|
|
@@ -676,6 +676,8 @@ The project is structured as a monorepo with components (a.k.a. workspaces in NP
|
|
|
676
676
|
- `pryv-socket.io`: Socket.IO add-on
|
|
677
677
|
- `pryv-monitor`: Monitor add-on
|
|
678
678
|
|
|
679
|
+
|
|
680
|
+
|
|
679
681
|
The code follows the [Semi-Standard](https://github.com/standard/semistandard) style.
|
|
680
682
|
|
|
681
683
|
### Building for the browser
|
|
@@ -696,6 +698,20 @@ just test <component> [...params]
|
|
|
696
698
|
- Extra parameters at the end are passed on to [Mocha](https://mochajs.org/) (default settings are defined in `.mocharc.js` files)
|
|
697
699
|
- Replace `test` with `test-debug`, `test-cover` for common presets
|
|
698
700
|
|
|
701
|
+
By default, tests are run against [Pryv Lab](https://www.pryv.com/pryvlab/) with service information URL `https://reg.pryv.me/service/info`.
|
|
702
|
+
|
|
703
|
+
To run the tests against another Pryv.io platform, set the `TEST_PRYVLIB_SERVICEINFO_URL` environment variable; for example:
|
|
704
|
+
|
|
705
|
+
```bash
|
|
706
|
+
TEST_PRYVLIB_SERVICEINFO_URL="https://reg.${DOMAIN}/service/info" just test all
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
To run the tests against _in-development_ API server components (e.g. open-source or Entreprise), set `TEST_PRYVLIB_DNSLESS_URL`; for example:
|
|
710
|
+
|
|
711
|
+
```bash
|
|
712
|
+
TEST_PRYVLIB_DNSLESS_URL="http://l.backloop.dev:3000/ just test all
|
|
713
|
+
```
|
|
714
|
+
|
|
699
715
|
#### Browser
|
|
700
716
|
|
|
701
717
|
Assuming browser files have been built (see above):
|
package/package.json
CHANGED
package/src/Service.js
CHANGED
|
@@ -68,6 +68,25 @@ class Service {
|
|
|
68
68
|
return this._serviceInfo;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Check if a service supports High Frequency Data Sets
|
|
73
|
+
* @return true if yes
|
|
74
|
+
*/
|
|
75
|
+
async supportsHF () {
|
|
76
|
+
const infos = await this.info();
|
|
77
|
+
return (infos.features == null || infos.features.noHF !== true);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Check if a service has username in the hostname or in the path of the api
|
|
82
|
+
* @return true if the service does not rely on DNS to find a host related to a username
|
|
83
|
+
*/
|
|
84
|
+
async isDnsLess () {
|
|
85
|
+
const infos = await this.info();
|
|
86
|
+
const hostname = infos.api.split('/')[2];
|
|
87
|
+
return !hostname.includes('{username}');
|
|
88
|
+
}
|
|
89
|
+
|
|
71
90
|
/**
|
|
72
91
|
* @private
|
|
73
92
|
* @param {ServiceInfo} serviceInfo
|
package/src/ServiceAssets.js
CHANGED
|
@@ -36,7 +36,7 @@ class ServiceAssets {
|
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* get a value from path separated by `:`
|
|
39
|
-
*
|
|
39
|
+
* example of key `lib-js:buttonSignIn`
|
|
40
40
|
* @param {string} [keyPath] if null, will return the all assets
|
|
41
41
|
*/
|
|
42
42
|
get (keyPath) {
|
|
@@ -53,7 +53,7 @@ class ServiceAssets {
|
|
|
53
53
|
/**
|
|
54
54
|
* get an Url from path separated by `:`
|
|
55
55
|
* identical to doing assets.relativeURL(assets.get(keyPath))
|
|
56
|
-
*
|
|
56
|
+
* example of key `lib-js:buttonSignIn`
|
|
57
57
|
* @param {string} [keyPath] if null, will return the all assets
|
|
58
58
|
*/
|
|
59
59
|
getUrl (keyPath) {
|
package/test/Connection.test.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* @license
|
|
3
3
|
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
4
|
*/
|
|
5
|
-
/* global describe, it, xit, before, after, beforeEach, afterEach, expect, Browser, pryv,
|
|
5
|
+
/* global describe, it, xit, before, after, beforeEach, afterEach, expect, Browser, pryv, Blob, FormData */
|
|
6
6
|
/* eslint-disable no-unused-expressions */
|
|
7
7
|
|
|
8
8
|
const { URL, URLSearchParams } = require('universal-url');
|
|
9
9
|
const cuid = require('cuid');
|
|
10
|
+
const testData = require('../../../test/test-data');
|
|
10
11
|
|
|
11
12
|
let conn = null;
|
|
12
13
|
|
|
@@ -261,7 +262,13 @@ describe('Connection', () => {
|
|
|
261
262
|
});
|
|
262
263
|
});
|
|
263
264
|
|
|
264
|
-
describe('HF events', ()
|
|
265
|
+
describe('HF events', async function () {
|
|
266
|
+
before(async function () {
|
|
267
|
+
if (!await conn.service.supportsHF()) {
|
|
268
|
+
this.skip();
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
265
272
|
it('Add data points to HF event', async () => {
|
|
266
273
|
const res = await conn.api([{
|
|
267
274
|
method: 'events.create',
|
|
@@ -302,8 +309,10 @@ describe('Connection', () => {
|
|
|
302
309
|
|
|
303
310
|
describe('API', () => {
|
|
304
311
|
it('endpoint property', async () => {
|
|
312
|
+
const [protocol, hostPath] = testData.serviceInfo.api.split('://');
|
|
313
|
+
const challenge = protocol + '://' + conn.token + '@' + hostPath.replace('{username}', testData.username);
|
|
305
314
|
const apiEndpoint = conn.apiEndpoint;
|
|
306
|
-
expect(apiEndpoint
|
|
315
|
+
expect(apiEndpoint).to.equal(challenge);
|
|
307
316
|
});
|
|
308
317
|
});
|
|
309
318
|
|
package/test/Service.test.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
/* global describe, it, before, expect, pryv, testData */
|
|
6
6
|
/* eslint-disable no-unused-expressions */
|
|
7
7
|
|
|
8
|
+
const isNode = (typeof window === 'undefined');
|
|
9
|
+
|
|
8
10
|
describe('Service', function () {
|
|
9
11
|
before(async function () {
|
|
10
12
|
this.timeout(5000);
|
|
@@ -75,7 +77,19 @@ describe('Service', function () {
|
|
|
75
77
|
it('login() failed on wrong username', async function () {
|
|
76
78
|
this.timeout(5000);
|
|
77
79
|
const pryvService = new pryv.Service(testData.serviceInfoUrl);
|
|
78
|
-
|
|
80
|
+
// check if username is in path or domain
|
|
81
|
+
try {
|
|
82
|
+
await pryvService.login('wrong-username', 'bobby', 'jslib-test');
|
|
83
|
+
} catch (error) {
|
|
84
|
+
let errorMessage = isNode ? 'getaddrinfo ENOTFOUND wrong' : 'Request has been terminated';
|
|
85
|
+
if (await pryvService.isDnsLess()) {
|
|
86
|
+
errorMessage = 'Unknown user "wrong-username"';
|
|
87
|
+
}
|
|
88
|
+
const receivedMessage = error.message.slice(0, errorMessage.length);
|
|
89
|
+
expect(receivedMessage).to.be.equal(errorMessage);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
throw new Error('Should fail');
|
|
79
93
|
});
|
|
80
94
|
});
|
|
81
95
|
});
|
package/test/browser-index.html
CHANGED