@livepreso/api 6.56.0 → 6.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.rush/temp/1aebf46f78ad5c45f82f8147751890adb37bef9d.log +10 -0
- package/.rush/temp/256021b5963b4c0221d3dec247b697b9691a9b2c.log +10 -0
- package/.rush/temp/2a322f00f12cf9d1e64afe81275cc78d01c49050.log +10 -0
- package/.rush/temp/30061f1865447dcbb3f20a305061205f3dbe6091.log +10 -0
- package/.rush/temp/3cdc82c352e8ed90607952873f3aa4c200490874.log +10 -0
- package/.rush/temp/45522aea0dee8cb2be1a53248ba45bd235743b43.log +10 -0
- package/.rush/temp/5489ab737e406518983c16c57fc3e1edc07c0341.log +10 -0
- package/.rush/temp/58fcbb7f15a76326d40e0839ab179755da82a891.log +10 -0
- package/.rush/temp/5bc0bba70b733baa4dd976667ba0a1386e516186.log +10 -0
- package/.rush/temp/64f1bb696f8d7d7e72907b80df316b127f72e23e.log +10 -0
- package/.rush/temp/6f640f951414ea68adb65c17e4ed7527cde54faf.log +10 -0
- package/.rush/temp/7c7b958682d4ab5697530be47d0aac62efe1adf1.log +10 -0
- package/.rush/temp/82bfb987463fbcfebf04022e6ed00015c73879c8.log +10 -0
- package/.rush/temp/844034aa6e542115075e8f3dc5ffc640973e0064.log +10 -0
- package/.rush/temp/8b42957a7c15da1f29cb57bee125f13affa70dca.log +10 -0
- package/.rush/temp/924652444ab5a6063f328a2217123a2227058896.log +10 -0
- package/.rush/temp/9f2030f96d62f3e38052e35201819a216566f14f.log +10 -0
- package/.rush/temp/a769db9d81a23000c0e9b1bf4f1a9a9e721d0d7c.log +10 -0
- package/.rush/temp/a87d3a8b4ece87ec66f27c86226a9f205617681f.log +10 -0
- package/.rush/temp/bb7a5bdcc4af4ad1507f81f33774b31f5b4e4fb7.log +10 -0
- package/.rush/temp/build-cache-tar.log +7 -0
- package/.rush/temp/c20e29ccaaa9231b38a28bb24451b4ce7562cdc0.log +10 -0
- package/.rush/temp/chunked-rush-logs/api.build.chunks.jsonl +15 -5
- package/.rush/temp/chunked-rush-logs/api.test.chunks.jsonl +1 -0
- package/.rush/temp/e21303db8f59b4625fd184c9114377d781fd24f8.log +10 -0
- package/.rush/temp/e6d303862765b6a5f41dd483d0f9ae083a1fae10.log +10 -0
- package/.rush/temp/eaf69fbc059d2f1258d7569136180d4a1d3c7072.log +10 -0
- package/.rush/temp/f85d279e2674966daaec83e1c3986a96f86ef304.log +10 -0
- package/.rush/temp/fc0a332c5b34c6b90006850cf2d93a48fb4b9a6e.log +10 -0
- package/.rush/temp/operation/build/all.log +15 -5
- package/.rush/temp/operation/build/error.log +13 -3
- package/.rush/temp/operation/build/log-chunks.jsonl +15 -5
- package/.rush/temp/operation/build/state.json +1 -1
- package/.rush/temp/operation/test/all.log +21 -0
- package/.rush/temp/operation/test/log-chunks.jsonl +21 -0
- package/.rush/temp/operation/test/state.json +3 -0
- package/.rush/temp/package-deps_build.json +185 -0
- package/.rush/temp/shrinkwrap-deps.json +11 -11
- package/CHANGELOG.json +24 -0
- package/CHANGELOG.md +15 -1
- package/api.build.log +9 -0
- package/api.test.cache.log +1 -0
- package/api.test.log +19 -0
- package/cjs/models/dispatch-preview.js +0 -2
- package/cjs/models/dispatch-preview.js.map +1 -1
- package/cjs/models/manifest-json.js +0 -2
- package/cjs/models/manifest-json.js.map +1 -1
- package/cjs/models/timing-log.js +17 -17
- package/cjs/models/timing-log.js.map +1 -1
- package/cjs/sync.js +17 -5
- package/cjs/sync.js.map +1 -1
- package/package.json +4 -4
- package/rush-logs/api.build.error.log +13 -3
- package/rush-logs/api.build.log +15 -5
- package/rush-logs/api.test.cache.log +1 -0
- package/rush-logs/api.test.log +1 -0
- package/src/models/dispatch-preview.js +0 -3
- package/src/models/manifest-json.js +7 -12
- package/src/models/timing-log.js +24 -28
- package/src/sync.js +17 -6
package/cjs/models/timing-log.js
CHANGED
|
@@ -11,14 +11,11 @@ require("./hosted-preso.js");
|
|
|
11
11
|
require("./user.js");
|
|
12
12
|
require("../collections/users.js");
|
|
13
13
|
var _utils = require("../utils.js");
|
|
14
|
-
var _auth = require("../auth.js");
|
|
15
14
|
var _base = require("./base.js");
|
|
16
|
-
var _lodash = _interopRequireDefault(require("lodash"));
|
|
17
15
|
var _dedentJs = _interopRequireDefault(require("dedent-js"));
|
|
18
16
|
var _log = _interopRequireDefault(require("../log.js"));
|
|
19
17
|
var _moment = _interopRequireDefault(require("moment"));
|
|
20
18
|
var _stateRegister = require("../state-register.js");
|
|
21
|
-
var _superagent = _interopRequireDefault(require("superagent"));
|
|
22
19
|
var _templateObject, _templateObject2;
|
|
23
20
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
24
21
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
@@ -121,6 +118,16 @@ var TimingLogModel = exports.TimingLogModel = _base.BaseModel.extend(/** @lends
|
|
|
121
118
|
attendee_set: "UserCollection",
|
|
122
119
|
remote_attendee_set: "UserCollection"
|
|
123
120
|
},
|
|
121
|
+
ajaxConfig: function ajaxConfig() {
|
|
122
|
+
return {
|
|
123
|
+
headers: {
|
|
124
|
+
"content-type": "application/vnd.salespreso+timinglog"
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
toServer: function toServer() {
|
|
129
|
+
return this.toCompactFormat();
|
|
130
|
+
},
|
|
124
131
|
/**
|
|
125
132
|
* Returns the current timing log model in expected compact format.
|
|
126
133
|
* @see http://doc.dev.salespreso.com/api/tracking.html#compact-representation
|
|
@@ -191,7 +198,8 @@ var TimingLogModel = exports.TimingLogModel = _base.BaseModel.extend(/** @lends
|
|
|
191
198
|
* timingLog.addEvent("http://client.salespreso.com/api/sections/28/", moment());
|
|
192
199
|
* timingLog.addEvent("http://client.salespreso.com/api/slides/100/", "2016-10-27T00:42:47.045186Z");
|
|
193
200
|
*/
|
|
194
|
-
addEvent: function addEvent(
|
|
201
|
+
addEvent: function addEvent(_path, timestamp) {
|
|
202
|
+
var path = _path;
|
|
195
203
|
if (!path) {
|
|
196
204
|
throw new Error("A path is required");
|
|
197
205
|
}
|
|
@@ -260,26 +268,18 @@ var TimingLogModel = exports.TimingLogModel = _base.BaseModel.extend(/** @lends
|
|
|
260
268
|
});
|
|
261
269
|
},
|
|
262
270
|
save: function save(data, options) {
|
|
263
|
-
var _this2 = this;
|
|
264
271
|
if (!this.events.length) {
|
|
265
272
|
return Promise.resolve(this.toJSON());
|
|
266
273
|
}
|
|
267
|
-
if (options && options.patch) {
|
|
268
|
-
return _base.BaseModel.prototype.save.call(this, data, options);
|
|
269
|
-
}
|
|
270
274
|
this.checkEventsAscending();
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
_this2.set(_lodash.default.omit(body, ["events"]));
|
|
275
|
-
return body;
|
|
276
|
-
}).catch(_superagent.default.SuperagentPromiseError, function (e) {
|
|
277
|
-
if (e.status === 405 && e.res.body.detail.indexOf("end") > -1) {
|
|
278
|
-
// Don't send timing log events if the tracking is ended.
|
|
275
|
+
return _base.BaseModel.prototype.save.call(this, data, options).catch(function (e) {
|
|
276
|
+
var _e$response, _e$response$body, _e$response$body$deta;
|
|
277
|
+
if (e.status === 405 && ((_e$response = e.response) === null || _e$response === void 0 ? void 0 : (_e$response$body = _e$response.body) === null || _e$response$body === void 0 ? void 0 : (_e$response$body$deta = _e$response$body.detail) === null || _e$response$body$deta === void 0 ? void 0 : _e$response$body$deta.indexOf("end")) > -1) {
|
|
279
278
|
throw e;
|
|
280
279
|
}
|
|
281
280
|
if (e.status >= 400 && e.status <= 499 || e.status === 503) {
|
|
282
|
-
|
|
281
|
+
var _e$response2;
|
|
282
|
+
e.message += "\nBody: ".concat(JSON.stringify((_e$response2 = e.response) === null || _e$response2 === void 0 ? void 0 : _e$response2.body));
|
|
283
283
|
}
|
|
284
284
|
throw e;
|
|
285
285
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timing-log.js","names":["require","_utils","_auth","_base","_lodash","_interopRequireDefault","_dedentJs","_log","_moment","_stateRegister","_superagent","_templateObject","_templateObject2","_createForOfIteratorHelper","r","e","t","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","_n","F","s","n","done","value","f","TypeError","o","a","u","call","next","return","_arrayLikeToArray","toString","slice","constructor","name","from","test","TimingLogModel","exports","BaseModel","extend","modelName","props","begin","type","required","end","events","default","created_date","modified_date","provisional","mode","values","children","appointment","hostedPreso","user","collections","attendee_set","remote_attendee_set","toCompactFormat","_this","getShortURL","url","moment","utc","format","DATE_FORMAT","startIndex","i","is_unfocused","map","_ref","timestamp","path","isUnfocused","millis","diff","duration","concat","attendeeSet","attendee","join","remoteAttendeeSet","modeTypeMap","present","view","prep","review","modeType","compact","dedent","_taggedTemplateLiteral2","addEvent","Error","time","push","DATE_FORMAT_T","checkEventsAscending","lastDate","sortEvents","_iterator","_step","event","isAfter","err","_ref2","log","warn","sort","event1","event2","save","data","options","_this2","Promise","resolve","toJSON","patch","prototype","method","isNew","superagent","set","Auth","headers","send","then","_ref3","body","_","omit","catch","SuperagentPromiseError","status","res","detail","indexOf","message","JSON","stringify","register"],"sources":["../../src/models/timing-log.js"],"sourcesContent":["import \"./appointment.js\";\nimport \"./hosted-preso.js\";\nimport \"./user.js\";\nimport \"../collections/users.js\";\n\nimport { DATE_FORMAT, DATE_FORMAT_T } from \"../utils.js\";\n\nimport { Auth } from \"../auth.js\";\nimport { BaseModel } from \"./base.js\";\nimport _ from \"lodash\";\nimport dedent from \"dedent-js\";\nimport { getShortURL } from \"../utils.js\";\nimport log from \"../log.js\";\nimport moment from \"moment\";\nimport { register } from \"../state-register.js\";\nimport superagent from \"superagent\";\n\n/**\n * @typedef Event\n * @type {object}\n * @property {string} path\n * @property {date} timestamp\n * @example\n * {\n *\t\"path\": \"https://client.salespreso.com/api/deckversions/4/\",\n *\t\"timestamp\": \"2016-10-27T00:42:47.045186Z\",\n *\t\"is_unfocused\": false,\n * }\n * @example\n * {\n * \t\"path\": \"https://client.salespreso.com/api/sections/28/\",\n * \t\"timestamp\": \"2016-10-27T00:43:59.430102Z\"\n *\t\"is_unfocused\": false,\n * }\n * @example\n * {\n * \t\"path\": \"https://client.salespreso.com/api/slides/380/\",\n * \t\"timestamp\": \"2016-10-27T00:45:01.038661Z\"\n *\t\"is_unfocused\": false,\n * }\n * @example\n * {\n * \t\"path\": \"https://client.salespreso.com/api/slides/378/\",\n * \t\"timestamp\": \"2016-10-27T00:45:13.495713Z\"\n *\t\"is_unfocused\": false,\n * }\n */\n\n/**\n * @constructor\n * @alias models.TimingLogModel\n * @extends models.BaseModel\n */\nexport const TimingLogModel = BaseModel.extend(\n\t/** @lends models.TimingLogModel# */ {\n\t\tmodelName: \"timinglogs\",\n\n\t\t/**\n\t\t * @property {date} begin\n\t\t * @property {date} end\n\t\t * @property {Event[]} events\n\t\t * @property {date} created_date\n\t\t * @property {date} modified_date\n\t\t */\n\t\tprops: {\n\t\t\tbegin: { type: \"date\", required: true },\n\t\t\tend: \"date\",\n\t\t\tevents: { type: \"array\", default: () => [] },\n\t\t\tcreated_date: \"date\",\n\t\t\tmodified_date: \"date\",\n\t\t\tprovisional: { type: \"boolean\", default: () => true },\n\t\t\tmode: {\n\t\t\t\ttype: \"string\",\n\t\t\t\tdefault: () => \"view\",\n\t\t\t\tvalues: [\n\t\t\t\t\t// A salesperson has presented a preso\n\t\t\t\t\t\"present\",\n\t\t\t\t\t// A customer has viewed an online preso\n\t\t\t\t\t\"view\",\n\t\t\t\t\t// A prep user or salesperson as prepared a preso\n\t\t\t\t\t\"prep\",\n\t\t\t\t\t// A salesperson has reviewed an old preso\n\t\t\t\t\t\"review\",\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\t/**\n\t\t * @property {models.AppointmentModel} appointment\n\t\t * @property {models.UserModel} user\n\t\t */\n\t\tchildren: {\n\t\t\tappointment: \"AppointmentModel\",\n\t\t\thostedPreso: \"HostedPresoModel\",\n\t\t\tuser: \"UserModel\",\n\t\t},\n\n\t\t/**\n\t\t * @property {collections.UserCollection} attendee_set\n\t\t * @property {collections.UserCollection} remote_attendee_set\n\t\t */\n\t\tcollections: {\n\t\t\tattendee_set: \"UserCollection\",\n\t\t\tremote_attendee_set: \"UserCollection\",\n\t\t},\n\n\t\t/**\n\t\t * Returns the current timing log model in expected compact format.\n\t\t * @see http://doc.dev.salespreso.com/api/tracking.html#compact-representation\n\t\t * @returns {string}\n\t\t */\n\t\ttoCompactFormat() {\n\t\t\tconst user = getShortURL(this.user.url());\n\n\t\t\tconst url = getShortURL(\n\t\t\t\tthis.hostedPreso ? this.hostedPreso.url() : this.appointment.url(),\n\t\t\t);\n\t\t\t// At this point, the expected output should have a space instead of a T in this\n\t\t\t// date format.\n\t\t\tconst begin = moment.utc(this.begin).format(DATE_FORMAT);\n\n\t\t\t// Strip out all unfocused events from the start (including any that are\n\t\t\t// in a row), as these will throw errors server side.\n\t\t\tlet startIndex = 0;\n\t\t\tfor (let i = 0; i < this.events.length; i++) {\n\t\t\t\tif (this.events[i].is_unfocused) {\n\t\t\t\t\tstartIndex = i + 1;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst events = this.events\n\t\t\t\t.slice(startIndex)\n\t\t\t\t.map(({ timestamp, path, is_unfocused: isUnfocused }) => {\n\t\t\t\t\tconst millis = moment(timestamp).diff(moment(this.begin), \"millis\");\n\n\t\t\t\t\tif (isUnfocused) {\n\t\t\t\t\t\tconst duration = moment\n\t\t\t\t\t\t\t.utc(timestamp)\n\t\t\t\t\t\t\t.diff(moment.utc(begin), \"milliseconds\");\n\n\t\t\t\t\t\treturn `${duration}ms unfocused`;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn `${millis}ms ${getShortURL(path)}`;\n\t\t\t\t});\n\n\t\t\tconst attendeeSet =\n\t\t\t\tthis.attendee_set && this.attendee_set.length\n\t\t\t\t\t? `\\n${this.attendee_set\n\t\t\t\t\t\t\t.map((attendee) => getShortURL(attendee.url()))\n\t\t\t\t\t\t\t.join(\" \")} attending`\n\t\t\t\t\t: \"\";\n\n\t\t\tconst remoteAttendeeSet =\n\t\t\t\tthis.remote_attendee_set && this.remote_attendee_set.length\n\t\t\t\t\t? `\\n${this.remote_attendee_set\n\t\t\t\t\t\t\t.map((attendee) => getShortURL(attendee.url()))\n\t\t\t\t\t\t\t.join(\" \")} attending remotely`\n\t\t\t\t\t: \"\";\n\n\t\t\tconst modeTypeMap = {\n\t\t\t\tpresent: \"viewing\",\n\t\t\t\tview: \"viewing\",\n\t\t\t\tprep: \"preparing\",\n\t\t\t\treview: \"reviewing\",\n\t\t\t};\n\n\t\t\tconst modeType = modeTypeMap[this.mode];\n\n\t\t\t// Note the newline is required at the end for the parser\n\t\t\t// to understand this\n\t\t\tlet compact = dedent`\n\t\t\t${user} ${modeType} ${url}${attendeeSet}${remoteAttendeeSet}\n\t\t\t${begin}\n\t\t\t${events.join(\"\\n\")}\\n\n\t\t`;\n\n\t\t\tif (this.end) {\n\t\t\t\tconst end = moment.utc(this.end).format(DATE_FORMAT);\n\t\t\t\tcompact += end;\n\t\t\t\tif (this.provisional) {\n\t\t\t\t\tcompact += \" provisional\";\n\t\t\t\t}\n\t\t\t\tcompact += \"\\n\";\n\t\t\t}\n\n\t\t\treturn compact;\n\t\t},\n\n\t\t/**\n\t\t * Add a new event to the log\n\t\t * @param {string} path - URL path. Matches a deck related endpoint (deckversion, section, slide. etc.)\n\t\t * @param {any} timestamp - A timestamp for the event - note that it can be anything that can be passed to moment\n\t\t * @example\n\t\t * const timingLog = new TimingLogModel();\n\t\t * timingLog.addEvent(\"http://client.salespreso.com/api/sections/28/\", moment());\n\t\t * timingLog.addEvent(\"http://client.salespreso.com/api/slides/100/\", \"2016-10-27T00:42:47.045186Z\");\n\t\t */\n\t\taddEvent(path, timestamp) {\n\t\t\tif (!path) {\n\t\t\t\tthrow new Error(\"A path is required\");\n\t\t\t}\n\t\t\tif (!timestamp) {\n\t\t\t\tthrow new Error(\"A timestamp is required\");\n\t\t\t}\n\n\t\t\tconst time = moment.utc(timestamp);\n\t\t\tconst isUnfocused = path === \"unfocused\";\n\n\t\t\tif (isUnfocused) {\n\t\t\t\tif (!this.events.length) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tfor (let i = this.events.length - 1; i >= 0; i--) {\n\t\t\t\t\tif (!this.events[i].is_unfocused) {\n\t\t\t\t\t\tpath = this.events[i].path;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.events.push({\n\t\t\t\ttimestamp: time.format(DATE_FORMAT_T),\n\t\t\t\tpath,\n\t\t\t\tis_unfocused: isUnfocused,\n\t\t\t});\n\t\t},\n\n\t\tcheckEventsAscending() {\n\t\t\tlet lastDate = null;\n\t\t\tlet sortEvents = false;\n\n\t\t\tfor (const event of this.events) {\n\t\t\t\tconst timestamp = moment(event.timestamp);\n\n\t\t\t\tif (lastDate && lastDate.isAfter(timestamp)) {\n\t\t\t\t\tsortEvents = true;\n\t\t\t\t}\n\n\t\t\t\tlastDate = timestamp;\n\t\t\t}\n\n\t\t\tif (sortEvents) {\n\t\t\t\tconst events = this.events.map(({ timestamp, path }) => {\n\t\t\t\t\treturn `${timestamp} ${getShortURL(path)}`;\n\t\t\t\t});\n\t\t\t\tlog.warn(dedent`\n\t\t\t\t\tEvents must be in ascending order. Instead we found:\n\n\t\t\t\t\t${this.begin} - begin\n\t\t\t\t\t${events.join(\"\\n\")}\n\t\t\t\t\t${this.end} - end\n\t\t\t\t`);\n\n\t\t\t\tthis.sortEvents();\n\t\t\t}\n\t\t},\n\n\t\t// We can't trust the server to give us events in the\n\t\t// correct order, so we sort them when necessary\n\t\tsortEvents() {\n\t\t\tthis.events.sort((event1, event2) => {\n\t\t\t\tconst diff = moment(event2.timestamp).diff(moment(event1.timestamp));\n\n\t\t\t\tif (diff > 0) {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else if (diff < 0) {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\n\t\t\t\treturn 0;\n\t\t\t});\n\t\t},\n\n\t\tsave(data, options) {\n\t\t\tif (!this.events.length) {\n\t\t\t\treturn Promise.resolve(this.toJSON());\n\t\t\t}\n\n\t\t\tif (options && options.patch) {\n\t\t\t\treturn BaseModel.prototype.save.call(this, data, options);\n\t\t\t}\n\n\t\t\tthis.checkEventsAscending();\n\n\t\t\tconst method = this.isNew() ? \"post\" : \"put\";\n\n\t\t\treturn superagent[method](this.url())\n\t\t\t\t.set(Auth.headers)\n\t\t\t\t.type(\"application/vnd.salespreso+timinglog\")\n\t\t\t\t.send(this.toCompactFormat())\n\t\t\t\t.then(({ body }) => {\n\t\t\t\t\tthis.set(_.omit(body, [\"events\"]));\n\t\t\t\t\treturn body;\n\t\t\t\t})\n\t\t\t\t.catch(superagent.SuperagentPromiseError, (e) => {\n\t\t\t\t\tif (e.status === 405 && e.res.body.detail.indexOf(\"end\") > -1) {\n\t\t\t\t\t\t// Don't send timing log events if the tracking is ended.\n\t\t\t\t\t\tthrow e;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ((e.status >= 400 && e.status <= 499) || e.status === 503) {\n\t\t\t\t\t\te.message += `\\nBody: ${JSON.stringify(e.res.body)}`;\n\t\t\t\t\t}\n\t\t\t\t\tthrow e;\n\t\t\t\t});\n\t\t},\n\t},\n);\n\nregister(\"TimingLogModel\", TimingLogModel);\n"],"mappings":";;;;;;;;AAAAA,OAAA;AACAA,OAAA;AACAA,OAAA;AACAA,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,SAAA,GAAAD,sBAAA,CAAAL,OAAA;AAEA,IAAAO,IAAA,GAAAF,sBAAA,CAAAL,OAAA;AACA,IAAAQ,OAAA,GAAAH,sBAAA,CAAAL,OAAA;AACA,IAAAS,cAAA,GAAAT,OAAA;AACA,IAAAU,WAAA,GAAAL,sBAAA,CAAAL,OAAA;AAAoC,IAAAW,eAAA,EAAAC,gBAAA;AAAA,SAAAC,2BAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,yBAAAC,MAAA,IAAAH,CAAA,CAAAG,MAAA,CAAAC,QAAA,KAAAJ,CAAA,qBAAAE,CAAA,QAAAG,KAAA,CAAAC,OAAA,CAAAN,CAAA,MAAAE,CAAA,GAAAK,2BAAA,CAAAP,CAAA,MAAAC,CAAA,IAAAD,CAAA,uBAAAA,CAAA,CAAAQ,MAAA,IAAAN,CAAA,KAAAF,CAAA,GAAAE,CAAA,OAAAO,EAAA,MAAAC,CAAA,YAAAA,EAAA,eAAAC,CAAA,EAAAD,CAAA,EAAAE,CAAA,WAAAA,EAAA,WAAAH,EAAA,IAAAT,CAAA,CAAAQ,MAAA,KAAAK,IAAA,WAAAA,IAAA,MAAAC,KAAA,EAAAd,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;MAAA,IAAXC,IAAI,GAAAD,KAAA,CAAJC,IAAI;MACZf,MAAI,CAACS,GAAG,CAACO,eAAC,CAACC,IAAI,CAACF,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;MAClC,OAAOA,IAAI;IACZ,CAAC,CAAC,CACDG,KAAK,CAACV,mBAAU,CAACW,sBAAsB,EAAE,UAAC/H,CAAC,EAAK;MAChD,IAAIA,CAAC,CAACgI,MAAM,KAAK,GAAG,IAAIhI,CAAC,CAACiI,GAAG,CAACN,IAAI,CAACO,MAAM,CAACC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE;QAC9D;QACA,MAAMnI,CAAC;MACR;MAEA,IAAKA,CAAC,CAACgI,MAAM,IAAI,GAAG,IAAIhI,CAAC,CAACgI,MAAM,IAAI,GAAG,IAAKhI,CAAC,CAACgI,MAAM,KAAK,GAAG,EAAE;QAC7DhI,CAAC,CAACoI,OAAO,eAAA5D,MAAA,CAAe6D,IAAI,CAACC,SAAS,CAACtI,CAAC,CAACiI,GAAG,CAACN,IAAI,CAAC,CAAE;MACrD;MACA,MAAM3H,CAAC;IACR,CAAC,CAAC;EACJ;AACD,CACD,CAAC;AAED,IAAAuI,uBAAQ,EAAC,gBAAgB,EAAE1G,cAAc,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"timing-log.js","names":["require","_utils","_base","_dedentJs","_interopRequireDefault","_log","_moment","_stateRegister","_templateObject","_templateObject2","_createForOfIteratorHelper","r","e","t","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","_n","F","s","n","done","value","f","TypeError","o","a","u","call","next","return","_arrayLikeToArray","toString","slice","constructor","name","from","test","TimingLogModel","exports","BaseModel","extend","modelName","props","begin","type","required","end","events","default","created_date","modified_date","provisional","mode","values","children","appointment","hostedPreso","user","collections","attendee_set","remote_attendee_set","ajaxConfig","headers","toServer","toCompactFormat","_this","getShortURL","url","moment","utc","format","DATE_FORMAT","startIndex","i","is_unfocused","map","_ref","timestamp","path","isUnfocused","millis","diff","duration","concat","attendeeSet","attendee","join","remoteAttendeeSet","modeTypeMap","present","view","prep","review","modeType","compact","dedent","_taggedTemplateLiteral2","addEvent","_path","Error","time","push","DATE_FORMAT_T","checkEventsAscending","lastDate","sortEvents","_iterator","_step","event","isAfter","err","_ref2","log","warn","sort","event1","event2","save","data","options","Promise","resolve","toJSON","prototype","catch","_e$response","_e$response$body","_e$response$body$deta","status","response","body","detail","indexOf","_e$response2","message","JSON","stringify","register"],"sources":["../../src/models/timing-log.js"],"sourcesContent":["import \"./appointment.js\";\nimport \"./hosted-preso.js\";\nimport \"./user.js\";\nimport \"../collections/users.js\";\n\nimport { DATE_FORMAT, DATE_FORMAT_T } from \"../utils.js\";\n\nimport { BaseModel } from \"./base.js\";\nimport dedent from \"dedent-js\";\nimport { getShortURL } from \"../utils.js\";\nimport log from \"../log.js\";\nimport moment from \"moment\";\nimport { register } from \"../state-register.js\";\n\n/**\n * @typedef Event\n * @type {object}\n * @property {string} path\n * @property {date} timestamp\n * @example\n * {\n *\t\"path\": \"https://client.salespreso.com/api/deckversions/4/\",\n *\t\"timestamp\": \"2016-10-27T00:42:47.045186Z\",\n *\t\"is_unfocused\": false,\n * }\n * @example\n * {\n * \t\"path\": \"https://client.salespreso.com/api/sections/28/\",\n * \t\"timestamp\": \"2016-10-27T00:43:59.430102Z\"\n *\t\"is_unfocused\": false,\n * }\n * @example\n * {\n * \t\"path\": \"https://client.salespreso.com/api/slides/380/\",\n * \t\"timestamp\": \"2016-10-27T00:45:01.038661Z\"\n *\t\"is_unfocused\": false,\n * }\n * @example\n * {\n * \t\"path\": \"https://client.salespreso.com/api/slides/378/\",\n * \t\"timestamp\": \"2016-10-27T00:45:13.495713Z\"\n *\t\"is_unfocused\": false,\n * }\n */\n\n/**\n * @constructor\n * @alias models.TimingLogModel\n * @extends models.BaseModel\n */\nexport const TimingLogModel = BaseModel.extend(\n\t/** @lends models.TimingLogModel# */ {\n\t\tmodelName: \"timinglogs\",\n\n\t\t/**\n\t\t * @property {date} begin\n\t\t * @property {date} end\n\t\t * @property {Event[]} events\n\t\t * @property {date} created_date\n\t\t * @property {date} modified_date\n\t\t */\n\t\tprops: {\n\t\t\tbegin: { type: \"date\", required: true },\n\t\t\tend: \"date\",\n\t\t\tevents: { type: \"array\", default: () => [] },\n\t\t\tcreated_date: \"date\",\n\t\t\tmodified_date: \"date\",\n\t\t\tprovisional: { type: \"boolean\", default: () => true },\n\t\t\tmode: {\n\t\t\t\ttype: \"string\",\n\t\t\t\tdefault: () => \"view\",\n\t\t\t\tvalues: [\n\t\t\t\t\t// A salesperson has presented a preso\n\t\t\t\t\t\"present\",\n\t\t\t\t\t// A customer has viewed an online preso\n\t\t\t\t\t\"view\",\n\t\t\t\t\t// A prep user or salesperson as prepared a preso\n\t\t\t\t\t\"prep\",\n\t\t\t\t\t// A salesperson has reviewed an old preso\n\t\t\t\t\t\"review\",\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\t/**\n\t\t * @property {models.AppointmentModel} appointment\n\t\t * @property {models.UserModel} user\n\t\t */\n\t\tchildren: {\n\t\t\tappointment: \"AppointmentModel\",\n\t\t\thostedPreso: \"HostedPresoModel\",\n\t\t\tuser: \"UserModel\",\n\t\t},\n\n\t\t/**\n\t\t * @property {collections.UserCollection} attendee_set\n\t\t * @property {collections.UserCollection} remote_attendee_set\n\t\t */\n\t\tcollections: {\n\t\t\tattendee_set: \"UserCollection\",\n\t\t\tremote_attendee_set: \"UserCollection\",\n\t\t},\n\n\t\tajaxConfig() {\n\t\t\treturn {\n\t\t\t\theaders: {\n\t\t\t\t\t\"content-type\": \"application/vnd.salespreso+timinglog\",\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\n\t\ttoServer() {\n\t\t\treturn this.toCompactFormat();\n\t\t},\n\n\t\t/**\n\t\t * Returns the current timing log model in expected compact format.\n\t\t * @see http://doc.dev.salespreso.com/api/tracking.html#compact-representation\n\t\t * @returns {string}\n\t\t */\n\t\ttoCompactFormat() {\n\t\t\tconst user = getShortURL(this.user.url());\n\n\t\t\tconst url = getShortURL(\n\t\t\t\tthis.hostedPreso ? this.hostedPreso.url() : this.appointment.url(),\n\t\t\t);\n\t\t\t// At this point, the expected output should have a space instead of a T in this\n\t\t\t// date format.\n\t\t\tconst begin = moment.utc(this.begin).format(DATE_FORMAT);\n\n\t\t\t// Strip out all unfocused events from the start (including any that are\n\t\t\t// in a row), as these will throw errors server side.\n\t\t\tlet startIndex = 0;\n\t\t\tfor (let i = 0; i < this.events.length; i++) {\n\t\t\t\tif (this.events[i].is_unfocused) {\n\t\t\t\t\tstartIndex = i + 1;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst events = this.events\n\t\t\t\t.slice(startIndex)\n\t\t\t\t.map(({ timestamp, path, is_unfocused: isUnfocused }) => {\n\t\t\t\t\tconst millis = moment(timestamp).diff(moment(this.begin), \"millis\");\n\n\t\t\t\t\tif (isUnfocused) {\n\t\t\t\t\t\tconst duration = moment\n\t\t\t\t\t\t\t.utc(timestamp)\n\t\t\t\t\t\t\t.diff(moment.utc(begin), \"milliseconds\");\n\n\t\t\t\t\t\treturn `${duration}ms unfocused`;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn `${millis}ms ${getShortURL(path)}`;\n\t\t\t\t});\n\n\t\t\tconst attendeeSet =\n\t\t\t\tthis.attendee_set && this.attendee_set.length\n\t\t\t\t\t? `\\n${this.attendee_set\n\t\t\t\t\t\t\t.map((attendee) => getShortURL(attendee.url()))\n\t\t\t\t\t\t\t.join(\" \")} attending`\n\t\t\t\t\t: \"\";\n\n\t\t\tconst remoteAttendeeSet =\n\t\t\t\tthis.remote_attendee_set && this.remote_attendee_set.length\n\t\t\t\t\t? `\\n${this.remote_attendee_set\n\t\t\t\t\t\t\t.map((attendee) => getShortURL(attendee.url()))\n\t\t\t\t\t\t\t.join(\" \")} attending remotely`\n\t\t\t\t\t: \"\";\n\n\t\t\tconst modeTypeMap = {\n\t\t\t\tpresent: \"viewing\",\n\t\t\t\tview: \"viewing\",\n\t\t\t\tprep: \"preparing\",\n\t\t\t\treview: \"reviewing\",\n\t\t\t};\n\n\t\t\tconst modeType = modeTypeMap[this.mode];\n\n\t\t\t// Note the newline is required at the end for the parser\n\t\t\t// to understand this\n\t\t\tlet compact = dedent`\n\t\t\t${user} ${modeType} ${url}${attendeeSet}${remoteAttendeeSet}\n\t\t\t${begin}\n\t\t\t${events.join(\"\\n\")}\\n\n\t\t`;\n\n\t\t\tif (this.end) {\n\t\t\t\tconst end = moment.utc(this.end).format(DATE_FORMAT);\n\t\t\t\tcompact += end;\n\t\t\t\tif (this.provisional) {\n\t\t\t\t\tcompact += \" provisional\";\n\t\t\t\t}\n\t\t\t\tcompact += \"\\n\";\n\t\t\t}\n\n\t\t\treturn compact;\n\t\t},\n\n\t\t/**\n\t\t * Add a new event to the log\n\t\t * @param {string} path - URL path. Matches a deck related endpoint (deckversion, section, slide. etc.)\n\t\t * @param {any} timestamp - A timestamp for the event - note that it can be anything that can be passed to moment\n\t\t * @example\n\t\t * const timingLog = new TimingLogModel();\n\t\t * timingLog.addEvent(\"http://client.salespreso.com/api/sections/28/\", moment());\n\t\t * timingLog.addEvent(\"http://client.salespreso.com/api/slides/100/\", \"2016-10-27T00:42:47.045186Z\");\n\t\t */\n\t\taddEvent(_path, timestamp) {\n\t\t\tlet path = _path;\n\n\t\t\tif (!path) {\n\t\t\t\tthrow new Error(\"A path is required\");\n\t\t\t}\n\t\t\tif (!timestamp) {\n\t\t\t\tthrow new Error(\"A timestamp is required\");\n\t\t\t}\n\n\t\t\tconst time = moment.utc(timestamp);\n\t\t\tconst isUnfocused = path === \"unfocused\";\n\n\t\t\tif (isUnfocused) {\n\t\t\t\tif (!this.events.length) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tfor (let i = this.events.length - 1; i >= 0; i--) {\n\t\t\t\t\tif (!this.events[i].is_unfocused) {\n\t\t\t\t\t\tpath = this.events[i].path;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.events.push({\n\t\t\t\ttimestamp: time.format(DATE_FORMAT_T),\n\t\t\t\tpath,\n\t\t\t\tis_unfocused: isUnfocused,\n\t\t\t});\n\t\t},\n\n\t\tcheckEventsAscending() {\n\t\t\tlet lastDate = null;\n\t\t\tlet sortEvents = false;\n\n\t\t\tfor (const event of this.events) {\n\t\t\t\tconst timestamp = moment(event.timestamp);\n\n\t\t\t\tif (lastDate && lastDate.isAfter(timestamp)) {\n\t\t\t\t\tsortEvents = true;\n\t\t\t\t}\n\n\t\t\t\tlastDate = timestamp;\n\t\t\t}\n\n\t\t\tif (sortEvents) {\n\t\t\t\tconst events = this.events.map(({ timestamp, path }) => {\n\t\t\t\t\treturn `${timestamp} ${getShortURL(path)}`;\n\t\t\t\t});\n\t\t\t\tlog.warn(dedent`\n\t\t\t\t\tEvents must be in ascending order. Instead we found:\n\n\t\t\t\t\t${this.begin} - begin\n\t\t\t\t\t${events.join(\"\\n\")}\n\t\t\t\t\t${this.end} - end\n\t\t\t\t`);\n\n\t\t\t\tthis.sortEvents();\n\t\t\t}\n\t\t},\n\n\t\t// We can't trust the server to give us events in the\n\t\t// correct order, so we sort them when necessary\n\t\tsortEvents() {\n\t\t\tthis.events.sort((event1, event2) => {\n\t\t\t\tconst diff = moment(event2.timestamp).diff(moment(event1.timestamp));\n\n\t\t\t\tif (diff > 0) {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else if (diff < 0) {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\n\t\t\t\treturn 0;\n\t\t\t});\n\t\t},\n\n\t\tsave(data, options) {\n\t\t\tif (!this.events.length) {\n\t\t\t\treturn Promise.resolve(this.toJSON());\n\t\t\t}\n\n\t\t\tthis.checkEventsAscending();\n\n\t\t\treturn BaseModel.prototype.save.call(this, data, options).catch((e) => {\n\t\t\t\tif (e.status === 405 && e.response?.body?.detail?.indexOf(\"end\") > -1) {\n\t\t\t\t\tthrow e;\n\t\t\t\t}\n\n\t\t\t\tif ((e.status >= 400 && e.status <= 499) || e.status === 503) {\n\t\t\t\t\te.message += `\\nBody: ${JSON.stringify(e.response?.body)}`;\n\t\t\t\t}\n\t\t\t\tthrow e;\n\t\t\t});\n\t\t},\n\t},\n);\n\nregister(\"TimingLogModel\", TimingLogModel);\n"],"mappings":";;;;;;;;AAAAA,OAAA;AACAA,OAAA;AACAA,OAAA;AACAA,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAEA,IAAAK,IAAA,GAAAD,sBAAA,CAAAJ,OAAA;AACA,IAAAM,OAAA,GAAAF,sBAAA,CAAAJ,OAAA;AACA,IAAAO,cAAA,GAAAP,OAAA;AAAgD,IAAAQ,eAAA,EAAAC,gBAAA;AAAA,SAAAC,2BAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,yBAAAC,MAAA,IAAAH,CAAA,CAAAG,MAAA,CAAAC,QAAA,KAAAJ,CAAA,qBAAAE,CAAA,QAAAG,KAAA,CAAAC,OAAA,CAAAN,CAAA,MAAAE,CAAA,GAAAK,2BAAA,CAAAP,CAAA,MAAAC,CAAA,IAAAD,CAAA,uBAAAA,CAAA,CAAAQ,MAAA,IAAAN,CAAA,KAAAF,CAAA,GAAAE,CAAA,OAAAO,EAAA,MAAAC,CAAA,YAAAA,EAAA,eAAAC,CAAA,EAAAD,CAAA,EAAAE,CAAA,WAAAA,EAAA,WAAAH,EAAA,IAAAT,CAAA,CAAAQ,MAAA,KAAAK,IAAA,WAAAA,IAAA,MAAAC,KAAA,EAAAd,CAAA,CAAAS,EAAA,UAAAR,CAAA,WAAAA,EAAAD,CAAA,UAAAA,CAAA,KAAAe,CAAA,EAAAL,CAAA,gBAAAM,SAAA,iJAAAC,CAAA,EAAAC,CAAA,O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AJ,qBAAA,uBAAxBA,qBAAA,CAA0BK,OAAO,CAAC,KAAK,CAAC,IAAG,CAAC,CAAC,EAAE;QACtE,MAAM5H,CAAC;MACR;MAEA,IAAKA,CAAC,CAACwH,MAAM,IAAI,GAAG,IAAIxH,CAAC,CAACwH,MAAM,IAAI,GAAG,IAAKxH,CAAC,CAACwH,MAAM,KAAK,GAAG,EAAE;QAAA,IAAAK,YAAA;QAC7D7H,CAAC,CAAC8H,OAAO,eAAAnD,MAAA,CAAeoD,IAAI,CAACC,SAAS,EAAAH,YAAA,GAAC7H,CAAC,CAACyH,QAAQ,cAAAI,YAAA,uBAAVA,YAAA,CAAYH,IAAI,CAAC,CAAE;MAC3D;MACA,MAAM1H,CAAC;IACR,CAAC,CAAC;EACH;AACD,CACD,CAAC;AAED,IAAAiI,uBAAQ,EAAC,gBAAgB,EAAEpG,cAAc,CAAC","ignoreList":[]}
|
package/cjs/sync.js
CHANGED
|
@@ -11,7 +11,6 @@ var _superagentBluebirdPromise = _interopRequireDefault(require("superagent-blue
|
|
|
11
11
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
12
12
|
var _log = _interopRequireDefault(require("./log.js"));
|
|
13
13
|
var _middleware = require("./middleware.js");
|
|
14
|
-
var _superagent = _interopRequireDefault(require("superagent"));
|
|
15
14
|
var defaults = _lodash.default.defaults;
|
|
16
15
|
var assign = _lodash.default.assign;
|
|
17
16
|
|
|
@@ -131,12 +130,24 @@ var ajaxSync = exports.ajaxSync = function ajaxSync(method, model, options) {
|
|
|
131
130
|
// Combine generated headers with user's headers.
|
|
132
131
|
if (ajaxConfig.headers) {
|
|
133
132
|
for (var key in ajaxConfig.headers) {
|
|
134
|
-
|
|
133
|
+
var lowerKey = key.toLowerCase();
|
|
134
|
+
// Use superagent's .type() method to explicitly set content-type
|
|
135
|
+
// This ensures superagent respects the content-type and doesn't override it
|
|
136
|
+
if (lowerKey === "content-type") {
|
|
137
|
+
request.type(ajaxConfig.headers[key].split(";")[0]);
|
|
138
|
+
} else {
|
|
139
|
+
request.header[lowerKey] = ajaxConfig.headers[key];
|
|
140
|
+
}
|
|
135
141
|
}
|
|
136
142
|
}
|
|
137
143
|
if (options.headers) {
|
|
138
144
|
for (var _key2 in options.headers) {
|
|
139
|
-
|
|
145
|
+
var _lowerKey = _key2.toLowerCase();
|
|
146
|
+
if (_lowerKey === "content-type") {
|
|
147
|
+
request.type(options.headers[_key2].split(";")[0]);
|
|
148
|
+
} else {
|
|
149
|
+
request.header[_lowerKey] = options.headers[_key2];
|
|
150
|
+
}
|
|
140
151
|
}
|
|
141
152
|
}
|
|
142
153
|
|
|
@@ -191,8 +202,9 @@ var ajaxSync = exports.ajaxSync = function ajaxSync(method, model, options) {
|
|
|
191
202
|
request.emit("success", response);
|
|
192
203
|
return data;
|
|
193
204
|
});
|
|
194
|
-
}).catch(
|
|
195
|
-
|
|
205
|
+
}).catch(function (e) {
|
|
206
|
+
var _e$res;
|
|
207
|
+
if (typeof e.status !== "undefined" && (_e$res = e.res) !== null && _e$res !== void 0 && _e$res.body && (e.status >= 400 && e.status < 500 || e.status === 503)) {
|
|
196
208
|
e.message += "\nBody: ".concat(JSON.stringify(e.res.body));
|
|
197
209
|
}
|
|
198
210
|
throw e;
|
package/cjs/sync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","names":["_bluebird","_interopRequireDefault","require","_superagentBluebirdPromise","_lodash","_log","_middleware","_superagent","defaults","_","assign","urlError","Error","methodMap","exports","create","update","patch","delete","read","defaultFetchURL","_ref","model","log","warn","url","buildURL","_ref2","method","split","sync","defaultOpts","_this","syncArguments","arguments","syncActions","middlewares","forEach","middleware","push","apply","Promise","all","then","_len","length","newOpts","Array","_key","joinedOpts","merge","concat","_toConsumableArray2","default","flat","ajaxSync","call","options","type","emulateHTTP","emulateJSON","params","result","data","batch","json","attrs","toJSON","requestSettings","request","SuperAgentRequest","toServer","isArray","FormData","pick","Object","keys","send","xhr","preflight","mc","getNextMiddleware","middlewareInterceptor","response","intercept","resolve","trigger","ajaxConfig","headers","key","header","toLowerCase","cachedResponse","JSON","parse","text","each","success","catch","error","message","timeout","e","set","emit","superagent","SuperagentPromiseError","res","body","status","stringify","originalError","code"],"sources":["../src/sync.js"],"sourcesContent":["import Promise from \"bluebird\";\nimport SuperAgentRequest from \"superagent-bluebird-promise\";\nimport _ from \"lodash\";\nimport log from \"./log.js\";\nimport { middlewares } from \"./middleware.js\";\nimport superagent from \"superagent\";\n\nconst defaults = _.defaults;\nconst assign = _.assign;\n\n// Throw an error when a URL is needed, and none is supplied.\nconst urlError = function () {\n\tthrow new Error(`A \"url\" property or function must be specified`);\n};\n\n// Map from CRUD to HTTP for our default `Backbone.sync` implementation.\nexport const methodMap = {\n\tcreate: \"POST\",\n\tupdate: \"PUT\",\n\tpatch: \"PATCH\",\n\tdelete: \"DELETE\",\n\tread: \"GET\",\n};\n\nexport const defaultFetchURL = function ({ model }) {\n\tlog.warn(\"Deprecation: defaultFetchURL is deprecated. Just use .url()\");\n\treturn model.url();\n};\n\nexport const buildURL = function ({ method, model }) {\n\tconst url = model.url();\n\n\t// If not a GET request, strip the query params from the url\n\tif (method !== \"read\") {\n\t\treturn url.split(\"?\")[0];\n\t}\n\n\treturn url;\n};\n\nexport const sync = function (method, model, defaultOpts) {\n\tconst syncArguments = arguments;\n\n\tif (method === \"read\") {\n\t\t// look for sync methods\n\t\tconst syncActions = [];\n\t\tmiddlewares.forEach((middleware) => {\n\t\t\tif (middleware.sync) {\n\t\t\t\tsyncActions.push(middleware.sync.apply(this, syncArguments));\n\t\t\t}\n\t\t});\n\n\t\treturn Promise.all(syncActions).then((...newOpts) => {\n\t\t\tconst joinedOpts = _.merge({}, defaultOpts, ...newOpts.flat());\n\t\t\treturn ajaxSync.call(this, method, model, joinedOpts);\n\t\t});\n\t}\n\treturn ajaxSync.call(this, method, model, defaultOpts);\n};\n\nexport const ajaxSync = function (method, model, options) {\n\tconst type = methodMap[method];\n\n\t// Default options, unless specified.\n\tdefaults(options || {}, {\n\t\temulateHTTP: false,\n\t\temulateJSON: false,\n\t});\n\n\t// Default request options.\n\tconst params = { type: type };\n\n\t// Ensure that we have a URL.\n\tif (!options.url) {\n\t\toptions.url = _.result(model, \"url\") || urlError();\n\t}\n\n\t// Ensure that we have the appropriate request data.\n\tif (\n\t\toptions.data === null &&\n\t\tmodel &&\n\t\t(method === \"create\" ||\n\t\t\tmethod === \"update\" ||\n\t\t\tmethod === \"patch\" ||\n\t\t\t(method === \"delete\" && options.batch))\n\t) {\n\t\tparams.json = options.attrs || model.toJSON(options);\n\t}\n\n\tconst url = buildURL({ method, model, options });\n\n\tconst requestSettings = assign(params, options);\n\trequestSettings.method = type;\n\n\tconst request = SuperAgentRequest(type, url);\n\n\tif (\n\t\ttype === \"PATCH\" ||\n\t\ttype === \"POST\" ||\n\t\ttype === \"PUT\" ||\n\t\t(type === \"DELETE\" && options.batch)\n\t) {\n\t\tlet data = model.toServer();\n\n\t\t// Note we can use formdata to override the way a patch works - if we\n\t\t// are doing this it's for a particular patch with an image or file,\n\t\t// probably.\n\t\tif (type === \"PATCH\" && !_.isArray(data) && !(data instanceof FormData)) {\n\t\t\t// Make sure we're only updating data actually passed to the save\n\t\t\t// function, rather than automatically generated stuff\n\t\t\tdata = _.pick(options.attrs, Object.keys(data));\n\t\t}\n\t\trequest.send(data);\n\t}\n\n\toptions.xhr = request;\n\n\tmiddlewares.forEach((middleware) => {\n\t\tif (middleware.preflight) {\n\t\t\tmiddleware.preflight(request, model, options);\n\t\t}\n\t});\n\n\tlet mc = 0;\n\n\tfunction getNextMiddleware(request) {\n\t\treturn function middlewareInterceptor(response) {\n\t\t\tif (mc < middlewares.length) {\n\t\t\t\treturn middlewares[mc++]\n\t\t\t\t\t.intercept(request, response, model)\n\t\t\t\t\t.then(getNextMiddleware(request));\n\t\t\t}\n\t\t\treturn Promise.resolve(response);\n\t\t};\n\t}\n\n\tmodel.trigger(\"request\", model, request, options, requestSettings);\n\trequest.requestSettings = requestSettings;\n\n\tconst ajaxConfig = _.result(model, \"ajaxConfig\") || {};\n\n\t// Combine generated headers with user's headers.\n\tif (ajaxConfig.headers) {\n\t\tfor (const key in ajaxConfig.headers) {\n\t\t\trequest.header[key.toLowerCase()] = ajaxConfig.headers[key];\n\t\t}\n\t}\n\n\tif (options.headers) {\n\t\tfor (const key in options.headers) {\n\t\t\trequest.header[key.toLowerCase()] = options.headers[key];\n\t\t}\n\t}\n\n\t// TODO: Remove me when this can be moved... for now this removal is quite a complex\n\t// process.\n\tif (options.cachedResponse) {\n\t\treturn Promise.resolve(options.cachedResponse)\n\t\t\t.then(getNextMiddleware(request))\n\t\t\t.then((response) => {\n\t\t\t\tif (!response.data) {\n\t\t\t\t\tresponse.data = JSON.parse(response.text);\n\t\t\t\t}\n\n\t\t\t\treturn Promise.each(middlewares, (middleware) => {\n\t\t\t\t\treturn middleware.success(request, response, model, true);\n\t\t\t\t}).then(() => {\n\t\t\t\t\tif (options.success) {\n\t\t\t\t\t\toptions.success(response.data, \"success\", response);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn response.data;\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((response) => {\n\t\t\t\treturn Promise.each(middlewares, (middleware) => {\n\t\t\t\t\treturn middleware.error(response, model);\n\t\t\t\t}).then(() => {\n\t\t\t\t\tif (options.error) {\n\t\t\t\t\t\toptions.error(response, \"error\", response.message);\n\t\t\t\t\t}\n\t\t\t\t\tthrow response;\n\t\t\t\t});\n\t\t\t});\n\t}\n\n\treturn (\n\t\trequest\n\t\t\t// Force a timeout on every request. Intermittent connections\n\t\t\t// can have the request continue trying for minutes otherwise.\n\t\t\t// 60 seconds is the timeout the server has, so we go for 65 seconds,\n\t\t\t// so we give the chance to the server to time out first - helps with\n\t\t\t// debugging.\n\t\t\t.timeout(65 * 1000)\n\t\t\t.then(getNextMiddleware(request))\n\t\t\t.then((response) => {\n\t\t\t\tlet data;\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse(response.text);\n\t\t\t\t} catch (e) {\n\t\t\t\t\tdata = response;\n\t\t\t\t}\n\n\t\t\t\tif (type !== \"DELETE\") {\n\t\t\t\t\tmodel.set(data);\n\t\t\t\t}\n\n\t\t\t\treturn Promise.each(middlewares, (middleware) => {\n\t\t\t\t\treturn middleware.success(request, response, model, false);\n\t\t\t\t}).then(() => {\n\t\t\t\t\tif (options.success) {\n\t\t\t\t\t\toptions.success(data, \"success\", response);\n\t\t\t\t\t}\n\t\t\t\t\trequest.emit(\"success\", response);\n\t\t\t\t\treturn data;\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch(superagent.SuperagentPromiseError, (e) => {\n\t\t\t\tif (\n\t\t\t\t\te.res &&\n\t\t\t\t\te.res.body &&\n\t\t\t\t\t((e.status >= 400 && e.status < 500) || e.status === 503)\n\t\t\t\t) {\n\t\t\t\t\te.message += `\\nBody: ${JSON.stringify(e.res.body)}`;\n\t\t\t\t}\n\t\t\t\tthrow e;\n\t\t\t})\n\t\t\t.catch((response) => {\n\t\t\t\treturn Promise.each(middlewares, (middleware) => {\n\t\t\t\t\treturn middleware.error(response);\n\t\t\t\t}).then(() => {\n\t\t\t\t\tif (options.error) {\n\t\t\t\t\t\toptions.error(response, \"error\", response.message);\n\t\t\t\t\t}\n\n\t\t\t\t\t// Provide a more explanatory error message on timeout\n\t\t\t\t\tif (\n\t\t\t\t\t\tresponse &&\n\t\t\t\t\t\tresponse.originalError &&\n\t\t\t\t\t\tresponse.originalError.code === \"ECONNABORTED\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Failed ${type} request on url: ${url}. ${response.message}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow response;\n\t\t\t\t});\n\t\t\t})\n\t);\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,0BAAA,GAAAF,sBAAA,CAAAC,OAAA;A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ACH,CAAC,CAAC,CACDmC,KAAK,CAACO,mBAAU,CAACC,sBAAsB,EAAE,UAACJ,CAAC,EAAK;IAChD,IACCA,CAAC,CAACK,GAAG,IACLL,CAAC,CAACK,GAAG,CAACC,IAAI,KACRN,CAAC,CAACO,MAAM,IAAI,GAAG,IAAIP,CAAC,CAACO,MAAM,GAAG,GAAG,IAAKP,CAAC,CAACO,MAAM,KAAK,GAAG,CAAC,EACxD;MACDP,CAAC,CAACF,OAAO,eAAAjD,MAAA,CAAe0C,IAAI,CAACiB,SAAS,CAACR,CAAC,CAACK,GAAG,CAACC,IAAI,CAAC,CAAE;IACrD;IACA,MAAMN,CAAC;EACR,CAAC,CAAC,CACDJ,KAAK,CAAC,UAACf,QAAQ,EAAK;IACpB,OAAO1C,iBAAO,CAACuD,IAAI,CAAC5D,uBAAW,EAAE,UAACE,UAAU,EAAK;MAChD,OAAOA,UAAU,CAAC6D,KAAK,CAAChB,QAAQ,CAAC;IAClC,CAAC,CAAC,CAACxC,IAAI,CAAC,YAAM;MACb,IAAIc,OAAO,CAAC0C,KAAK,EAAE;QAClB1C,OAAO,CAAC0C,KAAK,CAAChB,QAAQ,EAAE,OAAO,EAAEA,QAAQ,CAACiB,OAAO,CAAC;MACnD;;MAEA;MACA,IACCjB,QAAQ,IACRA,QAAQ,CAAC4B,aAAa,IACtB5B,QAAQ,CAAC4B,aAAa,CAACC,IAAI,KAAK,cAAc,EAC7C;QACD,MAAM,IAAIpG,KAAK,WAAAuC,MAAA,CACJO,IAAI,uBAAAP,MAAA,CAAoB1B,GAAG,QAAA0B,MAAA,CAAKgC,QAAQ,CAACiB,OAAO,CAC3D,CAAC;MACF;MAEA,MAAMjB,QAAQ;IACf,CAAC,CAAC;EACH,CAAC,CAAC;AAEL,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"sync.js","names":["_bluebird","_interopRequireDefault","require","_superagentBluebirdPromise","_lodash","_log","_middleware","defaults","_","assign","urlError","Error","methodMap","exports","create","update","patch","delete","read","defaultFetchURL","_ref","model","log","warn","url","buildURL","_ref2","method","split","sync","defaultOpts","_this","syncArguments","arguments","syncActions","middlewares","forEach","middleware","push","apply","Promise","all","then","_len","length","newOpts","Array","_key","joinedOpts","merge","concat","_toConsumableArray2","default","flat","ajaxSync","call","options","type","emulateHTTP","emulateJSON","params","result","data","batch","json","attrs","toJSON","requestSettings","request","SuperAgentRequest","toServer","isArray","FormData","pick","Object","keys","send","xhr","preflight","mc","getNextMiddleware","middlewareInterceptor","response","intercept","resolve","trigger","ajaxConfig","headers","key","lowerKey","toLowerCase","header","cachedResponse","JSON","parse","text","each","success","catch","error","message","timeout","e","set","emit","_e$res","status","res","body","stringify","originalError","code"],"sources":["../src/sync.js"],"sourcesContent":["import Promise from \"bluebird\";\nimport SuperAgentRequest from \"superagent-bluebird-promise\";\nimport _ from \"lodash\";\nimport log from \"./log.js\";\nimport { middlewares } from \"./middleware.js\";\n\nconst defaults = _.defaults;\nconst assign = _.assign;\n\n// Throw an error when a URL is needed, and none is supplied.\nconst urlError = function () {\n\tthrow new Error(`A \"url\" property or function must be specified`);\n};\n\n// Map from CRUD to HTTP for our default `Backbone.sync` implementation.\nexport const methodMap = {\n\tcreate: \"POST\",\n\tupdate: \"PUT\",\n\tpatch: \"PATCH\",\n\tdelete: \"DELETE\",\n\tread: \"GET\",\n};\n\nexport const defaultFetchURL = function ({ model }) {\n\tlog.warn(\"Deprecation: defaultFetchURL is deprecated. Just use .url()\");\n\treturn model.url();\n};\n\nexport const buildURL = function ({ method, model }) {\n\tconst url = model.url();\n\n\t// If not a GET request, strip the query params from the url\n\tif (method !== \"read\") {\n\t\treturn url.split(\"?\")[0];\n\t}\n\n\treturn url;\n};\n\nexport const sync = function (method, model, defaultOpts) {\n\tconst syncArguments = arguments;\n\n\tif (method === \"read\") {\n\t\t// look for sync methods\n\t\tconst syncActions = [];\n\t\tmiddlewares.forEach((middleware) => {\n\t\t\tif (middleware.sync) {\n\t\t\t\tsyncActions.push(middleware.sync.apply(this, syncArguments));\n\t\t\t}\n\t\t});\n\n\t\treturn Promise.all(syncActions).then((...newOpts) => {\n\t\t\tconst joinedOpts = _.merge({}, defaultOpts, ...newOpts.flat());\n\t\t\treturn ajaxSync.call(this, method, model, joinedOpts);\n\t\t});\n\t}\n\treturn ajaxSync.call(this, method, model, defaultOpts);\n};\n\nexport const ajaxSync = function (method, model, options) {\n\tconst type = methodMap[method];\n\n\t// Default options, unless specified.\n\tdefaults(options || {}, {\n\t\temulateHTTP: false,\n\t\temulateJSON: false,\n\t});\n\n\t// Default request options.\n\tconst params = { type: type };\n\n\t// Ensure that we have a URL.\n\tif (!options.url) {\n\t\toptions.url = _.result(model, \"url\") || urlError();\n\t}\n\n\t// Ensure that we have the appropriate request data.\n\tif (\n\t\toptions.data === null &&\n\t\tmodel &&\n\t\t(method === \"create\" ||\n\t\t\tmethod === \"update\" ||\n\t\t\tmethod === \"patch\" ||\n\t\t\t(method === \"delete\" && options.batch))\n\t) {\n\t\tparams.json = options.attrs || model.toJSON(options);\n\t}\n\n\tconst url = buildURL({ method, model, options });\n\n\tconst requestSettings = assign(params, options);\n\trequestSettings.method = type;\n\n\tconst request = SuperAgentRequest(type, url);\n\n\tif (\n\t\ttype === \"PATCH\" ||\n\t\ttype === \"POST\" ||\n\t\ttype === \"PUT\" ||\n\t\t(type === \"DELETE\" && options.batch)\n\t) {\n\t\tlet data = model.toServer();\n\n\t\t// Note we can use formdata to override the way a patch works - if we\n\t\t// are doing this it's for a particular patch with an image or file,\n\t\t// probably.\n\t\tif (type === \"PATCH\" && !_.isArray(data) && !(data instanceof FormData)) {\n\t\t\t// Make sure we're only updating data actually passed to the save\n\t\t\t// function, rather than automatically generated stuff\n\t\t\tdata = _.pick(options.attrs, Object.keys(data));\n\t\t}\n\t\trequest.send(data);\n\t}\n\n\toptions.xhr = request;\n\n\tmiddlewares.forEach((middleware) => {\n\t\tif (middleware.preflight) {\n\t\t\tmiddleware.preflight(request, model, options);\n\t\t}\n\t});\n\n\tlet mc = 0;\n\n\tfunction getNextMiddleware(request) {\n\t\treturn function middlewareInterceptor(response) {\n\t\t\tif (mc < middlewares.length) {\n\t\t\t\treturn middlewares[mc++]\n\t\t\t\t\t.intercept(request, response, model)\n\t\t\t\t\t.then(getNextMiddleware(request));\n\t\t\t}\n\t\t\treturn Promise.resolve(response);\n\t\t};\n\t}\n\n\tmodel.trigger(\"request\", model, request, options, requestSettings);\n\trequest.requestSettings = requestSettings;\n\n\tconst ajaxConfig = _.result(model, \"ajaxConfig\") || {};\n\n\t// Combine generated headers with user's headers.\n\tif (ajaxConfig.headers) {\n\t\tfor (const key in ajaxConfig.headers) {\n\t\t\tconst lowerKey = key.toLowerCase();\n\t\t\t// Use superagent's .type() method to explicitly set content-type\n\t\t\t// This ensures superagent respects the content-type and doesn't override it\n\t\t\tif (lowerKey === \"content-type\") {\n\t\t\t\trequest.type(ajaxConfig.headers[key].split(\";\")[0]);\n\t\t\t} else {\n\t\t\t\trequest.header[lowerKey] = ajaxConfig.headers[key];\n\t\t\t}\n\t\t}\n\t}\n\n\tif (options.headers) {\n\t\tfor (const key in options.headers) {\n\t\t\tconst lowerKey = key.toLowerCase();\n\t\t\tif (lowerKey === \"content-type\") {\n\t\t\t\trequest.type(options.headers[key].split(\";\")[0]);\n\t\t\t} else {\n\t\t\t\trequest.header[lowerKey] = options.headers[key];\n\t\t\t}\n\t\t}\n\t}\n\n\t// TODO: Remove me when this can be moved... for now this removal is quite a complex\n\t// process.\n\tif (options.cachedResponse) {\n\t\treturn Promise.resolve(options.cachedResponse)\n\t\t\t.then(getNextMiddleware(request))\n\t\t\t.then((response) => {\n\t\t\t\tif (!response.data) {\n\t\t\t\t\tresponse.data = JSON.parse(response.text);\n\t\t\t\t}\n\n\t\t\t\treturn Promise.each(middlewares, (middleware) => {\n\t\t\t\t\treturn middleware.success(request, response, model, true);\n\t\t\t\t}).then(() => {\n\t\t\t\t\tif (options.success) {\n\t\t\t\t\t\toptions.success(response.data, \"success\", response);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn response.data;\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((response) => {\n\t\t\t\treturn Promise.each(middlewares, (middleware) => {\n\t\t\t\t\treturn middleware.error(response, model);\n\t\t\t\t}).then(() => {\n\t\t\t\t\tif (options.error) {\n\t\t\t\t\t\toptions.error(response, \"error\", response.message);\n\t\t\t\t\t}\n\t\t\t\t\tthrow response;\n\t\t\t\t});\n\t\t\t});\n\t}\n\n\treturn (\n\t\trequest\n\t\t\t// Force a timeout on every request. Intermittent connections\n\t\t\t// can have the request continue trying for minutes otherwise.\n\t\t\t// 60 seconds is the timeout the server has, so we go for 65 seconds,\n\t\t\t// so we give the chance to the server to time out first - helps with\n\t\t\t// debugging.\n\t\t\t.timeout(65 * 1000)\n\t\t\t.then(getNextMiddleware(request))\n\t\t\t.then((response) => {\n\t\t\t\tlet data;\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse(response.text);\n\t\t\t\t} catch (e) {\n\t\t\t\t\tdata = response;\n\t\t\t\t}\n\n\t\t\t\tif (type !== \"DELETE\") {\n\t\t\t\t\tmodel.set(data);\n\t\t\t\t}\n\n\t\t\t\treturn Promise.each(middlewares, (middleware) => {\n\t\t\t\t\treturn middleware.success(request, response, model, false);\n\t\t\t\t}).then(() => {\n\t\t\t\t\tif (options.success) {\n\t\t\t\t\t\toptions.success(data, \"success\", response);\n\t\t\t\t\t}\n\t\t\t\t\trequest.emit(\"success\", response);\n\t\t\t\t\treturn data;\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((e) => {\n\t\t\t\tif (\n\t\t\t\t\ttypeof e.status !== \"undefined\" &&\n\t\t\t\t\te.res?.body &&\n\t\t\t\t\t((e.status >= 400 && e.status < 500) || e.status === 503)\n\t\t\t\t) {\n\t\t\t\t\te.message += `\\nBody: ${JSON.stringify(e.res.body)}`;\n\t\t\t\t}\n\t\t\t\tthrow e;\n\t\t\t})\n\t\t\t.catch((response) => {\n\t\t\t\treturn Promise.each(middlewares, (middleware) => {\n\t\t\t\t\treturn middleware.error(response);\n\t\t\t\t}).then(() => {\n\t\t\t\t\tif (options.error) {\n\t\t\t\t\t\toptions.error(response, \"error\", response.message);\n\t\t\t\t\t}\n\n\t\t\t\t\t// Provide a more explanatory error message on timeout\n\t\t\t\t\tif (\n\t\t\t\t\t\tresponse &&\n\t\t\t\t\t\tresponse.originalError &&\n\t\t\t\t\t\tresponse.originalError.code === \"ECONNABORTED\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Failed ${type} request on url: ${url}. ${response.message}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow response;\n\t\t\t\t});\n\t\t\t})\n\t);\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,0BAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,IAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAEA,IAAMK,QAAQ,GAAGC,eAAC,CAACD,QAAQ;AAC3B,IAAME,MAAM,GAAGD,eAAC,CAACC,MAAM;;AAEvB;AACA,IAAMC,QAAQ,GAAG,SAAXA,QAAQA,CAAA,EAAe;EAC5B,MAAM,IAAIC,KAAK,mDAAiD,CAAC;AAClE,CAAC;;AAED;AACO,IAAMC,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG;EACxBE,MAAM,EAAE,MAAM;EACdC,MAAM,EAAE,KAAK;EACbC,KAAK,EAAE,OAAO;EACdC,MAAM,EAAE,QAAQ;EAChBC,IAAI,EAAE;AACP,CAAC;AAEM,IAAMC,eAAe,GAAAN,OAAA,CAAAM,eAAA,GAAG,SAAlBA,eAAeA,CAAAC,IAAA,EAAwB;EAAA,IAATC,KAAK,GAAAD,IAAA,CAALC,KAAK;EA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,CAAC,CAACI,MAAM,GAAG,GAAG,IAAKJ,CAAC,CAACI,MAAM,KAAK,GAAG,CAAC,EACxD;MACDJ,CAAC,CAACF,OAAO,eAAAlD,MAAA,CAAe2C,IAAI,CAACgB,SAAS,CAACP,CAAC,CAACK,GAAG,CAACC,IAAI,CAAC,CAAE;IACrD;IACA,MAAMN,CAAC;EACR,CAAC,CAAC,CACDJ,KAAK,CAAC,UAAChB,QAAQ,EAAK;IACpB,OAAO1C,iBAAO,CAACwD,IAAI,CAAC7D,uBAAW,EAAE,UAACE,UAAU,EAAK;MAChD,OAAOA,UAAU,CAAC8D,KAAK,CAACjB,QAAQ,CAAC;IAClC,CAAC,CAAC,CAACxC,IAAI,CAAC,YAAM;MACb,IAAIc,OAAO,CAAC2C,KAAK,EAAE;QAClB3C,OAAO,CAAC2C,KAAK,CAACjB,QAAQ,EAAE,OAAO,EAAEA,QAAQ,CAACkB,OAAO,CAAC;MACnD;;MAEA;MACA,IACClB,QAAQ,IACRA,QAAQ,CAAC4B,aAAa,IACtB5B,QAAQ,CAAC4B,aAAa,CAACC,IAAI,KAAK,cAAc,EAC7C;QACD,MAAM,IAAIpG,KAAK,WAAAuC,MAAA,CACJO,IAAI,uBAAAP,MAAA,CAAoB1B,GAAG,QAAA0B,MAAA,CAAKgC,QAAQ,CAACkB,OAAO,CAC3D,CAAC;MACF;MAEA,MAAMlB,QAAQ;IACf,CAAC,CAAC;EACH,CAAC,CAAC;AAEL,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livepreso/api",
|
|
3
3
|
"license": "UNLICENSED",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.57.0",
|
|
5
5
|
"description": "Everything to do with talking to the SalePreso API",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"module": "esm/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"lodash": "^4.17.4",
|
|
24
24
|
"moment": "^2.18.1",
|
|
25
25
|
"qs": "^6.4.0",
|
|
26
|
-
"superagent": "
|
|
26
|
+
"superagent": "~10.3.0",
|
|
27
27
|
"superagent-bluebird-promise": "~4.2.0",
|
|
28
28
|
"systemjs": "^6.9.0"
|
|
29
29
|
},
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"jest-fixed-default-reporter": "~2.0.1",
|
|
57
57
|
"rosie": "~2.1.0",
|
|
58
58
|
"@faker-js/faker": "~7.5.0",
|
|
59
|
-
"
|
|
60
|
-
"
|
|
59
|
+
"@livepreso/eslint-config": "1.0.0",
|
|
60
|
+
"sp-test": "0.2.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"test:debug": "node --inspect node_modules/.bin/jest --watch --runInBand",
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
npm verbose cli /home/adam/.nvm/versions/node/v24.12.0/bin/node /home/adam/.nvm/versions/node/v24.12.0/bin/npm
|
|
2
|
+
npm info using npm@11.6.2
|
|
3
|
+
npm info using node@v24.12.0
|
|
4
|
+
npm verbose title npm run build:cjs
|
|
5
|
+
npm verbose argv "run" "build:cjs"
|
|
6
|
+
npm verbose logfile logs-max:10 dir:/home/adam/.npm/_logs/2026-02-17T02_45_57_253Z-
|
|
7
|
+
npm verbose logfile /home/adam/.npm/_logs/2026-02-17T02_45_57_253Z-debug-0.log
|
|
8
|
+
npm verbose cwd /home/adam/Programming/work/livepreso/modules/api
|
|
9
|
+
npm verbose os Linux 6.14.0-29-generic
|
|
10
|
+
npm verbose node v24.12.0
|
|
11
|
+
npm verbose npm v11.6.2
|
|
12
|
+
npm verbose exit 0
|
|
13
|
+
npm info ok
|
package/rush-logs/api.build.log
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
Invoking: run-p build:*
|
|
2
|
+
npm verbose cli /home/adam/.nvm/versions/node/v24.12.0/bin/node /home/adam/.nvm/versions/node/v24.12.0/bin/npm
|
|
3
|
+
npm info using npm@11.6.2
|
|
4
|
+
npm info using node@v24.12.0
|
|
5
|
+
npm verbose title npm run build:cjs
|
|
6
|
+
npm verbose argv "run" "build:cjs"
|
|
7
|
+
npm verbose logfile logs-max:10 dir:/home/adam/.npm/_logs/2026-02-17T02_45_57_253Z-
|
|
8
|
+
npm verbose logfile /home/adam/.npm/_logs/2026-02-17T02_45_57_253Z-debug-0.log
|
|
2
9
|
|
|
3
|
-
> @livepreso/api@6.
|
|
10
|
+
> @livepreso/api@6.55.2 build:cjs
|
|
4
11
|
> BABEL_ENV=cjs babel --delete-dir-on-start src/ --out-dir=cjs/ -s
|
|
5
12
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
Successfully compiled 165 files with Babel (6718ms).
|
|
14
|
+
npm verbose cwd /home/adam/Programming/work/livepreso/modules/api
|
|
15
|
+
npm verbose os Linux 6.14.0-29-generic
|
|
16
|
+
npm verbose node v24.12.0
|
|
17
|
+
npm verbose npm v11.6.2
|
|
18
|
+
npm verbose exit 0
|
|
19
|
+
npm info ok
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This project does not define the caching behavior of the "test" command, so caching has been disabled.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Invoking: jest --coverage --coverageReporters=json
|
|
@@ -197,18 +197,13 @@ export const ManifestJSONModel = BaseModel.extend(
|
|
|
197
197
|
const imports = _.map(fixturePaths, (fixture, key) => {
|
|
198
198
|
const path = `${rootAssetUrl}${fixture}`;
|
|
199
199
|
|
|
200
|
-
return superagent
|
|
201
|
-
.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
})
|
|
209
|
-
.catch(superagent.SuperagentPromiseError, (e) => {
|
|
210
|
-
throw e;
|
|
211
|
-
});
|
|
200
|
+
return superagent.get(path).then((response) => {
|
|
201
|
+
if (response.text) {
|
|
202
|
+
fixtures[key] = JSON.parse(response.text);
|
|
203
|
+
} else {
|
|
204
|
+
fixtures[key] = response.body || {};
|
|
205
|
+
}
|
|
206
|
+
});
|
|
212
207
|
});
|
|
213
208
|
|
|
214
209
|
await Promise.all(imports);
|
package/src/models/timing-log.js
CHANGED
|
@@ -5,15 +5,12 @@ import "../collections/users.js";
|
|
|
5
5
|
|
|
6
6
|
import { DATE_FORMAT, DATE_FORMAT_T } from "../utils.js";
|
|
7
7
|
|
|
8
|
-
import { Auth } from "../auth.js";
|
|
9
8
|
import { BaseModel } from "./base.js";
|
|
10
|
-
import _ from "lodash";
|
|
11
9
|
import dedent from "dedent-js";
|
|
12
10
|
import { getShortURL } from "../utils.js";
|
|
13
11
|
import log from "../log.js";
|
|
14
12
|
import moment from "moment";
|
|
15
13
|
import { register } from "../state-register.js";
|
|
16
|
-
import superagent from "superagent";
|
|
17
14
|
|
|
18
15
|
/**
|
|
19
16
|
* @typedef Event
|
|
@@ -104,6 +101,18 @@ export const TimingLogModel = BaseModel.extend(
|
|
|
104
101
|
remote_attendee_set: "UserCollection",
|
|
105
102
|
},
|
|
106
103
|
|
|
104
|
+
ajaxConfig() {
|
|
105
|
+
return {
|
|
106
|
+
headers: {
|
|
107
|
+
"content-type": "application/vnd.salespreso+timinglog",
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
toServer() {
|
|
113
|
+
return this.toCompactFormat();
|
|
114
|
+
},
|
|
115
|
+
|
|
107
116
|
/**
|
|
108
117
|
* Returns the current timing log model in expected compact format.
|
|
109
118
|
* @see http://doc.dev.salespreso.com/api/tracking.html#compact-representation
|
|
@@ -198,7 +207,9 @@ export const TimingLogModel = BaseModel.extend(
|
|
|
198
207
|
* timingLog.addEvent("http://client.salespreso.com/api/sections/28/", moment());
|
|
199
208
|
* timingLog.addEvent("http://client.salespreso.com/api/slides/100/", "2016-10-27T00:42:47.045186Z");
|
|
200
209
|
*/
|
|
201
|
-
addEvent(
|
|
210
|
+
addEvent(_path, timestamp) {
|
|
211
|
+
let path = _path;
|
|
212
|
+
|
|
202
213
|
if (!path) {
|
|
203
214
|
throw new Error("A path is required");
|
|
204
215
|
}
|
|
@@ -280,33 +291,18 @@ export const TimingLogModel = BaseModel.extend(
|
|
|
280
291
|
return Promise.resolve(this.toJSON());
|
|
281
292
|
}
|
|
282
293
|
|
|
283
|
-
if (options && options.patch) {
|
|
284
|
-
return BaseModel.prototype.save.call(this, data, options);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
294
|
this.checkEventsAscending();
|
|
288
295
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
return superagent[method](this.url())
|
|
292
|
-
.set(Auth.headers)
|
|
293
|
-
.type("application/vnd.salespreso+timinglog")
|
|
294
|
-
.send(this.toCompactFormat())
|
|
295
|
-
.then(({ body }) => {
|
|
296
|
-
this.set(_.omit(body, ["events"]));
|
|
297
|
-
return body;
|
|
298
|
-
})
|
|
299
|
-
.catch(superagent.SuperagentPromiseError, (e) => {
|
|
300
|
-
if (e.status === 405 && e.res.body.detail.indexOf("end") > -1) {
|
|
301
|
-
// Don't send timing log events if the tracking is ended.
|
|
302
|
-
throw e;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if ((e.status >= 400 && e.status <= 499) || e.status === 503) {
|
|
306
|
-
e.message += `\nBody: ${JSON.stringify(e.res.body)}`;
|
|
307
|
-
}
|
|
296
|
+
return BaseModel.prototype.save.call(this, data, options).catch((e) => {
|
|
297
|
+
if (e.status === 405 && e.response?.body?.detail?.indexOf("end") > -1) {
|
|
308
298
|
throw e;
|
|
309
|
-
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if ((e.status >= 400 && e.status <= 499) || e.status === 503) {
|
|
302
|
+
e.message += `\nBody: ${JSON.stringify(e.response?.body)}`;
|
|
303
|
+
}
|
|
304
|
+
throw e;
|
|
305
|
+
});
|
|
310
306
|
},
|
|
311
307
|
},
|
|
312
308
|
);
|
package/src/sync.js
CHANGED
|
@@ -3,7 +3,6 @@ import SuperAgentRequest from "superagent-bluebird-promise";
|
|
|
3
3
|
import _ from "lodash";
|
|
4
4
|
import log from "./log.js";
|
|
5
5
|
import { middlewares } from "./middleware.js";
|
|
6
|
-
import superagent from "superagent";
|
|
7
6
|
|
|
8
7
|
const defaults = _.defaults;
|
|
9
8
|
const assign = _.assign;
|
|
@@ -142,13 +141,25 @@ export const ajaxSync = function (method, model, options) {
|
|
|
142
141
|
// Combine generated headers with user's headers.
|
|
143
142
|
if (ajaxConfig.headers) {
|
|
144
143
|
for (const key in ajaxConfig.headers) {
|
|
145
|
-
|
|
144
|
+
const lowerKey = key.toLowerCase();
|
|
145
|
+
// Use superagent's .type() method to explicitly set content-type
|
|
146
|
+
// This ensures superagent respects the content-type and doesn't override it
|
|
147
|
+
if (lowerKey === "content-type") {
|
|
148
|
+
request.type(ajaxConfig.headers[key].split(";")[0]);
|
|
149
|
+
} else {
|
|
150
|
+
request.header[lowerKey] = ajaxConfig.headers[key];
|
|
151
|
+
}
|
|
146
152
|
}
|
|
147
153
|
}
|
|
148
154
|
|
|
149
155
|
if (options.headers) {
|
|
150
156
|
for (const key in options.headers) {
|
|
151
|
-
|
|
157
|
+
const lowerKey = key.toLowerCase();
|
|
158
|
+
if (lowerKey === "content-type") {
|
|
159
|
+
request.type(options.headers[key].split(";")[0]);
|
|
160
|
+
} else {
|
|
161
|
+
request.header[lowerKey] = options.headers[key];
|
|
162
|
+
}
|
|
152
163
|
}
|
|
153
164
|
}
|
|
154
165
|
|
|
@@ -215,10 +226,10 @@ export const ajaxSync = function (method, model, options) {
|
|
|
215
226
|
return data;
|
|
216
227
|
});
|
|
217
228
|
})
|
|
218
|
-
.catch(
|
|
229
|
+
.catch((e) => {
|
|
219
230
|
if (
|
|
220
|
-
e.
|
|
221
|
-
e.res
|
|
231
|
+
typeof e.status !== "undefined" &&
|
|
232
|
+
e.res?.body &&
|
|
222
233
|
((e.status >= 400 && e.status < 500) || e.status === 503)
|
|
223
234
|
) {
|
|
224
235
|
e.message += `\nBody: ${JSON.stringify(e.res.body)}`;
|