@configdirector/nuxt-sdk 1.7.0 → 1.9.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 +34 -0
- package/dist/module.d.mts +26 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +12 -7
- package/dist/runtime/app/composables/useConfigDirectorClient.d.mts +1 -1
- package/dist/runtime/app/composables/useConfigDirectorClient.d.ts +1 -1
- package/dist/runtime/app/composables/useConfigDirectorClientHooks.d.mts +1 -1
- package/dist/runtime/app/composables/useConfigDirectorClientHooks.d.ts +1 -1
- package/dist/runtime/app/composables/useConfigDirectorContext.mjs +8 -3
- package/dist/runtime/nitro/plugin.d.mts +1 -1
- package/dist/runtime/nitro/plugin.d.ts +1 -1
- package/dist/runtime/nitro/plugin.mjs +219 -80
- package/dist/runtime/plugin.client.mjs +186 -84
- package/dist/runtime/plugin.server.mjs +8 -3
- package/dist/runtime/server/composables/useConfigDirectorClient.d.mts +1 -1
- package/dist/runtime/server/composables/useConfigDirectorClient.d.ts +1 -1
- package/dist/runtime/server/composables/useConfigDirectorServerHooks.d.mts +1 -1
- package/dist/runtime/server/composables/useConfigDirectorServerHooks.d.ts +1 -1
- package/dist/runtime/{types-C54FjC1D.d.mts → types-Bgx2-3dY.d.mts} +1 -0
- package/dist/runtime/{types-BPvGEzJY.d.mts → types-CvmjergQ.d.mts} +6 -2
- package/dist/testing.d.mts +352 -0
- package/dist/testing.mjs +1645 -0
- package/package.json +11 -4
package/README.md
CHANGED
|
@@ -31,6 +31,40 @@ const { value: darkMode } = useConfigDirectorValue("dark-mode", false);
|
|
|
31
31
|
|
|
32
32
|
Full details are in the [official documentation](https://docs.configdirector.com/sdks/meta/nuxt).
|
|
33
33
|
|
|
34
|
+
## Test your code
|
|
35
|
+
|
|
36
|
+
`@configdirector/nuxt-sdk/testing` creates a real client connected to an in-memory server that your
|
|
37
|
+
test controls. Install it before the Nuxt app is created, at the top level of a test file or a
|
|
38
|
+
vitest setup file, and the ConfigDirector plugin provides it to the app instead of building a
|
|
39
|
+
client. Tests run in the `nuxt` environment of `@nuxt/test-utils` 4 (which needs vitest 4).
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { nextTick } from "vue";
|
|
43
|
+
import { mountSuspended } from "@nuxt/test-utils/runtime";
|
|
44
|
+
import { createTestClient, installTestClient } from "@configdirector/nuxt-sdk/testing";
|
|
45
|
+
import Checkout from "~/components/Checkout.vue";
|
|
46
|
+
|
|
47
|
+
const testClient = createTestClient({ values: { "dark-mode": true } });
|
|
48
|
+
installTestClient(testClient);
|
|
49
|
+
|
|
50
|
+
test("renders the dark mode", async () => {
|
|
51
|
+
const component = await mountSuspended(Checkout);
|
|
52
|
+
expect(component.text()).toContain("dark-mode: true");
|
|
53
|
+
|
|
54
|
+
testClient.setValue("dark-mode", false);
|
|
55
|
+
await nextTick();
|
|
56
|
+
expect(component.text()).toContain("dark-mode: false");
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`@nuxt/test-utils` 4 creates the app once per test file, inside a `beforeAll` hook, so install at
|
|
61
|
+
module level rather than in a hook, and reset the values between tests with `replaceValues`.
|
|
62
|
+
`@nuxt/test-utils` 3 creates the app before the test file loads, so the plugin cannot see a test
|
|
63
|
+
client installed there; upgrade to use the testing entry. While
|
|
64
|
+
installed, the plugin needs no `clientSdkKey`. Await `nextTick()` after `setValue`, `removeValue`,
|
|
65
|
+
and `replaceValues`. The test client also holds or fails `initialize` and `updateContext`, and
|
|
66
|
+
records every context in `contextUpdates`.
|
|
67
|
+
|
|
34
68
|
## Documentation
|
|
35
69
|
|
|
36
70
|
Refer to the [official documentation for the Nuxt SDK](https://docs.configdirector.com/sdks/meta/nuxt).
|
package/dist/module.d.mts
CHANGED
|
@@ -92,6 +92,32 @@ interface ConfigDirectorPublicRuntimeConfig {
|
|
|
92
92
|
* Can be set via the NUXT_PUBLIC_CONFIGDIRECTOR_BASE_URL environment variable.
|
|
93
93
|
*/
|
|
94
94
|
baseUrl?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Connection options for the browser client used on the client side.
|
|
97
|
+
*/
|
|
98
|
+
connection?: {
|
|
99
|
+
/**
|
|
100
|
+
* The connection mode, one of `streaming` (default) or `polling`. In `streaming` mode the
|
|
101
|
+
* connection stays open and receives config updates as they happen. In `polling` mode configs
|
|
102
|
+
* are fetched once during initialization and then again on every `pollingInterval`.
|
|
103
|
+
* Can be set via the NUXT_PUBLIC_CONFIGDIRECTOR_CONNECTION_MODE environment variable.
|
|
104
|
+
*/
|
|
105
|
+
mode?: ConnectionMode;
|
|
106
|
+
/**
|
|
107
|
+
* The polling interval in seconds when `mode` is `polling`. Has no effect in `streaming` mode.
|
|
108
|
+
* When omitted (or `0`), it defaults to 60 seconds. A value below the minimum of 30 seconds is
|
|
109
|
+
* raised to 30 seconds and a warning is logged.
|
|
110
|
+
* Can be set via the NUXT_PUBLIC_CONFIGDIRECTOR_CONNECTION_POLLING_INTERVAL environment variable.
|
|
111
|
+
*/
|
|
112
|
+
pollingInterval?: number;
|
|
113
|
+
/**
|
|
114
|
+
* How long, in milliseconds, the browser client waits for its initial config payload during
|
|
115
|
+
* initialization before the app renders with default values. When omitted (or `0`), it defaults
|
|
116
|
+
* to 2000 milliseconds.
|
|
117
|
+
* Can be set via the NUXT_PUBLIC_CONFIGDIRECTOR_CONNECTION_TIMEOUT environment variable.
|
|
118
|
+
*/
|
|
119
|
+
timeout?: number;
|
|
120
|
+
};
|
|
95
121
|
}
|
|
96
122
|
declare module "nuxt/schema" {
|
|
97
123
|
interface RuntimeConfig {
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -25,14 +25,19 @@ var module_default = defineNuxtModule({
|
|
|
25
25
|
...serverDefaults,
|
|
26
26
|
logLevel: options.logLevel
|
|
27
27
|
} : serverDefaults);
|
|
28
|
-
|
|
29
|
-
clientSdkKey: "",
|
|
30
|
-
logLevel: options.logLevel,
|
|
31
|
-
baseUrl: ""
|
|
32
|
-
} : {
|
|
28
|
+
const publicDefaults = {
|
|
33
29
|
clientSdkKey: "",
|
|
34
|
-
baseUrl: ""
|
|
35
|
-
|
|
30
|
+
baseUrl: "",
|
|
31
|
+
connection: {
|
|
32
|
+
mode: "streaming",
|
|
33
|
+
pollingInterval: 0,
|
|
34
|
+
timeout: 0
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
nuxt.options.runtimeConfig.public.configdirector = defu(nuxt.options.runtimeConfig.public.configdirector, options.logLevel !== void 0 ? {
|
|
38
|
+
...publicDefaults,
|
|
39
|
+
logLevel: options.logLevel
|
|
40
|
+
} : publicDefaults);
|
|
36
41
|
logger.debug("ConfigDirector Nuxt module setup complete");
|
|
37
42
|
addServerPlugin(resolver.resolve("./runtime/nitro/plugin"));
|
|
38
43
|
addServerHandler({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as ClientHooks } from "../../types-
|
|
1
|
+
import { t as ClientHooks } from "../../types-CvmjergQ.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/runtime/app/composables/useConfigDirectorClientHooks.d.ts
|
|
4
4
|
declare const useConfigDirectorClientHooks: (hooks: ClientHooks) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as ClientHooks } from "../../types-
|
|
1
|
+
import { t as ClientHooks } from "../../types-CvmjergQ.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/runtime/app/composables/useConfigDirectorClientHooks.d.ts
|
|
4
4
|
declare const useConfigDirectorClientHooks: (hooks: ClientHooks) => void;
|
|
@@ -16,9 +16,14 @@ const useConfigDirectorContext = () => {
|
|
|
16
16
|
state.value = rawContext;
|
|
17
17
|
if (oldContext != newContext) {
|
|
18
18
|
const timeout = getEffectiveTimeout(options?.timeoutMilliseconds);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
let timer;
|
|
20
|
+
try {
|
|
21
|
+
await Promise.race([client.updateContext(rawContext), new Promise((resolve) => {
|
|
22
|
+
timer = setTimeout(() => resolve(), timeout);
|
|
23
|
+
})]);
|
|
24
|
+
} finally {
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
};
|
|
24
29
|
return {
|