@dipswitch/sdk-node-launchdarkly 0.0.0-stage → 0.2.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Engineers Space LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,56 @@
1
- # Temporary Holding Version
1
+ # @dipswitch/sdk-node-launchdarkly
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Compare boolean flag values during a Node service's move from LaunchDarkly to Dipswitch.
4
+
5
+ ## Install
6
+
7
+ For local use, build and pack `sdk-node` and `sdk-node-launchdarkly`. In a service that already uses the LaunchDarkly Node server SDK, install both tarballs together.
8
+
9
+ ```sh
10
+ npm install ./dipswitch-sdk-node-0.2.0.tgz ./dipswitch-sdk-node-launchdarkly-0.2.0.tgz
11
+ ```
12
+
13
+ For released versions, install both Dipswitch packages from npm. The service supplies `@launchdarkly/node-server-sdk` in the supported `^9.16.4` range.
14
+
15
+ ```sh
16
+ npm install @dipswitch/sdk-node @dipswitch/sdk-node-launchdarkly
17
+ ```
18
+
19
+ ## Wrap
20
+
21
+ Pass your initialized LaunchDarkly client and route boolean checks through `isEnabled`. Keep passing the same context and fallback.
22
+
23
+ ```ts
24
+ import { createFlagClient } from '@dipswitch/sdk-node-launchdarkly'
25
+ import type { LDClient } from '@launchdarkly/node-server-sdk'
26
+
27
+ export function billingFlag(launchDarkly: LDClient) {
28
+ const flags = createFlagClient({ launchDarkly })
29
+ return flags.isEnabled('new-billing', { kind: 'user', key: 'user-123' }, false)
30
+ }
31
+ ```
32
+
33
+ ## Shadow and switch
34
+
35
+ At service startup, supply a Dipswitch client as well. Each check then evaluates both systems and serves the LaunchDarkly answer by default. Dipswitch reads the key of the LaunchDarkly user, including the `user` entry of a multi-context. Contexts without a user key get Dipswitch's no-user values.
36
+
37
+ ```ts
38
+ import { createClient } from '@dipswitch/sdk-node'
39
+ import { createFlagClient } from '@dipswitch/sdk-node-launchdarkly'
40
+ import type { LDClient } from '@launchdarkly/node-server-sdk'
41
+
42
+ export async function shadowFlags(launchDarkly: LDClient, serverKey: string, useDipswitch: boolean) {
43
+ const dipswitch = createClient({ serverKey })
44
+ await dipswitch.ready
45
+ const flags = createFlagClient({
46
+ launchDarkly,
47
+ dipswitch,
48
+ returnFrom: useDipswitch ? 'dipswitch' : 'launchdarkly',
49
+ })
50
+ return { flags, dipswitch }
51
+ }
52
+ ```
53
+
54
+ A difference is logged once per check with the flag key, user ID and both values. Supply `onMismatch` to send that record to your own logger. The selected SDK's answer returns as soon as it is ready. Comparison and logging can finish afterward. If an SDK throws, there is no mismatch to report for that check. An error from the selected SDK reaches the caller.
55
+
56
+ After a week with no mismatches, switch one service at a time to `returnFrom: 'dipswitch'`. Both checks still run with that setting. Close both SDKs when the service shuts down.
package/dist/index.cjs ADDED
@@ -0,0 +1,41 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ // src/index.ts
3
+ function userKey(context) {
4
+ if (typeof context !== "object" || context === null) return void 0;
5
+ const kind = "kind" in context ? context.kind : void 0;
6
+ const user = kind === "multi" && "user" in context ? context.user : kind === "user" || kind === void 0 ? context : void 0;
7
+ if (typeof user === "object" && user !== null && "key" in user && typeof user.key === "string" && user.key !== "") return user.key;
8
+ }
9
+ function logMismatch({ flagKey, launchDarkly, dipswitch }) {
10
+ console.warn("[Dipswitch shadow] Flag mismatch", {
11
+ flagKey,
12
+ launchDarkly,
13
+ dipswitch
14
+ });
15
+ }
16
+ /** Wraps the existing LaunchDarkly client. Adding a Dipswitch client enables comparison. */
17
+ function createFlagClient(options) {
18
+ const readLaunchDarkly = (key, context, fallback) => options.launchDarkly.boolVariation(key, context, fallback);
19
+ if (!options.dipswitch) return { isEnabled: readLaunchDarkly };
20
+ const { dipswitch, onMismatch = logMismatch, returnFrom = "launchdarkly" } = options;
21
+ return { isEnabled(flagKey, context, defaultValue, workspaceId) {
22
+ const next = (async () => {
23
+ const userId = userKey(context);
24
+ return {
25
+ userId,
26
+ value: workspaceId === void 0 ? dipswitch.isEnabled(flagKey, userId, defaultValue) : dipswitch.isEnabled(flagKey, userId, defaultValue, workspaceId)
27
+ };
28
+ })();
29
+ const legacy = (async () => readLaunchDarkly(flagKey, context, defaultValue))();
30
+ Promise.all([legacy, next]).then(([oldValue, { userId, value }]) => {
31
+ if (oldValue !== value) return onMismatch({
32
+ flagKey,
33
+ userId,
34
+ launchDarkly: oldValue,
35
+ dipswitch: value
36
+ });
37
+ }, () => void 0).catch(() => console.warn("[Dipswitch shadow] Mismatch handler failed"));
38
+ return returnFrom === "dipswitch" ? next.then(({ value }) => value) : legacy;
39
+ } };
40
+ }
41
+ exports.createFlagClient = createFlagClient;
@@ -0,0 +1,24 @@
1
+ import { DipswitchClient } from "@dipswitch/sdk-node";
2
+ import { LDClient, LDContext } from "@launchdarkly/node-server-sdk";
3
+ export interface FlagMismatch {
4
+ flagKey: string;
5
+ userId: string | undefined;
6
+ launchDarkly: boolean;
7
+ dipswitch: boolean;
8
+ }
9
+ export interface FlagClient {
10
+ isEnabled(flagKey: string, context: LDContext, defaultValue: boolean, workspaceId?: string): Promise<boolean>;
11
+ }
12
+ export type FlagClientOptions = {
13
+ launchDarkly: Pick<LDClient, 'boolVariation'>;
14
+ } & ({
15
+ dipswitch?: undefined;
16
+ onMismatch?: never;
17
+ returnFrom?: never;
18
+ } | {
19
+ dipswitch: Pick<DipswitchClient, 'isEnabled'>;
20
+ onMismatch?: (mismatch: FlagMismatch) => void | Promise<void>;
21
+ returnFrom?: 'launchdarkly' | 'dipswitch';
22
+ });
23
+ /** Wraps the existing LaunchDarkly client. Adding a Dipswitch client enables comparison. */
24
+ export declare function createFlagClient(options: FlagClientOptions): FlagClient;
@@ -0,0 +1,24 @@
1
+ import { DipswitchClient } from "@dipswitch/sdk-node";
2
+ import { LDClient, LDContext } from "@launchdarkly/node-server-sdk";
3
+ export interface FlagMismatch {
4
+ flagKey: string;
5
+ userId: string | undefined;
6
+ launchDarkly: boolean;
7
+ dipswitch: boolean;
8
+ }
9
+ export interface FlagClient {
10
+ isEnabled(flagKey: string, context: LDContext, defaultValue: boolean, workspaceId?: string): Promise<boolean>;
11
+ }
12
+ export type FlagClientOptions = {
13
+ launchDarkly: Pick<LDClient, 'boolVariation'>;
14
+ } & ({
15
+ dipswitch?: undefined;
16
+ onMismatch?: never;
17
+ returnFrom?: never;
18
+ } | {
19
+ dipswitch: Pick<DipswitchClient, 'isEnabled'>;
20
+ onMismatch?: (mismatch: FlagMismatch) => void | Promise<void>;
21
+ returnFrom?: 'launchdarkly' | 'dipswitch';
22
+ });
23
+ /** Wraps the existing LaunchDarkly client. Adding a Dipswitch client enables comparison. */
24
+ export declare function createFlagClient(options: FlagClientOptions): FlagClient;
package/dist/index.mjs ADDED
@@ -0,0 +1,40 @@
1
+ // src/index.ts
2
+ function userKey(context) {
3
+ if (typeof context !== "object" || context === null) return void 0;
4
+ const kind = "kind" in context ? context.kind : void 0;
5
+ const user = kind === "multi" && "user" in context ? context.user : kind === "user" || kind === void 0 ? context : void 0;
6
+ if (typeof user === "object" && user !== null && "key" in user && typeof user.key === "string" && user.key !== "") return user.key;
7
+ }
8
+ function logMismatch({ flagKey, launchDarkly, dipswitch }) {
9
+ console.warn("[Dipswitch shadow] Flag mismatch", {
10
+ flagKey,
11
+ launchDarkly,
12
+ dipswitch
13
+ });
14
+ }
15
+ /** Wraps the existing LaunchDarkly client. Adding a Dipswitch client enables comparison. */
16
+ function createFlagClient(options) {
17
+ const readLaunchDarkly = (key, context, fallback) => options.launchDarkly.boolVariation(key, context, fallback);
18
+ if (!options.dipswitch) return { isEnabled: readLaunchDarkly };
19
+ const { dipswitch, onMismatch = logMismatch, returnFrom = "launchdarkly" } = options;
20
+ return { isEnabled(flagKey, context, defaultValue, workspaceId) {
21
+ const next = (async () => {
22
+ const userId = userKey(context);
23
+ return {
24
+ userId,
25
+ value: workspaceId === void 0 ? dipswitch.isEnabled(flagKey, userId, defaultValue) : dipswitch.isEnabled(flagKey, userId, defaultValue, workspaceId)
26
+ };
27
+ })();
28
+ const legacy = (async () => readLaunchDarkly(flagKey, context, defaultValue))();
29
+ Promise.all([legacy, next]).then(([oldValue, { userId, value }]) => {
30
+ if (oldValue !== value) return onMismatch({
31
+ flagKey,
32
+ userId,
33
+ launchDarkly: oldValue,
34
+ dipswitch: value
35
+ });
36
+ }, () => void 0).catch(() => console.warn("[Dipswitch shadow] Mismatch handler failed"));
37
+ return returnFrom === "dipswitch" ? next.then(({ value }) => value) : legacy;
38
+ } };
39
+ }
40
+ export { createFlagClient };
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "@dipswitch/sdk-node-launchdarkly",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Compare LaunchDarkly and Dipswitch feature flags during a Node migration.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=20"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "types": "./dist/index.d.mts",
14
+ "default": "./dist/index.mjs"
15
+ },
16
+ "require": {
17
+ "types": "./dist/index.d.cts",
18
+ "default": "./dist/index.cjs"
19
+ }
20
+ }
21
+ },
22
+ "main": "./dist/index.cjs",
23
+ "module": "./dist/index.mjs",
24
+ "types": "./dist/index.d.cts",
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "sideEffects": false,
29
+ "dependencies": {
30
+ "@dipswitch/sdk-node": "0.2.0"
31
+ },
32
+ "peerDependencies": {
33
+ "@launchdarkly/node-server-sdk": "^9.16.4"
34
+ }
6
35
  }