lambder 1.0.124 → 1.0.125
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 +1 -1
- package/dist/Lambder.d.ts +2 -1
- package/dist/Lambder.js +2 -2
- package/dist/LambderCaller.js +9 -3
- package/dist/LambderResponseBuilder.d.ts +1 -0
- package/dist/LambderResponseBuilder.js +32 -1
- package/package.json +1 -1
- package/src/Lambder.ts +3 -2
- package/src/LambderCaller.ts +8 -3
- package/src/LambderResponseBuilder.ts +40 -1
package/Readme.md
CHANGED
package/dist/Lambder.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export type LambderRenderContext = {
|
|
|
17
17
|
apiPayload: any;
|
|
18
18
|
headers: APIGatewayProxyEventHeaders;
|
|
19
19
|
session: LambderSessionContext | null;
|
|
20
|
+
event: APIGatewayProxyEvent;
|
|
20
21
|
lambdaContext: Context;
|
|
21
22
|
_otherInternal: {
|
|
22
23
|
isApiCall: boolean;
|
|
@@ -63,7 +64,7 @@ export default class Lambder {
|
|
|
63
64
|
ejsPath?: string;
|
|
64
65
|
apiVersion?: string;
|
|
65
66
|
});
|
|
66
|
-
|
|
67
|
+
enableCors(isCorsEnabled: boolean): void;
|
|
67
68
|
enableDdbSession({ tableName, tableRegion, sessionSalt }: {
|
|
68
69
|
tableName: string;
|
|
69
70
|
tableRegion: string;
|
package/dist/Lambder.js
CHANGED
|
@@ -33,7 +33,7 @@ export const createContext = (event, lambdaContext, apiPath) => {
|
|
|
33
33
|
const apiPayload = isApiCall ? post.payload : null;
|
|
34
34
|
return {
|
|
35
35
|
host, path, pathParams, method,
|
|
36
|
-
get, post, cookie,
|
|
36
|
+
get, post, cookie, event,
|
|
37
37
|
apiName, apiPayload,
|
|
38
38
|
headers, session, lambdaContext,
|
|
39
39
|
_otherInternal: {
|
|
@@ -72,7 +72,7 @@ export default class Lambder {
|
|
|
72
72
|
};
|
|
73
73
|
this.utils = new LambderUtils({ ejsPath });
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
enableCors(isCorsEnabled) {
|
|
76
76
|
this.isCorsEnabled = isCorsEnabled;
|
|
77
77
|
}
|
|
78
78
|
enableDdbSession({ tableName, tableRegion, sessionSalt }, { partitionKey, sortKey } = { partitionKey: "pk", sortKey: "sk" }) {
|
package/dist/LambderCaller.js
CHANGED
|
@@ -51,10 +51,16 @@ export default class LambderCaller {
|
|
|
51
51
|
credentials: 'same-origin', redirect: 'follow', referrerPolicy: 'origin',
|
|
52
52
|
headers: { 'Content-Type': 'application/json', ...(headers || {}) },
|
|
53
53
|
body: JSON.stringify({ apiName, version, token, siteHost, payload, }),
|
|
54
|
-
}).then(res => {
|
|
54
|
+
}).then(async (res) => {
|
|
55
55
|
if (res.status >= 500)
|
|
56
56
|
throw new Error("Request failed: " + res.status + " - " + res.statusText);
|
|
57
|
-
|
|
57
|
+
if (res.headers.get("Content-Type")?.includes("application/lambder-json-stream")) {
|
|
58
|
+
const decompressed = res.json();
|
|
59
|
+
return decompressed;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return res.json();
|
|
63
|
+
}
|
|
58
64
|
});
|
|
59
65
|
fetchTracker.done = true;
|
|
60
66
|
if (this.fetchEndedHandler) {
|
|
@@ -95,7 +101,7 @@ export default class LambderCaller {
|
|
|
95
101
|
await this.notAuthorizedHandler();
|
|
96
102
|
}
|
|
97
103
|
else if (this.errorHandler) {
|
|
98
|
-
await this.errorHandler(new Error("
|
|
104
|
+
await this.errorHandler(new Error("Not Authorized;"));
|
|
99
105
|
}
|
|
100
106
|
return null;
|
|
101
107
|
}
|
|
@@ -47,4 +47,5 @@ export default class LambderResponseBuilder {
|
|
|
47
47
|
ejsTemplate(template: string, pageData: Record<string, any>, headers?: Record<string, string | string[]>): Promise<LambderResolverResponse>;
|
|
48
48
|
ejsFile(filePath: string, pageData: Record<string, any>, headers?: Record<string, string | string[]>): Promise<LambderResolverResponse>;
|
|
49
49
|
api<T = any>(payload: T | null, { versionExpired, sessionExpired, notAuthorized, message, errorMessage, logList, }?: LambderApiResponseConfig, headers?: Record<string, string | string[]>): LambderResolverResponse;
|
|
50
|
+
private apiBinary;
|
|
50
51
|
}
|
|
@@ -144,7 +144,11 @@ export default class LambderResponseBuilder {
|
|
|
144
144
|
}
|
|
145
145
|
const mimeType = mimeTypeResolver.lookup(filePath);
|
|
146
146
|
const body = this.readPublicFileSync(filePath);
|
|
147
|
-
|
|
147
|
+
if (body === "forbidden-public-path") {
|
|
148
|
+
throw { error: "Forbidden public path: " + filePath };
|
|
149
|
+
}
|
|
150
|
+
const bodyBuffer = Buffer.isBuffer(body) ? body : Buffer.from(body);
|
|
151
|
+
const bodyBase64 = bodyBuffer.toString("base64");
|
|
148
152
|
console.log("bodyBase64.length", bodyBase64.length);
|
|
149
153
|
return this.fileBase64(bodyBase64, mimeType || "", headers);
|
|
150
154
|
}
|
|
@@ -186,5 +190,32 @@ export default class LambderResponseBuilder {
|
|
|
186
190
|
}, headers);
|
|
187
191
|
}
|
|
188
192
|
;
|
|
193
|
+
apiBinary(payload, { versionExpired, sessionExpired, notAuthorized, message, errorMessage, logList, } = {
|
|
194
|
+
versionExpired: undefined, sessionExpired: undefined, notAuthorized: undefined,
|
|
195
|
+
message: null, errorMessage: null, logList: undefined
|
|
196
|
+
}, headers) {
|
|
197
|
+
const finalLogList = logList || this.ctx?._otherInternal?.logToApiResponseAccumulator;
|
|
198
|
+
const result = {
|
|
199
|
+
apiVersion: this.apiVersion,
|
|
200
|
+
payload,
|
|
201
|
+
...(versionExpired ? { versionExpired } : {}),
|
|
202
|
+
...(sessionExpired ? { sessionExpired } : {}),
|
|
203
|
+
...(notAuthorized ? { notAuthorized } : {}),
|
|
204
|
+
...(message ? { message } : {}),
|
|
205
|
+
...(errorMessage ? { errorMessage } : {}),
|
|
206
|
+
...(finalLogList?.length ? { logList: finalLogList } : {}),
|
|
207
|
+
};
|
|
208
|
+
return this.raw({
|
|
209
|
+
statusCode: 200,
|
|
210
|
+
isBase64Encoded: true,
|
|
211
|
+
multiValueHeaders: {
|
|
212
|
+
"Content-Type": ["application/lambder-json-stream"],
|
|
213
|
+
"Content-Encoding": ["gzip"],
|
|
214
|
+
...convertToMultiHeader(headers)
|
|
215
|
+
},
|
|
216
|
+
body: Buffer.from(JSON.stringify(result)).toString("base64"),
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
;
|
|
189
220
|
}
|
|
190
221
|
;
|
package/package.json
CHANGED
package/src/Lambder.ts
CHANGED
|
@@ -23,6 +23,7 @@ export type LambderRenderContext = {
|
|
|
23
23
|
apiPayload: any;
|
|
24
24
|
headers: APIGatewayProxyEventHeaders;
|
|
25
25
|
session: LambderSessionContext|null;
|
|
26
|
+
event: APIGatewayProxyEvent;
|
|
26
27
|
lambdaContext: Context;
|
|
27
28
|
_otherInternal: {
|
|
28
29
|
isApiCall: boolean,
|
|
@@ -78,7 +79,7 @@ export const createContext = (
|
|
|
78
79
|
|
|
79
80
|
return {
|
|
80
81
|
host, path, pathParams, method,
|
|
81
|
-
get, post, cookie,
|
|
82
|
+
get, post, cookie, event,
|
|
82
83
|
apiName, apiPayload,
|
|
83
84
|
headers, session, lambdaContext,
|
|
84
85
|
_otherInternal: {
|
|
@@ -133,7 +134,7 @@ export default class Lambder {
|
|
|
133
134
|
this.utils = new LambderUtils({ ejsPath });
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
|
|
137
|
+
enableCors(isCorsEnabled: boolean){
|
|
137
138
|
this.isCorsEnabled = isCorsEnabled;
|
|
138
139
|
}
|
|
139
140
|
|
package/src/LambderCaller.ts
CHANGED
|
@@ -117,9 +117,14 @@ export default class LambderCaller {
|
|
|
117
117
|
credentials: 'same-origin', redirect: 'follow', referrerPolicy: 'origin',
|
|
118
118
|
headers: { 'Content-Type': 'application/json', ...(headers || {}) },
|
|
119
119
|
body: JSON.stringify({ apiName, version, token, siteHost, payload, }),
|
|
120
|
-
}).then(res=>{
|
|
120
|
+
}).then(async (res)=>{
|
|
121
121
|
if(res.status >= 500) throw new Error("Request failed: " + res.status + " - " + res.statusText);
|
|
122
|
-
|
|
122
|
+
if(res.headers.get("Content-Type")?.includes("application/lambder-json-stream")){
|
|
123
|
+
const decompressed = res.json();
|
|
124
|
+
return decompressed;
|
|
125
|
+
}else{
|
|
126
|
+
return res.json();
|
|
127
|
+
}
|
|
123
128
|
}) as LambderApiResponse<T>;
|
|
124
129
|
fetchTracker.done = true;
|
|
125
130
|
if(this.fetchEndedHandler){
|
|
@@ -157,7 +162,7 @@ export default class LambderCaller {
|
|
|
157
162
|
if(this.notAuthorizedHandler){
|
|
158
163
|
await this.notAuthorizedHandler();
|
|
159
164
|
}else if(this.errorHandler){
|
|
160
|
-
await this.errorHandler(new Error("
|
|
165
|
+
await this.errorHandler(new Error("Not Authorized;"));
|
|
161
166
|
}
|
|
162
167
|
return null;
|
|
163
168
|
}
|
|
@@ -199,7 +199,11 @@ export default class LambderResponseBuilder {
|
|
|
199
199
|
}
|
|
200
200
|
const mimeType = mimeTypeResolver.lookup(filePath);
|
|
201
201
|
const body = this.readPublicFileSync(filePath);
|
|
202
|
-
|
|
202
|
+
if (body === "forbidden-public-path") {
|
|
203
|
+
throw { error: "Forbidden public path: " + filePath };
|
|
204
|
+
}
|
|
205
|
+
const bodyBuffer: Buffer = Buffer.isBuffer(body) ? body : Buffer.from(body);
|
|
206
|
+
const bodyBase64 = bodyBuffer.toString("base64");
|
|
203
207
|
console.log("bodyBase64.length",bodyBase64.length);
|
|
204
208
|
return this.fileBase64(bodyBase64, mimeType || "", headers);
|
|
205
209
|
};
|
|
@@ -258,4 +262,39 @@ export default class LambderResponseBuilder {
|
|
|
258
262
|
}, headers);
|
|
259
263
|
};
|
|
260
264
|
|
|
265
|
+
private apiBinary<T=any>(
|
|
266
|
+
payload: T | null,
|
|
267
|
+
{
|
|
268
|
+
versionExpired, sessionExpired, notAuthorized,
|
|
269
|
+
message, errorMessage, logList,
|
|
270
|
+
}: LambderApiResponseConfig = {
|
|
271
|
+
versionExpired: undefined, sessionExpired: undefined, notAuthorized: undefined,
|
|
272
|
+
message: null, errorMessage: null, logList: undefined
|
|
273
|
+
},
|
|
274
|
+
headers?: Record<string, string|string[]>,
|
|
275
|
+
): LambderResolverResponse {
|
|
276
|
+
const finalLogList = logList || this.ctx?._otherInternal?.logToApiResponseAccumulator;
|
|
277
|
+
const result = {
|
|
278
|
+
apiVersion: this.apiVersion,
|
|
279
|
+
payload,
|
|
280
|
+
...(versionExpired ? {versionExpired} : {}),
|
|
281
|
+
...(sessionExpired ? {sessionExpired} : {}),
|
|
282
|
+
...(notAuthorized ? {notAuthorized} : {}),
|
|
283
|
+
...(message ? {message} : {}),
|
|
284
|
+
...(errorMessage ? {errorMessage} : {}),
|
|
285
|
+
...(finalLogList?.length ? {logList: finalLogList} : {}),
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
return this.raw({
|
|
289
|
+
statusCode: 200,
|
|
290
|
+
isBase64Encoded: true,
|
|
291
|
+
multiValueHeaders: {
|
|
292
|
+
"Content-Type": ["application/lambder-json-stream"],
|
|
293
|
+
"Content-Encoding": ["gzip"],
|
|
294
|
+
...convertToMultiHeader(headers)
|
|
295
|
+
},
|
|
296
|
+
body: Buffer.from(JSON.stringify(result)).toString("base64"),
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
|
|
261
300
|
};
|