# Implementation COMMS-1125 - Build the service worker as its own TypeScript package

Project: Stream Communicator
Status: needs review
URL: https://community.openproject.org/work_packages/COMMS-1125

## OPEN POINTS

_No work packages_

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Designer |  |
| Developers | Kabiru Mwenja |

## Technical details

| Attribute | Value |
| --- | --- |
| Target versions | 18.1.0 |
| Module |  |
| Requires doc change | No |

## Belongs to

_No work packages_

## Previous chunks

_No work packages_

## Next chunks

_No work packages_

## Estimates

| Attribute | Value |
| --- | --- |
| Work |  |

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| % Complete |  |
| Category |  |
| Sprint |  |
| Backlog bucket |  |
| Priority | Medium |
| List |  |
| Pull preview |  |
| Labels |  |

## Description

The service worker behind offline support, the app badge and browser notifications is plain JavaScript inside an ERB view (`app/views/pwa/service-worker.js.erb`, about 600 lines). It is neither type checked nor linted, and its decision rules, such as when a notification is shown, replaced or closed and what a click opens, cannot be unit tested.

**Scope**

  - Move the worker logic into TypeScript modules in a package of their own, `packages/service-worker/`, with its own `package.json`, TypeScript, lint and vitest setup, so that `frontend/` stays the client side app only.

  - Build the package with esbuild into a hashed static asset. The ERB view keeps the stable `/service-worker` URL, passes the server configuration to the worker and imports the bundle. With the `progressive_web_app` feature flag off it serves the kill switch as before and imports nothing.

  - Add the package to the development setup (`bin/setup_dev`, `bin/compose setup`, `Procfile.dev`), the Docker images, the packaged installation and CI (own test workflow, ESLint, npm audit, Dependabot).

No change in behaviour for users.

**QA notes**

With the feature flag on: the offline page appears without a connection, the app badge shows the unread count, a browser notification arrives and a click on it opens the work package. With the flag off: the kill switch is served.

**Links**

  - Pull request: <https://github.com/opf/openproject/pull/26626>

  - Follows <mention class="mention" data-id="COMMS-1078" data-type="work_package" data-text="#COMMS-1078">#COMMS-1078</mention>
