@kyoji2/intercom-cli 0.1.0 → 0.1.6
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 +40 -1
- package/dist/index.js +21645 -20721
- package/package.json +7 -3
- package/src/cli/registry.ts +924 -0
- package/src/client.ts +10 -0
- package/src/commands/admins.ts +2 -2
- package/src/commands/articles.ts +8 -8
- package/src/commands/auth.ts +3 -3
- package/src/commands/companies.ts +6 -6
- package/src/commands/contacts.ts +13 -13
- package/src/commands/conversations.ts +72 -15
- package/src/commands/events.ts +4 -4
- package/src/commands/index.ts +24 -10
- package/src/commands/overview.ts +4 -2
- package/src/commands/replyPayload.ts +46 -0
- package/src/commands/tags.ts +6 -6
- package/src/commands/ticketTypes.ts +76 -0
- package/src/commands/tickets.ts +398 -0
- package/src/index.ts +19 -623
- package/src/utils/config.ts +31 -24
- package/src/utils/index.ts +1 -0
- package/src/utils/output.ts +1 -0
package/src/utils/config.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { access, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
2
3
|
import { homedir } from "node:os";
|
|
3
4
|
import { join } from "node:path";
|
|
4
5
|
|
|
@@ -13,8 +14,11 @@ export class ConfigError extends Error {
|
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
const
|
|
17
|
-
|
|
17
|
+
export const DEFAULT_CONFIG_DIR = join(homedir(), ".config", "intercom-cli");
|
|
18
|
+
|
|
19
|
+
function getConfigFile(configDir: string): string {
|
|
20
|
+
return join(configDir, "config.json");
|
|
21
|
+
}
|
|
18
22
|
|
|
19
23
|
function isValidConfig(data: unknown): data is Config {
|
|
20
24
|
if (typeof data !== "object" || data === null) return false;
|
|
@@ -22,13 +26,16 @@ function isValidConfig(data: unknown): data is Config {
|
|
|
22
26
|
return typeof obj.token === "string" && obj.token.length > 0;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
export async function loadConfig(): Promise<Config | null> {
|
|
29
|
+
export async function loadConfig(configDir: string): Promise<Config | null> {
|
|
26
30
|
try {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
const configFile = getConfigFile(configDir);
|
|
32
|
+
try {
|
|
33
|
+
await access(configFile);
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
30
37
|
|
|
31
|
-
const text = await
|
|
38
|
+
const text = await readFile(configFile, "utf-8");
|
|
32
39
|
if (!text.trim()) return null;
|
|
33
40
|
|
|
34
41
|
let data: unknown;
|
|
@@ -36,13 +43,13 @@ export async function loadConfig(): Promise<Config | null> {
|
|
|
36
43
|
data = JSON.parse(text);
|
|
37
44
|
} catch {
|
|
38
45
|
throw new ConfigError(
|
|
39
|
-
`Invalid JSON in config file: ${
|
|
46
|
+
`Invalid JSON in config file: ${configFile}. Delete the file and run 'intercom login' again.`,
|
|
40
47
|
);
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
if (!isValidConfig(data)) {
|
|
44
51
|
throw new ConfigError(
|
|
45
|
-
`Invalid config format in ${
|
|
52
|
+
`Invalid config format in ${configFile}. Expected { "token": "..." }. Delete the file and run 'intercom login' again.`,
|
|
46
53
|
);
|
|
47
54
|
}
|
|
48
55
|
|
|
@@ -53,11 +60,12 @@ export async function loadConfig(): Promise<Config | null> {
|
|
|
53
60
|
}
|
|
54
61
|
}
|
|
55
62
|
|
|
56
|
-
export function loadConfigSync(): Config | null {
|
|
63
|
+
export function loadConfigSync(configDir: string): Config | null {
|
|
57
64
|
try {
|
|
58
|
-
|
|
65
|
+
const configFile = getConfigFile(configDir);
|
|
66
|
+
if (!existsSync(configFile)) return null;
|
|
59
67
|
|
|
60
|
-
const text = readFileSync(
|
|
68
|
+
const text = readFileSync(configFile, "utf-8");
|
|
61
69
|
if (!text.trim()) return null;
|
|
62
70
|
|
|
63
71
|
const data = JSON.parse(text);
|
|
@@ -69,25 +77,24 @@ export function loadConfigSync(): Config | null {
|
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
|
|
72
|
-
export async function saveConfig(config: Config): Promise<void> {
|
|
80
|
+
export async function saveConfig(configDir: string, config: Config): Promise<void> {
|
|
73
81
|
if (!config.token || typeof config.token !== "string") {
|
|
74
82
|
throw new ConfigError("Invalid token: token must be a non-empty string");
|
|
75
83
|
}
|
|
76
84
|
|
|
77
|
-
|
|
78
|
-
await
|
|
85
|
+
const configFile = getConfigFile(configDir);
|
|
86
|
+
await mkdir(configDir, { recursive: true });
|
|
87
|
+
await writeFile(configFile, JSON.stringify(config, null, 2), "utf-8");
|
|
79
88
|
}
|
|
80
89
|
|
|
81
|
-
export async function deleteConfig(): Promise<void> {
|
|
90
|
+
export async function deleteConfig(configDir: string): Promise<void> {
|
|
82
91
|
try {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
await Bun.$`rm -f ${CONFIG_FILE}`;
|
|
86
|
-
}
|
|
92
|
+
const configFile = getConfigFile(configDir);
|
|
93
|
+
await rm(configFile, { force: true });
|
|
87
94
|
} catch {}
|
|
88
95
|
}
|
|
89
96
|
|
|
90
|
-
export function getToken(): string | null {
|
|
97
|
+
export function getToken(configDir: string): string | null {
|
|
91
98
|
const envToken = process.env.INTERCOM_ACCESS_TOKEN;
|
|
92
99
|
if (envToken) {
|
|
93
100
|
if (envToken.trim().length === 0) {
|
|
@@ -96,11 +103,11 @@ export function getToken(): string | null {
|
|
|
96
103
|
return envToken.trim();
|
|
97
104
|
}
|
|
98
105
|
|
|
99
|
-
const config = loadConfigSync();
|
|
106
|
+
const config = loadConfigSync(configDir);
|
|
100
107
|
return config?.token || null;
|
|
101
108
|
}
|
|
102
109
|
|
|
103
|
-
export async function getTokenAsync(): Promise<string | null> {
|
|
110
|
+
export async function getTokenAsync(configDir: string): Promise<string | null> {
|
|
104
111
|
const envToken = process.env.INTERCOM_ACCESS_TOKEN;
|
|
105
112
|
if (envToken) {
|
|
106
113
|
if (envToken.trim().length === 0) {
|
|
@@ -109,6 +116,6 @@ export async function getTokenAsync(): Promise<string | null> {
|
|
|
109
116
|
return envToken.trim();
|
|
110
117
|
}
|
|
111
118
|
|
|
112
|
-
const config = await loadConfig();
|
|
119
|
+
const config = await loadConfig(configDir);
|
|
113
120
|
return config?.token || null;
|
|
114
121
|
}
|
package/src/utils/index.ts
CHANGED