@rootsmithio/client 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +57 -2
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15344 -0
- package/dist/page.d.ts +14 -0
- package/dist/page.d.ts.map +1 -0
- package/dist/url.d.ts +3 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +31 -0
- package/package.json +51 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sidewave Digital Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
#
|
|
1
|
+
# RootSmith client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Read and render published RootSmith pages in any JavaScript framework, and
|
|
4
|
+
answer the signed refresh that RootSmith sends when you publish. It uses only
|
|
5
|
+
the standard `fetch`, `Request`, and `Response` objects. For Next.js, use
|
|
6
|
+
[`@rootsmithio/next`](../next), which wraps this package with the Next.js
|
|
7
|
+
cache, redirects, and metadata.
|
|
8
|
+
|
|
9
|
+
The package is built in this workspace. It has not been released to npm.
|
|
10
|
+
|
|
11
|
+
## Read pages
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createRootSmith } from "@rootsmithio/client"
|
|
15
|
+
|
|
16
|
+
export const rootSmith = createRootSmith({
|
|
17
|
+
apiUrl: process.env.ROOTSMITH_API_URL!,
|
|
18
|
+
siteId: process.env.ROOTSMITH_SITE_ID!,
|
|
19
|
+
})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
- `getPage(path)` returns the published page, `null` for a missing page or
|
|
23
|
+
an unsupported path, or `{ redirect }` when the page was merged into
|
|
24
|
+
another page. Send a 308 redirect for that case.
|
|
25
|
+
- `listPages(page)` returns up to 25 pages, sorted by path. `listAllPages()`
|
|
26
|
+
returns every published page.
|
|
27
|
+
- `init` adds request options, such as a framework cache setting, to each
|
|
28
|
+
read. Reads never follow redirects and time out after 10 seconds.
|
|
29
|
+
|
|
30
|
+
## Render a page
|
|
31
|
+
|
|
32
|
+
`renderHtml(page, { imageOrigins })` returns the page body as HTML inside a
|
|
33
|
+
`div` with the `rootsmith-markdown` class and the content/version attributes
|
|
34
|
+
used for live confirmation. It supports GitHub Flavored Markdown. Raw HTML is
|
|
35
|
+
removed, unsafe URL schemes are dropped, relative links resolve against the
|
|
36
|
+
page URL, and images load only from the page's origin or the listed origins.
|
|
37
|
+
|
|
38
|
+
## Refresh
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { createRootSmithHandler } from "@rootsmithio/client"
|
|
42
|
+
|
|
43
|
+
const handler = createRootSmithHandler({
|
|
44
|
+
refresh: (path) => cache.delete(path),
|
|
45
|
+
})
|
|
46
|
+
export const POST = ({ request }: { request: Request }) => handler(request)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The handler reads `ROOTSMITH_SITE_ID` and `ROOTSMITH_CONNECTION_SECRET` from
|
|
50
|
+
`process.env` when a request arrives, or uses `siteId` and `secret`. It
|
|
51
|
+
answers 503 until both are set. It checks the site, the timestamp, and the
|
|
52
|
+
HMAC signature, calls `refresh` for a refresh request, and signs its
|
|
53
|
+
response. `refresh` must finish before the handler returns.
|
|
54
|
+
|
|
55
|
+
## Verification
|
|
56
|
+
|
|
57
|
+
`pnpm --filter @rootsmithio/client test` checks rendering, sanitizing,
|
|
58
|
+
redirects, request options, and signed refresh requests.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PublishedPage } from "./page.js";
|
|
2
|
+
export type { PublishedPage } from "./page.js";
|
|
3
|
+
export { originOf, safeContentUrl } from "./url.js";
|
|
4
|
+
export declare function createRootSmith({ apiUrl, siteId, fetcher, init, }: {
|
|
5
|
+
apiUrl: string;
|
|
6
|
+
siteId: string;
|
|
7
|
+
fetcher?: typeof fetch;
|
|
8
|
+
init?: () => RequestInit;
|
|
9
|
+
}): {
|
|
10
|
+
listPages: (page?: number) => Promise<PublishedPage[]>;
|
|
11
|
+
listAllPages(): Promise<PublishedPage[]>;
|
|
12
|
+
getPage(path: string): Promise<PublishedPage | {
|
|
13
|
+
redirect: string;
|
|
14
|
+
} | null>;
|
|
15
|
+
};
|
|
16
|
+
export declare function createRootSmithHandler({ siteId: configuredSiteId, secret: configuredSecret, refresh, }?: {
|
|
17
|
+
siteId?: string;
|
|
18
|
+
secret?: string;
|
|
19
|
+
refresh?: (path: string) => void | Promise<void>;
|
|
20
|
+
}): (request: Request) => Promise<Response>;
|
|
21
|
+
export declare function renderHtml(page: Pick<PublishedPage, "id" | "revision" | "markdown" | "url">, { imageOrigins }?: {
|
|
22
|
+
imageOrigins?: string[];
|
|
23
|
+
}): string;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAG9C,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAEnD,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,MAAM,EACN,OAAe,EACf,IAAI,GACL,EAAE;IACD,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,OAAO,KAAK,CAAA;IACtB,IAAI,CAAC,EAAE,MAAM,WAAW,CAAA;CACzB;kCAOqC,OAAO,CAAC,aAAa,EAAE,CAAC;oBAQpC,OAAO,CAAC,aAAa,EAAE,CAAC;kBAStC,MAAM,GACX,OAAO,CAAC,aAAa,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;EAa1D;AAED,wBAAgB,sBAAsB,CAAC,EACrC,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,gBAAgB,EACxB,OAAkB,GACnB,GAAE;IACD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5C,IACuB,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CAoDhE;AAuBD,wBAAgB,UAAU,CACxB,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,UAAU,GAAG,UAAU,GAAG,KAAK,CAAC,EACjE,EAAE,YAAiB,EAAE,GAAE;IAAE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,UAgBxD"}
|