@dnax/core 0.3.2 → 0.3.3
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/app/hono.ts +17 -9
- package/lib/asyncLocalStorage.ts +19 -1
- package/package.json +1 -1
- package/types/index.ts +18 -1
package/app/hono.ts
CHANGED
|
@@ -134,11 +134,15 @@ function HonoInstance(): typeof app {
|
|
|
134
134
|
// access controle for api
|
|
135
135
|
app.use(cleanPath(API_PATH), async (c, next) => {
|
|
136
136
|
let session = sessionStorage();
|
|
137
|
+
|
|
137
138
|
const { action, collection, cleanDeep, useCache } = c.req.query() as Q;
|
|
138
139
|
|
|
139
140
|
let tenant_id = c.var["tenant-id"];
|
|
140
141
|
let col = getCollection(collection, tenant_id);
|
|
141
|
-
let colAccess =
|
|
142
|
+
let colAccess =
|
|
143
|
+
col?.access?.hasOwnProperty(action) ||
|
|
144
|
+
session.get()?.access?.hasOwnProperty(action) ||
|
|
145
|
+
null;
|
|
142
146
|
let nextLifecyle: any = false;
|
|
143
147
|
|
|
144
148
|
// Middleware for apis
|
|
@@ -187,14 +191,18 @@ function HonoInstance(): typeof app {
|
|
|
187
191
|
session: sessionStorage(),
|
|
188
192
|
});
|
|
189
193
|
} else {
|
|
190
|
-
if (
|
|
191
|
-
|
|
192
|
-
session
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
if (col && action && colAccess) {
|
|
195
|
+
let basicNextAccess = session?.get()?.access?.hasOwnProperty(action)
|
|
196
|
+
? session?.get()?.access?.[action]
|
|
197
|
+
: false;
|
|
198
|
+
nextLifecyle =
|
|
199
|
+
(await col?.access[action]({
|
|
200
|
+
session: sessionStorage(),
|
|
201
|
+
action: action,
|
|
202
|
+
c: c,
|
|
203
|
+
isAuth: c.var?._v?.isAuth || false,
|
|
204
|
+
rest: new useRest({ tenant_id: tenant_id }),
|
|
205
|
+
})) || basicNextAccess;
|
|
198
206
|
}
|
|
199
207
|
}
|
|
200
208
|
|
package/lib/asyncLocalStorage.ts
CHANGED
|
@@ -5,7 +5,24 @@ const asyncLocalStorage = new AsyncLocalStorage();
|
|
|
5
5
|
const key = "___sessionStorage___";
|
|
6
6
|
const stateKey = "____requestState____";
|
|
7
7
|
const sessionStorage = () => ({
|
|
8
|
-
get(): {
|
|
8
|
+
get(): {
|
|
9
|
+
state: object;
|
|
10
|
+
_v: object;
|
|
11
|
+
token: string;
|
|
12
|
+
access: {
|
|
13
|
+
allAction?: boolean;
|
|
14
|
+
aggreate?: boolean;
|
|
15
|
+
find?: boolean;
|
|
16
|
+
findOne?: boolean;
|
|
17
|
+
insertOne?: boolean;
|
|
18
|
+
insertMany?: boolean;
|
|
19
|
+
updateOne?: boolean;
|
|
20
|
+
updateMany?: boolean;
|
|
21
|
+
deleteOne?: boolean;
|
|
22
|
+
deleteMany?: boolean;
|
|
23
|
+
upload?: boolean;
|
|
24
|
+
};
|
|
25
|
+
} {
|
|
9
26
|
let store = asyncLocalStorage.getStore() as InstanceType<typeof Map>;
|
|
10
27
|
return (
|
|
11
28
|
(store.get(key) as {
|
|
@@ -61,6 +78,7 @@ const sessionStorage = () => ({
|
|
|
61
78
|
state: input.state,
|
|
62
79
|
access: input?.access || {},
|
|
63
80
|
});
|
|
81
|
+
|
|
64
82
|
store.set(key, {
|
|
65
83
|
...this.get(),
|
|
66
84
|
state: {
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -176,7 +176,24 @@ export type sessionCtx = {
|
|
|
176
176
|
upload?: boolean;
|
|
177
177
|
};
|
|
178
178
|
}) => void;
|
|
179
|
-
get: () => {
|
|
179
|
+
get: () => {
|
|
180
|
+
state: object;
|
|
181
|
+
_v: object;
|
|
182
|
+
access: {
|
|
183
|
+
allAction?: boolean;
|
|
184
|
+
aggreate?: boolean;
|
|
185
|
+
find?: boolean;
|
|
186
|
+
findOne?: boolean;
|
|
187
|
+
insertOne?: boolean;
|
|
188
|
+
insertMany?: boolean;
|
|
189
|
+
updateOne?: boolean;
|
|
190
|
+
updateMany?: boolean;
|
|
191
|
+
deleteOne?: boolean;
|
|
192
|
+
deleteMany?: boolean;
|
|
193
|
+
upload?: boolean;
|
|
194
|
+
};
|
|
195
|
+
token: string;
|
|
196
|
+
};
|
|
180
197
|
};
|
|
181
198
|
|
|
182
199
|
export type hooksCtx = (ctx: {
|