@wooch-tickets/wookster-cli 1.0.0

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/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @wookster/client
2
+
3
+ To install dependencies:
4
+
5
+ ```bash
6
+ bun install
7
+ ```
8
+
9
+ To run:
10
+
11
+ ```bash
12
+ bun run index.ts
13
+ ```
14
+
15
+ This project was created using `bun init` in bun v1.3.2. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
@@ -0,0 +1,29 @@
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
+ }
@@ -0,0 +1,29 @@
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
+ }
@@ -0,0 +1,100 @@
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
+ }
@@ -0,0 +1,106 @@
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
+ }
@@ -0,0 +1,130 @@
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;