@zktx.io/walrus-sites-preview 0.0.1 → 0.0.3
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 +85 -50
- package/package.json +1 -1
- package/preview.mjs +7 -4
package/README.md
CHANGED
|
@@ -1,100 +1,135 @@
|
|
|
1
|
-
# Walrus Sites Preview
|
|
1
|
+
# Walrus Sites Preview
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Preview Walrus Sites already deployed on testnet or mainnet locally using a familiar
|
|
4
|
+
npm → localhost workflow — without setting up a portal.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
This tool is for developers who want to quickly preview or debug a deployed Walrus Site in a simple, local-style environment.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Why this exists
|
|
11
|
+
|
|
12
|
+
Previewing a Walrus Site on testnet usually requires setting up a portal, which can be difficult for beginners and unnecessary for quick debugging.
|
|
13
|
+
|
|
14
|
+
This CLI removes that friction.
|
|
15
|
+
Give it a site object ID, and it serves the site locally.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## What it does
|
|
20
|
+
|
|
21
|
+
- Loads a Walrus Site using a site object ID
|
|
22
|
+
- Fetches resources via Sui RPC + Walrus aggregator
|
|
23
|
+
- Serves the site locally (e.g. `http://localhost:3000`)
|
|
24
|
+
- Focused purely on developer preview and debugging
|
|
25
|
+
|
|
26
|
+
This is not a production hosting solution and does not replace portals.
|
|
27
|
+
|
|
28
|
+
---
|
|
6
29
|
|
|
7
30
|
## Requirements
|
|
8
31
|
|
|
9
32
|
- Node.js 18+
|
|
10
33
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```sh
|
|
14
|
-
npm i -D @zktx.io/walrus-sites-preview
|
|
15
|
-
```
|
|
34
|
+
---
|
|
16
35
|
|
|
17
|
-
##
|
|
36
|
+
## Install
|
|
18
37
|
|
|
19
38
|
```sh
|
|
20
|
-
|
|
39
|
+
npm i -D @zktx.io/walrus-sites-preview
|
|
21
40
|
```
|
|
22
41
|
|
|
23
|
-
|
|
42
|
+
---
|
|
24
43
|
|
|
25
|
-
|
|
44
|
+
## Quick Start
|
|
26
45
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
## Run (via npm script)
|
|
30
|
-
|
|
31
|
-
Add this to your project:
|
|
46
|
+
Add an npm script to your project:
|
|
32
47
|
|
|
33
48
|
```json
|
|
34
49
|
{
|
|
35
50
|
"scripts": {
|
|
36
51
|
"preview:testnet": "preview -testnet -id 0xYOUR_SITE_OBJECT_ID -port 3000",
|
|
37
|
-
"preview:mainnet": "preview -mainnet -id 0xYOUR_SITE_OBJECT_ID -port 3000"
|
|
38
|
-
"preview": "preview"
|
|
52
|
+
"preview:mainnet": "preview -mainnet -id 0xYOUR_SITE_OBJECT_ID -port 3000"
|
|
39
53
|
}
|
|
40
54
|
}
|
|
41
55
|
```
|
|
42
56
|
|
|
43
|
-
|
|
57
|
+
Run:
|
|
44
58
|
|
|
45
59
|
```sh
|
|
46
60
|
npm run preview:testnet
|
|
47
61
|
```
|
|
48
62
|
|
|
49
|
-
|
|
63
|
+
Then open:
|
|
50
64
|
|
|
51
|
-
|
|
52
|
-
npm run preview -- -testnet -id 0xYOUR_SITE_OBJECT_ID -port 3000
|
|
53
|
-
```
|
|
65
|
+
`http://localhost:3000`
|
|
54
66
|
|
|
55
|
-
|
|
67
|
+
You can inspect the resolved configuration at:
|
|
56
68
|
|
|
57
|
-
|
|
69
|
+
`http://localhost:3000/__config`
|
|
58
70
|
|
|
59
|
-
|
|
60
|
-
- `portal/worker` → `./portal-worker`
|
|
61
|
-
- `portal/common` → `./portal-common`
|
|
62
|
-
- Source: `./portal-worker/src` (service worker TS) and `./portal-worker/static` (static assets)
|
|
63
|
-
- Shared libs: `./portal-common/lib/src` (shared implementation used by the worker)
|
|
64
|
-
- Build configs: `./webpack.config.*.cjs` (kept in this repo, not published)
|
|
65
|
-
- Build command:
|
|
71
|
+
---
|
|
66
72
|
|
|
67
|
-
|
|
68
|
-
npm install
|
|
69
|
-
npm run build
|
|
70
|
-
```
|
|
73
|
+
## Configuration
|
|
71
74
|
|
|
72
|
-
|
|
75
|
+
You can optionally create a `config.json` next to your `package.json`.
|
|
73
76
|
|
|
74
|
-
|
|
77
|
+
CLI flags always override file-based config.
|
|
75
78
|
|
|
76
|
-
|
|
79
|
+
If you use `-testnet` or `-mainnet`, the required RPC and aggregator URLs are filled automatically.
|
|
77
80
|
|
|
78
|
-
|
|
81
|
+
`config.json` supports:
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
- `siteObjectId` (required)
|
|
84
|
+
- `rpcUrlList` (required unless using `-testnet` / `-mainnet`)
|
|
85
|
+
- `aggregatorUrl` (required unless using `-testnet` / `-mainnet`)
|
|
86
|
+
- `sitePackage` (required unless using `-testnet` / `-mainnet`)
|
|
87
|
+
- `network` (optional, informational)
|
|
88
|
+
- `host`, `port` (via CLI flags)
|
|
89
|
+
|
|
90
|
+
Example:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"network": "testnet",
|
|
95
|
+
"rpcUrlList": ["https://fullnode.testnet.sui.io"],
|
|
96
|
+
"aggregatorUrl": "https://aggregator.walrus-testnet.walrus.space",
|
|
97
|
+
"sitePackage": "0x...",
|
|
98
|
+
"siteObjectId": "0x..."
|
|
99
|
+
}
|
|
82
100
|
```
|
|
83
101
|
|
|
84
|
-
|
|
102
|
+
To pass arguments dynamically:
|
|
85
103
|
|
|
86
104
|
```sh
|
|
87
|
-
|
|
105
|
+
npm i -D @zktx.io/walrus-sites-preview
|
|
88
106
|
```
|
|
89
107
|
|
|
90
|
-
|
|
108
|
+
Add a pass-through script:
|
|
91
109
|
|
|
92
|
-
```
|
|
93
|
-
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"scripts": {
|
|
113
|
+
"preview": "preview"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
94
116
|
```
|
|
95
117
|
|
|
96
|
-
|
|
118
|
+
Then run:
|
|
97
119
|
|
|
98
120
|
```sh
|
|
99
|
-
|
|
121
|
+
npm run preview -- -testnet -id 0xYOUR_SITE_OBJECT_ID -port 3000
|
|
100
122
|
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Source attribution
|
|
127
|
+
|
|
128
|
+
This package vendors and adapts parts of the Walrus Sites portal source code.
|
|
129
|
+
|
|
130
|
+
Where `dist` comes from (portal build):
|
|
131
|
+
|
|
132
|
+
- Source repo: https://github.com/MystenLabs/walrus-sites/tree/main/portal
|
|
133
|
+
- `portal/worker` → `./portal-worker`
|
|
134
|
+
- `portal/common` → `./portal-common`
|
|
135
|
+
- Source: `./portal-worker/src` (service worker TypeScript) and `./portal-worker/static` (static assets)
|
package/package.json
CHANGED
package/preview.mjs
CHANGED
|
@@ -194,7 +194,9 @@ function contentType(filePath) {
|
|
|
194
194
|
function safeResolve(rootDir, urlPath) {
|
|
195
195
|
const rel = urlPath.replace(/^\/+/, "");
|
|
196
196
|
const resolved = path.resolve(rootDir, rel);
|
|
197
|
-
|
|
197
|
+
const normalizedRoot = path.normalize(rootDir + path.sep);
|
|
198
|
+
const normalizedResolved = path.normalize(resolved + path.sep);
|
|
199
|
+
if (!normalizedResolved.startsWith(normalizedRoot)) return null;
|
|
198
200
|
return resolved;
|
|
199
201
|
}
|
|
200
202
|
|
|
@@ -403,9 +405,10 @@ async function createSiteHandler(siteConfig) {
|
|
|
403
405
|
if (message.includes("ERR_MODULE_NOT_FOUND") || message.includes("Cannot find package")) {
|
|
404
406
|
throw new Error(
|
|
405
407
|
[
|
|
406
|
-
"
|
|
407
|
-
"
|
|
408
|
-
|
|
408
|
+
"Failed to load @mysten/sui dependencies for site mode.",
|
|
409
|
+
"If you're running from this repo, run `npm install` here first.",
|
|
410
|
+
"If you're using the published package, reinstall it in your project: `npm i -D @zktx.io/walrus-sites-preview`.",
|
|
411
|
+
"Then run the command again.",
|
|
409
412
|
].join("\n"),
|
|
410
413
|
);
|
|
411
414
|
}
|