@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,102 @@
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 };
@@ -0,0 +1,137 @@
1
+ import { q as ReoptSDKConfig } from '../config-CtxyJsDR.js';
2
+ 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';
3
+ export { E as EditorSpec, e as PostSeo, f as PostStatus } from '../types-ckmDDW3N.js';
4
+
5
+ /**
6
+ * Reopt CMS Client
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { createReoptSDK } from "@reopt-ai/brandapp-sdk";
11
+ *
12
+ * const sdk = createReoptSDK({
13
+ * clientId: process.env.BRANDAPP_CLIENT_ID!,
14
+ * clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
15
+ * brandappId: process.env.BRANDAPP_ID!,
16
+ * });
17
+ *
18
+ * const { records: posts } = await sdk.cms.posts.list({ status: "published" });
19
+ * const post = await sdk.cms.posts.get(postId);
20
+ * const post = await sdk.cms.posts.getBySlug("hello-world");
21
+ * const tags = await sdk.cms.tags.list();
22
+ * ```
23
+ */
24
+ type ReoptCmsClient = ReturnType<typeof createReoptCmsClient>;
25
+ declare function createReoptCmsClient(config: ReoptSDKConfig): {
26
+ posts: {
27
+ list(query?: ListPostsQuery): Promise<CmsPaginatedResponse<Post>>;
28
+ get(postId: string): Promise<PostDetail>;
29
+ /**
30
+ * Slug 기반 단건 조회. URL 라우트(`/blog/[slug]`)에서 id 매핑 없이 사용.
31
+ * 같은 slug가 여러 그룹에 있을 수 있는 경우 `groupId` 또는 `groupSlug`로 좁힐 수 있다.
32
+ */
33
+ getBySlug(slug: string, opts?: {
34
+ groupId?: string;
35
+ groupSlug?: string;
36
+ }): Promise<PostDetail>;
37
+ };
38
+ postGroups: {
39
+ list(query?: ListPostGroupsQuery): Promise<CmsPaginatedResponse<PostGroup>>;
40
+ get(groupId: string): Promise<PostGroup>;
41
+ /**
42
+ * Slug 기반 그룹 단건 조회. env var(`REOPT_*_GROUP_ID`) 대신 slug 하드코딩
43
+ * 패턴(`CONTENT_GROUPS.blog.slug`)을 권장.
44
+ */
45
+ getBySlug(slug: string): Promise<PostGroup>;
46
+ };
47
+ tags: {
48
+ /** Brand 범위 안에서 사용된 포스트 태그 목록을 반환. */
49
+ list(query?: ListTagsQuery): Promise<Tag[]>;
50
+ };
51
+ };
52
+
53
+ /**
54
+ * CMS 헬퍼 — SEO 메타데이터, 사이트맵, RSS 피드 생성.
55
+ *
56
+ * 모두 순수 함수. Next.js / React 의존 없음. 외부 마케팅 사이트가
57
+ * `cms.posts.list()` / `cms.posts.getBySlug()` 결과를 그대로 넘기면
58
+ * 표준 출력 형식으로 변환된다.
59
+ */
60
+
61
+ type SeoMetadata = {
62
+ title?: string;
63
+ description?: string;
64
+ keywords?: string;
65
+ alternates?: {
66
+ canonical?: string;
67
+ };
68
+ openGraph?: {
69
+ type?: "article" | "website";
70
+ title?: string;
71
+ description?: string;
72
+ url?: string;
73
+ images?: {
74
+ url: string;
75
+ }[];
76
+ publishedTime?: string;
77
+ modifiedTime?: string;
78
+ authors?: string[];
79
+ };
80
+ twitter?: {
81
+ card?: "summary" | "summary_large_image";
82
+ title?: string;
83
+ description?: string;
84
+ images?: string[];
85
+ };
86
+ };
87
+ type SitemapItem = {
88
+ url: string;
89
+ lastModified?: string;
90
+ changeFrequency?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never";
91
+ priority?: number;
92
+ };
93
+ type ToMetadataOptions = {
94
+ /** 사이트 origin. 끝 슬래시 없음. e.g. "https://www.reopt.ai" */
95
+ siteUrl: string;
96
+ /** 포스트 URL prefix. 기본 "/blog". */
97
+ basePath?: string;
98
+ };
99
+ type ToSitemapOptions = {
100
+ siteUrl: string;
101
+ /** 포스트 URL prefix. 기본 "/blog". */
102
+ basePath?: string;
103
+ /** 모든 항목에 적용. 기본 "weekly". */
104
+ changeFrequency?: SitemapItem["changeFrequency"];
105
+ /** 모든 항목에 적용. 기본 0.7. */
106
+ priority?: number;
107
+ };
108
+ type ToRssOptions = {
109
+ siteUrl: string;
110
+ /** 채널 제목. */
111
+ title: string;
112
+ /** 채널 설명. */
113
+ description: string;
114
+ /** 포스트 URL prefix. 기본 "/blog". */
115
+ basePath?: string;
116
+ /** 채널 언어 코드. 기본 "ko". */
117
+ language?: string;
118
+ };
119
+ /**
120
+ * Post → Next.js Metadata. Post.seo 필드가 우선이고, 없으면 title/document로
121
+ * fallback. 외부 사용자는 결과를 `Metadata`로 cast하면 그대로 사용 가능.
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * import type { Metadata } from "next";
126
+ *
127
+ * export async function generateMetadata({ params }): Promise<Metadata> {
128
+ * const post = await sdk.cms.posts.getBySlug(params.slug);
129
+ * return toMetadata(post, { siteUrl: "https://www.reopt.ai" });
130
+ * }
131
+ * ```
132
+ */
133
+ declare function toMetadata(post: PostDetail | Post, opts: ToMetadataOptions): SeoMetadata;
134
+ declare function toSitemapItems(posts: Post[], opts: ToSitemapOptions): SitemapItem[];
135
+ declare function toRssFeed(posts: (Post | PostDetail)[], opts: ToRssOptions): string;
136
+
137
+ export { CmsPaginatedResponse, ListPostGroupsQuery, ListPostsQuery, ListTagsQuery, Post, PostDetail, PostGroup, type ReoptCmsClient, type SeoMetadata, type SitemapItem, Tag, type ToMetadataOptions, type ToRssOptions, type ToSitemapOptions, createReoptCmsClient, toMetadata, toRssFeed, toSitemapItems };
@@ -0,0 +1,101 @@
1
+ export { createReoptCmsClient } from '../chunk-WSEROZVO.js';
2
+ import '../chunk-6FLYVNZI.js';
3
+ import '../chunk-DI6QJPTQ.js';
4
+ import '../chunk-J5Y2GSJF.js';
5
+
6
+ // src/cms/helpers.ts
7
+ function joinUrl(siteUrl, path) {
8
+ const base = siteUrl.replace(/\/+$/, "");
9
+ const suffix = path.startsWith("/") ? path : `/${path}`;
10
+ return `${base}${suffix}`;
11
+ }
12
+ function postUrl(post, opts) {
13
+ const basePath = opts.basePath ?? "/blog";
14
+ return joinUrl(opts.siteUrl, `${basePath}/${post.slug}`);
15
+ }
16
+ function escapeXml(input) {
17
+ return input.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
18
+ }
19
+ function cdataSafe(input) {
20
+ return input.replace(/]]>/g, "]]]]><![CDATA[>");
21
+ }
22
+ function toMetadata(post, opts) {
23
+ const url = postUrl(post, opts);
24
+ const title = post.seo?.metaTitle ?? post.title;
25
+ const description = post.seo?.metaDescription ?? ("document" in post ? post.document.content.slice(0, 160) : void 0) ?? void 0;
26
+ const images = post.coverImage?.url ? [{ url: post.coverImage.url }] : void 0;
27
+ const authorName = post.author?.name;
28
+ const meta = {
29
+ title,
30
+ alternates: { canonical: url },
31
+ openGraph: {
32
+ type: "article",
33
+ title,
34
+ description,
35
+ url,
36
+ images,
37
+ publishedTime: post.publishedAt ?? void 0,
38
+ modifiedTime: post.updatedAt,
39
+ authors: authorName ? [authorName] : void 0
40
+ },
41
+ twitter: {
42
+ card: post.coverImage?.url ? "summary_large_image" : "summary",
43
+ title,
44
+ description,
45
+ images: post.coverImage?.url ? [post.coverImage.url] : void 0
46
+ }
47
+ };
48
+ if (description) meta.description = description;
49
+ if (post.seo?.metaKeywords) meta.keywords = post.seo.metaKeywords;
50
+ return meta;
51
+ }
52
+ function toSitemapItems(posts, opts) {
53
+ const changeFrequency = opts.changeFrequency ?? "weekly";
54
+ const priority = opts.priority ?? 0.7;
55
+ return posts.map((post) => ({
56
+ url: postUrl(post, opts),
57
+ lastModified: post.updatedAt,
58
+ changeFrequency,
59
+ priority
60
+ }));
61
+ }
62
+ function toRssFeed(posts, opts) {
63
+ const language = opts.language ?? "ko";
64
+ const channelLink = opts.siteUrl.replace(/\/+$/, "");
65
+ const lastBuildDate = (/* @__PURE__ */ new Date()).toUTCString();
66
+ const items = posts.map((post) => {
67
+ const link = postUrl(post, opts);
68
+ const pubDate = post.publishedAt ? new Date(post.publishedAt).toUTCString() : new Date(post.createdAt).toUTCString();
69
+ const description = post.seo?.metaDescription ?? ("document" in post ? post.document.content.slice(0, 280) : "");
70
+ return [
71
+ " <item>",
72
+ ` <title>${escapeXml(post.title)}</title>`,
73
+ ` <link>${escapeXml(link)}</link>`,
74
+ ` <guid isPermaLink="true">${escapeXml(link)}</guid>`,
75
+ ` <pubDate>${pubDate}</pubDate>`,
76
+ description ? ` <description><![CDATA[${cdataSafe(description)}]]></description>` : "",
77
+ ` <author>${escapeXml(post.author?.name ?? "")}</author>`,
78
+ ...post.tags.map(
79
+ (tag) => ` <category>${escapeXml(tag.text)}</category>`
80
+ ),
81
+ " </item>"
82
+ ].filter((line) => line.length > 0).join("\n");
83
+ }).join("\n");
84
+ return [
85
+ '<?xml version="1.0" encoding="UTF-8"?>',
86
+ '<rss version="2.0">',
87
+ " <channel>",
88
+ ` <title>${escapeXml(opts.title)}</title>`,
89
+ ` <link>${escapeXml(channelLink)}</link>`,
90
+ ` <description>${escapeXml(opts.description)}</description>`,
91
+ ` <language>${escapeXml(language)}</language>`,
92
+ ` <lastBuildDate>${lastBuildDate}</lastBuildDate>`,
93
+ items,
94
+ " </channel>",
95
+ "</rss>"
96
+ ].join("\n");
97
+ }
98
+
99
+ export { toMetadata, toRssFeed, toSitemapItems };
100
+ //# sourceMappingURL=index.js.map
101
+ //# sourceMappingURL=index.js.map