@zilfu/sdk 0.0.1 → 0.1.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/LICENSE +21 -0
- package/README.md +116 -20
- package/dist/index.cjs +733 -661
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +521 -382
- package/dist/index.d.ts +521 -382
- package/dist/index.js +733 -623
- package/dist/index.js.map +1 -1
- package/package.json +15 -18
- package/openapi.json +0 -3541
- package/src/client.ts +0 -38
- package/src/generated/client/client.gen.ts +0 -268
- package/src/generated/client/index.ts +0 -25
- package/src/generated/client/types.gen.ts +0 -268
- package/src/generated/client/utils.gen.ts +0 -331
- package/src/generated/client.gen.ts +0 -18
- package/src/generated/core/auth.gen.ts +0 -42
- package/src/generated/core/bodySerializer.gen.ts +0 -92
- package/src/generated/core/params.gen.ts +0 -153
- package/src/generated/core/pathSerializer.gen.ts +0 -181
- package/src/generated/core/serverSentEvents.gen.ts +0 -264
- package/src/generated/core/types.gen.ts +0 -118
- package/src/generated/core/utils.gen.ts +0 -143
- package/src/generated/index.ts +0 -4
- package/src/generated/sdk.gen.ts +0 -695
- package/src/generated/types.gen.ts +0 -2564
- package/src/index.ts +0 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zilfu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,47 +1,143 @@
|
|
|
1
1
|
# @zilfu/sdk
|
|
2
2
|
|
|
3
|
-
Official TypeScript SDK for the [Zilfu](https://zilfu.
|
|
3
|
+
Official TypeScript SDK for the [Zilfu](https://zilfu.app) API.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
|
-
```
|
|
7
|
+
```sh
|
|
8
8
|
pnpm add @zilfu/sdk
|
|
9
9
|
# or
|
|
10
10
|
npm install @zilfu/sdk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Requires Node 18.17+ (or any runtime with global `fetch`).
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
## Quickstart
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import { createZilfuClient
|
|
18
|
+
import { createZilfuClient } from "@zilfu/sdk";
|
|
19
19
|
|
|
20
|
-
createZilfuClient({
|
|
21
|
-
baseUrl:
|
|
20
|
+
const api = createZilfuClient({
|
|
21
|
+
baseUrl: "https://zilfu.app/api",
|
|
22
22
|
token: process.env.ZILFU_TOKEN!,
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
const
|
|
26
|
-
if (error) throw error;
|
|
27
|
-
console.log(data);
|
|
25
|
+
const spaces = await api.spaces.list();
|
|
28
26
|
```
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
## Auth
|
|
29
|
+
|
|
30
|
+
Mint a personal-access token at **Settings → API tokens** (or via `POST /api/api-tokens`). Pass it as a string or as a function for refresh logic:
|
|
31
31
|
|
|
32
32
|
```ts
|
|
33
|
-
createZilfuClient({
|
|
34
|
-
|
|
33
|
+
const api = createZilfuClient({
|
|
34
|
+
token: async () => await getTokenFromVault(),
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The `Authorization: Bearer <token>` header is added automatically to every request.
|
|
39
|
+
|
|
40
|
+
## Examples
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
// List posts in a space
|
|
44
|
+
await api.posts.list({ path: { space: 1 } });
|
|
45
|
+
|
|
46
|
+
// Create a multi-account post (a "cluster")
|
|
47
|
+
await api.posts.create({
|
|
48
|
+
path: { space: 1 },
|
|
49
|
+
body: {
|
|
50
|
+
space_id: 1,
|
|
51
|
+
items: [{ account_id: 1, social: "threads", main: { content: "Hello" } }],
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Update an entire cluster
|
|
56
|
+
await api.clusters.update({
|
|
57
|
+
path: { space: 1, cluster_id: "abc-123" },
|
|
58
|
+
body: { /* same shape as create */ },
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Reorder a bio link block
|
|
62
|
+
await api.bio.blocks.reorder({
|
|
63
|
+
path: { space: 1, block: 7 },
|
|
64
|
+
body: { sort_order: 2 },
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Upload media (FormData)
|
|
68
|
+
const fd = new FormData();
|
|
69
|
+
fd.append("file", file);
|
|
70
|
+
await api.media.create({ body: fd });
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Errors
|
|
74
|
+
|
|
75
|
+
Non-2xx responses throw a typed `ZilfuApiError`:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { ZilfuApiError } from "@zilfu/sdk";
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
await api.posts.create({ /* ... */ });
|
|
82
|
+
} catch (e) {
|
|
83
|
+
if (e instanceof ZilfuApiError) {
|
|
84
|
+
console.error(e.status, e.errors); // Laravel validation: { field: ["msg"] }
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Types
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import type {
|
|
93
|
+
PostResource,
|
|
94
|
+
SpaceResource,
|
|
95
|
+
AccountResource,
|
|
96
|
+
WebhookResource,
|
|
97
|
+
} from "@zilfu/sdk";
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
All request/response shapes are exported as named types.
|
|
101
|
+
|
|
102
|
+
## Custom fetch
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { fetch as undiciFetch } from "undici";
|
|
106
|
+
|
|
107
|
+
const api = createZilfuClient({
|
|
35
108
|
token,
|
|
36
|
-
fetch:
|
|
109
|
+
fetch: undiciFetch,
|
|
37
110
|
});
|
|
38
111
|
```
|
|
39
112
|
|
|
40
|
-
##
|
|
113
|
+
## Regenerating from the API spec
|
|
114
|
+
|
|
115
|
+
The package is generated from the live OpenAPI spec at `https://zilfu.app/docs/api.json` (Scramble).
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
pnpm sync:spec # fetches openapi.json
|
|
119
|
+
pnpm generate # regenerates src/generated
|
|
120
|
+
pnpm typecheck # verifies the smoke file still compiles
|
|
121
|
+
pnpm build
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Override the spec source for staging or local Herd:
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
SCRAMBLE_SPEC_URL=http://zilfu.test/docs/api.json pnpm sync:spec
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The generated `src/generated/` directory is committed; PRs that bump the spec show a reviewable diff of API surface changes.
|
|
131
|
+
|
|
132
|
+
A daily GitHub Actions cron (`.github/workflows/sync-spec.yml`) does this automatically and opens a PR if anything changed — review and merge, then cut a release with:
|
|
41
133
|
|
|
42
|
-
```
|
|
43
|
-
pnpm
|
|
44
|
-
|
|
45
|
-
pnpm build # bundle dist/
|
|
46
|
-
pnpm typecheck
|
|
134
|
+
```sh
|
|
135
|
+
pnpm version <patch|minor|major>
|
|
136
|
+
git push --follow-tags
|
|
47
137
|
```
|
|
138
|
+
|
|
139
|
+
The release workflow (`.github/workflows/release.yml`) publishes to npm with provenance and creates a GitHub release on every `v*` tag.
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
MIT
|