-
Notifications
You must be signed in to change notification settings - Fork 34
/
api.ts
87 lines (75 loc) · 2.34 KB
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2020 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {GaxiosOptions, GaxiosResponse} from 'gaxios';
import {
OAuth2Client,
GoogleAuth,
BaseExternalAccountClient,
} from 'google-auth-library';
import {Endpoint} from './endpoint';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface APIRequestParams<T = any> {
options: MethodOptions;
params: T;
requiredParams: string[];
pathParams: string[];
context: APIRequestContext;
mediaUrl?: string | null;
}
export interface GoogleConfigurable {
_options: GlobalOptions;
}
export interface APIRequestContext {
google?: GoogleConfigurable;
_options: GlobalOptions;
}
/**
* This interface is a mix of the AxiosRequestConfig options
* and our `auth` options.
*/
export interface GlobalOptions extends MethodOptions {
auth?: GoogleAuth | OAuth2Client | BaseExternalAccountClient | string;
universeDomain?: string;
universe_domain?: string;
}
export interface MethodOptions extends GaxiosOptions {
apiVersion?: string;
rootUrl?: string;
http2?: boolean;
userAgentDirectives?: UserAgentDirective[];
}
export interface StreamMethodOptions extends MethodOptions {
responseType: 'stream';
}
/**
* An additional directive to add to the user agent header.
* Directives come in the form of:
* User-Agent: <product> / <product-version> <comment>
*
* For more information, see:
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
*/
export interface UserAgentDirective {
product: string;
version: string;
comment?: string;
}
export interface ServiceOptions extends GlobalOptions {
version?: string;
}
export type BodyResponseCallback<T> = (
err: Error | null,
res?: GaxiosResponse<T> | null
) => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type APIEndpoint = Readonly<Endpoint & any>;