@configdirector/nuxt-sdk 1.13.1 → 1.14.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 +46 -6
- 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 +321 -81
- 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
|
@@ -7243,6 +7243,29 @@ const assignPercentage = ({ configId, contextIdentifier, contextKind }) => {
|
|
|
7243
7243
|
};
|
|
7244
7244
|
//#endregion
|
|
7245
7245
|
//#region ../config-evaluator/src/ConfigEvaluator.ts
|
|
7246
|
+
const NOT_MATCHED = { kind: "not-matched" };
|
|
7247
|
+
const outcomeByServingKind = {
|
|
7248
|
+
served: "matched",
|
|
7249
|
+
"not-matched": "not-matched",
|
|
7250
|
+
"rollout-skipped-no-identifier": "rollout-skipped-no-identifier"
|
|
7251
|
+
};
|
|
7252
|
+
const servedVariation = (config, variationId) => {
|
|
7253
|
+
if (variationId === void 0) return;
|
|
7254
|
+
const variation = (config.variations ?? []).find((candidate) => candidate.id === variationId);
|
|
7255
|
+
return variation ? {
|
|
7256
|
+
id: variationId,
|
|
7257
|
+
name: variation.name
|
|
7258
|
+
} : void 0;
|
|
7259
|
+
};
|
|
7260
|
+
const servedConfigState = (config, explanation) => ({
|
|
7261
|
+
id: config.id,
|
|
7262
|
+
key: config.key,
|
|
7263
|
+
type: config.type,
|
|
7264
|
+
value: explanation.value,
|
|
7265
|
+
valueId: explanation.valueId,
|
|
7266
|
+
variation: servedVariation(config, explanation.variationId),
|
|
7267
|
+
...explanation.rolloutShare
|
|
7268
|
+
});
|
|
7246
7269
|
var ConfigEvaluator = class {
|
|
7247
7270
|
conditionEvaluator = new ConditionEvaluator();
|
|
7248
7271
|
segmentEvaluator = new SegmentEvaluator(this.conditionEvaluator);
|
|
@@ -7252,59 +7275,55 @@ var ConfigEvaluator = class {
|
|
|
7252
7275
|
this.logger = logger;
|
|
7253
7276
|
}
|
|
7254
7277
|
evaluate(config, context, segments) {
|
|
7255
|
-
|
|
7256
|
-
return {
|
|
7257
|
-
id: config.id,
|
|
7258
|
-
key: config.key,
|
|
7259
|
-
type: config.type,
|
|
7260
|
-
value: explanation.value,
|
|
7261
|
-
valueId: explanation.valueId
|
|
7262
|
-
};
|
|
7278
|
+
return servedConfigState(config, this.explain(config, context, segments));
|
|
7263
7279
|
}
|
|
7264
7280
|
/**
|
|
7265
7281
|
* Evaluate a config for a context and record how the value was reached: every rule in the
|
|
7266
7282
|
* order it was walked with its outcome, the conditions that were checked with what they
|
|
7267
|
-
* resolved to, and the share a rollout assigned the context to.
|
|
7268
|
-
*
|
|
7269
|
-
*
|
|
7270
|
-
*
|
|
7283
|
+
* resolved to, and the share a rollout assigned the context to. A rollout reached by a context
|
|
7284
|
+
* without an identifier is skipped: the walk ends there and the default targeting rule value
|
|
7285
|
+
* is served with the reason `rollout-skipped-no-identifier`. `evaluate` is this walk with only
|
|
7286
|
+
* the value, its value ID, its variation and the rollout share that served it kept, so the two
|
|
7287
|
+
* cannot disagree. `segments` is the payload's segments map, which a segment condition looks
|
|
7288
|
+
* its segment up in; a segment it does not hold never matches.
|
|
7271
7289
|
*/
|
|
7272
7290
|
explain(config, context, segments) {
|
|
7273
|
-
const rules = [...config.target?.rules ?? []].sort((
|
|
7274
|
-
const
|
|
7275
|
-
let served;
|
|
7291
|
+
const rules = [...config.target?.rules ?? []].sort((rule, otherRule) => (rule.order ?? Number.MAX_SAFE_INTEGER) - (otherRule.order ?? Number.MAX_SAFE_INTEGER));
|
|
7292
|
+
const walkedRules = [];
|
|
7276
7293
|
for (const rule of rules) {
|
|
7277
|
-
|
|
7278
|
-
|
|
7279
|
-
|
|
7280
|
-
outcome: "not-evaluated",
|
|
7281
|
-
conditions: [],
|
|
7282
|
-
bucket: void 0
|
|
7283
|
-
});
|
|
7284
|
-
continue;
|
|
7285
|
-
}
|
|
7286
|
-
const result = this.explainRule(rule, config, context, segments);
|
|
7287
|
-
explanations.push(result.explanation);
|
|
7288
|
-
if (result.served !== void 0) served = {
|
|
7289
|
-
ruleId: rule.id,
|
|
7290
|
-
...result.served
|
|
7291
|
-
};
|
|
7294
|
+
const walkedRule = this.explainRule(rule, config, context, segments);
|
|
7295
|
+
walkedRules.push(walkedRule);
|
|
7296
|
+
if (walkedRule.serving.kind !== "not-matched") break;
|
|
7292
7297
|
}
|
|
7293
|
-
|
|
7294
|
-
|
|
7295
|
-
|
|
7296
|
-
|
|
7297
|
-
|
|
7298
|
-
|
|
7299
|
-
|
|
7300
|
-
rules: explanations
|
|
7301
|
-
};
|
|
7302
|
-
return {
|
|
7298
|
+
const ruleExplanations = [...walkedRules.map((walkedRule) => walkedRule.explanation), ...rules.slice(walkedRules.length).map((rule) => ({
|
|
7299
|
+
ruleId: rule.id,
|
|
7300
|
+
outcome: "not-evaluated",
|
|
7301
|
+
conditions: [],
|
|
7302
|
+
bucket: void 0
|
|
7303
|
+
}))];
|
|
7304
|
+
const defaultTargetingRuleValue = (reason) => ({
|
|
7303
7305
|
value: config.target?.defaultValue,
|
|
7304
7306
|
valueId: config.target?.defaultValueId,
|
|
7307
|
+
variationId: config.target?.defaultVariationId,
|
|
7308
|
+
rolloutShare: void 0,
|
|
7309
|
+
reason,
|
|
7305
7310
|
servedBy: { kind: "default" },
|
|
7306
|
-
rules:
|
|
7307
|
-
};
|
|
7311
|
+
rules: ruleExplanations
|
|
7312
|
+
});
|
|
7313
|
+
const lastServing = walkedRules[walkedRules.length - 1]?.serving ?? NOT_MATCHED;
|
|
7314
|
+
switch (lastServing.kind) {
|
|
7315
|
+
case "served": return {
|
|
7316
|
+
...lastServing.servedValue,
|
|
7317
|
+
reason: "found-match",
|
|
7318
|
+
servedBy: {
|
|
7319
|
+
kind: "rule",
|
|
7320
|
+
ruleId: lastServing.ruleId
|
|
7321
|
+
},
|
|
7322
|
+
rules: ruleExplanations
|
|
7323
|
+
};
|
|
7324
|
+
case "rollout-skipped-no-identifier": return defaultTargetingRuleValue("rollout-skipped-no-identifier");
|
|
7325
|
+
case "not-matched": return defaultTargetingRuleValue("found-match");
|
|
7326
|
+
}
|
|
7308
7327
|
}
|
|
7309
7328
|
explainRule(rule, config, context, segments) {
|
|
7310
7329
|
const explanation = {
|
|
@@ -7314,13 +7333,13 @@ var ConfigEvaluator = class {
|
|
|
7314
7333
|
bucket: void 0
|
|
7315
7334
|
};
|
|
7316
7335
|
try {
|
|
7317
|
-
let
|
|
7318
|
-
if (rule.type == "percentage")
|
|
7319
|
-
else if (rule.type == "conditional")
|
|
7320
|
-
|
|
7336
|
+
let serving = NOT_MATCHED;
|
|
7337
|
+
if (rule.type == "percentage") serving = this.explainRollout(rule, config, context, explanation);
|
|
7338
|
+
else if (rule.type == "conditional") serving = this.explainConditionalRule(rule, config, context, segments, explanation);
|
|
7339
|
+
explanation.outcome = outcomeByServingKind[serving.kind];
|
|
7321
7340
|
return {
|
|
7322
7341
|
explanation,
|
|
7323
|
-
|
|
7342
|
+
serving
|
|
7324
7343
|
};
|
|
7325
7344
|
} catch (error) {
|
|
7326
7345
|
this.logger.warn(`There was an error while evaluating a targeting rule '${rule?.id}' for '${config?.key}'. The rule will be disregarded.`, {
|
|
@@ -7335,47 +7354,58 @@ var ConfigEvaluator = class {
|
|
|
7335
7354
|
conditions: [],
|
|
7336
7355
|
bucket: void 0
|
|
7337
7356
|
},
|
|
7338
|
-
|
|
7357
|
+
serving: NOT_MATCHED
|
|
7339
7358
|
};
|
|
7340
7359
|
}
|
|
7341
7360
|
}
|
|
7342
|
-
|
|
7361
|
+
explainRollout(rule, config, context, explanation) {
|
|
7362
|
+
if (rule.percentages == null) return NOT_MATCHED;
|
|
7343
7363
|
const identifier = context?.context?.id ?? void 0;
|
|
7344
|
-
|
|
7364
|
+
if (identifier === void 0) return { kind: "rollout-skipped-no-identifier" };
|
|
7365
|
+
const assignedPercentage = assignPercentage({
|
|
7345
7366
|
configId: config.id,
|
|
7346
7367
|
contextIdentifier: identifier,
|
|
7347
7368
|
contextKind: effectiveContextKind(context)
|
|
7348
7369
|
});
|
|
7349
7370
|
const shares = [];
|
|
7350
|
-
let
|
|
7351
|
-
let
|
|
7352
|
-
for (const percentage of percentages) {
|
|
7353
|
-
const
|
|
7371
|
+
let shareStart = 0;
|
|
7372
|
+
let selectedPercentage = void 0;
|
|
7373
|
+
for (const percentage of rule.percentages) {
|
|
7374
|
+
const shareEnd = shareStart + percentage.percentage;
|
|
7354
7375
|
shares.push({
|
|
7355
7376
|
percentageId: percentage.id,
|
|
7356
|
-
from:
|
|
7357
|
-
to,
|
|
7377
|
+
from: shareStart,
|
|
7378
|
+
to: shareEnd,
|
|
7358
7379
|
value: percentage.value?.toString()
|
|
7359
7380
|
});
|
|
7360
|
-
if (
|
|
7361
|
-
|
|
7381
|
+
if (selectedPercentage === void 0 && assignedPercentage < shareEnd) selectedPercentage = percentage;
|
|
7382
|
+
shareStart = shareEnd;
|
|
7362
7383
|
}
|
|
7363
7384
|
explanation.bucket = {
|
|
7364
7385
|
identifier,
|
|
7365
|
-
defaultedToPredefinedBucket: identifier === void 0,
|
|
7366
7386
|
assignedPercentage,
|
|
7367
7387
|
shares,
|
|
7368
|
-
selectedPercentageId:
|
|
7388
|
+
selectedPercentageId: selectedPercentage?.id
|
|
7389
|
+
};
|
|
7390
|
+
if (selectedPercentage?.value == null) return NOT_MATCHED;
|
|
7391
|
+
return {
|
|
7392
|
+
kind: "served",
|
|
7393
|
+
ruleId: rule.id,
|
|
7394
|
+
servedValue: {
|
|
7395
|
+
value: selectedPercentage.value.toString(),
|
|
7396
|
+
valueId: selectedPercentage.valueId,
|
|
7397
|
+
variationId: selectedPercentage.variationId,
|
|
7398
|
+
rolloutShare: {
|
|
7399
|
+
ruleId: rule.id,
|
|
7400
|
+
shareId: selectedPercentage.id
|
|
7401
|
+
}
|
|
7402
|
+
}
|
|
7369
7403
|
};
|
|
7370
|
-
return selected?.value != null ? {
|
|
7371
|
-
value: selected.value.toString(),
|
|
7372
|
-
valueId: selected.valueId
|
|
7373
|
-
} : void 0;
|
|
7374
7404
|
}
|
|
7375
7405
|
explainConditionalRule(rule, config, context, segments, explanation) {
|
|
7376
|
-
let
|
|
7406
|
+
let aConditionDidNotMatch = false;
|
|
7377
7407
|
for (const condition of rule.conditions ?? []) {
|
|
7378
|
-
if (
|
|
7408
|
+
if (aConditionDidNotMatch) {
|
|
7379
7409
|
explanation.conditions.push({
|
|
7380
7410
|
conditionId: condition.id,
|
|
7381
7411
|
outcome: "not-evaluated"
|
|
@@ -7384,14 +7414,24 @@ var ConfigEvaluator = class {
|
|
|
7384
7414
|
}
|
|
7385
7415
|
const checked = this.explainCondition(condition, context, segments);
|
|
7386
7416
|
explanation.conditions.push(checked);
|
|
7387
|
-
|
|
7417
|
+
aConditionDidNotMatch = checked.outcome !== "matched";
|
|
7418
|
+
}
|
|
7419
|
+
if (aConditionDidNotMatch) return NOT_MATCHED;
|
|
7420
|
+
if (rule.target == "value") {
|
|
7421
|
+
if (rule.value == null) return NOT_MATCHED;
|
|
7422
|
+
return {
|
|
7423
|
+
kind: "served",
|
|
7424
|
+
ruleId: rule.id,
|
|
7425
|
+
servedValue: {
|
|
7426
|
+
value: rule.value.toString(),
|
|
7427
|
+
valueId: rule.valueId,
|
|
7428
|
+
variationId: rule.variationId,
|
|
7429
|
+
rolloutShare: void 0
|
|
7430
|
+
}
|
|
7431
|
+
};
|
|
7388
7432
|
}
|
|
7389
|
-
if (
|
|
7390
|
-
|
|
7391
|
-
value: rule.value.toString(),
|
|
7392
|
-
valueId: rule.valueId
|
|
7393
|
-
} : void 0;
|
|
7394
|
-
if (rule.target == "percentage") return this.explainPercentage(rule.percentages ?? [], config, context, explanation);
|
|
7433
|
+
if (rule.target == "percentage") return this.explainRollout(rule, config, context, explanation);
|
|
7434
|
+
return NOT_MATCHED;
|
|
7395
7435
|
}
|
|
7396
7436
|
explainCondition(condition, context, segments) {
|
|
7397
7437
|
if (condition.kind === "segment") {
|
|
@@ -7417,6 +7457,24 @@ var ConfigEvaluator = class {
|
|
|
7417
7457
|
};
|
|
7418
7458
|
//#endregion
|
|
7419
7459
|
//#region ../shared/src/value-parser.ts
|
|
7460
|
+
const NO_VARIATION_OR_ROLLOUT_SHARE = {
|
|
7461
|
+
variation: void 0,
|
|
7462
|
+
ruleId: void 0,
|
|
7463
|
+
shareId: void 0
|
|
7464
|
+
};
|
|
7465
|
+
const variationOf = (configState) => {
|
|
7466
|
+
const variation = configState.variation;
|
|
7467
|
+
if (variation == null) return;
|
|
7468
|
+
return variation.name ? {
|
|
7469
|
+
id: variation.id,
|
|
7470
|
+
name: variation.name
|
|
7471
|
+
} : { id: variation.id };
|
|
7472
|
+
};
|
|
7473
|
+
const variationAndRolloutShareOf = (configState) => ({
|
|
7474
|
+
variation: variationOf(configState),
|
|
7475
|
+
ruleId: configState.ruleId ?? void 0,
|
|
7476
|
+
shareId: configState.shareId ?? void 0
|
|
7477
|
+
});
|
|
7420
7478
|
const getRequestedType = (defaultValue) => {
|
|
7421
7479
|
const baseType = typeof defaultValue;
|
|
7422
7480
|
if (baseType === "object") try {
|
|
@@ -7441,6 +7499,13 @@ const configTypesNotReadableAsString = new Set([
|
|
|
7441
7499
|
"float"
|
|
7442
7500
|
]);
|
|
7443
7501
|
const parseConfigValue = (configState, defaultValue) => {
|
|
7502
|
+
const valueAndReason = parseValueAndReason(configState, defaultValue);
|
|
7503
|
+
return {
|
|
7504
|
+
...valueAndReason,
|
|
7505
|
+
...valueAndReason.usedDefault ? NO_VARIATION_OR_ROLLOUT_SHARE : variationAndRolloutShareOf(configState)
|
|
7506
|
+
};
|
|
7507
|
+
};
|
|
7508
|
+
const parseValueAndReason = (configState, defaultValue) => {
|
|
7444
7509
|
const value = configState.value;
|
|
7445
7510
|
const requestedType = getRequestedType(defaultValue);
|
|
7446
7511
|
if (value == null || value === "") return {
|
|
@@ -7899,11 +7964,149 @@ var EventQueue = class {
|
|
|
7899
7964
|
}
|
|
7900
7965
|
};
|
|
7901
7966
|
//#endregion
|
|
7967
|
+
//#region ../shared/src/utf8-byte-length.ts
|
|
7968
|
+
const isHighSurrogate = (codeUnit) => codeUnit >= 55296 && codeUnit <= 56319;
|
|
7969
|
+
const isLowSurrogate = (codeUnit) => codeUnit >= 56320 && codeUnit <= 57343;
|
|
7970
|
+
const utf8ByteLength = (text) => {
|
|
7971
|
+
let bytes = 0;
|
|
7972
|
+
for (let i = 0; i < text.length; i++) {
|
|
7973
|
+
const codeUnit = text.charCodeAt(i);
|
|
7974
|
+
if (codeUnit <= 127) bytes += 1;
|
|
7975
|
+
else if (codeUnit <= 2047) bytes += 2;
|
|
7976
|
+
else if (isHighSurrogate(codeUnit) && i + 1 < text.length && isLowSurrogate(text.charCodeAt(i + 1))) {
|
|
7977
|
+
bytes += 4;
|
|
7978
|
+
i++;
|
|
7979
|
+
} else bytes += 3;
|
|
7980
|
+
}
|
|
7981
|
+
return bytes;
|
|
7982
|
+
};
|
|
7983
|
+
//#endregion
|
|
7984
|
+
//#region ../shared/src/telemetry/reported-context.ts
|
|
7985
|
+
const USER_CONTEXT_KIND = "user";
|
|
7986
|
+
const reportedContextOf = (context) => {
|
|
7987
|
+
const contextIdentifier = context?.anonymous ? void 0 : context?.id;
|
|
7988
|
+
if (contextIdentifier === void 0) return {};
|
|
7989
|
+
return {
|
|
7990
|
+
contextKind: context?.kind ?? USER_CONTEXT_KIND,
|
|
7991
|
+
contextIdentifier
|
|
7992
|
+
};
|
|
7993
|
+
};
|
|
7994
|
+
//#endregion
|
|
7995
|
+
//#region ../shared/src/telemetry/tracked-events.ts
|
|
7996
|
+
const TRACKED_EVENTS_PER_BATCH = 1e3;
|
|
7997
|
+
const NAME_MAXIMUM_CHARACTERS = 150;
|
|
7998
|
+
const NAME_MAXIMUM_UTF16_UNITS = NAME_MAXIMUM_CHARACTERS * 2;
|
|
7999
|
+
const DETAILS_MAXIMUM_TOP_LEVEL_KEYS = 20;
|
|
8000
|
+
const DETAILS_MAXIMUM_JSON_BYTES = 1024;
|
|
8001
|
+
const trackedEventWarningMessages = {
|
|
8002
|
+
"name-outside-the-character-limit": `[ConfigDirectorClient] A tracked event was not reported because its name does not have 1 to ${NAME_MAXIMUM_CHARACTERS} characters.`,
|
|
8003
|
+
"value-not-a-finite-number": "[ConfigDirectorClient] A tracked event was reported without its value because the value is not a finite number.",
|
|
8004
|
+
"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.`,
|
|
8005
|
+
"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.`
|
|
8006
|
+
};
|
|
8007
|
+
const logBatchWarnings = (logger, warnings) => {
|
|
8008
|
+
for (const warning of warnings) logger.warn(`${trackedEventWarningMessages[warning]} Further tracked events like it are not logged until the next telemetry batch is sent.`);
|
|
8009
|
+
};
|
|
8010
|
+
const isGiven = (option) => option !== void 0 && option !== null;
|
|
8011
|
+
const isNonArrayObject = (candidate) => typeof candidate === "object" && candidate !== null && !Array.isArray(candidate);
|
|
8012
|
+
const isWithinTheCharacterLimit = (name) => typeof name === "string" && name.length >= 1 && name.length <= NAME_MAXIMUM_UTF16_UNITS && Array.from(name).length <= NAME_MAXIMUM_CHARACTERS;
|
|
8013
|
+
const reportableValueOf = (value) => {
|
|
8014
|
+
if (!isGiven(value)) return { status: "not-given" };
|
|
8015
|
+
if (typeof value === "number" && Number.isFinite(value)) return {
|
|
8016
|
+
status: "reportable",
|
|
8017
|
+
fields: { value }
|
|
8018
|
+
};
|
|
8019
|
+
return {
|
|
8020
|
+
status: "left-out",
|
|
8021
|
+
warning: "value-not-a-finite-number"
|
|
8022
|
+
};
|
|
8023
|
+
};
|
|
8024
|
+
const jsonCopyWithinTheLimits = (details) => {
|
|
8025
|
+
if (!isNonArrayObject(details)) return;
|
|
8026
|
+
try {
|
|
8027
|
+
const json = JSON.stringify(details);
|
|
8028
|
+
if (typeof json !== "string" || utf8ByteLength(json) > DETAILS_MAXIMUM_JSON_BYTES) return;
|
|
8029
|
+
const copy = JSON.parse(json);
|
|
8030
|
+
return isNonArrayObject(copy) && Object.keys(copy).length <= DETAILS_MAXIMUM_TOP_LEVEL_KEYS ? copy : void 0;
|
|
8031
|
+
} catch {
|
|
8032
|
+
return;
|
|
8033
|
+
}
|
|
8034
|
+
};
|
|
8035
|
+
const reportableDetailsOf = (details) => {
|
|
8036
|
+
if (!isGiven(details)) return { status: "not-given" };
|
|
8037
|
+
const jsonCopy = jsonCopyWithinTheLimits(details);
|
|
8038
|
+
if (jsonCopy === void 0) return {
|
|
8039
|
+
status: "left-out",
|
|
8040
|
+
warning: "details-not-reportable"
|
|
8041
|
+
};
|
|
8042
|
+
return {
|
|
8043
|
+
status: "reportable",
|
|
8044
|
+
fields: { details: jsonCopy }
|
|
8045
|
+
};
|
|
8046
|
+
};
|
|
8047
|
+
const fieldsOf = (option) => option.status === "reportable" ? option.fields : void 0;
|
|
8048
|
+
const warningsOf = (...options) => options.flatMap((option) => option.status === "left-out" ? [option.warning] : []);
|
|
8049
|
+
const admitTrackedEvent = (call) => {
|
|
8050
|
+
if (!isWithinTheCharacterLimit(call.name)) return {
|
|
8051
|
+
outcome: "dropped",
|
|
8052
|
+
warnings: ["name-outside-the-character-limit"]
|
|
8053
|
+
};
|
|
8054
|
+
const value = reportableValueOf(call.options?.value);
|
|
8055
|
+
const details = reportableDetailsOf(call.options?.details);
|
|
8056
|
+
return {
|
|
8057
|
+
outcome: "admitted",
|
|
8058
|
+
entry: {
|
|
8059
|
+
name: call.name,
|
|
8060
|
+
...reportedContextOf(call.context),
|
|
8061
|
+
...fieldsOf(value),
|
|
8062
|
+
...fieldsOf(details),
|
|
8063
|
+
happenedAt: call.happenedAt.toISOString()
|
|
8064
|
+
},
|
|
8065
|
+
warnings: warningsOf(value, details)
|
|
8066
|
+
};
|
|
8067
|
+
};
|
|
8068
|
+
//#endregion
|
|
8069
|
+
//#region ../shared/src/telemetry/TrackedEventQueue.ts
|
|
8070
|
+
var TrackedEventQueue = class {
|
|
8071
|
+
entries = [];
|
|
8072
|
+
warningsRaisedThisBatch = /* @__PURE__ */ new Set();
|
|
8073
|
+
add(admission) {
|
|
8074
|
+
return this.warningsOfKeeping(admission).filter((warning) => this.isFirstThisBatch(warning));
|
|
8075
|
+
}
|
|
8076
|
+
absorb(entries) {
|
|
8077
|
+
this.entries.push(...entries);
|
|
8078
|
+
}
|
|
8079
|
+
takeBatch() {
|
|
8080
|
+
const batch = this.entries;
|
|
8081
|
+
this.clear();
|
|
8082
|
+
return batch;
|
|
8083
|
+
}
|
|
8084
|
+
clear() {
|
|
8085
|
+
this.entries = [];
|
|
8086
|
+
this.warningsRaisedThisBatch.clear();
|
|
8087
|
+
}
|
|
8088
|
+
warningsOfKeeping(admission) {
|
|
8089
|
+
switch (admission.outcome) {
|
|
8090
|
+
case "dropped": return admission.warnings;
|
|
8091
|
+
case "admitted":
|
|
8092
|
+
if (this.entries.length >= 1e3) return ["batch-already-full"];
|
|
8093
|
+
this.entries.push(admission.entry);
|
|
8094
|
+
return admission.warnings;
|
|
8095
|
+
}
|
|
8096
|
+
}
|
|
8097
|
+
isFirstThisBatch(warning) {
|
|
8098
|
+
if (this.warningsRaisedThisBatch.has(warning)) return false;
|
|
8099
|
+
this.warningsRaisedThisBatch.add(warning);
|
|
8100
|
+
return true;
|
|
8101
|
+
}
|
|
8102
|
+
};
|
|
8103
|
+
//#endregion
|
|
7902
8104
|
//#region ../shared/src/telemetry/TelemetryEventCollector.ts
|
|
7903
8105
|
var TelemetryEventCollector = class {
|
|
7904
8106
|
logger;
|
|
7905
8107
|
evaluationEventQueue;
|
|
7906
8108
|
aggregator = new EventAggregator();
|
|
8109
|
+
trackedEventQueue = new TrackedEventQueue();
|
|
7907
8110
|
flushIntervalDelay;
|
|
7908
8111
|
flushTimeout;
|
|
7909
8112
|
collectEvents = true;
|
|
@@ -7920,6 +8123,10 @@ var TelemetryEventCollector = class {
|
|
|
7920
8123
|
this.started = true;
|
|
7921
8124
|
this.flushTimeout = setTimeout(() => this.flushAndScheduleNext(), this.initialFlushIntervalDelay);
|
|
7922
8125
|
}
|
|
8126
|
+
trackedEvent(admission) {
|
|
8127
|
+
if (!this.collectEvents) return;
|
|
8128
|
+
logBatchWarnings(this.logger, this.trackedEventQueue.add(admission));
|
|
8129
|
+
}
|
|
7923
8130
|
async flushAndScheduleNext() {
|
|
7924
8131
|
if (!this.collectEvents) return;
|
|
7925
8132
|
let response;
|
|
@@ -7953,6 +8160,7 @@ var TelemetryEventCollector = class {
|
|
|
7953
8160
|
this.logger.warn("[TelemetryEventCollector] Error flushing telemetry events during close: ", error);
|
|
7954
8161
|
}
|
|
7955
8162
|
this.evaluationEventQueue.clear();
|
|
8163
|
+
this.trackedEventQueue.clear();
|
|
7956
8164
|
}
|
|
7957
8165
|
dispose() {
|
|
7958
8166
|
this.close();
|
|
@@ -8029,8 +8237,7 @@ var ServerTelemetryEventCollector = class extends TelemetryEventCollector {
|
|
|
8029
8237
|
evaluatedConfig(payload) {
|
|
8030
8238
|
if (!this.collectEvents) return;
|
|
8031
8239
|
const context = payload.context ?? void 0;
|
|
8032
|
-
const contextKind =
|
|
8033
|
-
const contextId = context?.anonymous ? void 0 : context?.id;
|
|
8240
|
+
const { contextKind, contextIdentifier: contextId } = reportedContextOf(context);
|
|
8034
8241
|
if (contextId) this.contexts.set(`${contextKind}:${contextId}`, {
|
|
8035
8242
|
...context,
|
|
8036
8243
|
kind: contextKind
|
|
@@ -8038,7 +8245,7 @@ var ServerTelemetryEventCollector = class extends TelemetryEventCollector {
|
|
|
8038
8245
|
const event = {
|
|
8039
8246
|
...payload.evaluation,
|
|
8040
8247
|
contextId,
|
|
8041
|
-
contextKind
|
|
8248
|
+
contextKind
|
|
8042
8249
|
};
|
|
8043
8250
|
this.evaluationEventQueue.push(this.sanitizeEvaluatedConfigEvent(event));
|
|
8044
8251
|
}
|
|
@@ -8077,7 +8284,10 @@ var ServerTelemetryEventCollector = class extends TelemetryEventCollector {
|
|
|
8077
8284
|
const contextsSnapshot = this.snapshotContexts();
|
|
8078
8285
|
return await this.reporter?.report({
|
|
8079
8286
|
context: this._context,
|
|
8080
|
-
discreteEvents: {
|
|
8287
|
+
discreteEvents: {
|
|
8288
|
+
capturedContexts: contextsSnapshot.contexts,
|
|
8289
|
+
trackedEvents: this.trackedEventQueue.takeBatch()
|
|
8290
|
+
},
|
|
8081
8291
|
aggregatedEvents: {
|
|
8082
8292
|
evaluatedConfig: this.aggregator.aggregate(evaluationSnapshot),
|
|
8083
8293
|
invalidContext: this.invalidContextSubmissions.takeSnapshot()
|
|
@@ -8095,6 +8305,7 @@ const discardingTelemetryClient = {
|
|
|
8095
8305
|
start: () => {},
|
|
8096
8306
|
evaluatedConfig: () => {},
|
|
8097
8307
|
recordInvalidContext: () => "new-kind-sample",
|
|
8308
|
+
trackedEvent: () => {},
|
|
8098
8309
|
close: async () => {}
|
|
8099
8310
|
};
|
|
8100
8311
|
//#endregion
|
|
@@ -8337,11 +8548,13 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
8337
8548
|
evaluationOf(configKey, configDefinition, defaultValue, suppliedContext) {
|
|
8338
8549
|
const context = this.contextToEvaluate(suppliedContext);
|
|
8339
8550
|
if (configDefinition) {
|
|
8340
|
-
const
|
|
8551
|
+
const explanation = this.configEvaluator.explain(configDefinition, {
|
|
8341
8552
|
context,
|
|
8342
8553
|
metadata: this.metaContext
|
|
8343
8554
|
}, this.configSet?.segments);
|
|
8555
|
+
const configState = servedConfigState(configDefinition, explanation);
|
|
8344
8556
|
const parseResult = parseConfigValue(configState, defaultValue);
|
|
8557
|
+
const reason = parseResult.usedDefault ? parseResult.reason : explanation.reason;
|
|
8345
8558
|
this.usageEventCollector.evaluatedConfig({
|
|
8346
8559
|
context,
|
|
8347
8560
|
evaluation: {
|
|
@@ -8352,15 +8565,19 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
8352
8565
|
evaluatedValue: parseResult.parsedValue,
|
|
8353
8566
|
evaluatedValueId: parseResult.parsedValueId,
|
|
8354
8567
|
usedDefault: parseResult.usedDefault,
|
|
8355
|
-
evaluationReason:
|
|
8568
|
+
evaluationReason: reason,
|
|
8569
|
+
ruleId: parseResult.ruleId,
|
|
8570
|
+
shareId: parseResult.shareId,
|
|
8571
|
+
variationId: parseResult.variation?.id
|
|
8356
8572
|
}
|
|
8357
8573
|
});
|
|
8358
8574
|
const evaluation = {
|
|
8359
8575
|
key: configKey,
|
|
8360
8576
|
value: parseResult.parsedValue,
|
|
8361
8577
|
valueId: parseResult.parsedValueId ?? void 0,
|
|
8578
|
+
variation: parseResult.variation,
|
|
8362
8579
|
isDefaultValue: parseResult.usedDefault,
|
|
8363
|
-
reason
|
|
8580
|
+
reason,
|
|
8364
8581
|
context
|
|
8365
8582
|
};
|
|
8366
8583
|
this.dispatchEvaluationEvent(evaluation);
|
|
@@ -8391,6 +8608,24 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
|
|
|
8391
8608
|
return evaluation;
|
|
8392
8609
|
}
|
|
8393
8610
|
}
|
|
8611
|
+
track(eventName, context, options) {
|
|
8612
|
+
switch (this.connectionPlan.kind) {
|
|
8613
|
+
case "stay-offline": return;
|
|
8614
|
+
case "connect":
|
|
8615
|
+
try {
|
|
8616
|
+
const admittedContext = this.contextToEvaluate(context);
|
|
8617
|
+
this.usageEventCollector.trackedEvent(admitTrackedEvent({
|
|
8618
|
+
name: eventName,
|
|
8619
|
+
context: admittedContext,
|
|
8620
|
+
options,
|
|
8621
|
+
happenedAt: /* @__PURE__ */ new Date()
|
|
8622
|
+
}), admittedContext);
|
|
8623
|
+
} catch (error) {
|
|
8624
|
+
this.logger.warn("[ConfigDirectorClient] A tracked event was not reported because it could not be read: ", error);
|
|
8625
|
+
}
|
|
8626
|
+
return;
|
|
8627
|
+
}
|
|
8628
|
+
}
|
|
8394
8629
|
contextToEvaluate(suppliedContext) {
|
|
8395
8630
|
const admission = admitContext(suppliedContext);
|
|
8396
8631
|
switch (admission.outcome) {
|
|
@@ -8467,6 +8702,7 @@ var plugin_default = defineNitroPlugin((nitroApp) => {
|
|
|
8467
8702
|
const runtimeConfig = useRuntimeConfig();
|
|
8468
8703
|
const logger = createDefaultLogger(runtimeConfig.configdirector?.logLevel);
|
|
8469
8704
|
const { serverSdkKey, baseUrl, connection } = runtimeConfig.configdirector;
|
|
8705
|
+
const { appName, appVersion } = runtimeConfig.public.configdirector;
|
|
8470
8706
|
const connectionMode = connection?.mode || "streaming";
|
|
8471
8707
|
if (connectionMode !== "offline" && !serverSdkKey) {
|
|
8472
8708
|
const message = "The ConfigDirector serverSdkKey must be configured for the plugin to initialize. You can provide it in nuxt.config.ts under 'runtimeConfig.configdirector.serverSdkKey' or as a runtime environment variable named NUXT_CONFIGDIRECTOR_SERVER_SDK_KEY";
|
|
@@ -8476,9 +8712,13 @@ var plugin_default = defineNitroPlugin((nitroApp) => {
|
|
|
8476
8712
|
logger.debug("Initializing ConfigDirector Nitro plugin");
|
|
8477
8713
|
const client = new DefaultConfigDirectorClient(serverSdkKey || void 0, {
|
|
8478
8714
|
sdkName: "nuxt-sdk",
|
|
8479
|
-
sdkVersion: "1.
|
|
8715
|
+
sdkVersion: "1.14.0"
|
|
8480
8716
|
}, {
|
|
8481
8717
|
logger,
|
|
8718
|
+
metadata: {
|
|
8719
|
+
appName,
|
|
8720
|
+
appVersion
|
|
8721
|
+
},
|
|
8482
8722
|
connection: {
|
|
8483
8723
|
url: baseUrl || void 0,
|
|
8484
8724
|
mode: connectionMode,
|