lambder 1.0.62 → 1.0.63

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.
@@ -1,3 +1,4 @@
1
+ import { LambderApiResponse } from './LambderResponseBuilder';
1
2
  type VoidFunction = () => void | Promise<void>;
2
3
  type FetchTracker = {
3
4
  apiName: string;
@@ -47,7 +48,7 @@ export default class LambderCaller {
47
48
  fetchStartedHandler?: FetchStartEventHandler;
48
49
  fetchEndedHandler?: FetchEndEventHandler;
49
50
  });
50
- api<T>(apiName: string, payload?: any, headers?: Record<string, any>, options?: {
51
+ apiRaw<T>(apiName: string, payload?: any, headers?: Record<string, any>, options?: {
51
52
  versionExpiredHandler?: VoidFunction;
52
53
  sessionExpiredHandler?: VoidFunction;
53
54
  messageHandler?: MessageHandler;
@@ -56,6 +57,7 @@ export default class LambderCaller {
56
57
  errorHandler?: ErrorHandler;
57
58
  fetchStartedHandler?: FetchStartEventHandler;
58
59
  fetchEndedHandler?: FetchEndEventHandler;
59
- }): Promise<T | null>;
60
+ }): Promise<LambderApiResponse<T> | null>;
61
+ api<T>(...params: Parameters<typeof LambderCaller.prototype.apiRaw>): Promise<T | null>;
60
62
  }
61
63
  export {};
@@ -27,7 +27,7 @@ export default class LambderCaller {
27
27
  this.fetchEndedHandler = fetchEndedHandler;
28
28
  }
29
29
  ;
30
- async api(apiName, payload, headers, options) {
30
+ async apiRaw(apiName, payload, headers, options) {
31
31
  const fetchTracker = { apiName, done: false, fetchEndCalled: false };
32
32
  try {
33
33
  this.fetchTrackerList.push(fetchTracker);
@@ -93,7 +93,7 @@ export default class LambderCaller {
93
93
  if (data && data.errorMessage && this.errorMessageHandler) {
94
94
  await this.errorMessageHandler(data.errorMessage);
95
95
  }
96
- return data.payload ?? null;
96
+ return data;
97
97
  }
98
98
  catch (err) {
99
99
  const wrappedError = err instanceof Error ? err : new Error("Error: " + String(err));
@@ -112,4 +112,11 @@ export default class LambderCaller {
112
112
  }
113
113
  }
114
114
  ;
115
+ // Use the same type for api but adjust the return type
116
+ async api(...params) {
117
+ const result = await this.apiRaw(...params);
118
+ if (!result)
119
+ return null;
120
+ return result.payload ?? null;
121
+ }
115
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambder",
3
- "version": "1.0.62",
3
+ "version": "1.0.63",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -81,7 +81,7 @@ export default class LambderCaller {
81
81
 
82
82
  };
83
83
 
84
- async api<T>(apiName: string, payload?: any, headers?: Record<string, any>, options?: {
84
+ async apiRaw<T>(apiName: string, payload?: any, headers?: Record<string, any>, options?: {
85
85
  versionExpiredHandler?: VoidFunction,
86
86
  sessionExpiredHandler?: VoidFunction,
87
87
  messageHandler?: MessageHandler,
@@ -90,7 +90,7 @@ export default class LambderCaller {
90
90
  errorHandler?: ErrorHandler,
91
91
  fetchStartedHandler?: FetchStartEventHandler,
92
92
  fetchEndedHandler?: FetchEndEventHandler,
93
- }): Promise<T|null>{
93
+ }): Promise<LambderApiResponse<T>|null>{
94
94
  const fetchTracker: FetchTracker = { apiName, done: false, fetchEndCalled: false };
95
95
  try {
96
96
  this.fetchTrackerList.push(fetchTracker);
@@ -151,7 +151,7 @@ export default class LambderCaller {
151
151
  if(data && data.errorMessage && this.errorMessageHandler){
152
152
  await this.errorMessageHandler(data.errorMessage);
153
153
  }
154
- return data.payload ?? null;
154
+ return data;
155
155
  }catch(err){
156
156
  const wrappedError = err instanceof Error ? err : new Error("Error: " + String(err));
157
157
  fetchTracker.done = true;
@@ -166,4 +166,12 @@ export default class LambderCaller {
166
166
  return null;
167
167
  }
168
168
  };
169
+
170
+ // Use the same type for api but adjust the return type
171
+ async api<T>(...params: Parameters<typeof LambderCaller.prototype.apiRaw>): Promise<T|null> {
172
+ const result = await this.apiRaw<T>(...params);
173
+ if (!result) return null;
174
+ return result.payload ?? null;
175
+ }
176
+
169
177
  }