@mindbricks/mbx 1.0.4

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/README.md ADDED
@@ -0,0 +1,2 @@
1
+
2
+ LI tool for Mindbricks platform authentication.
package/dist/auth.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { LoginCredentials, LoginResponse, StoredToken } from './types';
2
+ export declare class AuthService {
3
+ private apiUrl;
4
+ constructor();
5
+ login(credentials: LoginCredentials): Promise<LoginResponse>;
6
+ prepareTokenForStorage(response: LoginResponse): StoredToken;
7
+ }
8
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,WAAW,EAAY,MAAM,SAAS,CAAC;AAGjF,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAS;;IAMjB,KAAK,CAAC,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAqClE,sBAAsB,CAAC,QAAQ,EAAE,aAAa,GAAG,WAAW;CAW7D"}
package/dist/auth.js ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AuthService = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const config_1 = require("./config");
9
+ class AuthService {
10
+ constructor() {
11
+ this.apiUrl = `${config_1.CONFIG.API_BASE_URL}${config_1.CONFIG.LOGIN_ENDPOINT}`;
12
+ }
13
+ async login(credentials) {
14
+ try {
15
+ const response = await axios_1.default.post(this.apiUrl, credentials, {
16
+ headers: {
17
+ 'Content-Type': 'application/json',
18
+ },
19
+ timeout: 30000,
20
+ });
21
+ return response.data;
22
+ }
23
+ catch (error) {
24
+ if (axios_1.default.isAxiosError(error)) {
25
+ const axiosError = error;
26
+ if (axiosError.response) {
27
+ const statusCode = axiosError.response.status;
28
+ const errorMessage = axiosError.response.data?.message || axiosError.response.data?.error;
29
+ throw new Error(`${errorMessage} (${statusCode})`);
30
+ }
31
+ else if (axiosError.request) {
32
+ throw new Error('No response from server. Please check your internet connection.');
33
+ }
34
+ else {
35
+ throw new Error(`Request error: ${axiosError.message}`);
36
+ }
37
+ }
38
+ throw new Error(`Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}`);
39
+ }
40
+ }
41
+ prepareTokenForStorage(response) {
42
+ return {
43
+ sessionId: response.sessionId,
44
+ accessToken: response.accessToken,
45
+ userId: response.userId,
46
+ email: response.email,
47
+ fullname: response.fullname,
48
+ roleId: response.roleId,
49
+ loginAt: response.loginAt,
50
+ };
51
+ }
52
+ }
53
+ exports.AuthService = AuthService;
54
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0C;AAE1C,qCAAkC;AAElC,MAAa,WAAW;IAGtB;QACE,IAAI,CAAC,MAAM,GAAG,GAAG,eAAM,CAAC,YAAY,GAAG,eAAM,CAAC,cAAc,EAAE,CAAC;IACjE,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,WAA6B;QACvC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,IAAI,CAAC,MAAM,EACX,WAAW,EACX;gBACE,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;iBACnC;gBACD,OAAO,EAAE,KAAK;aACf,CACF,CAAC;YAEF,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,eAAK,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC9B,MAAM,UAAU,GAAG,KAA6B,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names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commander_1 = require("commander");
5
+ const commands_1 = require("./commands");
6
+ const program = new commander_1.Command();
7
+ const handler = new commands_1.CommandHandler();
8
+ program
9
+ .name('mbx')
10
+ .description('Mindbricks CLI - Command line tools for Mindbricks platform')
11
+ .version('1.0.0');
12
+ program
13
+ .command('login')
14
+ .description('Authenticate with your account')
15
+ .action(async () => {
16
+ await handler.handleLogin();
17
+ });
18
+ program
19
+ .command('whoami')
20
+ .description('Display current authenticated user information')
21
+ .action(async () => {
22
+ await handler.handleWhoami();
23
+ });
24
+ program.parse(process.argv);
25
+ if (!process.argv.slice(2).length) {
26
+ program.outputHelp();
27
+ }
28
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,yCAAoC;AACpC,yCAA4C;AAE5C,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAC9B,MAAM,OAAO,GAAG,IAAI,yBAAc,EAAE,CAAC;AAErC,OAAO;KACJ,IAAI,CAAC,KAAK,CAAC;KACX,WAAW,CAAC,6DAA6D,CAAC;KAC1E,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,gCAAgC,CAAC;KAC7C,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;AAC9B,CAAC,CAAC,CAAC;AAGL,OAAO;KACJ,OAAO,CAAC,QAAQ,CAAC;KACjB,WAAW,CAAC,gDAAgD,CAAC;KAC7D,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,MAAM,OAAO,CAAC,YAAY,EAAE,CAAC;AAC/B,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,OAAO,CAAC,UAAU,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare class CommandHandler {
2
+ private authService;
3
+ private storage;
4
+ constructor();
5
+ handleLogin(): Promise<void>;
6
+ handleWhoami(): Promise<void>;
7
+ }
8
+ //# sourceMappingURL=commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAMA,qBAAa,cAAc;IACzB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,OAAO,CAAe;;IAQxB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAmD5B,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAuBpC"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CommandHandler = void 0;
7
+ const prompts_1 = __importDefault(require("prompts"));
8
+ const auth_1 = require("./auth");
9
+ const storage_1 = require("./storage");
10
+ const config_1 = require("./config");
11
+ class CommandHandler {
12
+ constructor() {
13
+ this.authService = new auth_1.AuthService();
14
+ this.storage = new storage_1.TokenStorage();
15
+ }
16
+ async handleLogin() {
17
+ try {
18
+ console.log('🔐 Authentication\n');
19
+ const credentials = await (0, prompts_1.default)([
20
+ {
21
+ type: 'text',
22
+ name: 'username',
23
+ message: 'Email:',
24
+ validate: (value) => {
25
+ if (!value || value.trim().length === 0) {
26
+ return 'Email is required';
27
+ }
28
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
29
+ if (!emailRegex.test(value)) {
30
+ return 'Please enter a valid email address';
31
+ }
32
+ return true;
33
+ }
34
+ },
35
+ {
36
+ type: 'password',
37
+ name: 'password',
38
+ message: 'Password:',
39
+ validate: (value) => value && value.length > 0 ? true : 'Password is required'
40
+ }
41
+ ]);
42
+ if (!credentials.username || !credentials.password) {
43
+ console.log('\n❌ Login cancelled');
44
+ process.exit(0);
45
+ }
46
+ console.log('\n⏳ Authenticating...');
47
+ const response = await this.authService.login(credentials);
48
+ const tokenData = this.authService.prepareTokenForStorage(response);
49
+ this.storage.saveToken(tokenData);
50
+ console.log(`\n${config_1.MESSAGES.LOGIN_SUCCESS}`);
51
+ console.log(`👤 Logged in as: ${tokenData.fullname} (${tokenData.email})`);
52
+ console.log(`📁 Token saved to: ${this.storage.getTokenPath()}`);
53
+ }
54
+ catch (error) {
55
+ console.error(`\n${config_1.MESSAGES.LOGIN_FAILED}`);
56
+ console.error(` ${error instanceof Error ? error.message : 'Unknown error'}`);
57
+ process.exit(1);
58
+ }
59
+ }
60
+ async handleWhoami() {
61
+ try {
62
+ const token = this.storage.getToken();
63
+ if (!token) {
64
+ console.log(`ℹ️ ${config_1.MESSAGES.NO_TOKEN}`);
65
+ return;
66
+ }
67
+ console.log('\n📋 Current Authentication Status\n');
68
+ console.log(` Name: ${token.fullname}`);
69
+ console.log(` Email: ${token.email}`);
70
+ console.log(` User ID: ${token.userId}`);
71
+ console.log(` Role: ${token.roleId}`);
72
+ console.log(` Session ID: ${token.sessionId}`);
73
+ console.log(` Logged in: ${new Date(token.loginAt).toLocaleString()}`);
74
+ console.log(`\n Token file: ${this.storage.getTokenPath()}`);
75
+ }
76
+ catch (error) {
77
+ console.error('❌ Failed to retrieve user information');
78
+ console.error(` ${error instanceof Error ? error.message : 'Unknown error'}`);
79
+ process.exit(1);
80
+ }
81
+ }
82
+ }
83
+ exports.CommandHandler = CommandHandler;
84
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts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B,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YAChD,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;YAC7C,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;YAC9C,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;YAC9C,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;YACjD,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;YAC1E,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QACjE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;YACvD,OAAO,CAAC,KAAK,CAAC,MAAM,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;YAChF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CACF;AApFD,wCAoFC"}
@@ -0,0 +1,14 @@
1
+ export declare const CONFIG: {
2
+ readonly API_BASE_URL: "https://app.mindbricks.com";
3
+ readonly LOGIN_ENDPOINT: "/api/mindbrix-auth/login";
4
+ readonly TOKEN_FILE_NAME: "mbx-token.json";
5
+ };
6
+ export declare const MESSAGES: {
7
+ readonly LOGIN_SUCCESS: "✓ Successfully logged in!";
8
+ readonly LOGIN_FAILED: "✗ Login failed";
9
+ readonly LOGOUT_SUCCESS: "✓ Successfully logged out";
10
+ readonly NO_TOKEN: "Not authenticated. Please run: mbx login";
11
+ readonly TOKEN_SAVED: "✓ Token saved successfully";
12
+ readonly INVALID_CREDENTIALS: "✗ Invalid email or password";
13
+ };
14
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM;;;;CAIT,CAAC;AAEX,eAAO,MAAM,QAAQ;;;;;;;CAOX,CAAC"}
package/dist/config.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MESSAGES = exports.CONFIG = void 0;
4
+ exports.CONFIG = {
5
+ API_BASE_URL: 'https://app.mindbricks.com',
6
+ LOGIN_ENDPOINT: '/api/mindbrix-auth/login',
7
+ TOKEN_FILE_NAME: 'mbx-token.json',
8
+ };
9
+ exports.MESSAGES = {
10
+ LOGIN_SUCCESS: '✓ Successfully logged in!',
11
+ LOGIN_FAILED: '✗ Login failed',
12
+ LOGOUT_SUCCESS: '✓ Successfully logged out',
13
+ NO_TOKEN: 'Not authenticated. Please run: mbx login',
14
+ TOKEN_SAVED: '✓ Token saved successfully',
15
+ INVALID_CREDENTIALS: '✗ Invalid email or password',
16
+ };
17
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAEa,QAAA,MAAM,GAAG;IACpB,YAAY,EAAE,4BAA4B;IAC1C,cAAc,EAAE,0BAA0B;IAC1C,eAAe,EAAE,gBAAgB;CACzB,CAAC;AAEE,QAAA,QAAQ,GAAG;IACtB,aAAa,EAAE,2BAA2B;IAC1C,YAAY,EAAE,gBAAgB;IAC9B,cAAc,EAAE,2BAA2B;IAC3C,QAAQ,EAAE,0CAA0C;IACpD,WAAW,EAAE,4BAA4B;IACzC,mBAAmB,EAAE,6BAA6B;CAC1C,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { AuthService } from './auth';
2
+ export { TokenStorage } from './storage';
3
+ export { CommandHandler } from './commands';
4
+ export * from './types';
5
+ export { CONFIG } from './config';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.CONFIG = exports.CommandHandler = exports.TokenStorage = exports.AuthService = void 0;
18
+ var auth_1 = require("./auth");
19
+ Object.defineProperty(exports, "AuthService", { enumerable: true, get: function () { return auth_1.AuthService; } });
20
+ var storage_1 = require("./storage");
21
+ Object.defineProperty(exports, "TokenStorage", { enumerable: true, get: function () { return storage_1.TokenStorage; } });
22
+ var commands_1 = require("./commands");
23
+ Object.defineProperty(exports, "CommandHandler", { enumerable: true, get: function () { return commands_1.CommandHandler; } });
24
+ __exportStar(require("./types"), exports);
25
+ var config_1 = require("./config");
26
+ Object.defineProperty(exports, "CONFIG", { enumerable: true, get: function () { return config_1.CONFIG; } });
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,+BAAqC;AAA5B,mGAAA,WAAW,OAAA;AACpB,qCAAyC;AAAhC,uGAAA,YAAY,OAAA;AACrB,uCAA4C;AAAnC,0GAAA,cAAc,OAAA;AACvB,0CAAwB;AACxB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA"}
@@ -0,0 +1,11 @@
1
+ import { StoredToken } from './types';
2
+ export declare class TokenStorage {
3
+ private tokenPath;
4
+ constructor(workingDirectory?: string);
5
+ saveToken(token: StoredToken): void;
6
+ getToken(): StoredToken | null;
7
+ deleteToken(): boolean;
8
+ hasToken(): boolean;
9
+ getTokenPath(): string;
10
+ }
11
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAKtC,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAAS;gBAEd,gBAAgB,GAAE,MAAsB;IAKpD,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAUnC,QAAQ,IAAI,WAAW,GAAG,IAAI;IAa9B,WAAW,IAAI,OAAO;IAatB,QAAQ,IAAI,OAAO;IAKnB,YAAY,IAAI,MAAM;CAGvB"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.TokenStorage = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const config_1 = require("./config");
40
+ class TokenStorage {
41
+ constructor(workingDirectory = process.cwd()) {
42
+ this.tokenPath = path.join(workingDirectory, config_1.CONFIG.TOKEN_FILE_NAME);
43
+ }
44
+ saveToken(token) {
45
+ try {
46
+ const tokenData = JSON.stringify(token, null, 2);
47
+ fs.writeFileSync(this.tokenPath, tokenData, 'utf-8');
48
+ }
49
+ catch (error) {
50
+ throw new Error(`Failed to save token: ${error instanceof Error ? error.message : 'Unknown error'}`);
51
+ }
52
+ }
53
+ getToken() {
54
+ try {
55
+ if (!fs.existsSync(this.tokenPath)) {
56
+ return null;
57
+ }
58
+ const tokenData = fs.readFileSync(this.tokenPath, 'utf-8');
59
+ return JSON.parse(tokenData);
60
+ }
61
+ catch (error) {
62
+ return null;
63
+ }
64
+ }
65
+ deleteToken() {
66
+ try {
67
+ if (fs.existsSync(this.tokenPath)) {
68
+ fs.unlinkSync(this.tokenPath);
69
+ return true;
70
+ }
71
+ return false;
72
+ }
73
+ catch (error) {
74
+ return false;
75
+ }
76
+ }
77
+ hasToken() {
78
+ return fs.existsSync(this.tokenPath);
79
+ }
80
+ getTokenPath() {
81
+ return this.tokenPath;
82
+ }
83
+ }
84
+ exports.TokenStorage = TokenStorage;
85
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAE7B,qCAAkC;AAIlC,MAAa,YAAY;IAGvB,YAAY,mBAA2B,OAAO,CAAC,GAAG,EAAE;QAClD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,eAAM,CAAC,eAAe,CAAC,CAAC;IACvE,CAAC;IAGD,SAAS,CAAC,KAAkB;QAC1B,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACjD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QACvD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;QACvG,CAAC;IACH,CAAC;IAGD,QAAQ;QACN,IAAI,CAAC;YACH,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;gBACnC,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,SAAS,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YAC3D,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAgB,CAAC;QAC9C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAGD,WAAW;QACT,IAAI,CAAC;YACH,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;gBAClC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC9B,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAGD,QAAQ;QACN,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAGD,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF;AApDD,oCAoDC"}
@@ -0,0 +1,67 @@
1
+ export interface LoginCredentials {
2
+ username: string;
3
+ password: string;
4
+ }
5
+ export interface LoginResponse {
6
+ appCodename: string;
7
+ sessionId: string;
8
+ userId: string;
9
+ email: string;
10
+ fullname: string;
11
+ avatar: string;
12
+ roleId: string;
13
+ mobile: string | null;
14
+ mobileVerified: boolean;
15
+ emailVerified: boolean;
16
+ stripeCustomerId: string;
17
+ birthday: string | null;
18
+ registeredAt: string;
19
+ loginAt: string;
20
+ _USERID: string;
21
+ loginIp: string;
22
+ city: string;
23
+ country: string;
24
+ localDateTime: string;
25
+ gmtOffset: number;
26
+ timeZoneCode: string;
27
+ language: {
28
+ code: string;
29
+ name: string;
30
+ native: string;
31
+ };
32
+ location: {
33
+ lat: number;
34
+ lon: number;
35
+ };
36
+ isp: string;
37
+ agent: {
38
+ deviceType: string;
39
+ os: string;
40
+ osVersion: string;
41
+ browserName: string;
42
+ browserVersion: string;
43
+ architecture: string | null;
44
+ model: string | null;
45
+ vendor: string;
46
+ };
47
+ checkTokenMark: string;
48
+ userBucketToken: string;
49
+ userEventToken: string;
50
+ accessToken: string;
51
+ }
52
+ export interface StoredToken {
53
+ sessionId: string;
54
+ accessToken: string;
55
+ userId: string;
56
+ email: string;
57
+ fullname: string;
58
+ roleId: string;
59
+ loginAt: string;
60
+ expiresAt?: string;
61
+ }
62
+ export interface ApiError {
63
+ message: string;
64
+ statusCode?: number;
65
+ error?: string;
66
+ }
67
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,OAAO,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE;QACL,UAAU,EAAE,MAAM,CAAC;QACnB,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@mindbricks/mbx",
3
+ "version": "1.0.4",
4
+ "description": "Mindbricks CLI Command line tools for Mindbricks platform",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "mbx": "dist/cli.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "dev": "tsc --watch",
12
+ "prepare": "npm run build",
13
+ "start": "node dist/cli.js"
14
+ },
15
+ "keywords": [
16
+ "mindbricks",
17
+ "cli",
18
+ "authentication",
19
+ "mbx"
20
+ ],
21
+ "author": "Mindbricks",
22
+ "license": "MIT",
23
+ "files": [
24
+ "dist",
25
+ "README.md"
26
+ ],
27
+ "dependencies": {
28
+ "axios": "^1.6.5",
29
+ "commander": "^12.0.0",
30
+ "prompts": "^2.4.2"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^20.11.5",
34
+ "@types/prompts": "^2.4.9",
35
+ "typescript": "^5.3.3"
36
+ },
37
+ "engines": {
38
+ "node": ">=16.0.0"
39
+ }
40
+ }