@zzish/sdk-js 0.5.3 → 0.5.7
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 +28 -22
- package/zzish.js +758 -689
- package/3rdparty.html +0 -87
- package/content.html +0 -162
- package/images/bg_hr.png +0 -0
- package/images/blacktocat.png +0 -0
- package/images/icon_download.png +0 -0
- package/images/sprite_download.png +0 -0
- package/index.html +0 -265
- package/javascripts/main.js +0 -1
- package/params.json +0 -1
- package/redirect.html +0 -48
- package/socket.html +0 -84
- package/stylesheets/pygment_trac.css +0 -70
- package/stylesheets/stylesheet.css +0 -425
- package/success.html +0 -11
- package/user.html +0 -139
package/zzish.js
CHANGED
|
@@ -1,53 +1,51 @@
|
|
|
1
1
|
// Global Zzish object
|
|
2
2
|
(function () {
|
|
3
|
-
|
|
4
|
-
|
|
5
3
|
Zzish = {};
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
/** ** FRONT END JAVASCRIPT STUFF (WITH STATE) ** */
|
|
8
6
|
|
|
9
|
-
//STATE THAT NEEDS TO BE TRACK PER USER (ON THE CLIENT SIDE)
|
|
7
|
+
// STATE THAT NEEDS TO BE TRACK PER USER (ON THE CLIENT SIDE)
|
|
10
8
|
|
|
11
|
-
//appConfig
|
|
12
|
-
|
|
13
|
-
//tracks this device
|
|
14
|
-
|
|
15
|
-
//tracks a session (resets when a new user is selected)
|
|
16
|
-
|
|
17
|
-
//the app Id (sandbox or production) generated from developer console (https://developer.zzish.com)
|
|
18
|
-
|
|
19
|
-
//keep track of the current user (so we know when session needs to be updated)
|
|
20
|
-
|
|
9
|
+
// appConfig
|
|
10
|
+
let appConfig;
|
|
11
|
+
// tracks this device
|
|
12
|
+
let deviceId;
|
|
13
|
+
// tracks a session (resets when a new user is selected)
|
|
14
|
+
let sessionId;
|
|
15
|
+
// the app Id (sandbox or production) generated from developer console (https://developer.zzish.com)
|
|
16
|
+
let appId;
|
|
17
|
+
// keep track of the current user (so we know when session needs to be updated)
|
|
18
|
+
let currentUser = null;
|
|
21
19
|
|
|
22
|
-
//store for storage
|
|
23
|
-
|
|
20
|
+
// store for storage
|
|
21
|
+
const dataStorage = {};
|
|
24
22
|
|
|
25
|
-
//Socket Info
|
|
26
|
-
|
|
23
|
+
// Socket Info
|
|
24
|
+
let WebSocket;
|
|
27
25
|
if (stateful() && window !== undefined) {
|
|
28
26
|
WebSocket = window.WebSocket || window.MozWebSocket;
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
28
|
+
let opencallback;
|
|
29
|
+
let errorcallback;
|
|
30
|
+
let messagecallback;
|
|
31
|
+
let connection;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/** ** CONFIGURATION ***** */
|
|
35
|
+
|
|
36
|
+
let defaultProtocol = "https://";
|
|
37
|
+
let baseUrl = "zapi.zzish.com/";
|
|
38
|
+
let webUrl = "https://live.zzish.com/";
|
|
39
|
+
let logEnabled = false;
|
|
40
|
+
let header = "X-api-key";
|
|
41
|
+
let headerprefix = "";
|
|
42
|
+
const makeStateless = false;
|
|
43
|
+
let socketUrl = "socket.zzish.com";
|
|
44
|
+
let connectedToSocket;
|
|
45
|
+
let currentSocketRetry = 0;
|
|
46
|
+
const maxSocketRetry = 10;
|
|
47
|
+
|
|
48
|
+
const getDataValue = function (key) {
|
|
51
49
|
if (dataStorage[key]) {
|
|
52
50
|
return dataStorage[key];
|
|
53
51
|
}
|
|
@@ -55,47 +53,43 @@
|
|
|
55
53
|
if (typeof localStorage !== "undefined") {
|
|
56
54
|
return localStorage.getItem(key);
|
|
57
55
|
}
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
56
|
+
} catch (err) {
|
|
60
57
|
|
|
61
58
|
}
|
|
62
59
|
return undefined;
|
|
63
60
|
};
|
|
64
61
|
|
|
65
|
-
|
|
62
|
+
const setDataValue = function (key, value) {
|
|
66
63
|
dataStorage[key] = value;
|
|
67
64
|
try {
|
|
68
65
|
if (typeof localStorage !== "undefined") {
|
|
69
66
|
return localStorage.setItem(key, value);
|
|
70
67
|
}
|
|
71
|
-
}
|
|
72
|
-
catch (err) {
|
|
68
|
+
} catch (err) {
|
|
73
69
|
|
|
74
70
|
}
|
|
75
71
|
};
|
|
76
72
|
|
|
77
|
-
|
|
73
|
+
const removeDataValue = function (key) {
|
|
78
74
|
delete dataStorage[key];
|
|
79
75
|
try {
|
|
80
76
|
if (typeof localStorage !== "undefined") {
|
|
81
77
|
localStorage.removeItem(key);
|
|
82
78
|
}
|
|
83
|
-
}
|
|
84
|
-
catch (err) {
|
|
79
|
+
} catch (err) {
|
|
85
80
|
|
|
86
81
|
}
|
|
87
82
|
};
|
|
88
83
|
|
|
89
|
-
|
|
90
|
-
for (
|
|
84
|
+
const clearDataValue = function () {
|
|
85
|
+
for (const i in dataStorage) {
|
|
91
86
|
delete dataStorage[i];
|
|
92
87
|
}
|
|
93
88
|
try {
|
|
94
89
|
if (typeof localStorage !== "undefined") {
|
|
95
90
|
localStorage.clear();
|
|
96
91
|
}
|
|
97
|
-
}
|
|
98
|
-
catch (err) {
|
|
92
|
+
} catch (err) {
|
|
99
93
|
|
|
100
94
|
}
|
|
101
95
|
};
|
|
@@ -104,9 +98,9 @@
|
|
|
104
98
|
* Checks to see if localStorage is defined. Then it's a stateful session
|
|
105
99
|
*/
|
|
106
100
|
function stateful() {
|
|
107
|
-
//if localstorage is not defined
|
|
108
|
-
if (makeStateless) return false;
|
|
109
|
-
return (typeof localStorage
|
|
101
|
+
// if localstorage is not defined
|
|
102
|
+
// if (makeStateless) return false;
|
|
103
|
+
return (typeof localStorage !== "undefined");
|
|
110
104
|
}
|
|
111
105
|
|
|
112
106
|
|
|
@@ -124,14 +118,14 @@
|
|
|
124
118
|
|
|
125
119
|
|
|
126
120
|
function getQueryParams() {
|
|
127
|
-
|
|
121
|
+
let params = {},
|
|
122
|
+
tokens,
|
|
128
123
|
re = /[?&]?([^=]+)=([^&]*)/g;
|
|
129
124
|
try {
|
|
130
|
-
|
|
125
|
+
let qs = "";
|
|
131
126
|
if (location.search!="") {
|
|
132
127
|
qs = location.search;
|
|
133
|
-
}
|
|
134
|
-
else if (location.hash!="") {
|
|
128
|
+
} else if (location.hash!="") {
|
|
135
129
|
qs = location.hash;
|
|
136
130
|
indexOf = qs.indexOf("?");
|
|
137
131
|
qs = qs.substring(indexOf+1);
|
|
@@ -141,68 +135,51 @@
|
|
|
141
135
|
params[decodeURIComponent(tokens[1])]
|
|
142
136
|
= decodeURIComponent(tokens[2]);
|
|
143
137
|
}
|
|
144
|
-
}
|
|
145
|
-
catch (err) {
|
|
138
|
+
} catch (err) {
|
|
146
139
|
|
|
147
140
|
}
|
|
148
141
|
return params;
|
|
149
142
|
}
|
|
150
143
|
|
|
151
|
-
function getConfigValue(config,field,originalValue) {
|
|
144
|
+
function getConfigValue(config, field, originalValue) {
|
|
152
145
|
if (config[field]!=undefined) return config[field];
|
|
153
146
|
return originalValue;
|
|
154
147
|
}
|
|
155
148
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
method: "POST",
|
|
159
|
-
url: getBaseUrl() + "statements/events",
|
|
160
|
-
data: {
|
|
161
|
-
platform : "js",
|
|
162
|
-
action: "START",
|
|
163
|
-
appId: appId
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
sendData(request, function (err, data) {
|
|
167
|
-
callCallBack(err, data, callback);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
149
|
+
// REMOVED: sendEvent() function - AppEvents functionality disabled to reduce MongoDB costs
|
|
150
|
+
// const sendEvent = function (event, callback) { ... } // No longer needed
|
|
170
151
|
|
|
171
152
|
/**
|
|
172
153
|
* Initialise Zzish instance
|
|
173
154
|
*/
|
|
174
155
|
Zzish.init = function (config) {
|
|
175
|
-
//generate a device if we don't have one
|
|
156
|
+
// generate a device if we don't have one
|
|
176
157
|
appConfig = config;
|
|
177
158
|
deviceId = getDataValue("deviceId");
|
|
178
159
|
if (deviceId == null) {
|
|
179
160
|
deviceId = v4();
|
|
180
161
|
setDataValue("deviceId", deviceId);
|
|
181
162
|
}
|
|
182
|
-
if (typeof config
|
|
183
|
-
try
|
|
184
|
-
{
|
|
163
|
+
if (typeof config ==="string") {
|
|
164
|
+
try {
|
|
185
165
|
config = JSON.parse(config);
|
|
186
166
|
Zzish.init(config);
|
|
187
|
-
}
|
|
188
|
-
catch (err) {
|
|
167
|
+
} catch (err) {
|
|
189
168
|
appId = config;
|
|
190
|
-
setDataValue("appConfig",config);
|
|
169
|
+
setDataValue("appConfig", config);
|
|
191
170
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
socketUrl = getConfigValue(config,'socketUrl',socketUrl);
|
|
203
|
-
setDataValue("appConfig",JSON.stringify(config));
|
|
171
|
+
} else if (typeof config ==="object") {
|
|
172
|
+
appId = getConfigValue(config, "api");
|
|
173
|
+
defaultProtocol = getConfigValue(config, "protocol", defaultProtocol);
|
|
174
|
+
baseUrl = getConfigValue(config, "baseUrl", baseUrl);
|
|
175
|
+
webUrl = getConfigValue(config, "webUrl", webUrl);
|
|
176
|
+
header = getConfigValue(config, "header", header);
|
|
177
|
+
headerprefix = getConfigValue(config, "headerprefix", headerprefix);
|
|
178
|
+
logEnabled = getConfigValue(config, "logEnabled", logEnabled);
|
|
179
|
+
socketUrl = getConfigValue(config, "socketUrl", socketUrl);
|
|
180
|
+
setDataValue("appConfig", JSON.stringify(config));
|
|
204
181
|
}
|
|
205
|
-
sendEvent("START")
|
|
182
|
+
// REMOVED: sendEvent("START") - AppEvents disabled to reduce MongoDB costs
|
|
206
183
|
};
|
|
207
184
|
|
|
208
185
|
|
|
@@ -210,32 +187,31 @@
|
|
|
210
187
|
* Stop Zzish instance
|
|
211
188
|
*/
|
|
212
189
|
Zzish.stop = function (callback) {
|
|
213
|
-
//generate a device if we don't have one
|
|
214
|
-
sendEvent("STOP")
|
|
190
|
+
// generate a device if we don't have one
|
|
191
|
+
// REMOVED: sendEvent("STOP") - AppEvents disabled to reduce MongoDB costs
|
|
215
192
|
};
|
|
216
193
|
|
|
217
|
-
|
|
218
|
-
if (params
|
|
219
|
-
Zzish.init(params
|
|
194
|
+
const params = getQueryParams();
|
|
195
|
+
if (params.zzishtoken!=null) {
|
|
196
|
+
Zzish.init(params.zzishtoken);
|
|
220
197
|
}
|
|
221
|
-
if (params
|
|
198
|
+
if (params.cancel!=undefined) {
|
|
222
199
|
removeDataValue("token");
|
|
223
200
|
}
|
|
224
201
|
|
|
225
202
|
|
|
226
|
-
|
|
227
|
-
/**** SERVER SIDE (NO STATE) *****/
|
|
203
|
+
/** ** SERVER SIDE (NO STATE) **** */
|
|
228
204
|
|
|
229
205
|
/**
|
|
230
206
|
* Presets the deviceId and SessionId which the developer stores if there is not state to store that info
|
|
231
207
|
*/
|
|
232
|
-
Zzish.initState = function(iDeviceId,iSessionId) {
|
|
208
|
+
Zzish.initState = function (iDeviceId, iSessionId) {
|
|
233
209
|
deviceId = iDeviceId;
|
|
234
210
|
sessionId = iSessionId;
|
|
235
211
|
return zzish;
|
|
236
212
|
};
|
|
237
213
|
|
|
238
|
-
|
|
214
|
+
/** ** CLIENT SIDE (REQUIRE STATE) **** */
|
|
239
215
|
|
|
240
216
|
/**
|
|
241
217
|
* Get the User (if the id is the same as the current one, returns the current user)
|
|
@@ -248,23 +224,21 @@
|
|
|
248
224
|
Zzish.getUser = function (id, name, callback) {
|
|
249
225
|
if (id==undefined) id = v4();
|
|
250
226
|
if (stateful()) {
|
|
251
|
-
//that means we have a front end service so we can check state
|
|
227
|
+
// that means we have a front end service so we can check state
|
|
252
228
|
if (currentUser==undefined || currentUser.id != id) {
|
|
253
229
|
sessionId = v4();
|
|
254
|
-
Zzish.createUser(id,name,
|
|
230
|
+
Zzish.createUser(id, name, (err, message) => {
|
|
255
231
|
if (!err) {
|
|
256
|
-
//set the current user if we don't have an error
|
|
232
|
+
// set the current user if we don't have an error
|
|
257
233
|
currentUser = message;
|
|
258
234
|
}
|
|
259
|
-
callCallBack(err, {status: 200, payload: message}, callback);
|
|
235
|
+
callCallBack(err, { status: 200, payload: message }, callback);
|
|
260
236
|
});
|
|
237
|
+
} else {
|
|
238
|
+
callCallBack(null, { status: 200, payload: currentUser }, callback);
|
|
261
239
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
Zzish.createUser(id,name,callback);
|
|
240
|
+
} else {
|
|
241
|
+
Zzish.createUser(id, name, callback);
|
|
268
242
|
}
|
|
269
243
|
};
|
|
270
244
|
|
|
@@ -276,13 +250,13 @@
|
|
|
276
250
|
* @return The user (returns a server user if it already exists). If it's the current User, returns that user
|
|
277
251
|
*/
|
|
278
252
|
Zzish.getUserByCode = function (code, callback) {
|
|
279
|
-
|
|
253
|
+
const request = {
|
|
280
254
|
method: "GET",
|
|
281
|
-
url: getBaseUrl()
|
|
255
|
+
url: `${getBaseUrl()}profiles/code/${code}`,
|
|
282
256
|
};
|
|
283
|
-
sendData(request,
|
|
257
|
+
sendData(request, (err, data) => {
|
|
284
258
|
callCallBack(err, data, callback);
|
|
285
|
-
})
|
|
259
|
+
});
|
|
286
260
|
};
|
|
287
261
|
|
|
288
262
|
/**
|
|
@@ -293,31 +267,30 @@
|
|
|
293
267
|
* @return The user (returns a server user if it already exists). If it's the current User, returns that user
|
|
294
268
|
*/
|
|
295
269
|
Zzish.getUsers = function (ids, callback) {
|
|
296
|
-
|
|
270
|
+
const request = {
|
|
297
271
|
method: "GET",
|
|
298
|
-
url: getBaseUrl()
|
|
272
|
+
url: `${getBaseUrl()}profiles/list/${encodeURIComponent(ids.join(";"))}`,
|
|
299
273
|
};
|
|
300
|
-
sendData(request,
|
|
274
|
+
sendData(request, (err, data) => {
|
|
301
275
|
callCallBack(err, data, callback);
|
|
302
|
-
})
|
|
276
|
+
});
|
|
303
277
|
};
|
|
304
278
|
|
|
305
279
|
/**
|
|
306
|
-
* Get a list of users (
|
|
280
|
+
* Get a list of users via POST (batched lookup beyond URL length cliff)
|
|
307
281
|
*
|
|
308
|
-
* @param ids -
|
|
309
|
-
* @param callback - An optional callback after
|
|
310
|
-
* @return The user (returns a server user if it already exists). If it's the current User, returns that user
|
|
282
|
+
* @param ids - Array of user IDs (required)
|
|
283
|
+
* @param callback - An optional callback after the request completes
|
|
311
284
|
*/
|
|
312
285
|
Zzish.getUsersByList = function (ids, callback) {
|
|
313
|
-
|
|
286
|
+
const request = {
|
|
314
287
|
method: "POST",
|
|
315
|
-
url: getBaseUrl()
|
|
316
|
-
data: ids
|
|
288
|
+
url: `${getBaseUrl()}profiles/listusers/`,
|
|
289
|
+
data: ids,
|
|
317
290
|
};
|
|
318
|
-
sendData(request,
|
|
291
|
+
sendData(request, (err, data) => {
|
|
319
292
|
callCallBack(err, data, callback);
|
|
320
|
-
})
|
|
293
|
+
});
|
|
321
294
|
};
|
|
322
295
|
|
|
323
296
|
/**
|
|
@@ -329,14 +302,14 @@
|
|
|
329
302
|
* @return The user (returns a server user if it already exists). If it's the current User, returns that user
|
|
330
303
|
*/
|
|
331
304
|
Zzish.saveUser = function (id, user, callback) {
|
|
332
|
-
|
|
305
|
+
const request = {
|
|
333
306
|
method: "POST",
|
|
334
|
-
url: getBaseUrl()
|
|
335
|
-
data: user
|
|
307
|
+
url: `${getBaseUrl()}profiles`,
|
|
308
|
+
data: user,
|
|
336
309
|
};
|
|
337
|
-
sendData(request,
|
|
310
|
+
sendData(request, (err, data) => {
|
|
338
311
|
callCallBack(err, data, callback);
|
|
339
|
-
})
|
|
312
|
+
});
|
|
340
313
|
};
|
|
341
314
|
|
|
342
315
|
/**
|
|
@@ -348,14 +321,14 @@
|
|
|
348
321
|
* @return The group (returns a server user if it already exists). If it's the current User, returns that user
|
|
349
322
|
*/
|
|
350
323
|
Zzish.saveGroup = function (id, group, callback) {
|
|
351
|
-
|
|
324
|
+
const request = {
|
|
352
325
|
method: "POST",
|
|
353
|
-
url: getBaseUrl()
|
|
354
|
-
data: group
|
|
326
|
+
url: `${getBaseUrl()}profiles/${id}/groups`,
|
|
327
|
+
data: group,
|
|
355
328
|
};
|
|
356
|
-
sendData(request,
|
|
329
|
+
sendData(request, (err, data) => {
|
|
357
330
|
callCallBack(err, data, callback);
|
|
358
|
-
})
|
|
331
|
+
});
|
|
359
332
|
};
|
|
360
333
|
|
|
361
334
|
|
|
@@ -371,19 +344,18 @@
|
|
|
371
344
|
if (game.uuid === undefined) {
|
|
372
345
|
game.uuid = v4();
|
|
373
346
|
}
|
|
374
|
-
|
|
347
|
+
const request = {
|
|
375
348
|
method: "POST",
|
|
376
|
-
url: getBaseUrl()
|
|
377
|
-
data: game
|
|
349
|
+
url: `${getBaseUrl()}statements/${userId}/games`,
|
|
350
|
+
data: game,
|
|
378
351
|
};
|
|
379
|
-
sendData(request,
|
|
352
|
+
sendData(request, (err, data) => {
|
|
380
353
|
callCallBack(err, data, callback);
|
|
381
|
-
})
|
|
354
|
+
});
|
|
382
355
|
return game.uuid;
|
|
383
356
|
};
|
|
384
357
|
|
|
385
358
|
|
|
386
|
-
|
|
387
359
|
/**
|
|
388
360
|
* Get results of a game
|
|
389
361
|
*
|
|
@@ -391,14 +363,14 @@
|
|
|
391
363
|
* @param callback - A callback to be called after message is sent (returns error,message)
|
|
392
364
|
* @return The game uuid
|
|
393
365
|
*/
|
|
394
|
-
Zzish.getGameActivities = function (userId,gameId, callback) {
|
|
395
|
-
|
|
366
|
+
Zzish.getGameActivities = function (userId, gameId, callback) {
|
|
367
|
+
const request = {
|
|
396
368
|
method: "GET",
|
|
397
|
-
url: getBaseUrl()
|
|
369
|
+
url: `${getBaseUrl()}statements/${userId}/games/${gameId}/activities`,
|
|
398
370
|
};
|
|
399
|
-
sendData(request,
|
|
371
|
+
sendData(request, (err, data) => {
|
|
400
372
|
callCallBack(err, data, callback);
|
|
401
|
-
})
|
|
373
|
+
});
|
|
402
374
|
};
|
|
403
375
|
|
|
404
376
|
/**
|
|
@@ -409,14 +381,14 @@
|
|
|
409
381
|
* @param callback - A callback to be called after message is sent (returns error,message)
|
|
410
382
|
* @return The game uuid
|
|
411
383
|
*/
|
|
412
|
-
Zzish.getGameActivity = function (userId,gameId, uuid, callback) {
|
|
413
|
-
|
|
384
|
+
Zzish.getGameActivity = function (userId, gameId, uuid, callback) {
|
|
385
|
+
const request = {
|
|
414
386
|
method: "GET",
|
|
415
|
-
url: getBaseUrl()
|
|
387
|
+
url: `${getBaseUrl()}statements/${userId}/games/${gameId}/activities/${uuid}`,
|
|
416
388
|
};
|
|
417
|
-
sendData(request,
|
|
389
|
+
sendData(request, (err, data) => {
|
|
418
390
|
callCallBack(err, data, callback);
|
|
419
|
-
})
|
|
391
|
+
});
|
|
420
392
|
};
|
|
421
393
|
|
|
422
394
|
/**
|
|
@@ -437,15 +409,15 @@
|
|
|
437
409
|
* @param callback - A callback to be called after message is sent (returns error,message)
|
|
438
410
|
*/
|
|
439
411
|
Zzish.startActivity = function (userId, activityName, code, callback) {
|
|
440
|
-
|
|
412
|
+
const parameters = {
|
|
441
413
|
activityDefinition: {
|
|
442
|
-
type: activityName
|
|
414
|
+
type: activityName,
|
|
443
415
|
},
|
|
444
416
|
extensions: {
|
|
445
|
-
groupCode: code
|
|
446
|
-
}
|
|
417
|
+
groupCode: code,
|
|
418
|
+
},
|
|
447
419
|
};
|
|
448
|
-
Zzish.startActivityWithObjects(userId,parameters, callback);
|
|
420
|
+
Zzish.startActivityWithObjects(userId, parameters, callback);
|
|
449
421
|
};
|
|
450
422
|
|
|
451
423
|
/**
|
|
@@ -456,19 +428,23 @@
|
|
|
456
428
|
* @param callback - A callback to be called after message is sent (returns error,message)
|
|
457
429
|
*/
|
|
458
430
|
Zzish.startActivityWithObjects = function (userId, parameters, callback) {
|
|
459
|
-
sendEvent("START_ACTIVITY")
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
uuid: userId
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
var message = {
|
|
431
|
+
// REMOVED: sendEvent("START_ACTIVITY") - AppEvents disabled
|
|
432
|
+
Zzish.setCurrentUser(userId);
|
|
433
|
+
const message = {
|
|
466
434
|
verb: "http://activitystrea.ms/schema/1.0/start",
|
|
467
|
-
activityUuid: parameters.activityId || v4()
|
|
435
|
+
activityUuid: parameters.activityId || v4(),
|
|
468
436
|
};
|
|
469
437
|
sendMessage(message, parameters, callback);
|
|
470
438
|
};
|
|
471
439
|
|
|
440
|
+
Zzish.setCurrentUser = function (userId) {
|
|
441
|
+
if (!currentUser || !stateful() || userId != currentUser.id) {
|
|
442
|
+
currentUser = {
|
|
443
|
+
uuid: userId,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
|
|
472
448
|
/**
|
|
473
449
|
* stop Activity with aid
|
|
474
450
|
*
|
|
@@ -478,16 +454,16 @@
|
|
|
478
454
|
*
|
|
479
455
|
*/
|
|
480
456
|
Zzish.stopActivity = function (activityId, states, callback) {
|
|
481
|
-
sendEvent("STOP_ACTIVITY")
|
|
482
|
-
|
|
483
|
-
|
|
457
|
+
// REMOVED: sendEvent("STOP_ACTIVITY") - AppEvents disabled
|
|
458
|
+
let pro;
|
|
459
|
+
let haveState = false;
|
|
484
460
|
if (states!=undefined && states.proficiency!=undefined) {
|
|
485
461
|
pro = states.proficiency;
|
|
486
462
|
delete states.proficiency;
|
|
487
463
|
}
|
|
488
|
-
|
|
489
|
-
states
|
|
490
|
-
}
|
|
464
|
+
const stateMap = {
|
|
465
|
+
states,
|
|
466
|
+
};
|
|
491
467
|
if (pro!=undefined) {
|
|
492
468
|
stateMap.proficiency = pro;
|
|
493
469
|
haveState = true;
|
|
@@ -496,9 +472,33 @@
|
|
|
496
472
|
haveState = true;
|
|
497
473
|
}
|
|
498
474
|
sendMessage({
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}, { states: haveState?stateMap:undefined},callback)
|
|
475
|
+
verb: "http://activitystrea.ms/schema/1.0/complete",
|
|
476
|
+
activityUuid: activityId,
|
|
477
|
+
}, { states: haveState?stateMap:undefined }, callback);
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Stop Activity with full parameters object (preserves activityDefinition)
|
|
482
|
+
*
|
|
483
|
+
* @param activityId - The activity id (returned from startActivity) (required)
|
|
484
|
+
* @param parameters - Object that may contain activityDefinition, states, extensions
|
|
485
|
+
* @param callback - A callback to be called after message is sent (returns error, message)
|
|
486
|
+
*
|
|
487
|
+
* Prefer this over stopActivity({}) so the resulting xAPI Statement carries
|
|
488
|
+
* object.definition.type. Spring Data 4.x strict mode rejects POST /api/statements
|
|
489
|
+
* payloads where definition.type is null when the historical ActivityDef
|
|
490
|
+
* collection contains multiple type=null rows for the app.
|
|
491
|
+
*/
|
|
492
|
+
Zzish.stopActivityWithObjects = function (activityId, parameters, callback) {
|
|
493
|
+
const params = parameters || {};
|
|
494
|
+
sendMessage({
|
|
495
|
+
verb: "http://activitystrea.ms/schema/1.0/complete",
|
|
496
|
+
activityUuid: activityId,
|
|
497
|
+
}, {
|
|
498
|
+
activityDefinition: params.activityDefinition,
|
|
499
|
+
states: params.states,
|
|
500
|
+
extensions: params.extensions,
|
|
501
|
+
}, callback);
|
|
502
502
|
};
|
|
503
503
|
|
|
504
504
|
/** * Update an activity instance with images
|
|
@@ -508,14 +508,14 @@
|
|
|
508
508
|
* @param callback - A callback to be called after message is sent (returns error,message)
|
|
509
509
|
*/
|
|
510
510
|
Zzish.updateActivityImages = function (activityId, images, callback) {
|
|
511
|
-
|
|
511
|
+
const request = {
|
|
512
512
|
method: "POST",
|
|
513
|
-
url: getBaseUrl()
|
|
513
|
+
url: `${getBaseUrl()}statements/activityinstances/${activityId}/images`,
|
|
514
514
|
data: images,
|
|
515
515
|
};
|
|
516
|
-
sendData(request,
|
|
516
|
+
sendData(request, (err, data) => {
|
|
517
517
|
callCallBack(err, data, callback);
|
|
518
|
-
})
|
|
518
|
+
});
|
|
519
519
|
};
|
|
520
520
|
|
|
521
521
|
/**
|
|
@@ -526,11 +526,49 @@
|
|
|
526
526
|
*
|
|
527
527
|
*/
|
|
528
528
|
Zzish.cancelActivity = function (activityId, callback) {
|
|
529
|
-
sendEvent("CANCEL_ACTIVITY")
|
|
529
|
+
// REMOVED: sendEvent("CANCEL_ACTIVITY") - AppEvents disabled
|
|
530
|
+
sendMessage({
|
|
531
|
+
verb: "http://activitystrea.ms/schema/1.0/cancel",
|
|
532
|
+
activityUuid: activityId,
|
|
533
|
+
}, {}, callback);
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Cancel Activity with full parameters object (preserves activityDefinition)
|
|
538
|
+
*
|
|
539
|
+
* @param activityId - The activity id (returned from startActivity) (required)
|
|
540
|
+
* @param parameters - Object that may contain activityDefinition, states, extensions
|
|
541
|
+
* @param callback - A callback to be called after message is sent (returns error, message)
|
|
542
|
+
*/
|
|
543
|
+
Zzish.cancelActivityWithObjects = function (activityId, parameters, callback) {
|
|
544
|
+
const params = parameters || {};
|
|
530
545
|
sendMessage({
|
|
531
546
|
verb: "http://activitystrea.ms/schema/1.0/cancel",
|
|
532
|
-
activityUuid: activityId
|
|
533
|
-
}, {
|
|
547
|
+
activityUuid: activityId,
|
|
548
|
+
}, {
|
|
549
|
+
activityDefinition: params.activityDefinition,
|
|
550
|
+
states: params.states,
|
|
551
|
+
extensions: params.extensions,
|
|
552
|
+
}, callback);
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Get incomplete Activity by profile ID and group content ID
|
|
557
|
+
*
|
|
558
|
+
* @param profileId - The profile ID of the user (required)
|
|
559
|
+
* @param groupContentId - The group content ID associated with the activity (required)
|
|
560
|
+
* @param callback - A callback to be called after message is sent (returns error,message)
|
|
561
|
+
*
|
|
562
|
+
*/
|
|
563
|
+
Zzish.getIncompleteActivity = function (profileId, groupContentId, callback) {
|
|
564
|
+
const incompleteStatus = "ACTIVITY_INSTANCE_STARTED";
|
|
565
|
+
const request = {
|
|
566
|
+
method: "GET",
|
|
567
|
+
url: `${getBaseUrl()}statements/activityinstances/user/${profileId.trim()}?groupContentId=${groupContentId.trim()}&status=${incompleteStatus}`,
|
|
568
|
+
};
|
|
569
|
+
sendData(request, (err, data) => {
|
|
570
|
+
callCallBack(err, data, callback);
|
|
571
|
+
});
|
|
534
572
|
};
|
|
535
573
|
|
|
536
574
|
/**
|
|
@@ -539,6 +577,7 @@
|
|
|
539
577
|
* @param activityId - The activity id (returned from startActivity) (required)
|
|
540
578
|
* @param actionName - The name of the action (required)
|
|
541
579
|
* @param response - A string representation of the action (optional)
|
|
580
|
+
* @param responseOption - A string representation of the action option, e.g. "A", "B", etc (optional)
|
|
542
581
|
* @param score - A float score (optional)
|
|
543
582
|
* @param duration - A long duration (optional)
|
|
544
583
|
* @param attempts - The number of attempts
|
|
@@ -546,44 +585,47 @@
|
|
|
546
585
|
* @param callback - A callback to be called after message is sent (returns error,message)
|
|
547
586
|
*
|
|
548
587
|
*/
|
|
549
|
-
Zzish.logAction = function (activityId, actionName, response, score, correct, duration, attempts, attributes, callback) {
|
|
550
|
-
|
|
551
|
-
type: actionName
|
|
588
|
+
Zzish.logAction = function (activityId, actionName, response, responseOption, score, correct, duration, attempts, attributes, callback) {
|
|
589
|
+
const definition = {
|
|
590
|
+
type: actionName,
|
|
552
591
|
};
|
|
553
|
-
|
|
592
|
+
const result = {};
|
|
554
593
|
if (response != undefined) {
|
|
555
|
-
result
|
|
594
|
+
result.response = response;
|
|
595
|
+
}
|
|
596
|
+
if (responseOption != undefined) {
|
|
597
|
+
result.responseOption = responseOption;
|
|
556
598
|
}
|
|
557
599
|
if (score != undefined) {
|
|
558
|
-
result
|
|
600
|
+
result.score = parseFloat(score);
|
|
559
601
|
}
|
|
560
602
|
if (correct != undefined) {
|
|
561
|
-
result
|
|
603
|
+
result.correct = correct;
|
|
562
604
|
}
|
|
563
605
|
if (duration != undefined) {
|
|
564
|
-
result
|
|
606
|
+
result.duration = parseInt(duration);
|
|
565
607
|
}
|
|
566
608
|
if (attempts != undefined) {
|
|
567
|
-
result
|
|
609
|
+
result.attempts = parseInt(attempts);
|
|
568
610
|
}
|
|
569
|
-
Zzish.logActionWithObjects(activityId,{definition
|
|
611
|
+
Zzish.logActionWithObjects(activityId, { definition, result }, callback);
|
|
570
612
|
};
|
|
571
613
|
|
|
572
614
|
Zzish.logActionWithObjects = function (activityId, parameters, callback) {
|
|
573
|
-
sendEvent("ACTION")
|
|
615
|
+
// REMOVED: sendEvent("ACTION") - AppEvents disabled
|
|
574
616
|
if (parameters.definition==undefined) {
|
|
575
617
|
parameters.definition = {};
|
|
576
618
|
}
|
|
577
|
-
|
|
619
|
+
const action = createActionObject(parameters);
|
|
578
620
|
sendMessage({
|
|
579
621
|
verb: "http://activitystrea.ms/schema/1.0/start",
|
|
580
622
|
activityUuid: activityId,
|
|
581
|
-
actions: [action]
|
|
623
|
+
actions: [action],
|
|
582
624
|
}, parameters, callback);
|
|
583
|
-
}
|
|
625
|
+
};
|
|
584
626
|
|
|
585
627
|
function createActionObject(parameters) {
|
|
586
|
-
|
|
628
|
+
let action = parameters.result;
|
|
587
629
|
if (action == undefined) {
|
|
588
630
|
action = {};
|
|
589
631
|
}
|
|
@@ -592,22 +634,36 @@
|
|
|
592
634
|
action.state = parameters.state;
|
|
593
635
|
if (typeof parameters.attributes === "string") {
|
|
594
636
|
action.attributes = JSON.parse(parameters.attributes);
|
|
595
|
-
}
|
|
596
|
-
else {
|
|
637
|
+
} else {
|
|
597
638
|
action.attributes = parameters.attributes;
|
|
598
639
|
}
|
|
599
640
|
return action;
|
|
600
641
|
}
|
|
601
642
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
643
|
+
/**
|
|
644
|
+
* Log a batch of Actions for the activity
|
|
645
|
+
*
|
|
646
|
+
* @param activityId - The activity id (returned from startActivity) (required)
|
|
647
|
+
* @param parameters - The parameters Object (must include activityDefinition.type)
|
|
648
|
+
* @param actionObjects - Array of action objects
|
|
649
|
+
* @param isQuizComplete - If true, emits verb=complete; otherwise verb=start (optional)
|
|
650
|
+
* @param callback - A callback to be called after message is sent (returns error, message)
|
|
651
|
+
*
|
|
652
|
+
* Accepts both the legacy 4-arg shape (callback at position 4) and the
|
|
653
|
+
* modern 5-arg shape (isQuizComplete at position 4, callback at position 5).
|
|
654
|
+
*/
|
|
655
|
+
Zzish.logActions = function (activityId, parameters, actionObjects, isQuizComplete, callback) {
|
|
656
|
+
// Arity tolerance: if 4th arg is a function, treat it as the callback.
|
|
657
|
+
if (typeof isQuizComplete === "function") {
|
|
658
|
+
callback = isQuizComplete;
|
|
659
|
+
isQuizComplete = false;
|
|
660
|
+
}
|
|
661
|
+
const actions = actionObjects.map((action) => createActionObject(action));
|
|
662
|
+
const verb = isQuizComplete ? "complete" : "start";
|
|
607
663
|
sendMessage({
|
|
608
|
-
verb:
|
|
664
|
+
verb: `http://activitystrea.ms/schema/1.0/${verb}`,
|
|
609
665
|
activityUuid: activityId,
|
|
610
|
-
actions
|
|
666
|
+
actions,
|
|
611
667
|
}, parameters, callback);
|
|
612
668
|
};
|
|
613
669
|
|
|
@@ -620,26 +676,27 @@
|
|
|
620
676
|
*/
|
|
621
677
|
var sendMessage = function (data, parameters, callback) {
|
|
622
678
|
if (currentUser) {
|
|
623
|
-
|
|
679
|
+
data.userUuid = currentUser.uuid;
|
|
624
680
|
}
|
|
625
681
|
if (parameters.extensions==undefined) {
|
|
626
682
|
parameters.extensions = {};
|
|
627
683
|
}
|
|
628
|
-
parameters.extensions
|
|
629
|
-
parameters.extensions
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
684
|
+
parameters.extensions.deviceId = deviceId;
|
|
685
|
+
parameters.extensions.sessionId = sessionId;
|
|
686
|
+
const message = buildSimulationMessage(data, parameters);
|
|
687
|
+
const headers = {
|
|
688
|
+
"Content-Type": "application/json",
|
|
633
689
|
};
|
|
634
690
|
headers[header] = headerprefix + appId;
|
|
635
|
-
|
|
691
|
+
if (logEnabled) console.log(`Sending${JSON.stringify(message)}`);
|
|
692
|
+
const request = {
|
|
636
693
|
method: "POST",
|
|
637
|
-
url: getBaseUrl()
|
|
638
|
-
data: message
|
|
694
|
+
url: `${getBaseUrl()}statements`,
|
|
695
|
+
data: message,
|
|
639
696
|
};
|
|
640
|
-
sendData(request,
|
|
697
|
+
sendData(request, (err, data) => {
|
|
641
698
|
callCallBack(err, data, callback);
|
|
642
|
-
})
|
|
699
|
+
});
|
|
643
700
|
};
|
|
644
701
|
|
|
645
702
|
/**
|
|
@@ -647,27 +704,27 @@
|
|
|
647
704
|
* @param data
|
|
648
705
|
* @returns partially built TinCan message
|
|
649
706
|
*/
|
|
650
|
-
var buildSimulationMessage = function (data,parameters) {
|
|
707
|
+
var buildSimulationMessage = function (data, parameters) {
|
|
651
708
|
if (parameters.activityDefinition==undefined) {
|
|
652
709
|
parameters.activityDefinition = {};
|
|
653
710
|
}
|
|
654
|
-
|
|
711
|
+
const message = {
|
|
655
712
|
actor: {
|
|
656
713
|
account: {
|
|
657
|
-
homePage:
|
|
658
|
-
name: data.userUuid
|
|
659
|
-
}
|
|
714
|
+
homePage: `http://www.zzish.com/${appId}`,
|
|
715
|
+
name: data.userUuid,
|
|
716
|
+
},
|
|
660
717
|
},
|
|
661
718
|
verb: {
|
|
662
|
-
id: data.verb
|
|
719
|
+
id: data.verb,
|
|
663
720
|
},
|
|
664
721
|
object: {
|
|
665
|
-
definition: parameters.activityDefinition
|
|
722
|
+
definition: parameters.activityDefinition,
|
|
666
723
|
},
|
|
667
724
|
id: data.activityUuid,
|
|
668
725
|
context: {
|
|
669
|
-
extensions: {}
|
|
670
|
-
}
|
|
726
|
+
extensions: {},
|
|
727
|
+
},
|
|
671
728
|
};
|
|
672
729
|
if (parameters.states!=undefined) {
|
|
673
730
|
message.object.state = parameters.states;
|
|
@@ -680,7 +737,7 @@
|
|
|
680
737
|
}
|
|
681
738
|
if (parameters.extensions) {
|
|
682
739
|
for (i in parameters.extensions) {
|
|
683
|
-
message.context.extensions[
|
|
740
|
+
message.context.extensions[`http://www.zzish.com/context/extension/${i}`] = parameters.extensions[i];
|
|
684
741
|
}
|
|
685
742
|
}
|
|
686
743
|
if (data.actions !== undefined) {
|
|
@@ -690,7 +747,6 @@
|
|
|
690
747
|
};
|
|
691
748
|
|
|
692
749
|
|
|
693
|
-
|
|
694
750
|
/**
|
|
695
751
|
* Simple replaceAll method
|
|
696
752
|
*
|
|
@@ -700,8 +756,8 @@
|
|
|
700
756
|
* @return The result after the replace is done
|
|
701
757
|
*/
|
|
702
758
|
function replaceAll(find, replace, str) {
|
|
703
|
-
if (str){
|
|
704
|
-
return str.replace(new RegExp(find,
|
|
759
|
+
if (str) {
|
|
760
|
+
return str.replace(new RegExp(find, "g"), replace);
|
|
705
761
|
}
|
|
706
762
|
}
|
|
707
763
|
|
|
@@ -712,33 +768,29 @@
|
|
|
712
768
|
* callback - callback method
|
|
713
769
|
*/
|
|
714
770
|
function callCallBack(err, data, callback) {
|
|
715
|
-
//check if callback exists
|
|
771
|
+
// check if callback exists
|
|
716
772
|
if (callback != undefined) {
|
|
717
|
-
if (err != undefined) {
|
|
718
|
-
|
|
719
|
-
//an error has ocurred when trying to get response
|
|
773
|
+
if (err != undefined) {
|
|
774
|
+
// an error has ocurred when trying to get response
|
|
720
775
|
callback(err.status, err.message);
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
//check if api returns 200
|
|
776
|
+
} else if (data != undefined) {
|
|
777
|
+
// check if api returns 200
|
|
724
778
|
if (data.status == 200) {
|
|
725
|
-
//return payload as message will be null
|
|
779
|
+
// return payload as message will be null
|
|
726
780
|
callback(undefined, data.payload);
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
//return message
|
|
781
|
+
} else {
|
|
782
|
+
// return message
|
|
730
783
|
callback(data.status, data.message);
|
|
731
784
|
}
|
|
732
|
-
}
|
|
733
|
-
else {
|
|
785
|
+
} else {
|
|
734
786
|
callback(400, "Zzish error");
|
|
735
787
|
}
|
|
736
788
|
}
|
|
737
789
|
}
|
|
738
790
|
|
|
739
|
-
|
|
791
|
+
/** ** BACK END STUFF TO SEND DATA ** */
|
|
740
792
|
|
|
741
|
-
|
|
793
|
+
/** ** LOGINSTUFF ** */
|
|
742
794
|
|
|
743
795
|
/**
|
|
744
796
|
* Returns true if it's a valid class code (not necessarily whether it exists)
|
|
@@ -747,12 +799,12 @@
|
|
|
747
799
|
*/
|
|
748
800
|
Zzish.validateClassCode = function (code) {
|
|
749
801
|
if (code!=undefined && code.length>1) {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
for (counter=0;counter<code.length-1;counter++) {
|
|
802
|
+
const charLast = code.slice(-1);
|
|
803
|
+
let total = 0;
|
|
804
|
+
for (counter=0; counter<code.length-1; counter++) {
|
|
753
805
|
total+=code.charCodeAt(counter);
|
|
754
806
|
}
|
|
755
|
-
total
|
|
807
|
+
total %=10;
|
|
756
808
|
if (charLast==total) {
|
|
757
809
|
return true;
|
|
758
810
|
}
|
|
@@ -771,24 +823,24 @@
|
|
|
771
823
|
* @param callback - An optional callback after user has been saved on server
|
|
772
824
|
*/
|
|
773
825
|
Zzish.authUser = function (id, name, code, callback) {
|
|
774
|
-
|
|
775
|
-
uuid
|
|
776
|
-
username
|
|
777
|
-
passwordText: code
|
|
826
|
+
const message = {
|
|
827
|
+
uuid: id,
|
|
828
|
+
username: name,
|
|
829
|
+
passwordText: code,
|
|
778
830
|
};
|
|
779
|
-
//create new session
|
|
831
|
+
// create new session
|
|
780
832
|
sessionId = uuid.v4();
|
|
781
|
-
|
|
833
|
+
const request = {
|
|
782
834
|
method: "POST",
|
|
783
|
-
url: getBaseUrl()
|
|
784
|
-
data: message
|
|
835
|
+
url: `${getBaseUrl()}profiles/auth`,
|
|
836
|
+
data: message,
|
|
785
837
|
};
|
|
786
|
-
sendData(request,
|
|
838
|
+
sendData(request, (err, data) => {
|
|
787
839
|
if (!err) {
|
|
788
840
|
currentUser = data;
|
|
789
841
|
}
|
|
790
842
|
callCallBack(err, data, callback);
|
|
791
|
-
})
|
|
843
|
+
});
|
|
792
844
|
};
|
|
793
845
|
|
|
794
846
|
/**
|
|
@@ -798,15 +850,15 @@
|
|
|
798
850
|
* @param callback - An optional callback after user has been saved on server
|
|
799
851
|
*/
|
|
800
852
|
|
|
801
|
-
Zzish.unauthUser = function (id,
|
|
802
|
-
|
|
853
|
+
Zzish.unauthUser = function (id, callback) {
|
|
854
|
+
const request = {
|
|
803
855
|
method: "POST",
|
|
804
|
-
url: getBaseUrl()
|
|
805
|
-
data: {}
|
|
856
|
+
url: `${getBaseUrl()}profiles/${id}/logout`,
|
|
857
|
+
data: {},
|
|
806
858
|
};
|
|
807
|
-
sendData(request,
|
|
859
|
+
sendData(request, (err, data) => {
|
|
808
860
|
callCallBack(err, data, callback);
|
|
809
|
-
})
|
|
861
|
+
});
|
|
810
862
|
};
|
|
811
863
|
|
|
812
864
|
/**
|
|
@@ -817,18 +869,18 @@
|
|
|
817
869
|
* @param callback - An optional callback after user has been saved on server
|
|
818
870
|
*/
|
|
819
871
|
Zzish.createUser = function (id, name, callback) {
|
|
820
|
-
|
|
821
|
-
uuid
|
|
822
|
-
name
|
|
872
|
+
const message = {
|
|
873
|
+
uuid: id,
|
|
874
|
+
name,
|
|
823
875
|
};
|
|
824
|
-
|
|
876
|
+
const request = {
|
|
825
877
|
method: "POST",
|
|
826
|
-
url: getBaseUrl()
|
|
827
|
-
data: message
|
|
878
|
+
url: `${getBaseUrl()}profiles`,
|
|
879
|
+
data: message,
|
|
828
880
|
};
|
|
829
|
-
sendData(request,
|
|
881
|
+
sendData(request, (err, data) => {
|
|
830
882
|
callCallBack(err, data, callback);
|
|
831
|
-
})
|
|
883
|
+
});
|
|
832
884
|
};
|
|
833
885
|
|
|
834
886
|
|
|
@@ -839,16 +891,16 @@
|
|
|
839
891
|
* @param callback - An optional callback after user has been saved on server
|
|
840
892
|
*/
|
|
841
893
|
Zzish.listGroups = function (profileId, callback) {
|
|
842
|
-
|
|
894
|
+
const request = {
|
|
843
895
|
method: "GET",
|
|
844
|
-
url: getBaseUrl()
|
|
896
|
+
url: `${getBaseUrl()}profiles/${profileId}/groups`,
|
|
845
897
|
};
|
|
846
|
-
sendData(request,
|
|
898
|
+
sendData(request, (err, data) => {
|
|
847
899
|
if (!err && data && data.payload) {
|
|
848
|
-
for (
|
|
849
|
-
|
|
850
|
-
link = replaceAll("\\\\","=====",link)
|
|
851
|
-
data.payload[i].link = webUrl
|
|
900
|
+
for (const i in data.payload) {
|
|
901
|
+
let link = replaceAll("/", "-----", data.payload[i].link);
|
|
902
|
+
link = replaceAll("\\\\", "=====", link);
|
|
903
|
+
data.payload[i].link = `${webUrl}learning-hub/tclassroom/${link}/live`;
|
|
852
904
|
}
|
|
853
905
|
}
|
|
854
906
|
callCallBack(err, data, callback);
|
|
@@ -863,13 +915,13 @@
|
|
|
863
915
|
* @param callback - An optional callback after user has been saved on server
|
|
864
916
|
*/
|
|
865
917
|
Zzish.listStudents = function (profileId, groupCode, callback) {
|
|
866
|
-
|
|
918
|
+
const request = {
|
|
867
919
|
method: "GET",
|
|
868
|
-
url: getBaseUrl()
|
|
920
|
+
url: `${getBaseUrl()}profiles/${profileId}/groups/code/${groupCode}/students`,
|
|
869
921
|
};
|
|
870
|
-
sendData(request,
|
|
922
|
+
sendData(request, (err, data) => {
|
|
871
923
|
callCallBack(err, data, callback);
|
|
872
|
-
})
|
|
924
|
+
});
|
|
873
925
|
};
|
|
874
926
|
|
|
875
927
|
|
|
@@ -880,17 +932,17 @@
|
|
|
880
932
|
* @param callback - An optional callback after user has been saved on server
|
|
881
933
|
*/
|
|
882
934
|
Zzish.listGroupContentForProfile = function (id, callback) {
|
|
883
|
-
|
|
935
|
+
const request = {
|
|
884
936
|
method: "GET",
|
|
885
|
-
url: getBaseUrl()
|
|
937
|
+
url: `${getBaseUrl()}profiles/${id}/groups/contents`,
|
|
886
938
|
};
|
|
887
|
-
sendData(request,
|
|
939
|
+
sendData(request, (err, data) => {
|
|
888
940
|
callCallBack(err, data, callback);
|
|
889
|
-
})
|
|
941
|
+
});
|
|
890
942
|
};
|
|
891
943
|
|
|
892
944
|
|
|
893
|
-
|
|
945
|
+
/** ** USER MANAGEMENT **** */
|
|
894
946
|
|
|
895
947
|
/**
|
|
896
948
|
* Authenticate based on user and password (which is md5') for app
|
|
@@ -903,21 +955,20 @@
|
|
|
903
955
|
*/
|
|
904
956
|
Zzish.authenticate = function (email, password, callback) {
|
|
905
957
|
if ((password==undefined || password =="") && (email=="" || email==undefined)) {
|
|
906
|
-
callback(400,"Email and Password are required");
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
password: password
|
|
958
|
+
callback(400, "Email and Password are required");
|
|
959
|
+
} else {
|
|
960
|
+
const message = {
|
|
961
|
+
email,
|
|
962
|
+
password,
|
|
912
963
|
};
|
|
913
|
-
|
|
964
|
+
const request = {
|
|
914
965
|
method: "POST",
|
|
915
|
-
url: getBaseUrl()
|
|
916
|
-
data: message
|
|
966
|
+
url: `${getBaseUrl()}profiles/authenticate`,
|
|
967
|
+
data: message,
|
|
917
968
|
};
|
|
918
|
-
sendData(request,
|
|
969
|
+
sendData(request, (err, data) => {
|
|
919
970
|
callCallBack(err, data, callback);
|
|
920
|
-
})
|
|
971
|
+
});
|
|
921
972
|
}
|
|
922
973
|
};
|
|
923
974
|
|
|
@@ -928,13 +979,13 @@
|
|
|
928
979
|
* @param callback - An optional callback after user has been saved on server
|
|
929
980
|
*/
|
|
930
981
|
Zzish.user = function (uuid, callback) {
|
|
931
|
-
|
|
982
|
+
const request = {
|
|
932
983
|
method: "GET",
|
|
933
|
-
url: getBaseUrl()
|
|
984
|
+
url: `${getBaseUrl()}profiles/authenticate/${uuid}`,
|
|
934
985
|
};
|
|
935
|
-
sendData(request,
|
|
986
|
+
sendData(request, (err, data) => {
|
|
936
987
|
callCallBack(err, data, callback);
|
|
937
|
-
})
|
|
988
|
+
});
|
|
938
989
|
};
|
|
939
990
|
|
|
940
991
|
/**
|
|
@@ -944,14 +995,14 @@
|
|
|
944
995
|
* @param callback - An optional callback after user has been saved on server
|
|
945
996
|
*/
|
|
946
997
|
Zzish.userByAttributes = function (attributes, callback) {
|
|
947
|
-
|
|
998
|
+
const request = {
|
|
948
999
|
method: "POST",
|
|
949
|
-
url: getBaseUrl()
|
|
950
|
-
data: attributes
|
|
1000
|
+
url: `${getBaseUrl()}profiles/authenticate/search`,
|
|
1001
|
+
data: attributes,
|
|
951
1002
|
};
|
|
952
|
-
sendData(request,
|
|
1003
|
+
sendData(request, (err, data) => {
|
|
953
1004
|
callCallBack(err, data, callback);
|
|
954
|
-
})
|
|
1005
|
+
});
|
|
955
1006
|
};
|
|
956
1007
|
|
|
957
1008
|
/**
|
|
@@ -962,18 +1013,18 @@
|
|
|
962
1013
|
* @param callback - An optional callback after user has been saved on server
|
|
963
1014
|
*/
|
|
964
1015
|
Zzish.registerUser = function (email, password, callback) {
|
|
965
|
-
|
|
966
|
-
email
|
|
967
|
-
password
|
|
1016
|
+
const message = {
|
|
1017
|
+
email,
|
|
1018
|
+
password,
|
|
968
1019
|
};
|
|
969
|
-
|
|
1020
|
+
const request = {
|
|
970
1021
|
method: "POST",
|
|
971
|
-
url: getBaseUrl()
|
|
972
|
-
data: message
|
|
1022
|
+
url: `${getBaseUrl()}profiles/authenticate/register`,
|
|
1023
|
+
data: message,
|
|
973
1024
|
};
|
|
974
|
-
sendData(request,
|
|
1025
|
+
sendData(request, (err, data) => {
|
|
975
1026
|
callCallBack(err, data, callback);
|
|
976
|
-
})
|
|
1027
|
+
});
|
|
977
1028
|
};
|
|
978
1029
|
|
|
979
1030
|
/**
|
|
@@ -983,14 +1034,14 @@
|
|
|
983
1034
|
* @param callback - An optional callback after user has been saved on server
|
|
984
1035
|
*/
|
|
985
1036
|
Zzish.updateUser = function (user, callback) {
|
|
986
|
-
|
|
1037
|
+
const request = {
|
|
987
1038
|
method: "POST",
|
|
988
|
-
url: getBaseUrl()
|
|
989
|
-
data: user
|
|
1039
|
+
url: `${getBaseUrl()}profiles/authenticate/update`,
|
|
1040
|
+
data: user,
|
|
990
1041
|
};
|
|
991
|
-
sendData(request,
|
|
1042
|
+
sendData(request, (err, data) => {
|
|
992
1043
|
callCallBack(err, data, callback);
|
|
993
|
-
})
|
|
1044
|
+
});
|
|
994
1045
|
};
|
|
995
1046
|
|
|
996
1047
|
/**
|
|
@@ -1001,14 +1052,14 @@
|
|
|
1001
1052
|
* @param callback - An optional callback after user has been saved on server
|
|
1002
1053
|
*/
|
|
1003
1054
|
Zzish.updatePassword = function (uuid, password, callback) {
|
|
1004
|
-
|
|
1055
|
+
const request = {
|
|
1005
1056
|
method: "POST",
|
|
1006
|
-
url: getBaseUrl()
|
|
1007
|
-
data: {password
|
|
1057
|
+
url: `${getBaseUrl()}profiles/authenticate/${uuid}/password`,
|
|
1058
|
+
data: { password },
|
|
1008
1059
|
};
|
|
1009
|
-
sendData(request,
|
|
1060
|
+
sendData(request, (err, data) => {
|
|
1010
1061
|
callCallBack(err, data, callback);
|
|
1011
|
-
})
|
|
1062
|
+
});
|
|
1012
1063
|
};
|
|
1013
1064
|
|
|
1014
1065
|
/**
|
|
@@ -1020,19 +1071,19 @@
|
|
|
1020
1071
|
* @param callback - An optional callback after user has been saved on server
|
|
1021
1072
|
*/
|
|
1022
1073
|
Zzish.registerUserWithZzish = function (userId, email, name, callback) {
|
|
1023
|
-
|
|
1024
|
-
email
|
|
1074
|
+
const message = {
|
|
1075
|
+
email,
|
|
1025
1076
|
profile: {
|
|
1026
1077
|
uuid: userId,
|
|
1027
|
-
name
|
|
1028
|
-
}
|
|
1078
|
+
name,
|
|
1079
|
+
},
|
|
1029
1080
|
};
|
|
1030
|
-
|
|
1081
|
+
const request = {
|
|
1031
1082
|
method: "POST",
|
|
1032
|
-
url: getBaseUrl()
|
|
1033
|
-
data: message
|
|
1083
|
+
url: `${getBaseUrl()}profiles/authenticate/eregister`,
|
|
1084
|
+
data: message,
|
|
1034
1085
|
};
|
|
1035
|
-
sendData(request,
|
|
1086
|
+
sendData(request, (err, data) => {
|
|
1036
1087
|
callCallBack(err, data, callback);
|
|
1037
1088
|
});
|
|
1038
1089
|
};
|
|
@@ -1044,23 +1095,23 @@
|
|
|
1044
1095
|
* @param callback - An optional callback after user has been saved on server
|
|
1045
1096
|
*/
|
|
1046
1097
|
Zzish.getTokenForUser = function (userId, callback) {
|
|
1047
|
-
|
|
1048
|
-
uuid: userId
|
|
1098
|
+
const message = {
|
|
1099
|
+
uuid: userId,
|
|
1049
1100
|
};
|
|
1050
|
-
|
|
1101
|
+
const request = {
|
|
1051
1102
|
method: "POST",
|
|
1052
|
-
url: getBaseUrl()
|
|
1053
|
-
data: message
|
|
1103
|
+
url: `${getBaseUrl()}profiles/authenticate/token`,
|
|
1104
|
+
data: message,
|
|
1054
1105
|
};
|
|
1055
|
-
sendData(request,
|
|
1056
|
-
callCallBack(err, data,
|
|
1057
|
-
|
|
1106
|
+
sendData(request, (err, data) => {
|
|
1107
|
+
callCallBack(err, data, (err, message) => {
|
|
1108
|
+
const url = `${webUrl}account/app/${message}/token`;
|
|
1058
1109
|
callback(err, url);
|
|
1059
1110
|
});
|
|
1060
1111
|
});
|
|
1061
1112
|
};
|
|
1062
1113
|
|
|
1063
|
-
|
|
1114
|
+
/** ** BACKEND CONTENT STUFF ** */
|
|
1064
1115
|
|
|
1065
1116
|
/**
|
|
1066
1117
|
* Save a Zzish content object
|
|
@@ -1071,19 +1122,18 @@
|
|
|
1071
1122
|
* @param content - The JSON object to save
|
|
1072
1123
|
* @param callback - An optional callback to call when done (returns error,message)
|
|
1073
1124
|
*/
|
|
1074
|
-
Zzish.postContent = function (profileId, type, uuid,meta,
|
|
1075
|
-
|
|
1076
|
-
uuid
|
|
1077
|
-
meta
|
|
1078
|
-
|
|
1079
|
-
payload: JSON.stringify(content)
|
|
1125
|
+
Zzish.postContent = function (profileId, type, uuid, meta, content, callback) {
|
|
1126
|
+
const data = {
|
|
1127
|
+
uuid,
|
|
1128
|
+
meta,
|
|
1129
|
+
payload: JSON.stringify(content),
|
|
1080
1130
|
};
|
|
1081
|
-
|
|
1131
|
+
const request = {
|
|
1082
1132
|
method: "POST",
|
|
1083
|
-
url: getBaseUrl()
|
|
1084
|
-
data
|
|
1133
|
+
url: `${getBaseUrl()}profiles/${profileId}/contents/${type}/${uuid}`,
|
|
1134
|
+
data,
|
|
1085
1135
|
};
|
|
1086
|
-
sendData(request,
|
|
1136
|
+
sendData(request, (err, data) => {
|
|
1087
1137
|
callCallBack(err, data, callback);
|
|
1088
1138
|
});
|
|
1089
1139
|
};
|
|
@@ -1099,18 +1149,18 @@
|
|
|
1099
1149
|
* @param callback - An optional callback to call when done (returns error,message)
|
|
1100
1150
|
*/
|
|
1101
1151
|
Zzish.postContentTagged = function (profileId, type, uuid, meta, content, tags, callback) {
|
|
1102
|
-
|
|
1103
|
-
uuid
|
|
1104
|
-
meta
|
|
1152
|
+
const data = {
|
|
1153
|
+
uuid,
|
|
1154
|
+
meta,
|
|
1105
1155
|
payload: JSON.stringify(content),
|
|
1106
|
-
tags
|
|
1156
|
+
tags,
|
|
1107
1157
|
};
|
|
1108
|
-
|
|
1158
|
+
const request = {
|
|
1109
1159
|
method: "POST",
|
|
1110
|
-
url: getBaseUrl()
|
|
1111
|
-
data
|
|
1160
|
+
url: `${getBaseUrl()}profiles/${profileId}/contents/${type}/${uuid}`,
|
|
1161
|
+
data,
|
|
1112
1162
|
};
|
|
1113
|
-
sendData(request,
|
|
1163
|
+
sendData(request, (err, data) => {
|
|
1114
1164
|
callCallBack(err, data, callback);
|
|
1115
1165
|
});
|
|
1116
1166
|
};
|
|
@@ -1123,47 +1173,48 @@
|
|
|
1123
1173
|
* @param callback - An optional callback to call when done (returns error,message)
|
|
1124
1174
|
*/
|
|
1125
1175
|
Zzish.deleteContent = function (profileId, type, id, callback) {
|
|
1126
|
-
|
|
1176
|
+
const request = {
|
|
1127
1177
|
method: "DELETE",
|
|
1128
|
-
url: getBaseUrl()
|
|
1178
|
+
url: `${getBaseUrl()}profiles/${profileId}/contents/${type}/${id}`,
|
|
1129
1179
|
};
|
|
1130
|
-
sendData(request,
|
|
1180
|
+
sendData(request, (err, data) => {
|
|
1131
1181
|
callCallBack(err, data, callback);
|
|
1132
1182
|
});
|
|
1133
1183
|
};
|
|
1134
1184
|
|
|
1135
|
-
|
|
1185
|
+
const formatContentObject = function (content, includePayload) {
|
|
1136
1186
|
if (content) {
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
meta
|
|
1142
|
-
attributes
|
|
1187
|
+
const { uuid, type, meta, attributes, payload, gameSessionStatus } = content;
|
|
1188
|
+
const result = {
|
|
1189
|
+
uuid,
|
|
1190
|
+
type,
|
|
1191
|
+
meta,
|
|
1192
|
+
attributes,
|
|
1193
|
+
gameSessionStatus,
|
|
1143
1194
|
};
|
|
1144
|
-
if (includePayload &&
|
|
1145
|
-
result.payload = JSON.parse(
|
|
1195
|
+
if (includePayload && payload!==undefined && payload!="") {
|
|
1196
|
+
result.payload = JSON.parse(payload);
|
|
1146
1197
|
}
|
|
1147
1198
|
return result;
|
|
1148
1199
|
}
|
|
1149
1200
|
return null;
|
|
1150
1201
|
};
|
|
1151
1202
|
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
if (data){
|
|
1155
|
-
for (
|
|
1156
|
-
list.push(formatContentObject(data.payload[i],includePayload));
|
|
1203
|
+
const formatListContents = function (data, includePayload) {
|
|
1204
|
+
const list = [];
|
|
1205
|
+
if (data) {
|
|
1206
|
+
for (const i in data.payload) {
|
|
1207
|
+
list.push(formatContentObject(data.payload[i], includePayload));
|
|
1157
1208
|
}
|
|
1158
1209
|
}
|
|
1159
1210
|
return list;
|
|
1160
1211
|
};
|
|
1161
1212
|
|
|
1162
|
-
|
|
1163
|
-
if (data && data.payload.contents){
|
|
1164
|
-
|
|
1165
|
-
for (
|
|
1166
|
-
|
|
1213
|
+
const formatListCategoryContents = function (data) {
|
|
1214
|
+
if (data && data.payload.contents) {
|
|
1215
|
+
const list = [];
|
|
1216
|
+
for (const i in data.payload.contents) {
|
|
1217
|
+
const result = formatContentObject(data.payload.contents[i], false);
|
|
1167
1218
|
list.push(result);
|
|
1168
1219
|
}
|
|
1169
1220
|
data.payload.contents = list;
|
|
@@ -1180,21 +1231,19 @@
|
|
|
1180
1231
|
* @param callback - A callback to call when done (returns error AND (message or data))
|
|
1181
1232
|
*/
|
|
1182
1233
|
Zzish.getContent = function (profileId, type, uuid, callback) {
|
|
1183
|
-
|
|
1234
|
+
const request = {
|
|
1184
1235
|
method: "GET",
|
|
1185
|
-
url: getBaseUrl()
|
|
1236
|
+
url: `${getBaseUrl()}profiles/${profileId}/contents/${type}/${uuid}`,
|
|
1186
1237
|
};
|
|
1187
|
-
sendData(request,
|
|
1188
|
-
callCallBack(err, data,
|
|
1238
|
+
sendData(request, (err, data) => {
|
|
1239
|
+
callCallBack(err, data, (status, message) => {
|
|
1189
1240
|
if (!err) {
|
|
1190
1241
|
if (data && data.payload!==undefined && data.payload!=null) {
|
|
1191
|
-
callback(err,formatContentObject(data.payload,true));
|
|
1192
|
-
}
|
|
1193
|
-
else {
|
|
1242
|
+
callback(err, formatContentObject(data.payload, true));
|
|
1243
|
+
} else {
|
|
1194
1244
|
callback("Invalid Data");
|
|
1195
1245
|
}
|
|
1196
|
-
}
|
|
1197
|
-
else {
|
|
1246
|
+
} else {
|
|
1198
1247
|
callback(status, message);
|
|
1199
1248
|
}
|
|
1200
1249
|
});
|
|
@@ -1209,27 +1258,51 @@
|
|
|
1209
1258
|
* @param callback - A callback to call when done (returns error AND (message or data))
|
|
1210
1259
|
*/
|
|
1211
1260
|
Zzish.getAssignment = function (profileId, type, uuid, callback) {
|
|
1212
|
-
|
|
1261
|
+
const request = {
|
|
1213
1262
|
method: "GET",
|
|
1214
|
-
url: getBaseUrl()
|
|
1263
|
+
url: `${getBaseUrl()}profiles/${profileId}/contents/${type}/assignments/${uuid}`,
|
|
1215
1264
|
};
|
|
1216
|
-
sendData(request,
|
|
1217
|
-
callCallBack(err, data,
|
|
1265
|
+
sendData(request, (err, data) => {
|
|
1266
|
+
callCallBack(err, data, (status, message) => {
|
|
1218
1267
|
if (!err) {
|
|
1219
1268
|
if (data && data.payload!==undefined && data.payload!=null) {
|
|
1220
|
-
callback(err,formatContentObject(data.payload,true));
|
|
1221
|
-
}
|
|
1222
|
-
else {
|
|
1269
|
+
callback(err, formatContentObject(data.payload, true));
|
|
1270
|
+
} else {
|
|
1223
1271
|
callback("Invalid Data");
|
|
1224
1272
|
}
|
|
1225
|
-
}
|
|
1226
|
-
else {
|
|
1273
|
+
} else {
|
|
1227
1274
|
callback(status, message);
|
|
1228
1275
|
}
|
|
1229
1276
|
});
|
|
1230
1277
|
});
|
|
1231
1278
|
};
|
|
1232
1279
|
|
|
1280
|
+
/**
|
|
1281
|
+
* Get the Zzish assignment's associated game session status
|
|
1282
|
+
* @param profileId - The id of the profile to which to get the content for
|
|
1283
|
+
* @param type - The content type
|
|
1284
|
+
* @param uuid - THe uuid of the student assignement
|
|
1285
|
+
* @param callback - A callback to call when done (returns error AND (message or data))
|
|
1286
|
+
*/
|
|
1287
|
+
Zzish.getAssignmentGameSessionStatus = function (profileId, type, uuid, callback) {
|
|
1288
|
+
const request = {
|
|
1289
|
+
method: "GET",
|
|
1290
|
+
url: `${getBaseUrl()}profiles/${profileId}/contents/${type}/assignments/${uuid}/status`,
|
|
1291
|
+
};
|
|
1292
|
+
sendData(request, (err, data) => {
|
|
1293
|
+
callCallBack(err, data, (status, message) => {
|
|
1294
|
+
if (!err) {
|
|
1295
|
+
if (data) {
|
|
1296
|
+
callback(err, data);
|
|
1297
|
+
} else {
|
|
1298
|
+
callback("Invalid Data");
|
|
1299
|
+
}
|
|
1300
|
+
} else {
|
|
1301
|
+
callback(status, message);
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
});
|
|
1305
|
+
};
|
|
1233
1306
|
|
|
1234
1307
|
|
|
1235
1308
|
/**
|
|
@@ -1240,22 +1313,19 @@
|
|
|
1240
1313
|
* @param callback - A callback to call when done (returns error AND (message or data))
|
|
1241
1314
|
*/
|
|
1242
1315
|
Zzish.getContents = function (profileId, type, uuids, callback) {
|
|
1243
|
-
|
|
1244
|
-
method: "
|
|
1245
|
-
url: getBaseUrl()
|
|
1246
|
-
data: uuids
|
|
1316
|
+
const request = {
|
|
1317
|
+
method: "GET",
|
|
1318
|
+
url: `${getBaseUrl()}profiles/${profileId}/contents/${type}/list/${encodeURIComponent(uuids.join(";"))}`,
|
|
1247
1319
|
};
|
|
1248
|
-
sendData(request,
|
|
1249
|
-
callCallBack(err, data,
|
|
1320
|
+
sendData(request, (err, data) => {
|
|
1321
|
+
callCallBack(err, data, (status, message) => {
|
|
1250
1322
|
if (!err) {
|
|
1251
1323
|
if (data && data.payload!==undefined && data.payload!=null) {
|
|
1252
|
-
callback(err, formatListContents(data,true));
|
|
1253
|
-
}
|
|
1254
|
-
else {
|
|
1324
|
+
callback(err, formatListContents(data, true));
|
|
1325
|
+
} else {
|
|
1255
1326
|
callback("Invalid Data");
|
|
1256
1327
|
}
|
|
1257
|
-
}
|
|
1258
|
-
else {
|
|
1328
|
+
} else {
|
|
1259
1329
|
callback(status, message);
|
|
1260
1330
|
}
|
|
1261
1331
|
});
|
|
@@ -1264,18 +1334,17 @@
|
|
|
1264
1334
|
|
|
1265
1335
|
|
|
1266
1336
|
function convertToParameters(obj) {
|
|
1267
|
-
|
|
1268
|
-
for (
|
|
1337
|
+
let str = "";
|
|
1338
|
+
for (const key in obj) {
|
|
1269
1339
|
if (str != "") {
|
|
1270
1340
|
str += "&";
|
|
1271
1341
|
}
|
|
1272
1342
|
if (Array.isArray(obj[key])) {
|
|
1273
|
-
for (
|
|
1274
|
-
str += key
|
|
1343
|
+
for (const i in obj[key]) {
|
|
1344
|
+
str += `${key}=${encodeURIComponent(JSON.stringify(obj[key][i]))}`;
|
|
1275
1345
|
}
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
str += key + "=" + encodeURIComponent(JSON.stringify(obj[key]));
|
|
1346
|
+
} else {
|
|
1347
|
+
str += `${key}=${encodeURIComponent(JSON.stringify(obj[key]))}`;
|
|
1279
1348
|
}
|
|
1280
1349
|
}
|
|
1281
1350
|
return str;
|
|
@@ -1288,16 +1357,15 @@
|
|
|
1288
1357
|
* @param callback - A callback to call when done (returns error AND (message or data))
|
|
1289
1358
|
*/
|
|
1290
1359
|
Zzish.searchPublicContent = function (type, meta, callback) {
|
|
1291
|
-
|
|
1360
|
+
const request = {
|
|
1292
1361
|
method: "GET",
|
|
1293
|
-
url: getBaseUrl()
|
|
1362
|
+
url: `${getBaseUrl()}profiles/publicconsumers/${type}/search?${convertToParameters(meta)}`,
|
|
1294
1363
|
};
|
|
1295
|
-
sendData(request,
|
|
1296
|
-
callCallBack(err, data,
|
|
1364
|
+
sendData(request, (err, data) => {
|
|
1365
|
+
callCallBack(err, data, (status, message) => {
|
|
1297
1366
|
if (!err) {
|
|
1298
|
-
callback(err, formatListContents(data,false));
|
|
1299
|
-
}
|
|
1300
|
-
else {
|
|
1367
|
+
callback(err, formatListContents(data, false));
|
|
1368
|
+
} else {
|
|
1301
1369
|
callback(status, message);
|
|
1302
1370
|
}
|
|
1303
1371
|
});
|
|
@@ -1312,16 +1380,15 @@
|
|
|
1312
1380
|
* @param callback - A callback to call when done (returns error AND (message or data))
|
|
1313
1381
|
*/
|
|
1314
1382
|
Zzish.searchContent = function (profileId, type, meta, callback) {
|
|
1315
|
-
|
|
1383
|
+
const request = {
|
|
1316
1384
|
method: "GET",
|
|
1317
|
-
url: getBaseUrl()
|
|
1385
|
+
url: `${getBaseUrl()}profiles/${profileId}/contents/${type}/search?${convertToParameters(meta)}`,
|
|
1318
1386
|
};
|
|
1319
|
-
sendData(request,
|
|
1320
|
-
callCallBack(err, data,
|
|
1387
|
+
sendData(request, (err, data) => {
|
|
1388
|
+
callCallBack(err, data, (status, message) => {
|
|
1321
1389
|
if (!err) {
|
|
1322
|
-
callback(err, formatListContents(data,false));
|
|
1323
|
-
}
|
|
1324
|
-
else {
|
|
1390
|
+
callback(err, formatListContents(data, false));
|
|
1391
|
+
} else {
|
|
1325
1392
|
callback(status, message);
|
|
1326
1393
|
}
|
|
1327
1394
|
});
|
|
@@ -1335,16 +1402,15 @@
|
|
|
1335
1402
|
* @param callback - A callback to call when done (returns error AND (message or list of zzish,name))
|
|
1336
1403
|
*/
|
|
1337
1404
|
Zzish.listContent = function (profileId, type, callback) {
|
|
1338
|
-
|
|
1405
|
+
const request = {
|
|
1339
1406
|
method: "GET",
|
|
1340
|
-
url: getBaseUrl()
|
|
1407
|
+
url: `${getBaseUrl()}profiles/${profileId}/contents/${type}`,
|
|
1341
1408
|
};
|
|
1342
|
-
sendData(request,
|
|
1343
|
-
callCallBack(err, data,
|
|
1409
|
+
sendData(request, (err, data) => {
|
|
1410
|
+
callCallBack(err, data, (status, message) => {
|
|
1344
1411
|
if (!err) {
|
|
1345
|
-
callback(err, formatListContents(data,false));
|
|
1346
|
-
}
|
|
1347
|
-
else {
|
|
1412
|
+
callback(err, formatListContents(data, false));
|
|
1413
|
+
} else {
|
|
1348
1414
|
callback(status, message);
|
|
1349
1415
|
}
|
|
1350
1416
|
});
|
|
@@ -1365,12 +1431,12 @@
|
|
|
1365
1431
|
* @param callback - A callback to call when done (returns error AND (message or list of zzish,name))
|
|
1366
1432
|
*/
|
|
1367
1433
|
Zzish.publishContent = function (profileId, type, uuid, options, callback) {
|
|
1368
|
-
|
|
1434
|
+
const request = {
|
|
1369
1435
|
method: "POST",
|
|
1370
|
-
url: getBaseUrl()
|
|
1371
|
-
data: options
|
|
1436
|
+
url: `${getBaseUrl()}profiles/${profileId}/contents/${type}/${uuid}/publish`,
|
|
1437
|
+
data: options,
|
|
1372
1438
|
};
|
|
1373
|
-
sendData(request,
|
|
1439
|
+
sendData(request, (err, data) => {
|
|
1374
1440
|
callCallBack(err, data, callback);
|
|
1375
1441
|
});
|
|
1376
1442
|
};
|
|
@@ -1383,13 +1449,13 @@
|
|
|
1383
1449
|
* @param groupCode - The Zzish code of an existing class
|
|
1384
1450
|
* @param callback - A callback to call when done (returns error AND (message or list of zzish,name))
|
|
1385
1451
|
*/
|
|
1386
|
-
Zzish.unpublishContent
|
|
1387
|
-
|
|
1452
|
+
Zzish.unpublishContent = function (profileId, type, uuid, groupCode, callback) {
|
|
1453
|
+
const request = {
|
|
1388
1454
|
method: "POST",
|
|
1389
|
-
url: getBaseUrl()
|
|
1390
|
-
data: {}
|
|
1455
|
+
url: `${getBaseUrl()}profiles/${profileId}/contents/${type}/${uuid}/${groupCode}/unpublish`,
|
|
1456
|
+
data: {},
|
|
1391
1457
|
};
|
|
1392
|
-
sendData(request,
|
|
1458
|
+
sendData(request, (err, data) => {
|
|
1393
1459
|
callCallBack(err, data, callback);
|
|
1394
1460
|
});
|
|
1395
1461
|
};
|
|
@@ -1402,21 +1468,20 @@
|
|
|
1402
1468
|
* @param callback - A callback to be called after message is sent (returns error,message)
|
|
1403
1469
|
*
|
|
1404
1470
|
*/
|
|
1405
|
-
Zzish.listContentForGroup = function(profileId, code, callback) {
|
|
1406
|
-
|
|
1471
|
+
Zzish.listContentForGroup = function (profileId, code, callback) {
|
|
1472
|
+
const request = {
|
|
1407
1473
|
method: "GET",
|
|
1408
|
-
url: getBaseUrl()
|
|
1474
|
+
url: `${getBaseUrl()}profiles/${profileId}/consumers/${code}`,
|
|
1409
1475
|
};
|
|
1410
|
-
sendData(request,
|
|
1411
|
-
callCallBack(err, data,
|
|
1476
|
+
sendData(request, (err, data) => {
|
|
1477
|
+
callCallBack(err, data, (status, message) => {
|
|
1412
1478
|
if (!err) {
|
|
1413
1479
|
callback(err, formatListCategoryContents(data));
|
|
1414
|
-
}
|
|
1415
|
-
else {
|
|
1480
|
+
} else {
|
|
1416
1481
|
callback(status, message);
|
|
1417
1482
|
}
|
|
1418
1483
|
});
|
|
1419
|
-
})
|
|
1484
|
+
});
|
|
1420
1485
|
};
|
|
1421
1486
|
|
|
1422
1487
|
/**
|
|
@@ -1427,22 +1492,21 @@
|
|
|
1427
1492
|
* @param callback - A callback to be called after message is sent (returns error,message)
|
|
1428
1493
|
*
|
|
1429
1494
|
*/
|
|
1430
|
-
Zzish.registerUserWithGroup = function(profileId, code, callback) {
|
|
1431
|
-
|
|
1495
|
+
Zzish.registerUserWithGroup = function (profileId, code, callback) {
|
|
1496
|
+
const request = {
|
|
1432
1497
|
method: "POST",
|
|
1433
|
-
url: getBaseUrl()
|
|
1434
|
-
data: {}
|
|
1498
|
+
url: `${getBaseUrl()}profiles/${profileId}/consumers/${code}/register`,
|
|
1499
|
+
data: {},
|
|
1435
1500
|
};
|
|
1436
|
-
sendData(request,
|
|
1437
|
-
callCallBack(err, data,
|
|
1501
|
+
sendData(request, (err, data) => {
|
|
1502
|
+
callCallBack(err, data, (status, message) => {
|
|
1438
1503
|
if (!err) {
|
|
1439
1504
|
callback(err, formatListCategoryContents(data));
|
|
1440
|
-
}
|
|
1441
|
-
else {
|
|
1505
|
+
} else {
|
|
1442
1506
|
callback(status, message);
|
|
1443
1507
|
}
|
|
1444
1508
|
});
|
|
1445
|
-
})
|
|
1509
|
+
});
|
|
1446
1510
|
};
|
|
1447
1511
|
|
|
1448
1512
|
/**
|
|
@@ -1466,11 +1530,11 @@
|
|
|
1466
1530
|
|
|
1467
1531
|
*/
|
|
1468
1532
|
Zzish.getUserResults = function (profileId, parameters, callback) {
|
|
1469
|
-
|
|
1533
|
+
const request = {
|
|
1470
1534
|
method: "GET",
|
|
1471
|
-
url: getBaseUrl()
|
|
1535
|
+
url: `${getBaseUrl()}statements/${profileId}/results?${convertToParameters(parameters)}`,
|
|
1472
1536
|
};
|
|
1473
|
-
sendData(request,
|
|
1537
|
+
sendData(request, (err, data) => {
|
|
1474
1538
|
callCallBack(err, data, callback);
|
|
1475
1539
|
});
|
|
1476
1540
|
};
|
|
@@ -1492,17 +1556,16 @@
|
|
|
1492
1556
|
|
|
1493
1557
|
*/
|
|
1494
1558
|
Zzish.loadPracticeQuiz = function (profileId, parameters, callback) {
|
|
1495
|
-
|
|
1559
|
+
const request = {
|
|
1496
1560
|
method: "GET",
|
|
1497
|
-
url: getBaseUrl()
|
|
1561
|
+
url: `${getBaseUrl()}profiles/${profileId}/consumers/practice?${convertToParameters(parameters)}`,
|
|
1498
1562
|
};
|
|
1499
|
-
sendData(request,
|
|
1563
|
+
sendData(request, (err, data) => {
|
|
1500
1564
|
callCallBack(err, data, callback);
|
|
1501
1565
|
});
|
|
1502
1566
|
};
|
|
1503
1567
|
|
|
1504
1568
|
|
|
1505
|
-
|
|
1506
1569
|
/**
|
|
1507
1570
|
* Get results for Zzish content object
|
|
1508
1571
|
* @param profileId - The id of the profile to which to get the content for
|
|
@@ -1511,11 +1574,11 @@
|
|
|
1511
1574
|
* @param callback - A callback to call when done (returns error AND (message or data))
|
|
1512
1575
|
*/
|
|
1513
1576
|
Zzish.getContentResults = function (profileId, type, uuid, callback) {
|
|
1514
|
-
|
|
1577
|
+
const request = {
|
|
1515
1578
|
method: "GET",
|
|
1516
|
-
url: getBaseUrl()
|
|
1579
|
+
url: `${getBaseUrl()}profiles/${profileId}/contents/${type}/${uuid}/results`,
|
|
1517
1580
|
};
|
|
1518
|
-
sendData(request,
|
|
1581
|
+
sendData(request, (err, data) => {
|
|
1519
1582
|
callCallBack(err, data, callback);
|
|
1520
1583
|
});
|
|
1521
1584
|
};
|
|
@@ -1527,11 +1590,11 @@
|
|
|
1527
1590
|
* @param callback - A callback to call when done (returns error AND (message or data))
|
|
1528
1591
|
*/
|
|
1529
1592
|
Zzish.getPublicContentResults = function (type, uuid, callback) {
|
|
1530
|
-
|
|
1593
|
+
const request = {
|
|
1531
1594
|
method: "GET",
|
|
1532
|
-
url: getBaseUrl()
|
|
1595
|
+
url: `${getBaseUrl()}profiles/publicconsumers/${type}/${uuid}/results`,
|
|
1533
1596
|
};
|
|
1534
|
-
sendData(request,
|
|
1597
|
+
sendData(request, (err, data) => {
|
|
1535
1598
|
callCallBack(err, data, callback);
|
|
1536
1599
|
});
|
|
1537
1600
|
};
|
|
@@ -1542,22 +1605,20 @@
|
|
|
1542
1605
|
* @param uuid - The Zzish content (JSON)
|
|
1543
1606
|
* @param callback - A callback to call when done (returns error AND (message or data))
|
|
1544
1607
|
*/
|
|
1545
|
-
Zzish.getPublicContent = function (type,uuid, callback) {
|
|
1546
|
-
|
|
1608
|
+
Zzish.getPublicContent = function (type, uuid, callback) {
|
|
1609
|
+
const request = {
|
|
1547
1610
|
method: "GET",
|
|
1548
|
-
url: getBaseUrl()
|
|
1611
|
+
url: `${getBaseUrl()}profiles/publicconsumers/${type}/${uuid}`,
|
|
1549
1612
|
};
|
|
1550
|
-
sendData(request,
|
|
1551
|
-
callCallBack(err, data,
|
|
1613
|
+
sendData(request, (err, data) => {
|
|
1614
|
+
callCallBack(err, data, (status, message) => {
|
|
1552
1615
|
if (!err) {
|
|
1553
1616
|
if (data) {
|
|
1554
|
-
callback(err,formatContentObject(data.payload,true));
|
|
1555
|
-
}
|
|
1556
|
-
else {
|
|
1617
|
+
callback(err, formatContentObject(data.payload, true));
|
|
1618
|
+
} else {
|
|
1557
1619
|
callback(status, message);
|
|
1558
1620
|
}
|
|
1559
|
-
}
|
|
1560
|
-
else {
|
|
1621
|
+
} else {
|
|
1561
1622
|
callback(status, message);
|
|
1562
1623
|
}
|
|
1563
1624
|
});
|
|
@@ -1570,17 +1631,16 @@
|
|
|
1570
1631
|
* @param code - The Zzish content code
|
|
1571
1632
|
* @param callback - A callback to call when done (returns error AND (message or data))
|
|
1572
1633
|
*/
|
|
1573
|
-
Zzish.getPublicContentByCode = function (type,code, callback) {
|
|
1574
|
-
|
|
1634
|
+
Zzish.getPublicContentByCode = function (type, code, callback) {
|
|
1635
|
+
const request = {
|
|
1575
1636
|
method: "GET",
|
|
1576
|
-
url: getBaseUrl()
|
|
1637
|
+
url: `${getBaseUrl()}profiles/publicconsumers/${type}/code/${code}`,
|
|
1577
1638
|
};
|
|
1578
|
-
sendData(request,
|
|
1579
|
-
callCallBack(err, data,
|
|
1639
|
+
sendData(request, (err, data) => {
|
|
1640
|
+
callCallBack(err, data, (status, message) => {
|
|
1580
1641
|
if (!err) {
|
|
1581
|
-
callback(err,formatContentObject(data.payload,true));
|
|
1582
|
-
}
|
|
1583
|
-
else {
|
|
1642
|
+
callback(err, formatContentObject(data.payload, true));
|
|
1643
|
+
} else {
|
|
1584
1644
|
callback(status, message);
|
|
1585
1645
|
}
|
|
1586
1646
|
});
|
|
@@ -1592,17 +1652,16 @@
|
|
|
1592
1652
|
* @param type - The content type
|
|
1593
1653
|
* @param callback - A callback to call when done (returns error AND (message or list of zzish,name))
|
|
1594
1654
|
*/
|
|
1595
|
-
Zzish.listPublicContent = function (type,callback) {
|
|
1596
|
-
|
|
1655
|
+
Zzish.listPublicContent = function (type, callback) {
|
|
1656
|
+
const request = {
|
|
1597
1657
|
method: "GET",
|
|
1598
|
-
url: getBaseUrl()
|
|
1658
|
+
url: `${getBaseUrl()}profiles/publicconsumers/${type}`,
|
|
1599
1659
|
};
|
|
1600
|
-
sendData(request,
|
|
1601
|
-
callCallBack(err, data,
|
|
1660
|
+
sendData(request, (err, data) => {
|
|
1661
|
+
callCallBack(err, data, (status, message) => {
|
|
1602
1662
|
if (!err) {
|
|
1603
1663
|
callback(err, formatListCategoryContents(data));
|
|
1604
|
-
}
|
|
1605
|
-
else {
|
|
1664
|
+
} else {
|
|
1606
1665
|
callback(status, message);
|
|
1607
1666
|
}
|
|
1608
1667
|
});
|
|
@@ -1616,12 +1675,12 @@
|
|
|
1616
1675
|
* @param callback - An optional callback to call when done (returns error,message)
|
|
1617
1676
|
*/
|
|
1618
1677
|
Zzish.postCategory = function (profileId, category, callback) {
|
|
1619
|
-
|
|
1678
|
+
const request = {
|
|
1620
1679
|
method: "POST",
|
|
1621
|
-
url: getBaseUrl()
|
|
1622
|
-
data: category
|
|
1680
|
+
url: `${getBaseUrl()}profiles/${profileId}/categories/`,
|
|
1681
|
+
data: category,
|
|
1623
1682
|
};
|
|
1624
|
-
sendData(request,
|
|
1683
|
+
sendData(request, (err, data) => {
|
|
1625
1684
|
callCallBack(err, data, callback);
|
|
1626
1685
|
});
|
|
1627
1686
|
};
|
|
@@ -1633,11 +1692,11 @@
|
|
|
1633
1692
|
* @param callback - An optional callback to call when done (returns error,message)
|
|
1634
1693
|
*/
|
|
1635
1694
|
Zzish.deleteCategory = function (profileId, id, callback) {
|
|
1636
|
-
|
|
1695
|
+
const request = {
|
|
1637
1696
|
method: "DELETE",
|
|
1638
|
-
url: getBaseUrl()
|
|
1697
|
+
url: `${getBaseUrl()}profiles/${profileId}/categories/${id}`,
|
|
1639
1698
|
};
|
|
1640
|
-
sendData(request,
|
|
1699
|
+
sendData(request, (err, data) => {
|
|
1641
1700
|
callCallBack(err, data, callback);
|
|
1642
1701
|
});
|
|
1643
1702
|
};
|
|
@@ -1648,36 +1707,35 @@
|
|
|
1648
1707
|
* @param callback - A callback to call when done (returns error AND (message or list of zzish,name))
|
|
1649
1708
|
*/
|
|
1650
1709
|
Zzish.listCategories = function (profileId, callback) {
|
|
1651
|
-
|
|
1710
|
+
const request = {
|
|
1652
1711
|
method: "GET",
|
|
1653
|
-
url: getBaseUrl()
|
|
1712
|
+
url: `${getBaseUrl()}profiles/${profileId}/categories`,
|
|
1654
1713
|
};
|
|
1655
|
-
sendData(request,
|
|
1714
|
+
sendData(request, (err, data) => {
|
|
1656
1715
|
callCallBack(err, data, callback);
|
|
1657
1716
|
});
|
|
1658
1717
|
};
|
|
1659
1718
|
|
|
1660
|
-
|
|
1719
|
+
/** ** USER STUFF ** */
|
|
1661
1720
|
|
|
1662
1721
|
|
|
1663
|
-
function loadLoginWithToken(type,params,callback) {
|
|
1664
|
-
sendEvent("LOGIN")
|
|
1665
|
-
|
|
1722
|
+
function loadLoginWithToken(type, params, callback) {
|
|
1723
|
+
// REMOVED: sendEvent("LOGIN") - AppEvents disabled
|
|
1724
|
+
const url = `${webUrl}account/applogin?token=${params.token}`;
|
|
1666
1725
|
if (type=="pop") {
|
|
1667
|
-
|
|
1726
|
+
const win = window.open(url, "Zzish Login", "width=800, height=600");
|
|
1668
1727
|
var pollTimer = window.setInterval(
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1728
|
+
() => {
|
|
1729
|
+
try {
|
|
1730
|
+
if (win.document.URL.indexOf(webUrl) === -1) {
|
|
1731
|
+
window.clearInterval(pollTimer);
|
|
1732
|
+
win.close();
|
|
1733
|
+
Zzish.getCurrentUser(token, callback);
|
|
1734
|
+
}
|
|
1735
|
+
} catch (e) {
|
|
1675
1736
|
}
|
|
1676
|
-
} catch(e) {
|
|
1677
|
-
}
|
|
1678
1737
|
}, 500);
|
|
1679
|
-
}
|
|
1680
|
-
else {
|
|
1738
|
+
} else {
|
|
1681
1739
|
window.location.href = url;
|
|
1682
1740
|
}
|
|
1683
1741
|
}
|
|
@@ -1688,46 +1746,44 @@
|
|
|
1688
1746
|
* @param options - a list of optinos for token
|
|
1689
1747
|
* @param callback - A callback to call when done (returns error AND (message or user))
|
|
1690
1748
|
*/
|
|
1691
|
-
Zzish.createToken = function (type,options,callback) {
|
|
1692
|
-
|
|
1749
|
+
Zzish.createToken = function (type, options, callback) {
|
|
1750
|
+
const token_request = {
|
|
1693
1751
|
method: "POST",
|
|
1694
|
-
url: getBaseUrl()
|
|
1695
|
-
data: { options
|
|
1752
|
+
url: `${getBaseUrl()}profiles/tokens`,
|
|
1753
|
+
data: { options },
|
|
1696
1754
|
};
|
|
1697
|
-
//create a token first
|
|
1755
|
+
// create a token first
|
|
1698
1756
|
sendData(token_request, callback);
|
|
1699
1757
|
};
|
|
1700
1758
|
|
|
1701
1759
|
/**
|
|
1702
|
-
*
|
|
1703
|
-
* @param uuid - The uuid
|
|
1704
|
-
* @param options - a list of optinos for token
|
|
1760
|
+
* Get a Token
|
|
1761
|
+
* @param uuid - The token uuid
|
|
1705
1762
|
* @param callback - A callback to call when done (returns error AND (message or user))
|
|
1706
1763
|
*/
|
|
1707
|
-
Zzish.
|
|
1708
|
-
|
|
1709
|
-
method: "
|
|
1710
|
-
url: getBaseUrl()
|
|
1711
|
-
data: { options: options }
|
|
1764
|
+
Zzish.getToken = function (uuid, callback) {
|
|
1765
|
+
const token_request = {
|
|
1766
|
+
method: "GET",
|
|
1767
|
+
url: `${getBaseUrl()}profiles/tokens/${uuid}`,
|
|
1712
1768
|
};
|
|
1713
|
-
//create a token first
|
|
1769
|
+
// create a token first
|
|
1714
1770
|
sendData(token_request, callback);
|
|
1715
1771
|
};
|
|
1716
1772
|
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
1773
|
/**
|
|
1720
|
-
*
|
|
1721
|
-
*
|
|
1722
|
-
* @param
|
|
1774
|
+
* Update a token's options
|
|
1775
|
+
*
|
|
1776
|
+
* @param uuid - The token UUID (required)
|
|
1777
|
+
* @param options - Options object to merge (required)
|
|
1778
|
+
* @param callback - An optional callback after the request completes
|
|
1723
1779
|
*/
|
|
1724
|
-
Zzish.
|
|
1725
|
-
|
|
1726
|
-
method: "
|
|
1727
|
-
url: getBaseUrl()
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
sendData(
|
|
1780
|
+
Zzish.updateToken = function (uuid, options, callback) {
|
|
1781
|
+
const tokenRequest = {
|
|
1782
|
+
method: "POST",
|
|
1783
|
+
url: `${getBaseUrl()}profiles/tokens/${uuid}`,
|
|
1784
|
+
data: { options: options },
|
|
1785
|
+
};
|
|
1786
|
+
sendData(tokenRequest, callback);
|
|
1731
1787
|
};
|
|
1732
1788
|
|
|
1733
1789
|
|
|
@@ -1738,86 +1794,84 @@
|
|
|
1738
1794
|
redirectURL - A URL hosted on the domain you are calling so that it can monitor success (will redirect to this page after succesful login and then close the page)
|
|
1739
1795
|
* @param callback - A callback to call when done (returns error AND (message or user))
|
|
1740
1796
|
*/
|
|
1741
|
-
Zzish.login = function (type,options,callback) {
|
|
1742
|
-
|
|
1797
|
+
Zzish.login = function (type, options, callback) {
|
|
1798
|
+
const token_request = {
|
|
1743
1799
|
method: "POST",
|
|
1744
|
-
url: getBaseUrl()
|
|
1745
|
-
data: { options
|
|
1800
|
+
url: `${getBaseUrl()}profiles/tokens`,
|
|
1801
|
+
data: { options },
|
|
1746
1802
|
};
|
|
1747
|
-
//create a token first
|
|
1748
|
-
sendData(token_request,
|
|
1749
|
-
|
|
1750
|
-
options
|
|
1803
|
+
// create a token first
|
|
1804
|
+
sendData(token_request, (err, data) => {
|
|
1805
|
+
callCallBack(err, data, (err, token) => {
|
|
1806
|
+
options.token=token;
|
|
1751
1807
|
setDataValue("token", token);
|
|
1752
|
-
loadLoginWithToken(type,options,callback);
|
|
1808
|
+
loadLoginWithToken(type, options, callback);
|
|
1753
1809
|
});
|
|
1754
1810
|
});
|
|
1755
1811
|
};
|
|
1756
1812
|
|
|
1757
|
-
Zzish.getCurrentUser = function(token,callback) {
|
|
1758
|
-
sendEvent("LAUNCH")
|
|
1813
|
+
Zzish.getCurrentUser = function (token, callback) {
|
|
1814
|
+
// REMOVED: sendEvent("LAUNCH") - AppEvents disabled
|
|
1759
1815
|
if (token==undefined) {
|
|
1760
|
-
//see if we can get token from query params
|
|
1761
|
-
token = getQueryParams()
|
|
1816
|
+
// see if we can get token from query params
|
|
1817
|
+
token = getQueryParams().token;
|
|
1762
1818
|
}
|
|
1763
1819
|
if (token==undefined) {
|
|
1764
1820
|
token = getDataValue("token");
|
|
1765
1821
|
}
|
|
1766
1822
|
if (token !== undefined && token!="Zzish error" && token!="undefined") {
|
|
1767
|
-
|
|
1823
|
+
const token_request = {
|
|
1768
1824
|
method: "GET",
|
|
1769
|
-
url: getBaseUrl()
|
|
1770
|
-
}
|
|
1771
|
-
//create a token first
|
|
1772
|
-
sendData(token_request,
|
|
1773
|
-
callCallBack(err, data,
|
|
1825
|
+
url: `${getBaseUrl()}profiles/tokens/${token}`,
|
|
1826
|
+
};
|
|
1827
|
+
// create a token first
|
|
1828
|
+
sendData(token_request, (err, data) => {
|
|
1829
|
+
callCallBack(err, data, (err, data) => {
|
|
1774
1830
|
if (data) {
|
|
1775
1831
|
data.token = token;
|
|
1776
1832
|
}
|
|
1777
|
-
callback(err,data);
|
|
1833
|
+
callback(err, data);
|
|
1778
1834
|
});
|
|
1779
1835
|
});
|
|
1780
|
-
}
|
|
1781
|
-
else {
|
|
1836
|
+
} else {
|
|
1782
1837
|
callback();
|
|
1783
1838
|
}
|
|
1784
|
-
}
|
|
1839
|
+
};
|
|
1785
1840
|
|
|
1786
1841
|
/**
|
|
1787
|
-
*
|
|
1788
|
-
*
|
|
1842
|
+
* Get a profile with attached metadata
|
|
1843
|
+
*
|
|
1844
|
+
* @param uuid - The profile UUID (required)
|
|
1845
|
+
* @param callback - An optional callback after the request completes
|
|
1789
1846
|
*/
|
|
1790
|
-
Zzish.
|
|
1791
|
-
|
|
1792
|
-
method: "
|
|
1793
|
-
url: getBaseUrl()
|
|
1794
|
-
}
|
|
1795
|
-
|
|
1796
|
-
sendData(request, function (err, data) {
|
|
1847
|
+
Zzish.getProfileWithMeta = function (uuid, callback) {
|
|
1848
|
+
const request = {
|
|
1849
|
+
method: "GET",
|
|
1850
|
+
url: `${getBaseUrl()}profiles/${uuid}/meta`,
|
|
1851
|
+
};
|
|
1852
|
+
sendData(request, (err, data) => {
|
|
1797
1853
|
callCallBack(err, data, callback);
|
|
1798
1854
|
});
|
|
1799
|
-
}
|
|
1855
|
+
};
|
|
1800
1856
|
|
|
1801
1857
|
/**
|
|
1802
|
-
*
|
|
1803
|
-
*
|
|
1804
|
-
* @param uuid - The profile User Id
|
|
1805
|
-
* @param callback - An optional callback after user profile has been fetched
|
|
1858
|
+
* Logout from Zzish
|
|
1859
|
+
* @param callback - A callback to call when done (returns error AND (message or user))
|
|
1806
1860
|
*/
|
|
1807
|
-
Zzish.
|
|
1808
|
-
|
|
1809
|
-
method: "
|
|
1810
|
-
url: getBaseUrl()
|
|
1861
|
+
Zzish.logout = function (token, callback) {
|
|
1862
|
+
const request = {
|
|
1863
|
+
method: "DELETE",
|
|
1864
|
+
url: `${getBaseUrl()}profiles/tokens/${token}`,
|
|
1811
1865
|
};
|
|
1812
|
-
|
|
1866
|
+
removeDataValue("token");
|
|
1867
|
+
sendData(request, (err, data) => {
|
|
1813
1868
|
callCallBack(err, data, callback);
|
|
1814
|
-
})
|
|
1869
|
+
});
|
|
1815
1870
|
};
|
|
1816
1871
|
|
|
1817
|
-
Zzish.connectToSocket = function(opencallback, errorcallback, messagecallback, msg) {
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
connection = new WebSocket('ws://' + socketUrl);
|
|
1872
|
+
Zzish.connectToSocket = function (opencallback, errorcallback, messagecallback, msg) {
|
|
1873
|
+
const start = function () {
|
|
1874
|
+
connection = new WebSocket(`ws://${socketUrl}`);
|
|
1821
1875
|
connection.onopen = function () {
|
|
1822
1876
|
if (connection.readyState === 1) {
|
|
1823
1877
|
Zzish.connectedToSocket = true;
|
|
@@ -1846,57 +1900,57 @@
|
|
|
1846
1900
|
errorcallback("Invalid JSON");
|
|
1847
1901
|
}
|
|
1848
1902
|
};
|
|
1849
|
-
}
|
|
1903
|
+
};
|
|
1850
1904
|
|
|
1851
|
-
setInterval(
|
|
1905
|
+
setInterval(() => {
|
|
1852
1906
|
if (connection.readyState !== 1) {
|
|
1853
1907
|
Zzish.connectedToSocket = false;
|
|
1854
1908
|
if (currentSocketRetry < maxSocketRetry) {
|
|
1855
|
-
currentSocketRetry
|
|
1909
|
+
currentSocketRetry++;
|
|
1856
1910
|
start();
|
|
1857
|
-
}
|
|
1858
|
-
else {
|
|
1911
|
+
} else {
|
|
1859
1912
|
errorcallback("Socket disconnected");
|
|
1860
1913
|
}
|
|
1861
1914
|
}
|
|
1862
1915
|
}, 3000);
|
|
1863
1916
|
|
|
1864
1917
|
start();
|
|
1865
|
-
}
|
|
1918
|
+
};
|
|
1866
1919
|
|
|
1867
|
-
Zzish.postToSocket = function(message) {
|
|
1920
|
+
Zzish.postToSocket = function (message) {
|
|
1868
1921
|
if (connection) {
|
|
1869
1922
|
connection.send(JSON.stringify(message));
|
|
1870
1923
|
}
|
|
1871
|
-
}
|
|
1924
|
+
};
|
|
1872
1925
|
|
|
1873
|
-
|
|
1874
|
-
|
|
1926
|
+
/** ** PROXY STUFF TO SEND DATA ** */
|
|
1927
|
+
/** * REQUEST has 3 attributes (method, url and data) *** */
|
|
1875
1928
|
|
|
1876
|
-
if (typeof window ===
|
|
1929
|
+
if (typeof window === "undefined") {
|
|
1877
1930
|
// we running in node so use https://www.npmjs.org/package/xmlhttprequest
|
|
1878
|
-
XMLHttpRequest = require(
|
|
1931
|
+
XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
|
|
1879
1932
|
}
|
|
1880
1933
|
|
|
1881
1934
|
|
|
1882
|
-
|
|
1883
|
-
|
|
1935
|
+
let req;
|
|
1936
|
+
let ocallback;
|
|
1884
1937
|
|
|
1885
1938
|
|
|
1886
1939
|
function sendData(request, callback) {
|
|
1887
|
-
if (typeof request.method ===
|
|
1940
|
+
if (typeof request.method === "undefined") {
|
|
1888
1941
|
request.method = "POST";
|
|
1889
1942
|
}
|
|
1943
|
+
if (logEnabled) console.log("Proxy.request ", request);
|
|
1890
1944
|
req = new XMLHttpRequest();
|
|
1891
|
-
if(req.addEventListener){
|
|
1892
|
-
req.addEventListener(
|
|
1893
|
-
|
|
1945
|
+
if (req.addEventListener) {
|
|
1946
|
+
req.addEventListener("load", function () {
|
|
1947
|
+
response(this, callback, logEnabled);
|
|
1894
1948
|
}, false);
|
|
1895
1949
|
|
|
1896
|
-
req.addEventListener(
|
|
1950
|
+
req.addEventListener("error", function () {
|
|
1897
1951
|
error(this, callback, logEnabled);
|
|
1898
1952
|
}, false);
|
|
1899
|
-
}else{
|
|
1953
|
+
} else {
|
|
1900
1954
|
ocallback = callback;
|
|
1901
1955
|
req.onload = outputResult;
|
|
1902
1956
|
}
|
|
@@ -1904,53 +1958,70 @@
|
|
|
1904
1958
|
|
|
1905
1959
|
req.open(request.method, request.url, true);
|
|
1906
1960
|
req.setRequestHeader(header, headerprefix+appId);
|
|
1907
|
-
req.setRequestHeader(
|
|
1961
|
+
req.setRequestHeader("Content-Type", "application/json");
|
|
1908
1962
|
req.send(JSON.stringify(request.data));
|
|
1909
1963
|
}
|
|
1910
1964
|
|
|
1911
1965
|
function outputResult() {
|
|
1912
|
-
if (
|
|
1913
|
-
|
|
1966
|
+
if (logEnabled) console.log("Proxy.response callback", req.responseText !== undefined, ocallback);
|
|
1967
|
+
if (typeof ocallback === "function") {
|
|
1968
|
+
const responseText = typeof req.responseText === "string" ? JSON.parse(req.responseText) : req.responseText;
|
|
1914
1969
|
ocallback(null, responseText);
|
|
1915
1970
|
}
|
|
1916
1971
|
}
|
|
1917
1972
|
|
|
1918
1973
|
function response(resp, callback, log) {
|
|
1919
|
-
|
|
1974
|
+
let err = null,
|
|
1975
|
+
res = null;
|
|
1976
|
+
|
|
1920
1977
|
try {
|
|
1921
|
-
|
|
1922
|
-
|
|
1978
|
+
const response = JSON.parse(resp.responseText);
|
|
1979
|
+
if (
|
|
1980
|
+
resp.status >= 200 &&
|
|
1981
|
+
resp.status < 300 &&
|
|
1982
|
+
(
|
|
1983
|
+
response.status == null ||
|
|
1984
|
+
(
|
|
1985
|
+
response.status >= 200 &&
|
|
1986
|
+
response.status < 300
|
|
1987
|
+
)
|
|
1988
|
+
)
|
|
1989
|
+
) {
|
|
1990
|
+
res = response;
|
|
1923
1991
|
} else {
|
|
1924
|
-
err =
|
|
1992
|
+
err = response;
|
|
1925
1993
|
}
|
|
1926
1994
|
} catch (e) {
|
|
1927
1995
|
err = resp.responseText;
|
|
1928
1996
|
}
|
|
1929
|
-
if (
|
|
1997
|
+
if (log) console.log("Proxy.response callback", err, res);
|
|
1998
|
+
if (err && window._LTracker) window._LTracker.push({ location: window.location.href, err });
|
|
1999
|
+
if (typeof callback === "function") {
|
|
1930
2000
|
callback(err, res);
|
|
1931
2001
|
}
|
|
1932
2002
|
}
|
|
1933
2003
|
|
|
1934
2004
|
function error(evt, callback, log) {
|
|
2005
|
+
console.error("Proxy.error", evt);
|
|
1935
2006
|
callback(evt.currentTarget, null);
|
|
1936
2007
|
}
|
|
1937
2008
|
|
|
1938
|
-
|
|
2009
|
+
/** * UUID STUFF from zzish.js ** */
|
|
1939
2010
|
|
|
1940
2011
|
|
|
1941
|
-
|
|
2012
|
+
const _global = this;
|
|
1942
2013
|
|
|
1943
2014
|
// Unique ID creation requires a high quality random # generator. We feature
|
|
1944
2015
|
// detect to determine the best RNG source, normalizing to a function that
|
|
1945
2016
|
// returns 128-bits of randomness, since that's what's usually required
|
|
1946
|
-
|
|
2017
|
+
let _rng;
|
|
1947
2018
|
|
|
1948
2019
|
// Node.js crypto-based RNG - http://nodejs.org/docs/v0.6.2/api/crypto.html
|
|
1949
2020
|
//
|
|
1950
2021
|
// Moderately fast, high quality
|
|
1951
|
-
if (typeof(_global.require)
|
|
2022
|
+
if (typeof (_global.require) === "function") {
|
|
1952
2023
|
try {
|
|
1953
|
-
|
|
2024
|
+
const _rb = _global.require("crypto").randomBytes;
|
|
1954
2025
|
_rng = _rb && function () {
|
|
1955
2026
|
return _rb(16);
|
|
1956
2027
|
};
|
|
@@ -1962,7 +2033,7 @@
|
|
|
1962
2033
|
// WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto
|
|
1963
2034
|
//
|
|
1964
2035
|
// Moderately fast, high quality
|
|
1965
|
-
|
|
2036
|
+
const _rnds8 = new Uint8Array(16);
|
|
1966
2037
|
_rng = function whatwgRNG() {
|
|
1967
2038
|
crypto.getRandomValues(_rnds8);
|
|
1968
2039
|
return _rnds8;
|
|
@@ -1974,7 +2045,7 @@
|
|
|
1974
2045
|
//
|
|
1975
2046
|
// If all else fails, use Math.random(). It's fast, but is of unspecified
|
|
1976
2047
|
// quality.
|
|
1977
|
-
|
|
2048
|
+
const _rnds = new Array(16);
|
|
1978
2049
|
_rng = function () {
|
|
1979
2050
|
for (var i = 0, r; i < 16; i++) {
|
|
1980
2051
|
if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
|
|
@@ -1986,11 +2057,11 @@
|
|
|
1986
2057
|
}
|
|
1987
2058
|
|
|
1988
2059
|
// Buffer class to use
|
|
1989
|
-
|
|
2060
|
+
const BufferClass = typeof (_global.Buffer) === "function" ? _global.Buffer : Array;
|
|
1990
2061
|
|
|
1991
2062
|
// Maps for number <-> hex string conversion
|
|
1992
|
-
|
|
1993
|
-
|
|
2063
|
+
const _byteToHex = [];
|
|
2064
|
+
const _hexToByte = {};
|
|
1994
2065
|
for (var i = 0; i < 256; i++) {
|
|
1995
2066
|
_byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
|
1996
2067
|
_hexToByte[_byteToHex[i]] = i;
|
|
@@ -1998,10 +2069,11 @@
|
|
|
1998
2069
|
|
|
1999
2070
|
// **`parse()` - Parse a UUID into it's component bytes**
|
|
2000
2071
|
function parse(s, buf, offset) {
|
|
2001
|
-
|
|
2072
|
+
let i = (buf && offset) || 0,
|
|
2073
|
+
ii = 0;
|
|
2002
2074
|
|
|
2003
2075
|
buf = buf || [];
|
|
2004
|
-
s.toLowerCase().replace(/[0-9a-f]{2}/g,
|
|
2076
|
+
s.toLowerCase().replace(/[0-9a-f]{2}/g, (oct) => {
|
|
2005
2077
|
if (ii < 16) { // Don't overflow!
|
|
2006
2078
|
buf[i + ii++] = _hexToByte[oct];
|
|
2007
2079
|
}
|
|
@@ -2017,15 +2089,16 @@
|
|
|
2017
2089
|
|
|
2018
2090
|
// **`unparse()` - Convert UUID byte array (ala parse()) into a string**
|
|
2019
2091
|
function unparse(buf, offset) {
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
bth[buf[i++]] + bth[buf[i++]]
|
|
2024
|
-
bth[buf[i++]]
|
|
2025
|
-
bth[buf[i++]]
|
|
2026
|
-
bth[buf[i++]]
|
|
2027
|
-
bth[buf[i++]]
|
|
2028
|
-
bth[buf[i++]]
|
|
2092
|
+
let i = offset || 0,
|
|
2093
|
+
bth = _byteToHex;
|
|
2094
|
+
return `${bth[buf[i++]] + bth[buf[i++]] +
|
|
2095
|
+
bth[buf[i++]] + bth[buf[i++]]}-${
|
|
2096
|
+
bth[buf[i++]]}${bth[buf[i++]]}-${
|
|
2097
|
+
bth[buf[i++]]}${bth[buf[i++]]}-${
|
|
2098
|
+
bth[buf[i++]]}${bth[buf[i++]]}-${
|
|
2099
|
+
bth[buf[i++]]}${bth[buf[i++]]
|
|
2100
|
+
}${bth[buf[i++]]}${bth[buf[i++]]
|
|
2101
|
+
}${bth[buf[i++]]}${bth[buf[i++]]}`;
|
|
2029
2102
|
}
|
|
2030
2103
|
|
|
2031
2104
|
// **`v1()` - Generate time-based UUID**
|
|
@@ -2034,41 +2107,42 @@
|
|
|
2034
2107
|
// and http://docs.python.org/library/zzish.html
|
|
2035
2108
|
|
|
2036
2109
|
// random #'s we need to init node and clockseq
|
|
2037
|
-
|
|
2110
|
+
const _seedBytes = _rng();
|
|
2038
2111
|
|
|
2039
2112
|
// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
|
|
2040
|
-
|
|
2113
|
+
const _nodeId = [
|
|
2041
2114
|
_seedBytes[0] | 0x01,
|
|
2042
|
-
_seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5]
|
|
2115
|
+
_seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5],
|
|
2043
2116
|
];
|
|
2044
2117
|
|
|
2045
2118
|
// Per 4.2.2, randomize (14 bit) clockseq
|
|
2046
|
-
|
|
2119
|
+
let _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff;
|
|
2047
2120
|
|
|
2048
2121
|
// Previous zzish creation time
|
|
2049
|
-
|
|
2122
|
+
let _lastMSecs = 0,
|
|
2123
|
+
_lastNSecs = 0;
|
|
2050
2124
|
|
|
2051
2125
|
// See https://github.com/broofa/node-zzish for API details
|
|
2052
2126
|
function v1(options, buf, offset) {
|
|
2053
|
-
|
|
2054
|
-
|
|
2127
|
+
let i = buf && offset || 0;
|
|
2128
|
+
const b = buf || [];
|
|
2055
2129
|
|
|
2056
2130
|
options = options || {};
|
|
2057
2131
|
|
|
2058
|
-
|
|
2132
|
+
let clockseq = options.clockseq != null ? options.clockseq : _clockseq;
|
|
2059
2133
|
|
|
2060
2134
|
// UUID timestamps are 100 nano-second units since the Gregorian epoch,
|
|
2061
2135
|
// (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
|
|
2062
2136
|
// time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
|
|
2063
2137
|
// (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
|
|
2064
|
-
|
|
2138
|
+
let msecs = options.msecs != null ? options.msecs : new Date().getTime();
|
|
2065
2139
|
|
|
2066
2140
|
// Per 4.2.1.2, use count of zzish's generated during the current clock
|
|
2067
2141
|
// cycle to simulate higher resolution clock
|
|
2068
|
-
|
|
2142
|
+
let nsecs = options.nsecs != null ? options.nsecs : _lastNSecs + 1;
|
|
2069
2143
|
|
|
2070
2144
|
// Time since last zzish creation (in msecs)
|
|
2071
|
-
|
|
2145
|
+
const dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs) / 10000;
|
|
2072
2146
|
|
|
2073
2147
|
// Per 4.2.1.2, Bump clockseq on clock regression
|
|
2074
2148
|
if (dt < 0 && options.clockseq == null) {
|
|
@@ -2083,7 +2157,7 @@
|
|
|
2083
2157
|
|
|
2084
2158
|
// Per 4.2.1.2 Throw error if too many uuids are requested
|
|
2085
2159
|
if (nsecs >= 10000) {
|
|
2086
|
-
throw new Error(
|
|
2160
|
+
throw new Error("zzish.v1(): Can't create more than 10M uuids/sec");
|
|
2087
2161
|
}
|
|
2088
2162
|
|
|
2089
2163
|
_lastMSecs = msecs;
|
|
@@ -2094,14 +2168,14 @@
|
|
|
2094
2168
|
msecs += 12219292800000;
|
|
2095
2169
|
|
|
2096
2170
|
// `time_low`
|
|
2097
|
-
|
|
2171
|
+
const tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
|
2098
2172
|
b[i++] = tl >>> 24 & 0xff;
|
|
2099
2173
|
b[i++] = tl >>> 16 & 0xff;
|
|
2100
2174
|
b[i++] = tl >>> 8 & 0xff;
|
|
2101
2175
|
b[i++] = tl & 0xff;
|
|
2102
2176
|
|
|
2103
2177
|
// `time_mid`
|
|
2104
|
-
|
|
2178
|
+
const tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;
|
|
2105
2179
|
b[i++] = tmh >>> 8 & 0xff;
|
|
2106
2180
|
b[i++] = tmh & 0xff;
|
|
2107
2181
|
|
|
@@ -2116,12 +2190,12 @@
|
|
|
2116
2190
|
b[i++] = clockseq & 0xff;
|
|
2117
2191
|
|
|
2118
2192
|
// `node`
|
|
2119
|
-
|
|
2120
|
-
for (
|
|
2193
|
+
const node = options.node || _nodeId;
|
|
2194
|
+
for (let n = 0; n < 6; n++) {
|
|
2121
2195
|
b[i + n] = node[n];
|
|
2122
2196
|
}
|
|
2123
2197
|
|
|
2124
|
-
return buf
|
|
2198
|
+
return buf || unparse(b);
|
|
2125
2199
|
}
|
|
2126
2200
|
|
|
2127
2201
|
// **`v4()` - Generate random UUID**
|
|
@@ -2129,15 +2203,15 @@
|
|
|
2129
2203
|
// See https://github.com/broofa/node-zzish for API details
|
|
2130
2204
|
function v4(options, buf, offset) {
|
|
2131
2205
|
// Deprecated - 'format' argument, as supported in v1.2
|
|
2132
|
-
|
|
2206
|
+
const i = buf && offset || 0;
|
|
2133
2207
|
|
|
2134
|
-
if (typeof(options)
|
|
2135
|
-
buf = options ==
|
|
2208
|
+
if (typeof (options) === "string") {
|
|
2209
|
+
buf = options == "binary" ? new BufferClass(16) : null;
|
|
2136
2210
|
options = null;
|
|
2137
2211
|
}
|
|
2138
2212
|
options = options || {};
|
|
2139
2213
|
|
|
2140
|
-
|
|
2214
|
+
const rnds = options.random || (options.rng || _rng)();
|
|
2141
2215
|
|
|
2142
2216
|
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
2143
2217
|
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
|
@@ -2145,7 +2219,7 @@
|
|
|
2145
2219
|
|
|
2146
2220
|
// Copy bytes to buffer, if provided
|
|
2147
2221
|
if (buf) {
|
|
2148
|
-
for (
|
|
2222
|
+
for (let ii = 0; ii < 16; ii++) {
|
|
2149
2223
|
buf[i + ii] = rnds[ii];
|
|
2150
2224
|
}
|
|
2151
2225
|
}
|
|
@@ -2153,26 +2227,22 @@
|
|
|
2153
2227
|
return buf || unparse(rnds);
|
|
2154
2228
|
}
|
|
2155
2229
|
|
|
2156
|
-
function isObject(obj) {
|
|
2157
|
-
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
2230
|
// Export public API
|
|
2161
2231
|
|
|
2162
2232
|
|
|
2163
2233
|
var zzish = Zzish;
|
|
2164
2234
|
|
|
2165
|
-
if (typeof define ===
|
|
2235
|
+
if (typeof define === "function" && define.amd) {
|
|
2166
2236
|
// Publish as AMD module
|
|
2167
|
-
define(
|
|
2237
|
+
define(() => {
|
|
2168
2238
|
return zzish;
|
|
2169
2239
|
});
|
|
2170
|
-
} else if (typeof(module)
|
|
2240
|
+
} else if (typeof (module) !== "undefined" && module.exports) {
|
|
2171
2241
|
// Publish as node.js module
|
|
2172
2242
|
module.exports = zzish;
|
|
2173
2243
|
} else {
|
|
2174
2244
|
// Publish as global (in browsers)
|
|
2175
|
-
|
|
2245
|
+
const _previousRoot = _global.uuid;
|
|
2176
2246
|
|
|
2177
2247
|
// **`noConflict()` - (browser only) to reset global 'zzish' var**
|
|
2178
2248
|
zzish.noConflict = function () {
|
|
@@ -2182,5 +2252,4 @@
|
|
|
2182
2252
|
|
|
2183
2253
|
_global.zzish = zzish;
|
|
2184
2254
|
}
|
|
2185
|
-
|
|
2186
|
-
})();
|
|
2255
|
+
}());
|