@zzish/sdk-js 0.5.3 → 0.5.6

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 CHANGED
@@ -1,24 +1,30 @@
1
1
  {
2
- "name": "@zzish/sdk-js",
3
- "version": "0.5.3",
4
- "description": "SDK for Zzish API",
5
- "main": "zzish.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/zzishdev/zzishsdk-js.git"
12
- },
13
- "keywords": [
14
- "zzish",
15
- "api",
16
- "sdk"
17
- ],
18
- "author": "Zzish Developers <developers@zzish.com> (http://www.zzish.com)",
19
- "license": "MIT",
20
- "bugs": {
21
- "url": "https://github.com/zzish/zzishsdk-js/issues"
22
- },
23
- "homepage": "https://github.com/zzish/zzishsdk-js"
2
+ "name": "@zzish/sdk-js",
3
+ "version": "0.5.6",
4
+ "description": "SDK for Zzish API",
5
+ "main": "zzish.js",
6
+ "files": [
7
+ "zzish.js"
8
+ ],
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "scripts": {
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/zzish/zzishsdk-js.git"
18
+ },
19
+ "keywords": [
20
+ "zzish",
21
+ "api",
22
+ "sdk"
23
+ ],
24
+ "author": "Zzish Developers <developers@zzish.com> (http://www.zzish.com)",
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/zzish/zzishsdk-js/issues"
28
+ },
29
+ "homepage": "https://github.com/zzish/zzishsdk-js"
24
30
  }
package/zzish.js CHANGED
@@ -153,20 +153,8 @@
153
153
  return originalValue;
154
154
  }
155
155
 
156
- var sendEvent = function(event, callback) {
157
- var request = {
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
- }
156
+ // REMOVED: sendEvent() function - AppEvents functionality disabled to reduce MongoDB costs
157
+ // var sendEvent = function(event, callback) { ... } // No longer needed
170
158
 
171
159
  /**
172
160
  * Initialise Zzish instance
@@ -202,7 +190,7 @@
202
190
  socketUrl = getConfigValue(config,'socketUrl',socketUrl);
203
191
  setDataValue("appConfig",JSON.stringify(config));
204
192
  }
205
- sendEvent("START");
193
+ // REMOVED: sendEvent("START") - AppEvents disabled to reduce MongoDB costs
206
194
  };
207
195
 
208
196
 
@@ -211,7 +199,7 @@
211
199
  */
212
200
  Zzish.stop = function (callback) {
213
201
  //generate a device if we don't have one
214
- sendEvent("STOP");
202
+ // REMOVED: sendEvent("STOP") - AppEvents disabled to reduce MongoDB costs
215
203
  };
216
204
 
217
205
  var params = getQueryParams();
@@ -456,7 +444,7 @@
456
444
  * @param callback - A callback to be called after message is sent (returns error,message)
457
445
  */
458
446
  Zzish.startActivityWithObjects = function (userId, parameters, callback) {
459
- sendEvent("START_ACTIVITY");
447
+ // REMOVED: sendEvent("START_ACTIVITY") - AppEvents disabled
460
448
  if (!currentUser || !stateful() || userId!=currentUser.id) {
461
449
  currentUser = {
462
450
  uuid: userId
@@ -478,7 +466,7 @@
478
466
  *
479
467
  */
480
468
  Zzish.stopActivity = function (activityId, states, callback) {
481
- sendEvent("STOP_ACTIVITY");
469
+ // REMOVED: sendEvent("STOP_ACTIVITY") - AppEvents disabled
482
470
  var pro = undefined;
483
471
  var haveState = false;
484
472
  if (states!=undefined && states.proficiency!=undefined) {
@@ -501,6 +489,30 @@
501
489
  }, { states: haveState?stateMap:undefined},callback)
502
490
  };
503
491
 
492
+ /**
493
+ * Stop Activity with full parameters object (preserves activityDefinition)
494
+ *
495
+ * @param activityId - The activity id (returned from startActivity) (required)
496
+ * @param parameters - Object that may contain activityDefinition, states, extensions
497
+ * @param callback - A callback to be called after message is sent (returns error,message)
498
+ *
499
+ * Prefer this over stopActivity({}) so the resulting xAPI Statement carries
500
+ * object.definition.type. Spring Data 4.x strict mode rejects POST /api/statements
501
+ * payloads where definition.type is null when the historical ActivityDef
502
+ * collection contains multiple type=null rows for the app.
503
+ */
504
+ Zzish.stopActivityWithObjects = function (activityId, parameters, callback) {
505
+ var params = parameters || {};
506
+ sendMessage({
507
+ verb: "http://activitystrea.ms/schema/1.0/complete",
508
+ activityUuid: activityId
509
+ }, {
510
+ activityDefinition: params.activityDefinition,
511
+ states: params.states,
512
+ extensions: params.extensions
513
+ }, callback);
514
+ };
515
+
504
516
  /** * Update an activity instance with images
505
517
  *
506
518
  * @param activityId - The activity instance id of activity
@@ -526,19 +538,42 @@
526
538
  *
527
539
  */
528
540
  Zzish.cancelActivity = function (activityId, callback) {
529
- sendEvent("CANCEL_ACTIVITY");
541
+ // REMOVED: sendEvent("CANCEL_ACTIVITY") - AppEvents disabled
530
542
  sendMessage({
531
543
  verb: "http://activitystrea.ms/schema/1.0/cancel",
532
544
  activityUuid: activityId
533
545
  }, {}, callback)
534
546
  };
535
547
 
548
+ /**
549
+ * Cancel Activity with full parameters object (preserves activityDefinition)
550
+ *
551
+ * @param activityId - The activity id (returned from startActivity) (required)
552
+ * @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.
557
+ */
558
+ Zzish.cancelActivityWithObjects = function (activityId, parameters, callback) {
559
+ var params = parameters || {};
560
+ sendMessage({
561
+ verb: "http://activitystrea.ms/schema/1.0/cancel",
562
+ activityUuid: activityId
563
+ }, {
564
+ activityDefinition: params.activityDefinition,
565
+ states: params.states,
566
+ extensions: params.extensions
567
+ }, callback);
568
+ };
569
+
536
570
  /**
537
571
  * Log an Action
538
572
  *
539
573
  * @param activityId - The activity id (returned from startActivity) (required)
540
574
  * @param actionName - The name of the action (required)
541
575
  * @param response - A string representation of the action (optional)
576
+ * @param responseOption - A string representation of the action option, e.g. "A", "B", etc (optional)
542
577
  * @param score - A float score (optional)
543
578
  * @param duration - A long duration (optional)
544
579
  * @param attempts - The number of attempts
@@ -546,7 +581,7 @@
546
581
  * @param callback - A callback to be called after message is sent (returns error,message)
547
582
  *
548
583
  */
549
- Zzish.logAction = function (activityId, actionName, response, score, correct, duration, attempts, attributes, callback) {
584
+ Zzish.logAction = function (activityId, actionName, response, responseOption, score, correct, duration, attempts, attributes, callback) {
550
585
  var definition = {
551
586
  type: actionName
552
587
  };
@@ -554,6 +589,9 @@
554
589
  if (response != undefined) {
555
590
  result["response"] = response;
556
591
  }
592
+ if (responseOption != undefined) {
593
+ result["responseOption"] = responseOption;
594
+ }
557
595
  if (score != undefined) {
558
596
  result["score"] = parseFloat(score);
559
597
  }
@@ -570,7 +608,7 @@
570
608
  };
571
609
 
572
610
  Zzish.logActionWithObjects = function (activityId, parameters, callback) {
573
- sendEvent("ACTION");
611
+ // REMOVED: sendEvent("ACTION") - AppEvents disabled
574
612
  if (parameters.definition==undefined) {
575
613
  parameters.definition = {};
576
614
  }
@@ -599,8 +637,17 @@
599
637
  return action;
600
638
  }
601
639
 
602
- Zzish.logActions = function (activityId, parameters, actionObjects, callback) {
603
- sendEvent("ACTION");
640
+ Zzish.logActions = function (activityId, parameters, actionObjects /*, [isComplete], callback */) {
641
+ // REMOVED: sendEvent("ACTION") - AppEvents disabled
642
+ // Accept both legacy 4-arg (callback at position 4) and the 5-arg
643
+ // (isComplete at position 4, callback at position 5) shape that
644
+ // quiz-player has been calling for years — the 5-arg variant was
645
+ // silently dropping its callback before this fix.
646
+ var callback;
647
+ var lastArg = arguments[arguments.length - 1];
648
+ if (typeof lastArg === "function") {
649
+ callback = lastArg;
650
+ }
604
651
  var actions = actionObjects.map(function(action) {
605
652
  return createActionObject(action);
606
653
  });
@@ -1661,7 +1708,7 @@
1661
1708
 
1662
1709
 
1663
1710
  function loadLoginWithToken(type,params,callback) {
1664
- sendEvent("LOGIN");
1711
+ // REMOVED: sendEvent("LOGIN") - AppEvents disabled
1665
1712
  var url = webUrl + 'account/applogin?token='+params.token;
1666
1713
  if (type=="pop") {
1667
1714
  var win = window.open(url, 'Zzish Login', 'width=800, height=600');
@@ -1755,7 +1802,7 @@
1755
1802
  };
1756
1803
 
1757
1804
  Zzish.getCurrentUser = function(token,callback) {
1758
- sendEvent("LAUNCH");
1805
+ // REMOVED: sendEvent("LAUNCH") - AppEvents disabled
1759
1806
  if (token==undefined) {
1760
1807
  //see if we can get token from query params
1761
1808
  token = getQueryParams()["token"];
package/3rdparty.html DELETED
@@ -1,87 +0,0 @@
1
- <!doctype html>
2
-
3
- <html lang="en">
4
- <head>
5
- <meta charset="utf-8">
6
-
7
- <title>Zzish Quick Javascript Client SDK</title>
8
-
9
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
10
- <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
11
-
12
- <script src="zzish.js"></script>
13
- <script>
14
- var init = false;
15
- var loggedIn = false;
16
- var token;
17
- var href;
18
-
19
- function initApp() {
20
- if (init) return true;
21
- if ($("#appId").val()!="") {
22
- var initParams = $("#appId").val();
23
- Zzish.init(initParams);
24
- init = true;
25
- console.log("App Initalized with id",$("#appId").val());
26
- return true;
27
- }
28
- else {
29
- alert ("Please enter your API KEY from http://www.zzish.co.uk/developer/")
30
- return false;
31
- }
32
- }
33
-
34
- function registerWithZzish() {
35
- var uuid = $("#uuid").val();
36
- var email = $("#email").val();
37
- var name = $("#name").val();
38
-
39
- if (initApp()) {
40
- Zzish.registerUserWithZzish(uuid, email, name, function(err, message) {
41
- console.log("Result from register", err, message);
42
- });
43
- }
44
- }
45
-
46
- function loadUser() {
47
- if (initApp()) {
48
- var uuid = $("#uuid").val();
49
- var redirect = $("#redirect").val();
50
- Zzish.getTokenForUser(uuid, function(err, url) {
51
- if (err == 400) {
52
- alert("Either the user doesn't exist or the user has not authorized this email")
53
- }
54
- else {
55
- href = url;
56
- console.log("Result from register", err, url);
57
- $("#dashboard").attr("href",url + "/" + redirect);
58
- }
59
- });
60
- }
61
- }
62
-
63
- function updateTarget() {
64
- $("#dashboard").attr("href",href + "/" + $("#redirect").val());
65
- }
66
- </script>
67
- </head>
68
-
69
- <body>
70
- <input type="text" id="appId" name="appId" placeholder="Your API Key" value="" size="40"/><br/>
71
- <h1>Login</h1>
72
- <div id="loginButtons">
73
- <input type="text" id="uuid" name="uuid" placeholder="UUID (Required)"/><br/>
74
- <input type="text" id="email" name="email" placeholder="Email (Required)"/><br/>
75
- <input type="text" id="name" name="name" placeholder="Name (Optional)"/><br/><br/>
76
- <input type="button" onclick="registerWithZzish()" value="RegisterWithZzish"/><br/><br/>
77
- <input type="button" onclick="loadUser()" value="LoadUser"/><br/><br/>
78
- <select id="redirect" onchange="updateTarget()">
79
- <option value="">Nothing defaults to home</option>
80
- <option value="home">Home</option>
81
- <option value="dashboard">Teacher Dashboard</option>
82
- </select>
83
- <a id="dashboard" target=_blank>Open Dashboard</a>
84
- <br/><br/>
85
- </div>
86
- </body>
87
- </html>
package/content.html DELETED
@@ -1,162 +0,0 @@
1
- <!doctype html>
2
-
3
- <html lang="en">
4
- <head>
5
- <meta charset="utf-8">
6
-
7
- <title>Zzish Quick Javascript Client SDK</title>
8
-
9
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
10
- <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
11
-
12
- <script src="zzish.js"></script>
13
- <script>
14
- var userId;
15
- var init = false;
16
-
17
- function initApp() {
18
- if (!init) {
19
- if ($("#appId").val()!="") {
20
- Zzish.init({
21
- api: $("#appId").val(),
22
- protocol: "http://",
23
- baseUrl: "localhost:8080/zzishapi/api/",
24
- webUrl: "http://localhost:3000/",
25
- header: "X-ApplicationId",
26
- headerprefix: "",
27
- logEnabled: true
28
- });
29
- //Zzish.init($("#appId").val());
30
- init = true;
31
- console.log("App Initalized with id",$("#appId").val());
32
- }
33
- else {
34
- alert ("Please enter your API KEY from http://www.zzish.co.uk/developer/")
35
- }
36
- }
37
- return init;
38
- }
39
-
40
- function createUser() {
41
- if (initApp()) {
42
- Zzish.getUser($("#userId").val(),$("#name").val(),function(err,message) {
43
- userId = message.uuid;
44
- console.log("User created with status" + message.uuid);
45
- });
46
-
47
- }
48
- }
49
-
50
- function postContent() {
51
- if (initApp()) {
52
- //postContent = function(profileId,id,name,content,callback)
53
- var JSON_val = JSON.parse($("#cjson").val());
54
- var content = {
55
- uuid: $("#cid").val(),
56
- name: $("#cname").val(),
57
- payload: JSON_val
58
- };
59
- Zzish.postContent(userId,content,function(err,message) {
60
- console.log("Content created with status" + err);
61
- });
62
- }
63
- }
64
-
65
- function getContent() {
66
- if (initApp()) {
67
- Zzish.getContent(userId,$("#gcid").val(),function(err,message) {
68
- $("#getContentOutput").html(JSON.stringify(message));
69
- });
70
- }
71
- }
72
-
73
- function listContent() {
74
- if (initApp()) {
75
- Zzish.listContent(userId,function(err,message) {
76
- $("#listContentOutput").html(JSON.stringify(message));
77
- });
78
- }
79
- }
80
-
81
- function deleteContent() {
82
- if (initApp()) {
83
- Zzish.deleteContent(userId,$("#dcid").val(),function(err,message) {
84
- console.log("")
85
- });
86
- }
87
- }
88
-
89
- function publishContent() {
90
- if (initApp()) {
91
- Zzish.publishContentToGroup(userId,$("#pemail").val(),$("#pid").val(),$("#pcode").val(),function(err,message) {
92
- $("#publishContentOutput").html(JSON.stringify(message));
93
- });
94
- }
95
- else {
96
- alert ("Please init with your APP_ID from http://www.zzish.co.uk/developer/")
97
- }
98
- }
99
-
100
- function unpublishContent() {
101
- if (initApp()) {
102
- Zzish.unpublishContent(userId,$("#pid").val(),$("#pcode").val(),function(err,message) {
103
- $("#publishContentOutput").html(JSON.stringify(message));
104
- });
105
- }
106
- else {
107
- alert ("Please init with your APP_ID from http://www.zzish.co.uk/developer/")
108
- }
109
- }
110
-
111
- function republishContent() {
112
- if (initApp()) {
113
- Zzish.republishContent(userId,$("#pid").val(),$("#pcode").val(),function(err,message) {
114
- $("#publishContentOutput").html(JSON.stringify(message));
115
- });
116
- }
117
- else {
118
- alert ("Please init with your APP_ID from http://www.zzish.co.uk/developer/")
119
- }
120
- }
121
- </script>
122
- </head>
123
-
124
- <body>
125
- <input type="text" id="appId" name="appId" placeholder="Your API Key" value="" size="40"/><br/>
126
- <h1>Create user</h1>
127
- <input type="text" id="userId" name="userId" placeholder="userId" value=""/><br/>
128
- <input type="text" id="name" name="name" placeholder="Name" value=""/><br/>
129
- <input type="button" onclick="createUser()" value="Create User"/><br/>
130
- <br/>
131
- <h1>Create Content</h1>
132
- <input type="text" id="cid" name="cid" placeholder="Content Id" value=""/><br/>
133
- <input type="text" id="cname" name="cname" placeholder="Content Name" value=""/><br/>
134
- <textarea id="cjson" name="cjson" placeholder="Content JSON" rows="10" cols="40"></textarea><br/>
135
- <input type="button" onclick="postContent()" value="Create Content"/><br/>
136
- <h1>Get Content</h1>
137
- <input type="text" id="gcid" name="gcid" placeholder="Content Id" value=""/><br/>
138
- <input type="button" onclick="getContent()" value="Get Content"/><br/>
139
- <h2>Output</h2>
140
- <div id="getContentOutput"></div>
141
- <br/>
142
- <h1>List Content</h1>
143
- <input type="button" onclick="listContent()" value="Get Content"/><br/>
144
- <h2>Output</h2>
145
- <div id="listContentOutput"></div>
146
- <br/>
147
- <h1>Publish Content</h1>
148
- <input type="text" id="pid" name="pid" placeholder="Content Id" value=""/><br/>
149
- <input type="text" id="pemail" name="pemail" placeholder="Email Address of Creator" value=""/><br/>
150
- <input type="text" id="pcode" name="pcode" placeholder="Group Code" value=""/><br/>
151
- <input type="button" onclick="publishContent()" value="Publish Content"/><br/>
152
- <input type="button" onclick="unpublishContent()" value="Unpublish Content"/><br/>
153
- <input type="button" onclick="republishContent()" value="Republish Content"/><br/>
154
- <h2>Output</h2>
155
- <div id="publishContentOutput"></div>
156
- <h1>Delete Content</h1>
157
- <input type="text" id="dcid" name="dcid" placeholder="Content Id" value=""/><br/>
158
- <input type="button" onclick="deleteContent()" value="Delete Content"/><br/>
159
- <input type="button" onclick="publishContent()" value="Publish Content"/><br/>
160
-
161
- </body>
162
- </html>
package/images/bg_hr.png DELETED
Binary file
Binary file
Binary file
Binary file