1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 01:03:35 +00:00
Files
browser/libs/common/src/platform/misc/support-status.ts
Justin Baur b07d6c29a4 Add Web Push Support (#11346)
* WIP: PoC with lots of terrible code with web push

* fix service worker building

* Work on WebPush Tailored to Browser

* Clean Up Web And MV2

* Fix Merge Conflicts

* Prettier

* Use Unsupported for MV2

* Add Doc Comments

* Remove Permission Button

* Fix Type Test

* Write Time In More Readable Format

* Add SignalR Logger

* `sheduleReconnect` -> `scheduleReconnect`

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>

* Capture Support Context In Connector

* Remove Unneeded CSP Change

* Fix Build

* Simplify `getOrCreateSubscription`

* Add More Docs to Matrix

* Update libs/common/src/platform/notifications/internal/worker-webpush-connection.service.ts

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>

* Move API Service Into Notifications Folder

* Allow Connection When Account Is Locked

* Add Comments to NotificationsService

* Only Change Support Status If Public Key Changes

* Move Service Choice Out To Method

* Use Named Constant For Disabled Notification Url

* Add Test & Cleanup

* Flatten

* Move Tests into `beforeEach` & `afterEach`

* Add Tests

* Test `distinctUntilChanged`'s Operators More

* Make Helper And Cleanup Chain

* Add Back Cast

* Add extra safety to incoming config check

* Put data through response object

* Apply TS Strict Rules

* Finish PushTechnology comment

* Use `instanceof` check

* Do Safer Worker Based Registration for MV3

* Remove TODO

* Switch to SignalR on any WebPush Error

* Fix Manifest Permissions

* Add Back `webNavigation`

* Sorry, Remove `webNavigation`

* Fixed merge conflicts.

---------

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
Co-authored-by: Todd Martin <tmartin@bitwarden.com>
Co-authored-by: Todd Martin <106564991+trmartin4@users.noreply.github.com>
2025-01-29 08:49:01 -05:00

49 lines
2.0 KiB
TypeScript

import { ObservableInput, OperatorFunction, switchMap } from "rxjs";
/**
* Indicates that the given set of actions is not supported and there is
* not anything the user can do to make it supported. The reason property
* should contain a documented and machine readable string so more in
* depth details can be shown to the user.
*/
export type NotSupported = { type: "not-supported"; reason: string };
/**
* Indicates that the given set of actions does not currently work but
* could be supported if configuration, either inside Bitwarden or outside,
* is done. The reason property should contain a documented and
* machine readable string so further instruction can be supplied to the caller.
*/
export type NeedsConfiguration = { type: "needs-configuration"; reason: string };
/**
* Indicates that the actions in the service property are supported.
*/
export type Supported<T> = { type: "supported"; service: T };
/**
* A type encapsulating the status of support for a service.
*/
export type SupportStatus<T> = Supported<T> | NeedsConfiguration | NotSupported;
/**
* Projects each source value to one of the given projects defined in `selectors`.
*
* @param selectors.supported The function to run when the given item reports that it is supported
* @param selectors.notSupported The function to run when the given item reports that it is either not-supported
* or needs-configuration.
* @returns A function that returns an Observable that emits the result of one of the given projection functions.
*/
export function supportSwitch<TService, TSupported, TNotSupported>(selectors: {
supported: (service: TService, index: number) => ObservableInput<TSupported>;
notSupported: (reason: string, index: number) => ObservableInput<TNotSupported>;
}): OperatorFunction<SupportStatus<TService>, TSupported | TNotSupported> {
return switchMap((supportStatus, index) => {
if (supportStatus.type === "supported") {
return selectors.supported(supportStatus.service, index);
}
return selectors.notSupported(supportStatus.reason, index);
});
}