aotrautils 0.0.2041 → 0.0.2043

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 (13/10/2026-01:52:42)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (17/10/2026-01:26:49)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -5485,7 +5485,7 @@ window.AOTRAUTILS_LIB_IS_LOADED=true;
5485
5485
 
5486
5486
 
5487
5487
 
5488
- /*utils CLIENT library associated with aotra version : «1_29072022-2359 (13/10/2026-01:52:42)»*/
5488
+ /*utils CLIENT library associated with aotra version : «1_29072022-2359 (17/10/2026-01:26:49)»*/
5489
5489
  /*-----------------------------------------------------------------------------*/
5490
5490
  /* ## Utility global methods in a browser (htmljs) client environment.
5491
5491
  *
@@ -5580,6 +5580,18 @@ window.getRequestURLParameters=(request)=>{
5580
5580
  return parameters;
5581
5581
  };
5582
5582
 
5583
+ window.getRequestHeaders=(request)=>{
5584
+ const results={};
5585
+ const visited=new Set();
5586
+ for(let i=0; i<request.rawHeaders.length; i+=2){ // Because req.rawHeaders isn’t an array of pairs. It’s a single flat list where names and values alternate !
5587
+ const headerName=request.rawHeaders[i].toLowerCase();
5588
+ if(visited.has(headerName)) continue;
5589
+ if(headerName in results) continue;
5590
+ visited.add(headerName);
5591
+ results[headerName]=request.rawHeaders[i+1];
5592
+ }
5593
+ return results;
5594
+ }
5583
5595
 
5584
5596
  window.getRequestBody=async function(request, maxSize = 1_000_000){
5585
5597
  const chunks=[];
@@ -13041,7 +13053,7 @@ window.createOritaMicroClient=function(url, port, isNode=false, staticMicroClien
13041
13053
 
13042
13054
 
13043
13055
 
13044
- /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (13/10/2026-01:52:42)»*/
13056
+ /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (17/10/2026-01:26:49)»*/
13045
13057
  /*-----------------------------------------------------------------------------*/
13046
13058
 
13047
13059
 
@@ -14130,10 +14142,10 @@ function rayVsUnitSphereClosestPoint(p, r) {
14130
14142
  // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
14131
14143
 
14132
14144
  window.AOTRAUTILS_GEOMETRY_LIB_IS_LOADED=true;
14133
- /*utils 3D library associated with aotra version : «1_29072022-2359 (13/10/2026-01:52:42)»*/
14145
+ /*utils 3D library associated with aotra version : «1_29072022-2359 (17/10/2026-01:26:49)»*/
14134
14146
  /*-----------------------------------------------------------------------------*/
14135
14147
 
14136
- /*utils AI library associated with aotra version : «1_29072022-2359 (13/10/2026-01:52:42)»*/
14148
+ /*utils AI library associated with aotra version : «1_29072022-2359 (17/10/2026-01:26:49)»*/
14137
14149
  /*-----------------------------------------------------------------------------*/
14138
14150
 
14139
14151
 
@@ -14397,7 +14409,7 @@ window.getLLMAPIClient=(modelName, apiURL, agentRole, defaultPrompt, llmProvider
14397
14409
 
14398
14410
 
14399
14411
 
14400
- /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (13/10/2026-01:52:42)»*/
14412
+ /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (17/10/2026-01:26:49)»*/
14401
14413
  /*-----------------------------------------------------------------------------*/
14402
14414
 
14403
14415
 
@@ -17234,19 +17246,33 @@ window.launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=
17234
17246
  if( requestHttpMethod=="GET" &&
17235
17247
  (!httpEndpoint.httpMethod || empty(httpEndpoint.httpMethod) || httpEndpoint.httpMethod.toUpperCase()=="GET")){
17236
17248
 
17237
- messageIn={...getRequestURLParameters(request)};
17249
+ messageIn={...getRequestURLParameters(request), ...getRequestHeaders(request)};
17238
17250
 
17239
17251
  }else if(requestHttpMethod=="POST"
17240
17252
  && contains(["POST","PUT","PATCH","DELETE"],httpEndpoint.httpMethod.toUpperCase())){
17241
17253
 
17242
- messageIn={...getRequestURLParameters(request), ...(await getRequestBody(request))};
17254
+ messageIn={...getRequestURLParameters(request), ...getRequestHeaders(request), ...(await getRequestBody(request))};
17243
17255
  }
17244
17256
 
17245
17257
  if(messageIn){
17246
17258
  let httpEndpointResultObject={httpStatus:200, body:{}};
17247
17259
  const serverReceptionEntryPoint=httpEndpoint.serverReceptionEntryPoint;
17248
17260
  if(serverReceptionEntryPoint){
17249
- httpEndpointResultObject.body=serverReceptionEntryPoint.execute(messageIn, null, false);
17261
+ const dataWrapped={data:messageIn};
17262
+ const eventOrMessage={data:dataWrapped};
17263
+
17264
+ // (we bypass the channel and message types filters !)
17265
+ try{
17266
+ httpEndpointResultObject.body=await serverReceptionEntryPoint.execute(eventOrMessage, null, false);
17267
+ }catch(treatmentsChannelError){
17268
+ // TODO : FIXME : DUPLICATED CODE !!!
17269
+ const errorMessage="ERROR : An error has occured during the processing of a client message on channel treatments.";
17270
+ // TRACE
17271
+ lognow(errorMessage, treatmentsChannelError);
17272
+ const errorDataWrapped={errorMessage:errorMessage, cause:{message:treatmentsChannelError.message}};
17273
+ httpEndpointResultObject.body=errorDataWrapped;
17274
+ httpEndpointResultObject.httpStatus=500;
17275
+ }
17250
17276
  }
17251
17277
 
17252
17278
  response.writeHead(httpEndpointResultObject.httpStatus, { "Content-Type": "application/json" });
@@ -17929,6 +17955,17 @@ window.isURLLocalhost=(url)=>{
17929
17955
 
17930
17956
 
17931
17957
 
17958
+ window.assert={};
17959
+ window.assert.notNull=(value, errorMessage=null)=>{
17960
+ if(typeof(value)=="undefined" || value==null)
17961
+ throw new Error(nonull(errorMessage, "ERROR : Value is null."));
17962
+ };
17963
+
17964
+
17965
+
17966
+
17967
+
17968
+
17932
17969
  /* ## Utility network global methods in a javascript, console (nodejs), or vanilla javascript with no browser environment.
17933
17970
  *
17934
17971
  * This set of methods gathers utility generic-purpose methods usable in any JS project.
@@ -17997,7 +18034,7 @@ if(typeof(window)==="undefined") window=global;
17997
18034
  // clientSocket.isConnectionAlive=true;
17998
18035
  //});
17999
18036
 
18000
-
18037
+ const ERRORS_CHANNEL_NAME="errors";
18001
18038
 
18002
18039
 
18003
18040
  // ==================================================================================================================
@@ -18397,6 +18434,7 @@ window.ServerReceptionEntryPointsBag=class ServerReceptionEntryPointsBag{
18397
18434
 
18398
18435
  // Executed whenever any message is received on any channel :
18399
18436
  executeAll(eventOrMessage, clientSocket=null){ // FOR REAL-TIME ONLY :
18437
+ const self=this;
18400
18438
 
18401
18439
  const clientsRoomsTag=this.clientsRoomsTag;
18402
18440
  if(!window.WebsocketImplementation.isInRoom(clientSocket, clientsRoomsTag)) return;
@@ -18416,25 +18454,25 @@ window.ServerReceptionEntryPointsBag=class ServerReceptionEntryPointsBag{
18416
18454
  foreach(this.serverReceptionEntryPoints, (serverReceptionEntryPoint,i)=>{
18417
18455
 
18418
18456
  // All listeners are executed IN PARALLEL !
18419
- const p=serverReceptionEntryPoint.execute(eventOrMessageParam, clientSocket);
18420
- p.then((message)=>{
18457
+ serverReceptionEntryPoint.execute(eventOrMessageParam, clientSocket).then((message)=>{
18421
18458
  /*DO NOTHING*/
18422
18459
  }).catch(treatmentsChannelError=>{
18460
+ // TODO : FIXME : DUPLICATED CODE !!!
18423
18461
  const errorMessage="ERROR : An error has occured during the processing of a client message on channel treatments.";
18424
-
18425
18462
  // TRACE
18426
18463
  lognow(errorMessage, treatmentsChannelError);
18427
-
18428
18464
  const errorDataWrapped={errorMessage:errorMessage, cause:treatmentsChannelError};
18429
- self.sendError(errorDataWrapped, clientSocketParam);
18430
-
18465
+ self.server.sendError(errorDataWrapped, clientSocket);
18431
18466
  });
18432
18467
 
18433
18468
  });
18434
18469
 
18435
18470
  }).catch(error=>{
18471
+ const errorMessage="ERROR : (.executeAllPrerequisites()) A prerequisite encountered an error :";
18436
18472
  // TRACE
18437
- lognow("ERROR : (.executeAllPrerequisites()) A prerequisite encountered an error :", error);
18473
+ lognow(errorMessage, error);
18474
+ const errorDataWrapped={errorMessage:errorMessage, cause:error};
18475
+ self.server.sendError(errorDataWrapped, clientSocket);
18438
18476
  });
18439
18477
 
18440
18478
  }
@@ -18470,7 +18508,7 @@ window.ServerReceptionEntryPointsBag=class ServerReceptionEntryPointsBag{
18470
18508
  const clientsRoomsTag=this.clientsRoomsTag;
18471
18509
  const messageTypes=(!messageType || empty(messageType) ? [] :
18472
18510
  (isArray(messageType) ? messageType : [messageType])
18473
- );
18511
+ );
18474
18512
  const listenerConfig={listenerMessageTypes:messageTypes, httpEndpointDefinition:httpEndpointDefinition};
18475
18513
  const serverReceptionEntryPoint=
18476
18514
  new window.ServerReceptionEntryPoint(channelNameParam, clientsRoomsTag, listenerConfig, asyncDoOnIncomingMessage);
@@ -18480,6 +18518,7 @@ window.ServerReceptionEntryPointsBag=class ServerReceptionEntryPointsBag{
18480
18518
  // TRACE
18481
18519
  lognow("INFO : Registered HTTP listener:",httpEndpointDefinition);
18482
18520
 
18521
+ httpEndpointDefinition.serverReceptionEntryPoint=serverReceptionEntryPoint;
18483
18522
  this.server.httpEndpoints.push(httpEndpointDefinition);
18484
18523
  }
18485
18524
 
@@ -18541,7 +18580,11 @@ window.ServerReceptionEntryPoint=class ServerReceptionEntryPoint{
18541
18580
  const dataRestored=restoreClassesInformation(dataLocal);
18542
18581
 
18543
18582
  // CAUTION : This method can be ASYNC or NOT ASYNC !!!
18544
- this.asyncDoOnIncomingMessage(dataRestored, clientSocketParam);
18583
+ // DBG
18584
+ if(isAsyncFunction(this.asyncDoOnIncomingMessage))
18585
+ return await this.asyncDoOnIncomingMessage(dataRestored, clientSocketParam);
18586
+ return this.asyncDoOnIncomingMessage(dataRestored, clientSocketParam);
18587
+
18545
18588
  }
18546
18589
 
18547
18590
  }
@@ -18638,8 +18681,9 @@ window.NodeServerInstance=class NodeServerInstance{
18638
18681
  // Channel information is stored in exchanged data :
18639
18682
  let dataWrapped=saveClassesInformation({channelName:channelName, data:data});
18640
18683
 
18641
-
18642
- if(!clientSocketParam){
18684
+ if(!clientSocketParam) return dataWrapped;
18685
+
18686
+ if(isString(clientSocketParam) && clientSocketParam=="*"){
18643
18687
 
18644
18688
  // DBG
18645
18689
  lognow("(SERVER) (server sends to all clients)");
@@ -18719,7 +18763,29 @@ window.NodeServerInstance=class NodeServerInstance{
18719
18763
 
18720
18764
  return dataWrapped;
18721
18765
  }
18722
-
18766
+
18767
+
18768
+ /*private*/sendError(error, clientSocketParam=null){
18769
+ // CAUTION ! NEVER DO THIS : clientSocketParam.send(...) ! (because it directly calls a single socket implementation !)
18770
+
18771
+ let errorMessageToSend=error;
18772
+ if(contains(typeof(error),"Error")){
18773
+ errorMessageToSend={
18774
+ type: error.type,
18775
+ httpStatus:error.httpStatus,
18776
+ error:(isString(error) ?
18777
+ {errorMessage:error}
18778
+ : {errorMessage:error.errorMessage, cause:(error.cause?{message:error.cause.message}:null)})
18779
+ };
18780
+ }
18781
+
18782
+ if(clientSocketParam){
18783
+ return this.send(ERRORS_CHANNEL_NAME, errorMessageToSend, null, clientSocketParam);
18784
+ }
18785
+ return errorMessageToSend;
18786
+ }
18787
+
18788
+
18723
18789
 
18724
18790
  onConnectionToClient(doOnConnection, doOnConnectionLost=null){
18725
18791
  const self=this;
@@ -18761,7 +18827,15 @@ window.NodeServerInstance=class NodeServerInstance{
18761
18827
  foreach(self.serverReceptionEntryPoints, (serverReceptionEntryPoint,i)=>{
18762
18828
  serverReceptionEntryPoint.execute(eventOrMessage, clientSocket, true).then(()=>{
18763
18829
  /*DO NOTHING*/
18830
+ }).catch(treatmentsChannelError=>{
18831
+ // TODO : FIXME : DUPLICATED CODE !!!
18832
+ const errorMessage="ERROR : An error has occured during the processing of a client message on channel treatments.";
18833
+ // TRACE
18834
+ lognow(errorMessage, treatmentsChannelError);
18835
+ const errorDataWrapped={errorMessage:errorMessage, cause:treatmentsChannelError};
18836
+ self.sendError(errorDataWrapped, clientSocket);
18764
18837
  });
18838
+
18765
18839
  });
18766
18840
 
18767
18841
  // NEW API :
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "aotrautils",
3
- "version": "0.0.2041",
3
+ "version": "0.0.2043",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "aotrautils",
9
- "version": "0.0.2041",
9
+ "version": "0.0.2043",
10
10
  "license": "HGPL-1.0",
11
11
  "dependencies": {
12
12
  "atob": "^2.1.2",
aotrautils/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils",
3
- "version": "0.0.2041",
3
+ "version": "0.0.2043",
4
4
  "main": "aotrautils.build.js",
5
5
  "description": "A library for vanilla javascript utils (client-side) used in aotra javascript CMS",
6
6
  "author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",