@pryv/monitor 1.0.6 → 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.
@@ -1,231 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <!--
4
- This file is moved in dist/ during build process.
5
- It should be opened in the same directory than pryv-monitor.js built
6
- -->
7
- <head>
8
- <meta charset="UTF-8" />
9
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
10
- <meta http-equiv="X-UA-Compatible" content="ie=edge" />
11
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
12
- integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
13
- <link rel="stylesheet" type="text/css" href="https://api.pryv.com/style/pryv.min.css">
14
- <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400">
15
-
16
- <title>Pryv Monitor - Javascript</title>
17
- <script src="https://api.pryv.com/lib-js/pryv.js"></script>
18
- <script src="https://api.pryv.com/lib-js-socket.io/pryv-socket.io.js"></script>
19
- <script src="pryv-monitor.js"></script>
20
- </head>
21
-
22
- <body>
23
- <div class="container">
24
- <h1>Monitor - Pryv Examples</h1>
25
- <span id="pryv-button"></span>
26
- <br>
27
- This example illustrates the creation, update and deletion of events as well as the monitoring of data changes (i.e.
28
- real time updates). You can open a second page of this fiddle and verify that actions on either page are reflected on
29
- the other.
30
-
31
- <div class="card">
32
- <div class="card-body">
33
- <h2 class="card-title">Actions</h2>
34
- <h5>Create</h5>
35
- <input type='text' id='create-content' placeholder='Content' value='Example content' />
36
- <button onClick='createNoteEvent()'>Create note event</button>
37
-
38
- <h5>Update</h5>
39
- <input type='text' id='update-id' placeholder='Event id' value='' />
40
- <input type='text' id='update-content' placeholder='Updated content' value='Updated example content' />
41
- <button onClick='updateNoteEvent()'>Update event</button>
42
-
43
- <h5>Delete</h5>
44
- <input type='text' id='delete-id' placeholder='Event id' value='' />
45
- <button onClick='deleteNoteEvent()'>Trash event (2x to delete)</button>
46
- </div>
47
- </div>
48
- <table width=100%>
49
- <tr>
50
- <td>
51
- <div class="card">
52
- <div class="card-body">
53
- <h2 class="card-title">Console</h2>
54
- <textarea id='console' cols=45 rows=20></textarea>
55
- </div>
56
- </td>
57
- <td>
58
- <div class="card">
59
- <div class="card-body">
60
- <h2 class="card-title">Monitor Events</h2>
61
- <textarea id='monitor-console' cols=45 rows=20></textarea>
62
- </div>
63
- </div>
64
- </td>
65
- </tr>
66
- </table>
67
- <br>
68
- <small>Source code of this demo app on <a
69
- href="https://github.com/pryv/lib-js-monitor.io/blob/master/examples/index.html">GitHub</a></small>
70
- </div>
71
- </body>
72
-
73
- <script>
74
- // --- usual boiler plate
75
-
76
- //-- UI Elements
77
- var $createContent = document.getElementById('create-content'),
78
- $updateId = document.getElementById('update-id'),
79
- $updateContent = document.getElementById('update-content'),
80
- $deleteId = document.getElementById('delete-id'),
81
- $console = document.getElementById('console'),
82
- $monitorConsole = document.getElementById('monitor-console');
83
-
84
- //-- Connection will be updated upon login
85
- var connection = null;
86
-
87
- var authSettings = {
88
- spanButtonID: 'pryv-button', // span id the DOM that will be replaced by the Service specific button
89
- onStateChange: pryvAuthStateChange, // event Listener for Authentication steps
90
- authRequest: { // See: https://api.pryv.com/reference/#auth-request
91
- requestingAppId: 'lib-js-monitor',
92
- languageCode: 'en', // optional (default english)
93
- requestedPermissions: [
94
- {
95
- streamId: 'test',
96
- defaultName: 'Test',
97
- level: 'manage'
98
- }
99
- ],
100
- clientData: {
101
- 'app-web-auth:description': {
102
- 'type': 'note/txt', 'content': 'I\'m monitoring changes, creating, updating and deleting notes in test.'
103
- }
104
- }
105
- }
106
- };
107
-
108
- function pryvAuthStateChange(state) { // called each time the authentication state changed
109
- logToConsole('##pryvAuthStateChange ' + state.id);
110
- if (state.id === Pryv.Browser.AuthStates.AUTHORIZED) {
111
- connection = new Pryv.Connection(state.apiEndpoint);
112
- logToConsole('# Auth succeeded for user ' + connection.apiEndpoint);
113
- initializeMonitor();
114
- }
115
- if (state.id === Pryv.Browser.AuthStates.LOGOUT) {
116
- connection = null;
117
- logToConsole('# Logout');
118
- closeMonitor();
119
- }
120
- }
121
-
122
- function resToJSON(res) {
123
- if (res.error || (res.event == null)) {
124
- if (res.eventDeletion == null)
125
- return "Error: " + JSON.stringify(res);
126
- return res.eventDeletion.id;
127
- }
128
- return res.event.id;
129
- }
130
-
131
- async function createNoteEvent() {
132
- if (connection == null) { return alert('Please sign in first.'); }
133
- const res = await connection.api([{
134
- method: 'events.create',
135
- params: {
136
- streamId: 'test',
137
- type: 'note/txt',
138
- content: $createContent.value
139
- }
140
- }]);
141
- logToConsole('# ACTION Creating event: ' + resToJSON(res[0]));
142
- }
143
-
144
- async function updateNoteEvent() {
145
- if (!connection) { return alert('Please sign in first.'); }
146
- const res = await connection.api([{
147
- method: 'events.update',
148
- params: {
149
- id: $updateId.value,
150
- update: {
151
- content: $updateContent.value
152
- }
153
- }
154
- }]);
155
- logToConsole('# ACTION Updating event: ' + resToJSON(res[0]));
156
- }
157
-
158
- async function deleteNoteEvent() {
159
- if (!connection) { return alert('Please sign in first.'); }
160
- const res = await connection.api([{
161
- method: 'events.delete',
162
- params: {
163
- id: $deleteId.value,
164
- }
165
- }]);
166
- logToConsole('# ACTION Deleting event: ' + resToJSON(res[0]));
167
- }
168
-
169
- function logToConsole(text) {
170
- $console.value += text + '\n';
171
- $console.scrollTop = $console.scrollHeight;
172
- }
173
-
174
- function logToMonitor(text) {
175
- $monitorConsole.value += text + '\n';
176
- $monitorConsole.scrollTop = $console.scrollHeight;
177
- }
178
-
179
- // following the APP GUIDELINES: https://api.pryv.com/guides/app-guidelines/
180
- (async function () {
181
- const serviceInfoUrl = Pryv.Browser.serviceInfoFromUrl() || 'https://reg.pryv.me/service/info';
182
- var service = await Pryv.Browser.setupAuth(authSettings, serviceInfoUrl);
183
- })();
184
-
185
- // --- monitor specific
186
- let monitor = null;
187
-
188
- /**
189
- * close monitor
190
- */
191
- function closeMonitor() {
192
- if (monitor == null) return;
193
- try {
194
- monitor.close();
195
- } catch (e) {}
196
- monitor = null;
197
- logToConsole("# Closed Monitor");
198
- }
199
-
200
- /**
201
- *
202
- */
203
- function initializeMonitor() {
204
- new Pryv.Monitor(connection, { limit: 2 })
205
- .on(Pryv.Monitor.Changes.EVENT_DELETE, function (event) {
206
- logToMonitor("> Event-DELETE: " + event.id);
207
- })
208
- .on(Pryv.Monitor.Changes.EVENT, function (event) {
209
- logToMonitor("> Event-CHANGE-or-ADD: " + event.id + '\n - ' + event.content);
210
- })
211
- .on(Pryv.Monitor.Changes.STREAMS, function (streams) {
212
- logToMonitor('> Event-STREAMS');
213
- })
214
- .on(Pryv.Monitor.Changes.STOP, function () {
215
- logToMonitor('> Event-STOP');
216
- })
217
- .on(Pryv.Monitor.Changes.READY, function () {
218
- logToMonitor('> Event-READY');
219
- })
220
- .on(Pryv.Monitor.Changes.ERROR, function (error) {
221
- logToMonitor('> Event-ERROR: \n' + error);
222
- })
223
- // uncomment / comment one of the two following line to switch
224
- // between EventsTimer or Socket updater
225
- //.addUpdateMethod(new Pryv.Monitor.UpdateMethod.EventsTimer(2000))
226
- .addUpdateMethod(new Pryv.Monitor.UpdateMethod.Socket())
227
- .start();
228
- logToConsole("# Monitor Started");
229
- }
230
- </script>
231
- </html>
Binary file
@@ -1,32 +0,0 @@
1
- const Pryv = require('pryv');
2
- require('@pryv/socket.io')(Pryv);
3
- require('../src/')(Pryv);
4
-
5
- const apiEndpoint = 'https://ck60yn9yv00011hd3vu1ocpi7@jslibtest.pryv.me';
6
-
7
- (async () => {
8
- const monitor = await (new Pryv.Monitor(apiEndpoint, { limit: 20 })
9
- .on(Pryv.Monitor.Changes.EVENT_DELETE, function (event) {
10
- console.log('> Delete event', event);
11
- })
12
- .on(Pryv.Monitor.Changes.EVENT, function (event) {
13
- console.log('> New event', event);
14
- })
15
- .on(Pryv.Monitor.Changes.STREAMS, function (streams) {
16
- console.log('> New streams', streams);
17
- })
18
- .on(Pryv.Monitor.Changes.STOP, function () {
19
- console.log('> Event-STOP');
20
- })
21
- .on(Pryv.Monitor.Changes.READY, function () {
22
- console.log('> Event-READY');
23
- })
24
- .on(Pryv.Monitor.Changes.ERROR, function (error) {
25
- console.log('> Event-ERROR: \n' + error);
26
- })
27
- //.addUpdateMethod(new Pryv.Monitor.UpdateMethod.EventsTimer(1000))
28
- .addUpdateMethod(new Pryv.Monitor.UpdateMethod.Socket())
29
- ).start();
30
- })();
31
-
32
-
@@ -1,28 +0,0 @@
1
- #!/bin/sh
2
-
3
- # working dir fix
4
- scriptsFolder=$(cd $(dirname "$0"); pwd)
5
- cd $scriptsFolder/..
6
-
7
- # check for basic prerequisites
8
- hash git 2>&- || { echo >&2 "I require git."; exit 1; }
9
- hash npm 2>&- || { echo >&2 "I require Node and NPM."; exit 1; }
10
-
11
- echo "
12
- Installing Node modules if necessary...
13
- "
14
- npm install
15
-
16
- distFolder=dist
17
- if [ ! -d $distFolder ]
18
- then
19
- echo "
20
- Setting up '$distFolder' folder for publishing to GitHub pages...
21
- "
22
- git clone -b gh-pages git@github.com:pryv/lib-js-monitor.git $distFolder
23
- fi
24
-
25
- echo "
26
-
27
- OK!
28
- "
package/test/helpers.js DELETED
@@ -1,30 +0,0 @@
1
- /**
2
- * Loaded by .mocharc.js for node tests
3
- */
4
- const chai = require('chai');
5
- const Pryv = require('pryv');
6
- require('../src')(Pryv); // Loading Monitor on Pryv
7
- const testData = require('../node_modules/pryv/test/test-data.js');
8
- global.chai = chai;
9
- global.Pryv = Pryv;
10
- global.testData = testData;
11
- global.should = chai.should();
12
- global.expect = chai.expect;
13
- global.testStreamId = testStreamId = 'monitor-test';
14
-
15
- global.prepareAndcreateBaseStreams = async () => {
16
- await testData.prepare();
17
- global.apiEndpoint = testData.apiEndpointWithToken;
18
- global.conn = new Pryv.Connection(apiEndpoint);
19
- const res = await conn.api([{
20
- method: 'streams.create',
21
- params: {
22
- id: testStreamId,
23
- name: testStreamId
24
- }
25
- }]);
26
- expect(res[0]).to.exist;
27
- if (res[0].stream) return;
28
- expect(res[0].error).to.exist;
29
- expect(res[0].error.id).to.equal('item-already-exists');
30
- }
package/webpack.config.js DELETED
@@ -1,37 +0,0 @@
1
- const path = require('path');
2
- const CopyPlugin = require('copy-webpack-plugin');
3
- const { webpackBabelConfig } = require('@pryv/lib-js-common');
4
-
5
- module.exports = [
6
- { // es6 not transpiled version
7
- mode: 'production',
8
- entry: {
9
- 'pryv-monitor': './src/browser-index.js'
10
- },
11
- output: {
12
- filename: '[name]-es6.js',
13
- path: path.resolve(__dirname, 'dist')
14
- },
15
- devtool: 'source-map'
16
- },
17
- { // es5 version
18
- mode: 'production',
19
- entry: {
20
- 'pryv-monitor': ['core-js/stable','./src/browser-index.js']
21
- },
22
- output: {
23
- filename: '[name].js',
24
- path: path.resolve(__dirname, 'dist')
25
- },
26
- plugins: [
27
- new CopyPlugin({
28
- patterns: [
29
- { from: 'examples/index.html', to: 'index.html' },
30
- ],
31
- }),
32
- ],
33
- module: webpackBabelConfig,
34
- devtool: 'source-map'
35
- }
36
-
37
- ];