@lls/offline 24.29.0-d24e9b32 → 24.29.0-d42e4822

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.
@@ -468,7 +468,7 @@ var onlineFirst = async (request, event) => {
468
468
  const responseFromCache = await tryOffline(request, event);
469
469
  if (!responseFromCache) {
470
470
  return new Response(
471
- `FAILED onlineFirst fetch ${e && typeof e === "object" && "message" in e ? e.message : e?.toString?.()} | ${event.request.url}`,
471
+ `FAILED fetch ${e && typeof e === "object" && "message" in e ? e.message : e?.toString?.()}`,
472
472
  {
473
473
  // @ts-ignore: poor ts typing
474
474
  ok: false,
@@ -493,18 +493,15 @@ swSelf.addEventListener("fetch", (ev) => {
493
493
  }
494
494
  return;
495
495
  }
496
- if (/api(-dev|-preprod)?\.lelivrescolaire\.fr\/?$/.test(url) && ev.request.method === "HEAD") {
497
- return;
498
- }
499
- if (/http:\/\/(localhost|127\.0\.0\.1):\d+/.test(url)) {
500
- return;
501
- }
502
496
  if (!mimeType && !isValidScreenCall) {
503
497
  if (!/\.(css|tsx?|[mj]sx?|woff2|wasm|fr|(web)?manifest)(\??|$)|@(vite|react|id)|(:6019\/?$)/.test(url)) {
504
498
  console.debug("no ext", extension || url);
505
499
  }
506
500
  return ev.respondWith(onlineFirst(ev.request, ev));
507
501
  }
502
+ if (/http:\/\/localhost:\d+\/(favicon\.svg|assets\/)/.test(url)) {
503
+ return;
504
+ }
508
505
  const entryId = knownLinks.get(url.replace(/https:\/\/.*?\//, "")) || knownLinks.get(`medias/${url.replace(/https:\/\/.*?\//, "")}`);
509
506
  if (isValidScreenCall) {
510
507
  return ev.respondWith(fetchScreenCall(ev, { offlineWorkerSync, knownLinks }));
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ declare module "@lls/offline"
package/lib/index.js CHANGED
@@ -1,6 +1,3 @@
1
- // src/hooks/useOfflineWorker.ts
2
- import { useCallback, useEffect, useState } from "react";
3
-
4
1
  // src/utils/error.ts
5
2
  var tryCatch = (fn) => {
6
3
  return (resolve, reject) => {
@@ -106,6 +103,7 @@ var combineHandlers = (...handlers) => {
106
103
  var clearCache = async (mode) => caches.delete(`LLS_OFFLINE_${mode}`);
107
104
 
108
105
  // src/hooks/useOfflineWorker.ts
106
+ import { useCallback, useEffect, useState } from "react";
109
107
  var offlineWorker = new Worker("/src/worker/offline-worker.js", { type: "module" });
110
108
  var { handler, ...offlineWorkerSync } = makeSyncWorker(
111
109
  offlineWorker,
@@ -200,9 +198,7 @@ var useOfflineWorker_default = ({
200
198
  checkUpdates,
201
199
  confEnv
202
200
  });
203
- if (process.env.DESKTOP_FLOWER_OFFLINE !== "1") {
204
- fetch(window.location.href.replace(window.location.search, ""));
205
- }
201
+ fetch(window.location.href.replace(window.location.search, ""));
206
202
  setReady(true);
207
203
  };
208
204
  fn();
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@lls/offline",
3
- "version": "24.29.0-d24e9b32",
3
+ "version": "24.29.0-d42e4822",
4
4
  "description": "offline",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
7
7
  "types": "./lib/builttypes/offline/src/index.d.ts",
8
8
  "exports": {
9
- "import": "./lib/index.js",
10
- "types": "./lib/builttypes/offline/src/index.d.ts"
9
+ ".": "./lib/index.js"
11
10
  },
12
11
  "files": [
13
12
  "lib/",
@@ -54,7 +53,7 @@
54
53
  "vite": "7.0.7",
55
54
  "vite-tsconfig-paths": "5.1.4",
56
55
  "zod": "3.25.50",
57
- "@lls/vitescripts": "24.29.0-d24e9b32"
56
+ "@lls/vitescripts": "24.29.0-d42e4822"
58
57
  },
59
58
  "dependencies": {
60
59
  "redux-persist": "6.0.0"
@@ -68,8 +67,5 @@
68
67
  "test": "bun test --bail __tests__/unit __tests__/e2e",
69
68
  "lint": "pnpm biome check --apply src __tests__ stories",
70
69
  "precommit": "pnpm lint"
71
- },
72
- "imports": {
73
- "#offline/*": "./lib/builttypes/offline/src/*.d.ts"
74
70
  }
75
71
  }
@@ -1,33 +0,0 @@
1
- type UseOfflineProps = {
2
- skipLoadBooks?: boolean;
3
- primaryOnly?: boolean;
4
- nativeReadFile?: (arg: {
5
- fname: string;
6
- }) => Promise<ArrayBuffer>;
7
- nativeWriteFile?: (arg: {
8
- fname: string;
9
- buffer: ArrayBuffer;
10
- }) => Promise<void>;
11
- nativeListZips?: () => Promise<Array<{
12
- name: string;
13
- }>>;
14
- checkUpdates?: boolean;
15
- storage?: 'opfs' | 'native' | 'cache';
16
- zipBaseUrl?: string;
17
- confEnv?: 'development' | 'production';
18
- };
19
- declare const _default: ({ skipLoadBooks, primaryOnly, nativeReadFile, nativeWriteFile, nativeListZips, checkUpdates, storage, zipBaseUrl, confEnv }?: UseOfflineProps) => {
20
- ready: boolean;
21
- loadBook: ({ forceRefresh, ...idOrUri }: {
22
- forceRefresh?: boolean;
23
- } & ({
24
- id: number;
25
- } | {
26
- uri: string;
27
- }), cbk?: (arg: {
28
- bytes: number;
29
- total: number;
30
- }) => void) => Promise<void>;
31
- reset: () => Promise<void>;
32
- };
33
- export default _default;
@@ -1,3 +0,0 @@
1
- export { default as useOfflineWorker } from '#offline/hooks/useOfflineWorker';
2
- export * from '#offline/store/index';
3
- export * from '#offline/store/offlinePersist';
@@ -1,3 +0,0 @@
1
- import type { AnyFunction } from '@lls/typings/utils';
2
- import type { Reducer } from 'redux';
3
- export declare const persistEntitiesReducer: (entitiesReducer: AnyFunction, CONF_ENV: string) => Reducer;
@@ -1,8 +0,0 @@
1
- import { persistStore } from 'redux-persist';
2
- type Store = Parameters<typeof persistStore>[0];
3
- import { type ReactNode } from 'react';
4
- export declare const OfflinePersist: ({ store, children }: {
5
- store: Store;
6
- children: ReactNode;
7
- }) => import("react/jsx-runtime").JSX.Element;
8
- export {};
@@ -1,2 +0,0 @@
1
- import type { AnyFunction } from '@lls/typings/utils';
2
- export declare const tryCatch: (fn: (...args: any[]) => Promise<unknown>) => (resolve: AnyFunction, reject: AnyFunction) => void | Promise<void>;
@@ -1,5 +0,0 @@
1
- export declare const parseRange: (range: string, size: number) => {
2
- start: number;
3
- end: number;
4
- chunkSize: number;
5
- };
@@ -1,29 +0,0 @@
1
- import type { AnyFunction } from '@lls/typings/utils';
2
- type OnMessageEvent = (m: MessageEvent) => void;
3
- type Handler = {
4
- canHandle: (methodName: string) => boolean;
5
- handle: OnMessageEvent;
6
- };
7
- export declare const makeSyncWorker: <WorkerApi extends {
8
- [k: string]: AnyFunction;
9
- }>(offlineWorker: {
10
- postMessage: Worker["postMessage"];
11
- }, methodNames: string[], dbg?: string) => WorkerApi & {
12
- on: (key: string, fn: AnyFunction) => void;
13
- } & {
14
- handler: Handler;
15
- };
16
- export declare const makeSyncHandler: (services: {
17
- [k: string]: (...args: any[]) => any;
18
- }) => {
19
- canHandle: (methodName: string) => boolean;
20
- handle: OnMessageEvent;
21
- };
22
- export declare const bufToJson: (buf: ArrayBuffer) => any;
23
- export declare const jsonToBuf: (json: {}) => Uint8Array<ArrayBuffer>;
24
- export declare const combineHandlers: (...handlers: Handler[]) => (message: MessageEvent) => void;
25
- export declare const openCache: (mode: string) => Promise<Cache>;
26
- export declare const clearCache: (mode: string) => Promise<boolean>;
27
- export declare const isValidZipName: (name: string) => boolean;
28
- export declare const isValidS3Zip: (response: Response) => boolean;
29
- export {};
@@ -1,7 +0,0 @@
1
- type Record = {
2
- sofh: number;
3
- name: Uint8Array;
4
- };
5
- export declare const readRecordData: (buf: Uint8Array, { sofh }: Record) => Uint8Array<ArrayBuffer>;
6
- export declare const getHeaders: (buf: Uint8Array) => Record[];
7
- export {};
@@ -1,16 +0,0 @@
1
- import { setKnownLinks as handleSetKnownLinks } from '#offline/worker/swFetchScreenCall.ts';
2
- declare const setKnownLinks: (arg: Parameters<typeof handleSetKnownLinks>[1]) => void;
3
- export type FetchWorkerSync = {
4
- setKnownLinks: typeof setKnownLinks;
5
- };
6
- declare const configure: ({ storage, confEnv }?: {
7
- storage?: "native" | "opfs" | "cache";
8
- confEnv?: "development" | "production";
9
- }) => void;
10
- export type FetchWorkerMain = {
11
- initChannel: (d: {
12
- ports: [MessagePort];
13
- }) => void;
14
- configure: typeof configure;
15
- };
16
- export {};
@@ -1,67 +0,0 @@
1
- import type { EntryId } from './types.js';
2
- import { searchBooks } from './wwApi.js';
3
- import { readZipEntry } from './wwZip.js';
4
- declare const slugToFileMeta: ({ slug }: {
5
- slug: string;
6
- }) => Promise<{
7
- pageId: number | undefined;
8
- chapterId: number | undefined;
9
- }>;
10
- type BookId = number | string;
11
- declare const loadBook: ({ id: bookId, forceRefresh }: {
12
- id: BookId;
13
- forceRefresh?: boolean;
14
- }) => Promise<void>;
15
- declare const loadPageContent: ({ bookId: iBookId, chapterId, pageId, entryId }: {
16
- bookId?: number;
17
- chapterId?: number;
18
- pageId?: number;
19
- entryId?: EntryId;
20
- }) => Promise<{
21
- viewer: {
22
- pages: {
23
- hits: [{
24
- id: number;
25
- book: {
26
- slug: string;
27
- urlLite: string;
28
- };
29
- chapter: {
30
- id: number;
31
- };
32
- }];
33
- };
34
- };
35
- }>;
36
- declare const ensureAppReady: () => void;
37
- export type OfflineWorkerSync = {
38
- readZipEntry: typeof readZipEntry;
39
- loadBook: typeof loadBook;
40
- slugToFileMeta: typeof slugToFileMeta;
41
- loadPageContent: typeof loadPageContent;
42
- searchBooks: typeof searchBooks;
43
- ensureAppReady: typeof ensureAppReady;
44
- };
45
- declare const loadBooks: ({ primaryOnly }?: {
46
- primaryOnly?: boolean | undefined;
47
- }) => Promise<void>;
48
- declare const configure: ({ storage, checkUpdates, zipBaseUrl, confEnv }: {
49
- storage?: "native" | "opfs" | "cache";
50
- checkUpdates?: boolean;
51
- zipBaseUrl?: string;
52
- confEnv?: "development" | "production";
53
- }) => void;
54
- declare const loadPreload: () => Promise<void>;
55
- declare const reset: () => Promise<void>;
56
- export type OfflineWorkerSyncMain = {
57
- initChannel: (d: {
58
- ports: [MessagePort];
59
- }) => void;
60
- loadPreload: typeof loadPreload;
61
- readZipEntry: typeof readZipEntry;
62
- loadBooks: typeof loadBooks;
63
- loadBook: typeof loadBook;
64
- configure: typeof configure;
65
- reset: typeof reset;
66
- };
67
- export {};
@@ -1,14 +0,0 @@
1
- import type { OfflineWorkerSync } from './offline-worker';
2
- import type { EntryId, SwEvent } from './types';
3
- export declare const canHandleScreenCall: (url: string) => boolean;
4
- export declare const handleScreenCall: (ev: SwEvent, { offlineWorkerSync, knownLinks }: {
5
- offlineWorkerSync: OfflineWorkerSync;
6
- knownLinks: Map<string, EntryId>;
7
- }) => Promise<{
8
- status: number;
9
- json: any;
10
- }>;
11
- export declare const setKnownLinks: (knownLinks: Map<string, EntryId>, { entryNames, bookId }: {
12
- entryNames: string[];
13
- bookId: number | string;
14
- }) => void;
@@ -1,58 +0,0 @@
1
- type Book = {
2
- id: number;
3
- chapters: {
4
- id: number;
5
- }[];
6
- uri: string;
7
- slug: string;
8
- urlLite: string;
9
- };
10
- type Page = {
11
- id: number;
12
- book: {
13
- slug: string;
14
- urlLite: string;
15
- };
16
- chapter: {
17
- id: number;
18
- };
19
- };
20
- type GqlBook = {
21
- viewer: {
22
- books: {
23
- hits: [Book];
24
- };
25
- };
26
- };
27
- type GqlPage = {
28
- viewer: {
29
- pages: {
30
- hits: [Page];
31
- };
32
- };
33
- };
34
- export declare const loadBook: (json: GqlBook) => void;
35
- type SlugFile = {
36
- [pageId: string]: `${number};${number}`;
37
- };
38
- export declare const slugToFileMeta: ({ slug, json }: {
39
- slug: string;
40
- json: SlugFile;
41
- }) => Promise<{
42
- pageId: number | undefined;
43
- chapterId: number | undefined;
44
- }>;
45
- export declare const loadPageContent: ({ chapterId, json }: {
46
- chapterId?: number;
47
- json: GqlPage;
48
- }) => Promise<GqlPage>;
49
- export declare const searchBooks: ({ uris, slugs, ids, chapterIds }: {
50
- uris?: string[];
51
- slugs?: string[];
52
- ids?: number[];
53
- chapterIds?: (number | undefined)[];
54
- }) => Promise<(Omit<Book, "chapters"> & {
55
- chapters: number[];
56
- })[]>;
57
- export declare const loadPreload: (json: GqlBook) => void;
58
- export {};
@@ -1,9 +0,0 @@
1
- type BookId = number | string;
2
- export declare const readZipEntry: ({ bookId, entryName, asJson }: {
3
- bookId: number | string;
4
- entryName: string;
5
- asJson?: boolean;
6
- }) => Promise<any>;
7
- export declare const hasZip: (bookId: BookId | string) => boolean;
8
- export declare const loadZip: (buf: Uint8Array, bookId: BookId) => Promise<string[]>;
9
- export {};