{"version":3,"file":"utils-BGfBVUFP.mjs","names":["slugifyFn"],"sources":["../src/import/utils.ts"],"sourcesContent":["/**\n * Shared import utilities\n *\n * Common constants and functions used across all WordPress import sources.\n */\n\nimport type { PortableTextBlock } from \"@premium-cms/gutenberg-to-portable-text\";\nimport mime from \"mime/lite\";\n\nimport { RESERVED_FIELD_SLUGS } from \"../schema/types.js\";\nimport type { ImportFieldDef, CollectionSchemaStatus } from \"./types.js\";\n\n// =============================================================================\n// Constants\n// =============================================================================\n\n/** Internal WordPress post types that should be excluded from import */\nexport const INTERNAL_POST_TYPES = [\n\t\"revision\",\n\t\"nav_menu_item\",\n\t\"custom_css\",\n\t\"customize_changeset\",\n\t\"oembed_cache\",\n\t\"wp_global_styles\",\n\t\"wp_navigation\",\n\t\"wp_template\",\n\t\"wp_template_part\",\n\t\"attachment\", // Handled separately as media\n\t\"wp_block\", // Handled separately as sections (reusable blocks)\n];\n\n/** Internal meta key prefixes to filter out */\nexport const INTERNAL_META_PREFIXES = [\"_edit_\", \"_wp_\"];\n\nconst NUMERIC_PATTERN = /^-?\\d+(\\.\\d+)?$/;\nconst TRAILING_SLASHES = /\\/+$/;\nconst WP_JSON_SUFFIX = /\\/wp-json\\/?.*$/;\n\n/** Specific internal meta keys */\nexport const INTERNAL_META_KEYS = [\"_edit_last\", \"_edit_lock\", \"_pingme\", \"_encloseme\"];\n\n/** Base fields required for any WordPress import */\nexport const 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 */\nexport const FEATURED_IMAGE_FIELD: ImportFieldDef = {\n\tslug: \"featured_image\",\n\tlabel: \"Featured Image\",\n\ttype: \"image\",\n\trequired: false,\n};\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Check if a post type is internal/should be excluded\n */\nexport function isInternalPostType(type: string): boolean {\n\treturn INTERNAL_POST_TYPES.includes(type);\n}\n\n/**\n * Check if a meta key is internal/should be filtered out\n */\nexport function isInternalMetaKey(key: string): boolean {\n\t// Check specific keys\n\tif (INTERNAL_META_KEYS.includes(key)) return true;\n\n\t// Check prefixes\n\tfor (const prefix of INTERNAL_META_PREFIXES) {\n\t\tif (key.startsWith(prefix)) return true;\n\t}\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\n// =============================================================================\n// Status Mapping\n// =============================================================================\n\n/** Valid WordPress statuses */\nexport type WpStatus = \"publish\" | \"draft\" | \"pending\" | \"private\" | \"future\";\n\n/**\n * Map WordPress status to normalized status\n */\nexport function mapWpStatus(status: string | undefined): WpStatus {\n\tswitch (status) {\n\t\tcase \"publish\":\n\t\t\treturn \"publish\";\n\t\tcase \"draft\":\n\t\t\treturn \"draft\";\n\t\tcase \"pending\":\n\t\t\treturn \"pending\";\n\t\tcase \"private\":\n\t\t\treturn \"private\";\n\t\tcase \"future\":\n\t\t\treturn \"future\";\n\t\tdefault:\n\t\t\treturn \"draft\";\n\t}\n}\n\n// =============================================================================\n// Collection Mapping\n// =============================================================================\n\n/** Default mappings from WordPress post types to EmDash collections */\nconst POST_TYPE_TO_COLLECTION: Record<string, string> = {\n\tpost: \"posts\",\n\tpage: \"pages\",\n\tattachment: \"media\",\n\tproduct: \"products\",\n\tportfolio: \"portfolio\",\n\ttestimonial: \"testimonials\",\n\tteam: \"team\",\n\tevent: \"events\",\n\tfaq: \"faqs\",\n};\n\n/**\n * Map WordPress post type to EmDash collection name\n */\nexport function mapPostTypeToCollection(postType: string): string {\n\treturn POST_TYPE_TO_COLLECTION[postType] || postType;\n}\n\n// =============================================================================\n// Meta Key Mapping\n// =============================================================================\n\n/**\n * Map WordPress meta key to EmDash field slug\n */\nexport function 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\n/**\n * Infer field type from meta key name and sample value\n */\nexport function inferMetaType(\n\tkey: string,\n\tvalue: string | undefined,\n): \"string\" | \"number\" | \"boolean\" | \"date\" | \"json\" {\n\tif (key.endsWith(\"_id\") || key === \"_thumbnail_id\") return \"string\";\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\n// =============================================================================\n// Plugin Bookkeeping Meta\n// =============================================================================\n\n/**\n * Meta prefixes written by well-known WordPress plugins as operational\n * bookkeeping (sync state, counters, cache keys) — not content. Without\n * this filter, a mature site's analysis suggests dozens of junk fields\n * per post type and the real content fields drown in them.\n *\n * ponytail: curated list of the plugins we've seen in the wild, not a\n * taxonomy of the WP ecosystem. Unknown plugins' meta still gets through;\n * extend the list as real sites surface new offenders.\n */\nconst PLUGIN_META_PREFIXES = [\n\t\"aawp_\", // AAWP (Amazon affiliate)\n\t\"algolia_\", // Algolia / WP Search with Algolia\n\t\"amazon_polly_\", // Amazon Polly\n\t\"ampforwp_\", // AMP for WP\n\t\"classifai_\", // ClassifAI\n\t\"essb_\", // Easy Social Share Buttons\n\t\"eg_\", // Essential Grid\n\t\"gnpub_\", // Google News publisher tools\n\t\"jetpack_\", // Jetpack\n\t\"mashsb_\", // MashShare\n\t\"monsterinsights_\", // MonsterInsights\n\t\"onesignal_\", // OneSignal push\n\t\"penci_\", // Penci themes\n\t\"perfmatters_\", // Perfmatters\n\t\"pys_\", // PixelYourSite\n\t\"rank_math_\", // Rank Math internals (title/description go through the SEO pass)\n\t\"rp4wp_\", // Related Posts for WP\n\t\"saswp_\", // Schema & Structured Data for WP\n\t\"sbg_\", // Simple Blog Grid\n\t\"snap_\", // SNAP auto-poster\n\t\"spay_\", // Simple Pay\n\t\"tie_\", // TieLabs themes\n\t\"wl_\", // WordLift\n\t\"wpil_\", // Link Whisper\n\t\"wprm_\", // WP Recipe Maker internals\n\t\"wpswa_\", // WP Search with Algolia\n\t\"wpuf_\", // WP User Frontend\n\t\"yarpp_\", // YARPP\n];\n\n/** Exact meta keys that are plugin/core bookkeeping, not content. */\nconst PLUGIN_META_KEYS = new Set([\n\t\"entity_same_as\", // WordLift\n\t\"exclude_from_search\", // search exclusion plugins\n\t\"footnotes\", // Gutenberg core footnotes store\n\t\"inline_featured_image\", // inline featured image plugin\n\t\"os_meta\", // theme option stores\n\t\"thirstydata\", // ThirstyAffiliates\n]);\n\n/**\n * Check whether a meta key is well-known plugin bookkeeping that should\n * not become a content field. Hyphens are normalized to underscores\n * before matching (e.g. `ampforwp-amp-on-off`).\n */\nexport function isPluginBookkeepingMeta(key: string): boolean {\n\tconst normalized = key.replaceAll(\"-\", \"_\");\n\tif (PLUGIN_META_KEYS.has(normalized)) return true;\n\treturn PLUGIN_META_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n\n// =============================================================================\n// Field Slug Sanitization\n// =============================================================================\n\nconst INVALID_FIELD_SLUG_CHARS = /[^a-z0-9_]+/g;\nconst LEADING_NON_ALPHA_CHARS = /^[^a-z]+/;\n\n/**\n * Sanitize a WordPress meta/ACF key into a valid EmDash field slug\n * (`/^[a-z][a-z0-9_]*$/`, max 63 chars, not reserved).\n *\n * Must be applied consistently on both sides of an import: once when\n * creating fields from the analysis, and again when matching incoming\n * meta keys onto schema fields — otherwise keys like `my-field` create\n * `my_field` but never receive values.\n */\nexport function sanitizeFieldSlug(key: string): string {\n\tconst sanitized = key\n\t\t.toLowerCase()\n\t\t.replace(INVALID_FIELD_SLUG_CHARS, \"_\")\n\t\t.replace(LEADING_NON_ALPHA_CHARS, \"\")\n\t\t.slice(0, 63);\n\tif (!sanitized) return \"field\";\n\tif (RESERVED_FIELD_SLUGS.includes(sanitized)) return `wp_${sanitized}`;\n\treturn sanitized;\n}\n\n// =============================================================================\n// Internal Link Relativization\n// =============================================================================\n\nconst REGEX_SPECIALS = /[.*+?^${}()|[\\]\\\\]/g;\nconst LEADING_WWW = /^www\\./;\n\n/**\n * Turn an absolute URL into a root-relative one when it points at the\n * source site (www-insensitive). Returns null when the URL should be\n * left alone: external links, non-http(s) schemes, and `/wp-content/`\n * media files — those stay absolute so the later media pass can match\n * them against its old-URL -> new-URL map.\n */\nfunction relativizeUrl(url: string, sourceHost: string): string | null {\n\tif (!url.startsWith(\"http://\") && !url.startsWith(\"https://\")) return null;\n\ttry {\n\t\tconst parsed = new URL(url);\n\t\tif (parsed.hostname.replace(LEADING_WWW, \"\") !== sourceHost) return null;\n\t\tif (parsed.pathname.startsWith(\"/wp-content/\")) return null;\n\t\treturn `${parsed.pathname}${parsed.search}${parsed.hash}` || \"/\";\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction relativizeMarkDefs(\n\tmarkDefs: Array<{ _type: string; [key: string]: unknown }> | undefined,\n\tsourceHost: string,\n): void {\n\tfor (const def of markDefs ?? []) {\n\t\tif (def._type === \"link\" && typeof def.href === \"string\") {\n\t\t\tdef.href = relativizeUrl(def.href, sourceHost) ?? def.href;\n\t\t}\n\t}\n}\n\n/**\n * Rewrite internal links in imported content to root-relative URLs, in\n * place. Without this, imported posts keep linking back to the old\n * WordPress domain (e.g. `https://oldsite.com/companies/google/`)\n * instead of staying on the new site.\n *\n * ponytail: path structures are kept as-is (WP permalink /2024/05/slug/\n * stays /2024/05/slug/) — mapping old paths onto the new site's routes\n * is the planned permalink->redirect-map feature.\n */\nexport function relativizeContentLinks(blocks: PortableTextBlock[], siteUrl: string): void {\n\tlet sourceHost: string;\n\ttry {\n\t\tsourceHost = new URL(siteUrl).hostname.replace(LEADING_WWW, \"\");\n\t} catch {\n\t\treturn;\n\t}\n\t// Raw HTML in the wild uses double-quoted, single-quoted, and unquoted\n\t// href values; the backreference \\1 matches the closing quote (or\n\t// nothing, for unquoted). Rewritten links are normalized to href=\"...\".\n\tconst hrefPattern = new RegExp(\n\t\t`href=([\"']?)https?://(?:www\\\\.)?${sourceHost.replace(REGEX_SPECIALS, \"\\\\$&\")}(/[^\"'\\\\s>]*)?\\\\1`,\n\t\t\"gi\",\n\t);\n\n\tfor (const block of blocks) {\n\t\tswitch (block._type) {\n\t\t\tcase \"block\":\n\t\t\t\trelativizeMarkDefs(block.markDefs, sourceHost);\n\t\t\t\tbreak;\n\t\t\tcase \"image\":\n\t\t\t\t// asset.url stays absolute (media pass), only the click-through link\n\t\t\t\tif (block.link) block.link = relativizeUrl(block.link, sourceHost) ?? block.link;\n\t\t\t\tbreak;\n\t\t\tcase \"table\":\n\t\t\t\tfor (const row of block.rows) {\n\t\t\t\t\tfor (const cell of row.cells) relativizeMarkDefs(cell.markDefs, sourceHost);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"columns\":\n\t\t\t\tfor (const column of block.columns) relativizeContentLinks(column.content, siteUrl);\n\t\t\t\tbreak;\n\t\t\tcase \"cover\":\n\t\t\t\trelativizeContentLinks(block.content, siteUrl);\n\t\t\t\tbreak;\n\t\t\tcase \"button\":\n\t\t\t\tif (block.url) block.url = relativizeUrl(block.url, sourceHost) ?? block.url;\n\t\t\t\tbreak;\n\t\t\tcase \"buttons\":\n\t\t\t\tfor (const button of block.buttons) {\n\t\t\t\t\tif (button.url) button.url = relativizeUrl(button.url, sourceHost) ?? button.url;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"htmlBlock\":\n\t\t\t\tblock.html = block.html.replace(\n\t\t\t\t\threfPattern,\n\t\t\t\t\t(_m, _quote: string, path: string | undefined) => {\n\t\t\t\t\t\treturn `href=\"${path || \"/\"}\"`;\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t// URL-less or media-only blocks: media URLs are the media pass's job\n\t\t\tcase \"code\":\n\t\t\tcase \"embed\":\n\t\t\tcase \"gallery\":\n\t\t\tcase \"break\":\n\t\t\tcase \"file\":\n\t\t\tcase \"pullquote\":\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tblock satisfies never;\n\t\t}\n\t}\n}\n\n// =============================================================================\n// String Utilities\n// =============================================================================\n\nexport { slugify } from \"../utils/slugify.js\";\n\n/**\n * Normalize URL for API requests\n */\nexport function normalizeUrl(url: string): string {\n\tlet normalized = url.trim();\n\n\t// Add protocol if missing\n\tif (!normalized.startsWith(\"http\")) {\n\t\tnormalized = `https://${normalized}`;\n\t}\n\n\t// Remove trailing slash\n\tnormalized = normalized.replace(TRAILING_SLASHES, \"\");\n\n\t// Remove /wp-json if included\n\tnormalized = normalized.replace(WP_JSON_SUFFIX, \"\");\n\n\treturn normalized;\n}\n\n// =============================================================================\n// File Utilities\n// =============================================================================\n\n/**\n * Extract filename from URL\n */\nexport function 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/**\n * Guess MIME type from filename\n */\nexport function guessMimeType(filename: string): string | undefined {\n\treturn mime.getType(filename) ?? undefined;\n}\n\n// =============================================================================\n// Attachment Map Builder\n// =============================================================================\n\n/**\n * Build a map of attachment IDs to URLs for resolving featured images\n */\nexport function buildAttachmentMap(\n\tattachments: Array<{ id?: number | string; url?: string }>,\n): Map<string, string> {\n\tconst map = new Map<string, string>();\n\tfor (const att of attachments) {\n\t\tif (att.id && att.url) {\n\t\t\tmap.set(String(att.id), att.url);\n\t\t}\n\t}\n\treturn map;\n}\n\n// =============================================================================\n// Schema Compatibility\n// =============================================================================\n\n/**\n * Check if two field types are compatible for import\n */\nexport function isTypeCompatible(requiredType: string, existingType: string): boolean {\n\tif (requiredType === existingType) return true;\n\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\n// =============================================================================\n// Byline Import Utilities\n// =============================================================================\n\nimport type { BylineRepository } from \"../database/repositories/byline.js\";\nimport { slugify as slugifyFn } from \"../utils/slugify.js\";\n\nconst MAX_SLUG_COLLISION_ATTEMPTS = 1000;\n\n/**\n * Find or create a unique byline slug, capped at MAX_SLUG_COLLISION_ATTEMPTS.\n */\nexport async function ensureUniqueBylineSlug(\n\tbylineRepo: BylineRepository,\n\tbaseSlug: string,\n): Promise<string> {\n\tlet candidate = baseSlug;\n\tlet suffix = 2;\n\twhile (await bylineRepo.findBySlug(candidate)) {\n\t\tif (suffix > MAX_SLUG_COLLISION_ATTEMPTS) {\n\t\t\tthrow new Error(\n\t\t\t\t`Byline slug collision limit exceeded for base slug \"${baseSlug}\". ` +\n\t\t\t\t\t`Tried ${MAX_SLUG_COLLISION_ATTEMPTS} variants.`,\n\t\t\t);\n\t\t}\n\t\tcandidate = `${baseSlug}-${suffix}`;\n\t\tsuffix++;\n\t}\n\treturn candidate;\n}\n\n/**\n * Resolve (find-or-create) a byline for an imported WordPress author.\n * Caches results in `cache` keyed by `authorLogin:mappedUserId`.\n */\nexport async function resolveImportByline(\n\tauthorLogin: string | undefined,\n\tdisplayName: string | undefined,\n\tmappedUserId: string | undefined,\n\tbylineRepo: BylineRepository,\n\tcache: Map<string, string>,\n): Promise<string | undefined> {\n\tif (!authorLogin) return undefined;\n\tconst cacheKey = `${authorLogin}:${mappedUserId ?? \"\"}`;\n\tconst cached = cache.get(cacheKey);\n\tif (cached) return cached;\n\n\tif (mappedUserId) {\n\t\tconst existingForUser = await bylineRepo.findByUserId(mappedUserId);\n\t\tif (existingForUser) {\n\t\t\tcache.set(cacheKey, existingForUser.id);\n\t\t\treturn existingForUser.id;\n\t\t}\n\t}\n\n\tconst name = displayName || authorLogin;\n\tconst slugBase = slugifyFn(authorLogin);\n\tconst slug = await ensureUniqueBylineSlug(bylineRepo, slugBase || \"author\");\n\tconst created = await bylineRepo.create({\n\t\tslug,\n\t\tdisplayName: name,\n\t\tuserId: mappedUserId ?? null,\n\t\tisGuest: !mappedUserId,\n\t});\n\n\tcache.set(cacheKey, created.id);\n\treturn created.id;\n}\n\n// =============================================================================\n// Schema Compatibility\n// =============================================================================\n\n/**\n * Check schema compatibility between required fields and existing collection\n */\nexport function checkSchemaCompatibility(\n\trequiredFields: ImportFieldDef[],\n\texistingCollection: { slug: string; fields: Map<string, { type: string }> } | 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,\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\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\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\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\n\treturn {\n\t\texists: true,\n\t\tfieldStatus,\n\t\tcanImport,\n\t\treason,\n\t};\n}\n"],"mappings":";;;;;;AAiBA,MAAa,sBAAsB;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;AAGD,MAAa,yBAAyB,CAAC,UAAU,OAAO;AAExD,MAAM,kBAAkB;AACxB,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;;AAGvB,MAAa,qBAAqB;CAAC;CAAc;CAAc;CAAW;CAAa;;AAGvF,MAAa,uBAAyC;CACrD;EAAE,MAAM;EAAS,OAAO;EAAS,MAAM;EAAU,UAAU;EAAM,YAAY;EAAM;CACnF;EAAE,MAAM;EAAW,OAAO;EAAW,MAAM;EAAgB,UAAU;EAAO,YAAY;EAAM;CAC9F;EAAE,MAAM;EAAW,OAAO;EAAW,MAAM;EAAQ,UAAU;EAAO;CACpE;;AAGD,MAAa,uBAAuC;CACnD,MAAM;CACN,OAAO;CACP,MAAM;CACN,UAAU;CACV;;;;AASD,SAA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