pryv 2.4.6 → 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/README.md +1 -1
- package/package.json +5 -4
- 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 +173 -120
- package/src/Service.js +44 -42
- package/src/ServiceAssets.js +17 -11
- package/src/globals.d.ts +76 -0
- package/src/index.d.ts +168 -40
- 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 +9 -34
- 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
|
|
|
@@ -129,8 +128,9 @@ describe('Connection', () => {
|
|
|
129
128
|
conn.options.chunkSize = 2;
|
|
130
129
|
|
|
131
130
|
let resultsReceivedCount = 0;
|
|
132
|
-
function oneMoreResult (res) {
|
|
131
|
+
function oneMoreResult (res, apiCall) {
|
|
133
132
|
expect(res.events).to.exist;
|
|
133
|
+
expect(apiCall.method).to.equal('events.get');
|
|
134
134
|
resultsReceivedCount++;
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -381,45 +381,20 @@ describe('Connection', () => {
|
|
|
381
381
|
|
|
382
382
|
if (typeof window === 'undefined') {
|
|
383
383
|
describe('Browser mock', function () {
|
|
384
|
-
const isNotAvailable = {
|
|
385
|
-
URL: global.URL == null,
|
|
386
|
-
URLSearchParams: global.URLSearchParams == null,
|
|
387
|
-
fetch: global.fetch == null
|
|
388
|
-
};
|
|
389
384
|
beforeEach(function () {
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
global.
|
|
393
|
-
global.
|
|
394
|
-
global.location = browser.location;
|
|
395
|
-
function fetch (...args) {
|
|
396
|
-
return browser.fetch(...args);
|
|
397
|
-
}
|
|
398
|
-
if (isNotAvailable.fetch) global.fetch = fetch;
|
|
399
|
-
if (isNotAvailable.URL) global.URL = URL;
|
|
400
|
-
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;
|
|
401
389
|
});
|
|
402
390
|
|
|
403
391
|
afterEach(function () {
|
|
404
392
|
delete global.document;
|
|
405
393
|
delete global.window;
|
|
406
394
|
delete global.location;
|
|
407
|
-
if (isNotAvailable.fetch) delete global.fetch;
|
|
408
|
-
if (isNotAvailable.URL) delete global.URL;
|
|
409
|
-
if (isNotAvailable.URLSearchParams) delete global.URLSearchParams;
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
it(' without fetch', async () => {
|
|
413
|
-
delete global.fetch;
|
|
414
|
-
const queryParams = { fromTime: 0, toTime: now, limit: 10000 };
|
|
415
|
-
let eventsCount = 0;
|
|
416
|
-
function forEachEvent (event) { eventsCount++; }
|
|
417
|
-
const res = await conn.getEventsStreamed(queryParams, forEachEvent);
|
|
418
|
-
expect(eventsCount).to.equal(res.eventsCount);
|
|
419
395
|
});
|
|
420
396
|
|
|
421
|
-
|
|
422
|
-
xit(' with fetch', async () => {
|
|
397
|
+
it(' with fetch', async () => {
|
|
423
398
|
const queryParams = { fromTime: 0, toTime: now, limit: 10000 };
|
|
424
399
|
let eventsCount = 0;
|
|
425
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