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.
- package/CHANGELOG.md +1021 -3
- package/README.md +43 -21
- package/dist/api/LambderApiAnswer.d.ts +18 -22
- package/dist/api/LambderApiAnswer.js +6 -7
- package/dist/api/LambderApiCallContext.d.ts +21 -8
- package/dist/api/LambderApiCallContext.js +22 -4
- package/dist/api/LambderApiDefinition.d.ts +4 -3
- package/dist/api/LambderApiEnvelope.d.ts +14 -9
- package/dist/api/LambderApiEnvelope.js +33 -34
- package/dist/api/LambderApiGuards.d.ts +78 -51
- package/dist/api/LambderApiGuards.js +34 -36
- package/dist/api/LambderApiIdempotency.d.ts +74 -61
- package/dist/api/LambderApiIdempotency.js +226 -151
- package/dist/api/LambderApiOutputValidationError.d.ts +32 -0
- package/dist/api/LambderApiOutputValidationError.js +50 -0
- package/dist/api/LambderApiPipeline.d.ts +77 -39
- package/dist/api/LambderApiPipeline.js +135 -62
- package/dist/api/LambderApiRateLimits.d.ts +208 -54
- package/dist/api/LambderApiRateLimits.js +197 -108
- package/dist/api/LambderApiRequest.d.ts +27 -21
- package/dist/api/LambderApiRequest.js +26 -19
- package/dist/api/LambderApiSignature.d.ts +12 -15
- package/dist/api/LambderApiSignature.js +28 -51
- package/dist/api/LambderApiValidationRefusal.d.ts +9 -9
- package/dist/api/LambderApiValidationRefusal.js +10 -10
- package/dist/build/freshProcessVerifier.d.ts +13 -0
- package/dist/build/freshProcessVerifier.js +19 -0
- package/dist/build/writeApiSignatures.d.ts +109 -0
- package/dist/build/writeApiSignatures.js +222 -0
- package/dist/build.d.ts +9 -0
- package/dist/build.js +8 -0
- package/dist/client/LambderCaller.d.ts +13 -44
- package/dist/client/LambderCaller.js +77 -84
- package/dist/client/LambderReloadLoopBreaker.d.ts +56 -26
- package/dist/client/LambderReloadLoopBreaker.js +90 -46
- package/dist/client/lambderFetchTransport.d.ts +4 -1
- package/dist/client/lambderFetchTransport.js +52 -28
- package/dist/client.d.ts +5 -3
- package/dist/client.js +2 -1
- package/dist/core/Lambder.d.ts +161 -69
- package/dist/core/Lambder.js +370 -226
- package/dist/core/LambderContext.d.ts +82 -15
- package/dist/core/LambderContext.js +107 -20
- package/dist/core/LambderCors.d.ts +21 -3
- package/dist/core/LambderCors.js +35 -16
- package/dist/core/LambderCrashHandling.d.ts +40 -0
- package/dist/core/LambderCrashHandling.js +97 -0
- package/dist/core/LambderCreateOptions.d.ts +151 -75
- package/dist/core/LambderCreateOptions.js +16 -23
- package/dist/core/LambderFiles.d.ts +28 -7
- package/dist/core/LambderFiles.js +73 -33
- package/dist/core/LambderIndexHtml.js +12 -11
- package/dist/core/LambderPolicyBuilders.d.ts +17 -5
- package/dist/core/LambderPolicyBuilders.js +17 -5
- package/dist/core/LambderPublicFiles.d.ts +11 -5
- package/dist/core/LambderPublicFiles.js +32 -4
- package/dist/core/LambderRequestPath.d.ts +43 -0
- package/dist/core/LambderRequestPath.js +63 -0
- package/dist/core/LambderResponse.d.ts +26 -5
- package/dist/core/LambderResponse.js +157 -70
- package/dist/core/LambderResponseBuilder.d.ts +49 -4
- package/dist/core/LambderResponseBuilder.js +64 -3
- package/dist/core/LambderRouting.d.ts +2 -3
- package/dist/core/LambderRouting.js +22 -7
- package/dist/core/LambderTemplatingEngine.js +211 -32
- package/dist/index.d.ts +15 -8
- package/dist/index.js +5 -4
- package/dist/invoke/LambderInvokeCaller.d.ts +37 -42
- package/dist/invoke/LambderInvokeCaller.js +76 -66
- package/dist/invoke/LambderInvokeOutcome.d.ts +27 -26
- package/dist/invoke/LambderInvokeOutcome.js +9 -22
- package/dist/invoke/LambderLambdaEvent.d.ts +44 -10
- package/dist/invoke/LambderLambdaEvent.js +80 -37
- package/dist/invoke/lambderHandlerTransport.d.ts +12 -10
- package/dist/invoke/lambderHandlerTransport.js +16 -19
- package/dist/mock/LambderMockApp.d.ts +67 -83
- package/dist/mock/LambderMockApp.js +167 -153
- package/dist/mock/LambderMockBrowserCookies.d.ts +24 -28
- package/dist/mock/LambderMockBrowserCookies.js +24 -28
- package/dist/mock/LambderMockCallRecorder.d.ts +15 -22
- package/dist/mock/LambderMockCallRecorder.js +19 -28
- package/dist/mock/LambderMockCreateOptions.d.ts +42 -24
- package/dist/mock/LambderMockEntryRegistry.d.ts +11 -12
- package/dist/mock/LambderMockEntryRegistry.js +24 -29
- package/dist/mock/LambderMockFailureInjector.d.ts +3 -6
- package/dist/mock/LambderMockFailureInjector.js +3 -6
- package/dist/mock/LambderMockTypes.d.ts +78 -108
- package/dist/mock/lambderMockInvokeTransport.d.ts +11 -13
- package/dist/mock/lambderMockInvokeTransport.js +11 -10
- package/dist/mock/lambderMockMswHandler.d.ts +33 -29
- package/dist/mock/lambderMockMswHandler.js +50 -39
- package/dist/mock.d.ts +3 -1
- package/dist/mock.js +5 -3
- package/dist/session/LambderSessionController.d.ts +108 -89
- package/dist/session/LambderSessionController.js +187 -168
- package/dist/session/LambderSessionCrypto.d.ts +16 -7
- package/dist/session/LambderSessionCrypto.js +26 -12
- package/dist/session/LambderSessionManager.d.ts +136 -47
- package/dist/session/LambderSessionManager.js +280 -139
- package/dist/shared/LambderHtml.d.ts +42 -3
- package/dist/shared/LambderHtml.js +127 -7
- package/dist/shared/LambderHtmlPositions.d.ts +173 -0
- package/dist/shared/LambderHtmlPositions.js +652 -0
- package/dist/shared/LambderI18n.d.ts +10 -11
- package/dist/shared/LambderI18n.js +33 -21
- package/dist/shared/contracts/LambderCache.d.ts +66 -0
- package/dist/shared/contracts/LambderCache.js +11 -0
- package/dist/shared/contracts/LambderFileSource.d.ts +6 -6
- package/dist/shared/contracts/LambderFileSource.js +5 -8
- package/dist/shared/contracts/LambderIdempotencyStore.d.ts +51 -22
- package/dist/shared/contracts/LambderIdempotencyStore.js +4 -5
- package/dist/shared/contracts/LambderRateLimiter.d.ts +27 -15
- package/dist/shared/contracts/LambderRateLimiter.js +4 -5
- package/dist/shared/contracts/LambderSessionStore.d.ts +65 -26
- package/dist/shared/contracts/LambderSessionStore.js +5 -6
- package/dist/shared/transport/LambderApiTransport.d.ts +27 -27
- package/dist/shared/transport/LambderApiTransport.js +7 -7
- package/dist/shared/transport/LambderCookieJar.d.ts +28 -35
- package/dist/shared/transport/LambderCookieJar.js +54 -66
- package/dist/shared/transport/lambderCookieJarTransport.d.ts +11 -13
- package/dist/shared/transport/lambderCookieJarTransport.js +24 -23
- package/dist/shared/util/LambderCallAbort.d.ts +5 -5
- package/dist/shared/util/LambderCallAbort.js +5 -5
- package/dist/shared/util/LambderClientIp.d.ts +27 -11
- package/dist/shared/util/LambderClientIp.js +96 -13
- package/dist/shared/util/LambderExpiringMap.d.ts +35 -49
- package/dist/shared/util/LambderExpiringMap.js +41 -57
- package/dist/shared/util/LambderNodeModules.js +6 -7
- package/dist/shared/util/LambderOptionChecks.d.ts +4 -4
- package/dist/shared/util/LambderOptionChecks.js +4 -4
- package/dist/shared/util/LambderResponseBrand.d.ts +5 -5
- package/dist/shared/util/LambderResponseBrand.js +5 -5
- package/dist/shared/util/LambderTestingDoors.d.ts +29 -0
- package/dist/shared/util/LambderTestingDoors.js +29 -0
- package/dist/shared/util/LambderTypeUtilities.d.ts +7 -8
- package/dist/shared/util/LambderTypeUtilities.js +3 -3
- package/dist/shared/util/boundKeyField.d.ts +20 -0
- package/dist/shared/util/boundKeyField.js +34 -0
- package/dist/shared/util/canonicalJson.d.ts +11 -0
- package/dist/shared/util/canonicalJson.js +28 -0
- package/dist/shared/util/joinKeyFields.d.ts +20 -0
- package/dist/shared/util/joinKeyFields.js +22 -0
- package/dist/shared/wire/LambderAnswerHeaders.d.ts +12 -16
- package/dist/shared/wire/LambderAnswerHeaders.js +12 -16
- package/dist/shared/wire/LambderApiContract.d.ts +107 -32
- package/dist/shared/wire/LambderApiOutcome.d.ts +43 -31
- package/dist/shared/wire/LambderApiOutcome.js +48 -23
- package/dist/shared/wire/LambderApiRefusal.d.ts +39 -27
- package/dist/shared/wire/LambderApiRefusal.js +36 -7
- package/dist/shared/wire/LambderApiSignature.d.ts +18 -22
- package/dist/shared/wire/LambderApiSignature.js +16 -19
- package/dist/shared/wire/LambderCallOptions.d.ts +38 -47
- package/dist/shared/wire/LambderCallOptions.js +9 -11
- package/dist/shared/wire/LambderCompressionCodec.d.ts +29 -34
- package/dist/shared/wire/LambderCompressionCodec.js +31 -36
- package/dist/shared/wire/LambderCompressionOption.d.ts +9 -9
- package/dist/shared/wire/LambderCompressionOption.js +9 -9
- package/dist/shared/wire/LambderCrashDetail.d.ts +12 -15
- package/dist/shared/wire/LambderCrashDetail.js +12 -15
- package/dist/shared/wire/LambderDefaultApiPath.d.ts +6 -0
- package/dist/shared/wire/LambderDefaultApiPath.js +6 -0
- package/dist/shared/wire/LambderHttpStatus.d.ts +6 -7
- package/dist/shared/wire/LambderIdempotencyKeyScope.d.ts +89 -0
- package/dist/shared/wire/LambderIdempotencyKeyScope.js +146 -0
- package/dist/shared/wire/LambderInvokeApiId.d.ts +27 -0
- package/dist/shared/wire/LambderInvokeApiId.js +27 -0
- package/dist/shared/wire/LambderOutcomeAssertions.d.ts +79 -0
- package/dist/shared/wire/LambderOutcomeAssertions.js +112 -0
- package/dist/shared/wire/LambderRequestPayload.d.ts +18 -20
- package/dist/shared/wire/LambderRequestPayload.js +4 -6
- package/dist/stores/LambderCacheFiller.d.ts +48 -0
- package/dist/stores/LambderCacheFiller.js +119 -0
- package/dist/stores/LambderCacheKeys.d.ts +26 -0
- package/dist/stores/LambderCacheKeys.js +54 -0
- package/dist/stores/LambderCacheValues.d.ts +45 -0
- package/dist/stores/LambderCacheValues.js +74 -0
- package/dist/stores/LambderDdbCache.d.ts +121 -56
- package/dist/stores/LambderDdbCache.js +528 -225
- package/dist/stores/LambderDdbIdempotencyStore.d.ts +33 -22
- package/dist/stores/LambderDdbIdempotencyStore.js +75 -50
- package/dist/stores/LambderDdbRateLimiter.d.ts +76 -20
- package/dist/stores/LambderDdbRateLimiter.js +151 -39
- package/dist/stores/LambderDdbSdk.d.ts +43 -31
- package/dist/stores/LambderDdbSdk.js +79 -33
- package/dist/stores/LambderDdbSessionStore.d.ts +27 -14
- package/dist/stores/LambderDdbSessionStore.js +119 -47
- package/dist/stores/LambderHttpFileSource.d.ts +15 -6
- package/dist/stores/LambderHttpFileSource.js +15 -13
- package/dist/stores/LambderMemoryCache.d.ts +49 -0
- package/dist/stores/LambderMemoryCache.js +113 -0
- package/dist/stores/LambderMemoryIdempotencyStore.d.ts +13 -12
- package/dist/stores/LambderMemoryIdempotencyStore.js +31 -30
- package/dist/stores/LambderMemoryRateLimiter.d.ts +8 -9
- package/dist/stores/LambderMemoryRateLimiter.js +14 -13
- package/dist/stores/LambderMemorySessionStore.d.ts +14 -11
- package/dist/stores/LambderMemorySessionStore.js +38 -19
- package/dist/stores/LambderS3FileSource.d.ts +21 -6
- package/dist/stores/LambderS3FileSource.js +12 -7
- package/dist/testing/LambderTestApp.d.ts +176 -0
- package/dist/testing/LambderTestApp.js +204 -0
- package/dist/testing/LambderTestVisitor.d.ts +153 -0
- package/dist/testing/LambderTestVisitor.js +154 -0
- package/dist/testing.d.ts +27 -0
- package/dist/testing.js +24 -0
- package/package.json +20 -3
- package/dist/api/LambderApiPolicyEngine.d.ts +0 -36
- package/dist/api/LambderApiPolicyEngine.js +0 -77
- package/dist/shared/util/LambderKeyFields.d.ts +0 -32
- 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("|");
|