oft-agt 0.5.12 → 0.5.14
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 +14 -2
- package/runtime/execute.mjs +3 -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.14",
|
|
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.14",
|
|
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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {interpolateVariables} from './custom-variables.mjs';
|
|
1
2
|
import http from 'node:http';
|
|
2
3
|
import https from 'node:https';
|
|
3
4
|
import {lookup} from 'node:dns';
|
|
@@ -9,12 +10,23 @@ export async function requestApi(raw,{resolveSecret=async()=>{throw Error('Secre
|
|
|
9
10
|
const url=new URL(await replace(c.url));if(url.username||url.password||!['http:','https:'].includes(url.protocol))throw Error('URL refusée.');
|
|
10
11
|
for(const p of c.params)if(p.key)url.searchParams.append(p.key,await replace(p.value));
|
|
11
12
|
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);
|
|
13
|
+
const body=await replace(c.body);if(resolvedSecrets.length&&url.protocol!=='https:')throw Error('HTTPS requis pour utiliser un secret.');
|
|
13
14
|
const result=await new Promise((resolve,reject)=>{
|
|
14
15
|
if(isIP(url.hostname.replaceAll(/[\[\]]/g,''))&&!publicAddress(url.hostname.replaceAll(/[\[\]]/g,'')))return reject(Error('Adresse locale refusée.'));
|
|
15
16
|
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
17
|
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
18
|
});
|
|
18
|
-
|
|
19
|
+
return {status:result.status,statusText:redactApiResult(result.statusText,resolvedSecrets),response:redactApiResult(result.response,resolvedSecrets)};
|
|
19
20
|
}
|
|
20
21
|
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;}
|
|
22
|
+
|
|
23
|
+
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;}
|
|
24
|
+
|
|
25
|
+
export async function interpolateApiArguments(args, options) {
|
|
26
|
+
const {body = '', ...rest} = args;
|
|
27
|
+
const resolved = await interpolateVariables(rest, options);
|
|
28
|
+
if (['GET', 'HEAD'].includes(args.method)) return {...resolved, body: ''};
|
|
29
|
+
let json;
|
|
30
|
+
try { json = JSON.parse(body); } catch { return {...resolved, body: await interpolateVariables(body, options)}; }
|
|
31
|
+
return {...resolved, body: JSON.stringify(await interpolateVariables(json, options))};
|
|
32
|
+
}
|
package/runtime/execute.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {interpolateApiArguments} from './api-request.mjs';
|
|
1
2
|
import { interpolateVariables, referencedVariables, VARIABLE_WARNING_CODES } from './custom-variables.mjs';
|
|
2
3
|
import { variableRuntimeOptions } from './variable-actions.mjs';
|
|
3
4
|
import { buttonRouter } from './button-router.mjs';
|
|
@@ -133,7 +134,7 @@ async function executeAdmitted(command, interaction, client, options) {
|
|
|
133
134
|
|
|
134
135
|
context.signal.throwIfAborted();
|
|
135
136
|
|
|
136
|
-
const args=await interpolateVariables(call.args,context.variableOptions);
|
|
137
|
+
const args=await (call.fn==='apiRequest'?interpolateApiArguments:interpolateVariables)(call.args,context.variableOptions);
|
|
137
138
|
const prepared=call.fn==='sendMessage'&&args.buttons?.length?(options.buttonRouter||buttonRouter).prepare(command,args.buttons,context,optionValues):null;
|
|
138
139
|
const invoke=async()=>{try{return await registry[call.fn](context,{...args,...(prepared?{components:prepared.components}:{})});}catch(error){prepared?.cancel();throw error;}};
|
|
139
140
|
|
|
@@ -160,7 +161,7 @@ async function executeAdmitted(command, interaction, client, options) {
|
|
|
160
161
|
|
|
161
162
|
context.signal.throwIfAborted();
|
|
162
163
|
|
|
163
|
-
const args=interpolateError(await interpolateVariables(call.args,{...context.variableOptions,base:{...context.variableOptions.base,...optionValues,...variables}}),variables);
|
|
164
|
+
const args=interpolateError(await (call.fn==='apiRequest'?interpolateApiArguments:interpolateVariables)(call.args,{...context.variableOptions,base:{...context.variableOptions.base,...optionValues,...variables}}),variables);
|
|
164
165
|
const prepared=call.fn==='sendMessage'&&args.buttons?.length?(options.buttonRouter||buttonRouter).prepare(command,args.buttons,context,{...optionValues,...variables}):null;
|
|
165
166
|
const invoke=async()=>{try{return await registry[call.fn](context,{...args,...(prepared?{components:prepared.components}:{})});}catch(error){prepared?.cancel();throw error;}};
|
|
166
167
|
|
package/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AGENT_VERSION = '0.5.
|
|
1
|
+
export const AGENT_VERSION = '0.5.14';
|