@looker/sdk-node 22.20.0 → 23.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/lib/esm/index.js +60 -5
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/nodeSdk.js +18 -14
- package/lib/esm/nodeSdk.js.map +1 -1
- package/lib/esm/nodeServices.js +15 -12
- package/lib/esm/nodeServices.js.map +1 -1
- package/lib/esm/nodeSession.js +18 -66
- package/lib/esm/nodeSession.js.map +1 -1
- package/lib/esm/nodeSettings.js +36 -45
- package/lib/esm/nodeSettings.js.map +1 -1
- package/lib/esm/nodeTransport.js +61 -97
- package/lib/esm/nodeTransport.js.map +1 -1
- package/lib/esm/testUtils/index.js +17 -0
- package/lib/esm/testUtils/index.js.map +1 -0
- package/lib/esm/testUtils/testUtils.js +55 -0
- package/lib/esm/testUtils/testUtils.js.map +1 -0
- package/lib/index.js +0 -10
- package/lib/index.js.map +1 -1
- package/lib/nodeSdk.js +0 -7
- package/lib/nodeSdk.js.map +1 -1
- package/lib/nodeServices.js +3 -11
- package/lib/nodeServices.js.map +1 -1
- package/lib/nodeSession.js +3 -63
- package/lib/nodeSession.js.map +1 -1
- package/lib/nodeSettings.js +6 -49
- package/lib/nodeSettings.js.map +1 -1
- package/lib/nodeTransport.js +15 -72
- package/lib/nodeTransport.js.map +1 -1
- package/lib/testUtils/index.js +0 -2
- package/lib/testUtils/index.js.map +1 -1
- package/lib/testUtils/testUtils.js +1 -15
- package/lib/testUtils/testUtils.js.map +1 -1
- package/package.json +5 -5
package/lib/nodeSession.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/nodeSession.ts"],"names":["strPost","strDelete","NodeSession","AuthSession","constructor","settings","transport","NodeTransport","AuthToken","activeToken","_sudoToken","access_token","_authToken","isAuthenticated","token","isActive","authenticate","props","getToken","headers","Authorization","isSudo","sudoId","login","reset","_login","toString","logout","result","_logout","sudoLogout","newId","section","readConfig","clientId","client_id","clientSecret","client_secret","message","body","ok","request","apiPath","undefined","setToken","promise","encodeURI","init","accessToken"],"mappings":";;;;;;;AAkCA;;AACA;;;;;;;;AAEA,IAAMA,OAAmB,GAAG,MAA5B;AACA,IAAMC,SAAqB,GAAG,QAA9B;;AAEO,MAAMC,WAAN,SAA0BC,mBAA1B,CAAsC;AAK3CC,EAAAA,WAAW,CAAQC,QAAR,EAAgCC,SAAhC,EAAwD;AACjE,UAAMD,QAAN,EAAgBC,SAAS,IAAI,IAAIC,4BAAJ,CAAkBF,QAAlB,CAA7B;AADiE,SAAhDA,QAAgD,GAAhDA,QAAgD;;AAAA,qCAJhC,UAIgC;;AAAA,wCAH3C,IAAIG,iBAAJ,EAG2C;;AAAA,wCAF3C,IAAIA,iBAAJ,EAE2C;AAElE;;AAKc,MAAXC,WAAW,GAAG;AAChB,QAAI,KAAKC,UAAL,CAAgBC,YAApB,EAAkC;AAChC,aAAO,KAAKD,UAAZ;AACD;;AACD,WAAO,KAAKE,UAAZ;AACD;;AAKDC,EAAAA,eAAe,GAAG;AAEhB,QAAMC,KAAK,GAAG,KAAKL,WAAnB;AACA,QAAI,EAAEK,KAAK,IAAIA,KAAK,CAACH,YAAjB,CAAJ,EAAoC,OAAO,KAAP;AACpC,WAAOG,KAAK,CAACC,QAAN,EAAP;AACD;;AAQKC,EAAAA,YAAY,CAACC,KAAD,EAAuB;AAAA;;AAAA;AACvC,UAAMH,KAAK,SAAS,KAAI,CAACI,QAAL,EAApB;;AACA,UAAIJ,KAAK,IAAIA,KAAK,CAACH,YAAnB,EAAiC;AAC/BM,QAAAA,KAAK,CAACE,OAAN,CAAcC,aAAd,oBAAwCN,KAAK,CAACH,YAA9C;AACD;;AACD,aAAOM,KAAP;AALuC;AAMxC;;AAEDI,EAAAA,MAAM,GAAG;AACP,WAAO,CAAC,CAAC,KAAKC,MAAP,IAAiB,KAAKZ,UAAL,CAAgBK,QAAhB,EAAxB;AACD;;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D,SAXa,EAYd,MAAI,CAAC1C,QAZS,CAAhB;;AAeA,YAAM2C,WAAW,SAAS,MAAI,CAACR,EAAL,CAAQK,OAAR,CAA1B;;AAEA,QAAA,MAAI,CAACnC,UAAL,CAAgBkC,QAAhB,CAAyBI,WAAzB;AACD;;AAED,aAAO,MAAI,CAACvC,WAAZ;AA3DmC;AA4DpC;;AAEaoB,EAAAA,OAAO,GAAG;AAAA;;AAAA;AACtB,UAAMf,KAAK,GAAG,MAAI,CAACL,WAAnB;;AACA,UAAMoC,OAAO,GAAG,MAAI,CAACvC,SAAL,CAAemC,OAAf,CACdxC,SADc,YAEX,MAAI,CAACyC,OAFM,cAGd,IAHc,EAId,IAJc,EAMbK,IAAD,IAAyB;AACvB,YAAIjC,KAAK,CAACH,YAAV,EAAwB;AACtBoC,UAAAA,IAAI,CAAC5B,OAAL,CAAaC,aAAb,oBAAuCN,KAAK,CAACH,YAA7C;AACD;;AACD,eAAOoC,IAAP;AACD,OAXa,EAYd,MAAI,CAAC1C,QAZS,CAAhB;;AAeA,YAAM,MAAI,CAACmC,EAAL,CAAQK,OAAR,CAAN;;AAGA,UAAI,MAAI,CAACvB,MAAT,EAAiB;AAEf,QAAA,MAAI,CAACA,MAAL,GAAc,EAAd;;AACA,QAAA,MAAI,CAACZ,UAAL,CAAgBc,KAAhB;;AACA,YAAI,CAAC,MAAI,CAACZ,UAAL,CAAgBG,QAAhB,EAAL,EAAiC;AAC/B,gBAAM,MAAI,CAACQ,KAAL,EAAN;AACD;AACF,OAPD,MAOO;AAEL,QAAA,MAAI,CAACC,KAAL;AACD;;AACD,aAAO,IAAP;AA/BsB;AAgCvB;;AAtM0C","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type {\n IRequestProps,\n ITransport,\n HttpMethod,\n IApiSettings,\n IAccessToken,\n IError,\n} from '@looker/sdk-rtl'\nimport { sdkError, encodeParams, AuthToken, AuthSession } from '@looker/sdk-rtl'\nimport { NodeTransport } from './nodeTransport'\n\nconst strPost: HttpMethod = 'POST'\nconst strDelete: HttpMethod = 'DELETE'\n\nexport class NodeSession extends AuthSession {\n private readonly apiPath: string = '/api/4.0'\n _authToken: AuthToken = new AuthToken()\n _sudoToken: AuthToken = new AuthToken()\n\n constructor(public settings: IApiSettings, transport?: ITransport) {\n super(settings, transport || new NodeTransport(settings))\n }\n\n /**\n * Abstraction of AuthToken retrieval to support sudo mode\n */\n get activeToken() {\n if (this._sudoToken.access_token) {\n return this._sudoToken\n }\n return this._authToken\n }\n\n /**\n * Is there an active authentication token?\n */\n isAuthenticated() {\n // TODO I think this can be simplified\n const token = this.activeToken\n if (!(token && token.access_token)) return false\n return token.isActive()\n }\n\n /**\n * Add authentication data to the pending API request\n * @param props initialized API request properties\n *\n * @returns the updated request properties\n */\n async authenticate(props: IRequestProps) {\n const token = await this.getToken()\n if (token && token.access_token) {\n props.headers.Authorization = `Bearer ${token.access_token}`\n }\n return props\n }\n\n isSudo() {\n return !!this.sudoId && this._sudoToken.isActive()\n }\n\n /**\n * retrieve the current authentication token. If there is no active token, performs default\n * login to retrieve the token\n */\n async getToken() {\n if (!this.isAuthenticated()) {\n await this.login()\n }\n return this.activeToken\n }\n\n /**\n * Reset the authentication session\n */\n reset() {\n this.sudoId = ''\n this._authToken.reset()\n this._sudoToken.reset()\n }\n\n /**\n * Activate the authentication token for the API3 or sudo user\n * @param sudoId {string | number}: optional. If provided, impersonates the user specified\n *\n */\n async login(sudoId?: string | number) {\n if (sudoId || sudoId !== this.sudoId || !this.isAuthenticated()) {\n if (sudoId) {\n await this._login(sudoId.toString())\n } else {\n await this._login()\n }\n }\n return this.activeToken\n }\n\n /**\n * Logout the active user. If the active user is sudo, the session reverts to the API3 user\n */\n async logout() {\n let result = false\n if (this.isAuthenticated()) {\n result = await this._logout()\n }\n return result\n }\n\n private async sudoLogout() {\n let result = false\n if (this.isSudo()) {\n result = await this.logout() // Logout the current sudo\n this._sudoToken.reset()\n }\n return result\n }\n\n // internal login method that manages default auth token and sudo workflow\n private async _login(newId?: string) {\n // for linty freshness, always logout sudo if set\n await this.sudoLogout()\n\n if (newId !== this.sudoId) {\n // Assign new requested sudo id\n this.sudoId = newId || ''\n }\n\n if (!this._authToken.isActive()) {\n this.reset()\n // only retain client API3 credentials for the lifetime of the login request\n const section = this.settings.readConfig()\n const clientId = section.client_id\n const clientSecret = section.client_secret\n if (!clientId || !clientSecret) {\n throw sdkError({\n message: 'API credentials client_id and/or client_secret are not set',\n })\n }\n const body = encodeParams({\n client_id: clientId,\n client_secret: clientSecret,\n })\n // authenticate client\n const token = await this.ok(\n this.transport.request<IAccessToken, IError>(\n strPost,\n `${this.apiPath}/login`,\n undefined,\n body\n )\n )\n this._authToken.setToken(token)\n }\n\n if (this.sudoId) {\n // Use the API user auth to sudo\n const token = this.activeToken\n const promise = this.transport.request<IAccessToken, IError>(\n strPost,\n encodeURI(`${this.apiPath}/login/${newId}`),\n null,\n null,\n // ensure the auth token is included in the sudo request\n (init: IRequestProps) => {\n if (token.access_token) {\n init.headers.Authorization = `Bearer ${token.access_token}`\n }\n return init\n },\n this.settings // TODO this may not be needed here\n )\n\n const accessToken = await this.ok(promise)\n\n this._sudoToken.setToken(accessToken)\n }\n\n return this.activeToken\n }\n\n private async _logout() {\n const token = this.activeToken\n const promise = this.transport.request<string, IError>(\n strDelete,\n `${this.apiPath}/logout`,\n null,\n null,\n // ensure the auth token is included in the logout promise\n (init: IRequestProps) => {\n if (token.access_token) {\n init.headers.Authorization = `Bearer ${token.access_token}`\n }\n return init\n },\n this.settings\n )\n\n await this.ok(promise)\n\n // If no error was thrown, logout was successful\n if (this.sudoId) {\n // User was logged out, so set auth back to default\n this.sudoId = ''\n this._sudoToken.reset()\n if (!this._authToken.isActive()) {\n await this.login()\n }\n } else {\n // completely logged out\n this.reset()\n }\n return true\n }\n}\n"],"file":"nodeSession.js"}
|
|
1
|
+
{"version":3,"file":"nodeSession.js","names":["strPost","strDelete","NodeSession","AuthSession","constructor","settings","transport","NodeTransport","AuthToken","activeToken","_sudoToken","access_token","_authToken","isAuthenticated","token","isActive","authenticate","props","getToken","headers","Authorization","isSudo","sudoId","login","reset","_login","toString","logout","result","_logout","sudoLogout","newId","section","readConfig","clientId","client_id","clientSecret","client_secret","sdkError","message","body","encodeParams","ok","request","apiPath","undefined","setToken","promise","encodeURI","init","accessToken"],"sources":["../src/nodeSession.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type {\n IRequestProps,\n ITransport,\n HttpMethod,\n IApiSettings,\n IAccessToken,\n IError,\n} from '@looker/sdk-rtl'\nimport { sdkError, encodeParams, AuthToken, AuthSession } from '@looker/sdk-rtl'\nimport { NodeTransport } from './nodeTransport'\n\nconst strPost: HttpMethod = 'POST'\nconst strDelete: HttpMethod = 'DELETE'\n\nexport class NodeSession extends AuthSession {\n private readonly apiPath: string = '/api/4.0'\n _authToken: AuthToken = new AuthToken()\n _sudoToken: AuthToken = new AuthToken()\n\n constructor(public settings: IApiSettings, transport?: ITransport) {\n super(settings, transport || new NodeTransport(settings))\n }\n\n /**\n * Abstraction of AuthToken retrieval to support sudo mode\n */\n get activeToken() {\n if (this._sudoToken.access_token) {\n return this._sudoToken\n }\n return this._authToken\n }\n\n /**\n * Is there an active authentication token?\n */\n isAuthenticated() {\n // TODO I think this can be simplified\n const token = this.activeToken\n if (!(token && token.access_token)) return false\n return token.isActive()\n }\n\n /**\n * Add authentication data to the pending API request\n * @param props initialized API request properties\n *\n * @returns the updated request properties\n */\n async authenticate(props: IRequestProps) {\n const token = await this.getToken()\n if (token && token.access_token) {\n props.headers.Authorization = `Bearer ${token.access_token}`\n }\n return props\n }\n\n isSudo() {\n return !!this.sudoId && this._sudoToken.isActive()\n }\n\n /**\n * retrieve the current authentication token. If there is no active token, performs default\n * login to retrieve the token\n */\n async getToken() {\n if (!this.isAuthenticated()) {\n await this.login()\n }\n return this.activeToken\n }\n\n /**\n * Reset the authentication session\n */\n reset() {\n this.sudoId = ''\n this._authToken.reset()\n this._sudoToken.reset()\n }\n\n /**\n * Activate the authentication token for the API3 or sudo user\n * @param sudoId {string | number}: optional. If provided, impersonates the user specified\n *\n */\n async login(sudoId?: string | number) {\n if (sudoId || sudoId !== this.sudoId || !this.isAuthenticated()) {\n if (sudoId) {\n await this._login(sudoId.toString())\n } else {\n await this._login()\n }\n }\n return this.activeToken\n }\n\n /**\n * Logout the active user. If the active user is sudo, the session reverts to the API3 user\n */\n async logout() {\n let result = false\n if (this.isAuthenticated()) {\n result = await this._logout()\n }\n return result\n }\n\n private async sudoLogout() {\n let result = false\n if (this.isSudo()) {\n result = await this.logout() // Logout the current sudo\n this._sudoToken.reset()\n }\n return result\n }\n\n // internal login method that manages default auth token and sudo workflow\n private async _login(newId?: string) {\n // for linty freshness, always logout sudo if set\n await this.sudoLogout()\n\n if (newId !== this.sudoId) {\n // Assign new requested sudo id\n this.sudoId = newId || ''\n }\n\n if (!this._authToken.isActive()) {\n this.reset()\n // only retain client API3 credentials for the lifetime of the login request\n const section = this.settings.readConfig()\n const clientId = section.client_id\n const clientSecret = section.client_secret\n if (!clientId || !clientSecret) {\n throw sdkError({\n message: 'API credentials client_id and/or client_secret are not set',\n })\n }\n const body = encodeParams({\n client_id: clientId,\n client_secret: clientSecret,\n })\n // authenticate client\n const token = await this.ok(\n this.transport.request<IAccessToken, IError>(\n strPost,\n `${this.apiPath}/login`,\n undefined,\n body\n )\n )\n this._authToken.setToken(token)\n }\n\n if (this.sudoId) {\n // Use the API user auth to sudo\n const token = this.activeToken\n const promise = this.transport.request<IAccessToken, IError>(\n strPost,\n encodeURI(`${this.apiPath}/login/${newId}`),\n null,\n null,\n // ensure the auth token is included in the sudo request\n (init: IRequestProps) => {\n if (token.access_token) {\n init.headers.Authorization = `Bearer ${token.access_token}`\n }\n return init\n },\n this.settings // TODO this may not be needed here\n )\n\n const accessToken = await this.ok(promise)\n\n this._sudoToken.setToken(accessToken)\n }\n\n return this.activeToken\n }\n\n private async _logout() {\n const token = this.activeToken\n const promise = this.transport.request<string, IError>(\n strDelete,\n `${this.apiPath}/logout`,\n null,\n null,\n // ensure the auth token is included in the logout promise\n (init: IRequestProps) => {\n if (token.access_token) {\n init.headers.Authorization = `Bearer ${token.access_token}`\n }\n return init\n },\n this.settings\n )\n\n await this.ok(promise)\n\n // If no error was thrown, logout was successful\n if (this.sudoId) {\n // User was logged out, so set auth back to default\n this.sudoId = ''\n this._sudoToken.reset()\n if (!this._authToken.isActive()) {\n await this.login()\n }\n } else {\n // completely logged out\n this.reset()\n }\n return true\n }\n}\n"],"mappings":";;;;;;AAkCA;AACA;AAA+C;AAAA;AAAA;AAAA;AAAA;AAE/C,IAAMA,OAAmB,GAAG,MAAM;AAClC,IAAMC,SAAqB,GAAG,QAAQ;AAE/B,MAAMC,WAAW,SAASC,mBAAW,CAAC;EAK3CC,WAAW,CAAQC,QAAsB,EAAEC,SAAsB,EAAE;IACjE,KAAK,CAACD,QAAQ,EAAEC,SAAS,IAAI,IAAIC,4BAAa,CAACF,QAAQ,CAAC,CAAC;IAAA,KADxCA,QAAsB,GAAtBA,QAAsB;IAAA,iCAJN,UAAU;IAAA,oCACrB,IAAIG,iBAAS,EAAE;IAAA,oCACf,IAAIA,iBAAS,EAAE;EAIvC;EAKA,IAAIC,WAAW,GAAG;IAChB,IAAI,IAAI,CAACC,UAAU,CAACC,YAAY,EAAE;MAChC,OAAO,IAAI,CAACD,UAAU;IACxB;IACA,OAAO,IAAI,CAACE,UAAU;EACxB;EAKAC,eAAe,GAAG;IAEhB,IAAMC,KAAK,GAAG,IAAI,CAACL,WAAW;IAC9B,IAAI,EAAEK,KAAK,IAAIA,KAAK,CAACH,YAAY,CAAC,EAAE,OAAO,KAAK;IAChD,OAAOG,KAAK,CAACC,QAAQ,EAAE;EACzB;EAQMC,YAAY,CAACC,KAAoB,EAAE;IAAA;IAAA;MACvC,IAAMH,KAAK,SAAS,KAAI,CAACI,QAAQ,EAAE;MACnC,IA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4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.readIniConfig = exports.readEnvConfig = exports.getenv = exports.NodeSettingsIniFile = exports.NodeSettings = exports.ApiConfigSection = exports.ApiConfig = void 0;
|
|
8
7
|
var fs = _interopRequireWildcard(require("fs"));
|
|
9
|
-
|
|
10
8
|
var ini = _interopRequireWildcard(require("ini"));
|
|
11
|
-
|
|
12
9
|
var _sdkRtl = require("@looker/sdk-rtl");
|
|
13
|
-
|
|
14
10
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
-
|
|
16
11
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
-
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
16
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
24
17
|
var getenv = function getenv(name) {
|
|
25
18
|
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
26
19
|
var val = process.env[name];
|
|
27
20
|
return val === undefined ? defaultValue : val;
|
|
28
21
|
};
|
|
29
|
-
|
|
30
22
|
exports.getenv = getenv;
|
|
31
|
-
|
|
32
23
|
var ApiConfig = contents => ini.parse(contents);
|
|
33
|
-
|
|
34
24
|
exports.ApiConfig = ApiConfig;
|
|
35
|
-
|
|
36
25
|
var ApiConfigSection = (contents, section) => {
|
|
37
26
|
var config = ApiConfig(contents);
|
|
38
|
-
|
|
39
27
|
if (!section) {
|
|
40
28
|
section = Object.keys(config)[0];
|
|
41
29
|
}
|
|
42
|
-
|
|
43
30
|
var settings = config[section];
|
|
44
|
-
|
|
45
31
|
if (!settings) {
|
|
46
32
|
throw new Error("No section named \"".concat(section, "\" was found"));
|
|
47
33
|
}
|
|
48
|
-
|
|
49
34
|
if (settings.api_version) {
|
|
50
35
|
console.warn('api_version is no longer read from a configuration file by the SDK');
|
|
51
36
|
}
|
|
52
|
-
|
|
53
37
|
return settings;
|
|
54
38
|
};
|
|
55
|
-
|
|
56
39
|
exports.ApiConfigSection = ApiConfigSection;
|
|
57
|
-
|
|
58
40
|
var readEnvConfig = envPrefix => {
|
|
59
41
|
var values = {};
|
|
60
42
|
var configMap = (0, _sdkRtl.ApiConfigMap)(envPrefix);
|
|
61
43
|
Object.keys(configMap).forEach(key => {
|
|
62
44
|
var envKey = configMap[key];
|
|
63
|
-
|
|
64
45
|
if (process.env[envKey] !== undefined) {
|
|
65
46
|
var val = (0, _sdkRtl.unquote)(process.env[envKey]);
|
|
66
47
|
values[key] = val;
|
|
@@ -68,89 +49,65 @@ var readEnvConfig = envPrefix => {
|
|
|
68
49
|
});
|
|
69
50
|
return values;
|
|
70
51
|
};
|
|
71
|
-
|
|
72
52
|
exports.readEnvConfig = readEnvConfig;
|
|
73
|
-
|
|
74
53
|
var readIniConfig = (fileName, envPrefix, section) => {
|
|
75
54
|
var config = readEnvConfig(envPrefix);
|
|
76
|
-
|
|
77
55
|
if (fileName && fs.existsSync(fileName)) {
|
|
78
56
|
config = _objectSpread(_objectSpread({}, ApiConfigSection(fs.readFileSync(fileName, 'utf8'), section)), config);
|
|
79
57
|
}
|
|
80
|
-
|
|
81
58
|
Object.keys(config).forEach(key => {
|
|
82
59
|
var val = config[key];
|
|
83
|
-
|
|
84
60
|
if (typeof val === 'string') {
|
|
85
61
|
config[key] = (0, _sdkRtl.unquote)(val);
|
|
86
62
|
}
|
|
87
63
|
});
|
|
88
64
|
return config;
|
|
89
65
|
};
|
|
90
|
-
|
|
91
66
|
exports.readIniConfig = readIniConfig;
|
|
92
|
-
|
|
93
67
|
class NodeSettings extends _sdkRtl.ApiSettings {
|
|
94
68
|
constructor(envPrefix, contents, section) {
|
|
95
69
|
var settings;
|
|
96
|
-
|
|
97
70
|
if (contents) {
|
|
98
71
|
if (typeof contents === 'string') {
|
|
99
72
|
settings = ApiConfigSection(contents, section);
|
|
100
73
|
} else {
|
|
101
74
|
settings = contents;
|
|
102
75
|
}
|
|
103
|
-
|
|
104
76
|
settings = _objectSpread(_objectSpread({}, readEnvConfig(envPrefix)), settings);
|
|
105
77
|
} else {
|
|
106
78
|
settings = readEnvConfig(envPrefix);
|
|
107
79
|
}
|
|
108
|
-
|
|
109
80
|
super(_objectSpread(_objectSpread({}, (0, _sdkRtl.DefaultSettings)()), settings));
|
|
110
|
-
|
|
111
81
|
_defineProperty(this, "envPrefix", void 0);
|
|
112
|
-
|
|
113
82
|
_defineProperty(this, "section", void 0);
|
|
114
|
-
|
|
115
83
|
this.section = section !== null && section !== void 0 ? section : '';
|
|
116
84
|
this.envPrefix = envPrefix;
|
|
117
85
|
}
|
|
118
|
-
|
|
119
86
|
readConfig(_section) {
|
|
120
87
|
return readEnvConfig(this.envPrefix);
|
|
121
88
|
}
|
|
122
|
-
|
|
123
89
|
}
|
|
124
|
-
|
|
125
90
|
exports.NodeSettings = NodeSettings;
|
|
126
|
-
|
|
127
91
|
class NodeSettingsIniFile extends NodeSettings {
|
|
128
92
|
constructor(envPrefix) {
|
|
129
93
|
var fileName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
130
94
|
var section = arguments.length > 2 ? arguments[2] : undefined;
|
|
131
|
-
|
|
132
95
|
if (fileName && !fs.existsSync(fileName)) {
|
|
133
96
|
throw (0, _sdkRtl.sdkError)({
|
|
134
97
|
message: "File ".concat(fileName, " was not found")
|
|
135
98
|
});
|
|
136
99
|
}
|
|
137
|
-
|
|
138
100
|
fileName = fileName || './looker.ini';
|
|
139
101
|
var config = readIniConfig(fileName, envPrefix, section);
|
|
140
102
|
var settings = (0, _sdkRtl.ValueSettings)(config, envPrefix);
|
|
141
103
|
super(envPrefix, settings, section);
|
|
142
|
-
|
|
143
104
|
_defineProperty(this, "fileName", void 0);
|
|
144
|
-
|
|
145
105
|
this.fileName = fileName;
|
|
146
106
|
}
|
|
147
|
-
|
|
148
107
|
readConfig(section) {
|
|
149
108
|
section = section || this.section;
|
|
150
109
|
return readIniConfig(this.fileName, this.envPrefix, section);
|
|
151
110
|
}
|
|
152
|
-
|
|
153
111
|
}
|
|
154
|
-
|
|
155
112
|
exports.NodeSettingsIniFile = NodeSettingsIniFile;
|
|
156
113
|
//# sourceMappingURL=nodeSettings.js.map
|
package/lib/nodeSettings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/nodeSettings.ts"],"names":["getenv","name","defaultValue","undefined","val","process","env","ApiConfig","contents","ini","parse","ApiConfigSection","section","config","Object","keys","settings","Error","api_version","console","warn","readEnvConfig","envPrefix","values","configMap","forEach","key","envKey","readIniConfig","fileName","fs","existsSync","readFileSync","NodeSettings","ApiSettings","constructor","readConfig","_section","NodeSettingsIniFile","message"],"mappings":";;;;;;;AA0BA;;AACA;;AAEA;;;;;;;;;;;;AAeO,IAAMA,MAAM,GAAG,SAATA,MAAS,CACpBC,IADoB,EAGjB;AAAA,MADHC,YACG,uEADgCC,SAChC;AACH,MAAMC,GAAG,GAAGC,OAAO,CAACC,GAAR,CAAYL,IAAZ,CAAZ;AACA,SAAOG,GAAG,KAAKD,SAAR,GAAoBD,YAApB,GAAmCE,GAA1C;AACD,CANM;;;;AAoBA,IAAMG,SAAS,GAAIC,QAAD,IAAkCC,GAAG,CAACC,KAAJ,CAAUF,QAAV,CAApD;;;;AAQA,IAAMG,gBAAgB,GAAG,CAC9BH,QAD8B,EAE9BI,OAF8B,KAGd;AAChB,MAAMC,MAAM,GAAGN,SAAS,CAACC,QAAD,CAAxB;;AACA,MAAI,CAACI,OAAL,EAAc;AAEZA,IAAAA,OAAO,GAAGE,MAAM,CAACC,IAAP,CAAYF,M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iBAAUV,QAAV;AAAT,OAAT,CAAN;AACD;;AAEDA,IAAAA,QAAQ,GAAGA,QAAQ,IAAI,cAAvB;AACA,QAAMhB,MAAM,GAAGe,aAAa,CAACC,QAAD,EAAWP,SAAX,EAAsBV,OAAtB,CAA5B;AACA,QAAMI,QAAQ,GAAG,2BAAcH,MAAd,EAAsBS,SAAtB,CAAjB;AACA,UAAMA,SAAN,EAAiBN,QAAjB,EAA2BJ,OAA3B;;AAR8D;;AAS9D,SAAKiB,QAAL,GAAgBA,QAAhB;AACD;;AAYDO,EAAAA,UAAU,CAACxB,OAAD,EAAgC;AACxCA,IAAAA,OAAO,GAAGA,OAAO,IAAI,KAAKA,OAA1B;AACA,WAAOgB,aAAa,CAAC,KAAKC,QAAN,EAAgB,KAAKP,SAArB,EAAgCV,OAAhC,CAApB;AACD;;AA5BmD","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport * as fs from 'fs'\nimport * as ini from 'ini'\nimport type { IApiSettings, IApiSection } from '@looker/sdk-rtl'\nimport {\n ApiConfigMap,\n ApiSettings,\n DefaultSettings,\n ValueSettings,\n sdkError,\n unquote,\n} from '@looker/sdk-rtl'\n\n/**\n * Read an environment key. Use defaultValue if it doesn't exist\n * @param {string} name Environment variable name\n * @param {string | undefined} defaultValue\n * @returns {string | undefined} The value of the environment variable if it exists, or defaultValue\n */\nexport const getenv = (\n name: string,\n defaultValue: string | undefined = undefined\n) => {\n const val = process.env[name]\n return val === undefined ? defaultValue : val\n}\n\n/**\n * Complete .INI file parse results\n */\nexport interface IApiConfig {\n [key: string]: any\n}\n\n/**\n * Parses `.ini` formatted content\n * @param contents formatted as an `.ini` file\n * @constructor\n */\nexport const ApiConfig = (contents: string): IApiConfig => ini.parse(contents)\n\n/**\n * Extract named or (default) first section from INI file\n * @param contents {string} Parameters formatted as an INI file\n * @param section {[key: string]: any;} Contents of INI section\n * @constructor\n */\nexport const ApiConfigSection = (\n contents: string,\n section?: string\n): IApiSection => {\n const config = ApiConfig(contents)\n if (!section) {\n // default to the first section if not specified\n section = Object.keys(config)[0]\n }\n const settings = config[section]\n if (!settings) {\n throw new Error(`No section named \"${section}\" was found`)\n }\n if (settings.api_version) {\n console.warn(\n 'api_version is no longer read from a configuration file by the SDK'\n )\n }\n return settings\n}\n\n/**\n * A utility function that loads environment variables and maps them to the standard configuration values\n *\n * @returns the populated `IApiSection`, which may be empty\n */\nexport const readEnvConfig = (envPrefix: string) => {\n const values: IApiSection = {}\n const configMap = ApiConfigMap(envPrefix)\n Object.keys(configMap).forEach((key) => {\n const envKey = configMap[key]\n if (process.env[envKey] !== undefined) {\n // Value exists. Map environment variable keys to config variable keys\n const val = unquote(process.env[envKey])\n values[key] = val\n }\n })\n return values\n}\n\n/**\n * A utility function that loads the configuration values from the specified file name and overrides them\n * with environment variable values, if the environment variables exist\n *\n * @param {string} fileName Name of configuration file to read\n * @param envPrefix environment variable prefix. Pass an empty string to skip environment reading.\n * @param {string} section Optional. Name of section of configuration file to read\n * @returns {IApiSection} containing the configuration values\n */\nexport const readIniConfig = (\n fileName: string,\n envPrefix: string,\n section?: string\n) => {\n // get environment variables\n let config = readEnvConfig(envPrefix)\n if (fileName && fs.existsSync(fileName)) {\n // override any config file settings with environment values if the environment value is set\n config = {\n ...ApiConfigSection(fs.readFileSync(fileName, 'utf8'), section),\n ...config,\n }\n }\n // Unquote any quoted configuration values\n Object.keys(config).forEach((key) => {\n const val = config[key]\n if (typeof val === 'string') {\n config[key] = unquote(val)\n }\n })\n return config\n}\n\n/**\n * Read configuration settings from Node environment variables\n *\n * This class initializes SDK settings **only** from the values passed in to its constructor and\n * (potentially) configured environment variables, and does not read a configuration file at all\n *\n * Any environment variables that **are** set, will override the values passed in to the constructor\n * with the same key\n *\n */\nexport class NodeSettings extends ApiSettings {\n protected readonly envPrefix!: string\n public section: string\n\n /**\n * Initialize config settings for the node SDK runtime\n * @param envPrefix Environment variable name prefix. Use empty string to not read the environment\n * @param contents contents of the read config\n * @param section name of ini section to process\n */\n constructor(\n envPrefix: string,\n contents?: string | IApiSettings,\n section?: string\n ) {\n let settings: IApiSettings\n if (contents) {\n if (typeof contents === 'string') {\n settings = ApiConfigSection(contents, section) as IApiSettings\n } else {\n settings = contents\n }\n settings = { ...readEnvConfig(envPrefix), ...settings }\n } else {\n settings = readEnvConfig(envPrefix) as IApiSettings\n }\n super({ ...DefaultSettings(), ...settings })\n this.section = section ?? ''\n this.envPrefix = envPrefix\n }\n\n /**\n * **NOTE**: If `envPrefix` is defined in the constructor, environment variables will be read in this call.\n *\n * @param _section section name is ignored here.\n */\n readConfig(_section?: string): IApiSection {\n return readEnvConfig(this.envPrefix)\n }\n}\n\n/**\n * Example class that reads a configuration from a file in node\n *\n * If `fileName` is not specified in the constructor, the default file name is `./looker.ini`\n *\n * **Warning**: `.ini` files storing credentials should be secured in the run-time environment, and\n * ignored by version control systems so credentials never get checked in to source code repositories.\n * A recommended pattern is using Node environment variables to specify confidential API credentials\n * while using an `.ini` file for values like `base_url`.\n *\n * **Note**: If the configuration file is specified but does **not** exist, an error will be thrown.\n * No error is thrown if the fileName defaulted to `./looker.ini` inside the constructor and that\n * file does not exist. In that case, configuration from environment variables will be required.\n *\n */\nexport class NodeSettingsIniFile extends NodeSettings {\n private readonly fileName!: string\n\n constructor(envPrefix: string, fileName = '', section?: string) {\n if (fileName && !fs.existsSync(fileName)) {\n throw sdkError({ message: `File ${fileName} was not found` })\n }\n // default fileName to looker.ini\n fileName = fileName || './looker.ini'\n const config = readIniConfig(fileName, envPrefix, section)\n const settings = ValueSettings(config, envPrefix)\n super(envPrefix, settings, section)\n this.fileName = fileName\n }\n\n /**\n * Read a configuration section and return it as a generic keyed collection\n * If the configuration file doesn't exist, environment variables will be used for the values\n * Environment variables, if set, also override the configuration file values\n *\n * **NOTE**: If `envPrefix` is defined in the constructor, environment variables will be read in this call.\n *\n * @param section {string} Name of Ini section to read. Optional. Defaults to first section.\n *\n */\n readConfig(section?: string): IApiSection {\n section = section || this.section\n return readIniConfig(this.fileName, this.envPrefix, section)\n }\n}\n"],"file":"nodeSettings.js"}
|
|
1
|
+
{"version":3,"file":"nodeSettings.js","names":["getenv","name","defaultValue","undefined","val","process","env","ApiConfig","contents","ini","parse","ApiConfigSection","section","config","Object","keys","settings","Error","api_version","console","warn","readEnvConfig","envPrefix","values","configMap","ApiConfigMap","forEach","key","envKey","unquote","readIniConfig","fileName","fs","existsSync","readFileSync","NodeSettings","ApiSettings","constructor","DefaultSettings","readConfig","_section","NodeSettingsIniFile","sdkError","message","ValueSettings"],"sources":["../src/nodeSettings.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport * as fs from 'fs'\nimport * as ini from 'ini'\nimport type { IApiSettings, IApiSection } from '@looker/sdk-rtl'\nimport {\n ApiConfigMap,\n ApiSettings,\n DefaultSettings,\n ValueSettings,\n sdkError,\n unquote,\n} from '@looker/sdk-rtl'\n\n/**\n * Read an environment key. Use defaultValue if it doesn't exist\n * @param {string} name Environment variable name\n * @param {string | undefined} defaultValue\n * @returns {string | undefined} The value of the environment variable if it exists, or defaultValue\n */\nexport const getenv = (\n name: string,\n defaultValue: string | undefined = undefined\n) => {\n const val = process.env[name]\n return val === undefined ? defaultValue : val\n}\n\n/**\n * Complete .INI file parse results\n */\nexport interface IApiConfig {\n [key: string]: any\n}\n\n/**\n * Parses `.ini` formatted content\n * @param contents formatted as an `.ini` file\n * @constructor\n */\nexport const ApiConfig = (contents: string): IApiConfig => ini.parse(contents)\n\n/**\n * Extract named or (default) first section from INI file\n * @param contents {string} Parameters formatted as an INI file\n * @param section {[key: string]: any;} Contents of INI section\n * @constructor\n */\nexport const ApiConfigSection = (\n contents: string,\n section?: string\n): IApiSection => {\n const config = ApiConfig(contents)\n if (!section) {\n // default to the first section if not specified\n section = Object.keys(config)[0]\n }\n const settings = config[section]\n if (!settings) {\n throw new Error(`No section named \"${section}\" was found`)\n }\n if (settings.api_version) {\n console.warn(\n 'api_version is no longer read from a configuration file by the SDK'\n )\n }\n return settings\n}\n\n/**\n * A utility function that loads environment variables and maps them to the standard configuration values\n *\n * @returns the populated `IApiSection`, which may be empty\n */\nexport const readEnvConfig = (envPrefix: string) => {\n const values: IApiSection = {}\n const configMap = ApiConfigMap(envPrefix)\n Object.keys(configMap).forEach((key) => {\n const envKey = configMap[key]\n if (process.env[envKey] !== undefined) {\n // Value exists. Map environment variable keys to config variable keys\n const val = unquote(process.env[envKey])\n values[key] = val\n }\n })\n return values\n}\n\n/**\n * A utility function that loads the configuration values from the specified file name and overrides them\n * with environment variable values, if the environment variables exist\n *\n * @param {string} fileName Name of configuration file to read\n * @param envPrefix environment variable prefix. Pass an empty string to skip environment reading.\n * @param {string} section Optional. Name of section of configuration file to read\n * @returns {IApiSection} containing the configuration values\n */\nexport const readIniConfig = (\n fileName: string,\n envPrefix: string,\n section?: string\n) => {\n // get environment variables\n let config = readEnvConfig(envPrefix)\n if (fileName && fs.existsSync(fileName)) {\n // override any config file settings with environment values if the environment value is set\n config = {\n ...ApiConfigSection(fs.readFileSync(fileName, 'utf8'), section),\n ...config,\n }\n }\n // Unquote any quoted configuration values\n Object.keys(config).forEach((key) => {\n const val = config[key]\n if (typeof val === 'string') {\n config[key] = unquote(val)\n }\n })\n return config\n}\n\n/**\n * Read configuration settings from Node environment variables\n *\n * This class initializes SDK settings **only** from the values passed in to its constructor and\n * (potentially) configured environment variables, and does not read a configuration file at all\n *\n * Any environment variables that **are** set, will override the values passed in to the constructor\n * with the same key\n *\n */\nexport class NodeSettings extends ApiSettings {\n protected readonly envPrefix!: string\n public section: string\n\n /**\n * Initialize config settings for the node SDK runtime\n * @param envPrefix Environment variable name prefix. Use empty string to not read the environment\n * @param contents contents of the read config\n * @param section name of ini section to process\n */\n constructor(\n envPrefix: string,\n contents?: string | IApiSettings,\n section?: string\n ) {\n let settings: IApiSettings\n if (contents) {\n if (typeof contents === 'string') {\n settings = ApiConfigSection(contents, section) as IApiSettings\n } else {\n settings = contents\n }\n settings = { ...readEnvConfig(envPrefix), ...settings }\n } else {\n settings = readEnvConfig(envPrefix) as IApiSettings\n }\n super({ ...DefaultSettings(), ...settings })\n this.section = section ?? ''\n this.envPrefix = envPrefix\n }\n\n /**\n * **NOTE**: If `envPrefix` is defined in the constructor, environment variables will be read in this call.\n *\n * @param _section section name is ignored here.\n */\n readConfig(_section?: string): IApiSection {\n return readEnvConfig(this.envPrefix)\n }\n}\n\n/**\n * Example class that reads a configuration from a file in node\n *\n * If `fileName` is not specified in the constructor, the default file name is `./looker.ini`\n *\n * **Warning**: `.ini` files storing credentials should be secured in the run-time environment, and\n * ignored by version control systems so credentials never get checked in to source code repositories.\n * A recommended pattern is using Node environment variables to specify confidential API credentials\n * while using an `.ini` file for values like `base_url`.\n *\n * **Note**: If the configuration file is specified but does **not** exist, an error will be thrown.\n * No error is thrown if the fileName defaulted to `./looker.ini` inside the constructor and that\n * file does not exist. In that case, configuration from environment variables will be required.\n *\n */\nexport class NodeSettingsIniFile extends NodeSettings {\n private readonly fileName!: string\n\n constructor(envPrefix: string, fileName = '', section?: string) {\n if (fileName && !fs.existsSync(fileName)) {\n throw sdkError({ message: `File ${fileName} was not found` })\n }\n // default fileName to looker.ini\n fileName = fileName || './looker.ini'\n const config = readIniConfig(fileName, envPrefix, section)\n const settings = ValueSettings(config, envPrefix)\n super(envPrefix, settings, section)\n this.fileName = fileName\n }\n\n /**\n * Read a configuration section and return it as a generic keyed collection\n * If the configuration file doesn't exist, environment variables will be used for the values\n * Environment variables, if set, also override the configuration file values\n *\n * **NOTE**: If `envPrefix` is defined in the constructor, environment variables will be read in this call.\n *\n * @param section {string} Name of Ini section to read. Optional. Defaults to first section.\n *\n */\n readConfig(section?: string): IApiSection {\n section = section || this.section\n return readIniConfig(this.fileName, this.envPrefix, section)\n }\n}\n"],"mappings":";;;;;;AA0BA;AACA;AAEA;AAOwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQjB,IAAMA,MA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IAAA;IAC5C,IAAI,CAACJ,OAAO,GAAGA,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAI,EAAE;IAC5B,IAAI,CAACU,SAAS,GAAGA,SAAS;EAC5B;EAOAiB,UAAU,CAACC,QAAiB,EAAe;IACzC,OAAOnB,aAAa,CAAC,IAAI,CAACC,SAAS,CAAC;EACtC;AACF;AAAC;AAiBM,MAAMmB,mBAAmB,SAASN,YAAY,CAAC;EAGpDE,WAAW,CAACf,SAAiB,EAAmC;IAAA,IAAjCS,QAAQ,uEAAG,EAAE;IAAA,IAAEnB,OAAgB;IAC5D,IAAImB,QAAQ,IAAI,CAACC,EAAE,CAACC,UAAU,CAACF,QAAQ,CAAC,EAAE;MACxC,MAAM,IAAAW,gBAAQ,EAAC;QAAEC,OAAO,iBAAUZ,QAAQ;MAAiB,CAAC,CAAC;IAC/D;IAEAA,QAAQ,GAAGA,QAAQ,IAAI,cAAc;IACrC,IAAMlB,MAAM,GAAGiB,aAAa,CAACC,QAAQ,EAAET,SAAS,EAAEV,OAAO,CAAC;IAC1D,IAAMI,QAAQ,GAAG,IAAA4B,qBAAa,EAAC/B,MAAM,EAAES,SAAS,CAAC;IACjD,KAAK,CAACA,SAAS,EAAEN,QAAQ,EAAEJ,OAAO,CAAC;IAAA;IACnC,IAAI,CAACmB,QAAQ,GAAGA,QAAQ;EAC1B;EAYAQ,UAAU,CAAC3B,OAAgB,EAAe;IACxCA,OAAO,GAAGA,OAAO,IAAI,IAAI,CAACA,OAAO;IACjC,OAAOkB,aAAa,CAAC,IAAI,CAACC,QAAQ,EAAE,IAAI,CAACT,SAAS,EAAEV,OAAO,CAAC;EAC9D;AACF;AAAC"}
|
package/lib/nodeTransport.js
CHANGED
|
@@ -4,79 +4,59 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.NodeTransport = exports.NodeCryptoHash = void 0;
|
|
7
|
-
|
|
8
7
|
var _crypto = _interopRequireDefault(require("crypto"));
|
|
9
|
-
|
|
10
8
|
var _request = _interopRequireDefault(require("request"));
|
|
11
|
-
|
|
12
9
|
var _requestPromiseNative = _interopRequireDefault(require("request-promise-native"));
|
|
13
|
-
|
|
14
10
|
var _readableStream = require("readable-stream");
|
|
15
|
-
|
|
16
11
|
var _errors = require("request-promise-native/errors");
|
|
17
|
-
|
|
18
12
|
var _sdkRtl = require("@looker/sdk-rtl");
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
-
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
16
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
18
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
28
19
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
29
|
-
|
|
30
20
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
31
|
-
|
|
32
21
|
var utf8 = 'utf8';
|
|
33
|
-
|
|
34
22
|
var asString = value => {
|
|
35
23
|
if (value instanceof Buffer) {
|
|
36
24
|
return Buffer.from(value).toString(utf8);
|
|
37
25
|
}
|
|
38
|
-
|
|
39
26
|
if (value instanceof Object) {
|
|
40
27
|
return JSON.stringify(value);
|
|
41
28
|
}
|
|
42
|
-
|
|
43
29
|
return value.toString();
|
|
44
30
|
};
|
|
45
|
-
|
|
46
31
|
class NodeCryptoHash {
|
|
47
32
|
secureRandom(byteCount) {
|
|
48
33
|
return _crypto.default.randomBytes(byteCount).toString('hex');
|
|
49
34
|
}
|
|
50
|
-
|
|
51
35
|
sha256Hash(message) {
|
|
52
36
|
return _asyncToGenerator(function* () {
|
|
53
37
|
var hash = _crypto.default.createHash('sha256');
|
|
54
|
-
|
|
55
38
|
hash.update(message);
|
|
56
39
|
return (0, _sdkRtl.safeBase64)(new Uint8Array(hash.digest()));
|
|
57
40
|
})();
|
|
58
41
|
}
|
|
59
|
-
|
|
60
42
|
}
|
|
61
|
-
|
|
62
43
|
exports.NodeCryptoHash = NodeCryptoHash;
|
|
63
|
-
|
|
64
44
|
class NodeTransport extends _sdkRtl.BaseTransport {
|
|
65
45
|
constructor(options) {
|
|
66
46
|
super(options);
|
|
67
47
|
this.options = options;
|
|
68
48
|
}
|
|
69
|
-
|
|
70
49
|
rawRequest(method, path, queryParams, body, authenticator, options) {
|
|
71
50
|
var _this = this;
|
|
72
|
-
|
|
73
51
|
return _asyncToGenerator(function* () {
|
|
74
52
|
var init = yield _this.initRequest(method, path, queryParams, body, authenticator, options);
|
|
75
53
|
var req = (0, _requestPromiseNative.default)(init).promise();
|
|
76
54
|
var rawResponse;
|
|
77
|
-
|
|
55
|
+
var requestStarted = Date.now();
|
|
56
|
+
var responseCompleted;
|
|
78
57
|
try {
|
|
79
58
|
var res = yield req;
|
|
59
|
+
responseCompleted = Date.now();
|
|
80
60
|
var resTyped = res;
|
|
81
61
|
rawResponse = {
|
|
82
62
|
method,
|
|
@@ -86,19 +66,19 @@ class NodeTransport extends _sdkRtl.BaseTransport {
|
|
|
86
66
|
ok: true,
|
|
87
67
|
statusCode: resTyped.statusCode,
|
|
88
68
|
statusMessage: resTyped.statusMessage,
|
|
89
|
-
headers: res.headers
|
|
69
|
+
headers: res.headers,
|
|
70
|
+
requestStarted,
|
|
71
|
+
responseCompleted
|
|
90
72
|
};
|
|
91
73
|
rawResponse.ok = _this.ok(rawResponse);
|
|
92
74
|
} catch (e) {
|
|
93
75
|
var statusMessage = "".concat(method, " ").concat(path);
|
|
94
76
|
var statusCode = 404;
|
|
95
77
|
var contentType = 'text';
|
|
96
|
-
|
|
97
78
|
var _body;
|
|
98
|
-
|
|
79
|
+
responseCompleted = Date.now();
|
|
99
80
|
if (e instanceof _errors.StatusCodeError) {
|
|
100
81
|
statusCode = e.statusCode;
|
|
101
|
-
|
|
102
82
|
if (e.error instanceof Buffer) {
|
|
103
83
|
_body = asString(e.error);
|
|
104
84
|
statusMessage += ": ".concat(statusCode);
|
|
@@ -114,7 +94,6 @@ class NodeTransport extends _sdkRtl.BaseTransport {
|
|
|
114
94
|
_body = JSON.stringify(e);
|
|
115
95
|
contentType = 'application/json';
|
|
116
96
|
}
|
|
117
|
-
|
|
118
97
|
rawResponse = {
|
|
119
98
|
method,
|
|
120
99
|
url: init.url.toString(),
|
|
@@ -123,23 +102,21 @@ class NodeTransport extends _sdkRtl.BaseTransport {
|
|
|
123
102
|
ok: false,
|
|
124
103
|
statusCode,
|
|
125
104
|
statusMessage,
|
|
126
|
-
headers: {}
|
|
105
|
+
headers: {},
|
|
106
|
+
requestStarted,
|
|
107
|
+
responseCompleted
|
|
127
108
|
};
|
|
128
109
|
}
|
|
129
|
-
|
|
130
110
|
return _this.observer ? _this.observer(rawResponse) : rawResponse;
|
|
131
111
|
})();
|
|
132
112
|
}
|
|
133
|
-
|
|
134
113
|
parseResponse(res) {
|
|
135
114
|
return _asyncToGenerator(function* () {
|
|
136
115
|
var mode = (0, _sdkRtl.responseMode)(res.contentType);
|
|
137
116
|
var response;
|
|
138
117
|
var error;
|
|
139
|
-
|
|
140
118
|
if (!res.ok) {
|
|
141
119
|
error = res.body;
|
|
142
|
-
|
|
143
120
|
if (typeof error === 'string') {
|
|
144
121
|
try {
|
|
145
122
|
error = JSON.parse(error);
|
|
@@ -149,23 +126,19 @@ class NodeTransport extends _sdkRtl.BaseTransport {
|
|
|
149
126
|
};
|
|
150
127
|
}
|
|
151
128
|
}
|
|
152
|
-
|
|
153
129
|
response = {
|
|
154
130
|
ok: false,
|
|
155
131
|
error
|
|
156
132
|
};
|
|
157
133
|
return response;
|
|
158
134
|
}
|
|
159
|
-
|
|
160
135
|
var result = yield res.body;
|
|
161
|
-
|
|
162
136
|
if (mode === _sdkRtl.ResponseMode.string) {
|
|
163
137
|
if (res.contentType.match(/^application\/.*\bjson\b/g)) {
|
|
164
138
|
try {
|
|
165
139
|
if (result instanceof Buffer) {
|
|
166
140
|
result = Buffer.from(result).toString(utf8);
|
|
167
141
|
}
|
|
168
|
-
|
|
169
142
|
if (!(result instanceof Object)) {
|
|
170
143
|
result = JSON.parse(result.toString());
|
|
171
144
|
}
|
|
@@ -178,13 +151,11 @@ class NodeTransport extends _sdkRtl.BaseTransport {
|
|
|
178
151
|
} else {
|
|
179
152
|
try {
|
|
180
153
|
var _result;
|
|
181
|
-
|
|
182
154
|
result = Buffer.from((_result = result) !== null && _result !== void 0 ? _result : '').toString('binary');
|
|
183
155
|
} catch (err) {
|
|
184
156
|
error = err;
|
|
185
157
|
}
|
|
186
158
|
}
|
|
187
|
-
|
|
188
159
|
if (!error) {
|
|
189
160
|
response = {
|
|
190
161
|
ok: true,
|
|
@@ -196,14 +167,11 @@ class NodeTransport extends _sdkRtl.BaseTransport {
|
|
|
196
167
|
error: error
|
|
197
168
|
};
|
|
198
169
|
}
|
|
199
|
-
|
|
200
170
|
return response;
|
|
201
171
|
})();
|
|
202
172
|
}
|
|
203
|
-
|
|
204
173
|
request(method, path, queryParams, body, authenticator, options) {
|
|
205
174
|
var _this2 = this;
|
|
206
|
-
|
|
207
175
|
return _asyncToGenerator(function* () {
|
|
208
176
|
try {
|
|
209
177
|
var res = yield _this2.rawRequest(method, path, queryParams, body, authenticator, options);
|
|
@@ -220,39 +188,28 @@ class NodeTransport extends _sdkRtl.BaseTransport {
|
|
|
220
188
|
}
|
|
221
189
|
})();
|
|
222
190
|
}
|
|
223
|
-
|
|
224
191
|
requestor(props) {
|
|
225
192
|
var _props$method;
|
|
226
|
-
|
|
227
193
|
var method = (_props$method = props.method) === null || _props$method === void 0 ? void 0 : _props$method.toString().toUpperCase();
|
|
228
|
-
|
|
229
194
|
switch (method) {
|
|
230
195
|
case 'GET':
|
|
231
196
|
return _request.default.get(props);
|
|
232
|
-
|
|
233
197
|
case 'PUT':
|
|
234
198
|
return _request.default.put(props);
|
|
235
|
-
|
|
236
199
|
case 'POST':
|
|
237
200
|
return _request.default.post(props);
|
|
238
|
-
|
|
239
201
|
case 'PATCH':
|
|
240
202
|
return _request.default.patch(props);
|
|
241
|
-
|
|
242
203
|
case 'DELETE':
|
|
243
204
|
return _request.default.put(props);
|
|
244
|
-
|
|
245
205
|
case 'HEAD':
|
|
246
206
|
return _request.default.head(props);
|
|
247
|
-
|
|
248
207
|
default:
|
|
249
208
|
return _request.default.get(props);
|
|
250
209
|
}
|
|
251
210
|
}
|
|
252
|
-
|
|
253
211
|
stream(callback, method, path, queryParams, body, authenticator, options) {
|
|
254
212
|
var _this3 = this;
|
|
255
|
-
|
|
256
213
|
return _asyncToGenerator(function* () {
|
|
257
214
|
var stream = new _readableStream.PassThrough();
|
|
258
215
|
var returnPromise = callback(stream);
|
|
@@ -260,9 +217,7 @@ class NodeTransport extends _sdkRtl.BaseTransport {
|
|
|
260
217
|
var streamPromise = new Promise((resolve, reject) => {
|
|
261
218
|
(0, _sdkRtl.trace)("[stream] beginning stream via download url", init);
|
|
262
219
|
var hasResolved = false;
|
|
263
|
-
|
|
264
220
|
var req = _this3.requestor(init);
|
|
265
|
-
|
|
266
221
|
req.on('error', err => {
|
|
267
222
|
if (hasResolved && err.code === 'ECONNRESET') {
|
|
268
223
|
(0, _sdkRtl.trace)('ignoring ECONNRESET that occurred after streaming finished', init);
|
|
@@ -296,34 +251,26 @@ class NodeTransport extends _sdkRtl.BaseTransport {
|
|
|
296
251
|
return results[0];
|
|
297
252
|
})();
|
|
298
253
|
}
|
|
299
|
-
|
|
300
254
|
verifySsl(options) {
|
|
301
255
|
if (!options) options = this.options;
|
|
302
256
|
return 'verify_ssl' in options ? options.verify_ssl : true;
|
|
303
257
|
}
|
|
304
|
-
|
|
305
258
|
timeout(options) {
|
|
306
259
|
if (!options) options = this.options;
|
|
307
260
|
if ('timeout' in options && options.timeout) return options.timeout;
|
|
308
261
|
return _sdkRtl.defaultTimeout;
|
|
309
262
|
}
|
|
310
|
-
|
|
311
263
|
initRequest(method, path, queryParams, body, authenticator, options) {
|
|
312
264
|
var _this4 = this;
|
|
313
|
-
|
|
314
265
|
return _asyncToGenerator(function* () {
|
|
315
266
|
options = options ? _objectSpread(_objectSpread({}, _this4.options), options) : _this4.options;
|
|
316
|
-
|
|
317
267
|
if (!options.agentTag) {
|
|
318
268
|
options.agentTag = _sdkRtl.agentPrefix;
|
|
319
269
|
}
|
|
320
|
-
|
|
321
270
|
var headers = _objectSpread({
|
|
322
271
|
[_sdkRtl.LookerAppId]: options.agentTag
|
|
323
272
|
}, options.headers);
|
|
324
|
-
|
|
325
273
|
var requestPath = _this4.makeUrl(path, options, queryParams);
|
|
326
|
-
|
|
327
274
|
var init = {
|
|
328
275
|
body: body || undefined,
|
|
329
276
|
encoding: null,
|
|
@@ -336,16 +283,12 @@ class NodeTransport extends _sdkRtl.BaseTransport {
|
|
|
336
283
|
url: requestPath
|
|
337
284
|
};
|
|
338
285
|
if ('encoding' in options) init.encoding = options.encoding;
|
|
339
|
-
|
|
340
286
|
if (authenticator) {
|
|
341
287
|
init = yield authenticator(init);
|
|
342
288
|
}
|
|
343
|
-
|
|
344
289
|
return init;
|
|
345
290
|
})();
|
|
346
291
|
}
|
|
347
|
-
|
|
348
292
|
}
|
|
349
|
-
|
|
350
293
|
exports.NodeTransport = NodeTransport;
|
|
351
294
|
//# sourceMappingURL=nodeTransport.js.map
|