{"_id":"emdash-header-footer-code","_rev":"3-c0fb566702afe93694fb624836103495","name":"emdash-header-footer-code","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"emdash-header-footer-code","version":"0.1.0","keywords":["emdash","emdash-plugin","cms","header","footer","snippets","analytics"],"license":"MIT","_id":"emdash-header-footer-code@0.1.0","maintainers":[{"name":"jithins","email":"jithinliveshere@gmail.com"}],"homepage":"https://github.com/jithinsk/emdash-header-footer-code#readme","bugs":{"url":"https://github.com/jithinsk/emdash-header-footer-code/issues"},"dist":{"shasum":"462564a067869008a35bf7dd82e44e3ac547df54","tarball":"https://registry.npmjs.org/emdash-header-footer-code/-/emdash-header-footer-code-0.1.0.tgz","fileCount":28,"integrity":"sha512-NYIRBS4ow95zOp1TEpvcaGuolLhDFWd3y18ZdjnjQdxItmuNpyIU8dp/hLzlZ+DPVe9Fv5Ftx8yMNE66IA6tZA==","signatures":[{"sig":"MEUCIEDQmqfTHFQG4n8xmTrUjLbazf6nZ2LpaNMe/b06Myq3AiEAykQf2HJ9w2KmRevKdsBnMy2aOXkcyPrWu7w5VIz9Qvc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":110582},"pnpm":{"onlyBuiltDependencies":["better-sqlite3","esbuild"]},"type":"module","exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./admin":"./src/admin/index.tsx","./plugin":{"types":"./dist/plugin.d.mts","default":"./dist/plugin.mjs"}},"gitHead":"0ffa6920dfae4c81c1be84e2efcdf52af1ce1e9d","scripts":{"e2e":"pnpm build && playwright test -c e2e/playwright.config.ts","test":"vitest run","build":"tsdown","smoke":"node scripts/smoke-pack.mjs","typecheck":"tsc --noEmit"},"_npmUser":{"name":"jithins","email":"jithinliveshere@gmail.com"},"repository":{"url":"git+https://github.com/jithinsk/emdash-header-footer-code.git","type":"git"},"_npmVersion":"11.8.0","description":"Add custom code snippets (analytics, verification tags, chat widgets, CSS/JS) to the head or body of EmDash pages — no theme edits.","directories":{},"_nodeVersion":"25.6.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.33.0","devDependencies":{"react":"19.2.4","emdash":"1.0.1","tsdown":"0.20.3","vitest":"4.1.10","react-dom":"19.2.4","typescript":"^6.0.3","@types/react":"19.2.14","@astrojs/react":"^6.0.5","better-sqlite3":"^12.4.1","@cloudflare/kumo":"2.6.0","@playwright/test":"^1.56.0","@axe-core/playwright":"^4.13.0","@types/better-sqlite3":"^7.6.13"},"peerDependencies":{"react":"^18.0.0 || ^19.0.0","emdash":"^1.0.1","@cloudflare/kumo":"^2.6.0"},"_npmOperationalInternal":{"tmp":"tmp/emdash-header-footer-code_0.1.0_1791200795666_0.39251717737338976","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"emdash-header-footer-code","version":"0.1.1","keywords":["emdash","emdash-plugin","cms","header","footer","snippets","analytics"],"license":"MIT","_id":"emdash-header-footer-code@0.1.1","maintainers":[{"name":"jithins","email":"jithinliveshere@gmail.com"}],"homepage":"https://github.com/jithinsk/emdash-header-footer-code#readme","bugs":{"url":"https://github.com/jithinsk/emdash-header-footer-code/issues"},"dist":{"shasum":"95a644ee41875cdcd330acf86328be46dcb3914c","tarball":"https://registry.npmjs.org/emdash-header-footer-code/-/emdash-header-footer-code-0.1.1.tgz","fileCount":28,"integrity":"sha512-9tH5OBo2S78z+CR8eB/6Mdqzp7jfK9pqMe/VlqHtJq5ZVReAOXQLUVrF+RqVNMU8HNN3w+JaA4VbQZUhFgAY5Q==","signatures":[{"sig":"MEUCIQCvPUvWNx0B6kGoyQJc7VSRv4W8UDOvuhM6BqWfzaPFXwIgNI3XzbhUwzEnAHwPZX8AazdfVHZG6kvVHvTIOJSHosc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIASvYX45WPvw3Nd1IoEZQLC9IJTYrjX01qIzDvqJCRRNAiEA/XtaH7jojQNiKDmGhR8bt/jKSIlsaE5g2iYo/8bvj2w=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/emdash-header-footer-code@0.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":110582},"pnpm":{"onlyBuiltDependencies":["better-sqlite3","esbuild"]},"type":"module","exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./admin":"./src/admin/index.tsx","./plugin":{"types":"./dist/plugin.d.mts","default":"./dist/plugin.mjs"}},"gitHead":"5bc691e3c61ad32aed83c55eaaebccda4a66b40b","scripts":{"e2e":"pnpm build && playwright test -c e2e/playwright.config.ts","test":"vitest run","build":"tsdown","smoke":"node scripts/smoke-pack.mjs","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"9d8275c8-49b5-48c4-93be-c5fb0183692f"}},"repository":{"url":"git+https://github.com/jithinsk/emdash-header-footer-code.git","type":"git"},"_npmVersion":"12.2.0","description":"Add custom code snippets (analytics, verification tags, chat widgets, CSS/JS) to the head or body of EmDash pages — no theme edits.","directories":{},"_nodeVersion":"24.21.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.33.0","devDependencies":{"react":"19.2.4","emdash":"1.0.1","tsdown":"0.20.3","vitest":"4.1.10","react-dom":"19.2.4","typescript":"^6.0.3","@types/react":"19.2.14","@astrojs/react":"^6.0.5","better-sqlite3":"^12.4.1","@cloudflare/kumo":"2.6.0","@playwright/test":"^1.56.0","@axe-core/playwright":"^4.13.0","@types/better-sqlite3":"^7.6.13"},"peerDependencies":{"react":"^18.0.0 || ^19.0.0","emdash":"^1.0.1","@cloudflare/kumo":"^2.6.0"},"_npmOperationalInternal":{"tmp":"tmp/emdash-header-footer-code_0.1.1_1791202957769_0.8184222584162872","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"_id":"emdash-header-footer-code@0.1.2","bugs":{"url":"https://github.com/jithinsk/emdash-header-footer-code/issues"},"dist":{"shasum":"0bb8063b68c60e5e57d24d45d52fe2b6816f9c02","tarball":"https://registry.npmjs.org/emdash-header-footer-code/-/emdash-header-footer-code-0.1.2.tgz","fileCount":28,"integrity":"sha512-gy06GzPa/6G9C6JivSKK0J0b9sT4XyKiu1LB/dA9M9yrLgDbTQC4FYew+fysCUgf5pyH0MOkcUd8+rt2EFEuxw==","signatures":[{"sig":"MEUCIQCDFiKsqhgd+EGzEh0D+kij+OmhB3gVfVixtgshel9RagIgSDQOm8jRnaBV0RWuTWmldlsWrzRbjXVWZ6UfO0YLovk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIAEU7a6QolHFBLNTDaZ+slFA6ShHyGRFJfBUiMRa06BQAiAHTFTJP9ovudT6NDHFhob64bv7yx30LdvAGJybBmTVBw=="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/emdash-header-footer-code@0.1.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":111349},"name":"emdash-header-footer-code","pnpm":{"onlyBuiltDependencies":["better-sqlite3","esbuild"]},"type":"module","exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./admin":"./src/admin/index.tsx","./plugin":{"types":"./dist/plugin.d.mts","default":"./dist/plugin.mjs"}},"gitHead":"4efc88f86067d2312b6bffd06bdf4a31776d6604","license":"MIT","scripts":{"e2e":"pnpm build && playwright test -c e2e/playwright.config.ts","test":"vitest run","build":"tsdown","smoke":"node scripts/smoke-pack.mjs","typecheck":"tsc --noEmit"},"version":"0.1.2","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"9d8275c8-49b5-48c4-93be-c5fb0183692f"}},"homepage":"https://emdash-code.jithins.dev","keywords":["emdash","emdash-plugin","cms","header","footer","snippets","analytics"],"repository":{"url":"git+https://github.com/jithinsk/emdash-header-footer-code.git","type":"git"},"_npmVersion":"12.2.0","description":"Add custom code snippets (analytics, verification tags, chat widgets, CSS/JS) to the head or body of EmDash pages — no theme edits.","directories":{},"maintainers":[{"name":"jithins","email":"jithinliveshere@gmail.com"}],"_nodeVersion":"24.21.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.33.0","devDependencies":{"react":"19.2.4","emdash":"1.0.1","tsdown":"0.20.3","vitest":"4.1.10","react-dom":"19.2.4","typescript":"^6.0.3","@types/react":"19.2.14","@astrojs/react":"^6.0.5","better-sqlite3":"^12.4.1","@cloudflare/kumo":"2.6.0","@playwright/test":"^1.56.0","@axe-core/playwright":"^4.13.0","@types/better-sqlite3":"^7.6.13"},"peerDependencies":{"react":"^18.0.0 || ^19.0.0","emdash":"^1.0.1","@cloudflare/kumo":"^2.6.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/emdash-header-footer-code_0.1.2_1791509371234_0.6381569525050586"}}},"time":{"created":"2026-10-05T11:46:35.506Z","modified":"2026-10-09T01:29:31.696Z","0.1.0":"2026-10-05T11:46:35.793Z","0.1.1":"2026-10-05T12:22:37.864Z","0.1.2":"2026-10-09T01:29:31.306Z"},"bugs":{"url":"https://github.com/jithinsk/emdash-header-footer-code/issues"},"license":"MIT","homepage":"https://emdash-code.jithins.dev","keywords":["emdash","emdash-plugin","cms","header","footer","snippets","analytics"],"repository":{"url":"git+https://github.com/jithinsk/emdash-header-footer-code.git","type":"git"},"description":"Add custom code snippets (analytics, verification tags, chat widgets, CSS/JS) to the head or body of EmDash pages — no theme edits.","maintainers":[{"name":"jithins","email":"jithinliveshere@gmail.com"}],"readme":"# emdash-header-footer-code\n\nAdd custom code snippets (analytics, verification tags, chat widgets, CSS/JS) to the head or body of your EmDash pages, with no theme edits.\n\n![native plugin — runs as first-party code](https://img.shields.io/badge/native%20plugin-runs%20as%20first--party%20code-orange)\n\n**Documentation: [emdash-code.jithins.dev](https://emdash-code.jithins.dev)**, with guides, recipes, troubleshooting and the full reference.\n\n![Snippet list: placement, priority, enabled toggle and where each snippet runs](https://raw.githubusercontent.com/jithinsk/emdash-header-footer-code/main/docs/screenshots/list.webp)\n\n<details>\n<summary>More screenshots: edit view and change log</summary>\n\n![Edit view: code editor with line numbers, settings, and path, page-kind and locale targeting](https://raw.githubusercontent.com/jithinsk/emdash-header-footer-code/main/docs/screenshots/edit.webp)\n\n![Change log: who created, edited, enabled, disabled or deleted each snippet](https://raw.githubusercontent.com/jithinsk/emdash-header-footer-code/main/docs/screenshots/changelog.webp)\n\n</details>\n\n## Security notice\n\nThis plugin runs as first-party code with no permission sandbox. Snippet code is intentionally unsanitised HTML and is output exactly as written. Only users with the `plugins:manage` permission (Admins) can create, edit, enable or delete snippets. Never paste code you don't trust.\n\n## Install\n\n```sh\nnpm install emdash-header-footer-code\n```\n\n```js\n// astro.config.mjs\nimport { headerFooterCode } from \"emdash-header-footer-code\";\nexport default defineConfig({\n  integrations: [emdash({ /* … */ plugins: [headerFooterCode()] })],\n});\n```\n\nThen redeploy. Native plugins cannot be installed from the EmDash plugin registry.\n\nRequires `emdash` ^1.0.1. Manage snippets at `/_emdash/admin/plugins/header-footer-code/snippets` (\"Header & Footer Code\" in the admin sidebar).\n\n## Capability\n\nThe plugin declares `hooks.page-fragments:register`. This is the only way to add scripts or HTML to public pages. Without it, EmDash would not register the hook. No other capability is requested.\n\n## Theme requirements\n\nYour layout must render `<EmDashHead />`, `<EmDashBodyStart />` and `<EmDashBodyEnd />`. If a component is missing, that placement silently renders nothing. The EmDash starter already includes all three.\n\n```astro\n---\n// src/layouts/Base.astro\nimport { EmDashHead, EmDashBodyStart, EmDashBodyEnd } from \"emdash/ui\";\nimport { createPublicPageContext } from \"emdash/page\";\nconst pageCtx = createPublicPageContext({\n  Astro,\n  kind: \"custom\", // \"content\" on content pages\n  pageType: \"website\",\n  title: \"My site\",\n});\n---\n<!doctype html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"UTF-8\" />\n    <title>My site</title>\n    <EmDashHead page={pageCtx} />\n  </head>\n  <body>\n    <EmDashBodyStart page={pageCtx} />\n    <slot />\n    <EmDashBodyEnd page={pageCtx} />\n  </body>\n</html>\n```\n\nThe EmDash starter's `src/layouts/Base.astro` is the reference for building `pageCtx`.\n\n## Using it\n\nEach snippet has these fields:\n\n| Field | Default | Notes |\n|---|---|---|\n| `name` | required | Shown in the admin list only. Up to 200 characters. |\n| `code` | required | Raw HTML (`<script>`, `<style>`, `<noscript>`, `<meta>`, …), output exactly as written. |\n| `placement` | `\"head\"` | `\"head\"`, `\"body:start\"` or `\"body:end\"`. |\n| `enabled` | `true` | Disabled snippets are never output. |\n| `priority` | `10` | Integer. Lower runs first within the same placement. |\n| `includePaths` | `[]` | Empty means every page. |\n| `excludePaths` | `[]` | Empty means none. Exclude wins over include. |\n| `pageKind` | `\"all\"` | `\"all\"`, `\"content\"` or `\"custom\"`. |\n| `locales` | `[]` | Empty means all locales. A page with no locale never matches a non-empty list. |\n| `meta` | `{}` | Reserved for extensions. See [Data model notes](#data-model-notes). |\n\n**Path matching**\n\n- A pattern must start with `/`, contain no whitespace, and may use `*` only as its final character. There is no regex.\n- A pattern is either an exact path or a prefix ending in `*`.\n- A trailing `/` is ignored on both the pattern and the path (except for `/` itself). Matching is case-sensitive.\n- Matching uses decoded paths, so non-ASCII patterns work as typed: `/blog/café/*` matches a request for `/blog/caf%C3%A9/x`. A path with a malformed percent-escape is matched as-is.\n- `/blog/*` matches `/blog/x` and `/blog/a/b`, but not `/blog`. List `/blog` separately to include it.\n- If any exclude pattern matches, the snippet is not output, even if an include pattern also matches.\n- Nothing is ever output on `/_emdash/` admin paths.\n\n**Placements and priority.** Snippets are output in `priority` order (ascending), then by creation time, then by id. Each snippet goes to the head, the start of the body, or the end of the body, according to its placement.\n\n## Kill switch\n\nThe \"Output enabled\" toggle at the top of the admin page disables all snippet output on every page without deleting or changing any snippet. Turning it off asks for confirmation. Turn it back on to resume.\n\n## Permissions\n\n| Role | Permission | Can do |\n|---|---|---|\n| Admin | `plugins:manage` | Everything: create, edit, enable, duplicate, delete, kill switch, view code. |\n| Editor | `plugins:read` | Open the page and see the snippet list, read-only. The list does not include code, and the create, edit and kill-switch controls are hidden. |\n\nWrite requests from an Editor are rejected with HTTP 403. This is covered by the end-to-end tests.\n\n## Change log\n\nEvery create, update, enable, disable, duplicate and delete, and every kill-switch change, is recorded with the time, the user and the snippet name. The admin page shows the latest 100 entries. v0.1 does not prune old entries.\n\n## Limits\n\n- 64 KB of code per snippet (UTF-8 bytes)\n- 512 KB of code in total\n- 100 snippets\n\nSaving past a limit, or with an invalid path pattern, shows a validation error in the form and nothing is saved.\n\n## Caching and freshness\n\n- Changes reach every server instance within about 1 second.\n- Pages served from an edge HTML cache (for example Cloudflare Workers Cache) update only after a purge. v0.1 does not purge automatically. For example:\n\n  ```ts\n  import { cache } from \"cloudflare:workers\";\n  await cache.purge({ purgeEverything: true });\n  ```\n\n- Ordering relative to other plugins' page fragments is not guaranteed.\n\n## Extending with transforms\n\nA transform runs on each matched snippet before it is output:\n\n```ts\ntype Transform = (ctx: TransformContext) => TransformResult;\n\ninterface TransformContext {\n  snippet: Readonly<Snippet>;\n  html: string; // the snippet code, or the previous transform's output\n  page: Readonly<PageInfo>; // EmDash's public page context\n}\n\ntype TransformResult =\n  | string\n  | null\n  | { html: string | null; fragments?: PageFragmentContribution[] };\n```\n\nTransforms are synchronous and run in order.\n\n- Return a **string** to replace the snippet HTML.\n- Return **`null`** to drop the snippet.\n- Return **`{ html, fragments }`** to replace the HTML (or drop it with `null`) and also contribute extra page fragments. Extra fragments are de-duplicated by `key`; the first wins.\n- If a transform throws, the error is logged and that snippet is skipped. Other snippets are unaffected.\n- Extra fragments are kept once returned: if an earlier transform returns fragments and a later transform drops the snippet (returns `null`) or throws, the snippet's own HTML is not output but those fragments still are.\n\nThe types `Transform`, `TransformContext`, `TransformResult`, `Snippet` and `HeaderFooterCodeRuntimeOptions` are exported from `emdash-header-footer-code/plugin` (the first four also from the package root).\n\nDescriptor options are JSON-serialised, so functions cannot be passed to `headerFooterCode()` directly. Instead, an extending package ships a wrapper entrypoint that calls `createPlugin` with its transforms:\n\n```ts\n// your-package/plugin.ts\nimport {\n  createPlugin as base,\n  type HeaderFooterCodeRuntimeOptions,\n  type Transform,\n} from \"emdash-header-footer-code/plugin\";\n\n/** Tag each <script> with the snippet's consent category so a consent manager can gate it. */\nconst tagConsentCategory: Transform = ({ snippet, html }) => {\n  const category = snippet.meta.consentCategory;\n  if (typeof category !== \"string\" || !/^[a-z-]+$/.test(category)) return html;\n  return html.replace(/<script\\b/gi, `<script data-category=\"${category}\"`);\n};\n\nexport function createPlugin(options: HeaderFooterCodeRuntimeOptions = {}) {\n  return base({ ...options, transforms: [...(options.transforms ?? []), tagConsentCategory] });\n}\n```\n\nA snippet saved with `meta: { consentCategory: \"analytics\" }` and code `<script src=\"https://example.com/a.js\"></script>` is then output as `<script data-category=\"analytics\" src=\"https://example.com/a.js\"></script>`.\n\nThen point the descriptor at it with a package specifier (not a relative path):\n\n```js\nplugins: [headerFooterCode({ entrypoint: \"your-package/plugin\" })]\n```\n\n`entrypoint` is a descriptor field and is not passed on as a plugin option.\n\n## Data model notes\n\n- `meta` is reserved for extensions (for example `meta.consentCategory`). It is stored and returned untouched, and unknown keys are preserved.\n- Every snippet has a `schemaVersion` (currently `1`). A record with a newer `schemaVersion` than the installed code understands is passed through unchanged and never rewritten.\n\n## Versioning\n\nThis package follows semver. Adding a capability is a major version, because native plugins have no consent prompt on upgrade.\n\n## Development\n\n```sh\npnpm install\npnpm test        # unit tests\npnpm typecheck\npnpm exec playwright install chromium   # once\npnpm e2e         # builds, then runs Playwright against an EmDash 1.0.1 starter in e2e/fixture\npnpm smoke       # packs the tarball, installs it into a copy of the fixture, astro build + production server\n```\n\nThe code is type-checked with TypeScript in strict mode (`pnpm typecheck`, run in CI) but is not yet linted.\n\n## Licence\n\nMIT\n","readmeFilename":"README.md"}