@dipswitch/openfeature-web 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,28 @@
1
- # Temporary Holding Version
1
+ # @dipswitch/openfeature-web
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
+ Use Dipswitch's browser SDK through OpenFeature. It reads evaluated values for the current user and forwards OpenFeature configuration-change events.
4
+
5
+ ```sh
6
+ npm install @dipswitch/openfeature-web @openfeature/web-sdk
7
+ ```
8
+
9
+ ```ts
10
+ import { DipswitchProvider } from '@dipswitch/openfeature-web'
11
+ import { OpenFeature, ProviderNotReadyError } from '@openfeature/web-sdk'
12
+
13
+ await OpenFeature.setProviderAndWait(
14
+ new DipswitchProvider({ clientKey: 'your-public-client-key' }),
15
+ { targetingKey: 'user-123' },
16
+ ).catch((error: unknown) => {
17
+ if (!(error instanceof ProviderNotReadyError)) throw error
18
+ })
19
+ const client = OpenFeature.getClient()
20
+ const billing = client.getBooleanDetails('new-billing', false)
21
+ console.log(billing.value, billing.reason)
22
+
23
+ await OpenFeature.setContext({ targetingKey: 'user-456' })
24
+ ```
25
+
26
+ Use the public client key and set `targetingKey` to the current user id. Pass an empty context on sign-out. Pass `edgeUrl` to use a local edge. The browser adapter has no signature option. Use the native browser SDK for signed identities. Use a string `workspaceId` in the OpenFeature context for workspace rollouts. If the flag uses a rollout key that is missing, evaluation details report it in `flagMetadata.missingRolloutKey`.
27
+
28
+ Loaded values carry the `CACHED` reason. A missing flag returns the supplied default with `FLAG_NOT_FOUND`. When the current user's values are unavailable, evaluations return the default with `PROVIDER_NOT_READY`. The SDK retries temporary failures and stops if the key is the wrong kind, is revoked, or keeps getting a 401. OpenFeature signals readiness once the current user's values arrive.
@@ -0,0 +1,26 @@
1
+ import { ClientOptions } from "@dipswitch/sdk-js";
2
+ import { EvaluationContext, OpenFeatureEventEmitter, Provider, ResolutionDetails } from "@openfeature/web-sdk";
3
+ export declare class DipswitchProvider implements Provider {
4
+ private readonly options;
5
+ readonly metadata: {
6
+ name: string;
7
+ };
8
+ readonly runsOn: "client";
9
+ readonly domainScoped = true;
10
+ readonly events: OpenFeatureEventEmitter;
11
+ private sdk?;
12
+ private unsubscribe?;
13
+ private version?;
14
+ private recovering;
15
+ private settingContext;
16
+ private pendingContext?;
17
+ constructor(options: Omit<ClientOptions, 'user' | 'workspaceId' | 'signature' | 'refetchDelayMaxMs'>);
18
+ initialize(context?: EvaluationContext): Promise<void>;
19
+ onContextChange(oldContext: EvaluationContext, next: EvaluationContext): Promise<void> | void;
20
+ onClose(): Promise<void>;
21
+ resolveBooleanEvaluation(key: string): ResolutionDetails<boolean>;
22
+ readonly resolveStringEvaluation: () => never;
23
+ readonly resolveNumberEvaluation: () => never;
24
+ readonly resolveObjectEvaluation: () => never;
25
+ private forwardChange;
26
+ }
package/dist/index.js ADDED
@@ -0,0 +1,95 @@
1
+ import { ADAPTER_REFETCH_DELAY_MAX_MS, createClient } from "@dipswitch/sdk-js";
2
+ import { FlagNotFoundError, OpenFeatureEventEmitter, ProviderEvents, ProviderNotReadyError, TypeMismatchError } from "@openfeature/web-sdk";
3
+ // src/index.ts
4
+ const user = (context) => context.targetingKey === void 0 ? void 0 : { id: context.targetingKey };
5
+ const workspace = (context) => typeof context.workspaceId === "string" ? context.workspaceId : void 0;
6
+ const unsupported = () => {
7
+ throw new TypeMismatchError("Dipswitch flags are boolean.");
8
+ };
9
+ const notReady = () => new ProviderNotReadyError("The current user’s flags have not loaded.");
10
+ var DipswitchProvider = class {
11
+ options;
12
+ metadata = { name: "Dipswitch" };
13
+ runsOn = "client";
14
+ domainScoped = true;
15
+ events = new OpenFeatureEventEmitter();
16
+ sdk;
17
+ unsubscribe;
18
+ version;
19
+ recovering = false;
20
+ settingContext = false;
21
+ pendingContext;
22
+ constructor(options) {
23
+ this.options = options;
24
+ }
25
+ async initialize(context = {}) {
26
+ this.recovering = false;
27
+ const sdk = createClient({
28
+ ...this.options,
29
+ user: user(context),
30
+ workspaceId: workspace(context),
31
+ refetchDelayMaxMs: ADAPTER_REFETCH_DELAY_MAX_MS
32
+ });
33
+ this.sdk = sdk;
34
+ await sdk.ready;
35
+ if (this.sdk !== sdk) return;
36
+ this.version = sdk.snapshotVersion;
37
+ this.unsubscribe = sdk.onChange(() => this.forwardChange(sdk.snapshotVersion));
38
+ if (this.version === void 0) {
39
+ this.recovering = true;
40
+ throw notReady();
41
+ }
42
+ }
43
+ onContextChange(oldContext, next) {
44
+ const sdk = this.sdk;
45
+ if (!sdk) return;
46
+ if (oldContext.targetingKey === next.targetingKey && workspace(oldContext) === workspace(next)) return this.pendingContext ?? (sdk.snapshotVersion === void 0 ? Promise.reject(notReady()) : void 0);
47
+ this.settingContext = true;
48
+ try {
49
+ const pending = sdk.identify(user(next), void 0, workspace(next)).then(() => {
50
+ if (this.sdk !== sdk) return;
51
+ if (this.pendingContext && this.pendingContext !== pending) return this.pendingContext;
52
+ this.pendingContext = void 0;
53
+ if (sdk.snapshotVersion === void 0) {
54
+ this.recovering = true;
55
+ throw notReady();
56
+ }
57
+ });
58
+ this.pendingContext = pending;
59
+ return pending;
60
+ } finally {
61
+ this.settingContext = false;
62
+ }
63
+ }
64
+ async onClose() {
65
+ this.unsubscribe?.();
66
+ this.sdk?.close();
67
+ this.unsubscribe = void 0;
68
+ this.sdk = void 0;
69
+ this.pendingContext = void 0;
70
+ }
71
+ resolveBooleanEvaluation(key) {
72
+ const result = this.sdk?.getFlagDetails(key);
73
+ if (!result || result.reason === "NOT_READY") throw notReady();
74
+ if (result.value === void 0) throw new FlagNotFoundError(`No flag named ${key}.`);
75
+ const { value, reason, metadata } = result;
76
+ return {
77
+ value,
78
+ reason,
79
+ ...metadata && { flagMetadata: metadata }
80
+ };
81
+ }
82
+ resolveStringEvaluation = unsupported;
83
+ resolveNumberEvaluation = unsupported;
84
+ resolveObjectEvaluation = unsupported;
85
+ forwardChange(version) {
86
+ if (version === void 0) return;
87
+ const changed = this.version !== void 0 && version > this.version;
88
+ if (changed || this.version === void 0) this.version = version;
89
+ if (this.recovering) {
90
+ this.recovering = false;
91
+ this.events.emit(ProviderEvents.Ready);
92
+ } else if (changed && !this.settingContext) this.events.emit(ProviderEvents.ConfigurationChanged);
93
+ }
94
+ };
95
+ export { DipswitchProvider };
package/package.json CHANGED
@@ -1,6 +1,25 @@
1
1
  {
2
2
  "name": "@dipswitch/openfeature-web",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Dipswitch provider for the OpenFeature web SDK.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "sideEffects": false,
19
+ "dependencies": {
20
+ "@dipswitch/sdk-js": "0.2.0"
21
+ },
22
+ "peerDependencies": {
23
+ "@openfeature/web-sdk": "^1.10.0"
24
+ }
6
25
  }