@lls/offline 24.22.0-dee67770 → 24.22.0-ebe52096

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.
@@ -19,7 +19,7 @@ var makeSyncWorker = (offlineWorker2, methodNames, dbg) => {
19
19
  const makeFn = (methodName) => {
20
20
  return ({ ports, ...arg } = {}) => {
21
21
  return new Promise((resolve, reject) => {
22
- const eventId = `${methodName}:${Date.now()}-${Math.random().toFixed(5)}`;
22
+ const eventId = `${methodName}:${Date.now()}`;
23
23
  dic[eventId] = { resolve, reject };
24
24
  offlineWorker2.postMessage({ eventId, methodName, arg }, ports);
25
25
  });
@@ -62,7 +62,7 @@ var makeSyncHandler = a(
62
62
  })
63
63
  );
64
64
  var jsonToBuf = (json) => new TextEncoder().encode(JSON.stringify(json));
65
- var openCache = async (mode) => caches.open(`LLS_OFFLINE_${mode}`);
65
+ var openCache = async () => caches.open(`LLS_OFFLINE_${process.env.CONF_ENV}`);
66
66
 
67
67
  // src/worker/swFetchScreenCall.ts
68
68
  var zipSlugName = (str) => str.replace(/[^a-zA-Z0-9-.]/g, "");
@@ -75,15 +75,6 @@ var cocoreFetchPartialPageScreen = async (_ev, { offlineWorkerSync: offlineWorke
75
75
  const gqlPage = await offlineWorkerSync2.loadPageContent({ entryId });
76
76
  return { data: gqlPage };
77
77
  };
78
- var cocoreFetchBookScreen = async (_ev, { offlineWorkerSync: offlineWorkerSync2, variables, knownLinks: knownLinks2 }) => {
79
- const key = `gqls/${zipSlugName(variables.uris[0] || "")}.json`;
80
- const entryId = knownLinks2.get(key);
81
- if (!entryId) {
82
- throw new Error(`uri not found ${key}`);
83
- }
84
- const gqlBook = await offlineWorkerSync2.loadPageContent({ entryId });
85
- return { data: gqlBook };
86
- };
87
78
  var cocoreFetchPartialPageSiblingsScreen = async (_ev) => {
88
79
  return { data: { viewer: {} } };
89
80
  };
@@ -198,7 +189,6 @@ var coreFetchPagesApi = async (ev, { offlineWorkerSync: offlineWorkerSync2, vari
198
189
  };
199
190
  var handles = {
200
191
  coreFetchBookDrawerScreen,
201
- cocoreFetchBookScreen,
202
192
  coreFetchPagesApi,
203
193
  cocoreFetchPartialPageScreen,
204
194
  cocoreFetchPartialPageSiblingsScreen
@@ -230,20 +220,21 @@ var setKnownLinks = (knownLinks2, { entryNames, bookId }) => {
230
220
  };
231
221
 
232
222
  // src/worker/fetch-worker.ts
233
- var STORAGE = "cache";
234
- var CONF_ENV = "development";
235
- var fetchAsset = async (_ev, { entryId, mimeType, offlineWorkerSync: offlineWorkerSync2 }) => {
223
+ var fetchAsset = async (ev, { entryId, mimeType, offlineWorkerSync: offlineWorkerSync2 }) => {
236
224
  try {
237
225
  const buf = await offlineWorkerSync2.readZipEntry(entryId);
226
+ const url = ev.request.url;
238
227
  return new Response(buf, {
239
228
  headers: {
240
229
  "Cache-Control": "max-age=600, s-maxage=600, public, proxy-revalidate",
241
- "Content-Length": buf.byteLength,
242
230
  "Content-Type": mimeType
243
231
  },
244
232
  // @ts-ignore: poor ts typing
233
+ ok: true,
234
+ redirected: false,
245
235
  status: 200,
246
- statusText: "OK"
236
+ type: "cors",
237
+ url
247
238
  });
248
239
  } catch (e) {
249
240
  console.error("FAILED fetchAsset", e);
@@ -251,7 +242,8 @@ var fetchAsset = async (_ev, { entryId, mimeType, offlineWorkerSync: offlineWork
251
242
  // @ts-ignore: poor ts typing
252
243
  ok: false,
253
244
  status: 500,
254
- statusText: e?.toString?.() || "fail fetch"
245
+ type: "cors",
246
+ url: ev.request.url
255
247
  });
256
248
  }
257
249
  };
@@ -294,7 +286,7 @@ var ACCEPTED_EXTENSIONS = {
294
286
  ".webp": "image/webp"
295
287
  };
296
288
  var putInCache = async (request, response) => {
297
- const cache = await openCache(CONF_ENV);
289
+ const cache = await openCache();
298
290
  await cache.put(request, response);
299
291
  };
300
292
  var onlineFirst = async (request, event) => {
@@ -323,6 +315,7 @@ var onlineFirst = async (request, event) => {
323
315
  return responseFromCache;
324
316
  }
325
317
  };
318
+ var STORAGE = "cache";
326
319
  var swSelf = self;
327
320
  swSelf.addEventListener("fetch", (ev) => {
328
321
  const url = ev.request.url;
@@ -369,23 +362,16 @@ var initChannel = async (__, { ports }) => {
369
362
  );
370
363
  offlineWorkerSync = sender;
371
364
  offlineWorker.onmessage = handler.handle;
372
- offlineWorkerSync.on("setKnownLinks", setKnownLinks.bind(null, knownLinks));
365
+ offlineWorkerSync.on("setKnownLinks", setKnownLinks.bind(null, setKnownLinks));
373
366
  offlineWorker.postMessage({ methodName: "sendAppReady" });
374
367
  };
375
368
  var knownLinks = /* @__PURE__ */ new Map();
376
- var configure = ({
377
- storage,
378
- confEnv
379
- } = {}) => {
369
+ var configure = ({ storage } = {}) => {
380
370
  STORAGE = "cache";
381
- CONF_ENV = "development";
382
371
  if (typeof storage !== "undefined") {
383
372
  STORAGE = storage;
384
373
  }
385
- if (typeof confEnv !== "undefined") {
386
- CONF_ENV = confEnv;
387
- }
388
- console.info("sw::configure", { STORAGE, CONF_ENV });
374
+ console.info("sw::configure", { STORAGE });
389
375
  };
390
376
  swSelf.onmessage = async ({
391
377
  data: { methodName, arg } = {},
@@ -30,7 +30,7 @@ var makeSyncWorker = (offlineWorker, methodNames, dbg) => {
30
30
  const makeFn = (methodName) => {
31
31
  return ({ ports, ...arg } = {}) => {
32
32
  return new Promise((resolve, reject) => {
33
- const eventId = `${methodName}:${Date.now()}-${Math.random().toFixed(5)}`;
33
+ const eventId = `${methodName}:${Date.now()}`;
34
34
  dic[eventId] = { resolve, reject };
35
35
  offlineWorker.postMessage({ eventId, methodName, arg }, ports);
36
36
  });
@@ -83,7 +83,7 @@ var combineHandlers = (...handlers) => {
83
83
  console.error("no handlers matched", methodName);
84
84
  };
85
85
  };
86
- var openCache = async (mode) => caches.open(`LLS_OFFLINE_${mode}`);
86
+ var openCache = async () => caches.open(`LLS_OFFLINE_${process.env.CONF_ENV}`);
87
87
 
88
88
  // src/worker/wwApi.ts
89
89
  var STATE = {
@@ -844,7 +844,6 @@ var loadZip = async (buf, bookId) => {
844
844
  var CHECK_UPDATES = true;
845
845
  var STORAGE = "cache";
846
846
  var ZIP_BASE_URL = "https://ci.lls.fr/artefacts/content/development";
847
- var CONF_ENV = "development";
848
847
  var LOADED_BOOKS = /* @__PURE__ */ new Map();
849
848
  var fetchZipFile = async (zipUrl, { forceRefresh } = {}) => {
850
849
  const fileName = zipUrl.split("/").slice(-1)[0];
@@ -924,7 +923,7 @@ var fetchZipFile = async (zipUrl, { forceRefresh } = {}) => {
924
923
  await accessHandle.write(arrayBuffer);
925
924
  await accessHandle.close();
926
925
  } else {
927
- const cache = await openCache(CONF_ENV);
926
+ const cache = await openCache();
928
927
  const response2 = new Response(arrayBuffer, {
929
928
  headers: {
930
929
  "Cache-Control": "max-age=600, s-maxage=600, public, proxy-revalidate",
@@ -1025,11 +1024,9 @@ var loadBooks = async ({ primaryOnly = false } = {}) => {
1025
1024
  const opfsRoot = await navigator.storage.getDirectory();
1026
1025
  entries = await opfsRoot.values();
1027
1026
  } else {
1028
- const cache = await openCache(CONF_ENV);
1027
+ const cache = await openCache();
1029
1028
  const keys = await cache.keys();
1030
- const zips = keys.filter((key2) => {
1031
- return key2.url.match(/lecture-cp\.zip/);
1032
- });
1029
+ const zips = keys.filter((key2) => key2.url.endsWith(".zip"));
1033
1030
  entries = zips.map((zip) => ({ name: String(zip.url.split("/").pop()) }));
1034
1031
  }
1035
1032
  for await (const entry of entries) {
@@ -1052,13 +1049,11 @@ var loadBooks = async ({ primaryOnly = false } = {}) => {
1052
1049
  var configure = ({
1053
1050
  storage,
1054
1051
  checkUpdates,
1055
- zipBaseUrl,
1056
- confEnv
1052
+ zipBaseUrl
1057
1053
  }) => {
1058
1054
  CHECK_UPDATES = true;
1059
1055
  STORAGE = "cache";
1060
1056
  ZIP_BASE_URL = "https://ci.lls.fr/artefacts/content/development";
1061
- CONF_ENV = "development";
1062
1057
  if (typeof storage !== "undefined") {
1063
1058
  STORAGE = storage;
1064
1059
  }
@@ -1068,10 +1063,7 @@ var configure = ({
1068
1063
  if (typeof zipBaseUrl !== "undefined") {
1069
1064
  ZIP_BASE_URL = zipBaseUrl;
1070
1065
  }
1071
- if (typeof confEnv !== "undefined") {
1072
- CONF_ENV = confEnv;
1073
- }
1074
- console.info("ow::configure", { STORAGE, CHECK_UPDATES, ZIP_BASE_URL, CONF_ENV });
1066
+ console.info("ow::configure", { STORAGE, CHECK_UPDATES, ZIP_BASE_URL });
1075
1067
  };
1076
1068
  var loadPreload2 = async () => {
1077
1069
  const zipUrl = "https://lls-ci-fr.s3.eu-west-3.amazonaws.com/artefacts/content/development/preload.zip";
package/lib/index.js CHANGED
@@ -30,7 +30,7 @@ var makeSyncWorker = (offlineWorker2, methodNames, dbg) => {
30
30
  const makeFn = (methodName) => {
31
31
  return ({ ports, ...arg } = {}) => {
32
32
  return new Promise((resolve, reject) => {
33
- const eventId = `${methodName}:${Date.now()}-${Math.random().toFixed(5)}`;
33
+ const eventId = `${methodName}:${Date.now()}`;
34
34
  dic[eventId] = { resolve, reject };
35
35
  offlineWorker2.postMessage({ eventId, methodName, arg }, ports);
36
36
  });
@@ -125,11 +125,10 @@ var installWorker = async ({
125
125
  nativeListZips,
126
126
  storage,
127
127
  zipBaseUrl,
128
- checkUpdates,
129
- confEnv
128
+ checkUpdates
130
129
  } = {}) => {
131
130
  const fetchWorker = await fetchWorkerPromise;
132
- const configureOptions = { storage, zipBaseUrl, checkUpdates, confEnv };
131
+ const configureOptions = { storage, zipBaseUrl, checkUpdates };
133
132
  if (nativeReadFile) {
134
133
  const wwHandler = makeSyncHandler(offlineWorker, { nativeReadFile, nativeWriteFile, nativeListZips });
135
134
  offlineWorker.onmessage = combineHandlers(handler, wwHandler);
@@ -163,8 +162,7 @@ var useOfflineWorker_default = ({
163
162
  nativeListZips,
164
163
  checkUpdates,
165
164
  storage,
166
- zipBaseUrl,
167
- confEnv
165
+ zipBaseUrl
168
166
  } = {}) => {
169
167
  const [ready, setReady] = useState(false);
170
168
  useEffect(() => {
@@ -176,15 +174,14 @@ var useOfflineWorker_default = ({
176
174
  nativeListZips,
177
175
  storage,
178
176
  zipBaseUrl,
179
- checkUpdates,
180
- confEnv
177
+ checkUpdates
181
178
  });
182
179
  await Promise.all([workersReadyPromise, setBooksLoadedPromise]);
183
180
  fetch(window.location.href.replace(window.location.search, ""));
184
181
  setReady(true);
185
182
  };
186
183
  fn();
187
- }, [primaryOnly, nativeReadFile, nativeWriteFile, nativeListZips, storage, zipBaseUrl, checkUpdates, confEnv]);
184
+ }, [primaryOnly, nativeReadFile, nativeWriteFile, nativeListZips, storage, zipBaseUrl, checkUpdates]);
188
185
  const loadBook = useCallback(
189
186
  async ({ id, forceRefresh }, cbk) => {
190
187
  offlineWorkerSync.on("opfsProgress", cbk);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lls/offline",
3
- "version": "24.22.0-dee67770",
3
+ "version": "24.22.0-ebe52096",
4
4
  "description": "offline",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -52,7 +52,7 @@
52
52
  "vite": "7.0.0",
53
53
  "vite-tsconfig-paths": "5.1.4",
54
54
  "zod": "3.25.50",
55
- "@lls/vitescripts": "24.22.0-dee67770"
55
+ "@lls/vitescripts": "24.22.0-ebe52096"
56
56
  },
57
57
  "dependencies": {
58
58
  "fflate": "0.8.2"