@noti-bot/sdk 0.7.0 → 0.8.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 +11 -7
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @noti-bot/sdk
|
|
2
2
|
|
|
3
|
-
NotiBot용 서버 측 TypeScript SDK입니다. 허브 주소는 `https://api.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,11 @@ const result = await kakao.sendMessage({
|
|
|
23
23
|
});
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
Node.js 20 이상, ESM을 지원합니다.
|
|
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`는 접수이며 실제 전달 성공이 아닙니다. 서버는
|
|
30
|
+
`queued: true`는 접수이며 실제 전달 성공이 아닙니다. 서버는 API 키별 `requestId`로 중복을 방지합니다. 같은 논리적 발송에는 같은 ID를 사용하세요. **SDK는 POST 또는 GET을 자동 재시도하지 않습니다.** 타임아웃은 이미 접수된 요청일 수 있으므로 새 ID로 재시도하면 중복 발송됩니다. `NotiBotTransportError.requestId`로 요청을 식별하고 대시보드 로그를 확인하세요.
|
|
31
31
|
|
|
32
32
|
## 멘션
|
|
33
33
|
|
|
@@ -97,6 +97,10 @@ try {
|
|
|
97
97
|
- 각 메서드의 두 번째 인자에 `{ signal }`을 넣어 취소할 수 있습니다.
|
|
98
98
|
- `fetch`와 `timeoutMs`(기본 10초)를 생성자에서 주입할 수 있습니다.
|
|
99
99
|
|
|
100
|
+
## 변경 이력
|
|
101
|
+
|
|
102
|
+
- **0.8.0** — 워크스페이스 API 키(`nb_live_`/`nb_test_`). `kb_` 키는 더 이상 동작하지 않음. 콘솔에서 새로 발급해 교체하세요. `room_not_bound` 대신 `404 room_not_found`.
|
|
103
|
+
|
|
100
104
|
## 릴리스
|
|
101
105
|
|
|
102
106
|
```sh
|
|
@@ -108,15 +112,15 @@ pnpm --filter @noti-bot/sdk pack --pack-destination /tmp/notibot-sdk-release
|
|
|
108
112
|
|
|
109
113
|
## 키 권한
|
|
110
114
|
|
|
111
|
-
대시보드에서 키 이름과 허용 작업을 선택합니다. `listRooms()`는 `rooms:read`, `sendMessage()`는 `messages:send`가 필요하며 부족하면 `403 insufficient_scope`가 반환됩니다. 키 권한은
|
|
115
|
+
대시보드에서 키 이름과 허용 작업을 선택합니다. `listRooms()`는 `rooms:read`, `sendMessage()`는 `messages:send`가 필요하며 부족하면 `403 insufficient_scope`가 반환됩니다. 키 권한은 워크스페이스의 방 범위를 넓히지 않습니다. 권한을 바꾸려면 새 키를 발급하고 연동을 교체한 뒤 이전 키를 폐기하세요.
|
|
112
116
|
|
|
113
117
|
## 실제 발송 없는 테스트 키
|
|
114
118
|
|
|
115
|
-
대시보드에서 키 환경을 **테스트**로 선택하세요. 같은 SDK·API 주소를 사용하며 서버가 키에 저장된 환경을 판별합니다. 클라이언트 요청으로 운영 키로 전환할 수 없습니다. 성공 응답은 HTTP 200, `test: true`, `queued: false`입니다.
|
|
119
|
+
대시보드에서 키 환경을 **테스트**로 선택하세요. 같은 SDK·API 주소를 사용하며 서버가 키에 저장된 환경을 판별합니다. 클라이언트 요청으로 운영 키로 전환할 수 없습니다. 성공 응답은 HTTP 200, `test: true`, `queued: false`입니다. 입력값·권한·워크스페이스의 활성 방을 검증하지만 폰 전달, 운영 발송 제한, 월 한도는 검증하지 않습니다. 테스트는 발송 큐·메시지 로그·과금 사용량을 생성하지 않으며 키당 분당 60회로 제한됩니다. 실제 방 목록과 연결 설정을 사용하는 검증 모드이며 별도 데이터 샌드박스는 아닙니다.
|
|
116
120
|
|
|
117
121
|
테스트 요청 ID는 저장하지 않습니다. 같은 ID의 테스트를 반복해도 매번 검증하며, 이후 운영 키에서 같은 ID로 실제 발송할 수 있습니다. 운영 전환은 운영 키를 새로 발급해 서버 환경변수를 교체하세요. 기존 키는 운영 키로 유지됩니다.
|
|
118
122
|
|
|
119
|
-
동일
|
|
123
|
+
동일 API 키로 이미 접수한 `requestId`의 방 ID 또는 본문을 바꾸면 `409 idempotency_conflict`를 반환합니다. 동일한 방·본문은 중복으로 처리하며 추가 큐/사용량을 만들지 않습니다. slug/방 표시명 변경은 고정 방 ID가 같으면 충돌로 보지 않습니다. 기존 기록 중 본문 검증값이 없는 건은 방 변경만 검출하고 재발송하지 않습니다. 검증값은 서버 비밀키로 보호하므로 비밀키 교체 후 이전 요청의 재시도는 충돌할 수 있습니다.
|
|
120
124
|
|
|
121
125
|
### Iris migration
|
|
122
126
|
|
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", "
|
|
22
|
+
export declare const NOTIBOT_ERROR_CODES: readonly ["validation_error", "invalid_room_slug", "unauthorized", "plan_message_limit", "insufficient_scope", "room_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
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
|
-
/**
|
|
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;
|
|
@@ -107,7 +107,7 @@ export declare class NotiBot {
|
|
|
107
107
|
constructor(options: NotiBotOptions);
|
|
108
108
|
sendMessage(input: SendMessageInput, options?: RequestOptions): Promise<SendMessageResult>;
|
|
109
109
|
listRooms(options?: RequestOptions): Promise<Room[]>;
|
|
110
|
-
/** Members of a room
|
|
110
|
+
/** Members of a room in this workspace. Requires the `rooms:read` scope. */
|
|
111
111
|
listRoomMembers(room: {
|
|
112
112
|
roomId: string;
|
|
113
113
|
} | {
|
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 (
|
|
30
|
-
throw new TypeError("A
|
|
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;
|
|
@@ -82,7 +82,7 @@ export class NotiBot {
|
|
|
82
82
|
throw new NotiBotProtocolError();
|
|
83
83
|
return data.rooms;
|
|
84
84
|
}
|
|
85
|
-
/** Members of a room
|
|
85
|
+
/** Members of a room in this workspace. Requires the `rooms:read` scope. */
|
|
86
86
|
async listRoomMembers(room, options = {}) {
|
|
87
87
|
return (await this.getRoomMembers(room, options)).members;
|
|
88
88
|
}
|
|
@@ -127,7 +127,7 @@ export class NotiBot {
|
|
|
127
127
|
},
|
|
128
128
|
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
129
129
|
signal: combined,
|
|
130
|
-
//
|
|
130
|
+
// API keys must never be forwarded to a redirected origin.
|
|
131
131
|
redirect: "error",
|
|
132
132
|
});
|
|
133
133
|
data = await response.json().catch(() => null);
|