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