@enhance-eng/sandbox 0.5.4 → 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 _0x5b232d=_0x7a6a;function _0x7a6a(_0x51a6bc,_0x264e2c){_0x51a6bc=_0x51a6bc-0x187;const _0x342c55=_0x342c();let _0x7a6afe=_0x342c55[_0x51a6bc];return _0x7a6afe;}(function(_0x1d2600,_0x28a000){const _0x2b4152=_0x7a6a,_0x42aec2=_0x1d2600();while(!![]){try{const _0x4bd39e=-parseInt(_0x2b4152(0x1aa))/0x1*(-parseInt(_0x2b4152(0x19a))/0x2)+parseInt(_0x2b4152(0x1a6))/0x3*(-parseInt(_0x2b4152(0x189))/0x4)+parseInt(_0x2b4152(0x1a5))/0x5*(parseInt(_0x2b4152(0x19d))/0x6)+-parseInt(_0x2b4152(0x194))/0x7*(-parseInt(_0x2b4152(0x196))/0x8)+-parseInt(_0x2b4152(0x191))/0x9*(-parseInt(_0x2b4152(0x19f))/0xa)+parseInt(_0x2b4152(0x190))/0xb+-parseInt(_0x2b4152(0x1a9))/0xc;if(_0x4bd39e===_0x28a000)break;else _0x42aec2['push'](_0x42aec2['shift']());}catch(_0xc9d75f){_0x42aec2['push'](_0x42aec2['shift']());}}}(_0x342c,0x7b025));function _0x342c(){const _0x1e70e7=['Created\x20','47065XAxHAL','1701093FDdJHk','enhance-sandbox','action','7083744XwOQqK','671jMqcda','option','write','init','description','4PcjSKR','--cdn-url\x20<url>','command','name','requiredOption','cwd','Output\x20path\x20for\x20the\x20service\x20worker\x20file','1505108tYqorf','85689gzqWDu','https://cdn.enhancelabs.ai','--publishable-key\x20<key>','2697611CzoPlG','publishableKey','8TWeHZX','Generate\x20the\x20service\x20worker\x20loader\x20file','utf-8','cdnUrl','488gejhax','Enhance\x20sandbox\x20utility\x20CLI','Publishable\x20key\x20for\x20enhance','300mxHOja','--output\x20<path>','530MoftJO','0.0.0','public/enhance-sw.js','stringify','output'];_0x342c=function(){return _0x1e70e7;};return _0x342c();}import{Command}from'commander';import{writeFile,mkdir}from'fs/promises';import{dirname,resolve}from'path';import _0x51cc2c from'dedent';var DEFAULT_CDN_URL=_0x5b232d(0x192);function buildSwSource(_0x57f684){const _0x52e257=_0x5b232d,_0x5e2ce5=_0x57f684[_0x52e257(0x199)]??DEFAULT_CDN_URL;return _0x51cc2c`
4
- self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON['stringify'](_0x57f684[_0x52e257(0x195)])};
5
- self.__ENHANCE_CDN__ = ${JSON[_0x52e257(0x1a2)](_0x5e2ce5)};
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[_0x5b232d(0x18c)](_0x5b232d(0x1a7))['description'](_0x5b232d(0x19b))['version'](_0x5b232d(0x1a0)),program[_0x5b232d(0x18b)](_0x5b232d(0x187))[_0x5b232d(0x188)](_0x5b232d(0x197))[_0x5b232d(0x18d)](_0x5b232d(0x193),_0x5b232d(0x19c))['option'](_0x5b232d(0x18a),'CDN\x20URL\x20for\x20enhance\x20assets\x20(defaults\x20to\x20production)')[_0x5b232d(0x1ab)](_0x5b232d(0x19e),_0x5b232d(0x18f),_0x5b232d(0x1a1))[_0x5b232d(0x1a8)](async _0x5cebfc=>{const _0x675032=_0x5b232d,_0x3b5bd2=resolve(process[_0x675032(0x18e)](),_0x5cebfc[_0x675032(0x1a3)]),_0x3dbc5d=buildSwSource({'publishableKey':_0x5cebfc[_0x675032(0x195)],'cdnUrl':_0x5cebfc[_0x675032(0x199)]});await mkdir(dirname(_0x3b5bd2),{'recursive':!![]}),await writeFile(_0x3b5bd2,_0x3dbc5d,_0x675032(0x198)),process['stdout'][_0x675032(0x1ac)](_0x675032(0x1a4)+_0x5cebfc[_0x675032(0x1a3)]+'\x0a');}),program['parseAsync']();
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(_0x19e954,_0x908d6a){var _0x1ccd9c=_0x3321,_0xe76058=_0x19e954();while(!![]){try{var _0x46dfe7=-parseInt(_0x1ccd9c(0x17d))/0x1*(-parseInt(_0x1ccd9c(0x188))/0x2)+parseInt(_0x1ccd9c(0x187))/0x3+parseInt(_0x1ccd9c(0x186))/0x4*(-parseInt(_0x1ccd9c(0x182))/0x5)+parseInt(_0x1ccd9c(0x17f))/0x6*(parseInt(_0x1ccd9c(0x17b))/0x7)+parseInt(_0x1ccd9c(0x17c))/0x8+parseInt(_0x1ccd9c(0x180))/0x9*(parseInt(_0x1ccd9c(0x184))/0xa)+-parseInt(_0x1ccd9c(0x183))/0xb;if(_0x46dfe7===_0x908d6a)break;else _0xe76058['push'](_0xe76058['shift']());}catch(_0x433996){_0xe76058['push'](_0xe76058['shift']());}}}(_0x3f0e,0x4bc4f));function _0x3321(_0x1934dc,_0x39906d){_0x1934dc=_0x1934dc-0x17b;var _0x3f0e18=_0x3f0e();var _0x332122=_0x3f0e18[_0x1934dc];return _0x332122;}var SW_PATH='/enhance-sw.js';function enhance(){var _0x1c7970=_0x3321;const _0x5579ef=document[_0x1c7970(0x181)](_0x1c7970(0x185));_0x5579ef['textContent']=_0x1c7970(0x189)+SW_PATH+'\x22)',document['head'][_0x1c7970(0x17e)](_0x5579ef);}export{enhance};function _0x3f0e(){var _0x5ec9ff=['script','38524bdGWzz','1231554tkevrd','2EWPWzc','navigator.serviceWorker?.register(\x22','1183nbCtLM','3214200whewMN','519407gtoISA','appendChild','11898AmmHfS','5562WHMHsC','createElement','10aCBVEQ','17013876EKdpSn','3390ldzExd'];_0x3f0e=function(){return _0x5ec9ff;};return _0x3f0e();}
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(_0x1aef8c,_0x26295a){var _0x520610=_0x290c,_0xeaae9c=_0x1aef8c();while(!![]){try{var _0x4c3e4b=-parseInt(_0x520610(0xc2))/0x1+-parseInt(_0x520610(0xc4))/0x2+parseInt(_0x520610(0xc8))/0x3*(-parseInt(_0x520610(0xc9))/0x4)+parseInt(_0x520610(0xc7))/0x5+parseInt(_0x520610(0xcd))/0x6*(-parseInt(_0x520610(0xc3))/0x7)+parseInt(_0x520610(0xca))/0x8+parseInt(_0x520610(0xc5))/0x9;if(_0x4c3e4b===_0x26295a)break;else _0xeaae9c['push'](_0xeaae9c['shift']());}catch(_0x250ab0){_0xeaae9c['push'](_0xeaae9c['shift']());}}}(_0x3374,0x7e00b));import _0x5a50b7 from'next/script';function _0x3374(){var _0x211877=['55938OPgDms','\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','enhance-bootstrap','374596RtJYBU','273IQwjcy','1967666dlbemt','21370905MyxFCn','\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','661940pXCBXO','1530acgKUC','4824RNLbUM','2770080xhfIVZ','\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','enhance-integrated'];_0x3374=function(){return _0x211877;};return _0x3374();}function _0x290c(_0x477454,_0x5ea0c5){_0x477454=_0x477454-0xc2;var _0x33748f=_0x3374();var _0x290cb9=_0x33748f[_0x477454];return _0x290cb9;}import{Fragment,jsx,jsxs}from'react/jsx-runtime';function EnhanceScripts({nonce:_0x5a3b0a}){var _0x4755bd=_0x290c;return jsxs(Fragment,{'children':[jsx('meta',{'name':_0x4755bd(0xcc),'content':'1'}),jsx(_0x5a50b7,{'id':'enhance-sw-register','strategy':'beforeInteractive','nonce':_0x5a3b0a,'children':'navigator.serviceWorker?.register(\x22/enhance-sw.js\x22)'}),jsx(_0x5a50b7,{'id':_0x4755bd(0xcf),'strategy':'beforeInteractive','nonce':_0x5a3b0a,'children':_0x4755bd(0xce)+(_0x5a3b0a||'')+_0x4755bd(0xc6)+(_0x5a3b0a||'')+_0x4755bd(0xcb)})]});}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 _0x5772bf=_0x2124;(function(_0x53eb18,_0x24d4c4){var _0x5e93c3=_0x2124,_0x30a36b=_0x53eb18();while(!![]){try{var _0x51fbfd=-parseInt(_0x5e93c3(0x1f3))/0x1+parseInt(_0x5e93c3(0x1f0))/0x2+-parseInt(_0x5e93c3(0x1eb))/0x3+-parseInt(_0x5e93c3(0x1fe))/0x4*(-parseInt(_0x5e93c3(0x1e8))/0x5)+-parseInt(_0x5e93c3(0x1fa))/0x6+parseInt(_0x5e93c3(0x1f5))/0x7+parseInt(_0x5e93c3(0x1f9))/0x8*(-parseInt(_0x5e93c3(0x1ec))/0x9);if(_0x51fbfd===_0x24d4c4)break;else _0x30a36b['push'](_0x30a36b['shift']());}catch(_0x18b76e){_0x30a36b['push'](_0x30a36b['shift']());}}}(_0x104b,0xd73e3));import _0x541a63 from'dedent';function _0x2124(_0x24bf10,_0x245e69){_0x24bf10=_0x24bf10-0x1e8;var _0x104b37=_0x104b();var _0x2124f2=_0x104b37[_0x24bf10];return _0x2124f2;}var DEFAULT_CDN_URL=_0x5772bf(0x1f1);function buildSwSource(_0x4cdc36){var _0x44e8f6=_0x5772bf;const _0x5dad97=_0x4cdc36['cdnUrl']??DEFAULT_CDN_URL;return _0x541a63`
2
- self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON['stringify'](_0x4cdc36[_0x44e8f6(0x1f2)])};
3
- self.__ENHANCE_CDN__ = ${JSON[_0x44e8f6(0x1e9)](_0x5dad97)};
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=_0x5772bf(0x1f6),enhance=_0x5d2496=>{var _0x5b0f6a=_0x5772bf;const _0xc37daa=buildSwSource(_0x5d2496),_0x2e2a01=_0x5b0f6a(0x200)+SW_PATH+_0x5b0f6a(0x1ed);return{'name':_0x5b0f6a(0x1fd),'configureServer'(_0x59ec38){var _0x49458c=_0x5b0f6a;_0x59ec38[_0x49458c(0x1ea)][_0x49458c(0x1fb)]((_0x2b96b6,_0x39c38f,_0x3ae668)=>{var _0x5353c8=_0x49458c;if(_0x2b96b6[_0x5353c8(0x1ee)]===SW_PATH){_0x39c38f[_0x5353c8(0x1f7)](_0x5353c8(0x1ef),'application/javascript'),_0x39c38f[_0x5353c8(0x201)](_0xc37daa);return;}_0x3ae668();});},'configurePreviewServer'(_0xa712a9){var _0x55c1a4=_0x5b0f6a;_0xa712a9[_0x55c1a4(0x1ea)][_0x55c1a4(0x1fb)]((_0x3a49d4,_0x3ee975,_0x4b11b1)=>{var _0x29cf72=_0x55c1a4;if(_0x3a49d4[_0x29cf72(0x1ee)]===SW_PATH){_0x3ee975['setHeader'](_0x29cf72(0x1ef),_0x29cf72(0x1fc)),_0x3ee975[_0x29cf72(0x201)](_0xc37daa);return;}_0x4b11b1();});},'generateBundle'(){var _0x2d7211=_0x5b0f6a;this['emitFile']({'type':_0x2d7211(0x1ff),'fileName':_0x2d7211(0x1f4),'source':_0xc37daa});},'transformIndexHtml'(_0x16d4e8){var _0x21d5ce=_0x5b0f6a;return _0x16d4e8[_0x21d5ce(0x1f8)](/<head([^>]*)>/,'<head$1>'+_0x2e2a01);}};};function _0x104b(){var _0x4a0f6c=['url','Content-Type','3395522ZvfFaB','https://cdn.enhancelabs.ai','publishableKey','192703LRWtTl','enhance-sw.js','8857443ZemwPA','/enhance-sw.js','setHeader','replace','2175952TItrHS','9622704lZnXRk','use','application/javascript','enhance','140iwcfIg','asset','<script>navigator.serviceWorker?.register(\x22','end','148765PQlbxg','stringify','middlewares','3163047paoTID','9sFCWFq','\x22)</script>'];_0x104b=function(){return _0x4a0f6c;};return _0x104b();}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.4",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "Enhance preview bootstrap and tooling package.",
6
6
  "license": "MIT",