@noti-bot/sdk 0.7.0 → 0.9.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
@@ -1,6 +1,6 @@
1
1
  # @noti-bot/sdk
2
2
 
3
- NotiBot용 서버 측 TypeScript SDK입니다. 허브 주소는 `https://api.notibot.xyz`, 서비스 API 키는 콘솔(`https://notibot.xyz`) 개발자 메뉴에서 발급합니다.
3
+ NotiBot용 서버 측 TypeScript SDK입니다. 허브 주소는 `https://api.notibot.xyz`, API 키(`nb_live_…` / `nb_test_…`)는 콘솔(`https://notibot.xyz`) API 키 화면에서 워크스페이스 단위로 발급합니다. 키 하나로 그 워크스페이스의 연결된 톡방 전체에 보낼 수 있고, 서비스·바인딩은 필요 없습니다.
4
4
 
5
5
  ```sh
6
6
  npm install @noti-bot/sdk
@@ -23,11 +23,20 @@ const result = await kakao.sendMessage({
23
23
  });
24
24
  ```
25
25
 
26
- Node.js 20 이상, ESM을 지원합니다. 서비스 키는 브라우저 번들에 넣지 마세요. SDK용 서비스 키와 개인 MCP 토큰은 별도입니다.
26
+ Node.js 20 이상, ESM을 지원합니다. API 키는 브라우저 번들에 넣지 마세요. SDK용 API 키(`nb_live_`/`nb_test_`)와 개인 MCP 토큰(`nbp_`)은 별도이며, 생성자는 `nb_live_`/`nb_test_`로 시작하지 않는 키를 `TypeError`로 거절합니다.
27
27
 
28
- `listRooms()`에서 방의 `id`, `slug`, `canReply`를 확인합니다. `roomId` 대신 `roomSlug: 'deploy-alerts'`도 사용할 수 있습니다. slug는 워크스페이스 안에서 고유하며 변경 시 이전 주소는 사용할 수 없습니다. 고정 ID 연동은 slug 변경 후에도 유지됩니다. 두 방식 모두 해당 API 키의 서비스에 연결된 방만 허용합니다.
28
+ `listRooms()`에서 방의 `id`, `slug`, `canReply`를 확인합니다. `roomId` 대신 `roomSlug: 'deploy-alerts'`도 사용할 수 있습니다. slug는 워크스페이스 안에서 고유하며 변경 시 이전 주소는 사용할 수 없습니다. 고정 ID 연동은 slug 변경 후에도 유지됩니다. 두 방식 모두 해당 API 키의 워크스페이스에 속한 active 방만 허용하며, 그 밖의 방은 `404 room_not_found`입니다.
29
29
 
30
- `queued: true`는 접수이며 실제 전달 성공이 아닙니다. 서버는 서비스별 `requestId`로 중복을 방지합니다. 같은 논리적 발송에는 같은 ID를 사용하세요. **SDK는 POST 또는 GET을 자동 재시도하지 않습니다.** 타임아웃은 이미 접수된 요청일 수 있으므로 새 ID로 재시도하면 중복 발송됩니다. `NotiBotTransportError.requestId`로 요청을 식별하고 대시보드 로그를 확인하세요.
30
+ `queued: true`는 접수이며 실제 전달 성공이 아닙니다. 서버는 API 키별 `requestId`로 중복을 방지합니다. 같은 논리적 발송에는 같은 ID를 사용하세요. **SDK는 POST 또는 GET을 자동 재시도하지 않습니다.** 타임아웃은 이미 접수된 요청일 수 있으므로 새 ID로 재시도하면 중복 발송됩니다. `NotiBotTransportError.requestId`로 요청을 식별하고 대시보드 로그를 확인하세요.
31
+
32
+ ## 전달 결과 확인
33
+
34
+ ```ts
35
+ const r = await kakao.getMessage('deploy:release-2026-10-10');
36
+ // r.status: 'queued' | 'sent' | 'failed' | 'expired' | 'duplicate', r.sent: true | false | null, r.error
37
+ ```
38
+
39
+ 이 API 키로 보낸 `requestId`만 조회됩니다(`messages:send` 필요). 없거나 다른 키가 보낸 ID면 `404 message_not_found`. `failed` + `error: 'delivery_unknown'`은 폰이 가져갔지만 결과를 못 받은 상태라 실제로 갔을 수 있습니다. 중복이 괜찮을 때만 **새** `requestId`로 다시 보내세요.
31
40
 
32
41
  ## 멘션
33
42
 
@@ -97,6 +106,11 @@ try {
97
106
  - 각 메서드의 두 번째 인자에 `{ signal }`을 넣어 취소할 수 있습니다.
98
107
  - `fetch`와 `timeoutMs`(기본 10초)를 생성자에서 주입할 수 있습니다.
99
108
 
109
+ ## 변경 이력
110
+
111
+ - **0.9.0** — `getMessage(requestId)`: 보낸 메시지의 전달 결과(`GET /v1/messages/{requestId}`).
112
+ - **0.8.0** — 워크스페이스 API 키(`nb_live_`/`nb_test_`). `kb_` 키는 더 이상 동작하지 않음. 콘솔에서 새로 발급해 교체하세요. `room_not_bound` 대신 `404 room_not_found`.
113
+
100
114
  ## 릴리스
101
115
 
102
116
  ```sh
@@ -108,15 +122,15 @@ pnpm --filter @noti-bot/sdk pack --pack-destination /tmp/notibot-sdk-release
108
122
 
109
123
  ## 키 권한
110
124
 
111
- 대시보드에서 키 이름과 허용 작업을 선택합니다. `listRooms()`는 `rooms:read`, `sendMessage()`는 `messages:send`가 필요하며 부족하면 `403 insufficient_scope`가 반환됩니다. 키 권한은 서비스에 연결된 방의 범위를 넓히지 않습니다. 기존 키는 두 권한을 유지합니다. 권한을 바꾸려면 새 키를 발급하고 연동을 교체한 뒤 이전 키를 폐기하세요.
125
+ 대시보드에서 키 이름과 허용 작업을 선택합니다. `listRooms()`는 `rooms:read`, `sendMessage()`는 `messages:send`가 필요하며 부족하면 `403 insufficient_scope`가 반환됩니다. 키 권한은 워크스페이스의 방 범위를 넓히지 않습니다. 권한을 바꾸려면 새 키를 발급하고 연동을 교체한 뒤 이전 키를 폐기하세요.
112
126
 
113
127
  ## 실제 발송 없는 테스트 키
114
128
 
115
- 대시보드에서 키 환경을 **테스트**로 선택하세요. 같은 SDK·API 주소를 사용하며 서버가 키에 저장된 환경을 판별합니다. 클라이언트 요청으로 운영 키로 전환할 수 없습니다. 성공 응답은 HTTP 200, `test: true`, `queued: false`입니다. 입력값·권한·활성 방 연결을 검증하지만 폰 전달, 운영 발송 제한, 월 한도는 검증하지 않습니다. 테스트는 발송 큐·메시지 로그·과금 사용량을 생성하지 않으며 서비스당 분당 60회로 제한됩니다. 실제 방 목록과 연결 설정을 사용하는 검증 모드이며 별도 데이터 샌드박스는 아닙니다.
129
+ 대시보드에서 키 환경을 **테스트**로 선택하세요. 같은 SDK·API 주소를 사용하며 서버가 키에 저장된 환경을 판별합니다. 클라이언트 요청으로 운영 키로 전환할 수 없습니다. 성공 응답은 HTTP 200, `test: true`, `queued: false`입니다. 입력값·권한·워크스페이스의 활성 방을 검증하지만 폰 전달, 운영 발송 제한, 월 한도는 검증하지 않습니다. 테스트는 발송 큐·메시지 로그·과금 사용량을 생성하지 않으며 키당 분당 60회로 제한됩니다. 실제 방 목록과 연결 설정을 사용하는 검증 모드이며 별도 데이터 샌드박스는 아닙니다.
116
130
 
117
131
  테스트 요청 ID는 저장하지 않습니다. 같은 ID의 테스트를 반복해도 매번 검증하며, 이후 운영 키에서 같은 ID로 실제 발송할 수 있습니다. 운영 전환은 운영 키를 새로 발급해 서버 환경변수를 교체하세요. 기존 키는 운영 키로 유지됩니다.
118
132
 
119
- 동일 서비스에서 이미 접수한 `requestId`의 방 ID 또는 본문을 바꾸면 `409 idempotency_conflict`를 반환합니다. 동일한 방·본문은 중복으로 처리하며 추가 큐/사용량을 만들지 않습니다. slug/방 표시명 변경은 고정 방 ID가 같으면 충돌로 보지 않습니다. 기존 기록 중 본문 검증값이 없는 건은 방 변경만 검출하고 재발송하지 않습니다. 검증값은 서버 비밀키로 보호하므로 비밀키 교체 후 이전 요청의 재시도는 충돌할 수 있습니다.
133
+ 동일 API 키로 이미 접수한 `requestId`의 방 ID 또는 본문을 바꾸면 `409 idempotency_conflict`를 반환합니다. 동일한 방·본문은 중복으로 처리하며 추가 큐/사용량을 만들지 않습니다. slug/방 표시명 변경은 고정 방 ID가 같으면 충돌로 보지 않습니다. 기존 기록 중 본문 검증값이 없는 건은 방 변경만 검출하고 재발송하지 않습니다. 검증값은 서버 비밀키로 보호하므로 비밀키 교체 후 이전 요청의 재시도는 충돌할 수 있습니다.
120
134
 
121
135
  ### Iris migration
122
136
 
package/dist/errors.d.ts CHANGED
@@ -19,7 +19,7 @@
19
19
  */
20
20
  export declare const NOTIBOT_ERROR_BRAND: unique symbol;
21
21
  /** 허브가 돌려주는 오류 코드. 서버 라우트(`src/outbound/routes.ts`)가 정본이다. */
22
- export declare const NOTIBOT_ERROR_CODES: readonly ["validation_error", "invalid_room_slug", "unauthorized", "plan_message_limit", "insufficient_scope", "room_not_bound", "room_inactive", "idempotency_conflict", "rate_limited", "kill_switch", "queue_full", "request_failed"];
22
+ export declare const NOTIBOT_ERROR_CODES: readonly ["validation_error", "invalid_room_slug", "unauthorized", "plan_message_limit", "insufficient_scope", "room_not_found", "message_not_found", "room_inactive", "idempotency_conflict", "rate_limited", "kill_switch", "queue_full", "request_failed"];
23
23
  export type NotiBotErrorCode = (typeof NOTIBOT_ERROR_CODES)[number];
24
24
  /**
25
25
  * 알려진 코드는 자동완성으로 뜨되, 허브가 새 코드를 추가해도 타입이 깨지지 않는다.
package/dist/errors.js CHANGED
@@ -25,7 +25,8 @@ export const NOTIBOT_ERROR_CODES = [
25
25
  "unauthorized",
26
26
  "plan_message_limit",
27
27
  "insufficient_scope",
28
- "room_not_bound",
28
+ "room_not_found",
29
+ "message_not_found",
29
30
  "room_inactive",
30
31
  "idempotency_conflict",
31
32
  "rate_limited",
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export declare function mention(kakaoUserId: string): string;
9
9
  export interface NotiBotOptions {
10
10
  /** Hub origin, e.g. https://hub.example.com. Never use the phone's private endpoint. */
11
11
  baseUrl: string;
12
- /** Service API key issued from the dashboard. Keep on your server. */
12
+ /** Workspace API key (nb_live_… / nb_test_…) issued from the console. Keep on your server. */
13
13
  apiKey: string;
14
14
  timeoutMs?: number;
15
15
  fetch?: typeof globalThis.fetch;
@@ -47,6 +47,22 @@ export interface SendMessageResult {
47
47
  request_id: string;
48
48
  room?: string;
49
49
  }
50
+ /** Hub-side delivery state of one sent message. */
51
+ export type MessageStatus = "queued" | "sent" | "failed" | "expired" | "duplicate";
52
+ /** Delivery result for a `requestId` sent with this API key. */
53
+ export interface MessageResult {
54
+ request_id: string;
55
+ room: string;
56
+ status: MessageStatus;
57
+ /** true: the phone handed it to KakaoTalk. false: rejected. null: still queued, or unknown. */
58
+ sent: boolean | null;
59
+ /** e.g. `delivery_unknown`, `no_session`, `expired_in_queue`. */
60
+ error: string | null;
61
+ /** Accepted at (epoch ms). */
62
+ at: number;
63
+ /** Phone result at (epoch ms), or null. */
64
+ sent_at: number | null;
65
+ }
50
66
  export interface Room {
51
67
  id?: string;
52
68
  slug?: string | null;
@@ -106,8 +122,15 @@ export declare class NotiBot {
106
122
  private readonly fetchFn;
107
123
  constructor(options: NotiBotOptions);
108
124
  sendMessage(input: SendMessageInput, options?: RequestOptions): Promise<SendMessageResult>;
125
+ /**
126
+ * Delivery result of a message this API key sent. Requires the `messages:send` scope.
127
+ * Rejects with `message_not_found` for unknown IDs, IDs of other keys, and test-key sends.
128
+ * `failed` + `delivery_unknown` means the phone may or may not have sent it: retry with a
129
+ * new requestId only when a duplicate is acceptable.
130
+ */
131
+ getMessage(requestId: string, options?: RequestOptions): Promise<MessageResult>;
109
132
  listRooms(options?: RequestOptions): Promise<Room[]>;
110
- /** Members of a room bound to this service. Requires the `rooms:read` scope. */
133
+ /** Members of a room in this workspace. Requires the `rooms:read` scope. */
111
134
  listRoomMembers(room: {
112
135
  roomId: string;
113
136
  } | {
package/dist/index.js CHANGED
@@ -26,8 +26,8 @@ export class NotiBot {
26
26
  url.search ||
27
27
  url.hash)
28
28
  throw new TypeError("baseUrl must be an HTTP(S) URL without credentials, query or fragment.");
29
- if (!options.apiKey.trim() || /[\r\n]/.test(options.apiKey))
30
- throw new TypeError("A non-empty service API key is required.");
29
+ if (!/^nb_(live|test)_[^\s]+$/.test(options.apiKey))
30
+ throw new TypeError("A NotiBot API key (nb_live_… or nb_test_…) is required.");
31
31
  this.baseUrl = url.toString().replace(/\/+$/, "");
32
32
  this.apiKey = options.apiKey;
33
33
  this.timeoutMs = options.timeoutMs ?? 10000;
@@ -69,6 +69,27 @@ export class NotiBot {
69
69
  throw new NotiBotProtocolError(requestId);
70
70
  return data;
71
71
  }
72
+ /**
73
+ * Delivery result of a message this API key sent. Requires the `messages:send` scope.
74
+ * Rejects with `message_not_found` for unknown IDs, IDs of other keys, and test-key sends.
75
+ * `failed` + `delivery_unknown` means the phone may or may not have sent it: retry with a
76
+ * new requestId only when a duplicate is acceptable.
77
+ */
78
+ async getMessage(requestId, options = {}) {
79
+ if (!requestId.trim() || requestId.length > 128)
80
+ throw new TypeError("requestId must contain 1 to 128 characters.");
81
+ const data = await this.request(`/v1/messages/${encodeURIComponent(requestId)}`, "GET", undefined, options.signal, requestId);
82
+ if (!object(data) ||
83
+ data.request_id !== requestId ||
84
+ typeof data.room !== "string" ||
85
+ !["queued", "sent", "failed", "expired", "duplicate"].includes(String(data.status)) ||
86
+ !(data.sent === null || typeof data.sent === "boolean") ||
87
+ !(data.error === null || typeof data.error === "string") ||
88
+ typeof data.at !== "number" ||
89
+ !(data.sent_at === null || typeof data.sent_at === "number"))
90
+ throw new NotiBotProtocolError(requestId);
91
+ return data;
92
+ }
72
93
  async listRooms(options = {}) {
73
94
  const data = await this.request("/v1/rooms", "GET", undefined, options.signal);
74
95
  if (!object(data) ||
@@ -82,7 +103,7 @@ export class NotiBot {
82
103
  throw new NotiBotProtocolError();
83
104
  return data.rooms;
84
105
  }
85
- /** Members of a room bound to this service. Requires the `rooms:read` scope. */
106
+ /** Members of a room in this workspace. Requires the `rooms:read` scope. */
86
107
  async listRoomMembers(room, options = {}) {
87
108
  return (await this.getRoomMembers(room, options)).members;
88
109
  }
@@ -127,7 +148,7 @@ export class NotiBot {
127
148
  },
128
149
  ...(body === undefined ? {} : { body: JSON.stringify(body) }),
129
150
  signal: combined,
130
- // Service keys must never be forwarded to a redirected origin.
151
+ // API keys must never be forwarded to a redirected origin.
131
152
  redirect: "error",
132
153
  });
133
154
  data = await response.json().catch(() => null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noti-bot/sdk",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Typed server-side client for the NotiBot API",
5
5
  "license": "MIT",
6
6
  "author": "Jeongmin Lee",