@configdirector/nuxt-sdk 1.13.2 → 1.14.1
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 +43 -4
- 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/useConfigDirectorValue.d.mts +1 -1
- package/dist/runtime/app/composables/useConfigDirectorValue.d.ts +1 -1
- package/dist/runtime/{native-values-CfhP0yLS.d.mts → native-values-Cq3SCmEH.d.mts} +49 -4
- 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 +9 -2
- package/dist/runtime/nitro/plugin.d.ts +9 -2
- package/dist/runtime/nitro/plugin.mjs +319 -82
- package/dist/runtime/plugin.client.mjs +191 -3
- package/dist/runtime/plugin.server.mjs +3 -0
- 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-BvqduMQP.d.mts → types-BNw2c3C0.d.mts} +17 -3
- package/dist/runtime/{types-qDEc6g8R.d.mts → types-CYquNKWW.d.mts} +18 -3
- package/dist/testing.d.mts +78 -7
- package/dist/testing.mjs +158 -5
- package/package.json +2 -2
package/dist/testing.mjs
CHANGED
|
@@ -666,6 +666,24 @@ const offlineSourceOf = (connection) => {
|
|
|
666
666
|
};
|
|
667
667
|
//#endregion
|
|
668
668
|
//#region ../shared/src/value-parser.ts
|
|
669
|
+
const NO_VARIATION_OR_ROLLOUT_SHARE = {
|
|
670
|
+
variation: void 0,
|
|
671
|
+
ruleId: void 0,
|
|
672
|
+
shareId: void 0
|
|
673
|
+
};
|
|
674
|
+
const variationOf = (configState) => {
|
|
675
|
+
const variation = configState.variation;
|
|
676
|
+
if (variation == null) return;
|
|
677
|
+
return variation.name ? {
|
|
678
|
+
id: variation.id,
|
|
679
|
+
name: variation.name
|
|
680
|
+
} : { id: variation.id };
|
|
681
|
+
};
|
|
682
|
+
const variationAndRolloutShareOf = (configState) => ({
|
|
683
|
+
variation: variationOf(configState),
|
|
684
|
+
ruleId: configState.ruleId ?? void 0,
|
|
685
|
+
shareId: configState.shareId ?? void 0
|
|
686
|
+
});
|
|
669
687
|
const getRequestedType = (defaultValue) => {
|
|
670
688
|
const baseType = typeof defaultValue;
|
|
671
689
|
if (baseType === "object") try {
|
|
@@ -690,6 +708,13 @@ const configTypesNotReadableAsString = new Set([
|
|
|
690
708
|
"float"
|
|
691
709
|
]);
|
|
692
710
|
const parseConfigValue = (configState, defaultValue) => {
|
|
711
|
+
const valueAndReason = parseValueAndReason(configState, defaultValue);
|
|
712
|
+
return {
|
|
713
|
+
...valueAndReason,
|
|
714
|
+
...valueAndReason.usedDefault ? NO_VARIATION_OR_ROLLOUT_SHARE : variationAndRolloutShareOf(configState)
|
|
715
|
+
};
|
|
716
|
+
};
|
|
717
|
+
const parseValueAndReason = (configState, defaultValue) => {
|
|
693
718
|
const value = configState.value;
|
|
694
719
|
const requestedType = getRequestedType(defaultValue);
|
|
695
720
|
if (value == null || value === "") return {
|
|
@@ -892,6 +917,7 @@ const discardingTelemetryClient = {
|
|
|
892
917
|
updateContext: async () => {},
|
|
893
918
|
evaluatedConfig: () => {},
|
|
894
919
|
recordInvalidContext: () => {},
|
|
920
|
+
trackedEvent: () => {},
|
|
895
921
|
close: async () => {}
|
|
896
922
|
};
|
|
897
923
|
//#endregion
|
|
@@ -1265,6 +1291,88 @@ const utf8ByteLength = (text) => {
|
|
|
1265
1291
|
return bytes;
|
|
1266
1292
|
};
|
|
1267
1293
|
//#endregion
|
|
1294
|
+
//#region ../shared/src/telemetry/reported-context.ts
|
|
1295
|
+
const USER_CONTEXT_KIND = "user";
|
|
1296
|
+
const reportedContextOf = (context) => {
|
|
1297
|
+
const contextIdentifier = context?.anonymous ? void 0 : context?.id;
|
|
1298
|
+
if (contextIdentifier === void 0) return {};
|
|
1299
|
+
return {
|
|
1300
|
+
contextKind: context?.kind ?? USER_CONTEXT_KIND,
|
|
1301
|
+
contextIdentifier
|
|
1302
|
+
};
|
|
1303
|
+
};
|
|
1304
|
+
//#endregion
|
|
1305
|
+
//#region ../shared/src/telemetry/tracked-events.ts
|
|
1306
|
+
const TRACKED_EVENTS_PER_BATCH = 1e3;
|
|
1307
|
+
const NAME_MAXIMUM_CHARACTERS = 150;
|
|
1308
|
+
const NAME_MAXIMUM_UTF16_UNITS = NAME_MAXIMUM_CHARACTERS * 2;
|
|
1309
|
+
const DETAILS_MAXIMUM_TOP_LEVEL_KEYS = 20;
|
|
1310
|
+
const DETAILS_MAXIMUM_JSON_BYTES = 1024;
|
|
1311
|
+
const trackedEventWarningMessages = {
|
|
1312
|
+
"name-outside-the-character-limit": `[ConfigDirectorClient] A tracked event was not reported because its name does not have 1 to ${NAME_MAXIMUM_CHARACTERS} characters.`,
|
|
1313
|
+
"value-not-a-finite-number": "[ConfigDirectorClient] A tracked event was reported without its value because the value is not a finite number.",
|
|
1314
|
+
"details-not-reportable": `[ConfigDirectorClient] A tracked event was reported without its details because they are not an object, have more than ${DETAILS_MAXIMUM_TOP_LEVEL_KEYS} top-level keys, are larger than ${DETAILS_MAXIMUM_JSON_BYTES} bytes as JSON, or cannot be written as JSON.`,
|
|
1315
|
+
"batch-already-full": `[ConfigDirectorClient] A tracked event was not reported because ${TRACKED_EVENTS_PER_BATCH} tracked events are already waiting for the next telemetry batch.`
|
|
1316
|
+
};
|
|
1317
|
+
const isGiven = (option) => option !== void 0 && option !== null;
|
|
1318
|
+
const isNonArrayObject = (candidate) => typeof candidate === "object" && candidate !== null && !Array.isArray(candidate);
|
|
1319
|
+
const isWithinTheCharacterLimit = (name) => typeof name === "string" && name.length >= 1 && name.length <= NAME_MAXIMUM_UTF16_UNITS && Array.from(name).length <= NAME_MAXIMUM_CHARACTERS;
|
|
1320
|
+
const reportableValueOf = (value) => {
|
|
1321
|
+
if (!isGiven(value)) return { status: "not-given" };
|
|
1322
|
+
if (typeof value === "number" && Number.isFinite(value)) return {
|
|
1323
|
+
status: "reportable",
|
|
1324
|
+
fields: { value }
|
|
1325
|
+
};
|
|
1326
|
+
return {
|
|
1327
|
+
status: "left-out",
|
|
1328
|
+
warning: "value-not-a-finite-number"
|
|
1329
|
+
};
|
|
1330
|
+
};
|
|
1331
|
+
const jsonCopyWithinTheLimits = (details) => {
|
|
1332
|
+
if (!isNonArrayObject(details)) return;
|
|
1333
|
+
try {
|
|
1334
|
+
const json = JSON.stringify(details);
|
|
1335
|
+
if (typeof json !== "string" || utf8ByteLength(json) > DETAILS_MAXIMUM_JSON_BYTES) return;
|
|
1336
|
+
const copy = JSON.parse(json);
|
|
1337
|
+
return isNonArrayObject(copy) && Object.keys(copy).length <= DETAILS_MAXIMUM_TOP_LEVEL_KEYS ? copy : void 0;
|
|
1338
|
+
} catch {
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
1341
|
+
};
|
|
1342
|
+
const reportableDetailsOf = (details) => {
|
|
1343
|
+
if (!isGiven(details)) return { status: "not-given" };
|
|
1344
|
+
const jsonCopy = jsonCopyWithinTheLimits(details);
|
|
1345
|
+
if (jsonCopy === void 0) return {
|
|
1346
|
+
status: "left-out",
|
|
1347
|
+
warning: "details-not-reportable"
|
|
1348
|
+
};
|
|
1349
|
+
return {
|
|
1350
|
+
status: "reportable",
|
|
1351
|
+
fields: { details: jsonCopy }
|
|
1352
|
+
};
|
|
1353
|
+
};
|
|
1354
|
+
const fieldsOf = (option) => option.status === "reportable" ? option.fields : void 0;
|
|
1355
|
+
const warningsOf = (...options) => options.flatMap((option) => option.status === "left-out" ? [option.warning] : []);
|
|
1356
|
+
const admitTrackedEvent = (call) => {
|
|
1357
|
+
if (!isWithinTheCharacterLimit(call.name)) return {
|
|
1358
|
+
outcome: "dropped",
|
|
1359
|
+
warnings: ["name-outside-the-character-limit"]
|
|
1360
|
+
};
|
|
1361
|
+
const value = reportableValueOf(call.options?.value);
|
|
1362
|
+
const details = reportableDetailsOf(call.options?.details);
|
|
1363
|
+
return {
|
|
1364
|
+
outcome: "admitted",
|
|
1365
|
+
entry: {
|
|
1366
|
+
name: call.name,
|
|
1367
|
+
...reportedContextOf(call.context),
|
|
1368
|
+
...fieldsOf(value),
|
|
1369
|
+
...fieldsOf(details),
|
|
1370
|
+
happenedAt: call.happenedAt.toISOString()
|
|
1371
|
+
},
|
|
1372
|
+
warnings: warningsOf(value, details)
|
|
1373
|
+
};
|
|
1374
|
+
};
|
|
1375
|
+
//#endregion
|
|
1268
1376
|
//#region ../js-client-core/src/cached-values.ts
|
|
1269
1377
|
const ENTRY_FORMAT_VERSION = 2;
|
|
1270
1378
|
const FIRST_ENTRY_FORMAT_VERSION = 1;
|
|
@@ -1785,12 +1893,16 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1785
1893
|
evaluatedValue: parseResult.parsedValue,
|
|
1786
1894
|
evaluatedValueId: parseResult.parsedValueId,
|
|
1787
1895
|
usedDefault: parseResult.usedDefault,
|
|
1788
|
-
evaluationReason: reason
|
|
1896
|
+
evaluationReason: reason,
|
|
1897
|
+
ruleId: parseResult.ruleId,
|
|
1898
|
+
shareId: parseResult.shareId,
|
|
1899
|
+
variationId: parseResult.variation?.id
|
|
1789
1900
|
});
|
|
1790
1901
|
const evaluation = {
|
|
1791
1902
|
key: configKey,
|
|
1792
1903
|
value: parseResult.parsedValue,
|
|
1793
1904
|
valueId: parseResult.parsedValueId ?? void 0,
|
|
1905
|
+
variation: parseResult.variation,
|
|
1794
1906
|
isDefaultValue: parseResult.usedDefault,
|
|
1795
1907
|
reason,
|
|
1796
1908
|
context: this.context
|
|
@@ -1833,6 +1945,19 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1833
1945
|
unwatchAll() {
|
|
1834
1946
|
this.handlersMap.clear();
|
|
1835
1947
|
}
|
|
1948
|
+
track(eventName, options) {
|
|
1949
|
+
try {
|
|
1950
|
+
const context = this.currentContext;
|
|
1951
|
+
this.telemetryClient.trackedEvent(admitTrackedEvent({
|
|
1952
|
+
name: eventName,
|
|
1953
|
+
context,
|
|
1954
|
+
options,
|
|
1955
|
+
happenedAt: /* @__PURE__ */ new Date()
|
|
1956
|
+
}), context);
|
|
1957
|
+
} catch (error) {
|
|
1958
|
+
this.logger.warn("[ConfigDirectorClient] A tracked event was not reported because it could not be read: ", error);
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1836
1961
|
pauseNetwork() {
|
|
1837
1962
|
switch (this.connectionPlan.kind) {
|
|
1838
1963
|
case "stay-offline": return;
|
|
@@ -1868,6 +1993,29 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
1868
1993
|
}
|
|
1869
1994
|
};
|
|
1870
1995
|
//#endregion
|
|
1996
|
+
//#region ../shared/src/telemetry/RecordedTrackedEvents.ts
|
|
1997
|
+
const recordedEventOf = (entry, context) => ({
|
|
1998
|
+
name: entry.name,
|
|
1999
|
+
...context === void 0 ? {} : { context },
|
|
2000
|
+
...entry.value === void 0 ? {} : { value: entry.value },
|
|
2001
|
+
...entry.details === void 0 ? {} : { details: entry.details }
|
|
2002
|
+
});
|
|
2003
|
+
var RecordedTrackedEvents = class {
|
|
2004
|
+
events = [];
|
|
2005
|
+
constructor(logger) {
|
|
2006
|
+
this.logger = logger;
|
|
2007
|
+
}
|
|
2008
|
+
record(admission, context) {
|
|
2009
|
+
admission.warnings.forEach((warning) => this.logger.warn(trackedEventWarningMessages[warning]));
|
|
2010
|
+
switch (admission.outcome) {
|
|
2011
|
+
case "dropped": return;
|
|
2012
|
+
case "admitted":
|
|
2013
|
+
this.events.push(recordedEventOf(admission.entry, context));
|
|
2014
|
+
return;
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
};
|
|
2018
|
+
//#endregion
|
|
1871
2019
|
//#region ../js-client-core/src/testing/InMemoryConnection.ts
|
|
1872
2020
|
const TEST_ENVIRONMENT = {
|
|
1873
2021
|
environmentId: "test-environment",
|
|
@@ -2058,9 +2206,10 @@ var InMemoryConnection = class {
|
|
|
2058
2206
|
//#region ../js-client-core/src/testing/TestClient.ts
|
|
2059
2207
|
const TEST_CLIENT_SDK_KEY = "test-client";
|
|
2060
2208
|
var InMemoryTestClient = class {
|
|
2061
|
-
constructor(client, connection) {
|
|
2209
|
+
constructor(client, connection, trackedEvents) {
|
|
2062
2210
|
this.client = client;
|
|
2063
2211
|
this.connection = connection;
|
|
2212
|
+
this.trackedEvents = trackedEvents;
|
|
2064
2213
|
}
|
|
2065
2214
|
setValue(key, value) {
|
|
2066
2215
|
this.connection.setValue(key, value);
|
|
@@ -2096,10 +2245,14 @@ var InMemoryTestClient = class {
|
|
|
2096
2245
|
const createTestClient$1 = (sdkOptions, options) => {
|
|
2097
2246
|
const logger = options?.logger ?? createDefaultLogger();
|
|
2098
2247
|
const connection = new InMemoryConnection(logger, options?.values ?? {});
|
|
2099
|
-
|
|
2248
|
+
const recordedTrackedEvents = new RecordedTrackedEvents(logger);
|
|
2249
|
+
return new InMemoryTestClient(new DefaultConfigDirectorClient(() => ({
|
|
2250
|
+
...discardingTelemetryClient,
|
|
2251
|
+
trackedEvent: (admission, context) => recordedTrackedEvents.record(admission, context)
|
|
2252
|
+
}), TEST_CLIENT_SDK_KEY, sdkOptions, {
|
|
2100
2253
|
logger,
|
|
2101
2254
|
connection: { timeout: options?.timeout }
|
|
2102
|
-
}, { transport: connection }), connection);
|
|
2255
|
+
}, { transport: connection }), connection, recordedTrackedEvents.events);
|
|
2103
2256
|
};
|
|
2104
2257
|
//#endregion
|
|
2105
2258
|
//#region ../js-client-core/src/installedTestClient.ts
|
|
@@ -2159,7 +2312,7 @@ const installTestClient = (testClient) => {
|
|
|
2159
2312
|
const createTestClient = (options) => {
|
|
2160
2313
|
return createTestClient$1({
|
|
2161
2314
|
sdkName: "nuxt-sdk",
|
|
2162
|
-
sdkVersion: "1.
|
|
2315
|
+
sdkVersion: "1.14.1"
|
|
2163
2316
|
}, options);
|
|
2164
2317
|
};
|
|
2165
2318
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@configdirector/nuxt-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.1",
|
|
4
4
|
"description": "Nuxt SDK for ConfigDirector. ConfigDirector is a remote configuration and feature flag service.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ConfigDirector",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"changelogen": "^0.6.2",
|
|
73
73
|
"eslint": "^10.7.0",
|
|
74
74
|
"jsdom": "^30.0.1",
|
|
75
|
-
"nuxt": "^4.
|
|
75
|
+
"nuxt": "^4.6.3",
|
|
76
76
|
"playwright": "^1.64.1",
|
|
77
77
|
"rimraf": "^6.1.3",
|
|
78
78
|
"tsdown": "^0.21.7",
|