@livepreso/api 6.55.1 → 6.56.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.
Files changed (66) hide show
  1. package/.rush/temp/shrinkwrap-deps.json +1013 -1191
  2. package/CHANGELOG.json +29 -0
  3. package/CHANGELOG.md +19 -1
  4. package/cjs/api.js +3 -5
  5. package/cjs/api.js.map +1 -1
  6. package/cjs/auth.spec.js +11 -11
  7. package/cjs/auth.spec.js.map +1 -1
  8. package/cjs/collections/appointment-tags.js +14 -15
  9. package/cjs/collections/appointment-tags.js.map +1 -1
  10. package/cjs/collections/base.spec.js +30 -30
  11. package/cjs/collections/base.spec.js.map +1 -1
  12. package/cjs/fixtures.js +1 -2
  13. package/cjs/fixtures.js.map +1 -1
  14. package/cjs/models/appointment.js +7 -7
  15. package/cjs/models/appointment.js.map +1 -1
  16. package/cjs/models/base.js +30 -12
  17. package/cjs/models/base.js.map +1 -1
  18. package/cjs/models/cms-val.spec.js +2 -2
  19. package/cjs/models/cms-val.spec.js.map +1 -1
  20. package/cjs/models/deck-version.js +14 -34
  21. package/cjs/models/deck-version.js.map +1 -1
  22. package/cjs/models/manifest-json.js +41 -5
  23. package/cjs/models/manifest-json.js.map +1 -1
  24. package/cjs/models/pack.js +2 -1
  25. package/cjs/models/pack.js.map +1 -1
  26. package/cjs/models/snapshot.spec.js +2 -2
  27. package/cjs/models/snapshot.spec.js.map +1 -1
  28. package/cjs/models/template.js +10 -10
  29. package/cjs/models/template.js.map +1 -1
  30. package/cjs/models/timing-log.spec.js +2 -2
  31. package/cjs/models/timing-log.spec.js.map +1 -1
  32. package/cjs/models/user.spec.js +4 -4
  33. package/cjs/models/user.spec.js.map +1 -1
  34. package/cjs/presentation/presentation-deck.js +19 -9
  35. package/cjs/presentation/presentation-deck.js.map +1 -1
  36. package/cjs/presentation/presentation-deck.spec.js +6 -6
  37. package/cjs/presentation/presentation-deck.spec.js.map +1 -1
  38. package/cjs/presentation/presentation-section.js +33 -10
  39. package/cjs/presentation/presentation-section.js.map +1 -1
  40. package/cjs/presentation/presentation-section.spec.js +24 -16
  41. package/cjs/presentation/presentation-section.spec.js.map +1 -1
  42. package/cjs/presentation/presentation-slide.js +18 -7
  43. package/cjs/presentation/presentation-slide.js.map +1 -1
  44. package/cjs/presentation/presentation-slide.spec.js +21 -12
  45. package/cjs/presentation/presentation-slide.spec.js.map +1 -1
  46. package/cjs/presentation/presentation-subslide.spec.js +10 -10
  47. package/cjs/presentation/presentation-subslide.spec.js.map +1 -1
  48. package/cjs/presentation/presentation.js +26 -26
  49. package/cjs/presentation/presentation.js.map +1 -1
  50. package/cjs/sync.js +1 -3
  51. package/cjs/sync.js.map +1 -1
  52. package/cjs/utils.js +33 -3
  53. package/cjs/utils.js.map +1 -1
  54. package/package.json +3 -3
  55. package/src/api.js +3 -5
  56. package/src/models/base.js +27 -9
  57. package/src/models/deck-version.js +5 -31
  58. package/src/models/manifest-json.js +33 -5
  59. package/src/models/pack.js +1 -0
  60. package/src/presentation/presentation-deck.js +9 -9
  61. package/src/presentation/presentation-section.js +35 -12
  62. package/src/presentation/presentation-section.spec.js +8 -0
  63. package/src/presentation/presentation-slide.js +7 -4
  64. package/src/presentation/presentation-slide.spec.js +9 -0
  65. package/src/sync.js +1 -3
  66. 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 _callee$(_context2) {
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 = 2;
49
+ _context2.prev = 1;
50
50
  _loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
51
51
  var auto, dvTemplate;
52
- return _regenerator.default.wrap(function _loop$(_context) {
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 = 6;
60
+ _context.next = 1;
61
61
  break;
62
62
  }
63
63
  auto.template = dvTemplate;
64
- _context.next = 9;
64
+ _context.next = 3;
65
65
  break;
66
- case 6:
67
- _context.next = 8;
66
+ case 1:
67
+ _context.next = 2;
68
68
  return auto.template.fetch();
69
- case 8:
69
+ case 2:
70
70
  templates.push(auto.template);
71
- case 9:
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 5:
78
+ case 2:
79
79
  if ((_step = _iterator.n()).done) {
80
- _context2.next = 9;
80
+ _context2.next = 4;
81
81
  break;
82
82
  }
83
- return _context2.delegateYield(_loop(), "t0", 7);
84
- case 7:
85
- _context2.next = 5;
83
+ return _context2.delegateYield(_loop(), "t0", 3);
84
+ case 3:
85
+ _context2.next = 2;
86
86
  break;
87
- case 9:
88
- _context2.next = 14;
87
+ case 4:
88
+ _context2.next = 6;
89
89
  break;
90
- case 11:
91
- _context2.prev = 11;
92
- _context2.t1 = _context2["catch"](2);
93
- _iterator.e(_context2.t1);
94
- case 14:
95
- _context2.prev = 14;
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(14);
98
- case 17:
97
+ return _context2.finish(6);
98
+ case 7:
99
99
  case "end":
100
100
  return _context2.stop();
101
101
  }
102
- }, _callee, null, [[2, 11, 14, 17]]);
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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AACK,sBAAsB,CAACG,aAAa,EAAED,OAAO,CAAC;EAC5E,IAAMZ,YAAY,GAAG,IAAIzD,YAAY,CAAC,CAAC;EACvCyD,YAAY,CAACpD,KAAK,CAACwD,GAAG,CAACtC,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,UAA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MpB,IAAI,GAAGqC,kCAAgB,CAACK,sBAAsB,CAACG,aAAa,EAAED,OAAO,CAAC;EAC5E,IAAMZ,YAAY,GAAG,IAAIvD,YAAY,CAAC,CAAC;EACvCuD,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.replace(urlParse.search, "");
43
+ return url.split("?")[0];
46
44
  }
47
45
  return url;
48
46
  };
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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C,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","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;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;AAEA,IAAMM,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;EAC/CC,YAAG,CAACC,IAAI,CAAC,6DAA6D,CAAC;EACvE,OAAOF,KAAK,CAACG,GA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ACnD;;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":[]}
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; } /* eslint-disable no-control-regex */
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
- return _url.default.parse(url).path;
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"],"m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AA,OAAM,IAAI;EAAA;EAC3D,IAAIgC,KAAK,CAACC,OAAO,CAACoC,GAAG,CAAC,EAAE;IACvB,OAAOA,GAAG,CAACnC,GAAG,CAAC,UAACsC,CAAC;MAAA,OAAKJ,cAAc,CAACI,CAAC,EAAEF,WAAW,CAAC;IAAA,EAAC;EACtD,CAAC,MAAM,IACN,IAAAG,QAAA,CAAArE,OAAA,EAAOiE,GAAG,MAAK,QAAQ,IACvBA,GAAG,KAAK,IAAI,IACZ,OAAOA,GAAG,KAAK,WAAW,EACzB;IACD,OAAO/E,MAAM,CAACC,IAAI,CAAC8E,GAAG,CAAC,CAAC/B,MAAM,CAAC,UAACoC,GAAG,EAAElC,GAAG,EAAK;MAC5C,OAAAzC,aAAA,CAAAA,aAAA,KAAY2E,GAAG,WAAAvE,gBAAA,CAAAC,OAAA,MAAGoC,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":[]}
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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAuB,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,O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[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@livepreso/api",
3
3
  "license": "UNLICENSED",
4
- "version": "6.55.1",
4
+ "version": "6.56.0",
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
- "@livepreso/eslint-config": "1.0.0",
60
- "sp-test": "0.2.0"
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",
package/src/api.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import Promise from "bluebird";
2
- import url2 from "url";
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 urlObj = url2.parse(Api._apiURL);
76
- urlObj.pathname = "";
77
- urlObj.search = "";
78
- return url2.format(urlObj);
75
+ const url = resolveURL(Api._apiURL, "/");
76
+ return url;
79
77
  },
80
78
 
81
79
  /**
@@ -1,4 +1,4 @@
1
- import { DATE_FORMAT_T, removeMultiByteChars } from "../utils.js";
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 = url2.parse(url).path;
250
- const resourceURLPath = url2.parse(resourceURL).path;
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: newVal ? moment.utc(newVal).format(DATE_FORMAT_T) : null,
289
+ val,
281
290
  type: "date",
282
291
  };
283
292
  },
284
293
  compare: (currentVal, newVal) => {
285
- if (typeof currentVal === "undefined") {
294
+ if (currentVal === undefined) {
286
295
  return false;
287
296
  }
288
297
 
289
298
  if (currentVal || newVal) {
290
- return moment(currentVal).isSame(moment(newVal));
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 !== newVal;
310
+ return currentVal === newVal;
293
311
  },
294
312
  },
295
313
  stringSanitized: {
@@ -5,15 +5,12 @@ import "./deck.js";
5
5
  import "./asset.js";
6
6
  import "./manifest-json.js";
7
7
 
8
- import { Auth } from "../auth.js";
9
8
  import { BaseModel } from "./base.js";
10
9
  import { DeckLayoutModel } from "./deck-layout.js";
11
10
  import { DeckVersionScreenshotCollection } from "../collections/deck-version-screenshots.js";
12
11
  import Promise from "bluebird";
13
12
  import { TemplateCollection } from "../collections.js";
14
- import _ from "lodash";
15
13
  import { register } from "../state-register.js";
16
- import superagent from "superagent";
17
14
 
18
15
  /**
19
16
  * @constructor
@@ -178,29 +175,6 @@ export const DeckVersionModel = BaseModel.extend(
178
175
  });
179
176
  },
180
177
 
181
- getFixtures(fixtures = {}, rootAssetUrl = this.getRootAssetUrl()) {
182
- const fixturePaths = this.manifest_json.fixtures || {};
183
-
184
- const imports = _.map(fixturePaths, (fixture, key) => {
185
- const path = `${rootAssetUrl}${fixture}`;
186
-
187
- return superagent
188
- .get(path)
189
- .then((response) => {
190
- if (response.text) {
191
- fixtures[key] = JSON.parse(response.text);
192
- } else {
193
- fixtures[key] = response.body || {};
194
- }
195
- })
196
- .catch(superagent.SuperagentPromiseError, (e) => {
197
- throw e;
198
- });
199
- });
200
-
201
- return Promise.all(imports);
202
- },
203
-
204
178
  fetch(opts, ...other) {
205
179
  const fetch = BaseModel.prototype.fetch.apply(this, [opts, ...other]);
206
180
  const shouldFetchTemplates = opts?.fetchTemplates ?? true;
@@ -226,17 +200,17 @@ export const DeckVersionModel = BaseModel.extend(
226
200
  );
227
201
  },
228
202
 
229
- fetchLayout: async function (presetId, scenarioID) {
203
+ fetchLayout: async function ({ presetID, scenarioID }) {
230
204
  let queryParams = { version: this.version };
231
- if (presetId) {
232
- queryParams.preset_id = presetId;
205
+ if (presetID) {
206
+ queryParams.preset_id = presetID;
233
207
  }
234
208
  if (scenarioID) {
235
209
  queryParams.scenario_id = scenarioID;
236
210
  }
237
211
 
238
- if (!this.id) {
239
- return Promise.reject(new Error("DeckVersion has no ID."));
212
+ if (!this.deck.id) {
213
+ return Promise.reject(new Error("DeckVersion has no deck."));
240
214
  }
241
215
 
242
216
  const layout = new DeckLayoutModel(
@@ -1,8 +1,10 @@
1
+ import _ from "lodash";
1
2
  import "./pack.js";
2
3
 
4
+ import superagent from "superagent";
3
5
  import { BaseModel } from "./base.js";
4
6
  import { register } from "../state-register.js";
5
- import url2 from "url";
7
+ import { resolveURL } from "../utils.js";
6
8
 
7
9
  /**
8
10
  * @constructor
@@ -135,7 +137,7 @@ export const ManifestJSONModel = BaseModel.extend(
135
137
  getDimensionsByName(name) {
136
138
  if (Array.isArray(this.dimensions)) {
137
139
  const dimension = this.dimensions.find(
138
- (d) => d.name?.toLowerCase() === name?.toLowerCase(),
140
+ (d) => d.name?.toLowerCase() === name.toLowerCase(),
139
141
  );
140
142
  if (!dimension) {
141
143
  return { width: 1024, height: 767 };
@@ -166,12 +168,12 @@ export const ManifestJSONModel = BaseModel.extend(
166
168
  getAssetPath(key = null) {
167
169
  if (key) {
168
170
  const [sectionKey, slideKey = null] = key.split("/");
169
- const sectionKeyPath = url2.resolve(
171
+ const sectionKeyPath = resolveURL(
170
172
  this.url(),
171
173
  `sections/${sectionKey}/`,
172
174
  );
173
175
  if (slideKey) {
174
- return url2.resolve(sectionKeyPath, `slides/${slideKey}/`);
176
+ return resolveURL(sectionKeyPath, `slides/${slideKey}/`);
175
177
  }
176
178
  return sectionKeyPath;
177
179
  }
@@ -185,7 +187,33 @@ export const ManifestJSONModel = BaseModel.extend(
185
187
  * @returns {?string}
186
188
  */
187
189
  getTemplateAssetPath(key) {
188
- return url2.resolve(this.getAssetPath(), `templates/${key}/`);
190
+ return resolveURL(this.getAssetPath(), `templates/${key}/`);
191
+ },
192
+
193
+ async getFixtures(rootAssetUrl) {
194
+ const fixturePaths = this.fixtures || {};
195
+ const fixtures = {};
196
+
197
+ const imports = _.map(fixturePaths, (fixture, key) => {
198
+ const path = `${rootAssetUrl}${fixture}`;
199
+
200
+ return superagent
201
+ .get(path)
202
+ .then((response) => {
203
+ if (response.text) {
204
+ fixtures[key] = JSON.parse(response.text);
205
+ } else {
206
+ fixtures[key] = response.body || {};
207
+ }
208
+ })
209
+ .catch(superagent.SuperagentPromiseError, (e) => {
210
+ throw e;
211
+ });
212
+ });
213
+
214
+ await Promise.all(imports);
215
+
216
+ return fixtures;
189
217
  },
190
218
 
191
219
  url() {