@onabl/js 0.1.2 → 0.1.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.
- package/README.md +56 -19
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,25 +1,62 @@
|
|
|
1
1
|
# `@onabl/js`
|
|
2
2
|
|
|
3
|
-
Framework-agnostic
|
|
4
|
-
|
|
3
|
+
Framework-agnostic JavaScript/TypeScript client for the onabl API. No React,
|
|
4
|
+
no DOM assumptions — install this directly in any JS backend, or use
|
|
5
|
+
`@onabl/react` / `@onabl/next` for framework-specific integration.
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
`docs/SDK-DESIGN.md` for the full intended API surface before adding to this
|
|
8
|
-
package, and `docs/INTEGRATION-LAYER-TODO.md` for current build status.
|
|
7
|
+
## Install
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
```bash
|
|
10
|
+
npm install @onabl/js
|
|
11
|
+
```
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {createOnablClient} from "@onabl/js";
|
|
17
|
+
|
|
18
|
+
const onabl = createOnablClient({
|
|
19
|
+
handle: "acme", // your onabl tenant handle
|
|
20
|
+
secretKey: process.env.ONABL_SECRET_KEY!, // server-side only, never expose to the browser
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const form = await onabl.forms.get();
|
|
24
|
+
|
|
25
|
+
const {quoteId, quoteUrl, token} = await onabl.submissions.create({
|
|
26
|
+
hours: 4,
|
|
27
|
+
serviceType: "design",
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`secretKey` must never reach the browser. If you're building a Next.js app,
|
|
32
|
+
use `@onabl/next` instead, which keeps the secret key server-side for you.
|
|
33
|
+
|
|
34
|
+
## What's included
|
|
35
|
+
|
|
36
|
+
- `createOnablClient()` — the typed API client (forms, submissions, quotes,
|
|
37
|
+
invoices, storage)
|
|
13
38
|
- `OnablError` and its subclasses (`OnablNotFound`, `OnablUnauthorized`,
|
|
14
|
-
`OnablValidation`, `OnablNetwork`)
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
`
|
|
19
|
-
|
|
20
|
-
##
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
39
|
+
`OnablValidation`, `OnablNetwork`) for typed error handling
|
|
40
|
+
- `presentQuote` / `groupLineItems` — helpers for rendering a quote's line
|
|
41
|
+
items and totals
|
|
42
|
+
- Form helpers (`getVisibleSteps`, `getAllFields`, `getInitialAnswers`,
|
|
43
|
+
`validateFields`) for building a custom multi-step quote form UI
|
|
44
|
+
|
|
45
|
+
## Errors
|
|
46
|
+
|
|
47
|
+
All client calls throw a subclass of `OnablError` on failure:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import {OnablNotFound, OnablValidation} from "@onabl/js";
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
await onabl.quotes.get(uuid, {token});
|
|
54
|
+
} catch (err) {
|
|
55
|
+
if (err instanceof OnablNotFound) {
|
|
56
|
+
// handle missing quote
|
|
57
|
+
}
|
|
58
|
+
if (err instanceof OnablValidation) {
|
|
59
|
+
// err.fieldErrors has per-field details
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onabl/js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Framework-agnostic onabl SDK core — typed API client, error classes, condition evaluator, form state machine, and quote presentation. No React, no DOM assumptions. See docs/SDK-DESIGN.md.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"vitest": "^1.6.0",
|
|
31
31
|
"typescript": "^5.4.0",
|
|
32
32
|
"@onabl/engine": "0.0.1",
|
|
33
|
-
"@onabl/
|
|
34
|
-
"@onabl/
|
|
33
|
+
"@onabl/eslint-config": "0.0.1",
|
|
34
|
+
"@onabl/typescript-config": "0.0.1"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@onabl/contracts": "0.1.
|
|
38
|
-
"@onabl/types": "0.1.
|
|
37
|
+
"@onabl/contracts": "0.1.2",
|
|
38
|
+
"@onabl/types": "0.1.1"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsup",
|