Skip to content

Commit 21c00d6

Browse files
committed
netlify fetch api
1 parent fda6ec8 commit 21c00d6

File tree

96 files changed

+6290
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+6290
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
5+
/*
6+
* https://www.npmjs.com/package/openapi-typescript-codegen
7+
* sudo npm install openapi-typescript-codegen -g
8+
* openapi -i https://open-api.netlify.com/swagger.json -o netlify -c fetch --name NetlifyClient --useOptions --indent 2
9+
*/
10+
11+
import type { BaseHttpRequest } from "./core/BaseHttpRequest.ts";
12+
import type { OpenAPIConfig } from "./core/OpenAPI.ts";
13+
import { FetchHttpRequest } from "./core/FetchHttpRequest.ts";
14+
15+
import { AccessTokenService } from "./services/AccessTokenService.ts";
16+
import { AccountMembershipService } from "./services/AccountMembershipService.ts";
17+
import { AccountTypeService } from "./services/AccountTypeService.ts";
18+
import { AssetService } from "./services/AssetService.ts";
19+
import { AssetPublicSignatureService } from "./services/AssetPublicSignatureService.ts";
20+
import { AuditLogService } from "./services/AuditLogService.ts";
21+
import { BuildService } from "./services/BuildService.ts";
22+
import { BuildHookService } from "./services/BuildHookService.ts";
23+
import { BuildLogMsgService } from "./services/BuildLogMsgService.ts";
24+
import { DeployService } from "./services/DeployService.ts";
25+
import { DeployedBranchService } from "./services/DeployedBranchService.ts";
26+
import { DeployKeyService } from "./services/DeployKeyService.ts";
27+
import { DnsZoneService } from "./services/DnsZoneService.ts";
28+
import { FileService } from "./services/FileService.ts";
29+
import { FormService } from "./services/FormService.ts";
30+
import { FunctionService } from "./services/FunctionService.ts";
31+
import { HookService } from "./services/HookService.ts";
32+
import { HookTypeService } from "./services/HookTypeService.ts";
33+
import { MemberService } from "./services/MemberService.ts";
34+
import { MetadataService } from "./services/MetadataService.ts";
35+
import { PaymentMethodService } from "./services/PaymentMethodService.ts";
36+
import { ServiceService } from "./services/ServiceService.ts";
37+
import { ServiceInstanceService } from "./services/ServiceInstanceService.ts";
38+
import { SiteService } from "./services/SiteService.ts";
39+
import { SniCertificateService } from "./services/SniCertificateService.ts";
40+
import { SnippetService } from "./services/SnippetService.ts";
41+
import { SplitTestService } from "./services/SplitTestService.ts";
42+
import { SubmissionService } from "./services/SubmissionService.ts";
43+
import { TicketService } from "./services/TicketService.ts";
44+
import { UserService } from "./services/UserService.ts";
45+
import { XInternalService } from "./services/XInternalService.ts";
46+
47+
type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;
48+
49+
export class NetlifyClient {
50+
public readonly accessToken: AccessTokenService;
51+
public readonly accountMembership: AccountMembershipService;
52+
public readonly accountType: AccountTypeService;
53+
public readonly asset: AssetService;
54+
public readonly assetPublicSignature: AssetPublicSignatureService;
55+
public readonly auditLog: AuditLogService;
56+
public readonly build: BuildService;
57+
public readonly buildHook: BuildHookService;
58+
public readonly buildLogMsg: BuildLogMsgService;
59+
public readonly deploy: DeployService;
60+
public readonly deployedBranch: DeployedBranchService;
61+
public readonly deployKey: DeployKeyService;
62+
public readonly dnsZone: DnsZoneService;
63+
public readonly file: FileService;
64+
public readonly form: FormService;
65+
public readonly function: FunctionService;
66+
public readonly hook: HookService;
67+
public readonly hookType: HookTypeService;
68+
public readonly member: MemberService;
69+
public readonly metadata: MetadataService;
70+
public readonly paymentMethod: PaymentMethodService;
71+
public readonly service: ServiceService;
72+
public readonly serviceInstance: ServiceInstanceService;
73+
public readonly site: SiteService;
74+
public readonly sniCertificate: SniCertificateService;
75+
public readonly snippet: SnippetService;
76+
public readonly splitTest: SplitTestService;
77+
public readonly submission: SubmissionService;
78+
public readonly ticket: TicketService;
79+
public readonly user: UserService;
80+
public readonly xInternal: XInternalService;
81+
82+
public readonly request: BaseHttpRequest;
83+
84+
constructor(
85+
config?: Partial<OpenAPIConfig>,
86+
HttpRequest: HttpRequestConstructor = FetchHttpRequest,
87+
) {
88+
this.request = new HttpRequest({
89+
BASE: config?.BASE ?? "https://api.netlify.com/api/v1",
90+
VERSION: config?.VERSION ?? "2.9.0",
91+
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
92+
CREDENTIALS: config?.CREDENTIALS ?? "include",
93+
TOKEN: config?.TOKEN,
94+
USERNAME: config?.USERNAME,
95+
PASSWORD: config?.PASSWORD,
96+
HEADERS: config?.HEADERS,
97+
ENCODE_PATH: config?.ENCODE_PATH,
98+
});
99+
100+
this.accessToken = new AccessTokenService(this.request);
101+
this.accountMembership = new AccountMembershipService(this.request);
102+
this.accountType = new AccountTypeService(this.request);
103+
this.asset = new AssetService(this.request);
104+
this.assetPublicSignature = new AssetPublicSignatureService(this.request);
105+
this.auditLog = new AuditLogService(this.request);
106+
this.build = new BuildService(this.request);
107+
this.buildHook = new BuildHookService(this.request);
108+
this.buildLogMsg = new BuildLogMsgService(this.request);
109+
this.deploy = new DeployService(this.request);
110+
this.deployedBranch = new DeployedBranchService(this.request);
111+
this.deployKey = new DeployKeyService(this.request);
112+
this.dnsZone = new DnsZoneService(this.request);
113+
this.file = new FileService(this.request);
114+
this.form = new FormService(this.request);
115+
this.function = new FunctionService(this.request);
116+
this.hook = new HookService(this.request);
117+
this.hookType = new HookTypeService(this.request);
118+
this.member = new MemberService(this.request);
119+
this.metadata = new MetadataService(this.request);
120+
this.paymentMethod = new PaymentMethodService(this.request);
121+
this.service = new ServiceService(this.request);
122+
this.serviceInstance = new ServiceInstanceService(this.request);
123+
this.site = new SiteService(this.request);
124+
this.sniCertificate = new SniCertificateService(this.request);
125+
this.snippet = new SnippetService(this.request);
126+
this.splitTest = new SplitTestService(this.request);
127+
this.submission = new SubmissionService(this.request);
128+
this.ticket = new TicketService(this.request);
129+
this.user = new UserService(this.request);
130+
this.xInternal = new XInternalService(this.request);
131+
}
132+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// deno-lint-ignore-file
2+
/* istanbul ignore file */
3+
/* tslint:disable */
4+
/* eslint-disable */
5+
import type { ApiResult } from "./ApiResult.ts";
6+
7+
export class ApiError extends Error {
8+
public readonly url: string;
9+
public readonly status: number;
10+
public readonly statusText: string;
11+
public readonly body: any;
12+
13+
constructor(response: ApiResult, message: string) {
14+
super(message);
15+
16+
this.name = "ApiError";
17+
this.url = response.url;
18+
this.status = response.status;
19+
this.statusText = response.statusText;
20+
this.body = response.body;
21+
}
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// deno-lint-ignore-file
2+
/* istanbul ignore file */
3+
/* tslint:disable */
4+
/* eslint-disable */
5+
export type ApiRequestOptions = {
6+
readonly method:
7+
| "GET"
8+
| "PUT"
9+
| "POST"
10+
| "DELETE"
11+
| "OPTIONS"
12+
| "HEAD"
13+
| "PATCH";
14+
readonly url: string;
15+
readonly path?: Record<string, any>;
16+
readonly cookies?: Record<string, any>;
17+
readonly headers?: Record<string, any>;
18+
readonly query?: Record<string, any>;
19+
readonly formData?: Record<string, any>;
20+
readonly body?: any;
21+
readonly mediaType?: string;
22+
readonly responseHeader?: string;
23+
readonly errors?: Record<number, string>;
24+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// deno-lint-ignore-file
2+
/* istanbul ignore file */
3+
/* tslint:disable */
4+
/* eslint-disable */
5+
export type ApiResult = {
6+
readonly url: string;
7+
readonly ok: boolean;
8+
readonly status: number;
9+
readonly statusText: string;
10+
readonly body: any;
11+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// deno-lint-ignore-file
2+
/* istanbul ignore file */
3+
/* tslint:disable */
4+
/* eslint-disable */
5+
import type { ApiRequestOptions } from "./ApiRequestOptions.ts";
6+
import type { CancelablePromise } from "./CancelablePromise.ts";
7+
import type { OpenAPIConfig } from "./OpenAPI.ts";
8+
9+
export abstract class BaseHttpRequest {
10+
constructor(public readonly config: OpenAPIConfig) {}
11+
12+
public abstract request<T>(options: ApiRequestOptions): CancelablePromise<T>;
13+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// deno-lint-ignore-file
2+
/* istanbul ignore file */
3+
/* tslint:disable */
4+
/* eslint-disable */
5+
export class CancelError extends Error {
6+
constructor(message: string) {
7+
super(message);
8+
this.name = "CancelError";
9+
}
10+
11+
public get isCancelled(): boolean {
12+
return true;
13+
}
14+
}
15+
16+
export interface OnCancel {
17+
readonly isResolved: boolean;
18+
readonly isRejected: boolean;
19+
readonly isCancelled: boolean;
20+
21+
(cancelHandler: () => void): void;
22+
}
23+
24+
export class CancelablePromise<T> implements Promise<T> {
25+
readonly [Symbol.toStringTag]: string;
26+
27+
private _isResolved: boolean;
28+
private _isRejected: boolean;
29+
private _isCancelled: boolean;
30+
private readonly _cancelHandlers: (() => void)[];
31+
private readonly _promise: Promise<T>;
32+
private _resolve?: (value: T | PromiseLike<T>) => void;
33+
private _reject?: (reason?: any) => void;
34+
35+
constructor(
36+
executor: (
37+
resolve: (value: T | PromiseLike<T>) => void,
38+
reject: (reason?: any) => void,
39+
onCancel: OnCancel,
40+
) => void,
41+
) {
42+
this._isResolved = false;
43+
this._isRejected = false;
44+
this._isCancelled = false;
45+
this._cancelHandlers = [];
46+
this._promise = new Promise<T>((resolve, reject) => {
47+
this._resolve = resolve;
48+
this._reject = reject;
49+
50+
const onResolve = (value: T | PromiseLike<T>): void => {
51+
if (this._isResolved || this._isRejected || this._isCancelled) {
52+
return;
53+
}
54+
this._isResolved = true;
55+
this._resolve?.(value);
56+
};
57+
58+
const onReject = (reason?: any): void => {
59+
if (this._isResolved || this._isRejected || this._isCancelled) {
60+
return;
61+
}
62+
this._isRejected = true;
63+
this._reject?.(reason);
64+
};
65+
66+
const onCancel = (cancelHandler: () => void): void => {
67+
if (this._isResolved || this._isRejected || this._isCancelled) {
68+
return;
69+
}
70+
this._cancelHandlers.push(cancelHandler);
71+
};
72+
73+
Object.defineProperty(onCancel, "isResolved", {
74+
get: (): boolean => this._isResolved,
75+
});
76+
77+
Object.defineProperty(onCancel, "isRejected", {
78+
get: (): boolean => this._isRejected,
79+
});
80+
81+
Object.defineProperty(onCancel, "isCancelled", {
82+
get: (): boolean => this._isCancelled,
83+
});
84+
85+
return executor(onResolve, onReject, onCancel as OnCancel);
86+
});
87+
}
88+
89+
public then<TResult1 = T, TResult2 = never>(
90+
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
91+
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null,
92+
): Promise<TResult1 | TResult2> {
93+
return this._promise.then(onFulfilled, onRejected);
94+
}
95+
96+
public catch<TResult = never>(
97+
onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null,
98+
): Promise<T | TResult> {
99+
return this._promise.catch(onRejected);
100+
}
101+
102+
public finally(onFinally?: (() => void) | null): Promise<T> {
103+
return this._promise.finally(onFinally);
104+
}
105+
106+
public cancel(): void {
107+
if (this._isResolved || this._isRejected || this._isCancelled) {
108+
return;
109+
}
110+
this._isCancelled = true;
111+
if (this._cancelHandlers.length) {
112+
try {
113+
for (const cancelHandler of this._cancelHandlers) {
114+
cancelHandler();
115+
}
116+
} catch (error) {
117+
console.warn("Cancellation threw an error", error);
118+
return;
119+
}
120+
}
121+
this._cancelHandlers.length = 0;
122+
this._reject?.(new CancelError("Request aborted"));
123+
}
124+
125+
public get isCancelled(): boolean {
126+
return this._isCancelled;
127+
}
128+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// deno-lint-ignore-file
2+
/* istanbul ignore file */
3+
/* tslint:disable */
4+
/* eslint-disable */
5+
import type { ApiRequestOptions } from "./ApiRequestOptions.ts";
6+
import { BaseHttpRequest } from "./BaseHttpRequest.ts";
7+
import type { CancelablePromise } from "./CancelablePromise.ts";
8+
import type { OpenAPIConfig } from "./OpenAPI.ts";
9+
import { request as __request } from "./request.ts";
10+
11+
export class FetchHttpRequest extends BaseHttpRequest {
12+
constructor(config: OpenAPIConfig) {
13+
super(config);
14+
}
15+
16+
/**
17+
* Request method
18+
* @param options The request options from the service
19+
* @returns CancelablePromise<T>
20+
* @throws ApiError
21+
*/
22+
public override request<T>(options: ApiRequestOptions): CancelablePromise<T> {
23+
return __request(this.config, options);
24+
}
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
import type { ApiRequestOptions } from "./ApiRequestOptions.ts";
5+
6+
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
7+
type Headers = Record<string, string>;
8+
9+
export type OpenAPIConfig = {
10+
BASE: string;
11+
VERSION: string;
12+
WITH_CREDENTIALS: boolean;
13+
CREDENTIALS: "include" | "omit" | "same-origin";
14+
TOKEN?: string | Resolver<string>;
15+
USERNAME?: string | Resolver<string>;
16+
PASSWORD?: string | Resolver<string>;
17+
HEADERS?: Headers | Resolver<Headers>;
18+
ENCODE_PATH?: (path: string) => string;
19+
};
20+
21+
export const OpenAPI: OpenAPIConfig = {
22+
BASE: "https://api.netlify.com/api/v1",
23+
VERSION: "2.9.0",
24+
WITH_CREDENTIALS: false,
25+
CREDENTIALS: "include",
26+
TOKEN: undefined,
27+
USERNAME: undefined,
28+
PASSWORD: undefined,
29+
HEADERS: undefined,
30+
ENCODE_PATH: undefined,
31+
};

0 commit comments

Comments
 (0)