{"version":3,"file":"analyze.mjs","names":[],"sources":["../../../../../../src/astro/routes/api/import/wordpress/analyze.ts"],"sourcesContent":["/**\n * WordPress WXR analyze endpoint\n *\n * POST /_emdash/api/import/wordpress/analyze\n *\n * Accepts a WXR file upload and returns analysis of its contents,\n * including post types, counts, custom fields, and schema compatibility.\n */\n\nimport type { APIRoute } from \"astro\";\nimport { parseWxrString, SchemaRegistry, type WxrData } from \"@premium-cms/emdash\";\nimport mime from \"mime/lite\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, apiSuccess, handleError } from \"#api/error.js\";\nimport { RESERVED_COLLECTION_SLUGS } from \"#schema/types.js\";\nimport type { EmDashHandlers } from \"#types\";\n\nexport const prerender = false;\n\nconst NUMERIC_PATTERN = /^-?\\d+(\\.\\d+)?$/;\nconst INVALID_SLUG_CHARS = /[^a-z0-9_]/g;\nconst LEADING_NON_ALPHA = /^[^a-z]+/;\n\n/** Field compatibility status */\nexport type FieldCompatibility =\n\t| \"compatible\" // Field exists with compatible type\n\t| \"type_mismatch\" // Field exists but type differs\n\t| \"missing\"; // Field doesn't exist\n\n/** Single field definition for import */\nexport interface ImportFieldDef {\n\tslug: string;\n\tlabel: string;\n\ttype: string;\n\trequired: boolean;\n\tsearchable?: boolean;\n}\n\n/** Schema status for a collection */\nexport interface CollectionSchemaStatus {\n\t/** Whether collection exists */\n\texists: boolean;\n\t/** If exists, per-field compatibility */\n\tfieldStatus: Record<\n\t\tstring,\n\t\t{\n\t\t\tstatus: FieldCompatibility;\n\t\t\texistingType?: string;\n\t\t\trequiredType: string;\n\t\t}\n\t>;\n\t/** Can we safely import to this collection? */\n\tcanImport: boolean;\n\t/** Human-readable reason if canImport is false */\n\treason?: string;\n}\n\n/** Post type with full schema info */\nexport interface PostTypeAnalysis {\n\t/** WordPress post type name */\n\tname: string;\n\t/** Number of items to import */\n\tcount: number;\n\t/** Suggested collection slug */\n\tsuggestedCollection: string;\n\t/** Fields we need to create */\n\trequiredFields: ImportFieldDef[];\n\t/** Schema compatibility status */\n\tschemaStatus: CollectionSchemaStatus;\n}\n\n/** Individual attachment info for media import */\nexport interface AttachmentInfo {\n\tid?: number;\n\ttitle?: string;\n\turl?: string;\n\tfilename?: string;\n\tmimeType?: string;\n}\n\n/** Author info from WordPress */\nexport interface WpAuthorInfo {\n\tid?: number;\n\tlogin?: string;\n\temail?: string;\n\tdisplayName?: string;\n\tpostCount: number;\n}\n\nexport interface WxrAnalysis {\n\tsite: {\n\t\ttitle: string;\n\t\turl: string;\n\t};\n\tpostTypes: PostTypeAnalysis[];\n\tattachments: {\n\t\tcount: number;\n\t\titems: AttachmentInfo[];\n\t};\n\tcategories: number;\n\ttags: number;\n\tauthors: WpAuthorInfo[];\n\tcustomFields: Array<{\n\t\tkey: string;\n\t\tcount: number;\n\t\tsamples: string[];\n\t\tsuggestedField: string;\n\t\tsuggestedType: \"string\" | \"number\" | \"boolean\" | \"date\" | \"json\";\n\t\tisInternal: boolean;\n\t}>;\n}\n\nexport const POST: APIRoute = async ({ request, locals }) => {\n\tconst { emdash, user } = locals;\n\n\tconst denied = requirePerm(user, \"import:execute\");\n\tif (denied) return denied;\n\n\ttry {\n\t\tconst formData = await request.formData();\n\t\tconst fileEntry = formData.get(\"file\");\n\t\tconst file = fileEntry instanceof File ? fileEntry : null;\n\n\t\tif (!file) {\n\t\t\treturn apiError(\"VALIDATION_ERROR\", \"No file provided\", 400);\n\t\t}\n\n\t\t// Parse WXR\n\t\tconst text = await file.text();\n\t\tconst wxr = await parseWxrString(text);\n\n\t\t// Fetch existing collections from schema registry\n\t\tconst existingCollections = await fetchExistingCollections(emdash?.db);\n\n\t\t// Analyze content with schema compatibility\n\t\tconst analysis = analyzeWxr(wxr, existingCollections);\n\n\t\treturn apiSuccess(analysis);\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to analyze file\", \"WXR_ANALYZE_ERROR\");\n\t}\n};\n\n/** Existing collection info from schema registry */\ninterface ExistingCollection {\n\tslug: string;\n\tfields: Map<string, { type: string; columnType: string }>;\n}\n\n/** Fetch collections and their fields from schema registry */\nasync function fetchExistingCollections(\n\tdb: EmDashHandlers[\"db\"] | undefined,\n): Promise<Map<string, ExistingCollection>> {\n\tconst result = new Map<string, ExistingCollection>();\n\n\tif (!db) return result;\n\n\ttry {\n\t\tconst registry = new SchemaRegistry(db);\n\n\t\tconst collections = await registry.listCollections();\n\n\t\tfor (const collection of collections) {\n\t\t\tconst fields = await registry.listFields(collection.id);\n\t\t\tconst fieldMap = new Map<string, { type: string; columnType: string }>();\n\n\t\t\tfor (const field of fields) {\n\t\t\t\tfieldMap.set(field.slug, {\n\t\t\t\t\ttype: field.type,\n\t\t\t\t\tcolumnType: field.columnType,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tresult.set(collection.slug, {\n\t\t\t\tslug: collection.slug,\n\t\t\t\tfields: fieldMap,\n\t\t\t});\n\t\t}\n\t} catch (error) {\n\t\tconsole.warn(\"Could not fetch schema registry:\", error);\n\t}\n\n\treturn result;\n}\n\n/** Base fields required for any WordPress import */\nconst BASE_REQUIRED_FIELDS: ImportFieldDef[] = [\n\t{ slug: \"title\", label: \"Title\", type: \"string\", required: true, searchable: true },\n\t{ slug: \"content\", label: \"Content\", type: \"portableText\", required: false, searchable: true },\n\t{ slug: \"excerpt\", label: \"Excerpt\", type: \"text\", required: false },\n];\n\n/** Featured image field - only added to post types that have _thumbnail_id */\nconst FEATURED_IMAGE_FIELD: ImportFieldDef = {\n\tslug: \"featured_image\",\n\tlabel: \"Featured Image\",\n\ttype: \"image\",\n\trequired: false,\n};\n\nfunction analyzeWxr(\n\twxr: WxrData,\n\texistingCollections: Map<string, ExistingCollection>,\n): WxrAnalysis {\n\t// Count post types and track which have featured images\n\tconst postTypeCounts = new Map<string, number>();\n\tconst postTypesWithThumbnails = new Set<string>();\n\tconst metaKeys = new Map<string, { count: number; samples: string[]; isInternal: boolean }>();\n\tconst authorPostCounts = new Map<string, number>();\n\n\tfor (const post of wxr.posts) {\n\t\tconst type = post.postType || \"post\";\n\t\tpostTypeCounts.set(type, (postTypeCounts.get(type) || 0) + 1);\n\n\t\t// Count posts per author (by login)\n\t\tif (post.creator) {\n\t\t\tauthorPostCounts.set(post.creator, (authorPostCounts.get(post.creator) || 0) + 1);\n\t\t}\n\n\t\t// Track if this post type has featured images\n\t\tif (post.meta.has(\"_thumbnail_id\")) {\n\t\t\tpostTypesWithThumbnails.add(type);\n\t\t}\n\n\t\t// Analyze meta keys\n\t\tfor (const [key, value] of post.meta) {\n\t\t\tconst existing = metaKeys.get(key);\n\t\t\tif (existing) {\n\t\t\t\texisting.count++;\n\t\t\t\tif (existing.samples.length < 3 && value) {\n\t\t\t\t\texisting.samples.push(value.slice(0, 100));\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmetaKeys.set(key, {\n\t\t\t\t\tcount: 1,\n\t\t\t\t\tsamples: value ? [value.slice(0, 100)] : [],\n\t\t\t\t\tisInternal: isInternalMetaKey(key),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t// Map meta keys to fields (for custom fields analysis)\n\tconst customFields = [...metaKeys.entries()]\n\t\t.filter(([_, info]) => !info.isInternal)\n\t\t.map(([key, info]) => ({\n\t\t\tkey,\n\t\t\tcount: info.count,\n\t\t\tsamples: info.samples,\n\t\t\tsuggestedField: mapMetaKeyToField(key),\n\t\t\tsuggestedType: inferMetaType(key, info.samples[0]),\n\t\t\tisInternal: info.isInternal,\n\t\t}))\n\t\t.toSorted((a, b) => b.count - a.count);\n\n\t// Build post type analysis with schema compatibility\n\tconst seenSlugs = new Map<string, number>();\n\tconst postTypes: PostTypeAnalysis[] = [...postTypeCounts.entries()]\n\t\t.filter(([type]) => !isInternalPostType(type))\n\t\t.map(([name, count]) => {\n\t\t\tlet suggestedCollection = mapPostTypeToCollection(name);\n\n\t\t\t// Deduplicate: if multiple post types produce the same slug, append a suffix\n\t\t\tconst seen = seenSlugs.get(suggestedCollection) ?? 0;\n\t\t\tseenSlugs.set(suggestedCollection, seen + 1);\n\t\t\tif (seen > 0) {\n\t\t\t\tsuggestedCollection = `${suggestedCollection}_${seen}`;\n\t\t\t}\n\t\t\tconst existingCollection = existingCollections.get(suggestedCollection);\n\n\t\t\t// Build required fields - add featured_image only if posts have thumbnails\n\t\t\tconst requiredFields = [...BASE_REQUIRED_FIELDS];\n\t\t\tif (postTypesWithThumbnails.has(name)) {\n\t\t\t\trequiredFields.push(FEATURED_IMAGE_FIELD);\n\t\t\t}\n\n\t\t\tconst schemaStatus = checkSchemaCompatibility(requiredFields, existingCollection);\n\n\t\t\treturn {\n\t\t\t\tname,\n\t\t\t\tcount,\n\t\t\t\tsuggestedCollection,\n\t\t\t\trequiredFields,\n\t\t\t\tschemaStatus,\n\t\t\t};\n\t\t})\n\t\t.toSorted((a, b) => b.count - a.count);\n\n\t// Build attachment info list\n\tconst attachmentItems: AttachmentInfo[] = wxr.attachments.map((att) => {\n\t\tconst filename = att.url ? getFilenameFromUrl(att.url) : undefined;\n\t\tconst mimeType = filename ? guessMimeType(filename) : undefined;\n\t\treturn {\n\t\t\tid: att.id,\n\t\t\ttitle: att.title,\n\t\t\turl: att.url,\n\t\t\tfilename,\n\t\t\tmimeType,\n\t\t};\n\t});\n\n\treturn {\n\t\tsite: {\n\t\t\ttitle: wxr.site.title || \"WordPress Site\",\n\t\t\turl: wxr.site.link || \"\",\n\t\t},\n\t\tpostTypes,\n\t\tattachments: {\n\t\t\tcount: wxr.attachments.length,\n\t\t\titems: attachmentItems,\n\t\t},\n\t\tcategories: wxr.categories.length,\n\t\ttags: wxr.tags.length,\n\t\tauthors: wxr.authors.map((a) => ({\n\t\t\tid: a.id,\n\t\t\tlogin: a.login,\n\t\t\temail: a.email,\n\t\t\tdisplayName: a.displayName || a.login || \"Unknown\",\n\t\t\tpostCount: a.login ? authorPostCounts.get(a.login) || 0 : 0,\n\t\t})),\n\t\tcustomFields,\n\t};\n}\n\n/** Extract filename from URL */\nfunction getFilenameFromUrl(url: string): string | undefined {\n\ttry {\n\t\tconst parsed = new URL(url);\n\t\tconst segments = parsed.pathname.split(\"/\").filter(Boolean);\n\t\treturn segments.pop();\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** Guess MIME type from filename extension */\nfunction guessMimeType(filename: string): string | undefined {\n\treturn mime.getType(filename) ?? undefined;\n}\n\n/** Check if a collection schema is compatible with import requirements */\nfunction checkSchemaCompatibility(\n\trequiredFields: ImportFieldDef[],\n\texistingCollection: ExistingCollection | undefined,\n): CollectionSchemaStatus {\n\tif (!existingCollection) {\n\t\t// Collection doesn't exist - will need to create it\n\t\tconst fieldStatus: CollectionSchemaStatus[\"fieldStatus\"] = {};\n\t\tfor (const field of requiredFields) {\n\t\t\tfieldStatus[field.slug] = {\n\t\t\t\tstatus: \"missing\",\n\t\t\t\trequiredType: field.type,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\texists: false,\n\t\t\tfieldStatus,\n\t\t\tcanImport: true, // We can create it\n\t\t};\n\t}\n\n\t// Collection exists - check field compatibility\n\tconst fieldStatus: CollectionSchemaStatus[\"fieldStatus\"] = {};\n\tconst incompatibleFields: string[] = [];\n\n\tfor (const field of requiredFields) {\n\t\tconst existingField = existingCollection.fields.get(field.slug);\n\n\t\tif (!existingField) {\n\t\t\t// Field missing - we can add it\n\t\t\tfieldStatus[field.slug] = {\n\t\t\t\tstatus: \"missing\",\n\t\t\t\trequiredType: field.type,\n\t\t\t};\n\t\t} else if (isTypeCompatible(field.type, existingField.type)) {\n\t\t\t// Field exists and is compatible\n\t\t\tfieldStatus[field.slug] = {\n\t\t\t\tstatus: \"compatible\",\n\t\t\t\texistingType: existingField.type,\n\t\t\t\trequiredType: field.type,\n\t\t\t};\n\t\t} else {\n\t\t\t// Field exists but type doesn't match\n\t\t\tfieldStatus[field.slug] = {\n\t\t\t\tstatus: \"type_mismatch\",\n\t\t\t\texistingType: existingField.type,\n\t\t\t\trequiredType: field.type,\n\t\t\t};\n\t\t\tincompatibleFields.push(field.slug);\n\t\t}\n\t}\n\n\tconst canImport = incompatibleFields.length === 0;\n\tconst reason = canImport\n\t\t? undefined\n\t\t: `Incompatible field types: ${incompatibleFields.join(\", \")}. ` +\n\t\t\t`Existing fields have different types than required for import.`;\n\n\treturn {\n\t\texists: true,\n\t\tfieldStatus,\n\t\tcanImport,\n\t\treason,\n\t};\n}\n\n/** Check if two field types are compatible for import */\nfunction isTypeCompatible(requiredType: string, existingType: string): boolean {\n\t// Exact match\n\tif (requiredType === existingType) return true;\n\n\t// Compatible mappings\n\tconst compatibleTypes: Record<string, string[]> = {\n\t\tstring: [\"string\", \"text\", \"slug\"],\n\t\ttext: [\"string\", \"text\"],\n\t\tportableText: [\"portableText\", \"json\"],\n\t\tnumber: [\"number\", \"integer\"],\n\t\tinteger: [\"number\", \"integer\"],\n\t};\n\n\tconst compatible = compatibleTypes[requiredType];\n\treturn compatible?.includes(existingType) ?? false;\n}\n\nfunction isInternalPostType(type: string): boolean {\n\treturn [\n\t\t\"revision\",\n\t\t\"nav_menu_item\",\n\t\t\"custom_css\",\n\t\t\"customize_changeset\",\n\t\t\"oembed_cache\",\n\t\t\"wp_global_styles\",\n\t\t\"wp_navigation\",\n\t\t\"wp_template\",\n\t\t\"wp_template_part\",\n\t\t\"attachment\", // Handled separately as media\n\t\t\"wp_block\", // Handled separately as sections (reusable blocks)\n\t].includes(type);\n}\n\nfunction isInternalMetaKey(key: string): boolean {\n\tif (key.startsWith(\"_edit_\")) return true;\n\tif (key.startsWith(\"_wp_\")) return true;\n\tif (key === \"_edit_last\" || key === \"_edit_lock\") return true;\n\tif (key === \"_pingme\" || key === \"_encloseme\") return true;\n\n\t// Keep these useful ones\n\tif (key === \"_thumbnail_id\") return false;\n\tif (key.startsWith(\"_yoast_\")) return false;\n\tif (key.startsWith(\"_rank_math_\")) return false;\n\n\t// Other underscore prefixes are usually internal\n\tif (key.startsWith(\"_\")) return true;\n\n\treturn false;\n}\n\nfunction sanitizeSlug(slug: string): string {\n\tconst sanitized = slug\n\t\t.toLowerCase()\n\t\t.replace(INVALID_SLUG_CHARS, \"_\")\n\t\t.replace(LEADING_NON_ALPHA, \"\");\n\tif (!sanitized) return \"imported\";\n\tif (RESERVED_COLLECTION_SLUGS.includes(sanitized)) return `wp_${sanitized}`;\n\treturn sanitized;\n}\n\nfunction mapPostTypeToCollection(postType: string): string {\n\tconst mapping: Record<string, string> = {\n\t\tpost: \"posts\",\n\t\tpage: \"pages\",\n\t\tattachment: \"media\",\n\t\tproduct: \"products\",\n\t\tportfolio: \"portfolio\",\n\t\ttestimonial: \"testimonials\",\n\t\tteam: \"team\",\n\t\tevent: \"events\",\n\t\tfaq: \"faqs\",\n\t};\n\treturn mapping[postType] || sanitizeSlug(postType);\n}\n\nfunction mapMetaKeyToField(key: string): string {\n\t// SEO plugins\n\tif (key === \"_yoast_wpseo_title\") return \"seo_title\";\n\tif (key === \"_yoast_wpseo_metadesc\") return \"seo_description\";\n\tif (key === \"_rank_math_title\") return \"seo_title\";\n\tif (key === \"_rank_math_description\") return \"seo_description\";\n\tif (key === \"_thumbnail_id\") return \"featured_image\";\n\n\t// Remove leading underscore\n\tif (key.startsWith(\"_\")) return key.slice(1);\n\n\treturn key;\n}\n\nfunction inferMetaType(\n\tkey: string,\n\tvalue: string | undefined,\n): \"string\" | \"number\" | \"boolean\" | \"date\" | \"json\" {\n\tif (key.endsWith(\"_id\") || key === \"_thumbnail_id\") return \"string\"; // reference\n\tif (key.endsWith(\"_date\") || key.endsWith(\"_time\")) return \"date\";\n\tif (key.endsWith(\"_count\") || key.endsWith(\"_number\")) return \"number\";\n\n\tif (!value) return \"string\";\n\n\t// Serialized PHP or JSON\n\tif (value.startsWith(\"a:\") || value.startsWith(\"{\") || value.startsWith(\"[\")) return \"json\";\n\n\t// Number\n\tif (NUMERIC_PATTERN.test(value)) return \"number\";\n\n\t// Boolean\n\tif ([\"0\", \"1\", \"true\", \"false\"].includes(value)) return \"boolean\";\n\n\treturn \"string\";\n}\n\nfunction capitalize(str: string): string {\n\treturn str.charAt(0).toUpperCase() + str.slice(1);\n}\n\nfunction singularize(str: string): string {\n\tif (str.endsWith(\"ies\")) return str.slice(0, -3) + \"y\";\n\tif (str.endsWith(\"s\")) return str.slice(0, -1);\n\treturn str;\n}\n\n// Export helpers for use in prepare endpoint\nexport { capitalize, sanitizeSlug, singularize, mapPostTypeToCollection };\n"],"mappings":";;;;;;;;;AAkBA,MAAa,YAAY;AAEzB,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,oBAAoB;AA2F1B,MAAa,OAAiB,OAAO,EAAE,SAAS,aAAa;CAC5D,MAAM,EAAE,QAAQ,SAAS;CAEzB,MAAM,SAAS,YAAY,MAAM,iBAAiB;AAClD,KAAI,OAAQ,QAAO;AAEnB,KAAI;EAEH,MAAM,aADW,MAAM,QAAQ,UAAU,EACd,IAAI,OAAO;EACtC,MAAM,OAAO,qBAAqB,OAAO,YAAY;AAErD,MAAI,CAAC,KACJ,QAAO,SAAS,oBAAoB,oBAAoB,IAAI;AAa7D,SAAO,WAFU,WANL,MAAM,eADL,MAAM,KAAK,MAAM,CACQ,EAGV,MAAM,yBAAyB,QAAQ,GAAG,CAGjB,CAE1B;UACnB,OAAO;AACf,SAAO,YAAY,OAAO,0BAA0B,oBAAoB;;;;AAW1E,eAAe,yBACd,IAC2C;CAC3C,MAAM,yBAAS,IAAI,KAAiC;AAEpD,KAAI,CAAC,GAAI,QAAO;AAEhB,KAAI;EACH,MAAM,WAAW,IAAI,eAAe,GAAG;EAEvC,MAAM,cAAc,MAAM,SAAS,iBAAiB;AAEpD,OAAK,MAAM,cAAc,aAAa;GACrC,MAAM,SAAS,MAAM,SAAS,WAAW,WAAW,GAAG;GACvD,MAAM,2BAAW,IAAI,KAAmD;AAExE,QAAK,MAAM,SAAS,OACnB,UAAS,IAAI,MAAM,MAAM;IACxB,MAAM,MAAM;IACZ,YAAY,MAAM;IAClB,CAAC;AAGH,UAAO,IAAI,WAAW,MAAM;IAC3B,MAAM,WAAW;IACj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