@julien-lin/universal-pwa-templates 1.1.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 UniversalPWA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # @julien-lin/universal-pwa-templates
2
+
3
+ Templates de manifest, service workers et snippets d’injection adaptés aux cibles (statique, SPA, SSR) et variantes framework (Next/Nuxt, WordPress, Laravel, Symfony).
4
+
package/dist/index.cjs ADDED
@@ -0,0 +1,580 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ determineTemplateType: () => determineTemplateType,
24
+ getAvailableTemplateTypes: () => getAvailableTemplateTypes,
25
+ getServiceWorkerTemplate: () => getServiceWorkerTemplate,
26
+ phpServiceWorkerTemplate: () => phpServiceWorkerTemplate,
27
+ placeholder: () => placeholder,
28
+ spaServiceWorkerTemplate: () => spaServiceWorkerTemplate,
29
+ ssrServiceWorkerTemplate: () => ssrServiceWorkerTemplate,
30
+ staticServiceWorkerTemplate: () => staticServiceWorkerTemplate,
31
+ wordpressServiceWorkerTemplate: () => wordpressServiceWorkerTemplate
32
+ });
33
+ module.exports = __toCommonJS(index_exports);
34
+
35
+ // src/service-worker/static.ts
36
+ var staticServiceWorkerTemplate = `
37
+ import { precacheAndRoute } from 'workbox-precaching'
38
+ import { registerRoute } from 'workbox-routing'
39
+ import { CacheFirst, NetworkFirst } from 'workbox-strategies'
40
+ import { CacheableResponsePlugin } from 'workbox-cacheable-response'
41
+ import { ExpirationPlugin } from 'workbox-expiration'
42
+
43
+ // Precache des assets statiques
44
+ precacheAndRoute(self.__WB_MANIFEST)
45
+
46
+ // CacheFirst pour images, fonts, CSS, JS
47
+ registerRoute(
48
+ ({ request }) => request.destination === 'image',
49
+ new CacheFirst({
50
+ cacheName: 'images-cache',
51
+ plugins: [
52
+ new CacheableResponsePlugin({
53
+ statuses: [0, 200],
54
+ }),
55
+ new ExpirationPlugin({
56
+ maxEntries: 60,
57
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
58
+ }),
59
+ ],
60
+ })
61
+ )
62
+
63
+ registerRoute(
64
+ ({ request }) => request.destination === 'font',
65
+ new CacheFirst({
66
+ cacheName: 'fonts-cache',
67
+ plugins: [
68
+ new CacheableResponsePlugin({
69
+ statuses: [0, 200],
70
+ }),
71
+ new ExpirationPlugin({
72
+ maxEntries: 30,
73
+ maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
74
+ }),
75
+ ],
76
+ })
77
+ )
78
+
79
+ registerRoute(
80
+ ({ request }) => request.destination === 'style' || request.destination === 'script',
81
+ new CacheFirst({
82
+ cacheName: 'assets-cache',
83
+ plugins: [
84
+ new CacheableResponsePlugin({
85
+ statuses: [0, 200],
86
+ }),
87
+ new ExpirationPlugin({
88
+ maxEntries: 50,
89
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
90
+ }),
91
+ ],
92
+ })
93
+ )
94
+
95
+ // NetworkFirst pour les pages HTML
96
+ registerRoute(
97
+ ({ request }) => request.mode === 'navigate',
98
+ new NetworkFirst({
99
+ cacheName: 'pages-cache',
100
+ plugins: [
101
+ new CacheableResponsePlugin({
102
+ statuses: [0, 200],
103
+ }),
104
+ new ExpirationPlugin({
105
+ maxEntries: 50,
106
+ maxAgeSeconds: 24 * 60 * 60, // 24 heures
107
+ }),
108
+ ],
109
+ })
110
+ )
111
+ `;
112
+
113
+ // src/service-worker/spa.ts
114
+ var spaServiceWorkerTemplate = `
115
+ import { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching'
116
+ import { registerRoute, NavigationRoute } from 'workbox-routing'
117
+ import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'
118
+ import { CacheableResponsePlugin } from 'workbox-cacheable-response'
119
+ import { ExpirationPlugin } from 'workbox-expiration'
120
+
121
+ // Precache des assets statiques
122
+ precacheAndRoute(self.__WB_MANIFEST)
123
+
124
+ // Navigation route pour SPA (toutes les navigations vers index.html)
125
+ const navigationHandler = createHandlerBoundToURL('/index.html')
126
+ const navigationRoute = new NavigationRoute(navigationHandler, {
127
+ allowlist: [/^\\//],
128
+ denylist: [/^\\/api/, /^\\/_/],
129
+ })
130
+ registerRoute(navigationRoute)
131
+
132
+ // CacheFirst pour images, fonts
133
+ registerRoute(
134
+ ({ request }) => request.destination === 'image',
135
+ new CacheFirst({
136
+ cacheName: 'images-cache',
137
+ plugins: [
138
+ new CacheableResponsePlugin({
139
+ statuses: [0, 200],
140
+ }),
141
+ new ExpirationPlugin({
142
+ maxEntries: 60,
143
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
144
+ }),
145
+ ],
146
+ })
147
+ )
148
+
149
+ registerRoute(
150
+ ({ request }) => request.destination === 'font',
151
+ new CacheFirst({
152
+ cacheName: 'fonts-cache',
153
+ plugins: [
154
+ new CacheableResponsePlugin({
155
+ statuses: [0, 200],
156
+ }),
157
+ new ExpirationPlugin({
158
+ maxEntries: 30,
159
+ maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
160
+ }),
161
+ ],
162
+ })
163
+ )
164
+
165
+ // StaleWhileRevalidate pour CSS/JS (mise \xE0 jour en arri\xE8re-plan)
166
+ registerRoute(
167
+ ({ request }) => request.destination === 'style' || request.destination === 'script',
168
+ new StaleWhileRevalidate({
169
+ cacheName: 'assets-cache',
170
+ plugins: [
171
+ new CacheableResponsePlugin({
172
+ statuses: [0, 200],
173
+ }),
174
+ new ExpirationPlugin({
175
+ maxEntries: 50,
176
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
177
+ }),
178
+ ],
179
+ })
180
+ )
181
+
182
+ // NetworkFirst pour les appels API
183
+ registerRoute(
184
+ ({ url }) => url.pathname.startsWith('/api/'),
185
+ new NetworkFirst({
186
+ cacheName: 'api-cache',
187
+ plugins: [
188
+ new CacheableResponsePlugin({
189
+ statuses: [0, 200],
190
+ }),
191
+ new ExpirationPlugin({
192
+ maxEntries: 50,
193
+ maxAgeSeconds: 5 * 60, // 5 minutes
194
+ }),
195
+ ],
196
+ })
197
+ )
198
+ `;
199
+
200
+ // src/service-worker/ssr.ts
201
+ var ssrServiceWorkerTemplate = `
202
+ import { precacheAndRoute } from 'workbox-precaching'
203
+ import { registerRoute } from 'workbox-routing'
204
+ import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'
205
+ import { CacheableResponsePlugin } from 'workbox-cacheable-response'
206
+ import { ExpirationPlugin } from 'workbox-expiration'
207
+
208
+ // Precache des assets statiques critiques
209
+ precacheAndRoute(self.__WB_MANIFEST)
210
+
211
+ // NetworkFirst pour les pages HTML (priorit\xE9 au serveur pour contenu frais)
212
+ registerRoute(
213
+ ({ request }) => request.mode === 'navigate',
214
+ new NetworkFirst({
215
+ cacheName: 'pages-cache',
216
+ plugins: [
217
+ new CacheableResponsePlugin({
218
+ statuses: [0, 200],
219
+ }),
220
+ new ExpirationPlugin({
221
+ maxEntries: 50,
222
+ maxAgeSeconds: 24 * 60 * 60, // 24 heures
223
+ }),
224
+ ],
225
+ networkTimeoutSeconds: 3, // Timeout de 3 secondes
226
+ })
227
+ )
228
+
229
+ // CacheFirst pour images, fonts
230
+ registerRoute(
231
+ ({ request }) => request.destination === 'image',
232
+ new CacheFirst({
233
+ cacheName: 'images-cache',
234
+ plugins: [
235
+ new CacheableResponsePlugin({
236
+ statuses: [0, 200],
237
+ }),
238
+ new ExpirationPlugin({
239
+ maxEntries: 60,
240
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
241
+ }),
242
+ ],
243
+ })
244
+ )
245
+
246
+ registerRoute(
247
+ ({ request }) => request.destination === 'font',
248
+ new CacheFirst({
249
+ cacheName: 'fonts-cache',
250
+ plugins: [
251
+ new CacheableResponsePlugin({
252
+ statuses: [0, 200],
253
+ }),
254
+ new ExpirationPlugin({
255
+ maxEntries: 30,
256
+ maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
257
+ }),
258
+ ],
259
+ })
260
+ )
261
+
262
+ // StaleWhileRevalidate pour CSS/JS
263
+ registerRoute(
264
+ ({ request }) => request.destination === 'style' || request.destination === 'script',
265
+ new StaleWhileRevalidate({
266
+ cacheName: 'assets-cache',
267
+ plugins: [
268
+ new CacheableResponsePlugin({
269
+ statuses: [0, 200],
270
+ }),
271
+ new ExpirationPlugin({
272
+ maxEntries: 50,
273
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
274
+ }),
275
+ ],
276
+ })
277
+ )
278
+
279
+ // NetworkFirst pour les appels API
280
+ registerRoute(
281
+ ({ url }) => url.pathname.startsWith('/api/') || url.pathname.startsWith('/graphql'),
282
+ new NetworkFirst({
283
+ cacheName: 'api-cache',
284
+ plugins: [
285
+ new CacheableResponsePlugin({
286
+ statuses: [0, 200],
287
+ }),
288
+ new ExpirationPlugin({
289
+ maxEntries: 50,
290
+ maxAgeSeconds: 5 * 60, // 5 minutes
291
+ }),
292
+ ],
293
+ networkTimeoutSeconds: 3,
294
+ })
295
+ )
296
+ `;
297
+
298
+ // src/service-worker/wordpress.ts
299
+ var wordpressServiceWorkerTemplate = `
300
+ import { precacheAndRoute } from 'workbox-precaching'
301
+ import { registerRoute } from 'workbox-routing'
302
+ import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'
303
+ import { CacheableResponsePlugin } from 'workbox-cacheable-response'
304
+ import { ExpirationPlugin } from 'workbox-expiration'
305
+
306
+ // Precache des assets statiques
307
+ precacheAndRoute(self.__WB_MANIFEST)
308
+
309
+ // NetworkFirst pour les pages WordPress (priorit\xE9 au serveur)
310
+ registerRoute(
311
+ ({ request }) => request.mode === 'navigate',
312
+ new NetworkFirst({
313
+ cacheName: 'wp-pages-cache',
314
+ plugins: [
315
+ new CacheableResponsePlugin({
316
+ statuses: [0, 200],
317
+ }),
318
+ new ExpirationPlugin({
319
+ maxEntries: 50,
320
+ maxAgeSeconds: 24 * 60 * 60, // 24 heures
321
+ }),
322
+ ],
323
+ networkTimeoutSeconds: 3,
324
+ })
325
+ )
326
+
327
+ // CacheFirst pour les assets WordPress (wp-content)
328
+ registerRoute(
329
+ ({ url }) => url.pathname.includes('/wp-content/'),
330
+ new CacheFirst({
331
+ cacheName: 'wp-assets-cache',
332
+ plugins: [
333
+ new CacheableResponsePlugin({
334
+ statuses: [0, 200],
335
+ }),
336
+ new ExpirationPlugin({
337
+ maxEntries: 100,
338
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
339
+ }),
340
+ ],
341
+ })
342
+ )
343
+
344
+ // CacheFirst pour images
345
+ registerRoute(
346
+ ({ request }) => request.destination === 'image',
347
+ new CacheFirst({
348
+ cacheName: 'images-cache',
349
+ plugins: [
350
+ new CacheableResponsePlugin({
351
+ statuses: [0, 200],
352
+ }),
353
+ new ExpirationPlugin({
354
+ maxEntries: 60,
355
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
356
+ }),
357
+ ],
358
+ })
359
+ )
360
+
361
+ // CacheFirst pour fonts
362
+ registerRoute(
363
+ ({ request }) => request.destination === 'font',
364
+ new CacheFirst({
365
+ cacheName: 'fonts-cache',
366
+ plugins: [
367
+ new CacheableResponsePlugin({
368
+ statuses: [0, 200],
369
+ }),
370
+ new ExpirationPlugin({
371
+ maxEntries: 30,
372
+ maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
373
+ }),
374
+ ],
375
+ })
376
+ )
377
+
378
+ // StaleWhileRevalidate pour CSS/JS
379
+ registerRoute(
380
+ ({ request }) => request.destination === 'style' || request.destination === 'script',
381
+ new StaleWhileRevalidate({
382
+ cacheName: 'assets-cache',
383
+ plugins: [
384
+ new CacheableResponsePlugin({
385
+ statuses: [0, 200],
386
+ }),
387
+ new ExpirationPlugin({
388
+ maxEntries: 50,
389
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
390
+ }),
391
+ ],
392
+ })
393
+ )
394
+
395
+ // NetworkFirst pour wp-admin et wp-json (API REST WordPress)
396
+ registerRoute(
397
+ ({ url }) => url.pathname.startsWith('/wp-admin/') || url.pathname.startsWith('/wp-json/'),
398
+ new NetworkFirst({
399
+ cacheName: 'wp-api-cache',
400
+ plugins: [
401
+ new CacheableResponsePlugin({
402
+ statuses: [0, 200],
403
+ }),
404
+ new ExpirationPlugin({
405
+ maxEntries: 30,
406
+ maxAgeSeconds: 5 * 60, // 5 minutes
407
+ }),
408
+ ],
409
+ networkTimeoutSeconds: 3,
410
+ })
411
+ )
412
+ `;
413
+
414
+ // src/service-worker/php.ts
415
+ var phpServiceWorkerTemplate = `
416
+ import { precacheAndRoute } from 'workbox-precaching'
417
+ import { registerRoute } from 'workbox-routing'
418
+ import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'
419
+ import { CacheableResponsePlugin } from 'workbox-cacheable-response'
420
+ import { ExpirationPlugin } from 'workbox-expiration'
421
+
422
+ // Precache des assets statiques
423
+ precacheAndRoute(self.__WB_MANIFEST)
424
+
425
+ // NetworkFirst pour les pages PHP (priorit\xE9 au serveur)
426
+ registerRoute(
427
+ ({ request }) => request.mode === 'navigate',
428
+ new NetworkFirst({
429
+ cacheName: 'php-pages-cache',
430
+ plugins: [
431
+ new CacheableResponsePlugin({
432
+ statuses: [0, 200],
433
+ }),
434
+ new ExpirationPlugin({
435
+ maxEntries: 50,
436
+ maxAgeSeconds: 24 * 60 * 60, // 24 heures
437
+ }),
438
+ ],
439
+ networkTimeoutSeconds: 3,
440
+ })
441
+ )
442
+
443
+ // CacheFirst pour les assets publics (build/, public/)
444
+ registerRoute(
445
+ ({ url }) => url.pathname.startsWith('/build/') || url.pathname.startsWith('/public/'),
446
+ new CacheFirst({
447
+ cacheName: 'public-assets-cache',
448
+ plugins: [
449
+ new CacheableResponsePlugin({
450
+ statuses: [0, 200],
451
+ }),
452
+ new ExpirationPlugin({
453
+ maxEntries: 100,
454
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
455
+ }),
456
+ ],
457
+ })
458
+ )
459
+
460
+ // CacheFirst pour images
461
+ registerRoute(
462
+ ({ request }) => request.destination === 'image',
463
+ new CacheFirst({
464
+ cacheName: 'images-cache',
465
+ plugins: [
466
+ new CacheableResponsePlugin({
467
+ statuses: [0, 200],
468
+ }),
469
+ new ExpirationPlugin({
470
+ maxEntries: 60,
471
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
472
+ }),
473
+ ],
474
+ })
475
+ )
476
+
477
+ // CacheFirst pour fonts
478
+ registerRoute(
479
+ ({ request }) => request.destination === 'font',
480
+ new CacheFirst({
481
+ cacheName: 'fonts-cache',
482
+ plugins: [
483
+ new CacheableResponsePlugin({
484
+ statuses: [0, 200],
485
+ }),
486
+ new ExpirationPlugin({
487
+ maxEntries: 30,
488
+ maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
489
+ }),
490
+ ],
491
+ })
492
+ )
493
+
494
+ // StaleWhileRevalidate pour CSS/JS
495
+ registerRoute(
496
+ ({ request }) => request.destination === 'style' || request.destination === 'script',
497
+ new StaleWhileRevalidate({
498
+ cacheName: 'assets-cache',
499
+ plugins: [
500
+ new CacheableResponsePlugin({
501
+ statuses: [0, 200],
502
+ }),
503
+ new ExpirationPlugin({
504
+ maxEntries: 50,
505
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
506
+ }),
507
+ ],
508
+ })
509
+ )
510
+
511
+ // NetworkFirst pour les routes API
512
+ registerRoute(
513
+ ({ url }) => url.pathname.startsWith('/api/') || url.pathname.startsWith('/graphql'),
514
+ new NetworkFirst({
515
+ cacheName: 'api-cache',
516
+ plugins: [
517
+ new CacheableResponsePlugin({
518
+ statuses: [0, 200],
519
+ }),
520
+ new ExpirationPlugin({
521
+ maxEntries: 50,
522
+ maxAgeSeconds: 5 * 60, // 5 minutes
523
+ }),
524
+ ],
525
+ networkTimeoutSeconds: 3,
526
+ })
527
+ )
528
+ `;
529
+
530
+ // src/service-worker/index.ts
531
+ function getServiceWorkerTemplate(type) {
532
+ const templates = {
533
+ static: staticServiceWorkerTemplate,
534
+ spa: spaServiceWorkerTemplate,
535
+ ssr: ssrServiceWorkerTemplate,
536
+ wordpress: wordpressServiceWorkerTemplate,
537
+ php: phpServiceWorkerTemplate
538
+ };
539
+ const content = templates[type];
540
+ if (!content) {
541
+ throw new Error(`Unknown service worker template type: ${type}`);
542
+ }
543
+ return {
544
+ type,
545
+ content: content.trim()
546
+ };
547
+ }
548
+ function getAvailableTemplateTypes() {
549
+ return ["static", "spa", "ssr", "wordpress", "php"];
550
+ }
551
+ function determineTemplateType(architecture, framework) {
552
+ if (framework === "WordPress") {
553
+ return "wordpress";
554
+ }
555
+ if (framework === "Symfony" || framework === "Laravel") {
556
+ return "php";
557
+ }
558
+ if (architecture === "spa") {
559
+ return "spa";
560
+ }
561
+ if (architecture === "ssr") {
562
+ return "ssr";
563
+ }
564
+ return "static";
565
+ }
566
+
567
+ // src/index.ts
568
+ var placeholder = true;
569
+ // Annotate the CommonJS export names for ESM import in node:
570
+ 0 && (module.exports = {
571
+ determineTemplateType,
572
+ getAvailableTemplateTypes,
573
+ getServiceWorkerTemplate,
574
+ phpServiceWorkerTemplate,
575
+ placeholder,
576
+ spaServiceWorkerTemplate,
577
+ ssrServiceWorkerTemplate,
578
+ staticServiceWorkerTemplate,
579
+ wordpressServiceWorkerTemplate
580
+ });
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Template Service Worker pour sites statiques
3
+ * Stratégie : Precache + CacheFirst pour assets
4
+ */
5
+ declare const staticServiceWorkerTemplate = "\nimport { precacheAndRoute } from 'workbox-precaching'\nimport { registerRoute } from 'workbox-routing'\nimport { CacheFirst, NetworkFirst } from 'workbox-strategies'\nimport { CacheableResponsePlugin } from 'workbox-cacheable-response'\nimport { ExpirationPlugin } from 'workbox-expiration'\n\n// Precache des assets statiques\nprecacheAndRoute(self.__WB_MANIFEST)\n\n// CacheFirst pour images, fonts, CSS, JS\nregisterRoute(\n ({ request }) => request.destination === 'image',\n new CacheFirst({\n cacheName: 'images-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 60,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\nregisterRoute(\n ({ request }) => request.destination === 'font',\n new CacheFirst({\n cacheName: 'fonts-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 30,\n maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an\n }),\n ],\n })\n)\n\nregisterRoute(\n ({ request }) => request.destination === 'style' || request.destination === 'script',\n new CacheFirst({\n cacheName: 'assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours\n }),\n ],\n })\n)\n\n// NetworkFirst pour les pages HTML\nregisterRoute(\n ({ request }) => request.mode === 'navigate',\n new NetworkFirst({\n cacheName: 'pages-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 24 * 60 * 60, // 24 heures\n }),\n ],\n })\n)\n";
6
+
7
+ /**
8
+ * Template Service Worker pour SPA (Single Page Application)
9
+ * Stratégie : Precache + NetworkFirst pour navigation + CacheFirst pour assets
10
+ */
11
+ declare const spaServiceWorkerTemplate = "\nimport { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching'\nimport { registerRoute, NavigationRoute } from 'workbox-routing'\nimport { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'\nimport { CacheableResponsePlugin } from 'workbox-cacheable-response'\nimport { ExpirationPlugin } from 'workbox-expiration'\n\n// Precache des assets statiques\nprecacheAndRoute(self.__WB_MANIFEST)\n\n// Navigation route pour SPA (toutes les navigations vers index.html)\nconst navigationHandler = createHandlerBoundToURL('/index.html')\nconst navigationRoute = new NavigationRoute(navigationHandler, {\n allowlist: [/^\\//],\n denylist: [/^\\/api/, /^\\/_/],\n})\nregisterRoute(navigationRoute)\n\n// CacheFirst pour images, fonts\nregisterRoute(\n ({ request }) => request.destination === 'image',\n new CacheFirst({\n cacheName: 'images-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 60,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\nregisterRoute(\n ({ request }) => request.destination === 'font',\n new CacheFirst({\n cacheName: 'fonts-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 30,\n maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an\n }),\n ],\n })\n)\n\n// StaleWhileRevalidate pour CSS/JS (mise \u00E0 jour en arri\u00E8re-plan)\nregisterRoute(\n ({ request }) => request.destination === 'style' || request.destination === 'script',\n new StaleWhileRevalidate({\n cacheName: 'assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours\n }),\n ],\n })\n)\n\n// NetworkFirst pour les appels API\nregisterRoute(\n ({ url }) => url.pathname.startsWith('/api/'),\n new NetworkFirst({\n cacheName: 'api-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 5 * 60, // 5 minutes\n }),\n ],\n })\n)\n";
12
+
13
+ /**
14
+ * Template Service Worker pour SSR (Server-Side Rendered)
15
+ * Stratégie : NetworkFirst pour pages + CacheFirst pour assets
16
+ */
17
+ declare const ssrServiceWorkerTemplate = "\nimport { precacheAndRoute } from 'workbox-precaching'\nimport { registerRoute } from 'workbox-routing'\nimport { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'\nimport { CacheableResponsePlugin } from 'workbox-cacheable-response'\nimport { ExpirationPlugin } from 'workbox-expiration'\n\n// Precache des assets statiques critiques\nprecacheAndRoute(self.__WB_MANIFEST)\n\n// NetworkFirst pour les pages HTML (priorit\u00E9 au serveur pour contenu frais)\nregisterRoute(\n ({ request }) => request.mode === 'navigate',\n new NetworkFirst({\n cacheName: 'pages-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 24 * 60 * 60, // 24 heures\n }),\n ],\n networkTimeoutSeconds: 3, // Timeout de 3 secondes\n })\n)\n\n// CacheFirst pour images, fonts\nregisterRoute(\n ({ request }) => request.destination === 'image',\n new CacheFirst({\n cacheName: 'images-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 60,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\nregisterRoute(\n ({ request }) => request.destination === 'font',\n new CacheFirst({\n cacheName: 'fonts-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 30,\n maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an\n }),\n ],\n })\n)\n\n// StaleWhileRevalidate pour CSS/JS\nregisterRoute(\n ({ request }) => request.destination === 'style' || request.destination === 'script',\n new StaleWhileRevalidate({\n cacheName: 'assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours\n }),\n ],\n })\n)\n\n// NetworkFirst pour les appels API\nregisterRoute(\n ({ url }) => url.pathname.startsWith('/api/') || url.pathname.startsWith('/graphql'),\n new NetworkFirst({\n cacheName: 'api-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 5 * 60, // 5 minutes\n }),\n ],\n networkTimeoutSeconds: 3,\n })\n)\n";
18
+
19
+ /**
20
+ * Template Service Worker pour WordPress
21
+ * Stratégie : NetworkFirst pour pages + CacheFirst pour assets WordPress
22
+ */
23
+ declare const wordpressServiceWorkerTemplate = "\nimport { precacheAndRoute } from 'workbox-precaching'\nimport { registerRoute } from 'workbox-routing'\nimport { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'\nimport { CacheableResponsePlugin } from 'workbox-cacheable-response'\nimport { ExpirationPlugin } from 'workbox-expiration'\n\n// Precache des assets statiques\nprecacheAndRoute(self.__WB_MANIFEST)\n\n// NetworkFirst pour les pages WordPress (priorit\u00E9 au serveur)\nregisterRoute(\n ({ request }) => request.mode === 'navigate',\n new NetworkFirst({\n cacheName: 'wp-pages-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 24 * 60 * 60, // 24 heures\n }),\n ],\n networkTimeoutSeconds: 3,\n })\n)\n\n// CacheFirst pour les assets WordPress (wp-content)\nregisterRoute(\n ({ url }) => url.pathname.includes('/wp-content/'),\n new CacheFirst({\n cacheName: 'wp-assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 100,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\n// CacheFirst pour images\nregisterRoute(\n ({ request }) => request.destination === 'image',\n new CacheFirst({\n cacheName: 'images-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 60,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\n// CacheFirst pour fonts\nregisterRoute(\n ({ request }) => request.destination === 'font',\n new CacheFirst({\n cacheName: 'fonts-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 30,\n maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an\n }),\n ],\n })\n)\n\n// StaleWhileRevalidate pour CSS/JS\nregisterRoute(\n ({ request }) => request.destination === 'style' || request.destination === 'script',\n new StaleWhileRevalidate({\n cacheName: 'assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours\n }),\n ],\n })\n)\n\n// NetworkFirst pour wp-admin et wp-json (API REST WordPress)\nregisterRoute(\n ({ url }) => url.pathname.startsWith('/wp-admin/') || url.pathname.startsWith('/wp-json/'),\n new NetworkFirst({\n cacheName: 'wp-api-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 30,\n maxAgeSeconds: 5 * 60, // 5 minutes\n }),\n ],\n networkTimeoutSeconds: 3,\n })\n)\n";
24
+
25
+ /**
26
+ * Template Service Worker pour Symfony/Laravel
27
+ * Stratégie : NetworkFirst pour pages + CacheFirst pour assets publics
28
+ */
29
+ declare const phpServiceWorkerTemplate = "\nimport { precacheAndRoute } from 'workbox-precaching'\nimport { registerRoute } from 'workbox-routing'\nimport { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'\nimport { CacheableResponsePlugin } from 'workbox-cacheable-response'\nimport { ExpirationPlugin } from 'workbox-expiration'\n\n// Precache des assets statiques\nprecacheAndRoute(self.__WB_MANIFEST)\n\n// NetworkFirst pour les pages PHP (priorit\u00E9 au serveur)\nregisterRoute(\n ({ request }) => request.mode === 'navigate',\n new NetworkFirst({\n cacheName: 'php-pages-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 24 * 60 * 60, // 24 heures\n }),\n ],\n networkTimeoutSeconds: 3,\n })\n)\n\n// CacheFirst pour les assets publics (build/, public/)\nregisterRoute(\n ({ url }) => url.pathname.startsWith('/build/') || url.pathname.startsWith('/public/'),\n new CacheFirst({\n cacheName: 'public-assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 100,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\n// CacheFirst pour images\nregisterRoute(\n ({ request }) => request.destination === 'image',\n new CacheFirst({\n cacheName: 'images-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 60,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\n// CacheFirst pour fonts\nregisterRoute(\n ({ request }) => request.destination === 'font',\n new CacheFirst({\n cacheName: 'fonts-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 30,\n maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an\n }),\n ],\n })\n)\n\n// StaleWhileRevalidate pour CSS/JS\nregisterRoute(\n ({ request }) => request.destination === 'style' || request.destination === 'script',\n new StaleWhileRevalidate({\n cacheName: 'assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours\n }),\n ],\n })\n)\n\n// NetworkFirst pour les routes API\nregisterRoute(\n ({ url }) => url.pathname.startsWith('/api/') || url.pathname.startsWith('/graphql'),\n new NetworkFirst({\n cacheName: 'api-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 5 * 60, // 5 minutes\n }),\n ],\n networkTimeoutSeconds: 3,\n })\n)\n";
30
+
31
+ type ServiceWorkerTemplateType = 'static' | 'spa' | 'ssr' | 'wordpress' | 'php';
32
+ interface ServiceWorkerTemplate {
33
+ type: ServiceWorkerTemplateType;
34
+ content: string;
35
+ }
36
+ /**
37
+ * Récupère le template de service worker selon le type
38
+ */
39
+ declare function getServiceWorkerTemplate(type: ServiceWorkerTemplateType): ServiceWorkerTemplate;
40
+ /**
41
+ * Liste tous les types de templates disponibles
42
+ */
43
+ declare function getAvailableTemplateTypes(): ServiceWorkerTemplateType[];
44
+ /**
45
+ * Détermine le type de template à partir de l'architecture et du framework
46
+ */
47
+ declare function determineTemplateType(architecture: 'spa' | 'ssr' | 'static', framework?: string | null): ServiceWorkerTemplateType;
48
+
49
+ declare const placeholder = true;
50
+
51
+ export { type ServiceWorkerTemplate, type ServiceWorkerTemplateType, determineTemplateType, getAvailableTemplateTypes, getServiceWorkerTemplate, phpServiceWorkerTemplate, placeholder, spaServiceWorkerTemplate, ssrServiceWorkerTemplate, staticServiceWorkerTemplate, wordpressServiceWorkerTemplate };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Template Service Worker pour sites statiques
3
+ * Stratégie : Precache + CacheFirst pour assets
4
+ */
5
+ declare const staticServiceWorkerTemplate = "\nimport { precacheAndRoute } from 'workbox-precaching'\nimport { registerRoute } from 'workbox-routing'\nimport { CacheFirst, NetworkFirst } from 'workbox-strategies'\nimport { CacheableResponsePlugin } from 'workbox-cacheable-response'\nimport { ExpirationPlugin } from 'workbox-expiration'\n\n// Precache des assets statiques\nprecacheAndRoute(self.__WB_MANIFEST)\n\n// CacheFirst pour images, fonts, CSS, JS\nregisterRoute(\n ({ request }) => request.destination === 'image',\n new CacheFirst({\n cacheName: 'images-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 60,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\nregisterRoute(\n ({ request }) => request.destination === 'font',\n new CacheFirst({\n cacheName: 'fonts-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 30,\n maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an\n }),\n ],\n })\n)\n\nregisterRoute(\n ({ request }) => request.destination === 'style' || request.destination === 'script',\n new CacheFirst({\n cacheName: 'assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours\n }),\n ],\n })\n)\n\n// NetworkFirst pour les pages HTML\nregisterRoute(\n ({ request }) => request.mode === 'navigate',\n new NetworkFirst({\n cacheName: 'pages-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 24 * 60 * 60, // 24 heures\n }),\n ],\n })\n)\n";
6
+
7
+ /**
8
+ * Template Service Worker pour SPA (Single Page Application)
9
+ * Stratégie : Precache + NetworkFirst pour navigation + CacheFirst pour assets
10
+ */
11
+ declare const spaServiceWorkerTemplate = "\nimport { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching'\nimport { registerRoute, NavigationRoute } from 'workbox-routing'\nimport { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'\nimport { CacheableResponsePlugin } from 'workbox-cacheable-response'\nimport { ExpirationPlugin } from 'workbox-expiration'\n\n// Precache des assets statiques\nprecacheAndRoute(self.__WB_MANIFEST)\n\n// Navigation route pour SPA (toutes les navigations vers index.html)\nconst navigationHandler = createHandlerBoundToURL('/index.html')\nconst navigationRoute = new NavigationRoute(navigationHandler, {\n allowlist: [/^\\//],\n denylist: [/^\\/api/, /^\\/_/],\n})\nregisterRoute(navigationRoute)\n\n// CacheFirst pour images, fonts\nregisterRoute(\n ({ request }) => request.destination === 'image',\n new CacheFirst({\n cacheName: 'images-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 60,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\nregisterRoute(\n ({ request }) => request.destination === 'font',\n new CacheFirst({\n cacheName: 'fonts-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 30,\n maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an\n }),\n ],\n })\n)\n\n// StaleWhileRevalidate pour CSS/JS (mise \u00E0 jour en arri\u00E8re-plan)\nregisterRoute(\n ({ request }) => request.destination === 'style' || request.destination === 'script',\n new StaleWhileRevalidate({\n cacheName: 'assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours\n }),\n ],\n })\n)\n\n// NetworkFirst pour les appels API\nregisterRoute(\n ({ url }) => url.pathname.startsWith('/api/'),\n new NetworkFirst({\n cacheName: 'api-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 5 * 60, // 5 minutes\n }),\n ],\n })\n)\n";
12
+
13
+ /**
14
+ * Template Service Worker pour SSR (Server-Side Rendered)
15
+ * Stratégie : NetworkFirst pour pages + CacheFirst pour assets
16
+ */
17
+ declare const ssrServiceWorkerTemplate = "\nimport { precacheAndRoute } from 'workbox-precaching'\nimport { registerRoute } from 'workbox-routing'\nimport { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'\nimport { CacheableResponsePlugin } from 'workbox-cacheable-response'\nimport { ExpirationPlugin } from 'workbox-expiration'\n\n// Precache des assets statiques critiques\nprecacheAndRoute(self.__WB_MANIFEST)\n\n// NetworkFirst pour les pages HTML (priorit\u00E9 au serveur pour contenu frais)\nregisterRoute(\n ({ request }) => request.mode === 'navigate',\n new NetworkFirst({\n cacheName: 'pages-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 24 * 60 * 60, // 24 heures\n }),\n ],\n networkTimeoutSeconds: 3, // Timeout de 3 secondes\n })\n)\n\n// CacheFirst pour images, fonts\nregisterRoute(\n ({ request }) => request.destination === 'image',\n new CacheFirst({\n cacheName: 'images-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 60,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\nregisterRoute(\n ({ request }) => request.destination === 'font',\n new CacheFirst({\n cacheName: 'fonts-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 30,\n maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an\n }),\n ],\n })\n)\n\n// StaleWhileRevalidate pour CSS/JS\nregisterRoute(\n ({ request }) => request.destination === 'style' || request.destination === 'script',\n new StaleWhileRevalidate({\n cacheName: 'assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours\n }),\n ],\n })\n)\n\n// NetworkFirst pour les appels API\nregisterRoute(\n ({ url }) => url.pathname.startsWith('/api/') || url.pathname.startsWith('/graphql'),\n new NetworkFirst({\n cacheName: 'api-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 5 * 60, // 5 minutes\n }),\n ],\n networkTimeoutSeconds: 3,\n })\n)\n";
18
+
19
+ /**
20
+ * Template Service Worker pour WordPress
21
+ * Stratégie : NetworkFirst pour pages + CacheFirst pour assets WordPress
22
+ */
23
+ declare const wordpressServiceWorkerTemplate = "\nimport { precacheAndRoute } from 'workbox-precaching'\nimport { registerRoute } from 'workbox-routing'\nimport { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'\nimport { CacheableResponsePlugin } from 'workbox-cacheable-response'\nimport { ExpirationPlugin } from 'workbox-expiration'\n\n// Precache des assets statiques\nprecacheAndRoute(self.__WB_MANIFEST)\n\n// NetworkFirst pour les pages WordPress (priorit\u00E9 au serveur)\nregisterRoute(\n ({ request }) => request.mode === 'navigate',\n new NetworkFirst({\n cacheName: 'wp-pages-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 24 * 60 * 60, // 24 heures\n }),\n ],\n networkTimeoutSeconds: 3,\n })\n)\n\n// CacheFirst pour les assets WordPress (wp-content)\nregisterRoute(\n ({ url }) => url.pathname.includes('/wp-content/'),\n new CacheFirst({\n cacheName: 'wp-assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 100,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\n// CacheFirst pour images\nregisterRoute(\n ({ request }) => request.destination === 'image',\n new CacheFirst({\n cacheName: 'images-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 60,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\n// CacheFirst pour fonts\nregisterRoute(\n ({ request }) => request.destination === 'font',\n new CacheFirst({\n cacheName: 'fonts-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 30,\n maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an\n }),\n ],\n })\n)\n\n// StaleWhileRevalidate pour CSS/JS\nregisterRoute(\n ({ request }) => request.destination === 'style' || request.destination === 'script',\n new StaleWhileRevalidate({\n cacheName: 'assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours\n }),\n ],\n })\n)\n\n// NetworkFirst pour wp-admin et wp-json (API REST WordPress)\nregisterRoute(\n ({ url }) => url.pathname.startsWith('/wp-admin/') || url.pathname.startsWith('/wp-json/'),\n new NetworkFirst({\n cacheName: 'wp-api-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 30,\n maxAgeSeconds: 5 * 60, // 5 minutes\n }),\n ],\n networkTimeoutSeconds: 3,\n })\n)\n";
24
+
25
+ /**
26
+ * Template Service Worker pour Symfony/Laravel
27
+ * Stratégie : NetworkFirst pour pages + CacheFirst pour assets publics
28
+ */
29
+ declare const phpServiceWorkerTemplate = "\nimport { precacheAndRoute } from 'workbox-precaching'\nimport { registerRoute } from 'workbox-routing'\nimport { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'\nimport { CacheableResponsePlugin } from 'workbox-cacheable-response'\nimport { ExpirationPlugin } from 'workbox-expiration'\n\n// Precache des assets statiques\nprecacheAndRoute(self.__WB_MANIFEST)\n\n// NetworkFirst pour les pages PHP (priorit\u00E9 au serveur)\nregisterRoute(\n ({ request }) => request.mode === 'navigate',\n new NetworkFirst({\n cacheName: 'php-pages-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 24 * 60 * 60, // 24 heures\n }),\n ],\n networkTimeoutSeconds: 3,\n })\n)\n\n// CacheFirst pour les assets publics (build/, public/)\nregisterRoute(\n ({ url }) => url.pathname.startsWith('/build/') || url.pathname.startsWith('/public/'),\n new CacheFirst({\n cacheName: 'public-assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 100,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\n// CacheFirst pour images\nregisterRoute(\n ({ request }) => request.destination === 'image',\n new CacheFirst({\n cacheName: 'images-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 60,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours\n }),\n ],\n })\n)\n\n// CacheFirst pour fonts\nregisterRoute(\n ({ request }) => request.destination === 'font',\n new CacheFirst({\n cacheName: 'fonts-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 30,\n maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an\n }),\n ],\n })\n)\n\n// StaleWhileRevalidate pour CSS/JS\nregisterRoute(\n ({ request }) => request.destination === 'style' || request.destination === 'script',\n new StaleWhileRevalidate({\n cacheName: 'assets-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours\n }),\n ],\n })\n)\n\n// NetworkFirst pour les routes API\nregisterRoute(\n ({ url }) => url.pathname.startsWith('/api/') || url.pathname.startsWith('/graphql'),\n new NetworkFirst({\n cacheName: 'api-cache',\n plugins: [\n new CacheableResponsePlugin({\n statuses: [0, 200],\n }),\n new ExpirationPlugin({\n maxEntries: 50,\n maxAgeSeconds: 5 * 60, // 5 minutes\n }),\n ],\n networkTimeoutSeconds: 3,\n })\n)\n";
30
+
31
+ type ServiceWorkerTemplateType = 'static' | 'spa' | 'ssr' | 'wordpress' | 'php';
32
+ interface ServiceWorkerTemplate {
33
+ type: ServiceWorkerTemplateType;
34
+ content: string;
35
+ }
36
+ /**
37
+ * Récupère le template de service worker selon le type
38
+ */
39
+ declare function getServiceWorkerTemplate(type: ServiceWorkerTemplateType): ServiceWorkerTemplate;
40
+ /**
41
+ * Liste tous les types de templates disponibles
42
+ */
43
+ declare function getAvailableTemplateTypes(): ServiceWorkerTemplateType[];
44
+ /**
45
+ * Détermine le type de template à partir de l'architecture et du framework
46
+ */
47
+ declare function determineTemplateType(architecture: 'spa' | 'ssr' | 'static', framework?: string | null): ServiceWorkerTemplateType;
48
+
49
+ declare const placeholder = true;
50
+
51
+ export { type ServiceWorkerTemplate, type ServiceWorkerTemplateType, determineTemplateType, getAvailableTemplateTypes, getServiceWorkerTemplate, phpServiceWorkerTemplate, placeholder, spaServiceWorkerTemplate, ssrServiceWorkerTemplate, staticServiceWorkerTemplate, wordpressServiceWorkerTemplate };
package/dist/index.js ADDED
@@ -0,0 +1,545 @@
1
+ // src/service-worker/static.ts
2
+ var staticServiceWorkerTemplate = `
3
+ import { precacheAndRoute } from 'workbox-precaching'
4
+ import { registerRoute } from 'workbox-routing'
5
+ import { CacheFirst, NetworkFirst } from 'workbox-strategies'
6
+ import { CacheableResponsePlugin } from 'workbox-cacheable-response'
7
+ import { ExpirationPlugin } from 'workbox-expiration'
8
+
9
+ // Precache des assets statiques
10
+ precacheAndRoute(self.__WB_MANIFEST)
11
+
12
+ // CacheFirst pour images, fonts, CSS, JS
13
+ registerRoute(
14
+ ({ request }) => request.destination === 'image',
15
+ new CacheFirst({
16
+ cacheName: 'images-cache',
17
+ plugins: [
18
+ new CacheableResponsePlugin({
19
+ statuses: [0, 200],
20
+ }),
21
+ new ExpirationPlugin({
22
+ maxEntries: 60,
23
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
24
+ }),
25
+ ],
26
+ })
27
+ )
28
+
29
+ registerRoute(
30
+ ({ request }) => request.destination === 'font',
31
+ new CacheFirst({
32
+ cacheName: 'fonts-cache',
33
+ plugins: [
34
+ new CacheableResponsePlugin({
35
+ statuses: [0, 200],
36
+ }),
37
+ new ExpirationPlugin({
38
+ maxEntries: 30,
39
+ maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
40
+ }),
41
+ ],
42
+ })
43
+ )
44
+
45
+ registerRoute(
46
+ ({ request }) => request.destination === 'style' || request.destination === 'script',
47
+ new CacheFirst({
48
+ cacheName: 'assets-cache',
49
+ plugins: [
50
+ new CacheableResponsePlugin({
51
+ statuses: [0, 200],
52
+ }),
53
+ new ExpirationPlugin({
54
+ maxEntries: 50,
55
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
56
+ }),
57
+ ],
58
+ })
59
+ )
60
+
61
+ // NetworkFirst pour les pages HTML
62
+ registerRoute(
63
+ ({ request }) => request.mode === 'navigate',
64
+ new NetworkFirst({
65
+ cacheName: 'pages-cache',
66
+ plugins: [
67
+ new CacheableResponsePlugin({
68
+ statuses: [0, 200],
69
+ }),
70
+ new ExpirationPlugin({
71
+ maxEntries: 50,
72
+ maxAgeSeconds: 24 * 60 * 60, // 24 heures
73
+ }),
74
+ ],
75
+ })
76
+ )
77
+ `;
78
+
79
+ // src/service-worker/spa.ts
80
+ var spaServiceWorkerTemplate = `
81
+ import { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching'
82
+ import { registerRoute, NavigationRoute } from 'workbox-routing'
83
+ import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'
84
+ import { CacheableResponsePlugin } from 'workbox-cacheable-response'
85
+ import { ExpirationPlugin } from 'workbox-expiration'
86
+
87
+ // Precache des assets statiques
88
+ precacheAndRoute(self.__WB_MANIFEST)
89
+
90
+ // Navigation route pour SPA (toutes les navigations vers index.html)
91
+ const navigationHandler = createHandlerBoundToURL('/index.html')
92
+ const navigationRoute = new NavigationRoute(navigationHandler, {
93
+ allowlist: [/^\\//],
94
+ denylist: [/^\\/api/, /^\\/_/],
95
+ })
96
+ registerRoute(navigationRoute)
97
+
98
+ // CacheFirst pour images, fonts
99
+ registerRoute(
100
+ ({ request }) => request.destination === 'image',
101
+ new CacheFirst({
102
+ cacheName: 'images-cache',
103
+ plugins: [
104
+ new CacheableResponsePlugin({
105
+ statuses: [0, 200],
106
+ }),
107
+ new ExpirationPlugin({
108
+ maxEntries: 60,
109
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
110
+ }),
111
+ ],
112
+ })
113
+ )
114
+
115
+ registerRoute(
116
+ ({ request }) => request.destination === 'font',
117
+ new CacheFirst({
118
+ cacheName: 'fonts-cache',
119
+ plugins: [
120
+ new CacheableResponsePlugin({
121
+ statuses: [0, 200],
122
+ }),
123
+ new ExpirationPlugin({
124
+ maxEntries: 30,
125
+ maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
126
+ }),
127
+ ],
128
+ })
129
+ )
130
+
131
+ // StaleWhileRevalidate pour CSS/JS (mise \xE0 jour en arri\xE8re-plan)
132
+ registerRoute(
133
+ ({ request }) => request.destination === 'style' || request.destination === 'script',
134
+ new StaleWhileRevalidate({
135
+ cacheName: 'assets-cache',
136
+ plugins: [
137
+ new CacheableResponsePlugin({
138
+ statuses: [0, 200],
139
+ }),
140
+ new ExpirationPlugin({
141
+ maxEntries: 50,
142
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
143
+ }),
144
+ ],
145
+ })
146
+ )
147
+
148
+ // NetworkFirst pour les appels API
149
+ registerRoute(
150
+ ({ url }) => url.pathname.startsWith('/api/'),
151
+ new NetworkFirst({
152
+ cacheName: 'api-cache',
153
+ plugins: [
154
+ new CacheableResponsePlugin({
155
+ statuses: [0, 200],
156
+ }),
157
+ new ExpirationPlugin({
158
+ maxEntries: 50,
159
+ maxAgeSeconds: 5 * 60, // 5 minutes
160
+ }),
161
+ ],
162
+ })
163
+ )
164
+ `;
165
+
166
+ // src/service-worker/ssr.ts
167
+ var ssrServiceWorkerTemplate = `
168
+ import { precacheAndRoute } from 'workbox-precaching'
169
+ import { registerRoute } from 'workbox-routing'
170
+ import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'
171
+ import { CacheableResponsePlugin } from 'workbox-cacheable-response'
172
+ import { ExpirationPlugin } from 'workbox-expiration'
173
+
174
+ // Precache des assets statiques critiques
175
+ precacheAndRoute(self.__WB_MANIFEST)
176
+
177
+ // NetworkFirst pour les pages HTML (priorit\xE9 au serveur pour contenu frais)
178
+ registerRoute(
179
+ ({ request }) => request.mode === 'navigate',
180
+ new NetworkFirst({
181
+ cacheName: 'pages-cache',
182
+ plugins: [
183
+ new CacheableResponsePlugin({
184
+ statuses: [0, 200],
185
+ }),
186
+ new ExpirationPlugin({
187
+ maxEntries: 50,
188
+ maxAgeSeconds: 24 * 60 * 60, // 24 heures
189
+ }),
190
+ ],
191
+ networkTimeoutSeconds: 3, // Timeout de 3 secondes
192
+ })
193
+ )
194
+
195
+ // CacheFirst pour images, fonts
196
+ registerRoute(
197
+ ({ request }) => request.destination === 'image',
198
+ new CacheFirst({
199
+ cacheName: 'images-cache',
200
+ plugins: [
201
+ new CacheableResponsePlugin({
202
+ statuses: [0, 200],
203
+ }),
204
+ new ExpirationPlugin({
205
+ maxEntries: 60,
206
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
207
+ }),
208
+ ],
209
+ })
210
+ )
211
+
212
+ registerRoute(
213
+ ({ request }) => request.destination === 'font',
214
+ new CacheFirst({
215
+ cacheName: 'fonts-cache',
216
+ plugins: [
217
+ new CacheableResponsePlugin({
218
+ statuses: [0, 200],
219
+ }),
220
+ new ExpirationPlugin({
221
+ maxEntries: 30,
222
+ maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
223
+ }),
224
+ ],
225
+ })
226
+ )
227
+
228
+ // StaleWhileRevalidate pour CSS/JS
229
+ registerRoute(
230
+ ({ request }) => request.destination === 'style' || request.destination === 'script',
231
+ new StaleWhileRevalidate({
232
+ cacheName: 'assets-cache',
233
+ plugins: [
234
+ new CacheableResponsePlugin({
235
+ statuses: [0, 200],
236
+ }),
237
+ new ExpirationPlugin({
238
+ maxEntries: 50,
239
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
240
+ }),
241
+ ],
242
+ })
243
+ )
244
+
245
+ // NetworkFirst pour les appels API
246
+ registerRoute(
247
+ ({ url }) => url.pathname.startsWith('/api/') || url.pathname.startsWith('/graphql'),
248
+ new NetworkFirst({
249
+ cacheName: 'api-cache',
250
+ plugins: [
251
+ new CacheableResponsePlugin({
252
+ statuses: [0, 200],
253
+ }),
254
+ new ExpirationPlugin({
255
+ maxEntries: 50,
256
+ maxAgeSeconds: 5 * 60, // 5 minutes
257
+ }),
258
+ ],
259
+ networkTimeoutSeconds: 3,
260
+ })
261
+ )
262
+ `;
263
+
264
+ // src/service-worker/wordpress.ts
265
+ var wordpressServiceWorkerTemplate = `
266
+ import { precacheAndRoute } from 'workbox-precaching'
267
+ import { registerRoute } from 'workbox-routing'
268
+ import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'
269
+ import { CacheableResponsePlugin } from 'workbox-cacheable-response'
270
+ import { ExpirationPlugin } from 'workbox-expiration'
271
+
272
+ // Precache des assets statiques
273
+ precacheAndRoute(self.__WB_MANIFEST)
274
+
275
+ // NetworkFirst pour les pages WordPress (priorit\xE9 au serveur)
276
+ registerRoute(
277
+ ({ request }) => request.mode === 'navigate',
278
+ new NetworkFirst({
279
+ cacheName: 'wp-pages-cache',
280
+ plugins: [
281
+ new CacheableResponsePlugin({
282
+ statuses: [0, 200],
283
+ }),
284
+ new ExpirationPlugin({
285
+ maxEntries: 50,
286
+ maxAgeSeconds: 24 * 60 * 60, // 24 heures
287
+ }),
288
+ ],
289
+ networkTimeoutSeconds: 3,
290
+ })
291
+ )
292
+
293
+ // CacheFirst pour les assets WordPress (wp-content)
294
+ registerRoute(
295
+ ({ url }) => url.pathname.includes('/wp-content/'),
296
+ new CacheFirst({
297
+ cacheName: 'wp-assets-cache',
298
+ plugins: [
299
+ new CacheableResponsePlugin({
300
+ statuses: [0, 200],
301
+ }),
302
+ new ExpirationPlugin({
303
+ maxEntries: 100,
304
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
305
+ }),
306
+ ],
307
+ })
308
+ )
309
+
310
+ // CacheFirst pour images
311
+ registerRoute(
312
+ ({ request }) => request.destination === 'image',
313
+ new CacheFirst({
314
+ cacheName: 'images-cache',
315
+ plugins: [
316
+ new CacheableResponsePlugin({
317
+ statuses: [0, 200],
318
+ }),
319
+ new ExpirationPlugin({
320
+ maxEntries: 60,
321
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
322
+ }),
323
+ ],
324
+ })
325
+ )
326
+
327
+ // CacheFirst pour fonts
328
+ registerRoute(
329
+ ({ request }) => request.destination === 'font',
330
+ new CacheFirst({
331
+ cacheName: 'fonts-cache',
332
+ plugins: [
333
+ new CacheableResponsePlugin({
334
+ statuses: [0, 200],
335
+ }),
336
+ new ExpirationPlugin({
337
+ maxEntries: 30,
338
+ maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
339
+ }),
340
+ ],
341
+ })
342
+ )
343
+
344
+ // StaleWhileRevalidate pour CSS/JS
345
+ registerRoute(
346
+ ({ request }) => request.destination === 'style' || request.destination === 'script',
347
+ new StaleWhileRevalidate({
348
+ cacheName: 'assets-cache',
349
+ plugins: [
350
+ new CacheableResponsePlugin({
351
+ statuses: [0, 200],
352
+ }),
353
+ new ExpirationPlugin({
354
+ maxEntries: 50,
355
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
356
+ }),
357
+ ],
358
+ })
359
+ )
360
+
361
+ // NetworkFirst pour wp-admin et wp-json (API REST WordPress)
362
+ registerRoute(
363
+ ({ url }) => url.pathname.startsWith('/wp-admin/') || url.pathname.startsWith('/wp-json/'),
364
+ new NetworkFirst({
365
+ cacheName: 'wp-api-cache',
366
+ plugins: [
367
+ new CacheableResponsePlugin({
368
+ statuses: [0, 200],
369
+ }),
370
+ new ExpirationPlugin({
371
+ maxEntries: 30,
372
+ maxAgeSeconds: 5 * 60, // 5 minutes
373
+ }),
374
+ ],
375
+ networkTimeoutSeconds: 3,
376
+ })
377
+ )
378
+ `;
379
+
380
+ // src/service-worker/php.ts
381
+ var phpServiceWorkerTemplate = `
382
+ import { precacheAndRoute } from 'workbox-precaching'
383
+ import { registerRoute } from 'workbox-routing'
384
+ import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'
385
+ import { CacheableResponsePlugin } from 'workbox-cacheable-response'
386
+ import { ExpirationPlugin } from 'workbox-expiration'
387
+
388
+ // Precache des assets statiques
389
+ precacheAndRoute(self.__WB_MANIFEST)
390
+
391
+ // NetworkFirst pour les pages PHP (priorit\xE9 au serveur)
392
+ registerRoute(
393
+ ({ request }) => request.mode === 'navigate',
394
+ new NetworkFirst({
395
+ cacheName: 'php-pages-cache',
396
+ plugins: [
397
+ new CacheableResponsePlugin({
398
+ statuses: [0, 200],
399
+ }),
400
+ new ExpirationPlugin({
401
+ maxEntries: 50,
402
+ maxAgeSeconds: 24 * 60 * 60, // 24 heures
403
+ }),
404
+ ],
405
+ networkTimeoutSeconds: 3,
406
+ })
407
+ )
408
+
409
+ // CacheFirst pour les assets publics (build/, public/)
410
+ registerRoute(
411
+ ({ url }) => url.pathname.startsWith('/build/') || url.pathname.startsWith('/public/'),
412
+ new CacheFirst({
413
+ cacheName: 'public-assets-cache',
414
+ plugins: [
415
+ new CacheableResponsePlugin({
416
+ statuses: [0, 200],
417
+ }),
418
+ new ExpirationPlugin({
419
+ maxEntries: 100,
420
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
421
+ }),
422
+ ],
423
+ })
424
+ )
425
+
426
+ // CacheFirst pour images
427
+ registerRoute(
428
+ ({ request }) => request.destination === 'image',
429
+ new CacheFirst({
430
+ cacheName: 'images-cache',
431
+ plugins: [
432
+ new CacheableResponsePlugin({
433
+ statuses: [0, 200],
434
+ }),
435
+ new ExpirationPlugin({
436
+ maxEntries: 60,
437
+ maxAgeSeconds: 30 * 24 * 60 * 60, // 30 jours
438
+ }),
439
+ ],
440
+ })
441
+ )
442
+
443
+ // CacheFirst pour fonts
444
+ registerRoute(
445
+ ({ request }) => request.destination === 'font',
446
+ new CacheFirst({
447
+ cacheName: 'fonts-cache',
448
+ plugins: [
449
+ new CacheableResponsePlugin({
450
+ statuses: [0, 200],
451
+ }),
452
+ new ExpirationPlugin({
453
+ maxEntries: 30,
454
+ maxAgeSeconds: 365 * 24 * 60 * 60, // 1 an
455
+ }),
456
+ ],
457
+ })
458
+ )
459
+
460
+ // StaleWhileRevalidate pour CSS/JS
461
+ registerRoute(
462
+ ({ request }) => request.destination === 'style' || request.destination === 'script',
463
+ new StaleWhileRevalidate({
464
+ cacheName: 'assets-cache',
465
+ plugins: [
466
+ new CacheableResponsePlugin({
467
+ statuses: [0, 200],
468
+ }),
469
+ new ExpirationPlugin({
470
+ maxEntries: 50,
471
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 jours
472
+ }),
473
+ ],
474
+ })
475
+ )
476
+
477
+ // NetworkFirst pour les routes API
478
+ registerRoute(
479
+ ({ url }) => url.pathname.startsWith('/api/') || url.pathname.startsWith('/graphql'),
480
+ new NetworkFirst({
481
+ cacheName: 'api-cache',
482
+ plugins: [
483
+ new CacheableResponsePlugin({
484
+ statuses: [0, 200],
485
+ }),
486
+ new ExpirationPlugin({
487
+ maxEntries: 50,
488
+ maxAgeSeconds: 5 * 60, // 5 minutes
489
+ }),
490
+ ],
491
+ networkTimeoutSeconds: 3,
492
+ })
493
+ )
494
+ `;
495
+
496
+ // src/service-worker/index.ts
497
+ function getServiceWorkerTemplate(type) {
498
+ const templates = {
499
+ static: staticServiceWorkerTemplate,
500
+ spa: spaServiceWorkerTemplate,
501
+ ssr: ssrServiceWorkerTemplate,
502
+ wordpress: wordpressServiceWorkerTemplate,
503
+ php: phpServiceWorkerTemplate
504
+ };
505
+ const content = templates[type];
506
+ if (!content) {
507
+ throw new Error(`Unknown service worker template type: ${type}`);
508
+ }
509
+ return {
510
+ type,
511
+ content: content.trim()
512
+ };
513
+ }
514
+ function getAvailableTemplateTypes() {
515
+ return ["static", "spa", "ssr", "wordpress", "php"];
516
+ }
517
+ function determineTemplateType(architecture, framework) {
518
+ if (framework === "WordPress") {
519
+ return "wordpress";
520
+ }
521
+ if (framework === "Symfony" || framework === "Laravel") {
522
+ return "php";
523
+ }
524
+ if (architecture === "spa") {
525
+ return "spa";
526
+ }
527
+ if (architecture === "ssr") {
528
+ return "ssr";
529
+ }
530
+ return "static";
531
+ }
532
+
533
+ // src/index.ts
534
+ var placeholder = true;
535
+ export {
536
+ determineTemplateType,
537
+ getAvailableTemplateTypes,
538
+ getServiceWorkerTemplate,
539
+ phpServiceWorkerTemplate,
540
+ placeholder,
541
+ spaServiceWorkerTemplate,
542
+ ssrServiceWorkerTemplate,
543
+ staticServiceWorkerTemplate,
544
+ wordpressServiceWorkerTemplate
545
+ };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@julien-lin/universal-pwa-templates",
3
+ "version": "1.1.0",
4
+ "description": "Templates de service workers pour UniversalPWA",
5
+ "keywords": [
6
+ "pwa",
7
+ "progressive-web-app",
8
+ "workbox",
9
+ "service-worker",
10
+ "templates"
11
+ ],
12
+ "author": "julien-lin",
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/julien-lin/UniversalPWA.git",
17
+ "directory": "packages/templates"
18
+ },
19
+ "homepage": "https://github.com/julien-lin/UniversalPWA#readme",
20
+ "bugs": {
21
+ "url": "https://github.com/julien-lin/UniversalPWA/issues"
22
+ },
23
+ "type": "module",
24
+ "main": "dist/index.js",
25
+ "module": "dist/index.mjs",
26
+ "types": "dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js",
31
+ "require": "./dist/index.cjs"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "dependencies": {
38
+ "zod": "^4.2.1"
39
+ },
40
+ "devDependencies": {
41
+ "@vitest/coverage-v8": "^2.1.4",
42
+ "tsup": "^8.3.0",
43
+ "tsx": "^4.19.0",
44
+ "typescript": "~5.9.3",
45
+ "vitest": "^2.1.4"
46
+ },
47
+ "scripts": {
48
+ "dev": "tsx src/index.ts",
49
+ "build": "tsup src/index.ts --dts --format esm,cjs",
50
+ "lint": "eslint src --ext .ts",
51
+ "test": "vitest run"
52
+ }
53
+ }