@scalemule/nextjs 0.1.29 → 0.1.31

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.
@@ -12,13 +12,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
12
  var __getOwnPropNames = Object.getOwnPropertyNames;
13
13
  var __getProtoOf = Object.getPrototypeOf;
14
14
  var __hasOwnProp = Object.prototype.hasOwnProperty;
15
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
16
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
17
- }) : x)(function(x) {
18
- if (typeof require !== "undefined") return require.apply(this, arguments);
19
- throw Error('Dynamic require of "' + x + '" is not supported');
20
- });
21
- var __commonJS = (cb, mod) => function __require2() {
15
+ var __commonJS = (cb, mod) => function __require() {
22
16
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
23
17
  };
24
18
  var __copyProps = (to, from, except, desc) => {
@@ -34,13 +28,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
34
28
  // file that has been converted to a CommonJS file using a Babel-
35
29
  // compatible transform (i.e. "__esModule" has not been set), then set
36
30
  // "default" to the CommonJS "module.exports" for node compatibility.
37
- !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ __defProp(target, "default", { value: mod, enumerable: true }) ,
38
32
  mod
39
33
  ));
40
34
 
41
- // ../sdk/node_modules/semver/internal/constants.js
35
+ // node_modules/semver/internal/constants.js
42
36
  var require_constants = __commonJS({
43
- "../sdk/node_modules/semver/internal/constants.js"(exports$1, module) {
37
+ "node_modules/semver/internal/constants.js"(exports$1, module) {
44
38
  var SEMVER_SPEC_VERSION = "2.0.0";
45
39
  var MAX_LENGTH = 256;
46
40
  var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || /* istanbul ignore next */
@@ -69,18 +63,18 @@ var require_constants = __commonJS({
69
63
  }
70
64
  });
71
65
 
72
- // ../sdk/node_modules/semver/internal/debug.js
66
+ // node_modules/semver/internal/debug.js
73
67
  var require_debug = __commonJS({
74
- "../sdk/node_modules/semver/internal/debug.js"(exports$1, module) {
68
+ "node_modules/semver/internal/debug.js"(exports$1, module) {
75
69
  var debug = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {
76
70
  };
77
71
  module.exports = debug;
78
72
  }
79
73
  });
80
74
 
81
- // ../sdk/node_modules/semver/internal/re.js
75
+ // node_modules/semver/internal/re.js
82
76
  var require_re = __commonJS({
83
- "../sdk/node_modules/semver/internal/re.js"(exports$1, module) {
77
+ "node_modules/semver/internal/re.js"(exports$1, module) {
84
78
  var {
85
79
  MAX_SAFE_COMPONENT_LENGTH,
86
80
  MAX_SAFE_BUILD_LENGTH,
@@ -165,9 +159,9 @@ var require_re = __commonJS({
165
159
  }
166
160
  });
167
161
 
168
- // ../sdk/node_modules/semver/internal/parse-options.js
162
+ // node_modules/semver/internal/parse-options.js
169
163
  var require_parse_options = __commonJS({
170
- "../sdk/node_modules/semver/internal/parse-options.js"(exports$1, module) {
164
+ "node_modules/semver/internal/parse-options.js"(exports$1, module) {
171
165
  var looseOption = Object.freeze({ loose: true });
172
166
  var emptyOpts = Object.freeze({});
173
167
  var parseOptions = (options) => {
@@ -183,9 +177,9 @@ var require_parse_options = __commonJS({
183
177
  }
184
178
  });
185
179
 
186
- // ../sdk/node_modules/semver/internal/identifiers.js
180
+ // node_modules/semver/internal/identifiers.js
187
181
  var require_identifiers = __commonJS({
188
- "../sdk/node_modules/semver/internal/identifiers.js"(exports$1, module) {
182
+ "node_modules/semver/internal/identifiers.js"(exports$1, module) {
189
183
  var numeric = /^[0-9]+$/;
190
184
  var compareIdentifiers = (a, b) => {
191
185
  if (typeof a === "number" && typeof b === "number") {
@@ -207,9 +201,9 @@ var require_identifiers = __commonJS({
207
201
  }
208
202
  });
209
203
 
210
- // ../sdk/node_modules/semver/classes/semver.js
204
+ // node_modules/semver/classes/semver.js
211
205
  var require_semver = __commonJS({
212
- "../sdk/node_modules/semver/classes/semver.js"(exports$1, module) {
206
+ "node_modules/semver/classes/semver.js"(exports$1, module) {
213
207
  var debug = require_debug();
214
208
  var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
215
209
  var { safeRe: re, t } = require_re();
@@ -485,9 +479,9 @@ var require_semver = __commonJS({
485
479
  }
486
480
  });
487
481
 
488
- // ../sdk/node_modules/semver/functions/parse.js
482
+ // node_modules/semver/functions/parse.js
489
483
  var require_parse = __commonJS({
490
- "../sdk/node_modules/semver/functions/parse.js"(exports$1, module) {
484
+ "node_modules/semver/functions/parse.js"(exports$1, module) {
491
485
  var SemVer = require_semver();
492
486
  var parse = (version, options, throwErrors = false) => {
493
487
  if (version instanceof SemVer) {
@@ -506,9 +500,9 @@ var require_parse = __commonJS({
506
500
  }
507
501
  });
508
502
 
509
- // ../sdk/node_modules/semver/functions/valid.js
503
+ // node_modules/semver/functions/valid.js
510
504
  var require_valid = __commonJS({
511
- "../sdk/node_modules/semver/functions/valid.js"(exports$1, module) {
505
+ "node_modules/semver/functions/valid.js"(exports$1, module) {
512
506
  var parse = require_parse();
513
507
  var valid = (version, options) => {
514
508
  const v = parse(version, options);
@@ -518,9 +512,9 @@ var require_valid = __commonJS({
518
512
  }
519
513
  });
520
514
 
521
- // ../sdk/node_modules/semver/functions/clean.js
515
+ // node_modules/semver/functions/clean.js
522
516
  var require_clean = __commonJS({
523
- "../sdk/node_modules/semver/functions/clean.js"(exports$1, module) {
517
+ "node_modules/semver/functions/clean.js"(exports$1, module) {
524
518
  var parse = require_parse();
525
519
  var clean = (version, options) => {
526
520
  const s = parse(version.trim().replace(/^[=v]+/, ""), options);
@@ -530,9 +524,9 @@ var require_clean = __commonJS({
530
524
  }
531
525
  });
532
526
 
533
- // ../sdk/node_modules/semver/functions/inc.js
527
+ // node_modules/semver/functions/inc.js
534
528
  var require_inc = __commonJS({
535
- "../sdk/node_modules/semver/functions/inc.js"(exports$1, module) {
529
+ "node_modules/semver/functions/inc.js"(exports$1, module) {
536
530
  var SemVer = require_semver();
537
531
  var inc = (version, release, options, identifier, identifierBase) => {
538
532
  if (typeof options === "string") {
@@ -553,9 +547,9 @@ var require_inc = __commonJS({
553
547
  }
554
548
  });
555
549
 
556
- // ../sdk/node_modules/semver/functions/diff.js
550
+ // node_modules/semver/functions/diff.js
557
551
  var require_diff = __commonJS({
558
- "../sdk/node_modules/semver/functions/diff.js"(exports$1, module) {
552
+ "node_modules/semver/functions/diff.js"(exports$1, module) {
559
553
  var parse = require_parse();
560
554
  var diff = (version1, version2) => {
561
555
  const v1 = parse(version1, null, true);
@@ -596,36 +590,36 @@ var require_diff = __commonJS({
596
590
  }
597
591
  });
598
592
 
599
- // ../sdk/node_modules/semver/functions/major.js
593
+ // node_modules/semver/functions/major.js
600
594
  var require_major = __commonJS({
601
- "../sdk/node_modules/semver/functions/major.js"(exports$1, module) {
595
+ "node_modules/semver/functions/major.js"(exports$1, module) {
602
596
  var SemVer = require_semver();
603
597
  var major = (a, loose) => new SemVer(a, loose).major;
604
598
  module.exports = major;
605
599
  }
606
600
  });
607
601
 
608
- // ../sdk/node_modules/semver/functions/minor.js
602
+ // node_modules/semver/functions/minor.js
609
603
  var require_minor = __commonJS({
610
- "../sdk/node_modules/semver/functions/minor.js"(exports$1, module) {
604
+ "node_modules/semver/functions/minor.js"(exports$1, module) {
611
605
  var SemVer = require_semver();
612
606
  var minor = (a, loose) => new SemVer(a, loose).minor;
613
607
  module.exports = minor;
614
608
  }
615
609
  });
616
610
 
617
- // ../sdk/node_modules/semver/functions/patch.js
611
+ // node_modules/semver/functions/patch.js
618
612
  var require_patch = __commonJS({
619
- "../sdk/node_modules/semver/functions/patch.js"(exports$1, module) {
613
+ "node_modules/semver/functions/patch.js"(exports$1, module) {
620
614
  var SemVer = require_semver();
621
615
  var patch = (a, loose) => new SemVer(a, loose).patch;
622
616
  module.exports = patch;
623
617
  }
624
618
  });
625
619
 
626
- // ../sdk/node_modules/semver/functions/prerelease.js
620
+ // node_modules/semver/functions/prerelease.js
627
621
  var require_prerelease = __commonJS({
628
- "../sdk/node_modules/semver/functions/prerelease.js"(exports$1, module) {
622
+ "node_modules/semver/functions/prerelease.js"(exports$1, module) {
629
623
  var parse = require_parse();
630
624
  var prerelease = (version, options) => {
631
625
  const parsed = parse(version, options);
@@ -635,36 +629,36 @@ var require_prerelease = __commonJS({
635
629
  }
636
630
  });
637
631
 
638
- // ../sdk/node_modules/semver/functions/compare.js
632
+ // node_modules/semver/functions/compare.js
639
633
  var require_compare = __commonJS({
640
- "../sdk/node_modules/semver/functions/compare.js"(exports$1, module) {
634
+ "node_modules/semver/functions/compare.js"(exports$1, module) {
641
635
  var SemVer = require_semver();
642
636
  var compare = (a, b, loose) => new SemVer(a, loose).compare(new SemVer(b, loose));
643
637
  module.exports = compare;
644
638
  }
645
639
  });
646
640
 
647
- // ../sdk/node_modules/semver/functions/rcompare.js
641
+ // node_modules/semver/functions/rcompare.js
648
642
  var require_rcompare = __commonJS({
649
- "../sdk/node_modules/semver/functions/rcompare.js"(exports$1, module) {
643
+ "node_modules/semver/functions/rcompare.js"(exports$1, module) {
650
644
  var compare = require_compare();
651
645
  var rcompare = (a, b, loose) => compare(b, a, loose);
652
646
  module.exports = rcompare;
653
647
  }
654
648
  });
655
649
 
656
- // ../sdk/node_modules/semver/functions/compare-loose.js
650
+ // node_modules/semver/functions/compare-loose.js
657
651
  var require_compare_loose = __commonJS({
658
- "../sdk/node_modules/semver/functions/compare-loose.js"(exports$1, module) {
652
+ "node_modules/semver/functions/compare-loose.js"(exports$1, module) {
659
653
  var compare = require_compare();
660
654
  var compareLoose = (a, b) => compare(a, b, true);
661
655
  module.exports = compareLoose;
662
656
  }
663
657
  });
664
658
 
665
- // ../sdk/node_modules/semver/functions/compare-build.js
659
+ // node_modules/semver/functions/compare-build.js
666
660
  var require_compare_build = __commonJS({
667
- "../sdk/node_modules/semver/functions/compare-build.js"(exports$1, module) {
661
+ "node_modules/semver/functions/compare-build.js"(exports$1, module) {
668
662
  var SemVer = require_semver();
669
663
  var compareBuild = (a, b, loose) => {
670
664
  const versionA = new SemVer(a, loose);
@@ -675,81 +669,81 @@ var require_compare_build = __commonJS({
675
669
  }
676
670
  });
677
671
 
678
- // ../sdk/node_modules/semver/functions/sort.js
672
+ // node_modules/semver/functions/sort.js
679
673
  var require_sort = __commonJS({
680
- "../sdk/node_modules/semver/functions/sort.js"(exports$1, module) {
674
+ "node_modules/semver/functions/sort.js"(exports$1, module) {
681
675
  var compareBuild = require_compare_build();
682
676
  var sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
683
677
  module.exports = sort;
684
678
  }
685
679
  });
686
680
 
687
- // ../sdk/node_modules/semver/functions/rsort.js
681
+ // node_modules/semver/functions/rsort.js
688
682
  var require_rsort = __commonJS({
689
- "../sdk/node_modules/semver/functions/rsort.js"(exports$1, module) {
683
+ "node_modules/semver/functions/rsort.js"(exports$1, module) {
690
684
  var compareBuild = require_compare_build();
691
685
  var rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
692
686
  module.exports = rsort;
693
687
  }
694
688
  });
695
689
 
696
- // ../sdk/node_modules/semver/functions/gt.js
690
+ // node_modules/semver/functions/gt.js
697
691
  var require_gt = __commonJS({
698
- "../sdk/node_modules/semver/functions/gt.js"(exports$1, module) {
692
+ "node_modules/semver/functions/gt.js"(exports$1, module) {
699
693
  var compare = require_compare();
700
694
  var gt = (a, b, loose) => compare(a, b, loose) > 0;
701
695
  module.exports = gt;
702
696
  }
703
697
  });
704
698
 
705
- // ../sdk/node_modules/semver/functions/lt.js
699
+ // node_modules/semver/functions/lt.js
706
700
  var require_lt = __commonJS({
707
- "../sdk/node_modules/semver/functions/lt.js"(exports$1, module) {
701
+ "node_modules/semver/functions/lt.js"(exports$1, module) {
708
702
  var compare = require_compare();
709
703
  var lt = (a, b, loose) => compare(a, b, loose) < 0;
710
704
  module.exports = lt;
711
705
  }
712
706
  });
713
707
 
714
- // ../sdk/node_modules/semver/functions/eq.js
708
+ // node_modules/semver/functions/eq.js
715
709
  var require_eq = __commonJS({
716
- "../sdk/node_modules/semver/functions/eq.js"(exports$1, module) {
710
+ "node_modules/semver/functions/eq.js"(exports$1, module) {
717
711
  var compare = require_compare();
718
712
  var eq = (a, b, loose) => compare(a, b, loose) === 0;
719
713
  module.exports = eq;
720
714
  }
721
715
  });
722
716
 
723
- // ../sdk/node_modules/semver/functions/neq.js
717
+ // node_modules/semver/functions/neq.js
724
718
  var require_neq = __commonJS({
725
- "../sdk/node_modules/semver/functions/neq.js"(exports$1, module) {
719
+ "node_modules/semver/functions/neq.js"(exports$1, module) {
726
720
  var compare = require_compare();
727
721
  var neq = (a, b, loose) => compare(a, b, loose) !== 0;
728
722
  module.exports = neq;
729
723
  }
730
724
  });
731
725
 
732
- // ../sdk/node_modules/semver/functions/gte.js
726
+ // node_modules/semver/functions/gte.js
733
727
  var require_gte = __commonJS({
734
- "../sdk/node_modules/semver/functions/gte.js"(exports$1, module) {
728
+ "node_modules/semver/functions/gte.js"(exports$1, module) {
735
729
  var compare = require_compare();
736
730
  var gte = (a, b, loose) => compare(a, b, loose) >= 0;
737
731
  module.exports = gte;
738
732
  }
739
733
  });
740
734
 
741
- // ../sdk/node_modules/semver/functions/lte.js
735
+ // node_modules/semver/functions/lte.js
742
736
  var require_lte = __commonJS({
743
- "../sdk/node_modules/semver/functions/lte.js"(exports$1, module) {
737
+ "node_modules/semver/functions/lte.js"(exports$1, module) {
744
738
  var compare = require_compare();
745
739
  var lte = (a, b, loose) => compare(a, b, loose) <= 0;
746
740
  module.exports = lte;
747
741
  }
748
742
  });
749
743
 
750
- // ../sdk/node_modules/semver/functions/cmp.js
744
+ // node_modules/semver/functions/cmp.js
751
745
  var require_cmp = __commonJS({
752
- "../sdk/node_modules/semver/functions/cmp.js"(exports$1, module) {
746
+ "node_modules/semver/functions/cmp.js"(exports$1, module) {
753
747
  var eq = require_eq();
754
748
  var neq = require_neq();
755
749
  var gt = require_gt();
@@ -796,9 +790,9 @@ var require_cmp = __commonJS({
796
790
  }
797
791
  });
798
792
 
799
- // ../sdk/node_modules/semver/functions/coerce.js
793
+ // node_modules/semver/functions/coerce.js
800
794
  var require_coerce = __commonJS({
801
- "../sdk/node_modules/semver/functions/coerce.js"(exports$1, module) {
795
+ "node_modules/semver/functions/coerce.js"(exports$1, module) {
802
796
  var SemVer = require_semver();
803
797
  var parse = require_parse();
804
798
  var { safeRe: re, t } = require_re();
@@ -841,9 +835,9 @@ var require_coerce = __commonJS({
841
835
  }
842
836
  });
843
837
 
844
- // ../sdk/node_modules/semver/internal/lrucache.js
838
+ // node_modules/semver/internal/lrucache.js
845
839
  var require_lrucache = __commonJS({
846
- "../sdk/node_modules/semver/internal/lrucache.js"(exports$1, module) {
840
+ "node_modules/semver/internal/lrucache.js"(exports$1, module) {
847
841
  var LRUCache = class {
848
842
  constructor() {
849
843
  this.max = 1e3;
@@ -878,9 +872,9 @@ var require_lrucache = __commonJS({
878
872
  }
879
873
  });
880
874
 
881
- // ../sdk/node_modules/semver/classes/range.js
875
+ // node_modules/semver/classes/range.js
882
876
  var require_range = __commonJS({
883
- "../sdk/node_modules/semver/classes/range.js"(exports$1, module) {
877
+ "node_modules/semver/classes/range.js"(exports$1, module) {
884
878
  var SPACE_CHARACTERS = /\s+/g;
885
879
  var Range = class _Range {
886
880
  constructor(range, options) {
@@ -982,9 +976,9 @@ var require_range = __commonJS({
982
976
  if (rangeMap.size > 1 && rangeMap.has("")) {
983
977
  rangeMap.delete("");
984
978
  }
985
- const result = [...rangeMap.values()];
986
- cache.set(memoKey, result);
987
- return result;
979
+ const result2 = [...rangeMap.values()];
980
+ cache.set(memoKey, result2);
981
+ return result2;
988
982
  }
989
983
  intersects(range, options) {
990
984
  if (!(range instanceof _Range)) {
@@ -1038,16 +1032,16 @@ var require_range = __commonJS({
1038
1032
  var isNullSet = (c) => c.value === "<0.0.0-0";
1039
1033
  var isAny = (c) => c.value === "";
1040
1034
  var isSatisfiable = (comparators, options) => {
1041
- let result = true;
1035
+ let result2 = true;
1042
1036
  const remainingComparators = comparators.slice();
1043
1037
  let testComparator = remainingComparators.pop();
1044
- while (result && remainingComparators.length) {
1045
- result = remainingComparators.every((otherComparator) => {
1038
+ while (result2 && remainingComparators.length) {
1039
+ result2 = remainingComparators.every((otherComparator) => {
1046
1040
  return testComparator.intersects(otherComparator, options);
1047
1041
  });
1048
1042
  testComparator = remainingComparators.pop();
1049
1043
  }
1050
- return result;
1044
+ return result2;
1051
1045
  };
1052
1046
  var parseComparator = (comp, options) => {
1053
1047
  comp = comp.replace(re[t.BUILD], "");
@@ -1254,9 +1248,9 @@ var require_range = __commonJS({
1254
1248
  }
1255
1249
  });
1256
1250
 
1257
- // ../sdk/node_modules/semver/classes/comparator.js
1251
+ // node_modules/semver/classes/comparator.js
1258
1252
  var require_comparator = __commonJS({
1259
- "../sdk/node_modules/semver/classes/comparator.js"(exports$1, module) {
1253
+ "node_modules/semver/classes/comparator.js"(exports$1, module) {
1260
1254
  var ANY = /* @__PURE__ */ Symbol("SemVer ANY");
1261
1255
  var Comparator = class _Comparator {
1262
1256
  static get ANY() {
@@ -1366,9 +1360,9 @@ var require_comparator = __commonJS({
1366
1360
  }
1367
1361
  });
1368
1362
 
1369
- // ../sdk/node_modules/semver/functions/satisfies.js
1363
+ // node_modules/semver/functions/satisfies.js
1370
1364
  var require_satisfies = __commonJS({
1371
- "../sdk/node_modules/semver/functions/satisfies.js"(exports$1, module) {
1365
+ "node_modules/semver/functions/satisfies.js"(exports$1, module) {
1372
1366
  var Range = require_range();
1373
1367
  var satisfies = (version, range, options) => {
1374
1368
  try {
@@ -1382,18 +1376,18 @@ var require_satisfies = __commonJS({
1382
1376
  }
1383
1377
  });
1384
1378
 
1385
- // ../sdk/node_modules/semver/ranges/to-comparators.js
1379
+ // node_modules/semver/ranges/to-comparators.js
1386
1380
  var require_to_comparators = __commonJS({
1387
- "../sdk/node_modules/semver/ranges/to-comparators.js"(exports$1, module) {
1381
+ "node_modules/semver/ranges/to-comparators.js"(exports$1, module) {
1388
1382
  var Range = require_range();
1389
1383
  var toComparators = (range, options) => new Range(range, options).set.map((comp) => comp.map((c) => c.value).join(" ").trim().split(" "));
1390
1384
  module.exports = toComparators;
1391
1385
  }
1392
1386
  });
1393
1387
 
1394
- // ../sdk/node_modules/semver/ranges/max-satisfying.js
1388
+ // node_modules/semver/ranges/max-satisfying.js
1395
1389
  var require_max_satisfying = __commonJS({
1396
- "../sdk/node_modules/semver/ranges/max-satisfying.js"(exports$1, module) {
1390
+ "node_modules/semver/ranges/max-satisfying.js"(exports$1, module) {
1397
1391
  var SemVer = require_semver();
1398
1392
  var Range = require_range();
1399
1393
  var maxSatisfying = (versions, range, options) => {
@@ -1419,9 +1413,9 @@ var require_max_satisfying = __commonJS({
1419
1413
  }
1420
1414
  });
1421
1415
 
1422
- // ../sdk/node_modules/semver/ranges/min-satisfying.js
1416
+ // node_modules/semver/ranges/min-satisfying.js
1423
1417
  var require_min_satisfying = __commonJS({
1424
- "../sdk/node_modules/semver/ranges/min-satisfying.js"(exports$1, module) {
1418
+ "node_modules/semver/ranges/min-satisfying.js"(exports$1, module) {
1425
1419
  var SemVer = require_semver();
1426
1420
  var Range = require_range();
1427
1421
  var minSatisfying = (versions, range, options) => {
@@ -1447,9 +1441,9 @@ var require_min_satisfying = __commonJS({
1447
1441
  }
1448
1442
  });
1449
1443
 
1450
- // ../sdk/node_modules/semver/ranges/min-version.js
1444
+ // node_modules/semver/ranges/min-version.js
1451
1445
  var require_min_version = __commonJS({
1452
- "../sdk/node_modules/semver/ranges/min-version.js"(exports$1, module) {
1446
+ "node_modules/semver/ranges/min-version.js"(exports$1, module) {
1453
1447
  var SemVer = require_semver();
1454
1448
  var Range = require_range();
1455
1449
  var gt = require_gt();
@@ -1505,9 +1499,9 @@ var require_min_version = __commonJS({
1505
1499
  }
1506
1500
  });
1507
1501
 
1508
- // ../sdk/node_modules/semver/ranges/valid.js
1502
+ // node_modules/semver/ranges/valid.js
1509
1503
  var require_valid2 = __commonJS({
1510
- "../sdk/node_modules/semver/ranges/valid.js"(exports$1, module) {
1504
+ "node_modules/semver/ranges/valid.js"(exports$1, module) {
1511
1505
  var Range = require_range();
1512
1506
  var validRange = (range, options) => {
1513
1507
  try {
@@ -1520,9 +1514,9 @@ var require_valid2 = __commonJS({
1520
1514
  }
1521
1515
  });
1522
1516
 
1523
- // ../sdk/node_modules/semver/ranges/outside.js
1517
+ // node_modules/semver/ranges/outside.js
1524
1518
  var require_outside = __commonJS({
1525
- "../sdk/node_modules/semver/ranges/outside.js"(exports$1, module) {
1519
+ "node_modules/semver/ranges/outside.js"(exports$1, module) {
1526
1520
  var SemVer = require_semver();
1527
1521
  var Comparator = require_comparator();
1528
1522
  var { ANY } = Comparator;
@@ -1588,27 +1582,27 @@ var require_outside = __commonJS({
1588
1582
  }
1589
1583
  });
1590
1584
 
1591
- // ../sdk/node_modules/semver/ranges/gtr.js
1585
+ // node_modules/semver/ranges/gtr.js
1592
1586
  var require_gtr = __commonJS({
1593
- "../sdk/node_modules/semver/ranges/gtr.js"(exports$1, module) {
1587
+ "node_modules/semver/ranges/gtr.js"(exports$1, module) {
1594
1588
  var outside = require_outside();
1595
1589
  var gtr = (version, range, options) => outside(version, range, ">", options);
1596
1590
  module.exports = gtr;
1597
1591
  }
1598
1592
  });
1599
1593
 
1600
- // ../sdk/node_modules/semver/ranges/ltr.js
1594
+ // node_modules/semver/ranges/ltr.js
1601
1595
  var require_ltr = __commonJS({
1602
- "../sdk/node_modules/semver/ranges/ltr.js"(exports$1, module) {
1596
+ "node_modules/semver/ranges/ltr.js"(exports$1, module) {
1603
1597
  var outside = require_outside();
1604
1598
  var ltr = (version, range, options) => outside(version, range, "<", options);
1605
1599
  module.exports = ltr;
1606
1600
  }
1607
1601
  });
1608
1602
 
1609
- // ../sdk/node_modules/semver/ranges/intersects.js
1603
+ // node_modules/semver/ranges/intersects.js
1610
1604
  var require_intersects = __commonJS({
1611
- "../sdk/node_modules/semver/ranges/intersects.js"(exports$1, module) {
1605
+ "node_modules/semver/ranges/intersects.js"(exports$1, module) {
1612
1606
  var Range = require_range();
1613
1607
  var intersects = (r1, r2, options) => {
1614
1608
  r1 = new Range(r1, options);
@@ -1619,9 +1613,9 @@ var require_intersects = __commonJS({
1619
1613
  }
1620
1614
  });
1621
1615
 
1622
- // ../sdk/node_modules/semver/ranges/simplify.js
1616
+ // node_modules/semver/ranges/simplify.js
1623
1617
  var require_simplify = __commonJS({
1624
- "../sdk/node_modules/semver/ranges/simplify.js"(exports$1, module) {
1618
+ "node_modules/semver/ranges/simplify.js"(exports$1, module) {
1625
1619
  var satisfies = require_satisfies();
1626
1620
  var compare = require_compare();
1627
1621
  module.exports = (versions, range, options) => {
@@ -1668,9 +1662,9 @@ var require_simplify = __commonJS({
1668
1662
  }
1669
1663
  });
1670
1664
 
1671
- // ../sdk/node_modules/semver/ranges/subset.js
1665
+ // node_modules/semver/ranges/subset.js
1672
1666
  var require_subset = __commonJS({
1673
- "../sdk/node_modules/semver/ranges/subset.js"(exports$1, module) {
1667
+ "node_modules/semver/ranges/subset.js"(exports$1, module) {
1674
1668
  var Range = require_range();
1675
1669
  var Comparator = require_comparator();
1676
1670
  var { ANY } = Comparator;
@@ -1829,9 +1823,9 @@ var require_subset = __commonJS({
1829
1823
  }
1830
1824
  });
1831
1825
 
1832
- // ../sdk/node_modules/semver/index.js
1826
+ // node_modules/semver/index.js
1833
1827
  var require_semver2 = __commonJS({
1834
- "../sdk/node_modules/semver/index.js"(exports$1, module) {
1828
+ "node_modules/semver/index.js"(exports$1, module) {
1835
1829
  var internalRe = require_re();
1836
1830
  var constants = require_constants();
1837
1831
  var SemVer = require_semver();
@@ -1923,546 +1917,6 @@ var require_semver2 = __commonJS({
1923
1917
  }
1924
1918
  });
1925
1919
 
1926
- // ../sdk/dist/flags/server.js
1927
- var require_server = __commonJS({
1928
- "../sdk/dist/flags/server.js"(exports$1, module) {
1929
- var __defProp2 = Object.defineProperty;
1930
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
1931
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
1932
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
1933
- var __export = (target, all) => {
1934
- for (var name in all)
1935
- __defProp2(target, name, { get: all[name], enumerable: true });
1936
- };
1937
- var __copyProps2 = (to, from, except, desc) => {
1938
- if (from && typeof from === "object" || typeof from === "function") {
1939
- for (let key of __getOwnPropNames2(from))
1940
- if (!__hasOwnProp2.call(to, key) && key !== except)
1941
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
1942
- }
1943
- return to;
1944
- };
1945
- var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
1946
- var server_exports = {};
1947
- __export(server_exports, {
1948
- FlagClient: () => FlagClient2,
1949
- allConditionsMatch: () => allConditionsMatch,
1950
- evaluateFlag: () => evaluateFlag,
1951
- hashToBucket: () => hashToBucket
1952
- });
1953
- module.exports = __toCommonJS(server_exports);
1954
- var import_node_crypto = __require("crypto");
1955
- function hashToBucket(flagKey, identifier, salt) {
1956
- const hash = (0, import_node_crypto.createHash)("sha256").update(`${salt}.${flagKey}.${identifier}`).digest();
1957
- return hash.readUInt32BE(0) % 1e4;
1958
- }
1959
- var import_semver = require_semver2();
1960
- function allConditionsMatch(conditions, context) {
1961
- return conditions.every((c) => conditionMatches(c, context));
1962
- }
1963
- function conditionMatches(condition, context) {
1964
- const attributeValue = getAttribute(context, condition.attribute);
1965
- const op = condition.operator;
1966
- if (op === "exists") return attributeValue !== void 0 && attributeValue !== null;
1967
- if (op === "not_exists") return attributeValue === void 0 || attributeValue === null;
1968
- if (attributeValue === void 0 || attributeValue === null) return false;
1969
- switch (op) {
1970
- case "eq":
1971
- return compareValues(attributeValue, condition.value) === 0;
1972
- case "neq":
1973
- return compareValues(attributeValue, condition.value) !== 0;
1974
- case "in":
1975
- return candidateValues(condition).some((v) => compareValues(attributeValue, v) === 0);
1976
- case "not_in":
1977
- return !candidateValues(condition).some((v) => compareValues(attributeValue, v) === 0);
1978
- case "contains":
1979
- return containsValue(attributeValue, condition.value);
1980
- case "starts_with":
1981
- return typeof attributeValue === "string" && typeof condition.value === "string" ? attributeValue.startsWith(condition.value) : false;
1982
- case "ends_with":
1983
- return typeof attributeValue === "string" && typeof condition.value === "string" ? attributeValue.endsWith(condition.value) : false;
1984
- case "gt":
1985
- return compareValues(attributeValue, condition.value) === 1;
1986
- case "gte": {
1987
- const cmp = compareValues(attributeValue, condition.value);
1988
- return cmp === 1 || cmp === 0;
1989
- }
1990
- case "lt":
1991
- return compareValues(attributeValue, condition.value) === -1;
1992
- case "lte": {
1993
- const cmp = compareValues(attributeValue, condition.value);
1994
- return cmp === -1 || cmp === 0;
1995
- }
1996
- case "regex": {
1997
- if (typeof attributeValue !== "string" || typeof condition.value !== "string") return false;
1998
- try {
1999
- return new RegExp(condition.value).test(attributeValue);
2000
- } catch {
2001
- return false;
2002
- }
2003
- }
2004
- case "semver_eq":
2005
- return semverCmp(attributeValue, condition.value) === 0;
2006
- case "semver_neq":
2007
- return semverCmp(attributeValue, condition.value) !== 0;
2008
- case "semver_gt":
2009
- return semverCmp(attributeValue, condition.value) === 1;
2010
- case "semver_gte": {
2011
- const cmp = semverCmp(attributeValue, condition.value);
2012
- return cmp === 1 || cmp === 0;
2013
- }
2014
- case "semver_lt":
2015
- return semverCmp(attributeValue, condition.value) === -1;
2016
- case "semver_lte": {
2017
- const cmp = semverCmp(attributeValue, condition.value);
2018
- return cmp === -1 || cmp === 0;
2019
- }
2020
- default:
2021
- return false;
2022
- }
2023
- }
2024
- function getAttribute(context, key) {
2025
- switch (key) {
2026
- case "user_id":
2027
- return context.user_id;
2028
- case "email":
2029
- return context.email;
2030
- case "session_id":
2031
- return context.session_id;
2032
- case "ip_address":
2033
- return context.ip_address;
2034
- case "user_agent":
2035
- return context.user_agent;
2036
- case "timestamp":
2037
- return context.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
2038
- default:
2039
- return context[key];
2040
- }
2041
- }
2042
- function candidateValues(condition) {
2043
- if (condition.values && condition.values.length > 0) return condition.values;
2044
- if (condition.value === void 0 || condition.value === null) return [];
2045
- if (Array.isArray(condition.value)) return condition.value;
2046
- return [condition.value];
2047
- }
2048
- function compareValues(actual, expected) {
2049
- if (expected === void 0 || expected === null) return null;
2050
- const numA = toNumber(actual);
2051
- const numB = toNumber(expected);
2052
- if (numA !== null && numB !== null) {
2053
- if (numA < numB) return -1;
2054
- if (numA > numB) return 1;
2055
- return 0;
2056
- }
2057
- if (typeof actual === "boolean" && typeof expected === "boolean") {
2058
- if (actual === expected) return 0;
2059
- return actual ? 1 : -1;
2060
- }
2061
- const strA = toString(actual);
2062
- const strB = toString(expected);
2063
- if (strA !== null && strB !== null) {
2064
- if (strA < strB) return -1;
2065
- if (strA > strB) return 1;
2066
- return 0;
2067
- }
2068
- return null;
2069
- }
2070
- function containsValue(actual, expected) {
2071
- if (expected === void 0 || expected === null) return false;
2072
- if (Array.isArray(actual)) {
2073
- return actual.some((item) => compareValues(item, expected) === 0);
2074
- }
2075
- if (typeof actual === "string" && typeof expected === "string") {
2076
- return actual.includes(expected);
2077
- }
2078
- return false;
2079
- }
2080
- function toNumber(value) {
2081
- if (typeof value === "number") return value;
2082
- if (typeof value === "string") {
2083
- const n = Number(value);
2084
- return isNaN(n) ? null : n;
2085
- }
2086
- return null;
2087
- }
2088
- function toString(value) {
2089
- if (typeof value === "string") return value;
2090
- return null;
2091
- }
2092
- function semverCmp(actual, expected) {
2093
- if (typeof actual !== "string" || typeof expected !== "string") return null;
2094
- try {
2095
- const a = (0, import_semver.parse)(actual);
2096
- const b = (0, import_semver.parse)(expected);
2097
- if (!a || !b) return null;
2098
- return (0, import_semver.compare)(a, b);
2099
- } catch {
2100
- return null;
2101
- }
2102
- }
2103
- function evaluateFlag(flag, config, context, segmentIndex) {
2104
- const effectiveDefault = flag.environment_default_value ?? flag.default_value;
2105
- if (flag.status !== "active") {
2106
- return result(flag, config.environment, effectiveDefault, "disabled");
2107
- }
2108
- if (!flag.environment_enabled) {
2109
- return result(flag, config.environment, effectiveDefault, "disabled");
2110
- }
2111
- const bucketIdentifier = getBucketIdentifier(context);
2112
- for (const rule of flag.rules) {
2113
- if (!rule.enabled) continue;
2114
- if (rule.segment_ids.length > 0) {
2115
- const segmentMatched = rule.segment_ids.some((segId) => {
2116
- const segment = segmentIndex ? segmentIndex.get(segId) : config.segments.find((s) => s.id === segId);
2117
- if (!segment) return false;
2118
- return userMatchesSegment(segment, context);
2119
- });
2120
- if (!segmentMatched) continue;
2121
- }
2122
- if (!allConditionsMatch(rule.conditions, context)) continue;
2123
- if (rule.rollout_percentage !== null && rule.rollout_percentage !== void 0) {
2124
- const bucket = hashToBucket(flag.flag_key, bucketIdentifier, config.rollout_salt);
2125
- if (bucket >= rule.rollout_percentage) continue;
2126
- return {
2127
- flag_id: flag.flag_id,
2128
- flag_key: flag.flag_key,
2129
- environment: config.environment,
2130
- value: rule.serve_value,
2131
- reason: "rule_match",
2132
- matched_rule_id: rule.id,
2133
- variant_key: null,
2134
- bucket
2135
- };
2136
- }
2137
- return {
2138
- flag_id: flag.flag_id,
2139
- flag_key: flag.flag_key,
2140
- environment: config.environment,
2141
- value: rule.serve_value,
2142
- reason: "rule_match",
2143
- matched_rule_id: rule.id,
2144
- variant_key: null,
2145
- bucket: null
2146
- };
2147
- }
2148
- if (flag.variants.length > 0) {
2149
- const totalWeight = flag.variants.reduce((sum, v) => sum + v.weight, 0);
2150
- if (totalWeight > 0) {
2151
- const bucket = hashToBucket(flag.flag_key, bucketIdentifier, config.rollout_salt);
2152
- const scaled = Math.floor(bucket * totalWeight / 1e4);
2153
- let cursor = 0;
2154
- for (const variant of flag.variants) {
2155
- cursor += variant.weight;
2156
- if (scaled < cursor) {
2157
- return {
2158
- flag_id: flag.flag_id,
2159
- flag_key: flag.flag_key,
2160
- environment: config.environment,
2161
- value: variant.value,
2162
- reason: "variant",
2163
- matched_rule_id: null,
2164
- variant_key: variant.variant_key,
2165
- bucket
2166
- };
2167
- }
2168
- }
2169
- }
2170
- }
2171
- return result(flag, config.environment, effectiveDefault, "default");
2172
- }
2173
- function getBucketIdentifier(context) {
2174
- return context.user_id ?? context.session_id ?? context.email ?? context.ip_address ?? "anonymous";
2175
- }
2176
- function userMatchesSegment(segment, context) {
2177
- const identifiers = [context.user_id, context.email, context.session_id].filter(
2178
- (v) => v !== void 0 && v !== null
2179
- );
2180
- if (identifiers.some((id) => segment.excluded_users.includes(id))) {
2181
- return false;
2182
- }
2183
- if (identifiers.some((id) => segment.included_users.includes(id))) {
2184
- return true;
2185
- }
2186
- return allConditionsMatch(segment.conditions, context);
2187
- }
2188
- function result(flag, environment, value, reason) {
2189
- return {
2190
- flag_id: flag.flag_id,
2191
- flag_key: flag.flag_key,
2192
- environment,
2193
- value,
2194
- reason,
2195
- matched_rule_id: null,
2196
- variant_key: null,
2197
- bucket: null
2198
- };
2199
- }
2200
- var FlagClient2 = class {
2201
- constructor(options) {
2202
- this.config = null;
2203
- this.flagIndex = /* @__PURE__ */ new Map();
2204
- this.segmentIndex = /* @__PURE__ */ new Map();
2205
- this.lastETag = "";
2206
- this.streamState = "idle";
2207
- this.pollTimer = null;
2208
- this.reconnectTimer = null;
2209
- this.telemetryTimer = null;
2210
- this.abortController = null;
2211
- this.initPromise = null;
2212
- this.telemetryCounters = /* @__PURE__ */ new Map();
2213
- this.isShuttingDown = false;
2214
- this.streamConnectInFlight = false;
2215
- this.apiKey = options.apiKey;
2216
- this.environment = options.environment;
2217
- this.gatewayUrl = options.gatewayUrl;
2218
- }
2219
- async init() {
2220
- this.isShuttingDown = false;
2221
- if (this.config) return;
2222
- if (this.initPromise) return this.initPromise;
2223
- this.initPromise = this.doInit();
2224
- try {
2225
- await this.initPromise;
2226
- } finally {
2227
- this.initPromise = null;
2228
- }
2229
- }
2230
- async doInit() {
2231
- const resp = await fetch(`${this.gatewayUrl}/v1/flags/config?environment=${encodeURIComponent(this.environment)}`, {
2232
- headers: { "x-api-key": this.apiKey }
2233
- });
2234
- if (resp.status === 403) throw new Error("Secret API key required for /config");
2235
- if (!resp.ok) throw new Error(`Config fetch failed: ${resp.status}`);
2236
- const json = await resp.json();
2237
- this.config = json.data;
2238
- this.buildIndexes();
2239
- this.lastETag = resp.headers.get("etag") || "";
2240
- this.connectStream();
2241
- this.startTelemetryFlush();
2242
- }
2243
- buildIndexes() {
2244
- this.flagIndex.clear();
2245
- this.segmentIndex.clear();
2246
- if (!this.config) return;
2247
- for (const flag of this.config.flags) {
2248
- this.flagIndex.set(flag.flag_key, flag);
2249
- }
2250
- for (const segment of this.config.segments) {
2251
- this.segmentIndex.set(segment.id, segment);
2252
- }
2253
- }
2254
- evaluate(flagKey, context) {
2255
- if (!this.config) throw new Error("FlagClient not initialized \u2014 call init() first");
2256
- const flagConfig = this.flagIndex.get(flagKey);
2257
- if (!flagConfig) {
2258
- return {
2259
- flag_id: "",
2260
- flag_key: flagKey,
2261
- environment: this.environment,
2262
- value: null,
2263
- reason: "not_found",
2264
- matched_rule_id: null,
2265
- variant_key: null,
2266
- bucket: null
2267
- };
2268
- }
2269
- const result2 = evaluateFlag(flagConfig, this.config, context, this.segmentIndex);
2270
- this.recordTelemetry(result2);
2271
- return result2;
2272
- }
2273
- evaluateBatch(flagKeys, context) {
2274
- if (!this.config) throw new Error("FlagClient not initialized \u2014 call init() first");
2275
- const results = {};
2276
- for (const key of flagKeys) {
2277
- const flagConfig = this.flagIndex.get(key);
2278
- if (flagConfig) {
2279
- const result2 = evaluateFlag(flagConfig, this.config, context, this.segmentIndex);
2280
- this.recordTelemetry(result2);
2281
- results[key] = result2;
2282
- }
2283
- }
2284
- return results;
2285
- }
2286
- async shutdown() {
2287
- this.isShuttingDown = true;
2288
- this.streamState = "idle";
2289
- this.abortController?.abort();
2290
- this.abortController = null;
2291
- if (this.pollTimer) {
2292
- clearInterval(this.pollTimer);
2293
- this.pollTimer = null;
2294
- }
2295
- if (this.reconnectTimer) {
2296
- clearInterval(this.reconnectTimer);
2297
- this.reconnectTimer = null;
2298
- }
2299
- if (this.telemetryTimer) {
2300
- clearInterval(this.telemetryTimer);
2301
- this.telemetryTimer = null;
2302
- }
2303
- await this.flushTelemetry();
2304
- }
2305
- // ======== SSE Streaming ========
2306
- async connectStream() {
2307
- if (this.isShuttingDown || this.streamState === "streaming" || this.streamConnectInFlight) return;
2308
- this.streamConnectInFlight = true;
2309
- this.abortController?.abort();
2310
- const abortController = new AbortController();
2311
- this.abortController = abortController;
2312
- const shouldResumePolling = this.streamState !== "polling";
2313
- let startPolling = shouldResumePolling;
2314
- try {
2315
- const resp = await fetch(
2316
- `${this.gatewayUrl}/v1/flags/stream?environment=${encodeURIComponent(this.environment)}`,
2317
- {
2318
- headers: {
2319
- "x-api-key": this.apiKey,
2320
- "Last-Event-ID": String(this.config?.version ?? 0)
2321
- },
2322
- signal: abortController.signal
2323
- }
2324
- );
2325
- if (resp.ok && resp.body) {
2326
- this.streamState = "streaming";
2327
- this.stopPolling();
2328
- startPolling = false;
2329
- const reader = resp.body.getReader();
2330
- const decoder = new TextDecoder();
2331
- let buffer = "";
2332
- while (true) {
2333
- const { done, value } = await reader.read();
2334
- if (done) break;
2335
- buffer += decoder.decode(value, { stream: true });
2336
- let idx;
2337
- while ((idx = buffer.indexOf("\n\n")) !== -1) {
2338
- const frame = buffer.slice(0, idx);
2339
- buffer = buffer.slice(idx + 2);
2340
- this.handleSseFrame(frame);
2341
- }
2342
- }
2343
- if (this.streamState === "streaming") {
2344
- this.streamState = "idle";
2345
- startPolling = true;
2346
- }
2347
- }
2348
- } catch {
2349
- startPolling = !abortController.signal.aborted && shouldResumePolling;
2350
- } finally {
2351
- this.streamConnectInFlight = false;
2352
- }
2353
- if (!this.isShuttingDown && startPolling) {
2354
- this.startPolling();
2355
- }
2356
- }
2357
- handleSseFrame(frame) {
2358
- let eventType = "";
2359
- let data = "";
2360
- for (const line of frame.split("\n")) {
2361
- if (line.startsWith("event:")) eventType = line.slice(6).trim();
2362
- else if (line.startsWith("data:")) data += line.slice(5).trim();
2363
- }
2364
- if (eventType === "config" && data) {
2365
- try {
2366
- const parsed = JSON.parse(data);
2367
- const newConfig = parsed.data;
2368
- if (newConfig && newConfig.version !== void 0) {
2369
- this.config = newConfig;
2370
- this.buildIndexes();
2371
- }
2372
- } catch {
2373
- }
2374
- }
2375
- }
2376
- // ======== Polling Fallback ========
2377
- startPolling() {
2378
- if (this.streamState === "polling") return;
2379
- this.streamState = "polling";
2380
- this.pollTimer = setInterval(() => void this.pollConfig(), 6e4);
2381
- this.reconnectTimer = setInterval(() => void this.connectStream(), 3e5);
2382
- }
2383
- stopPolling() {
2384
- if (this.pollTimer) {
2385
- clearInterval(this.pollTimer);
2386
- this.pollTimer = null;
2387
- }
2388
- if (this.reconnectTimer) {
2389
- clearInterval(this.reconnectTimer);
2390
- this.reconnectTimer = null;
2391
- }
2392
- }
2393
- async pollConfig() {
2394
- try {
2395
- const headers2 = { "x-api-key": this.apiKey };
2396
- if (this.lastETag) headers2["if-none-match"] = this.lastETag;
2397
- const resp = await fetch(
2398
- `${this.gatewayUrl}/v1/flags/config?environment=${encodeURIComponent(this.environment)}`,
2399
- { headers: headers2 }
2400
- );
2401
- if (resp.status === 304) return;
2402
- if (!resp.ok) return;
2403
- const json = await resp.json();
2404
- this.config = json.data;
2405
- this.buildIndexes();
2406
- this.lastETag = resp.headers.get("etag") || "";
2407
- } catch {
2408
- }
2409
- }
2410
- // ======== Telemetry ========
2411
- recordTelemetry(evaluation) {
2412
- const key = `${evaluation.flag_key}:${evaluation.reason}:${String(evaluation.value)}`;
2413
- const existing = this.telemetryCounters.get(key);
2414
- if (existing) {
2415
- existing.count++;
2416
- if (evaluation.value === true) existing.true_count++;
2417
- else if (evaluation.value === false) existing.false_count++;
2418
- } else {
2419
- this.telemetryCounters.set(key, {
2420
- flag_key: evaluation.flag_key,
2421
- flag_id: evaluation.flag_id,
2422
- reason: evaluation.reason,
2423
- count: 1,
2424
- true_count: evaluation.value === true ? 1 : 0,
2425
- false_count: evaluation.value === false ? 1 : 0
2426
- });
2427
- }
2428
- }
2429
- startTelemetryFlush() {
2430
- this.telemetryTimer = setInterval(() => void this.flushTelemetry(), 6e4);
2431
- }
2432
- async flushTelemetry() {
2433
- if (this.telemetryCounters.size === 0) return;
2434
- const evaluations = Array.from(this.telemetryCounters.values());
2435
- this.telemetryCounters.clear();
2436
- try {
2437
- await fetch(`${this.gatewayUrl}/v1/flags/telemetry`, {
2438
- method: "POST",
2439
- headers: {
2440
- "Content-Type": "application/json",
2441
- "x-api-key": this.apiKey
2442
- },
2443
- body: JSON.stringify({
2444
- environment: this.environment,
2445
- evaluations
2446
- })
2447
- });
2448
- } catch {
2449
- for (const counter of evaluations) {
2450
- const key = `${counter.flag_key}:${counter.reason}:${counter.count}`;
2451
- const existing = this.telemetryCounters.get(key);
2452
- if (existing) {
2453
- existing.count += counter.count;
2454
- existing.true_count += counter.true_count;
2455
- existing.false_count += counter.false_count;
2456
- } else {
2457
- this.telemetryCounters.set(key, counter);
2458
- }
2459
- }
2460
- }
2461
- }
2462
- };
2463
- }
2464
- });
2465
-
2466
1920
  // src/types/index.ts
2467
1921
  var ScaleMuleApiError = class extends Error {
2468
1922
  constructor(error, status) {
@@ -2532,11 +1986,13 @@ function extractClientContext(request) {
2532
1986
  const userAgent = headers2.get("user-agent") || void 0;
2533
1987
  const deviceFingerprint = headers2.get("x-device-fingerprint") || void 0;
2534
1988
  const referrer = headers2.get("referer") || void 0;
1989
+ const anonymousId = headers2.get("x-anonymous-id") || void 0;
2535
1990
  return {
2536
1991
  ip,
2537
1992
  userAgent,
2538
1993
  deviceFingerprint,
2539
- referrer
1994
+ referrer,
1995
+ anonymousId
2540
1996
  };
2541
1997
  }
2542
1998
  function extractClientContextFromReq(req) {
@@ -2591,11 +2047,13 @@ function extractClientContextFromReq(req) {
2591
2047
  const userAgent = getHeader("user-agent");
2592
2048
  const deviceFingerprint = getHeader("x-device-fingerprint");
2593
2049
  const referrer = getHeader("referer");
2050
+ const anonymousId = getHeader("x-anonymous-id");
2594
2051
  return {
2595
2052
  ip,
2596
2053
  userAgent,
2597
2054
  deviceFingerprint,
2598
- referrer
2055
+ referrer,
2056
+ anonymousId
2599
2057
  };
2600
2058
  }
2601
2059
  function buildClientContextHeaders(context) {
@@ -2616,6 +2074,9 @@ function buildClientContextHeaders(context) {
2616
2074
  if (context.referrer) {
2617
2075
  headers2["X-Client-Referrer"] = context.referrer;
2618
2076
  }
2077
+ if (context.anonymousId) {
2078
+ headers2["x-anonymous-id"] = context.anonymousId;
2079
+ }
2619
2080
  return headers2;
2620
2081
  }
2621
2082
  function buildFlagContext(clientContext, extraContext = {}) {
@@ -3861,7 +3322,7 @@ function createAuthRoutes(config = {}) {
3861
3322
  if (!email) {
3862
3323
  return errorResponse("VALIDATION_ERROR", "Email required", 400);
3863
3324
  }
3864
- const result = await sm.auth.forgotPassword(email, { clientContext });
3325
+ const result2 = await sm.auth.forgotPassword(email, { clientContext });
3865
3326
  return successResponse({ message: "If an account exists, a reset email has been sent" });
3866
3327
  }
3867
3328
  // ==================== Reset Password ====================
@@ -5006,9 +4467,9 @@ var CODE_TO_STATUS = {
5006
4467
  function errorCodeToStatus(code) {
5007
4468
  return CODE_TO_STATUS[code.toLowerCase()] || 400;
5008
4469
  }
5009
- function unwrap(result) {
5010
- if (result !== null && result !== void 0 && typeof result === "object" && ("success" in result || "error" in result) && "data" in result) {
5011
- const envelope = result;
4470
+ function unwrap(result2) {
4471
+ if (result2 !== null && result2 !== void 0 && typeof result2 === "object" && ("success" in result2 || "error" in result2) && "data" in result2) {
4472
+ const envelope = result2;
5012
4473
  if (envelope.error || envelope.success === false) {
5013
4474
  const err = envelope.error;
5014
4475
  const code = err?.code || "UNKNOWN_ERROR";
@@ -5022,7 +4483,7 @@ function unwrap(result) {
5022
4483
  }
5023
4484
  return envelope.data;
5024
4485
  }
5025
- return result;
4486
+ return result2;
5026
4487
  }
5027
4488
 
5028
4489
  // src/server/handler.ts
@@ -5049,10 +4510,10 @@ function apiHandler(handler, options) {
5049
4510
  searchParams: request.nextUrl.searchParams,
5050
4511
  session
5051
4512
  };
5052
- const result = await handler(request, context);
5053
- if (result instanceof Response) return result;
5054
- if (result !== void 0) {
5055
- return Response.json({ success: true, data: result }, { status: 200 });
4513
+ const result2 = await handler(request, context);
4514
+ if (result2 instanceof Response) return result2;
4515
+ if (result2 !== void 0) {
4516
+ return Response.json({ success: true, data: result2 }, { status: 200 });
5056
4517
  }
5057
4518
  return new Response(null, { status: 204 });
5058
4519
  } catch (error) {
@@ -5099,14 +4560,14 @@ function parseWebhookEvent(payload) {
5099
4560
  }
5100
4561
  async function registerVideoWebhook(url, options) {
5101
4562
  const sm = createServerClient(options?.clientConfig);
5102
- const result = await sm.webhooks.create({
4563
+ const result2 = await sm.webhooks.create({
5103
4564
  webhook_name: options?.name || "Video Status Webhook",
5104
4565
  url,
5105
4566
  events: options?.events || ["video.ready", "video.failed"]
5106
4567
  });
5107
4568
  return {
5108
- id: result.id,
5109
- secret: result.secret
4569
+ id: result2.id,
4570
+ secret: result2.secret
5110
4571
  };
5111
4572
  }
5112
4573
  function createWebhookRoutes(config = {}) {
@@ -5194,8 +4655,517 @@ function createWebhookHandler(config = {}) {
5194
4655
  };
5195
4656
  }
5196
4657
 
4658
+ // node_modules/@scalemule/sdk/dist/flags/server.mjs
4659
+ var import_semver = __toESM(require_semver2());
4660
+ function hashToBucket(flagKey, identifier, salt) {
4661
+ const hash = crypto$1.createHash("sha256").update(`${salt}.${flagKey}.${identifier}`).digest();
4662
+ return hash.readUInt32BE(0) % 1e4;
4663
+ }
4664
+ function allConditionsMatch(conditions, context) {
4665
+ return conditions.every((c) => conditionMatches(c, context));
4666
+ }
4667
+ function conditionMatches(condition, context) {
4668
+ const attributeValue = getAttribute(context, condition.attribute);
4669
+ const op = condition.operator;
4670
+ if (op === "exists") return attributeValue !== void 0 && attributeValue !== null;
4671
+ if (op === "not_exists") return attributeValue === void 0 || attributeValue === null;
4672
+ if (attributeValue === void 0 || attributeValue === null) return false;
4673
+ switch (op) {
4674
+ case "eq":
4675
+ return compareValues(attributeValue, condition.value) === 0;
4676
+ case "neq":
4677
+ return compareValues(attributeValue, condition.value) !== 0;
4678
+ case "in":
4679
+ return candidateValues(condition).some((v) => compareValues(attributeValue, v) === 0);
4680
+ case "not_in":
4681
+ return !candidateValues(condition).some((v) => compareValues(attributeValue, v) === 0);
4682
+ case "contains":
4683
+ return containsValue(attributeValue, condition.value);
4684
+ case "starts_with":
4685
+ return typeof attributeValue === "string" && typeof condition.value === "string" ? attributeValue.startsWith(condition.value) : false;
4686
+ case "ends_with":
4687
+ return typeof attributeValue === "string" && typeof condition.value === "string" ? attributeValue.endsWith(condition.value) : false;
4688
+ case "gt":
4689
+ return compareValues(attributeValue, condition.value) === 1;
4690
+ case "gte": {
4691
+ const cmp = compareValues(attributeValue, condition.value);
4692
+ return cmp === 1 || cmp === 0;
4693
+ }
4694
+ case "lt":
4695
+ return compareValues(attributeValue, condition.value) === -1;
4696
+ case "lte": {
4697
+ const cmp = compareValues(attributeValue, condition.value);
4698
+ return cmp === -1 || cmp === 0;
4699
+ }
4700
+ case "regex": {
4701
+ if (typeof attributeValue !== "string" || typeof condition.value !== "string") return false;
4702
+ try {
4703
+ return new RegExp(condition.value).test(attributeValue);
4704
+ } catch {
4705
+ return false;
4706
+ }
4707
+ }
4708
+ case "semver_eq":
4709
+ return semverCmp(attributeValue, condition.value) === 0;
4710
+ case "semver_neq":
4711
+ return semverCmp(attributeValue, condition.value) !== 0;
4712
+ case "semver_gt":
4713
+ return semverCmp(attributeValue, condition.value) === 1;
4714
+ case "semver_gte": {
4715
+ const cmp = semverCmp(attributeValue, condition.value);
4716
+ return cmp === 1 || cmp === 0;
4717
+ }
4718
+ case "semver_lt":
4719
+ return semverCmp(attributeValue, condition.value) === -1;
4720
+ case "semver_lte": {
4721
+ const cmp = semverCmp(attributeValue, condition.value);
4722
+ return cmp === -1 || cmp === 0;
4723
+ }
4724
+ default:
4725
+ return false;
4726
+ }
4727
+ }
4728
+ function getAttribute(context, key) {
4729
+ switch (key) {
4730
+ case "user_id":
4731
+ return context.user_id;
4732
+ case "email":
4733
+ return context.email;
4734
+ case "session_id":
4735
+ return context.session_id;
4736
+ case "ip_address":
4737
+ return context.ip_address;
4738
+ case "user_agent":
4739
+ return context.user_agent;
4740
+ case "timestamp":
4741
+ return context.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
4742
+ default:
4743
+ return context[key];
4744
+ }
4745
+ }
4746
+ function candidateValues(condition) {
4747
+ if (condition.values && condition.values.length > 0) return condition.values;
4748
+ if (condition.value === void 0 || condition.value === null) return [];
4749
+ if (Array.isArray(condition.value)) return condition.value;
4750
+ return [condition.value];
4751
+ }
4752
+ function compareValues(actual, expected) {
4753
+ if (expected === void 0 || expected === null) return null;
4754
+ const numA = toNumber(actual);
4755
+ const numB = toNumber(expected);
4756
+ if (numA !== null && numB !== null) {
4757
+ if (numA < numB) return -1;
4758
+ if (numA > numB) return 1;
4759
+ return 0;
4760
+ }
4761
+ if (typeof actual === "boolean" && typeof expected === "boolean") {
4762
+ if (actual === expected) return 0;
4763
+ return actual ? 1 : -1;
4764
+ }
4765
+ const strA = toString(actual);
4766
+ const strB = toString(expected);
4767
+ if (strA !== null && strB !== null) {
4768
+ if (strA < strB) return -1;
4769
+ if (strA > strB) return 1;
4770
+ return 0;
4771
+ }
4772
+ return null;
4773
+ }
4774
+ function containsValue(actual, expected) {
4775
+ if (expected === void 0 || expected === null) return false;
4776
+ if (Array.isArray(actual)) {
4777
+ return actual.some((item) => compareValues(item, expected) === 0);
4778
+ }
4779
+ if (typeof actual === "string" && typeof expected === "string") {
4780
+ return actual.includes(expected);
4781
+ }
4782
+ return false;
4783
+ }
4784
+ function toNumber(value) {
4785
+ if (typeof value === "number") return value;
4786
+ if (typeof value === "string") {
4787
+ const n = Number(value);
4788
+ return isNaN(n) ? null : n;
4789
+ }
4790
+ return null;
4791
+ }
4792
+ function toString(value) {
4793
+ if (typeof value === "string") return value;
4794
+ return null;
4795
+ }
4796
+ function semverCmp(actual, expected) {
4797
+ if (typeof actual !== "string" || typeof expected !== "string") return null;
4798
+ try {
4799
+ const a = (0, import_semver.parse)(actual);
4800
+ const b = (0, import_semver.parse)(expected);
4801
+ if (!a || !b) return null;
4802
+ return (0, import_semver.compare)(a, b);
4803
+ } catch {
4804
+ return null;
4805
+ }
4806
+ }
4807
+ function evaluateFlag(flag, config, context, segmentIndex) {
4808
+ const effectiveDefault = flag.environment_default_value ?? flag.default_value;
4809
+ if (flag.status !== "active") {
4810
+ return result(flag, config.environment, effectiveDefault, "disabled");
4811
+ }
4812
+ if (!flag.environment_enabled) {
4813
+ return result(flag, config.environment, effectiveDefault, "disabled");
4814
+ }
4815
+ const bucketIdentifier = getBucketIdentifier(context);
4816
+ for (const rule of flag.rules) {
4817
+ if (!rule.enabled) continue;
4818
+ if (rule.segment_ids.length > 0) {
4819
+ const segmentMatched = rule.segment_ids.some((segId) => {
4820
+ const segment = segmentIndex ? segmentIndex.get(segId) : config.segments.find((s) => s.id === segId);
4821
+ if (!segment) return false;
4822
+ return userMatchesSegment(segment, context);
4823
+ });
4824
+ if (!segmentMatched) continue;
4825
+ }
4826
+ if (!allConditionsMatch(rule.conditions, context)) continue;
4827
+ if (rule.rollout_percentage !== null && rule.rollout_percentage !== void 0) {
4828
+ const bucket = hashToBucket(flag.flag_key, bucketIdentifier, config.rollout_salt);
4829
+ if (bucket >= rule.rollout_percentage) continue;
4830
+ return {
4831
+ flag_id: flag.flag_id,
4832
+ flag_key: flag.flag_key,
4833
+ environment: config.environment,
4834
+ value: rule.serve_value,
4835
+ reason: "rule_match",
4836
+ matched_rule_id: rule.id,
4837
+ variant_key: null,
4838
+ bucket
4839
+ };
4840
+ }
4841
+ return {
4842
+ flag_id: flag.flag_id,
4843
+ flag_key: flag.flag_key,
4844
+ environment: config.environment,
4845
+ value: rule.serve_value,
4846
+ reason: "rule_match",
4847
+ matched_rule_id: rule.id,
4848
+ variant_key: null,
4849
+ bucket: null
4850
+ };
4851
+ }
4852
+ if (flag.variants.length > 0) {
4853
+ const totalWeight = flag.variants.reduce((sum, v) => sum + v.weight, 0);
4854
+ if (totalWeight > 0) {
4855
+ const bucket = hashToBucket(flag.flag_key, bucketIdentifier, config.rollout_salt);
4856
+ const scaled = Math.floor(bucket * totalWeight / 1e4);
4857
+ let cursor = 0;
4858
+ for (const variant of flag.variants) {
4859
+ cursor += variant.weight;
4860
+ if (scaled < cursor) {
4861
+ return {
4862
+ flag_id: flag.flag_id,
4863
+ flag_key: flag.flag_key,
4864
+ environment: config.environment,
4865
+ value: variant.value,
4866
+ reason: "variant",
4867
+ matched_rule_id: null,
4868
+ variant_key: variant.variant_key,
4869
+ bucket
4870
+ };
4871
+ }
4872
+ }
4873
+ }
4874
+ }
4875
+ return result(flag, config.environment, effectiveDefault, "default");
4876
+ }
4877
+ function getBucketIdentifier(context) {
4878
+ return context.user_id ?? context.session_id ?? context.email ?? context.ip_address ?? "anonymous";
4879
+ }
4880
+ function userMatchesSegment(segment, context) {
4881
+ const identifiers = [context.user_id, context.email, context.session_id].filter(
4882
+ (v) => v !== void 0 && v !== null
4883
+ );
4884
+ if (identifiers.some((id) => segment.excluded_users.includes(id))) {
4885
+ return false;
4886
+ }
4887
+ if (identifiers.some((id) => segment.included_users.includes(id))) {
4888
+ return true;
4889
+ }
4890
+ return allConditionsMatch(segment.conditions, context);
4891
+ }
4892
+ function result(flag, environment, value, reason) {
4893
+ return {
4894
+ flag_id: flag.flag_id,
4895
+ flag_key: flag.flag_key,
4896
+ environment,
4897
+ value,
4898
+ reason,
4899
+ matched_rule_id: null,
4900
+ variant_key: null,
4901
+ bucket: null
4902
+ };
4903
+ }
4904
+ var FlagClient = class {
4905
+ constructor(options) {
4906
+ this.config = null;
4907
+ this.flagIndex = /* @__PURE__ */ new Map();
4908
+ this.segmentIndex = /* @__PURE__ */ new Map();
4909
+ this.lastETag = "";
4910
+ this.streamState = "idle";
4911
+ this.pollTimer = null;
4912
+ this.reconnectTimer = null;
4913
+ this.telemetryTimer = null;
4914
+ this.abortController = null;
4915
+ this.initPromise = null;
4916
+ this.telemetryCounters = /* @__PURE__ */ new Map();
4917
+ this.isShuttingDown = false;
4918
+ this.streamConnectInFlight = false;
4919
+ this.apiKey = options.apiKey;
4920
+ this.environment = options.environment;
4921
+ this.gatewayUrl = options.gatewayUrl;
4922
+ }
4923
+ async init() {
4924
+ this.isShuttingDown = false;
4925
+ if (this.config) return;
4926
+ if (this.initPromise) return this.initPromise;
4927
+ this.initPromise = this.doInit();
4928
+ try {
4929
+ await this.initPromise;
4930
+ } finally {
4931
+ this.initPromise = null;
4932
+ }
4933
+ }
4934
+ async doInit() {
4935
+ const resp = await fetch(`${this.gatewayUrl}/v1/flags/config?environment=${encodeURIComponent(this.environment)}`, {
4936
+ headers: { "x-api-key": this.apiKey }
4937
+ });
4938
+ if (resp.status === 403) throw new Error("Secret API key required for /config");
4939
+ if (!resp.ok) throw new Error(`Config fetch failed: ${resp.status}`);
4940
+ const json = await resp.json();
4941
+ this.config = json.data;
4942
+ this.buildIndexes();
4943
+ this.lastETag = resp.headers.get("etag") || "";
4944
+ this.connectStream();
4945
+ this.startTelemetryFlush();
4946
+ }
4947
+ buildIndexes() {
4948
+ this.flagIndex.clear();
4949
+ this.segmentIndex.clear();
4950
+ if (!this.config) return;
4951
+ for (const flag of this.config.flags) {
4952
+ this.flagIndex.set(flag.flag_key, flag);
4953
+ }
4954
+ for (const segment of this.config.segments) {
4955
+ this.segmentIndex.set(segment.id, segment);
4956
+ }
4957
+ }
4958
+ evaluate(flagKey, context) {
4959
+ if (!this.config) throw new Error("FlagClient not initialized \u2014 call init() first");
4960
+ const flagConfig = this.flagIndex.get(flagKey);
4961
+ if (!flagConfig) {
4962
+ return {
4963
+ flag_id: "",
4964
+ flag_key: flagKey,
4965
+ environment: this.environment,
4966
+ value: null,
4967
+ reason: "not_found",
4968
+ matched_rule_id: null,
4969
+ variant_key: null,
4970
+ bucket: null
4971
+ };
4972
+ }
4973
+ const result2 = evaluateFlag(flagConfig, this.config, context, this.segmentIndex);
4974
+ this.recordTelemetry(result2);
4975
+ return result2;
4976
+ }
4977
+ evaluateBatch(flagKeys, context) {
4978
+ if (!this.config) throw new Error("FlagClient not initialized \u2014 call init() first");
4979
+ const results = {};
4980
+ for (const key of flagKeys) {
4981
+ const flagConfig = this.flagIndex.get(key);
4982
+ if (flagConfig) {
4983
+ const result2 = evaluateFlag(flagConfig, this.config, context, this.segmentIndex);
4984
+ this.recordTelemetry(result2);
4985
+ results[key] = result2;
4986
+ }
4987
+ }
4988
+ return results;
4989
+ }
4990
+ async shutdown() {
4991
+ this.isShuttingDown = true;
4992
+ this.streamState = "idle";
4993
+ this.abortController?.abort();
4994
+ this.abortController = null;
4995
+ if (this.pollTimer) {
4996
+ clearInterval(this.pollTimer);
4997
+ this.pollTimer = null;
4998
+ }
4999
+ if (this.reconnectTimer) {
5000
+ clearInterval(this.reconnectTimer);
5001
+ this.reconnectTimer = null;
5002
+ }
5003
+ if (this.telemetryTimer) {
5004
+ clearInterval(this.telemetryTimer);
5005
+ this.telemetryTimer = null;
5006
+ }
5007
+ await this.flushTelemetry();
5008
+ }
5009
+ // ======== SSE Streaming ========
5010
+ async connectStream() {
5011
+ if (this.isShuttingDown || this.streamState === "streaming" || this.streamConnectInFlight) return;
5012
+ this.streamConnectInFlight = true;
5013
+ this.abortController?.abort();
5014
+ const abortController = new AbortController();
5015
+ this.abortController = abortController;
5016
+ const shouldResumePolling = this.streamState !== "polling";
5017
+ let startPolling = shouldResumePolling;
5018
+ try {
5019
+ const resp = await fetch(
5020
+ `${this.gatewayUrl}/v1/flags/stream?environment=${encodeURIComponent(this.environment)}`,
5021
+ {
5022
+ headers: {
5023
+ "x-api-key": this.apiKey,
5024
+ "Last-Event-ID": String(this.config?.version ?? 0)
5025
+ },
5026
+ signal: abortController.signal
5027
+ }
5028
+ );
5029
+ if (resp.ok && resp.body) {
5030
+ this.streamState = "streaming";
5031
+ this.stopPolling();
5032
+ startPolling = false;
5033
+ const reader = resp.body.getReader();
5034
+ const decoder = new TextDecoder();
5035
+ let buffer = "";
5036
+ while (true) {
5037
+ const { done, value } = await reader.read();
5038
+ if (done) break;
5039
+ buffer += decoder.decode(value, { stream: true });
5040
+ let idx;
5041
+ while ((idx = buffer.indexOf("\n\n")) !== -1) {
5042
+ const frame = buffer.slice(0, idx);
5043
+ buffer = buffer.slice(idx + 2);
5044
+ this.handleSseFrame(frame);
5045
+ }
5046
+ }
5047
+ if (this.streamState === "streaming") {
5048
+ this.streamState = "idle";
5049
+ startPolling = true;
5050
+ }
5051
+ }
5052
+ } catch {
5053
+ startPolling = !abortController.signal.aborted && shouldResumePolling;
5054
+ } finally {
5055
+ this.streamConnectInFlight = false;
5056
+ }
5057
+ if (!this.isShuttingDown && startPolling) {
5058
+ this.startPolling();
5059
+ }
5060
+ }
5061
+ handleSseFrame(frame) {
5062
+ let eventType = "";
5063
+ let data = "";
5064
+ for (const line of frame.split("\n")) {
5065
+ if (line.startsWith("event:")) eventType = line.slice(6).trim();
5066
+ else if (line.startsWith("data:")) data += line.slice(5).trim();
5067
+ }
5068
+ if (eventType === "config" && data) {
5069
+ try {
5070
+ const parsed = JSON.parse(data);
5071
+ const newConfig = parsed.data;
5072
+ if (newConfig && newConfig.version !== void 0) {
5073
+ this.config = newConfig;
5074
+ this.buildIndexes();
5075
+ }
5076
+ } catch {
5077
+ }
5078
+ }
5079
+ }
5080
+ // ======== Polling Fallback ========
5081
+ startPolling() {
5082
+ if (this.streamState === "polling") return;
5083
+ this.streamState = "polling";
5084
+ this.pollTimer = setInterval(() => void this.pollConfig(), 6e4);
5085
+ this.reconnectTimer = setInterval(() => void this.connectStream(), 3e5);
5086
+ }
5087
+ stopPolling() {
5088
+ if (this.pollTimer) {
5089
+ clearInterval(this.pollTimer);
5090
+ this.pollTimer = null;
5091
+ }
5092
+ if (this.reconnectTimer) {
5093
+ clearInterval(this.reconnectTimer);
5094
+ this.reconnectTimer = null;
5095
+ }
5096
+ }
5097
+ async pollConfig() {
5098
+ try {
5099
+ const headers2 = { "x-api-key": this.apiKey };
5100
+ if (this.lastETag) headers2["if-none-match"] = this.lastETag;
5101
+ const resp = await fetch(
5102
+ `${this.gatewayUrl}/v1/flags/config?environment=${encodeURIComponent(this.environment)}`,
5103
+ { headers: headers2 }
5104
+ );
5105
+ if (resp.status === 304) return;
5106
+ if (!resp.ok) return;
5107
+ const json = await resp.json();
5108
+ this.config = json.data;
5109
+ this.buildIndexes();
5110
+ this.lastETag = resp.headers.get("etag") || "";
5111
+ } catch {
5112
+ }
5113
+ }
5114
+ // ======== Telemetry ========
5115
+ recordTelemetry(evaluation) {
5116
+ const key = `${evaluation.flag_key}:${evaluation.reason}:${String(evaluation.value)}`;
5117
+ const existing = this.telemetryCounters.get(key);
5118
+ if (existing) {
5119
+ existing.count++;
5120
+ if (evaluation.value === true) existing.true_count++;
5121
+ else if (evaluation.value === false) existing.false_count++;
5122
+ } else {
5123
+ this.telemetryCounters.set(key, {
5124
+ flag_key: evaluation.flag_key,
5125
+ flag_id: evaluation.flag_id,
5126
+ reason: evaluation.reason,
5127
+ count: 1,
5128
+ true_count: evaluation.value === true ? 1 : 0,
5129
+ false_count: evaluation.value === false ? 1 : 0
5130
+ });
5131
+ }
5132
+ }
5133
+ startTelemetryFlush() {
5134
+ this.telemetryTimer = setInterval(() => void this.flushTelemetry(), 6e4);
5135
+ }
5136
+ async flushTelemetry() {
5137
+ if (this.telemetryCounters.size === 0) return;
5138
+ const evaluations = Array.from(this.telemetryCounters.values());
5139
+ this.telemetryCounters.clear();
5140
+ try {
5141
+ await fetch(`${this.gatewayUrl}/v1/flags/telemetry`, {
5142
+ method: "POST",
5143
+ headers: {
5144
+ "Content-Type": "application/json",
5145
+ "x-api-key": this.apiKey
5146
+ },
5147
+ body: JSON.stringify({
5148
+ environment: this.environment,
5149
+ evaluations
5150
+ })
5151
+ });
5152
+ } catch {
5153
+ for (const counter of evaluations) {
5154
+ const key = `${counter.flag_key}:${counter.reason}:${counter.count}`;
5155
+ const existing = this.telemetryCounters.get(key);
5156
+ if (existing) {
5157
+ existing.count += counter.count;
5158
+ existing.true_count += counter.true_count;
5159
+ existing.false_count += counter.false_count;
5160
+ } else {
5161
+ this.telemetryCounters.set(key, counter);
5162
+ }
5163
+ }
5164
+ }
5165
+ }
5166
+ };
5167
+
5197
5168
  // src/server/bootstrap-flags.ts
5198
- var import_server2 = __toESM(require_server());
5199
5169
  var _clients = /* @__PURE__ */ new Map();
5200
5170
  var _initPromises = /* @__PURE__ */ new Map();
5201
5171
  var _serverClient = null;
@@ -5223,7 +5193,7 @@ async function getFlagClient(environment) {
5223
5193
  const pending = _initPromises.get(key);
5224
5194
  if (pending) return pending;
5225
5195
  const promise = (async () => {
5226
- const client = new import_server2.FlagClient({ apiKey, environment, gatewayUrl });
5196
+ const client = new FlagClient({ apiKey, environment, gatewayUrl });
5227
5197
  await Promise.race([
5228
5198
  client.init(),
5229
5199
  new Promise(
@@ -5272,8 +5242,8 @@ async function getBootstrapFlags(flagKeys, environment = "prod", extraContext =
5272
5242
  const clientIp = extractClientIp(hdrs);
5273
5243
  const context = { ...extraContext };
5274
5244
  if (clientIp) context.ip_address = clientIp;
5275
- const result = await getServerClient().flags.evaluateBatch(flagKeys, context, environment);
5276
- return result || {};
5245
+ const result2 = await getServerClient().flags.evaluateBatch(flagKeys, context, environment);
5246
+ return result2 || {};
5277
5247
  } catch {
5278
5248
  return {};
5279
5249
  }
@@ -5423,15 +5393,15 @@ async function getAppSecret(key) {
5423
5393
  }
5424
5394
  try {
5425
5395
  const client = createServerClient();
5426
- const result = await client.secrets.get(key);
5427
- if (!noCache && result) {
5396
+ const result2 = await client.secrets.get(key);
5397
+ if (!noCache && result2) {
5428
5398
  secretsCache[key] = {
5429
- value: result.value,
5430
- version: result.version,
5399
+ value: result2.value,
5400
+ version: result2.version,
5431
5401
  cachedAt: Date.now()
5432
5402
  };
5433
5403
  }
5434
- return result?.value;
5404
+ return result2?.value;
5435
5405
  } catch (error) {
5436
5406
  if (error instanceof ScaleMuleApiError && error.code === "SECRET_NOT_FOUND") {
5437
5407
  return void 0;
@@ -5482,17 +5452,17 @@ async function getBundle(key, resolve = true) {
5482
5452
  }
5483
5453
  try {
5484
5454
  const client = createServerClient();
5485
- const result = await client.bundles.get(key, resolve);
5486
- if (!noCache && result) {
5455
+ const result2 = await client.bundles.get(key, resolve);
5456
+ if (!noCache && result2) {
5487
5457
  bundlesCache[key] = {
5488
- type: result.type,
5489
- data: result.data,
5490
- version: result.version,
5491
- inheritsFrom: result.inherits_from,
5458
+ type: result2.type,
5459
+ data: result2.data,
5460
+ version: result2.version,
5461
+ inheritsFrom: result2.inherits_from,
5492
5462
  cachedAt: Date.now()
5493
5463
  };
5494
5464
  }
5495
- return result?.data;
5465
+ return result2?.data;
5496
5466
  } catch (error) {
5497
5467
  if (error instanceof ScaleMuleApiError && error.code === "BUNDLE_NOT_FOUND") {
5498
5468
  return void 0;