@qodalis/cli-curl 0.0.3 → 2.0.0-beta.1

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,20 +0,0 @@
1
- import { CliProcessCommand, CliProcessorMetadata, ICliCommandProcessor, ICliExecutionContext } from '@qodalis/cli-core';
2
- import * as i0 from "@angular/core";
3
- export declare class CliCurlCommandProcessor implements ICliCommandProcessor {
4
- command: string;
5
- description: string;
6
- author: import("@qodalis/cli-core").ICliCommandAuthor;
7
- version: string;
8
- processors?: ICliCommandProcessor[] | undefined;
9
- metadata?: CliProcessorMetadata | undefined;
10
- constructor();
11
- processCommand(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
12
- initialize(context: ICliExecutionContext): Promise<void>;
13
- private registerSubProcessors;
14
- private executeRequest;
15
- private generateCurlCommand;
16
- private rewriteUrlToProxy;
17
- writeDescription(context: ICliExecutionContext): void;
18
- static ɵfac: i0.ɵɵFactoryDeclaration<CliCurlCommandProcessor, never>;
19
- static ɵprov: i0.ɵɵInjectableDeclaration<CliCurlCommandProcessor>;
20
- }
package/lib/version.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const LIBRARY_VERSION = "0.0.3";
package/umd/index.js DELETED
@@ -1,257 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('@qodalis/cli-core'), require('@angular/core')) :
3
- typeof define === 'function' && define.amd ? define(['@qodalis/cli-core', '@angular/core'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.cliCore, global.ngCore));
5
- })(this, (function (cliCore, core) { 'use strict';
6
-
7
- /******************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
22
-
23
-
24
- function __decorate(decorators, target, key, desc) {
25
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
26
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
27
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
28
- return c > 3 && r && Object.defineProperty(target, key, r), r;
29
- }
30
-
31
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
32
- var e = new Error(message);
33
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
34
- };
35
-
36
- // Automatically generated during build
37
- const LIBRARY_VERSION = '0.0.3';
38
-
39
- let CliCurlCommandProcessor = class CliCurlCommandProcessor {
40
- constructor() {
41
- this.command = 'curl';
42
- this.description = 'A command-line tool to execute HTTP requests on your server. Supports GET, POST, PUT, DELETE, headers, and body data.';
43
- this.author = cliCore.DefaultLibraryAuthor;
44
- this.version = LIBRARY_VERSION;
45
- this.processors = [];
46
- this.metadata = {
47
- icon: '🌐',
48
- };
49
- this.registerSubProcessors();
50
- }
51
- async processCommand(command, context) {
52
- context.executor.showHelp(command, context);
53
- }
54
- async initialize(context) { }
55
- registerSubProcessors() {
56
- this.processors = [
57
- {
58
- command: 'get',
59
- description: 'Perform an HTTP GET request',
60
- valueRequired: true,
61
- parameters: [
62
- {
63
- name: 'header',
64
- aliases: ['H'],
65
- type: 'array',
66
- description: 'Add custom headers. Accept multiple headers.',
67
- required: false,
68
- },
69
- {
70
- name: 'proxy',
71
- type: 'boolean',
72
- description: 'Use procy',
73
- required: false,
74
- },
75
- ],
76
- processCommand: async (command, context) => {
77
- await this.executeRequest('GET', command, context);
78
- },
79
- },
80
- {
81
- command: 'post',
82
- description: 'Perform an HTTP POST request',
83
- valueRequired: true,
84
- parameters: [
85
- {
86
- name: 'header',
87
- aliases: ['H'],
88
- type: 'array',
89
- description: 'Add custom headers',
90
- required: false,
91
- },
92
- {
93
- name: 'data',
94
- aliases: ['d'],
95
- type: 'string',
96
- description: 'Request body',
97
- required: false,
98
- },
99
- {
100
- name: 'proxy',
101
- type: 'boolean',
102
- description: 'Use procy',
103
- required: false,
104
- },
105
- ],
106
- processCommand: async (command, context) => {
107
- await this.executeRequest('POST', command, context);
108
- },
109
- },
110
- {
111
- command: 'put',
112
- description: 'Perform an HTTP PUT request',
113
- valueRequired: true,
114
- parameters: [
115
- {
116
- name: 'header',
117
- aliases: ['H'],
118
- type: 'array',
119
- description: 'Add custom headers',
120
- required: false,
121
- },
122
- {
123
- name: 'data',
124
- aliases: ['d'],
125
- type: 'string',
126
- description: 'Request body',
127
- required: false,
128
- },
129
- {
130
- name: 'proxy',
131
- type: 'boolean',
132
- description: 'Use procy',
133
- required: false,
134
- },
135
- ],
136
- processCommand: async (command, context) => {
137
- await this.executeRequest('PUT', command, context);
138
- },
139
- },
140
- {
141
- command: 'delete',
142
- description: 'Perform an HTTP DELETE request',
143
- valueRequired: true,
144
- parameters: [
145
- {
146
- name: 'header',
147
- aliases: ['H'],
148
- type: 'array',
149
- description: 'Add custom headers',
150
- required: false,
151
- },
152
- {
153
- name: 'proxy',
154
- type: 'boolean',
155
- description: 'Use procy',
156
- required: false,
157
- },
158
- ],
159
- processCommand: async (command, context) => {
160
- await this.executeRequest('DELETE', command, context);
161
- },
162
- },
163
- ];
164
- }
165
- async executeRequest(method, command, context) {
166
- const url = command.value;
167
- const headers = command.args['header'] || command.args['H'] || [];
168
- const data = command.args['data'] || command.args['d'];
169
- const verbose = !!command.args['verbose'];
170
- const useProxy = !!command.args['proxy'];
171
- if (!url) {
172
- context.writer.writeError('URL is required.');
173
- return;
174
- }
175
- // Prepare headers
176
- const headersObject = headers.reduce((acc, header) => {
177
- const [key, value] = header.split(':').map((str) => str.trim());
178
- if (key && value)
179
- acc[key] = value;
180
- return acc;
181
- }, {});
182
- // Prepare request options
183
- const options = {
184
- method,
185
- headers: headersObject,
186
- body: data ? JSON.stringify(JSON.parse(data)) : undefined,
187
- };
188
- try {
189
- const requestUrl = useProxy ? this.rewriteUrlToProxy(url) : url;
190
- const response = await fetch(requestUrl, options);
191
- const text = await response.text();
192
- context.writer.writeSuccess('Request successful:');
193
- if (verbose) {
194
- context.writer.writeln(`Status: ${response.status}`);
195
- context.writer.writeln(`Headers: ${JSON.stringify(response.headers, null, 2)}`);
196
- }
197
- context.writer.writeln(text);
198
- context.process.output(text);
199
- }
200
- catch (error) {
201
- context.writer.writeError(`Request failed: ${error}`);
202
- context.process.exit(-1);
203
- }
204
- finally {
205
- context.writer.writeln();
206
- context.writer.writeInfo('Equivalent curl command:');
207
- context.writer.writeln(this.generateCurlCommand(url, method, headers, data));
208
- }
209
- }
210
- generateCurlCommand(url, method, headers, data) {
211
- const headerString = headers.map((h) => `-H "${h}"`).join(' ');
212
- const dataString = data ? `-d '${data}'` : '';
213
- return `curl -X ${method} ${headerString} ${dataString} "${url}"`;
214
- }
215
- rewriteUrlToProxy(originalUrl) {
216
- const regex = /^(https?):\/\/([^\/]+)(\/.*)?$/i;
217
- const match = originalUrl.match(regex);
218
- if (!match) {
219
- throw new Error('Invalid URL provided');
220
- }
221
- const scheme = match[1]; // 'http' or 'https'
222
- const domain = match[2]; // domain.com
223
- const path = match[3] || '/'; // /path or '/'
224
- return `https://proxy.qodalis.com/proxy/${scheme}/${domain}${path}`;
225
- }
226
- writeDescription(context) {
227
- const { writer } = context;
228
- writer.writeln(this.description);
229
- writer.writeln();
230
- writer.writeln('📋 Usage:');
231
- writer.writeln(` ${writer.wrapInColor('curl <method> <url> [options]', cliCore.CliForegroundColor.Cyan)}`);
232
- writer.writeln();
233
- writer.writeln('⚙️ Options:');
234
- writer.writeln(` ${writer.wrapInColor('-H, --header', cliCore.CliForegroundColor.Yellow)} Add custom headers`);
235
- writer.writeln(` ${writer.wrapInColor('-d, --data', cliCore.CliForegroundColor.Yellow)} Add request body (JSON)`);
236
- writer.writeln(` ${writer.wrapInColor('--verbose', cliCore.CliForegroundColor.Yellow)} Print detailed response (status, headers)`);
237
- writer.writeln(` ${writer.wrapInColor('--proxy', cliCore.CliForegroundColor.Yellow)} Route request through proxy`);
238
- writer.writeln();
239
- writer.writeln('📝 Examples:');
240
- writer.writeln(` curl get https://api.example.com/users`);
241
- writer.writeln(` curl post https://api.example.com/users -d='{"name":"John"}' -H="Content-Type: application/json"`);
242
- writer.writeln(` curl delete https://api.example.com/users/1 --proxy`);
243
- writer.writeln();
244
- writer.writeWarning('⚠️ The server must allow CORS for this tool to work');
245
- }
246
- };
247
- CliCurlCommandProcessor = __decorate([
248
- core.Injectable()
249
- ], CliCurlCommandProcessor);
250
-
251
- const module = {
252
- name: '@qodalis/cli-curl',
253
- processors: [new CliCurlCommandProcessor()],
254
- };
255
- cliCore.bootUmdModule(module);
256
-
257
- }));