UNPKG

4.75 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="node" />
3import * as http from 'http';
4import { Storage } from './storage.js';
5import { GoogleAuth } from 'google-auth-library';
6type GoogleAuthLike = Pick<GoogleAuth, 'getCredentials' | 'sign'>;
7/**
8 * @deprecated Use {@link GoogleAuth} instead
9 */
10export interface AuthClient {
11 sign(blobToSign: string): Promise<string>;
12 getCredentials(): Promise<{
13 client_email?: string;
14 }>;
15}
16export interface BucketI {
17 name: string;
18}
19export interface FileI {
20 name: string;
21}
22export interface Query {
23 [key: string]: string;
24}
25export interface GetSignedUrlConfigInternal {
26 expiration: number;
27 accessibleAt?: Date;
28 method: string;
29 extensionHeaders?: http.OutgoingHttpHeaders;
30 queryParams?: Query;
31 cname?: string;
32 contentMd5?: string;
33 contentType?: string;
34 bucket: string;
35 file?: string;
36 /**
37 * The host for the generated signed URL
38 *
39 * @example
40 * 'https://localhost:8080/'
41 */
42 host?: string | URL;
43 /**
44 * An endpoint for generating the signed URL
45 *
46 * @example
47 * 'https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/'
48 */
49 signingEndpoint?: string | URL;
50}
51export interface SignerGetSignedUrlConfig {
52 method: 'GET' | 'PUT' | 'DELETE' | 'POST';
53 expires: string | number | Date;
54 accessibleAt?: string | number | Date;
55 virtualHostedStyle?: boolean;
56 version?: 'v2' | 'v4';
57 cname?: string;
58 extensionHeaders?: http.OutgoingHttpHeaders;
59 queryParams?: Query;
60 contentMd5?: string;
61 contentType?: string;
62 /**
63 * The host for the generated signed URL
64 *
65 * @example
66 * 'https://localhost:8080/'
67 */
68 host?: string | URL;
69 /**
70 * An endpoint for generating the signed URL
71 *
72 * @example
73 * 'https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/'
74 */
75 signingEndpoint?: string | URL;
76}
77export type SignerGetSignedUrlResponse = string;
78export type GetSignedUrlResponse = [SignerGetSignedUrlResponse];
79export interface GetSignedUrlCallback {
80 (err: Error | null, url?: string): void;
81}
82export declare enum SignerExceptionMessages {
83 ACCESSIBLE_DATE_INVALID = "The accessible at date provided was invalid.",
84 EXPIRATION_BEFORE_ACCESSIBLE_DATE = "An expiration date cannot be before accessible date.",
85 X_GOOG_CONTENT_SHA256 = "The header X-Goog-Content-SHA256 must be a hexadecimal string."
86}
87/**
88 * @const {string}
89 * @deprecated - unused
90 */
91export declare const PATH_STYLED_HOST = "https://storage.googleapis.com";
92export declare class URLSigner {
93 private auth;
94 private bucket;
95 private file?;
96 /**
97 * A {@link Storage} object.
98 *
99 * @privateRemarks
100 *
101 * Technically this is a required field, however it would be a breaking change to
102 * move it before optional properties. In the next major we should refactor the
103 * constructor of this class to only accept a config object.
104 */
105 private storage;
106 constructor(auth: AuthClient | GoogleAuthLike, bucket: BucketI, file?: FileI | undefined,
107 /**
108 * A {@link Storage} object.
109 *
110 * @privateRemarks
111 *
112 * Technically this is a required field, however it would be a breaking change to
113 * move it before optional properties. In the next major we should refactor the
114 * constructor of this class to only accept a config object.
115 */
116 storage?: Storage);
117 getSignedUrl(cfg: SignerGetSignedUrlConfig): Promise<SignerGetSignedUrlResponse>;
118 private getSignedUrlV2;
119 private getSignedUrlV4;
120 /**
121 * Create canonical headers for signing v4 url.
122 *
123 * The canonical headers for v4-signing a request demands header names are
124 * first lowercased, followed by sorting the header names.
125 * Then, construct the canonical headers part of the request:
126 * <lowercasedHeaderName> + ":" + Trim(<value>) + "\n"
127 * ..
128 * <lowercasedHeaderName> + ":" + Trim(<value>) + "\n"
129 *
130 * @param headers
131 * @private
132 */
133 getCanonicalHeaders(headers: http.OutgoingHttpHeaders): string;
134 getCanonicalRequest(method: string, path: string, query: string, headers: string, signedHeaders: string, contentSha256?: string): string;
135 getCanonicalQueryParams(query: Query): string;
136 getResourcePath(cname: boolean, bucket: string, file?: string): string;
137 parseExpires(expires: string | number | Date, current?: Date): number;
138 parseAccessibleAt(accessibleAt?: string | number | Date): number;
139}
140/**
141 * Custom error type for errors related to getting signed errors and policies.
142 *
143 * @private
144 */
145export declare class SigningError extends Error {
146 name: string;
147}
148export {};