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