lambder 4.3.2 → 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +51 -7
- package/dist/client/LambderCaller.d.ts +75 -27
- package/dist/client/LambderCaller.js +18 -2
- package/dist/client.d.ts +1 -1
- package/dist/core/Lambder.d.ts +19 -9
- package/dist/core/Lambder.js +17 -12
- package/dist/core/LambderFiles.d.ts +85 -0
- package/dist/core/LambderFiles.js +116 -0
- package/dist/core/LambderPublicFiles.d.ts +12 -20
- package/dist/core/LambderPublicFiles.js +12 -66
- package/dist/core/LambderResponseBuilder.d.ts +15 -13
- package/dist/core/LambderResponseBuilder.js +19 -54
- package/dist/core/LambderTemplatingEngine.d.ts +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +2 -0
- package/dist/session/LambderSessionController.d.ts +7 -0
- package/dist/session/LambderSessionController.js +10 -0
- package/dist/session/LambderSessionManager.d.ts +11 -0
- package/dist/session/LambderSessionManager.js +38 -2
- package/dist/stores/LambderS3FileSource.d.ts +35 -0
- package/dist/stores/LambderS3FileSource.js +53 -0
- package/package.json +3 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Files from an S3 bucket, or any S3-compatible store such as Cloudflare
|
|
3
|
+
* R2 (pass its endpoint in clientConfig). Needs @aws-sdk/client-s3, an
|
|
4
|
+
* optional peer dependency loaded on first read, so apps that serve from a
|
|
5
|
+
* folder never load it. A missing object reads as null and the request
|
|
6
|
+
* falls through; grant s3:ListBucket besides s3:GetObject, otherwise S3
|
|
7
|
+
* answers a missing key with AccessDenied, which propagates as an error.
|
|
8
|
+
* An object's Content-Type is used unless it is a generic octet-stream, in
|
|
9
|
+
* which case the extension decides, as for local files.
|
|
10
|
+
*/
|
|
11
|
+
export class LambderS3FileSource {
|
|
12
|
+
bucket;
|
|
13
|
+
prefix;
|
|
14
|
+
clientConfig;
|
|
15
|
+
client;
|
|
16
|
+
sdk;
|
|
17
|
+
constructor({ bucket, prefix = "", client, clientConfig }) {
|
|
18
|
+
if (!bucket.trim())
|
|
19
|
+
throw new Error("bucket is required");
|
|
20
|
+
this.bucket = bucket;
|
|
21
|
+
this.prefix = prefix;
|
|
22
|
+
this.client = client;
|
|
23
|
+
this.clientConfig = clientConfig;
|
|
24
|
+
}
|
|
25
|
+
loadSdk() {
|
|
26
|
+
if (!this.sdk) {
|
|
27
|
+
this.sdk = import("@aws-sdk/client-s3").catch(() => {
|
|
28
|
+
throw new Error("LambderS3FileSource requires @aws-sdk/client-s3: npm install @aws-sdk/client-s3");
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return this.sdk;
|
|
32
|
+
}
|
|
33
|
+
async read(relativePath) {
|
|
34
|
+
const { S3Client, GetObjectCommand } = await this.loadSdk();
|
|
35
|
+
if (!this.client)
|
|
36
|
+
this.client = new S3Client(this.clientConfig ?? {});
|
|
37
|
+
let output;
|
|
38
|
+
try {
|
|
39
|
+
output = await this.client.send(new GetObjectCommand({ Bucket: this.bucket, Key: `${this.prefix}${relativePath}` }));
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
const name = err.name;
|
|
43
|
+
if (name === "NoSuchKey" || name === "NotFound")
|
|
44
|
+
return null;
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
if (!output.Body)
|
|
48
|
+
return null;
|
|
49
|
+
const body = Buffer.from(await output.Body.transformToByteArray());
|
|
50
|
+
const contentType = output.ContentType;
|
|
51
|
+
return contentType && !contentType.endsWith("octet-stream") ? { body, mimeType: contentType } : { body };
|
|
52
|
+
}
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lambder",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"zod": "^4.1.12"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
+
"@aws-sdk/client-s3": "^3.574.0",
|
|
64
65
|
"msw": "^2.0.0"
|
|
65
66
|
},
|
|
66
67
|
"peerDependenciesMeta": {
|
|
@@ -69,6 +70,7 @@
|
|
|
69
70
|
}
|
|
70
71
|
},
|
|
71
72
|
"devDependencies": {
|
|
73
|
+
"@aws-sdk/client-s3": "^3.1127.0",
|
|
72
74
|
"@types/aws-lambda": "^8.10.136",
|
|
73
75
|
"@types/cookie": "^0.6.0",
|
|
74
76
|
"@types/js-cookie": "^3.0.6",
|