@configdirector/nuxt-sdk 1.14.2 → 1.15.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 +13 -0
- package/dist/module.json +1 -1
- 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/useConfigDirectorContext.mjs +8 -2
- package/dist/runtime/app/composables/useConfigDirectorValue.d.mts +1 -1
- package/dist/runtime/app/composables/useConfigDirectorValue.d.ts +1 -1
- package/dist/runtime/{native-values-BjAsU5SD.d.mts → native-values-DQVM1FGD.d.mts} +13 -0
- package/dist/runtime/nitro/offline-values.d.mts +1 -1
- package/dist/runtime/nitro/offline-values.d.ts +1 -1
- package/dist/runtime/nitro/plugin.d.mts +2 -2
- package/dist/runtime/nitro/plugin.d.ts +2 -2
- package/dist/runtime/nitro/plugin.mjs +30 -18
- package/dist/runtime/plugin.client.mjs +141 -42
- package/dist/runtime/plugin.server.mjs +11 -3
- package/dist/runtime/server/composables/useConfigDirectorServerClient.d.mts +1 -1
- package/dist/runtime/server/composables/useConfigDirectorServerClient.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-BeMbqkgk.d.mts → types-CXuEYplq.d.mts} +1 -1
- package/dist/runtime/{types-BOsBpju5.d.mts → types-CqVeH32Z.d.mts} +1 -1
- package/dist/testing.d.mts +15 -2
- package/dist/testing.mjs +96 -24
- package/package.json +1 -1
package/dist/module.d.mts
CHANGED
|
@@ -81,6 +81,10 @@ type ConfigDirectorContext = {
|
|
|
81
81
|
* or the site's data is cleared. However, keep in mind that this value is used for segmenting
|
|
82
82
|
* contexts in percentage rollouts, and changes to the {@link id} could result in the context
|
|
83
83
|
* being assigned to a different percentile.
|
|
84
|
+
*
|
|
85
|
+
* An identifier has at most 256 characters. A client SDK ignores a context with a longer one as
|
|
86
|
+
* a whole: it logs an error and evaluates as if no context had been provided. A server SDK still
|
|
87
|
+
* evaluates such a context, and ConfigDirector does not add it to the environment's contexts.
|
|
84
88
|
*/
|
|
85
89
|
id?: string;
|
|
86
90
|
/**
|
|
@@ -98,11 +102,20 @@ type ConfigDirectorContext = {
|
|
|
98
102
|
/**
|
|
99
103
|
* The context's display name. This will be shown in the ConfigDirector dashboard and may be
|
|
100
104
|
* used for targeting rules.
|
|
105
|
+
*
|
|
106
|
+
* A name has at most 256 characters. A client SDK ignores a context with a longer one as a
|
|
107
|
+
* whole: it logs an error and evaluates as if no context had been provided. A server SDK still
|
|
108
|
+
* evaluates such a context, and ConfigDirector does not add it to the environment's contexts.
|
|
101
109
|
*/
|
|
102
110
|
name?: string;
|
|
103
111
|
/**
|
|
104
112
|
* Any arbitrary traits for the context. They will be shown in the ConfigDirector dashboard
|
|
105
113
|
* and may be used for targeting rules.
|
|
114
|
+
*
|
|
115
|
+
* Traits take at most 64 KB once written as JSON. A client SDK ignores a context with larger
|
|
116
|
+
* traits as a whole: it logs an error and evaluates as if no context had been provided. A server
|
|
117
|
+
* SDK still evaluates such a context, and ConfigDirector does not add it to the environment's
|
|
118
|
+
* contexts.
|
|
106
119
|
*/
|
|
107
120
|
traits?: {
|
|
108
121
|
[key: string]: unknown;
|
package/dist/module.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as ClientHooks } from "../../types-
|
|
1
|
+
import { t as ClientHooks } from "../../types-CqVeH32Z.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-CqVeH32Z.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/runtime/app/composables/useConfigDirectorClientHooks.d.ts
|
|
4
4
|
declare const useConfigDirectorClientHooks: (hooks: ClientHooks) => void;
|
|
@@ -41,12 +41,13 @@ const getEffectiveTimeout = (option) => {
|
|
|
41
41
|
const useConfigDirectorContext = () => {
|
|
42
42
|
const state = useState("configdirector-context");
|
|
43
43
|
const { client } = useConfigDirectorClient();
|
|
44
|
-
const { $configDirectorClientStartup } = useNuxtApp();
|
|
44
|
+
const { $configDirectorClientStartup, $configDirectorClientContextUpdate } = useNuxtApp();
|
|
45
45
|
const startup = $configDirectorClientStartup;
|
|
46
|
+
const updateClientContext = $configDirectorClientContextUpdate;
|
|
46
47
|
const handContextToClient = (rawContext) => {
|
|
47
48
|
switch (decideContextUpdateAction(client, rawContext, startup.waitsForFirstContext)) {
|
|
48
49
|
case "startClient": return startup.start(rawContext);
|
|
49
|
-
case "updateContext": return
|
|
50
|
+
case "updateContext": return updateClientContext(rawContext);
|
|
50
51
|
}
|
|
51
52
|
};
|
|
52
53
|
const updateContext = async (context, options) => {
|
|
@@ -57,12 +58,17 @@ const useConfigDirectorContext = () => {
|
|
|
57
58
|
if (oldContext != newContext) {
|
|
58
59
|
const timeout = getEffectiveTimeout(options?.timeoutMilliseconds);
|
|
59
60
|
let timer;
|
|
61
|
+
const showContextHeldByClient = () => {
|
|
62
|
+
state.value = client.context;
|
|
63
|
+
};
|
|
64
|
+
client.on("connectionError", showContextHeldByClient);
|
|
60
65
|
try {
|
|
61
66
|
await Promise.race([handContextToClient(rawContext), new Promise((resolve) => {
|
|
62
67
|
timer = setTimeout(() => resolve(), timeout);
|
|
63
68
|
})]);
|
|
64
69
|
} finally {
|
|
65
70
|
clearTimeout(timer);
|
|
71
|
+
client.off("connectionError", showContextHeldByClient);
|
|
66
72
|
}
|
|
67
73
|
}
|
|
68
74
|
};
|
|
@@ -93,6 +93,10 @@ type ConfigDirectorContext = {
|
|
|
93
93
|
* or the site's data is cleared. However, keep in mind that this value is used for segmenting
|
|
94
94
|
* contexts in percentage rollouts, and changes to the {@link id} could result in the context
|
|
95
95
|
* being assigned to a different percentile.
|
|
96
|
+
*
|
|
97
|
+
* An identifier has at most 256 characters. A client SDK ignores a context with a longer one as
|
|
98
|
+
* a whole: it logs an error and evaluates as if no context had been provided. A server SDK still
|
|
99
|
+
* evaluates such a context, and ConfigDirector does not add it to the environment's contexts.
|
|
96
100
|
*/
|
|
97
101
|
id?: string;
|
|
98
102
|
/**
|
|
@@ -110,11 +114,20 @@ type ConfigDirectorContext = {
|
|
|
110
114
|
/**
|
|
111
115
|
* The context's display name. This will be shown in the ConfigDirector dashboard and may be
|
|
112
116
|
* used for targeting rules.
|
|
117
|
+
*
|
|
118
|
+
* A name has at most 256 characters. A client SDK ignores a context with a longer one as a
|
|
119
|
+
* whole: it logs an error and evaluates as if no context had been provided. A server SDK still
|
|
120
|
+
* evaluates such a context, and ConfigDirector does not add it to the environment's contexts.
|
|
113
121
|
*/
|
|
114
122
|
name?: string;
|
|
115
123
|
/**
|
|
116
124
|
* Any arbitrary traits for the context. They will be shown in the ConfigDirector dashboard
|
|
117
125
|
* and may be used for targeting rules.
|
|
126
|
+
*
|
|
127
|
+
* Traits take at most 64 KB once written as JSON. A client SDK ignores a context with larger
|
|
128
|
+
* traits as a whole: it logs an error and evaluates as if no context had been provided. A server
|
|
129
|
+
* SDK still evaluates such a context, and ConfigDirector does not add it to the environment's
|
|
130
|
+
* contexts.
|
|
118
131
|
*/
|
|
119
132
|
traits?: {
|
|
120
133
|
[key: string]: unknown;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { o as ConnectionMode } from "../native-values-
|
|
2
|
-
import { n as ConfigDirectorClient } from "../types-
|
|
1
|
+
import { o as ConnectionMode } from "../native-values-DQVM1FGD.mjs";
|
|
2
|
+
import { n as ConfigDirectorClient } from "../types-CXuEYplq.mjs";
|
|
3
3
|
import * as _$nitropack from "nitropack";
|
|
4
4
|
|
|
5
5
|
//#region src/runtime/nitro/plugin.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { o as ConnectionMode } from "../native-values-
|
|
2
|
-
import { n as ConfigDirectorClient } from "../types-
|
|
1
|
+
import { o as ConnectionMode } from "../native-values-DQVM1FGD.mjs";
|
|
2
|
+
import { n as ConfigDirectorClient } from "../types-CXuEYplq.mjs";
|
|
3
3
|
import * as _$nitropack from "nitropack";
|
|
4
4
|
|
|
5
5
|
//#region src/runtime/nitro/plugin.d.ts
|
|
@@ -7722,18 +7722,25 @@ const resolvePollingInterval = (configuredSeconds, defaults) => {
|
|
|
7722
7722
|
var InvalidContextSubmissions = class {
|
|
7723
7723
|
countsByKindSample = /* @__PURE__ */ new Map();
|
|
7724
7724
|
countBeyondSampleLimit = 0;
|
|
7725
|
+
countsBySizeLimit = /* @__PURE__ */ new Map();
|
|
7725
7726
|
startTime;
|
|
7726
|
-
|
|
7727
|
+
recordInvalidKind(kindSample) {
|
|
7727
7728
|
this.startTime ??= /* @__PURE__ */ new Date();
|
|
7728
|
-
return this.
|
|
7729
|
+
return this.addInvalidKind(kindSample, 1);
|
|
7730
|
+
}
|
|
7731
|
+
recordOverSizeLimit(reason) {
|
|
7732
|
+
this.startTime ??= /* @__PURE__ */ new Date();
|
|
7733
|
+
this.addOverSizeLimit(reason, 1);
|
|
7729
7734
|
}
|
|
7730
7735
|
absorb(entries) {
|
|
7731
7736
|
for (const entry of entries) {
|
|
7732
7737
|
if (this.startTime === void 0 || entry.startTime < this.startTime) this.startTime = entry.startTime;
|
|
7733
|
-
|
|
7738
|
+
const { event } = entry;
|
|
7739
|
+
if (event.reason === "invalid-context-kind") this.addInvalidKind(event.kindSample, entry.count);
|
|
7740
|
+
else this.addOverSizeLimit(event.reason, entry.count);
|
|
7734
7741
|
}
|
|
7735
7742
|
}
|
|
7736
|
-
|
|
7743
|
+
addInvalidKind(kindSample, count) {
|
|
7737
7744
|
if (kindSample !== void 0) {
|
|
7738
7745
|
const knownCount = this.countsByKindSample.get(kindSample);
|
|
7739
7746
|
if (knownCount !== void 0) {
|
|
@@ -7749,26 +7756,31 @@ var InvalidContextSubmissions = class {
|
|
|
7749
7756
|
this.countBeyondSampleLimit += count;
|
|
7750
7757
|
return firstBeyondSampleLimit ? "first-beyond-sample-limit" : "beyond-sample-limit";
|
|
7751
7758
|
}
|
|
7759
|
+
addOverSizeLimit(reason, count) {
|
|
7760
|
+
this.countsBySizeLimit.set(reason, (this.countsBySizeLimit.get(reason) ?? 0) + count);
|
|
7761
|
+
}
|
|
7752
7762
|
takeSnapshot() {
|
|
7753
7763
|
const endTime = /* @__PURE__ */ new Date();
|
|
7754
7764
|
const startTime = this.startTime ?? endTime;
|
|
7755
|
-
const entryOf = (count,
|
|
7765
|
+
const entryOf = (count, event) => ({
|
|
7756
7766
|
startTime,
|
|
7757
7767
|
endTime,
|
|
7758
7768
|
count,
|
|
7759
|
-
event
|
|
7760
|
-
reason: "invalid-context-kind",
|
|
7761
|
-
kindSample
|
|
7762
|
-
}
|
|
7769
|
+
event
|
|
7763
7770
|
});
|
|
7764
|
-
const sampledEntries = Array.from(this.countsByKindSample, ([kindSample, count]) => entryOf(count,
|
|
7765
|
-
|
|
7771
|
+
const sampledEntries = Array.from(this.countsByKindSample, ([kindSample, count]) => entryOf(count, {
|
|
7772
|
+
reason: "invalid-context-kind",
|
|
7773
|
+
kindSample
|
|
7774
|
+
}));
|
|
7775
|
+
const invalidKindEntries = this.countBeyondSampleLimit > 0 ? [...sampledEntries, entryOf(this.countBeyondSampleLimit, { reason: "invalid-context-kind" })] : sampledEntries;
|
|
7776
|
+
const sizeLimitEntries = Array.from(this.countsBySizeLimit, ([reason, count]) => entryOf(count, { reason }));
|
|
7766
7777
|
this.clear();
|
|
7767
|
-
return
|
|
7778
|
+
return [...invalidKindEntries, ...sizeLimitEntries];
|
|
7768
7779
|
}
|
|
7769
7780
|
clear() {
|
|
7770
7781
|
this.countsByKindSample.clear();
|
|
7771
7782
|
this.countBeyondSampleLimit = 0;
|
|
7783
|
+
this.countsBySizeLimit.clear();
|
|
7772
7784
|
this.startTime = void 0;
|
|
7773
7785
|
}
|
|
7774
7786
|
};
|
|
@@ -8249,8 +8261,8 @@ var ServerTelemetryEventCollector = class extends TelemetryEventCollector {
|
|
|
8249
8261
|
};
|
|
8250
8262
|
this.evaluationEventQueue.push(this.sanitizeEvaluatedConfigEvent(event));
|
|
8251
8263
|
}
|
|
8252
|
-
|
|
8253
|
-
return this.invalidContextSubmissions.
|
|
8264
|
+
recordInvalidContextKind(kindSample) {
|
|
8265
|
+
return this.invalidContextSubmissions.recordInvalidKind(kindSample);
|
|
8254
8266
|
}
|
|
8255
8267
|
sanitizeEvaluatedConfigEvent(event) {
|
|
8256
8268
|
return {
|
|
@@ -8304,7 +8316,7 @@ var ServerTelemetryEventCollector = class extends TelemetryEventCollector {
|
|
|
8304
8316
|
const discardingTelemetryClient = {
|
|
8305
8317
|
start: () => {},
|
|
8306
8318
|
evaluatedConfig: () => {},
|
|
8307
|
-
|
|
8319
|
+
recordInvalidContextKind: () => "new-kind-sample",
|
|
8308
8320
|
trackedEvent: () => {},
|
|
8309
8321
|
close: async () => {}
|
|
8310
8322
|
};
|
|
@@ -8337,7 +8349,7 @@ const liveTimeoutWarningDetails = {
|
|
|
8337
8349
|
streaming: "The client will continue to retry since there were no fatal errors detected. Configs will return the default value until the connection succeeds.",
|
|
8338
8350
|
polling: "Since the client was configured without streaming, configs may not update and always return the default value."
|
|
8339
8351
|
};
|
|
8340
|
-
const
|
|
8352
|
+
const logInvalidContextKind = {
|
|
8341
8353
|
"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 '_'.`),
|
|
8342
8354
|
"known-kind-sample": () => {},
|
|
8343
8355
|
"first-beyond-sample-limit": (logger) => logger.error(`[ConfigDirectorClient] Ignored a context with another invalid kind and evaluated as if no context was supplied. 20 different invalid kinds were logged recently, so further invalid kinds are not logged individually.`),
|
|
@@ -8631,7 +8643,7 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
8631
8643
|
switch (admission.outcome) {
|
|
8632
8644
|
case "admitted": return admission.context;
|
|
8633
8645
|
case "ignored":
|
|
8634
|
-
|
|
8646
|
+
logInvalidContextKind[this.usageEventCollector.recordInvalidContextKind(admission.kindSample)](this.logger, admission.kindSample);
|
|
8635
8647
|
return;
|
|
8636
8648
|
}
|
|
8637
8649
|
}
|
|
@@ -8712,7 +8724,7 @@ var plugin_default = defineNitroPlugin((nitroApp) => {
|
|
|
8712
8724
|
logger.debug("Initializing ConfigDirector Nitro plugin");
|
|
8713
8725
|
const client = new DefaultConfigDirectorClient(serverSdkKey || void 0, {
|
|
8714
8726
|
sdkName: "nuxt-sdk",
|
|
8715
|
-
sdkVersion: "1.
|
|
8727
|
+
sdkVersion: "1.15.0"
|
|
8716
8728
|
}, {
|
|
8717
8729
|
logger,
|
|
8718
8730
|
metadata: {
|
|
@@ -919,7 +919,8 @@ const createDefaultLogger$1 = (level, messageDecorator) => {
|
|
|
919
919
|
const discardingTelemetryClient = {
|
|
920
920
|
updateContext: async () => {},
|
|
921
921
|
evaluatedConfig: () => {},
|
|
922
|
-
|
|
922
|
+
recordInvalidContextKind: () => {},
|
|
923
|
+
recordContextOverSizeLimit: () => {},
|
|
923
924
|
trackedEvent: () => {},
|
|
924
925
|
close: async () => {}
|
|
925
926
|
};
|
|
@@ -1172,12 +1173,12 @@ var PollingTransport = class extends AbstractPollingTransport {
|
|
|
1172
1173
|
this.endCurrentConnection();
|
|
1173
1174
|
const generation = this.connectionGeneration;
|
|
1174
1175
|
const clientSession = await this.options.clientSession;
|
|
1175
|
-
if (
|
|
1176
|
+
if (!this.isCurrentConnection(generation)) return this;
|
|
1176
1177
|
try {
|
|
1177
|
-
await this.fetchConfigs(context, timeout, clientSession);
|
|
1178
|
+
await this.fetchConfigs(context, timeout, clientSession, generation);
|
|
1178
1179
|
} finally {
|
|
1179
|
-
if (
|
|
1180
|
-
this.fetchConfigs(context, timeout, clientSession).catch((error) => {
|
|
1180
|
+
if (this.continuesPolling(generation)) this.schedulePollingInterval(() => {
|
|
1181
|
+
this.fetchConfigs(context, timeout, clientSession, generation).catch((error) => {
|
|
1181
1182
|
this.logger.error("[PollingTransport] Error during polling:", error);
|
|
1182
1183
|
});
|
|
1183
1184
|
});
|
|
@@ -1193,7 +1194,13 @@ var PollingTransport = class extends AbstractPollingTransport {
|
|
|
1193
1194
|
this.clearPollingInterval();
|
|
1194
1195
|
this.lastUpdateTimestamp = void 0;
|
|
1195
1196
|
}
|
|
1196
|
-
|
|
1197
|
+
isCurrentConnection(generation) {
|
|
1198
|
+
return generation === this.connectionGeneration;
|
|
1199
|
+
}
|
|
1200
|
+
continuesPolling(generation) {
|
|
1201
|
+
return !this.fatalError && this.isCurrentConnection(generation);
|
|
1202
|
+
}
|
|
1203
|
+
async fetchConfigs(context, timeout, clientSession, generation) {
|
|
1197
1204
|
if (this.fatalError) {
|
|
1198
1205
|
this.logger.warn("[PollingTransport] There was a prior unrecoverable error. Ignoring attempt to reconnect.");
|
|
1199
1206
|
return;
|
|
@@ -1214,6 +1221,7 @@ var PollingTransport = class extends AbstractPollingTransport {
|
|
|
1214
1221
|
await this.handleNonOkResponse(response);
|
|
1215
1222
|
if (response.status == 200) {
|
|
1216
1223
|
const json = JSON.parse(await response.text());
|
|
1224
|
+
if (!this.isCurrentConnection(generation)) return;
|
|
1217
1225
|
this.lastUpdateTimestamp = json.timestamp;
|
|
1218
1226
|
this.eventEmitter.emit("configSetReceived", json);
|
|
1219
1227
|
}
|
|
@@ -1298,6 +1306,42 @@ const utf8ByteLength = (text) => {
|
|
|
1298
1306
|
return bytes;
|
|
1299
1307
|
};
|
|
1300
1308
|
//#endregion
|
|
1309
|
+
//#region ../js-client-core/src/context-admission.ts
|
|
1310
|
+
const IDENTIFIER_MAXIMUM_CHARACTERS = 256;
|
|
1311
|
+
const NAME_MAXIMUM_CHARACTERS$1 = 256;
|
|
1312
|
+
const TRAITS_MAXIMUM_JSON_BYTES = 65536;
|
|
1313
|
+
const hasMoreCharactersThan = (maximumCharacters, text) => typeof text === "string" && Array.from(text).length > maximumCharacters;
|
|
1314
|
+
const hasMoreJsonBytesThan = (maximumBytes, traits) => {
|
|
1315
|
+
let json;
|
|
1316
|
+
try {
|
|
1317
|
+
json = JSON.stringify(traits);
|
|
1318
|
+
} catch {
|
|
1319
|
+
return false;
|
|
1320
|
+
}
|
|
1321
|
+
return json !== void 0 && utf8ByteLength(json) > maximumBytes;
|
|
1322
|
+
};
|
|
1323
|
+
const firstSizeLimitPassedBy = (context) => {
|
|
1324
|
+
if (hasMoreCharactersThan(IDENTIFIER_MAXIMUM_CHARACTERS, context?.id)) return "identifier-too-long";
|
|
1325
|
+
if (hasMoreCharactersThan(NAME_MAXIMUM_CHARACTERS$1, context?.name)) return "name-too-long";
|
|
1326
|
+
if (hasMoreJsonBytesThan(TRAITS_MAXIMUM_JSON_BYTES, context?.traits)) return "traits-too-large";
|
|
1327
|
+
};
|
|
1328
|
+
const admitClientContext = (context) => {
|
|
1329
|
+
const kindAdmission = admitContext(context);
|
|
1330
|
+
if (kindAdmission.outcome === "ignored") return {
|
|
1331
|
+
outcome: "invalid kind",
|
|
1332
|
+
kindSample: kindAdmission.kindSample
|
|
1333
|
+
};
|
|
1334
|
+
const passedSizeLimit = firstSizeLimitPassedBy(context);
|
|
1335
|
+
if (passedSizeLimit !== void 0) return {
|
|
1336
|
+
outcome: "over a size limit",
|
|
1337
|
+
reason: passedSizeLimit
|
|
1338
|
+
};
|
|
1339
|
+
return {
|
|
1340
|
+
outcome: "admitted",
|
|
1341
|
+
context
|
|
1342
|
+
};
|
|
1343
|
+
};
|
|
1344
|
+
//#endregion
|
|
1301
1345
|
//#region ../shared/src/telemetry/reported-context.ts
|
|
1302
1346
|
const USER_CONTEXT_KIND = "user";
|
|
1303
1347
|
const reportedContextOf = (context) => {
|
|
@@ -1554,6 +1598,26 @@ var CachedValuesStore = class {
|
|
|
1554
1598
|
//#endregion
|
|
1555
1599
|
//#region ../js-client-core/src/DefaultConfigDirectorClient.ts
|
|
1556
1600
|
const MAX_EXPONENTIAL_DELAY = 9;
|
|
1601
|
+
const CONTEXT_SIZE_LIMIT_EXPLANATIONS = {
|
|
1602
|
+
"identifier-too-long": "its id is longer than 256 characters",
|
|
1603
|
+
"name-too-long": "its name is longer than 256 characters",
|
|
1604
|
+
"traits-too-large": "its traits are over 64 KB of JSON"
|
|
1605
|
+
};
|
|
1606
|
+
const createReadyOrClosedSignal = () => {
|
|
1607
|
+
let raise;
|
|
1608
|
+
return {
|
|
1609
|
+
raised: new Promise((resolve) => {
|
|
1610
|
+
raise = resolve;
|
|
1611
|
+
}),
|
|
1612
|
+
raise
|
|
1613
|
+
};
|
|
1614
|
+
};
|
|
1615
|
+
const waitAtMost = async (timeout, awaited) => {
|
|
1616
|
+
let timeoutTimer;
|
|
1617
|
+
await Promise.race([awaited, new Promise((resolve) => {
|
|
1618
|
+
timeoutTimer = setTimeout(() => resolve(), timeout);
|
|
1619
|
+
})]).finally(() => clearTimeout(timeoutTimer));
|
|
1620
|
+
};
|
|
1557
1621
|
var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
1558
1622
|
logger;
|
|
1559
1623
|
telemetryClient;
|
|
@@ -1562,14 +1626,14 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1562
1626
|
transport;
|
|
1563
1627
|
eventEmitter = new Emitter();
|
|
1564
1628
|
timeout;
|
|
1565
|
-
timeoutTimer;
|
|
1566
1629
|
ready = false;
|
|
1567
1630
|
initializing = false;
|
|
1568
1631
|
hasReceivedConfigSet = false;
|
|
1569
|
-
readyPromise;
|
|
1570
1632
|
readyResolve;
|
|
1633
|
+
readyOrClosedSignal = createReadyOrClosedSignal();
|
|
1571
1634
|
currentContext;
|
|
1572
1635
|
submittedContext;
|
|
1636
|
+
latestConnectAttempt = 0;
|
|
1573
1637
|
connectionPlan;
|
|
1574
1638
|
clientSession;
|
|
1575
1639
|
cachedValuesStore;
|
|
@@ -1776,12 +1840,16 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1776
1840
|
await this.connectToTransport(this.admittedContextFor(context, submission), submission);
|
|
1777
1841
|
}
|
|
1778
1842
|
admittedContextFor(suppliedContext, submission) {
|
|
1779
|
-
const admission =
|
|
1843
|
+
const admission = admitClientContext(suppliedContext);
|
|
1780
1844
|
switch (admission.outcome) {
|
|
1781
1845
|
case "admitted": return admission.context;
|
|
1782
|
-
case "
|
|
1846
|
+
case "invalid kind":
|
|
1783
1847
|
this.logger.error(`[ConfigDirectorClient] Ignored the context supplied for ${submission} because its kind '${admission.kindSample}' is invalid; continuing as if no context was supplied. A context kind has 1 to 64 characters, using only lowercase letters, digits, '-' and '_'.`);
|
|
1784
|
-
this.telemetryClient.
|
|
1848
|
+
this.telemetryClient.recordInvalidContextKind(admission.kindSample);
|
|
1849
|
+
return;
|
|
1850
|
+
case "over a size limit":
|
|
1851
|
+
this.logger.error(`[ConfigDirectorClient] Ignored the context supplied for ${submission} because ${CONTEXT_SIZE_LIMIT_EXPLANATIONS[admission.reason]}; continuing as if no context was supplied.`);
|
|
1852
|
+
this.telemetryClient.recordContextOverSizeLimit(admission.reason);
|
|
1785
1853
|
return;
|
|
1786
1854
|
}
|
|
1787
1855
|
}
|
|
@@ -1789,31 +1857,28 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1789
1857
|
return this.currentContext;
|
|
1790
1858
|
}
|
|
1791
1859
|
async connectToTransport(context, caller) {
|
|
1860
|
+
const attempt = ++this.latestConnectAttempt;
|
|
1861
|
+
const readyOrClosed = this.readyOrClosedSignal.raised;
|
|
1792
1862
|
this.submittedContext = context;
|
|
1793
1863
|
if (caller === "initialization") this.startCachedValuesAdoption();
|
|
1794
1864
|
try {
|
|
1795
1865
|
this.ready = false;
|
|
1796
|
-
|
|
1866
|
+
new Promise((resolve) => {
|
|
1797
1867
|
this.readyResolve = resolve;
|
|
1798
1868
|
}).then((cancelled) => {
|
|
1799
1869
|
if (cancelled) return;
|
|
1800
1870
|
this.ready = true;
|
|
1801
1871
|
this.initializing = false;
|
|
1872
|
+
this.signalReadyOrClosed();
|
|
1802
1873
|
this.emit("clientReady", { action: caller });
|
|
1803
1874
|
this.logger.debug("[ConfigDirectorClient] Received initial payload from the server, client is ready");
|
|
1804
1875
|
});
|
|
1805
1876
|
const startTime = (/* @__PURE__ */ new Date()).getTime();
|
|
1806
1877
|
await this.transport.connect(context ?? {}, this.timeout, caller);
|
|
1807
|
-
this.
|
|
1808
|
-
this.telemetryClient.updateContext(context).catch((error) => this.logger.warn("[ConfigDirectorClient] Telemetry could not update the context: ", error));
|
|
1809
|
-
this.emit("contextUpdated", { context });
|
|
1878
|
+
if (attempt === this.latestConnectAttempt) this.adoptContext(context);
|
|
1810
1879
|
const elapsedTime = (/* @__PURE__ */ new Date()).getTime() - startTime;
|
|
1811
1880
|
const remainingTimeout = this.timeout - elapsedTime;
|
|
1812
|
-
|
|
1813
|
-
this.timeoutTimer = void 0;
|
|
1814
|
-
if (remainingTimeout > 0) await Promise.race([this.readyPromise, new Promise((resolve) => {
|
|
1815
|
-
this.timeoutTimer = setTimeout(() => resolve(), remainingTimeout);
|
|
1816
|
-
})]).finally(() => clearTimeout(this.timeoutTimer));
|
|
1881
|
+
if (remainingTimeout > 0) await waitAtMost(remainingTimeout, readyOrClosed);
|
|
1817
1882
|
if (!this.ready) this.logger.warn(`[ConfigDirectorClient] Timed out waiting for ${caller} after ${this.timeout}ms. ${this.timeoutWarningDetails()}`);
|
|
1818
1883
|
} catch (error) {
|
|
1819
1884
|
if (error instanceof ConfigDirectorInitializationError) {
|
|
@@ -1823,6 +1888,15 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1823
1888
|
this.logger.error(`[ConfigDirectorClient] An error occurred during ${caller}: `, error);
|
|
1824
1889
|
}
|
|
1825
1890
|
}
|
|
1891
|
+
adoptContext(context) {
|
|
1892
|
+
this.currentContext = context;
|
|
1893
|
+
this.telemetryClient.updateContext(context).catch((error) => this.logger.warn("[ConfigDirectorClient] Telemetry could not update the context: ", error));
|
|
1894
|
+
this.emit("contextUpdated", { context });
|
|
1895
|
+
}
|
|
1896
|
+
signalReadyOrClosed() {
|
|
1897
|
+
this.readyOrClosedSignal.raise();
|
|
1898
|
+
this.readyOrClosedSignal = createReadyOrClosedSignal();
|
|
1899
|
+
}
|
|
1826
1900
|
timeoutWarningDetails() {
|
|
1827
1901
|
switch (this.connectionPlan.kind) {
|
|
1828
1902
|
case "connect": return "The client will continue to retry since there were no fatal errors detected. Configs will return the default value until the connection succeeds.";
|
|
@@ -1975,8 +2049,6 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1975
2049
|
case "stay-offline": return;
|
|
1976
2050
|
case "connect":
|
|
1977
2051
|
this.logger.debug("[ConfigDirectorClient] pauseNetwork() called, pausing transport connection");
|
|
1978
|
-
clearTimeout(this.timeoutTimer);
|
|
1979
|
-
this.timeoutTimer = void 0;
|
|
1980
2052
|
this.transport.close();
|
|
1981
2053
|
this.ready = false;
|
|
1982
2054
|
return;
|
|
@@ -1992,12 +2064,12 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1992
2064
|
}
|
|
1993
2065
|
async close() {
|
|
1994
2066
|
this.logger.debug("[ConfigDirectorClient] close() has been called, closing connection to server");
|
|
1995
|
-
clearTimeout(this.timeoutTimer);
|
|
1996
2067
|
this.readyResolve?.(true);
|
|
1997
2068
|
this.telemetryClient.close().catch((error) => this.logger.warn("[ConfigDirectorClient] Telemetry could not close: ", error));
|
|
1998
2069
|
this.transport.close();
|
|
1999
2070
|
this.ready = false;
|
|
2000
2071
|
this.initializing = false;
|
|
2072
|
+
this.signalReadyOrClosed();
|
|
2001
2073
|
}
|
|
2002
2074
|
dispose() {
|
|
2003
2075
|
this.clear();
|
|
@@ -2067,18 +2139,25 @@ var TrackedEventQueue = class {
|
|
|
2067
2139
|
var InvalidContextSubmissions = class {
|
|
2068
2140
|
countsByKindSample = /* @__PURE__ */ new Map();
|
|
2069
2141
|
countBeyondSampleLimit = 0;
|
|
2142
|
+
countsBySizeLimit = /* @__PURE__ */ new Map();
|
|
2070
2143
|
startTime;
|
|
2071
|
-
|
|
2144
|
+
recordInvalidKind(kindSample) {
|
|
2072
2145
|
this.startTime ??= /* @__PURE__ */ new Date();
|
|
2073
|
-
return this.
|
|
2146
|
+
return this.addInvalidKind(kindSample, 1);
|
|
2147
|
+
}
|
|
2148
|
+
recordOverSizeLimit(reason) {
|
|
2149
|
+
this.startTime ??= /* @__PURE__ */ new Date();
|
|
2150
|
+
this.addOverSizeLimit(reason, 1);
|
|
2074
2151
|
}
|
|
2075
2152
|
absorb(entries) {
|
|
2076
2153
|
for (const entry of entries) {
|
|
2077
2154
|
if (this.startTime === void 0 || entry.startTime < this.startTime) this.startTime = entry.startTime;
|
|
2078
|
-
|
|
2155
|
+
const { event } = entry;
|
|
2156
|
+
if (event.reason === "invalid-context-kind") this.addInvalidKind(event.kindSample, entry.count);
|
|
2157
|
+
else this.addOverSizeLimit(event.reason, entry.count);
|
|
2079
2158
|
}
|
|
2080
2159
|
}
|
|
2081
|
-
|
|
2160
|
+
addInvalidKind(kindSample, count) {
|
|
2082
2161
|
if (kindSample !== void 0) {
|
|
2083
2162
|
const knownCount = this.countsByKindSample.get(kindSample);
|
|
2084
2163
|
if (knownCount !== void 0) {
|
|
@@ -2094,26 +2173,31 @@ var InvalidContextSubmissions = class {
|
|
|
2094
2173
|
this.countBeyondSampleLimit += count;
|
|
2095
2174
|
return firstBeyondSampleLimit ? "first-beyond-sample-limit" : "beyond-sample-limit";
|
|
2096
2175
|
}
|
|
2176
|
+
addOverSizeLimit(reason, count) {
|
|
2177
|
+
this.countsBySizeLimit.set(reason, (this.countsBySizeLimit.get(reason) ?? 0) + count);
|
|
2178
|
+
}
|
|
2097
2179
|
takeSnapshot() {
|
|
2098
2180
|
const endTime = /* @__PURE__ */ new Date();
|
|
2099
2181
|
const startTime = this.startTime ?? endTime;
|
|
2100
|
-
const entryOf = (count,
|
|
2182
|
+
const entryOf = (count, event) => ({
|
|
2101
2183
|
startTime,
|
|
2102
2184
|
endTime,
|
|
2103
2185
|
count,
|
|
2104
|
-
event
|
|
2105
|
-
reason: "invalid-context-kind",
|
|
2106
|
-
kindSample
|
|
2107
|
-
}
|
|
2186
|
+
event
|
|
2108
2187
|
});
|
|
2109
|
-
const sampledEntries = Array.from(this.countsByKindSample, ([kindSample, count]) => entryOf(count,
|
|
2110
|
-
|
|
2188
|
+
const sampledEntries = Array.from(this.countsByKindSample, ([kindSample, count]) => entryOf(count, {
|
|
2189
|
+
reason: "invalid-context-kind",
|
|
2190
|
+
kindSample
|
|
2191
|
+
}));
|
|
2192
|
+
const invalidKindEntries = this.countBeyondSampleLimit > 0 ? [...sampledEntries, entryOf(this.countBeyondSampleLimit, { reason: "invalid-context-kind" })] : sampledEntries;
|
|
2193
|
+
const sizeLimitEntries = Array.from(this.countsBySizeLimit, ([reason, count]) => entryOf(count, { reason }));
|
|
2111
2194
|
this.clear();
|
|
2112
|
-
return
|
|
2195
|
+
return [...invalidKindEntries, ...sizeLimitEntries];
|
|
2113
2196
|
}
|
|
2114
2197
|
clear() {
|
|
2115
2198
|
this.countsByKindSample.clear();
|
|
2116
2199
|
this.countBeyondSampleLimit = 0;
|
|
2200
|
+
this.countsBySizeLimit.clear();
|
|
2117
2201
|
this.startTime = void 0;
|
|
2118
2202
|
}
|
|
2119
2203
|
};
|
|
@@ -2162,7 +2246,7 @@ var WebWorkerTelemetryClient = class {
|
|
|
2162
2246
|
return;
|
|
2163
2247
|
}
|
|
2164
2248
|
try {
|
|
2165
|
-
return new Worker(URL.createObjectURL(new Blob(["(function(){let e=async(e,t)=>e.valueId?{valueId:e.valueId}:e.value?e.value.length<=500&&e.type!=`json`?{value:e.value}:{valueId:await t(e.value)}:e,t=e=>{let t=Object.keys(e);if(t.length==0)return!0;for(let n of t)if((e[n]?.length??0)>0)return!1;return!0},n=e=>{if(!e)return!0;let t=Object.keys(e);if(t.length==0)return!0;for(let n of t)if((e[n]??0)>0)return!1;return!0},r=async(e,t,n,r)=>{let i=new AbortController,a=setTimeout(()=>{r.debug(`[fetchWithTimeout] Reached timeout, aborting request`),i.abort()},e);try{let e=await fetch(typeof t==`string`||t instanceof Request?t:t.toString(),{...n,signal:i.signal});return clearTimeout(a),e}catch(e){throw r.warn(`[fetchWithTimeout] Fetch error: `,e),clearTimeout(a),e}},i=e=>e?.name===`NotAllowedError`?!0:e instanceof TypeError,a=e=>e>=55296&&e<=56319,o=e=>e>=56320&&e<=57343,s=e=>{let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r<=127?t+=1:r<=2047?t+=2:a(r)&&n+1<e.length&&o(e.charCodeAt(n+1))?(t+=4,n++):t+=3}return t};var c=class{constructor(e){this.executeRequests=!0,this.sdkKey=e.sdkKey,this.logger=e.logger,this.sdkIdentity=e.sdkIdentity,this.metaContext=e.metaContext,this.url=e.urlFactory(`client/telemetry/v1`,e.baseUrl),this.clientSession=e.clientSession}async report({context:e,discreteEvents:t,aggregatedEvents:n,droppedEvents:r}){if(!this.executeRequests)return{success:!1,fatalError:!0};let{instanceId:i}=await this.clientSession,a={clientSdkKey:this.sdkKey,instanceId:i,metaContext:{sdkName:this.sdkIdentity.sdkName,sdkVersion:this.sdkIdentity.sdkVersion,appName:this.metaContext.appName,appVersion:this.metaContext.appVersion},context:e,discreteEvents:t,aggregatedEvents:n,droppedEvents:r};if(this.isReportEmpty(a))return{success:!0,fatalError:!1};let o=await this.sendReport(a);return o.fatalError&&(this.executeRequests=!1),o}isReportEmpty(e){return t(e.discreteEvents)&&t(e.aggregatedEvents)&&n(e.droppedEvents)}async sendReport(e){try{let t=JSON.stringify(e),n=await r(5e3,this.url,{method:`POST`,body:t,keepalive:s(t)<=32768},this.logger),i=this.isStatusFatal(n.status);return i?this.logger.warn(`[EventReporter] Received a fatal status response (${n.status}) from the telemetry endpoint. No more telemetry data will be sent.`):n.status===413&&this.logger.warn(`[EventReporter] The telemetry endpoint responded with status ${n.status}. The events in this report were discarded.`),{success:n.ok,fatalError:i}}catch(e){let t=i(e);return this.logger.warn(`[EventReporter] Error attempting to send telemetry data: ${e}`,{error:e}),{success:!1,fatalError:t}}}isStatusFatal(e){return!!e&&e>=400&&e<500&&e!=429&&e!=413}},l=class{aggregate(e){if(e.events.length==0)return[];let t=new Map;for(let n of e.events){let e=JSON.stringify(n),r=t.get(e)?.count||0;t.set(e,{event:n,count:r+1})}return Array.from(t).map(([,t])=>({startTime:e.startTime,endTime:e.endTime,count:t.count,event:t.event}))}},u=class{constructor(e){this._events=[],this._droppedEventCount=0,this.limit=e??1e3}get events(){return this._events}get reachedLimit(){return this._events.length>=this.limit}get droppedEventCount(){return this._droppedEventCount}push(...e){this.startTime||=new Date;let t=Math.max(0,e.length-this.limit),n=e.slice(t,e.length);if(this._droppedEventCount+=t,this._events.length+n.length>this.limit){let e=this._events.length+n.length-this.limit;this._events.splice(0,e),this._droppedEventCount+=e}return this._events.push(...n)}takeSnapshot(){let e=new Date,t=this.startTime??e,n=this._events.splice(0),r=this._droppedEventCount;return this.startTime=void 0,this._droppedEventCount=0,{startTime:t,endTime:e,events:n,droppedCount:r}}clear(){this._events=[],this.startTime=void 0,this._droppedEventCount=0}};let d={\"name-outside-the-character-limit\":`[ConfigDirectorClient] A tracked event was not reported because its name does not have 1 to 150 characters.`,\"value-not-a-finite-number\":`[ConfigDirectorClient] A tracked event was reported without its value because the value is not a finite number.`,\"details-not-reportable\":`[ConfigDirectorClient] A tracked event was reported without its details because they are not an object, have more than 20 top-level keys, are larger than 1024 bytes as JSON, or cannot be written as JSON.`,\"batch-already-full\":`[ConfigDirectorClient] A tracked event was not reported because 1000 tracked events are already waiting for the next telemetry batch.`},f=(e,t)=>{for(let n of t)e.warn(`${d[n]} Further tracked events like it are not logged until the next telemetry batch is sent.`)};var p=class{constructor(){this.entries=[],this.warningsRaisedThisBatch=new Set}add(e){return this.warningsOfKeeping(e).filter(e=>this.isFirstThisBatch(e))}absorb(e){this.entries.push(...e)}takeBatch(){let e=this.entries;return this.clear(),e}clear(){this.entries=[],this.warningsRaisedThisBatch.clear()}warningsOfKeeping(e){switch(e.outcome){case`dropped`:return e.warnings;case`admitted`:return this.entries.length>=1e3?[`batch-already-full`]:(this.entries.push(e.entry),e.warnings)}}isFirstThisBatch(e){return this.warningsRaisedThisBatch.has(e)?!1:(this.warningsRaisedThisBatch.add(e),!0)}},m=class{constructor(e){this.aggregator=new l,this.trackedEventQueue=new p,this.collectEvents=!0,this.started=!1,this.logger=e.logger,this.evaluationEventQueue=new u(e.evaluationQueueLimit??1e3),this.flushIntervalDelay=e.flushIntervalDelay??3e4,this.initialFlushIntervalDelay=e.initialFlushIntervalDelay??5e3}start(){this.started||!this.collectEvents||(this.started=!0,this.flushTimeout=setTimeout(()=>this.flushAndScheduleNext(),this.initialFlushIntervalDelay))}trackedEvent(e){this.collectEvents&&f(this.logger,this.trackedEventQueue.add(e))}async flushAndScheduleNext(){if(!this.collectEvents)return;let e;try{e=await this.flush()}catch(t){this.logger.warn(`[TelemetryEventCollector] Error flushing telemetry events: `,t),e={success:!1,fatalError:!1}}e.fatalError?(this.collectEvents=!1,this.close(),this.logger.warn(`[TelemetryEventCollector] Received a fatal error from telemetry collection. No longer collecting events.`)):this.collectEvents&&(this.cancelScheduledFlush(),this.flushTimeout=setTimeout(()=>this.flushAndScheduleNext(),this.flushIntervalDelay))}cancelScheduledFlush(){clearTimeout(this.flushTimeout)}async close(){this.collectEvents=!1,clearTimeout(this.flushTimeout);try{await this.flush()}catch(e){this.logger.warn(`[TelemetryEventCollector] Error flushing telemetry events during close: `,e)}this.evaluationEventQueue.clear(),this.trackedEventQueue.clear()}dispose(){this.close()}},h=class{constructor(e){this.valueIdGenerator=e,this.valueIdGenerator=e}async process(t){let n=await Promise.all(t.events.map(async t=>({...t,defaultValue:await e(t.defaultValue,this.valueIdGenerator),evaluatedValue:await e(t.evaluatedValue,this.valueIdGenerator)})));return{...t,events:n}}},g=class{constructor(){this.countsByKindSample=new Map,this.countBeyondSampleLimit=0}record(e){return this.startTime??=new Date,this.add(e,1)}absorb(e){for(let t of e)(this.startTime===void 0||t.startTime<this.startTime)&&(this.startTime=t.startTime),this.add(t.event.kindSample,t.count)}add(e,t){if(e!==void 0){let n=this.countsByKindSample.get(e);if(n!==void 0)return this.countsByKindSample.set(e,n+t),`known-kind-sample`;if(this.countsByKindSample.size<20)return this.countsByKindSample.set(e,t),`new-kind-sample`}let n=this.countBeyondSampleLimit===0;return this.countBeyondSampleLimit+=t,n?`first-beyond-sample-limit`:`beyond-sample-limit`}takeSnapshot(){let e=new Date,t=this.startTime??e,n=(n,r)=>({startTime:t,endTime:e,count:n,event:{reason:`invalid-context-kind`,kindSample:r}}),r=Array.from(this.countsByKindSample,([e,t])=>n(t,e)),i=this.countBeyondSampleLimit>0?[...r,n(this.countBeyondSampleLimit)]:r;return this.clear(),i}clear(){this.countsByKindSample.clear(),this.countBeyondSampleLimit=0,this.startTime=void 0}},_=class extends m{constructor(e){super(e),this.invalidContextSubmissions=new g,this.reporter=new c(e),this.evaluationEventSnapshotPreprocessor=new h(e.valueIdGenerator)}async updateContext(e){this.cancelScheduledFlush(),await this.flush(),this._context=e,await this.flushAndScheduleNext()}evaluatedConfig(e){this.collectEvents&&this.evaluationEventQueue.push(e)}recordInvalidContext(e){this.invalidContextSubmissions.record(e)}absorbInvalidContextSubmissions(e){this.invalidContextSubmissions.absorb(e)}absorbTrackedEventEntries(e){this.trackedEventQueue.absorb(e)}async forceFlush(){this.cancelScheduledFlush(),await this.flushAndScheduleNext()}async flush(){if(!this.reporter)return{success:!1,fatalError:!1};let e=await this.evaluationEventSnapshotPreprocessor.process(this.evaluationEventQueue.takeSnapshot());return await this.reporter?.report({context:this._context,discreteEvents:{trackedEvents:this.trackedEventQueue.takeBatch()},aggregatedEvents:{evaluatedConfig:this.aggregator.aggregate(e),invalidContext:this.invalidContextSubmissions.takeSnapshot()},droppedEvents:{evaluatedConfig:e.droppedCount}})}};let v=(e,t)=>new URL(e,t?.toString()),y=(e,t)=>{let n=BigInt(0),r=BigInt(62),i=Array.from(e).map(e=>e.toString(16).padStart(2,`0`)).join(``),a=BigInt(`0x`+i),o=``;for(;a>n;)o=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`[Number(a%r)]+o,a/=r;return o.padStart(t,`0`)},b=Math.ceil(128/Math.log2(62)),x=new TextEncoder,S=async e=>{if(typeof crypto>`u`||crypto.subtle==null)return;let t=await crypto.subtle.digest(`SHA-256`,x.encode(e?.toString()??``));return y(new Uint8Array(t,0,16),b)},C,w,T=new Promise(e=>{w=e}),E=(e,t,...n)=>({type:`Log`,payload:{level:e,message:t,args:n}}),D=e=>{try{self.postMessage(e)}catch{self.postMessage(E(e.payload.level,e.payload.message))}},O={debug:function(e,...t){D(E(`debug`,e,t))},info:function(e,...t){D(E(`info`,e,t))},warn:function(e,...t){D(E(`warn`,e,t))},error:function(e,...t){D(E(`error`,e,t))}};addEventListener(`message`,e=>{let t=e.data;if(t.type!=`Initialize`&&!C){O.info(`[TelemetryWorker] Ignoring ${t.type} because no collector is configured`);return}switch(O.debug(`[TelemetryWorker] Received '${t.type}' event:`,t),t.type){case`Initialize`:if(C){O.warn(`[TelemetryWorker] Received a duplicate Initialize event, ignoring it`);break}C=new _({...t.payload,baseUrl:v(t.payload.baseUrl),urlFactory:v,valueIdGenerator:S,logger:O,clientSession:T}),C.start();break;case`ClientSession`:w(t.payload);break;case`EvaluatedConfigEvent`:C?.evaluatedConfig(t.payload);break;case`InvalidContextSubmissions`:C?.absorbInvalidContextSubmissions(t.payload.entries);break;case`TrackedEvent`:C?.trackedEvent(t.payload);break;case`TrackedEventEntries`:C?.absorbTrackedEventEntries(t.payload.entries);break;case`UpdateContext`:C?.updateContext(t.payload.context);break;case`Flush`:C?.forceFlush();break;case`Close`:(C?.close()??Promise.resolve()).then(()=>{self.postMessage({type:`Closed`}),self.close()});break}})})();"], { type: "application/javascript" })));
|
|
2249
|
+
return new Worker(URL.createObjectURL(new Blob(["(function(){let e=async(e,t)=>e.valueId?{valueId:e.valueId}:e.value?e.value.length<=500&&e.type!=`json`?{value:e.value}:{valueId:await t(e.value)}:e,t=e=>{let t=Object.keys(e);if(t.length==0)return!0;for(let n of t)if((e[n]?.length??0)>0)return!1;return!0},n=e=>{if(!e)return!0;let t=Object.keys(e);if(t.length==0)return!0;for(let n of t)if((e[n]??0)>0)return!1;return!0},r=async(e,t,n,r)=>{let i=new AbortController,a=setTimeout(()=>{r.debug(`[fetchWithTimeout] Reached timeout, aborting request`),i.abort()},e);try{let e=await fetch(typeof t==`string`||t instanceof Request?t:t.toString(),{...n,signal:i.signal});return clearTimeout(a),e}catch(e){throw r.warn(`[fetchWithTimeout] Fetch error: `,e),clearTimeout(a),e}},i=e=>e?.name===`NotAllowedError`?!0:e instanceof TypeError,a=e=>e>=55296&&e<=56319,o=e=>e>=56320&&e<=57343,s=e=>{let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r<=127?t+=1:r<=2047?t+=2:a(r)&&n+1<e.length&&o(e.charCodeAt(n+1))?(t+=4,n++):t+=3}return t};var c=class{constructor(e){this.executeRequests=!0,this.sdkKey=e.sdkKey,this.logger=e.logger,this.sdkIdentity=e.sdkIdentity,this.metaContext=e.metaContext,this.url=e.urlFactory(`client/telemetry/v1`,e.baseUrl),this.clientSession=e.clientSession}async report({context:e,discreteEvents:t,aggregatedEvents:n,droppedEvents:r}){if(!this.executeRequests)return{success:!1,fatalError:!0};let{instanceId:i}=await this.clientSession,a={clientSdkKey:this.sdkKey,instanceId:i,metaContext:{sdkName:this.sdkIdentity.sdkName,sdkVersion:this.sdkIdentity.sdkVersion,appName:this.metaContext.appName,appVersion:this.metaContext.appVersion},context:e,discreteEvents:t,aggregatedEvents:n,droppedEvents:r};if(this.isReportEmpty(a))return{success:!0,fatalError:!1};let o=await this.sendReport(a);return o.fatalError&&(this.executeRequests=!1),o}isReportEmpty(e){return t(e.discreteEvents)&&t(e.aggregatedEvents)&&n(e.droppedEvents)}async sendReport(e){try{let t=JSON.stringify(e),n=await r(5e3,this.url,{method:`POST`,body:t,keepalive:s(t)<=32768},this.logger),i=this.isStatusFatal(n.status);return i?this.logger.warn(`[EventReporter] Received a fatal status response (${n.status}) from the telemetry endpoint. No more telemetry data will be sent.`):n.status===413&&this.logger.warn(`[EventReporter] The telemetry endpoint responded with status ${n.status}. The events in this report were discarded.`),{success:n.ok,fatalError:i}}catch(e){let t=i(e);return this.logger.warn(`[EventReporter] Error attempting to send telemetry data: ${e}`,{error:e}),{success:!1,fatalError:t}}}isStatusFatal(e){return!!e&&e>=400&&e<500&&e!=429&&e!=413}},l=class{aggregate(e){if(e.events.length==0)return[];let t=new Map;for(let n of e.events){let e=JSON.stringify(n),r=t.get(e)?.count||0;t.set(e,{event:n,count:r+1})}return Array.from(t).map(([,t])=>({startTime:e.startTime,endTime:e.endTime,count:t.count,event:t.event}))}},u=class{constructor(e){this._events=[],this._droppedEventCount=0,this.limit=e??1e3}get events(){return this._events}get reachedLimit(){return this._events.length>=this.limit}get droppedEventCount(){return this._droppedEventCount}push(...e){this.startTime||=new Date;let t=Math.max(0,e.length-this.limit),n=e.slice(t,e.length);if(this._droppedEventCount+=t,this._events.length+n.length>this.limit){let e=this._events.length+n.length-this.limit;this._events.splice(0,e),this._droppedEventCount+=e}return this._events.push(...n)}takeSnapshot(){let e=new Date,t=this.startTime??e,n=this._events.splice(0),r=this._droppedEventCount;return this.startTime=void 0,this._droppedEventCount=0,{startTime:t,endTime:e,events:n,droppedCount:r}}clear(){this._events=[],this.startTime=void 0,this._droppedEventCount=0}};let d={\"name-outside-the-character-limit\":`[ConfigDirectorClient] A tracked event was not reported because its name does not have 1 to 150 characters.`,\"value-not-a-finite-number\":`[ConfigDirectorClient] A tracked event was reported without its value because the value is not a finite number.`,\"details-not-reportable\":`[ConfigDirectorClient] A tracked event was reported without its details because they are not an object, have more than 20 top-level keys, are larger than 1024 bytes as JSON, or cannot be written as JSON.`,\"batch-already-full\":`[ConfigDirectorClient] A tracked event was not reported because 1000 tracked events are already waiting for the next telemetry batch.`},f=(e,t)=>{for(let n of t)e.warn(`${d[n]} Further tracked events like it are not logged until the next telemetry batch is sent.`)};var p=class{constructor(){this.entries=[],this.warningsRaisedThisBatch=new Set}add(e){return this.warningsOfKeeping(e).filter(e=>this.isFirstThisBatch(e))}absorb(e){this.entries.push(...e)}takeBatch(){let e=this.entries;return this.clear(),e}clear(){this.entries=[],this.warningsRaisedThisBatch.clear()}warningsOfKeeping(e){switch(e.outcome){case`dropped`:return e.warnings;case`admitted`:return this.entries.length>=1e3?[`batch-already-full`]:(this.entries.push(e.entry),e.warnings)}}isFirstThisBatch(e){return this.warningsRaisedThisBatch.has(e)?!1:(this.warningsRaisedThisBatch.add(e),!0)}},m=class{constructor(e){this.aggregator=new l,this.trackedEventQueue=new p,this.collectEvents=!0,this.started=!1,this.logger=e.logger,this.evaluationEventQueue=new u(e.evaluationQueueLimit??1e3),this.flushIntervalDelay=e.flushIntervalDelay??3e4,this.initialFlushIntervalDelay=e.initialFlushIntervalDelay??5e3}start(){this.started||!this.collectEvents||(this.started=!0,this.flushTimeout=setTimeout(()=>this.flushAndScheduleNext(),this.initialFlushIntervalDelay))}trackedEvent(e){this.collectEvents&&f(this.logger,this.trackedEventQueue.add(e))}async flushAndScheduleNext(){if(!this.collectEvents)return;let e;try{e=await this.flush()}catch(t){this.logger.warn(`[TelemetryEventCollector] Error flushing telemetry events: `,t),e={success:!1,fatalError:!1}}e.fatalError?(this.collectEvents=!1,this.close(),this.logger.warn(`[TelemetryEventCollector] Received a fatal error from telemetry collection. No longer collecting events.`)):this.collectEvents&&(this.cancelScheduledFlush(),this.flushTimeout=setTimeout(()=>this.flushAndScheduleNext(),this.flushIntervalDelay))}cancelScheduledFlush(){clearTimeout(this.flushTimeout)}async close(){this.collectEvents=!1,clearTimeout(this.flushTimeout);try{await this.flush()}catch(e){this.logger.warn(`[TelemetryEventCollector] Error flushing telemetry events during close: `,e)}this.evaluationEventQueue.clear(),this.trackedEventQueue.clear()}dispose(){this.close()}},h=class{constructor(e){this.valueIdGenerator=e,this.valueIdGenerator=e}async process(t){let n=await Promise.all(t.events.map(async t=>({...t,defaultValue:await e(t.defaultValue,this.valueIdGenerator),evaluatedValue:await e(t.evaluatedValue,this.valueIdGenerator)})));return{...t,events:n}}},g=class{constructor(){this.countsByKindSample=new Map,this.countBeyondSampleLimit=0,this.countsBySizeLimit=new Map}recordInvalidKind(e){return this.startTime??=new Date,this.addInvalidKind(e,1)}recordOverSizeLimit(e){this.startTime??=new Date,this.addOverSizeLimit(e,1)}absorb(e){for(let t of e){(this.startTime===void 0||t.startTime<this.startTime)&&(this.startTime=t.startTime);let{event:e}=t;e.reason===`invalid-context-kind`?this.addInvalidKind(e.kindSample,t.count):this.addOverSizeLimit(e.reason,t.count)}}addInvalidKind(e,t){if(e!==void 0){let n=this.countsByKindSample.get(e);if(n!==void 0)return this.countsByKindSample.set(e,n+t),`known-kind-sample`;if(this.countsByKindSample.size<20)return this.countsByKindSample.set(e,t),`new-kind-sample`}let n=this.countBeyondSampleLimit===0;return this.countBeyondSampleLimit+=t,n?`first-beyond-sample-limit`:`beyond-sample-limit`}addOverSizeLimit(e,t){this.countsBySizeLimit.set(e,(this.countsBySizeLimit.get(e)??0)+t)}takeSnapshot(){let e=new Date,t=this.startTime??e,n=(n,r)=>({startTime:t,endTime:e,count:n,event:r}),r=Array.from(this.countsByKindSample,([e,t])=>n(t,{reason:`invalid-context-kind`,kindSample:e})),i=this.countBeyondSampleLimit>0?[...r,n(this.countBeyondSampleLimit,{reason:`invalid-context-kind`})]:r,a=Array.from(this.countsBySizeLimit,([e,t])=>n(t,{reason:e}));return this.clear(),[...i,...a]}clear(){this.countsByKindSample.clear(),this.countBeyondSampleLimit=0,this.countsBySizeLimit.clear(),this.startTime=void 0}},_=class extends m{constructor(e){super(e),this.invalidContextSubmissions=new g,this.reporter=new c(e),this.evaluationEventSnapshotPreprocessor=new h(e.valueIdGenerator)}async updateContext(e){this.cancelScheduledFlush(),await this.flush(),this._context=e,await this.flushAndScheduleNext()}evaluatedConfig(e){this.collectEvents&&this.evaluationEventQueue.push(e)}recordInvalidContextKind(e){this.invalidContextSubmissions.recordInvalidKind(e)}recordContextOverSizeLimit(e){this.invalidContextSubmissions.recordOverSizeLimit(e)}absorbInvalidContextSubmissions(e){this.invalidContextSubmissions.absorb(e)}absorbTrackedEventEntries(e){this.trackedEventQueue.absorb(e)}async forceFlush(){this.cancelScheduledFlush(),await this.flushAndScheduleNext()}async flush(){if(!this.reporter)return{success:!1,fatalError:!1};let e=await this.evaluationEventSnapshotPreprocessor.process(this.evaluationEventQueue.takeSnapshot());return await this.reporter?.report({context:this._context,discreteEvents:{trackedEvents:this.trackedEventQueue.takeBatch()},aggregatedEvents:{evaluatedConfig:this.aggregator.aggregate(e),invalidContext:this.invalidContextSubmissions.takeSnapshot()},droppedEvents:{evaluatedConfig:e.droppedCount}})}};let v=(e,t)=>new URL(e,t?.toString()),y=(e,t)=>{let n=BigInt(0),r=BigInt(62),i=Array.from(e).map(e=>e.toString(16).padStart(2,`0`)).join(``),a=BigInt(`0x`+i),o=``;for(;a>n;)o=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`[Number(a%r)]+o,a/=r;return o.padStart(t,`0`)},b=Math.ceil(128/Math.log2(62)),x=new TextEncoder,S=async e=>{if(typeof crypto>`u`||crypto.subtle==null)return;let t=await crypto.subtle.digest(`SHA-256`,x.encode(e?.toString()??``));return y(new Uint8Array(t,0,16),b)},C,w,T=new Promise(e=>{w=e}),E=(e,t,...n)=>({type:`Log`,payload:{level:e,message:t,args:n}}),D=e=>{try{self.postMessage(e)}catch{self.postMessage(E(e.payload.level,e.payload.message))}},O={debug:function(e,...t){D(E(`debug`,e,t))},info:function(e,...t){D(E(`info`,e,t))},warn:function(e,...t){D(E(`warn`,e,t))},error:function(e,...t){D(E(`error`,e,t))}};addEventListener(`message`,e=>{let t=e.data;if(t.type!=`Initialize`&&!C){O.info(`[TelemetryWorker] Ignoring ${t.type} because no collector is configured`);return}switch(O.debug(`[TelemetryWorker] Received '${t.type}' event:`,t),t.type){case`Initialize`:if(C){O.warn(`[TelemetryWorker] Received a duplicate Initialize event, ignoring it`);break}C=new _({...t.payload,baseUrl:v(t.payload.baseUrl),urlFactory:v,valueIdGenerator:S,logger:O,clientSession:T}),C.start();break;case`ClientSession`:w(t.payload);break;case`EvaluatedConfigEvent`:C?.evaluatedConfig(t.payload);break;case`InvalidContextSubmissions`:C?.absorbInvalidContextSubmissions(t.payload.entries);break;case`TrackedEvent`:C?.trackedEvent(t.payload);break;case`TrackedEventEntries`:C?.absorbTrackedEventEntries(t.payload.entries);break;case`UpdateContext`:C?.updateContext(t.payload.context);break;case`Flush`:C?.forceFlush();break;case`Close`:(C?.close()??Promise.resolve()).then(()=>{self.postMessage({type:`Closed`}),self.close()});break}})})();"], { type: "application/javascript" })));
|
|
2166
2250
|
} catch (error) {
|
|
2167
2251
|
this.turnOff("[WebWorkerTelemetryClient] Telemetry is off because the telemetry Web Worker could not be created: ", error);
|
|
2168
2252
|
return;
|
|
@@ -2244,8 +2328,12 @@ var WebWorkerTelemetryClient = class {
|
|
|
2244
2328
|
if (this.pendingEvaluations.length >= this.pendingEvaluationLimit) this.pendingEvaluations.shift();
|
|
2245
2329
|
this.pendingEvaluations.push(evaluatedConfigMessage);
|
|
2246
2330
|
}
|
|
2247
|
-
|
|
2248
|
-
this.pendingInvalidContextSubmissions.
|
|
2331
|
+
recordInvalidContextKind(kindSample) {
|
|
2332
|
+
this.pendingInvalidContextSubmissions.recordInvalidKind(kindSample);
|
|
2333
|
+
this.forwardInvalidContextSubmissions(this.worker);
|
|
2334
|
+
}
|
|
2335
|
+
recordContextOverSizeLimit(reason) {
|
|
2336
|
+
this.pendingInvalidContextSubmissions.recordOverSizeLimit(reason);
|
|
2249
2337
|
this.forwardInvalidContextSubmissions(this.worker);
|
|
2250
2338
|
}
|
|
2251
2339
|
trackedEvent(admission) {
|
|
@@ -2473,12 +2561,13 @@ const getEffectiveTimeout = (option) => {
|
|
|
2473
2561
|
const useConfigDirectorContext = () => {
|
|
2474
2562
|
const state = useState("configdirector-context");
|
|
2475
2563
|
const { client } = useConfigDirectorClient();
|
|
2476
|
-
const { $configDirectorClientStartup } = useNuxtApp();
|
|
2564
|
+
const { $configDirectorClientStartup, $configDirectorClientContextUpdate } = useNuxtApp();
|
|
2477
2565
|
const startup = $configDirectorClientStartup;
|
|
2566
|
+
const updateClientContext = $configDirectorClientContextUpdate;
|
|
2478
2567
|
const handContextToClient = (rawContext) => {
|
|
2479
2568
|
switch (decideContextUpdateAction(client, rawContext, startup.waitsForFirstContext)) {
|
|
2480
2569
|
case "startClient": return startup.start(rawContext);
|
|
2481
|
-
case "updateContext": return
|
|
2570
|
+
case "updateContext": return updateClientContext(rawContext);
|
|
2482
2571
|
}
|
|
2483
2572
|
};
|
|
2484
2573
|
const updateContext = async (context, options) => {
|
|
@@ -2489,12 +2578,17 @@ const useConfigDirectorContext = () => {
|
|
|
2489
2578
|
if (oldContext != newContext) {
|
|
2490
2579
|
const timeout = getEffectiveTimeout(options?.timeoutMilliseconds);
|
|
2491
2580
|
let timer;
|
|
2581
|
+
const showContextHeldByClient = () => {
|
|
2582
|
+
state.value = client.context;
|
|
2583
|
+
};
|
|
2584
|
+
client.on("connectionError", showContextHeldByClient);
|
|
2492
2585
|
try {
|
|
2493
2586
|
await Promise.race([handContextToClient(rawContext), new Promise((resolve) => {
|
|
2494
2587
|
timer = setTimeout(() => resolve(), timeout);
|
|
2495
2588
|
})]);
|
|
2496
2589
|
} finally {
|
|
2497
2590
|
clearTimeout(timer);
|
|
2591
|
+
client.off("connectionError", showContextHeldByClient);
|
|
2498
2592
|
}
|
|
2499
2593
|
}
|
|
2500
2594
|
};
|
|
@@ -2539,6 +2633,10 @@ var plugin_client_default = defineNuxtPlugin(async (nuxtApp) => {
|
|
|
2539
2633
|
settleReadyStatus();
|
|
2540
2634
|
}
|
|
2541
2635
|
};
|
|
2636
|
+
const updateContext = async (context) => {
|
|
2637
|
+
await client.updateContext(context);
|
|
2638
|
+
settleReadyStatus();
|
|
2639
|
+
};
|
|
2542
2640
|
nuxtApp.hooks.hook("app:created", async () => {
|
|
2543
2641
|
const { context } = useConfigDirectorContext();
|
|
2544
2642
|
const rawContext = toRaw(context.value);
|
|
@@ -2561,7 +2659,8 @@ var plugin_client_default = defineNuxtPlugin(async (nuxtApp) => {
|
|
|
2561
2659
|
return { provide: {
|
|
2562
2660
|
configDirectorClient: client,
|
|
2563
2661
|
configDirectorClientReadyStatus: readonly(readyStatus),
|
|
2564
|
-
configDirectorClientStartup: startup
|
|
2662
|
+
configDirectorClientStartup: startup,
|
|
2663
|
+
configDirectorClientContextUpdate: updateContext
|
|
2565
2664
|
} };
|
|
2566
2665
|
});
|
|
2567
2666
|
const buildClient = async (configdirector, logger) => {
|
|
@@ -2574,7 +2673,7 @@ const buildClient = async (configdirector, logger) => {
|
|
|
2574
2673
|
return {
|
|
2575
2674
|
client: createBrowserClient(configdirector?.clientSdkKey || void 0, {
|
|
2576
2675
|
sdkName: "nuxt-sdk",
|
|
2577
|
-
sdkVersion: "1.
|
|
2676
|
+
sdkVersion: "1.15.0"
|
|
2578
2677
|
}, {
|
|
2579
2678
|
metadata: {
|
|
2580
2679
|
appName: configdirector?.appName,
|
|
@@ -97,12 +97,13 @@ const getEffectiveTimeout = (option) => {
|
|
|
97
97
|
const useConfigDirectorContext = () => {
|
|
98
98
|
const state = useState("configdirector-context");
|
|
99
99
|
const { client } = useConfigDirectorClient();
|
|
100
|
-
const { $configDirectorClientStartup } = useNuxtApp();
|
|
100
|
+
const { $configDirectorClientStartup, $configDirectorClientContextUpdate } = useNuxtApp();
|
|
101
101
|
const startup = $configDirectorClientStartup;
|
|
102
|
+
const updateClientContext = $configDirectorClientContextUpdate;
|
|
102
103
|
const handContextToClient = (rawContext) => {
|
|
103
104
|
switch (decideContextUpdateAction(client, rawContext, startup.waitsForFirstContext)) {
|
|
104
105
|
case "startClient": return startup.start(rawContext);
|
|
105
|
-
case "updateContext": return
|
|
106
|
+
case "updateContext": return updateClientContext(rawContext);
|
|
106
107
|
}
|
|
107
108
|
};
|
|
108
109
|
const updateContext = async (context, options) => {
|
|
@@ -113,12 +114,17 @@ const useConfigDirectorContext = () => {
|
|
|
113
114
|
if (oldContext != newContext) {
|
|
114
115
|
const timeout = getEffectiveTimeout(options?.timeoutMilliseconds);
|
|
115
116
|
let timer;
|
|
117
|
+
const showContextHeldByClient = () => {
|
|
118
|
+
state.value = client.context;
|
|
119
|
+
};
|
|
120
|
+
client.on("connectionError", showContextHeldByClient);
|
|
116
121
|
try {
|
|
117
122
|
await Promise.race([handContextToClient(rawContext), new Promise((resolve) => {
|
|
118
123
|
timer = setTimeout(() => resolve(), timeout);
|
|
119
124
|
})]);
|
|
120
125
|
} finally {
|
|
121
126
|
clearTimeout(timer);
|
|
127
|
+
client.off("connectionError", showContextHeldByClient);
|
|
122
128
|
}
|
|
123
129
|
}
|
|
124
130
|
};
|
|
@@ -141,6 +147,7 @@ var plugin_server_default = defineNuxtPlugin((nuxtApp) => {
|
|
|
141
147
|
waitsForFirstContext: false,
|
|
142
148
|
start: (context) => client.initialize(context)
|
|
143
149
|
};
|
|
150
|
+
const updateContext = (context) => client.updateContext(context);
|
|
144
151
|
nuxtApp.hooks.hook("app:created", async () => {
|
|
145
152
|
logger.debug("Updating ConfigDirector context for SSR evaluation");
|
|
146
153
|
const { context } = useConfigDirectorContext();
|
|
@@ -149,7 +156,8 @@ var plugin_server_default = defineNuxtPlugin((nuxtApp) => {
|
|
|
149
156
|
return { provide: {
|
|
150
157
|
configDirectorClient: client,
|
|
151
158
|
configDirectorClientReadyStatus: readonly(readyStatus),
|
|
152
|
-
configDirectorClientStartup: startup
|
|
159
|
+
configDirectorClientStartup: startup,
|
|
160
|
+
configDirectorClientContextUpdate: updateContext
|
|
153
161
|
} };
|
|
154
162
|
});
|
|
155
163
|
var SsrClient = class {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ConfigDirectorClient } from "../../types-
|
|
1
|
+
import { n as ConfigDirectorClient } from "../../types-CXuEYplq.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/runtime/server/composables/useConfigDirectorServerClient.d.ts
|
|
4
4
|
declare const useConfigDirectorServerClient: () => ConfigDirectorClient;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ConfigDirectorClient } from "../../types-
|
|
1
|
+
import { n as ConfigDirectorClient } from "../../types-CXuEYplq.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/runtime/server/composables/useConfigDirectorServerClient.d.ts
|
|
4
4
|
declare const useConfigDirectorServerClient: () => ConfigDirectorClient;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as ClientHooks } from "../../types-
|
|
1
|
+
import { t as ClientHooks } from "../../types-CXuEYplq.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/runtime/server/composables/useConfigDirectorServerHooks.d.ts
|
|
4
4
|
declare const useConfigDirectorServerHooks: (hooks: ClientHooks) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as ClientHooks } from "../../types-
|
|
1
|
+
import { t as ClientHooks } from "../../types-CXuEYplq.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/runtime/server/composables/useConfigDirectorServerHooks.d.ts
|
|
4
4
|
declare const useConfigDirectorServerHooks: (hooks: ClientHooks) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ConfigValueType, i as ConfigState, n as ConfigDirectorContext, r as ConfigEvaluation, s as TrackOptions } from "./native-values-
|
|
1
|
+
import { a as ConfigValueType, i as ConfigState, n as ConfigDirectorContext, r as ConfigEvaluation, s as TrackOptions } from "./native-values-DQVM1FGD.mjs";
|
|
2
2
|
|
|
3
3
|
//#region ../js-server-sdk/src/types.d.ts
|
|
4
4
|
type ClientEvents = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ConfigValueType, n as ConfigDirectorContext, r as ConfigEvaluation, s as TrackOptions } from "./native-values-
|
|
1
|
+
import { a as ConfigValueType, n as ConfigDirectorContext, r as ConfigEvaluation, s as TrackOptions } from "./native-values-DQVM1FGD.mjs";
|
|
2
2
|
|
|
3
3
|
//#region ../js-client-core/src/Emitter.d.ts
|
|
4
4
|
type EventType = string | symbol;
|
package/dist/testing.d.mts
CHANGED
|
@@ -103,6 +103,10 @@ type ConfigDirectorContext = {
|
|
|
103
103
|
* or the site's data is cleared. However, keep in mind that this value is used for segmenting
|
|
104
104
|
* contexts in percentage rollouts, and changes to the {@link id} could result in the context
|
|
105
105
|
* being assigned to a different percentile.
|
|
106
|
+
*
|
|
107
|
+
* An identifier has at most 256 characters. A client SDK ignores a context with a longer one as
|
|
108
|
+
* a whole: it logs an error and evaluates as if no context had been provided. A server SDK still
|
|
109
|
+
* evaluates such a context, and ConfigDirector does not add it to the environment's contexts.
|
|
106
110
|
*/
|
|
107
111
|
id?: string;
|
|
108
112
|
/**
|
|
@@ -120,11 +124,20 @@ type ConfigDirectorContext = {
|
|
|
120
124
|
/**
|
|
121
125
|
* The context's display name. This will be shown in the ConfigDirector dashboard and may be
|
|
122
126
|
* used for targeting rules.
|
|
127
|
+
*
|
|
128
|
+
* A name has at most 256 characters. A client SDK ignores a context with a longer one as a
|
|
129
|
+
* whole: it logs an error and evaluates as if no context had been provided. A server SDK still
|
|
130
|
+
* evaluates such a context, and ConfigDirector does not add it to the environment's contexts.
|
|
123
131
|
*/
|
|
124
132
|
name?: string;
|
|
125
133
|
/**
|
|
126
134
|
* Any arbitrary traits for the context. They will be shown in the ConfigDirector dashboard
|
|
127
135
|
* and may be used for targeting rules.
|
|
136
|
+
*
|
|
137
|
+
* Traits take at most 64 KB once written as JSON. A client SDK ignores a context with larger
|
|
138
|
+
* traits as a whole: it logs an error and evaluates as if no context had been provided. A server
|
|
139
|
+
* SDK still evaluates such a context, and ConfigDirector does not add it to the environment's
|
|
140
|
+
* contexts.
|
|
128
141
|
*/
|
|
129
142
|
traits?: {
|
|
130
143
|
[key: string]: unknown;
|
|
@@ -397,8 +410,8 @@ interface TestClient {
|
|
|
397
410
|
failContextUpdate(): void;
|
|
398
411
|
/**
|
|
399
412
|
* The context of every `initialize` and `updateContext` call, in call order. `initialize` without
|
|
400
|
-
* a context records an empty context, and so does a call whose context has an invalid kind
|
|
401
|
-
* the client connects without it. Resumes are not recorded.
|
|
413
|
+
* a context records an empty context, and so does a call whose context has an invalid kind or is
|
|
414
|
+
* over the context size limits, since the client connects without it. Resumes are not recorded.
|
|
402
415
|
*/
|
|
403
416
|
readonly contextUpdates: ConfigDirectorContext[];
|
|
404
417
|
/**
|
package/dist/testing.mjs
CHANGED
|
@@ -916,7 +916,8 @@ const createDefaultLogger = (level, messageDecorator) => {
|
|
|
916
916
|
const discardingTelemetryClient = {
|
|
917
917
|
updateContext: async () => {},
|
|
918
918
|
evaluatedConfig: () => {},
|
|
919
|
-
|
|
919
|
+
recordInvalidContextKind: () => {},
|
|
920
|
+
recordContextOverSizeLimit: () => {},
|
|
920
921
|
trackedEvent: () => {},
|
|
921
922
|
close: async () => {}
|
|
922
923
|
};
|
|
@@ -1169,12 +1170,12 @@ var PollingTransport = class extends AbstractPollingTransport {
|
|
|
1169
1170
|
this.endCurrentConnection();
|
|
1170
1171
|
const generation = this.connectionGeneration;
|
|
1171
1172
|
const clientSession = await this.options.clientSession;
|
|
1172
|
-
if (
|
|
1173
|
+
if (!this.isCurrentConnection(generation)) return this;
|
|
1173
1174
|
try {
|
|
1174
|
-
await this.fetchConfigs(context, timeout, clientSession);
|
|
1175
|
+
await this.fetchConfigs(context, timeout, clientSession, generation);
|
|
1175
1176
|
} finally {
|
|
1176
|
-
if (
|
|
1177
|
-
this.fetchConfigs(context, timeout, clientSession).catch((error) => {
|
|
1177
|
+
if (this.continuesPolling(generation)) this.schedulePollingInterval(() => {
|
|
1178
|
+
this.fetchConfigs(context, timeout, clientSession, generation).catch((error) => {
|
|
1178
1179
|
this.logger.error("[PollingTransport] Error during polling:", error);
|
|
1179
1180
|
});
|
|
1180
1181
|
});
|
|
@@ -1190,7 +1191,13 @@ var PollingTransport = class extends AbstractPollingTransport {
|
|
|
1190
1191
|
this.clearPollingInterval();
|
|
1191
1192
|
this.lastUpdateTimestamp = void 0;
|
|
1192
1193
|
}
|
|
1193
|
-
|
|
1194
|
+
isCurrentConnection(generation) {
|
|
1195
|
+
return generation === this.connectionGeneration;
|
|
1196
|
+
}
|
|
1197
|
+
continuesPolling(generation) {
|
|
1198
|
+
return !this.fatalError && this.isCurrentConnection(generation);
|
|
1199
|
+
}
|
|
1200
|
+
async fetchConfigs(context, timeout, clientSession, generation) {
|
|
1194
1201
|
if (this.fatalError) {
|
|
1195
1202
|
this.logger.warn("[PollingTransport] There was a prior unrecoverable error. Ignoring attempt to reconnect.");
|
|
1196
1203
|
return;
|
|
@@ -1211,6 +1218,7 @@ var PollingTransport = class extends AbstractPollingTransport {
|
|
|
1211
1218
|
await this.handleNonOkResponse(response);
|
|
1212
1219
|
if (response.status == 200) {
|
|
1213
1220
|
const json = JSON.parse(await response.text());
|
|
1221
|
+
if (!this.isCurrentConnection(generation)) return;
|
|
1214
1222
|
this.lastUpdateTimestamp = json.timestamp;
|
|
1215
1223
|
this.eventEmitter.emit("configSetReceived", json);
|
|
1216
1224
|
}
|
|
@@ -1291,6 +1299,42 @@ const utf8ByteLength = (text) => {
|
|
|
1291
1299
|
return bytes;
|
|
1292
1300
|
};
|
|
1293
1301
|
//#endregion
|
|
1302
|
+
//#region ../js-client-core/src/context-admission.ts
|
|
1303
|
+
const IDENTIFIER_MAXIMUM_CHARACTERS = 256;
|
|
1304
|
+
const NAME_MAXIMUM_CHARACTERS$1 = 256;
|
|
1305
|
+
const TRAITS_MAXIMUM_JSON_BYTES = 65536;
|
|
1306
|
+
const hasMoreCharactersThan = (maximumCharacters, text) => typeof text === "string" && Array.from(text).length > maximumCharacters;
|
|
1307
|
+
const hasMoreJsonBytesThan = (maximumBytes, traits) => {
|
|
1308
|
+
let json;
|
|
1309
|
+
try {
|
|
1310
|
+
json = JSON.stringify(traits);
|
|
1311
|
+
} catch {
|
|
1312
|
+
return false;
|
|
1313
|
+
}
|
|
1314
|
+
return json !== void 0 && utf8ByteLength(json) > maximumBytes;
|
|
1315
|
+
};
|
|
1316
|
+
const firstSizeLimitPassedBy = (context) => {
|
|
1317
|
+
if (hasMoreCharactersThan(IDENTIFIER_MAXIMUM_CHARACTERS, context?.id)) return "identifier-too-long";
|
|
1318
|
+
if (hasMoreCharactersThan(NAME_MAXIMUM_CHARACTERS$1, context?.name)) return "name-too-long";
|
|
1319
|
+
if (hasMoreJsonBytesThan(TRAITS_MAXIMUM_JSON_BYTES, context?.traits)) return "traits-too-large";
|
|
1320
|
+
};
|
|
1321
|
+
const admitClientContext = (context) => {
|
|
1322
|
+
const kindAdmission = admitContext(context);
|
|
1323
|
+
if (kindAdmission.outcome === "ignored") return {
|
|
1324
|
+
outcome: "invalid kind",
|
|
1325
|
+
kindSample: kindAdmission.kindSample
|
|
1326
|
+
};
|
|
1327
|
+
const passedSizeLimit = firstSizeLimitPassedBy(context);
|
|
1328
|
+
if (passedSizeLimit !== void 0) return {
|
|
1329
|
+
outcome: "over a size limit",
|
|
1330
|
+
reason: passedSizeLimit
|
|
1331
|
+
};
|
|
1332
|
+
return {
|
|
1333
|
+
outcome: "admitted",
|
|
1334
|
+
context
|
|
1335
|
+
};
|
|
1336
|
+
};
|
|
1337
|
+
//#endregion
|
|
1294
1338
|
//#region ../shared/src/telemetry/reported-context.ts
|
|
1295
1339
|
const USER_CONTEXT_KIND = "user";
|
|
1296
1340
|
const reportedContextOf = (context) => {
|
|
@@ -1542,6 +1586,26 @@ var CachedValuesStore = class {
|
|
|
1542
1586
|
//#endregion
|
|
1543
1587
|
//#region ../js-client-core/src/DefaultConfigDirectorClient.ts
|
|
1544
1588
|
const MAX_EXPONENTIAL_DELAY = 9;
|
|
1589
|
+
const CONTEXT_SIZE_LIMIT_EXPLANATIONS = {
|
|
1590
|
+
"identifier-too-long": "its id is longer than 256 characters",
|
|
1591
|
+
"name-too-long": "its name is longer than 256 characters",
|
|
1592
|
+
"traits-too-large": "its traits are over 64 KB of JSON"
|
|
1593
|
+
};
|
|
1594
|
+
const createReadyOrClosedSignal = () => {
|
|
1595
|
+
let raise;
|
|
1596
|
+
return {
|
|
1597
|
+
raised: new Promise((resolve) => {
|
|
1598
|
+
raise = resolve;
|
|
1599
|
+
}),
|
|
1600
|
+
raise
|
|
1601
|
+
};
|
|
1602
|
+
};
|
|
1603
|
+
const waitAtMost = async (timeout, awaited) => {
|
|
1604
|
+
let timeoutTimer;
|
|
1605
|
+
await Promise.race([awaited, new Promise((resolve) => {
|
|
1606
|
+
timeoutTimer = setTimeout(() => resolve(), timeout);
|
|
1607
|
+
})]).finally(() => clearTimeout(timeoutTimer));
|
|
1608
|
+
};
|
|
1545
1609
|
var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
1546
1610
|
logger;
|
|
1547
1611
|
telemetryClient;
|
|
@@ -1550,14 +1614,14 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1550
1614
|
transport;
|
|
1551
1615
|
eventEmitter = new Emitter();
|
|
1552
1616
|
timeout;
|
|
1553
|
-
timeoutTimer;
|
|
1554
1617
|
ready = false;
|
|
1555
1618
|
initializing = false;
|
|
1556
1619
|
hasReceivedConfigSet = false;
|
|
1557
|
-
readyPromise;
|
|
1558
1620
|
readyResolve;
|
|
1621
|
+
readyOrClosedSignal = createReadyOrClosedSignal();
|
|
1559
1622
|
currentContext;
|
|
1560
1623
|
submittedContext;
|
|
1624
|
+
latestConnectAttempt = 0;
|
|
1561
1625
|
connectionPlan;
|
|
1562
1626
|
clientSession;
|
|
1563
1627
|
cachedValuesStore;
|
|
@@ -1764,12 +1828,16 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1764
1828
|
await this.connectToTransport(this.admittedContextFor(context, submission), submission);
|
|
1765
1829
|
}
|
|
1766
1830
|
admittedContextFor(suppliedContext, submission) {
|
|
1767
|
-
const admission =
|
|
1831
|
+
const admission = admitClientContext(suppliedContext);
|
|
1768
1832
|
switch (admission.outcome) {
|
|
1769
1833
|
case "admitted": return admission.context;
|
|
1770
|
-
case "
|
|
1834
|
+
case "invalid kind":
|
|
1771
1835
|
this.logger.error(`[ConfigDirectorClient] Ignored the context supplied for ${submission} because its kind '${admission.kindSample}' is invalid; continuing as if no context was supplied. A context kind has 1 to 64 characters, using only lowercase letters, digits, '-' and '_'.`);
|
|
1772
|
-
this.telemetryClient.
|
|
1836
|
+
this.telemetryClient.recordInvalidContextKind(admission.kindSample);
|
|
1837
|
+
return;
|
|
1838
|
+
case "over a size limit":
|
|
1839
|
+
this.logger.error(`[ConfigDirectorClient] Ignored the context supplied for ${submission} because ${CONTEXT_SIZE_LIMIT_EXPLANATIONS[admission.reason]}; continuing as if no context was supplied.`);
|
|
1840
|
+
this.telemetryClient.recordContextOverSizeLimit(admission.reason);
|
|
1773
1841
|
return;
|
|
1774
1842
|
}
|
|
1775
1843
|
}
|
|
@@ -1777,31 +1845,28 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1777
1845
|
return this.currentContext;
|
|
1778
1846
|
}
|
|
1779
1847
|
async connectToTransport(context, caller) {
|
|
1848
|
+
const attempt = ++this.latestConnectAttempt;
|
|
1849
|
+
const readyOrClosed = this.readyOrClosedSignal.raised;
|
|
1780
1850
|
this.submittedContext = context;
|
|
1781
1851
|
if (caller === "initialization") this.startCachedValuesAdoption();
|
|
1782
1852
|
try {
|
|
1783
1853
|
this.ready = false;
|
|
1784
|
-
|
|
1854
|
+
new Promise((resolve) => {
|
|
1785
1855
|
this.readyResolve = resolve;
|
|
1786
1856
|
}).then((cancelled) => {
|
|
1787
1857
|
if (cancelled) return;
|
|
1788
1858
|
this.ready = true;
|
|
1789
1859
|
this.initializing = false;
|
|
1860
|
+
this.signalReadyOrClosed();
|
|
1790
1861
|
this.emit("clientReady", { action: caller });
|
|
1791
1862
|
this.logger.debug("[ConfigDirectorClient] Received initial payload from the server, client is ready");
|
|
1792
1863
|
});
|
|
1793
1864
|
const startTime = (/* @__PURE__ */ new Date()).getTime();
|
|
1794
1865
|
await this.transport.connect(context ?? {}, this.timeout, caller);
|
|
1795
|
-
this.
|
|
1796
|
-
this.telemetryClient.updateContext(context).catch((error) => this.logger.warn("[ConfigDirectorClient] Telemetry could not update the context: ", error));
|
|
1797
|
-
this.emit("contextUpdated", { context });
|
|
1866
|
+
if (attempt === this.latestConnectAttempt) this.adoptContext(context);
|
|
1798
1867
|
const elapsedTime = (/* @__PURE__ */ new Date()).getTime() - startTime;
|
|
1799
1868
|
const remainingTimeout = this.timeout - elapsedTime;
|
|
1800
|
-
|
|
1801
|
-
this.timeoutTimer = void 0;
|
|
1802
|
-
if (remainingTimeout > 0) await Promise.race([this.readyPromise, new Promise((resolve) => {
|
|
1803
|
-
this.timeoutTimer = setTimeout(() => resolve(), remainingTimeout);
|
|
1804
|
-
})]).finally(() => clearTimeout(this.timeoutTimer));
|
|
1869
|
+
if (remainingTimeout > 0) await waitAtMost(remainingTimeout, readyOrClosed);
|
|
1805
1870
|
if (!this.ready) this.logger.warn(`[ConfigDirectorClient] Timed out waiting for ${caller} after ${this.timeout}ms. ${this.timeoutWarningDetails()}`);
|
|
1806
1871
|
} catch (error) {
|
|
1807
1872
|
if (error instanceof ConfigDirectorInitializationError) {
|
|
@@ -1811,6 +1876,15 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1811
1876
|
this.logger.error(`[ConfigDirectorClient] An error occurred during ${caller}: `, error);
|
|
1812
1877
|
}
|
|
1813
1878
|
}
|
|
1879
|
+
adoptContext(context) {
|
|
1880
|
+
this.currentContext = context;
|
|
1881
|
+
this.telemetryClient.updateContext(context).catch((error) => this.logger.warn("[ConfigDirectorClient] Telemetry could not update the context: ", error));
|
|
1882
|
+
this.emit("contextUpdated", { context });
|
|
1883
|
+
}
|
|
1884
|
+
signalReadyOrClosed() {
|
|
1885
|
+
this.readyOrClosedSignal.raise();
|
|
1886
|
+
this.readyOrClosedSignal = createReadyOrClosedSignal();
|
|
1887
|
+
}
|
|
1814
1888
|
timeoutWarningDetails() {
|
|
1815
1889
|
switch (this.connectionPlan.kind) {
|
|
1816
1890
|
case "connect": return "The client will continue to retry since there were no fatal errors detected. Configs will return the default value until the connection succeeds.";
|
|
@@ -1963,8 +2037,6 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1963
2037
|
case "stay-offline": return;
|
|
1964
2038
|
case "connect":
|
|
1965
2039
|
this.logger.debug("[ConfigDirectorClient] pauseNetwork() called, pausing transport connection");
|
|
1966
|
-
clearTimeout(this.timeoutTimer);
|
|
1967
|
-
this.timeoutTimer = void 0;
|
|
1968
2040
|
this.transport.close();
|
|
1969
2041
|
this.ready = false;
|
|
1970
2042
|
return;
|
|
@@ -1980,12 +2052,12 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1980
2052
|
}
|
|
1981
2053
|
async close() {
|
|
1982
2054
|
this.logger.debug("[ConfigDirectorClient] close() has been called, closing connection to server");
|
|
1983
|
-
clearTimeout(this.timeoutTimer);
|
|
1984
2055
|
this.readyResolve?.(true);
|
|
1985
2056
|
this.telemetryClient.close().catch((error) => this.logger.warn("[ConfigDirectorClient] Telemetry could not close: ", error));
|
|
1986
2057
|
this.transport.close();
|
|
1987
2058
|
this.ready = false;
|
|
1988
2059
|
this.initializing = false;
|
|
2060
|
+
this.signalReadyOrClosed();
|
|
1989
2061
|
}
|
|
1990
2062
|
dispose() {
|
|
1991
2063
|
this.clear();
|
|
@@ -2312,7 +2384,7 @@ const installTestClient = (testClient) => {
|
|
|
2312
2384
|
const createTestClient = (options) => {
|
|
2313
2385
|
return createTestClient$1({
|
|
2314
2386
|
sdkName: "nuxt-sdk",
|
|
2315
|
-
sdkVersion: "1.
|
|
2387
|
+
sdkVersion: "1.15.0"
|
|
2316
2388
|
}, options);
|
|
2317
2389
|
};
|
|
2318
2390
|
//#endregion
|
package/package.json
CHANGED