@reopt-ai/brandapp-sdk 3.3.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.
Files changed (102) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +10 -1
  3. package/dist/abort--nOBFN4M.js +50 -0
  4. package/dist/ai/index.d.ts +2 -314
  5. package/dist/ai/index.js +3 -8
  6. package/dist/ai-provider/index.d.ts +79 -163
  7. package/dist/ai-provider/index.js +752 -685
  8. package/dist/auth/index.d.ts +27 -27
  9. package/dist/auth/index.js +41 -34
  10. package/dist/better-auth/client.d.ts +6 -5
  11. package/dist/better-auth/client.js +28 -5
  12. package/dist/better-auth/index.d.ts +19 -17
  13. package/dist/better-auth/index.js +180 -144
  14. package/dist/client-B1q5P8rv.js +83 -0
  15. package/dist/client-B9QHVhdM.js +77 -0
  16. package/dist/client-BGGd_cpV.d.ts +103 -0
  17. package/dist/client-BJcy1V1a.js +140 -0
  18. package/dist/client-Beivhucf.js +55 -0
  19. package/dist/client-BruP5_nU.d.ts +147 -0
  20. package/dist/client-D-yNxNfk.js +28 -0
  21. package/dist/client-D0eBxh8j.d.ts +284 -0
  22. package/dist/client-D3RHHUUW.d.ts +207 -0
  23. package/dist/client-D6gs61w8.d.ts +53 -0
  24. package/dist/client-DBnK7ooQ.js +86 -0
  25. package/dist/client-DDw5yz_h.d.ts +53 -0
  26. package/dist/client-DPmoKuR9.js +305 -0
  27. package/dist/client-DsdakibF.js +503 -0
  28. package/dist/client-Dxg8_DIH.d.ts +71 -0
  29. package/dist/client-EbhUIhHq.js +53 -0
  30. package/dist/client-lk6wBu_0.d.ts +48 -0
  31. package/dist/client-p49ol9pg.d.ts +124 -0
  32. package/dist/cms/index.d.ts +52 -108
  33. package/dist/cms/index.js +103 -86
  34. package/dist/config-CRytOPPl.d.ts +394 -0
  35. package/dist/config-Cw0a3-C8.js +487 -0
  36. package/dist/dev/index.d.ts +2 -528
  37. package/dist/dev/index.js +2731 -2967
  38. package/dist/eav/coerce.d.ts +3 -1
  39. package/dist/eav/coerce.js +72 -46
  40. package/dist/eav/index.d.ts +72 -100
  41. package/dist/eav/index.js +158 -126
  42. package/dist/eav/migrate.d.ts +112 -109
  43. package/dist/eav/migrate.js +230 -196
  44. package/dist/eav/schema.d.ts +111 -150
  45. package/dist/eav/schema.js +624 -603
  46. package/dist/encoding-Bwfm3iaE.js +21 -0
  47. package/dist/{errors-BjDFIyA6.d.ts → errors-CRCcErNC.d.ts} +55 -53
  48. package/dist/feedback/index.d.ts +2 -132
  49. package/dist/feedback/index.js +3 -6
  50. package/dist/files/index.d.ts +14 -14
  51. package/dist/files/index.js +41 -25
  52. package/dist/http-client-QKUvvirs.js +386 -0
  53. package/dist/index-DrVaKfhs.d.ts +456 -0
  54. package/dist/index-Z6OGcurJ.d.ts +169 -0
  55. package/dist/index.d.ts +6 -230
  56. package/dist/index.js +119 -71
  57. package/dist/logout/index.d.ts +56 -53
  58. package/dist/logout/index.js +232 -289
  59. package/dist/plans/index.d.ts +2 -236
  60. package/dist/plans/index.js +3 -6
  61. package/dist/push/index.d.ts +2 -79
  62. package/dist/push/index.js +3 -6
  63. package/dist/query-BvbCiGWb.js +35 -0
  64. package/dist/react/hooks.d.ts +97 -99
  65. package/dist/react/hooks.js +742 -404
  66. package/dist/sse-parser-FMjxM7sY.js +86 -0
  67. package/dist/terms/index.d.ts +3 -79
  68. package/dist/terms/index.js +3 -6
  69. package/dist/testing/index.d.ts +52 -104
  70. package/dist/testing/index.js +94 -72
  71. package/dist/types-B-SMkH6s.d.ts +26 -0
  72. package/dist/types-BXDcoJHG.d.ts +131 -0
  73. package/dist/types-BrghN2rJ.d.ts +105 -0
  74. package/dist/types-DjDRszNj.js +11 -0
  75. package/dist/webhooks/index.d.ts +77 -50
  76. package/dist/webhooks/index.js +150 -127
  77. package/docs/api-reference.md +87 -6
  78. package/package.json +6 -5
  79. package/dist/chunk-2LSCQHAU.js +0 -21
  80. package/dist/chunk-4U4ZPPL4.js +0 -599
  81. package/dist/chunk-55KHY5GH.js +0 -96
  82. package/dist/chunk-C5VTRZWX.js +0 -458
  83. package/dist/chunk-F7BXBTZI.js +0 -54
  84. package/dist/chunk-FJUCWXX3.js +0 -350
  85. package/dist/chunk-H33OTQEN.js +0 -112
  86. package/dist/chunk-L4DHB36G.js +0 -75
  87. package/dist/chunk-OG7R3UAR.js +0 -105
  88. package/dist/chunk-PF24XU54.js +0 -32
  89. package/dist/chunk-QN3QD67K.js +0 -49
  90. package/dist/chunk-REIKXSMY.js +0 -7
  91. package/dist/chunk-UGBBXCZE.js +0 -157
  92. package/dist/chunk-UVT2E6KD.js +0 -81
  93. package/dist/chunk-YPLT3RFL.js +0 -63
  94. package/dist/chunk-YTKSAWV2.js +0 -463
  95. package/dist/client-BkcO-0C2.d.ts +0 -216
  96. package/dist/client-CN5_tNOC.d.ts +0 -147
  97. package/dist/client-DttyeM_h.d.ts +0 -102
  98. package/dist/config-CtxyJsDR.d.ts +0 -397
  99. package/dist/typed-client-BxOVIiMU.d.ts +0 -40
  100. package/dist/types-6E3ZLL9X.d.ts +0 -24
  101. package/dist/types-DskYLVb8.d.ts +0 -104
  102. package/dist/types-ckmDDW3N.d.ts +0 -129
@@ -1,147 +0,0 @@
1
- import { q as ReoptSDKConfig } from './config-CtxyJsDR.js';
2
-
3
- /** 파일 정보 */
4
- type FileInfo = {
5
- /** 파일 ID */
6
- id: string;
7
- /** 파일명 */
8
- name: string;
9
- /** 파일 URL (Vercel Blob) */
10
- url: string | null;
11
- /** 파일 크기 (bytes) */
12
- size: number;
13
- /** MIME 타입 */
14
- contentType: string | null;
15
- /** 저장 경로 */
16
- pathname: string;
17
- /** 생성일 (ISO 8601) */
18
- createdAt: string;
19
- /** 수정일 (ISO 8601) */
20
- updatedAt: string;
21
- };
22
- /** 파일 목록 조회 쿼리 */
23
- type FileListQuery = {
24
- /** 페이지 번호 (기본 1) */
25
- page?: number;
26
- /** 페이지 당 항목 수 (기본 20) */
27
- limit?: number;
28
- /** MIME 타입 필터 (e.g. "image/png", "image/*") */
29
- contentType?: string;
30
- /** 정렬 기준 */
31
- sortBy?: "createdAt" | "name" | "size";
32
- /** 정렬 순서 */
33
- sortOrder?: "asc" | "desc";
34
- };
35
- /** 파일 목록 응답 */
36
- type FileListResponse = {
37
- data: FileInfo[];
38
- meta: {
39
- page: number;
40
- limit: number;
41
- total: number;
42
- };
43
- };
44
- /** 파일 업로드 옵션 */
45
- type UploadOptions = {
46
- /** 파일명 (미지정 시 원본 파일명 또는 자동 생성) */
47
- name?: string;
48
- /** MIME 타입 (미지정 시 자동 감지) */
49
- contentType?: string;
50
- /** 외부 AbortSignal — 업로드 중도 취소용. SDK 타임아웃과 병합됨. */
51
- signal?: AbortSignal;
52
- /** 이 호출에만 적용할 타임아웃 (ms). 미지정 시 SDK 기본값. */
53
- timeout?: number;
54
- };
55
-
56
- /**
57
- * BrandApp File 클라이언트
58
- *
59
- * 기존 BaseHttpClient를 활용하여 파일 목록/조회/삭제를 처리하고,
60
- * 업로드는 FormData(multipart)가 필요하므로 globalThis.fetch를 직접 사용합니다.
61
- *
62
- * @example
63
- * ```ts
64
- * const sdk = createReoptSDK({ ... });
65
- *
66
- * // List files
67
- * const { data: files, meta } = await sdk.files.list({ page: 1, limit: 20 });
68
- *
69
- * // Get single file
70
- * const file = await sdk.files.get(fileId);
71
- *
72
- * // Upload file
73
- * const uploaded = await sdk.files.upload(blob, { name: "banner.png" });
74
- * console.log(uploaded.url);
75
- *
76
- * // Delete file
77
- * await sdk.files.delete(fileId);
78
- * ```
79
- */
80
-
81
- declare class ReoptFileClient {
82
- private readonly http;
83
- private readonly timeout;
84
- constructor(config: ReoptSDKConfig);
85
- /**
86
- * 파일 목록 조회
87
- *
88
- * @example
89
- * ```ts
90
- * const { data: files, meta } = await sdk.files.list({
91
- * page: 1,
92
- * limit: 20,
93
- * contentType: "image/*",
94
- * sortBy: "createdAt",
95
- * sortOrder: "desc",
96
- * });
97
- * console.log(`Total: ${meta.total}`);
98
- * ```
99
- */
100
- list(query?: FileListQuery): Promise<FileListResponse>;
101
- /**
102
- * 단일 파일 조회
103
- *
104
- * @example
105
- * ```ts
106
- * const file = await sdk.files.get("file-uuid");
107
- * console.log(file.name, file.url);
108
- * ```
109
- */
110
- get(fileId: string): Promise<FileInfo>;
111
- /**
112
- * 파일 삭제
113
- *
114
- * @example
115
- * ```ts
116
- * await sdk.files.delete("file-uuid");
117
- * ```
118
- */
119
- delete(fileId: string): Promise<void>;
120
- /**
121
- * 파일 업로드
122
- *
123
- * FormData(multipart)로 파일을 전송합니다.
124
- * BaseHttpClient는 JSON 전용이므로 globalThis.fetch를 직접 사용합니다.
125
- *
126
- * @example
127
- * ```ts
128
- * // Blob 업로드
129
- * const blob = new Blob(["hello"], { type: "text/plain" });
130
- * const file = await sdk.files.upload(blob, { name: "hello.txt" });
131
- *
132
- * // File 업로드 (브라우저)
133
- * const file = await sdk.files.upload(inputEl.files[0]);
134
- *
135
- * // Buffer 업로드 (Node.js)
136
- * const buf = fs.readFileSync("image.png");
137
- * const file = await sdk.files.upload(buf, {
138
- * name: "image.png",
139
- * contentType: "image/png",
140
- * });
141
- * ```
142
- */
143
- upload(file: Blob | Uint8Array | File, options?: UploadOptions): Promise<FileInfo>;
144
- }
145
- declare function createReoptFileClient(config: ReoptSDKConfig): ReoptFileClient;
146
-
147
- export { type FileInfo as F, ReoptFileClient as R, type UploadOptions as U, type FileListQuery as a, type FileListResponse as b, createReoptFileClient as c };
@@ -1,102 +0,0 @@
1
- import { q as ReoptSDKConfig } from './config-CtxyJsDR.js';
2
-
3
- /**
4
- * User-scoped auth types.
5
- *
6
- * These describe the Bearer-authenticated endpoints exposed by Reopt for
7
- * apps that have obtained an OAuth access token on behalf of an end user.
8
- * App-scoped (Basic Auth) operations live under `eav/`, `ai/`, `files/`,
9
- * `cms/` — they never need an access token.
10
- */
11
- /**
12
- * OIDC userinfo claims returned by `GET /api/auth/oauth2/userinfo`.
13
- *
14
- * Reopt always returns the core claims when the caller's token carries the
15
- * matching scopes (`openid`, `profile`, `email`). Additional claims may
16
- * appear when extra scopes are granted.
17
- */
18
- type UserInfoClaims = {
19
- sub: string;
20
- email?: string;
21
- email_verified?: boolean;
22
- name?: string;
23
- picture?: string;
24
- given_name?: string;
25
- family_name?: string;
26
- [claim: string]: unknown;
27
- };
28
- /**
29
- * Result of linking the current OAuth user to the Brandapp's customer table.
30
- *
31
- * The call is an idempotent upsert — the first invocation creates
32
- * `Customer`, `BrandCustomer`, `BrandappCustomer`, and `CustomerExternalId`
33
- * rows; subsequent calls refresh `authorizedAt` and flip `status` back to
34
- * `active`.
35
- */
36
- type LinkCurrentUserResult = {
37
- customerId: string;
38
- };
39
-
40
- /**
41
- * Brandapp Auth client — user-scoped (Bearer) endpoints.
42
- *
43
- * The rest of the SDK (`eav`, `ai`, `files`, `cms`) speaks to Reopt with the
44
- * app's Client Credentials (Basic Auth) and therefore returns app-wide data.
45
- * When a Brandapp wants to do something *on behalf of* a signed-in user
46
- * (link that user to a Customer row, fetch their OIDC claims, …), it needs
47
- * the user's OAuth access token instead.
48
- *
49
- * This client centralises those endpoints so consumers don't hardcode paths
50
- * or repeat Bearer-auth boilerplate:
51
- *
52
- * - `linkCurrentUser(accessToken)` — POST /api/v1/brandapp/{id}/external-auth
53
- * Idempotent upsert of Customer ↔ reoptUser link. First call creates
54
- * `Customer`, `BrandCustomer`, `BrandappCustomer`, and
55
- * `CustomerExternalId` rows; subsequent calls refresh `authorizedAt`.
56
- * - `getUserInfo(accessToken)` — GET /api/auth/oauth2/userinfo
57
- * Standard OIDC claims (sub / email / name / picture / …) scoped by
58
- * the access token.
59
- *
60
- * Errors are mapped to the SDK's error hierarchy (`AuthError` on 401,
61
- * `ForbiddenError` on 403, etc.) via the shared {@link BaseHttpClient}.
62
- *
63
- * @example
64
- * ```ts
65
- * const sdk = createReoptSDK({ clientId, clientSecret, brandappId });
66
- *
67
- * // Inside a server handler that has the user's OAuth access token:
68
- * const { customerId } = await sdk.auth.linkCurrentUser(accessToken);
69
- * const claims = await sdk.auth.getUserInfo(accessToken);
70
- * ```
71
- */
72
-
73
- declare class ReoptAuthClient {
74
- /**
75
- * Root client for `/api/auth/*` endpoints (OIDC userinfo, etc). Pinned to
76
- * the id server because Better Auth's handler is only mounted there.
77
- */
78
- private readonly rootHttp;
79
- /** Brandapp-scoped client — prefixed for per-brandapp endpoints. */
80
- private readonly brandappHttp;
81
- constructor(config: ReoptSDKConfig);
82
- /**
83
- * Upsert the Customer ↔ reoptUser link for the OAuth user represented by
84
- * the supplied access token.
85
- */
86
- linkCurrentUser(accessToken: string): Promise<LinkCurrentUserResult>;
87
- /**
88
- * Soft-withdraw the current OAuth user from this Brandapp: BrandappCustomer
89
- * flips to `churned`, the Brand↔Customer junction is removed, all
90
- * terms-consents move to `withdrawn`, and any Stripe subscription is
91
- * cancelled. The Customer record itself is retained so re-linking later
92
- * restores the same customerId (see `linkCurrentUser`).
93
- */
94
- withdrawCurrentUser(accessToken: string): Promise<LinkCurrentUserResult>;
95
- /**
96
- * Fetch the OIDC userinfo claims for the supplied access token.
97
- */
98
- getUserInfo(accessToken: string): Promise<UserInfoClaims>;
99
- }
100
- declare function createReoptAuthClient(config: ReoptSDKConfig): ReoptAuthClient;
101
-
102
- export { type LinkCurrentUserResult as L, ReoptAuthClient as R, type UserInfoClaims as U, createReoptAuthClient as c };
@@ -1,397 +0,0 @@
1
- type EavDataType = "string" | "textarea" | "number" | "boolean" | "date" | "email" | "url" | "select" | "multiselect";
2
- /**
3
- * 외부 SDK가 다루는 EAV schema host 분기.
4
- *
5
- * - `brandapp` (default): brandapp-scoped 자유 테이블 (EavRecord N rows).
6
- * - `brandappAuthUser`: BrandappAuthUser 1:1 메타. record id = authUserId,
7
- * record write/update는 BrandappAuthUser.customData JSONB로 들어간다.
8
- *
9
- * `customer`/`post`는 workspace 운영자 전용이라 SDK 표면에서는 노출하지 않는다.
10
- */
11
- type EavSchemaLinkedTo = "brandapp" | "brandappAuthUser";
12
- type EavEntity = {
13
- id: string;
14
- brandappId: string;
15
- name: string;
16
- description: string | null;
17
- icon: string | null;
18
- /** Host 분기. 1.7.0 부터 응답에 포함 (이전 SDK는 무시 가능). */
19
- linkedTo: EavSchemaLinkedTo;
20
- createdAt: string;
21
- updatedAt: string;
22
- };
23
- type CreateEntityInput = {
24
- name: string;
25
- description?: string;
26
- icon?: string;
27
- /** 호스트 분기. 생략 시 `'brandapp'` (자유 테이블). */
28
- linkedTo?: EavSchemaLinkedTo;
29
- };
30
- type UpdateEntityInput = {
31
- name?: string;
32
- description?: string | null;
33
- icon?: string | null;
34
- };
35
- type EavAttributeOption = {
36
- value: string;
37
- label: string;
38
- color?: string;
39
- };
40
- type EavValidation = {
41
- min?: number;
42
- max?: number;
43
- pattern?: string;
44
- minLength?: number;
45
- maxLength?: number;
46
- customMessage?: string;
47
- };
48
- type EavAttribute = {
49
- id: string;
50
- entityId: string;
51
- name: string;
52
- label: string;
53
- dataType: EavDataType;
54
- isRequired: boolean;
55
- isUnique: boolean;
56
- defaultValue: string | null;
57
- validation: EavValidation | null;
58
- options: EavAttributeOption[] | null;
59
- sortOrder: number;
60
- createdAt: string;
61
- updatedAt: string;
62
- };
63
- type CreateAttributeInput = {
64
- name: string;
65
- label: string;
66
- dataType: EavDataType;
67
- isRequired?: boolean;
68
- isUnique?: boolean;
69
- defaultValue?: string;
70
- validation?: EavValidation;
71
- options?: EavAttributeOption[];
72
- sortOrder?: number;
73
- };
74
- type UpdateAttributeInput = {
75
- name?: string;
76
- label?: string;
77
- dataType?: EavDataType;
78
- isRequired?: boolean;
79
- isUnique?: boolean;
80
- defaultValue?: string | null;
81
- validation?: EavValidation | null;
82
- options?: EavAttributeOption[] | null;
83
- sortOrder?: number;
84
- };
85
- type EavRecord = {
86
- id: string;
87
- entityId: string;
88
- authUserId: string | null;
89
- values: Record<string, unknown>;
90
- createdAt: string;
91
- updatedAt: string;
92
- };
93
- type CreateRecordInput = {
94
- authUserId?: string;
95
- values: Record<string, unknown>;
96
- };
97
- type UpdateRecordInput = {
98
- values: Record<string, unknown>;
99
- };
100
- type BulkUpdateItem = {
101
- id: string;
102
- values: Record<string, unknown>;
103
- };
104
- type AttributeFilterOperator = "eq" | "neq" | "contains" | "gt" | "lt" | "gte" | "lte" | "is_null" | "is_not_null" | "after" | "before";
105
- type AttributeFilter = {
106
- attributeId: string;
107
- operator: AttributeFilterOperator;
108
- value?: unknown;
109
- };
110
- type PaginatedResponse<T> = {
111
- records: T[];
112
- total: number;
113
- page: number;
114
- limit: number;
115
- totalPages: number;
116
- };
117
- type ListRecordsQuery = {
118
- page?: number;
119
- limit?: number;
120
- authUserId?: string;
121
- sortBy?: "createdAt" | "updatedAt" | (string & {});
122
- sortOrder?: "asc" | "desc";
123
- filters?: AttributeFilter[];
124
- };
125
- type CountRecordsQuery = {
126
- authUserId?: string;
127
- filters?: AttributeFilter[];
128
- };
129
- type UpsertRecordInput = {
130
- authUserId?: string;
131
- filters: AttributeFilter[];
132
- values: Record<string, unknown>;
133
- };
134
- type UpsertRecordResult<T = EavRecord> = {
135
- data: T;
136
- created: boolean;
137
- };
138
- type DeleteWhereInput = {
139
- authUserId?: string;
140
- filters: AttributeFilter[];
141
- };
142
- /** Return value of the backfill transformer per record. */
143
- type BackfillTransform = (record: EavRecord) => Record<string, unknown> | null | undefined;
144
- type BackfillOptions = {
145
- /** Filters applied to `records.list` while iterating. */
146
- filters?: AttributeFilter[];
147
- /** Restricts the iteration to a single user's records. */
148
- authUserId?: string;
149
- /** Sort order during iteration (default: `createdAt` ascending). */
150
- sortBy?: ListRecordsQuery["sortBy"];
151
- sortOrder?: ListRecordsQuery["sortOrder"];
152
- /** Page size used while streaming (default: 100, server max). */
153
- pageSize?: number;
154
- /**
155
- * Records per `bulkUpdate` flush (default: 100, server max; clamped to
156
- * 1..100). Transformed values are buffered and written in batched
157
- * transactions instead of one PATCH per record — for a large backfill this
158
- * cuts the request count ~100×. If a batch transaction fails, the SDK falls
159
- * back to per-record updates for that batch so `failed[]` stays accurate and
160
- * the run never aborts. Set `1` to update one record per request.
161
- */
162
- batchSize?: number;
163
- /** Maximum concurrent batch flushes in flight (default: 5). */
164
- concurrency?: number;
165
- /** Transformer — return the new partial values, or `null`/`undefined` to skip. */
166
- transform: BackfillTransform;
167
- /** Called after every record is processed (success, skip, or fail). */
168
- onProgress?: (event: BackfillProgressEvent) => void;
169
- };
170
- type BackfillProgressEvent = {
171
- processed: number;
172
- total: number;
173
- updated: number;
174
- skipped: number;
175
- failed: number;
176
- };
177
- type BackfillFailure = {
178
- recordId: string;
179
- error: string;
180
- };
181
- type BackfillResult = {
182
- total: number;
183
- updated: number;
184
- skipped: number;
185
- failed: BackfillFailure[];
186
- };
187
-
188
- type AttributeDef = {
189
- dataType: EavDataType;
190
- label: string;
191
- isRequired?: boolean;
192
- isUnique?: boolean;
193
- defaultValue?: string;
194
- validation?: EavValidation;
195
- options?: readonly EavAttributeOption[];
196
- sortOrder?: number;
197
- /**
198
- * Stable server-side ID (UUID). When set, `computeDiff` matches by this
199
- * ID before falling back to name / previousNames / lockfile heuristics.
200
- * Once chosen, never change this value — that's the whole point.
201
- *
202
- * Equivalent to Prisma's `@id` annotation: pin the row identity in the
203
- * schema itself so renames and external mutations cannot orphan it.
204
- *
205
- * @example
206
- * attributes: {
207
- * level: {
208
- * id: "01HX3K8Q9YZABCDEF1234567",
209
- * dataType: "string",
210
- * label: "Level",
211
- * }
212
- * }
213
- */
214
- id?: string;
215
- /**
216
- * Names this attribute used to have. When present, `computeDiff` matches
217
- * a server attribute with one of these names and treats it as a rename
218
- * (`update` action with a `name` change) instead of `delete + create`,
219
- * preserving all existing record values.
220
- *
221
- * @example
222
- * attributes: {
223
- * level: {
224
- * dataType: "string",
225
- * label: "Level",
226
- * previousNames: ["tier"], // server still has "tier" — auto-renamed
227
- * }
228
- * }
229
- */
230
- previousNames?: readonly string[];
231
- };
232
- type EntityDef<A extends Record<string, AttributeDef> = Record<string, AttributeDef>> = {
233
- name: string;
234
- description?: string;
235
- icon?: string;
236
- attributes: A;
237
- };
238
- type SchemaDef<E extends Record<string, EntityDef> = Record<string, EntityDef>> = {
239
- entities: E;
240
- };
241
- type InferDataType<D extends EavDataType, O> = D extends "number" ? number : D extends "boolean" ? boolean : D extends "select" ? O extends readonly {
242
- value: infer V;
243
- }[] ? V : string : D extends "multiselect" ? O extends readonly {
244
- value: infer V;
245
- }[] ? V[] : string[] : string;
246
- type RequiredKeys<A extends Record<string, AttributeDef>> = {
247
- [K in keyof A]: A[K] extends {
248
- isRequired: true;
249
- } ? K : never;
250
- }[keyof A];
251
- type OptionalKeys<A extends Record<string, AttributeDef>> = {
252
- [K in keyof A]: A[K] extends {
253
- isRequired: true;
254
- } ? never : K;
255
- }[keyof A];
256
- type InferValues<E extends EntityDef> = {
257
- [K in RequiredKeys<E["attributes"]>]: InferDataType<E["attributes"][K]["dataType"], E["attributes"][K] extends {
258
- options: infer O;
259
- } ? O : never>;
260
- } & {
261
- [K in OptionalKeys<E["attributes"]>]?: InferDataType<E["attributes"][K]["dataType"], E["attributes"][K] extends {
262
- options: infer O;
263
- } ? O : never>;
264
- };
265
-
266
- /**
267
- * Three-level debug logger.
268
- *
269
- * - "off" — silent (default)
270
- * - "info" — request/response/retry/error one-liners
271
- * - "trace" — everything in "info" plus request body, response status,
272
- * response body, and request id
273
- *
274
- * Backwards compatible: `debug: true` maps to "info", `debug: false` to "off".
275
- *
276
- * Auto-detection:
277
- * - BRANDAPP_SDK_DEBUG=trace → trace
278
- * - BRANDAPP_SDK_DEBUG=info | "1" → info
279
- * - DEBUG=*brandapp* → info
280
- *
281
- * Set BRANDAPP_SDK_LOG_FORMAT=json for machine-readable logs (AI agent consumers).
282
- */
283
- type DebugLevel = "off" | "info" | "trace";
284
- type DebugLogger = {
285
- level: DebugLevel;
286
- request(method: string, url: string, requestId: string, body?: unknown): void;
287
- response(method: string, url: string, status: number, durationMs: number, requestId: string, body?: unknown): void;
288
- retry(method: string, url: string, attempt: number, reason: string): void;
289
- error(method: string, url: string, error: string, requestId: string): void;
290
- };
291
-
292
- /**
293
- * Default API host for EAV / AI / Files / CMS / Terms. Consumers can override
294
- * via `config.baseUrl` or the `REOPT_BASE_URL` env var.
295
- *
296
- * The canonical production host is `brandapp.reopt.ai` (the brandapp data API —
297
- * distinct from `{alias}.reopt.ai` brandfront sites). The legacy `brand.reopt.ai`
298
- * host stays served indefinitely as a backward-compat alias, so SDK builds
299
- * published before this change keep working. ⚠️ Flip takes effect only on
300
- * re-publish — republish after `brandapp.reopt.ai` is live on Vercel.
301
- * (dev host stays `brand.reopt.de:3443` — bound to the local hosts file + cert.)
302
- */
303
- declare const REOPT_BASE_URLS: {
304
- readonly production: "https://brandapp.reopt.ai";
305
- readonly development: "https://brand.reopt.de:3443";
306
- };
307
- type ReoptSDKConfig<S extends SchemaDef = SchemaDef> = {
308
- /**
309
- * OAuth Client ID. Required for Basic Auth (client credentials). **Optional**
310
- * when a short-lived `token` is supplied instead — that's the secure
311
- * client-side pattern (see {@link assertBrowserSafe}).
312
- */
313
- clientId?: string;
314
- /**
315
- * OAuth Client Secret — a long-lived admin credential (`scope=['*']`, can mint
316
- * tokens). **Never expose it to the browser.** Required for Basic Auth;
317
- * **optional** when `token` is supplied. {@link assertBrowserSafe} throws if it
318
- * is present in a browser context.
319
- */
320
- clientSecret?: string;
321
- /** Brandapp ID (v1 API path에 사용) */
322
- brandappId: string;
323
- /**
324
- * Short-lived service token (Phase D-2b, RFC-0006). When set, every
325
- * outbound request uses `Authorization: Bearer <token>` instead of the
326
- * Basic Auth header derived from clientId/clientSecret.
327
- *
328
- * The Basic credentials remain required by `validateConfig` — they
329
- * stay around in case the caller wants to fall back (e.g. mint a fresh
330
- * token after expiry, or hit `/token/mint` itself). Per-call overrides
331
- * via `FetchOptions.bearerToken` still take precedence.
332
- */
333
- token?: string;
334
- /**
335
- * true: production (https://brandapp.reopt.ai)
336
- * false: development (https://brand.reopt.de:3443)
337
- * undefined (default): auto-detect from `NODE_ENV === "production"`
338
- */
339
- isProduction?: boolean;
340
- /**
341
- * Custom base URL — overrides `REOPT_BASE_URL` env, `isProduction`, and the
342
- * NODE_ENV default. Use this when you need different URLs per SDK instance
343
- * in the same process. For single-process apps, prefer the `REOPT_BASE_URL`
344
- * env var (no need to thread `baseUrl` through every call site).
345
- */
346
- baseUrl?: string;
347
- /**
348
- * Custom id (auth) base URL — overrides `REOPT_ID_BASE_URL` env and the URL
349
- * derived from `baseUrl` / `REOPT_BASE_URL` / `isProduction`. Set this when
350
- * the Better Auth handler is hosted at a non-standard origin (custom dev
351
- * cluster, on-prem deploy, etc.). For standard reopt.{ai,io,de} hosts you
352
- * can omit both this and the env var — it's auto-derived from the API host.
353
- */
354
- idBaseUrl?: string;
355
- /** Request timeout (ms), default: 15000 (AI/Files clients default to 30000) */
356
- timeout?: number;
357
- /**
358
- * Max **total** attempts per request, including the first — *not* the number
359
- * of retries. Default 3 means 1 initial call + up to 2 retries. `1` disables
360
- * retries entirely.
361
- */
362
- maxRetries?: number;
363
- /**
364
- * Opt in to retrying non-idempotent requests (POST/PATCH) on 5xx / network /
365
- * timeout failures. Off by default: a mutating request that the server may
366
- * have already committed (record create, AI credit charge, terms consent) is
367
- * **not** retried, to avoid duplicate side effects. 429 (rate-limited, never
368
- * processed) is always retried regardless of this flag. When enabled, mutating
369
- * requests still carry an `Idempotency-Key` (the request id) so a server that
370
- * supports it can de-duplicate retries.
371
- */
372
- retryNonIdempotent?: boolean;
373
- /** EAV schema for type-safe entity() client */
374
- schema?: S;
375
- /**
376
- * Debug logging level.
377
- * - `false` / `"off"` (default): silent
378
- * - `true` / `"info"`: one-line per request, response, retry, error
379
- * - `"trace"`: also dumps redacted request/response bodies + request ids
380
- *
381
- * Auto-detected from `BRANDAPP_SDK_DEBUG=trace|info|1` or `DEBUG=*brandapp*`.
382
- * Set `BRANDAPP_SDK_LOG_FORMAT=json` for machine-readable structured logs.
383
- */
384
- debug?: boolean | DebugLevel;
385
- };
386
- /**
387
- * Resolve the main API base URL for the given SDK config. Priority:
388
- *
389
- * 1. `config.baseUrl` — explicit override
390
- * 2. `REOPT_BASE_URL` env var — set this once and skip threading
391
- * `baseUrl` through every `createReoptSDK()` call
392
- * 3. default by `isProduction` / `NODE_ENV` (production →
393
- * `brandapp.reopt.ai`, otherwise → `brand.reopt.de:3443`)
394
- */
395
- declare function resolveBaseUrl(config: ReoptSDKConfig): string;
396
-
397
- export { type AttributeDef as A, type BackfillOptions as B, type CountRecordsQuery as C, type DebugLevel as D, type EavAttribute as E, type InferValues as I, type ListRecordsQuery as L, type PaginatedResponse as P, REOPT_BASE_URLS as R, type SchemaDef as S, type UpdateAttributeInput as U, type AttributeFilter as a, type AttributeFilterOperator as b, type BackfillResult as c, type BulkUpdateItem as d, type CreateAttributeInput as e, type CreateEntityInput as f, type CreateRecordInput as g, type DebugLogger as h, type DeleteWhereInput as i, type EavAttributeOption as j, type EavDataType as k, type EavEntity as l, type EavRecord as m, type EavSchemaLinkedTo as n, type EavValidation as o, type EntityDef as p, type ReoptSDKConfig as q, type UpdateEntityInput as r, type UpdateRecordInput as s, type UpsertRecordInput as t, type UpsertRecordResult as u, resolveBaseUrl as v };
@@ -1,40 +0,0 @@
1
- import { p as EntityDef, L as ListRecordsQuery, P as PaginatedResponse, m as EavRecord, I as InferValues, a as AttributeFilter, u as UpsertRecordResult, C as CountRecordsQuery, d as BulkUpdateItem, i as DeleteWhereInput, B as BackfillOptions, c as BackfillResult } from './config-CtxyJsDR.js';
2
-
3
- /** EavRecord with typed values instead of Record<string, unknown> */
4
- type TypedEavRecord<V> = Omit<EavRecord, "values"> & {
5
- values: V;
6
- };
7
- /** Entity-scoped client with typed records API */
8
- type EntityClient<E extends EntityDef> = {
9
- readonly entityName: string;
10
- records: {
11
- list(query?: ListRecordsQuery): Promise<PaginatedResponse<TypedEavRecord<InferValues<E>>>>;
12
- findOne(query?: Omit<ListRecordsQuery, "page">): Promise<TypedEavRecord<InferValues<E>> | null>;
13
- create(input: {
14
- authUserId?: string;
15
- values: InferValues<E>;
16
- }): Promise<TypedEavRecord<InferValues<E>>>;
17
- upsert(input: {
18
- authUserId?: string;
19
- filters: AttributeFilter[];
20
- values: InferValues<E>;
21
- }): Promise<UpsertRecordResult<TypedEavRecord<InferValues<E>>>>;
22
- get(recordId: string): Promise<TypedEavRecord<InferValues<E>>>;
23
- update(recordId: string, input: {
24
- values: Partial<InferValues<E>>;
25
- }): Promise<TypedEavRecord<InferValues<E>>>;
26
- delete(recordId: string): Promise<void>;
27
- count(query?: CountRecordsQuery): Promise<number>;
28
- bulkCreate(records: Array<{
29
- authUserId?: string;
30
- values: InferValues<E>;
31
- }>): Promise<TypedEavRecord<InferValues<E>>[]>;
32
- bulkDelete(ids: string[]): Promise<number>;
33
- bulkUpdate(updates: BulkUpdateItem[]): Promise<TypedEavRecord<InferValues<E>>[]>;
34
- deleteWhere(input: DeleteWhereInput): Promise<number>;
35
- listAll(query?: Omit<ListRecordsQuery, "page">): AsyncGenerator<TypedEavRecord<InferValues<E>>>;
36
- backfill(opts: BackfillOptions): Promise<BackfillResult>;
37
- };
38
- };
39
-
40
- export type { EntityClient as E, TypedEavRecord as T };