@enhance-eng/sandbox 0.4.2 → 0.5.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 +27 -1
- package/dist/cli.js +4 -4
- package/dist/index.js +1 -1
- package/dist/next/index.d.ts +7 -0
- package/dist/next/index.js +1 -0
- package/dist/vite/index.js +4 -4
- package/package.json +10 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Enhance sandbox library for adding preview functionality to your application.
|
|
4
4
|
|
|
5
|
-
**Supported frameworks:** React SPAs and statically generated sites.
|
|
5
|
+
**Supported frameworks:** React SPAs, Next.js (App Router), and statically generated sites.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -10,6 +10,32 @@ Enhance sandbox library for adding preview functionality to your application.
|
|
|
10
10
|
npm install @enhance-eng/sandbox
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
## Next.js (App Router)
|
|
14
|
+
|
|
15
|
+
To enable Enhance in your Next.js application and resolve hydration errors, add the `EnhanceScripts` component to your root layout.
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
// app/layout.tsx
|
|
19
|
+
import { EnhanceScripts } from "@enhance-eng/sandbox/next";
|
|
20
|
+
|
|
21
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
22
|
+
return (
|
|
23
|
+
<html lang="en">
|
|
24
|
+
<head>
|
|
25
|
+
<EnhanceScripts />
|
|
26
|
+
</head>
|
|
27
|
+
<body>{children}</body>
|
|
28
|
+
</html>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
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.
|
|
38
|
+
|
|
13
39
|
## Vite
|
|
14
40
|
|
|
15
41
|
Add the plugin to your Vite config:
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON[
|
|
5
|
-
self.__ENHANCE_CDN__ = ${JSON[
|
|
3
|
+
function _0x39ae(_0x1cc14,_0x1856a3){_0x1cc14=_0x1cc14-0xdb;const _0xd87329=_0xd873();let _0x39ae73=_0xd87329[_0x1cc14];return _0x39ae73;}const _0x25baf0=_0x39ae;(function(_0xef7e99,_0x31d8b3){const _0x381e67=_0x39ae,_0x174caa=_0xef7e99();while(!![]){try{const _0x1afd9a=parseInt(_0x381e67(0xf7))/0x1*(parseInt(_0x381e67(0xdc))/0x2)+parseInt(_0x381e67(0xf2))/0x3*(-parseInt(_0x381e67(0xea))/0x4)+parseInt(_0x381e67(0xe7))/0x5+-parseInt(_0x381e67(0xe5))/0x6*(-parseInt(_0x381e67(0xe9))/0x7)+parseInt(_0x381e67(0xe6))/0x8*(-parseInt(_0x381e67(0xf6))/0x9)+-parseInt(_0x381e67(0xf9))/0xa*(parseInt(_0x381e67(0xe1))/0xb)+parseInt(_0x381e67(0xf3))/0xc;if(_0x1afd9a===_0x31d8b3)break;else _0x174caa['push'](_0x174caa['shift']());}catch(_0x3899fe){_0x174caa['push'](_0x174caa['shift']());}}}(_0xd873,0x4396f));import{Command}from'commander';import{writeFile,mkdir}from'fs/promises';import{dirname,resolve}from'path';import _0x304d3b from'dedent';var DEFAULT_CDN_URL=_0x25baf0(0xe4);function _0xd873(){const _0x45f087=['option','stdout','stringify','--publishable-key\x20<key>','cdnUrl','--cdn-url\x20<url>','utf-8','6kXVoNp','5406300flEFVM','CDN\x20URL\x20for\x20enhance\x20assets\x20(defaults\x20to\x20production)','Enhance\x20sandbox\x20utility\x20CLI','1612134UGIyBq','20rsKBOB','parseAsync','3513910QsMuLA','Output\x20path\x20for\x20the\x20service\x20worker\x20file','write','output','name','description','51702pVwfbF','publishableKey','public/enhance-sw.js','Created\x20','cwd','11RpSUqC','command','version','https://cdn.enhancelabs.ai','3306uFiTFX','16YDvJEl','1112555fMuFmp','action','4200zFYmbs','1068332MMcfAs'];_0xd873=function(){return _0x45f087;};return _0xd873();}function buildSwSource(_0x191913){const _0x1d2b90=_0x25baf0,_0x5a6475=_0x191913['cdnUrl']??DEFAULT_CDN_URL;return _0x304d3b`
|
|
4
|
+
self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON['stringify'](_0x191913[_0x1d2b90(0xdd)])};
|
|
5
|
+
self.__ENHANCE_CDN__ = ${JSON[_0x1d2b90(0xed)](_0x5a6475)};
|
|
6
6
|
importScripts(self.__ENHANCE_CDN__ + "/loader/loader.v1.js");
|
|
7
|
-
`;}
|
|
7
|
+
`;}var program=new Command();program[_0x25baf0(0xfd)]('enhance-sandbox')[_0x25baf0(0xdb)](_0x25baf0(0xf5))[_0x25baf0(0xe3)]('0.0.0'),program[_0x25baf0(0xe2)]('init')['description']('Generate\x20the\x20service\x20worker\x20loader\x20file')['requiredOption'](_0x25baf0(0xee),'Publishable\x20key\x20for\x20enhance')[_0x25baf0(0xeb)](_0x25baf0(0xf0),_0x25baf0(0xf4))[_0x25baf0(0xeb)]('--output\x20<path>',_0x25baf0(0xfa),_0x25baf0(0xde))[_0x25baf0(0xe8)](async _0x3d64a6=>{const _0x104580=_0x25baf0,_0x27062d=resolve(process[_0x104580(0xe0)](),_0x3d64a6[_0x104580(0xfc)]),_0x3bc787=buildSwSource({'publishableKey':_0x3d64a6['publishableKey'],'cdnUrl':_0x3d64a6[_0x104580(0xef)]});await mkdir(dirname(_0x27062d),{'recursive':!![]}),await writeFile(_0x27062d,_0x3bc787,_0x104580(0xf1)),process[_0x104580(0xec)][_0x104580(0xfb)](_0x104580(0xdf)+_0x3d64a6['output']+'\x0a');}),program[_0x25baf0(0xf8)]();
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
function _0x399a(){var _0x4a8466=['890xCFMpv','8682PMfMKL','/enhance-sw.js','createElement','3207348rDwcpQ','330058zvTPDH','head','1730JLyMUs','4726015HMiadh','8DaPCKb','1924100xRZhIO','8obAXRL','62433qEIObR','8940525LsZDgT'];_0x399a=function(){return _0x4a8466;};return _0x399a();}var _0x19df33=_0x4102;(function(_0xd7350d,_0x33c52d){var _0x498a31=_0x4102,_0x2d133c=_0xd7350d();while(!![]){try{var _0x3aa225=parseInt(_0x498a31(0x9c))/0x1*(parseInt(_0x498a31(0xa0))/0x2)+-parseInt(_0x498a31(0x9b))/0x3+parseInt(_0x498a31(0xa1))/0x4+-parseInt(_0x498a31(0x97))/0x5*(-parseInt(_0x498a31(0x98))/0x6)+parseInt(_0x498a31(0x9f))/0x7*(-parseInt(_0x498a31(0xa2))/0x8)+-parseInt(_0x498a31(0xa3))/0x9*(-parseInt(_0x498a31(0x9e))/0xa)+-parseInt(_0x498a31(0x96))/0xb;if(_0x3aa225===_0x33c52d)break;else _0x2d133c['push'](_0x2d133c['shift']());}catch(_0x42c2c8){_0x2d133c['push'](_0x2d133c['shift']());}}}(_0x399a,0xab5c0));function _0x4102(_0x56934a,_0x244299){_0x56934a=_0x56934a-0x96;var _0x399ada=_0x399a();var _0x41023d=_0x399ada[_0x56934a];return _0x41023d;}var SW_PATH=_0x19df33(0x99);function enhance(){var _0x44d10d=_0x19df33;const _0x57c3f3=document[_0x44d10d(0x9a)]('script');_0x57c3f3['textContent']='navigator.serviceWorker?.register(\x22'+SW_PATH+'\x22)',document[_0x44d10d(0x9d)]['appendChild'](_0x57c3f3);}export{enhance};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(_0x429c3e,_0xfdecdc){var _0xeade24=_0x87a1,_0x38a56d=_0x429c3e();while(!![]){try{var _0x27bbc5=-parseInt(_0xeade24(0x179))/0x1*(-parseInt(_0xeade24(0x17f))/0x2)+-parseInt(_0xeade24(0x183))/0x3*(-parseInt(_0xeade24(0x17c))/0x4)+parseInt(_0xeade24(0x184))/0x5*(parseInt(_0xeade24(0x187))/0x6)+-parseInt(_0xeade24(0x17a))/0x7+-parseInt(_0xeade24(0x182))/0x8+parseInt(_0xeade24(0x186))/0x9+-parseInt(_0xeade24(0x178))/0xa*(parseInt(_0xeade24(0x181))/0xb);if(_0x27bbc5===_0xfdecdc)break;else _0x38a56d['push'](_0x38a56d['shift']());}catch(_0x45dc85){_0x38a56d['push'](_0x38a56d['shift']());}}}(_0xd937,0x7ec5a));import _0x5b161e from'next/script';import{Fragment,jsx,jsxs}from'react/jsx-runtime';function EnhanceScripts({nonce:_0x55d1ce}){var _0x36f584=_0x87a1;return jsxs(Fragment,{'children':[jsx(_0x36f584(0x180),{'name':_0x36f584(0x17e),'content':'1'}),jsx(_0x5b161e,{'id':'enhance-sw-register','strategy':_0x36f584(0x185),'nonce':_0x55d1ce,'children':_0x36f584(0x177)}),jsx(_0x5b161e,{'id':_0x36f584(0x17b),'src':_0x36f584(0x188),'strategy':_0x36f584(0x185),'nonce':_0x55d1ce}),jsx(_0x5b161e,{'id':_0x36f584(0x176),'src':_0x36f584(0x175),'strategy':_0x36f584(0x17d),'nonce':_0x55d1ce})]});}function _0x87a1(_0x45dd76,_0x52d624){_0x45dd76=_0x45dd76-0x175;var _0xd937c7=_0xd937();var _0x87a18=_0xd937c7[_0x45dd76];return _0x87a18;}function _0xd937(){var _0x54a2d0=['124518QlrZHN','/__enhance/init.js','/__enhance/overlay.js','enhance-overlay','navigator.serviceWorker?.register(\x22/enhance-sw.js\x22)','9930NcRdSl','43OFRyJu','5623898LJhzjt','enhance-init','34756ykBqIZ','afterInteractive','enhance-integrated','8054IYDPiC','meta','55gZsFDP','4690656WChCOZ','186qzAOsX','170jPFzbw','beforeInteractive','4468392CAMJVW'];_0xd937=function(){return _0x54a2d0;};return _0xd937();}export{EnhanceScripts};
|
package/dist/vite/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function
|
|
2
|
-
self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON[
|
|
3
|
-
self.__ENHANCE_CDN__ = ${JSON[
|
|
1
|
+
function _0x51f6(){var _0x139ac1=['url','2786571CUIbRk','808695dZUwfJ','emitFile','\x22)</script>','<script>navigator.serviceWorker?.register(\x22','enhance-sw.js','https://cdn.enhancelabs.ai','asset','end','Content-Type','use','303826OArAdD','21mXReNv','stringify','<head$1>','application/javascript','replace','3QbtOsO','1771912DzcKgv','3848556QUhYGo','/enhance-sw.js','enhance','2163090OjsijO','1292252FHagJO','middlewares'];_0x51f6=function(){return _0x139ac1;};return _0x51f6();}var _0x10cb34=_0x2b48;(function(_0x1ff09a,_0x517e1a){var _0x3b54d8=_0x2b48,_0x48beca=_0x1ff09a();while(!![]){try{var _0x118009=-parseInt(_0x3b54d8(0x6e))/0x1*(-parseInt(_0x3b54d8(0x82))/0x2)+-parseInt(_0x3b54d8(0x78))/0x3+parseInt(_0x3b54d8(0x74))/0x4+-parseInt(_0x3b54d8(0x73))/0x5+parseInt(_0x3b54d8(0x70))/0x6+parseInt(_0x3b54d8(0x83))/0x7*(-parseInt(_0x3b54d8(0x6f))/0x8)+parseInt(_0x3b54d8(0x77))/0x9;if(_0x118009===_0x517e1a)break;else _0x48beca['push'](_0x48beca['shift']());}catch(_0x5bceb6){_0x48beca['push'](_0x48beca['shift']());}}}(_0x51f6,0x58abd));function _0x2b48(_0x50139d,_0x5acd90){_0x50139d=_0x50139d-0x6d;var _0x51f6fc=_0x51f6();var _0x2b48ae=_0x51f6fc[_0x50139d];return _0x2b48ae;}import _0x5a26bb from'dedent';var DEFAULT_CDN_URL=_0x10cb34(0x7d);function buildSwSource(_0x8f6b86){var _0x526f1f=_0x10cb34;const _0x141dcb=_0x8f6b86['cdnUrl']??DEFAULT_CDN_URL;return _0x5a26bb`
|
|
2
|
+
self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON[_0x526f1f(0x84)](_0x8f6b86['publishableKey'])};
|
|
3
|
+
self.__ENHANCE_CDN__ = ${JSON['stringify'](_0x141dcb)};
|
|
4
4
|
importScripts(self.__ENHANCE_CDN__ + "/loader/loader.v1.js");
|
|
5
|
-
`;}var SW_PATH=
|
|
5
|
+
`;}var SW_PATH=_0x10cb34(0x71),enhance=_0x27d2c5=>{var _0x175996=_0x10cb34;const _0x1f590b=buildSwSource(_0x27d2c5),_0xdcd7c0=_0x175996(0x7b)+SW_PATH+_0x175996(0x7a);return{'name':_0x175996(0x72),'configureServer'(_0x3c5400){_0x3c5400['middlewares']['use']((_0x52e1c6,_0x107e80,_0x165cf0)=>{var _0x46ad4c=_0x2b48;if(_0x52e1c6[_0x46ad4c(0x76)]===SW_PATH){_0x107e80['setHeader'](_0x46ad4c(0x80),_0x46ad4c(0x86)),_0x107e80[_0x46ad4c(0x7f)](_0x1f590b);return;}_0x165cf0();});},'configurePreviewServer'(_0x856979){var _0x593117=_0x175996;_0x856979[_0x593117(0x75)][_0x593117(0x81)]((_0x385165,_0x5e79e4,_0x4fb33c)=>{var _0x1ca821=_0x593117;if(_0x385165[_0x1ca821(0x76)]===SW_PATH){_0x5e79e4['setHeader'](_0x1ca821(0x80),_0x1ca821(0x86)),_0x5e79e4[_0x1ca821(0x7f)](_0x1f590b);return;}_0x4fb33c();});},'generateBundle'(){var _0x3269f0=_0x175996;this[_0x3269f0(0x79)]({'type':_0x3269f0(0x7e),'fileName':_0x3269f0(0x7c),'source':_0x1f590b});},'transformIndexHtml'(_0x5edbea){var _0x50b5ce=_0x175996;return _0x5edbea[_0x50b5ce(0x6d)](/<head([^>]*)>/,_0x50b5ce(0x85)+_0xdcd7c0);}};};export{enhance};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enhance-eng/sandbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Enhance preview bootstrap and tooling package.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
"./vite": {
|
|
16
16
|
"types": "./dist/vite/index.d.ts",
|
|
17
17
|
"import": "./dist/vite/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./next": {
|
|
20
|
+
"types": "./dist/next/index.d.ts",
|
|
21
|
+
"import": "./dist/next/index.js"
|
|
18
22
|
}
|
|
19
23
|
},
|
|
20
24
|
"files": [
|
|
@@ -29,6 +33,11 @@
|
|
|
29
33
|
"dedent": "^1.7.1",
|
|
30
34
|
"zod": "^3.22.4"
|
|
31
35
|
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"next": ">=13.0.0",
|
|
38
|
+
"react": ">=18.0.0",
|
|
39
|
+
"react-dom": ">=18.0.0"
|
|
40
|
+
},
|
|
32
41
|
"publishConfig": {
|
|
33
42
|
"access": "public"
|
|
34
43
|
}
|