pryv 2.4.7 → 3.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/package.json +4 -3
- package/src/Auth/AuthController.js +46 -29
- package/src/Auth/index.js +3 -3
- package/src/Browser/CookieUtils.js +8 -5
- package/src/Browser/LoginButton.js +7 -4
- package/src/Connection.js +171 -119
- package/src/Service.js +44 -42
- package/src/ServiceAssets.js +17 -11
- package/src/globals.d.ts +76 -0
- package/src/index.d.ts +167 -39
- package/src/index.js +3 -1
- package/src/lib/PryvError.js +30 -0
- package/src/lib/{browser-getEventStreamed.js → getEventStreamed.js} +2 -7
- package/src/lib/json-parser.js +1 -2
- package/src/utils.js +68 -7
- package/test/Browser.AuthController.test.js +10 -10
- package/test/Browser.test.js +10 -10
- package/test/Connection.test.js +7 -33
- package/test/Service.test.js +6 -8
- package/test/ServiceAssets.test.js +8 -9
- package/test/utils.test.js +0 -1
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* @license
|
|
3
3
|
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
4
|
*/
|
|
5
|
-
/* global describe, it, before, after, expect, testData,
|
|
6
|
-
/* eslint-disable no-unused-expressions */
|
|
5
|
+
/* global describe, it, before, after, expect, testData, JSDOM */
|
|
7
6
|
|
|
8
7
|
const utils = require('../src/utils.js');
|
|
9
8
|
const Service = require('../src/Service');
|
|
@@ -13,20 +12,21 @@ describe('Browser.LoginButton', function () {
|
|
|
13
12
|
this.timeout(15000);
|
|
14
13
|
|
|
15
14
|
let auth;
|
|
16
|
-
let
|
|
15
|
+
let cleanupDom = false;
|
|
17
16
|
before(async function () {
|
|
18
17
|
if (typeof document !== 'undefined') return; // in browser
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
global.
|
|
24
|
-
global.
|
|
18
|
+
cleanupDom = true;
|
|
19
|
+
const dom = new JSDOM('<!DOCTYPE html>', {
|
|
20
|
+
url: 'http://localhost/?pryvServiceInfoUrl=https://zou.zou/service/info'
|
|
21
|
+
});
|
|
22
|
+
global.document = dom.window.document;
|
|
23
|
+
global.window = dom.window;
|
|
24
|
+
global.location = dom.window.location;
|
|
25
25
|
global.navigator = { userAgent: 'Safari' };
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
after(async function () {
|
|
29
|
-
if (!
|
|
29
|
+
if (!cleanupDom) return; // in browser
|
|
30
30
|
delete global.document;
|
|
31
31
|
delete global.window;
|
|
32
32
|
delete global.location;
|
package/test/Browser.test.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* @license
|
|
3
3
|
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
4
|
*/
|
|
5
|
-
/* global describe, it, before, after, expect,
|
|
6
|
-
/* eslint-disable no-unused-expressions */
|
|
5
|
+
/* global describe, it, before, after, expect, JSDOM, pryv, testData */
|
|
7
6
|
|
|
8
7
|
function genSettings () {
|
|
9
8
|
function defaultStateChange (state) {
|
|
@@ -26,21 +25,22 @@ describe('Browser', function () {
|
|
|
26
25
|
await testData.prepare();
|
|
27
26
|
});
|
|
28
27
|
|
|
29
|
-
let
|
|
28
|
+
let cleanupDom = false;
|
|
30
29
|
|
|
31
30
|
before(async () => {
|
|
32
31
|
if (typeof document !== 'undefined') return; // in browser
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
global.
|
|
38
|
-
global.
|
|
32
|
+
cleanupDom = true;
|
|
33
|
+
const dom = new JSDOM('<!DOCTYPE html>', {
|
|
34
|
+
url: 'http://localhost/?pryvServiceInfoUrl=https://zou.zou/service/info'
|
|
35
|
+
});
|
|
36
|
+
global.document = dom.window.document;
|
|
37
|
+
global.window = dom.window;
|
|
38
|
+
global.location = dom.window.location;
|
|
39
39
|
global.navigator = { userAgent: 'Safari' };
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
after(async () => {
|
|
43
|
-
if (!
|
|
43
|
+
if (!cleanupDom) return; // in browser
|
|
44
44
|
delete global.document;
|
|
45
45
|
delete global.window;
|
|
46
46
|
delete global.location;
|
package/test/Connection.test.js
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* @license
|
|
3
3
|
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
4
|
*/
|
|
5
|
-
/* global describe, it,
|
|
6
|
-
/* eslint-disable no-unused-expressions */
|
|
5
|
+
/* global describe, it, before, after, beforeEach, afterEach, expect, JSDOM, pryv, Blob, FormData */
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
// URL and URLSearchParams are native in Node.js and browsers
|
|
9
8
|
const cuid = require('cuid');
|
|
10
9
|
const testData = require('../../../test/test-data');
|
|
11
10
|
|
|
@@ -382,45 +381,20 @@ describe('Connection', () => {
|
|
|
382
381
|
|
|
383
382
|
if (typeof window === 'undefined') {
|
|
384
383
|
describe('Browser mock', function () {
|
|
385
|
-
const isNotAvailable = {
|
|
386
|
-
URL: global.URL == null,
|
|
387
|
-
URLSearchParams: global.URLSearchParams == null,
|
|
388
|
-
fetch: global.fetch == null
|
|
389
|
-
};
|
|
390
384
|
beforeEach(function () {
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
global.
|
|
394
|
-
global.
|
|
395
|
-
global.location = browser.location;
|
|
396
|
-
function fetch (...args) {
|
|
397
|
-
return browser.fetch(...args);
|
|
398
|
-
}
|
|
399
|
-
if (isNotAvailable.fetch) global.fetch = fetch;
|
|
400
|
-
if (isNotAvailable.URL) global.URL = URL;
|
|
401
|
-
if (isNotAvailable.URLSearchParams) global.URLSearchParams = URLSearchParams;
|
|
385
|
+
const dom = new JSDOM('<!DOCTYPE html>', { url: 'http://localhost/' });
|
|
386
|
+
global.document = dom.window.document;
|
|
387
|
+
global.window = dom.window;
|
|
388
|
+
global.location = dom.window.location;
|
|
402
389
|
});
|
|
403
390
|
|
|
404
391
|
afterEach(function () {
|
|
405
392
|
delete global.document;
|
|
406
393
|
delete global.window;
|
|
407
394
|
delete global.location;
|
|
408
|
-
if (isNotAvailable.fetch) delete global.fetch;
|
|
409
|
-
if (isNotAvailable.URL) delete global.URL;
|
|
410
|
-
if (isNotAvailable.URLSearchParams) delete global.URLSearchParams;
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
it(' without fetch', async () => {
|
|
414
|
-
delete global.fetch;
|
|
415
|
-
const queryParams = { fromTime: 0, toTime: now, limit: 10000 };
|
|
416
|
-
let eventsCount = 0;
|
|
417
|
-
function forEachEvent (event) { eventsCount++; }
|
|
418
|
-
const res = await conn.getEventsStreamed(queryParams, forEachEvent);
|
|
419
|
-
expect(eventsCount).to.equal(res.eventsCount);
|
|
420
395
|
});
|
|
421
396
|
|
|
422
|
-
|
|
423
|
-
xit(' with fetch', async () => {
|
|
397
|
+
it(' with fetch', async () => {
|
|
424
398
|
const queryParams = { fromTime: 0, toTime: now, limit: 10000 };
|
|
425
399
|
let eventsCount = 0;
|
|
426
400
|
function forEachEvent (event) { eventsCount++; }
|
package/test/Service.test.js
CHANGED
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
4
|
*/
|
|
5
5
|
/* global describe, it, before, expect, pryv, testData */
|
|
6
|
-
/* eslint-disable no-unused-expressions */
|
|
7
|
-
|
|
8
|
-
const isNode = (typeof window === 'undefined');
|
|
9
6
|
|
|
10
7
|
describe('Service', function () {
|
|
11
8
|
before(async function () {
|
|
@@ -81,12 +78,13 @@ describe('Service', function () {
|
|
|
81
78
|
try {
|
|
82
79
|
await pryvService.login('wrong-username', 'bobby', 'jslib-test');
|
|
83
80
|
} catch (error) {
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
|
|
81
|
+
const isDnsLess = await pryvService.isDnsLess();
|
|
82
|
+
if (isDnsLess) {
|
|
83
|
+
expect(error.message).to.include('Unknown user');
|
|
84
|
+
} else {
|
|
85
|
+
// fetch throws 'fetch failed'
|
|
86
|
+
expect(error.message).to.match(/Load failed|fetch failed|getaddrinfo ENOTFOUND|Request has been terminated/);
|
|
87
87
|
}
|
|
88
|
-
const receivedMessage = error.message.slice(0, errorMessage.length);
|
|
89
|
-
expect(receivedMessage).to.be.equal(errorMessage);
|
|
90
88
|
return;
|
|
91
89
|
}
|
|
92
90
|
throw new Error('Should fail');
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* @license
|
|
3
3
|
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
4
|
*/
|
|
5
|
-
/* global describe, it, before, after, expect,
|
|
5
|
+
/* global describe, it, before, after, expect, JSDOM, pryv, testData */
|
|
6
6
|
|
|
7
7
|
describe('ServiceAssets', function () {
|
|
8
|
-
let
|
|
8
|
+
let cleanupDom = false;
|
|
9
9
|
|
|
10
10
|
before(async function () {
|
|
11
11
|
this.timeout(15000);
|
|
@@ -14,16 +14,15 @@ describe('ServiceAssets', function () {
|
|
|
14
14
|
|
|
15
15
|
before(async () => {
|
|
16
16
|
if (typeof document !== 'undefined') return; // in browser
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
global.
|
|
21
|
-
global.
|
|
22
|
-
global.location = browser.location;
|
|
17
|
+
cleanupDom = true;
|
|
18
|
+
const dom = new JSDOM('<!DOCTYPE html>', { url: 'http://localhost/' });
|
|
19
|
+
global.document = dom.window.document;
|
|
20
|
+
global.window = dom.window;
|
|
21
|
+
global.location = dom.window.location;
|
|
23
22
|
});
|
|
24
23
|
|
|
25
24
|
after(async () => {
|
|
26
|
-
if (!
|
|
25
|
+
if (!cleanupDom) return; // in browser
|
|
27
26
|
delete global.document;
|
|
28
27
|
delete global.window;
|
|
29
28
|
delete global.location;
|
package/test/utils.test.js
CHANGED