tempest-react-sdk 0.7.0 → 0.9.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 +41 -28
- package/bin/create-tempest-app.mjs +141 -70
- package/bin/lib/openapi/generate.mjs +259 -0
- package/bin/lib/openapi/generate.test.mjs +129 -0
- package/bin/lib/openapi/load.mjs +24 -0
- package/bin/lib/openapi/schema-to-zod.mjs +123 -0
- package/bin/lib/openapi/schema-to-zod.test.mjs +81 -0
- package/bin/tempest.mjs +364 -0
- package/dist/sw.cjs +2 -0
- package/dist/sw.cjs.map +1 -0
- package/dist/sw.d.ts +233 -0
- package/dist/sw.js +361 -0
- package/dist/sw.js.map +1 -0
- package/dist/tempest-react-sdk.cjs +3 -3
- package/dist/tempest-react-sdk.cjs.map +1 -1
- package/dist/tempest-react-sdk.d.ts +130 -0
- package/dist/tempest-react-sdk.js +1565 -1646
- package/dist/tempest-react-sdk.js.map +1 -1
- package/dist/vite.cjs +3 -1
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.ts +136 -0
- package/dist/vite.js +253 -34
- package/dist/vite.js.map +1 -1
- package/package.json +10 -2
- package/template/_prettierrc.json +9 -0
- package/template/eslint.config.js +18 -1
- package/template/package.json +7 -1
- package/template-pwa/README.md +64 -0
- package/template-pwa/_env.example +7 -0
- package/template-pwa/index.html +22 -0
- package/template-pwa/package.json +9 -0
- package/template-pwa/public/icon.svg +4 -0
- package/template-pwa/public/manifest.webmanifest +35 -0
- package/template-pwa/src/main.tsx +29 -0
- package/template-pwa/src/pages/Dashboard.tsx +73 -0
- package/template-pwa/src/sw.ts +70 -0
- package/template-pwa/src/vite-env.d.ts +12 -0
- package/template-pwa/vite.config.ts +21 -0
- package/template-pwa/vite.sw.config.ts +27 -0
|
@@ -1259,6 +1259,17 @@ export declare interface CreateLoggerOptions {
|
|
|
1259
1259
|
*/
|
|
1260
1260
|
export declare function createOfflineStore<TItem, TKey extends string | number = string>(config: OfflineStoreConfig<TItem>): OfflineStore<TItem, TKey>;
|
|
1261
1261
|
|
|
1262
|
+
/**
|
|
1263
|
+
* Build a `206 Partial Content` response from a full one for an HTTP `Range`
|
|
1264
|
+
* request. Supports `bytes=start-end`, open-ended `bytes=start-` and suffix
|
|
1265
|
+
* `bytes=-suffixLength`. Returns the original response when there is no usable
|
|
1266
|
+
* `Range` header, or a `416` when the range is unsatisfiable.
|
|
1267
|
+
*
|
|
1268
|
+
* @param request The incoming request (its `Range` header drives the slice).
|
|
1269
|
+
* @param response The full (200) response to slice.
|
|
1270
|
+
*/
|
|
1271
|
+
export declare function createPartialResponse(request: Request, response: Response): Promise<Response>;
|
|
1272
|
+
|
|
1262
1273
|
/**
|
|
1263
1274
|
* Build a [[TelemetryAdapter]] backed by [`posthog-js`](https://posthog.com/docs/libraries/js).
|
|
1264
1275
|
* The PostHog client is supplied by the caller (not bundled).
|
|
@@ -2455,6 +2466,42 @@ export declare interface InputProps extends Omit<InputHTMLAttributes<HTMLInputEl
|
|
|
2455
2466
|
|
|
2456
2467
|
export declare type InputSize = "sm" | "md" | "lg";
|
|
2457
2468
|
|
|
2469
|
+
/**
|
|
2470
|
+
* Install the background-sync queue: on a failed mutating request, the request
|
|
2471
|
+
* is serialized to IndexedDB and a sync is registered; the original fetch still
|
|
2472
|
+
* rejects (so your app can show an offline state), and the request is replayed
|
|
2473
|
+
* later when the network returns.
|
|
2474
|
+
*/
|
|
2475
|
+
export declare function installBackgroundSync(options?: InstallBackgroundSyncOptions): void;
|
|
2476
|
+
|
|
2477
|
+
/**
|
|
2478
|
+
* Background-sync helper: queue failed mutating requests (POST/PUT/PATCH/DELETE)
|
|
2479
|
+
* while offline and replay them when connectivity returns. A dependency-free
|
|
2480
|
+
* take on Workbox's `BackgroundSyncPlugin`, backed by a tiny IndexedDB queue.
|
|
2481
|
+
*
|
|
2482
|
+
* Import inside your `sw.ts`. Uses the Background Sync API (`registration.sync`)
|
|
2483
|
+
* when available, and also replays opportunistically on the next request as a
|
|
2484
|
+
* fallback for browsers without it (e.g. Safari).
|
|
2485
|
+
*
|
|
2486
|
+
* @example
|
|
2487
|
+
* import { installBackgroundSync } from "tempest-react-sdk/sw";
|
|
2488
|
+
*
|
|
2489
|
+
* installBackgroundSync({ match: (url) => url.pathname.startsWith("/api/") });
|
|
2490
|
+
*/
|
|
2491
|
+
/** Options for {@link installBackgroundSync}. */
|
|
2492
|
+
export declare interface InstallBackgroundSyncOptions {
|
|
2493
|
+
/**
|
|
2494
|
+
* Which requests to queue on failure. A `RegExp` against the URL or a
|
|
2495
|
+
* predicate. Only non-`GET` requests are ever considered. Default: all
|
|
2496
|
+
* non-`GET` requests.
|
|
2497
|
+
*/
|
|
2498
|
+
match?: RegExp | ((url: URL, request: Request) => boolean);
|
|
2499
|
+
/** IndexedDB database name, also used as the sync tag. Default `tempest-bg-sync`. */
|
|
2500
|
+
queueName?: string;
|
|
2501
|
+
/** Drop queued requests older than this (minutes) on replay. Default `1440` (24h). */
|
|
2502
|
+
maxRetentionMinutes?: number;
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2458
2505
|
/**
|
|
2459
2506
|
* Install a `notificationclick` handler that focuses an existing client when
|
|
2460
2507
|
* possible and falls back to opening a new window.
|
|
@@ -2466,6 +2513,32 @@ export declare interface InstallNotificationClickHandlerOptions {
|
|
|
2466
2513
|
resolveUrl?: (data: unknown) => string;
|
|
2467
2514
|
}
|
|
2468
2515
|
|
|
2516
|
+
/**
|
|
2517
|
+
* Precache the app shell at `install` and serve it offline:
|
|
2518
|
+
* - reads `precache-manifest.json` (emitted by `tempestPwaManifest()`),
|
|
2519
|
+
* - caches every listed URL under a versioned cache,
|
|
2520
|
+
* - on `activate`, deletes stale precache versions and claims open clients,
|
|
2521
|
+
* - on `fetch`, serves precached assets cache-first and falls back to the
|
|
2522
|
+
* `navigateFallback` document for offline navigations (SPA routing).
|
|
2523
|
+
*
|
|
2524
|
+
* Same-origin only. Register this LAST, after any {@link installRuntimeCache}.
|
|
2525
|
+
*/
|
|
2526
|
+
export declare function installPrecache(options?: InstallPrecacheOptions): void;
|
|
2527
|
+
|
|
2528
|
+
/** Options for {@link installPrecache}. */
|
|
2529
|
+
export declare interface InstallPrecacheOptions {
|
|
2530
|
+
/** URL of the manifest emitted by `tempestPwaManifest()`. Default `/precache-manifest.json`. */
|
|
2531
|
+
manifestUrl?: string;
|
|
2532
|
+
/** Cache name prefix; the manifest `version` is appended. Default `tempest-precache`. */
|
|
2533
|
+
cacheName?: string;
|
|
2534
|
+
/** App-shell document served for navigation requests offline. Default `/index.html`. */
|
|
2535
|
+
navigateFallback?: string;
|
|
2536
|
+
/** Navigation paths that should NOT use the fallback (e.g. `[/^\/api\//]`). */
|
|
2537
|
+
navigateFallbackDenylist?: RegExp[];
|
|
2538
|
+
/** Activate the new worker immediately after precaching. Default `true`. */
|
|
2539
|
+
skipWaiting?: boolean;
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2469
2542
|
/**
|
|
2470
2543
|
* Install a `push` event listener that parses the payload as JSON (with a
|
|
2471
2544
|
* plain-text fallback) and shows a notification.
|
|
@@ -2486,6 +2559,18 @@ export declare interface InstallPushHandlerOptions {
|
|
|
2486
2559
|
transform?: (payload: PushPayload) => PushPayload | null;
|
|
2487
2560
|
}
|
|
2488
2561
|
|
|
2562
|
+
/**
|
|
2563
|
+
* Install a `fetch` handler that resolves matching `GET` requests with the
|
|
2564
|
+
* given runtime strategies. Non-matching requests are left untouched (no
|
|
2565
|
+
* `respondWith`), so a later {@link installPrecache} can handle them.
|
|
2566
|
+
*
|
|
2567
|
+
* Register this BEFORE `installPrecache` so specific routes win over the
|
|
2568
|
+
* precache catch-all.
|
|
2569
|
+
*
|
|
2570
|
+
* @param routes Ordered rules; the first whose `match` passes handles the request.
|
|
2571
|
+
*/
|
|
2572
|
+
export declare function installRuntimeCache(routes: RuntimeRoute[]): void;
|
|
2573
|
+
|
|
2489
2574
|
/**
|
|
2490
2575
|
* Install a `message` listener that activates a waiting worker when the host
|
|
2491
2576
|
* app sends `{ type: "SKIP_WAITING" }`.
|
|
@@ -3635,6 +3720,51 @@ export declare type RouterKind = "browser" | "hash" | "memory";
|
|
|
3635
3720
|
|
|
3636
3721
|
export { Routes }
|
|
3637
3722
|
|
|
3723
|
+
/** A single runtime-caching rule, matched against each `GET` request. */
|
|
3724
|
+
export declare interface RuntimeRoute {
|
|
3725
|
+
/** A `RegExp` tested against the full URL, or a predicate over the parsed URL. */
|
|
3726
|
+
match: RegExp | ((url: URL, request: Request) => boolean);
|
|
3727
|
+
/** How to resolve a match. */
|
|
3728
|
+
strategy: RuntimeStrategy;
|
|
3729
|
+
/** Cache bucket name for this route. */
|
|
3730
|
+
cacheName: string;
|
|
3731
|
+
/** Trim the cache to at most this many entries (FIFO) after each write. */
|
|
3732
|
+
maxEntries?: number;
|
|
3733
|
+
/** Treat a cached response older than this (seconds) as a miss. */
|
|
3734
|
+
maxAgeSeconds?: number;
|
|
3735
|
+
/** For `network-first`: fall back to cache after this timeout (seconds). */
|
|
3736
|
+
networkTimeoutSeconds?: number;
|
|
3737
|
+
/**
|
|
3738
|
+
* Serve HTTP `Range` requests (206 Partial Content) by slicing the cached
|
|
3739
|
+
* full response. Enable for audio/video so seeking works offline. The full
|
|
3740
|
+
* resource is cached once (the `Range` header is stripped before caching).
|
|
3741
|
+
*/
|
|
3742
|
+
rangeRequests?: boolean;
|
|
3743
|
+
}
|
|
3744
|
+
|
|
3745
|
+
/**
|
|
3746
|
+
* Service-worker caching helpers — a small, dependency-free subset of what
|
|
3747
|
+
* Workbox provides: precaching of the build's app shell (so the app launches
|
|
3748
|
+
* offline) plus runtime caching strategies for fonts, APIs and images.
|
|
3749
|
+
*
|
|
3750
|
+
* Import these inside your own `sw.ts`. They run in the service-worker global
|
|
3751
|
+
* scope, not the main thread. Pair `installPrecache` with the
|
|
3752
|
+
* `tempestPwaManifest()` Vite plugin (from `tempest-react-sdk/vite`), which
|
|
3753
|
+
* emits the `precache-manifest.json` this reads at install time.
|
|
3754
|
+
*
|
|
3755
|
+
* @example
|
|
3756
|
+
* /// <reference lib="webworker" />
|
|
3757
|
+
* import { installRuntimeCache, installPrecache } from "tempest-react-sdk/sw";
|
|
3758
|
+
*
|
|
3759
|
+
* // Register specific routes FIRST so they win over the precache catch-all.
|
|
3760
|
+
* installRuntimeCache([
|
|
3761
|
+
* { match: /\/api\//, strategy: "network-first", cacheName: "api", maxAgeSeconds: 300 },
|
|
3762
|
+
* ]);
|
|
3763
|
+
* installPrecache();
|
|
3764
|
+
*/
|
|
3765
|
+
/** Caching strategy for a runtime route. Mirrors the common Workbox trio. */
|
|
3766
|
+
export declare type RuntimeStrategy = "cache-first" | "network-first" | "stale-while-revalidate";
|
|
3767
|
+
|
|
3638
3768
|
/**
|
|
3639
3769
|
* Apply `env(safe-area-inset-*)` padding so content avoids iOS notch /
|
|
3640
3770
|
* Android navbar / device chrome. Wrap the outermost container of pages
|