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,72 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<title>Auth with redirection - Pryv JS lib</title>
|
|
6
|
-
<script src="../pryv.js"></script>
|
|
7
|
-
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
|
8
|
-
<meta content="utf-8" http-equiv="encoding">
|
|
9
|
-
</head>
|
|
10
|
-
|
|
11
|
-
<body>
|
|
12
|
-
<span id="pryv-button"></span>
|
|
13
|
-
<script>
|
|
14
|
-
let authSettings = {
|
|
15
|
-
spanButtonID: 'pryv-button', // span id the DOM that will be replaced by the Service specific button
|
|
16
|
-
onStateChange: function pryvAuthStateChange(state) { // called each time the authentication state changed
|
|
17
|
-
switch(state.id) {
|
|
18
|
-
case Pryv.Auth.AuthStates.LOADING:
|
|
19
|
-
console.log('Loading service information...');
|
|
20
|
-
break;
|
|
21
|
-
case Pryv.Auth.AuthStates.INITIALIZED:
|
|
22
|
-
console.log('Service information is retrieved so authorization can start. You can display login / registration screen or redirect to the our hosted app - web - auth application.');
|
|
23
|
-
break;
|
|
24
|
-
case Pryv.Auth.AuthStates.AUTHORIZED:
|
|
25
|
-
console.log('User is authorized and can access his personal data');
|
|
26
|
-
break;
|
|
27
|
-
case Pryv.Auth.AuthStates.SIGNOUT:
|
|
28
|
-
console.log('User just logged off, please delete all the session related data');
|
|
29
|
-
break;
|
|
30
|
-
case Pryv.Auth.AuthStates.ERROR:
|
|
31
|
-
console.log('Error:', state?.message);
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}, // event Listener for Authentication steps
|
|
35
|
-
authRequest: { // See: https://api.pryv.com/reference/#auth-request
|
|
36
|
-
requestingAppId: 'lib-js-test',
|
|
37
|
-
languageCode: 'fr', // optional (default english)
|
|
38
|
-
returnURL: 'auto#',
|
|
39
|
-
requestedPermissions: [{
|
|
40
|
-
streamId: 'test',
|
|
41
|
-
defaultName: 'Test',
|
|
42
|
-
level: 'read',
|
|
43
|
-
}],
|
|
44
|
-
// the login page where user will be redirected
|
|
45
|
-
returnURL: 'https://l.rec.la:9443/demos/auth-with-redirection.html#'
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const serviceInfoUrl = null; // 'https://api.pryv.com/lib-js/demos/service-info.json';
|
|
50
|
-
const serviceInfoJson = {
|
|
51
|
-
"register": "https://reg.pryv.me",
|
|
52
|
-
"access": "https://access.pryv.me/access",
|
|
53
|
-
"api": "https://{username}.pryv.me/",
|
|
54
|
-
"name": "Pryv Lab",
|
|
55
|
-
"home": "https://www.pryv.com",
|
|
56
|
-
"support": "https://pryv.com/helpdesk",
|
|
57
|
-
"terms": "https://pryv.com/pryv-lab-terms-of-use/",
|
|
58
|
-
"eventTypes": "https://api.pryv.com/event-types/flat.json",
|
|
59
|
-
"assets": {
|
|
60
|
-
"definitions": "https://pryv.github.io/assets-pryv.me/index.json"
|
|
61
|
-
}};
|
|
62
|
-
(async function () {
|
|
63
|
-
let service = await Pryv.Auth.setupAuth(
|
|
64
|
-
authSettings,
|
|
65
|
-
serviceInfoUrl,
|
|
66
|
-
serviceInfoJson
|
|
67
|
-
);
|
|
68
|
-
})();
|
|
69
|
-
</script>
|
|
70
|
-
</body>
|
|
71
|
-
|
|
72
|
-
</html>
|
package/web-demos/auth.html
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<title>Auth - Pryv JS lib</title>
|
|
6
|
-
<script src="../pryv.js"></script>
|
|
7
|
-
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
|
8
|
-
<meta content="utf-8" http-equiv="encoding">
|
|
9
|
-
</head>
|
|
10
|
-
|
|
11
|
-
<body>
|
|
12
|
-
<span id="pryv-button"></span>
|
|
13
|
-
<script>
|
|
14
|
-
const authSettings = {
|
|
15
|
-
spanButtonID: 'pryv-button', // span id the DOM that will be replaced by the Service specific button
|
|
16
|
-
onStateChange: function pryvAuthStateChange(state) { // called each time the authentication state changed
|
|
17
|
-
switch(state.id) {
|
|
18
|
-
case Pryv.Auth.AuthStates.LOADING:
|
|
19
|
-
console.log('Loading service information...');
|
|
20
|
-
break;
|
|
21
|
-
case Pryv.Auth.AuthStates.INITIALIZED:
|
|
22
|
-
console.log('Service information is retrieved so authorization can start. You can display login / registration screen or redirect to the our hosted app - web - auth application.');
|
|
23
|
-
break;
|
|
24
|
-
case Pryv.Auth.AuthStates.AUTHORIZED:
|
|
25
|
-
console.log('User is authorized and can access his personal data');
|
|
26
|
-
break;
|
|
27
|
-
case Pryv.Auth.AuthStates.SIGNOUT:
|
|
28
|
-
console.log('User just logged off, please delete all the session related data');
|
|
29
|
-
break;
|
|
30
|
-
case Pryv.Auth.AuthStates.ERROR:
|
|
31
|
-
console.log('Error:', state?.message);
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}, // event Listener for Authentication steps
|
|
35
|
-
authRequest: { // See: https://api.pryv.com/reference/#auth-request
|
|
36
|
-
requestingAppId: 'lib-js-test',
|
|
37
|
-
requestedPermissions: [
|
|
38
|
-
{
|
|
39
|
-
streamId: 'test',
|
|
40
|
-
defaultName: 'test',
|
|
41
|
-
level: 'manage'
|
|
42
|
-
}
|
|
43
|
-
],
|
|
44
|
-
clientData: {
|
|
45
|
-
'app-web-auth:description': {
|
|
46
|
-
'type': 'note/txt',
|
|
47
|
-
'content': 'This is a consent message.'
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
// referer: 'my test with lib-js', // optional string to track registration source
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const serviceInfoUrl = null;// 'https://api.pryv.com/lib-js/demos/service-info.json';
|
|
55
|
-
const serviceInfoJson = {
|
|
56
|
-
"register": "https://reg.pryv.me",
|
|
57
|
-
"access": "https://access.pryv.me/access",
|
|
58
|
-
"api": "https://{username}.pryv.me/",
|
|
59
|
-
"name": "Pryv Lab",
|
|
60
|
-
"home": "https://www.pryv.com",
|
|
61
|
-
"support": "https://pryv.com/helpdesk",
|
|
62
|
-
"terms": "https://pryv.com/pryv-lab-terms-of-use/",
|
|
63
|
-
"eventTypes": "https://api.pryv.com/event-types/flat.json",
|
|
64
|
-
"assets": {
|
|
65
|
-
"definitions": "https://pryv.github.io/assets-pryv.me/index.json"
|
|
66
|
-
}};
|
|
67
|
-
(async function () {
|
|
68
|
-
service = await Pryv.Auth.setupAuth(
|
|
69
|
-
authSettings,
|
|
70
|
-
serviceInfoUrl,
|
|
71
|
-
serviceInfoJson
|
|
72
|
-
);
|
|
73
|
-
})();
|
|
74
|
-
</script>
|
|
75
|
-
</body>
|
|
76
|
-
|
|
77
|
-
</html>
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<title>Custom Login button - Pryv JS lib</title>
|
|
6
|
-
<script src="../pryv.js"></script>
|
|
7
|
-
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
|
8
|
-
<meta content="utf-8" http-equiv="encoding">
|
|
9
|
-
</head>
|
|
10
|
-
|
|
11
|
-
<body>
|
|
12
|
-
<button type="button" id="pryv-button">My custom button</button>
|
|
13
|
-
<script>
|
|
14
|
-
const authSettings = {
|
|
15
|
-
spanButtonID: 'pryv-button', // span id the DOM that will be replaced by the Service specific button
|
|
16
|
-
authRequest: { // See: https://api.pryv.com/reference/#auth-request
|
|
17
|
-
requestingAppId: 'custom-login-button-example',
|
|
18
|
-
requestedPermissions: [
|
|
19
|
-
{
|
|
20
|
-
streamId: 'test',
|
|
21
|
-
defaultName: 'test',
|
|
22
|
-
level: 'manage'
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
class MyLoginButton {
|
|
29
|
-
|
|
30
|
-
constructor(authSettings, service) {
|
|
31
|
-
this.authSettings = authSettings;
|
|
32
|
-
this.service = service;
|
|
33
|
-
this.serviceInfo = service.infoSync();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async init() {
|
|
37
|
-
const loginButtonSpan = document.getElementById(this.authSettings.spanButtonID);
|
|
38
|
-
loginButtonSpan.addEventListener('click', this.onClick.bind(this));
|
|
39
|
-
this.loginButtonSpan = loginButtonSpan;
|
|
40
|
-
|
|
41
|
-
this._cookieKey = 'pryv-libjs-' + this.authSettings.authRequest.requestingAppId;
|
|
42
|
-
|
|
43
|
-
this.auth = new Pryv.Auth.AuthController(this.authSettings, this.service, this);
|
|
44
|
-
await this.auth.init();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
onClick() {
|
|
48
|
-
this.auth.handleClick();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async onStateChange (state) {
|
|
52
|
-
switch (state.status) {
|
|
53
|
-
case Pryv.Auth.AuthStates.LOADING:
|
|
54
|
-
this.text = 'Loading visual assets';
|
|
55
|
-
break;
|
|
56
|
-
case Pryv.Auth.AuthStates.INITIALIZED:
|
|
57
|
-
this.text = 'Sign into: ' + this.serviceInfo.name;
|
|
58
|
-
break;
|
|
59
|
-
case Pryv.Auth.AuthStates.NEED_SIGNIN:
|
|
60
|
-
const loginUrl = state.authUrl || state.url; // .url is deprecated
|
|
61
|
-
if (this.authSettings.authRequest.returnURL) { // open on same page (no Popup)
|
|
62
|
-
location.href = loginUrl;
|
|
63
|
-
return;
|
|
64
|
-
} else {
|
|
65
|
-
startLoginScreen(this, loginUrl);
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
case Pryv.Auth.AuthStates.AUTHORIZED:
|
|
69
|
-
this.text = 'Signed in as ' + state.username;
|
|
70
|
-
this.saveAuthorizationData({
|
|
71
|
-
apiEndpoint: state.apiEndpoint,
|
|
72
|
-
username: state.username
|
|
73
|
-
});
|
|
74
|
-
break;
|
|
75
|
-
case Pryv.Auth.AuthStates.SIGNOUT:
|
|
76
|
-
const message = 'Do you wish to sign out?';
|
|
77
|
-
if (confirm(message)) {
|
|
78
|
-
this.deleteAuthorizationData();
|
|
79
|
-
this.auth.init();
|
|
80
|
-
}
|
|
81
|
-
break;
|
|
82
|
-
case Pryv.Auth.AuthStates.ERROR:
|
|
83
|
-
this.text = getErrorMessage(this, state.message);
|
|
84
|
-
break;
|
|
85
|
-
default:
|
|
86
|
-
console.log('WARNING Unhandled state for Login: ' + state.status);
|
|
87
|
-
}
|
|
88
|
-
if (this.loginButtonSpan) {
|
|
89
|
-
this.loginButtonSpan.innerHTML = this.text;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
saveAuthorizationData(authData) {
|
|
94
|
-
console.log('You should save this object to the storage', authData);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
getAuthorizationData() {
|
|
98
|
-
return Pryv.Browser.CookieUtils.get(this._cookieKey);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async deleteAuthorizationData() {
|
|
102
|
-
console.log('You should delete saved data from the storage');
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function startLoginScreen(loginButton, authUrl) {
|
|
107
|
-
console.log('My custom popup that is huge:');
|
|
108
|
-
let screenX = typeof window.screenX !== 'undefined' ? window.screenX : window.screenLeft,
|
|
109
|
-
screenY = typeof window.screenY !== 'undefined' ? window.screenY : window.screenTop,
|
|
110
|
-
outerWidth = typeof window.outerWidth !== 'undefined' ?
|
|
111
|
-
window.outerWidth : document.body.clientWidth,
|
|
112
|
-
outerHeight = typeof window.outerHeight !== 'undefined' ?
|
|
113
|
-
window.outerHeight : (document.body.clientHeight - 22),
|
|
114
|
-
width = 900,
|
|
115
|
-
height = 500,
|
|
116
|
-
left = parseInt(screenX + ((outerWidth - width) / 2), 10),
|
|
117
|
-
top = parseInt(screenY + ((outerHeight - height) / 2.5), 10),
|
|
118
|
-
features = (
|
|
119
|
-
'width=' + width +
|
|
120
|
-
',height=' + height +
|
|
121
|
-
',left=' + left +
|
|
122
|
-
',top=' + top +
|
|
123
|
-
',scrollbars=yes'
|
|
124
|
-
);
|
|
125
|
-
loginButton.popup = window.open(authUrl, 'Your custom Sign-in pop-up', features);
|
|
126
|
-
|
|
127
|
-
if (!loginButton.popup) {
|
|
128
|
-
console.log('Pop-up blocked. A second click should allow it.');
|
|
129
|
-
} else if (window.focus) {
|
|
130
|
-
loginButton.popup.focus();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const serviceInfoUrl = null; // 'https://api.pryv.com/lib-js/demos/service-info.json';
|
|
135
|
-
const serviceInfoJson = {
|
|
136
|
-
"register": "https://reg.pryv.me",
|
|
137
|
-
"access": "https://access.pryv.me/access",
|
|
138
|
-
"api": "https://{username}.pryv.me/",
|
|
139
|
-
"name": "Pryv Lab",
|
|
140
|
-
"home": "https://www.pryv.com",
|
|
141
|
-
"support": "https://pryv.com/helpdesk",
|
|
142
|
-
"terms": "https://pryv.com/pryv-lab-terms-of-use/",
|
|
143
|
-
"eventTypes": "https://api.pryv.com/event-types/flat.json",
|
|
144
|
-
"assets": {
|
|
145
|
-
"definitions": "https://pryv.github.io/assets-pryv.me/index.json"
|
|
146
|
-
}};
|
|
147
|
-
(async function () {
|
|
148
|
-
let service = await Pryv.Auth.setupAuth(
|
|
149
|
-
authSettings,
|
|
150
|
-
serviceInfoUrl,
|
|
151
|
-
serviceInfoJson,
|
|
152
|
-
MyLoginButton,
|
|
153
|
-
);
|
|
154
|
-
})();
|
|
155
|
-
</script>
|
|
156
|
-
</body>
|
|
157
|
-
|
|
158
|
-
</html>
|
package/web-demos/index.html
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<title>Pryv - Javascript Lib</title>
|
|
6
|
-
<script src="../pryv.js"></script>
|
|
7
|
-
</head>
|
|
8
|
-
|
|
9
|
-
<body>
|
|
10
|
-
<h1>Pryv value form</h1>
|
|
11
|
-
|
|
12
|
-
<p>This example lets the user sign in then enter notes and values.</p>
|
|
13
|
-
|
|
14
|
-
<p>
|
|
15
|
-
<span id="pryv-button"></span> <strong>⇠ sign in here</strong><br>
|
|
16
|
-
</p>
|
|
17
|
-
|
|
18
|
-
<h5>Notes</h5>
|
|
19
|
-
<input type='text' id='create-note' placeholder='Content' value='' />
|
|
20
|
-
<button onClick='createNoteEvent()'>Save Note</button>
|
|
21
|
-
|
|
22
|
-
<h5>Numerical Value</h5>
|
|
23
|
-
<input type='text' id='create-value' placeholder='Content' value='' />
|
|
24
|
-
<button onClick='createValueEvent()'>Save Value</button>
|
|
25
|
-
|
|
26
|
-
<h5>Upload File</h5>
|
|
27
|
-
<input type="file" id="create-file" >
|
|
28
|
-
<button onClick='uploadFile()'>Save Value</button>
|
|
29
|
-
|
|
30
|
-
<h3>Events</h3>
|
|
31
|
-
<textarea id='events'></textarea>
|
|
32
|
-
|
|
33
|
-
<div class="clearfix"></div>
|
|
34
|
-
<h3>Console</h3>
|
|
35
|
-
<textarea id='console'></textarea>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
</body>
|
|
39
|
-
|
|
40
|
-
<script>
|
|
41
|
-
|
|
42
|
-
// will handle the connection
|
|
43
|
-
var connection = null;
|
|
44
|
-
|
|
45
|
-
var serviceCustomizations = {
|
|
46
|
-
assets: {
|
|
47
|
-
definitions: 'https://pryv.github.io/assets-pryv.me/index.json'
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
let serviceInfoUrl = 'https://reg.pryv.me/service/infos';
|
|
52
|
-
// override serviceInfo if provided in the url.
|
|
53
|
-
serviceInfoUrl = Pryv.Browser.serviceInfoFromUrl() || serviceInfoUrl;
|
|
54
|
-
|
|
55
|
-
var authSettings = {
|
|
56
|
-
spanButtonID: 'pryv-button',
|
|
57
|
-
onStateChange: pryvAuthStateChange,
|
|
58
|
-
authRequest: { // See: http://api.pryv.com/reference/#auth-request
|
|
59
|
-
languageCode: 'fr',
|
|
60
|
-
requestingAppId: 'test-value-notes',
|
|
61
|
-
requestedPermissions: [
|
|
62
|
-
{
|
|
63
|
-
streamId: 'test',
|
|
64
|
-
defaultName: 'test',
|
|
65
|
-
level: 'manage'
|
|
66
|
-
}
|
|
67
|
-
],
|
|
68
|
-
clientData: {
|
|
69
|
-
'app-web-auth:description': {
|
|
70
|
-
'type': 'note/txt', 'content': 'This is a consent message.'
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var $console = document.getElementById('console'),
|
|
78
|
-
$events = document.getElementById('events'),
|
|
79
|
-
$noteContent = document.getElementById('create-note'),
|
|
80
|
-
$valueContent = document.getElementById('create-value'),
|
|
81
|
-
$fileContent = document.getElementById('create-file')
|
|
82
|
-
;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
(async function () {
|
|
86
|
-
const service = await Pryv.Auth.setupAuth(authSettings, serviceInfoUrl, serviceCustomizations);
|
|
87
|
-
(await service.assets()).setAllDefaults();
|
|
88
|
-
})();
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
function pryvAuthStateChange(state) {
|
|
92
|
-
console.log('##pryvAuthStateChange', state);
|
|
93
|
-
if (state.id === Pryv.Auth.AuthStates.AUTHORIZED) {
|
|
94
|
-
connection = new Pryv.Connection(state.apiEndpoint);
|
|
95
|
-
logToConsole('# Browser succeeded for user ' + connection.apiEndpoint);
|
|
96
|
-
}
|
|
97
|
-
if (state.id === Pryv.Auth.AuthStates.SIGNOUT) {
|
|
98
|
-
connection = null;
|
|
99
|
-
logToConsole('# Logout');
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// Handle local user actions
|
|
105
|
-
|
|
106
|
-
function createNoteEvent() {
|
|
107
|
-
createEvent({
|
|
108
|
-
streamId: 'test',
|
|
109
|
-
type: 'note/txt',
|
|
110
|
-
content: $noteContent.value
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
function createValueEvent() {
|
|
116
|
-
createEvent({
|
|
117
|
-
streamId: 'test',
|
|
118
|
-
type: 'count/generic',
|
|
119
|
-
content: $valueContent.value
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
function uploadFile() {
|
|
125
|
-
console.log($fileContent.files);
|
|
126
|
-
if (!$fileContent.files[0]) {
|
|
127
|
-
alert('Choose a file first');
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
const formData = new FormData();
|
|
131
|
-
formData.append('file0', $fileContent.files[0]);
|
|
132
|
-
connection.createEventWithFormData(
|
|
133
|
-
{ type: 'file/attached', streamId: 'test' },
|
|
134
|
-
formData
|
|
135
|
-
).then(function (res, err) {
|
|
136
|
-
if (err) { return logToConsole('...error: ' + JSON.stringify(err)); }
|
|
137
|
-
logToConsole('...event created: ' + JSON.stringify(res));
|
|
138
|
-
getLastEvents();
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function createEvent(data) {
|
|
143
|
-
if (!connection) { return alert('Please sign in first.'); }
|
|
144
|
-
logToConsole('Creating event...');
|
|
145
|
-
var data = [{
|
|
146
|
-
method: 'events.create',
|
|
147
|
-
params: data
|
|
148
|
-
}];
|
|
149
|
-
connection.api(data).then(function (res, err) {
|
|
150
|
-
if (err) { return logToConsole('...error: ' + JSON.stringify(err)); }
|
|
151
|
-
logToConsole('...event created: ' + JSON.stringify(res));
|
|
152
|
-
getLastEvents();
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// UTILS
|
|
157
|
-
// Retrieve last events
|
|
158
|
-
function getLastEvents() {
|
|
159
|
-
var data = [{
|
|
160
|
-
method: 'events.get',
|
|
161
|
-
params: {
|
|
162
|
-
limit: 20
|
|
163
|
-
}
|
|
164
|
-
}];
|
|
165
|
-
connection.api(data).then(function (res, err) {
|
|
166
|
-
// convert pryv.Event objects to plain data for display
|
|
167
|
-
display(res[0].events, $events);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function logToConsole(text) {
|
|
172
|
-
$console.value += text + '\n';
|
|
173
|
-
$console.scrollTop = $console.scrollHeight;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function display(obj, $textArea) {
|
|
177
|
-
$textArea.value = JSON.stringify(obj, null, 2);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
</script>
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
</html>
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"register": "https://reg.pryv.me",
|
|
3
|
-
"access": "https://access.pryv.me/access",
|
|
4
|
-
"api": "https://{username}.pryv.me/",
|
|
5
|
-
"name": "Pryv Lab",
|
|
6
|
-
"home": "https://www.pryv.com",
|
|
7
|
-
"support": "https://pryv.com/helpdesk",
|
|
8
|
-
"terms": "https://pryv.com/pryv-lab-terms-of-use/",
|
|
9
|
-
"eventTypes": "https://api.pryv.com/event-types/flat.json",
|
|
10
|
-
"assets": {
|
|
11
|
-
"definitions": "https://pryv.github.io/assets-pryv.me/index.json"
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<title>Pryv - Javascript Lib Stream Example</title>
|
|
6
|
-
<script src="../pryv.js"></script>
|
|
7
|
-
</head>
|
|
8
|
-
<style>
|
|
9
|
-
body {
|
|
10
|
-
font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
h3 {
|
|
14
|
-
margin: 1.5em 0 0;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
h5 {
|
|
18
|
-
margin: 1em 0 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
textarea {
|
|
22
|
-
width: 100%;
|
|
23
|
-
height: 20em;
|
|
24
|
-
}
|
|
25
|
-
</style>
|
|
26
|
-
|
|
27
|
-
<body>
|
|
28
|
-
<h1>Pryv stream events</h1>
|
|
29
|
-
|
|
30
|
-
<h5>Actions</h5>
|
|
31
|
-
<button onClick='getStreamEvents()'>StreamEvents</button>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<div class="clearfix"></div>
|
|
35
|
-
<h3>Console</h3>
|
|
36
|
-
<textarea id='console'></textarea>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
</body>
|
|
40
|
-
|
|
41
|
-
<script>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var $console = document.getElementById('console');
|
|
45
|
-
|
|
46
|
-
const apiEndpoint = 'https://ck60yn9yv00011hd3vu1ocpi7@jslibtest.pryv.me';
|
|
47
|
-
// will handle the connection
|
|
48
|
-
var connection = new Pryv.Connection(apiEndpoint);;
|
|
49
|
-
|
|
50
|
-
function getStreamEvents() {
|
|
51
|
-
var params = { limit: 10000 };
|
|
52
|
-
|
|
53
|
-
function foreachEvent(event) {
|
|
54
|
-
// logToConsole(JSON.stringify(event));
|
|
55
|
-
console.log('.');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
connection.getEventsStreamed(params, foreachEvent).then(function (res, err) {
|
|
59
|
-
logToConsole('*** DONE ****: ' + JSON.stringify(res));
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
function logToConsole(text) {
|
|
66
|
-
$console.value += text + '\n';
|
|
67
|
-
$console.scrollTop = $console.scrollHeight;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function display(obj, $textArea) {
|
|
71
|
-
$textArea.value = JSON.stringify(obj, null, 2);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
</script>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
</html>
|
package/webpack.config.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const webpack = require('webpack');
|
|
3
|
-
const CopyPlugin = require('copy-webpack-plugin');
|
|
4
|
-
const { webpackBabelConfig } = require('@pryv/lib-js-common');
|
|
5
|
-
|
|
6
|
-
module.exports = [
|
|
7
|
-
{ // es6 version
|
|
8
|
-
mode: 'production',
|
|
9
|
-
entry: {
|
|
10
|
-
'pryv': ['./src/index.js'],
|
|
11
|
-
},
|
|
12
|
-
output: {
|
|
13
|
-
filename: '[name]-es6.js',
|
|
14
|
-
path: path.resolve(__dirname, 'dist'),
|
|
15
|
-
libraryTarget: 'var',
|
|
16
|
-
library: 'Pryv'
|
|
17
|
-
},
|
|
18
|
-
plugins: [
|
|
19
|
-
new CopyPlugin({ patterns: [
|
|
20
|
-
{ from: 'web-demos', to: 'demos' },
|
|
21
|
-
]})],
|
|
22
|
-
devtool: 'source-map',
|
|
23
|
-
},
|
|
24
|
-
{ // es5 version
|
|
25
|
-
mode: 'production',
|
|
26
|
-
entry: {
|
|
27
|
-
'pryv': ['./src/index.js'],
|
|
28
|
-
},
|
|
29
|
-
output: {
|
|
30
|
-
filename: '[name].js',
|
|
31
|
-
path: path.resolve(__dirname, 'dist'),
|
|
32
|
-
libraryTarget: 'var',
|
|
33
|
-
library: 'Pryv'
|
|
34
|
-
},
|
|
35
|
-
devtool: 'source-map',
|
|
36
|
-
module: webpackBabelConfig
|
|
37
|
-
},
|
|
38
|
-
{ // es5 version including socket.io and monitors
|
|
39
|
-
mode: 'production',
|
|
40
|
-
entry: {
|
|
41
|
-
'pryv-socket.io-monitor': ['./src/index-socket.io-monitor.js'],
|
|
42
|
-
},
|
|
43
|
-
output: {
|
|
44
|
-
filename: '[name].js',
|
|
45
|
-
path: path.resolve(__dirname, 'dist'),
|
|
46
|
-
libraryTarget: 'var',
|
|
47
|
-
library: 'Pryv'
|
|
48
|
-
},
|
|
49
|
-
devtool: 'source-map',
|
|
50
|
-
module: webpackBabelConfig,
|
|
51
|
-
resolve: {
|
|
52
|
-
fallback: {
|
|
53
|
-
'fs': false,
|
|
54
|
-
'path': false,
|
|
55
|
-
},
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
{ // browser test suite (es6)
|
|
59
|
-
mode: 'development',
|
|
60
|
-
entry: {
|
|
61
|
-
'browser-tests': './test/browser-index.js',
|
|
62
|
-
},
|
|
63
|
-
output: {
|
|
64
|
-
filename: '[name].js',
|
|
65
|
-
path: path.resolve(__dirname, 'dist/tests/'),
|
|
66
|
-
libraryTarget: 'var',
|
|
67
|
-
library: 'browserTest'
|
|
68
|
-
},
|
|
69
|
-
plugins: [
|
|
70
|
-
new webpack.IgnorePlugin({resourceRegExp: /zombie/}),
|
|
71
|
-
new CopyPlugin({ patterns: [
|
|
72
|
-
{ from: 'test/browser-tests.html' },
|
|
73
|
-
]})
|
|
74
|
-
],
|
|
75
|
-
devtool: 'source-map',
|
|
76
|
-
resolve: {
|
|
77
|
-
fallback: {
|
|
78
|
-
'fs': false,
|
|
79
|
-
'path': false,
|
|
80
|
-
},
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
];
|