@openziti/ziti-mcp-server 0.1.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/LICENSE +201 -0
- package/README.md +868 -0
- package/dist/auth/client-credentials-flow.d.ts +21 -0
- package/dist/auth/client-credentials-flow.js +63 -0
- package/dist/auth/client-credentials-flow.js.map +1 -0
- package/dist/auth/device-auth-flow.d.ts +47 -0
- package/dist/auth/device-auth-flow.js +291 -0
- package/dist/auth/device-auth-flow.js.map +1 -0
- package/dist/clients/base.d.ts +74 -0
- package/dist/clients/base.js +109 -0
- package/dist/clients/base.js.map +1 -0
- package/dist/clients/claude.d.ts +22 -0
- package/dist/clients/claude.js +40 -0
- package/dist/clients/claude.js.map +1 -0
- package/dist/clients/cursor.d.ts +22 -0
- package/dist/clients/cursor.js +39 -0
- package/dist/clients/cursor.js.map +1 -0
- package/dist/clients/index.d.ts +33 -0
- package/dist/clients/index.js +39 -0
- package/dist/clients/index.js.map +1 -0
- package/dist/clients/types.d.ts +70 -0
- package/dist/clients/types.js +2 -0
- package/dist/clients/types.js.map +1 -0
- package/dist/clients/utils.d.ts +22 -0
- package/dist/clients/utils.js +46 -0
- package/dist/clients/utils.js.map +1 -0
- package/dist/clients/vscode.d.ts +76 -0
- package/dist/clients/vscode.js +159 -0
- package/dist/clients/vscode.js.map +1 -0
- package/dist/clients/windsurf.d.ts +22 -0
- package/dist/clients/windsurf.js +39 -0
- package/dist/clients/windsurf.js.map +1 -0
- package/dist/commands/init.d.ts +45 -0
- package/dist/commands/init.js +133 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/logout.d.ts +12 -0
- package/dist/commands/logout.js +90 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/run.d.ts +15 -0
- package/dist/commands/run.js +94 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/session.d.ts +12 -0
- package/dist/commands/session.js +99 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +105 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +67 -0
- package/dist/server.js +171 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/api-sessions.d.ts +3 -0
- package/dist/tools/api-sessions.js +86 -0
- package/dist/tools/api-sessions.js.map +1 -0
- package/dist/tools/auth-policies.d.ts +3 -0
- package/dist/tools/auth-policies.js +347 -0
- package/dist/tools/auth-policies.js.map +1 -0
- package/dist/tools/authenticators.d.ts +3 -0
- package/dist/tools/authenticators.js +183 -0
- package/dist/tools/authenticators.js.map +1 -0
- package/dist/tools/certificate-authorities.d.ts +3 -0
- package/dist/tools/certificate-authorities.js +288 -0
- package/dist/tools/certificate-authorities.js.map +1 -0
- package/dist/tools/config-types.d.ts +3 -0
- package/dist/tools/config-types.js +194 -0
- package/dist/tools/config-types.js.map +1 -0
- package/dist/tools/configs.d.ts +3 -0
- package/dist/tools/configs.js +203 -0
- package/dist/tools/configs.js.map +1 -0
- package/dist/tools/controller-settings.d.ts +3 -0
- package/dist/tools/controller-settings.js +219 -0
- package/dist/tools/controller-settings.js.map +1 -0
- package/dist/tools/controllers.d.ts +3 -0
- package/dist/tools/controllers.js +89 -0
- package/dist/tools/controllers.js.map +1 -0
- package/dist/tools/edge-router-policies.d.ts +3 -0
- package/dist/tools/edge-router-policies.js +262 -0
- package/dist/tools/edge-router-policies.js.map +1 -0
- package/dist/tools/edge-routers.d.ts +3 -0
- package/dist/tools/edge-routers.js +381 -0
- package/dist/tools/edge-routers.js.map +1 -0
- package/dist/tools/enrollments.d.ts +3 -0
- package/dist/tools/enrollments.js +187 -0
- package/dist/tools/enrollments.js.map +1 -0
- package/dist/tools/external-jwt-signers.d.ts +3 -0
- package/dist/tools/external-jwt-signers.js +242 -0
- package/dist/tools/external-jwt-signers.js.map +1 -0
- package/dist/tools/identities.d.ts +3 -0
- package/dist/tools/identities.js +741 -0
- package/dist/tools/identities.js.map +1 -0
- package/dist/tools/identity-types.d.ts +3 -0
- package/dist/tools/identity-types.js +58 -0
- package/dist/tools/identity-types.js.map +1 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.js +101 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/posture-checks.d.ts +3 -0
- package/dist/tools/posture-checks.js +254 -0
- package/dist/tools/posture-checks.js.map +1 -0
- package/dist/tools/routers.d.ts +3 -0
- package/dist/tools/routers.js +169 -0
- package/dist/tools/routers.js.map +1 -0
- package/dist/tools/service-edge-router-policies.d.ts +3 -0
- package/dist/tools/service-edge-router-policies.js +282 -0
- package/dist/tools/service-edge-router-policies.js.map +1 -0
- package/dist/tools/service-policies.d.ts +3 -0
- package/dist/tools/service-policies.js +311 -0
- package/dist/tools/service-policies.js.map +1 -0
- package/dist/tools/services.d.ts +3 -0
- package/dist/tools/services.js +403 -0
- package/dist/tools/services.js.map +1 -0
- package/dist/tools/sessions.d.ts +3 -0
- package/dist/tools/sessions.js +86 -0
- package/dist/tools/sessions.js.map +1 -0
- package/dist/tools/terminators.d.ts +3 -0
- package/dist/tools/terminators.js +187 -0
- package/dist/tools/terminators.js.map +1 -0
- package/dist/tools/transit-routers.d.ts +3 -0
- package/dist/tools/transit-routers.js +169 -0
- package/dist/tools/transit-routers.js.map +1 -0
- package/dist/utils/analytics.d.ts +75 -0
- package/dist/utils/analytics.js +191 -0
- package/dist/utils/analytics.js.map +1 -0
- package/dist/utils/auth0-client.d.ts +27 -0
- package/dist/utils/auth0-client.js +67 -0
- package/dist/utils/auth0-client.js.map +1 -0
- package/dist/utils/authenticated-client.d.ts +6 -0
- package/dist/utils/authenticated-client.js +55 -0
- package/dist/utils/authenticated-client.js.map +1 -0
- package/dist/utils/config.d.ts +65 -0
- package/dist/utils/config.js +80 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/constants.d.ts +15 -0
- package/dist/utils/constants.js +17 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/controller-client/client/client.gen.d.ts +2 -0
- package/dist/utils/controller-client/client/client.gen.js +229 -0
- package/dist/utils/controller-client/client/client.gen.js.map +1 -0
- package/dist/utils/controller-client/client/index.d.ts +8 -0
- package/dist/utils/controller-client/client/index.js +7 -0
- package/dist/utils/controller-client/client/index.js.map +1 -0
- package/dist/utils/controller-client/client/types.gen.d.ts +117 -0
- package/dist/utils/controller-client/client/types.gen.js +3 -0
- package/dist/utils/controller-client/client/types.gen.js.map +1 -0
- package/dist/utils/controller-client/client/utils.gen.d.ts +33 -0
- package/dist/utils/controller-client/client/utils.gen.js +232 -0
- package/dist/utils/controller-client/client/utils.gen.js.map +1 -0
- package/dist/utils/controller-client/client.gen.d.ts +12 -0
- package/dist/utils/controller-client/client.gen.js +6 -0
- package/dist/utils/controller-client/client.gen.js.map +1 -0
- package/dist/utils/controller-client/core/auth.gen.d.ts +18 -0
- package/dist/utils/controller-client/core/auth.gen.js +15 -0
- package/dist/utils/controller-client/core/auth.gen.js.map +1 -0
- package/dist/utils/controller-client/core/bodySerializer.gen.d.ts +25 -0
- package/dist/utils/controller-client/core/bodySerializer.gen.js +58 -0
- package/dist/utils/controller-client/core/bodySerializer.gen.js.map +1 -0
- package/dist/utils/controller-client/core/params.gen.d.ts +43 -0
- package/dist/utils/controller-client/core/params.gen.js +101 -0
- package/dist/utils/controller-client/core/params.gen.js.map +1 -0
- package/dist/utils/controller-client/core/pathSerializer.gen.d.ts +33 -0
- package/dist/utils/controller-client/core/pathSerializer.gen.js +115 -0
- package/dist/utils/controller-client/core/pathSerializer.gen.js.map +1 -0
- package/dist/utils/controller-client/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/utils/controller-client/core/queryKeySerializer.gen.js +100 -0
- package/dist/utils/controller-client/core/queryKeySerializer.gen.js.map +1 -0
- package/dist/utils/controller-client/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/utils/controller-client/core/serverSentEvents.gen.js +136 -0
- package/dist/utils/controller-client/core/serverSentEvents.gen.js.map +1 -0
- package/dist/utils/controller-client/core/types.gen.d.ts +78 -0
- package/dist/utils/controller-client/core/types.gen.js +3 -0
- package/dist/utils/controller-client/core/types.gen.js.map +1 -0
- package/dist/utils/controller-client/core/utils.gen.d.ts +19 -0
- package/dist/utils/controller-client/core/utils.gen.js +88 -0
- package/dist/utils/controller-client/core/utils.gen.js.map +1 -0
- package/dist/utils/controller-client/index.d.ts +2 -0
- package/dist/utils/controller-client/index.js +3 -0
- package/dist/utils/controller-client/index.js.map +1 -0
- package/dist/utils/controller-client/sdk.gen.d.ts +1302 -0
- package/dist/utils/controller-client/sdk.gen.js +4436 -0
- package/dist/utils/controller-client/sdk.gen.js.map +1 -0
- package/dist/utils/controller-client/types.gen.d.ts +9170 -0
- package/dist/utils/controller-client/types.gen.js +3 -0
- package/dist/utils/controller-client/types.gen.js.map +1 -0
- package/dist/utils/glob.d.ts +75 -0
- package/dist/utils/glob.js +110 -0
- package/dist/utils/glob.js.map +1 -0
- package/dist/utils/http-utility.d.ts +5 -0
- package/dist/utils/http-utility.js +68 -0
- package/dist/utils/http-utility.js.map +1 -0
- package/dist/utils/keychain.d.ts +129 -0
- package/dist/utils/keychain.js +193 -0
- package/dist/utils/keychain.js.map +1 -0
- package/dist/utils/logger.d.ts +4 -0
- package/dist/utils/logger.js +28 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/package.d.ts +3 -0
- package/dist/utils/package.js +9 -0
- package/dist/utils/package.js.map +1 -0
- package/dist/utils/scopes.d.ts +12 -0
- package/dist/utils/scopes.js +19 -0
- package/dist/utils/scopes.js.map +1 -0
- package/dist/utils/terminal.d.ts +35 -0
- package/dist/utils/terminal.js +409 -0
- package/dist/utils/terminal.js.map +1 -0
- package/dist/utils/tools.d.ts +63 -0
- package/dist/utils/tools.js +149 -0
- package/dist/utils/tools.js.map +1 -0
- package/dist/utils/types.d.ts +55 -0
- package/dist/utils/types.js +3 -0
- package/dist/utils/types.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default scopes to be used when no specific scopes are provided.
|
|
3
|
+
* This is an empty array, meaning no scopes are required by default to
|
|
4
|
+
* promote security by default.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_SCOPES: string[];
|
|
7
|
+
/**
|
|
8
|
+
* Returns a unique list of all required scopes across all tools.
|
|
9
|
+
*
|
|
10
|
+
* @returns {string[]} - An array of unique scopes required by all tools.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getAllScopes(): string[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TOOLS } from '../tools/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Default scopes to be used when no specific scopes are provided.
|
|
4
|
+
* This is an empty array, meaning no scopes are required by default to
|
|
5
|
+
* promote security by default.
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_SCOPES = [];
|
|
8
|
+
/**
|
|
9
|
+
* Returns a unique list of all required scopes across all tools.
|
|
10
|
+
*
|
|
11
|
+
* @returns {string[]} - An array of unique scopes required by all tools.
|
|
12
|
+
*/
|
|
13
|
+
export function getAllScopes() {
|
|
14
|
+
// Use flatMap to extract and flatten all scopes, with empty fallback
|
|
15
|
+
const allScopes = TOOLS.flatMap((tool) => tool._meta?.requiredScopes ?? []);
|
|
16
|
+
// Create unique set from collected scopes
|
|
17
|
+
return [...new Set(allScopes)];
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=scopes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopes.js","sourceRoot":"","sources":["../../src/utils/scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAa,EAAE,CAAC;AAE3C;;;;GAIG;AACH,MAAM,UAAU,YAAY;IAC1B,qEAAqE;IACrE,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,cAAc,IAAI,EAAE,CAAC,CAAC;IAE5E,0CAA0C;IAC1C,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic function to prompt user for a choice from a list of options
|
|
3
|
+
*/
|
|
4
|
+
export declare function promptForChoice<T extends string>(question: string, choices: Array<{
|
|
5
|
+
label: string;
|
|
6
|
+
value: T;
|
|
7
|
+
}>, defaultChoice?: T): Promise<T>;
|
|
8
|
+
/**
|
|
9
|
+
* Generic function to prompt user for a file/directory path with validation
|
|
10
|
+
*/
|
|
11
|
+
export declare function promptForPath(question: string, options?: {
|
|
12
|
+
required?: boolean;
|
|
13
|
+
mustExist?: boolean;
|
|
14
|
+
mustBeDirectory?: boolean;
|
|
15
|
+
mustBeFile?: boolean;
|
|
16
|
+
}): Promise<string>;
|
|
17
|
+
export declare const cliOutput: (message: string) => boolean;
|
|
18
|
+
export declare const startSpinner: (message: string) => void;
|
|
19
|
+
export declare const stopSpinner: () => void;
|
|
20
|
+
export declare const getTenantFromToken: (accessToken: string) => string;
|
|
21
|
+
export declare const promptForBrowserPermission: () => Promise<boolean>;
|
|
22
|
+
export declare const promptForScopeSelection: (providedScopes?: string[]) => Promise<string[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Masks a tenant name according to the specified format:
|
|
25
|
+
* - Shows letters before the dash
|
|
26
|
+
* - Shows 3 letters after the dash
|
|
27
|
+
* - Shows the last word after the last dot
|
|
28
|
+
* - Masks everything else with "xxx"
|
|
29
|
+
*
|
|
30
|
+
* Example: "dev-sfhjdfhdgfghhjdfhf.us.auth0.com" becomes "dev-sfh***com"
|
|
31
|
+
*
|
|
32
|
+
* @param tenantName The tenant name to mask
|
|
33
|
+
* @returns The masked tenant name or the original if it doesn't match the expected format
|
|
34
|
+
*/
|
|
35
|
+
export declare function maskTenantName(tenantName: string | undefined | null): string;
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { jwtDecode } from 'jwt-decode';
|
|
3
|
+
import readline from 'readline';
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { getAllScopes } from './scopes.js';
|
|
7
|
+
/**
|
|
8
|
+
* Generic function to prompt user for a choice from a list of options
|
|
9
|
+
*/
|
|
10
|
+
export async function promptForChoice(question, choices, defaultChoice) {
|
|
11
|
+
const rl = readline.createInterface({
|
|
12
|
+
input: process.stdin,
|
|
13
|
+
output: process.stdout,
|
|
14
|
+
});
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
console.log(chalk.cyan(`\n${question}`));
|
|
17
|
+
choices.forEach((choice, index) => {
|
|
18
|
+
console.log(`${index + 1}. ${choice.label}`);
|
|
19
|
+
});
|
|
20
|
+
rl.question(chalk.yellow(`Enter your choice (1-${choices.length}): `), (answer) => {
|
|
21
|
+
rl.close();
|
|
22
|
+
const choice = answer.trim();
|
|
23
|
+
const choiceIndex = parseInt(choice, 10) - 1;
|
|
24
|
+
if (choiceIndex >= 0 && choiceIndex < choices.length) {
|
|
25
|
+
resolve(choices[choiceIndex].value);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
// Try to match by label (case insensitive)
|
|
29
|
+
const matchedChoice = choices.find((c) => c.value.toLowerCase() === choice.toLowerCase() ||
|
|
30
|
+
c.label.toLowerCase().includes(choice.toLowerCase()));
|
|
31
|
+
if (matchedChoice) {
|
|
32
|
+
resolve(matchedChoice.value);
|
|
33
|
+
}
|
|
34
|
+
else if (defaultChoice) {
|
|
35
|
+
console.log(chalk.yellow(`Invalid choice, defaulting to ${defaultChoice}.`));
|
|
36
|
+
resolve(defaultChoice);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.log(chalk.yellow(`Invalid choice, defaulting to first option.`));
|
|
40
|
+
resolve(choices[0].value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Generic function to prompt user for a file/directory path with validation
|
|
48
|
+
*/
|
|
49
|
+
export async function promptForPath(question, options = {}) {
|
|
50
|
+
const rl = readline.createInterface({
|
|
51
|
+
input: process.stdin,
|
|
52
|
+
output: process.stdout,
|
|
53
|
+
});
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
const askForPath = () => {
|
|
56
|
+
rl.question(chalk.yellow(question), (input) => {
|
|
57
|
+
const trimmedInput = input.trim();
|
|
58
|
+
if (options.required && !trimmedInput) {
|
|
59
|
+
console.log(chalk.red('Path is required'));
|
|
60
|
+
askForPath();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!trimmedInput) {
|
|
64
|
+
rl.close();
|
|
65
|
+
resolve('');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const resolvedPath = path.resolve(trimmedInput);
|
|
69
|
+
if (options.mustExist && !fs.existsSync(resolvedPath)) {
|
|
70
|
+
console.log(chalk.red(`Path does not exist: ${resolvedPath}`));
|
|
71
|
+
askForPath();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (options.mustBeDirectory &&
|
|
75
|
+
fs.existsSync(resolvedPath) &&
|
|
76
|
+
!fs.statSync(resolvedPath).isDirectory()) {
|
|
77
|
+
console.log(chalk.red(`Path is not a directory: ${resolvedPath}`));
|
|
78
|
+
askForPath();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (options.mustBeFile &&
|
|
82
|
+
fs.existsSync(resolvedPath) &&
|
|
83
|
+
!fs.statSync(resolvedPath).isFile()) {
|
|
84
|
+
console.log(chalk.red(`Path is not a file: ${resolvedPath}`));
|
|
85
|
+
askForPath();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
rl.close();
|
|
89
|
+
resolve(resolvedPath);
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
askForPath();
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Handles terminal interactions, output formatting, spinners, and user input
|
|
97
|
+
*/
|
|
98
|
+
class Terminal {
|
|
99
|
+
spinnerInterval = null;
|
|
100
|
+
currentMessage = '';
|
|
101
|
+
spinnerConfig = {
|
|
102
|
+
frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],
|
|
103
|
+
interval: 80,
|
|
104
|
+
};
|
|
105
|
+
audiencePath = '/api/v2/';
|
|
106
|
+
/**
|
|
107
|
+
* Writes a message to stdout
|
|
108
|
+
*
|
|
109
|
+
* @param {string} message - The message to output
|
|
110
|
+
* @returns {boolean} - Always returns true
|
|
111
|
+
*/
|
|
112
|
+
output(message) {
|
|
113
|
+
process.stdout.write(message);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Starts a spinner with the given message
|
|
118
|
+
*
|
|
119
|
+
* @param {string} message - Message to display alongside the spinner
|
|
120
|
+
*/
|
|
121
|
+
startSpinner(message) {
|
|
122
|
+
let frameIndex = 0;
|
|
123
|
+
this.currentMessage = message;
|
|
124
|
+
// Clear any existing spinner
|
|
125
|
+
this.stopSpinnerWithoutMessage();
|
|
126
|
+
// Initial spinner state
|
|
127
|
+
process.stdout.write(`\r${chalk.cyan(this.spinnerConfig.frames[0])} ${message}`);
|
|
128
|
+
this.spinnerInterval = setInterval(() => {
|
|
129
|
+
process.stdout.write(`\r${chalk.cyan(this.spinnerConfig.frames[frameIndex])} ${message}`);
|
|
130
|
+
frameIndex = (frameIndex + 1) % this.spinnerConfig.frames.length;
|
|
131
|
+
}, this.spinnerConfig.interval);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Stops the spinner and clears the line without showing a completion message
|
|
135
|
+
*/
|
|
136
|
+
stopSpinnerWithoutMessage() {
|
|
137
|
+
if (this.spinnerInterval) {
|
|
138
|
+
clearInterval(this.spinnerInterval);
|
|
139
|
+
this.spinnerInterval = null;
|
|
140
|
+
// Clear the spinner line
|
|
141
|
+
process.stdout.write('\r\x1B[K');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Stops the spinner and shows a completion message
|
|
146
|
+
*/
|
|
147
|
+
stopSpinner() {
|
|
148
|
+
if (this.spinnerInterval) {
|
|
149
|
+
this.stopSpinnerWithoutMessage();
|
|
150
|
+
this.output(`${chalk.green('✓')} ${this.currentMessage}\n`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Extracts tenant information from an access token
|
|
155
|
+
*
|
|
156
|
+
* @param {string} accessToken - JWT access token
|
|
157
|
+
* @returns {string} - The tenant hostname
|
|
158
|
+
* @throws {Error} - If tenant extraction fails
|
|
159
|
+
*/
|
|
160
|
+
getTenantFromToken(accessToken) {
|
|
161
|
+
try {
|
|
162
|
+
const payload = jwtDecode(accessToken);
|
|
163
|
+
const audiences = Array.isArray(payload.aud) ? payload.aud : [payload.aud];
|
|
164
|
+
for (const aud of audiences) {
|
|
165
|
+
const url = new URL(aud);
|
|
166
|
+
if (url.pathname === this.audiencePath) {
|
|
167
|
+
return url.host;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
throw new Error('No valid audience found in token');
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
174
|
+
throw new Error(`Failed to extract tenant: ${errorMessage}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Prompts user for permission to open browser
|
|
179
|
+
*
|
|
180
|
+
* @returns {Promise<boolean>} - Resolves to true when user presses Enter
|
|
181
|
+
*/
|
|
182
|
+
async promptForBrowserPermission() {
|
|
183
|
+
const rl = readline.createInterface({
|
|
184
|
+
input: process.stdin,
|
|
185
|
+
output: process.stdout,
|
|
186
|
+
});
|
|
187
|
+
return new Promise((resolve) => {
|
|
188
|
+
rl.question(chalk.yellow(`Press Enter to open the browser to log in or ${chalk.cyan('^C')} to quit.\n`), () => {
|
|
189
|
+
rl.close();
|
|
190
|
+
resolve(true);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Prompts user to select scopes or uses provided ones
|
|
196
|
+
*
|
|
197
|
+
* @param {string[]} [providedScopes] - Optional pre-selected scopes
|
|
198
|
+
* @returns {Promise<string[]>} - Resolves to array of selected scopes
|
|
199
|
+
*/
|
|
200
|
+
async promptForScopeSelection(providedScopes) {
|
|
201
|
+
// If providedScopes were specified via --scopes flag, return them directly
|
|
202
|
+
if (providedScopes && providedScopes.length > 0) {
|
|
203
|
+
console.log(chalk.green(`Using provided scopes: ${providedScopes.join(', ')}`));
|
|
204
|
+
return providedScopes;
|
|
205
|
+
}
|
|
206
|
+
const scopeSelector = new ScopeSelector();
|
|
207
|
+
return scopeSelector.selectScopes();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Handles interactive scope selection in the terminal
|
|
212
|
+
*/
|
|
213
|
+
class ScopeSelector {
|
|
214
|
+
allScopes = [];
|
|
215
|
+
selectedScopes = new Set();
|
|
216
|
+
currentIndex = 0;
|
|
217
|
+
/**
|
|
218
|
+
* Creates a new scope selector instance
|
|
219
|
+
*/
|
|
220
|
+
constructor() {
|
|
221
|
+
this.allScopes = getAllScopes();
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Displays the interactive scope selection UI
|
|
225
|
+
*
|
|
226
|
+
* @returns {Promise<string[]>} - Resolves to an array of selected scopes
|
|
227
|
+
*/
|
|
228
|
+
async selectScopes() {
|
|
229
|
+
// Display header
|
|
230
|
+
console.log(chalk.cyan.bold('\nSelect scopes using spacebar, then press Enter to confirm:'));
|
|
231
|
+
console.log(chalk.dim('(Press spacebar to toggle selection, arrows to navigate, Enter when done)'));
|
|
232
|
+
console.log();
|
|
233
|
+
// Only add newlines if there are actually scopes to display
|
|
234
|
+
if (this.allScopes.length === 0) {
|
|
235
|
+
console.log(chalk.yellow('No scopes available to select.'));
|
|
236
|
+
return [];
|
|
237
|
+
}
|
|
238
|
+
// Hide cursor
|
|
239
|
+
process.stdout.write('\x1B[?25l');
|
|
240
|
+
// Handle keyboard input
|
|
241
|
+
process.stdin.setRawMode(true);
|
|
242
|
+
process.stdin.resume();
|
|
243
|
+
// Add initial newlines for menu display
|
|
244
|
+
this.allScopes.forEach(() => console.log(''));
|
|
245
|
+
// Display the menu initially
|
|
246
|
+
this.renderMenu();
|
|
247
|
+
return this.handleKeyboardInput();
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Sets up event listeners for keyboard input during scope selection
|
|
251
|
+
*
|
|
252
|
+
* @returns {Promise<string[]>} - Resolves to the selected scopes
|
|
253
|
+
*/
|
|
254
|
+
handleKeyboardInput() {
|
|
255
|
+
return new Promise((resolve) => {
|
|
256
|
+
process.stdin.on('data', (key) => {
|
|
257
|
+
const keyString = String(key);
|
|
258
|
+
if (this.handleControlKey(keyString, resolve)) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (keyString === ' ') {
|
|
262
|
+
this.toggleCurrentSelection();
|
|
263
|
+
}
|
|
264
|
+
else if (keyString.startsWith('\u001B[')) {
|
|
265
|
+
this.handleArrowKeys(keyString);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Handles control keys (Enter, Ctrl+C) during selection
|
|
272
|
+
*
|
|
273
|
+
* @param {string} keyString - The key input string
|
|
274
|
+
* @param {(scopes: string[]) => void} resolve - The promise resolve function
|
|
275
|
+
* @returns {boolean} - True if a control key was handled, false otherwise
|
|
276
|
+
*/
|
|
277
|
+
handleControlKey(keyString, resolve) {
|
|
278
|
+
if (keyString === '\r' || keyString === '\n') {
|
|
279
|
+
// Enter key - finish selection
|
|
280
|
+
this.cleanup();
|
|
281
|
+
const result = Array.from(this.selectedScopes);
|
|
282
|
+
if (result.length === 0) {
|
|
283
|
+
console.log(chalk.yellow('No scopes selected.'));
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
console.log(chalk.green(`Selected scopes: ${result.join(', ')}`));
|
|
287
|
+
}
|
|
288
|
+
resolve(result);
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
if (keyString === '\u0003') {
|
|
292
|
+
// Ctrl+C - exit
|
|
293
|
+
this.cleanup();
|
|
294
|
+
console.log(chalk.red('Selection cancelled.'));
|
|
295
|
+
process.exit(0);
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Toggles selection of the current scope
|
|
302
|
+
*/
|
|
303
|
+
toggleCurrentSelection() {
|
|
304
|
+
const scope = this.allScopes[this.currentIndex];
|
|
305
|
+
if (this.selectedScopes.has(scope)) {
|
|
306
|
+
this.selectedScopes.delete(scope);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
this.selectedScopes.add(scope);
|
|
310
|
+
}
|
|
311
|
+
this.renderMenu();
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Handles arrow key navigation
|
|
315
|
+
*
|
|
316
|
+
* @param {string} keyString - The key input string
|
|
317
|
+
*/
|
|
318
|
+
handleArrowKeys(keyString) {
|
|
319
|
+
// Simple arrow keys (up/down)
|
|
320
|
+
if (keyString === '\u001B[A') {
|
|
321
|
+
this.currentIndex = Math.max(0, this.currentIndex - 1);
|
|
322
|
+
this.renderMenu();
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (keyString === '\u001B[B') {
|
|
326
|
+
this.currentIndex = Math.min(this.allScopes.length - 1, this.currentIndex + 1);
|
|
327
|
+
this.renderMenu();
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
// Handle other arrow key combinations
|
|
331
|
+
const arrowMatch = keyString.match(/\u001B\[(\d+)?([A-D])/);
|
|
332
|
+
if (arrowMatch) {
|
|
333
|
+
const [_, count, direction] = arrowMatch;
|
|
334
|
+
const moveCount = parseInt(count || '1', 10);
|
|
335
|
+
if (direction === 'A') {
|
|
336
|
+
// Up arrow
|
|
337
|
+
this.currentIndex = Math.max(0, this.currentIndex - moveCount);
|
|
338
|
+
this.renderMenu();
|
|
339
|
+
}
|
|
340
|
+
else if (direction === 'B') {
|
|
341
|
+
// Down arrow
|
|
342
|
+
this.currentIndex = Math.min(this.allScopes.length - 1, this.currentIndex + moveCount);
|
|
343
|
+
this.renderMenu();
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Renders the scope selection menu in the terminal
|
|
349
|
+
*/
|
|
350
|
+
renderMenu() {
|
|
351
|
+
// Clear previous menu
|
|
352
|
+
process.stdout.write('\r\x1B[K'); // Clear current line
|
|
353
|
+
for (let i = 0; i < this.allScopes.length; i++) {
|
|
354
|
+
process.stdout.write('\x1B[1A\x1B[K'); // Move up and clear line
|
|
355
|
+
}
|
|
356
|
+
// Display each scope with selection indicator
|
|
357
|
+
this.allScopes.forEach((scope, index) => {
|
|
358
|
+
const isSelected = this.selectedScopes.has(scope);
|
|
359
|
+
const isCurrent = index === this.currentIndex;
|
|
360
|
+
process.stdout.write(`${isCurrent ? '>' : ' '} ${isSelected ? '[x]' : '[ ]'} ${chalk.green(scope)}\n`);
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Cleans up terminal state after selection
|
|
365
|
+
*/
|
|
366
|
+
cleanup() {
|
|
367
|
+
process.stdin.setRawMode(false);
|
|
368
|
+
process.stdin.pause();
|
|
369
|
+
process.stdin.removeAllListeners('data');
|
|
370
|
+
process.stdout.write('\x1B[?25h'); // Show cursor
|
|
371
|
+
console.log(''); // Add a newline
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
// Create and export the Terminal instance
|
|
375
|
+
const terminal = new Terminal();
|
|
376
|
+
// Export functions that match the original API
|
|
377
|
+
export const cliOutput = (message) => terminal.output(message);
|
|
378
|
+
export const startSpinner = (message) => terminal.startSpinner(message);
|
|
379
|
+
export const stopSpinner = () => terminal.stopSpinner();
|
|
380
|
+
export const getTenantFromToken = (accessToken) => terminal.getTenantFromToken(accessToken);
|
|
381
|
+
export const promptForBrowserPermission = () => terminal.promptForBrowserPermission();
|
|
382
|
+
export const promptForScopeSelection = (providedScopes) => terminal.promptForScopeSelection(providedScopes);
|
|
383
|
+
/**
|
|
384
|
+
* Masks a tenant name according to the specified format:
|
|
385
|
+
* - Shows letters before the dash
|
|
386
|
+
* - Shows 3 letters after the dash
|
|
387
|
+
* - Shows the last word after the last dot
|
|
388
|
+
* - Masks everything else with "xxx"
|
|
389
|
+
*
|
|
390
|
+
* Example: "dev-sfhjdfhdgfghhjdfhf.us.auth0.com" becomes "dev-sfh***com"
|
|
391
|
+
*
|
|
392
|
+
* @param tenantName The tenant name to mask
|
|
393
|
+
* @returns The masked tenant name or the original if it doesn't match the expected format
|
|
394
|
+
*/
|
|
395
|
+
export function maskTenantName(tenantName) {
|
|
396
|
+
if (!tenantName) {
|
|
397
|
+
return 'unknown';
|
|
398
|
+
}
|
|
399
|
+
const dashIndex = tenantName.indexOf('-');
|
|
400
|
+
const lastDotIndex = tenantName.lastIndexOf('.');
|
|
401
|
+
if (dashIndex === -1 || lastDotIndex === -1) {
|
|
402
|
+
return tenantName; // Return as is if format doesn't match expected pattern
|
|
403
|
+
}
|
|
404
|
+
const prefix = tenantName.substring(0, dashIndex);
|
|
405
|
+
const threeAfterDash = tenantName.substring(dashIndex + 1, dashIndex + 4);
|
|
406
|
+
const lastPart = tenantName.substring(lastDotIndex + 1);
|
|
407
|
+
return `${prefix}-${threeAfterDash}***${lastPart}`;
|
|
408
|
+
}
|
|
409
|
+
//# sourceMappingURL=terminal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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,cAAc,CAAC,UAAqC;IAClE,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1C,MAAM,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAEjD,IAAI,SAAS,KAAK,CAAC,CAAC,IAAI,YAAY,KAAK,CAAC,CAAC,EAAE,CAAC;QAC5C,OAAO,UAAU,CAAC,CAAC,wDAAwD;IAC7E,CAAC;IAED,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IAClD,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC;IAC1E,MAAM,QAAQ,GAAG,UAAU,CAAC,SAAS,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;IAExD,OAAO,GAAG,MAAM,IAAI,cAAc,MAAM,QAAQ,EAAE,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Tool } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Filters the provided tools collection based on specified glob patterns and readOnly flag.
|
|
4
|
+
* This function processes the input patterns against available tools to determine
|
|
5
|
+
* which tools should be returned. It handles special cases like wildcard patterns,
|
|
6
|
+
* empty pattern arrays, and pattern matching errors. When readOnly is true,
|
|
7
|
+
* it only returns tools that have _meta.readOnly set to true or tools that follow read-only patterns.
|
|
8
|
+
*
|
|
9
|
+
* IMPORTANT: The readOnly flag takes priority over pattern matching for security reasons.
|
|
10
|
+
* Even if patterns match non-read-only tools, when readOnly=true is specified,
|
|
11
|
+
* only read-only tools will be returned.
|
|
12
|
+
*
|
|
13
|
+
* @param allTools - Complete collection of available tools to be filtered
|
|
14
|
+
* @param patterns - Optional glob patterns to filter tools by (e.g., 'ziti*', 'jwt-*')
|
|
15
|
+
* If omitted or empty, all tools will be returned
|
|
16
|
+
* A single '*' pattern will return all tools
|
|
17
|
+
* @param readOnly - Optional flag to only return read-only tools
|
|
18
|
+
* When true, only returns tools marked as readOnly
|
|
19
|
+
* Takes priority over pattern matching for security
|
|
20
|
+
* @returns Array of Tool objects that match the specified criteria
|
|
21
|
+
* Returns all tools if no patterns provided or on error
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Return all tools that start with "auth"
|
|
25
|
+
* const authTools = getAvailableTools(tools, ['auth*']);
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Return all read-only tools (regardless of pattern matching)
|
|
29
|
+
* const readOnlyTools = getAvailableTools(tools, ['*'], true);
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // Return only read-only tools that match the pattern
|
|
33
|
+
* // Note: --read-only takes priority, so even if the pattern matches non-read-only tools,
|
|
34
|
+
* // only the read-only ones will be returned
|
|
35
|
+
* const readOnlyAuthTools = getAvailableTools(tools, ['ziti_*_application'], true);
|
|
36
|
+
*/
|
|
37
|
+
export declare function getAvailableTools(allTools: Tool[], patterns?: string[], readOnly?: boolean): Tool[];
|
|
38
|
+
/**
|
|
39
|
+
* Validates tool patterns against available tools to ensure each pattern matches at least one tool.
|
|
40
|
+
* This function verifies that each provided pattern (including glob patterns) corresponds to
|
|
41
|
+
* at least one available tool, throwing specific errors for different validation scenarios.
|
|
42
|
+
*
|
|
43
|
+
* @param patterns - Array of tool name patterns to validate
|
|
44
|
+
* Can include glob patterns with wildcards (e.g., 'ziti*')
|
|
45
|
+
* Empty array or undefined will skip validation
|
|
46
|
+
* @param availableTools - Collection of Tool objects to validate patterns against
|
|
47
|
+
*
|
|
48
|
+
* @throws {Error} If availableTools is not a valid array or is empty
|
|
49
|
+
* @throws {Error} If any pattern doesn't match at least one tool name, with different
|
|
50
|
+
* error messages for exact matches vs. wildcard patterns
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Validate specific tool names
|
|
54
|
+
* validatePatterns(['ziti-jwt', 'ziti-management'], tools);
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // Validate with glob patterns
|
|
58
|
+
* validatePatterns(['ziti*', 'jwt-*'], tools);
|
|
59
|
+
*
|
|
60
|
+
* @see {@link Glob} for the pattern matching implementation
|
|
61
|
+
* @see {@link getAvailableTools} for filtering tools using these patterns
|
|
62
|
+
*/
|
|
63
|
+
export declare function validatePatterns(patterns: string[], availableTools: Tool[]): void;
|