@enhance-eng/sandbox 0.5.5 → 0.6.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 CHANGED
@@ -12,7 +12,17 @@ npm install @enhance-eng/sandbox
12
12
 
13
13
  ## Next.js (App Router)
14
14
 
15
- To enable Enhance in your Next.js application and resolve hydration errors, add the `EnhanceScripts` component to your root layout.
15
+ Generate the service worker file, then add the `EnhanceScripts` component to your root layout.
16
+
17
+ **Step 1:** Generate the service worker:
18
+
19
+ ```bash
20
+ npx enhance-sandbox init --publishable-key pk_your_key
21
+ ```
22
+
23
+ This writes `public/enhance-sw.js`. Commit the file to your repository.
24
+
25
+ **Step 2:** Add the component to your root layout:
16
26
 
17
27
  ```tsx
18
28
  // app/layout.tsx
@@ -30,11 +40,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
30
40
  }
31
41
  ```
32
42
 
33
- This component ensures:
34
-
35
- - The Service Worker is installed reliably.
36
- - HMR works correctly through the preview proxy.
37
- - React hydrates without mismatch errors by rendering the scripts natively.
43
+ The `EnhanceScripts` component registers the service worker, bootstraps the overlay, and renders scripts natively so React hydrates without mismatch errors.
38
44
 
39
45
  ## Vite
40
46
 
@@ -42,29 +48,56 @@ Add the plugin to your Vite config:
42
48
 
43
49
  ```typescript
44
50
  // vite.config.ts
51
+ import { defineConfig } from "vite";
45
52
  import { enhance } from "@enhance-eng/sandbox/vite";
46
53
 
47
54
  export default defineConfig({
48
- plugins: [enhance()],
55
+ plugins: [
56
+ enhance({
57
+ publishableKey: "pk_your_key",
58
+ }),
59
+ ],
49
60
  });
50
61
  ```
51
62
 
52
- That's it. The plugin handles everything automatically.
63
+ The plugin generates the service worker, serves it in dev, emits it as a build asset, and injects the registration script automatically.
53
64
 
54
65
  ## Other Build Tools
55
66
 
56
- For non-Vite setups, use the CLI to copy the required assets to your public directory:
67
+ For non-Vite, non-Next.js setups, generate the service worker with the CLI, then register it in your app.
68
+
69
+ **Step 1:** Generate the service worker:
57
70
 
58
71
  ```bash
59
- npx enhance-sandbox prepare-sw --public-dir ./public
72
+ npx enhance-sandbox init --publishable-key pk_your_key
60
73
  ```
61
74
 
62
- Then initialize Enhance in your application entry point:
75
+ **Step 2:** Register it in your application entry point:
63
76
 
64
77
  ```typescript
65
- import { Enhance } from "@enhance-eng/sandbox";
78
+ import { enhance } from "@enhance-eng/sandbox";
66
79
 
67
- Enhance.init();
80
+ enhance();
68
81
  ```
69
82
 
70
- Run the CLI as part of your build process to keep assets up to date.
83
+ ## Existing Service Worker
84
+
85
+ If your app already uses a service worker (e.g. for offline support or caching), pass its URL with the `serviceWorker` option so Enhance registers only during playground sessions and falls back to your service worker for normal visitors.
86
+
87
+ **Vite:**
88
+
89
+ ```typescript
90
+ enhance({ publishableKey: "pk_your_key", serviceWorker: "/sw.js" });
91
+ ```
92
+
93
+ **Next.js:**
94
+
95
+ ```tsx
96
+ <EnhanceScripts serviceWorker="/sw.js" />
97
+ ```
98
+
99
+ **Other:**
100
+
101
+ ```typescript
102
+ enhance({ serviceWorker: "/sw.js" });
103
+ ```
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const _0x18a81e=_0x318d;(function(_0x415aab,_0x23f55b){const _0x2c9811=_0x318d,_0x405cdb=_0x415aab();while(!![]){try{const _0x689c0f=parseInt(_0x2c9811(0x16a))/0x1+-parseInt(_0x2c9811(0x15b))/0x2+-parseInt(_0x2c9811(0x15d))/0x3+-parseInt(_0x2c9811(0x152))/0x4*(-parseInt(_0x2c9811(0x160))/0x5)+-parseInt(_0x2c9811(0x14e))/0x6+-parseInt(_0x2c9811(0x165))/0x7+parseInt(_0x2c9811(0x161))/0x8*(parseInt(_0x2c9811(0x168))/0x9);if(_0x689c0f===_0x23f55b)break;else _0x405cdb['push'](_0x405cdb['shift']());}catch(_0x315f51){_0x405cdb['push'](_0x405cdb['shift']());}}}(_0xbaed,0xc7347));import{Command}from'commander';import{writeFile,mkdir}from'fs/promises';function _0xbaed(){const _0x5ea0d2=['description','parseAsync','3830769RAbYre','Enhance\x20sandbox\x20utility\x20CLI','423253CYMXdc','cdnUrl','--publishable-key\x20<key>','--output\x20<path>','7587384MhcXum','Publishable\x20key\x20for\x20enhance','stdout','name','656212mvICMP','Generate\x20the\x20service\x20worker\x20loader\x20file','action','Created\x20','publishableKey','0.0.0','public/enhance-sw.js','output','Output\x20path\x20for\x20the\x20service\x20worker\x20file','1382208OPTkgl','utf-8','735966yftEGc','option','CDN\x20URL\x20for\x20enhance\x20assets\x20(defaults\x20to\x20production)','45WyiMed','32UbwWqX','enhance-sandbox','https://cdn.enhancelabs.ai','cwd','4097527fWIWvm'];_0xbaed=function(){return _0x5ea0d2;};return _0xbaed();}function _0x318d(_0x407a37,_0x356c5d){_0x407a37=_0x407a37-0x14e;const _0xbaed26=_0xbaed();let _0x318dec=_0xbaed26[_0x407a37];return _0x318dec;}import{dirname,resolve}from'path';import _0x2bd2e1 from'dedent';var DEFAULT_CDN_URL=_0x18a81e(0x163);function buildSwSource(_0xa859c0){const _0x3555e2=_0x18a81e,_0x596367=_0xa859c0[_0x3555e2(0x16b)]??DEFAULT_CDN_URL;return _0x2bd2e1`
4
- self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON['stringify'](_0xa859c0[_0x3555e2(0x156)])};
5
- self.__ENHANCE_CDN__ = ${JSON['stringify'](_0x596367)};
3
+ const _0x31af8d=_0x49ab;(function(_0x502963,_0x5c2180){const _0x135f3b=_0x49ab,_0x168507=_0x502963();while(!![]){try{const _0x221103=parseInt(_0x135f3b(0xfe))/0x1*(parseInt(_0x135f3b(0xfb))/0x2)+-parseInt(_0x135f3b(0xf5))/0x3+-parseInt(_0x135f3b(0xeb))/0x4+-parseInt(_0x135f3b(0xe9))/0x5+-parseInt(_0x135f3b(0x106))/0x6*(-parseInt(_0x135f3b(0xf6))/0x7)+parseInt(_0x135f3b(0xf2))/0x8*(parseInt(_0x135f3b(0xf7))/0x9)+parseInt(_0x135f3b(0x109))/0xa;if(_0x221103===_0x5c2180)break;else _0x168507['push'](_0x168507['shift']());}catch(_0x3279aa){_0x168507['push'](_0x168507['shift']());}}}(_0x3c5f,0x1da02));import{Command}from'commander';import{writeFile,mkdir}from'fs/promises';import{dirname,resolve}from'path';function _0x3c5f(){const _0xd61fe3=['utf-8','write','19384yfxiZD','--publishable-key\x20<key>','version','20kjGbHa','requiredOption','CDN\x20URL\x20for\x20enhance\x20assets\x20(defaults\x20to\x20production)','public/enhance-sw.js','output','action','option','--cdn-url\x20<url>','211530zdgdOU','cdnUrl','init','695220QLDdIG','stringify','Generate\x20the\x20service\x20worker\x20loader\x20file','name','--service-worker\x20<url>','1200815pSoPzM','serviceWorker','598268SfaAHa','enhance-sandbox','description','\x0aRegister\x20with:\x0a\x0a\x20\x20import\x20{\x20enhance\x20}\x20from\x20\x22@enhance-eng/sandbox\x22;\x0a\x20\x20enhance({\x20serviceWorker:\x20','Publishable\x20key\x20for\x20enhance','Enhance\x20sandbox\x20utility\x20CLI','URL\x20of\x20your\x20existing\x20service\x20worker\x20(e.g.\x20/sw.js)','48tLFGZm','\x20});\x0a','publishableKey','52869wZwkQe','7FNPxHJ','345123QAGBWh','--output\x20<path>'];_0x3c5f=function(){return _0xd61fe3;};return _0x3c5f();}import _0x5f4d43 from'dedent';var DEFAULT_CDN_URL='https://cdn.enhancelabs.ai';function _0x49ab(_0x4bad38,_0x306c6b){_0x4bad38=_0x4bad38-0xe8;const _0x3c5f32=_0x3c5f();let _0x49ab88=_0x3c5f32[_0x4bad38];return _0x49ab88;}function buildSwSource(_0x5e0b58){const _0x149dcd=_0x49ab,_0xf49fdb=_0x5e0b58[_0x149dcd(0x107)]??DEFAULT_CDN_URL;return _0x5f4d43`
4
+ self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON['stringify'](_0x5e0b58[_0x149dcd(0xf4)])};
5
+ self.__ENHANCE_CDN__ = ${JSON[_0x149dcd(0x10a)](_0xf49fdb)};
6
6
  importScripts(self.__ENHANCE_CDN__ + "/loader/loader.v1.js");
7
- `;}var program=new Command();program[_0x18a81e(0x151)](_0x18a81e(0x162))[_0x18a81e(0x166)](_0x18a81e(0x169))['version'](_0x18a81e(0x157)),program['command']('init')['description'](_0x18a81e(0x153))['requiredOption'](_0x18a81e(0x16c),_0x18a81e(0x14f))[_0x18a81e(0x15e)]('--cdn-url\x20<url>',_0x18a81e(0x15f))[_0x18a81e(0x15e)](_0x18a81e(0x16d),_0x18a81e(0x15a),_0x18a81e(0x158))[_0x18a81e(0x154)](async _0xa35646=>{const _0x3cc0a9=_0x18a81e,_0x8ae17=resolve(process[_0x3cc0a9(0x164)](),_0xa35646['output']),_0x5a9cc9=buildSwSource({'publishableKey':_0xa35646['publishableKey'],'cdnUrl':_0xa35646[_0x3cc0a9(0x16b)]});await mkdir(dirname(_0x8ae17),{'recursive':!![]}),await writeFile(_0x8ae17,_0x5a9cc9,_0x3cc0a9(0x15c)),process[_0x3cc0a9(0x150)]['write'](_0x3cc0a9(0x155)+_0xa35646[_0x3cc0a9(0x159)]+'\x0a');}),program[_0x18a81e(0x167)]();
7
+ `;}var program=new Command();program[_0x31af8d(0x10c)](_0x31af8d(0xec))['description'](_0x31af8d(0xf0))[_0x31af8d(0xfd)]('0.0.0'),program['command'](_0x31af8d(0x108))[_0x31af8d(0xed)](_0x31af8d(0x10b))[_0x31af8d(0xff)](_0x31af8d(0xfc),_0x31af8d(0xef))['option'](_0x31af8d(0x105),_0x31af8d(0x100))[_0x31af8d(0x104)](_0x31af8d(0xf8),'Output\x20path\x20for\x20the\x20service\x20worker\x20file',_0x31af8d(0x101))['option'](_0x31af8d(0xe8),_0x31af8d(0xf1))[_0x31af8d(0x103)](async _0x55ec5d=>{const _0x2a3257=_0x31af8d,_0x39fe77=resolve(process['cwd'](),_0x55ec5d[_0x2a3257(0x102)]),_0x252b8c=buildSwSource({'publishableKey':_0x55ec5d[_0x2a3257(0xf4)],'cdnUrl':_0x55ec5d[_0x2a3257(0x107)]});await mkdir(dirname(_0x39fe77),{'recursive':!![]}),await writeFile(_0x39fe77,_0x252b8c,_0x2a3257(0xf9)),process['stdout']['write']('Created\x20'+_0x55ec5d['output']+'\x0a'),_0x55ec5d['serviceWorker']&&process['stdout'][_0x2a3257(0xfa)](_0x2a3257(0xee)+JSON['stringify'](_0x55ec5d[_0x2a3257(0xea)])+_0x2a3257(0xf3));}),program['parseAsync']();
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { E as EnhanceOptions } from './sw-source-CUI8GVoj.js';
2
2
 
3
- declare function enhance(): void;
3
+ declare function enhance(options?: {
4
+ serviceWorker?: string;
5
+ }): void;
4
6
 
5
7
  export { enhance };
package/dist/index.js CHANGED
@@ -1 +1,13 @@
1
- function _0x239a(){var _0x3647fb=['createElement','23441kHieWR','head','1538028emKEwE','387882vYuGqi','navigator.serviceWorker?.register(\x22','2qzeBCl','appendChild','40KwKFrz','22746zZyzCN','script','5EMCgQw','1910TUkyXU','textContent','1431269NrwHGC','612144BndaUv','189600fOvFus'];_0x239a=function(){return _0x3647fb;};return _0x239a();}(function(_0x52c95e,_0x474c0e){var _0x4edd19=_0xf3e0,_0x2905b5=_0x52c95e();while(!![]){try{var _0xc4031a=-parseInt(_0x4edd19(0x1a5))/0x1+-parseInt(_0x4edd19(0x1ac))/0x2*(-parseInt(_0x4edd19(0x1af))/0x3)+parseInt(_0x4edd19(0x1a4))/0x4*(-parseInt(_0x4edd19(0x1a0))/0x5)+-parseInt(_0x4edd19(0x1a9))/0x6+parseInt(_0x4edd19(0x1a3))/0x7+parseInt(_0x4edd19(0x1ae))/0x8*(parseInt(_0x4edd19(0x1aa))/0x9)+parseInt(_0x4edd19(0x1a1))/0xa*(parseInt(_0x4edd19(0x1a7))/0xb);if(_0xc4031a===_0x474c0e)break;else _0x2905b5['push'](_0x2905b5['shift']());}catch(_0x149f85){_0x2905b5['push'](_0x2905b5['shift']());}}}(_0x239a,0x39842));function _0xf3e0(_0x3336db,_0xd678e5){_0x3336db=_0x3336db-0x1a0;var _0x239aab=_0x239a();var _0xf3e0c3=_0x239aab[_0x3336db];return _0xf3e0c3;}var SW_PATH='/enhance-sw.js';function enhance(){var _0x54be66=_0xf3e0;const _0x1d45af=document[_0x54be66(0x1a6)](_0x54be66(0x1b0));_0x1d45af[_0x54be66(0x1a2)]=_0x54be66(0x1ab)+SW_PATH+'\x22)',document[_0x54be66(0x1a8)][_0x54be66(0x1ad)](_0x1d45af);}export{enhance};
1
+ function _0x37a4(){var _0x10ff3b=['serviceWorker','textContent','head','navigator.serviceWorker?.register(\x22','4390857baNFsl','16nGqXVo','1xtkIlr','stringify','1870120OnpSut','enhance_interop','3330912Mynnnk','904920QaqBiX','enhance_playground','script','createElement','102162FdEyqP','appendChild','1277292HHETsT','840308ebeAMM'];_0x37a4=function(){return _0x10ff3b;};return _0x37a4();}var _0x490382=_0x2dcc;(function(_0x22b375,_0x328357){var _0x427c50=_0x2dcc,_0x3188a9=_0x22b375();while(!![]){try{var _0x3c7300=parseInt(_0x427c50(0x193))/0x1*(parseInt(_0x427c50(0x18b))/0x2)+parseInt(_0x427c50(0x189))/0x3+-parseInt(_0x427c50(0x182))/0x4+-parseInt(_0x427c50(0x185))/0x5+parseInt(_0x427c50(0x184))/0x6+parseInt(_0x427c50(0x18c))/0x7*(parseInt(_0x427c50(0x192))/0x8)+-parseInt(_0x427c50(0x191))/0x9;if(_0x3c7300===_0x328357)break;else _0x3188a9['push'](_0x3188a9['shift']());}catch(_0x30be21){_0x3188a9['push'](_0x3188a9['shift']());}}}(_0x37a4,0x50f21));import _0xde264c from'dedent';function _0x2dcc(_0x303b99,_0x210496){_0x303b99=_0x303b99-0x181;var _0x37a423=_0x37a4();var _0x2dcce8=_0x37a423[_0x303b99];return _0x2dcce8;}var SW_PATH='/enhance-sw.js',PLAYGROUND_COOKIE=_0x490382(0x186),INTEROP_QUERY_PARAM=_0x490382(0x183),INTEROP_QUERY_VALUE='1';function buildRegistrationScript({serviceWorker:_0x21a0a0}){var _0x5377c8=_0x490382;if(!_0x21a0a0)return _0x5377c8(0x190)+SW_PATH+'\x22);';const _0x949c8e=SW_PATH+'?'+INTEROP_QUERY_PARAM+'='+INTEROP_QUERY_VALUE;return _0xde264c`
2
+ (function() {
3
+ var sw = navigator.serviceWorker;
4
+ if (!sw) return;
5
+ var hasParam = new URLSearchParams(location.search).has("playground");
6
+ var hasCookie = document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1;
7
+ if (hasParam || hasCookie) {
8
+ sw.register("${_0x949c8e}");
9
+ return;
10
+ }
11
+ sw.register(${JSON[_0x5377c8(0x181)](_0x21a0a0)});
12
+ })();
13
+ `;}function enhance(_0x39b02c){var _0x9f3cc2=_0x490382;const _0x5f20a5=document[_0x9f3cc2(0x188)](_0x9f3cc2(0x187));_0x5f20a5[_0x9f3cc2(0x18e)]=buildRegistrationScript({'serviceWorker':_0x39b02c?.[_0x9f3cc2(0x18d)]}),document[_0x9f3cc2(0x18f)][_0x9f3cc2(0x18a)](_0x5f20a5);}export{enhance};
@@ -1,7 +1,8 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
 
3
- declare function EnhanceScripts({ nonce }: {
3
+ declare function EnhanceScripts({ nonce, serviceWorker }: {
4
4
  nonce?: string;
5
+ serviceWorker?: string;
5
6
  }): react_jsx_runtime.JSX.Element;
6
7
 
7
8
  export { EnhanceScripts };
@@ -1 +1,63 @@
1
- (function(_0xcbfe14,_0x4baa4a){var _0x5dc3a8=_0x5893,_0x5289c8=_0xcbfe14();while(!![]){try{var _0x776a8b=-parseInt(_0x5dc3a8(0x1b0))/0x1+parseInt(_0x5dc3a8(0x1aa))/0x2+-parseInt(_0x5dc3a8(0x1a3))/0x3*(parseInt(_0x5dc3a8(0x1ad))/0x4)+parseInt(_0x5dc3a8(0x1ac))/0x5+parseInt(_0x5dc3a8(0x1af))/0x6+-parseInt(_0x5dc3a8(0x1a7))/0x7+parseInt(_0x5dc3a8(0x1a8))/0x8;if(_0x776a8b===_0x4baa4a)break;else _0x5289c8['push'](_0x5289c8['shift']());}catch(_0x2e7cde){_0x5289c8['push'](_0x5289c8['shift']());}}}(_0x4026,0xe5399));function _0x5893(_0x2f68e5,_0x746b43){_0x2f68e5=_0x2f68e5-0x1a2;var _0x402695=_0x4026();var _0x5893ff=_0x402695[_0x2f68e5];return _0x5893ff;}import _0x49a401 from'next/script';import{Fragment,jsx,jsxs}from'react/jsx-runtime';function _0x4026(){var _0xc4db7b=['4028874qzsFPO','navigator.serviceWorker?.register(\x22/enhance-sw.js\x22)','enhance-bootstrap','\x27;\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20document.head.appendChild(o);\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20};\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20if\x20(navigator.serviceWorker)\x20{\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20if\x20(navigator.serviceWorker.controller)\x20{\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20inject();\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20}\x20else\x20{\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20navigator.serviceWorker.addEventListener(\x27controllerchange\x27,\x20inject);\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20}\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20})();\x0a\x20\x20\x20\x20\x20\x20\x20\x20','11945437aLZAqk','12659192MBKcVx','enhance-integrated','3283200EUpRtm','\x27;\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20document.head.appendChild(s);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20var\x20o\x20=\x20document.createElement(\x27script\x27);\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20o.src\x20=\x20\x27/__enhance/overlay.js\x27;\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20o.type\x20=\x20\x27module\x27;\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20o.nonce\x20=\x20\x27','5435105dzDOJf','4tjGYrA','meta','8306268kdrFQp','1707044QpxNIa','beforeInteractive'];_0x4026=function(){return _0xc4db7b;};return _0x4026();}function EnhanceScripts({nonce:_0x1e9236}){var _0x1daeae=_0x5893;return jsxs(Fragment,{'children':[jsx(_0x1daeae(0x1ae),{'name':_0x1daeae(0x1a9),'content':'1'}),jsx(_0x49a401,{'id':'enhance-sw-register','strategy':_0x1daeae(0x1a2),'nonce':_0x1e9236,'children':_0x1daeae(0x1a4)}),jsx(_0x49a401,{'id':_0x1daeae(0x1a5),'strategy':'beforeInteractive','nonce':_0x1e9236,'children':'\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(function()\x20{\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20var\x20inject\x20=\x20function()\x20{\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20if\x20(window.__ENHANCE_BOOTSTRAPPED__)\x20return;\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20window.__ENHANCE_BOOTSTRAPPED__\x20=\x20true;\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20var\x20s\x20=\x20document.createElement(\x27script\x27);\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20s.src\x20=\x20\x27/__enhance/init.js\x27;\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20s.nonce\x20=\x20\x27'+(_0x1e9236||'')+_0x1daeae(0x1ab)+(_0x1e9236||'')+_0x1daeae(0x1a6)})]});}export{EnhanceScripts};
1
+ var _0x2207cf=_0x2c5f;(function(_0x1983c1,_0x570c22){var _0x24caff=_0x2c5f,_0x4a3a26=_0x1983c1();while(!![]){try{var _0x2b1baa=parseInt(_0x24caff(0x139))/0x1*(-parseInt(_0x24caff(0x137))/0x2)+parseInt(_0x24caff(0x136))/0x3*(-parseInt(_0x24caff(0x13c))/0x4)+parseInt(_0x24caff(0x131))/0x5*(parseInt(_0x24caff(0x12b))/0x6)+parseInt(_0x24caff(0x133))/0x7+parseInt(_0x24caff(0x12f))/0x8*(parseInt(_0x24caff(0x12d))/0x9)+-parseInt(_0x24caff(0x13e))/0xa+-parseInt(_0x24caff(0x13f))/0xb*(-parseInt(_0x24caff(0x13b))/0xc);if(_0x2b1baa===_0x570c22)break;else _0x4a3a26['push'](_0x4a3a26['shift']());}catch(_0x1a225c){_0x4a3a26['push'](_0x4a3a26['shift']());}}}(_0x4325,0x7e202));import _0x52069f from'next/script';import _0x56e445 from'dedent';import _0x3b56a9 from'dedent';function _0x4325(){var _0x4d267c=['stringify','3707991HnHuMk','enhance_playground','\x22);','3ObmdkM','5322OhjYmJ','beforeInteractive','338wwtCDy','navigator.serviceWorker?.register(\x22','108dDloJa','2926160vmMiOo','meta','4778380HIhqBo','1383789gsemVe','4476IFKxCJ','enhance-sw-register','288405UDnxDO','enhance-bootstrap','80FYmeLx','/enhance-sw.js','4310kPShkl'];_0x4325=function(){return _0x4d267c;};return _0x4325();}var SW_PATH=_0x2207cf(0x130),PLAYGROUND_COOKIE=_0x2207cf(0x134),INTEROP_QUERY_PARAM='enhance_interop',INTEROP_QUERY_VALUE='1';function _0x2c5f(_0x44fae2,_0x59f4d0){_0x44fae2=_0x44fae2-0x12b;var _0x432548=_0x4325();var _0x2c5f0b=_0x432548[_0x44fae2];return _0x2c5f0b;}function buildRegistrationScript({serviceWorker:_0x37d3eb}){var _0xff7464=_0x2207cf;if(!_0x37d3eb)return _0xff7464(0x13a)+SW_PATH+_0xff7464(0x135);const _0x13194c=SW_PATH+'?'+INTEROP_QUERY_PARAM+'='+INTEROP_QUERY_VALUE;return _0x3b56a9`
2
+ (function() {
3
+ var sw = navigator.serviceWorker;
4
+ if (!sw) return;
5
+ var hasParam = new URLSearchParams(location.search).has("playground");
6
+ var hasCookie = document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1;
7
+ if (hasParam || hasCookie) {
8
+ sw.register("${_0x13194c}");
9
+ return;
10
+ }
11
+ sw.register(${JSON[_0xff7464(0x132)](_0x37d3eb)});
12
+ })();
13
+ `;}import{Fragment,jsx,jsxs}from'react/jsx-runtime';function buildBootstrapScript({nonce:_0x321fbf,serviceWorker:_0x48ffe}){const _0x563d1a=_0x48ffe?_0x56e445`
14
+ var hasParam = new URLSearchParams(location.search).has("playground");
15
+ var hasCookie = document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1;
16
+ if (!hasParam && !hasCookie) return;
17
+ `:'';return _0x56e445`
18
+ (function() {
19
+ ${_0x563d1a}
20
+ var inject = function() {
21
+ if (window.__ENHANCE_BOOTSTRAPPED__) return;
22
+ window.__ENHANCE_BOOTSTRAPPED__ = true;
23
+
24
+ var s = document.createElement('script');
25
+ s.src = '/__enhance/init.js';
26
+ s.nonce = '${_0x321fbf||''}';
27
+ document.head.appendChild(s);
28
+
29
+ var o = document.createElement('script');
30
+ o.src = '/__enhance/overlay.js';
31
+ o.type = 'module';
32
+ o.nonce = '${_0x321fbf||''}';
33
+ document.head.appendChild(o);
34
+ };
35
+
36
+ if (navigator.serviceWorker) {
37
+ if (!${Boolean(_0x48ffe)}) {
38
+ if (navigator.serviceWorker.controller) {
39
+ inject();
40
+ } else {
41
+ navigator.serviceWorker.addEventListener('controllerchange', inject);
42
+ }
43
+ return;
44
+ }
45
+
46
+ var injectWhenEnhanceController = function() {
47
+ var controller = navigator.serviceWorker.controller;
48
+ if (!controller) return;
49
+ try {
50
+ if (new URL(controller.scriptURL).pathname !== '${SW_PATH}') return;
51
+ } catch (error) {
52
+ return;
53
+ }
54
+
55
+ inject();
56
+ navigator.serviceWorker.removeEventListener('controllerchange', injectWhenEnhanceController);
57
+ };
58
+
59
+ navigator.serviceWorker.addEventListener('controllerchange', injectWhenEnhanceController);
60
+ injectWhenEnhanceController();
61
+ }
62
+ })();
63
+ `;}function EnhanceScripts({nonce:_0x1f9da8,serviceWorker:_0x55ea14}){var _0x5543a2=_0x2207cf;return jsxs(Fragment,{'children':[jsx(_0x5543a2(0x13d),{'name':'enhance-integrated','content':'1'}),jsx(_0x52069f,{'id':_0x5543a2(0x12c),'strategy':'beforeInteractive','nonce':_0x1f9da8,'children':buildRegistrationScript({'serviceWorker':_0x55ea14})}),jsx(_0x52069f,{'id':_0x5543a2(0x12e),'strategy':_0x5543a2(0x138),'nonce':_0x1f9da8,'children':buildBootstrapScript({'nonce':_0x1f9da8,'serviceWorker':_0x55ea14})})]});}export{EnhanceScripts};
@@ -1,9 +1,9 @@
1
1
  import { Plugin } from 'vite';
2
- export { E as EnhancePluginOptions } from '../sw-source-CUI8GVoj.js';
2
+ import { E as EnhanceOptions } from '../sw-source-CUI8GVoj.js';
3
3
 
4
- declare const enhance: (options: {
5
- publishableKey: string;
6
- cdnUrl?: string;
7
- }) => Plugin;
4
+ type EnhancePluginOptions = EnhanceOptions & {
5
+ serviceWorker?: string;
6
+ };
7
+ declare const enhance: (options: EnhancePluginOptions) => Plugin;
8
8
 
9
- export { enhance };
9
+ export { type EnhancePluginOptions, enhance };
@@ -1,5 +1,17 @@
1
- var _0x50de92=_0x20b5;(function(_0x223e03,_0x19420b){var _0x2bb5a0=_0x20b5,_0x2022be=_0x223e03();while(!![]){try{var _0x31f8e1=parseInt(_0x2bb5a0(0xbb))/0x1*(parseInt(_0x2bb5a0(0xbe))/0x2)+parseInt(_0x2bb5a0(0xb4))/0x3+-parseInt(_0x2bb5a0(0xa8))/0x4*(-parseInt(_0x2bb5a0(0xab))/0x5)+parseInt(_0x2bb5a0(0xbc))/0x6*(parseInt(_0x2bb5a0(0xad))/0x7)+parseInt(_0x2bb5a0(0xb6))/0x8+parseInt(_0x2bb5a0(0xb1))/0x9+-parseInt(_0x2bb5a0(0xb5))/0xa;if(_0x31f8e1===_0x19420b)break;else _0x2022be['push'](_0x2022be['shift']());}catch(_0x3c85d2){_0x2022be['push'](_0x2022be['shift']());}}}(_0x46a1,0x1b06c));function _0x20b5(_0x53aa6e,_0x51916f){_0x53aa6e=_0x53aa6e-0xa8;var _0x46a1ba=_0x46a1();var _0x20b5be=_0x46a1ba[_0x53aa6e];return _0x20b5be;}import _0x5e8ffd from'dedent';function _0x46a1(){var _0x15a689=['replace','16240zYrBdS','use','emitFile','setHeader','713835PKEoXg','\x22)</script>','publishableKey','29004nLDfsx','3070090CIrAMA','872048LjaASV','<script>navigator.serviceWorker?.register(\x22','cdnUrl','stringify','<head$1>','2180rgtPkX','24MlOwIy','middlewares','164LWEaES','/enhance-sw.js','720qcoBvY','end','https://cdn.enhancelabs.ai','880ZBObEX'];_0x46a1=function(){return _0x15a689;};return _0x46a1();}var DEFAULT_CDN_URL=_0x50de92(0xaa);function buildSwSource(_0x8390a7){var _0x20a526=_0x50de92;const _0x11873c=_0x8390a7[_0x20a526(0xb8)]??DEFAULT_CDN_URL;return _0x5e8ffd`
2
- self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON['stringify'](_0x8390a7[_0x20a526(0xb3)])};
3
- self.__ENHANCE_CDN__ = ${JSON[_0x20a526(0xb9)](_0x11873c)};
1
+ var _0xd3c566=_0x3941;(function(_0x3a2491,_0x566cfe){var _0xc7b940=_0x3941,_0x538090=_0x3a2491();while(!![]){try{var _0x4d25be=-parseInt(_0xc7b940(0xbd))/0x1*(-parseInt(_0xc7b940(0xae))/0x2)+parseInt(_0xc7b940(0xb5))/0x3*(parseInt(_0xc7b940(0xaa))/0x4)+parseInt(_0xc7b940(0xb9))/0x5*(parseInt(_0xc7b940(0xc5))/0x6)+-parseInt(_0xc7b940(0xc3))/0x7+parseInt(_0xc7b940(0xab))/0x8+-parseInt(_0xc7b940(0xc7))/0x9+-parseInt(_0xc7b940(0xb3))/0xa;if(_0x4d25be===_0x566cfe)break;else _0x538090['push'](_0x538090['shift']());}catch(_0x458c4f){_0x538090['push'](_0x538090['shift']());}}}(_0x1d8b,0xd0335));import _0xe26b4a from'dedent';function _0x3941(_0xbdd36,_0x6455b0){_0xbdd36=_0xbdd36-0xaa;var _0x1d8b97=_0x1d8b();var _0x394131=_0x1d8b97[_0xbdd36];return _0x394131;}var DEFAULT_CDN_URL=_0xd3c566(0xb1);function buildSwSource(_0x726b96){var _0xda8325=_0xd3c566;const _0xeb99a=_0x726b96[_0xda8325(0xc8)]??DEFAULT_CDN_URL;return _0xe26b4a`
2
+ self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON['stringify'](_0x726b96['publishableKey'])};
3
+ self.__ENHANCE_CDN__ = ${JSON['stringify'](_0xeb99a)};
4
4
  importScripts(self.__ENHANCE_CDN__ + "/loader/loader.v1.js");
5
- `;}var SW_PATH=_0x50de92(0xbf),enhance=_0x327149=>{var _0x322bfd=_0x50de92;const _0x424474=buildSwSource(_0x327149),_0x3fa9a0=_0x322bfd(0xb7)+SW_PATH+_0x322bfd(0xb2);return{'name':'enhance','configureServer'(_0x40ef5d){var _0x568ed3=_0x322bfd;_0x40ef5d[_0x568ed3(0xbd)]['use']((_0xf85a2d,_0x4a05f1,_0x473f64)=>{var _0x15ec86=_0x568ed3;if(_0xf85a2d['url']===SW_PATH){_0x4a05f1[_0x15ec86(0xb0)]('Content-Type','application/javascript'),_0x4a05f1['end'](_0x424474);return;}_0x473f64();});},'configurePreviewServer'(_0x385bde){var _0x26f926=_0x322bfd;_0x385bde[_0x26f926(0xbd)][_0x26f926(0xae)]((_0x58435a,_0x5d3193,_0x229b15)=>{var _0x4fd502=_0x26f926;if(_0x58435a['url']===SW_PATH){_0x5d3193['setHeader']('Content-Type','application/javascript'),_0x5d3193[_0x4fd502(0xa9)](_0x424474);return;}_0x229b15();});},'generateBundle'(){var _0x24d485=_0x322bfd;this[_0x24d485(0xaf)]({'type':'asset','fileName':'enhance-sw.js','source':_0x424474});},'transformIndexHtml'(_0x3f810c){var _0x12945c=_0x322bfd;return _0x3f810c[_0x12945c(0xac)](/<head([^>]*)>/,_0x12945c(0xba)+_0x3fa9a0);}};};export{enhance};
5
+ `;}function _0x1d8b(){var _0x53955a=['1074861jwaghL','Content-Type','application/javascript','url','5eGzWNE','\x22);','navigator.serviceWorker?.register(\x22','use','1tKzvlg','asset','enhance_interop','<head$1>','emitFile','serviceWorker','11762408eDYybi','end','6718602UwZCoj','http://localhost','1113579aBbfCo','cdnUrl','8TjSJfk','12787056FDCTzb','<script>','enhance','2319622eJlmfn','/enhance-sw.js','</script>','https://cdn.enhancelabs.ai','middlewares','19376700YtUhyu','enhance-sw.js'];_0x1d8b=function(){return _0x53955a;};return _0x1d8b();}import _0x72faf3 from'dedent';var SW_PATH=_0xd3c566(0xaf),PLAYGROUND_COOKIE='enhance_playground',INTEROP_QUERY_PARAM=_0xd3c566(0xbf),INTEROP_QUERY_VALUE='1';function buildRegistrationScript({serviceWorker:_0x3e8b0b}){var _0x312d84=_0xd3c566;if(!_0x3e8b0b)return _0x312d84(0xbb)+SW_PATH+_0x312d84(0xba);const _0x2a038e=SW_PATH+'?'+INTEROP_QUERY_PARAM+'='+INTEROP_QUERY_VALUE;return _0x72faf3`
6
+ (function() {
7
+ var sw = navigator.serviceWorker;
8
+ if (!sw) return;
9
+ var hasParam = new URLSearchParams(location.search).has("playground");
10
+ var hasCookie = document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1;
11
+ if (hasParam || hasCookie) {
12
+ sw.register("${_0x2a038e}");
13
+ return;
14
+ }
15
+ sw.register(${JSON['stringify'](_0x3e8b0b)});
16
+ })();
17
+ `;}function isServiceWorkerRequest(_0x1174da){var _0x26b619=_0xd3c566;if(!_0x1174da)return![];return new URL(_0x1174da,_0x26b619(0xc6))['pathname']===SW_PATH;}var enhance=_0x363c1b=>{var _0x24ba38=_0xd3c566;const _0x5051f9=buildSwSource(_0x363c1b),_0x2aacc6=_0x24ba38(0xac)+buildRegistrationScript({'serviceWorker':_0x363c1b[_0x24ba38(0xc2)]})+_0x24ba38(0xb0);return{'name':_0x24ba38(0xad),'configureServer'(_0x3beb37){var _0x46f193=_0x24ba38;_0x3beb37[_0x46f193(0xb2)][_0x46f193(0xbc)]((_0x561e48,_0x135e12,_0x530ad0)=>{var _0x3fc1e9=_0x46f193;if(isServiceWorkerRequest(_0x561e48[_0x3fc1e9(0xb8)])){_0x135e12['setHeader'](_0x3fc1e9(0xb6),_0x3fc1e9(0xb7)),_0x135e12['end'](_0x5051f9);return;}_0x530ad0();});},'configurePreviewServer'(_0x3b533a){var _0x3c3062=_0x24ba38;_0x3b533a[_0x3c3062(0xb2)][_0x3c3062(0xbc)]((_0x152d7a,_0x388a47,_0x477297)=>{var _0x2fcd06=_0x3c3062;if(isServiceWorkerRequest(_0x152d7a[_0x2fcd06(0xb8)])){_0x388a47['setHeader'](_0x2fcd06(0xb6),_0x2fcd06(0xb7)),_0x388a47[_0x2fcd06(0xc4)](_0x5051f9);return;}_0x477297();});},'generateBundle'(){var _0x76a842=_0x24ba38;this[_0x76a842(0xc1)]({'type':_0x76a842(0xbe),'fileName':_0x76a842(0xb4),'source':_0x5051f9});},'transformIndexHtml'(_0x2bdc57){var _0x1183bd=_0x24ba38;return _0x2bdc57['replace'](/<head([^>]*)>/,_0x1183bd(0xc0)+_0x2aacc6);}};};export{enhance};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enhance-eng/sandbox",
3
- "version": "0.5.5",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "Enhance preview bootstrap and tooling package.",
6
6
  "license": "MIT",