@blorp-labs/piefed-api-client 0.0.0-b0dfa6b → 0.0.0-f708c72
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 +61 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,18 +10,70 @@ Includes:
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
12
12
|
```sh
|
|
13
|
-
# .npmrc — point @blorp-labs scope to GitHub Packages
|
|
14
|
-
echo "@blorp-labs:registry=https://npm.pkg.github.com" >> .npmrc
|
|
15
|
-
|
|
16
13
|
pnpm add @blorp-labs/piefed-api-client
|
|
17
14
|
```
|
|
18
15
|
|
|
19
16
|
## Usage
|
|
20
17
|
|
|
18
|
+
### Basic
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { createClient } from '@blorp-labs/piefed-api-client';
|
|
22
|
+
|
|
23
|
+
const client = createClient('https://piefed.social');
|
|
24
|
+
const site = await client.getApiAlphaSite();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### With authentication
|
|
28
|
+
|
|
21
29
|
```ts
|
|
22
|
-
|
|
30
|
+
const client = createClient('https://piefed.social', {
|
|
31
|
+
headers: { Authorization: 'Bearer <token>' },
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### With default fetch options
|
|
36
|
+
|
|
37
|
+
Any [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) option (except `body` and `method`) can be set as a default:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const client = createClient('https://piefed.social', {
|
|
41
|
+
cache: 'no-store',
|
|
42
|
+
headers: { Authorization: 'Bearer <token>' },
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Per-call options override the defaults; headers are merged.
|
|
23
47
|
|
|
24
|
-
|
|
48
|
+
### Multiple instances
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
const a = createClient('https://instance-a.com');
|
|
52
|
+
const b = createClient('https://instance-b.com');
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Error handling
|
|
56
|
+
|
|
57
|
+
Errors throw an `ApiError` with `.status` and `.data`:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { createClient, ApiError } from '@blorp-labs/piefed-api-client';
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const site = await client.getApiAlphaSite();
|
|
64
|
+
} catch (e) {
|
|
65
|
+
if (e instanceof ApiError) {
|
|
66
|
+
console.error(e.status, e.data);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Zod schemas
|
|
72
|
+
|
|
73
|
+
Zod schemas are exported from the `/zod` subpath:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { getApiAlphaSiteQueryParams } from '@blorp-labs/piefed-api-client/zod';
|
|
25
77
|
```
|
|
26
78
|
|
|
27
79
|
## Development
|
|
@@ -37,8 +89,7 @@ pnpm build # compile TypeScript → dist/
|
|
|
37
89
|
|
|
38
90
|
## Automation
|
|
39
91
|
|
|
40
|
-
A GitHub Actions workflow
|
|
41
|
-
1. Regenerates `src/`
|
|
42
|
-
2.
|
|
43
|
-
3.
|
|
44
|
-
4. Publishes to GitHub Packages
|
|
92
|
+
A GitHub Actions workflow triggers on every push to `main`. It:
|
|
93
|
+
1. Regenerates `src/` from the live OpenAPI spec
|
|
94
|
+
2. Sets the version to `0.0.0-{commit-sha}`
|
|
95
|
+
3. Builds and publishes to npm
|
package/package.json
CHANGED