@onabl/next 0.1.2 → 0.1.4
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 +61 -16
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,18 +1,63 @@
|
|
|
1
1
|
# `@onabl/next`
|
|
2
2
|
|
|
3
|
-
Next.js integration for the onabl SDK.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
Next.js integration for the onabl SDK. Provides the server-side route
|
|
4
|
+
handlers and helpers that keep your onabl secret key out of the browser, so
|
|
5
|
+
`@onabl/react`'s hooks have a same-origin proxy to call.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @onabl/next @onabl/react
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Mount the route handlers at a catch-all API route:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// app/api/onabl/[...onabl]/route.ts
|
|
19
|
+
import {createOnablRouteHandlers} from "@onabl/next";
|
|
20
|
+
|
|
21
|
+
export const {GET, POST, PATCH} = createOnablRouteHandlers({
|
|
22
|
+
handle: "acme",
|
|
23
|
+
secretKey: process.env.ONABL_SECRET_KEY!,
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then use `@onabl/react`'s hooks anywhere in your app — `OnablProvider`
|
|
28
|
+
defaults to this route already:
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import {OnablProvider} from "@onabl/react";
|
|
32
|
+
|
|
33
|
+
export default function RootLayout({children}: {children: React.ReactNode}) {
|
|
34
|
+
return <OnablProvider>{children}</OnablProvider>;
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For a Server Component quote or invoice page (e.g. an emailed link opened
|
|
39
|
+
with `?token=`), use `createOnablServerClient` to fetch data directly, and
|
|
40
|
+
`setAccessCookieOn` to persist the token so subsequent client-side actions
|
|
41
|
+
(accept/decline, POP upload) are authenticated:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import {createOnablServerClient, setAccessCookieOn} from "@onabl/next";
|
|
45
|
+
|
|
46
|
+
const onabl = createOnablServerClient({
|
|
47
|
+
handle: "acme",
|
|
48
|
+
secretKey: process.env.ONABL_SECRET_KEY!,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const quote = await onabl.quotes.get(uuid, {token});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## What's included
|
|
55
|
+
|
|
56
|
+
- `createOnablRouteHandlers(config)` — the `{GET, POST, PATCH}` route
|
|
57
|
+
handler factory for your proxy route
|
|
58
|
+
- `createOnablServerClient(config)` — a server-side client for Server
|
|
59
|
+
Components/Server Actions
|
|
60
|
+
- `setAccessCookieOn(res, uuid, token)` — persists a customer access token
|
|
61
|
+
as an httpOnly cookie
|
|
62
|
+
- `accessCookieName`, `ACCESS_COOKIE_MAX_AGE_SECONDS` — cookie naming/expiry
|
|
63
|
+
constants, if you need to read the cookie yourself (e.g. in middleware)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onabl/next",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Next.js integration for the onabl SDK — server-action-free route-handler factory, cookie-aware client, RSC-safe boundary. See docs/SDK-DESIGN.md.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"tsup": "^8.0.0",
|
|
32
32
|
"vitest": "^1.6.0",
|
|
33
33
|
"typescript": "^5.4.0",
|
|
34
|
-
"@onabl/
|
|
35
|
-
"@onabl/
|
|
34
|
+
"@onabl/eslint-config": "0.0.1",
|
|
35
|
+
"@onabl/typescript-config": "0.0.1"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@onabl/
|
|
39
|
-
"@onabl/
|
|
38
|
+
"@onabl/js": "0.1.4",
|
|
39
|
+
"@onabl/react": "0.1.4"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"next": "^16",
|