Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@google-cloud/common

Package Overview
Dependencies
Maintainers
4
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/common - npm Package Compare versions

Comparing version 0.27.0 to 0.28.0

2

build/src/index.d.ts

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

*/
export { DeleteCallback, ExistsCallback, GetConfig, GetMetadataCallback, InstanceResponseCallback, Interceptor, Metadata, Methods, ResponseCallback, ServiceObject, ServiceObjectConfig, ServiceObjectParent, SetMetadataResponse } from './service-object';
export { DeleteCallback, ExistsCallback, GetConfig, InstanceResponseCallback, Interceptor, Metadata, MetadataCallback, MetadataResponse, Methods, ResponseCallback, ServiceObject, ServiceObjectConfig, ServiceObjectParent, SetMetadataResponse } from './service-object';
/**

@@ -34,0 +34,0 @@ * @type {module:common/util}

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

*/
import { GetMetadataCallback, ServiceObject, ServiceObjectConfig } from './service-object';
import { MetadataCallback, ServiceObject, ServiceObjectConfig } from './service-object';
export declare class Operation<T = any> extends ServiceObject<T> {

@@ -55,3 +55,3 @@ completeListeners: number;

*/
protected poll_(callback: GetMetadataCallback): void;
protected poll_(callback: MetadataCallback): void;
/**

@@ -58,0 +58,0 @@ * Poll `getMetadata` to check the operation's status. This runs a loop to

@@ -19,16 +19,16 @@ /*!

import * as r from 'request';
import { StreamRequestOptions } from '.';
import { ApiError, BodyResponseCallback, DecorateRequestOptions } from './util';
export declare type CreateOptions = {};
export declare type RequestResponse = [Metadata, r.Response];
export interface ServiceObjectParent {
Promise?: PromiseConstructor;
requestStream(reqOpts: DecorateRequestOptions): r.Request;
request(reqOpts: DecorateRequestOptions): Promise<r.Response>;
request(reqOpts: DecorateRequestOptions, callback: BodyResponseCallback): void;
}
export interface Interceptor {
[index: string]: any;
request(opts: r.Options): DecorateRequestOptions;
}
export declare type Metadata = any;
export declare type GetMetadataCallback = (err: Error | null, metadata?: Metadata | null, apiResponse?: r.Response) => void;
export declare type MetadataResponse = [Metadata, r.Response];
export declare type MetadataCallback = (err: Error | null, metadata?: Metadata, apiResponse?: r.Response) => void;
export interface ExistsCallback {

@@ -89,3 +89,3 @@ (err: Error | null, exists?: boolean): void;

}
export declare type SetMetadataResponse = [r.Response];
export declare type SetMetadataResponse = [Metadata];
export declare type GetResponse<T> = [T, r.Response];

@@ -167,4 +167,4 @@ /**

*/
getMetadata(): Promise<Metadata>;
getMetadata(callback: GetMetadataCallback): void;
getMetadata(): Promise<MetadataResponse>;
getMetadata(callback: MetadataCallback): void;
/**

@@ -179,3 +179,3 @@ * Set the metadata for this object.

setMetadata(metadata: Metadata): Promise<SetMetadataResponse>;
setMetadata(metadata: Metadata, callback: ResponseCallback): void;
setMetadata(metadata: Metadata, callback: MetadataCallback): void;
/**

@@ -190,4 +190,3 @@ * Make an authenticated API request.

*/
request_(reqOpts: StreamRequestOptions): r.Request;
request_(reqOpts: DecorateRequestOptions): Promise<r.Response>;
private request_;
/**

@@ -202,3 +201,3 @@ * Make an authenticated API request.

*/
request(reqOpts: DecorateRequestOptions): Promise<r.Response>;
request(reqOpts: DecorateRequestOptions): Promise<RequestResponse>;
request(reqOpts: DecorateRequestOptions, callback: BodyResponseCallback): void;

@@ -205,0 +204,0 @@ /**

@@ -101,4 +101,5 @@ "use strict";

// newly-created one.
function onCreate(err, instance) {
const args = [].slice.call(arguments);
// tslint: disable-next-line no-any
function onCreate(...args) {
const [err, instance] = args;
if (!err) {

@@ -108,3 +109,3 @@ self.metadata = instance.metadata;

}
callback.apply(null, args);
callback(...args);
}

@@ -123,3 +124,3 @@ args.push(onCreate);

// behavior. Ensure we call the original `request` method.
this.request(reqOpts).then(res => callback(null, res), callback);
this.request(reqOpts, callback);
}

@@ -172,3 +173,3 @@ exists(callback) {

args.push(onCreate);
self.create.apply(self, args);
self.create(...args);
return;

@@ -186,14 +187,11 @@ }

{};
const reqOpts = extend({
uri: '',
}, methodConfig.reqOpts);
const reqOpts = extend({ uri: '' }, methodConfig.reqOpts);
// The `request` method may have been overridden to hold any special
// behavior. Ensure we call the original `request` method.
this.request(reqOpts).then(resp => {
this.metadata = resp.body;
callback(null, this.metadata, resp);
}, callback);
this.request(reqOpts, (err, body, res) => {
this.metadata = body;
callback(err, this.metadata, res);
});
}
setMetadata(metadata, callback) {
const self = this;
callback = callback || util_1.util.noop;

@@ -210,8 +208,8 @@ const methodConfig = (typeof this.methods.setMetadata === 'object' &&

// behavior. Ensure we call the original `request` method.
this.request(reqOpts).then((resp) => {
self.metadata = resp;
callback(null, resp);
}, callback);
this.request(reqOpts, (err, body, res) => {
this.metadata = body;
callback(err, this.metadata, res);
});
}
request_(reqOpts) {
request_(reqOpts, callback) {
reqOpts = extend(true, {}, reqOpts);

@@ -236,9 +234,6 @@ const isAbsoluteUrl = reqOpts.uri.indexOf('http') === 0;

}
return this.parent.request(reqOpts);
this.parent.request(reqOpts, callback);
}
request(reqOpts, callback) {
if (!callback) {
return this.request_(reqOpts);
}
this.request_(reqOpts).then(res => callback(null, res.body, res), err => callback(err, err.response ? err.response.body : null, err.response));
this.request_(reqOpts, callback);
}

@@ -259,3 +254,3 @@ /**

exports.ServiceObject = ServiceObject;
promisify_1.promisifyAll(ServiceObject, { exclude: ['requestStream', 'request', 'request_'] });
promisify_1.promisifyAll(ServiceObject);
//# sourceMappingURL=service-object.js.map

@@ -16,4 +16,5 @@ /*!

*/
import { GoogleAuth } from 'google-auth-library';
import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';
import * as r from 'request';
import { Interceptor } from './service-object';
import { BodyResponseCallback, DecorateRequestOptions, MakeAuthenticatedRequest, PackageJson } from './util';

@@ -35,9 +36,10 @@ export interface StreamRequestOptions extends DecorateRequestOptions {

requestModule: typeof r;
/**
* Reuse an existing GoogleAuth client instead of creating a new one.
*/
authClient?: GoogleAuth;
}
export interface ServiceOptions {
interceptors_?: {};
projectId?: string;
export interface ServiceOptions extends GoogleAuthOptions {
interceptors_?: Interceptor[];
promise?: PromiseConstructor;
credentials?: {};
keyFilename?: string;
email?: string;

@@ -91,4 +93,3 @@ token?: string;

*/
request_(reqOpts: StreamRequestOptions): r.Request;
request_(reqOpts: DecorateRequestOptions): Promise<r.Response>;
private request_;
/**

@@ -103,3 +104,2 @@ * Make an authenticated API request.

*/
request(reqOpts: DecorateRequestOptions): Promise<r.Response>;
request(reqOpts: DecorateRequestOptions, callback: BodyResponseCallback): void;

@@ -106,0 +106,0 @@ /**

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

const extend = require("extend");
const pify = require("pify");
const util_1 = require("./util");

@@ -99,4 +98,3 @@ const PROJECT_ID_TOKEN = '{{projectId}}';

}
request_(reqOpts) {
// TODO: fix the tests so this can be private
request_(reqOpts, callback) {
reqOpts = extend(true, {}, reqOpts);

@@ -124,3 +122,4 @@ const isAbsoluteUrl = reqOpts.uri.indexOf('http') === 0;

// Interceptors should be called in the order they were assigned.
const combinedInterceptors = [].slice.call(this.globalInterceptors)
const combinedInterceptors = []
.slice.call(this.globalInterceptors)
.concat(this.interceptors)

@@ -141,32 +140,19 @@ .concat(arrify(reqOpts.interceptors_));

if (reqOpts.shouldReturnStream) {
// tslint:disable-next-line:no-any
return this.makeAuthenticatedRequest(reqOpts);
}
else {
return pify(this.makeAuthenticatedRequest, { multiArgs: true })(reqOpts)
.then(args => {
/**
* Note: this returns an array of results in the form of a
* BodyResponseCallback, which means: [body, response]. Return
* the response object in the promise result.
*/
return args.length > 1 ? args[1] : null;
}, e => {
if (Array.isArray(e) && e.length > 0) {
const [err, body, res] = e;
if (res) {
res.body = err;
err.response = res;
}
throw err;
}
throw e;
});
this.makeAuthenticatedRequest(reqOpts, callback);
}
}
/**
* Make an authenticated API request.
*
* @private
*
* @param {object} reqOpts - Request options that are passed to `request`.
* @param {string} reqOpts.uri - A URI relative to the baseUrl.
* @param {function} callback - The callback function passed to `request`.
*/
request(reqOpts, callback) {
if (!callback) {
return this.request_(reqOpts);
}
this.request_(reqOpts).then(res => callback(null, res.body, res), err => callback(err, err.response ? err.response.body : undefined, err.response));
this.request_(reqOpts, callback);
}

@@ -173,0 +159,0 @@ /**

@@ -64,2 +64,7 @@ /**

request: typeof r;
/**
* A pre-instantiated GoogleAuth client that should be used.
* A new will be created if this is not set.
*/
authClient?: GoogleAuth;
}

@@ -274,4 +279,12 @@ export interface MakeAuthenticatedRequestOptions {

getUserAgentFromPackageJson(packageJson: PackageJson): string;
/**
* Given two parameters, figure out if this is either:
* - Just a callback function
* - An options object, and then a callback function
* @param optionsOrCallback An options object or callback.
* @param cb A potentially undefined callback.
*/
maybeOptionsOrCallback<T = {}, C = (err?: Error) => void>(optionsOrCallback?: T | C, cb?: C): [T, C];
}
declare const util: Util;
export { util };

@@ -282,3 +282,3 @@ "use strict";

}
const authClient = new google_auth_library_1.GoogleAuth(googleAutoAuthConfig);
const authClient = googleAutoAuthConfig.authClient || new google_auth_library_1.GoogleAuth(googleAutoAuthConfig);
function makeAuthenticatedRequest(reqOpts, optionsOrCallback) {

@@ -490,2 +490,14 @@ let stream;

}
/**
* Given two parameters, figure out if this is either:
* - Just a callback function
* - An options object, and then a callback function
* @param optionsOrCallback An options object or callback.
* @param cb A potentially undefined callback.
*/
maybeOptionsOrCallback(optionsOrCallback, cb) {
return typeof optionsOrCallback === 'function' ?
[{}, optionsOrCallback] :
[optionsOrCallback, cb];
}
}

@@ -492,0 +504,0 @@ exports.Util = Util;

@@ -7,2 +7,33 @@ # Changelog

## v0.28.0
12-13-2018 14:34 PST
**This release has breaking changes**. The signature of the protected `request` method on `ServiceObject` has been changed. The method now resolves with an array of `[Body, Response]`, making it consistent with all other promisified methods. This change was made to fix several breaking changes that occurred in the `0.18.0` release.
### New Features
- feat: allow passing GoogleAuth client to Service ([#314](https://github.com/googleapis/nodejs-common/pull/314))
- feat: add maybeOptionsOrCallback util method ([#315](https://github.com/googleapis/nodejs-common/pull/315))
### Bug Fixes
- fix: revert async behavior of request ([#331](https://github.com/googleapis/nodejs-common/pull/331))
### Documentation
- docs: update readme badges ([#316](https://github.com/googleapis/nodejs-common/pull/316))
### Internal / Testing Changes
- chore(deps): update dependency @types/sinon to v7 ([#332](https://github.com/googleapis/nodejs-common/pull/332))
- chore(build): inject yoshi automation key ([#330](https://github.com/googleapis/nodejs-common/pull/330))
- chore: update nyc and eslint configs ([#329](https://github.com/googleapis/nodejs-common/pull/329))
- chore: fix publish.sh permission +x ([#327](https://github.com/googleapis/nodejs-common/pull/327))
- fix(build): fix Kokoro release script ([#326](https://github.com/googleapis/nodejs-common/pull/326))
- build: add Kokoro configs for autorelease ([#325](https://github.com/googleapis/nodejs-common/pull/325))
- chore: always nyc report before calling codecov ([#322](https://github.com/googleapis/nodejs-common/pull/322))
- chore: nyc ignore build/test by default ([#321](https://github.com/googleapis/nodejs-common/pull/321))
- chore(build): update the prettier config ([#319](https://github.com/googleapis/nodejs-common/pull/319))
- chore: update license file ([#318](https://github.com/googleapis/nodejs-common/pull/318))
- fix(build): fix system key decryption ([#313](https://github.com/googleapis/nodejs-common/pull/313))
- chore(deps): update dependency @types/sinon to v5.0.7 ([#308](https://github.com/googleapis/nodejs-common/pull/308))
- chore(deps): update dependency typescript to ~3.2.0 ([#312](https://github.com/googleapis/nodejs-common/pull/312))
## v0.27.0

@@ -9,0 +40,0 @@

{
"name": "@google-cloud/common",
"description": "Common components for Cloud APIs Node.js Client Libraries",
"version": "0.27.0",
"version": "0.28.0",
"license": "Apache-2.0",

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

"@types/proxyquire": "^1.3.28",
"@types/sinon": "5.0.5",
"@types/sinon": "7.0.0",
"@types/tmp": "0.0.33",

@@ -80,4 +80,4 @@ "axios": "^0.18.0",

"tmp": "0.0.33",
"typescript": "~3.1.0"
"typescript": "~3.2.0"
}
}

@@ -6,3 +6,3 @@ <img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

[![release level](https://img.shields.io/badge/release%20level-alpha-orange.svg?style&#x3D;flat)](https://cloud.google.com/terms/launch-stages)
[![CircleCI](https://img.shields.io/circleci/project/github/googleapis/nodejs-common.svg?style=flat)](https://circleci.com/gh/googleapis/nodejs-common)
[![npm version](https://img.shields.io/npm/v/@google-cloud/common.svg)](https://www.npmjs.org/package/@google-cloud/common)
[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-common/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-common)

@@ -80,1 +80,2 @@

[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png

Sorry, the diff of this file is not supported yet

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