Skip to content

Commit

Permalink
fix(interprocess): issue where append and override was not working as…
Browse files Browse the repository at this point in the history
… expected
  • Loading branch information
daltonmenezes committed Nov 19, 2022
1 parent 97c68eb commit 4717403
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/interprocess/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/interprocess/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,30 @@ export function createApiToGlobalWindowExposer<Handle, Invoke, Remove>(
>(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'],
Expand All @@ -41,7 +55,7 @@ export function createApiToGlobalWindowExposer<Handle, Invoke, Remove>(

return {
key,
api: (props.override ? props.override(allAPIs) : api) as APIReturn,
api: publicApi as APIReturn & typeof append,
}
}

Expand Down

0 comments on commit 4717403

Please sign in to comment.