@zilfu/sdk 0.1.0 → 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 +113 -21
- package/dist/index.cjs +83 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -35
- package/dist/index.d.ts +60 -35
- package/dist/index.js +83 -20
- package/dist/index.js.map +1 -1
- package/package.json +15 -17
- package/openapi.json +0 -3541
- package/src/client.ts +0 -41
- package/src/generated/client/client.gen.ts +0 -280
- package/src/generated/client/index.ts +0 -25
- package/src/generated/client/types.gen.ts +0 -217
- package/src/generated/client/utils.gen.ts +0 -318
- package/src/generated/client.gen.ts +0 -16
- package/src/generated/core/auth.gen.ts +0 -41
- package/src/generated/core/bodySerializer.gen.ts +0 -82
- package/src/generated/core/params.gen.ts +0 -169
- package/src/generated/core/pathSerializer.gen.ts +0 -171
- package/src/generated/core/queryKeySerializer.gen.ts +0 -117
- package/src/generated/core/serverSentEvents.gen.ts +0 -242
- package/src/generated/core/types.gen.ts +0 -104
- package/src/generated/core/utils.gen.ts +0 -140
- package/src/generated/index.ts +0 -4
- package/src/generated/sdk.gen.ts +0 -658
- package/src/generated/types.gen.ts +0 -2564
- package/src/index.ts +0 -22
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,51 +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 } from
|
|
18
|
+
import { createZilfuClient } from "@zilfu/sdk";
|
|
19
19
|
|
|
20
20
|
const api = createZilfuClient({
|
|
21
|
-
baseUrl:
|
|
21
|
+
baseUrl: "https://zilfu.app/api",
|
|
22
22
|
token: process.env.ZILFU_TOKEN!,
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const spaces = await api.spaces.list();
|
|
26
|
+
```
|
|
27
|
+
|
|
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
|
+
|
|
32
|
+
```ts
|
|
33
|
+
const api = createZilfuClient({
|
|
34
|
+
token: async () => await getTokenFromVault(),
|
|
29
35
|
});
|
|
30
36
|
```
|
|
31
37
|
|
|
32
|
-
|
|
38
|
+
The `Authorization: Bearer <token>` header is added automatically to every request.
|
|
33
39
|
|
|
34
|
-
|
|
40
|
+
## Examples
|
|
35
41
|
|
|
36
42
|
```ts
|
|
37
|
-
|
|
38
|
-
|
|
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({
|
|
39
108
|
token,
|
|
40
|
-
fetch:
|
|
109
|
+
fetch: undiciFetch,
|
|
41
110
|
});
|
|
42
111
|
```
|
|
43
112
|
|
|
44
|
-
##
|
|
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:
|
|
45
133
|
|
|
46
|
-
```
|
|
47
|
-
pnpm
|
|
48
|
-
|
|
49
|
-
pnpm build # bundle dist/
|
|
50
|
-
pnpm typecheck
|
|
134
|
+
```sh
|
|
135
|
+
pnpm version <patch|minor|major>
|
|
136
|
+
git push --follow-tags
|
|
51
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
|
package/dist/index.cjs
CHANGED
|
@@ -823,7 +823,7 @@ var HeyApiRegistry = class {
|
|
|
823
823
|
get(key) {
|
|
824
824
|
const instance = this.instances.get(key ?? this.defaultKey);
|
|
825
825
|
if (!instance) {
|
|
826
|
-
throw new Error(`No SDK client found. Create one with "new
|
|
826
|
+
throw new Error(`No SDK client found. Create one with "new ZilfuApi()" to fix this error.`);
|
|
827
827
|
}
|
|
828
828
|
return instance;
|
|
829
829
|
}
|
|
@@ -893,7 +893,7 @@ var Accounts = class extends HeyApiClient {
|
|
|
893
893
|
});
|
|
894
894
|
}
|
|
895
895
|
};
|
|
896
|
-
var
|
|
896
|
+
var ApiTokens = class extends HeyApiClient {
|
|
897
897
|
/**
|
|
898
898
|
* Create an API token
|
|
899
899
|
*
|
|
@@ -923,7 +923,7 @@ var Tokens = class extends HeyApiClient {
|
|
|
923
923
|
});
|
|
924
924
|
}
|
|
925
925
|
};
|
|
926
|
-
var
|
|
926
|
+
var Blocks = class extends HeyApiClient {
|
|
927
927
|
list(options) {
|
|
928
928
|
return (options.client ?? this.client).get({
|
|
929
929
|
security: [{ scheme: "bearer", type: "http" }],
|
|
@@ -1014,6 +1014,19 @@ var Bio = class extends HeyApiClient {
|
|
|
1014
1014
|
}
|
|
1015
1015
|
});
|
|
1016
1016
|
}
|
|
1017
|
+
_blocks;
|
|
1018
|
+
get blocks() {
|
|
1019
|
+
return this._blocks ??= new Blocks({ client: this.client });
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
var Health = class extends HeyApiClient {
|
|
1023
|
+
check(options) {
|
|
1024
|
+
return (options?.client ?? this.client).get({
|
|
1025
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1026
|
+
url: "/health",
|
|
1027
|
+
...options
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1017
1030
|
};
|
|
1018
1031
|
var Media = class extends HeyApiClient {
|
|
1019
1032
|
/**
|
|
@@ -1332,28 +1345,28 @@ var Webhooks = class extends HeyApiClient {
|
|
|
1332
1345
|
});
|
|
1333
1346
|
}
|
|
1334
1347
|
};
|
|
1335
|
-
var
|
|
1348
|
+
var ZilfuApi = class _ZilfuApi extends HeyApiClient {
|
|
1336
1349
|
static __registry = new HeyApiRegistry();
|
|
1337
1350
|
constructor(args) {
|
|
1338
1351
|
super(args);
|
|
1339
|
-
|
|
1352
|
+
_ZilfuApi.__registry.set(this, args?.key);
|
|
1340
1353
|
}
|
|
1341
1354
|
_accounts;
|
|
1342
1355
|
get accounts() {
|
|
1343
1356
|
return this._accounts ??= new Accounts({ client: this.client });
|
|
1344
1357
|
}
|
|
1345
|
-
|
|
1346
|
-
get
|
|
1347
|
-
return this.
|
|
1348
|
-
}
|
|
1349
|
-
_bioBlocks;
|
|
1350
|
-
get bioBlocks() {
|
|
1351
|
-
return this._bioBlocks ??= new BioBlocks({ client: this.client });
|
|
1358
|
+
_apiTokens;
|
|
1359
|
+
get apiTokens() {
|
|
1360
|
+
return this._apiTokens ??= new ApiTokens({ client: this.client });
|
|
1352
1361
|
}
|
|
1353
1362
|
_bio;
|
|
1354
1363
|
get bio() {
|
|
1355
1364
|
return this._bio ??= new Bio({ client: this.client });
|
|
1356
1365
|
}
|
|
1366
|
+
_health;
|
|
1367
|
+
get health() {
|
|
1368
|
+
return this._health ??= new Health({ client: this.client });
|
|
1369
|
+
}
|
|
1357
1370
|
_media;
|
|
1358
1371
|
get media() {
|
|
1359
1372
|
return this._media ??= new Media({ client: this.client });
|
|
@@ -1388,31 +1401,68 @@ var ZilfuClient = class _ZilfuClient extends HeyApiClient {
|
|
|
1388
1401
|
}
|
|
1389
1402
|
};
|
|
1390
1403
|
|
|
1404
|
+
// src/errors.ts
|
|
1405
|
+
var ZilfuApiError = class extends Error {
|
|
1406
|
+
status;
|
|
1407
|
+
statusText;
|
|
1408
|
+
url;
|
|
1409
|
+
body;
|
|
1410
|
+
errors;
|
|
1411
|
+
constructor(init) {
|
|
1412
|
+
const message = extractMessage(init);
|
|
1413
|
+
super(message);
|
|
1414
|
+
this.name = "ZilfuApiError";
|
|
1415
|
+
this.status = init.status;
|
|
1416
|
+
this.statusText = init.statusText;
|
|
1417
|
+
this.url = init.url;
|
|
1418
|
+
this.body = init.body;
|
|
1419
|
+
this.errors = extractValidationErrors(init.body);
|
|
1420
|
+
}
|
|
1421
|
+
};
|
|
1422
|
+
function extractMessage(init) {
|
|
1423
|
+
const body = init.body;
|
|
1424
|
+
if (body && typeof body === "object" && "message" in body) {
|
|
1425
|
+
const m = body.message;
|
|
1426
|
+
if (typeof m === "string" && m.length > 0) {
|
|
1427
|
+
return m;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
return `Zilfu API ${init.status}${init.statusText ? ` ${init.statusText}` : ""}`;
|
|
1431
|
+
}
|
|
1432
|
+
function extractValidationErrors(body) {
|
|
1433
|
+
if (!body || typeof body !== "object" || !("errors" in body)) {
|
|
1434
|
+
return void 0;
|
|
1435
|
+
}
|
|
1436
|
+
const errors = body.errors;
|
|
1437
|
+
if (!errors || typeof errors !== "object") {
|
|
1438
|
+
return void 0;
|
|
1439
|
+
}
|
|
1440
|
+
return errors;
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1391
1443
|
// src/client.ts
|
|
1392
|
-
function createZilfuClient(
|
|
1393
|
-
const
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1444
|
+
function createZilfuClient(opts) {
|
|
1445
|
+
const client2 = createClient(
|
|
1446
|
+
createConfig({
|
|
1447
|
+
baseUrl: opts.baseUrl ?? "https://zilfu.app/api",
|
|
1448
|
+
fetch: opts.fetch,
|
|
1449
|
+
headers: { accept: "application/json", ...opts.headers },
|
|
1450
|
+
auth: opts.token,
|
|
1451
|
+
throwOnError: true
|
|
1452
|
+
})
|
|
1453
|
+
);
|
|
1454
|
+
client2.interceptors.error.use((error, response) => {
|
|
1455
|
+
return new ZilfuApiError({
|
|
1456
|
+
status: response?.status ?? 0,
|
|
1457
|
+
statusText: response?.statusText,
|
|
1458
|
+
url: response?.url,
|
|
1459
|
+
body: error
|
|
1460
|
+
});
|
|
1398
1461
|
});
|
|
1399
|
-
return new
|
|
1462
|
+
return new ZilfuApi({ client: client2 });
|
|
1400
1463
|
}
|
|
1401
1464
|
|
|
1402
|
-
exports.
|
|
1403
|
-
exports.Bio = Bio;
|
|
1404
|
-
exports.BioBlocks = BioBlocks;
|
|
1405
|
-
exports.Clusters = Clusters;
|
|
1406
|
-
exports.Media = Media;
|
|
1407
|
-
exports.Posts = Posts;
|
|
1408
|
-
exports.Queue = Queue;
|
|
1409
|
-
exports.Slots = Slots;
|
|
1410
|
-
exports.Spaces = Spaces;
|
|
1411
|
-
exports.Subscription = Subscription;
|
|
1412
|
-
exports.Tokens = Tokens;
|
|
1413
|
-
exports.Webhooks = Webhooks;
|
|
1414
|
-
exports.ZilfuClient = ZilfuClient;
|
|
1415
|
-
exports.client = client;
|
|
1465
|
+
exports.ZilfuApiError = ZilfuApiError;
|
|
1416
1466
|
exports.createZilfuClient = createZilfuClient;
|
|
1417
1467
|
//# sourceMappingURL=index.cjs.map
|
|
1418
1468
|
//# sourceMappingURL=index.cjs.map
|