pryv 2.2.0 → 2.3.0
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/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 +36 -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/README.md +0 -742
- 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/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
|
-
];
|