@dipswitch/sdk-node-launchdarkly 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +55 -2
- package/dist/index.cjs +37 -0
- package/dist/index.d.cts +24 -0
- package/dist/index.d.mts +24 -0
- package/dist/index.mjs +36 -0
- package/package.json +32 -3
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
|
-
#
|
|
1
|
+
# @dipswitch/sdk-node-launchdarkly
|
|
2
2
|
|
|
3
|
-
|
|
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.1.0.tgz ./dipswitch-sdk-node-launchdarkly-0.1.0.tgz
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
After publication, install both Dipswitch packages from npm for the shadow example. 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,37 @@
|
|
|
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(mismatch) {
|
|
10
|
+
console.warn("[Dipswitch shadow] Flag mismatch", mismatch);
|
|
11
|
+
}
|
|
12
|
+
/** Wraps the existing LaunchDarkly client. Adding a Dipswitch client enables comparison. */
|
|
13
|
+
function createFlagClient(options) {
|
|
14
|
+
const readLaunchDarkly = (key, context, fallback) => options.launchDarkly.boolVariation(key, context, fallback);
|
|
15
|
+
if (!options.dipswitch) return { isEnabled: readLaunchDarkly };
|
|
16
|
+
const { dipswitch, onMismatch = logMismatch, returnFrom = "launchdarkly" } = options;
|
|
17
|
+
return { isEnabled(flagKey, context, defaultValue) {
|
|
18
|
+
const next = (async () => {
|
|
19
|
+
const userId = userKey(context);
|
|
20
|
+
return {
|
|
21
|
+
userId,
|
|
22
|
+
value: dipswitch.isEnabled(flagKey, userId, defaultValue)
|
|
23
|
+
};
|
|
24
|
+
})();
|
|
25
|
+
const legacy = (async () => readLaunchDarkly(flagKey, context, defaultValue))();
|
|
26
|
+
Promise.all([legacy, next]).then(([oldValue, { userId, value }]) => {
|
|
27
|
+
if (oldValue !== value) return onMismatch({
|
|
28
|
+
flagKey,
|
|
29
|
+
userId,
|
|
30
|
+
launchDarkly: oldValue,
|
|
31
|
+
dipswitch: value
|
|
32
|
+
});
|
|
33
|
+
}, () => void 0).catch(() => console.warn("[Dipswitch shadow] Mismatch handler failed"));
|
|
34
|
+
return returnFrom === "dipswitch" ? next.then(({ value }) => value) : legacy;
|
|
35
|
+
} };
|
|
36
|
+
}
|
|
37
|
+
exports.createFlagClient = createFlagClient;
|
package/dist/index.d.cts
ADDED
|
@@ -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): 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.d.mts
ADDED
|
@@ -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): 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,36 @@
|
|
|
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(mismatch) {
|
|
9
|
+
console.warn("[Dipswitch shadow] Flag mismatch", mismatch);
|
|
10
|
+
}
|
|
11
|
+
/** Wraps the existing LaunchDarkly client. Adding a Dipswitch client enables comparison. */
|
|
12
|
+
function createFlagClient(options) {
|
|
13
|
+
const readLaunchDarkly = (key, context, fallback) => options.launchDarkly.boolVariation(key, context, fallback);
|
|
14
|
+
if (!options.dipswitch) return { isEnabled: readLaunchDarkly };
|
|
15
|
+
const { dipswitch, onMismatch = logMismatch, returnFrom = "launchdarkly" } = options;
|
|
16
|
+
return { isEnabled(flagKey, context, defaultValue) {
|
|
17
|
+
const next = (async () => {
|
|
18
|
+
const userId = userKey(context);
|
|
19
|
+
return {
|
|
20
|
+
userId,
|
|
21
|
+
value: dipswitch.isEnabled(flagKey, userId, defaultValue)
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
const legacy = (async () => readLaunchDarkly(flagKey, context, defaultValue))();
|
|
25
|
+
Promise.all([legacy, next]).then(([oldValue, { userId, value }]) => {
|
|
26
|
+
if (oldValue !== value) return onMismatch({
|
|
27
|
+
flagKey,
|
|
28
|
+
userId,
|
|
29
|
+
launchDarkly: oldValue,
|
|
30
|
+
dipswitch: value
|
|
31
|
+
});
|
|
32
|
+
}, () => void 0).catch(() => console.warn("[Dipswitch shadow] Mismatch handler failed"));
|
|
33
|
+
return returnFrom === "dipswitch" ? next.then(({ value }) => value) : legacy;
|
|
34
|
+
} };
|
|
35
|
+
}
|
|
36
|
+
export { createFlagClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dipswitch/sdk-node-launchdarkly",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.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.1.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@launchdarkly/node-server-sdk": "^9.16.4"
|
|
34
|
+
}
|
|
6
35
|
}
|