oft-agt 0.5.12 → 0.5.13
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.
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/runtime/api-request.mjs +4 -2
- package/version.mjs +1 -1
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oft-agt",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.13",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "oft-agt",
|
|
9
|
-
"version": "0.5.
|
|
9
|
+
"version": "0.5.13",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"discord.js": "^14.14.0",
|
|
12
12
|
"ws": "^8.18.0"
|
package/package.json
CHANGED
package/runtime/api-request.mjs
CHANGED
|
@@ -9,12 +9,14 @@ export async function requestApi(raw,{resolveSecret=async()=>{throw Error('Secre
|
|
|
9
9
|
const url=new URL(await replace(c.url));if(url.username||url.password||!['http:','https:'].includes(url.protocol))throw Error('URL refusée.');
|
|
10
10
|
for(const p of c.params)if(p.key)url.searchParams.append(p.key,await replace(p.value));
|
|
11
11
|
const headers={'User-Agent':'Oftone-Agent/1'};for(const h of c.headers)if(h.key){if(/^(host|content-length|connection|transfer-encoding|upgrade)$/i.test(h.key)||/[\r\n]/.test(h.key))throw Error('En-tête refusé.');headers[h.key]=await replace(h.value);}
|
|
12
|
-
const body=await replace(c.body);
|
|
12
|
+
const body=await replace(c.body);if(resolvedSecrets.length&&url.protocol!=='https:')throw Error('HTTPS requis pour utiliser un secret.');
|
|
13
13
|
const result=await new Promise((resolve,reject)=>{
|
|
14
14
|
if(isIP(url.hostname.replaceAll(/[\[\]]/g,''))&&!publicAddress(url.hostname.replaceAll(/[\[\]]/g,'')))return reject(Error('Adresse locale refusée.'));
|
|
15
15
|
const req=(url.protocol==='https:'?https:http).request(url,{method:c.method,headers,signal:signal?AbortSignal.any([signal,AbortSignal.timeout(c.timeout)]):AbortSignal.timeout(c.timeout),lookup:(host,options,cb)=>lookup(host,{all:true},(err,addresses)=>{if(err||!addresses.length||addresses.some(a=>!publicAddress(a.address)))return cb(Error('Adresse réseau refusée.'));const a=addresses[0];cb(null,options.all?[a]:a.address,a.family);})},res=>{let size=0;const chunks=[];res.on('data',chunk=>{size+=chunk.length;if(size>262144){req.destroy(Error('Réponse trop volumineuse.'));return;}chunks.push(chunk);});res.on('end',()=>{const text=Buffer.concat(chunks).toString('utf8');let response;try{response=JSON.parse(text);}catch{response=text;}resolve({status:res.statusCode,statusText:res.statusMessage||'',response});});res.on('error',reject);});
|
|
16
16
|
req.setTimeout(c.timeout,()=>req.destroy(Error('Délai de requête dépassé.')));req.on('error',()=>reject(Error('Requête API échouée.')));if(!['GET','HEAD'].includes(c.method))req.write(body);req.end();
|
|
17
17
|
});
|
|
18
|
-
|
|
18
|
+
return {status:result.status,statusText:redactApiResult(result.statusText,resolvedSecrets),response:redactApiResult(result.response,resolvedSecrets)};
|
|
19
19
|
}
|
|
20
20
|
export function responseVariables(c,result){const values={[c.name+'_status-code']:String(result.status),[c.name+'_status-text']:result.statusText,[c.name+'_response']:typeof result.response==='string'?result.response:JSON.stringify(result.response)};for(const o of c.outputs){let v=result.response;for(const key of o.path)v=v&&typeof v==='object'&&Object.hasOwn(v,key)?v[key]:undefined;values[c.name+'_'+o.name]=v===undefined?'':typeof v==='object'?JSON.stringify(v):String(v);}return values;}
|
|
21
|
+
|
|
22
|
+
export function redactApiResult(value,secrets){const redact=s=>{for(const secret of secrets)if(secret)s=s.split(secret).join('••••');return s;};if(typeof value==='string')return redact(value);if(Array.isArray(value))return value.map(v=>redactApiResult(v,secrets));if(value&&typeof value==='object')return Object.fromEntries(Object.entries(value).map(([k,v])=>[redact(k),redactApiResult(v,secrets)]));return value;}
|
package/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AGENT_VERSION = '0.5.
|
|
1
|
+
export const AGENT_VERSION = '0.5.13';
|