flags 0.2.1 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +428 -0
- package/LICENSE.md +21 -0
- package/README.md +44 -93
- package/dist/analytics.cjs +7 -0
- package/dist/analytics.cjs.map +1 -0
- package/dist/analytics.d.cts +8 -0
- package/dist/analytics.d.ts +8 -0
- package/dist/analytics.js +7 -0
- package/dist/analytics.js.map +1 -0
- package/dist/chunk-2UDLZC33.js +9 -0
- package/dist/chunk-2UDLZC33.js.map +1 -0
- package/dist/chunk-AVMIIWOF.cjs +21 -0
- package/dist/chunk-AVMIIWOF.cjs.map +1 -0
- package/dist/chunk-D2GBVCQQ.cjs +406 -0
- package/dist/chunk-D2GBVCQQ.cjs.map +1 -0
- package/dist/chunk-MEG7RDX7.cjs +9 -0
- package/dist/chunk-MEG7RDX7.cjs.map +1 -0
- package/dist/chunk-OQHOV3IB.js +406 -0
- package/dist/chunk-OQHOV3IB.js.map +1 -0
- package/dist/chunk-ZNKTXALY.js +21 -0
- package/dist/chunk-ZNKTXALY.js.map +1 -0
- package/dist/index.cjs +25 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +89 -0
- package/dist/index.d.ts +89 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/next.cjs +611 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.d.cts +191 -0
- package/dist/next.d.ts +191 -0
- package/dist/next.js +611 -0
- package/dist/next.js.map +1 -0
- package/dist/react.cjs +39 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +20 -0
- package/dist/react.d.ts +20 -0
- package/dist/react.js +39 -0
- package/dist/react.js.map +1 -0
- package/dist/sveltekit.cjs +171 -0
- package/dist/sveltekit.cjs.map +1 -0
- package/dist/sveltekit.d.cts +42 -0
- package/dist/sveltekit.d.ts +42 -0
- package/dist/sveltekit.js +171 -0
- package/dist/sveltekit.js.map +1 -0
- package/dist/types-swW0-Ony.d.cts +236 -0
- package/dist/types-swW0-Ony.d.ts +236 -0
- package/package.json +112 -28
- package/LICENSE +0 -9
- package/dist/flags.cjs +0 -366
- package/dist/flags.cjs.map +0 -1
- package/dist/flags.d.cts +0 -84
- package/dist/flags.d.ts +0 -84
- package/dist/flags.js +0 -330
- package/dist/flags.js.map +0 -1
package/dist/next.cjs
ADDED
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkAVMIIWOFcjs = require('./chunk-AVMIIWOF.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkD2GBVCQQcjs = require('./chunk-D2GBVCQQ.cjs');
|
|
13
|
+
require('./chunk-MEG7RDX7.cjs');
|
|
14
|
+
|
|
15
|
+
// src/next/index.ts
|
|
16
|
+
var _cookies = require('@edge-runtime/cookies');
|
|
17
|
+
|
|
18
|
+
// src/next/async-memoize-one.ts
|
|
19
|
+
function memoizeOne(fn, isEqual, { cachePromiseRejection = false } = {}) {
|
|
20
|
+
let calledOnce = false;
|
|
21
|
+
let oldArgs;
|
|
22
|
+
let lastResult;
|
|
23
|
+
function memoized(...newArgs) {
|
|
24
|
+
if (calledOnce && isEqual(newArgs, oldArgs))
|
|
25
|
+
return lastResult;
|
|
26
|
+
lastResult = fn.apply(this, newArgs);
|
|
27
|
+
if (!cachePromiseRejection && lastResult.catch) {
|
|
28
|
+
lastResult.catch(() => calledOnce = false);
|
|
29
|
+
}
|
|
30
|
+
calledOnce = true;
|
|
31
|
+
oldArgs = newArgs;
|
|
32
|
+
return lastResult;
|
|
33
|
+
}
|
|
34
|
+
return memoized;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/next/overrides.ts
|
|
38
|
+
var memoizedDecrypt = memoizeOne(
|
|
39
|
+
(text) => _chunkD2GBVCQQcjs.decrypt.call(void 0, text),
|
|
40
|
+
(a, b) => a[0] === b[0],
|
|
41
|
+
// only the first argument gets compared
|
|
42
|
+
{ cachePromiseRejection: true }
|
|
43
|
+
);
|
|
44
|
+
async function getOverrides(cookie) {
|
|
45
|
+
if (typeof cookie === "string" && cookie !== "") {
|
|
46
|
+
const cookieOverrides = await memoizedDecrypt(cookie);
|
|
47
|
+
return _nullishCoalesce(cookieOverrides, () => ( null));
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/next/serialization.ts
|
|
53
|
+
var _jose = require('jose');
|
|
54
|
+
var memoizedVerify = memoizeOne(
|
|
55
|
+
(code, secret) => _jose.compactVerify.call(void 0, code, _jose.base64url.decode(secret), {
|
|
56
|
+
algorithms: ["HS256"]
|
|
57
|
+
}),
|
|
58
|
+
(a, b) => a[0] === b[0] && a[1] === b[1],
|
|
59
|
+
// only first two args matter
|
|
60
|
+
{ cachePromiseRejection: true }
|
|
61
|
+
);
|
|
62
|
+
var memoizedSign = memoizeOne(
|
|
63
|
+
(uint8Array, secret) => new (0, _jose.CompactSign)(uint8Array).setProtectedHeader({ alg: "HS256" }).sign(_jose.base64url.decode(secret)),
|
|
64
|
+
(a, b) => (
|
|
65
|
+
// matchedIndices array must be equal
|
|
66
|
+
a[0].length === b[0].length && a[0].every((v, i) => b[0][i] === v) && // secrets must be equal
|
|
67
|
+
a[1] === b[1]
|
|
68
|
+
),
|
|
69
|
+
{ cachePromiseRejection: true }
|
|
70
|
+
);
|
|
71
|
+
function splitUint8Array(array, index) {
|
|
72
|
+
const firstHalf = array.slice(0, index);
|
|
73
|
+
const secondHalf = array.slice(index);
|
|
74
|
+
return [firstHalf, secondHalf];
|
|
75
|
+
}
|
|
76
|
+
async function deserialize(code, flags, secret) {
|
|
77
|
+
const { payload } = await memoizedVerify(code, secret);
|
|
78
|
+
const [matchedIndicesArray, valuesUint8Array] = payload.length === flags.length ? [payload] : splitUint8Array(payload, flags.length);
|
|
79
|
+
const valuesArray = valuesUint8Array ? (
|
|
80
|
+
// re-add opening and closing brackets since we remove them when serializing
|
|
81
|
+
JSON.parse(`[${new TextDecoder().decode(valuesUint8Array)}]`)
|
|
82
|
+
) : null;
|
|
83
|
+
let spilled = 0;
|
|
84
|
+
return matchedIndicesArray.reduce(
|
|
85
|
+
(acc, valueIndex, index) => {
|
|
86
|
+
const flag2 = flags[index];
|
|
87
|
+
if (!flag2) {
|
|
88
|
+
throw new Error(`flags: No flag at index ${index}`);
|
|
89
|
+
}
|
|
90
|
+
switch (valueIndex) {
|
|
91
|
+
case 253 /* BOOLEAN_FALSE */:
|
|
92
|
+
acc[flag2.key] = false;
|
|
93
|
+
break;
|
|
94
|
+
case 254 /* BOOLEAN_TRUE */:
|
|
95
|
+
acc[flag2.key] = true;
|
|
96
|
+
break;
|
|
97
|
+
case 255 /* UNLISTED_VALUE */:
|
|
98
|
+
acc[flag2.key] = valuesArray[spilled++];
|
|
99
|
+
break;
|
|
100
|
+
case 252 /* NULL */:
|
|
101
|
+
acc[flag2.key] = null;
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
acc[flag2.key] = _optionalChain([flag2, 'access', _ => _.options, 'optionalAccess', _2 => _2[valueIndex], 'optionalAccess', _3 => _3.value]);
|
|
105
|
+
}
|
|
106
|
+
return acc;
|
|
107
|
+
},
|
|
108
|
+
{}
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
var matchIndex = /* @__PURE__ */ function() {
|
|
112
|
+
const stringifiedOptionsCache = /* @__PURE__ */ new Map();
|
|
113
|
+
return function matchIndex2(options, value) {
|
|
114
|
+
const t = typeof value;
|
|
115
|
+
if (value === null || t === "boolean" || t === "string" || t === "number") {
|
|
116
|
+
return options.findIndex((v) => v.value === value);
|
|
117
|
+
}
|
|
118
|
+
const stringifiedValue = JSON.stringify(value);
|
|
119
|
+
let stringifiedOptions = stringifiedOptionsCache.get(options);
|
|
120
|
+
if (!stringifiedOptions) {
|
|
121
|
+
stringifiedOptions = options.map((o) => JSON.stringify(o.value));
|
|
122
|
+
stringifiedOptionsCache.set(options, stringifiedOptions);
|
|
123
|
+
}
|
|
124
|
+
return stringifiedOptions.findIndex(
|
|
125
|
+
(stringifiedOption) => stringifiedOption === stringifiedValue
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
}();
|
|
129
|
+
function joinUint8Arrays(array1, array2) {
|
|
130
|
+
const combined = new Uint8Array(array1.length + array2.length);
|
|
131
|
+
combined.set(array1);
|
|
132
|
+
combined.set(array2, array1.length);
|
|
133
|
+
return combined;
|
|
134
|
+
}
|
|
135
|
+
async function serialize(flagSet, flags, secret) {
|
|
136
|
+
const unlistedValues = [];
|
|
137
|
+
const matchedIndices = new Uint8Array(
|
|
138
|
+
flags.map((flag2) => {
|
|
139
|
+
const options = Array.isArray(flag2.options) ? flag2.options : [];
|
|
140
|
+
const value = flagSet[flag2.key];
|
|
141
|
+
if (!Object.prototype.hasOwnProperty.call(flagSet, flag2.key) || value === void 0) {
|
|
142
|
+
throw new Error(`flags: Missing value for flag "${flag2.key}"`);
|
|
143
|
+
}
|
|
144
|
+
switch (value) {
|
|
145
|
+
case null:
|
|
146
|
+
return 252 /* NULL */;
|
|
147
|
+
case false:
|
|
148
|
+
return 253 /* BOOLEAN_FALSE */;
|
|
149
|
+
case true:
|
|
150
|
+
return 254 /* BOOLEAN_TRUE */;
|
|
151
|
+
}
|
|
152
|
+
const matchedIndex = matchIndex(options, value);
|
|
153
|
+
if (matchedIndex > -1)
|
|
154
|
+
return matchedIndex;
|
|
155
|
+
unlistedValues.push(value);
|
|
156
|
+
return 255 /* UNLISTED_VALUE */;
|
|
157
|
+
})
|
|
158
|
+
);
|
|
159
|
+
let joined;
|
|
160
|
+
if (unlistedValues.length > 0) {
|
|
161
|
+
const jsonArray = new TextEncoder().encode(
|
|
162
|
+
// slicing removes opening and closing array brackets as they'll always be
|
|
163
|
+
// there and we can re-add them when deserializing
|
|
164
|
+
JSON.stringify(unlistedValues).slice(1, -1)
|
|
165
|
+
);
|
|
166
|
+
joined = joinUint8Arrays(matchedIndices, jsonArray);
|
|
167
|
+
} else {
|
|
168
|
+
joined = matchedIndices;
|
|
169
|
+
}
|
|
170
|
+
return memoizedSign(joined, secret);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/next/precompute.ts
|
|
174
|
+
async function evaluate(flags) {
|
|
175
|
+
return Promise.all(flags.map((flag2) => flag2()));
|
|
176
|
+
}
|
|
177
|
+
async function precompute(flags) {
|
|
178
|
+
const values = await evaluate(flags);
|
|
179
|
+
return serialize2(flags, values);
|
|
180
|
+
}
|
|
181
|
+
function combine(flags, values) {
|
|
182
|
+
return Object.fromEntries(flags.map((flag2, i) => [flag2.key, values[i]]));
|
|
183
|
+
}
|
|
184
|
+
async function serialize2(flags, values, secret = process.env.FLAGS_SECRET) {
|
|
185
|
+
if (!secret) {
|
|
186
|
+
throw new Error("flags: Can not serialize due to missing secret");
|
|
187
|
+
}
|
|
188
|
+
return serialize(combine(flags, values), flags, secret);
|
|
189
|
+
}
|
|
190
|
+
async function deserialize2(flags, code, secret = process.env.FLAGS_SECRET) {
|
|
191
|
+
if (!secret) {
|
|
192
|
+
throw new Error("flags: Can not serialize due to missing secret");
|
|
193
|
+
}
|
|
194
|
+
return deserialize(code, flags, secret);
|
|
195
|
+
}
|
|
196
|
+
async function getPrecomputed(flagOrFlags, precomputeFlags, code, secret = process.env.FLAGS_SECRET) {
|
|
197
|
+
if (!secret) {
|
|
198
|
+
throw new Error(
|
|
199
|
+
"flags: getPrecomputed was called without a secret. Please set FLAGS_SECRET environment variable."
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
const flagSet = await deserialize2(precomputeFlags, code, secret);
|
|
203
|
+
if (Array.isArray(flagOrFlags)) {
|
|
204
|
+
return flagOrFlags.map((flag2) => flagSet[flag2.key]);
|
|
205
|
+
} else {
|
|
206
|
+
return flagSet[flagOrFlags.key];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function* cartesianIterator(items) {
|
|
210
|
+
const remainder = items.length > 1 ? cartesianIterator(items.slice(1)) : [[]];
|
|
211
|
+
for (let r of remainder)
|
|
212
|
+
for (let h of items.at(0))
|
|
213
|
+
yield [h, ...r];
|
|
214
|
+
}
|
|
215
|
+
async function generatePermutations(flags, filter = null, secret = process.env.FLAGS_SECRET) {
|
|
216
|
+
if (!secret) {
|
|
217
|
+
throw new Error(
|
|
218
|
+
"flags: generatePermutations was called without a secret. Please set FLAGS_SECRET environment variable."
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
const options = flags.map((flag2) => {
|
|
222
|
+
if (!flag2.options)
|
|
223
|
+
return [false, true];
|
|
224
|
+
return flag2.options.map((option) => option.value);
|
|
225
|
+
});
|
|
226
|
+
const list = [];
|
|
227
|
+
for (const permutation of cartesianIterator(options)) {
|
|
228
|
+
const permObject = permutation.reduce(
|
|
229
|
+
(acc, value, index) => {
|
|
230
|
+
acc[flags[index].key] = value;
|
|
231
|
+
return acc;
|
|
232
|
+
},
|
|
233
|
+
{}
|
|
234
|
+
);
|
|
235
|
+
if (!filter || filter(permObject))
|
|
236
|
+
list.push(permObject);
|
|
237
|
+
}
|
|
238
|
+
return Promise.all(list.map((values) => serialize(values, flags, secret)));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/next/is-internal-next-error.ts
|
|
242
|
+
var REACT_POSTPONE_TYPE = Symbol.for("react.postpone");
|
|
243
|
+
function isPostpone(error) {
|
|
244
|
+
return typeof error === "object" && error !== null && "$$typeof" in error && error.$$typeof === REACT_POSTPONE_TYPE;
|
|
245
|
+
}
|
|
246
|
+
function isInternalNextError(error) {
|
|
247
|
+
if (isPostpone(error))
|
|
248
|
+
return true;
|
|
249
|
+
if (typeof error !== "object" || error === null || !("digest" in error) || typeof error.digest !== "string") {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
const errorCode = error.digest.split(";")[0];
|
|
253
|
+
return errorCode === "NEXT_REDIRECT" || errorCode === "DYNAMIC_SERVER_USAGE" || errorCode === "BAILOUT_TO_CLIENT_SIDE_RENDERING" || errorCode === "NEXT_NOT_FOUND";
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// src/next/dedupe.ts
|
|
257
|
+
function createCacheNode() {
|
|
258
|
+
return {
|
|
259
|
+
s: 0 /* UNTERMINATED */,
|
|
260
|
+
v: void 0,
|
|
261
|
+
o: null,
|
|
262
|
+
p: null
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function dedupe(fn) {
|
|
266
|
+
const requestStore = /* @__PURE__ */ new WeakMap();
|
|
267
|
+
return async function(...args) {
|
|
268
|
+
const { headers } = await Promise.resolve().then(() => _interopRequireWildcard(require("next/headers")));
|
|
269
|
+
const h = await headers();
|
|
270
|
+
let cacheNode = requestStore.get(h);
|
|
271
|
+
if (!cacheNode) {
|
|
272
|
+
cacheNode = createCacheNode();
|
|
273
|
+
requestStore.set(h, cacheNode);
|
|
274
|
+
}
|
|
275
|
+
for (let i = 0; i < args.length; i++) {
|
|
276
|
+
const arg = args[i];
|
|
277
|
+
if (typeof arg === "function" || typeof arg === "object" && arg !== null) {
|
|
278
|
+
let objectCache = cacheNode.o;
|
|
279
|
+
if (objectCache === null) {
|
|
280
|
+
cacheNode.o = objectCache = /* @__PURE__ */ new WeakMap();
|
|
281
|
+
}
|
|
282
|
+
const objectNode = objectCache.get(arg);
|
|
283
|
+
if (objectNode === void 0) {
|
|
284
|
+
cacheNode = createCacheNode();
|
|
285
|
+
objectCache.set(arg, cacheNode);
|
|
286
|
+
} else {
|
|
287
|
+
cacheNode = objectNode;
|
|
288
|
+
}
|
|
289
|
+
} else {
|
|
290
|
+
let primitiveCache = cacheNode.p;
|
|
291
|
+
if (primitiveCache === null) {
|
|
292
|
+
cacheNode.p = primitiveCache = /* @__PURE__ */ new Map();
|
|
293
|
+
}
|
|
294
|
+
const primitiveNode = primitiveCache.get(arg);
|
|
295
|
+
if (primitiveNode === void 0) {
|
|
296
|
+
cacheNode = createCacheNode();
|
|
297
|
+
primitiveCache.set(arg, cacheNode);
|
|
298
|
+
} else {
|
|
299
|
+
cacheNode = primitiveNode;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (cacheNode.s === 1 /* TERMINATED */) {
|
|
304
|
+
return cacheNode.v;
|
|
305
|
+
}
|
|
306
|
+
if (cacheNode.s === 2 /* ERRORED */) {
|
|
307
|
+
throw cacheNode.v;
|
|
308
|
+
}
|
|
309
|
+
try {
|
|
310
|
+
const result = fn.apply(this, args);
|
|
311
|
+
cacheNode.s = 1 /* TERMINATED */;
|
|
312
|
+
cacheNode.v = result;
|
|
313
|
+
return result;
|
|
314
|
+
} catch (error) {
|
|
315
|
+
cacheNode.s = 2 /* ERRORED */;
|
|
316
|
+
cacheNode.v = error;
|
|
317
|
+
throw error;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// src/next/index.ts
|
|
323
|
+
var evaluationCache = /* @__PURE__ */ new WeakMap();
|
|
324
|
+
function getCachedValuePromise(headers, flagKey, entitiesKey) {
|
|
325
|
+
const map = _optionalChain([evaluationCache, 'access', _4 => _4.get, 'call', _5 => _5(headers), 'optionalAccess', _6 => _6.get, 'call', _7 => _7(flagKey)]);
|
|
326
|
+
if (!map)
|
|
327
|
+
return void 0;
|
|
328
|
+
return map.get(entitiesKey);
|
|
329
|
+
}
|
|
330
|
+
function setCachedValuePromise(headers, flagKey, entitiesKey, flagValue) {
|
|
331
|
+
const byHeaders = evaluationCache.get(headers);
|
|
332
|
+
if (!byHeaders) {
|
|
333
|
+
evaluationCache.set(
|
|
334
|
+
headers,
|
|
335
|
+
/* @__PURE__ */ new Map([[flagKey, /* @__PURE__ */ new Map([[entitiesKey, flagValue]])]])
|
|
336
|
+
);
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
const byFlagKey = byHeaders.get(flagKey);
|
|
340
|
+
if (!byFlagKey) {
|
|
341
|
+
byHeaders.set(flagKey, /* @__PURE__ */ new Map([[entitiesKey, flagValue]]));
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
byFlagKey.set(entitiesKey, flagValue);
|
|
345
|
+
}
|
|
346
|
+
var transformMap = /* @__PURE__ */ new WeakMap();
|
|
347
|
+
var headersMap = /* @__PURE__ */ new WeakMap();
|
|
348
|
+
var cookiesMap = /* @__PURE__ */ new WeakMap();
|
|
349
|
+
var identifyArgsMap = /* @__PURE__ */ new WeakMap();
|
|
350
|
+
function transformToHeaders(incomingHeaders) {
|
|
351
|
+
const cached = transformMap.get(incomingHeaders);
|
|
352
|
+
if (cached !== void 0)
|
|
353
|
+
return cached;
|
|
354
|
+
const headers = new Headers();
|
|
355
|
+
for (const [key, value] of Object.entries(incomingHeaders)) {
|
|
356
|
+
if (Array.isArray(value)) {
|
|
357
|
+
value.forEach((item) => headers.append(key, item));
|
|
358
|
+
} else if (value !== void 0) {
|
|
359
|
+
headers.append(key, value);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
transformMap.set(incomingHeaders, headers);
|
|
363
|
+
return headers;
|
|
364
|
+
}
|
|
365
|
+
function sealHeaders(headers) {
|
|
366
|
+
const cached = headersMap.get(headers);
|
|
367
|
+
if (cached !== void 0)
|
|
368
|
+
return cached;
|
|
369
|
+
const sealed = _chunkD2GBVCQQcjs.HeadersAdapter.seal(headers);
|
|
370
|
+
headersMap.set(headers, sealed);
|
|
371
|
+
return sealed;
|
|
372
|
+
}
|
|
373
|
+
function sealCookies(headers) {
|
|
374
|
+
const cached = cookiesMap.get(headers);
|
|
375
|
+
if (cached !== void 0)
|
|
376
|
+
return cached;
|
|
377
|
+
const sealed = _chunkD2GBVCQQcjs.RequestCookiesAdapter.seal(new (0, _cookies.RequestCookies)(headers));
|
|
378
|
+
cookiesMap.set(headers, sealed);
|
|
379
|
+
return sealed;
|
|
380
|
+
}
|
|
381
|
+
function isIdentifyFunction(identify) {
|
|
382
|
+
return typeof identify === "function";
|
|
383
|
+
}
|
|
384
|
+
async function getEntities(identify, dedupeCacheKey, readonlyHeaders, readonlyCookies) {
|
|
385
|
+
if (!identify)
|
|
386
|
+
return void 0;
|
|
387
|
+
if (!isIdentifyFunction(identify))
|
|
388
|
+
return identify;
|
|
389
|
+
const args = identifyArgsMap.get(dedupeCacheKey);
|
|
390
|
+
if (args)
|
|
391
|
+
return identify(...args);
|
|
392
|
+
const nextArgs = [
|
|
393
|
+
{ headers: readonlyHeaders, cookies: readonlyCookies }
|
|
394
|
+
];
|
|
395
|
+
identifyArgsMap.set(dedupeCacheKey, nextArgs);
|
|
396
|
+
return identify(...nextArgs);
|
|
397
|
+
}
|
|
398
|
+
function getDecide(definition) {
|
|
399
|
+
return function decide(params) {
|
|
400
|
+
if (typeof definition.decide === "function") {
|
|
401
|
+
return definition.decide(params);
|
|
402
|
+
}
|
|
403
|
+
if (typeof _optionalChain([definition, 'access', _8 => _8.adapter, 'optionalAccess', _9 => _9.decide]) === "function") {
|
|
404
|
+
return definition.adapter.decide({ key: definition.key, ...params });
|
|
405
|
+
}
|
|
406
|
+
throw new Error(`flags: No decide function provided for ${definition.key}`);
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
function getIdentify(definition) {
|
|
410
|
+
return function identify(params) {
|
|
411
|
+
if (typeof definition.identify === "function") {
|
|
412
|
+
return definition.identify(params);
|
|
413
|
+
}
|
|
414
|
+
if (typeof _optionalChain([definition, 'access', _10 => _10.adapter, 'optionalAccess', _11 => _11.identify]) === "function") {
|
|
415
|
+
return definition.adapter.identify(params);
|
|
416
|
+
}
|
|
417
|
+
return definition.identify;
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
function getRun(definition, decide) {
|
|
421
|
+
return async function run(options) {
|
|
422
|
+
let readonlyHeaders;
|
|
423
|
+
let readonlyCookies;
|
|
424
|
+
let dedupeCacheKey;
|
|
425
|
+
if (options.request) {
|
|
426
|
+
const headers = transformToHeaders(options.request.headers);
|
|
427
|
+
readonlyHeaders = sealHeaders(headers);
|
|
428
|
+
readonlyCookies = sealCookies(headers);
|
|
429
|
+
dedupeCacheKey = options.request.headers;
|
|
430
|
+
} else {
|
|
431
|
+
const { headers, cookies } = await Promise.resolve().then(() => _interopRequireWildcard(require("next/headers")));
|
|
432
|
+
const [headersStore, cookiesStore] = await Promise.all([
|
|
433
|
+
headers(),
|
|
434
|
+
cookies()
|
|
435
|
+
]);
|
|
436
|
+
readonlyHeaders = headersStore;
|
|
437
|
+
readonlyCookies = cookiesStore;
|
|
438
|
+
dedupeCacheKey = headersStore;
|
|
439
|
+
}
|
|
440
|
+
const overrides = await getOverrides(
|
|
441
|
+
_optionalChain([readonlyCookies, 'access', _12 => _12.get, 'call', _13 => _13("vercel-flag-overrides"), 'optionalAccess', _14 => _14.value])
|
|
442
|
+
);
|
|
443
|
+
const entities = await getEntities(
|
|
444
|
+
options.identify,
|
|
445
|
+
dedupeCacheKey,
|
|
446
|
+
readonlyHeaders,
|
|
447
|
+
readonlyCookies
|
|
448
|
+
);
|
|
449
|
+
const entitiesKey = _nullishCoalesce(JSON.stringify(entities), () => ( ""));
|
|
450
|
+
const cachedValue = getCachedValuePromise(
|
|
451
|
+
readonlyHeaders,
|
|
452
|
+
definition.key,
|
|
453
|
+
entitiesKey
|
|
454
|
+
);
|
|
455
|
+
if (cachedValue !== void 0) {
|
|
456
|
+
_chunkD2GBVCQQcjs.setSpanAttribute.call(void 0, "method", "cached");
|
|
457
|
+
const value = await cachedValue;
|
|
458
|
+
return value;
|
|
459
|
+
}
|
|
460
|
+
if (overrides && overrides[definition.key] !== void 0) {
|
|
461
|
+
_chunkD2GBVCQQcjs.setSpanAttribute.call(void 0, "method", "override");
|
|
462
|
+
const decision2 = overrides[definition.key];
|
|
463
|
+
setCachedValuePromise(
|
|
464
|
+
readonlyHeaders,
|
|
465
|
+
definition.key,
|
|
466
|
+
entitiesKey,
|
|
467
|
+
Promise.resolve(decision2)
|
|
468
|
+
);
|
|
469
|
+
_chunkD2GBVCQQcjs.internalReportValue.call(void 0, definition.key, decision2, {
|
|
470
|
+
reason: "override"
|
|
471
|
+
});
|
|
472
|
+
return decision2;
|
|
473
|
+
}
|
|
474
|
+
const decisionPromise = (async () => {
|
|
475
|
+
return decide({
|
|
476
|
+
headers: readonlyHeaders,
|
|
477
|
+
cookies: readonlyCookies,
|
|
478
|
+
entities
|
|
479
|
+
});
|
|
480
|
+
})().then(
|
|
481
|
+
(value) => {
|
|
482
|
+
if (value !== void 0)
|
|
483
|
+
return value;
|
|
484
|
+
if (definition.defaultValue !== void 0)
|
|
485
|
+
return definition.defaultValue;
|
|
486
|
+
throw new Error(
|
|
487
|
+
`flags: Flag "${definition.key}" must have a defaultValue or a decide function that returns a value`
|
|
488
|
+
);
|
|
489
|
+
},
|
|
490
|
+
(error) => {
|
|
491
|
+
if (isInternalNextError(error))
|
|
492
|
+
throw error;
|
|
493
|
+
if (definition.defaultValue !== void 0) {
|
|
494
|
+
if (process.env.NODE_ENV === "development") {
|
|
495
|
+
console.info(
|
|
496
|
+
`flags: Flag "${definition.key}" is falling back to its defaultValue`
|
|
497
|
+
);
|
|
498
|
+
} else {
|
|
499
|
+
console.warn(
|
|
500
|
+
`flags: Flag "${definition.key}" is falling back to its defaultValue after catching the following error`,
|
|
501
|
+
error
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
return definition.defaultValue;
|
|
505
|
+
}
|
|
506
|
+
console.warn(
|
|
507
|
+
`flags: Flag "${definition.key}" could not be evaluated`
|
|
508
|
+
);
|
|
509
|
+
throw error;
|
|
510
|
+
}
|
|
511
|
+
);
|
|
512
|
+
setCachedValuePromise(
|
|
513
|
+
readonlyHeaders,
|
|
514
|
+
definition.key,
|
|
515
|
+
entitiesKey,
|
|
516
|
+
decisionPromise
|
|
517
|
+
);
|
|
518
|
+
const decision = await decisionPromise;
|
|
519
|
+
if (_optionalChain([definition, 'access', _15 => _15.config, 'optionalAccess', _16 => _16.reportValue]) !== false) {
|
|
520
|
+
_chunkD2GBVCQQcjs.reportValue.call(void 0, definition.key, decision);
|
|
521
|
+
}
|
|
522
|
+
return decision;
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
function getOrigin(definition) {
|
|
526
|
+
if (definition.origin)
|
|
527
|
+
return definition.origin;
|
|
528
|
+
if (typeof _optionalChain([definition, 'access', _17 => _17.adapter, 'optionalAccess', _18 => _18.origin]) === "function")
|
|
529
|
+
return definition.adapter.origin(definition.key);
|
|
530
|
+
return _optionalChain([definition, 'access', _19 => _19.adapter, 'optionalAccess', _20 => _20.origin]);
|
|
531
|
+
}
|
|
532
|
+
function flag(definition) {
|
|
533
|
+
const decide = getDecide(definition);
|
|
534
|
+
const identify = getIdentify(definition);
|
|
535
|
+
const run = getRun(definition, decide);
|
|
536
|
+
const origin = getOrigin(definition);
|
|
537
|
+
const flag2 = _chunkD2GBVCQQcjs.trace.call(void 0,
|
|
538
|
+
async (...args) => {
|
|
539
|
+
_chunkD2GBVCQQcjs.setSpanAttribute.call(void 0, "method", "decided");
|
|
540
|
+
if (typeof args[0] === "string" && Array.isArray(args[1])) {
|
|
541
|
+
const [precomputedCode, precomputedGroup, secret] = args;
|
|
542
|
+
if (precomputedCode && precomputedGroup) {
|
|
543
|
+
_chunkD2GBVCQQcjs.setSpanAttribute.call(void 0, "method", "precomputed");
|
|
544
|
+
return getPrecomputed(
|
|
545
|
+
flag2,
|
|
546
|
+
precomputedGroup,
|
|
547
|
+
precomputedCode,
|
|
548
|
+
secret
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (args[0] && typeof args[0] === "object" && "headers" in args[0]) {
|
|
553
|
+
const [request] = args;
|
|
554
|
+
return run({ identify, request });
|
|
555
|
+
}
|
|
556
|
+
return run({ identify, request: void 0 });
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
name: "flag",
|
|
560
|
+
isVerboseTrace: false,
|
|
561
|
+
attributes: { key: definition.key }
|
|
562
|
+
}
|
|
563
|
+
);
|
|
564
|
+
flag2.key = definition.key;
|
|
565
|
+
flag2.defaultValue = definition.defaultValue;
|
|
566
|
+
flag2.origin = origin;
|
|
567
|
+
flag2.options = _chunkAVMIIWOFcjs.normalizeOptions.call(void 0, definition.options);
|
|
568
|
+
flag2.description = definition.description;
|
|
569
|
+
flag2.identify = identify ? _chunkD2GBVCQQcjs.trace.call(void 0, identify, {
|
|
570
|
+
isVerboseTrace: false,
|
|
571
|
+
name: "identify",
|
|
572
|
+
attributes: { key: definition.key }
|
|
573
|
+
}) : identify;
|
|
574
|
+
flag2.decide = _chunkD2GBVCQQcjs.trace.call(void 0, decide, {
|
|
575
|
+
isVerboseTrace: false,
|
|
576
|
+
name: "decide",
|
|
577
|
+
attributes: { key: definition.key }
|
|
578
|
+
});
|
|
579
|
+
flag2.run = _chunkD2GBVCQQcjs.trace.call(void 0, run, {
|
|
580
|
+
isVerboseTrace: false,
|
|
581
|
+
name: "run",
|
|
582
|
+
attributes: { key: definition.key }
|
|
583
|
+
});
|
|
584
|
+
return flag2;
|
|
585
|
+
}
|
|
586
|
+
function getProviderData(flags) {
|
|
587
|
+
const definitions = Object.values(flags).filter((i) => !Array.isArray(i)).reduce((acc, d) => {
|
|
588
|
+
acc[d.key] = {
|
|
589
|
+
options: d.options,
|
|
590
|
+
origin: d.origin,
|
|
591
|
+
description: d.description,
|
|
592
|
+
defaultValue: d.defaultValue,
|
|
593
|
+
declaredInCode: true
|
|
594
|
+
};
|
|
595
|
+
return acc;
|
|
596
|
+
}, {});
|
|
597
|
+
return { definitions, hints: [] };
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
exports.combine = combine; exports.dedupe = dedupe; exports.deserialize = deserialize2; exports.evaluate = evaluate; exports.flag = flag; exports.generatePermutations = generatePermutations; exports.getPrecomputed = getPrecomputed; exports.getProviderData = getProviderData; exports.precompute = precompute; exports.serialize = serialize2;
|
|
611
|
+
//# sourceMappingURL=next.cjs.map
|