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 7.7.0 to 7.8.0

5

build/cjs/src/bucket.d.ts

@@ -14,3 +14,3 @@ /// <reference types="node" />

import { Storage, Cors, PreconditionOptions, BucketOptions } from './storage.js';
import { GetSignedUrlResponse, GetSignedUrlCallback, URLSigner, Query } from './signer.js';
import { GetSignedUrlResponse, GetSignedUrlCallback, SignerGetSignedUrlConfig, URLSigner, Query } from './signer.js';
import { Readable } from 'stream';

@@ -82,2 +82,3 @@ import { CRC32CValidatorGenerator } from './crc32c.js';

endOffset?: string;
includeFoldersAsPrefixes?: boolean;
includeTrailingDelimiter?: boolean;

@@ -243,3 +244,3 @@ prefix?: string;

}
export interface GetBucketSignedUrlConfig {
export interface GetBucketSignedUrlConfig extends Pick<SignerGetSignedUrlConfig, 'host' | 'signingEndpoint'> {
action: 'list';

@@ -246,0 +247,0 @@ version?: 'v2' | 'v4';

16

build/cjs/src/file.d.ts

@@ -12,3 +12,3 @@ /// <reference types="node" />

import { Acl, AclMetadata } from './acl.js';
import { GetSignedUrlResponse, GetSignedUrlCallback, URLSigner, Query } from './signer.js';
import { GetSignedUrlResponse, GetSignedUrlCallback, URLSigner, SignerGetSignedUrlConfig, Query } from './signer.js';
import { Duplexify, GCCL_GCS_CMD_KEY } from './nodejs-common/util.js';

@@ -44,2 +44,7 @@ import { CRC32C, CRC32CValidatorGenerator } from './crc32c.js';

};
/**
* @example
* 'https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/'
*/
signingEndpoint?: string;
}

@@ -55,2 +60,7 @@ export interface PolicyFields {

fields?: PolicyFields;
/**
* @example
* 'https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/'
*/
signingEndpoint?: string;
}

@@ -65,3 +75,3 @@ export interface GenerateSignedPostPolicyV4Callback {

}
export interface GetSignedUrlConfig {
export interface GetSignedUrlConfig extends Pick<SignerGetSignedUrlConfig, 'host' | 'signingEndpoint'> {
action: 'read' | 'write' | 'delete' | 'resumable';

@@ -178,3 +188,3 @@ version?: 'v2' | 'v4';

/**
* @private
* @deprecated - no longer used
*/

@@ -181,0 +191,0 @@ export declare const STORAGE_POST_POLICY_BASE_URL = "https://storage.googleapis.com";

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

authClient?: AuthClient | GoogleAuth;
/**
* Set to true if the endpoint is a custom URL
*/
customEndpoint?: boolean;
}

@@ -65,5 +69,6 @@ export interface ServiceOptions extends Omit<GoogleAuthOptions, 'authClient'> {

authClient: GoogleAuth<AuthClient>;
private getCredentials;
readonly apiEndpoint: string;
apiEndpoint: string;
timeout?: number;
universeDomain: string;
customEndpoint: boolean;
/**

@@ -70,0 +75,0 @@ * Service is a base class, meant to be inherited from by a "service," like

@@ -27,2 +27,18 @@ "use strict";

exports.Service = exports.DEFAULT_PROJECT_ID_TOKEN = void 0;
/*!
* Copyright 2022 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const google_auth_library_1 = require("google-auth-library");
const uuid = __importStar(require("uuid"));

@@ -60,3 +76,5 @@ const util_js_1 = require("./util.js");

this.providedUserAgent = options.userAgent;
const reqCfg = {
this.universeDomain = options.universeDomain || google_auth_library_1.DEFAULT_UNIVERSE;
this.customEndpoint = config.customEndpoint || false;
this.makeAuthenticatedRequest = util_js_1.util.makeAuthenticatedRequestFactory({
...config,

@@ -69,8 +87,8 @@ projectIdRequired: this.projectIdRequired,

email: options.email,
token: options.token,
};
this.makeAuthenticatedRequest =
util_js_1.util.makeAuthenticatedRequestFactory(reqCfg);
clientOptions: {
universeDomain: options.universeDomain,
...options.clientOptions,
},
});
this.authClient = this.makeAuthenticatedRequest.authClient;
this.getCredentials = this.makeAuthenticatedRequest.getCredentials;
const isCloudFunctionEnv = !!process.env.FUNCTION_NAME;

@@ -77,0 +95,0 @@ if (isCloudFunctionEnv) {

@@ -91,3 +91,3 @@ /*!

* A pre-instantiated `AuthClient` or `GoogleAuth` client that should be used.
* A new will be created if this is not set.
* A new client will be created if this is not set.
*/

@@ -94,0 +94,0 @@ authClient?: AuthClient | GoogleAuth;

@@ -382,8 +382,8 @@ "use strict";

else {
// Pass an `AuthClient` to `GoogleAuth`, if available
const config = {
// Pass an `AuthClient` & `clientOptions` to `GoogleAuth`, if available
authClient = new google_auth_library_1.GoogleAuth({
...googleAutoAuthConfig,
authClient: googleAutoAuthConfig.authClient,
};
authClient = new google_auth_library_1.GoogleAuth(config);
clientOptions: googleAutoAuthConfig.clientOptions,
});
}

@@ -390,0 +390,0 @@ function makeAuthenticatedRequest(reqOpts, optionsOrCallback) {

@@ -31,5 +31,6 @@ /// <reference types="node" />

* Defaults to `storage.googleapis.com`.
*
* **Warning**:
* If this value does not match the pattern *.googleapis.com,
* an emulator context will be assumed and authentication will be bypassed.
* If this value does not match the current GCP universe an emulator context
* will be assumed and authentication will be bypassed.
*/

@@ -147,2 +148,6 @@ apiEndpoint?: string;

/**
* The service domain for a given Cloud universe.
*/
universeDomain?: string;
/**
* If you already have a resumable URI from a previously-created resumable

@@ -149,0 +154,0 @@ * upload, just pass it in here and we'll use that.

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

const RESUMABLE_INCOMPLETE_STATUS_CODE = 308;
const DEFAULT_API_ENDPOINT_REGEX = /.*\.googleapis\.com/;
const packageJson = (0, package_json_helper_cjs_1.getPackageJSON)();

@@ -114,6 +113,21 @@ exports.PROTOCOL_REGEX = /^(\w*):\/\//;

this.authClient = cfg.authClient || new google_auth_library_1.GoogleAuth(cfg.authConfig);
this.apiEndpoint = 'https://storage.googleapis.com';
if (cfg.apiEndpoint) {
const universe = cfg.universeDomain || google_auth_library_1.DEFAULT_UNIVERSE;
this.apiEndpoint = `https://storage.${universe}`;
if (cfg.apiEndpoint && cfg.apiEndpoint !== this.apiEndpoint) {
this.apiEndpoint = this.sanitizeEndpoint(cfg.apiEndpoint);
if (!DEFAULT_API_ENDPOINT_REGEX.test(cfg.apiEndpoint)) {
const hostname = new URL(this.apiEndpoint).hostname;
// check if it is a domain of a known universe
const isDomain = hostname === universe;
const isDefaultUniverseDomain = hostname === google_auth_library_1.DEFAULT_UNIVERSE;
// check if it is a subdomain of a known universe
// by checking a last (universe's length + 1) of a hostname
const isSubDomainOfUniverse = hostname.slice(-(universe.length + 1)) === `.${universe}`;
const isSubDomainOfDefaultUniverse = hostname.slice(-(google_auth_library_1.DEFAULT_UNIVERSE.length + 1)) ===
`.${google_auth_library_1.DEFAULT_UNIVERSE}`;
if (!isDomain &&
!isDefaultUniverseDomain &&
!isSubDomainOfUniverse &&
!isSubDomainOfDefaultUniverse) {
// a custom, non-universe domain,
// use gaxios
this.authClient = gaxios;

@@ -120,0 +134,0 @@ }

/// <reference types="node" />
/// <reference types="node" />
import * as http from 'http';
interface GetCredentialsResponse {
client_email?: string;
}
import { Storage } from './storage.js';
import { GoogleAuth } from 'google-auth-library';
type GoogleAuthLike = Pick<GoogleAuth, 'getCredentials' | 'sign'>;
/**
* @deprecated Use {@link GoogleAuth} instead
*/
export interface AuthClient {
sign(blobToSign: string): Promise<string>;
getCredentials(): Promise<GetCredentialsResponse>;
getCredentials(): Promise<{
client_email?: string;
}>;
}

@@ -30,2 +36,16 @@ export interface BucketI {

file?: string;
/**
* The host for the generated signed URL
*
* @example
* 'https://localhost:8080/'
*/
host?: string | URL;
/**
* An endpoint for generating the signed URL
*
* @example
* 'https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/'
*/
signingEndpoint?: string | URL;
}

@@ -43,2 +63,16 @@ export interface SignerGetSignedUrlConfig {

contentType?: string;
/**
* The host for the generated signed URL
*
* @example
* 'https://localhost:8080/'
*/
host?: string | URL;
/**
* An endpoint for generating the signed URL
*
* @example
* 'https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/'
*/
signingEndpoint?: string | URL;
}

@@ -57,10 +91,30 @@ export type SignerGetSignedUrlResponse = string;

* @const {string}
* @private
* @deprecated - unused
*/
export declare const PATH_STYLED_HOST = "https://storage.googleapis.com";
export declare class URLSigner {
private authClient;
private auth;
private bucket;
private file?;
constructor(authClient: AuthClient, bucket: BucketI, file?: FileI);
/**
* A {@link Storage} object.
*
* @privateRemarks
*
* Technically this is a required field, however it would be a breaking change to
* move it before optional properties. In the next major we should refactor the
* constructor of this class to only accept a config object.
*/
private storage;
constructor(auth: AuthClient | GoogleAuthLike, bucket: BucketI, file?: FileI | undefined,
/**
* A {@link Storage} object.
*
* @privateRemarks
*
* Technically this is a required field, however it would be a breaking change to
* move it before optional properties. In the next major we should refactor the
* constructor of this class to only accept a config object.
*/
storage?: Storage);
getSignedUrl(cfg: SignerGetSignedUrlConfig): Promise<SignerGetSignedUrlResponse>;

@@ -67,0 +121,0 @@ private getSignedUrlV2;

@@ -57,10 +57,21 @@ "use strict";

* @const {string}
* @private
* @deprecated - unused
*/
exports.PATH_STYLED_HOST = 'https://storage.googleapis.com';
class URLSigner {
constructor(authClient, bucket, file) {
constructor(auth, bucket, file,
/**
* A {@link Storage} object.
*
* @privateRemarks
*
* Technically this is a required field, however it would be a breaking change to
* move it before optional properties. In the next major we should refactor the
* constructor of this class to only accept a config object.
*/
storage = new storage_js_1.Storage()) {
this.auth = auth;
this.bucket = bucket;
this.file = file;
this.authClient = authClient;
this.storage = storage;
}

@@ -81,3 +92,3 @@ getSignedUrl(cfg) {

else if (isVirtualHostedStyle) {
customHost = `https://${this.bucket.name}.storage.googleapis.com`;
customHost = `https://${this.bucket.name}.storage.${this.storage.universeDomain}`;
}

@@ -107,4 +118,5 @@ const secondsToMilliseconds = 1000;

return promise.then(query => {
var _a;
query = Object.assign(query, cfg.queryParams);
const signedUrl = new url.URL(config.cname || exports.PATH_STYLED_HOST);
const signedUrl = new url.URL(((_a = cfg.host) === null || _a === void 0 ? void 0 : _a.toString()) || config.cname || this.storage.apiEndpoint);
signedUrl.pathname = this.getResourcePath(!!config.cname, this.bucket.name, config.file);

@@ -127,6 +139,7 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any

const sign = async () => {
const authClient = this.authClient;
var _a;
const auth = this.auth;
try {
const signature = await authClient.sign(blobToSign);
const credentials = await authClient.getCredentials();
const signature = await auth.sign(blobToSign, (_a = config.signingEndpoint) === null || _a === void 0 ? void 0 : _a.toString());
const credentials = await auth.getCredentials();
return {

@@ -148,2 +161,3 @@ GoogleAccessId: credentials.client_email,

getSignedUrlV4(config) {
var _a;
config.accessibleAt = config.accessibleAt

@@ -159,4 +173,4 @@ ? config.accessibleAt

const extensionHeaders = Object.assign({}, config.extensionHeaders);
const fqdn = new url.URL(config.cname || exports.PATH_STYLED_HOST);
extensionHeaders.host = fqdn.host;
const fqdn = new url.URL(((_a = config.host) === null || _a === void 0 ? void 0 : _a.toString()) || config.cname || this.storage.apiEndpoint);
extensionHeaders.host = fqdn.hostname;
if (config.contentMd5) {

@@ -185,3 +199,4 @@ extensionHeaders['content-md5'] = config.contentMd5;

const sign = async () => {
const credentials = await this.authClient.getCredentials();
var _a;
const credentials = await this.auth.getCredentials();
const credential = `${credentials.client_email}/${credentialScope}`;

@@ -211,3 +226,3 @@ const dateISO = (0, util_js_1.formatAsUTCISO)(config.accessibleAt ? config.accessibleAt : new Date(), true);

try {
const signature = await this.authClient.sign(blobToSign);
const signature = await this.auth.sign(blobToSign, (_a = config.signingEndpoint) === null || _a === void 0 ? void 0 : _a.toString());
const signatureHex = Buffer.from(signature, 'base64').toString('hex');

@@ -214,0 +229,0 @@ const signedQuery = Object.assign({}, queryParams, {

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

const crc32c_js_1 = require("./crc32c.js");
const google_auth_library_1 = require("google-auth-library");
var IdempotencyStrategy;

@@ -459,3 +460,4 @@ (function (IdempotencyStrategy) {

var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
let apiEndpoint = 'https://storage.googleapis.com';
const universe = options.universeDomain || google_auth_library_1.DEFAULT_UNIVERSE;
let apiEndpoint = `https://storage.${universe}`;
let customEndpoint = false;

@@ -462,0 +464,0 @@ // Note: EMULATOR_HOST is an experimental configuration variable. Use apiEndpoint instead.

@@ -14,3 +14,3 @@ /// <reference types="node" />

import { Storage, Cors, PreconditionOptions, BucketOptions } from './storage.js';
import { GetSignedUrlResponse, GetSignedUrlCallback, URLSigner, Query } from './signer.js';
import { GetSignedUrlResponse, GetSignedUrlCallback, SignerGetSignedUrlConfig, URLSigner, Query } from './signer.js';
import { Readable } from 'stream';

@@ -82,2 +82,3 @@ import { CRC32CValidatorGenerator } from './crc32c.js';

endOffset?: string;
includeFoldersAsPrefixes?: boolean;
includeTrailingDelimiter?: boolean;

@@ -243,3 +244,3 @@ prefix?: string;

}
export interface GetBucketSignedUrlConfig {
export interface GetBucketSignedUrlConfig extends Pick<SignerGetSignedUrlConfig, 'host' | 'signingEndpoint'> {
action: 'list';

@@ -246,0 +247,0 @@ version?: 'v2' | 'v4';

@@ -12,3 +12,3 @@ /// <reference types="node" />

import { Acl, AclMetadata } from './acl.js';
import { GetSignedUrlResponse, GetSignedUrlCallback, URLSigner, Query } from './signer.js';
import { GetSignedUrlResponse, GetSignedUrlCallback, URLSigner, SignerGetSignedUrlConfig, Query } from './signer.js';
import { Duplexify, GCCL_GCS_CMD_KEY } from './nodejs-common/util.js';

@@ -44,2 +44,7 @@ import { CRC32C, CRC32CValidatorGenerator } from './crc32c.js';

};
/**
* @example
* 'https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/'
*/
signingEndpoint?: string;
}

@@ -55,2 +60,7 @@ export interface PolicyFields {

fields?: PolicyFields;
/**
* @example
* 'https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/'
*/
signingEndpoint?: string;
}

@@ -65,3 +75,3 @@ export interface GenerateSignedPostPolicyV4Callback {

}
export interface GetSignedUrlConfig {
export interface GetSignedUrlConfig extends Pick<SignerGetSignedUrlConfig, 'host' | 'signingEndpoint'> {
action: 'read' | 'write' | 'delete' | 'resumable';

@@ -178,3 +188,3 @@ version?: 'v2' | 'v4';

/**
* @private
* @deprecated - no longer used
*/

@@ -181,0 +191,0 @@ export declare const STORAGE_POST_POLICY_BASE_URL = "https://storage.googleapis.com";

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

authClient?: AuthClient | GoogleAuth;
/**
* Set to true if the endpoint is a custom URL
*/
customEndpoint?: boolean;
}

@@ -65,5 +69,6 @@ export interface ServiceOptions extends Omit<GoogleAuthOptions, 'authClient'> {

authClient: GoogleAuth<AuthClient>;
private getCredentials;
readonly apiEndpoint: string;
apiEndpoint: string;
timeout?: number;
universeDomain: string;
customEndpoint: boolean;
/**

@@ -70,0 +75,0 @@ * Service is a base class, meant to be inherited from by a "service," like

@@ -0,1 +1,17 @@

/*!
* Copyright 2022 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DEFAULT_UNIVERSE, } from 'google-auth-library';
import * as uuid from 'uuid';

@@ -33,3 +49,5 @@ import { GCCL_GCS_CMD_KEY, util, } from './util.js';

this.providedUserAgent = options.userAgent;
const reqCfg = {
this.universeDomain = options.universeDomain || DEFAULT_UNIVERSE;
this.customEndpoint = config.customEndpoint || false;
this.makeAuthenticatedRequest = util.makeAuthenticatedRequestFactory({
...config,

@@ -42,8 +60,8 @@ projectIdRequired: this.projectIdRequired,

email: options.email,
token: options.token,
};
this.makeAuthenticatedRequest =
util.makeAuthenticatedRequestFactory(reqCfg);
clientOptions: {
universeDomain: options.universeDomain,
...options.clientOptions,
},
});
this.authClient = this.makeAuthenticatedRequest.authClient;
this.getCredentials = this.makeAuthenticatedRequest.getCredentials;
const isCloudFunctionEnv = !!process.env.FUNCTION_NAME;

@@ -50,0 +68,0 @@ if (isCloudFunctionEnv) {

@@ -91,3 +91,3 @@ /*!

* A pre-instantiated `AuthClient` or `GoogleAuth` client that should be used.
* A new will be created if this is not set.
* A new client will be created if this is not set.
*/

@@ -94,0 +94,0 @@ authClient?: AuthClient | GoogleAuth;

@@ -351,8 +351,8 @@ /*!

else {
// Pass an `AuthClient` to `GoogleAuth`, if available
const config = {
// Pass an `AuthClient` & `clientOptions` to `GoogleAuth`, if available
authClient = new GoogleAuth({
...googleAutoAuthConfig,
authClient: googleAutoAuthConfig.authClient,
};
authClient = new GoogleAuth(config);
clientOptions: googleAutoAuthConfig.clientOptions,
});
}

@@ -359,0 +359,0 @@ function makeAuthenticatedRequest(reqOpts, optionsOrCallback) {

@@ -31,5 +31,6 @@ /// <reference types="node" />

* Defaults to `storage.googleapis.com`.
*
* **Warning**:
* If this value does not match the pattern *.googleapis.com,
* an emulator context will be assumed and authentication will be bypassed.
* If this value does not match the current GCP universe an emulator context
* will be assumed and authentication will be bypassed.
*/

@@ -147,2 +148,6 @@ apiEndpoint?: string;

/**
* The service domain for a given Cloud universe.
*/
universeDomain?: string;
/**
* If you already have a resumable URI from a previously-created resumable

@@ -149,0 +154,0 @@ * upload, just pass it in here and we'll use that.

@@ -29,3 +29,3 @@ // Copyright 2022 Google LLC

import * as gaxios from 'gaxios';
import { GoogleAuth } from 'google-auth-library';
import { DEFAULT_UNIVERSE, GoogleAuth, } from 'google-auth-library';
import { Readable, Writable } from 'stream';

@@ -41,3 +41,2 @@ import AsyncRetry from 'async-retry';

const RESUMABLE_INCOMPLETE_STATUS_CODE = 308;
const DEFAULT_API_ENDPOINT_REGEX = /.*\.googleapis\.com/;
const packageJson = getPackageJSON();

@@ -86,6 +85,21 @@ export const PROTOCOL_REGEX = /^(\w*):\/\//;

this.authClient = cfg.authClient || new GoogleAuth(cfg.authConfig);
this.apiEndpoint = 'https://storage.googleapis.com';
if (cfg.apiEndpoint) {
const universe = cfg.universeDomain || DEFAULT_UNIVERSE;
this.apiEndpoint = `https://storage.${universe}`;
if (cfg.apiEndpoint && cfg.apiEndpoint !== this.apiEndpoint) {
this.apiEndpoint = this.sanitizeEndpoint(cfg.apiEndpoint);
if (!DEFAULT_API_ENDPOINT_REGEX.test(cfg.apiEndpoint)) {
const hostname = new URL(this.apiEndpoint).hostname;
// check if it is a domain of a known universe
const isDomain = hostname === universe;
const isDefaultUniverseDomain = hostname === DEFAULT_UNIVERSE;
// check if it is a subdomain of a known universe
// by checking a last (universe's length + 1) of a hostname
const isSubDomainOfUniverse = hostname.slice(-(universe.length + 1)) === `.${universe}`;
const isSubDomainOfDefaultUniverse = hostname.slice(-(DEFAULT_UNIVERSE.length + 1)) ===
`.${DEFAULT_UNIVERSE}`;
if (!isDomain &&
!isDefaultUniverseDomain &&
!isSubDomainOfUniverse &&
!isSubDomainOfDefaultUniverse) {
// a custom, non-universe domain,
// use gaxios
this.authClient = gaxios;

@@ -92,0 +106,0 @@ }

/// <reference types="node" />
/// <reference types="node" />
import * as http from 'http';
interface GetCredentialsResponse {
client_email?: string;
}
import { Storage } from './storage.js';
import { GoogleAuth } from 'google-auth-library';
type GoogleAuthLike = Pick<GoogleAuth, 'getCredentials' | 'sign'>;
/**
* @deprecated Use {@link GoogleAuth} instead
*/
export interface AuthClient {
sign(blobToSign: string): Promise<string>;
getCredentials(): Promise<GetCredentialsResponse>;
getCredentials(): Promise<{
client_email?: string;
}>;
}

@@ -30,2 +36,16 @@ export interface BucketI {

file?: string;
/**
* The host for the generated signed URL
*
* @example
* 'https://localhost:8080/'
*/
host?: string | URL;
/**
* An endpoint for generating the signed URL
*
* @example
* 'https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/'
*/
signingEndpoint?: string | URL;
}

@@ -43,2 +63,16 @@ export interface SignerGetSignedUrlConfig {

contentType?: string;
/**
* The host for the generated signed URL
*
* @example
* 'https://localhost:8080/'
*/
host?: string | URL;
/**
* An endpoint for generating the signed URL
*
* @example
* 'https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/'
*/
signingEndpoint?: string | URL;
}

@@ -57,10 +91,30 @@ export type SignerGetSignedUrlResponse = string;

* @const {string}
* @private
* @deprecated - unused
*/
export declare const PATH_STYLED_HOST = "https://storage.googleapis.com";
export declare class URLSigner {
private authClient;
private auth;
private bucket;
private file?;
constructor(authClient: AuthClient, bucket: BucketI, file?: FileI);
/**
* A {@link Storage} object.
*
* @privateRemarks
*
* Technically this is a required field, however it would be a breaking change to
* move it before optional properties. In the next major we should refactor the
* constructor of this class to only accept a config object.
*/
private storage;
constructor(auth: AuthClient | GoogleAuthLike, bucket: BucketI, file?: FileI | undefined,
/**
* A {@link Storage} object.
*
* @privateRemarks
*
* Technically this is a required field, however it would be a breaking change to
* move it before optional properties. In the next major we should refactor the
* constructor of this class to only accept a config object.
*/
storage?: Storage);
getSignedUrl(cfg: SignerGetSignedUrlConfig): Promise<SignerGetSignedUrlResponse>;

@@ -67,0 +121,0 @@ private getSignedUrlV2;

@@ -16,3 +16,3 @@ // Copyright 2020 Google LLC

import * as url from 'url';
import { ExceptionMessages } from './storage.js';
import { ExceptionMessages, Storage } from './storage.js';
import { encodeURI, qsStringify, objectEntries, formatAsUTCISO } from './util.js';

@@ -32,10 +32,21 @@ export var SignerExceptionMessages;

* @const {string}
* @private
* @deprecated - unused
*/
export const PATH_STYLED_HOST = 'https://storage.googleapis.com';
export class URLSigner {
constructor(authClient, bucket, file) {
constructor(auth, bucket, file,
/**
* A {@link Storage} object.
*
* @privateRemarks
*
* Technically this is a required field, however it would be a breaking change to
* move it before optional properties. In the next major we should refactor the
* constructor of this class to only accept a config object.
*/
storage = new Storage()) {
this.auth = auth;
this.bucket = bucket;
this.file = file;
this.authClient = authClient;
this.storage = storage;
}

@@ -56,3 +67,3 @@ getSignedUrl(cfg) {

else if (isVirtualHostedStyle) {
customHost = `https://${this.bucket.name}.storage.googleapis.com`;
customHost = `https://${this.bucket.name}.storage.${this.storage.universeDomain}`;
}

@@ -82,4 +93,5 @@ const secondsToMilliseconds = 1000;

return promise.then(query => {
var _a;
query = Object.assign(query, cfg.queryParams);
const signedUrl = new url.URL(config.cname || PATH_STYLED_HOST);
const signedUrl = new url.URL(((_a = cfg.host) === null || _a === void 0 ? void 0 : _a.toString()) || config.cname || this.storage.apiEndpoint);
signedUrl.pathname = this.getResourcePath(!!config.cname, this.bucket.name, config.file);

@@ -102,6 +114,7 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any

const sign = async () => {
const authClient = this.authClient;
var _a;
const auth = this.auth;
try {
const signature = await authClient.sign(blobToSign);
const credentials = await authClient.getCredentials();
const signature = await auth.sign(blobToSign, (_a = config.signingEndpoint) === null || _a === void 0 ? void 0 : _a.toString());
const credentials = await auth.getCredentials();
return {

@@ -123,2 +136,3 @@ GoogleAccessId: credentials.client_email,

getSignedUrlV4(config) {
var _a;
config.accessibleAt = config.accessibleAt

@@ -134,4 +148,4 @@ ? config.accessibleAt

const extensionHeaders = Object.assign({}, config.extensionHeaders);
const fqdn = new url.URL(config.cname || PATH_STYLED_HOST);
extensionHeaders.host = fqdn.host;
const fqdn = new url.URL(((_a = config.host) === null || _a === void 0 ? void 0 : _a.toString()) || config.cname || this.storage.apiEndpoint);
extensionHeaders.host = fqdn.hostname;
if (config.contentMd5) {

@@ -160,3 +174,4 @@ extensionHeaders['content-md5'] = config.contentMd5;

const sign = async () => {
const credentials = await this.authClient.getCredentials();
var _a;
const credentials = await this.auth.getCredentials();
const credential = `${credentials.client_email}/${credentialScope}`;

@@ -186,3 +201,3 @@ const dateISO = formatAsUTCISO(config.accessibleAt ? config.accessibleAt : new Date(), true);

try {
const signature = await this.authClient.sign(blobToSign);
const signature = await this.auth.sign(blobToSign, (_a = config.signingEndpoint) === null || _a === void 0 ? void 0 : _a.toString());
const signatureHex = Buffer.from(signature, 'base64').toString('hex');

@@ -189,0 +204,0 @@ const signedQuery = Object.assign({}, queryParams, {

@@ -27,2 +27,3 @@ // Copyright 2019 Google LLC

import { CRC32C_DEFAULT_VALIDATOR_GENERATOR, } from './crc32c.js';
import { DEFAULT_UNIVERSE } from 'google-auth-library';
export var IdempotencyStrategy;

@@ -455,3 +456,4 @@ (function (IdempotencyStrategy) {

var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
let apiEndpoint = 'https://storage.googleapis.com';
const universe = options.universeDomain || DEFAULT_UNIVERSE;
let apiEndpoint = `https://storage.${universe}`;
let customEndpoint = false;

@@ -458,0 +460,0 @@ // Note: EMULATOR_HOST is an experimental configuration variable. Use apiEndpoint instead.

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

@@ -81,7 +81,7 @@ "author": "Google Inc.",

"compressible": "^2.0.12",
"duplexify": "^4.0.0",
"duplexify": "^4.1.3",
"ent": "^2.2.0",
"fast-xml-parser": "^4.3.0",
"gaxios": "^6.0.2",
"google-auth-library": "^9.0.0",
"google-auth-library": "^9.6.3",
"mime": "^3.0.0",

@@ -115,5 +115,5 @@ "mime-types": "^2.0.8",

"@types/yargs": "^17.0.10",
"c8": "^8.0.0",
"c8": "^9.0.0",
"form-data": "^4.0.0",
"gapic-tools": "^0.2.0",
"gapic-tools": "^0.4.0",
"gts": "^5.0.0",

@@ -126,3 +126,3 @@ "jsdoc": "^4.0.0",

"mockery": "^2.1.0",
"nock": "~13.4.0",
"nock": "~13.5.0",
"node-fetch": "^2.6.7",

@@ -129,0 +129,0 @@ "pack-n-play": "^2.0.0",

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

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