lambder 7.2.5 → 8.0.2

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 (209) hide show
  1. package/CHANGELOG.md +1021 -3
  2. package/README.md +43 -21
  3. package/dist/api/LambderApiAnswer.d.ts +18 -22
  4. package/dist/api/LambderApiAnswer.js +6 -7
  5. package/dist/api/LambderApiCallContext.d.ts +21 -8
  6. package/dist/api/LambderApiCallContext.js +22 -4
  7. package/dist/api/LambderApiDefinition.d.ts +4 -3
  8. package/dist/api/LambderApiEnvelope.d.ts +14 -9
  9. package/dist/api/LambderApiEnvelope.js +33 -34
  10. package/dist/api/LambderApiGuards.d.ts +78 -51
  11. package/dist/api/LambderApiGuards.js +34 -36
  12. package/dist/api/LambderApiIdempotency.d.ts +74 -61
  13. package/dist/api/LambderApiIdempotency.js +226 -151
  14. package/dist/api/LambderApiOutputValidationError.d.ts +32 -0
  15. package/dist/api/LambderApiOutputValidationError.js +50 -0
  16. package/dist/api/LambderApiPipeline.d.ts +77 -39
  17. package/dist/api/LambderApiPipeline.js +135 -62
  18. package/dist/api/LambderApiRateLimits.d.ts +208 -54
  19. package/dist/api/LambderApiRateLimits.js +197 -108
  20. package/dist/api/LambderApiRequest.d.ts +27 -21
  21. package/dist/api/LambderApiRequest.js +26 -19
  22. package/dist/api/LambderApiSignature.d.ts +12 -15
  23. package/dist/api/LambderApiSignature.js +28 -51
  24. package/dist/api/LambderApiValidationRefusal.d.ts +9 -9
  25. package/dist/api/LambderApiValidationRefusal.js +10 -10
  26. package/dist/build/freshProcessVerifier.d.ts +13 -0
  27. package/dist/build/freshProcessVerifier.js +19 -0
  28. package/dist/build/writeApiSignatures.d.ts +109 -0
  29. package/dist/build/writeApiSignatures.js +222 -0
  30. package/dist/build.d.ts +9 -0
  31. package/dist/build.js +8 -0
  32. package/dist/client/LambderCaller.d.ts +13 -44
  33. package/dist/client/LambderCaller.js +77 -84
  34. package/dist/client/LambderReloadLoopBreaker.d.ts +56 -26
  35. package/dist/client/LambderReloadLoopBreaker.js +90 -46
  36. package/dist/client/lambderFetchTransport.d.ts +4 -1
  37. package/dist/client/lambderFetchTransport.js +52 -28
  38. package/dist/client.d.ts +5 -3
  39. package/dist/client.js +2 -1
  40. package/dist/core/Lambder.d.ts +161 -69
  41. package/dist/core/Lambder.js +370 -226
  42. package/dist/core/LambderContext.d.ts +82 -15
  43. package/dist/core/LambderContext.js +107 -20
  44. package/dist/core/LambderCors.d.ts +21 -3
  45. package/dist/core/LambderCors.js +35 -16
  46. package/dist/core/LambderCrashHandling.d.ts +40 -0
  47. package/dist/core/LambderCrashHandling.js +97 -0
  48. package/dist/core/LambderCreateOptions.d.ts +151 -75
  49. package/dist/core/LambderCreateOptions.js +16 -23
  50. package/dist/core/LambderFiles.d.ts +28 -7
  51. package/dist/core/LambderFiles.js +73 -33
  52. package/dist/core/LambderIndexHtml.js +12 -11
  53. package/dist/core/LambderPolicyBuilders.d.ts +17 -5
  54. package/dist/core/LambderPolicyBuilders.js +17 -5
  55. package/dist/core/LambderPublicFiles.d.ts +11 -5
  56. package/dist/core/LambderPublicFiles.js +32 -4
  57. package/dist/core/LambderRequestPath.d.ts +43 -0
  58. package/dist/core/LambderRequestPath.js +63 -0
  59. package/dist/core/LambderResponse.d.ts +26 -5
  60. package/dist/core/LambderResponse.js +157 -70
  61. package/dist/core/LambderResponseBuilder.d.ts +49 -4
  62. package/dist/core/LambderResponseBuilder.js +64 -3
  63. package/dist/core/LambderRouting.d.ts +2 -3
  64. package/dist/core/LambderRouting.js +22 -7
  65. package/dist/core/LambderTemplatingEngine.js +211 -32
  66. package/dist/index.d.ts +15 -8
  67. package/dist/index.js +5 -4
  68. package/dist/invoke/LambderInvokeCaller.d.ts +37 -42
  69. package/dist/invoke/LambderInvokeCaller.js +76 -66
  70. package/dist/invoke/LambderInvokeOutcome.d.ts +27 -26
  71. package/dist/invoke/LambderInvokeOutcome.js +9 -22
  72. package/dist/invoke/LambderLambdaEvent.d.ts +44 -10
  73. package/dist/invoke/LambderLambdaEvent.js +80 -37
  74. package/dist/invoke/lambderHandlerTransport.d.ts +12 -10
  75. package/dist/invoke/lambderHandlerTransport.js +16 -19
  76. package/dist/mock/LambderMockApp.d.ts +67 -83
  77. package/dist/mock/LambderMockApp.js +167 -153
  78. package/dist/mock/LambderMockBrowserCookies.d.ts +24 -28
  79. package/dist/mock/LambderMockBrowserCookies.js +24 -28
  80. package/dist/mock/LambderMockCallRecorder.d.ts +15 -22
  81. package/dist/mock/LambderMockCallRecorder.js +19 -28
  82. package/dist/mock/LambderMockCreateOptions.d.ts +42 -24
  83. package/dist/mock/LambderMockEntryRegistry.d.ts +11 -12
  84. package/dist/mock/LambderMockEntryRegistry.js +24 -29
  85. package/dist/mock/LambderMockFailureInjector.d.ts +3 -6
  86. package/dist/mock/LambderMockFailureInjector.js +3 -6
  87. package/dist/mock/LambderMockTypes.d.ts +78 -108
  88. package/dist/mock/lambderMockInvokeTransport.d.ts +11 -13
  89. package/dist/mock/lambderMockInvokeTransport.js +11 -10
  90. package/dist/mock/lambderMockMswHandler.d.ts +33 -29
  91. package/dist/mock/lambderMockMswHandler.js +50 -39
  92. package/dist/mock.d.ts +3 -1
  93. package/dist/mock.js +5 -3
  94. package/dist/session/LambderSessionController.d.ts +108 -89
  95. package/dist/session/LambderSessionController.js +187 -168
  96. package/dist/session/LambderSessionCrypto.d.ts +16 -7
  97. package/dist/session/LambderSessionCrypto.js +26 -12
  98. package/dist/session/LambderSessionManager.d.ts +136 -47
  99. package/dist/session/LambderSessionManager.js +280 -139
  100. package/dist/shared/LambderHtml.d.ts +42 -3
  101. package/dist/shared/LambderHtml.js +127 -7
  102. package/dist/shared/LambderHtmlPositions.d.ts +173 -0
  103. package/dist/shared/LambderHtmlPositions.js +652 -0
  104. package/dist/shared/LambderI18n.d.ts +10 -11
  105. package/dist/shared/LambderI18n.js +33 -21
  106. package/dist/shared/contracts/LambderCache.d.ts +66 -0
  107. package/dist/shared/contracts/LambderCache.js +11 -0
  108. package/dist/shared/contracts/LambderFileSource.d.ts +6 -6
  109. package/dist/shared/contracts/LambderFileSource.js +5 -8
  110. package/dist/shared/contracts/LambderIdempotencyStore.d.ts +51 -22
  111. package/dist/shared/contracts/LambderIdempotencyStore.js +4 -5
  112. package/dist/shared/contracts/LambderRateLimiter.d.ts +27 -15
  113. package/dist/shared/contracts/LambderRateLimiter.js +4 -5
  114. package/dist/shared/contracts/LambderSessionStore.d.ts +65 -26
  115. package/dist/shared/contracts/LambderSessionStore.js +5 -6
  116. package/dist/shared/transport/LambderApiTransport.d.ts +27 -27
  117. package/dist/shared/transport/LambderApiTransport.js +7 -7
  118. package/dist/shared/transport/LambderCookieJar.d.ts +28 -35
  119. package/dist/shared/transport/LambderCookieJar.js +54 -66
  120. package/dist/shared/transport/lambderCookieJarTransport.d.ts +11 -13
  121. package/dist/shared/transport/lambderCookieJarTransport.js +24 -23
  122. package/dist/shared/util/LambderCallAbort.d.ts +5 -5
  123. package/dist/shared/util/LambderCallAbort.js +5 -5
  124. package/dist/shared/util/LambderClientIp.d.ts +27 -11
  125. package/dist/shared/util/LambderClientIp.js +96 -13
  126. package/dist/shared/util/LambderExpiringMap.d.ts +35 -49
  127. package/dist/shared/util/LambderExpiringMap.js +41 -57
  128. package/dist/shared/util/LambderNodeModules.js +6 -7
  129. package/dist/shared/util/LambderOptionChecks.d.ts +4 -4
  130. package/dist/shared/util/LambderOptionChecks.js +4 -4
  131. package/dist/shared/util/LambderResponseBrand.d.ts +5 -5
  132. package/dist/shared/util/LambderResponseBrand.js +5 -5
  133. package/dist/shared/util/LambderTestingDoors.d.ts +29 -0
  134. package/dist/shared/util/LambderTestingDoors.js +29 -0
  135. package/dist/shared/util/LambderTypeUtilities.d.ts +7 -8
  136. package/dist/shared/util/LambderTypeUtilities.js +3 -3
  137. package/dist/shared/util/boundKeyField.d.ts +20 -0
  138. package/dist/shared/util/boundKeyField.js +34 -0
  139. package/dist/shared/util/canonicalJson.d.ts +11 -0
  140. package/dist/shared/util/canonicalJson.js +28 -0
  141. package/dist/shared/util/joinKeyFields.d.ts +20 -0
  142. package/dist/shared/util/joinKeyFields.js +22 -0
  143. package/dist/shared/wire/LambderAnswerHeaders.d.ts +12 -16
  144. package/dist/shared/wire/LambderAnswerHeaders.js +12 -16
  145. package/dist/shared/wire/LambderApiContract.d.ts +107 -32
  146. package/dist/shared/wire/LambderApiOutcome.d.ts +43 -31
  147. package/dist/shared/wire/LambderApiOutcome.js +48 -23
  148. package/dist/shared/wire/LambderApiRefusal.d.ts +39 -27
  149. package/dist/shared/wire/LambderApiRefusal.js +36 -7
  150. package/dist/shared/wire/LambderApiSignature.d.ts +18 -22
  151. package/dist/shared/wire/LambderApiSignature.js +16 -19
  152. package/dist/shared/wire/LambderCallOptions.d.ts +38 -47
  153. package/dist/shared/wire/LambderCallOptions.js +9 -11
  154. package/dist/shared/wire/LambderCompressionCodec.d.ts +29 -34
  155. package/dist/shared/wire/LambderCompressionCodec.js +31 -36
  156. package/dist/shared/wire/LambderCompressionOption.d.ts +9 -9
  157. package/dist/shared/wire/LambderCompressionOption.js +9 -9
  158. package/dist/shared/wire/LambderCrashDetail.d.ts +12 -15
  159. package/dist/shared/wire/LambderCrashDetail.js +12 -15
  160. package/dist/shared/wire/LambderDefaultApiPath.d.ts +6 -0
  161. package/dist/shared/wire/LambderDefaultApiPath.js +6 -0
  162. package/dist/shared/wire/LambderHttpStatus.d.ts +6 -7
  163. package/dist/shared/wire/LambderIdempotencyKeyScope.d.ts +89 -0
  164. package/dist/shared/wire/LambderIdempotencyKeyScope.js +146 -0
  165. package/dist/shared/wire/LambderInvokeApiId.d.ts +27 -0
  166. package/dist/shared/wire/LambderInvokeApiId.js +27 -0
  167. package/dist/shared/wire/LambderOutcomeAssertions.d.ts +79 -0
  168. package/dist/shared/wire/LambderOutcomeAssertions.js +112 -0
  169. package/dist/shared/wire/LambderRequestPayload.d.ts +18 -20
  170. package/dist/shared/wire/LambderRequestPayload.js +4 -6
  171. package/dist/stores/LambderCacheFiller.d.ts +48 -0
  172. package/dist/stores/LambderCacheFiller.js +119 -0
  173. package/dist/stores/LambderCacheKeys.d.ts +26 -0
  174. package/dist/stores/LambderCacheKeys.js +54 -0
  175. package/dist/stores/LambderCacheValues.d.ts +45 -0
  176. package/dist/stores/LambderCacheValues.js +74 -0
  177. package/dist/stores/LambderDdbCache.d.ts +121 -56
  178. package/dist/stores/LambderDdbCache.js +528 -225
  179. package/dist/stores/LambderDdbIdempotencyStore.d.ts +33 -22
  180. package/dist/stores/LambderDdbIdempotencyStore.js +75 -50
  181. package/dist/stores/LambderDdbRateLimiter.d.ts +76 -20
  182. package/dist/stores/LambderDdbRateLimiter.js +151 -39
  183. package/dist/stores/LambderDdbSdk.d.ts +43 -31
  184. package/dist/stores/LambderDdbSdk.js +79 -33
  185. package/dist/stores/LambderDdbSessionStore.d.ts +27 -14
  186. package/dist/stores/LambderDdbSessionStore.js +119 -47
  187. package/dist/stores/LambderHttpFileSource.d.ts +15 -6
  188. package/dist/stores/LambderHttpFileSource.js +15 -13
  189. package/dist/stores/LambderMemoryCache.d.ts +49 -0
  190. package/dist/stores/LambderMemoryCache.js +113 -0
  191. package/dist/stores/LambderMemoryIdempotencyStore.d.ts +13 -12
  192. package/dist/stores/LambderMemoryIdempotencyStore.js +31 -30
  193. package/dist/stores/LambderMemoryRateLimiter.d.ts +8 -9
  194. package/dist/stores/LambderMemoryRateLimiter.js +14 -13
  195. package/dist/stores/LambderMemorySessionStore.d.ts +14 -11
  196. package/dist/stores/LambderMemorySessionStore.js +38 -19
  197. package/dist/stores/LambderS3FileSource.d.ts +21 -6
  198. package/dist/stores/LambderS3FileSource.js +12 -7
  199. package/dist/testing/LambderTestApp.d.ts +176 -0
  200. package/dist/testing/LambderTestApp.js +204 -0
  201. package/dist/testing/LambderTestVisitor.d.ts +153 -0
  202. package/dist/testing/LambderTestVisitor.js +154 -0
  203. package/dist/testing.d.ts +27 -0
  204. package/dist/testing.js +24 -0
  205. package/package.json +20 -3
  206. package/dist/api/LambderApiPolicyEngine.d.ts +0 -36
  207. package/dist/api/LambderApiPolicyEngine.js +0 -77
  208. package/dist/shared/util/LambderKeyFields.d.ts +0 -32
  209. package/dist/shared/util/LambderKeyFields.js +0 -34
@@ -1,77 +0,0 @@
1
- import { LambderApiGuardsEngine } from "./LambderApiGuards.js";
2
- import { LambderApiRateLimitsEngine } from "./LambderApiRateLimits.js";
3
- import { LambderApiIdempotencyEngine } from "./LambderApiIdempotency.js";
4
- /** An API that asks for idempotency: declared, and not the explicit `false` opt-out. */
5
- const usesIdempotency = (definition) => definition.idempotency !== undefined && definition.idempotency !== false;
6
- /**
7
- * Runtime side of the declarative API options: composes the three policy
8
- * subsystems (rate limits in ./LambderApiRateLimits.ts, guards in
9
- * ./LambderApiGuards.ts, idempotency in ./LambderApiIdempotency.ts), asserts
10
- * registrations against them at startup, and executes them around handlers
11
- * at request time. Owned by LambderApiPipeline; apps interact through the
12
- * create() options (rateLimits, guards, idempotency) and the per-API
13
- * options.
14
- */
15
- export class LambderApiPolicyEngine {
16
- rateLimits = new LambderApiRateLimitsEngine();
17
- guards = new LambderApiGuardsEngine();
18
- idempotency = new LambderApiIdempotencyEngine();
19
- /** True once any of the three subsystems was configured. */
20
- get isConfigured() {
21
- return this.rateLimits.isConfigured || this.guards.isConfigured || this.idempotency.isConfigured;
22
- }
23
- configureRateLimits(config) {
24
- this.rateLimits.configure(config);
25
- }
26
- configureGuards(guards) {
27
- this.guards.configure(guards);
28
- }
29
- configureIdempotency(config) {
30
- this.idempotency.configure(config);
31
- }
32
- /** Startup validation of one API's declarative options. */
33
- assertRegistration(definition) {
34
- const { name, mode } = definition;
35
- // Each subsystem reports its own absence. One combined message would
36
- // tell an API that declares guards on an instance with no guards map
37
- // that none of the three was configured, which reads as a question
38
- // about all three when only one of them is missing.
39
- if (definition.rateLimit !== undefined && !this.rateLimits.isConfigured) {
40
- throw new Error(`Lambder: API "${name}" declares rateLimit but no rateLimits option was configured at creation.`);
41
- }
42
- if (definition.guards !== undefined && !this.guards.isConfigured) {
43
- throw new Error(`Lambder: API "${name}" declares guards but no guards option was configured at creation.`);
44
- }
45
- this.rateLimits.assertRegistration(name, mode, definition.rateLimit);
46
- this.guards.assertRegistration(name, mode, definition.guards);
47
- // `idempotency: false` is an explicit opt-out, not a use: it asks for
48
- // nothing and so needs no store behind it.
49
- if (usesIdempotency(definition)) {
50
- if (!this.idempotency.isConfigured) {
51
- throw new Error(`Lambder: API "${name}" declares idempotency but no idempotency store was configured at creation.`);
52
- }
53
- this.idempotency.assertRegistration(name, definition.idempotency);
54
- }
55
- }
56
- /** The rate-limit policies that can be checked before the session is read: see LambderApiRateLimitsEngine.run. */
57
- async runSessionlessRateLimits(request, ctx, definition) {
58
- await this.rateLimits.run(definition.name, request, ctx, definition.rateLimit, "beforeSession");
59
- }
60
- /** The remaining rate limits, then guards, in declared order. Refusals throw; the trace records each guard as it runs. */
61
- async runPreflight(request, ctx, definition, trace) {
62
- await this.rateLimits.run(definition.name, request, ctx, definition.rateLimit, "afterSession");
63
- await this.guards.run(request, ctx, definition.guards, trace);
64
- }
65
- /** Idempotency replay fast path, run before the preflight: see LambderApiIdempotencyEngine.findReplay. */
66
- async findReplay(request, ctx, definition, trace) {
67
- if (!definition.idempotency)
68
- return null;
69
- return await this.idempotency.findReplay(definition.name, request, ctx, trace);
70
- }
71
- /** Idempotency claim/replay wrapper around handler execution: see LambderApiIdempotencyEngine.withIdempotency. */
72
- async withIdempotency(request, ctx, definition, trace, exec) {
73
- if (!definition.idempotency)
74
- return await exec();
75
- return await this.idempotency.withIdempotency(definition.name, request, ctx, definition.idempotency, trace, exec);
76
- }
77
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * Joining the fields of a tracker or scope key.
3
- *
4
- * Both the rate limiter and the idempotency engine build a key by joining a
5
- * few fields with a separator, and at least one field in each is caller data:
6
- * a rate-limit key returned by a policy handler, an idempotency key posted
7
- * with the request. A plain join lets two different field lists produce one
8
- * string, so two callers land on one counter or one caller reads another's
9
- * stored answer.
10
- *
11
- * Escaping the caller's use of the separator rather than rejecting or
12
- * reserving it: the caller chose the character for its own reasons, and a
13
- * limit that refuses a legal key is a bug of its own.
14
- *
15
- * The join is one-way. Nothing here reads a key back apart, because nothing
16
- * needs to: a key is looked up, counted against or compared, never taken to
17
- * pieces. The escaping is there so that distinct field lists cannot collide,
18
- * not so that the fields can be recovered.
19
- *
20
- * LambderDdbCache's sort-key encoding looks similar and is deliberately the
21
- * other thing: a reversible escape, because a cached entry's sort key is
22
- * handed back to the caller by listSortKeys and therefore has to decode to
23
- * exactly what was written. Two schemes, two jobs; neither should be reached
24
- * for in the other's place.
25
- *
26
- * Written once because the two engines had drifted, one escaping and one not.
27
- */
28
- /**
29
- * The fields joined into one key, each escaped, so no two distinct field
30
- * lists can produce the same string.
31
- */
32
- export declare const joinKeyFields: (...fields: string[]) => string;
@@ -1,34 +0,0 @@
1
- /**
2
- * Joining the fields of a tracker or scope key.
3
- *
4
- * Both the rate limiter and the idempotency engine build a key by joining a
5
- * few fields with a separator, and at least one field in each is caller data:
6
- * a rate-limit key returned by a policy handler, an idempotency key posted
7
- * with the request. A plain join lets two different field lists produce one
8
- * string, so two callers land on one counter or one caller reads another's
9
- * stored answer.
10
- *
11
- * Escaping the caller's use of the separator rather than rejecting or
12
- * reserving it: the caller chose the character for its own reasons, and a
13
- * limit that refuses a legal key is a bug of its own.
14
- *
15
- * The join is one-way. Nothing here reads a key back apart, because nothing
16
- * needs to: a key is looked up, counted against or compared, never taken to
17
- * pieces. The escaping is there so that distinct field lists cannot collide,
18
- * not so that the fields can be recovered.
19
- *
20
- * LambderDdbCache's sort-key encoding looks similar and is deliberately the
21
- * other thing: a reversible escape, because a cached entry's sort key is
22
- * handed back to the caller by listSortKeys and therefore has to decode to
23
- * exactly what was written. Two schemes, two jobs; neither should be reached
24
- * for in the other's place.
25
- *
26
- * Written once because the two engines had drifted, one escaping and one not.
27
- */
28
- /** One field, with the separator and its own escape character escaped. */
29
- const escapeKeyField = (value) => value.replace(/\\/g, "\\\\").replace(/\|/g, "\\|");
30
- /**
31
- * The fields joined into one key, each escaped, so no two distinct field
32
- * lists can produce the same string.
33
- */
34
- export const joinKeyFields = (...fields) => fields.map(escapeKeyField).join("|");