@aws-lambda-powertools/feature-flags 0.0.0 → 2.37.0
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/README.md +70 -4
- package/lib/cjs/FeatureFlags.d.ts +98 -0
- package/lib/cjs/FeatureFlags.d.ts.map +1 -0
- package/lib/cjs/FeatureFlags.js +260 -0
- package/lib/cjs/appconfig/appConfigStore.d.ts +38 -0
- package/lib/cjs/appconfig/appConfigStore.d.ts.map +1 -0
- package/lib/cjs/appconfig/appConfigStore.js +65 -0
- package/lib/cjs/appconfig/index.d.ts +4 -0
- package/lib/cjs/appconfig/index.d.ts.map +1 -0
- package/lib/cjs/appconfig/index.js +5 -0
- package/lib/cjs/appconfig-agent/appConfigAgentStore.d.ts +37 -0
- package/lib/cjs/appconfig-agent/appConfigAgentStore.d.ts.map +1 -0
- package/lib/cjs/appconfig-agent/appConfigAgentStore.js +59 -0
- package/lib/cjs/appconfig-agent/appConfigVariantStore.d.ts +46 -0
- package/lib/cjs/appconfig-agent/appConfigVariantStore.d.ts.map +1 -0
- package/lib/cjs/appconfig-agent/appConfigVariantStore.js +176 -0
- package/lib/cjs/appconfig-agent/index.d.ts +6 -0
- package/lib/cjs/appconfig-agent/index.d.ts.map +1 -0
- package/lib/cjs/appconfig-agent/index.js +8 -0
- package/lib/cjs/constants.d.ts +56 -0
- package/lib/cjs/constants.d.ts.map +1 -0
- package/lib/cjs/constants.js +86 -0
- package/lib/cjs/context.d.ts +21 -0
- package/lib/cjs/context.d.ts.map +1 -0
- package/lib/cjs/context.js +42 -0
- package/lib/cjs/envelope/index.d.ts +20 -0
- package/lib/cjs/envelope/index.d.ts.map +1 -0
- package/lib/cjs/envelope/index.js +29 -0
- package/lib/cjs/errors.d.ts +74 -0
- package/lib/cjs/errors.d.ts.map +1 -0
- package/lib/cjs/errors.js +116 -0
- package/lib/cjs/index.d.ts +6 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +15 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/parameters-stores/classify.d.ts +20 -0
- package/lib/cjs/parameters-stores/classify.d.ts.map +1 -0
- package/lib/cjs/parameters-stores/classify.js +50 -0
- package/lib/cjs/parameters-stores/createDocumentSource.d.ts +17 -0
- package/lib/cjs/parameters-stores/createDocumentSource.d.ts.map +1 -0
- package/lib/cjs/parameters-stores/createDocumentSource.js +31 -0
- package/lib/cjs/parameters-stores/envelope.d.ts +22 -0
- package/lib/cjs/parameters-stores/envelope.d.ts.map +1 -0
- package/lib/cjs/parameters-stores/envelope.js +39 -0
- package/lib/cjs/ruleEngine/actions.d.ts +5 -0
- package/lib/cjs/ruleEngine/actions.d.ts.map +1 -0
- package/lib/cjs/ruleEngine/actions.js +155 -0
- package/lib/cjs/ruleEngine/datetime.d.ts +12 -0
- package/lib/cjs/ruleEngine/datetime.d.ts.map +1 -0
- package/lib/cjs/ruleEngine/datetime.js +134 -0
- package/lib/cjs/ruleEngine/evaluate.d.ts +15 -0
- package/lib/cjs/ruleEngine/evaluate.d.ts.map +1 -0
- package/lib/cjs/ruleEngine/evaluate.js +60 -0
- package/lib/cjs/ruleEngine/guards.d.ts +51 -0
- package/lib/cjs/ruleEngine/guards.d.ts.map +1 -0
- package/lib/cjs/ruleEngine/guards.js +123 -0
- package/lib/cjs/ruleEngine/index.d.ts +35 -0
- package/lib/cjs/ruleEngine/index.d.ts.map +1 -0
- package/lib/cjs/ruleEngine/index.js +70 -0
- package/lib/cjs/ruleEngine/json.d.ts +16 -0
- package/lib/cjs/ruleEngine/json.d.ts.map +1 -0
- package/lib/cjs/ruleEngine/json.js +38 -0
- package/lib/cjs/ruleEngine/time.d.ts +14 -0
- package/lib/cjs/ruleEngine/time.d.ts.map +1 -0
- package/lib/cjs/ruleEngine/time.js +102 -0
- package/lib/cjs/ruleEngine/validate.d.ts +11 -0
- package/lib/cjs/ruleEngine/validate.d.ts.map +1 -0
- package/lib/cjs/ruleEngine/validate.js +134 -0
- package/lib/cjs/ruleEngine/validateScheduleAndModulo.d.ts +13 -0
- package/lib/cjs/ruleEngine/validateScheduleAndModulo.d.ts.map +1 -0
- package/lib/cjs/ruleEngine/validateScheduleAndModulo.js +38 -0
- package/lib/cjs/ruleEngine/validationCache.d.ts +12 -0
- package/lib/cjs/ruleEngine/validationCache.d.ts.map +1 -0
- package/lib/cjs/ruleEngine/validationCache.js +29 -0
- package/lib/cjs/types/AppConfigAgentStore.d.ts +20 -0
- package/lib/cjs/types/AppConfigAgentStore.d.ts.map +1 -0
- package/lib/cjs/types/AppConfigAgentStore.js +2 -0
- package/lib/cjs/types/AppConfigStore.d.ts +25 -0
- package/lib/cjs/types/AppConfigStore.d.ts.map +1 -0
- package/lib/cjs/types/AppConfigStore.js +2 -0
- package/lib/cjs/types/AppConfigVariantStore.d.ts +16 -0
- package/lib/cjs/types/AppConfigVariantStore.d.ts.map +1 -0
- package/lib/cjs/types/AppConfigVariantStore.js +2 -0
- package/lib/cjs/types/Envelope.d.ts +16 -0
- package/lib/cjs/types/Envelope.d.ts.map +1 -0
- package/lib/cjs/types/Envelope.js +2 -0
- package/lib/cjs/types/RuleEngine.d.ts +83 -0
- package/lib/cjs/types/RuleEngine.d.ts.map +1 -0
- package/lib/cjs/types/RuleEngine.js +2 -0
- package/lib/cjs/types/VariantEvaluation.d.ts +20 -0
- package/lib/cjs/types/VariantEvaluation.d.ts.map +1 -0
- package/lib/cjs/types/VariantEvaluation.js +2 -0
- package/lib/cjs/types/index.d.ts +81 -0
- package/lib/cjs/types/index.d.ts.map +1 -0
- package/lib/cjs/types/index.js +2 -0
- package/lib/cjs/variant.d.ts +9 -0
- package/lib/cjs/variant.d.ts.map +1 -0
- package/lib/cjs/variant.js +26 -0
- package/lib/esm/FeatureFlags.d.ts +98 -0
- package/lib/esm/FeatureFlags.d.ts.map +1 -0
- package/lib/esm/FeatureFlags.js +257 -0
- package/lib/esm/appconfig/appConfigStore.d.ts +38 -0
- package/lib/esm/appconfig/appConfigStore.d.ts.map +1 -0
- package/lib/esm/appconfig/appConfigStore.js +62 -0
- package/lib/esm/appconfig/index.d.ts +4 -0
- package/lib/esm/appconfig/index.d.ts.map +1 -0
- package/lib/esm/appconfig/index.js +1 -0
- package/lib/esm/appconfig-agent/appConfigAgentStore.d.ts +37 -0
- package/lib/esm/appconfig-agent/appConfigAgentStore.d.ts.map +1 -0
- package/lib/esm/appconfig-agent/appConfigAgentStore.js +56 -0
- package/lib/esm/appconfig-agent/appConfigVariantStore.d.ts +46 -0
- package/lib/esm/appconfig-agent/appConfigVariantStore.d.ts.map +1 -0
- package/lib/esm/appconfig-agent/appConfigVariantStore.js +172 -0
- package/lib/esm/appconfig-agent/index.d.ts +6 -0
- package/lib/esm/appconfig-agent/index.d.ts.map +1 -0
- package/lib/esm/appconfig-agent/index.js +2 -0
- package/lib/esm/constants.d.ts +56 -0
- package/lib/esm/constants.d.ts.map +1 -0
- package/lib/esm/constants.js +77 -0
- package/lib/esm/context.d.ts +21 -0
- package/lib/esm/context.d.ts.map +1 -0
- package/lib/esm/context.js +37 -0
- package/lib/esm/envelope/index.d.ts +20 -0
- package/lib/esm/envelope/index.d.ts.map +1 -0
- package/lib/esm/envelope/index.js +26 -0
- package/lib/esm/errors.d.ts +74 -0
- package/lib/esm/errors.d.ts.map +1 -0
- package/lib/esm/errors.js +107 -0
- package/lib/esm/index.d.ts +6 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +3 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/parameters-stores/classify.d.ts +20 -0
- package/lib/esm/parameters-stores/classify.d.ts.map +1 -0
- package/lib/esm/parameters-stores/classify.js +47 -0
- package/lib/esm/parameters-stores/createDocumentSource.d.ts +17 -0
- package/lib/esm/parameters-stores/createDocumentSource.d.ts.map +1 -0
- package/lib/esm/parameters-stores/createDocumentSource.js +28 -0
- package/lib/esm/parameters-stores/envelope.d.ts +22 -0
- package/lib/esm/parameters-stores/envelope.d.ts.map +1 -0
- package/lib/esm/parameters-stores/envelope.js +35 -0
- package/lib/esm/ruleEngine/actions.d.ts +5 -0
- package/lib/esm/ruleEngine/actions.d.ts.map +1 -0
- package/lib/esm/ruleEngine/actions.js +152 -0
- package/lib/esm/ruleEngine/datetime.d.ts +12 -0
- package/lib/esm/ruleEngine/datetime.d.ts.map +1 -0
- package/lib/esm/ruleEngine/datetime.js +131 -0
- package/lib/esm/ruleEngine/evaluate.d.ts +15 -0
- package/lib/esm/ruleEngine/evaluate.d.ts.map +1 -0
- package/lib/esm/ruleEngine/evaluate.js +57 -0
- package/lib/esm/ruleEngine/guards.d.ts +51 -0
- package/lib/esm/ruleEngine/guards.d.ts.map +1 -0
- package/lib/esm/ruleEngine/guards.js +113 -0
- package/lib/esm/ruleEngine/index.d.ts +35 -0
- package/lib/esm/ruleEngine/index.d.ts.map +1 -0
- package/lib/esm/ruleEngine/index.js +67 -0
- package/lib/esm/ruleEngine/json.d.ts +16 -0
- package/lib/esm/ruleEngine/json.d.ts.map +1 -0
- package/lib/esm/ruleEngine/json.js +34 -0
- package/lib/esm/ruleEngine/time.d.ts +14 -0
- package/lib/esm/ruleEngine/time.d.ts.map +1 -0
- package/lib/esm/ruleEngine/time.js +97 -0
- package/lib/esm/ruleEngine/validate.d.ts +11 -0
- package/lib/esm/ruleEngine/validate.d.ts.map +1 -0
- package/lib/esm/ruleEngine/validate.js +131 -0
- package/lib/esm/ruleEngine/validateScheduleAndModulo.d.ts +13 -0
- package/lib/esm/ruleEngine/validateScheduleAndModulo.d.ts.map +1 -0
- package/lib/esm/ruleEngine/validateScheduleAndModulo.js +35 -0
- package/lib/esm/ruleEngine/validationCache.d.ts +12 -0
- package/lib/esm/ruleEngine/validationCache.d.ts.map +1 -0
- package/lib/esm/ruleEngine/validationCache.js +26 -0
- package/lib/esm/types/AppConfigAgentStore.d.ts +20 -0
- package/lib/esm/types/AppConfigAgentStore.d.ts.map +1 -0
- package/lib/esm/types/AppConfigStore.d.ts +25 -0
- package/lib/esm/types/AppConfigStore.d.ts.map +1 -0
- package/lib/esm/types/AppConfigStore.js +1 -0
- package/lib/esm/types/AppConfigVariantStore.d.ts +16 -0
- package/lib/esm/types/AppConfigVariantStore.d.ts.map +1 -0
- package/lib/esm/types/AppConfigVariantStore.js +1 -0
- package/lib/esm/types/Envelope.d.ts +16 -0
- package/lib/esm/types/Envelope.d.ts.map +1 -0
- package/lib/esm/types/Envelope.js +1 -0
- package/lib/esm/types/RuleEngine.d.ts +83 -0
- package/lib/esm/types/RuleEngine.d.ts.map +1 -0
- package/lib/esm/types/RuleEngine.js +1 -0
- package/lib/esm/types/VariantEvaluation.d.ts +20 -0
- package/lib/esm/types/VariantEvaluation.d.ts.map +1 -0
- package/lib/esm/types/VariantEvaluation.js +1 -0
- package/lib/esm/types/index.d.ts +81 -0
- package/lib/esm/types/index.d.ts.map +1 -0
- package/lib/esm/types/index.js +1 -0
- package/lib/esm/variant.d.ts +9 -0
- package/lib/esm/variant.d.ts.map +1 -0
- package/lib/esm/variant.js +21 -0
- package/package.json +133 -13
- package/lib/index.js +0 -3
- /package/lib/{index.d.ts → esm/types/AppConfigAgentStore.js} +0 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { isRecord } from '@aws-lambda-powertools/commons';
|
|
2
|
+
import { isRunningInLambda } from '@aws-lambda-powertools/commons/utils/env';
|
|
3
|
+
import { getConfig } from '@aws-lambda-powertools/parameters/appconfig-agent';
|
|
4
|
+
import { FlagNotFoundError } from '@aws-lambda-powertools/parameters/errors';
|
|
5
|
+
import { StoreNames } from '../constants.js';
|
|
6
|
+
import { isFiniteContextValue, isScalar } from '../context.js';
|
|
7
|
+
import { InvalidContextError, SchemaValidationError, StoreUnavailableError, } from '../errors.js';
|
|
8
|
+
import { isAvailabilityFailure } from '../parameters-stores/classify.js';
|
|
9
|
+
import { registerVariantStore } from '../variant.js';
|
|
10
|
+
/**
|
|
11
|
+
* Creates a Store that retrieves Agent-selected AppConfig Variants.
|
|
12
|
+
*
|
|
13
|
+
* Requires AppConfig Agent Lambda extension version `2.0.678` or later and the optional
|
|
14
|
+
* `@aws-lambda-powertools/parameters` peer. The Agent owns evaluation, caching,
|
|
15
|
+
* and polling. A single requested flag in Lambda uses selective retrieval;
|
|
16
|
+
* batches and getAll retrieve the whole profile and select flags locally.
|
|
17
|
+
* Normalizes only requested flags in a batch.
|
|
18
|
+
*
|
|
19
|
+
* Outside Lambda or with `POWERTOOLS_DEV` enabled, every method uses the whole
|
|
20
|
+
* profile from `POWERTOOLS_APPCONFIG_AGENT_RETURN_VALUE`. Set that variable to a
|
|
21
|
+
* flag-keyed JSON object, not an unwrapped single flag.
|
|
22
|
+
*
|
|
23
|
+
* Context keys must match `^[A-Za-z_][A-Za-z0-9_.-]*$`; values must be strings,
|
|
24
|
+
* finite numbers, or booleans. Rejects arrays and invalid context before retrieval.
|
|
25
|
+
* Parameters JSON-quotes and ASCII-escapes strings in the Agent Context header.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} options - Configure retrieval and logging
|
|
28
|
+
* @param {string} options.name - Identify the configuration profile
|
|
29
|
+
* @param {string} options.environment - Identify the environment
|
|
30
|
+
* @param {string} options.application - Identify the application or use the service name
|
|
31
|
+
* @param {number} options.timeout - Set the request timeout in milliseconds
|
|
32
|
+
* @param {GenericLogger} options.logger - Log selected Variant names without values
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const flags = new FeatureFlags({
|
|
36
|
+
* store: appConfigVariantStore({ environment: 'prod', name: 'features' }),
|
|
37
|
+
* });
|
|
38
|
+
* const ui = await flags.evaluate({
|
|
39
|
+
* name: 'ui_refresh', context: { tier: 'premium' }, default: disabledVariant(),
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
const appConfigVariantStore = (options) => {
|
|
44
|
+
/** Retrieves JSON through Parameters and classifies transport failures. */
|
|
45
|
+
const retrieve = async (context, flags) => {
|
|
46
|
+
validateVariantContext(context);
|
|
47
|
+
try {
|
|
48
|
+
return await getConfig(options.name, {
|
|
49
|
+
application: options.application,
|
|
50
|
+
environment: options.environment,
|
|
51
|
+
timeout: options.timeout,
|
|
52
|
+
transform: 'json',
|
|
53
|
+
throwOnMissing: true,
|
|
54
|
+
agentOptions: {
|
|
55
|
+
...(flags ? { flags } : {}),
|
|
56
|
+
context,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error instanceof FlagNotFoundError)
|
|
62
|
+
throw error;
|
|
63
|
+
if (isAvailabilityFailure(error)) {
|
|
64
|
+
throw new StoreUnavailableError(`${StoreNames.APPCONFIG_VARIANT} is unavailable`, { cause: error });
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const store = {
|
|
70
|
+
name: StoreNames.APPCONFIG_VARIANT,
|
|
71
|
+
getMany: async (names, context) => {
|
|
72
|
+
const requested = [...new Set(names)];
|
|
73
|
+
if (requested.length === 1 && isRunningInLambda()) {
|
|
74
|
+
const name = requested[0];
|
|
75
|
+
let flag;
|
|
76
|
+
try {
|
|
77
|
+
flag = await retrieve(context, requested);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error instanceof FlagNotFoundError) {
|
|
81
|
+
return Object.fromEntries([[name, { found: false }]]);
|
|
82
|
+
}
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
return Object.fromEntries([[name, normalize(name, flag, options)]]);
|
|
86
|
+
}
|
|
87
|
+
const profile = validateProfile(await retrieve(context));
|
|
88
|
+
const results = [];
|
|
89
|
+
for (const name of requested) {
|
|
90
|
+
results.push([
|
|
91
|
+
name,
|
|
92
|
+
Object.hasOwn(profile, name)
|
|
93
|
+
? normalize(name, profile[name], options)
|
|
94
|
+
: { found: false },
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
return Object.fromEntries(results);
|
|
98
|
+
},
|
|
99
|
+
getAll: async (context) => {
|
|
100
|
+
const profile = validateProfile(await retrieve(context));
|
|
101
|
+
const results = [];
|
|
102
|
+
for (const [name, flag] of Object.entries(profile)) {
|
|
103
|
+
results.push([name, normalize(name, flag, options)]);
|
|
104
|
+
}
|
|
105
|
+
return Object.fromEntries(results);
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
registerVariantStore(store);
|
|
109
|
+
return store;
|
|
110
|
+
};
|
|
111
|
+
/** Rejects Agent-incompatible context and narrows its values for Parameters. @internal */
|
|
112
|
+
function validateVariantContext(context) {
|
|
113
|
+
for (const [key, value] of Object.entries(context)) {
|
|
114
|
+
if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(key) ||
|
|
115
|
+
!isScalar(value) ||
|
|
116
|
+
(typeof value === 'number' && !Number.isFinite(value))) {
|
|
117
|
+
throw new InvalidContextError(`Invalid evaluation context key '${key}'`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** Rejects a whole-profile response that is not a flag-keyed object. @internal */
|
|
122
|
+
const validateProfile = (profile) => {
|
|
123
|
+
if (!isRecord(profile)) {
|
|
124
|
+
throw new SchemaValidationError('AppConfig Variant profile must be an object');
|
|
125
|
+
}
|
|
126
|
+
return profile;
|
|
127
|
+
};
|
|
128
|
+
/** Normalizes one flag without exposing response values in errors or logs. @internal */
|
|
129
|
+
const normalize = (name, flag, options) => {
|
|
130
|
+
if (!isRecord(flag)) {
|
|
131
|
+
throw new SchemaValidationError(`Flag '${name}' must be an object`);
|
|
132
|
+
}
|
|
133
|
+
const variant = Object.hasOwn(flag, '_variant') ? flag._variant : 'default';
|
|
134
|
+
if (!Object.hasOwn(flag, 'enabled') ||
|
|
135
|
+
typeof flag.enabled !== 'boolean' ||
|
|
136
|
+
typeof variant !== 'string') {
|
|
137
|
+
throw new SchemaValidationError(`Flag '${name}' must contain valid Variant fields`);
|
|
138
|
+
}
|
|
139
|
+
const attributes = [];
|
|
140
|
+
for (const [key, value] of Object.entries(flag)) {
|
|
141
|
+
if (key === 'enabled' || key === '_variant')
|
|
142
|
+
continue;
|
|
143
|
+
if (!isFiniteContextValue(value)) {
|
|
144
|
+
throw new SchemaValidationError(`Flag '${name}' must contain valid Variant attributes`);
|
|
145
|
+
}
|
|
146
|
+
attributes.push([key, value]);
|
|
147
|
+
}
|
|
148
|
+
const value = {
|
|
149
|
+
enabled: flag.enabled,
|
|
150
|
+
variant,
|
|
151
|
+
attributes: Object.fromEntries(attributes),
|
|
152
|
+
};
|
|
153
|
+
options.logger?.debug({
|
|
154
|
+
store: StoreNames.APPCONFIG_VARIANT,
|
|
155
|
+
name,
|
|
156
|
+
variant: value.variant,
|
|
157
|
+
});
|
|
158
|
+
return { found: true, value, enabled: value.enabled };
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Creates a fresh disabled Variant fallback with no attributes.
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const ui = await flags.evaluate({ name: 'ui_refresh', default: disabledVariant() });
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
const disabledVariant = () => ({
|
|
168
|
+
enabled: false,
|
|
169
|
+
variant: 'default',
|
|
170
|
+
attributes: {},
|
|
171
|
+
});
|
|
172
|
+
export { appConfigVariantStore, disabledVariant };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { AppConfigAgentStoreOptions } from '../types/AppConfigAgentStore.js';
|
|
2
|
+
export type { AppConfigVariantStoreOptions } from '../types/AppConfigVariantStore.js';
|
|
3
|
+
export type { EnvelopeSearchFn } from '../types/Envelope.js';
|
|
4
|
+
export { appConfigAgentStore } from './appConfigAgentStore.js';
|
|
5
|
+
export { appConfigVariantStore, disabledVariant, } from './appConfigVariantStore.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/appconfig-agent/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAClF,YAAY,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACtF,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EACL,qBAAqB,EACrB,eAAe,GAChB,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Names the built-in Stores. @internal */
|
|
2
|
+
declare const StoreNames: {
|
|
3
|
+
readonly RULE_ENGINE: "rule-engine";
|
|
4
|
+
readonly APPCONFIG: "appconfig";
|
|
5
|
+
readonly APPCONFIG_AGENT: "appconfig-agent";
|
|
6
|
+
readonly APPCONFIG_VARIANT: "appconfig-variant";
|
|
7
|
+
};
|
|
8
|
+
/** Names the fields in a Python-format Flag Document. @internal */
|
|
9
|
+
declare const FlagDocumentFields: {
|
|
10
|
+
readonly DEFAULT: "default";
|
|
11
|
+
readonly BOOLEAN_TYPE: "boolean_type";
|
|
12
|
+
readonly RULES: "rules";
|
|
13
|
+
readonly WHEN_MATCH: "when_match";
|
|
14
|
+
readonly CONDITIONS: "conditions";
|
|
15
|
+
readonly ACTION: "action";
|
|
16
|
+
readonly KEY: "key";
|
|
17
|
+
readonly VALUE: "value";
|
|
18
|
+
};
|
|
19
|
+
/** Names the supported Actions. @internal */
|
|
20
|
+
declare const RuleActions: {
|
|
21
|
+
readonly EQUALS: "EQUALS";
|
|
22
|
+
readonly NOT_EQUALS: "NOT_EQUALS";
|
|
23
|
+
readonly KEY_GREATER_THAN_VALUE: "KEY_GREATER_THAN_VALUE";
|
|
24
|
+
readonly KEY_GREATER_THAN_OR_EQUAL_VALUE: "KEY_GREATER_THAN_OR_EQUAL_VALUE";
|
|
25
|
+
readonly KEY_LESS_THAN_VALUE: "KEY_LESS_THAN_VALUE";
|
|
26
|
+
readonly KEY_LESS_THAN_OR_EQUAL_VALUE: "KEY_LESS_THAN_OR_EQUAL_VALUE";
|
|
27
|
+
readonly STARTSWITH: "STARTSWITH";
|
|
28
|
+
readonly ENDSWITH: "ENDSWITH";
|
|
29
|
+
readonly IN: "IN";
|
|
30
|
+
readonly NOT_IN: "NOT_IN";
|
|
31
|
+
readonly KEY_IN_VALUE: "KEY_IN_VALUE";
|
|
32
|
+
readonly KEY_NOT_IN_VALUE: "KEY_NOT_IN_VALUE";
|
|
33
|
+
readonly VALUE_IN_KEY: "VALUE_IN_KEY";
|
|
34
|
+
readonly VALUE_NOT_IN_KEY: "VALUE_NOT_IN_KEY";
|
|
35
|
+
readonly ALL_IN_VALUE: "ALL_IN_VALUE";
|
|
36
|
+
readonly ANY_IN_VALUE: "ANY_IN_VALUE";
|
|
37
|
+
readonly NONE_IN_VALUE: "NONE_IN_VALUE";
|
|
38
|
+
readonly SCHEDULE_BETWEEN_TIME_RANGE: "SCHEDULE_BETWEEN_TIME_RANGE";
|
|
39
|
+
readonly SCHEDULE_BETWEEN_DATETIME_RANGE: "SCHEDULE_BETWEEN_DATETIME_RANGE";
|
|
40
|
+
readonly SCHEDULE_BETWEEN_DAYS_OF_WEEK: "SCHEDULE_BETWEEN_DAYS_OF_WEEK";
|
|
41
|
+
readonly MODULO_RANGE: "MODULO_RANGE";
|
|
42
|
+
};
|
|
43
|
+
/** Maps schedule Actions to their fixed clock keys. @internal */
|
|
44
|
+
declare const TimeActionKeys: {
|
|
45
|
+
readonly SCHEDULE_BETWEEN_TIME_RANGE: "CURRENT_TIME";
|
|
46
|
+
readonly SCHEDULE_BETWEEN_DATETIME_RANGE: "CURRENT_DATETIME";
|
|
47
|
+
readonly SCHEDULE_BETWEEN_DAYS_OF_WEEK: "CURRENT_DAY_OF_WEEK";
|
|
48
|
+
};
|
|
49
|
+
/** Lists Python's TimeValues.days(), including its harmless DAYS entry. @internal */
|
|
50
|
+
declare const TimeDays: readonly ["DAYS", "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"];
|
|
51
|
+
/** Lists retrieval error names that identify availability failures. @internal */
|
|
52
|
+
declare const AvailabilityErrorNames: readonly ["ThrottlingException", "TooManyRequestsException", "InternalServerException", "ServiceUnavailableException", "TimeoutError", "AbortError"];
|
|
53
|
+
/** Lists Node network error codes that identify availability failures. @internal */
|
|
54
|
+
declare const AvailabilityErrorCodes: readonly ["ECONNRESET", "ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND", "EAI_AGAIN"];
|
|
55
|
+
export { AvailabilityErrorCodes, AvailabilityErrorNames, FlagDocumentFields, RuleActions, StoreNames, TimeActionKeys, TimeDays, };
|
|
56
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,QAAA,MAAM,UAAU;;;;;CAKN,CAAC;AAEX,mEAAmE;AACnE,QAAA,MAAM,kBAAkB;;;;;;;;;CASd,CAAC;AAEX,6CAA6C;AAC7C,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;CAsBP,CAAC;AAEX,iEAAiE;AACjE,QAAA,MAAM,cAAc;;;;CAIV,CAAC;AAEX,qFAAqF;AACrF,QAAA,MAAM,QAAQ,iGASJ,CAAC;AAEX,iFAAiF;AACjF,QAAA,MAAM,sBAAsB,sJAOlB,CAAC;AAEX,oFAAoF;AACpF,QAAA,MAAM,sBAAsB,gFAMlB,CAAC;AAEX,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,cAAc,EACd,QAAQ,GACT,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Names the built-in Stores. @internal */
|
|
2
|
+
const StoreNames = {
|
|
3
|
+
RULE_ENGINE: 'rule-engine',
|
|
4
|
+
APPCONFIG: 'appconfig',
|
|
5
|
+
APPCONFIG_AGENT: 'appconfig-agent',
|
|
6
|
+
APPCONFIG_VARIANT: 'appconfig-variant',
|
|
7
|
+
};
|
|
8
|
+
/** Names the fields in a Python-format Flag Document. @internal */
|
|
9
|
+
const FlagDocumentFields = {
|
|
10
|
+
DEFAULT: 'default',
|
|
11
|
+
BOOLEAN_TYPE: 'boolean_type',
|
|
12
|
+
RULES: 'rules',
|
|
13
|
+
WHEN_MATCH: 'when_match',
|
|
14
|
+
CONDITIONS: 'conditions',
|
|
15
|
+
ACTION: 'action',
|
|
16
|
+
KEY: 'key',
|
|
17
|
+
VALUE: 'value',
|
|
18
|
+
};
|
|
19
|
+
/** Names the supported Actions. @internal */
|
|
20
|
+
const RuleActions = {
|
|
21
|
+
EQUALS: 'EQUALS',
|
|
22
|
+
NOT_EQUALS: 'NOT_EQUALS',
|
|
23
|
+
KEY_GREATER_THAN_VALUE: 'KEY_GREATER_THAN_VALUE',
|
|
24
|
+
KEY_GREATER_THAN_OR_EQUAL_VALUE: 'KEY_GREATER_THAN_OR_EQUAL_VALUE',
|
|
25
|
+
KEY_LESS_THAN_VALUE: 'KEY_LESS_THAN_VALUE',
|
|
26
|
+
KEY_LESS_THAN_OR_EQUAL_VALUE: 'KEY_LESS_THAN_OR_EQUAL_VALUE',
|
|
27
|
+
STARTSWITH: 'STARTSWITH',
|
|
28
|
+
ENDSWITH: 'ENDSWITH',
|
|
29
|
+
IN: 'IN',
|
|
30
|
+
NOT_IN: 'NOT_IN',
|
|
31
|
+
KEY_IN_VALUE: 'KEY_IN_VALUE',
|
|
32
|
+
KEY_NOT_IN_VALUE: 'KEY_NOT_IN_VALUE',
|
|
33
|
+
VALUE_IN_KEY: 'VALUE_IN_KEY',
|
|
34
|
+
VALUE_NOT_IN_KEY: 'VALUE_NOT_IN_KEY',
|
|
35
|
+
ALL_IN_VALUE: 'ALL_IN_VALUE',
|
|
36
|
+
ANY_IN_VALUE: 'ANY_IN_VALUE',
|
|
37
|
+
NONE_IN_VALUE: 'NONE_IN_VALUE',
|
|
38
|
+
SCHEDULE_BETWEEN_TIME_RANGE: 'SCHEDULE_BETWEEN_TIME_RANGE',
|
|
39
|
+
SCHEDULE_BETWEEN_DATETIME_RANGE: 'SCHEDULE_BETWEEN_DATETIME_RANGE',
|
|
40
|
+
SCHEDULE_BETWEEN_DAYS_OF_WEEK: 'SCHEDULE_BETWEEN_DAYS_OF_WEEK',
|
|
41
|
+
MODULO_RANGE: 'MODULO_RANGE',
|
|
42
|
+
};
|
|
43
|
+
/** Maps schedule Actions to their fixed clock keys. @internal */
|
|
44
|
+
const TimeActionKeys = {
|
|
45
|
+
SCHEDULE_BETWEEN_TIME_RANGE: 'CURRENT_TIME',
|
|
46
|
+
SCHEDULE_BETWEEN_DATETIME_RANGE: 'CURRENT_DATETIME',
|
|
47
|
+
SCHEDULE_BETWEEN_DAYS_OF_WEEK: 'CURRENT_DAY_OF_WEEK',
|
|
48
|
+
};
|
|
49
|
+
/** Lists Python's TimeValues.days(), including its harmless DAYS entry. @internal */
|
|
50
|
+
const TimeDays = [
|
|
51
|
+
'DAYS',
|
|
52
|
+
'SUNDAY',
|
|
53
|
+
'MONDAY',
|
|
54
|
+
'TUESDAY',
|
|
55
|
+
'WEDNESDAY',
|
|
56
|
+
'THURSDAY',
|
|
57
|
+
'FRIDAY',
|
|
58
|
+
'SATURDAY',
|
|
59
|
+
];
|
|
60
|
+
/** Lists retrieval error names that identify availability failures. @internal */
|
|
61
|
+
const AvailabilityErrorNames = [
|
|
62
|
+
'ThrottlingException',
|
|
63
|
+
'TooManyRequestsException',
|
|
64
|
+
'InternalServerException',
|
|
65
|
+
'ServiceUnavailableException',
|
|
66
|
+
'TimeoutError',
|
|
67
|
+
'AbortError',
|
|
68
|
+
];
|
|
69
|
+
/** Lists Node network error codes that identify availability failures. @internal */
|
|
70
|
+
const AvailabilityErrorCodes = [
|
|
71
|
+
'ECONNRESET',
|
|
72
|
+
'ECONNREFUSED',
|
|
73
|
+
'ETIMEDOUT',
|
|
74
|
+
'ENOTFOUND',
|
|
75
|
+
'EAI_AGAIN',
|
|
76
|
+
];
|
|
77
|
+
export { AvailabilityErrorCodes, AvailabilityErrorNames, FlagDocumentFields, RuleActions, StoreNames, TimeActionKeys, TimeDays, };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ContextScalar, ContextValue } from './types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Checks for a string, number, or boolean in context values and fallbacks.
|
|
4
|
+
* @param value - Supply the value to check
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
declare const isScalar: (value: unknown) => value is ContextScalar;
|
|
8
|
+
/**
|
|
9
|
+
* Checks finite scalar attributes and flat arrays, rejecting sparse arrays.
|
|
10
|
+
* @param value - Supply the attribute value to check
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
declare const isFiniteContextValue: (value: unknown) => value is ContextValue;
|
|
14
|
+
/**
|
|
15
|
+
* Describes an invalid context value's kind without exposing its value.
|
|
16
|
+
* @param value - Supply the invalid context value to describe
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
declare const getInvalidContextKind: (value: unknown) => string;
|
|
20
|
+
export { getInvalidContextKind, isFiniteContextValue, isScalar };
|
|
21
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEpE;;;;GAIG;AACH,QAAA,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,aACsB,CAAC;AAEnE;;;;GAIG;AACH,QAAA,MAAM,oBAAoB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,YAWvD,CAAC;AAEF;;;;GAIG;AACH,QAAA,MAAM,qBAAqB,GAAI,OAAO,OAAO,KAAG,MAS/C,CAAC;AAEF,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isNumber, isString } from '@aws-lambda-powertools/commons';
|
|
2
|
+
/**
|
|
3
|
+
* Checks for a string, number, or boolean in context values and fallbacks.
|
|
4
|
+
* @param value - Supply the value to check
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
const isScalar = (value) => isString(value) || isNumber(value) || typeof value === 'boolean';
|
|
8
|
+
/**
|
|
9
|
+
* Checks finite scalar attributes and flat arrays, rejecting sparse arrays.
|
|
10
|
+
* @param value - Supply the attribute value to check
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
const isFiniteContextValue = (value) => {
|
|
14
|
+
const values = Array.isArray(value) ? Array.from(value) : [value];
|
|
15
|
+
for (const entry of values) {
|
|
16
|
+
if (!isScalar(entry) ||
|
|
17
|
+
(typeof entry === 'number' && !Number.isFinite(entry))) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Describes an invalid context value's kind without exposing its value.
|
|
25
|
+
* @param value - Supply the invalid context value to describe
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
const getInvalidContextKind = (value) => {
|
|
29
|
+
if (value === null)
|
|
30
|
+
return 'null';
|
|
31
|
+
if (Array.isArray(value)) {
|
|
32
|
+
const offendingElement = Array.from(value).find((element) => !isScalar(element));
|
|
33
|
+
return `an array containing ${getInvalidContextKind(offendingElement)}`;
|
|
34
|
+
}
|
|
35
|
+
return typeof value;
|
|
36
|
+
};
|
|
37
|
+
export { getInvalidContextKind, isFiniteContextValue, isScalar };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Searches a configuration with JMESPath and the Powertools custom functions.
|
|
3
|
+
*
|
|
4
|
+
* Install `@aws-lambda-powertools/jmespath` to use this optional helper.
|
|
5
|
+
* @param expression - Select the embedded Flag Document
|
|
6
|
+
* @param data - Supply the retrieved configuration
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { appConfigAgentStore } from '@aws-lambda-powertools/feature-flags/appconfig-agent';
|
|
10
|
+
* import { search } from '@aws-lambda-powertools/feature-flags/envelope';
|
|
11
|
+
*
|
|
12
|
+
* const store = appConfigAgentStore({
|
|
13
|
+
* application: 'my-app', environment: 'prod', name: 'features',
|
|
14
|
+
* envelope: 'powertools_json(settings).flags', envelopeSearchFn: search,
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare const search: (expression: string, data: unknown) => unknown;
|
|
19
|
+
export { search };
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AACH,QAAA,MAAM,MAAM,GAAI,YAAY,MAAM,EAAE,MAAM,OAAO,KAAG,OAKnD,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { search as JMESPathSearch } from '@aws-lambda-powertools/jmespath';
|
|
2
|
+
import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions';
|
|
3
|
+
/**
|
|
4
|
+
* Searches a configuration with JMESPath and the Powertools custom functions.
|
|
5
|
+
*
|
|
6
|
+
* Install `@aws-lambda-powertools/jmespath` to use this optional helper.
|
|
7
|
+
* @param expression - Select the embedded Flag Document
|
|
8
|
+
* @param data - Supply the retrieved configuration
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { appConfigAgentStore } from '@aws-lambda-powertools/feature-flags/appconfig-agent';
|
|
12
|
+
* import { search } from '@aws-lambda-powertools/feature-flags/envelope';
|
|
13
|
+
*
|
|
14
|
+
* const store = appConfigAgentStore({
|
|
15
|
+
* application: 'my-app', environment: 'prod', name: 'features',
|
|
16
|
+
* envelope: 'powertools_json(settings).flags', envelopeSearchFn: search,
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
const search = (expression, data) => {
|
|
21
|
+
// Match Logger's JMESPath input boundary; the search engine checks operands at runtime.
|
|
22
|
+
return JMESPathSearch(expression, data, {
|
|
23
|
+
customFunctions: new PowertoolsFunctions(),
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
export { search };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
/** Provides the base error for the feature flags utility. */
|
|
3
|
+
declare class FeatureFlagsError extends Error {
|
|
4
|
+
constructor(message: string, options?: ErrorOptions);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Reports a known availability failure from a Store.
|
|
8
|
+
*
|
|
9
|
+
* Stores throw this error for timeouts, connection failures, throttling, or
|
|
10
|
+
* service unavailability. The evaluator catches this category and returns
|
|
11
|
+
* fallbacks.
|
|
12
|
+
*/
|
|
13
|
+
declare class StoreUnavailableError extends FeatureFlagsError {
|
|
14
|
+
constructor(message: string, options?: ErrorOptions);
|
|
15
|
+
}
|
|
16
|
+
/** Reports an invalid evaluation context without exposing its values. */
|
|
17
|
+
declare class InvalidContextError extends FeatureFlagsError {
|
|
18
|
+
/**
|
|
19
|
+
* Creates an invalid context error.
|
|
20
|
+
* @param message - Describe the invalid context key
|
|
21
|
+
* @param options - Supply optional error details
|
|
22
|
+
*/
|
|
23
|
+
constructor(message: string, options?: ErrorOptions);
|
|
24
|
+
}
|
|
25
|
+
/** Reports a flag value whose type differs from its primitive fallback. */
|
|
26
|
+
declare class FlagValueTypeError extends FeatureFlagsError {
|
|
27
|
+
/**
|
|
28
|
+
* Creates a flag value type error.
|
|
29
|
+
* @param message - Describe the flag and mismatched types
|
|
30
|
+
* @param options - Supply optional error details
|
|
31
|
+
*/
|
|
32
|
+
constructor(message: string, options?: ErrorOptions);
|
|
33
|
+
}
|
|
34
|
+
/** Reports an invalid Flag Document without exposing its values. */
|
|
35
|
+
declare class SchemaValidationError extends FeatureFlagsError {
|
|
36
|
+
/**
|
|
37
|
+
* Creates a schema validation error.
|
|
38
|
+
* @param message - Describe the invalid flag, Rule, or Condition
|
|
39
|
+
* @param options - Supply optional error details
|
|
40
|
+
*/
|
|
41
|
+
constructor(message: string, options?: ErrorOptions);
|
|
42
|
+
}
|
|
43
|
+
/** Reports incompatible Condition operands without exposing their values. */
|
|
44
|
+
declare class ConditionEvaluationError extends FeatureFlagsError {
|
|
45
|
+
/**
|
|
46
|
+
* Creates a condition evaluation error.
|
|
47
|
+
* @param message - Identify the flag, Rule, key, and Action
|
|
48
|
+
* @param options - Supply optional error details
|
|
49
|
+
*/
|
|
50
|
+
constructor(message: string, options?: ErrorOptions);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Reports schema validation failures without exposing values or validator messages.
|
|
54
|
+
*
|
|
55
|
+
* Preserves the validator's issues array or the value thrown by the schema as cause.
|
|
56
|
+
* Messages list issue paths or report that the schema threw. Uses an empty issues
|
|
57
|
+
* array as cause and a single synthetic (root) path when a schema returns undefined
|
|
58
|
+
* without issues.
|
|
59
|
+
*/
|
|
60
|
+
declare class FlagResultValidationError extends FeatureFlagsError {
|
|
61
|
+
readonly flag: string;
|
|
62
|
+
readonly source: 'fallback' | 'result';
|
|
63
|
+
/**
|
|
64
|
+
* Creates a validation error and preserves the issues or thrown value as its cause.
|
|
65
|
+
* @param flag - Identify the flag
|
|
66
|
+
* @param source - Identify the fallback or Store result
|
|
67
|
+
* @param issues - Supply the validator's issue paths and cause
|
|
68
|
+
* @param {Object} options - Report a failure thrown by the schema instead of issues
|
|
69
|
+
* @param {unknown} options.cause - Preserve the original value thrown by the schema
|
|
70
|
+
*/
|
|
71
|
+
constructor(flag: string, source: 'fallback' | 'result', issues: ReadonlyArray<StandardSchemaV1.Issue>, options?: ErrorOptions);
|
|
72
|
+
}
|
|
73
|
+
export { ConditionEvaluationError, FeatureFlagsError, FlagResultValidationError, FlagValueTypeError, InvalidContextError, SchemaValidationError, StoreUnavailableError, };
|
|
74
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,6DAA6D;AAC7D,cAAM,iBAAkB,SAAQ,KAAK;gBAChB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAI3D;AAED;;;;;;GAMG;AACH,cAAM,qBAAsB,SAAQ,iBAAiB;gBAChC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAI3D;AAED,yEAAyE;AACzE,cAAM,mBAAoB,SAAQ,iBAAiB;IACjD;;;;OAIG;gBACgB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAI3D;AAED,2EAA2E;AAC3E,cAAM,kBAAmB,SAAQ,iBAAiB;IAChD;;;;OAIG;gBACgB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAI3D;AAED,oEAAoE;AACpE,cAAM,qBAAsB,SAAQ,iBAAiB;IACnD;;;;OAIG;gBACgB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAI3D;AAED,6EAA6E;AAC7E,cAAM,wBAAyB,SAAQ,iBAAiB;IACtD;;;;OAIG;gBACgB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAI3D;AAED;;;;;;;GAOG;AACH,cAAM,yBAA0B,SAAQ,iBAAiB;IACvD,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,MAAM,EAAE,UAAU,GAAG,QAAQ,CAAC;IAE9C;;;;;;;OAOG;gBAED,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,GAAG,QAAQ,EAC7B,MAAM,EAAE,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAC7C,OAAO,CAAC,EAAE,YAAY;CAwBzB;AAED,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,yBAAyB,EACzB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,GACtB,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** Provides the base error for the feature flags utility. */
|
|
2
|
+
class FeatureFlagsError extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = 'FeatureFlagsError';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Reports a known availability failure from a Store.
|
|
10
|
+
*
|
|
11
|
+
* Stores throw this error for timeouts, connection failures, throttling, or
|
|
12
|
+
* service unavailability. The evaluator catches this category and returns
|
|
13
|
+
* fallbacks.
|
|
14
|
+
*/
|
|
15
|
+
class StoreUnavailableError extends FeatureFlagsError {
|
|
16
|
+
constructor(message, options) {
|
|
17
|
+
super(message, options);
|
|
18
|
+
this.name = 'StoreUnavailableError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Reports an invalid evaluation context without exposing its values. */
|
|
22
|
+
class InvalidContextError extends FeatureFlagsError {
|
|
23
|
+
/**
|
|
24
|
+
* Creates an invalid context error.
|
|
25
|
+
* @param message - Describe the invalid context key
|
|
26
|
+
* @param options - Supply optional error details
|
|
27
|
+
*/
|
|
28
|
+
constructor(message, options) {
|
|
29
|
+
super(message, options);
|
|
30
|
+
this.name = 'InvalidContextError';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Reports a flag value whose type differs from its primitive fallback. */
|
|
34
|
+
class FlagValueTypeError extends FeatureFlagsError {
|
|
35
|
+
/**
|
|
36
|
+
* Creates a flag value type error.
|
|
37
|
+
* @param message - Describe the flag and mismatched types
|
|
38
|
+
* @param options - Supply optional error details
|
|
39
|
+
*/
|
|
40
|
+
constructor(message, options) {
|
|
41
|
+
super(message, options);
|
|
42
|
+
this.name = 'FlagValueTypeError';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Reports an invalid Flag Document without exposing its values. */
|
|
46
|
+
class SchemaValidationError extends FeatureFlagsError {
|
|
47
|
+
/**
|
|
48
|
+
* Creates a schema validation error.
|
|
49
|
+
* @param message - Describe the invalid flag, Rule, or Condition
|
|
50
|
+
* @param options - Supply optional error details
|
|
51
|
+
*/
|
|
52
|
+
constructor(message, options) {
|
|
53
|
+
super(message, options);
|
|
54
|
+
this.name = 'SchemaValidationError';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Reports incompatible Condition operands without exposing their values. */
|
|
58
|
+
class ConditionEvaluationError extends FeatureFlagsError {
|
|
59
|
+
/**
|
|
60
|
+
* Creates a condition evaluation error.
|
|
61
|
+
* @param message - Identify the flag, Rule, key, and Action
|
|
62
|
+
* @param options - Supply optional error details
|
|
63
|
+
*/
|
|
64
|
+
constructor(message, options) {
|
|
65
|
+
super(message, options);
|
|
66
|
+
this.name = 'ConditionEvaluationError';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Reports schema validation failures without exposing values or validator messages.
|
|
71
|
+
*
|
|
72
|
+
* Preserves the validator's issues array or the value thrown by the schema as cause.
|
|
73
|
+
* Messages list issue paths or report that the schema threw. Uses an empty issues
|
|
74
|
+
* array as cause and a single synthetic (root) path when a schema returns undefined
|
|
75
|
+
* without issues.
|
|
76
|
+
*/
|
|
77
|
+
class FlagResultValidationError extends FeatureFlagsError {
|
|
78
|
+
flag;
|
|
79
|
+
source;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a validation error and preserves the issues or thrown value as its cause.
|
|
82
|
+
* @param flag - Identify the flag
|
|
83
|
+
* @param source - Identify the fallback or Store result
|
|
84
|
+
* @param issues - Supply the validator's issue paths and cause
|
|
85
|
+
* @param {Object} options - Report a failure thrown by the schema instead of issues
|
|
86
|
+
* @param {unknown} options.cause - Preserve the original value thrown by the schema
|
|
87
|
+
*/
|
|
88
|
+
constructor(flag, source, issues, options) {
|
|
89
|
+
const paths = [];
|
|
90
|
+
for (const issue of issues) {
|
|
91
|
+
const segments = [];
|
|
92
|
+
for (const segment of issue.path ?? []) {
|
|
93
|
+
segments.push(String(typeof segment === 'object' ? segment.key : segment));
|
|
94
|
+
}
|
|
95
|
+
paths.push(segments.length > 0 ? segments.join('.') : '(root)');
|
|
96
|
+
}
|
|
97
|
+
super(options
|
|
98
|
+
? `Flag '${flag}' ${source} failed schema validation: the schema threw`
|
|
99
|
+
: `Flag '${flag}' ${source} failed schema validation at ${paths.length > 0 ? paths.join(', ') : '(root)'}`, options ?? {
|
|
100
|
+
cause: issues,
|
|
101
|
+
});
|
|
102
|
+
this.name = 'FlagResultValidationError';
|
|
103
|
+
this.flag = flag;
|
|
104
|
+
this.source = source;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export { ConditionEvaluationError, FeatureFlagsError, FlagResultValidationError, FlagValueTypeError, InvalidContextError, SchemaValidationError, StoreUnavailableError, };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ConditionEvaluationError, FeatureFlagsError, FlagResultValidationError, FlagValueTypeError, InvalidContextError, SchemaValidationError, StoreUnavailableError, } from './errors.js';
|
|
2
|
+
export { FeatureFlags } from './FeatureFlags.js';
|
|
3
|
+
export { ruleEngineStore } from './ruleEngine/index.js';
|
|
4
|
+
export type * from './types/index.js';
|
|
5
|
+
export type { RuleEngineStoreOptions } from './types/RuleEngine.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,yBAAyB,EACzB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,mBAAmB,kBAAkB,CAAC;AACtC,YAAY,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ConditionEvaluationError, FeatureFlagsError, FlagResultValidationError, FlagValueTypeError, InvalidContextError, SchemaValidationError, StoreUnavailableError, } from './errors.js';
|
|
2
|
+
export { FeatureFlags } from './FeatureFlags.js';
|
|
3
|
+
export { ruleEngineStore } from './ruleEngine/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|