@quonfig/react 0.0.5 → 0.0.8
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 +7 -7
- package/dist/index.cjs +9 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +9 -92
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -37,13 +37,13 @@ const WrappedApp = () => {
|
|
|
37
37
|
|
|
38
38
|
Here's an explanation of each provider prop:
|
|
39
39
|
|
|
40
|
-
| property | required | type | purpose
|
|
41
|
-
| ------------------- | -------- | ----------------- |
|
|
42
|
-
| `sdkKey` | yes | `string` | your Quonfig SDK key
|
|
43
|
-
| `onError` | no | `(error) => void` | callback invoked if quonfig fails to initialize
|
|
44
|
-
| `contextAttributes` | no | `Contexts` | this is the context attributes object you passed when setting up the provider
|
|
45
|
-
| `timeout` | no | `number` | initialization timeout (defaults to 10 seconds)
|
|
46
|
-
| `pollInterval` | no | `number` | configures quonfig to poll for updates every `pollInterval` ms.
|
|
40
|
+
| property | required | type | purpose |
|
|
41
|
+
| ------------------- | -------- | ----------------- | ----------------------------------------------------------------------------- |
|
|
42
|
+
| `sdkKey` | yes | `string` | your Quonfig SDK key |
|
|
43
|
+
| `onError` | no | `(error) => void` | callback invoked if quonfig fails to initialize |
|
|
44
|
+
| `contextAttributes` | no | `Contexts` | this is the context attributes object you passed when setting up the provider |
|
|
45
|
+
| `timeout` | no | `number` | initialization timeout (defaults to 10 seconds) |
|
|
46
|
+
| `pollInterval` | no | `number` | configures quonfig to poll for updates every `pollInterval` ms. |
|
|
47
47
|
|
|
48
48
|
### Usage in Your Components
|
|
49
49
|
|
package/dist/index.cjs
CHANGED
|
@@ -7,96 +7,12 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
7
7
|
|
|
8
8
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
12
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
-
};
|
|
10
|
+
// src/index.tsx
|
|
14
11
|
|
|
15
|
-
//
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
packageManager: "yarn@4.11.0",
|
|
20
|
-
name: "@quonfig/react",
|
|
21
|
-
version: "0.0.5",
|
|
22
|
-
description: "Feature Flags & Dynamic Configuration as a Service",
|
|
23
|
-
main: "dist/index.cjs",
|
|
24
|
-
module: "dist/index.mjs",
|
|
25
|
-
types: "dist/index.d.ts",
|
|
26
|
-
repository: {
|
|
27
|
-
type: "git",
|
|
28
|
-
url: "https://github.com/quonfig/sdk-react.git"
|
|
29
|
-
},
|
|
30
|
-
bugs: {
|
|
31
|
-
url: "https://github.com/quonfig/sdk-react/issues"
|
|
32
|
-
},
|
|
33
|
-
homepage: "https://github.com/quonfig/sdk-react#readme",
|
|
34
|
-
exports: {
|
|
35
|
-
".": {
|
|
36
|
-
types: "./dist/index.d.ts",
|
|
37
|
-
import: "./dist/index.mjs",
|
|
38
|
-
require: "./dist/index.cjs",
|
|
39
|
-
default: "./dist/index.cjs"
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
files: [
|
|
43
|
-
"dist/",
|
|
44
|
-
"README.md",
|
|
45
|
-
"LICENSE",
|
|
46
|
-
"CHANGELOG.md"
|
|
47
|
-
],
|
|
48
|
-
scripts: {
|
|
49
|
-
build: "rm -rf dist/ && tsup",
|
|
50
|
-
dev: "tsup --watch",
|
|
51
|
-
bundle: "esbuild --minify --target=esnext --bundle --outfile=dist/quonfig-react.bundle.js --global-name=window.quonfigReactNamespace dist/index.cjs && echo 'window.quonfigReact = window.quonfigReactNamespace.quonfigReact' >> dist/quonfig-react.bundle.js",
|
|
52
|
-
test: "tsup && jest --verbose",
|
|
53
|
-
lint: "eslint --ext .ts,.tsx src/",
|
|
54
|
-
prettier: "prettier . -l",
|
|
55
|
-
"prettier:fix": "prettier --write ."
|
|
56
|
-
},
|
|
57
|
-
author: "Jeffrey Chupp",
|
|
58
|
-
license: "ISC",
|
|
59
|
-
keywords: [
|
|
60
|
-
"feature-flags",
|
|
61
|
-
"config"
|
|
62
|
-
],
|
|
63
|
-
devDependencies: {
|
|
64
|
-
"@quonfig/javascript": ">=0.0.3",
|
|
65
|
-
"@testing-library/jest-dom": "^5.16.5",
|
|
66
|
-
"@testing-library/react": "^13.3.0",
|
|
67
|
-
"@types/jest": "^28.1.6",
|
|
68
|
-
"@types/node": "^18.6.5",
|
|
69
|
-
"@types/react": "^19.1.10",
|
|
70
|
-
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
|
71
|
-
"@typescript-eslint/parser": "^5.33.0",
|
|
72
|
-
eslint: "^8.21.0",
|
|
73
|
-
"eslint-config-airbnb": "^19.0.4",
|
|
74
|
-
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
75
|
-
"eslint-config-prettier": "^8.8.0",
|
|
76
|
-
"eslint-plugin-import": "^2.26.0",
|
|
77
|
-
"eslint-plugin-jest": "^26.8.2",
|
|
78
|
-
"eslint-plugin-jsx-a11y": "^6.6.1",
|
|
79
|
-
"eslint-plugin-react": "^7.30.1",
|
|
80
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
81
|
-
jest: "^28.1.3",
|
|
82
|
-
"jest-environment-jsdom": "^28.1.3",
|
|
83
|
-
"jest-fetch-mock": "^3.0.3",
|
|
84
|
-
prettier: "^3.0.0",
|
|
85
|
-
react: "^19.1.1",
|
|
86
|
-
"react-dom": "^19.1.1",
|
|
87
|
-
"ts-jest": "^28.0.7",
|
|
88
|
-
"ts-node": "^10.9.1",
|
|
89
|
-
tsup: "^8.4.0",
|
|
90
|
-
typescript: "^4.7.4"
|
|
91
|
-
},
|
|
92
|
-
peerDependencies: {
|
|
93
|
-
"@quonfig/javascript": ">=0.0.3",
|
|
94
|
-
react: "^16 || ^17 || ^18 || ^19"
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
var { version } = require_package();
|
|
12
|
+
// src/version.ts
|
|
13
|
+
var version_default = "0.0.7";
|
|
14
|
+
|
|
15
|
+
// src/QuonfigProvider.tsx
|
|
100
16
|
var defaultContext = {
|
|
101
17
|
get: (_key) => void 0,
|
|
102
18
|
getDuration: (_key) => void 0,
|
|
@@ -206,12 +122,13 @@ function QuonfigProvider({
|
|
|
206
122
|
if (!sdkKey) {
|
|
207
123
|
throw new Error("QuonfigProvider: sdkKey is required");
|
|
208
124
|
}
|
|
209
|
-
quonfigClient.
|
|
125
|
+
quonfigClient.clientName = "react";
|
|
126
|
+
quonfigClient.clientVersion = version_default;
|
|
127
|
+
const resolvedApiUrls = apiUrls != null ? apiUrls : apiUrl ? [apiUrl] : void 0;
|
|
210
128
|
const initOptions = {
|
|
211
129
|
context: contextAttributes,
|
|
212
130
|
sdkKey,
|
|
213
|
-
|
|
214
|
-
apiUrls,
|
|
131
|
+
apiUrls: resolvedApiUrls,
|
|
215
132
|
timeout,
|
|
216
133
|
afterEvaluationCallback,
|
|
217
134
|
collectEvaluationSummaries,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/QuonfigProvider.tsx","../src/QuonfigTestProvider.tsx"],"names":["quonfig","React","Quonfig","encodeContexts"],"mappings":";;;;;;;;;;;;;;;AAAA,IAAA,eAAA,GAAA,UAAA,CAAA;AAAA,EAAA,cAAA,CAAA,OAAA,EAAA,MAAA,EAAA;AAAA,IAAA,MAAA,CAAA,OAAA,GAAA;AAAA,MACE,cAAA,EAAkB,aAAA;AAAA,MAClB,IAAA,EAAQ,gBAAA;AAAA,MACR,OAAA,EAAW,OAAA;AAAA,MACX,WAAA,EAAe,oDAAA;AAAA,MACf,IAAA,EAAQ,gBAAA;AAAA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onfig/react\",\n \"version\": \"0.0.5\",\n \"description\": \"Feature Flags & Dynamic Configuration as a Service\",\n \"main\": \"dist/index.cjs\",\n \"module\": \"dist/index.mjs\",\n \"types\": \"dist/index.d.ts\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/quonfig/sdk-react.git\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/quonfig/sdk-react/issues\"\n },\n \"homepage\": \"https://github.com/quonfig/sdk-react#readme\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.cjs\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"files\": [\n \"dist/\",\n \"README.md\",\n \"LICENSE\",\n \"CHANGELOG.md\"\n ],\n \"scripts\": {\n \"build\": \"rm -rf dist/ && tsup\",\n \"dev\": \"tsup --watch\",\n \"bundle\": \"esbuild --minify --target=esnext --bundle --outfile=dist/quonfig-react.bundle.js --global-name=window.quonfigReactNamespace dist/index.cjs && echo 'window.quonfigReact = window.quonfigReactNamespace.quonfigReact' >> dist/quonfig-react.bundle.js\",\n \"test\": \"tsup && jest --verbose\",\n \"lint\": \"eslint --ext .ts,.tsx src/\",\n \"prettier\": \"prettier . -l\",\n \"prettier:fix\": \"prettier --write .\"\n },\n \"author\": \"Jeffrey Chupp\",\n \"license\": \"ISC\",\n \"keywords\": [\n \"feature-flags\",\n \"config\"\n ],\n \"devDependencies\": {\n \"@quonfig/javascript\": \">=0.0.3\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^13.3.0\",\n \"@types/jest\": \"^28.1.6\",\n \"@types/node\": \"^18.6.5\",\n \"@types/react\": \"^19.1.10\",\n \"@typescript-eslint/eslint-plugin\": \"^5.33.0\",\n \"@typescript-eslint/parser\": \"^5.33.0\",\n \"eslint\": \"^8.21.0\",\n \"eslint-config-airbnb\": \"^19.0.4\",\n \"eslint-config-airbnb-typescript\": \"^17.0.0\",\n \"eslint-config-prettier\": \"^8.8.0\",\n \"eslint-plugin-import\": \"^2.26.0\",\n \"eslint-plugin-jest\": \"^26.8.2\",\n \"eslint-plugin-jsx-a11y\": \"^6.6.1\",\n \"eslint-plugin-react\": \"^7.30.1\",\n \"eslint-plugin-react-hooks\": \"^4.6.0\",\n \"jest\": \"^28.1.3\",\n \"jest-environment-jsdom\": \"^28.1.3\",\n \"jest-fetch-mock\": \"^3.0.3\",\n \"prettier\": \"^3.0.0\",\n \"react\": \"^19.1.1\",\n \"react-dom\": \"^19.1.1\",\n \"ts-jest\": \"^28.0.7\",\n \"ts-node\": \"^10.9.1\",\n \"tsup\": \"^8.4.0\",\n \"typescript\": \"^4.7.4\"\n },\n \"peerDependencies\": {\n \"@quonfig/javascript\": \">=0.0.3\",\n \"react\": \"^16 || ^17 || ^18 || ^19\"\n }\n}\n","import React, { PropsWithChildren } from \"react\";\nimport {\n quonfig,\n type InitOptions,\n type ConfigValue,\n type Contexts,\n Quonfig,\n TypedFrontEndConfigurationRaw,\n FrontEndConfigurationRaw,\n Duration,\n encodeContexts,\n} from \"@quonfig/javascript\";\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version } = require(\"../package.json\");\n\n// @quonfig/cli#generate will create interfaces into this namespace for React to consume\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface FrontEndConfigurationAccessor {}\n\nexport type TypedFrontEndConfigurationAccessor = keyof FrontEndConfigurationAccessor extends never\n ? Record<string, unknown>\n : {\n [TypedFlagKey in keyof FrontEndConfigurationAccessor]: FrontEndConfigurationAccessor[TypedFlagKey];\n };\n\ntype ClassMethods<T> = { [K in keyof T]: T[K] };\n\ntype QuonfigTypesafeClass<T = unknown> = new (\n // eslint-disable-next-line no-shadow\n quonfig: Quonfig\n) => T;\n\ntype SharedSettings = Partial<\n Pick<\n InitOptions,\n | \"sdkKey\"\n | \"apiUrl\"\n | \"apiUrls\"\n | \"timeout\"\n | \"collectEvaluationSummaries\"\n | \"collectLoggerNames\"\n >\n> & {\n // We need to redefine the afterEvaluationCallback type to ensure proper dynamic resolution of K\n afterEvaluationCallback?: <K extends keyof TypedFrontEndConfigurationRaw>(\n key: K,\n value: TypedFrontEndConfigurationRaw[K],\n contexts: Contexts | undefined\n ) => void;\n pollInterval?: number;\n onError?: (error: Error) => void;\n};\n\nexport type BaseContext = {\n get: <K extends keyof TypedFrontEndConfigurationRaw>(key: K) => TypedFrontEndConfigurationRaw[K];\n getDuration: <\n K extends keyof FrontEndConfigurationRaw extends never\n ? string\n : {\n [IK in keyof TypedFrontEndConfigurationRaw]: TypedFrontEndConfigurationRaw[IK] extends Duration\n ? IK\n : never;\n }[keyof TypedFrontEndConfigurationRaw],\n >(\n key: K\n ) => Duration | undefined;\n contextAttributes: Contexts;\n isEnabled: <\n K extends keyof FrontEndConfigurationRaw extends never\n ? string\n : {\n [IK in keyof TypedFrontEndConfigurationRaw]: TypedFrontEndConfigurationRaw[IK] extends boolean\n ? IK\n : never;\n }[keyof TypedFrontEndConfigurationRaw],\n >(\n key: K\n ) => boolean;\n loading: boolean;\n quonfig: typeof quonfig;\n keys: (keyof TypedFrontEndConfigurationRaw)[];\n settings: SharedSettings;\n};\n\nexport type ProvidedContext = BaseContext & ClassMethods<QuonfigTypesafeClass>;\n\nexport const defaultContext: BaseContext = {\n get: (_key) => undefined,\n getDuration: (_key) => undefined,\n isEnabled: (_key) => false,\n keys: [],\n loading: true,\n contextAttributes: {},\n quonfig,\n settings: {},\n};\n\nexport const QuonfigContext = React.createContext<ProvidedContext>(\n defaultContext as ProvidedContext\n);\n\n// This is a factory function that creates a fully typed useQuonfig hook for a specific QuonfigTypesafe class\nexport function createQuonfigHook<T>(TypesafeClass: QuonfigTypesafeClass<T>) {\n return function useQuonfigHook(): BaseContext & T {\n const baseContext = React.useContext(QuonfigContext);\n\n // Memoize the typesafe instance to prevent unnecessary constructor calls\n const typesafeInstance = React.useMemo(() => {\n const instance = new TypesafeClass(baseContext.quonfig);\n\n // Copy baseContext properties to typesafeInstance except for `get` + `quonfig`\n Object.assign(instance as any, {\n getDuration: baseContext.getDuration,\n contextAttributes: baseContext.contextAttributes,\n isEnabled: baseContext.isEnabled,\n loading: baseContext.loading,\n keys: baseContext.keys,\n settings: baseContext.settings,\n });\n\n return instance;\n }, [baseContext]);\n\n return typesafeInstance as BaseContext & T;\n };\n}\n\n// Basic hook for general use - requires type parameter\nexport const useBaseQuonfig = () => React.useContext(QuonfigContext);\n\n// General hook that returns the context with any explicit type\nexport const useQuonfig = (): ProvidedContext => useBaseQuonfig() as unknown as ProvidedContext;\n\nlet globalQuonfigIsTaken = false;\n\nexport const assignQuonfigClient = () => {\n if (globalQuonfigIsTaken) {\n return new Quonfig();\n }\n\n globalQuonfigIsTaken = true;\n return quonfig;\n};\n\nexport type QuonfigProviderProps = SharedSettings & {\n sdkKey: string;\n contextAttributes?: Contexts;\n initialFlags?: Record<string, unknown>;\n};\n\nconst getContextKey = (\n contextAttributes: Contexts,\n onError: (e: Error) => void\n): string => {\n try {\n if (Object.keys(contextAttributes).length === 0) {\n // eslint-disable-next-line no-console\n console.warn(\n \"QuonfigProvider: You haven't passed any contextAttributes. See https://docs.quonfig.com/docs/sdks/react#using-context\"\n );\n }\n\n return encodeContexts(contextAttributes);\n } catch (e) {\n onError(e as Error);\n return \"\";\n }\n};\n\nfunction QuonfigProvider({\n sdkKey,\n contextAttributes = {},\n onError = (e: unknown) => {\n // eslint-disable-next-line no-console\n console.error(e);\n },\n initialFlags,\n children,\n timeout,\n apiUrl,\n apiUrls,\n pollInterval,\n afterEvaluationCallback = undefined,\n collectEvaluationSummaries,\n collectLoggerNames,\n}: PropsWithChildren<QuonfigProviderProps>) {\n const settings = {\n sdkKey,\n apiUrl,\n apiUrls,\n timeout,\n pollInterval,\n onError,\n afterEvaluationCallback,\n collectEvaluationSummaries,\n collectLoggerNames,\n };\n\n // We use this state to prevent a double-init when useEffect fires due to\n // StrictMode\n const mostRecentlyLoadingContextKey = React.useRef<string | undefined>(undefined);\n // We use this state to pass the loading state to the Provider (updating\n // currentLoadingContextKey won't trigger an update)\n const [loading, setLoading] = React.useState(true);\n const [initialLoad, setInitialLoad] = React.useState(true);\n // Here we track the current identity so we can reload our config when it\n // changes\n const [loadedContextKey, setLoadedContextKey] = React.useState(\"\");\n\n const quonfigClient: Quonfig = React.useMemo(() => assignQuonfigClient(), []);\n\n const contextKey = getContextKey(contextAttributes, onError);\n\n if (initialFlags && initialLoad) {\n quonfigClient.hydrate(initialFlags);\n setInitialLoad(false);\n setLoadedContextKey(contextKey);\n setLoading(false);\n mostRecentlyLoadingContextKey.current = contextKey;\n\n if (pollInterval) {\n // eslint-disable-next-line no-console\n console.warn(\"Polling is not supported when hydrating flags via initialFlags\");\n }\n }\n\n React.useEffect(() => {\n setInitialLoad(false);\n\n if (mostRecentlyLoadingContextKey.current === contextKey) {\n return;\n }\n\n setLoading(true);\n try {\n if (mostRecentlyLoadingContextKey.current === undefined) {\n mostRecentlyLoadingContextKey.current = contextKey;\n\n if (!sdkKey) {\n throw new Error(\"QuonfigProvider: sdkKey is required\");\n }\n\n quonfigClient.clientNameString = \"sdk-react\";\n\n const initOptions: InitOptions = {\n context: contextAttributes,\n sdkKey,\n apiUrl,\n apiUrls,\n timeout,\n afterEvaluationCallback,\n collectEvaluationSummaries,\n collectLoggerNames,\n };\n\n quonfigClient\n .init(initOptions)\n .then(() => {\n setLoadedContextKey(contextKey);\n setLoading(false);\n\n if (pollInterval) {\n quonfigClient.poll({ frequencyInMs: pollInterval });\n }\n })\n .catch((reason: any) => {\n setLoading(false);\n onError(reason);\n });\n } else {\n mostRecentlyLoadingContextKey.current = contextKey;\n\n quonfigClient\n .updateContext(contextAttributes)\n .then(() => {\n setLoadedContextKey(contextKey);\n setLoading(false);\n })\n .catch((reason: any) => {\n setLoading(false);\n onError(reason);\n });\n }\n } catch (e) {\n setLoading(false);\n onError(e as Error);\n }\n }, [\n sdkKey,\n loadedContextKey,\n contextKey,\n loading,\n setLoading,\n onError,\n quonfigClient.instanceHash,\n ]);\n\n const value = React.useMemo(() => {\n const baseContext: ProvidedContext = {\n isEnabled: quonfigClient.isEnabled.bind(quonfigClient),\n contextAttributes,\n get: quonfigClient.get.bind(quonfigClient),\n getDuration: quonfigClient.getDuration.bind(quonfigClient),\n keys: Object.keys(quonfigClient.extract()),\n quonfig: quonfigClient,\n loading,\n settings,\n };\n\n return baseContext;\n }, [loadedContextKey, loading, quonfigClient.instanceHash, settings]);\n\n return <QuonfigContext.Provider value={value}>{children}</QuonfigContext.Provider>;\n}\n\nexport { QuonfigProvider, ConfigValue, SharedSettings, QuonfigTypesafeClass };\n","import React, { PropsWithChildren } from \"react\";\nimport { QuonfigContext, assignQuonfigClient, ProvidedContext } from \"./QuonfigProvider\";\n\nexport type QuonfigTestProviderProps = {\n config: Record<string, any>;\n sdkKey?: string;\n};\n\nfunction QuonfigTestProvider({\n sdkKey,\n config,\n children,\n}: PropsWithChildren<QuonfigTestProviderProps>) {\n const get = (key: string) => config[key];\n const getDuration = (key: string) => config[key];\n const isEnabled = (key: string) => !!get(key);\n\n const quonfigClient = React.useMemo(() => assignQuonfigClient(), []);\n\n const value = React.useMemo(() => {\n quonfigClient.get = get;\n quonfigClient.getDuration = getDuration;\n quonfigClient.isEnabled = isEnabled;\n\n const baseContext: ProvidedContext = {\n isEnabled,\n contextAttributes: config.contextAttributes,\n get,\n getDuration,\n loading: false,\n quonfig: quonfigClient,\n keys: Object.keys(config),\n settings: { sdkKey: sdkKey ?? \"fake-sdk-key-via-the-test-provider\" },\n };\n\n return baseContext;\n }, [config, quonfigClient, sdkKey]);\n\n return <QuonfigContext.Provider value={value}>{children}</QuonfigContext.Provider>;\n}\n\nexport { QuonfigTestProvider };\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/version.ts","../src/QuonfigProvider.tsx","../src/QuonfigTestProvider.tsx"],"names":["quonfig","React","Quonfig","encodeContexts"],"mappings":";;;;;;;;;;;;AACA,IAAO,eAAA,GAAQ,OAAA;;;ACkFR,IA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c,GAAA,GAAM,GAAA;AACpB,IAAA,aAAA,CAAc,WAAA,GAAc,WAAA;AAC5B,IAAA,aAAA,CAAc,SAAA,GAAY,SAAA;AAE1B,IAAA,MAAM,WAAA,GAA+B;AAAA,MACnC,SAAA;AAAA,MACA,mBAAmB,MAAA,CAAO,iBAAA;AAAA,MAC1B,GAAA;AAAA,MACA,WAAA;AAAA,MACA,OAAA,EAAS,KAAA;AAAA,MACT,OAAA,EAAS,aAAA;AAAA,MACT,IAAA,EAAM,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA;AAAA,MACxB,QAAA,EAAU,EAAE,MAAA,EAAQ,MAAA,IAAA,IAAA,GAAA,MAAA,GAAU,oCAAA;AAAqC,KACrE;AAEA,IAAA,OAAO,WAAA;AAAA,EACT,CAAA,EAAG,CAAC,MAAA,EAAQ,aAAA,EAAe,MAAM,CAAC,CAAA;AAElC,EAAA,uBAAOA,sBAAAA,CAAA,aAAA,CAAC,eAAe,QAAA,EAAf,EAAwB,SAAe,QAAS,CAAA;AAC1D","file":"index.cjs","sourcesContent":["// AUTO-GENERATED from package.json by scripts/generate-version.mjs — do not edit.\nexport default \"0.0.7\";\n","import React, { PropsWithChildren } from \"react\";\nimport {\n quonfig,\n type InitOptions,\n type ConfigValue,\n type Contexts,\n Quonfig,\n TypedFrontEndConfigurationRaw,\n FrontEndConfigurationRaw,\n Duration,\n encodeContexts,\n} from \"@quonfig/javascript\";\nimport reactSdkVersion from \"./version\";\n\n// @quonfig/cli#generate will create interfaces into this namespace for React to consume\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface FrontEndConfigurationAccessor {}\n\nexport type TypedFrontEndConfigurationAccessor = keyof FrontEndConfigurationAccessor extends never\n ? Record<string, unknown>\n : {\n [TypedFlagKey in keyof FrontEndConfigurationAccessor]: FrontEndConfigurationAccessor[TypedFlagKey];\n };\n\ntype ClassMethods<T> = { [K in keyof T]: T[K] };\n\ntype QuonfigTypesafeClass<T = unknown> = new (\n // eslint-disable-next-line no-shadow\n quonfig: Quonfig\n) => T;\n\ntype SharedSettings = Partial<\n Pick<\n InitOptions,\n \"sdkKey\" | \"apiUrls\" | \"timeout\" | \"collectEvaluationSummaries\" | \"collectLoggerNames\"\n >\n> & {\n // Convenience alias for a single API URL — normalized to apiUrls=[apiUrl]\n // before being passed to the underlying SDK, which only accepts apiUrls.\n apiUrl?: string;\n // We need to redefine the afterEvaluationCallback type to ensure proper dynamic resolution of K\n afterEvaluationCallback?: <K extends keyof TypedFrontEndConfigurationRaw>(\n key: K,\n value: TypedFrontEndConfigurationRaw[K],\n contexts: Contexts | undefined\n ) => void;\n pollInterval?: number;\n onError?: (error: Error) => void;\n};\n\nexport type BaseContext = {\n get: <K extends keyof TypedFrontEndConfigurationRaw>(key: K) => TypedFrontEndConfigurationRaw[K];\n getDuration: <\n K extends keyof FrontEndConfigurationRaw extends never\n ? string\n : {\n [IK in keyof TypedFrontEndConfigurationRaw]: TypedFrontEndConfigurationRaw[IK] extends Duration\n ? IK\n : never;\n }[keyof TypedFrontEndConfigurationRaw],\n >(\n key: K\n ) => Duration | undefined;\n contextAttributes: Contexts;\n isEnabled: <\n K extends keyof FrontEndConfigurationRaw extends never\n ? string\n : {\n [IK in keyof TypedFrontEndConfigurationRaw]: TypedFrontEndConfigurationRaw[IK] extends boolean\n ? IK\n : never;\n }[keyof TypedFrontEndConfigurationRaw],\n >(\n key: K\n ) => boolean;\n loading: boolean;\n quonfig: typeof quonfig;\n keys: (keyof TypedFrontEndConfigurationRaw)[];\n settings: SharedSettings;\n};\n\nexport type ProvidedContext = BaseContext & ClassMethods<QuonfigTypesafeClass>;\n\nexport const defaultContext: BaseContext = {\n get: (_key) => undefined,\n getDuration: (_key) => undefined,\n isEnabled: (_key) => false,\n keys: [],\n loading: true,\n contextAttributes: {},\n quonfig,\n settings: {},\n};\n\nexport const QuonfigContext = React.createContext<ProvidedContext>(\n defaultContext as ProvidedContext\n);\n\n// This is a factory function that creates a fully typed useQuonfig hook for a specific QuonfigTypesafe class\nexport function createQuonfigHook<T>(TypesafeClass: QuonfigTypesafeClass<T>) {\n return function useQuonfigHook(): BaseContext & T {\n const baseContext = React.useContext(QuonfigContext);\n\n // Memoize the typesafe instance to prevent unnecessary constructor calls\n const typesafeInstance = React.useMemo(() => {\n const instance = new TypesafeClass(baseContext.quonfig);\n\n // Copy baseContext properties to typesafeInstance except for `get` + `quonfig`\n Object.assign(instance as any, {\n getDuration: baseContext.getDuration,\n contextAttributes: baseContext.contextAttributes,\n isEnabled: baseContext.isEnabled,\n loading: baseContext.loading,\n keys: baseContext.keys,\n settings: baseContext.settings,\n });\n\n return instance;\n }, [baseContext]);\n\n return typesafeInstance as BaseContext & T;\n };\n}\n\n// Basic hook for general use - requires type parameter\nexport const useBaseQuonfig = () => React.useContext(QuonfigContext);\n\n// General hook that returns the context with any explicit type\nexport const useQuonfig = (): ProvidedContext => useBaseQuonfig() as unknown as ProvidedContext;\n\nlet globalQuonfigIsTaken = false;\n\nexport const assignQuonfigClient = () => {\n if (globalQuonfigIsTaken) {\n return new Quonfig();\n }\n\n globalQuonfigIsTaken = true;\n return quonfig;\n};\n\nexport type QuonfigProviderProps = SharedSettings & {\n sdkKey: string;\n contextAttributes?: Contexts;\n initialFlags?: Record<string, unknown>;\n};\n\nconst getContextKey = (contextAttributes: Contexts, onError: (e: Error) => void): string => {\n try {\n if (Object.keys(contextAttributes).length === 0) {\n // eslint-disable-next-line no-console\n console.warn(\n \"QuonfigProvider: You haven't passed any contextAttributes. See https://docs.quonfig.com/docs/sdks/react#using-context\"\n );\n }\n\n return encodeContexts(contextAttributes);\n } catch (e) {\n onError(e as Error);\n return \"\";\n }\n};\n\nfunction QuonfigProvider({\n sdkKey,\n contextAttributes = {},\n onError = (e: unknown) => {\n // eslint-disable-next-line no-console\n console.error(e);\n },\n initialFlags,\n children,\n timeout,\n apiUrl,\n apiUrls,\n pollInterval,\n afterEvaluationCallback = undefined,\n collectEvaluationSummaries,\n collectLoggerNames,\n}: PropsWithChildren<QuonfigProviderProps>) {\n const settings = {\n sdkKey,\n apiUrl,\n apiUrls,\n timeout,\n pollInterval,\n onError,\n afterEvaluationCallback,\n collectEvaluationSummaries,\n collectLoggerNames,\n };\n\n // We use this state to prevent a double-init when useEffect fires due to\n // StrictMode\n const mostRecentlyLoadingContextKey = React.useRef<string | undefined>(undefined);\n // We use this state to pass the loading state to the Provider (updating\n // currentLoadingContextKey won't trigger an update)\n const [loading, setLoading] = React.useState(true);\n const [initialLoad, setInitialLoad] = React.useState(true);\n // Here we track the current identity so we can reload our config when it\n // changes\n const [loadedContextKey, setLoadedContextKey] = React.useState(\"\");\n\n const quonfigClient: Quonfig = React.useMemo(() => assignQuonfigClient(), []);\n\n const contextKey = getContextKey(contextAttributes, onError);\n\n if (initialFlags && initialLoad) {\n quonfigClient.hydrate(initialFlags);\n setInitialLoad(false);\n setLoadedContextKey(contextKey);\n setLoading(false);\n mostRecentlyLoadingContextKey.current = contextKey;\n\n if (pollInterval) {\n // eslint-disable-next-line no-console\n console.warn(\"Polling is not supported when hydrating flags via initialFlags\");\n }\n }\n\n React.useEffect(() => {\n setInitialLoad(false);\n\n if (mostRecentlyLoadingContextKey.current === contextKey) {\n return;\n }\n\n setLoading(true);\n try {\n if (mostRecentlyLoadingContextKey.current === undefined) {\n mostRecentlyLoadingContextKey.current = contextKey;\n\n if (!sdkKey) {\n throw new Error(\"QuonfigProvider: sdkKey is required\");\n }\n\n quonfigClient.clientName = \"react\";\n quonfigClient.clientVersion = reactSdkVersion;\n\n const resolvedApiUrls = apiUrls ?? (apiUrl ? [apiUrl] : undefined);\n\n const initOptions: InitOptions = {\n context: contextAttributes,\n sdkKey,\n apiUrls: resolvedApiUrls,\n timeout,\n afterEvaluationCallback,\n collectEvaluationSummaries,\n collectLoggerNames,\n };\n\n quonfigClient\n .init(initOptions)\n .then(() => {\n setLoadedContextKey(contextKey);\n setLoading(false);\n\n if (pollInterval) {\n quonfigClient.poll({ frequencyInMs: pollInterval });\n }\n })\n .catch((reason: any) => {\n setLoading(false);\n onError(reason);\n });\n } else {\n mostRecentlyLoadingContextKey.current = contextKey;\n\n quonfigClient\n .updateContext(contextAttributes)\n .then(() => {\n setLoadedContextKey(contextKey);\n setLoading(false);\n })\n .catch((reason: any) => {\n setLoading(false);\n onError(reason);\n });\n }\n } catch (e) {\n setLoading(false);\n onError(e as Error);\n }\n }, [\n sdkKey,\n loadedContextKey,\n contextKey,\n loading,\n setLoading,\n onError,\n quonfigClient.instanceHash,\n ]);\n\n const value = React.useMemo(() => {\n const baseContext: ProvidedContext = {\n isEnabled: quonfigClient.isEnabled.bind(quonfigClient),\n contextAttributes,\n get: quonfigClient.get.bind(quonfigClient),\n getDuration: quonfigClient.getDuration.bind(quonfigClient),\n keys: Object.keys(quonfigClient.extract()),\n quonfig: quonfigClient,\n loading,\n settings,\n };\n\n return baseContext;\n }, [loadedContextKey, loading, quonfigClient.instanceHash, settings]);\n\n return <QuonfigContext.Provider value={value}>{children}</QuonfigContext.Provider>;\n}\n\nexport { QuonfigProvider, ConfigValue, SharedSettings, QuonfigTypesafeClass };\n","import React, { PropsWithChildren } from \"react\";\nimport { QuonfigContext, assignQuonfigClient, ProvidedContext } from \"./QuonfigProvider\";\n\nexport type QuonfigTestProviderProps = {\n config: Record<string, any>;\n sdkKey?: string;\n};\n\nfunction QuonfigTestProvider({\n sdkKey,\n config,\n children,\n}: PropsWithChildren<QuonfigTestProviderProps>) {\n const get = (key: string) => config[key];\n const getDuration = (key: string) => config[key];\n const isEnabled = (key: string) => !!get(key);\n\n const quonfigClient = React.useMemo(() => assignQuonfigClient(), []);\n\n const value = React.useMemo(() => {\n quonfigClient.get = get;\n quonfigClient.getDuration = getDuration;\n quonfigClient.isEnabled = isEnabled;\n\n const baseContext: ProvidedContext = {\n isEnabled,\n contextAttributes: config.contextAttributes,\n get,\n getDuration,\n loading: false,\n quonfig: quonfigClient,\n keys: Object.keys(config),\n settings: { sdkKey: sdkKey ?? \"fake-sdk-key-via-the-test-provider\" },\n };\n\n return baseContext;\n }, [config, quonfigClient, sdkKey]);\n\n return <QuonfigContext.Provider value={value}>{children}</QuonfigContext.Provider>;\n}\n\nexport { QuonfigTestProvider };\n"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -11,7 +11,8 @@ type ClassMethods<T> = {
|
|
|
11
11
|
[K in keyof T]: T[K];
|
|
12
12
|
};
|
|
13
13
|
type QuonfigTypesafeClass<T = unknown> = new (quonfig: Quonfig) => T;
|
|
14
|
-
type SharedSettings = Partial<Pick<InitOptions, "sdkKey" | "
|
|
14
|
+
type SharedSettings = Partial<Pick<InitOptions, "sdkKey" | "apiUrls" | "timeout" | "collectEvaluationSummaries" | "collectLoggerNames">> & {
|
|
15
|
+
apiUrl?: string;
|
|
15
16
|
afterEvaluationCallback?: <K extends keyof TypedFrontEndConfigurationRaw>(key: K, value: TypedFrontEndConfigurationRaw[K], contexts: Contexts | undefined) => void;
|
|
16
17
|
pollInterval?: number;
|
|
17
18
|
onError?: (error: Error) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,8 @@ type ClassMethods<T> = {
|
|
|
11
11
|
[K in keyof T]: T[K];
|
|
12
12
|
};
|
|
13
13
|
type QuonfigTypesafeClass<T = unknown> = new (quonfig: Quonfig) => T;
|
|
14
|
-
type SharedSettings = Partial<Pick<InitOptions, "sdkKey" | "
|
|
14
|
+
type SharedSettings = Partial<Pick<InitOptions, "sdkKey" | "apiUrls" | "timeout" | "collectEvaluationSummaries" | "collectLoggerNames">> & {
|
|
15
|
+
apiUrl?: string;
|
|
15
16
|
afterEvaluationCallback?: <K extends keyof TypedFrontEndConfigurationRaw>(key: K, value: TypedFrontEndConfigurationRaw[K], contexts: Contexts | undefined) => void;
|
|
16
17
|
pollInterval?: number;
|
|
17
18
|
onError?: (error: Error) => void;
|
package/dist/index.mjs
CHANGED
|
@@ -2,96 +2,12 @@ import { quonfig, encodeContexts, Quonfig } from '@quonfig/javascript';
|
|
|
2
2
|
export { quonfig } from '@quonfig/javascript';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
7
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
8
|
-
};
|
|
5
|
+
// src/index.tsx
|
|
9
6
|
|
|
10
|
-
//
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
packageManager: "yarn@4.11.0",
|
|
15
|
-
name: "@quonfig/react",
|
|
16
|
-
version: "0.0.5",
|
|
17
|
-
description: "Feature Flags & Dynamic Configuration as a Service",
|
|
18
|
-
main: "dist/index.cjs",
|
|
19
|
-
module: "dist/index.mjs",
|
|
20
|
-
types: "dist/index.d.ts",
|
|
21
|
-
repository: {
|
|
22
|
-
type: "git",
|
|
23
|
-
url: "https://github.com/quonfig/sdk-react.git"
|
|
24
|
-
},
|
|
25
|
-
bugs: {
|
|
26
|
-
url: "https://github.com/quonfig/sdk-react/issues"
|
|
27
|
-
},
|
|
28
|
-
homepage: "https://github.com/quonfig/sdk-react#readme",
|
|
29
|
-
exports: {
|
|
30
|
-
".": {
|
|
31
|
-
types: "./dist/index.d.ts",
|
|
32
|
-
import: "./dist/index.mjs",
|
|
33
|
-
require: "./dist/index.cjs",
|
|
34
|
-
default: "./dist/index.cjs"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
files: [
|
|
38
|
-
"dist/",
|
|
39
|
-
"README.md",
|
|
40
|
-
"LICENSE",
|
|
41
|
-
"CHANGELOG.md"
|
|
42
|
-
],
|
|
43
|
-
scripts: {
|
|
44
|
-
build: "rm -rf dist/ && tsup",
|
|
45
|
-
dev: "tsup --watch",
|
|
46
|
-
bundle: "esbuild --minify --target=esnext --bundle --outfile=dist/quonfig-react.bundle.js --global-name=window.quonfigReactNamespace dist/index.cjs && echo 'window.quonfigReact = window.quonfigReactNamespace.quonfigReact' >> dist/quonfig-react.bundle.js",
|
|
47
|
-
test: "tsup && jest --verbose",
|
|
48
|
-
lint: "eslint --ext .ts,.tsx src/",
|
|
49
|
-
prettier: "prettier . -l",
|
|
50
|
-
"prettier:fix": "prettier --write ."
|
|
51
|
-
},
|
|
52
|
-
author: "Jeffrey Chupp",
|
|
53
|
-
license: "ISC",
|
|
54
|
-
keywords: [
|
|
55
|
-
"feature-flags",
|
|
56
|
-
"config"
|
|
57
|
-
],
|
|
58
|
-
devDependencies: {
|
|
59
|
-
"@quonfig/javascript": ">=0.0.3",
|
|
60
|
-
"@testing-library/jest-dom": "^5.16.5",
|
|
61
|
-
"@testing-library/react": "^13.3.0",
|
|
62
|
-
"@types/jest": "^28.1.6",
|
|
63
|
-
"@types/node": "^18.6.5",
|
|
64
|
-
"@types/react": "^19.1.10",
|
|
65
|
-
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
|
66
|
-
"@typescript-eslint/parser": "^5.33.0",
|
|
67
|
-
eslint: "^8.21.0",
|
|
68
|
-
"eslint-config-airbnb": "^19.0.4",
|
|
69
|
-
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
70
|
-
"eslint-config-prettier": "^8.8.0",
|
|
71
|
-
"eslint-plugin-import": "^2.26.0",
|
|
72
|
-
"eslint-plugin-jest": "^26.8.2",
|
|
73
|
-
"eslint-plugin-jsx-a11y": "^6.6.1",
|
|
74
|
-
"eslint-plugin-react": "^7.30.1",
|
|
75
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
76
|
-
jest: "^28.1.3",
|
|
77
|
-
"jest-environment-jsdom": "^28.1.3",
|
|
78
|
-
"jest-fetch-mock": "^3.0.3",
|
|
79
|
-
prettier: "^3.0.0",
|
|
80
|
-
react: "^19.1.1",
|
|
81
|
-
"react-dom": "^19.1.1",
|
|
82
|
-
"ts-jest": "^28.0.7",
|
|
83
|
-
"ts-node": "^10.9.1",
|
|
84
|
-
tsup: "^8.4.0",
|
|
85
|
-
typescript: "^4.7.4"
|
|
86
|
-
},
|
|
87
|
-
peerDependencies: {
|
|
88
|
-
"@quonfig/javascript": ">=0.0.3",
|
|
89
|
-
react: "^16 || ^17 || ^18 || ^19"
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
var { version } = require_package();
|
|
7
|
+
// src/version.ts
|
|
8
|
+
var version_default = "0.0.7";
|
|
9
|
+
|
|
10
|
+
// src/QuonfigProvider.tsx
|
|
95
11
|
var defaultContext = {
|
|
96
12
|
get: (_key) => void 0,
|
|
97
13
|
getDuration: (_key) => void 0,
|
|
@@ -201,12 +117,13 @@ function QuonfigProvider({
|
|
|
201
117
|
if (!sdkKey) {
|
|
202
118
|
throw new Error("QuonfigProvider: sdkKey is required");
|
|
203
119
|
}
|
|
204
|
-
quonfigClient.
|
|
120
|
+
quonfigClient.clientName = "react";
|
|
121
|
+
quonfigClient.clientVersion = version_default;
|
|
122
|
+
const resolvedApiUrls = apiUrls != null ? apiUrls : apiUrl ? [apiUrl] : void 0;
|
|
205
123
|
const initOptions = {
|
|
206
124
|
context: contextAttributes,
|
|
207
125
|
sdkKey,
|
|
208
|
-
|
|
209
|
-
apiUrls,
|
|
126
|
+
apiUrls: resolvedApiUrls,
|
|
210
127
|
timeout,
|
|
211
128
|
afterEvaluationCallback,
|
|
212
129
|
collectEvaluationSummaries,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/QuonfigProvider.tsx","../src/QuonfigTestProvider.tsx"],"names":["React"],"mappings":";;;;;;;;;;AAAA,IAAA,eAAA,GAAA,UAAA,CAAA;AAAA,EAAA,cAAA,CAAA,OAAA,EAAA,MAAA,EAAA;AAAA,IAAA,MAAA,CAAA,OAAA,GAAA;AAAA,MACE,cAAA,EAAkB,aAAA;AAAA,MAClB,IAAA,EAAQ,gBAAA;AAAA,MACR,OAAA,EAAW,OAAA;AAAA,MACX,WAAA,EAAe,oDAAA;AAAA,MACf,IAAA,EAAQ,gBAAA;AAAA,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Flags & Dynamic Configuration as a Service\",\n \"main\": \"dist/index.cjs\",\n \"module\": \"dist/index.mjs\",\n \"types\": \"dist/index.d.ts\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/quonfig/sdk-react.git\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/quonfig/sdk-react/issues\"\n },\n \"homepage\": \"https://github.com/quonfig/sdk-react#readme\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.cjs\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"files\": [\n \"dist/\",\n \"README.md\",\n \"LICENSE\",\n \"CHANGELOG.md\"\n ],\n \"scripts\": {\n \"build\": \"rm -rf dist/ && tsup\",\n \"dev\": \"tsup --watch\",\n \"bundle\": \"esbuild --minify --target=esnext --bundle --outfile=dist/quonfig-react.bundle.js --global-name=window.quonfigReactNamespace dist/index.cjs && echo 'window.quonfigReact = window.quonfigReactNamespace.quonfigReact' >> dist/quonfig-react.bundle.js\",\n \"test\": \"tsup && jest --verbose\",\n \"lint\": \"eslint --ext .ts,.tsx src/\",\n \"prettier\": \"prettier . -l\",\n \"prettier:fix\": \"prettier --write .\"\n },\n \"author\": \"Jeffrey Chupp\",\n \"license\": \"ISC\",\n \"keywords\": [\n \"feature-flags\",\n \"config\"\n ],\n \"devDependencies\": {\n \"@quonfig/javascript\": \">=0.0.3\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^13.3.0\",\n \"@types/jest\": \"^28.1.6\",\n \"@types/node\": \"^18.6.5\",\n \"@types/react\": \"^19.1.10\",\n \"@typescript-eslint/eslint-plugin\": \"^5.33.0\",\n \"@typescript-eslint/parser\": \"^5.33.0\",\n \"eslint\": \"^8.21.0\",\n \"eslint-config-airbnb\": \"^19.0.4\",\n \"eslint-config-airbnb-typescript\": \"^17.0.0\",\n \"eslint-config-prettier\": \"^8.8.0\",\n \"eslint-plugin-import\": \"^2.26.0\",\n \"eslint-plugin-jest\": \"^26.8.2\",\n \"eslint-plugin-jsx-a11y\": \"^6.6.1\",\n \"eslint-plugin-react\": \"^7.30.1\",\n \"eslint-plugin-react-hooks\": \"^4.6.0\",\n \"jest\": \"^28.1.3\",\n \"jest-environment-jsdom\": \"^28.1.3\",\n \"jest-fetch-mock\": \"^3.0.3\",\n \"prettier\": \"^3.0.0\",\n \"react\": \"^19.1.1\",\n \"react-dom\": \"^19.1.1\",\n \"ts-jest\": \"^28.0.7\",\n \"ts-node\": \"^10.9.1\",\n \"tsup\": \"^8.4.0\",\n \"typescript\": \"^4.7.4\"\n },\n \"peerDependencies\": {\n \"@quonfig/javascript\": \">=0.0.3\",\n \"react\": \"^16 || ^17 || ^18 || ^19\"\n }\n}\n","import React, { PropsWithChildren } from \"react\";\nimport {\n quonfig,\n type InitOptions,\n type ConfigValue,\n type Contexts,\n Quonfig,\n TypedFrontEndConfigurationRaw,\n FrontEndConfigurationRaw,\n Duration,\n encodeContexts,\n} from \"@quonfig/javascript\";\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version } = require(\"../package.json\");\n\n// @quonfig/cli#generate will create interfaces into this namespace for React to consume\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface FrontEndConfigurationAccessor {}\n\nexport type TypedFrontEndConfigurationAccessor = keyof FrontEndConfigurationAccessor extends never\n ? Record<string, unknown>\n : {\n [TypedFlagKey in keyof FrontEndConfigurationAccessor]: FrontEndConfigurationAccessor[TypedFlagKey];\n };\n\ntype ClassMethods<T> = { [K in keyof T]: T[K] };\n\ntype QuonfigTypesafeClass<T = unknown> = new (\n // eslint-disable-next-line no-shadow\n quonfig: Quonfig\n) => T;\n\ntype SharedSettings = Partial<\n Pick<\n InitOptions,\n | \"sdkKey\"\n | \"apiUrl\"\n | \"apiUrls\"\n | \"timeout\"\n | \"collectEvaluationSummaries\"\n | \"collectLoggerNames\"\n >\n> & {\n // We need to redefine the afterEvaluationCallback type to ensure proper dynamic resolution of K\n afterEvaluationCallback?: <K extends keyof TypedFrontEndConfigurationRaw>(\n key: K,\n value: TypedFrontEndConfigurationRaw[K],\n contexts: Contexts | undefined\n ) => void;\n pollInterval?: number;\n onError?: (error: Error) => void;\n};\n\nexport type BaseContext = {\n get: <K extends keyof TypedFrontEndConfigurationRaw>(key: K) => TypedFrontEndConfigurationRaw[K];\n getDuration: <\n K extends keyof FrontEndConfigurationRaw extends never\n ? string\n : {\n [IK in keyof TypedFrontEndConfigurationRaw]: TypedFrontEndConfigurationRaw[IK] extends Duration\n ? IK\n : never;\n }[keyof TypedFrontEndConfigurationRaw],\n >(\n key: K\n ) => Duration | undefined;\n contextAttributes: Contexts;\n isEnabled: <\n K extends keyof FrontEndConfigurationRaw extends never\n ? string\n : {\n [IK in keyof TypedFrontEndConfigurationRaw]: TypedFrontEndConfigurationRaw[IK] extends boolean\n ? IK\n : never;\n }[keyof TypedFrontEndConfigurationRaw],\n >(\n key: K\n ) => boolean;\n loading: boolean;\n quonfig: typeof quonfig;\n keys: (keyof TypedFrontEndConfigurationRaw)[];\n settings: SharedSettings;\n};\n\nexport type ProvidedContext = BaseContext & ClassMethods<QuonfigTypesafeClass>;\n\nexport const defaultContext: BaseContext = {\n get: (_key) => undefined,\n getDuration: (_key) => undefined,\n isEnabled: (_key) => false,\n keys: [],\n loading: true,\n contextAttributes: {},\n quonfig,\n settings: {},\n};\n\nexport const QuonfigContext = React.createContext<ProvidedContext>(\n defaultContext as ProvidedContext\n);\n\n// This is a factory function that creates a fully typed useQuonfig hook for a specific QuonfigTypesafe class\nexport function createQuonfigHook<T>(TypesafeClass: QuonfigTypesafeClass<T>) {\n return function useQuonfigHook(): BaseContext & T {\n const baseContext = React.useContext(QuonfigContext);\n\n // Memoize the typesafe instance to prevent unnecessary constructor calls\n const typesafeInstance = React.useMemo(() => {\n const instance = new TypesafeClass(baseContext.quonfig);\n\n // Copy baseContext properties to typesafeInstance except for `get` + `quonfig`\n Object.assign(instance as any, {\n getDuration: baseContext.getDuration,\n contextAttributes: baseContext.contextAttributes,\n isEnabled: baseContext.isEnabled,\n loading: baseContext.loading,\n keys: baseContext.keys,\n settings: baseContext.settings,\n });\n\n return instance;\n }, [baseContext]);\n\n return typesafeInstance as BaseContext & T;\n };\n}\n\n// Basic hook for general use - requires type parameter\nexport const useBaseQuonfig = () => React.useContext(QuonfigContext);\n\n// General hook that returns the context with any explicit type\nexport const useQuonfig = (): ProvidedContext => useBaseQuonfig() as unknown as ProvidedContext;\n\nlet globalQuonfigIsTaken = false;\n\nexport const assignQuonfigClient = () => {\n if (globalQuonfigIsTaken) {\n return new Quonfig();\n }\n\n globalQuonfigIsTaken = true;\n return quonfig;\n};\n\nexport type QuonfigProviderProps = SharedSettings & {\n sdkKey: string;\n contextAttributes?: Contexts;\n initialFlags?: Record<string, unknown>;\n};\n\nconst getContextKey = (\n contextAttributes: Contexts,\n onError: (e: Error) => void\n): string => {\n try {\n if (Object.keys(contextAttributes).length === 0) {\n // eslint-disable-next-line no-console\n console.warn(\n \"QuonfigProvider: You haven't passed any contextAttributes. See https://docs.quonfig.com/docs/sdks/react#using-context\"\n );\n }\n\n return encodeContexts(contextAttributes);\n } catch (e) {\n onError(e as Error);\n return \"\";\n }\n};\n\nfunction QuonfigProvider({\n sdkKey,\n contextAttributes = {},\n onError = (e: unknown) => {\n // eslint-disable-next-line no-console\n console.error(e);\n },\n initialFlags,\n children,\n timeout,\n apiUrl,\n apiUrls,\n pollInterval,\n afterEvaluationCallback = undefined,\n collectEvaluationSummaries,\n collectLoggerNames,\n}: PropsWithChildren<QuonfigProviderProps>) {\n const settings = {\n sdkKey,\n apiUrl,\n apiUrls,\n timeout,\n pollInterval,\n onError,\n afterEvaluationCallback,\n collectEvaluationSummaries,\n collectLoggerNames,\n };\n\n // We use this state to prevent a double-init when useEffect fires due to\n // StrictMode\n const mostRecentlyLoadingContextKey = React.useRef<string | undefined>(undefined);\n // We use this state to pass the loading state to the Provider (updating\n // currentLoadingContextKey won't trigger an update)\n const [loading, setLoading] = React.useState(true);\n const [initialLoad, setInitialLoad] = React.useState(true);\n // Here we track the current identity so we can reload our config when it\n // changes\n const [loadedContextKey, setLoadedContextKey] = React.useState(\"\");\n\n const quonfigClient: Quonfig = React.useMemo(() => assignQuonfigClient(), []);\n\n const contextKey = getContextKey(contextAttributes, onError);\n\n if (initialFlags && initialLoad) {\n quonfigClient.hydrate(initialFlags);\n setInitialLoad(false);\n setLoadedContextKey(contextKey);\n setLoading(false);\n mostRecentlyLoadingContextKey.current = contextKey;\n\n if (pollInterval) {\n // eslint-disable-next-line no-console\n console.warn(\"Polling is not supported when hydrating flags via initialFlags\");\n }\n }\n\n React.useEffect(() => {\n setInitialLoad(false);\n\n if (mostRecentlyLoadingContextKey.current === contextKey) {\n return;\n }\n\n setLoading(true);\n try {\n if (mostRecentlyLoadingContextKey.current === undefined) {\n mostRecentlyLoadingContextKey.current = contextKey;\n\n if (!sdkKey) {\n throw new Error(\"QuonfigProvider: sdkKey is required\");\n }\n\n quonfigClient.clientNameString = \"sdk-react\";\n\n const initOptions: InitOptions = {\n context: contextAttributes,\n sdkKey,\n apiUrl,\n apiUrls,\n timeout,\n afterEvaluationCallback,\n collectEvaluationSummaries,\n collectLoggerNames,\n };\n\n quonfigClient\n .init(initOptions)\n .then(() => {\n setLoadedContextKey(contextKey);\n setLoading(false);\n\n if (pollInterval) {\n quonfigClient.poll({ frequencyInMs: pollInterval });\n }\n })\n .catch((reason: any) => {\n setLoading(false);\n onError(reason);\n });\n } else {\n mostRecentlyLoadingContextKey.current = contextKey;\n\n quonfigClient\n .updateContext(contextAttributes)\n .then(() => {\n setLoadedContextKey(contextKey);\n setLoading(false);\n })\n .catch((reason: any) => {\n setLoading(false);\n onError(reason);\n });\n }\n } catch (e) {\n setLoading(false);\n onError(e as Error);\n }\n }, [\n sdkKey,\n loadedContextKey,\n contextKey,\n loading,\n setLoading,\n onError,\n quonfigClient.instanceHash,\n ]);\n\n const value = React.useMemo(() => {\n const baseContext: ProvidedContext = {\n isEnabled: quonfigClient.isEnabled.bind(quonfigClient),\n contextAttributes,\n get: quonfigClient.get.bind(quonfigClient),\n getDuration: quonfigClient.getDuration.bind(quonfigClient),\n keys: Object.keys(quonfigClient.extract()),\n quonfig: quonfigClient,\n loading,\n settings,\n };\n\n return baseContext;\n }, [loadedContextKey, loading, quonfigClient.instanceHash, settings]);\n\n return <QuonfigContext.Provider value={value}>{children}</QuonfigContext.Provider>;\n}\n\nexport { QuonfigProvider, ConfigValue, SharedSettings, QuonfigTypesafeClass };\n","import React, { PropsWithChildren } from \"react\";\nimport { QuonfigContext, assignQuonfigClient, ProvidedContext } from \"./QuonfigProvider\";\n\nexport type QuonfigTestProviderProps = {\n config: Record<string, any>;\n sdkKey?: string;\n};\n\nfunction QuonfigTestProvider({\n sdkKey,\n config,\n children,\n}: PropsWithChildren<QuonfigTestProviderProps>) {\n const get = (key: string) => config[key];\n const getDuration = (key: string) => config[key];\n const isEnabled = (key: string) => !!get(key);\n\n const quonfigClient = React.useMemo(() => assignQuonfigClient(), []);\n\n const value = React.useMemo(() => {\n quonfigClient.get = get;\n quonfigClient.getDuration = getDuration;\n quonfigClient.isEnabled = isEnabled;\n\n const baseContext: ProvidedContext = {\n isEnabled,\n contextAttributes: config.contextAttributes,\n get,\n getDuration,\n loading: false,\n quonfig: quonfigClient,\n keys: Object.keys(config),\n settings: { sdkKey: sdkKey ?? \"fake-sdk-key-via-the-test-provider\" },\n };\n\n return baseContext;\n }, [config, quonfigClient, sdkKey]);\n\n return <QuonfigContext.Provider value={value}>{children}</QuonfigContext.Provider>;\n}\n\nexport { QuonfigTestProvider };\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/version.ts","../src/QuonfigProvider.tsx","../src/QuonfigTestProvider.tsx"],"names":["React"],"mappings":";;;;;;;AACA,IAAO,eAAA,GAAQ,OAAA;;;ACkFR,IAAM,cAAA,GAA8B;AAAA,EACzC,GAAA,EAAK,CAAC,IAAA,KAAS,MAAA;AAAA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1B,IAAA,MAAM,WAAA,GAA+B;AAAA,MACnC,SAAA;AAAA,MACA,mBAAmB,MAAA,CAAO,iBAAA;AAAA,MAC1B,GAAA;AAAA,MACA,WAAA;AAAA,MACA,OAAA,EAAS,KAAA;AAAA,MACT,OAAA,EAAS,aAAA;AAAA,MACT,IAAA,EAAM,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA;AAAA,MACxB,QAAA,EAAU,EAAE,MAAA,EAAQ,MAAA,IAAA,IAAA,GAAA,MAAA,GAAU,oCAAA;AAAqC,KACrE;AAEA,IAAA,OAAO,WAAA;AAAA,EACT,CAAA,EAAG,CAAC,MAAA,EAAQ,aAAA,EAAe,MAAM,CAAC,CAAA;AAElC,EAAA,uBAAOA,KAAAA,CAAA,aAAA,CAAC,eAAe,QAAA,EAAf,EAAwB,SAAe,QAAS,CAAA;AAC1D","file":"index.mjs","sourcesContent":["// AUTO-GENERATED from package.json by scripts/generate-version.mjs — do not edit.\nexport default \"0.0.7\";\n","import React, { PropsWithChildren } from \"react\";\nimport {\n quonfig,\n type InitOptions,\n type ConfigValue,\n type Contexts,\n Quonfig,\n TypedFrontEndConfigurationRaw,\n FrontEndConfigurationRaw,\n Duration,\n encodeContexts,\n} from \"@quonfig/javascript\";\nimport reactSdkVersion from \"./version\";\n\n// @quonfig/cli#generate will create interfaces into this namespace for React to consume\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface FrontEndConfigurationAccessor {}\n\nexport type TypedFrontEndConfigurationAccessor = keyof FrontEndConfigurationAccessor extends never\n ? Record<string, unknown>\n : {\n [TypedFlagKey in keyof FrontEndConfigurationAccessor]: FrontEndConfigurationAccessor[TypedFlagKey];\n };\n\ntype ClassMethods<T> = { [K in keyof T]: T[K] };\n\ntype QuonfigTypesafeClass<T = unknown> = new (\n // eslint-disable-next-line no-shadow\n quonfig: Quonfig\n) => T;\n\ntype SharedSettings = Partial<\n Pick<\n InitOptions,\n \"sdkKey\" | \"apiUrls\" | \"timeout\" | \"collectEvaluationSummaries\" | \"collectLoggerNames\"\n >\n> & {\n // Convenience alias for a single API URL — normalized to apiUrls=[apiUrl]\n // before being passed to the underlying SDK, which only accepts apiUrls.\n apiUrl?: string;\n // We need to redefine the afterEvaluationCallback type to ensure proper dynamic resolution of K\n afterEvaluationCallback?: <K extends keyof TypedFrontEndConfigurationRaw>(\n key: K,\n value: TypedFrontEndConfigurationRaw[K],\n contexts: Contexts | undefined\n ) => void;\n pollInterval?: number;\n onError?: (error: Error) => void;\n};\n\nexport type BaseContext = {\n get: <K extends keyof TypedFrontEndConfigurationRaw>(key: K) => TypedFrontEndConfigurationRaw[K];\n getDuration: <\n K extends keyof FrontEndConfigurationRaw extends never\n ? string\n : {\n [IK in keyof TypedFrontEndConfigurationRaw]: TypedFrontEndConfigurationRaw[IK] extends Duration\n ? IK\n : never;\n }[keyof TypedFrontEndConfigurationRaw],\n >(\n key: K\n ) => Duration | undefined;\n contextAttributes: Contexts;\n isEnabled: <\n K extends keyof FrontEndConfigurationRaw extends never\n ? string\n : {\n [IK in keyof TypedFrontEndConfigurationRaw]: TypedFrontEndConfigurationRaw[IK] extends boolean\n ? IK\n : never;\n }[keyof TypedFrontEndConfigurationRaw],\n >(\n key: K\n ) => boolean;\n loading: boolean;\n quonfig: typeof quonfig;\n keys: (keyof TypedFrontEndConfigurationRaw)[];\n settings: SharedSettings;\n};\n\nexport type ProvidedContext = BaseContext & ClassMethods<QuonfigTypesafeClass>;\n\nexport const defaultContext: BaseContext = {\n get: (_key) => undefined,\n getDuration: (_key) => undefined,\n isEnabled: (_key) => false,\n keys: [],\n loading: true,\n contextAttributes: {},\n quonfig,\n settings: {},\n};\n\nexport const QuonfigContext = React.createContext<ProvidedContext>(\n defaultContext as ProvidedContext\n);\n\n// This is a factory function that creates a fully typed useQuonfig hook for a specific QuonfigTypesafe class\nexport function createQuonfigHook<T>(TypesafeClass: QuonfigTypesafeClass<T>) {\n return function useQuonfigHook(): BaseContext & T {\n const baseContext = React.useContext(QuonfigContext);\n\n // Memoize the typesafe instance to prevent unnecessary constructor calls\n const typesafeInstance = React.useMemo(() => {\n const instance = new TypesafeClass(baseContext.quonfig);\n\n // Copy baseContext properties to typesafeInstance except for `get` + `quonfig`\n Object.assign(instance as any, {\n getDuration: baseContext.getDuration,\n contextAttributes: baseContext.contextAttributes,\n isEnabled: baseContext.isEnabled,\n loading: baseContext.loading,\n keys: baseContext.keys,\n settings: baseContext.settings,\n });\n\n return instance;\n }, [baseContext]);\n\n return typesafeInstance as BaseContext & T;\n };\n}\n\n// Basic hook for general use - requires type parameter\nexport const useBaseQuonfig = () => React.useContext(QuonfigContext);\n\n// General hook that returns the context with any explicit type\nexport const useQuonfig = (): ProvidedContext => useBaseQuonfig() as unknown as ProvidedContext;\n\nlet globalQuonfigIsTaken = false;\n\nexport const assignQuonfigClient = () => {\n if (globalQuonfigIsTaken) {\n return new Quonfig();\n }\n\n globalQuonfigIsTaken = true;\n return quonfig;\n};\n\nexport type QuonfigProviderProps = SharedSettings & {\n sdkKey: string;\n contextAttributes?: Contexts;\n initialFlags?: Record<string, unknown>;\n};\n\nconst getContextKey = (contextAttributes: Contexts, onError: (e: Error) => void): string => {\n try {\n if (Object.keys(contextAttributes).length === 0) {\n // eslint-disable-next-line no-console\n console.warn(\n \"QuonfigProvider: You haven't passed any contextAttributes. See https://docs.quonfig.com/docs/sdks/react#using-context\"\n );\n }\n\n return encodeContexts(contextAttributes);\n } catch (e) {\n onError(e as Error);\n return \"\";\n }\n};\n\nfunction QuonfigProvider({\n sdkKey,\n contextAttributes = {},\n onError = (e: unknown) => {\n // eslint-disable-next-line no-console\n console.error(e);\n },\n initialFlags,\n children,\n timeout,\n apiUrl,\n apiUrls,\n pollInterval,\n afterEvaluationCallback = undefined,\n collectEvaluationSummaries,\n collectLoggerNames,\n}: PropsWithChildren<QuonfigProviderProps>) {\n const settings = {\n sdkKey,\n apiUrl,\n apiUrls,\n timeout,\n pollInterval,\n onError,\n afterEvaluationCallback,\n collectEvaluationSummaries,\n collectLoggerNames,\n };\n\n // We use this state to prevent a double-init when useEffect fires due to\n // StrictMode\n const mostRecentlyLoadingContextKey = React.useRef<string | undefined>(undefined);\n // We use this state to pass the loading state to the Provider (updating\n // currentLoadingContextKey won't trigger an update)\n const [loading, setLoading] = React.useState(true);\n const [initialLoad, setInitialLoad] = React.useState(true);\n // Here we track the current identity so we can reload our config when it\n // changes\n const [loadedContextKey, setLoadedContextKey] = React.useState(\"\");\n\n const quonfigClient: Quonfig = React.useMemo(() => assignQuonfigClient(), []);\n\n const contextKey = getContextKey(contextAttributes, onError);\n\n if (initialFlags && initialLoad) {\n quonfigClient.hydrate(initialFlags);\n setInitialLoad(false);\n setLoadedContextKey(contextKey);\n setLoading(false);\n mostRecentlyLoadingContextKey.current = contextKey;\n\n if (pollInterval) {\n // eslint-disable-next-line no-console\n console.warn(\"Polling is not supported when hydrating flags via initialFlags\");\n }\n }\n\n React.useEffect(() => {\n setInitialLoad(false);\n\n if (mostRecentlyLoadingContextKey.current === contextKey) {\n return;\n }\n\n setLoading(true);\n try {\n if (mostRecentlyLoadingContextKey.current === undefined) {\n mostRecentlyLoadingContextKey.current = contextKey;\n\n if (!sdkKey) {\n throw new Error(\"QuonfigProvider: sdkKey is required\");\n }\n\n quonfigClient.clientName = \"react\";\n quonfigClient.clientVersion = reactSdkVersion;\n\n const resolvedApiUrls = apiUrls ?? (apiUrl ? [apiUrl] : undefined);\n\n const initOptions: InitOptions = {\n context: contextAttributes,\n sdkKey,\n apiUrls: resolvedApiUrls,\n timeout,\n afterEvaluationCallback,\n collectEvaluationSummaries,\n collectLoggerNames,\n };\n\n quonfigClient\n .init(initOptions)\n .then(() => {\n setLoadedContextKey(contextKey);\n setLoading(false);\n\n if (pollInterval) {\n quonfigClient.poll({ frequencyInMs: pollInterval });\n }\n })\n .catch((reason: any) => {\n setLoading(false);\n onError(reason);\n });\n } else {\n mostRecentlyLoadingContextKey.current = contextKey;\n\n quonfigClient\n .updateContext(contextAttributes)\n .then(() => {\n setLoadedContextKey(contextKey);\n setLoading(false);\n })\n .catch((reason: any) => {\n setLoading(false);\n onError(reason);\n });\n }\n } catch (e) {\n setLoading(false);\n onError(e as Error);\n }\n }, [\n sdkKey,\n loadedContextKey,\n contextKey,\n loading,\n setLoading,\n onError,\n quonfigClient.instanceHash,\n ]);\n\n const value = React.useMemo(() => {\n const baseContext: ProvidedContext = {\n isEnabled: quonfigClient.isEnabled.bind(quonfigClient),\n contextAttributes,\n get: quonfigClient.get.bind(quonfigClient),\n getDuration: quonfigClient.getDuration.bind(quonfigClient),\n keys: Object.keys(quonfigClient.extract()),\n quonfig: quonfigClient,\n loading,\n settings,\n };\n\n return baseContext;\n }, [loadedContextKey, loading, quonfigClient.instanceHash, settings]);\n\n return <QuonfigContext.Provider value={value}>{children}</QuonfigContext.Provider>;\n}\n\nexport { QuonfigProvider, ConfigValue, SharedSettings, QuonfigTypesafeClass };\n","import React, { PropsWithChildren } from \"react\";\nimport { QuonfigContext, assignQuonfigClient, ProvidedContext } from \"./QuonfigProvider\";\n\nexport type QuonfigTestProviderProps = {\n config: Record<string, any>;\n sdkKey?: string;\n};\n\nfunction QuonfigTestProvider({\n sdkKey,\n config,\n children,\n}: PropsWithChildren<QuonfigTestProviderProps>) {\n const get = (key: string) => config[key];\n const getDuration = (key: string) => config[key];\n const isEnabled = (key: string) => !!get(key);\n\n const quonfigClient = React.useMemo(() => assignQuonfigClient(), []);\n\n const value = React.useMemo(() => {\n quonfigClient.get = get;\n quonfigClient.getDuration = getDuration;\n quonfigClient.isEnabled = isEnabled;\n\n const baseContext: ProvidedContext = {\n isEnabled,\n contextAttributes: config.contextAttributes,\n get,\n getDuration,\n loading: false,\n quonfig: quonfigClient,\n keys: Object.keys(config),\n settings: { sdkKey: sdkKey ?? \"fake-sdk-key-via-the-test-provider\" },\n };\n\n return baseContext;\n }, [config, quonfigClient, sdkKey]);\n\n return <QuonfigContext.Provider value={value}>{children}</QuonfigContext.Provider>;\n}\n\nexport { QuonfigTestProvider };\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"packageManager": "yarn@4.11.0",
|
|
3
3
|
"name": "@quonfig/react",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"description": "Feature Flags & Dynamic Configuration as a Service",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"CHANGELOG.md"
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
|
+
"prebuild": "node scripts/generate-version.mjs",
|
|
32
33
|
"build": "rm -rf dist/ && tsup",
|
|
33
34
|
"dev": "tsup --watch",
|
|
34
35
|
"bundle": "esbuild --minify --target=esnext --bundle --outfile=dist/quonfig-react.bundle.js --global-name=window.quonfigReactNamespace dist/index.cjs && echo 'window.quonfigReact = window.quonfigReactNamespace.quonfigReact' >> dist/quonfig-react.bundle.js",
|
|
@@ -44,7 +45,7 @@
|
|
|
44
45
|
"config"
|
|
45
46
|
],
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@quonfig/javascript": ">=0.0.
|
|
48
|
+
"@quonfig/javascript": ">=0.0.11",
|
|
48
49
|
"@testing-library/jest-dom": "^5.16.5",
|
|
49
50
|
"@testing-library/react": "^13.3.0",
|
|
50
51
|
"@types/jest": "^28.1.6",
|
|
@@ -73,7 +74,7 @@
|
|
|
73
74
|
"typescript": "^4.7.4"
|
|
74
75
|
},
|
|
75
76
|
"peerDependencies": {
|
|
76
|
-
"@quonfig/javascript": ">=0.0.
|
|
77
|
+
"@quonfig/javascript": ">=0.0.11",
|
|
77
78
|
"react": "^16 || ^17 || ^18 || ^19"
|
|
78
79
|
}
|
|
79
80
|
}
|