@reopt-ai/brandapp-sdk 3.1.0 → 3.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/CHANGELOG.md +147 -0
- package/README.md +39 -14
- package/dist/abort--nOBFN4M.js +50 -0
- package/dist/ai/index.d.ts +2 -314
- package/dist/ai/index.js +3 -7
- package/dist/ai-provider/index.d.ts +79 -163
- package/dist/ai-provider/index.js +752 -671
- package/dist/auth/index.d.ts +27 -27
- package/dist/auth/index.js +41 -33
- package/dist/better-auth/client.d.ts +6 -5
- package/dist/better-auth/client.js +28 -5
- package/dist/better-auth/index.d.ts +19 -17
- package/dist/better-auth/index.js +180 -133
- package/dist/client-B1q5P8rv.js +83 -0
- package/dist/client-B9QHVhdM.js +77 -0
- package/dist/client-BGGd_cpV.d.ts +103 -0
- package/dist/client-BJcy1V1a.js +140 -0
- package/dist/client-Beivhucf.js +55 -0
- package/dist/client-BruP5_nU.d.ts +147 -0
- package/dist/client-D-yNxNfk.js +28 -0
- package/dist/client-D0eBxh8j.d.ts +284 -0
- package/dist/client-D3RHHUUW.d.ts +207 -0
- package/dist/client-D6gs61w8.d.ts +53 -0
- package/dist/client-DBnK7ooQ.js +86 -0
- package/dist/client-DDw5yz_h.d.ts +53 -0
- package/dist/client-DPmoKuR9.js +305 -0
- package/dist/client-DsdakibF.js +503 -0
- package/dist/client-Dxg8_DIH.d.ts +71 -0
- package/dist/client-EbhUIhHq.js +53 -0
- package/dist/client-lk6wBu_0.d.ts +48 -0
- package/dist/client-p49ol9pg.d.ts +124 -0
- package/dist/cms/index.d.ts +52 -108
- package/dist/cms/index.js +105 -84
- package/dist/config-CRytOPPl.d.ts +394 -0
- package/dist/config-Cw0a3-C8.js +487 -0
- package/dist/dev/index.d.ts +2 -509
- package/dist/dev/index.js +2740 -2873
- package/dist/eav/coerce.d.ts +3 -1
- package/dist/eav/coerce.js +72 -46
- package/dist/eav/index.d.ts +72 -100
- package/dist/eav/index.js +158 -125
- package/dist/eav/migrate.d.ts +112 -109
- package/dist/eav/migrate.js +230 -196
- package/dist/eav/schema.d.ts +111 -150
- package/dist/eav/schema.js +624 -603
- package/dist/encoding-Bwfm3iaE.js +21 -0
- package/dist/{errors-DIAS8Rsl.d.ts → errors-CRCcErNC.d.ts} +55 -53
- package/dist/feedback/index.d.ts +2 -132
- package/dist/feedback/index.js +3 -5
- package/dist/files/index.d.ts +14 -14
- package/dist/files/index.js +41 -24
- package/dist/http-client-QKUvvirs.js +386 -0
- package/dist/index-DrVaKfhs.d.ts +456 -0
- package/dist/index-Z6OGcurJ.d.ts +169 -0
- package/dist/index.d.ts +6 -221
- package/dist/index.js +119 -70
- package/dist/logout/index.d.ts +109 -0
- package/dist/logout/index.js +264 -0
- package/dist/plans/index.d.ts +2 -236
- package/dist/plans/index.js +3 -5
- package/dist/push/index.d.ts +2 -79
- package/dist/push/index.js +3 -5
- package/dist/query-BvbCiGWb.js +35 -0
- package/dist/react/hooks.d.ts +97 -95
- package/dist/react/hooks.js +742 -356
- package/dist/sse-parser-FMjxM7sY.js +86 -0
- package/dist/terms/index.d.ts +3 -79
- package/dist/terms/index.js +3 -5
- package/dist/testing/index.d.ts +52 -104
- package/dist/testing/index.js +94 -72
- package/dist/types-B-SMkH6s.d.ts +26 -0
- package/dist/types-BXDcoJHG.d.ts +131 -0
- package/dist/types-BrghN2rJ.d.ts +105 -0
- package/dist/types-DjDRszNj.js +11 -0
- package/dist/webhooks/index.d.ts +77 -47
- package/dist/webhooks/index.js +150 -127
- package/docs/api-reference.md +179 -2
- package/docs/dev-server.md +19 -18
- package/docs/errors.md +72 -15
- package/docs/logout.md +166 -0
- package/package.json +10 -5
- package/dist/chunk-2Q654O63.js +0 -350
- package/dist/chunk-F7BXBTZI.js +0 -54
- package/dist/chunk-IJOXTBIE.js +0 -599
- package/dist/chunk-JWXUVQRC.js +0 -157
- package/dist/chunk-L4DHB36G.js +0 -75
- package/dist/chunk-MRQY45U5.js +0 -465
- package/dist/chunk-N5JVE4WX.js +0 -449
- package/dist/chunk-O3PUWIDJ.js +0 -105
- package/dist/chunk-POLKEOYH.js +0 -63
- package/dist/chunk-R5CCGDUH.js +0 -49
- package/dist/chunk-RBHP7IZF.js +0 -96
- package/dist/chunk-REIKXSMY.js +0 -7
- package/dist/chunk-T7YTITRJ.js +0 -112
- package/dist/chunk-V73GORO3.js +0 -81
- package/dist/chunk-VRNBYSWU.js +0 -32
- package/dist/client-BkcO-0C2.d.ts +0 -216
- package/dist/client-CN5_tNOC.d.ts +0 -147
- package/dist/client-DttyeM_h.d.ts +0 -102
- package/dist/config-CtxyJsDR.d.ts +0 -397
- package/dist/typed-client-BxOVIiMU.d.ts +0 -40
- package/dist/types-6E3ZLL9X.d.ts +0 -24
- package/dist/types-DskYLVb8.d.ts +0 -104
- package/dist/types-ckmDDW3N.d.ts +0 -129
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,153 @@ All notable changes to `@reopt-ai/brandapp-sdk` are documented here.
|
|
|
5
5
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
6
|
This project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
7
|
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [3.4.0] — 2026-07-27
|
|
11
|
+
|
|
12
|
+
구독 생애주기를 **서버에서** 따라갈 수 있게 됐다 — 웹훅 4종과 실 결제 해지 결과가
|
|
13
|
+
추가되고, 피드백이 양방향 스레드가 됐다. 전부 backward-compatible(minor).
|
|
14
|
+
|
|
15
|
+
### Added — 구독 생애주기 웹훅 (`@reopt-ai/brandapp-sdk/webhooks`)
|
|
16
|
+
|
|
17
|
+
지금까지 웹훅 이벤트는 contact/workflow 5종뿐이라 브랜드앱 소비자는 구독 상태 변화를
|
|
18
|
+
**서버에서 알 방법이 없었다**. 체크아웃 복귀 URL이나 `getMyPlan` 폴링에만 의존했고,
|
|
19
|
+
사용자 행동 없이 일어나는 변화(정기결제 실패, 카드 만료, PG측 해지)는 폴링해야만
|
|
20
|
+
발견됐다.
|
|
21
|
+
|
|
22
|
+
- **`WebhookEventType`에 4종 추가** — `subscriptionActivated`(체크아웃 완료 → 엔타이틀먼트
|
|
23
|
+
부여) / `subscriptionRenewed`(정기결제 성공 → `accessUntil` 연장) /
|
|
24
|
+
`subscriptionCanceled`(해지 — `accessUntil`까지는 접근 유지) /
|
|
25
|
+
`subscriptionPaymentFailed`(past due → 독촉·유예 안내).
|
|
26
|
+
- **`SubscriptionWebhookData`** — 4종의 공통 페이로드
|
|
27
|
+
(`brandappId`, `brandappCustomerId`, `customerId`, `planId`, `planName`, `provider`,
|
|
28
|
+
`accessUntil`).
|
|
29
|
+
|
|
30
|
+
웹훅은 **워크스페이스 단위**로 등록되므로 한 워크스페이스에 브랜드앱이 여럿이면 같은
|
|
31
|
+
엔드포인트로 전부 도착한다 — `data.brandappId`로 반드시 필터링할 것. 플랫폼 쪽 발행은
|
|
32
|
+
결제 상태 커밋과 같은 트랜잭션(transactional outbox)이라 상태와 알림이 어긋나지 않는다.
|
|
33
|
+
|
|
34
|
+
### Added — 실 결제 해지 결과 (`sdk.plans.cancel`)
|
|
35
|
+
|
|
36
|
+
`CancelSubscriptionResult`에 세 필드 추가(모두 optional — 구버전 서버는 내려주지 않는다):
|
|
37
|
+
|
|
38
|
+
- **`provider`** — `sandbox` | `paddle` | `toss` | `apple` | `google`. 안내 문구를 결제
|
|
39
|
+
수단별로 가를 때.
|
|
40
|
+
- **`accessUntil`** — 이 시각(ISO-8601)까지는 계속 이용 가능. `null`이면 무기한 플랜.
|
|
41
|
+
- **`providerCanceled`** — 결제사 쪽 해지까지 성공했는지. `false`면 로컬 구독은 확실히
|
|
42
|
+
종료됐지만(다음 청구 없음) 결제사 대시보드에 잔재가 남아 운영자 확인이 필요할 수 있다.
|
|
43
|
+
|
|
44
|
+
`cancel`은 이제 **sandbox 전용이 아니다** — 실 결제(Paddle/Toss)와 IAP 구독도 같은
|
|
45
|
+
호출로 해지된다(플랫폼 측 변경, SDK 호출 형태는 동일). 로컬 확정 먼저, 결제사 해지는
|
|
46
|
+
best-effort. IAP는 스토어에서 해지되므로 원격 호출 없음.
|
|
47
|
+
|
|
48
|
+
### Changed
|
|
49
|
+
|
|
50
|
+
- **문서 — 실 Paddle 체크아웃 지원 반영.** `createCheckout`의 `LIVE_MODE_UNSUPPORTED`(409)는
|
|
51
|
+
이제 **Toss** 실 결제 + 유료 플랜에만 해당한다. Paddle 브랜드앱은 같은 호출로 Paddle
|
|
52
|
+
호스티드 결제 페이지 URL을 받는다(0원 플랜은 live 모드에서도 sandbox 세션 흐름). 코드
|
|
53
|
+
동작은 이전 릴리스에서 이미 그랬고, 이번엔 JSDoc·`docs/api-reference.md`를 정합화했다.
|
|
54
|
+
|
|
55
|
+
### Added — Feedback 양방향 스레드 (`sdk.feedback`)
|
|
56
|
+
|
|
57
|
+
고객이 운영팀 답변을 **평가하고 되받아칠 수 있게** 됐다. 지금까지 피드백은 한 번의
|
|
58
|
+
왕복으로 끝났고 — 답변이 빗나가면 고객은 새 피드백을 다시 내야 했으며 운영 큐에는
|
|
59
|
+
맥락이 끊긴 별개 항목이 쌓였다. 전부 backward-compatible(minor).
|
|
60
|
+
|
|
61
|
+
- **`sdk.feedback.me.reply(feedbackId, content, accessToken)`** — 자기 피드백 스레드에
|
|
62
|
+
답글. 이미 응답된 피드백은 새 상태 `reopened`로 전이하고 워크스페이스에 알림이 간다.
|
|
63
|
+
반환값 `feedbackStatus`로 재오픈 여부를 바로 알 수 있다.
|
|
64
|
+
- **`sdk.feedback.me.rateReply(feedbackId, replyId, helpful, accessToken)`** — 운영팀
|
|
65
|
+
답변의 유용성 평가(`true`/`false`/`null`로 취소). 평가만으로는 재오픈되지 않는다.
|
|
66
|
+
- **`FeedbackReply.author`** (`"staff" | "customer"`) — 스레드가 양방향이 되면서 각
|
|
67
|
+
메시지의 방향이 노출된다. 운영자 신원은 계속 비노출.
|
|
68
|
+
- **`FeedbackReply.helpful`** — 고객이 그 답변에 매긴 평가(staff 답변에만, null = 미평가).
|
|
69
|
+
- **`FeedbackStatus`에 `"reopened"` 추가** — 응답 후 고객이 되물어 워크스페이스 차례가
|
|
70
|
+
된 상태. `status` 필터로도 조회 가능.
|
|
71
|
+
|
|
72
|
+
`replyCount`는 **staff 답변 수 그대로**다 — 고객이 자기 답글을 달았다고
|
|
73
|
+
`replyCount > 0`("답변 왔음") 신호가 켜지지 않는다.
|
|
74
|
+
|
|
75
|
+
## [3.3.0] — 2026-07-24
|
|
76
|
+
|
|
77
|
+
리뷰(멀티에이전트 교차검증) 후속 하드닝 — 로그아웃 보안·코어 정확성·AI/React/CMS
|
|
78
|
+
견고성·문서 정합. 전부 backward-compatible(minor). 새 테스트 +33.
|
|
79
|
+
|
|
80
|
+
### Security — OIDC 로그아웃 (`@reopt-ai/brandapp-sdk/logout`)
|
|
81
|
+
|
|
82
|
+
- **JWKS 강제 refetch 스로틀 + in-flight 병합** — 공개(무인증) back-channel 엔드포인트에서
|
|
83
|
+
서명 불일치마다 무제한으로 JWKS를 재조회하던 것을 jwks_uri별 쿨다운(30s)과 동시 요청
|
|
84
|
+
병합으로 상한. 위조 토큰 폭주가 공유 JWKS 엔드포인트로 부하를 반사시키는 벡터 차단.
|
|
85
|
+
초기 캐시 채우기 fetch는 쿨다운에 포함되지 않아 키 로테이션 복구는 단일 검증 내 유지.
|
|
86
|
+
- **discovery/JWKS fetch 타임아웃(5s, fail-closed)** — 느린 IdP가 공개 로그아웃 핸들러를
|
|
87
|
+
붙잡지 못하게 `AbortSignal.timeout` 적용.
|
|
88
|
+
- **인프라 실패와 토큰 검증 실패 분리 (§2.8)** — discovery/JWKS 일시 불가는 새 코드
|
|
89
|
+
`logout_verification_unavailable`로 던지고 핸들러가 **HTTP 503(retryable)** 반환. 잘못된
|
|
90
|
+
토큰만 400. 정상 토큰을 일시 JWKS 장애 때 영구 거부(400)하던 문제 해소.
|
|
91
|
+
|
|
92
|
+
### Security — 코어
|
|
93
|
+
|
|
94
|
+
- **`assertBrowserSafe` Web/Service Worker 감지** — `window` 없이 실행되는 worker에서도
|
|
95
|
+
`clientSecret` 사용을 차단(publicly-served worker JS로의 admin 자격 유출 방지).
|
|
96
|
+
|
|
97
|
+
### Fixed
|
|
98
|
+
|
|
99
|
+
- **에러 `requestId` 유실** — `RateLimitError`/`ServerError`가 재시도 소진 후 `context`(및
|
|
100
|
+
`requestId`)를 실제로 보유하도록 수정(이전엔 임시 객체에 써서 버려짐). 지원 티켓용
|
|
101
|
+
X-Request-Id를 항상 읽을 수 있음.
|
|
102
|
+
- **whitespace 토큰 → `Bearer <whitespace>`** — `createAuthHeader`가 `validateConfig`와 동일한
|
|
103
|
+
`token.trim()` 의미를 따라, 공백뿐인 토큰은 Basic으로 폴백하고 유효 토큰의 주변 공백도 제거.
|
|
104
|
+
- **AI 이미지 2-hop 파손 이미지** — Blob URL이 비-2xx면 오류 페이지 바이트를 base64로 반환하던
|
|
105
|
+
것을 typed provider 에러로 승격(`response.ok` 가드).
|
|
106
|
+
- **AI provider body 전송 무한 대기** — `fetchWithTimeout`이 헤더뿐 아니라 body 전송까지
|
|
107
|
+
타임아웃 창 안에서 커버(헤더 도착 즉시 타이머 해제하던 문제).
|
|
108
|
+
- **React `useEavRecordsInfinite` 캐시 충돌** — finite/infinite 레코드 리스트가 같은 queryKey를
|
|
109
|
+
공유해 shape가 충돌하던 것을, `recordsInfinite` 네임스페이스 분리로 해소. 뮤테이션 무효화는
|
|
110
|
+
길이-3 prefix로 바꿔 쿼리 객체 유무와 무관하게 finite·infinite·count 리스트를 모두 무효화
|
|
111
|
+
(trailing-undefined 키가 필터된 리스트를 못 지우던 잠복 버그 동반 수정).
|
|
112
|
+
- **RSS 피드 XML-불법 제어문자** — `toRssFeed`가 XML 1.0에서 표현 불가한 C0 제어문자를 제거해,
|
|
113
|
+
한 글자로 피드 전체가 not-well-formed가 되던 것 방지(escapeXml·CDATA 양 경로).
|
|
114
|
+
- **cms/files 경로 ID 미인코딩** — `cms.posts.get`/`cms.postGroups.get`/`files.get`/`files.delete`가
|
|
115
|
+
경로 ID를 `encodeURIComponent`로 감싸, `/`·`?`·`#`·`..` 포함 id가 다른 엔드포인트로 새는 것 방지.
|
|
116
|
+
|
|
117
|
+
### Added
|
|
118
|
+
|
|
119
|
+
- **`FetchOptions.idempotent`** — POST/PATCH로 터널링된 read를 per-call로 재시도 대상에 편입
|
|
120
|
+
(client 전역 `retryNonIdempotent` 없이). Better Auth 어댑터의 `findOne`/`findMany`/`count`가
|
|
121
|
+
이를 사용해 인증 hot path의 일시적 5xx를 재시도(뮤테이션은 그대로 비재시도).
|
|
122
|
+
- **Caller-cancel = `CANCELLED`** — 외부 `AbortSignal` 취소가 이제 `TIMEOUT`(408)이 아니라
|
|
123
|
+
`name: "AbortError"`인 `CANCELLED` 에러로 즉시 종료(재시도 소진하지 않음). 내부 타임아웃만
|
|
124
|
+
`TIMEOUT`.
|
|
125
|
+
- **Dev 서버 faithful OIDC mock** — dev 서버가 인메모리 Ed25519 키페어로 실 EdDSA `id_token`을
|
|
126
|
+
서명하고 `/api/auth/jwks`·`/api/auth/oauth2/end-session`을 실제로 마운트. 새
|
|
127
|
+
`dev.mintLogoutToken({ clientId, sessionId, userId })`로 소비자가 back-channel 로그아웃 핸들러를
|
|
128
|
+
dev 서버 대상 end-to-end로 검증 가능. discovery는 서명이 불가한 런타임에선 해당 능력을 광고하지
|
|
129
|
+
않음(reduced-but-coherent).
|
|
130
|
+
|
|
131
|
+
### Changed
|
|
132
|
+
|
|
133
|
+
- 로그아웃 검증 캐시 리셋(`clearLogoutTokenCaches`)이 새 refetch 스로틀 상태도 비운다.
|
|
134
|
+
|
|
135
|
+
## [3.2.0] — 2026-07-24
|
|
136
|
+
|
|
137
|
+
OIDC **Single Logout** 상호운용 — reopt와 외부 앱 사이 세션 종료를 양방향으로 연결한다
|
|
138
|
+
(RFC-0016 세션 표면 스코핑). 새 sub-path `@reopt-ai/brandapp-sdk/logout`. 전부 additive(minor).
|
|
139
|
+
|
|
140
|
+
### Added — `@reopt-ai/brandapp-sdk/logout`
|
|
141
|
+
|
|
142
|
+
- **`createBackchannelLogoutHandler({ onLogout })`** — OIDC Back-Channel Logout 수신 핸들러
|
|
143
|
+
(`Request → Response`). reopt가 IdP 세션 폐기(로그아웃·차단·삭제·기기 종료) 시 보내는
|
|
144
|
+
`logout_token`을 검증하고 `onLogout({ sid, sub })`로 앱의 파생 세션을 종료하게 한다.
|
|
145
|
+
Next.js Route Handler·Hono·Fetch 서버 어디에나 마운트 가능.
|
|
146
|
+
- **`verifyBackchannelLogoutToken(token, opts)`** — HTTP 래퍼 없이 logout_token만 검증
|
|
147
|
+
(커스텀 전송·테스트용). 실패 시 `ReoptSDKError(code: "invalid_logout_token")`.
|
|
148
|
+
- **`buildEndSessionUrl({ idToken, postLogoutRedirectUri, state })`** — RP-Initiated Logout
|
|
149
|
+
URL 조립. 사용자를 reopt `end_session_endpoint`로 보내 IdP 세션(및 전 파생 세션)까지 종료.
|
|
150
|
+
|
|
151
|
+
서명 검증은 **Web Crypto(Ed25519)** — 외부 의존 없음(Node 20+ / Deno / Workers / 최신 브라우저).
|
|
152
|
+
스펙(OIDC Back-Channel Logout 1.0) 전 검증 적용: 서명·iss·aud·iat·events·sid·nonce 금지·alg 고정.
|
|
153
|
+
상세: [docs/logout.md](./docs/logout.md).
|
|
154
|
+
|
|
8
155
|
## [3.1.0] — 2026-07-15
|
|
9
156
|
|
|
10
157
|
플랜 구독 결제를 SDK로 완결 — `plans`가 read-only에서 **hosted checkout**(구독·결제·취소)까지
|
package/README.md
CHANGED
|
@@ -280,21 +280,37 @@ const meta = asJson<Meta>(record.values.meta); // Meta | undefined
|
|
|
280
280
|
|
|
281
281
|
## Exports
|
|
282
282
|
|
|
283
|
-
| Path
|
|
284
|
-
|
|
|
285
|
-
| `"."`
|
|
286
|
-
| `"./better-auth"`
|
|
287
|
-
| `"./better-auth/client"`
|
|
288
|
-
| `"./eav"`
|
|
289
|
-
| `"./eav/schema"`
|
|
290
|
-
| `"./eav/coerce"`
|
|
283
|
+
| Path | Main Exports | Requires `better-auth` |
|
|
284
|
+
| ---------------------------- | -------------------------------------------------------------------------------------- | ---------------------- |
|
|
285
|
+
| `"."` | `createReoptSDK`, `createLazySDK`, `initReoptSDK`, `getReoptSDK`, errors | No |
|
|
286
|
+
| `"./better-auth"` | `createReoptBetterAuth`, `createReoptAdapter`, `createReoptOAuth` | Yes |
|
|
287
|
+
| `"./better-auth/client"` | `createReoptOAuthClient`, `REOPT_PROVIDER_ID` | Yes |
|
|
288
|
+
| `"./eav"` | `createReoptEavClient`, `collectAll`, EAV types, `TypedEavRecord`, `EntityClient` | No |
|
|
289
|
+
| `"./eav/schema"` | `defineEntity`, `defineSchema`, `syncSchema`, `computeDiff`, schema/sync types | No |
|
|
290
|
+
| `"./eav/coerce"` | `asString`, `asNumber`, `asBoolean`, `asDate`, `asJson`, `asStringArray` | No |
|
|
291
|
+
| `"./eav/migrate"` | `defineMigration`, `runMigrations`, migration types | No |
|
|
292
|
+
| `"./ai"` / `"./ai-provider"` | `ReoptAiClient` / `createBrandappProvider` (Vercel AI SDK) | No |
|
|
293
|
+
| `"./auth"` | `getSessionFromCookies`, `verifySession`, `sdk.auth` client | No |
|
|
294
|
+
| `"./cms"` | `sdk.cms` types + `toMetadata` / `toSitemapItems` / `toRssFeed` / `EditorSpec` | No |
|
|
295
|
+
| `"./files"` | file client types + `optimizeUrl`, `createImageLoader` | No |
|
|
296
|
+
| `"./terms"` | Terms list / consent / withdraw types | No |
|
|
297
|
+
| `"./plans"` | `createReoptPlansClient`, `Plan` / `CheckoutSession` / `CurrentPlan` types | No |
|
|
298
|
+
| `"./push"` | Customer device token register / unregister / list types | No |
|
|
299
|
+
| `"./feedback"` | Customer feedback submission types | No |
|
|
300
|
+
| `"./logout"` | `createBackchannelLogoutHandler`, `verifyBackchannelLogoutToken`, `buildEndSessionUrl` | No |
|
|
301
|
+
| `"./webhooks"` | `createWebhookHandler`, `verifySignature` | No |
|
|
302
|
+
| `"./react/hooks"` | TanStack Query hooks (`useAiCredits`, `useEavRecords`, …) | No |
|
|
303
|
+
| `"./dev"` / `"./testing"` | `createDevServer` / `createTestSDK` (local dev + fixtures) | No |
|
|
304
|
+
|
|
305
|
+
> Full signatures for every sub-path: [`docs/api-reference.md`](./docs/api-reference.md).
|
|
291
306
|
|
|
292
307
|
> **Bundle tip.** `createReoptSDK()` eagerly wires every client (ai, auth, cms,
|
|
293
|
-
> eav, files, terms), so importing it pulls all of them
|
|
294
|
-
> only use one domain, import its factory or sub-path
|
|
295
|
-
> drops the rest — e.g.
|
|
296
|
-
>
|
|
297
|
-
>
|
|
308
|
+
> eav, feedback, files, plans, push, terms), so importing it pulls all of them
|
|
309
|
+
> into your bundle. If you only use one domain, import its factory or sub-path
|
|
310
|
+
> directly so tree-shaking drops the rest — e.g.
|
|
311
|
+
> `import { createReoptEavClient } from "@reopt-ai/brandapp-sdk/eav"` instead of
|
|
312
|
+
> the unified `createReoptSDK`. The core is edge-safe (no Node built-ins) and
|
|
313
|
+
> `sideEffects: false`, so unused sub-paths cost nothing.
|
|
298
314
|
|
|
299
315
|
## Configuration
|
|
300
316
|
|
|
@@ -438,9 +454,18 @@ export const POST = createWebhookHandler({
|
|
|
438
454
|
```
|
|
439
455
|
|
|
440
456
|
Event types: `contactCreated` / `contactUpdated` / `contactDeleted` /
|
|
441
|
-
`workflowRunCompleted` / `workflowRunFailed
|
|
457
|
+
`workflowRunCompleted` / `workflowRunFailed`, plus the subscription lifecycle
|
|
458
|
+
(3.4+) `subscriptionActivated` / `subscriptionRenewed` /
|
|
459
|
+
`subscriptionCanceled` / `subscriptionPaymentFailed`. Each `payload` is
|
|
442
460
|
`{ id, type, entityType, entityId, createdAt, data }`.
|
|
443
461
|
|
|
462
|
+
Subscription events carry `SubscriptionWebhookData`
|
|
463
|
+
(`{ brandappId, brandappCustomerId, customerId, planId, planName, provider, accessUntil }`)
|
|
464
|
+
— this is the server-side way to sync entitlements for changes that happen with
|
|
465
|
+
no user action (renewal, failed charge, provider-side cancellation). Webhooks
|
|
466
|
+
are registered per workspace, so filter on `data.brandappId`, and treat
|
|
467
|
+
`subscriptionCanceled` as "access until `accessUntil`", not "revoke now".
|
|
468
|
+
|
|
444
469
|
The handler verifies the `x-reopt-signature` header
|
|
445
470
|
(`sha256=HMAC-SHA256(secret, "{timestamp}.{body}")`) in constant time against
|
|
446
471
|
the `x-reopt-timestamp` header, rejects a missing/invalid signature or timestamp
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//#region src/core/abort.ts
|
|
2
|
+
function createManagedAbort(opts) {
|
|
3
|
+
const { timeoutMs, external, idle = false } = opts;
|
|
4
|
+
const controller = new AbortController();
|
|
5
|
+
let timer;
|
|
6
|
+
let finished = false;
|
|
7
|
+
let timedOut = false;
|
|
8
|
+
const arm = () => {
|
|
9
|
+
timer = setTimeout(() => {
|
|
10
|
+
timedOut = true;
|
|
11
|
+
controller.abort();
|
|
12
|
+
}, timeoutMs);
|
|
13
|
+
};
|
|
14
|
+
const disarm = () => {
|
|
15
|
+
if (timer !== void 0) {
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
timer = void 0;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const onExternalAbort = () => {
|
|
21
|
+
disarm();
|
|
22
|
+
controller.abort();
|
|
23
|
+
};
|
|
24
|
+
if (external) if (external.aborted) {
|
|
25
|
+
controller.abort();
|
|
26
|
+
finished = true;
|
|
27
|
+
} else external.addEventListener("abort", onExternalAbort, { once: true });
|
|
28
|
+
if (!finished) arm();
|
|
29
|
+
return {
|
|
30
|
+
signal: controller.signal,
|
|
31
|
+
kick() {
|
|
32
|
+
if (!idle || finished) return;
|
|
33
|
+
disarm();
|
|
34
|
+
arm();
|
|
35
|
+
},
|
|
36
|
+
cleanup() {
|
|
37
|
+
if (finished) return;
|
|
38
|
+
finished = true;
|
|
39
|
+
disarm();
|
|
40
|
+
external?.removeEventListener("abort", onExternalAbort);
|
|
41
|
+
},
|
|
42
|
+
get timedOut() {
|
|
43
|
+
return timedOut;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { createManagedAbort as t };
|
|
50
|
+
//# sourceMappingURL=abort--nOBFN4M.js.map
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -1,314 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/** 메시지 역할 */
|
|
4
|
-
type MessageRole = "system" | "user" | "assistant";
|
|
5
|
-
/** 채팅 메시지 */
|
|
6
|
-
type ChatMessage = {
|
|
7
|
-
role: MessageRole;
|
|
8
|
-
content: string;
|
|
9
|
-
};
|
|
10
|
-
/** AI completion 요청 옵션 */
|
|
11
|
-
type CompletionOptions = {
|
|
12
|
-
/** 모델 ID (e.g. "anthropic/claude-haiku-4.5"). 미지정 시 BrandApp 기본 모델. */
|
|
13
|
-
model?: string;
|
|
14
|
-
/** 커스텀 에이전트 ID (e.g. "custom:uuid") */
|
|
15
|
-
agentId?: string;
|
|
16
|
-
/** 메시지 배열 */
|
|
17
|
-
messages: ChatMessage[];
|
|
18
|
-
/** 최대 출력 토큰 (기본 4096) */
|
|
19
|
-
maxTokens?: number;
|
|
20
|
-
/** 생성 온도 (0-2) */
|
|
21
|
-
temperature?: number;
|
|
22
|
-
/** BrandappCustomer ID (사용량 추적용) */
|
|
23
|
-
customerId?: string;
|
|
24
|
-
/** AbortSignal for request cancellation */
|
|
25
|
-
signal?: AbortSignal;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* 생성 종료 사유. `unified`는 AI SDK v3 finishReason과 같은 어휘다. 서버가 보고하면
|
|
29
|
-
* 채워지고, 미보고 시 생략된다(소비처는 없으면 정상 종료로 간주).
|
|
30
|
-
*/
|
|
31
|
-
type FinishReason = {
|
|
32
|
-
unified: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other";
|
|
33
|
-
raw?: string;
|
|
34
|
-
};
|
|
35
|
-
/** AI completion 응답 (non-streaming) */
|
|
36
|
-
type CompletionResult = {
|
|
37
|
-
id: string;
|
|
38
|
-
model: string;
|
|
39
|
-
message: {
|
|
40
|
-
role: "assistant";
|
|
41
|
-
content: string;
|
|
42
|
-
};
|
|
43
|
-
usage: {
|
|
44
|
-
promptTokens: number;
|
|
45
|
-
completionTokens: number;
|
|
46
|
-
creditCost: number;
|
|
47
|
-
};
|
|
48
|
-
creditsRemaining: number;
|
|
49
|
-
/** 생성 종료 사유 (서버가 보고 시) */
|
|
50
|
-
finishReason?: FinishReason;
|
|
51
|
-
/**
|
|
52
|
-
* true면 이 호출은 잔액을 초과해 차감됐다(출력은 이미 생성되어 반환되지만 잔액은
|
|
53
|
-
* 0으로 소진). 다음 호출은 사전 크레딧 체크에서 차단된다 — "1회 후 차단" 의도.
|
|
54
|
-
*/
|
|
55
|
-
creditLimited?: boolean;
|
|
56
|
-
};
|
|
57
|
-
/** 크레딧 잔액 정보 */
|
|
58
|
-
type CreditInfo = {
|
|
59
|
-
balance: number;
|
|
60
|
-
limit: number;
|
|
61
|
-
percentage: number;
|
|
62
|
-
resetAt: string | null;
|
|
63
|
-
status: "normal" | "warning" | "critical" | "exhausted";
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* 사용 가능 모델 정보 — `sdk.ai.models()` / `sdk.ai.imageModels()` 응답 항목.
|
|
67
|
-
*
|
|
68
|
-
* 서버 `AvailableModel`(packages/ai)과 구조가 일치한다 — contract type-test가
|
|
69
|
-
* CI에서 동일성을 강제한다. `isDefault`로 "model 미지정 시 쓰이는 기본 모델"을,
|
|
70
|
-
* `modality`로 chat/image 구분을 사전에 알 수 있다.
|
|
71
|
-
*/
|
|
72
|
-
type ModelInfo = {
|
|
73
|
-
id: string;
|
|
74
|
-
displayName: string;
|
|
75
|
-
description: string;
|
|
76
|
-
provider: string;
|
|
77
|
-
/** chat | image */
|
|
78
|
-
modality: "chat" | "image";
|
|
79
|
-
tier: string;
|
|
80
|
-
tierLabel: string;
|
|
81
|
-
/** credits per 1K input tokens (image-only 모델은 0) */
|
|
82
|
-
inputRate: number;
|
|
83
|
-
/** credits per 1K output tokens (image-only 모델은 0) */
|
|
84
|
-
outputRate: number;
|
|
85
|
-
/** 이미지 생성당 고정 크레딧 (image 모델 전용) */
|
|
86
|
-
creditsPerImage?: number;
|
|
87
|
-
/** 최대 입력 컨텍스트 토큰 */
|
|
88
|
-
contextWindow?: number;
|
|
89
|
-
/** 최대 출력 토큰 */
|
|
90
|
-
maxOutputTokens?: number;
|
|
91
|
-
/** 이미지/파일 입력(비전) 지원 */
|
|
92
|
-
supportsVision?: boolean;
|
|
93
|
-
/** function/tool calling 지원 (외부 brandapp API에서는 미노출이나 메타로 제공) */
|
|
94
|
-
supportsTools?: boolean;
|
|
95
|
-
/** 이 brandapp의 기본 모델인지 (modality별 기본값과 일치) */
|
|
96
|
-
isDefault: boolean;
|
|
97
|
-
};
|
|
98
|
-
/** 이미지 생성 요청 옵션 */
|
|
99
|
-
type ImageGenerateOptions = {
|
|
100
|
-
/** 이미지 설명 프롬프트 */
|
|
101
|
-
prompt: string;
|
|
102
|
-
/** 네거티브 프롬프트 (생성에서 제외할 요소) */
|
|
103
|
-
negativePrompt?: string;
|
|
104
|
-
/** 스타일 (e.g. "watercolor", "photorealistic") */
|
|
105
|
-
style?: string;
|
|
106
|
-
/** 종횡비 (기본 1:1) */
|
|
107
|
-
aspectRatio?: "1:1" | "16:9" | "9:16" | "4:3" | "3:4";
|
|
108
|
-
/** 이미지 모델 (기본: google/gemini-2.5-flash-image) */
|
|
109
|
-
model?: string;
|
|
110
|
-
/** BrandappCustomer ID (사용량 추적용) */
|
|
111
|
-
customerId?: string;
|
|
112
|
-
};
|
|
113
|
-
/** 이미지 생성 결과 */
|
|
114
|
-
type ImageGenerateResult = {
|
|
115
|
-
/** 파일 ID */
|
|
116
|
-
id: string;
|
|
117
|
-
/** 이미지 URL (Vercel Blob) */
|
|
118
|
-
url: string;
|
|
119
|
-
/** 파일 크기 (bytes) */
|
|
120
|
-
size: number;
|
|
121
|
-
/** MIME 타입 */
|
|
122
|
-
contentType: string;
|
|
123
|
-
/** 사용량 */
|
|
124
|
-
usage: {
|
|
125
|
-
creditCost: number;
|
|
126
|
-
};
|
|
127
|
-
/** 남은 크레딧 */
|
|
128
|
-
creditsRemaining: number;
|
|
129
|
-
/** true면 잔액 초과 차감(이미지는 반환되나 잔액 소진, 다음 호출 차단) */
|
|
130
|
-
creditLimited?: boolean;
|
|
131
|
-
};
|
|
132
|
-
/** SSE 스트림 이벤트 */
|
|
133
|
-
type StreamEvent = {
|
|
134
|
-
event: "text-delta";
|
|
135
|
-
data: string;
|
|
136
|
-
} | {
|
|
137
|
-
event: "done";
|
|
138
|
-
data: StreamDoneData;
|
|
139
|
-
} | {
|
|
140
|
-
event: "error";
|
|
141
|
-
data: {
|
|
142
|
-
code: string;
|
|
143
|
-
message: string;
|
|
144
|
-
};
|
|
145
|
-
};
|
|
146
|
-
/** 스트림 완료 메타데이터 */
|
|
147
|
-
type StreamDoneData = {
|
|
148
|
-
usage: {
|
|
149
|
-
promptTokens: number;
|
|
150
|
-
completionTokens: number;
|
|
151
|
-
creditCost: number;
|
|
152
|
-
};
|
|
153
|
-
creditsRemaining: number;
|
|
154
|
-
/** 생성 종료 사유 (서버가 보고 시) */
|
|
155
|
-
finishReason?: FinishReason;
|
|
156
|
-
};
|
|
157
|
-
/** 커스텀 에이전트 정보 */
|
|
158
|
-
type AgentInfo = {
|
|
159
|
-
id: string;
|
|
160
|
-
name: string;
|
|
161
|
-
description: string;
|
|
162
|
-
defaultModel: string;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* BrandApp AI 클라이언트
|
|
167
|
-
*
|
|
168
|
-
* 기존 BaseHttpClient를 확장하여 AI API를 호출합니다.
|
|
169
|
-
* SSE 스트리밍은 fetch API를 직접 사용합니다.
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* ```ts
|
|
173
|
-
* const sdk = createReoptSDK({ ... });
|
|
174
|
-
*
|
|
175
|
-
* // Non-streaming
|
|
176
|
-
* const result = await sdk.ai.complete({
|
|
177
|
-
* messages: [{ role: "user", content: "안녕하세요" }],
|
|
178
|
-
* });
|
|
179
|
-
* console.log(result.message.content);
|
|
180
|
-
*
|
|
181
|
-
* // Streaming
|
|
182
|
-
* for await (const chunk of sdk.ai.stream({
|
|
183
|
-
* messages: [{ role: "user", content: "안녕하세요" }],
|
|
184
|
-
* })) {
|
|
185
|
-
* process.stdout.write(chunk);
|
|
186
|
-
* }
|
|
187
|
-
*
|
|
188
|
-
* // Credits
|
|
189
|
-
* const credits = await sdk.ai.credits();
|
|
190
|
-
* console.log(`${credits.balance} / ${credits.limit}`);
|
|
191
|
-
*
|
|
192
|
-
* // Models
|
|
193
|
-
* const models = await sdk.ai.models();
|
|
194
|
-
* ```
|
|
195
|
-
*/
|
|
196
|
-
|
|
197
|
-
declare class ReoptAiClient {
|
|
198
|
-
private readonly http;
|
|
199
|
-
/**
|
|
200
|
-
* Idle (inactivity) timeout for streaming, in ms — the maximum gap allowed
|
|
201
|
-
* *between* SSE chunks, not a deadline on the whole generation. A long but
|
|
202
|
-
* healthy generation keeps resetting this; only a genuine stall aborts.
|
|
203
|
-
*/
|
|
204
|
-
private readonly streamIdleTimeout;
|
|
205
|
-
constructor(config: ReoptSDKConfig);
|
|
206
|
-
/**
|
|
207
|
-
* AI 텍스트 생성 (non-streaming)
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* ```ts
|
|
211
|
-
* const result = await sdk.ai.complete({
|
|
212
|
-
* messages: [{ role: "user", content: "Hello" }],
|
|
213
|
-
* model: "anthropic/claude-haiku-4.5",
|
|
214
|
-
* maxTokens: 1024,
|
|
215
|
-
* });
|
|
216
|
-
* console.log(result.message.content);
|
|
217
|
-
* ```
|
|
218
|
-
*/
|
|
219
|
-
complete(options: CompletionOptions): Promise<CompletionResult>;
|
|
220
|
-
/**
|
|
221
|
-
* AI 텍스트 생성 (SSE 스트리밍)
|
|
222
|
-
*
|
|
223
|
-
* async generator로 텍스트 청크를 반환합니다.
|
|
224
|
-
* 사용량 메타데이터가 필요하면 `streamWithMetadata()`를 사용하세요.
|
|
225
|
-
*
|
|
226
|
-
* @example
|
|
227
|
-
* ```ts
|
|
228
|
-
* for await (const chunk of sdk.ai.stream({
|
|
229
|
-
* messages: [{ role: "user", content: "Hello" }],
|
|
230
|
-
* })) {
|
|
231
|
-
* process.stdout.write(chunk);
|
|
232
|
-
* }
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
stream(options: CompletionOptions): AsyncGenerator<string>;
|
|
236
|
-
/**
|
|
237
|
-
* AI 텍스트 생성 (SSE 스트리밍 + 메타데이터)
|
|
238
|
-
*
|
|
239
|
-
* 텍스트 청크와 함께 최종 사용량/크레딧 메타데이터를 반환합니다.
|
|
240
|
-
*
|
|
241
|
-
* @example
|
|
242
|
-
* ```ts
|
|
243
|
-
* const { textStream, metadata } = sdk.ai.streamWithMetadata({
|
|
244
|
-
* messages: [{ role: "user", content: "Hello" }],
|
|
245
|
-
* });
|
|
246
|
-
*
|
|
247
|
-
* let text = "";
|
|
248
|
-
* for await (const chunk of textStream) {
|
|
249
|
-
* text += chunk;
|
|
250
|
-
* }
|
|
251
|
-
*
|
|
252
|
-
* const meta = await metadata;
|
|
253
|
-
* console.log(`사용 크레딧: ${meta?.usage.creditCost}`);
|
|
254
|
-
* ```
|
|
255
|
-
*/
|
|
256
|
-
streamWithMetadata(options: CompletionOptions): {
|
|
257
|
-
textStream: AsyncGenerator<string>;
|
|
258
|
-
metadata: Promise<StreamDoneData | null>;
|
|
259
|
-
};
|
|
260
|
-
/**
|
|
261
|
-
* 이미지 생성
|
|
262
|
-
*
|
|
263
|
-
* BrandApp의 AI 크레딧으로 이미지를 생성합니다.
|
|
264
|
-
* 생성된 이미지는 자동으로 Vercel Blob에 저장되고 URL이 반환됩니다.
|
|
265
|
-
*
|
|
266
|
-
* @example
|
|
267
|
-
* ```ts
|
|
268
|
-
* const image = await sdk.ai.generateImage({
|
|
269
|
-
* prompt: "브랜드 배너 이미지",
|
|
270
|
-
* style: "minimalist",
|
|
271
|
-
* aspectRatio: "16:9",
|
|
272
|
-
* });
|
|
273
|
-
* console.log(image.url); // https://...blob.vercel-storage.com/...
|
|
274
|
-
* console.log(image.size); // 12345 (bytes)
|
|
275
|
-
* ```
|
|
276
|
-
*/
|
|
277
|
-
generateImage(options: ImageGenerateOptions): Promise<ImageGenerateResult>;
|
|
278
|
-
/**
|
|
279
|
-
* 크레딧 잔액 조회
|
|
280
|
-
*
|
|
281
|
-
* @example
|
|
282
|
-
* ```ts
|
|
283
|
-
* const credits = await sdk.ai.credits();
|
|
284
|
-
* console.log(`${credits.balance} / ${credits.limit} (${credits.status})`);
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
credits(): Promise<CreditInfo>;
|
|
288
|
-
/**
|
|
289
|
-
* 사용 가능 모델 목록 조회
|
|
290
|
-
*
|
|
291
|
-
* @example
|
|
292
|
-
* ```ts
|
|
293
|
-
* const models = await sdk.ai.models();
|
|
294
|
-
* models.forEach(m => console.log(`${m.id} (${m.tierLabel})`));
|
|
295
|
-
* ```
|
|
296
|
-
*/
|
|
297
|
-
models(): Promise<ModelInfo[]>;
|
|
298
|
-
/**
|
|
299
|
-
* 사용 가능한 커스텀 에이전트 목록 조회
|
|
300
|
-
*
|
|
301
|
-
* @example
|
|
302
|
-
* ```ts
|
|
303
|
-
* const agents = await sdk.ai.agents();
|
|
304
|
-
* for (const agent of agents) {
|
|
305
|
-
* console.log(`${agent.name}: ${agent.description}`);
|
|
306
|
-
* }
|
|
307
|
-
* ```
|
|
308
|
-
*/
|
|
309
|
-
agents(): Promise<AgentInfo[]>;
|
|
310
|
-
private fetchSSE;
|
|
311
|
-
}
|
|
312
|
-
declare function createReoptAiClient(config: ReoptSDKConfig): ReoptAiClient;
|
|
313
|
-
|
|
314
|
-
export { type AgentInfo, type ChatMessage, type CompletionOptions, type CompletionResult, type CreditInfo, type FinishReason, type ImageGenerateOptions, type ImageGenerateResult, type MessageRole, type ModelInfo, ReoptAiClient, type StreamDoneData, type StreamEvent, createReoptAiClient };
|
|
1
|
+
import { a as CompletionOptions, c as FinishReason, d as MessageRole, f as ModelInfo, i as ChatMessage, l as ImageGenerateOptions, m as StreamEvent, n as createReoptAiClient, o as CompletionResult, p as StreamDoneData, r as AgentInfo, s as CreditInfo, t as ReoptAiClient, u as ImageGenerateResult } from "../client-D0eBxh8j.js";
|
|
2
|
+
export { type AgentInfo, type ChatMessage, type CompletionOptions, type CompletionResult, type CreditInfo, type FinishReason, type ImageGenerateOptions, type ImageGenerateResult, type MessageRole, type ModelInfo, ReoptAiClient, type StreamDoneData, type StreamEvent, createReoptAiClient };
|
package/dist/ai/index.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import '../chunk-N5JVE4WX.js';
|
|
5
|
-
import '../chunk-MRQY45U5.js';
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { n as createReoptAiClient, t as ReoptAiClient } from "../client-DPmoKuR9.js";
|
|
2
|
+
|
|
3
|
+
export { ReoptAiClient, createReoptAiClient };
|