@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,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StoreUnavailableError = exports.SchemaValidationError = exports.InvalidContextError = exports.FlagValueTypeError = exports.FlagResultValidationError = exports.FeatureFlagsError = exports.ConditionEvaluationError = void 0;
4
+ /** Provides the base error for the feature flags utility. */
5
+ class FeatureFlagsError extends Error {
6
+ constructor(message, options) {
7
+ super(message, options);
8
+ this.name = 'FeatureFlagsError';
9
+ }
10
+ }
11
+ exports.FeatureFlagsError = FeatureFlagsError;
12
+ /**
13
+ * Reports a known availability failure from a Store.
14
+ *
15
+ * Stores throw this error for timeouts, connection failures, throttling, or
16
+ * service unavailability. The evaluator catches this category and returns
17
+ * fallbacks.
18
+ */
19
+ class StoreUnavailableError extends FeatureFlagsError {
20
+ constructor(message, options) {
21
+ super(message, options);
22
+ this.name = 'StoreUnavailableError';
23
+ }
24
+ }
25
+ exports.StoreUnavailableError = StoreUnavailableError;
26
+ /** Reports an invalid evaluation context without exposing its values. */
27
+ class InvalidContextError extends FeatureFlagsError {
28
+ /**
29
+ * Creates an invalid context error.
30
+ * @param message - Describe the invalid context key
31
+ * @param options - Supply optional error details
32
+ */
33
+ constructor(message, options) {
34
+ super(message, options);
35
+ this.name = 'InvalidContextError';
36
+ }
37
+ }
38
+ exports.InvalidContextError = InvalidContextError;
39
+ /** Reports a flag value whose type differs from its primitive fallback. */
40
+ class FlagValueTypeError extends FeatureFlagsError {
41
+ /**
42
+ * Creates a flag value type error.
43
+ * @param message - Describe the flag and mismatched types
44
+ * @param options - Supply optional error details
45
+ */
46
+ constructor(message, options) {
47
+ super(message, options);
48
+ this.name = 'FlagValueTypeError';
49
+ }
50
+ }
51
+ exports.FlagValueTypeError = FlagValueTypeError;
52
+ /** Reports an invalid Flag Document without exposing its values. */
53
+ class SchemaValidationError extends FeatureFlagsError {
54
+ /**
55
+ * Creates a schema validation error.
56
+ * @param message - Describe the invalid flag, Rule, or Condition
57
+ * @param options - Supply optional error details
58
+ */
59
+ constructor(message, options) {
60
+ super(message, options);
61
+ this.name = 'SchemaValidationError';
62
+ }
63
+ }
64
+ exports.SchemaValidationError = SchemaValidationError;
65
+ /** Reports incompatible Condition operands without exposing their values. */
66
+ class ConditionEvaluationError extends FeatureFlagsError {
67
+ /**
68
+ * Creates a condition evaluation error.
69
+ * @param message - Identify the flag, Rule, key, and Action
70
+ * @param options - Supply optional error details
71
+ */
72
+ constructor(message, options) {
73
+ super(message, options);
74
+ this.name = 'ConditionEvaluationError';
75
+ }
76
+ }
77
+ exports.ConditionEvaluationError = ConditionEvaluationError;
78
+ /**
79
+ * Reports schema validation failures without exposing values or validator messages.
80
+ *
81
+ * Preserves the validator's issues array or the value thrown by the schema as cause.
82
+ * Messages list issue paths or report that the schema threw. Uses an empty issues
83
+ * array as cause and a single synthetic (root) path when a schema returns undefined
84
+ * without issues.
85
+ */
86
+ class FlagResultValidationError extends FeatureFlagsError {
87
+ flag;
88
+ source;
89
+ /**
90
+ * Creates a validation error and preserves the issues or thrown value as its cause.
91
+ * @param flag - Identify the flag
92
+ * @param source - Identify the fallback or Store result
93
+ * @param issues - Supply the validator's issue paths and cause
94
+ * @param {Object} options - Report a failure thrown by the schema instead of issues
95
+ * @param {unknown} options.cause - Preserve the original value thrown by the schema
96
+ */
97
+ constructor(flag, source, issues, options) {
98
+ const paths = [];
99
+ for (const issue of issues) {
100
+ const segments = [];
101
+ for (const segment of issue.path ?? []) {
102
+ segments.push(String(typeof segment === 'object' ? segment.key : segment));
103
+ }
104
+ paths.push(segments.length > 0 ? segments.join('.') : '(root)');
105
+ }
106
+ super(options
107
+ ? `Flag '${flag}' ${source} failed schema validation: the schema threw`
108
+ : `Flag '${flag}' ${source} failed schema validation at ${paths.length > 0 ? paths.join(', ') : '(root)'}`, options ?? {
109
+ cause: issues,
110
+ });
111
+ this.name = 'FlagResultValidationError';
112
+ this.flag = flag;
113
+ this.source = source;
114
+ }
115
+ }
116
+ exports.FlagResultValidationError = FlagResultValidationError;
@@ -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"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ruleEngineStore = exports.FeatureFlags = exports.StoreUnavailableError = exports.SchemaValidationError = exports.InvalidContextError = exports.FlagValueTypeError = exports.FlagResultValidationError = exports.FeatureFlagsError = exports.ConditionEvaluationError = void 0;
4
+ var errors_js_1 = require("./errors.js");
5
+ Object.defineProperty(exports, "ConditionEvaluationError", { enumerable: true, get: function () { return errors_js_1.ConditionEvaluationError; } });
6
+ Object.defineProperty(exports, "FeatureFlagsError", { enumerable: true, get: function () { return errors_js_1.FeatureFlagsError; } });
7
+ Object.defineProperty(exports, "FlagResultValidationError", { enumerable: true, get: function () { return errors_js_1.FlagResultValidationError; } });
8
+ Object.defineProperty(exports, "FlagValueTypeError", { enumerable: true, get: function () { return errors_js_1.FlagValueTypeError; } });
9
+ Object.defineProperty(exports, "InvalidContextError", { enumerable: true, get: function () { return errors_js_1.InvalidContextError; } });
10
+ Object.defineProperty(exports, "SchemaValidationError", { enumerable: true, get: function () { return errors_js_1.SchemaValidationError; } });
11
+ Object.defineProperty(exports, "StoreUnavailableError", { enumerable: true, get: function () { return errors_js_1.StoreUnavailableError; } });
12
+ var FeatureFlags_js_1 = require("./FeatureFlags.js");
13
+ Object.defineProperty(exports, "FeatureFlags", { enumerable: true, get: function () { return FeatureFlags_js_1.FeatureFlags; } });
14
+ var index_js_1 = require("./ruleEngine/index.js");
15
+ Object.defineProperty(exports, "ruleEngineStore", { enumerable: true, get: function () { return index_js_1.ruleEngineStore; } });
@@ -0,0 +1 @@
1
+ { "type": "commonjs" }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Classifies Parameters retrieval failures using structured fields only.
3
+ *
4
+ * Agent HTTP 5xx and 429 responses identify an unavailable store; other statuses
5
+ * identify configuration failures. Missing parameters always propagate, even
6
+ * when their cause resembles an outage. Transform errors and unrelated errors
7
+ * also propagate because they are not retrieval errors.
8
+ *
9
+ * For a plain GetParameterError, a TypeError cause identifies a failed fetch.
10
+ * Timeout, abort, throttling, internal server, and service unavailable names,
11
+ * Node network codes, and SDK HTTP 5xx or 429 metadata identify an outage.
12
+ * All other causes, including access denial, missing resources, bad requests,
13
+ * other HTTP statuses, and absent causes, propagate unchanged.
14
+ *
15
+ * @param error - Supply the Parameters error to classify
16
+ * @internal
17
+ */
18
+ declare const isAvailabilityFailure: (error: unknown) => boolean;
19
+ export { isAvailabilityFailure };
20
+ //# sourceMappingURL=classify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../../../src/parameters-stores/classify.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;GAgBG;AACH,QAAA,MAAM,qBAAqB,GAAI,OAAO,OAAO,KAAG,OA4B/C,CAAC;AAEF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAvailabilityFailure = void 0;
4
+ const commons_1 = require("@aws-lambda-powertools/commons");
5
+ const errors_1 = require("@aws-lambda-powertools/parameters/errors");
6
+ const constants_js_1 = require("../constants.js");
7
+ /**
8
+ * Classifies Parameters retrieval failures using structured fields only.
9
+ *
10
+ * Agent HTTP 5xx and 429 responses identify an unavailable store; other statuses
11
+ * identify configuration failures. Missing parameters always propagate, even
12
+ * when their cause resembles an outage. Transform errors and unrelated errors
13
+ * also propagate because they are not retrieval errors.
14
+ *
15
+ * For a plain GetParameterError, a TypeError cause identifies a failed fetch.
16
+ * Timeout, abort, throttling, internal server, and service unavailable names,
17
+ * Node network codes, and SDK HTTP 5xx or 429 metadata identify an outage.
18
+ * All other causes, including access denial, missing resources, bad requests,
19
+ * other HTTP statuses, and absent causes, propagate unchanged.
20
+ *
21
+ * @param error - Supply the Parameters error to classify
22
+ * @internal
23
+ */
24
+ const isAvailabilityFailure = (error) => {
25
+ if (error instanceof errors_1.AppConfigAgentError) {
26
+ return error.statusCode >= 500 || error.statusCode === 429;
27
+ }
28
+ if (!(error instanceof errors_1.GetParameterError) ||
29
+ error instanceof errors_1.ParameterNotFoundError) {
30
+ return false;
31
+ }
32
+ const cause = error.cause;
33
+ if (cause instanceof TypeError)
34
+ return true;
35
+ // isRecord excludes native Errors, so accept those through their own type guard.
36
+ if (!(cause instanceof Error) && !(0, commons_1.isRecord)(cause))
37
+ return false;
38
+ if (constants_js_1.AvailabilityErrorNames.some((name) => cause.name === name))
39
+ return true;
40
+ if ('code' in cause &&
41
+ constants_js_1.AvailabilityErrorCodes.some((code) => cause.code === code))
42
+ return true;
43
+ if ('$metadata' in cause && (0, commons_1.isRecord)(cause.$metadata)) {
44
+ const statusCode = cause.$metadata.httpStatusCode;
45
+ return (typeof statusCode === 'number' &&
46
+ (statusCode >= 500 || statusCode === 429));
47
+ }
48
+ return false;
49
+ };
50
+ exports.isAvailabilityFailure = isAvailabilityFailure;
@@ -0,0 +1,17 @@
1
+ import type { JSONValue } from '@aws-lambda-powertools/commons/types';
2
+ import type { EnvelopeOptions } from '../types/Envelope.js';
3
+ /**
4
+ * Creates a Flag Document source with shared availability and envelope handling.
5
+ * @param {Object} options - Configure retrieval and document selection
6
+ * @param {string} options.storeName - Name the Store in availability errors
7
+ * @param {Function} options.retrieve - Retrieve JSON with missing configurations rejected
8
+ * @param {string} options.envelope - Select an embedded Flag Document
9
+ * @param {Function} options.envelopeSearchFn - Apply the envelope expression
10
+ * @internal
11
+ */
12
+ declare const createDocumentSource: ({ storeName, retrieve, ...envelopeOptions }: {
13
+ storeName: string;
14
+ retrieve: () => Promise<JSONValue>;
15
+ } & EnvelopeOptions) => (() => Promise<JSONValue>);
16
+ export { createDocumentSource };
17
+ //# sourceMappingURL=createDocumentSource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDocumentSource.d.ts","sourceRoot":"","sources":["../../../src/parameters-stores/createDocumentSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAEtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAI5D;;;;;;;;GAQG;AACH,QAAA,MAAM,oBAAoB,GACvB,6CAIE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,CAAC;CACpC,GAAG,eAAe,KAAG,CAAC,MAAM,OAAO,CAAC,SAAS,CAAC,CAc9C,CAAC;AAEJ,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDocumentSource = void 0;
4
+ const errors_js_1 = require("../errors.js");
5
+ const classify_js_1 = require("./classify.js");
6
+ const envelope_js_1 = require("./envelope.js");
7
+ /**
8
+ * Creates a Flag Document source with shared availability and envelope handling.
9
+ * @param {Object} options - Configure retrieval and document selection
10
+ * @param {string} options.storeName - Name the Store in availability errors
11
+ * @param {Function} options.retrieve - Retrieve JSON with missing configurations rejected
12
+ * @param {string} options.envelope - Select an embedded Flag Document
13
+ * @param {Function} options.envelopeSearchFn - Apply the envelope expression
14
+ * @internal
15
+ */
16
+ const createDocumentSource = ({ storeName, retrieve, ...envelopeOptions }) => async () => {
17
+ let document;
18
+ try {
19
+ document = await retrieve();
20
+ }
21
+ catch (error) {
22
+ if ((0, classify_js_1.isAvailabilityFailure)(error)) {
23
+ throw new errors_js_1.StoreUnavailableError(`${storeName} is unavailable`, {
24
+ cause: error,
25
+ });
26
+ }
27
+ throw error;
28
+ }
29
+ return (0, envelope_js_1.applyEnvelope)(document, envelopeOptions);
30
+ };
31
+ exports.createDocumentSource = createDocumentSource;
@@ -0,0 +1,22 @@
1
+ import type { JSONValue } from '@aws-lambda-powertools/commons/types';
2
+ import type { EnvelopeOptions, EnvelopeSearchFn } from '../types/Envelope.js';
3
+ /**
4
+ * Rejects incomplete envelope options before a Store constructs its transport.
5
+ * @param {Object} options - Supply the document selection options
6
+ * @param {string} options.envelope - Select an embedded Flag Document
7
+ * @param {Function} options.envelopeSearchFn - Apply the envelope expression
8
+ * @internal
9
+ */
10
+ declare const validateEnvelopeOptions: (options: {
11
+ envelope?: string;
12
+ envelopeSearchFn?: EnvelopeSearchFn;
13
+ }) => EnvelopeOptions;
14
+ /**
15
+ * Selects a Flag Document without falling back after an envelope miss.
16
+ * @param document - Supply the JSON configuration
17
+ * @param options - Select the Flag Document with an expression and search function
18
+ * @internal
19
+ */
20
+ declare const applyEnvelope: (document: JSONValue, options: EnvelopeOptions) => JSONValue;
21
+ export { applyEnvelope, validateEnvelopeOptions };
22
+ //# sourceMappingURL=envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../../src/parameters-stores/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAEtE,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE9E;;;;;;GAMG;AACH,QAAA,MAAM,uBAAuB,GAAI,SAAS;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC,KAAG,eASH,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,aAAa,GACjB,UAAU,SAAS,EACnB,SAAS,eAAe,KACvB,SAWF,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,CAAC"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateEnvelopeOptions = exports.applyEnvelope = void 0;
4
+ const errors_js_1 = require("../errors.js");
5
+ /**
6
+ * Rejects incomplete envelope options before a Store constructs its transport.
7
+ * @param {Object} options - Supply the document selection options
8
+ * @param {string} options.envelope - Select an embedded Flag Document
9
+ * @param {Function} options.envelopeSearchFn - Apply the envelope expression
10
+ * @internal
11
+ */
12
+ const validateEnvelopeOptions = (options) => {
13
+ const { envelope, envelopeSearchFn } = options;
14
+ if (envelope === undefined && envelopeSearchFn === undefined)
15
+ return {};
16
+ if (envelope === undefined || envelopeSearchFn === undefined) {
17
+ throw new errors_js_1.FeatureFlagsError("Options 'envelope' and 'envelopeSearchFn' must be provided together");
18
+ }
19
+ return { envelope, envelopeSearchFn };
20
+ };
21
+ exports.validateEnvelopeOptions = validateEnvelopeOptions;
22
+ /**
23
+ * Selects a Flag Document without falling back after an envelope miss.
24
+ * @param document - Supply the JSON configuration
25
+ * @param options - Select the Flag Document with an expression and search function
26
+ * @internal
27
+ */
28
+ const applyEnvelope = (document, options) => {
29
+ const { envelope, envelopeSearchFn } = options;
30
+ if (envelope === undefined)
31
+ return document;
32
+ const result = envelopeSearchFn(envelope, document);
33
+ if (result === undefined || result === null) {
34
+ throw new errors_js_1.SchemaValidationError(`Envelope '${envelope}' did not select a Flag Document`);
35
+ }
36
+ // Search functions return unknown; the rule engine validates the selected document at the JSON boundary.
37
+ return result;
38
+ };
39
+ exports.applyEnvelope = applyEnvelope;
@@ -0,0 +1,5 @@
1
+ import type { Comparator, RuleAction, TimeAction } from '../types/RuleEngine.js';
2
+ /** Dispatches each supported Action to its strict comparator. @internal */
3
+ declare const actions: Record<Exclude<RuleAction, TimeAction>, Comparator>;
4
+ export { actions };
5
+ //# sourceMappingURL=actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/ruleEngine/actions.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACX,MAAM,wBAAwB,CAAC;AAkJhC,2EAA2E;AAC3E,QAAA,MAAM,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE,UAAU,CAqChE,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.actions = void 0;
4
+ const commons_1 = require("@aws-lambda-powertools/commons");
5
+ const constants_js_1 = require("../constants.js");
6
+ const guards_js_1 = require("./guards.js");
7
+ /**
8
+ * Compares numbers directly and strings by Unicode code point without coercion.
9
+ * @param context - Supply the context operand
10
+ * @param value - Supply the document operand
11
+ * @param comparator - Compare numeric operands or a string order against zero
12
+ * @internal
13
+ */
14
+ const compareOrdered = (context, value, comparator) => {
15
+ if ((0, commons_1.isNumber)(context) && (0, commons_1.isNumber)(value)) {
16
+ return comparator(context, value);
17
+ }
18
+ if ((0, commons_1.isString)(context) && (0, commons_1.isString)(value)) {
19
+ return comparator((0, commons_1.compareStringsByCodePoint)(context, value), 0);
20
+ }
21
+ throw new TypeError('Incompatible operands');
22
+ };
23
+ /**
24
+ * Compares two strings without coercion.
25
+ * @param context - Supply the context operand
26
+ * @param value - Supply the document operand
27
+ * @param comparator - Apply the string comparison
28
+ * @internal
29
+ */
30
+ const compareStrings = (context, value, comparator) => {
31
+ if ((0, commons_1.isString)(context) && (0, commons_1.isString)(value))
32
+ return comparator(context, value);
33
+ throw new TypeError('Incompatible operands');
34
+ };
35
+ /**
36
+ * Checks whether a string starts with a prefix by Unicode code point.
37
+ * @param container - Supply the string to check
38
+ * @param prefix - Supply the prefix to match
39
+ * @internal
40
+ */
41
+ const startsWithByCodePoint = (container, prefix) => {
42
+ if (prefix === '')
43
+ return true;
44
+ // Compare code points so a lone surrogate cannot match half of a surrogate pair.
45
+ const containerCodePoints = Array.from(container);
46
+ const prefixCodePoints = Array.from(prefix);
47
+ return prefixCodePoints.every((codePoint, index) => codePoint === containerCodePoints[index]);
48
+ };
49
+ /**
50
+ * Checks whether a string ends with a suffix by Unicode code point.
51
+ * @param container - Supply the string to check
52
+ * @param suffix - Supply the suffix to match
53
+ * @internal
54
+ */
55
+ const endsWithByCodePoint = (container, suffix) => {
56
+ if (suffix === '')
57
+ return true;
58
+ // Compare code points so a lone surrogate cannot match half of a surrogate pair.
59
+ const containerCodePoints = Array.from(container);
60
+ const suffixCodePoints = Array.from(suffix);
61
+ const start = containerCodePoints.length - suffixCodePoints.length;
62
+ return suffixCodePoints.every((codePoint, index) => codePoint === containerCodePoints[start + index]);
63
+ };
64
+ /**
65
+ * Checks whether an array contains a value using strict JSON equality.
66
+ * @param container - Supply the array to search
67
+ * @param needle - Supply the value to find
68
+ * @internal
69
+ */
70
+ const containsArray = (container, needle) => container.some((entry) => (0, commons_1.isStrictEqual)(entry, needle));
71
+ /**
72
+ * Checks whether a string contains a substring by Unicode code point.
73
+ * @param container - Supply the string to search
74
+ * @param needle - Supply the substring to find
75
+ * @internal
76
+ */
77
+ const containsSubstring = (container, needle) => {
78
+ if (needle === '')
79
+ return true;
80
+ // Iterate code points so a lone surrogate cannot match half of a surrogate pair.
81
+ const containerCodePoints = Array.from(container);
82
+ const needleCodePoints = Array.from(needle);
83
+ for (const [index] of containerCodePoints.entries()) {
84
+ if (needleCodePoints.every((codePoint, offset) => codePoint === containerCodePoints[index + offset])) {
85
+ return true;
86
+ }
87
+ }
88
+ return false;
89
+ };
90
+ /**
91
+ * Checks Python-style membership in arrays, own object keys, or strings.
92
+ * @param container - Supply the array, object, or string to search
93
+ * @param needle - Supply the value, key, or substring to find
94
+ * @internal
95
+ */
96
+ const contains = (container, needle) => {
97
+ if (Array.isArray(container))
98
+ return containsArray(container, needle);
99
+ if ((0, commons_1.isRecord)(container)) {
100
+ if ((0, commons_1.isString)(needle))
101
+ return Object.hasOwn(container, needle);
102
+ if ((0, commons_1.isNumber)(needle) || typeof needle === 'boolean' || (0, commons_1.isNull)(needle))
103
+ return false;
104
+ throw new TypeError('Incompatible operands');
105
+ }
106
+ if ((0, commons_1.isString)(container)) {
107
+ if (!(0, commons_1.isString)(needle))
108
+ throw new TypeError('Incompatible operands');
109
+ return containsSubstring(container, needle);
110
+ }
111
+ throw new TypeError('Incompatible operands');
112
+ };
113
+ /**
114
+ * Compares two arrays using a supplied membership quantifier.
115
+ * @param context - Supply the context array
116
+ * @param value - Supply the document array
117
+ * @param comparator - Apply the membership quantifier
118
+ * @internal
119
+ */
120
+ const compareArrays = (context, value, comparator) => {
121
+ if (!Array.isArray(context) || !Array.isArray(value))
122
+ throw new TypeError('Incompatible operands');
123
+ return comparator((entry) => containsArray(value, entry), context);
124
+ };
125
+ /** Dispatches each supported Action to its strict comparator. @internal */
126
+ const actions = {
127
+ [constants_js_1.RuleActions.EQUALS]: commons_1.isStrictEqual,
128
+ [constants_js_1.RuleActions.NOT_EQUALS]: (context, value) => !(0, commons_1.isStrictEqual)(context, value),
129
+ [constants_js_1.RuleActions.KEY_GREATER_THAN_VALUE]: (context, value) => compareOrdered(context, value, (left, right) => left > right),
130
+ [constants_js_1.RuleActions.KEY_GREATER_THAN_OR_EQUAL_VALUE]: (context, value) => compareOrdered(context, value, (left, right) => left >= right),
131
+ [constants_js_1.RuleActions.KEY_LESS_THAN_VALUE]: (context, value) => compareOrdered(context, value, (left, right) => left < right),
132
+ [constants_js_1.RuleActions.KEY_LESS_THAN_OR_EQUAL_VALUE]: (context, value) => compareOrdered(context, value, (left, right) => left <= right),
133
+ [constants_js_1.RuleActions.STARTSWITH]: (context, value) => compareStrings(context, value, startsWithByCodePoint),
134
+ [constants_js_1.RuleActions.ENDSWITH]: (context, value) => compareStrings(context, value, endsWithByCodePoint),
135
+ [constants_js_1.RuleActions.IN]: (context, value) => contains(value, context),
136
+ [constants_js_1.RuleActions.NOT_IN]: (context, value) => !contains(value, context),
137
+ [constants_js_1.RuleActions.KEY_IN_VALUE]: (context, value) => contains(value, context),
138
+ [constants_js_1.RuleActions.KEY_NOT_IN_VALUE]: (context, value) => !contains(value, context),
139
+ [constants_js_1.RuleActions.VALUE_IN_KEY]: (context, value) => contains(context, value),
140
+ [constants_js_1.RuleActions.VALUE_NOT_IN_KEY]: (context, value) => !contains(context, value),
141
+ [constants_js_1.RuleActions.ALL_IN_VALUE]: (context, value) => compareArrays(context, value, (matches, entries) => entries.every(matches)),
142
+ [constants_js_1.RuleActions.ANY_IN_VALUE]: (context, value) => compareArrays(context, value, (matches, entries) => entries.some(matches)),
143
+ [constants_js_1.RuleActions.NONE_IN_VALUE]: (context, value) => compareArrays(context, value, (matches, entries) => !entries.some(matches)),
144
+ [constants_js_1.RuleActions.MODULO_RANGE]: (context, value) => {
145
+ if (!(0, commons_1.isNumber)(context) || !(0, guards_js_1.isModuloRange)(value))
146
+ throw new TypeError('Incompatible operands');
147
+ const { BASE: base, START: start, END: end } = value;
148
+ const remainder = context % base;
149
+ // Python gives negative remainders the divisor's sign. Avoid adding the base
150
+ // to positive remainders, which can lose precision for fractional contexts.
151
+ const modulo = remainder < 0 ? remainder + base : remainder;
152
+ return start <= modulo && modulo <= end;
153
+ },
154
+ };
155
+ exports.actions = actions;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Parses timezone-naive datetime.fromisoformat formats into sortable wall-clock fields.
3
+ * Accepts calendar and ISO week dates, basic and extended times, date-only bounds,
4
+ * one-character separators, and dot/comma fractions. Like Python, fractions denote
5
+ * seconds even after hours or minutes and truncate to six digits. Never parses a
6
+ * bound through the host timezone or resolves a DST gap/overlap to an instant.
7
+ * @param value - Supply the document bound
8
+ * @internal
9
+ */
10
+ declare const parseNaiveDatetime: (value: unknown) => string | null;
11
+ export { parseNaiveDatetime };
12
+ //# sourceMappingURL=datetime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datetime.d.ts","sourceRoot":"","sources":["../../../src/ruleEngine/datetime.ts"],"names":[],"mappings":"AAyEA;;;;;;;;GAQG;AACH,QAAA,MAAM,kBAAkB,GAAI,OAAO,OAAO,KAAG,MAAM,GAAG,IA8CrD,CAAC;AAEF,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseNaiveDatetime = void 0;
4
+ /**
5
+ * Checks Gregorian calendar fields without depending on the host timezone.
6
+ * @param year - Supply the year
7
+ * @param month - Supply the month
8
+ * @param day - Supply the day
9
+ * @internal
10
+ */
11
+ const isCalendarDate = (year, month, day) => {
12
+ const leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
13
+ const monthLengths = [
14
+ 31,
15
+ leapYear ? 29 : 28,
16
+ 31,
17
+ 30,
18
+ 31,
19
+ 30,
20
+ 31,
21
+ 31,
22
+ 30,
23
+ 31,
24
+ 30,
25
+ 31,
26
+ ];
27
+ return (year >= 1 &&
28
+ year <= 9999 &&
29
+ month >= 1 &&
30
+ month <= 12 &&
31
+ day >= 1 &&
32
+ day <= monthLengths[month - 1]);
33
+ };
34
+ /**
35
+ * Converts a Python-compatible ISO week date to a calendar date using UTC only.
36
+ * @param year - Supply the ISO week year
37
+ * @param week - Supply the ISO week number
38
+ * @param day - Supply the ISO weekday, Monday being one
39
+ * @internal
40
+ */
41
+ const weekDate = (year, week, day) => {
42
+ const date = new Date(0);
43
+ date.setUTCFullYear(year, 0, 1);
44
+ const januaryFirst = date.getUTCDay();
45
+ const leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
46
+ const weeks = januaryFirst === 4 || (januaryFirst === 3 && leapYear) ? 53 : 52;
47
+ if (year < 1 || week < 1 || week > weeks)
48
+ return null;
49
+ date.setUTCDate(4);
50
+ const mondayOffset = (date.getUTCDay() + 6) % 7;
51
+ date.setUTCDate(4 - mondayOffset + (week - 1) * 7 + day - 1);
52
+ if (date.getUTCFullYear() > 9999)
53
+ return null;
54
+ return date.toISOString().slice(0, 10);
55
+ };
56
+ /**
57
+ * Finds Python's date/time separator, including ambiguous basic ISO week dates.
58
+ * @param value - Supply the datetime string
59
+ * @internal
60
+ */
61
+ const datePrefixLength = (value) => {
62
+ if (value[4] === '-') {
63
+ if (value[5] !== 'W')
64
+ return 10;
65
+ // Python prefers '-' as a separator in YYYY-Www-## over a numeric separator.
66
+ return value[8] === '-' && !/^\d$/.test(value[10] ?? '') ? 10 : 8;
67
+ }
68
+ if (value[4] !== 'W')
69
+ return 8;
70
+ let index = 7;
71
+ while (/^\d$/.test(value[index] ?? ''))
72
+ index++;
73
+ if (index < 9)
74
+ return index;
75
+ return index % 2 === 0 ? 7 : 8;
76
+ };
77
+ /**
78
+ * Parses timezone-naive datetime.fromisoformat formats into sortable wall-clock fields.
79
+ * Accepts calendar and ISO week dates, basic and extended times, date-only bounds,
80
+ * one-character separators, and dot/comma fractions. Like Python, fractions denote
81
+ * seconds even after hours or minutes and truncate to six digits. Never parses a
82
+ * bound through the host timezone or resolves a DST gap/overlap to an instant.
83
+ * @param value - Supply the document bound
84
+ * @internal
85
+ */
86
+ const parseNaiveDatetime = (value) => {
87
+ if (typeof value !== 'string')
88
+ return null;
89
+ const dateLength = datePrefixLength(value);
90
+ const datePrefix = value.slice(0, dateLength);
91
+ const calendar = /^(\d{4})(-?)(\d{2})\2(\d{2})$/.exec(datePrefix);
92
+ const week = /^(\d{4})(-?)W(\d{2})(?:\2([1-7]))?$/.exec(datePrefix);
93
+ let date;
94
+ if (calendar) {
95
+ const year = Number(calendar[1]);
96
+ const month = Number(calendar[3]);
97
+ const day = Number(calendar[4]);
98
+ if (!isCalendarDate(year, month, day))
99
+ return null;
100
+ date = `${calendar[1]}-${calendar[3]}-${calendar[4]}`;
101
+ }
102
+ else if (week) {
103
+ const parsed = weekDate(Number(week[1]), Number(week[3]), Number(week[4] ?? 1));
104
+ if (parsed === null)
105
+ return null;
106
+ date = parsed;
107
+ }
108
+ else {
109
+ return null;
110
+ }
111
+ if (value.length === dateLength)
112
+ return `${date}T00:00:00.000000`;
113
+ // Python permits any single Unicode character between date and time.
114
+ // A parsed date prefix with remaining input guarantees a separator code point.
115
+ const separator = String.fromCodePoint(value.codePointAt(dateLength));
116
+ // Python's validator replaces Z with +00:00 before parsing, so Z is never a naive separator.
117
+ if (separator === 'Z')
118
+ return null;
119
+ const time = value.slice(dateLength + separator.length);
120
+ // Python also accepts a basic HHMMSS time followed by two or more fraction digits.
121
+ const match = /^(\d{2})(?:(:?)(\d{2})(?:\2(\d{2}))?)?(?:[.,](\d+))?$/.exec(time) ??
122
+ /^(\d{2})()(\d{2})(\d{2})(\d{2,})$/.exec(time);
123
+ // JavaScript's $ also matches before a trailing newline; Python consumes all input.
124
+ if (!match || match[0] !== time)
125
+ return null;
126
+ const hour = match[1];
127
+ const minute = match[3] ?? '00';
128
+ const second = match[4] ?? '00';
129
+ if (Number(hour) > 23 || Number(minute) > 59 || Number(second) > 59)
130
+ return null;
131
+ const fraction = (match[5] ?? '').slice(0, 6).padEnd(6, '0');
132
+ return `${date}T${hour}:${minute}:${second}.${fraction}`;
133
+ };
134
+ exports.parseNaiveDatetime = parseNaiveDatetime;