netlify-api 1.4.1 → 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.
Files changed (43) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +44 -3
  3. package/dist/components-c1mxsnm9.d.ts +2772 -0
  4. package/dist/components-c1mxsnm9.d.ts.map +1 -0
  5. package/dist/{components-eneirm1i.js → components-guauto8m.js} +923 -440
  6. package/dist/{components-clupkq1b.cjs → components-kairy70t.cjs} +929 -439
  7. package/dist/components-lahqw4b2.d.ts +2772 -0
  8. package/dist/components-lahqw4b2.d.ts.map +1 -0
  9. package/dist/components.cjs +8 -1
  10. package/dist/components.d.cts +2 -0
  11. package/dist/components.d.cts.map +1 -0
  12. package/dist/components.d.mts +1 -3021
  13. package/dist/components.d.mts.map +1 -1
  14. package/dist/components.mjs +1 -1
  15. package/dist/effect.cjs +131 -24
  16. package/dist/effect.d.cts +543 -0
  17. package/dist/effect.d.cts.map +1 -0
  18. package/dist/effect.d.mts +97 -9
  19. package/dist/effect.d.mts.map +1 -1
  20. package/dist/effect.mjs +125 -4
  21. package/dist/index.cjs +346 -26
  22. package/dist/index.d.cts +249 -0
  23. package/dist/index.d.cts.map +1 -0
  24. package/dist/index.d.mts +249 -0
  25. package/dist/index.d.mts.map +1 -0
  26. package/dist/index.d.ts +6293 -2409
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.mjs +31 -27
  29. package/dist/{schemas-bl2qhxel.cjs → schemas-gcraq33n.cjs} +2259 -379
  30. package/dist/{schemas-goc7bnr4.js → schemas-i1pnxe6s.js} +1954 -380
  31. package/dist/schemas.cjs +307 -1
  32. package/dist/schemas.d.cts +11531 -0
  33. package/dist/schemas.d.cts.map +1 -0
  34. package/dist/schemas.d.mts +2495 -616
  35. package/dist/schemas.d.mts.map +1 -1
  36. package/dist/schemas.mjs +1 -1
  37. package/dist/types.cjs +75 -8
  38. package/dist/types.d.cts +17004 -0
  39. package/dist/types.d.cts.map +1 -0
  40. package/dist/types.d.mts +3031 -785
  41. package/dist/types.d.mts.map +1 -1
  42. package/dist/types.mjs +64 -7
  43. 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: "https://api.netlify.com/api/v1", // optional override
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 |