netlify 13.1.10 → 13.1.11
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 +44 -5
- package/lib/index.js +46 -24
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
type APIOptions = {
|
|
2
|
+
/** @example 'netlify/js-client' */
|
|
3
|
+
userAgent?: string;
|
|
4
|
+
/** @example 'https' */
|
|
5
|
+
scheme?: string;
|
|
6
|
+
/** @example 'api.netlify.com' */
|
|
7
|
+
host?: string;
|
|
8
|
+
/** @example '/api/v1' */
|
|
9
|
+
pathPrefix?: string;
|
|
10
|
+
accessToken?: string;
|
|
11
|
+
/** @example 'HttpsProxyAgent' */
|
|
12
|
+
agent?: string;
|
|
13
|
+
/**
|
|
14
|
+
* parameters you want available for every request.
|
|
15
|
+
* Global params are only sent of the OpenAPI spec specifies the provided params.
|
|
16
|
+
*/
|
|
17
|
+
globalParams?: Record<string, unknown>;
|
|
18
|
+
};
|
|
19
|
+
export declare class NetlifyAPI {
|
|
20
|
+
#private;
|
|
21
|
+
defaultHeaders: Record<string, string>;
|
|
22
|
+
/** The protocol is used like `https` */
|
|
23
|
+
scheme: string;
|
|
24
|
+
host: string;
|
|
25
|
+
pathPrefix: string;
|
|
26
|
+
agent?: string;
|
|
27
|
+
globalParams: Record<string, unknown>;
|
|
28
|
+
constructor(options?: APIOptions);
|
|
29
|
+
constructor(accessToken: string | undefined, options?: APIOptions);
|
|
30
|
+
/** Retrieves the access token */
|
|
4
31
|
get accessToken(): string | null;
|
|
32
|
+
set accessToken(token: string | null);
|
|
5
33
|
get basePath(): string;
|
|
6
34
|
getAccessToken(ticket: any, { poll, timeout }?: {
|
|
7
35
|
poll?: number | undefined;
|
|
8
36
|
timeout?: number | undefined;
|
|
9
|
-
}): Promise<
|
|
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
|
+
}>;
|
|
10
48
|
}
|
|
11
|
-
export const methods: any[];
|
|
49
|
+
export declare const methods: any[];
|
|
50
|
+
export {};
|
package/lib/index.js
CHANGED
|
@@ -2,36 +2,55 @@ import pWaitFor from 'p-wait-for';
|
|
|
2
2
|
import { getMethods } from './methods/index.js';
|
|
3
3
|
import { openApiSpec } from './open_api.js';
|
|
4
4
|
import { getOperations } from './operations.js';
|
|
5
|
+
// 1 second
|
|
6
|
+
const DEFAULT_TICKET_POLL = 1e3;
|
|
7
|
+
// 1 hour
|
|
8
|
+
const DEFAULT_TICKET_TIMEOUT = 3.6e6;
|
|
5
9
|
export class NetlifyAPI {
|
|
10
|
+
#accessToken = null;
|
|
11
|
+
defaultHeaders = {
|
|
12
|
+
accept: 'application/json',
|
|
13
|
+
};
|
|
14
|
+
/** The protocol is used like `https` */
|
|
15
|
+
scheme;
|
|
16
|
+
host;
|
|
17
|
+
pathPrefix;
|
|
18
|
+
agent;
|
|
19
|
+
globalParams = {};
|
|
6
20
|
constructor(firstArg, secondArg) {
|
|
7
21
|
// variadic arguments
|
|
8
|
-
const [accessTokenInput,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
const [accessTokenInput, options = {}] = typeof firstArg === 'object' ? [null, firstArg] : [firstArg, secondArg];
|
|
23
|
+
this.globalParams = options.globalParams || {};
|
|
24
|
+
this.agent = options.agent;
|
|
25
|
+
this.scheme = options.scheme || openApiSpec.schemes[0];
|
|
26
|
+
this.host = options.host || openApiSpec.host;
|
|
27
|
+
this.pathPrefix = options.pathPrefix || openApiSpec.basePath;
|
|
28
|
+
// use the setter to set the header as well
|
|
29
|
+
this.accessToken = options.accessToken || accessTokenInput || null;
|
|
30
|
+
this.defaultHeaders['User-agent'] = options.userAgent || 'netlify/js-client';
|
|
31
|
+
const methods = getMethods({
|
|
32
|
+
basePath: this.basePath,
|
|
33
|
+
defaultHeaders: this.defaultHeaders,
|
|
34
|
+
agent: this.agent,
|
|
35
|
+
globalParams: this.globalParams,
|
|
36
|
+
});
|
|
37
|
+
Object.assign(this, { ...methods });
|
|
18
38
|
}
|
|
39
|
+
/** Retrieves the access token */
|
|
19
40
|
get accessToken() {
|
|
20
|
-
|
|
21
|
-
if (typeof Authorization !== 'string' || !Authorization.startsWith('Bearer ')) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
return Authorization.replace('Bearer ', '');
|
|
41
|
+
return this.#accessToken;
|
|
25
42
|
}
|
|
26
43
|
set accessToken(token) {
|
|
27
44
|
if (!token) {
|
|
28
45
|
delete this.defaultHeaders.Authorization;
|
|
46
|
+
this.#accessToken = null;
|
|
29
47
|
return;
|
|
30
48
|
}
|
|
31
|
-
this
|
|
49
|
+
this.#accessToken = token;
|
|
50
|
+
this.defaultHeaders.Authorization = `Bearer ${this.#accessToken}`;
|
|
32
51
|
}
|
|
33
52
|
get basePath() {
|
|
34
|
-
return
|
|
53
|
+
return `${this.scheme}://${this.host}${this.pathPrefix}`;
|
|
35
54
|
}
|
|
36
55
|
async getAccessToken(ticket, { poll = DEFAULT_TICKET_POLL, timeout = DEFAULT_TICKET_TIMEOUT } = {}) {
|
|
37
56
|
const { id } = ticket;
|
|
@@ -54,12 +73,15 @@ export class NetlifyAPI {
|
|
|
54
73
|
this.accessToken = accessTokenResponse.access_token;
|
|
55
74
|
return accessTokenResponse.access_token;
|
|
56
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
|
+
}
|
|
57
86
|
}
|
|
58
|
-
const getBasePath = function ({ scheme, host, pathPrefix }) {
|
|
59
|
-
return `${scheme}://${host}${pathPrefix}`;
|
|
60
|
-
};
|
|
61
|
-
// 1 second
|
|
62
|
-
const DEFAULT_TICKET_POLL = 1e3;
|
|
63
|
-
// 1 hour
|
|
64
|
-
const DEFAULT_TICKET_TIMEOUT = 3.6e6;
|
|
65
87
|
export const methods = getOperations();
|
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.1.
|
|
4
|
+
"version": "13.1.11",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/index.js",
|
|
7
7
|
"main": "./lib/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"node client"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@netlify/open-api": "^2.
|
|
44
|
+
"@netlify/open-api": "^2.26.0",
|
|
45
45
|
"lodash-es": "^4.17.21",
|
|
46
46
|
"micro-api-client": "^3.3.0",
|
|
47
47
|
"node-fetch": "^3.0.0",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": "^14.16.0 || >=16.0.0"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "01ca6c705c4b568b7552a7d90a9801ebdc747594"
|
|
67
67
|
}
|