{"version":3,"file":"sections-oKB9roBX.mjs","names":[],"sources":["../src/sections/index.ts","../src/api/handlers/sections.ts"],"sourcesContent":["/**\n * Sections runtime functions\n *\n * Sections are reusable content blocks that can be inserted into any Portable Text field.\n */\n\nimport type { Kysely } from \"kysely\";\n\nimport { encodeCursor, decodeCursor, type FindManyResult } from \"../database/repositories/types.js\";\nimport type { Database } from \"../database/types.js\";\nimport { getDb } from \"../loader.js\";\nimport type { Section, SectionRow, GetSectionsOptions } from \"./types.js\";\n\nexport type {\n\tSection,\n\tSectionSource,\n\tSectionRow,\n\tCreateSectionInput,\n\tUpdateSectionInput,\n\tGetSectionsOptions,\n} from \"./types.js\";\n\n/**\n * Get a section by slug\n *\n * @example\n * ```ts\n * import { getSection } from \"@premium-cms/emdash\";\n *\n * const section = await getSection(\"hero-centered\");\n * if (section) {\n *   console.log(section.content); // Portable Text array\n * }\n * ```\n */\nexport async function getSection(slug: string): Promise<Section | null> {\n\tconst db = await getDb();\n\treturn getSectionWithDb(slug, db);\n}\n\n/**\n * Get a section by slug (with explicit db)\n *\n * @internal Use `getSection()` in templates. This variant is for admin routes\n * that already have a database handle.\n */\nexport async function getSectionWithDb(\n\tslug: string,\n\tdb: Kysely<Database>,\n): Promise<Section | null> {\n\tconst row = await db\n\t\t.selectFrom(\"_emdash_sections\")\n\t\t.selectAll()\n\t\t.$castTo<SectionRow>()\n\t\t.where(\"slug\", \"=\", slug)\n\t\t.executeTakeFirst();\n\n\tif (!row) {\n\t\treturn null;\n\t}\n\n\treturn rowToSection(row, db);\n}\n\n/**\n * Get a section by ID\n *\n * @internal Primarily for admin use\n */\nexport async function getSectionById(id: string, db: Kysely<Database>): Promise<Section | null> {\n\tconst row = await db\n\t\t.selectFrom(\"_emdash_sections\")\n\t\t.selectAll()\n\t\t.$castTo<SectionRow>()\n\t\t.where(\"id\", \"=\", id)\n\t\t.executeTakeFirst();\n\n\tif (!row) {\n\t\treturn null;\n\t}\n\n\treturn rowToSection(row, db);\n}\n\n/**\n * Get all sections with optional filtering\n *\n * @example\n * ```ts\n * import { getSections } from \"@premium-cms/emdash\";\n *\n * // Get all theme-provided sections\n * const themeSections = await getSections({ source: \"theme\" });\n *\n * // Search sections\n * const results = await getSections({ search: \"pricing\" });\n * ```\n */\nexport async function getSections(\n\toptions: GetSectionsOptions = {},\n): Promise<FindManyResult<Section>> {\n\tconst db = await getDb();\n\treturn getSectionsWithDb(db, options);\n}\n\n/**\n * Get all sections with optional filtering (with explicit db)\n *\n * @internal Use `getSections()` in templates. This variant is for admin routes\n * that already have a database handle.\n */\nexport async function getSectionsWithDb(\n\tdb: Kysely<Database>,\n\toptions: GetSectionsOptions = {},\n): Promise<FindManyResult<Section>> {\n\tconst limit = Math.min(Math.max(1, options.limit || 50), 100);\n\n\tlet query = db.selectFrom(\"_emdash_sections\").selectAll();\n\n\t// Filter by source\n\tif (options.source) {\n\t\tquery = query.where(\"source\", \"=\", options.source);\n\t}\n\n\t// Search - search title, description, and keywords\n\tif (options.search) {\n\t\tconst searchTerm = `%${options.search.toLowerCase()}%`;\n\t\tquery = query.where((eb) =>\n\t\t\teb.or([\n\t\t\t\teb(\"title\", \"like\", searchTerm),\n\t\t\t\teb(\"description\", \"like\", searchTerm),\n\t\t\t\teb(\"keywords\", \"like\", searchTerm),\n\t\t\t]),\n\t\t);\n\t}\n\n\t// Order by title ASC, id ASC for stable cursor pagination\n\tquery = query.orderBy(\"title\", \"asc\").orderBy(\"id\", \"asc\");\n\n\t// Cursor-based pagination — throws on invalid cursor.\n\tif (options.cursor) {\n\t\tconst decoded = decodeCursor(options.cursor);\n\t\tquery = query.where((eb) =>\n\t\t\teb.or([\n\t\t\t\teb(\"title\", \">\", decoded.orderValue),\n\t\t\t\teb.and([eb(\"title\", \"=\", decoded.orderValue), eb(\"id\", \">\", decoded.id)]),\n\t\t\t]),\n\t\t);\n\t}\n\n\tquery = query.limit(limit + 1);\n\n\tconst rows = await query.$castTo<SectionRow>().execute();\n\tconst hasMore = rows.length > limit;\n\tconst sliced = rows.slice(0, limit);\n\n\t// Convert rows to sections\n\tconst items = await Promise.all(sliced.map((row) => rowToSection(row, db)));\n\tconst result: FindManyResult<Section> = { items };\n\n\tif (hasMore && items.length > 0) {\n\t\tconst last = items.at(-1)!;\n\t\tresult.nextCursor = encodeCursor(last.title, last.id);\n\t}\n\n\treturn result;\n}\n\n/**\n * Convert a section row to the API type\n */\nasync function rowToSection(row: SectionRow, db: Kysely<Database>): Promise<Section> {\n\t// Parse keywords\n\tlet keywords: string[] = [];\n\tif (row.keywords) {\n\t\ttry {\n\t\t\tkeywords = JSON.parse(row.keywords);\n\t\t} catch {\n\t\t\t// Invalid JSON, ignore\n\t\t}\n\t}\n\n\t// Parse content — stored as JSON array of Portable Text blocks\n\tlet content: Section[\"content\"] = [];\n\tif (row.content) {\n\t\ttry {\n\t\t\tconst parsed: unknown = JSON.parse(row.content);\n\t\t\tif (Array.isArray(parsed)) {\n\t\t\t\t// DB stores serialized PortableTextBlock[]; trust the schema\n\t\t\t\tcontent = parsed;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Invalid JSON, ignore\n\t\t}\n\t}\n\n\t// Get preview URL from media (if present)\n\tlet previewUrl: string | undefined;\n\tif (row.preview_media_id) {\n\t\tconst media = await db\n\t\t\t.selectFrom(\"media\")\n\t\t\t.select(\"storage_key\")\n\t\t\t.where(\"id\", \"=\", row.preview_media_id)\n\t\t\t.executeTakeFirst();\n\n\t\tif (media) {\n\t\t\tpreviewUrl = `/_emdash/media/${media.storage_key}`;\n\t\t}\n\t}\n\n\treturn {\n\t\tid: row.id,\n\t\tslug: row.slug,\n\t\ttitle: row.title,\n\t\tdescription: row.description ?? undefined,\n\t\tkeywords,\n\t\tcontent,\n\t\tpreviewUrl,\n\t\tsource: row.source,\n\t\tthemeId: row.theme_id ?? undefined,\n\t\tcreatedAt: row.created_at,\n\t\tupdatedAt: row.updated_at,\n\t};\n}\n","/**\n * Section CRUD handlers\n */\n\nimport type { Kysely } from \"kysely\";\nimport { ulid } from \"ulidx\";\n\nimport { InvalidCursorError } from \"../../database/repositories/types.js\";\nimport type { FindManyResult } from \"../../database/repositories/types.js\";\nimport type { Database } from \"../../database/types.js\";\nimport {\n\tgetSectionById,\n\tgetSectionWithDb,\n\tgetSectionsWithDb,\n\ttype Section,\n\ttype GetSectionsOptions,\n} from \"../../sections/index.js\";\nimport type { ApiResult } from \"../types.js\";\n\nconst SLUG_PATTERN = /^[a-z0-9-]+$/;\n\nexport type SectionListResponse = FindManyResult<Section>;\n\n/**\n * List sections with optional filters\n */\nexport async function handleSectionList(\n\tdb: Kysely<Database>,\n\tparams: GetSectionsOptions,\n): Promise<ApiResult<SectionListResponse>> {\n\ttry {\n\t\tconst result = await getSectionsWithDb(db, {\n\t\t\tsource: params.source,\n\t\t\tsearch: params.search,\n\t\t\tlimit: params.limit,\n\t\t\tcursor: params.cursor,\n\t\t});\n\n\t\treturn { success: true, data: result };\n\t} catch (error) {\n\t\tif (error instanceof InvalidCursorError) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: { code: \"INVALID_CURSOR\", message: error.message },\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"SECTION_LIST_ERROR\", message: \"Failed to fetch sections\" },\n\t\t};\n\t}\n}\n\n/**\n * Create a section\n */\nexport async function handleSectionCreate(\n\tdb: Kysely<Database>,\n\tinput: {\n\t\tslug: string;\n\t\ttitle: string;\n\t\tdescription?: string;\n\t\tkeywords?: string[];\n\t\tcontent: unknown[];\n\t\tpreviewMediaId?: string;\n\t\tsource?: string;\n\t\tthemeId?: string;\n\t},\n): Promise<ApiResult<Section>> {\n\ttry {\n\t\t// Validate slug format\n\t\tif (!SLUG_PATTERN.test(input.slug)) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\t\tmessage: \"slug must only contain lowercase letters, numbers, and hyphens\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\t// Check if slug already exists\n\t\tconst existing = await db\n\t\t\t.selectFrom(\"_emdash_sections\")\n\t\t\t.select(\"id\")\n\t\t\t.where(\"slug\", \"=\", input.slug)\n\t\t\t.executeTakeFirst();\n\n\t\tif (existing) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"CONFLICT\",\n\t\t\t\t\tmessage: `Section with slug \"${input.slug}\" already exists`,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tconst id = ulid();\n\t\tconst now = new Date().toISOString();\n\n\t\tawait db\n\t\t\t.insertInto(\"_emdash_sections\")\n\t\t\t.values({\n\t\t\t\tid,\n\t\t\t\tslug: input.slug,\n\t\t\t\ttitle: input.title,\n\t\t\t\tdescription: input.description ?? null,\n\t\t\t\tkeywords: input.keywords ? JSON.stringify(input.keywords) : null,\n\t\t\t\tcontent: JSON.stringify(input.content),\n\t\t\t\tpreview_media_id: input.previewMediaId ?? null,\n\t\t\t\tsource: input.source ?? \"user\",\n\t\t\t\ttheme_id: input.themeId ?? null,\n\t\t\t\tcreated_at: now,\n\t\t\t\tupdated_at: now,\n\t\t\t})\n\t\t\t.execute();\n\n\t\tconst section = await getSectionById(id, db);\n\t\tif (!section) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: { code: \"SECTION_CREATE_ERROR\", message: \"Failed to fetch created section\" },\n\t\t\t};\n\t\t}\n\n\t\treturn { success: true, data: section };\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"SECTION_CREATE_ERROR\", message: \"Failed to create section\" },\n\t\t};\n\t}\n}\n\n/**\n * Get a section by slug\n */\nexport async function handleSectionGet(\n\tdb: Kysely<Database>,\n\tslug: string,\n): Promise<ApiResult<Section>> {\n\ttry {\n\t\tconst section = await getSectionWithDb(slug, db);\n\n\t\tif (!section) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: { code: \"NOT_FOUND\", message: `Section \"${slug}\" not found` },\n\t\t\t};\n\t\t}\n\n\t\treturn { success: true, data: section };\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"SECTION_GET_ERROR\", message: \"Failed to fetch section\" },\n\t\t};\n\t}\n}\n\n/**\n * Update a section by slug\n */\nexport async function handleSectionUpdate(\n\tdb: Kysely<Database>,\n\tslug: string,\n\tinput: {\n\t\tslug?: string;\n\t\ttitle?: string;\n\t\tdescription?: string;\n\t\tkeywords?: string[];\n\t\tcontent?: unknown[];\n\t\tpreviewMediaId?: string | null;\n\t},\n): Promise<ApiResult<Section>> {\n\ttry {\n\t\t// Check if section exists\n\t\tconst existing = await db\n\t\t\t.selectFrom(\"_emdash_sections\")\n\t\t\t.select([\"id\", \"source\"])\n\t\t\t.where(\"slug\", \"=\", slug)\n\t\t\t.executeTakeFirst();\n\n\t\tif (!existing) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: { code: \"NOT_FOUND\", message: `Section \"${slug}\" not found` },\n\t\t\t};\n\t\t}\n\n\t\t// Validate new slug if changing\n\t\tif (input.slug && input.slug !== slug) {\n\t\t\tif (!SLUG_PATTERN.test(input.slug)) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\t\t\tmessage: \"slug must only contain lowercase letters, numbers, and hyphens\",\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Check if new slug already exists\n\t\t\tconst slugExists = await db\n\t\t\t\t.selectFrom(\"_emdash_sections\")\n\t\t\t\t.select(\"id\")\n\t\t\t\t.where(\"slug\", \"=\", input.slug)\n\t\t\t\t.executeTakeFirst();\n\n\t\t\tif (slugExists) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tcode: \"CONFLICT\",\n\t\t\t\t\t\tmessage: `Section with slug \"${input.slug}\" already exists`,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// Build update object\n\t\tconst updates: Record<string, unknown> = {\n\t\t\tupdated_at: new Date().toISOString(),\n\t\t};\n\n\t\tif (input.slug !== undefined) updates.slug = input.slug;\n\t\tif (input.title !== undefined) updates.title = input.title;\n\t\tif (input.description !== undefined) updates.description = input.description;\n\t\tif (input.keywords !== undefined) updates.keywords = JSON.stringify(input.keywords);\n\t\tif (input.content !== undefined) updates.content = JSON.stringify(input.content);\n\t\tif (input.previewMediaId !== undefined) updates.preview_media_id = input.previewMediaId;\n\n\t\tawait db.updateTable(\"_emdash_sections\").set(updates).where(\"id\", \"=\", existing.id).execute();\n\n\t\tconst section = await getSectionById(existing.id, db);\n\t\tif (!section) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: { code: \"SECTION_UPDATE_ERROR\", message: \"Failed to fetch updated section\" },\n\t\t\t};\n\t\t}\n\n\t\treturn { success: true, data: section };\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"SECTION_UPDATE_ERROR\", message: \"Failed to update section\" },\n\t\t};\n\t}\n}\n\n/**\n * Delete a section by slug\n */\nexport async function handleSectionDelete(\n\tdb: Kysely<Database>,\n\tslug: string,\n): Promise<ApiResult<{ deleted: true }>> {\n\ttry {\n\t\t// Check if section exists and get source\n\t\tconst existing = await db\n\t\t\t.selectFrom(\"_emdash_sections\")\n\t\t\t.select([\"id\", \"source\", \"theme_id\"])\n\t\t\t.where(\"slug\", \"=\", slug)\n\t\t\t.executeTakeFirst();\n\n\t\tif (!existing) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: { code: \"NOT_FOUND\", message: `Section \"${slug}\" not found` },\n\t\t\t};\n\t\t}\n\n\t\t// Prevent deleting theme sections\n\t\tif (existing.source === \"theme\") {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"FORBIDDEN\",\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t\"Cannot delete theme-provided sections. Edit the section to create a user copy, then delete that.\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tawait db.deleteFrom(\"_emdash_sections\").where(\"id\", \"=\", existing.id).execute();\n\n\t\treturn { success: true, data: { deleted: true } };\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"SECTION_DELETE_ERROR\", message: \"Failed to delete section\" },\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmCA,eAAsB,WAAW,MAAuC;AAEvE,QAAO,iBAAiB,MADb,MAAM,OAAO,CACS;;;;;;;;AASlC,eAAsB,iBACrB,MACA,IAC0B;CAC1B,MAAM,MAAM,MAAM,GAChB,WAAW,mBAAmB,CAC9B,WAAW,CACX,SAAqB,CACrB,MAAM,QAAQ,KAAK,KAAK,CACxB,kBAAkB;AAEpB,KAAI,CAAC,IACJ,QAAO;AAGR,QAAO,aAAa,KAAK,GAAG;;;;;;;AAQ7B,eAAsB,eAAe,IAAY,IAA+C;CAC/F,MAAM,MAAM,MAAM,GAChB,WAAW,mBAAmB,CAC9B,WAAW,CACX,SAAqB,CACrB,MAAM,MAAM,KAAK,GAAG,CACpB,kBAAkB;AAEpB,KAAI,CAAC,IACJ,QAAO;AAGR,QAAO,aAAa,KAAK,GAAG;;;;;;;;;;;;;;;;AAiB7B,eAAsB,YACrB,UAA8B,EAAE,EACG;AAEnC,QAAO,kBADI,MAAM,OAAO,EACK,QAAQ;;;;;;;;AAStC,eAAsB,kBACrB,IACA,UAA8B,EAAE,EACG;CACnC,MAAM,QAAQ,KAAK,IAAI,KAAK,IAAI,GAAG,QAAQ,SAAS,GAAG,EAAE,IAAI;CAE7D,IAAI,QAAQ,GAAG,WAAW,mBAAmB,CAAC,WAAW;AAGzD,KAAI,QAAQ,OACX,SAA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