@ops-ai/react-router-toggly 1.2.0 → 1.5.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/CHANGELOG.md +38 -0
- package/dist/client.cjs +106 -22
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +5 -2
- package/dist/client.d.ts +5 -2
- package/dist/client.js +108 -24
- package/dist/client.js.map +1 -1
- package/dist/server.cjs +94 -48
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +86 -48
- package/dist/server.js.map +1 -1
- package/dist/telemetry/grpc.cjs +1 -1
- package/dist/telemetry/grpc.cjs.map +1 -1
- package/dist/telemetry/grpc.js +1 -1
- package/dist/telemetry/grpc.js.map +1 -1
- package/package.json +4 -3
- package/proto/usage.proto +3 -0
package/dist/server.cjs
CHANGED
|
@@ -11,6 +11,7 @@ var fs = require('fs');
|
|
|
11
11
|
var path = require('path');
|
|
12
12
|
var url = require('url');
|
|
13
13
|
var reactRouter = require('react-router');
|
|
14
|
+
var togglySegments = require('@ops-ai/toggly-segments');
|
|
14
15
|
|
|
15
16
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
16
17
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -212,7 +213,15 @@ var MAX_UNIQUE_USER_HASHES_PER_FEATURE = 1e4;
|
|
|
212
213
|
var MAX_APPLICATION_UNIQUE_USER_HASHES = 1e4;
|
|
213
214
|
var MAX_FEATURES_PER_BATCH = 500;
|
|
214
215
|
function emptyVariant() {
|
|
215
|
-
return {
|
|
216
|
+
return {
|
|
217
|
+
checkCount: 0,
|
|
218
|
+
requestCount: 0,
|
|
219
|
+
usedCount: 0,
|
|
220
|
+
viewedCount: 0,
|
|
221
|
+
errorCount: 0,
|
|
222
|
+
durationSumMs: 0,
|
|
223
|
+
errorDurationSumMs: 0
|
|
224
|
+
};
|
|
216
225
|
}
|
|
217
226
|
function emptyFeature() {
|
|
218
227
|
return {
|
|
@@ -324,6 +333,32 @@ var UsageBatcher = class {
|
|
|
324
333
|
this.addHashCapped(agg.uniqueViewedUserHashes, hash, this.maxUniqueHashesPerFeature);
|
|
325
334
|
}
|
|
326
335
|
}
|
|
336
|
+
recordUsageError(feature, _identity, variant = "enabled", count = 1) {
|
|
337
|
+
if (count <= 0) return;
|
|
338
|
+
const agg = this.get(feature);
|
|
339
|
+
if (!agg) return;
|
|
340
|
+
this.getVariant(agg, variant).errorCount += count;
|
|
341
|
+
}
|
|
342
|
+
recordUsageDuration(feature, durationMs, _identity, variant = "enabled", failed = false) {
|
|
343
|
+
if (!Number.isFinite(durationMs) || durationMs <= 0) return;
|
|
344
|
+
const ms = Math.floor(durationMs);
|
|
345
|
+
const agg = this.get(feature);
|
|
346
|
+
if (!agg) return;
|
|
347
|
+
const stats = this.getVariant(agg, variant);
|
|
348
|
+
if (failed) stats.errorDurationSumMs += ms;
|
|
349
|
+
else stats.durationSumMs += ms;
|
|
350
|
+
}
|
|
351
|
+
recordUsageScopeOutcome(feature, outcome, identity, variant = "enabled") {
|
|
352
|
+
if (outcome.cancelled) return;
|
|
353
|
+
if (outcome.failed) {
|
|
354
|
+
this.recordUsageError(feature, identity, variant);
|
|
355
|
+
if (outcome.durationMs != null) {
|
|
356
|
+
this.recordUsageDuration(feature, outcome.durationMs, identity, variant, true);
|
|
357
|
+
}
|
|
358
|
+
} else if (outcome.durationMs != null) {
|
|
359
|
+
this.recordUsageDuration(feature, outcome.durationMs, identity, variant, false);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
327
362
|
isEmpty() {
|
|
328
363
|
return this.perFeature.size === 0 && this.appUnique.size === 0 && this.definitionCacheHits === 0 && this.definitionCacheMisses === 0;
|
|
329
364
|
}
|
|
@@ -333,10 +368,7 @@ var UsageBatcher = class {
|
|
|
333
368
|
featureCount() {
|
|
334
369
|
return this.perFeature.size;
|
|
335
370
|
}
|
|
336
|
-
|
|
337
|
-
if (this.isEmpty()) {
|
|
338
|
-
return null;
|
|
339
|
-
}
|
|
371
|
+
buildPayload() {
|
|
340
372
|
const payload = {
|
|
341
373
|
appKey: this.appKey,
|
|
342
374
|
environment: this.environment,
|
|
@@ -346,57 +378,60 @@ var UsageBatcher = class {
|
|
|
346
378
|
uniqueUserHashes: [...this.appUnique],
|
|
347
379
|
processStartTime: toProtobufTimestamp(this.processStartTime)
|
|
348
380
|
};
|
|
349
|
-
if (this.instanceName)
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
if (this.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
381
|
+
if (this.instanceName) payload.instanceName = this.instanceName;
|
|
382
|
+
if (this.appVersion) payload.appVersion = this.appVersion;
|
|
383
|
+
if (this.definitionCacheHits > 0) payload.definitionCacheHits = this.definitionCacheHits;
|
|
384
|
+
if (this.definitionCacheMisses > 0) payload.definitionCacheMisses = this.definitionCacheMisses;
|
|
385
|
+
return payload;
|
|
386
|
+
}
|
|
387
|
+
appendFeatureStat(payload, snapshots, feature, agg) {
|
|
388
|
+
const variantStats = {};
|
|
389
|
+
for (const [name, stats] of agg.variantStats) {
|
|
390
|
+
if (stats.checkCount > 0 || stats.requestCount > 0 || stats.usedCount > 0 || stats.viewedCount > 0 || stats.errorCount > 0 || stats.durationSumMs > 0 || stats.errorDurationSumMs > 0) {
|
|
391
|
+
variantStats[name] = { ...stats };
|
|
392
|
+
}
|
|
360
393
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
394
|
+
if (agg.uniqueUsersEnabled.size > 0) snapshots.uniqueUsersEnabled[feature] = [...agg.uniqueUsersEnabled];
|
|
395
|
+
if (agg.uniqueUsersDisabled.size > 0) snapshots.uniqueUsersDisabled[feature] = [...agg.uniqueUsersDisabled];
|
|
396
|
+
if (agg.uniqueUsersUsed.size > 0) snapshots.uniqueUsersUsed[feature] = [...agg.uniqueUsersUsed];
|
|
397
|
+
payload.stats.push({
|
|
398
|
+
feature,
|
|
399
|
+
uniqueContextIdentifierEnabledCount: agg.uniqueUsersEnabled.size,
|
|
400
|
+
uniqueContextIdentifierDisabledCount: agg.uniqueUsersDisabled.size,
|
|
401
|
+
uniqueUsersUsedCount: agg.uniqueUsersUsed.size,
|
|
402
|
+
uniqueUserHashes: [...agg.uniqueUserHashes],
|
|
403
|
+
uniqueViewedUserHashes: [...agg.uniqueViewedUserHashes],
|
|
404
|
+
variantStats
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
buildIdentitySnapshots(payload) {
|
|
408
|
+
const snapshots = {
|
|
409
|
+
uniqueUsersEnabled: {},
|
|
410
|
+
uniqueUsersDisabled: {},
|
|
411
|
+
uniqueUsersUsed: {}
|
|
412
|
+
};
|
|
364
413
|
for (const [feature, agg] of this.perFeature) {
|
|
365
|
-
|
|
366
|
-
for (const [name, stats] of agg.variantStats) {
|
|
367
|
-
if (stats.checkCount > 0 || stats.requestCount > 0 || stats.usedCount > 0 || stats.viewedCount > 0) {
|
|
368
|
-
variantStats[name] = { ...stats };
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
if (agg.uniqueUsersEnabled.size > 0) {
|
|
372
|
-
uniqueUsersEnabled[feature] = [...agg.uniqueUsersEnabled];
|
|
373
|
-
}
|
|
374
|
-
if (agg.uniqueUsersDisabled.size > 0) {
|
|
375
|
-
uniqueUsersDisabled[feature] = [...agg.uniqueUsersDisabled];
|
|
376
|
-
}
|
|
377
|
-
if (agg.uniqueUsersUsed.size > 0) {
|
|
378
|
-
uniqueUsersUsed[feature] = [...agg.uniqueUsersUsed];
|
|
379
|
-
}
|
|
380
|
-
payload.stats.push({
|
|
381
|
-
feature,
|
|
382
|
-
uniqueContextIdentifierEnabledCount: agg.uniqueUsersEnabled.size,
|
|
383
|
-
uniqueContextIdentifierDisabledCount: agg.uniqueUsersDisabled.size,
|
|
384
|
-
uniqueUsersUsedCount: agg.uniqueUsersUsed.size,
|
|
385
|
-
uniqueUserHashes: [...agg.uniqueUserHashes],
|
|
386
|
-
uniqueViewedUserHashes: [...agg.uniqueViewedUserHashes],
|
|
387
|
-
variantStats
|
|
388
|
-
});
|
|
414
|
+
this.appendFeatureStat(payload, snapshots, feature, agg);
|
|
389
415
|
}
|
|
416
|
+
return snapshots;
|
|
417
|
+
}
|
|
418
|
+
reset() {
|
|
390
419
|
this.perFeature = /* @__PURE__ */ new Map();
|
|
391
420
|
this.appUnique = /* @__PURE__ */ new Set();
|
|
392
421
|
this.droppedFeatures = false;
|
|
393
422
|
this.definitionCacheHits = 0;
|
|
394
423
|
this.definitionCacheMisses = 0;
|
|
424
|
+
}
|
|
425
|
+
buildAndReset() {
|
|
426
|
+
if (this.isEmpty()) {
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
const payload = this.buildPayload();
|
|
430
|
+
const snapshots = this.buildIdentitySnapshots(payload);
|
|
431
|
+
this.reset();
|
|
395
432
|
return {
|
|
396
433
|
payload,
|
|
397
|
-
|
|
398
|
-
uniqueUsersDisabled,
|
|
399
|
-
uniqueUsersUsed
|
|
434
|
+
...snapshots
|
|
400
435
|
};
|
|
401
436
|
}
|
|
402
437
|
restoreFromBundle(bundle) {
|
|
@@ -417,6 +452,9 @@ var UsageBatcher = class {
|
|
|
417
452
|
target.requestCount += vs.requestCount ?? 0;
|
|
418
453
|
target.usedCount += vs.usedCount ?? 0;
|
|
419
454
|
target.viewedCount += vs.viewedCount ?? 0;
|
|
455
|
+
target.errorCount += vs.errorCount ?? 0;
|
|
456
|
+
target.durationSumMs += vs.durationSumMs ?? 0;
|
|
457
|
+
target.errorDurationSumMs += vs.errorDurationSumMs ?? 0;
|
|
420
458
|
}
|
|
421
459
|
for (const hash of stat.uniqueUserHashes ?? []) {
|
|
422
460
|
this.addHashCapped(agg.uniqueUserHashes, hash, this.maxUniqueHashesPerFeature);
|
|
@@ -587,7 +625,7 @@ var MetricsBatcher = class {
|
|
|
587
625
|
|
|
588
626
|
// src/core/sdk-identity.ts
|
|
589
627
|
var SDK_ID = "react-router";
|
|
590
|
-
var SDK_VERSION = "1.
|
|
628
|
+
var SDK_VERSION = "1.5.0";
|
|
591
629
|
function sdkUserAgent() {
|
|
592
630
|
return `toggly-${SDK_ID}/${SDK_VERSION}`;
|
|
593
631
|
}
|
|
@@ -1107,7 +1145,7 @@ async function extractEvalContext(request, providers = {}) {
|
|
|
1107
1145
|
|
|
1108
1146
|
// src/server/sdk-identity.ts
|
|
1109
1147
|
var SDK_ID2 = "react-router";
|
|
1110
|
-
var SDK_VERSION2 = "1.
|
|
1148
|
+
var SDK_VERSION2 = "1.5.0";
|
|
1111
1149
|
var SDK_HEADER_ID = "X-Toggly-Sdk";
|
|
1112
1150
|
var SDK_HEADER_VERSION = "X-Toggly-Sdk-Version";
|
|
1113
1151
|
function sdkUserAgent2() {
|
|
@@ -2449,6 +2487,14 @@ Object.defineProperty(exports, "fromHttpRequest", {
|
|
|
2449
2487
|
enumerable: true,
|
|
2450
2488
|
get: function () { return togglyEval.fromHttpRequest; }
|
|
2451
2489
|
});
|
|
2490
|
+
Object.defineProperty(exports, "SegmentMembershipError", {
|
|
2491
|
+
enumerable: true,
|
|
2492
|
+
get: function () { return togglySegments.SegmentMembershipError; }
|
|
2493
|
+
});
|
|
2494
|
+
Object.defineProperty(exports, "createSegmentMembershipClient", {
|
|
2495
|
+
enumerable: true,
|
|
2496
|
+
get: function () { return togglySegments.createSegmentMembershipClient; }
|
|
2497
|
+
});
|
|
2452
2498
|
exports.HEADERS = HEADERS;
|
|
2453
2499
|
exports.STORAGE_KEYS = STORAGE_KEYS;
|
|
2454
2500
|
exports.TOGGLY_LOADER_KEY = TOGGLY_LOADER_KEY;
|