emdash 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{apply-B4MsLM-w.mjs → apply-5uslYdUu.mjs} +174 -17
- package/dist/apply-5uslYdUu.mjs.map +1 -0
- package/dist/astro/index.d.mts +4 -4
- package/dist/astro/index.mjs +7 -3
- package/dist/astro/index.mjs.map +1 -1
- package/dist/astro/middleware/auth.d.mts +4 -4
- package/dist/astro/middleware/redirect.mjs +1 -1
- package/dist/astro/middleware/request-context.mjs +6 -1
- package/dist/astro/middleware/request-context.mjs.map +1 -1
- package/dist/astro/middleware.mjs +13 -12
- package/dist/astro/middleware.mjs.map +1 -1
- package/dist/astro/types.d.mts +13 -4
- package/dist/astro/types.d.mts.map +1 -1
- package/dist/cli/index.mjs +4 -4
- package/dist/{content-BsBoyj8G.mjs → content-D7J5y73J.mjs} +27 -1
- package/dist/{content-BsBoyj8G.mjs.map → content-D7J5y73J.mjs.map} +1 -1
- package/dist/db/index.d.mts +2 -2
- package/dist/db/index.mjs +1 -1
- package/dist/{index-BYv0mB9g.d.mts → index-De6_Xv3v.d.mts} +77 -3
- package/dist/index-De6_Xv3v.d.mts.map +1 -0
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +7 -7
- package/dist/media/local-runtime.d.mts +4 -4
- package/dist/plugins/adapt-sandbox-entry.d.mts +4 -4
- package/dist/{query-Bk_3vKvU.mjs → query-g4Ug-9j9.mjs} +3 -3
- package/dist/{query-Bk_3vKvU.mjs.map → query-g4Ug-9j9.mjs.map} +1 -1
- package/dist/{redirect-7lGhLBNZ.mjs → redirect-CN0Rt9Ob.mjs} +66 -10
- package/dist/redirect-CN0Rt9Ob.mjs.map +1 -0
- package/dist/{runner-Fl2NcUUz.d.mts → runner-BR2xKwhn.d.mts} +2 -2
- package/dist/{runner-Fl2NcUUz.d.mts.map → runner-BR2xKwhn.d.mts.map} +1 -1
- package/dist/{runner-Cd-_WyDo.mjs → runner-tQ7BJ4T7.mjs} +211 -134
- package/dist/runner-tQ7BJ4T7.mjs.map +1 -0
- package/dist/runtime.d.mts +4 -4
- package/dist/{search-DI4bM2w9.mjs → search-B0effn3j.mjs} +117 -23
- package/dist/search-B0effn3j.mjs.map +1 -0
- package/dist/seed/index.d.mts +2 -2
- package/dist/seed/index.mjs +3 -3
- package/dist/{taxonomies-DbrKzDju.mjs → taxonomies-K2z0Uhnj.mjs} +2 -2
- package/dist/{taxonomies-DbrKzDju.mjs.map → taxonomies-K2z0Uhnj.mjs.map} +1 -1
- package/dist/{types-8xrvl_68.d.mts → types-C2v0c34j.d.mts} +10 -1
- package/dist/{types-8xrvl_68.d.mts.map → types-C2v0c34j.d.mts.map} +1 -1
- package/dist/{validate-CaLH1Ia2.d.mts → validate-kM8Pjuf7.d.mts} +2 -2
- package/dist/{validate-CaLH1Ia2.d.mts.map → validate-kM8Pjuf7.d.mts.map} +1 -1
- package/dist/version-BnTKdfam.mjs +7 -0
- package/dist/{version-Uaf2ynPX.mjs.map → version-BnTKdfam.mjs.map} +1 -1
- package/package.json +5 -5
- package/src/api/handlers/content.ts +2 -0
- package/src/api/schemas/content.ts +8 -0
- package/src/astro/integration/font-provider.ts +3 -1
- package/src/astro/integration/index.ts +2 -0
- package/src/astro/integration/runtime.ts +55 -1
- package/src/astro/routes/admin.astro +14 -7
- package/src/astro/routes/api/auth/magic-link/send.ts +2 -1
- package/src/astro/routes/api/auth/passkey/options.ts +2 -1
- package/src/astro/routes/api/auth/signup/request.ts +26 -8
- package/src/astro/routes/api/comments/[collection]/[contentId]/index.ts +10 -6
- package/src/astro/routes/api/content/[collection]/[id]/compare.ts +1 -1
- package/src/astro/routes/api/content/[collection]/[id]/preview-url.ts +1 -1
- package/src/astro/routes/api/content/[collection]/[id]/revisions.ts +1 -1
- package/src/astro/routes/api/content/[collection]/[id]/translations.ts +26 -0
- package/src/astro/routes/api/content/[collection]/[id].ts +30 -2
- package/src/astro/routes/api/content/[collection]/index.ts +19 -1
- package/src/astro/routes/api/content/[collection]/trash.ts +1 -1
- package/src/astro/routes/api/import/wordpress-plugin/analyze.ts +4 -3
- package/src/astro/routes/api/import/wordpress-plugin/execute.ts +4 -3
- package/src/astro/routes/api/manifest.ts +7 -0
- package/src/astro/routes/api/oauth/device/code.ts +2 -1
- package/src/astro/routes/api/oauth/device/token.ts +2 -1
- package/src/astro/routes/api/setup/admin-verify.ts +30 -5
- package/src/astro/routes/api/setup/admin.ts +32 -8
- package/src/astro/routes/api/setup/index.ts +5 -2
- package/src/astro/types.ts +9 -0
- package/src/auth/rate-limit.ts +50 -22
- package/src/auth/setup-nonce.ts +22 -0
- package/src/auth/trusted-proxy.ts +92 -0
- package/src/database/migrations/035_bounded_404_log.ts +112 -0
- package/src/database/migrations/runner.ts +2 -0
- package/src/database/repositories/content.ts +39 -0
- package/src/database/repositories/options.ts +25 -0
- package/src/database/repositories/redirect.ts +111 -8
- package/src/database/types.ts +9 -0
- package/src/emdash-runtime.ts +3 -1
- package/src/import/registry.ts +4 -3
- package/src/import/ssrf.ts +253 -12
- package/src/mcp/server.ts +76 -3
- package/src/plugins/context.ts +15 -3
- package/src/plugins/manager.ts +6 -0
- package/src/plugins/request-meta.ts +66 -15
- package/src/plugins/routes.ts +3 -1
- package/src/seed/apply.ts +26 -0
- package/src/visual-editing/toolbar.ts +6 -1
- package/dist/apply-B4MsLM-w.mjs.map +0 -1
- package/dist/index-BYv0mB9g.d.mts.map +0 -1
- package/dist/redirect-7lGhLBNZ.mjs.map +0 -1
- package/dist/runner-Cd-_WyDo.mjs.map +0 -1
- package/dist/search-DI4bM2w9.mjs.map +0 -1
- package/dist/version-Uaf2ynPX.mjs +0 -7
package/dist/seed/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import { _ as SeedTaxonomyTerm, a as applySeed, b as ValidationResult, c as SeedCollection, d as SeedFile, f as SeedMenu, g as SeedTaxonomy, h as SeedSection, i as defaultSeed, l as SeedContentEntry, m as SeedRedirect, n as loadSeed, o as SeedApplyOptions, p as SeedMenuItem, r as loadUserSeed, s as SeedApplyResult, t as validateSeed, u as SeedField, v as SeedWidget, y as SeedWidgetArea } from "../validate-
|
|
1
|
+
import "../types-C2v0c34j.mjs";
|
|
2
|
+
import { _ as SeedTaxonomyTerm, a as applySeed, b as ValidationResult, c as SeedCollection, d as SeedFile, f as SeedMenu, g as SeedTaxonomy, h as SeedSection, i as defaultSeed, l as SeedContentEntry, m as SeedRedirect, n as loadSeed, o as SeedApplyOptions, p as SeedMenuItem, r as loadUserSeed, s as SeedApplyResult, t as validateSeed, u as SeedField, v as SeedWidget, y as SeedWidgetArea } from "../validate-kM8Pjuf7.mjs";
|
|
3
3
|
export { type SeedApplyOptions, type SeedApplyResult, type SeedCollection, type SeedContentEntry, type SeedField, type SeedFile, type SeedMenu, type SeedMenuItem, type SeedRedirect, type SeedSection, type SeedTaxonomy, type SeedTaxonomyTerm, type SeedWidget, type SeedWidgetArea, type ValidationResult, applySeed, defaultSeed, loadSeed, loadUserSeed, validateSeed };
|
package/dist/seed/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "../dialect-helpers-DhTzaUxP.mjs";
|
|
2
|
-
import "../content-
|
|
2
|
+
import "../content-D7J5y73J.mjs";
|
|
3
3
|
import "../base64-MBPo9ozB.mjs";
|
|
4
4
|
import "../types-CMMN0pNg.mjs";
|
|
5
5
|
import "../media-DqHVh136.mjs";
|
|
6
|
-
import { t as applySeed } from "../apply-
|
|
7
|
-
import "../redirect-
|
|
6
|
+
import { t as applySeed } from "../apply-5uslYdUu.mjs";
|
|
7
|
+
import "../redirect-CN0Rt9Ob.mjs";
|
|
8
8
|
import "../byline-C4OVd8b3.mjs";
|
|
9
9
|
import "../registry-Ci3WxVAr.mjs";
|
|
10
10
|
import "../loader-DeiBJEMe.mjs";
|
|
@@ -278,7 +278,7 @@ function primeEntryTermsCache(collection, entryId, byTaxonomy, applicableTaxonom
|
|
|
278
278
|
* Get entries by term (wraps getEmDashCollection)
|
|
279
279
|
*/
|
|
280
280
|
async function getEntriesByTerm(collection, taxonomyName, termSlug) {
|
|
281
|
-
const { getEmDashCollection } = await import("./query-
|
|
281
|
+
const { getEmDashCollection } = await import("./query-g4Ug-9j9.mjs").then((n) => n.o);
|
|
282
282
|
const { entries } = await getEmDashCollection(collection, { where: { [taxonomyName]: termSlug } });
|
|
283
283
|
return entries;
|
|
284
284
|
}
|
|
@@ -305,4 +305,4 @@ function buildTree(flatTerms, counts) {
|
|
|
305
305
|
|
|
306
306
|
//#endregion
|
|
307
307
|
export { getTaxonomyDefs as a, getTermsForEntries as c, getTaxonomyDef as i, invalidateTermCache as l, getEntriesByTerm as n, getTaxonomyTerms as o, getEntryTerms as r, getTerm as s, getAllTermsForEntries as t, taxonomies_exports as u };
|
|
308
|
-
//# sourceMappingURL=taxonomies-
|
|
308
|
+
//# sourceMappingURL=taxonomies-K2z0Uhnj.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taxonomies-DbrKzDju.mjs","names":[],"sources":["../src/taxonomies/index.ts"],"sourcesContent":["/**\n * Runtime API for taxonomies\n *\n * Provides functions to query taxonomy definitions and terms.\n */\n\nimport { getDb } from \"../loader.js\";\nimport { requestCached, setRequestCacheEntry } from \"../request-cache.js\";\nimport { chunks, SQL_BATCH_SIZE } from \"../utils/chunks.js\";\nimport { isMissingTableError } from \"../utils/db-errors.js\";\nimport type { TaxonomyDef, TaxonomyTerm, TaxonomyTermRow } from \"./types.js\";\n\n/**\n * No-op — kept for API compatibility.\n *\n * Used to invalidate a worker-lifetime \"has any term assignments?\" probe.\n * That probe added a query on every cold isolate to save one query on\n * sites with zero term assignments (i.e. the wrong tradeoff), so we\n * dropped it. The batch term join below returns an empty map for empty\n * sites at the same cost as the probe, without the pre-check.\n */\nexport function invalidateTermCache(): void {\n\t// Intentionally empty.\n}\n\n/**\n * Get all taxonomy definitions\n */\nexport async function getTaxonomyDefs(): Promise<TaxonomyDef[]> {\n\treturn requestCached(\"taxonomy-defs:all\", async () => {\n\t\tconst db = await getDb();\n\n\t\tconst rows = await db.selectFrom(\"_emdash_taxonomy_defs\").selectAll().execute();\n\n\t\treturn rows.map((row) => ({\n\t\t\tid: row.id,\n\t\t\tname: row.name,\n\t\t\tlabel: row.label,\n\t\t\tlabelSingular: row.label_singular ?? undefined,\n\t\t\thierarchical: row.hierarchical === 1,\n\t\t\tcollections: row.collections ? JSON.parse(row.collections) : [],\n\t\t}));\n\t});\n}\n\n/**\n * Get a single taxonomy definition by name\n */\nexport async function getTaxonomyDef(name: string): Promise<TaxonomyDef | null> {\n\treturn requestCached(`taxonomy-def:${name}`, async () => {\n\t\tconst db = await getDb();\n\n\t\tconst row = await db\n\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", name)\n\t\t\t.executeTakeFirst();\n\n\t\tif (!row) return null;\n\n\t\treturn {\n\t\t\tid: row.id,\n\t\t\tname: row.name,\n\t\t\tlabel: row.label,\n\t\t\tlabelSingular: row.label_singular ?? undefined,\n\t\t\thierarchical: row.hierarchical === 1,\n\t\t\tcollections: row.collections ? JSON.parse(row.collections) : [],\n\t\t};\n\t});\n}\n\n/**\n * Get all terms for a taxonomy (as tree for hierarchical, flat for tags)\n */\nexport async function getTaxonomyTerms(taxonomyName: string): Promise<TaxonomyTerm[]> {\n\treturn requestCached(`taxonomy-terms:${taxonomyName}`, async () => {\n\t\tconst db = await getDb();\n\n\t\t// Get taxonomy definition to check if hierarchical\n\t\tconst def = await getTaxonomyDef(taxonomyName);\n\t\tif (!def) return [];\n\n\t\t// Get all terms for this taxonomy\n\t\tconst rows = await db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", taxonomyName)\n\t\t\t.orderBy(\"label\", \"asc\")\n\t\t\t.execute();\n\n\t\t// Count entries for each term\n\t\tconst countsResult = await db\n\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t.select([\"taxonomy_id\"])\n\t\t\t.select((eb) => eb.fn.count<number>(\"entry_id\").as(\"count\"))\n\t\t\t.groupBy(\"taxonomy_id\")\n\t\t\t.execute();\n\n\t\tconst counts = new Map<string, number>();\n\t\tfor (const row of countsResult) {\n\t\t\tcounts.set(row.taxonomy_id, row.count);\n\t\t}\n\n\t\tconst flatTerms: TaxonomyTermRow[] = rows.map((row) => ({\n\t\t\tid: row.id,\n\t\t\tname: row.name,\n\t\t\tslug: row.slug,\n\t\t\tlabel: row.label,\n\t\t\tparent_id: row.parent_id,\n\t\t\tdata: row.data,\n\t\t}));\n\n\t\t// If hierarchical, build tree. Otherwise return flat\n\t\tif (def.hierarchical) {\n\t\t\treturn buildTree(flatTerms, counts);\n\t\t}\n\n\t\treturn flatTerms.map((term) => ({\n\t\t\tid: term.id,\n\t\t\tname: term.name,\n\t\t\tslug: term.slug,\n\t\t\tlabel: term.label,\n\t\t\tchildren: [],\n\t\t\tcount: counts.get(term.id) ?? 0,\n\t\t}));\n\t});\n}\n\n/**\n * Get a single term by taxonomy and slug\n */\nexport async function getTerm(taxonomyName: string, slug: string): Promise<TaxonomyTerm | null> {\n\tconst db = await getDb();\n\n\tconst row = await db\n\t\t.selectFrom(\"taxonomies\")\n\t\t.selectAll()\n\t\t.where(\"name\", \"=\", taxonomyName)\n\t\t.where(\"slug\", \"=\", slug)\n\t\t.executeTakeFirst();\n\n\tif (!row) return null;\n\n\t// Get entry count\n\tconst countResult = await db\n\t\t.selectFrom(\"content_taxonomies\")\n\t\t.select((eb) => eb.fn.count<number>(\"entry_id\").as(\"count\"))\n\t\t.where(\"taxonomy_id\", \"=\", row.id)\n\t\t.executeTakeFirst();\n\n\tconst count = countResult?.count ?? 0;\n\n\t// Get children if hierarchical\n\tconst childRows = await db\n\t\t.selectFrom(\"taxonomies\")\n\t\t.selectAll()\n\t\t.where(\"parent_id\", \"=\", row.id)\n\t\t.orderBy(\"label\", \"asc\")\n\t\t.execute();\n\n\tconst children = childRows.map((child) => ({\n\t\tid: child.id,\n\t\tname: child.name,\n\t\tslug: child.slug,\n\t\tlabel: child.label,\n\t\tparentId: child.parent_id ?? undefined,\n\t\tchildren: [],\n\t}));\n\n\treturn {\n\t\tid: row.id,\n\t\tname: row.name,\n\t\tslug: row.slug,\n\t\tlabel: row.label,\n\t\tparentId: row.parent_id ?? undefined,\n\t\tdescription: row.data ? JSON.parse(row.data).description : undefined,\n\t\tchildren,\n\t\tcount,\n\t};\n}\n\n/**\n * Get terms assigned to an entry\n */\nexport function getEntryTerms(\n\tcollection: string,\n\tentryId: string,\n\ttaxonomyName?: string,\n): Promise<TaxonomyTerm[]> {\n\treturn requestCached(`terms:${collection}:${entryId}:${taxonomyName ?? \"*\"}`, async () => {\n\t\tconst db = await getDb();\n\n\t\tlet query = db\n\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t.innerJoin(\"taxonomies\", \"taxonomies.id\", \"content_taxonomies.taxonomy_id\")\n\t\t\t.selectAll(\"taxonomies\")\n\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t.where(\"content_taxonomies.entry_id\", \"=\", entryId);\n\n\t\tif (taxonomyName) {\n\t\t\tquery = query.where(\"taxonomies.name\", \"=\", taxonomyName);\n\t\t}\n\n\t\tconst rows = await query.execute();\n\n\t\treturn rows.map((row) => ({\n\t\t\tid: row.id,\n\t\t\tname: row.name,\n\t\t\tslug: row.slug,\n\t\t\tlabel: row.label,\n\t\t\tparentId: row.parent_id ?? undefined,\n\t\t\tchildren: [],\n\t\t}));\n\t});\n}\n\n/**\n * Get terms for multiple entries in a single query (batched API)\n *\n * This is more efficient than calling getEntryTerms for each entry\n * when you need terms for a list of entries.\n *\n * @param collection - The collection type (e.g., \"posts\")\n * @param entryIds - Array of entry IDs\n * @param taxonomyName - The taxonomy name (e.g., \"categories\")\n * @returns Map from entry ID to array of terms\n */\nexport async function getTermsForEntries(\n\tcollection: string,\n\tentryIds: string[],\n\ttaxonomyName: string,\n): Promise<Map<string, TaxonomyTerm[]>> {\n\tconst result = new Map<string, TaxonomyTerm[]>();\n\n\t// Initialize all entry IDs with empty arrays so callers can always\n\t// expect the key to be present.\n\tconst uniqueIds = [...new Set(entryIds)];\n\tfor (const id of uniqueIds) {\n\t\tresult.set(id, []);\n\t}\n\n\tif (uniqueIds.length === 0) {\n\t\treturn result;\n\t}\n\n\tconst db = await getDb();\n\n\t// Chunk the IN clause so we stay below D1's ~100 bound-parameter limit\n\t// (and equivalent limits on other dialects). Matches getContentBylinesMany.\n\t//\n\t// Sites with no term assignments get back empty rows for one query —\n\t// the previous \"has any term assignments\" probe spent a round-trip on\n\t// every request to save that single query on empty sites, which is\n\t// backwards. Pre-migration databases (content_taxonomies missing) fall\n\t// through to the `isMissingTableError` catch and return empties.\n\tfor (const chunk of chunks(uniqueIds, SQL_BATCH_SIZE)) {\n\t\tlet rows;\n\t\ttry {\n\t\t\trows = await db\n\t\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t\t.innerJoin(\"taxonomies\", \"taxonomies.id\", \"content_taxonomies.taxonomy_id\")\n\t\t\t\t.select([\n\t\t\t\t\t\"content_taxonomies.entry_id\",\n\t\t\t\t\t\"taxonomies.id\",\n\t\t\t\t\t\"taxonomies.name\",\n\t\t\t\t\t\"taxonomies.slug\",\n\t\t\t\t\t\"taxonomies.label\",\n\t\t\t\t\t\"taxonomies.parent_id\",\n\t\t\t\t])\n\t\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t\t.where(\"content_taxonomies.entry_id\", \"in\", chunk)\n\t\t\t\t.where(\"taxonomies.name\", \"=\", taxonomyName)\n\t\t\t\t.execute();\n\t\t} catch (error) {\n\t\t\tif (isMissingTableError(error)) return result;\n\t\t\tthrow error;\n\t\t}\n\n\t\tfor (const row of rows) {\n\t\t\tconst entryId = row.entry_id;\n\t\t\tconst term: TaxonomyTerm = {\n\t\t\t\tid: row.id,\n\t\t\t\tname: row.name,\n\t\t\t\tslug: row.slug,\n\t\t\t\tlabel: row.label,\n\t\t\t\tparentId: row.parent_id ?? undefined,\n\t\t\t\tchildren: [],\n\t\t\t};\n\n\t\t\tconst terms = result.get(entryId);\n\t\t\tif (terms) {\n\t\t\t\tterms.push(term);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/**\n * Batch-fetch terms for multiple entries across ALL taxonomies in a single query.\n *\n * Returns a Map keyed by entry ID, where each value is a Record keyed by\n * taxonomy name with the matching terms as an array. Used by\n * getEmDashCollection to eagerly hydrate `entry.data.terms` and avoid\n * the N+1 pattern that callers hit when they loop and call getEntryTerms.\n *\n * Pre-migration databases (content_taxonomies missing) return an empty\n * Map — the join falls through to the `isMissingTableError` branch.\n */\nexport async function getAllTermsForEntries(\n\tcollection: string,\n\tentryIds: string[],\n): Promise<Map<string, Record<string, TaxonomyTerm[]>>> {\n\tconst result = new Map<string, Record<string, TaxonomyTerm[]>>();\n\n\t// Initialize unique entry IDs with empty objects so callers can always\n\t// expect the key to be present. Deduping also reduces wasted bound\n\t// parameters when a caller accidentally passes duplicates.\n\tconst uniqueIds = [...new Set(entryIds)];\n\tfor (const id of uniqueIds) {\n\t\tresult.set(id, {});\n\t}\n\n\tif (uniqueIds.length === 0) {\n\t\treturn result;\n\t}\n\n\tconst db = await getDb();\n\n\t// Look up which taxonomies apply to this collection. Used below to\n\t// seed empty arrays for taxonomies the entry has no terms in — so\n\t// callers (including the pre-populated getEntryTerms cache) get a\n\t// deterministic `[]` back rather than a cache miss that triggers a DB\n\t// round-trip just to confirm \"no terms\".\n\tconst applicableTaxonomyNames = await getCollectionTaxonomyNames(collection);\n\n\t// Chunk the IN clause to stay below D1's ~100 bound-parameter limit\n\t// (and equivalent limits on other dialects). Matches getContentBylinesMany.\n\t//\n\t// Previously we did a separate \"has any assignments\" probe to skip the\n\t// join on empty sites. That traded one query per request for a query\n\t// saved only on empty sites — backwards. Now the join runs directly\n\t// (returning zero rows cheaply) and pre-migration databases are caught\n\t// by the `isMissingTableError` branch below.\n\tfor (const chunk of chunks(uniqueIds, SQL_BATCH_SIZE)) {\n\t\tlet rows;\n\t\ttry {\n\t\t\trows = await db\n\t\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t\t.innerJoin(\"taxonomies\", \"taxonomies.id\", \"content_taxonomies.taxonomy_id\")\n\t\t\t\t.select([\n\t\t\t\t\t\"content_taxonomies.entry_id\",\n\t\t\t\t\t\"taxonomies.id\",\n\t\t\t\t\t\"taxonomies.name\",\n\t\t\t\t\t\"taxonomies.slug\",\n\t\t\t\t\t\"taxonomies.label\",\n\t\t\t\t\t\"taxonomies.parent_id\",\n\t\t\t\t])\n\t\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t\t.where(\"content_taxonomies.entry_id\", \"in\", chunk)\n\t\t\t\t.orderBy(\"taxonomies.label\", \"asc\")\n\t\t\t\t.execute();\n\t\t} catch (error) {\n\t\t\tif (isMissingTableError(error)) {\n\t\t\t\tfor (const id of uniqueIds) {\n\t\t\t\t\tprimeEntryTermsCache(collection, id, {}, applicableTaxonomyNames);\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\n\t\tfor (const row of rows) {\n\t\t\tconst entryId = row.entry_id;\n\t\t\tconst term: TaxonomyTerm = {\n\t\t\t\tid: row.id,\n\t\t\t\tname: row.name,\n\t\t\t\tslug: row.slug,\n\t\t\t\tlabel: row.label,\n\t\t\t\tparentId: row.parent_id ?? undefined,\n\t\t\t\tchildren: [],\n\t\t\t};\n\n\t\t\tconst byTaxonomy = result.get(entryId);\n\t\t\tif (!byTaxonomy) continue;\n\t\t\tconst existing = byTaxonomy[row.name];\n\t\t\tif (existing) {\n\t\t\t\texisting.push(term);\n\t\t\t} else {\n\t\t\t\tbyTaxonomy[row.name] = [term];\n\t\t\t}\n\t\t}\n\t}\n\n\t// Prime the request-scoped cache so legacy callers of getEntryTerms\n\t// (which still work per-entry) hit the in-memory cache instead of\n\t// re-querying. This is what gives us the N+1 win in existing templates\n\t// without requiring them to be rewritten.\n\tfor (const [entryId, byTaxonomy] of result) {\n\t\tprimeEntryTermsCache(collection, entryId, byTaxonomy, applicableTaxonomyNames);\n\t}\n\n\treturn result;\n}\n\n/**\n * Return the list of taxonomy names applicable to a collection, request-\n * cached so a page render only pays for it once.\n *\n * Returns an empty list when taxonomies haven't been defined yet.\n */\nasync function getCollectionTaxonomyNames(collection: string): Promise<string[]> {\n\ttry {\n\t\tconst defs = await getTaxonomyDefs();\n\t\treturn defs.filter((d) => d.collections.includes(collection)).map((d) => d.name);\n\t} catch (error) {\n\t\tif (isMissingTableError(error)) return [];\n\t\tthrow error;\n\t}\n}\n\n/**\n * Pre-populate the request-cache for every getEntryTerms call-shape that\n * could hit this entry:\n *\n * getEntryTerms(collection, entryId) -> key `terms:C:E:*`\n * getEntryTerms(collection, entryId, \"tag\") -> key `terms:C:E:tag`\n * getEntryTerms(collection, entryId, \"category\") -> key `terms:C:E:category`\n * ...one per taxonomy that applies to this collection\n *\n * Taxonomies with no rows on this entry are seeded with `[]` so legacy\n * callers short-circuit to the cached empty array instead of re-querying.\n */\nfunction primeEntryTermsCache(\n\tcollection: string,\n\tentryId: string,\n\tbyTaxonomy: Record<string, TaxonomyTerm[]>,\n\tapplicableTaxonomyNames: string[],\n): void {\n\t// Seed every applicable taxonomy with at least [] so\n\t// getEntryTerms(collection, id, \"tag\") doesn't miss the cache when an\n\t// entry has no tags.\n\tfor (const name of applicableTaxonomyNames) {\n\t\tsetRequestCacheEntry(`terms:${collection}:${entryId}:${name}`, byTaxonomy[name] ?? []);\n\t}\n\t// Also seed individual names that show up in data but aren't listed\n\t// as applicable (e.g. taxonomy reassigned to a different collection\n\t// since the terms were written).\n\tfor (const [name, terms] of Object.entries(byTaxonomy)) {\n\t\tsetRequestCacheEntry(`terms:${collection}:${entryId}:${name}`, terms);\n\t}\n\t// Flattened `*` view — all terms across all taxonomies in one array.\n\tconst allTerms = Object.values(byTaxonomy).flat();\n\tsetRequestCacheEntry(`terms:${collection}:${entryId}:*`, allTerms);\n}\n\n/**\n * Get entries by term (wraps getEmDashCollection)\n */\nexport async function getEntriesByTerm(\n\tcollection: string,\n\ttaxonomyName: string,\n\ttermSlug: string,\n): Promise<Array<{ id: string; data: Record<string, unknown> }>> {\n\tconst { getEmDashCollection } = await import(\"../query.js\");\n\n\t// Build options as the expected type — getEmDashCollection accepts\n\t// a generic options object with `where` for filtering by taxonomy\n\tconst options: Record<string, unknown> = {\n\t\twhere: { [taxonomyName]: termSlug },\n\t};\n\tconst { entries } = await getEmDashCollection(collection, options);\n\n\treturn entries;\n}\n\n/**\n * Build tree structure from flat terms\n */\nfunction buildTree(flatTerms: TaxonomyTermRow[], counts: Map<string, number>): TaxonomyTerm[] {\n\tconst map = new Map<string, TaxonomyTerm>();\n\tconst roots: TaxonomyTerm[] = [];\n\n\t// First pass: create nodes\n\tfor (const term of flatTerms) {\n\t\tmap.set(term.id, {\n\t\t\tid: term.id,\n\t\t\tname: term.name,\n\t\t\tslug: term.slug,\n\t\t\tlabel: term.label,\n\t\t\tparentId: term.parent_id ?? undefined,\n\t\t\tdescription: term.data ? JSON.parse(term.data).description : undefined,\n\t\t\tchildren: [],\n\t\t\tcount: counts.get(term.id) ?? 0,\n\t\t});\n\t}\n\n\t// Second pass: build tree\n\tfor (const term of map.values()) {\n\t\tif (term.parentId && map.has(term.parentId)) {\n\t\t\tmap.get(term.parentId)!.children.push(term);\n\t\t} else {\n\t\t\troots.push(term);\n\t\t}\n\t}\n\n\treturn roots;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,sBAA4B;;;;AAO5C,eAAsB,kBAA0C;AAC/D,QAAO,cAAc,qBAAqB,YAAY;AAKrD,UAFa,OAFF,MAAM,OAAO,EAEF,WAAW,wBAAwB,CAAC,WAAW,CAAC,SAAS,EAEnE,KAAK,SAAS;GACzB,IAAI,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I;EAC9B,CAAC;AAIH,MAAK,MAAM,QAAQ,IAAI,QAAQ,CAC9B,KAAI,KAAK,YAAY,IAAI,IAAI,KAAK,SAAS,CAC1C,KAAI,IAAI,KAAK,SAAS,CAAE,SAAS,KAAK,KAAK;KAE3C,OAAM,KAAK,KAAK;AAIlB,QAAO"}
|
|
1
|
+
{"version":3,"file":"taxonomies-K2z0Uhnj.mjs","names":[],"sources":["../src/taxonomies/index.ts"],"sourcesContent":["/**\n * Runtime API for taxonomies\n *\n * Provides functions to query taxonomy definitions and terms.\n */\n\nimport { getDb } from \"../loader.js\";\nimport { requestCached, setRequestCacheEntry } from \"../request-cache.js\";\nimport { chunks, SQL_BATCH_SIZE } from \"../utils/chunks.js\";\nimport { isMissingTableError } from \"../utils/db-errors.js\";\nimport type { TaxonomyDef, TaxonomyTerm, TaxonomyTermRow } from \"./types.js\";\n\n/**\n * No-op — kept for API compatibility.\n *\n * Used to invalidate a worker-lifetime \"has any term assignments?\" probe.\n * That probe added a query on every cold isolate to save one query on\n * sites with zero term assignments (i.e. the wrong tradeoff), so we\n * dropped it. The batch term join below returns an empty map for empty\n * sites at the same cost as the probe, without the pre-check.\n */\nexport function invalidateTermCache(): void {\n\t// Intentionally empty.\n}\n\n/**\n * Get all taxonomy definitions\n */\nexport async function getTaxonomyDefs(): Promise<TaxonomyDef[]> {\n\treturn requestCached(\"taxonomy-defs:all\", async () => {\n\t\tconst db = await getDb();\n\n\t\tconst rows = await db.selectFrom(\"_emdash_taxonomy_defs\").selectAll().execute();\n\n\t\treturn rows.map((row) => ({\n\t\t\tid: row.id,\n\t\t\tname: row.name,\n\t\t\tlabel: row.label,\n\t\t\tlabelSingular: row.label_singular ?? undefined,\n\t\t\thierarchical: row.hierarchical === 1,\n\t\t\tcollections: row.collections ? JSON.parse(row.collections) : [],\n\t\t}));\n\t});\n}\n\n/**\n * Get a single taxonomy definition by name\n */\nexport async function getTaxonomyDef(name: string): Promise<TaxonomyDef | null> {\n\treturn requestCached(`taxonomy-def:${name}`, async () => {\n\t\tconst db = await getDb();\n\n\t\tconst row = await db\n\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", name)\n\t\t\t.executeTakeFirst();\n\n\t\tif (!row) return null;\n\n\t\treturn {\n\t\t\tid: row.id,\n\t\t\tname: row.name,\n\t\t\tlabel: row.label,\n\t\t\tlabelSingular: row.label_singular ?? undefined,\n\t\t\thierarchical: row.hierarchical === 1,\n\t\t\tcollections: row.collections ? JSON.parse(row.collections) : [],\n\t\t};\n\t});\n}\n\n/**\n * Get all terms for a taxonomy (as tree for hierarchical, flat for tags)\n */\nexport async function getTaxonomyTerms(taxonomyName: string): Promise<TaxonomyTerm[]> {\n\treturn requestCached(`taxonomy-terms:${taxonomyName}`, async () => {\n\t\tconst db = await getDb();\n\n\t\t// Get taxonomy definition to check if hierarchical\n\t\tconst def = await getTaxonomyDef(taxonomyName);\n\t\tif (!def) return [];\n\n\t\t// Get all terms for this taxonomy\n\t\tconst rows = await db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", taxonomyName)\n\t\t\t.orderBy(\"label\", \"asc\")\n\t\t\t.execute();\n\n\t\t// Count entries for each term\n\t\tconst countsResult = await db\n\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t.select([\"taxonomy_id\"])\n\t\t\t.select((eb) => eb.fn.count<number>(\"entry_id\").as(\"count\"))\n\t\t\t.groupBy(\"taxonomy_id\")\n\t\t\t.execute();\n\n\t\tconst counts = new Map<string, number>();\n\t\tfor (const row of countsResult) {\n\t\t\tcounts.set(row.taxonomy_id, row.count);\n\t\t}\n\n\t\tconst flatTerms: TaxonomyTermRow[] = rows.map((row) => ({\n\t\t\tid: row.id,\n\t\t\tname: row.name,\n\t\t\tslug: row.slug,\n\t\t\tlabel: row.label,\n\t\t\tparent_id: row.parent_id,\n\t\t\tdata: row.data,\n\t\t}));\n\n\t\t// If hierarchical, build tree. Otherwise return flat\n\t\tif (def.hierarchical) {\n\t\t\treturn buildTree(flatTerms, counts);\n\t\t}\n\n\t\treturn flatTerms.map((term) => ({\n\t\t\tid: term.id,\n\t\t\tname: term.name,\n\t\t\tslug: term.slug,\n\t\t\tlabel: term.label,\n\t\t\tchildren: [],\n\t\t\tcount: counts.get(term.id) ?? 0,\n\t\t}));\n\t});\n}\n\n/**\n * Get a single term by taxonomy and slug\n */\nexport async function getTerm(taxonomyName: string, slug: string): Promise<TaxonomyTerm | null> {\n\tconst db = await getDb();\n\n\tconst row = await db\n\t\t.selectFrom(\"taxonomies\")\n\t\t.selectAll()\n\t\t.where(\"name\", \"=\", taxonomyName)\n\t\t.where(\"slug\", \"=\", slug)\n\t\t.executeTakeFirst();\n\n\tif (!row) return null;\n\n\t// Get entry count\n\tconst countResult = await db\n\t\t.selectFrom(\"content_taxonomies\")\n\t\t.select((eb) => eb.fn.count<number>(\"entry_id\").as(\"count\"))\n\t\t.where(\"taxonomy_id\", \"=\", row.id)\n\t\t.executeTakeFirst();\n\n\tconst count = countResult?.count ?? 0;\n\n\t// Get children if hierarchical\n\tconst childRows = await db\n\t\t.selectFrom(\"taxonomies\")\n\t\t.selectAll()\n\t\t.where(\"parent_id\", \"=\", row.id)\n\t\t.orderBy(\"label\", \"asc\")\n\t\t.execute();\n\n\tconst children = childRows.map((child) => ({\n\t\tid: child.id,\n\t\tname: child.name,\n\t\tslug: child.slug,\n\t\tlabel: child.label,\n\t\tparentId: child.parent_id ?? undefined,\n\t\tchildren: [],\n\t}));\n\n\treturn {\n\t\tid: row.id,\n\t\tname: row.name,\n\t\tslug: row.slug,\n\t\tlabel: row.label,\n\t\tparentId: row.parent_id ?? undefined,\n\t\tdescription: row.data ? JSON.parse(row.data).description : undefined,\n\t\tchildren,\n\t\tcount,\n\t};\n}\n\n/**\n * Get terms assigned to an entry\n */\nexport function getEntryTerms(\n\tcollection: string,\n\tentryId: string,\n\ttaxonomyName?: string,\n): Promise<TaxonomyTerm[]> {\n\treturn requestCached(`terms:${collection}:${entryId}:${taxonomyName ?? \"*\"}`, async () => {\n\t\tconst db = await getDb();\n\n\t\tlet query = db\n\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t.innerJoin(\"taxonomies\", \"taxonomies.id\", \"content_taxonomies.taxonomy_id\")\n\t\t\t.selectAll(\"taxonomies\")\n\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t.where(\"content_taxonomies.entry_id\", \"=\", entryId);\n\n\t\tif (taxonomyName) {\n\t\t\tquery = query.where(\"taxonomies.name\", \"=\", taxonomyName);\n\t\t}\n\n\t\tconst rows = await query.execute();\n\n\t\treturn rows.map((row) => ({\n\t\t\tid: row.id,\n\t\t\tname: row.name,\n\t\t\tslug: row.slug,\n\t\t\tlabel: row.label,\n\t\t\tparentId: row.parent_id ?? undefined,\n\t\t\tchildren: [],\n\t\t}));\n\t});\n}\n\n/**\n * Get terms for multiple entries in a single query (batched API)\n *\n * This is more efficient than calling getEntryTerms for each entry\n * when you need terms for a list of entries.\n *\n * @param collection - The collection type (e.g., \"posts\")\n * @param entryIds - Array of entry IDs\n * @param taxonomyName - The taxonomy name (e.g., \"categories\")\n * @returns Map from entry ID to array of terms\n */\nexport async function getTermsForEntries(\n\tcollection: string,\n\tentryIds: string[],\n\ttaxonomyName: string,\n): Promise<Map<string, TaxonomyTerm[]>> {\n\tconst result = new Map<string, TaxonomyTerm[]>();\n\n\t// Initialize all entry IDs with empty arrays so callers can always\n\t// expect the key to be present.\n\tconst uniqueIds = [...new Set(entryIds)];\n\tfor (const id of uniqueIds) {\n\t\tresult.set(id, []);\n\t}\n\n\tif (uniqueIds.length === 0) {\n\t\treturn result;\n\t}\n\n\tconst db = await getDb();\n\n\t// Chunk the IN clause so we stay below D1's ~100 bound-parameter limit\n\t// (and equivalent limits on other dialects). Matches getContentBylinesMany.\n\t//\n\t// Sites with no term assignments get back empty rows for one query —\n\t// the previous \"has any term assignments\" probe spent a round-trip on\n\t// every request to save that single query on empty sites, which is\n\t// backwards. Pre-migration databases (content_taxonomies missing) fall\n\t// through to the `isMissingTableError` catch and return empties.\n\tfor (const chunk of chunks(uniqueIds, SQL_BATCH_SIZE)) {\n\t\tlet rows;\n\t\ttry {\n\t\t\trows = await db\n\t\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t\t.innerJoin(\"taxonomies\", \"taxonomies.id\", \"content_taxonomies.taxonomy_id\")\n\t\t\t\t.select([\n\t\t\t\t\t\"content_taxonomies.entry_id\",\n\t\t\t\t\t\"taxonomies.id\",\n\t\t\t\t\t\"taxonomies.name\",\n\t\t\t\t\t\"taxonomies.slug\",\n\t\t\t\t\t\"taxonomies.label\",\n\t\t\t\t\t\"taxonomies.parent_id\",\n\t\t\t\t])\n\t\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t\t.where(\"content_taxonomies.entry_id\", \"in\", chunk)\n\t\t\t\t.where(\"taxonomies.name\", \"=\", taxonomyName)\n\t\t\t\t.execute();\n\t\t} catch (error) {\n\t\t\tif (isMissingTableError(error)) return result;\n\t\t\tthrow error;\n\t\t}\n\n\t\tfor (const row of rows) {\n\t\t\tconst entryId = row.entry_id;\n\t\t\tconst term: TaxonomyTerm = {\n\t\t\t\tid: row.id,\n\t\t\t\tname: row.name,\n\t\t\t\tslug: row.slug,\n\t\t\t\tlabel: row.label,\n\t\t\t\tparentId: row.parent_id ?? undefined,\n\t\t\t\tchildren: [],\n\t\t\t};\n\n\t\t\tconst terms = result.get(entryId);\n\t\t\tif (terms) {\n\t\t\t\tterms.push(term);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/**\n * Batch-fetch terms for multiple entries across ALL taxonomies in a single query.\n *\n * Returns a Map keyed by entry ID, where each value is a Record keyed by\n * taxonomy name with the matching terms as an array. Used by\n * getEmDashCollection to eagerly hydrate `entry.data.terms` and avoid\n * the N+1 pattern that callers hit when they loop and call getEntryTerms.\n *\n * Pre-migration databases (content_taxonomies missing) return an empty\n * Map — the join falls through to the `isMissingTableError` branch.\n */\nexport async function getAllTermsForEntries(\n\tcollection: string,\n\tentryIds: string[],\n): Promise<Map<string, Record<string, TaxonomyTerm[]>>> {\n\tconst result = new Map<string, Record<string, TaxonomyTerm[]>>();\n\n\t// Initialize unique entry IDs with empty objects so callers can always\n\t// expect the key to be present. Deduping also reduces wasted bound\n\t// parameters when a caller accidentally passes duplicates.\n\tconst uniqueIds = [...new Set(entryIds)];\n\tfor (const id of uniqueIds) {\n\t\tresult.set(id, {});\n\t}\n\n\tif (uniqueIds.length === 0) {\n\t\treturn result;\n\t}\n\n\tconst db = await getDb();\n\n\t// Look up which taxonomies apply to this collection. Used below to\n\t// seed empty arrays for taxonomies the entry has no terms in — so\n\t// callers (including the pre-populated getEntryTerms cache) get a\n\t// deterministic `[]` back rather than a cache miss that triggers a DB\n\t// round-trip just to confirm \"no terms\".\n\tconst applicableTaxonomyNames = await getCollectionTaxonomyNames(collection);\n\n\t// Chunk the IN clause to stay below D1's ~100 bound-parameter limit\n\t// (and equivalent limits on other dialects). Matches getContentBylinesMany.\n\t//\n\t// Previously we did a separate \"has any assignments\" probe to skip the\n\t// join on empty sites. That traded one query per request for a query\n\t// saved only on empty sites — backwards. Now the join runs directly\n\t// (returning zero rows cheaply) and pre-migration databases are caught\n\t// by the `isMissingTableError` branch below.\n\tfor (const chunk of chunks(uniqueIds, SQL_BATCH_SIZE)) {\n\t\tlet rows;\n\t\ttry {\n\t\t\trows = await db\n\t\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t\t.innerJoin(\"taxonomies\", \"taxonomies.id\", \"content_taxonomies.taxonomy_id\")\n\t\t\t\t.select([\n\t\t\t\t\t\"content_taxonomies.entry_id\",\n\t\t\t\t\t\"taxonomies.id\",\n\t\t\t\t\t\"taxonomies.name\",\n\t\t\t\t\t\"taxonomies.slug\",\n\t\t\t\t\t\"taxonomies.label\",\n\t\t\t\t\t\"taxonomies.parent_id\",\n\t\t\t\t])\n\t\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t\t.where(\"content_taxonomies.entry_id\", \"in\", chunk)\n\t\t\t\t.orderBy(\"taxonomies.label\", \"asc\")\n\t\t\t\t.execute();\n\t\t} catch (error) {\n\t\t\tif (isMissingTableError(error)) {\n\t\t\t\tfor (const id of uniqueIds) {\n\t\t\t\t\tprimeEntryTermsCache(collection, id, {}, applicableTaxonomyNames);\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\n\t\tfor (const row of rows) {\n\t\t\tconst entryId = row.entry_id;\n\t\t\tconst term: TaxonomyTerm = {\n\t\t\t\tid: row.id,\n\t\t\t\tname: row.name,\n\t\t\t\tslug: row.slug,\n\t\t\t\tlabel: row.label,\n\t\t\t\tparentId: row.parent_id ?? undefined,\n\t\t\t\tchildren: [],\n\t\t\t};\n\n\t\t\tconst byTaxonomy = result.get(entryId);\n\t\t\tif (!byTaxonomy) continue;\n\t\t\tconst existing = byTaxonomy[row.name];\n\t\t\tif (existing) {\n\t\t\t\texisting.push(term);\n\t\t\t} else {\n\t\t\t\tbyTaxonomy[row.name] = [term];\n\t\t\t}\n\t\t}\n\t}\n\n\t// Prime the request-scoped cache so legacy callers of getEntryTerms\n\t// (which still work per-entry) hit the in-memory cache instead of\n\t// re-querying. This is what gives us the N+1 win in existing templates\n\t// without requiring them to be rewritten.\n\tfor (const [entryId, byTaxonomy] of result) {\n\t\tprimeEntryTermsCache(collection, entryId, byTaxonomy, applicableTaxonomyNames);\n\t}\n\n\treturn result;\n}\n\n/**\n * Return the list of taxonomy names applicable to a collection, request-\n * cached so a page render only pays for it once.\n *\n * Returns an empty list when taxonomies haven't been defined yet.\n */\nasync function getCollectionTaxonomyNames(collection: string): Promise<string[]> {\n\ttry {\n\t\tconst defs = await getTaxonomyDefs();\n\t\treturn defs.filter((d) => d.collections.includes(collection)).map((d) => d.name);\n\t} catch (error) {\n\t\tif (isMissingTableError(error)) return [];\n\t\tthrow error;\n\t}\n}\n\n/**\n * Pre-populate the request-cache for every getEntryTerms call-shape that\n * could hit this entry:\n *\n * getEntryTerms(collection, entryId) -> key `terms:C:E:*`\n * getEntryTerms(collection, entryId, \"tag\") -> key `terms:C:E:tag`\n * getEntryTerms(collection, entryId, \"category\") -> key `terms:C:E:category`\n * ...one per taxonomy that applies to this collection\n *\n * Taxonomies with no rows on this entry are seeded with `[]` so legacy\n * callers short-circuit to the cached empty array instead of re-querying.\n */\nfunction primeEntryTermsCache(\n\tcollection: string,\n\tentryId: string,\n\tbyTaxonomy: Record<string, TaxonomyTerm[]>,\n\tapplicableTaxonomyNames: string[],\n): void {\n\t// Seed every applicable taxonomy with at least [] so\n\t// getEntryTerms(collection, id, \"tag\") doesn't miss the cache when an\n\t// entry has no tags.\n\tfor (const name of applicableTaxonomyNames) {\n\t\tsetRequestCacheEntry(`terms:${collection}:${entryId}:${name}`, byTaxonomy[name] ?? []);\n\t}\n\t// Also seed individual names that show up in data but aren't listed\n\t// as applicable (e.g. taxonomy reassigned to a different collection\n\t// since the terms were written).\n\tfor (const [name, terms] of Object.entries(byTaxonomy)) {\n\t\tsetRequestCacheEntry(`terms:${collection}:${entryId}:${name}`, terms);\n\t}\n\t// Flattened `*` view — all terms across all taxonomies in one array.\n\tconst allTerms = Object.values(byTaxonomy).flat();\n\tsetRequestCacheEntry(`terms:${collection}:${entryId}:*`, allTerms);\n}\n\n/**\n * Get entries by term (wraps getEmDashCollection)\n */\nexport async function getEntriesByTerm(\n\tcollection: string,\n\ttaxonomyName: string,\n\ttermSlug: string,\n): Promise<Array<{ id: string; data: Record<string, unknown> }>> {\n\tconst { getEmDashCollection } = await import(\"../query.js\");\n\n\t// Build options as the expected type — getEmDashCollection accepts\n\t// a generic options object with `where` for filtering by taxonomy\n\tconst options: Record<string, unknown> = {\n\t\twhere: { [taxonomyName]: termSlug },\n\t};\n\tconst { entries } = await getEmDashCollection(collection, options);\n\n\treturn entries;\n}\n\n/**\n * Build tree structure from flat terms\n */\nfunction buildTree(flatTerms: TaxonomyTermRow[], counts: Map<string, number>): TaxonomyTerm[] {\n\tconst map = new Map<string, TaxonomyTerm>();\n\tconst roots: TaxonomyTerm[] = [];\n\n\t// First pass: create nodes\n\tfor (const term of flatTerms) {\n\t\tmap.set(term.id, {\n\t\t\tid: term.id,\n\t\t\tname: term.name,\n\t\t\tslug: term.slug,\n\t\t\tlabel: term.label,\n\t\t\tparentId: term.parent_id ?? undefined,\n\t\t\tdescription: term.data ? JSON.parse(term.data).description : undefined,\n\t\t\tchildren: [],\n\t\t\tcount: counts.get(term.id) ?? 0,\n\t\t});\n\t}\n\n\t// Second pass: build tree\n\tfor (const term of map.values()) {\n\t\tif (term.parentId && map.has(term.parentId)) {\n\t\t\tmap.get(term.parentId)!.children.push(term);\n\t\t} else {\n\t\t\troots.push(term);\n\t\t}\n\t}\n\n\treturn roots;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,sBAA4B;;;;AAO5C,eAAsB,kBAA0C;AAC/D,QAAO,cAAc,qBAAqB,YAAY;AAKrD,UAFa,OAFF,MAAM,OAAO,EAEF,WAAW,wBAAwB,CAAC,WAAW,CAAC,SAAS,EAEnE,KAAK,SAAS;GACzB,IAAI,IAAI;GACR,MAAM,IAAI;GACV,OAAO,IAAI;GACX,eAAe,IAAI,kBAAkB;GACrC,cAAc,IAAI,iBAAiB;GACnC,aAAa,IAAI,cAAc,KAAK,MAAM,IAAI,YAAY,GAAG,EAAE;GAC/D,EAAE;GACF;;;;;AAMH,eAAsB,eAAe,MAA2C;AAC/E,QAAO,cAAc,gBAAgB,QAAQ,YAAY;EAGxD,MAAM,MAAM,OAFD,MAAM,OAAO,EAGtB,WAAW,wBAAwB,CACnC,WAAW,CACX,MAAM,QAAQ,KAAK,KAAK,CACxB,kBAAkB;AAEpB,MAAI,CAAC,IAAK,QAAO;AAEjB,SAAO;GACN,IAAI,IAAI;GACR,MAAM,IAAI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G,QAAQ,WAAW,SAAS,EAAE,CAAC;AAKvF,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,WAAW,CACrD,sBAAqB,SAAS,WAAW,GAAG,QAAQ,GAAG,QAAQ,MAAM;CAGtE,MAAM,WAAW,OAAO,OAAO,WAAW,CAAC,MAAM;AACjD,sBAAqB,SAAS,WAAW,GAAG,QAAQ,KAAK,SAAS;;;;;AAMnE,eAAsB,iBACrB,YACA,cACA,UACgE;CAChE,MAAM,EAAE,wBAAwB,MAAM,OAAO;CAO7C,MAAM,EAAE,YAAY,MAAM,oBAAoB,YAHL,EACxC,OAAO,GAAG,eAAe,UAAU,EACnC,CACiE;AAElE,QAAO;;;;;AAMR,SAAS,UAAU,WAA8B,QAA6C;CAC7F,MAAM,sBAAM,IAAI,KAA2B;CAC3C,MAAM,QAAwB,EAAE;AAGhC,MAAK,MAAM,QAAQ,UAClB,KAAI,IAAI,KAAK,IAAI;EAChB,IAAI,KAAK;EACT,MAAM,KAAK;EACX,MAAM,KAAK;EACX,OAAO,KAAK;EACZ,UAAU,KAAK,aAAa;EAC5B,aAAa,KAAK,OAAO,KAAK,MAAM,KAAK,KAAK,CAAC,cAAc;EAC7D,UAAU,EAAE;EACZ,OAAO,OAAO,IAAI,KAAK,GAAG,IAAI;EAC9B,CAAC;AAIH,MAAK,MAAM,QAAQ,IAAI,QAAQ,CAC9B,KAAI,KAAK,YAAY,IAAI,IAAI,KAAK,SAAS,CAC1C,KAAI,IAAI,KAAK,SAAS,CAAE,SAAS,KAAK,KAAK;KAE3C,OAAM,KAAK,KAAK;AAIlB,QAAO"}
|
|
@@ -393,6 +393,15 @@ interface NotFoundLogTable {
|
|
|
393
393
|
referrer: string | null;
|
|
394
394
|
user_agent: string | null;
|
|
395
395
|
ip: string | null;
|
|
396
|
+
hits: number;
|
|
397
|
+
/**
|
|
398
|
+
* Migration 035 adds this as a nullable column (SQLite can't add a
|
|
399
|
+
* NOT NULL column with a non-constant default to an existing table).
|
|
400
|
+
* The `log404` upsert always writes a value, so new and updated rows
|
|
401
|
+
* always have one, but existing rows pre-migration were backfilled
|
|
402
|
+
* without a NOT NULL constraint. Typed as nullable to match the schema.
|
|
403
|
+
*/
|
|
404
|
+
last_seen_at: string | null;
|
|
396
405
|
created_at: string;
|
|
397
406
|
}
|
|
398
407
|
interface BylineTable {
|
|
@@ -423,4 +432,4 @@ interface RateLimitTable {
|
|
|
423
432
|
}
|
|
424
433
|
//#endregion
|
|
425
434
|
export { MediaTable as n, UserTable as r, Database as t };
|
|
426
|
-
//# sourceMappingURL=types-
|
|
435
|
+
//# sourceMappingURL=types-C2v0c34j.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-C2v0c34j.d.mts","names":[],"sources":["../src/database/types.ts"],"mappings":";;;UAMiB,aAAA;EAChB,EAAA;EACA,UAAA;EACA,QAAA;EACA,IAAA;EACA,SAAA;EACA,UAAA,EAAY,SAAA;AAAA;AAAA,UAGI,aAAA;EAChB,EAAA;EACA,IAAA;EACA,IAAA;EACA,KAAA;EACA,SAAA;EACA,IAAA;AAAA;AAAA,UAGgB,oBAAA;EAChB,UAAA;EACA,QAAA;EACA,WAAA;AAAA;AAAA,UAGgB,gBAAA;EAChB,EAAA;EACA,IAAA;EACA,KAAA;EACA,cAAA;EACA,YAAA;EACA,WAAA;EACA,UAAA,EAAY,SAAA;AAAA;AAAA,UAGI,UAAA;EAChB,EAAA;EACA,QAAA;EACA,SAAA;EACA,IAAA;EACA,KAAA;EACA,MAAA;EACA,GAAA;EACA,OAAA;EACA,WAAA;EACA,MAAA;EACA,YAAA;EACA,QAAA;EACA,cAAA;EACA,UAAA,EAAY,SAAA;EACZ,SAAA;AAAA;AAAA,UAGgB,SAAA;EAChB,EAAA;EACA,KAAA;EACA,IAAA;EACA,UAAA;EACA,IAAA;EACA,cAAA;EACA,IAAA;EACA,QAAA,EAAU,SAAA;EACV,UAAA,EAAY,SAAA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AA;EACA,YAAA;EACA,GAAA;EACA,eAAA;EACA,WAAA;EACA,OAAA;EACA,QAAA;EACA,UAAA,EAAY,SAAA;EACZ,UAAA,EAAY,SAAA;AAAA;AAAA,UAGI,kBAAA;EAChB,EAAA;EACA,eAAA;EACA,UAAA;EACA,SAAA;EACA,UAAA;EACA,UAAA;EACA,UAAA,EAAY,SAAA;AAAA;AAAA,UAKI,cAAA;EAChB,GAAA;EACA,MAAA;EACA,KAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Database } from "./types-
|
|
1
|
+
import { t as Database } from "./types-C2v0c34j.mjs";
|
|
2
2
|
import { i as SiteSettings, m as FieldType } from "./types-CnZYHyLW.mjs";
|
|
3
3
|
import { d as Storage } from "./types-CFWjXmus.mjs";
|
|
4
4
|
import { Kysely } from "kysely";
|
|
@@ -328,4 +328,4 @@ declare function loadUserSeed(): Promise<SeedFile | null>;
|
|
|
328
328
|
declare function validateSeed(data: unknown): ValidationResult;
|
|
329
329
|
//#endregion
|
|
330
330
|
export { SeedTaxonomyTerm as _, applySeed as a, ValidationResult as b, SeedCollection as c, SeedFile as d, SeedMenu as f, SeedTaxonomy as g, SeedSection as h, defaultSeed as i, SeedContentEntry as l, SeedRedirect as m, loadSeed as n, SeedApplyOptions as o, SeedMenuItem as p, loadUserSeed as r, SeedApplyResult as s, validateSeed as t, SeedField as u, SeedWidget as v, SeedWidgetArea as y };
|
|
331
|
-
//# sourceMappingURL=validate-
|
|
331
|
+
//# sourceMappingURL=validate-kM8Pjuf7.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-
|
|
1
|
+
{"version":3,"file":"validate-kM8Pjuf7.d.mts","names":[],"sources":["../src/seed/types.ts","../src/seed/apply.ts","../src/seed/default.ts","../src/seed/load.ts","../src/seed/validate.ts"],"mappings":";;;;;;;;;UAciB,QAAA;EAwBR;EAtBR,OAAA;EA4Bc;EAzBd,OAAA;EA+BU;EA5BV,IA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AChC,QAAA;IAAY,OAAA;IAAiB,OAAA;IAAiB,OAAA;EAAA;EAC9C,QAAA;IAAY,OAAA;EAAA;EACZ,OAAA;IAAW,OAAA;IAAiB,OAAA;IAAiB,OAAA;EAAA;EAC7C,KAAA;IAAS,OAAA;IAAiB,OAAA;EAAA;AAAA;;;;UAMV,gBAAA;EAChB,KAAA;EACA,MAAA;EACA,QAAA;AAAA;;;;;;;;;;;;;iBCzOqB,SAAA,CACrB,EAAA,EAAI,MAAA,CAAO,QAAA,GACX,IAAA,EAAM,QAAA,EACN,OAAA,GAAS,gBAAA,GACP,OAAA,CAAQ,eAAA;;;cCxDE,WAAA,EAAa,QAAA;;;;;;iBCcJ,QAAA,CAAA,GAAY,OAAA,CAAQ,QAAA;;;;iBAQpB,YAAA,CAAA,GAAgB,OAAA,CAAQ,QAAA;;;AHjB9C;;;;;;AAAA,iBIuBgB,YAAA,CAAa,IAAA,YAAgB,gBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-
|
|
1
|
+
{"version":3,"file":"version-BnTKdfam.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/**\n * Build-time version constants, replaced by tsdown/Vite `define`.\n * Falls back to \"dev\" when running uncompiled (tests, dev).\n */\n\ndeclare const __EMDASH_VERSION__: string;\ndeclare const __EMDASH_COMMIT__: string;\n\nexport const VERSION: string =\n\ttypeof __EMDASH_VERSION__ !== \"undefined\" ? __EMDASH_VERSION__ : \"dev\";\n\nexport const COMMIT: string = typeof __EMDASH_COMMIT__ !== \"undefined\" ? __EMDASH_COMMIT__ : \"dev\";\n"],"mappings":";AAQA,MAAa;AAGb,MAAa"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "emdash",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Astro-native CMS with WordPress migration support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -185,9 +185,9 @@
|
|
|
185
185
|
"ulidx": "^2.4.1",
|
|
186
186
|
"upng-js": "^2.1.0",
|
|
187
187
|
"zod": "^4.3.5",
|
|
188
|
-
"@emdash-cms/
|
|
189
|
-
"@emdash-cms/
|
|
190
|
-
"@emdash-cms/gutenberg-to-portable-text": "0.
|
|
188
|
+
"@emdash-cms/admin": "0.7.0",
|
|
189
|
+
"@emdash-cms/auth": "0.7.0",
|
|
190
|
+
"@emdash-cms/gutenberg-to-portable-text": "0.7.0"
|
|
191
191
|
},
|
|
192
192
|
"optionalDependencies": {
|
|
193
193
|
"@libsql/kysely-libsql": "^0.4.0",
|
|
@@ -215,7 +215,7 @@
|
|
|
215
215
|
"vite": "^6.0.0",
|
|
216
216
|
"vitest": "^4.0.18",
|
|
217
217
|
"zod-openapi": "^5.4.6",
|
|
218
|
-
"@emdash-cms/blocks": "0.
|
|
218
|
+
"@emdash-cms/blocks": "0.7.0"
|
|
219
219
|
},
|
|
220
220
|
"repository": {
|
|
221
221
|
"type": "git",
|
|
@@ -483,6 +483,7 @@ export async function handleContentUpdate(
|
|
|
483
483
|
bylines?: ContentBylineInput[];
|
|
484
484
|
_rev?: string;
|
|
485
485
|
seo?: ContentSeoInput;
|
|
486
|
+
publishedAt?: string | null;
|
|
486
487
|
},
|
|
487
488
|
): Promise<ApiResult<ContentResponse>> {
|
|
488
489
|
try {
|
|
@@ -542,6 +543,7 @@ export async function handleContentUpdate(
|
|
|
542
543
|
slug: body.slug,
|
|
543
544
|
status: body.status,
|
|
544
545
|
authorId: body.authorId,
|
|
546
|
+
publishedAt: body.publishedAt,
|
|
545
547
|
});
|
|
546
548
|
|
|
547
549
|
if (body.bylines !== undefined) {
|
|
@@ -27,6 +27,11 @@ export const contentListQuery = cursorPaginationQuery
|
|
|
27
27
|
})
|
|
28
28
|
.meta({ id: "ContentListQuery" });
|
|
29
29
|
|
|
30
|
+
/** ISO 8601 datetime for `publishedAt` / `createdAt`. Routes gate writes behind `content:publish_any`. */
|
|
31
|
+
const contentDateOverride = z.iso
|
|
32
|
+
.datetime({ offset: true, message: "must be an ISO 8601 datetime" })
|
|
33
|
+
.nullish();
|
|
34
|
+
|
|
30
35
|
export const contentCreateBody = z
|
|
31
36
|
.object({
|
|
32
37
|
data: z.record(z.string(), z.unknown()),
|
|
@@ -36,6 +41,8 @@ export const contentCreateBody = z
|
|
|
36
41
|
locale: localeCode.optional(),
|
|
37
42
|
translationOf: z.string().optional(),
|
|
38
43
|
seo: contentSeoInput.optional(),
|
|
44
|
+
publishedAt: contentDateOverride,
|
|
45
|
+
createdAt: contentDateOverride,
|
|
39
46
|
})
|
|
40
47
|
.meta({ id: "ContentCreateBody" });
|
|
41
48
|
|
|
@@ -52,6 +59,7 @@ export const contentUpdateBody = z
|
|
|
52
59
|
.meta({ description: "Opaque revision token for optimistic concurrency" }),
|
|
53
60
|
skipRevision: z.boolean().optional(),
|
|
54
61
|
seo: contentSeoInput.optional(),
|
|
62
|
+
publishedAt: contentDateOverride,
|
|
55
63
|
})
|
|
56
64
|
.meta({ id: "ContentUpdateBody" });
|
|
57
65
|
|
|
@@ -30,6 +30,7 @@ const ALL_GOOGLE_SUBSETS = [
|
|
|
30
30
|
"cyrillic-ext",
|
|
31
31
|
"devanagari",
|
|
32
32
|
"ethiopic",
|
|
33
|
+
"farsi",
|
|
33
34
|
"georgian",
|
|
34
35
|
"greek",
|
|
35
36
|
"greek-ext",
|
|
@@ -57,7 +58,7 @@ const ALL_GOOGLE_SUBSETS = [
|
|
|
57
58
|
];
|
|
58
59
|
|
|
59
60
|
/**
|
|
60
|
-
* Known Noto Sans script families on Google Fonts.
|
|
61
|
+
* Known Noto Sans and Sans script families on Google Fonts.
|
|
61
62
|
* Maps user-friendly script names to Google Fonts family names.
|
|
62
63
|
*/
|
|
63
64
|
const NOTO_SCRIPT_FAMILIES: Record<string, string> = {
|
|
@@ -69,6 +70,7 @@ const NOTO_SCRIPT_FAMILIES: Record<string, string> = {
|
|
|
69
70
|
"chinese-hongkong": "Noto Sans HK",
|
|
70
71
|
devanagari: "Noto Sans Devanagari",
|
|
71
72
|
ethiopic: "Noto Sans Ethiopic",
|
|
73
|
+
farsi: "Vazirmatn",
|
|
72
74
|
georgian: "Noto Sans Georgian",
|
|
73
75
|
gujarati: "Noto Sans Gujarati",
|
|
74
76
|
gurmukhi: "Noto Sans Gurmukhi",
|
|
@@ -159,7 +159,9 @@ export function emdash(config: EmDashConfig = {}): AstroIntegration {
|
|
|
159
159
|
auth: resolvedConfig.auth,
|
|
160
160
|
marketplace: resolvedConfig.marketplace,
|
|
161
161
|
siteUrl: resolvedConfig.siteUrl,
|
|
162
|
+
trustedProxyHeaders: resolvedConfig.trustedProxyHeaders,
|
|
162
163
|
maxUploadSize: resolvedConfig.maxUploadSize,
|
|
164
|
+
admin: resolvedConfig.admin,
|
|
163
165
|
};
|
|
164
166
|
|
|
165
167
|
// Determine auth mode for route injection
|
|
@@ -284,6 +284,32 @@ export interface EmDashConfig {
|
|
|
284
284
|
*/
|
|
285
285
|
siteUrl?: string;
|
|
286
286
|
|
|
287
|
+
/**
|
|
288
|
+
* Headers to trust for client IP resolution when running behind a reverse
|
|
289
|
+
* proxy. The first header in this list that is present on the request
|
|
290
|
+
* wins. Applies to rate limiting for auth endpoints and comment
|
|
291
|
+
* submission.
|
|
292
|
+
*
|
|
293
|
+
* Common values:
|
|
294
|
+
* - `x-real-ip` — nginx, Caddy, Traefik
|
|
295
|
+
* - `fly-client-ip` — Fly.io
|
|
296
|
+
* - `x-forwarded-for` — generic (first entry is used)
|
|
297
|
+
*
|
|
298
|
+
* Only set this when you **control the reverse proxy**. Untrusted
|
|
299
|
+
* clients can set any header they like; trusting headers from an open
|
|
300
|
+
* network is an IP-spoofing vulnerability that defeats rate limiting.
|
|
301
|
+
*
|
|
302
|
+
* On Cloudflare the `cf` object on the request is used automatically —
|
|
303
|
+
* you normally don't need to set this. Leave unset (or empty) to
|
|
304
|
+
* preserve the default: IP is resolved only when the request came
|
|
305
|
+
* through Cloudflare's edge.
|
|
306
|
+
*
|
|
307
|
+
* Falls back to `EMDASH_TRUSTED_PROXY_HEADERS` env var (comma-separated)
|
|
308
|
+
* when this option is not set, so operators can configure at deploy
|
|
309
|
+
* time without touching the Astro config.
|
|
310
|
+
*/
|
|
311
|
+
trustedProxyHeaders?: string[];
|
|
312
|
+
|
|
287
313
|
/**
|
|
288
314
|
* Enable playground mode for ephemeral "try EmDash" sites.
|
|
289
315
|
*
|
|
@@ -378,13 +404,41 @@ export interface EmDashConfig {
|
|
|
378
404
|
* Additional Noto Sans script families to include.
|
|
379
405
|
*
|
|
380
406
|
* Available scripts: arabic, armenian, bengali, chinese-simplified,
|
|
381
|
-
* chinese-traditional, chinese-hongkong, devanagari, ethiopic,
|
|
407
|
+
* chinese-traditional, chinese-hongkong, devanagari, ethiopic, farsi,
|
|
382
408
|
* georgian, gujarati, gurmukhi, hebrew, japanese, kannada, khmer,
|
|
383
409
|
* korean, lao, malayalam, myanmar, oriya, sinhala, tamil, telugu,
|
|
384
410
|
* thai, tibetan.
|
|
385
411
|
*/
|
|
386
412
|
scripts?: string[];
|
|
387
413
|
};
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Admin UI branding (white-labeling).
|
|
417
|
+
*
|
|
418
|
+
* Overrides the default EmDash logo and name in the admin panel.
|
|
419
|
+
* Use this to white-label the CMS for agency or enterprise deployments.
|
|
420
|
+
* These settings are separate from the public site settings (title, logo,
|
|
421
|
+
* favicon) which remain available for SEO and front-end use.
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* ```ts
|
|
425
|
+
* emdash({
|
|
426
|
+
* admin: {
|
|
427
|
+
* logo: "/images/agency-logo.webp",
|
|
428
|
+
* siteName: "AgencyX CMS",
|
|
429
|
+
* favicon: "/favicon.ico",
|
|
430
|
+
* },
|
|
431
|
+
* })
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
admin?: {
|
|
435
|
+
/** URL or path to a custom logo image for the admin UI (login page, sidebar). */
|
|
436
|
+
logo?: string;
|
|
437
|
+
/** Custom name displayed in the admin sidebar and browser tab. */
|
|
438
|
+
siteName?: string;
|
|
439
|
+
/** URL or path to a custom favicon for the admin panel. */
|
|
440
|
+
favicon?: string;
|
|
441
|
+
};
|
|
388
442
|
}
|
|
389
443
|
|
|
390
444
|
/**
|
|
@@ -18,6 +18,9 @@ import { resolveLocale, loadMessages, getLocaleDir } from "@emdash-cms/admin/loc
|
|
|
18
18
|
const resolvedLocale = resolveLocale(Astro.request);
|
|
19
19
|
const resolvedDir = getLocaleDir(resolvedLocale);
|
|
20
20
|
const messages = await loadMessages(resolvedLocale);
|
|
21
|
+
|
|
22
|
+
const adminConfig = Astro.locals.emdash?.config?.admin;
|
|
23
|
+
const pageTitle = adminConfig?.siteName ? `${adminConfig.siteName} Admin` : "EmDash Admin";
|
|
21
24
|
---
|
|
22
25
|
|
|
23
26
|
<!doctype html>
|
|
@@ -26,13 +29,17 @@ const messages = await loadMessages(resolvedLocale);
|
|
|
26
29
|
<meta charset="UTF-8" />
|
|
27
30
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
28
31
|
<Font cssVariable="--font-emdash" />
|
|
29
|
-
|
|
30
|
-
rel="icon"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
{adminConfig?.favicon ? (
|
|
33
|
+
<link rel="icon" href={adminConfig.favicon} />
|
|
34
|
+
) : (
|
|
35
|
+
<link
|
|
36
|
+
rel="icon"
|
|
37
|
+
href="data:image/svg+xml,<svg width='75' height='75' viewBox='0 0 75 75' fill='none' xmlns='http://www.w3.org/2000/svg'> <g clip-path='url(%23clip0_50_99)'> <rect x='3' y='3' width='69' height='69' rx='10.518' stroke='url(%23paint0_linear_50_99)' stroke-width='6'/> <rect x='18' y='34' width='39.3661' height='6.56101' fill='url(%23paint1_linear_50_99)'/> </g> <defs> <linearGradient id='paint0_linear_50_99' x1='-42.9996' y1='124' x2='92.4233' y2='-41.7456' gradientUnits='userSpaceOnUse'> <stop stop-color='%230F006B'/> <stop offset='0.0833333' stop-color='%23281A81'/> <stop offset='0.166667' stop-color='%235D0C83'/> <stop offset='0.25' stop-color='%23911475'/> <stop offset='0.333333' stop-color='%23CE2F55'/> <stop offset='0.416667' stop-color='%23FF6633'/> <stop offset='0.5' stop-color='%23F6821F'/> <stop offset='0.583333' stop-color='%23FBAD41'/> <stop offset='0.666667' stop-color='%23FFCD89'/> <stop offset='0.75' stop-color='%23FFE9CB'/> <stop offset='0.833333' stop-color='%23FFF7EC'/> <stop offset='0.916667' stop-color='%23FFF8EE'/> <stop offset='1' stop-color='white'/> </linearGradient> <linearGradient id='paint1_linear_50_99' x1='91.4992' y1='27.4982' x2='28.1217' y2='54.1775' gradientUnits='userSpaceOnUse'> <stop stop-color='white'/> <stop offset='0.129253' stop-color='%23FFF8EE'/> <stop offset='0.617058' stop-color='%23FBAD41'/> <stop offset='0.848019' stop-color='%23F6821F'/> <stop offset='1' stop-color='%23FF6633'/> </linearGradient> <clipPath id='clip0_50_99'> <rect width='75' height='75' fill='white'/> </clipPath> </defs> </svg>"
|
|
38
|
+
/>
|
|
39
|
+
)}
|
|
40
|
+
<title>{pageTitle}</title>
|
|
34
41
|
</head>
|
|
35
|
-
<body>
|
|
42
|
+
<body class="isolate">
|
|
36
43
|
<div id="admin-root" class="min-h-screen">
|
|
37
44
|
<div id="emdash-boot-loader">
|
|
38
45
|
<style>
|
|
@@ -82,7 +89,7 @@ const messages = await loadMessages(resolvedLocale);
|
|
|
82
89
|
</style>
|
|
83
90
|
<div class="loader-inner">
|
|
84
91
|
<div class="spinner"></div>
|
|
85
|
-
<p>Loading EmDash
|
|
92
|
+
<p>{adminConfig?.siteName ? `Loading ${adminConfig.siteName}...` : "Loading EmDash..."}</p>
|
|
86
93
|
</div>
|
|
87
94
|
</div>
|
|
88
95
|
<AdminWrapper client:only="react" locale={resolvedLocale} messages={messages} />
|
|
@@ -19,6 +19,7 @@ import { isParseError, parseBody } from "#api/parse.js";
|
|
|
19
19
|
import { magicLinkSendBody } from "#api/schemas.js";
|
|
20
20
|
import { getSiteBaseUrl } from "#api/site-url.js";
|
|
21
21
|
import { checkRateLimit, getClientIp } from "#auth/rate-limit.js";
|
|
22
|
+
import { getTrustedProxyHeaders } from "#auth/trusted-proxy.js";
|
|
22
23
|
import { OptionsRepository } from "#db/repositories/options.js";
|
|
23
24
|
|
|
24
25
|
export const POST: APIRoute = async ({ request, locals }) => {
|
|
@@ -36,7 +37,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
|
|
36
37
|
if (isParseError(body)) return body;
|
|
37
38
|
|
|
38
39
|
// Rate limit: 3 requests per 300 seconds (5 minutes) per IP
|
|
39
|
-
const ip = getClientIp(request);
|
|
40
|
+
const ip = getClientIp(request, getTrustedProxyHeaders(emdash.config));
|
|
40
41
|
const rateLimit = await checkRateLimit(emdash.db, ip, "magic-link/send", 3, 300);
|
|
41
42
|
if (!rateLimit.allowed) {
|
|
42
43
|
// Return success-shaped response to avoid revealing rate limit
|
|
@@ -20,6 +20,7 @@ import { passkeyOptionsBody } from "#api/schemas.js";
|
|
|
20
20
|
import { createChallengeStore, cleanupExpiredChallenges } from "#auth/challenge-store.js";
|
|
21
21
|
import { getPasskeyConfig } from "#auth/passkey-config.js";
|
|
22
22
|
import { checkRateLimit, getClientIp, rateLimitResponse } from "#auth/rate-limit.js";
|
|
23
|
+
import { getTrustedProxyHeaders } from "#auth/trusted-proxy.js";
|
|
23
24
|
import { OptionsRepository } from "#db/repositories/options.js";
|
|
24
25
|
|
|
25
26
|
export const POST: APIRoute = async ({ request, locals }) => {
|
|
@@ -38,7 +39,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
|
|
38
39
|
if (isParseError(body)) return body;
|
|
39
40
|
|
|
40
41
|
// Rate limit: 10 requests per 60 seconds per IP
|
|
41
|
-
const ip = getClientIp(request);
|
|
42
|
+
const ip = getClientIp(request, getTrustedProxyHeaders(emdash.config));
|
|
42
43
|
const rateLimit = await checkRateLimit(emdash.db, ip, "passkey/options", 10, 60);
|
|
43
44
|
if (!rateLimit.allowed) {
|
|
44
45
|
return rateLimitResponse(60);
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Request self-signup. Sends verification email if domain is allowed.
|
|
5
5
|
* Always returns 200 to prevent email enumeration.
|
|
6
|
+
*
|
|
7
|
+
* Rate limited: 3 requests per 5 minutes per IP. Mirrors magic-link/send.
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
10
|
import type { APIRoute } from "astro";
|
|
@@ -16,8 +18,18 @@ import { apiError, apiSuccess } from "#api/error.js";
|
|
|
16
18
|
import { isParseError, parseBody } from "#api/parse.js";
|
|
17
19
|
import { signupRequestBody } from "#api/schemas.js";
|
|
18
20
|
import { getSiteBaseUrl } from "#api/site-url.js";
|
|
21
|
+
import { checkRateLimit, getClientIp } from "#auth/rate-limit.js";
|
|
22
|
+
import { getTrustedProxyHeaders } from "#auth/trusted-proxy.js";
|
|
19
23
|
import { OptionsRepository } from "#db/repositories/options.js";
|
|
20
24
|
|
|
25
|
+
// Generic response body used for both the real success path and the
|
|
26
|
+
// rate-limited / domain-disallowed paths. Keeping them identical prevents
|
|
27
|
+
// the caller from distinguishing between them.
|
|
28
|
+
const GENERIC_SUCCESS = {
|
|
29
|
+
success: true,
|
|
30
|
+
message: "If your email domain is allowed, you'll receive a verification email.",
|
|
31
|
+
};
|
|
32
|
+
|
|
21
33
|
export const POST: APIRoute = async ({ request, locals }) => {
|
|
22
34
|
const { emdash } = locals;
|
|
23
35
|
|
|
@@ -35,9 +47,21 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
try {
|
|
50
|
+
// Parse the body first — this avoids burning a rate-limit slot on
|
|
51
|
+
// malformed input and keeps the timing of the rate-limited and
|
|
52
|
+
// real paths aligned.
|
|
38
53
|
const body = await parseBody(request, signupRequestBody);
|
|
39
54
|
if (isParseError(body)) return body;
|
|
40
55
|
|
|
56
|
+
// Rate limit: 3 requests per 300 seconds per IP. Matches magic-link/send.
|
|
57
|
+
const ip = getClientIp(request, getTrustedProxyHeaders(emdash.config));
|
|
58
|
+
const rateLimit = await checkRateLimit(emdash.db, ip, "signup/request", 3, 300);
|
|
59
|
+
if (!rateLimit.allowed) {
|
|
60
|
+
// Return success-shaped response to avoid revealing rate limiting
|
|
61
|
+
// (and by extension, the fact that the caller is probing).
|
|
62
|
+
return apiSuccess(GENERIC_SUCCESS);
|
|
63
|
+
}
|
|
64
|
+
|
|
41
65
|
const adapter = createKyselyAdapter(emdash.db);
|
|
42
66
|
|
|
43
67
|
// Get site config for signup email
|
|
@@ -60,18 +84,12 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
|
|
60
84
|
);
|
|
61
85
|
|
|
62
86
|
// Always return success to prevent email enumeration
|
|
63
|
-
return apiSuccess(
|
|
64
|
-
success: true,
|
|
65
|
-
message: "If your email domain is allowed, you'll receive a verification email.",
|
|
66
|
-
});
|
|
87
|
+
return apiSuccess(GENERIC_SUCCESS);
|
|
67
88
|
} catch (error) {
|
|
68
89
|
console.error("Signup request error:", error);
|
|
69
90
|
|
|
70
91
|
// Don't reveal internal errors - just return generic success
|
|
71
92
|
// to prevent information leakage
|
|
72
|
-
return apiSuccess(
|
|
73
|
-
success: true,
|
|
74
|
-
message: "If your email domain is allowed, you'll receive a verification email.",
|
|
75
|
-
});
|
|
93
|
+
return apiSuccess(GENERIC_SUCCESS);
|
|
76
94
|
}
|
|
77
95
|
};
|
|
@@ -139,18 +139,22 @@ export const POST: APIRoute = async ({ params, request, locals }) => {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
// Anti-spam: Rate limiting
|
|
142
|
-
const meta = extractRequestMeta(request);
|
|
142
|
+
const meta = extractRequestMeta(request, emdash.config);
|
|
143
143
|
const ipSalt =
|
|
144
144
|
import.meta.env.EMDASH_AUTH_SECRET || import.meta.env.AUTH_SECRET || "emdash-ip-salt";
|
|
145
145
|
let ipHash: string;
|
|
146
146
|
if (meta.ip) {
|
|
147
147
|
ipHash = await hashIp(meta.ip, ipSalt);
|
|
148
|
-
} else if (meta.userAgent) {
|
|
149
|
-
// Fallback: hash user-agent as a rough identifier when IP is unavailable
|
|
150
|
-
ipHash = await hashIp(`ua:${meta.userAgent}`, ipSalt);
|
|
151
148
|
} else {
|
|
152
|
-
//
|
|
153
|
-
//
|
|
149
|
+
// No trusted IP — fail closed by bucketing all unidentifiable
|
|
150
|
+
// requests together. A larger limit reflects the shared bucket.
|
|
151
|
+
//
|
|
152
|
+
// Self-hosted operators behind a reverse proxy should set
|
|
153
|
+
// `trustedProxyHeaders` in the EmDash config (or the
|
|
154
|
+
// EMDASH_TRUSTED_PROXY_HEADERS env var) so this path isn't hit
|
|
155
|
+
// for legitimate traffic. UA-hashing was previously used here
|
|
156
|
+
// but was trivially rotatable — the shared bucket is stricter
|
|
157
|
+
// and forces operators toward a real fix.
|
|
154
158
|
ipHash = "unknown";
|
|
155
159
|
}
|
|
156
160
|
const unknownBucketLimit = ipHash === "unknown" ? 20 : undefined;
|