carto-cli 0.1.0-rc.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.
- package/.nvmrc +1 -0
- package/ARCHITECTURE.md +497 -0
- package/CHANGELOG.md +28 -0
- package/LICENSE +15 -0
- package/MAP_JSON.md +516 -0
- package/README.md +1595 -0
- package/WORKFLOW_JSON.md +623 -0
- package/dist/api.js +489 -0
- package/dist/auth-oauth.js +485 -0
- package/dist/auth-server.js +432 -0
- package/dist/browser.js +30 -0
- package/dist/colors.js +45 -0
- package/dist/commands/activity.js +427 -0
- package/dist/commands/admin.js +177 -0
- package/dist/commands/ai.js +489 -0
- package/dist/commands/auth.js +652 -0
- package/dist/commands/connections.js +412 -0
- package/dist/commands/credentials.js +606 -0
- package/dist/commands/imports.js +234 -0
- package/dist/commands/maps.js +1022 -0
- package/dist/commands/org.js +195 -0
- package/dist/commands/sql.js +326 -0
- package/dist/commands/users.js +459 -0
- package/dist/commands/workflows.js +1025 -0
- package/dist/config.js +320 -0
- package/dist/download.js +108 -0
- package/dist/help.js +285 -0
- package/dist/http.js +139 -0
- package/dist/index.js +1133 -0
- package/dist/logo.js +11 -0
- package/dist/prompt.js +67 -0
- package/dist/schedule-parser.js +287 -0
- package/jest.config.ts +43 -0
- package/package.json +53 -0
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.credentialsList = credentialsList;
|
|
4
|
+
exports.credentialsCreateToken = credentialsCreateToken;
|
|
5
|
+
exports.credentialsCreateSPA = credentialsCreateSPA;
|
|
6
|
+
exports.credentialsCreateM2M = credentialsCreateM2M;
|
|
7
|
+
exports.credentialsGetToken = credentialsGetToken;
|
|
8
|
+
exports.credentialsGetOAuth = credentialsGetOAuth;
|
|
9
|
+
exports.credentialsUpdateToken = credentialsUpdateToken;
|
|
10
|
+
exports.credentialsUpdateOAuth = credentialsUpdateOAuth;
|
|
11
|
+
exports.credentialsDeleteToken = credentialsDeleteToken;
|
|
12
|
+
exports.credentialsDeleteOAuth = credentialsDeleteOAuth;
|
|
13
|
+
const api_1 = require("../api");
|
|
14
|
+
const colors_1 = require("../colors");
|
|
15
|
+
const prompt_1 = require("../prompt");
|
|
16
|
+
/**
|
|
17
|
+
* List all credentials or specific type
|
|
18
|
+
*/
|
|
19
|
+
async function credentialsList(type, options, token, baseUrl, jsonOutput, debug = false, profile) {
|
|
20
|
+
try {
|
|
21
|
+
const client = await api_1.ApiClient.create(token, baseUrl, debug, profile);
|
|
22
|
+
const results = {};
|
|
23
|
+
// Determine what to list
|
|
24
|
+
const listTokens = !type || type === 'tokens';
|
|
25
|
+
const listSPA = !type || type === 'spa' || type === 'oauth';
|
|
26
|
+
const listM2M = !type || type === 'm2m' || type === 'oauth';
|
|
27
|
+
// Fetch API Access Tokens
|
|
28
|
+
if (listTokens) {
|
|
29
|
+
try {
|
|
30
|
+
const tokens = await client.get('/v3/tokens');
|
|
31
|
+
results.tokens = Array.isArray(tokens) ? tokens : (tokens.data || tokens.results || []);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
results.tokens = [];
|
|
35
|
+
results.tokensError = err.message;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Fetch SPA OAuth Clients
|
|
39
|
+
if (listSPA) {
|
|
40
|
+
try {
|
|
41
|
+
const spaClients = await client.getAccounts('/oauth-clients?type=spa');
|
|
42
|
+
results.spa = Array.isArray(spaClients) ? spaClients : [];
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
results.spa = [];
|
|
46
|
+
results.spaError = err.message;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Fetch M2M OAuth Clients
|
|
50
|
+
if (listM2M) {
|
|
51
|
+
try {
|
|
52
|
+
const m2mClients = await client.getAccounts('/oauth-clients?type=m2m');
|
|
53
|
+
results.m2m = Array.isArray(m2mClients) ? m2mClients : [];
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
results.m2m = [];
|
|
57
|
+
results.m2mError = err.message;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (jsonOutput) {
|
|
61
|
+
console.log(JSON.stringify(results));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Display API Access Tokens
|
|
65
|
+
if (results.tokens) {
|
|
66
|
+
console.log((0, colors_1.bold)(`\n=== API Access Tokens (${results.tokens.length}) ===\n`));
|
|
67
|
+
if (results.tokens.length === 0) {
|
|
68
|
+
console.log((0, colors_1.dim)(' No API Access Tokens found'));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
results.tokens.forEach((t) => {
|
|
72
|
+
console.log((0, colors_1.bold)('Token: ') + t.token.substring(0, 20) + '...');
|
|
73
|
+
console.log(' Allowed APIs: ' + (t.allowed_apis || []).join(', '));
|
|
74
|
+
if (t.grants && t.grants.length > 0) {
|
|
75
|
+
console.log(' Grants:');
|
|
76
|
+
t.grants.forEach((grant) => {
|
|
77
|
+
console.log(` - ${grant.connection_name} → ${grant.source}`);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
console.log(' Created: ' + new Date(t.created_at).toLocaleString());
|
|
81
|
+
console.log('');
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (results.tokensError) {
|
|
86
|
+
console.log((0, colors_1.error)(` Error fetching tokens: ${results.tokensError}`));
|
|
87
|
+
}
|
|
88
|
+
// Display SPA OAuth Clients
|
|
89
|
+
if (results.spa) {
|
|
90
|
+
console.log((0, colors_1.bold)(`\n=== SPA OAuth Clients (${results.spa.length}) ===\n`));
|
|
91
|
+
if (results.spa.length === 0) {
|
|
92
|
+
console.log((0, colors_1.dim)(' No SPA OAuth Clients found'));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
results.spa.forEach((client) => {
|
|
96
|
+
console.log((0, colors_1.bold)(client.title) + (0, colors_1.dim)(` (${client.client_id})`));
|
|
97
|
+
console.log(' Type: SPA');
|
|
98
|
+
console.log(' Created: ' + new Date(client.createdAt).toLocaleString());
|
|
99
|
+
console.log('');
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (results.spaError) {
|
|
104
|
+
console.log((0, colors_1.error)(` Error fetching SPA clients: ${results.spaError}`));
|
|
105
|
+
}
|
|
106
|
+
// Display M2M OAuth Clients
|
|
107
|
+
if (results.m2m) {
|
|
108
|
+
console.log((0, colors_1.bold)(`\n=== M2M OAuth Clients (${results.m2m.length}) ===\n`));
|
|
109
|
+
if (results.m2m.length === 0) {
|
|
110
|
+
console.log((0, colors_1.dim)(' No M2M OAuth Clients found'));
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
results.m2m.forEach((client) => {
|
|
114
|
+
console.log((0, colors_1.bold)(client.title) + (0, colors_1.dim)(` (${client.client_id})`));
|
|
115
|
+
console.log(' Type: M2M');
|
|
116
|
+
console.log(' Created: ' + new Date(client.createdAt).toLocaleString());
|
|
117
|
+
console.log('');
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (results.m2mError) {
|
|
122
|
+
console.log((0, colors_1.error)(` Error fetching M2M clients: ${results.m2mError}`));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
if (jsonOutput) {
|
|
128
|
+
console.log(JSON.stringify({ success: false, error: err.message }));
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
console.log((0, colors_1.error)('✗ Failed to list credentials: ' + err.message));
|
|
132
|
+
}
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Create API Access Token
|
|
138
|
+
*/
|
|
139
|
+
async function credentialsCreateToken(options, token, baseUrl, jsonOutput, debug = false, profile) {
|
|
140
|
+
try {
|
|
141
|
+
const client = await api_1.ApiClient.create(token, baseUrl, debug, profile);
|
|
142
|
+
// Build request body from options
|
|
143
|
+
let body;
|
|
144
|
+
if (options.jsonBody) {
|
|
145
|
+
// Use raw JSON body
|
|
146
|
+
body = JSON.parse(options.jsonBody);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
// Build body from flags
|
|
150
|
+
body = {
|
|
151
|
+
grants: [],
|
|
152
|
+
allowed_apis: [],
|
|
153
|
+
referers: []
|
|
154
|
+
};
|
|
155
|
+
// Parse grants (connection and source pairs)
|
|
156
|
+
if (options.connection && options.source) {
|
|
157
|
+
if (Array.isArray(options.connection)) {
|
|
158
|
+
for (let i = 0; i < options.connection.length; i++) {
|
|
159
|
+
body.grants.push({
|
|
160
|
+
connection_name: options.connection[i],
|
|
161
|
+
source: options.source[i] || '*'
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
body.grants.push({
|
|
167
|
+
connection_name: options.connection,
|
|
168
|
+
source: options.source
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// Parse APIs
|
|
173
|
+
if (options.apis) {
|
|
174
|
+
body.allowed_apis = options.apis.split(',').map((a) => a.trim());
|
|
175
|
+
}
|
|
176
|
+
// Parse referers
|
|
177
|
+
if (options.referers) {
|
|
178
|
+
body.referers = options.referers.split(',').map((r) => r.trim());
|
|
179
|
+
}
|
|
180
|
+
else if (options.referer) {
|
|
181
|
+
body.referers = [options.referer];
|
|
182
|
+
}
|
|
183
|
+
// Validation
|
|
184
|
+
if (body.grants.length === 0) {
|
|
185
|
+
throw new Error('At least one grant is required. Use --connection and --source flags.');
|
|
186
|
+
}
|
|
187
|
+
if (body.allowed_apis.length === 0) {
|
|
188
|
+
throw new Error('At least one API is required. Use --apis flag (e.g., --apis sql,maps,imports)');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const result = await client.post('/v3/tokens', body);
|
|
192
|
+
if (jsonOutput) {
|
|
193
|
+
console.log(JSON.stringify(result));
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
console.log((0, colors_1.success)('\n✓ API Access Token created successfully\n'));
|
|
197
|
+
console.log((0, colors_1.bold)('Token: ') + result.token);
|
|
198
|
+
console.log((0, colors_1.bold)('Allowed APIs: ') + result.allowed_apis.join(', '));
|
|
199
|
+
if (result.grants && result.grants.length > 0) {
|
|
200
|
+
console.log((0, colors_1.bold)('\nGrants:'));
|
|
201
|
+
result.grants.forEach((grant) => {
|
|
202
|
+
console.log(` - ${grant.connection_name} → ${grant.source}`);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if (result.referers && result.referers.length > 0) {
|
|
206
|
+
console.log((0, colors_1.bold)('\nReferers:'));
|
|
207
|
+
result.referers.forEach((ref) => {
|
|
208
|
+
console.log(` - ${ref}`);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
console.log('');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
if (jsonOutput) {
|
|
216
|
+
console.log(JSON.stringify({ success: false, error: err.message }));
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
console.log((0, colors_1.error)('✗ Failed to create token: ' + err.message));
|
|
220
|
+
}
|
|
221
|
+
process.exit(1);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Create SPA OAuth Client
|
|
226
|
+
*/
|
|
227
|
+
async function credentialsCreateSPA(options, token, baseUrl, jsonOutput, debug = false, profile) {
|
|
228
|
+
try {
|
|
229
|
+
const client = await api_1.ApiClient.create(token, baseUrl, debug, profile);
|
|
230
|
+
// Build request body
|
|
231
|
+
let body;
|
|
232
|
+
if (options.jsonBody) {
|
|
233
|
+
body = JSON.parse(options.jsonBody);
|
|
234
|
+
body.type = 'spa';
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
body = {
|
|
238
|
+
type: 'spa',
|
|
239
|
+
title: options.title,
|
|
240
|
+
initiate_login_uri: options.loginUri,
|
|
241
|
+
callbacks: options.callback || options.callbacks,
|
|
242
|
+
allowed_logout_urls: options.logoutUrl || options.allowedLogoutUrls,
|
|
243
|
+
web_origins: options.webOrigin || options.webOrigins,
|
|
244
|
+
allowed_origins: options.allowedOrigin || options.allowedOrigins
|
|
245
|
+
};
|
|
246
|
+
// Validation
|
|
247
|
+
if (!body.title) {
|
|
248
|
+
throw new Error('Title is required. Use --title flag.');
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const result = await client.postAccounts('/oauth-clients', body);
|
|
252
|
+
if (jsonOutput) {
|
|
253
|
+
console.log(JSON.stringify(result));
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
console.log((0, colors_1.success)('\n✓ SPA OAuth Client created successfully\n'));
|
|
257
|
+
console.log((0, colors_1.bold)('Client ID: ') + result.id);
|
|
258
|
+
console.log((0, colors_1.bold)('Title: ') + body.title);
|
|
259
|
+
console.log((0, colors_1.bold)('Type: ') + 'spa');
|
|
260
|
+
console.log('');
|
|
261
|
+
console.log((0, colors_1.info)('Use this Client ID in your single-page application to authenticate users.'));
|
|
262
|
+
console.log('');
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
catch (err) {
|
|
266
|
+
if (jsonOutput) {
|
|
267
|
+
console.log(JSON.stringify({ success: false, error: err.message }));
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
console.log((0, colors_1.error)('✗ Failed to create SPA client: ' + err.message));
|
|
271
|
+
}
|
|
272
|
+
process.exit(1);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Create M2M OAuth Client
|
|
277
|
+
*/
|
|
278
|
+
async function credentialsCreateM2M(options, token, baseUrl, jsonOutput, debug = false, profile) {
|
|
279
|
+
try {
|
|
280
|
+
const client = await api_1.ApiClient.create(token, baseUrl, debug, profile);
|
|
281
|
+
// Build request body
|
|
282
|
+
let body;
|
|
283
|
+
if (options.jsonBody) {
|
|
284
|
+
body = JSON.parse(options.jsonBody);
|
|
285
|
+
body.type = 'm2m';
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
body = {
|
|
289
|
+
type: 'm2m',
|
|
290
|
+
title: options.title
|
|
291
|
+
};
|
|
292
|
+
// Validation
|
|
293
|
+
if (!body.title) {
|
|
294
|
+
throw new Error('Title is required. Use --title flag.');
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const result = await client.postAccounts('/oauth-clients', body);
|
|
298
|
+
if (jsonOutput) {
|
|
299
|
+
console.log(JSON.stringify(result));
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
console.log((0, colors_1.success)('\n✓ M2M OAuth Client created successfully\n'));
|
|
303
|
+
console.log((0, colors_1.bold)('Client ID: ') + result.id);
|
|
304
|
+
console.log((0, colors_1.bold)('Title: ') + body.title);
|
|
305
|
+
console.log((0, colors_1.bold)('Type: ') + 'm2m');
|
|
306
|
+
console.log('');
|
|
307
|
+
if (result.client_secret) {
|
|
308
|
+
console.log((0, colors_1.bold)('Client Secret: ') + result.client_secret);
|
|
309
|
+
console.log('');
|
|
310
|
+
console.log((0, colors_1.error)('⚠️ IMPORTANT: Save the client secret now - you won\'t be able to see it again!'));
|
|
311
|
+
}
|
|
312
|
+
console.log('');
|
|
313
|
+
console.log((0, colors_1.info)('Use these credentials in your backend service for machine-to-machine authentication.'));
|
|
314
|
+
console.log('');
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch (err) {
|
|
318
|
+
if (jsonOutput) {
|
|
319
|
+
console.log(JSON.stringify({ success: false, error: err.message }));
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
console.log((0, colors_1.error)('✗ Failed to create M2M client: ' + err.message));
|
|
323
|
+
}
|
|
324
|
+
process.exit(1);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Get API Access Token details
|
|
329
|
+
*/
|
|
330
|
+
async function credentialsGetToken(tokenId, token, baseUrl, jsonOutput, debug = false, profile) {
|
|
331
|
+
try {
|
|
332
|
+
const client = await api_1.ApiClient.create(token, baseUrl, debug, profile);
|
|
333
|
+
const result = await client.get(`/v3/tokens/${tokenId}`);
|
|
334
|
+
if (jsonOutput) {
|
|
335
|
+
console.log(JSON.stringify(result));
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
console.log((0, colors_1.bold)('\n=== API Access Token Details ===\n'));
|
|
339
|
+
console.log((0, colors_1.bold)('Token: ') + result.token);
|
|
340
|
+
console.log((0, colors_1.bold)('Created: ') + new Date(result.created_at).toLocaleString());
|
|
341
|
+
console.log((0, colors_1.bold)('Allowed APIs: ') + result.allowed_apis.join(', '));
|
|
342
|
+
if (result.grants && result.grants.length > 0) {
|
|
343
|
+
console.log((0, colors_1.bold)('\nGrants:'));
|
|
344
|
+
result.grants.forEach((grant) => {
|
|
345
|
+
console.log(` - ${grant.connection_name} → ${grant.source}`);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
if (result.referers && result.referers.length > 0) {
|
|
349
|
+
console.log((0, colors_1.bold)('\nReferers:'));
|
|
350
|
+
result.referers.forEach((ref) => {
|
|
351
|
+
console.log(` - ${ref}`);
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
console.log('');
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
catch (err) {
|
|
358
|
+
if (jsonOutput) {
|
|
359
|
+
console.log(JSON.stringify({ success: false, error: err.message }));
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
console.log((0, colors_1.error)('✗ Failed to get token: ' + err.message));
|
|
363
|
+
}
|
|
364
|
+
process.exit(1);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Get OAuth Client details (SPA or M2M)
|
|
369
|
+
*/
|
|
370
|
+
async function credentialsGetOAuth(clientId, clientType, token, baseUrl, jsonOutput, debug = false, profile) {
|
|
371
|
+
try {
|
|
372
|
+
const client = await api_1.ApiClient.create(token, baseUrl, debug, profile);
|
|
373
|
+
const result = await client.getAccounts(`/oauth-clients/${clientId}`);
|
|
374
|
+
if (jsonOutput) {
|
|
375
|
+
console.log(JSON.stringify(result));
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
const type = result.app_type || clientType || 'Unknown';
|
|
379
|
+
console.log((0, colors_1.bold)(`\n=== ${type.toUpperCase()} OAuth Client Details ===\n`));
|
|
380
|
+
console.log((0, colors_1.bold)('Client ID: ') + result.client_id);
|
|
381
|
+
console.log((0, colors_1.bold)('Title: ') + result.title);
|
|
382
|
+
console.log((0, colors_1.bold)('Type: ') + type);
|
|
383
|
+
console.log((0, colors_1.bold)('Created: ') + new Date(result.createdAt).toLocaleString());
|
|
384
|
+
console.log((0, colors_1.bold)('Updated: ') + new Date(result.updatedAt).toLocaleString());
|
|
385
|
+
console.log('');
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
catch (err) {
|
|
389
|
+
if (jsonOutput) {
|
|
390
|
+
console.log(JSON.stringify({ success: false, error: err.message }));
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
console.log((0, colors_1.error)('✗ Failed to get OAuth client: ' + err.message));
|
|
394
|
+
}
|
|
395
|
+
process.exit(1);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Update API Access Token
|
|
400
|
+
*/
|
|
401
|
+
async function credentialsUpdateToken(tokenId, options, token, baseUrl, jsonOutput, debug = false, profile) {
|
|
402
|
+
try {
|
|
403
|
+
const client = await api_1.ApiClient.create(token, baseUrl, debug, profile);
|
|
404
|
+
// Build update body
|
|
405
|
+
let body;
|
|
406
|
+
if (options.jsonBody) {
|
|
407
|
+
body = JSON.parse(options.jsonBody);
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
// Get current token to preserve existing values
|
|
411
|
+
const current = await client.get(`/v3/tokens/${tokenId}`);
|
|
412
|
+
body = {
|
|
413
|
+
grants: current.grants || [],
|
|
414
|
+
allowed_apis: current.allowed_apis || [],
|
|
415
|
+
referers: current.referers || []
|
|
416
|
+
};
|
|
417
|
+
// Update grants
|
|
418
|
+
if (options.addGrant) {
|
|
419
|
+
const [connection, source] = options.addGrant.split(',');
|
|
420
|
+
body.grants.push({ connection_name: connection, source: source || '*' });
|
|
421
|
+
}
|
|
422
|
+
// Update APIs
|
|
423
|
+
if (options.addApi) {
|
|
424
|
+
body.allowed_apis.push(options.addApi);
|
|
425
|
+
}
|
|
426
|
+
// Update referers
|
|
427
|
+
if (options.referers) {
|
|
428
|
+
body.referers = options.referers.split(',').map((r) => r.trim());
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
const result = await client.patch(`/v3/tokens/${tokenId}`, body);
|
|
432
|
+
if (jsonOutput) {
|
|
433
|
+
console.log(JSON.stringify(result));
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
console.log((0, colors_1.success)('\n✓ API Access Token updated successfully\n'));
|
|
437
|
+
console.log((0, colors_1.bold)('Token: ') + result.token);
|
|
438
|
+
console.log((0, colors_1.bold)('Allowed APIs: ') + result.allowed_apis.join(', '));
|
|
439
|
+
console.log('');
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
catch (err) {
|
|
443
|
+
if (jsonOutput) {
|
|
444
|
+
console.log(JSON.stringify({ success: false, error: err.message }));
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
console.log((0, colors_1.error)('✗ Failed to update token: ' + err.message));
|
|
448
|
+
}
|
|
449
|
+
process.exit(1);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Update OAuth Client (SPA or M2M)
|
|
454
|
+
*/
|
|
455
|
+
async function credentialsUpdateOAuth(clientId, options, token, baseUrl, jsonOutput, debug = false, profile) {
|
|
456
|
+
try {
|
|
457
|
+
const client = await api_1.ApiClient.create(token, baseUrl, debug, profile);
|
|
458
|
+
// Get current client to determine type
|
|
459
|
+
const current = await client.getAccounts(`/oauth-clients/${clientId}`);
|
|
460
|
+
// Build update body
|
|
461
|
+
let body;
|
|
462
|
+
if (options.jsonBody) {
|
|
463
|
+
body = JSON.parse(options.jsonBody);
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
body = {
|
|
467
|
+
title: options.title || current.title,
|
|
468
|
+
type: current.app_type
|
|
469
|
+
};
|
|
470
|
+
// For SPA clients, can update URLs
|
|
471
|
+
if (current.app_type === 'spa') {
|
|
472
|
+
if (options.loginUri)
|
|
473
|
+
body.initiate_login_uri = options.loginUri;
|
|
474
|
+
if (options.callback)
|
|
475
|
+
body.callbacks = options.callback;
|
|
476
|
+
if (options.logoutUrl)
|
|
477
|
+
body.allowed_logout_urls = options.logoutUrl;
|
|
478
|
+
if (options.webOrigin)
|
|
479
|
+
body.web_origins = options.webOrigin;
|
|
480
|
+
if (options.allowedOrigin)
|
|
481
|
+
body.allowed_origins = options.allowedOrigin;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
await client.putAccounts(`/oauth-clients/${clientId}`, body);
|
|
485
|
+
if (jsonOutput) {
|
|
486
|
+
console.log(JSON.stringify({ success: true, clientId }));
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
console.log((0, colors_1.success)('\n✓ OAuth Client updated successfully\n'));
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
catch (err) {
|
|
493
|
+
if (jsonOutput) {
|
|
494
|
+
console.log(JSON.stringify({ success: false, error: err.message }));
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
console.log((0, colors_1.error)('✗ Failed to update OAuth client: ' + err.message));
|
|
498
|
+
}
|
|
499
|
+
process.exit(1);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Delete API Access Token
|
|
504
|
+
*/
|
|
505
|
+
async function credentialsDeleteToken(tokenId, token, baseUrl, jsonOutput, debug = false, profile, yes) {
|
|
506
|
+
try {
|
|
507
|
+
const client = await api_1.ApiClient.create(token, baseUrl, debug, profile);
|
|
508
|
+
// Skip confirmation if --yes or --json flag is set
|
|
509
|
+
const skipConfirmation = yes || jsonOutput;
|
|
510
|
+
if (!skipConfirmation) {
|
|
511
|
+
// Fetch token details to show in confirmation prompt
|
|
512
|
+
let tokenDetails;
|
|
513
|
+
try {
|
|
514
|
+
tokenDetails = await client.get(`/v3/tokens/${tokenId}`);
|
|
515
|
+
}
|
|
516
|
+
catch (err) {
|
|
517
|
+
// If we can't fetch details, proceed with generic message
|
|
518
|
+
console.log((0, colors_1.warning)('\n⚠️ Warning: This will permanently delete this API Access Token.'));
|
|
519
|
+
console.log((0, colors_1.warning)(` Token ID: ${tokenId}`));
|
|
520
|
+
}
|
|
521
|
+
if (tokenDetails) {
|
|
522
|
+
console.log((0, colors_1.warning)('\n⚠️ Warning: This will permanently delete:'));
|
|
523
|
+
console.log(` API Access Token: ${tokenDetails.token.substring(0, 20)}...`);
|
|
524
|
+
console.log(` Allowed APIs: ${tokenDetails.allowed_apis.join(', ')}`);
|
|
525
|
+
if (tokenDetails.grants && tokenDetails.grants.length > 0) {
|
|
526
|
+
console.log(` Grants: ${tokenDetails.grants.length} grant(s)`);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
console.log('');
|
|
530
|
+
const confirmed = await (0, prompt_1.promptForConfirmation)("Type 'delete' to confirm: ", 'delete');
|
|
531
|
+
if (!confirmed) {
|
|
532
|
+
console.log('\nDeletion cancelled');
|
|
533
|
+
process.exit(0);
|
|
534
|
+
}
|
|
535
|
+
console.log('');
|
|
536
|
+
}
|
|
537
|
+
await client.delete(`/v3/tokens/${tokenId}`);
|
|
538
|
+
if (jsonOutput) {
|
|
539
|
+
console.log(JSON.stringify({ success: true, message: 'Token deleted successfully' }));
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
console.log((0, colors_1.success)('✓ API Access Token deleted successfully'));
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
catch (err) {
|
|
546
|
+
if (jsonOutput) {
|
|
547
|
+
console.log(JSON.stringify({ success: false, error: err.message }));
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
console.log((0, colors_1.error)('✗ Failed to delete token: ' + err.message));
|
|
551
|
+
}
|
|
552
|
+
process.exit(1);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Delete OAuth Client (SPA or M2M)
|
|
557
|
+
*/
|
|
558
|
+
async function credentialsDeleteOAuth(clientId, token, baseUrl, jsonOutput, debug = false, profile, yes) {
|
|
559
|
+
try {
|
|
560
|
+
const client = await api_1.ApiClient.create(token, baseUrl, debug, profile);
|
|
561
|
+
// Skip confirmation if --yes or --json flag is set
|
|
562
|
+
const skipConfirmation = yes || jsonOutput;
|
|
563
|
+
if (!skipConfirmation) {
|
|
564
|
+
// Fetch OAuth client details to show in confirmation prompt
|
|
565
|
+
let clientDetails;
|
|
566
|
+
try {
|
|
567
|
+
clientDetails = await client.getAccounts(`/oauth-clients/${clientId}`);
|
|
568
|
+
}
|
|
569
|
+
catch (err) {
|
|
570
|
+
// If we can't fetch details, proceed with generic message
|
|
571
|
+
console.log((0, colors_1.warning)('\n⚠️ Warning: This will permanently delete this OAuth Client.'));
|
|
572
|
+
console.log((0, colors_1.warning)(` Client ID: ${clientId}`));
|
|
573
|
+
}
|
|
574
|
+
if (clientDetails) {
|
|
575
|
+
const clientType = clientDetails.app_type || 'Unknown';
|
|
576
|
+
console.log((0, colors_1.warning)('\n⚠️ Warning: This will permanently delete:'));
|
|
577
|
+
console.log(` OAuth Client: "${clientDetails.title}"`);
|
|
578
|
+
console.log(` Type: ${clientType.toUpperCase()}`);
|
|
579
|
+
console.log(` Client ID: ${clientDetails.client_id}`);
|
|
580
|
+
}
|
|
581
|
+
console.log('');
|
|
582
|
+
const confirmed = await (0, prompt_1.promptForConfirmation)("Type 'delete' to confirm: ", 'delete');
|
|
583
|
+
if (!confirmed) {
|
|
584
|
+
console.log('\nDeletion cancelled');
|
|
585
|
+
process.exit(0);
|
|
586
|
+
}
|
|
587
|
+
console.log('');
|
|
588
|
+
}
|
|
589
|
+
await client.deleteAccounts(`/oauth-clients/${clientId}`);
|
|
590
|
+
if (jsonOutput) {
|
|
591
|
+
console.log(JSON.stringify({ success: true, message: 'OAuth Client deleted successfully' }));
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
console.log((0, colors_1.success)('✓ OAuth Client deleted successfully'));
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
catch (err) {
|
|
598
|
+
if (jsonOutput) {
|
|
599
|
+
console.log(JSON.stringify({ success: false, error: err.message }));
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
console.log((0, colors_1.error)('✗ Failed to delete OAuth client: ' + err.message));
|
|
603
|
+
}
|
|
604
|
+
process.exit(1);
|
|
605
|
+
}
|
|
606
|
+
}
|