data-primals-engine 1.7.1 → 1.7.2

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.
Files changed (36) hide show
  1. package/README.md +160 -160
  2. package/client/package-lock.json +484 -175
  3. package/client/package.json +7 -4
  4. package/client/src/AssistantChat.jsx +1 -3
  5. package/client/src/DataLayout.jsx +19 -20
  6. package/client/src/DataTable.jsx +2 -2
  7. package/client/src/DocumentationPageLayout.scss +1 -1
  8. package/client/src/ViewSwitcher.jsx +1 -1
  9. package/client/vite.config.js +31 -30
  10. package/package.json +27 -17
  11. package/src/ai.jobs.js +135 -0
  12. package/src/constants.js +561 -545
  13. package/src/data.js +2 -0
  14. package/src/engine.js +50 -42
  15. package/src/modules/assistant/assistant.js +782 -763
  16. package/src/modules/assistant/constants.js +23 -16
  17. package/src/modules/assistant/providers.js +77 -37
  18. package/src/modules/bucket.js +4 -0
  19. package/src/modules/data/data.cluster.js +191 -0
  20. package/src/modules/data/data.core.js +11 -8
  21. package/src/modules/data/data.js +311 -311
  22. package/src/modules/data/data.operations.js +186 -106
  23. package/src/modules/data/data.relations.js +1 -0
  24. package/src/modules/data/data.replication.js +83 -0
  25. package/src/modules/data/data.routes.js +2183 -1879
  26. package/src/modules/mongodb.js +76 -73
  27. package/src/modules/user.js +7 -1
  28. package/src/modules/worker-script-runner.js +97 -0
  29. package/src/modules/workflow.js +177 -52
  30. package/src/packs.js +5701 -5701
  31. package/src/providers.js +298 -297
  32. package/test/assistant.test.js +207 -206
  33. package/test/data.integration.test.js +1425 -1416
  34. package/test/import_export.integration.test.js +210 -210
  35. package/test/workflow.actions.integration.test.js +487 -475
  36. package/test/workflow.integration.test.js +332 -329
package/src/data.js CHANGED
@@ -37,6 +37,8 @@ export function getUserHash(user) {
37
37
  if( isDemoUser(user) ){
38
38
  return user.username;
39
39
  }
40
+ if( user.hash )
41
+ return user.hash;
40
42
  return user ? (
41
43
  isLocalUser(user) ? getObjectHash({id: 'LOCAL_USER'+user._user+user.username}) : getObjectHash({id: user.hash})
42
44
  ) : 0;
package/src/engine.js CHANGED
@@ -1,9 +1,18 @@
1
+ import path from "node:path";
2
+ import {fileURLToPath} from 'node:url';
3
+ import process from "process";
4
+ // Charger les variables d'environnement depuis le fichier .env
5
+ import dotenv from "dotenv";
6
+
7
+ // Charger le .env depuis la racine du projet appelant, et non depuis la lib.
8
+ dotenv.config({ path: path.resolve(process.cwd(), '.env') });
9
+
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
1
11
  import {GameObject, Logger} from "./gameObject.js";
2
12
  import {Config} from "./config.js";
3
13
  import fs from 'node:fs'
4
14
  import express from 'express'
5
15
  import {MongoClient as InternalMongoClient} from 'mongodb'
6
- import process from "process";
7
16
  import {
8
17
  cookiesSecret,
9
18
  databasePoolSize,
@@ -19,19 +28,13 @@ import formidableMiddleware from 'express-formidable';
19
28
  import sirv from "sirv";
20
29
  import * as tls from "node:tls";
21
30
  import {Event} from "./events.js";
22
- import path from "node:path";
23
- import { fileURLToPath, pathToFileURL } from 'node:url';
31
+ import { pathToFileURL } from 'node:url';
24
32
  import {validateModelStructure} from "./modules/data/data.validation.js";
25
33
  import { setSafeRegex } from "./filter.js";
26
34
  import safeRegexCallback from "safe-regex";
27
35
  import {createModel, deleteModels, getModels, installAllPacks} from "./modules/data/data.operations.js";
28
36
  // Constants
29
37
 
30
- // On définit __dirname pour obtenir le chemin absolu du répertoire courant,
31
- // ce qui est la méthode standard en ES Modules.
32
- const __filename = fileURLToPath(import.meta.url);
33
- const __dirname = path.dirname(__filename);
34
-
35
38
  let dbName = Config.Get('dbName', dbNameBase);
36
39
  let caFile, certFile, keyFile;
37
40
  try {
@@ -53,49 +56,54 @@ const secureContext = tls.createSecureContext({
53
56
 
54
57
  export const dbUrl = process.env.CI ? 'mongodb://mongodb:27017' : (process.env.MONGO_DB_URL || 'mongodb://127.0.0.1:27017');
55
58
 
56
- const isTlsActive = !(!process.env.TLS || ["0", "false"].includes(process.env.TLS.toLowerCase()));
57
-
58
- const clientOptions = {
59
- maxPoolSize: databasePoolSize
60
- };
61
-
62
- // We add TLS options if enabled
63
- if (isTlsActive) {
64
- clientOptions.tls = true;
65
-
66
- // is mTLS ? (client certificate required instead of password)
67
- if (process.env.CERT) {
68
- clientOptions.secureContext = tls.createSecureContext({
69
- ca: fs.readFileSync(process.env.CA_CERT),
70
- cert: fs.readFileSync(process.env.CERT),
71
- key: fs.readFileSync(process.env.CERT_KEY)
72
- });
73
- }else {
74
- // Path to the authority certificate
75
- if (process.env.CA_CERT) {
76
- clientOptions.tlsCAFile = process.env.CA_CERT;
59
+ export const InitMongo = () => {
60
+ const isTlsActive = !(!process.env.TLS || ["0", "false"].includes(process.env.TLS.toLowerCase()));
61
+ const clientOptions = {
62
+ maxPoolSize: databasePoolSize,
63
+ authSource: 'admin'
64
+ };
65
+ if (isTlsActive) {
66
+ clientOptions.tls = true;
67
+ console.log("TLS ACTIVE");
68
+ // is mTLS ? (client certificate required instead of password)
69
+ if (process.env.CERT) {
70
+ clientOptions.secureContext = tls.createSecureContext({
71
+ ca: fs.readFileSync(process.env.CA_CERT),
72
+ cert: fs.readFileSync(process.env.CERT),
73
+ key: fs.readFileSync(process.env.CERT_KEY)
74
+ });
75
+ }else {
76
+ // Path to the authority certificate
77
+ if (process.env.CA_CERT) {
78
+ clientOptions.tlsCAFile = process.env.CA_CERT;
79
+ }
80
+ // Path to the certificate key
81
+ if (process.env.CERT_KEY) {
82
+ clientOptions.tlsCertificateKeyFile = process.env.CERT_KEY;
83
+ }
77
84
  }
78
- // Path to the certificate key
79
- if (process.env.CERT_KEY) {
80
- clientOptions.tlsCertificateKeyFile = process.env.CERT_KEY;
85
+ if (tlsAllowInvalidCertificates) {
86
+ clientOptions.tlsAllowInvalidCertificates = true;
87
+ console.warn("🚨 [SECURITY WARNING] tlsAllowInvalidCertificates is ON. Server certificate will not be validated.");
81
88
  }
89
+ if (tlsAllowInvalidHostnames) {
90
+ clientOptions.tlsAllowInvalidHostnames = true;
91
+ console.warn("🚨 [SECURITY WARNING] tlsAllowInvalidHostnames is ON. Server hostname will not be validated.");
92
+ }
93
+ }else{
94
+ console.log("🚨[SEC] TLS INACTIVE", dbUrl, clientOptions);
82
95
  }
83
- if (tlsAllowInvalidCertificates) {
84
- clientOptions.tlsAllowInvalidCertificates = true;
85
- console.warn("🚨 [SECURITY WARNING] tlsAllowInvalidCertificates is ON. Server certificate will not be validated.");
86
- }
87
- if (tlsAllowInvalidHostnames) {
88
- clientOptions.tlsAllowInvalidHostnames = true;
89
- console.warn("🚨 [SECURITY WARNING] tlsAllowInvalidHostnames is ON. Server hostname will not be validated.");
90
- }
96
+ return new InternalMongoClient(dbUrl, clientOptions);
91
97
  }
92
98
 
93
- export const MongoClient = new InternalMongoClient(dbUrl, clientOptions);
94
-
99
+ export let MongoClient = null;
95
100
 
96
101
  // Database Name
97
102
  export const MongoDatabase = () => {
98
103
  let dbName = Config.Get('dbName', dbNameBase);
104
+ if( !MongoClient)
105
+ MongoClient = InitMongo();
106
+ console.log('SELECTING ' + dbName + " database.");
99
107
  return MongoClient.db(dbName);
100
108
  }
101
109