Files
WRNexusJSDoc/app/pages/packages/pwa.wrn
T

183 lines
11 KiB
Plaintext

page wrnexuspwa {
seo {
title = "@wrnexus/pwa"
description = "Progressive Web App manifests, service workers, and offline strategies."
}
view {
<div class="docs-shell">
<a href="#main" class="skip-link">Skip to content</a>
<header class="topbar">
<a class="brand" href="/"><span>W</span> WRNexusJS</a>
<nav aria-label="Primary"><a href="/getting-started">Get started</a><a href="/packages">Packages</a><a href="https://component.wrnexusjs.dev/">Components</a><a href="/language">Language</a><a href="/architecture">Architecture</a></nav>
<div class="topbar-actions"><a class="preview-pill" href="/access">Private preview · v0.8.4</a><button data-wire-theme-toggle class="theme-button" aria-label="Toggle color theme" title="Toggle color theme">◐</button></div>
</header>
<div class="mobile-doc-nav"><details><summary>Browse documentation</summary><nav><a href="/getting-started">Get started</a><a href="/packages">Packages</a><a href="https://component.wrnexusjs.dev/">Components</a><a href="/language">Language</a><a href="/architecture">Architecture</a><a href="/tutorial">Tutorial</a><a href="/guides/project-structure">Guides</a><a href="/examples">Examples</a><a href="/search">Search</a></nav></details></div>
<main class="portal-main docs-layout">
<article id="main" class="documentation prose standalone package-document"><nav class="breadcrumbs" aria-label="Breadcrumb"><a href="/">Home</a><span>/</span><a href="/packages">Packages</a><span>/</span><span aria-current="page">@wrnexus/pwa</span></nav><section class="doc-intro"><span class="eyebrow">Frontend · Package reference</span><h1>@wrnexus/pwa</h1><p>Progressive Web App manifests, service workers, and offline strategies.</p><div class="doc-meta"><span>v0.8.4</span><span>Private registry</span><span>Frontend</span></div><section id="access" class="access-callout"><h2>Install the package</h2><p>After WorkRoot approves private registry access, install the release-aligned package:</p><pre><code>bun add @wrnexus/pwa@0.8.4</code><button type="button" class="copy-button" aria-label="Copy installation command">Copy</button></pre><p><a href="/access">Request preview access</a>. Never put registry tokens in source control.</p></section></section><section id="guide"><p>Official PWA primitives for manifests, service workers, offline pages and precaching, runtime caching, background synchronization, push notifications, install/update events, offline mutation stores, and conflict resolution. <code>createOfflineQueue()</code> accepts a durable IndexedDB-style store and retries requests with stable idempotency headers.</p></section><section id="api" class="api"><h2>Complete TypeScript API</h2><p>Generated from the exact installed package declarations.</p><pre data-language="typescript"><code>interface IndexedDbMigration &#123;
version: number;
migrate(db: IDBDatabase, transaction: IDBTransaction): void;
&#125;
declare function openPwaDatabase(name: string, migrations: IndexedDbMigration[], factory?: IDBFactory): Promise&lt;IDBDatabase&gt;;
declare function indexedDbOfflineQueueStore(db: IDBDatabase, storeName?: string): OfflineQueueStore;
declare const offlineQueueMigration: IndexedDbMigration;
interface StoredPushSubscription &#123;
id: string;
userId: string;
endpoint: string;
expirationTime?: number | null;
keys: &#123;
p256dh: string;
auth: string;
&#125;;
createdAt: number;
&#125;
interface PushSubscriptionStore &#123;
put(value: StoredPushSubscription): Promise&lt;void&gt;;
remove(id: string): Promise&lt;void&gt;;
list(userId: string): Promise&lt;StoredPushSubscription[]&gt;;
&#125;
declare function memoryPushSubscriptionStore(): PushSubscriptionStore;
interface PushSqlClient &#123;
query&lt;T = Record&lt;string, unknown&gt;&gt;(sql: string, parameters?: unknown[]): Promise&lt;&#123;
rows: T[];
&#125;&gt;;
&#125;
declare function postgresPushSubscriptionStore(db: PushSqlClient): PushSubscriptionStore;
declare const POSTGRES_PUSH_SUBSCRIPTION_SCHEMA = &quot;CREATE TABLE IF NOT EXISTS wrnexus_push_subscriptions (id text PRIMARY KEY,user_id text NOT NULL,endpoint text NOT NULL,expiration_time bigint,p256dh text NOT NULL,auth text NOT NULL,created_at bigint NOT NULL); CREATE INDEX IF NOT EXISTS wrnexus_push_user ON wrnexus_push_subscriptions (user_id);&quot;;
declare function createPushSubscriptionService(store: PushSubscriptionStore, options?: &#123;
now?: () =&gt; number;
maxPerUser?: number;
&#125;): &#123;
subscribe(userId: string, value: &#123;
endpoint: string;
expirationTime?: number | null;
keys: &#123;
p256dh: string;
auth: string;
&#125;;
&#125;): Promise&lt;&#123;
keys: &#123;
p256dh: string;
auth: string;
&#125;;
createdAt: number;
endpoint: string;
expirationTime?: number | null;
id: string;
userId: string;
&#125;&gt;;
unsubscribe: (id: string) =&gt; Promise&lt;void&gt;;
list: (userId: string) =&gt; Promise&lt;StoredPushSubscription[]&gt;;
&#125;;
declare function renderOfflineQueueReview(items: OfflineMutation[], conflicts?: Array&lt;&#123;
id: string;
message: string;
&#125;&gt;): string;
declare const PWA_REVIEW_RUNTIME = &quot;document.addEventListener(\&quot;click\&quot;,event=&gt;&#123;const button=event.target.closest(\&quot;[data-pwa-retry],[data-pwa-remove],[data-pwa-client],[data-pwa-server]\&quot;);if(!button)return;const action=button.hasAttribute(\&quot;data-pwa-retry\&quot;)?\&quot;retry\&quot;:button.hasAttribute(\&quot;data-pwa-remove\&quot;)?\&quot;remove\&quot;:button.hasAttribute(\&quot;data-pwa-client\&quot;)?\&quot;client\&quot;:\&quot;server\&quot;;const id=button.getAttribute(\&quot;data-pwa-\&quot;+action);dispatchEvent(new CustomEvent(\&quot;wrnexus:pwa-review\&quot;,&#123;detail:&#123;action,id&#125;&#125;))&#125;);&quot;;
type RuntimeCacheStrategy = &quot;network-first&quot; | &quot;cache-first&quot; | &quot;stale-while-revalidate&quot;;
interface RuntimeCacheRule &#123;
pattern: string;
strategy: RuntimeCacheStrategy;
cacheName?: string;
methods?: string[];
&#125;
interface ServiceWorkerOptions &#123;
cacheName?: string;
offlineUrl?: string;
startUrl?: string;
cacheUrls?: string[];
runtimeCaching?: RuntimeCacheRule[];
backgroundSyncTag?: string;
&#125;
interface WebManifestOptions &#123;
name: string;
shortName?: string;
description?: string;
id?: string;
startUrl?: string;
scope?: string;
display?: &quot;standalone&quot; | &quot;fullscreen&quot; | &quot;minimal-ui&quot; | &quot;browser&quot;;
themeColor?: string;
backgroundColor?: string;
icons?: Array&lt;&#123;
src: string;
sizes: string;
type?: string;
purpose?: string;
&#125;&gt;;
shortcuts?: unknown[];
screenshots?: unknown[];
categories?: string[];
lang?: string;
&#125;
declare function createWebManifest(options: WebManifestOptions): &#123;
id: string;
name: string;
short_name: string;
description: string | undefined;
start_url: string;
scope: string;
display: &quot;standalone&quot; | &quot;fullscreen&quot; | &quot;minimal-ui&quot; | &quot;browser&quot;;
theme_color: string;
background_color: string;
icons: &#123;
src: string;
sizes: string;
type?: string;
purpose?: string;
&#125;[];
shortcuts: unknown[];
screenshots: unknown[];
categories: string[];
lang: string;
&#125;;
declare function generateServiceWorker(options?: ServiceWorkerOptions): string;
interface OfflineMutation&lt;T = unknown&gt; &#123;
id: string;
createdAt: number;
updatedAt: number;
endpoint: string;
method: string;
payload: T;
attempts: number;
&#125;
interface OfflineQueueStore &#123;
list(): Promise&lt;OfflineMutation[]&gt;;
put(item: OfflineMutation): Promise&lt;void&gt;;
remove(id: string): Promise&lt;void&gt;;
&#125;
declare function memoryOfflineQueueStore(): OfflineQueueStore;
type ConflictResolution&lt;T&gt; = &#123;
action: &quot;client&quot; | &quot;server&quot; | &quot;merge&quot;;
value: T;
&#125;;
declare function resolveOfflineConflict&lt;T extends object&gt;(client: T, server: T, strategy?: &quot;client-wins&quot; | &quot;server-wins&quot; | &quot;last-write-wins&quot; | ((client: T, server: T) =&gt; T)): ConflictResolution&lt;T&gt;;
declare function createOfflineQueue(options?: &#123;
store?: OfflineQueueStore;
fetch?: (input: string | URL | Request, init?: RequestInit) =&gt; Promise&lt;Response&gt;;
maxItems?: number;
now?: () =&gt; number;
&#125;): &#123;
enqueue&lt;T&gt;(input: Omit&lt;OfflineMutation&lt;T&gt;, &quot;id&quot; | &quot;createdAt&quot; | &quot;updatedAt&quot; | &quot;attempts&quot;&gt;): Promise&lt;OfflineMutation&lt;T&gt;&gt;;
list: () =&gt; Promise&lt;OfflineMutation&lt;unknown&gt;[]&gt;;
sync(): Promise&lt;&#123;
id: string;
ok: boolean;
status?: number;
&#125;[]&gt;;
remove: (id: string) =&gt; Promise&lt;void&gt;;
&#125;;
declare function pwaClientRuntime(serviceWorkerUrl?: string): string;
declare function subscribeToPush(registration: ServiceWorkerRegistration, publicKey: Uint8Array): Promise&lt;PushSubscription&gt;;
export &#123; type ConflictResolution, type IndexedDbMigration, type OfflineMutation, type OfflineQueueStore, POSTGRES_PUSH_SUBSCRIPTION_SCHEMA, PWA_REVIEW_RUNTIME, type PushSqlClient, type PushSubscriptionStore, type RuntimeCacheRule, type RuntimeCacheStrategy, type ServiceWorkerOptions, type StoredPushSubscription, type WebManifestOptions, createOfflineQueue, createPushSubscriptionService, createWebManifest, generateServiceWorker, indexedDbOfflineQueueStore, memoryOfflineQueueStore, memoryPushSubscriptionStore, offlineQueueMigration, openPwaDatabase, postgresPushSubscriptionStore, pwaClientRuntime, renderOfflineQueueReview, resolveOfflineConflict, subscribeToPush &#125;;
</code></pre></section><section id="examples" class="examples"><h2>Examples</h2><p>Copy-ready examples from the installed package documentation.</p><div class="example-grid"><article class="example-card"><h3>Install @wrnexus/pwa</h3><pre data-language="sh"><code>bun add @wrnexus/pwa</code></pre></article><article class="example-card"><h3>Import @wrnexus/pwa</h3><pre data-language="ts"><code>import * as pwa from &quot;@wrnexus/pwa&quot;;</code></pre></article></div></section></article>
<aside class="on-this-page"><h2>On this page</h2><nav><a class="toc-level-2" href="#guide">Guide</a><a class="toc-level-2" href="#api">Complete API</a><a class="toc-level-2" href="#examples">Examples</a></nav></aside>
</main>
<footer><div class="footer-brand"><span class="footer-mark" aria-hidden="true">W</span><p><strong>WRNexusJS 0.8.4</strong><span>Complete API documentation generated from installed package declarations.</span></p></div><nav aria-label="Footer"><a href="/packages">All packages</a><a href="/getting-started">Get started</a><a href="/security">Security</a><a href="/support">Support</a><a href="/llms.txt">AI guide</a></nav><p class="footer-meta">Private Developer Preview · Bun-native</p></footer>
</div>
}
}