@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channels.d.ts","sourceRoot":"","sources":["../../src/commands/channels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"channels.d.ts","sourceRoot":"","sources":["../../src/commands/channels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,wBAAgB,oBAAoB,IAAI,OAAO,CAwC9C"}
|
|
@@ -7,6 +7,7 @@ const client_factory_1 = require("../utils/client-factory");
|
|
|
7
7
|
const constants_1 = require("../utils/constants");
|
|
8
8
|
const channel_formatter_1 = require("../utils/channel-formatter");
|
|
9
9
|
const channels_list_formatters_1 = require("../utils/formatters/channels-list-formatters");
|
|
10
|
+
const option_parsers_1 = require("../utils/option-parsers");
|
|
10
11
|
function setupChannelsCommand() {
|
|
11
12
|
const channelsCommand = new commander_1.Command('channels');
|
|
12
13
|
channelsCommand
|
|
@@ -22,10 +23,11 @@ function setupChannelsCommand() {
|
|
|
22
23
|
// Map channel type to API types
|
|
23
24
|
const types = (0, channel_formatter_1.getChannelTypes)(options.type);
|
|
24
25
|
// List channels
|
|
26
|
+
const limit = (0, option_parsers_1.parseLimit)(options.limit, 100);
|
|
25
27
|
const channels = await client.listChannels({
|
|
26
28
|
types,
|
|
27
|
-
exclude_archived: !options.includeArchived,
|
|
28
|
-
limit:
|
|
29
|
+
exclude_archived: !(0, option_parsers_1.parseBoolean)(options.includeArchived),
|
|
30
|
+
limit: limit,
|
|
29
31
|
});
|
|
30
32
|
if (channels.length === 0) {
|
|
31
33
|
console.log(constants_1.ERROR_MESSAGES.NO_CHANNELS_FOUND);
|
|
@@ -33,8 +35,9 @@ function setupChannelsCommand() {
|
|
|
33
35
|
}
|
|
34
36
|
// Format and display channels
|
|
35
37
|
const channelInfos = channels.map(channel_formatter_1.mapChannelToInfo);
|
|
36
|
-
const
|
|
37
|
-
formatter.format
|
|
38
|
+
const format = (0, option_parsers_1.parseFormat)(options.format);
|
|
39
|
+
const formatter = (0, channels_list_formatters_1.createChannelsListFormatter)(format);
|
|
40
|
+
formatter.format({ channels: channelInfos });
|
|
38
41
|
}));
|
|
39
42
|
return channelsCommand;
|
|
40
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channels.js","sourceRoot":"","sources":["../../src/commands/channels.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"channels.js","sourceRoot":"","sources":["../../src/commands/channels.ts"],"names":[],"mappings":";;AASA,oDAwCC;AAjDD,yCAAoC;AACpC,8DAAuD;AACvD,4DAA4D;AAC5D,kDAAoD;AAEpD,kEAA+E;AAC/E,2FAA2F;AAC3F,4DAAgF;AAEhF,SAAgB,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QAC3C,MAAM,SAAS,GAAG,IAAA,sDAA2B,EAAC,MAAM,CAAC,CAAC;QACtD,SAAS,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC;IAC/C,CAAC,CAAC,CACH,CAAC;IAEJ,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unread.d.ts","sourceRoot":"","sources":["../../src/commands/unread.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"unread.d.ts","sourceRoot":"","sources":["../../src/commands/unread.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoDpC,wBAAgB,kBAAkB,IAAI,OAAO,CAyB5C"}
|
package/dist/commands/unread.js
CHANGED
|
@@ -8,28 +8,22 @@ const commander_1 = require("commander");
|
|
|
8
8
|
const command_wrapper_1 = require("../utils/command-wrapper");
|
|
9
9
|
const client_factory_1 = require("../utils/client-factory");
|
|
10
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
-
const date_utils_1 = require("../utils/date-utils");
|
|
12
|
-
const channel_formatter_1 = require("../utils/channel-formatter");
|
|
13
11
|
const channel_formatters_1 = require("../utils/formatters/channel-formatters");
|
|
12
|
+
const message_formatters_1 = require("../utils/formatters/message-formatters");
|
|
14
13
|
const constants_1 = require("../utils/constants");
|
|
15
|
-
const
|
|
14
|
+
const option_parsers_1 = require("../utils/option-parsers");
|
|
16
15
|
async function handleSpecificChannelUnread(client, options) {
|
|
17
16
|
const result = await client.getChannelUnread(options.channel);
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
result.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
: '(no text)';
|
|
29
|
-
console.log(text);
|
|
30
|
-
console.log('');
|
|
31
|
-
});
|
|
32
|
-
}
|
|
17
|
+
const format = (0, option_parsers_1.parseFormat)(options.format);
|
|
18
|
+
const countOnly = (0, option_parsers_1.parseBoolean)(options.countOnly);
|
|
19
|
+
const formatter = (0, message_formatters_1.createMessageFormatter)(format);
|
|
20
|
+
formatter.format({
|
|
21
|
+
channel: result.channel,
|
|
22
|
+
messages: result.messages,
|
|
23
|
+
users: result.users,
|
|
24
|
+
countOnly: countOnly,
|
|
25
|
+
format: format,
|
|
26
|
+
});
|
|
33
27
|
}
|
|
34
28
|
async function handleAllChannelsUnread(client, options) {
|
|
35
29
|
const channels = await client.listUnreadChannels();
|
|
@@ -38,10 +32,12 @@ async function handleAllChannelsUnread(client, options) {
|
|
|
38
32
|
return;
|
|
39
33
|
}
|
|
40
34
|
// Apply limit
|
|
41
|
-
const limit =
|
|
35
|
+
const limit = (0, option_parsers_1.parseLimit)(options.limit, constants_1.DEFAULTS.UNREAD_DISPLAY_LIMIT);
|
|
42
36
|
const displayChannels = channels.slice(0, limit);
|
|
43
|
-
const
|
|
44
|
-
|
|
37
|
+
const format = (0, option_parsers_1.parseFormat)(options.format);
|
|
38
|
+
const countOnly = (0, option_parsers_1.parseBoolean)(options.countOnly);
|
|
39
|
+
const formatter = (0, channel_formatters_1.createChannelFormatter)(format, countOnly);
|
|
40
|
+
formatter.format({ channels: displayChannels, countOnly: countOnly });
|
|
45
41
|
}
|
|
46
42
|
function setupUnreadCommand() {
|
|
47
43
|
const unreadCommand = new commander_1.Command('unread')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unread.js","sourceRoot":"","sources":["../../src/commands/unread.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"unread.js","sourceRoot":"","sources":["../../src/commands/unread.ts"],"names":[],"mappings":";;;;;AAoDA,gDAyBC;AA7ED,yCAAoC;AACpC,8DAAuD;AACvD,4DAA4D;AAG5D,kDAA0B;AAC1B,+EAAgF;AAChF,+EAAgF;AACh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,GAAG,IAAA,2CAAsB,EAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC5D,SAAS,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;AACxE,CAAC;AAED,SAAgB,kBAAkB;IAChC,MAAM,aAAa,GAAG,IAAI,mBAAO,CAAC,QAAQ,CAAC;SACxC,WAAW,CAAC,sCAAsC,CAAC;SACnD,MAAM,CAAC,yBAAyB,EAAE,oCAAoC,CAAC;SACvE,MAAM,CAAC,mBAAmB,EAAE,oCAAoC,EAAE,OAAO,CAAC;SAC1E,MAAM,CAAC,cAAc,EAAE,yBAAyB,EAAE,KAAK,CAAC;SACxD,MAAM,CACL,kBAAkB,EAClB,uCAAuC,EACvC,oBAAQ,CAAC,oBAAoB,CAAC,QAAQ,EAAE,CACzC;SACA,MAAM,CAAC,qBAAqB,EAAE,gCAAgC,CAAC;SAC/D,MAAM,CACL,IAAA,6BAAW,EAAC,KAAK,EAAE,OAAsB,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,MAAM,IAAA,kCAAiB,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAExD,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,2BAA2B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,MAAM,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEJ,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ConfigData {
|
|
2
|
+
profiles: Record<string, any>;
|
|
3
|
+
currentProfile: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class ConfigFileManager {
|
|
6
|
+
private readonly configPath;
|
|
7
|
+
constructor();
|
|
8
|
+
read(): Promise<ConfigData>;
|
|
9
|
+
write(data: ConfigData): Promise<void>;
|
|
10
|
+
exists(): Promise<boolean>;
|
|
11
|
+
getConfigPath(): string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=config-file-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-file-manager.d.ts","sourceRoot":"","sources":["../../../src/utils/config/config-file-manager.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;;IAM9B,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC;IAqB3B,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAShC,aAAa,IAAI,MAAM;CAGxB"}
|
|
@@ -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.ConfigFileManager = void 0;
|
|
37
|
+
const fs = __importStar(require("fs/promises"));
|
|
38
|
+
const os = __importStar(require("os"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
class ConfigFileManager {
|
|
41
|
+
constructor() {
|
|
42
|
+
this.configPath = path.join(os.homedir(), '.slack-cli', 'config.json');
|
|
43
|
+
}
|
|
44
|
+
async read() {
|
|
45
|
+
try {
|
|
46
|
+
await fs.access(this.configPath);
|
|
47
|
+
const data = await fs.readFile(this.configPath, 'utf-8');
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(data);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
throw new Error('Invalid configuration file');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error.message === 'Invalid configuration file') {
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
// File doesn't exist, return default config
|
|
60
|
+
return {
|
|
61
|
+
profiles: {},
|
|
62
|
+
currentProfile: 'default',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async write(data) {
|
|
67
|
+
const dir = path.dirname(this.configPath);
|
|
68
|
+
await fs.mkdir(dir, { recursive: true });
|
|
69
|
+
await fs.writeFile(this.configPath, JSON.stringify(data, null, 2), 'utf-8');
|
|
70
|
+
}
|
|
71
|
+
async exists() {
|
|
72
|
+
try {
|
|
73
|
+
await fs.access(this.configPath);
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
getConfigPath() {
|
|
81
|
+
return this.configPath;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.ConfigFileManager = ConfigFileManager;
|
|
85
|
+
//# sourceMappingURL=config-file-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-file-manager.js","sourceRoot":"","sources":["../../../src/utils/config/config-file-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAClC,uCAAyB;AACzB,2CAA6B;AAO7B,MAAa,iBAAiB;IAG5B;QACE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;IACzE,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACjC,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACzD,IAAI,CAAC;gBACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,KAAK,CAAC,OAAO,KAAK,4BAA4B,EAAE,CAAC;gBACnD,MAAM,KAAK,CAAC;YACd,CAAC;YACD,4CAA4C;YAC5C,OAAO;gBACL,QAAQ,EAAE,EAAE;gBACZ,cAAc,EAAE,SAAS;aAC1B,CAAC;QACJ,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAgB;QAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1C,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACjC,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF;AA9CD,8CA8CC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Config } from '../../types/config';
|
|
2
|
+
import { ConfigFileManager } from './config-file-manager';
|
|
3
|
+
import { TokenCryptoService } from './token-crypto-service';
|
|
4
|
+
export declare class ProfileManager {
|
|
5
|
+
private fileManager;
|
|
6
|
+
private cryptoService;
|
|
7
|
+
constructor(fileManager: ConfigFileManager, cryptoService: TokenCryptoService);
|
|
8
|
+
getProfile(profileName: string): Promise<Config>;
|
|
9
|
+
setProfile(profileName: string, config: Config): Promise<void>;
|
|
10
|
+
deleteProfile(profileName: string): Promise<void>;
|
|
11
|
+
listProfiles(): Promise<string[]>;
|
|
12
|
+
getCurrentProfile(): Promise<string>;
|
|
13
|
+
setCurrentProfile(profileName: string): Promise<void>;
|
|
14
|
+
profileExists(profileName: string): Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=profile-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile-manager.d.ts","sourceRoot":"","sources":["../../../src/utils/config/profile-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAc,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,qBAAa,cAAc;IAEvB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,aAAa;gBADb,WAAW,EAAE,iBAAiB,EAC9B,aAAa,EAAE,kBAAkB;IAGrC,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmBhD,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAa9D,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWjD,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKjC,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAKpC,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWrD,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAI3D"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProfileManager = void 0;
|
|
4
|
+
class ProfileManager {
|
|
5
|
+
constructor(fileManager, cryptoService) {
|
|
6
|
+
this.fileManager = fileManager;
|
|
7
|
+
this.cryptoService = cryptoService;
|
|
8
|
+
}
|
|
9
|
+
async getProfile(profileName) {
|
|
10
|
+
const data = await this.fileManager.read();
|
|
11
|
+
const profile = data.profiles[profileName];
|
|
12
|
+
if (!profile) {
|
|
13
|
+
throw new Error(`Profile "${profileName}" not found`);
|
|
14
|
+
}
|
|
15
|
+
// Decrypt token if encrypted
|
|
16
|
+
const token = this.cryptoService.isEncrypted(profile.token)
|
|
17
|
+
? this.cryptoService.decrypt(profile.token)
|
|
18
|
+
: profile.token;
|
|
19
|
+
return {
|
|
20
|
+
...profile,
|
|
21
|
+
token,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async setProfile(profileName, config) {
|
|
25
|
+
const data = await this.fileManager.read();
|
|
26
|
+
// Encrypt the token before saving
|
|
27
|
+
const encryptedConfig = {
|
|
28
|
+
...config,
|
|
29
|
+
token: this.cryptoService.encrypt(config.token),
|
|
30
|
+
};
|
|
31
|
+
data.profiles[profileName] = encryptedConfig;
|
|
32
|
+
await this.fileManager.write(data);
|
|
33
|
+
}
|
|
34
|
+
async deleteProfile(profileName) {
|
|
35
|
+
const data = await this.fileManager.read();
|
|
36
|
+
if (!data.profiles[profileName]) {
|
|
37
|
+
throw new Error(`Profile "${profileName}" not found`);
|
|
38
|
+
}
|
|
39
|
+
delete data.profiles[profileName];
|
|
40
|
+
await this.fileManager.write(data);
|
|
41
|
+
}
|
|
42
|
+
async listProfiles() {
|
|
43
|
+
const data = await this.fileManager.read();
|
|
44
|
+
return Object.keys(data.profiles);
|
|
45
|
+
}
|
|
46
|
+
async getCurrentProfile() {
|
|
47
|
+
const data = await this.fileManager.read();
|
|
48
|
+
return data.currentProfile || 'default';
|
|
49
|
+
}
|
|
50
|
+
async setCurrentProfile(profileName) {
|
|
51
|
+
const data = await this.fileManager.read();
|
|
52
|
+
if (!data.profiles[profileName]) {
|
|
53
|
+
throw new Error(`Profile "${profileName}" not found`);
|
|
54
|
+
}
|
|
55
|
+
data.currentProfile = profileName;
|
|
56
|
+
await this.fileManager.write(data);
|
|
57
|
+
}
|
|
58
|
+
async profileExists(profileName) {
|
|
59
|
+
const data = await this.fileManager.read();
|
|
60
|
+
return profileName in data.profiles;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ProfileManager = ProfileManager;
|
|
64
|
+
//# sourceMappingURL=profile-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile-manager.js","sourceRoot":"","sources":["../../../src/utils/config/profile-manager.ts"],"names":[],"mappings":";;;AAIA,MAAa,cAAc;IACzB,YACU,WAA8B,EAC9B,aAAiC;QADjC,gBAAW,GAAX,WAAW,CAAmB;QAC9B,kBAAa,GAAb,aAAa,CAAoB;IACxC,CAAC;IAEJ,KAAK,CAAC,UAAU,CAAC,WAAmB;QAClC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAE3C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,YAAY,WAAW,aAAa,CAAC,CAAC;QACxD,CAAC;QAED,6BAA6B;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC;YACzD,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;YAC3C,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;QAElB,OAAO;YACL,GAAG,OAAO;YACV,KAAK;SACN,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,WAAmB,EAAE,MAAc;QAClD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QAE3C,kCAAkC;QAClC,MAAM,eAAe,GAAG;YACtB,GAAG,MAAM;YACT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AC;QAClC,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,WAAmB;QACrC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QAC3C,OAAO,WAAW,IAAI,IAAI,CAAC,QAAQ,CAAC;IACtC,CAAC;CACF;AA1ED,wCA0EC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class TokenCryptoService {
|
|
2
|
+
private readonly algorithm;
|
|
3
|
+
private readonly keyLength;
|
|
4
|
+
private readonly ivLength;
|
|
5
|
+
private readonly separator;
|
|
6
|
+
private deriveKey;
|
|
7
|
+
encrypt(token: string): string;
|
|
8
|
+
decrypt(encryptedData: string): string;
|
|
9
|
+
isEncrypted(value: string): boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=token-crypto-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-crypto-service.d.ts","sourceRoot":"","sources":["../../../src/utils/config/token-crypto-service.ts"],"names":[],"mappings":"AAEA,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiB;IAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAM;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAM;IAC/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAO;IAEjC,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAgB9B,OAAO,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IA8BtC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAkBpC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
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.TokenCryptoService = void 0;
|
|
37
|
+
const crypto = __importStar(require("crypto"));
|
|
38
|
+
class TokenCryptoService {
|
|
39
|
+
constructor() {
|
|
40
|
+
this.algorithm = 'aes-256-cbc';
|
|
41
|
+
this.keyLength = 32;
|
|
42
|
+
this.ivLength = 16;
|
|
43
|
+
this.separator = ':';
|
|
44
|
+
}
|
|
45
|
+
deriveKey() {
|
|
46
|
+
// Derive a consistent key from a fixed string
|
|
47
|
+
// In production, this should use a more secure method
|
|
48
|
+
const fixedSalt = 'slack-cli-salt-v1';
|
|
49
|
+
return crypto.pbkdf2Sync('slack-cli-key', fixedSalt, 100000, this.keyLength, 'sha256');
|
|
50
|
+
}
|
|
51
|
+
encrypt(token) {
|
|
52
|
+
try {
|
|
53
|
+
const key = this.deriveKey();
|
|
54
|
+
const iv = crypto.randomBytes(this.ivLength);
|
|
55
|
+
const cipher = crypto.createCipheriv(this.algorithm, key, iv);
|
|
56
|
+
let encrypted = cipher.update(token, 'utf8', 'hex');
|
|
57
|
+
encrypted += cipher.final('hex');
|
|
58
|
+
// Combine IV and encrypted data
|
|
59
|
+
return iv.toString('hex') + this.separator + encrypted;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throw new Error('Failed to encrypt token');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
decrypt(encryptedData) {
|
|
66
|
+
try {
|
|
67
|
+
if (!encryptedData || !encryptedData.includes(this.separator)) {
|
|
68
|
+
throw new Error('Invalid encrypted data format');
|
|
69
|
+
}
|
|
70
|
+
const parts = encryptedData.split(this.separator);
|
|
71
|
+
if (parts.length !== 2) {
|
|
72
|
+
throw new Error('Invalid encrypted data format');
|
|
73
|
+
}
|
|
74
|
+
const iv = Buffer.from(parts[0], 'hex');
|
|
75
|
+
const encrypted = parts[1];
|
|
76
|
+
if (iv.length !== this.ivLength) {
|
|
77
|
+
throw new Error('Invalid IV length');
|
|
78
|
+
}
|
|
79
|
+
const key = this.deriveKey();
|
|
80
|
+
const decipher = crypto.createDecipheriv(this.algorithm, key, iv);
|
|
81
|
+
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
|
|
82
|
+
decrypted += decipher.final('utf8');
|
|
83
|
+
return decrypted;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw new Error('Failed to decrypt token');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
isEncrypted(value) {
|
|
90
|
+
if (!value)
|
|
91
|
+
return false;
|
|
92
|
+
// Check if the value has the expected format
|
|
93
|
+
const parts = value.split(this.separator);
|
|
94
|
+
if (parts.length !== 2)
|
|
95
|
+
return false;
|
|
96
|
+
// Check if the IV part is valid hex and has correct length
|
|
97
|
+
try {
|
|
98
|
+
const ivHex = parts[0];
|
|
99
|
+
if (!/^[0-9a-fA-F]+$/.test(ivHex))
|
|
100
|
+
return false;
|
|
101
|
+
if (ivHex.length !== this.ivLength * 2)
|
|
102
|
+
return false;
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.TokenCryptoService = TokenCryptoService;
|
|
111
|
+
//# sourceMappingURL=token-crypto-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-crypto-service.js","sourceRoot":"","sources":["../../../src/utils/config/token-crypto-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC,MAAa,kBAAkB;IAA/B;QACmB,cAAS,GAAG,aAAa,CAAC;QAC1B,cAAS,GAAG,EAAE,CAAC;QACf,aAAQ,GAAG,EAAE,CAAC;QACd,cAAS,GAAG,GAAG,CAAC;IAyEnC,CAAC;IAvES,SAAS;QACf,8CAA8C;QAC9C,sDAAsD;QACtD,MAAM,SAAS,GAAG,mBAAmB,CAAC;QACtC,OAAO,MAAM,CAAC,UAAU,CAAC,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACzF,CAAC;IAED,OAAO,CAAC,KAAa;QACnB,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YAC7B,MAAM,EAAE,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AAG,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YAC7B,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;YAElE,IAAI,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;YAC1D,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAEpC,OAAO,SAAS,CAAC;QACnB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,WAAW,CAAC,KAAa;QACvB,IAAI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAC;QAEzB,6CAA6C;QAC7C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAErC,2DAA2D;QAC3D,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACvB,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;YAChD,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,QAAQ,GAAG,CAAC;gBAAE,OAAO,KAAK,CAAC;YAErD,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF;AA7ED,gDA6EC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface BaseFormatter<T> {
|
|
2
|
+
format(data: T): void;
|
|
3
|
+
}
|
|
4
|
+
export declare abstract class AbstractFormatter<T> implements BaseFormatter<T> {
|
|
5
|
+
abstract format(data: T): void;
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class JsonFormatter<TInput, TOutput = any> extends AbstractFormatter<TInput> {
|
|
8
|
+
protected abstract transform(data: TInput): TOutput;
|
|
9
|
+
format(data: TInput): void;
|
|
10
|
+
}
|
|
11
|
+
export interface FormatterMap<T> {
|
|
12
|
+
table: BaseFormatter<T>;
|
|
13
|
+
simple: BaseFormatter<T>;
|
|
14
|
+
json: BaseFormatter<T>;
|
|
15
|
+
[key: string]: BaseFormatter<T>;
|
|
16
|
+
}
|
|
17
|
+
export declare class FormatterFactory<T> {
|
|
18
|
+
private formatters;
|
|
19
|
+
constructor(formatters: FormatterMap<T>);
|
|
20
|
+
create(format?: string): BaseFormatter<T>;
|
|
21
|
+
}
|
|
22
|
+
export declare function createFormatterFactory<T>(formatters: FormatterMap<T>): FormatterFactory<T>;
|
|
23
|
+
//# sourceMappingURL=base-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-formatter.d.ts","sourceRoot":"","sources":["../../../src/utils/formatters/base-formatter.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;CACvB;AAED,8BAAsB,iBAAiB,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IACpE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;CAC/B;AAED,8BAAsB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,GAAG,CAAE,SAAQ,iBAAiB,CAAC,MAAM,CAAC;IAC1F,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAEnD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAG3B;AAED,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACxB,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACzB,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;CACjC;AAED,qBAAa,gBAAgB,CAAC,CAAC;IACjB,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IAE/C,MAAM,CAAC,MAAM,GAAE,MAAgB,GAAG,aAAa,CAAC,CAAC,CAAC;CAGnD;AAED,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAE1F"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormatterFactory = exports.JsonFormatter = exports.AbstractFormatter = void 0;
|
|
4
|
+
exports.createFormatterFactory = createFormatterFactory;
|
|
5
|
+
class AbstractFormatter {
|
|
6
|
+
}
|
|
7
|
+
exports.AbstractFormatter = AbstractFormatter;
|
|
8
|
+
class JsonFormatter extends AbstractFormatter {
|
|
9
|
+
format(data) {
|
|
10
|
+
console.log(JSON.stringify(this.transform(data), null, 2));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.JsonFormatter = JsonFormatter;
|
|
14
|
+
class FormatterFactory {
|
|
15
|
+
constructor(formatters) {
|
|
16
|
+
this.formatters = formatters;
|
|
17
|
+
}
|
|
18
|
+
create(format = 'table') {
|
|
19
|
+
return this.formatters[format] || this.formatters.table;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.FormatterFactory = FormatterFactory;
|
|
23
|
+
function createFormatterFactory(formatters) {
|
|
24
|
+
return new FormatterFactory(formatters);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=base-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-formatter.js","sourceRoot":"","sources":["../../../src/utils/formatters/base-formatter.ts"],"names":[],"mappings":";;;AA+BA,wDAEC;AA7BD,MAAsB,iBAAiB;CAEtC;AAFD,8CAEC;AAED,MAAsB,aAAqC,SAAQ,iBAAyB;IAG1F,MAAM,CAAC,IAAY;QACjB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7D,CAAC;CACF;AAND,sCAMC;AASD,MAAa,gBAAgB;IAC3B,YAAoB,UAA2B;QAA3B,eAAU,GAAV,UAAU,CAAiB;IAAG,CAAC;IAEnD,MAAM,CAAC,SAAiB,OAAO;QAC7B,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;IAC1D,CAAC;CACF;AAND,4CAMC;AAED,SAAgB,sBAAsB,CAAI,UAA2B;IACnE,OAAO,IAAI,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import { BaseFormatter } from './output-formatter';
|
|
2
1
|
import { Channel } from '../slack-api-client';
|
|
3
|
-
export
|
|
4
|
-
|
|
2
|
+
export interface ChannelFormatterOptions {
|
|
3
|
+
channels: Channel[];
|
|
4
|
+
countOnly?: boolean;
|
|
5
5
|
}
|
|
6
|
-
export declare
|
|
7
|
-
format(channels: Channel[]): void;
|
|
8
|
-
}
|
|
9
|
-
export declare class ChannelJsonFormatter extends BaseFormatter<Channel> {
|
|
10
|
-
format(channels: Channel[]): void;
|
|
11
|
-
}
|
|
12
|
-
export declare class ChannelCountFormatter extends BaseFormatter<Channel> {
|
|
13
|
-
format(channels: Channel[]): void;
|
|
14
|
-
}
|
|
15
|
-
export declare function createChannelFormatter(format: string, countOnly: boolean): BaseFormatter<Channel>;
|
|
6
|
+
export declare function createChannelFormatter(format: string, countOnly: boolean): import("./base-formatter").BaseFormatter<ChannelFormatterOptions>;
|
|
16
7
|
//# sourceMappingURL=channel-formatters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel-formatters.d.ts","sourceRoot":"","sources":["../../../src/utils/formatters/channel-formatters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"channel-formatters.d.ts","sourceRoot":"","sources":["../../../src/utils/formatters/channel-formatters.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAI9C,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAwDD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,qEAKxE"}
|