@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.
Files changed (27) hide show
  1. package/dist/module.d.mts +43 -4
  2. package/dist/module.json +1 -1
  3. package/dist/runtime/app/composables/useConfigDirectorClient.d.mts +1 -1
  4. package/dist/runtime/app/composables/useConfigDirectorClient.d.ts +1 -1
  5. package/dist/runtime/app/composables/useConfigDirectorClientHooks.d.mts +1 -1
  6. package/dist/runtime/app/composables/useConfigDirectorClientHooks.d.ts +1 -1
  7. package/dist/runtime/app/composables/useConfigDirectorContext.d.mts +1 -1
  8. package/dist/runtime/app/composables/useConfigDirectorContext.d.ts +1 -1
  9. package/dist/runtime/app/composables/useConfigDirectorValue.d.mts +1 -1
  10. package/dist/runtime/app/composables/useConfigDirectorValue.d.ts +1 -1
  11. package/dist/runtime/{native-values-CfhP0yLS.d.mts → native-values-Cq3SCmEH.d.mts} +49 -4
  12. package/dist/runtime/nitro/offline-values.d.mts +1 -1
  13. package/dist/runtime/nitro/offline-values.d.ts +1 -1
  14. package/dist/runtime/nitro/plugin.d.mts +9 -2
  15. package/dist/runtime/nitro/plugin.d.ts +9 -2
  16. package/dist/runtime/nitro/plugin.mjs +319 -82
  17. package/dist/runtime/plugin.client.mjs +191 -3
  18. package/dist/runtime/plugin.server.mjs +3 -0
  19. package/dist/runtime/server/composables/useConfigDirectorServerClient.d.mts +1 -1
  20. package/dist/runtime/server/composables/useConfigDirectorServerClient.d.ts +1 -1
  21. package/dist/runtime/server/composables/useConfigDirectorServerHooks.d.mts +1 -1
  22. package/dist/runtime/server/composables/useConfigDirectorServerHooks.d.ts +1 -1
  23. package/dist/runtime/{types-BvqduMQP.d.mts → types-BNw2c3C0.d.mts} +17 -3
  24. package/dist/runtime/{types-qDEc6g8R.d.mts → types-CYquNKWW.d.mts} +18 -3
  25. package/dist/testing.d.mts +78 -7
  26. package/dist/testing.mjs +158 -5
  27. 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
- const explanation = this.explain(config, context, segments);
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. `evaluate` is this walk with
7268
- * only the value and its value ID kept, so the two cannot disagree. `segments` is the payload's
7269
- * segments map, which a segment condition looks its segment up in; a segment it does not hold
7270
- * never matches.
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((a, b) => (a.order ?? Number.MAX_SAFE_INTEGER) - (b.order ?? Number.MAX_SAFE_INTEGER));
7274
- const explanations = [];
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
- if (served) {
7278
- explanations.push({
7279
- ruleId: rule.id,
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
- if (served) return {
7294
- value: served.value,
7295
- valueId: served.valueId,
7296
- servedBy: {
7297
- kind: "rule",
7298
- ruleId: served.ruleId
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: explanations
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 served;
7318
- if (rule.type == "percentage") served = this.explainPercentage(rule.percentages ?? [], config, context, explanation);
7319
- else if (rule.type == "conditional") served = this.explainConditionalRule(rule, config, context, segments, explanation);
7320
- if (served !== void 0) explanation.outcome = "matched";
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
- served
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
- served: void 0
7357
+ serving: NOT_MATCHED
7339
7358
  };
7340
7359
  }
7341
7360
  }
7342
- explainPercentage(percentages, config, context, explanation) {
7361
+ explainRollout(rule, config, context, explanation) {
7362
+ if (rule.percentages == null) return NOT_MATCHED;
7343
7363
  const identifier = context?.context?.id ?? void 0;
7344
- const assignedPercentage = identifier === void 0 ? 0 : assignPercentage({
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 sum = 0;
7351
- let selected = void 0;
7352
- for (const percentage of percentages) {
7353
- const to = sum + percentage.percentage;
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: sum,
7357
- to,
7377
+ from: shareStart,
7378
+ to: shareEnd,
7358
7379
  value: percentage.value?.toString()
7359
7380
  });
7360
- if (selected === void 0 && assignedPercentage < to) selected = percentage;
7361
- sum = to;
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: selected?.id
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 failed = false;
7406
+ let aConditionDidNotMatch = false;
7377
7407
  for (const condition of rule.conditions ?? []) {
7378
- if (failed) {
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
- failed = checked.outcome !== "matched";
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 (failed) return;
7390
- if (rule.target == "value") return rule.value != null ? {
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 {
@@ -7757,6 +7822,7 @@ const isDroppedEventsEmpty = (droppedEvents) => {
7757
7822
  };
7758
7823
  //#endregion
7759
7824
  //#region ../js-server-sdk/src/telemetry/ServerEventReporter.ts
7825
+ const REPORT_TOO_LARGE_STATUS = 413;
7760
7826
  var ServerEventReporter = class {
7761
7827
  sdkKey;
7762
7828
  sdkIdentity;
@@ -7807,6 +7873,7 @@ var ServerEventReporter = class {
7807
7873
  }, this.logger);
7808
7874
  const isFatalError = this.isStatusFatal(response.status);
7809
7875
  if (isFatalError) this.logger.warn(`[EventReporter] Received a fatal status response (${response.status}) from the telemetry endpoint. No more telemetry data will be sent.`);
7876
+ else if (response.status === REPORT_TOO_LARGE_STATUS) this.logger.warn(`[EventReporter] The telemetry endpoint responded with status ${response.status}. The events in this report were discarded.`);
7810
7877
  return {
7811
7878
  success: response.ok,
7812
7879
  fatalError: isFatalError
@@ -7820,7 +7887,7 @@ var ServerEventReporter = class {
7820
7887
  }
7821
7888
  }
7822
7889
  isStatusFatal(status) {
7823
- return !!status && status >= 400 && status < 500 && status != 429;
7890
+ return !!status && status >= 400 && status < 500 && status != 429 && status != REPORT_TOO_LARGE_STATUS;
7824
7891
  }
7825
7892
  };
7826
7893
  //#endregion
@@ -7899,11 +7966,149 @@ var EventQueue = class {
7899
7966
  }
7900
7967
  };
7901
7968
  //#endregion
7969
+ //#region ../shared/src/utf8-byte-length.ts
7970
+ const isHighSurrogate = (codeUnit) => codeUnit >= 55296 && codeUnit <= 56319;
7971
+ const isLowSurrogate = (codeUnit) => codeUnit >= 56320 && codeUnit <= 57343;
7972
+ const utf8ByteLength = (text) => {
7973
+ let bytes = 0;
7974
+ for (let i = 0; i < text.length; i++) {
7975
+ const codeUnit = text.charCodeAt(i);
7976
+ if (codeUnit <= 127) bytes += 1;
7977
+ else if (codeUnit <= 2047) bytes += 2;
7978
+ else if (isHighSurrogate(codeUnit) && i + 1 < text.length && isLowSurrogate(text.charCodeAt(i + 1))) {
7979
+ bytes += 4;
7980
+ i++;
7981
+ } else bytes += 3;
7982
+ }
7983
+ return bytes;
7984
+ };
7985
+ //#endregion
7986
+ //#region ../shared/src/telemetry/reported-context.ts
7987
+ const USER_CONTEXT_KIND = "user";
7988
+ const reportedContextOf = (context) => {
7989
+ const contextIdentifier = context?.anonymous ? void 0 : context?.id;
7990
+ if (contextIdentifier === void 0) return {};
7991
+ return {
7992
+ contextKind: context?.kind ?? USER_CONTEXT_KIND,
7993
+ contextIdentifier
7994
+ };
7995
+ };
7996
+ //#endregion
7997
+ //#region ../shared/src/telemetry/tracked-events.ts
7998
+ const TRACKED_EVENTS_PER_BATCH = 1e3;
7999
+ const NAME_MAXIMUM_CHARACTERS = 150;
8000
+ const NAME_MAXIMUM_UTF16_UNITS = NAME_MAXIMUM_CHARACTERS * 2;
8001
+ const DETAILS_MAXIMUM_TOP_LEVEL_KEYS = 20;
8002
+ const DETAILS_MAXIMUM_JSON_BYTES = 1024;
8003
+ const trackedEventWarningMessages = {
8004
+ "name-outside-the-character-limit": `[ConfigDirectorClient] A tracked event was not reported because its name does not have 1 to ${NAME_MAXIMUM_CHARACTERS} characters.`,
8005
+ "value-not-a-finite-number": "[ConfigDirectorClient] A tracked event was reported without its value because the value is not a finite number.",
8006
+ "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.`,
8007
+ "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.`
8008
+ };
8009
+ const logBatchWarnings = (logger, warnings) => {
8010
+ for (const warning of warnings) logger.warn(`${trackedEventWarningMessages[warning]} Further tracked events like it are not logged until the next telemetry batch is sent.`);
8011
+ };
8012
+ const isGiven = (option) => option !== void 0 && option !== null;
8013
+ const isNonArrayObject = (candidate) => typeof candidate === "object" && candidate !== null && !Array.isArray(candidate);
8014
+ const isWithinTheCharacterLimit = (name) => typeof name === "string" && name.length >= 1 && name.length <= NAME_MAXIMUM_UTF16_UNITS && Array.from(name).length <= NAME_MAXIMUM_CHARACTERS;
8015
+ const reportableValueOf = (value) => {
8016
+ if (!isGiven(value)) return { status: "not-given" };
8017
+ if (typeof value === "number" && Number.isFinite(value)) return {
8018
+ status: "reportable",
8019
+ fields: { value }
8020
+ };
8021
+ return {
8022
+ status: "left-out",
8023
+ warning: "value-not-a-finite-number"
8024
+ };
8025
+ };
8026
+ const jsonCopyWithinTheLimits = (details) => {
8027
+ if (!isNonArrayObject(details)) return;
8028
+ try {
8029
+ const json = JSON.stringify(details);
8030
+ if (typeof json !== "string" || utf8ByteLength(json) > DETAILS_MAXIMUM_JSON_BYTES) return;
8031
+ const copy = JSON.parse(json);
8032
+ return isNonArrayObject(copy) && Object.keys(copy).length <= DETAILS_MAXIMUM_TOP_LEVEL_KEYS ? copy : void 0;
8033
+ } catch {
8034
+ return;
8035
+ }
8036
+ };
8037
+ const reportableDetailsOf = (details) => {
8038
+ if (!isGiven(details)) return { status: "not-given" };
8039
+ const jsonCopy = jsonCopyWithinTheLimits(details);
8040
+ if (jsonCopy === void 0) return {
8041
+ status: "left-out",
8042
+ warning: "details-not-reportable"
8043
+ };
8044
+ return {
8045
+ status: "reportable",
8046
+ fields: { details: jsonCopy }
8047
+ };
8048
+ };
8049
+ const fieldsOf = (option) => option.status === "reportable" ? option.fields : void 0;
8050
+ const warningsOf = (...options) => options.flatMap((option) => option.status === "left-out" ? [option.warning] : []);
8051
+ const admitTrackedEvent = (call) => {
8052
+ if (!isWithinTheCharacterLimit(call.name)) return {
8053
+ outcome: "dropped",
8054
+ warnings: ["name-outside-the-character-limit"]
8055
+ };
8056
+ const value = reportableValueOf(call.options?.value);
8057
+ const details = reportableDetailsOf(call.options?.details);
8058
+ return {
8059
+ outcome: "admitted",
8060
+ entry: {
8061
+ name: call.name,
8062
+ ...reportedContextOf(call.context),
8063
+ ...fieldsOf(value),
8064
+ ...fieldsOf(details),
8065
+ happenedAt: call.happenedAt.toISOString()
8066
+ },
8067
+ warnings: warningsOf(value, details)
8068
+ };
8069
+ };
8070
+ //#endregion
8071
+ //#region ../shared/src/telemetry/TrackedEventQueue.ts
8072
+ var TrackedEventQueue = class {
8073
+ entries = [];
8074
+ warningsRaisedThisBatch = /* @__PURE__ */ new Set();
8075
+ add(admission) {
8076
+ return this.warningsOfKeeping(admission).filter((warning) => this.isFirstThisBatch(warning));
8077
+ }
8078
+ absorb(entries) {
8079
+ this.entries.push(...entries);
8080
+ }
8081
+ takeBatch() {
8082
+ const batch = this.entries;
8083
+ this.clear();
8084
+ return batch;
8085
+ }
8086
+ clear() {
8087
+ this.entries = [];
8088
+ this.warningsRaisedThisBatch.clear();
8089
+ }
8090
+ warningsOfKeeping(admission) {
8091
+ switch (admission.outcome) {
8092
+ case "dropped": return admission.warnings;
8093
+ case "admitted":
8094
+ if (this.entries.length >= 1e3) return ["batch-already-full"];
8095
+ this.entries.push(admission.entry);
8096
+ return admission.warnings;
8097
+ }
8098
+ }
8099
+ isFirstThisBatch(warning) {
8100
+ if (this.warningsRaisedThisBatch.has(warning)) return false;
8101
+ this.warningsRaisedThisBatch.add(warning);
8102
+ return true;
8103
+ }
8104
+ };
8105
+ //#endregion
7902
8106
  //#region ../shared/src/telemetry/TelemetryEventCollector.ts
7903
8107
  var TelemetryEventCollector = class {
7904
8108
  logger;
7905
8109
  evaluationEventQueue;
7906
8110
  aggregator = new EventAggregator();
8111
+ trackedEventQueue = new TrackedEventQueue();
7907
8112
  flushIntervalDelay;
7908
8113
  flushTimeout;
7909
8114
  collectEvents = true;
@@ -7920,6 +8125,10 @@ var TelemetryEventCollector = class {
7920
8125
  this.started = true;
7921
8126
  this.flushTimeout = setTimeout(() => this.flushAndScheduleNext(), this.initialFlushIntervalDelay);
7922
8127
  }
8128
+ trackedEvent(admission) {
8129
+ if (!this.collectEvents) return;
8130
+ logBatchWarnings(this.logger, this.trackedEventQueue.add(admission));
8131
+ }
7923
8132
  async flushAndScheduleNext() {
7924
8133
  if (!this.collectEvents) return;
7925
8134
  let response;
@@ -7953,6 +8162,7 @@ var TelemetryEventCollector = class {
7953
8162
  this.logger.warn("[TelemetryEventCollector] Error flushing telemetry events during close: ", error);
7954
8163
  }
7955
8164
  this.evaluationEventQueue.clear();
8165
+ this.trackedEventQueue.clear();
7956
8166
  }
7957
8167
  dispose() {
7958
8168
  this.close();
@@ -8029,8 +8239,7 @@ var ServerTelemetryEventCollector = class extends TelemetryEventCollector {
8029
8239
  evaluatedConfig(payload) {
8030
8240
  if (!this.collectEvents) return;
8031
8241
  const context = payload.context ?? void 0;
8032
- const contextKind = effectiveContextKind({ context });
8033
- const contextId = context?.anonymous ? void 0 : context?.id;
8242
+ const { contextKind, contextIdentifier: contextId } = reportedContextOf(context);
8034
8243
  if (contextId) this.contexts.set(`${contextKind}:${contextId}`, {
8035
8244
  ...context,
8036
8245
  kind: contextKind
@@ -8038,7 +8247,7 @@ var ServerTelemetryEventCollector = class extends TelemetryEventCollector {
8038
8247
  const event = {
8039
8248
  ...payload.evaluation,
8040
8249
  contextId,
8041
- contextKind: contextId === void 0 ? void 0 : contextKind
8250
+ contextKind
8042
8251
  };
8043
8252
  this.evaluationEventQueue.push(this.sanitizeEvaluatedConfigEvent(event));
8044
8253
  }
@@ -8077,7 +8286,10 @@ var ServerTelemetryEventCollector = class extends TelemetryEventCollector {
8077
8286
  const contextsSnapshot = this.snapshotContexts();
8078
8287
  return await this.reporter?.report({
8079
8288
  context: this._context,
8080
- discreteEvents: { capturedContexts: contextsSnapshot.contexts },
8289
+ discreteEvents: {
8290
+ capturedContexts: contextsSnapshot.contexts,
8291
+ trackedEvents: this.trackedEventQueue.takeBatch()
8292
+ },
8081
8293
  aggregatedEvents: {
8082
8294
  evaluatedConfig: this.aggregator.aggregate(evaluationSnapshot),
8083
8295
  invalidContext: this.invalidContextSubmissions.takeSnapshot()
@@ -8095,6 +8307,7 @@ const discardingTelemetryClient = {
8095
8307
  start: () => {},
8096
8308
  evaluatedConfig: () => {},
8097
8309
  recordInvalidContext: () => "new-kind-sample",
8310
+ trackedEvent: () => {},
8098
8311
  close: async () => {}
8099
8312
  };
8100
8313
  //#endregion
@@ -8337,11 +8550,13 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
8337
8550
  evaluationOf(configKey, configDefinition, defaultValue, suppliedContext) {
8338
8551
  const context = this.contextToEvaluate(suppliedContext);
8339
8552
  if (configDefinition) {
8340
- const configState = this.configEvaluator.evaluate(configDefinition, {
8553
+ const explanation = this.configEvaluator.explain(configDefinition, {
8341
8554
  context,
8342
8555
  metadata: this.metaContext
8343
8556
  }, this.configSet?.segments);
8557
+ const configState = servedConfigState(configDefinition, explanation);
8344
8558
  const parseResult = parseConfigValue(configState, defaultValue);
8559
+ const reason = parseResult.usedDefault ? parseResult.reason : explanation.reason;
8345
8560
  this.usageEventCollector.evaluatedConfig({
8346
8561
  context,
8347
8562
  evaluation: {
@@ -8352,15 +8567,19 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
8352
8567
  evaluatedValue: parseResult.parsedValue,
8353
8568
  evaluatedValueId: parseResult.parsedValueId,
8354
8569
  usedDefault: parseResult.usedDefault,
8355
- evaluationReason: parseResult.reason
8570
+ evaluationReason: reason,
8571
+ ruleId: parseResult.ruleId,
8572
+ shareId: parseResult.shareId,
8573
+ variationId: parseResult.variation?.id
8356
8574
  }
8357
8575
  });
8358
8576
  const evaluation = {
8359
8577
  key: configKey,
8360
8578
  value: parseResult.parsedValue,
8361
8579
  valueId: parseResult.parsedValueId ?? void 0,
8580
+ variation: parseResult.variation,
8362
8581
  isDefaultValue: parseResult.usedDefault,
8363
- reason: parseResult.reason,
8582
+ reason,
8364
8583
  context
8365
8584
  };
8366
8585
  this.dispatchEvaluationEvent(evaluation);
@@ -8391,6 +8610,24 @@ var DefaultConfigDirectorClient = class DefaultConfigDirectorClient {
8391
8610
  return evaluation;
8392
8611
  }
8393
8612
  }
8613
+ track(eventName, context, options) {
8614
+ switch (this.connectionPlan.kind) {
8615
+ case "stay-offline": return;
8616
+ case "connect":
8617
+ try {
8618
+ const admittedContext = this.contextToEvaluate(context);
8619
+ this.usageEventCollector.trackedEvent(admitTrackedEvent({
8620
+ name: eventName,
8621
+ context: admittedContext,
8622
+ options,
8623
+ happenedAt: /* @__PURE__ */ new Date()
8624
+ }), admittedContext);
8625
+ } catch (error) {
8626
+ this.logger.warn("[ConfigDirectorClient] A tracked event was not reported because it could not be read: ", error);
8627
+ }
8628
+ return;
8629
+ }
8630
+ }
8394
8631
  contextToEvaluate(suppliedContext) {
8395
8632
  const admission = admitContext(suppliedContext);
8396
8633
  switch (admission.outcome) {
@@ -8477,7 +8714,7 @@ var plugin_default = defineNitroPlugin((nitroApp) => {
8477
8714
  logger.debug("Initializing ConfigDirector Nitro plugin");
8478
8715
  const client = new DefaultConfigDirectorClient(serverSdkKey || void 0, {
8479
8716
  sdkName: "nuxt-sdk",
8480
- sdkVersion: "1.13.2"
8717
+ sdkVersion: "1.14.1"
8481
8718
  }, {
8482
8719
  logger,
8483
8720
  metadata: {