pryv 2.1.8 → 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/README.md CHANGED
@@ -343,7 +343,7 @@ or from a Buffer
343
343
 
344
344
  ```javascript
345
345
  const filePath = './test/my_image.png';
346
- const buggerData = fs.readFileSync(filePath);
346
+ const bufferData = fs.readFileSync(filePath);
347
347
 
348
348
  const result = await connection.createEventWithFileFromBuffer(
349
349
  {
@@ -402,6 +402,21 @@ connect.createEventWithFormData(
402
402
  // handle result here
403
403
  }
404
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
+
405
420
  ```
406
421
 
407
422
  ### High Frequency Events
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pryv",
3
- "version": "2.1.8",
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": "node node_modules/jsdoc/jsdoc.js -c .jsdoc-conf.json",
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,19 +38,19 @@
38
38
  }
39
39
  ],
40
40
  "dependencies": {
41
- "superagent": "^5.2.2"
41
+ "superagent": "^6.1.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@pryv/lib-js-common": "git+https://github.com/pryv/lib-js-common.git#1.0.4",
44
+ "@pryv/lib-js-common": "github:pryv/lib-js-common#1.0.6",
45
45
  "@pryv/monitor": "^1.0.5",
46
46
  "@pryv/socket.io": "^1.0.5",
47
47
  "chai": "^4.3.4",
48
48
  "chai-as-promised": "^7.1.1",
49
49
  "cuid": "^2.1.8",
50
- "mocha": "^6.2.3",
50
+ "mocha": "^9.1.3",
51
51
  "node-fetch": "^2.6.0",
52
- "nyc": "^14.1.1",
53
- "rec-la": "latest",
52
+ "nyc": "^15.1.0",
53
+ "rec.la": "latest",
54
54
  "universal-url": "^2.0.0",
55
55
  "zombie": "^6.1.4"
56
56
  }
@@ -4,7 +4,13 @@ const testData = require('./test-data.js');
4
4
  let conn = null;
5
5
  const { URL, URLSearchParams } = require('universal-url');
6
6
  const cuid = require('cuid');
7
- const { readFileSync } = require('fs');
7
+
8
+ const isNode = (typeof window === 'undefined');
9
+
10
+ let readFileSync;
11
+ if (isNode) { // node
12
+ readFileSync = require('fs').readFileSync;
13
+ }
8
14
 
9
15
  describe('Connection', () => {
10
16
 
@@ -184,27 +190,12 @@ describe('Connection', () => {
184
190
  });
185
191
 
186
192
  describe('Attachements', () => {
187
- it('Create event with attachment from file', async () => {
188
- let res = null;
189
-
190
- if (typeof window === 'undefined') { // node
191
-
192
- res = await conn.createEventWithFile({
193
- type: 'picture/attached',
194
- streamId: 'data'
195
- }, './test/Y.png');
196
-
197
- } else { // browser
198
- const formData = new FormData();
199
- var blob = new Blob(['Hello'], { type: "text/txt" });
200
- formData.append("webmasterfile", blob);
201
-
202
- res = await conn.createEventWithFormData({
203
- type: 'file/attached',
204
- streamId: 'data'
205
- }, formData);
206
-
207
- }
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');
208
199
 
209
200
 
210
201
  should.exist(res);
@@ -216,38 +207,65 @@ describe('Connection', () => {
216
207
  res.event.attachments[0].fileName.should.equal('Y.png');
217
208
  });
218
209
 
219
- it('Create event with attachment from Buffer', async () => {
220
- const fileData = readFileSync('./test/Y.png');
221
-
222
- let res = null;
223
-
224
- if (typeof window === 'undefined') { // node
225
-
226
- res = await conn.createEventWithFileFromBuffer({
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({
227
215
  type: 'picture/attached',
228
216
  streamId: 'data'
229
217
  }, fileData, 'Y.png');
230
218
 
231
- } else { // browser
232
- const formData = new FormData();
233
- var blob = new Blob(['Hello'], { type: "text/txt" });
234
- formData.append("webmasterfile", blob);
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');
226
+
227
+ });
235
228
 
236
- res = await conn.createEventWithFormData({
237
- type: 'file/attached',
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',
238
235
  streamId: 'data'
239
- }, formData);
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(); }
240
251
 
241
- }
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);
242
260
 
243
261
 
244
262
  should.exist(res);
245
263
  should.exist(res.event);
246
264
  should.exist(res.event.attachments);
247
265
  res.event.attachments.length.should.equal(1);
248
- res.event.attachments[0].size.should.equal(14798);
249
- res.event.attachments[0].type.should.equal('image/png');
250
- res.event.attachments[0].fileName.should.equal('Y.png');
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');
251
269
  });
252
270
 
253
271
 
@@ -340,14 +358,14 @@ describe('Connection', () => {
340
358
  });
341
359
 
342
360
  it('no-events ', async () => {
343
- const queryParams = { fromTime: 0, toTime: now, tags: ['RANDOM-123'] };
361
+ const queryParams = { fromTime: 0, toTime: now, types: ['type/unexistent'] };
344
362
  function forEachEvent(event) { }
345
363
  const res = await conn.getEventsStreamed(queryParams, forEachEvent);
346
364
  expect(0).to.equal(res.eventsCount);
347
365
  });
348
366
 
349
367
  it('no-events includeDeletions', async () => {
350
- const queryParams = { fromTime: 0, toTime: now, tags: ['RANDOM-123'], includeDeletions: true, modifiedSince: 0 };
368
+ const queryParams = { fromTime: 0, toTime: now, types: ['type/unexistent'], includeDeletions: true, modifiedSince: 0 };
351
369
  function forEachEvent(event) { }
352
370
  const res = await conn.getEventsStreamed(queryParams, forEachEvent);
353
371
  expect(0).to.equal(res.eventsCount);
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('Origin', 'https://l.rec.la')
69
+ .set(headers)
67
70
  .send({ username: username, password: username, appId: 'js-lib-test' });
68
71
 
69
72
  // create data stream
package/webpack.config.js CHANGED
@@ -24,7 +24,7 @@ module.exports = [
24
24
  { // es5 version
25
25
  mode: 'production',
26
26
  entry: {
27
- 'pryv': ['core-js/stable', './src/index.js'],
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': ['core-js/stable', './src/index-socket.io-monitor.js'],
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
  ];