@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.
Files changed (2) hide show
  1. package/README.md +61 -16
  2. 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. Owns the secret-key-holding server
4
- layer so an integrator's client components never see it see
5
- `docs/SDK-DESIGN.md` §1 for the two-file, eleven-line target this package
6
- exists to make possible.
7
-
8
- **Status:** skeleton only (Phase 14 §14.5.4, not started — `@onabl/react`
9
- has to land first).
10
-
11
- ## What belongs here
12
-
13
- - `createOnablClient(config)` — re-exported from `@onabl/react`/`@onabl/js`
14
- with Next-aware cookie handling
15
- - `onabl.routes()` the `{GET, POST, PATCH}` route-handler factory, mounted
16
- at `app/api/onabl/[...onabl]/route.ts` in a consumer's app
17
- - The RSC-safe boundary that makes it structurally impossible to pass server
18
- config (the secret key) into a client component
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.2",
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/typescript-config": "0.0.1",
35
- "@onabl/eslint-config": "0.0.1"
34
+ "@onabl/eslint-config": "0.0.1",
35
+ "@onabl/typescript-config": "0.0.1"
36
36
  },
37
37
  "dependencies": {
38
- "@onabl/react": "0.1.2",
39
- "@onabl/js": "0.1.2"
38
+ "@onabl/js": "0.1.4",
39
+ "@onabl/react": "0.1.4"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "next": "^16",