pryv 2.2.0 → 2.3.2
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 +291 -299
- package/package.json +11 -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 +37 -48
- 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
package/src/Service.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
|
+
*/
|
|
2
5
|
const utils = require('./utils.js');
|
|
3
6
|
// Connection is required at the end of this file to allow circular requires.
|
|
4
7
|
const Assets = require('./ServiceAssets.js');
|
|
5
8
|
|
|
6
|
-
|
|
7
9
|
/**
|
|
8
|
-
* @class
|
|
10
|
+
* @class pryv.Service
|
|
9
11
|
* A Pryv.io deployment is a unique "Service", as an example **Pryv Lab** is a service, deployed with the domain name **pryv.me**.
|
|
10
|
-
*
|
|
11
|
-
* `
|
|
12
|
+
*
|
|
13
|
+
* `pryv.Service` exposes tools to interact with Pryv.io at a "Platform" level.
|
|
12
14
|
*
|
|
13
15
|
* ##### Initizalization with a service info URL
|
|
14
|
-
```
|
|
15
|
-
const service = new
|
|
16
|
+
```js
|
|
17
|
+
const service = new pryv.Service('https://reg.pryv.me/service/info');
|
|
16
18
|
```
|
|
17
19
|
|
|
18
20
|
- With the content of a serviceInfo configuration
|
|
19
21
|
|
|
20
22
|
Service information properties can be overriden with specific values. This might be usefull to test new designs on production platforms.
|
|
21
23
|
|
|
22
|
-
```
|
|
24
|
+
```js
|
|
23
25
|
const serviceInfoUrl = 'https://reg.pryv.me/service/info';
|
|
24
26
|
const serviceCustomizations = {
|
|
25
27
|
name: 'Pryv Lab 2',
|
|
@@ -27,68 +29,67 @@ const serviceCustomizations = {
|
|
|
27
29
|
definitions: 'https://pryv.github.io/assets-pryv.me/index.json'
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
const service = new
|
|
31
|
-
```
|
|
32
|
+
const service = new pryv.Service(serviceInfoUrl, serviceCustomizations);
|
|
33
|
+
```
|
|
32
34
|
|
|
33
|
-
* @memberof
|
|
34
|
-
*
|
|
35
|
+
* @memberof pryv
|
|
36
|
+
*
|
|
35
37
|
* @constructor
|
|
36
38
|
* @param {string} serviceInfoUrl Url point to /service/info of a Pryv platform see: {@link https://api.pryv.com/reference/#service-info}
|
|
37
39
|
*/
|
|
38
40
|
class Service {
|
|
39
|
-
|
|
40
41
|
constructor (serviceInfoUrl, serviceCustomizations) {
|
|
41
|
-
this.
|
|
42
|
+
this._serviceInfo = null;
|
|
42
43
|
this._assets = null;
|
|
43
44
|
this._polling = false;
|
|
44
|
-
this.
|
|
45
|
+
this._serviceInfoUrl = serviceInfoUrl;
|
|
45
46
|
this._pryvServiceCustomizations = serviceCustomizations;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
50
|
* Return service info parameters info known of fetch it if needed.
|
|
50
|
-
* Example
|
|
51
|
-
* - name of a platform
|
|
52
|
-
* `const serviceName = await service.info().name`
|
|
53
|
-
* @see
|
|
51
|
+
* Example
|
|
52
|
+
* - name of a platform
|
|
53
|
+
* `const serviceName = await service.info().name`
|
|
54
|
+
* @see ServiceInfo For details on available properties.
|
|
54
55
|
* @param {boolean?} forceFetch If true, will force fetching service info.
|
|
55
|
-
* @returns {Promise<
|
|
56
|
+
* @returns {Promise<ServiceInfo>} Promise to Service info Object
|
|
56
57
|
*/
|
|
57
58
|
async info (forceFetch) {
|
|
58
|
-
if (forceFetch || !this.
|
|
59
|
+
if (forceFetch || !this._serviceInfo) {
|
|
59
60
|
let baseServiceInfo = {};
|
|
60
|
-
if (this.
|
|
61
|
-
const res = await utils.superagent.get(this.
|
|
61
|
+
if (this._serviceInfoUrl) {
|
|
62
|
+
const res = await utils.superagent.get(this._serviceInfoUrl).set('Access-Control-Allow-Origin', '*').set('accept', 'json');
|
|
62
63
|
baseServiceInfo = res.body;
|
|
63
64
|
}
|
|
64
65
|
Object.assign(baseServiceInfo, this._pryvServiceCustomizations);
|
|
65
66
|
this.setServiceInfo(baseServiceInfo);
|
|
66
67
|
}
|
|
67
|
-
return this.
|
|
68
|
+
return this._serviceInfo;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
/**
|
|
71
72
|
* @private
|
|
72
|
-
* @param {
|
|
73
|
+
* @param {ServiceInfo} serviceInfo
|
|
73
74
|
*/
|
|
74
75
|
setServiceInfo (serviceInfo) {
|
|
75
76
|
if (!serviceInfo.name) {
|
|
76
77
|
throw new Error('Invalid data from service/info');
|
|
77
78
|
}
|
|
78
|
-
// cleanup serviceInfo for eventual url not finishing by "/"
|
|
79
|
+
// cleanup serviceInfo for eventual url not finishing by "/"
|
|
79
80
|
// code will be obsolete with next version of register
|
|
80
81
|
['access', 'api', 'register'].forEach((key) => {
|
|
81
82
|
if (serviceInfo[key].slice(-1) !== '/') {
|
|
82
83
|
serviceInfo[key] += '/';
|
|
83
84
|
}
|
|
84
85
|
});
|
|
85
|
-
this.
|
|
86
|
+
this._serviceInfo = serviceInfo;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
/**
|
|
89
90
|
* Return assets property content
|
|
90
91
|
* @param {boolean?} forceFetch If true, will force fetching service info.
|
|
91
|
-
* @returns {Promise<ServiceAssets>} Promise to ServiceAssets
|
|
92
|
+
* @returns {Promise<ServiceAssets>} Promise to ServiceAssets
|
|
92
93
|
*/
|
|
93
94
|
async assets (forceFetch) {
|
|
94
95
|
if (!forceFetch && this._assets) {
|
|
@@ -106,17 +107,17 @@ class Service {
|
|
|
106
107
|
|
|
107
108
|
/**
|
|
108
109
|
* Return service info parameters info known or null if not yet loaded
|
|
109
|
-
* @returns {
|
|
110
|
+
* @returns {ServiceInfo} Service Info definition
|
|
110
111
|
*/
|
|
111
112
|
infoSync () {
|
|
112
|
-
return this.
|
|
113
|
+
return this._serviceInfo;
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
/**
|
|
116
117
|
* Return an API Endpoint from a username and token
|
|
117
118
|
* @param {string} username
|
|
118
119
|
* @param {string} [token]
|
|
119
|
-
* @return {
|
|
120
|
+
* @return {APIEndpoint}
|
|
120
121
|
*/
|
|
121
122
|
async apiEndpointFor (username, token) {
|
|
122
123
|
const serviceInfo = await this.info();
|
|
@@ -124,25 +125,25 @@ class Service {
|
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
/**
|
|
127
|
-
* Return an API Endpoint from a username and token and a
|
|
128
|
+
* Return an API Endpoint from a username and token and a ServiceInfo.
|
|
128
129
|
* This is method is rarely used. See **apiEndpointFor** as an alternative.
|
|
129
|
-
* @param {
|
|
130
|
+
* @param {ServiceInfo} serviceInfo
|
|
130
131
|
* @param {string} username
|
|
131
132
|
* @param {string} [token]
|
|
132
|
-
* @return {
|
|
133
|
+
* @return {APIEndpoint}
|
|
133
134
|
*/
|
|
134
135
|
static buildAPIEndpoint (serviceInfo, username, token) {
|
|
135
136
|
const endpoint = serviceInfo.api.replace('{username}', username);
|
|
136
|
-
return utils.
|
|
137
|
+
return utils.buildAPIEndpoint({ endpoint: endpoint, token: token });
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
/**
|
|
140
|
-
* Issue a "login call on the Service" return a Connection on success
|
|
141
|
+
* Issue a "login call on the Service" return a Connection on success
|
|
141
142
|
* **! Warning**: the token of the connection will be a "Personal" token that expires
|
|
142
143
|
* @see https://api.pryv.com/reference-full/#login-user
|
|
143
|
-
* @param {string} username
|
|
144
|
-
* @param {string} password
|
|
145
|
-
* @param {string} appId
|
|
144
|
+
* @param {string} username
|
|
145
|
+
* @param {string} password
|
|
146
|
+
* @param {string} appId
|
|
146
147
|
* @param {string} [originHeader=service-info.register] Only for Node.js. If not set will use the register value of service info. In browsers this will overridden by current page location.
|
|
147
148
|
* @throws {Error} on invalid login
|
|
148
149
|
*/
|
|
@@ -167,10 +168,11 @@ class Service {
|
|
|
167
168
|
this // Pre load Connection with service
|
|
168
169
|
);
|
|
169
170
|
} catch (e) {
|
|
170
|
-
if (e.response &&
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
if (e.response &&
|
|
172
|
+
e.response.body &&
|
|
173
|
+
e.response.body.error &&
|
|
174
|
+
e.response.body.error.message) {
|
|
175
|
+
throw new Error(e.response.body.error.message);
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
178
|
}
|
|
@@ -183,7 +185,7 @@ const Connection = require('./Connection');
|
|
|
183
185
|
|
|
184
186
|
/**
|
|
185
187
|
* Object to handle Pryv Service Informations https://api.pryv.com/reference/#service-info
|
|
186
|
-
* @typedef {Object}
|
|
188
|
+
* @typedef {Object} ServiceInfo
|
|
187
189
|
* @property {string} register The URL of the register service.
|
|
188
190
|
* @property {string} access The URL of the access page.
|
|
189
191
|
* @property {string} api The API endpoint format.
|
|
@@ -191,7 +193,7 @@ const Connection = require('./Connection');
|
|
|
191
193
|
* @property {string} home The URL of the platform's home page.
|
|
192
194
|
* @property {string} support The email or URL of the support page.
|
|
193
195
|
* @property {string} terms The terms and conditions, in plain text or the URL displaying them.
|
|
194
|
-
* @property {string}
|
|
196
|
+
* @property {string} eventTypes The URL of the list of validated event types.
|
|
195
197
|
* @property {Object} [assets] Holder for service specific Assets (icons, css, ...)
|
|
196
198
|
* @property {String} [assets.definitions] URL to json object with assets definitions
|
|
197
199
|
*/
|
package/src/ServiceAssets.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
|
+
*/
|
|
1
5
|
const utils = require('./utils.js');
|
|
6
|
+
|
|
7
|
+
/* global location */
|
|
8
|
+
|
|
2
9
|
/**
|
|
3
10
|
* Holds Pryv Service informations.
|
|
4
|
-
*
|
|
11
|
+
*
|
|
5
12
|
* It's returned by `service.assets()`
|
|
6
13
|
*
|
|
7
|
-
* @memberof
|
|
14
|
+
* @memberof pryv
|
|
8
15
|
**/
|
|
9
16
|
class ServiceAssets {
|
|
10
17
|
/**
|
|
@@ -12,7 +19,7 @@ class ServiceAssets {
|
|
|
12
19
|
* @param { object} assets The content of service/info.assets properties.
|
|
13
20
|
* @param { string } pryvServiceAssetsSourceUrl Url point to assets of the service of a Pryv platform: https://api.pryv.com/reference/#service-info property `assets.src`
|
|
14
21
|
*/
|
|
15
|
-
constructor(assets, assetsURL) {
|
|
22
|
+
constructor (assets, assetsURL) {
|
|
16
23
|
this._assets = assets;
|
|
17
24
|
this._assetsURL = assetsURL;
|
|
18
25
|
}
|
|
@@ -22,7 +29,7 @@ class ServiceAssets {
|
|
|
22
29
|
* @param {string} pryvServiceAssetsSourceUrl
|
|
23
30
|
* @returns {ServiceAssets}
|
|
24
31
|
*/
|
|
25
|
-
static async setup(pryvServiceAssetsSourceUrl) {
|
|
32
|
+
static async setup (pryvServiceAssetsSourceUrl) {
|
|
26
33
|
const res = await utils.superagent.get(pryvServiceAssetsSourceUrl).set('accept', 'json');
|
|
27
34
|
return new ServiceAssets(res.body, pryvServiceAssetsSourceUrl);
|
|
28
35
|
}
|
|
@@ -30,9 +37,9 @@ class ServiceAssets {
|
|
|
30
37
|
/**
|
|
31
38
|
* get a value from path separated by `:`
|
|
32
39
|
* exemple of key `lib-js:buttonSignIn`
|
|
33
|
-
* @param {string} [keyPath] if null, will return the all assets
|
|
40
|
+
* @param {string} [keyPath] if null, will return the all assets
|
|
34
41
|
*/
|
|
35
|
-
get(keyPath) {
|
|
42
|
+
get (keyPath) {
|
|
36
43
|
let result = Object.assign({}, this._assets);
|
|
37
44
|
if (keyPath) {
|
|
38
45
|
keyPath.split(':').forEach((key) => {
|
|
@@ -47,12 +54,12 @@ class ServiceAssets {
|
|
|
47
54
|
* get an Url from path separated by `:`
|
|
48
55
|
* identical to doing assets.relativeURL(assets.get(keyPath))
|
|
49
56
|
* exemple of key `lib-js:buttonSignIn`
|
|
50
|
-
* @param {string} [keyPath] if null, will return the all assets
|
|
57
|
+
* @param {string} [keyPath] if null, will return the all assets
|
|
51
58
|
*/
|
|
52
|
-
getUrl(keyPath) {
|
|
59
|
+
getUrl (keyPath) {
|
|
53
60
|
const url = this.get(keyPath);
|
|
54
61
|
if (typeof url !== 'string') {
|
|
55
|
-
throw new Error(
|
|
62
|
+
throw new Error(`Unexpected value for ${keyPath}: ${url}`);
|
|
56
63
|
}
|
|
57
64
|
return this.relativeURL(url);
|
|
58
65
|
}
|
|
@@ -60,16 +67,16 @@ class ServiceAssets {
|
|
|
60
67
|
/**
|
|
61
68
|
* get relativeUrl
|
|
62
69
|
*/
|
|
63
|
-
relativeURL(url) {
|
|
70
|
+
relativeURL (url) {
|
|
64
71
|
return relPathToAbs(this._assets.baseUrl || this._assetsURL, url);
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
// ---------------- Default service resources
|
|
75
|
+
|
|
69
76
|
/**
|
|
70
77
|
* Set all defaults Favicon, CSS
|
|
71
78
|
*/
|
|
72
|
-
async setAllDefaults() {
|
|
79
|
+
async setAllDefaults () {
|
|
73
80
|
this.setFavicon();
|
|
74
81
|
await this.loadCSS();
|
|
75
82
|
}
|
|
@@ -77,8 +84,8 @@ class ServiceAssets {
|
|
|
77
84
|
/**
|
|
78
85
|
* Set service Favicon to Web Page
|
|
79
86
|
*/
|
|
80
|
-
setFavicon() {
|
|
81
|
-
|
|
87
|
+
setFavicon () {
|
|
88
|
+
const link = document.querySelector("link[rel*='icon']") || document.createElement('link');
|
|
82
89
|
link.type = 'image/x-icon';
|
|
83
90
|
link.rel = 'shortcut icon';
|
|
84
91
|
link.href = this.relativeURL(this._assets.favicon.default.url);
|
|
@@ -88,40 +95,41 @@ class ServiceAssets {
|
|
|
88
95
|
/**
|
|
89
96
|
* Set default service CSS
|
|
90
97
|
*/
|
|
91
|
-
async loadCSS() {
|
|
98
|
+
async loadCSS () {
|
|
92
99
|
loadCSS(this.relativeURL(this._assets.css.default.url));
|
|
93
100
|
}
|
|
94
101
|
|
|
95
102
|
// ---- Login
|
|
96
103
|
|
|
97
104
|
/**
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
* Load CSS for Login button
|
|
106
|
+
*/
|
|
100
107
|
async loginButtonLoadCSS () {
|
|
101
108
|
loadCSS(this.relativeURL(this._assets['lib-js'].buttonSignIn.css));
|
|
102
109
|
}
|
|
103
110
|
|
|
104
111
|
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
async loginButtonGetHTML() {
|
|
112
|
+
* Get HTML for Login Button
|
|
113
|
+
*/
|
|
114
|
+
async loginButtonGetHTML () {
|
|
108
115
|
const res = await utils.superagent.get(this.relativeURL(this._assets['lib-js'].buttonSignIn.html)).set('accept', 'html');
|
|
109
116
|
return res.text;
|
|
110
117
|
}
|
|
111
118
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
async loginButtonGetMessages() {
|
|
119
|
+
/**
|
|
120
|
+
* Get Messages strings for Login Button
|
|
121
|
+
*/
|
|
122
|
+
async loginButtonGetMessages () {
|
|
116
123
|
const res = await utils.superagent.get(this.relativeURL(this._assets['lib-js'].buttonSignIn.messages)).set('accept', 'json');
|
|
117
124
|
return res.body;
|
|
118
125
|
}
|
|
119
|
-
|
|
120
126
|
}
|
|
121
127
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
module.exports = ServiceAssets;
|
|
129
|
+
|
|
130
|
+
function loadCSS (url) {
|
|
131
|
+
const head = document.getElementsByTagName('head')[0];
|
|
132
|
+
const link = document.createElement('link');
|
|
125
133
|
link.id = url;
|
|
126
134
|
link.rel = 'stylesheet';
|
|
127
135
|
link.type = 'text/css';
|
|
@@ -130,8 +138,11 @@ function loadCSS(url) {
|
|
|
130
138
|
head.appendChild(link);
|
|
131
139
|
}
|
|
132
140
|
|
|
141
|
+
/* HACK: disabling linting until code is cleaned up */
|
|
142
|
+
/* eslint-disable */
|
|
143
|
+
|
|
133
144
|
/*\
|
|
134
|
-
|*| Modified version of
|
|
145
|
+
|*| Modified version of
|
|
135
146
|
|*| :: translate relative paths to absolute paths ::
|
|
136
147
|
|*|
|
|
137
148
|
|*| https://developer.mozilla.org/en-US/docs/Web/API/document.cookie
|
|
@@ -154,9 +165,6 @@ function relPathToAbs (baseUrlString, sRelPath) {
|
|
|
154
165
|
sDir = (sDir + sPath.substring(nStart, nEnd)).replace(new RegExp("(?:\\\/+[^\\\/]*){0," + ((nUpLn - 1) / 3) + "}$"),
|
|
155
166
|
"/");
|
|
156
167
|
}
|
|
157
|
-
|
|
168
|
+
const portStr = baseLocation.port ? ':' + baseLocation.port : '';
|
|
158
169
|
return baseLocation.protocol + '//' + baseLocation.hostname + portStr + sDir + sPath.substr(nStart);
|
|
159
170
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
module.exports = ServiceAssets;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
|
+
*/
|
|
5
|
+
// make lib available as `Pryv` (with capital P, deprecated) for backward-compatibility with apps importing via <script>
|
|
6
|
+
// TODO: remove deprecated alias with next major version
|
|
7
|
+
module.exports = global.Pryv = require('./index');
|
package/src/index.d.ts
CHANGED
|
@@ -67,6 +67,7 @@ declare module 'pryv' {
|
|
|
67
67
|
createdBy: Identifier;
|
|
68
68
|
modified: Timestamp;
|
|
69
69
|
modifiedBy: Identifier;
|
|
70
|
+
apiEndpoint: string;
|
|
70
71
|
};
|
|
71
72
|
|
|
72
73
|
type FollowedSlice = {
|
|
@@ -168,7 +169,7 @@ declare module 'pryv' {
|
|
|
168
169
|
|
|
169
170
|
type EditMetadata = 'created' | 'createdBy' | 'modified' | 'modifiedBy';
|
|
170
171
|
|
|
171
|
-
export type
|
|
172
|
+
export type APICallMethods = {
|
|
172
173
|
// mfa
|
|
173
174
|
'mfa.challenge': {
|
|
174
175
|
params: null;
|
|
@@ -516,20 +517,20 @@ declare module 'pryv' {
|
|
|
516
517
|
) extends (k: infer I) => any
|
|
517
518
|
? I
|
|
518
519
|
: never;
|
|
519
|
-
type
|
|
520
|
-
type
|
|
521
|
-
NonNullable<
|
|
520
|
+
type APICallResultUnion = APICallMethods[keyof APICallMethods]['res'];
|
|
521
|
+
type APICallResultTypes = UnionToIntersection<
|
|
522
|
+
NonNullable<APICallResultUnion>
|
|
522
523
|
>;
|
|
523
524
|
|
|
524
525
|
type PossibleError = {
|
|
525
526
|
error?: Error;
|
|
526
527
|
};
|
|
527
528
|
|
|
528
|
-
type
|
|
529
|
-
|
|
529
|
+
type APICallResult<K extends keyof APICallMethods> =
|
|
530
|
+
APICallMethods[K]['res'] & PossibleError;
|
|
530
531
|
|
|
531
|
-
export type
|
|
532
|
-
result:
|
|
532
|
+
export type APICallResultHandler<K extends keyof APICallMethods> = (
|
|
533
|
+
result: APICallResult<K>,
|
|
533
534
|
) => Promise<any>;
|
|
534
535
|
export type StreamedEventsHandler = (event: Event) => void;
|
|
535
536
|
|
|
@@ -546,36 +547,36 @@ declare module 'pryv' {
|
|
|
546
547
|
export type EventFileCreationParams = Partial<
|
|
547
548
|
Omit<Event, 'attachments' | EditMetadata>
|
|
548
549
|
>;
|
|
549
|
-
export type
|
|
550
|
-
K extends keyof
|
|
550
|
+
export type APICall<K extends keyof APICallMethods = keyof APICallMethods> =
|
|
551
|
+
K extends keyof APICallMethods
|
|
551
552
|
? {
|
|
552
553
|
method: K;
|
|
553
|
-
params:
|
|
554
|
-
handleResult?:
|
|
554
|
+
params: APICallMethods[K]['params'];
|
|
555
|
+
handleResult?: APICallResultHandler<K>;
|
|
555
556
|
}
|
|
556
557
|
: never;
|
|
557
558
|
|
|
558
|
-
export type
|
|
559
|
+
export type TypedAPICallResult = APICallResultTypes & PossibleError;
|
|
559
560
|
|
|
560
|
-
export type
|
|
561
|
+
export type APICallProgressHandler = (percentage: number) => void;
|
|
561
562
|
|
|
562
563
|
interface AccessInfo extends Access {
|
|
563
564
|
calls: KeyValue;
|
|
564
565
|
user: KeyValue;
|
|
565
566
|
}
|
|
566
567
|
|
|
567
|
-
type
|
|
568
|
+
type EventAPICallRes = {
|
|
568
569
|
event?: Event;
|
|
569
570
|
} & PossibleError;
|
|
570
571
|
|
|
571
572
|
export interface Connection {
|
|
572
|
-
new (
|
|
573
|
+
new (apiEndpoint: string, service?: Service): Connection;
|
|
573
574
|
get service(): Service;
|
|
574
575
|
username(): Promise<string>;
|
|
575
|
-
api<Calls extends
|
|
576
|
+
api<Calls extends APICall[] = APICall[]>(
|
|
576
577
|
apiCalls: Calls,
|
|
577
|
-
res?:
|
|
578
|
-
): Promise<Array<
|
|
578
|
+
res?: APICallProgressHandler[],
|
|
579
|
+
): Promise<Array<TypedAPICallResult>>;
|
|
579
580
|
getEventsStreamed(
|
|
580
581
|
queryParams: Partial<EventQueryParamsStreamQuery>,
|
|
581
582
|
forEachEvent: StreamedEventsHandler,
|
|
@@ -583,16 +584,16 @@ declare module 'pryv' {
|
|
|
583
584
|
createEventWithFile(
|
|
584
585
|
params: EventFileCreationParams,
|
|
585
586
|
filePath: string | Buffer | Blob,
|
|
586
|
-
): Promise<
|
|
587
|
+
): Promise<EventAPICallRes>;
|
|
587
588
|
createEventWithFormData(
|
|
588
589
|
params: EventFileCreationParams,
|
|
589
590
|
formData: FormData,
|
|
590
|
-
): Promise<
|
|
591
|
+
): Promise<EventAPICallRes>;
|
|
591
592
|
createEventWithFileFromBuffer(
|
|
592
593
|
params: EventFileCreationParams,
|
|
593
|
-
bufferData: string | Buffer,
|
|
594
|
+
bufferData: string | Buffer | Blob,
|
|
594
595
|
filename: string,
|
|
595
|
-
): Promise<
|
|
596
|
+
): Promise<EventAPICallRes>;
|
|
596
597
|
addPointsToHFEvent(
|
|
597
598
|
id: Identifier,
|
|
598
599
|
fields: string[],
|
|
@@ -615,7 +616,7 @@ declare module 'pryv' {
|
|
|
615
616
|
};
|
|
616
617
|
};
|
|
617
618
|
|
|
618
|
-
export type
|
|
619
|
+
export type ServiceInfo = {
|
|
619
620
|
register: string;
|
|
620
621
|
access: string;
|
|
621
622
|
api: string;
|
|
@@ -625,6 +626,10 @@ declare module 'pryv' {
|
|
|
625
626
|
terms: string;
|
|
626
627
|
eventTypes: string;
|
|
627
628
|
version: string;
|
|
629
|
+
assets: {
|
|
630
|
+
definitions: string;
|
|
631
|
+
};
|
|
632
|
+
serial: string;
|
|
628
633
|
};
|
|
629
634
|
|
|
630
635
|
export type AssetsConfig = {
|
|
@@ -650,10 +655,10 @@ declare module 'pryv' {
|
|
|
650
655
|
serviceInfoUrl: string,
|
|
651
656
|
serviceCustomizations?: serviceCustomizations,
|
|
652
657
|
): Service;
|
|
653
|
-
info(forceFetch?: boolean): Promise<
|
|
654
|
-
setServiceInfo(serviceInfo: Partial<
|
|
658
|
+
info(forceFetch?: boolean): Promise<ServiceInfo>;
|
|
659
|
+
setServiceInfo(serviceInfo: Partial<ServiceInfo>): Promise<void>;
|
|
655
660
|
assets(forceFetch?: boolean): Promise<AssetsConfig>;
|
|
656
|
-
infoSync():
|
|
661
|
+
infoSync(): ServiceInfo | null;
|
|
657
662
|
apiEndpointFor(username: string, token: string): Promise<string>;
|
|
658
663
|
login(
|
|
659
664
|
username: string,
|
|
@@ -676,22 +681,6 @@ declare module 'pryv' {
|
|
|
676
681
|
| 'ACCEPTED'
|
|
677
682
|
| 'SIGNOUT';
|
|
678
683
|
|
|
679
|
-
type ServiceInfo = {
|
|
680
|
-
access: string;
|
|
681
|
-
api: string;
|
|
682
|
-
assets: {
|
|
683
|
-
definitions: string;
|
|
684
|
-
};
|
|
685
|
-
eventTypes: string;
|
|
686
|
-
home: string;
|
|
687
|
-
name: string;
|
|
688
|
-
register: string;
|
|
689
|
-
serial: string;
|
|
690
|
-
support: string;
|
|
691
|
-
terms: string;
|
|
692
|
-
version: string;
|
|
693
|
-
};
|
|
694
|
-
|
|
695
684
|
type StateChangeTypes = {
|
|
696
685
|
LOADING: {};
|
|
697
686
|
INITIALIZED: {
|
|
@@ -816,15 +805,15 @@ declare module 'pryv' {
|
|
|
816
805
|
serviceInfoFromUrl: getServiceInfoFromURL;
|
|
817
806
|
}
|
|
818
807
|
|
|
819
|
-
type
|
|
808
|
+
type TokenAndAPIEndpoint = {
|
|
820
809
|
endpoint: string;
|
|
821
810
|
token: string;
|
|
822
811
|
};
|
|
823
812
|
|
|
824
813
|
export interface utils {
|
|
825
814
|
isBrowser(): boolean;
|
|
826
|
-
|
|
827
|
-
|
|
815
|
+
extractTokenAndAPIEndpoint(apiEndpoint: string): TokenAndAPIEndpoint;
|
|
816
|
+
buildAPIEndpoint(tokenAndAPI: TokenAndAPIEndpoint): string;
|
|
828
817
|
browserIsMobileOrTablet(navigator: string): boolean;
|
|
829
818
|
cleanURLFromPrYvParams(url: string): string;
|
|
830
819
|
getQueryParamsFromURL(url: string): KeyValue;
|
|
@@ -832,7 +821,7 @@ declare module 'pryv' {
|
|
|
832
821
|
|
|
833
822
|
type version = string;
|
|
834
823
|
|
|
835
|
-
let
|
|
824
|
+
let pryv: {
|
|
836
825
|
Service: Service;
|
|
837
826
|
Connection: Connection;
|
|
838
827
|
Auth: Auth;
|
|
@@ -841,5 +830,5 @@ declare module 'pryv' {
|
|
|
841
830
|
version: version;
|
|
842
831
|
};
|
|
843
832
|
|
|
844
|
-
export default
|
|
833
|
+
export default pryv;
|
|
845
834
|
}
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* `pryv` library
|
|
7
|
+
* @exports pryv
|
|
8
|
+
* @property {pryv.Service} Service - To interact with Pryv.io at a "Platform level"
|
|
9
|
+
* @property {pryv.Connection} Connection - To interact with an individual's (user) data set
|
|
10
|
+
* @property {pryv.Browser} Browser - Browser Tools - Access request helpers and visuals (button)
|
|
11
|
+
* @property {pryv.utils} utils - Exposes **superagent** for HTTP calls and tools to manipulate Pryv's API Endpoints
|
|
12
|
+
*/
|
|
13
|
+
module.exports = {
|
|
14
|
+
Service: require('./Service'),
|
|
15
|
+
Connection: require('./Connection'),
|
|
16
|
+
Auth: require('./Auth'),
|
|
17
|
+
Browser: require('./Browser'),
|
|
18
|
+
utils: require('./utils'),
|
|
19
|
+
version: require('../package.json').version
|
|
20
|
+
};
|