@enhance-eng/sandbox 0.5.5 → 0.7.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 _0x4b528f=_0x18f9;(function(_0x212534,_0x31f7cb){const _0x2e97bf=_0x18f9,_0x52500d=_0x212534();while(!![]){try{const _0x58c11e=parseInt(_0x2e97bf(0x1f0))/0x1+-parseInt(_0x2e97bf(0x1e8))/0x2+parseInt(_0x2e97bf(0x1de))/0x3+parseInt(_0x2e97bf(0x1ce))/0x4*(-parseInt(_0x2e97bf(0x1d0))/0x5)+parseInt(_0x2e97bf(0x1cf))/0x6+parseInt(_0x2e97bf(0x1ed))/0x7*(-parseInt(_0x2e97bf(0x1e9))/0x8)+-parseInt(_0x2e97bf(0x1e6))/0x9*(-parseInt(_0x2e97bf(0x1f2))/0xa);if(_0x58c11e===_0x31f7cb)break;else _0x52500d['push'](_0x52500d['shift']());}catch(_0x194d58){_0x52500d['push'](_0x52500d['shift']());}}}(_0xfd0e,0x569ea));import{Command}from'commander';import{writeFile,mkdir}from'fs/promises';import{dirname,resolve}from'path';import _0x10d255 from'dedent';function _0xfd0e(){const _0x24708c=['write','option','init','parseAsync','\x20});\x0a','1647vhWURF','serviceWorker','203742dAdFMo','8hyJeBW','Output\x20path\x20for\x20the\x20service\x20worker\x20file','stringify','https://cdn.enhancelabs.ai','1987951VUpLQA','stdout','URL\x20of\x20your\x20existing\x20service\x20worker\x20(e.g.\x20/sw.js)','609803rKKFFT','Enhance\x20sandbox\x20utility\x20CLI','2620snbvQO','command','cdnUrl','2003012sHovuD','3154428kCTbNR','5prTIdj','enhance-sandbox','0.0.0','--cdn-url\x20<url>','cwd','CDN\x20URL\x20for\x20enhance\x20assets\x20(defaults\x20to\x20production)','description','Created\x20','action','version','requiredOption','name','Publishable\x20key\x20for\x20enhance','public/enhance-sw.js','173772cLWIpV','output','Generate\x20the\x20service\x20worker\x20loader\x20file'];_0xfd0e=function(){return _0x24708c;};return _0xfd0e();}var DEFAULT_CDN_URL=_0x4b528f(0x1ec);function buildSwSource(_0x401f28){const _0x2e2dc0=_0x4b528f,_0x1b52aa=_0x401f28[_0x2e2dc0(0x1cd)]??DEFAULT_CDN_URL;return _0x10d255`
4
+ self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON[_0x2e2dc0(0x1eb)](_0x401f28['publishableKey'])};
5
+ self.__ENHANCE_CDN__ = ${JSON[_0x2e2dc0(0x1eb)](_0x1b52aa)};
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
+ `;}function _0x18f9(_0x35d564,_0x5b0fb2){_0x35d564=_0x35d564-0x1cd;const _0xfd0ee5=_0xfd0e();let _0x18f9d8=_0xfd0ee5[_0x35d564];return _0x18f9d8;}var program=new Command();program[_0x4b528f(0x1db)](_0x4b528f(0x1d1))[_0x4b528f(0x1d6)](_0x4b528f(0x1f1))[_0x4b528f(0x1d9)](_0x4b528f(0x1d2)),program[_0x4b528f(0x1f3)](_0x4b528f(0x1e3))[_0x4b528f(0x1d6)](_0x4b528f(0x1e0))[_0x4b528f(0x1da)]('--publishable-key\x20<key>',_0x4b528f(0x1dc))['option'](_0x4b528f(0x1d3),_0x4b528f(0x1d5))[_0x4b528f(0x1e2)]('--output\x20<path>',_0x4b528f(0x1ea),_0x4b528f(0x1dd))['option']('--service-worker\x20<url>',_0x4b528f(0x1ef))[_0x4b528f(0x1d8)](async _0x4be961=>{const _0x4a2374=_0x4b528f,_0x47ff6d=resolve(process[_0x4a2374(0x1d4)](),_0x4be961[_0x4a2374(0x1df)]),_0x59f269=buildSwSource({'publishableKey':_0x4be961['publishableKey'],'cdnUrl':_0x4be961[_0x4a2374(0x1cd)]});await mkdir(dirname(_0x47ff6d),{'recursive':!![]}),await writeFile(_0x47ff6d,_0x59f269,'utf-8'),process['stdout']['write'](_0x4a2374(0x1d7)+_0x4be961[_0x4a2374(0x1df)]+'\x0a'),_0x4be961[_0x4a2374(0x1e7)]&&process[_0x4a2374(0x1ee)][_0x4a2374(0x1e1)]('\x0aRegister\x20with:\x0a\x0a\x20\x20import\x20{\x20enhance\x20}\x20from\x20\x22@enhance-eng/sandbox\x22;\x0a\x20\x20enhance({\x20serviceWorker:\x20'+JSON[_0x4a2374(0x1eb)](_0x4be961[_0x4a2374(0x1e7)])+_0x4a2374(0x1e5));}),program[_0x4b528f(0x1e4)]();
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,36 @@
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
+ var _0x5590ac=_0x1a19;(function(_0x5b403b,_0x540534){var _0x1312de=_0x1a19,_0x11eb11=_0x5b403b();while(!![]){try{var _0x56002c=parseInt(_0x1312de(0x17d))/0x1*(parseInt(_0x1312de(0x17f))/0x2)+parseInt(_0x1312de(0x178))/0x3*(-parseInt(_0x1312de(0x189))/0x4)+-parseInt(_0x1312de(0x17e))/0x5+-parseInt(_0x1312de(0x17a))/0x6*(-parseInt(_0x1312de(0x188))/0x7)+parseInt(_0x1312de(0x183))/0x8*(parseInt(_0x1312de(0x187))/0x9)+parseInt(_0x1312de(0x181))/0xa+-parseInt(_0x1312de(0x176))/0xb*(parseInt(_0x1312de(0x184))/0xc);if(_0x56002c===_0x540534)break;else _0x11eb11['push'](_0x11eb11['shift']());}catch(_0x4487dd){_0x11eb11['push'](_0x11eb11['shift']());}}}(_0x143e,0xa0ace));import _0x54713e from'dedent';var SW_PATH=_0x5590ac(0x17b),PLAYGROUND_COOKIE=_0x5590ac(0x179),INTEROP_QUERY_PARAM='enhance_interop',INTEROP_QUERY_VALUE='1',BOOTSTRAP_COOKIE_MAX_AGE=0x2*0x3c;function buildRegistrationScript({serviceWorker:_0x3d716d}){var _0x3eeee4=_0x5590ac;if(!_0x3d716d)return _0x3eeee4(0x180)+SW_PATH+_0x3eeee4(0x177);const _0x55a012=SW_PATH+'?'+INTEROP_QUERY_PARAM+'='+INTEROP_QUERY_VALUE;return _0x54713e`
2
+ (function() {
3
+ var sw = navigator.serviceWorker;
4
+ if (!sw) return;
5
+ var search = new URLSearchParams(location.search);
6
+ var isExit = search.get("enhance_exit") === "1" || search.get("exit_enhance") === "1" || search.get("enhance_exited") === "1";
7
+ if (isExit) {
8
+ document.cookie = "${PLAYGROUND_COOKIE}=; path=/; max-age=0";
9
+ search.delete("enhance_exit");
10
+ search.delete("exit_enhance");
11
+ search.delete("enhance_exited");
12
+ var cleanUrl = location.pathname + (search.toString() ? "?" + search : "") + location.hash;
13
+ history.replaceState(null, "", cleanUrl);
14
+ sw.register(${JSON['stringify'](_0x3d716d)});
15
+ return;
16
+ }
17
+ var playgroundId = search.get("playground");
18
+ if (!playgroundId) {
19
+ var hashIdx = location.hash.indexOf("?");
20
+ if (hashIdx !== -1) {
21
+ playgroundId = new URLSearchParams(location.hash.slice(hashIdx + 1)).get("playground");
22
+ }
23
+ }
24
+ if (playgroundId) {
25
+ var secure = location.protocol === "https:" ? "; secure" : "";
26
+ document.cookie = "${PLAYGROUND_COOKIE}=" + encodeURIComponent(playgroundId) + "; path=/; max-age=${BOOTSTRAP_COOKIE_MAX_AGE}; samesite=lax" + secure;
27
+ sw.register("${_0x55a012}");
28
+ return;
29
+ }
30
+ if (document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1) {
31
+ sw.register("${_0x55a012}");
32
+ return;
33
+ }
34
+ sw.register(${JSON[_0x3eeee4(0x186)](_0x3d716d)});
35
+ })();
36
+ `;}function enhance(_0x1a7053){var _0x339a51=_0x5590ac;const _0x2b005a=document[_0x339a51(0x17c)]('script');_0x2b005a[_0x339a51(0x182)]=buildRegistrationScript({'serviceWorker':_0x1a7053?.['serviceWorker']}),document[_0x339a51(0x185)]['appendChild'](_0x2b005a);}function _0x143e(){var _0x2cb754=['4570330eZqutb','57340FivxOq','navigator.serviceWorker?.register(\x22','9356330DQVDBF','textContent','1960eEvrJl','24BfLPMh','head','stringify','21177hyStSr','7jPJJgK','508ZUhWAq','111364xNTtwO','\x22);','16233IIPXBD','enhance_playground','1680774lLYIFr','/enhance-sw.js','createElement','17lIPXXm'];_0x143e=function(){return _0x2cb754;};return _0x143e();}function _0x1a19(_0x100f5e,_0x4be7c5){_0x100f5e=_0x100f5e-0x176;var _0x143e87=_0x143e();var _0x1a1924=_0x143e87[_0x100f5e];return _0x1a1924;}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,86 @@
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 _0x592b33=_0x41d0;(function(_0x1df2c0,_0x679265){var _0x205615=_0x41d0,_0x43a16d=_0x1df2c0();while(!![]){try{var _0x3f9388=-parseInt(_0x205615(0xe7))/0x1*(-parseInt(_0x205615(0xe9))/0x2)+-parseInt(_0x205615(0xe3))/0x3+parseInt(_0x205615(0xe8))/0x4*(-parseInt(_0x205615(0xe0))/0x5)+-parseInt(_0x205615(0xd9))/0x6+-parseInt(_0x205615(0xdc))/0x7+parseInt(_0x205615(0xda))/0x8+-parseInt(_0x205615(0xdf))/0x9*(-parseInt(_0x205615(0xdd))/0xa);if(_0x3f9388===_0x679265)break;else _0x43a16d['push'](_0x43a16d['shift']());}catch(_0x2677fe){_0x43a16d['push'](_0x43a16d['shift']());}}}(_0x2b22,0xd5010));import _0x3c89cb from'next/script';import _0x2e4b67 from'dedent';import _0xa43f77 from'dedent';var SW_PATH=_0x592b33(0xe5),PLAYGROUND_COOKIE='enhance_playground',INTEROP_QUERY_PARAM=_0x592b33(0xe2),INTEROP_QUERY_VALUE='1',BOOTSTRAP_COOKIE_MAX_AGE=0x2*0x3c;function _0x41d0(_0x4b1331,_0x14ff97){_0x4b1331=_0x4b1331-0xd9;var _0x2b22df=_0x2b22();var _0x41d097=_0x2b22df[_0x4b1331];return _0x41d097;}function buildRegistrationScript({serviceWorker:_0x133c56}){var _0x47f44b=_0x592b33;if(!_0x133c56)return'navigator.serviceWorker?.register(\x22'+SW_PATH+_0x47f44b(0xe6);const _0x30d910=SW_PATH+'?'+INTEROP_QUERY_PARAM+'='+INTEROP_QUERY_VALUE;return _0xa43f77`
2
+ (function() {
3
+ var sw = navigator.serviceWorker;
4
+ if (!sw) return;
5
+ var search = new URLSearchParams(location.search);
6
+ var isExit = search.get("enhance_exit") === "1" || search.get("exit_enhance") === "1" || search.get("enhance_exited") === "1";
7
+ if (isExit) {
8
+ document.cookie = "${PLAYGROUND_COOKIE}=; path=/; max-age=0";
9
+ search.delete("enhance_exit");
10
+ search.delete("exit_enhance");
11
+ search.delete("enhance_exited");
12
+ var cleanUrl = location.pathname + (search.toString() ? "?" + search : "") + location.hash;
13
+ history.replaceState(null, "", cleanUrl);
14
+ sw.register(${JSON[_0x47f44b(0xe1)](_0x133c56)});
15
+ return;
16
+ }
17
+ var playgroundId = search.get("playground");
18
+ if (!playgroundId) {
19
+ var hashIdx = location.hash.indexOf("?");
20
+ if (hashIdx !== -1) {
21
+ playgroundId = new URLSearchParams(location.hash.slice(hashIdx + 1)).get("playground");
22
+ }
23
+ }
24
+ if (playgroundId) {
25
+ var secure = location.protocol === "https:" ? "; secure" : "";
26
+ document.cookie = "${PLAYGROUND_COOKIE}=" + encodeURIComponent(playgroundId) + "; path=/; max-age=${BOOTSTRAP_COOKIE_MAX_AGE}; samesite=lax" + secure;
27
+ sw.register("${_0x30d910}");
28
+ return;
29
+ }
30
+ if (document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1) {
31
+ sw.register("${_0x30d910}");
32
+ return;
33
+ }
34
+ sw.register(${JSON[_0x47f44b(0xe1)](_0x133c56)});
35
+ })();
36
+ `;}import{Fragment,jsx,jsxs}from'react/jsx-runtime';function _0x2b22(){var _0x4484a7=['\x22);','5323aZzrBU','1572344YEfsSV','32zEPhnu','7834554VqUDHk','12101088rnXlHy','meta','11334554iBhCMV','130ZgRVZQ','beforeInteractive','3084678qEweem','10zecidS','stringify','enhance_interop','4409499cQrnUa','enhance-bootstrap','/enhance-sw.js'];_0x2b22=function(){return _0x4484a7;};return _0x2b22();}function buildBootstrapScript({nonce:_0x55f40b,serviceWorker:_0xf063be}){const _0xe0f885=_0xf063be?_0x2e4b67`
37
+ var hasParam = new URLSearchParams(location.search).has("playground");
38
+ var hasCookie = document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1;
39
+ if (!hasParam && !hasCookie) return;
40
+ `:'';return _0x2e4b67`
41
+ (function() {
42
+ ${_0xe0f885}
43
+ var inject = function() {
44
+ if (window.__ENHANCE_BOOTSTRAPPED__) return;
45
+ window.__ENHANCE_BOOTSTRAPPED__ = true;
46
+
47
+ var s = document.createElement('script');
48
+ s.src = '/__enhance/init.js';
49
+ s.nonce = '${_0x55f40b||''}';
50
+ document.head.appendChild(s);
51
+
52
+ var o = document.createElement('script');
53
+ o.src = '/__enhance/overlay.js';
54
+ o.type = 'module';
55
+ o.nonce = '${_0x55f40b||''}';
56
+ document.head.appendChild(o);
57
+ };
58
+
59
+ if (navigator.serviceWorker) {
60
+ if (!${Boolean(_0xf063be)}) {
61
+ if (navigator.serviceWorker.controller) {
62
+ inject();
63
+ } else {
64
+ navigator.serviceWorker.addEventListener('controllerchange', inject);
65
+ }
66
+ return;
67
+ }
68
+
69
+ var injectWhenEnhanceController = function() {
70
+ var controller = navigator.serviceWorker.controller;
71
+ if (!controller) return;
72
+ try {
73
+ if (new URL(controller.scriptURL).pathname !== '${SW_PATH}') return;
74
+ } catch (error) {
75
+ return;
76
+ }
77
+
78
+ inject();
79
+ navigator.serviceWorker.removeEventListener('controllerchange', injectWhenEnhanceController);
80
+ };
81
+
82
+ navigator.serviceWorker.addEventListener('controllerchange', injectWhenEnhanceController);
83
+ injectWhenEnhanceController();
84
+ }
85
+ })();
86
+ `;}function EnhanceScripts({nonce:_0x21c9e6,serviceWorker:_0x688946}){var _0x29d823=_0x592b33;return jsxs(Fragment,{'children':[jsx(_0x29d823(0xdb),{'name':'enhance-integrated','content':'1'}),jsx(_0x3c89cb,{'id':'enhance-sw-register','strategy':_0x29d823(0xde),'nonce':_0x21c9e6,'children':buildRegistrationScript({'serviceWorker':_0x688946})}),jsx(_0x3c89cb,{'id':_0x29d823(0xe4),'strategy':_0x29d823(0xde),'nonce':_0x21c9e6,'children':buildBootstrapScript({'nonce':_0x21c9e6,'serviceWorker':_0x688946})})]});}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,40 @@
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 _0x37ae85=_0x45e8;(function(_0x2981b4,_0x2e6435){var _0x5c60aa=_0x45e8,_0x266a22=_0x2981b4();while(!![]){try{var _0x1867dc=parseInt(_0x5c60aa(0x84))/0x1+parseInt(_0x5c60aa(0x7e))/0x2*(parseInt(_0x5c60aa(0x8b))/0x3)+parseInt(_0x5c60aa(0x82))/0x4*(-parseInt(_0x5c60aa(0x76))/0x5)+parseInt(_0x5c60aa(0x86))/0x6+parseInt(_0x5c60aa(0x7a))/0x7+parseInt(_0x5c60aa(0x8d))/0x8*(parseInt(_0x5c60aa(0x71))/0x9)+-parseInt(_0x5c60aa(0x75))/0xa;if(_0x1867dc===_0x2e6435)break;else _0x266a22['push'](_0x266a22['shift']());}catch(_0x2c1311){_0x266a22['push'](_0x266a22['shift']());}}}(_0x5da4,0x21fa5));function _0x45e8(_0x38d35f,_0xff6165){_0x38d35f=_0x38d35f-0x6c;var _0x5da4f8=_0x5da4();var _0x45e8bb=_0x5da4f8[_0x38d35f];return _0x45e8bb;}import _0xc9db64 from'dedent';var DEFAULT_CDN_URL=_0x37ae85(0x8e);function buildSwSource(_0x3d5e44){var _0x486403=_0x37ae85;const _0x219f3d=_0x3d5e44[_0x486403(0x77)]??DEFAULT_CDN_URL;return _0xc9db64`
2
+ self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON[_0x486403(0x85)](_0x3d5e44[_0x486403(0x83)])};
3
+ self.__ENHANCE_CDN__ = ${JSON[_0x486403(0x85)](_0x219f3d)};
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
+ `;}import _0xf8edd4 from'dedent';var SW_PATH=_0x37ae85(0x88),PLAYGROUND_COOKIE=_0x37ae85(0x6f),INTEROP_QUERY_PARAM=_0x37ae85(0x7d),INTEROP_QUERY_VALUE='1',BOOTSTRAP_COOKIE_MAX_AGE=0x2*0x3c;function _0x5da4(){var _0x9c79ce=['</script>','86980aOtitg','publishableKey','17858eupoiu','stringify','535584VBoohP','replace','/enhance-sw.js','setHeader','navigator.serviceWorker?.register(\x22','22107vTwTcu','middlewares','8608RtYluJ','https://cdn.enhancelabs.ai','asset','<head$1>','pathname','enhance_playground','enhance-sw.js','1233DnVPhk','Content-Type','enhance','http://localhost','1381510KFwFxP','10ZnmHfO','cdnUrl','end','\x22);','412377IApoOx','serviceWorker','url','enhance_interop','2NNcrBE','application/javascript','use'];_0x5da4=function(){return _0x9c79ce;};return _0x5da4();}function buildRegistrationScript({serviceWorker:_0x362627}){var _0x1d7ee6=_0x37ae85;if(!_0x362627)return _0x1d7ee6(0x8a)+SW_PATH+_0x1d7ee6(0x79);const _0x385fda=SW_PATH+'?'+INTEROP_QUERY_PARAM+'='+INTEROP_QUERY_VALUE;return _0xf8edd4`
6
+ (function() {
7
+ var sw = navigator.serviceWorker;
8
+ if (!sw) return;
9
+ var search = new URLSearchParams(location.search);
10
+ var isExit = search.get("enhance_exit") === "1" || search.get("exit_enhance") === "1" || search.get("enhance_exited") === "1";
11
+ if (isExit) {
12
+ document.cookie = "${PLAYGROUND_COOKIE}=; path=/; max-age=0";
13
+ search.delete("enhance_exit");
14
+ search.delete("exit_enhance");
15
+ search.delete("enhance_exited");
16
+ var cleanUrl = location.pathname + (search.toString() ? "?" + search : "") + location.hash;
17
+ history.replaceState(null, "", cleanUrl);
18
+ sw.register(${JSON[_0x1d7ee6(0x85)](_0x362627)});
19
+ return;
20
+ }
21
+ var playgroundId = search.get("playground");
22
+ if (!playgroundId) {
23
+ var hashIdx = location.hash.indexOf("?");
24
+ if (hashIdx !== -1) {
25
+ playgroundId = new URLSearchParams(location.hash.slice(hashIdx + 1)).get("playground");
26
+ }
27
+ }
28
+ if (playgroundId) {
29
+ var secure = location.protocol === "https:" ? "; secure" : "";
30
+ document.cookie = "${PLAYGROUND_COOKIE}=" + encodeURIComponent(playgroundId) + "; path=/; max-age=${BOOTSTRAP_COOKIE_MAX_AGE}; samesite=lax" + secure;
31
+ sw.register("${_0x385fda}");
32
+ return;
33
+ }
34
+ if (document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1) {
35
+ sw.register("${_0x385fda}");
36
+ return;
37
+ }
38
+ sw.register(${JSON['stringify'](_0x362627)});
39
+ })();
40
+ `;}function isServiceWorkerRequest(_0x4b6279){var _0x603232=_0x37ae85;if(!_0x4b6279)return![];return new URL(_0x4b6279,_0x603232(0x74))[_0x603232(0x6e)]===SW_PATH;}var enhance=_0x200df1=>{var _0x3841b3=_0x37ae85;const _0x23762f=buildSwSource(_0x200df1),_0x1b24e1='<script>'+buildRegistrationScript({'serviceWorker':_0x200df1[_0x3841b3(0x7b)]})+_0x3841b3(0x81);return{'name':_0x3841b3(0x73),'configureServer'(_0x8f6d16){var _0x51d626=_0x3841b3;_0x8f6d16[_0x51d626(0x8c)][_0x51d626(0x80)]((_0x5761ec,_0x240be4,_0x2ac662)=>{var _0x23ca81=_0x51d626;if(isServiceWorkerRequest(_0x5761ec[_0x23ca81(0x7c)])){_0x240be4['setHeader'](_0x23ca81(0x72),'application/javascript'),_0x240be4['end'](_0x23762f);return;}_0x2ac662();});},'configurePreviewServer'(_0x788149){var _0x3c73a0=_0x3841b3;_0x788149[_0x3c73a0(0x8c)][_0x3c73a0(0x80)]((_0x5eb3bb,_0x4ba7f3,_0x4ea06b)=>{var _0x18220a=_0x3c73a0;if(isServiceWorkerRequest(_0x5eb3bb[_0x18220a(0x7c)])){_0x4ba7f3[_0x18220a(0x89)](_0x18220a(0x72),_0x18220a(0x7f)),_0x4ba7f3[_0x18220a(0x78)](_0x23762f);return;}_0x4ea06b();});},'generateBundle'(){var _0x54a906=_0x3841b3;this['emitFile']({'type':_0x54a906(0x6c),'fileName':_0x54a906(0x70),'source':_0x23762f});},'transformIndexHtml'(_0x331359){var _0x3f2336=_0x3841b3;return _0x331359[_0x3f2336(0x87)](/<head([^>]*)>/,_0x3f2336(0x6d)+_0x1b24e1);}};};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.7.0",
4
4
  "type": "module",
5
5
  "description": "Enhance preview bootstrap and tooling package.",
6
6
  "license": "MIT",