@livepreso/api 6.55.2 → 6.56.1
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 +1013 -1191
- package/CHANGELOG.json +29 -0
- package/CHANGELOG.md +19 -1
- package/api.build.log +9 -0
- package/api.test.cache.log +1 -0
- package/api.test.log +19 -0
- package/cjs/api.js +3 -5
- package/cjs/api.js.map +1 -1
- package/cjs/auth.spec.js +11 -11
- package/cjs/auth.spec.js.map +1 -1
- package/cjs/collections/appointment-tags.js +14 -15
- package/cjs/collections/appointment-tags.js.map +1 -1
- package/cjs/collections/base.spec.js +30 -30
- package/cjs/collections/base.spec.js.map +1 -1
- package/cjs/fixtures.js +1 -2
- package/cjs/fixtures.js.map +1 -1
- package/cjs/models/appointment.js +7 -7
- package/cjs/models/appointment.js.map +1 -1
- package/cjs/models/base.js +30 -12
- package/cjs/models/base.js.map +1 -1
- package/cjs/models/cms-val.spec.js +2 -2
- package/cjs/models/cms-val.spec.js.map +1 -1
- package/cjs/models/deck-version.js +14 -34
- package/cjs/models/deck-version.js.map +1 -1
- package/cjs/models/manifest-json.js +41 -5
- package/cjs/models/manifest-json.js.map +1 -1
- package/cjs/models/pack.js +2 -1
- package/cjs/models/pack.js.map +1 -1
- package/cjs/models/snapshot.spec.js +2 -2
- package/cjs/models/snapshot.spec.js.map +1 -1
- package/cjs/models/template.js +10 -10
- package/cjs/models/template.js.map +1 -1
- package/cjs/models/timing-log.js +17 -17
- package/cjs/models/timing-log.js.map +1 -1
- package/cjs/models/timing-log.spec.js +2 -2
- package/cjs/models/timing-log.spec.js.map +1 -1
- package/cjs/models/user.spec.js +4 -4
- package/cjs/models/user.spec.js.map +1 -1
- package/cjs/presentation/presentation-deck.js +19 -9
- package/cjs/presentation/presentation-deck.js.map +1 -1
- package/cjs/presentation/presentation-deck.spec.js +6 -6
- package/cjs/presentation/presentation-deck.spec.js.map +1 -1
- package/cjs/presentation/presentation-section.js +30 -9
- package/cjs/presentation/presentation-section.js.map +1 -1
- package/cjs/presentation/presentation-section.spec.js +24 -16
- package/cjs/presentation/presentation-section.spec.js.map +1 -1
- package/cjs/presentation/presentation-slide.js +18 -7
- package/cjs/presentation/presentation-slide.js.map +1 -1
- package/cjs/presentation/presentation-slide.spec.js +21 -12
- package/cjs/presentation/presentation-slide.spec.js.map +1 -1
- package/cjs/presentation/presentation-subslide.spec.js +10 -10
- package/cjs/presentation/presentation-subslide.spec.js.map +1 -1
- package/cjs/presentation/presentation.js +26 -26
- package/cjs/presentation/presentation.js.map +1 -1
- package/cjs/sync.js +15 -5
- package/cjs/sync.js.map +1 -1
- package/cjs/utils.js +33 -3
- package/cjs/utils.js.map +1 -1
- package/package.json +3 -3
- 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/api.js +3 -5
- package/src/models/base.js +27 -9
- package/src/models/deck-version.js +5 -31
- package/src/models/manifest-json.js +33 -5
- package/src/models/pack.js +1 -0
- package/src/models/timing-log.js +24 -28
- package/src/presentation/presentation-deck.js +9 -9
- package/src/presentation/presentation-section.js +31 -11
- package/src/presentation/presentation-section.spec.js +8 -0
- package/src/presentation/presentation-slide.js +7 -4
- package/src/presentation/presentation-slide.spec.js +9 -0
- package/src/sync.js +15 -5
- package/src/utils.js +31 -2
|
@@ -40,16 +40,16 @@ Presentation.createFromDeckversion = function (deckversionURL, options) {
|
|
|
40
40
|
return deckversion.fetch().then(function () {
|
|
41
41
|
return _bluebird.default.all([deckversion.manifest_json.fetch(), deckversion.deck.fetch()]);
|
|
42
42
|
}).then(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
43
|
-
var templates, _iterator, _step, _loop;
|
|
44
|
-
return _regenerator.default.wrap(function
|
|
43
|
+
var templates, _iterator, _step, _loop, _t;
|
|
44
|
+
return _regenerator.default.wrap(function (_context2) {
|
|
45
45
|
while (1) switch (_context2.prev = _context2.next) {
|
|
46
46
|
case 0:
|
|
47
47
|
templates = (0, _toConsumableArray2.default)(deckversion.template_set.models);
|
|
48
48
|
_iterator = _createForOfIteratorHelper(opts.autoAdjuncts.models);
|
|
49
|
-
_context2.prev =
|
|
49
|
+
_context2.prev = 1;
|
|
50
50
|
_loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
|
|
51
51
|
var auto, dvTemplate;
|
|
52
|
-
return _regenerator.default.wrap(function
|
|
52
|
+
return _regenerator.default.wrap(function (_context) {
|
|
53
53
|
while (1) switch (_context.prev = _context.next) {
|
|
54
54
|
case 0:
|
|
55
55
|
auto = _step.value;
|
|
@@ -57,49 +57,49 @@ Presentation.createFromDeckversion = function (deckversionURL, options) {
|
|
|
57
57
|
return t.url() === auto.template.url();
|
|
58
58
|
});
|
|
59
59
|
if (!dvTemplate) {
|
|
60
|
-
_context.next =
|
|
60
|
+
_context.next = 1;
|
|
61
61
|
break;
|
|
62
62
|
}
|
|
63
63
|
auto.template = dvTemplate;
|
|
64
|
-
_context.next =
|
|
64
|
+
_context.next = 3;
|
|
65
65
|
break;
|
|
66
|
-
case
|
|
67
|
-
_context.next =
|
|
66
|
+
case 1:
|
|
67
|
+
_context.next = 2;
|
|
68
68
|
return auto.template.fetch();
|
|
69
|
-
case
|
|
69
|
+
case 2:
|
|
70
70
|
templates.push(auto.template);
|
|
71
|
-
case
|
|
71
|
+
case 3:
|
|
72
72
|
case "end":
|
|
73
73
|
return _context.stop();
|
|
74
74
|
}
|
|
75
75
|
}, _loop);
|
|
76
76
|
});
|
|
77
77
|
_iterator.s();
|
|
78
|
-
case
|
|
78
|
+
case 2:
|
|
79
79
|
if ((_step = _iterator.n()).done) {
|
|
80
|
-
_context2.next =
|
|
80
|
+
_context2.next = 4;
|
|
81
81
|
break;
|
|
82
82
|
}
|
|
83
|
-
return _context2.delegateYield(_loop(), "t0",
|
|
84
|
-
case
|
|
85
|
-
_context2.next =
|
|
83
|
+
return _context2.delegateYield(_loop(), "t0", 3);
|
|
84
|
+
case 3:
|
|
85
|
+
_context2.next = 2;
|
|
86
86
|
break;
|
|
87
|
-
case
|
|
88
|
-
_context2.next =
|
|
87
|
+
case 4:
|
|
88
|
+
_context2.next = 6;
|
|
89
89
|
break;
|
|
90
|
-
case
|
|
91
|
-
_context2.prev =
|
|
92
|
-
|
|
93
|
-
_iterator.e(
|
|
94
|
-
case
|
|
95
|
-
_context2.prev =
|
|
90
|
+
case 5:
|
|
91
|
+
_context2.prev = 5;
|
|
92
|
+
_t = _context2["catch"](1);
|
|
93
|
+
_iterator.e(_t);
|
|
94
|
+
case 6:
|
|
95
|
+
_context2.prev = 6;
|
|
96
96
|
_iterator.f();
|
|
97
|
-
return _context2.finish(
|
|
98
|
-
case
|
|
97
|
+
return _context2.finish(6);
|
|
98
|
+
case 7:
|
|
99
99
|
case "end":
|
|
100
100
|
return _context2.stop();
|
|
101
101
|
}
|
|
102
|
-
}, _callee, null, [[
|
|
102
|
+
}, _callee, null, [[1, 5, 6, 7]]);
|
|
103
103
|
}))).then(function () {
|
|
104
104
|
return deckversion.deck.tags.fetch();
|
|
105
105
|
}).then(function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation.js","names":["require","_models","_autoAdjuncts","_basePresentationModel","_presentationDeck","_bluebird","_interopRequireDefault","_lodash","_log","_stateRegister","_excluded","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","_createForOfIteratorHelper","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","_n","F","s","n","done","value","f","TypeError","a","u","call","next","return","_arrayLikeToArray","toString","slice","constructor","name","from","test","Presentation","exports","BasePresentationModel","extend","collections","decks","createFromDeckversion","deckversionURL","options","deckversion","DeckVersionModel","opts","_","defaults","includeTemplates","choicelist","autoAdjuncts","AutoAdjunctCollection","fetch","then","Promise","all","manifest_json","deck","_asyncToGenerator2","_regenerator","mark","_callee","templates","_iterator","_step","_loop","wrap","_callee$","_context2","prev","_toConsumableArray2","template_set","models","auto","dvTemplate","_loop$","_context","find","url","template","stop","delegateYield","t1","finish","tags","deckTags","items","reduce","tagObj","tagItem","namespaced_key","presentation","otherOpts","_objectWithoutProperties2","toJSON","add","PresentationDeck","createFromDeckVersion","catch","log","error","createFromManifestJSON","manifestJSON","project","manifestModel","ManifestJSONModel","_url","register"],"sources":["../../src/presentation/presentation.js"],"sourcesContent":["import \"./presentation-decks.js\";\n\nimport { DeckVersionModel, ManifestJSONModel } from \"../models.js\";\n\nimport { AutoAdjunctCollection } from \"../collections/auto-adjuncts.js\";\nimport { BasePresentationModel } from \"./base-presentation-model.js\";\nimport { PresentationDeck } from \"./presentation-deck.js\";\nimport Promise from \"bluebird\";\nimport _ from \"lodash\";\nimport log from \"../log.js\";\nimport { register } from \"../state-register.js\";\n\nexport const Presentation = BasePresentationModel.extend({\n\tcollections: {\n\t\tdecks: \"PresentationDeckCollection\",\n\t},\n});\n\nPresentation.createFromDeckversion = function (deckversionURL, options) {\n\tconst deckversion = new DeckVersionModel(deckversionURL);\n\tconst opts = _.defaults(options, {\n\t\tincludeTemplates: false,\n\t\tchoicelist: null,\n\t\tautoAdjuncts: new AutoAdjunctCollection(),\n\t});\n\n\treturn deckversion\n\t\t.fetch()\n\t\t.then(() => {\n\t\t\treturn Promise.all([\n\t\t\t\tdeckversion.manifest_json.fetch(),\n\t\t\t\tdeckversion.deck.fetch(),\n\t\t\t]);\n\t\t})\n\t\t.then(async () => {\n\t\t\tconst templates = [...deckversion.template_set.models];\n\n\t\t\tfor (const auto of opts.autoAdjuncts.models) {\n\t\t\t\tconst dvTemplate = templates.find(\n\t\t\t\t\t(t) => t.url() === auto.template.url(),\n\t\t\t\t);\n\t\t\t\tif (dvTemplate) {\n\t\t\t\t\tauto.template = dvTemplate;\n\t\t\t\t} else {\n\t\t\t\t\tawait auto.template.fetch();\n\t\t\t\t\ttemplates.push(auto.template);\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\t.then(() => {\n\t\t\treturn deckversion.deck.tags.fetch();\n\t\t})\n\t\t.then(() => {\n\t\t\tconst deckTags = deckversion.deck.tags.items.reduce((tagObj, tagItem) => {\n\t\t\t\ttagObj[tagItem.namespaced_key] = tagItem.tags;\n\t\t\t\treturn tagObj;\n\t\t\t}, {});\n\n\t\t\tconst presentation = new Presentation();\n\n\t\t\tconst { includeTemplates, ...otherOpts } = opts;\n\n\t\t\tif (includeTemplates) {\n\t\t\t\totherOpts.templates = deckversion.template_set.toJSON();\n\t\t\t}\n\n\t\t\tpresentation.decks.add([\n\t\t\t\tPresentationDeck.createFromDeckVersion(deckversion, {\n\t\t\t\t\t...otherOpts,\n\t\t\t\t\tdeckTags,\n\t\t\t\t}),\n\t\t\t]);\n\n\t\t\treturn presentation;\n\t\t})\n\t\t.catch((e) => {\n\t\t\tlog.error(e);\n\t\t\tthrow e;\n\t\t});\n};\n\nPresentation.createFromManifestJSON = function (manifestJSON, project, url) {\n\tconst manifestModel = new ManifestJSONModel(manifestJSON.toJSON());\n\n\t// Let's use the model to transport the base url for the deck assets\n\tmanifestModel._url = url;\n\n\tconst deck = PresentationDeck.createFromManifestJSON(manifestModel, project);\n\tconst presentation = new Presentation();\n\tpresentation.decks.add(deck);\n\treturn presentation;\n};\n\nregister(\"Presentation\", Presentation);\n"],"mappings":";;;;;;;;;;;;AAAAA,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAC,sBAAA,CAAAN,OAAA;AACA,IAAAO,OAAA,GAAAD,sBAAA,CAAAN,OAAA;AACA,IAAAQ,IAAA,GAAAF,sBAAA,CAAAN,OAAA;AACA,IAAAS,cAAA,GAAAT,OAAA;AAAgD,IAAAU,SAAA;AAAA,SAAAC,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,UAAAC,CAAA,WAAAW,SAAA,CAAAZ,CAAA,IAAAY,SAAA,CAAAZ,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAI,MAAA,CAAAD,CAAA,OAAAa,OAAA,WAAAd,CAAA,QAAAe,gBAAA,CAAAC,OAAA,EAAAjB,CAAA,EAAAC,CAA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ACtC,IAAI,CAAC;EAC5B,OAAOkC,YAAY;AACpB,CAAC;AAED,IAAAgB,uBAAQ,EAAC,cAAc,EAAEzE,YAAY,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"presentation.js","names":["require","_models","_autoAdjuncts","_basePresentationModel","_presentationDeck","_bluebird","_interopRequireDefault","_lodash","_log","_stateRegister","_excluded","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","_createForOfIteratorHelper","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","_n","F","s","n","done","value","f","TypeError","a","u","call","next","return","_arrayLikeToArray","toString","slice","constructor","name","from","test","Presentation","exports","BasePresentationModel","extend","collections","decks","createFromDeckversion","deckversionURL","options","deckversion","DeckVersionModel","opts","_","defaults","includeTemplates","choicelist","autoAdjuncts","AutoAdjunctCollection","fetch","then","Promise","all","manifest_json","deck","_asyncToGenerator2","_regenerator","mark","_callee","templates","_iterator","_step","_loop","_t","wrap","_context2","prev","_toConsumableArray2","template_set","models","auto","dvTemplate","_context","find","url","template","stop","delegateYield","finish","tags","deckTags","items","reduce","tagObj","tagItem","namespaced_key","presentation","otherOpts","_objectWithoutProperties2","toJSON","add","PresentationDeck","createFromDeckVersion","catch","log","error","createFromManifestJSON","manifestJSON","project","manifestModel","ManifestJSONModel","_url","register"],"sources":["../../src/presentation/presentation.js"],"sourcesContent":["import \"./presentation-decks.js\";\n\nimport { DeckVersionModel, ManifestJSONModel } from \"../models.js\";\n\nimport { AutoAdjunctCollection } from \"../collections/auto-adjuncts.js\";\nimport { BasePresentationModel } from \"./base-presentation-model.js\";\nimport { PresentationDeck } from \"./presentation-deck.js\";\nimport Promise from \"bluebird\";\nimport _ from \"lodash\";\nimport log from \"../log.js\";\nimport { register } from \"../state-register.js\";\n\nexport const Presentation = BasePresentationModel.extend({\n\tcollections: {\n\t\tdecks: \"PresentationDeckCollection\",\n\t},\n});\n\nPresentation.createFromDeckversion = function (deckversionURL, options) {\n\tconst deckversion = new DeckVersionModel(deckversionURL);\n\tconst opts = _.defaults(options, {\n\t\tincludeTemplates: false,\n\t\tchoicelist: null,\n\t\tautoAdjuncts: new AutoAdjunctCollection(),\n\t});\n\n\treturn deckversion\n\t\t.fetch()\n\t\t.then(() => {\n\t\t\treturn Promise.all([\n\t\t\t\tdeckversion.manifest_json.fetch(),\n\t\t\t\tdeckversion.deck.fetch(),\n\t\t\t]);\n\t\t})\n\t\t.then(async () => {\n\t\t\tconst templates = [...deckversion.template_set.models];\n\n\t\t\tfor (const auto of opts.autoAdjuncts.models) {\n\t\t\t\tconst dvTemplate = templates.find(\n\t\t\t\t\t(t) => t.url() === auto.template.url(),\n\t\t\t\t);\n\t\t\t\tif (dvTemplate) {\n\t\t\t\t\tauto.template = dvTemplate;\n\t\t\t\t} else {\n\t\t\t\t\tawait auto.template.fetch();\n\t\t\t\t\ttemplates.push(auto.template);\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\t.then(() => {\n\t\t\treturn deckversion.deck.tags.fetch();\n\t\t})\n\t\t.then(() => {\n\t\t\tconst deckTags = deckversion.deck.tags.items.reduce((tagObj, tagItem) => {\n\t\t\t\ttagObj[tagItem.namespaced_key] = tagItem.tags;\n\t\t\t\treturn tagObj;\n\t\t\t}, {});\n\n\t\t\tconst presentation = new Presentation();\n\n\t\t\tconst { includeTemplates, ...otherOpts } = opts;\n\n\t\t\tif (includeTemplates) {\n\t\t\t\totherOpts.templates = deckversion.template_set.toJSON();\n\t\t\t}\n\n\t\t\tpresentation.decks.add([\n\t\t\t\tPresentationDeck.createFromDeckVersion(deckversion, {\n\t\t\t\t\t...otherOpts,\n\t\t\t\t\tdeckTags,\n\t\t\t\t}),\n\t\t\t]);\n\n\t\t\treturn presentation;\n\t\t})\n\t\t.catch((e) => {\n\t\t\tlog.error(e);\n\t\t\tthrow e;\n\t\t});\n};\n\nPresentation.createFromManifestJSON = function (manifestJSON, project, url) {\n\tconst manifestModel = new ManifestJSONModel(manifestJSON.toJSON());\n\n\t// Let's use the model to transport the base url for the deck assets\n\tmanifestModel._url = url;\n\n\tconst deck = PresentationDeck.createFromManifestJSON(manifestModel, project);\n\tconst presentation = new Presentation();\n\tpresentation.decks.add(deck);\n\treturn presentation;\n};\n\nregister(\"Presentation\", Presentation);\n"],"mappings":";;;;;;;;;;;;AAAAA,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAC,sBAAA,CAAAN,OAAA;AACA,IAAAO,OAAA,GAAAD,sBAAA,CAAAN,OAAA;AACA,IAAAQ,IAAA,GAAAF,sBAAA,CAAAN,OAAA;AACA,IAAAS,cAAA,GAAAT,OAAA;AAAgD,IAAAU,SAAA;AAAA,SAAAC,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,UAAAC,CAAA,WAAAW,SAAA,CAAAZ,CAAA,IAAAY,SAAA,CAAAZ,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAI,MAAA,CAAAD,CAAA,OAAAa,OAAA,WA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,YAAY,CAAClD,KAAK,CAACsD,GAAG,CAACpC,IAAI,CAAC;EAC5B,OAAOgC,YAAY;AACpB,CAAC;AAED,IAAAgB,uBAAQ,EAAC,cAAc,EAAEvE,YAAY,CAAC","ignoreList":[]}
|
package/cjs/sync.js
CHANGED
|
@@ -12,7 +12,6 @@ var _lodash = _interopRequireDefault(require("lodash"));
|
|
|
12
12
|
var _log = _interopRequireDefault(require("./log.js"));
|
|
13
13
|
var _middleware = require("./middleware.js");
|
|
14
14
|
var _superagent = _interopRequireDefault(require("superagent"));
|
|
15
|
-
var _url = _interopRequireDefault(require("url"));
|
|
16
15
|
var defaults = _lodash.default.defaults;
|
|
17
16
|
var assign = _lodash.default.assign;
|
|
18
17
|
|
|
@@ -38,11 +37,10 @@ var buildURL = exports.buildURL = function buildURL(_ref2) {
|
|
|
38
37
|
var method = _ref2.method,
|
|
39
38
|
model = _ref2.model;
|
|
40
39
|
var url = model.url();
|
|
41
|
-
var urlParse = _url.default.parse(url);
|
|
42
40
|
|
|
43
41
|
// If not a GET request, strip the query params from the url
|
|
44
42
|
if (method !== "read") {
|
|
45
|
-
return url.
|
|
43
|
+
return url.split("?")[0];
|
|
46
44
|
}
|
|
47
45
|
return url;
|
|
48
46
|
};
|
|
@@ -133,12 +131,24 @@ var ajaxSync = exports.ajaxSync = function ajaxSync(method, model, options) {
|
|
|
133
131
|
// Combine generated headers with user's headers.
|
|
134
132
|
if (ajaxConfig.headers) {
|
|
135
133
|
for (var key in ajaxConfig.headers) {
|
|
136
|
-
|
|
134
|
+
var lowerKey = key.toLowerCase();
|
|
135
|
+
// Use superagent's .type() method to explicitly set content-type
|
|
136
|
+
// This ensures superagent respects the content-type and doesn't override it
|
|
137
|
+
if (lowerKey === "content-type") {
|
|
138
|
+
request.type(ajaxConfig.headers[key].split(";")[0]);
|
|
139
|
+
} else {
|
|
140
|
+
request.header[lowerKey] = ajaxConfig.headers[key];
|
|
141
|
+
}
|
|
137
142
|
}
|
|
138
143
|
}
|
|
139
144
|
if (options.headers) {
|
|
140
145
|
for (var _key2 in options.headers) {
|
|
141
|
-
|
|
146
|
+
var _lowerKey = _key2.toLowerCase();
|
|
147
|
+
if (_lowerKey === "content-type") {
|
|
148
|
+
request.type(options.headers[_key2].split(";")[0]);
|
|
149
|
+
} else {
|
|
150
|
+
request.header[_lowerKey] = options.headers[_key2];
|
|
151
|
+
}
|
|
142
152
|
}
|
|
143
153
|
}
|
|
144
154
|
|
package/cjs/sync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","names":["_bluebird","_interopRequireDefault","require","_superagentBluebirdPromise","_lodash","_log","_middleware","_superagent","_url","defaults","_","assign","urlError","Error","methodMap","exports","create","update","patch","delete","read","defaultFetchURL","_ref","model","log","warn","url","buildURL","_ref2","method","urlParse","url2","parse","replace","search","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","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\";\nimport url2 from \"url\";\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\tconst urlParse = url2.parse(url);\n\n\t// If not a GET request, strip the query params from the url\n\tif (method !== \"read\") {\n\t\treturn url.replace(urlParse.search, \"\");\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;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,IAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,IAAA,GAAAP,sBAAA,CAAAC,OAAA;AAEA,IAAMO,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;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CAAe0C,IAAI,CAACgB,SAAS,CAACR,CAAC,CAACK,GAAG,CAACC,IAAI,CAAC,CAAE;IACrD;IACA,MAAMN,CAAC;EACR,CAAC,CAAC,CACDJ,KAAK,CAAC,UAACd,QAAQ,EAAK;IACpB,OAAO1C,iBAAO,CAACsD,IAAI,CAAC3D,uBAAW,EAAE,UAACE,UAAU,EAAK;MAChD,OAAOA,UAAU,CAAC4D,KAAK,CAACf,QAAQ,CAAC;IAClC,CAAC,CAAC,CAACxC,IAAI,CAAC,YAAM;MACb,IAAIc,OAAO,CAACyC,KAAK,EAAE;QAClBzC,OAAO,CAACyC,KAAK,CAACf,QAAQ,EAAE,OAAO,EAAEA,QAAQ,CAACgB,OAAO,CAAC;MACnD;;MAEA;MACA,IACChB,QAAQ,IACRA,QAAQ,CAAC2B,aAAa,IACtB3B,QAAQ,CAAC2B,aAAa,CAACC,IAAI,KAAK,cAAc,EAC7C;QACD,MAAM,IAAIvG,KAAK,WAAA2C,MAAA,CACJO,IAAI,uBAAAP,MAAA,CAAoB9B,GAAG,QAAA8B,MAAA,CAAKgC,QAAQ,CAACgB,OAAO,CAC3D,CAAC;MACF;MAEA,MAAMhB,QAAQ;IACf,CAAC,CAAC;EACH,CAAC,CAAC;AAEL,CAAC","ignoreList":[]}
|
|
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","lowerKey","toLowerCase","header","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\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(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 === \"EC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AAO1C,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,CAAC6B,aAAa,IACtB7B,QAAQ,CAAC6B,aAAa,CAACC,IAAI,KAAK,cAAc,EAC7C;QACD,MAAM,IAAIrG,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/cjs/utils.js
CHANGED
|
@@ -12,19 +12,49 @@ exports.isImpostor = isImpostor;
|
|
|
12
12
|
exports.isImpostorDeck = isImpostorDeck;
|
|
13
13
|
exports.removeMultiByteChars = removeMultiByteChars;
|
|
14
14
|
exports.replaceHostname = replaceHostname;
|
|
15
|
+
exports.resolveURL = resolveURL;
|
|
15
16
|
exports.sanitizeBase64 = sanitizeBase64;
|
|
16
17
|
exports.setSequentialSequences = setSequentialSequences;
|
|
17
18
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
19
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
19
20
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
20
21
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
21
|
-
var _url = _interopRequireDefault(require("url"));
|
|
22
22
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
23
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
23
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
24
|
+
/* eslint-disable no-control-regex */
|
|
25
|
+
|
|
24
26
|
var DATE_FORMAT = exports.DATE_FORMAT = "YYYY-MM-DD HH:mm:ss.SSSSSS[Z]";
|
|
25
27
|
var DATE_FORMAT_T = exports.DATE_FORMAT_T = "YYYY-MM-DDTHH:mm:ss.SSSSSS[Z]";
|
|
26
28
|
function getShortURL(url) {
|
|
27
|
-
|
|
29
|
+
if (!url) return url;
|
|
30
|
+
if (typeof url !== "string") return url;
|
|
31
|
+
try {
|
|
32
|
+
return new URL(url, "http://a.b").pathname;
|
|
33
|
+
} catch (e) {
|
|
34
|
+
return url;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Resolves a target URL relative to a base URL in a manner similar to a Web browser resolving an anchor tag.
|
|
40
|
+
* Matches url.resolve() behavior but handles relative bases.
|
|
41
|
+
*/
|
|
42
|
+
function resolveURL(base, relative) {
|
|
43
|
+
if (!base) return relative;
|
|
44
|
+
if (!relative) return base;
|
|
45
|
+
var dummyBase = "http://a.b";
|
|
46
|
+
try {
|
|
47
|
+
// Try resolving normally (if base is absolute)
|
|
48
|
+
return new URL(relative, base).href;
|
|
49
|
+
} catch (e) {
|
|
50
|
+
try {
|
|
51
|
+
// If base is relative, resolve it against a dummy base, then strip it
|
|
52
|
+
var resolved = new URL(relative, new URL(base, dummyBase));
|
|
53
|
+
return resolved.href.replace(dummyBase, "");
|
|
54
|
+
} catch (e2) {
|
|
55
|
+
return relative;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
28
58
|
}
|
|
29
59
|
|
|
30
60
|
/**
|
package/cjs/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["_lodash","_interopRequireDefault","require","_url","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","DATE_FORMAT","exports","DATE_FORMAT_T","getShortURL","url","url2","parse","path","removeMultiByteChars","_txt","txt","replace","HOSTNAME_RE","getHostname","data","Error","concat","match","replaceHostname","before","after","hostnameBefore","hostnameAfter","indexOf","Array","isArray","map","item","_","isObject","reduce","newObj","key","getMaxID","deckVersionModel","ids","section_set","section","slides","slide_set","slide","subslides","subslide_set","subslide","id","_toConsumableArray2","flatten","max","setSequentialSequences","deck","sections","index","sequence","isImpostor","model","tags","isImpostorDeck","first","Boolean","find","sanitizeBase64","obj","conditionFn","undefined","v","_typeof2","acc","re","test","_conditionFn","process","env","NODE_ENV","window","Cypress"],"sources":["../src/utils.js"],"sourcesContent":["import _ from \"lodash\";\n/* eslint-disable no-control-regex */\nimport url2 from \"url\";\n\nexport const DATE_FORMAT = \"YYYY-MM-DD HH:mm:ss.SSSSSS[Z]\";\nexport const DATE_FORMAT_T = \"YYYY-MM-DDTHH:mm:ss.SSSSSS[Z]\";\n\nexport function getShortURL(url) {\n\treturn url2.parse(url).path;\n}\n\n/**\n * Sometimes a string(especially from another platform) has characters encoded using another method.\n * In these circumstances those characters, when encoded with utf-8, look like errors.\n * see http://i18nqa.com/debug/utf8-debug.html for examples\n */\nexport function removeMultiByteChars(_txt) {\n\t// replace possible whitespace characters (non-breaking space, thin space etc.) with a normal space\n\tconst txt = _txt.replace(/(\\xA0|\\x20|\\x07|â)/gmu, \" \");\n\n\t// remove every other cursed character entirely.\n\treturn txt.replace(\n\t\t/[\\xC0-\\xDF][\\x80-\\xBF]|[\\xE0-\\xEF][\\x80-\\xBF]{2}|[\\xF0-\\xF7][\\x80-\\xBF]{3}|[\\x80-\\xBF][\\xC0-\\xFF]/gmu,\n\t\t\"\",\n\t);\n}\n\nconst HOSTNAME_RE = /^(?:https?:\\/\\/)?([\\w-\\._]*)/;\n\nexport function getHostname(data) {\n\tif (typeof data !== \"string\") {\n\t\tthrow new Error(\n\t\t\t`Arg must contain a hostname, ie: \"test.livepreso.com\". Found \"${data}\"`,\n\t\t);\n\t}\n\n\treturn data.match(HOSTNAME_RE)[1];\n}\n\n/**\n * Replaces the hostname in some data (regardless of it being a string, array or object),\n * it will recursively update it all.\n *\n * Eg:\n *\n * replaceHostname(\"https://test.com/api/cool/1/\", \"test.com\", \"real.com\")\n * > \"https://real.com/api/cool/1/\"\n *\n */\nexport function replaceHostname(data, before, after) {\n\t// Don't do anything if they're the same!\n\tif (before === after) {\n\t\treturn data;\n\t}\n\n\tconst hostnameBefore = getHostname(before, \"Before\");\n\tconst hostnameAfter = getHostname(after, \"After\");\n\n\tif (typeof data === \"string\" && data.indexOf(\"http\") === 0) {\n\t\treturn data.replace(hostnameBefore, hostnameAfter);\n\t} else if (Array.isArray(data)) {\n\t\treturn data.map((item) => replaceHostname(item, before, after));\n\t} else if (_.isObject(data)) {\n\t\treturn Object.keys(data).reduce((newObj, key) => {\n\t\t\tnewObj[key] = replaceHostname(data[key], before, after);\n\t\t\treturn newObj;\n\t\t}, {});\n\t}\n\treturn data;\n}\n\n// Takes the deckversion model and retrieves the highest id between all of\n// the sections, slides and subslides\nexport function getMaxID(deckVersionModel) {\n\tconst ids = deckVersionModel.section_set.map((section) => {\n\t\tlet slides = [];\n\t\tif (section.slide_set) {\n\t\t\tslides = section.slide_set.map((slide) => {\n\t\t\t\tlet subslides = [];\n\n\t\t\t\tif (slide.subslide_set) {\n\t\t\t\t\tsubslides = slide.subslide_set.map((subslide) => subslide.id);\n\t\t\t\t}\n\n\t\t\t\treturn [slide.id, ...subslides];\n\t\t\t});\n\t\t}\n\n\t\treturn [section.id, ..._.flatten(slides)];\n\t});\n\n\treturn _.max(_.flatten(ids));\n}\n\n// The sections, slides and subslides are currently ordered by sequence\n// but the sequence is not necessarily 0-based and sequential (e.g. in the\n// case of impostor decks). We fix that here.\nexport function setSequentialSequences(deck) {\n\tdeck.sections.forEach((section, index) => {\n\t\tsection.sequence = index;\n\t\tsection.index = index;\n\n\t\tsection.slides.forEach((slide, index) => {\n\t\t\tslide.sequence = index;\n\t\t\tslide.index = index;\n\n\t\t\tslide.subslides.forEach((subslide, index) => {\n\t\t\t\tsubslide.sequence = index;\n\t\t\t\tsubslide.index = index;\n\t\t\t});\n\t\t});\n\t});\n}\n\n// A simple function to check the tags of a model - if it has the \"section-header\"\n// tag then it's an impostor slide\nexport function isImpostor(model) {\n\tconst tags = model.tags || [];\n\n\treturn tags.indexOf(\"section-header\") !== -1;\n}\n\n// An impostor deck will have impostor slides - checking for these is the\n// most reliable method of determining whether a deck is an impostor deck,\n// and is also the same method that the server uses.\nexport function isImpostorDeck(deckVersionModel) {\n\tconst section = deckVersionModel.section_set.first();\n\n\treturn Boolean(\n\t\tsection && section.slide_set.find((slide) => isImpostor(slide)),\n\t);\n}\n\n/**\n * Strips base64 strings recursively.\n *\n * Optionally accepts a condition function, which you can use you add any extra\n * checks to test whether you want to clear the string.\n */\nexport function sanitizeBase64(obj, conditionFn = () => true) {\n\tif (Array.isArray(obj)) {\n\t\treturn obj.map((v) => sanitizeBase64(v, conditionFn));\n\t} else if (\n\t\ttypeof obj === \"object\" &&\n\t\tobj !== null &&\n\t\ttypeof obj !== \"undefined\"\n\t) {\n\t\treturn Object.keys(obj).reduce((acc, key) => {\n\t\t\treturn { ...acc, [key]: sanitizeBase64(obj[key], conditionFn) };\n\t\t}, {});\n\t} else if (typeof obj === \"string\") {\n\t\t// Catch anything that looks like base64, or base64%2C (which is the encoded version)\n\t\t// and strip it. This is a last resort, we'd prefer not to be in this position!\n\t\tconst re = /base64(,|(%2C))/;\n\n\t\tif (re.test(obj)) {\n\t\t\t// If you're a developer, let's throw an error.\n\t\t\tif (process.env.NODE_ENV === \"development\" && !window.Cypress) {\n\t\t\t\tthrow new Error(\"Tried to save a base64 string. Figure out why!\");\n\t\t\t}\n\n\t\t\tif (conditionFn?.(obj) ?? true) {\n\t\t\t\treturn \"\";\n\t\t\t}\n\t\t}\n\t}\n\treturn obj;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,IAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAuB,SAAAE,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,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WAAW,CAAC;IAC9D,CAAC,EAAE,CAAC,CAAC,CAAC;EACP,CAAC,MAAM,IAAI,OAAOD,GAAG,KAAK,QAAQ,EAAE;IACnC;IACA;IACA,IAAMM,EAAE,GAAG,iBAAiB;IAE5B,IAAIA,EAAE,CAACC,IAAI,CAACP,GAAG,CAAC,EAAE;MAAA,IAAAQ,YAAA;MACjB;MACA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,aAAa,IAAI,CAACC,MAAM,CAACC,OAAO,EAAE;QAC9D,MAAM,IAAI3D,KAAK,CAAC,gDAAgD,CAAC;MAClE;MAEA,KAAAsD,YAAA,GAAIP,WAAW,aAAXA,WAAW,uBAAXA,WAAW,CAAGD,GAAG,CAAC,cAAAQ,YAAA,cAAAA,YAAA,GAAI,IAAI,EAAE;QAC/B,OAAO,EAAE;MACV;IACD;EACD;EACA,OAAOR,GAAG;AACX","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_lodash","_interopRequireDefault","require","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","DATE_FORMAT","exports","DATE_FORMAT_T","getShortURL","url","URL","pathname","resolveURL","base","relative","dummyBase","href","resolved","replace","e2","removeMultiByteChars","_txt","txt","HOSTNAME_RE","getHostname","data","Error","concat","match","replaceHostname","before","after","hostnameBefore","hostnameAfter","indexOf","Array","isArray","map","item","_","isObject","reduce","newObj","key","getMaxID","deckVersionModel","ids","section_set","section","slides","slide_set","slide","subslides","subslide_set","subslide","id","_toConsumableArray2","flatten","max","setSequentialSequences","deck","sections","index","sequence","isImpostor","model","tags","isImpostorDeck","first","Boolean","find","sanitizeBase64","obj","conditionFn","undefined","v","_typeof2","acc","re","test","_conditionFn","process","env","NODE_ENV","window","Cypress"],"sources":["../src/utils.js"],"sourcesContent":["import _ from \"lodash\";\n/* eslint-disable no-control-regex */\n\nexport const DATE_FORMAT = \"YYYY-MM-DD HH:mm:ss.SSSSSS[Z]\";\nexport const DATE_FORMAT_T = \"YYYY-MM-DDTHH:mm:ss.SSSSSS[Z]\";\n\nexport function getShortURL(url) {\n\tif (!url) return url;\n\tif (typeof url !== \"string\") return url;\n\n\ttry {\n\t\treturn new URL(url, \"http://a.b\").pathname;\n\t} catch (e) {\n\t\treturn url;\n\t}\n}\n\n/**\n * Resolves a target URL relative to a base URL in a manner similar to a Web browser resolving an anchor tag.\n * Matches url.resolve() behavior but handles relative bases.\n */\nexport function resolveURL(base, relative) {\n\tif (!base) return relative;\n\tif (!relative) return base;\n\n\tconst dummyBase = \"http://a.b\";\n\ttry {\n\t\t// Try resolving normally (if base is absolute)\n\t\treturn new URL(relative, base).href;\n\t} catch (e) {\n\t\ttry {\n\t\t\t// If base is relative, resolve it against a dummy base, then strip it\n\t\t\tconst resolved = new URL(relative, new URL(base, dummyBase));\n\t\t\treturn resolved.href.replace(dummyBase, \"\");\n\t\t} catch (e2) {\n\t\t\treturn relative;\n\t\t}\n\t}\n}\n\n/**\n * Sometimes a string(especially from another platform) has characters encoded using another method.\n * In these circumstances those characters, when encoded with utf-8, look like errors.\n * see http://i18nqa.com/debug/utf8-debug.html for examples\n */\nexport function removeMultiByteChars(_txt) {\n\t// replace possible whitespace characters (non-breaking space, thin space etc.) with a normal space\n\tconst txt = _txt.replace(/(\\xA0|\\x20|\\x07|â)/gmu, \" \");\n\n\t// remove every other cursed character entirely.\n\treturn txt.replace(\n\t\t/[\\xC0-\\xDF][\\x80-\\xBF]|[\\xE0-\\xEF][\\x80-\\xBF]{2}|[\\xF0-\\xF7][\\x80-\\xBF]{3}|[\\x80-\\xBF][\\xC0-\\xFF]/gmu,\n\t\t\"\",\n\t);\n}\n\nconst HOSTNAME_RE = /^(?:https?:\\/\\/)?([\\w-\\._]*)/;\n\nexport function getHostname(data) {\n\tif (typeof data !== \"string\") {\n\t\tthrow new Error(\n\t\t\t`Arg must contain a hostname, ie: \"test.livepreso.com\". Found \"${data}\"`,\n\t\t);\n\t}\n\n\treturn data.match(HOSTNAME_RE)[1];\n}\n\n/**\n * Replaces the hostname in some data (regardless of it being a string, array or object),\n * it will recursively update it all.\n *\n * Eg:\n *\n * replaceHostname(\"https://test.com/api/cool/1/\", \"test.com\", \"real.com\")\n * > \"https://real.com/api/cool/1/\"\n *\n */\nexport function replaceHostname(data, before, after) {\n\t// Don't do anything if they're the same!\n\tif (before === after) {\n\t\treturn data;\n\t}\n\n\tconst hostnameBefore = getHostname(before, \"Before\");\n\tconst hostnameAfter = getHostname(after, \"After\");\n\n\tif (typeof data === \"string\" && data.indexOf(\"http\") === 0) {\n\t\treturn data.replace(hostnameBefore, hostnameAfter);\n\t} else if (Array.isArray(data)) {\n\t\treturn data.map((item) => replaceHostname(item, before, after));\n\t} else if (_.isObject(data)) {\n\t\treturn Object.keys(data).reduce((newObj, key) => {\n\t\t\tnewObj[key] = replaceHostname(data[key], before, after);\n\t\t\treturn newObj;\n\t\t}, {});\n\t}\n\treturn data;\n}\n\n// Takes the deckversion model and retrieves the highest id between all of\n// the sections, slides and subslides\nexport function getMaxID(deckVersionModel) {\n\tconst ids = deckVersionModel.section_set.map((section) => {\n\t\tlet slides = [];\n\t\tif (section.slide_set) {\n\t\t\tslides = section.slide_set.map((slide) => {\n\t\t\t\tlet subslides = [];\n\n\t\t\t\tif (slide.subslide_set) {\n\t\t\t\t\tsubslides = slide.subslide_set.map((subslide) => subslide.id);\n\t\t\t\t}\n\n\t\t\t\treturn [slide.id, ...subslides];\n\t\t\t});\n\t\t}\n\n\t\treturn [section.id, ..._.flatten(slides)];\n\t});\n\n\treturn _.max(_.flatten(ids));\n}\n\n// The sections, slides and subslides are currently ordered by sequence\n// but the sequence is not necessarily 0-based and sequential (e.g. in the\n// case of impostor decks). We fix that here.\nexport function setSequentialSequences(deck) {\n\tdeck.sections.forEach((section, index) => {\n\t\tsection.sequence = index;\n\t\tsection.index = index;\n\n\t\tsection.slides.forEach((slide, index) => {\n\t\t\tslide.sequence = index;\n\t\t\tslide.index = index;\n\n\t\t\tslide.subslides.forEach((subslide, index) => {\n\t\t\t\tsubslide.sequence = index;\n\t\t\t\tsubslide.index = index;\n\t\t\t});\n\t\t});\n\t});\n}\n\n// A simple function to check the tags of a model - if it has the \"section-header\"\n// tag then it's an impostor slide\nexport function isImpostor(model) {\n\tconst tags = model.tags || [];\n\n\treturn tags.indexOf(\"section-header\") !== -1;\n}\n\n// An impostor deck will have impostor slides - checking for these is the\n// most reliable method of determining whether a deck is an impostor deck,\n// and is also the same method that the server uses.\nexport function isImpostorDeck(deckVersionModel) {\n\tconst section = deckVersionModel.section_set.first();\n\n\treturn Boolean(\n\t\tsection && section.slide_set.find((slide) => isImpostor(slide)),\n\t);\n}\n\n/**\n * Strips base64 strings recursively.\n *\n * Optionally accepts a condition function, which you can use you add any extra\n * checks to test whether you want to clear the string.\n */\nexport function sanitizeBase64(obj, conditionFn = () => true) {\n\tif (Array.isArray(obj)) {\n\t\treturn obj.map((v) => sanitizeBase64(v, conditionFn));\n\t} else if (\n\t\ttypeof obj === \"object\" &&\n\t\tobj !== null &&\n\t\ttypeof obj !== \"undefined\"\n\t) {\n\t\treturn Object.keys(obj).reduce((acc, key) => {\n\t\t\treturn { ...acc, [key]: sanitizeBase64(obj[key], conditionFn) };\n\t\t}, {});\n\t} else if (typeof obj === \"string\") {\n\t\t// Catch anything that looks like base64, or base64%2C (which is the encoded version)\n\t\t// and strip it. This is a last resort, we'd prefer not to be in this position!\n\t\tconst re = /base64(,|(%2C))/;\n\n\t\tif (re.test(obj)) {\n\t\t\t// If you're a developer, let's throw an error.\n\t\t\tif (process.env.NODE_ENV === \"development\" && !window.Cypress) {\n\t\t\t\tthrow new Error(\"Tried to save a base64 string. Figure out why!\");\n\t\t\t}\n\n\t\t\tif (conditionFn?.(obj) ?? true) {\n\t\t\t\treturn \"\";\n\t\t\t}\n\t\t}\n\t}\n\treturn obj;\n}\n"],"m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A,CAAAC,OAAA,MAAG0C,GAAG,EAAG4B,cAAc,CAACC,GAAG,CAAC7B,GAAG,CAAC,EAAE8B,WAAW,CAAC;IAC9D,CAAC,EAAE,CAAC,CAAC,CAAC;EACP,CAAC,MAAM,IAAI,OAAOD,GAAG,KAAK,QAAQ,EAAE;IACnC;IACA;IACA,IAAMM,EAAE,GAAG,iBAAiB;IAE5B,IAAIA,EAAE,CAACC,IAAI,CAACP,GAAG,CAAC,EAAE;MAAA,IAAAQ,YAAA;MACjB;MACA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,aAAa,IAAI,CAACC,MAAM,CAACC,OAAO,EAAE;QAC9D,MAAM,IAAI3D,KAAK,CAAC,gDAAgD,CAAC;MAClE;MAEA,KAAAsD,YAAA,GAAIP,WAAW,aAAXA,WAAW,uBAAXA,WAAW,CAAGD,GAAG,CAAC,cAAAQ,YAAA,cAAAA,YAAA,GAAI,IAAI,EAAE;QAC/B,OAAO,EAAE;MACV;IACD;EACD;EACA,OAAOR,GAAG;AACX","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.56.1",
|
|
5
5
|
"description": "Everything to do with talking to the SalePreso API",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"module": "esm/index.js",
|
|
@@ -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
|
+
"sp-test": "0.2.0",
|
|
60
|
+
"@livepreso/eslint-config": "1.0.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
|
package/src/api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Promise from "bluebird";
|
|
2
|
-
import
|
|
2
|
+
import { resolveURL } from "./utils.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @namespace api
|
|
@@ -72,10 +72,8 @@ export const Api = {
|
|
|
72
72
|
* @returns {string}
|
|
73
73
|
*/
|
|
74
74
|
getRootURL() {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
urlObj.search = "";
|
|
78
|
-
return url2.format(urlObj);
|
|
75
|
+
const url = resolveURL(Api._apiURL, "/");
|
|
76
|
+
return url;
|
|
79
77
|
},
|
|
80
78
|
|
|
81
79
|
/**
|
package/src/models/base.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getShortURL, removeMultiByteChars } from "../utils.js";
|
|
2
2
|
|
|
3
3
|
import { Api } from "../api.js";
|
|
4
4
|
import Collection from "ampersand-rest-collection";
|
|
@@ -8,11 +8,9 @@ import SuperAgentRequest from "superagent-bluebird-promise";
|
|
|
8
8
|
import _ from "lodash";
|
|
9
9
|
import dedent from "dedent-js";
|
|
10
10
|
import log from "../log.js";
|
|
11
|
-
import moment from "moment";
|
|
12
11
|
import qs from "qs";
|
|
13
12
|
import { registeredStates } from "../state-register.js";
|
|
14
13
|
import { sync } from "../sync.js";
|
|
15
|
-
import url2 from "url";
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
16
|
* @constructor
|
|
@@ -246,8 +244,8 @@ export const BaseModel = Model.extend(
|
|
|
246
244
|
return null;
|
|
247
245
|
}
|
|
248
246
|
|
|
249
|
-
const urlPath =
|
|
250
|
-
const resourceURLPath =
|
|
247
|
+
const urlPath = getShortURL(url);
|
|
248
|
+
const resourceURLPath = getShortURL(resourceURL);
|
|
251
249
|
|
|
252
250
|
// Remove the '/api' if present
|
|
253
251
|
const resourceEnd = resourceURLPath.split("/api").join("");
|
|
@@ -276,20 +274,40 @@ export const BaseModel = Model.extend(
|
|
|
276
274
|
dataTypes: {
|
|
277
275
|
date: {
|
|
278
276
|
set: (newVal) => {
|
|
277
|
+
let val = null;
|
|
278
|
+
if (newVal) {
|
|
279
|
+
try {
|
|
280
|
+
const date = new Date(newVal);
|
|
281
|
+
if (!isNaN(date.getTime())) {
|
|
282
|
+
val = date.toISOString().replace("Z", "000Z");
|
|
283
|
+
}
|
|
284
|
+
} catch (_e) {
|
|
285
|
+
// fallback to null if invalid
|
|
286
|
+
}
|
|
287
|
+
}
|
|
279
288
|
return {
|
|
280
|
-
val
|
|
289
|
+
val,
|
|
281
290
|
type: "date",
|
|
282
291
|
};
|
|
283
292
|
},
|
|
284
293
|
compare: (currentVal, newVal) => {
|
|
285
|
-
if (
|
|
294
|
+
if (currentVal === undefined) {
|
|
286
295
|
return false;
|
|
287
296
|
}
|
|
288
297
|
|
|
289
298
|
if (currentVal || newVal) {
|
|
290
|
-
|
|
299
|
+
if (currentVal === newVal) {
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
const d1 = new Date(currentVal);
|
|
304
|
+
const d2 = new Date(newVal);
|
|
305
|
+
return d1.getTime() === d2.getTime();
|
|
306
|
+
} catch (_e) {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
291
309
|
}
|
|
292
|
-
return currentVal
|
|
310
|
+
return currentVal === newVal;
|
|
293
311
|
},
|
|
294
312
|
},
|
|
295
313
|
stringSanitized: {
|