@kiyeonjeon21/ncli 0.1.7 → 0.1.9
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/dist/commands/datalab.js +3 -12
- package/dist/commands/init.js +25 -22
- package/dist/commands/search.js +2 -6
- package/dist/core/client.js +1 -1
- package/dist/core/error.d.ts +1 -0
- package/dist/core/error.js +19 -0
- package/package.json +1 -1
package/dist/commands/datalab.js
CHANGED
|
@@ -4,6 +4,7 @@ import { NaverClient } from "../core/client.js";
|
|
|
4
4
|
import { getOutputFormat, getFieldMask, printOutput, printJson } from "../core/output.js";
|
|
5
5
|
import { getSchema } from "../schemas/index.js";
|
|
6
6
|
import { readJsonArg } from "../core/stdin.js";
|
|
7
|
+
import { writeError } from "../core/error.js";
|
|
7
8
|
const DATALAB_BASE_URL = "https://openapi.naver.com/v1/datalab";
|
|
8
9
|
export const datalabCommand = new Command("datalab").description("Naver DataLab trend and shopping insight APIs. Rate limit: 1,000/day");
|
|
9
10
|
datalabCommand
|
|
@@ -43,12 +44,7 @@ Schema: ncli schema datalab.trend`)
|
|
|
43
44
|
printOutput(data, format, fields ?? undefined);
|
|
44
45
|
}
|
|
45
46
|
catch (err) {
|
|
46
|
-
|
|
47
|
-
error: {
|
|
48
|
-
code: "COMMAND_FAILED",
|
|
49
|
-
message: err instanceof Error ? err.message : String(err),
|
|
50
|
-
},
|
|
51
|
-
}) + "\n");
|
|
47
|
+
writeError(err);
|
|
52
48
|
process.exit(1);
|
|
53
49
|
}
|
|
54
50
|
});
|
|
@@ -89,12 +85,7 @@ Schema: ncli schema datalab.shopping`)
|
|
|
89
85
|
printOutput(data, format, fields ?? undefined);
|
|
90
86
|
}
|
|
91
87
|
catch (err) {
|
|
92
|
-
|
|
93
|
-
error: {
|
|
94
|
-
code: "COMMAND_FAILED",
|
|
95
|
-
message: err instanceof Error ? err.message : String(err),
|
|
96
|
-
},
|
|
97
|
-
}) + "\n");
|
|
88
|
+
writeError(err);
|
|
98
89
|
process.exit(1);
|
|
99
90
|
}
|
|
100
91
|
});
|
package/dist/commands/init.js
CHANGED
|
@@ -13,7 +13,7 @@ function prompt(question, mask = false) {
|
|
|
13
13
|
});
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
// Masked input
|
|
16
|
+
// Masked input — handles both typing and paste
|
|
17
17
|
return new Promise((resolve) => {
|
|
18
18
|
process.stderr.write(question);
|
|
19
19
|
const stdin = process.stdin;
|
|
@@ -23,27 +23,30 @@ function prompt(question, mask = false) {
|
|
|
23
23
|
stdin.resume();
|
|
24
24
|
stdin.setEncoding("utf-8");
|
|
25
25
|
let input = "";
|
|
26
|
-
const onData = (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
stdin.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
const onData = (data) => {
|
|
27
|
+
for (const ch of data) {
|
|
28
|
+
if (ch === "\r" || ch === "\n") {
|
|
29
|
+
stdin.removeListener("data", onData);
|
|
30
|
+
if (stdin.isTTY)
|
|
31
|
+
stdin.setRawMode(wasRaw ?? false);
|
|
32
|
+
stdin.pause();
|
|
33
|
+
process.stderr.write("\n");
|
|
34
|
+
resolve(input.trim());
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
else if (ch === "\x7f" || ch === "\b") {
|
|
38
|
+
if (input.length > 0) {
|
|
39
|
+
input = input.slice(0, -1);
|
|
40
|
+
process.stderr.write("\b \b");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (ch === "\x03") {
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
input += ch;
|
|
48
|
+
process.stderr.write("*");
|
|
39
49
|
}
|
|
40
|
-
}
|
|
41
|
-
else if (ch === "\x03") {
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
input += ch;
|
|
46
|
-
process.stderr.write("*");
|
|
47
50
|
}
|
|
48
51
|
};
|
|
49
52
|
stdin.on("data", onData);
|
|
@@ -76,7 +79,7 @@ export const initCommand = new Command("init")
|
|
|
76
79
|
process.stderr.write(" Register an app at: https://developers.naver.com/apps/\n");
|
|
77
80
|
process.stderr.write(" Select APIs: Search, DataLab, etc.\n");
|
|
78
81
|
process.stderr.write(" Web service URL: http://localhost\n\n");
|
|
79
|
-
const clientId = await prompt(" Client ID: ");
|
|
82
|
+
const clientId = await prompt(" Client ID: ", true);
|
|
80
83
|
if (!clientId) {
|
|
81
84
|
process.stderr.write(" Aborted — no Client ID provided.\n");
|
|
82
85
|
process.exit(1);
|
package/dist/commands/search.js
CHANGED
|
@@ -5,6 +5,7 @@ import { getOutputFormat, getFieldMask, printOutput, printJson } from "../core/o
|
|
|
5
5
|
import { validateAgentInput, sanitizeResponse } from "../core/validate.js";
|
|
6
6
|
import { getSchema } from "../schemas/index.js";
|
|
7
7
|
import { readJsonArg } from "../core/stdin.js";
|
|
8
|
+
import { writeError } from "../core/error.js";
|
|
8
9
|
const SEARCH_TYPES = [
|
|
9
10
|
"blog",
|
|
10
11
|
"news",
|
|
@@ -163,12 +164,7 @@ for (const type of SEARCH_TYPES) {
|
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
catch (err) {
|
|
166
|
-
|
|
167
|
-
error: {
|
|
168
|
-
code: "COMMAND_FAILED",
|
|
169
|
-
message: err instanceof Error ? err.message : String(err),
|
|
170
|
-
},
|
|
171
|
-
}) + "\n");
|
|
167
|
+
writeError(err);
|
|
172
168
|
process.exit(1);
|
|
173
169
|
}
|
|
174
170
|
});
|
package/dist/core/client.js
CHANGED
|
@@ -18,7 +18,7 @@ function parseNaverError(status, body) {
|
|
|
18
18
|
return {
|
|
19
19
|
error: {
|
|
20
20
|
code: `HTTP_${status}`,
|
|
21
|
-
message: hint ? `${errorMessage} (${hint})` : errorMessage
|
|
21
|
+
message: hint ? `${errorMessage} (${hint})` : errorMessage || `HTTP ${status} error`,
|
|
22
22
|
status,
|
|
23
23
|
naverCode: errorCode || undefined,
|
|
24
24
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function writeError(err: unknown): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function writeError(err) {
|
|
2
|
+
if (err instanceof Error) {
|
|
3
|
+
// If message is already a JSON error from client.ts, pass through
|
|
4
|
+
try {
|
|
5
|
+
const parsed = JSON.parse(err.message);
|
|
6
|
+
if (parsed.error) {
|
|
7
|
+
process.stderr.write(JSON.stringify(parsed) + "\n");
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
// not JSON, wrap it
|
|
13
|
+
}
|
|
14
|
+
process.stderr.write(JSON.stringify({ error: { code: "COMMAND_FAILED", message: err.message } }) + "\n");
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
process.stderr.write(JSON.stringify({ error: { code: "COMMAND_FAILED", message: String(err) } }) + "\n");
|
|
18
|
+
}
|
|
19
|
+
}
|