lambder 1.0.63 → 1.0.64
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/.vscode/settings.json +3 -1
- package/dist/Lambder.js +12 -3
- package/dist/LambderCaller.d.ts +2 -1
- package/dist/LambderCaller.js +5 -4
- package/package.json +1 -1
- package/src/Lambder.ts +10 -3
- package/src/LambderCaller.ts +6 -4
package/.vscode/settings.json
CHANGED
package/dist/Lambder.js
CHANGED
|
@@ -69,7 +69,8 @@ export default class Lambder {
|
|
|
69
69
|
testPatternMatch(pattern, path) {
|
|
70
70
|
return (match(pattern, { decode: decodeURIComponent }))(path) !== false;
|
|
71
71
|
}
|
|
72
|
-
async validateSession(
|
|
72
|
+
async validateSession(ctx) {
|
|
73
|
+
const { session, apiName, post, cookie } = ctx;
|
|
73
74
|
if (!session)
|
|
74
75
|
return false;
|
|
75
76
|
if (!session.userId || !session.userIdHash || !session.sessionHash || !session.csrfToken)
|
|
@@ -78,6 +79,14 @@ export default class Lambder {
|
|
|
78
79
|
return false;
|
|
79
80
|
if (session.expiresTimeStamp > Date.now())
|
|
80
81
|
return false;
|
|
82
|
+
if (apiName) {
|
|
83
|
+
if (!post.token)
|
|
84
|
+
return false;
|
|
85
|
+
if (post.token !== cookie.LMBDRTOKEN)
|
|
86
|
+
return false;
|
|
87
|
+
if (post.token !== session.csrfToken)
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
81
90
|
// Check DDB;
|
|
82
91
|
return false;
|
|
83
92
|
}
|
|
@@ -128,7 +137,7 @@ export default class Lambder {
|
|
|
128
137
|
(typeof condition === "function" && condition(ctx)) ||
|
|
129
138
|
(condition?.constructor == RegExp && condition.test(ctx.path)))),
|
|
130
139
|
actionFn: async (ctx, resolver) => {
|
|
131
|
-
const isSessionValid = this.validateSession(ctx
|
|
140
|
+
const isSessionValid = this.validateSession(ctx);
|
|
132
141
|
if (!isSessionValid)
|
|
133
142
|
throw new Error("Session not found");
|
|
134
143
|
if (typeof condition === "string") {
|
|
@@ -157,7 +166,7 @@ export default class Lambder {
|
|
|
157
166
|
(typeof apiName === "function" && apiName(ctx)) ||
|
|
158
167
|
(apiName?.constructor == RegExp && apiName.test(ctx.apiName))),
|
|
159
168
|
actionFn: async (ctx, resolver) => {
|
|
160
|
-
const isSessionValid = this.validateSession(ctx
|
|
169
|
+
const isSessionValid = this.validateSession(ctx);
|
|
161
170
|
if (!isSessionValid)
|
|
162
171
|
throw new Error("Session not found");
|
|
163
172
|
return await actionFn(ctx, resolver);
|
package/dist/LambderCaller.d.ts
CHANGED
|
@@ -48,7 +48,8 @@ export default class LambderCaller {
|
|
|
48
48
|
fetchStartedHandler?: FetchStartEventHandler;
|
|
49
49
|
fetchEndedHandler?: FetchEndEventHandler;
|
|
50
50
|
});
|
|
51
|
-
apiRaw<T>(apiName: string, payload?: any,
|
|
51
|
+
apiRaw<T>(apiName: string, payload?: any, options?: {
|
|
52
|
+
headers?: Record<string, any>;
|
|
52
53
|
versionExpiredHandler?: VoidFunction;
|
|
53
54
|
sessionExpiredHandler?: VoidFunction;
|
|
54
55
|
messageHandler?: MessageHandler;
|
package/dist/LambderCaller.js
CHANGED
|
@@ -27,7 +27,8 @@ export default class LambderCaller {
|
|
|
27
27
|
this.fetchEndedHandler = fetchEndedHandler;
|
|
28
28
|
}
|
|
29
29
|
;
|
|
30
|
-
async apiRaw(apiName, payload,
|
|
30
|
+
async apiRaw(apiName, payload, options) {
|
|
31
|
+
const headers = options?.headers;
|
|
31
32
|
const fetchTracker = { apiName, done: false, fetchEndCalled: false };
|
|
32
33
|
try {
|
|
33
34
|
this.fetchTrackerList.push(fetchTracker);
|
|
@@ -37,7 +38,7 @@ export default class LambderCaller {
|
|
|
37
38
|
activeFetchList: this.fetchTrackerList.filter(v => !v.done)
|
|
38
39
|
});
|
|
39
40
|
const version = this.apiVersion;
|
|
40
|
-
const token = Cookies.get("
|
|
41
|
+
const token = Cookies.get("LMBDRTOKEN") || "";
|
|
41
42
|
const siteHost = window.location.hostname;
|
|
42
43
|
let data = await fetch(this.apiPath, {
|
|
43
44
|
method: 'POST', mode: 'same-origin', cache: 'no-cache',
|
|
@@ -68,8 +69,8 @@ export default class LambderCaller {
|
|
|
68
69
|
return null;
|
|
69
70
|
}
|
|
70
71
|
if (data && data.sessionExpired) {
|
|
71
|
-
Cookies.set('
|
|
72
|
-
Cookies.set('
|
|
72
|
+
Cookies.set('LMBDRAUTHID', '', { expires: -1 });
|
|
73
|
+
Cookies.set('LMBDRTOKEN', '', { expires: -1 });
|
|
73
74
|
if (this.sessionExpiredHandler) {
|
|
74
75
|
await this.sessionExpiredHandler();
|
|
75
76
|
}
|
package/package.json
CHANGED
package/src/Lambder.ts
CHANGED
|
@@ -123,11 +123,18 @@ export default class Lambder {
|
|
|
123
123
|
return (match(pattern, { decode: decodeURIComponent }))(path) !== false;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
private async validateSession (
|
|
126
|
+
private async validateSession (ctx: RenderContext): Promise<boolean>{
|
|
127
|
+
const { session, apiName, post, cookie } = ctx;
|
|
127
128
|
if(!session) return false;
|
|
128
129
|
if(!session.userId || !session.userIdHash || !session.sessionHash || !session.csrfToken) return false;
|
|
129
130
|
if(!session.createdTimeStamp || !session.expiresTimeStamp) return false;
|
|
130
131
|
if(session.expiresTimeStamp > Date.now()) return false;
|
|
132
|
+
|
|
133
|
+
if(apiName){
|
|
134
|
+
if(!post.token) return false;
|
|
135
|
+
if(post.token !== cookie.LMBDRTOKEN) return false;
|
|
136
|
+
if(post.token !== session.csrfToken) return false;
|
|
137
|
+
}
|
|
131
138
|
// Check DDB;
|
|
132
139
|
return false;
|
|
133
140
|
};
|
|
@@ -183,7 +190,7 @@ export default class Lambder {
|
|
|
183
190
|
)
|
|
184
191
|
),
|
|
185
192
|
actionFn: async (ctx:RenderContext, resolver: Resolver) => {
|
|
186
|
-
const isSessionValid = this.validateSession(ctx
|
|
193
|
+
const isSessionValid = this.validateSession(ctx);
|
|
187
194
|
if(!isSessionValid) throw new Error("Session not found");
|
|
188
195
|
if(typeof condition === "string"){
|
|
189
196
|
ctx.pathParams = this.getPatternMatch(condition, ctx.path);
|
|
@@ -214,7 +221,7 @@ export default class Lambder {
|
|
|
214
221
|
(apiName?.constructor == RegExp && apiName.test(ctx.apiName))
|
|
215
222
|
),
|
|
216
223
|
actionFn: async (ctx:RenderContext, resolver: Resolver) => {
|
|
217
|
-
const isSessionValid = this.validateSession(ctx
|
|
224
|
+
const isSessionValid = this.validateSession(ctx);
|
|
218
225
|
if(!isSessionValid) throw new Error("Session not found");
|
|
219
226
|
return await actionFn(ctx, resolver);
|
|
220
227
|
}
|
package/src/LambderCaller.ts
CHANGED
|
@@ -81,7 +81,8 @@ export default class LambderCaller {
|
|
|
81
81
|
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
async apiRaw<T>(apiName: string, payload?: any,
|
|
84
|
+
async apiRaw<T>(apiName: string, payload?: any, options?: {
|
|
85
|
+
headers?: Record<string, any>
|
|
85
86
|
versionExpiredHandler?: VoidFunction,
|
|
86
87
|
sessionExpiredHandler?: VoidFunction,
|
|
87
88
|
messageHandler?: MessageHandler,
|
|
@@ -91,6 +92,7 @@ export default class LambderCaller {
|
|
|
91
92
|
fetchStartedHandler?: FetchStartEventHandler,
|
|
92
93
|
fetchEndedHandler?: FetchEndEventHandler,
|
|
93
94
|
}): Promise<LambderApiResponse<T>|null>{
|
|
95
|
+
const headers = options?.headers;
|
|
94
96
|
const fetchTracker: FetchTracker = { apiName, done: false, fetchEndCalled: false };
|
|
95
97
|
try {
|
|
96
98
|
this.fetchTrackerList.push(fetchTracker);
|
|
@@ -99,7 +101,7 @@ export default class LambderCaller {
|
|
|
99
101
|
activeFetchList: this.fetchTrackerList.filter(v=>!v.done)
|
|
100
102
|
});
|
|
101
103
|
const version = this.apiVersion;
|
|
102
|
-
const token = Cookies.get("
|
|
104
|
+
const token = Cookies.get("LMBDRTOKEN") || "";
|
|
103
105
|
const siteHost = window.location.hostname;
|
|
104
106
|
let data = await fetch(this.apiPath, {
|
|
105
107
|
method: 'POST', mode: 'same-origin', cache: 'no-cache',
|
|
@@ -128,8 +130,8 @@ export default class LambderCaller {
|
|
|
128
130
|
return null;
|
|
129
131
|
}
|
|
130
132
|
if(data && data.sessionExpired){
|
|
131
|
-
Cookies.set('
|
|
132
|
-
Cookies.set('
|
|
133
|
+
Cookies.set('LMBDRAUTHID', '', { expires: -1 });
|
|
134
|
+
Cookies.set('LMBDRTOKEN', '', { expires: -1 });
|
|
133
135
|
if(this.sessionExpiredHandler){
|
|
134
136
|
await this.sessionExpiredHandler();
|
|
135
137
|
}else if(this.errorHandler){
|