@airdraft/client 0.1.4 → 0.1.5
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/CHANGELOG.md +17 -0
- package/README.md +74 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.1.5](https://github.com/aevrHQ/airdraft/compare/client@v0.1.3...client@v0.1.5) (2026-05-23)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add `story` field type with schema definition and UI support; include media file for demo ([f5d3f88](https://github.com/aevrHQ/airdraft/commit/f5d3f884afda98e613c50ce1a0ebb3c591a84511))
|
|
11
|
+
* enhance media field handling in renderTypes function to include metadata support ([b80245c](https://github.com/aevrHQ/airdraft/commit/b80245caf91e2a436172e875fff89c83a56b5ff3))
|
|
12
|
+
* enhance MIME type handling in FilesSdkMediaAdapter and withMedia plugin ([186d33f](https://github.com/aevrHQ/airdraft/commit/186d33f33d31431c579a821eaa1a7a5ea13be4e7))
|
|
13
|
+
* implement `blocks` field type with schema definition, validation, and UI support ([a3d57d1](https://github.com/aevrHQ/airdraft/commit/a3d57d11d82f38871fe044641bbb5a98cda3cb75))
|
|
14
|
+
* **react-content:** add support for media lists and urls ([2cb0891](https://github.com/aevrHQ/airdraft/commit/2cb089102b0530217f305c782435138592f7754d))
|
|
15
|
+
* **types:** add asCollectionConfig function for casting schema objects ([f5bcaaf](https://github.com/aevrHQ/airdraft/commit/f5bcaafa42fb43d749c89dfe7e7b075adcd18474))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Code Refactoring
|
|
19
|
+
|
|
20
|
+
* code structure for improved readability and maintainability ([410de76](https://github.com/aevrHQ/airdraft/commit/410de761725340ea8edbb50b7de122797b58d942))
|
|
21
|
+
|
|
5
22
|
### [0.1.3](https://github.com/aevrHQ/airdraft/compare/client@v0.1.2...client@v0.1.3) (2026-05-23)
|
|
6
23
|
|
|
7
24
|
|
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# @airdraft/client
|
|
2
|
+
|
|
3
|
+
Typed HTTP client for the Airdraft CMS API. Use this in custom front-ends, scripts, or any environment that communicates with an Airdraft server over HTTP.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @airdraft/client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { AirdraftClient } from '@airdraft/client'
|
|
15
|
+
|
|
16
|
+
const client = new AirdraftClient({
|
|
17
|
+
baseUrl: 'https://your-site.com/api/cms',
|
|
18
|
+
apiKey: process.env.AIRDRAFT_API_KEY,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
// List entries
|
|
22
|
+
const { data } = await client.entries.list('posts')
|
|
23
|
+
|
|
24
|
+
// Get single entry
|
|
25
|
+
const entry = await client.entries.get('posts', 'hello-world')
|
|
26
|
+
|
|
27
|
+
// Create entry
|
|
28
|
+
await client.entries.create('posts', { title: 'Hello', published: false })
|
|
29
|
+
|
|
30
|
+
// Update entry (optimistic lock via SHA)
|
|
31
|
+
await client.entries.update('posts', 'hello-world', { title: 'Updated' }, entry.meta.sha)
|
|
32
|
+
|
|
33
|
+
// Delete entry
|
|
34
|
+
await client.entries.delete('posts', 'hello-world', entry.meta.sha)
|
|
35
|
+
|
|
36
|
+
// Media
|
|
37
|
+
const items = await client.media.list()
|
|
38
|
+
const uploaded = await client.media.upload(file)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
### `new AirdraftClient(options)`
|
|
44
|
+
|
|
45
|
+
| Option | Type | Description |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| `baseUrl` | `string` | Base URL of the CMS API (no trailing slash). |
|
|
48
|
+
| `apiKey` | `string` | API key sent as `Authorization: Bearer <key>`. |
|
|
49
|
+
| `getToken` | `() => string \| null` | Alternative to `apiKey` — dynamic token provider (e.g. from localStorage). |
|
|
50
|
+
|
|
51
|
+
### `AirdraftClientError`
|
|
52
|
+
|
|
53
|
+
All non-2xx responses throw an `AirdraftClientError`:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { AirdraftClientError } from '@airdraft/client'
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
await client.entries.update(...)
|
|
60
|
+
} catch (err) {
|
|
61
|
+
if (err instanceof AirdraftClientError) {
|
|
62
|
+
console.log(err.code) // e.g. 'VALIDATION_ERROR'
|
|
63
|
+
console.log(err.statusCode) // e.g. 422
|
|
64
|
+
console.log(err.message) // human-readable message
|
|
65
|
+
console.log(err.details) // Array<{ field, message }> for validation errors
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`details` is populated for `VALIDATION_ERROR` responses and contains per-field failure information.
|
|
71
|
+
|
|
72
|
+
## Changelog
|
|
73
|
+
|
|
74
|
+
See [CHANGELOG.md](./CHANGELOG.md).
|