tiny-essentials 1.28.18 → 1.29.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 +1 -1
- package/changelog/1/28/19.md +24 -0
- package/changelog/1/29/0.md +58 -0
- package/dist/v1/ColorSafeStringify.min.js +1 -1
- package/dist/v1/TinyAdvancedRaffle.min.js +1 -1
- package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
- package/dist/v1/TinyAnalogClock.min.js +1 -1
- package/dist/v1/TinyArrayComparator.min.js +1 -1
- package/dist/v1/TinyArrayPaginator.min.js +1 -1
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyBrowserMonitor.min.js +1 -0
- package/dist/v1/TinyClassManager.min.js +1 -1
- package/dist/v1/TinyClipboard.min.js +1 -1
- package/dist/v1/TinyCloner.min.js +1 -0
- package/dist/v1/TinyColorConverter.min.js +1 -1
- package/dist/v1/TinyColorValidator.min.js +1 -1
- package/dist/v1/TinyCookieConsent.min.js +1 -1
- package/dist/v1/TinyDayNightCycle.min.js +1 -1
- package/dist/v1/TinyDebugger.min.js +1 -1
- package/dist/v1/TinyDomReadyManager.min.js +1 -1
- package/dist/v1/TinyDragDropDetector.min.js +1 -1
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyElementObserver.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyGamepad.min.js +1 -1
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinyHtmlTagRegexBuilder.min.js +1 -0
- package/dist/v1/TinyHttpResponseRegistry.min.js +1 -0
- package/dist/v1/TinyI18.min.js +1 -1
- package/dist/v1/TinyIframeEvents.min.js +1 -1
- package/dist/v1/TinyInventory.min.js +1 -1
- package/dist/v1/TinyInventoryTrader.min.js +1 -1
- package/dist/v1/TinyLevelUp.min.js +1 -1
- package/dist/v1/TinyLoadingScreen.min.js +1 -1
- package/dist/v1/TinyLocalStorage.min.js +1 -1
- package/dist/v1/TinyMaInSys.min.js +1 -1
- package/dist/v1/TinyMapCache.min.js +1 -0
- package/dist/v1/TinyMediaPlayer.min.js +1 -1
- package/dist/v1/TinyNeedBar.min.js +1 -1
- package/dist/v1/TinyNewWinEvents.min.js +1 -1
- package/dist/v1/TinyNotificationAdapter.min.js +1 -0
- package/dist/v1/TinyNotifications.min.js +1 -1
- package/dist/v1/TinyNotifyCenter.min.js +1 -1
- package/dist/v1/TinyOPFSFileSystem.min.js +1 -0
- package/dist/v1/TinyPasswordValidator.min.js +1 -0
- package/dist/v1/TinyPluginPackage.min.js +1 -0
- package/dist/v1/TinyPromiseQueue.min.js +1 -1
- package/dist/v1/TinyPushManager.min.js +1 -0
- package/dist/v1/TinyPushPayload.min.js +1 -0
- package/dist/v1/TinyPushRouter.min.js +1 -0
- package/dist/v1/TinyRadioFm.min.js +1 -1
- package/dist/v1/TinyRateLimiter.min.js +1 -1
- package/dist/v1/TinyRegexEs.min.js +1 -0
- package/dist/v1/TinyRouter.min.js +1 -0
- package/dist/v1/TinyServiceWorker.min.js +1 -0
- package/dist/v1/TinyServiceWorkerEngine.min.js +1 -0
- package/dist/v1/TinySetMapPackage.min.js +1 -0
- package/dist/v1/TinySimpleDice.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyStorageBucketFileSystem.min.js +1 -0
- package/dist/v1/TinyTextDiffer.min.js +1 -1
- package/dist/v1/TinyTextRangeEditor.min.js +1 -1
- package/dist/v1/TinyTextarea.min.js +1 -1
- package/dist/v1/TinyThrottledApi.min.js +1 -0
- package/dist/v1/TinyTimeout.min.js +1 -1
- package/dist/v1/TinyToastNotify.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/TinyUriParser.min.js +1 -0
- package/dist/v1/TinyVersion.min.js +1 -0
- package/dist/v1/TinyWebWorker.min.js +1 -0
- package/dist/v1/TinyWebWorkerEngine.min.js +1 -0
- package/dist/v1/UltraRandomMsgGen.min.js +1 -1
- package/dist/v1/basics/array.cjs +2 -2
- package/dist/v1/basics/array.d.mts +2 -0
- package/dist/v1/basics/array.d.mts.map +1 -1
- package/dist/v1/basics/array.mjs +2 -1
- package/dist/v1/basics/browserDetector.cjs +37 -12
- package/dist/v1/basics/browserDetector.d.mts +8 -0
- package/dist/v1/basics/browserDetector.d.mts.map +1 -1
- package/dist/v1/basics/browserDetector.mjs +32 -13
- package/dist/v1/basics/crypto.cjs +23 -0
- package/dist/v1/basics/crypto.d.mts +10 -0
- package/dist/v1/basics/crypto.d.mts.map +1 -0
- package/dist/v1/basics/crypto.mjs +18 -0
- package/dist/v1/basics/html.cjs +0 -3
- package/dist/v1/basics/html.d.mts.map +1 -1
- package/dist/v1/basics/html.mjs +0 -2
- package/dist/v1/basics/index.cjs +8 -1
- package/dist/v1/basics/index.d.mts +6 -5
- package/dist/v1/basics/index.d.mts.map +1 -1
- package/dist/v1/basics/index.mjs +6 -5
- package/dist/v1/basics/objChecker.cjs +88 -0
- package/dist/v1/basics/objChecker.d.mts +26 -0
- package/dist/v1/basics/objChecker.d.mts.map +1 -1
- package/dist/v1/basics/objChecker.mjs +74 -0
- package/dist/v1/basics/objFilter.cjs +234 -93
- package/dist/v1/basics/objFilter.d.mts +96 -22
- package/dist/v1/basics/objFilter.d.mts.map +1 -1
- package/dist/v1/basics/objFilter.mjs +216 -92
- package/dist/v1/basics/promiseUtils.cjs +48 -12
- package/dist/v1/basics/promiseUtils.d.mts +45 -12
- package/dist/v1/basics/promiseUtils.d.mts.map +1 -1
- package/dist/v1/basics/promiseUtils.mjs +47 -12
- package/dist/v1/basics/text.cjs +0 -12
- package/dist/v1/basics/text.d.mts +0 -10
- package/dist/v1/basics/text.d.mts.map +1 -1
- package/dist/v1/basics/text.mjs +0 -10
- package/dist/v1/css/TinyCookieConsent.min.css +1 -0
- package/dist/v1/css/TinyCookieConsent.min.css.map +1 -0
- package/dist/v1/css/TinyDraggerExample.min.css +1 -0
- package/dist/v1/css/TinyDraggerExample.min.css.map +1 -0
- package/dist/v1/css/TinyLoadingScreen.min.css +1 -0
- package/dist/v1/css/TinyLoadingScreen.min.css.map +1 -0
- package/dist/v1/css/TinyNotify.min.css +1 -0
- package/dist/v1/css/TinyNotify.min.css.map +1 -0
- package/dist/v1/css/aiMarker.min.css +1 -0
- package/dist/v1/css/aiMarker.min.css.map +1 -0
- package/dist/v1/index.cjs +88 -3
- package/dist/v1/index.d.mts +31 -6
- package/dist/v1/index.d.mts.map +1 -1
- package/dist/v1/index.mjs +32 -7
- package/dist/v1/jsdoc/EventEmitter.cjs +4 -0
- package/dist/v1/jsdoc/EventEmitter.d.mts +33 -0
- package/dist/v1/jsdoc/EventEmitter.d.mts.map +1 -0
- package/dist/v1/jsdoc/EventEmitter.mjs +18 -0
- package/dist/v1/libs/array/TinyArrayComparator.cjs +240 -25
- package/dist/v1/libs/array/TinyArrayComparator.d.mts +130 -22
- package/dist/v1/libs/array/TinyArrayComparator.d.mts.map +1 -1
- package/dist/v1/libs/array/TinyArrayComparator.mjs +210 -24
- package/dist/v1/libs/fs/constants.cjs +74 -0
- package/dist/v1/libs/fs/constants.d.mts +22 -0
- package/dist/v1/libs/fs/constants.d.mts.map +1 -0
- package/dist/v1/libs/fs/constants.mjs +53 -0
- package/dist/v1/libs/fs/encoding.cjs +118 -0
- package/dist/v1/libs/fs/encoding.d.mts +50 -0
- package/dist/v1/libs/fs/encoding.d.mts.map +1 -0
- package/dist/v1/libs/fs/encoding.mjs +102 -0
- package/dist/v1/libs/fs/error.cjs +188 -0
- package/dist/v1/libs/fs/error.d.mts +105 -0
- package/dist/v1/libs/fs/error.d.mts.map +1 -0
- package/dist/v1/libs/fs/error.mjs +158 -0
- package/dist/v1/libs/fs/handle.cjs +121 -0
- package/dist/v1/libs/fs/handle.d.mts +56 -0
- package/dist/v1/libs/fs/handle.d.mts.map +1 -0
- package/dist/v1/libs/fs/handle.mjs +100 -0
- package/dist/v1/libs/fs/index.cjs +700 -0
- package/dist/v1/libs/fs/index.d.mts +377 -0
- package/dist/v1/libs/fs/index.d.mts.map +1 -0
- package/dist/v1/libs/fs/index.mjs +630 -0
- package/dist/v1/libs/fs/path.cjs +234 -0
- package/dist/v1/libs/fs/path.d.mts +176 -0
- package/dist/v1/libs/fs/path.d.mts.map +1 -0
- package/dist/v1/libs/fs/path.mjs +197 -0
- package/dist/v1/libs/fs/plugins/OPFS/StorageBucket.cjs +202 -0
- package/dist/v1/libs/fs/plugins/OPFS/StorageBucket.d.mts +121 -0
- package/dist/v1/libs/fs/plugins/OPFS/StorageBucket.d.mts.map +1 -0
- package/dist/v1/libs/fs/plugins/OPFS/StorageBucket.mjs +172 -0
- package/dist/v1/libs/fs/plugins/OPFS/index.cjs +334 -0
- package/dist/v1/libs/fs/plugins/OPFS/index.d.mts +98 -0
- package/dist/v1/libs/fs/plugins/OPFS/index.d.mts.map +1 -0
- package/dist/v1/libs/fs/plugins/OPFS/index.mjs +300 -0
- package/dist/v1/libs/fs/stats.cjs +245 -0
- package/dist/v1/libs/fs/stats.d.mts +226 -0
- package/dist/v1/libs/fs/stats.d.mts.map +1 -0
- package/dist/v1/libs/fs/stats.mjs +197 -0
- package/dist/v1/libs/html/events/TinyIframeEvents.cjs +10 -1
- package/dist/v1/libs/html/events/TinyIframeEvents.d.mts +9 -2
- package/dist/v1/libs/html/events/TinyIframeEvents.d.mts.map +1 -1
- package/dist/v1/libs/html/events/TinyIframeEvents.mjs +8 -1
- package/dist/v1/libs/html/events/TinyNewWinEvents.cjs +14 -3
- package/dist/v1/libs/html/events/TinyNewWinEvents.d.mts +21 -5
- package/dist/v1/libs/html/events/TinyNewWinEvents.d.mts.map +1 -1
- package/dist/v1/libs/html/events/TinyNewWinEvents.mjs +12 -3
- package/dist/v1/libs/html/scroll/TinySmartScroller.cjs +13 -1
- package/dist/v1/libs/html/scroll/TinySmartScroller.d.mts +29 -2
- package/dist/v1/libs/html/scroll/TinySmartScroller.d.mts.map +1 -1
- package/dist/v1/libs/html/scroll/TinySmartScroller.mjs +11 -1
- package/dist/v1/libs/math/TinyAdvancedRaffle.cjs +13 -1
- package/dist/v1/libs/math/TinyAdvancedRaffle.d.mts +32 -2
- package/dist/v1/libs/math/TinyAdvancedRaffle.d.mts.map +1 -1
- package/dist/v1/libs/math/TinyAdvancedRaffle.mjs +11 -1
- package/dist/v1/libs/math/TinyTimeout.cjs +0 -14
- package/dist/v1/libs/math/TinyTimeout.d.mts +0 -11
- package/dist/v1/libs/math/TinyTimeout.d.mts.map +1 -1
- package/dist/v1/libs/math/TinyTimeout.mjs +0 -13
- package/dist/v1/libs/media/TinyMediaPlayer/index.cjs +25 -1
- package/dist/v1/libs/media/TinyMediaPlayer/index.d.mts +35 -2
- package/dist/v1/libs/media/TinyMediaPlayer/index.d.mts.map +1 -1
- package/dist/v1/libs/media/TinyMediaPlayer/index.mjs +23 -1
- package/dist/v1/libs/media/TinyMediaPlayer.cjs +2 -2
- package/dist/v1/libs/media/TinyMediaPlayer.d.mts +2 -2
- package/dist/v1/libs/media/TinyMediaPlayer.d.mts.map +1 -1
- package/dist/v1/libs/media/TinyMediaPlayer.mjs +2 -2
- package/dist/v1/libs/media/TinyRadioFm.cjs +19 -1
- package/dist/v1/libs/media/TinyRadioFm.d.mts +78 -2
- package/dist/v1/libs/media/TinyRadioFm.d.mts.map +1 -1
- package/dist/v1/libs/media/TinyRadioFm.mjs +17 -1
- package/dist/v1/libs/plugin/TinyPlugin.cjs +1630 -0
- package/dist/v1/libs/plugin/TinyPlugin.d.mts +753 -0
- package/dist/v1/libs/plugin/TinyPlugin.d.mts.map +1 -0
- package/dist/v1/libs/plugin/TinyPlugin.mjs +1376 -0
- package/dist/v1/libs/plugin/TinyVersion.cjs +204 -0
- package/dist/v1/libs/plugin/TinyVersion.d.mts +70 -0
- package/dist/v1/libs/plugin/TinyVersion.d.mts.map +1 -0
- package/dist/v1/libs/plugin/TinyVersion.mjs +179 -0
- package/dist/v1/libs/router/TinyRouter.cjs +661 -0
- package/dist/v1/libs/router/TinyRouter.d.mts +320 -0
- package/dist/v1/libs/router/TinyRouter.d.mts.map +1 -0
- package/dist/v1/libs/router/TinyRouter.mjs +572 -0
- package/dist/v1/libs/storage/TinyLocalStorage.cjs +20 -1
- package/dist/v1/libs/storage/TinyLocalStorage.d.mts +64 -2
- package/dist/v1/libs/storage/TinyLocalStorage.d.mts.map +1 -1
- package/dist/v1/libs/storage/TinyLocalStorage.mjs +18 -1
- package/dist/v1/libs/storage/TinyMapCache.cjs +373 -0
- package/dist/v1/libs/storage/TinyMapCache.d.mts +274 -0
- package/dist/v1/libs/storage/TinyMapCache.d.mts.map +1 -0
- package/dist/v1/libs/storage/TinyMapCache.mjs +333 -0
- package/dist/v1/libs/storage/TinySetMapDatabase.cjs +1167 -0
- package/dist/v1/libs/storage/TinySetMapDatabase.d.mts +603 -0
- package/dist/v1/libs/storage/TinySetMapDatabase.d.mts.map +1 -0
- package/dist/v1/libs/storage/TinySetMapDatabase.mjs +1059 -0
- package/dist/v1/libs/sw/browser/TinyNotificationAdapter.cjs +126 -0
- package/dist/v1/libs/sw/browser/TinyNotificationAdapter.d.mts +132 -0
- package/dist/v1/libs/sw/browser/TinyNotificationAdapter.d.mts.map +1 -0
- package/dist/v1/libs/sw/browser/TinyNotificationAdapter.mjs +109 -0
- package/dist/v1/libs/sw/browser/TinyPushManager.cjs +310 -0
- package/dist/v1/libs/sw/browser/TinyPushManager.d.mts +168 -0
- package/dist/v1/libs/sw/browser/TinyPushManager.d.mts.map +1 -0
- package/dist/v1/libs/sw/browser/TinyPushManager.mjs +264 -0
- package/dist/v1/libs/sw/browser/TinyServiceWorker.cjs +1060 -0
- package/dist/v1/libs/sw/browser/TinyServiceWorker.d.mts +348 -0
- package/dist/v1/libs/sw/browser/TinyServiceWorker.d.mts.map +1 -0
- package/dist/v1/libs/sw/browser/TinyServiceWorker.mjs +933 -0
- package/dist/v1/libs/sw/browser/plugins/TabManager.cjs +315 -0
- package/dist/v1/libs/sw/browser/plugins/TabManager.d.mts +178 -0
- package/dist/v1/libs/sw/browser/plugins/TabManager.d.mts.map +1 -0
- package/dist/v1/libs/sw/browser/plugins/TabManager.mjs +274 -0
- package/dist/v1/libs/sw/browser/utils.cjs +28 -0
- package/dist/v1/libs/sw/browser/utils.d.mts +8 -0
- package/dist/v1/libs/sw/browser/utils.d.mts.map +1 -0
- package/dist/v1/libs/sw/browser/utils.mjs +21 -0
- package/dist/v1/libs/sw/service/TinyPushRouter.cjs +222 -0
- package/dist/v1/libs/sw/service/TinyPushRouter.d.mts +138 -0
- package/dist/v1/libs/sw/service/TinyPushRouter.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/TinyPushRouter.mjs +201 -0
- package/dist/v1/libs/sw/service/TinyServiceWorkerEngine.cjs +3016 -0
- package/dist/v1/libs/sw/service/TinyServiceWorkerEngine.d.mts +993 -0
- package/dist/v1/libs/sw/service/TinyServiceWorkerEngine.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/TinyServiceWorkerEngine.mjs +2558 -0
- package/dist/v1/libs/sw/service/plugins/GlobBypassPlugin.cjs +88 -0
- package/dist/v1/libs/sw/service/plugins/GlobBypassPlugin.d.mts +32 -0
- package/dist/v1/libs/sw/service/plugins/GlobBypassPlugin.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/plugins/GlobBypassPlugin.mjs +69 -0
- package/dist/v1/libs/sw/service/plugins/GlobCachePlugin.cjs +112 -0
- package/dist/v1/libs/sw/service/plugins/GlobCachePlugin.d.mts +31 -0
- package/dist/v1/libs/sw/service/plugins/GlobCachePlugin.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/plugins/GlobCachePlugin.mjs +91 -0
- package/dist/v1/libs/sw/service/plugins/Ping.cjs +32 -0
- package/dist/v1/libs/sw/service/plugins/Ping.d.mts +9 -0
- package/dist/v1/libs/sw/service/plugins/Ping.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/plugins/Ping.mjs +25 -0
- package/dist/v1/libs/sw/service/plugins/TabManager.cjs +457 -0
- package/dist/v1/libs/sw/service/plugins/TabManager.d.mts +91 -0
- package/dist/v1/libs/sw/service/plugins/TabManager.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/plugins/TabManager.mjs +372 -0
- package/dist/v1/libs/sw/service/plugins/ViteFileDetector.cjs +180 -0
- package/dist/v1/libs/sw/service/plugins/ViteFileDetector.d.mts +28 -0
- package/dist/v1/libs/sw/service/plugins/ViteFileDetector.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/plugins/ViteFileDetector.mjs +148 -0
- package/dist/v1/libs/sw/service/shared/TinyPushPayload.cjs +199 -0
- package/dist/v1/libs/sw/service/shared/TinyPushPayload.d.mts +80 -0
- package/dist/v1/libs/sw/service/shared/TinyPushPayload.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/shared/TinyPushPayload.mjs +174 -0
- package/dist/v1/libs/sw/utils.cjs +57 -0
- package/dist/v1/libs/sw/utils.d.mts +173 -0
- package/dist/v1/libs/sw/utils.d.mts.map +1 -0
- package/dist/v1/libs/sw/utils.mjs +50 -0
- package/dist/v1/libs/text/TinyI18/Browser-NON-DOM.cjs +57 -0
- package/dist/v1/libs/text/TinyI18/Browser-NON-DOM.d.mts +39 -0
- package/dist/v1/libs/text/TinyI18/Browser-NON-DOM.d.mts.map +1 -0
- package/dist/v1/libs/text/TinyI18/Browser-NON-DOM.mjs +48 -0
- package/dist/v1/libs/text/TinyI18/Browser.cjs +64 -0
- package/dist/v1/libs/text/TinyI18/Browser.d.mts +47 -0
- package/dist/v1/libs/text/TinyI18/Browser.d.mts.map +1 -0
- package/dist/v1/libs/text/TinyI18/Browser.mjs +57 -0
- package/dist/v1/libs/text/TinyI18/Node.cjs +49 -0
- package/dist/v1/libs/text/TinyI18/Node.d.mts +38 -0
- package/dist/v1/libs/text/TinyI18/Node.d.mts.map +1 -0
- package/dist/v1/libs/text/TinyI18/Node.mjs +43 -0
- package/dist/v1/libs/text/TinyI18/browser-utils.cjs +17 -0
- package/dist/v1/libs/text/TinyI18/browser-utils.d.mts +8 -0
- package/dist/v1/libs/text/TinyI18/browser-utils.d.mts.map +1 -0
- package/dist/v1/libs/text/TinyI18/browser-utils.mjs +13 -0
- package/dist/v1/libs/text/{TinyI18.cjs → TinyI18/index.cjs} +205 -104
- package/dist/v1/libs/text/{TinyI18.d.mts → TinyI18/index.d.mts} +141 -92
- package/dist/v1/libs/text/TinyI18/index.d.mts.map +1 -0
- package/dist/v1/libs/text/{TinyI18.mjs → TinyI18/index.mjs} +195 -101
- package/dist/v1/libs/tools/TinyBrowserMonitor.cjs +1088 -0
- package/dist/v1/libs/tools/TinyBrowserMonitor.d.mts +621 -0
- package/dist/v1/libs/tools/TinyBrowserMonitor.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyBrowserMonitor.mjs +940 -0
- package/dist/v1/libs/tools/TinyDebugger.cjs +180 -19
- package/dist/v1/libs/tools/TinyDebugger.d.mts +220 -24
- package/dist/v1/libs/tools/TinyDebugger.d.mts.map +1 -1
- package/dist/v1/libs/tools/TinyDebugger.mjs +161 -19
- package/dist/v1/libs/tools/TinyHtmlTagRegexBuilder.cjs +256 -0
- package/dist/v1/libs/tools/TinyHtmlTagRegexBuilder.d.mts +125 -0
- package/dist/v1/libs/tools/TinyHtmlTagRegexBuilder.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHtmlTagRegexBuilder.mjs +223 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser-NON-DOM.cjs +23 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser-NON-DOM.d.mts +17 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser-NON-DOM.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser-NON-DOM.mjs +19 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser.cjs +23 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser.d.mts +17 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser.mjs +19 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/EmptyRequestCodes.cjs +390 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/EmptyRequestCodes.d.mts +9 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/EmptyRequestCodes.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/EmptyRequestCodes.mjs +387 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/JsDoc.cjs +2 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/JsDoc.d.mts +27 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/JsDoc.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/JsDoc.mjs +12 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/LICENSE +53 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/index.cjs +405 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/index.d.mts +34 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/index.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/index.mjs +342 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Node.cjs +23 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Node.d.mts +17 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Node.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Node.mjs +19 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/RequestCodes.cjs +327 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/RequestCodes.d.mts +9 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/RequestCodes.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/RequestCodes.mjs +324 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/index.cjs +268 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/index.d.mts +107 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/index.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/index.mjs +238 -0
- package/dist/v1/libs/tools/TinyPasswordValidator.cjs +491 -0
- package/dist/v1/libs/tools/TinyPasswordValidator.d.mts +246 -0
- package/dist/v1/libs/tools/TinyPasswordValidator.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyPasswordValidator.mjs +434 -0
- package/dist/v1/libs/tools/TinyPkgExportValidator.cjs +48 -0
- package/dist/v1/libs/tools/TinyPkgExportValidator.d.mts +14 -0
- package/dist/v1/libs/tools/TinyPkgExportValidator.d.mts.map +1 -1
- package/dist/v1/libs/tools/TinyPkgExportValidator.mjs +44 -0
- package/dist/v1/libs/tools/TinySiteMap.cjs +1029 -0
- package/dist/v1/libs/tools/TinySiteMap.d.mts +429 -0
- package/dist/v1/libs/tools/TinySiteMap.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinySiteMap.mjs +910 -0
- package/dist/v1/libs/tools/TinySiteMapStream.cjs +121 -0
- package/dist/v1/libs/tools/TinySiteMapStream.d.mts +51 -0
- package/dist/v1/libs/tools/TinySiteMapStream.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinySiteMapStream.mjs +85 -0
- package/dist/v1/libs/tools/TinyURLSecurityVerifier.cjs +444 -0
- package/dist/v1/libs/tools/TinyURLSecurityVerifier.d.mts +217 -0
- package/dist/v1/libs/tools/TinyURLSecurityVerifier.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyURLSecurityVerifier.mjs +394 -0
- package/dist/v1/libs/tools/TinyUriParser/BlueSky.cjs +613 -0
- package/dist/v1/libs/tools/TinyUriParser/BlueSky.d.mts +152 -0
- package/dist/v1/libs/tools/TinyUriParser/BlueSky.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyUriParser/BlueSky.mjs +527 -0
- package/dist/v1/libs/tools/TinyUriParser/Discord.cjs +1119 -0
- package/dist/v1/libs/tools/TinyUriParser/Discord.d.mts +306 -0
- package/dist/v1/libs/tools/TinyUriParser/Discord.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyUriParser/Discord.mjs +968 -0
- package/dist/v1/libs/tools/TinyUriParser/MatrixProtocol.cjs +469 -0
- package/dist/v1/libs/tools/TinyUriParser/MatrixProtocol.d.mts +80 -0
- package/dist/v1/libs/tools/TinyUriParser/MatrixProtocol.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyUriParser/MatrixProtocol.mjs +379 -0
- package/dist/v1/libs/tools/TinyUriParser.cjs +217 -0
- package/dist/v1/libs/tools/TinyUriParser.d.mts +109 -0
- package/dist/v1/libs/tools/TinyUriParser.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyUriParser.mjs +183 -0
- package/dist/v1/libs/utils/TinyCloner.cjs +466 -0
- package/dist/v1/libs/utils/TinyCloner.d.mts +221 -0
- package/dist/v1/libs/utils/TinyCloner.d.mts.map +1 -0
- package/dist/v1/libs/utils/TinyCloner.mjs +416 -0
- package/dist/v1/libs/utils/TinyPromiseQueue.cjs +1 -1
- package/dist/v1/libs/utils/TinyPromiseQueue.d.mts +2 -2
- package/dist/v1/libs/utils/TinyPromiseQueue.d.mts.map +1 -1
- package/dist/v1/libs/utils/TinyPromiseQueue.mjs +1 -1
- package/dist/v1/libs/utils/TinyThrottledApi.cjs +333 -0
- package/dist/v1/libs/utils/TinyThrottledApi.d.mts +163 -0
- package/dist/v1/libs/utils/TinyThrottledApi.d.mts.map +1 -0
- package/dist/v1/libs/utils/TinyThrottledApi.mjs +294 -0
- package/dist/v1/libs/worker/browser/TinyWebWorker.cjs +342 -0
- package/dist/v1/libs/worker/browser/TinyWebWorker.d.mts +97 -0
- package/dist/v1/libs/worker/browser/TinyWebWorker.d.mts.map +1 -0
- package/dist/v1/libs/worker/browser/TinyWebWorker.mjs +305 -0
- package/dist/v1/libs/worker/engine/TinyWebWorkerEngine.cjs +346 -0
- package/dist/v1/libs/worker/engine/TinyWebWorkerEngine.d.mts +127 -0
- package/dist/v1/libs/worker/engine/TinyWebWorkerEngine.d.mts.map +1 -0
- package/dist/v1/libs/worker/engine/TinyWebWorkerEngine.mjs +304 -0
- package/dist/v1/regexp/Email.cjs +185 -0
- package/dist/v1/regexp/Email.d.mts +73 -0
- package/dist/v1/regexp/Email.d.mts.map +1 -0
- package/dist/v1/regexp/Email.mjs +153 -0
- package/dist/v1/regexp/Glob.cjs +293 -0
- package/dist/v1/regexp/Glob.d.mts +45 -0
- package/dist/v1/regexp/Glob.d.mts.map +1 -0
- package/dist/v1/regexp/Glob.mjs +260 -0
- package/dist/v1/regexp/Ipv4.cjs +57 -0
- package/dist/v1/regexp/Ipv4.d.mts +29 -0
- package/dist/v1/regexp/Ipv4.d.mts.map +1 -0
- package/dist/v1/regexp/Ipv4.mjs +45 -0
- package/dist/v1/regexp/Ipv6.cjs +67 -0
- package/dist/v1/regexp/Ipv6.d.mts +29 -0
- package/dist/v1/regexp/Ipv6.d.mts.map +1 -0
- package/dist/v1/regexp/Ipv6.mjs +54 -0
- package/dist/v1/regexp/SegmentExtractor.cjs +145 -0
- package/dist/v1/regexp/SegmentExtractor.d.mts +91 -0
- package/dist/v1/regexp/SegmentExtractor.d.mts.map +1 -0
- package/dist/v1/regexp/SegmentExtractor.mjs +116 -0
- package/dist/v1/regexp/UrlDetector.cjs +125 -0
- package/dist/v1/regexp/UrlDetector.d.mts +67 -0
- package/dist/v1/regexp/UrlDetector.d.mts.map +1 -0
- package/dist/v1/regexp/UrlDetector.mjs +102 -0
- package/dist/v1/regexp/Username/index.cjs +233 -0
- package/dist/v1/regexp/Username/index.d.mts +77 -0
- package/dist/v1/regexp/Username/index.d.mts.map +1 -0
- package/dist/v1/regexp/Username/index.mjs +199 -0
- package/dist/v1/regexp/Username/jsDoc.cjs +2 -0
- package/dist/v1/regexp/Username/jsDoc.d.mts +57 -0
- package/dist/v1/regexp/Username/jsDoc.d.mts.map +1 -0
- package/dist/v1/regexp/Username/jsDoc.mjs +18 -0
- package/dist/v1/regexp/Username/templates/BlueSky.cjs +56 -0
- package/dist/v1/regexp/Username/templates/BlueSky.d.mts +35 -0
- package/dist/v1/regexp/Username/templates/BlueSky.d.mts.map +1 -0
- package/dist/v1/regexp/Username/templates/BlueSky.mjs +52 -0
- package/dist/v1/regexp/Username/templates/Discord.cjs +505 -0
- package/dist/v1/regexp/Username/templates/Discord.d.mts +209 -0
- package/dist/v1/regexp/Username/templates/Discord.d.mts.map +1 -0
- package/dist/v1/regexp/Username/templates/Discord.mjs +458 -0
- package/dist/v1/regexp/Username/templates/MatrixProtocol.cjs +143 -0
- package/dist/v1/regexp/Username/templates/MatrixProtocol.d.mts +70 -0
- package/dist/v1/regexp/Username/templates/MatrixProtocol.d.mts.map +1 -0
- package/dist/v1/regexp/Username/templates/MatrixProtocol.mjs +128 -0
- package/dist/v1/regexp/Username/templates/deprecated/Discord.cjs +24 -0
- package/dist/v1/regexp/Username/templates/deprecated/Discord.d.mts +17 -0
- package/dist/v1/regexp/Username/templates/deprecated/Discord.d.mts.map +1 -0
- package/dist/v1/regexp/Username/templates/deprecated/Discord.mjs +20 -0
- package/dist/v1/regexp/Username/templates/index.cjs +11 -0
- package/dist/v1/regexp/Username/templates/index.d.mts +5 -0
- package/dist/v1/regexp/Username/templates/index.d.mts.map +1 -0
- package/dist/v1/regexp/Username/templates/index.mjs +4 -0
- package/dist/v1/regexp/index.cjs +41 -0
- package/dist/v1/regexp/index.d.mts +9 -0
- package/dist/v1/regexp/index.d.mts.map +1 -0
- package/dist/v1/regexp/index.mjs +8 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Browser.cjs +64 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Browser.d.mts +11 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Browser.d.mts.map +1 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Browser.mjs +51 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/FileInput.cjs +66 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/FileInput.d.mts +11 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/FileInput.d.mts.map +1 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/FileInput.mjs +51 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Node.cjs +39 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Node.d.mts +11 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Node.d.mts.map +1 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Node.mjs +28 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Template.cjs +494 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Template.d.mts +142 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Template.d.mts.map +1 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Template.mjs +445 -0
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.cjs +725 -0
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.d.mts +293 -0
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.d.mts.map +1 -0
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.mjs +614 -0
- package/dist/v1/webTemplates/bootstrap/5.3/scss/input/Placeholder-Colors-Fix.scss +64 -0
- package/dist/v1/webTemplates/bootstrap/5.3/scss/spacing/Spacing-Plus.scss +31 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Browser/index.cjs +135 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Browser/index.d.mts +83 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Browser/index.d.mts.map +1 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Browser/index.mjs +120 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Node/index.cjs +127 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Node/index.d.mts +95 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Node/index.d.mts.map +1 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Node/index.mjs +109 -0
- package/dist/v1/webTemplates/multiformats/14.0/IPFSHasher/index.cjs +83 -0
- package/dist/v1/webTemplates/multiformats/14.0/IPFSHasher/index.d.mts +46 -0
- package/dist/v1/webTemplates/multiformats/14.0/IPFSHasher/index.d.mts.map +1 -0
- package/dist/v1/webTemplates/multiformats/14.0/IPFSHasher/index.mjs +71 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.cjs +493 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.d.mts +67 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.d.mts.map +1 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.mjs +399 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/githubUtils.cjs +35 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/githubUtils.d.mts +6 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/githubUtils.d.mts.map +1 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/githubUtils.mjs +29 -0
- package/docs/info/RegExp.md +74 -0
- package/docs/v1/Exports.md +111 -0
- package/docs/v1/README.md +117 -13
- package/docs/v1/basics/asyncReplace.md +2 -0
- package/docs/v1/basics/browserDetector.md +28 -11
- package/docs/v1/basics/crypto.md +85 -0
- package/docs/v1/basics/deprecated/html.md +2 -0
- package/docs/v1/basics/deprecated/objFilter.md +2 -0
- package/docs/v1/basics/html.md +2 -0
- package/docs/v1/basics/objChecker.md +55 -0
- package/docs/v1/basics/objFilter.md +57 -86
- package/docs/v1/basics/promiseUtils.md +12 -3
- package/docs/v1/basics/text.md +0 -1
- package/docs/v1/libs/array/TinyArrayComparator.md +50 -39
- package/docs/v1/libs/fs/TinyFS.md +752 -0
- package/docs/v1/libs/fs/TinyOPFSFileSystem.md +495 -0
- package/docs/v1/libs/fs/TinyStorageBucketFileSystem.md +407 -0
- package/docs/v1/libs/plugin/TinyPlugin.md +441 -0
- package/docs/v1/libs/plugin/TinyVersion.md +145 -0
- package/docs/v1/libs/router/TinyRouter.md +216 -0
- package/docs/v1/libs/storage/TinyMapCache.md +219 -0
- package/docs/v1/libs/storage/TinySetMapDatabase.md +478 -0
- package/docs/v1/libs/sw/browser/TinyNotificationAdapter.md +280 -0
- package/docs/v1/libs/sw/browser/TinyPushManager.md +782 -0
- package/docs/v1/libs/sw/browser/TinyServiceWorker.md +365 -0
- package/docs/v1/libs/sw/browser/plugins/TabManager.md +133 -0
- package/docs/v1/libs/sw/service/TinyPushRouter.md +314 -0
- package/docs/v1/libs/sw/service/TinyServiceWorkerEngine.md +748 -0
- package/docs/v1/libs/sw/service/plugins/GlobBypassPlugin.md +229 -0
- package/docs/v1/libs/sw/service/plugins/GlobCachePlugin.md +91 -0
- package/docs/v1/libs/sw/service/plugins/Ping.md +36 -0
- package/docs/v1/libs/sw/service/plugins/TabManager.md +64 -0
- package/docs/v1/libs/sw/service/plugins/ViteFileDetector.md +92 -0
- package/docs/v1/libs/sw/service/shared/TinyPushPayload.md +316 -0
- package/docs/v1/libs/text/TinyI18.md +80 -56
- package/docs/v1/libs/tools/TinyBrowserMonitor.md +170 -0
- package/docs/v1/libs/tools/TinyDebugger.md +117 -1
- package/docs/v1/libs/tools/TinyHtmlTagRegexBuilder.md +141 -0
- package/docs/v1/libs/tools/TinyHttpResponseRegistry.md +129 -0
- package/docs/v1/libs/tools/TinyPasswordValidator.md +153 -0
- package/docs/v1/libs/tools/TinyPkgExportValidator.md +45 -1
- package/docs/v1/libs/tools/TinySiteMap.md +134 -0
- package/docs/v1/libs/tools/TinySiteMapStream.md +97 -0
- package/docs/v1/libs/tools/TinyURLSecurityVerifier.md +146 -0
- package/docs/v1/libs/tools/TinyUriParser/Discord.md +374 -0
- package/docs/v1/libs/tools/TinyUriParser/MatrixProtocol.md +54 -0
- package/docs/v1/libs/tools/TinyUriParser.md +128 -0
- package/docs/v1/libs/utils/TinyCloner.md +126 -0
- package/docs/v1/libs/utils/TinyPromiseQueue.md +1 -1
- package/docs/v1/libs/utils/TinyThrottledApi.md +219 -0
- package/docs/v1/libs/worker/browser/TinyWebWorker.md +331 -0
- package/docs/v1/libs/worker/engine/TinyWebWorkerEngine.md +137 -0
- package/docs/v1/regexp/Email.md +127 -0
- package/docs/v1/regexp/Glob.md +155 -0
- package/docs/v1/regexp/IPv4.md +103 -0
- package/docs/v1/regexp/IPv6.md +122 -0
- package/docs/v1/regexp/SegmentExtractor.md +120 -0
- package/docs/v1/regexp/UrlDetector.md +117 -0
- package/docs/v1/regexp/Username/Base.md +131 -0
- package/docs/v1/regexp/Username/Discord.md +267 -0
- package/docs/v1/regexp/Username/MatrixProtocol.md +131 -0
- package/docs/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters.md +569 -0
- package/docs/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.md +174 -0
- package/docs/v1/webTemplates/media/MediaValidator/v1/Browser.md +123 -0
- package/docs/v1/webTemplates/media/MediaValidator/v1/Node.md +136 -0
- package/docs/v1/webTemplates/multiformats/14.0/IPFSHasher.md +310 -0
- package/docs/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.md +131 -0
- package/docs/v1/webTemplates/vite/7.3/plugins/githubUtils.md +50 -0
- package/package.json +313 -18
- package/types/EventEmitter.d.ts +48 -0
- package/dist/v1/libs/text/TinyI18.d.mts.map +0 -1
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
# 🚀 TinyServiceWorkerEngine Documentation
|
|
2
|
+
|
|
3
|
+
Welcome to the official documentation for the **TinyServiceWorkerEngine**. This engine is a professional-grade tool designed to manage the complexities of a Service Worker, specifically focusing on **Fetch Interception**, **Messaging Communication**, and **Lifecycle Management**.
|
|
4
|
+
|
|
5
|
+
Instead of writing hundreds of lines of repetitive `addEventListener` logic, this engine provides a structured, plugin-based architecture to handle network requests and cross-context communication.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🧠 Core Concepts (The Mental Model)
|
|
10
|
+
|
|
11
|
+
To use this engine effectively, you must understand its three primary "layers":
|
|
12
|
+
|
|
13
|
+
1. **The Interception Layer (Fetch):** The engine sits between the browser and the network. It can watch every request, match it against patterns (URLs or Regex), and decide: *"Should I let this go to the internet, or should I provide a custom response (like a cached file or an error page)?"*
|
|
14
|
+
2. **The Communication Layer (Messaging):** The Service Worker lives in a separate thread from your web page. This engine provides a "bridge" to send structured messages back and forth using `postMessage`, including helper methods to reply specifically to the sender.
|
|
15
|
+
3. **The Routing Layer (Router):** When a fetch fails (e.g., a 404 or 500 error), the engine can automatically route the user to a specific "Error Page" (like `404.html`) without you writing manual logic every time.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 🛠️ Getting Started
|
|
20
|
+
|
|
21
|
+
### 1. The Constructor
|
|
22
|
+
|
|
23
|
+
To start the engine, you must instantiate the `TinyServiceWorkerEngine` class and call the `.init()` method.
|
|
24
|
+
|
|
25
|
+
When you instantiate the engine, you can provide two configuration objects.
|
|
26
|
+
|
|
27
|
+
#### `new TinyServiceWorkerEngine(config, lgConfig)`
|
|
28
|
+
|
|
29
|
+
**Parameter: `config` (Object) — `ServiceWorkerSettings`**
|
|
30
|
+
Defines the operational behavior of the engine.
|
|
31
|
+
* `spaMode` (boolean): If `true`, the engine uses the `spaPath` (default: `/index.html`) when handling routing errors. If `false`, it uses the original requested path.
|
|
32
|
+
* `lifecycle` (Object) — `LifecycleOptions`: Controls how the `install` and `activate` phases are resolved.
|
|
33
|
+
* `installStrategy` (`'immediate' | 'wait' | 'manual'`): How the `install` phase is resolved. Default: `'immediate'`.
|
|
34
|
+
* `activateStrategy` (`'immediate' | 'wait' | 'manual'`): How the `activate` phase is resolved. Default: `'immediate'`.
|
|
35
|
+
* `installOrder` (`'before' | 'after'`): Whether the install strategy runs before or after the install listeners. Default: `'after'`.
|
|
36
|
+
* `activateOrder` (`'before' | 'after'`): Whether the activate strategy runs before or after the activate listeners. Default: `'after'`.
|
|
37
|
+
* `fetch` (Object):
|
|
38
|
+
* `enabled` (boolean): Activates/deactivates fetch interception.
|
|
39
|
+
* `router` (Object):
|
|
40
|
+
* `enabled` (boolean): Activates/deactivates the automatic error routing.
|
|
41
|
+
* `codes` (Map<number, RouterCodeConfig>): A Map where keys are HTTP status codes and values are custom response handlers.
|
|
42
|
+
* `push` (Object) — `PushOptions`: Configuration for push notification interception.
|
|
43
|
+
* `enabled` (boolean): Activates/deactivates push event interception.
|
|
44
|
+
* `vapidPublicKey` (string): Base64 URL-safe VAPID public key.
|
|
45
|
+
* `subscribeEndpoint` (string): Backend route that persists subscriptions.
|
|
46
|
+
* `defaultIcon` (string): Fallback notification icon.
|
|
47
|
+
* `defaultBadge` (string): Fallback notification badge.
|
|
48
|
+
* `defaultUrl` (string): Fallback click URL.
|
|
49
|
+
* `sync` (Object) — `SyncOptions`: Configuration for background sync event interception.
|
|
50
|
+
* `enabled` (boolean): Activates/deactivates sync event interception.
|
|
51
|
+
* `messaging` (Object):
|
|
52
|
+
* `enabled` (boolean): Activates/deactivates the `message` event listener.
|
|
53
|
+
|
|
54
|
+
**Parameter: `lgConfig` (Object) — `LoggerOptions`**
|
|
55
|
+
Defines how the engine logs its internal operations.
|
|
56
|
+
* `debugMode` (boolean): If `true`, enables verbose internal logging.
|
|
57
|
+
* `useLogColors` (boolean): If `true`, adds terminal/console colors to logs.
|
|
58
|
+
* `logger` (Object): A custom logger (defaults to `console`).
|
|
59
|
+
|
|
60
|
+
**Why this structure?**
|
|
61
|
+
By separating `config` from `lgConfig`, we separate **business logic** (how the SW behaves) from **developer tools** (how the SW reports its status).
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
import TinyServiceWorkerEngine from 'tiny-essentials/libs/sw/service/TinyServiceWorkerEngine';
|
|
65
|
+
|
|
66
|
+
const engine = new TinyServiceWorkerEngine({
|
|
67
|
+
spaMode: true, // Set to true if you are building a Single Page Application
|
|
68
|
+
lifecycle: {
|
|
69
|
+
installStrategy: 'manual', // 'immediate' | 'wait' | 'manual'
|
|
70
|
+
activateStrategy: 'manual',
|
|
71
|
+
installOrder: 'after',
|
|
72
|
+
activateOrder: 'after',
|
|
73
|
+
},
|
|
74
|
+
fetch: {
|
|
75
|
+
enabled: true,
|
|
76
|
+
router: {
|
|
77
|
+
enabled: true,
|
|
78
|
+
codes: new Map(), // You can add custom status code handlers here
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
messaging: {
|
|
82
|
+
enabled: true,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// This is a mandatory step to start listening to events
|
|
87
|
+
engine.init();
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Why `init()`?**
|
|
91
|
+
The constructor sets up the internal state, but the `.init()` method actually attaches the listeners to the `self` (Service Worker) global scope. Without it, the engine remains idle.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## 🌐 Feature 1: Fetch Interception
|
|
96
|
+
|
|
97
|
+
The engine allows you to intercept requests using three different levels of granularity. All listeners receive a `fetchObj` and `result` as the arguments.
|
|
98
|
+
|
|
99
|
+
**Callback Signature:**
|
|
100
|
+
`async (fetchObj: FetchObj, result: FetchCheckerResult) => Promise<void> | void`
|
|
101
|
+
|
|
102
|
+
### 📦 The `fetchObj` Argument Reference
|
|
103
|
+
When a match is found, the callback is executed with this object:
|
|
104
|
+
|
|
105
|
+
| Property | Type | Description |
|
|
106
|
+
| :--- | :--- | :--- |
|
|
107
|
+
| `event` | `FetchEvent` | The original browser FetchEvent. |
|
|
108
|
+
| `request` | `Request` | The original Request object being intercepted. |
|
|
109
|
+
| `url` | `URL` | The parsed URL object of the request. |
|
|
110
|
+
| `params` | `Record<string, string>` | Key-value pairs extracted from dynamic paths (e.g., `/:id`). |
|
|
111
|
+
| `isSameOrigin` | `boolean` | `true` if the request is from the same origin as the SW. |
|
|
112
|
+
| `replyTo` | `Function` | Helper to reply to the specific client that triggered the fetch. |
|
|
113
|
+
| `replyToAll` | `Function` | Helper to broadcast a message to all open browser tabs. |
|
|
114
|
+
| `replyTemplate` | `Function` | Utility to format a message object before sending. |
|
|
115
|
+
| `error` | `Error` (Optional) | Contains error details if the plugin execution failed. |
|
|
116
|
+
|
|
117
|
+
### ⚙️ The Interception Flow Control (`result` object)
|
|
118
|
+
|
|
119
|
+
When you intercept a request, the engine provides a `result` object as the **second argument** to your callback function. This object is used to communicate back to the engine how the interception should proceed.
|
|
120
|
+
|
|
121
|
+
#### `FetchCheckerResult` Property Reference
|
|
122
|
+
|
|
123
|
+
| Property | Type | Description |
|
|
124
|
+
| :--- | :--- | :--- |
|
|
125
|
+
| `code` | `number` | The HTTP status code associated with the fetch result. This can be used to trigger the Router. |
|
|
126
|
+
| `needValidation` | `boolean` | **The Router Trigger.** If `true`, the engine checks the `code` against the Router configuration. If the code is an error (like 404), the engine will serve the configured error page. |
|
|
127
|
+
| `continueCheck` | `boolean` | **The Flow Controller.** If set to `false`, the engine immediately stops searching for other matching plugins and proceeds with the standard network request. |
|
|
128
|
+
| `customPath` | `string` (optional) | Overrides the path resolved by the Router for this specific request. |
|
|
129
|
+
| `customMsg` | `string` (optional) | Overrides the message sent to the Router for this specific request. |
|
|
130
|
+
| `customResponse` | `Response` (optional) | **The Direct Reply.** If set to a `Response` instance, the engine returns it immediately, bypassing the Router and the network. |
|
|
131
|
+
|
|
132
|
+
> ⚠️ **Important — Priority Order:** The engine evaluates `continueCheck` **before** `customResponse`. If you set `continueCheck = false`, the engine performs the network request and **ignores** any `customResponse` you may have set. To return a custom response, set **only** `customResponse` and leave `continueCheck` as `true` (its default).
|
|
133
|
+
|
|
134
|
+
#### 🛠️ Practical Implementation Examples
|
|
135
|
+
|
|
136
|
+
**1. Returning a Custom Response (`customResponse`)**
|
|
137
|
+
Callbacks do **not** return a `Response`. Instead, you assign it to `result.customResponse`. The engine detects this instance after the plugin chain finishes and returns it to the browser.
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
engine.addFetchUrlListener('/api/secure-data', async (fetchObj, result) => {
|
|
141
|
+
// Perform security logic...
|
|
142
|
+
|
|
143
|
+
// Provide a direct response using customResponse
|
|
144
|
+
result.customResponse = new Response(JSON.stringify({ data: 'secret' }), {
|
|
145
|
+
headers: { 'Content-Type': 'application/json' },
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**2. Stopping the Search (Flow Control)**
|
|
151
|
+
If you want to stop the engine from evaluating other plugins for this request and let the network handle it, set `continueCheck` to `false`.
|
|
152
|
+
|
|
153
|
+
```javascript
|
|
154
|
+
engine.addFetchUrlListener('/api/public', async (fetchObj, result) => {
|
|
155
|
+
// Stop the engine from looking for more matches for this request
|
|
156
|
+
result.continueCheck = false;
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**3. Forcing an Error Page (Router Trigger)**
|
|
161
|
+
If your plugin detects that a resource is missing (even if the browser has not realized it yet), you can force the engine to trigger the Router by setting `needValidation` to `true` and providing a `code`.
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
engine.addFetchUrlListener('/old-api/:version', async (fetchObj, result) => {
|
|
165
|
+
const isLegacy = fetchObj.params.version === 'v1';
|
|
166
|
+
|
|
167
|
+
if (isLegacy) {
|
|
168
|
+
// Force the engine to treat this as a 404 error and trigger the Router
|
|
169
|
+
result.code = 404;
|
|
170
|
+
result.needValidation = true;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**4. Bypassing the Router for Errors**
|
|
176
|
+
Sometimes a request returns a 404, but you want the browser to handle it normally (perhaps to allow a different part of your app to catch the error) instead of showing a custom `404.html` page.
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
engine.addFetchUrlListener('/api/external-service', async (fetchObj, result) => {
|
|
180
|
+
// We do not want the Router to intercept this 404.
|
|
181
|
+
// We want the original 404 response to go straight to the application.
|
|
182
|
+
result.needValidation = false;
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**5. Exact or Parameterized URL Matching**
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
// Intercepting a specific path
|
|
190
|
+
engine.addFetchUrlListener('/api/config', async ({ url }, result) => {
|
|
191
|
+
console.log('Intercepted config request:', url);
|
|
192
|
+
result.customResponse = new Response(JSON.stringify({ status: 'ok' }), {
|
|
193
|
+
headers: { 'Content-Type': 'application/json' },
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Intercepting a parameterized path
|
|
198
|
+
engine.addFetchUrlListener('/user/:id', async ({ params }, result) => {
|
|
199
|
+
const { id } = params; // The engine extracts ':id' automatically
|
|
200
|
+
result.customResponse = new Response(`Hello User ${id}`);
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**6. Regular Expression (RegExp) Matching**
|
|
205
|
+
Use this for patterns that are too complex for simple URL strings.
|
|
206
|
+
|
|
207
|
+
```javascript
|
|
208
|
+
// Intercepting any image request
|
|
209
|
+
engine.addFetchRegExpListener('\\.png$', async ({ url }) => {
|
|
210
|
+
console.log('User requested a PNG:', url.pathname);
|
|
211
|
+
// You could return a placeholder image here
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**7. Global Tracking**
|
|
216
|
+
If you want to perform an action (like logging) on **every single request** without changing the response, use the Global listener.
|
|
217
|
+
|
|
218
|
+
```javascript
|
|
219
|
+
engine.addFetchGlobalListener('analytics', async ({ url }) => {
|
|
220
|
+
console.log(`Request made to: ${url.pathname}`);
|
|
221
|
+
// This does not stop the request; it just "watches" it.
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## 💬 Feature 2: Messaging System
|
|
228
|
+
|
|
229
|
+
The messaging system enables bidirectional communication. Listeners receive a `msg` object as their first argument.
|
|
230
|
+
|
|
231
|
+
### 📦 The `msg` Argument Reference
|
|
232
|
+
When a message is received, the callback is executed with this object:
|
|
233
|
+
|
|
234
|
+
| Property | Type | Description |
|
|
235
|
+
| :--- | :--- | :--- |
|
|
236
|
+
| `event` | `ExtendableMessageEvent` | The original message event. |
|
|
237
|
+
| `clientId` | `string` | The unique ID of the client (tab) that sent the message. |
|
|
238
|
+
| `data` | `Object` | The payload sent by the client (`event.data.data`). |
|
|
239
|
+
| `reply` | `Function` | A convenience method to reply directly to the sender. |
|
|
240
|
+
| `replyTo` | `Function` | Sends a message to a specific `Client`. |
|
|
241
|
+
| `replyToAll` | `Function` | Broadcasts a message to all available clients. |
|
|
242
|
+
| `replyTemplate` | `Function` | Formats the reply into the required `MessagingData` structure. |
|
|
243
|
+
|
|
244
|
+
```javascript
|
|
245
|
+
engine.addMessageListener('GET_USER_DATA', async ({ data, reply }) => {
|
|
246
|
+
const userId = data.id;
|
|
247
|
+
|
|
248
|
+
// Perform some logic
|
|
249
|
+
const userData = { id: userId, name: 'Yasmin' };
|
|
250
|
+
|
|
251
|
+
// Reply directly to the specific window/client that asked
|
|
252
|
+
reply('USER_DATA_RESPONSE', userData);
|
|
253
|
+
});
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Sending a Message from the Website (Main Thread)
|
|
257
|
+
|
|
258
|
+
```javascript
|
|
259
|
+
// In your main app.js
|
|
260
|
+
navigator.serviceWorker.controller.postMessage({
|
|
261
|
+
type: 'GET_USER_DATA',
|
|
262
|
+
data: { id: 123 }
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// Listening for the reply
|
|
266
|
+
navigator.serviceWorker.addEventListener('message', (event) => {
|
|
267
|
+
if (event.data.type === 'USER_DATA_RESPONSE') {
|
|
268
|
+
console.log('Received data:', event.data.data);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Why use `msg.reply()`?**
|
|
274
|
+
In a Service Worker, there might be many open tabs. If you use a broadcast, every tab receives the message. `msg.reply()` ensures that **only the tab that requested the data** receives the answer.
|
|
275
|
+
|
|
276
|
+
### 🚫 Event Blacklist (Third-Party Isolation)
|
|
277
|
+
|
|
278
|
+
The `message` event is shared by every Service Worker in the same scope. A third-party worker can therefore deliver events that reach your handlers. The blacklist drops those events **before** they are dispatched to any registered listener.
|
|
279
|
+
|
|
280
|
+
```javascript
|
|
281
|
+
// Ignore every event emitted by a third-party worker.
|
|
282
|
+
engine.addToEventBlacklist('THIRD_PARTY_PING');
|
|
283
|
+
engine.addToEventBlacklist('analytics:beacon');
|
|
284
|
+
|
|
285
|
+
// Check and remove.
|
|
286
|
+
engine.hasInEventBlacklist('THIRD_PARTY_PING'); // true
|
|
287
|
+
engine.removeFromEventBlacklist('THIRD_PARTY_PING'); // true
|
|
288
|
+
|
|
289
|
+
// Inspect or reset the whole list.
|
|
290
|
+
console.log(engine.eventBlacklist); // ['analytics:beacon']
|
|
291
|
+
engine.clearEventBlacklist();
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
> **Note:** The filter is applied to **incoming** messages only. It never blocks an event that your own code sends with `reply`, `replyTo` or `replyToAll`.
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## 🚦 Feature 3: The HTTP Router
|
|
299
|
+
|
|
300
|
+
The router automatically handles errors by serving specific HTML files based on the HTTP status code.
|
|
301
|
+
|
|
302
|
+
### Customizing Error Pages
|
|
303
|
+
|
|
304
|
+
`addRouterCode` expects a `RouterCodeConfig` object. The recommended way to build one is the `createFetchRes` helper, which wires the `pathGetter` into the correct fetch handler:
|
|
305
|
+
|
|
306
|
+
```javascript
|
|
307
|
+
// If a request returns a 404, serve a custom 404.html file
|
|
308
|
+
engine.addRouterCode(
|
|
309
|
+
404,
|
|
310
|
+
engine.createFetchRes({
|
|
311
|
+
isError: true,
|
|
312
|
+
msg: 'Not Found',
|
|
313
|
+
logMsg: 'User tried to access a non-existent route',
|
|
314
|
+
pathGetter: () => '/errors/custom-404.html',
|
|
315
|
+
}),
|
|
316
|
+
);
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
**Why use this?**
|
|
320
|
+
This mimics how professional web servers (like Apache2) work. It ensures that if an API call or a page load fails, the user sees a beautiful, branded error page instead of a generic browser error.
|
|
321
|
+
|
|
322
|
+
### Inspecting the Router State
|
|
323
|
+
|
|
324
|
+
```javascript
|
|
325
|
+
// Returns a deep clone of the config for a specific code (or undefined)
|
|
326
|
+
const cfg = engine.getRouterCode(404);
|
|
327
|
+
|
|
328
|
+
// Returns the effective config used at runtime (custom code, then default, then 500 fallback)
|
|
329
|
+
const resolved = engine.getCodeCfg(404);
|
|
330
|
+
|
|
331
|
+
// Removes a custom code handler
|
|
332
|
+
engine.removeRouterCode(404);
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### Global Messages and SPA Mode
|
|
336
|
+
|
|
337
|
+
The engine keeps a `globalMsgCode` object that stores the default paths and messages for `200`, `404`, and `500`, plus the `spaPath` (default: `/index.html`).
|
|
338
|
+
|
|
339
|
+
```javascript
|
|
340
|
+
// Read the current global messages (deep clone)
|
|
341
|
+
const messages = engine.globalMsgCode;
|
|
342
|
+
|
|
343
|
+
// Patch the global messages (shallow merge, then deep clone)
|
|
344
|
+
engine.updateGlobalMsgCode({ 404: { path: '/errors/not-found.html' } });
|
|
345
|
+
|
|
346
|
+
// Toggle SPA mode at runtime
|
|
347
|
+
engine.spaMode = true;
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## 🔔 Feature 4: Push & Notifications
|
|
353
|
+
|
|
354
|
+
The engine provides built-in support for the Web Push API and user interaction with browser notifications.
|
|
355
|
+
|
|
356
|
+
### 📡 Push Events
|
|
357
|
+
When a push event is received from the server, the engine automates the following workflow:
|
|
358
|
+
1. **Data Parsing:** It attempts to parse the payload as JSON. If parsing fails, it falls back to a text format.
|
|
359
|
+
2. **Internal Event:** It emits a `push` event, allowing plugins to react to the incoming data.
|
|
360
|
+
3. **Client Broadcast:** It automatically broadcasts a `sw:PushReceived` message to all open browser tabs/clients via `postMessage`. This allows your website's main thread to react to the push event in real-time.
|
|
361
|
+
|
|
362
|
+
### 🖱️ Notification Interaction
|
|
363
|
+
The engine listens for `notificationclick` events. When a user interacts with a notification:
|
|
364
|
+
1. **Event Emission:** The engine emits a `notificationclick` event for internal handling.
|
|
365
|
+
2. **Automatic Cleanup:** The engine automatically calls `event.notification.close()` to dismiss the notification from the user's screen.
|
|
366
|
+
|
|
367
|
+
### 🔕 Notification Close
|
|
368
|
+
When a notification is dismissed by the user (either by clicking the close button or by the system), the engine emits a `notificationclose` event. The same event is emitted when the browser forwards a `sw:NotificationClosed` message to the Service Worker.
|
|
369
|
+
|
|
370
|
+
```javascript
|
|
371
|
+
engine.on('notificationclose', ({ event }) => {
|
|
372
|
+
console.log('Notification closed:', event);
|
|
373
|
+
});
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### 🔁 Subscription Change
|
|
377
|
+
The browser fires a `pushsubscriptionchange` event when the push service rotates the subscription endpoint. Without a handler, the user would silently stop receiving pushes. The engine:
|
|
378
|
+
1. **Emits the event:** `pushsubscriptionchange` is emitted so your code can persist the new subscription.
|
|
379
|
+
2. **Broadcasts a message:** A `sw:PushSubscriptionChange` message is sent to every open client, allowing the main thread to re-sync the subscription with your backend.
|
|
380
|
+
|
|
381
|
+
```javascript
|
|
382
|
+
engine.on('pushsubscriptionchange', ({ event }) => {
|
|
383
|
+
// Persist the new subscription on your backend.
|
|
384
|
+
});
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### 🛠️ Manual Notifications
|
|
388
|
+
You can trigger a native browser notification directly from the Service Worker using the `showNotification` method.
|
|
389
|
+
|
|
390
|
+
```javascript
|
|
391
|
+
// Triggering a manual notification
|
|
392
|
+
await engine.showNotification('New Message', 'You have received a new notification!', {
|
|
393
|
+
icon: '/icons/icon-192x192.png',
|
|
394
|
+
badge: '/icons/badge-72x72.png'
|
|
395
|
+
});
|
|
396
|
+
```
|
|
397
|
+
*Note: This method will throw an error if `push.enabled` is set to `false` in the configuration.*
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
401
|
+
## 🔄 Feature 5: Background Sync
|
|
402
|
+
|
|
403
|
+
The engine provides built-in support for the **Background Sync API**. This allows your application to defer tasks (like sending analytics or syncing data) until the user has a stable internet connection.
|
|
404
|
+
|
|
405
|
+
When a `sync` event is triggered by the browser, the engine:
|
|
406
|
+
1. **Identifies the Task:** It uses the `tag` from the `SyncEvent` to find the specific callback registered for that tag.
|
|
407
|
+
2. **Lifecycle Emission:** It emits `beforeSync` and `afterSync` events.
|
|
408
|
+
3. **Error Handling:** If the callback fails, it emits a `syncError` event.
|
|
409
|
+
|
|
410
|
+
### 🛠️ Implementation Example
|
|
411
|
+
|
|
412
|
+
```javascript
|
|
413
|
+
// Register a handler for a specific sync tag
|
|
414
|
+
engine.addSyncListener('sync-analytics', async ({ event, tag }) => {
|
|
415
|
+
console.log(`Syncing analytics for tag: ${tag}`);
|
|
416
|
+
// Perform the sync logic...
|
|
417
|
+
await performAnalyticsSync();
|
|
418
|
+
});
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## 🔌 Feature 6: The API System (Bidirectional RPC)
|
|
424
|
+
|
|
425
|
+
While the **Messaging System** is fire-and-forget, the **API System** implements a request/response (RPC) pattern between the Service Worker and a specific client. It uses a `correlationId` to match each response to its original request.
|
|
426
|
+
|
|
427
|
+
### 🛠️ Registering a Handler (`onApi`)
|
|
428
|
+
|
|
429
|
+
The handler receives an `ApiHandlerOptions` object and its **return value** (or the resolved value of the returned Promise) is automatically sent back to the caller.
|
|
430
|
+
|
|
431
|
+
```javascript
|
|
432
|
+
engine.onApi('GET_CACHED_USER', async ({ data, clientId, replyApi }) => {
|
|
433
|
+
// 'data' is the payload sent by the browser
|
|
434
|
+
// 'clientId' identifies the tab that made the call
|
|
435
|
+
// 'replyApi' lets you call back into the browser and await a response
|
|
436
|
+
const token = await replyApi('REQUEST_USER_TOKEN', { scope: 'profile' }, 5000);
|
|
437
|
+
|
|
438
|
+
return { id: data.id, name: 'Yasmin', token };
|
|
439
|
+
});
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
### 📤 Calling a Client from the Service Worker (`emitApi`)
|
|
443
|
+
|
|
444
|
+
```javascript
|
|
445
|
+
const client = await sw.clients.get(clientId);
|
|
446
|
+
|
|
447
|
+
// Sends 'REQUEST_USER_TOKEN' to the client and waits up to 5s for a response
|
|
448
|
+
const response = await engine.emitApi(client, 'REQUEST_USER_TOKEN', { scope: 'profile' }, 5000);
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### 🗑️ Removing a Handler (`offApi`)
|
|
452
|
+
|
|
453
|
+
```javascript
|
|
454
|
+
engine.offApi('GET_CACHED_USER');
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### ⏱️ Timeout Behavior
|
|
458
|
+
|
|
459
|
+
If the client does not respond within the timeout window (default: `10000` ms), the returned Promise rejects with an `Error` whose message is `API timeout: <type>`. The pending request is then discarded from the internal `#pendingRequests` map.
|
|
460
|
+
|
|
461
|
+
---
|
|
462
|
+
|
|
463
|
+
## ♻️ Feature 7: Lifecycle Management
|
|
464
|
+
|
|
465
|
+
The engine exposes the `install` and `activate` phases through a configurable strategy system. Each phase has two independent settings:
|
|
466
|
+
|
|
467
|
+
- **Strategy** (`installStrategy` / `activateStrategy`): *what* the engine does with the phase.
|
|
468
|
+
- **Order** (`installOrder` / `activateOrder`): *when* the strategy runs relative to your registered listeners.
|
|
469
|
+
|
|
470
|
+
### 🎯 Strategies
|
|
471
|
+
|
|
472
|
+
| Value | `install` phase | `activate` phase |
|
|
473
|
+
| :--- | :--- | :--- |
|
|
474
|
+
| `'immediate'` *(default)* | Calls `skipWaiting()` right away. | Calls `clients.claim()` right away. |
|
|
475
|
+
| `'wait'` | Never calls `skipWaiting()`. The new worker stays in the `waiting` state until every tab is closed. | Never calls `clients.claim()`. Only future navigations are controlled. |
|
|
476
|
+
| `'manual'` | Does not call `skipWaiting()`. Emits `waitingForActivation` and lets the app decide. | Does not call `clients.claim()`. Emits `waitingForClaim` and lets the app decide. |
|
|
477
|
+
|
|
478
|
+
### 🔀 Order
|
|
479
|
+
|
|
480
|
+
| Value | Behavior |
|
|
481
|
+
| :--- | :--- |
|
|
482
|
+
| `'after'` *(default)* | Listeners run first, then the strategy is resolved. |
|
|
483
|
+
| `'before'` | The strategy is resolved first, then the listeners run. |
|
|
484
|
+
|
|
485
|
+
The `'before'` order is useful when a migration routine must run **before** the new worker takes control of the open tabs. The `'after'` order is the safe default: your listeners always run against a fully initialized worker.
|
|
486
|
+
|
|
487
|
+
### 🛠️ Configuration
|
|
488
|
+
|
|
489
|
+
```javascript
|
|
490
|
+
const engine = new TinyServiceWorkerEngine({
|
|
491
|
+
lifecycle: {
|
|
492
|
+
installStrategy: 'manual',
|
|
493
|
+
activateStrategy: 'manual',
|
|
494
|
+
installOrder: 'after',
|
|
495
|
+
activateOrder: 'after',
|
|
496
|
+
},
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
engine.init();
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
You can also patch the lifecycle configuration at runtime:
|
|
503
|
+
|
|
504
|
+
```javascript
|
|
505
|
+
// Partial patch: omitted keys keep their current value.
|
|
506
|
+
engine.lifecycle = { installOrder: 'before' };
|
|
507
|
+
|
|
508
|
+
// Read a deep clone of the current lifecycle configuration.
|
|
509
|
+
const { installStrategy } = engine.lifecycle;
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
### 🖐️ Manual Activation
|
|
513
|
+
|
|
514
|
+
When a strategy is set to `'manual'`, the engine emits an event and waits. You can then promote the worker on demand:
|
|
515
|
+
|
|
516
|
+
```javascript
|
|
517
|
+
// Service Worker context
|
|
518
|
+
engine.on('waitingForActivation', () => {
|
|
519
|
+
// Notify every open tab that a new version is ready.
|
|
520
|
+
TinyServiceWorkerEngine.replyToAll({ type: 'app:UpdateReady' });
|
|
521
|
+
});
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
```javascript
|
|
525
|
+
// Page context
|
|
526
|
+
navigator.serviceWorker.addEventListener('message', (event) => {
|
|
527
|
+
if (event.data?.type === 'app:UpdateReady') {
|
|
528
|
+
navigator.serviceWorker.getRegistration().then((reg) => {
|
|
529
|
+
// The engine listens for this message and calls skipWaiting() for you.
|
|
530
|
+
reg.waiting?.postMessage({ type: 'sw:SkipWaiting' });
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
### 🧩 Registering Lifecycle Listeners
|
|
537
|
+
|
|
538
|
+
```javascript
|
|
539
|
+
engine.addInstallListener('warm-cache', async ({ event }) => {
|
|
540
|
+
const cache = await caches.open('v2');
|
|
541
|
+
await cache.addAll(['/offline.html']);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
engine.addActivateListener('cleanup', async ({ event }) => {
|
|
545
|
+
const keys = await caches.keys();
|
|
546
|
+
await Promise.all(keys.filter((key) => key !== 'v2').map((key) => caches.delete(key)));
|
|
547
|
+
});
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
A listener that throws is logged and emitted as `installListenerError` or `activateListenerError`. It never blocks the Service Worker lifecycle.
|
|
551
|
+
|
|
552
|
+
### 🔄 Forcing a Client Reload
|
|
553
|
+
|
|
554
|
+
When the new worker changes the routing contract, the open tabs must be reloaded to stay consistent. Use `reloadClients` to navigate every controlled client at once:
|
|
555
|
+
|
|
556
|
+
```javascript
|
|
557
|
+
await engine.reloadClients(); // Reloads the current URL of each client
|
|
558
|
+
await engine.reloadClients('/'); // Or navigate them all to a specific URL
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
---
|
|
562
|
+
|
|
563
|
+
## 🧰 Static Utilities
|
|
564
|
+
|
|
565
|
+
These static methods are exposed on the class itself and can be used without instantiating the engine.
|
|
566
|
+
|
|
567
|
+
| Method | Description |
|
|
568
|
+
| :--- | :--- |
|
|
569
|
+
| `TinyServiceWorkerEngine.isNavigate(req)` | Returns `true` if the request mode is `'navigate'`. |
|
|
570
|
+
| `TinyServiceWorkerEngine.isSameOrigin(data)` | Returns `true` if the given `Request` or `URL` shares the Service Worker's origin. |
|
|
571
|
+
| `TinyServiceWorkerEngine.replyTemplate(type, payload)` | Formats a message into the standard `MessagingData` shape. Throws if `type` starts with `sw:`. |
|
|
572
|
+
| `TinyServiceWorkerEngine.replyTo(client, type, payload)` | Sends a message to a single `Client`. |
|
|
573
|
+
| `TinyServiceWorkerEngine.replyToAll({ type, data, options })` | Broadcasts a message to all matching clients. |
|
|
574
|
+
|
|
575
|
+
### Reserved Event Types
|
|
576
|
+
|
|
577
|
+
Any message type that starts with the `sw:` prefix is **reserved** for internal PWA lifecycle management. Passing such a type to `replyTemplate` or `replyTo` will throw a `TypeError`.
|
|
578
|
+
|
|
579
|
+
The engine uses the following internal types:
|
|
580
|
+
|
|
581
|
+
| Type | Direction | Description |
|
|
582
|
+
| :--- | :--- | :--- |
|
|
583
|
+
| `sw:ApiResponse` | Browser → SW | Carries the response of an `emitApi` call. |
|
|
584
|
+
| `sw:NotificationClicked` | Browser → SW | Forwards a notification click to the engine. |
|
|
585
|
+
| `sw:NotificationClosed` | Browser → SW | Forwards a notification close to the engine. |
|
|
586
|
+
| `sw:PrepareUpdate` | Browser → SW | Asks the engine to fetch and install a new version. |
|
|
587
|
+
| `sw:Updated` | SW → Browser | The update finished and the new worker is waiting. |
|
|
588
|
+
| `sw:UpdateError` | SW → Browser | The update failed. |
|
|
589
|
+
| `sw:SkipWaiting` | Browser → SW | Promotes the waiting worker to active. |
|
|
590
|
+
| `sw:PushReceived` | SW → Browser | A push event was received. |
|
|
591
|
+
| `sw:PushSubscriptionChange` | SW → Browser | The push subscription changed and must be re-synced. |
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
## ⚙️ Configuration & Security
|
|
596
|
+
|
|
597
|
+
### Strict Validation
|
|
598
|
+
The engine is designed with "Fail Fast" principles. If you pass an incorrect type (e.g., passing a `string` where a `boolean` is expected in the config), the engine will throw a `TypeError` immediately.
|
|
599
|
+
|
|
600
|
+
**Why?**
|
|
601
|
+
In Service Workers, debugging is notoriously difficult because they run in the background. By throwing errors during initialization, we catch configuration mistakes immediately during development.
|
|
602
|
+
|
|
603
|
+
### SPA Mode
|
|
604
|
+
If `spaMode` is set to `true`, the engine adjusts how paths are calculated. This is essential for frameworks like React, Vue, or Angular where the routing is handled on the client side.
|
|
605
|
+
|
|
606
|
+
---
|
|
607
|
+
|
|
608
|
+
## 📝 API Reference Summary
|
|
609
|
+
|
|
610
|
+
To make navigation easier, the API is divided into functional modules: **Fetch Management**, **Messaging**, **Router Management**, **API (RPC)**, and **Lifecycle & State**.
|
|
611
|
+
|
|
612
|
+
### 🌐 1. Fetch Management
|
|
613
|
+
|
|
614
|
+
| Method | Purpose | Arguments | Returns |
|
|
615
|
+
| :--- | :--- | :--- | :--- |
|
|
616
|
+
| **Registration** | | | |
|
|
617
|
+
| `addFetchUrlListener` | Registers an exact or parameterized URL match. | `type (string)`, `callback` | `void` |
|
|
618
|
+
| `addFetchRegExpListener` | Registers a pattern match via Regex. | `type (string)`, `callback` | `void` |
|
|
619
|
+
| `addFetchGlobalListener` | Registers a listener for every request. | `type (string)`, `callback` | `void` |
|
|
620
|
+
| **Retrieval & Check** | | | |
|
|
621
|
+
| `getFetchUrlListener` | Retrieves a specific URL listener. | `type (string)` | `callback \| undefined` |
|
|
622
|
+
| `getFetchRegExpListener` | Retrieves a specific RegExp listener. | `type (string)` | `callback \| undefined` |
|
|
623
|
+
| `getFetchGlobalListener` | Retrieves a specific global listener. | `type (string)` | `callback \| undefined` |
|
|
624
|
+
| `hasFetchUrl` | Checks if a URL listener exists. | `type (string)` | `boolean` |
|
|
625
|
+
| `hasFetchRegExp` | Checks if a RegExp listener exists. | `type (string)` | `boolean` |
|
|
626
|
+
| `hasFetchGlobal` | Checks if a global listener exists. | `type (string)` | `boolean` |
|
|
627
|
+
| **Removal & Cleanup** | | | |
|
|
628
|
+
| `removeFetchUrlListener` | Removes a specific URL listener. | `type (string)` | `boolean` |
|
|
629
|
+
| `removeFetchRegExpListener` | Removes a specific RegExp listener. | `type (string)` | `boolean` |
|
|
630
|
+
| `removeFetchGlobalListener` | Removes a specific global listener. | `type (string)` | `boolean` |
|
|
631
|
+
| `clearFetchUrls` | Wipes all registered URL listeners. | None | `void` |
|
|
632
|
+
| `clearFetchRegExps` | Wipes all registered RegExp listeners. | None | `void` |
|
|
633
|
+
| `clearFetchGlobals` | Wipes all registered global listeners. | None | `void` |
|
|
634
|
+
| **Metadata** | | | |
|
|
635
|
+
| `fetchUrlSize` | Returns the count of URL listeners. | None | `number` |
|
|
636
|
+
| `fetchRegExpSize` | Returns the count of RegExp listeners. | None | `number` |
|
|
637
|
+
| `fetchGlobalSize` | Returns the count of global listeners. | None | `number` |
|
|
638
|
+
|
|
639
|
+
### 💬 2. Message Management
|
|
640
|
+
|
|
641
|
+
| Method | Purpose | Arguments | Returns |
|
|
642
|
+
| :--- | :--- | :--- | :--- |
|
|
643
|
+
| **Registration** | | | |
|
|
644
|
+
| `addMessageListener` | Registers a listener for a message type. | `type (string)`, `callback` | `void` |
|
|
645
|
+
| **Retrieval & Check** | | | |
|
|
646
|
+
| `getMessageListener` | Retrieves a specific message listener. | `type (string)` | `callback \| undefined` |
|
|
647
|
+
| `hasMessageListener` | Checks if a message listener exists. | `type (string)` | `boolean` |
|
|
648
|
+
| **Removal & Cleanup** | | | |
|
|
649
|
+
| `removeMessageListener` | Removes a specific message listener. | `type (string)` | `boolean` |
|
|
650
|
+
| `clearMessageListeners` | Wipes all registered message listeners. | None | `void` |
|
|
651
|
+
| **Event Blacklist** | | | |
|
|
652
|
+
| `addToEventBlacklist` | Ignores every incoming event with the given name. | `type (string)` | `void` |
|
|
653
|
+
| `removeFromEventBlacklist` | Removes an event name from the blacklist. | `type (string)` | `boolean` |
|
|
654
|
+
| `hasInEventBlacklist` | Checks whether an event name is blacklisted. | `type (string)` | `boolean` |
|
|
655
|
+
| `clearEventBlacklist` | Wipes the entire blacklist. | None | `void` |
|
|
656
|
+
| `eventBlacklist` | Returns a copy of every blacklisted event name. | None | `string[]` |
|
|
657
|
+
| **Metadata** | | | |
|
|
658
|
+
| `messagesSize` | Returns the count of message listeners. | None | `number` |
|
|
659
|
+
|
|
660
|
+
### 🔌 3. API (RPC) Management
|
|
661
|
+
|
|
662
|
+
| Method | Purpose | Arguments | Returns |
|
|
663
|
+
| :--- | :--- | :--- | :--- |
|
|
664
|
+
| `onApi` | Registers a handler for API calls coming from the browser. | `type (string)`, `callback` | `void` |
|
|
665
|
+
| `offApi` | Removes a registered API handler. | `type (string)` | `boolean` |
|
|
666
|
+
| `emitApi` | Sends a request to a specific client and waits for a response. | `client (Client)`, `type (string)`, `data (any)`, `timeout (number)` | `Promise<any>` |
|
|
667
|
+
|
|
668
|
+
### 🚦 4. Router Management
|
|
669
|
+
|
|
670
|
+
| Method | Purpose | Arguments | Returns |
|
|
671
|
+
| :--- | :--- | :--- | :--- |
|
|
672
|
+
| `addRouterCode` | Adds/updates a custom handler for a code. | `code (number)`, `config (RouterCodeConfig)` | `void` |
|
|
673
|
+
| `removeRouterCode` | Removes a custom code handler. | `code (number)` | `boolean` |
|
|
674
|
+
| `getRouterCode` | Retrieves a deep clone of a code config. | `code (number)` | `RouterCodeConfig \| undefined` |
|
|
675
|
+
| `getCodeCfg` | Resolves the effective config for a code (custom → default → 500). | `code (number)` | `RouterCodeConfig` |
|
|
676
|
+
| `updateGlobalMsgCode` | Merges a partial patch into the global message map. | `patch (Partial<GlobalMsgCode>)` | `void` |
|
|
677
|
+
| `createFetchRes` | Builds a `RouterCodeConfig` from a `pathGetter`. | `{ isError, msg, logMsg, pathGetter }` | `RouterCodeConfig` |
|
|
678
|
+
| `globalPathGetter` | Returns the SPA path or the original path. | `path (string)` | `string` |
|
|
679
|
+
|
|
680
|
+
### 🔄 5. Sync Management
|
|
681
|
+
|
|
682
|
+
| Method | Purpose | Arguments | Returns |
|
|
683
|
+
| :--- | :--- | :--- | :--- |
|
|
684
|
+
| **Registration** | | | |
|
|
685
|
+
| `addSyncListener` | Registers a handler for a specific sync tag. | `tag (string)`, `callback` | `void` |
|
|
686
|
+
| **Retrieval & Check** | | | |
|
|
687
|
+
| `syncListenerSize` | Returns the count of registered sync listeners. | None | `number` |
|
|
688
|
+
| **Removal & Cleanup** | | | |
|
|
689
|
+
| `removeSyncListener` | Removes a sync handler. | `tag (string)` | `boolean` |
|
|
690
|
+
| `clearSyncListeners` | Wipes all registered sync listeners. | None | `void` |
|
|
691
|
+
|
|
692
|
+
### ⚙️ 6. Lifecycle, State & Utility
|
|
693
|
+
|
|
694
|
+
| Method / Property | Purpose | Arguments | Returns |
|
|
695
|
+
| :--- | :--- | :--- | :--- |
|
|
696
|
+
| `init` | Initializes the Service Worker event listeners. | None | `void` |
|
|
697
|
+
| `started` | Whether `init()` has already been called. | None | `boolean` |
|
|
698
|
+
| `spaMode` | Gets/sets SPA mode at runtime. | `boolean` | `boolean` |
|
|
699
|
+
| `config` | Gets a deep clone of the config / applies a partial update. | `Partial<PartialServiceWorkerSettings>` | `ServiceWorkerSettings` |
|
|
700
|
+
| `globalMsgCode` | Gets/sets the global message map. | `Object` | `Object` |
|
|
701
|
+
| `showNotification` | Displays a native notification to the user. | `title (string)`, `body (string)`, `options (Object)` | `Promise<void>` |
|
|
702
|
+
|
|
703
|
+
### ♻️ 7. Lifecycle Management
|
|
704
|
+
|
|
705
|
+
| Method / Property | Purpose | Arguments | Returns |
|
|
706
|
+
| :--- | :--- | :--- | :--- |
|
|
707
|
+
| `lifecycle` | Gets a deep clone / merges a partial lifecycle config. | `Partial<LifecycleOptions>` | `LifecycleOptions` |
|
|
708
|
+
| `skipWaiting` | Promotes the waiting worker to active. | `event? (ExtendableEvent)` | `Promise<boolean>` |
|
|
709
|
+
| `claimClients` | Makes the active worker control the open clients. | `query? (ClientQueryOptions)` | `Promise<readonly Client[]>` |
|
|
710
|
+
| `reloadClients` | Navigates every controlled client to a URL. | `url? (string)` | `Promise<number>` |
|
|
711
|
+
| **Install Listeners** | | | |
|
|
712
|
+
| `addInstallListener` | Registers an `install` listener. | `tag (string)`, `callback` | `void` |
|
|
713
|
+
| `removeInstallListener` | Removes an `install` listener. | `tag (string)` | `boolean` |
|
|
714
|
+
| `getInstallListener` | Retrieves an `install` listener. | `tag (string)` | `callback \| undefined` |
|
|
715
|
+
| `hasInstallListener` | Checks if an `install` listener exists. | `tag (string)` | `boolean` |
|
|
716
|
+
| `clearInstallListeners` | Wipes all `install` listeners. | None | `void` |
|
|
717
|
+
| `installListenerSize` | Returns the count of `install` listeners. | None | `number` |
|
|
718
|
+
| **Activate Listeners** | | | |
|
|
719
|
+
| `addActivateListener` | Registers an `activate` listener. | `tag (string)`, `callback` | `void` |
|
|
720
|
+
| `removeActivateListener` | Removes an `activate` listener. | `tag (string)` | `boolean` |
|
|
721
|
+
| `getActivateListener` | Retrieves an `activate` listener. | `tag (string)` | `callback \| undefined` |
|
|
722
|
+
| `hasActivateListener` | Checks if an `activate` listener exists. | `tag (string)` | `boolean` |
|
|
723
|
+
| `clearActivateListeners` | Wipes all `activate` listeners. | None | `void` |
|
|
724
|
+
| `activateListenerSize` | Returns the count of `activate` listeners. | None | `number` |
|
|
725
|
+
|
|
726
|
+
---
|
|
727
|
+
|
|
728
|
+
## 🔗 Full PWA Integration (Client-Side)
|
|
729
|
+
|
|
730
|
+
To achieve a complete and seamless Progressive Web App (PWA) experience, it is highly recommended to use the `TinyServiceWorkerEngine` in conjunction with our dedicated client-side module.
|
|
731
|
+
|
|
732
|
+
While the `TinyServiceWorkerEngine` manages the background logic and network interception within the **Service Worker context**, the **`TinyServiceWorker`** module provides the necessary interface to interact with the engine from your **Main Thread (the browser window)**.
|
|
733
|
+
|
|
734
|
+
### 📍 Recommended Next Step
|
|
735
|
+
To learn how to communicate with the engine from your web application, please refer to the integration guide here:
|
|
736
|
+
👉 [TinyServiceWorker](../browser/TinyServiceWorker.md)
|
|
737
|
+
|
|
738
|
+
**Why integrate both?**
|
|
739
|
+
Using both modules allows you to fully leverage the **Messaging System**. This enables your website to:
|
|
740
|
+
1. **Listen** to events triggered by the Service Worker.
|
|
741
|
+
2. **Trigger** updates and lifecycle events.
|
|
742
|
+
3. **Exchange data** between the background process and the user interface in real-time.
|
|
743
|
+
|
|
744
|
+
---
|
|
745
|
+
|
|
746
|
+
## 🧩 TinyPlugin Ecosystem Integration
|
|
747
|
+
|
|
748
|
+
`TinyServiceWorker` is not a standalone utility; it is a first-class citizen of the **[TinyPlugin](../../plugin/TinyPlugin.md)** architecture.
|