@storyteq/platform-integration 1.0.8 → 1.0.9-beta
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.
|
@@ -32,5 +32,5 @@ export interface ICreateMediaConfig {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
export declare class CreateMediaPage extends BaseFrameController<typeof AVAILABLE_CREATE_MEDIA_EVENTS> {
|
|
35
|
-
constructor(spawnElement: string, STAuthToken: string | false, templateId: number, companyId: number, config?: ICreateMediaConfig);
|
|
35
|
+
constructor(spawnElement: string, STAuthToken: string | false, templateId: number, companyId: number, config?: ICreateMediaConfig, clientId?: string);
|
|
36
36
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BaseFrameController } from './BaseFrameController';
|
|
2
2
|
export declare class CrmAnalyticsPage extends BaseFrameController<['loaded']> {
|
|
3
|
-
constructor(spawnElement: string, STAuthToken: string | false, templateId: number, campaignId: number, config?: any);
|
|
3
|
+
constructor(spawnElement: string, STAuthToken: string | false, templateId: number, campaignId: number, config?: any, clientId?: string);
|
|
4
4
|
}
|
package/build/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("lodash-es")):"function"==typeof define&&define.amd?define(["lodash-es"],t):"object"==typeof exports?exports["@storyteq/platform-integration"]=t(require("lodash-es")):e["@storyteq/platform-integration"]=t(e._)}(this,(function(e){return function(){"use strict";var t={731:function(t){t.exports=e}},n={};function r(e){var s=n[e];if(void 0!==s)return s.exports;var
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("lodash-es")):"function"==typeof define&&define.amd?define(["lodash-es"],t):"object"==typeof exports?exports["@storyteq/platform-integration"]=t(require("lodash-es")):e["@storyteq/platform-integration"]=t(e._)}(this,(function(e){return function(){"use strict";var t={731:function(t){t.exports=e}},n={};function r(e){var s=n[e];if(void 0!==s)return s.exports;var o=n[e]={exports:{}};return t[e](o,o.exports,r),o.exports}r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};return function(){r.r(s),r.d(s,{AVAILABLE_CREATE_MEDIA_EVENTS:function(){return o},CreateMediaPage:function(){return i},CrmAnalyticsPage:function(){return a}});var e=r(731);function t(){return window.APP_URL??"https://platform.storyteq.com"}class n{constructor(n,r,s,o,i,a={}){this.spawnElement=n,this.authToken=r,this.availableEvents=i,this._eventListeners=[],this._readyForToken=!1,this._readyForTokenCb=()=>{this._readyForToken=!0,this._jwtToken&&(this.setJwtToken(this._jwtToken),this._jwtToken="")},this._receiveMessage=t=>{if(t.origin===this._url.origin)try{const n=JSON.parse(t.data);this._eventListeners.forEach((({event:t,cb:r})=>{const s=(0,e.omit)(n,["event"]);t===n.event&&r(s)}))}catch(e){console.error("[Storyteq platform integration] Failed to parse incoming frame message;",t.data)}},this._url=new URL(s,t());const c={no_navigation:"true",config:o,...a};r?c.auth_token=r:(c.auth_via_message="",this._eventListeners.push({event:"ready_for_token",cb:this._readyForTokenCb})),(0,e.forEach)(c,((e,t)=>{this._url.searchParams.set(t,e)})),this._init()}_init(){["interactive","complete"].includes(document.readyState)?this._spawn():document.addEventListener("readystatechange",(()=>{["interactive","complete"].includes(document.readyState)&&this._spawn()}))}_spawn(){const e=document.createElement("iframe");e.src=this._url.toString(),e.style.width="100%",e.style.height="100%",e.style.position="absolute",e.style.border="none";const t=document.querySelector(this.spawnElement);t||console.error(`[Storyteq platform integration] Failed to find target element ${this.spawnElement}`),t.style.position="relative",t.appendChild(e),this._frame=e,this._initiatePageListeners()}_initiatePageListeners(){window.addEventListener("message",this._receiveMessage,!1)}on(e,t){return this.availableEvents.includes(e)||console.error(`[Storyteq platform integration] Trying to listen to unsupported event "${e}"`),this._eventListeners.push({event:e,cb:t}),this}sendMessage(e){return this._frame.contentWindow.postMessage(e,{targetOrigin:this._url.origin}),this}setJwtToken(e){return this._readyForToken?this.sendMessage({type:"JWT_TOKEN",token:e}):this._jwtToken=e,this}destroy(){if(this._frame){window.removeEventListener("message",this._receiveMessage),this._eventListeners=[];try{this._frame.parentElement.removeChild(this._frame)}catch(e){}}}}const o=["loaded","created","batch-created","batch-loaded","canceled"];class i extends n{constructor(e,n,r,s,i={},a){let c="";c=t().startsWith("https://app.storyteq.")?`/platform/${a??"_"}/integration`:"/integration",super(e,n,c,JSON.stringify(i),o,{companyId:`${s}`,templateId:`${r}`})}}class a extends n{constructor(e,n,r,s,o,i){const a=t().startsWith("https://app.storyteq.");let c="";c=i||a?`/platform/${i??"_"}/campaigns/${s}/templates/${r}`:`/campaigns/${s}/templates/${r}`,super(e,n,c,JSON.stringify(o),["loaded"])}}}(),s}()}));
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,EAAQG,QAAQ,cACR,mBAAXC,QAAyBA,OAAOC,IAC9CD,OAAO,CAAC,aAAcJ,GACI,iBAAZC,QACdA,QAAQ,kCAAoCD,EAAQG,QAAQ,cAE5DJ,EAAK,kCAAoCC,EAAQD,EAAQ,EAC1D,CATD,CASGO,MAAM,SAASC,GAClB,O,+CCVAL,EAAOD,QAAUM,C,GCCbC,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaV,QAGrB,IAAIC,EAASM,EAAyBE,GAAY,CAGjDT,QAAS,CAAC,GAOX,OAHAY,EAAoBH,G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,YAAaD,UAFtCvF,KAAKoC,UAAYmD,EAKZvF,IACT,CAEOyF,UACL,GAAKzF,KAAK+E,OAAV,CAIAzB,OAAOoC,oBAAoB,UAAW1F,KAAKsC,iBAE3CtC,KAAKiC,gBAAkB,GAEvB,IACEjC,KAAK+E,OAAOY,cAAcC,YAAY5F,KAAK+E,O,CAC3C,MAAO5B,GAAO,C,CAClB,EE7IK,MAAM0C,EAAoG,CAC/G,SACA,UACA,gBACA,eACA,YAsBK,MAAMC,UAAwBrE,EACnCC,YACEC,EACAoE,EACAC,EACAC,EACAnE,EAA6B,CAAC,GAI9BoE,MAAMvE,EAAcoE,EAFP,eAE0BpD,KAAKwD,UAAUrE,GAAS+D,EAA+B,CAC5FI,UAAW,GAAGA,IACdD,WAAY,GAAGA,KAEnB,ECzCK,MAAMI,UAAyB3E,EACpCC,YAAYC,EAAsBoE,EAA6BC,EAAoBK,EAAoBvE,GAGrGoE,MAAMvE,EAAcoE,EAFP,cAAcM,eAAwBL,IAEZrD,KAAKwD,UAAUrE,GAAS,CAAC,UAClE,E","sources":["webpack://@storyteq/platform-integration/webpack/universalModuleDefinition","webpack://@storyteq/platform-integration/external umd {\"commonjs\":\"lodash-es\",\"commonjs2\":\"lodash-es\",\"amd\":\"lodash-es\",\"root\":\"_\"}","webpack://@storyteq/platform-integration/webpack/bootstrap","webpack://@storyteq/platform-integration/webpack/runtime/define property getters","webpack://@storyteq/platform-integration/webpack/runtime/hasOwnProperty shorthand","webpack://@storyteq/platform-integration/webpack/runtime/make namespace object","webpack://@storyteq/platform-integration/./src/classes/BaseFrameController.ts","webpack://@storyteq/platform-integration/./src/get-frame-url.ts","webpack://@storyteq/platform-integration/./src/classes/CreateMediaPage.ts","webpack://@storyteq/platform-integration/./src/classes/CrmAnalyticsPage.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"lodash-es\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"lodash-es\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"@storyteq/platform-integration\"] = factory(require(\"lodash-es\"));\n\telse\n\t\troot[\"@storyteq/platform-integration\"] = factory(root[\"_\"]);\n})(this, function(__WEBPACK_EXTERNAL_MODULE__731__) {\nreturn ","module.exports = __WEBPACK_EXTERNAL_MODULE__731__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = function(exports, definition) {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }","// define __esModule on exports\n__webpack_require__.r = function(exports) {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { forEach, omit } from 'lodash-es';\nimport { getFrameUrl } from '../get-frame-url';\nimport { OneOf } from '../interfaces/one-of.interface';\n\nexport class BaseFrameController<T extends Array<string>> {\n private _url: URL;\n private _eventListeners: Array<{ event: string; cb: (data: unknown) => void }> = [];\n private _readyForToken = false;\n private _jwtToken: string;\n private _frame: HTMLIFrameElement;\n\n private _readyForTokenCb = () => {\n this._readyForToken = true;\n\n if (this._jwtToken) {\n this.setJwtToken(this._jwtToken);\n this._jwtToken = '';\n }\n };\n\n constructor(\n public readonly spawnElement: string,\n public readonly authToken: string | false,\n uri: string,\n config: string,\n public readonly availableEvents: T,\n extraSearchParams: Record<string, string> = {}\n ) {\n this._url = new URL(uri, getFrameUrl());\n\n const searchParams: Record<string, string> = {\n no_navigation: 'true',\n config: config,\n ...extraSearchParams,\n };\n\n if (authToken) {\n searchParams.auth_token = authToken;\n } else {\n searchParams.auth_via_message = '';\n\n this._eventListeners.push({ event: 'ready_for_token', cb: this._readyForTokenCb });\n }\n\n forEach(searchParams, (value: string, key: string) => {\n this._url.searchParams.set(key, value);\n });\n\n this._init();\n }\n\n private _init(): void {\n if (!['interactive', 'complete'].includes(document.readyState)) {\n document.addEventListener('readystatechange', () => {\n if (['interactive', 'complete'].includes(document.readyState)) this._spawn();\n });\n } else this._spawn();\n }\n\n private _spawn(): void {\n const iframe: HTMLIFrameElement = document.createElement('iframe');\n\n iframe.src = this._url.toString();\n iframe.style.width = '100%';\n iframe.style.height = '100%';\n iframe.style.position = 'absolute';\n iframe.style.border = 'none';\n\n const spawnElement: HTMLElement = document.querySelector(this.spawnElement);\n\n if (!spawnElement) {\n console.error(`[Storyteq platform integration] Failed to find target element ${this.spawnElement}`);\n }\n\n spawnElement.style.position = 'relative';\n spawnElement.appendChild(iframe);\n\n this._frame = iframe;\n\n this._initiatePageListeners();\n }\n\n private _receiveMessage = (e: MessageEvent) => {\n if (e.origin === this._url.origin) {\n try {\n const messagePayload = JSON.parse(e.data);\n\n this._eventListeners.forEach(({ event, cb }) => {\n const eventPayload = omit(messagePayload, ['event']);\n\n if (event === messagePayload.event) cb(eventPayload);\n });\n } catch (error) {\n console.error('[Storyteq platform integration] Failed to parse incoming frame message;', e.data);\n }\n }\n };\n\n private _initiatePageListeners(): void {\n window.addEventListener('message', this._receiveMessage, false);\n }\n\n public on(event: OneOf<T>, cb: (data: unknown) => void): this {\n if (!this.availableEvents.includes(event)) {\n console.error(`[Storyteq platform integration] Trying to listen to unsupported event \"${event}\"`);\n }\n\n this._eventListeners.push({\n event,\n cb,\n });\n\n return this;\n }\n\n public sendMessage(message: any): this {\n this._frame.contentWindow.postMessage(message, { targetOrigin: this._url.origin });\n\n return this;\n }\n\n public setJwtToken(token: string): this {\n if (!this._readyForToken) {\n this._jwtToken = token;\n } else {\n this.sendMessage({ type: 'JWT_TOKEN', token });\n }\n\n return this;\n }\n\n public destroy(): void {\n if (!this._frame) {\n return;\n }\n\n window.removeEventListener('message', this._receiveMessage);\n\n this._eventListeners = [];\n\n try {\n this._frame.parentElement.removeChild(this._frame);\n } catch (error) {}\n }\n}\n","export function getFrameUrl() {\n return window.APP_URL ?? 'https://platform.storyteq.com';\n}\n","import { BaseFrameController } from './BaseFrameController';\n\nexport const AVAILABLE_CREATE_MEDIA_EVENTS: ['loaded', 'created', 'batch-created', 'batch-loaded', 'canceled'] = [\n 'loaded',\n 'created',\n 'batch-created',\n 'batch-loaded',\n 'canceled',\n];\n\nexport interface ICreateMediaConfig {\n creationType?: 'batch' | 'batch-edit' | 'batch-copy';\n batchId?: number;\n publish?: Array<{ type: string; variant?: string; parameters?: Array<string> }>; // Upon rendering completion, publish to this channel\n notifications?: Array<{ type?: string; route?: string }>; // Will send a notification to the target route upon media status change with the full media object\n mediaRecreateHash?: string;\n ui?: {\n customizationItems?: Array<{ item: string; value: string | boolean }>;\n endScreenActions?: Array<{ action: string; value: string }>;\n forceMediaPreviewBeforeCreate?: 'on_first_render' | 'always';\n theme?: {\n primaryColor?: string;\n };\n }; // Customize the UI\n batchUi?: {\n enableNameEdit?: boolean;\n }; // Customize the batch UI\n}\n\nexport class CreateMediaPage extends BaseFrameController<typeof AVAILABLE_CREATE_MEDIA_EVENTS> {\n constructor(\n spawnElement: string,\n STAuthToken: string | false,\n templateId: number,\n companyId: number,\n config: ICreateMediaConfig = {}\n ) {\n const page = `/integration`;\n\n super(spawnElement, STAuthToken, page, JSON.stringify(config), AVAILABLE_CREATE_MEDIA_EVENTS, {\n companyId: `${companyId}`,\n templateId: `${templateId}`,\n });\n }\n}\n","import { BaseFrameController } from './BaseFrameController';\n\nexport class CrmAnalyticsPage extends BaseFrameController<['loaded']> {\n constructor(spawnElement: string, STAuthToken: string | false, templateId: number, campaignId: number, config?) {\n const page = `/campaigns/${campaignId}/templates/${templateId}`;\n\n super(spawnElement, STAuthToken, page, JSON.stringify(config), ['loaded']);\n }\n}\n"],"names":["root","factory","exports","module","require","define","amd","this","__WEBPACK_EXTERNAL_MODULE__731__","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","d","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","value","BaseFrameController","constructor","spawnElement","authToken","uri","config","availableEvents","extraSearchParams","_eventListeners","_readyForToken","_readyForTokenCb","_jwtToken","setJwtToken","_receiveMessage","e","origin","_url","messagePayload","JSON","parse","data","forEach","event","cb","eventPayload","omit","error","console","URL","window","APP_URL","searchParams","no_navigation","auth_token","auth_via_message","push","set","_init","includes","document","readyState","_spawn","addEventListener","iframe","createElement","src","toString","style","width","height","position","border","querySelector","appendChild","_frame","_initiatePageListeners","on","sendMessage","message","contentWindow","postMessage","targetOrigin","token","type","destroy","removeEventListener","parentElement","removeChild","AVAILABLE_CREATE_MEDIA_EVENTS","CreateMediaPage","STAuthToken","templateId","companyId","super","stringify","CrmAnalyticsPage","campaignId"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,EAAQG,QAAQ,cACR,mBAAXC,QAAyBA,OAAOC,IAC9CD,OAAO,CAAC,aAAcJ,GACI,iBAAZC,QACdA,QAAQ,kCAAoCD,EAAQG,QAAQ,cAE5DJ,EAAK,kCAAoCC,EAAQD,EAAQ,EAC1D,CATD,CASGO,MAAM,SAASC,GAClB,O,+C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,MAG1FlD,KAAKoC,gBAAgByB,KAAK,CACxBX,QACAC,OAGKnD,IACT,CAEOmF,YAAYC,GAGjB,OAFApF,KAAKgF,OAAOK,cAAcC,YAAYF,EAAS,CAAEG,aAAcvF,KAAK4C,KAAKD,SAElE3C,IACT,CAEOwC,YAAYgD,GAOjB,OANKxF,KAAKqC,eAGRrC,KAAKmF,YAAY,CAAEM,KAAM,YAAaD,UAFtCxF,KAAKuC,UAAYiD,EAKZxF,IACT,CAEO0F,UACL,GAAK1F,KAAKgF,OAAV,CAIAtD,OAAOiE,oBAAoB,UAAW3F,KAAKyC,iBAE3CzC,KAAKoC,gBAAkB,GAEvB,IACEpC,KAAKgF,OAAOY,cAAcC,YAAY7F,KAAKgF,O,CAC3C,MAAO1B,GAAO,C,CAClB,EC5IK,MAAMwC,EAAoG,CAC/G,SACA,UACA,gBACA,eACA,YAsBK,MAAMC,UAAwBnE,EACnCC,YACEC,EACAkE,EACAC,EACAC,EACAjE,EAA6B,CAAC,EAC9BkE,GAIA,IAAIC,EAAO,GAGTA,EALe3E,IAAc4E,WAAW,yBAKjC,aAAaF,GAAY,kBAEzB,eAGTG,MAAMxE,EAAckE,EAAaI,EAAMtD,KAAKyD,UAAUtE,GAAS6D,EAA+B,CAC5FI,UAAW,GAAGA,IACdD,WAAY,GAAGA,KAEnB,EClDK,MAAMO,UAAyB5E,EACpCC,YACEC,EACAkE,EACAC,EACAQ,EACAxE,EACAkE,GAEA,MAAMO,EAAWjF,IAAc4E,WAAW,yBAE1C,IAAID,EAAO,GAGTA,EADED,GAAYO,EACP,aAAaP,GAAY,iBAAiBM,eAAwBR,IAElE,cAAcQ,eAAwBR,IAG/CK,MAAMxE,EAAckE,EAAaI,EAAMtD,KAAKyD,UAAUtE,GAAS,CAAC,UAClE,E","sources":["webpack://@storyteq/platform-integration/webpack/universalModuleDefinition","webpack://@storyteq/platform-integration/external umd {\"commonjs\":\"lodash-es\",\"commonjs2\":\"lodash-es\",\"amd\":\"lodash-es\",\"root\":\"_\"}","webpack://@storyteq/platform-integration/webpack/bootstrap","webpack://@storyteq/platform-integration/webpack/runtime/define property getters","webpack://@storyteq/platform-integration/webpack/runtime/hasOwnProperty shorthand","webpack://@storyteq/platform-integration/webpack/runtime/make namespace object","webpack://@storyteq/platform-integration/./src/get-frame-url.ts","webpack://@storyteq/platform-integration/./src/classes/BaseFrameController.ts","webpack://@storyteq/platform-integration/./src/classes/CreateMediaPage.ts","webpack://@storyteq/platform-integration/./src/classes/CrmAnalyticsPage.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"lodash-es\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"lodash-es\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"@storyteq/platform-integration\"] = factory(require(\"lodash-es\"));\n\telse\n\t\troot[\"@storyteq/platform-integration\"] = factory(root[\"_\"]);\n})(this, function(__WEBPACK_EXTERNAL_MODULE__731__) {\nreturn ","module.exports = __WEBPACK_EXTERNAL_MODULE__731__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = function(exports, definition) {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }","// define __esModule on exports\n__webpack_require__.r = function(exports) {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export function getFrameUrl() {\n return window.APP_URL ?? 'https://platform.storyteq.com';\n}\n","import { forEach, omit } from 'lodash-es';\nimport { getFrameUrl } from '../get-frame-url';\nimport { OneOf } from '../interfaces/one-of.interface';\n\nexport class BaseFrameController<T extends Array<string>> {\n private _url: URL;\n private _eventListeners: Array<{ event: string; cb: (data: unknown) => void }> = [];\n private _readyForToken = false;\n private _jwtToken: string;\n private _frame: HTMLIFrameElement;\n\n private _readyForTokenCb = () => {\n this._readyForToken = true;\n\n if (this._jwtToken) {\n this.setJwtToken(this._jwtToken);\n this._jwtToken = '';\n }\n };\n\n constructor(\n public readonly spawnElement: string,\n public readonly authToken: string | false,\n uri: string,\n config: string,\n public readonly availableEvents: T,\n extraSearchParams: Record<string, string> = {}\n ) {\n this._url = new URL(uri, getFrameUrl());\n\n const searchParams: Record<string, string> = {\n no_navigation: 'true',\n config: config,\n ...extraSearchParams,\n };\n\n if (authToken) {\n searchParams.auth_token = authToken;\n } else {\n searchParams.auth_via_message = '';\n\n this._eventListeners.push({ event: 'ready_for_token', cb: this._readyForTokenCb });\n }\n\n forEach(searchParams, (value: string, key: string) => {\n this._url.searchParams.set(key, value);\n });\n\n this._init();\n }\n\n private _init(): void {\n if (!['interactive', 'complete'].includes(document.readyState)) {\n document.addEventListener('readystatechange', () => {\n if (['interactive', 'complete'].includes(document.readyState)) this._spawn();\n });\n } else this._spawn();\n }\n\n private _spawn(): void {\n const iframe: HTMLIFrameElement = document.createElement('iframe');\n\n iframe.src = this._url.toString();\n iframe.style.width = '100%';\n iframe.style.height = '100%';\n iframe.style.position = 'absolute';\n iframe.style.border = 'none';\n\n const spawnElement: HTMLElement = document.querySelector(this.spawnElement);\n\n if (!spawnElement) {\n console.error(`[Storyteq platform integration] Failed to find target element ${this.spawnElement}`);\n }\n\n spawnElement.style.position = 'relative';\n spawnElement.appendChild(iframe);\n\n this._frame = iframe;\n\n this._initiatePageListeners();\n }\n\n private _receiveMessage = (e: MessageEvent) => {\n if (e.origin === this._url.origin) {\n try {\n const messagePayload = JSON.parse(e.data);\n\n this._eventListeners.forEach(({ event, cb }) => {\n const eventPayload = omit(messagePayload, ['event']);\n\n if (event === messagePayload.event) cb(eventPayload);\n });\n } catch (error) {\n console.error('[Storyteq platform integration] Failed to parse incoming frame message;', e.data);\n }\n }\n };\n\n private _initiatePageListeners(): void {\n window.addEventListener('message', this._receiveMessage, false);\n }\n\n public on(event: OneOf<T>, cb: (data: unknown) => void): this {\n if (!this.availableEvents.includes(event)) {\n console.error(`[Storyteq platform integration] Trying to listen to unsupported event \"${event}\"`);\n }\n\n this._eventListeners.push({\n event,\n cb,\n });\n\n return this;\n }\n\n public sendMessage(message: any): this {\n this._frame.contentWindow.postMessage(message, { targetOrigin: this._url.origin });\n\n return this;\n }\n\n public setJwtToken(token: string): this {\n if (!this._readyForToken) {\n this._jwtToken = token;\n } else {\n this.sendMessage({ type: 'JWT_TOKEN', token });\n }\n\n return this;\n }\n\n public destroy(): void {\n if (!this._frame) {\n return;\n }\n\n window.removeEventListener('message', this._receiveMessage);\n\n this._eventListeners = [];\n\n try {\n this._frame.parentElement.removeChild(this._frame);\n } catch (error) {}\n }\n}\n","import { BaseFrameController } from './BaseFrameController';\nimport { getFrameUrl } from '../get-frame-url';\n\nexport const AVAILABLE_CREATE_MEDIA_EVENTS: ['loaded', 'created', 'batch-created', 'batch-loaded', 'canceled'] = [\n 'loaded',\n 'created',\n 'batch-created',\n 'batch-loaded',\n 'canceled',\n];\n\nexport interface ICreateMediaConfig {\n creationType?: 'batch' | 'batch-edit' | 'batch-copy';\n batchId?: number;\n publish?: Array<{ type: string; variant?: string; parameters?: Array<string> }>; // Upon rendering completion, publish to this channel\n notifications?: Array<{ type?: string; route?: string }>; // Will send a notification to the target route upon media status change with the full media object\n mediaRecreateHash?: string;\n ui?: {\n customizationItems?: Array<{ item: string; value: string | boolean }>;\n endScreenActions?: Array<{ action: string; value: string }>;\n forceMediaPreviewBeforeCreate?: 'on_first_render' | 'always';\n theme?: {\n primaryColor?: string;\n };\n }; // Customize the UI\n batchUi?: {\n enableNameEdit?: boolean;\n }; // Customize the batch UI\n}\n\nexport class CreateMediaPage extends BaseFrameController<typeof AVAILABLE_CREATE_MEDIA_EVENTS> {\n constructor(\n spawnElement: string,\n STAuthToken: string | false,\n templateId: number,\n companyId: number,\n config: ICreateMediaConfig = {},\n clientId?: string\n ) {\n const isNewUrl = getFrameUrl().startsWith('https://app.storyteq.');\n\n let page = '';\n\n if (isNewUrl) {\n page = `/platform/${clientId ?? '_'}/integration`;\n } else {\n page = `/integration`;\n }\n\n super(spawnElement, STAuthToken, page, JSON.stringify(config), AVAILABLE_CREATE_MEDIA_EVENTS, {\n companyId: `${companyId}`,\n templateId: `${templateId}`,\n });\n }\n}\n","import { BaseFrameController } from './BaseFrameController';\nimport { getFrameUrl } from '../get-frame-url';\n\nexport class CrmAnalyticsPage extends BaseFrameController<['loaded']> {\n constructor(\n spawnElement: string,\n STAuthToken: string | false,\n templateId: number,\n campaignId: number,\n config?,\n clientId?: string\n ) {\n const isNewUrl = getFrameUrl().startsWith('https://app.storyteq.');\n\n let page = '';\n\n if (clientId || isNewUrl) {\n page = `/platform/${clientId ?? '_'}/campaigns/${campaignId}/templates/${templateId}`;\n } else {\n page = `/campaigns/${campaignId}/templates/${templateId}`;\n }\n\n super(spawnElement, STAuthToken, page, JSON.stringify(config), ['loaded']);\n }\n}\n"],"names":["root","factory","exports","module","require","define","amd","this","__WEBPACK_EXTERNAL_MODULE__731__","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","d","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","value","getFrameUrl","window","APP_URL","BaseFrameController","constructor","spawnElement","authToken","uri","config","availableEvents","extraSearchParams","_eventListeners","_readyForToken","_readyForTokenCb","_jwtToken","setJwtToken","_receiveMessage","e","origin","_url","messagePayload","JSON","parse","data","forEach","event","cb","eventPayload","omit","error","console","URL","searchParams","no_navigation","auth_token","auth_via_message","push","set","_init","includes","document","readyState","_spawn","addEventListener","iframe","createElement","src","toString","style","width","height","position","border","querySelector","appendChild","_frame","_initiatePageListeners","on","sendMessage","message","contentWindow","postMessage","targetOrigin","token","type","destroy","removeEventListener","parentElement","removeChild","AVAILABLE_CREATE_MEDIA_EVENTS","CreateMediaPage","STAuthToken","templateId","companyId","clientId","page","startsWith","super","stringify","CrmAnalyticsPage","campaignId","isNewUrl"],"sourceRoot":""}
|
package/package.json
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyteq/platform-integration",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9-beta",
|
|
4
4
|
"description": "Integrate with views from the Storyteq platform",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
7
7
|
"packageManager": "pnpm@8.15.6",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "webpack --config webpack/webpack.config.prod.js",
|
|
10
|
-
"start": "webpack-dev-server --open --config webpack/webpack.config.dev.js",
|
|
11
|
-
"release": "standard-version",
|
|
12
|
-
"prepack": "pnpm run build",
|
|
13
|
-
"lint": "eslint src",
|
|
14
|
-
"prepare": "pnpm run build"
|
|
15
|
-
},
|
|
16
8
|
"keywords": [
|
|
17
9
|
"storyteq"
|
|
18
10
|
],
|
|
@@ -40,5 +32,11 @@
|
|
|
40
32
|
},
|
|
41
33
|
"dependencies": {
|
|
42
34
|
"lodash-es": "^4.17.21"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "webpack --config webpack/webpack.config.prod.js",
|
|
38
|
+
"start": "webpack-dev-server --open --config webpack/webpack.config.dev.js",
|
|
39
|
+
"release": "standard-version",
|
|
40
|
+
"lint": "eslint src"
|
|
43
41
|
}
|
|
44
|
-
}
|
|
42
|
+
}
|