@dnax/core 0.3.2 → 0.3.4
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 +26 -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,16 @@ 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
|
+
session.get()?.access?.hasOwnProperty("allAction");
|
|
146
|
+
null;
|
|
142
147
|
let nextLifecyle: any = false;
|
|
143
148
|
|
|
144
149
|
// Middleware for apis
|
|
@@ -187,14 +192,26 @@ function HonoInstance(): typeof app {
|
|
|
187
192
|
session: sessionStorage(),
|
|
188
193
|
});
|
|
189
194
|
} else {
|
|
190
|
-
if (
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
if (col && action && colAccess) {
|
|
196
|
+
let basicNextAccess = false;
|
|
197
|
+
|
|
198
|
+
if (session.get().access.hasOwnProperty(action)) {
|
|
199
|
+
basicNextAccess = session.get().access[action];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (session.get().access.hasOwnProperty("allAction")) {
|
|
203
|
+
basicNextAccess = session.get().access["allAction"];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
nextLifecyle = basicNextAccess
|
|
207
|
+
? basicNextAccess
|
|
208
|
+
: await col?.access[action]({
|
|
209
|
+
session: sessionStorage(),
|
|
210
|
+
action: action,
|
|
211
|
+
c: c,
|
|
212
|
+
isAuth: c.var?._v?.isAuth || false,
|
|
213
|
+
rest: new useRest({ tenant_id: tenant_id }),
|
|
214
|
+
});
|
|
198
215
|
}
|
|
199
216
|
}
|
|
200
217
|
|
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: {
|