@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
package/README.md
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
|
-
# Powertools for AWS Lambda (TypeScript) - Feature Flags
|
|
1
|
+
# Powertools for AWS Lambda (TypeScript) - Feature Flags <!-- omit in toc -->
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
> This is a placeholder package used to reserve the package name ahead of the first release of the `feature-flags` utility. **Do not use this in production yet.**
|
|
3
|
+
Powertools for AWS Lambda (TypeScript) is a developer toolkit to implement Serverless [best practices and increase developer velocity](https://docs.aws.amazon.com/powertools/typescript/latest/#features).
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
- [Intro](#intro)
|
|
6
|
+
- [Usage](#usage)
|
|
7
|
+
- [Contribute](#contribute)
|
|
8
|
+
- [Roadmap](#roadmap)
|
|
9
|
+
- [Connect](#connect)
|
|
10
|
+
- [License](#license)
|
|
11
|
+
|
|
12
|
+
## Intro
|
|
13
|
+
|
|
14
|
+
The Feature Flags utility evaluates flags against caller-supplied context. Use a local rule engine over a Powertools for Python freeform Flag Document, AWS AppConfig Agent-selected variants, or your own Store. Every evaluation has an explicit fallback for a missing flag or an availability failure.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Install the core utility for local rules or custom Stores:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm install @aws-lambda-powertools/feature-flags
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import {
|
|
26
|
+
FeatureFlags,
|
|
27
|
+
ruleEngineStore,
|
|
28
|
+
} from '@aws-lambda-powertools/feature-flags';
|
|
29
|
+
|
|
30
|
+
const flags = new FeatureFlags({
|
|
31
|
+
store: ruleEngineStore({
|
|
32
|
+
source: async () => ({
|
|
33
|
+
checkout_v2: {
|
|
34
|
+
default: false,
|
|
35
|
+
rules: {
|
|
36
|
+
premium_customers: {
|
|
37
|
+
when_match: true,
|
|
38
|
+
conditions: [{ action: 'EQUALS', key: 'tier', value: 'premium' }],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const handler = async () => {
|
|
47
|
+
return flags.evaluate({
|
|
48
|
+
name: 'checkout_v2',
|
|
49
|
+
context: { tier: 'premium' },
|
|
50
|
+
default: false,
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
See the [Feature Flags documentation](https://docs.aws.amazon.com/powertools/typescript/latest/features/feature-flags/) for AppConfig installation, IAM permissions, variants, result validation, and testing.
|
|
56
|
+
|
|
57
|
+
## Contribute
|
|
58
|
+
|
|
59
|
+
If you are interested in contributing to this project, please refer to our [Contributing Guidelines](https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/CONTRIBUTING.md).
|
|
60
|
+
|
|
61
|
+
## Roadmap
|
|
62
|
+
|
|
63
|
+
Follow [issue #3754](https://github.com/aws-powertools/powertools-lambda-typescript/issues/3754) for Feature Flags implementation progress.
|
|
64
|
+
|
|
65
|
+
## Connect
|
|
66
|
+
|
|
67
|
+
- **Powertools for AWS Lambda on GitHub Discussions**: [Join the conversation](https://github.com/aws-powertools/powertools-lambda-typescript/discussions)
|
|
68
|
+
- **Email**: <aws-lambda-powertools-feedback@amazon.com>
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
This library is licensed under the MIT-0 License. See the LICENSE file.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { JSONValue } from '@aws-lambda-powertools/commons/types';
|
|
2
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
+
import type { EvaluateManyOptions, EvaluateManyResult, EvaluateOptions, EvaluateResult, EvaluateWithSchemaOptions, FeatureFlagsOptions, GetEnabledFeaturesOptions, Variant } from './types/index.js';
|
|
4
|
+
import type { EvaluateManyVariantOptions, EvaluateManyVariantResult, EvaluateVariantOptions } from './types/VariantEvaluation.js';
|
|
5
|
+
/**
|
|
6
|
+
* Evaluates feature flags against a caller-supplied {@link Store | `Store`}.
|
|
7
|
+
*
|
|
8
|
+
* Infers the Store's value type. Variant stores require full Variant fallbacks
|
|
9
|
+
* and return Variants without schemas; JSON stores retain primitive inference
|
|
10
|
+
* and optional Standard Schema validation.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const flags = new FeatureFlags({ store: myStore });
|
|
15
|
+
* const enabled = await flags.evaluate({ name: 'checkout_v2', default: false });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare class FeatureFlags<Value = JSONValue> {
|
|
19
|
+
#private;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a feature flag evaluator.
|
|
22
|
+
* @param {Object} options - Configure the evaluator
|
|
23
|
+
* @param {Store} options.store - Supply the Store for flag lookups
|
|
24
|
+
* @param {GenericLogger} options.logger - Log outcomes without values
|
|
25
|
+
*/
|
|
26
|
+
constructor(options: FeatureFlagsOptions<Value>);
|
|
27
|
+
/**
|
|
28
|
+
* Evaluates one flag and returns its value or the required fallback.
|
|
29
|
+
*
|
|
30
|
+
* Handles {@link StoreUnavailableError | `StoreUnavailableError`} with the fallback.
|
|
31
|
+
* With a schema, validates the fallback before contacting the {@link Store | `Store`}
|
|
32
|
+
* and replaces the primitive type check with schema validation. Returns the
|
|
33
|
+
* validated output on both the found path and the fallback path, and rejects
|
|
34
|
+
* schema outputs that are undefined.
|
|
35
|
+
* Variant stores require a full Variant fallback, return it unchanged on a
|
|
36
|
+
* fallback path, and do not accept schemas.
|
|
37
|
+
*
|
|
38
|
+
* @param {Object} options - Configure the flag evaluation
|
|
39
|
+
* @param {string} options.name - Identify the flag
|
|
40
|
+
* @param {EvaluationContext} options.context - Supply scalar facts for evaluation
|
|
41
|
+
* @param {JSONValue} options.default - Supply the fallback and, without a schema, the expected primitive type
|
|
42
|
+
* @param {StandardSchemaV1} options.schema - Validate the fallback and result with an optional schema
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const enabled = await flags.evaluate({
|
|
46
|
+
* name: 'checkout_v2', context: { tier: 'premium' }, default: false,
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const settings = await flags.evaluate({
|
|
52
|
+
* name: 'settings', default: { theme: 'light' }, schema: settingsSchema,
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
evaluate<Schema extends StandardSchemaV1>(options: Value extends Variant ? never : EvaluateWithSchemaOptions<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
57
|
+
evaluate<Fallback extends JSONValue>(options: Value extends Variant ? EvaluateVariantOptions : EvaluateOptions<Fallback>): Promise<Value extends Variant ? Variant : EvaluateResult<Fallback>>;
|
|
58
|
+
/**
|
|
59
|
+
* Evaluates several flags with an independent fallback for each flag.
|
|
60
|
+
*
|
|
61
|
+
* Handles {@link StoreUnavailableError | `StoreUnavailableError`} with every fallback.
|
|
62
|
+
* Validates schema-backed fallbacks before contacting the {@link Store | `Store`}.
|
|
63
|
+
* Each schema replaces the primitive type check and supplies the output on both
|
|
64
|
+
* the found path and the fallback path. Rejects undefined schema outputs and
|
|
65
|
+
* throws for the whole batch if any flag fails validation.
|
|
66
|
+
* Variant stores require a full Variant fallback per flag and do not accept
|
|
67
|
+
* schemas. Each requested key resolves to a Variant.
|
|
68
|
+
*
|
|
69
|
+
* @param {Object} options - Configure the batch evaluation
|
|
70
|
+
* @param {Object} options.flags - Supply flag names and their fallbacks
|
|
71
|
+
* @param {EvaluationContext} options.context - Supply scalar facts for evaluation
|
|
72
|
+
* @param {Object} options.schemas - Validate selected flags and their fallbacks
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const result = await flags.evaluateMany({
|
|
76
|
+
* flags: { checkout_v2: false, limit: 10 }, context: { tier: 'premium' },
|
|
77
|
+
* });
|
|
78
|
+
* const settings = await flags.evaluateMany({
|
|
79
|
+
* flags: { settings: { theme: 'light' }, banner: 'none' },
|
|
80
|
+
* schemas: { settings: settingsSchema },
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
evaluateMany<Flags extends Record<string, JSONValue>, Schemas extends Partial<Record<string, StandardSchemaV1>> = Partial<Record<string, never>>>(options: Value extends Variant ? EvaluateManyVariantOptions<Flags> : EvaluateManyOptions<Flags, Schemas>): Promise<Value extends Variant ? EvaluateManyVariantResult<Flags> : EvaluateManyResult<Flags, Schemas>>;
|
|
85
|
+
/**
|
|
86
|
+
* Gets enabled flag names in the {@link Store | `Store`}'s iteration order.
|
|
87
|
+
*
|
|
88
|
+
* @param {Object} options - Configure the lookup
|
|
89
|
+
* @param {EvaluationContext} options.context - Supply scalar facts for evaluation
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const enabled = await flags.getEnabledFeatures({ context: { tier: 'premium' } });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
getEnabledFeatures(options?: GetEnabledFeaturesOptions): Promise<string[]>;
|
|
96
|
+
}
|
|
97
|
+
export { FeatureFlags };
|
|
98
|
+
//# sourceMappingURL=FeatureFlags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FeatureFlags.d.ts","sourceRoot":"","sources":["../../src/FeatureFlags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EACV,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAQ9D,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,yBAAyB,EAEzB,mBAAmB,EACnB,yBAAyB,EAGzB,OAAO,EACR,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,0BAA0B,EAC1B,yBAAyB,EACzB,sBAAsB,EACvB,MAAM,8BAA8B,CAAC;AAGtC;;;;;;;;;;;;GAYG;AACH,cAAM,YAAY,CAAC,KAAK,GAAG,SAAS;;IAKlC;;;;;OAKG;gBACgB,OAAO,EAAE,mBAAmB,CAAC,KAAK,CAAC;IAMtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACI,QAAQ,CAAC,MAAM,SAAS,gBAAgB,EAC7C,OAAO,EAAE,KAAK,SAAS,OAAO,GAAG,KAAK,GAAG,yBAAyB,CAAC,MAAM,CAAC,GACzE,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAEzC,QAAQ,CAAC,QAAQ,SAAS,SAAS,EACxC,OAAO,EAAE,KAAK,SAAS,OAAO,GAC1B,sBAAsB,GACtB,eAAe,CAAC,QAAQ,CAAC,GAC5B,OAAO,CAAC,KAAK,SAAS,OAAO,GAAG,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAwDtE;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,YAAY,CACjB,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EACvC,OAAO,SAAS,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,GAAG,OAAO,CACjE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CACtB,EAED,OAAO,EAAE,KAAK,SAAS,OAAO,GAC1B,0BAA0B,CAAC,KAAK,CAAC,GACjC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,GACtC,OAAO,CACR,KAAK,SAAS,OAAO,GACjB,yBAAyB,CAAC,KAAK,CAAC,GAChC,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,CACvC;IAqFD;;;;;;;;;OASG;IACU,kBAAkB,CAC7B,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,MAAM,EAAE,CAAC;CA2BrB;AA6ED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FeatureFlags = void 0;
|
|
4
|
+
const context_js_1 = require("./context.js");
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
const variant_js_1 = require("./variant.js");
|
|
7
|
+
/**
|
|
8
|
+
* Evaluates feature flags against a caller-supplied {@link Store | `Store`}.
|
|
9
|
+
*
|
|
10
|
+
* Infers the Store's value type. Variant stores require full Variant fallbacks
|
|
11
|
+
* and return Variants without schemas; JSON stores retain primitive inference
|
|
12
|
+
* and optional Standard Schema validation.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const flags = new FeatureFlags({ store: myStore });
|
|
17
|
+
* const enabled = await flags.evaluate({ name: 'checkout_v2', default: false });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
class FeatureFlags {
|
|
21
|
+
#store;
|
|
22
|
+
#variantStore;
|
|
23
|
+
#logger;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a feature flag evaluator.
|
|
26
|
+
* @param {Object} options - Configure the evaluator
|
|
27
|
+
* @param {Store} options.store - Supply the Store for flag lookups
|
|
28
|
+
* @param {GenericLogger} options.logger - Log outcomes without values
|
|
29
|
+
*/
|
|
30
|
+
constructor(options) {
|
|
31
|
+
this.#store = options.store;
|
|
32
|
+
this.#variantStore = (0, variant_js_1.isVariantStore)(options.store);
|
|
33
|
+
this.#logger = options.logger;
|
|
34
|
+
}
|
|
35
|
+
async evaluate(options) {
|
|
36
|
+
const { name, context = {} } = options;
|
|
37
|
+
validateContext(context);
|
|
38
|
+
if (this.#variantStore)
|
|
39
|
+
validateVariantFallback(name, options.default);
|
|
40
|
+
const fallback = !this.#variantStore && 'schema' in options
|
|
41
|
+
? await validateWithSchema(name, 'fallback', options.default, options.schema)
|
|
42
|
+
: options.default;
|
|
43
|
+
let result;
|
|
44
|
+
try {
|
|
45
|
+
result = await this.#store.getMany([name], context);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (!(error instanceof errors_js_1.StoreUnavailableError))
|
|
49
|
+
throw error;
|
|
50
|
+
this.#logger?.warn({
|
|
51
|
+
name,
|
|
52
|
+
store: this.#store.name,
|
|
53
|
+
reason: 'unavailable',
|
|
54
|
+
});
|
|
55
|
+
this.#logger?.debug({
|
|
56
|
+
name,
|
|
57
|
+
store: this.#store.name,
|
|
58
|
+
outcome: 'fallback',
|
|
59
|
+
});
|
|
60
|
+
return fallback;
|
|
61
|
+
}
|
|
62
|
+
const flag = result[name];
|
|
63
|
+
if (!flag?.found) {
|
|
64
|
+
this.#logger?.warn({ name, store: this.#store.name, reason: 'missing' });
|
|
65
|
+
this.#logger?.debug({
|
|
66
|
+
name,
|
|
67
|
+
store: this.#store.name,
|
|
68
|
+
outcome: 'fallback',
|
|
69
|
+
});
|
|
70
|
+
return fallback;
|
|
71
|
+
}
|
|
72
|
+
let value = flag.value;
|
|
73
|
+
if (!this.#variantStore && 'schema' in options) {
|
|
74
|
+
value = await validateWithSchema(name, 'result', value, options.schema);
|
|
75
|
+
}
|
|
76
|
+
else if (!this.#variantStore) {
|
|
77
|
+
validateFlagValue(name, fallback, value);
|
|
78
|
+
}
|
|
79
|
+
this.#logger?.debug({ name, store: this.#store.name, outcome: 'found' });
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
async evaluateMany(options) {
|
|
83
|
+
const { flags, context = {}, schemas = {} } = options;
|
|
84
|
+
validateContext(context);
|
|
85
|
+
const names = Object.keys(flags);
|
|
86
|
+
const fallbacks = [];
|
|
87
|
+
for (const name of names) {
|
|
88
|
+
if (this.#variantStore)
|
|
89
|
+
validateVariantFallback(name, flags[name]);
|
|
90
|
+
const schema = !this.#variantStore && Object.hasOwn(schemas, name)
|
|
91
|
+
? schemas[name]
|
|
92
|
+
: undefined;
|
|
93
|
+
fallbacks.push([
|
|
94
|
+
name,
|
|
95
|
+
schema
|
|
96
|
+
? await validateWithSchema(name, 'fallback', flags[name], schema)
|
|
97
|
+
: flags[name],
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
let result;
|
|
101
|
+
try {
|
|
102
|
+
result = await this.#store.getMany(names, context);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (!(error instanceof errors_js_1.StoreUnavailableError))
|
|
106
|
+
throw error;
|
|
107
|
+
this.#logger?.warn({
|
|
108
|
+
store: this.#store.name,
|
|
109
|
+
reason: 'unavailable',
|
|
110
|
+
names,
|
|
111
|
+
});
|
|
112
|
+
this.#logger?.debug({
|
|
113
|
+
store: this.#store.name,
|
|
114
|
+
outcome: 'fallback',
|
|
115
|
+
names,
|
|
116
|
+
});
|
|
117
|
+
return Object.fromEntries(fallbacks);
|
|
118
|
+
}
|
|
119
|
+
const values = [];
|
|
120
|
+
const missing = [];
|
|
121
|
+
for (const [name, fallback] of fallbacks) {
|
|
122
|
+
const flag = result[name];
|
|
123
|
+
if (!flag?.found) {
|
|
124
|
+
missing.push(name);
|
|
125
|
+
values.push([name, fallback]);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const schema = !this.#variantStore && Object.hasOwn(schemas, name)
|
|
129
|
+
? schemas[name]
|
|
130
|
+
: undefined;
|
|
131
|
+
if (schema) {
|
|
132
|
+
values.push([
|
|
133
|
+
name,
|
|
134
|
+
await validateWithSchema(name, 'result', flag.value, schema),
|
|
135
|
+
]);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
if (!this.#variantStore)
|
|
139
|
+
validateFlagValue(name, fallback, flag.value);
|
|
140
|
+
values.push([name, flag.value]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (missing.length > 0) {
|
|
145
|
+
this.#logger?.warn({
|
|
146
|
+
store: this.#store.name,
|
|
147
|
+
reason: 'missing',
|
|
148
|
+
names: missing,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
this.#logger?.debug({
|
|
152
|
+
store: this.#store.name,
|
|
153
|
+
outcome: missing.length === 0
|
|
154
|
+
? 'found'
|
|
155
|
+
: missing.length === names.length
|
|
156
|
+
? 'fallback'
|
|
157
|
+
: 'partial',
|
|
158
|
+
names,
|
|
159
|
+
});
|
|
160
|
+
return Object.fromEntries(values);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Gets enabled flag names in the {@link Store | `Store`}'s iteration order.
|
|
164
|
+
*
|
|
165
|
+
* @param {Object} options - Configure the lookup
|
|
166
|
+
* @param {EvaluationContext} options.context - Supply scalar facts for evaluation
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* const enabled = await flags.getEnabledFeatures({ context: { tier: 'premium' } });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
async getEnabledFeatures(options = {}) {
|
|
173
|
+
const { context = {} } = options;
|
|
174
|
+
validateContext(context);
|
|
175
|
+
let result;
|
|
176
|
+
try {
|
|
177
|
+
result = await this.#store.getAll(context);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if (!(error instanceof errors_js_1.StoreUnavailableError))
|
|
181
|
+
throw error;
|
|
182
|
+
this.#logger?.warn({ store: this.#store.name, reason: 'unavailable' });
|
|
183
|
+
this.#logger?.debug({
|
|
184
|
+
store: this.#store.name,
|
|
185
|
+
outcome: 'fallback',
|
|
186
|
+
enabled: 0,
|
|
187
|
+
});
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
190
|
+
const enabled = [];
|
|
191
|
+
for (const [name, flag] of Object.entries(result)) {
|
|
192
|
+
if (flag.found && flag.enabled)
|
|
193
|
+
enabled.push(name);
|
|
194
|
+
}
|
|
195
|
+
this.#logger?.debug({
|
|
196
|
+
store: this.#store.name,
|
|
197
|
+
outcome: 'found',
|
|
198
|
+
enabled: enabled.length,
|
|
199
|
+
});
|
|
200
|
+
return enabled;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.FeatureFlags = FeatureFlags;
|
|
204
|
+
/**
|
|
205
|
+
* Validates a fallback or Store result and returns the schema output.
|
|
206
|
+
* @param name - Identify the flag
|
|
207
|
+
* @param source - Identify the fallback or result
|
|
208
|
+
* @param value - Supply the value to validate
|
|
209
|
+
* @param schema - Supply the Standard Schema validator
|
|
210
|
+
* @internal
|
|
211
|
+
*/
|
|
212
|
+
const validateWithSchema = async (name, source, value, schema) => {
|
|
213
|
+
let result;
|
|
214
|
+
try {
|
|
215
|
+
result = await schema['~standard'].validate(value);
|
|
216
|
+
}
|
|
217
|
+
catch (cause) {
|
|
218
|
+
throw new errors_js_1.FlagResultValidationError(name, source, [], { cause });
|
|
219
|
+
}
|
|
220
|
+
if (result.issues) {
|
|
221
|
+
throw new errors_js_1.FlagResultValidationError(name, source, result.issues);
|
|
222
|
+
}
|
|
223
|
+
if (result.value === undefined) {
|
|
224
|
+
throw new errors_js_1.FlagResultValidationError(name, source, []);
|
|
225
|
+
}
|
|
226
|
+
// Schemas own the validated value contract; public overloads expose their output type.
|
|
227
|
+
return result.value;
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Validates scalar context facts before contacting the Store.
|
|
231
|
+
* @param context - Supply the evaluation context
|
|
232
|
+
* @internal
|
|
233
|
+
*/
|
|
234
|
+
const validateContext = (context) => {
|
|
235
|
+
for (const [key, value] of Object.entries(context)) {
|
|
236
|
+
if (!(Array.isArray(value)
|
|
237
|
+
? Array.from(value).every(context_js_1.isScalar)
|
|
238
|
+
: (0, context_js_1.isScalar)(value))) {
|
|
239
|
+
throw new errors_js_1.InvalidContextError(`Invalid evaluation context key '${key}': expected a string, number, boolean, or array of those, received ${(0, context_js_1.getInvalidContextKind)(value)}`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* Checks a Store value against its primitive fallback type.
|
|
245
|
+
* @param name - Identify the flag
|
|
246
|
+
* @param fallback - Supply the expected primitive type
|
|
247
|
+
* @param value - Supply the Store value
|
|
248
|
+
* @internal
|
|
249
|
+
*/
|
|
250
|
+
const validateFlagValue = (name, fallback, value) => {
|
|
251
|
+
if ((0, context_js_1.isScalar)(fallback) && typeof value !== typeof fallback) {
|
|
252
|
+
throw new errors_js_1.FlagValueTypeError(`Flag '${name}' expected type '${typeof fallback}' but received '${typeof value}'`);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
/** Rejects invalid Variant fallbacks before contacting the Store. @internal */
|
|
256
|
+
const validateVariantFallback = (name, fallback) => {
|
|
257
|
+
if (!(0, variant_js_1.isVariant)(fallback)) {
|
|
258
|
+
throw new errors_js_1.FlagValueTypeError(`Flag '${name}' requires a Variant fallback`);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AppConfigStoreOptions } from '../types/AppConfigStore.js';
|
|
2
|
+
import type { Store } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Store that retrieves and evaluates AppConfig freeform Flag Documents.
|
|
5
|
+
*
|
|
6
|
+
* Install `@aws-lambda-powertools/parameters` and `@aws-sdk/client-appconfigdata`
|
|
7
|
+
* to use this sub-path. One provider per Store owns retrieval caching.
|
|
8
|
+
* Supply both `envelope` and `envelopeSearchFn` to select an embedded document.
|
|
9
|
+
* Known availability failures return the evaluator's fallback; configuration,
|
|
10
|
+
* transform, and envelope errors propagate.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} options - Configure retrieval and logging
|
|
13
|
+
* @param {string} options.name - Identify the configuration profile
|
|
14
|
+
* @param {string} options.environment - Identify the environment
|
|
15
|
+
* @param {string} options.application - Identify the application or use the service name
|
|
16
|
+
* @param {string} options.envelope - Select an embedded Flag Document
|
|
17
|
+
* @param {Function} options.envelopeSearchFn - Apply the envelope expression
|
|
18
|
+
* @param {number} options.maxAge - Set the Parameters cache duration in seconds
|
|
19
|
+
* @param {AppConfigDataClient} options.awsSdkV3Client - Supply an AppConfigData client
|
|
20
|
+
* @param {AppConfigDataClientConfig} options.clientConfig - Configure a new AppConfigData client
|
|
21
|
+
* @param {GenericLogger} options.logger - Log rule engine outcomes without values
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { FeatureFlags } from '@aws-lambda-powertools/feature-flags';
|
|
25
|
+
* import { appConfigStore } from '@aws-lambda-powertools/feature-flags/appconfig';
|
|
26
|
+
* import { search } from '@aws-lambda-powertools/feature-flags/envelope';
|
|
27
|
+
*
|
|
28
|
+
* const store = appConfigStore({
|
|
29
|
+
* application: 'my-app', environment: 'prod', name: 'features',
|
|
30
|
+
* envelope: 'settings.flags', envelopeSearchFn: search,
|
|
31
|
+
* });
|
|
32
|
+
* const flags = new FeatureFlags({ store });
|
|
33
|
+
* const enabled = await flags.evaluate({ name: 'checkout_v2', default: false });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare const appConfigStore: (options: AppConfigStoreOptions) => Store;
|
|
37
|
+
export { appConfigStore };
|
|
38
|
+
//# sourceMappingURL=appConfigStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appConfigStore.d.ts","sourceRoot":"","sources":["../../../src/appconfig/appConfigStore.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,QAAA,MAAM,cAAc,GAAI,SAAS,qBAAqB,KAAG,KAuBxD,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.appConfigStore = void 0;
|
|
4
|
+
const appconfig_1 = require("@aws-lambda-powertools/parameters/appconfig");
|
|
5
|
+
const constants_js_1 = require("../constants.js");
|
|
6
|
+
const createDocumentSource_js_1 = require("../parameters-stores/createDocumentSource.js");
|
|
7
|
+
const envelope_js_1 = require("../parameters-stores/envelope.js");
|
|
8
|
+
const index_js_1 = require("../ruleEngine/index.js");
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Store that retrieves and evaluates AppConfig freeform Flag Documents.
|
|
11
|
+
*
|
|
12
|
+
* Install `@aws-lambda-powertools/parameters` and `@aws-sdk/client-appconfigdata`
|
|
13
|
+
* to use this sub-path. One provider per Store owns retrieval caching.
|
|
14
|
+
* Supply both `envelope` and `envelopeSearchFn` to select an embedded document.
|
|
15
|
+
* Known availability failures return the evaluator's fallback; configuration,
|
|
16
|
+
* transform, and envelope errors propagate.
|
|
17
|
+
*
|
|
18
|
+
* @param {Object} options - Configure retrieval and logging
|
|
19
|
+
* @param {string} options.name - Identify the configuration profile
|
|
20
|
+
* @param {string} options.environment - Identify the environment
|
|
21
|
+
* @param {string} options.application - Identify the application or use the service name
|
|
22
|
+
* @param {string} options.envelope - Select an embedded Flag Document
|
|
23
|
+
* @param {Function} options.envelopeSearchFn - Apply the envelope expression
|
|
24
|
+
* @param {number} options.maxAge - Set the Parameters cache duration in seconds
|
|
25
|
+
* @param {AppConfigDataClient} options.awsSdkV3Client - Supply an AppConfigData client
|
|
26
|
+
* @param {AppConfigDataClientConfig} options.clientConfig - Configure a new AppConfigData client
|
|
27
|
+
* @param {GenericLogger} options.logger - Log rule engine outcomes without values
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { FeatureFlags } from '@aws-lambda-powertools/feature-flags';
|
|
31
|
+
* import { appConfigStore } from '@aws-lambda-powertools/feature-flags/appconfig';
|
|
32
|
+
* import { search } from '@aws-lambda-powertools/feature-flags/envelope';
|
|
33
|
+
*
|
|
34
|
+
* const store = appConfigStore({
|
|
35
|
+
* application: 'my-app', environment: 'prod', name: 'features',
|
|
36
|
+
* envelope: 'settings.flags', envelopeSearchFn: search,
|
|
37
|
+
* });
|
|
38
|
+
* const flags = new FeatureFlags({ store });
|
|
39
|
+
* const enabled = await flags.evaluate({ name: 'checkout_v2', default: false });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
const appConfigStore = (options) => {
|
|
43
|
+
const envelopeOptions = (0, envelope_js_1.validateEnvelopeOptions)(options);
|
|
44
|
+
const provider = new appconfig_1.AppConfigProvider({
|
|
45
|
+
application: options.application,
|
|
46
|
+
environment: options.environment,
|
|
47
|
+
...(options.awsSdkV3Client
|
|
48
|
+
? { awsSdkV3Client: options.awsSdkV3Client }
|
|
49
|
+
: { clientConfig: options.clientConfig }),
|
|
50
|
+
});
|
|
51
|
+
return (0, index_js_1.ruleEngineStore)({
|
|
52
|
+
name: constants_js_1.StoreNames.APPCONFIG,
|
|
53
|
+
logger: options.logger,
|
|
54
|
+
source: (0, createDocumentSource_js_1.createDocumentSource)({
|
|
55
|
+
storeName: constants_js_1.StoreNames.APPCONFIG,
|
|
56
|
+
...envelopeOptions,
|
|
57
|
+
retrieve: () => provider.get(options.name, {
|
|
58
|
+
transform: 'json',
|
|
59
|
+
maxAge: options.maxAge,
|
|
60
|
+
throwOnMissing: true,
|
|
61
|
+
}),
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
exports.appConfigStore = appConfigStore;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/appconfig/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.appConfigStore = void 0;
|
|
4
|
+
var appConfigStore_js_1 = require("./appConfigStore.js");
|
|
5
|
+
Object.defineProperty(exports, "appConfigStore", { enumerable: true, get: function () { return appConfigStore_js_1.appConfigStore; } });
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AppConfigAgentStoreOptions } from '../types/AppConfigAgentStore.js';
|
|
2
|
+
import type { Store } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Store that retrieves freeform Flag Documents through the AppConfig Agent.
|
|
5
|
+
*
|
|
6
|
+
* Install `@aws-lambda-powertools/parameters` to use this sub-path. Attach the AppConfig
|
|
7
|
+
* Agent Lambda extension to your function. The Agent owns caching and polling;
|
|
8
|
+
* this Store evaluates the retrieved document locally without loading the SDK.
|
|
9
|
+
* Supply both `envelope` and `envelopeSearchFn` to select an embedded document.
|
|
10
|
+
* Known availability failures return the evaluator's fallback; configuration,
|
|
11
|
+
* transform, and envelope errors propagate.
|
|
12
|
+
*
|
|
13
|
+
* @param {Object} options - Configure retrieval and logging
|
|
14
|
+
* @param {string} options.name - Identify the configuration profile
|
|
15
|
+
* @param {string} options.environment - Identify the environment
|
|
16
|
+
* @param {string} options.application - Identify the application or use the service name
|
|
17
|
+
* @param {string} options.envelope - Select an embedded Flag Document
|
|
18
|
+
* @param {Function} options.envelopeSearchFn - Apply the envelope expression
|
|
19
|
+
* @param {number} options.timeout - Set the request timeout in milliseconds
|
|
20
|
+
* @param {GenericLogger} options.logger - Log rule engine outcomes without values
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { FeatureFlags } from '@aws-lambda-powertools/feature-flags';
|
|
24
|
+
* import { appConfigAgentStore } from '@aws-lambda-powertools/feature-flags/appconfig-agent';
|
|
25
|
+
* import { search } from '@aws-lambda-powertools/feature-flags/envelope';
|
|
26
|
+
*
|
|
27
|
+
* const store = appConfigAgentStore({
|
|
28
|
+
* application: 'my-app', environment: 'prod', name: 'features',
|
|
29
|
+
* envelope: 'settings.flags', envelopeSearchFn: search,
|
|
30
|
+
* });
|
|
31
|
+
* const flags = new FeatureFlags({ store });
|
|
32
|
+
* const enabled = await flags.evaluate({ name: 'checkout_v2', default: false });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare const appConfigAgentStore: (options: AppConfigAgentStoreOptions) => Store;
|
|
36
|
+
export { appConfigAgentStore };
|
|
37
|
+
//# sourceMappingURL=appConfigAgentStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appConfigAgentStore.d.ts","sourceRoot":"","sources":["../../../src/appconfig-agent/appConfigAgentStore.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAClF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,QAAA,MAAM,mBAAmB,GAAI,SAAS,0BAA0B,KAAG,KAkBlE,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.appConfigAgentStore = void 0;
|
|
4
|
+
const appconfig_agent_1 = require("@aws-lambda-powertools/parameters/appconfig-agent");
|
|
5
|
+
const constants_js_1 = require("../constants.js");
|
|
6
|
+
const createDocumentSource_js_1 = require("../parameters-stores/createDocumentSource.js");
|
|
7
|
+
const envelope_js_1 = require("../parameters-stores/envelope.js");
|
|
8
|
+
const index_js_1 = require("../ruleEngine/index.js");
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Store that retrieves freeform Flag Documents through the AppConfig Agent.
|
|
11
|
+
*
|
|
12
|
+
* Install `@aws-lambda-powertools/parameters` to use this sub-path. Attach the AppConfig
|
|
13
|
+
* Agent Lambda extension to your function. The Agent owns caching and polling;
|
|
14
|
+
* this Store evaluates the retrieved document locally without loading the SDK.
|
|
15
|
+
* Supply both `envelope` and `envelopeSearchFn` to select an embedded document.
|
|
16
|
+
* Known availability failures return the evaluator's fallback; configuration,
|
|
17
|
+
* transform, and envelope errors propagate.
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} options - Configure retrieval and logging
|
|
20
|
+
* @param {string} options.name - Identify the configuration profile
|
|
21
|
+
* @param {string} options.environment - Identify the environment
|
|
22
|
+
* @param {string} options.application - Identify the application or use the service name
|
|
23
|
+
* @param {string} options.envelope - Select an embedded Flag Document
|
|
24
|
+
* @param {Function} options.envelopeSearchFn - Apply the envelope expression
|
|
25
|
+
* @param {number} options.timeout - Set the request timeout in milliseconds
|
|
26
|
+
* @param {GenericLogger} options.logger - Log rule engine outcomes without values
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { FeatureFlags } from '@aws-lambda-powertools/feature-flags';
|
|
30
|
+
* import { appConfigAgentStore } from '@aws-lambda-powertools/feature-flags/appconfig-agent';
|
|
31
|
+
* import { search } from '@aws-lambda-powertools/feature-flags/envelope';
|
|
32
|
+
*
|
|
33
|
+
* const store = appConfigAgentStore({
|
|
34
|
+
* application: 'my-app', environment: 'prod', name: 'features',
|
|
35
|
+
* envelope: 'settings.flags', envelopeSearchFn: search,
|
|
36
|
+
* });
|
|
37
|
+
* const flags = new FeatureFlags({ store });
|
|
38
|
+
* const enabled = await flags.evaluate({ name: 'checkout_v2', default: false });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
const appConfigAgentStore = (options) => {
|
|
42
|
+
const envelopeOptions = (0, envelope_js_1.validateEnvelopeOptions)(options);
|
|
43
|
+
return (0, index_js_1.ruleEngineStore)({
|
|
44
|
+
name: constants_js_1.StoreNames.APPCONFIG_AGENT,
|
|
45
|
+
logger: options.logger,
|
|
46
|
+
source: (0, createDocumentSource_js_1.createDocumentSource)({
|
|
47
|
+
storeName: constants_js_1.StoreNames.APPCONFIG_AGENT,
|
|
48
|
+
...envelopeOptions,
|
|
49
|
+
retrieve: () => (0, appconfig_agent_1.getConfig)(options.name, {
|
|
50
|
+
application: options.application,
|
|
51
|
+
environment: options.environment,
|
|
52
|
+
timeout: options.timeout,
|
|
53
|
+
transform: 'json',
|
|
54
|
+
throwOnMissing: true,
|
|
55
|
+
}),
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
exports.appConfigAgentStore = appConfigAgentStore;
|