@dipswitch/openfeature-web 0.1.0 → 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/README.md CHANGED
@@ -23,6 +23,6 @@ console.log(billing.value, billing.reason)
23
23
  await OpenFeature.setContext({ targetingKey: 'user-456' })
24
24
  ```
25
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.
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
27
 
28
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.
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ export declare class DipswitchProvider implements Provider {
14
14
  private recovering;
15
15
  private settingContext;
16
16
  private pendingContext?;
17
- constructor(options: Omit<ClientOptions, 'user' | 'signature' | 'refetchDelayMaxMs'>);
17
+ constructor(options: Omit<ClientOptions, 'user' | 'workspaceId' | 'signature' | 'refetchDelayMaxMs'>);
18
18
  initialize(context?: EvaluationContext): Promise<void>;
19
19
  onContextChange(oldContext: EvaluationContext, next: EvaluationContext): Promise<void> | void;
20
20
  onClose(): Promise<void>;
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import { ADAPTER_REFETCH_DELAY_MAX_MS, createClient } from "@dipswitch/sdk-js";
2
2
  import { FlagNotFoundError, OpenFeatureEventEmitter, ProviderEvents, ProviderNotReadyError, TypeMismatchError } from "@openfeature/web-sdk";
3
3
  // src/index.ts
4
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;
5
6
  const unsupported = () => {
6
7
  throw new TypeMismatchError("Dipswitch flags are boolean.");
7
8
  };
@@ -26,6 +27,7 @@ var DipswitchProvider = class {
26
27
  const sdk = createClient({
27
28
  ...this.options,
28
29
  user: user(context),
30
+ workspaceId: workspace(context),
29
31
  refetchDelayMaxMs: ADAPTER_REFETCH_DELAY_MAX_MS
30
32
  });
31
33
  this.sdk = sdk;
@@ -41,10 +43,10 @@ var DipswitchProvider = class {
41
43
  onContextChange(oldContext, next) {
42
44
  const sdk = this.sdk;
43
45
  if (!sdk) return;
44
- if (oldContext.targetingKey === next.targetingKey) return this.pendingContext ?? (sdk.snapshotVersion === void 0 ? Promise.reject(notReady()) : void 0);
46
+ if (oldContext.targetingKey === next.targetingKey && workspace(oldContext) === workspace(next)) return this.pendingContext ?? (sdk.snapshotVersion === void 0 ? Promise.reject(notReady()) : void 0);
45
47
  this.settingContext = true;
46
48
  try {
47
- const pending = sdk.identify(user(next)).then(() => {
49
+ const pending = sdk.identify(user(next), void 0, workspace(next)).then(() => {
48
50
  if (this.sdk !== sdk) return;
49
51
  if (this.pendingContext && this.pendingContext !== pending) return this.pendingContext;
50
52
  this.pendingContext = void 0;
@@ -70,7 +72,12 @@ var DipswitchProvider = class {
70
72
  const result = this.sdk?.getFlagDetails(key);
71
73
  if (!result || result.reason === "NOT_READY") throw notReady();
72
74
  if (result.value === void 0) throw new FlagNotFoundError(`No flag named ${key}.`);
73
- return result;
75
+ const { value, reason, metadata } = result;
76
+ return {
77
+ value,
78
+ reason,
79
+ ...metadata && { flagMetadata: metadata }
80
+ };
74
81
  }
75
82
  resolveStringEvaluation = unsupported;
76
83
  resolveNumberEvaluation = unsupported;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dipswitch/openfeature-web",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Dipswitch provider for the OpenFeature web SDK.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "sideEffects": false,
19
19
  "dependencies": {
20
- "@dipswitch/sdk-js": "0.1.0"
20
+ "@dipswitch/sdk-js": "0.2.0"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@openfeature/web-sdk": "^1.10.0"