pepr 0.53.1 → 0.54.0-nightly.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/dist/cli/build/build.helpers.d.ts +7 -0
- package/dist/cli/build/build.helpers.d.ts.map +1 -1
- package/dist/cli/build/index.d.ts.map +1 -1
- package/dist/cli/update/index.d.ts.map +1 -1
- package/dist/cli.js +119 -13
- package/dist/controller.js +1 -1
- package/dist/lib/assets/webhooks.d.ts +1 -0
- package/dist/lib/assets/webhooks.d.ts.map +1 -1
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/features/FeatureFlags.d.ts +12 -0
- package/dist/lib/features/FeatureFlags.d.ts.map +1 -0
- package/dist/lib/features/store.d.ts +13 -0
- package/dist/lib/features/store.d.ts.map +1 -0
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib.js +94 -13
- package/dist/lib.js.map +3 -3
- package/package.json +7 -7
- package/src/cli/build/build.helpers.ts +23 -1
- package/src/cli/build/index.ts +6 -1
- package/src/cli/update/index.ts +2 -1
- package/src/cli.ts +12 -0
- package/src/lib/assets/webhooks.ts +7 -0
- package/src/lib/controller/index.ts +8 -0
- package/src/lib/core/capability.ts +11 -11
- package/src/lib/core/queue.ts +1 -1
- package/src/lib/features/FeatureFlags.ts +23 -0
- package/src/lib/features/store.ts +92 -0
- package/src/lib/helpers.ts +8 -7
- package/src/lib/telemetry/metrics.ts +1 -1
- package/src/templates/capabilities/hello-pepr.ts +4 -6
package/dist/lib.js
CHANGED
|
@@ -569,9 +569,9 @@ var Capability = class {
|
|
|
569
569
|
const isNotEmpty = (value) => Object.keys(value).length > 0;
|
|
570
570
|
const log = (message, cbString) => {
|
|
571
571
|
const filteredObj = (0, import_ramda2.pickBy)(isNotEmpty, binding.filters);
|
|
572
|
-
logger_default.info(`${message} configured for ${binding.event}
|
|
573
|
-
logger_default.info(
|
|
574
|
-
logger_default.debug(
|
|
572
|
+
logger_default.info({ prefix }, `${message} configured for ${binding.event}`);
|
|
573
|
+
logger_default.info({ prefix }, JSON.stringify(filteredObj));
|
|
574
|
+
logger_default.debug({ prefix }, cbString);
|
|
575
575
|
};
|
|
576
576
|
function Validate(validateCallback) {
|
|
577
577
|
if (registerAdmission) {
|
|
@@ -676,42 +676,42 @@ var Capability = class {
|
|
|
676
676
|
}
|
|
677
677
|
}
|
|
678
678
|
function InNamespace(...namespaces) {
|
|
679
|
-
logger_default.debug(`Add namespaces filter ${namespaces}
|
|
679
|
+
logger_default.debug({ prefix }, `Add namespaces filter ${namespaces}`);
|
|
680
680
|
binding.filters.namespaces.push(...namespaces);
|
|
681
681
|
return { ...commonChain, WithName, WithNameRegex };
|
|
682
682
|
}
|
|
683
683
|
function InNamespaceRegex(...namespaces) {
|
|
684
|
-
logger_default.debug(`Add regex namespaces filter ${namespaces}
|
|
684
|
+
logger_default.debug({ prefix }, `Add regex namespaces filter ${namespaces}`);
|
|
685
685
|
binding.filters.regexNamespaces.push(...namespaces.map((regex) => regex.source));
|
|
686
686
|
return { ...commonChain, WithName, WithNameRegex };
|
|
687
687
|
}
|
|
688
688
|
function WithDeletionTimestamp() {
|
|
689
|
-
logger_default.debug("Add deletionTimestamp filter");
|
|
689
|
+
logger_default.debug({ prefix }, "Add deletionTimestamp filter");
|
|
690
690
|
binding.filters.deletionTimestamp = true;
|
|
691
691
|
return commonChain;
|
|
692
692
|
}
|
|
693
693
|
function WithNameRegex(regexName) {
|
|
694
|
-
logger_default.debug(`Add regex name filter ${regexName}
|
|
694
|
+
logger_default.debug({ prefix }, `Add regex name filter ${regexName}`);
|
|
695
695
|
binding.filters.regexName = regexName.source;
|
|
696
696
|
return commonChain;
|
|
697
697
|
}
|
|
698
698
|
function WithName(name) {
|
|
699
|
-
logger_default.debug(`Add name filter ${name}
|
|
699
|
+
logger_default.debug({ prefix }, `Add name filter ${name}`);
|
|
700
700
|
binding.filters.name = name;
|
|
701
701
|
return commonChain;
|
|
702
702
|
}
|
|
703
703
|
function WithLabel(key, value = "") {
|
|
704
|
-
logger_default.debug(`Add label filter ${key}=${value}
|
|
704
|
+
logger_default.debug({ prefix }, `Add label filter ${key}=${value}`);
|
|
705
705
|
binding.filters.labels[key] = value;
|
|
706
706
|
return commonChain;
|
|
707
707
|
}
|
|
708
708
|
function WithAnnotation(key, value = "") {
|
|
709
|
-
logger_default.debug(`Add annotation filter ${key}=${value}
|
|
709
|
+
logger_default.debug({ prefix }, `Add annotation filter ${key}=${value}`);
|
|
710
710
|
binding.filters.annotations[key] = value;
|
|
711
711
|
return commonChain;
|
|
712
712
|
}
|
|
713
713
|
function Alias(alias) {
|
|
714
|
-
logger_default.debug(`Adding prefix alias ${alias}
|
|
714
|
+
logger_default.debug({ prefix }, `Adding prefix alias ${alias}`);
|
|
715
715
|
binding.alias = alias;
|
|
716
716
|
return commonChain;
|
|
717
717
|
}
|
|
@@ -782,7 +782,7 @@ var MetricsCollector = class {
|
|
|
782
782
|
#getMetricName = (name) => `${this.#prefix}_${name}`;
|
|
783
783
|
#addMetric = (collection, MetricType, { name, help, labelNames }) => {
|
|
784
784
|
if (collection.has(this.#getMetricName(name))) {
|
|
785
|
-
logger_default.debug(`Metric for ${name} already exists
|
|
785
|
+
logger_default.debug({ loggingPrefix }, `Metric for ${name} already exists`);
|
|
786
786
|
return;
|
|
787
787
|
}
|
|
788
788
|
const metric = new MetricType({
|
|
@@ -1959,6 +1959,81 @@ function karForValidate(ar, vr) {
|
|
|
1959
1959
|
};
|
|
1960
1960
|
}
|
|
1961
1961
|
|
|
1962
|
+
// src/lib/features/FeatureFlags.ts
|
|
1963
|
+
var FeatureFlags = {
|
|
1964
|
+
REFERENCE_FLAG: {
|
|
1965
|
+
key: "reference_flag",
|
|
1966
|
+
metadata: {
|
|
1967
|
+
name: "Reference Flag",
|
|
1968
|
+
description: "A feature flag to show intended usage.",
|
|
1969
|
+
defaultValue: false
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
};
|
|
1973
|
+
|
|
1974
|
+
// src/lib/features/store.ts
|
|
1975
|
+
var FeatureStore = class {
|
|
1976
|
+
featureFlagLimit = 4;
|
|
1977
|
+
features = {};
|
|
1978
|
+
addFeature(key, value) {
|
|
1979
|
+
if (!key || value === void 0 || value === "") return;
|
|
1980
|
+
const validKeys = Object.values(FeatureFlags).filter((f) => f?.key).map((f) => f.key);
|
|
1981
|
+
if (!validKeys.includes(key)) {
|
|
1982
|
+
throw new Error(`Unknown feature flag: ${key}`);
|
|
1983
|
+
}
|
|
1984
|
+
const lowerValue = value.toLowerCase();
|
|
1985
|
+
if (lowerValue === "true") {
|
|
1986
|
+
this.features[key] = true;
|
|
1987
|
+
} else if (lowerValue === "false") {
|
|
1988
|
+
this.features[key] = false;
|
|
1989
|
+
} else if (!isNaN(Number(value))) {
|
|
1990
|
+
this.features[key] = Number(value);
|
|
1991
|
+
} else {
|
|
1992
|
+
this.features[key] = value;
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
get(key) {
|
|
1996
|
+
if (!Object.values(FeatureFlags).some((f) => f?.key === key)) {
|
|
1997
|
+
throw new Error(`Unknown feature flag: ${key}`);
|
|
1998
|
+
}
|
|
1999
|
+
if (!(key in this.features)) {
|
|
2000
|
+
throw new Error(`Feature flag '${key}' exists but has not been set`);
|
|
2001
|
+
}
|
|
2002
|
+
return this.features[key];
|
|
2003
|
+
}
|
|
2004
|
+
getAll() {
|
|
2005
|
+
return { ...this.features };
|
|
2006
|
+
}
|
|
2007
|
+
initialize(featuresStr, env = process.env) {
|
|
2008
|
+
Object.keys(env).filter((key) => key.startsWith("PEPR_FEATURE_")).forEach((key) => {
|
|
2009
|
+
this.addFeature(key.replace("PEPR_FEATURE_", "").toLowerCase(), env[key] || "");
|
|
2010
|
+
});
|
|
2011
|
+
if (featuresStr) {
|
|
2012
|
+
featuresStr.split(",").map((feature) => feature.split("=")).filter((parts) => parts.length === 2).forEach(([key, value]) => {
|
|
2013
|
+
this.addFeature(key.trim(), value.trim());
|
|
2014
|
+
});
|
|
2015
|
+
}
|
|
2016
|
+
this.applyDefaultValues();
|
|
2017
|
+
this.validateFeatureCount();
|
|
2018
|
+
}
|
|
2019
|
+
applyDefaultValues() {
|
|
2020
|
+
Object.values(FeatureFlags).filter(
|
|
2021
|
+
(feature) => feature?.key && feature?.metadata?.defaultValue !== void 0 && !(feature.key in this.features)
|
|
2022
|
+
).forEach((feature) => {
|
|
2023
|
+
this.features[feature.key] = feature.metadata.defaultValue;
|
|
2024
|
+
});
|
|
2025
|
+
}
|
|
2026
|
+
validateFeatureCount() {
|
|
2027
|
+
const featureCount = Object.keys(this.features).length;
|
|
2028
|
+
if (featureCount > this.featureFlagLimit) {
|
|
2029
|
+
throw new Error(
|
|
2030
|
+
`Too many feature flags active: ${featureCount} (maximum: ${this.featureFlagLimit}). Use of more than ${this.featureFlagLimit} feature flags is not supported.`
|
|
2031
|
+
);
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
};
|
|
2035
|
+
var featureFlagStore = new FeatureStore();
|
|
2036
|
+
|
|
1962
2037
|
// src/lib/controller/index.ts
|
|
1963
2038
|
if (!process.env.PEPR_NODE_WARNINGS) {
|
|
1964
2039
|
process.removeAllListeners("warning");
|
|
@@ -2010,6 +2085,12 @@ var Controller = class _Controller {
|
|
|
2010
2085
|
"Cannot start Pepr module: Pepr module was not instantiated with deferStart=true"
|
|
2011
2086
|
);
|
|
2012
2087
|
}
|
|
2088
|
+
try {
|
|
2089
|
+
featureFlagStore.initialize();
|
|
2090
|
+
logger_default.info(`Feature flag store initialized: ${JSON.stringify(featureFlagStore.getAll())}`);
|
|
2091
|
+
} catch (error) {
|
|
2092
|
+
logger_default.warn(error, "Could not initialize feature flags");
|
|
2093
|
+
}
|
|
2013
2094
|
const options = {
|
|
2014
2095
|
key: import_fs.default.readFileSync(process.env.SSL_KEY_PATH || "/etc/certs/tls.key"),
|
|
2015
2096
|
cert: import_fs.default.readFileSync(process.env.SSL_CERT_PATH || "/etc/certs/tls.crt")
|
|
@@ -2262,7 +2343,7 @@ var Queue = class {
|
|
|
2262
2343
|
logger_default.debug(note, "Reconciled");
|
|
2263
2344
|
element.resolve();
|
|
2264
2345
|
} catch (e) {
|
|
2265
|
-
logger_default.debug(`Error reconciling ${element.item.metadata.name}
|
|
2346
|
+
logger_default.debug({ error: e }, `Error reconciling ${element.item.metadata.name}`);
|
|
2266
2347
|
element.reject(e);
|
|
2267
2348
|
} finally {
|
|
2268
2349
|
logger_default.debug(this.stats(), "Queue stats - shift");
|