netlify 13.3.0 → 13.3.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/lib/index.d.ts CHANGED
@@ -17,6 +17,17 @@ type APIOptions = {
17
17
  */
18
18
  globalParams?: Record<string, unknown>;
19
19
  };
20
+ /**
21
+ * The Netlify API client.
22
+ * @see {@link https://open-api.netlify.com | Open API Reference}
23
+ * @see {@link https://docs.netlify.com/api/get-started | Online Documentation}
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const client = new NetlifyAPI('YOUR_ACCESS_TOKEN')
28
+ * const sites = await client.listSites()
29
+ * ```
30
+ */
20
31
  export interface NetlifyAPI extends DynamicMethods {
21
32
  }
22
33
  export declare class NetlifyAPI {
package/lib/types.d.ts CHANGED
@@ -1,4 +1,16 @@
1
+ import type { ReadStream } from 'node:fs';
1
2
  import type { operations } from '@netlify/open-api';
3
+ import type { RequestInit } from 'node-fetch';
4
+ /**
5
+ * Determines whether all keys in T are optional.
6
+ */
7
+ type AreAllOptional<T> = keyof T extends never ? true : T extends Record<string, any> ? {
8
+ [K in keyof T]-?: undefined extends T[K] ? never : K;
9
+ }[keyof T] extends never ? true : false : false;
10
+ /**
11
+ * Determines whether `path` and `query` are both optional.
12
+ */
13
+ type IsPathAndQueryOptional<K extends keyof operations> = 'parameters' extends keyof operations[K] ? AreAllOptional<'path' extends keyof operations[K]['parameters'] ? operations[K]['parameters']['path'] : object> extends true ? AreAllOptional<'query' extends keyof operations[K]['parameters'] ? operations[K]['parameters']['query'] : object> extends true ? true : false : false : true;
2
14
  /**
3
15
  * Converts snake_case to camelCase for TypeScript types.
4
16
  */
@@ -10,19 +22,108 @@ type SnakeToCamel<T> = {
10
22
  [K in keyof T as CamelCase<K & string>]: T[K];
11
23
  };
12
24
  /**
13
- * Combines snake_case and camelCase parameters.
25
+ * Combines snake_case and camelCase parameters into one Params type.
26
+ */
27
+ type Params<T> = SnakeToCamel<T> | T;
28
+ type HasRequestBody<K extends keyof operations> = 'requestBody' extends keyof operations[K] ? operations[K]['requestBody'] extends {
29
+ content: any;
30
+ } ? 'application/json' extends keyof operations[K]['requestBody']['content'] ? true : 'application/octet-stream' extends keyof operations[K]['requestBody']['content'] ? true : false : false : false;
31
+ /**
32
+ * Extracts the request body type from the operation.
33
+ */
34
+ type RequestBody<K extends keyof operations> = 'requestBody' extends keyof operations[K] ? operations[K]['requestBody'] extends {
35
+ content: any;
36
+ } ? 'application/json' extends keyof operations[K]['requestBody']['content'] ? operations[K]['requestBody']['content']['application/json'] : 'application/octet-stream' extends keyof operations[K]['requestBody']['content'] ? ReadStream | (() => ReadStream) : never : never : never;
37
+ type IsRequestBodyJson<K extends keyof operations> = 'requestBody' extends keyof operations[K] ? operations[K]['requestBody'] extends {
38
+ content: any;
39
+ } ? 'application/json' extends keyof operations[K]['requestBody']['content'] ? true : false : false : false;
40
+ type IsRequestBodyOctetStream<K extends keyof operations> = 'requestBody' extends keyof operations[K] ? operations[K]['requestBody'] extends {
41
+ content: any;
42
+ } ? 'application/octet-stream' extends keyof operations[K]['requestBody']['content'] ? true : false : false : false;
43
+ type RequestBodyParam<K extends keyof operations> = HasRequestBody<K> extends true ? IsRequestBodyOptional<K> extends true ? DetailedRequestBodyOptional<K> : DetailedRequestBody<K> : never;
44
+ type DetailedRequestBody<K extends keyof operations> = IsRequestBodyJson<K> extends true ? {
45
+ /**
46
+ * The request body for `application/json`.
47
+ * Automatically serialized to JSON based on the operation.
48
+ * Can be a JSON object or a function returning one.
49
+ */
50
+ body: RequestBody<K> | (() => RequestBody<K>);
51
+ } : IsRequestBodyOctetStream<K> extends true ? {
52
+ /**
53
+ * The request body for `application/octet-stream`.
54
+ * Can be a Node.js readable stream or a function returning one
55
+ * @example
56
+ * fs.createReadStream('./file')
57
+ * @example
58
+ * () => fs.createReadStream('./file')
59
+ */
60
+ body: ReadStream | (() => ReadStream);
61
+ } : never;
62
+ type DetailedRequestBodyOptional<K extends keyof operations> = IsRequestBodyJson<K> extends true ? {
63
+ /**
64
+ * The request body for `application/json`.
65
+ * Automatically serialized to JSON based on the operation.
66
+ * Can be a JSON object or a function returning one.
67
+ */
68
+ body?: RequestBody<K> | (() => RequestBody<K>);
69
+ } : IsRequestBodyOctetStream<K> extends true ? {
70
+ /**
71
+ * The request body for `application/octet-stream`.
72
+ * Can be a Node.js readable stream or a function returning one
73
+ * @example
74
+ * fs.createReadStream('./file')
75
+ * @example
76
+ * () => fs.createReadStream('./file')
77
+ */
78
+ body?: ReadStream | (() => ReadStream);
79
+ } : never;
80
+ /**
81
+ * Determines whether all properties in the request body are optional.
82
+ */
83
+ type IsRequestBodyOptional<K extends keyof operations> = HasRequestBody<K> extends true ? (AreAllOptional<RequestBody<K>> extends true ? true : false) : true;
84
+ /**
85
+ * Determines whether any parameters or request body are required.
86
+ */
87
+ type IsParamsOrRequestBodyRequired<K extends keyof operations> = 'parameters' extends keyof operations[K] ? IsPathAndQueryOptional<K> extends true ? IsRequestBodyOptional<K> extends true ? false : true : true : false;
88
+ /**
89
+ * Extracts and combines `path` and `query` parameters into a single type.
14
90
  */
15
- type CombinedCaseParams<T> = SnakeToCamel<T> | T;
91
+ type ExtractPathAndQueryParameters<K extends keyof operations> = 'parameters' extends keyof operations[K] ? 'path' extends keyof operations[K]['parameters'] ? 'query' extends keyof operations[K]['parameters'] ? Params<Omit<operations[K]['parameters']['path'], keyof operations[K]['parameters']['query']> & operations[K]['parameters']['query']> : Params<operations[K]['parameters']['path']> : 'query' extends keyof operations[K]['parameters'] ? Params<operations[K]['parameters']['query']> : undefined : undefined;
16
92
  /**
17
- * Combines `path` and `query` parameters into a single type.
93
+ * Combines path, query, and request body parameters into a single type.
18
94
  */
19
- type OperationParams<K extends keyof operations> = 'parameters' extends keyof operations[K] ? 'path' extends keyof operations[K]['parameters'] ? 'query' extends keyof operations[K]['parameters'] ? CombinedCaseParams<Omit<operations[K]['parameters']['path'], keyof operations[K]['parameters']['query']> & operations[K]['parameters']['query']> : CombinedCaseParams<operations[K]['parameters']['path']> : 'query' extends keyof operations[K]['parameters'] ? CombinedCaseParams<operations[K]['parameters']['query']> : undefined : undefined;
95
+ type CombinedParamsAndRequestBody<K extends keyof operations> = HasRequestBody<K> extends true ? ExtractPathAndQueryParameters<K> & RequestBodyParam<K> : ExtractPathAndQueryParameters<K>;
96
+ type OperationParams<K extends keyof operations> = IsParamsOrRequestBodyRequired<K> extends false ? CombinedParamsAndRequestBody<K> | void | undefined : CombinedParamsAndRequestBody<K>;
20
97
  type SuccessHttpStatusCodes = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;
21
98
  /**
22
99
  * Extracts the response type from the operation.
23
100
  */
24
101
  type OperationResponse<K extends keyof operations> = 'responses' extends keyof operations[K] ? SuccessHttpStatusCodes extends infer StatusKeys ? StatusKeys extends keyof operations[K]['responses'] ? 'content' extends keyof operations[K]['responses'][StatusKeys] ? 'application/json' extends keyof operations[K]['responses'][StatusKeys]['content'] ? operations[K]['responses'][StatusKeys]['content']['application/json'] : never : never : never : never : never;
25
102
  export type DynamicMethods = {
26
- [K in keyof operations]: (params: OperationParams<K>) => Promise<OperationResponse<K>>;
103
+ [K in keyof operations]: (params: OperationParams<K>,
104
+ /**
105
+ * Any properties you want passed to `node-fetch`.
106
+ *
107
+ * The `headers` property is merged with some `defaultHeaders`:
108
+ * ```ts
109
+ * {
110
+ * 'User-agent': 'netlify-js-client',
111
+ * 'accept': 'application/json',
112
+ * }
113
+ * ```
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const site = await client.getSite(
118
+ * { site_id: 'YOUR_SITE_ID' },
119
+ * {
120
+ * headers: {
121
+ * 'X-Example-Header': 'Example Value',
122
+ * },
123
+ * },
124
+ * )
125
+ * ```
126
+ */
127
+ opts?: RequestInit | void | undefined) => Promise<OperationResponse<K>>;
27
128
  };
28
129
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "netlify",
3
3
  "description": "Netlify Node.js API client",
4
- "version": "13.3.0",
4
+ "version": "13.3.1",
5
5
  "type": "module",
6
6
  "exports": "./lib/index.js",
7
7
  "main": "./lib/index.js",
@@ -63,5 +63,5 @@
63
63
  "engines": {
64
64
  "node": "^14.16.0 || >=16.0.0"
65
65
  },
66
- "gitHead": "0a66a5592b80f8b2e2538ebc385d3eea8777c7b7"
66
+ "gitHead": "bba5964d53efc4efe7ff7f1f5ff139d81c8c840b"
67
67
  }