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