1 | import { AuthClient, GoogleAuth, GoogleAuthOptions } from 'google-auth-library';
|
2 | import * as r from 'teeny-request';
|
3 | import { Interceptor } from './service-object';
|
4 | import { BodyResponseCallback, DecorateRequestOptions, MakeAuthenticatedRequest, PackageJson } from './util';
|
5 | export interface StreamRequestOptions extends DecorateRequestOptions {
|
6 | shouldReturnStream: true;
|
7 | }
|
8 | export interface ServiceConfig {
|
9 | /**
|
10 | * The base URL to make API requests to.
|
11 | */
|
12 | baseUrl: string;
|
13 | /**
|
14 | * The API Endpoint to use when connecting to the service.
|
15 | * Example: storage.googleapis.com
|
16 | */
|
17 | apiEndpoint: string;
|
18 | /**
|
19 | * The scopes required for the request.
|
20 | */
|
21 | scopes: string[];
|
22 | projectIdRequired?: boolean;
|
23 | packageJson: PackageJson;
|
24 | /**
|
25 | * Reuse an existing `AuthClient` or `GoogleAuth` client instead of creating a new one.
|
26 | */
|
27 | authClient?: AuthClient | GoogleAuth;
|
28 | }
|
29 | export interface ServiceOptions extends Omit<GoogleAuthOptions, 'authClient'> {
|
30 | authClient?: AuthClient | GoogleAuth;
|
31 | interceptors_?: Interceptor[];
|
32 | email?: string;
|
33 | token?: string;
|
34 | timeout?: number;
|
35 | userAgent?: string;
|
36 | useAuthWithCustomEndpoint?: boolean;
|
37 | }
|
38 | export declare class Service {
|
39 | baseUrl: string;
|
40 | private globalInterceptors;
|
41 | interceptors: Interceptor[];
|
42 | private packageJson;
|
43 | projectId: string;
|
44 | private projectIdRequired;
|
45 | providedUserAgent?: string;
|
46 | makeAuthenticatedRequest: MakeAuthenticatedRequest;
|
47 | authClient: GoogleAuth<AuthClient>;
|
48 | private getCredentials;
|
49 | readonly apiEndpoint: string;
|
50 | timeout?: number;
|
51 | /**
|
52 | * Service is a base class, meant to be inherited from by a "service," like
|
53 | * BigQuery or Storage.
|
54 | *
|
55 | * This handles making authenticated requests by exposing a `makeReq_`
|
56 | * function.
|
57 | *
|
58 | * @constructor
|
59 | * @alias module:common/service
|
60 | *
|
61 | * @param {object} config - Configuration object.
|
62 | * @param {string} config.baseUrl - The base URL to make API requests to.
|
63 | * @param {string[]} config.scopes - The scopes required for the request.
|
64 | * @param {object=} options - [Configuration object](#/docs).
|
65 | */
|
66 | constructor(config: ServiceConfig, options?: ServiceOptions);
|
67 | /**
|
68 | * Return the user's custom request interceptors.
|
69 | */
|
70 | getRequestInterceptors(): Function[];
|
71 | /**
|
72 | * Get and update the Service's project ID.
|
73 | *
|
74 | * @param {function} callback - The callback function.
|
75 | */
|
76 | getProjectId(): Promise<string>;
|
77 | getProjectId(callback: (err: Error | null, projectId?: string) => void): void;
|
78 | protected getProjectIdAsync(): Promise<string>;
|
79 | /**
|
80 | * Make an authenticated API request.
|
81 | *
|
82 | * @private
|
83 | *
|
84 | * @param {object} reqOpts - Request options that are passed to `request`.
|
85 | * @param {string} reqOpts.uri - A URI relative to the baseUrl.
|
86 | * @param {function} callback - The callback function passed to `request`.
|
87 | */
|
88 | private request_;
|
89 | /**
|
90 | * Make an authenticated API request.
|
91 | *
|
92 | * @param {object} reqOpts - Request options that are passed to `request`.
|
93 | * @param {string} reqOpts.uri - A URI relative to the baseUrl.
|
94 | * @param {function} callback - The callback function passed to `request`.
|
95 | */
|
96 | request(reqOpts: DecorateRequestOptions, callback: BodyResponseCallback): void;
|
97 | /**
|
98 | * Make an authenticated API request.
|
99 | *
|
100 | * @param {object} reqOpts - Request options that are passed to `request`.
|
101 | * @param {string} reqOpts.uri - A URI relative to the baseUrl.
|
102 | */
|
103 | requestStream(reqOpts: DecorateRequestOptions): r.Request;
|
104 | }
|