UNPKG

22.5 kBTypeScriptView Raw
1/// <reference types="node" />
2import { ApiError, BodyResponseCallback, DecorateRequestOptions, DeleteCallback, ExistsCallback, GetConfig, Metadata, ResponseBody, ServiceObject } from '@google-cloud/common';
3import * as http from 'http';
4import { Acl } from './acl';
5import { Channel } from './channel';
6import { File, FileOptions, CreateResumableUploadOptions, CreateWriteStreamOptions } from './file';
7import { Iam } from './iam';
8import { Notification } from './notification';
9import { Storage, Cors } from './storage';
10import { GetSignedUrlResponse, GetSignedUrlCallback, URLSigner, Query } from './signer';
11interface BucketOptions {
12 userProject?: string;
13}
14export declare type GetFilesResponse = [File[], {}, Metadata];
15export interface GetFilesCallback {
16 (err: Error | null, files?: File[], nextQuery?: {}, apiResponse?: Metadata): void;
17}
18interface WatchAllOptions {
19 delimiter?: string;
20 maxResults?: number;
21 pageToken?: string;
22 prefix?: string;
23 projection?: string;
24 userProject?: string;
25 versions?: boolean;
26}
27export interface AddLifecycleRuleOptions {
28 append?: boolean;
29}
30export interface LifecycleRule {
31 action: {
32 type: string;
33 storageClass?: string;
34 } | string;
35 condition: {
36 [key: string]: boolean | Date | number | string;
37 };
38 storageClass?: string;
39}
40export interface EnableLoggingOptions {
41 bucket?: string | Bucket;
42 prefix: string;
43}
44export interface GetFilesOptions {
45 autoPaginate?: boolean;
46 delimiter?: string;
47 /** @deprecated */
48 directory?: string;
49 endOffset?: string;
50 includeTrailingDelimiter?: boolean;
51 prefix?: string;
52 maxApiCalls?: number;
53 maxResults?: number;
54 pageToken?: string;
55 startOffset?: string;
56 userProject?: string;
57 versions?: boolean;
58}
59export interface CombineOptions {
60 kmsKeyName?: string;
61 userProject?: string;
62}
63export interface CombineCallback {
64 (err: Error | null, newFile: File | null, apiResponse: Metadata): void;
65}
66export declare type CombineResponse = [File, Metadata];
67export interface CreateChannelConfig extends WatchAllOptions {
68 address: string;
69}
70export interface CreateChannelOptions {
71 userProject?: string;
72}
73export declare type CreateChannelResponse = [Channel, Metadata];
74export interface CreateChannelCallback {
75 (err: Error | null, channel: Channel | null, apiResponse: Metadata): void;
76}
77export interface CreateNotificationOptions {
78 customAttributes?: {
79 [key: string]: string;
80 };
81 eventTypes?: string[];
82 objectNamePrefix?: string;
83 payloadFormat?: string;
84 userProject?: string;
85}
86export interface CreateNotificationCallback {
87 (err: Error | null, notification: Notification | null, apiResponse: Metadata): void;
88}
89export declare type CreateNotificationResponse = [Notification, Metadata];
90export interface DeleteBucketOptions {
91 ignoreNotFound?: boolean;
92 userProject?: string;
93}
94export declare type DeleteBucketResponse = [Metadata];
95export interface DeleteBucketCallback extends DeleteCallback {
96 (err: Error | null, apiResponse: Metadata): void;
97}
98export interface DeleteFilesOptions extends GetFilesOptions {
99 force?: boolean;
100}
101export interface DeleteFilesCallback {
102 (err: Error | Error[] | null, apiResponse?: object): void;
103}
104export declare type DeleteLabelsResponse = [Metadata];
105export declare type DeleteLabelsCallback = SetLabelsCallback;
106export declare type DisableRequesterPaysResponse = [Metadata];
107export interface DisableRequesterPaysCallback {
108 (err?: Error | null, apiResponse?: object): void;
109}
110export declare type EnableRequesterPaysResponse = [Metadata];
111export interface EnableRequesterPaysCallback {
112 (err?: Error | null, apiResponse?: Metadata): void;
113}
114export interface BucketExistsOptions extends GetConfig {
115 userProject?: string;
116}
117export declare type BucketExistsResponse = [boolean];
118export declare type BucketExistsCallback = ExistsCallback;
119export interface GetBucketOptions extends GetConfig {
120 userProject?: string;
121}
122export declare type GetBucketResponse = [Bucket, Metadata];
123export interface GetBucketCallback {
124 (err: ApiError | null, bucket: Bucket | null, apiResponse: Metadata): void;
125}
126export interface GetLabelsOptions {
127 userProject?: string;
128}
129export declare type GetLabelsResponse = [Metadata];
130export interface GetLabelsCallback {
131 (err: Error | null, labels: object | null): void;
132}
133export declare type GetBucketMetadataResponse = [Metadata, Metadata];
134export interface GetBucketMetadataCallback {
135 (err: ApiError | null, metadata: Metadata | null, apiResponse: Metadata): void;
136}
137export interface GetBucketMetadataOptions {
138 userProject?: string;
139}
140export interface GetBucketSignedUrlConfig {
141 action: 'list';
142 version?: 'v2' | 'v4';
143 cname?: string;
144 virtualHostedStyle?: boolean;
145 expires: string | number | Date;
146 extensionHeaders?: http.OutgoingHttpHeaders;
147 queryParams?: Query;
148}
149export declare enum BucketActionToHTTPMethod {
150 list = "GET"
151}
152export interface GetNotificationsOptions {
153 userProject?: string;
154}
155export interface GetNotificationsCallback {
156 (err: Error | null, notifications: Notification[] | null, apiResponse: Metadata): void;
157}
158export declare type GetNotificationsResponse = [Notification[], Metadata];
159export interface MakeBucketPrivateOptions {
160 includeFiles?: boolean;
161 force?: boolean;
162 metadata?: Metadata;
163 userProject?: string;
164}
165export declare type MakeBucketPrivateResponse = [File[]];
166export interface MakeBucketPrivateCallback {
167 (err?: Error | null, files?: File[]): void;
168}
169export interface MakeBucketPublicOptions {
170 includeFiles?: boolean;
171 force?: boolean;
172}
173export interface MakeBucketPublicCallback {
174 (err?: Error | null, files?: File[]): void;
175}
176export declare type MakeBucketPublicResponse = [File[]];
177export interface SetBucketMetadataOptions {
178 userProject?: string;
179}
180export declare type SetBucketMetadataResponse = [Metadata];
181export interface SetBucketMetadataCallback {
182 (err?: Error | null, metadata?: Metadata): void;
183}
184export interface BucketLockCallback {
185 (err?: Error | null, apiResponse?: Metadata): void;
186}
187export declare type BucketLockResponse = [Metadata];
188export interface Labels {
189 [key: string]: string;
190}
191export interface SetLabelsOptions {
192 userProject?: string;
193}
194export declare type SetLabelsResponse = [Metadata];
195export interface SetLabelsCallback {
196 (err?: Error | null, metadata?: Metadata): void;
197}
198export interface SetBucketStorageClassOptions {
199 userProject?: string;
200}
201export interface SetBucketStorageClassCallback {
202 (err?: Error | null): void;
203}
204export declare type UploadResponse = [File, Metadata];
205export interface UploadCallback {
206 (err: Error | null, file?: File | null, apiResponse?: Metadata): void;
207}
208export interface UploadOptions extends CreateResumableUploadOptions, CreateWriteStreamOptions {
209 destination?: string | File;
210 encryptionKey?: string | Buffer;
211 kmsKeyName?: string;
212 resumable?: boolean;
213 timeout?: number;
214 onUploadProgress?: (progressEvent: any) => void;
215}
216export interface MakeAllFilesPublicPrivateOptions {
217 force?: boolean;
218 private?: boolean;
219 public?: boolean;
220 userProject?: string;
221}
222interface MakeAllFilesPublicPrivateCallback {
223 (err?: Error | Error[] | null, files?: File[]): void;
224}
225declare type MakeAllFilesPublicPrivateResponse = [File[]];
226/**
227 * Get and set IAM policies for your bucket.
228 *
229 * @name Bucket#iam
230 * @mixes Iam
231 *
232 * @see [Cloud Storage IAM Management](https://cloud.google.com/storage/docs/access-control/iam#short_title_iam_management)
233 * @see [Granting, Changing, and Revoking Access](https://cloud.google.com/iam/docs/granting-changing-revoking-access)
234 * @see [IAM Roles](https://cloud.google.com/iam/docs/understanding-roles)
235 *
236 * @example
237 * const {Storage} = require('@google-cloud/storage');
238 * const storage = new Storage();
239 * const bucket = storage.bucket('albums');
240 *
241 * //-
242 * // Get the IAM policy for your bucket.
243 * //-
244 * bucket.iam.getPolicy(function(err, policy) {
245 * console.log(policy);
246 * });
247 *
248 * //-
249 * // If the callback is omitted, we'll return a Promise.
250 * //-
251 * bucket.iam.getPolicy().then(function(data) {
252 * const policy = data[0];
253 * const apiResponse = data[1];
254 * });
255 *
256 * @example <caption>include:samples/iam.js</caption>
257 * region_tag:storage_view_bucket_iam_members
258 * Example of retrieving a bucket's IAM policy:
259 *
260 * @example <caption>include:samples/iam.js</caption>
261 * region_tag:storage_add_bucket_iam_member
262 * Example of adding to a bucket's IAM policy:
263 *
264 * @example <caption>include:samples/iam.js</caption>
265 * region_tag:storage_remove_bucket_iam_member
266 * Example of removing from a bucket's IAM policy:
267 */
268/**
269 * Cloud Storage uses access control lists (ACLs) to manage object and
270 * bucket access. ACLs are the mechanism you use to share objects with other
271 * users and allow other users to access your buckets and objects.
272 *
273 * An ACL consists of one or more entries, where each entry grants permissions
274 * to an entity. Permissions define the actions that can be performed against
275 * an object or bucket (for example, `READ` or `WRITE`); the entity defines
276 * who the permission applies to (for example, a specific user or group of
277 * users).
278 *
279 * The `acl` object on a Bucket instance provides methods to get you a list of
280 * the ACLs defined on your bucket, as well as set, update, and delete them.
281 *
282 * Buckets also have
283 * [default
284 * ACLs](https://cloud.google.com/storage/docs/access-control/lists#default)
285 * for all created files. Default ACLs specify permissions that all new
286 * objects added to the bucket will inherit by default. You can add, delete,
287 * get, and update entities and permissions for these as well with
288 * {@link Bucket#acl.default}.
289 *
290 * @see [About Access Control Lists]{@link http://goo.gl/6qBBPO}
291 * @see [Default ACLs]{@link https://cloud.google.com/storage/docs/access-control/lists#default}
292 *
293 * @name Bucket#acl
294 * @mixes Acl
295 * @property {Acl} default Cloud Storage Buckets have
296 * [default
297 * ACLs](https://cloud.google.com/storage/docs/access-control/lists#default)
298 * for all created files. You can add, delete, get, and update entities and
299 * permissions for these as well. The method signatures and examples are all
300 * the same, after only prefixing the method call with `default`.
301 *
302 * @example
303 * const {Storage} = require('@google-cloud/storage');
304 * const storage = new Storage();
305 *
306 * //-
307 * // Make a bucket's contents publicly readable.
308 * //-
309 * const myBucket = storage.bucket('my-bucket');
310 *
311 * const options = {
312 * entity: 'allUsers',
313 * role: storage.acl.READER_ROLE
314 * };
315 *
316 * myBucket.acl.add(options, function(err, aclObject) {});
317 *
318 * //-
319 * // If the callback is omitted, we'll return a Promise.
320 * //-
321 * myBucket.acl.add(options).then(function(data) {
322 * const aclObject = data[0];
323 * const apiResponse = data[1];
324 * });
325 *
326 * @example <caption>include:samples/acl.js</caption>
327 * region_tag:storage_print_bucket_acl
328 * Example of printing a bucket's ACL:
329 *
330 * @example <caption>include:samples/acl.js</caption>
331 * region_tag:storage_print_bucket_acl_for_user
332 * Example of printing a bucket's ACL for a specific user:
333 *
334 * @example <caption>include:samples/acl.js</caption>
335 * region_tag:storage_add_bucket_owner
336 * Example of adding an owner to a bucket:
337 *
338 * @example <caption>include:samples/acl.js</caption>
339 * region_tag:storage_remove_bucket_owner
340 * Example of removing an owner from a bucket:
341 *
342 * @example <caption>include:samples/acl.js</caption>
343 * region_tag:storage_add_bucket_default_owner
344 * Example of adding a default owner to a bucket:
345 *
346 * @example <caption>include:samples/acl.js</caption>
347 * region_tag:storage_remove_bucket_default_owner
348 * Example of removing a default owner from a bucket:
349 */
350/**
351 * The API-formatted resource description of the bucket.
352 *
353 * Note: This is not guaranteed to be up-to-date when accessed. To get the
354 * latest record, call the `getMetadata()` method.
355 *
356 * @name Bucket#metadata
357 * @type {object}
358 */
359/**
360 * The bucket's name.
361 * @name Bucket#name
362 * @type {string}
363 */
364/**
365 * Get {@link File} objects for the files currently in the bucket as a
366 * readable object stream.
367 *
368 * @method Bucket#getFilesStream
369 * @param {GetFilesOptions} [query] Query object for listing files.
370 * @returns {ReadableStream} A readable stream that emits {@link File} instances.
371 *
372 * @example
373 * const {Storage} = require('@google-cloud/storage');
374 * const storage = new Storage();
375 * const bucket = storage.bucket('albums');
376 *
377 * bucket.getFilesStream()
378 * .on('error', console.error)
379 * .on('data', function(file) {
380 * // file is a File object.
381 * })
382 * .on('end', function() {
383 * // All files retrieved.
384 * });
385 *
386 * //-
387 * // If you anticipate many results, you can end a stream early to prevent
388 * // unnecessary processing and API requests.
389 * //-
390 * bucket.getFilesStream()
391 * .on('data', function(file) {
392 * this.end();
393 * });
394 *
395 * //-
396 * // If you're filtering files with a delimiter, you should use
397 * // {@link Bucket#getFiles} and set `autoPaginate: false` in order to
398 * // preserve the `apiResponse` argument.
399 * //-
400 * const prefixes = [];
401 *
402 * function callback(err, files, nextQuery, apiResponse) {
403 * prefixes = prefixes.concat(apiResponse.prefixes);
404 *
405 * if (nextQuery) {
406 * bucket.getFiles(nextQuery, callback);
407 * } else {
408 * // prefixes = The finished array of prefixes.
409 * }
410 * }
411 *
412 * bucket.getFiles({
413 * autoPaginate: false,
414 * delimiter: '/'
415 * }, callback);
416 */
417/**
418 * Create a Bucket object to interact with a Cloud Storage bucket.
419 *
420 * @class
421 * @hideconstructor
422 *
423 * @param {Storage} storage A {@link Storage} instance.
424 * @param {string} name The name of the bucket.
425 * @param {object} [options] Configuration object.
426 * @param {string} [options.userProject] User project.
427 *
428 * @example
429 * const {Storage} = require('@google-cloud/storage');
430 * const storage = new Storage();
431 * const bucket = storage.bucket('albums');
432 */
433declare class Bucket extends ServiceObject {
434 metadata: Metadata;
435 name: string;
436 /**
437 * A reference to the {@link Storage} associated with this {@link Bucket}
438 * instance.
439 * @name Bucket#storage
440 * @type {Storage}
441 */
442 storage: Storage;
443 /**
444 * A user project to apply to each request from this bucket.
445 * @name Bucket#userProject
446 * @type {string}
447 */
448 userProject?: string;
449 acl: Acl;
450 iam: Iam;
451 getFilesStream: Function;
452 signer?: URLSigner;
453 constructor(storage: Storage, name: string, options?: BucketOptions);
454 addLifecycleRule(rule: LifecycleRule, options?: AddLifecycleRuleOptions): Promise<SetBucketMetadataResponse>;
455 addLifecycleRule(rule: LifecycleRule, options: AddLifecycleRuleOptions, callback: SetBucketMetadataCallback): void;
456 addLifecycleRule(rule: LifecycleRule, callback: SetBucketMetadataCallback): void;
457 combine(sources: string[] | File[], destination: string | File, options?: CombineOptions): Promise<CombineResponse>;
458 combine(sources: string[] | File[], destination: string | File, options: CombineOptions, callback: CombineCallback): void;
459 combine(sources: string[] | File[], destination: string | File, callback: CombineCallback): void;
460 createChannel(id: string, config: CreateChannelConfig, options?: CreateChannelOptions): Promise<CreateChannelResponse>;
461 createChannel(id: string, config: CreateChannelConfig, callback: CreateChannelCallback): void;
462 createChannel(id: string, config: CreateChannelConfig, options: CreateChannelOptions, callback: CreateChannelCallback): void;
463 createNotification(topic: string, options?: CreateNotificationOptions): Promise<CreateNotificationResponse>;
464 createNotification(topic: string, options: CreateNotificationOptions, callback: CreateNotificationCallback): void;
465 createNotification(topic: string, callback: CreateNotificationCallback): void;
466 deleteFiles(query?: DeleteFilesOptions): Promise<void>;
467 deleteFiles(callback: DeleteFilesCallback): void;
468 deleteFiles(query: DeleteFilesOptions, callback: DeleteFilesCallback): void;
469 deleteLabels(labels?: string | string[]): Promise<DeleteLabelsResponse>;
470 deleteLabels(callback: DeleteLabelsCallback): void;
471 deleteLabels(labels: string | string[], callback: DeleteLabelsCallback): void;
472 disableRequesterPays(): Promise<DisableRequesterPaysResponse>;
473 disableRequesterPays(callback: DisableRequesterPaysCallback): void;
474 enableLogging(config: EnableLoggingOptions): Promise<SetBucketMetadataResponse>;
475 enableLogging(config: EnableLoggingOptions, callback: SetBucketMetadataCallback): void;
476 enableRequesterPays(): Promise<EnableRequesterPaysResponse>;
477 enableRequesterPays(callback: EnableRequesterPaysCallback): void;
478 /**
479 * Create a {@link File} object. See {@link File} to see how to handle
480 * the different use cases you may have.
481 *
482 * @param {string} name The name of the file in this bucket.
483 * @param {FileOptions} [options] Configuration options.
484 * @param {string|number} [options.generation] Only use a specific revision of
485 * this file.
486 * @param {string} [options.encryptionKey] A custom encryption key. See
487 * [Customer-supplied Encryption
488 * Keys](https://cloud.google.com/storage/docs/encryption#customer-supplied).
489 * @param {string} [options.kmsKeyName] The name of the Cloud KMS key that will
490 * be used to encrypt the object. Must be in the format:
491 * `projects/my-project/locations/location/keyRings/my-kr/cryptoKeys/my-key`.
492 * KMS key ring must use the same location as the bucket.
493 * @param {string} [options.userProject] The ID of the project which will be
494 * billed for all requests made from File object.
495 * @returns {File}
496 *
497 * @example
498 * const {Storage} = require('@google-cloud/storage');
499 * const storage = new Storage();
500 * const bucket = storage.bucket('albums');
501 * const file = bucket.file('my-existing-file.png');
502 */
503 file(name: string, options?: FileOptions): File;
504 getFiles(query?: GetFilesOptions): Promise<GetFilesResponse>;
505 getFiles(query: GetFilesOptions, callback: GetFilesCallback): void;
506 getFiles(callback: GetFilesCallback): void;
507 getLabels(options: GetLabelsOptions): Promise<GetLabelsResponse>;
508 getLabels(callback: GetLabelsCallback): void;
509 getLabels(options: GetLabelsOptions, callback: GetLabelsCallback): void;
510 getNotifications(options?: GetNotificationsOptions): Promise<GetNotificationsResponse>;
511 getNotifications(callback: GetNotificationsCallback): void;
512 getNotifications(options: GetNotificationsOptions, callback: GetNotificationsCallback): void;
513 getSignedUrl(cfg: GetBucketSignedUrlConfig): Promise<GetSignedUrlResponse>;
514 getSignedUrl(cfg: GetBucketSignedUrlConfig, callback: GetSignedUrlCallback): void;
515 lock(metageneration: number | string): Promise<BucketLockResponse>;
516 lock(metageneration: number | string, callback: BucketLockCallback): void;
517 makePrivate(options?: MakeBucketPrivateOptions): Promise<MakeBucketPrivateResponse>;
518 makePrivate(callback: MakeBucketPrivateCallback): void;
519 makePrivate(options: MakeBucketPrivateOptions, callback: MakeBucketPrivateCallback): void;
520 makePublic(options?: MakeBucketPublicOptions): Promise<MakeBucketPublicResponse>;
521 makePublic(callback: MakeBucketPublicCallback): void;
522 makePublic(options: MakeBucketPublicOptions, callback: MakeBucketPublicCallback): void;
523 /**
524 * Get a reference to a Cloud Pub/Sub Notification.
525 *
526 * @param {string} id ID of notification.
527 * @returns {Notification}
528 * @see Notification
529 *
530 * @example
531 * const {Storage} = require('@google-cloud/storage');
532 * const storage = new Storage();
533 * const bucket = storage.bucket('my-bucket');
534 * const notification = bucket.notification('1');
535 */
536 notification(id: string): Notification;
537 removeRetentionPeriod(): Promise<SetBucketMetadataResponse>;
538 removeRetentionPeriod(callback: SetBucketMetadataCallback): void;
539 request(reqOpts: DecorateRequestOptions): Promise<[ResponseBody, Metadata]>;
540 request(reqOpts: DecorateRequestOptions, callback: BodyResponseCallback): void;
541 setLabels(labels: Labels, options?: SetLabelsOptions): Promise<SetLabelsResponse>;
542 setLabels(labels: Labels, callback: SetLabelsCallback): void;
543 setLabels(labels: Labels, options: SetLabelsOptions, callback: SetLabelsCallback): void;
544 setRetentionPeriod(duration: number): Promise<SetBucketMetadataResponse>;
545 setRetentionPeriod(duration: number, callback: SetBucketMetadataCallback): void;
546 setCorsConfiguration(corsConfiguration: Cors[]): Promise<SetBucketMetadataResponse>;
547 setCorsConfiguration(corsConfiguration: Cors[], callback: SetBucketMetadataCallback): void;
548 setStorageClass(storageClass: string, options?: SetBucketStorageClassOptions): Promise<SetBucketMetadataResponse>;
549 setStorageClass(storageClass: string, callback: SetBucketStorageClassCallback): void;
550 setStorageClass(storageClass: string, options: SetBucketStorageClassOptions, callback: SetBucketStorageClassCallback): void;
551 /**
552 * Set a user project to be billed for all requests made from this Bucket
553 * object and any files referenced from this Bucket object.
554 *
555 * @param {string} userProject The user project.
556 *
557 * @example
558 * const {Storage} = require('@google-cloud/storage');
559 * const storage = new Storage();
560 * const bucket = storage.bucket('albums');
561 *
562 * bucket.setUserProject('grape-spaceship-123');
563 */
564 setUserProject(userProject: string): void;
565 upload(pathString: string, options?: UploadOptions): Promise<UploadResponse>;
566 upload(pathString: string, options: UploadOptions, callback: UploadCallback): void;
567 upload(pathString: string, callback: UploadCallback): void;
568 makeAllFilesPublicPrivate_(options?: MakeAllFilesPublicPrivateOptions): Promise<MakeAllFilesPublicPrivateResponse>;
569 makeAllFilesPublicPrivate_(callback: MakeAllFilesPublicPrivateCallback): void;
570 makeAllFilesPublicPrivate_(options: MakeAllFilesPublicPrivateOptions, callback: MakeAllFilesPublicPrivateCallback): void;
571 getId(): string;
572}
573/**
574 * Reference to the {@link Bucket} class.
575 * @name module:@google-cloud/storage.Bucket
576 * @see Bucket
577 */
578export { Bucket };