@dnax/core 0.3.1 → 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 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 = col?.access?.hasOwnProperty(action) || null;
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 ((col && action && colAccess) ?? false) {
191
- nextLifecyle = await col?.access[action]({
192
- session: sessionStorage(),
193
- action: action,
194
- c: c,
195
- isAuth: c.var?._v?.isAuth || false,
196
- rest: new useRest({ tenant_id: tenant_id }),
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
 
@@ -5,7 +5,24 @@ const asyncLocalStorage = new AsyncLocalStorage();
5
5
  const key = "___sessionStorage___";
6
6
  const stateKey = "____requestState____";
7
7
  const sessionStorage = () => ({
8
- get(): { state: object; _v: object; token: string } {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/types/index.ts CHANGED
@@ -163,6 +163,7 @@ export type sessionCtx = {
163
163
  token?: string;
164
164
  _v?: object;
165
165
  access?: {
166
+ allAction?: boolean;
166
167
  aggreate?: boolean;
167
168
  find?: boolean;
168
169
  findOne?: boolean;
@@ -175,7 +176,24 @@ export type sessionCtx = {
175
176
  upload?: boolean;
176
177
  };
177
178
  }) => void;
178
- get: () => { state: object; _v: object };
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
+ };
179
197
  };
180
198
 
181
199
  export type hooksCtx = (ctx: {