From 4717403b7fb3a1dfb53f9c385e760622ab46e2e9 Mon Sep 17 00:00:00 2001 From: Dalton Menezes Date: Sat, 19 Nov 2022 02:46:49 -0300 Subject: [PATCH] fix(interprocess): issue where append and override was not working as expected --- packages/interprocess/CHANGELOG.md | 6 +++++ packages/interprocess/package.json | 2 +- .../createApiToGlobalWindowExposer.ts | 24 +++++++++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/interprocess/CHANGELOG.md b/packages/interprocess/CHANGELOG.md index a0216ce..30cdcb0 100644 --- a/packages/interprocess/CHANGELOG.md +++ b/packages/interprocess/CHANGELOG.md @@ -1,5 +1,11 @@ # interprocess +## 0.2.1 + +### Patch Changes + +- fix and issue where append and override was not working as expected + ## 0.2.0 ### Minor Changes diff --git a/packages/interprocess/package.json b/packages/interprocess/package.json index aa98b7a..89aeecf 100644 --- a/packages/interprocess/package.json +++ b/packages/interprocess/package.json @@ -1,6 +1,6 @@ { "name": "interprocess", - "version": "0.2.0", + "version": "0.2.1", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", "types": "dist/index.d.ts", diff --git a/packages/interprocess/src/factories/createApiToGlobalWindowExposer.ts b/packages/interprocess/src/factories/createApiToGlobalWindowExposer.ts index 5a0b835..3d89aa2 100644 --- a/packages/interprocess/src/factories/createApiToGlobalWindowExposer.ts +++ b/packages/interprocess/src/factories/createApiToGlobalWindowExposer.ts @@ -17,16 +17,30 @@ export function createApiToGlobalWindowExposer( >(props: APIConfig = defaultAPIConfig as unknown as APIConfig) { const { apiKey, exposeAll, append } = Object.assign(defaultAPIConfig, props) - const defaultAPI = Object.assign({ invoke: rendererInvoke }, append) + const defaultAPI = { invoke: rendererInvoke, ...append } - const allAPIs = Object.assign(defaultAPI, { + const restrictedAPIs = { handle: rendererHandle, remove: rendererRemove, - }) + } + + const allAPIs = { ...restrictedAPIs, ...defaultAPI } + + const allApisWithoutAppend = { + ...restrictedAPIs, + invoke: rendererInvoke, + } const api = exposeAll ? allAPIs : defaultAPI - contextBridge.exposeInMainWorld(apiKey || defaultAPIConfig.apiKey, api) + const publicApi = props.override + ? { ...props.override(allApisWithoutAppend), ...append } + : api + + contextBridge.exposeInMainWorld( + apiKey || defaultAPIConfig.apiKey, + publicApi + ) const key = apiKey as StringAssertion< APIConfig['apiKey'], @@ -41,7 +55,7 @@ export function createApiToGlobalWindowExposer( return { key, - api: (props.override ? props.override(allAPIs) : api) as APIReturn, + api: publicApi as APIReturn & typeof append, } }