@configdirector/nuxt-sdk 0.1.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 +136 -0
- package/dist/module.d.mts +85 -0
- package/dist/module.json +8 -0
- package/dist/module.mjs +66 -0
- package/dist/runtime/app/composables/useConfigDirectorClient.d.mts +8 -0
- package/dist/runtime/app/composables/useConfigDirectorClient.d.ts +8 -0
- package/dist/runtime/app/composables/useConfigDirectorClient.mjs +8 -0
- package/dist/runtime/app/composables/useConfigDirectorContext.d.mts +12 -0
- package/dist/runtime/app/composables/useConfigDirectorContext.d.ts +12 -0
- package/dist/runtime/app/composables/useConfigDirectorContext.mjs +30 -0
- package/dist/runtime/app/composables/useConfigDirectorStatus.d.mts +10 -0
- package/dist/runtime/app/composables/useConfigDirectorStatus.d.ts +10 -0
- package/dist/runtime/app/composables/useConfigDirectorStatus.mjs +13 -0
- package/dist/runtime/app/composables/useConfigDirectorValue.d.mts +12 -0
- package/dist/runtime/app/composables/useConfigDirectorValue.d.ts +12 -0
- package/dist/runtime/app/composables/useConfigDirectorValue.mjs +19 -0
- package/dist/runtime/nitro/middleware.d.mts +130 -0
- package/dist/runtime/nitro/middleware.d.ts +130 -0
- package/dist/runtime/nitro/middleware.mjs +8 -0
- package/dist/runtime/nitro/plugin.d.mts +12 -0
- package/dist/runtime/nitro/plugin.d.ts +12 -0
- package/dist/runtime/nitro/plugin.mjs +1397 -0
- package/dist/runtime/plugin.client.d.mts +4 -0
- package/dist/runtime/plugin.client.mjs +1162 -0
- package/dist/runtime/plugin.server.d.mts +4 -0
- package/dist/runtime/plugin.server.mjs +106 -0
- package/dist/runtime/server/composables/useConfigDirectorClient.d.mts +6 -0
- package/dist/runtime/server/composables/useConfigDirectorClient.d.ts +6 -0
- package/dist/runtime/server/composables/useConfigDirectorClient.mjs +9 -0
- package/dist/runtime/types-CQWNx-gI.d.mts +34 -0
- package/dist/runtime/types-CkzBXJwA.d.mts +4 -0
- package/dist/runtime/types-D9MFb76Q.d.mts +85 -0
- package/dist/runtime/types-KSnINlzh.d.mts +135 -0
- package/package.json +76 -0
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# ConfigDirector Nuxt SDK
|
|
2
|
+
|
|
3
|
+
## Getting started
|
|
4
|
+
|
|
5
|
+
### 1. Install
|
|
6
|
+
|
|
7
|
+
Install from NPM:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install --save @configdirector/nuxt-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### 2. Configure the Nuxt module
|
|
14
|
+
|
|
15
|
+
The Nuxt SDK requires the client SDK key for evaluation in the browser, and the server SDK key for server side rendering (SSR) and for server routes.
|
|
16
|
+
|
|
17
|
+
You can provide the keys in `nuxt.config.ts`:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
export default defineNuxtConfig({
|
|
21
|
+
//...
|
|
22
|
+
modules: ["@configdirector/nuxt-sdk"],
|
|
23
|
+
runtimeConfig: {
|
|
24
|
+
public: {
|
|
25
|
+
configdirector: {
|
|
26
|
+
clientSdkKey: "YOUR-CLIENT-SDK-KEY",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
configdirector: {
|
|
30
|
+
serverSdkKey: "YOUR-SERVER-SDK-KEY", // This is a secret, do not commit to your source repository
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Since the server SDK key is a secret value, the recommended approach is to provide it via an environment variable:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
export NUXT_CONFIGDIRECTOR_SERVER_SDK_KEY=YOUR-SERVER-SDK-KEY
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The client key can also be provided via an environment variable, which overrides the key provided in: `nuxt.config.ts`:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
export NUXT_PUBLIC_CONFIGDIRECTOR_CLIENT_SDK_KEY=YOUR-CLIENT-SDK-KEY
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 3. Retrieve config values
|
|
49
|
+
|
|
50
|
+
Retrieve a config value with the `useConfigDirectorValue` composable:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
<script setup lang="ts">
|
|
54
|
+
const { value } = useConfigDirectorValue<string>("my-config", "default value");
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<template>
|
|
58
|
+
<div>my-config is : {{ value }}</div>
|
|
59
|
+
</template>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
You can also determine if the client is still initializing, so rather than transition from the default value to the evaluated value, you can show a loading state until the client is ready and config values are evaluated:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
<script setup lang="ts">
|
|
66
|
+
const { value, loading } = useConfigDirectorValue<string>("my-config", "default value");
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<div v-if="loading">Loading...</div>
|
|
71
|
+
<div v-else>my-config is : {{ value }}</div>
|
|
72
|
+
</template>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Alternatively, you can also use the `useConfigDirectorStatus` composable to retrieve just the status:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
<script setup lang="ts">
|
|
79
|
+
const { loading } = useConfigDirectorStatus();
|
|
80
|
+
</script>
|
|
81
|
+
|
|
82
|
+
<template>
|
|
83
|
+
<div v-if="loading">Loading...</div>
|
|
84
|
+
<div v-else><SomeComponentThatUsesConfigValues /></div>
|
|
85
|
+
</template>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 4. Updating the user context
|
|
89
|
+
|
|
90
|
+
Update the user context with the `useConfigDirectorContext` composable:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
<script setup lang="ts">
|
|
94
|
+
const { context, updateContext } = useConfigDirectorContext();
|
|
95
|
+
const { value } = useConfigDirectorValue<string>("my-config", "default value");
|
|
96
|
+
|
|
97
|
+
const onUpdate = () => {
|
|
98
|
+
updateContext({
|
|
99
|
+
id: "54321",
|
|
100
|
+
name: "Another User",
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
</script>
|
|
104
|
+
|
|
105
|
+
<template>
|
|
106
|
+
<div>Current context: {{ context }}</div>
|
|
107
|
+
<div>my-config is : {{ value }}</div>
|
|
108
|
+
<button type="button" @click="onUpdate">Update Context</button>
|
|
109
|
+
</template>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 5. Retrieving config values in a server handler
|
|
113
|
+
|
|
114
|
+
On the server side, there is a Nitro composable to retrieve the ConfigDirector client:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
export default defineEventHandler(async (_event) => {
|
|
118
|
+
const client = useConfigDirectorClient();
|
|
119
|
+
return client.getValue("my-config", "default value");
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`getValue` can also accepts an optional user context:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
export default defineEventHandler(async (_event) => {
|
|
127
|
+
const client = useConfigDirectorClient();
|
|
128
|
+
return client.getValue("my-config", "default value", { id: "some-user-id", name: "Example User" });
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The server side evaluation is performed entirely by the SDK. Unlike the browser client which must retrieve new values when the user context is updated, the server evaluator can evaluate targeting rules locally (without additional network requests to ConfigDirector) for any user context.
|
|
133
|
+
|
|
134
|
+
## Getting Help
|
|
135
|
+
|
|
136
|
+
Reach out to us via https://www.configdirector.com/support
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as _$_nuxt_schema0 from "@nuxt/schema";
|
|
2
|
+
import { LogLevel } from "consola";
|
|
3
|
+
|
|
4
|
+
//#region src/module.d.ts
|
|
5
|
+
interface ConfigDirectorRuntimeConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Your ConfigDirector Server SDK key. You can obtain this key from the ConfigDirector
|
|
8
|
+
* dashboard under the project settings.
|
|
9
|
+
*
|
|
10
|
+
* This is a secret value and should not be committed to a source code repository. Alternatively,
|
|
11
|
+
* it can be provided at runtime via the NUXT_CONFIGDIRECTOR_SERVER_SDK_KEY environment variable.
|
|
12
|
+
*/
|
|
13
|
+
serverSdkKey: string;
|
|
14
|
+
/**
|
|
15
|
+
* Log level for the server side of the ConfigDirector Nuxt SDK, using consola's numeric levels.
|
|
16
|
+
* 0 = error, 1 = warn, 2 = log, 3 = info, 4 = debug, 5 = trace.
|
|
17
|
+
* This value overrides the module's logLevel and the global Nuxt/consola log level.
|
|
18
|
+
*/
|
|
19
|
+
logLevel?: LogLevel;
|
|
20
|
+
/**
|
|
21
|
+
* Override the ConfigDirector server API base URL. Only update this if you are using a proxy
|
|
22
|
+
* for ConfigDirector.
|
|
23
|
+
* Can be set via the NUXT_CONFIGDIRECTOR_BASE_URL environment variable.
|
|
24
|
+
*/
|
|
25
|
+
baseUrl?: string;
|
|
26
|
+
}
|
|
27
|
+
interface ConfigDirectorPublicRuntimeConfig {
|
|
28
|
+
/**
|
|
29
|
+
* Your ConfigDirector Client SDK key. You can obtain this key from the ConfigDirector
|
|
30
|
+
* dashboard under the project settings.
|
|
31
|
+
*
|
|
32
|
+
* This value is not a secret. It can alternatively be provided at runtime via the
|
|
33
|
+
* NUXT_PUBLIC_CONFIGDIRECTOR_CLIENT_SDK_KEY environment variable.
|
|
34
|
+
*/
|
|
35
|
+
clientSdkKey: string;
|
|
36
|
+
/**
|
|
37
|
+
* Your app's name. This value can be used in ConfigDirector targeting rules.
|
|
38
|
+
*/
|
|
39
|
+
appName?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Your app's version. This value can be used in ConfigDirector targeting rules.
|
|
42
|
+
*
|
|
43
|
+
* This can be a semver value or an arbitrary string (like a commit hash).
|
|
44
|
+
*/
|
|
45
|
+
appVersion?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Log level for the client/browser side of the ConfigDirector Nuxt SDK, using consola's numeric levels.
|
|
48
|
+
* 0 = error, 1 = warn, 2 = log, 3 = info, 4 = debug, 5 = trace.
|
|
49
|
+
* This value overrides the module's logLevel and the global Nuxt/consola log level.
|
|
50
|
+
*/
|
|
51
|
+
logLevel?: LogLevel;
|
|
52
|
+
/**
|
|
53
|
+
* Override the ConfigDirector client API base URL. Primarily useful for testing.
|
|
54
|
+
* When omitted, the default ConfigDirector client endpoint is used.
|
|
55
|
+
* Can be set via the NUXT_PUBLIC_CONFIGDIRECTOR_BASE_URL environment variable.
|
|
56
|
+
*/
|
|
57
|
+
baseUrl?: string;
|
|
58
|
+
}
|
|
59
|
+
declare module "nuxt/schema" {
|
|
60
|
+
interface RuntimeConfig {
|
|
61
|
+
configdirector: ConfigDirectorRuntimeConfig;
|
|
62
|
+
}
|
|
63
|
+
interface PublicRuntimeConfig {
|
|
64
|
+
configdirector: ConfigDirectorPublicRuntimeConfig;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
declare module "@nuxt/schema" {
|
|
68
|
+
interface RuntimeConfig {
|
|
69
|
+
configdirector: ConfigDirectorRuntimeConfig;
|
|
70
|
+
}
|
|
71
|
+
interface PublicRuntimeConfig {
|
|
72
|
+
configdirector: ConfigDirectorPublicRuntimeConfig;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
interface ModuleOptions {
|
|
76
|
+
/**
|
|
77
|
+
* Log level for the ConfigDirector SDK, using consola's numeric levels.
|
|
78
|
+
* 0 = error, 1 = warn, 2 = log, 3 = info, 4 = debug, 5 = trace.
|
|
79
|
+
* When omitted, the SDK inherits the global Nuxt/consola log level.
|
|
80
|
+
*/
|
|
81
|
+
logLevel?: LogLevel;
|
|
82
|
+
}
|
|
83
|
+
declare const _default: _$_nuxt_schema0.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
84
|
+
//#endregion
|
|
85
|
+
export { ModuleOptions, _default as default };
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { addImports, addPlugin, addServerHandler, addServerImports, addServerPlugin, createResolver, defineNuxtModule, useLogger } from "@nuxt/kit";
|
|
2
|
+
import { defu } from "defu";
|
|
3
|
+
//#region src/module.ts
|
|
4
|
+
var module_default = defineNuxtModule({
|
|
5
|
+
meta: {
|
|
6
|
+
name: "@configdirector/nuxt-sdk",
|
|
7
|
+
configKey: "configdirector",
|
|
8
|
+
compatibility: { nuxt: ">=4.0.0" }
|
|
9
|
+
},
|
|
10
|
+
defaults: {},
|
|
11
|
+
setup(options, nuxt) {
|
|
12
|
+
const logger = useLogger("configdirector");
|
|
13
|
+
const resolver = createResolver(import.meta.url);
|
|
14
|
+
nuxt.options.runtimeConfig.configdirector = defu(nuxt.options.runtimeConfig.configdirector, options.logLevel !== void 0 ? {
|
|
15
|
+
serverSdkKey: "",
|
|
16
|
+
logLevel: options.logLevel,
|
|
17
|
+
baseUrl: ""
|
|
18
|
+
} : {
|
|
19
|
+
serverSdkKey: "",
|
|
20
|
+
baseUrl: ""
|
|
21
|
+
});
|
|
22
|
+
nuxt.options.runtimeConfig.public.configdirector = defu(nuxt.options.runtimeConfig.public.configdirector, options.logLevel !== void 0 ? {
|
|
23
|
+
clientSdkKey: "",
|
|
24
|
+
logLevel: options.logLevel,
|
|
25
|
+
baseUrl: ""
|
|
26
|
+
} : {
|
|
27
|
+
clientSdkKey: "",
|
|
28
|
+
baseUrl: ""
|
|
29
|
+
});
|
|
30
|
+
logger.debug("ConfigDirector Nuxt module setup complete");
|
|
31
|
+
addServerPlugin(resolver.resolve("./runtime/nitro/plugin"));
|
|
32
|
+
addServerHandler({
|
|
33
|
+
middleware: true,
|
|
34
|
+
handler: resolver.resolve("./runtime/nitro/middleware")
|
|
35
|
+
});
|
|
36
|
+
addServerImports({
|
|
37
|
+
name: "useConfigDirectorClient",
|
|
38
|
+
as: "useConfigDirectorClient",
|
|
39
|
+
from: resolver.resolve("./runtime/server/composables/useConfigDirectorClient")
|
|
40
|
+
});
|
|
41
|
+
addPlugin(resolver.resolve("./runtime/plugin.server"));
|
|
42
|
+
addPlugin(resolver.resolve("./runtime/plugin.client"));
|
|
43
|
+
addImports({
|
|
44
|
+
name: "useConfigDirectorClient",
|
|
45
|
+
as: "useConfigDirectorClient",
|
|
46
|
+
from: resolver.resolve("./runtime/app/composables/useConfigDirectorClient")
|
|
47
|
+
});
|
|
48
|
+
addImports({
|
|
49
|
+
name: "useConfigDirectorStatus",
|
|
50
|
+
as: "useConfigDirectorStatus",
|
|
51
|
+
from: resolver.resolve("./runtime/app/composables/useConfigDirectorStatus")
|
|
52
|
+
});
|
|
53
|
+
addImports({
|
|
54
|
+
name: "useConfigDirectorContext",
|
|
55
|
+
as: "useConfigDirectorContext",
|
|
56
|
+
from: resolver.resolve("./runtime/app/composables/useConfigDirectorContext")
|
|
57
|
+
});
|
|
58
|
+
addImports({
|
|
59
|
+
name: "useConfigDirectorValue",
|
|
60
|
+
as: "useConfigDirectorValue",
|
|
61
|
+
from: resolver.resolve("./runtime/app/composables/useConfigDirectorValue")
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
//#endregion
|
|
66
|
+
export { module_default as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { t as ConfigDirectorClient } from "../../types-KSnINlzh.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/app/composables/useConfigDirectorClient.d.ts
|
|
4
|
+
declare const useConfigDirectorClient: () => {
|
|
5
|
+
client: ConfigDirectorClient;
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { useConfigDirectorClient };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { t as ConfigDirectorClient } from "../../types-KSnINlzh.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/app/composables/useConfigDirectorClient.d.ts
|
|
4
|
+
declare const useConfigDirectorClient: () => {
|
|
5
|
+
client: ConfigDirectorClient;
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { useConfigDirectorClient };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useNuxtApp } from "#app";
|
|
2
|
+
//#region src/runtime/app/composables/useConfigDirectorClient.ts
|
|
3
|
+
const useConfigDirectorClient = () => {
|
|
4
|
+
const { $configDirectorClient } = useNuxtApp();
|
|
5
|
+
return { client: $configDirectorClient };
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { useConfigDirectorClient };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as ConfigDirectorContext } from "../../types-CQWNx-gI.mjs";
|
|
2
|
+
import { Ref } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/app/composables/useConfigDirectorContext.d.ts
|
|
5
|
+
declare const useConfigDirectorContext: () => {
|
|
6
|
+
context: Readonly<Ref<ConfigDirectorContext | undefined>>;
|
|
7
|
+
updateContext: (context: ConfigDirectorContext, options?: {
|
|
8
|
+
timeoutMilliseconds: number;
|
|
9
|
+
}) => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useConfigDirectorContext };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as ConfigDirectorContext } from "../../types-CQWNx-gI.mjs";
|
|
2
|
+
import { Ref } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/app/composables/useConfigDirectorContext.d.ts
|
|
5
|
+
declare const useConfigDirectorContext: () => {
|
|
6
|
+
context: Readonly<Ref<ConfigDirectorContext | undefined>>;
|
|
7
|
+
updateContext: (context: ConfigDirectorContext, options?: {
|
|
8
|
+
timeoutMilliseconds: number;
|
|
9
|
+
}) => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useConfigDirectorContext };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useConfigDirectorClient } from "./useConfigDirectorClient.mjs";
|
|
2
|
+
import { useState } from "#app";
|
|
3
|
+
import { readonly, toRaw } from "vue";
|
|
4
|
+
//#region src/runtime/app/composables/useConfigDirectorContext.ts
|
|
5
|
+
const DEFAULT_TIMEOUT = 3e3;
|
|
6
|
+
const getEffectiveTimeout = (option) => {
|
|
7
|
+
return option && option > 0 ? option : DEFAULT_TIMEOUT;
|
|
8
|
+
};
|
|
9
|
+
const useConfigDirectorContext = () => {
|
|
10
|
+
const state = useState("configdirector-context");
|
|
11
|
+
const { client } = useConfigDirectorClient();
|
|
12
|
+
const updateContext = async (context, options) => {
|
|
13
|
+
const rawContext = toRaw(context);
|
|
14
|
+
const oldContext = JSON.stringify(state.value);
|
|
15
|
+
const newContext = JSON.stringify(rawContext);
|
|
16
|
+
state.value = rawContext;
|
|
17
|
+
if (oldContext != newContext) {
|
|
18
|
+
const timeout = getEffectiveTimeout(options?.timeoutMilliseconds);
|
|
19
|
+
await Promise.race([client.updateContext(rawContext), new Promise((resolve) => {
|
|
20
|
+
setTimeout(() => resolve(), timeout);
|
|
21
|
+
})]);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
context: readonly(state),
|
|
26
|
+
updateContext
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { useConfigDirectorContext };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as ClientStatus } from "../../types-CkzBXJwA.mjs";
|
|
2
|
+
import { Ref, ShallowRef } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/app/composables/useConfigDirectorStatus.d.ts
|
|
5
|
+
declare const useConfigDirectorStatus: () => {
|
|
6
|
+
readyStatus: Readonly<ShallowRef<ClientStatus>>;
|
|
7
|
+
loading: Readonly<Ref<boolean>>;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { useConfigDirectorStatus };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as ClientStatus } from "../../types-CkzBXJwA.mjs";
|
|
2
|
+
import { Ref, ShallowRef } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/app/composables/useConfigDirectorStatus.d.ts
|
|
5
|
+
declare const useConfigDirectorStatus: () => {
|
|
6
|
+
readyStatus: Readonly<ShallowRef<ClientStatus>>;
|
|
7
|
+
loading: Readonly<Ref<boolean>>;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { useConfigDirectorStatus };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useNuxtApp } from "#app";
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
//#region src/runtime/app/composables/useConfigDirectorStatus.ts
|
|
4
|
+
const useConfigDirectorStatus = () => {
|
|
5
|
+
const { $configDirectorClientReadyStatus } = useNuxtApp();
|
|
6
|
+
const readyStatus = $configDirectorClientReadyStatus;
|
|
7
|
+
return {
|
|
8
|
+
readyStatus,
|
|
9
|
+
loading: computed(() => readyStatus.value === "loading")
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { useConfigDirectorStatus };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { n as ConfigValueType } from "../../types-CQWNx-gI.mjs";
|
|
2
|
+
import { t as ClientStatus } from "../../types-CkzBXJwA.mjs";
|
|
3
|
+
import { Ref, ShallowRef } from "vue";
|
|
4
|
+
|
|
5
|
+
//#region src/runtime/app/composables/useConfigDirectorValue.d.ts
|
|
6
|
+
declare const useConfigDirectorValue: <T extends ConfigValueType>(configKey: string, defaultValue: T) => {
|
|
7
|
+
value: ShallowRef<T>;
|
|
8
|
+
readyStatus: Readonly<Ref<ClientStatus>>;
|
|
9
|
+
loading: Readonly<Ref<boolean>>;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useConfigDirectorValue };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { n as ConfigValueType } from "../../types-CQWNx-gI.mjs";
|
|
2
|
+
import { t as ClientStatus } from "../../types-CkzBXJwA.mjs";
|
|
3
|
+
import { Ref, ShallowRef } from "vue";
|
|
4
|
+
|
|
5
|
+
//#region src/runtime/app/composables/useConfigDirectorValue.d.ts
|
|
6
|
+
declare const useConfigDirectorValue: <T extends ConfigValueType>(configKey: string, defaultValue: T) => {
|
|
7
|
+
value: ShallowRef<T>;
|
|
8
|
+
readyStatus: Readonly<Ref<ClientStatus>>;
|
|
9
|
+
loading: Readonly<Ref<boolean>>;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useConfigDirectorValue };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useConfigDirectorClient } from "./useConfigDirectorClient.mjs";
|
|
2
|
+
import { useConfigDirectorStatus } from "./useConfigDirectorStatus.mjs";
|
|
3
|
+
import { onBeforeUnmount, shallowRef } from "vue";
|
|
4
|
+
//#region src/runtime/app/composables/useConfigDirectorValue.ts
|
|
5
|
+
const useConfigDirectorValue = (configKey, defaultValue) => {
|
|
6
|
+
const { client } = useConfigDirectorClient();
|
|
7
|
+
const { readyStatus, loading } = useConfigDirectorStatus();
|
|
8
|
+
const configValue = shallowRef(client.getValue(configKey, defaultValue));
|
|
9
|
+
const watcher = (newValue) => configValue.value = newValue;
|
|
10
|
+
client.watch(configKey, defaultValue, watcher);
|
|
11
|
+
onBeforeUnmount(() => client.unwatch(configKey, watcher));
|
|
12
|
+
return {
|
|
13
|
+
value: configValue,
|
|
14
|
+
readyStatus,
|
|
15
|
+
loading
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { useConfigDirectorValue };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import * as _$h3 from "h3";
|
|
2
|
+
|
|
3
|
+
//#region ../js-server-sdk/dist/configdirector-server.d.cts
|
|
4
|
+
//#region ../shared/src/types.d.ts
|
|
5
|
+
type ConfigEnumLikeType = {
|
|
6
|
+
[key: string]: string | number;
|
|
7
|
+
};
|
|
8
|
+
type ConfigValueType = string | number | boolean | object | ConfigEnumLikeType;
|
|
9
|
+
/**
|
|
10
|
+
* The user's context to be sent to ConfigDirector. This context will be used for targeting
|
|
11
|
+
* rules evaluation.
|
|
12
|
+
*/
|
|
13
|
+
type ConfigDirectorContext = {
|
|
14
|
+
/**
|
|
15
|
+
* The user's identifier. This should be a value that uniquely identifies an application
|
|
16
|
+
* user.
|
|
17
|
+
* In the case of anonymous users, you could generate a UUID or alternatively not provide
|
|
18
|
+
* the {@link id} and the SDK will generate a random UUID. However, keep in mind that this
|
|
19
|
+
* value is used for segmenting users in percentage rollouts, and changes to the {@link id}
|
|
20
|
+
* could result in the user being assigned to a different percentile.
|
|
21
|
+
*/
|
|
22
|
+
id?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The user's display name. This will be shown in the ConfigDirector dashboard and may be
|
|
25
|
+
* used for targeting rules.
|
|
26
|
+
*/
|
|
27
|
+
name?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Any arbitrary traits for the current user. They will be shown in the ConfigDirector
|
|
30
|
+
* dashboard and may be used for targeting rules.
|
|
31
|
+
*/
|
|
32
|
+
traits?: {
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Metadata about your application. It is recommended you include these values when configuring
|
|
38
|
+
* a ConfigDirector client so that you can use them in targeting rules.
|
|
39
|
+
*/
|
|
40
|
+
type ClientEvents = {
|
|
41
|
+
configsUpdated: {
|
|
42
|
+
keys: string[];
|
|
43
|
+
};
|
|
44
|
+
clientReady: undefined;
|
|
45
|
+
};
|
|
46
|
+
type WatchHandler<T extends ConfigValueType> = (message: T) => void;
|
|
47
|
+
/**
|
|
48
|
+
* The ConfigDirector SDK client object.
|
|
49
|
+
*
|
|
50
|
+
* Applications should create a single instance of `ConfigDirectorClient`, and call
|
|
51
|
+
* {@link initialize} during application initialization.
|
|
52
|
+
*/
|
|
53
|
+
interface ConfigDirectorClient {
|
|
54
|
+
/**
|
|
55
|
+
* Initializes the connection to ConfigDirector to retrieve config definitions. Until
|
|
56
|
+
* initialization is successful, all flags will return their default value provided to
|
|
57
|
+
* {@link watch} or {@link getValue}.
|
|
58
|
+
*
|
|
59
|
+
* If the connection fails or is interrupted with a transient error (network error,
|
|
60
|
+
* internal server error, etc) the client will continue to attempt to connect. However,
|
|
61
|
+
* if the connection fails with a persistent error, like an invalid SDK key, the client will
|
|
62
|
+
* not attempt to re-connect and an error will be logged to the console or the provided
|
|
63
|
+
* logger.
|
|
64
|
+
*/
|
|
65
|
+
initialize(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Returns whether or not the client is ready after calling {@link initialize}
|
|
68
|
+
*
|
|
69
|
+
* The definition of ready is that the connection to the server was successful, and config definitions
|
|
70
|
+
* were received.
|
|
71
|
+
*/
|
|
72
|
+
get isReady(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Evaluates a config and returns its value based on the current context and targeting rules
|
|
75
|
+
*
|
|
76
|
+
* @returns The evaluated config value, or the `defaultValue` if the config state was unavailable
|
|
77
|
+
* @param configKey The config key to evaluate
|
|
78
|
+
* @param defaultValue The default value to be returned if the config state is unavailable. For
|
|
79
|
+
* example, if the client cannot connect to the server due to network conditions, or if getValue
|
|
80
|
+
* is called before initialization is done.
|
|
81
|
+
* @param context The user's context to be used for targeting rules evaluation (optional)
|
|
82
|
+
*/
|
|
83
|
+
getValue<T extends ConfigValueType>(configKey: string, defaultValue: T, context?: ConfigDirectorContext): T;
|
|
84
|
+
/**
|
|
85
|
+
* Watches for changes to a a config evaluation value. Whenever the config value changes, the
|
|
86
|
+
* provided callback function will be called with the new value. Changes can happen due to updates
|
|
87
|
+
* to the config in the ConfigDirector dashboard, or if the context is updated via {@link updateContext}.
|
|
88
|
+
*
|
|
89
|
+
* @returns An 'unwatch' function that can be called to remove the subscriber
|
|
90
|
+
*
|
|
91
|
+
* @param configKey The config key to watch
|
|
92
|
+
* @param defaultValue The default value to be referenced if the config state is unavailable
|
|
93
|
+
* @param callback The callback function to be called whenever the config value is updated
|
|
94
|
+
* @param context The user's context to be used for targeting rules evaluation (optional)
|
|
95
|
+
*/
|
|
96
|
+
watch<T extends ConfigValueType>(configKey: string, defaultValue: T, callback: WatchHandler<T>, context?: ConfigDirectorContext): () => void;
|
|
97
|
+
/**
|
|
98
|
+
* Removes a particular subscriber to the given `configKey`, or all subscribers if no callback
|
|
99
|
+
* is provided.
|
|
100
|
+
*
|
|
101
|
+
* @param configKey The config key to remove subscribers from
|
|
102
|
+
* @param callback The subscriber to be removed. If not provided, all subscribers are removed for
|
|
103
|
+
* the given `configKey`.
|
|
104
|
+
*/
|
|
105
|
+
unwatch<T extends ConfigValueType>(configKey: string, callback?: WatchHandler<T>): void;
|
|
106
|
+
/**
|
|
107
|
+
* Removes all subscribers from all config keys
|
|
108
|
+
*/
|
|
109
|
+
unwatchAll(): void;
|
|
110
|
+
on<T extends keyof ClientEvents>(eventName: T, handler: (args: ClientEvents[T]) => void): void;
|
|
111
|
+
off<T extends keyof ClientEvents>(eventName: T, handler?: (args: ClientEvents[T]) => void): void;
|
|
112
|
+
/**
|
|
113
|
+
* Disposes of the client. All connections are closed, and all event and config key subscribers
|
|
114
|
+
* are removed.
|
|
115
|
+
*
|
|
116
|
+
* Intended to be called when your application shuts down
|
|
117
|
+
*/
|
|
118
|
+
dispose(): void;
|
|
119
|
+
} //#endregion
|
|
120
|
+
//#region ../shared/src/logger.d.ts
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/runtime/nitro/middleware.d.ts
|
|
123
|
+
declare const _default: _$h3.EventHandler<_$h3.EventHandlerRequest, void>;
|
|
124
|
+
declare module "h3" {
|
|
125
|
+
interface H3EventContext {
|
|
126
|
+
configDirectorClient: ConfigDirectorClient;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
export { _default as default };
|