Proyecto audio control. inicado con panel y control.

This commit is contained in:
2025-11-11 02:26:04 -05:00
parent 7ea49a026e
commit 6895960127
4248 changed files with 493435 additions and 0 deletions

21
node_modules/gtoken/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Ryan Seys
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

187
node_modules/gtoken/README.md generated vendored Normal file
View File

@@ -0,0 +1,187 @@
<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"/>
# [node-gtoken](https://github.com/googleapis/node-gtoken)
[![npm version][npm-image]][npm-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![codecov][codecov-image]][codecov-url]
[![Code Style: Google][gts-image]][gts-url]
> Node.js Google Authentication Service Account Tokens
This is a low level utility library used to interact with Google Authentication services. **In most cases, you probably want to use the [google-auth-library](https://github.com/googleapis/google-auth-library-nodejs) instead.**
* [gtoken API Reference][client-docs]
* [github.com/googleapis/node-gtoken](https://github.com/googleapis/node-gtoken)
## Installation
``` sh
npm install gtoken
```
## Usage
### Use with a `.pem` or `.json` key file:
``` js
const { GoogleToken } = require('gtoken');
const gtoken = new GoogleToken({
keyFile: 'path/to/key.pem', // or path to .json key file
email: 'my_service_account_email@developer.gserviceaccount.com',
scope: ['https://scope1', 'https://scope2'], // or space-delimited string of scopes
eagerRefreshThresholdMillis: 5 * 60 * 1000
});
gtoken.getToken((err, tokens) => {
if (err) {
console.log(err);
return;
}
console.log(tokens);
// {
// access_token: 'very-secret-token',
// expires_in: 3600,
// token_type: 'Bearer'
// }
});
```
You can also use the async/await style API:
``` js
const tokens = await gtoken.getToken()
console.log(tokens);
```
Or use promises:
```js
gtoken.getToken()
.then(tokens => {
console.log(tokens)
})
.catch(console.error);
```
### Use with a service account `.json` key file:
``` js
const { GoogleToken } = require('gtoken');
const gtoken = new GoogleToken({
keyFile: 'path/to/key.json',
scope: ['https://scope1', 'https://scope2'], // or space-delimited string of scopes
eagerRefreshThresholdMillis: 5 * 60 * 1000
});
gtoken.getToken((err, tokens) => {
if (err) {
console.log(err);
return;
}
console.log(tokens);
});
```
### Pass the private key as a string directly:
``` js
const key = '-----BEGIN RSA PRIVATE KEY-----\nXXXXXXXXXXX...';
const { GoogleToken } = require('gtoken');
const gtoken = new GoogleToken({
email: 'my_service_account_email@developer.gserviceaccount.com',
scope: ['https://scope1', 'https://scope2'], // or space-delimited string of scopes
key: key,
eagerRefreshThresholdMillis: 5 * 60 * 1000
});
```
## Options
> Various options that can be set when creating initializing the `gtoken` object.
- `options.email or options.iss`: The service account email address.
- `options.scope`: An array of scope strings or space-delimited string of scopes.
- `options.sub`: The email address of the user requesting delegated access.
- `options.keyFile`: The filename of `.json` key or `.pem` key.
- `options.key`: The raw RSA private key value, in place of using `options.keyFile`.
- `options.additionalClaims`: Additional claims to include in the JWT when requesting a token.
- `options.eagerRefreshThresholdMillis`: How long must a token be valid for in order to return it from the cache. Defaults to 0.
### .getToken(callback)
> Returns the cached tokens or requests a new one and returns it.
``` js
gtoken.getToken((err, token) => {
console.log(err || token);
// gtoken.rawToken value is also set
});
```
### .getCredentials('path/to/key.json')
> Given a keyfile, returns the key and (if available) the client email.
```js
const creds = await gtoken.getCredentials('path/to/key.json');
```
### Properties
> Various properties set on the gtoken object after call to `.getToken()`.
- `gtoken.idToken`: The OIDC token returned (if any).
- `gtoken.accessToken`: The access token.
- `gtoken.expiresAt`: The expiry date as milliseconds since 1970/01/01
- `gtoken.key`: The raw key value.
- `gtoken.rawToken`: Most recent raw token data received from Google.
### .hasExpired()
> Returns true if the token has expired, or token does not exist.
``` js
const tokens = await gtoken.getToken();
gtoken.hasExpired(); // false
```
### .revokeToken()
> Revoke the token if set.
``` js
await gtoken.revokeToken();
console.log('Token revoked!');
```
## Downloading your private `.json` key from Google
1. Open the [Google Developer Console][gdevconsole].
2. Open your project and under "APIs & auth", click Credentials.
3. Generate a new `.json` key and download it into your project.
## Converting your `.p12` key to a `.pem` key
If you'd like to convert to a `.pem` for use later, use OpenSSL if you have it installed.
``` sh
$ openssl pkcs12 -in key.p12 -nodes -nocerts > key.pem
```
Don't forget, the passphrase when converting these files is the string `'notasecret'`
## License
[MIT](https://github.com/googleapis/node-gtoken/blob/main/LICENSE)
[codecov-image]: https://codecov.io/gh/googleapis/node-gtoken/branch/main/graph/badge.svg
[codecov-url]: https://codecov.io/gh/googleapis/node-gtoken
[gdevconsole]: https://console.developers.google.com
[gts-image]: https://img.shields.io/badge/code%20style-google-blueviolet.svg
[gts-url]: https://www.npmjs.com/package/gts
[npm-image]: https://img.shields.io/npm/v/gtoken.svg
[npm-url]: https://npmjs.org/package/gtoken
[snyk-image]: https://snyk.io/test/github/googleapis/node-gtoken/badge.svg
[snyk-url]: https://snyk.io/test/github/googleapis/node-gtoken
[client-docs]: https://googleapis.dev/nodejs/gtoken/latest/

450
node_modules/gtoken/build/cjs/src/index.cjs generated vendored Normal file
View File

@@ -0,0 +1,450 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GoogleToken = void 0;
var fs = _interopRequireWildcard(require("fs"));
var _gaxios = require("gaxios");
var jws = _interopRequireWildcard(require("jws"));
var path = _interopRequireWildcard(require("path"));
var _util = require("util");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t3 in e) "default" !== _t3 && {}.hasOwnProperty.call(e, _t3) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t3)) && (i.get || i.set) ? o(f, _t3, i) : f[_t3] = e[_t3]); return f; })(e, t); }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } /**
* Copyright 2018 Google LLC
*
* Distributed under MIT license.
* See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
var readFile = fs.readFile ? (0, _util.promisify)(fs.readFile) : /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
return _regenerator().w(function (_context) {
while (1) switch (_context.n) {
case 0:
throw new ErrorWithCode('use key rather than keyFile.', 'MISSING_CREDENTIALS');
case 1:
return _context.a(2);
}
}, _callee);
}));
var GOOGLE_TOKEN_URL = 'https://oauth2.googleapis.com/token';
var GOOGLE_REVOKE_TOKEN_URL = 'https://oauth2.googleapis.com/revoke?token=';
var ErrorWithCode = /*#__PURE__*/function (_Error) {
function ErrorWithCode(message, code) {
var _this;
_classCallCheck(this, ErrorWithCode);
_this = _callSuper(this, ErrorWithCode, [message]);
_defineProperty(_this, "code", void 0);
_this.code = code;
return _this;
}
_inherits(ErrorWithCode, _Error);
return _createClass(ErrorWithCode);
}(/*#__PURE__*/_wrapNativeSuper(Error));
var _inFlightRequest = /*#__PURE__*/new WeakMap();
var _GoogleToken_brand = /*#__PURE__*/new WeakSet();
var GoogleToken = exports.GoogleToken = /*#__PURE__*/function () {
/**
* Create a GoogleToken.
*
* @param options Configuration object.
*/
function GoogleToken(_options) {
_classCallCheck(this, GoogleToken);
_classPrivateMethodInitSpec(this, _GoogleToken_brand);
_defineProperty(this, "expiresAt", void 0);
_defineProperty(this, "key", void 0);
_defineProperty(this, "keyFile", void 0);
_defineProperty(this, "iss", void 0);
_defineProperty(this, "sub", void 0);
_defineProperty(this, "scope", void 0);
_defineProperty(this, "rawToken", void 0);
_defineProperty(this, "tokenExpires", void 0);
_defineProperty(this, "email", void 0);
_defineProperty(this, "additionalClaims", void 0);
_defineProperty(this, "eagerRefreshThresholdMillis", void 0);
_defineProperty(this, "transporter", {
request: function request(opts) {
return (0, _gaxios.request)(opts);
}
});
_classPrivateFieldInitSpec(this, _inFlightRequest, void 0);
_assertClassBrand(_GoogleToken_brand, this, _configure).call(this, _options);
}
/**
* Returns whether the token has expired.
*
* @return true if the token has expired, false otherwise.
*/
return _createClass(GoogleToken, [{
key: "accessToken",
get: function get() {
return this.rawToken ? this.rawToken.access_token : undefined;
}
}, {
key: "idToken",
get: function get() {
return this.rawToken ? this.rawToken.id_token : undefined;
}
}, {
key: "tokenType",
get: function get() {
return this.rawToken ? this.rawToken.token_type : undefined;
}
}, {
key: "refreshToken",
get: function get() {
return this.rawToken ? this.rawToken.refresh_token : undefined;
}
}, {
key: "hasExpired",
value: function hasExpired() {
var now = new Date().getTime();
if (this.rawToken && this.expiresAt) {
return now >= this.expiresAt;
} else {
return true;
}
}
/**
* Returns whether the token will expire within eagerRefreshThresholdMillis
*
* @return true if the token will be expired within eagerRefreshThresholdMillis, false otherwise.
*/
}, {
key: "isTokenExpiring",
value: function isTokenExpiring() {
var _this$eagerRefreshThr;
var now = new Date().getTime();
var eagerRefreshThresholdMillis = (_this$eagerRefreshThr = this.eagerRefreshThresholdMillis) !== null && _this$eagerRefreshThr !== void 0 ? _this$eagerRefreshThr : 0;
if (this.rawToken && this.expiresAt) {
return this.expiresAt <= now + eagerRefreshThresholdMillis;
} else {
return true;
}
}
/**
* Returns a cached token or retrieves a new one from Google.
*
* @param callback The callback function.
*/
}, {
key: "getToken",
value: function getToken(callback) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (_typeof(callback) === 'object') {
opts = callback;
callback = undefined;
}
opts = Object.assign({
forceRefresh: false
}, opts);
if (callback) {
var cb = callback;
_assertClassBrand(_GoogleToken_brand, this, _getTokenAsync).call(this, opts).then(function (t) {
return cb(null, t);
}, callback);
return;
}
return _assertClassBrand(_GoogleToken_brand, this, _getTokenAsync).call(this, opts);
}
/**
* Given a keyFile, extract the key and client email if available
* @param keyFile Path to a json, pem, or p12 file that contains the key.
* @returns an object with privateKey and clientEmail properties
*/
}, {
key: "getCredentials",
value: (function () {
var _getCredentials = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(keyFile) {
var ext, key, body, privateKey, clientEmail, _privateKey, _t;
return _regenerator().w(function (_context2) {
while (1) switch (_context2.n) {
case 0:
ext = path.extname(keyFile);
_t = ext;
_context2.n = _t === '.json' ? 1 : _t === '.der' ? 4 : _t === '.crt' ? 4 : _t === '.pem' ? 4 : _t === '.p12' ? 6 : _t === '.pfx' ? 6 : 7;
break;
case 1:
_context2.n = 2;
return readFile(keyFile, 'utf8');
case 2:
key = _context2.v;
body = JSON.parse(key);
privateKey = body.private_key;
clientEmail = body.client_email;
if (!(!privateKey || !clientEmail)) {
_context2.n = 3;
break;
}
throw new ErrorWithCode('private_key and client_email are required.', 'MISSING_CREDENTIALS');
case 3:
return _context2.a(2, {
privateKey: privateKey,
clientEmail: clientEmail
});
case 4:
_context2.n = 5;
return readFile(keyFile, 'utf8');
case 5:
_privateKey = _context2.v;
return _context2.a(2, {
privateKey: _privateKey
});
case 6:
throw new ErrorWithCode('*.p12 certificates are not supported after v6.1.2. ' + 'Consider utilizing *.json format or converting *.p12 to *.pem using the OpenSSL CLI.', 'UNKNOWN_CERTIFICATE_TYPE');
case 7:
throw new ErrorWithCode('Unknown certificate type. Type is determined based on file extension. ' + 'Current supported extensions are *.json, and *.pem.', 'UNKNOWN_CERTIFICATE_TYPE');
case 8:
return _context2.a(2);
}
}, _callee2);
}));
function getCredentials(_x) {
return _getCredentials.apply(this, arguments);
}
return getCredentials;
}())
}, {
key: "revokeToken",
value: function revokeToken(callback) {
if (callback) {
_assertClassBrand(_GoogleToken_brand, this, _revokeTokenAsync).call(this).then(function () {
return callback();
}, callback);
return;
}
return _assertClassBrand(_GoogleToken_brand, this, _revokeTokenAsync).call(this);
}
}]);
}();
function _getTokenAsync(_x2) {
return _getTokenAsync2.apply(this, arguments);
}
function _getTokenAsync2() {
_getTokenAsync2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(opts) {
return _regenerator().w(function (_context3) {
while (1) switch (_context3.n) {
case 0:
if (!(_classPrivateFieldGet(_inFlightRequest, this) && !opts.forceRefresh)) {
_context3.n = 1;
break;
}
return _context3.a(2, _classPrivateFieldGet(_inFlightRequest, this));
case 1:
_context3.p = 1;
_context3.n = 2;
return _classPrivateFieldSet(_inFlightRequest, this, _assertClassBrand(_GoogleToken_brand, this, _getTokenAsyncInner).call(this, opts));
case 2:
return _context3.a(2, _context3.v);
case 3:
_context3.p = 3;
_classPrivateFieldSet(_inFlightRequest, this, undefined);
return _context3.f(3);
case 4:
return _context3.a(2);
}
}, _callee3, this, [[1,, 3, 4]]);
}));
return _getTokenAsync2.apply(this, arguments);
}
function _getTokenAsyncInner(_x3) {
return _getTokenAsyncInner2.apply(this, arguments);
}
function _getTokenAsyncInner2() {
_getTokenAsyncInner2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(opts) {
var creds;
return _regenerator().w(function (_context4) {
while (1) switch (_context4.n) {
case 0:
if (!(this.isTokenExpiring() === false && opts.forceRefresh === false)) {
_context4.n = 1;
break;
}
return _context4.a(2, Promise.resolve(this.rawToken));
case 1:
if (!(!this.key && !this.keyFile)) {
_context4.n = 2;
break;
}
throw new Error('No key or keyFile set.');
case 2:
if (!(!this.key && this.keyFile)) {
_context4.n = 4;
break;
}
_context4.n = 3;
return this.getCredentials(this.keyFile);
case 3:
creds = _context4.v;
this.key = creds.privateKey;
this.iss = creds.clientEmail || this.iss;
if (!creds.clientEmail) {
_assertClassBrand(_GoogleToken_brand, this, _ensureEmail).call(this);
}
case 4:
return _context4.a(2, _assertClassBrand(_GoogleToken_brand, this, _requestToken).call(this));
}
}, _callee4, this);
}));
return _getTokenAsyncInner2.apply(this, arguments);
}
function _ensureEmail() {
if (!this.iss) {
throw new ErrorWithCode('email is required.', 'MISSING_CREDENTIALS');
}
}
function _revokeTokenAsync() {
return _revokeTokenAsync2.apply(this, arguments);
}
function _revokeTokenAsync2() {
_revokeTokenAsync2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
var url;
return _regenerator().w(function (_context5) {
while (1) switch (_context5.n) {
case 0:
if (this.accessToken) {
_context5.n = 1;
break;
}
throw new Error('No token to revoke.');
case 1:
url = GOOGLE_REVOKE_TOKEN_URL + this.accessToken;
_context5.n = 2;
return this.transporter.request({
url: url,
retry: true
});
case 2:
_assertClassBrand(_GoogleToken_brand, this, _configure).call(this, {
email: this.iss,
sub: this.sub,
key: this.key,
keyFile: this.keyFile,
scope: this.scope,
additionalClaims: this.additionalClaims
});
case 3:
return _context5.a(2);
}
}, _callee5, this);
}));
return _revokeTokenAsync2.apply(this, arguments);
}
/**
* Configure the GoogleToken for re-use.
* @param {object} options Configuration object.
*/
function _configure() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
this.keyFile = options.keyFile;
this.key = options.key;
this.rawToken = undefined;
this.iss = options.email || options.iss;
this.sub = options.sub;
this.additionalClaims = options.additionalClaims;
if (_typeof(options.scope) === 'object') {
this.scope = options.scope.join(' ');
} else {
this.scope = options.scope;
}
this.eagerRefreshThresholdMillis = options.eagerRefreshThresholdMillis;
if (options.transporter) {
this.transporter = options.transporter;
}
}
/**
* Request the token from Google.
*/
function _requestToken() {
return _requestToken2.apply(this, arguments);
}
function _requestToken2() {
_requestToken2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
var iat, additionalClaims, payload, signedJWT, r, _response, _response2, body, desc, _t2;
return _regenerator().w(function (_context6) {
while (1) switch (_context6.n) {
case 0:
iat = Math.floor(new Date().getTime() / 1000);
additionalClaims = this.additionalClaims || {};
payload = Object.assign({
iss: this.iss,
scope: this.scope,
aud: GOOGLE_TOKEN_URL,
exp: iat + 3600,
iat: iat,
sub: this.sub
}, additionalClaims);
signedJWT = jws.sign({
header: {
alg: 'RS256'
},
payload: payload,
secret: this.key
});
_context6.p = 1;
_context6.n = 2;
return this.transporter.request({
method: 'POST',
url: GOOGLE_TOKEN_URL,
data: new URLSearchParams({
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
assertion: signedJWT
}),
responseType: 'json',
retryConfig: {
httpMethodsToRetry: ['POST']
}
});
case 2:
r = _context6.v;
this.rawToken = r.data;
this.expiresAt = r.data.expires_in === null || r.data.expires_in === undefined ? undefined : (iat + r.data.expires_in) * 1000;
return _context6.a(2, this.rawToken);
case 3:
_context6.p = 3;
_t2 = _context6.v;
this.rawToken = undefined;
this.tokenExpires = undefined;
body = _t2.response && (_response = _t2.response) !== null && _response !== void 0 && _response.data ? (_response2 = _t2.response) === null || _response2 === void 0 ? void 0 : _response2.data : {};
if (body.error) {
desc = body.error_description ? ": ".concat(body.error_description) : '';
_t2.message = "".concat(body.error).concat(desc);
}
throw _t2;
case 4:
return _context6.a(2);
}
}, _callee6, this, [[1, 3]]);
}));
return _requestToken2.apply(this, arguments);
}

93
node_modules/gtoken/build/cjs/src/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,93 @@
/**
* Copyright 2018 Google LLC
*
* Distributed under MIT license.
* See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
import { GaxiosOptions, GaxiosPromise } from 'gaxios';
export interface Transporter {
request<T>(opts: GaxiosOptions): GaxiosPromise<T>;
}
export type GetTokenCallback = (err: Error | null, token?: TokenData) => void;
export interface Credentials {
privateKey: string;
clientEmail?: string;
}
export interface TokenData {
refresh_token?: string;
expires_in?: number;
access_token?: string;
token_type?: string;
id_token?: string;
}
export interface TokenOptions {
keyFile?: string;
key?: string;
email?: string;
iss?: string;
sub?: string;
scope?: string | string[];
additionalClaims?: {};
eagerRefreshThresholdMillis?: number;
transporter?: Transporter;
}
export interface GetTokenOptions {
forceRefresh?: boolean;
}
export declare class GoogleToken {
#private;
get accessToken(): string | undefined;
get idToken(): string | undefined;
get tokenType(): string | undefined;
get refreshToken(): string | undefined;
expiresAt?: number;
key?: string;
keyFile?: string;
iss?: string;
sub?: string;
scope?: string;
rawToken?: TokenData;
tokenExpires?: number;
email?: string;
additionalClaims?: {};
eagerRefreshThresholdMillis?: number;
transporter: Transporter;
/**
* Create a GoogleToken.
*
* @param options Configuration object.
*/
constructor(options?: TokenOptions);
/**
* Returns whether the token has expired.
*
* @return true if the token has expired, false otherwise.
*/
hasExpired(): boolean;
/**
* Returns whether the token will expire within eagerRefreshThresholdMillis
*
* @return true if the token will be expired within eagerRefreshThresholdMillis, false otherwise.
*/
isTokenExpiring(): boolean;
/**
* Returns a cached token or retrieves a new one from Google.
*
* @param callback The callback function.
*/
getToken(opts?: GetTokenOptions): Promise<TokenData>;
getToken(callback: GetTokenCallback, opts?: GetTokenOptions): void;
/**
* Given a keyFile, extract the key and client email if available
* @param keyFile Path to a json, pem, or p12 file that contains the key.
* @returns an object with privateKey and clientEmail properties
*/
getCredentials(keyFile: string): Promise<Credentials>;
/**
* Revoke the token if one is set.
*
* @param callback The callback function.
*/
revokeToken(): Promise<void>;
revokeToken(callback: (err?: Error) => void): void;
}

93
node_modules/gtoken/build/esm/src/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,93 @@
/**
* Copyright 2018 Google LLC
*
* Distributed under MIT license.
* See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
import { GaxiosOptions, GaxiosPromise } from 'gaxios';
export interface Transporter {
request<T>(opts: GaxiosOptions): GaxiosPromise<T>;
}
export type GetTokenCallback = (err: Error | null, token?: TokenData) => void;
export interface Credentials {
privateKey: string;
clientEmail?: string;
}
export interface TokenData {
refresh_token?: string;
expires_in?: number;
access_token?: string;
token_type?: string;
id_token?: string;
}
export interface TokenOptions {
keyFile?: string;
key?: string;
email?: string;
iss?: string;
sub?: string;
scope?: string | string[];
additionalClaims?: {};
eagerRefreshThresholdMillis?: number;
transporter?: Transporter;
}
export interface GetTokenOptions {
forceRefresh?: boolean;
}
export declare class GoogleToken {
#private;
get accessToken(): string | undefined;
get idToken(): string | undefined;
get tokenType(): string | undefined;
get refreshToken(): string | undefined;
expiresAt?: number;
key?: string;
keyFile?: string;
iss?: string;
sub?: string;
scope?: string;
rawToken?: TokenData;
tokenExpires?: number;
email?: string;
additionalClaims?: {};
eagerRefreshThresholdMillis?: number;
transporter: Transporter;
/**
* Create a GoogleToken.
*
* @param options Configuration object.
*/
constructor(options?: TokenOptions);
/**
* Returns whether the token has expired.
*
* @return true if the token has expired, false otherwise.
*/
hasExpired(): boolean;
/**
* Returns whether the token will expire within eagerRefreshThresholdMillis
*
* @return true if the token will be expired within eagerRefreshThresholdMillis, false otherwise.
*/
isTokenExpiring(): boolean;
/**
* Returns a cached token or retrieves a new one from Google.
*
* @param callback The callback function.
*/
getToken(opts?: GetTokenOptions): Promise<TokenData>;
getToken(callback: GetTokenCallback, opts?: GetTokenOptions): void;
/**
* Given a keyFile, extract the key and client email if available
* @param keyFile Path to a json, pem, or p12 file that contains the key.
* @returns an object with privateKey and clientEmail properties
*/
getCredentials(keyFile: string): Promise<Credentials>;
/**
* Revoke the token if one is set.
*
* @param callback The callback function.
*/
revokeToken(): Promise<void>;
revokeToken(callback: (err?: Error) => void): void;
}

275
node_modules/gtoken/build/esm/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,275 @@
/**
* Copyright 2018 Google LLC
*
* Distributed under MIT license.
* See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
import * as fs from 'fs';
import { request } from 'gaxios';
import * as jws from 'jws';
import * as path from 'path';
import { promisify } from 'util';
const readFile = fs.readFile
? promisify(fs.readFile)
: async () => {
// if running in the web-browser, fs.readFile may not have been shimmed.
throw new ErrorWithCode('use key rather than keyFile.', 'MISSING_CREDENTIALS');
};
const GOOGLE_TOKEN_URL = 'https://oauth2.googleapis.com/token';
const GOOGLE_REVOKE_TOKEN_URL = 'https://oauth2.googleapis.com/revoke?token=';
class ErrorWithCode extends Error {
code;
constructor(message, code) {
super(message);
this.code = code;
}
}
export class GoogleToken {
get accessToken() {
return this.rawToken ? this.rawToken.access_token : undefined;
}
get idToken() {
return this.rawToken ? this.rawToken.id_token : undefined;
}
get tokenType() {
return this.rawToken ? this.rawToken.token_type : undefined;
}
get refreshToken() {
return this.rawToken ? this.rawToken.refresh_token : undefined;
}
expiresAt;
key;
keyFile;
iss;
sub;
scope;
rawToken;
tokenExpires;
email;
additionalClaims;
eagerRefreshThresholdMillis;
transporter = {
request: opts => request(opts),
};
#inFlightRequest;
/**
* Create a GoogleToken.
*
* @param options Configuration object.
*/
constructor(options) {
this.#configure(options);
}
/**
* Returns whether the token has expired.
*
* @return true if the token has expired, false otherwise.
*/
hasExpired() {
const now = new Date().getTime();
if (this.rawToken && this.expiresAt) {
return now >= this.expiresAt;
}
else {
return true;
}
}
/**
* Returns whether the token will expire within eagerRefreshThresholdMillis
*
* @return true if the token will be expired within eagerRefreshThresholdMillis, false otherwise.
*/
isTokenExpiring() {
const now = new Date().getTime();
const eagerRefreshThresholdMillis = this.eagerRefreshThresholdMillis ?? 0;
if (this.rawToken && this.expiresAt) {
return this.expiresAt <= now + eagerRefreshThresholdMillis;
}
else {
return true;
}
}
getToken(callback, opts = {}) {
if (typeof callback === 'object') {
opts = callback;
callback = undefined;
}
opts = Object.assign({
forceRefresh: false,
}, opts);
if (callback) {
const cb = callback;
this.#getTokenAsync(opts).then(t => cb(null, t), callback);
return;
}
return this.#getTokenAsync(opts);
}
/**
* Given a keyFile, extract the key and client email if available
* @param keyFile Path to a json, pem, or p12 file that contains the key.
* @returns an object with privateKey and clientEmail properties
*/
async getCredentials(keyFile) {
const ext = path.extname(keyFile);
switch (ext) {
case '.json': {
const key = await readFile(keyFile, 'utf8');
const body = JSON.parse(key);
const privateKey = body.private_key;
const clientEmail = body.client_email;
if (!privateKey || !clientEmail) {
throw new ErrorWithCode('private_key and client_email are required.', 'MISSING_CREDENTIALS');
}
return { privateKey, clientEmail };
}
case '.der':
case '.crt':
case '.pem': {
const privateKey = await readFile(keyFile, 'utf8');
return { privateKey };
}
case '.p12':
case '.pfx': {
throw new ErrorWithCode('*.p12 certificates are not supported after v6.1.2. ' +
'Consider utilizing *.json format or converting *.p12 to *.pem using the OpenSSL CLI.', 'UNKNOWN_CERTIFICATE_TYPE');
}
default:
throw new ErrorWithCode('Unknown certificate type. Type is determined based on file extension. ' +
'Current supported extensions are *.json, and *.pem.', 'UNKNOWN_CERTIFICATE_TYPE');
}
}
async #getTokenAsync(opts) {
if (this.#inFlightRequest && !opts.forceRefresh) {
return this.#inFlightRequest;
}
try {
return await (this.#inFlightRequest = this.#getTokenAsyncInner(opts));
}
finally {
this.#inFlightRequest = undefined;
}
}
async #getTokenAsyncInner(opts) {
if (this.isTokenExpiring() === false && opts.forceRefresh === false) {
return Promise.resolve(this.rawToken);
}
if (!this.key && !this.keyFile) {
throw new Error('No key or keyFile set.');
}
if (!this.key && this.keyFile) {
const creds = await this.getCredentials(this.keyFile);
this.key = creds.privateKey;
this.iss = creds.clientEmail || this.iss;
if (!creds.clientEmail) {
this.#ensureEmail();
}
}
return this.#requestToken();
}
#ensureEmail() {
if (!this.iss) {
throw new ErrorWithCode('email is required.', 'MISSING_CREDENTIALS');
}
}
revokeToken(callback) {
if (callback) {
this.#revokeTokenAsync().then(() => callback(), callback);
return;
}
return this.#revokeTokenAsync();
}
async #revokeTokenAsync() {
if (!this.accessToken) {
throw new Error('No token to revoke.');
}
const url = GOOGLE_REVOKE_TOKEN_URL + this.accessToken;
await this.transporter.request({
url,
retry: true,
});
this.#configure({
email: this.iss,
sub: this.sub,
key: this.key,
keyFile: this.keyFile,
scope: this.scope,
additionalClaims: this.additionalClaims,
});
}
/**
* Configure the GoogleToken for re-use.
* @param {object} options Configuration object.
*/
#configure(options = {}) {
this.keyFile = options.keyFile;
this.key = options.key;
this.rawToken = undefined;
this.iss = options.email || options.iss;
this.sub = options.sub;
this.additionalClaims = options.additionalClaims;
if (typeof options.scope === 'object') {
this.scope = options.scope.join(' ');
}
else {
this.scope = options.scope;
}
this.eagerRefreshThresholdMillis = options.eagerRefreshThresholdMillis;
if (options.transporter) {
this.transporter = options.transporter;
}
}
/**
* Request the token from Google.
*/
async #requestToken() {
const iat = Math.floor(new Date().getTime() / 1000);
const additionalClaims = this.additionalClaims || {};
const payload = Object.assign({
iss: this.iss,
scope: this.scope,
aud: GOOGLE_TOKEN_URL,
exp: iat + 3600,
iat,
sub: this.sub,
}, additionalClaims);
const signedJWT = jws.sign({
header: { alg: 'RS256' },
payload,
secret: this.key,
});
try {
const r = await this.transporter.request({
method: 'POST',
url: GOOGLE_TOKEN_URL,
data: new URLSearchParams({
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
assertion: signedJWT,
}),
responseType: 'json',
retryConfig: {
httpMethodsToRetry: ['POST'],
},
});
this.rawToken = r.data;
this.expiresAt =
r.data.expires_in === null || r.data.expires_in === undefined
? undefined
: (iat + r.data.expires_in) * 1000;
return this.rawToken;
}
catch (e) {
this.rawToken = undefined;
this.tokenExpires = undefined;
const body = e.response && e.response?.data
? e.response?.data
: {};
if (body.error) {
const desc = body.error_description
? `: ${body.error_description}`
: '';
e.message = `${body.error}${desc}`;
}
throw e;
}
}
}

99
node_modules/gtoken/package.json generated vendored Normal file
View File

@@ -0,0 +1,99 @@
{
"name": "gtoken",
"version": "8.0.0",
"description": "Node.js Google Authentication Service Account Tokens",
"main": "./build/cjs/src/index.cjs",
"type": "module",
"types": "./build/cjs/src/index.d.ts",
"engines": {
"node": ">=18"
},
"repository": "google/node-gtoken",
"scripts": {
"lint": "gts check",
"clean": "rm -rf build",
"fix": "gts fix",
"compile:esm": "tsc -p ./tsconfig.esm.json",
"compile:cjs": "tsc -p ./tsconfig.json && npm run babel",
"compile": "npm run compile:esm && npm run compile:cjs",
"prepare": "npm run compile",
"pretest": "npm run compile",
"presystem-test": "npm run compile",
"system-test:cjs": "mocha build/cjs/system-test --timeout 600000",
"system-test:esm": "mocha build/esm/system-test --timeout 600000 --experimental-modules",
"system-test": "npm run system-test:esm && npm run system-test:cjs",
"test:cjs": "c8 mocha --timeout=5000 build/cjs/test",
"test:esm": "c8 mocha build/esm/test --loader=esmock",
"test": "npm run test:esm && npm run test:cjs",
"docs": "jsdoc -c .jsdoc.json",
"predocs-test": "npm run docs",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
"prelint": "cd samples; npm link ../; npm install",
"precompile": "rm -rf build",
"babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files"
},
"exports": {
".": {
"import": {
"types": "./build/esm/src/index.d.ts",
"default": "./build/esm/src/index.js"
},
"require": {
"types": "./build/cjs/src/index.d.ts",
"default": "./build/cjs/src/index.cjs"
}
}
},
"keywords": [
"google",
"service",
"account",
"api",
"token",
"api",
"auth"
],
"author": {
"name": "Google, LLC"
},
"license": "MIT",
"dependencies": {
"gaxios": "^7.0.0",
"jws": "^4.0.0"
},
"devDependencies": {
"@babel/cli": "^7.23.0",
"@babel/core": "^7.23.0",
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@babel/preset-env": "^7.22.20",
"@babel/preset-typescript": "^7.23.0",
"@types/jws": "^3.2.10",
"@types/mocha": "^10.0.9",
"@types/node": "^22.9.0",
"babel-plugin-replace-import-extension": "^1.1.4",
"c8": "^10.1.2",
"esmock": "^2.6.9",
"gapic-tools": "^0.4.6",
"gts": "^6.0.2",
"jsdoc": "^4.0.4",
"jsdoc-fresh": "^4.0.0",
"jsdoc-region-tag": "^3.0.0",
"linkinator": "^6.1.2",
"mocha": "^10.8.2",
"nock": "^14.0.0",
"pack-n-play": "^2.1.0",
"pdfmake": "^0.2.15",
"proxyquire": "^2.1.3",
"typescript": "^5.6.3"
},
"files": [
"build/esm",
"build/cjs",
"!build/cjs/system-test",
"!build/esm/system-test",
"!build/cjs/test",
"!build/esm/test",
"!build/esm/**/*.map",
"!build/cjs/**/*.map"
]
}