@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.
Files changed (3) hide show
  1. package/README.md +85 -50
  2. package/package.json +1 -1
  3. package/preview.mjs +7 -4
package/README.md CHANGED
@@ -1,100 +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)
12
-
13
- ```sh
14
- npm i -D @zktx.io/walrus-sites-preview
15
- ```
34
+ ---
16
35
 
17
- ## Run (recommended via `npx`)
36
+ ## Install
18
37
 
19
38
  ```sh
20
- npx preview -testnet -id 0xYOUR_SITE_OBJECT_ID -port 3000
39
+ npm i -D @zktx.io/walrus-sites-preview
21
40
  ```
22
41
 
23
- This starts a local server at `http://localhost:3000`. Running `preview` without options prints help.
42
+ ---
24
43
 
25
- You can inspect the effective config at `http://localhost:3000/__config`.
44
+ ## Quick Start
26
45
 
27
- If you prefer a file-based config, create `config.json` next to your `package.json` and pass overrides as needed (the CLI flags win).
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
- Then run:
57
+ Run:
44
58
 
45
59
  ```sh
46
60
  npm run preview:testnet
47
61
  ```
48
62
 
49
- To pass arguments dynamically, use `--`:
63
+ Then open:
50
64
 
51
- ```sh
52
- npm run preview -- -testnet -id 0xYOUR_SITE_OBJECT_ID -port 3000
53
- ```
65
+ `http://localhost:3000`
54
66
 
55
- ## Where `dist` comes from (portal build)
67
+ You can inspect the resolved configuration at:
56
68
 
57
- This section is for maintainers of this package. Consumers don’t need to build `dist/` manually (it ships in the npm package).
69
+ `http://localhost:3000/__config`
58
70
 
59
- - Vendored from the walrus-sites portal codebase:
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
- ```sh
68
- npm install
69
- npm run build
70
- ```
73
+ ## Configuration
71
74
 
72
- ## Publish
75
+ You can optionally create a `config.json` next to your `package.json`.
73
76
 
74
- This package is set up to publish with `dist/` included. `npm pack` / `npm publish` runs `prepack`, which rebuilds `dist/` via `npm run build`.
77
+ CLI flags always override file-based config.
75
78
 
76
- ## Maintainers: static mode
79
+ If you use `-testnet` or `-mainnet`, the required RPC and aggregator URLs are filled automatically.
77
80
 
78
- If you only want to serve a local static folder as a SPA:
81
+ `config.json` supports:
79
82
 
80
- ```sh
81
- npx preview --mode static --dist ./dist -port 3000
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
- If your `dist` lives somewhere else:
102
+ To pass arguments dynamically:
85
103
 
86
104
  ```sh
87
- npx preview --mode static --dist /absolute/path/to/dist
105
+ npm i -D @zktx.io/walrus-sites-preview
88
106
  ```
89
107
 
90
- ## Options
108
+ Add a pass-through script:
91
109
 
92
- ```sh
93
- npx preview -port 8090 --open
110
+ ```json
111
+ {
112
+ "scripts": {
113
+ "preview": "preview"
114
+ }
115
+ }
94
116
  ```
95
117
 
96
- Override site config without editing `config.json`:
118
+ Then run:
97
119
 
98
120
  ```sh
99
- 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
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
@@ -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.1",
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
  }