aotrautils-srv 0.0.1575 → 0.0.1577

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 (11/05/2025-00:04:38)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (11/05/2025-01:14:10)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -4895,7 +4895,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
4895
4895
 
4896
4896
 
4897
4897
 
4898
- /*utils AI library associated with aotra version : «1_29072022-2359 (11/05/2025-00:04:38)»*/
4898
+ /*utils AI library associated with aotra version : «1_29072022-2359 (11/05/2025-01:14:10)»*/
4899
4899
  /*-----------------------------------------------------------------------------*/
4900
4900
 
4901
4901
 
@@ -5041,7 +5041,7 @@ getOpenAIAPIClient=(modelName, apiURL, agentRole, defaultPrompt)=>{
5041
5041
 
5042
5042
 
5043
5043
 
5044
- /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (11/05/2025-00:04:38)»*/
5044
+ /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (11/05/2025-01:14:10)»*/
5045
5045
  /*-----------------------------------------------------------------------------*/
5046
5046
 
5047
5047
 
@@ -6054,8 +6054,11 @@ getListManager=function(config){
6054
6054
  // USE THIS INSTEAD :
6055
6055
  performHTTPRequest=function(completeURL,httpMethod="GET",headers={},requestBodyOrNamedArgs=null,isNodeContext=false,addCORSHeader=ADD_CORS_HEADER){
6056
6056
 
6057
+ // Body
6057
6058
  let requestBodyOrNamedArgsStr=null;
6058
6059
  if(requestBodyOrNamedArgs){
6060
+ if(isString(requestBodyOrNamedArgs) && !isObject(requestBodyOrNamedArgs))
6061
+ throw new Error("ERROR : Body for request cannot be a string ! Must be a simple object.");
6059
6062
  try{
6060
6063
  requestBodyOrNamedArgsStr=stringifyObject(requestBodyOrNamedArgs)
6061
6064
  // We remove all the breaklines :
@@ -6064,7 +6067,14 @@ performHTTPRequest=function(completeURL,httpMethod="GET",headers={},requestBodyO
6064
6067
  requestBodyOrNamedArgsStr=""+requestBodyOrNamedArgs;
6065
6068
  }
6066
6069
  }
6067
-
6070
+ let body=null;
6071
+ // Not the same way to send parameters, with POST/PUT http method :
6072
+ if(contains(["POST","PUT"],httpMethod) && requestBodyOrNamedArgs){
6073
+ // CAUTION : IF POST/PUT METHOD THEN WE MUST NOT PASS A STRING, BUT A PLAIN OBJECT ! ELSE IT WILL CAUSE STRANGE BUGS !!!
6074
+ body=requestBodyOrNamedArgs;
6075
+ }
6076
+
6077
+ // Headers
6068
6078
  if(contains(["POST","PUT"],httpMethod)){
6069
6079
  headers["Content-Type"]="application/json";
6070
6080
  if(requestBodyOrNamedArgsStr)
@@ -6083,13 +6093,13 @@ performHTTPRequest=function(completeURL,httpMethod="GET",headers={},requestBodyO
6083
6093
  // DBG
6084
6094
  lognow("formatted API URL : "+completeURL);
6085
6095
  }
6086
-
6096
+
6087
6097
  // CASE BROWSER CONTEXT :
6088
6098
  if(!isNodeContext || typeof(require)=="undefined"){
6089
6099
  // TRACE
6090
6100
  lognow("INFO : We are not running in a browser context (isNodeContext:"+isNodeContext+";typeof(require):"+(typeof(require))+"). Using browser library.");
6091
6101
 
6092
- const body=((contains(["POST","PUT"],httpMethod) && requestBodyOrNamedArgs)?requestBodyOrNamedArgsStr:null);
6102
+
6093
6103
  return new Promise((resolve,reject)=>{
6094
6104
  fetch(completeURL, {
6095
6105
  method: httpMethod,
@@ -6164,12 +6174,9 @@ performHTTPRequest=function(completeURL,httpMethod="GET",headers={},requestBodyO
6164
6174
  // A chunk of data has been received.
6165
6175
  response.on("data", (chunk) => {
6166
6176
  responseDataStr += chunk;
6167
-
6168
- // DBG
6169
- const str = Buffer.from(chunk).toString("utf8");
6170
- lognow(">>>str:"+str);
6171
-
6172
-
6177
+ // // DEBUG ONLY
6178
+ // const str = Buffer.from(chunk).toString("utf8");
6179
+ // lognow(">>>str:"+str);
6173
6180
  });
6174
6181
 
6175
6182
  // The whole response has been received.
@@ -6219,12 +6226,9 @@ performHTTPRequest=function(completeURL,httpMethod="GET",headers={},requestBodyO
6219
6226
  reject({error:error, httpStatus:null});
6220
6227
  });
6221
6228
 
6222
-
6223
- // Not the same way to send parameters in POST http method :
6224
- if(contains(["POST","PUT"],httpMethod)){
6225
- // (We need to stringify parameters or else we'll have an error :)
6226
- if(requestBodyOrNamedArgs)
6227
- request.write(requestBodyOrNamedArgsStr);
6229
+ // Not the same way to send parameters, with POST/PUT http method :
6230
+ if(contains(["POST","PUT"],httpMethod) && body){
6231
+ request.write(body);
6228
6232
  }
6229
6233
 
6230
6234
  // End the request
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.1575",
3
+ "version": "0.0.1577",
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)",