diff --git a/package.json b/package.json index acdd6269..dd07cb54 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "skyflow-js", "preferGlobal": true, "analyze": false, - "version": "2.7.4", + "version": "2.7.4-dev.81aa0e9", "author": "Skyflow", "description": "Skyflow JavaScript SDK", "homepage": "https://github.com/skyflowapi/skyflow-js", diff --git a/src/core/external/collect/compose-collect-container.ts b/src/core/external/collect/compose-collect-container.ts index 735f79ec..a52484ed 100644 --- a/src/core/external/collect/compose-collect-container.ts +++ b/src/core/external/collect/compose-collect-container.ts @@ -461,20 +461,22 @@ class ComposableContainer extends Container { reject(err); }); window.addEventListener('message', (event) => { - if (event.data?.type + if (event?.origin === properties.IFRAME_SECURE_ORIGIN) { + if (event?.data?.type === ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_RESPONSE + this.#containerId) { - const data = event.data.data; - if (!data || data?.error) { - printLog(`${JSON.stringify(data?.error)}`, MessageType.ERROR, this.#context.logLevel); - reject(data?.error); - } else if (data?.records) { - printLog(parameterizedString(logs.infoLogs.COLLECT_SUBMIT_SUCCESS, CLASS_NAME), - MessageType.LOG, - this.#context.logLevel); - resolve(data); - } else { - printLog(`${JSON.stringify(data)}`, MessageType.ERROR, this.#context.logLevel); - reject(data); + const data = event.data.data; + if (!data || data?.error) { + printLog(`${JSON.stringify(data?.error)}`, MessageType.ERROR, this.#context.logLevel); + reject(data?.error); + } else if (data?.records) { + printLog(parameterizedString(logs.infoLogs.COLLECT_SUBMIT_SUCCESS, CLASS_NAME), + MessageType.LOG, + this.#context.logLevel); + resolve(data); + } else { + printLog(`${JSON.stringify(data)}`, MessageType.ERROR, this.#context.logLevel); + reject(data); + } } } }); @@ -546,20 +548,22 @@ class ComposableContainer extends Container { errorMessages: this.#customErrorMessages, }); window.addEventListener('message', (event) => { - if (event.data?.type + if (event?.origin === properties.IFRAME_SECURE_ORIGIN) { + if (event.data?.type === ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_FILE_CALL_RESPONSE + this.#containerId) { - const data = event.data.data; - if (!data || data?.error) { - printLog(`${JSON.stringify(data?.error)}`, MessageType.ERROR, this.#context.logLevel); - reject(data?.error); - } else if (data?.fileUploadResponse) { - printLog(parameterizedString(logs.infoLogs.COLLECT_SUBMIT_SUCCESS, CLASS_NAME), - MessageType.LOG, - this.#context.logLevel); - resolve(data); - } else { - printLog(`${JSON.stringify(data)}`, MessageType.ERROR, this.#context.logLevel); - reject(data); + const data = event.data.data; + if (!data || data?.error) { + printLog(`${JSON.stringify(data?.error)}`, MessageType.ERROR, this.#context.logLevel); + reject(data?.error); + } else if (data?.fileUploadResponse) { + printLog(parameterizedString(logs.infoLogs.COLLECT_SUBMIT_SUCCESS, CLASS_NAME), + MessageType.LOG, + this.#context.logLevel); + resolve(data); + } else { + printLog(`${JSON.stringify(data)}`, MessageType.ERROR, this.#context.logLevel); + reject(data); + } } } }); diff --git a/src/core/external/reveal/composable-reveal-container.ts b/src/core/external/reveal/composable-reveal-container.ts index ed22f59c..864317ac 100644 --- a/src/core/external/reveal/composable-reveal-container.ts +++ b/src/core/external/reveal/composable-reveal-container.ts @@ -376,23 +376,25 @@ class ComposableRevealContainer extends Container { ); window?.addEventListener('message', (event) => { - if (event?.data?.type + if (event?.origin === properties.IFRAME_SECURE_ORIGIN) { + if (event?.data?.type === ELEMENT_EVENTS_TO_IFRAME.REVEAL_RESPONSE_READY + this.#containerId) { - const revealData = event?.data?.data; - if (revealData?.errors) { - printLog( - parameterizedString(logs?.errorLogs?.FAILED_REVEAL), - MessageType.ERROR, - this.#context?.logLevel, - ); - reject(revealData); - } else { - printLog( - parameterizedString(logs?.infoLogs?.REVEAL_SUBMIT_SUCCESS, CLASS_NAME), - MessageType.LOG, - this.#context?.logLevel, - ); - resolve(revealData); + const revealData = event?.data?.data; + if (revealData?.errors) { + printLog( + parameterizedString(logs?.errorLogs?.FAILED_REVEAL), + MessageType.ERROR, + this.#context?.logLevel, + ); + reject(revealData); + } else { + printLog( + parameterizedString(logs?.infoLogs?.REVEAL_SUBMIT_SUCCESS, CLASS_NAME), + MessageType.LOG, + this.#context?.logLevel, + ); + resolve(revealData); + } } } }); @@ -436,39 +438,45 @@ class ComposableRevealContainer extends Container { MessageType.LOG, this.#context.logLevel); window.addEventListener('message', (messagEevent) => { - if (messagEevent?.data?.type === ELEMENT_EVENTS_TO_CLIENT.MOUNTED + if (messagEevent?.origin === properties.IFRAME_SECURE_ORIGIN) { + if (messagEevent?.data?.type === ELEMENT_EVENTS_TO_CLIENT.MOUNTED + this.#containerId) { - this.#emitEvent( - ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_REVEAL + this.#containerId, { - data: { - type: REVEAL_TYPES.REVEAL, - containerId: this.#containerId, - elementIds, + this.#emitEvent( + ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_REVEAL + this.#containerId, { + data: { + type: REVEAL_TYPES.REVEAL, + containerId: this.#containerId, + elementIds, + }, + clientConfig: { + vaultURL: this.#metaData.clientJSON.config.vaultURL, + vaultID: this.#metaData.clientJSON.config.vaultID, + authToken, + }, + context: this.#context, }, - clientConfig: { - vaultURL: this.#metaData.clientJSON.config.vaultURL, - vaultID: this.#metaData.clientJSON.config.vaultID, - authToken, - }, - context: this.#context, - }, - ); - window.addEventListener('message', (event) => { - if (event?.data?.type + ); + window.addEventListener('message', (event) => { + if (event?.origin === properties.IFRAME_SECURE_ORIGIN) { + if (event?.data?.type === ELEMENT_EVENTS_TO_IFRAME.REVEAL_RESPONSE_READY + this.#containerId) { - const revealData = event?.data?.data; - if (revealData?.errors) { - printLog(parameterizedString(logs.errorLogs.FAILED_REVEAL), - MessageType.ERROR, this.#context.logLevel); - reject(revealData); - } else { - printLog(parameterizedString(logs.infoLogs.REVEAL_SUBMIT_SUCCESS, CLASS_NAME), - MessageType.LOG, - this.#context.logLevel); - resolve(revealData); + const revealData = event?.data?.data; + if (revealData?.errors) { + printLog(parameterizedString(logs.errorLogs.FAILED_REVEAL), + MessageType.ERROR, this.#context.logLevel); + reject(revealData); + } else { + printLog( + parameterizedString(logs.infoLogs.REVEAL_SUBMIT_SUCCESS, CLASS_NAME), + MessageType.LOG, + this.#context.logLevel, + ); + resolve(revealData); + } + } } - } - }); + }); + } } }); }).catch((err:any) => { diff --git a/src/core/external/reveal/reveal-container.ts b/src/core/external/reveal/reveal-container.ts index d2ab586f..b17008b8 100644 --- a/src/core/external/reveal/reveal-container.ts +++ b/src/core/external/reveal/reveal-container.ts @@ -270,28 +270,30 @@ class RevealContainer extends Container { } #emitRevealRequest(resolve, reject) { - bus.emit( - ELEMENT_EVENTS_TO_IFRAME.REVEAL_CALL_REQUESTS + this.#metaData.uuid, - { - type: REVEAL_TYPES.REVEAL, - records: this.#revealRecords, - containerId: this.#containerId, - errorMessages: this.#customErrorMessages, - }, - (revealData: any) => { - this.#mountedRecords = []; - if (revealData.error) { - printLog(parameterizedString(logs.errorLogs.FAILED_REVEAL), - MessageType.ERROR, this.#context.logLevel); - reject(revealData.error); - } else { - printLog(parameterizedString(logs.infoLogs.REVEAL_SUBMIT_SUCCESS, CLASS_NAME), - MessageType.LOG, - this.#context.logLevel); - resolve(revealData); - } - }, - ); + bus + .target(properties.IFRAME_SECURE_ORIGIN) + .emit( + ELEMENT_EVENTS_TO_IFRAME.REVEAL_CALL_REQUESTS + this.#metaData.uuid, + { + type: REVEAL_TYPES.REVEAL, + records: this.#revealRecords, + containerId: this.#containerId, + errorMessages: this.#customErrorMessages, + }, + (revealData: any) => { + this.#mountedRecords = []; + if (revealData.error) { + printLog(parameterizedString(logs.errorLogs.FAILED_REVEAL), + MessageType.ERROR, this.#context.logLevel); + reject(revealData.error); + } else { + printLog(parameterizedString(logs.infoLogs.REVEAL_SUBMIT_SUCCESS, CLASS_NAME), + MessageType.LOG, + this.#context.logLevel); + resolve(revealData); + } + }, + ); } } export default RevealContainer; diff --git a/src/core/external/reveal/reveal-element.ts b/src/core/external/reveal/reveal-element.ts index e8d8c3d3..d926c800 100644 --- a/src/core/external/reveal/reveal-element.ts +++ b/src/core/external/reveal/reveal-element.ts @@ -198,7 +198,7 @@ class RevealElement extends SkyflowElement { loglevel); validateRenderElementRecord(this.#recordData); bus - // .target(properties.IFRAME_SECURE_ORIGIN) + .target(properties.IFRAME_SECURE_ORIGIN) .emit( ELEMENT_EVENTS_TO_IFRAME.REVEAL_CALL_REQUESTS + this.#metaData.uuid, { @@ -250,7 +250,7 @@ class RevealElement extends SkyflowElement { .target(properties.IFRAME_SECURE_ORIGIN) .on(ELEMENT_EVENTS_TO_IFRAME.SKYFLOW_FRAME_CONTROLLER_READY + this.#metaData.uuid, () => { bus - // .target(properties.IFRAME_SECURE_ORIGIN) + .target(properties.IFRAME_SECURE_ORIGIN) .emit( ELEMENT_EVENTS_TO_IFRAME.REVEAL_CALL_REQUESTS + this.#metaData.uuid, { diff --git a/src/core/external/skyflow-container.ts b/src/core/external/skyflow-container.ts index b7b9f33d..3604ffdf 100644 --- a/src/core/external/skyflow-container.ts +++ b/src/core/external/skyflow-container.ts @@ -103,7 +103,7 @@ class SkyflowContainer { validateDetokenizeInput(detokenizeInput); bus - // .target(properties.IFRAME_SECURE_ORIGIN) + .target(properties.IFRAME_SECURE_ORIGIN) .emit( ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, { @@ -135,17 +135,19 @@ class SkyflowContainer { bus .target(properties.IFRAME_SECURE_ORIGIN) .on(ELEMENT_EVENTS_TO_IFRAME.PUREJS_FRAME_READY + this.#containerId, () => { - bus.emit( - ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, - { - type: PUREJS_TYPES.DETOKENIZE, - records: detokenizeInput.records, - }, - (revealData: any) => { - if (revealData.error) reject(revealData.error); - else resolve(revealData); - }, - ); + bus + .target(properties.IFRAME_SECURE_ORIGIN) + .emit( + ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, + { + type: PUREJS_TYPES.DETOKENIZE, + records: detokenizeInput.records, + }, + (revealData: any) => { + if (revealData.error) reject(revealData.error); + else resolve(revealData); + }, + ); }); printLog(parameterizedString(logs.infoLogs.EMIT_PURE_JS_REQUEST, CLASS_NAME, PUREJS_TYPES.DETOKENIZE), @@ -176,7 +178,7 @@ class SkyflowContainer { } validateInsertRecords(records, options); bus - // .target(properties.IFRAME_SECURE_ORIGIN) + .target(properties.IFRAME_SECURE_ORIGIN) .emit( ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, { @@ -221,20 +223,22 @@ class SkyflowContainer { bus .target(properties.IFRAME_SECURE_ORIGIN) .on(ELEMENT_EVENTS_TO_IFRAME.PUREJS_FRAME_READY + this.#containerId, () => { - bus.emit( - ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, - { - type: PUREJS_TYPES.INSERT, - records, - options, - }, - (insertedData: any) => { - if (insertedData.error) { - printLog(`${JSON.stringify(insertedData.error)}`, MessageType.ERROR, this.#context.logLevel); - reject(insertedData.error); - } else resolve(insertedData); - }, - ); + bus + .target(properties.IFRAME_SECURE_ORIGIN) + .emit( + ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, + { + type: PUREJS_TYPES.INSERT, + records, + options, + }, + (insertedData: any) => { + if (insertedData.error) { + printLog(`${JSON.stringify(insertedData.error)}`, MessageType.ERROR, this.#context.logLevel); + reject(insertedData.error); + } else resolve(insertedData); + }, + ); }); printLog(parameterizedString(logs.infoLogs.EMIT_PURE_JS_REQUEST, CLASS_NAME, PUREJS_TYPES.INSERT), @@ -257,6 +261,7 @@ class SkyflowContainer { validateUpdateRecord(record, options); bus + .target(properties.IFRAME_SECURE_ORIGIN) .emit( ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, { @@ -291,20 +296,22 @@ class SkyflowContainer { bus .target(properties.IFRAME_SECURE_ORIGIN) .on(ELEMENT_EVENTS_TO_IFRAME.PUREJS_FRAME_READY + this.#containerId, () => { - bus.emit( - ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, - { - type: PUREJS_TYPES.UPDATE, - record, - options, - }, - (updatedData: any) => { - if (updatedData.error) { - printLog(`${JSON.stringify(updatedData.error)}`, MessageType.ERROR, this.#context.logLevel); - reject(updatedData.error); - } else resolve(updatedData); - }, - ); + bus + .target(properties.IFRAME_SECURE_ORIGIN) + .emit( + ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, + { + type: PUREJS_TYPES.UPDATE, + record, + options, + }, + (updatedData: any) => { + if (updatedData.error) { + printLog(`${JSON.stringify(updatedData.error)}`, MessageType.ERROR, this.#context.logLevel); + reject(updatedData.error); + } else resolve(updatedData); + }, + ); }); printLog(parameterizedString(logs.infoLogs.EMIT_PURE_JS_REQUEST, CLASS_NAME, PUREJS_TYPES.UPDATE), @@ -328,7 +335,7 @@ class SkyflowContainer { validateGetByIdInput(getByIdInput); bus - // .target(properties.IFRAME_SECURE_ORIGIN) + .target(properties.IFRAME_SECURE_ORIGIN) .emit( ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, { @@ -361,17 +368,19 @@ class SkyflowContainer { bus .target(properties.IFRAME_SECURE_ORIGIN) .on(ELEMENT_EVENTS_TO_IFRAME.PUREJS_FRAME_READY + this.#containerId, () => { - bus.emit( - ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, - { - type: PUREJS_TYPES.GET_BY_SKYFLOWID, - records: getByIdInput.records, - }, - (revealData: any) => { - if (revealData.error) reject(revealData.error); - else resolve(revealData); - }, - ); + bus + .target(properties.IFRAME_SECURE_ORIGIN) + .emit( + ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, + { + type: PUREJS_TYPES.GET_BY_SKYFLOWID, + records: getByIdInput.records, + }, + (revealData: any) => { + if (revealData.error) reject(revealData.error); + else resolve(revealData); + }, + ); }); printLog(parameterizedString(logs.infoLogs.EMIT_PURE_JS_REQUEST, CLASS_NAME, PUREJS_TYPES.GET_BY_SKYFLOWID), @@ -394,7 +403,7 @@ class SkyflowContainer { this.#context.logLevel); validateGetInput(getInput, options); bus - // .target(properties.IFRAME_SECURE_ORIGIN) + .target(properties.IFRAME_SECURE_ORIGIN) .emit( ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, { @@ -428,18 +437,20 @@ class SkyflowContainer { bus .target(properties.IFRAME_SECURE_ORIGIN) .on(ELEMENT_EVENTS_TO_IFRAME.PUREJS_FRAME_READY + this.#containerId, () => { - bus.emit( - ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, - { - type: PUREJS_TYPES.GET, - records: getInput.records, - options, - }, - (revealData: any) => { - if (revealData.error) reject(revealData.error); - else resolve(revealData); - }, - ); + bus + .target(properties.IFRAME_SECURE_ORIGIN) + .emit( + ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, + { + type: PUREJS_TYPES.GET, + records: getInput.records, + options, + }, + (revealData: any) => { + if (revealData.error) reject(revealData.error); + else resolve(revealData); + }, + ); }); printLog(parameterizedString(logs.infoLogs.EMIT_PURE_JS_REQUEST, CLASS_NAME, PUREJS_TYPES.GET), @@ -464,7 +475,7 @@ class SkyflowContainer { validateDeleteRecords(records, options); bus - // .target(properties.IFRAME_SECURE_ORIGIN) + .target(properties.IFRAME_SECURE_ORIGIN) .emit( ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, { @@ -501,20 +512,22 @@ class SkyflowContainer { bus .target(properties.IFRAME_SECURE_ORIGIN) .on(ELEMENT_EVENTS_TO_IFRAME.PUREJS_FRAME_READY + this.#containerId, () => { - bus.emit( - ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, - { - type: PUREJS_TYPES.DELETE, - records, - options, - }, - (deletedData: any) => { - if (deletedData.error) { - printLog(`${JSON.stringify(deletedData.error)}`, MessageType.ERROR, this.#context.logLevel); - reject(deletedData.error); - } else resolve(deletedData); - }, - ); + bus + .target(properties.IFRAME_SECURE_ORIGIN) + .emit( + ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST + this.#containerId, + { + type: PUREJS_TYPES.DELETE, + records, + options, + }, + (deletedData: any) => { + if (deletedData.error) { + printLog(`${JSON.stringify(deletedData.error)}`, MessageType.ERROR, this.#context.logLevel); + reject(deletedData.error); + } else resolve(deletedData); + }, + ); }); printLog(parameterizedString(logs.infoLogs.EMIT_PURE_JS_REQUEST, CLASS_NAME, PUREJS_TYPES.DELETE), diff --git a/src/core/internal/composable-frame-element-init.ts b/src/core/internal/composable-frame-element-init.ts index 3f60db79..07da2cd5 100644 --- a/src/core/internal/composable-frame-element-init.ts +++ b/src/core/internal/composable-frame-element-init.ts @@ -62,38 +62,69 @@ export default class RevealComposableFrameElementInit { this.createContainerDiv(this.group); window?.addEventListener('message', (event) => { - if (event?.data?.name === ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_REVEAL + if (event?.origin === this.clientMetaData.clientDomain) { + if (event?.data?.name === ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_REVEAL + this.containerId && event?.data?.data?.type === REVEAL_TYPES.REVEAL) { - this.#context = event?.data?.context; - const data = event?.data?.data ?? {}; - const elementIds = data?.elementIds ?? []; - const revealDataInput: IRevealRecordComposable[] = []; - this.#client = new Client(event?.data?.clientConfig ?? {}, { - uuid: '', - clientDomain: '', - }); - this.#client.setErrorMessages(event?.data?.errorMessages || {}); - - elementIds?.forEach((element) => { - this.revealFrameList?.forEach((revealFrame) => { - const data2 = revealFrame?.getData?.(); - if (data2?.name === element?.frameId) { - if (data2 && !data2?.skyflowID) { - const revealRecord: IRevealRecordComposable = { - token: data2?.token ?? '', - redaction: data2?.redaction, - iframeName: data2?.name ?? '', - }; - revealDataInput?.push(revealRecord); + this.#context = event?.data?.context; + const data = event?.data?.data ?? {}; + const elementIds = data?.elementIds ?? []; + const revealDataInput: IRevealRecordComposable[] = []; + this.#client = new Client(event?.data?.clientConfig ?? {}, { + uuid: '', + clientDomain: '', + }); + this.#client.setErrorMessages(event?.data?.errorMessages || {}); + + elementIds?.forEach((element) => { + this.revealFrameList?.forEach((revealFrame) => { + const data2 = revealFrame?.getData?.(); + if (data2?.name === element?.frameId) { + if (data2 && !data2?.skyflowID) { + const revealRecord: IRevealRecordComposable = { + token: data2?.token ?? '', + redaction: data2?.redaction, + iframeName: data2?.name ?? '', + }; + revealDataInput?.push(revealRecord); + } } - } + }); }); - }); - this.revealData(revealDataInput, this.containerId, event?.data?.clientConfig?.authToken) - ?.then((revealResponse: any) => { - if (revealResponse?.records?.length > 0) { - const formattedRecord = formatRecordsForClientComposable(revealResponse); + this.revealData(revealDataInput, this.containerId, event?.data?.clientConfig?.authToken) + ?.then((revealResponse: any) => { + if (revealResponse?.records?.length > 0) { + const formattedRecord = formatRecordsForClientComposable(revealResponse); + window?.parent?.postMessage( + { + type: ELEMENT_EVENTS_TO_IFRAME.REVEAL_RESPONSE_READY + this.containerId, + data: formattedRecord, + }, + this.clientMetaData?.clientDomain, + ); + + revealResponse?.records?.forEach((record: any) => { + this.revealFrameList?.forEach((revealFrame) => { + if (revealFrame?.getData()?.name === record?.frameId) { + revealFrame?.responseUpdate?.(record); + } + }); + }); + } + + window?.parent?.postMessage( + { + type: ELEMENT_EVENTS_TO_IFRAME.HEIGHT_CALLBACK + window?.name, + data: { + height: this.rootDiv?.scrollHeight ?? 0, + name: window?.name, + }, + }, + this.clientMetaData?.clientDomain, + ); + }) + ?.catch((error) => { + const formattedRecord = formatRecordsForClientComposable(error); window?.parent?.postMessage( { type: ELEMENT_EVENTS_TO_IFRAME.REVEAL_RESPONSE_READY + this.containerId, @@ -102,63 +133,34 @@ export default class RevealComposableFrameElementInit { this.clientMetaData?.clientDomain, ); - revealResponse?.records?.forEach((record: any) => { + error?.records?.forEach((record: any) => { this.revealFrameList?.forEach((revealFrame) => { if (revealFrame?.getData()?.name === record?.frameId) { revealFrame?.responseUpdate?.(record); } }); }); - } - - window?.parent?.postMessage( - { - type: ELEMENT_EVENTS_TO_IFRAME.HEIGHT_CALLBACK + window?.name, - data: { - height: this.rootDiv?.scrollHeight ?? 0, - name: window?.name, - }, - }, - this.clientMetaData?.clientDomain, - ); - }) - ?.catch((error) => { - const formattedRecord = formatRecordsForClientComposable(error); - window?.parent?.postMessage( - { - type: ELEMENT_EVENTS_TO_IFRAME.REVEAL_RESPONSE_READY + this.containerId, - data: formattedRecord, - }, - this.clientMetaData?.clientDomain, - ); - - error?.records?.forEach((record: any) => { - this.revealFrameList?.forEach((revealFrame) => { - if (revealFrame?.getData()?.name === record?.frameId) { - revealFrame?.responseUpdate?.(record); - } - }); - }); - error?.errors?.forEach((error1: any) => { - this.revealFrameList?.forEach((revealFrame) => { - if (revealFrame?.getData()?.name === error1?.frameId) { - revealFrame?.responseUpdate?.(error1); - } + error?.errors?.forEach((error1: any) => { + this.revealFrameList?.forEach((revealFrame) => { + if (revealFrame?.getData()?.name === error1?.frameId) { + revealFrame?.responseUpdate?.(error1); + } + }); }); - }); - window?.parent?.postMessage( - { - type: ELEMENT_EVENTS_TO_IFRAME.HEIGHT_CALLBACK + window?.name, - data: { - height: this.rootDiv?.scrollHeight ?? 0, - name: window?.name, + window?.parent?.postMessage( + { + type: ELEMENT_EVENTS_TO_IFRAME.HEIGHT_CALLBACK + window?.name, + data: { + height: this.rootDiv?.scrollHeight ?? 0, + name: window?.name, + }, }, - }, - this.clientMetaData?.clientDomain, - ); - }); + this.clientMetaData?.clientDomain, + ); + }); + } } }); @@ -341,30 +343,32 @@ export default class RevealComposableFrameElementInit { ); window?.addEventListener('message', (event) => { - if (event?.data?.name === ELEMENT_EVENTS_TO_CLIENT.HEIGHT + window?.name) { - window?.parent?.postMessage( - { - type: ELEMENT_EVENTS_TO_IFRAME.HEIGHT_CALLBACK + window?.name, - data: { - height: this.rootDiv?.scrollHeight ?? 0, - name: window?.name, + if (event?.origin === this.clientMetaData.clientDomain) { + if (event?.data?.name === ELEMENT_EVENTS_TO_CLIENT.HEIGHT + window?.name) { + window?.parent?.postMessage( + { + type: ELEMENT_EVENTS_TO_IFRAME.HEIGHT_CALLBACK + window?.name, + data: { + height: this.rootDiv?.scrollHeight ?? 0, + name: window?.name, + }, }, - }, - this.clientMetaData?.clientDomain, - ); - } - if (event?.data?.type + this.clientMetaData?.clientDomain, + ); + } + if (event?.data?.type === ELEMENT_EVENTS_TO_IFRAME.HEIGHT_CALLBACK_COMPOSABLE + window?.name) { - window?.parent?.postMessage( - { - type: ELEMENT_EVENTS_TO_IFRAME.HEIGHT_CALLBACK + window?.name, - data: { - height: this.rootDiv?.scrollHeight ?? 0, - name: window?.name, + window?.parent?.postMessage( + { + type: ELEMENT_EVENTS_TO_IFRAME.HEIGHT_CALLBACK + window?.name, + data: { + height: this.rootDiv?.scrollHeight ?? 0, + name: window?.name, + }, }, - }, - this.clientMetaData?.clientDomain, - ); + this.clientMetaData?.clientDomain, + ); + } } }); }; diff --git a/src/core/internal/frame-element-init.ts b/src/core/internal/frame-element-init.ts index 70afa30b..62eb3769 100644 --- a/src/core/internal/frame-element-init.ts +++ b/src/core/internal/frame-element-init.ts @@ -66,7 +66,7 @@ export default class FrameElementInit { this.updateGroupData(); this.createContainerDiv(this.group); bus - // .target(this.clientMetaData.clientDomain) + .target(this.clientMetaData?.clientDomain) .emit(ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CONTAINER + this.containerId, {}, (data: any) => { data.client.config = { ...data.client.config, @@ -78,72 +78,72 @@ export default class FrameElementInit { } private handleCollectCall = (event: MessageEvent) => { - this.iframeFormList.forEach((inputElement) => { - if (inputElement) { - if (inputElement.fieldType + if (event?.origin === this.clientMetaData?.clientDomain) { + this.iframeFormList.forEach((inputElement) => { + if (inputElement) { + if (inputElement.fieldType === ELEMENTS.MULTI_FILE_INPUT.name) { - if (event?.data && event?.data?.name === `${ELEMENT_EVENTS_TO_IFRAME.MULTIPLE_UPLOAD_FILES}:${inputElement.iFrameName}`) { - this.#client = Client.fromJSON(event?.data?.clientConfig); - this.multipleUploadFiles(inputElement, event?.data?.clientConfig, - event?.data?.options, event?.data?.errorMessages) - ?.then((response: any) => { - window?.parent.postMessage({ - type: `${ELEMENT_EVENTS_TO_IFRAME.MULTIPLE_UPLOAD_FILES_RESPONSE}:${inputElement.iFrameName}`, - data: response, - }, this.clientMetaData?.clientDomain); - }).catch((error) => { - window?.parent.postMessage({ - type: `${ELEMENT_EVENTS_TO_IFRAME.MULTIPLE_UPLOAD_FILES_RESPONSE}:${inputElement.iFrameName}`, - data: error, - }, this.clientMetaData?.clientDomain); - }); + if (event?.data && event?.data?.name === `${ELEMENT_EVENTS_TO_IFRAME.MULTIPLE_UPLOAD_FILES}:${inputElement.iFrameName}`) { + this.#client = Client.fromJSON(event?.data?.clientConfig); + this.multipleUploadFiles(inputElement, event?.data?.clientConfig, + event?.data?.options, event?.data?.errorMessages) + ?.then((response: any) => { + window?.parent.postMessage({ + type: `${ELEMENT_EVENTS_TO_IFRAME.MULTIPLE_UPLOAD_FILES_RESPONSE}:${inputElement.iFrameName}`, + data: response, + }, this.clientMetaData?.clientDomain); + }).catch((error) => { + window?.parent.postMessage({ + type: `${ELEMENT_EVENTS_TO_IFRAME.MULTIPLE_UPLOAD_FILES_RESPONSE}:${inputElement.iFrameName}`, + data: error, + }, this.clientMetaData?.clientDomain); + }); + } } } - } - }); + }); - // if (event.origin === this.clientMetaData.clientDomain) { - if (event?.data && event?.data?.name === ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_REQUESTS + if (event?.data && event?.data?.name === ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_REQUESTS + this.containerId) { - if (event?.data?.data && event?.data?.data?.type === COLLECT_TYPES.COLLECT) { - this.tokenize(event?.data?.data, event?.data?.clientConfig, event?.data?.errorMessages) - .then((response: any) => { - window?.parent.postMessage({ - type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_RESPONSE + this.containerId, - data: response, - }, this.clientMetaData?.clientDomain); - }) - .catch((error) => { - window?.parent.postMessage({ - type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_RESPONSE + this.containerId, - data: error, - }, this.clientMetaData?.clientDomain); - }); - } else if (event.data.data && event.data.data.type === COLLECT_TYPES.FILE_UPLOAD) { - this.parallelUploadFiles(event.data.data, - event.data.clientConfig, event?.data?.errorMessages) - .then((response: any) => { - window?.parent.postMessage({ - type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_FILE_CALL_RESPONSE + this.containerId, - data: response, - }, this.clientMetaData?.clientDomain); - }) - .catch((error) => { - window?.parent.postMessage({ - type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_FILE_CALL_RESPONSE + this.containerId, - data: error, - }, this.clientMetaData?.clientDomain); - }); + if (event?.data?.data && event?.data?.data?.type === COLLECT_TYPES.COLLECT) { + this.tokenize(event?.data?.data, event?.data?.clientConfig, event?.data?.errorMessages) + .then((response: any) => { + window?.parent.postMessage({ + type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_RESPONSE + this.containerId, + data: response, + }, this.clientMetaData?.clientDomain); + }) + .catch((error) => { + window?.parent.postMessage({ + type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_RESPONSE + this.containerId, + data: error, + }, this.clientMetaData?.clientDomain); + }); + } else if (event.data.data && event.data.data.type === COLLECT_TYPES.FILE_UPLOAD) { + this.parallelUploadFiles(event.data.data, + event.data.clientConfig, event?.data?.errorMessages) + .then((response: any) => { + window?.parent.postMessage({ + type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_FILE_CALL_RESPONSE + this.containerId, + data: response, + }, this.clientMetaData?.clientDomain); + }) + .catch((error) => { + window?.parent.postMessage({ + type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_FILE_CALL_RESPONSE + this.containerId, + data: error, + }, this.clientMetaData?.clientDomain); + }); + } + } + if (event?.data?.name === ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CONTAINER + this.containerId) { + const data = event.data; + data.client.config = { + ...data.client.config, + }; + this.#client = Client.fromJSON(data.client) as any; } } - if (event?.data?.name === ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CONTAINER + this.containerId) { - const data = event.data; - data.client.config = { - ...data.client.config, - }; - this.#client = Client.fromJSON(data.client) as any; - } - // } }; private parallelUploadFiles = (options, config, diff --git a/src/core/internal/skyflow-frame/skyflow-frame-controller.ts b/src/core/internal/skyflow-frame/skyflow-frame-controller.ts index cd28462e..4ccbd908 100644 --- a/src/core/internal/skyflow-frame/skyflow-frame-controller.ts +++ b/src/core/internal/skyflow-frame/skyflow-frame-controller.ts @@ -288,7 +288,7 @@ class SkyflowFrameController { }, ); bus - // .target(this.#clientDomain) + .target(this.#clientDomain) .emit(ELEMENT_EVENTS_TO_IFRAME.PUREJS_FRAME_READY + this.#clientId, {}, (data: any) => { this.#context = data.context; data.client.config = { @@ -356,6 +356,7 @@ class SkyflowFrameController { } }); bus + .target(this.#clientDomain) .emit(ELEMENT_EVENTS_TO_IFRAME.SKYFLOW_FRAME_CONTROLLER_READY + this.#clientId, {}, (data: any) => { this.#context = data.context; diff --git a/src/utils/bus-events/index.ts b/src/utils/bus-events/index.ts index 4cfe1952..31e38d59 100644 --- a/src/utils/bus-events/index.ts +++ b/src/utils/bus-events/index.ts @@ -7,21 +7,25 @@ import properties from '../../properties'; export function getAccessToken(clientId: string) { return new Promise((resolve, reject) => { - bus.emit(ELEMENT_EVENTS_TO_IFRAME.GET_BEARER_TOKEN + clientId, {}, - (data:any) => { - if (data?.error) { - reject(data.error); - } - resolve(data.authToken); - }); + bus + // .target(properties.IFRAME_SECURE_ORIGIN) + .emit(ELEMENT_EVENTS_TO_IFRAME.GET_BEARER_TOKEN + clientId, {}, + (data:any) => { + if (data?.error) { + reject(data.error); + } + resolve(data.authToken); + }); - bus.emit(ELEMENT_EVENTS_TO_IFRAME.GET_BEARER_TOKEN, {}, - (data:any) => { - if (data?.error) { - reject(data.error); - } - resolve(data.authToken); - }); + bus + // .target(properties.IFRAME_SECURE_ORIGIN) + .emit(ELEMENT_EVENTS_TO_IFRAME.GET_BEARER_TOKEN, {}, + (data:any) => { + if (data?.error) { + reject(data.error); + } + resolve(data.authToken); + }); }); } diff --git a/tests/core/external/collect/collect-container.test.js b/tests/core/external/collect/collect-container.test.js index e2b26d58..b2e31fe6 100644 --- a/tests/core/external/collect/collect-container.test.js +++ b/tests/core/external/collect/collect-container.test.js @@ -211,7 +211,8 @@ describe('Collect container', () => { onSpy = jest.spyOn(bus, 'on'); targetSpy.mockReturnValue({ on, - off: jest.fn() + off: jest.fn(), + emit: emitSpy, }); }); @@ -1742,7 +1743,8 @@ describe('iframe cleanup logic', () => { onSpy = jest.spyOn(bus, 'on'); targetSpy.mockReturnValue({ on, - off: jest.fn() + off: jest.fn(), + emit: emitSpy, }); div1 = document.createElement('div'); div2 = document.createElement('div'); diff --git a/tests/core/external/collect/collect-container.test.ts b/tests/core/external/collect/collect-container.test.ts index fb9da2cf..c8a24295 100644 --- a/tests/core/external/collect/collect-container.test.ts +++ b/tests/core/external/collect/collect-container.test.ts @@ -139,6 +139,7 @@ describe("Collect container", () => { targetSpy.mockReturnValue({ on, off: jest.fn(), + emit: emitSpy, }); }); @@ -303,6 +304,7 @@ describe("iframe cleanup logic", () => { targetSpy.mockReturnValue({ on, off: jest.fn(), + emit: emitSpy, }); div1 = document.createElement("div"); div2 = document.createElement("div"); diff --git a/tests/core/external/collect/collect-element.test.js b/tests/core/external/collect/collect-element.test.js index b9f06b84..7c4c0d9b 100644 --- a/tests/core/external/collect/collect-element.test.js +++ b/tests/core/external/collect/collect-element.test.js @@ -135,7 +135,8 @@ describe('collect element', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - off: jest.fn() + off: jest.fn(), + emit: emitSpy, }); }); diff --git a/tests/core/external/collect/collect-element.test.ts b/tests/core/external/collect/collect-element.test.ts index a070cf91..e6a1781a 100644 --- a/tests/core/external/collect/collect-element.test.ts +++ b/tests/core/external/collect/collect-element.test.ts @@ -178,6 +178,7 @@ describe("testing collect element under various scenarios", () => { targetSpy.mockReturnValue({ on, off: jest.fn(), + emit: emitSpy, }); }); diff --git a/tests/core/external/collect/composable-container.test.js b/tests/core/external/collect/composable-container.test.js index 8e06ecb3..e29375b3 100644 --- a/tests/core/external/collect/composable-container.test.js +++ b/tests/core/external/collect/composable-container.test.js @@ -15,6 +15,7 @@ import EventEmitter from '../../../../src/event-emitter'; import { parameterizedString } from '../../../../src/utils/logs-helper'; import { SKYFLOW_FRAME_CONTROLLER_READY } from '../../../../src/core/constants'; import SkyflowError from '../../../../src/libs/skyflow-error'; +import properties from '../../../../src/properties'; const bus = require('framebus'); @@ -193,7 +194,8 @@ describe('test composable container class',()=>{ onSpy = jest.spyOn(bus, 'on'); targetSpy.mockReturnValue({ on, - off: jest.fn() + off: jest.fn(), + emit: emitSpy, }); windowSpy = jest.spyOn(window, "window", "get"); }); @@ -296,6 +298,7 @@ describe('test composable container class',()=>{ const collectPromiseSuccess = container.collect(options); window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, data: { type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_RESPONSE + '1234', // containerId data: {...collectResponse} @@ -307,8 +310,9 @@ describe('test composable container class',()=>{ const collectPromiseError = container.collect(options); - - window.dispatchEvent(new MessageEvent('message', { + + window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, data: { type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_RESPONSE + '1234', // containerId data: { error: "Error occured"} @@ -563,9 +567,11 @@ describe('test composable container class',()=>{ emitterSpy(); setTimeout(()=>{ container.collect(options); - const collectCb = emitSpy.mock.calls[0][2]; - collectCb(collectResponse); - collectCb({ error: 'Error occured' }) + const collectCb = emitSpy.mock.calls[0]?.[2]; + if (collectCb) { + collectCb(collectResponse); + collectCb({ error: 'Error occured' }); + } },200); }); @@ -652,6 +658,7 @@ describe('test composable container class',()=>{ await Promise.resolve('token'); window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, data: { type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_FILE_CALL_RESPONSE + '1234', // containerId data: { fileUploadResponse: [{ skyflow_id: 'id1' }] } @@ -667,20 +674,22 @@ describe('test composable container class',()=>{ await Promise.resolve('token'); window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, data: { type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_FILE_CALL_RESPONSE + '1234', // containerId data: { error: "Error occured"} } })); - + await expect(collectPromiseError).rejects.toEqual("Error occured"); // Test error scenario case 2 - no fileUploadResponse and no error const collectPromiseError2 = container.uploadFiles(options); - + await Promise.resolve('token'); - + window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, data: { type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_FILE_CALL_RESPONSE + '1234', // containerId data: { errors: "Error occured"} diff --git a/tests/core/external/collect/composable-container.test.ts b/tests/core/external/collect/composable-container.test.ts index f2af6f76..cd2ba782 100644 --- a/tests/core/external/collect/composable-container.test.ts +++ b/tests/core/external/collect/composable-container.test.ts @@ -25,6 +25,7 @@ import SkyflowContainer from "../../../../src/core/external/skyflow-container"; import { ContainerType } from "../../../../src/skyflow"; import { Metadata } from "../../../../src/core/internal/internal-types"; import IFrame from "../../../../src/core/external/common/iframe"; +import properties from "../../../../src/properties"; global.ResizeObserver = jest.fn(() => ({ observe: jest.fn(), @@ -184,6 +185,7 @@ describe("test composable container class", () => { targetSpy.mockReturnValue({ on, off: jest.fn(), + emit: emitSpy, }); }); @@ -297,6 +299,7 @@ describe("test composable container class", () => { const collectPromiseSuccess: Promise = container.collect(options); window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, data: { type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_RESPONSE + '1234', // containerId data: {...collectResponse} @@ -308,8 +311,9 @@ describe("test composable container class", () => { const collectPromiseError: Promise = container.collect(options); - - window.dispatchEvent(new MessageEvent('message', { + + window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, data: { type: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_RESPONSE + '1234', // containerId data: { error: "Error occured"} diff --git a/tests/core/external/reveal/reveal-composable-container.test.js b/tests/core/external/reveal/reveal-composable-container.test.js index a5a88a6b..4926b71e 100644 --- a/tests/core/external/reveal/reveal-composable-container.test.js +++ b/tests/core/external/reveal/reveal-composable-container.test.js @@ -12,7 +12,6 @@ import SKYFLOW_ERROR_CODE from "../../../../src/utils/constants"; import { parameterizedString } from "../../../../src/utils/logs-helper"; import SkyflowError from "../../../../src/libs/skyflow-error"; import logs from "../../../../src/utils/logs"; - // Mock internal element to intercept constructor arguments for mount coverage jest.mock('../../../../src/core/external/reveal/composable-reveal-internal', () => { return { @@ -31,6 +30,7 @@ jest.mock('../../../../src/core/external/reveal/composable-reveal-internal', () }; }); import ComposableRevealInternalElement from '../../../../src/core/external/reveal/composable-reveal-internal'; +import properties from "../../../../src/properties"; iframerUtils.getIframeSrc = jest.fn(() => ('https://google.com')); const mockUuid = '1234'; @@ -51,7 +51,8 @@ describe("Reveal Composable Container Class", () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - off + off, + emit: emitSpy, }); }); const getBearerToken = jest.fn().mockImplementation(() => Promise.resolve('token')); @@ -370,6 +371,7 @@ describe("Reveal Composable Container Class", () => { await Promise.resolve('token'); expect(res).toBeInstanceOf(Promise); //ELEMENT_EVENTS_TO_CLIENT.MOUNTED window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, data: { type: ELEMENT_EVENTS_TO_CLIENT.MOUNTED + mockUuid, data: data @@ -377,6 +379,7 @@ describe("Reveal Composable Container Class", () => { })); await Promise.resolve(); window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, data: { type: ELEMENT_EVENTS_TO_IFRAME.REVEAL_RESPONSE_READY + mockUuid, data: {"success":[{token:"1815-6223-1073-1425"}]} @@ -401,6 +404,7 @@ describe("Reveal Composable Container Class", () => { await Promise.resolve('token'); expect(res).toBeInstanceOf(Promise); //ELEMENT_EVENTS_TO_CLIENT.MOUNTED window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, data: { type: ELEMENT_EVENTS_TO_CLIENT.MOUNTED + mockUuid, data: data @@ -408,6 +412,7 @@ describe("Reveal Composable Container Class", () => { })); await Promise.resolve(); window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, data: { type: ELEMENT_EVENTS_TO_IFRAME.REVEAL_RESPONSE_READY + mockUuid, data: {"errors":{ @@ -427,12 +432,12 @@ describe("Reveal Composable Container Class", () => { description: "Failed to fetch bearer token" } }); - + const clientDataFail = { ...clientData, getSkyflowBearerToken: getBearerTokenFail, }; - + const testRevealContainer = new ComposableRevealContainer(clientDataFail, [], { logLevel: LogLevel.ERROR,env:Env.PROD }, { layout:[1] }); @@ -443,9 +448,9 @@ describe("Reveal Composable Container Class", () => { token: "1815-6223-1073-1425", containerId:mockUuid } - + const res = testRevealContainer.reveal(); - + await expect(res).rejects.toEqual({errors:{code:400,description:"Failed to fetch bearer token"}}); }); @@ -454,12 +459,6 @@ describe("Reveal Composable Container Class", () => { const testRevealContainer = new ComposableRevealContainer(clientData, [], { logLevel: LogLevel.ERROR,env:Env.PROD }, { layout:[1] }); - window.dispatchEvent(new MessageEvent('message', { - data: { - type: ELEMENT_EVENTS_TO_CLIENT.MOUNTED + mockUuid, - data: data - } - })); testRevealContainer.create({ token: "1815-6223-1073-1425", }); @@ -467,11 +466,20 @@ describe("Reveal Composable Container Class", () => { token: "1815-6223-1073-1425", containerId:mockUuid } - + const res = testRevealContainer.reveal(); await Promise.resolve('token'); expect(res).toBeInstanceOf(Promise); //ELEMENT_EVENTS_TO_CLIENT.MOUNTED window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, + data: { + type: ELEMENT_EVENTS_TO_CLIENT.MOUNTED + mockUuid, + data: data + } + })); + await Promise.resolve(); + window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, data: { type: ELEMENT_EVENTS_TO_IFRAME.REVEAL_RESPONSE_READY + mockUuid, data: {"success":[{token:"1815-6223-1073-1425"}]} @@ -484,12 +492,6 @@ describe("Reveal Composable Container Class", () => { const testRevealContainer = new ComposableRevealContainer(clientData, [], { logLevel: LogLevel.ERROR,env:Env.PROD }, { layout:[1] }); - window.dispatchEvent(new MessageEvent('message', { - data: { - type: ELEMENT_EVENTS_TO_CLIENT.MOUNTED + mockUuid, - data: data - } - })); testRevealContainer.create({ token: "1815-6223-1073-1425", }); @@ -497,12 +499,20 @@ describe("Reveal Composable Container Class", () => { token: "1815-6223-1073-1425", containerId:mockUuid } - + const res = testRevealContainer.reveal(); await Promise.resolve('token'); expect(res).toBeInstanceOf(Promise); //ELEMENT_EVENTS_TO_CLIENT.MOUNTED - window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, + data: { + type: ELEMENT_EVENTS_TO_CLIENT.MOUNTED + mockUuid, + data: data + } + })); + await Promise.resolve(); + window.dispatchEvent(new MessageEvent('message', { + origin: properties.IFRAME_SECURE_ORIGIN, data: { type: ELEMENT_EVENTS_TO_IFRAME.REVEAL_RESPONSE_READY + mockUuid, data: {"errors":{ diff --git a/tests/core/external/reveal/reveal-composable-element.test.js b/tests/core/external/reveal/reveal-composable-element.test.js index bd8be7d5..ab8a3a20 100644 --- a/tests/core/external/reveal/reveal-composable-element.test.js +++ b/tests/core/external/reveal/reveal-composable-element.test.js @@ -100,7 +100,8 @@ describe("Reveal Composable Element Class", () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - off + off, + emit: emitSpy, }); const client = new Client(clientData.client.config, clientData); skyflowContainer = new SkyflowContainer(client, { logLevel: LogLevel.DEBUG, env: Env.PROD }); diff --git a/tests/core/external/reveal/reveal-composable-internal.test.js b/tests/core/external/reveal/reveal-composable-internal.test.js index f825f1d7..4d79828c 100644 --- a/tests/core/external/reveal/reveal-composable-internal.test.js +++ b/tests/core/external/reveal/reveal-composable-internal.test.js @@ -137,7 +137,8 @@ describe("Reveal Element Class", () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - off + off, + emit: emitSpy, }); windowSpy = jest.spyOn(window, "window", "get"); const client = new Client(clientData.client.config, clientData); diff --git a/tests/core/external/reveal/reveal-container.test.js b/tests/core/external/reveal/reveal-container.test.js index 48f03257..660b5ee6 100644 --- a/tests/core/external/reveal/reveal-container.test.js +++ b/tests/core/external/reveal/reveal-container.test.js @@ -31,7 +31,8 @@ describe("Reveal Container Class", () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - off + off, + emit: emitSpy, }); }); const getBearerToken = jest.fn().mockImplementation(() => Promise.resolve()); diff --git a/tests/core/external/reveal/reveal-container.test.ts b/tests/core/external/reveal/reveal-container.test.ts index a1fb0db4..dee56702 100644 --- a/tests/core/external/reveal/reveal-container.test.ts +++ b/tests/core/external/reveal/reveal-container.test.ts @@ -105,6 +105,7 @@ describe("Reveal Container Class", () => { targetSpy.mockReturnValue({ on, off, + emit: emitSpy, }); }); diff --git a/tests/core/external/reveal/reveal-element.test.js b/tests/core/external/reveal/reveal-element.test.js index 491bfdb8..ccee593f 100644 --- a/tests/core/external/reveal/reveal-element.test.js +++ b/tests/core/external/reveal/reveal-element.test.js @@ -148,7 +148,8 @@ describe("Reveal Element Class", () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - off + off, + emit: emitSpy, }); const client = new Client(clientData.client.config, clientData); skyflowContainer = new SkyflowContainer(client, { logLevel: LogLevel.DEBUG, env: Env.PROD }); @@ -584,7 +585,8 @@ describe("Reveal Element Methods",()=>{ targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - off + off, + emit: emitSpy, }); }); it("mount with invalid div",()=>{ diff --git a/tests/core/external/reveal/reveal-element.test.ts b/tests/core/external/reveal/reveal-element.test.ts index a42047d4..9d181f13 100644 --- a/tests/core/external/reveal/reveal-element.test.ts +++ b/tests/core/external/reveal/reveal-element.test.ts @@ -177,6 +177,7 @@ describe("Reveal Element Class", () => { targetSpy.mockReturnValue({ on, off, + emit: emitSpy, }); const client = new Client(skyflowConfig, metaData); skyflowContainer = new SkyflowContainer(client, { @@ -699,6 +700,7 @@ describe("Reveal Element Methods", () => { targetSpy.mockReturnValue({ on, off, + emit: emitSpy, }); }); test("file render error case", () => { diff --git a/tests/core/internal/composable-frame-element-init.test.js b/tests/core/internal/composable-frame-element-init.test.js index 9b753d1d..02e789b6 100644 --- a/tests/core/internal/composable-frame-element-init.test.js +++ b/tests/core/internal/composable-frame-element-init.test.js @@ -168,13 +168,13 @@ describe('composableFrameElementInit Additional Test Cases', () => { RevealComposableFrameElementInit.startFrameElement(); postMessageSpy.mockClear(); - window.dispatchEvent(new MessageEvent('message', { data: { name: ELEMENT_EVENTS_TO_CLIENT.HEIGHT + id } })); + window.dispatchEvent(new MessageEvent('message', { origin: 'http://localhost.com', data: { name: ELEMENT_EVENTS_TO_CLIENT.HEIGHT + id } })); const call1 = postMessageSpy.mock.calls.find(c => c[0]?.type === ELEMENT_EVENTS_TO_IFRAME.HEIGHT_CALLBACK + id); expect(call1).toBeTruthy(); expect(call1[0].data).toMatchObject({ name: id, height: expect.any(Number) }); postMessageSpy.mockClear(); - window.dispatchEvent(new MessageEvent('message', { data: { type: ELEMENT_EVENTS_TO_IFRAME.HEIGHT_CALLBACK_COMPOSABLE + id } })); + window.dispatchEvent(new MessageEvent('message', { origin: 'http://localhost.com', data: { type: ELEMENT_EVENTS_TO_IFRAME.HEIGHT_CALLBACK_COMPOSABLE + id } })); const call2 = postMessageSpy.mock.calls.find(c => c[0]?.type === ELEMENT_EVENTS_TO_IFRAME.HEIGHT_CALLBACK + id); expect(call2).toBeTruthy(); expect(call2[0].data).toMatchObject({ name: id, height: expect.any(Number) }); @@ -1003,6 +1003,7 @@ describe('composableFrameElementInit Additional Test Cases', () => { if (messageHandler) { messageHandler({ + origin: 'http://localhost.com', data:{ name: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_REVEAL + containerId, context:{ @@ -1097,6 +1098,7 @@ describe('composableFrameElementInit Additional Test Cases', () => { }); if (messageHandler) { messageHandler({ + origin: 'http://localhost.com', data:{ name: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_REVEAL + containerId, context:{ diff --git a/tests/core/internal/frame-element-init.additional.test.js b/tests/core/internal/frame-element-init.additional.test.js index 6ab29ecf..58b4636b 100644 --- a/tests/core/internal/frame-element-init.additional.test.js +++ b/tests/core/internal/frame-element-init.additional.test.js @@ -459,6 +459,7 @@ describe('FrameElementInit extended unit tests', () => { const clientConfig = { vaultID: 'v1', vaultURL: 'https://vault.url', authToken: 'tok' }; // Directly invoke private handler with synthetic event instance['handleCollectCall']({ + origin: 'http://localhost.com', data: { name: `${ELEMENT_EVENTS_TO_IFRAME.MULTIPLE_UPLOAD_FILES}:${multiElement.iFrameName}`, clientConfig, @@ -486,6 +487,7 @@ describe('FrameElementInit extended unit tests', () => { instance['multipleUploadFiles'] = jest.fn().mockRejectedValue({ error: 'fail' }); const clientConfig = { vaultID: 'v1', vaultURL: 'https://vault.url', authToken: 'tok' }; instance['handleCollectCall']({ + origin: 'http://localhost.com', data: { name: `${ELEMENT_EVENTS_TO_IFRAME.MULTIPLE_UPLOAD_FILES}:${multiElement.iFrameName}`, clientConfig, @@ -508,6 +510,7 @@ describe('FrameElementInit extended unit tests', () => { instance['tokenize'] = jest.fn().mockResolvedValue({ records: [{ id: '1' }] }); const clientConfig = { vaultID: 'v1', vaultURL: 'https://vault.url', authToken: 'tok' }; instance['handleCollectCall']({ + origin: 'http://localhost.com', data: { name: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_REQUESTS + instance.containerId, data: { type: COLLECT_TYPES.COLLECT }, @@ -534,6 +537,7 @@ describe('FrameElementInit extended unit tests', () => { instance['tokenize'] = jest.fn().mockRejectedValue({ error: 'bad' }); const clientConfig = { vaultID: 'v1', vaultURL: 'https://vault.url', authToken: 'tok' }; instance['handleCollectCall']({ + origin: 'http://localhost.com', data: { name: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_REQUESTS + instance.containerId, data: { type: COLLECT_TYPES.COLLECT }, @@ -559,6 +563,7 @@ describe('FrameElementInit extended unit tests', () => { instance['parallelUploadFiles'] = jest.fn().mockResolvedValue({ fileUploadResponse: [{ ok: true }] }); const clientConfig = { vaultID: 'v1', vaultURL: 'https://vault.url', authToken: 'tok' }; instance['handleCollectCall']({ + origin: 'http://localhost.com', data: { name: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_REQUESTS + instance.containerId, data: { type: COLLECT_TYPES.FILE_UPLOAD }, @@ -584,6 +589,7 @@ describe('FrameElementInit extended unit tests', () => { instance['parallelUploadFiles'] = jest.fn().mockRejectedValue({ error: 'upload-fail' }); const clientConfig = { vaultID: 'v1', vaultURL: 'https://vault.url', authToken: 'tok' }; instance['handleCollectCall']({ + origin: 'http://localhost.com', data: { name: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CALL_REQUESTS + instance.containerId, data: { type: COLLECT_TYPES.FILE_UPLOAD }, @@ -608,6 +614,7 @@ describe('FrameElementInit extended unit tests', () => { const spyFromJSON = jest.spyOn(Client, 'fromJSON'); const clientConfigPayload = { config: { vaultURL: 'https://vault.url', vaultID: 'vaultX' } }; instance['handleCollectCall']({ + origin: 'http://localhost.com', data: { name: ELEMENT_EVENTS_TO_IFRAME.COMPOSABLE_CONTAINER + instance.containerId, client: clientConfigPayload, diff --git a/tests/core/internal/frame-element-init.test.js b/tests/core/internal/frame-element-init.test.js index 8ddd65fc..f9a21d74 100644 --- a/tests/core/internal/frame-element-init.test.js +++ b/tests/core/internal/frame-element-init.test.js @@ -669,6 +669,7 @@ describe('FrameElementInit Additional Test Cases', () => { // Simulate multi file upload message event if (messageHandler) { messageHandler(new MessageEvent('message', { + origin: 'http://localhost.com', data: { name: `${ELEMENT_EVENTS_TO_IFRAME.MULTIPLE_UPLOAD_FILES}:element:MULTI_FILE_INPUT:123`, clientConfig: { diff --git a/tests/core/internal/iframe-form/iframe-form.test.js b/tests/core/internal/iframe-form/iframe-form.test.js index f42504f6..339b8a2d 100644 --- a/tests/core/internal/iframe-form/iframe-form.test.js +++ b/tests/core/internal/iframe-form/iframe-form.test.js @@ -67,6 +67,7 @@ describe('test iframeFormelement', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); windowSpy = jest.spyOn(global, 'window', 'get'); windowSpy.mockImplementation(()=>({ diff --git a/tests/core/internal/internal-index.test.js b/tests/core/internal/internal-index.test.js index 5e352a6b..93496ce2 100644 --- a/tests/core/internal/internal-index.test.js +++ b/tests/core/internal/internal-index.test.js @@ -40,6 +40,7 @@ describe('domReady function - FrameElement', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); windowSpy = jest.spyOn(window,'parent','get'); const originalPostMessage = window.postMessage; @@ -275,6 +276,7 @@ describe('FrameElement', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); windowSpy = jest.spyOn(window,'parent','get'); diff --git a/tests/core/internal/reveal/reveal-frame.test.js b/tests/core/internal/reveal/reveal-frame.test.js index b57c88d0..b27981b1 100644 --- a/tests/core/internal/reveal/reveal-frame.test.js +++ b/tests/core/internal/reveal/reveal-frame.test.js @@ -137,7 +137,8 @@ describe("Reveal Frame Class",()=>{ targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - off + off, + emit: emitSpy, }); }); @@ -1067,6 +1068,7 @@ describe("Reveal Frame Class", () => { targetSpy.mockReturnValue({ on: onMock, off: offMock, + emit: emitSpy, }); }); @@ -2100,6 +2102,7 @@ describe("Reveal Frame Class - Additional Tests", () => { targetSpy.mockReturnValue({ on: onMock, off: offMock, + emit: emitSpy, }); // Clean up DOM between tests to avoid interference diff --git a/tests/core/internal/skyflow-frame/skyflow-frame-controller-upload-tokenize.test.js b/tests/core/internal/skyflow-frame/skyflow-frame-controller-upload-tokenize.test.js index 72df6ea2..d828c468 100644 --- a/tests/core/internal/skyflow-frame/skyflow-frame-controller-upload-tokenize.test.js +++ b/tests/core/internal/skyflow-frame/skyflow-frame-controller-upload-tokenize.test.js @@ -52,6 +52,7 @@ describe('Uploading files to the vault', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); testValue = { @@ -504,6 +505,7 @@ describe('SkyflowFrameController - tokenize function', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); testValue = { diff --git a/tests/core/internal/skyflow-frame/skyflow-frame-controller-upload-tokenize.test.ts b/tests/core/internal/skyflow-frame/skyflow-frame-controller-upload-tokenize.test.ts index ada8f52f..4541025b 100644 --- a/tests/core/internal/skyflow-frame/skyflow-frame-controller-upload-tokenize.test.ts +++ b/tests/core/internal/skyflow-frame/skyflow-frame-controller-upload-tokenize.test.ts @@ -66,6 +66,7 @@ describe("Uploading files to the vault", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); testValue = { @@ -441,6 +442,7 @@ describe("SkyflowFrameController - tokenize function", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); testValue = { diff --git a/tests/core/internal/skyflow-frame/skyflow-frame-controller.test.js b/tests/core/internal/skyflow-frame/skyflow-frame-controller.test.js index ad0aae65..aae33fed 100644 --- a/tests/core/internal/skyflow-frame/skyflow-frame-controller.test.js +++ b/tests/core/internal/skyflow-frame/skyflow-frame-controller.test.js @@ -129,6 +129,7 @@ describe('push event', () => { onSpy = jest.spyOn(bus, 'on'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); busEvents.getAccessToken = jest.fn(() => Promise.resolve('access token')); }); @@ -335,6 +336,7 @@ describe('Inserting records into the vault', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -465,6 +467,7 @@ describe('Updating records in the vault', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); busEvents.getAccessToken = jest.fn(() => Promise.resolve('access token')); }); @@ -607,6 +610,7 @@ describe('Retrieving data using skyflowId', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -670,6 +674,7 @@ describe('Retrieving data using skyflow tokens', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -763,6 +768,7 @@ describe('Retrieving data using skyflow tokens', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -827,6 +833,7 @@ describe('Retrieving data using get', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -1020,6 +1027,7 @@ describe('Failed to fetch accessToken get', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -1066,6 +1074,7 @@ describe('Failed to fetch accessToken Getbyid', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -1143,7 +1152,7 @@ describe('Deleting records from the vault', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - emit + emit: emitSpy, }); busEvents.getAccessToken = jest.fn(() => Promise.resolve('access token')); }); @@ -1220,7 +1229,7 @@ describe('getAcessToken error delete', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - emit + emit: emitSpy, }); }); @@ -1262,7 +1271,7 @@ describe('test render file request', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - emit + emit: emitSpy, }); busEvents.getAccessToken = jest.fn(() => Promise.resolve('access token')); }); @@ -1345,7 +1354,7 @@ describe('test reveal request', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - emit + emit: emitSpy, }); busEvents.getAccessToken = jest.fn(() => Promise.resolve('access token')); }); diff --git a/tests/core/internal/skyflow-frame/skyflow-frame-controller.test.ts b/tests/core/internal/skyflow-frame/skyflow-frame-controller.test.ts index 2716e8b6..ca5598be 100644 --- a/tests/core/internal/skyflow-frame/skyflow-frame-controller.test.ts +++ b/tests/core/internal/skyflow-frame/skyflow-frame-controller.test.ts @@ -147,6 +147,7 @@ describe("push event", () => { onSpy = jest.spyOn(bus, "on"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); jest .spyOn(busEvents, "getAccessToken") @@ -380,6 +381,7 @@ describe("Inserting records into the vault", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -533,6 +535,7 @@ describe("Updating records in the vault", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); jest .spyOn(busEvents, "getAccessToken") @@ -699,6 +702,7 @@ describe("Retrieving data using skyflowId", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -779,6 +783,7 @@ describe("Retrieving data using skyflow tokens", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -898,6 +903,7 @@ describe("Retrieving data using skyflow tokens", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -981,6 +987,7 @@ describe("Retrieving data using get", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -1228,6 +1235,7 @@ describe("Failed to fetch accessToken get", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -1277,6 +1285,7 @@ describe("Failed to fetch accessToken Getbyid", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); @@ -1356,7 +1365,7 @@ describe("Deleting records from the vault", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, - emit, + emit: emitSpy, }); }); @@ -1489,7 +1498,7 @@ describe("test render file request", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, - emit, + emit: emitSpy, }); jest .spyOn(busEvents, "getAccessToken") @@ -1608,7 +1617,7 @@ describe("test reveal request", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, - emit, + emit: emitSpy, }); jest .spyOn(busEvents, "getAccessToken") @@ -1864,7 +1873,7 @@ describe("SkyflowFrameController error message handling", () => { emitSpy = jest.spyOn(bus, "emit"); targetSpy = jest.spyOn(bus, "target"); onSpy = jest.spyOn(bus, "on"); - targetSpy.mockReturnValue({ on }); + targetSpy.mockReturnValue({ on, emit: emitSpy }); window.name = "controller:frameId:clientDomain:true"; windowSpy = jest.spyOn(window, "parent", "get"); windowSpy.mockImplementation(() => ({ diff --git a/tests/skyflow.test.js b/tests/skyflow.test.js index e19db09a..bcb20837 100644 --- a/tests/skyflow.test.js +++ b/tests/skyflow.test.js @@ -201,6 +201,7 @@ describe('skyflow insert', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); skyflow = Skyflow.init({ @@ -407,6 +408,7 @@ describe('skyflow update', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); skyflow = Skyflow.init({ @@ -414,7 +416,7 @@ describe('skyflow update', () => { vaultURL: 'https://vaulturl.com', getBearerToken: jest.fn(), }); - }); + }); afterEach(() => { jest.clearAllMocks(); @@ -609,7 +611,7 @@ describe('skyflow detokenize', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - emit, + emit: emitSpy, }); skyflow = Skyflow.init({ @@ -863,6 +865,7 @@ describe('skyflow get', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); skyflow = Skyflow.init({ @@ -1004,6 +1007,7 @@ describe('skyflow getById', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); skyflow = Skyflow.init({ @@ -1152,6 +1156,7 @@ describe('skyflow get', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); skyflow = Skyflow.init({ @@ -1447,6 +1452,7 @@ describe('skyflow get with options', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); skyflow = Skyflow.init({ @@ -1636,6 +1642,7 @@ describe('Get BearerToken Listener', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); }); test('listener with valid Token', (done) => { @@ -1723,7 +1730,7 @@ describe('Skyflow delete tests', () => { targetSpy = jest.spyOn(bus, 'target'); targetSpy.mockReturnValue({ on, - emit + emit: emitSpy, }); skyflow = Skyflow.init({ diff --git a/tests/skyflow.test.ts b/tests/skyflow.test.ts index d01d53c6..7cb90c1e 100644 --- a/tests/skyflow.test.ts +++ b/tests/skyflow.test.ts @@ -114,6 +114,7 @@ describe("skyflow insert", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); const config: ISkyflow = { @@ -216,6 +217,7 @@ describe("skyflow update", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); const config: ISkyflow = { @@ -428,7 +430,7 @@ describe("skyflow detokenize", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, - emit, + emit: emitSpy, }); skyflow = Skyflow.init({ @@ -447,6 +449,7 @@ describe("skyflow detokenize", () => { const frameReayEvent = on.mock.calls.filter((data) => data[0].includes(ELEMENT_EVENTS_TO_IFRAME.PUREJS_FRAME_READY) ); + const frameReadyCb = frameReayEvent[0][1]; const cb2 = jest.fn(); frameReadyCb({}, cb2); @@ -557,6 +560,7 @@ describe("skyflow get", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); skyflow = Skyflow.init({ @@ -633,6 +637,7 @@ describe("skyflow getById", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); skyflow = Skyflow.init({ @@ -709,6 +714,7 @@ describe("skyflow get", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); skyflow = Skyflow.init({ @@ -838,6 +844,7 @@ describe("skyflow get with options", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, + emit: emitSpy, }); skyflow = Skyflow.init({ @@ -944,7 +951,7 @@ describe("Skyflow delete tests", () => { targetSpy = jest.spyOn(bus, "target"); targetSpy.mockReturnValue({ on, - emit, + emit: emitSpy, }); skyflow = Skyflow.init({ @@ -970,6 +977,7 @@ describe("Skyflow delete tests", () => { const emitEvent = emitSpy.mock.calls.filter((data) => data[0].includes(ELEMENT_EVENTS_TO_IFRAME.PUREJS_REQUEST) ); + console.log("emitEvent", emitSpy); const emitCb = emitEvent[0][2]; emitCb(deleteResponse);