@configdirector/nuxt-sdk 0.1.1 → 0.5.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 +4 -142
- package/dist/module.json +1 -1
- package/dist/module.mjs +25 -23
- 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/useConfigDirectorContext.d.mts +1 -1
- package/dist/runtime/app/composables/useConfigDirectorContext.d.ts +1 -1
- package/dist/runtime/app/composables/useConfigDirectorValue.d.mts +1 -1
- package/dist/runtime/app/composables/useConfigDirectorValue.d.ts +1 -1
- package/dist/runtime/nitro/middleware.d.mts +1 -119
- package/dist/runtime/nitro/middleware.d.ts +1 -119
- package/dist/runtime/nitro/plugin.d.mts +1 -1
- package/dist/runtime/nitro/plugin.d.ts +1 -1
- package/dist/runtime/nitro/plugin.mjs +200 -34
- package/dist/runtime/plugin.client.mjs +134 -53
- package/dist/runtime/server/composables/useConfigDirectorClient.d.mts +1 -1
- package/dist/runtime/server/composables/useConfigDirectorClient.d.ts +1 -1
- package/dist/runtime/{types-CQWNx-gI.d.mts → types-BWxsGnk2.d.mts} +9 -1
- package/dist/runtime/{types-KSnINlzh.d.mts → types-D9IS8RoC.d.mts} +1 -1
- package/dist/runtime/{types-D9MFb76Q.d.mts → types-DGQ1B6mZ.d.mts} +12 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,150 +1,12 @@
|
|
|
1
1
|
# ConfigDirector Nuxt SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is the Nuxt SDK for [ConfigDirector](https://www.configdirector.com).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Documentation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Refer to the [official documentation for the Nuxt SDK](https://docs.configdirector.com/sdks/meta/nuxt).
|
|
8
8
|
|
|
9
|
-
|
|
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
|
-
The `value` returned is a ShallowRef that will update whenever the config value is updated in the ConfigDirector dashboard, or if it evaluates to a different value due to targeting rules (for example, if the user context is updated). Keep in mind that it is a ShallowRef when accessing it in scripts:
|
|
63
|
-
|
|
64
|
-
```ts
|
|
65
|
-
<script setup lang="ts">
|
|
66
|
-
const { value: myConfigValue } = useConfigDirectorValue<string>("my-config", "default value");
|
|
67
|
-
|
|
68
|
-
const someOtherDerivedValue = computed(() => `Hello ${myConfigValue.value}`);
|
|
69
|
-
</script>
|
|
70
|
-
|
|
71
|
-
<template>
|
|
72
|
-
<div>my-config is : {{ someOtherDerivedValue }}</div>
|
|
73
|
-
</template>
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
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:
|
|
78
|
-
|
|
79
|
-
```ts
|
|
80
|
-
<script setup lang="ts">
|
|
81
|
-
const { value, loading } = useConfigDirectorValue<string>("my-config", "default value");
|
|
82
|
-
</script>
|
|
83
|
-
|
|
84
|
-
<template>
|
|
85
|
-
<div v-if="loading">Loading...</div>
|
|
86
|
-
<div v-else>my-config is : {{ value }}</div>
|
|
87
|
-
</template>
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Additionally, you can also use the `useConfigDirectorStatus` composable to retrieve just the status:
|
|
91
|
-
|
|
92
|
-
```ts
|
|
93
|
-
<script setup lang="ts">
|
|
94
|
-
const { loading } = useConfigDirectorStatus();
|
|
95
|
-
</script>
|
|
96
|
-
|
|
97
|
-
<template>
|
|
98
|
-
<div v-if="loading">Loading...</div>
|
|
99
|
-
<div v-else><SomeComponentThatUsesConfigValues /></div>
|
|
100
|
-
</template>
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### 4. Updating the user context
|
|
104
|
-
|
|
105
|
-
Update the user context with the `useConfigDirectorContext` composable:
|
|
106
|
-
|
|
107
|
-
```ts
|
|
108
|
-
<script setup lang="ts">
|
|
109
|
-
const { context, updateContext } = useConfigDirectorContext();
|
|
110
|
-
const { value } = useConfigDirectorValue<string>("my-config", "default value");
|
|
111
|
-
|
|
112
|
-
const onUpdate = () => {
|
|
113
|
-
updateContext({
|
|
114
|
-
id: "54321",
|
|
115
|
-
name: "Another User",
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
</script>
|
|
119
|
-
|
|
120
|
-
<template>
|
|
121
|
-
<div>Current context: {{ context }}</div>
|
|
122
|
-
<div>my-config is : {{ value }}</div>
|
|
123
|
-
<button type="button" @click="onUpdate">Update Context</button>
|
|
124
|
-
</template>
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### 5. Retrieving config values in a server handler
|
|
128
|
-
|
|
129
|
-
On the server side, there is a Nitro composable to retrieve the ConfigDirector client:
|
|
130
|
-
|
|
131
|
-
```ts
|
|
132
|
-
export default defineEventHandler(async (_event) => {
|
|
133
|
-
const client = useConfigDirectorClient();
|
|
134
|
-
return client.getValue("my-config", "default value");
|
|
135
|
-
});
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
`getValue` also accepts an optional user context:
|
|
139
|
-
|
|
140
|
-
```ts
|
|
141
|
-
export default defineEventHandler(async (_event) => {
|
|
142
|
-
const client = useConfigDirectorClient();
|
|
143
|
-
return client.getValue("my-config", "default value", { id: "some-user-id", name: "Example User" });
|
|
144
|
-
});
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
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.
|
|
9
|
+
There is also [a quickstart guide for ConfigDirector and any of our SDKs](https://docs.configdirector.com/getting-started/quickstart).
|
|
148
10
|
|
|
149
11
|
## Getting Help
|
|
150
12
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -5,7 +5,7 @@ var module_default = defineNuxtModule({
|
|
|
5
5
|
meta: {
|
|
6
6
|
name: "@configdirector/nuxt-sdk",
|
|
7
7
|
configKey: "configdirector",
|
|
8
|
-
compatibility: { nuxt: ">=
|
|
8
|
+
compatibility: { nuxt: ">=3.7.0" }
|
|
9
9
|
},
|
|
10
10
|
defaults: {},
|
|
11
11
|
setup(options, nuxt) {
|
|
@@ -33,33 +33,35 @@ var module_default = defineNuxtModule({
|
|
|
33
33
|
middleware: true,
|
|
34
34
|
handler: resolver.resolve("./runtime/nitro/middleware")
|
|
35
35
|
});
|
|
36
|
-
addServerImports({
|
|
36
|
+
addServerImports([{
|
|
37
37
|
name: "useConfigDirectorClient",
|
|
38
38
|
as: "useConfigDirectorClient",
|
|
39
39
|
from: resolver.resolve("./runtime/server/composables/useConfigDirectorClient")
|
|
40
|
-
});
|
|
40
|
+
}]);
|
|
41
41
|
addPlugin(resolver.resolve("./runtime/plugin.server"));
|
|
42
42
|
addPlugin(resolver.resolve("./runtime/plugin.client"));
|
|
43
|
-
addImports(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
43
|
+
addImports([
|
|
44
|
+
{
|
|
45
|
+
name: "useConfigDirectorClient",
|
|
46
|
+
as: "useConfigDirectorClient",
|
|
47
|
+
from: resolver.resolve("./runtime/app/composables/useConfigDirectorClient")
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "useConfigDirectorStatus",
|
|
51
|
+
as: "useConfigDirectorStatus",
|
|
52
|
+
from: resolver.resolve("./runtime/app/composables/useConfigDirectorStatus")
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "useConfigDirectorContext",
|
|
56
|
+
as: "useConfigDirectorContext",
|
|
57
|
+
from: resolver.resolve("./runtime/app/composables/useConfigDirectorContext")
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "useConfigDirectorValue",
|
|
61
|
+
as: "useConfigDirectorValue",
|
|
62
|
+
from: resolver.resolve("./runtime/app/composables/useConfigDirectorValue")
|
|
63
|
+
}
|
|
64
|
+
]);
|
|
63
65
|
}
|
|
64
66
|
});
|
|
65
67
|
//#endregion
|
|
@@ -1,124 +1,6 @@
|
|
|
1
1
|
import * as _$h3 from "h3";
|
|
2
|
+
import { ConfigDirectorClient } from "@configdirector/server-sdk";
|
|
2
3
|
|
|
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
4
|
//#region src/runtime/nitro/middleware.d.ts
|
|
123
5
|
declare const _default: _$h3.EventHandler<_$h3.EventHandlerRequest, void>;
|
|
124
6
|
declare module "h3" {
|
|
@@ -1,124 +1,6 @@
|
|
|
1
1
|
import * as _$h3 from "h3";
|
|
2
|
+
import { ConfigDirectorClient } from "@configdirector/server-sdk";
|
|
2
3
|
|
|
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
4
|
//#region src/runtime/nitro/middleware.d.ts
|
|
123
5
|
declare const _default: _$h3.EventHandler<_$h3.EventHandlerRequest, void>;
|
|
124
6
|
declare module "h3" {
|