@aws-lambda-powertools/feature-flags 0.0.0-stage → 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.
Files changed (196) hide show
  1. package/README.md +71 -2
  2. package/lib/cjs/FeatureFlags.d.ts +98 -0
  3. package/lib/cjs/FeatureFlags.d.ts.map +1 -0
  4. package/lib/cjs/FeatureFlags.js +260 -0
  5. package/lib/cjs/appconfig/appConfigStore.d.ts +38 -0
  6. package/lib/cjs/appconfig/appConfigStore.d.ts.map +1 -0
  7. package/lib/cjs/appconfig/appConfigStore.js +65 -0
  8. package/lib/cjs/appconfig/index.d.ts +4 -0
  9. package/lib/cjs/appconfig/index.d.ts.map +1 -0
  10. package/lib/cjs/appconfig/index.js +5 -0
  11. package/lib/cjs/appconfig-agent/appConfigAgentStore.d.ts +37 -0
  12. package/lib/cjs/appconfig-agent/appConfigAgentStore.d.ts.map +1 -0
  13. package/lib/cjs/appconfig-agent/appConfigAgentStore.js +59 -0
  14. package/lib/cjs/appconfig-agent/appConfigVariantStore.d.ts +46 -0
  15. package/lib/cjs/appconfig-agent/appConfigVariantStore.d.ts.map +1 -0
  16. package/lib/cjs/appconfig-agent/appConfigVariantStore.js +176 -0
  17. package/lib/cjs/appconfig-agent/index.d.ts +6 -0
  18. package/lib/cjs/appconfig-agent/index.d.ts.map +1 -0
  19. package/lib/cjs/appconfig-agent/index.js +8 -0
  20. package/lib/cjs/constants.d.ts +56 -0
  21. package/lib/cjs/constants.d.ts.map +1 -0
  22. package/lib/cjs/constants.js +86 -0
  23. package/lib/cjs/context.d.ts +21 -0
  24. package/lib/cjs/context.d.ts.map +1 -0
  25. package/lib/cjs/context.js +42 -0
  26. package/lib/cjs/envelope/index.d.ts +20 -0
  27. package/lib/cjs/envelope/index.d.ts.map +1 -0
  28. package/lib/cjs/envelope/index.js +29 -0
  29. package/lib/cjs/errors.d.ts +74 -0
  30. package/lib/cjs/errors.d.ts.map +1 -0
  31. package/lib/cjs/errors.js +116 -0
  32. package/lib/cjs/index.d.ts +6 -0
  33. package/lib/cjs/index.d.ts.map +1 -0
  34. package/lib/cjs/index.js +15 -0
  35. package/lib/cjs/package.json +1 -0
  36. package/lib/cjs/parameters-stores/classify.d.ts +20 -0
  37. package/lib/cjs/parameters-stores/classify.d.ts.map +1 -0
  38. package/lib/cjs/parameters-stores/classify.js +50 -0
  39. package/lib/cjs/parameters-stores/createDocumentSource.d.ts +17 -0
  40. package/lib/cjs/parameters-stores/createDocumentSource.d.ts.map +1 -0
  41. package/lib/cjs/parameters-stores/createDocumentSource.js +31 -0
  42. package/lib/cjs/parameters-stores/envelope.d.ts +22 -0
  43. package/lib/cjs/parameters-stores/envelope.d.ts.map +1 -0
  44. package/lib/cjs/parameters-stores/envelope.js +39 -0
  45. package/lib/cjs/ruleEngine/actions.d.ts +5 -0
  46. package/lib/cjs/ruleEngine/actions.d.ts.map +1 -0
  47. package/lib/cjs/ruleEngine/actions.js +155 -0
  48. package/lib/cjs/ruleEngine/datetime.d.ts +12 -0
  49. package/lib/cjs/ruleEngine/datetime.d.ts.map +1 -0
  50. package/lib/cjs/ruleEngine/datetime.js +134 -0
  51. package/lib/cjs/ruleEngine/evaluate.d.ts +15 -0
  52. package/lib/cjs/ruleEngine/evaluate.d.ts.map +1 -0
  53. package/lib/cjs/ruleEngine/evaluate.js +60 -0
  54. package/lib/cjs/ruleEngine/guards.d.ts +51 -0
  55. package/lib/cjs/ruleEngine/guards.d.ts.map +1 -0
  56. package/lib/cjs/ruleEngine/guards.js +123 -0
  57. package/lib/cjs/ruleEngine/index.d.ts +35 -0
  58. package/lib/cjs/ruleEngine/index.d.ts.map +1 -0
  59. package/lib/cjs/ruleEngine/index.js +70 -0
  60. package/lib/cjs/ruleEngine/json.d.ts +16 -0
  61. package/lib/cjs/ruleEngine/json.d.ts.map +1 -0
  62. package/lib/cjs/ruleEngine/json.js +38 -0
  63. package/lib/cjs/ruleEngine/time.d.ts +14 -0
  64. package/lib/cjs/ruleEngine/time.d.ts.map +1 -0
  65. package/lib/cjs/ruleEngine/time.js +102 -0
  66. package/lib/cjs/ruleEngine/validate.d.ts +11 -0
  67. package/lib/cjs/ruleEngine/validate.d.ts.map +1 -0
  68. package/lib/cjs/ruleEngine/validate.js +134 -0
  69. package/lib/cjs/ruleEngine/validateScheduleAndModulo.d.ts +13 -0
  70. package/lib/cjs/ruleEngine/validateScheduleAndModulo.d.ts.map +1 -0
  71. package/lib/cjs/ruleEngine/validateScheduleAndModulo.js +38 -0
  72. package/lib/cjs/ruleEngine/validationCache.d.ts +12 -0
  73. package/lib/cjs/ruleEngine/validationCache.d.ts.map +1 -0
  74. package/lib/cjs/ruleEngine/validationCache.js +29 -0
  75. package/lib/cjs/types/AppConfigAgentStore.d.ts +20 -0
  76. package/lib/cjs/types/AppConfigAgentStore.d.ts.map +1 -0
  77. package/lib/cjs/types/AppConfigAgentStore.js +2 -0
  78. package/lib/cjs/types/AppConfigStore.d.ts +25 -0
  79. package/lib/cjs/types/AppConfigStore.d.ts.map +1 -0
  80. package/lib/cjs/types/AppConfigStore.js +2 -0
  81. package/lib/cjs/types/AppConfigVariantStore.d.ts +16 -0
  82. package/lib/cjs/types/AppConfigVariantStore.d.ts.map +1 -0
  83. package/lib/cjs/types/AppConfigVariantStore.js +2 -0
  84. package/lib/cjs/types/Envelope.d.ts +16 -0
  85. package/lib/cjs/types/Envelope.d.ts.map +1 -0
  86. package/lib/cjs/types/Envelope.js +2 -0
  87. package/lib/cjs/types/RuleEngine.d.ts +83 -0
  88. package/lib/cjs/types/RuleEngine.d.ts.map +1 -0
  89. package/lib/cjs/types/RuleEngine.js +2 -0
  90. package/lib/cjs/types/VariantEvaluation.d.ts +20 -0
  91. package/lib/cjs/types/VariantEvaluation.d.ts.map +1 -0
  92. package/lib/cjs/types/VariantEvaluation.js +2 -0
  93. package/lib/cjs/types/index.d.ts +81 -0
  94. package/lib/cjs/types/index.d.ts.map +1 -0
  95. package/lib/cjs/types/index.js +2 -0
  96. package/lib/cjs/variant.d.ts +9 -0
  97. package/lib/cjs/variant.d.ts.map +1 -0
  98. package/lib/cjs/variant.js +26 -0
  99. package/lib/esm/FeatureFlags.d.ts +98 -0
  100. package/lib/esm/FeatureFlags.d.ts.map +1 -0
  101. package/lib/esm/FeatureFlags.js +257 -0
  102. package/lib/esm/appconfig/appConfigStore.d.ts +38 -0
  103. package/lib/esm/appconfig/appConfigStore.d.ts.map +1 -0
  104. package/lib/esm/appconfig/appConfigStore.js +62 -0
  105. package/lib/esm/appconfig/index.d.ts +4 -0
  106. package/lib/esm/appconfig/index.d.ts.map +1 -0
  107. package/lib/esm/appconfig/index.js +1 -0
  108. package/lib/esm/appconfig-agent/appConfigAgentStore.d.ts +37 -0
  109. package/lib/esm/appconfig-agent/appConfigAgentStore.d.ts.map +1 -0
  110. package/lib/esm/appconfig-agent/appConfigAgentStore.js +56 -0
  111. package/lib/esm/appconfig-agent/appConfigVariantStore.d.ts +46 -0
  112. package/lib/esm/appconfig-agent/appConfigVariantStore.d.ts.map +1 -0
  113. package/lib/esm/appconfig-agent/appConfigVariantStore.js +172 -0
  114. package/lib/esm/appconfig-agent/index.d.ts +6 -0
  115. package/lib/esm/appconfig-agent/index.d.ts.map +1 -0
  116. package/lib/esm/appconfig-agent/index.js +2 -0
  117. package/lib/esm/constants.d.ts +56 -0
  118. package/lib/esm/constants.d.ts.map +1 -0
  119. package/lib/esm/constants.js +77 -0
  120. package/lib/esm/context.d.ts +21 -0
  121. package/lib/esm/context.d.ts.map +1 -0
  122. package/lib/esm/context.js +37 -0
  123. package/lib/esm/envelope/index.d.ts +20 -0
  124. package/lib/esm/envelope/index.d.ts.map +1 -0
  125. package/lib/esm/envelope/index.js +26 -0
  126. package/lib/esm/errors.d.ts +74 -0
  127. package/lib/esm/errors.d.ts.map +1 -0
  128. package/lib/esm/errors.js +107 -0
  129. package/lib/esm/index.d.ts +6 -0
  130. package/lib/esm/index.d.ts.map +1 -0
  131. package/lib/esm/index.js +3 -0
  132. package/lib/esm/package.json +1 -0
  133. package/lib/esm/parameters-stores/classify.d.ts +20 -0
  134. package/lib/esm/parameters-stores/classify.d.ts.map +1 -0
  135. package/lib/esm/parameters-stores/classify.js +47 -0
  136. package/lib/esm/parameters-stores/createDocumentSource.d.ts +17 -0
  137. package/lib/esm/parameters-stores/createDocumentSource.d.ts.map +1 -0
  138. package/lib/esm/parameters-stores/createDocumentSource.js +28 -0
  139. package/lib/esm/parameters-stores/envelope.d.ts +22 -0
  140. package/lib/esm/parameters-stores/envelope.d.ts.map +1 -0
  141. package/lib/esm/parameters-stores/envelope.js +35 -0
  142. package/lib/esm/ruleEngine/actions.d.ts +5 -0
  143. package/lib/esm/ruleEngine/actions.d.ts.map +1 -0
  144. package/lib/esm/ruleEngine/actions.js +152 -0
  145. package/lib/esm/ruleEngine/datetime.d.ts +12 -0
  146. package/lib/esm/ruleEngine/datetime.d.ts.map +1 -0
  147. package/lib/esm/ruleEngine/datetime.js +131 -0
  148. package/lib/esm/ruleEngine/evaluate.d.ts +15 -0
  149. package/lib/esm/ruleEngine/evaluate.d.ts.map +1 -0
  150. package/lib/esm/ruleEngine/evaluate.js +57 -0
  151. package/lib/esm/ruleEngine/guards.d.ts +51 -0
  152. package/lib/esm/ruleEngine/guards.d.ts.map +1 -0
  153. package/lib/esm/ruleEngine/guards.js +113 -0
  154. package/lib/esm/ruleEngine/index.d.ts +35 -0
  155. package/lib/esm/ruleEngine/index.d.ts.map +1 -0
  156. package/lib/esm/ruleEngine/index.js +67 -0
  157. package/lib/esm/ruleEngine/json.d.ts +16 -0
  158. package/lib/esm/ruleEngine/json.d.ts.map +1 -0
  159. package/lib/esm/ruleEngine/json.js +34 -0
  160. package/lib/esm/ruleEngine/time.d.ts +14 -0
  161. package/lib/esm/ruleEngine/time.d.ts.map +1 -0
  162. package/lib/esm/ruleEngine/time.js +97 -0
  163. package/lib/esm/ruleEngine/validate.d.ts +11 -0
  164. package/lib/esm/ruleEngine/validate.d.ts.map +1 -0
  165. package/lib/esm/ruleEngine/validate.js +131 -0
  166. package/lib/esm/ruleEngine/validateScheduleAndModulo.d.ts +13 -0
  167. package/lib/esm/ruleEngine/validateScheduleAndModulo.d.ts.map +1 -0
  168. package/lib/esm/ruleEngine/validateScheduleAndModulo.js +35 -0
  169. package/lib/esm/ruleEngine/validationCache.d.ts +12 -0
  170. package/lib/esm/ruleEngine/validationCache.d.ts.map +1 -0
  171. package/lib/esm/ruleEngine/validationCache.js +26 -0
  172. package/lib/esm/types/AppConfigAgentStore.d.ts +20 -0
  173. package/lib/esm/types/AppConfigAgentStore.d.ts.map +1 -0
  174. package/lib/esm/types/AppConfigAgentStore.js +1 -0
  175. package/lib/esm/types/AppConfigStore.d.ts +25 -0
  176. package/lib/esm/types/AppConfigStore.d.ts.map +1 -0
  177. package/lib/esm/types/AppConfigStore.js +1 -0
  178. package/lib/esm/types/AppConfigVariantStore.d.ts +16 -0
  179. package/lib/esm/types/AppConfigVariantStore.d.ts.map +1 -0
  180. package/lib/esm/types/AppConfigVariantStore.js +1 -0
  181. package/lib/esm/types/Envelope.d.ts +16 -0
  182. package/lib/esm/types/Envelope.d.ts.map +1 -0
  183. package/lib/esm/types/Envelope.js +1 -0
  184. package/lib/esm/types/RuleEngine.d.ts +83 -0
  185. package/lib/esm/types/RuleEngine.d.ts.map +1 -0
  186. package/lib/esm/types/RuleEngine.js +1 -0
  187. package/lib/esm/types/VariantEvaluation.d.ts +20 -0
  188. package/lib/esm/types/VariantEvaluation.d.ts.map +1 -0
  189. package/lib/esm/types/VariantEvaluation.js +1 -0
  190. package/lib/esm/types/index.d.ts +81 -0
  191. package/lib/esm/types/index.d.ts.map +1 -0
  192. package/lib/esm/types/index.js +1 -0
  193. package/lib/esm/variant.d.ts +9 -0
  194. package/lib/esm/variant.d.ts.map +1 -0
  195. package/lib/esm/variant.js +21 -0
  196. package/package.json +137 -3
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validate = void 0;
4
+ const commons_1 = require("@aws-lambda-powertools/commons");
5
+ const constants_js_1 = require("../constants.js");
6
+ const errors_js_1 = require("../errors.js");
7
+ const json_js_1 = require("./json.js");
8
+ const validateScheduleAndModulo_js_1 = require("./validateScheduleAndModulo.js");
9
+ /**
10
+ * Validates an entire Python-format Flag Document and returns typed definitions.
11
+ * @param document - Supply the retrieved document
12
+ * @param logger - Log accepted empty documents and empty Rules without values
13
+ * @internal
14
+ */
15
+ const validate = (document, logger) => {
16
+ if (!(0, commons_1.isRecord)(document))
17
+ throw new errors_js_1.SchemaValidationError('Flag Document must be an object');
18
+ const entries = [];
19
+ for (const [name, flag] of Object.entries(document)) {
20
+ const location = `Flag '${name}'`;
21
+ if (!(0, commons_1.isRecord)(flag) || !Object.hasOwn(flag, constants_js_1.FlagDocumentFields.DEFAULT)) {
22
+ throw new errors_js_1.SchemaValidationError(`${location} must be an object with a default`);
23
+ }
24
+ const booleanType = Object.hasOwn(flag, constants_js_1.FlagDocumentFields.BOOLEAN_TYPE)
25
+ ? flag[constants_js_1.FlagDocumentFields.BOOLEAN_TYPE]
26
+ : true;
27
+ if (typeof booleanType !== 'boolean')
28
+ throw new errors_js_1.SchemaValidationError(`${location} boolean_type must be a boolean`);
29
+ const defaultValue = validateResult(flag[constants_js_1.FlagDocumentFields.DEFAULT], booleanType, `${location} default`);
30
+ const rules = Object.hasOwn(flag, constants_js_1.FlagDocumentFields.RULES)
31
+ ? validateRules(flag[constants_js_1.FlagDocumentFields.RULES], name, booleanType, logger)
32
+ : {};
33
+ entries.push([name, { default: defaultValue, rules }]);
34
+ }
35
+ if (entries.length === 0)
36
+ logger?.warn({ store: constants_js_1.StoreNames.RULE_ENGINE, reason: 'empty-document' });
37
+ return Object.fromEntries(entries);
38
+ };
39
+ exports.validate = validate;
40
+ /**
41
+ * Validates named Rules without changing their insertion order.
42
+ * @param rules - Supply the Rules object
43
+ * @param name - Identify the flag
44
+ * @param booleanType - Require boolean results for boolean flags
45
+ * @param logger - Log accepted empty Rules without values
46
+ * @internal
47
+ */
48
+ const validateRules = (rules, name, booleanType, logger) => {
49
+ if (!(0, commons_1.isRecord)(rules))
50
+ throw new errors_js_1.SchemaValidationError(`Flag '${name}' rules must be an object`);
51
+ const entries = [];
52
+ for (const [ruleName, rule] of Object.entries(rules)) {
53
+ const location = `Flag '${name}', rule '${ruleName}'`;
54
+ if (ruleName.length === 0 ||
55
+ (/^(0|[1-9]\d*)$/.test(ruleName) && Number(ruleName) < 2 ** 32 - 1)) {
56
+ throw new errors_js_1.SchemaValidationError(`${location} must use a non-empty name that preserves insertion order`);
57
+ }
58
+ if (!(0, commons_1.isRecord)(rule) ||
59
+ !Object.hasOwn(rule, constants_js_1.FlagDocumentFields.WHEN_MATCH)) {
60
+ throw new errors_js_1.SchemaValidationError(`${location} must be an object with when_match`);
61
+ }
62
+ const whenMatch = validateResult(rule[constants_js_1.FlagDocumentFields.WHEN_MATCH], booleanType, `${location} when_match`);
63
+ const conditions = rule[constants_js_1.FlagDocumentFields.CONDITIONS];
64
+ if (!Array.isArray(conditions) || conditions.length === 0) {
65
+ throw new errors_js_1.SchemaValidationError(`${location} conditions must be a non-empty array`);
66
+ }
67
+ const validatedConditions = [];
68
+ for (const [index, condition] of conditions.entries())
69
+ validatedConditions.push(validateCondition(condition, `${location}, condition ${index}`));
70
+ entries.push([
71
+ ruleName,
72
+ { when_match: whenMatch, conditions: validatedConditions },
73
+ ]);
74
+ }
75
+ if (entries.length === 0)
76
+ logger?.warn({
77
+ store: constants_js_1.StoreNames.RULE_ENGINE,
78
+ reason: 'empty-rules',
79
+ name,
80
+ });
81
+ return Object.fromEntries(entries);
82
+ };
83
+ /**
84
+ * Validates a Condition and identifies failures without including operand values.
85
+ * @param condition - Supply the Condition object
86
+ * @param location - Identify its flag, Rule, and zero-based Condition index
87
+ * @internal
88
+ */
89
+ const validateCondition = (condition, location) => {
90
+ if (!(0, commons_1.isRecord)(condition))
91
+ throw new errors_js_1.SchemaValidationError(`${location} must be an object`);
92
+ const action = condition[constants_js_1.FlagDocumentFields.ACTION];
93
+ const key = condition[constants_js_1.FlagDocumentFields.KEY];
94
+ const identifier = `${location}, key '${(0, commons_1.isString)(key) ? key : '<invalid>'}', action '${(0, commons_1.isString)(action) ? action : '<invalid>'}'`;
95
+ if (!(0, commons_1.isString)(action))
96
+ throw new errors_js_1.SchemaValidationError(`${identifier} action must be a string`);
97
+ if (!isRuleAction(action))
98
+ throw new errors_js_1.SchemaValidationError(`${identifier} action is unknown`);
99
+ if (!(0, commons_1.isString)(key) || key.length === 0)
100
+ throw new errors_js_1.SchemaValidationError(`${identifier} key must be a non-empty string`);
101
+ const value = condition[constants_js_1.FlagDocumentFields.VALUE];
102
+ if (!Object.hasOwn(condition, constants_js_1.FlagDocumentFields.VALUE) ||
103
+ !(0, json_js_1.isJSONValue)(value)) {
104
+ throw new errors_js_1.SchemaValidationError(`${identifier} value must be present and contain JSON`);
105
+ }
106
+ if ((action === constants_js_1.RuleActions.ALL_IN_VALUE ||
107
+ action === constants_js_1.RuleActions.ANY_IN_VALUE ||
108
+ action === constants_js_1.RuleActions.NONE_IN_VALUE) &&
109
+ !Array.isArray(value)) {
110
+ throw new errors_js_1.SchemaValidationError(`${identifier} value must be an array`);
111
+ }
112
+ (0, validateScheduleAndModulo_js_1.validateScheduleAndModulo)(action, key, value, identifier);
113
+ return { action, key, value };
114
+ };
115
+ /**
116
+ * Checks whether an Action belongs to the supported vocabulary.
117
+ * @param action - Supply the Action name
118
+ * @internal
119
+ */
120
+ const isRuleAction = (action) => Object.hasOwn(constants_js_1.RuleActions, action);
121
+ /**
122
+ * Validates a Flag Default or Rule result.
123
+ * @param value - Supply the result value
124
+ * @param booleanType - Require a boolean for boolean flags
125
+ * @param location - Identify the flag, Rule, and field without values
126
+ * @internal
127
+ */
128
+ const validateResult = (value, booleanType, location) => {
129
+ if (booleanType && typeof value !== 'boolean')
130
+ throw new errors_js_1.SchemaValidationError(`${location} must be a boolean`);
131
+ if (!(0, json_js_1.isJSONValue)(value))
132
+ throw new errors_js_1.SchemaValidationError(`${location} must contain JSON`);
133
+ return value;
134
+ };
@@ -0,0 +1,13 @@
1
+ import type { JSONValue } from '@aws-lambda-powertools/commons/types';
2
+ import type { RuleAction } from '../types/RuleEngine.js';
3
+ /**
4
+ * Validates schedule keys, time/day bounds, zones, and modulo integer bounds.
5
+ * @param action - Supply the validated Action name
6
+ * @param key - Supply the context or clock key
7
+ * @param value - Supply the JSON document operand
8
+ * @param location - Identify the Condition without operand values
9
+ * @internal
10
+ */
11
+ declare const validateScheduleAndModulo: (action: RuleAction, key: string, value: JSONValue, location: string) => void;
12
+ export { validateScheduleAndModulo };
13
+ //# sourceMappingURL=validateScheduleAndModulo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateScheduleAndModulo.d.ts","sourceRoot":"","sources":["../../../src/ruleEngine/validateScheduleAndModulo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAGtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAazD;;;;;;;GAOG;AACH,QAAA,MAAM,yBAAyB,GAC7B,QAAQ,UAAU,EAClB,KAAK,MAAM,EACX,OAAO,SAAS,EAChB,UAAU,MAAM,KACf,IA4BF,CAAC;AAEF,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateScheduleAndModulo = void 0;
4
+ const constants_js_1 = require("../constants.js");
5
+ const errors_js_1 = require("../errors.js");
6
+ const guards_js_1 = require("./guards.js");
7
+ const time_js_1 = require("./time.js");
8
+ /**
9
+ * Validates schedule keys, time/day bounds, zones, and modulo integer bounds.
10
+ * @param action - Supply the validated Action name
11
+ * @param key - Supply the context or clock key
12
+ * @param value - Supply the JSON document operand
13
+ * @param location - Identify the Condition without operand values
14
+ * @internal
15
+ */
16
+ const validateScheduleAndModulo = (action, key, value, location) => {
17
+ if (action === constants_js_1.RuleActions.MODULO_RANGE) {
18
+ if (!(0, guards_js_1.isModuloRange)(value))
19
+ throw new errors_js_1.SchemaValidationError(`${location} ${(0, guards_js_1.getModuloRangeError)(value)}`);
20
+ return;
21
+ }
22
+ if (!(0, time_js_1.isTimeAction)(action))
23
+ return;
24
+ if (key !== constants_js_1.TimeActionKeys[action])
25
+ throw new errors_js_1.SchemaValidationError(`${location} key must be ${constants_js_1.TimeActionKeys[action]}`);
26
+ if (action === constants_js_1.RuleActions.SCHEDULE_BETWEEN_DAYS_OF_WEEK) {
27
+ if (!(0, guards_js_1.isDaysOfWeek)(value))
28
+ throw new errors_js_1.SchemaValidationError(`${location} ${(0, guards_js_1.getDaysOfWeekError)(value)}`);
29
+ }
30
+ else if (action === constants_js_1.RuleActions.SCHEDULE_BETWEEN_TIME_RANGE) {
31
+ if (!(0, guards_js_1.isTimeRange)(value))
32
+ throw new errors_js_1.SchemaValidationError(`${location} ${(0, guards_js_1.getTimeRangeError)(value)}`);
33
+ }
34
+ else if (!(0, guards_js_1.isDatetimeRange)(value)) {
35
+ throw new errors_js_1.SchemaValidationError(`${location} ${(0, guards_js_1.getDatetimeRangeError)(value)}`);
36
+ }
37
+ };
38
+ exports.validateScheduleAndModulo = validateScheduleAndModulo;
@@ -0,0 +1,12 @@
1
+ import type { GenericLogger } from '@aws-lambda-powertools/commons/types';
2
+ import type { DocumentValidator } from '../types/RuleEngine.js';
3
+ /**
4
+ * Returns a validator that reuses the last validation while document content is unchanged.
5
+ * The returned function keeps state between calls: the last validated document and its content key.
6
+ * It keeps exactly one entry, and invalid documents throw without replacing it.
7
+ * @param logger - Log validation warnings without values
8
+ * @internal
9
+ */
10
+ declare const createValidationCache: (logger?: GenericLogger) => DocumentValidator;
11
+ export { createValidationCache };
12
+ //# sourceMappingURL=validationCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validationCache.d.ts","sourceRoot":"","sources":["../../../src/ruleEngine/validationCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAE1E,OAAO,KAAK,EACV,iBAAiB,EAElB,MAAM,wBAAwB,CAAC;AAIhC;;;;;;GAMG;AACH,QAAA,MAAM,qBAAqB,GAAI,SAAS,aAAa,KAAG,iBAcvD,CAAC;AAEF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createValidationCache = void 0;
4
+ const errors_js_1 = require("../errors.js");
5
+ const json_js_1 = require("./json.js");
6
+ const validate_js_1 = require("./validate.js");
7
+ /**
8
+ * Returns a validator that reuses the last validation while document content is unchanged.
9
+ * The returned function keeps state between calls: the last validated document and its content key.
10
+ * It keeps exactly one entry, and invalid documents throw without replacing it.
11
+ * @param logger - Log validation warnings without values
12
+ * @internal
13
+ */
14
+ const createValidationCache = (logger) => {
15
+ let lastValidated;
16
+ return (document) => {
17
+ // Check before stringifying: undefined, nonfinite numbers, and non-JSON objects can otherwise collide with valid JSON.
18
+ if (!(0, json_js_1.isJSONValue)(document))
19
+ throw new errors_js_1.SchemaValidationError('Flag Document must contain JSON');
20
+ const key = JSON.stringify(document);
21
+ if (lastValidated?.key === key)
22
+ return lastValidated.document;
23
+ // Validate an owned copy so neither source mutations nor concurrent retrievals change this call's rules.
24
+ const compiled = (0, validate_js_1.validate)(structuredClone(document), logger);
25
+ lastValidated = { key, document: compiled };
26
+ return compiled;
27
+ };
28
+ };
29
+ exports.createValidationCache = createValidationCache;
@@ -0,0 +1,20 @@
1
+ import type { GenericLogger } from '@aws-lambda-powertools/commons/types';
2
+ import type { EnvelopeOptions } from './Envelope.js';
3
+ /**
4
+ * Configures Agent retrieval and local evaluation of a freeform Flag Document.
5
+ * @expand
6
+ */
7
+ type AppConfigAgentStoreOptions = EnvelopeOptions & {
8
+ /** Identifies the configuration profile by name or ID. */
9
+ name: string;
10
+ /** Identifies the environment by name or ID. */
11
+ environment: string;
12
+ /** Identifies the application, defaulting to `POWERTOOLS_SERVICE_NAME`. */
13
+ application?: string;
14
+ /** Sets the Agent request timeout in milliseconds. */
15
+ timeout?: number;
16
+ /** Logs rule engine warnings and outcomes without values. */
17
+ logger?: GenericLogger;
18
+ };
19
+ export type { AppConfigAgentStoreOptions };
20
+ //# sourceMappingURL=AppConfigAgentStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppConfigAgentStore.d.ts","sourceRoot":"","sources":["../../../src/types/AppConfigAgentStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD;;;GAGG;AACH,KAAK,0BAA0B,GAAG,eAAe,GAAG;IAClD,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,YAAY,EAAE,0BAA0B,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,25 @@
1
+ import type { GenericLogger } from '@aws-lambda-powertools/commons/types';
2
+ import type { AppConfigDataClient, AppConfigDataClientConfig } from '@aws-sdk/client-appconfigdata';
3
+ import type { EnvelopeOptions } from './Envelope.js';
4
+ /**
5
+ * Configures retrieval and local evaluation of an AppConfig freeform Flag Document.
6
+ * @expand
7
+ */
8
+ type AppConfigStoreOptions = EnvelopeOptions & {
9
+ /** Identifies the configuration profile by name or ID. */
10
+ name: string;
11
+ /** Identifies the environment by name or ID. */
12
+ environment: string;
13
+ /** Identifies the application, defaulting to `POWERTOOLS_SERVICE_NAME`. */
14
+ application?: string;
15
+ /** Sets the Parameters cache duration in seconds. */
16
+ maxAge?: number;
17
+ /** Supplies the AppConfigData client instead of creating one. */
18
+ awsSdkV3Client?: AppConfigDataClient;
19
+ /** Configures the AppConfigData client when no client is supplied. */
20
+ clientConfig?: AppConfigDataClientConfig;
21
+ /** Logs rule engine warnings and outcomes without values. */
22
+ logger?: GenericLogger;
23
+ };
24
+ export type { AppConfigStoreOptions };
25
+ //# sourceMappingURL=AppConfigStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppConfigStore.d.ts","sourceRoot":"","sources":["../../../src/types/AppConfigStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,KAAK,EACV,mBAAmB,EACnB,yBAAyB,EAC1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD;;;GAGG;AACH,KAAK,qBAAqB,GAAG,eAAe,GAAG;IAC7C,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,sEAAsE;IACtE,YAAY,CAAC,EAAE,yBAAyB,CAAC;IACzC,6DAA6D;IAC7D,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,YAAY,EAAE,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import type { GenericLogger } from '@aws-lambda-powertools/commons/types';
2
+ /** Configures Agent retrieval of evaluated AppConfig Variants. */
3
+ type AppConfigVariantStoreOptions = {
4
+ /** Identifies the configuration profile by name or ID. */
5
+ name: string;
6
+ /** Identifies the environment by name or ID. */
7
+ environment: string;
8
+ /** Identifies the application, defaulting to `POWERTOOLS_SERVICE_NAME`. */
9
+ application?: string;
10
+ /** Sets the Agent request timeout in milliseconds. */
11
+ timeout?: number;
12
+ /** Logs selected Variant names without values. */
13
+ logger?: GenericLogger;
14
+ };
15
+ export type { AppConfigVariantStoreOptions };
16
+ //# sourceMappingURL=AppConfigVariantStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppConfigVariantStore.d.ts","sourceRoot":"","sources":["../../../src/types/AppConfigVariantStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAE1E,kEAAkE;AAClE,KAAK,4BAA4B,GAAG;IAClC,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,YAAY,EAAE,4BAA4B,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ /** Searches a configuration for an embedded Flag Document. */
2
+ type EnvelopeSearchFn = (expression: string, data: unknown) => unknown;
3
+ /** Configures document selection with both an expression and a search function. @internal */
4
+ type EnvelopeOptions = {
5
+ /** Selects an embedded Flag Document with the supplied search function. */
6
+ envelope: string;
7
+ /** Applies the envelope expression to the retrieved configuration. */
8
+ envelopeSearchFn: EnvelopeSearchFn;
9
+ } | {
10
+ /** Leaves the retrieved configuration unchanged. */
11
+ envelope?: never;
12
+ /** Omits document selection when no envelope is supplied. */
13
+ envelopeSearchFn?: never;
14
+ };
15
+ export type { EnvelopeOptions, EnvelopeSearchFn };
16
+ //# sourceMappingURL=Envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Envelope.d.ts","sourceRoot":"","sources":["../../../src/types/Envelope.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,KAAK,gBAAgB,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC;AAEvE,6FAA6F;AAC7F,KAAK,eAAe,GAChB;IACE,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,gBAAgB,EAAE,gBAAgB,CAAC;CACpC,GACD;IACE,oDAAoD;IACpD,QAAQ,CAAC,EAAE,KAAK,CAAC;IACjB,6DAA6D;IAC7D,gBAAgB,CAAC,EAAE,KAAK,CAAC;CAC1B,CAAC;AAEN,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,83 @@
1
+ import type { GenericLogger, JSONValue } from '@aws-lambda-powertools/commons/types';
2
+ import type { RuleActions, TimeActionKeys } from '../constants.js';
3
+ import type { EvaluationContext } from './index.js';
4
+ /** Configures retrieval and optional logging for a local rule engine Store. */
5
+ type RuleEngineStoreOptions = {
6
+ /** Names the Store, defaulting to `rule-engine`. */
7
+ name?: string;
8
+ /** Retrieves a Python-format Flag Document for each Store call. */
9
+ source: () => Promise<JSONValue>;
10
+ /** Logs validation warnings and evaluation outcomes without values. */
11
+ logger?: GenericLogger;
12
+ /** Supplies the clock for schedule Actions, ignoring caller context. Defaults to () => new Date(). */
13
+ now?: () => Date;
14
+ };
15
+ /** Identifies a supported Action. @internal */
16
+ type RuleAction = (typeof RuleActions)[keyof typeof RuleActions];
17
+ /** Compares a context operand with a document operand. @internal */
18
+ type Comparator = (context: unknown, value: JSONValue) => boolean;
19
+ /** Carries a validated Action and its operands' key and value. @internal */
20
+ type Condition = {
21
+ action: RuleAction;
22
+ key: string;
23
+ value: JSONValue;
24
+ };
25
+ /** Carries a validated result and its AND-connected Conditions. @internal */
26
+ type Rule = {
27
+ when_match: JSONValue;
28
+ conditions: Condition[];
29
+ };
30
+ /** Carries a validated Flag Default and ordered named Rules. @internal */
31
+ type Flag = {
32
+ default: JSONValue;
33
+ rules: Record<string, Rule>;
34
+ };
35
+ /** Maps flag names to validated flag definitions. @internal */
36
+ type FlagDocument = Record<string, Flag>;
37
+ /** Holds the last validated document and its serialized source content. @internal */
38
+ type RuleEngineSnapshot = {
39
+ key: string;
40
+ document: FlagDocument;
41
+ };
42
+ /** Validates a retrieved document and returns compiled flag definitions. @internal */
43
+ type DocumentValidator = (document: unknown) => FlagDocument;
44
+ /** Identifies an Action that reads the clock instead of caller context. @internal */
45
+ type TimeAction = keyof typeof TimeActionKeys;
46
+ /** Carries validated bounds for a schedule Action. @internal */
47
+ type TimeRange = {
48
+ START: string;
49
+ END: string;
50
+ TIMEZONE?: string;
51
+ };
52
+ /** Carries validated naive ISO bounds for a datetime schedule Action. @internal */
53
+ type DatetimeRange = {
54
+ START: string;
55
+ END: string;
56
+ TIMEZONE?: string;
57
+ };
58
+ /** Carries validated day names for a schedule Action. @internal */
59
+ type DaysOfWeek = {
60
+ DAYS: string[];
61
+ TIMEZONE?: string;
62
+ };
63
+ /** Carries validated integer bounds for a modulo Action. @internal */
64
+ type ModuloRange = {
65
+ BASE: number;
66
+ START: number;
67
+ END: number;
68
+ };
69
+ /** Configures one flag evaluation without changing its identifying arguments. @internal */
70
+ type EvaluateFlagOptions = {
71
+ context: EvaluationContext;
72
+ logger?: GenericLogger;
73
+ now: Date;
74
+ };
75
+ /** Supplies identifiers, caller facts, and the shared clock instant for a Condition. @internal */
76
+ type MatchConditionOptions = {
77
+ name: string;
78
+ rule: string;
79
+ context: EvaluationContext;
80
+ now: Date;
81
+ };
82
+ export type { Comparator, Condition, DatetimeRange, DaysOfWeek, DocumentValidator, EvaluateFlagOptions, Flag, FlagDocument, MatchConditionOptions, ModuloRange, Rule, RuleAction, RuleEngineSnapshot, RuleEngineStoreOptions, TimeAction, TimeRange, };
83
+ //# sourceMappingURL=RuleEngine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RuleEngine.d.ts","sourceRoot":"","sources":["../../../src/types/RuleEngine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACV,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,+EAA+E;AAC/E,KAAK,sBAAsB,GAAG;IAC5B,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,MAAM,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,CAAC;IACjC,uEAAuE;IACvE,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,sGAAsG;IACtG,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB,CAAC;AAEF,+CAA+C;AAC/C,KAAK,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEjE,oEAAoE;AACpE,KAAK,UAAU,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC;AAElE,4EAA4E;AAC5E,KAAK,SAAS,GAAG;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAEvE,6EAA6E;AAC7E,KAAK,IAAI,GAAG;IAAE,UAAU,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,SA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AC;AAEF,kGAAkG;AAClG,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,iBAAiB,CAAC;IAC3B,GAAG,EAAE,IAAI,CAAC;CACX,CAAC;AAEF,YAAY,EACV,UAAU,EACV,SAAS,EACT,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,mBAAmB,EACnB,IAAI,EACJ,YAAY,EACZ,qBAAqB,EACrB,WAAW,EACX,IAAI,EACJ,UAAU,EACV,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACV,SAAS,GACV,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,20 @@
1
+ import type { EvaluationContext, Variant } from './index.js';
2
+ /** Supplies a full Variant fallback without a schema. */
3
+ type EvaluateVariantOptions = {
4
+ name: string;
5
+ context?: EvaluationContext;
6
+ default: Variant;
7
+ schema?: never;
8
+ };
9
+ /** Supplies a full Variant fallback per flag without schemas. */
10
+ type EvaluateManyVariantOptions<Flags> = {
11
+ flags: Flags & Record<string, Variant>;
12
+ context?: EvaluationContext;
13
+ schemas?: never;
14
+ };
15
+ /** Preserves batch keys while returning full Variants rather than fallback literals. */
16
+ type EvaluateManyVariantResult<Flags> = {
17
+ [Name in keyof Flags]: Variant;
18
+ };
19
+ export type { EvaluateManyVariantOptions, EvaluateManyVariantResult, EvaluateVariantOptions, };
20
+ //# sourceMappingURL=VariantEvaluation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VariantEvaluation.d.ts","sourceRoot":"","sources":["../../../src/types/VariantEvaluation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE7D,yDAAyD;AACzD,KAAK,sBAAsB,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB,CAAC;AAEF,iEAAiE;AACjE,KAAK,0BAA0B,CAAC,KAAK,IAAI;IACvC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,OAAO,CAAC,EAAE,KAAK,CAAC;CACjB,CAAC;AAEF,wFAAwF;AACxF,KAAK,yBAAyB,CAAC,KAAK,IAAI;KACrC,IAAI,IAAI,MAAM,KAAK,GAAG,OAAO;CAC/B,CAAC;AAEF,YAAY,EACV,0BAA0B,EAC1B,yBAAyB,EACzB,sBAAsB,GACvB,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,81 @@
1
+ import type { GenericLogger, JSONValue } from '@aws-lambda-powertools/commons/types';
2
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
3
+ /** Configures the Store and optional logger for flag evaluation. */
4
+ type FeatureFlagsOptions<Value = JSONValue> = {
5
+ /** Provides flag lookups. */
6
+ store: Store<Value>;
7
+ /** Logs evaluation outcomes without values. */
8
+ logger?: GenericLogger;
9
+ };
10
+ /**
11
+ * Widens primitive fallbacks and uses JSONValue for structured fallbacks.
12
+ *
13
+ * A structured literal cannot soundly describe a Store result.
14
+ */
15
+ type EvaluateResult<Fallback> = Fallback extends boolean ? boolean : Fallback extends number ? number : Fallback extends string ? string : JSONValue;
16
+ /** Supplies the flag name, context, and required fallback for evaluation. */
17
+ type EvaluateOptions<Fallback extends JSONValue> = {
18
+ name: string;
19
+ context?: EvaluationContext;
20
+ default: Fallback;
21
+ };
22
+ /** Supplies a schema and its input fallback to {@link FeatureFlags.evaluate | `evaluate`}. */
23
+ type EvaluateWithSchemaOptions<Schema extends StandardSchemaV1> = {
24
+ name: string;
25
+ context?: EvaluationContext;
26
+ default: StandardSchemaV1.InferInput<Schema>;
27
+ /** Validates the fallback and result without producing undefined. */
28
+ schema: undefined extends StandardSchemaV1.InferOutput<Schema> ? never : Schema;
29
+ };
30
+ /** Supplies per-flag fallbacks, optional schemas, and context to {@link FeatureFlags.evaluateMany | `evaluateMany`}. */
31
+ type EvaluateManyOptions<Flags extends Record<string, JSONValue>, Schemas extends Partial<Record<string, StandardSchemaV1>> = Partial<Record<string, never>>> = {
32
+ flags: Flags;
33
+ context?: EvaluationContext;
34
+ /** Validates selected flags without producing undefined. */
35
+ schemas?: Schemas & {
36
+ [Name in keyof Schemas]: Name extends keyof Flags ? NonNullable<Schemas[Name]> extends StandardSchemaV1 ? undefined extends StandardSchemaV1.InferOutput<NonNullable<Schemas[Name]>> ? never : Schemas[Name] : Schemas[Name] : never;
37
+ };
38
+ };
39
+ /**
40
+ * Infers a schema output or widens the fallback when no schema exists.
41
+ * @internal
42
+ */
43
+ type EvaluateSchemaResult<Schema, Fallback> = Schema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Schema> : EvaluateResult<Fallback>;
44
+ /** Infers schema outputs and widens other fallbacks through {@link EvaluateResult | `EvaluateResult`}. */
45
+ type EvaluateManyResult<Flags extends Record<string, JSONValue>, Schemas extends Partial<Record<string, StandardSchemaV1>> = Partial<Record<string, never>>> = {
46
+ [Name in keyof Flags]: Name extends keyof Schemas ? EvaluateSchemaResult<Schemas[Name], Flags[Name]> : EvaluateResult<Flags[Name]>;
47
+ };
48
+ /** Supplies context to {@link FeatureFlags.getEnabledFeatures | `getEnabledFeatures`}. */
49
+ type GetEnabledFeaturesOptions = {
50
+ context?: EvaluationContext;
51
+ };
52
+ /** Represents a scalar fact in an evaluation context. */
53
+ type ContextScalar = string | number | boolean;
54
+ /** Represents a scalar fact or a list of scalar facts. */
55
+ type ContextValue = ContextScalar | ContextScalar[];
56
+ /** Carries caller-supplied per-request facts for flag evaluation. */
57
+ type EvaluationContext = Record<string, ContextValue>;
58
+ /** Distinguishes a found flag and its value from a missing flag. */
59
+ type StoreResult<Value = JSONValue> = {
60
+ found: true;
61
+ value: Value;
62
+ enabled: boolean;
63
+ } | {
64
+ found: false;
65
+ };
66
+ /** Answers the value of a flag for a given evaluation context. */
67
+ type Store<Value = JSONValue> = {
68
+ name: string;
69
+ getMany(names: readonly string[], context: EvaluationContext): Promise<Record<string, StoreResult<Value>>>;
70
+ getAll(context: EvaluationContext): Promise<Record<string, StoreResult<Value>>>;
71
+ };
72
+ /** Represents a normalized AWS AppConfig multi-variant result. */
73
+ type Variant = {
74
+ enabled: boolean;
75
+ variant: string;
76
+ attributes: Record<string, ContextValue>;
77
+ };
78
+ export type { ContextScalar, ContextValue, EvaluateManyOptions, EvaluateManyResult, EvaluateOptions, EvaluateResult, EvaluateSchemaResult, EvaluateWithSchemaOptions, EvaluationContext, FeatureFlagsOptions, GetEnabledFeaturesOptions, Store, StoreResult, Variant, };
79
+ export type { EnvelopeOptions, EnvelopeSearchFn } from './Envelope.js';
80
+ export type { EvaluateManyVariantOptions, EvaluateManyVariantResult, EvaluateVariantOptions, } from './VariantEvaluation.js';
81
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACV,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,oEAAoE;AACpE,KAAK,mBAAmB,CAAC,KAAK,GAAG,SAAS,IAAI;IAC5C,6BAA6B;IAC7B,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACpB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF;;;;GAIG;AACH,KAAK,cAAc,CAAC,QAAQ,IAAI,QAAQ,SAAS,OAAO,GACpD,OAAO,GACP,QAAQ,SAAS,MAAM,GACrB,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AAO,CACL,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC/C,MAAM,CACJ,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;CAChD,CAAC;AAEF,kEAAkE;AAClE,KAAK,OAAO,GAAG;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAC1C,CAAC;AAEF,YAAY,EACV,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,yBAAyB,EACzB,iBAAiB,EACjB,mBAAmB,EACnB,yBAAyB,EACzB,KAAK,EACL,WAAW,EACX,OAAO,GACR,CAAC;AACF,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACvE,YAAY,EACV,0BAA0B,EAC1B,yBAAyB,EACzB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import type { Variant } from './types/index.js';
2
+ /** Registers a Variant store for runtime fallback validation. @internal */
3
+ declare const registerVariantStore: (store: object) => void;
4
+ /** Checks whether a store requires Variant fallbacks. @internal */
5
+ declare const isVariantStore: (store: object) => boolean;
6
+ /** Checks the exact normalized Variant shape and every attribute. @internal */
7
+ declare const isVariant: (value: unknown) => value is Variant;
8
+ export { isVariant, isVariantStore, registerVariantStore };
9
+ //# sourceMappingURL=variant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variant.d.ts","sourceRoot":"","sources":["../../src/variant.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAKhD,2EAA2E;AAC3E,QAAA,MAAM,oBAAoB,GAAI,OAAO,MAAM,KAAG,IAE7C,CAAC;AAEF,mEAAmE;AACnE,QAAA,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,OAAmC,CAAC;AAE5E,+EAA+E;AAC/E,QAAA,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,OASgB,CAAC;AAE9D,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerVariantStore = exports.isVariantStore = exports.isVariant = void 0;
4
+ const commons_1 = require("@aws-lambda-powertools/commons");
5
+ const context_js_1 = require("./context.js");
6
+ /** Tracks built-in Variant stores without importing their transport. @internal */
7
+ const variantStores = new WeakSet();
8
+ /** Registers a Variant store for runtime fallback validation. @internal */
9
+ const registerVariantStore = (store) => {
10
+ variantStores.add(store);
11
+ };
12
+ exports.registerVariantStore = registerVariantStore;
13
+ /** Checks whether a store requires Variant fallbacks. @internal */
14
+ const isVariantStore = (store) => variantStores.has(store);
15
+ exports.isVariantStore = isVariantStore;
16
+ /** Checks the exact normalized Variant shape and every attribute. @internal */
17
+ const isVariant = (value) => (0, commons_1.isRecord)(value) &&
18
+ Reflect.ownKeys(value).length === 3 &&
19
+ Object.hasOwn(value, 'enabled') &&
20
+ typeof value.enabled === 'boolean' &&
21
+ Object.hasOwn(value, 'variant') &&
22
+ typeof value.variant === 'string' &&
23
+ Object.hasOwn(value, 'attributes') &&
24
+ (0, commons_1.isRecord)(value.attributes) &&
25
+ Object.values(value.attributes).every(context_js_1.isFiniteContextValue);
26
+ exports.isVariant = isVariant;