@reopt-ai/brandapp-sdk 3.0.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 +574 -0
- package/LICENSE +21 -0
- package/README.md +468 -0
- package/dist/ai/index.d.ts +314 -0
- package/dist/ai/index.js +7 -0
- package/dist/ai-provider/index.d.ts +196 -0
- package/dist/ai-provider/index.js +703 -0
- package/dist/auth/index.d.ts +76 -0
- package/dist/auth/index.js +40 -0
- package/dist/better-auth/client.d.ts +29 -0
- package/dist/better-auth/client.js +10 -0
- package/dist/better-auth/index.d.ts +82 -0
- package/dist/better-auth/index.js +145 -0
- package/dist/chunk-6FLYVNZI.js +32 -0
- package/dist/chunk-6KPKZ7ZB.js +49 -0
- package/dist/chunk-DI6QJPTQ.js +449 -0
- package/dist/chunk-E457LO5A.js +599 -0
- package/dist/chunk-F7BXBTZI.js +54 -0
- package/dist/chunk-J5Y2GSJF.js +443 -0
- package/dist/chunk-K3YVJE6E.js +96 -0
- package/dist/chunk-KU2LN5SE.js +350 -0
- package/dist/chunk-L4DHB36G.js +75 -0
- package/dist/chunk-PJZB4VP7.js +63 -0
- package/dist/chunk-REIKXSMY.js +7 -0
- package/dist/chunk-T2WXHAAC.js +54 -0
- package/dist/chunk-TUKIYH4Q.js +112 -0
- package/dist/chunk-WSEROZVO.js +81 -0
- package/dist/chunk-YRGLBM6V.js +157 -0
- package/dist/client-BkcO-0C2.d.ts +216 -0
- package/dist/client-CN5_tNOC.d.ts +147 -0
- package/dist/client-DttyeM_h.d.ts +102 -0
- package/dist/cms/index.d.ts +137 -0
- package/dist/cms/index.js +101 -0
- package/dist/config-CtxyJsDR.d.ts +397 -0
- package/dist/dev/index.d.ts +509 -0
- package/dist/dev/index.js +3071 -0
- package/dist/eav/coerce.d.ts +42 -0
- package/dist/eav/coerce.js +65 -0
- package/dist/eav/index.d.ts +214 -0
- package/dist/eav/index.js +147 -0
- package/dist/eav/migrate.d.ts +236 -0
- package/dist/eav/migrate.js +219 -0
- package/dist/eav/schema.d.ts +260 -0
- package/dist/eav/schema.js +656 -0
- package/dist/errors-5hd5ZR-M.d.ts +158 -0
- package/dist/feedback/index.d.ts +132 -0
- package/dist/feedback/index.js +5 -0
- package/dist/files/index.d.ts +54 -0
- package/dist/files/index.js +31 -0
- package/dist/index.d.ts +221 -0
- package/dist/index.js +84 -0
- package/dist/plans/index.d.ts +140 -0
- package/dist/plans/index.js +5 -0
- package/dist/push/index.d.ts +79 -0
- package/dist/push/index.js +5 -0
- package/dist/react/hooks.d.ts +376 -0
- package/dist/react/hooks.js +421 -0
- package/dist/terms/index.d.ts +79 -0
- package/dist/terms/index.js +5 -0
- package/dist/testing/index.d.ts +154 -0
- package/dist/testing/index.js +81 -0
- package/dist/typed-client-BxOVIiMU.d.ts +40 -0
- package/dist/types-6E3ZLL9X.d.ts +24 -0
- package/dist/types-DskYLVb8.d.ts +104 -0
- package/dist/types-ckmDDW3N.d.ts +129 -0
- package/dist/webhooks/index.d.ts +140 -0
- package/dist/webhooks/index.js +142 -0
- package/docs/api-reference.md +557 -0
- package/docs/cms.md +318 -0
- package/docs/dev-server.md +164 -0
- package/docs/environment.md +211 -0
- package/docs/errors.md +290 -0
- package/docs/files.md +272 -0
- package/docs/migration.md +315 -0
- package/docs/testing.md +163 -0
- package/package.json +173 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
type ReoptSDKErrorContext = {
|
|
2
|
+
method?: string;
|
|
3
|
+
url?: string;
|
|
4
|
+
attempt?: number;
|
|
5
|
+
/**
|
|
6
|
+
* The X-Request-Id sent with the failing request (mirrored back by the
|
|
7
|
+
* server when supported). Use this when reporting bugs to support — it
|
|
8
|
+
* uniquely identifies the request in our logs.
|
|
9
|
+
*/
|
|
10
|
+
requestId?: string;
|
|
11
|
+
};
|
|
12
|
+
/** 구조화된 진단 정보 — AI 에이전트가 파싱하여 자동 해결 시도 가능 */
|
|
13
|
+
type ErrorDiagnostic = {
|
|
14
|
+
/** 에러 원인 설명 */
|
|
15
|
+
cause: string;
|
|
16
|
+
/** 해결 방법 (에이전트가 실행 가능한 단계) */
|
|
17
|
+
fix: string;
|
|
18
|
+
/** 관련 환경변수 */
|
|
19
|
+
envVar?: string;
|
|
20
|
+
/** 관련 문서 경로 (node_modules/@reopt-ai/brandapp-sdk/docs/ 기준) */
|
|
21
|
+
doc?: string;
|
|
22
|
+
};
|
|
23
|
+
declare class ReoptSDKError extends Error {
|
|
24
|
+
readonly status: number;
|
|
25
|
+
readonly code: string;
|
|
26
|
+
readonly context?: ReoptSDKErrorContext;
|
|
27
|
+
readonly diagnostic?: ErrorDiagnostic;
|
|
28
|
+
constructor(message: string, status: number, code: string, context?: ReoptSDKErrorContext, diagnostic?: ErrorDiagnostic);
|
|
29
|
+
}
|
|
30
|
+
declare class AuthError extends ReoptSDKError {
|
|
31
|
+
constructor(message?: string, context?: ReoptSDKErrorContext);
|
|
32
|
+
}
|
|
33
|
+
declare class RateLimitError extends ReoptSDKError {
|
|
34
|
+
constructor(message?: string, retryAfterMs?: number);
|
|
35
|
+
}
|
|
36
|
+
declare class ServerError extends ReoptSDKError {
|
|
37
|
+
constructor(message?: string);
|
|
38
|
+
}
|
|
39
|
+
/** AI 크레딧 잔액 부족 (HTTP 402). */
|
|
40
|
+
declare class CreditLimitError extends ReoptSDKError {
|
|
41
|
+
constructor(message?: string, context?: ReoptSDKErrorContext, code?: string);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 요청한 모델이 현재 plan tier에서 허용되지 않음 (HTTP 403, `MODEL_ACCESS_DENIED`).
|
|
45
|
+
* 일반 권한 실패(`ForbiddenError`)와 구분해 모델 선택/업그레이드 안내를 준다.
|
|
46
|
+
*/
|
|
47
|
+
declare class ModelAccessError extends ReoptSDKError {
|
|
48
|
+
constructor(message?: string, context?: ReoptSDKErrorContext);
|
|
49
|
+
}
|
|
50
|
+
/** 알 수 없는 모델 ID (HTTP 404, `MODEL_NOT_FOUND`). */
|
|
51
|
+
declare class ModelNotFoundError extends ReoptSDKError {
|
|
52
|
+
constructor(message?: string, context?: ReoptSDKErrorContext);
|
|
53
|
+
}
|
|
54
|
+
/** 콘텐츠 정책 위반으로 생성 거부 (HTTP 422, `CONTENT_FILTER`). */
|
|
55
|
+
declare class ContentFilterError extends ReoptSDKError {
|
|
56
|
+
constructor(message?: string, context?: ReoptSDKErrorContext);
|
|
57
|
+
}
|
|
58
|
+
declare class BadRequestError extends ReoptSDKError {
|
|
59
|
+
constructor(message?: string, context?: ReoptSDKErrorContext, code?: string);
|
|
60
|
+
}
|
|
61
|
+
declare class ForbiddenError extends ReoptSDKError {
|
|
62
|
+
constructor(message?: string, context?: ReoptSDKErrorContext, code?: string);
|
|
63
|
+
}
|
|
64
|
+
declare class NotFoundError extends ReoptSDKError {
|
|
65
|
+
constructor(message?: string, context?: ReoptSDKErrorContext, code?: string);
|
|
66
|
+
}
|
|
67
|
+
declare class ConflictError extends ReoptSDKError {
|
|
68
|
+
constructor(message?: string, context?: ReoptSDKErrorContext, code?: string);
|
|
69
|
+
}
|
|
70
|
+
/** 한 brandapp user에 이미 같은 EAV entity의 record가 존재 (1:1 메타 위반). */
|
|
71
|
+
declare class AuthUserRecordExistsError extends ConflictError {
|
|
72
|
+
constructor(message?: string, context?: ReoptSDKErrorContext);
|
|
73
|
+
}
|
|
74
|
+
/** bulk create 입력에 같은 authUserId가 중복으로 등장 (1:1 메타 위반). */
|
|
75
|
+
declare class DuplicateAuthUserError extends ConflictError {
|
|
76
|
+
constructor(message?: string, context?: ReoptSDKErrorContext);
|
|
77
|
+
}
|
|
78
|
+
/** 참조한 brandappAuthUser가 이 brandapp에 존재하지 않음. status는 호출 경로에 따라 400 또는 422. */
|
|
79
|
+
declare class AuthUserNotFoundError extends ReoptSDKError {
|
|
80
|
+
constructor(message?: string, status?: 400 | 422, context?: ReoptSDKErrorContext);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* EAV 한도 초과 — entity/attribute/record 수가 plan 한도를 넘음.
|
|
84
|
+
* `code`로 어느 자원이 초과됐는지 분기:
|
|
85
|
+
* - `LIMIT_EXCEEDED_ENTITIES`
|
|
86
|
+
* - `LIMIT_EXCEEDED_ATTRIBUTES`
|
|
87
|
+
* - `LIMIT_EXCEEDED_RECORDS`
|
|
88
|
+
*/
|
|
89
|
+
declare class LimitExceededError extends ReoptSDKError {
|
|
90
|
+
constructor(message: string, code: "LIMIT_EXCEEDED_ENTITIES" | "LIMIT_EXCEEDED_ATTRIBUTES" | "LIMIT_EXCEEDED_RECORDS", context?: ReoptSDKErrorContext);
|
|
91
|
+
}
|
|
92
|
+
/** 필드 수준 검증 에러 */
|
|
93
|
+
type FieldError = {
|
|
94
|
+
/** 필드 이름 (attribute name) */
|
|
95
|
+
field: string;
|
|
96
|
+
/** 에러 메시지 */
|
|
97
|
+
message: string;
|
|
98
|
+
/** 에러 코드 (e.g. "required", "invalid_format", "too_long") */
|
|
99
|
+
code?: string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* 필드 수준 검증 에러
|
|
103
|
+
*
|
|
104
|
+
* API가 필드별 에러를 반환하면 자동으로 파싱됩니다.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* try {
|
|
109
|
+
* await sdk.eav.records.create(entityId, { values: {} });
|
|
110
|
+
* } catch (e) {
|
|
111
|
+
* if (e instanceof ValidationError) {
|
|
112
|
+
* e.fieldErrors.forEach(fe =>
|
|
113
|
+
* console.log(`${fe.field}: ${fe.message}`)
|
|
114
|
+
* );
|
|
115
|
+
* // "name: 필수 필드입니다"
|
|
116
|
+
* // "email: 올바른 이메일 형식이 아닙니다"
|
|
117
|
+
* }
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
declare class ValidationError extends ReoptSDKError {
|
|
122
|
+
readonly fieldErrors: FieldError[];
|
|
123
|
+
constructor(message: string, fieldErrors: FieldError[], context?: ReoptSDKErrorContext);
|
|
124
|
+
/** 특정 필드의 에러 메시지 반환 */
|
|
125
|
+
getFieldError(field: string): string | undefined;
|
|
126
|
+
/** 필드 → 메시지 맵 반환 */
|
|
127
|
+
toFieldMap(): Record<string, string>;
|
|
128
|
+
}
|
|
129
|
+
/** Bundle-safe type guard for ValidationError */
|
|
130
|
+
declare function isValidationError(error: unknown): error is ValidationError;
|
|
131
|
+
/**
|
|
132
|
+
* Bundle-safe type guard — works even when multiple SDK versions coexist.
|
|
133
|
+
*
|
|
134
|
+
* Duck-types on the SDK error shape (`status: number` + `code: string`) rather
|
|
135
|
+
* than `instanceof` to avoid cross-package class identity issues. (The base
|
|
136
|
+
* class name isn't checked because subclasses override `this.name` to
|
|
137
|
+
* `AuthError`/`ValidationError`/… — a single name comparison would miss them.)
|
|
138
|
+
* The type checks below keep a plain `Error` that happens to carry unrelated
|
|
139
|
+
* `status`/`code` fields from matching.
|
|
140
|
+
*/
|
|
141
|
+
declare function isReoptSDKError(error: unknown): error is ReoptSDKError;
|
|
142
|
+
/** Bundle-safe type guard for CreditLimitError */
|
|
143
|
+
declare function isCreditLimitError(error: unknown): error is CreditLimitError;
|
|
144
|
+
/** Bundle-safe type guard for ModelAccessError */
|
|
145
|
+
declare function isModelAccessError(error: unknown): error is ModelAccessError;
|
|
146
|
+
/**
|
|
147
|
+
* HTTP 상태 + 서버 에러 코드를 typed `ReoptSDKError`로 매핑하는 **단일 출처**.
|
|
148
|
+
*
|
|
149
|
+
* 비스트림 HTTP(`BaseHttpClient`), SSE 스트리밍(`ai/client.ts`), AI SDK provider
|
|
150
|
+
* (`ai-provider/provider-http.ts`)가 모두 이 함수를 거쳐 동일한 코드/진단을 갖는
|
|
151
|
+
* 에러를 생성한다. 그래서 `sdk.ai.*`와 `brandapp(...)`의 에러 형태가 통일된다.
|
|
152
|
+
*
|
|
153
|
+
* 반환만 하고 throw하지 않는다 — 호출처가 재시도 가능 여부(429/5xx)에 따라
|
|
154
|
+
* throw할지 `lastError`에 담을지 결정한다.
|
|
155
|
+
*/
|
|
156
|
+
declare function mapHttpStatusToError(status: number, code: string | undefined, message: string | undefined, ctx?: ReoptSDKErrorContext, fieldErrors?: FieldError[]): ReoptSDKError;
|
|
157
|
+
|
|
158
|
+
export { AuthError as A, BadRequestError as B, ConflictError as C, DuplicateAuthUserError as D, type ErrorDiagnostic as E, type FieldError as F, LimitExceededError as L, ModelAccessError as M, NotFoundError as N, RateLimitError as R, ServerError as S, ValidationError as V, AuthUserNotFoundError as a, AuthUserRecordExistsError as b, ContentFilterError as c, CreditLimitError as d, ForbiddenError as e, ModelNotFoundError as f, ReoptSDKError as g, type ReoptSDKErrorContext as h, isCreditLimitError as i, isModelAccessError as j, isReoptSDKError as k, isValidationError as l, mapHttpStatusToError as m };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { q as ReoptSDKConfig } from '../config-CtxyJsDR.js';
|
|
2
|
+
|
|
3
|
+
/** Feedback processing status. */
|
|
4
|
+
type FeedbackStatus = "new" | "in_progress" | "responded" | "archived";
|
|
5
|
+
/**
|
|
6
|
+
* A reply the workspace staff sent for a feedback. Only public fields are
|
|
7
|
+
* exposed — the responding staff identity is never included.
|
|
8
|
+
*/
|
|
9
|
+
type FeedbackReply = {
|
|
10
|
+
id: string;
|
|
11
|
+
content: string;
|
|
12
|
+
/** ISO datetime */
|
|
13
|
+
createdAt: string;
|
|
14
|
+
};
|
|
15
|
+
/** A customer feedback item as returned by the Brandapp Feedback API. */
|
|
16
|
+
type Feedback = {
|
|
17
|
+
id: string;
|
|
18
|
+
title: string | null;
|
|
19
|
+
content: string;
|
|
20
|
+
category: string | null;
|
|
21
|
+
/** 1–5, when the feedback carried a rating */
|
|
22
|
+
rating: number | null;
|
|
23
|
+
status: FeedbackStatus;
|
|
24
|
+
/** Linked reopt Customer id (null = anonymous) */
|
|
25
|
+
customerId: string | null;
|
|
26
|
+
replyCount: number;
|
|
27
|
+
/** ISO datetime */
|
|
28
|
+
createdAt: string;
|
|
29
|
+
};
|
|
30
|
+
/** Feedback detail including the reply thread. */
|
|
31
|
+
type FeedbackDetail = Feedback & {
|
|
32
|
+
replies: FeedbackReply[];
|
|
33
|
+
};
|
|
34
|
+
type CreateFeedbackInput = {
|
|
35
|
+
/** Feedback body (1–8000 chars). */
|
|
36
|
+
content: string;
|
|
37
|
+
title?: string;
|
|
38
|
+
category?: string;
|
|
39
|
+
/** 1–5 */
|
|
40
|
+
rating?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Customer id to attribute the feedback to (app-credential path only —
|
|
43
|
+
* the server verifies the customer is linked to this brandapp). Ignored
|
|
44
|
+
* on the `me.*` path where the token's customer is used.
|
|
45
|
+
*/
|
|
46
|
+
customerId?: string;
|
|
47
|
+
/** Free-form metadata (max 4000 chars serialized). */
|
|
48
|
+
metadata?: Record<string, unknown>;
|
|
49
|
+
};
|
|
50
|
+
type ListFeedbackQuery = {
|
|
51
|
+
status?: FeedbackStatus;
|
|
52
|
+
/** Filter by linked Customer id (app-credential path only). */
|
|
53
|
+
customerId?: string;
|
|
54
|
+
/** 1-based page (default 1). */
|
|
55
|
+
page?: number;
|
|
56
|
+
/** Page size 1–100 (default 20). */
|
|
57
|
+
limit?: number;
|
|
58
|
+
};
|
|
59
|
+
type FeedbackListMeta = {
|
|
60
|
+
page: number;
|
|
61
|
+
limit: number;
|
|
62
|
+
total: number;
|
|
63
|
+
};
|
|
64
|
+
type FeedbackListResult = {
|
|
65
|
+
feedbacks: Feedback[];
|
|
66
|
+
meta: FeedbackListMeta;
|
|
67
|
+
};
|
|
68
|
+
type CreateFeedbackResult = {
|
|
69
|
+
id: string;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Brandapp Feedback client.
|
|
74
|
+
*
|
|
75
|
+
* Lets a Brandapp collect customer feedback and read back the feedback with
|
|
76
|
+
* staff replies, so the external app can render a "내 피드백/답변" surface.
|
|
77
|
+
* Collected feedback lands in the reopt Studio CRM feedback inbox where the
|
|
78
|
+
* workspace staff triages it (reply / convert to task).
|
|
79
|
+
*
|
|
80
|
+
* Two credential paths:
|
|
81
|
+
* - App credentials (Basic / service token) — `create`, `list`, `get`.
|
|
82
|
+
* `list`/`get` are scoped to feedback this brandapp collected.
|
|
83
|
+
* - End-user OAuth access token — `me.create`, `me.list`, `me.get`.
|
|
84
|
+
* Scoped to the signed-in user's linked customer; `me.list` includes
|
|
85
|
+
* feedback the same customer submitted through brand forms too.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const sdk = createReoptSDK({ clientId, clientSecret, brandappId });
|
|
90
|
+
*
|
|
91
|
+
* // Server-side collection (attribute to a linked customer if known):
|
|
92
|
+
* await sdk.feedback.create({ content: "배송이 늦어요", rating: 2, customerId });
|
|
93
|
+
*
|
|
94
|
+
* // Signed-in user surface (OAuth access token):
|
|
95
|
+
* const { feedbacks } = await sdk.feedback.me.list(accessToken);
|
|
96
|
+
* const detail = await sdk.feedback.me.get(feedbacks[0]!.id, accessToken);
|
|
97
|
+
* detail.replies; // staff replies to render
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
declare class ReoptFeedbackClient {
|
|
102
|
+
private readonly http;
|
|
103
|
+
constructor(config: ReoptSDKConfig);
|
|
104
|
+
/**
|
|
105
|
+
* Create a feedback with app credentials (server-to-server collection).
|
|
106
|
+
* Pass `customerId` to attribute it to a customer linked to this brandapp.
|
|
107
|
+
*/
|
|
108
|
+
create(input: CreateFeedbackInput): Promise<CreateFeedbackResult>;
|
|
109
|
+
/** List feedback this brandapp collected (app credentials). */
|
|
110
|
+
list(query?: ListFeedbackQuery): Promise<FeedbackListResult>;
|
|
111
|
+
/** Fetch one feedback with its reply thread (app credentials). */
|
|
112
|
+
get(feedbackId: string): Promise<FeedbackDetail>;
|
|
113
|
+
/** End-user surface — requires the signed-in user's OAuth access token. */
|
|
114
|
+
readonly me: {
|
|
115
|
+
/**
|
|
116
|
+
* Create a feedback as the signed-in user. The server resolves the
|
|
117
|
+
* token's linked customer; unlinked users get 403 `LINK_REQUIRED`
|
|
118
|
+
* (call `sdk.auth.linkCurrentUser` first).
|
|
119
|
+
*/
|
|
120
|
+
create: (input: Omit<CreateFeedbackInput, "customerId">, accessToken: string) => Promise<CreateFeedbackResult>;
|
|
121
|
+
/**
|
|
122
|
+
* List the signed-in user's own feedback (all collection sources —
|
|
123
|
+
* brand form submissions included).
|
|
124
|
+
*/
|
|
125
|
+
list: (accessToken: string, query?: Omit<ListFeedbackQuery, "customerId">) => Promise<FeedbackListResult>;
|
|
126
|
+
/** Fetch one of the signed-in user's feedback with staff replies. */
|
|
127
|
+
get: (feedbackId: string, accessToken: string) => Promise<FeedbackDetail>;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
declare function createReoptFeedbackClient(config: ReoptSDKConfig): ReoptFeedbackClient;
|
|
131
|
+
|
|
132
|
+
export { type CreateFeedbackInput, type CreateFeedbackResult, type Feedback, type FeedbackDetail, type FeedbackListMeta, type FeedbackListResult, type FeedbackReply, type FeedbackStatus, type ListFeedbackQuery, ReoptFeedbackClient, createReoptFeedbackClient };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export { F as FileInfo, a as FileListQuery, b as FileListResponse, R as ReoptFileClient, U as UploadOptions, c as createReoptFileClient } from '../client-CN5_tNOC.js';
|
|
2
|
+
import '../config-CtxyJsDR.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 이미지 URL 헬퍼 — Next.js `<Image>`와 결합해 사용.
|
|
6
|
+
*
|
|
7
|
+
* SDK는 vendor-specific 이미지 변환을 강제하지 않는다.
|
|
8
|
+
* 이 모듈은 (1) optimization 쿼리 추가, (2) Next.js custom loader 생성,
|
|
9
|
+
* (3) `remotePatterns` 설정용 호스트 목록을 제공한다.
|
|
10
|
+
*/
|
|
11
|
+
type OptimizeUrlOptions = {
|
|
12
|
+
/** 출력 너비(px). 미지정 시 query 추가하지 않음. */
|
|
13
|
+
width?: number;
|
|
14
|
+
/** 1-100 범위 quality. */
|
|
15
|
+
quality?: number;
|
|
16
|
+
};
|
|
17
|
+
type ImageLoaderArgs = {
|
|
18
|
+
src: string;
|
|
19
|
+
width: number;
|
|
20
|
+
quality?: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* `next.config.ts`의 `images.remotePatterns`에 사용. Reopt가 호스팅하는
|
|
24
|
+
* 이미지(Vercel Blob, future CDN)를 Next.js Image optimization이 가져갈 수 있게 등록.
|
|
25
|
+
*/
|
|
26
|
+
type ImageRemotePattern = {
|
|
27
|
+
protocol: "https";
|
|
28
|
+
hostname: string;
|
|
29
|
+
};
|
|
30
|
+
declare const REOPT_IMAGE_REMOTE_PATTERNS: ImageRemotePattern[];
|
|
31
|
+
/**
|
|
32
|
+
* src에 width / quality 쿼리를 추가. 잘못된 URL은 그대로 반환.
|
|
33
|
+
*
|
|
34
|
+
* Next.js Image가 자체 optimization endpoint(`/_next/image`)를 사용하므로
|
|
35
|
+
* 일반적으로는 이 함수를 직접 호출할 필요 없음 — Next.js가 알아서 처리한다.
|
|
36
|
+
* 정적 OG 이미지 등 외부 사용자가 직접 URL을 만들 때만 사용.
|
|
37
|
+
*/
|
|
38
|
+
declare function optimizeUrl(src: string, opts: OptimizeUrlOptions): string;
|
|
39
|
+
/**
|
|
40
|
+
* Next.js Image `loader` prop과 호환되는 함수 반환. Next.js의 default loader
|
|
41
|
+
* (`/_next/image?url=...`) 대신 src 자체에 쿼리를 붙여 반환.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* import Image from "next/image";
|
|
46
|
+
* import { createImageLoader } from "@reopt-ai/brandapp-sdk/files";
|
|
47
|
+
*
|
|
48
|
+
* const loader = createImageLoader({ quality: 80 });
|
|
49
|
+
* <Image loader={loader} src={url} width={1200} height={630} alt="" />;
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare function createImageLoader(defaults?: OptimizeUrlOptions): ({ src, width, quality }: ImageLoaderArgs) => string;
|
|
53
|
+
|
|
54
|
+
export { type ImageLoaderArgs, type ImageRemotePattern, type OptimizeUrlOptions, REOPT_IMAGE_REMOTE_PATTERNS, createImageLoader, optimizeUrl };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export { ReoptFileClient, createReoptFileClient } from '../chunk-YRGLBM6V.js';
|
|
2
|
+
import '../chunk-F7BXBTZI.js';
|
|
3
|
+
import '../chunk-DI6QJPTQ.js';
|
|
4
|
+
import '../chunk-J5Y2GSJF.js';
|
|
5
|
+
|
|
6
|
+
// src/files/helpers.ts
|
|
7
|
+
var REOPT_IMAGE_REMOTE_PATTERNS = [
|
|
8
|
+
{ protocol: "https", hostname: "*.public.blob.vercel-storage.com" }
|
|
9
|
+
];
|
|
10
|
+
function optimizeUrl(src, opts) {
|
|
11
|
+
if (opts.width === void 0 && opts.quality === void 0) return src;
|
|
12
|
+
try {
|
|
13
|
+
const url = new URL(src);
|
|
14
|
+
if (opts.width !== void 0) url.searchParams.set("w", String(opts.width));
|
|
15
|
+
if (opts.quality !== void 0)
|
|
16
|
+
url.searchParams.set("q", String(opts.quality));
|
|
17
|
+
return url.toString();
|
|
18
|
+
} catch {
|
|
19
|
+
return src;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function createImageLoader(defaults) {
|
|
23
|
+
return ({ src, width, quality }) => optimizeUrl(src, {
|
|
24
|
+
width,
|
|
25
|
+
quality: quality ?? defaults?.quality
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { REOPT_IMAGE_REMOTE_PATTERNS, createImageLoader, optimizeUrl };
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { ReoptTermsClient } from './terms/index.js';
|
|
2
|
+
import { ReoptPushClient } from './push/index.js';
|
|
3
|
+
import { ReoptPlansClient } from './plans/index.js';
|
|
4
|
+
import { R as ReoptFileClient } from './client-CN5_tNOC.js';
|
|
5
|
+
import { ReoptFeedbackClient } from './feedback/index.js';
|
|
6
|
+
import { q as ReoptSDKConfig, S as SchemaDef, D as DebugLevel, l as EavEntity, f as CreateEntityInput, E as EavAttribute, r as UpdateEntityInput, e as CreateAttributeInput, U as UpdateAttributeInput, L as ListRecordsQuery, P as PaginatedResponse, m as EavRecord, g as CreateRecordInput, s as UpdateRecordInput, C as CountRecordsQuery, d as BulkUpdateItem, t as UpsertRecordInput, u as UpsertRecordResult, i as DeleteWhereInput, B as BackfillOptions, c as BackfillResult, p as EntityDef } from './config-CtxyJsDR.js';
|
|
7
|
+
export { h as DebugLogger, R as REOPT_BASE_URLS, v as resolveBaseUrl } from './config-CtxyJsDR.js';
|
|
8
|
+
import { a as ListPostsQuery, C as CmsPaginatedResponse, P as Post, c as PostDetail, L as ListPostGroupsQuery, d as PostGroup, b as ListTagsQuery, T as Tag } from './types-ckmDDW3N.js';
|
|
9
|
+
import { R as ReoptAuthClient } from './client-DttyeM_h.js';
|
|
10
|
+
import { ReoptAiClient } from './ai/index.js';
|
|
11
|
+
export { AgentInfo, ChatMessage, CompletionOptions, CompletionResult, CreditInfo, FinishReason, ImageGenerateOptions, ImageGenerateResult, MessageRole, ModelInfo, StreamDoneData, StreamEvent } from './ai/index.js';
|
|
12
|
+
export { A as AuthError, a as AuthUserNotFoundError, b as AuthUserRecordExistsError, B as BadRequestError, C as ConflictError, c as ContentFilterError, d as CreditLimitError, D as DuplicateAuthUserError, E as ErrorDiagnostic, F as FieldError, e as ForbiddenError, L as LimitExceededError, M as ModelAccessError, f as ModelNotFoundError, N as NotFoundError, R as RateLimitError, g as ReoptSDKError, h as ReoptSDKErrorContext, S as ServerError, V as ValidationError, i as isCreditLimitError, j as isModelAccessError, k as isReoptSDKError, l as isValidationError, m as mapHttpStatusToError } from './errors-5hd5ZR-M.js';
|
|
13
|
+
import { E as EntityClient } from './typed-client-BxOVIiMU.js';
|
|
14
|
+
export { T as TypedEavRecord } from './typed-client-BxOVIiMU.js';
|
|
15
|
+
import './types-DskYLVb8.js';
|
|
16
|
+
|
|
17
|
+
type FetchOptions = {
|
|
18
|
+
/** Abort the request via an external AbortSignal (merged with timeout signal). */
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
/** Override the client-level timeout for this call only (ms). */
|
|
21
|
+
timeout?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Swap the default Basic Auth header for `Authorization: Bearer <token>` on
|
|
24
|
+
* this call only. Used by user-scoped endpoints (e.g. `/external-auth`,
|
|
25
|
+
* OIDC userinfo) where the caller supplies an OAuth access token rather
|
|
26
|
+
* than client credentials.
|
|
27
|
+
*/
|
|
28
|
+
bearerToken?: string;
|
|
29
|
+
};
|
|
30
|
+
type BaseHttpClientOptions = {
|
|
31
|
+
/**
|
|
32
|
+
* Route requests at the id (auth) server instead of the main API host.
|
|
33
|
+
* Used for OIDC userinfo, Better Auth, and other `/api/auth/*` endpoints
|
|
34
|
+
* that only exist on `id.reopt.ai`.
|
|
35
|
+
*/
|
|
36
|
+
useIdServer?: boolean;
|
|
37
|
+
};
|
|
38
|
+
declare class BaseHttpClient {
|
|
39
|
+
private readonly baseUrl;
|
|
40
|
+
private readonly authHeader;
|
|
41
|
+
private readonly timeout;
|
|
42
|
+
private readonly maxRetries;
|
|
43
|
+
private readonly retryNonIdempotent;
|
|
44
|
+
private readonly debug;
|
|
45
|
+
constructor(config: ReoptSDKConfig, pathPrefix: string, options?: BaseHttpClientOptions);
|
|
46
|
+
/**
|
|
47
|
+
* Resolved request origin + path prefix
|
|
48
|
+
* (e.g. `https://brandapp.reopt.ai/api/v1/brandapp/{id}/ai`). Exposed so domain
|
|
49
|
+
* clients that must hand-roll `fetch` (SSE streaming, multipart upload) reuse
|
|
50
|
+
* the same resolved host instead of re-deriving it.
|
|
51
|
+
*/
|
|
52
|
+
get requestBaseUrl(): string;
|
|
53
|
+
/** The default `Authorization` header value (Basic or pre-minted Bearer). */
|
|
54
|
+
get authorizationHeader(): string;
|
|
55
|
+
/** Configured request timeout in ms. */
|
|
56
|
+
get timeoutMs(): number;
|
|
57
|
+
fetch<T>(method: string, path: string, body?: unknown, options?: FetchOptions): Promise<T>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Create a lazy SDK instance that initializes on first property access.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { createLazySDK } from "@reopt-ai/brandapp-sdk";
|
|
66
|
+
* import schema from "./eav.schema";
|
|
67
|
+
*
|
|
68
|
+
* export const sdk = createLazySDK(() => ({
|
|
69
|
+
* clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
70
|
+
* clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
71
|
+
* brandappId: process.env.BRANDAPP_ID!,
|
|
72
|
+
* schema,
|
|
73
|
+
* }));
|
|
74
|
+
*
|
|
75
|
+
* // First property access triggers initialization
|
|
76
|
+
* await sdk.eav.entity("contacts").records.list();
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function createLazySDK<S extends SchemaDef = SchemaDef>(configFactory: () => ReoptSDKConfig<S>): ReoptSDK<S>;
|
|
80
|
+
/**
|
|
81
|
+
* Initialize the global SDK singleton with explicit config.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { initReoptSDK } from "@reopt-ai/brandapp-sdk";
|
|
86
|
+
*
|
|
87
|
+
* initReoptSDK({
|
|
88
|
+
* clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
89
|
+
* clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
90
|
+
* brandappId: process.env.BRANDAPP_ID!,
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare function initReoptSDK<S extends SchemaDef = SchemaDef>(config: ReoptSDKConfig<S>): ReoptSDK<S>;
|
|
95
|
+
/**
|
|
96
|
+
* Get the global SDK singleton.
|
|
97
|
+
*
|
|
98
|
+
* Returns the instance set by `initReoptSDK()`, or auto-creates one
|
|
99
|
+
* from environment variables (`BRANDAPP_CLIENT_ID`, `BRANDAPP_CLIENT_SECRET`,
|
|
100
|
+
* `BRANDAPP_ID`).
|
|
101
|
+
*
|
|
102
|
+
* ⚠️ **Schema generic is not carried here.** A single module-global variable
|
|
103
|
+
* structurally cannot preserve a per-call schema type, so this always returns
|
|
104
|
+
* the default-schema `ReoptSDK` — `sdk.eav.entity(name)` falls back to untyped
|
|
105
|
+
* access (no autocomplete / `InferValues`). For type-safe EAV, prefer
|
|
106
|
+
* {@link createLazySDK} (or `createReoptSDK`) with your `schema`, which keeps
|
|
107
|
+
* the generic intact.
|
|
108
|
+
*
|
|
109
|
+
* @throws {Error} If no instance exists and env vars are missing
|
|
110
|
+
*/
|
|
111
|
+
declare function getReoptSDK(): ReoptSDK;
|
|
112
|
+
/** Reset the global SDK singleton. Useful for testing. */
|
|
113
|
+
declare function resetSDK(): void;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Create a unified Reopt SDK instance
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { createReoptSDK } from "@reopt-ai/brandapp-sdk";
|
|
121
|
+
*
|
|
122
|
+
* const sdk = createReoptSDK({
|
|
123
|
+
* clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
124
|
+
* clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
125
|
+
* brandappId: process.env.BRANDAPP_ID!,
|
|
126
|
+
* });
|
|
127
|
+
*
|
|
128
|
+
* // EAV client
|
|
129
|
+
* const entities = await sdk.eav.entities.list();
|
|
130
|
+
*
|
|
131
|
+
* // AI client
|
|
132
|
+
* const result = await sdk.ai.complete({
|
|
133
|
+
* messages: [{ role: "user", content: "Hello" }],
|
|
134
|
+
* });
|
|
135
|
+
*
|
|
136
|
+
* // File client
|
|
137
|
+
* const { data: files } = await sdk.files.list();
|
|
138
|
+
* const uploaded = await sdk.files.upload(blob, { name: "banner.png" });
|
|
139
|
+
*
|
|
140
|
+
* // CMS client
|
|
141
|
+
* const { records: posts } = await sdk.cms.posts.list({ status: "published" });
|
|
142
|
+
* const post = await sdk.cms.posts.get(postId);
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
type ReoptSDK<S extends SchemaDef = SchemaDef> = ReturnType<typeof createReoptSDK<S>>;
|
|
146
|
+
declare function createReoptSDK<S extends SchemaDef = SchemaDef>(config: ReoptSDKConfig<S>): {
|
|
147
|
+
config: {
|
|
148
|
+
brandappId: string;
|
|
149
|
+
debug: boolean | DebugLevel;
|
|
150
|
+
};
|
|
151
|
+
ai: ReoptAiClient;
|
|
152
|
+
auth: ReoptAuthClient;
|
|
153
|
+
cms: {
|
|
154
|
+
posts: {
|
|
155
|
+
list(query?: ListPostsQuery): Promise<CmsPaginatedResponse<Post>>;
|
|
156
|
+
get(postId: string): Promise<PostDetail>;
|
|
157
|
+
getBySlug(slug: string, opts?: {
|
|
158
|
+
groupId?: string;
|
|
159
|
+
groupSlug?: string;
|
|
160
|
+
}): Promise<PostDetail>;
|
|
161
|
+
};
|
|
162
|
+
postGroups: {
|
|
163
|
+
list(query?: ListPostGroupsQuery): Promise<CmsPaginatedResponse<PostGroup>>;
|
|
164
|
+
get(groupId: string): Promise<PostGroup>;
|
|
165
|
+
getBySlug(slug: string): Promise<PostGroup>;
|
|
166
|
+
};
|
|
167
|
+
tags: {
|
|
168
|
+
list(query?: ListTagsQuery): Promise<Tag[]>;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
eav: {
|
|
172
|
+
entities: {
|
|
173
|
+
list(): Promise<EavEntity[]>;
|
|
174
|
+
create(input: CreateEntityInput): Promise<EavEntity>;
|
|
175
|
+
get(entityId: string): Promise<EavEntity & {
|
|
176
|
+
attributes: EavAttribute[];
|
|
177
|
+
}>;
|
|
178
|
+
update(entityId: string, input: UpdateEntityInput): Promise<EavEntity>;
|
|
179
|
+
delete(entityId: string): Promise<void>;
|
|
180
|
+
};
|
|
181
|
+
attributes: {
|
|
182
|
+
create(entityId: string, input: CreateAttributeInput): Promise<EavAttribute>;
|
|
183
|
+
update(entityId: string, attributeId: string, input: UpdateAttributeInput): Promise<EavAttribute>;
|
|
184
|
+
delete(entityId: string, attributeId: string): Promise<void>;
|
|
185
|
+
};
|
|
186
|
+
records: {
|
|
187
|
+
list(entityId: string, query?: ListRecordsQuery): Promise<PaginatedResponse<EavRecord>>;
|
|
188
|
+
create(entityId: string, input: CreateRecordInput): Promise<EavRecord>;
|
|
189
|
+
get(entityId: string, recordId: string): Promise<EavRecord>;
|
|
190
|
+
update(entityId: string, recordId: string, input: UpdateRecordInput): Promise<EavRecord>;
|
|
191
|
+
delete(entityId: string, recordId: string): Promise<void>;
|
|
192
|
+
count(entityId: string, query?: CountRecordsQuery): Promise<number>;
|
|
193
|
+
bulkDelete(entityId: string, ids: string[]): Promise<number>;
|
|
194
|
+
bulkUpdate(entityId: string, updates: BulkUpdateItem[]): Promise<EavRecord[]>;
|
|
195
|
+
findOne(entityId: string, query?: Omit<ListRecordsQuery, "page">): Promise<EavRecord | null>;
|
|
196
|
+
upsert(entityId: string, input: UpsertRecordInput): Promise<UpsertRecordResult<EavRecord>>;
|
|
197
|
+
bulkCreate(entityId: string, records: CreateRecordInput[]): Promise<EavRecord[]>;
|
|
198
|
+
deleteWhere(entityId: string, input: DeleteWhereInput): Promise<number>;
|
|
199
|
+
listAll(entityId: string, query?: Omit<ListRecordsQuery, "page">): AsyncGenerator<EavRecord>;
|
|
200
|
+
backfill(entityId: string, opts: BackfillOptions): Promise<BackfillResult>;
|
|
201
|
+
};
|
|
202
|
+
users: {
|
|
203
|
+
getRecords(authUserId: string, query?: Omit<ListRecordsQuery, "authUserId">): Promise<PaginatedResponse<EavRecord>>;
|
|
204
|
+
};
|
|
205
|
+
schemaHash(): Promise<{
|
|
206
|
+
hash: string;
|
|
207
|
+
schemaCount: number;
|
|
208
|
+
fieldCount: number;
|
|
209
|
+
generatedAt: string;
|
|
210
|
+
}>;
|
|
211
|
+
entity<K extends string & keyof S["entities"]>(name: K): EntityClient<S["entities"][K] extends EntityDef ? S["entities"][K] : EntityDef>;
|
|
212
|
+
invalidateCache(): void;
|
|
213
|
+
};
|
|
214
|
+
feedback: ReoptFeedbackClient;
|
|
215
|
+
files: ReoptFileClient;
|
|
216
|
+
plans: ReoptPlansClient;
|
|
217
|
+
push: ReoptPushClient;
|
|
218
|
+
terms: ReoptTermsClient;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export { BaseHttpClient, DebugLevel, EntityClient, type ReoptSDK, ReoptSDKConfig, createLazySDK, createReoptSDK, getReoptSDK, initReoptSDK, resetSDK };
|