@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.
- package/CHANGELOG.md +147 -0
- package/README.md +39 -14
- package/dist/abort--nOBFN4M.js +50 -0
- package/dist/ai/index.d.ts +2 -314
- package/dist/ai/index.js +3 -7
- package/dist/ai-provider/index.d.ts +79 -163
- package/dist/ai-provider/index.js +752 -671
- package/dist/auth/index.d.ts +27 -27
- package/dist/auth/index.js +41 -33
- package/dist/better-auth/client.d.ts +6 -5
- package/dist/better-auth/client.js +28 -5
- package/dist/better-auth/index.d.ts +19 -17
- package/dist/better-auth/index.js +180 -133
- package/dist/client-B1q5P8rv.js +83 -0
- package/dist/client-B9QHVhdM.js +77 -0
- package/dist/client-BGGd_cpV.d.ts +103 -0
- package/dist/client-BJcy1V1a.js +140 -0
- package/dist/client-Beivhucf.js +55 -0
- package/dist/client-BruP5_nU.d.ts +147 -0
- package/dist/client-D-yNxNfk.js +28 -0
- package/dist/client-D0eBxh8j.d.ts +284 -0
- package/dist/client-D3RHHUUW.d.ts +207 -0
- package/dist/client-D6gs61w8.d.ts +53 -0
- package/dist/client-DBnK7ooQ.js +86 -0
- package/dist/client-DDw5yz_h.d.ts +53 -0
- package/dist/client-DPmoKuR9.js +305 -0
- package/dist/client-DsdakibF.js +503 -0
- package/dist/client-Dxg8_DIH.d.ts +71 -0
- package/dist/client-EbhUIhHq.js +53 -0
- package/dist/client-lk6wBu_0.d.ts +48 -0
- package/dist/client-p49ol9pg.d.ts +124 -0
- package/dist/cms/index.d.ts +52 -108
- package/dist/cms/index.js +105 -84
- package/dist/config-CRytOPPl.d.ts +394 -0
- package/dist/config-Cw0a3-C8.js +487 -0
- package/dist/dev/index.d.ts +2 -509
- package/dist/dev/index.js +2740 -2873
- package/dist/eav/coerce.d.ts +3 -1
- package/dist/eav/coerce.js +72 -46
- package/dist/eav/index.d.ts +72 -100
- package/dist/eav/index.js +158 -125
- package/dist/eav/migrate.d.ts +112 -109
- package/dist/eav/migrate.js +230 -196
- package/dist/eav/schema.d.ts +111 -150
- package/dist/eav/schema.js +624 -603
- package/dist/encoding-Bwfm3iaE.js +21 -0
- package/dist/{errors-DIAS8Rsl.d.ts → errors-CRCcErNC.d.ts} +55 -53
- package/dist/feedback/index.d.ts +2 -132
- package/dist/feedback/index.js +3 -5
- package/dist/files/index.d.ts +14 -14
- package/dist/files/index.js +41 -24
- package/dist/http-client-QKUvvirs.js +386 -0
- package/dist/index-DrVaKfhs.d.ts +456 -0
- package/dist/index-Z6OGcurJ.d.ts +169 -0
- package/dist/index.d.ts +6 -221
- package/dist/index.js +119 -70
- package/dist/logout/index.d.ts +109 -0
- package/dist/logout/index.js +264 -0
- package/dist/plans/index.d.ts +2 -236
- package/dist/plans/index.js +3 -5
- package/dist/push/index.d.ts +2 -79
- package/dist/push/index.js +3 -5
- package/dist/query-BvbCiGWb.js +35 -0
- package/dist/react/hooks.d.ts +97 -95
- package/dist/react/hooks.js +742 -356
- package/dist/sse-parser-FMjxM7sY.js +86 -0
- package/dist/terms/index.d.ts +3 -79
- package/dist/terms/index.js +3 -5
- package/dist/testing/index.d.ts +52 -104
- package/dist/testing/index.js +94 -72
- package/dist/types-B-SMkH6s.d.ts +26 -0
- package/dist/types-BXDcoJHG.d.ts +131 -0
- package/dist/types-BrghN2rJ.d.ts +105 -0
- package/dist/types-DjDRszNj.js +11 -0
- package/dist/webhooks/index.d.ts +77 -47
- package/dist/webhooks/index.js +150 -127
- package/docs/api-reference.md +179 -2
- package/docs/dev-server.md +19 -18
- package/docs/errors.md +72 -15
- package/docs/logout.md +166 -0
- package/package.json +10 -5
- package/dist/chunk-2Q654O63.js +0 -350
- package/dist/chunk-F7BXBTZI.js +0 -54
- package/dist/chunk-IJOXTBIE.js +0 -599
- package/dist/chunk-JWXUVQRC.js +0 -157
- package/dist/chunk-L4DHB36G.js +0 -75
- package/dist/chunk-MRQY45U5.js +0 -465
- package/dist/chunk-N5JVE4WX.js +0 -449
- package/dist/chunk-O3PUWIDJ.js +0 -105
- package/dist/chunk-POLKEOYH.js +0 -63
- package/dist/chunk-R5CCGDUH.js +0 -49
- package/dist/chunk-RBHP7IZF.js +0 -96
- package/dist/chunk-REIKXSMY.js +0 -7
- package/dist/chunk-T7YTITRJ.js +0 -112
- package/dist/chunk-V73GORO3.js +0 -81
- package/dist/chunk-VRNBYSWU.js +0 -32
- package/dist/client-BkcO-0C2.d.ts +0 -216
- package/dist/client-CN5_tNOC.d.ts +0 -147
- package/dist/client-DttyeM_h.d.ts +0 -102
- package/dist/config-CtxyJsDR.d.ts +0 -397
- package/dist/typed-client-BxOVIiMU.d.ts +0 -40
- package/dist/types-6E3ZLL9X.d.ts +0 -24
- package/dist/types-DskYLVb8.d.ts +0 -104
- package/dist/types-ckmDDW3N.d.ts +0 -129
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { n as ReoptSDKConfig } from "./config-CRytOPPl.js";
|
|
2
|
+
//#region src/files/types.d.ts
|
|
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
|
+
//#endregion
|
|
56
|
+
//#region src/files/client.d.ts
|
|
57
|
+
declare class ReoptFileClient {
|
|
58
|
+
private readonly http;
|
|
59
|
+
private readonly timeout;
|
|
60
|
+
constructor(config: ReoptSDKConfig);
|
|
61
|
+
/**
|
|
62
|
+
* 파일 목록 조회
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const { data: files, meta } = await sdk.files.list({
|
|
67
|
+
* page: 1,
|
|
68
|
+
* limit: 20,
|
|
69
|
+
* contentType: "image/*",
|
|
70
|
+
* sortBy: "createdAt",
|
|
71
|
+
* sortOrder: "desc",
|
|
72
|
+
* });
|
|
73
|
+
* console.log(`Total: ${meta.total}`);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
list(query?: FileListQuery): Promise<FileListResponse>;
|
|
77
|
+
/**
|
|
78
|
+
* 단일 파일 조회
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const file = await sdk.files.get("file-uuid");
|
|
83
|
+
* console.log(file.name, file.url);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
get(fileId: string): Promise<FileInfo>;
|
|
87
|
+
/**
|
|
88
|
+
* 파일 삭제
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* await sdk.files.delete("file-uuid");
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
delete(fileId: string): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* 파일 업로드
|
|
98
|
+
*
|
|
99
|
+
* FormData(multipart)로 파일을 전송합니다.
|
|
100
|
+
* BaseHttpClient는 JSON 전용이므로 globalThis.fetch를 직접 사용합니다.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* // Blob 업로드
|
|
105
|
+
* const blob = new Blob(["hello"], { type: "text/plain" });
|
|
106
|
+
* const file = await sdk.files.upload(blob, { name: "hello.txt" });
|
|
107
|
+
*
|
|
108
|
+
* // File 업로드 (브라우저)
|
|
109
|
+
* const file = await sdk.files.upload(inputEl.files[0]);
|
|
110
|
+
*
|
|
111
|
+
* // Buffer 업로드 (Node.js)
|
|
112
|
+
* const buf = fs.readFileSync("image.png");
|
|
113
|
+
* const file = await sdk.files.upload(buf, {
|
|
114
|
+
* name: "image.png",
|
|
115
|
+
* contentType: "image/png",
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
upload(file: Blob | Uint8Array | File, options?: UploadOptions): Promise<FileInfo>;
|
|
120
|
+
}
|
|
121
|
+
declare function createReoptFileClient(config: ReoptSDKConfig): ReoptFileClient;
|
|
122
|
+
//#endregion
|
|
123
|
+
export { FileListResponse as a, FileListQuery as i, createReoptFileClient as n, UploadOptions as o, FileInfo as r, ReoptFileClient as t };
|
|
124
|
+
//# sourceMappingURL=client-p49ol9pg.d.ts.map
|
package/dist/cms/index.d.ts
CHANGED
|
@@ -1,120 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
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
|
-
|
|
1
|
+
import { a as ListTagsQuery, c as PostGroup, d as Tag, i as ListPostsQuery, l as PostSeo, n as EditorSpec, o as Post, r as ListPostGroupsQuery, s as PostDetail, t as CmsPaginatedResponse, u as PostStatus } from "../types-BXDcoJHG.js";
|
|
2
|
+
import { n as createReoptCmsClient, t as ReoptCmsClient } from "../client-DDw5yz_h.js";
|
|
3
|
+
//#region src/cms/helpers.d.ts
|
|
61
4
|
type SeoMetadata = {
|
|
5
|
+
title?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
keywords?: string;
|
|
8
|
+
alternates?: {
|
|
9
|
+
canonical?: string;
|
|
10
|
+
};
|
|
11
|
+
openGraph?: {
|
|
12
|
+
type?: "article" | "website";
|
|
13
|
+
title?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
url?: string;
|
|
16
|
+
images?: {
|
|
17
|
+
url: string;
|
|
18
|
+
}[];
|
|
19
|
+
publishedTime?: string;
|
|
20
|
+
modifiedTime?: string;
|
|
21
|
+
authors?: string[];
|
|
22
|
+
};
|
|
23
|
+
twitter?: {
|
|
24
|
+
card?: "summary" | "summary_large_image";
|
|
62
25
|
title?: string;
|
|
63
26
|
description?: string;
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
};
|
|
27
|
+
images?: string[];
|
|
28
|
+
};
|
|
86
29
|
};
|
|
87
30
|
type SitemapItem = {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
31
|
+
url: string;
|
|
32
|
+
lastModified?: string;
|
|
33
|
+
changeFrequency?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never";
|
|
34
|
+
priority?: number;
|
|
92
35
|
};
|
|
93
36
|
type ToMetadataOptions = {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
37
|
+
/** 사이트 origin. 끝 슬래시 없음. e.g. "https://www.reopt.ai" */
|
|
38
|
+
siteUrl: string;
|
|
39
|
+
/** 포스트 URL prefix. 기본 "/blog". */
|
|
40
|
+
basePath?: string;
|
|
98
41
|
};
|
|
99
42
|
type ToSitemapOptions = {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
43
|
+
siteUrl: string;
|
|
44
|
+
/** 포스트 URL prefix. 기본 "/blog". */
|
|
45
|
+
basePath?: string;
|
|
46
|
+
/** 모든 항목에 적용. 기본 "weekly". */
|
|
47
|
+
changeFrequency?: SitemapItem["changeFrequency"];
|
|
48
|
+
/** 모든 항목에 적용. 기본 0.7. */
|
|
49
|
+
priority?: number;
|
|
107
50
|
};
|
|
108
51
|
type ToRssOptions = {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
52
|
+
siteUrl: string;
|
|
53
|
+
/** 채널 제목. */
|
|
54
|
+
title: string;
|
|
55
|
+
/** 채널 설명. */
|
|
56
|
+
description: string;
|
|
57
|
+
/** 포스트 URL prefix. 기본 "/blog". */
|
|
58
|
+
basePath?: string;
|
|
59
|
+
/** 채널 언어 코드. 기본 "ko". */
|
|
60
|
+
language?: string;
|
|
118
61
|
};
|
|
119
62
|
/**
|
|
120
63
|
* Post → Next.js Metadata. Post.seo 필드가 우선이고, 없으면 title/document로
|
|
@@ -133,5 +76,6 @@ type ToRssOptions = {
|
|
|
133
76
|
declare function toMetadata(post: PostDetail | Post, opts: ToMetadataOptions): SeoMetadata;
|
|
134
77
|
declare function toSitemapItems(posts: Post[], opts: ToSitemapOptions): SitemapItem[];
|
|
135
78
|
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 };
|
|
79
|
+
//#endregion
|
|
80
|
+
export { type CmsPaginatedResponse, type EditorSpec, type ListPostGroupsQuery, type ListPostsQuery, type ListTagsQuery, type Post, type PostDetail, type PostGroup, type PostSeo, type PostStatus, type ReoptCmsClient, type SeoMetadata, type SitemapItem, type Tag, type ToMetadataOptions, type ToRssOptions, type ToSitemapOptions, createReoptCmsClient, toMetadata, toRssFeed, toSitemapItems };
|
|
81
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/cms/index.js
CHANGED
|
@@ -1,101 +1,122 @@
|
|
|
1
|
-
|
|
2
|
-
import '../chunk-VRNBYSWU.js';
|
|
3
|
-
import '../chunk-N5JVE4WX.js';
|
|
4
|
-
import '../chunk-MRQY45U5.js';
|
|
1
|
+
import { t as createReoptCmsClient } from "../client-Beivhucf.js";
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
//#region src/cms/helpers.ts
|
|
7
4
|
function joinUrl(siteUrl, path) {
|
|
8
|
-
|
|
9
|
-
const suffix = path.startsWith("/") ? path : `/${path}`;
|
|
10
|
-
return `${base}${suffix}`;
|
|
5
|
+
return `${siteUrl.replace(/\/+$/, "")}${path.startsWith("/") ? path : `/${path}`}`;
|
|
11
6
|
}
|
|
12
7
|
function postUrl(post, opts) {
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const basePath = opts.basePath ?? "/blog";
|
|
9
|
+
return joinUrl(opts.siteUrl, `${basePath}/${post.slug}`);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* XML 1.0에서 문서 어디에도 올 수 없는 제어문자(C0 제어문자 중 탭·LF·CR 제외)를
|
|
13
|
+
* 제거한다. 이 문자들은 숫자 엔티티로도 표현할 수 없어 이스케이프가 불가능하므로,
|
|
14
|
+
* 하나라도 남으면 피드 전체가 not-well-formed가 되어 모든 항목이 파싱 실패한다.
|
|
15
|
+
* (PDF·워드에서 붙여넣은 텍스트에 \x0B/\x0C가 흔히 섞인다.)
|
|
16
|
+
*/
|
|
17
|
+
function stripXmlInvalidChars(input) {
|
|
18
|
+
return input.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g, "");
|
|
15
19
|
}
|
|
16
20
|
function escapeXml(input) {
|
|
17
|
-
|
|
21
|
+
return stripXmlInvalidChars(input).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
18
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* CDATA 섹션 안에 안전하게 넣도록 `]]>` 종료 시퀀스를 분할한다. 내용에 `]]>`가
|
|
25
|
+
* 포함되면 CDATA가 조기 종료돼 RSS XML이 파손되거나 마크업이 주입될 수 있다.
|
|
26
|
+
* escapeXml을 거치지 않는 경로이므로 여기서도 XML-불법 제어문자를 제거한다.
|
|
27
|
+
*/
|
|
19
28
|
function cdataSafe(input) {
|
|
20
|
-
|
|
29
|
+
return stripXmlInvalidChars(input).replace(/]]>/g, "]]]]><![CDATA[>");
|
|
21
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Post → Next.js Metadata. Post.seo 필드가 우선이고, 없으면 title/document로
|
|
33
|
+
* fallback. 외부 사용자는 결과를 `Metadata`로 cast하면 그대로 사용 가능.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import type { Metadata } from "next";
|
|
38
|
+
*
|
|
39
|
+
* export async function generateMetadata({ params }): Promise<Metadata> {
|
|
40
|
+
* const post = await sdk.cms.posts.getBySlug(params.slug);
|
|
41
|
+
* return toMetadata(post, { siteUrl: "https://www.reopt.ai" });
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
22
45
|
function toMetadata(post, opts) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
const url = postUrl(post, opts);
|
|
47
|
+
const title = post.seo?.metaTitle ?? post.title;
|
|
48
|
+
const description = post.seo?.metaDescription ?? ("document" in post ? post.document.content.slice(0, 160) : void 0) ?? void 0;
|
|
49
|
+
const images = post.coverImage?.url ? [{ url: post.coverImage.url }] : void 0;
|
|
50
|
+
const authorName = post.author?.name;
|
|
51
|
+
const meta = {
|
|
52
|
+
title,
|
|
53
|
+
alternates: { canonical: url },
|
|
54
|
+
openGraph: {
|
|
55
|
+
type: "article",
|
|
56
|
+
title,
|
|
57
|
+
description,
|
|
58
|
+
url,
|
|
59
|
+
images,
|
|
60
|
+
publishedTime: post.publishedAt ?? void 0,
|
|
61
|
+
modifiedTime: post.updatedAt,
|
|
62
|
+
authors: authorName ? [authorName] : void 0
|
|
63
|
+
},
|
|
64
|
+
twitter: {
|
|
65
|
+
card: post.coverImage?.url ? "summary_large_image" : "summary",
|
|
66
|
+
title,
|
|
67
|
+
description,
|
|
68
|
+
images: post.coverImage?.url ? [post.coverImage.url] : void 0
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
if (description) meta.description = description;
|
|
72
|
+
if (post.seo?.metaKeywords) meta.keywords = post.seo.metaKeywords;
|
|
73
|
+
return meta;
|
|
51
74
|
}
|
|
52
75
|
function toSitemapItems(posts, opts) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
76
|
+
const changeFrequency = opts.changeFrequency ?? "weekly";
|
|
77
|
+
const priority = opts.priority ?? .7;
|
|
78
|
+
return posts.map((post) => ({
|
|
79
|
+
url: postUrl(post, opts),
|
|
80
|
+
lastModified: post.updatedAt,
|
|
81
|
+
changeFrequency,
|
|
82
|
+
priority
|
|
83
|
+
}));
|
|
61
84
|
}
|
|
62
85
|
function toRssFeed(posts, opts) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"</rss>"
|
|
96
|
-
].join("\n");
|
|
86
|
+
const language = opts.language ?? "ko";
|
|
87
|
+
const channelLink = opts.siteUrl.replace(/\/+$/, "");
|
|
88
|
+
const lastBuildDate = (/* @__PURE__ */ new Date()).toUTCString();
|
|
89
|
+
const items = posts.map((post) => {
|
|
90
|
+
const link = postUrl(post, opts);
|
|
91
|
+
const pubDate = post.publishedAt ? new Date(post.publishedAt).toUTCString() : new Date(post.createdAt).toUTCString();
|
|
92
|
+
const description = post.seo?.metaDescription ?? ("document" in post ? post.document.content.slice(0, 280) : "");
|
|
93
|
+
return [
|
|
94
|
+
" <item>",
|
|
95
|
+
` <title>${escapeXml(post.title)}</title>`,
|
|
96
|
+
` <link>${escapeXml(link)}</link>`,
|
|
97
|
+
` <guid isPermaLink="true">${escapeXml(link)}</guid>`,
|
|
98
|
+
` <pubDate>${pubDate}</pubDate>`,
|
|
99
|
+
description ? ` <description><![CDATA[${cdataSafe(description)}]]></description>` : "",
|
|
100
|
+
` <author>${escapeXml(post.author?.name ?? "")}</author>`,
|
|
101
|
+
...post.tags.map((tag) => ` <category>${escapeXml(tag.text)}</category>`),
|
|
102
|
+
" </item>"
|
|
103
|
+
].filter((line) => line.length > 0).join("\n");
|
|
104
|
+
}).join("\n");
|
|
105
|
+
return [
|
|
106
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
|
|
107
|
+
"<rss version=\"2.0\">",
|
|
108
|
+
" <channel>",
|
|
109
|
+
` <title>${escapeXml(opts.title)}</title>`,
|
|
110
|
+
` <link>${escapeXml(channelLink)}</link>`,
|
|
111
|
+
` <description>${escapeXml(opts.description)}</description>`,
|
|
112
|
+
` <language>${escapeXml(language)}</language>`,
|
|
113
|
+
` <lastBuildDate>${lastBuildDate}</lastBuildDate>`,
|
|
114
|
+
items,
|
|
115
|
+
" </channel>",
|
|
116
|
+
"</rss>"
|
|
117
|
+
].join("\n");
|
|
97
118
|
}
|
|
98
119
|
|
|
99
|
-
|
|
100
|
-
|
|
120
|
+
//#endregion
|
|
121
|
+
export { createReoptCmsClient, toMetadata, toRssFeed, toSitemapItems };
|
|
101
122
|
//# sourceMappingURL=index.js.map
|