@configdirector/nuxt-sdk 1.10.0 → 1.11.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/dist/module.d.mts +76 -15
- package/dist/module.json +1 -1
- package/dist/module.mjs +13 -4
- 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.d.mts +1 -1
- package/dist/runtime/app/composables/useConfigDirectorContext.d.ts +1 -1
- package/dist/runtime/app/composables/useConfigDirectorStatus.d.mts +1 -1
- package/dist/runtime/app/composables/useConfigDirectorStatus.d.ts +1 -1
- package/dist/runtime/app/composables/useConfigDirectorValue.d.mts +2 -2
- package/dist/runtime/app/composables/useConfigDirectorValue.d.ts +2 -2
- package/dist/runtime/{types-IPLvRsUO.d.mts → native-values-BV2k_xR2.d.mts} +11 -1
- package/dist/runtime/native-values-DZJjFBvk.mjs +116 -0
- package/dist/runtime/nitro/middleware.mjs +5 -1
- package/dist/runtime/nitro/offline-values.d.mts +7 -0
- package/dist/runtime/nitro/offline-values.d.ts +7 -0
- package/dist/runtime/nitro/offline-values.mjs +15 -0
- package/dist/runtime/nitro/plugin.d.mts +3 -1
- package/dist/runtime/nitro/plugin.d.ts +3 -1
- package/dist/runtime/nitro/plugin.mjs +232 -83
- package/dist/runtime/plugin.client.mjs +341 -86
- package/dist/runtime/server/composables/useConfigDirectorServerClient.d.mts +6 -0
- package/dist/runtime/server/composables/useConfigDirectorServerClient.d.ts +6 -0
- package/dist/runtime/server/composables/{useConfigDirectorClient.mjs → useConfigDirectorServerClient.mjs} +3 -3
- package/dist/runtime/server/composables/useConfigDirectorServerHooks.d.mts +1 -1
- package/dist/runtime/server/composables/useConfigDirectorServerHooks.d.ts +1 -1
- package/dist/runtime/{types-B9_4pADA.d.mts → types-CS7AMNWe.d.mts} +1 -1
- package/dist/runtime/{types-DQhBe4Ei.d.mts → types-Dt3bENKf.d.mts} +1 -1
- package/dist/testing.d.mts +13 -13
- package/dist/testing.mjs +292 -156
- package/package.json +1 -1
- package/dist/runtime/server/composables/useConfigDirectorClient.d.mts +0 -6
- package/dist/runtime/server/composables/useConfigDirectorClient.d.ts +0 -6
- /package/dist/runtime/{types-F0fKKk6-.d.mts → types-C30VJ25l.d.mts} +0 -0
|
@@ -1,35 +1,13 @@
|
|
|
1
1
|
import { t as admitContext } from "../context-kind-D6YBNij2.mjs";
|
|
2
|
+
import { a as ConfigDirectorValidationError, i as ConfigDirectorInitializationError, n as encodeNativeValue, r as ConfigDirectorConnectionError } from "../native-values-DZJjFBvk.mjs";
|
|
2
3
|
import EventEmitter, { EventEmitter as EventEmitter$1 } from "node:events";
|
|
3
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
|
+
import { readFile } from "node:fs/promises";
|
|
6
|
+
import { resolve } from "node:path";
|
|
4
7
|
import * as semver from "semver";
|
|
5
8
|
import { rapidhash } from "rapidhash-js";
|
|
6
9
|
import { defineNitroPlugin, useRuntimeConfig } from "nitropack/runtime";
|
|
7
10
|
import { consola } from "consola";
|
|
8
|
-
//#region ../shared/src/errors.ts
|
|
9
|
-
var ConfigDirectorConnectionError = class ConfigDirectorConnectionError extends Error {
|
|
10
|
-
name = "ConfigDirectorConnectionError";
|
|
11
|
-
status;
|
|
12
|
-
constructor(message, status) {
|
|
13
|
-
super(message);
|
|
14
|
-
this.status = status;
|
|
15
|
-
Object.setPrototypeOf(this, ConfigDirectorConnectionError.prototype);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
var ConfigDirectorValidationError = class ConfigDirectorValidationError extends Error {
|
|
19
|
-
name = "ConfigDirectorValidationError";
|
|
20
|
-
constructor(message) {
|
|
21
|
-
super(message);
|
|
22
|
-
Object.setPrototypeOf(this, ConfigDirectorValidationError.prototype);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
var ConfigDirectorInitializationError = class ConfigDirectorInitializationError extends Error {
|
|
26
|
-
name = "ConfigDirectorInitializationError";
|
|
27
|
-
constructor(message) {
|
|
28
|
-
super(message);
|
|
29
|
-
Object.setPrototypeOf(this, ConfigDirectorInitializationError.prototype);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
//#endregion
|
|
33
11
|
//#region ../eventsource/src/errors.ts
|
|
34
12
|
var StreamClosedError = class StreamClosedError extends Error {
|
|
35
13
|
name = "StreamClosedError";
|
|
@@ -636,6 +614,150 @@ var PollingTransport = class extends AbstractPollingTransport {
|
|
|
636
614
|
}
|
|
637
615
|
};
|
|
638
616
|
//#endregion
|
|
617
|
+
//#region ../js-server-sdk/src/native-values.ts
|
|
618
|
+
const unconditionalConfig = (id, key, value) => {
|
|
619
|
+
const encoded = encodeNativeValue(key, value);
|
|
620
|
+
return {
|
|
621
|
+
id,
|
|
622
|
+
key,
|
|
623
|
+
type: encoded.type,
|
|
624
|
+
variations: [{
|
|
625
|
+
name: null,
|
|
626
|
+
value: encoded.value
|
|
627
|
+
}],
|
|
628
|
+
target: {
|
|
629
|
+
defaultValue: encoded.value,
|
|
630
|
+
rules: []
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
};
|
|
634
|
+
//#endregion
|
|
635
|
+
//#region ../js-server-sdk/src/OfflineTransport.ts
|
|
636
|
+
const OFFLINE_ENVIRONMENT = {
|
|
637
|
+
environmentId: "offline",
|
|
638
|
+
projectId: "offline"
|
|
639
|
+
};
|
|
640
|
+
var OfflineTransport = class {
|
|
641
|
+
emitter = new EventEmitter();
|
|
642
|
+
connected = false;
|
|
643
|
+
constructor(source) {
|
|
644
|
+
this.source = source;
|
|
645
|
+
}
|
|
646
|
+
async connect() {
|
|
647
|
+
const configs = await loadOfflineConfigs(this.source);
|
|
648
|
+
this.connected = true;
|
|
649
|
+
this.emitter.emit("configBundleReceived", {
|
|
650
|
+
...OFFLINE_ENVIRONMENT,
|
|
651
|
+
kind: "full",
|
|
652
|
+
configs
|
|
653
|
+
});
|
|
654
|
+
return this;
|
|
655
|
+
}
|
|
656
|
+
get isConnected() {
|
|
657
|
+
return this.connected;
|
|
658
|
+
}
|
|
659
|
+
on(name, handler) {
|
|
660
|
+
this.emitter.on(name, handler);
|
|
661
|
+
}
|
|
662
|
+
off(name, handler) {
|
|
663
|
+
if (handler) this.emitter.off(name, handler);
|
|
664
|
+
else this.emitter.removeAllListeners(name);
|
|
665
|
+
}
|
|
666
|
+
close() {
|
|
667
|
+
this.connected = false;
|
|
668
|
+
}
|
|
669
|
+
dispose() {
|
|
670
|
+
this.close();
|
|
671
|
+
this.emitter.removeAllListeners();
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
const loadOfflineConfigs = async (source) => {
|
|
675
|
+
switch (source.kind) {
|
|
676
|
+
case "in-code-defaults": return {};
|
|
677
|
+
case "values": return encodeOfflineValues(source.values, "The offline values");
|
|
678
|
+
case "file": return encodeOfflineValues(await readOfflineValuesFile(source.path), `The offline values file '${source.path}'`);
|
|
679
|
+
case "rejected": throw new ConfigDirectorInitializationError(source.message);
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
const readOfflineValuesFile = async (path) => {
|
|
683
|
+
let text;
|
|
684
|
+
try {
|
|
685
|
+
text = await readFile(resolve(path), "utf8");
|
|
686
|
+
} catch (error) {
|
|
687
|
+
throw new ConfigDirectorInitializationError(`The offline values file '${path}' could not be read: ${messageOf(error)}`);
|
|
688
|
+
}
|
|
689
|
+
let parsed;
|
|
690
|
+
try {
|
|
691
|
+
parsed = JSON.parse(text);
|
|
692
|
+
} catch (error) {
|
|
693
|
+
throw new ConfigDirectorInitializationError(`The offline values file '${path}' is not valid JSON: ${messageOf(error)}`);
|
|
694
|
+
}
|
|
695
|
+
if (!isJsonObject(parsed)) throw new ConfigDirectorInitializationError(`The offline values file '${path}' must hold a JSON object with one value per config key, but holds ${describeJson(parsed)}.`);
|
|
696
|
+
return parsed;
|
|
697
|
+
};
|
|
698
|
+
const encodeOfflineValues = (values, subject) => {
|
|
699
|
+
try {
|
|
700
|
+
return Object.fromEntries(Object.entries(values).map(([key, value]) => [key, unconditionalConfig(`offline:${key}`, key, value)]));
|
|
701
|
+
} catch (error) {
|
|
702
|
+
if (error instanceof ConfigDirectorValidationError) throw new ConfigDirectorInitializationError(`${subject} could not be loaded. ${error.message}`);
|
|
703
|
+
throw error;
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
const isJsonObject = (parsed) => typeof parsed === "object" && parsed !== null && !Array.isArray(parsed);
|
|
707
|
+
const describeJson = (parsed) => {
|
|
708
|
+
if (parsed === null) return "null";
|
|
709
|
+
if (Array.isArray(parsed)) return "an array";
|
|
710
|
+
return `a ${typeof parsed}`;
|
|
711
|
+
};
|
|
712
|
+
const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
713
|
+
//#endregion
|
|
714
|
+
//#region ../js-server-sdk/src/connection-plan.ts
|
|
715
|
+
const defaultBaseUrl = new URL("https://server-sdk-api.configdirector.com");
|
|
716
|
+
const planConnection = (serverSdkKey, connection) => {
|
|
717
|
+
if (connection?.mode === "offline") return {
|
|
718
|
+
kind: "stay-offline",
|
|
719
|
+
source: offlineSourceOf(connection)
|
|
720
|
+
};
|
|
721
|
+
const mode = connection?.mode ?? "streaming";
|
|
722
|
+
if (!serverSdkKey || serverSdkKey.trim().length == 0) throw new ConfigDirectorValidationError("No server SDK key was provided, the client cannot be instantiated without a valid server SDK key");
|
|
723
|
+
if (connection?.file !== void 0 || connection?.values !== void 0) return {
|
|
724
|
+
kind: "stay-offline",
|
|
725
|
+
source: {
|
|
726
|
+
kind: "rejected",
|
|
727
|
+
message: `The connection options 'file' and 'values' apply only when the connection mode is 'offline', but the mode is '${mode}'.`
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
return {
|
|
731
|
+
kind: "connect",
|
|
732
|
+
mode,
|
|
733
|
+
serverSdkKey,
|
|
734
|
+
baseUrl: baseUrlOf(connection?.url)
|
|
735
|
+
};
|
|
736
|
+
};
|
|
737
|
+
const baseUrlOf = (url) => {
|
|
738
|
+
if (!url) return defaultBaseUrl;
|
|
739
|
+
try {
|
|
740
|
+
return new URL(url);
|
|
741
|
+
} catch (error) {
|
|
742
|
+
throw new ConfigDirectorValidationError(`Invalid base URL '${url}'. Parsing failed: ${error}`);
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
const offlineSourceOf = (connection) => {
|
|
746
|
+
if (connection.file !== void 0 && connection.values !== void 0) return {
|
|
747
|
+
kind: "rejected",
|
|
748
|
+
message: "An offline connection takes either 'file' or 'values', not both."
|
|
749
|
+
};
|
|
750
|
+
if (connection.file !== void 0) return {
|
|
751
|
+
kind: "file",
|
|
752
|
+
path: connection.file
|
|
753
|
+
};
|
|
754
|
+
if (connection.values !== void 0) return {
|
|
755
|
+
kind: "values",
|
|
756
|
+
values: connection.values
|
|
757
|
+
};
|
|
758
|
+
return { kind: "in-code-defaults" };
|
|
759
|
+
};
|
|
760
|
+
//#endregion
|
|
639
761
|
//#region ../config-evaluator/src/json-pointer.ts
|
|
640
762
|
const ARRAY_INDEX_PATTERN = /^(?:0|[1-9][0-9]*)$/;
|
|
641
763
|
const INVALID_ESCAPE_PATTERN = /~(?![01])/;
|
|
@@ -7949,6 +8071,14 @@ var ServerTelemetryEventCollector = class extends TelemetryEventCollector {
|
|
|
7949
8071
|
}
|
|
7950
8072
|
};
|
|
7951
8073
|
//#endregion
|
|
8074
|
+
//#region ../js-server-sdk/src/telemetry/discarding.ts
|
|
8075
|
+
const discardingTelemetryClient = {
|
|
8076
|
+
start: () => {},
|
|
8077
|
+
evaluatedConfig: () => {},
|
|
8078
|
+
recordInvalidContext: () => "new-kind-sample",
|
|
8079
|
+
close: async () => {}
|
|
8080
|
+
};
|
|
8081
|
+
//#endregion
|
|
7952
8082
|
//#region ../shared/src/base62-encoder.ts
|
|
7953
8083
|
const BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
7954
8084
|
const toBase62 = (buf, length) => {
|
|
@@ -7971,9 +8101,12 @@ const generateValueId = async (v) => {
|
|
|
7971
8101
|
};
|
|
7972
8102
|
//#endregion
|
|
7973
8103
|
//#region ../js-server-sdk/src/DefaultConfigDirectorClient.ts
|
|
7974
|
-
const defaultBaseUrl = new URL("https://server-sdk-api.configdirector.com");
|
|
7975
8104
|
const DEFAULT_FLUSH_INTERVAL = 3e4;
|
|
7976
8105
|
const DEFAULT_EVENT_QUEUE_LIMIT = 5e3;
|
|
8106
|
+
const liveTimeoutWarningDetails = {
|
|
8107
|
+
streaming: "The client will continue to retry since there were no fatal errors detected. Configs will return the default value until the connection succeeds.",
|
|
8108
|
+
polling: "Since the client was configured without streaming, configs may not update and always return the default value."
|
|
8109
|
+
};
|
|
7977
8110
|
const logInvalidContext = {
|
|
7978
8111
|
"new-kind-sample": (logger, kindSample) => logger.error(`[ConfigDirectorClient] Ignored a context with the invalid kind '${kindSample}' and evaluated as if no context was supplied. A context kind has 1 to 64 characters, using only lowercase letters, digits, '-' and '_'.`),
|
|
7979
8112
|
"known-kind-sample": () => {},
|
|
@@ -7981,7 +8114,7 @@ const logInvalidContext = {
|
|
|
7981
8114
|
"beyond-sample-limit": () => {}
|
|
7982
8115
|
};
|
|
7983
8116
|
const usesAnySegment = (definition, segmentIds) => (definition.target?.rules ?? []).some((rule) => rule.type === "conditional" && (rule.conditions ?? []).some((condition) => condition.kind === "segment" && segmentIds.has(condition.segmentId)));
|
|
7984
|
-
var DefaultConfigDirectorClient = class {
|
|
8117
|
+
var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
7985
8118
|
logger;
|
|
7986
8119
|
usageEventCollector;
|
|
7987
8120
|
configSet;
|
|
@@ -7993,19 +8126,21 @@ var DefaultConfigDirectorClient = class {
|
|
|
7993
8126
|
readyPromise;
|
|
7994
8127
|
readyResolve;
|
|
7995
8128
|
readyTimer;
|
|
7996
|
-
|
|
8129
|
+
connectionPlan;
|
|
7997
8130
|
configEvaluator;
|
|
7998
8131
|
metaContext;
|
|
8132
|
+
static from(serverSdkKeyOrOptions, sdkOptions, clientOptions) {
|
|
8133
|
+
if (typeof serverSdkKeyOrOptions === "object") return new DefaultConfigDirectorClient(void 0, sdkOptions, serverSdkKeyOrOptions);
|
|
8134
|
+
return new DefaultConfigDirectorClient(serverSdkKeyOrOptions, sdkOptions, clientOptions);
|
|
8135
|
+
}
|
|
7999
8136
|
constructor(serverSdkKey, sdkOptions, clientOptions, internalClientOptions) {
|
|
8000
8137
|
this.logger = clientOptions?.logger ?? createDefaultLogger$1();
|
|
8001
8138
|
this.timeout = clientOptions?.connection?.timeout ?? 3e3;
|
|
8002
8139
|
this.metaContext = clientOptions?.metadata ?? {};
|
|
8003
|
-
this.
|
|
8140
|
+
this.connectionPlan = planConnection(serverSdkKey, clientOptions?.connection);
|
|
8004
8141
|
this.configEvaluator = new ConfigEvaluator(this.logger);
|
|
8005
|
-
|
|
8006
|
-
this.
|
|
8007
|
-
this.usageEventCollector = internalClientOptions?.telemetry ?? this.buildTelemetryCollector(serverSdkKey, sdkOptions, baseUrl, clientOptions);
|
|
8008
|
-
this.transport = internalClientOptions?.transport ?? this.buildTransport(serverSdkKey, sdkOptions, baseUrl, clientOptions);
|
|
8142
|
+
this.usageEventCollector = internalClientOptions?.telemetry ?? this.buildTelemetryClient(sdkOptions, clientOptions);
|
|
8143
|
+
this.transport = internalClientOptions?.transport ?? this.buildTransport(sdkOptions, clientOptions);
|
|
8009
8144
|
this.transport.on("configBundleReceived", (configBundle) => {
|
|
8010
8145
|
this.readyResolve?.(false);
|
|
8011
8146
|
const removedKeys = this.findKeysRemovedBy(configBundle);
|
|
@@ -8067,16 +8202,20 @@ var DefaultConfigDirectorClient = class {
|
|
|
8067
8202
|
})]);
|
|
8068
8203
|
this.clearReadyTimer();
|
|
8069
8204
|
}
|
|
8070
|
-
if (!this.ready) {
|
|
8071
|
-
const warningDetails = this.connectionMode === "streaming" ? "The client will continue to retry since there were no fatal errors detected. Configs will return the default value until the connection succeeds." : "Since the client was configured without streaming, configs may not update and always return the default value.";
|
|
8072
|
-
this.logger.warn(`[ConfigDirectorClient] Timed out waiting for initialization after ${this.timeout}ms. ${warningDetails}`);
|
|
8073
|
-
}
|
|
8205
|
+
if (!this.ready) this.logger.warn(`[ConfigDirectorClient] Timed out waiting for initialization after ${this.timeout}ms. ${this.timeoutWarningDetails()}`);
|
|
8074
8206
|
} catch (error) {
|
|
8207
|
+
if (error instanceof ConfigDirectorInitializationError) throw error;
|
|
8075
8208
|
this.logger.error("[ConfigDirectorClient] An error occurred during initialization: ", error);
|
|
8076
8209
|
}
|
|
8077
8210
|
}
|
|
8078
|
-
|
|
8079
|
-
|
|
8211
|
+
timeoutWarningDetails() {
|
|
8212
|
+
switch (this.connectionPlan.kind) {
|
|
8213
|
+
case "connect": return liveTimeoutWarningDetails[this.connectionPlan.mode];
|
|
8214
|
+
case "stay-offline": return "The offline values were not delivered, so configs return the default value.";
|
|
8215
|
+
}
|
|
8216
|
+
}
|
|
8217
|
+
pollingIntervalFor(mode, configuredSeconds) {
|
|
8218
|
+
if (mode !== "polling") return;
|
|
8080
8219
|
const resolved = resolvePollingInterval(configuredSeconds, {
|
|
8081
8220
|
defaultSeconds: 300,
|
|
8082
8221
|
minimumSeconds: 60
|
|
@@ -8084,38 +8223,48 @@ var DefaultConfigDirectorClient = class {
|
|
|
8084
8223
|
if (resolved.warning) this.logger.warn(`[ConfigDirectorClient] ${resolved.warning}`);
|
|
8085
8224
|
return resolved.seconds;
|
|
8086
8225
|
}
|
|
8087
|
-
|
|
8088
|
-
const
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
|
|
8093
|
-
|
|
8094
|
-
|
|
8095
|
-
|
|
8096
|
-
|
|
8097
|
-
|
|
8098
|
-
|
|
8099
|
-
|
|
8100
|
-
|
|
8226
|
+
buildTelemetryClient(sdkOptions, clientOptions) {
|
|
8227
|
+
const plan = this.connectionPlan;
|
|
8228
|
+
switch (plan.kind) {
|
|
8229
|
+
case "stay-offline": return discardingTelemetryClient;
|
|
8230
|
+
case "connect": {
|
|
8231
|
+
const queueLimit = clientOptions?.telemetry?.eventQueueLimit ?? DEFAULT_EVENT_QUEUE_LIMIT;
|
|
8232
|
+
return new ServerTelemetryEventCollector({
|
|
8233
|
+
sdkKey: plan.serverSdkKey,
|
|
8234
|
+
sdkIdentity: sdkOptions,
|
|
8235
|
+
metaContext: clientOptions?.metadata ?? {},
|
|
8236
|
+
logger: this.logger,
|
|
8237
|
+
baseUrl: plan.baseUrl,
|
|
8238
|
+
flushIntervalDelay: clientOptions?.telemetry?.flushInterval ?? DEFAULT_FLUSH_INTERVAL,
|
|
8239
|
+
evaluationQueueLimit: Math.ceil(queueLimit * .7),
|
|
8240
|
+
contextLimit: Math.floor(queueLimit * .3),
|
|
8241
|
+
urlFactory: defaultUrlFactory,
|
|
8242
|
+
valueIdGenerator: generateValueId
|
|
8243
|
+
});
|
|
8244
|
+
}
|
|
8245
|
+
}
|
|
8101
8246
|
}
|
|
8102
|
-
buildTransport(
|
|
8103
|
-
|
|
8104
|
-
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8247
|
+
buildTransport(sdkOptions, clientOptions) {
|
|
8248
|
+
const plan = this.connectionPlan;
|
|
8249
|
+
switch (plan.kind) {
|
|
8250
|
+
case "stay-offline": return new OfflineTransport(plan.source);
|
|
8251
|
+
case "connect": return new (this.getTransportConstructor(plan.mode))({
|
|
8252
|
+
serverSdkKey: plan.serverSdkKey,
|
|
8253
|
+
baseUrl: plan.baseUrl,
|
|
8254
|
+
metaContext: {
|
|
8255
|
+
...clientOptions?.metadata,
|
|
8256
|
+
sdkName: sdkOptions.sdkName,
|
|
8257
|
+
sdkVersion: sdkOptions.sdkVersion
|
|
8258
|
+
},
|
|
8259
|
+
logger: this.logger,
|
|
8260
|
+
pollingInterval: this.pollingIntervalFor(plan.mode, clientOptions?.connection?.pollingInterval)
|
|
8261
|
+
});
|
|
8262
|
+
}
|
|
8114
8263
|
}
|
|
8115
8264
|
getTransportConstructor(mode) {
|
|
8116
8265
|
switch (mode) {
|
|
8117
8266
|
case "polling": return PollingTransport;
|
|
8118
|
-
|
|
8267
|
+
case "streaming": return StreamingTransport;
|
|
8119
8268
|
}
|
|
8120
8269
|
}
|
|
8121
8270
|
findKeysRemovedBy(configBundle) {
|
|
@@ -8230,17 +8379,6 @@ var DefaultConfigDirectorClient = class {
|
|
|
8230
8379
|
dispatchEvaluationEvent(event) {
|
|
8231
8380
|
setTimeout(() => this.eventEmitter.emit("configEvaluated", { evaluation: event }), 0);
|
|
8232
8381
|
}
|
|
8233
|
-
parseUrl(url) {
|
|
8234
|
-
if (!url) return;
|
|
8235
|
-
try {
|
|
8236
|
-
return new URL(url);
|
|
8237
|
-
} catch (error) {
|
|
8238
|
-
throw new ConfigDirectorValidationError(`Invalid base URL '${url}'. Parsing failed: ${error}`);
|
|
8239
|
-
}
|
|
8240
|
-
}
|
|
8241
|
-
validateSdkKeyPresence(sdkKey) {
|
|
8242
|
-
if (!sdkKey || sdkKey.trim().length == 0) throw new ConfigDirectorValidationError("No server SDK key was provided, the client cannot be instantiated without a valid server SDK key");
|
|
8243
|
-
}
|
|
8244
8382
|
validateDefaultValue(defaultValue) {
|
|
8245
8383
|
if (defaultValue === void 0 || defaultValue === null) throw new ConfigDirectorValidationError("Invalid default value. The default value for a config must be defined and non-null.");
|
|
8246
8384
|
if (typeof defaultValue === "function") throw new ConfigDirectorValidationError("Invalid default value. The default value for a config cannot be a function.");
|
|
@@ -8304,27 +8442,38 @@ const createDefaultLogger = (level) => {
|
|
|
8304
8442
|
var plugin_default = defineNitroPlugin((nitroApp) => {
|
|
8305
8443
|
const runtimeConfig = useRuntimeConfig();
|
|
8306
8444
|
const logger = createDefaultLogger(runtimeConfig.configdirector?.logLevel);
|
|
8307
|
-
|
|
8445
|
+
const { serverSdkKey, baseUrl, connection } = runtimeConfig.configdirector;
|
|
8446
|
+
const connectionMode = connection?.mode || "streaming";
|
|
8447
|
+
if (connectionMode !== "offline" && !serverSdkKey) {
|
|
8308
8448
|
const message = "The ConfigDirector serverSdkKey must be configured for the plugin to initialize. You can provide it in nuxt.config.ts under 'runtimeConfig.configdirector.serverSdkKey' or as a runtime environment variable named NUXT_CONFIGDIRECTOR_SERVER_SDK_KEY";
|
|
8309
8449
|
logger.error(message);
|
|
8310
8450
|
throw new ConfigDirectorInitializationError(message);
|
|
8311
8451
|
}
|
|
8312
8452
|
logger.debug("Initializing ConfigDirector Nitro plugin");
|
|
8313
|
-
const
|
|
8314
|
-
const client = new DefaultConfigDirectorClient(serverSdkKey, {
|
|
8453
|
+
const client = new DefaultConfigDirectorClient(serverSdkKey || void 0, {
|
|
8315
8454
|
sdkName: "nuxt-sdk",
|
|
8316
|
-
sdkVersion: "1.
|
|
8455
|
+
sdkVersion: "1.11.0"
|
|
8317
8456
|
}, {
|
|
8318
8457
|
logger,
|
|
8319
8458
|
connection: {
|
|
8320
8459
|
url: baseUrl || void 0,
|
|
8321
|
-
mode:
|
|
8460
|
+
mode: connectionMode,
|
|
8461
|
+
file: connection?.file || void 0,
|
|
8462
|
+
values: connection?.values,
|
|
8322
8463
|
pollingInterval: connection?.pollingInterval || void 0,
|
|
8323
8464
|
timeout: connection?.timeout || void 0
|
|
8324
8465
|
}
|
|
8325
8466
|
});
|
|
8467
|
+
const initialization = client.initialize();
|
|
8468
|
+
initialization.catch((error) => {
|
|
8469
|
+
logger.error("The ConfigDirector server client could not initialize, so every request fails:", error);
|
|
8470
|
+
});
|
|
8326
8471
|
nitroApp.configDirectorClient = client;
|
|
8327
|
-
nitroApp.
|
|
8472
|
+
nitroApp.configDirectorConnectionMode = connectionMode;
|
|
8473
|
+
nitroApp.configDirectorInitialization = initialization;
|
|
8474
|
+
nitroApp.hooks.hook("request", (event) => {
|
|
8475
|
+
useRuntimeConfig(event).public.configdirector.serverConnectionMode = connectionMode;
|
|
8476
|
+
});
|
|
8328
8477
|
});
|
|
8329
8478
|
//#endregion
|
|
8330
8479
|
export { plugin_default as default };
|