lambder 1.0.95 → 1.0.97

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 CHANGED
@@ -38,7 +38,7 @@ const lambder = new Lambder({
38
38
  lambder.addApi("getCompanyPage", async ({ apiPayload }, res) => {
39
39
  const companyName = apiPayload.companyName;
40
40
  const data = await fetchDataSomehow(companyName);
41
- return res.api({ payload: data });
41
+ return res.api(data);
42
42
  });
43
43
 
44
44
  // Define a simple route
@@ -102,7 +102,7 @@ lambder.addApi("getCompanyPage", async (ctx, res) => {
102
102
  } = ctx;
103
103
  const companyName = apiPayload.companyName;
104
104
  const data = await fetchDataSomehow(companyName);
105
- return res.api({ payload: data });
105
+ return res.api(data);
106
106
  });
107
107
  ```
108
108
 
@@ -217,7 +217,7 @@ lambder.addApi("getCompanyName", async (ctx, res) => {
217
217
  // attempts to serve the fallback file.
218
218
  // Returns a JSON error if neither file is found.
219
219
 
220
- return res.api({ payload, notAuthorized, message, errorMessage }, headers);
220
+ return res.api(payload, { notAuthorized, message, errorMessage }, headers);
221
221
  // This function works together with the LambderCaller from the frontend.
222
222
  // Sends a standardized API response including the payload and status
223
223
  // flags like versionExpired, sessionExpired, notAuthorized, along with
@@ -237,7 +237,7 @@ lambder.addApi("getCompanyName", async (ctx, res) => {
237
237
  res.die.cors();
238
238
  res.die.fileBase64(fileBase64, mimeType, headers);
239
239
  res.die.file(filePath, headers, fallbackFilePath);
240
- res.die.api({ payload, versionExpired, sessionExpired, notAuthorized, message, errorMessage }, headers);
240
+ res.die.api(payload, { versionExpired, sessionExpired, notAuthorized, message, errorMessage }, headers);
241
241
  });
242
242
  ```
243
243
 
@@ -4,14 +4,16 @@ export type LambderResolverResponse = {
4
4
  body: string | null;
5
5
  isBase64Encoded?: boolean;
6
6
  };
7
- export type LambderApiResponse<T> = {
8
- payload?: T | null;
7
+ export type LambderApiResponseConfig = {
9
8
  versionExpired?: boolean;
10
9
  sessionExpired?: boolean;
11
10
  notAuthorized?: boolean;
12
11
  message?: any;
13
12
  errorMessage?: any;
14
13
  };
14
+ export type LambderApiResponse<T> = LambderApiResponseConfig & {
15
+ payload?: T | null;
16
+ };
15
17
  export default class LambderResponseBuilder {
16
18
  private isCorsEnabled;
17
19
  private publicPath;
@@ -32,5 +34,5 @@ export default class LambderResponseBuilder {
32
34
  cors(): LambderResolverResponse;
33
35
  fileBase64(fileBase64: string, mimeType: string, headers?: Record<string, string | string[]>): LambderResolverResponse;
34
36
  file(filePath: string, headers?: Record<string, string | string[]>, fallbackFilePath?: string): LambderResolverResponse;
35
- api<T>({ payload, versionExpired, sessionExpired, notAuthorized, message, errorMessage, }: LambderApiResponse<T>, headers?: Record<string, string | string[]>): LambderResolverResponse;
37
+ api<T = any>(payload: T | null, { versionExpired, sessionExpired, notAuthorized, message, errorMessage, }?: LambderApiResponseConfig, headers?: Record<string, string | string[]>): LambderResolverResponse;
36
38
  }
@@ -119,7 +119,10 @@ export default class LambderResponseBuilder {
119
119
  return this.fileBase64(bodyBase64, mimeType || "", headers);
120
120
  }
121
121
  ;
122
- api({ payload, versionExpired, sessionExpired, notAuthorized, message = null, errorMessage = null, }, headers) {
122
+ api(payload, { versionExpired, sessionExpired, notAuthorized, message = null, errorMessage = null, } = {
123
+ versionExpired: undefined, sessionExpired: undefined, notAuthorized: undefined,
124
+ message: null, errorMessage: null,
125
+ }, headers) {
123
126
  return this.json({
124
127
  apiVersion: this.apiVersion,
125
128
  payload,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambder",
3
- "version": "1.0.95",
3
+ "version": "1.0.97",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,8 +21,7 @@ export type LambderResolverResponse = {
21
21
  isBase64Encoded?: boolean,
22
22
  };
23
23
 
24
- export type LambderApiResponse<T> = {
25
- payload?: T | null;
24
+ export type LambderApiResponseConfig = {
26
25
  versionExpired?: boolean;
27
26
  sessionExpired?: boolean;
28
27
  notAuthorized?: boolean;
@@ -30,6 +29,11 @@ export type LambderApiResponse<T> = {
30
29
  errorMessage?: any;
31
30
  }
32
31
 
32
+
33
+ export type LambderApiResponse<T> = LambderApiResponseConfig & {
34
+ payload?: T | null;
35
+ }
36
+
33
37
  export default class LambderResponseBuilder {
34
38
  private isCorsEnabled: boolean;
35
39
  private publicPath: string;
@@ -166,12 +170,15 @@ export default class LambderResponseBuilder {
166
170
  return this.fileBase64(bodyBase64, mimeType || "", headers);
167
171
  };
168
172
 
169
- api<T>(
170
- {
171
- payload,
173
+ api<T=any>(
174
+ payload: T | null,
175
+ {
172
176
  versionExpired, sessionExpired, notAuthorized,
173
177
  message = null, errorMessage = null,
174
- }: LambderApiResponse<T>,
178
+ }: LambderApiResponseConfig = {
179
+ versionExpired: undefined, sessionExpired: undefined, notAuthorized: undefined,
180
+ message: null, errorMessage: null,
181
+ },
175
182
  headers?: Record<string, string|string[]>,
176
183
  ): LambderResolverResponse {
177
184
  return this.json({