Socket
Socket
Sign inDemoInstall

@google-cloud/storage

Package Overview
Dependencies
Maintainers
1
Versions
183
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/storage - npm Package Compare versions

Comparing version 6.1.0 to 6.2.0

15

build/src/bucket.d.ts
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { ApiError, BodyResponseCallback, DecorateRequestOptions, DeleteCallback, ExistsCallback, GetConfig, Metadata, ResponseBody, ServiceObject } from './nodejs-common';

@@ -475,2 +476,16 @@ import * as http from 'http';

constructor(storage: Storage, name: string, options?: BucketOptions);
/**
* The bucket's Cloud Storage URI (`gs://`)
*
* @example
* ```ts
* const {Storage} = require('@google-cloud/storage');
* const storage = new Storage();
* const bucket = storage.bucket('my-bucket');
*
* // `gs://my-bucket`
* const href = bucket.cloudStorageURI.href;
* ```
*/
get cloudStorageURI(): URL;
addLifecycleRule(rule: LifecycleRule, options?: AddLifecycleRuleOptions): Promise<SetBucketMetadataResponse>;

@@ -477,0 +492,0 @@ addLifecycleRule(rule: LifecycleRule, options: AddLifecycleRuleOptions, callback: SetBucketMetadataCallback): void;

/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { BodyResponseCallback, DecorateRequestOptions, GetConfig, Metadata, ServiceObject } from './nodejs-common';

@@ -352,2 +353,17 @@ import { Writable, Readable } from 'stream';

/**
* The object's Cloud Storage URI (`gs://`)
*
* @example
* ```ts
* const {Storage} = require('@google-cloud/storage');
* const storage = new Storage();
* const bucket = storage.bucket('my-bucket');
* const file = bucket.file('image.png');
*
* // `gs://my-bucket/image.png`
* const href = file.cloudStorageURI.href;
* ```
*/
get cloudStorageURI(): URL;
/**
* A helper method for determining if a request should be retried based on preconditions.

@@ -354,0 +370,0 @@ * This should only be used for methods where the idempotency is determined by

1

build/src/nodejs-common/service.d.ts

@@ -5,2 +5,3 @@ import { AuthClient, GoogleAuth, GoogleAuthOptions } from 'google-auth-library';

import { BodyResponseCallback, DecorateRequestOptions, MakeAuthenticatedRequest, PackageJson } from './util';
export declare const DEFAULT_PROJECT_ID_TOKEN = "{{projectId}}";
export interface StreamRequestOptions extends DecorateRequestOptions {

@@ -7,0 +8,0 @@ shouldReturnStream: true;

8

build/src/nodejs-common/service.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Service = void 0;
exports.Service = exports.DEFAULT_PROJECT_ID_TOKEN = void 0;
/*!

@@ -23,3 +23,3 @@ * Copyright 2022 Google LLC. All Rights Reserved.

const util_1 = require("./util");
const PROJECT_ID_TOKEN = '{{projectId}}';
exports.DEFAULT_PROJECT_ID_TOKEN = '{{projectId}}';
class Service {

@@ -48,3 +48,3 @@ /**

this.packageJson = config.packageJson;
this.projectId = options.projectId || PROJECT_ID_TOKEN;
this.projectId = options.projectId || exports.DEFAULT_PROJECT_ID_TOKEN;
this.projectIdRequired = config.projectIdRequired !== false;

@@ -94,3 +94,3 @@ this.providedUserAgent = options.userAgent;

const projectId = await this.authClient.getProjectId();
if (this.projectId === PROJECT_ID_TOKEN && projectId) {
if (this.projectId === exports.DEFAULT_PROJECT_ID_TOKEN && projectId) {
this.projectId = projectId;

@@ -97,0 +97,0 @@ }

@@ -87,2 +87,6 @@ /*!

authClient?: AuthClient | GoogleAuth;
/**
* Determines if a projectId is required for authenticated requests. Defaults to `true`.
*/
projectIdRequired?: boolean;
}

@@ -89,0 +93,0 @@ export interface MakeAuthenticatedRequestOptions {

@@ -30,2 +30,3 @@ "use strict";

const uuid = require("uuid");
const service_1 = require("./service");
const packageJson = require('../../../package.json');

@@ -327,3 +328,3 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires

const googleAutoAuthConfig = extend({}, config);
if (googleAutoAuthConfig.projectId === '{{projectId}}') {
if (googleAutoAuthConfig.projectId === service_1.DEFAULT_PROJECT_ID_TOKEN) {
delete googleAutoAuthConfig.projectId;

@@ -355,3 +356,6 @@ }

const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : undefined;
const onAuthenticated = (err, authenticatedReqOpts) => {
async function setProjectId() {
projectId = await authClient.getProjectId();
}
const onAuthenticated = async (err, authenticatedReqOpts) => {
const authLibraryError = err;

@@ -367,2 +371,3 @@ const autoAuthFailed = err &&

try {
// Try with existing `projectId` value
authenticatedReqOpts = util.decorateRequest(authenticatedReqOpts, projectId);

@@ -372,6 +377,20 @@ err = null;

catch (e) {
// A projectId was required, but we don't have one.
// Re-use the "Could not load the default credentials error" if
// auto auth failed.
err = err || e;
if (e instanceof projectify_1.MissingProjectIdError) {
// A `projectId` was required, but we don't have one.
try {
// Attempt to get the `projectId`
await setProjectId();
authenticatedReqOpts = util.decorateRequest(authenticatedReqOpts, projectId);
err = null;
}
catch (e) {
// Re-use the "Could not load the default credentials error" if
// auto auth failed.
err = err || e;
}
}
else {
// Some other error unrelated to missing `projectId`
err = err || e;
}
}

@@ -407,19 +426,42 @@ }

};
Promise.all([
config.projectId && config.projectId !== '{{projectId}}'
? // The user provided a project ID. We don't need to check with the
// auth client, it could be incorrect.
new Promise(resolve => resolve(config.projectId))
: authClient.getProjectId(),
reqConfig.customEndpoint && reqConfig.useAuthWithCustomEndpoint !== true
? // Using a custom API override. Do not use `google-auth-library` for
// authentication. (ex: connecting to a local Datastore server)
new Promise(resolve => resolve(reqOpts))
: authClient.authorizeRequest(reqOpts),
])
.then(([_projectId, authorizedReqOpts]) => {
projectId = _projectId;
onAuthenticated(null, authorizedReqOpts);
})
.catch(onAuthenticated);
const prepareRequest = async () => {
try {
const getProjectId = async () => {
if (config.projectId &&
config.projectId !== service_1.DEFAULT_PROJECT_ID_TOKEN) {
// The user provided a project ID. We don't need to check with the
// auth client, it could be incorrect.
return config.projectId;
}
if (config.projectIdRequired === false) {
// A projectId is not required. Return the default.
return service_1.DEFAULT_PROJECT_ID_TOKEN;
}
return setProjectId();
};
const authorizeRequest = async () => {
if (reqConfig.customEndpoint &&
!reqConfig.useAuthWithCustomEndpoint) {
// Using a custom API override. Do not use `google-auth-library` for
// authentication. (ex: connecting to a local Datastore server)
return reqOpts;
}
else {
return authClient.authorizeRequest(reqOpts);
}
};
const [_projectId, authorizedReqOpts] = await Promise.all([
getProjectId(),
authorizeRequest(),
]);
if (_projectId) {
projectId = _projectId;
}
return onAuthenticated(null, authorizedReqOpts);
}
catch (e) {
return onAuthenticated(e);
}
};
prepareRequest();
if (stream) {

@@ -426,0 +468,0 @@ return stream;

{
"name": "@google-cloud/storage",
"description": "Cloud Storage Client Library for Node.js",
"version": "6.1.0",
"version": "6.2.0",
"license": "Apache-2.0",

@@ -54,3 +54,3 @@ "author": "Google Inc.",

"@google-cloud/paginator": "^3.0.7",
"@google-cloud/projectify": "^2.0.0",
"@google-cloud/projectify": "^3.0.0",
"@google-cloud/promisify": "^3.0.0",

@@ -76,3 +76,3 @@ "abort-controller": "^3.0.0",

"devDependencies": {
"@google-cloud/pubsub": "^2.0.0",
"@google-cloud/pubsub": "^3.0.0",
"@grpc/grpc-js": "^1.0.3",

@@ -101,4 +101,4 @@ "@grpc/proto-loader": "^0.6.0",

"jsdoc": "^3.6.2",
"jsdoc-fresh": "^1.0.1",
"jsdoc-region-tag": "^1.0.2",
"jsdoc-fresh": "^2.0.0",
"jsdoc-region-tag": "^2.0.0",
"linkinator": "^2.0.0",

@@ -105,0 +105,0 @@ "mocha": "^9.2.2",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc