netlify 13.2.1 → 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 +17 -13
- package/lib/index.js +0 -10
- package/lib/types.d.ts +129 -0
- package/lib/types.js +1 -0
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DynamicMethods } from './types.js';
|
|
1
2
|
type APIOptions = {
|
|
2
3
|
/** @example 'netlify/js-client' */
|
|
3
4
|
userAgent?: string;
|
|
@@ -16,6 +17,19 @@ type APIOptions = {
|
|
|
16
17
|
*/
|
|
17
18
|
globalParams?: Record<string, unknown>;
|
|
18
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
|
+
*/
|
|
31
|
+
export interface NetlifyAPI extends DynamicMethods {
|
|
32
|
+
}
|
|
19
33
|
export declare class NetlifyAPI {
|
|
20
34
|
#private;
|
|
21
35
|
defaultHeaders: Record<string, string>;
|
|
@@ -28,23 +42,13 @@ export declare class NetlifyAPI {
|
|
|
28
42
|
constructor(options?: APIOptions);
|
|
29
43
|
constructor(accessToken: string | undefined, options?: APIOptions);
|
|
30
44
|
/** Retrieves the access token */
|
|
31
|
-
get accessToken(): string | null;
|
|
32
|
-
set accessToken(token: string | null);
|
|
45
|
+
get accessToken(): string | undefined | null;
|
|
46
|
+
set accessToken(token: string | undefined | null);
|
|
33
47
|
get basePath(): string;
|
|
34
48
|
getAccessToken(ticket: any, { poll, timeout }?: {
|
|
35
49
|
poll?: number | undefined;
|
|
36
50
|
timeout?: number | undefined;
|
|
37
|
-
}): Promise<string>;
|
|
38
|
-
showTicket(_config: {
|
|
39
|
-
ticketId: string;
|
|
40
|
-
}): Promise<{
|
|
41
|
-
authorized: boolean;
|
|
42
|
-
}>;
|
|
43
|
-
exchangeTicket(_config: {
|
|
44
|
-
ticketId: string;
|
|
45
|
-
}): Promise<{
|
|
46
|
-
access_token: string;
|
|
47
|
-
}>;
|
|
51
|
+
}): Promise<string | undefined>;
|
|
48
52
|
}
|
|
49
53
|
export declare const methods: any[];
|
|
50
54
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -73,15 +73,5 @@ export class NetlifyAPI {
|
|
|
73
73
|
this.accessToken = accessTokenResponse.access_token;
|
|
74
74
|
return accessTokenResponse.access_token;
|
|
75
75
|
}
|
|
76
|
-
// Those methods are getting implemented by the Object.assign(this, { ...methods }) in the constructor
|
|
77
|
-
// This is a way where we can still maintain proper types while not implementing them.
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
79
|
-
showTicket(_config) {
|
|
80
|
-
throw new Error('Will be overridden in constructor!');
|
|
81
|
-
}
|
|
82
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
83
|
-
exchangeTicket(_config) {
|
|
84
|
-
throw new Error('Will be overridden in constructor!');
|
|
85
|
-
}
|
|
86
76
|
}
|
|
87
77
|
export const methods = getOperations();
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { ReadStream } from 'node:fs';
|
|
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;
|
|
14
|
+
/**
|
|
15
|
+
* Converts snake_case to camelCase for TypeScript types.
|
|
16
|
+
*/
|
|
17
|
+
type CamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${T}${Capitalize<CamelCase<U>>}` : S;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a union of both snake_case and camelCase keys with their respective types.
|
|
20
|
+
*/
|
|
21
|
+
type SnakeToCamel<T> = {
|
|
22
|
+
[K in keyof T as CamelCase<K & string>]: T[K];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
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.
|
|
90
|
+
*/
|
|
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;
|
|
92
|
+
/**
|
|
93
|
+
* Combines path, query, and request body parameters into a single type.
|
|
94
|
+
*/
|
|
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>;
|
|
97
|
+
type SuccessHttpStatusCodes = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;
|
|
98
|
+
/**
|
|
99
|
+
* Extracts the response type from the operation.
|
|
100
|
+
*/
|
|
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;
|
|
102
|
+
export type DynamicMethods = {
|
|
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>>;
|
|
128
|
+
};
|
|
129
|
+
export {};
|
package/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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.
|
|
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": "
|
|
66
|
+
"gitHead": "bba5964d53efc4efe7ff7f1f5ff139d81c8c840b"
|
|
67
67
|
}
|