@ops-ai/react-router-toggly 1.2.0 → 1.2.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/server.js CHANGED
@@ -325,10 +325,7 @@ var UsageBatcher = class {
325
325
  featureCount() {
326
326
  return this.perFeature.size;
327
327
  }
328
- buildAndReset() {
329
- if (this.isEmpty()) {
330
- return null;
331
- }
328
+ buildPayload() {
332
329
  const payload = {
333
330
  appKey: this.appKey,
334
331
  environment: this.environment,
@@ -338,57 +335,60 @@ var UsageBatcher = class {
338
335
  uniqueUserHashes: [...this.appUnique],
339
336
  processStartTime: toProtobufTimestamp(this.processStartTime)
340
337
  };
341
- if (this.instanceName) {
342
- payload.instanceName = this.instanceName;
343
- }
344
- if (this.appVersion) {
345
- payload.appVersion = this.appVersion;
346
- }
347
- if (this.definitionCacheHits > 0) {
348
- payload.definitionCacheHits = this.definitionCacheHits;
349
- }
350
- if (this.definitionCacheMisses > 0) {
351
- payload.definitionCacheMisses = this.definitionCacheMisses;
338
+ if (this.instanceName) payload.instanceName = this.instanceName;
339
+ if (this.appVersion) payload.appVersion = this.appVersion;
340
+ if (this.definitionCacheHits > 0) payload.definitionCacheHits = this.definitionCacheHits;
341
+ if (this.definitionCacheMisses > 0) payload.definitionCacheMisses = this.definitionCacheMisses;
342
+ return payload;
343
+ }
344
+ appendFeatureStat(payload, snapshots, feature, agg) {
345
+ const variantStats = {};
346
+ for (const [name, stats] of agg.variantStats) {
347
+ if (stats.checkCount > 0 || stats.requestCount > 0 || stats.usedCount > 0 || stats.viewedCount > 0) {
348
+ variantStats[name] = { ...stats };
349
+ }
352
350
  }
353
- const uniqueUsersEnabled = {};
354
- const uniqueUsersDisabled = {};
355
- const uniqueUsersUsed = {};
351
+ if (agg.uniqueUsersEnabled.size > 0) snapshots.uniqueUsersEnabled[feature] = [...agg.uniqueUsersEnabled];
352
+ if (agg.uniqueUsersDisabled.size > 0) snapshots.uniqueUsersDisabled[feature] = [...agg.uniqueUsersDisabled];
353
+ if (agg.uniqueUsersUsed.size > 0) snapshots.uniqueUsersUsed[feature] = [...agg.uniqueUsersUsed];
354
+ payload.stats.push({
355
+ feature,
356
+ uniqueContextIdentifierEnabledCount: agg.uniqueUsersEnabled.size,
357
+ uniqueContextIdentifierDisabledCount: agg.uniqueUsersDisabled.size,
358
+ uniqueUsersUsedCount: agg.uniqueUsersUsed.size,
359
+ uniqueUserHashes: [...agg.uniqueUserHashes],
360
+ uniqueViewedUserHashes: [...agg.uniqueViewedUserHashes],
361
+ variantStats
362
+ });
363
+ }
364
+ buildIdentitySnapshots(payload) {
365
+ const snapshots = {
366
+ uniqueUsersEnabled: {},
367
+ uniqueUsersDisabled: {},
368
+ uniqueUsersUsed: {}
369
+ };
356
370
  for (const [feature, agg] of this.perFeature) {
357
- const variantStats = {};
358
- for (const [name, stats] of agg.variantStats) {
359
- if (stats.checkCount > 0 || stats.requestCount > 0 || stats.usedCount > 0 || stats.viewedCount > 0) {
360
- variantStats[name] = { ...stats };
361
- }
362
- }
363
- if (agg.uniqueUsersEnabled.size > 0) {
364
- uniqueUsersEnabled[feature] = [...agg.uniqueUsersEnabled];
365
- }
366
- if (agg.uniqueUsersDisabled.size > 0) {
367
- uniqueUsersDisabled[feature] = [...agg.uniqueUsersDisabled];
368
- }
369
- if (agg.uniqueUsersUsed.size > 0) {
370
- uniqueUsersUsed[feature] = [...agg.uniqueUsersUsed];
371
- }
372
- payload.stats.push({
373
- feature,
374
- uniqueContextIdentifierEnabledCount: agg.uniqueUsersEnabled.size,
375
- uniqueContextIdentifierDisabledCount: agg.uniqueUsersDisabled.size,
376
- uniqueUsersUsedCount: agg.uniqueUsersUsed.size,
377
- uniqueUserHashes: [...agg.uniqueUserHashes],
378
- uniqueViewedUserHashes: [...agg.uniqueViewedUserHashes],
379
- variantStats
380
- });
371
+ this.appendFeatureStat(payload, snapshots, feature, agg);
381
372
  }
373
+ return snapshots;
374
+ }
375
+ reset() {
382
376
  this.perFeature = /* @__PURE__ */ new Map();
383
377
  this.appUnique = /* @__PURE__ */ new Set();
384
378
  this.droppedFeatures = false;
385
379
  this.definitionCacheHits = 0;
386
380
  this.definitionCacheMisses = 0;
381
+ }
382
+ buildAndReset() {
383
+ if (this.isEmpty()) {
384
+ return null;
385
+ }
386
+ const payload = this.buildPayload();
387
+ const snapshots = this.buildIdentitySnapshots(payload);
388
+ this.reset();
387
389
  return {
388
390
  payload,
389
- uniqueUsersEnabled,
390
- uniqueUsersDisabled,
391
- uniqueUsersUsed
391
+ ...snapshots
392
392
  };
393
393
  }
394
394
  restoreFromBundle(bundle) {
@@ -579,7 +579,7 @@ var MetricsBatcher = class {
579
579
 
580
580
  // src/core/sdk-identity.ts
581
581
  var SDK_ID = "react-router";
582
- var SDK_VERSION = "1.2.0";
582
+ var SDK_VERSION = "1.2.1";
583
583
  function sdkUserAgent() {
584
584
  return `toggly-${SDK_ID}/${SDK_VERSION}`;
585
585
  }
@@ -1099,7 +1099,7 @@ async function extractEvalContext(request, providers = {}) {
1099
1099
 
1100
1100
  // src/server/sdk-identity.ts
1101
1101
  var SDK_ID2 = "react-router";
1102
- var SDK_VERSION2 = "1.2.0";
1102
+ var SDK_VERSION2 = "1.2.1";
1103
1103
  var SDK_HEADER_ID = "X-Toggly-Sdk";
1104
1104
  var SDK_HEADER_VERSION = "X-Toggly-Sdk-Version";
1105
1105
  function sdkUserAgent2() {