@dif.sh/react 0.4.1 → 0.4.3

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
@@ -71,6 +71,15 @@ export function CheckoutCTA() {
71
71
  You can also keep using the bare import directly in non-component code —
72
72
  both paths read the same module-level state set by `<DifProvider>`.
73
73
 
74
+ ## Preview & QA forcing
75
+
76
+ `<DifProvider>` reads the `?_dif=` URL param / `_dif` cookie on mount, so anyone
77
+ can force a variant by opening a link — `?_dif=checkout-cta-v2=variant_a`
78
+ (`?_dif=off` clears). A forced assignment **never fires an exposure**, and a
79
+ small preview badge shows the active forces. Disable per-env with
80
+ `allowOverrides={false}`, or hide the badge with `preview={false}`. Generate the
81
+ link with `npx dif qa --force <exp>=<variant> --preview-url <url>`.
82
+
74
83
  ## What this package does, what it doesn't
75
84
 
76
85
  **Does:**
@@ -12,6 +12,10 @@ export interface DifContextValue {
12
12
  export interface DifProviderProps {
13
13
  config: DifInitConfig;
14
14
  children: ReactNode;
15
+ /** Honor `?_dif=` / `_dif`-cookie QA forces. Default `true`; set `false` to gate by env. */
16
+ allowOverrides?: boolean;
17
+ /** Show the preview badge when a force is active. Default `true`. */
18
+ preview?: boolean;
15
19
  }
16
20
  /**
17
21
  * Initializes the SDK exactly once and provides `useDif()` to descendants.
@@ -20,7 +24,7 @@ export interface DifProviderProps {
20
24
  * provider with a different config will replace the previous config. v0 does
21
25
  * not re-init on prop changes — pass a stable config object.
22
26
  */
23
- export declare function DifProvider({ config, children }: DifProviderProps): import("react/jsx-runtime").JSX.Element;
27
+ export declare function DifProvider({ config, children, allowOverrides, preview }: DifProviderProps): import("react/jsx-runtime").JSX.Element;
24
28
  /** Hook returning `{ track, exposure }`. Must be called inside `<DifProvider>`. */
25
29
  export declare function useDif(): DifContextValue;
26
30
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAEA,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E;IAC9E,QAAQ,EAAE,YAAY,CAAC;CACxB;AAID,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,SAAS,CAAC;IACpB,4FAA4F;IAC5F,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,qEAAqE;IACrE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE,gBAAgB,2CAoB1F;AAED,mFAAmF;AACnF,wBAAgB,MAAM,IAAI,eAAe,CAMxC"}
package/dist/provider.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { createContext, useContext, useRef } from "react";
4
- import { dif } from "@dif.sh/sdk";
3
+ import { createContext, useContext, useRef, useEffect } from "react";
4
+ import { dif, syncOverrides, mountDifPreview } from "@dif.sh/sdk";
5
5
  const DifContext = createContext(null);
6
6
  /**
7
7
  * Initializes the SDK exactly once and provides `useDif()` to descendants.
@@ -10,12 +10,19 @@ const DifContext = createContext(null);
10
10
  * provider with a different config will replace the previous config. v0 does
11
11
  * not re-init on prop changes — pass a stable config object.
12
12
  */
13
- export function DifProvider({ config, children }) {
13
+ export function DifProvider({ config, children, allowOverrides, preview }) {
14
14
  const initialized = useRef(false);
15
15
  if (!initialized.current) {
16
16
  dif.init(config);
17
17
  initialized.current = true;
18
18
  }
19
+ // Client-only (effects don't run during SSR): reconcile QA/preview forces from
20
+ // the `?_dif=` URL param / `_dif` cookie, then show the badge if one is active.
21
+ useEffect(() => {
22
+ syncOverrides({ allow: allowOverrides !== false });
23
+ if (preview !== false)
24
+ mountDifPreview();
25
+ }, [allowOverrides, preview]);
19
26
  const value = {
20
27
  track: (metric, opts) => dif.track(metric, opts),
21
28
  exposure: ((id, branches) => dif(id, branches)),
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAkB,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAclC,MAAM,UAAU,GAAG,aAAa,CAAyB,IAAI,CAAC,CAAC;AAO/D;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAoB;IAChE,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QACzB,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjB,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC;IAC7B,CAAC;IAED,MAAM,KAAK,GAAoB;QAC7B,KAAK,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC;QAChD,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAiB;KAChE,CAAC;IAEF,OAAO,KAAC,UAAU,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAuB,CAAC;AAC7E,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,MAAM;IACpB,MAAM,GAAG,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,aAAa,EA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QACT,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dif.sh/react",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "React adapter for @dif.sh/sdk — provider + useDif hook.",
5
5
  "license": "MIT",
6
6
  "type": "module",