@zzish/sdk-js 0.5.7 → 0.5.9

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/zzish.js +43 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzish/sdk-js",
3
- "version": "0.5.7",
3
+ "version": "0.5.9",
4
4
  "description": "SDK for Zzish API",
5
5
  "main": "zzish.js",
6
6
  "files": [
package/zzish.js CHANGED
@@ -1122,19 +1122,50 @@
1122
1122
  * @param content - The JSON object to save
1123
1123
  * @param callback - An optional callback to call when done (returns error,message)
1124
1124
  */
1125
- Zzish.postContent = function (profileId, type, uuid, meta, content, callback) {
1125
+ Zzish.postContent = function (profileId, type, uuid, meta /* , [tags], content, callback */) {
1126
+ // Arity-tolerant: support both the modern 6-arg shape and the legacy
1127
+ // 7-arg shape that includes `tags`. Legacy callers (quizalize quiz.js,
1128
+ // quiz-player server routes, anything pre-0.5.7) pass:
1129
+ // postContent(profileId, type, uuid, meta, tags, content, callback)
1130
+ // Modern callers pass:
1131
+ // postContent(profileId, type, uuid, meta, content, callback)
1132
+ // Detect by total argument count; the callback is always the last
1133
+ // argument and it's the only function in the trailing position.
1134
+ const args = arguments;
1135
+ let tags;
1136
+ let content;
1137
+ let callback;
1138
+ if (args.length >= 7) {
1139
+ tags = args[4];
1140
+ content = args[5];
1141
+ callback = args[6];
1142
+ } else if (args.length === 6) {
1143
+ content = args[4];
1144
+ callback = args[5];
1145
+ } else if (args.length === 5) {
1146
+ content = args[4];
1147
+ }
1148
+
1126
1149
  const data = {
1127
1150
  uuid,
1128
1151
  meta,
1129
1152
  payload: JSON.stringify(content),
1130
1153
  };
1154
+ // Forward `tags` on the wire only when the legacy caller supplied them.
1155
+ // The zzish-api content endpoint reads `content.getTags()` and persists
1156
+ // them onto the merged ActivityDef, so omitting the field preserves
1157
+ // the existing rows instead of overwriting them with an empty list.
1158
+ if (tags !== undefined) {
1159
+ data.tags = tags;
1160
+ }
1161
+
1131
1162
  const request = {
1132
1163
  method: "POST",
1133
1164
  url: `${getBaseUrl()}profiles/${profileId}/contents/${type}/${uuid}`,
1134
1165
  data,
1135
1166
  };
1136
- sendData(request, (err, data) => {
1137
- callCallBack(err, data, callback);
1167
+ sendData(request, (err, responseData) => {
1168
+ callCallBack(err, responseData, callback);
1138
1169
  });
1139
1170
  };
1140
1171
 
@@ -1995,7 +2026,15 @@
1995
2026
  err = resp.responseText;
1996
2027
  }
1997
2028
  if (log) console.log("Proxy.response callback", err, res);
1998
- if (err && window._LTracker) window._LTracker.push({ location: window.location.href, err });
2029
+ // Loggly hook browser-only. Guarded with `typeof window` so the SDK
2030
+ // can be loaded inside a Node.js server (spitafields, quizalize,
2031
+ // quiz-player's SSR shim) without throwing a ReferenceError on the
2032
+ // raw `window` access. `typeof` on an undeclared identifier returns
2033
+ // "undefined" instead of throwing, which `window !== "undefined"`
2034
+ // would not.
2035
+ if (err && typeof window !== "undefined" && window._LTracker) {
2036
+ window._LTracker.push({ location: window.location.href, err });
2037
+ }
1999
2038
  if (typeof callback === "function") {
2000
2039
  callback(err, res);
2001
2040
  }