Skip to content

Bundle shared helpers into injected scripts to avoid duplicated copies #7

Done

Description

@melvincarvalho

Follow-up surfaced during #6 review.

Problem

src/auth-header-utils.js is the canonical home for the Authorization header helpers (hasAuthorizationHeader, fetchCallHasAuthorization, setAuthorizationOnOptions, normalizeFetchCall) and is unit-tested via Node ESM.

But src/injected.js (content script, isolated world) and src/nip98-interceptor.js (injected into page context) both duplicate the bodies inline because they run as classic scripts and can't import. Injected.js and nip98-interceptor.js also run in different global scopes, so a window.__podkeyAuthHeaderUtils cache can't be shared between them.

This means future changes to the helper logic have to be made in three places and kept in sync manually.

Proposed fix

Extend scripts/bundle.js to bundle src/injected.js and src/nip98-interceptor.js via esbuild (like background.js already is), pulling auth-header-utils.js in as an imported module. Output to .bundle.js files and point the manifest / the dynamic <script> injection at the bundled URLs.

Scope note

Not fixing in #6 because that PR is scoped to the auth-overwrite bug and this is a build-system change with its own test surface (manifest updates, script-URL changes, CI).

Activity

  1. jjohare commented on Nov 28, 2026

    @jjohare
    Collaborator

    Still valid, with a narrower scope than when this was filed (checked at bd39ce8):

    • src/injected.js no longer carries copies of the helpers. Only src/nip98-interceptor.js does: four functions on main, six with Retry a signed GET/HEAD unsigned when it fails before a response (#33) #34. None has drifted from src/auth-header-utils.js (compared function by function, ignoring comments and whitespace).
    • The sharper reason to do it: src/auth-header-utils.js is imported by no runtime code, so test/auth-header-utils.test.js tests a module that never ships. The copies that actually run are covered only through the vm-sandbox tests.

    Smallest change:

    1. scripts/bundle.js: one more esbuild entry, src/nip98-interceptor.js to src/nip98-interceptor.bundle.js, format: 'iife'.
    2. Replace the duplicated bodies in the interceptor with an import from ./auth-header-utils.js, keeping the __podkey_nip98_intercepted guard.
    3. Point web_accessible_resources in manifest.json and the getURL call at src/injected.js:13 at the bundle; add it to .gitignore.
    4. test/body-hash.test.js:26 (and test/unsigned-retry.test.js from Retry a signed GET/HEAD unsigned when it fails before a response (#33) #34) read the raw file with readFileSync and would trip on import: build in-test with esbuild write: false, or add pretest: npm run bundle.

    injected.js itself does not need bundling. Best done straight after #34 lands, since that PR adds two more copies.

  2. jjohare commented on Nov 28, 2026

    @jjohare
    Collaborator

    Done in 0.0.13 (a2265b7). src/nip98-interceptor.js is bundled with esbuild and imports src/auth-header-utils.js, so there is one copy and the tests run the shipped code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions