@uniformdev/context-devtools 12.2.1-alpha.170

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.txt ADDED
@@ -0,0 +1,2 @@
1
+ © 2022 Uniform Systems, Inc. All Rights Reserved.
2
+ See details of Uniform Systems, Inc. Master Subscription Agreement here: https://uniform.dev/eula
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ Uniform Context DevTools
2
+
3
+ Part of the Uniform Context tracking and analysis platform.
4
+
5
+ part of the [Uniform Platform](https://uniform.app). See our [documentation](https://docs.uniform.app) for more details.
@@ -0,0 +1,35 @@
1
+ import { OutputSeverity, DevToolsState, DevToolsActions, Context } from '@uniformdev/context';
2
+
3
+ declare type DevToolsSettings = {
4
+ apiKey?: string;
5
+ projectId?: string;
6
+ apiHost?: string;
7
+ logLevel?: OutputSeverity;
8
+ /** Current route the app is on */
9
+ route?: string;
10
+ };
11
+ declare type ContextDevToolsProps = {
12
+ state: DevToolsState;
13
+ actions: DevToolsActions;
14
+ settings: DevToolsSettings;
15
+ saveSettings: (settings: DevToolsSettings) => void;
16
+ };
17
+ declare function ContextDevTools(props: ContextDevToolsProps): JSX.Element;
18
+
19
+ declare type EmbeddedContextDevToolsProps = {
20
+ /**
21
+ * Pass a Context instance to connect to DevTools.
22
+ * This is optional, and defaults to a context instance registered in `window`
23
+ * when the `enableContextDevTools()` plugin is activated so no direct contact is required.
24
+ *
25
+ * Using the window interface enables you to render the DevTools in an isolated React app easily,
26
+ * or in non-React apps.
27
+ */
28
+ context?: Context;
29
+ /** Initial settings for the devtools. */
30
+ initialSettings?: DevToolsSettings;
31
+ };
32
+ /** Renders Uniform Context DevTools in an embedded state (as a React component that can be an island on a demo page, for example) */
33
+ declare function EmbeddedContextDevTools({ context, initialSettings }: EmbeddedContextDevToolsProps): JSX.Element;
34
+
35
+ export { ContextDevTools, ContextDevToolsProps, DevToolsSettings, EmbeddedContextDevTools, EmbeddedContextDevToolsProps };
@@ -0,0 +1 @@
1
+ import*as e from"react";import{computeDimensionDisplayName as S,DimensionClient as x}from"@uniformdev/context/api";import{useAsync as C}from"react-use";function f({apiHost:t,apiKey:s,projectId:o}){return C(async()=>!t||!s||!o?{}:(await new x({projectId:o,apiKey:s,apiHost:t}).get()).dimensions.reduce((a,r)=>(a[r.dim]={...r,displayName:S(r)},a),{}),[t,s,o])}function D(t){let{value:s}=f(t.settings);return e.createElement("article",null,e.createElement("h1",null,"MUH DEV TOOLS"),e.createElement("section",null,e.createElement("h2",null,"Dimensions"),e.createElement("ul",null,Object.entries(t.state.scores).map(([o,n])=>{var a,r;let v=(r=(a=s==null?void 0:s[o])==null?void 0:a.displayName)!=null?r:o;return e.createElement("li",{key:o},v,": ",n)}))),e.createElement("details",null,e.createElement("summary",null,"Show raw state"),e.createElement("pre",null,JSON.stringify(t.state,null,2))),e.createElement("button",{type:"button",onClick:()=>t.actions.update({enrichments:[{cat:"cat",key:"alert",str:50}]})},"Update cat_alert enr"),e.createElement("button",{type:"button",onClick:()=>t.actions.rawUpdate([{type:"settest",data:{test:"cat alert!",variant:"nyan"}}])},"Set cat alert a/b test"),e.createElement("fieldset",{style:{display:"flex",flexDirection:"column"}},e.createElement("legend",null,"Configure Settings"),e.createElement("em",null,"Bad form, do not copy this crapcode ;)"),e.createElement("input",{type:"text",value:t.settings.apiHost,placeholder:"API Host",onChange:o=>t.saveSettings({...t.settings,apiHost:o.currentTarget.value})}),e.createElement("input",{type:"text",value:t.settings.apiKey,placeholder:"API Key",onChange:o=>t.saveSettings({...t.settings,apiKey:o.currentTarget.value})}),e.createElement("input",{type:"text",value:t.settings.projectId,placeholder:"Project ID",onChange:o=>t.saveSettings({...t.settings,projectId:o.currentTarget.value})}),e.createElement("select",{value:t.settings.logLevel,placeholder:"Project ID",onChange:o=>t.saveSettings({...t.settings,logLevel:o.currentTarget.value})},e.createElement("option",{value:"none"},"Off"),e.createElement("option",{value:"debug"},"Debug"),e.createElement("option",{value:"info"},"Info"),e.createElement("option",{value:"warn"},"Warn"),e.createElement("option",{value:"error"},"Error"))))}import{Context as h}from"@uniformdev/context";import*as i from"react";function j({context:t,initialSettings:s}){let o=t!=null?t:typeof window!="undefined"?window.__UNIFORM_DEVTOOLS_CONTEXT_INSTANCE__:void 0,n=o!=null?o:new h({manifest:{project:{}}}),[v,a]=i.useState({data:n.storage.data,manifest:n.manifest.data,scores:n.scores,personalizations:[],tests:[]}),[r,T]=i.useState(s!=null?s:{});i.useEffect(()=>{let d=()=>{a(c=>({...c,scores:n.scores,data:n.storage.data,manifest:n.manifest.data}))},l=c=>{a(u=>({...u,personalizations:[...u.personalizations,c]}))},p=c=>{a(u=>({...u,tests:[...u.tests,c]}))};return n.events.on("personalizationResult",l),n.events.on("testResult",p),n.storage.events.on("*",d),()=>{n.storage.events.off("*",d),n.events.off("personalizationResult",l),n.events.off("testResult",p)}},[n]);let y=i.useMemo(()=>({update:l=>n.update(l),forget:()=>n.forget(!1),rawUpdate:l=>n.storage.updateData(l)}),[n]);return o?i.createElement(D,{state:v,actions:y,settings:r,saveSettings:T}):i.createElement("p",null,"Unable to find Uniform Context. Ensure the devtools plugin is activated.")}export{D as ContextDevTools,j as EmbeddedContextDevTools};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var E=Object.create;var d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var T=t=>d(t,"__esModule",{value:!0});var N=(t,o)=>{for(var e in o)d(t,e,{get:o[e],enumerable:!0})},y=(t,o,e,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of O(o))!I.call(t,i)&&(e||i!=="default")&&d(t,i,{get:()=>o[i],enumerable:!(s=w(o,i))||s.enumerable});return t},S=(t,o)=>y(T(d(t!=null?E(P(t)):{},"default",!o&&t&&t.__esModule?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t),z=(t=>(o,e)=>t&&t.get(o)||(e=y(T({}),o,1),t&&t.set(o,e),e))(typeof WeakMap!="undefined"?new WeakMap:0);var U={};N(U,{ContextDevTools:()=>f,EmbeddedContextDevTools:()=>A});var n=S(require("react"));var g=require("@uniformdev/context/api"),x=require("react-use");function C({apiHost:t,apiKey:o,projectId:e}){return(0,x.useAsync)(async()=>!t||!o||!e?{}:(await new g.DimensionClient({projectId:e,apiKey:o,apiHost:t}).get()).dimensions.reduce((r,l)=>(r[l.dim]={...l,displayName:(0,g.computeDimensionDisplayName)(l)},r),{}),[t,o,e])}function f(t){let{value:o}=C(t.settings);return n.createElement("article",null,n.createElement("h1",null,"MUH DEV TOOLS"),n.createElement("section",null,n.createElement("h2",null,"Dimensions"),n.createElement("ul",null,Object.entries(t.state.scores).map(([e,s])=>{var r,l;let i=(l=(r=o==null?void 0:o[e])==null?void 0:r.displayName)!=null?l:e;return n.createElement("li",{key:e},i,": ",s)}))),n.createElement("details",null,n.createElement("summary",null,"Show raw state"),n.createElement("pre",null,JSON.stringify(t.state,null,2))),n.createElement("button",{type:"button",onClick:()=>t.actions.update({enrichments:[{cat:"cat",key:"alert",str:50}]})},"Update cat_alert enr"),n.createElement("button",{type:"button",onClick:()=>t.actions.rawUpdate([{type:"settest",data:{test:"cat alert!",variant:"nyan"}}])},"Set cat alert a/b test"),n.createElement("fieldset",{style:{display:"flex",flexDirection:"column"}},n.createElement("legend",null,"Configure Settings"),n.createElement("em",null,"Bad form, do not copy this crapcode ;)"),n.createElement("input",{type:"text",value:t.settings.apiHost,placeholder:"API Host",onChange:e=>t.saveSettings({...t.settings,apiHost:e.currentTarget.value})}),n.createElement("input",{type:"text",value:t.settings.apiKey,placeholder:"API Key",onChange:e=>t.saveSettings({...t.settings,apiKey:e.currentTarget.value})}),n.createElement("input",{type:"text",value:t.settings.projectId,placeholder:"Project ID",onChange:e=>t.saveSettings({...t.settings,projectId:e.currentTarget.value})}),n.createElement("select",{value:t.settings.logLevel,placeholder:"Project ID",onChange:e=>t.saveSettings({...t.settings,logLevel:e.currentTarget.value})},n.createElement("option",{value:"none"},"Off"),n.createElement("option",{value:"debug"},"Debug"),n.createElement("option",{value:"info"},"Info"),n.createElement("option",{value:"warn"},"Warn"),n.createElement("option",{value:"error"},"Error"))))}var h=require("@uniformdev/context"),a=S(require("react"));function A({context:t,initialSettings:o}){let e=t!=null?t:typeof window!="undefined"?window.__UNIFORM_DEVTOOLS_CONTEXT_INSTANCE__:void 0,s=e!=null?e:new h.Context({manifest:{project:{}}}),[i,r]=a.useState({data:s.storage.data,manifest:s.manifest.data,scores:s.scores,personalizations:[],tests:[]}),[l,R]=a.useState(o!=null?o:{});a.useEffect(()=>{let m=()=>{r(u=>({...u,scores:s.scores,data:s.storage.data,manifest:s.manifest.data}))},c=u=>{r(v=>({...v,personalizations:[...v.personalizations,u]}))},D=u=>{r(v=>({...v,tests:[...v.tests,u]}))};return s.events.on("personalizationResult",c),s.events.on("testResult",D),s.storage.events.on("*",m),()=>{s.storage.events.off("*",m),s.events.off("personalizationResult",c),s.events.off("testResult",D)}},[s]);let b=a.useMemo(()=>({update:c=>s.update(c),forget:()=>s.forget(!1),rawUpdate:c=>s.storage.updateData(c)}),[s]);return e?a.createElement(f,{state:i,actions:b,settings:l,saveSettings:R}):a.createElement("p",null,"Unable to find Uniform Context. Ensure the devtools plugin is activated.")}module.exports=z(U);0&&(module.exports={ContextDevTools,EmbeddedContextDevTools});
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import*as e from"react";import{computeDimensionDisplayName as S,DimensionClient as x}from"@uniformdev/context/api";import{useAsync as C}from"react-use";function f({apiHost:t,apiKey:s,projectId:o}){return C(async()=>!t||!s||!o?{}:(await new x({projectId:o,apiKey:s,apiHost:t}).get()).dimensions.reduce((a,r)=>(a[r.dim]={...r,displayName:S(r)},a),{}),[t,s,o])}function D(t){let{value:s}=f(t.settings);return e.createElement("article",null,e.createElement("h1",null,"MUH DEV TOOLS"),e.createElement("section",null,e.createElement("h2",null,"Dimensions"),e.createElement("ul",null,Object.entries(t.state.scores).map(([o,n])=>{var a,r;let v=(r=(a=s==null?void 0:s[o])==null?void 0:a.displayName)!=null?r:o;return e.createElement("li",{key:o},v,": ",n)}))),e.createElement("details",null,e.createElement("summary",null,"Show raw state"),e.createElement("pre",null,JSON.stringify(t.state,null,2))),e.createElement("button",{type:"button",onClick:()=>t.actions.update({enrichments:[{cat:"cat",key:"alert",str:50}]})},"Update cat_alert enr"),e.createElement("button",{type:"button",onClick:()=>t.actions.rawUpdate([{type:"settest",data:{test:"cat alert!",variant:"nyan"}}])},"Set cat alert a/b test"),e.createElement("fieldset",{style:{display:"flex",flexDirection:"column"}},e.createElement("legend",null,"Configure Settings"),e.createElement("em",null,"Bad form, do not copy this crapcode ;)"),e.createElement("input",{type:"text",value:t.settings.apiHost,placeholder:"API Host",onChange:o=>t.saveSettings({...t.settings,apiHost:o.currentTarget.value})}),e.createElement("input",{type:"text",value:t.settings.apiKey,placeholder:"API Key",onChange:o=>t.saveSettings({...t.settings,apiKey:o.currentTarget.value})}),e.createElement("input",{type:"text",value:t.settings.projectId,placeholder:"Project ID",onChange:o=>t.saveSettings({...t.settings,projectId:o.currentTarget.value})}),e.createElement("select",{value:t.settings.logLevel,placeholder:"Project ID",onChange:o=>t.saveSettings({...t.settings,logLevel:o.currentTarget.value})},e.createElement("option",{value:"none"},"Off"),e.createElement("option",{value:"debug"},"Debug"),e.createElement("option",{value:"info"},"Info"),e.createElement("option",{value:"warn"},"Warn"),e.createElement("option",{value:"error"},"Error"))))}import{Context as h}from"@uniformdev/context";import*as i from"react";function j({context:t,initialSettings:s}){let o=t!=null?t:typeof window!="undefined"?window.__UNIFORM_DEVTOOLS_CONTEXT_INSTANCE__:void 0,n=o!=null?o:new h({manifest:{project:{}}}),[v,a]=i.useState({data:n.storage.data,manifest:n.manifest.data,scores:n.scores,personalizations:[],tests:[]}),[r,T]=i.useState(s!=null?s:{});i.useEffect(()=>{let d=()=>{a(c=>({...c,scores:n.scores,data:n.storage.data,manifest:n.manifest.data}))},l=c=>{a(u=>({...u,personalizations:[...u.personalizations,c]}))},p=c=>{a(u=>({...u,tests:[...u.tests,c]}))};return n.events.on("personalizationResult",l),n.events.on("testResult",p),n.storage.events.on("*",d),()=>{n.storage.events.off("*",d),n.events.off("personalizationResult",l),n.events.off("testResult",p)}},[n]);let y=i.useMemo(()=>({update:l=>n.update(l),forget:()=>n.forget(!1),rawUpdate:l=>n.storage.updateData(l)}),[n]);return o?i.createElement(D,{state:v,actions:y,settings:r,saveSettings:T}):i.createElement("p",null,"Unable to find Uniform Context. Ensure the devtools plugin is activated.")}export{D as ContextDevTools,j as EmbeddedContextDevTools};
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@uniformdev/context-devtools",
3
+ "version": "12.2.1-alpha.170+899ea147",
4
+ "description": "Uniform Context developer tools components",
5
+ "license": "SEE LICENSE IN LICENSE.txt",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.esm.js",
8
+ "exports": {
9
+ "import": {
10
+ "node": "./dist/index.mjs",
11
+ "default": "./dist/index.esm.js"
12
+ },
13
+ "require": "./dist/index.js"
14
+ },
15
+ "types": "./dist/index.d.ts",
16
+ "sideEffects": false,
17
+ "scripts": {
18
+ "build": "tsup",
19
+ "dev": "tsup --watch",
20
+ "clean": "rimraf dist",
21
+ "test": "jest --maxWorkers=1 --passWithNoTests",
22
+ "lint": "eslint \"src/**/*.{js,ts,tsx}\"",
23
+ "format": "prettier --write \"src/**/*.{js,ts,tsx}\"",
24
+ "ci:verify": "run-p lint test",
25
+ "ci:build": "tsup --minify --clean"
26
+ },
27
+ "devDependencies": {
28
+ "@types/jest": "27.4.0",
29
+ "@types/node": "16.11.12",
30
+ "@types/react": "17.0.39",
31
+ "eslint": "8.7.0",
32
+ "eslint-plugin-react": "7.28.0",
33
+ "eslint-plugin-react-hooks": "4.3.0",
34
+ "jest": "27.4.7",
35
+ "npm-run-all": "4.1.5",
36
+ "rimraf": "3.0.2",
37
+ "ts-jest": "27.1.3",
38
+ "tsup": "5.11.11"
39
+ },
40
+ "dependencies": {
41
+ "@uniformdev/context": "^12.2.1-alpha.170+899ea147",
42
+ "react": "^17.0.2",
43
+ "react-dom": "^17.0.2",
44
+ "react-use": "17.3.2"
45
+ },
46
+ "files": [
47
+ "/dist"
48
+ ],
49
+ "gitHead": "899ea147cdea482a014e02911fc9554c81dd2cbc"
50
+ }