@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.
Files changed (76) hide show
  1. package/CHANGELOG.md +574 -0
  2. package/LICENSE +21 -0
  3. package/README.md +468 -0
  4. package/dist/ai/index.d.ts +314 -0
  5. package/dist/ai/index.js +7 -0
  6. package/dist/ai-provider/index.d.ts +196 -0
  7. package/dist/ai-provider/index.js +703 -0
  8. package/dist/auth/index.d.ts +76 -0
  9. package/dist/auth/index.js +40 -0
  10. package/dist/better-auth/client.d.ts +29 -0
  11. package/dist/better-auth/client.js +10 -0
  12. package/dist/better-auth/index.d.ts +82 -0
  13. package/dist/better-auth/index.js +145 -0
  14. package/dist/chunk-6FLYVNZI.js +32 -0
  15. package/dist/chunk-6KPKZ7ZB.js +49 -0
  16. package/dist/chunk-DI6QJPTQ.js +449 -0
  17. package/dist/chunk-E457LO5A.js +599 -0
  18. package/dist/chunk-F7BXBTZI.js +54 -0
  19. package/dist/chunk-J5Y2GSJF.js +443 -0
  20. package/dist/chunk-K3YVJE6E.js +96 -0
  21. package/dist/chunk-KU2LN5SE.js +350 -0
  22. package/dist/chunk-L4DHB36G.js +75 -0
  23. package/dist/chunk-PJZB4VP7.js +63 -0
  24. package/dist/chunk-REIKXSMY.js +7 -0
  25. package/dist/chunk-T2WXHAAC.js +54 -0
  26. package/dist/chunk-TUKIYH4Q.js +112 -0
  27. package/dist/chunk-WSEROZVO.js +81 -0
  28. package/dist/chunk-YRGLBM6V.js +157 -0
  29. package/dist/client-BkcO-0C2.d.ts +216 -0
  30. package/dist/client-CN5_tNOC.d.ts +147 -0
  31. package/dist/client-DttyeM_h.d.ts +102 -0
  32. package/dist/cms/index.d.ts +137 -0
  33. package/dist/cms/index.js +101 -0
  34. package/dist/config-CtxyJsDR.d.ts +397 -0
  35. package/dist/dev/index.d.ts +509 -0
  36. package/dist/dev/index.js +3071 -0
  37. package/dist/eav/coerce.d.ts +42 -0
  38. package/dist/eav/coerce.js +65 -0
  39. package/dist/eav/index.d.ts +214 -0
  40. package/dist/eav/index.js +147 -0
  41. package/dist/eav/migrate.d.ts +236 -0
  42. package/dist/eav/migrate.js +219 -0
  43. package/dist/eav/schema.d.ts +260 -0
  44. package/dist/eav/schema.js +656 -0
  45. package/dist/errors-5hd5ZR-M.d.ts +158 -0
  46. package/dist/feedback/index.d.ts +132 -0
  47. package/dist/feedback/index.js +5 -0
  48. package/dist/files/index.d.ts +54 -0
  49. package/dist/files/index.js +31 -0
  50. package/dist/index.d.ts +221 -0
  51. package/dist/index.js +84 -0
  52. package/dist/plans/index.d.ts +140 -0
  53. package/dist/plans/index.js +5 -0
  54. package/dist/push/index.d.ts +79 -0
  55. package/dist/push/index.js +5 -0
  56. package/dist/react/hooks.d.ts +376 -0
  57. package/dist/react/hooks.js +421 -0
  58. package/dist/terms/index.d.ts +79 -0
  59. package/dist/terms/index.js +5 -0
  60. package/dist/testing/index.d.ts +154 -0
  61. package/dist/testing/index.js +81 -0
  62. package/dist/typed-client-BxOVIiMU.d.ts +40 -0
  63. package/dist/types-6E3ZLL9X.d.ts +24 -0
  64. package/dist/types-DskYLVb8.d.ts +104 -0
  65. package/dist/types-ckmDDW3N.d.ts +129 -0
  66. package/dist/webhooks/index.d.ts +140 -0
  67. package/dist/webhooks/index.js +142 -0
  68. package/docs/api-reference.md +557 -0
  69. package/docs/cms.md +318 -0
  70. package/docs/dev-server.md +164 -0
  71. package/docs/environment.md +211 -0
  72. package/docs/errors.md +290 -0
  73. package/docs/files.md +272 -0
  74. package/docs/migration.md +315 -0
  75. package/docs/testing.md +163 -0
  76. package/package.json +173 -0
@@ -0,0 +1,509 @@
1
+ import { E as EditorSpec } from '../types-ckmDDW3N.js';
2
+ import { e as TermsJurisdiction } from '../types-DskYLVb8.js';
3
+
4
+ /**
5
+ * In-Memory Store for BrandApp Dev Server
6
+ *
7
+ * Map-based storage that mirrors the production Prisma models.
8
+ * Supports JSON serialization for persistence across restarts.
9
+ */
10
+
11
+ type DevEntity = {
12
+ id: string;
13
+ brandappId: string;
14
+ name: string;
15
+ description: string | null;
16
+ icon: string;
17
+ /** Host 분기. dev-server는 backend의 'brandapp' / 'brandappAuthUser'만 미러. */
18
+ linkedTo: "brandapp" | "brandappAuthUser";
19
+ maxRecords: number;
20
+ createdAt: Date;
21
+ updatedAt: Date;
22
+ };
23
+ type DevAttribute = {
24
+ id: string;
25
+ entityId: string;
26
+ name: string;
27
+ label: string;
28
+ dataType: string;
29
+ isRequired: boolean;
30
+ isUnique: boolean;
31
+ defaultValue: string | null;
32
+ validation: unknown | null;
33
+ options: unknown | null;
34
+ sortOrder: number;
35
+ createdAt: Date;
36
+ updatedAt: Date;
37
+ };
38
+ type DevValue = {
39
+ recordId: string;
40
+ attributeId: string;
41
+ value: string;
42
+ };
43
+ type DevRecord = {
44
+ id: string;
45
+ entityId: string;
46
+ brandappAuthUserId: string | null;
47
+ createdAt: Date;
48
+ updatedAt: Date;
49
+ values: DevValue[];
50
+ };
51
+ type DevAuthUser = {
52
+ id: string;
53
+ brandappId: string;
54
+ email: string;
55
+ emailVerified: boolean;
56
+ name: string | null;
57
+ image: string | null;
58
+ createdAt: Date;
59
+ updatedAt: Date;
60
+ };
61
+ type DevAuthSession = {
62
+ id: string;
63
+ userId: string;
64
+ brandappId: string;
65
+ token: string;
66
+ expiresAt: Date;
67
+ ipAddress: string | null;
68
+ userAgent: string | null;
69
+ createdAt: Date;
70
+ updatedAt: Date;
71
+ };
72
+ type DevAuthAccount = {
73
+ id: string;
74
+ userId: string;
75
+ brandappId: string;
76
+ providerId: string;
77
+ accountId: string;
78
+ accessToken: string | null;
79
+ refreshToken: string | null;
80
+ accessTokenExpiresAt: Date | null;
81
+ refreshTokenExpiresAt: Date | null;
82
+ idToken: string | null;
83
+ scope: string | null;
84
+ password: string | null;
85
+ createdAt: Date;
86
+ updatedAt: Date;
87
+ };
88
+ type DevAuthVerification = {
89
+ id: string;
90
+ brandappId: string;
91
+ identifier: string;
92
+ value: string;
93
+ expiresAt: Date;
94
+ createdAt: Date;
95
+ updatedAt: Date;
96
+ };
97
+ type DevFile = {
98
+ id: string;
99
+ brandappId: string;
100
+ name: string;
101
+ contentType: string;
102
+ size: number;
103
+ url: string;
104
+ createdAt: Date;
105
+ updatedAt: Date;
106
+ };
107
+ /**
108
+ * DevPost mirrors production `Post`/`PostDetail` shape so dev-server responses are
109
+ * indistinguishable from the remote API after the cms-handler maps them.
110
+ * Dates remain as `Date` objects in-memory and are stringified at the boundary.
111
+ */
112
+ type DevPost = {
113
+ id: string;
114
+ brandappId: string;
115
+ slug: string;
116
+ title: string;
117
+ /** Plain-text content (검색용). */
118
+ content: string;
119
+ /** EditorSpec — opt-editor 호환 rich content. dev seeder가 MDX→EditorSpec 변환해서 넣음. */
120
+ contentRich: EditorSpec | null;
121
+ status: string;
122
+ groupId: string | null;
123
+ /** Publish 시각 (status='published' or 'scheduled'에서 의미 있음). */
124
+ publishedAt: Date | null;
125
+ /** Cover image (id + URL). dev에서는 외부 URL 또는 placeholder 권장. */
126
+ coverImage: {
127
+ id: string;
128
+ url: string | null;
129
+ } | null;
130
+ /** Author info. */
131
+ author: {
132
+ id: string;
133
+ name: string;
134
+ image: string | null;
135
+ };
136
+ /** Document icon (emoji 또는 URL). */
137
+ icon: string | null;
138
+ /** Tags as `{id, text}` references — production SDK Tag와 동일. */
139
+ tags: {
140
+ id: string;
141
+ text: string;
142
+ }[];
143
+ /** SEO meta. */
144
+ seo: {
145
+ metaTitle: string | null;
146
+ metaDescription: string | null;
147
+ metaKeywords: string | null;
148
+ };
149
+ createdAt: Date;
150
+ updatedAt: Date;
151
+ };
152
+ type DevPostGroup = {
153
+ id: string;
154
+ brandappId: string;
155
+ /** 브랜드 내 안정적 식별자 (production PostGroup.slug 미러). null 허용. */
156
+ slug: string | null;
157
+ name: string;
158
+ description: string | null;
159
+ color: string;
160
+ /** Brand reference (dev에서는 brandappId를 brand id로 사용해도 OK). */
161
+ brand: {
162
+ id: string;
163
+ name: string;
164
+ } | null;
165
+ createdAt: Date;
166
+ updatedAt: Date;
167
+ };
168
+ type DevTerms = {
169
+ id: string;
170
+ brandappId: string;
171
+ title: string;
172
+ type: "termsOfService" | "privacyPolicy" | "marketingConsent" | "custom";
173
+ jurisdiction: TermsJurisdiction;
174
+ isRequired: boolean;
175
+ isActive: boolean;
176
+ sortOrder: number;
177
+ createdAt: Date;
178
+ updatedAt: Date;
179
+ };
180
+ type DevTermsVersion = {
181
+ id: string;
182
+ termsId: string;
183
+ version: number;
184
+ locale: string;
185
+ content: string;
186
+ changeSummary: string | null;
187
+ publishedAt: Date;
188
+ isCurrent: boolean;
189
+ reConsentDeadline: Date | null;
190
+ createdAt: Date;
191
+ };
192
+ type DevTermsConsent = {
193
+ id: string;
194
+ versionId: string;
195
+ customerId: string;
196
+ status: "granted" | "withdrawn" | "pendingReConsent";
197
+ consentedAt: Date;
198
+ withdrawnAt: Date | null;
199
+ source: string | null;
200
+ ipAddress: string | null;
201
+ userAgent: string | null;
202
+ consentCountry: string | null;
203
+ consentLocale: string | null;
204
+ createdAt: Date;
205
+ };
206
+ type StoreSnapshot = {
207
+ entities: DevEntity[];
208
+ attributes: DevAttribute[];
209
+ records: DevRecord[];
210
+ authUsers: DevAuthUser[];
211
+ authSessions: DevAuthSession[];
212
+ authAccounts: DevAuthAccount[];
213
+ authVerifications: DevAuthVerification[];
214
+ files: DevFile[];
215
+ posts: DevPost[];
216
+ postGroups: DevPostGroup[];
217
+ terms: DevTerms[];
218
+ termsVersions: DevTermsVersion[];
219
+ termsConsents: DevTermsConsent[];
220
+ };
221
+ declare class InMemoryStore {
222
+ entities: Map<string, DevEntity>;
223
+ attributes: Map<string, DevAttribute>;
224
+ records: Map<string, DevRecord>;
225
+ authUsers: Map<string, DevAuthUser>;
226
+ authSessions: Map<string, DevAuthSession>;
227
+ authAccounts: Map<string, DevAuthAccount>;
228
+ authVerifications: Map<string, DevAuthVerification>;
229
+ files: Map<string, DevFile>;
230
+ posts: Map<string, DevPost>;
231
+ postGroups: Map<string, DevPostGroup>;
232
+ terms: Map<string, DevTerms>;
233
+ termsVersions: Map<string, DevTermsVersion>;
234
+ termsConsents: Map<string, DevTermsConsent>;
235
+ generateId(): string;
236
+ now(): Date;
237
+ findMany<T>(map: Map<string, T>, predicate: (item: T) => boolean): T[];
238
+ findFirst<T>(map: Map<string, T>, predicate: (item: T) => boolean): T | null;
239
+ count<T>(map: Map<string, T>, predicate: (item: T) => boolean): number;
240
+ getEntitiesByBrandapp(brandappId: string): DevEntity[];
241
+ getAttributesByEntity(entityId: string): DevAttribute[];
242
+ getRecordsByEntity(entityId: string): DevRecord[];
243
+ getRecordValues(recordId: string): DevValue[];
244
+ /**
245
+ * Produce a snapshot that is safe to mutate without affecting the store.
246
+ * Dates are preserved by reconstructing them after a structuredClone.
247
+ */
248
+ toSnapshot(): StoreSnapshot;
249
+ toJSON(): string;
250
+ fromSnapshot(snapshot: StoreSnapshot): void;
251
+ fromJSON(json: string): void;
252
+ clear(): void;
253
+ }
254
+
255
+ /**
256
+ * Markdown → EditorSpec converter for dev seed workflows.
257
+ *
258
+ * Production studio writes EditorSpec directly via opt-editor; reopt-www and
259
+ * other marketing sites prefer authoring posts as `.mdx` files committed to
260
+ * git. This helper bridges the two by calling `@reopt-ai/opt-editor`'s
261
+ * `markdownToSpec` so the dev server returns EditorSpec identical to what
262
+ * production studio would produce for the same markdown.
263
+ *
264
+ * `@reopt-ai/opt-editor` is an OPTIONAL peer dependency — the consumer
265
+ * installs it as a devDependency. The dynamic import keeps it out of the
266
+ * production bundle of any consumer that only fetches posts at runtime.
267
+ *
268
+ * Phase 1 scope: plain markdown (headings, paragraphs, lists, code, links,
269
+ * images, blockquote, hr). MDX JSX components (`<Hero />` etc.) are NOT
270
+ * converted — `markdownToSpec` will drop or error on them. Custom element
271
+ * support is Phase 2 (register opt-editor element schemas + mapping table).
272
+ *
273
+ * @example
274
+ * ```ts
275
+ * import { createDevServer } from "@reopt-ai/brandapp-sdk/dev";
276
+ * import { markdownToEditorSpec } from "@reopt-ai/brandapp-sdk/dev";
277
+ * import { readFile } from "node:fs/promises";
278
+ *
279
+ * const mdx = await readFile("content/blog/hello.mdx", "utf-8");
280
+ * const contentRich = await markdownToEditorSpec(mdx);
281
+ *
282
+ * await dev.seedPosts([
283
+ * { groupSlug: "blog", slug: "hello", title: "Hello", contentRich },
284
+ * ]);
285
+ * ```
286
+ */
287
+
288
+ /**
289
+ * Convert a single markdown string to EditorSpec.
290
+ *
291
+ * Throws if `@reopt-ai/opt-editor` is not installed.
292
+ */
293
+ declare function markdownToEditorSpec(markdown: string): Promise<EditorSpec>;
294
+ /**
295
+ * Batch helper — converts multiple markdown bodies in one go.
296
+ * Useful when seeding many posts from MDX files.
297
+ */
298
+ declare function markdownToEditorSpecMany(markdowns: string[]): Promise<EditorSpec[]>;
299
+
300
+ /**
301
+ * @reopt-ai/brandapp-sdk/dev
302
+ *
303
+ * Local development server for BrandApp consumer projects.
304
+ * Provides an in-memory implementation of the full BrandApp API
305
+ * so developers can work offline without hitting the remote server.
306
+ *
307
+ * @example
308
+ * ```ts
309
+ * import { createDevServer } from "@reopt-ai/brandapp-sdk/dev";
310
+ * import schema from "./eav.schema";
311
+ *
312
+ * const dev = await createDevServer({
313
+ * schema,
314
+ * port: 4300,
315
+ * });
316
+ *
317
+ * console.log(`Dev server running at ${dev.url}`);
318
+ *
319
+ * // Seed data
320
+ * await dev.seed({
321
+ * contacts: [
322
+ * { values: { name: "Alice", email: "alice@test.com" } },
323
+ * ],
324
+ * });
325
+ *
326
+ * // Use with SDK
327
+ * const sdk = createReoptSDK({
328
+ * clientId: "dev",
329
+ * clientSecret: "dev",
330
+ * brandappId: "dev",
331
+ * baseUrl: dev.url,
332
+ * });
333
+ * ```
334
+ */
335
+
336
+ type ProxyConfig = {
337
+ /** Remote Reopt server URL (e.g. "https://brand.reopt.de:3443") */
338
+ remoteUrl: string;
339
+ /** Remote OAuth credentials */
340
+ remoteCredentials: {
341
+ clientId: string;
342
+ clientSecret: string;
343
+ brandappId: string;
344
+ };
345
+ /** Per-module proxy strategy: "local" (in-memory) or "passthrough" (remote) */
346
+ routes?: {
347
+ eav?: "local" | "passthrough";
348
+ ai?: "local" | "passthrough";
349
+ files?: "local" | "passthrough";
350
+ auth?: "local" | "passthrough";
351
+ cms?: "local" | "passthrough";
352
+ terms?: "local" | "passthrough";
353
+ };
354
+ };
355
+ type DevServerOptions = {
356
+ /** Port to listen on (default: 0 = auto-assign) */
357
+ port?: number;
358
+ /** BrandApp ID for dev context (default: "dev-brandapp") */
359
+ brandappId?: string;
360
+ /** Path to persist data across restarts (default: none) */
361
+ dataPath?: string;
362
+ /** Auto-seed entities from EAV schema definition */
363
+ schema?: DevSchema;
364
+ /** Enable verbose logging */
365
+ verbose?: boolean;
366
+ /** Proxy configuration — forward selected API calls to remote server */
367
+ proxy?: ProxyConfig;
368
+ };
369
+ type DevSchema = {
370
+ entities: Record<string, {
371
+ name?: string;
372
+ description?: string;
373
+ icon?: string;
374
+ maxRecords?: number;
375
+ attributes: Record<string, {
376
+ label?: string;
377
+ dataType?: string;
378
+ isRequired?: boolean;
379
+ isUnique?: boolean;
380
+ defaultValue?: string;
381
+ options?: Array<{
382
+ value: string;
383
+ label: string;
384
+ color?: string;
385
+ }>;
386
+ }>;
387
+ }>;
388
+ };
389
+ type SeedRecordInput = {
390
+ authUserId?: string;
391
+ values: Record<string, unknown>;
392
+ /**
393
+ * Per-record upsert key. Defaults to the entity's provided unique
394
+ * attributes, then falls back to all provided value keys in upsert mode.
395
+ */
396
+ upsertKey?: string | string[];
397
+ };
398
+ type SeedData = Record<string, SeedRecordInput[]>;
399
+ type SeedOptions = {
400
+ /** Append preserves legacy behaviour; upsert refreshes matching records. */
401
+ mode?: "append" | "upsert";
402
+ /** Global upsert key for every record in this seed call. */
403
+ upsertKey?: string | string[];
404
+ };
405
+ type SeedTermsItem = {
406
+ title: string;
407
+ type?: "termsOfService" | "privacyPolicy" | "marketingConsent" | "custom";
408
+ jurisdiction?: TermsJurisdiction;
409
+ isRequired?: boolean;
410
+ /** Defaults to inserting order, ascending. */
411
+ sortOrder?: number;
412
+ /** BCP 47 locale of the current published version. */
413
+ locale?: string;
414
+ /** Markdown / plain-text body of the current published version. */
415
+ content: string;
416
+ changeSummary?: string;
417
+ };
418
+ /**
419
+ * Idempotent PostGroup seed. `(brandappId, slug)` is the upsert key.
420
+ * The server generates `id` on first insert; subsequent calls with the same
421
+ * slug update name/description/color in place.
422
+ */
423
+ type SeedPostGroupInput = {
424
+ /** 브랜드 내 안정적 식별자. SDK consumer가 이 값으로 그룹을 참조한다. */
425
+ slug: string;
426
+ name: string;
427
+ description?: string;
428
+ color?: string;
429
+ };
430
+ type SeedPostInput = {
431
+ /** 소속 PostGroup의 slug. seedPostGroups로 먼저 만들어두거나 함께 시드 가능. */
432
+ groupSlug: string;
433
+ /** 그룹 내 안정적 식별자 (URL slug). 같은 groupSlug+slug 조합으로 upsert. */
434
+ slug: string;
435
+ title: string;
436
+ /** Plain-text content (검색용). */
437
+ content?: string;
438
+ /** EditorSpec — opt-editor 호환. MDX seed는 dev seeder에서 변환 후 여기에 넣음. */
439
+ contentRich?: EditorSpec | null;
440
+ status?: "draft" | "scheduled" | "published" | "archived";
441
+ publishedAt?: string | Date | null;
442
+ coverImage?: {
443
+ id?: string;
444
+ url: string | null;
445
+ } | null;
446
+ author?: Partial<{
447
+ id: string;
448
+ name: string;
449
+ image: string | null;
450
+ }>;
451
+ icon?: string | null;
452
+ /** Tags 입력 — 문자열은 dev seeder가 `{id: 'tag:<text>', text}` 형태로 정규화. */
453
+ tags?: Array<string | {
454
+ id: string;
455
+ text: string;
456
+ }>;
457
+ seo?: {
458
+ metaTitle?: string | null;
459
+ metaDescription?: string | null;
460
+ metaKeywords?: string | null;
461
+ };
462
+ };
463
+ /**
464
+ * Unified seed input for `dev.seedAll()`. Each field is optional and applied
465
+ * in order: postGroups → posts → entities → terms.
466
+ */
467
+ type SeedAllInput = {
468
+ postGroups?: SeedPostGroupInput[];
469
+ posts?: SeedPostInput[];
470
+ /** EAV records keyed by entity name — backward-compatible with `dev.seed()`. */
471
+ entities?: SeedData;
472
+ terms?: SeedTermsItem[];
473
+ };
474
+ type DevServer = {
475
+ /** Base URL of the running server */
476
+ url: string;
477
+ /** Port the server is listening on */
478
+ port: number;
479
+ /** The underlying in-memory store */
480
+ store: InMemoryStore;
481
+ /** Seed records into entities by name */
482
+ seed: (data: SeedData, options?: SeedOptions) => Promise<void>;
483
+ /** Seed BrandApp terms with their initial published version */
484
+ seedTerms: (items: SeedTermsItem[]) => Promise<void>;
485
+ /**
486
+ * Seed PostGroups identified by slug. Idempotent — running twice with the
487
+ * same slug updates name/description/color in place.
488
+ */
489
+ seedPostGroups: (items: SeedPostGroupInput[]) => Promise<void>;
490
+ /**
491
+ * Seed Posts identified by `(groupSlug, slug)`. Idempotent. The PostGroup
492
+ * referenced by `groupSlug` must exist (call `seedPostGroups` first or use
493
+ * `seedAll`).
494
+ */
495
+ seedPosts: (items: SeedPostInput[]) => Promise<void>;
496
+ /** One-shot seeder that applies postGroups → posts → entities → terms in order. */
497
+ seedAll: (input: SeedAllInput) => Promise<void>;
498
+ /** Reset all data (optionally re-seed schema) */
499
+ reset: () => Promise<void>;
500
+ /** Save current state to a JSON file */
501
+ snapshot: (path: string) => Promise<void>;
502
+ /** Restore state from a JSON file */
503
+ restore: (path: string) => Promise<void>;
504
+ /** Stop the dev server */
505
+ close: () => Promise<void>;
506
+ };
507
+ declare function createDevServer(options?: DevServerOptions): Promise<DevServer>;
508
+
509
+ export { type DevAttribute, type DevEntity, type DevPost, type DevPostGroup, type DevRecord, type DevSchema, type DevServer, type DevServerOptions, InMemoryStore, type ProxyConfig, type SeedAllInput, type SeedData, type SeedOptions, type SeedPostGroupInput, type SeedPostInput, type SeedRecordInput, type SeedTermsItem, type StoreSnapshot, createDevServer, markdownToEditorSpec, markdownToEditorSpecMany };