api-response-manager 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/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "api-response-manager",
3
+ "version": "1.0.0",
4
+ "description": "Command-line interface for API Response Manager",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "arm": "bin/arm.js"
8
+ },
9
+ "scripts": {
10
+ "test": "jest",
11
+ "link": "npm link"
12
+ },
13
+ "keywords": [
14
+ "api",
15
+ "testing",
16
+ "tunnel",
17
+ "webhook",
18
+ "cli",
19
+ "developer-tools"
20
+ ],
21
+ "author": "Vijay Singh Purohit",
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "commander": "^11.1.0",
25
+ "axios": "^1.6.2",
26
+ "chalk": "^4.1.2",
27
+ "inquirer": "^8.2.5",
28
+ "ora": "^5.4.1",
29
+ "ws": "^8.14.2",
30
+ "dotenv": "^16.3.1",
31
+ "conf": "^10.2.0",
32
+ "boxen": "^5.1.2",
33
+ "cli-table3": "^0.6.3",
34
+ "update-notifier": "^6.0.2"
35
+ },
36
+ "devDependencies": {
37
+ "jest": "^29.7.0"
38
+ },
39
+ "engines": {
40
+ "node": ">=14.0.0"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/vijaypurohit322/api-response-manager.git"
45
+ },
46
+ "bugs": {
47
+ "url": "https://github.com/vijaypurohit322/api-response-manager/issues"
48
+ },
49
+ "homepage": "https://github.com/vijaypurohit322/api-response-manager#readme"
50
+ }
package/utils/api.js ADDED
@@ -0,0 +1,145 @@
1
+ const axios = require('axios');
2
+ const config = require('./config');
3
+ const chalk = require('chalk');
4
+
5
+ class APIClient {
6
+ constructor() {
7
+ this.baseURL = config.get('apiUrl') || 'http://localhost:5000/api';
8
+ this.client = axios.create({
9
+ baseURL: this.baseURL,
10
+ timeout: 30000,
11
+ headers: {
12
+ 'Content-Type': 'application/json'
13
+ }
14
+ });
15
+
16
+ // Add auth token to requests
17
+ this.client.interceptors.request.use((config) => {
18
+ const token = this.getToken();
19
+ if (token) {
20
+ config.headers['x-auth-token'] = token;
21
+ }
22
+ return config;
23
+ });
24
+
25
+ // Handle errors
26
+ this.client.interceptors.response.use(
27
+ (response) => response,
28
+ (error) => {
29
+ if (error.response?.status === 401) {
30
+ console.error(chalk.red('Authentication failed. Please run: arm login'));
31
+ process.exit(1);
32
+ }
33
+ throw error;
34
+ }
35
+ );
36
+ }
37
+
38
+ getToken() {
39
+ return config.get('token');
40
+ }
41
+
42
+ setToken(token) {
43
+ config.set('token', token);
44
+ }
45
+
46
+ clearToken() {
47
+ config.delete('token');
48
+ }
49
+
50
+ // Auth
51
+ async login(email, password) {
52
+ const response = await this.client.post('/auth/login', { email, password });
53
+ return response.data;
54
+ }
55
+
56
+ async register(name, email, password) {
57
+ const response = await this.client.post('/auth/register', { name, email, password });
58
+ return response.data;
59
+ }
60
+
61
+ // Tunnels
62
+ async createTunnel(data) {
63
+ const response = await this.client.post('/tunnels', data);
64
+ return response.data;
65
+ }
66
+
67
+ async getTunnels() {
68
+ const response = await this.client.get('/tunnels');
69
+ return response.data;
70
+ }
71
+
72
+ async getTunnel(id) {
73
+ const response = await this.client.get(`/tunnels/${id}`);
74
+ return response.data;
75
+ }
76
+
77
+ async deleteTunnel(id) {
78
+ const response = await this.client.delete(`/tunnels/${id}`);
79
+ return response.data;
80
+ }
81
+
82
+ async getTunnelStats(id) {
83
+ const response = await this.client.get(`/tunnels/${id}/stats`);
84
+ return response.data;
85
+ }
86
+
87
+ async getTunnelRequests(id, params = {}) {
88
+ const response = await this.client.get(`/tunnels/${id}/requests`, { params });
89
+ return response.data;
90
+ }
91
+
92
+ // Webhooks
93
+ async createWebhook(data) {
94
+ const response = await this.client.post('/webhooks', data);
95
+ return response.data;
96
+ }
97
+
98
+ async getWebhooks() {
99
+ const response = await this.client.get('/webhooks');
100
+ return response.data;
101
+ }
102
+
103
+ async getWebhook(id) {
104
+ const response = await this.client.get(`/webhooks/${id}`);
105
+ return response.data;
106
+ }
107
+
108
+ async deleteWebhook(id) {
109
+ const response = await this.client.delete(`/webhooks/${id}`);
110
+ return response.data;
111
+ }
112
+
113
+ async getWebhookRequests(id, params = {}) {
114
+ const response = await this.client.get(`/webhooks/${id}/requests`, { params });
115
+ return response.data;
116
+ }
117
+
118
+ async replayWebhookRequest(webhookId, requestId) {
119
+ const response = await this.client.post(`/webhooks/${webhookId}/requests/${requestId}/replay`);
120
+ return response.data;
121
+ }
122
+
123
+ // Projects
124
+ async getProjects() {
125
+ const response = await this.client.get('/projects');
126
+ return response.data;
127
+ }
128
+
129
+ async createProject(data) {
130
+ const response = await this.client.post('/projects', data);
131
+ return response.data;
132
+ }
133
+
134
+ async getProject(id) {
135
+ const response = await this.client.get(`/projects/${id}`);
136
+ return response.data;
137
+ }
138
+
139
+ async getProjectResponses(id, params = {}) {
140
+ const response = await this.client.get(`/projects/${id}/responses`, { params });
141
+ return response.data;
142
+ }
143
+ }
144
+
145
+ module.exports = new APIClient();
@@ -0,0 +1,40 @@
1
+ const Conf = require('conf');
2
+ const path = require('path');
3
+
4
+ const config = new Conf({
5
+ projectName: 'arm-cli',
6
+ defaults: {
7
+ apiUrl: 'http://localhost:5000/api',
8
+ token: null,
9
+ userId: null,
10
+ email: null,
11
+ defaultTunnelPort: 3000,
12
+ defaultWebhookExpiry: 86400 // 24 hours
13
+ },
14
+ schema: {
15
+ apiUrl: {
16
+ type: 'string',
17
+ format: 'uri'
18
+ },
19
+ token: {
20
+ type: ['string', 'null']
21
+ },
22
+ userId: {
23
+ type: ['string', 'null']
24
+ },
25
+ email: {
26
+ type: ['string', 'null']
27
+ },
28
+ defaultTunnelPort: {
29
+ type: 'number',
30
+ minimum: 1,
31
+ maximum: 65535
32
+ },
33
+ defaultWebhookExpiry: {
34
+ type: 'number',
35
+ minimum: 3600
36
+ }
37
+ }
38
+ });
39
+
40
+ module.exports = config;