@kiyeonjeon21/ncli 0.1.2 → 0.1.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/CONTEXT.md +3 -3
- package/LICENSE +21 -0
- package/dist/cli.js +6 -1
- package/dist/commands/datalab.js +2 -2
- package/dist/commands/init.js +44 -8
- package/dist/commands/search.js +11 -11
- package/dist/core/output.js +18 -2
- package/package.json +1 -1
- package/skills/datalab.md +4 -4
- package/skills/search.md +2 -2
package/CONTEXT.md
CHANGED
|
@@ -55,7 +55,7 @@ naver search blog "AI" --fields "title,link,description" --output json
|
|
|
55
55
|
naver search news --json '{"query":"AI","display":5,"sort":"date"}'
|
|
56
56
|
|
|
57
57
|
# NDJSON for streaming
|
|
58
|
-
naver search shop "
|
|
58
|
+
naver search shop "laptop" --output ndjson --fields "title,lprice,mallName"
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
### DataLab
|
|
@@ -65,14 +65,14 @@ naver datalab trend --json '{
|
|
|
65
65
|
"startDate":"2026-01-01",
|
|
66
66
|
"endDate":"2026-04-01",
|
|
67
67
|
"timeUnit":"month",
|
|
68
|
-
"keywordGroups":[{"groupName":"AI","keywords":["
|
|
68
|
+
"keywordGroups":[{"groupName":"AI","keywords":["artificial intelligence","AI"]}]
|
|
69
69
|
}'
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
### Dry-run
|
|
73
73
|
|
|
74
74
|
```bash
|
|
75
|
-
naver --dry-run search blog "
|
|
75
|
+
naver --dry-run search blog "test"
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
## Error Handling
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kiyeon Jeon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import "dotenv/config";
|
|
3
|
+
import { readFileSync } from "fs";
|
|
4
|
+
import { join, dirname } from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
3
6
|
import { Command } from "commander";
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
|
|
4
9
|
import { searchCommand } from "./commands/search.js";
|
|
5
10
|
import { datalabCommand } from "./commands/datalab.js";
|
|
6
11
|
import { authCommand } from "./commands/auth.js";
|
|
@@ -12,7 +17,7 @@ const program = new Command();
|
|
|
12
17
|
program
|
|
13
18
|
.name("ncli")
|
|
14
19
|
.description("Agent-native CLI for Naver Open APIs")
|
|
15
|
-
.version(
|
|
20
|
+
.version(pkg.version)
|
|
16
21
|
.option("--output <format>", "output format: json, ndjson, table", "json")
|
|
17
22
|
.option("--fields <fields>", "comma-separated field mask")
|
|
18
23
|
.option("--dry-run", "validate without executing")
|
package/dist/commands/datalab.js
CHANGED
|
@@ -13,7 +13,7 @@ datalabCommand
|
|
|
13
13
|
.option("--describe", "show API schema for this command (no execution)")
|
|
14
14
|
.addHelpText("after", `
|
|
15
15
|
Examples:
|
|
16
|
-
ncli datalab trend --json '{"startDate":"2026-01-01","endDate":"2026-04-01","timeUnit":"month","keywordGroups":[{"groupName":"AI","keywords":["AI","
|
|
16
|
+
ncli datalab trend --json '{"startDate":"2026-01-01","endDate":"2026-04-01","timeUnit":"month","keywordGroups":[{"groupName":"AI","keywords":["AI","artificial intelligence"]}]}'
|
|
17
17
|
|
|
18
18
|
Schema: ncli schema datalab.trend`)
|
|
19
19
|
.action(async (opts) => {
|
|
@@ -59,7 +59,7 @@ datalabCommand
|
|
|
59
59
|
.option("--describe", "show API schema for this command (no execution)")
|
|
60
60
|
.addHelpText("after", `
|
|
61
61
|
Examples:
|
|
62
|
-
ncli datalab shopping --json '{"startDate":"2026-01-01","endDate":"2026-04-01","timeUnit":"month","category":[{"name":"
|
|
62
|
+
ncli datalab shopping --json '{"startDate":"2026-01-01","endDate":"2026-04-01","timeUnit":"month","category":[{"name":"laptop","param":["50000832"]}]}'
|
|
63
63
|
|
|
64
64
|
Schema: ncli schema datalab.shopping`)
|
|
65
65
|
.action(async (opts) => {
|
package/dist/commands/init.js
CHANGED
|
@@ -3,13 +3,49 @@ import { mkdirSync, existsSync, readFileSync, writeFileSync } from "fs";
|
|
|
3
3
|
import { createInterface } from "readline";
|
|
4
4
|
import { NCLI_DIR, NCLI_ENV_PATH, loadConfig } from "../core/config.js";
|
|
5
5
|
import { printJson } from "../core/output.js";
|
|
6
|
-
function prompt(question) {
|
|
7
|
-
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
6
|
+
function prompt(question, mask = false) {
|
|
8
7
|
return new Promise((resolve) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
process.stderr.write(question);
|
|
9
|
+
if (!mask) {
|
|
10
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
11
|
+
rl.question("", (answer) => {
|
|
12
|
+
rl.close();
|
|
13
|
+
resolve(answer.trim());
|
|
14
|
+
});
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// Masked input
|
|
18
|
+
const stdin = process.stdin;
|
|
19
|
+
const wasRaw = stdin.isRaw;
|
|
20
|
+
if (stdin.isTTY)
|
|
21
|
+
stdin.setRawMode(true);
|
|
22
|
+
stdin.resume();
|
|
23
|
+
stdin.setEncoding("utf-8");
|
|
24
|
+
let input = "";
|
|
25
|
+
const onData = (ch) => {
|
|
26
|
+
if (ch === "\r" || ch === "\n") {
|
|
27
|
+
stdin.removeListener("data", onData);
|
|
28
|
+
if (stdin.isTTY)
|
|
29
|
+
stdin.setRawMode(wasRaw ?? false);
|
|
30
|
+
stdin.pause();
|
|
31
|
+
process.stderr.write("\n");
|
|
32
|
+
resolve(input.trim());
|
|
33
|
+
}
|
|
34
|
+
else if (ch === "\x7f" || ch === "\b") {
|
|
35
|
+
if (input.length > 0) {
|
|
36
|
+
input = input.slice(0, -1);
|
|
37
|
+
process.stderr.write("\b \b");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (ch === "\x03") {
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
input += ch;
|
|
45
|
+
process.stderr.write("*");
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
stdin.on("data", onData);
|
|
13
49
|
});
|
|
14
50
|
}
|
|
15
51
|
export const initCommand = new Command("init")
|
|
@@ -39,12 +75,12 @@ export const initCommand = new Command("init")
|
|
|
39
75
|
process.stderr.write(" Register an app at: https://developers.naver.com/apps/\n");
|
|
40
76
|
process.stderr.write(" Select APIs: Search, DataLab, etc.\n");
|
|
41
77
|
process.stderr.write(" Web service URL: http://localhost\n\n");
|
|
42
|
-
const clientId = await prompt(" Client ID: ");
|
|
78
|
+
const clientId = await prompt(" Client ID: ", true);
|
|
43
79
|
if (!clientId) {
|
|
44
80
|
process.stderr.write(" Aborted — no Client ID provided.\n");
|
|
45
81
|
process.exit(1);
|
|
46
82
|
}
|
|
47
|
-
const clientSecret = await prompt(" Client Secret: ");
|
|
83
|
+
const clientSecret = await prompt(" Client Secret: ", true);
|
|
48
84
|
if (!clientSecret) {
|
|
49
85
|
process.stderr.write(" Aborted — no Client Secret provided.\n");
|
|
50
86
|
process.exit(1);
|
package/dist/commands/search.js
CHANGED
|
@@ -24,18 +24,18 @@ const SEARCH_BASE_URL = "https://openapi.naver.com/v1/search";
|
|
|
24
24
|
const SEARCH_EXAMPLES = {
|
|
25
25
|
blog: ` ncli search blog "AI" --fields "title,link,description"
|
|
26
26
|
ncli search blog --json '{"query":"AI","display":5,"sort":"date"}'`,
|
|
27
|
-
news: ` ncli search news "
|
|
27
|
+
news: ` ncli search news "semiconductor" --fields "title,link,pubDate"`,
|
|
28
28
|
web: ` ncli search web "TypeScript" --fields "title,link,description"`,
|
|
29
|
-
image: ` ncli search image "
|
|
30
|
-
book: ` ncli search book "
|
|
31
|
-
cafe: ` ncli search cafe "
|
|
32
|
-
kin: ` ncli search kin "
|
|
33
|
-
encyclopedia: ` ncli search encyclopedia "
|
|
34
|
-
shop: ` ncli search shop "
|
|
35
|
-
local: ` ncli search local "
|
|
36
|
-
errata: ` ncli search errata "
|
|
37
|
-
adult: ` ncli search adult "
|
|
38
|
-
doc: ` ncli search doc "
|
|
29
|
+
image: ` ncli search image "Jeju" --display 5`,
|
|
30
|
+
book: ` ncli search book "artificial intelligence" --fields "title,author,publisher,isbn"`,
|
|
31
|
+
cafe: ` ncli search cafe "restaurant" --fields "title,link,cafename"`,
|
|
32
|
+
kin: ` ncli search kin "programming" --sort count`,
|
|
33
|
+
encyclopedia: ` ncli search encyclopedia "quantum mechanics" --fields "title,link,description"`,
|
|
34
|
+
shop: ` ncli search shop "laptop" --fields "title,lprice,mallName" --sort dsc`,
|
|
35
|
+
local: ` ncli search local "Gangnam restaurant" --fields "title,address,telephone"`,
|
|
36
|
+
errata: ` ncli search errata "typo check"`,
|
|
37
|
+
adult: ` ncli search adult "keyword"`,
|
|
38
|
+
doc: ` ncli search doc "AI research paper" --fields "title,link,description"`,
|
|
39
39
|
};
|
|
40
40
|
const API_TYPE_MAP = {
|
|
41
41
|
encyclopedia: "encyc",
|
package/dist/core/output.js
CHANGED
|
@@ -24,12 +24,28 @@ export function applyFieldMask(data, fields) {
|
|
|
24
24
|
}
|
|
25
25
|
return result;
|
|
26
26
|
}
|
|
27
|
+
function stripHtml(value) {
|
|
28
|
+
if (typeof value === "string") {
|
|
29
|
+
return value.replace(/<\/?[^>]+(>|$)/g, "");
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(value)) {
|
|
32
|
+
return value.map(stripHtml);
|
|
33
|
+
}
|
|
34
|
+
if (typeof value === "object" && value !== null) {
|
|
35
|
+
const result = {};
|
|
36
|
+
for (const [k, v] of Object.entries(value)) {
|
|
37
|
+
result[k] = stripHtml(v);
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
27
43
|
export function printJson(data) {
|
|
28
|
-
process.stdout.write(JSON.stringify(data, null, 2) + "\n");
|
|
44
|
+
process.stdout.write(JSON.stringify(stripHtml(data), null, 2) + "\n");
|
|
29
45
|
}
|
|
30
46
|
export function printNdjson(items) {
|
|
31
47
|
for (const item of items) {
|
|
32
|
-
process.stdout.write(JSON.stringify(item) + "\n");
|
|
48
|
+
process.stdout.write(JSON.stringify(stripHtml(item)) + "\n");
|
|
33
49
|
}
|
|
34
50
|
}
|
|
35
51
|
export function printOutput(data, format, fields) {
|
package/package.json
CHANGED
package/skills/datalab.md
CHANGED
|
@@ -31,8 +31,8 @@ naver datalab trend --json '{
|
|
|
31
31
|
"endDate": "2026-04-01",
|
|
32
32
|
"timeUnit": "month",
|
|
33
33
|
"keywordGroups": [
|
|
34
|
-
{"groupName": "AI", "keywords": ["
|
|
35
|
-
{"groupName": "
|
|
34
|
+
{"groupName": "AI", "keywords": ["artificial intelligence", "AI"]},
|
|
35
|
+
{"groupName": "blockchain", "keywords": ["blockchain", "blockchain"]}
|
|
36
36
|
]
|
|
37
37
|
}'
|
|
38
38
|
```
|
|
@@ -45,7 +45,7 @@ naver datalab shopping --json '{
|
|
|
45
45
|
"endDate": "2026-04-01",
|
|
46
46
|
"timeUnit": "month",
|
|
47
47
|
"category": [
|
|
48
|
-
{"name": "
|
|
48
|
+
{"name": "laptop", "param": ["50000832"]}
|
|
49
49
|
]
|
|
50
50
|
}'
|
|
51
51
|
```
|
|
@@ -57,7 +57,7 @@ naver datalab trend --json '{
|
|
|
57
57
|
"startDate": "2026-01-01",
|
|
58
58
|
"endDate": "2026-04-01",
|
|
59
59
|
"timeUnit": "week",
|
|
60
|
-
"keywordGroups": [{"groupName": "test", "keywords": ["
|
|
60
|
+
"keywordGroups": [{"groupName": "test", "keywords": ["test"]}],
|
|
61
61
|
"device": "mo",
|
|
62
62
|
"gender": "f",
|
|
63
63
|
"ages": ["20", "30"]
|
package/skills/search.md
CHANGED
|
@@ -29,7 +29,7 @@ export NAVER_CLIENT_SECRET="your-client-secret"
|
|
|
29
29
|
### Quick search
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
|
-
naver search blog "
|
|
32
|
+
naver search blog "keyword" --fields "title,link,description"
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
### Paginated search
|
|
@@ -45,7 +45,7 @@ naver search news "AI" --display 10 --start 11 --fields "title,link,pubDate"
|
|
|
45
45
|
### JSON payload
|
|
46
46
|
|
|
47
47
|
```bash
|
|
48
|
-
naver search shop --json '{"query":"
|
|
48
|
+
naver search shop --json '{"query":"macbook","display":5,"sort":"dsc"}' \
|
|
49
49
|
--fields "title,lprice,hprice,mallName"
|
|
50
50
|
```
|
|
51
51
|
|