Skip to content

Add --entrypoint flag for remote Edge Apps + bundle screenly_inject.js#284

Merged
sergey-borovkov merged 6 commits intomasterfrom
feat/remote-entrypoint-and-js-injection
May 5, 2026
Merged

Add --entrypoint flag for remote Edge Apps + bundle screenly_inject.js#284
sergey-borovkov merged 6 commits intomasterfrom
feat/remote-entrypoint-and-js-injection

Conversation

@sergey-borovkov
Copy link
Copy Markdown
Contributor

@sergey-borovkov sergey-borovkov commented May 4, 2026

Summary

  • Adds screenly edge-app create --entrypoint <URL> for remote-global Edge Apps. Writes entrypoint.type: remote-global + uri into screenly.yml, drops a starter screenly_inject.js next to the manifest, and skips the index.html stub.
  • screenly_inject.js is treated as a normal bundled asset file: it ships with the revision and the player reads it from the file tree.
  • deploy materializes a one-shot virtual index.html placeholder if the user has none, so the version always has at least one signed asset to publish. First-deploy short-circuit added so the no-changes guard doesn't block the initial publish.
  • screenly_inject.js template ships with helpers (setValue, setReactValue, setCookie, onPath) and commented examples drawn from the Playground javascript-injectors patterns (form-fill login, cookie-based SSO, fetch-override). Includes a comment warning that DOMContentLoaded has already fired by the time the inject runs.
  • Adds GET URL/status logging in commands::get so failures inside deploy can be diagnosed without bisection.
  • Docs: docs/EdgeApps.md describes the new flow, screenly_settings, and how to wire credentials/secrets through.

Test plan

  • cargo build --release, cargo test — all 200+ tests pass (one pre-existing flaky env-races test in utils.rs is unaffected by this change).
  • Live e2e: create --entrypoint https://httpbin.org/headers → set settings/secret → instance createdeploy → playlist → append. Player picks up the bundled screenly_inject.js, IIFE-wraps it with screenly_settings, executes — green banner with the greeting and api_token visible above httpbin's JSON output.
  • Reviewer: try create without --entrypoint and confirm the existing flow (writes index.html, no screenly_inject.js) is unchanged.

Make remote-entrypoint Edge Apps a first-class create option and lay the
groundwork for a per-deploy JS injection workflow.

- `screenly edge-app create --name X --entrypoint <URL>` writes
  `screenly.yml` with `entrypoint.type: remote-global` + URI, drops a
  starter `screenly_inject.js`, and adds it to `.ignore`. No `index.html`
  on disk for remote apps.
- `deploy` materializes a placeholder `index.html` for the duration of
  the upload (the backend rejects publishing versions with no signed
  assets) and removes it after.
- Adds `is_first_deploy` short-circuit so the first deploy of a fresh
  app isn't blocked by the no-changes check.
- New `sync_js_injection` step at the end of `deploy`: looks up the
  installation's stable asset and PATCHes `js_injection` from the
  local file. Wait/retry until the asset is provisioned.
- Adds request URL/status logging to `commands::get` for easier
  diagnosis.
- Docs (`docs/EdgeApps.md`) describe the new flow and the
  `screenly_settings` runtime hook for inject scripts.

WIP: the final `js_injection` PATCH currently 400s on the live API
({"code":"22P02","error":"Invalid input value: nil"}). TODO marker in
`set_asset_js_injection` — switch to the new revision-scoped
js_injection endpoint when the backend ships it.
Lift the four recurring patterns from the Playground javascript-injectors
examples (setValue, setReactValue for framework-controlled inputs,
setCookie for SSO, onPath for path-guarded execution) into the bundled
screenly_inject.js. Includes commented examples for form-fill login,
cookie-based SSO, and a fetch-override Bearer-token attach so users
porting from Playground get a familiar starting shape.
The player will read screenly_inject.js straight from the edge app's
file tree (octo-avenger change in a separate commit), so the CLI no
longer needs to talk to the assets endpoint to set js_injection. This
removes:

- `sync_js_injection`, `wait_for_installation_stable_asset` and their
  call site at the end of `deploy`
- `set_asset_js_injection` and `get_installation_stable_asset` on the
  Api struct
- `screenly_inject.js` from the always-excluded list (so it's actually
  uploaded as a normal asset file)
- the `.ignore` write in `create --entrypoint` (file is bundled now)

Kept: the `--entrypoint` flag, the `screenly_inject.js` template write
on `create`, the `VirtualIndexHtml` placeholder for the case where the
user removes the inject file (the version still needs at least one
signed asset to publish), the URL+status logging in `commands::get`.

Docs updated to describe the file-based flow.
The player runs the inject script after the page is fully loaded, so
wrapping code in `document.addEventListener('DOMContentLoaded', ...)`
silently fails — the listener gets registered after the event has
already fired. Added a comment in the bundled template warning about
this so users don't reach for the familiar pattern by reflex.
…text

- `cargo fmt` (extra blank lines).
- `--entrypoint` help string was still describing the old behavior of
  adding the inject file to `.ignore`; updated to describe the
  bundle-with-revision flow.
- Regenerated `docs/CommandLineHelp.md` to match.
@sergey-borovkov sergey-borovkov merged commit 7191b08 into master May 5, 2026
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants