@lazrus/nukle 0.2.0 → 0.2.1
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 +81 -9
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,21 +1,93 @@
|
|
|
1
1
|
# @lazrus/nukle
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The official TypeScript client for Nukle. Read website content, access media
|
|
4
|
+
metadata, manage input-form schemas from your server, and accept browser-safe
|
|
5
|
+
form submissions.
|
|
6
|
+
|
|
7
|
+
[Documentation](https://docs.nukle.in) · [API reference](https://docs.nukle.in)
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @lazrus/nukle
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
pnpm add @lazrus/nukle
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
Create a website-scoped API key in Nukle Studio, then use it only on your
|
|
22
|
+
server. Never expose a `nukle_live_...` key in browser code.
|
|
4
23
|
|
|
5
24
|
```ts
|
|
6
25
|
import { createNukleClient } from "@lazrus/nukle";
|
|
7
26
|
|
|
8
|
-
// Server-only: keep the website API key out of browser code.
|
|
9
27
|
const nukle = createNukleClient({ apiKey: process.env.NUKLE_API_KEY! });
|
|
10
|
-
|
|
28
|
+
|
|
29
|
+
const hero = await nukle.getSingleton<{ title: string; subtitle: string }>(
|
|
30
|
+
"hero",
|
|
31
|
+
);
|
|
32
|
+
const cards = await nukle.getRepeatable<{ title: string }>("cards");
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The client uses `https://api.nukle.in` by default. For local development,
|
|
36
|
+
provide your Core origin without `/v1`:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
const nukle = createNukleClient({
|
|
40
|
+
apiKey: process.env.NUKLE_API_KEY!,
|
|
41
|
+
baseUrl: "http://localhost:3001",
|
|
42
|
+
});
|
|
11
43
|
```
|
|
12
44
|
|
|
13
|
-
|
|
45
|
+
## What you can do
|
|
14
46
|
|
|
15
|
-
|
|
47
|
+
- Read all modules, a single module, singleton content, or repeatable content.
|
|
48
|
+
- List media, retrieve media metadata, and download authenticated media bytes.
|
|
49
|
+
- Create, inspect, activate, deactivate, and rotate public credentials for
|
|
50
|
+
input forms from server-only code.
|
|
51
|
+
- Submit a public form from a browser using its restricted `nukle_form_...`
|
|
52
|
+
credential.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { createNukleFormClient } from "@lazrus/nukle";
|
|
56
|
+
|
|
57
|
+
const contact = createNukleFormClient({
|
|
58
|
+
formKey: "nukle_form_REPLACE_ME",
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
await contact.submit({
|
|
62
|
+
email: "reader@example.com",
|
|
63
|
+
message: "Hello from our website",
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The form credential is safe for browser code. It cannot access website
|
|
68
|
+
content, media, or form-management operations. Configure the form's allowed
|
|
69
|
+
origins in Nukle before accepting browser submissions.
|
|
70
|
+
|
|
71
|
+
## Errors
|
|
72
|
+
|
|
73
|
+
API failures are thrown as `NukleApiError`, with an HTTP `status`, stable
|
|
74
|
+
`code`, and optional `details` field.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { NukleApiError } from "@lazrus/nukle";
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
await nukle.getModule("hero");
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (error instanceof NukleApiError) {
|
|
83
|
+
console.error(error.status, error.code, error.message);
|
|
84
|
+
} else {
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
16
89
|
|
|
17
|
-
|
|
18
|
-
- [Development, testing, and npm publishing](../../docs/sdk/development-and-publishing.md)
|
|
19
|
-
- [Runnable examples](../../docs/sdk/examples/README.md)
|
|
90
|
+
## Documentation
|
|
20
91
|
|
|
21
|
-
|
|
92
|
+
Visit [docs.nukle.in](https://docs.nukle.in) for the complete API reference,
|
|
93
|
+
form-management guide, local-development setup, and runnable examples.
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lazrus/nukle",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Typed client for Nukle public website delivery APIs.",
|
|
5
|
+
"homepage": "https://docs.nukle.in",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"types": "./dist/index.d.ts",
|
|
7
8
|
"main": "./dist/index.js",
|
|
@@ -20,8 +21,8 @@
|
|
|
20
21
|
"eslint": "^9",
|
|
21
22
|
"tsx": "^4.23.15",
|
|
22
23
|
"typescript": "5.9.2",
|
|
23
|
-
"@repo/
|
|
24
|
-
"@repo/
|
|
24
|
+
"@repo/eslint-config": "0.0.0",
|
|
25
|
+
"@repo/typescript-config": "0.0.0"
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
28
|
"build": "tsc",
|