@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.
Files changed (104) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/README.md +39 -14
  3. package/dist/abort--nOBFN4M.js +50 -0
  4. package/dist/ai/index.d.ts +2 -314
  5. package/dist/ai/index.js +3 -7
  6. package/dist/ai-provider/index.d.ts +79 -163
  7. package/dist/ai-provider/index.js +752 -671
  8. package/dist/auth/index.d.ts +27 -27
  9. package/dist/auth/index.js +41 -33
  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 -133
  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 +105 -84
  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 -509
  37. package/dist/dev/index.js +2740 -2873
  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 -125
  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-DIAS8Rsl.d.ts → errors-CRCcErNC.d.ts} +55 -53
  48. package/dist/feedback/index.d.ts +2 -132
  49. package/dist/feedback/index.js +3 -5
  50. package/dist/files/index.d.ts +14 -14
  51. package/dist/files/index.js +41 -24
  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 -221
  56. package/dist/index.js +119 -70
  57. package/dist/logout/index.d.ts +109 -0
  58. package/dist/logout/index.js +264 -0
  59. package/dist/plans/index.d.ts +2 -236
  60. package/dist/plans/index.js +3 -5
  61. package/dist/push/index.d.ts +2 -79
  62. package/dist/push/index.js +3 -5
  63. package/dist/query-BvbCiGWb.js +35 -0
  64. package/dist/react/hooks.d.ts +97 -95
  65. package/dist/react/hooks.js +742 -356
  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 -5
  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 -47
  76. package/dist/webhooks/index.js +150 -127
  77. package/docs/api-reference.md +179 -2
  78. package/docs/dev-server.md +19 -18
  79. package/docs/errors.md +72 -15
  80. package/docs/logout.md +166 -0
  81. package/package.json +10 -5
  82. package/dist/chunk-2Q654O63.js +0 -350
  83. package/dist/chunk-F7BXBTZI.js +0 -54
  84. package/dist/chunk-IJOXTBIE.js +0 -599
  85. package/dist/chunk-JWXUVQRC.js +0 -157
  86. package/dist/chunk-L4DHB36G.js +0 -75
  87. package/dist/chunk-MRQY45U5.js +0 -465
  88. package/dist/chunk-N5JVE4WX.js +0 -449
  89. package/dist/chunk-O3PUWIDJ.js +0 -105
  90. package/dist/chunk-POLKEOYH.js +0 -63
  91. package/dist/chunk-R5CCGDUH.js +0 -49
  92. package/dist/chunk-RBHP7IZF.js +0 -96
  93. package/dist/chunk-REIKXSMY.js +0 -7
  94. package/dist/chunk-T7YTITRJ.js +0 -112
  95. package/dist/chunk-V73GORO3.js +0 -81
  96. package/dist/chunk-VRNBYSWU.js +0 -32
  97. package/dist/client-BkcO-0C2.d.ts +0 -216
  98. package/dist/client-CN5_tNOC.d.ts +0 -147
  99. package/dist/client-DttyeM_h.d.ts +0 -102
  100. package/dist/config-CtxyJsDR.d.ts +0 -397
  101. package/dist/typed-client-BxOVIiMU.d.ts +0 -40
  102. package/dist/types-6E3ZLL9X.d.ts +0 -24
  103. package/dist/types-DskYLVb8.d.ts +0 -104
  104. package/dist/types-ckmDDW3N.d.ts +0 -129
@@ -0,0 +1,394 @@
1
+ //#region src/eav/types.d.ts
2
+ type EavDataType = "string" | "textarea" | "number" | "boolean" | "date" | "email" | "url" | "select" | "multiselect";
3
+ /**
4
+ * 외부 SDK가 다루는 EAV schema host 분기.
5
+ *
6
+ * - `brandapp` (default): brandapp-scoped 자유 테이블 (EavRecord N rows).
7
+ * - `brandappAuthUser`: BrandappAuthUser 1:1 메타. record id = authUserId,
8
+ * record write/update는 BrandappAuthUser.customData JSONB로 들어간다.
9
+ *
10
+ * `customer`/`post`는 workspace 운영자 전용이라 SDK 표면에서는 노출하지 않는다.
11
+ */
12
+ type EavSchemaLinkedTo = "brandapp" | "brandappAuthUser";
13
+ type EavEntity = {
14
+ id: string;
15
+ brandappId: string;
16
+ name: string;
17
+ description: string | null;
18
+ icon: string | null;
19
+ /** Host 분기. 1.7.0 부터 응답에 포함 (이전 SDK는 무시 가능). */
20
+ linkedTo: EavSchemaLinkedTo;
21
+ createdAt: string;
22
+ updatedAt: string;
23
+ };
24
+ type CreateEntityInput = {
25
+ name: string;
26
+ description?: string;
27
+ icon?: string;
28
+ /** 호스트 분기. 생략 시 `'brandapp'` (자유 테이블). */
29
+ linkedTo?: EavSchemaLinkedTo;
30
+ };
31
+ type UpdateEntityInput = {
32
+ name?: string;
33
+ description?: string | null;
34
+ icon?: string | null;
35
+ };
36
+ type EavAttributeOption = {
37
+ value: string;
38
+ label: string;
39
+ color?: string;
40
+ };
41
+ type EavValidation = {
42
+ min?: number;
43
+ max?: number;
44
+ pattern?: string;
45
+ minLength?: number;
46
+ maxLength?: number;
47
+ customMessage?: string;
48
+ };
49
+ type EavAttribute = {
50
+ id: string;
51
+ entityId: string;
52
+ name: string;
53
+ label: string;
54
+ dataType: EavDataType;
55
+ isRequired: boolean;
56
+ isUnique: boolean;
57
+ defaultValue: string | null;
58
+ validation: EavValidation | null;
59
+ options: EavAttributeOption[] | null;
60
+ sortOrder: number;
61
+ createdAt: string;
62
+ updatedAt: string;
63
+ };
64
+ type CreateAttributeInput = {
65
+ name: string;
66
+ label: string;
67
+ dataType: EavDataType;
68
+ isRequired?: boolean;
69
+ isUnique?: boolean;
70
+ defaultValue?: string;
71
+ validation?: EavValidation;
72
+ options?: EavAttributeOption[];
73
+ sortOrder?: number;
74
+ };
75
+ type UpdateAttributeInput = {
76
+ name?: string;
77
+ label?: string;
78
+ dataType?: EavDataType;
79
+ isRequired?: boolean;
80
+ isUnique?: boolean;
81
+ defaultValue?: string | null;
82
+ validation?: EavValidation | null;
83
+ options?: EavAttributeOption[] | null;
84
+ sortOrder?: number;
85
+ };
86
+ type EavRecord = {
87
+ id: string;
88
+ entityId: string;
89
+ authUserId: string | null;
90
+ values: Record<string, unknown>;
91
+ createdAt: string;
92
+ updatedAt: string;
93
+ };
94
+ type CreateRecordInput = {
95
+ authUserId?: string;
96
+ values: Record<string, unknown>;
97
+ };
98
+ type UpdateRecordInput = {
99
+ values: Record<string, unknown>;
100
+ };
101
+ type BulkUpdateItem = {
102
+ id: string;
103
+ values: Record<string, unknown>;
104
+ };
105
+ type AttributeFilterOperator = "eq" | "neq" | "contains" | "gt" | "lt" | "gte" | "lte" | "is_null" | "is_not_null" | "after" | "before";
106
+ type AttributeFilter = {
107
+ attributeId: string;
108
+ operator: AttributeFilterOperator;
109
+ value?: unknown;
110
+ };
111
+ type PaginatedResponse<T> = {
112
+ records: T[];
113
+ total: number;
114
+ page: number;
115
+ limit: number;
116
+ totalPages: number;
117
+ };
118
+ type ListRecordsQuery = {
119
+ page?: number;
120
+ limit?: number;
121
+ authUserId?: string;
122
+ sortBy?: "createdAt" | "updatedAt" | (string & {});
123
+ sortOrder?: "asc" | "desc";
124
+ filters?: AttributeFilter[];
125
+ };
126
+ type CountRecordsQuery = {
127
+ authUserId?: string;
128
+ filters?: AttributeFilter[];
129
+ };
130
+ type UpsertRecordInput = {
131
+ authUserId?: string;
132
+ filters: AttributeFilter[];
133
+ values: Record<string, unknown>;
134
+ };
135
+ type UpsertRecordResult<T = EavRecord> = {
136
+ data: T;
137
+ created: boolean;
138
+ };
139
+ type DeleteWhereInput = {
140
+ authUserId?: string;
141
+ filters: AttributeFilter[];
142
+ };
143
+ /** Return value of the backfill transformer per record. */
144
+ type BackfillTransform = (record: EavRecord) => Record<string, unknown> | null | undefined;
145
+ type BackfillOptions = {
146
+ /** Filters applied to `records.list` while iterating. */
147
+ filters?: AttributeFilter[];
148
+ /** Restricts the iteration to a single user's records. */
149
+ authUserId?: string;
150
+ /** Sort order during iteration (default: `createdAt` ascending). */
151
+ sortBy?: ListRecordsQuery["sortBy"];
152
+ sortOrder?: ListRecordsQuery["sortOrder"];
153
+ /** Page size used while streaming (default: 100, server max). */
154
+ pageSize?: number;
155
+ /**
156
+ * Records per `bulkUpdate` flush (default: 100, server max; clamped to
157
+ * 1..100). Transformed values are buffered and written in batched
158
+ * transactions instead of one PATCH per record — for a large backfill this
159
+ * cuts the request count ~100×. If a batch transaction fails, the SDK falls
160
+ * back to per-record updates for that batch so `failed[]` stays accurate and
161
+ * the run never aborts. Set `1` to update one record per request.
162
+ */
163
+ batchSize?: number;
164
+ /** Maximum concurrent batch flushes in flight (default: 5). */
165
+ concurrency?: number;
166
+ /** Transformer — return the new partial values, or `null`/`undefined` to skip. */
167
+ transform: BackfillTransform;
168
+ /** Called after every record is processed (success, skip, or fail). */
169
+ onProgress?: (event: BackfillProgressEvent) => void;
170
+ };
171
+ type BackfillProgressEvent = {
172
+ processed: number;
173
+ total: number;
174
+ updated: number;
175
+ skipped: number;
176
+ failed: number;
177
+ };
178
+ type BackfillFailure = {
179
+ recordId: string;
180
+ error: string;
181
+ };
182
+ type BackfillResult = {
183
+ total: number;
184
+ updated: number;
185
+ skipped: number;
186
+ failed: BackfillFailure[];
187
+ };
188
+ //#endregion
189
+ //#region src/eav/schema/types.d.ts
190
+ type AttributeDef = {
191
+ dataType: EavDataType;
192
+ label: string;
193
+ isRequired?: boolean;
194
+ isUnique?: boolean;
195
+ defaultValue?: string;
196
+ validation?: EavValidation;
197
+ options?: readonly EavAttributeOption[];
198
+ sortOrder?: number;
199
+ /**
200
+ * Stable server-side ID (UUID). When set, `computeDiff` matches by this
201
+ * ID before falling back to name / previousNames / lockfile heuristics.
202
+ * Once chosen, never change this value — that's the whole point.
203
+ *
204
+ * Equivalent to Prisma's `@id` annotation: pin the row identity in the
205
+ * schema itself so renames and external mutations cannot orphan it.
206
+ *
207
+ * @example
208
+ * attributes: {
209
+ * level: {
210
+ * id: "01HX3K8Q9YZABCDEF1234567",
211
+ * dataType: "string",
212
+ * label: "Level",
213
+ * }
214
+ * }
215
+ */
216
+ id?: string;
217
+ /**
218
+ * Names this attribute used to have. When present, `computeDiff` matches
219
+ * a server attribute with one of these names and treats it as a rename
220
+ * (`update` action with a `name` change) instead of `delete + create`,
221
+ * preserving all existing record values.
222
+ *
223
+ * @example
224
+ * attributes: {
225
+ * level: {
226
+ * dataType: "string",
227
+ * label: "Level",
228
+ * previousNames: ["tier"], // server still has "tier" — auto-renamed
229
+ * }
230
+ * }
231
+ */
232
+ previousNames?: readonly string[];
233
+ };
234
+ type EntityDef<A extends Record<string, AttributeDef> = Record<string, AttributeDef>> = {
235
+ name: string;
236
+ description?: string;
237
+ icon?: string;
238
+ attributes: A;
239
+ };
240
+ type SchemaDef<E extends Record<string, EntityDef> = Record<string, EntityDef>> = {
241
+ entities: E;
242
+ };
243
+ type InferDataType<D extends EavDataType, O> = D extends "number" ? number : D extends "boolean" ? boolean : D extends "select" ? O extends readonly {
244
+ value: infer V;
245
+ }[] ? V : string : D extends "multiselect" ? O extends readonly {
246
+ value: infer V;
247
+ }[] ? V[] : string[] : string;
248
+ type RequiredKeys<A extends Record<string, AttributeDef>> = { [K in keyof A]: A[K] extends {
249
+ isRequired: true;
250
+ } ? K : never; }[keyof A];
251
+ type OptionalKeys<A extends Record<string, AttributeDef>> = { [K in keyof A]: A[K] extends {
252
+ isRequired: true;
253
+ } ? never : K; }[keyof A];
254
+ type InferValues<E extends EntityDef> = { [K in RequiredKeys<E["attributes"]>]: InferDataType<E["attributes"][K]["dataType"], E["attributes"][K] extends {
255
+ options: infer O;
256
+ } ? O : never>; } & { [K in OptionalKeys<E["attributes"]>]?: InferDataType<E["attributes"][K]["dataType"], E["attributes"][K] extends {
257
+ options: infer O;
258
+ } ? O : never>; };
259
+ //#endregion
260
+ //#region src/core/debug.d.ts
261
+ /**
262
+ * Three-level debug logger.
263
+ *
264
+ * - "off" — silent (default)
265
+ * - "info" — request/response/retry/error one-liners
266
+ * - "trace" — everything in "info" plus request body, response status,
267
+ * response body, and request id
268
+ *
269
+ * Backwards compatible: `debug: true` maps to "info", `debug: false` to "off".
270
+ *
271
+ * Auto-detection:
272
+ * - BRANDAPP_SDK_DEBUG=trace → trace
273
+ * - BRANDAPP_SDK_DEBUG=info | "1" → info
274
+ * - DEBUG=*brandapp* → info
275
+ *
276
+ * Set BRANDAPP_SDK_LOG_FORMAT=json for machine-readable logs (AI agent consumers).
277
+ */
278
+ type DebugLevel = "off" | "info" | "trace";
279
+ type DebugLogger = {
280
+ level: DebugLevel;
281
+ request(method: string, url: string, requestId: string, body?: unknown): void;
282
+ response(method: string, url: string, status: number, durationMs: number, requestId: string, body?: unknown): void;
283
+ retry(method: string, url: string, attempt: number, reason: string): void;
284
+ error(method: string, url: string, error: string, requestId: string): void;
285
+ };
286
+ //#endregion
287
+ //#region src/core/config.d.ts
288
+ /**
289
+ * Default API host for EAV / AI / Files / CMS / Terms. Consumers can override
290
+ * via `config.baseUrl` or the `REOPT_BASE_URL` env var.
291
+ *
292
+ * The canonical production host is `brandapp.reopt.ai` (the brandapp data API —
293
+ * distinct from `{alias}.reopt.ai` brandfront sites). The legacy `brand.reopt.ai`
294
+ * host stays served indefinitely as a backward-compat alias, so SDK builds
295
+ * published before this change keep working. ⚠️ Flip takes effect only on
296
+ * re-publish — republish after `brandapp.reopt.ai` is live on Vercel.
297
+ * (dev host stays `brand.reopt.de:3443` — bound to the local hosts file + cert.)
298
+ */
299
+ declare const REOPT_BASE_URLS: {
300
+ readonly production: "https://brandapp.reopt.ai";
301
+ readonly development: "https://brand.reopt.de:3443";
302
+ };
303
+ type ReoptSDKConfig<S extends SchemaDef = SchemaDef> = {
304
+ /**
305
+ * OAuth Client ID. Required for Basic Auth (client credentials). **Optional**
306
+ * when a short-lived `token` is supplied instead — that's the secure
307
+ * client-side pattern (see {@link assertBrowserSafe}).
308
+ */
309
+ clientId?: string;
310
+ /**
311
+ * OAuth Client Secret — a long-lived admin credential (`scope=['*']`, can mint
312
+ * tokens). **Never expose it to the browser.** Required for Basic Auth;
313
+ * **optional** when `token` is supplied. {@link assertBrowserSafe} throws if it
314
+ * is present in a browser context.
315
+ */
316
+ clientSecret?: string;
317
+ /** Brandapp ID (v1 API path에 사용) */
318
+ brandappId: string;
319
+ /**
320
+ * Short-lived service token (Phase D-2b, RFC-0006). When set, every
321
+ * outbound request uses `Authorization: Bearer <token>` instead of the
322
+ * Basic Auth header derived from clientId/clientSecret.
323
+ *
324
+ * The Basic credentials remain required by `validateConfig` — they
325
+ * stay around in case the caller wants to fall back (e.g. mint a fresh
326
+ * token after expiry, or hit `/token/mint` itself). Per-call overrides
327
+ * via `FetchOptions.bearerToken` still take precedence.
328
+ */
329
+ token?: string;
330
+ /**
331
+ * true: production (https://brandapp.reopt.ai)
332
+ * false: development (https://brand.reopt.de:3443)
333
+ * undefined (default): auto-detect from `NODE_ENV === "production"`
334
+ */
335
+ isProduction?: boolean;
336
+ /**
337
+ * Custom base URL — overrides `REOPT_BASE_URL` env, `isProduction`, and the
338
+ * NODE_ENV default. Use this when you need different URLs per SDK instance
339
+ * in the same process. For single-process apps, prefer the `REOPT_BASE_URL`
340
+ * env var (no need to thread `baseUrl` through every call site).
341
+ */
342
+ baseUrl?: string;
343
+ /**
344
+ * Custom id (auth) base URL — overrides `REOPT_ID_BASE_URL` env and the URL
345
+ * derived from `baseUrl` / `REOPT_BASE_URL` / `isProduction`. Set this when
346
+ * the Better Auth handler is hosted at a non-standard origin (custom dev
347
+ * cluster, on-prem deploy, etc.). For standard reopt.{ai,io,de} hosts you
348
+ * can omit both this and the env var — it's auto-derived from the API host.
349
+ */
350
+ idBaseUrl?: string;
351
+ /** Request timeout (ms), default: 15000 (AI/Files clients default to 30000) */
352
+ timeout?: number;
353
+ /**
354
+ * Max **total** attempts per request, including the first — *not* the number
355
+ * of retries. Default 3 means 1 initial call + up to 2 retries. `1` disables
356
+ * retries entirely.
357
+ */
358
+ maxRetries?: number;
359
+ /**
360
+ * Opt in to retrying non-idempotent requests (POST/PATCH) on 5xx / network /
361
+ * timeout failures. Off by default: a mutating request that the server may
362
+ * have already committed (record create, AI credit charge, terms consent) is
363
+ * **not** retried, to avoid duplicate side effects. 429 (rate-limited, never
364
+ * processed) is always retried regardless of this flag. When enabled, mutating
365
+ * requests still carry an `Idempotency-Key` (the request id) so a server that
366
+ * supports it can de-duplicate retries.
367
+ */
368
+ retryNonIdempotent?: boolean;
369
+ /** EAV schema for type-safe entity() client */
370
+ schema?: S;
371
+ /**
372
+ * Debug logging level.
373
+ * - `false` / `"off"` (default): silent
374
+ * - `true` / `"info"`: one-line per request, response, retry, error
375
+ * - `"trace"`: also dumps redacted request/response bodies + request ids
376
+ *
377
+ * Auto-detected from `BRANDAPP_SDK_DEBUG=trace|info|1` or `DEBUG=*brandapp*`.
378
+ * Set `BRANDAPP_SDK_LOG_FORMAT=json` for machine-readable structured logs.
379
+ */
380
+ debug?: boolean | DebugLevel;
381
+ };
382
+ /**
383
+ * Resolve the main API base URL for the given SDK config. Priority:
384
+ *
385
+ * 1. `config.baseUrl` — explicit override
386
+ * 2. `REOPT_BASE_URL` env var — set this once and skip threading
387
+ * `baseUrl` through every `createReoptSDK()` call
388
+ * 3. default by `isProduction` / `NODE_ENV` (production →
389
+ * `brandapp.reopt.ai`, otherwise → `brand.reopt.de:3443`)
390
+ */
391
+ declare function resolveBaseUrl(config: ReoptSDKConfig): string;
392
+ //#endregion
393
+ export { UpdateEntityInput as A, EavEntity as C, ListRecordsQuery as D, EavValidation as E, UpsertRecordInput as M, UpsertRecordResult as N, PaginatedResponse as O, EavDataType as S, EavSchemaLinkedTo as T, CreateEntityInput as _, DebugLogger as a, EavAttribute as b, InferValues as c, AttributeFilterOperator as d, BackfillOptions as f, CreateAttributeInput as g, CountRecordsQuery as h, DebugLevel as i, UpdateRecordInput as j, UpdateAttributeInput as k, SchemaDef as l, BulkUpdateItem as m, ReoptSDKConfig as n, AttributeDef as o, BackfillResult as p, resolveBaseUrl as r, EntityDef as s, REOPT_BASE_URLS as t, AttributeFilter as u, CreateRecordInput as v, EavRecord as w, EavAttributeOption as x, DeleteWhereInput as y };
394
+ //# sourceMappingURL=config-CRytOPPl.d.ts.map