netlify-api 1.4.0 → 3.0.4
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 +15 -0
- package/README.md +44 -3
- package/dist/components-c1mxsnm9.d.ts +2772 -0
- package/dist/components-c1mxsnm9.d.ts.map +1 -0
- package/dist/{components-eneirm1i.js → components-guauto8m.js} +923 -440
- package/dist/{components-clupkq1b.cjs → components-kairy70t.cjs} +929 -439
- package/dist/components-lahqw4b2.d.ts +2772 -0
- package/dist/components-lahqw4b2.d.ts.map +1 -0
- package/dist/components.cjs +8 -1
- package/dist/components.d.cts +2 -0
- package/dist/components.d.cts.map +1 -0
- package/dist/components.d.mts +1 -3021
- package/dist/components.d.mts.map +1 -1
- package/dist/components.mjs +1 -1
- package/dist/effect.cjs +131 -24
- package/dist/effect.d.cts +543 -0
- package/dist/effect.d.cts.map +1 -0
- package/dist/effect.d.mts +97 -9
- package/dist/effect.d.mts.map +1 -1
- package/dist/effect.mjs +125 -4
- package/dist/index.cjs +346 -26
- package/dist/index.d.cts +249 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +249 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +6308 -2424
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +31 -27
- package/dist/{schemas-ha5203ib.cjs → schemas-gcraq33n.cjs} +2290 -410
- package/dist/{schemas-kqcu3ivr.js → schemas-i1pnxe6s.js} +1985 -411
- package/dist/schemas.cjs +307 -1
- package/dist/schemas.d.cts +11531 -0
- package/dist/schemas.d.cts.map +1 -0
- package/dist/schemas.d.mts +2533 -654
- package/dist/schemas.d.mts.map +1 -1
- package/dist/schemas.mjs +1 -1
- package/dist/types.cjs +75 -8
- package/dist/types.d.cts +17004 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +3032 -786
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +64 -7
- package/package.json +57 -29
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) SferaDev
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -32,20 +32,59 @@ Operations are grouped by tag: `client.api.<tag>.<operation>(params)`.
|
|
|
32
32
|
```ts
|
|
33
33
|
const client = new NetlifyApi({
|
|
34
34
|
token: process.env.NETLIFY_TOKEN ?? "",
|
|
35
|
-
basePath: "
|
|
35
|
+
basePath: "/api/v1", // optional, the default
|
|
36
36
|
fetch: myFetchImplementation, // optional
|
|
37
37
|
});
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
`basePath` is the path prefix appended to `https://api.netlify.com`, not a full URL. The host is fixed and cannot be configured.
|
|
41
|
+
|
|
42
|
+
### Calling by method and path
|
|
43
|
+
|
|
44
|
+
`client.request()` addresses an operation by its HTTP method and path instead of its tag and name. Parameters and the result are typed the same way as through `client.api`.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const sites = await client.request("GET /sites", { queryParams: { per_page: 10 } });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
An endpoint that is not in the spec throws.
|
|
51
|
+
|
|
52
|
+
### Refreshing an OAuth token
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
const { tokenType, accessToken, refreshToken, scope, createdAt } = await client.auth.refreshToken({
|
|
56
|
+
refreshToken: storedRefreshToken,
|
|
57
|
+
clientId: process.env.NETLIFY_CLIENT_ID ?? "",
|
|
58
|
+
clientSecret: process.env.NETLIFY_CLIENT_SECRET ?? "",
|
|
59
|
+
authToken: currentAccessToken, // optional, defaults to the client's token
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
This posts to `https://api.netlify.com/oauth/token` and returns the new token pair, with `createdAt` as a Unix timestamp.
|
|
64
|
+
|
|
65
|
+
### Errors
|
|
66
|
+
|
|
67
|
+
A request that gets an HTTP error response rejects with `{ status, payload }`: `status` is the HTTP status code and `payload` is the parsed error body, or the raw body text, up to 1000 characters, when it is not JSON. A request that never gets a response rejects with an `Error` whose message names the method, the path and the reason, and whose `cause` is the original exception. A request cancelled through `signal` rejects with what the signal was aborted with, as is: the `AbortError`, or the `TimeoutError` of `AbortSignal.timeout()`.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
try {
|
|
71
|
+
await client.api.site.getSite({ pathParams: { site_id: "missing" } });
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (typeof error === "object" && error !== null && "status" in error && "payload" in error) {
|
|
74
|
+
console.error(error.status, error.payload);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
40
79
|
## Effect
|
|
41
80
|
|
|
42
|
-
The `effect` entrypoint exposes every operation as an `Effect`. It requires `effect` as a peer dependency.
|
|
81
|
+
The `effect` entrypoint exposes every operation as an `Effect`. It requires `effect` 4 as a peer dependency.
|
|
43
82
|
|
|
44
83
|
```ts
|
|
45
84
|
import { Effect } from "effect";
|
|
46
85
|
import { ApiService, makeApiLayer } from "netlify-api/effect";
|
|
47
86
|
|
|
48
|
-
const program = ApiService.site.listSites(
|
|
87
|
+
const program = ApiService.site.listSites();
|
|
49
88
|
|
|
50
89
|
await Effect.runPromise(
|
|
51
90
|
program.pipe(Effect.provide(makeApiLayer({ token: process.env.NETLIFY_TOKEN })))
|
|
@@ -54,6 +93,8 @@ await Effect.runPromise(
|
|
|
54
93
|
|
|
55
94
|
Errors are typed as `ApiError`, `NetworkError` and `ValidationError`.
|
|
56
95
|
|
|
96
|
+
`makeApiLayer` accepts `token` and `headers`. Its `baseUrl` option is ignored by this client, which always calls `https://api.netlify.com/api/v1`.
|
|
97
|
+
|
|
57
98
|
## Entrypoints
|
|
58
99
|
|
|
59
100
|
| Import | Contents |
|