UNPKG

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