@zilfu/sdk 0.1.0 → 0.1.2
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 +84 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -106
- package/dist/index.d.ts +61 -106
- package/dist/index.js +84 -33
- package/dist/index.js.map +1 -1
- package/package.json +14 -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
|
}
|
|
@@ -832,18 +832,6 @@ var HeyApiRegistry = class {
|
|
|
832
832
|
}
|
|
833
833
|
};
|
|
834
834
|
var Accounts = class extends HeyApiClient {
|
|
835
|
-
/**
|
|
836
|
-
* Disconnect multiple accounts
|
|
837
|
-
*
|
|
838
|
-
* Removes several social account connections in a single request and dispatches a webhook event for each.
|
|
839
|
-
*/
|
|
840
|
-
deleteMany(options) {
|
|
841
|
-
return (options.client ?? this.client).delete({
|
|
842
|
-
security: [{ scheme: "bearer", type: "http" }],
|
|
843
|
-
url: "/spaces/{space}/accounts",
|
|
844
|
-
...options
|
|
845
|
-
});
|
|
846
|
-
}
|
|
847
835
|
/**
|
|
848
836
|
* List accounts
|
|
849
837
|
*
|
|
@@ -883,7 +871,7 @@ var Accounts = class extends HeyApiClient {
|
|
|
883
871
|
/**
|
|
884
872
|
* Disconnect an account
|
|
885
873
|
*
|
|
886
|
-
* Removes the
|
|
874
|
+
* Removes the given account and every other account on the same platform within the space, dispatching an AccountDisconnected webhook for each.
|
|
887
875
|
*/
|
|
888
876
|
delete(options) {
|
|
889
877
|
return (options.client ?? this.client).delete({
|
|
@@ -893,7 +881,7 @@ var Accounts = class extends HeyApiClient {
|
|
|
893
881
|
});
|
|
894
882
|
}
|
|
895
883
|
};
|
|
896
|
-
var
|
|
884
|
+
var ApiTokens = class extends HeyApiClient {
|
|
897
885
|
/**
|
|
898
886
|
* Create an API token
|
|
899
887
|
*
|
|
@@ -923,7 +911,7 @@ var Tokens = class extends HeyApiClient {
|
|
|
923
911
|
});
|
|
924
912
|
}
|
|
925
913
|
};
|
|
926
|
-
var
|
|
914
|
+
var Blocks = class extends HeyApiClient {
|
|
927
915
|
list(options) {
|
|
928
916
|
return (options.client ?? this.client).get({
|
|
929
917
|
security: [{ scheme: "bearer", type: "http" }],
|
|
@@ -1014,6 +1002,19 @@ var Bio = class extends HeyApiClient {
|
|
|
1014
1002
|
}
|
|
1015
1003
|
});
|
|
1016
1004
|
}
|
|
1005
|
+
_blocks;
|
|
1006
|
+
get blocks() {
|
|
1007
|
+
return this._blocks ??= new Blocks({ client: this.client });
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
var Health = class extends HeyApiClient {
|
|
1011
|
+
check(options) {
|
|
1012
|
+
return (options?.client ?? this.client).get({
|
|
1013
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1014
|
+
url: "/health",
|
|
1015
|
+
...options
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1017
1018
|
};
|
|
1018
1019
|
var Media = class extends HeyApiClient {
|
|
1019
1020
|
/**
|
|
@@ -1332,28 +1333,28 @@ var Webhooks = class extends HeyApiClient {
|
|
|
1332
1333
|
});
|
|
1333
1334
|
}
|
|
1334
1335
|
};
|
|
1335
|
-
var
|
|
1336
|
+
var ZilfuApi = class _ZilfuApi extends HeyApiClient {
|
|
1336
1337
|
static __registry = new HeyApiRegistry();
|
|
1337
1338
|
constructor(args) {
|
|
1338
1339
|
super(args);
|
|
1339
|
-
|
|
1340
|
+
_ZilfuApi.__registry.set(this, args?.key);
|
|
1340
1341
|
}
|
|
1341
1342
|
_accounts;
|
|
1342
1343
|
get accounts() {
|
|
1343
1344
|
return this._accounts ??= new Accounts({ client: this.client });
|
|
1344
1345
|
}
|
|
1345
|
-
|
|
1346
|
-
get
|
|
1347
|
-
return this.
|
|
1348
|
-
}
|
|
1349
|
-
_bioBlocks;
|
|
1350
|
-
get bioBlocks() {
|
|
1351
|
-
return this._bioBlocks ??= new BioBlocks({ client: this.client });
|
|
1346
|
+
_apiTokens;
|
|
1347
|
+
get apiTokens() {
|
|
1348
|
+
return this._apiTokens ??= new ApiTokens({ client: this.client });
|
|
1352
1349
|
}
|
|
1353
1350
|
_bio;
|
|
1354
1351
|
get bio() {
|
|
1355
1352
|
return this._bio ??= new Bio({ client: this.client });
|
|
1356
1353
|
}
|
|
1354
|
+
_health;
|
|
1355
|
+
get health() {
|
|
1356
|
+
return this._health ??= new Health({ client: this.client });
|
|
1357
|
+
}
|
|
1357
1358
|
_media;
|
|
1358
1359
|
get media() {
|
|
1359
1360
|
return this._media ??= new Media({ client: this.client });
|
|
@@ -1388,31 +1389,68 @@ var ZilfuClient = class _ZilfuClient extends HeyApiClient {
|
|
|
1388
1389
|
}
|
|
1389
1390
|
};
|
|
1390
1391
|
|
|
1392
|
+
// src/errors.ts
|
|
1393
|
+
var ZilfuApiError = class extends Error {
|
|
1394
|
+
status;
|
|
1395
|
+
statusText;
|
|
1396
|
+
url;
|
|
1397
|
+
body;
|
|
1398
|
+
errors;
|
|
1399
|
+
constructor(init) {
|
|
1400
|
+
const message = extractMessage(init);
|
|
1401
|
+
super(message);
|
|
1402
|
+
this.name = "ZilfuApiError";
|
|
1403
|
+
this.status = init.status;
|
|
1404
|
+
this.statusText = init.statusText;
|
|
1405
|
+
this.url = init.url;
|
|
1406
|
+
this.body = init.body;
|
|
1407
|
+
this.errors = extractValidationErrors(init.body);
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
function extractMessage(init) {
|
|
1411
|
+
const body = init.body;
|
|
1412
|
+
if (body && typeof body === "object" && "message" in body) {
|
|
1413
|
+
const m = body.message;
|
|
1414
|
+
if (typeof m === "string" && m.length > 0) {
|
|
1415
|
+
return m;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
return `Zilfu API ${init.status}${init.statusText ? ` ${init.statusText}` : ""}`;
|
|
1419
|
+
}
|
|
1420
|
+
function extractValidationErrors(body) {
|
|
1421
|
+
if (!body || typeof body !== "object" || !("errors" in body)) {
|
|
1422
|
+
return void 0;
|
|
1423
|
+
}
|
|
1424
|
+
const errors = body.errors;
|
|
1425
|
+
if (!errors || typeof errors !== "object") {
|
|
1426
|
+
return void 0;
|
|
1427
|
+
}
|
|
1428
|
+
return errors;
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1391
1431
|
// src/client.ts
|
|
1392
|
-
function createZilfuClient(
|
|
1393
|
-
const
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1432
|
+
function createZilfuClient(opts) {
|
|
1433
|
+
const client2 = createClient(
|
|
1434
|
+
createConfig({
|
|
1435
|
+
baseUrl: opts.baseUrl ?? "https://zilfu.app/api",
|
|
1436
|
+
fetch: opts.fetch,
|
|
1437
|
+
headers: { accept: "application/json", ...opts.headers },
|
|
1438
|
+
auth: opts.token,
|
|
1439
|
+
throwOnError: true
|
|
1440
|
+
})
|
|
1441
|
+
);
|
|
1442
|
+
client2.interceptors.error.use((error, response) => {
|
|
1443
|
+
return new ZilfuApiError({
|
|
1444
|
+
status: response?.status ?? 0,
|
|
1445
|
+
statusText: response?.statusText,
|
|
1446
|
+
url: response?.url,
|
|
1447
|
+
body: error
|
|
1448
|
+
});
|
|
1398
1449
|
});
|
|
1399
|
-
return new
|
|
1450
|
+
return new ZilfuApi({ client: client2 });
|
|
1400
1451
|
}
|
|
1401
1452
|
|
|
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;
|
|
1453
|
+
exports.ZilfuApiError = ZilfuApiError;
|
|
1416
1454
|
exports.createZilfuClient = createZilfuClient;
|
|
1417
1455
|
//# sourceMappingURL=index.cjs.map
|
|
1418
1456
|
//# sourceMappingURL=index.cjs.map
|