@reshapr/reshapr-cli 0.0.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.
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Copyright The Reshapr Authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export function formatEndpoint(fqdn, organizationId, serviceName, serviceVersion) {
17
+ return `${fqdn}/mcp/${organizationId}/${encodeUrl(serviceName)}/${encodeUrl(serviceVersion)}`;
18
+ }
19
+ function encodeUrl(url) {
20
+ return url.replace(/\s/g, '+');
21
+ }
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright The Reshapr Authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import chalk from "chalk";
17
+ export class Logger {
18
+ static muted = false;
19
+ static mute() {
20
+ Logger.muted = true;
21
+ }
22
+ static unmute() {
23
+ Logger.muted = false;
24
+ }
25
+ static bold(message) {
26
+ if (!Logger.muted) {
27
+ console.log(chalk.white.bold(message));
28
+ }
29
+ }
30
+ static log(message) {
31
+ if (!Logger.muted) {
32
+ console.log(message);
33
+ }
34
+ }
35
+ static info(message) {
36
+ if (!Logger.muted) {
37
+ console.log(chalk.bgBlue('ℹ️ ') + chalk.blue(` ${message}`));
38
+ }
39
+ }
40
+ static success(message) {
41
+ if (!Logger.muted) {
42
+ console.log(chalk.bgGreen('✅') + chalk.green(` ${message}`));
43
+ }
44
+ }
45
+ static warn(message) {
46
+ if (!Logger.muted) {
47
+ console.warn(chalk.bgYellow('⚠️ ') + chalk.yellow(` ${message}`));
48
+ }
49
+ }
50
+ static error(message) {
51
+ console.error(chalk.bgRed('❌') + chalk.red(` ${message}`));
52
+ }
53
+ }
@@ -0,0 +1 @@
1
+ export const CLI_VERSION = "0.0.1";
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@reshapr/reshapr-cli",
3
+ "version": "0.0.1",
4
+ "description": "CLI for reshapr.io - The MCP Gateway for AI-Native API Access!",
5
+ "type": "module",
6
+ "main": "src/cli.ts",
7
+ "bin": {
8
+ "reshapr": "dist/cli.js"
9
+ },
10
+ "license": "Apache-2.0",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "scripts": {
15
+ "start": "node src/cli.ts",
16
+ "prebuild": "node -p \"'export const CLI_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
17
+ "build": "tsc",
18
+ "dev": "tsc --watch",
19
+ "test": "vitest",
20
+ "lint": "eslint src/**/*.ts"
21
+ },
22
+ "dependencies": {
23
+ "chalk": "^5.4.1",
24
+ "commander": "^14.0.0",
25
+ "get-port": "^7.1.0",
26
+ "inquirer": "^12.7.0",
27
+ "js-yaml": "^4.1.0",
28
+ "open": "^10.2.0",
29
+ "yocto-spinner": "^1.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/commander": "^2.12.0",
33
+ "@types/js-yaml": "^4.0.9",
34
+ "@types/node": "^24.0.13",
35
+ "typescript": "^5.8.3"
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "engines": {
41
+ "node": ">= 20"
42
+ }
43
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * Copyright The Reshapr Authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ import { program } from 'commander';
19
+ import * as yaml from 'js-yaml';
20
+ import { loginCommand, infoCommand, logoutCommand, importCommand, attachCommand, quotasCommand } from './commands/index.js';
21
+ import { ConfigUtil } from './utils/config.js';
22
+ import { Logger } from './utils/logger.js';
23
+ import { Context } from './utils/context.js';
24
+ import { CLI_VERSION } from './version.js';
25
+ import { CLI_NAME, CLI_LABEL } from './constants.js';
26
+
27
+ program
28
+ .name(CLI_NAME)
29
+ .description(CLI_LABEL + ' CLI - A command line interface for ' + CLI_LABEL)
30
+ .version(CLI_VERSION)
31
+ .hook('preAction', (thisCommand, actionCommand) => {
32
+ ConfigUtil.readConfig();
33
+ if (actionCommand.name() != 'login' && actionCommand.name() != 'logout') {
34
+ if (!ConfigUtil.config.token) {
35
+ Logger.warn(`You are not logged in. Please login first using the \`${CLI_NAME} login\` command.`);
36
+ process.exit(1);
37
+ }
38
+ if (ConfigUtil.config.exp && ConfigUtil.config.exp < Date.now() / 1000) {
39
+ Logger.warn(`Your token has expired. Please login again using the \`${CLI_NAME} login\` command.`);
40
+ process.exit(1);
41
+ }
42
+ }
43
+
44
+ if (actionCommand.opts().output) {
45
+ Logger.mute();
46
+ }
47
+ })
48
+ .hook('postAction', (thisCommand, actionCommand) => {
49
+ if (actionCommand.opts().output) {
50
+ Logger.unmute();
51
+ // Check requested format.
52
+ const format = actionCommand.opts().output.toLowerCase();
53
+ if (format !== 'json' && format !== 'yaml') {
54
+ Logger.error('Invalid output format. Supported formats are json and yaml.');
55
+ process.exit(1);
56
+ }
57
+
58
+ if (!Context.isEmpty()) {
59
+ if (Context.size() === 1) {
60
+ const firstKey = Object.keys(Context.getAll())[0];
61
+ if (format === 'json') {
62
+ Logger.log(convertToJson(Context.get(firstKey)));
63
+ } else if (format === 'yaml') {
64
+ Logger.log(convertToYaml(Context.get(firstKey)));
65
+ }
66
+ } else {
67
+ if (format === 'json') {
68
+ Logger.log(convertToJson(Context.getAll()));
69
+ } else if (format === 'yaml') {
70
+ Logger.log(convertToYaml(Context.getAll()));
71
+ }
72
+ }
73
+ }
74
+ }
75
+ });
76
+
77
+ function convertToJson(data: any) : string {
78
+ return JSON.stringify(data, null, 2);
79
+ }
80
+ function convertToYaml(data: any): string {
81
+ return yaml.dump(data);
82
+ }
83
+
84
+
85
+ process.on('uncaughtException', (error) => {
86
+ console.error('Uncaught Exception:', error);
87
+ process.exit(1);
88
+ });
89
+
90
+ process.on('unhandledRejection', (reason, promise) => {
91
+ console.error('Unhandled Rejection at:', promise, 'reason:', reason);
92
+ process.exit(1);
93
+ });
94
+
95
+
96
+ // Load commands.
97
+ program.addCommand(loginCommand);
98
+ program.addCommand(infoCommand);
99
+ program.addCommand(logoutCommand);
100
+ program.addCommand(importCommand);
101
+ program.addCommand(attachCommand);
102
+ program.addCommand(quotasCommand);
103
+
104
+ program.parse(process.argv);