@urugus/slack-cli 0.2.2 → 0.2.3
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/.claude/settings.local.json +2 -1
- package/dist/commands/channels.d.ts.map +1 -1
- package/dist/commands/channels.js +7 -4
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/unread.d.ts.map +1 -1
- package/dist/commands/unread.js +17 -21
- package/dist/commands/unread.js.map +1 -1
- package/dist/utils/config/config-file-manager.d.ts +13 -0
- package/dist/utils/config/config-file-manager.d.ts.map +1 -0
- package/dist/utils/config/config-file-manager.js +85 -0
- package/dist/utils/config/config-file-manager.js.map +1 -0
- package/dist/utils/config/profile-manager.d.ts +16 -0
- package/dist/utils/config/profile-manager.d.ts.map +1 -0
- package/dist/utils/config/profile-manager.js +64 -0
- package/dist/utils/config/profile-manager.js.map +1 -0
- package/dist/utils/config/token-crypto-service.d.ts +11 -0
- package/dist/utils/config/token-crypto-service.d.ts.map +1 -0
- package/dist/utils/config/token-crypto-service.js +111 -0
- package/dist/utils/config/token-crypto-service.js.map +1 -0
- package/dist/utils/formatters/base-formatter.d.ts +23 -0
- package/dist/utils/formatters/base-formatter.d.ts.map +1 -0
- package/dist/utils/formatters/base-formatter.js +26 -0
- package/dist/utils/formatters/base-formatter.js.map +1 -0
- package/dist/utils/formatters/channel-formatters.d.ts +4 -13
- package/dist/utils/formatters/channel-formatters.d.ts.map +1 -1
- package/dist/utils/formatters/channel-formatters.js +18 -26
- package/dist/utils/formatters/channel-formatters.js.map +1 -1
- package/dist/utils/formatters/channels-list-formatters.d.ts +3 -10
- package/dist/utils/formatters/channels-list-formatters.d.ts.map +1 -1
- package/dist/utils/formatters/channels-list-formatters.js +15 -22
- package/dist/utils/formatters/channels-list-formatters.js.map +1 -1
- package/dist/utils/formatters/message-formatters.d.ts +9 -0
- package/dist/utils/formatters/message-formatters.d.ts.map +1 -0
- package/dist/utils/formatters/message-formatters.js +72 -0
- package/dist/utils/formatters/message-formatters.js.map +1 -0
- package/dist/utils/option-parsers.d.ts +47 -0
- package/dist/utils/option-parsers.d.ts.map +1 -0
- package/dist/utils/option-parsers.js +75 -0
- package/dist/utils/option-parsers.js.map +1 -0
- package/dist/utils/profile-config-refactored.d.ts +20 -0
- package/dist/utils/profile-config-refactored.d.ts.map +1 -0
- package/dist/utils/profile-config-refactored.js +174 -0
- package/dist/utils/profile-config-refactored.js.map +1 -0
- package/package.json +1 -1
- package/src/commands/channels.ts +7 -4
- package/src/commands/unread.ts +18 -21
- package/src/utils/config/config-file-manager.ts +56 -0
- package/src/utils/config/profile-manager.ts +79 -0
- package/src/utils/config/token-crypto-service.ts +80 -0
- package/src/utils/formatters/base-formatter.ts +34 -0
- package/src/utils/formatters/channel-formatters.ts +25 -23
- package/src/utils/formatters/channels-list-formatters.ts +27 -31
- package/src/utils/formatters/message-formatters.ts +85 -0
- package/src/utils/option-parsers.ts +100 -0
- package/src/utils/profile-config-refactored.ts +161 -0
- package/tests/commands/unread.test.ts +112 -0
- package/tests/utils/config/config-file-manager.test.ts +118 -0
- package/tests/utils/config/profile-manager.test.ts +266 -0
- package/tests/utils/config/token-crypto-service.test.ts +98 -0
|
@@ -3,14 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ChannelCountFormatter = exports.ChannelJsonFormatter = exports.ChannelSimpleFormatter = exports.ChannelTableFormatter = void 0;
|
|
7
6
|
exports.createChannelFormatter = createChannelFormatter;
|
|
8
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
const
|
|
8
|
+
const base_formatter_1 = require("./base-formatter");
|
|
10
9
|
const channel_formatter_1 = require("../channel-formatter");
|
|
11
10
|
const date_utils_1 = require("../date-utils");
|
|
12
|
-
class ChannelTableFormatter extends
|
|
13
|
-
format(channels) {
|
|
11
|
+
class ChannelTableFormatter extends base_formatter_1.AbstractFormatter {
|
|
12
|
+
format({ channels }) {
|
|
14
13
|
console.log(chalk_1.default.bold('Channel Unread Last Message'));
|
|
15
14
|
console.log('─'.repeat(50));
|
|
16
15
|
channels.forEach((channel) => {
|
|
@@ -22,29 +21,25 @@ class ChannelTableFormatter extends output_formatter_1.BaseFormatter {
|
|
|
22
21
|
});
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
format(channels) {
|
|
24
|
+
class ChannelSimpleFormatter extends base_formatter_1.AbstractFormatter {
|
|
25
|
+
format({ channels }) {
|
|
28
26
|
channels.forEach((channel) => {
|
|
29
27
|
const channelName = (0, channel_formatter_1.formatChannelName)(channel.name);
|
|
30
28
|
console.log(`${channelName} (${channel.unread_count || 0})`);
|
|
31
29
|
});
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const output = channels.map((channel) => ({
|
|
32
|
+
class ChannelJsonFormatter extends base_formatter_1.JsonFormatter {
|
|
33
|
+
transform({ channels }) {
|
|
34
|
+
return channels.map((channel) => ({
|
|
38
35
|
channel: (0, channel_formatter_1.formatChannelName)(channel.name),
|
|
39
36
|
channelId: channel.id,
|
|
40
37
|
unreadCount: channel.unread_count || 0,
|
|
41
38
|
}));
|
|
42
|
-
console.log(JSON.stringify(output, null, 2));
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
format(channels) {
|
|
41
|
+
class ChannelCountFormatter extends base_formatter_1.AbstractFormatter {
|
|
42
|
+
format({ channels }) {
|
|
48
43
|
let totalUnread = 0;
|
|
49
44
|
channels.forEach((channel) => {
|
|
50
45
|
const count = channel.unread_count || 0;
|
|
@@ -55,19 +50,16 @@ class ChannelCountFormatter extends output_formatter_1.BaseFormatter {
|
|
|
55
50
|
console.log(chalk_1.default.bold(`Total: ${totalUnread} unread messages`));
|
|
56
51
|
}
|
|
57
52
|
}
|
|
58
|
-
|
|
53
|
+
const channelFormatterFactory = (0, base_formatter_1.createFormatterFactory)({
|
|
54
|
+
table: new ChannelTableFormatter(),
|
|
55
|
+
simple: new ChannelSimpleFormatter(),
|
|
56
|
+
json: new ChannelJsonFormatter(),
|
|
57
|
+
count: new ChannelCountFormatter(),
|
|
58
|
+
});
|
|
59
59
|
function createChannelFormatter(format, countOnly) {
|
|
60
60
|
if (countOnly) {
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
switch (format) {
|
|
64
|
-
case 'json':
|
|
65
|
-
return new ChannelJsonFormatter();
|
|
66
|
-
case 'simple':
|
|
67
|
-
return new ChannelSimpleFormatter();
|
|
68
|
-
case 'table':
|
|
69
|
-
default:
|
|
70
|
-
return new ChannelTableFormatter();
|
|
61
|
+
return channelFormatterFactory.create('count');
|
|
71
62
|
}
|
|
63
|
+
return channelFormatterFactory.create(format);
|
|
72
64
|
}
|
|
73
65
|
//# sourceMappingURL=channel-formatters.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel-formatters.js","sourceRoot":"","sources":["../../../src/utils/formatters/channel-formatters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"channel-formatters.js","sourceRoot":"","sources":["../../../src/utils/formatters/channel-formatters.ts"],"names":[],"mappings":";;;;;AAiEA,wDAKC;AAtED,kDAA0B;AAC1B,qDAA4F;AAE5F,4DAAyD;AACzD,8CAAqD;AAOrD,MAAM,qBAAsB,SAAQ,kCAA0C;IAC5E,MAAM,CAAC,EAAE,QAAQ,EAA2B;QAC1C,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC,CAAC;QACjE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QAE5B,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC3B,MAAM,WAAW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AM,CAAC,EAAE,QAAQ,EAA2B;QAC1C,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY,IAAI,CAAC,CAAC;YACxC,WAAW,IAAI,KAAK,CAAC;YACrB,MAAM,WAAW,GAAG,IAAA,qCAAiB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACpD,OAAO,CAAC,GAAG,CAAC,GAAG,WAAW,KAAK,KAAK,EAAE,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,UAAU,WAAW,kBAAkB,CAAC,CAAC,CAAC;IACnE,CAAC;CACF;AAED,MAAM,uBAAuB,GAAG,IAAA,uCAAsB,EAA0B;IAC9E,KAAK,EAAE,IAAI,qBAAqB,EAAE;IAClC,MAAM,EAAE,IAAI,sBAAsB,EAAE;IACpC,IAAI,EAAE,IAAI,oBAAoB,EAAE;IAChC,KAAK,EAAE,IAAI,qBAAqB,EAAE;CACnC,CAAC,CAAC;AAEH,SAAgB,sBAAsB,CAAC,MAAc,EAAE,SAAkB;IACvE,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,uBAAuB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,uBAAuB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import { BaseFormatter } from './output-formatter';
|
|
2
1
|
import { ChannelInfo } from '../channel-formatter';
|
|
3
|
-
export
|
|
4
|
-
|
|
2
|
+
export interface ChannelsListFormatterOptions {
|
|
3
|
+
channels: ChannelInfo[];
|
|
5
4
|
}
|
|
6
|
-
export declare
|
|
7
|
-
format(channels: ChannelInfo[]): void;
|
|
8
|
-
}
|
|
9
|
-
export declare class ChannelsJsonFormatter extends BaseFormatter<ChannelInfo> {
|
|
10
|
-
format(channels: ChannelInfo[]): void;
|
|
11
|
-
}
|
|
12
|
-
export declare function createChannelsListFormatter(format: string): BaseFormatter<ChannelInfo>;
|
|
5
|
+
export declare function createChannelsListFormatter(format: string): import("./base-formatter").BaseFormatter<ChannelsListFormatterOptions>;
|
|
13
6
|
//# sourceMappingURL=channels-list-formatters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channels-list-formatters.d.ts","sourceRoot":"","sources":["../../../src/utils/formatters/channels-list-formatters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"channels-list-formatters.d.ts","sourceRoot":"","sources":["../../../src/utils/formatters/channels-list-formatters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AA+CD,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,0EAEzD"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChannelsJsonFormatter = exports.ChannelsSimpleFormatter = exports.ChannelsTableFormatter = void 0;
|
|
4
3
|
exports.createChannelsListFormatter = createChannelsListFormatter;
|
|
5
|
-
const
|
|
6
|
-
class ChannelsTableFormatter extends
|
|
7
|
-
format(channels) {
|
|
4
|
+
const base_formatter_1 = require("./base-formatter");
|
|
5
|
+
class ChannelsTableFormatter extends base_formatter_1.AbstractFormatter {
|
|
6
|
+
format({ channels }) {
|
|
8
7
|
// Print table header
|
|
9
8
|
console.log('Name Type Members Created Description');
|
|
10
9
|
console.log('─'.repeat(65));
|
|
@@ -19,35 +18,29 @@ class ChannelsTableFormatter extends output_formatter_1.BaseFormatter {
|
|
|
19
18
|
});
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
format(channels) {
|
|
21
|
+
class ChannelsSimpleFormatter extends base_formatter_1.AbstractFormatter {
|
|
22
|
+
format({ channels }) {
|
|
25
23
|
channels.forEach((channel) => console.log(channel.name));
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
console.log(JSON.stringify(channels.map((channel) => ({
|
|
26
|
+
class ChannelsJsonFormatter extends base_formatter_1.JsonFormatter {
|
|
27
|
+
transform({ channels }) {
|
|
28
|
+
return channels.map((channel) => ({
|
|
32
29
|
id: channel.id,
|
|
33
30
|
name: channel.name,
|
|
34
31
|
type: channel.type,
|
|
35
32
|
members: channel.members,
|
|
36
33
|
created: channel.created + 'T00:00:00Z',
|
|
37
34
|
purpose: channel.purpose,
|
|
38
|
-
}))
|
|
35
|
+
}));
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
|
-
|
|
38
|
+
const channelsListFormatterFactory = (0, base_formatter_1.createFormatterFactory)({
|
|
39
|
+
table: new ChannelsTableFormatter(),
|
|
40
|
+
simple: new ChannelsSimpleFormatter(),
|
|
41
|
+
json: new ChannelsJsonFormatter(),
|
|
42
|
+
});
|
|
42
43
|
function createChannelsListFormatter(format) {
|
|
43
|
-
|
|
44
|
-
case 'json':
|
|
45
|
-
return new ChannelsJsonFormatter();
|
|
46
|
-
case 'simple':
|
|
47
|
-
return new ChannelsSimpleFormatter();
|
|
48
|
-
case 'table':
|
|
49
|
-
default:
|
|
50
|
-
return new ChannelsTableFormatter();
|
|
51
|
-
}
|
|
44
|
+
return channelsListFormatterFactory.create(format);
|
|
52
45
|
}
|
|
53
46
|
//# sourceMappingURL=channels-list-formatters.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channels-list-formatters.js","sourceRoot":"","sources":["../../../src/utils/formatters/channels-list-formatters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"channels-list-formatters.js","sourceRoot":"","sources":["../../../src/utils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AC;IAC3D,CAAC;CACF;AAED,MAAM,qBAAsB,SAAQ,8BAA2C;IACnE,SAAS,CAAC,EAAE,QAAQ,EAAgC;QAC5D,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAChC,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO,GAAG,YAAY;YACvC,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC,CAAC,CAAC;IACN,CAAC;CACF;AAED,MAAM,4BAA4B,GAAG,IAAA,uCAAsB,EAA+B;IACxF,KAAK,EAAE,IAAI,sBAAsB,EAAE;IACnC,MAAM,EAAE,IAAI,uBAAuB,EAAE;IACrC,IAAI,EAAE,IAAI,qBAAqB,EAAE;CAClC,CAAC,CAAC;AAEH,SAAgB,2BAA2B,CAAC,MAAc;IACxD,OAAO,4BAA4B,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface MessageFormatterOptions {
|
|
2
|
+
channel: any;
|
|
3
|
+
messages: any[];
|
|
4
|
+
users: Map<string, string>;
|
|
5
|
+
countOnly: boolean;
|
|
6
|
+
format: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function createMessageFormatter(format: string): import("./base-formatter").BaseFormatter<MessageFormatterOptions>;
|
|
9
|
+
//# sourceMappingURL=message-formatters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-formatters.d.ts","sourceRoot":"","sources":["../../../src/utils/formatters/message-formatters.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,GAAG,CAAC;IACb,QAAQ,EAAE,GAAG,EAAE,CAAC;IAChB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAsED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,qEAEpD"}
|
|
@@ -0,0 +1,72 @@
|
|
|
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.createMessageFormatter = createMessageFormatter;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const base_formatter_1 = require("./base-formatter");
|
|
9
|
+
const date_utils_1 = require("../date-utils");
|
|
10
|
+
const format_utils_1 = require("../format-utils");
|
|
11
|
+
const channel_formatter_1 = require("../channel-formatter");
|
|
12
|
+
class TableMessageFormatter extends base_formatter_1.AbstractFormatter {
|
|
13
|
+
format(options) {
|
|
14
|
+
const { channel, messages, users, countOnly } = options;
|
|
15
|
+
const channelName = (0, channel_formatter_1.formatChannelName)(channel.name);
|
|
16
|
+
console.log(chalk_1.default.bold(`${channelName}: ${channel.unread_count || 0} unread messages`));
|
|
17
|
+
if (!countOnly && messages.length > 0) {
|
|
18
|
+
console.log('');
|
|
19
|
+
messages.forEach((message) => {
|
|
20
|
+
const timestamp = (0, date_utils_1.formatSlackTimestamp)(message.ts);
|
|
21
|
+
const author = message.user ? users.get(message.user) || message.user : 'unknown';
|
|
22
|
+
console.log(`${chalk_1.default.gray(timestamp)} ${chalk_1.default.cyan(author)}`);
|
|
23
|
+
const text = message.text ? (0, format_utils_1.formatMessageWithMentions)(message.text, users) : '(no text)';
|
|
24
|
+
console.log(text);
|
|
25
|
+
console.log('');
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
class SimpleMessageFormatter extends base_formatter_1.AbstractFormatter {
|
|
31
|
+
format(options) {
|
|
32
|
+
const { channel, messages, users, countOnly } = options;
|
|
33
|
+
const channelName = (0, channel_formatter_1.formatChannelName)(channel.name);
|
|
34
|
+
console.log(`${channelName} (${channel.unread_count || 0})`);
|
|
35
|
+
if (!countOnly && messages.length > 0) {
|
|
36
|
+
messages.forEach((message) => {
|
|
37
|
+
const timestamp = (0, date_utils_1.formatSlackTimestamp)(message.ts);
|
|
38
|
+
const author = message.user ? users.get(message.user) || message.user : 'unknown';
|
|
39
|
+
const text = message.text ? (0, format_utils_1.formatMessageWithMentions)(message.text, users) : '(no text)';
|
|
40
|
+
console.log(`[${timestamp}] ${author}: ${text}`);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
class JsonMessageFormatter extends base_formatter_1.JsonFormatter {
|
|
46
|
+
transform(options) {
|
|
47
|
+
const { channel, messages, users, countOnly } = options;
|
|
48
|
+
const channelName = (0, channel_formatter_1.formatChannelName)(channel.name);
|
|
49
|
+
const output = {
|
|
50
|
+
channel: channelName,
|
|
51
|
+
channelId: channel.id,
|
|
52
|
+
unreadCount: channel.unread_count || 0,
|
|
53
|
+
};
|
|
54
|
+
if (!countOnly && messages.length > 0) {
|
|
55
|
+
output.messages = messages.map((message) => ({
|
|
56
|
+
timestamp: (0, date_utils_1.formatSlackTimestamp)(message.ts),
|
|
57
|
+
author: message.user ? users.get(message.user) || message.user : 'unknown',
|
|
58
|
+
text: message.text || '(no text)',
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
return output;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const messageFormatterFactory = (0, base_formatter_1.createFormatterFactory)({
|
|
65
|
+
table: new TableMessageFormatter(),
|
|
66
|
+
simple: new SimpleMessageFormatter(),
|
|
67
|
+
json: new JsonMessageFormatter(),
|
|
68
|
+
});
|
|
69
|
+
function createMessageFormatter(format) {
|
|
70
|
+
return messageFormatterFactory.create(format);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=message-formatters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-formatters.js","sourceRoot":"","sources":["../../../src/utils/formatters/message-formatters.ts"],"names":[],"mappings":";;;;;AAkFA,wDAEC;AApFD,kDAA0B;AAC1B,qDAA4F;AAC5F,8CAAqD;AACrD,kDAA4D;AAC5D,4DAAyD;AAUzD,MAAM,qBAAsB,SAAQ,kCAA0C;IAC5E,MAAM,CAAC,OAAgC;QACrC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QACxD,MAAM,WAAW,GAAG,IAAA,qCAAiB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEpD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,GAAG,WAAW,KAAK,OAAO,CAAC,YAAY,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC;QAExF,IAAI,CAAC,SAAS,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAChB,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC3B,MAAM,SAAS,GAAG,IAAA,iCAAoB,EAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACnD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;gBAClF,OAAO,CAAC,GAAG,CAAC,GAAG,eAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,eAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBAC9D,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,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|
|
4
|
+
/**
|
|
5
|
+
* Parse format option with default value
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseFormat(format?: string, defaultFormat?: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Parse limit option with default value
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseLimit(limit: string | undefined, defaultLimit: number): number;
|
|
12
|
+
/**
|
|
13
|
+
* Parse boolean option with default value
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseBoolean(value?: boolean, defaultValue?: boolean): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Parse count option with default value
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseCount(count: string | undefined, defaultCount: number, min?: number, max?: number): number;
|
|
20
|
+
/**
|
|
21
|
+
* Parse profile option
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseProfile(profile?: string): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Common option defaults
|
|
26
|
+
*/
|
|
27
|
+
export declare const OPTION_DEFAULTS: {
|
|
28
|
+
readonly format: "table";
|
|
29
|
+
readonly limit: 100;
|
|
30
|
+
readonly countOnly: false;
|
|
31
|
+
readonly includeArchived: false;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Parse common list options
|
|
35
|
+
*/
|
|
36
|
+
export interface ListOptions {
|
|
37
|
+
format?: string;
|
|
38
|
+
limit?: string;
|
|
39
|
+
countOnly?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface ParsedListOptions {
|
|
42
|
+
format: string;
|
|
43
|
+
limit: number;
|
|
44
|
+
countOnly: boolean;
|
|
45
|
+
}
|
|
46
|
+
export declare function parseListOptions(options: ListOptions, defaults?: Partial<ParsedListOptions>): ParsedListOptions;
|
|
47
|
+
//# sourceMappingURL=option-parsers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"option-parsers.d.ts","sourceRoot":"","sources":["../../src/utils/option-parsers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,aAAa,SAAU,GAAG,MAAM,CAE5E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAElF;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,YAAY,UAAQ,GAAG,OAAO,CAE3E;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,YAAY,EAAE,MAAM,EACpB,GAAG,CAAC,EAAE,MAAM,EACZ,GAAG,CAAC,EAAE,MAAM,GACX,MAAM,CAgBR;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEjE;AAED;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;CAKlB,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,WAAW,EACpB,QAAQ,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACpC,iBAAiB,CAanB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Common option parsing utilities to reduce duplication
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OPTION_DEFAULTS = void 0;
|
|
7
|
+
exports.parseFormat = parseFormat;
|
|
8
|
+
exports.parseLimit = parseLimit;
|
|
9
|
+
exports.parseBoolean = parseBoolean;
|
|
10
|
+
exports.parseCount = parseCount;
|
|
11
|
+
exports.parseProfile = parseProfile;
|
|
12
|
+
exports.parseListOptions = parseListOptions;
|
|
13
|
+
/**
|
|
14
|
+
* Parse format option with default value
|
|
15
|
+
*/
|
|
16
|
+
function parseFormat(format, defaultFormat = 'table') {
|
|
17
|
+
return format || defaultFormat;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse limit option with default value
|
|
21
|
+
*/
|
|
22
|
+
function parseLimit(limit, defaultLimit) {
|
|
23
|
+
return parseInt(limit || defaultLimit.toString(), 10);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parse boolean option with default value
|
|
27
|
+
*/
|
|
28
|
+
function parseBoolean(value, defaultValue = false) {
|
|
29
|
+
return value !== undefined ? value : defaultValue;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parse count option with default value
|
|
33
|
+
*/
|
|
34
|
+
function parseCount(count, defaultCount, min, max) {
|
|
35
|
+
const parsed = parseInt(count || defaultCount.toString(), 10);
|
|
36
|
+
if (isNaN(parsed)) {
|
|
37
|
+
return defaultCount;
|
|
38
|
+
}
|
|
39
|
+
if (min !== undefined && parsed < min) {
|
|
40
|
+
return min;
|
|
41
|
+
}
|
|
42
|
+
if (max !== undefined && parsed > max) {
|
|
43
|
+
return max;
|
|
44
|
+
}
|
|
45
|
+
return parsed;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parse profile option
|
|
49
|
+
*/
|
|
50
|
+
function parseProfile(profile) {
|
|
51
|
+
return profile;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Common option defaults
|
|
55
|
+
*/
|
|
56
|
+
exports.OPTION_DEFAULTS = {
|
|
57
|
+
format: 'table',
|
|
58
|
+
limit: 100,
|
|
59
|
+
countOnly: false,
|
|
60
|
+
includeArchived: false,
|
|
61
|
+
};
|
|
62
|
+
function parseListOptions(options, defaults) {
|
|
63
|
+
const mergedDefaults = {
|
|
64
|
+
format: exports.OPTION_DEFAULTS.format,
|
|
65
|
+
limit: exports.OPTION_DEFAULTS.limit,
|
|
66
|
+
countOnly: exports.OPTION_DEFAULTS.countOnly,
|
|
67
|
+
...defaults,
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
format: parseFormat(options.format, mergedDefaults.format),
|
|
71
|
+
limit: parseLimit(options.limit, mergedDefaults.limit),
|
|
72
|
+
countOnly: parseBoolean(options.countOnly, mergedDefaults.countOnly),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=option-parsers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"option-parsers.js","sourceRoot":"","sources":["../../src/utils/option-parsers.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAKH,kCAEC;AAKD,gCAEC;AAKD,oCAEC;AAKD,gCAqBC;AAKD,oCAEC;AA2BD,4CAgBC;AA/FD;;GAEG;AACH,SAAgB,WAAW,CAAC,MAAe,EAAE,aAAa,GAAG,OAAO;IAClE,OAAO,MAAM,IAAI,aAAa,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,KAAyB,EAAE,YAAoB;IACxE,OAAO,QAAQ,CAAC,KAAK,IAAI,YAAY,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,KAAe,EAAE,YAAY,GAAG,KAAK;IAChE,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,SAAgB,UAAU,CACxB,KAAyB,EACzB,YAAoB,EACpB,GAAY,EACZ,GAAY;IAEZ,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,IAAI,YAAY,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;IAE9D,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QAClB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,IAAI,GAAG,KAAK,SAAS,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;QACtC,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,GAAG,KAAK,SAAS,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;QACtC,OAAO,GAAG,CAAC;IACb,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,OAAgB;IAC3C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACU,QAAA,eAAe,GAAG;IAC7B,MAAM,EAAE,OAAO;IACf,KAAK,EAAE,GAAG;IACV,SAAS,EAAE,KAAK;IAChB,eAAe,EAAE,KAAK;CACd,CAAC;AAiBX,SAAgB,gBAAgB,CAC9B,OAAoB,EACpB,QAAqC;IAErC,MAAM,cAAc,GAAG;QACrB,MAAM,EAAE,uBAAe,CAAC,MAAM;QAC9B,KAAK,EAAE,uBAAe,CAAC,KAAK;QAC5B,SAAS,EAAE,uBAAe,CAAC,SAAS;QACpC,GAAG,QAAQ;KACZ,CAAC;IAEF,OAAO;QACL,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC;QAC1D,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC;QACtD,SAAS,EAAE,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,SAAS,CAAC;KACrE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Config, ConfigOptions, Profile } from '../types/config';
|
|
2
|
+
export declare class ProfileConfigManager {
|
|
3
|
+
private fileManager;
|
|
4
|
+
private cryptoService;
|
|
5
|
+
private profileManager;
|
|
6
|
+
constructor(_options?: ConfigOptions);
|
|
7
|
+
setToken(token: string, profile?: string): Promise<void>;
|
|
8
|
+
getConfig(profile?: string): Promise<Config | null>;
|
|
9
|
+
listProfiles(): Promise<Profile[]>;
|
|
10
|
+
useProfile(profile: string): Promise<void>;
|
|
11
|
+
getCurrentProfile(): Promise<string>;
|
|
12
|
+
clearConfig(profile?: string): Promise<void>;
|
|
13
|
+
maskToken(token: string): string;
|
|
14
|
+
migrateIfNeeded(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export declare const profileConfig: {
|
|
17
|
+
getCurrentProfile: () => string;
|
|
18
|
+
getToken: (_profile?: string) => string | undefined;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=profile-config-refactored.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile-config-refactored.d.ts","sourceRoot":"","sources":["../../src/utils/profile-config-refactored.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAOtE,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,cAAc,CAAiB;gBAE3B,QAAQ,GAAE,aAAkB;IAQlC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBxD,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAcnD,YAAY,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAiBlC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS1C,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIpC,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgClD,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAY1B,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;CAwBvC;AAGD,eAAO,MAAM,aAAa;6BACD,MAAM;0BAGP,MAAM,KAAG,MAAM,GAAG,SAAS;CAKlD,CAAC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
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.profileConfig = exports.ProfileConfigManager = void 0;
|
|
37
|
+
const constants_1 = require("./constants");
|
|
38
|
+
const config_file_manager_1 = require("./config/config-file-manager");
|
|
39
|
+
const token_crypto_service_1 = require("./config/token-crypto-service");
|
|
40
|
+
const profile_manager_1 = require("./config/profile-manager");
|
|
41
|
+
const fs = __importStar(require("fs/promises"));
|
|
42
|
+
class ProfileConfigManager {
|
|
43
|
+
constructor(_options = {}) {
|
|
44
|
+
// Note: ConfigFileManager currently doesn't support custom configDir
|
|
45
|
+
// This would need to be added if required
|
|
46
|
+
this.fileManager = new config_file_manager_1.ConfigFileManager();
|
|
47
|
+
this.cryptoService = new token_crypto_service_1.TokenCryptoService();
|
|
48
|
+
this.profileManager = new profile_manager_1.ProfileManager(this.fileManager, this.cryptoService);
|
|
49
|
+
}
|
|
50
|
+
async setToken(token, profile) {
|
|
51
|
+
const profileName = profile || (await this.profileManager.getCurrentProfile());
|
|
52
|
+
const config = {
|
|
53
|
+
token,
|
|
54
|
+
updatedAt: new Date().toISOString(),
|
|
55
|
+
};
|
|
56
|
+
await this.profileManager.setProfile(profileName, config);
|
|
57
|
+
// Set as default profile if it's the first one or explicitly setting default
|
|
58
|
+
const profiles = await this.profileManager.listProfiles();
|
|
59
|
+
if (profiles.length === 1 || profileName === constants_1.DEFAULT_PROFILE_NAME) {
|
|
60
|
+
await this.profileManager.setCurrentProfile(profileName);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async getConfig(profile) {
|
|
64
|
+
const profileName = profile || (await this.profileManager.getCurrentProfile());
|
|
65
|
+
try {
|
|
66
|
+
return await this.profileManager.getProfile(profileName);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
// Return null if profile not found
|
|
70
|
+
if (error instanceof Error && error.message.includes('not found')) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async listProfiles() {
|
|
77
|
+
const profileNames = await this.profileManager.listProfiles();
|
|
78
|
+
const currentProfile = await this.profileManager.getCurrentProfile();
|
|
79
|
+
const profiles = [];
|
|
80
|
+
for (const name of profileNames) {
|
|
81
|
+
const config = await this.profileManager.getProfile(name);
|
|
82
|
+
profiles.push({
|
|
83
|
+
name,
|
|
84
|
+
config,
|
|
85
|
+
isDefault: name === currentProfile,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return profiles;
|
|
89
|
+
}
|
|
90
|
+
async useProfile(profile) {
|
|
91
|
+
const exists = await this.profileManager.profileExists(profile);
|
|
92
|
+
if (!exists) {
|
|
93
|
+
throw new Error(`Profile "${profile}" does not exist`);
|
|
94
|
+
}
|
|
95
|
+
await this.profileManager.setCurrentProfile(profile);
|
|
96
|
+
}
|
|
97
|
+
async getCurrentProfile() {
|
|
98
|
+
return await this.profileManager.getCurrentProfile();
|
|
99
|
+
}
|
|
100
|
+
async clearConfig(profile) {
|
|
101
|
+
const profileName = profile || (await this.profileManager.getCurrentProfile());
|
|
102
|
+
try {
|
|
103
|
+
await this.profileManager.deleteProfile(profileName);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
// If profile doesn't exist, do nothing
|
|
107
|
+
if (error instanceof Error && error.message.includes('not found')) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
// If we deleted the current profile, set a new default
|
|
113
|
+
const currentProfile = await this.profileManager.getCurrentProfile();
|
|
114
|
+
if (currentProfile === profileName) {
|
|
115
|
+
const remainingProfiles = await this.profileManager.listProfiles();
|
|
116
|
+
if (remainingProfiles.length > 0) {
|
|
117
|
+
await this.profileManager.setCurrentProfile(remainingProfiles[0]);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// No profiles left, delete the config file
|
|
121
|
+
try {
|
|
122
|
+
await fs.unlink(this.fileManager.getConfigPath());
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
if (error && typeof error === 'object' && 'code' in error && error.code !== 'ENOENT') {
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
maskToken(token) {
|
|
133
|
+
if (token.length <= constants_1.TOKEN_MIN_LENGTH) {
|
|
134
|
+
return '****';
|
|
135
|
+
}
|
|
136
|
+
const prefix = token.substring(0, constants_1.TOKEN_MASK_LENGTH);
|
|
137
|
+
const suffix = token.substring(token.length - constants_1.TOKEN_MASK_LENGTH);
|
|
138
|
+
return `${prefix}-****-****-${suffix}`;
|
|
139
|
+
}
|
|
140
|
+
// Migration support - to be called separately if needed
|
|
141
|
+
async migrateIfNeeded() {
|
|
142
|
+
const data = await this.fileManager.read();
|
|
143
|
+
// Check if migration is needed (old format detection)
|
|
144
|
+
const anyData = data;
|
|
145
|
+
if (anyData.token && !anyData.profiles) {
|
|
146
|
+
// Old format detected, migrate
|
|
147
|
+
const oldConfig = {
|
|
148
|
+
token: anyData.token,
|
|
149
|
+
updatedAt: anyData.updatedAt || new Date().toISOString(),
|
|
150
|
+
};
|
|
151
|
+
// Create new format
|
|
152
|
+
const newData = {
|
|
153
|
+
profiles: { [constants_1.DEFAULT_PROFILE_NAME]: oldConfig },
|
|
154
|
+
currentProfile: constants_1.DEFAULT_PROFILE_NAME,
|
|
155
|
+
};
|
|
156
|
+
await this.fileManager.write(newData);
|
|
157
|
+
// Re-encrypt token using new service
|
|
158
|
+
await this.setToken(oldConfig.token, constants_1.DEFAULT_PROFILE_NAME);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.ProfileConfigManager = ProfileConfigManager;
|
|
163
|
+
// Export a simplified version for backward compatibility
|
|
164
|
+
exports.profileConfig = {
|
|
165
|
+
getCurrentProfile: () => {
|
|
166
|
+
return constants_1.DEFAULT_PROFILE_NAME;
|
|
167
|
+
},
|
|
168
|
+
getToken: (_profile) => {
|
|
169
|
+
// This is a simplified version for testing
|
|
170
|
+
// In real usage, it would need to be async
|
|
171
|
+
return undefined;
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
//# sourceMappingURL=profile-config-refactored.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile-config-refactored.js","sourceRoot":"","sources":["../../src/utils/profile-config-refactored.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAAwF;AACxF,sEAAiE;AACjE,wEAAmE;AACnE,8DAA0D;AAC1D,gDAAkC;AAElC,MAAa,oBAAoB;IAK/B,YAAY,WAA0B,EAAE;QACtC,qEAAqE;QACrE,0CAA0C;QAC1C,IAAI,CAAC,WAAW,GAAG,IAAI,uCAAiB,EAAE,CAAC;QAC3C,IAAI,CAAC,aAAa,GAAG,IAAI,yCAAkB,EAAE,CAAC;QAC9C,IAAI,CAAC,cAAc,GAAG,IAAI,gCAAc,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACjF,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAa,EAAE,OAAgB;QAC5C,MAAM,WAAW,GAAG,OAAO,IAAI,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,iBAAiB,EAAE,CAAC,CAAC;QAC/E,MAAM,MAAM,GAAW;YACrB,KAAK;YACL,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC;QAEF,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QAE1D,6EAA6E;QAC7E,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC;QAC1D,IAAI,QAAQ,CAAC,MAAM,KAAK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