nworks 0.3.3 → 0.4.0

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 CHANGED
@@ -26,7 +26,7 @@ nworks login \
26
26
  --bot-id <BOT_ID>
27
27
 
28
28
  # User OAuth 로그인 (캘린더, 드라이브 등 사용자 API용)
29
- nworks login --user --scope calendar.read,file
29
+ nworks login --user --scope calendar.read,file,mail
30
30
 
31
31
  # 인증 확인
32
32
  nworks whoami
@@ -45,6 +45,12 @@ nworks drive list
45
45
 
46
46
  # 파일 업로드
47
47
  nworks drive upload --file ./report.pdf
48
+
49
+ # 메일 전송
50
+ nworks mail send --to "user@example.com" --subject "제목" --body "내용"
51
+
52
+ # 받은편지함 조회
53
+ nworks mail list
48
54
  ```
49
55
 
50
56
  ## CLI Commands
@@ -131,6 +137,27 @@ nworks drive download --file-id <fileId> --out ./downloads --name report.pdf
131
137
 
132
138
  > **Note**: 드라이브 API는 User OAuth가 필요합니다. 먼저 `nworks login --user --scope file`을 실행하세요. 읽기만 필요하면 `file.read` scope로 충분합니다.
133
139
 
140
+ ### 메일 (User OAuth 필요)
141
+
142
+ ```bash
143
+ # 메일 전송
144
+ nworks mail send --to "user@example.com" --subject "제목" --body "내용"
145
+
146
+ # CC/BCC 포함
147
+ nworks mail send --to "user@example.com" --cc "cc@example.com" --subject "제목" --body "내용"
148
+
149
+ # 받은편지함 목록
150
+ nworks mail list
151
+
152
+ # 읽지 않은 메일만
153
+ nworks mail list --unread
154
+
155
+ # 메일 상세 조회
156
+ nworks mail read --id <mailId>
157
+ ```
158
+
159
+ > **Note**: 메일 API는 User OAuth가 필요합니다. 먼저 `nworks login --user --scope mail`을 실행하세요. 읽기만 필요하면 `mail.read` scope로 충분합니다.
160
+
134
161
  ### MCP 서버
135
162
 
136
163
  ```bash
@@ -172,6 +199,8 @@ nworks mcp --list-tools # 등록된 tool 목록
172
199
  | `calendar.read` | 캘린더 일정 조회 | User OAuth | `calendar list` |
173
200
  | `file` | 드라이브 읽기/쓰기 | User OAuth | `drive list/upload/download` |
174
201
  | `file.read` | 드라이브 읽기 전용 | User OAuth | `drive list/download` |
202
+ | `mail` | 메일 읽기/쓰기 | User OAuth | `mail send/list/read` |
203
+ | `mail.read` | 메일 읽기 전용 | User OAuth | `mail list/read` |
175
204
 
176
205
  > **Tip**: scope를 변경한 후에는 토큰을 재발급해야 합니다.
177
206
  > ```bash
@@ -225,7 +254,10 @@ NWORKS_VERBOSE=1 # optional, 디버그 로깅
225
254
  - ~~**v0.1** — 메시지, 조직 구성원, MCP 서버~~
226
255
  - ~~**v0.2** — 캘린더 일정 조회 + User OAuth~~
227
256
  - ~~**v0.3** — 드라이브 파일 조회/업로드/다운로드 (`nworks drive`)~~
228
- - **v0.4** — 게시판, 메일 (`nworks board`, `nworks mail`)
257
+ - ~~**v0.4** — 메일 (`nworks mail send/list/read`)~~
258
+ - **v0.5** — 할 일 (`nworks task list/create/update/delete`)
259
+ - **v0.6** — 캘린더 쓰기 (`nworks calendar create/update/delete`)
260
+ - **v0.7** — 게시판 (`nworks board list/post/read`)
229
261
 
230
262
  ## License
231
263
 
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ var __export = (target, all) => {
7
7
 
8
8
  // src/index.ts
9
9
  import { createRequire } from "module";
10
- import { Command as Command9 } from "commander";
10
+ import { Command as Command10 } from "commander";
11
11
 
12
12
  // src/commands/login.ts
13
13
  import { Command } from "commander";
@@ -1100,9 +1100,185 @@ var downloadCommand = new Command7("download").description("Download a file from
1100
1100
  });
1101
1101
  var driveCommand = new Command7("drive").description("Drive operations (requires User OAuth with file scope)").addCommand(listCommand2).addCommand(uploadCommand).addCommand(downloadCommand);
1102
1102
 
1103
- // src/commands/mcp-cmd.ts
1103
+ // src/commands/mail.ts
1104
1104
  import { Command as Command8 } from "commander";
1105
1105
 
1106
+ // src/api/mail.ts
1107
+ var BASE_URL4 = "https://www.worksapis.com/v1.0";
1108
+ async function authedFetch2(url2, init, profile) {
1109
+ const token = await getValidUserToken(profile);
1110
+ const headers = new Headers(init.headers);
1111
+ headers.set("Authorization", `Bearer ${token}`);
1112
+ return fetch(url2, { ...init, headers });
1113
+ }
1114
+ async function handleError2(res) {
1115
+ if (res.status === 401) {
1116
+ throw new AuthError("User token expired. Run `nworks login --user --scope mail` again.");
1117
+ }
1118
+ let code = "UNKNOWN";
1119
+ let description = `HTTP ${res.status}`;
1120
+ try {
1121
+ const body = await res.json();
1122
+ code = body.code ?? code;
1123
+ description = body.description ?? description;
1124
+ } catch {
1125
+ }
1126
+ throw new ApiError(code, description, res.status);
1127
+ }
1128
+ async function sendMail(opts) {
1129
+ const userId = opts.userId ?? "me";
1130
+ const profile = opts.profile ?? "default";
1131
+ const url2 = `${BASE_URL4}/users/${userId}/mail`;
1132
+ if (process.env["NWORKS_VERBOSE"] === "1") {
1133
+ console.error(`[nworks] POST ${url2}`);
1134
+ }
1135
+ const body = {
1136
+ to: opts.to,
1137
+ subject: opts.subject
1138
+ };
1139
+ if (opts.body !== void 0) body.body = opts.body;
1140
+ if (opts.cc) body.cc = opts.cc;
1141
+ if (opts.bcc) body.bcc = opts.bcc;
1142
+ if (opts.contentType) body.contentType = opts.contentType;
1143
+ const res = await authedFetch2(
1144
+ url2,
1145
+ {
1146
+ method: "POST",
1147
+ headers: { "Content-Type": "application/json" },
1148
+ body: JSON.stringify(body)
1149
+ },
1150
+ profile
1151
+ );
1152
+ if (res.status === 202) return;
1153
+ if (!res.ok) return handleError2(res);
1154
+ }
1155
+ async function listMails(folderId = 0, userId = "me", count = 30, cursor, isUnread, profile = "default") {
1156
+ const params = new URLSearchParams();
1157
+ params.set("count", String(count));
1158
+ if (cursor) params.set("cursor", cursor);
1159
+ if (isUnread) params.set("isUnread", "true");
1160
+ const url2 = `${BASE_URL4}/users/${userId}/mail/mailfolders/${folderId}/children?${params.toString()}`;
1161
+ if (process.env["NWORKS_VERBOSE"] === "1") {
1162
+ console.error(`[nworks] GET ${url2}`);
1163
+ }
1164
+ const res = await authedFetch2(url2, { method: "GET" }, profile);
1165
+ if (!res.ok) return handleError2(res);
1166
+ const data = await res.json();
1167
+ return {
1168
+ mails: data.mails ?? [],
1169
+ unreadCount: data.unreadCount,
1170
+ folderName: data.folderName,
1171
+ totalCount: data.totalCount,
1172
+ responseMetaData: data.responseMetaData
1173
+ };
1174
+ }
1175
+ async function readMail(mailId, userId = "me", profile = "default") {
1176
+ const url2 = `${BASE_URL4}/users/${userId}/mail/${mailId}`;
1177
+ if (process.env["NWORKS_VERBOSE"] === "1") {
1178
+ console.error(`[nworks] GET ${url2}`);
1179
+ }
1180
+ const res = await authedFetch2(url2, { method: "GET" }, profile);
1181
+ if (!res.ok) return handleError2(res);
1182
+ return await res.json();
1183
+ }
1184
+
1185
+ // src/commands/mail.ts
1186
+ var sendCommand2 = new Command8("send").description("Send a mail (requires User OAuth with mail scope)").requiredOption("--to <emails>", "Recipient email addresses (separate with ;)").requiredOption("--subject <subject>", "Mail subject").option("--body <body>", "Mail body content").option("--cc <emails>", "CC email addresses (separate with ;)").option("--bcc <emails>", "BCC email addresses (separate with ;)").option("--content-type <type>", "Body format: html or text", "html").option("--user <userId>", "Sender user ID (default: me)").option("--profile <name>", "Profile name", "default").option("--json", "JSON output").option("--dry-run", "Print request without sending").action(async (opts) => {
1187
+ try {
1188
+ const sendOpts = {
1189
+ to: opts.to,
1190
+ subject: opts.subject,
1191
+ body: opts.body,
1192
+ cc: opts.cc,
1193
+ bcc: opts.bcc,
1194
+ contentType: opts.contentType,
1195
+ userId: opts.user ?? "me",
1196
+ profile: opts.profile
1197
+ };
1198
+ if (opts.dryRun) {
1199
+ output({ dryRun: true, request: sendOpts }, opts);
1200
+ return;
1201
+ }
1202
+ await sendMail(sendOpts);
1203
+ output({ success: true, message: "Mail sent (async)" }, opts);
1204
+ } catch (err) {
1205
+ const error48 = err;
1206
+ errorOutput({ code: error48.code, message: error48.message }, opts);
1207
+ process.exitCode = 1;
1208
+ }
1209
+ });
1210
+ var listCommand3 = new Command8("list").description("List mails in a folder (requires User OAuth with mail or mail.read scope)").option("--folder <folderId>", "Folder ID (default: 0 = inbox)", "0").option("--count <n>", "Items per page (default: 30)", "30").option("--cursor <cursor>", "Pagination cursor").option("--unread", "Show unread mails only", false).option("--user <userId>", "Target user ID (default: me)").option("--profile <name>", "Profile name", "default").option("--json", "JSON output").action(async (opts) => {
1211
+ try {
1212
+ const result = await listMails(
1213
+ parseInt(opts.folder, 10),
1214
+ opts.user ?? "me",
1215
+ parseInt(opts.count, 10),
1216
+ opts.cursor,
1217
+ opts.unread,
1218
+ opts.profile
1219
+ );
1220
+ const mails = result.mails.map((m) => ({
1221
+ mailId: m.mailId,
1222
+ from: m.from.email,
1223
+ subject: m.subject,
1224
+ date: m.receivedTime,
1225
+ status: m.status,
1226
+ attachments: m.attachCount ?? 0
1227
+ }));
1228
+ output(
1229
+ {
1230
+ mails,
1231
+ count: mails.length,
1232
+ totalCount: result.totalCount,
1233
+ unreadCount: result.unreadCount,
1234
+ folderName: result.folderName,
1235
+ nextCursor: result.responseMetaData?.nextCursor ?? null
1236
+ },
1237
+ opts
1238
+ );
1239
+ } catch (err) {
1240
+ const error48 = err;
1241
+ errorOutput({ code: error48.code, message: error48.message }, opts);
1242
+ process.exitCode = 1;
1243
+ }
1244
+ });
1245
+ var readCommand = new Command8("read").description("Read a specific mail (requires User OAuth with mail or mail.read scope)").requiredOption("--id <mailId>", "Mail ID").option("--user <userId>", "Target user ID (default: me)").option("--profile <name>", "Profile name", "default").option("--json", "JSON output").action(async (opts) => {
1246
+ try {
1247
+ const result = await readMail(
1248
+ parseInt(opts.id, 10),
1249
+ opts.user ?? "me",
1250
+ opts.profile
1251
+ );
1252
+ const mail = result.mail;
1253
+ output(
1254
+ {
1255
+ mailId: mail.mailId,
1256
+ from: mail.from,
1257
+ to: mail.to,
1258
+ cc: mail.cc ?? [],
1259
+ subject: mail.subject,
1260
+ body: mail.body,
1261
+ date: mail.receivedTime,
1262
+ attachments: result.attachments?.map((a) => ({
1263
+ id: a.attachmentId,
1264
+ filename: a.filename,
1265
+ contentType: a.contentType,
1266
+ size: a.size
1267
+ })) ?? []
1268
+ },
1269
+ opts
1270
+ );
1271
+ } catch (err) {
1272
+ const error48 = err;
1273
+ errorOutput({ code: error48.code, message: error48.message }, opts);
1274
+ process.exitCode = 1;
1275
+ }
1276
+ });
1277
+ var mailCommand = new Command8("mail").description("Mail operations (requires User OAuth with mail scope)").addCommand(sendCommand2).addCommand(listCommand3).addCommand(readCommand);
1278
+
1279
+ // src/commands/mcp-cmd.ts
1280
+ import { Command as Command9 } from "commander";
1281
+
1106
1282
  // src/mcp/server.ts
1107
1283
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
1108
1284
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
@@ -15123,6 +15299,120 @@ function registerTools(server) {
15123
15299
  }
15124
15300
  }
15125
15301
  );
15302
+ server.tool(
15303
+ "nworks_mail_send",
15304
+ "\uBA54\uC77C\uC744 \uC804\uC1A1\uD569\uB2C8\uB2E4 (User OAuth mail scope \uD544\uC694). \uBE44\uB3D9\uAE30 \uC804\uC1A1\uC73C\uB85C, \uC131\uACF5 \uC2DC 202 \uC751\uB2F5\uC744 \uBC18\uD658\uD569\uB2C8\uB2E4.",
15305
+ {
15306
+ to: external_exports.string().describe("\uC218\uC2E0\uC790 \uC774\uBA54\uC77C (\uC5EC\uB7EC \uBA85\uC740 ; \uB85C \uAD6C\uBD84)"),
15307
+ subject: external_exports.string().describe("\uBA54\uC77C \uC81C\uBAA9"),
15308
+ body: external_exports.string().optional().describe("\uBA54\uC77C \uBCF8\uBB38"),
15309
+ cc: external_exports.string().optional().describe("\uCC38\uC870 \uC774\uBA54\uC77C (\uC5EC\uB7EC \uBA85\uC740 ; \uB85C \uAD6C\uBD84)"),
15310
+ bcc: external_exports.string().optional().describe("\uC228\uC740\uCC38\uC870 \uC774\uBA54\uC77C (\uC5EC\uB7EC \uBA85\uC740 ; \uB85C \uAD6C\uBD84)"),
15311
+ contentType: external_exports.enum(["html", "text"]).optional().describe("\uBCF8\uBB38 \uD615\uC2DD (\uAE30\uBCF8: html)"),
15312
+ userId: external_exports.string().optional().describe("\uBC1C\uC2E0\uC790 ID (\uBBF8\uC9C0\uC815 \uC2DC me)")
15313
+ },
15314
+ async ({ to, subject, body, cc, bcc, contentType, userId }) => {
15315
+ try {
15316
+ await sendMail({
15317
+ to,
15318
+ subject,
15319
+ body,
15320
+ cc,
15321
+ bcc,
15322
+ contentType,
15323
+ userId: userId ?? "me"
15324
+ });
15325
+ return {
15326
+ content: [{ type: "text", text: JSON.stringify({ success: true, message: "Mail sent (async)" }) }]
15327
+ };
15328
+ } catch (err) {
15329
+ const error48 = err;
15330
+ return {
15331
+ content: [{ type: "text", text: `Error: ${error48.message}` }],
15332
+ isError: true
15333
+ };
15334
+ }
15335
+ }
15336
+ );
15337
+ server.tool(
15338
+ "nworks_mail_list",
15339
+ "\uBA54\uC77C\uD568\uC758 \uBA54\uC77C \uBAA9\uB85D\uC744 \uC870\uD68C\uD569\uB2C8\uB2E4 (User OAuth mail \uB610\uB294 mail.read scope \uD544\uC694)",
15340
+ {
15341
+ folderId: external_exports.number().optional().describe("\uBA54\uC77C \uD3F4\uB354 ID (\uAE30\uBCF8: 0 = \uBC1B\uC740\uD3B8\uC9C0\uD568)"),
15342
+ count: external_exports.number().optional().describe("\uD398\uC774\uC9C0\uB2F9 \uD56D\uBAA9 \uC218 (\uAE30\uBCF8: 30, \uCD5C\uB300: 200)"),
15343
+ cursor: external_exports.string().optional().describe("\uD398\uC774\uC9C0\uB124\uC774\uC158 \uCEE4\uC11C"),
15344
+ isUnread: external_exports.boolean().optional().describe("\uC77D\uC9C0 \uC54A\uC740 \uBA54\uC77C\uB9CC \uC870\uD68C"),
15345
+ userId: external_exports.string().optional().describe("\uB300\uC0C1 \uC0AC\uC6A9\uC790 ID (\uBBF8\uC9C0\uC815 \uC2DC me)")
15346
+ },
15347
+ async ({ folderId, count, cursor, isUnread, userId }) => {
15348
+ try {
15349
+ const result = await listMails(
15350
+ folderId ?? 0,
15351
+ userId ?? "me",
15352
+ count ?? 30,
15353
+ cursor,
15354
+ isUnread
15355
+ );
15356
+ const mails = result.mails.map((m) => ({
15357
+ mailId: m.mailId,
15358
+ from: m.from.email,
15359
+ subject: m.subject,
15360
+ date: m.receivedTime,
15361
+ status: m.status,
15362
+ attachments: m.attachCount ?? 0
15363
+ }));
15364
+ return {
15365
+ content: [{ type: "text", text: JSON.stringify({ mails, count: mails.length, totalCount: result.totalCount, unreadCount: result.unreadCount, nextCursor: result.responseMetaData?.nextCursor ?? null }) }]
15366
+ };
15367
+ } catch (err) {
15368
+ const error48 = err;
15369
+ return {
15370
+ content: [{ type: "text", text: `Error: ${error48.message}` }],
15371
+ isError: true
15372
+ };
15373
+ }
15374
+ }
15375
+ );
15376
+ server.tool(
15377
+ "nworks_mail_read",
15378
+ "\uD2B9\uC815 \uBA54\uC77C\uC758 \uC0C1\uC138 \uB0B4\uC6A9\uC744 \uC870\uD68C\uD569\uB2C8\uB2E4 (User OAuth mail \uB610\uB294 mail.read scope \uD544\uC694)",
15379
+ {
15380
+ mailId: external_exports.number().describe("\uBA54\uC77C ID"),
15381
+ userId: external_exports.string().optional().describe("\uB300\uC0C1 \uC0AC\uC6A9\uC790 ID (\uBBF8\uC9C0\uC815 \uC2DC me)")
15382
+ },
15383
+ async ({ mailId, userId }) => {
15384
+ try {
15385
+ const result = await readMail(
15386
+ mailId,
15387
+ userId ?? "me"
15388
+ );
15389
+ const mail = result.mail;
15390
+ return {
15391
+ content: [{ type: "text", text: JSON.stringify({
15392
+ mailId: mail.mailId,
15393
+ from: mail.from,
15394
+ to: mail.to,
15395
+ cc: mail.cc ?? [],
15396
+ subject: mail.subject,
15397
+ body: mail.body,
15398
+ date: mail.receivedTime,
15399
+ attachments: result.attachments?.map((a) => ({
15400
+ id: a.attachmentId,
15401
+ filename: a.filename,
15402
+ contentType: a.contentType,
15403
+ size: a.size
15404
+ })) ?? []
15405
+ }) }]
15406
+ };
15407
+ } catch (err) {
15408
+ const error48 = err;
15409
+ return {
15410
+ content: [{ type: "text", text: `Error: ${error48.message}` }],
15411
+ isError: true
15412
+ };
15413
+ }
15414
+ }
15415
+ );
15126
15416
  server.tool(
15127
15417
  "nworks_whoami",
15128
15418
  "\uD604\uC7AC \uC778\uC99D\uB41C NAVER WORKS \uACC4\uC815 \uC815\uBCF4\uB97C \uD655\uC778\uD569\uB2C8\uB2E4",
@@ -15164,7 +15454,7 @@ async function startMcpServer() {
15164
15454
  }
15165
15455
 
15166
15456
  // src/commands/mcp-cmd.ts
15167
- var mcpCommand = new Command8("mcp").description("Start MCP server (stdio transport)").option("--list-tools", "List available MCP tools").action(async (opts) => {
15457
+ var mcpCommand = new Command9("mcp").description("Start MCP server (stdio transport)").option("--list-tools", "List available MCP tools").action(async (opts) => {
15168
15458
  if (opts.listTools) {
15169
15459
  console.log("nworks_message_send \u2014 Send message to user or channel");
15170
15460
  console.log("nworks_message_members \u2014 List channel members");
@@ -15179,7 +15469,7 @@ var mcpCommand = new Command8("mcp").description("Start MCP server (stdio transp
15179
15469
  // src/index.ts
15180
15470
  var require2 = createRequire(import.meta.url);
15181
15471
  var { version: version2 } = require2("../package.json");
15182
- var program = new Command9().name("nworks").description("NAVER WORKS CLI \u2014 built for humans and AI agents").version(version2).option("--json", "Always output JSON").option("-v, --verbose", "Debug logging").option("--dry-run", "Print request without calling API").option("-p, --profile <name>", "Profile name", "default");
15472
+ var program = new Command10().name("nworks").description("NAVER WORKS CLI \u2014 built for humans and AI agents").version(version2).option("--json", "Always output JSON").option("-v, --verbose", "Debug logging").option("--dry-run", "Print request without calling API").option("-p, --profile <name>", "Profile name", "default");
15183
15473
  program.addCommand(loginCommand);
15184
15474
  program.addCommand(logoutCommand);
15185
15475
  program.addCommand(whoamiCommand);
@@ -15187,6 +15477,7 @@ program.addCommand(messageCommand);
15187
15477
  program.addCommand(directoryCommand);
15188
15478
  program.addCommand(calendarCommand);
15189
15479
  program.addCommand(driveCommand);
15480
+ program.addCommand(mailCommand);
15190
15481
  program.addCommand(mcpCommand);
15191
15482
  program.parse();
15192
15483
  //# sourceMappingURL=index.js.map