configcat-vue
Version:
A community-maintained SDK for integrating ConfigCat feature flags into Vue.js applications.
1,328 lines • 95.9 kB
JavaScript
import { defineComponent as bt, ref as Ct, inject as Nt, onBeforeMount as Rt, onUnmounted as Ft, renderSlot as ue } from "vue";
var ve;
(function(i) {
i[i.No = 0] = "No", i[i.Should = 1] = "Should", i[i.Force = 2] = "Force";
})(ve || (ve = {}));
var te;
(function(i) {
i[i.Boolean = 0] = "Boolean", i[i.String = 1] = "String", i[i.Int = 2] = "Int", i[i.Double = 3] = "Double";
})(te || (te = {}));
var ye;
(function(i) {
i[i.TextIsOneOf = 0] = "TextIsOneOf", i[i.TextIsNotOneOf = 1] = "TextIsNotOneOf", i[i.TextContainsAnyOf = 2] = "TextContainsAnyOf", i[i.TextNotContainsAnyOf = 3] = "TextNotContainsAnyOf", i[i.SemVerIsOneOf = 4] = "SemVerIsOneOf", i[i.SemVerIsNotOneOf = 5] = "SemVerIsNotOneOf", i[i.SemVerLess = 6] = "SemVerLess", i[i.SemVerLessOrEquals = 7] = "SemVerLessOrEquals", i[i.SemVerGreater = 8] = "SemVerGreater", i[i.SemVerGreaterOrEquals = 9] = "SemVerGreaterOrEquals", i[i.NumberEquals = 10] = "NumberEquals", i[i.NumberNotEquals = 11] = "NumberNotEquals", i[i.NumberLess = 12] = "NumberLess", i[i.NumberLessOrEquals = 13] = "NumberLessOrEquals", i[i.NumberGreater = 14] = "NumberGreater", i[i.NumberGreaterOrEquals = 15] = "NumberGreaterOrEquals", i[i.SensitiveTextIsOneOf = 16] = "SensitiveTextIsOneOf", i[i.SensitiveTextIsNotOneOf = 17] = "SensitiveTextIsNotOneOf", i[i.DateTimeBefore = 18] = "DateTimeBefore", i[i.DateTimeAfter = 19] = "DateTimeAfter", i[i.SensitiveTextEquals = 20] = "SensitiveTextEquals", i[i.SensitiveTextNotEquals = 21] = "SensitiveTextNotEquals", i[i.SensitiveTextStartsWithAnyOf = 22] = "SensitiveTextStartsWithAnyOf", i[i.SensitiveTextNotStartsWithAnyOf = 23] = "SensitiveTextNotStartsWithAnyOf", i[i.SensitiveTextEndsWithAnyOf = 24] = "SensitiveTextEndsWithAnyOf", i[i.SensitiveTextNotEndsWithAnyOf = 25] = "SensitiveTextNotEndsWithAnyOf", i[i.SensitiveArrayContainsAnyOf = 26] = "SensitiveArrayContainsAnyOf", i[i.SensitiveArrayNotContainsAnyOf = 27] = "SensitiveArrayNotContainsAnyOf", i[i.TextEquals = 28] = "TextEquals", i[i.TextNotEquals = 29] = "TextNotEquals", i[i.TextStartsWithAnyOf = 30] = "TextStartsWithAnyOf", i[i.TextNotStartsWithAnyOf = 31] = "TextNotStartsWithAnyOf", i[i.TextEndsWithAnyOf = 32] = "TextEndsWithAnyOf", i[i.TextNotEndsWithAnyOf = 33] = "TextNotEndsWithAnyOf", i[i.ArrayContainsAnyOf = 34] = "ArrayContainsAnyOf", i[i.ArrayNotContainsAnyOf = 35] = "ArrayNotContainsAnyOf";
})(ye || (ye = {}));
var me;
(function(i) {
i[i.Equals = 0] = "Equals", i[i.NotEquals = 1] = "NotEquals";
})(me || (me = {}));
var Ee;
(function(i) {
i[i.IsIn = 0] = "IsIn", i[i.IsNotIn = 1] = "IsNotIn";
})(Ee || (Ee = {}));
const Tn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
__proto__: null,
get PrerequisiteFlagComparator() {
return me;
},
get RedirectMode() {
return ve;
},
get SegmentComparator() {
return Ee;
},
get SettingType() {
return te;
},
get UserComparator() {
return ye;
}
}, Symbol.toStringTag, { value: "Module" }));
class O {
static equals(e, t) {
return e.httpETag && t.httpETag ? e.httpETag === t.httpETag : e.configJson === t.configJson;
}
constructor(e, t, n, s) {
this.configJson = e, this.config = t, this.timestamp = n, this.httpETag = s;
}
with(e) {
return new O(this.configJson, this.config, e, this.httpETag);
}
get isEmpty() {
return !this.config;
}
isExpired(e) {
return this === O.empty || this.timestamp + e < O.generateTimestamp();
}
static generateTimestamp() {
return (/* @__PURE__ */ new Date()).getTime();
}
static serialize(e) {
var t, n;
return e.timestamp + `
` + ((t = e.httpETag) !== null && t !== void 0 ? t : "") + `
` + ((n = e.configJson) !== null && n !== void 0 ? n : "");
}
static deserialize(e) {
const t = Array(2);
let n = 0;
for (let u = 0; u < t.length; u++) {
if (n = e.indexOf(`
`, n), n < 0)
throw new Error("Number of values is fewer than expected.");
t[u] = n++;
}
let s = t[0], r = e.substring(0, s);
const o = parseInt(r);
if (isNaN(o))
throw new Error("Invalid fetch time: " + r);
n = s + 1, s = t[1], r = e.substring(n, s);
const a = r.length > 0 ? r : void 0;
n = s + 1, r = e.substring(n);
let l, c;
return r.length > 0 && (l = U.deserialize(r), c = r), new O(c, l, o, a);
}
}
O.serializationFormatVersion = "v2";
O.empty = new O(void 0, void 0, 0, void 0);
class U {
static deserialize(e) {
const t = JSON.parse(e);
if (typeof t != "object" || !t)
throw new Error("Invalid config JSON content:" + e);
return new U(t);
}
constructor(e) {
var t, n;
this.preferences = e.p != null ? new Lt(e.p) : void 0, this.segments = (n = (t = e.s) === null || t === void 0 ? void 0 : t.map((s) => new kt(s))) !== null && n !== void 0 ? n : [], this.settings = e.f != null ? Object.entries(e.f).reduce((s, [r, o]) => (s[r] = new $(o, this), s), {}) : {};
}
get salt() {
var e;
return (e = this.preferences) === null || e === void 0 ? void 0 : e.salt;
}
}
class Lt {
constructor(e) {
this.baseUrl = e.u, this.redirectMode = e.r, this.salt = e.s;
}
}
class kt {
constructor(e) {
var t, n;
this.name = e.n, this.conditions = (n = (t = e.r) === null || t === void 0 ? void 0 : t.map((s) => new ot(s))) !== null && n !== void 0 ? n : [];
}
}
class Fe {
constructor(e, t = !1) {
this.value = t ? e.v : at(e.v), this.variationId = e.i;
}
}
class $ extends Fe {
constructor(e, t) {
var n, s, r, o, a, l;
super(e, e.t < 0), this.type = e.t, this.percentageOptionsAttribute = (n = e.a) !== null && n !== void 0 ? n : "Identifier", this.targetingRules = (r = (s = e.r) === null || s === void 0 ? void 0 : s.map((c) => new Dt(c, t))) !== null && r !== void 0 ? r : [], this.percentageOptions = (a = (o = e.p) === null || o === void 0 ? void 0 : o.map((c) => new rt(c))) !== null && a !== void 0 ? a : [], this.configJsonSalt = (l = t == null ? void 0 : t.salt) !== null && l !== void 0 ? l : "";
}
static fromValue(e) {
return new $({
t: -1,
v: e
});
}
}
class Dt {
constructor(e, t) {
var n, s;
this.conditions = (s = (n = e.c) === null || n === void 0 ? void 0 : n.map((r) => r.u != null ? new ot(r.u) : r.p != null ? new $t(r.p) : r.s != null ? new Pt(r.s, t) : void 0)) !== null && s !== void 0 ? s : [], this.then = e.p != null ? e.p.map((r) => new rt(r)) : new Fe(e.s);
}
}
class rt extends Fe {
constructor(e) {
super(e), this.percentage = e.p;
}
}
class ot {
constructor(e) {
var t, n;
this.type = "UserCondition", this.comparisonAttribute = e.a, this.comparator = e.c, this.comparisonValue = (n = (t = e.s) !== null && t !== void 0 ? t : e.d) !== null && n !== void 0 ? n : e.l;
}
}
class $t {
constructor(e) {
this.type = "PrerequisiteFlagCondition", this.prerequisiteFlagKey = e.f, this.comparator = e.c, this.comparisonValue = at(e.v);
}
}
class Pt {
constructor(e, t) {
this.type = "SegmentCondition", this.segment = t.segments[e.s], this.comparator = e.c;
}
}
function at(i) {
var e, t, n;
return (n = (t = (e = i.b) !== null && e !== void 0 ? e : i.s) !== null && t !== void 0 ? t : i.i) !== null && n !== void 0 ? n : i.d;
}
function Mt(i) {
return te[i];
}
var Oe;
(function(i) {
i[i.Fetched = 0] = "Fetched", i[i.NotModified = 1] = "NotModified", i[i.Errored = 2] = "Errored";
})(Oe || (Oe = {}));
class I {
constructor(e, t, n, s) {
this.status = e, this.config = t, this.errorMessage = n, this.errorException = s;
}
static success(e) {
return new I(0, e);
}
static notModified(e) {
return new I(1, e);
}
static error(e, t, n) {
return new I(2, e, t ?? "Unknown error.", n);
}
}
class b extends Error {
constructor(e, ...t) {
super(((n, s) => {
switch (n) {
case "abort":
return "Request was aborted.";
case "timeout":
const [r] = s;
return `Request timed out. Timeout value: ${r}ms`;
case "failure":
const [o] = s, a = "Request failed due to a network or protocol error.";
return o ? a + " " + (o instanceof Error ? o.message : o + "") : a;
}
})(e, t)), this.cause = e, this instanceof b || (Object.setPrototypeOf || ((n, s) => n.__proto__ = s))(this, b.prototype), this.args = t;
}
}
class N {
constructor(e, t) {
this.errorMessage = e, this.errorException = t;
}
get isSuccess() {
return this.errorMessage === null;
}
static from(e) {
return e.status !== 2 ? N.success() : N.failure(e.errorMessage, e.errorException);
}
static success() {
return new N(null);
}
static failure(e, t) {
return new N(e, t);
}
}
var ne;
(function(i) {
i[i.NoFlagData = 0] = "NoFlagData", i[i.HasLocalOverrideFlagDataOnly = 1] = "HasLocalOverrideFlagDataOnly", i[i.HasCachedFlagDataOnly = 2] = "HasCachedFlagDataOnly", i[i.HasUpToDateFlagData = 3] = "HasUpToDateFlagData";
})(ne || (ne = {}));
var Se;
(function(i) {
i[i.Online = 0] = "Online", i[i.Offline = 1] = "Offline", i[i.Disposed = 2] = "Disposed";
})(Se || (Se = {}));
function Ve(i) {
return Se[i];
}
class Le {
constructor(e, t) {
this.configFetcher = e, this.options = t, this.pendingFetch = null, this.cacheKey = t.getCacheKey(), this.configFetcher = e, this.options = t, this.status = t.offline ? 1 : 0;
}
dispose() {
this.status = 2;
}
get disposed() {
return this.status === 2;
}
async refreshConfigAsync() {
const e = await this.options.cache.get(this.cacheKey);
if (this.isOffline) {
const t = this.options.logger.configServiceCannotInitiateHttpCalls().toString();
return [N.failure(t), e];
} else {
const [t, n] = await this.refreshConfigCoreAsync(e);
return [N.from(t), n];
}
}
async refreshConfigCoreAsync(e) {
const t = await this.fetchAsync(e);
let n = !1;
const s = t.status === 0;
return (s || t.config.timestamp > e.timestamp && (!t.config.isEmpty || e.isEmpty)) && (await this.options.cache.set(this.cacheKey, t.config), n = s && !O.equals(t.config, e), e = t.config), this.onConfigFetched(t.config), n && this.onConfigChanged(t.config), [t, e];
}
onConfigFetched(e) {
this.options.logger.debug("config fetched");
}
onConfigChanged(e) {
var t;
this.options.logger.debug("config changed"), this.options.hooks.emit("configChanged", (t = e.config) !== null && t !== void 0 ? t : new U({}));
}
fetchAsync(e) {
var t;
return (t = this.pendingFetch) !== null && t !== void 0 ? t : this.pendingFetch = (async () => {
try {
return await this.fetchLogicAsync(e);
} finally {
this.pendingFetch = null;
}
})();
}
async fetchLogicAsync(e) {
var t;
const n = this.options;
n.logger.debug("ConfigServiceBase.fetchLogicAsync() - called.");
let s;
try {
const [r, o] = await this.fetchRequestAsync((t = e.httpETag) !== null && t !== void 0 ? t : null);
switch (r.statusCode) {
case 200:
return o instanceof U ? (n.logger.debug("ConfigServiceBase.fetchLogicAsync(): fetch was successful. Returning new config."), I.success(new O(r.body, o, O.generateTimestamp(), r.eTag))) : (s = n.logger.fetchReceived200WithInvalidBody(o).toString(), n.logger.debug(`ConfigServiceBase.fetchLogicAsync(): ${r.statusCode} ${r.reasonPhrase} was received but the HTTP response content was invalid. Returning null.`), I.error(e, s, o));
case 304:
return e.isEmpty ? (s = n.logger.fetchReceived304WhenLocalCacheIsEmpty(r.statusCode, r.reasonPhrase).toString(), n.logger.debug(`ConfigServiceBase.fetchLogicAsync(): ${r.statusCode} ${r.reasonPhrase} was received when no config is cached locally. Returning null.`), I.error(e, s)) : (n.logger.debug("ConfigServiceBase.fetchLogicAsync(): content was not modified. Returning last config with updated timestamp."), I.notModified(e.with(O.generateTimestamp())));
case 403:
case 404:
return s = n.logger.fetchFailedDueToInvalidSdkKey().toString(), n.logger.debug("ConfigServiceBase.fetchLogicAsync(): fetch was unsuccessful. Returning last config (if any) with updated timestamp."), I.error(e.with(O.generateTimestamp()), s);
default:
return s = n.logger.fetchFailedDueToUnexpectedHttpResponse(r.statusCode, r.reasonPhrase).toString(), n.logger.debug("ConfigServiceBase.fetchLogicAsync(): fetch was unsuccessful. Returning null."), I.error(e, s);
}
} catch (r) {
return s = (r instanceof b && r.cause === "timeout" ? n.logger.fetchFailedDueToRequestTimeout(r.args[0], r) : n.logger.fetchFailedDueToUnexpectedError(r)).toString(), n.logger.debug("ConfigServiceBase.fetchLogicAsync(): fetch was unsuccessful. Returning null."), I.error(e, s, r);
}
}
async fetchRequestAsync(e, t = 2) {
const n = this.options;
n.logger.debug("ConfigServiceBase.fetchRequestAsync() - called.");
for (let s = 0; ; s++) {
n.logger.debug(`ConfigServiceBase.fetchRequestAsync(): calling fetchLogic()${s > 0 ? `, retry ${s}/${t}` : ""}`);
const r = await this.configFetcher.fetchLogic(n, e);
if (r.statusCode !== 200)
return [r];
if (!r.body)
return n.logger.debug("ConfigServiceBase.fetchRequestAsync(): no response body."), [r, new Error("No response body.")];
let o;
try {
o = U.deserialize(r.body);
} catch (u) {
return n.logger.debug("ConfigServiceBase.fetchRequestAsync(): invalid response body."), [r, u];
}
const a = o.preferences;
if (!a)
return n.logger.debug("ConfigServiceBase.fetchRequestAsync(): preferences is empty."), [r, o];
const l = a.baseUrl;
if (!l || l === n.baseUrl)
return n.logger.debug("ConfigServiceBase.fetchRequestAsync(): baseUrl OK."), [r, o];
const c = a.redirectMode;
if (n.baseUrlOverriden && c !== 2)
return n.logger.debug("ConfigServiceBase.fetchRequestAsync(): options.baseUrlOverriden && redirect !== 2."), [r, o];
if (n.baseUrl = l, c === 0)
return [r, o];
if (c === 1 && n.logger.dataGovernanceIsOutOfSync(), s >= t)
return n.logger.fetchFailedDueToRedirectLoop(), [r, o];
}
}
get isOfflineExactly() {
return this.status === 1;
}
get isOffline() {
return this.status !== 0;
}
setOnlineCore() {
}
setOnline() {
this.status === 1 ? (this.setOnlineCore(), this.status = 0, this.options.logger.configServiceStatusChanged(Ve(this.status))) : this.disposed && this.options.logger.configServiceMethodHasNoEffectDueToDisposedClient("setOnline");
}
setOfflineCore() {
}
setOffline() {
this.status === 0 ? (this.setOfflineCore(), this.status = 1, this.options.logger.configServiceStatusChanged(Ve(this.status))) : this.disposed && this.options.logger.configServiceMethodHasNoEffectDueToDisposedClient("setOffline");
}
syncUpWithCache() {
return this.options.cache.get(this.cacheKey);
}
async getReadyPromise(e, t) {
const n = await t(e);
return this.options.hooks.emit("clientReady", n), n;
}
}
class he {
constructor() {
this.callbacks = [];
}
get aborted() {
return !this.callbacks;
}
abort() {
if (!this.aborted) {
const e = this.callbacks;
this.callbacks = null;
for (const t of e)
t();
}
}
registerCallback(e) {
return this.aborted ? (e(), () => {
}) : (this.callbacks.push(e), () => {
const t = this.callbacks;
let n;
t && (n = t.indexOf(e)) >= 0 && t.splice(n, 1);
});
}
}
function qe(i, e) {
let t;
return new Promise((n) => {
const s = e == null ? void 0 : e.registerCallback(() => {
clearTimeout(t), n(!1);
});
t = setTimeout(() => {
s == null || s(), n(!0);
}, i);
});
}
function D(i, e = !1) {
return i instanceof Error ? e && i.stack ? i.stack : i.toString() : i + "";
}
function Be(i) {
throw i;
}
function x(i) {
return Array.isArray(i);
}
function ke(i) {
return x(i) && !i.some((e) => typeof e != "string");
}
function De(i, e = 0, t, n = ", ") {
const s = i.length;
if (!s)
return "";
let r = "";
return e > 0 && s > e && (i = i.slice(0, e), t && (r = t(s - e))), "'" + i.join("'" + n + "'") + "'" + r;
}
function Ut(i) {
return typeof (i == null ? void 0 : i.then) == "function";
}
function K(i) {
function e(o, a) {
const l = o.charCodeAt(a);
if (55296 <= l && l < 56320) {
const c = o.charCodeAt(a + 1);
if (56320 <= c && c <= 57343)
return (l << 10) + c - 56613888;
}
return l;
}
let t = "", n = 0;
const s = String.fromCharCode;
let r;
for (r = 0; r < i.length; r++) {
const o = e(i, r);
o <= 127 || (t += i.slice(n, r), o <= 2047 ? (t += s(192 | o >> 6), t += s(128 | o & 63)) : o <= 65535 ? (t += s(224 | o >> 12), t += s(128 | o >> 6 & 63), t += s(128 | o & 63)) : (t += s(240 | o >> 18), t += s(128 | o >> 12 & 63), t += s(128 | o >> 6 & 63), t += s(128 | o & 63), ++r), n = r + 1);
}
return t += i.slice(n, r);
}
function $e(i) {
return typeof i == "number" ? i : typeof i != "string" || !i.length || /^\s*$|^\s*0[^\d.e]/.test(i) ? NaN : +i;
}
const xt = 500;
class _t extends Le {
constructor(e, t) {
super(e, t), this.signalInitialization = () => {
}, this.stopToken = new he(), this.pollIntervalMs = t.pollIntervalSeconds * 1e3, this.pollExpirationMs = this.pollIntervalMs - xt;
const n = this.syncUpWithCache();
if (t.maxInitWaitTimeSeconds !== 0) {
this.initialized = !1;
const s = new Promise((r) => this.signalInitialization = r);
this.initializationPromise = this.waitForInitializationAsync(s).then((r) => (this.initialized = !0, r));
} else
this.initialized = !0, this.initializationPromise = Promise.resolve(!1);
this.readyPromise = this.getReadyPromise(this.initializationPromise, async (s) => (await s, this.getCacheState(this.options.cache.getInMemory()))), t.offline || this.startRefreshWorker(n, this.stopToken);
}
async waitForInitializationAsync(e) {
if (this.options.maxInitWaitTimeSeconds < 0)
return await e, !0;
const t = new he(), n = await Promise.race([
e.then(() => !0),
qe(this.options.maxInitWaitTimeSeconds * 1e3, t).then(() => !1)
]);
return t.abort(), n;
}
async getConfig() {
this.options.logger.debug("AutoPollConfigService.getConfig() called.");
function e(n) {
n.debug("AutoPollConfigService.getConfig() - returning value from cache.");
}
let t;
if (!this.isOffline && !this.initialized) {
if (t = await this.options.cache.get(this.cacheKey), !t.isExpired(this.pollIntervalMs))
return e(this.options.logger), t;
this.options.logger.debug("AutoPollConfigService.getConfig() - cache is empty or expired, waiting for initialization."), await this.initializationPromise;
}
return t = await this.options.cache.get(this.cacheKey), t.isExpired(this.pollIntervalMs) ? this.options.logger.debug("AutoPollConfigService.getConfig() - cache is empty or expired.") : e(this.options.logger), t;
}
refreshConfigAsync() {
return this.options.logger.debug("AutoPollConfigService.refreshConfigAsync() called."), super.refreshConfigAsync();
}
dispose() {
this.options.logger.debug("AutoPollConfigService.dispose() called."), super.dispose(), this.stopToken.aborted || this.stopRefreshWorker();
}
onConfigFetched(e) {
this.signalInitialization(), super.onConfigFetched(e);
}
setOnlineCore() {
this.startRefreshWorker(null, this.stopToken);
}
setOfflineCore() {
this.stopRefreshWorker(), this.stopToken = new he();
}
async startRefreshWorker(e, t) {
this.options.logger.debug("AutoPollConfigService.startRefreshWorker() called.");
let n = !0;
for (; !t.aborted; ) {
try {
const s = (/* @__PURE__ */ new Date()).getTime() + this.pollIntervalMs;
try {
await this.refreshWorkerLogic(n, e);
} catch (o) {
this.options.logger.autoPollConfigServiceErrorDuringPolling(o);
}
const r = s - (/* @__PURE__ */ new Date()).getTime();
r > 0 && await qe(r, t);
} catch (s) {
this.options.logger.autoPollConfigServiceErrorDuringPolling(s);
}
n = !1, e = null;
}
}
stopRefreshWorker() {
this.options.logger.debug("AutoPollConfigService.stopRefreshWorker() called."), this.stopToken.abort();
}
async refreshWorkerLogic(e, t) {
this.options.logger.debug("AutoPollConfigService.refreshWorkerLogic() - called.");
const n = await (t ?? this.options.cache.get(this.cacheKey));
n.isExpired(this.pollExpirationMs) ? (e ? !this.isOfflineExactly : !this.isOffline) && await this.refreshConfigCoreAsync(n) : e && this.signalInitialization();
}
getCacheState(e) {
return e.isEmpty ? 0 : e.isExpired(this.pollIntervalMs) ? 2 : 3;
}
}
class lt {
constructor() {
this.cachedConfig = O.empty;
}
set(e, t) {
this.cachedConfig = t;
}
get(e) {
return this.cachedConfig;
}
getInMemory() {
return this.cachedConfig;
}
}
class ae {
constructor(e, t) {
this.cache = e, this.logger = t, this.cachedConfig = O.empty;
}
async set(e, t) {
try {
if (!t.isEmpty)
this.cachedSerializedConfig = O.serialize(t), this.cachedConfig = t;
else {
this.cachedSerializedConfig = void 0, this.cachedConfig = t;
return;
}
await this.cache.set(e, this.cachedSerializedConfig);
} catch (n) {
this.logger.configServiceCacheWriteError(n);
}
}
updateCachedConfig(e) {
e == null || e === this.cachedSerializedConfig || (this.cachedConfig = O.deserialize(e), this.cachedSerializedConfig = e);
}
get(e) {
try {
const t = this.cache.get(e);
if (Ut(t))
return (async (n) => {
try {
this.updateCachedConfig(await n);
} catch (s) {
this.logger.configServiceCacheReadError(s);
}
return this.cachedConfig;
})(t);
this.updateCachedConfig(t);
} catch (t) {
this.logger.configServiceCacheReadError(t);
}
return Promise.resolve(this.cachedConfig);
}
getInMemory() {
return this.cachedConfig;
}
}
var Ae;
(function(i) {
i[i.Debug = 4] = "Debug", i[i.Info = 3] = "Info", i[i.Warn = 2] = "Warn", i[i.Error = 1] = "Error", i[i.Off = -1] = "Off";
})(Ae || (Ae = {}));
function Vt(i) {
return Ae[i];
}
class y {
static from(...e) {
return (t, ...n) => new y(t, e, n);
}
constructor(e, t, n) {
this.strings = e, this.argNames = t, this.argValues = n;
}
get defaultFormattedMessage() {
let e = this.cachedDefaultFormattedMessage;
if (e === void 0) {
e = "";
const { strings: t, argValues: n } = this;
let s = 0;
for (; s < t.length - 1; s++)
e += t[s], e += n[s];
e += t[s], this.cachedDefaultFormattedMessage = e;
}
return e;
}
toString() {
return this.defaultFormattedMessage;
}
}
class qt {
get level() {
var e;
return (e = this.logger.level) !== null && e !== void 0 ? e : 2;
}
get eol() {
var e;
return (e = this.logger.eol) !== null && e !== void 0 ? e : `
`;
}
constructor(e, t) {
this.logger = e, this.hooks = t;
}
isEnabled(e) {
return this.level >= e;
}
log(e, t, n, s) {
var r;
return this.isEnabled(e) && this.logger.log(e, t, n, s), e === 1 && ((r = this.hooks) === null || r === void 0 || r.emit("clientError", n.toString(), s)), n;
}
debug(e) {
this.log(4, 0, e);
}
configJsonIsNotPresent(e) {
return this.log(1, 1e3, y.from("DEFAULT_RETURN_VALUE")`Config JSON is not present. Returning ${e}.`);
}
configJsonIsNotPresentSingle(e, t, n) {
return this.log(1, 1e3, y.from("KEY", "DEFAULT_PARAM_NAME", "DEFAULT_PARAM_VALUE")`Config JSON is not present when evaluating setting '${e}'. Returning the \`${t}\` parameter that you specified in your application: '${n}'.`);
}
settingEvaluationFailedDueToMissingKey(e, t, n, s) {
return this.log(1, 1001, y.from("KEY", "DEFAULT_PARAM_NAME", "DEFAULT_PARAM_VALUE", "AVAILABLE_KEYS")`Failed to evaluate setting '${e}' (the key was not found in config JSON). Returning the \`${t}\` parameter that you specified in your application: '${n}'. Available keys: [${s}].`);
}
settingEvaluationError(e, t, n) {
return this.log(1, 1002, y.from("METHOD_NAME", "DEFAULT_RETURN_VALUE")`Error occurred in the \`${e}\` method. Returning ${t}.`, n);
}
settingEvaluationErrorSingle(e, t, n, s, r) {
return this.log(1, 1002, y.from("METHOD_NAME", "KEY", "DEFAULT_PARAM_NAME", "DEFAULT_PARAM_VALUE")`Error occurred in the \`${e}\` method while evaluating setting '${t}'. Returning the \`${n}\` parameter that you specified in your application: '${s}'.`, r);
}
forceRefreshError(e, t) {
return this.log(1, 1003, y.from("METHOD_NAME")`Error occurred in the \`${e}\` method.`, t);
}
fetchFailedDueToInvalidSdkKey() {
return this.log(1, 1100, "Your SDK Key seems to be wrong. You can find the valid SDK Key at https://app.configcat.com/sdkkey");
}
fetchFailedDueToUnexpectedHttpResponse(e, t) {
return this.log(1, 1101, y.from("STATUS_CODE", "REASON_PHRASE")`Unexpected HTTP response was received while trying to fetch config JSON: ${e} ${t}`);
}
fetchFailedDueToRequestTimeout(e, t) {
return this.log(1, 1102, y.from("TIMEOUT")`Request timed out while trying to fetch config JSON. Timeout value: ${e}ms`, t);
}
fetchFailedDueToUnexpectedError(e) {
return this.log(1, 1103, "Unexpected error occurred while trying to fetch config JSON. It is most likely due to a local network issue. Please make sure your application can reach the ConfigCat CDN servers (or your proxy server) over HTTP.", e);
}
fetchFailedDueToRedirectLoop() {
return this.log(1, 1104, "Redirection loop encountered while trying to fetch config JSON. Please contact us at https://configcat.com/support/");
}
fetchReceived200WithInvalidBody(e) {
return this.log(1, 1105, "Fetching config JSON was successful but the HTTP response content was invalid.", e);
}
fetchReceived304WhenLocalCacheIsEmpty(e, t) {
return this.log(1, 1106, y.from("STATUS_CODE", "REASON_PHRASE")`Unexpected HTTP response was received when no config JSON is cached locally: ${e} ${t}`);
}
autoPollConfigServiceErrorDuringPolling(e) {
return this.log(1, 1200, "Error occurred during auto polling.", e);
}
settingForVariationIdIsNotPresent(e) {
return this.log(1, 2011, y.from("VARIATION_ID")`Could not find the setting for the specified variation ID: '${e}'.`);
}
configServiceCacheReadError(e) {
return this.log(1, 2200, "Error occurred while reading the cache.", e);
}
configServiceCacheWriteError(e) {
return this.log(1, 2201, "Error occurred while writing the cache.", e);
}
clientIsAlreadyCreated(e) {
return this.log(2, 3e3, y.from("SDK_KEY")`There is an existing client instance for the specified SDK Key. No new client instance will be created and the specified options are ignored. Returning the existing client instance. SDK Key: '${e}'.`);
}
userObjectIsMissing(e) {
return this.log(2, 3001, y.from("KEY")`Cannot evaluate targeting rules and % options for setting '${e}' (User Object is missing). You should pass a User Object to the evaluation methods like \`getValueAsync()\` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/`);
}
dataGovernanceIsOutOfSync() {
return this.log(2, 3002, "The `dataGovernance` parameter specified at the client initialization is not in sync with the preferences on the ConfigCat Dashboard. Read more: https://configcat.com/docs/advanced/data-governance/");
}
userObjectAttributeIsMissingPercentage(e, t) {
return this.log(2, 3003, y.from("KEY", "ATTRIBUTE_NAME", "ATTRIBUTE_NAME")`Cannot evaluate % options for setting '${e}' (the User.${t} attribute is missing). You should set the User.${t} attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/`);
}
userObjectAttributeIsMissingCondition(e, t, n) {
return this.log(2, 3003, y.from("CONDITION", "KEY", "ATTRIBUTE_NAME", "ATTRIBUTE_NAME")`Cannot evaluate condition (${e}) for setting '${t}' (the User.${n} attribute is missing). You should set the User.${n} attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/`);
}
userObjectAttributeIsInvalid(e, t, n, s) {
return this.log(2, 3004, y.from("CONDITION", "KEY", "REASON", "ATTRIBUTE_NAME")`Cannot evaluate condition (${e}) for setting '${t}' (${n}). Please check the User.${s} attribute and make sure that its value corresponds to the comparison operator.`);
}
userObjectAttributeIsAutoConverted(e, t, n, s) {
return this.log(2, 3005, y.from("CONDITION", "KEY", "ATTRIBUTE_NAME", "ATTRIBUTE_VALUE")`Evaluation of condition (${e}) for setting '${t}' may not produce the expected result (the User.${n} attribute is not a string value, thus it was automatically converted to the string value '${s}'). Please make sure that using a non-string value was intended.`);
}
configServiceCannotInitiateHttpCalls() {
return this.log(2, 3200, "Client is in offline mode, it cannot initiate HTTP calls.");
}
configServiceMethodHasNoEffectDueToDisposedClient(e) {
return this.log(2, 3201, y.from("METHOD_NAME")`The client object is already disposed, thus \`${e}()\` has no effect.`);
}
configServiceMethodHasNoEffectDueToOverrideBehavior(e, t) {
return this.log(2, 3202, y.from("OVERRIDE_BEHAVIOR", "METHOD_NAME")`Client is configured to use the \`${e}\` override behavior, thus \`${t}()\` has no effect.`);
}
settingEvaluated(e) {
return this.log(3, 5e3, y.from("EVALUATE_LOG")`${e}`);
}
configServiceStatusChanged(e) {
return this.log(3, 5200, y.from("MODE")`Switched to ${e.toUpperCase()} mode.`);
}
}
class ct {
constructor(e = 2, t = `
`) {
this.level = e, this.eol = t, this.SOURCE = "ConfigCat";
}
log(e, t, n, s) {
const [r, o] = e === 4 ? [console.info, "DEBUG"] : e === 3 ? [console.info, "INFO"] : e === 2 ? [console.warn, "WARN"] : e === 1 ? [console.error, "ERROR"] : [console.log, Vt(e).toUpperCase()], a = s !== void 0 ? this.eol + D(s, !0) : "";
r(`${this.SOURCE} - ${o} - [${t}] ${n}${a}`);
}
}
class we {
constructor() {
this.addListener = this.on, this.off = this.removeListener;
}
on() {
return this;
}
once() {
return this;
}
removeListener() {
return this;
}
removeAllListeners() {
return this;
}
listeners() {
return [];
}
listenerCount() {
return 0;
}
eventNames() {
return [];
}
emit() {
return !1;
}
}
function ut(i) {
function e(F, L) {
var J = F << L | F >>> 32 - L;
return J;
}
var t, n, s, r = new Array(80), o = 1732584193, a = 4023233417, l = 2562383102, c = 271733878, u = 3285377520, h, g, f, p, m, A;
i = K(i);
var E = i.length, w = new Array();
for (n = 0; n < E - 3; n += 4)
s = i.charCodeAt(n) << 24 | i.charCodeAt(n + 1) << 16 | i.charCodeAt(n + 2) << 8 | i.charCodeAt(n + 3), w.push(s);
switch (E % 4) {
case 0:
n = 2147483648;
break;
case 1:
n = i.charCodeAt(E - 1) << 24 | 8388608;
break;
case 2:
n = i.charCodeAt(E - 2) << 24 | i.charCodeAt(E - 1) << 16 | 32768;
break;
case 3:
n = i.charCodeAt(E - 3) << 24 | i.charCodeAt(E - 2) << 16 | i.charCodeAt(E - 1) << 8 | 128;
break;
}
for (w.push(n); w.length % 16 != 14; )
w.push(0);
for (w.push(E >>> 29), w.push(E << 3 & 4294967295), t = 0; t < w.length; t += 16) {
for (n = 0; n < 16; n++)
r[n] = w[t + n];
for (n = 16; n <= 79; n++)
r[n] = e(r[n - 3] ^ r[n - 8] ^ r[n - 14] ^ r[n - 16], 1);
for (h = o, g = a, f = l, p = c, m = u, n = 0; n <= 19; n++)
A = e(h, 5) + (g & f | ~g & p) + m + r[n] + 1518500249 & 4294967295, m = p, p = f, f = e(g, 30), g = h, h = A;
for (n = 20; n <= 39; n++)
A = e(h, 5) + (g ^ f ^ p) + m + r[n] + 1859775393 & 4294967295, m = p, p = f, f = e(g, 30), g = h, h = A;
for (n = 40; n <= 59; n++)
A = e(h, 5) + (g & f | g & p | f & p) + m + r[n] + 2400959708 & 4294967295, m = p, p = f, f = e(g, 30), g = h, h = A;
for (n = 60; n <= 79; n++)
A = e(h, 5) + (g ^ f ^ p) + m + r[n] + 3395469782 & 4294967295, m = p, p = f, f = e(g, 30), g = h, h = A;
o = o + h & 4294967295, a = a + g & 4294967295, l = l + f & 4294967295, c = c + p & 4294967295, u = u + m & 4294967295;
}
return gt([o, a, l, c, u]);
}
function ht(i) {
function e(xe, _e) {
return xe >>> _e | xe << 32 - _e;
}
const t = "length";
var n = Math.pow, s = n(2, 32), r, o, a = ht, l = a.h, c = a.k;
if (!c) {
l = [], c = [];
for (var u = {}, h = 2, g = 0; g < 64; h++)
if (!u[h]) {
for (r = 0; r < 313; r += h)
u[r] = h;
l[g] = n(h, 0.5) * s | 0, c[g++] = n(h, 1 / 3) * s | 0;
}
a.h = l = l.slice(0, 8), a.k = c;
}
var f = i[t] * 8;
i += "";
for (var p = []; i[t] % 64 - 56; )
i += "\0";
for (r = 0; r < i[t]; r++)
o = i.charCodeAt(r), p[r >> 2] |= o << (3 - r) % 4 * 8;
for (p[p[t]] = f / s | 0, p[p[t]] = f, o = 0; o < p[t]; ) {
var m = p.slice(o, o += 16), A = l;
for (l = l.slice(0, 8), r = 0; r < 64; r++) {
var E = m[r - 15], w = m[r - 2], F = l[0], L = l[4], J = l[7] + (e(L, 6) ^ e(L, 11) ^ e(L, 25)) + (L & l[5] ^ ~L & l[6]) + c[r] + (m[r] = r < 16 ? m[r] : m[r - 16] + (e(E, 7) ^ e(E, 18) ^ E >>> 3) + m[r - 7] + (e(w, 17) ^ e(w, 19) ^ w >>> 10) | 0), It = (e(F, 2) ^ e(F, 13) ^ e(F, 22)) + (F & l[1] ^ F & l[2] ^ l[1] & l[2]);
l = [J + It | 0].concat(l), l[4] = l[4] + J | 0;
}
for (r = 0; r < 8; r++)
l[r] = l[r] + A[r] | 0;
}
return gt(l, 8);
}
function gt(i, e) {
const t = "0123456789abcdef";
var n = "";
e ?? (e = i.length);
for (let s = 0; s < e; s++)
for (let r = 3; r >= 0; r--) {
const o = i[s] >> (r << 3) & 255;
n += t[o >> 4], n += t[o & 15];
}
return n;
}
const We = new we();
class Ke {
constructor(e) {
this.addListener = this.on, this.off = this.removeListener, this.eventEmitter = e;
}
tryDisconnect() {
const e = this.eventEmitter;
return this.eventEmitter = We, e !== We;
}
on(e, t) {
return this.eventEmitter.on(e, t), this;
}
once(e, t) {
return this.eventEmitter.once(e, t), this;
}
removeListener(e, t) {
return this.eventEmitter.removeListener(e, t), this;
}
removeAllListeners(e) {
return this.eventEmitter.removeAllListeners(e), this;
}
listeners(e) {
return this.eventEmitter.listeners(e);
}
listenerCount(e) {
return this.eventEmitter.listenerCount(e);
}
eventNames() {
return this.eventEmitter.eventNames();
}
emit(e, ...t) {
return this.eventEmitter.emit(e, ...t);
}
}
function ft() {
const i = function(e) {
this.target = e;
};
return i.prototype.deref = function() {
return this.target;
}, i.isFallback = !0, i;
}
const dt = () => typeof WeakRef == "function";
var Te;
(function(i) {
i[i.AutoPoll = 0] = "AutoPoll", i[i.LazyLoad = 1] = "LazyLoad", i[i.ManualPoll = 2] = "ManualPoll";
})(Te || (Te = {}));
var He;
(function(i) {
i[i.Global = 0] = "Global", i[i.EuOnly = 1] = "EuOnly";
})(He || (He = {}));
class P {
constructor(e, t, n, s, r) {
var o, a, l;
if (this.requestTimeoutMs = 3e4, this.baseUrlOverriden = !1, this.offline = !1, !e)
throw new Error("Invalid 'sdkKey' value");
switch (this.sdkKey = e, this.clientVersion = t, this.dataGovernance = (o = n == null ? void 0 : n.dataGovernance) !== null && o !== void 0 ? o : 0, this.dataGovernance) {
case 1:
this.baseUrl = "https://cdn-eu.configcat.com";
break;
default:
this.baseUrl = "https://cdn-global.configcat.com";
break;
}
const c = (a = r == null ? void 0 : r()) !== null && a !== void 0 ? a : new we(), u = new Ke(c), h = new (dt() ? WeakRef : ft())(u);
this.hooks = {
hooks: u,
hooksWeakRef: h,
emit(p, ...m) {
var A, E;
return (E = (A = this.hooksWeakRef.deref()) === null || A === void 0 ? void 0 : A.emit(p, ...m)) !== null && E !== void 0 ? E : !1;
}
};
let g, f;
if (n) {
if (g = n.logger, f = n.cache, n.requestTimeoutMs) {
if (n.requestTimeoutMs < 0)
throw new Error("Invalid 'requestTimeoutMs' value");
this.requestTimeoutMs = n.requestTimeoutMs;
}
n.baseUrl && (this.baseUrl = n.baseUrl, this.baseUrlOverriden = !0), n.flagOverrides && (this.flagOverrides = n.flagOverrides), n.defaultUser && (this.defaultUser = n.defaultUser), n.offline && (this.offline = n.offline), (l = n.setupHooks) === null || l === void 0 || l.call(n, u);
}
this.logger = new qt(g ?? new ct(), this.hooks), this.cache = f ? new ae(f, this.logger) : s ? s(this) : new lt();
}
yieldHooks() {
const e = this.hooks, t = e.hooks;
return delete e.hooks, t ?? new Ke(new we());
}
getUrl() {
return this.baseUrl + "/configuration-files/" + this.sdkKey + "/" + P.configFileName + "?sdk=" + this.clientVersion;
}
getCacheKey() {
return ut(`${this.sdkKey}_${P.configFileName}_${O.serializationFormatVersion}`);
}
}
P.configFileName = "config_v6.json";
class ze extends P {
constructor(e, t, n, s, r, o) {
super(e, t + "/a-" + n, s, r, o), this.pollIntervalSeconds = 60, this.maxInitWaitTimeSeconds = 5, s && (s.pollIntervalSeconds != null && (this.pollIntervalSeconds = s.pollIntervalSeconds), s.maxInitWaitTimeSeconds != null && (this.maxInitWaitTimeSeconds = s.maxInitWaitTimeSeconds));
const a = 2147483;
if (!(typeof this.pollIntervalSeconds == "number" && 1 <= this.pollIntervalSeconds && this.pollIntervalSeconds <= a))
throw new Error("Invalid 'pollIntervalSeconds' value");
if (!(typeof this.maxInitWaitTimeSeconds == "number" && this.maxInitWaitTimeSeconds <= a))
throw new Error("Invalid 'maxInitWaitTimeSeconds' value");
}
}
class je extends P {
constructor(e, t, n, s, r, o) {
super(e, t + "/m-" + n, s, r, o);
}
}
class Je extends P {
constructor(e, t, n, s, r, o) {
if (super(e, t + "/l-" + n, s, r, o), this.cacheTimeToLiveSeconds = 60, s && s.cacheTimeToLiveSeconds != null && (this.cacheTimeToLiveSeconds = s.cacheTimeToLiveSeconds), !(typeof this.cacheTimeToLiveSeconds == "number" && 1 <= this.cacheTimeToLiveSeconds && this.cacheTimeToLiveSeconds <= 2147483647))
throw new Error("Invalid 'cacheTimeToLiveSeconds' value");
}
}
var Ie;
(function(i) {
i[i.LocalOnly = 0] = "LocalOnly", i[i.LocalOverRemote = 1] = "LocalOverRemote", i[i.RemoteOverLocal = 2] = "RemoteOverLocal";
})(Ie || (Ie = {}));
function Bt(i) {
return Ie[i];
}
class Wt {
constructor(e, t) {
this.initialSettings = Ge(e), t && (this.map = e);
}
getOverrides() {
return Promise.resolve(this.getOverridesSync());
}
getOverridesSync() {
return this.map ? Ge(this.map) : this.initialSettings;
}
}
function Ge(i) {
const e = {};
for (const t in i)
Object.prototype.hasOwnProperty.call(i, t) && (e[t] = $.fromValue(i[t]));
return e;
}
const Kt = "cc-", G = ";str";
class Ht {
get currentValue() {
if (!(typeof location > "u"))
return location.search;
}
}
let Y;
class zt {
constructor(e, t, n) {
this.watchChanges = e, this.paramPrefix = t ?? Kt, n ?? (n = Y ?? (Y = new Ht())), this.queryStringProvider = n;
const s = n.currentValue;
this.settings = Qe(s, this.paramPrefix), this.queryString = Ye(s);
}
getOverrides() {
return Promise.resolve(this.getOverridesSync());
}
getOverridesSync() {
if (this.watchChanges) {
const e = this.queryStringProvider.currentValue, t = Ye(e);
this.queryString !== t && (this.settings = Qe(e, this.paramPrefix), this.queryString = t);
}
return this.settings;
}
}
function Ye(i) {
if (i == null)
return "";
if (typeof i == "string")
return i;
let e = "", t = "?";
for (const n in i) {
if (!Object.prototype.hasOwnProperty.call(i, n))
continue;
const s = i[n];
let r, o;
if (!x(s))
r = s, o = 1;
else if (s.length)
r = s[0], o = s.length;
else
continue;
for (let a = 0; e += t + encodeURIComponent(n) + "=" + encodeURIComponent(r), !(++a >= o); )
t = "&", r = s[a];
}
return e;
}
function Qe(i, e) {
const t = {};
return typeof i == "string" ? Jt(i, e, t) : i != null && jt(i, e, t), t;
}
function jt(i, e, t) {
for (const n in i) {
if (!Object.prototype.hasOwnProperty.call(i, n))
continue;
const s = i[n];
let r, o;
if (!x(s))
r = s, o = 1;
else if (s.length)
r = s[0], o = s.length;
else
continue;
for (let a = 0; pt(n, r, e, t), !(++a >= o); )
r = s[a];
}
}
function Jt(i, e, t) {
if (!i || i.lastIndexOf("?", 0) < 0)
return;
const n = i.substring(1).split("&");
for (let s of n) {
s = s.replace(/\+/g, " ");
const r = s.indexOf("="), o = decodeURIComponent(r >= 0 ? s.substring(0, r) : s), a = r >= 0 ? decodeURIComponent(s.substring(r + 1)) : "";
pt(o, a, e, t);
}
}
function pt(i, e, t, n) {
if (!i || i.length <= t.length || i.lastIndexOf(t, 0) < 0)
return;
i = i.substring(t.length), i.length > G.length && i.indexOf(G, i.length - G.length) >= 0 ? i = i.substring(0, i.length - G.length) : e = Gt(e), n[i] = $.fromValue(e);
}
function Gt(i) {
switch (i.toLowerCase()) {
case "false":
return !1;
case "true":
return !0;
default:
const e = $e(i);
return isNaN(e) ? i : e;
}
}
class Yt extends Le {
constructor(e, t) {
super(e, t), this.cacheTimeToLiveMs = t.cacheTimeToLiveSeconds * 1e3;
const n = this.syncUpWithCache();
this.readyPromise = this.getReadyPromise(n, async (s) => this.getCacheState(await s));
}
async getConfig() {
this.options.logger.debug("LazyLoadConfigService.getConfig() called.");
function e(n, s = "") {
n.debug(`LazyLoadConfigService.getConfig(): cache is empty or expired${s}.`);
}
let t = await this.options.cache.get(this.cacheKey);
return t.isExpired(this.cacheTimeToLiveMs) ? (this.isOffline ? e(this.options.logger) : (e(this.options.logger, ", calling refreshConfigCoreAsync()"), [, t] = await this.refreshConfigCoreAsync(t)), t) : (this.options.logger.debug("LazyLoadConfigService.getConfig(): cache is valid, returning from cache."), t);
}
refreshConfigAsync() {
return this.options.logger.debug("LazyLoadConfigService.refreshConfigAsync() called."), super.refreshConfigAsync();
}
getCacheState(e) {
return e.isEmpty ? 0 : e.isExpired(this.cacheTimeToLiveMs) ? 2 : 3;
}
}
class Qt extends Le {
constructor(e, t) {
super(e, t);
const n = this.syncUpWithCache();
this.readyPromise = this.getReadyPromise(n, async (s) => this.getCacheState(await s));
}
getCacheState(e) {
return e.isEmpty ? 0 : 2;
}
async getConfig() {
return this.options.logger.debug("ManualPollService.getConfig() called."), await this.options.cache.get(this.cacheKey);
}
refreshConfigAsync() {
return this.options.logger.debug("ManualPollService.refreshConfigAsync() called."), super.refreshConfigAsync();
}
}
const vt = "<invalid value>", ge = "<invalid name>", Pe = "<invalid operator>", Xe = "<invalid reference>", Xt = 10;
class yt {
constructor(e) {
this.eol = e, this.log = "", this.indent = "";
}
resetIndent() {
return this.indent = "", this;
}
increaseIndent() {
return this.indent += " ", this;
}
decreaseIndent() {
return this.indent = this.indent.slice(0, -2), this;
}
newLine(e) {
return this.log += this.eol + this.indent + (e ?? ""), this;
}
append(e) {
return this.log += e, this;
}
toString() {
return this.log;
}
appendUserConditionCore(e, t, n) {
return this.append(`User.${e} ${fe(t)} '${n ?? vt}'`);
}
appendUserConditionString(e, t, n, s) {
return typeof n != "string" ? this.appendUserConditionCore(e, t) : this.appendUserConditionCore(e, t, s ? "<hashed value>" : n);
}
appendUserConditionStringList(e, t, n, s) {
if (!ke(n))
return this.appendUserConditionCore(e, t);
const r = "value", o = "values", a = fe(t);
if (s)
return this.append(`User.${e} ${a} [<${n.length} hashed ${n.length === 1 ? r : o}>]`);
{
const l = De(n, Xt, (c) => `, ... <${c} more ${c === 1 ? r : o}>`);
return this.append(`User.${e} ${a} [${l}]`);
}
}
appendUserConditionNumber(e, t, n, s) {
if (typeof n != "number")
return this.appendUserConditionCore(e, t);
const r = fe(t);
let o;
return s && !isNaN(o = new Date(n * 1e3)) ? this.append(`User.${e} ${r} '${n}' (${o.toISOString()} UTC)`) : this.append(`User.${e} ${r} '${n}'`);
}
appendUserCondition(e) {
const t = typeof e.comparisonAttribute == "string" ? e.comparisonAttribute : ge, n = e.comparator;
switch (e.comparator) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 30:
case 31:
case 32:
case 33:
case 34:
case 35:
return this.appendUserConditionStringList(t, n, e.comparisonValue, !1);
case 6:
case 7:
case 8:
case 9:
case 28:
case 29:
return this.appendUserConditionString(t, n, e.comparisonValue, !1);
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
return this.appendUserConditionNumber(t, n, e.comparisonValue);
case 16:
case 17:
case 22:
case 23:
case 24:
case 25:
case 26:
case 27:
return this.appendUserConditionStringList(t, n, e.comparisonValue, !0);
case 18:
case 19:
return this.appendUserConditionNumber(t, n, e.comparisonValue, !0);
case 20:
case 21:
return this.appendUserConditionString(t, n, e.comparisonValue, !0);
default:
return this.appendUserConditionCore(t, n, e.comparisonValue);
}
}
appendPrerequisiteFlagCondition(e, t) {
const n = typeof e.prerequisiteFlagKey != "string" ? ge : e.prerequisiteFlagKey in t ? e.prerequisiteFlagKey : Xe, s = e.comparator, r = e.comparisonValue;
return this.append(`Flag '${n}' ${Zt(s)} '${ie(r)}'`);
}
appendSegmentCondition(e) {
const t = e.segment, n = e.comparator, s = t == null ? Xe : typeof t.name != "string" || !t.name ? ge : t.name;
return this.append(`User ${mt(n)} '${s}'`);
}
appendConditionResult(e) {
return this.append(`${e}`);
}
appendConditionConsequence(e) {
return this.append(" => ").appendConditionResult(e), e ? this : this.append(", skipping the remaining AND conditions");
}
appendTargetingRuleThenPart(e, t) {
(t ? this.newLine() : this.append(" ")).append("THEN");
const n = e.then;
return this.append(x(n) ? " % options" : ` '${ie(n.value)}'`);
}
appendTargetingRuleConsequence(e, t, n) {
return this.increaseIndent(), this.appendTargetingRuleThenPart(e, n).append(" => ").append(t === !0 ? "MATCH, applying rule" : t === !1 ? "no match" : t), this.decreaseIndent();
}
}
function fe(i) {
switch (i) {
case 0:
case 16:
case 4:
return "IS ONE OF";
case 1:
case 17:
case 5:
return "IS NOT ONE OF";
case 2:
return "CONTAINS ANY OF";
case 3:
return "NOT CONTAINS ANY OF";
case 6:
case 12:
return "<";
case 7:
case 13:
return "<=";
case 8:
case 14:
return ">";
case 9:
case 15:
return ">=";
case 10:
return "=";
case 11:
return "!=";
case 18:
return "BEFORE";
case 19:
return "AFTER";
case 28:
case 20:
return "EQUALS";
case 29:
case 21:
return "NOT EQUALS";
case 30:
case 22:
return "STARTS WITH ANY OF";
case 31:
case 23:
return "NOT STARTS WITH ANY OF";
case 32:
case 24:
return "ENDS WITH ANY OF";
case 33:
case 25:
return "NOT ENDS WITH ANY OF";
case 34:
case 26:
return "ARRAY CONTAINS ANY OF";
case 35:
case 27:
return "ARRAY NOT CONTAINS ANY OF";
default:
return Pe;
}
}
function Me(i) {
return new yt("").appendUserCondition(i).toString();
}
function Zt(i) {
switch (i) {
case 0:
return "EQUALS";
case 1:
return "NOT EQUALS";
default:
return Pe;
}
}
function mt(i) {
switch (i) {
case 0:
return "IS IN SEGMENT";
case 1:
return "IS NOT IN SEGMENT";
default:
return Pe;
}
}
function ie(i) {
return z(i) ? i.toString() : vt;
}
const Ze = /^[0-9]+$/, _ = (i, e) => {
const t = Ze.test(i), n = Ze.test(e);
return t && n && (i = +i, e = +e), i === e ? 0 : t && !n ? -1 : n && !t ? 1 : i < e ? -1 : 1;
}, be = 256, Q = Number.MAX_SAFE_INTEGER || 9007199254740991, H = [], v = [], d = {};
let en = 0;
const S = (i, e) => {
const t = en++;
d[i] = t, v[t] = e, H[t] = new RegExp(e);
};
S("NUMERICIDENTIFIER", "0|[1-9]\\d*");
S("NUMERICIDENTIFIERLOOSE", "[0-9]+");
S("NONNUMERICIDENTIFIER", "\\d*[a-zA-Z-][a-zA-Z0-9-]*");
S("MAINVERSION", `(${v[d.NUMERICIDENTIFIER]})\\.(${v[d.NUMERICIDENTIFIER]})\\.(${v[d.NUMERICIDENTIFIER]})`);
S("MAINVERSIONLOOSE", `(${v[d.NUMERICIDENTIFIERLOOSE]})\\.(${v[d.NUMERICIDENTIFIERLOOSE]})\\.(${v[d.NUMERICIDENTIFIERLOOSE]})`);
S("PRERELEASEIDENTIFIER", `(?:${v[d.NUMERICIDENTIFIER]}|${v[d.NONNUMERICIDENTIFIER]})`);
S("PRERELEASEIDENTIFIERLOOSE", `(?:${v[d.NUMERICIDENTIFIERLOOSE]}|${v[d.NONNUMERICIDENTIFIER]})`);
S("PRERELEASE", `(?:-(${v[d.PRERELEASEIDENTIFIER]}(?:\\.${v[d.PRERELEASEIDENTIFIER]})*))`);
S("PRERELEASELOOSE", `(?:-?(${v[d.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${v[d.PRERELEASEIDENTIFIERLOOSE]})*))`);
S("BUILDIDENTIFIER", "[0-9A-Za-z-]+");
S("BUILD", `(?:\\+(${v[d.BUILDIDENTIFIER