@dnax/core 0.74.2 → 0.74.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 CHANGED
@@ -243,6 +243,7 @@ function HonoInstance(): typeof app {
243
243
  if (col && action && colAccess) {
244
244
  let basicNextAccess = false;
245
245
 
246
+ // get permission by role
246
247
  if (getPermission(session.get()?.role, tenant_id)) {
247
248
  basicNextAccess = checkPermission(
248
249
  session.get()?.role,
@@ -258,7 +259,8 @@ function HonoInstance(): typeof app {
258
259
 
259
260
  nextLifecyle = basicNextAccess;
260
261
 
261
- if (col?.access?.hasOwnProperty(action)) {
262
+ // si pas de role alors checking les permissions par access
263
+ if (col?.access?.hasOwnProperty(action) && !basicNextAccess) {
262
264
  nextLifecyle = await col?.access[action]({
263
265
  session: sessionStorage(),
264
266
  action: action,
@@ -901,7 +903,7 @@ function HonoInstance(): typeof app {
901
903
  }
902
904
 
903
905
  app.onError((err, c) => {
904
- console.error(err?.message);
906
+ // console.error(err?.message);
905
907
  c.status(500);
906
908
  return c.json({ message: err?.message });
907
909
  });
@@ -2589,13 +2589,15 @@ class useRest {
2589
2589
  this.#session?.startTransaction();
2590
2590
  }
2591
2591
  } catch (err: any) {
2592
- if (!options?.silent) {
2592
+ if (options?.silent) {
2593
2593
  consola.error(err?.message | err);
2594
+ } else {
2595
+ throw new Error(err?.message || err);
2594
2596
  }
2595
2597
  }
2596
2598
  }
2597
2599
 
2598
- async abortTransaction() {
2600
+ async abortTransaction(options?: { silent?: boolean }) {
2599
2601
  return new Promise(async (resolve, reject) => {
2600
2602
  try {
2601
2603
  if (this.#session) {
@@ -2603,12 +2605,16 @@ class useRest {
2603
2605
  return resolve(true);
2604
2606
  }
2605
2607
  } catch (err: any) {
2606
- return reject(err?.message || err);
2608
+ if (options?.silent) {
2609
+ console.error(err?.message || err);
2610
+ } else {
2611
+ return reject(err?.message || err);
2612
+ }
2607
2613
  }
2608
2614
  });
2609
2615
  }
2610
2616
 
2611
- async endSession() {
2617
+ async endSession(options?: { silent?: boolean }) {
2612
2618
  return new Promise(async (resolve, reject) => {
2613
2619
  try {
2614
2620
  if (this.#session) {
@@ -2617,12 +2623,19 @@ class useRest {
2617
2623
  }
2618
2624
  return resolve(true);
2619
2625
  } catch (err: any) {
2620
- return reject(err?.message || err);
2626
+ if (options?.silent) {
2627
+ console.error(err?.message || err);
2628
+ } else {
2629
+ return reject(err?.message || err);
2630
+ }
2621
2631
  }
2622
2632
  });
2623
2633
  }
2624
2634
 
2625
- async commitTransaction(options?: { closeSession?: boolean }) {
2635
+ async commitTransaction(options?: {
2636
+ closeSession?: boolean;
2637
+ silent?: boolean;
2638
+ }) {
2626
2639
  return new Promise(async (resolve, reject) => {
2627
2640
  if (this.#session) {
2628
2641
  await this.#session
@@ -2636,7 +2649,11 @@ class useRest {
2636
2649
  resolve(true);
2637
2650
  })
2638
2651
  .catch((err: any) => {
2639
- reject(err?.message || err);
2652
+ if (options?.silent) {
2653
+ console.error(err?.message || err);
2654
+ } else {
2655
+ return reject(err?.message || err);
2656
+ }
2640
2657
  });
2641
2658
  }
2642
2659
  });
@@ -222,7 +222,7 @@ function toBson<T>(
222
222
  }
223
223
 
224
224
  // updateMany
225
- if (options?.action == "updateMany") {
225
+ if (options?.action == "updateMany" && Array.isArray(data)) {
226
226
  data?.map((d) => {
227
227
  d.updatedAt = new Date();
228
228
  });
package/index.ts CHANGED
@@ -6,6 +6,7 @@ import * as v from "joi";
6
6
  import { $ } from "bun";
7
7
  import define from "./define";
8
8
  import * as utils from "./utils";
9
+ import { app } from "./app/hono";
9
10
  import { FilesystemSftpAdapter, MinioAdapter } from "./lib/media";
10
11
  import { crypt } from "./lib/crypto";
11
12
  import { contextStorage } from "./lib/asyncLocalStorage";
@@ -21,6 +22,7 @@ const Adapter = {
21
22
  };
22
23
 
23
24
  export {
25
+ app,
24
26
  runApp,
25
27
  define,
26
28
  utils,
@@ -0,0 +1,60 @@
1
+ import { useRest } from "../../driver/mongo/rest";
2
+ import type { sessionCtx } from "../../types";
3
+ import type { socketIoType } from "../../lib/socket/instance";
4
+ type ActivityType = {
5
+ name: string;
6
+ exec: (ctx: {
7
+ input: any;
8
+ rest: InstanceType<typeof useRest>;
9
+ session: sessionCtx;
10
+ isAuth: boolean;
11
+ io: socketIoType;
12
+ }) => Promise<{ output: any; error: any; success: boolean }>;
13
+ };
14
+
15
+ type workflowConfig = {
16
+ name: string;
17
+ activities: ActivityType[];
18
+ };
19
+
20
+ class Workflow {
21
+ private config: workflowConfig;
22
+ constructor(config: workflowConfig) {
23
+ this.config = config;
24
+ }
25
+ async run(context: {
26
+ rest: InstanceType<typeof useRest>;
27
+ session: sessionCtx;
28
+ isAuth: boolean;
29
+ io: socketIoType;
30
+ input: any;
31
+ }) {
32
+ let l = this.config.activities.length || 0;
33
+ let index = 0;
34
+ if (index < l) {
35
+ let activity = this.config.activities[index];
36
+ let r = {
37
+ output: null,
38
+ error: null,
39
+ success: false,
40
+ };
41
+ if (index > 0) {
42
+ r = await activity.exec({
43
+ input: context.input,
44
+ rest: context.rest,
45
+ session: context.session,
46
+ isAuth: context.isAuth,
47
+ io: context.io,
48
+ });
49
+ } else {
50
+ await activity.exec({
51
+ input: r.output,
52
+ rest: context.rest,
53
+ session: context.session,
54
+ isAuth: context.isAuth,
55
+ io: context.io,
56
+ });
57
+ }
58
+ }
59
+ }
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.74.2",
3
+ "version": "0.74.4",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {},