@spfn/cms 0.1.0-alpha.63 → 0.1.0-alpha.65

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 (103) hide show
  1. package/README.md +67 -30
  2. package/dist/actions-CwvmPG0e.d.ts +296 -0
  3. package/dist/actions.d.ts +1 -143
  4. package/dist/actions.js +5 -5
  5. package/dist/actions.js.map +1 -1
  6. package/dist/api.d.ts +376 -0
  7. package/dist/api.js +364 -0
  8. package/dist/api.js.map +1 -0
  9. package/dist/client.d.ts +115 -141
  10. package/dist/client.js +860 -63
  11. package/dist/client.js.map +1 -1
  12. package/dist/{types.d.ts → index-Dh5FjWzR.d.ts} +32 -1
  13. package/dist/index.d.ts +21 -43
  14. package/dist/index.js +556 -1061
  15. package/dist/index.js.map +1 -1
  16. package/dist/label-sync-generator-B0EmvtWM.d.ts +32 -0
  17. package/dist/{contracts → lib/contracts}/labels.d.ts +13 -12
  18. package/dist/{contracts → lib/contracts}/labels.js +7 -7
  19. package/dist/lib/contracts/labels.js.map +1 -0
  20. package/dist/{contracts → lib/contracts}/published-cache.d.ts +3 -2
  21. package/dist/{contracts → lib/contracts}/published-cache.js +2 -2
  22. package/dist/lib/contracts/published-cache.js.map +1 -0
  23. package/dist/{contracts → lib/contracts}/values.d.ts +6 -4
  24. package/dist/{contracts → lib/contracts}/values.js +3 -3
  25. package/dist/lib/contracts/values.js.map +1 -0
  26. package/dist/{entities → server/entities}/cms-audit-logs.js +3 -3
  27. package/dist/server/entities/cms-audit-logs.js.map +1 -0
  28. package/dist/{entities → server/entities}/cms-draft-cache.js +1 -1
  29. package/dist/server/entities/cms-draft-cache.js.map +1 -0
  30. package/dist/{entities → server/entities}/cms-label-values.js +3 -3
  31. package/dist/server/entities/cms-label-values.js.map +1 -0
  32. package/dist/{entities → server/entities}/cms-label-versions.js +3 -3
  33. package/dist/server/entities/cms-label-versions.js.map +1 -0
  34. package/dist/{entities → server/entities}/cms-labels.js +1 -1
  35. package/dist/server/entities/cms-labels.js.map +1 -0
  36. package/dist/{entities → server/entities}/cms-published-cache.js +1 -1
  37. package/dist/server/entities/cms-published-cache.js.map +1 -0
  38. package/dist/{entities → server/entities}/index.js +6 -6
  39. package/dist/server/entities/index.js.map +1 -0
  40. package/dist/{generators → server/generators}/index.d.ts +1 -2
  41. package/dist/{generators → server/generators}/index.js +169 -75
  42. package/dist/server/generators/index.js.map +1 -0
  43. package/dist/server/labels/index.d.ts +1 -0
  44. package/dist/{labels → server/labels}/index.js +1 -1
  45. package/dist/server/labels/index.js.map +1 -0
  46. package/dist/{repositories → server/repositories}/index.js +11 -11
  47. package/dist/server/repositories/index.js.map +1 -0
  48. package/dist/{routes → server/routes}/labels/[id]/index.js +20 -20
  49. package/dist/server/routes/labels/[id]/index.js.map +1 -0
  50. package/dist/{routes → server/routes}/labels/by-key/[key]/index.js +20 -20
  51. package/dist/server/routes/labels/by-key/[key]/index.js.map +1 -0
  52. package/dist/{routes → server/routes}/labels/index.d.ts +2 -2
  53. package/dist/{routes → server/routes}/labels/index.js +21 -22
  54. package/dist/server/routes/labels/index.js.map +1 -0
  55. package/dist/{routes → server/routes}/published-cache/index.js +14 -14
  56. package/dist/server/routes/published-cache/index.js.map +1 -0
  57. package/dist/{routes → server/routes}/values/[labelId]/[version]/index.js +16 -16
  58. package/dist/server/routes/values/[labelId]/[version]/index.js.map +1 -0
  59. package/dist/{routes → server/routes}/values/[labelId]/index.js +16 -16
  60. package/dist/server/routes/values/[labelId]/index.js.map +1 -0
  61. package/dist/server.d.ts +76 -7
  62. package/dist/server.js +1601 -42
  63. package/dist/server.js.map +1 -1
  64. package/package.json +37 -35
  65. package/dist/contracts/labels.js.map +0 -1
  66. package/dist/contracts/published-cache.js.map +0 -1
  67. package/dist/contracts/values.js.map +0 -1
  68. package/dist/entities/cms-audit-logs.js.map +0 -1
  69. package/dist/entities/cms-draft-cache.js.map +0 -1
  70. package/dist/entities/cms-label-values.js.map +0 -1
  71. package/dist/entities/cms-label-versions.js.map +0 -1
  72. package/dist/entities/cms-labels.js.map +0 -1
  73. package/dist/entities/cms-published-cache.js.map +0 -1
  74. package/dist/entities/index.js.map +0 -1
  75. package/dist/generators/index.js.map +0 -1
  76. package/dist/label-sync-generator-lQrcVfja.d.ts +0 -36
  77. package/dist/labels/index.d.ts +0 -34
  78. package/dist/labels/index.js.map +0 -1
  79. package/dist/repositories/index.js.map +0 -1
  80. package/dist/routes/labels/[id]/index.js.map +0 -1
  81. package/dist/routes/labels/by-key/[key]/index.js.map +0 -1
  82. package/dist/routes/labels/index.js.map +0 -1
  83. package/dist/routes/published-cache/index.js.map +0 -1
  84. package/dist/routes/values/[labelId]/[version]/index.js.map +0 -1
  85. package/dist/routes/values/[labelId]/index.js.map +0 -1
  86. package/dist/store.d.ts +0 -81
  87. package/dist/store.js +0 -403
  88. package/dist/store.js.map +0 -1
  89. package/dist/types.js +0 -1
  90. package/dist/types.js.map +0 -1
  91. package/dist/{entities → server/entities}/cms-audit-logs.d.ts +0 -0
  92. package/dist/{entities → server/entities}/cms-draft-cache.d.ts +0 -0
  93. package/dist/{entities → server/entities}/cms-label-values.d.ts +0 -0
  94. package/dist/{entities → server/entities}/cms-label-versions.d.ts +0 -0
  95. package/dist/{entities → server/entities}/cms-labels.d.ts +0 -0
  96. package/dist/{entities → server/entities}/cms-published-cache.d.ts +0 -0
  97. package/dist/{entities → server/entities}/index.d.ts +0 -0
  98. package/dist/{repositories → server/repositories}/index.d.ts +7 -7
  99. /package/dist/{routes → server/routes}/labels/_id_/index.d.ts +0 -0
  100. /package/dist/{routes → server/routes}/labels/by-key/_key_/index.d.ts +0 -0
  101. /package/dist/{routes → server/routes}/published-cache/index.d.ts +0 -0
  102. /package/dist/{routes → server/routes}/values/_labelId_/_version_/index.d.ts +0 -0
  103. /package/dist/{routes → server/routes}/values/_labelId_/index.d.ts +0 -0
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // src/cms.config.ts
1
+ // src/server/config/cms.config.ts
2
2
  function getEnvVar(key, defaultValue) {
3
3
  return process.env[key] || defaultValue;
4
4
  }
@@ -10,7 +10,7 @@ function getEnvBoolean(key, defaultValue) {
10
10
  function loadConfigFromEnv() {
11
11
  const defaultLocale = getEnvVar("SPFN_CMS_DEFAULT_LOCALE", "en");
12
12
  const supportedLocalesStr = getEnvVar("SPFN_CMS_SUPPORTED_LOCALES", "en,ko");
13
- const detectBrowserLanguage2 = getEnvBoolean("SPFN_CMS_DETECT_BROWSER_LANGUAGE", true);
13
+ const detectBrowserLanguage = getEnvBoolean("SPFN_CMS_DETECT_BROWSER_LANGUAGE", true);
14
14
  const supportedLocales = supportedLocalesStr.split(",").map((locale) => locale.trim()).filter((locale) => locale.length > 0);
15
15
  if (!supportedLocales.includes(defaultLocale)) {
16
16
  supportedLocales.unshift(defaultLocale);
@@ -18,7 +18,7 @@ function loadConfigFromEnv() {
18
18
  return {
19
19
  defaultLocale,
20
20
  supportedLocales,
21
- detectBrowserLanguage: detectBrowserLanguage2
21
+ detectBrowserLanguage
22
22
  };
23
23
  }
24
24
  var currentConfig = loadConfigFromEnv();
@@ -42,1075 +42,570 @@ function resetCmsConfig() {
42
42
  currentConfig = loadConfigFromEnv();
43
43
  }
44
44
 
45
- // src/server.ts
46
- import { cache } from "react";
47
- import { client } from "@spfn/core/client";
45
+ // src/lib/constants/index.ts
46
+ var DEFAULT_LABELS_DIR = "src/lib/labels";
48
47
 
49
- // src/contracts/published-cache.ts
50
- import { Type } from "@sinclair/typebox";
51
- var SectionData = Type.Object({
52
- section: Type.String(),
53
- locale: Type.String(),
54
- content: Type.Record(Type.String(), Type.Any()),
55
- version: Type.Number(),
56
- publishedAt: Type.Union([Type.String(), Type.Null()])
57
- });
58
- var getPublishedCacheContract = {
59
- method: "GET",
60
- path: "/cms/published-cache",
61
- query: Type.Object({
62
- sections: Type.Union([
63
- Type.String({ description: "\uB2E8\uC77C \uC139\uC158 \uC774\uB984 (\uC608: home)" }),
64
- Type.Array(Type.String(), { description: '\uC5EC\uB7EC \uC139\uC158 \uC774\uB984 (\uC608: ["home", "footer"])' })
65
- ]),
66
- locale: Type.Optional(Type.String({ default: "ko", description: "\uC5B8\uC5B4 \uCF54\uB4DC" }))
67
- }),
68
- response: Type.Union([
69
- // 성공: 항상 배열로 반환
70
- Type.Array(SectionData),
71
- // 에러
72
- Type.Object({
73
- error: Type.String()
74
- })
75
- ])
76
- };
77
-
78
- // src/helpers/locale.actions.ts
79
- import { cookies, headers } from "next/headers.js";
80
-
81
- // src/helpers/locale.constants.ts
48
+ // src/lib/constants/locale.constants.ts
82
49
  var LOCALE_COOKIE_KEY = "spfn-locale";
83
-
84
- // src/helpers/locale.actions.ts
85
- async function detectBrowserLanguage() {
86
- try {
87
- const headersList = await headers();
88
- const acceptLanguage = headersList.get("accept-language");
89
- if (!acceptLanguage) {
90
- return null;
91
- }
92
- const languages = acceptLanguage.split(",").map((lang) => {
93
- const [code] = lang.split(";");
94
- return code.split("-")[0].trim();
95
- });
96
- const config = getCmsConfig();
97
- for (const lang of languages) {
98
- if (config.supportedLocales.includes(lang)) {
99
- return lang;
100
- }
101
- }
102
- return null;
103
- } catch (error) {
104
- return null;
105
- }
106
- }
107
- async function getLocale() {
108
- const config = getCmsConfig();
109
- const cookieStore = await cookies();
110
- const cookieLocale = cookieStore.get(LOCALE_COOKIE_KEY)?.value;
111
- if (cookieLocale && config.supportedLocales.includes(cookieLocale)) {
112
- return cookieLocale;
113
- }
114
- if (config.detectBrowserLanguage) {
115
- const browserLang = await detectBrowserLanguage();
116
- if (browserLang) {
117
- return browserLang;
118
- }
119
- }
120
- return config.defaultLocale;
121
- }
122
-
123
- // src/server.ts
124
- function replaceVariables(text7, replace) {
125
- return text7.replace(/\{(\w+)}/g, (match, key) => {
126
- const value = replace[key];
127
- return value !== void 0 ? String(value) : match;
128
- });
129
- }
130
- var getSection = cache(async (section, locale) => {
131
- const actualLocale = locale ?? await getLocale();
132
- try {
133
- const response = await client.call(
134
- getPublishedCacheContract,
135
- {
136
- query: { sections: section, locale: actualLocale }
137
- }
138
- );
139
- if ("error" in response) {
140
- console.warn(`[CMS] ${response.error}`);
141
- const sectionData2 = {
142
- section,
143
- locale: actualLocale,
144
- content: {},
145
- version: 0,
146
- publishedAt: null
147
- };
148
- const t2 = (_key, defaultValue) => defaultValue ?? "";
149
- return { t: t2, data: sectionData2 };
150
- }
151
- const found = response[0];
152
- if (!found) {
153
- const sectionData2 = {
154
- section,
155
- locale: actualLocale,
156
- content: {},
157
- version: 0,
158
- publishedAt: null
159
- };
160
- const t2 = (_key, defaultValue) => defaultValue ?? "";
161
- return { t: t2, data: sectionData2 };
162
- }
163
- const sectionData = {
164
- section: found.section,
165
- locale: found.locale,
166
- content: found.content || {},
167
- version: found.version,
168
- publishedAt: found.publishedAt
169
- };
170
- const t = (key, defaultValue, replace) => {
171
- const fullKey = `${section}.${key}`;
172
- let value = sectionData.content[fullKey];
173
- if (value === void 0 || value === null) {
174
- value = defaultValue ?? "";
175
- }
176
- if (typeof value !== "string") {
177
- return "";
178
- }
179
- if (replace) {
180
- value = replaceVariables(value, replace);
181
- }
182
- return value;
183
- };
184
- return {
185
- t,
186
- data: sectionData
187
- };
188
- } catch (error) {
189
- console.error(`[CMS] Failed to fetch section "${section}":`, error);
190
- const sectionData = {
191
- section,
192
- locale: actualLocale,
193
- content: {},
194
- version: 0,
195
- publishedAt: null
196
- };
197
- const t = (_key, defaultValue) => defaultValue ?? "";
198
- return { t, data: sectionData };
199
- }
200
- });
201
- var getSections = cache(async (sections, locale) => {
202
- const actualLocale = locale ?? await getLocale();
203
- try {
204
- const response = await client.call(
205
- getPublishedCacheContract,
206
- {
207
- query: { sections, locale: actualLocale }
208
- }
209
- );
210
- if ("error" in response) {
211
- console.warn(`[CMS] ${response.error}`);
212
- const sectionsMap2 = {};
213
- sections.forEach((section) => {
214
- sectionsMap2[section] = {
215
- t: (_key, defaultValue) => defaultValue ?? "",
216
- data: {
217
- section,
218
- locale: actualLocale,
219
- content: {},
220
- version: 0,
221
- publishedAt: null
222
- }
223
- };
224
- });
225
- return sectionsMap2;
226
- }
227
- const sectionsMap = {};
228
- sections.forEach((section) => {
229
- sectionsMap[section] = {
230
- t: (_key, defaultValue) => defaultValue ?? "",
231
- data: {
232
- section,
233
- locale: actualLocale,
234
- content: {},
235
- version: 0,
236
- publishedAt: null
237
- }
238
- };
239
- });
240
- response.forEach((sectionData) => {
241
- const createTranslationFn = (section, content) => {
242
- return (key, defaultValue, replace) => {
243
- const fullKey = `${section}.${key}`;
244
- let value = content[fullKey];
245
- if (value === void 0 || value === null) {
246
- value = defaultValue ?? "";
247
- }
248
- if (typeof value !== "string") {
249
- return "";
250
- }
251
- if (replace) {
252
- value = replaceVariables(value, replace);
253
- }
254
- return value;
255
- };
256
- };
257
- sectionsMap[sectionData.section] = {
258
- t: createTranslationFn(sectionData.section, sectionData.content),
259
- data: {
260
- section: sectionData.section,
261
- locale: sectionData.locale,
262
- content: sectionData.content,
263
- version: sectionData.version,
264
- publishedAt: sectionData.publishedAt
265
- }
266
- };
267
- });
268
- return sectionsMap;
269
- } catch (error) {
270
- console.error(`[CMS] Failed to fetch sections:`, error);
271
- const sectionsMap = {};
272
- sections.forEach((section) => {
273
- sectionsMap[section] = {
274
- t: (_key, defaultValue) => defaultValue ?? "",
275
- data: {
276
- section,
277
- locale: actualLocale,
278
- content: {},
279
- version: 0,
280
- publishedAt: null
281
- }
282
- };
283
- });
284
- return sectionsMap;
285
- }
286
- });
287
-
288
- // src/repositories/cms-labels.repository.ts
289
- import { findOne, findMany as findManyHelper, create as createHelper, updateOne, deleteOne, count as countHelper } from "@spfn/core/db";
290
- import { desc } from "drizzle-orm";
291
-
292
- // src/entities/cms-labels.ts
293
- import { index, integer, serial, text, timestamp } from "drizzle-orm/pg-core";
294
- import { createFunctionSchema } from "@spfn/core/db";
295
- var schema = createFunctionSchema("@spfn/cms");
296
- var cmsLabels = schema.table("labels", {
297
- // Primary Key
298
- id: serial("id").primaryKey(),
299
- // 라벨 식별자
300
- key: text("key").notNull().unique(),
301
- // 예: "home.hero.title", "why-futureplay.hero.subtitle"
302
- // 구조: {section}.{component}.{property}
303
- // 섹션 분류 (페이지 단위)
304
- section: text("section").notNull(),
305
- // 예: "home", "why-futureplay", "team"
306
- // 값 타입
307
- type: text("type").notNull(),
308
- // "text" | "image" | "video" | "file" | "object"
309
- // 기본값
310
- defaultValue: text("default_value"),
311
- // 라벨의 기본값 (sync 시 설정)
312
- // 설명
313
- description: text("description"),
314
- // 라벨에 대한 설명 (optional)
315
- // 현재 발행된 버전 번호
316
- publishedVersion: integer("published_version"),
317
- // null = 미발행 상태
318
- // 1, 2, 3... = 발행된 버전 번호
319
- // 생성자 추적
320
- createdBy: text("created_by"),
321
- // 타임스탬프
322
- createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
323
- updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
324
- }, (table) => [
325
- // 인덱스: 섹션별 조회 최적화
326
- index("cms_labels_section_idx").on(table.section),
327
- // 인덱스: key로 조회 최적화 (unique 제약으로 자동 생성되지만 명시)
328
- index("cms_labels_key_idx").on(table.key)
329
- ]);
330
-
331
- // src/entities/cms-label-values.ts
332
- import { serial as serial2, integer as integer2, text as text2, jsonb, timestamp as timestamp2, index as index2, unique } from "drizzle-orm/pg-core";
333
- import { createFunctionSchema as createFunctionSchema2 } from "@spfn/core/db";
334
- var schema2 = createFunctionSchema2("@spfn/cms");
335
- var cmsLabelValues = schema2.table("label_values", {
336
- // Primary Key
337
- id: serial2("id").primaryKey(),
338
- // Foreign Key: cms_labels
339
- labelId: integer2("label_id").notNull().references(() => cmsLabels.id, { onDelete: "cascade" }),
340
- // 버전 번호
341
- version: integer2("version").notNull().default(1),
342
- // 언어 코드
343
- locale: text2("locale").notNull().default("ko"),
344
- // "ko" | "en" | "ja"
345
- // 반응형 브레이크포인트
346
- breakpoint: text2("breakpoint"),
347
- // null = 기본값 (모든 화면 크기)
348
- // "sm" | "md" | "lg" | "xl" | "2xl"
349
- // 실제 (JSONB)
350
- value: jsonb("value").notNull(),
351
- // LabelValue 타입:
352
- // - TextValue: { type: "text", content: string }
353
- // - ImageValue: { type: "image", url: string, alt?: string, width?: number, height?: number }
354
- // - VideoValue: { type: "video", url: string, thumbnail?: string, duration?: number }
355
- // - FileValue: { type: "file", url: string, filename: string, size?: number }
356
- // - ObjectValue: { type: "object", fields: Record<string, LabelValue> }
357
- // 생성 시각
358
- createdAt: timestamp2("created_at", { withTimezone: true }).notNull().defaultNow()
359
- }, (table) => [
360
- // UNIQUE 제약: 같은 버전에서 locale + breakpoint 조합은 유일
361
- unique("cms_label_values_locale_breakpoint_unique").on(table.labelId, table.version, table.locale, table.breakpoint),
362
- // 인덱스: labelId + version 복합 조회 최적화
363
- index2("cms_label_values_label_version_idx").on(table.labelId, table.version),
364
- // 인덱스: locale 필터링 최적화
365
- index2("cms_label_values_locale_idx").on(table.locale)
366
- ]);
367
-
368
- // src/entities/cms-label-versions.ts
369
- import { serial as serial3, integer as integer3, text as text3, timestamp as timestamp3, index as index3, unique as unique2 } from "drizzle-orm/pg-core";
370
- import { createFunctionSchema as createFunctionSchema3 } from "@spfn/core/db";
371
- var schema3 = createFunctionSchema3("@spfn/cms");
372
- var cmsLabelVersions = schema3.table("label_versions", {
373
- // Primary Key
374
- id: serial3("id").primaryKey(),
375
- // Foreign Key: cms_labels
376
- labelId: integer3("label_id").notNull().references(() => cmsLabels.id, { onDelete: "cascade" }),
377
- // 버전 번호
378
- version: integer3("version").notNull(),
379
- // 버전 상태
380
- status: text3("status").notNull(),
381
- // "draft" | "published" | "archived"
382
- // 발행 정보
383
- publishedAt: timestamp3("published_at", { withTimezone: true }),
384
- publishedBy: text3("published_by"),
385
- // 버전 노트 (변경사항 설명)
386
- notes: text3("notes"),
387
- // 버전 생성자
388
- createdBy: text3("created_by"),
389
- // 생성 시각
390
- createdAt: timestamp3("created_at", { withTimezone: true }).notNull().defaultNow()
391
- }, (table) => [
392
- // UNIQUE 제약: 각 라벨의 버전 번호는 고유
393
- unique2("cms_label_versions_label_version_unique").on(table.labelId, table.version),
394
- // 인덱스: labelId로 버전 목록 조회 최적화
395
- index3("cms_label_versions_label_id_idx").on(table.labelId),
396
- // 인덱스: status 필터링 최적화
397
- index3("cms_label_versions_status_idx").on(table.status)
398
- ]);
399
-
400
- // src/entities/cms-draft-cache.ts
401
- import { serial as serial4, text as text4, jsonb as jsonb2, timestamp as timestamp4, index as index4, unique as unique3 } from "drizzle-orm/pg-core";
402
- import { createFunctionSchema as createFunctionSchema4 } from "@spfn/core/db";
403
- var schema4 = createFunctionSchema4("@spfn/cms");
404
- var cmsDraftCache = schema4.table("draft_cache", {
405
- // Primary Key
406
- id: serial4("id").primaryKey(),
407
- // 섹션 (페이지 단위)
408
- section: text4("section").notNull(),
409
- // "home" | "why-futureplay" | "team" | "our-companies" | "apply"
410
- // 언어
411
- locale: text4("locale").notNull(),
412
- // "ko" | "en" | "ja"
413
- // 사용자 ID (핵심 필드!)
414
- userId: text4("user_id").notNull(),
415
- // 각 관리자의 독립적인 작업 공간
416
- // Draft 콘텐츠 (JSONB)
417
- content: jsonb2("content").notNull(),
418
- // Record<string, LabelValue>
419
- // {
420
- // "home.hero.title": { type: "text", content: "수정 중..." },
421
- // "home.hero.subtitle": { type: "text", content: "새로운 문구" },
422
- // ...
423
- // }
424
- // 최종 수정 시각
425
- updatedAt: timestamp4("updated_at", { withTimezone: true }).notNull().defaultNow()
426
- }, (table) => [
427
- // UNIQUE 제약: section + locale + userId 조합은 유일
428
- unique3("cms_draft_cache_unique").on(table.section, table.locale, table.userId),
429
- // 인덱스: section으로 조회 최적화
430
- index4("cms_draft_cache_section_idx").on(table.section),
431
- // 인덱스: userId로 사용자의 모든 draft 조회 최적화
432
- index4("cms_draft_cache_user_idx").on(table.userId)
433
- ]);
434
-
435
- // src/entities/cms-published-cache.ts
436
- import { serial as serial5, text as text5, jsonb as jsonb3, integer as integer4, timestamp as timestamp5, index as index5, unique as unique4 } from "drizzle-orm/pg-core";
437
- import { createFunctionSchema as createFunctionSchema5 } from "@spfn/core/db";
438
- var schema5 = createFunctionSchema5("@spfn/cms");
439
- var cmsPublishedCache = schema5.table("published_cache", {
440
- // Primary Key
441
- id: serial5("id").primaryKey(),
442
- // 섹션 (페이지 단위)
443
- section: text5("section").notNull(),
444
- // "home" | "why-futureplay" | "team" | "our-companies" | "apply"
445
- // 언어
446
- locale: text5("locale").notNull(),
447
- // "ko" | "en" | "ja"
448
- // 캐시된 콘텐츠 (JSONB)
449
- content: jsonb3("content").notNull(),
450
- // Record<string, LabelValue>
451
- // {
452
- // "home.hero.title": { type: "text", content: "..." },
453
- // "home.hero.image": { type: "image", url: "...", alt: "..." },
454
- // ...
455
- // }
456
- // 발행 정보
457
- publishedAt: timestamp5("published_at", { withTimezone: true }).notNull(),
458
- publishedBy: text5("published_by"),
459
- // 캐시 버전 (클라이언트 캐싱용)
460
- version: integer4("version").notNull().default(1)
461
- }, (table) => [
462
- // UNIQUE 제약: section + locale 조합은 유일
463
- unique4("cms_published_cache_unique").on(table.section, table.locale),
464
- // 인덱스: section으로 조회 최적화
465
- index5("cms_published_cache_section_idx").on(table.section)
466
- ]);
467
-
468
- // src/entities/cms-audit-logs.ts
469
- import { serial as serial6, integer as integer5, text as text6, jsonb as jsonb4, timestamp as timestamp6, index as index6 } from "drizzle-orm/pg-core";
470
- import { createFunctionSchema as createFunctionSchema6 } from "@spfn/core/db";
471
- var schema6 = createFunctionSchema6("@spfn/cms");
472
- var cmsAuditLogs = schema6.table("audit_logs", {
473
- // Primary Key
474
- id: serial6("id").primaryKey(),
475
- // Foreign Key: cms_labels (nullable - 라벨 삭제 시 로그는 유지)
476
- labelId: integer5("label_id").references(() => cmsLabels.id, { onDelete: "set null" }),
477
- // 작업 유형
478
- action: text6("action").notNull(),
479
- // "create" | "update" | "publish" | "unpublish" | "archive" | "delete" | "rollback" | "duplicate"
480
- // 사용자 정보
481
- userId: text6("user_id").notNull(),
482
- userName: text6("user_name"),
483
- // 변경 내용 (before/after)
484
- changes: jsonb4("changes"),
485
- // { before: {...}, after: {...} }
486
- // 추가 메타데이터
487
- metadata: jsonb4("metadata"),
488
- // { version: number, ip: string, userAgent: string, ... }
489
- // 작업 시각
490
- createdAt: timestamp6("created_at", { withTimezone: true }).notNull().defaultNow()
491
- }, (table) => [
492
- // 인덱스: labelId로 이력 조회 최적화
493
- index6("cms_audit_logs_label_id_idx").on(table.labelId),
494
- // 인덱스: userId로 사용자 활동 조회 최적화
495
- index6("cms_audit_logs_user_id_idx").on(table.userId),
496
- // 인덱스: action 필터링 최적화
497
- index6("cms_audit_logs_action_idx").on(table.action),
498
- // 인덱스: 시간순 조회 최적화
499
- index6("cms_audit_logs_created_at_idx").on(table.createdAt)
500
- ]);
501
-
502
- // src/repositories/cms-labels.repository.ts
503
- async function findMany(options) {
504
- const { section, limit = 20, offset = 0 } = options || {};
505
- return findManyHelper(cmsLabels, {
506
- where: section ? { section } : void 0,
507
- orderBy: desc(cmsLabels.updatedAt),
508
- limit,
509
- offset
510
- });
511
- }
512
- async function count(section) {
513
- return countHelper(cmsLabels, section ? { section } : void 0);
514
- }
515
- async function findById(id) {
516
- return findOne(cmsLabels, { id });
517
- }
518
- async function findByKey(key) {
519
- return findOne(cmsLabels, { key });
520
- }
521
- async function findBySection(section) {
522
- return findManyHelper(cmsLabels, {
523
- where: { section },
524
- orderBy: desc(cmsLabels.updatedAt)
525
- });
526
- }
527
- async function create(data) {
528
- return createHelper(cmsLabels, data);
529
- }
530
- async function updateById(id, data) {
531
- return updateOne(cmsLabels, { id }, { ...data, updatedAt: /* @__PURE__ */ new Date() });
532
- }
533
- async function deleteById(id) {
534
- return deleteOne(cmsLabels, { id });
535
- }
536
- var cmsLabelsRepository = {
537
- findMany,
538
- count,
539
- findById,
540
- findByKey,
541
- findBySection,
542
- create,
543
- updateById,
544
- deleteById
545
- };
546
-
547
- // src/repositories/cms-label-values.repository.ts
548
- import { findOne as findOne2, findMany as findMany2, create as create2, updateOne as updateOne2, deleteMany } from "@spfn/core/db";
549
- import { eq, and, isNull } from "drizzle-orm";
550
- async function findByLabelIdAndVersion(labelId, version, options) {
551
- const { locale, breakpoint } = options || {};
552
- const conditions = [
553
- eq(cmsLabelValues.labelId, labelId),
554
- eq(cmsLabelValues.version, version)
555
- ];
556
- if (locale) {
557
- conditions.push(eq(cmsLabelValues.locale, locale));
558
- }
559
- if (breakpoint !== void 0) {
560
- conditions.push(
561
- breakpoint === null ? isNull(cmsLabelValues.breakpoint) : eq(cmsLabelValues.breakpoint, breakpoint)
562
- );
563
- }
564
- return findMany2(cmsLabelValues, {
565
- where: and(...conditions)
566
- });
567
- }
568
- async function upsert(data) {
569
- const existing = await findOne2(
570
- cmsLabelValues,
571
- and(
572
- eq(cmsLabelValues.labelId, data.labelId),
573
- eq(cmsLabelValues.version, data.version ?? 1),
574
- eq(cmsLabelValues.locale, data.locale || "ko"),
575
- data.breakpoint ? eq(cmsLabelValues.breakpoint, data.breakpoint) : isNull(cmsLabelValues.breakpoint)
576
- )
577
- );
578
- if (existing) {
579
- const updated = await updateOne2(
580
- cmsLabelValues,
581
- { id: existing.id },
582
- { value: data.value }
583
- );
584
- return updated;
585
- } else {
586
- return create2(cmsLabelValues, data);
587
- }
588
- }
589
- async function upsertMany(values) {
590
- const results = [];
591
- for (const value of values) {
592
- const result = await upsert(value);
593
- results.push(result);
594
- }
595
- return results;
596
- }
597
- async function deleteByVersion(labelId, version) {
598
- return deleteMany(
599
- cmsLabelValues,
600
- and(
601
- eq(cmsLabelValues.labelId, labelId),
602
- eq(cmsLabelValues.version, version)
603
- )
604
- );
605
- }
606
- var cmsLabelValuesRepository = {
607
- findByLabelIdAndVersion,
608
- upsert,
609
- upsertMany,
610
- deleteByVersion
611
- };
612
-
613
- // src/repositories/cms-draft-cache.repository.ts
614
- import { findOne as findOne3, findMany as findMany3, deleteOne as deleteOne2, deleteMany as deleteMany2, upsert as upsertHelper } from "@spfn/core/db";
615
- import { eq as eq2, and as and2, lt } from "drizzle-orm";
616
- async function findByUser(section, locale, userId) {
617
- return findOne3(
618
- cmsDraftCache,
619
- and2(
620
- eq2(cmsDraftCache.section, section),
621
- eq2(cmsDraftCache.locale, locale),
622
- eq2(cmsDraftCache.userId, userId)
623
- )
624
- );
625
- }
626
- async function upsert2(data) {
627
- return upsertHelper(cmsDraftCache, data, {
628
- target: [cmsDraftCache.section, cmsDraftCache.locale, cmsDraftCache.userId],
629
- set: {
630
- content: data.content,
631
- updatedAt: /* @__PURE__ */ new Date()
632
- }
633
- });
634
- }
635
- async function findAllByUser(userId) {
636
- return findMany3(cmsDraftCache, {
637
- where: eq2(cmsDraftCache.userId, userId)
638
- });
639
- }
640
- async function deleteByUser(section, locale, userId) {
641
- await deleteOne2(
642
- cmsDraftCache,
643
- and2(
644
- eq2(cmsDraftCache.section, section),
645
- eq2(cmsDraftCache.locale, locale),
646
- eq2(cmsDraftCache.userId, userId)
647
- )
648
- );
649
- }
650
- async function cleanupOldDrafts(daysOld = 30) {
651
- const cutoffDate = /* @__PURE__ */ new Date();
652
- cutoffDate.setDate(cutoffDate.getDate() - daysOld);
653
- return deleteMany2(
654
- cmsDraftCache,
655
- lt(cmsDraftCache.updatedAt, cutoffDate)
656
- );
657
- }
658
- var cmsDraftCacheRepository = {
659
- findByUser,
660
- upsert: upsert2,
661
- findAllByUser,
662
- deleteByUser,
663
- cleanupOldDrafts
664
- };
665
-
666
- // src/repositories/cms-published-cache.repository.ts
667
- import { findOne as findOne4, findMany as findMany4, deleteOne as deleteOne3, deleteMany as deleteMany3, upsert as upsertHelper2 } from "@spfn/core/db";
668
- import { eq as eq3, and as and3, sql } from "drizzle-orm";
669
- async function findBySection2(section, locale = "ko") {
670
- return findOne4(
671
- cmsPublishedCache,
672
- and3(
673
- eq3(cmsPublishedCache.section, section),
674
- eq3(cmsPublishedCache.locale, locale)
675
- )
676
- );
677
- }
678
- async function upsert3(data) {
679
- return upsertHelper2(cmsPublishedCache, data, {
680
- target: [cmsPublishedCache.section, cmsPublishedCache.locale],
681
- set: {
682
- content: data.content,
683
- publishedAt: data.publishedAt,
684
- publishedBy: data.publishedBy,
685
- version: sql`${cmsPublishedCache.version} + 1`
686
- // 버전 증가로 클라이언트 캐시 무효화
687
- }
688
- });
689
- }
690
- async function findAllLanguages(section) {
691
- return findMany4(cmsPublishedCache, {
692
- where: eq3(cmsPublishedCache.section, section)
693
- });
694
- }
695
- async function deleteBySection(section, locale) {
696
- if (locale) {
697
- await deleteOne3(
698
- cmsPublishedCache,
699
- and3(
700
- eq3(cmsPublishedCache.section, section),
701
- eq3(cmsPublishedCache.locale, locale)
702
- )
703
- );
704
- } else {
705
- await deleteMany3(
706
- cmsPublishedCache,
707
- eq3(cmsPublishedCache.section, section)
708
- );
50
+ var LOCALE_INFO_MAP = {
51
+ // 한국어
52
+ ko: {
53
+ locale: "ko",
54
+ countryCode: "KR",
55
+ flag: "&#x1F1F0;&#x1F1F7;",
56
+ dialCode: "+82",
57
+ nativeName: "\uD55C\uAD6D\uC5B4",
58
+ englishName: "Korean",
59
+ currencyCode: "KRW",
60
+ dateFormat: "YYYY.MM.DD"
61
+ },
62
+ // 영어 (미국)
63
+ en: {
64
+ locale: "en",
65
+ countryCode: "US",
66
+ flag: "&#x1F1FA;&#x1F1F8;",
67
+ dialCode: "+1",
68
+ nativeName: "English",
69
+ englishName: "English",
70
+ currencyCode: "USD",
71
+ dateFormat: "MM/DD/YYYY"
72
+ },
73
+ // 일본어
74
+ ja: {
75
+ locale: "ja",
76
+ countryCode: "JP",
77
+ flag: "&#x1F1EF;&#x1F1F5;",
78
+ dialCode: "+81",
79
+ nativeName: "\u65E5\u672C\u8A9E",
80
+ englishName: "Japanese",
81
+ currencyCode: "JPY",
82
+ dateFormat: "YYYY/MM/DD"
83
+ },
84
+ // 중국어 (간체)
85
+ zh: {
86
+ locale: "zh",
87
+ countryCode: "CN",
88
+ flag: "&#x1F1E8;&#x1F1F3;",
89
+ dialCode: "+86",
90
+ nativeName: "\u7B80\u4F53\u4E2D\u6587",
91
+ englishName: "Chinese (Simplified)",
92
+ currencyCode: "CNY",
93
+ dateFormat: "YYYY-MM-DD"
94
+ },
95
+ // 중국어 (번체, 대만)
96
+ "zh-TW": {
97
+ locale: "zh-TW",
98
+ countryCode: "TW",
99
+ flag: "&#x1F1F9;&#x1F1FC;",
100
+ dialCode: "+886",
101
+ nativeName: "\u7E41\u9AD4\u4E2D\u6587",
102
+ englishName: "Chinese (Traditional)",
103
+ currencyCode: "TWD",
104
+ dateFormat: "YYYY/MM/DD"
105
+ },
106
+ // 스페인어
107
+ es: {
108
+ locale: "es",
109
+ countryCode: "ES",
110
+ flag: "&#x1F1EA;&#x1F1F8;",
111
+ dialCode: "+34",
112
+ nativeName: "Espa\xF1ol",
113
+ englishName: "Spanish",
114
+ currencyCode: "EUR",
115
+ dateFormat: "DD/MM/YYYY"
116
+ },
117
+ // 프랑스어
118
+ fr: {
119
+ locale: "fr",
120
+ countryCode: "FR",
121
+ flag: "&#x1F1EB;&#x1F1F7;",
122
+ dialCode: "+33",
123
+ nativeName: "Fran\xE7ais",
124
+ englishName: "French",
125
+ currencyCode: "EUR",
126
+ dateFormat: "DD/MM/YYYY"
127
+ },
128
+ // 독일어
129
+ de: {
130
+ locale: "de",
131
+ countryCode: "DE",
132
+ flag: "&#x1F1E9;&#x1F1EA;",
133
+ dialCode: "+49",
134
+ nativeName: "Deutsch",
135
+ englishName: "German",
136
+ currencyCode: "EUR",
137
+ dateFormat: "DD.MM.YYYY"
138
+ },
139
+ // 이탈리아어
140
+ it: {
141
+ locale: "it",
142
+ countryCode: "IT",
143
+ flag: "&#x1F1EE;&#x1F1F9;",
144
+ dialCode: "+39",
145
+ nativeName: "Italiano",
146
+ englishName: "Italian",
147
+ currencyCode: "EUR",
148
+ dateFormat: "DD/MM/YYYY"
149
+ },
150
+ // 포르투갈어 (브라질)
151
+ pt: {
152
+ locale: "pt",
153
+ countryCode: "BR",
154
+ flag: "&#x1F1E7;&#x1F1F7;",
155
+ dialCode: "+55",
156
+ nativeName: "Portugu\xEAs",
157
+ englishName: "Portuguese",
158
+ currencyCode: "BRL",
159
+ dateFormat: "DD/MM/YYYY"
160
+ },
161
+ // 러시아어
162
+ ru: {
163
+ locale: "ru",
164
+ countryCode: "RU",
165
+ flag: "&#x1F1F7;&#x1F1FA;",
166
+ dialCode: "+7",
167
+ nativeName: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439",
168
+ englishName: "Russian",
169
+ currencyCode: "RUB",
170
+ dateFormat: "DD.MM.YYYY"
171
+ },
172
+ // 아랍어
173
+ ar: {
174
+ locale: "ar",
175
+ countryCode: "SA",
176
+ flag: "&#x1F1F8;&#x1F1E6;",
177
+ dialCode: "+966",
178
+ nativeName: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629",
179
+ englishName: "Arabic",
180
+ rtl: true,
181
+ currencyCode: "SAR",
182
+ dateFormat: "DD/MM/YYYY"
183
+ },
184
+ // 힌디어
185
+ hi: {
186
+ locale: "hi",
187
+ countryCode: "IN",
188
+ flag: "&#x1F1EE;&#x1F1F3;",
189
+ dialCode: "+91",
190
+ nativeName: "\u0939\u093F\u0928\u094D\u0926\u0940",
191
+ englishName: "Hindi",
192
+ currencyCode: "INR",
193
+ dateFormat: "DD/MM/YYYY"
194
+ },
195
+ // 태국어
196
+ th: {
197
+ locale: "th",
198
+ countryCode: "TH",
199
+ flag: "&#x1F1F9;&#x1F1ED;",
200
+ dialCode: "+66",
201
+ nativeName: "\u0E44\u0E17\u0E22",
202
+ englishName: "Thai",
203
+ currencyCode: "THB",
204
+ dateFormat: "DD/MM/YYYY"
205
+ },
206
+ // 베트남어
207
+ vi: {
208
+ locale: "vi",
209
+ countryCode: "VN",
210
+ flag: "&#x1F1FB;&#x1F1F3;",
211
+ dialCode: "+84",
212
+ nativeName: "Ti\u1EBFng Vi\u1EC7t",
213
+ englishName: "Vietnamese",
214
+ currencyCode: "VND",
215
+ dateFormat: "DD/MM/YYYY"
216
+ },
217
+ // 인도네시아어
218
+ id: {
219
+ locale: "id",
220
+ countryCode: "ID",
221
+ flag: "&#x1F1EE;&#x1F1E9;",
222
+ dialCode: "+62",
223
+ nativeName: "Bahasa Indonesia",
224
+ englishName: "Indonesian",
225
+ currencyCode: "IDR",
226
+ dateFormat: "DD/MM/YYYY"
227
+ },
228
+ // 터키어
229
+ tr: {
230
+ locale: "tr",
231
+ countryCode: "TR",
232
+ flag: "&#x1F1F9;&#x1F1F7;",
233
+ dialCode: "+90",
234
+ nativeName: "T\xFCrk\xE7e",
235
+ englishName: "Turkish",
236
+ currencyCode: "TRY",
237
+ dateFormat: "DD.MM.YYYY"
238
+ },
239
+ // 폴란드어
240
+ pl: {
241
+ locale: "pl",
242
+ countryCode: "PL",
243
+ flag: "&#x1F1F5;&#x1F1F1;",
244
+ dialCode: "+48",
245
+ nativeName: "Polski",
246
+ englishName: "Polish",
247
+ currencyCode: "PLN",
248
+ dateFormat: "DD.MM.YYYY"
249
+ },
250
+ // 네덜란드어
251
+ nl: {
252
+ locale: "nl",
253
+ countryCode: "NL",
254
+ flag: "&#x1F1F3;&#x1F1F1;",
255
+ dialCode: "+31",
256
+ nativeName: "Nederlands",
257
+ englishName: "Dutch",
258
+ currencyCode: "EUR",
259
+ dateFormat: "DD-MM-YYYY"
260
+ },
261
+ // 중국어 (홍콩)
262
+ "zh-HK": {
263
+ locale: "zh-HK",
264
+ countryCode: "HK",
265
+ flag: "&#x1F1ED;&#x1F1F0;",
266
+ dialCode: "+852",
267
+ nativeName: "\u7E41\u9AD4\u4E2D\u6587 (\u9999\u6E2F)",
268
+ englishName: "Chinese (Hong Kong)",
269
+ currencyCode: "HKD",
270
+ dateFormat: "YYYY/MM/DD"
271
+ },
272
+ // 말레이어
273
+ ms: {
274
+ locale: "ms",
275
+ countryCode: "MY",
276
+ flag: "&#x1F1F2;&#x1F1FE;",
277
+ dialCode: "+60",
278
+ nativeName: "Bahasa Melayu",
279
+ englishName: "Malay",
280
+ currencyCode: "MYR",
281
+ dateFormat: "DD/MM/YYYY"
282
+ },
283
+ // 영어 (영국)
284
+ "en-GB": {
285
+ locale: "en-GB",
286
+ countryCode: "GB",
287
+ flag: "&#x1F1EC;&#x1F1E7;",
288
+ dialCode: "+44",
289
+ nativeName: "English (UK)",
290
+ englishName: "English (United Kingdom)",
291
+ currencyCode: "GBP",
292
+ dateFormat: "DD/MM/YYYY"
293
+ },
294
+ // 영어 (캐나다)
295
+ "en-CA": {
296
+ locale: "en-CA",
297
+ countryCode: "CA",
298
+ flag: "&#x1F1E8;&#x1F1E6;",
299
+ dialCode: "+1",
300
+ nativeName: "English (Canada)",
301
+ englishName: "English (Canada)",
302
+ currencyCode: "CAD",
303
+ dateFormat: "YYYY-MM-DD"
304
+ },
305
+ // 영어 (호주)
306
+ "en-AU": {
307
+ locale: "en-AU",
308
+ countryCode: "AU",
309
+ flag: "&#x1F1E6;&#x1F1FA;",
310
+ dialCode: "+61",
311
+ nativeName: "English (Australia)",
312
+ englishName: "English (Australia)",
313
+ currencyCode: "AUD",
314
+ dateFormat: "DD/MM/YYYY"
315
+ },
316
+ // 영어 (뉴질랜드)
317
+ "en-NZ": {
318
+ locale: "en-NZ",
319
+ countryCode: "NZ",
320
+ flag: "&#x1F1F3;&#x1F1FF;",
321
+ dialCode: "+64",
322
+ nativeName: "English (New Zealand)",
323
+ englishName: "English (New Zealand)",
324
+ currencyCode: "NZD",
325
+ dateFormat: "DD/MM/YYYY"
326
+ },
327
+ // 스페인어 (멕시코)
328
+ "es-MX": {
329
+ locale: "es-MX",
330
+ countryCode: "MX",
331
+ flag: "&#x1F1F2;&#x1F1FD;",
332
+ dialCode: "+52",
333
+ nativeName: "Espa\xF1ol (M\xE9xico)",
334
+ englishName: "Spanish (Mexico)",
335
+ currencyCode: "MXN",
336
+ dateFormat: "DD/MM/YYYY"
337
+ },
338
+ // 스페인어 (아르헨티나)
339
+ "es-AR": {
340
+ locale: "es-AR",
341
+ countryCode: "AR",
342
+ flag: "&#x1F1E6;&#x1F1F7;",
343
+ dialCode: "+54",
344
+ nativeName: "Espa\xF1ol (Argentina)",
345
+ englishName: "Spanish (Argentina)",
346
+ currencyCode: "ARS",
347
+ dateFormat: "DD/MM/YYYY"
348
+ },
349
+ // 스페인어 (콜롬비아)
350
+ "es-CO": {
351
+ locale: "es-CO",
352
+ countryCode: "CO",
353
+ flag: "&#x1F1E8;&#x1F1F4;",
354
+ dialCode: "+57",
355
+ nativeName: "Espa\xF1ol (Colombia)",
356
+ englishName: "Spanish (Colombia)",
357
+ currencyCode: "COP",
358
+ dateFormat: "DD/MM/YYYY"
359
+ },
360
+ // 스웨덴어
361
+ sv: {
362
+ locale: "sv",
363
+ countryCode: "SE",
364
+ flag: "&#x1F1F8;&#x1F1EA;",
365
+ dialCode: "+46",
366
+ nativeName: "Svenska",
367
+ englishName: "Swedish",
368
+ currencyCode: "SEK",
369
+ dateFormat: "YYYY-MM-DD"
370
+ },
371
+ // 노르웨이어
372
+ no: {
373
+ locale: "no",
374
+ countryCode: "NO",
375
+ flag: "&#x1F1F3;&#x1F1F4;",
376
+ dialCode: "+47",
377
+ nativeName: "Norsk",
378
+ englishName: "Norwegian",
379
+ currencyCode: "NOK",
380
+ dateFormat: "DD.MM.YYYY"
381
+ },
382
+ // 덴마크어
383
+ da: {
384
+ locale: "da",
385
+ countryCode: "DK",
386
+ flag: "&#x1F1E9;&#x1F1F0;",
387
+ dialCode: "+45",
388
+ nativeName: "Dansk",
389
+ englishName: "Danish",
390
+ currencyCode: "DKK",
391
+ dateFormat: "DD-MM-YYYY"
392
+ },
393
+ // 핀란드어
394
+ fi: {
395
+ locale: "fi",
396
+ countryCode: "FI",
397
+ flag: "&#x1F1EB;&#x1F1EE;",
398
+ dialCode: "+358",
399
+ nativeName: "Suomi",
400
+ englishName: "Finnish",
401
+ currencyCode: "EUR",
402
+ dateFormat: "DD.MM.YYYY"
403
+ },
404
+ // 우크라이나어
405
+ uk: {
406
+ locale: "uk",
407
+ countryCode: "UA",
408
+ flag: "&#x1F1FA;&#x1F1E6;",
409
+ dialCode: "+380",
410
+ nativeName: "\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430",
411
+ englishName: "Ukrainian",
412
+ currencyCode: "UAH",
413
+ dateFormat: "DD.MM.YYYY"
414
+ },
415
+ // 체코어
416
+ cs: {
417
+ locale: "cs",
418
+ countryCode: "CZ",
419
+ flag: "&#x1F1E8;&#x1F1FF;",
420
+ dialCode: "+420",
421
+ nativeName: "\u010Ce\u0161tina",
422
+ englishName: "Czech",
423
+ currencyCode: "CZK",
424
+ dateFormat: "DD.MM.YYYY"
425
+ },
426
+ // 헝가리어
427
+ hu: {
428
+ locale: "hu",
429
+ countryCode: "HU",
430
+ flag: "&#x1F1ED;&#x1F1FA;",
431
+ dialCode: "+36",
432
+ nativeName: "Magyar",
433
+ englishName: "Hungarian",
434
+ currencyCode: "HUF",
435
+ dateFormat: "YYYY.MM.DD."
436
+ },
437
+ // 루마니아어
438
+ ro: {
439
+ locale: "ro",
440
+ countryCode: "RO",
441
+ flag: "&#x1F1F7;&#x1F1F4;",
442
+ dialCode: "+40",
443
+ nativeName: "Rom\xE2n\u0103",
444
+ englishName: "Romanian",
445
+ currencyCode: "RON",
446
+ dateFormat: "DD.MM.YYYY"
447
+ },
448
+ // 불가리아어
449
+ bg: {
450
+ locale: "bg",
451
+ countryCode: "BG",
452
+ flag: "&#x1F1E7;&#x1F1EC;",
453
+ dialCode: "+359",
454
+ nativeName: "\u0411\u044A\u043B\u0433\u0430\u0440\u0441\u043A\u0438",
455
+ englishName: "Bulgarian",
456
+ currencyCode: "BGN",
457
+ dateFormat: "DD.MM.YYYY"
458
+ },
459
+ // 크로아티아어
460
+ hr: {
461
+ locale: "hr",
462
+ countryCode: "HR",
463
+ flag: "&#x1F1ED;&#x1F1F7;",
464
+ dialCode: "+385",
465
+ nativeName: "Hrvatski",
466
+ englishName: "Croatian",
467
+ currencyCode: "HRK",
468
+ dateFormat: "DD.MM.YYYY."
469
+ },
470
+ // 세르비아어
471
+ sr: {
472
+ locale: "sr",
473
+ countryCode: "RS",
474
+ flag: "&#x1F1F7;&#x1F1F8;",
475
+ dialCode: "+381",
476
+ nativeName: "\u0421\u0440\u043F\u0441\u043A\u0438",
477
+ englishName: "Serbian",
478
+ currencyCode: "RSD",
479
+ dateFormat: "DD.MM.YYYY."
480
+ },
481
+ // 슬로바키아어
482
+ sk: {
483
+ locale: "sk",
484
+ countryCode: "SK",
485
+ flag: "&#x1F1F8;&#x1F1F0;",
486
+ dialCode: "+421",
487
+ nativeName: "Sloven\u010Dina",
488
+ englishName: "Slovak",
489
+ currencyCode: "EUR",
490
+ dateFormat: "DD.MM.YYYY"
491
+ },
492
+ // 슬로베니아어
493
+ sl: {
494
+ locale: "sl",
495
+ countryCode: "SI",
496
+ flag: "&#x1F1F8;&#x1F1EE;",
497
+ dialCode: "+386",
498
+ nativeName: "Sloven\u0161\u010Dina",
499
+ englishName: "Slovenian",
500
+ currencyCode: "EUR",
501
+ dateFormat: "DD.MM.YYYY"
502
+ },
503
+ // 리투아니아어
504
+ lt: {
505
+ locale: "lt",
506
+ countryCode: "LT",
507
+ flag: "&#x1F1F1;&#x1F1F9;",
508
+ dialCode: "+370",
509
+ nativeName: "Lietuvi\u0173",
510
+ englishName: "Lithuanian",
511
+ currencyCode: "EUR",
512
+ dateFormat: "YYYY-MM-DD"
513
+ },
514
+ // 라트비아어
515
+ lv: {
516
+ locale: "lv",
517
+ countryCode: "LV",
518
+ flag: "&#x1F1F1;&#x1F1FB;",
519
+ dialCode: "+371",
520
+ nativeName: "Latvie\u0161u",
521
+ englishName: "Latvian",
522
+ currencyCode: "EUR",
523
+ dateFormat: "DD.MM.YYYY."
524
+ },
525
+ // 에스토니아어
526
+ et: {
527
+ locale: "et",
528
+ countryCode: "EE",
529
+ flag: "&#x1F1EA;&#x1F1EA;",
530
+ dialCode: "+372",
531
+ nativeName: "Eesti",
532
+ englishName: "Estonian",
533
+ currencyCode: "EUR",
534
+ dateFormat: "DD.MM.YYYY"
535
+ },
536
+ // 그리스어
537
+ el: {
538
+ locale: "el",
539
+ countryCode: "GR",
540
+ flag: "&#x1F1EC;&#x1F1F7;",
541
+ dialCode: "+30",
542
+ nativeName: "\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AC",
543
+ englishName: "Greek",
544
+ currencyCode: "EUR",
545
+ dateFormat: "DD/MM/YYYY"
546
+ },
547
+ // 페르시아어
548
+ fa: {
549
+ locale: "fa",
550
+ countryCode: "IR",
551
+ flag: "&#x1F1EE;&#x1F1F7;",
552
+ dialCode: "+98",
553
+ nativeName: "\u0641\u0627\u0631\u0633\u06CC",
554
+ englishName: "Persian",
555
+ rtl: true,
556
+ currencyCode: "IRR",
557
+ dateFormat: "YYYY/MM/DD"
558
+ },
559
+ // 히브리어
560
+ he: {
561
+ locale: "he",
562
+ countryCode: "IL",
563
+ flag: "&#x1F1EE;&#x1F1F1;",
564
+ dialCode: "+972",
565
+ nativeName: "\u05E2\u05D1\u05E8\u05D9\u05EA",
566
+ englishName: "Hebrew",
567
+ rtl: true,
568
+ currencyCode: "ILS",
569
+ dateFormat: "DD/MM/YYYY"
570
+ },
571
+ // 스와힐리어
572
+ sw: {
573
+ locale: "sw",
574
+ countryCode: "KE",
575
+ flag: "&#x1F1F0;&#x1F1EA;",
576
+ dialCode: "+254",
577
+ nativeName: "Kiswahili",
578
+ englishName: "Swahili",
579
+ currencyCode: "KES",
580
+ dateFormat: "DD/MM/YYYY"
709
581
  }
710
- }
711
- var cmsPublishedCacheRepository = {
712
- findBySection: findBySection2,
713
- upsert: upsert3,
714
- findAllLanguages,
715
- deleteBySection
716
582
  };
717
-
718
- // src/helpers/sync.ts
719
- import { existsSync, readdirSync, readFileSync, statSync } from "fs";
720
- import { basename, extname, join } from "path";
721
-
722
- // src/labels/helpers.ts
723
- function flattenLabels(labels) {
724
- const result = [];
725
- function isLabelDefinition(obj) {
726
- return "key" in obj && "defaultValue" in obj && typeof obj.key === "string" && (typeof obj.defaultValue === "string" || typeof obj.defaultValue === "object");
727
- }
728
- function traverse(obj) {
729
- if (isLabelDefinition(obj)) {
730
- result.push({
731
- key: obj.key,
732
- defaultValue: obj.defaultValue,
733
- description: obj.description
734
- });
735
- } else {
736
- Object.values(obj).forEach((value) => {
737
- if (typeof value === "object" && value !== null) {
738
- traverse(value);
739
- }
740
- });
741
- }
742
- }
743
- traverse(labels);
744
- return result;
745
- }
746
- function extractLabels(definition) {
747
- return flattenLabels(definition.labels);
583
+ function getLocaleInfo(locale) {
584
+ return LOCALE_INFO_MAP[locale];
748
585
  }
749
-
750
- // src/helpers/sync.ts
751
- async function syncAll(sections, options = {}) {
752
- const results = [];
753
- for (const definition of sections) {
754
- const result = await syncSection(definition, options);
755
- results.push(result);
756
- }
757
- return results;
586
+ function getSupportedLocales() {
587
+ return Object.keys(LOCALE_INFO_MAP);
758
588
  }
759
- function loadLabelsFromJson(labelsDir) {
760
- const sections = [];
761
- if (!existsSync(labelsDir)) {
762
- console.warn(`[CMS] Labels directory not found: ${labelsDir}`);
763
- console.warn(`[CMS] Expected directory structure:`);
764
- console.warn(`[CMS] ${labelsDir}/`);
765
- console.warn(`[CMS] \u251C\u2500\u2500 common/ # Section directory`);
766
- console.warn(`[CMS] \u2502 \u251C\u2500\u2500 messages.json`);
767
- console.warn(`[CMS] \u2502 \u2514\u2500\u2500 errors.json`);
768
- console.warn(`[CMS] \u2514\u2500\u2500 home/ # Section directory`);
769
- console.warn(`[CMS] \u2514\u2500\u2500 hero.json`);
770
- return sections;
771
- }
772
- try {
773
- const entries = readdirSync(labelsDir);
774
- if (entries.length === 0) {
775
- console.warn(`[CMS] Labels directory is empty: ${labelsDir}`);
776
- console.warn(`[CMS] Create section directories with JSON files inside`);
777
- return sections;
778
- }
779
- const jsonFiles = entries.filter((e) => extname(e) === ".json");
780
- if (jsonFiles.length > 0) {
781
- console.warn(`[CMS] Found JSON files directly in ${labelsDir}:`);
782
- jsonFiles.forEach((f) => console.warn(`[CMS] - ${f} (will be ignored)`));
783
- console.warn(`[CMS] JSON files should be inside section directories`);
784
- console.warn(`[CMS] Example: Move ${jsonFiles[0]} to ${labelsDir}/${basename(jsonFiles[0], ".json")}/${jsonFiles[0]}`);
785
- }
786
- for (const entry of entries) {
787
- const sectionPath = join(labelsDir, entry);
788
- const stat = statSync(sectionPath);
789
- if (stat.isDirectory()) {
790
- const sectionName = entry;
791
- const labels = loadSectionLabels(sectionPath);
792
- if (Object.keys(labels).length > 0) {
793
- sections.push({ section: sectionName, labels });
794
- } else {
795
- console.warn(`[CMS] Section directory "${sectionName}" has no valid JSON files`);
796
- }
797
- }
798
- }
799
- if (sections.length === 0) {
800
- console.warn(`[CMS] No valid section directories found in ${labelsDir}`);
801
- }
802
- } catch (error) {
803
- console.warn(`[CMS] Could not scan labels directory: ${labelsDir}`);
804
- console.error(`[CMS] Error:`, error);
805
- }
806
- return sections;
589
+ function getFlag(locale) {
590
+ return LOCALE_INFO_MAP[locale]?.flag ?? "";
807
591
  }
808
- function loadSectionLabels(sectionPath) {
809
- const labels = {};
810
- try {
811
- const files = readdirSync(sectionPath);
812
- for (const file of files) {
813
- if (extname(file) === ".json") {
814
- const filePath = join(sectionPath, file);
815
- const categoryName = basename(file, ".json");
816
- try {
817
- const content = readFileSync(filePath, "utf-8");
818
- labels[categoryName] = JSON.parse(content);
819
- } catch (error) {
820
- console.warn(`[CMS] Failed to parse ${filePath}`);
821
- }
822
- }
823
- }
824
- } catch (error) {
825
- console.warn(`[CMS] Could not read section directory: ${sectionPath}`);
826
- }
827
- return labels;
592
+ function getDialCode(locale) {
593
+ return LOCALE_INFO_MAP[locale]?.dialCode ?? "";
828
594
  }
829
- async function syncSection(definition, options = {}) {
830
- const {
831
- dryRun = false,
832
- updateExisting = false,
833
- removeUnused = false,
834
- verbose = false
835
- } = options;
836
- const { section } = definition;
837
- const result = {
838
- section,
839
- created: 0,
840
- updated: 0,
841
- deleted: 0,
842
- unchanged: 0,
843
- errors: []
844
- };
845
- try {
846
- const definedLabels = extractLabels(definition);
847
- const definedKeys = new Set(definedLabels.map((l) => l.key));
848
- const existingLabels = await cmsLabelsRepository.findBySection(section);
849
- const existingMap = new Map(existingLabels.map((l) => [l.key, l]));
850
- if (verbose) {
851
- console.log(`
852
- [${section}] Found ${definedLabels.length} labels in definition`);
853
- console.log(`[${section}] Found ${existingLabels.length} labels in DB`);
854
- }
855
- for (const label of definedLabels) {
856
- const existing = existingMap.get(label.key);
857
- if (!existing) {
858
- if (verbose) console.log(` [CREATE] ${label.key}`);
859
- if (!dryRun) {
860
- try {
861
- const defaultValue = typeof label.defaultValue === "object" ? JSON.stringify(label.defaultValue) : label.defaultValue;
862
- await cmsLabelsRepository.create({
863
- section,
864
- key: label.key,
865
- type: label.type || "text",
866
- // 라벨 타입 (기본값: 'text')
867
- defaultValue,
868
- description: label.description
869
- });
870
- } catch (error) {
871
- result.errors.push({
872
- key: label.key,
873
- error: error instanceof Error ? error.message : String(error)
874
- });
875
- continue;
876
- }
877
- }
878
- result.created++;
879
- } else if (updateExisting) {
880
- const newDefaultValue = typeof label.defaultValue === "object" ? JSON.stringify(label.defaultValue) : label.defaultValue;
881
- const hasChanged = existing.defaultValue !== newDefaultValue;
882
- if (hasChanged) {
883
- if (verbose) {
884
- console.log(` [UPDATE] ${label.key}`);
885
- console.log(` Old: "${existing.defaultValue}"`);
886
- console.log(` New: "${newDefaultValue}"`);
887
- }
888
- if (!dryRun) {
889
- try {
890
- await cmsLabelsRepository.updateById(existing.id, {
891
- defaultValue: newDefaultValue,
892
- description: label.description
893
- });
894
- } catch (error) {
895
- result.errors.push({
896
- key: label.key,
897
- error: error instanceof Error ? error.message : String(error)
898
- });
899
- continue;
900
- }
901
- }
902
- result.updated++;
903
- } else {
904
- result.unchanged++;
905
- }
906
- } else {
907
- result.unchanged++;
908
- }
909
- }
910
- if (removeUnused) {
911
- for (const existing of existingLabels) {
912
- if (!definedKeys.has(existing.key)) {
913
- if (verbose) console.log(` [DELETE] ${existing.key}`);
914
- if (!dryRun) {
915
- try {
916
- await cmsLabelsRepository.deleteById(existing.id);
917
- } catch (error) {
918
- result.errors.push({
919
- key: existing.key,
920
- error: error instanceof Error ? error.message : String(error)
921
- });
922
- continue;
923
- }
924
- }
925
- result.deleted++;
926
- }
927
- }
928
- }
929
- if (!dryRun && (result.created > 0 || result.updated > 0 || result.deleted > 0)) {
930
- if (verbose) console.log(` [CACHE] Updating published cache for section: ${section}`);
931
- await updatePublishedCache(section);
932
- }
933
- } catch (error) {
934
- result.errors.push({
935
- key: "__section__",
936
- error: error instanceof Error ? error.message : String(error)
937
- });
938
- }
939
- return result;
940
- }
941
- async function updatePublishedCache(section) {
942
- const labels = await cmsLabelsRepository.findBySection(section);
943
- const localesSet = /* @__PURE__ */ new Set();
944
- const labelsByLocale = {};
945
- labels.forEach((label) => {
946
- try {
947
- const parsed = JSON.parse(label.defaultValue || "{}");
948
- if (typeof parsed === "object" && !Array.isArray(parsed)) {
949
- Object.keys(parsed).forEach((locale) => localesSet.add(locale));
950
- Object.entries(parsed).forEach(([locale, value]) => {
951
- if (!labelsByLocale[locale]) labelsByLocale[locale] = {};
952
- labelsByLocale[locale][label.key] = value;
953
- });
954
- } else {
955
- if (!labelsByLocale.ko) labelsByLocale.ko = {};
956
- labelsByLocale.ko[label.key] = label.defaultValue;
957
- localesSet.add("ko");
958
- }
959
- } catch {
960
- if (!labelsByLocale.ko) labelsByLocale.ko = {};
961
- labelsByLocale.ko[label.key] = label.defaultValue;
962
- localesSet.add("ko");
963
- }
964
- });
965
- const timestamp7 = /* @__PURE__ */ new Date();
966
- for (const locale of localesSet) {
967
- await cmsPublishedCacheRepository.upsert({
968
- section,
969
- locale,
970
- content: labelsByLocale[locale] || {},
971
- publishedAt: timestamp7,
972
- publishedBy: "system"
973
- });
974
- }
975
- }
976
- async function initLabelSync(options = {}) {
977
- const isDevelopment = process.env.NODE_ENV === "development";
978
- const verbose = options.verbose ?? isDevelopment;
979
- const labelsDir = options.labelsDir ?? "src/cms/labels";
980
- if (verbose) {
981
- console.log("\n\u{1F504} Initializing label sync...\n");
982
- }
983
- const sections = loadLabelsFromJson(labelsDir);
984
- if (sections.length === 0) {
985
- if (verbose) {
986
- console.log("\u26A0\uFE0F No labels found in", labelsDir);
987
- console.log("");
988
- }
989
- return;
990
- }
991
- const results = await syncAll(sections, {
992
- updateExisting: true,
993
- // 🔄 항상 업데이트 (프로덕션 포함)
994
- ...options,
995
- verbose
996
- });
997
- const totalCreated = results.reduce((sum, r) => sum + r.created, 0);
998
- const totalUpdated = results.reduce((sum, r) => sum + r.updated, 0);
999
- const totalUnchanged = results.reduce((sum, r) => sum + r.unchanged, 0);
1000
- const totalErrors = results.reduce((sum, r) => sum + r.errors.length, 0);
1001
- if (verbose) {
1002
- console.log("\u2705 Label sync completed\n");
1003
- console.log(` Sections: ${results.length}`);
1004
- console.log(` Created: ${totalCreated}`);
1005
- console.log(` Updated: ${totalUpdated}`);
1006
- console.log(` Unchanged: ${totalUnchanged}`);
1007
- if (totalErrors > 0) {
1008
- console.log(` Errors: ${totalErrors}
1009
- `);
1010
- } else {
1011
- console.log("");
1012
- }
1013
- }
1014
- if (totalErrors > 0) {
1015
- results.forEach((result) => {
1016
- result.errors.forEach((error) => {
1017
- console.error(`[${result.section}] ${error.key}: ${error.error}`);
1018
- });
1019
- });
1020
- }
1021
- }
1022
-
1023
- // src/generators/label-sync-generator.ts
1024
- import { logger } from "@spfn/core";
1025
- import { join as join2 } from "path";
1026
- var syncLogger = logger.child("label-sync");
1027
- var LabelSyncGenerator = class {
1028
- name = "label-sync";
1029
- labelsDir;
1030
- constructor(config = {}) {
1031
- this.labelsDir = config.labelsDir ?? "src/cms/labels";
1032
- }
1033
- /**
1034
- * Watch patterns for label definition files
1035
- */
1036
- get watchPatterns() {
1037
- return [
1038
- `${this.labelsDir}/**/*.json`
1039
- ];
1040
- }
1041
- async generate(options) {
1042
- if (options.debug) {
1043
- syncLogger.info("Starting label sync...");
1044
- }
1045
- try {
1046
- const labelsPath = join2(options.cwd, this.labelsDir);
1047
- const sections = loadLabelsFromJson(labelsPath);
1048
- if (sections.length === 0) {
1049
- syncLogger.warn(`No labels found in ${labelsPath}`);
1050
- return;
1051
- }
1052
- syncLogger.info(`Found ${sections.length} sections`);
1053
- const results = await syncAll(sections, {
1054
- verbose: options.debug ?? false,
1055
- updateExisting: true
1056
- // 항상 업데이트 (프로덕션 포함)
1057
- });
1058
- const totalCreated = results.reduce((sum, r) => sum + r.created, 0);
1059
- const totalUpdated = results.reduce((sum, r) => sum + r.updated, 0);
1060
- const totalErrors = results.reduce((sum, r) => sum + r.errors.length, 0);
1061
- if (options.debug || totalCreated > 0 || totalUpdated > 0) {
1062
- syncLogger.info("Label sync completed", {
1063
- sections: results.length,
1064
- created: totalCreated,
1065
- updated: totalUpdated,
1066
- errors: totalErrors
1067
- });
1068
- }
1069
- if (totalErrors > 0) {
1070
- results.forEach((result) => {
1071
- result.errors.forEach((error) => {
1072
- syncLogger.error(`[${result.section}] ${error.key}: ${error.error}`);
1073
- });
1074
- });
1075
- }
1076
- } catch (error) {
1077
- syncLogger.error(
1078
- "Label sync failed",
1079
- error instanceof Error ? error : new Error(String(error))
1080
- );
1081
- }
1082
- }
1083
- async onFileChange(filePath, event) {
1084
- syncLogger.info(`Label file ${event}`, { file: filePath });
1085
- await this.generate({ cwd: process.cwd(), debug: true });
1086
- }
1087
- };
1088
- function createLabelSyncGenerator(config) {
1089
- return new LabelSyncGenerator(config);
595
+ function isRTL(locale) {
596
+ return LOCALE_INFO_MAP[locale]?.rtl ?? false;
1090
597
  }
1091
598
  export {
1092
- LabelSyncGenerator,
1093
- cmsAuditLogs,
1094
- cmsDraftCache,
1095
- cmsDraftCacheRepository,
1096
- cmsLabelValues,
1097
- cmsLabelValuesRepository,
1098
- cmsLabelVersions,
1099
- cmsLabels,
1100
- cmsLabelsRepository,
1101
- cmsPublishedCache,
1102
- cmsPublishedCacheRepository,
599
+ DEFAULT_LABELS_DIR,
600
+ LOCALE_COOKIE_KEY,
601
+ LOCALE_INFO_MAP,
1103
602
  configureCms,
1104
- createLabelSyncGenerator,
1105
- extractLabels,
1106
- flattenLabels,
1107
603
  getCmsConfig,
1108
- getSection,
1109
- getSections,
1110
- initLabelSync,
1111
- loadLabelsFromJson,
1112
- resetCmsConfig,
1113
- syncAll,
1114
- syncSection
604
+ getDialCode,
605
+ getFlag,
606
+ getLocaleInfo,
607
+ getSupportedLocales,
608
+ isRTL,
609
+ resetCmsConfig
1115
610
  };
1116
611
  //# sourceMappingURL=index.js.map