@livepreso/api 6.55.2 → 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.
- package/.rush/temp/shrinkwrap-deps.json +1013 -1191
- package/CHANGELOG.json +17 -0
- package/CHANGELOG.md +12 -1
- 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.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 +1 -3
- 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/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/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 +1 -3
- package/src/utils.js +31 -2
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,I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AEpB,QAAQ,CAAC;MACjC,OAAOpB,IAAI;IACZ,CAAC,CAAC;EACH,CAAC,CAAC,CACDkC,KAAK,CAACO,mBAAU,CAACC,sBAAsB,EAAE,UAACJ,CAAC,EAAK;IAChD,IACCA,CAAC,CAACK,GAAG,IACLL,CAAC,CAACK,GAAG,CAACC,IAAI,KACRN,CAAC,CAACO,MAAM,IAAI,GAAG,IAAIP,CAAC,CAACO,MAAM,GAAG,GAAG,IAAKP,CAAC,CAACO,MAAM,KAAK,GAAG,CAAC,EACxD;MACDP,CAAC,CAACF,OAAO,eAAAhD,MAAA,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","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,GAAG,CAAC,CAAC;AACnB,CAAC;AAEM,IAAMC,QAAQ,GAAAZ,OAAA,CAAAY,QAAA,GAAG,SAAXA,QAAQA,CAAAC,KAAA,EAA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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; }
|
|
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,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,CAAA,EAAAC,CAAA,CAAAD,CAAA,SAAAE,MAAA,CAAAe,yBAAA,GAAAf,MAAA,CAAAgB,gBAAA,CAAAnB,CAAA,EAAAG,MAAA,CAAAe,yBAAA,CAAAhB,CAAA,KAAAH,OAAA,CAAAI,MAAA,CAAAD,CAAA,GAA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AAW,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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E;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.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
|
-
"
|
|
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",
|
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: {
|
|
@@ -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 (
|
|
203
|
+
fetchLayout: async function ({ presetID, scenarioID }) {
|
|
230
204
|
let queryParams = { version: this.version };
|
|
231
|
-
if (
|
|
232
|
-
queryParams.preset_id =
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
171
|
+
const sectionKeyPath = resolveURL(
|
|
170
172
|
this.url(),
|
|
171
173
|
`sections/${sectionKey}/`,
|
|
172
174
|
);
|
|
173
175
|
if (slideKey) {
|
|
174
|
-
return
|
|
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
|
|
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() {
|
package/src/models/pack.js
CHANGED
|
@@ -17,7 +17,7 @@ import _ from "lodash";
|
|
|
17
17
|
import { getAssetRoot } from "../index.js";
|
|
18
18
|
import log from "../log.js";
|
|
19
19
|
import { register } from "../state-register";
|
|
20
|
-
import
|
|
20
|
+
import { resolveURL } from "../utils.js";
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* @constructor
|
|
@@ -67,6 +67,9 @@ export const PresentationDeck = BasePresentationModel.extend(
|
|
|
67
67
|
version: "number",
|
|
68
68
|
namespacedKey: "string",
|
|
69
69
|
cmsvalkey_set: "array",
|
|
70
|
+
isWelcome: { type: "boolean", default: true },
|
|
71
|
+
isSlide: { type: "boolean", default: false },
|
|
72
|
+
isSection: { type: "boolean", default: false },
|
|
70
73
|
},
|
|
71
74
|
|
|
72
75
|
/**
|
|
@@ -406,8 +409,8 @@ PresentationDeck.createFromManifestJSON = function (manifestJSON, project) {
|
|
|
406
409
|
index: 0,
|
|
407
410
|
visible: true,
|
|
408
411
|
key: manifestJSON.key || "manifest_deck",
|
|
409
|
-
html:
|
|
410
|
-
css:
|
|
412
|
+
html: resolveURL(manifestJSON.getAssetPath(), "index.html"),
|
|
413
|
+
css: resolveURL(manifestJSON.getAssetPath(), "slide.css"),
|
|
411
414
|
common: manifestJSON.common,
|
|
412
415
|
thumbnail: null,
|
|
413
416
|
deckID: 1,
|
|
@@ -434,8 +437,8 @@ PresentationDeck.createFromManifestJSON = function (manifestJSON, project) {
|
|
|
434
437
|
return {
|
|
435
438
|
key: newKey,
|
|
436
439
|
sequence,
|
|
437
|
-
html:
|
|
438
|
-
css:
|
|
440
|
+
html: resolveURL(manifestJSON.getAssetPath(key), "index.html"),
|
|
441
|
+
css: resolveURL(manifestJSON.getAssetPath(key), "slide.css"),
|
|
439
442
|
title: manifestJSON.titles[key],
|
|
440
443
|
tags: manifestJSON.tags[key] || [],
|
|
441
444
|
cmsvalkey_set: [],
|
|
@@ -500,10 +503,7 @@ PresentationDeck.createFromManifestJSON = function (manifestJSON, project) {
|
|
|
500
503
|
key,
|
|
501
504
|
sequence: manifestJSON.templates[key].ordering,
|
|
502
505
|
index_asset: {
|
|
503
|
-
url:
|
|
504
|
-
manifestJSON.getTemplateAssetPath(key),
|
|
505
|
-
"index.html",
|
|
506
|
-
),
|
|
506
|
+
url: resolveURL(manifestJSON.getTemplateAssetPath(key), "index.html"),
|
|
507
507
|
},
|
|
508
508
|
cmsvalkey_set: cmsvals,
|
|
509
509
|
};
|
|
@@ -17,7 +17,7 @@ import { PresentationSlide } from "./presentation-slide.js";
|
|
|
17
17
|
import _ from "lodash";
|
|
18
18
|
import { getAssetRoot } from "../index.js";
|
|
19
19
|
import { register } from "../state-register.js";
|
|
20
|
-
import
|
|
20
|
+
import { resolveURL } from "../utils.js";
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* @constructor
|
|
@@ -102,11 +102,10 @@ export const PresentationSection = BasePresentationModel.extend(
|
|
|
102
102
|
tagsEditable: "boolean",
|
|
103
103
|
tags: "array",
|
|
104
104
|
impostor: "boolean",
|
|
105
|
-
isWelcome: {
|
|
106
|
-
type: "boolean",
|
|
107
|
-
default: false,
|
|
108
|
-
},
|
|
109
105
|
cmsvalkey_set: "array",
|
|
106
|
+
isWelcome: { type: "boolean", default: false },
|
|
107
|
+
isSlide: { type: "boolean", default: false },
|
|
108
|
+
isSection: { type: "boolean", default: true },
|
|
110
109
|
},
|
|
111
110
|
|
|
112
111
|
/**
|
|
@@ -445,8 +444,8 @@ PresentationSection.createFromManifestJSON = function (
|
|
|
445
444
|
id: parseInt(_.uniqueId(), 10),
|
|
446
445
|
index,
|
|
447
446
|
title: manifestJSON.titles[sectionKey],
|
|
448
|
-
html:
|
|
449
|
-
css:
|
|
447
|
+
html: resolveURL(manifestJSON.getAssetPath(sectionKey), "index.html"),
|
|
448
|
+
css: resolveURL(manifestJSON.getAssetPath(sectionKey), "slide.css"),
|
|
450
449
|
key: sectionKey,
|
|
451
450
|
sequence: manifestJSON.ordering[sectionKey] - 1,
|
|
452
451
|
thumbnail: null,
|
|
@@ -605,11 +604,32 @@ PresentationSection.createFromAutoAdjunct = function (model, opts = {}) {
|
|
|
605
604
|
return autoAdjunctSection;
|
|
606
605
|
};
|
|
607
606
|
|
|
608
|
-
PresentationSection.createFromTemplate = function (
|
|
607
|
+
PresentationSection.createFromTemplate = function (
|
|
608
|
+
template,
|
|
609
|
+
index,
|
|
610
|
+
minID = 0,
|
|
611
|
+
options = {},
|
|
612
|
+
) {
|
|
609
613
|
const templateModel = new TemplateModel(template);
|
|
610
614
|
|
|
615
|
+
_.defaults(options, {
|
|
616
|
+
rootAssetPath: null,
|
|
617
|
+
});
|
|
618
|
+
|
|
611
619
|
const deckversion = new DeckVersionModel(templateModel.deckversion);
|
|
612
|
-
|
|
620
|
+
|
|
621
|
+
let html;
|
|
622
|
+
let css;
|
|
623
|
+
|
|
624
|
+
if (options.rootAssetPath) {
|
|
625
|
+
const origPath = templateModel.index_asset.orig_path;
|
|
626
|
+
html = `${options.rootAssetPath}${origPath}/index.html`;
|
|
627
|
+
css = `${options.rootAssetPath}${origPath}/slide.css`;
|
|
628
|
+
} else {
|
|
629
|
+
const templateAssetRoot = getAssetRoot(templateModel.index_asset.url());
|
|
630
|
+
html = `${templateAssetRoot}index.html`;
|
|
631
|
+
css = `${templateAssetRoot}slide.css`;
|
|
632
|
+
}
|
|
613
633
|
|
|
614
634
|
const presentationSection = new PresentationSection({
|
|
615
635
|
id: minID + parseInt(_.uniqueId(), 10),
|
|
@@ -617,8 +637,8 @@ PresentationSection.createFromTemplate = function (template, index, minID = 0) {
|
|
|
617
637
|
template: templateModel,
|
|
618
638
|
key: `template-${templateModel.key}`,
|
|
619
639
|
title: templateModel.title,
|
|
620
|
-
html
|
|
621
|
-
css
|
|
640
|
+
html,
|
|
641
|
+
css,
|
|
622
642
|
custom: false,
|
|
623
643
|
visible: true,
|
|
624
644
|
thumbnail: templateModel.image_256,
|
|
@@ -63,6 +63,8 @@ describe("#createFromSection", () => {
|
|
|
63
63
|
id: 1728,
|
|
64
64
|
impostor: false,
|
|
65
65
|
index: 0,
|
|
66
|
+
isSection: true,
|
|
67
|
+
isSlide: false,
|
|
66
68
|
isWelcome: false,
|
|
67
69
|
key: "agenda",
|
|
68
70
|
namespacedKey: "agenda",
|
|
@@ -192,6 +194,8 @@ describe("#createFromAdjunctSection", () => {
|
|
|
192
194
|
"https://staging-test-cdn.salespreso.com/media/autoadjunct/123.png",
|
|
193
195
|
impostor: false,
|
|
194
196
|
index: 1,
|
|
197
|
+
isSection: true,
|
|
198
|
+
isSlide: false,
|
|
195
199
|
isWelcome: false,
|
|
196
200
|
key: "adjunct-1737",
|
|
197
201
|
sequence: 1,
|
|
@@ -325,6 +329,8 @@ describe("#createFromImpostorSection", () => {
|
|
|
325
329
|
id: 23898,
|
|
326
330
|
impostor: true,
|
|
327
331
|
index: 0,
|
|
332
|
+
isSection: true,
|
|
333
|
+
isSlide: false,
|
|
328
334
|
isWelcome: false,
|
|
329
335
|
key: "agenda",
|
|
330
336
|
namespacedKey: "test-deck/agenda",
|
|
@@ -437,6 +443,8 @@ describe("#createFromAutoAdjunct", () => {
|
|
|
437
443
|
"https://staging-test-cdn.salespreso.com/media/autoadjunct/123.png",
|
|
438
444
|
impostor: false,
|
|
439
445
|
index: 3,
|
|
446
|
+
isSection: true,
|
|
447
|
+
isSlide: false,
|
|
440
448
|
isWelcome: false,
|
|
441
449
|
key: "autoadjunct-five",
|
|
442
450
|
sequence: 3,
|