pryv 2.1.9 → 2.3.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.
- package/README.md +300 -304
- package/package.json +12 -45
- package/src/Auth/AuthController.js +43 -50
- package/src/Auth/AuthStates.js +12 -12
- package/src/Auth/LoginMessages.js +17 -14
- package/src/Auth/index.js +18 -15
- package/src/Browser/CookieUtils.js +37 -27
- package/src/Browser/LoginButton.js +42 -37
- package/src/Browser/index.js +16 -42
- package/src/Connection.js +102 -95
- package/src/Service.js +47 -45
- package/src/ServiceAssets.js +42 -34
- package/src/browser-index-bundle.js +8 -0
- package/src/browser-index.js +7 -0
- package/src/index.d.ts +833 -0
- package/src/index.js +20 -3
- package/src/lib/browser-getEventStreamed.js +21 -19
- package/src/lib/json-parser.js +23 -24
- package/src/utils.js +55 -43
- package/test/Browser.AuthController.test.js +19 -21
- package/test/Browser.test.js +23 -26
- package/test/Connection.test.js +135 -151
- package/test/Service.test.js +30 -44
- package/test/ServiceAssets.test.js +16 -22
- package/test/browser-index.html +26 -0
- package/test/utils.test.js +30 -35
- package/.jsdoc-conf.json +0 -29
- package/.mocharc.js +0 -13
- package/LICENSE.md +0 -27
- package/scripts/setup-environment-dev.sh +0 -28
- package/scripts/upload.sh +0 -15
- package/src/Pryv.js +0 -19
- package/src/index-socket.io-monitor.js +0 -4
- package/src/index.html +0 -17
- package/test/browser-index.js +0 -11
- package/test/browser-tests.html +0 -31
- package/test/helpers.js +0 -8
- package/test/load-test-account.js +0 -108
- package/test/test-data.js +0 -95
- package/web-demos/auth-with-redirection.html +0 -72
- package/web-demos/auth.html +0 -77
- package/web-demos/custom-login-button.html +0 -158
- package/web-demos/index.html +0 -186
- package/web-demos/service-info.json +0 -13
- package/web-demos/stream-examples.html +0 -80
- package/webpack.config.js +0 -83
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
|
+
*/
|
|
5
|
+
/* global describe, it, before, after, expect, Browser, pryv, testData */
|
|
4
6
|
|
|
5
7
|
describe('ServiceAssets', function () {
|
|
6
8
|
let removeZombie = false;
|
|
@@ -9,7 +11,7 @@ describe('ServiceAssets', function () {
|
|
|
9
11
|
this.timeout(5000);
|
|
10
12
|
await testData.prepare();
|
|
11
13
|
});
|
|
12
|
-
|
|
14
|
+
|
|
13
15
|
before(async () => {
|
|
14
16
|
if (typeof document !== 'undefined') return; // in browser
|
|
15
17
|
removeZombie = true;
|
|
@@ -21,59 +23,51 @@ describe('ServiceAssets', function () {
|
|
|
21
23
|
});
|
|
22
24
|
|
|
23
25
|
after(async () => {
|
|
24
|
-
if (!
|
|
26
|
+
if (!removeZombie) return; // in browser
|
|
25
27
|
delete global.document;
|
|
26
|
-
delete global.window;
|
|
27
|
-
delete global.location;
|
|
28
|
+
delete global.window;
|
|
29
|
+
delete global.location;
|
|
28
30
|
});
|
|
29
31
|
|
|
30
32
|
it('relativeURL()', async () => {
|
|
31
|
-
|
|
32
|
-
const pryvService = new Pryv.Service(null, testData.serviceInfo);
|
|
33
|
+
const pryvService = new pryv.Service(null, testData.serviceInfo);
|
|
33
34
|
const assets = await pryvService.assets();
|
|
34
35
|
expect(assets.relativeURL('./toto')).to.eql(testData.serviceInfo.assets.definitions.replace('index.json', 'toto'));
|
|
35
|
-
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
it('setAllDefaults()', async () => {
|
|
39
|
-
const pryvService = new
|
|
39
|
+
const pryvService = new pryv.Service(null, testData.serviceInfo);
|
|
40
40
|
const assets = await pryvService.assets();
|
|
41
41
|
await assets.setAllDefaults();
|
|
42
|
-
|
|
43
42
|
});
|
|
44
43
|
|
|
45
44
|
it('Load all external elements', async () => {
|
|
46
|
-
const pryvService = new
|
|
45
|
+
const pryvService = new pryv.Service(null, testData.serviceInfo);
|
|
47
46
|
const assets = await pryvService.assets();
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
|
|
50
48
|
await assets.loginButtonLoadCSS();
|
|
51
49
|
await assets.loginButtonGetHTML();
|
|
52
50
|
await assets.loginButtonGetMessages();
|
|
53
|
-
|
|
54
51
|
});
|
|
55
52
|
|
|
56
53
|
it('.get() returns all assets', async () => {
|
|
57
|
-
const pryvService = new
|
|
54
|
+
const pryvService = new pryv.Service(null, testData.serviceInfo);
|
|
58
55
|
const assets = await pryvService.assets();
|
|
59
56
|
const allAssets = await assets.get();
|
|
60
57
|
expect(allAssets.favicon.default.url).to.eql('favicon.ico');
|
|
61
58
|
});
|
|
62
59
|
|
|
63
60
|
it('.get(keyPath) ', async () => {
|
|
64
|
-
const pryvService = new
|
|
61
|
+
const pryvService = new pryv.Service(null, testData.serviceInfo);
|
|
65
62
|
const assets = await pryvService.assets();
|
|
66
63
|
const faviconUrl = await assets.get('favicon:default:url');
|
|
67
64
|
expect(faviconUrl).to.eql('favicon.ico');
|
|
68
65
|
});
|
|
69
66
|
|
|
70
67
|
it('.getUrl(keyPath) ', async () => {
|
|
71
|
-
const pryvService = new
|
|
68
|
+
const pryvService = new pryv.Service(null, testData.serviceInfo);
|
|
72
69
|
const assets = await pryvService.assets();
|
|
73
70
|
const faviconUrl = await assets.getUrl('favicon:default:url');
|
|
74
71
|
expect(faviconUrl).to.eql(testData.serviceInfo.assets.definitions.replace('index.json', 'favicon.ico'));
|
|
75
72
|
});
|
|
76
|
-
|
|
77
73
|
});
|
|
78
|
-
|
|
79
|
-
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<title>Pryv JS lib browser tests</title>
|
|
5
|
+
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
|
|
6
|
+
</head>
|
|
7
|
+
|
|
8
|
+
<body>
|
|
9
|
+
<div id="mocha"></div>
|
|
10
|
+
<script src="https://unpkg.com/chai/chai.js"></script>
|
|
11
|
+
<script src="https://unpkg.com/mocha/mocha.js"></script>
|
|
12
|
+
|
|
13
|
+
<script class="mocha-init">
|
|
14
|
+
mocha.setup('bdd');
|
|
15
|
+
mocha.setup({ignoreLeaks: true});
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<!-- Files cf. webpack config -->
|
|
19
|
+
<script src="pryv.js"></script>
|
|
20
|
+
<script src="tests.js"></script>
|
|
21
|
+
|
|
22
|
+
<script>
|
|
23
|
+
mocha.run();
|
|
24
|
+
</script>
|
|
25
|
+
</body>
|
|
26
|
+
</html>
|
package/test/utils.test.js
CHANGED
|
@@ -1,68 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
|
+
*/
|
|
5
|
+
/* global describe, it, before, expect, pryv, testData */
|
|
6
|
+
/* eslint-disable no-unused-expressions */
|
|
6
7
|
|
|
7
8
|
describe('utils', function () {
|
|
8
|
-
|
|
9
9
|
before(async function () {
|
|
10
10
|
this.timeout(5000);
|
|
11
11
|
await testData.prepare();
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
it('
|
|
15
|
-
const tokenAndAPI =
|
|
16
|
-
.
|
|
17
|
-
testData.token.
|
|
18
|
-
|
|
19
|
-
(testData.apiEndpoint).
|
|
14
|
+
it('extractTokenAndAPIEndpoint', function (done) {
|
|
15
|
+
const tokenAndAPI = pryv.utils
|
|
16
|
+
.extractTokenAndAPIEndpoint(testData.apiEndpointWithToken);
|
|
17
|
+
expect(testData.token).to.equal(tokenAndAPI.token);
|
|
18
|
+
|
|
19
|
+
expect(testData.apiEndpoint).to.equal(tokenAndAPI.endpoint);
|
|
20
20
|
done();
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
it('
|
|
24
|
-
const tokenAndAPI =
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
it('extractTokenAndAPIEndpoint should work without token', function (done) {
|
|
24
|
+
const tokenAndAPI = pryv.utils
|
|
25
|
+
.extractTokenAndAPIEndpoint(testData.apiEndpoint);
|
|
26
|
+
|
|
27
|
+
expect(tokenAndAPI.token).to.not.exist;
|
|
28
28
|
|
|
29
|
-
(testData.apiEndpoint).
|
|
29
|
+
expect(testData.apiEndpoint).to.equal(tokenAndAPI.endpoint);
|
|
30
30
|
done();
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
it('
|
|
33
|
+
it('extractTokenAndAPIEndpoint should fail on invalid url', function (done) {
|
|
34
34
|
let error = null;
|
|
35
35
|
try {
|
|
36
|
-
|
|
37
|
-
.extractTokenAndApiEndpoint('blip');
|
|
36
|
+
pryv.utils.extractTokenAndAPIEndpoint('blip');
|
|
38
37
|
} catch (e) {
|
|
39
38
|
error = e;
|
|
40
|
-
|
|
41
39
|
return done();
|
|
42
40
|
}
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
expect(error).to.exist;
|
|
45
42
|
});
|
|
46
43
|
|
|
47
44
|
it('buildAPIEndpoint with token', function (done) {
|
|
48
|
-
const apiEndpoint =
|
|
49
|
-
.
|
|
50
|
-
token: testData.token,
|
|
51
|
-
endpoint: testData.apiEndpoint
|
|
52
|
-
|
|
45
|
+
const apiEndpoint = pryv.utils
|
|
46
|
+
.buildAPIEndpoint({
|
|
47
|
+
token: testData.token,
|
|
48
|
+
endpoint: testData.apiEndpoint
|
|
49
|
+
});
|
|
50
|
+
expect(apiEndpoint).to.equal(testData.apiEndpointWithToken);
|
|
53
51
|
done();
|
|
54
52
|
});
|
|
55
53
|
|
|
56
54
|
it('buildAPIEndpoint without token', function (done) {
|
|
57
|
-
const apiEndpoint =
|
|
58
|
-
.
|
|
55
|
+
const apiEndpoint = pryv.utils
|
|
56
|
+
.buildAPIEndpoint({
|
|
59
57
|
token: null,
|
|
60
58
|
endpoint: testData.apiEndpoint
|
|
61
59
|
});
|
|
62
|
-
apiEndpoint.
|
|
60
|
+
expect(apiEndpoint).to.equal(testData.apiEndpoint);
|
|
63
61
|
done();
|
|
64
62
|
});
|
|
65
|
-
|
|
66
63
|
});
|
|
67
|
-
|
|
68
|
-
|
package/.jsdoc-conf.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"plugins": [
|
|
3
|
-
"plugins/markdown"
|
|
4
|
-
],
|
|
5
|
-
"recurseDepth": 10,
|
|
6
|
-
"source": {
|
|
7
|
-
"include": ["./src"],
|
|
8
|
-
"includePattern": ".+\\.js(doc|x)?$",
|
|
9
|
-
"excludePattern": "(^|\\/|\\\\)_"
|
|
10
|
-
},
|
|
11
|
-
"sourceType": "module",
|
|
12
|
-
"tags": {
|
|
13
|
-
"allowUnknownTags": true,
|
|
14
|
-
"dictionaries": [
|
|
15
|
-
"jsdoc",
|
|
16
|
-
"closure"
|
|
17
|
-
]
|
|
18
|
-
},
|
|
19
|
-
"templates": {
|
|
20
|
-
"cleverLinks": false,
|
|
21
|
-
"monospaceLinks": false
|
|
22
|
-
},
|
|
23
|
-
"opts": {
|
|
24
|
-
"encoding": "utf8",
|
|
25
|
-
"destination": "./dist/docs",
|
|
26
|
-
"recurse": true,
|
|
27
|
-
"readme": "./README.md"
|
|
28
|
-
}
|
|
29
|
-
}
|
package/.mocharc.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
diff: true,
|
|
3
|
-
extension: ['js'],
|
|
4
|
-
opts: false,
|
|
5
|
-
package: './package.json',
|
|
6
|
-
reporter: 'spec',
|
|
7
|
-
slow: 75,
|
|
8
|
-
timeout: 2000,
|
|
9
|
-
require: 'test/helpers.js',
|
|
10
|
-
ui: 'bdd',
|
|
11
|
-
'watch-files': ['lib/**/*.js', 'test/**/*.js'],
|
|
12
|
-
'watch-ignore': ['lib/vendor']
|
|
13
|
-
};
|
package/LICENSE.md
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2020-2021, Pryv S.A.
|
|
2
|
-
All rights reserved.
|
|
3
|
-
|
|
4
|
-
Redistribution and use in source and binary forms, with or without modification,
|
|
5
|
-
are permitted provided that the following conditions are met:
|
|
6
|
-
|
|
7
|
-
- Redistributions of source code must retain the above copyright notice, this
|
|
8
|
-
list of conditions and the following disclaimer.
|
|
9
|
-
|
|
10
|
-
- Redistributions in binary form must reproduce the above copyright notice, this
|
|
11
|
-
list of conditions and the following disclaimer in the documentation and/or
|
|
12
|
-
other materials provided with the distribution.
|
|
13
|
-
|
|
14
|
-
- Neither the name of Pryv nor the names of its
|
|
15
|
-
contributors may be used to endorse or promote products derived from
|
|
16
|
-
this software without specific prior written permission.
|
|
17
|
-
|
|
18
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
19
|
-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
20
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
22
|
-
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
23
|
-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
24
|
-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
25
|
-
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
27
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
|
|
3
|
-
# working dir fix
|
|
4
|
-
scriptsFolder=$(cd $(dirname "$0"); pwd)
|
|
5
|
-
cd $scriptsFolder/..
|
|
6
|
-
|
|
7
|
-
# check for basic prerequisites
|
|
8
|
-
hash git 2>&- || { echo >&2 "I require git."; exit 1; }
|
|
9
|
-
hash npm 2>&- || { echo >&2 "I require Node and NPM."; exit 1; }
|
|
10
|
-
|
|
11
|
-
echo "
|
|
12
|
-
Installing Node modules if necessary...
|
|
13
|
-
"
|
|
14
|
-
npm install
|
|
15
|
-
|
|
16
|
-
distFolder=dist
|
|
17
|
-
if [ ! -d $distFolder ]
|
|
18
|
-
then
|
|
19
|
-
echo "
|
|
20
|
-
Setting up '$distFolder' folder for publishing to GitHub pages...
|
|
21
|
-
"
|
|
22
|
-
git clone -b gh-pages git@github.com:pryv/lib-js.git $distFolder
|
|
23
|
-
fi
|
|
24
|
-
|
|
25
|
-
echo "
|
|
26
|
-
|
|
27
|
-
OK!
|
|
28
|
-
"
|
package/scripts/upload.sh
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
|
|
3
|
-
set -e
|
|
4
|
-
|
|
5
|
-
# working dir fix
|
|
6
|
-
scriptsFolder=$(cd $(dirname "$0"); pwd)
|
|
7
|
-
cd $scriptsFolder/..
|
|
8
|
-
|
|
9
|
-
if [ $# -eq 0 ]
|
|
10
|
-
then
|
|
11
|
-
echo "No commit message was provided, please provide a message as argument for readability";
|
|
12
|
-
exit 1;
|
|
13
|
-
fi
|
|
14
|
-
|
|
15
|
-
cd dist && git add . && git add -u . && git commit -m "$1" && git push
|
package/src/Pryv.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Pryv library
|
|
4
|
-
* @version 1.0
|
|
5
|
-
* @exports Pryv
|
|
6
|
-
* @property {Pryv.Service} Service - To interact with Pryv.io at a "Platform level"
|
|
7
|
-
* @property {Pryv.Connection} Connection - To interact with an individual's (user) data set
|
|
8
|
-
* @property {Pryv.Browser} Browser - Browser Tools - Access request helpers and visuals (button)
|
|
9
|
-
* @property {Pryv.utils} utils - Exposes **superagent** for HTTP calls and tools to manipulate Pryv's Api Endpoints
|
|
10
|
-
*/
|
|
11
|
-
module.exports = {
|
|
12
|
-
Service: require('./Service'),
|
|
13
|
-
Connection: require('./Connection'),
|
|
14
|
-
Auth: require('./Auth'),
|
|
15
|
-
Browser: require('./Browser'),
|
|
16
|
-
utils: require('./utils'),
|
|
17
|
-
version: require('../package.json').version
|
|
18
|
-
}
|
|
19
|
-
|
package/src/index.html
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<title>Pryv - Light - Javascript Lib</title>
|
|
6
|
-
|
|
7
|
-
<script src="./print.bundle.js"></script>
|
|
8
|
-
</head>
|
|
9
|
-
|
|
10
|
-
<body>
|
|
11
|
-
-
|
|
12
|
-
<script src="./bundle.js"></script>
|
|
13
|
-
+
|
|
14
|
-
<script src="./app.bundle.js"></script>
|
|
15
|
-
</body>
|
|
16
|
-
|
|
17
|
-
</html>
|
package/test/browser-index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Entry Point for WebPack to build test series to be run in browser
|
|
3
|
-
*/
|
|
4
|
-
//mocha.setup({ ignoreLeaks: true });
|
|
5
|
-
|
|
6
|
-
require('./utils.test.js');
|
|
7
|
-
require('./Connection.test.js');
|
|
8
|
-
require('./Service.test.js');
|
|
9
|
-
require('./ServiceAssets.test.js');
|
|
10
|
-
require('./Browser.test.js');
|
|
11
|
-
require('./Browser.AuthController.test.js');
|
package/test/browser-tests.html
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<title>Pryv Javascrip Lib - Browser Tests </title>
|
|
6
|
-
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
|
|
7
|
-
</head>
|
|
8
|
-
|
|
9
|
-
<body>
|
|
10
|
-
<div id="mocha"></div>
|
|
11
|
-
<script src="https://unpkg.com/chai/chai.js"></script>
|
|
12
|
-
<script src="https://unpkg.com/mocha/mocha.js"></script>
|
|
13
|
-
<script class="mocha-init">
|
|
14
|
-
mocha.setup('bdd');
|
|
15
|
-
mocha.checkLeaks();
|
|
16
|
-
</script>
|
|
17
|
-
<script src="../pryv.js"></script>
|
|
18
|
-
|
|
19
|
-
<!-- load code you want to test here -->
|
|
20
|
-
<!-- ------------------------------------ -->
|
|
21
|
-
<script type="text/javascript" src="browser-tests.js"></script>
|
|
22
|
-
<!-- ------------------------------------ -->
|
|
23
|
-
<!-- load your test files here -->
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
<script>
|
|
27
|
-
mocha.run();
|
|
28
|
-
</script>
|
|
29
|
-
</body>
|
|
30
|
-
|
|
31
|
-
</html>
|
package/test/helpers.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
const testData = require('./test-data.js');
|
|
2
|
-
const Pryv = require('../src');
|
|
3
|
-
|
|
4
|
-
const conn = new Pryv.Connection(testData.apiEndpointWithToken);
|
|
5
|
-
|
|
6
|
-
const TEST_DATA_VERSION = "v1";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// -- check if account is already loaded
|
|
10
|
-
const res = conn.api([{
|
|
11
|
-
"method": "events.get",
|
|
12
|
-
"params": {
|
|
13
|
-
"streams": ["data"],
|
|
14
|
-
"types": ["test/version"],
|
|
15
|
-
"limit": 1
|
|
16
|
-
}
|
|
17
|
-
}]).then((res, err) => {
|
|
18
|
-
if (res[0].events[0] && res[0].events[0].content === TEST_DATA_VERSION) {
|
|
19
|
-
console.log('TEST ACCOUNT IS UP TO DATE');
|
|
20
|
-
} else {
|
|
21
|
-
doLoad();
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
function doLoad() {
|
|
26
|
-
let query = [
|
|
27
|
-
{ // trash eventual stream data
|
|
28
|
-
"method": "streams.delete",
|
|
29
|
-
"params": {
|
|
30
|
-
"id": "data",
|
|
31
|
-
"mergeEventsWithParent": false
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
{ // clear from trash eventual stream data
|
|
35
|
-
"method": "streams.delete",
|
|
36
|
-
"params": {
|
|
37
|
-
"id": "data",
|
|
38
|
-
"mergeEventsWithParent": false
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"method": "streams.create",
|
|
43
|
-
"params": {
|
|
44
|
-
"id": "data",
|
|
45
|
-
"name": "Test Data",
|
|
46
|
-
"clientData": {
|
|
47
|
-
"pryv-browser:charts": {
|
|
48
|
-
"mass/kg": {
|
|
49
|
-
"settings": {
|
|
50
|
-
"color": "#1abc9c",
|
|
51
|
-
"style": "line",
|
|
52
|
-
"transform": "none",
|
|
53
|
-
"interval": "auto"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
"method": "events.create",
|
|
62
|
-
"params": {
|
|
63
|
-
"streamId": "data",
|
|
64
|
-
"type": "test/version",
|
|
65
|
-
"content": TEST_DATA_VERSION
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
const now = (new Date()).getTime() / 1000;
|
|
71
|
-
const steps = 60 * 60 ; // 1 hours
|
|
72
|
-
for (let i = 0; i < 10000; i++) {
|
|
73
|
-
query.push(
|
|
74
|
-
{
|
|
75
|
-
"method": "events.create",
|
|
76
|
-
"params": {
|
|
77
|
-
"time": now - i * steps,
|
|
78
|
-
"streamId": "data",
|
|
79
|
-
"type": "mass/kg",
|
|
80
|
-
"content": Math.sin(i / 180)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const res = conn.api(query).then((res, err) => {
|
|
87
|
-
trashFirst200DeleteFirst100(res).then((res2, err2) => {
|
|
88
|
-
console.log(res2);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function trashFirst200DeleteFirst100(res) {
|
|
94
|
-
const query = [];
|
|
95
|
-
for (let i = 5; i < 205; i++) {
|
|
96
|
-
const k = (i < 105) ? 2 : 1;
|
|
97
|
-
for (j = 0; j < k; j++) { // do twice for the firsts 100
|
|
98
|
-
console.log(res[i]);
|
|
99
|
-
query.push({
|
|
100
|
-
"method": "events.delete",
|
|
101
|
-
"params": {
|
|
102
|
-
"id": res[i].event.id
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return await conn.api(query);
|
|
108
|
-
}
|
package/test/test-data.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
const superagent = require('superagent');
|
|
2
|
-
|
|
3
|
-
const username = 'jslibtest5';
|
|
4
|
-
const serviceInfoUrl = 'https://reg.pryv.me/service/info';
|
|
5
|
-
//const serviceInfoUrl = 'https://l.rec.la:4443/reg/service/info';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Data used for tests
|
|
9
|
-
*/
|
|
10
|
-
const testData = {
|
|
11
|
-
username: username,
|
|
12
|
-
password: username,
|
|
13
|
-
serviceInfoUrl: serviceInfoUrl,
|
|
14
|
-
token: null,
|
|
15
|
-
serviceInfo: null,
|
|
16
|
-
apiEndpoint: null,
|
|
17
|
-
apiEndpointWithToken: null
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
async function prepare() {
|
|
22
|
-
if (testData.token != null) return testData;
|
|
23
|
-
console.log('Preparing test Data..');
|
|
24
|
-
// fetch serviceInfo
|
|
25
|
-
|
|
26
|
-
const serviceInfo = (await superagent.get(serviceInfoUrl)).body;
|
|
27
|
-
if (serviceInfo.api == null) throw 'Invalid service Info ' + JSON.stringify(serviceInfo);
|
|
28
|
-
// test if user exists
|
|
29
|
-
const userExists = (await superagent.get(serviceInfo.register + username + '/check_username')).body;
|
|
30
|
-
if (typeof userExists.reserved === 'undefined') throw 'Invalid user exists ' + JSON.stringify(userExists);
|
|
31
|
-
|
|
32
|
-
let hostingCandidate = null;
|
|
33
|
-
if (! userExists.reserved) { // create user
|
|
34
|
-
// get available hosting
|
|
35
|
-
const hostings = (await superagent.get(serviceInfo.register + 'hostings').set('accept', 'json')).body;
|
|
36
|
-
findOneHostingKey(hostings, 'N');
|
|
37
|
-
function findOneHostingKey(o, parentKey) {
|
|
38
|
-
for (const key of Object.keys(o)) {
|
|
39
|
-
if (parentKey === 'hostings') {
|
|
40
|
-
hostingCandidate = key;
|
|
41
|
-
return key;
|
|
42
|
-
}
|
|
43
|
-
if (typeof o[key] !== 'string')
|
|
44
|
-
findOneHostingKey(o[key], key);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
if (hostingCandidate == null) throw 'Cannot find hosting in: ' + JSON.stringify(hostings);
|
|
48
|
-
const hosting = hostingCandidate;
|
|
49
|
-
|
|
50
|
-
// create user
|
|
51
|
-
await superagent.post(serviceInfo.register + 'user')
|
|
52
|
-
.send({
|
|
53
|
-
appid: 'js-lib-test',
|
|
54
|
-
hosting: hosting,
|
|
55
|
-
username: username,
|
|
56
|
-
password: username,
|
|
57
|
-
email: username + '@pryv.io',
|
|
58
|
-
invitationtoken: 'enjoy',
|
|
59
|
-
languageCode: 'en',
|
|
60
|
-
referer: 'test-suite'
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
const apiEndpoint = serviceInfo.api.replace('{username}', username);
|
|
64
|
-
|
|
65
|
-
// login user
|
|
66
|
-
const headers = {};
|
|
67
|
-
if (typeof window === 'undefined') { headers.Origin = 'https://l.rec.la'; }; // node only
|
|
68
|
-
const loginRes = await superagent.post(apiEndpoint + 'auth/login')
|
|
69
|
-
.set(headers)
|
|
70
|
-
.send({ username: username, password: username, appId: 'js-lib-test' });
|
|
71
|
-
|
|
72
|
-
// create data stream
|
|
73
|
-
try {
|
|
74
|
-
const streamRes = await superagent.post(apiEndpoint + 'streams').set('authorization', loginRes.body.token).send(
|
|
75
|
-
{
|
|
76
|
-
id: 'data',
|
|
77
|
-
name: 'Data'
|
|
78
|
-
}
|
|
79
|
-
)
|
|
80
|
-
} catch (e) {
|
|
81
|
-
}
|
|
82
|
-
if ((loginRes.body == null) || (loginRes.body.token == null)) throw 'Failed login process during testData prepare' + loginRes.text;
|
|
83
|
-
testData.serviceInfo = serviceInfo;
|
|
84
|
-
testData.token = loginRes.body.token;
|
|
85
|
-
|
|
86
|
-
const regexAPIandToken = /(.+):\/\/(.+)/gm;
|
|
87
|
-
const res = regexAPIandToken.exec(apiEndpoint);
|
|
88
|
-
testData.apiEndpointWithToken = res[1] + '://' + testData.token + '@' + res[2];
|
|
89
|
-
testData.apiEndpoint = apiEndpoint;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
testData.prepare = prepare;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
module.exports = testData;
|