Skip to content

Commit cbe59d1

Browse files
committed
docs: package release docs
1 parent 60e0390 commit cbe59d1

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
### Docs
1515

1616
- Added missing docs pages for `@openclaw/fs-safe/config`, `@openclaw/fs-safe/store`, `@openclaw/fs-safe/advanced`, and `@openclaw/fs-safe/test-hooks`.
17+
- Corrected path-helper docs for the synchronous `isPathInsideWithRealpath` and `safeRealpathSync` behavior.
18+
- Included the Markdown docs in the npm package so README links resolve after install.
1719

1820
## 0.1.1 - 2026-05-06
1921

‎docs/path.md‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from "@openclaw/fs-safe/path";
1818
```
1919

20-
These helpers are also re-exported from the main entry; the `/path` subpath is for callers that want the smallest possible import.
20+
Only `root()`, `FsSafeError`, and the Python helper config live on the main entry. Path helpers are deliberately a subpath import so the main entry stays small.
2121

2222
## Boundary checks
2323

@@ -34,15 +34,22 @@ isPathInside("/srv/uploads", "/srv/uploads"); // true (root itsel
3434

3535
The check is platform-aware: on Windows, paths are normalized for case and separator before comparison.
3636

37-
### `isPathInsideWithRealpath(rootDir, target)`
37+
### `isPathInsideWithRealpath(rootDir, target, opts?)`
3838

39-
Async. Same as `isPathInside`, but resolves both inputs through `realpath` first. Use this when you want the canonical answer and either input might be a symlink.
39+
Synchronous. Same as `isPathInside`, but resolves both inputs through `realpath` first. Use this when you want the canonical answer and either input might be a symlink.
4040

4141
```ts
42-
await isPathInsideWithRealpath("/srv/uploads", "/srv/symlink-to-elsewhere"); // false
42+
isPathInsideWithRealpath("/srv/uploads", "/srv/symlink-to-elsewhere"); // false
4343
```
4444

45-
Throws on `realpath` failure for either input. Catch with `isNotFoundPathError(err)` if you want missing inputs to be a "no" rather than an exception.
45+
```ts
46+
type Options = {
47+
requireRealpath?: boolean; // default true
48+
cache?: Map<string, string>;
49+
};
50+
```
51+
52+
Does not throw on missing inputs — `realpath` failures are absorbed by the underlying `safeRealpathSync`. By default (`requireRealpath: true`) the function returns `false` when either input cannot be resolved. Pass `{ requireRealpath: false }` to fall back to the lexical answer from `isPathInside` instead.
4653

4754
### `isWithinDir(rootDir, targetPath)`
4855

@@ -60,14 +67,14 @@ const base = resolveSafeBaseDir("/srv/uploads/."); // "/srv/uploads"
6067

6168
### `safeRealpathSync(targetPath, cache?)`
6269

63-
Synchronous `realpath` that returns `null` instead of throwing on missing paths. Pass an optional `Map<string, string>` to cache results across calls within a single operation.
70+
Synchronous `realpath` that returns `null` instead of throwing on any error. Pass an optional `Map<string, string>` to cache results across calls within a single operation.
6471

6572
```ts
6673
const real = safeRealpathSync("/srv/uploads/photo.jpg");
6774
if (real === null) return notFound();
6875
```
6976

70-
Errors other than `ENOENT` propagate normally.
77+
All `realpath` failures collapse to `null` — there is no distinction between `ENOENT`, `EACCES`, and other I/O errors. Use `fs.realpathSync` directly if you need to branch on the error code.
7178

7279
### `safeStatSync(targetPath)`
7380

@@ -133,7 +140,7 @@ try {
133140
if (isNotFoundPathError(err)) return reply(404);
134141
throw err;
135142
}
136-
if (!await isPathInsideWithRealpath("/srv/uploads", canonical)) {
143+
if (!isPathInsideWithRealpath("/srv/uploads", canonical)) {
137144
return reply(403);
138145
}
139146
```

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dist/**/*.js",
1212
"dist/**/*.d.ts",
1313
"dist/**/*.d.ts.map",
14+
"docs/**/*.md",
1415
"README.md",
1516
"CHANGELOG.md",
1617
"SECURITY.md",

0 commit comments

Comments
 (0)