@softistx/alxia-react-router 0.88.0 → 0.89.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/oidc/callback.d.ts +4 -0
- package/dist/oidc/callback.d.ts.map +1 -0
- package/dist/oidc/client.d.ts +57 -0
- package/dist/oidc/client.d.ts.map +1 -0
- package/dist/oidc/context.d.ts +42 -0
- package/dist/oidc/context.d.ts.map +1 -0
- package/dist/oidc/dpop-fetch.d.ts +2 -1
- package/dist/oidc/dpop-fetch.d.ts.map +1 -1
- package/dist/oidc/env.d.ts +1 -1
- package/dist/oidc/env.d.ts.map +1 -1
- package/dist/oidc/index.d.ts +2 -1
- package/dist/oidc/index.d.ts.map +1 -1
- package/dist/oidc/index.js +550 -486
- package/dist/oidc/index.js.map +18 -9
- package/dist/oidc/logout.d.ts +4 -0
- package/dist/oidc/logout.d.ts.map +1 -0
- package/dist/oidc/refresh.d.ts +10 -0
- package/dist/oidc/refresh.d.ts.map +1 -0
- package/dist/oidc/routes.d.ts +1 -1
- package/dist/oidc/routes.d.ts.map +1 -1
- package/dist/oidc/session.d.ts +7 -0
- package/dist/oidc/session.d.ts.map +1 -0
- package/dist/oidc/signin.d.ts +4 -0
- package/dist/oidc/signin.d.ts.map +1 -0
- package/dist/oidc/stored.d.ts +21 -0
- package/dist/oidc/stored.d.ts.map +1 -0
- package/dist/oidc/tokens.d.ts +13 -0
- package/dist/oidc/tokens.d.ts.map +1 -0
- package/dist/oidc/{oidc.d.ts → types.d.ts} +4 -59
- package/dist/oidc/{oidc.d.ts.map → types.d.ts.map} +1 -1
- package/dist/oidc/user.d.ts +6 -0
- package/dist/oidc/user.d.ts.map +1 -0
- package/dist/pwa/react/index.d.ts +2 -0
- package/dist/pwa/react/index.d.ts.map +1 -1
- package/dist/pwa/react/index.js +264 -3
- package/dist/pwa/react/index.js.map +6 -3
- package/dist/pwa/react/push-status.d.ts +31 -0
- package/dist/pwa/react/push-status.d.ts.map +1 -0
- package/dist/pwa/react/push-store.d.ts +55 -0
- package/dist/pwa/react/push-store.d.ts.map +1 -0
- package/dist/pwa/react/use-push-subscription.d.ts +15 -0
- package/dist/pwa/react/use-push-subscription.d.ts.map +1 -0
- package/dist/pwa/worker/index.d.ts +2 -0
- package/dist/pwa/worker/index.d.ts.map +1 -1
- package/dist/pwa/worker/index.js +94 -4
- package/dist/pwa/worker/index.js.map +7 -6
- package/dist/pwa/worker/plan.d.ts +7 -0
- package/dist/pwa/worker/plan.d.ts.map +1 -1
- package/dist/pwa/worker/push.d.ts +48 -0
- package/dist/pwa/worker/push.d.ts.map +1 -0
- package/dist/pwa/worker/scope.d.ts +23 -0
- package/dist/pwa/worker/scope.d.ts.map +1 -1
- package/dist/pwa/worker/start-worker.d.ts +2 -0
- package/dist/pwa/worker/start-worker.d.ts.map +1 -1
- package/docs/guide/pwa.md +101 -1
- package/docs/troubleshooting.md +18 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { JWTPayload } from 'jose';
|
|
2
|
-
import {
|
|
3
|
-
import { OidcError } from './errors';
|
|
4
|
-
import {
|
|
2
|
+
import type { DpopAlgorithm, DpopBinding } from './dpop';
|
|
3
|
+
import type { OidcError } from './errors';
|
|
4
|
+
import type { Fetcher } from './flow';
|
|
5
5
|
/** What `oidcClient` takes. */
|
|
6
6
|
export interface OidcOptions {
|
|
7
7
|
/** The issuer's identifier, exactly as its discovery document names it (no trailing slash needed). */
|
|
@@ -92,59 +92,4 @@ export interface OidcUser {
|
|
|
92
92
|
/** The `fetch` the client was given (global `fetch` by default): `dpopFetch` sends a bearer call through it. */
|
|
93
93
|
readonly fetch: Fetcher;
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
export interface OidcClient {
|
|
97
|
-
/** The route action or loader that starts the sign-in: a redirect to the issuer. `?next=` is kept, through `safeNext`. */
|
|
98
|
-
signIn(request: Request): Promise<Response>;
|
|
99
|
-
/** The redirect route: checks state, exchanges the code, validates the id token, sets the token cookie and redirects to `next`. Throws `OidcError`. */
|
|
100
|
-
callback(request: Request): Promise<Response>;
|
|
101
|
-
/** The signed-in user (refreshed if due), or `null`. */
|
|
102
|
-
oidcUser(request: Request): Promise<OidcUser | null>;
|
|
103
|
-
/**
|
|
104
|
-
* Refreshes `user` from its own tokens (not the request's cookie, which a rotation
|
|
105
|
-
* leaves behind) when its access token ends within `refreshSkewSeconds`, and returns
|
|
106
|
-
* the new user, whose `headers` hold the `Set-Cookie` to send; `user` itself when
|
|
107
|
-
* nothing is due, or with `{ force: true }` always. A forced refresh inside the
|
|
108
|
-
* flight window of `refreshFlightMs` shares that flight's tokens; with no refresh
|
|
109
|
-
* token it returns `user` while its access token is valid. A refresh that fails
|
|
110
|
-
* throws `OidcError` (`refresh-failed`) when the access token has ended, else
|
|
111
|
-
* returns `user`. Only a user this client returned can be refreshed (else
|
|
112
|
-
* `TypeError`).
|
|
113
|
-
*/
|
|
114
|
-
refresh(user: OidcUser, options?: {
|
|
115
|
-
readonly force?: boolean | undefined;
|
|
116
|
-
}): Promise<OidcUser>;
|
|
117
|
-
/** Like `oidcUser`, but throws a redirect to the sign-in route (with a safe `next`) when there is none. */
|
|
118
|
-
requireOidcUser(request: Request): Promise<OidcUser>;
|
|
119
|
-
/** Clears the token cookie (after revoking the tokens with `revokeOnLogout`) and redirects to the issuer's `end_session_endpoint` (with `id_token_hint`), else to `postLogoutRedirectUri` or `/`. Call it from an action. */
|
|
120
|
-
logout(request: Request): Promise<Response>;
|
|
121
|
-
/** The cookie names as sent, prefixes included. */
|
|
122
|
-
readonly names: {
|
|
123
|
-
readonly session: string;
|
|
124
|
-
readonly challenge: string;
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* A BFF as the relying party of an external OpenID Connect issuer:
|
|
129
|
-
* authorization code with PKCE (S256), state and nonce in a short-lived
|
|
130
|
-
* `__Host-` challenge cookie, discovery (cached), the code exchange, the id
|
|
131
|
-
* token validated against the issuer's keys (`jose`, an optional peer), the
|
|
132
|
-
* tokens in a sealed `__Host-` cookie, a single-flight refresh and
|
|
133
|
-
* RP-initiated logout.
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* export const oidc = oidcClient({
|
|
137
|
-
* issuer: 'https://id.example.com',
|
|
138
|
-
* clientId: 'my-app',
|
|
139
|
-
* clientSecret: process.env.OIDC_CLIENT_SECRET,
|
|
140
|
-
* redirectUri: 'https://app.example.com/auth/callback',
|
|
141
|
-
* scopes: ['openid', 'profile', 'email', 'offline_access'],
|
|
142
|
-
* secret: process.env.SESSION_SECRET!,
|
|
143
|
-
* name: 'my-app_oidc',
|
|
144
|
-
* secure: !import.meta.env.DEV,
|
|
145
|
-
* });
|
|
146
|
-
* // routes/auth.callback.ts: export const loader = ({ request }) => oidc.callback(request);
|
|
147
|
-
* // any loader: const { claims, headers } = await oidc.requireOidcUser(request);
|
|
148
|
-
*/
|
|
149
|
-
export declare function oidcClient(options: OidcOptions): OidcClient;
|
|
150
|
-
//# sourceMappingURL=oidc.d.ts.map
|
|
95
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/oidc/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC,+BAA+B;AAC/B,MAAM,WAAW,WAAW;IAC3B,sGAAsG;IACtG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,uGAAuG;IACv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ads, from the session's tokens; remembers them for `refresh`. */
|
|
5
|
+
export declare function toUser(ctx: OidcContext, stored: Stored, headers: Headers): Promise<OidcUser>;
|
|
6
|
+
//# sourceMappingURL=user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/oidc/user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,wFAAwF;AACxF,wBAAsB,MAAM,CAC3B,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,QAAQ,CAAC,CAqBnB"}
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* `react` is its only import (an optional peer of the package), and what it
|
|
4
4
|
* shares with `/pwa` is a chunk of that entry.
|
|
5
5
|
*/
|
|
6
|
+
export { derivePushStatus, type PushFacts, type PushPermission, type PushStatus, urlBase64ToBytes, } from './push-status';
|
|
6
7
|
export { useOnline } from './use-online';
|
|
8
|
+
export { type PushSubscriptionJson, type PushSubscriptionState, usePushStatus, usePushSubscription, } from './use-push-subscription';
|
|
7
9
|
export { type ServiceWorkerOptions, useServiceWorker, } from './use-service-worker';
|
|
8
10
|
export { updateNotice, useUpdateNotice } from './use-update-notice';
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pwa/react/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pwa/react/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,gBAAgB,GAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,aAAa,EACb,mBAAmB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,KAAK,oBAAoB,EACzB,gBAAgB,GAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/pwa/react/index.js
CHANGED
|
@@ -5,6 +5,30 @@ import {
|
|
|
5
5
|
sessionStore2
|
|
6
6
|
} from "../../chunks/index-9xv2a8et.js";
|
|
7
7
|
|
|
8
|
+
// src/pwa/react/push-status.ts
|
|
9
|
+
function derivePushStatus(facts) {
|
|
10
|
+
if (facts.ios && !facts.installedPwa && !facts.hasPushManager) {
|
|
11
|
+
return "install-required";
|
|
12
|
+
}
|
|
13
|
+
if (!facts.hasServiceWorker || !facts.hasPushManager || !facts.hasNotification) {
|
|
14
|
+
return "unsupported";
|
|
15
|
+
}
|
|
16
|
+
if (facts.asking)
|
|
17
|
+
return "asking";
|
|
18
|
+
if (facts.permission === "denied")
|
|
19
|
+
return "denied";
|
|
20
|
+
if (facts.permission === "granted" && facts.subscribed)
|
|
21
|
+
return "granted";
|
|
22
|
+
return "available";
|
|
23
|
+
}
|
|
24
|
+
function urlBase64ToBytes(value) {
|
|
25
|
+
const padded = value.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(value.length / 4) * 4, "=");
|
|
26
|
+
const raw = atob(padded);
|
|
27
|
+
const bytes = new Uint8Array(raw.length);
|
|
28
|
+
for (let i = 0;i < raw.length; i++)
|
|
29
|
+
bytes[i] = raw.charCodeAt(i);
|
|
30
|
+
return bytes;
|
|
31
|
+
}
|
|
8
32
|
// src/pwa/react/use-online.ts
|
|
9
33
|
import { useSyncExternalStore } from "react";
|
|
10
34
|
function subscribe(onChange) {
|
|
@@ -18,6 +42,239 @@ function subscribe(onChange) {
|
|
|
18
42
|
function useOnline() {
|
|
19
43
|
return useSyncExternalStore(subscribe, () => navigator.onLine, () => true);
|
|
20
44
|
}
|
|
45
|
+
// src/pwa/react/use-push-subscription.ts
|
|
46
|
+
import { useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
47
|
+
|
|
48
|
+
// src/pwa/react/push-store.ts
|
|
49
|
+
var NONE = {
|
|
50
|
+
hasServiceWorker: false,
|
|
51
|
+
hasPushManager: false,
|
|
52
|
+
hasNotification: false,
|
|
53
|
+
ios: false,
|
|
54
|
+
installedPwa: false,
|
|
55
|
+
permission: "default",
|
|
56
|
+
subscribed: false
|
|
57
|
+
};
|
|
58
|
+
function isIos() {
|
|
59
|
+
const ua = navigator.userAgent ?? "";
|
|
60
|
+
return /iPad|iPhone|iPod/.test(ua) || navigator.platform === "MacIntel" && (navigator.maxTouchPoints ?? 0) > 1;
|
|
61
|
+
}
|
|
62
|
+
function isInstalled() {
|
|
63
|
+
const standalone = navigator.standalone;
|
|
64
|
+
return standalone === true || typeof window.matchMedia === "function" && window.matchMedia("(display-mode: standalone)").matches;
|
|
65
|
+
}
|
|
66
|
+
function capabilities() {
|
|
67
|
+
return {
|
|
68
|
+
hasServiceWorker: "serviceWorker" in navigator,
|
|
69
|
+
hasPushManager: "PushManager" in window,
|
|
70
|
+
hasNotification: typeof Notification !== "undefined"
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async function readEnv() {
|
|
74
|
+
const caps = capabilities();
|
|
75
|
+
let sub = null;
|
|
76
|
+
if (caps.hasServiceWorker && caps.hasPushManager) {
|
|
77
|
+
try {
|
|
78
|
+
const registration = await navigator.serviceWorker.getRegistration();
|
|
79
|
+
const current = await registration?.pushManager.getSubscription();
|
|
80
|
+
sub = current ? current.toJSON() : null;
|
|
81
|
+
} catch {
|
|
82
|
+
sub = null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
sub,
|
|
87
|
+
env: {
|
|
88
|
+
...caps,
|
|
89
|
+
ios: isIos(),
|
|
90
|
+
installedPwa: isInstalled(),
|
|
91
|
+
permission: caps.hasNotification ? Notification.permission : "default",
|
|
92
|
+
subscribed: sub !== null
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function sameKey(current, bytes) {
|
|
97
|
+
if (!current)
|
|
98
|
+
return false;
|
|
99
|
+
const a = new Uint8Array(current);
|
|
100
|
+
return a.length === bytes.length && a.every((value, i) => value === bytes[i]);
|
|
101
|
+
}
|
|
102
|
+
function createPushStore() {
|
|
103
|
+
let env = NONE;
|
|
104
|
+
let subscription = null;
|
|
105
|
+
let asking = false;
|
|
106
|
+
let replaced = null;
|
|
107
|
+
let version = 0;
|
|
108
|
+
let inflight = null;
|
|
109
|
+
const listeners = new Set;
|
|
110
|
+
let detach;
|
|
111
|
+
let snapshot;
|
|
112
|
+
const build = () => {
|
|
113
|
+
const status = derivePushStatus({
|
|
114
|
+
...env,
|
|
115
|
+
subscribed: subscription !== null,
|
|
116
|
+
asking
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
status,
|
|
120
|
+
supported: status !== "unsupported" && status !== "install-required",
|
|
121
|
+
permission: env.permission,
|
|
122
|
+
installedPwa: env.installedPwa,
|
|
123
|
+
subscription,
|
|
124
|
+
replaced,
|
|
125
|
+
subscribe,
|
|
126
|
+
unsubscribe
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
const publish = () => {
|
|
130
|
+
snapshot = build();
|
|
131
|
+
for (const listener of listeners)
|
|
132
|
+
listener();
|
|
133
|
+
};
|
|
134
|
+
async function refresh() {
|
|
135
|
+
const started = version;
|
|
136
|
+
const read = await readEnv();
|
|
137
|
+
if (started !== version)
|
|
138
|
+
return;
|
|
139
|
+
env = read.env;
|
|
140
|
+
subscription = read.sub;
|
|
141
|
+
publish();
|
|
142
|
+
}
|
|
143
|
+
async function run(vapidPublicKey) {
|
|
144
|
+
const caps = capabilities();
|
|
145
|
+
if (!caps.hasServiceWorker || !caps.hasPushManager || !caps.hasNotification) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
const registration = await navigator.serviceWorker.getRegistration();
|
|
149
|
+
if (!registration) {
|
|
150
|
+
throw new Error("usePushSubscription: no service worker is registered; register the service worker first");
|
|
151
|
+
}
|
|
152
|
+
const permission = await Notification.requestPermission();
|
|
153
|
+
env = { ...env, permission };
|
|
154
|
+
if (permission !== "granted")
|
|
155
|
+
return null;
|
|
156
|
+
const bytes = urlBase64ToBytes(vapidPublicKey);
|
|
157
|
+
const { pushManager } = registration;
|
|
158
|
+
const existing = await pushManager.getSubscription();
|
|
159
|
+
let old = null;
|
|
160
|
+
if (existing) {
|
|
161
|
+
const same = sameKey(existing.options?.applicationServerKey, bytes);
|
|
162
|
+
if (same) {
|
|
163
|
+
subscription = existing.toJSON();
|
|
164
|
+
return subscription;
|
|
165
|
+
}
|
|
166
|
+
old = existing.endpoint;
|
|
167
|
+
await existing.unsubscribe();
|
|
168
|
+
}
|
|
169
|
+
const init = { userVisibleOnly: true, applicationServerKey: bytes };
|
|
170
|
+
let created;
|
|
171
|
+
try {
|
|
172
|
+
created = await pushManager.subscribe(init);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (error.name !== "InvalidStateError")
|
|
175
|
+
throw error;
|
|
176
|
+
const stale = await pushManager.getSubscription();
|
|
177
|
+
if (stale) {
|
|
178
|
+
old ??= stale.endpoint;
|
|
179
|
+
await stale.unsubscribe();
|
|
180
|
+
}
|
|
181
|
+
created = await pushManager.subscribe(init);
|
|
182
|
+
}
|
|
183
|
+
replaced = old;
|
|
184
|
+
subscription = created.toJSON();
|
|
185
|
+
return subscription;
|
|
186
|
+
}
|
|
187
|
+
function subscribe(vapidPublicKey) {
|
|
188
|
+
if (inflight)
|
|
189
|
+
return inflight;
|
|
190
|
+
version++;
|
|
191
|
+
asking = true;
|
|
192
|
+
replaced = null;
|
|
193
|
+
publish();
|
|
194
|
+
const promise = run(vapidPublicKey).finally(() => {
|
|
195
|
+
version++;
|
|
196
|
+
asking = false;
|
|
197
|
+
inflight = null;
|
|
198
|
+
publish();
|
|
199
|
+
});
|
|
200
|
+
inflight = promise;
|
|
201
|
+
return promise;
|
|
202
|
+
}
|
|
203
|
+
async function unsubscribe() {
|
|
204
|
+
const caps = capabilities();
|
|
205
|
+
if (!caps.hasServiceWorker || !caps.hasPushManager)
|
|
206
|
+
return null;
|
|
207
|
+
version++;
|
|
208
|
+
try {
|
|
209
|
+
const registration = await navigator.serviceWorker.getRegistration();
|
|
210
|
+
const current = await registration?.pushManager.getSubscription();
|
|
211
|
+
if (!current) {
|
|
212
|
+
subscription = null;
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
const { endpoint } = current;
|
|
216
|
+
await current.unsubscribe();
|
|
217
|
+
subscription = null;
|
|
218
|
+
return endpoint;
|
|
219
|
+
} finally {
|
|
220
|
+
version++;
|
|
221
|
+
publish();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function attach() {
|
|
225
|
+
refresh();
|
|
226
|
+
const onVisible = () => {
|
|
227
|
+
if (document.visibilityState !== "hidden")
|
|
228
|
+
refresh();
|
|
229
|
+
};
|
|
230
|
+
document.addEventListener("visibilitychange", onVisible);
|
|
231
|
+
let status;
|
|
232
|
+
let attached = true;
|
|
233
|
+
try {
|
|
234
|
+
navigator.permissions?.query({ name: "notifications" }).then((result) => {
|
|
235
|
+
if (!attached)
|
|
236
|
+
return;
|
|
237
|
+
status = result;
|
|
238
|
+
result.onchange = () => void refresh();
|
|
239
|
+
}).catch(() => {
|
|
240
|
+
return;
|
|
241
|
+
});
|
|
242
|
+
} catch {}
|
|
243
|
+
return () => {
|
|
244
|
+
attached = false;
|
|
245
|
+
document.removeEventListener("visibilitychange", onVisible);
|
|
246
|
+
if (status)
|
|
247
|
+
status.onchange = null;
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
snapshot = build();
|
|
251
|
+
const server = snapshot;
|
|
252
|
+
return {
|
|
253
|
+
subscribe(listener) {
|
|
254
|
+
if (listeners.size === 0)
|
|
255
|
+
detach = attach();
|
|
256
|
+
listeners.add(listener);
|
|
257
|
+
return () => {
|
|
258
|
+
listeners.delete(listener);
|
|
259
|
+
if (listeners.size === 0) {
|
|
260
|
+
detach?.();
|
|
261
|
+
detach = undefined;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
},
|
|
265
|
+
getSnapshot: () => snapshot,
|
|
266
|
+
getServerSnapshot: () => server
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
var pushStore = createPushStore();
|
|
270
|
+
|
|
271
|
+
// src/pwa/react/use-push-subscription.ts
|
|
272
|
+
function usePushSubscription() {
|
|
273
|
+
return useSyncExternalStore2(pushStore.subscribe, pushStore.getSnapshot, pushStore.getServerSnapshot);
|
|
274
|
+
}
|
|
275
|
+
function usePushStatus() {
|
|
276
|
+
return usePushSubscription().status;
|
|
277
|
+
}
|
|
21
278
|
// src/pwa/react/use-service-worker.ts
|
|
22
279
|
import { useEffect, useRef } from "react";
|
|
23
280
|
|
|
@@ -39,10 +296,10 @@ function startServiceWorker(environment, options) {
|
|
|
39
296
|
}
|
|
40
297
|
|
|
41
298
|
// src/pwa/react/use-update-notice.ts
|
|
42
|
-
import { useSyncExternalStore as
|
|
299
|
+
import { useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
43
300
|
var updateNotice = createUpdateNotice2(sessionStore2);
|
|
44
301
|
function useUpdateNotice(notice = updateNotice) {
|
|
45
|
-
return
|
|
302
|
+
return useSyncExternalStore3((listener) => notice.subscribe(listener), () => notice.current(), () => {
|
|
46
303
|
return;
|
|
47
304
|
});
|
|
48
305
|
}
|
|
@@ -65,11 +322,15 @@ function useServiceWorker(options) {
|
|
|
65
322
|
}, [enabled, url, scope, notice]);
|
|
66
323
|
}
|
|
67
324
|
export {
|
|
325
|
+
derivePushStatus,
|
|
68
326
|
updateNotice,
|
|
327
|
+
urlBase64ToBytes,
|
|
69
328
|
useOnline,
|
|
329
|
+
usePushStatus,
|
|
330
|
+
usePushSubscription,
|
|
70
331
|
useServiceWorker,
|
|
71
332
|
useUpdateNotice
|
|
72
333
|
};
|
|
73
334
|
|
|
74
|
-
//# debugId=
|
|
335
|
+
//# debugId=86033255FD05D82F64756E2164756E21
|
|
75
336
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/pwa/react/use-online.ts", "../src/pwa/react/use-service-worker.ts", "../src/pwa/model/start-service-worker.ts", "../src/pwa/react/use-update-notice.ts"],
|
|
3
|
+
"sources": ["../src/pwa/react/push-status.ts", "../src/pwa/react/use-online.ts", "../src/pwa/react/use-push-subscription.ts", "../src/pwa/react/push-store.ts", "../src/pwa/react/use-service-worker.ts", "../src/pwa/model/start-service-worker.ts", "../src/pwa/react/use-update-notice.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
+
"/** Where the push flow stands, as an opt-in card shows it. */\nexport type PushStatus =\n\t/** Can be asked for: permission not decided, or granted with no subscription yet. */\n\t| 'available'\n\t/** `subscribe()` is running: the permission prompt or the subscription is pending. */\n\t| 'asking'\n\t/** Permission granted and this browser holds a subscription. */\n\t| 'granted'\n\t/** The user blocked notifications; only the browser's settings can undo it. */\n\t| 'denied'\n\t/** iOS outside an installed PWA: add the app to the home screen first. */\n\t| 'install-required'\n\t/** No service worker, no Push API or no Notification API. */\n\t| 'unsupported';\n\nexport type PushPermission = 'default' | 'granted' | 'denied';\n\n/** What `derivePushStatus` reads: plain facts, no browser objects. */\nexport interface PushFacts {\n\thasServiceWorker: boolean;\n\thasPushManager: boolean;\n\thasNotification: boolean;\n\tios: boolean;\n\tinstalledPwa: boolean;\n\tpermission: PushPermission;\n\tsubscribed: boolean;\n\tasking: boolean;\n}\n\n/** The status for the facts; pure. */\nexport function derivePushStatus(facts: PushFacts): PushStatus {\n\tif (facts.ios && !facts.installedPwa && !facts.hasPushManager) {\n\t\treturn 'install-required';\n\t}\n\tif (\n\t\t!facts.hasServiceWorker ||\n\t\t!facts.hasPushManager ||\n\t\t!facts.hasNotification\n\t) {\n\t\treturn 'unsupported';\n\t}\n\tif (facts.asking) return 'asking';\n\tif (facts.permission === 'denied') return 'denied';\n\tif (facts.permission === 'granted' && facts.subscribed) return 'granted';\n\treturn 'available';\n}\n\n/** A base64url VAPID public key as the bytes `applicationServerKey` takes. */\nexport function urlBase64ToBytes(value: string): Uint8Array<ArrayBuffer> {\n\tconst padded = value\n\t\t.replace(/-/g, '+')\n\t\t.replace(/_/g, '/')\n\t\t.padEnd(Math.ceil(value.length / 4) * 4, '=');\n\tconst raw = atob(padded);\n\tconst bytes = new Uint8Array(raw.length);\n\tfor (let i = 0; i < raw.length; i++) bytes[i] = raw.charCodeAt(i);\n\treturn bytes;\n}\n",
|
|
5
6
|
"import { useSyncExternalStore } from 'react';\n\nfunction subscribe(onChange: () => void) {\n\twindow.addEventListener('online', onChange);\n\twindow.addEventListener('offline', onChange);\n\treturn () => {\n\t\twindow.removeEventListener('online', onChange);\n\t\twindow.removeEventListener('offline', onChange);\n\t};\n}\n\n/**\n * Whether the browser says it is online. Online on the server and during\n * hydration, so the first client render matches the server's.\n */\nexport function useOnline(): boolean {\n\treturn useSyncExternalStore(\n\t\tsubscribe,\n\t\t() => navigator.onLine,\n\t\t() => true,\n\t);\n}\n",
|
|
7
|
+
"import { useSyncExternalStore } from 'react';\nimport type { PushStatus } from './push-status';\nimport { pushStore } from './push-store';\n\nexport type { PushSubscriptionJson, PushSubscriptionState } from './push-store';\n\nimport type { PushSubscriptionState } from './push-store';\n\n/**\n * The page's side of Web Push: the derived `status` and `subscribe` /\n * `unsubscribe`. Every call shares one state, so a card and a button agree.\n * It never prompts on mount; `subscribe` asks for permission only inside the\n * call, so wire it to a click. On the server and while hydrating the status is\n * `unsupported` and nothing touches `window`; the browser is read once\n * something is mounted, and again when the tab shows or the permission changes.\n */\nexport function usePushSubscription(): PushSubscriptionState {\n\treturn useSyncExternalStore(\n\t\tpushStore.subscribe,\n\t\tpushStore.getSnapshot,\n\t\tpushStore.getServerSnapshot,\n\t);\n}\n\n/** Just the derived status, for a presentational opt-in card's `status` prop. */\nexport function usePushStatus(): PushStatus {\n\treturn usePushSubscription().status;\n}\n",
|
|
8
|
+
"import {\n\tderivePushStatus,\n\ttype PushFacts,\n\ttype PushPermission,\n\ttype PushStatus,\n\turlBase64ToBytes,\n} from './push-status';\n\n/** `PushSubscription.toJSON()`: what the app sends to its server. */\nexport interface PushSubscriptionJson {\n\tendpoint?: string;\n\texpirationTime?: number | null;\n\tkeys?: Record<string, string>;\n}\n\nexport interface PushSubscriptionState {\n\t/** The derived status (`available`, `asking`, `granted`, …). */\n\tstatus: PushStatus;\n\t/** Whether this browser can do Web Push at all (`status` is neither `unsupported` nor `install-required`). */\n\tsupported: boolean;\n\t/** `Notification.permission`; `'default'` until the browser is read. */\n\tpermission: PushPermission;\n\t/** Whether the page runs as an installed app (`display-mode: standalone`). */\n\tinstalledPwa: boolean;\n\t/** The current subscription's `toJSON()`, or `null`. */\n\tsubscription: PushSubscriptionJson | null;\n\t/**\n\t * The endpoint of an older subscription the last `subscribe()` replaced\n\t * (made with another VAPID key), so the app can tell its server to drop it;\n\t * `null` otherwise.\n\t */\n\treplaced: string | null;\n\t/**\n\t * Asks for permission, then subscribes. Call it from a click: the\n\t * permission prompt is requested inside this call and never on mount.\n\t * Resolves with the subscription's `toJSON()` to send to the server, `null`\n\t * when the user did not grant permission or the browser has no Web Push, and\n\t * rejects with an error when no service worker is registered (checked before\n\t * the prompt). A second call while one runs returns the same promise. A\n\t * subscription made with another VAPID key is replaced (see `replaced`).\n\t */\n\tsubscribe(vapidPublicKey: string): Promise<PushSubscriptionJson | null>;\n\t/** Unsubscribes; resolves with the endpoint to tell the server about, or `null` when there was no subscription or no Web Push. */\n\tunsubscribe(): Promise<string | null>;\n}\n\ntype Env = Omit<PushFacts, 'asking'>;\n\nconst NONE: Env = {\n\thasServiceWorker: false,\n\thasPushManager: false,\n\thasNotification: false,\n\tios: false,\n\tinstalledPwa: false,\n\tpermission: 'default',\n\tsubscribed: false,\n};\n\nfunction isIos(): boolean {\n\tconst ua = navigator.userAgent ?? '';\n\treturn (\n\t\t/iPad|iPhone|iPod/.test(ua) ||\n\t\t(navigator.platform === 'MacIntel' && (navigator.maxTouchPoints ?? 0) > 1)\n\t);\n}\n\nfunction isInstalled(): boolean {\n\tconst standalone = (navigator as { standalone?: boolean }).standalone;\n\treturn (\n\t\tstandalone === true ||\n\t\t(typeof window.matchMedia === 'function' &&\n\t\t\twindow.matchMedia('(display-mode: standalone)').matches)\n\t);\n}\n\nfunction capabilities() {\n\treturn {\n\t\thasServiceWorker: 'serviceWorker' in navigator,\n\t\thasPushManager: 'PushManager' in window,\n\t\thasNotification: typeof Notification !== 'undefined',\n\t};\n}\n\nasync function readEnv(): Promise<{\n\tenv: Env;\n\tsub: PushSubscriptionJson | null;\n}> {\n\tconst caps = capabilities();\n\tlet sub: PushSubscriptionJson | null = null;\n\tif (caps.hasServiceWorker && caps.hasPushManager) {\n\t\ttry {\n\t\t\tconst registration = await navigator.serviceWorker.getRegistration();\n\t\t\tconst current = await registration?.pushManager.getSubscription();\n\t\t\tsub = current ? current.toJSON() : null;\n\t\t} catch {\n\t\t\tsub = null;\n\t\t}\n\t}\n\treturn {\n\t\tsub,\n\t\tenv: {\n\t\t\t...caps,\n\t\t\tios: isIos(),\n\t\t\tinstalledPwa: isInstalled(),\n\t\t\tpermission: caps.hasNotification ? Notification.permission : 'default',\n\t\t\tsubscribed: sub !== null,\n\t\t},\n\t};\n}\n\nfunction sameKey(current: ArrayBuffer | null | undefined, bytes: Uint8Array) {\n\tif (!current) return false;\n\tconst a = new Uint8Array(current);\n\treturn a.length === bytes.length && a.every((value, i) => value === bytes[i]);\n}\n\n/**\n * The page's one Web Push state, shared by every `usePushSubscription` and\n * `usePushStatus`. It reads the browser while something listens, never\n * during render, and re-reads when the tab shows again or the permission\n * changes. Exported for specs; the page uses `pushStore`.\n */\nexport function createPushStore() {\n\tlet env: Env = NONE;\n\tlet subscription: PushSubscriptionJson | null = null;\n\tlet asking = false;\n\tlet replaced: string | null = null;\n\t/** Bumped by every subscribe and unsubscribe, so an older read never overwrites their result. */\n\tlet version = 0;\n\tlet inflight: Promise<PushSubscriptionJson | null> | null = null;\n\tconst listeners = new Set<() => void>();\n\tlet detach: (() => void) | undefined;\n\n\tlet snapshot: PushSubscriptionState;\n\tconst build = (): PushSubscriptionState => {\n\t\tconst status = derivePushStatus({\n\t\t\t...env,\n\t\t\tsubscribed: subscription !== null,\n\t\t\tasking,\n\t\t});\n\t\treturn {\n\t\t\tstatus,\n\t\t\tsupported: status !== 'unsupported' && status !== 'install-required',\n\t\t\tpermission: env.permission,\n\t\t\tinstalledPwa: env.installedPwa,\n\t\t\tsubscription,\n\t\t\treplaced,\n\t\t\tsubscribe,\n\t\t\tunsubscribe,\n\t\t};\n\t};\n\tconst publish = () => {\n\t\tsnapshot = build();\n\t\tfor (const listener of listeners) listener();\n\t};\n\n\tasync function refresh() {\n\t\tconst started = version;\n\t\tconst read = await readEnv();\n\t\tif (started !== version) return;\n\t\tenv = read.env;\n\t\tsubscription = read.sub;\n\t\tpublish();\n\t}\n\n\tasync function run(vapidPublicKey: string) {\n\t\tconst caps = capabilities();\n\t\tif (\n\t\t\t!caps.hasServiceWorker ||\n\t\t\t!caps.hasPushManager ||\n\t\t\t!caps.hasNotification\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t\t// Before the prompt: a user must not be asked for nothing.\n\t\tconst registration = await navigator.serviceWorker.getRegistration();\n\t\tif (!registration) {\n\t\t\tthrow new Error(\n\t\t\t\t'usePushSubscription: no service worker is registered; register the service worker first',\n\t\t\t);\n\t\t}\n\t\tconst permission = await Notification.requestPermission();\n\t\tenv = { ...env, permission };\n\t\tif (permission !== 'granted') return null;\n\t\tconst bytes = urlBase64ToBytes(vapidPublicKey);\n\t\tconst { pushManager } = registration;\n\t\tconst existing = await pushManager.getSubscription();\n\t\tlet old: string | null = null;\n\t\tif (existing) {\n\t\t\tconst same = sameKey(existing.options?.applicationServerKey, bytes);\n\t\t\tif (same) {\n\t\t\t\tsubscription = existing.toJSON();\n\t\t\t\treturn subscription;\n\t\t\t}\n\t\t\told = existing.endpoint;\n\t\t\tawait existing.unsubscribe();\n\t\t}\n\t\tconst init = { userVisibleOnly: true, applicationServerKey: bytes };\n\t\tlet created: PushSubscription;\n\t\ttry {\n\t\t\tcreated = await pushManager.subscribe(init);\n\t\t} catch (error) {\n\t\t\tif ((error as { name?: string }).name !== 'InvalidStateError')\n\t\t\t\tthrow error;\n\t\t\tconst stale = await pushManager.getSubscription();\n\t\t\tif (stale) {\n\t\t\t\told ??= stale.endpoint;\n\t\t\t\tawait stale.unsubscribe();\n\t\t\t}\n\t\t\tcreated = await pushManager.subscribe(init);\n\t\t}\n\t\treplaced = old;\n\t\tsubscription = created.toJSON();\n\t\treturn subscription;\n\t}\n\n\tfunction subscribe(vapidPublicKey: string) {\n\t\tif (inflight) return inflight;\n\t\tversion++;\n\t\tasking = true;\n\t\treplaced = null;\n\t\tpublish();\n\t\tconst promise = run(vapidPublicKey).finally(() => {\n\t\t\tversion++;\n\t\t\tasking = false;\n\t\t\tinflight = null;\n\t\t\tpublish();\n\t\t});\n\t\tinflight = promise;\n\t\treturn promise;\n\t}\n\n\tasync function unsubscribe() {\n\t\tconst caps = capabilities();\n\t\tif (!caps.hasServiceWorker || !caps.hasPushManager) return null;\n\t\tversion++;\n\t\ttry {\n\t\t\tconst registration = await navigator.serviceWorker.getRegistration();\n\t\t\tconst current = await registration?.pushManager.getSubscription();\n\t\t\tif (!current) {\n\t\t\t\tsubscription = null;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst { endpoint } = current;\n\t\t\tawait current.unsubscribe();\n\t\t\tsubscription = null;\n\t\t\treturn endpoint;\n\t\t} finally {\n\t\t\tversion++;\n\t\t\tpublish();\n\t\t}\n\t}\n\n\tfunction attach() {\n\t\tvoid refresh();\n\t\tconst onVisible = () => {\n\t\t\tif (document.visibilityState !== 'hidden') void refresh();\n\t\t};\n\t\tdocument.addEventListener('visibilitychange', onVisible);\n\t\tlet status: { onchange: unknown } | undefined;\n\t\tlet attached = true;\n\t\ttry {\n\t\t\tvoid navigator.permissions\n\t\t\t\t?.query({ name: 'notifications' })\n\t\t\t\t.then((result) => {\n\t\t\t\t\tif (!attached) return;\n\t\t\t\t\tstatus = result;\n\t\t\t\t\tresult.onchange = () => void refresh();\n\t\t\t\t})\n\t\t\t\t.catch(() => undefined);\n\t\t} catch {\n\t\t\t// `notifications` is not a queryable permission here.\n\t\t}\n\t\treturn () => {\n\t\t\tattached = false;\n\t\t\tdocument.removeEventListener('visibilitychange', onVisible);\n\t\t\tif (status) status.onchange = null;\n\t\t};\n\t}\n\n\tsnapshot = build();\n\tconst server = snapshot;\n\treturn {\n\t\tsubscribe(listener: () => void) {\n\t\t\tif (listeners.size === 0) detach = attach();\n\t\t\tlisteners.add(listener);\n\t\t\treturn () => {\n\t\t\t\tlisteners.delete(listener);\n\t\t\t\tif (listeners.size === 0) {\n\t\t\t\t\tdetach?.();\n\t\t\t\t\tdetach = undefined;\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t\tgetSnapshot: () => snapshot,\n\t\tgetServerSnapshot: () => server,\n\t};\n}\n\n/** The page's one store. */\nexport const pushStore = createPushStore();\n",
|
|
6
9
|
"import { useEffect, useRef } from 'react';\nimport { startServiceWorker } from '../model/start-service-worker';\nimport type { UpdateNoticeStore } from '../model/update-notice';\nimport { updateNotice } from './use-update-notice';\n\nexport interface ServiceWorkerOptions {\n\t/**\n\t * Whether to register at all. The app decides, typically\n\t * `import.meta.env.PROD`: a worker under a dev server caches the code being\n\t * edited. This package never reads `import.meta.env` itself.\n\t */\n\tenabled: boolean;\n\t/** The worker's path. `SERVICE_WORKER_URL` by default. */\n\turl?: string;\n\t/** The scope it controls. `'/'` by default. */\n\tscope?: string;\n\t/** Where a waiting version is offered. The page's `updateNotice` by default. */\n\tnotice?: UpdateNoticeStore;\n\t/**\n\t * Called when registering fails (private mode, a blocked script). The app\n\t * works without a worker, so by default the error is dropped. An `onError`\n\t * that throws becomes an unhandled rejection.\n\t */\n\tonError?: (error: unknown) => void;\n}\n\n/**\n * Registers the service worker after `load` when `enabled`, in a browser\n * that has one. When a new version waits, `notice` offers it (`useUpdateNotice`\n * reads it); nothing activates it unasked. Does nothing on the server.\n *\n * The options are read when the effect runs, which is on mount and when\n * `enabled`, `url`, `scope` or `notice` change; `onError` is always the\n * latest. The listeners it adds (the update check, the controller change)\n * stay for the page's life: there is no cleanup, a page has one worker.\n */\nexport function useServiceWorker(options: ServiceWorkerOptions): void {\n\tconst { enabled, url, scope, notice = updateNotice } = options;\n\tconst onError = useRef(options.onError);\n\tuseEffect(() => {\n\t\tonError.current = options.onError;\n\t});\n\tuseEffect(() => {\n\t\tstartServiceWorker(\n\t\t\t{ navigator },\n\t\t\t{\n\t\t\t\tenabled,\n\t\t\t\tnotice,\n\t\t\t\tonError: (error) => onError.current?.(error),\n\t\t\t\t...(url !== undefined && { url }),\n\t\t\t\t...(scope !== undefined && { scope }),\n\t\t\t},\n\t\t);\n\t}, [enabled, url, scope, notice]);\n}\n",
|
|
7
10
|
"import type { ServiceWorkerContainerLike } from './registration';\nimport { afterLoad, registerServiceWorker } from './registration';\nimport type { UpdateNoticeStore } from './update-notice';\n\n/** What starting reads of the browser: `navigator`, which may have no worker. */\nexport interface ServiceWorkerEnvironment {\n\tnavigator: object & { serviceWorker?: ServiceWorkerContainerLike };\n}\n\nexport interface StartServiceWorkerOptions {\n\tenabled: boolean;\n\turl?: string;\n\tscope?: string;\n\tnotice: Pick<UpdateNoticeStore, 'offer'>;\n\tonError?: (error: unknown) => void;\n}\n\n/**\n * The body of `useServiceWorker`'s effect, a plain function so that it is\n * tested without React: registers after `load` when `enabled` and the\n * browser has a worker container, offers each waiting version to `notice`,\n * and hands a failed registration to `onError`. The listeners it adds live\n * for the page.\n */\nexport function startServiceWorker(\n\tenvironment: ServiceWorkerEnvironment,\n\toptions: StartServiceWorkerOptions,\n): void {\n\tconst { navigator } = environment;\n\tif (!options.enabled || !('serviceWorker' in navigator)) return;\n\tconst container = navigator.serviceWorker;\n\tif (!container) return;\n\tconst { url, scope, notice, onError } = options;\n\tafterLoad(() => {\n\t\tregisterServiceWorker(\n\t\t\tcontainer,\n\t\t\t(worker, apply) => notice.offer(() => apply(worker)),\n\t\t\t{\n\t\t\t\t...(url !== undefined && { url }),\n\t\t\t\t...(scope !== undefined && { scope }),\n\t\t\t},\n\t\t).catch((error: unknown) => onError?.(error));\n\t});\n}\n",
|
|
8
11
|
"import { useSyncExternalStore } from 'react';\nimport {\n\tcreateUpdateNotice,\n\tsessionStore,\n\ttype UpdateNotice,\n\ttype UpdateNoticeStore,\n} from '../model/update-notice';\n\n/**\n * The page's one notice, which `useServiceWorker` offers and\n * `useUpdateNotice` reads. It lives here, not in `/pwa`, so that the model a\n * worker bundle imports makes nothing at load.\n */\nexport const updateNotice: UpdateNoticeStore = createUpdateNotice(sessionStore);\n\n/**\n * The update notice to show: a new version waits and \"Later\" was not asked.\n * None on the server. `notice` is the page's `updateNotice` unless the app\n * made a store of its own.\n */\nexport function useUpdateNotice(\n\tnotice: UpdateNoticeStore = updateNotice,\n): UpdateNotice | undefined {\n\treturn useSyncExternalStore(\n\t\t(listener) => notice.subscribe(listener),\n\t\t() => notice.current(),\n\t\t() => undefined,\n\t);\n}\n"
|
|
9
12
|
],
|
|
10
|
-
"mappings": ";;;;;;;;AAAA;AAEA,SAAS,SAAS,CAAC,UAAsB;AAAA,EACxC,OAAO,iBAAiB,UAAU,QAAQ;AAAA,EAC1C,OAAO,iBAAiB,WAAW,QAAQ;AAAA,EAC3C,OAAO,MAAM;AAAA,IACZ,OAAO,oBAAoB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aAAa,OAAO,UAAU,QAAQ,GACvC,MAAM,OAAO,QAAQ,GACrB,MAAG;AAAA,IAAG;AAAA,GACP;AAAA;;;AFSM,SAAS,gBAAgB,CAAC,SAAqC;AAAA,EACrE,QAAQ,SAAS,KAAK,OAAO,SAAS,iBAAiB;AAAA,EACvD,MAAM,UAAU,OAAO,QAAQ,OAAO;AAAA,EACtC,UAAU,MAAM;AAAA,IACf,QAAQ,UAAU,QAAQ;AAAA,GAC1B;AAAA,EACD,UAAU,MAAM;AAAA,IACf,mBACC,EAAE,UAAU,GACZ;AAAA,MACC;AAAA,MACA;AAAA,MACA,SAAS,CAAC,UAAU,QAAQ,UAAU,KAAK;AAAA,SACvC,QAAQ,aAAa,EAAE,IAAI;AAAA,SAC3B,UAAU,aAAa,EAAE,MAAM;AAAA,IACpC,CACD;AAAA,KACE,CAAC,SAAS,KAAK,OAAO,MAAM,CAAC;AAAA;",
|
|
14
|
+
"debugId": "86033255FD05D82F64756E2164756E21",
|
|
12
15
|
"names": []
|
|
13
16
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Where the push flow stands, as an opt-in card shows it. */
|
|
2
|
+
export type PushStatus =
|
|
3
|
+
/** Can be asked for: permission not decided, or granted with no subscription yet. */
|
|
4
|
+
'available'
|
|
5
|
+
/** `subscribe()` is running: the permission prompt or the subscription is pending. */
|
|
6
|
+
| 'asking'
|
|
7
|
+
/** Permission granted and this browser holds a subscription. */
|
|
8
|
+
| 'granted'
|
|
9
|
+
/** The user blocked notifications; only the browser's settings can undo it. */
|
|
10
|
+
| 'denied'
|
|
11
|
+
/** iOS outside an installed PWA: add the app to the home screen first. */
|
|
12
|
+
| 'install-required'
|
|
13
|
+
/** No service worker, no Push API or no Notification API. */
|
|
14
|
+
| 'unsupported';
|
|
15
|
+
export type PushPermission = 'default' | 'granted' | 'denied';
|
|
16
|
+
/** What `derivePushStatus` reads: plain facts, no browser objects. */
|
|
17
|
+
export interface PushFacts {
|
|
18
|
+
hasServiceWorker: boolean;
|
|
19
|
+
hasPushManager: boolean;
|
|
20
|
+
hasNotification: boolean;
|
|
21
|
+
ios: boolean;
|
|
22
|
+
installedPwa: boolean;
|
|
23
|
+
permission: PushPermission;
|
|
24
|
+
subscribed: boolean;
|
|
25
|
+
asking: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** The status for the facts; pure. */
|
|
28
|
+
export declare function derivePushStatus(facts: PushFacts): PushStatus;
|
|
29
|
+
/** A base64url VAPID public key as the bytes `applicationServerKey` takes. */
|
|
30
|
+
export declare function urlBase64ToBytes(value: string): Uint8Array<ArrayBuffer>;
|
|
31
|
+
//# sourceMappingURL=push-status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-status.d.ts","sourceRoot":"","sources":["../../../src/pwa/react/push-status.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,MAAM,UAAU;AACrB,qFAAqF;AACnF,WAAW;AACb,sFAAsF;GACpF,QAAQ;AACV,gEAAgE;GAC9D,SAAS;AACX,+EAA+E;GAC7E,QAAQ;AACV,0EAA0E;GACxE,kBAAkB;AACpB,6DAA6D;GAC3D,aAAa,CAAC;AAEjB,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE9D,sEAAsE;AACtE,MAAM,WAAW,SAAS;IACzB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,cAAc,EAAE,OAAO,CAAC;IACxB,eAAe,EAAE,OAAO,CAAC;IACzB,GAAG,EAAE,OAAO,CAAC;IACb,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,EAAE,cAAc,CAAC;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;CAChB;AAED,sCAAsC;AACtC,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,CAe7D;AAED,8EAA8E;AAC9E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CASvE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type PushPermission, type PushStatus } from './push-status';
|
|
2
|
+
/** `PushSubscription.toJSON()`: what the app sends to its server. */
|
|
3
|
+
export interface PushSubscriptionJson {
|
|
4
|
+
endpoint?: string;
|
|
5
|
+
expirationTime?: number | null;
|
|
6
|
+
keys?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export interface PushSubscriptionState {
|
|
9
|
+
/** The derived status (`available`, `asking`, `granted`, …). */
|
|
10
|
+
status: PushStatus;
|
|
11
|
+
/** Whether this browser can do Web Push at all (`status` is neither `unsupported` nor `install-required`). */
|
|
12
|
+
supported: boolean;
|
|
13
|
+
/** `Notification.permission`; `'default'` until the browser is read. */
|
|
14
|
+
permission: PushPermission;
|
|
15
|
+
/** Whether the page runs as an installed app (`display-mode: standalone`). */
|
|
16
|
+
installedPwa: boolean;
|
|
17
|
+
/** The current subscription's `toJSON()`, or `null`. */
|
|
18
|
+
subscription: PushSubscriptionJson | null;
|
|
19
|
+
/**
|
|
20
|
+
* The endpoint of an older subscription the last `subscribe()` replaced
|
|
21
|
+
* (made with another VAPID key), so the app can tell its server to drop it;
|
|
22
|
+
* `null` otherwise.
|
|
23
|
+
*/
|
|
24
|
+
replaced: string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Asks for permission, then subscribes. Call it from a click: the
|
|
27
|
+
* permission prompt is requested inside this call and never on mount.
|
|
28
|
+
* Resolves with the subscription's `toJSON()` to send to the server, `null`
|
|
29
|
+
* when the user did not grant permission or the browser has no Web Push, and
|
|
30
|
+
* rejects with an error when no service worker is registered (checked before
|
|
31
|
+
* the prompt). A second call while one runs returns the same promise. A
|
|
32
|
+
* subscription made with another VAPID key is replaced (see `replaced`).
|
|
33
|
+
*/
|
|
34
|
+
subscribe(vapidPublicKey: string): Promise<PushSubscriptionJson | null>;
|
|
35
|
+
/** Unsubscribes; resolves with the endpoint to tell the server about, or `null` when there was no subscription or no Web Push. */
|
|
36
|
+
unsubscribe(): Promise<string | null>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The page's one Web Push state, shared by every `usePushSubscription` and
|
|
40
|
+
* `usePushStatus`. It reads the browser while something listens, never
|
|
41
|
+
* during render, and re-reads when the tab shows again or the permission
|
|
42
|
+
* changes. Exported for specs; the page uses `pushStore`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createPushStore(): {
|
|
45
|
+
subscribe(listener: () => void): () => void;
|
|
46
|
+
getSnapshot: () => PushSubscriptionState;
|
|
47
|
+
getServerSnapshot: () => PushSubscriptionState;
|
|
48
|
+
};
|
|
49
|
+
/** The page's one store. */
|
|
50
|
+
export declare const pushStore: {
|
|
51
|
+
subscribe(listener: () => void): () => void;
|
|
52
|
+
getSnapshot: () => PushSubscriptionState;
|
|
53
|
+
getServerSnapshot: () => PushSubscriptionState;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=push-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-store.d.ts","sourceRoot":"","sources":["../../../src/pwa/react/push-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,cAAc,EACnB,KAAK,UAAU,EAEf,MAAM,eAAe,CAAC;AAEvB,qEAAqE;AACrE,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACrC,gEAAgE;IAChE,MAAM,EAAE,UAAU,CAAC;IACnB,8GAA8G;IAC9G,SAAS,EAAE,OAAO,CAAC;IACnB,wEAAwE;IACxE,UAAU,EAAE,cAAc,CAAC;IAC3B,8EAA8E;IAC9E,YAAY,EAAE,OAAO,CAAC;IACtB,wDAAwD;IACxD,YAAY,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC1C;;;;OAIG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB;;;;;;;;OAQG;IACH,SAAS,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC;IACxE,kIAAkI;IAClI,WAAW,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACtC;AAwED;;;;;GAKG;AACH,wBAAgB,eAAe;wBAiKT,MAAM,IAAI;;;EAc/B;AAED,4BAA4B;AAC5B,eAAO,MAAM,SAAS;wBAjBA,MAAM,IAAI;;;CAiBU,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PushStatus } from './push-status';
|
|
2
|
+
export type { PushSubscriptionJson, PushSubscriptionState } from './push-store';
|
|
3
|
+
import type { PushSubscriptionState } from './push-store';
|
|
4
|
+
/**
|
|
5
|
+
* The page's side of Web Push: the derived `status` and `subscribe` /
|
|
6
|
+
* `unsubscribe`. Every call shares one state, so a card and a button agree.
|
|
7
|
+
* It never prompts on mount; `subscribe` asks for permission only inside the
|
|
8
|
+
* call, so wire it to a click. On the server and while hydrating the status is
|
|
9
|
+
* `unsupported` and nothing touches `window`; the browser is read once
|
|
10
|
+
* something is mounted, and again when the tab shows or the permission changes.
|
|
11
|
+
*/
|
|
12
|
+
export declare function usePushSubscription(): PushSubscriptionState;
|
|
13
|
+
/** Just the derived status, for a presentational opt-in card's `status` prop. */
|
|
14
|
+
export declare function usePushStatus(): PushStatus;
|
|
15
|
+
//# sourceMappingURL=use-push-subscription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-push-subscription.d.ts","sourceRoot":"","sources":["../../../src/pwa/react/use-push-subscription.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,YAAY,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,IAAI,qBAAqB,CAM3D;AAED,iFAAiF;AACjF,wBAAgB,aAAa,IAAI,UAAU,CAE1C"}
|
|
@@ -6,5 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { injectedPrecache } from './injected';
|
|
8
8
|
export type { ExpirationOptions, WorkerOptions } from './plan';
|
|
9
|
+
export type { NotificationClickEventLike, PushEventLike, PushOptions, PushPayload, } from './push';
|
|
10
|
+
export { handleNotificationClick, handlePush } from './push';
|
|
9
11
|
export { startWorker } from './start-worker';
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pwa/worker/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pwa/worker/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/D,YAAY,EACX,0BAA0B,EAC1B,aAAa,EACb,WAAW,EACX,WAAW,GACX,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|