pryv 2.1.5 → 2.1.9
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/LICENSE.md +1 -1
- package/README.md +44 -1
- package/package.json +10 -11
- package/src/Browser/LoginButton.js +2 -1
- package/src/Connection.js +17 -0
- package/test/Connection.test.js +73 -29
- package/test/test-data.js +4 -1
- package/web-demos/custom-login-button.html +1 -1
- package/webpack.config.js +16 -4
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -7,11 +7,19 @@ This JavaScript library is meant to facilitate writing NodeJS and browser apps f
|
|
|
7
7
|
*Prerequisites*: Node 12
|
|
8
8
|
|
|
9
9
|
- Setup: `npm run setup`
|
|
10
|
+
|
|
10
11
|
- Build pryv.js library for browsers: `npm run build`, the result is published in `./dist`
|
|
12
|
+
|
|
11
13
|
- Build documentation: `npm run doc`, the result is published in `./dist/docs`
|
|
14
|
+
|
|
15
|
+
Note: as per v2.1.7 `jsdoc` dev dependency has been removed from package.json .. it should be installed with `npm install jsoc --dev`
|
|
16
|
+
|
|
12
17
|
- Node Tests: `npm run test`
|
|
18
|
+
|
|
13
19
|
- Coverage: `npm run cover`, the result is visible in `./coverage`
|
|
20
|
+
|
|
14
21
|
- Browser tests: **build**, then `npm run webserver` and open [https://l.rec.la:9443/tests/browser-tests.html?pryvServiceInfoUrl=https://zouzou.com/service/info](https://l.rec.la:9443/tests/browser-tests.html?pryvServiceInfoUrl=https://zouzou.com/service/info)
|
|
22
|
+
|
|
15
23
|
- Update on CDN: After running **setup** and **build** scripts, run `npm run gh-pages ${COMMIT_MESSAGE}`. If this fails, run `npm run clear` to rebuild a fresh `dist/` folder
|
|
16
24
|
|
|
17
25
|
## Usage
|
|
@@ -331,6 +339,22 @@ const result = await connection.createEventWithFile(
|
|
|
331
339
|
);
|
|
332
340
|
```
|
|
333
341
|
|
|
342
|
+
or from a Buffer
|
|
343
|
+
|
|
344
|
+
```javascript
|
|
345
|
+
const filePath = './test/my_image.png';
|
|
346
|
+
const bufferData = fs.readFileSync(filePath);
|
|
347
|
+
|
|
348
|
+
const result = await connection.createEventWithFileFromBuffer(
|
|
349
|
+
{
|
|
350
|
+
type: 'picture/attached',
|
|
351
|
+
streamId: 'data'
|
|
352
|
+
},
|
|
353
|
+
bufferData,
|
|
354
|
+
'my_image.png' // filename
|
|
355
|
+
);
|
|
356
|
+
```
|
|
357
|
+
|
|
334
358
|
#### Browser
|
|
335
359
|
|
|
336
360
|
From an Input field
|
|
@@ -378,6 +402,21 @@ connect.createEventWithFormData(
|
|
|
378
402
|
// handle result here
|
|
379
403
|
}
|
|
380
404
|
);
|
|
405
|
+
|
|
406
|
+
// -- alternative with a filename
|
|
407
|
+
|
|
408
|
+
connect.createEventWithFileFromBuffer(
|
|
409
|
+
{
|
|
410
|
+
type: 'file/attached',
|
|
411
|
+
streamId: 'data'
|
|
412
|
+
},
|
|
413
|
+
blob, 'filename.txt') // here we can directly use the blob
|
|
414
|
+
.then(function (res, err) {
|
|
415
|
+
// handle result here
|
|
416
|
+
}
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
|
|
381
420
|
```
|
|
382
421
|
|
|
383
422
|
### High Frequency Events
|
|
@@ -681,6 +720,10 @@ You can find html examples in the [`./web-demos`](/web-demos) directory. You can
|
|
|
681
720
|
|
|
682
721
|
# Change Log
|
|
683
722
|
|
|
723
|
+
## 2.1.7
|
|
724
|
+
|
|
725
|
+
- Removed JSDOC dev dependency for security reason
|
|
726
|
+
|
|
684
727
|
## 2.1.0
|
|
685
728
|
|
|
686
729
|
- UI separated from the Authentication logic
|
|
@@ -692,4 +735,4 @@ You can find html examples in the [`./web-demos`](/web-demos) directory. You can
|
|
|
692
735
|
- Various dependencies upgrades
|
|
693
736
|
- Fixing Origin header in Browser distribution
|
|
694
737
|
|
|
695
|
-
## 2.0.1 Initial Release
|
|
738
|
+
## 2.0.1 Initial Release
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pryv",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.9",
|
|
4
4
|
"homepage": "https://github.com/pryv/lib-js",
|
|
5
5
|
"description": "Pryv Javascript Library",
|
|
6
6
|
"keywords": [
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"setup": "./scripts/setup-environment-dev.sh",
|
|
23
23
|
"build": "webpack --config webpack.config.js",
|
|
24
|
-
"doc": "
|
|
24
|
+
"doc": "npx jsdoc -c .jsdoc-conf.json",
|
|
25
25
|
"test": "mocha --reporter spec test/**/*.test.js --timeout 3000",
|
|
26
26
|
"test-debug": "mocha --inpect-brk=40000 --reporter spec test/**/*.test.js ",
|
|
27
27
|
"test:browser": "npm run build; ",
|
|
@@ -38,20 +38,19 @@
|
|
|
38
38
|
}
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"superagent": "^
|
|
41
|
+
"superagent": "^6.1.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@pryv/lib-js-common": "
|
|
45
|
-
"@pryv/monitor": "^1.0.
|
|
46
|
-
"@pryv/socket.io": "^1.0.
|
|
47
|
-
"chai": "^4.
|
|
44
|
+
"@pryv/lib-js-common": "github:pryv/lib-js-common#1.0.6",
|
|
45
|
+
"@pryv/monitor": "^1.0.5",
|
|
46
|
+
"@pryv/socket.io": "^1.0.5",
|
|
47
|
+
"chai": "^4.3.4",
|
|
48
48
|
"chai-as-promised": "^7.1.1",
|
|
49
49
|
"cuid": "^2.1.8",
|
|
50
|
-
"
|
|
51
|
-
"mocha": "^6.2.3",
|
|
50
|
+
"mocha": "^9.1.3",
|
|
52
51
|
"node-fetch": "^2.6.0",
|
|
53
|
-
"nyc": "^
|
|
54
|
-
"rec
|
|
52
|
+
"nyc": "^15.1.0",
|
|
53
|
+
"rec.la": "latest",
|
|
55
54
|
"universal-url": "^2.0.0",
|
|
56
55
|
"zombie": "^6.1.4"
|
|
57
56
|
}
|
|
@@ -154,7 +154,8 @@ async function startLoginScreen (loginButton, authUrl) {
|
|
|
154
154
|
loginButton.popup = window.open(authUrl, 'prYv Sign-in', features);
|
|
155
155
|
|
|
156
156
|
if (!loginButton.popup) {
|
|
157
|
-
loginButton.auth.stopAuthRequest('FAILED_TO_OPEN_WINDOW');
|
|
157
|
+
// loginButton.auth.stopAuthRequest('FAILED_TO_OPEN_WINDOW');
|
|
158
|
+
console.log('Pop-up blocked. A second click should allow it.');
|
|
158
159
|
} else if (window.focus) {
|
|
159
160
|
loginButton.popup.focus();
|
|
160
161
|
}
|
package/src/Connection.js
CHANGED
|
@@ -257,6 +257,23 @@ class Connection {
|
|
|
257
257
|
return res.body
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
+
/**
|
|
261
|
+
* Create an event from a Buffer
|
|
262
|
+
* NODE.jS ONLY
|
|
263
|
+
* @param {Event} event
|
|
264
|
+
* @param {Buffer} bufferData
|
|
265
|
+
* @param {string} fileName
|
|
266
|
+
*/
|
|
267
|
+
async createEventWithFileFromBuffer(event, bufferData, filename) {
|
|
268
|
+
const res = await this._post('events')
|
|
269
|
+
.field('event', JSON.stringify(event))
|
|
270
|
+
.attach('file', bufferData, filename);
|
|
271
|
+
|
|
272
|
+
const now = Date.now() / 1000;
|
|
273
|
+
this._handleMeta(res.body, now);
|
|
274
|
+
return res.body
|
|
275
|
+
}
|
|
276
|
+
|
|
260
277
|
/**
|
|
261
278
|
* Create an event with attached formData
|
|
262
279
|
* !! BROWSER ONLY
|
package/test/Connection.test.js
CHANGED
|
@@ -5,6 +5,13 @@ let conn = null;
|
|
|
5
5
|
const { URL, URLSearchParams } = require('universal-url');
|
|
6
6
|
const cuid = require('cuid');
|
|
7
7
|
|
|
8
|
+
const isNode = (typeof window === 'undefined');
|
|
9
|
+
|
|
10
|
+
let readFileSync;
|
|
11
|
+
if (isNode) { // node
|
|
12
|
+
readFileSync = require('fs').readFileSync;
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
describe('Connection', () => {
|
|
9
16
|
|
|
10
17
|
before(async function () {
|
|
@@ -183,35 +190,85 @@ describe('Connection', () => {
|
|
|
183
190
|
});
|
|
184
191
|
|
|
185
192
|
describe('Attachements', () => {
|
|
186
|
-
it('Create event with
|
|
187
|
-
|
|
193
|
+
it('Node Only: Create event with attachment from file', async function () {
|
|
194
|
+
if (!isNode) { this.skip(); }
|
|
195
|
+
const res = await conn.createEventWithFile({
|
|
196
|
+
type: 'picture/attached',
|
|
197
|
+
streamId: 'data'
|
|
198
|
+
}, './test/Y.png');
|
|
188
199
|
|
|
189
|
-
if (typeof window === 'undefined') { // node
|
|
190
200
|
|
|
191
|
-
|
|
201
|
+
should.exist(res);
|
|
202
|
+
should.exist(res.event);
|
|
203
|
+
should.exist(res.event.attachments);
|
|
204
|
+
res.event.attachments.length.should.equal(1);
|
|
205
|
+
res.event.attachments[0].size.should.equal(14798);
|
|
206
|
+
res.event.attachments[0].type.should.equal('image/png');
|
|
207
|
+
res.event.attachments[0].fileName.should.equal('Y.png');
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('Node Only: Create event with attachment from Buffer', async function () {
|
|
211
|
+
if (!isNode) { this.skip(); }
|
|
212
|
+
|
|
213
|
+
const fileData = readFileSync('./test/Y.png');
|
|
214
|
+
const res = await conn.createEventWithFileFromBuffer({
|
|
192
215
|
type: 'picture/attached',
|
|
193
216
|
streamId: 'data'
|
|
194
|
-
}, '
|
|
217
|
+
}, fileData, 'Y.png');
|
|
195
218
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
219
|
+
should.exist(res);
|
|
220
|
+
should.exist(res.event);
|
|
221
|
+
should.exist(res.event.attachments);
|
|
222
|
+
res.event.attachments.length.should.equal(1);
|
|
223
|
+
res.event.attachments[0].size.should.equal(14798);
|
|
224
|
+
res.event.attachments[0].type.should.equal('image/png');
|
|
225
|
+
res.event.attachments[0].fileName.should.equal('Y.png');
|
|
200
226
|
|
|
201
|
-
|
|
202
|
-
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('Browser Only: Create event with attachment from Buffer', async function () {
|
|
230
|
+
if (isNode) { this.skip(); }
|
|
231
|
+
|
|
232
|
+
const blob = new Blob(['Hello'], { type: "text/txt" });
|
|
233
|
+
const res = await conn.createEventWithFileFromBuffer({
|
|
234
|
+
type: 'picture/attached',
|
|
203
235
|
streamId: 'data'
|
|
204
|
-
},
|
|
236
|
+
}, blob, 'Hello.txt');
|
|
237
|
+
|
|
238
|
+
should.exist(res);
|
|
239
|
+
should.exist(res.event);
|
|
240
|
+
console.log(res.event);
|
|
241
|
+
should.exist(res.event.attachments);
|
|
242
|
+
res.event.attachments.length.should.equal(1);
|
|
243
|
+
res.event.attachments[0].size.should.equal(5);
|
|
244
|
+
res.event.attachments[0].type.should.equal('text/txt');
|
|
245
|
+
res.event.attachments[0].fileName.should.equal('Hello.txt');
|
|
246
|
+
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('Browser Only: Create event with attachment formData', async function () {
|
|
250
|
+
if (isNode) { this.skip(); }
|
|
205
251
|
|
|
206
|
-
|
|
252
|
+
const formData = new FormData();
|
|
253
|
+
const blob = new Blob(['Hello'], { type: "text/txt" });
|
|
254
|
+
formData.append("webmasterfile", blob);
|
|
255
|
+
|
|
256
|
+
const res = await conn.createEventWithFormData({
|
|
257
|
+
type: 'file/attached',
|
|
258
|
+
streamId: 'data'
|
|
259
|
+
}, formData);
|
|
207
260
|
|
|
208
261
|
|
|
209
262
|
should.exist(res);
|
|
210
263
|
should.exist(res.event);
|
|
211
264
|
should.exist(res.event.attachments);
|
|
212
265
|
res.event.attachments.length.should.equal(1);
|
|
213
|
-
|
|
266
|
+
res.event.attachments[0].size.should.equal(5);
|
|
267
|
+
res.event.attachments[0].type.should.equal('text/txt');
|
|
268
|
+
res.event.attachments[0].fileName.should.equal('blob');
|
|
214
269
|
});
|
|
270
|
+
|
|
271
|
+
|
|
215
272
|
});
|
|
216
273
|
|
|
217
274
|
describe('HF events', () => {
|
|
@@ -301,14 +358,14 @@ describe('Connection', () => {
|
|
|
301
358
|
});
|
|
302
359
|
|
|
303
360
|
it('no-events ', async () => {
|
|
304
|
-
const queryParams = { fromTime: 0, toTime: now,
|
|
361
|
+
const queryParams = { fromTime: 0, toTime: now, types: ['type/unexistent'] };
|
|
305
362
|
function forEachEvent(event) { }
|
|
306
363
|
const res = await conn.getEventsStreamed(queryParams, forEachEvent);
|
|
307
364
|
expect(0).to.equal(res.eventsCount);
|
|
308
365
|
});
|
|
309
366
|
|
|
310
367
|
it('no-events includeDeletions', async () => {
|
|
311
|
-
const queryParams = { fromTime: 0, toTime: now,
|
|
368
|
+
const queryParams = { fromTime: 0, toTime: now, types: ['type/unexistent'], includeDeletions: true, modifiedSince: 0 };
|
|
312
369
|
function forEachEvent(event) { }
|
|
313
370
|
const res = await conn.getEventsStreamed(queryParams, forEachEvent);
|
|
314
371
|
expect(0).to.equal(res.eventsCount);
|
|
@@ -406,19 +463,6 @@ describe('Connection', () => {
|
|
|
406
463
|
should.equal(newUser.access.name, accessInfoUser.name);
|
|
407
464
|
});
|
|
408
465
|
|
|
409
|
-
it('has same permissions', () => {
|
|
410
|
-
should.exist(accessInfoUser);
|
|
411
|
-
should.exist(accessInfoUser.permissions);
|
|
412
|
-
let lengthPermission = accessInfoUser.permissions.length;
|
|
413
|
-
should.equal(newUser.access.permissions.length, lengthPermission);
|
|
414
|
-
for (let i = 0; i < lengthPermission; i++) {
|
|
415
|
-
should.exist(accessInfoUser.permissions[i].streamId);
|
|
416
|
-
should.equal(newUser.access.permissions[i].streamId, accessInfoUser.permissions[i].streamId);
|
|
417
|
-
should.exist(accessInfoUser.permissions[i].level);
|
|
418
|
-
should.equal(newUser.access.permissions[i].level, accessInfoUser.permissions[i].level);
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
|
|
422
466
|
it('has same token', () => {
|
|
423
467
|
should.exist(accessInfoUser.token);
|
|
424
468
|
should.equal(newUser.access.token, accessInfoUser.token);
|
package/test/test-data.js
CHANGED
|
@@ -61,9 +61,12 @@ async function prepare() {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
const apiEndpoint = serviceInfo.api.replace('{username}', username);
|
|
64
|
+
|
|
64
65
|
// login user
|
|
66
|
+
const headers = {};
|
|
67
|
+
if (typeof window === 'undefined') { headers.Origin = 'https://l.rec.la'; }; // node only
|
|
65
68
|
const loginRes = await superagent.post(apiEndpoint + 'auth/login')
|
|
66
|
-
.set(
|
|
69
|
+
.set(headers)
|
|
67
70
|
.send({ username: username, password: username, appId: 'js-lib-test' });
|
|
68
71
|
|
|
69
72
|
// create data stream
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
loginButton.popup = window.open(authUrl, 'Your custom Sign-in pop-up', features);
|
|
126
126
|
|
|
127
127
|
if (!loginButton.popup) {
|
|
128
|
-
console.log('
|
|
128
|
+
console.log('Pop-up blocked. A second click should allow it.');
|
|
129
129
|
} else if (window.focus) {
|
|
130
130
|
loginButton.popup.focus();
|
|
131
131
|
}
|
package/webpack.config.js
CHANGED
|
@@ -24,7 +24,7 @@ module.exports = [
|
|
|
24
24
|
{ // es5 version
|
|
25
25
|
mode: 'production',
|
|
26
26
|
entry: {
|
|
27
|
-
'pryv': ['
|
|
27
|
+
'pryv': ['./src/index.js'],
|
|
28
28
|
},
|
|
29
29
|
output: {
|
|
30
30
|
filename: '[name].js',
|
|
@@ -38,7 +38,7 @@ module.exports = [
|
|
|
38
38
|
{ // es5 version including socket.io and monitors
|
|
39
39
|
mode: 'production',
|
|
40
40
|
entry: {
|
|
41
|
-
'pryv-socket.io-monitor': ['
|
|
41
|
+
'pryv-socket.io-monitor': ['./src/index-socket.io-monitor.js'],
|
|
42
42
|
},
|
|
43
43
|
output: {
|
|
44
44
|
filename: '[name].js',
|
|
@@ -47,7 +47,13 @@ module.exports = [
|
|
|
47
47
|
library: 'Pryv'
|
|
48
48
|
},
|
|
49
49
|
devtool: 'source-map',
|
|
50
|
-
module: webpackBabelConfig
|
|
50
|
+
module: webpackBabelConfig,
|
|
51
|
+
resolve: {
|
|
52
|
+
fallback: {
|
|
53
|
+
'fs': false,
|
|
54
|
+
'path': false,
|
|
55
|
+
},
|
|
56
|
+
}
|
|
51
57
|
},
|
|
52
58
|
{ // browser test suite (es6)
|
|
53
59
|
mode: 'development',
|
|
@@ -61,11 +67,17 @@ module.exports = [
|
|
|
61
67
|
library: 'browserTest'
|
|
62
68
|
},
|
|
63
69
|
plugins: [
|
|
64
|
-
new webpack.IgnorePlugin(/zombie/),
|
|
70
|
+
new webpack.IgnorePlugin({resourceRegExp: /zombie/}),
|
|
65
71
|
new CopyPlugin({ patterns: [
|
|
66
72
|
{ from: 'test/browser-tests.html' },
|
|
67
73
|
]})
|
|
68
74
|
],
|
|
69
75
|
devtool: 'source-map',
|
|
76
|
+
resolve: {
|
|
77
|
+
fallback: {
|
|
78
|
+
'fs': false,
|
|
79
|
+
'path': false,
|
|
80
|
+
},
|
|
81
|
+
}
|
|
70
82
|
}
|
|
71
83
|
];
|