@wooch-tickets/wookster-cli 1.0.1 → 1.0.2
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/dist/cli/index.js +6 -6
- package/dist/index.js +17 -28
- package/package.json +6 -5
- package/dist/cli/base-command.js +0 -29
- package/dist/cli/commands/base-command.js +0 -29
- package/dist/cli/commands/listener/base-command.js +0 -100
- package/dist/cli/commands/listener/base-request-handler-command.js +0 -106
- package/dist/cli/commands/listener/proxy-executor.js +0 -130
- package/dist/cli/commands/listener/script-executor.js +0 -285
- package/dist/cli/commands/script-executor.js +0 -31
- package/dist/cli/env.js +0 -28
- package/dist/cli/global-option-applier.js +0 -36
- package/dist/cli/global-option-parsing.js +0 -70
- package/dist/cli/rx-event-counter.js +0 -12
- package/dist/client/handlers/base.request-handler.js +0 -12
- package/dist/client/handlers/method.request-handler.js +0 -27
- package/dist/client/handlers/multi.request-handler.js +0 -19
- package/dist/client/handlers/subject.request-handler.js +0 -21
- package/dist/client/logger/global-logger.js +0 -29
- package/dist/client/logger/json.logger.js +0 -29
- package/dist/client/logger/log.js +0 -2
- package/dist/client/logger/logger-service.js +0 -90
- package/dist/client/logger/logger.decorator.js +0 -29
- package/dist/client/logger/noop.logger.js +0 -9
- package/dist/client/logger/pretty.logger.js +0 -56
- package/dist/client/models/handler-models.js +0 -21
- package/dist/client/models/webhook-request.js +0 -23
- package/dist/client/services/request-handler.service.js +0 -226
package/dist/cli/index.js
CHANGED
|
@@ -9,8 +9,8 @@ const global_option_applier_1 = require("./global-option-applier");
|
|
|
9
9
|
const program = new commander_1.Command();
|
|
10
10
|
program
|
|
11
11
|
.name('wookster')
|
|
12
|
-
.description('CLI for Wookster Virtual Hooks')
|
|
13
|
-
.version(
|
|
12
|
+
.description('Official CLI for Wookster. Connect workers to process or proxy webhook events from Virtual Hooks.')
|
|
13
|
+
.version(APP_VERSION);
|
|
14
14
|
program.hook('preAction', global_option_applier_1.globalOptionApplier);
|
|
15
15
|
//global actions:
|
|
16
16
|
program.addOption(new commander_1.Option('--verbose').default(false, 'Enable verbose logging'));
|
|
@@ -18,16 +18,16 @@ program.addOption(new commander_1.Option('--logger <type>', "Specify logger type
|
|
|
18
18
|
program.addOption(new commander_1.Option('-k, --api-key <apiKey>', "Api key for authentication"));
|
|
19
19
|
program.addOption(new commander_1.Option('-u, --server-url <serverUrl>', 'Server URL to connect to'));
|
|
20
20
|
program
|
|
21
|
-
.command('
|
|
22
|
-
.description('
|
|
21
|
+
.command('worker-script')
|
|
22
|
+
.description('Connect to Wookster as a worker and execute a provided script for each incoming webhook event')
|
|
23
23
|
.requiredOption("-w, --worker <worker>", 'Worker identifier to process requests')
|
|
24
24
|
.requiredOption('-s, --script <script>', 'Path to the script to execute for each request')
|
|
25
25
|
.action(async (options) => {
|
|
26
26
|
(0, base_request_handler_command_1.runCommand)(script_executor_1.ScriptExecutor, options);
|
|
27
27
|
});
|
|
28
28
|
program
|
|
29
|
-
.command('proxy')
|
|
30
|
-
.description('
|
|
29
|
+
.command('worker-proxy')
|
|
30
|
+
.description('Connect to Wookster as a worker and proxy each incoming webhook event to a specified target URL')
|
|
31
31
|
.requiredOption('-w, --worker <worker>', 'Worker identifier to process requests')
|
|
32
32
|
.requiredOption('-t, --target <target>', 'Target url to proxy webhook request (http.s)')
|
|
33
33
|
.action(async (argument) => {
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
service.
|
|
19
|
-
(new method_request_handler_1.MethodRequestHandler((request) => {
|
|
20
|
-
mainLogger.info('Received request:', request);
|
|
21
|
-
return Promise.resolve(handler_models_1.WebhookResult.success());
|
|
22
|
-
}));
|
|
23
|
-
(0, fromEvent_1.fromEvent)(process, 'SIGINT').subscribe(async () => {
|
|
24
|
-
mainLogger.info('Received SIGINT, shutting down...');
|
|
25
|
-
await service.destroy();
|
|
26
|
-
process.exit(0);
|
|
27
|
-
});
|
|
28
|
-
(0, node_timers_1.setInterval)(() => { }, 5000);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";var ge=Object.create;var C=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,Te=Object.prototype.hasOwnProperty;var he=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),H=t=>{throw TypeError(t)};var We=(t,e,r)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var le=(t,e)=>C(t,"name",{value:e,configurable:!0});var Pe=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Oe(e))!Te.call(t,s)&&s!==r&&C(t,s,{get:()=>e[s],enumerable:!(o=pe(e,s))||o.enumerable});return t};var $=(t,e,r)=>(r=t!=null?ge(qe(t)):{},Pe(e||!t||!t.__esModule?C(r,"default",{value:t,enumerable:!0}):r,t));var R=t=>[,,,ge(t?.[he("metadata")]??null)],me=["class","method","getter","setter","accessor","field","value","get","set"],P=t=>t!==void 0&&typeof t!="function"?H("Function expected"):t,Ce=(t,e,r,o,s)=>({kind:me[t],name:e,metadata:o,addInitializer:n=>r._?H("Already initialized"):s.push(P(n||null))}),He=(t,e)=>We(e,he("metadata"),t[3]),S=(t,e,r,o)=>{for(var s=0,n=t[e>>1],i=n&&n.length;s<i;s++)e&1?n[s].call(r):o=n[s].call(r,o);return o},x=(t,e,r,o,s,n)=>{var i,c,m,p,y,a=e&7,B=!!(e&8),g=!!(e&16),J=a>3?t.length+1:a?B?1:2:0,ae=me[a+5],ce=a>3&&(t[J-1]=[]),Le=t[J]||(t[J]=[]),d=a&&(!g&&!B&&(s=s.prototype),a<5&&(a>3||!g)&&pe(a<4?s:{get[r](){return ue(this,n)},set[r](u){return de(this,n,u)}},r));a?g&&a<4&&le(n,(a>2?"set ":a>1?"get ":"")+r):le(s,r);for(var j=o.length-1;j>=0;j--)p=Ce(a,r,m={},t[3],Le),a&&(p.static=B,p.private=g,y=p.access={has:g?u=>Ke(s,u):u=>r in u},a^3&&(y.get=g?u=>(a^1?ue:_e)(u,s,a^4?n:d.get):u=>u[r]),a>2&&(y.set=g?(u,Q)=>de(u,s,Q,a^4?n:d.set):(u,Q)=>u[r]=Q)),c=(0,o[j])(a?a<4?g?n:d[ae]:a>4?void 0:{get:d.get,set:d.set}:s,p),m._=1,a^4||c===void 0?P(c)&&(a>4?ce.unshift(c):a?g?n=c:d[ae]=c:s=c):typeof c!="object"||c===null?H("Object expected"):(P(i=c.get)&&(d.get=i),P(i=c.set)&&(d.set=i),P(i=c.init)&&ce.unshift(i));return a||He(t,s),d&&C(s,r,d),g?a^4?n:d:s};var X=(t,e,r)=>e.has(t)||H("Cannot "+r),Ke=(t,e)=>Object(e)!==e?H('Cannot use the "in" operator on this value'):t.has(e),ue=(t,e,r)=>(X(t,e,"read from private field"),r?r.call(t):e.get(t));var de=(t,e,r,o)=>(X(t,e,"write to private field"),o?o.call(t,r):e.set(t,r),r),_e=(t,e,r)=>(X(t,e,"access private method"),r);var k=require("commander");var re=require("rxjs/internal/observable/fromEvent");var Y=["info","warn","error"];function fe(t){Y.includes(t)||Y.push(t)}var E=class{logger;source;messageQueue=[];constructor(e,r){this.logger=e,this.source=r}info(e,r={}){this.sendToLogger("info",e,r)}warn(e,r={}){this.sendToLogger("warn",e,r)}error(e,r={}){this.sendToLogger("error",e,r)}debug(e,r={}){this.sendToLogger("debug",e,r)}sendToLogger(e,r,o){let s={severity:e,source:this.source||"unknown",message:this.tryReplace(r,o),timestamp:new Date,context:o};this.ensureLoggerState(s),this.log(s)}log(e){Y.includes(e.severity)&&this.logger.log(e)}tryReplace(e,r){for(let o in r){let s=`{${o}}`;e.includes(s)&&(e=e.replace(s,String(r[o])))}return e}ensureLoggerState(e=null){if(this.logger){if(this.messageQueue.length){for(let o of this.messageQueue)this.log(o);this.messageQueue=[]}return}let r=K();r||e&&(this.messageQueue.push(e),this.messageQueue.length>5&&console.error(`Please set a global logger, you are losing log messages in ${this.source}`)),this.logger=r}flushQueue(){this.ensureLoggerState()}};var ye,$e;function K(){return ye}function A(t){typeof t=="function"&&(t=new t),ye=t,$e=_()}function _(t){return new E(K(),t||"global")}function O(t){return function(e){let r=t??e.name,o=new E(K(),r);return o.debug(`Logger for ${r} created successfully`),class extends e{log=o}}}var L=class{log;constructor(){}};var f=require("@stomp/rx-stomp"),V=$(require("node:assert"));var l=class t{code;message;state="success";executionTime;constructor(e,r,o){this.state=e,this.code=r,this.message=o}static success(e="OK",r=200){return new t("success",r,e)}static failure(e="Error",r=500){return new t("failure",r,e)}};var I=class{id;method;body;headers;type;signature;constructor(e){this.id=e.id,this.method=e.method,this.body=e.body,this.headers=e.headers,this.type=e.type,this.signature=e.signature}};function z(t,e){let r=t[e];(0,V.default)(r!=null,`Missing required property: ${String(e)}`),typeof r=="string"&&(0,V.default)(r.trim().length>0,`Property ${String(e)} cannot be an empty string`)}var Ae="/queue/worker/webhook_request",be="/messages/worker/webhook-request/{requestId}",ve,Z,Ie;ve=[O()];var b=class extends(Ie=L){options;handler;client;tunnelSub;listenerSub;intervalHandle;constructor(e){super(),(0,V.default)(e,"RequestHandlerService requires options"),z(e,"worker"),z(e,"apiKey"),z(e,"serverUrl"),this.options=e,this.handler=e.handler,this.client=new f.RxStomp;let r={"api-key":this.options.apiKey};e.worker&&(r.worker=e.worker),this.client.configure({reconnectTimeMode:f.ReconnectionTimeMode.LINEAR,maxReconnectDelay:1e4,brokerURL:this.options.serverUrl,connectHeaders:r,reconnectDelay:1e3,beforeConnect:()=>(this.log.info("Connecting to server..."),Promise.resolve())})}setHandler(e){this.handler=e}start(){if(!this.handler)throw new Error("Cannot start RequestHandlerService without a handler set");this.tunnelSub=this.client.connected$.subscribe({next:async e=>{switch(this.log.debug(`Connection state changed: ${f.RxStompState[e]}`),e){case f.RxStompState.OPEN:this.log.info("Connected to server"),await this.handler.connected();break;case f.RxStompState.CLOSED:await this.handler.disconnected(),this.log.info("Disconnected from server");break}}}),this.client.webSocketErrors$.subscribe({next:e=>{this.log.error(`Tunnel error, client disconnected ....${e}`)}}),this.client.stompErrors$.subscribe({next:e=>{if(e.headers.message){if(e.headers.message.includes("Failed to send message")){this.log.error("Error, forbidden access to the ressource. Please check your API key and worker ID."),this.reportError({type:"connection",level:"fatal",message:"Forbidden access to the resource, likely due to invalid API key or worker ID"});return}}else this.log.error(`STOMP Error: ${e.body}`)}}),this.listenerSub=this.client.watch(`${Ae}/${this.options.worker}`).subscribe(async e=>{if(!this.handler)return;let r;try{r=JSON.parse(e.body),r=new I(r)}catch(s){this.sendState("unknown",l.failure("Invalid request payload")),this.log.error(`Received invalid request payload: ${s.message}`);return}let o=Date.now();try{this.log.debug("Processing request "+r.id),this.ackMessage(r.id);let s=await this.handler.handle(r);s.executionTime=Date.now()-o,this.sendState(r.id,s)}catch(s){this.log.error(`Error processing request ${r.id}: ${s.message}`);let n=l.failure(s.message);n.executionTime=Date.now()-o,this.sendState(r.id,n)}}),this.log.info("Starting Outbound tunnel..."),this.client.activate(),this.intervalHandle=setInterval(async()=>{this.client.connected()?this.log.debug("Connection is healthy"):(this.log.warn("Connection is not healthy, attempting to reconnect..."),await this.client.deactivate({force:!0}),this.client.activate(),this.log.info("Reconnection attempt initiated"))},5e3)}async destroy(e=!1){this.tunnelSub?.unsubscribe(),await this.client.deactivate({force:e}),this.intervalHandle?.close()}ackMessage(e){this.log.debug("Sending ack for request "+e),this.client.publish({destination:be.replace("{requestId}",e),body:JSON.stringify({type:"ack"})})}sendState(e,r){this.log.debug("Sending result for request "+e+": "+r.state,r);let o=be.replace("{requestId}",e);this.client.publish({destination:o,body:JSON.stringify({type:"response",data:{state:r.state,message:r.message,code:r.code,executionTime:r.executionTime}})})}errorHandler;setErrorHandler(e){this.errorHandler=e}reportError(e){this.errorHandler&&this.errorHandler(e)}};Z=R(Ie),b=x(Z,0,"RequestHandlerService",ve,b),S(Z,1,b);var we={};function q(t){let e=we[t];return e||process.env[t]}function ee(t,e){we[t]=e}function ke(t){for(let e in t)t[e]||delete t[e];return t}var T=class extends L{service;constructor(){super()}init(e){let r=this.convertEnvToConfig(),o=this.convertOptionsToConfig(e),s={...r,...o};s.worker&&this.log.debug(`Prepare worker listening as: ...${s.worker.substring(20)}`),s.apiKey||(this.log.error("API key is required to start the request handler command. Please provide it via the WOOKSTER_API_KEY environment variable or the --api-key command line option."),process.exit(1)),this.service=new b({worker:s.worker,apiKey:s.apiKey,serverUrl:s.serverUrl})}start(){this.service?.start(),this.service?.setErrorHandler(e=>{this.log.error("An error occurred in the request handler service",{type:e.type,level:e.level,message:e.message,error:e.error?{message:e.error.message,cause:e.error.cause}:void 0}),e.level==="fatal"&&(this.log.error("Fatal error encountered, shutting down..."),process.exit(1))})}async destroy(){await this.service?.destroy(),this.log.info("Connection closed")}async forceDestroy(){await this.service?.destroy(!0)}convertEnvToConfig(){return ke({worker:q("WOOKSTER_WORKER_ID"),apiKey:q("WOOKSTER_API_KEY"),serverUrl:q("WOOKSTER_URL")})}convertOptionsToConfig(e){return ke({worker:e.worker,apiKey:e.apiKey,serverUrl:e.serverUrl})}setHandler(e){this.service?.setHandler(e)}};function te(t,e){let r=new t,o=_("command");o.debug("Handler initialisation.."),r.init(e),o.debug("Handler ready !"),r.start(),o.debug("Listening started."),(0,re.fromEvent)(process,"SIGINT").subscribe(async()=>{r.destroy(),o.info("Goodbye !"),process.exit(0)}),(0,re.fromEvent)(process,"SIGTERM").subscribe(async()=>{r.forceDestroy(),process.exit(0)}),process.stdin.resume()}var U=class{connected(){return Promise.resolve()}disconnected(){return Promise.resolve()}};var M=class t extends U{method;constructor(e){super(),this.method=e}handle(e){return this.method(e)}static from(e){return new t(e)}static forObject(e,r){let o=e[r];if(typeof o!="function")throw new Error(`Property ${String(r)} is not a function on the provided object`);return new t(s=>o.call(e,s))}};var Ve="X-Webhook-Signature",Re,oe,Ue;Re=[O()];var v=class extends(Ue=T){target;constructor(){super()}init(e){super.init(e),this.target=e.target,this.target||(this.log.error("Target URL is required for proxy executor"),process.exit(1)),this.log.info(`Proxying requests to: ${this.target}`);let r=this.generateHandler();this.setHandler(r),this.log.info("Proxy executor initialized successfully!")}generateHandler(){return new M(async e=>{this.log.info(`Proxying ${e.id} to ${this.target}`);try{let r=await fetch(this.target,{method:e.method,headers:{[Ve]:e.signature,...e.headers,"Content-Type":this.toContentType(e.type)},body:e.body});if(r.ok)return l.success("Request proxied successfully",r.status);let o=await r.text();return this.log.warn(`Proxy ${e.id} received non-2xx response`,{status:r.status}),this.log.debug(`Proxy ${e.id} body:`,{status:r.status,body:o}),l.failure(o,r.status)}catch(r){let o=r;return this.log.error("Error thrown during request",{request_id:e.id,error:{message:o.message,cause:o.cause}}),l.failure(o.message)}})}toContentType(e){switch(e){case"JSON":return"application/json";case"XML":return"application/xml";case"FORM_URLENCODED":return"application/x-www-form-urlencoded";case"PLAIN_TEXT":return"text/plain";default:return"application/octet-stream"}}};oe=R(Ue),v=x(oe,0,"ProxyExecutor",Re,v),S(oe,1,v);var D=$(require("node:fs")),ne=$(require("node:path")),W=$(require("node:vm"));var xe,se,Me;xe=[O()];var w=class extends(Me=T){constructor(){super()}init(e){super.init(e);let r=e.script;if(!r)throw new Error("Script path is required");this.log.info(`Loading script from: ${r}`);try{let o=new ie(r);this.setHandler(o),this.log.info(`Script ${o.handlerType} loaded successfully !`)}catch(o){this.log.error(`Failed to load script: ${o.message}`),process.exit(1)}}};se=R(Me),w=x(se,0,"ScriptExecutor",xe,w),S(se,1,w);var ie=class{constructor(e){this.path=e;this.loadScript(this.path)}method;handlerType="method";connected(){return Promise.resolve()}disconnected(){return Promise.resolve()}handle(e){return new Promise((r,o)=>{if(!this.method)return o(new Error("Method not loaded"));let s={ok:(n,i=200)=>l.success(n,i),error:(n,i=500)=>l.failure(n,i)};try{let n=this.method(e,s);if(n instanceof Promise){n.then(r).catch(o);return}r(n)}catch(n){o(n)}})}loadScript(e){let r=process.cwd()+"/"+e;if(!D.existsSync(r))throw new Error(`Script file not found at path: ${r}`);let o=D.readFileSync(r,"utf-8"),s=/^\/\/@wookster\/(\w+):?(\w+)?$/m,n=o.match(s);if(!n)throw new Error(Se);let i=n[1],c=n[2]||"";if(i!=="method"&&i!=="file")throw new Error(`Unsupported script type: ${i}. Supported types are 'method' and 'file',
|
|
3
|
+
|
|
4
|
+
${Se}`);this.handlerType=i,i==="method"?this.loadMethodScript(o,r,c):i==="file"&&this.loadFileScript(o,r)}getConsoleProxy(e){let r=_(e);function o(s){return s.map(n=>{if(typeof n=="string")return n;if(typeof n=="object")try{return JSON.stringify(n)}catch{return String(n)}else return String(n)}).join(" ")}return{log:(...s)=>r.info(o(s)),info:(...s)=>r.info(o(s)),warn:(...s)=>r.warn(o(s)),error:(...s)=>r.error(o(s)),debug:(...s)=>r.debug(o(s)),trace:(...s)=>r.debug(o(s)),dir:s=>r.debug(JSON.stringify(s,null,2)),assert:(s,...n)=>{s||r.error("Assertion failed: "+n.join(" "))}}}loadMethodScript(e,r,o){(!o||o.trim()==="")&&(o="handle");let s=new W.Script(e,{filename:r}),n=ne.default.basename(r),i=this.getConsoleProxy(n),c=W.createContext({console:i,exports:{},require,module:{}});s.runInContext(c);let m=c.exports;if(m&&typeof m[o]=="function"){i.debug(`Loaded method from exports: ${o}`),this.method=m[o];return}else if(typeof c[o]=="function"){i.debug(`Loaded method from context: ${o}`),this.method=c[o];return}else throw new Error(`Method ${o} not found in script`)}loadFileScript(e,r){let o=new W.Script(e,{filename:r}),s=ne.default.basename(r);this.method=n=>{let i,c={ok:(p,y=200)=>(i||(i=l.success(p,y)),i),error:(p,y=500)=>(i||(i=l.failure(p,y)),i)},m=W.createContext({console:this.getConsoleProxy(s),require,request:n,response:c});if(o.runInContext(m),!i)throw new Error("Script did not return a response. Please use response.ok() or response.error() to return a response.");return i}}},Se=`Script file is missing required header.
|
|
5
|
+
Please add a header in the following format at the top of your script file:
|
|
6
|
+
//@wookster/method:<function_name>
|
|
7
|
+
or
|
|
8
|
+
//@wookster/file
|
|
9
|
+
|
|
10
|
+
Ex:
|
|
11
|
+
//@wookster/method:handle
|
|
12
|
+
|
|
13
|
+
function handle(request, response) {
|
|
14
|
+
// your code here
|
|
15
|
+
return response.ok('Request handled successfully');
|
|
16
|
+
}
|
|
17
|
+
`;var N=class{mapping={timestamp:"timestamp",severity:"level",source:"source",message:"message",context:"context"};constructor(e){e&&(this.mapping={...this.mapping,...e})}log(e){let r={};r[this.mapping.timestamp]=e.timestamp.toISOString(),r[this.mapping.severity]=e.severity,r[this.mapping.source]=e.source,r[this.mapping.message]=e.message,Object.keys(e.context).length&&(r[this.mapping.context]=e.context),console.log(JSON.stringify(r))}};var G=class{log(){}};var De="{timestamp} {severity} -- {source} : {message} {context}",F=class{constructor(e=!0,r=De){this.color=e;this.template=r}log(e){let r=e.timestamp.toISOString(),o=this.prettySeverity(e.severity),s=this.prettySource(e.source),n=e.message,i=Object.keys(e.context).length?JSON.stringify(e.context):"";if(this.color)switch(e.severity){case"info":o=`\x1B[32m${o}\x1B[0m`;break;case"warn":o=`\x1B[33m${o}\x1B[0m`;break;case"error":o=`\x1B[31m${o}\x1B[0m`;break;case"debug":o=`\x1B[34m${o}\x1B[0m`;break}let c=this.template.replace("{timestamp}",r).replace("{severity}",o).replace("{source}",s).replace("{message}",n).replace("{context}",i);console.log(c)}prettySource(e){return e.length>30?e.substring(e.length-30):e.padEnd(30," ")}prettySeverity(e){return e.toUpperCase().padStart(5," ")}};function Ne(t){switch(t||(t=q("WOOKSTER_LOGGER")??"pretty"),t){case"json":A(N);break;case"pretty":A(F);break;case"noop":A(G);break;default:throw new Error(`Unknown logger type: ${t}`)}}function Ee(t){let e=t.opts();e.verbose&&fe("debug"),Ne(e.logger),ee("WOOKSTER_API_KEY",e.apiKey),ee("WOOKSTER_URL",e.serverUrl)}var h=new k.Command;h.name("wookster").description("Official CLI for Wookster. Connect workers to process or proxy webhook events from Virtual Hooks.").version("1.0.2");h.hook("preAction",Ee);h.addOption(new k.Option("--verbose").default(!1,"Enable verbose logging"));h.addOption(new k.Option("--logger <type>","Specify logger type").choices(["json","pretty","noop"]));h.addOption(new k.Option("-k, --api-key <apiKey>","Api key for authentication"));h.addOption(new k.Option("-u, --server-url <serverUrl>","Server URL to connect to"));h.command("worker-script").description("Connect to Wookster as a worker and execute a provided script for each incoming webhook event").requiredOption("-w, --worker <worker>","Worker identifier to process requests").requiredOption("-s, --script <script>","Path to the script to execute for each request").action(async t=>{te(w,t)});h.command("worker-proxy").description("Connect to Wookster as a worker and proxy each incoming webhook event to a specified target URL").requiredOption("-w, --worker <worker>","Worker identifier to process requests").requiredOption("-t, --target <target>","Target url to proxy webhook request (http.s)").action(async t=>{te(v,t)});h.parseAsync();
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooch-tickets/wookster-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A TypeScript cli library for connecting to Wookster's services",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"typescript": "^5"
|
|
7
7
|
},
|
|
8
8
|
"type": "commonjs",
|
|
9
9
|
"bin": {
|
|
10
|
-
"wookster": "
|
|
10
|
+
"wookster": "dist/index.js"
|
|
11
11
|
},
|
|
12
|
-
"main": "./dist/
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "
|
|
15
|
-
"dev": "
|
|
14
|
+
"build": "node build.js",
|
|
15
|
+
"dev": "nodemon --watch 'src/**/*.ts' --exec node build.js",
|
|
16
16
|
"start:dev": "concurrently \"npm run dev\" \"nodemon --watch 'dist/**/*.js' --exec 'node' dist/cli/index.js\"",
|
|
17
17
|
"lint": "eslint src/**/*.ts --fix",
|
|
18
18
|
"prepublishOnly": "npm run lint && npm run build"
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@types/node": "^25.0.3",
|
|
32
32
|
"@types/ws": "^8.5.4",
|
|
33
33
|
"concurrently": "^9.2.1",
|
|
34
|
+
"esbuild": "^0.27.2",
|
|
34
35
|
"eslint": "^8.57.1",
|
|
35
36
|
"globals": "^16.5.0",
|
|
36
37
|
"nodemon": "^3.1.11",
|
package/dist/cli/base-command.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseCommand = void 0;
|
|
4
|
-
exports.runCommand = runCommand;
|
|
5
|
-
const fromEvent_1 = require("rxjs/internal/observable/fromEvent");
|
|
6
|
-
class BaseCommand {
|
|
7
|
-
constructor() { }
|
|
8
|
-
init() {
|
|
9
|
-
}
|
|
10
|
-
start() {
|
|
11
|
-
}
|
|
12
|
-
destroy() {
|
|
13
|
-
}
|
|
14
|
-
forceDestroy() {
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.BaseCommand = BaseCommand;
|
|
18
|
-
function runCommand(command) {
|
|
19
|
-
command.init();
|
|
20
|
-
command.start();
|
|
21
|
-
(0, fromEvent_1.fromEvent)(process, 'SIGINT').subscribe(async () => {
|
|
22
|
-
command.destroy();
|
|
23
|
-
process.exit(0);
|
|
24
|
-
});
|
|
25
|
-
(0, fromEvent_1.fromEvent)(process, 'SIGTERM').subscribe(async () => {
|
|
26
|
-
command.forceDestroy();
|
|
27
|
-
process.exit(0);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseCommand = void 0;
|
|
4
|
-
exports.runCommand = runCommand;
|
|
5
|
-
const fromEvent_1 = require("rxjs/internal/observable/fromEvent");
|
|
6
|
-
class BaseCommand {
|
|
7
|
-
constructor() { }
|
|
8
|
-
init() {
|
|
9
|
-
}
|
|
10
|
-
start() {
|
|
11
|
-
}
|
|
12
|
-
destroy() {
|
|
13
|
-
}
|
|
14
|
-
forceDestroy() {
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.BaseCommand = BaseCommand;
|
|
18
|
-
function runCommand(command) {
|
|
19
|
-
command.init();
|
|
20
|
-
command.start();
|
|
21
|
-
(0, fromEvent_1.fromEvent)(process, 'SIGINT').subscribe(async () => {
|
|
22
|
-
command.destroy();
|
|
23
|
-
process.exit(0);
|
|
24
|
-
});
|
|
25
|
-
(0, fromEvent_1.fromEvent)(process, 'SIGTERM').subscribe(async () => {
|
|
26
|
-
command.forceDestroy();
|
|
27
|
-
process.exit(0);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
-
var _, done = false;
|
|
8
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
-
var context = {};
|
|
10
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
-
if (kind === "accessor") {
|
|
15
|
-
if (result === void 0) continue;
|
|
16
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
-
}
|
|
21
|
-
else if (_ = accept(result)) {
|
|
22
|
-
if (kind === "field") initializers.unshift(_);
|
|
23
|
-
else descriptor[key] = _;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
-
done = true;
|
|
28
|
-
};
|
|
29
|
-
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
-
var useValue = arguments.length > 2;
|
|
31
|
-
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
-
}
|
|
34
|
-
return useValue ? value : void 0;
|
|
35
|
-
};
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.BaseCommand = void 0;
|
|
38
|
-
exports.runCommand = runCommand;
|
|
39
|
-
const fromEvent_1 = require("rxjs/internal/observable/fromEvent");
|
|
40
|
-
const logger_decorator_1 = require("../../../client/logger/logger.decorator");
|
|
41
|
-
const env_1 = require("../../env");
|
|
42
|
-
let BaseCommand = (() => {
|
|
43
|
-
let _classDecorators = [(0, logger_decorator_1.Log)("main")];
|
|
44
|
-
let _classDescriptor;
|
|
45
|
-
let _classExtraInitializers = [];
|
|
46
|
-
let _classThis;
|
|
47
|
-
let _classSuper = logger_decorator_1.WithLogger;
|
|
48
|
-
var BaseCommand = class extends _classSuper {
|
|
49
|
-
static { _classThis = this; }
|
|
50
|
-
static {
|
|
51
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
52
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
53
|
-
BaseCommand = _classThis = _classDescriptor.value;
|
|
54
|
-
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
55
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
56
|
-
}
|
|
57
|
-
constructor() {
|
|
58
|
-
super();
|
|
59
|
-
}
|
|
60
|
-
init(opts) {
|
|
61
|
-
const env = this.convertEnvToConfig();
|
|
62
|
-
const optEnv = this.convertOptionsToConfig(opts);
|
|
63
|
-
}
|
|
64
|
-
start() {
|
|
65
|
-
this.log.info(`Starting client at ${new Date().toISOString()}`);
|
|
66
|
-
}
|
|
67
|
-
destroy() {
|
|
68
|
-
}
|
|
69
|
-
forceDestroy() {
|
|
70
|
-
}
|
|
71
|
-
convertEnvToConfig() {
|
|
72
|
-
return {
|
|
73
|
-
worker: (0, env_1.getEnvVar)("WOOKSTER_WORKER_ID"),
|
|
74
|
-
apiKey: (0, env_1.getEnvVar)("WOOKSTER_API_KEY"),
|
|
75
|
-
serverUrl: (0, env_1.getEnvVar)("WOOKSTER_URL"),
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
convertOptionsToConfig(options) {
|
|
79
|
-
return {
|
|
80
|
-
worker: options.worker,
|
|
81
|
-
apiKey: options.apiKey,
|
|
82
|
-
serverUrl: options.serverUrl
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
return BaseCommand = _classThis;
|
|
87
|
-
})();
|
|
88
|
-
exports.BaseCommand = BaseCommand;
|
|
89
|
-
function runCommand(command, options) {
|
|
90
|
-
command.init(options);
|
|
91
|
-
command.start();
|
|
92
|
-
(0, fromEvent_1.fromEvent)(process, 'SIGINT').subscribe(async () => {
|
|
93
|
-
command.destroy();
|
|
94
|
-
process.exit(0);
|
|
95
|
-
});
|
|
96
|
-
(0, fromEvent_1.fromEvent)(process, 'SIGTERM').subscribe(async () => {
|
|
97
|
-
command.forceDestroy();
|
|
98
|
-
process.exit(0);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseRequestHandlerCommand = void 0;
|
|
4
|
-
exports.runCommand = runCommand;
|
|
5
|
-
const fromEvent_1 = require("rxjs/internal/observable/fromEvent");
|
|
6
|
-
const global_logger_1 = require("../../../client/logger/global-logger");
|
|
7
|
-
const logger_decorator_1 = require("../../../client/logger/logger.decorator");
|
|
8
|
-
const request_handler_service_1 = require("../../../client/services/request-handler.service");
|
|
9
|
-
const env_1 = require("../../env");
|
|
10
|
-
function cleanNull(param) {
|
|
11
|
-
for (const paramKey in param) {
|
|
12
|
-
if (!param[paramKey]) {
|
|
13
|
-
delete param[paramKey];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return param;
|
|
17
|
-
}
|
|
18
|
-
class BaseRequestHandlerCommand extends logger_decorator_1.WithLogger {
|
|
19
|
-
service;
|
|
20
|
-
constructor() {
|
|
21
|
-
super();
|
|
22
|
-
}
|
|
23
|
-
init(opts) {
|
|
24
|
-
const env = this.convertEnvToConfig();
|
|
25
|
-
const optEnv = this.convertOptionsToConfig(opts);
|
|
26
|
-
//env is base of the config, overridden by command line options
|
|
27
|
-
const config = {
|
|
28
|
-
...env,
|
|
29
|
-
...optEnv
|
|
30
|
-
};
|
|
31
|
-
if (config.worker) {
|
|
32
|
-
this.log.debug(`Prepare worker listening as: ...${config.worker.substring(20)}`);
|
|
33
|
-
}
|
|
34
|
-
if (!config.apiKey) {
|
|
35
|
-
this.log.error("API key is required to start the request handler command. Please provide it via the WOOKSTER_API_KEY environment variable or the --api-key command line option.");
|
|
36
|
-
process.exit(1);
|
|
37
|
-
}
|
|
38
|
-
this.service = new request_handler_service_1.RequestHandlerService({
|
|
39
|
-
worker: config.worker,
|
|
40
|
-
apiKey: config.apiKey,
|
|
41
|
-
serverUrl: config.serverUrl,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
start() {
|
|
45
|
-
this.service?.start();
|
|
46
|
-
this.service?.setErrorHandler((error) => {
|
|
47
|
-
this.log.error("An error occurred in the request handler service", {
|
|
48
|
-
type: error.type,
|
|
49
|
-
level: error.level,
|
|
50
|
-
message: error.message,
|
|
51
|
-
error: error.error ? {
|
|
52
|
-
message: error.error.message,
|
|
53
|
-
cause: error.error.cause
|
|
54
|
-
} : undefined
|
|
55
|
-
});
|
|
56
|
-
if (error.level === 'fatal') {
|
|
57
|
-
this.log.error("Fatal error encountered, shutting down...");
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
async destroy() {
|
|
63
|
-
await this.service?.destroy();
|
|
64
|
-
this.log.info("Connection closed");
|
|
65
|
-
}
|
|
66
|
-
async forceDestroy() {
|
|
67
|
-
await this.service?.destroy(true);
|
|
68
|
-
}
|
|
69
|
-
convertEnvToConfig() {
|
|
70
|
-
return cleanNull({
|
|
71
|
-
worker: (0, env_1.getEnvVar)("WOOKSTER_WORKER_ID"),
|
|
72
|
-
apiKey: (0, env_1.getEnvVar)("WOOKSTER_API_KEY"),
|
|
73
|
-
serverUrl: (0, env_1.getEnvVar)("WOOKSTER_URL"),
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
convertOptionsToConfig(options) {
|
|
77
|
-
return cleanNull({
|
|
78
|
-
worker: options.worker,
|
|
79
|
-
apiKey: options.apiKey,
|
|
80
|
-
serverUrl: options.serverUrl
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
setHandler(handler) {
|
|
84
|
-
this.service?.setHandler(handler);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.BaseRequestHandlerCommand = BaseRequestHandlerCommand;
|
|
88
|
-
function runCommand(factory, options) {
|
|
89
|
-
const command = new factory();
|
|
90
|
-
const commandProcessLogger = (0, global_logger_1.generateLogService)('command');
|
|
91
|
-
commandProcessLogger.debug("Handler initialisation..");
|
|
92
|
-
command.init(options);
|
|
93
|
-
commandProcessLogger.debug("Handler ready !");
|
|
94
|
-
command.start();
|
|
95
|
-
commandProcessLogger.debug("Listening started.");
|
|
96
|
-
(0, fromEvent_1.fromEvent)(process, 'SIGINT').subscribe(async () => {
|
|
97
|
-
command.destroy();
|
|
98
|
-
commandProcessLogger.info("Goodbye !");
|
|
99
|
-
process.exit(0);
|
|
100
|
-
});
|
|
101
|
-
(0, fromEvent_1.fromEvent)(process, 'SIGTERM').subscribe(async () => {
|
|
102
|
-
command.forceDestroy();
|
|
103
|
-
process.exit(0);
|
|
104
|
-
});
|
|
105
|
-
process.stdin.resume();
|
|
106
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
-
var _, done = false;
|
|
8
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
-
var context = {};
|
|
10
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
-
if (kind === "accessor") {
|
|
15
|
-
if (result === void 0) continue;
|
|
16
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
-
}
|
|
21
|
-
else if (_ = accept(result)) {
|
|
22
|
-
if (kind === "field") initializers.unshift(_);
|
|
23
|
-
else descriptor[key] = _;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
-
done = true;
|
|
28
|
-
};
|
|
29
|
-
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
-
var useValue = arguments.length > 2;
|
|
31
|
-
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
-
}
|
|
34
|
-
return useValue ? value : void 0;
|
|
35
|
-
};
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.ProxyExecutor = void 0;
|
|
38
|
-
const method_request_handler_1 = require("../../../client/handlers/method.request-handler");
|
|
39
|
-
const logger_decorator_1 = require("../../../client/logger/logger.decorator");
|
|
40
|
-
const handler_models_1 = require("../../../client/models/handler-models");
|
|
41
|
-
const base_request_handler_command_1 = require("./base-request-handler-command");
|
|
42
|
-
const WEBHOOK_SIGN_HEADER = 'X-Webhook-Signature';
|
|
43
|
-
let ProxyExecutor = (() => {
|
|
44
|
-
let _classDecorators = [(0, logger_decorator_1.Log)()];
|
|
45
|
-
let _classDescriptor;
|
|
46
|
-
let _classExtraInitializers = [];
|
|
47
|
-
let _classThis;
|
|
48
|
-
let _classSuper = base_request_handler_command_1.BaseRequestHandlerCommand;
|
|
49
|
-
var ProxyExecutor = class extends _classSuper {
|
|
50
|
-
static { _classThis = this; }
|
|
51
|
-
static {
|
|
52
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
53
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
54
|
-
ProxyExecutor = _classThis = _classDescriptor.value;
|
|
55
|
-
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
56
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
57
|
-
}
|
|
58
|
-
target;
|
|
59
|
-
constructor() {
|
|
60
|
-
super();
|
|
61
|
-
}
|
|
62
|
-
init(opts) {
|
|
63
|
-
super.init(opts);
|
|
64
|
-
this.target = opts.target;
|
|
65
|
-
if (!this.target) {
|
|
66
|
-
this.log.error('Target URL is required for proxy executor');
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
this.log.info(`Proxying requests to: ${this.target}`);
|
|
70
|
-
const handler = this.generateHandler();
|
|
71
|
-
this.setHandler(handler);
|
|
72
|
-
this.log.info(`Proxy executor initialized successfully!`);
|
|
73
|
-
}
|
|
74
|
-
generateHandler() {
|
|
75
|
-
return new method_request_handler_1.MethodRequestHandler(async (request) => {
|
|
76
|
-
this.log.info(`Proxying ${request.id} to ${this.target}`);
|
|
77
|
-
try {
|
|
78
|
-
const res = await fetch(this.target, {
|
|
79
|
-
method: request.method,
|
|
80
|
-
headers: {
|
|
81
|
-
[WEBHOOK_SIGN_HEADER]: request.signature,
|
|
82
|
-
...request.headers,
|
|
83
|
-
'Content-Type': this.toContentType(request.type)
|
|
84
|
-
},
|
|
85
|
-
body: request.body
|
|
86
|
-
});
|
|
87
|
-
if (res.ok) {
|
|
88
|
-
return handler_models_1.WebhookResult.success('Request proxied successfully', res.status);
|
|
89
|
-
}
|
|
90
|
-
const body = await res.text();
|
|
91
|
-
this.log.warn(`Proxy ${request.id} received non-2xx response`, {
|
|
92
|
-
status: res.status
|
|
93
|
-
});
|
|
94
|
-
this.log.debug(`Proxy ${request.id} body:`, {
|
|
95
|
-
status: res.status,
|
|
96
|
-
body: body
|
|
97
|
-
});
|
|
98
|
-
return handler_models_1.WebhookResult.failure(body, res.status);
|
|
99
|
-
}
|
|
100
|
-
catch (e) {
|
|
101
|
-
const error = e;
|
|
102
|
-
this.log.error('Error thrown during request', {
|
|
103
|
-
request_id: request.id,
|
|
104
|
-
error: {
|
|
105
|
-
message: error.message,
|
|
106
|
-
cause: error.cause
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
return handler_models_1.WebhookResult.failure(error.message);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
toContentType(type) {
|
|
114
|
-
switch (type) {
|
|
115
|
-
case 'JSON':
|
|
116
|
-
return 'application/json';
|
|
117
|
-
case 'XML':
|
|
118
|
-
return 'application/xml';
|
|
119
|
-
case 'FORM_URLENCODED':
|
|
120
|
-
return 'application/x-www-form-urlencoded';
|
|
121
|
-
case 'PLAIN_TEXT':
|
|
122
|
-
return 'text/plain';
|
|
123
|
-
default:
|
|
124
|
-
return 'application/octet-stream';
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
return ProxyExecutor = _classThis;
|
|
129
|
-
})();
|
|
130
|
-
exports.ProxyExecutor = ProxyExecutor;
|