aotrautils-srv 0.0.2036 → 0.0.2038

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:47)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (17/10/2026-01:27:15)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -5485,7 +5485,7 @@ window.AOTRAUTILS_LIB_IS_LOADED=true;
5485
5485
 
5486
5486
 
5487
5487
 
5488
- /*utils AI library associated with aotra version : «1_29072022-2359 (13/10/2026-01:52:47)»*/
5488
+ /*utils AI library associated with aotra version : «1_29072022-2359 (17/10/2026-01:27:15)»*/
5489
5489
  /*-----------------------------------------------------------------------------*/
5490
5490
 
5491
5491
 
@@ -5749,7 +5749,7 @@ window.getLLMAPIClient=(modelName, apiURL, agentRole, defaultPrompt, llmProvider
5749
5749
 
5750
5750
 
5751
5751
 
5752
- /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (13/10/2026-01:52:47)»*/
5752
+ /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (17/10/2026-01:27:15)»*/
5753
5753
  /*-----------------------------------------------------------------------------*/
5754
5754
 
5755
5755
 
@@ -8586,19 +8586,33 @@ window.launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=
8586
8586
  if( requestHttpMethod=="GET" &&
8587
8587
  (!httpEndpoint.httpMethod || empty(httpEndpoint.httpMethod) || httpEndpoint.httpMethod.toUpperCase()=="GET")){
8588
8588
 
8589
- messageIn={...getRequestURLParameters(request)};
8589
+ messageIn={...getRequestURLParameters(request), ...getRequestHeaders(request)};
8590
8590
 
8591
8591
  }else if(requestHttpMethod=="POST"
8592
8592
  && contains(["POST","PUT","PATCH","DELETE"],httpEndpoint.httpMethod.toUpperCase())){
8593
8593
 
8594
- messageIn={...getRequestURLParameters(request), ...(await getRequestBody(request))};
8594
+ messageIn={...getRequestURLParameters(request), ...getRequestHeaders(request), ...(await getRequestBody(request))};
8595
8595
  }
8596
8596
 
8597
8597
  if(messageIn){
8598
8598
  let httpEndpointResultObject={httpStatus:200, body:{}};
8599
8599
  const serverReceptionEntryPoint=httpEndpoint.serverReceptionEntryPoint;
8600
8600
  if(serverReceptionEntryPoint){
8601
- httpEndpointResultObject.body=serverReceptionEntryPoint.execute(messageIn, null, false);
8601
+ const dataWrapped={data:messageIn};
8602
+ const eventOrMessage={data:dataWrapped};
8603
+
8604
+ // (we bypass the channel and message types filters !)
8605
+ try{
8606
+ httpEndpointResultObject.body=await serverReceptionEntryPoint.execute(eventOrMessage, null, false);
8607
+ }catch(treatmentsChannelError){
8608
+ // TODO : FIXME : DUPLICATED CODE !!!
8609
+ const errorMessage="ERROR : An error has occured during the processing of a client message on channel treatments.";
8610
+ // TRACE
8611
+ lognow(errorMessage, treatmentsChannelError);
8612
+ const errorDataWrapped={errorMessage:errorMessage, cause:{message:treatmentsChannelError.message}};
8613
+ httpEndpointResultObject.body=errorDataWrapped;
8614
+ httpEndpointResultObject.httpStatus=500;
8615
+ }
8602
8616
  }
8603
8617
 
8604
8618
  response.writeHead(httpEndpointResultObject.httpStatus, { "Content-Type": "application/json" });
@@ -9281,6 +9295,17 @@ window.isURLLocalhost=(url)=>{
9281
9295
 
9282
9296
 
9283
9297
 
9298
+ window.assert={};
9299
+ window.assert.notNull=(value, errorMessage=null)=>{
9300
+ if(typeof(value)=="undefined" || value==null)
9301
+ throw new Error(nonull(errorMessage, "ERROR : Value is null."));
9302
+ };
9303
+
9304
+
9305
+
9306
+
9307
+
9308
+
9284
9309
  /* ## Utility network global methods in a javascript, console (nodejs), or vanilla javascript with no browser environment.
9285
9310
  *
9286
9311
  * This set of methods gathers utility generic-purpose methods usable in any JS project.
@@ -9349,7 +9374,7 @@ if(typeof(window)==="undefined") window=global;
9349
9374
  // clientSocket.isConnectionAlive=true;
9350
9375
  //});
9351
9376
 
9352
-
9377
+ const ERRORS_CHANNEL_NAME="errors";
9353
9378
 
9354
9379
 
9355
9380
  // ==================================================================================================================
@@ -9749,6 +9774,7 @@ window.ServerReceptionEntryPointsBag=class ServerReceptionEntryPointsBag{
9749
9774
 
9750
9775
  // Executed whenever any message is received on any channel :
9751
9776
  executeAll(eventOrMessage, clientSocket=null){ // FOR REAL-TIME ONLY :
9777
+ const self=this;
9752
9778
 
9753
9779
  const clientsRoomsTag=this.clientsRoomsTag;
9754
9780
  if(!window.WebsocketImplementation.isInRoom(clientSocket, clientsRoomsTag)) return;
@@ -9768,25 +9794,25 @@ window.ServerReceptionEntryPointsBag=class ServerReceptionEntryPointsBag{
9768
9794
  foreach(this.serverReceptionEntryPoints, (serverReceptionEntryPoint,i)=>{
9769
9795
 
9770
9796
  // All listeners are executed IN PARALLEL !
9771
- const p=serverReceptionEntryPoint.execute(eventOrMessageParam, clientSocket);
9772
- p.then((message)=>{
9797
+ serverReceptionEntryPoint.execute(eventOrMessageParam, clientSocket).then((message)=>{
9773
9798
  /*DO NOTHING*/
9774
9799
  }).catch(treatmentsChannelError=>{
9800
+ // TODO : FIXME : DUPLICATED CODE !!!
9775
9801
  const errorMessage="ERROR : An error has occured during the processing of a client message on channel treatments.";
9776
-
9777
9802
  // TRACE
9778
9803
  lognow(errorMessage, treatmentsChannelError);
9779
-
9780
9804
  const errorDataWrapped={errorMessage:errorMessage, cause:treatmentsChannelError};
9781
- self.sendError(errorDataWrapped, clientSocketParam);
9782
-
9805
+ self.server.sendError(errorDataWrapped, clientSocket);
9783
9806
  });
9784
9807
 
9785
9808
  });
9786
9809
 
9787
9810
  }).catch(error=>{
9811
+ const errorMessage="ERROR : (.executeAllPrerequisites()) A prerequisite encountered an error :";
9788
9812
  // TRACE
9789
- lognow("ERROR : (.executeAllPrerequisites()) A prerequisite encountered an error :", error);
9813
+ lognow(errorMessage, error);
9814
+ const errorDataWrapped={errorMessage:errorMessage, cause:error};
9815
+ self.server.sendError(errorDataWrapped, clientSocket);
9790
9816
  });
9791
9817
 
9792
9818
  }
@@ -9822,7 +9848,7 @@ window.ServerReceptionEntryPointsBag=class ServerReceptionEntryPointsBag{
9822
9848
  const clientsRoomsTag=this.clientsRoomsTag;
9823
9849
  const messageTypes=(!messageType || empty(messageType) ? [] :
9824
9850
  (isArray(messageType) ? messageType : [messageType])
9825
- );
9851
+ );
9826
9852
  const listenerConfig={listenerMessageTypes:messageTypes, httpEndpointDefinition:httpEndpointDefinition};
9827
9853
  const serverReceptionEntryPoint=
9828
9854
  new window.ServerReceptionEntryPoint(channelNameParam, clientsRoomsTag, listenerConfig, asyncDoOnIncomingMessage);
@@ -9832,6 +9858,7 @@ window.ServerReceptionEntryPointsBag=class ServerReceptionEntryPointsBag{
9832
9858
  // TRACE
9833
9859
  lognow("INFO : Registered HTTP listener:",httpEndpointDefinition);
9834
9860
 
9861
+ httpEndpointDefinition.serverReceptionEntryPoint=serverReceptionEntryPoint;
9835
9862
  this.server.httpEndpoints.push(httpEndpointDefinition);
9836
9863
  }
9837
9864
 
@@ -9893,7 +9920,11 @@ window.ServerReceptionEntryPoint=class ServerReceptionEntryPoint{
9893
9920
  const dataRestored=restoreClassesInformation(dataLocal);
9894
9921
 
9895
9922
  // CAUTION : This method can be ASYNC or NOT ASYNC !!!
9896
- this.asyncDoOnIncomingMessage(dataRestored, clientSocketParam);
9923
+ // DBG
9924
+ if(isAsyncFunction(this.asyncDoOnIncomingMessage))
9925
+ return await this.asyncDoOnIncomingMessage(dataRestored, clientSocketParam);
9926
+ return this.asyncDoOnIncomingMessage(dataRestored, clientSocketParam);
9927
+
9897
9928
  }
9898
9929
 
9899
9930
  }
@@ -9990,8 +10021,9 @@ window.NodeServerInstance=class NodeServerInstance{
9990
10021
  // Channel information is stored in exchanged data :
9991
10022
  let dataWrapped=saveClassesInformation({channelName:channelName, data:data});
9992
10023
 
9993
-
9994
- if(!clientSocketParam){
10024
+ if(!clientSocketParam) return dataWrapped;
10025
+
10026
+ if(isString(clientSocketParam) && clientSocketParam=="*"){
9995
10027
 
9996
10028
  // DBG
9997
10029
  lognow("(SERVER) (server sends to all clients)");
@@ -10071,7 +10103,29 @@ window.NodeServerInstance=class NodeServerInstance{
10071
10103
 
10072
10104
  return dataWrapped;
10073
10105
  }
10074
-
10106
+
10107
+
10108
+ /*private*/sendError(error, clientSocketParam=null){
10109
+ // CAUTION ! NEVER DO THIS : clientSocketParam.send(...) ! (because it directly calls a single socket implementation !)
10110
+
10111
+ let errorMessageToSend=error;
10112
+ if(contains(typeof(error),"Error")){
10113
+ errorMessageToSend={
10114
+ type: error.type,
10115
+ httpStatus:error.httpStatus,
10116
+ error:(isString(error) ?
10117
+ {errorMessage:error}
10118
+ : {errorMessage:error.errorMessage, cause:(error.cause?{message:error.cause.message}:null)})
10119
+ };
10120
+ }
10121
+
10122
+ if(clientSocketParam){
10123
+ return this.send(ERRORS_CHANNEL_NAME, errorMessageToSend, null, clientSocketParam);
10124
+ }
10125
+ return errorMessageToSend;
10126
+ }
10127
+
10128
+
10075
10129
 
10076
10130
  onConnectionToClient(doOnConnection, doOnConnectionLost=null){
10077
10131
  const self=this;
@@ -10113,7 +10167,15 @@ window.NodeServerInstance=class NodeServerInstance{
10113
10167
  foreach(self.serverReceptionEntryPoints, (serverReceptionEntryPoint,i)=>{
10114
10168
  serverReceptionEntryPoint.execute(eventOrMessage, clientSocket, true).then(()=>{
10115
10169
  /*DO NOTHING*/
10170
+ }).catch(treatmentsChannelError=>{
10171
+ // TODO : FIXME : DUPLICATED CODE !!!
10172
+ const errorMessage="ERROR : An error has occured during the processing of a client message on channel treatments.";
10173
+ // TRACE
10174
+ lognow(errorMessage, treatmentsChannelError);
10175
+ const errorDataWrapped={errorMessage:errorMessage, cause:treatmentsChannelError};
10176
+ self.sendError(errorDataWrapped, clientSocket);
10116
10177
  });
10178
+
10117
10179
  });
10118
10180
 
10119
10181
  // NEW API :
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.2036",
3
+ "version": "0.0.2038",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "aotrautils-srv",
9
- "version": "0.0.2036",
9
+ "version": "0.0.2038",
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.2036",
3
+ "version": "0.0.2038",
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)",