@zktx.io/walrus-sites-preview 0.0.2 → 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.
Files changed (3) hide show
  1. package/README.md +84 -44
  2. package/package.json +1 -1
  3. package/preview.mjs +7 -4
package/README.md CHANGED
@@ -1,95 +1,135 @@
1
- # Walrus Sites Preview (CLI)
1
+ # Walrus Sites Preview
2
2
 
3
- Installable CLI to preview Walrus Sites locally:
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
- - **site mode**: fetch resources via Sui RPC + Walrus aggregator for a given site object ID
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
- ## Install (as dev dependency)
34
+ ---
35
+
36
+ ## Install
12
37
 
13
38
  ```sh
14
39
  npm i -D @zktx.io/walrus-sites-preview
15
40
  ```
16
41
 
17
- ## Run (via npm script)
42
+ ---
18
43
 
19
- Add this to your project:
44
+ ## Quick Start
45
+
46
+ Add an npm script to your project:
20
47
 
21
48
  ```json
22
49
  {
23
50
  "scripts": {
24
51
  "preview:testnet": "preview -testnet -id 0xYOUR_SITE_OBJECT_ID -port 3000",
25
- "preview:mainnet": "preview -mainnet -id 0xYOUR_SITE_OBJECT_ID -port 3000",
26
- "preview": "preview"
52
+ "preview:mainnet": "preview -mainnet -id 0xYOUR_SITE_OBJECT_ID -port 3000"
27
53
  }
28
54
  }
29
55
  ```
30
56
 
31
- Then run:
57
+ Run:
32
58
 
33
59
  ```sh
34
60
  npm run preview:testnet
35
61
  ```
36
62
 
37
- This starts a local server at `http://localhost:3000`.
63
+ Then open:
38
64
 
39
- You can inspect the effective config at `http://localhost:3000/__config`.
65
+ `http://localhost:3000`
40
66
 
41
- If you prefer a file-based config, create `config.json` next to your `package.json` and pass overrides as needed (the CLI flags win).
67
+ You can inspect the resolved configuration at:
42
68
 
43
- To pass arguments dynamically, use `--`:
69
+ `http://localhost:3000/__config`
44
70
 
45
- ```sh
46
- npm run preview -- -testnet -id 0xYOUR_SITE_OBJECT_ID -port 3000
47
- ```
48
-
49
- ## Where `dist` comes from (portal build)
71
+ ---
50
72
 
51
- This section is for maintainers of this package. Consumers don’t need to build `dist/` manually (it ships in the npm package).
73
+ ## Configuration
52
74
 
53
- - Vendored from the walrus-sites portal codebase:
54
- - Source repo: https://github.com/MystenLabs/walrus-sites/tree/main/portal
55
- - `portal/worker` → `./portal-worker`
56
- - `portal/common` → `./portal-common`
57
- - Source: `./portal-worker/src` (service worker TS) and `./portal-worker/static` (static assets)
58
- - Shared libs: `./portal-common/lib/src` (shared implementation used by the worker)
59
- - Build configs: `./webpack.config.*.cjs` (kept in this repo, not published)
60
- - Build command:
75
+ You can optionally create a `config.json` next to your `package.json`.
61
76
 
62
- ```sh
63
- npm install
64
- npm run build
65
- ```
77
+ CLI flags always override file-based config.
66
78
 
67
- ## Publish
79
+ If you use `-testnet` or `-mainnet`, the required RPC and aggregator URLs are filled automatically.
68
80
 
69
- This package is set up to publish with `dist/` included. `npm pack` / `npm publish` runs `prepack`, which rebuilds `dist/` via `npm run build`.
81
+ `config.json` supports:
70
82
 
71
- ## Maintainers: static mode
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)
72
89
 
73
- If you only want to serve a local static folder as a SPA:
90
+ Example:
74
91
 
75
- ```sh
76
- npx preview --mode static --dist ./dist -port 3000
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
+ }
77
100
  ```
78
101
 
79
- If your `dist` lives somewhere else:
102
+ To pass arguments dynamically:
80
103
 
81
104
  ```sh
82
- npx preview --mode static --dist /absolute/path/to/dist
105
+ npm i -D @zktx.io/walrus-sites-preview
83
106
  ```
84
107
 
85
- ## Options
108
+ Add a pass-through script:
86
109
 
87
- ```sh
88
- npx preview -port 8090 --open
110
+ ```json
111
+ {
112
+ "scripts": {
113
+ "preview": "preview"
114
+ }
115
+ }
89
116
  ```
90
117
 
91
- Override site config without editing `config.json`:
118
+ Then run:
92
119
 
93
120
  ```sh
94
- npx preview --site-object-id 0x... --rpc https://fullnode.mainnet.sui.io --aggregator https://aggregator.walrus-mainnet.walrus.space --site-package 0x...
121
+ npm run preview -- -testnet -id 0xYOUR_SITE_OBJECT_ID -port 3000
95
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zktx.io/walrus-sites-preview",
3
3
  "description": "Local preview CLI for Walrus Sites (fetch from Sui + Walrus, or serve bundled static portal dist).",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "preview": "preview.mjs"
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
- if (!resolved.startsWith(rootDir + path.sep) && resolved !== rootDir) return null;
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
- "Missing npm dependencies for site mode.",
407
- "Run `npm install` in this package (requires network access).",
408
- `Or run static mode: \`${CLI_NAME} --mode static\``,
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
  }