GoogleOauth2.0 First implementation

First try for GoogleOauth2.0
This commit is contained in:
Georg Reisinger
2018-10-26 14:02:15 +02:00
parent 216a04e233
commit b171f1646c
1880 changed files with 912953 additions and 7 deletions

View File

@ -0,0 +1,18 @@
# Changelog
[npm history][1]
[1]: https://www.npmjs.com/package/nodejs-googleapis-common?activeTab=versions
## v0.3.0
This release uses the 2.0 release of `google-auth-library`. A summary of these changes (including breaking changes) can be found in the [release notes](https://github.com/google/google-auth-library-nodejs/releases/tag/v2.0.0).
### Dependencies
- Upgrade to google-auth-library 2.0 (#6)
## v0.2.1
### Fixes
- fix: use the latest google-auth-library (#4)

202
express-server/node_modules/googleapis-common/LICENSE generated vendored Normal file
View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2013 Google Inc.
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.

View File

@ -0,0 +1,76 @@
<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"/>
# [Google APIs Common Module: Node.js Client](https://github.com/google/google-api-nodejs-client)
[![release level](https://img.shields.io/badge/release%20level-alpha-orange.svg?style&#x3D;flat)](https://cloud.google.com/terms/launch-stages)
> Node.js googleapis common package
Google Cloud Common node.js module contains stuff used by other Cloud API modules.
* [github.com/googlecloudplatform/google-cloud-node](https://github.com/googlecloudplatform/google-cloud-node)
Read more about the client libraries for Cloud APIs, including the older
Google APIs Client Libraries, in [Client Libraries Explained][explained].
[explained]: https://cloud.google.com/apis/docs/client-libraries-explained
**Table of contents:**
* [Quickstart](#quickstart)
* [Before you begin](#before-you-begin)
* [Installing the client library](#installing-the-client-library)
* [Using the client library](#using-the-client-library)
* [Versioning](#versioning)
* [Contributing](#contributing)
* [License](#license)
## Quickstart
### Before you begin
1. Select or create a Cloud Platform project.
[Go to the projects page][projects]
1. Enable billing for your project.
[Enable billing][billing]
1. [Set up authentication with a service account][auth] so you can access the
API from your local workstation.
[projects]: https://console.cloud.google.com/project
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
[auth]: https://cloud.google.com/docs/authentication/getting-started
### Installing the package
npm install --save googleapis-common
It's unlikely you will need to install this package directly, as it will be
installed as a dependency when you install other `@google` packages.
## Versioning
This library follows [Semantic Versioning](http://semver.org/).
This library is considered to be in **alpha**. This means it is still a
work-in-progress and under active development. Any release is subject to
backwards-incompatible changes at any time.
More Information: [Google Cloud Platform Launch Stages][launch_stages]
[launch_stages]: https://cloud.google.com/terms/launch-stages
## Contributing
Contributions welcome! See the [Contributing Guide](https://github.com/googlecloudplatform/google-cloud-node/blob/master/.github/CONTRIBUTING.md).
## License
Apache Version 2.0
See [LICENSE](https://github.com/googlecloudplatform/google-cloud-node/blob/master/LICENSE)
[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png

View File

@ -0,0 +1,59 @@
import { AxiosAdapter, AxiosProxyConfig, AxiosRequestConfig, AxiosResponse, AxiosTransformer, CancelToken } from 'axios';
import { OAuth2Client } from 'google-auth-library';
import { Endpoint } from './endpoint';
export interface APIRequestParams<T = any> {
options: AxiosRequestConfig;
params: T;
requiredParams: string[];
pathParams: string[];
context: APIRequestContext;
mediaUrl?: string | null;
}
export interface GoogleConfigurable {
_options: GlobalOptions;
}
export interface APIRequestContext {
google?: GoogleConfigurable;
_options: GlobalOptions;
}
/**
* This interface is a mix of the AxiosRequestConfig options
* and our `auth: OAuth2Client|string` options. We need to redefine
* the interface here because the `auth` property already exists
* on AxiosRequestConfig, and uses an entirely different type.
*/
export interface GlobalOptions {
url?: string;
method?: string;
baseURL?: string;
transformRequest?: AxiosTransformer | AxiosTransformer[];
transformResponse?: AxiosTransformer | AxiosTransformer[];
headers?: any;
params?: any;
paramsSerializer?: (params: any) => string;
data?: any;
timeout?: number;
withCredentials?: boolean;
adapter?: AxiosAdapter;
auth?: OAuth2Client | string;
responseType?: string;
xsrfCookieName?: string;
xsrfHeaderName?: string;
onUploadProgress?: (progressEvent: any) => void;
onDownloadProgress?: (progressEvent: any) => void;
maxContentLength?: number;
validateStatus?: (status: number) => boolean;
maxRedirects?: number;
httpAgent?: any;
httpsAgent?: any;
proxy?: AxiosProxyConfig | false;
cancelToken?: CancelToken;
}
export interface MethodOptions extends AxiosRequestConfig {
rootUrl?: string;
}
export interface ServiceOptions extends GlobalOptions {
version?: string;
}
export declare type BodyResponseCallback<T> = (err: Error | null, res?: AxiosResponse<T> | null) => void;
export declare type APIEndpoint = Readonly<Endpoint & any>;

View File

@ -0,0 +1,15 @@
"use strict";
// Copyright 2018, Google, LLC.
// 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.
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=api.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC"}

View File

@ -0,0 +1,4 @@
import { GoogleConfigurable, ServiceOptions } from '.';
export declare function getAPI<T>(api: string, options: ServiceOptions | string, versions: {
[index: string]: any;
}, context?: GoogleConfigurable): T;

View File

@ -0,0 +1,40 @@
"use strict";
// Copyright 2018, Google, LLC.
// 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.
Object.defineProperty(exports, "__esModule", { value: true });
function getAPI(api, options,
// tslint:disable-next-line no-any
versions, context) {
let version;
if (typeof options === 'string') {
version = options;
options = {};
}
else if (typeof options === 'object') {
version = options.version;
delete options.version;
}
else {
throw new Error('Argument error: Accepts only string or object');
}
try {
const ctr = versions[version];
const ep = new ctr(options, context);
return Object.freeze(ep);
}
catch (e) {
throw new Error(`Unable to load endpoint ${api}("${version}"): ${e.message}`);
}
}
exports.getAPI = getAPI;
//# sourceMappingURL=apiIndex.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"apiIndex.js","sourceRoot":"","sources":["../../src/apiIndex.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAIjC,SAAgB,MAAM,CAClB,GAAW,EAAE,OAA8B;AAC3C,kCAAkC;AAClC,QAAgC,EAAE,OAA4B;IAChE,IAAI,OAAe,CAAC;IACpB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO,GAAG,OAAO,CAAC;QAClB,OAAO,GAAG,EAAE,CAAC;KACd;SAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QACtC,OAAO,GAAG,OAAO,CAAC,OAAQ,CAAC;QAC3B,OAAO,OAAO,CAAC,OAAO,CAAC;KACxB;SAAM;QACL,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;KAClE;IACD,IAAI;QACF,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9B,MAAM,EAAE,GAAG,IAAI,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAM,CAAC;KAC/B;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,IAAI,KAAK,CACX,2BAA2B,GAAG,KAAK,OAAO,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;KACnE;AACH,CAAC;AAtBD,wBAsBC"}

View File

@ -0,0 +1,10 @@
import { AxiosPromise } from 'axios';
import { BodyResponseCallback } from 'google-auth-library/build/src/transporters';
import { APIRequestParams } from './api';
/**
* Create and send request to Google API
* @param parameters Parameters used to form request
* @param callback Callback when request finished or error found
*/
export declare function createAPIRequest<T>(parameters: APIRequestParams): AxiosPromise<T>;
export declare function createAPIRequest<T>(parameters: APIRequestParams, callback: BodyResponseCallback<T>): void;

View File

@ -0,0 +1,249 @@
"use strict";
// Copyright 2014-2016, Google, Inc.
// 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.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const google_auth_library_1 = require("google-auth-library");
const qs = require("qs");
const stream = require("stream");
const urlTemplate = require("url-template");
const uuid = require("uuid");
const maxContentLength = Math.pow(2, 31);
// tslint:disable-next-line no-var-requires
const pkg = require('../../package.json');
const USER_AGENT = `google-api-nodejs-client/${pkg.version} (gzip)`;
function isReadableStream(obj) {
return obj instanceof stream.Readable && typeof obj._read === 'function';
}
function getMissingParams(params, required) {
const missing = new Array();
required.forEach(param => {
// Is the required param in the params object?
if (params[param] === undefined) {
missing.push(param);
}
});
// If there are any required params missing, return their names in array,
// otherwise return null
return missing.length > 0 ? missing : null;
}
function createAPIRequest(parameters, callback) {
if (callback) {
createAPIRequestAsync(parameters).then(r => callback(null, r), callback);
}
else {
return createAPIRequestAsync(parameters);
}
}
exports.createAPIRequest = createAPIRequest;
function createAPIRequestAsync(parameters) {
return __awaiter(this, void 0, void 0, function* () {
let params = parameters.params;
const options = Object.assign({}, parameters.options);
// Create a new params object so it can no longer be modified from outside
// code Also support global and per-client params, but allow them to be
// overriden per-request
const topOptions = parameters.context.google ?
parameters.context.google._options.params :
{};
params = Object.assign({}, // New base object
topOptions, // Global params
parameters.context._options.params, // Per-client params
params // API call params
);
const media = params.media || {};
/**
* In a previous version of this API, the request body was stuffed in a field
* named `resource`. This caused lots of problems, because it's not uncommon
* to have an actual named parameter required which is also named `resource`.
* This mean that users would have to use `resource_` in those cases, which
* pretty much nobody figures out on their own. The request body is now
* documented as being in the `requestBody` property, but we also need to keep
* using `resource` for reasons of back-compat. Cases that need to be covered
* here:
* - user provides just a `resource` with a request body
* - user provides both a `resource` and a `resource_`
* - user provides just a `requestBody`
* - user provides both a `requestBody` and a `resource`
*/
const resource = params.requestBody ? params.requestBody : params.resource;
if (!params.requestBody && params.resource) {
delete params.resource;
}
delete params.requestBody;
let authClient = params.auth || parameters.context._options.auth ||
(parameters.context.google ? parameters.context.google._options.auth :
null);
const defaultMime = typeof media.body === 'string' ?
'text/plain' :
'application/octet-stream';
delete params.media;
delete params.auth;
// Grab headers from user provided options
const headers = params.headers || {};
delete params.headers;
// Un-alias parameters that were modified due to conflicts with reserved names
Object.keys(params).forEach(key => {
if (key.slice(-1) === '_') {
const newKey = key.slice(0, -1);
params[newKey] = params[key];
delete params[key];
}
});
// Check for missing required parameters in the API request
const missingParams = getMissingParams(params, parameters.requiredParams);
if (missingParams) {
// Some params are missing - stop further operations and inform the
// developer which required params are not included in the request
throw new Error('Missing required parameters: ' + missingParams.join(', '));
}
// Parse urls
if (options.url) {
options.url = urlTemplate.parse(options.url).expand(params);
}
if (parameters.mediaUrl) {
parameters.mediaUrl = urlTemplate.parse(parameters.mediaUrl).expand(params);
}
// When forming the querystring, override the serializer so that array
// values are serialized like this:
// myParams: ['one', 'two'] ---> 'myParams=one&myParams=two'
// This serializer also encodes spaces in the querystring as `%20`,
// whereas the default serializer in axios encodes to a `+`.
options.paramsSerializer = (params) => {
return qs.stringify(params, { arrayFormat: 'repeat' });
};
// delete path parameters from the params object so they do not end up in
// query
parameters.pathParams.forEach(param => {
delete params[param];
});
// if authClient is actually a string, use it as an API KEY
if (typeof authClient === 'string') {
params.key = params.key || authClient;
authClient = undefined;
}
if (parameters.mediaUrl && media.body) {
options.url = parameters.mediaUrl;
if (resource) {
// Axios doesn't support multipart/related uploads, so it has to
// be implemented here.
params.uploadType = 'multipart';
const multipart = [
{ 'Content-Type': 'application/json', body: JSON.stringify(resource) }, {
'Content-Type': media.mimeType || (resource && resource.mimeType) || defaultMime,
body: media.body // can be a readable stream or raw string!
}
];
const boundary = uuid.v4();
const finale = `--${boundary}--`;
const rStream = new stream.PassThrough();
const pStream = new ProgressStream();
const isStream = isReadableStream(multipart[1].body);
headers['Content-Type'] = `multipart/related; boundary=${boundary}`;
for (const part of multipart) {
const preamble = `--${boundary}\r\nContent-Type: ${part['Content-Type']}\r\n\r\n`;
rStream.push(preamble);
if (typeof part.body === 'string') {
rStream.push(part.body);
rStream.push('\r\n');
}
else {
// Axios does not natively support onUploadProgress in node.js.
// Pipe through the pStream first to read the number of bytes read
// for the purpose of tracking progress.
pStream.on('progress', bytesRead => {
if (options.onUploadProgress) {
options.onUploadProgress({ bytesRead });
}
});
part.body.pipe(pStream).pipe(rStream, { end: false });
part.body.on('end', () => {
rStream.push('\r\n');
rStream.push(finale);
rStream.push(null);
});
}
}
if (!isStream) {
rStream.push(finale);
rStream.push(null);
}
options.data = rStream;
}
else {
params.uploadType = 'media';
Object.assign(headers, { 'Content-Type': media.mimeType || defaultMime });
options.data = media.body;
}
}
else {
options.data = resource || undefined;
}
options.headers = headers;
options.params = params;
// We need to set a default content size, or the max defaults
// to 10MB. Setting to 2GB by default.
// https://github.com/google/google-api-nodejs-client/issues/991
options.maxContentLength = options.maxContentLength || maxContentLength;
options.headers['Accept-Encoding'] = 'gzip';
options.headers['User-Agent'] = USER_AGENT;
// By default Axios treats any 2xx as valid, and all non 2xx status
// codes as errors. This is a problem for HTTP 304s when used along
// with an eTag.
if (!options.validateStatus) {
options.validateStatus = (status) => {
return (status >= 200 && status < 300) || status === 304;
};
}
// Combine the AxiosRequestConfig options passed with this specific
// API call witht the global options configured at the API Context
// level, or at the global level.
const mergedOptions = Object.assign({}, (parameters.context.google ? parameters.context.google._options : {}), parameters.context._options, options);
delete mergedOptions.auth; // is overridden by our auth code
// Perform the HTTP request. NOTE: this function used to return a
// mikeal/request object. Since the transition to Axios, the method is
// now void. This may be a source of confusion for users upgrading from
// version 24.0 -> 25.0 or up.
if (authClient && typeof authClient === 'object') {
return authClient.request(mergedOptions);
}
else {
return (new google_auth_library_1.DefaultTransporter()).request(mergedOptions);
}
});
}
/**
* Basic Passthrough Stream that records the number of bytes read
* every time the cursor is moved.
*/
class ProgressStream extends stream.Transform {
constructor() {
super(...arguments);
this.bytesRead = 0;
}
// tslint:disable-next-line: no-any
_transform(chunk, encoding, callback) {
this.bytesRead += chunk.length;
this.emit('progress', this.bytesRead);
this.push(chunk);
callback();
}
}
//# sourceMappingURL=apirequest.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,42 @@
import { GlobalOptions } from './api';
import { Endpoint } from './endpoint';
export declare type EndpointCreator = (options: GlobalOptions, google: {}) => Endpoint;
export interface DiscoveryOptions {
includePrivate?: boolean;
debug?: boolean;
}
export declare class Discovery {
private transporter;
private options;
/**
* Discovery for discovering API endpoints
*
* @param options Options for discovery
*/
constructor(options: DiscoveryOptions);
/**
* Generate and Endpoint from an endpoint schema object.
*
* @param schema The schema from which to generate the Endpoint.
* @return A function that creates an endpoint.
*/
private makeEndpoint;
/**
* Log output of generator. Works just like console.log
*/
private log;
/**
* Generate all APIs and return as in-memory object.
* @param discoveryUrl
*/
discoverAllAPIs(discoveryUrl: string): Promise<{}>;
/**
* Generate API file given discovery URL
*
* @param apiDiscoveryUrl URL or filename of discovery doc for API
* @returns A promise that resolves with a function that creates the endpoint
*/
discoverAPI(apiDiscoveryUrl: string | {
url: string;
}): Promise<EndpointCreator>;
}

View File

@ -0,0 +1,152 @@
"use strict";
// Copyright 2014-2016, Google, Inc.
// 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.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const google_auth_library_1 = require("google-auth-library");
const pify = require("pify");
const url = require("url");
const util = require("util");
const apirequest_1 = require("./apirequest");
const endpoint_1 = require("./endpoint");
const fsp = pify(fs);
class Discovery {
/**
* Discovery for discovering API endpoints
*
* @param options Options for discovery
*/
constructor(options) {
this.transporter = new google_auth_library_1.DefaultTransporter();
this.options = options || {};
}
/**
* Generate and Endpoint from an endpoint schema object.
*
* @param schema The schema from which to generate the Endpoint.
* @return A function that creates an endpoint.
*/
makeEndpoint(schema) {
return (options) => {
const ep = new endpoint_1.Endpoint(options);
ep.applySchema(ep, schema, schema, ep);
return ep;
};
}
/**
* Log output of generator. Works just like console.log
*/
log(...args) {
if (this.options && this.options.debug) {
console.log.apply(this, arguments);
}
}
/**
* Generate all APIs and return as in-memory object.
* @param discoveryUrl
*/
discoverAllAPIs(discoveryUrl) {
return __awaiter(this, void 0, void 0, function* () {
const headers = this.options.includePrivate ? {} : { 'X-User-Ip': '0.0.0.0' };
const res = yield this.transporter.request({ url: discoveryUrl, headers });
const items = res.data.items;
const apis = yield Promise.all(items.map((api) => __awaiter(this, void 0, void 0, function* () {
const endpointCreator = yield this.discoverAPI(api.discoveryRestUrl);
return { api, endpointCreator };
})));
const versionIndex = {};
// tslint:disable-next-line no-any
const apisIndex = {};
for (const set of apis) {
if (!apisIndex[set.api.name]) {
versionIndex[set.api.name] = {};
apisIndex[set.api.name] = (options) => {
const type = typeof options;
let version;
if (type === 'string') {
version = options;
options = {};
}
else if (type === 'object') {
version = options.version;
delete options.version;
}
else {
throw new Error('Argument error: Accepts only string or object');
}
try {
const ep =
// tslint:disable-next-line: no-any
set.endpointCreator(options, this);
return Object.freeze(ep); // create new & freeze
}
catch (e) {
throw new Error(util.format('Unable to load endpoint %s("%s"): %s', set.api.name, version, e.message));
}
};
}
versionIndex[set.api.name][set.api.version] = set.endpointCreator;
}
return apisIndex;
});
}
/**
* Generate API file given discovery URL
*
* @param apiDiscoveryUrl URL or filename of discovery doc for API
* @returns A promise that resolves with a function that creates the endpoint
*/
discoverAPI(apiDiscoveryUrl) {
return __awaiter(this, void 0, void 0, function* () {
if (typeof apiDiscoveryUrl === 'string') {
const parts = url.parse(apiDiscoveryUrl);
if (apiDiscoveryUrl && !parts.protocol) {
this.log('Reading from file ' + apiDiscoveryUrl);
const file = yield fsp.readFile(apiDiscoveryUrl, { encoding: 'utf8' });
return this.makeEndpoint(JSON.parse(file));
}
else {
this.log('Requesting ' + apiDiscoveryUrl);
const res = yield this.transporter.request({ url: apiDiscoveryUrl });
return this.makeEndpoint(res.data);
}
}
else {
const options = apiDiscoveryUrl;
this.log('Requesting ' + options.url);
const url = options.url;
delete options.url;
const parameters = {
options: { url, method: 'GET' },
requiredParams: [],
pathParams: [],
params: options,
context: { google: { _options: {} }, _options: {} }
};
const pcr = pify(apirequest_1.createAPIRequest);
const res = yield pcr(parameters);
return this.makeEndpoint(res.data);
}
});
}
}
exports.Discovery = Discovery;
//# sourceMappingURL=discovery.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/discovery.ts"],"names":[],"mappings":";AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;;;;;;;;AAEjC,yBAAyB;AACzB,6DAAuD;AACvD,6BAA6B;AAC7B,2BAA2B;AAC3B,6BAA6B;AAE7B,6CAA8C;AAC9C,yCAAoC;AAKpC,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;AAOrB,MAAa,SAAS;IAIpB;;;;OAIG;IACH,YAAY,OAAyB;QAR7B,gBAAW,GAAG,IAAI,wCAAkB,EAAE,CAAC;QAS7C,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACK,YAAY,CAAC,MAAc;QACjC,OAAO,CAAC,OAAW,EAAE,EAAE;YACrB,MAAM,EAAE,GAAG,IAAI,mBAAQ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AI,CAAC,CAAC;aACpC;QACH,CAAC;KAAA;CACF;AA3HD,8BA2HC"}

View File

@ -0,0 +1,42 @@
import { APIRequestContext, GlobalOptions } from './api';
import { Schema, SchemaResource } from './schema';
export interface Target {
[index: string]: {};
}
export declare class Endpoint implements Target, APIRequestContext {
_options: GlobalOptions;
google: any;
[index: string]: {};
constructor(options: {});
/**
* Given a schema, add methods and resources to a target.
*
* @param {object} target The target to which to apply the schema.
* @param {object} rootSchema The top-level schema, so we don't lose track of it
* during recursion.
* @param {object} schema The current schema from which to extract methods and
* resources.
* @param {object} context The context to add to each method.
*/
applySchema(target: Target, rootSchema: Schema, schema: SchemaResource, context: APIRequestContext): void;
/**
* Given a schema, add methods to a target.
*
* @param {object} target The target to which to apply the methods.
* @param {object} rootSchema The top-level schema, so we don't lose track of it
* during recursion.
* @param {object} schema The current schema from which to extract methods.
* @param {object} context The context to add to each method.
*/
private applyMethodsFromSchema;
/**
* Given a method schema, add a method to a target.
*
* @param target The target to which to add the method.
* @param schema The top-level schema that contains the rootUrl, etc.
* @param method The method schema from which to generate the method.
* @param context The context to add to the method.
*/
private makeMethod;
private getPathParams;
}

View File

@ -0,0 +1,124 @@
"use strict";
// Copyright 2018, Google, LLC.
// 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.
Object.defineProperty(exports, "__esModule", { value: true });
const apirequest_1 = require("./apirequest");
class Endpoint {
constructor(options) {
this._options = options || {};
}
/**
* Given a schema, add methods and resources to a target.
*
* @param {object} target The target to which to apply the schema.
* @param {object} rootSchema The top-level schema, so we don't lose track of it
* during recursion.
* @param {object} schema The current schema from which to extract methods and
* resources.
* @param {object} context The context to add to each method.
*/
applySchema(target, rootSchema, schema, context) {
this.applyMethodsFromSchema(target, rootSchema, schema, context);
if (schema.resources) {
for (const resourceName in schema.resources) {
if (schema.resources.hasOwnProperty(resourceName)) {
const resource = schema.resources[resourceName];
if (!target[resourceName]) {
target[resourceName] = {};
}
this.applySchema(target[resourceName], rootSchema, resource, context);
}
}
}
}
/**
* Given a schema, add methods to a target.
*
* @param {object} target The target to which to apply the methods.
* @param {object} rootSchema The top-level schema, so we don't lose track of it
* during recursion.
* @param {object} schema The current schema from which to extract methods.
* @param {object} context The context to add to each method.
*/
applyMethodsFromSchema(target, rootSchema, schema, context) {
if (schema.methods) {
for (const name in schema.methods) {
if (schema.methods.hasOwnProperty(name)) {
const method = schema.methods[name];
target[name] = this.makeMethod(rootSchema, method, context);
}
}
}
}
/**
* Given a method schema, add a method to a target.
*
* @param target The target to which to add the method.
* @param schema The top-level schema that contains the rootUrl, etc.
* @param method The method schema from which to generate the method.
* @param context The context to add to the method.
*/
makeMethod(schema, method, context) {
return (paramsOrCallback, callback) => {
const params = typeof paramsOrCallback === 'function' ? {} : paramsOrCallback;
callback =
typeof paramsOrCallback === 'function' ? paramsOrCallback : callback;
const schemaUrl = buildurl(schema.rootUrl + schema.servicePath + method.path);
const parameters = {
options: {
url: schemaUrl.substring(1, schemaUrl.length - 1),
method: method.httpMethod
},
params,
requiredParams: method.parameterOrder || [],
pathParams: this.getPathParams(method.parameters),
context
};
if (method.mediaUpload && method.mediaUpload.protocols &&
method.mediaUpload.protocols.simple &&
method.mediaUpload.protocols.simple.path) {
const mediaUrl = buildurl(schema.rootUrl + method.mediaUpload.protocols.simple.path);
parameters.mediaUrl = mediaUrl.substring(1, mediaUrl.length - 1);
}
if (!callback) {
return apirequest_1.createAPIRequest(parameters);
}
apirequest_1.createAPIRequest(parameters, callback);
return;
};
}
getPathParams(params) {
const pathParams = new Array();
if (typeof params !== 'object') {
params = {};
}
Object.keys(params).forEach(key => {
if (params[key].location === 'path') {
pathParams.push(key);
}
});
return pathParams;
}
}
exports.Endpoint = Endpoint;
/**
* Build a string used to create a URL from the discovery doc provided URL.
* replace double slashes with single slash (except in https://)
* @private
* @param input URL to build from
* @return Resulting built URL
*/
function buildurl(input) {
return input ? `'${input}'`.replace(/([^:]\/)\/+/g, '$1') : '';
}
//# sourceMappingURL=endpoint.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../src/endpoint.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAKjC,6CAA8C;AAO9C,MAAa,QAAQ;IAMnB,YAAY,OAAW;QACrB,IAAI,CAAC,QAAQ,GAAG,OAAO,IAAI,EAAE,CAAC;IAChC,CAAC;IAED;;;;;;;;;OASG;IACH,WAAW,CACP,MAAc,EAAE,UAAkB,EAAE,MAAsB,EAC1D,OAA0B;QAC5B,IAAI,CAAC,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACjE,IAAI,MAAM,CAAC,SAAS,EAAE;YACpB,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,SAAS,EAAE;gBAC3C,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,YAAY,CAAC,EAAE;oBACjD,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;oBAChD,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE;wBACzB,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;qBAC3B;oBACD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;iBACvE;aACF;SACF;IACH,CAAC;IAED;;;;;;;;OAQG;IACK,sBAAs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RequestParams, BodyResponseCallback, GlobalOptions, GoogleConfigurable, MethodOptions, ServiceOptions } from './api';
export { getAPI } from './apiIndex';
export { createAPIRequest } from './apirequest';
export { Discovery, DiscoveryOptions, EndpointCreator } from './discovery';
export { Endpoint, Target } from './endpoint';
export { FragmentResponse, HttpMethod, ParameterFormat, Schema, SchemaItem, SchemaItems, SchemaMethod, SchemaMethods, SchemaParameter, SchemaParameters, SchemaResource, SchemaResources, Schemas, SchemaType } from './schema';

View File

@ -0,0 +1,23 @@
"use strict";
// Copyright 2018, Google, LLC.
// 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.
Object.defineProperty(exports, "__esModule", { value: true });
var apiIndex_1 = require("./apiIndex");
exports.getAPI = apiIndex_1.getAPI;
var apirequest_1 = require("./apirequest");
exports.createAPIRequest = apirequest_1.createAPIRequest;
var discovery_1 = require("./discovery");
exports.Discovery = discovery_1.Discovery;
var endpoint_1 = require("./endpoint");
exports.Endpoint = endpoint_1.Endpoint;
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,uCAAkC;AAA1B,4BAAA,MAAM,CAAA;AACd,2CAA8C;AAAtC,wCAAA,gBAAgB,CAAA;AACxB,yCAAyE;AAAjE,gCAAA,SAAS,CAAA;AACjB,uCAA4C;AAApC,8BAAA,QAAQ,CAAA"}

View File

@ -0,0 +1,123 @@
/**
* These are a collection of interfaces that represent the GoogleApis
* Discovery json formats.
*/
export interface Schemas {
discoveryVersion: string;
kind: string;
items: Schema[];
}
export interface Schema {
auth: {
oauth2: {
scopes: {
[index: string]: {
description: string;
};
};
};
};
basePath: string;
baseUrl: string;
batchPath: string;
description: string;
discoveryVersion: string;
discoveryRestUrl: string;
documentationLink: string;
etag: string;
icons: {
x16: string;
x32: string;
};
id: string;
kind: string;
methods: SchemaMethods;
name: string;
ownerDomain: string;
ownerName: string;
parameters: SchemaParameters;
protocol: string;
resources: SchemaResources;
revision: string;
rootUrl: string;
schemas: SchemaItems;
servicePath: string;
title: string;
version: string;
}
export interface SchemaResources {
[index: string]: SchemaResource;
}
export interface SchemaResource {
methods?: SchemaMethods;
resources?: SchemaResources;
}
export interface SchemaItems {
[index: string]: SchemaItem;
}
export interface SchemaItem {
description?: string;
default?: string;
id?: string;
properties?: {
[index: string]: SchemaItem;
};
items?: {
[index: string]: SchemaItem;
};
type?: SchemaType;
format?: ParameterFormat;
$ref?: string;
}
export interface SchemaParameters {
[index: string]: SchemaParameter;
}
export interface SchemaParameter {
default: string;
description: string;
location: string;
enum: string[];
enumDescription: string[];
type: SchemaType;
format: ParameterFormat;
required: boolean;
}
export interface SchemaMethods {
[index: string]: SchemaMethod;
}
export interface SchemaMethod {
description: string;
httpMethod: HttpMethod;
id: string;
parameterOrder?: string[];
parameters?: {
[index: string]: SchemaParameter;
};
path: string;
request: {
$ref: string;
};
response: {
$ref: string;
};
sampleUrl: string;
scopes: string[];
fragment: string;
mediaUpload: {
protocols: {
simple: {
path: string;
};
};
};
}
export interface FragmentResponse {
codeFragment: {
[index: string]: {
fragment: string;
};
};
}
export declare type ParameterFormat = 'int32';
export declare type HttpMethod = 'GET' | 'PATCH' | 'PUT';
export declare type SchemaType = 'object' | 'integer' | 'string' | 'array' | 'boolean';

View File

@ -0,0 +1,15 @@
"use strict";
// Copyright 2018, Google, LLC.
// 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.
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=schema.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC"}

View File

@ -0,0 +1,80 @@
{
"_from": "googleapis-common@^0.3.0",
"_id": "googleapis-common@0.3.0",
"_inBundle": false,
"_integrity": "sha512-OqQ2iskzjPHLoM+AXk7e/TmEsdgxyAk8PVbMg0S8v2wPhgMu2wTawEL7zH9QG236u/RqQ1Ak120oSWsamPnWGg==",
"_location": "/googleapis-common",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "googleapis-common@^0.3.0",
"name": "googleapis-common",
"escapedName": "googleapis-common",
"rawSpec": "^0.3.0",
"saveSpec": null,
"fetchSpec": "^0.3.0"
},
"_requiredBy": [
"/googleapis"
],
"_resolved": "https://registry.npmjs.org/googleapis-common/-/googleapis-common-0.3.0.tgz",
"_shasum": "97ba111f7420367e636a30a2b87be4a7f220c7e9",
"_spec": "googleapis-common@^0.3.0",
"_where": "C:\\Users\\Georg\\GitHub\\SmartShopper\\express-server\\node_modules\\googleapis",
"author": {
"name": "Google LLC"
},
"bundleDependencies": false,
"dependencies": {
"axios": "^0.18.0",
"google-auth-library": "^2.0.0",
"pify": "^3.0.0",
"qs": "^6.5.2",
"url-template": "^2.0.8",
"uuid": "^3.2.1"
},
"deprecated": false,
"description": "A common tooling library used by the googleapis npm module. You probably don't want to use this directly.",
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/nock": "^9.3.0",
"@types/pify": "^3.0.2",
"@types/qs": "^6.5.1",
"@types/url-template": "^2.0.28",
"@types/uuid": "^3.4.3",
"codecov": "^3.0.4",
"gts": "^0.8.0",
"ink-docstrap": "^1.3.2",
"intelli-espower-loader": "^1.0.1",
"jsdoc": "^3.5.5",
"mocha": "^5.2.0",
"nock": "^9.6.0",
"source-map-support": "^0.5.8",
"typescript": "~3.0.0"
},
"files": [
"build/src"
],
"keywords": [],
"license": "Apache-2.0",
"main": "build/src/index.js",
"name": "googleapis-common",
"scripts": {
"check": "gts check",
"clean": "gts clean",
"compile": "tsc -p .",
"docs": "jsdoc -c .jsdoc.js",
"fix": "gts fix",
"lint": "npm run check",
"posttest": "npm run check",
"prepare": "npm run compile",
"presystem-test": "npm run compile",
"pretest": "npm run compile",
"samples-test": "mocha build/samples-test",
"system-test": "mocha build/system-test",
"test": "mocha build/test"
},
"types": "build/src/index.d.ts",
"version": "0.3.0"
}