UNPKG

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