Skip to content

Commit 451f17d

Browse files
committed
refactor: moving deriveNamespace back to ElectronIPC
1 parent 909cbf5 commit 451f17d

10 files changed

Lines changed: 17 additions & 23 deletions

File tree

packages/sdk/electron/__tests__/ElectronClient.ipcMain.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import type {
88
LDIdentifyOptions,
99
} from '@launchdarkly/js-client-sdk-common';
1010

11-
import { deriveNamespace } from '../src/deriveNamespace';
1211
import { ElectronClient } from '../src/ElectronClient';
13-
import { getIPCChannelName } from '../src/ElectronIPC';
12+
import { deriveNamespace, getIPCChannelName } from '../src/ElectronIPC';
1413
import ElectronCrypto from '../src/platform/ElectronCrypto';
1514
import ElectronEncoding from '../src/platform/ElectronEncoding';
1615
import ElectronInfo from '../src/platform/ElectronInfo';

packages/sdk/electron/__tests__/ElectronIPC.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { deriveNamespace } from '../src/deriveNamespace';
2-
import { getIPCChannelName } from '../src/ElectronIPC';
1+
import { deriveNamespace, getIPCChannelName } from '../src/ElectronIPC';
32

43
it('derives namespace from credential alone', () => {
54
expect(deriveNamespace('mob-abc-123')).toBe('mob-abc-123');

packages/sdk/electron/__tests__/bridge/LDClientBridge.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ipcRenderer } from 'electron';
22

33
import '../../src/bridge';
44
import type { LDClientBridge } from '../../src/bridge/LDClientBridge';
5-
import { deriveNamespace } from '../../src/deriveNamespace';
5+
import { deriveNamespace } from '../../src/ElectronIPC';
66
import type { LDContext } from '../../src/index';
77

88
const clientSideId = 'client-side-id';

packages/sdk/electron/__tests__/renderer/ElectronRendererClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { LDContext } from '@launchdarkly/js-client-sdk-common';
22

33
import type { LDClientBridge } from '../../src/bridge/LDClientBridge';
4-
import { deriveNamespace } from '../../src/deriveNamespace';
4+
import { deriveNamespace } from '../../src/ElectronIPC';
55
import { ElectronRendererClient } from '../../src/renderer/ElectronRendererClient';
66

77
const ldClientBridge: LDClientBridge = {

packages/sdk/electron/src/ElectronClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ import {
2525
readFlagsFromBootstrap,
2626
} from '@launchdarkly/js-client-sdk-common';
2727

28-
import { deriveNamespace } from './deriveNamespace';
2928
import ElectronDataManager from './ElectronDataManager';
3029
import {
3130
AllAsyncChannels,
3231
AllSyncChannels,
32+
deriveNamespace,
3333
getIPCChannelName,
3434
IpcEventCallback,
3535
IpcEventSubscription,

packages/sdk/electron/src/ElectronIPC.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { MessagePortMain } from 'electron';
2+
13
import { LDEmitterEventName } from '@launchdarkly/js-client-sdk-common';
24

35
/**
@@ -68,7 +70,7 @@ export type IPCChannel = IPCSyncChannel | IPCAsyncChannel;
6870
*/
6971
export interface IpcEventSubscription {
7072
broadcastCallback: (...args: any[]) => void;
71-
ports: Map<string, Electron.MessagePortMain>;
73+
ports: Map<string, MessagePortMain>;
7274
}
7375

7476
export interface IpcEventCallback {
@@ -82,3 +84,10 @@ export interface IpcEventCallback {
8284
export function getIPCChannelName(namespace: string, channel: IPCChannel): string {
8385
return `ld:${namespace}:${channel}`;
8486
}
87+
88+
/**
89+
* Derives a storage/IPC namespace from a credential and an optional user-provided namespace.
90+
*/
91+
export function deriveNamespace(credential: string, customNamespace?: string): string {
92+
return customNamespace ? `${customNamespace}_${credential}` : credential;
93+
}

packages/sdk/electron/src/ElectronOptions.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ export interface ElectronOptions extends LDOptionsBase {
122122
/**
123123
* An optional namespace to isolate this client's storage and IPC channels
124124
* from other clients using the same credential in the same process.
125-
*
126-
* @remarks
127-
* Useful when running multiple client instances (e.g., multiple environments)
128-
* in the same Electron app. When omitted, isolation is based solely on the credential.
129125
*/
130126
namespace?: string;
131127
}

packages/sdk/electron/src/deriveNamespace.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/sdk/electron/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { deriveNamespace } from './deriveNamespace';
21
import { makeClient } from './ElectronClient';
2+
import { deriveNamespace } from './ElectronIPC';
33
import type { ElectronOptions, LDProxyOptions, LDTLSOptions } from './ElectronOptions';
44
import type { LDClient, LDStartOptions } from './LDClient';
55
import type { LDContext } from './LDCommon';

packages/sdk/electron/src/renderer/ElectronRendererClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
} from '@launchdarkly/js-client-sdk-common';
1414

1515
import type { LDClientBridge } from '../bridge/LDClientBridge';
16-
import { deriveNamespace } from '../deriveNamespace';
16+
import { deriveNamespace } from '../ElectronIPC';
1717
import type { LDRendererClient } from './LDRendererClient';
1818

1919
export class ElectronRendererClient implements LDRendererClient {

0 commit comments

Comments
 (0)