aotrautils-srv 0.0.1930 → 0.0.1933

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.
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- /*utils COMMONS library associated with aotra version : «1_29072022-2359 (26/07/2026-17:25:47)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (02/08/2026-00:11:14)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -5195,7 +5195,7 @@ window.getPathFileName=(path, fileSeparator="/", removeExtension=false)=>{
5195
5195
  // ======================== Timeout ========================
5196
5196
 
5197
5197
  // CAUTION : This is not a routine, but a single-use timeout !
5198
- window.MonoThreadedTimeout=class {
5198
+ window.MonoThreadedTimeout=class MonoThreadedTimeout{
5199
5199
  constructor(actuator, delayMillis){
5200
5200
  this.actuator=actuator;
5201
5201
  }
@@ -5309,7 +5309,7 @@ window.getMonoThreadedRoutine=function(actuator, refreshMillis=null, startDepend
5309
5309
  }
5310
5310
 
5311
5311
 
5312
- window.MonoThreadedGoToGoal=class {
5312
+ window.MonoThreadedGoToGoal=class MonoThreadedGoToGoal{
5313
5313
  constructor(actuator,actualValue,goalValue,refreshMillis=null,totalTimeMillis=1000,mode="linear"){
5314
5314
 
5315
5315
  this.actuator=actuator;
@@ -5470,7 +5470,7 @@ window.AOTRAUTILS_LIB_IS_LOADED=true;
5470
5470
 
5471
5471
 
5472
5472
 
5473
- /*utils AI library associated with aotra version : «1_29072022-2359 (26/07/2026-17:25:47)»*/
5473
+ /*utils AI library associated with aotra version : «1_29072022-2359 (02/08/2026-00:11:14)»*/
5474
5474
  /*-----------------------------------------------------------------------------*/
5475
5475
 
5476
5476
 
@@ -5573,7 +5573,7 @@ window.LLMAPIClient=class LLMAPIClient{
5573
5573
  const parameters=getAPIRequestParameters(messages);
5574
5574
 
5575
5575
  return new Promise((resolve,reject)=>{
5576
- window.performHTTPRequest(this.apiURL, "POST", headers, parameters, true).then((responseObj)=>{
5576
+ performHTTPRequest(this.apiURL, "POST", headers, parameters, true).then((responseObj)=>{
5577
5577
  const responseData=responseObj.responseData;
5578
5578
  const data=responseData;
5579
5579
 
@@ -5730,7 +5730,7 @@ window.getLLMAPIClient=(modelName, apiURL, agentRole, defaultPrompt, llmProvider
5730
5730
 
5731
5731
 
5732
5732
 
5733
- /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (26/07/2026-17:25:47)»*/
5733
+ /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (02/08/2026-00:11:14)»*/
5734
5734
  /*-----------------------------------------------------------------------------*/
5735
5735
 
5736
5736
 
@@ -5771,7 +5771,7 @@ if(typeof(window)==="undefined") window=global;
5771
5771
 
5772
5772
  // New implementation :
5773
5773
 
5774
- window.AORTACClientCell=class{
5774
+ window.AORTACClientCell=class AORTACClientCell{
5775
5775
 
5776
5776
  constructor(serverCellOrigin, model, view, isNodeContext=true){
5777
5777
 
@@ -6142,7 +6142,7 @@ window.AORTAC_OUTCOMING_SERVERS_CONNECTION_GLOBAL_TIMEOUT=30000;
6142
6142
  window.AORTAC_SERVER_CELL_PERIODICAL_CONNECTIVITY_CHECK_MILLIS=2000;
6143
6143
 
6144
6144
 
6145
- window.AORTACServerCell=class{
6145
+ window.AORTACServerCell=class AORTACServerCell{
6146
6146
 
6147
6147
  constructor(quorumNumber=1, selfOrigin, outcomingCellsOrigins, model, controller, sslConfig={/*OPTIONAL*/certPath:null,/*OPTIONAL*/keyPath:null}){
6148
6148
 
@@ -7728,7 +7728,7 @@ window.crypto=require("node:crypto");
7728
7728
 
7729
7729
  const FILE_ENCODING="utf8";
7730
7730
 
7731
- const ADD_CORS_HEADER=true;
7731
+ const ADD_CORS_HEADER_BY_DEFAULT=true;
7732
7732
 
7733
7733
 
7734
7734
  // DEBUG
@@ -7740,99 +7740,122 @@ if(typeof(require)!=="undefined" && typeof(window.fs)==="undefined" ){
7740
7740
  }
7741
7741
 
7742
7742
 
7743
- // Nodejs filesystem utils :
7744
- if(typeof(window.fs)==="undefined"){
7745
- // TRACE
7746
- console.log("WARN : Could not find the nodejs dependency «fs», aborting persister setup.");
7747
- window.getPersister=()=>{ return null; };
7748
-
7749
- }else{
7750
-
7743
+
7744
+ window.Persister=class Persister{
7751
7745
 
7752
- window.getPersister=function(dataDirPath,prefix=""){
7746
+ constructor(dataDirPath="./", prefix="", createDirectoryIfNotExists=false){
7747
+ this.dataDirPath=dataDirPath;
7748
+ this.prefix=prefix;
7749
+ this.createDirectoryIfNotExists=createDirectoryIfNotExists;
7753
7750
 
7754
- let self={
7751
+ }
7752
+
7753
+ //FILE_NAME_PATTERN:"data.clientId.repositoryName.json",
7754
+ /*private*/getPath(clientId="noclient", repositoryName="norepository"){
7755
7755
 
7756
- dataDirPath:dataDirPath,
7757
- prefix:prefix,
7758
-
7759
- //FILE_NAME_PATTERN:"data.clientId.repositoryName.json",
7760
- /*private*/getPath:function(clientId="noclient", repositoryName="norepository"){
7761
- // let path=self.FILE_NAME_PATTERN.replace(new RegExp("@clientId@","g"),clientId);
7762
- let path=`${self.dataDirPath}`
7763
- + (blank(self.prefix)?"":(self.prefix+"."))
7764
- +`${clientId}.${repositoryName}.json`;
7765
- return path;
7766
- },
7767
-
7768
- readTreeObjectFromFile:function(clientId="noclient", repositoryName="norepository", keepClassName=false){
7769
-
7770
- let path=self.getPath(clientId,repositoryName);
7771
- let resultFlat=null;
7756
+ const self=this;
7772
7757
 
7773
- try{
7758
+ // let path=self.FILE_NAME_PATTERN.replace(new RegExp("@clientId@","g"),clientId);
7759
+ let path=`${self.dataDirPath}`
7760
+ + (blank(self.prefix)?"":(self.prefix+"."))
7761
+ +`${clientId}.${repositoryName}.json`;
7762
+ return path;
7763
+ }
7774
7764
 
7775
- resultFlat=window.fs.readFileSync(path, FILE_ENCODING);
7776
-
7777
- }catch(error){
7778
- // TRACE
7779
- console.log("ERROR : Could not read file «"+path+"».");
7765
+ /*private*/createDirectoryIfNecessary(path){
7766
+ if(!fileExists(path) && this.createDirectoryIfNotExists){
7767
+ // TRACE
7768
+ lognow(`WARN : Directory «${path}» does not exist. We will create it.`);
7769
+ createDirectory(path);
7770
+ }
7771
+ }
7772
+
7773
+ readTreeObjectFromFile(clientId="noclient", repositoryName="norepository", keepClassName=false){
7774
+ const self=this;
7775
+
7776
+ let resultFlat=null;
7777
+ let path=self.getPath(clientId, repositoryName);
7778
+ this.createDirectoryIfNecessary(path);
7780
7779
 
7781
- return null;
7782
- }
7783
-
7784
-
7785
- let resultData={};
7786
-
7787
- // 1)
7788
- if(!empty(resultFlat)) resultData=parseJSON(resultFlat);
7789
-
7790
- // 2)
7791
- if(!empty(resultData) && isFlatMap(resultData)){
7792
- // CAUTION : We have to keep the type information, here too ! (in the sub-objects)
7793
- resultData=getAsTreeStructure(resultData, keepClassName);
7794
- }
7795
-
7796
- return resultData;
7797
- },
7780
+
7781
+ try{
7798
7782
 
7783
+ resultFlat=window.fs.readFileSync(path, FILE_ENCODING);
7799
7784
 
7800
- saveDataToFileForClient:function(clientId,repositoryName,dataFlatForClient,forceKeepUnflatten=false,doOnSuccess=null){
7801
-
7802
- if(!empty(dataFlatForClient) && !isFlatMap(dataFlatForClient) && !forceKeepUnflatten){
7803
- dataFlatForClient=getAsFlatStructure(dataFlatForClient);
7804
- }
7805
-
7806
- // reserved characters : -/\^$*+?.()|[]{}
7807
- // CANNOT USE stringifyObject(...) function because we are in a common, lower-level library !
7808
- let dataFlatStr=stringifyObject(dataFlatForClient)
7809
- // We «aerate» the produced JSON :
7810
- .replace(/":[\w]*\{/gim,"\":{\n").replace(/,"/gim,",\n\"")
7811
- // ...except for inline, escaped JSON string representations :
7812
- .replace(/\\\":[\w]*\{\n/gim,"\\\":{");
7813
- // NO : .replace(/}/gim,"}\n");
7814
-
7815
-
7816
- let path=self.getPath(clientId,repositoryName);
7817
- window.fs.writeFile(path, dataFlatStr, FILE_ENCODING, (error) => {
7818
- if(error){
7819
- // TRACE
7820
- console.log("ERROR : Could not write file «"+path+"»:",error);
7821
- throw error;
7822
- }
7823
- if(doOnSuccess) doOnSuccess(dataFlatForClient);
7824
- });
7825
- }
7826
-
7827
- };
7785
+ }catch(error){
7786
+ // TRACE
7787
+ console.log("ERROR : Could not read file «"+path+"».");
7788
+
7789
+ return null;
7790
+ }
7828
7791
 
7829
7792
 
7830
- return self;
7831
- };
7793
+ let resultData={};
7794
+
7795
+ // 1)
7796
+ if(!empty(resultFlat)) resultData=parseJSON(resultFlat);
7797
+
7798
+ // 2)
7799
+ if(!empty(resultData) && isFlatMap(resultData)){
7800
+ // CAUTION : We have to keep the type information, here too ! (in the sub-objects)
7801
+ resultData=getAsTreeStructure(resultData, keepClassName);
7802
+ }
7803
+
7804
+ return resultData;
7805
+ }
7806
+
7832
7807
 
7808
+ saveDataToFileForClient(clientId, repositoryName, dataFlatForClient, forceKeepUnflatten=false, doOnSuccess=null){
7809
+ const self=this;
7810
+
7811
+ if(!empty(dataFlatForClient) && !isFlatMap(dataFlatForClient) && !forceKeepUnflatten){
7812
+ dataFlatForClient=getAsFlatStructure(dataFlatForClient);
7813
+ }
7814
+
7815
+ // reserved characters : -/\^$*+?.()|[]{}
7816
+ // CANNOT USE stringifyObject(...) function because we are in a common, lower-level library !
7817
+ let dataFlatStr=stringifyObject(dataFlatForClient)
7818
+ // We «aerate» the produced JSON :
7819
+ .replace(/":[\w]*\{/gim,"\":{\n").replace(/,"/gim,",\n\"")
7820
+ // ...except for inline, escaped JSON string representations :
7821
+ .replace(/\\\":[\w]*\{\n/gim,"\\\":{");
7822
+ // NO : .replace(/}/gim,"}\n");
7823
+
7824
+
7825
+ let path=self.getPath(clientId, repositoryName);
7826
+ this.createDirectoryIfNecessary(path);
7827
+
7828
+ window.fs.writeFile(path, dataFlatStr, FILE_ENCODING, (error) => {
7829
+ if(error){
7830
+ // TRACE
7831
+ console.log("ERROR : Could not write file «"+path+"»:",error);
7832
+ throw error;
7833
+ }
7834
+ if(doOnSuccess) doOnSuccess(dataFlatForClient);
7835
+ });
7836
+ }
7837
+
7838
+
7833
7839
  }
7834
7840
 
7835
7841
 
7842
+
7843
+
7844
+
7845
+
7846
+
7847
+ // Nodejs filesystem utils :
7848
+ if(typeof(window.fs)==="undefined"){
7849
+ // TRACE
7850
+ console.log("WARN : Could not find the nodejs dependency «fs», aborting persister setup.");
7851
+ window.getPersister=()=>{ return null; };
7852
+ }else{
7853
+ window.getPersister=function(dataDirPath, prefix="", createDirectoryIfNotExists=false){
7854
+ return new Persister(dataDirPath, prefix, createDirectoryIfNotExists);
7855
+ };
7856
+ }
7857
+
7858
+ // Also handles directories !
7836
7859
  window.fileExists=(filePath)=>{
7837
7860
  if(typeof(window.fs)=="undefined"){
7838
7861
  // TRACE
@@ -7842,7 +7865,18 @@ window.fileExists=(filePath)=>{
7842
7865
  return window.fs.existsSync(filePath);
7843
7866
  };
7844
7867
 
7845
-
7868
+ window.createDirectory=(dirPath)=>{
7869
+ if(typeof(window.fs)=="undefined"){
7870
+ // TRACE
7871
+ lognow("ERROR : «fs» node dependency is not available ! Cannot create directory at path «"+dirPath+"».");
7872
+ return;
7873
+ }
7874
+ try {
7875
+ fs.mkdirSync(dirPath, { recursive: true });
7876
+ } catch (err) {
7877
+ console.error("Error creating directory:", err);
7878
+ }
7879
+ }
7846
7880
 
7847
7881
  // Nodejs server launching helper functions :
7848
7882
  //Networking management :
@@ -8290,7 +8324,8 @@ window.WebsocketImplementation={
8290
8324
  };
8291
8325
 
8292
8326
 
8293
- window.launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, doOnConnectionLost=null, /*OPTIONAL*/sslOptions=null, httpHandlerParam=null, addCORSHeader=ADD_CORS_HEADER){
8327
+ window.launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, doOnConnectionLost=null, /*OPTIONAL*/sslOptions=null, httpHandlerParam=null,
8328
+ addCORSHeader=ADD_CORS_HEADER_BY_DEFAULT){
8294
8329
 
8295
8330
  const EXCLUDED_FILENAMES_PARTS=[".keyHash.",".pem"];
8296
8331
 
@@ -8636,7 +8671,7 @@ window.initNodeServerInfrastructureWrapper=function(doOnClientConnection=null, d
8636
8671
 
8637
8672
  // ========================= UTILITY SERVERSIDE METHODS : =========================
8638
8673
 
8639
- window.ListManager=class{
8674
+ window.ListManager=class ListManager{
8640
8675
 
8641
8676
  constructor(config){
8642
8677
  this.config=config;
@@ -8806,7 +8841,9 @@ window.getListManager=function(config){
8806
8841
  // NO : IN A NODE CONTEXT WITH require("...") WILL RESULT IN AN UNDEFINED FUNCTION ERROR !!!
8807
8842
  // function performHTTPRequest(...){...
8808
8843
  // USE THIS INSTEAD :
8809
- window.performHTTPRequest=function(completeURL, httpMethod="GET", headers={}, requestBodyOrNamedArgs=null, isNodeContext=false, addCORSHeader=ADD_CORS_HEADER){
8844
+ window.performHTTPRequest=function(completeURL, httpMethod="GET", headers={}, requestBodyOrNamedArgs=null, isNodeContext=false,
8845
+ addCORSHeader=ADD_CORS_HEADER_BY_DEFAULT,
8846
+ allowSelfSignedCerts=false/*RECOMMENDED VALUE, TRY NOT TO SET IT TO «true» !!!*/){
8810
8847
 
8811
8848
  // Body
8812
8849
  let requestBodyOrNamedArgsStr=null;
@@ -8856,12 +8893,19 @@ window.performHTTPRequest=function(completeURL, httpMethod="GET", headers={}, re
8856
8893
  // TRACE
8857
8894
  lognow("INFO : We are not running in a browser context (isNodeContext:"+isNodeContext+";typeof(require):"+(typeof(require))+"). Using browser library.");
8858
8895
 
8896
+ const options={
8897
+ method: httpMethod,
8898
+ headers: headers,
8899
+ body: body,
8900
+ };
8901
+
8902
+
8903
+ if(allowSelfSignedCerts)
8904
+ options.rejectUnauthorized=true;
8905
+
8906
+
8859
8907
  return new Promise((resolve,reject)=>{
8860
- fetch(completeURL, {
8861
- method: httpMethod,
8862
- headers: headers,
8863
- body: body,
8864
- })
8908
+ fetch(completeURL, options)
8865
8909
  // STRANGE : DOES NOT WORK !!:
8866
8910
  //.then(response => response.json())
8867
8911
  // STRANGE : DOES WORK :
@@ -8917,7 +8961,12 @@ window.performHTTPRequest=function(completeURL, httpMethod="GET", headers={}, re
8917
8961
  }
8918
8962
 
8919
8963
  options.headers=headers;
8920
-
8964
+
8965
+
8966
+ if(allowSelfSignedCerts)
8967
+ options.rejectUnauthorized=true;
8968
+
8969
+
8921
8970
  return new Promise((resolve,reject)=>{
8922
8971
 
8923
8972
  // Create the HTTP request
@@ -9197,7 +9246,7 @@ window.initClient=function(isNodeContext=true
9197
9246
 
9198
9247
 
9199
9248
 
9200
- window.ClientReceptionEntryPoint=class{
9249
+ window.ClientReceptionEntryPoint=class ClientReceptionEntryPoint{
9201
9250
 
9202
9251
  constructor(channelNameParam, entryPointId, clientsRoomsTag, listenerConfig, doOnIncomingMessage){
9203
9252
  this.channelName=channelNameParam;
@@ -9276,7 +9325,7 @@ window.ClientReceptionEntryPoint=class{
9276
9325
  //
9277
9326
  // CLIENT INSTANCE :
9278
9327
  //
9279
- window.ClientInstance=class{
9328
+ window.ClientInstance=class ClientInstance{
9280
9329
 
9281
9330
  constructor(clientSocket){
9282
9331
 
@@ -9484,7 +9533,7 @@ window.ClientInstance=class{
9484
9533
 
9485
9534
  // ==================================================================================================================
9486
9535
 
9487
- window.ServerReceptionEntryPoint=class{
9536
+ window.ServerReceptionEntryPoint=class ServerReceptionEntryPoint{
9488
9537
 
9489
9538
  constructor(channelNameParam, clientsRoomsTag, listenerConfig=null, doOnIncomingMessage){
9490
9539
  this.channelName=channelNameParam;
@@ -9546,7 +9595,7 @@ window.ServerReceptionEntryPoint=class{
9546
9595
 
9547
9596
 
9548
9597
 
9549
- window.NodeServerInstance=class{
9598
+ window.NodeServerInstance=class NodeServerInstance{
9550
9599
 
9551
9600
  constructor(serverSocket, listenableServer){
9552
9601
 
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.1930",
3
+ "version": "0.0.1933",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "aotrautils-srv",
9
- "version": "0.0.1930",
9
+ "version": "0.0.1933",
10
10
  "license": "HGPL-1.0",
11
11
  "dependencies": {
12
12
  "atob": "^2.1.2",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.1930",
3
+ "version": "0.0.1933",
4
4
  "main": "aotrautils-srv.build.js",
5
5
  "description": "A library for vanilla javascript utils (server-side) used in aotra javascript CMS",
6
6
  "author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",