@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.
@@ -1,122 +1,113 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
-
5
- 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; }
6
-
7
- import * as fs from 'fs';
8
- import * as ini from 'ini';
9
- import { ApiConfigMap, ApiSettings, DefaultSettings, ValueSettings, sdkError, unquote } from '@looker/sdk-rtl';
10
- export var getenv = function getenv(name) {
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.readIniConfig = exports.readEnvConfig = exports.getenv = exports.NodeSettingsIniFile = exports.NodeSettings = exports.ApiConfigSection = exports.ApiConfig = void 0;
7
+ var fs = _interopRequireWildcard(require("fs"));
8
+ var ini = _interopRequireWildcard(require("ini"));
9
+ var _sdkRtl = require("@looker/sdk-rtl");
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); }
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; }
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); }
17
+ var getenv = function getenv(name) {
11
18
  var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
12
19
  var val = process.env[name];
13
20
  return val === undefined ? defaultValue : val;
14
21
  };
15
- export var ApiConfig = contents => ini.parse(contents);
16
- export var ApiConfigSection = (contents, section) => {
22
+ exports.getenv = getenv;
23
+ var ApiConfig = contents => ini.parse(contents);
24
+ exports.ApiConfig = ApiConfig;
25
+ var ApiConfigSection = (contents, section) => {
17
26
  var config = ApiConfig(contents);
18
-
19
27
  if (!section) {
20
28
  section = Object.keys(config)[0];
21
29
  }
22
-
23
30
  var settings = config[section];
24
-
25
31
  if (!settings) {
26
32
  throw new Error("No section named \"".concat(section, "\" was found"));
27
33
  }
28
-
29
34
  if (settings.api_version) {
30
35
  console.warn('api_version is no longer read from a configuration file by the SDK');
31
36
  }
32
-
33
37
  return settings;
34
38
  };
35
- export var readEnvConfig = envPrefix => {
39
+ exports.ApiConfigSection = ApiConfigSection;
40
+ var readEnvConfig = envPrefix => {
36
41
  var values = {};
37
- var configMap = ApiConfigMap(envPrefix);
42
+ var configMap = (0, _sdkRtl.ApiConfigMap)(envPrefix);
38
43
  Object.keys(configMap).forEach(key => {
39
44
  var envKey = configMap[key];
40
-
41
45
  if (process.env[envKey] !== undefined) {
42
- var val = unquote(process.env[envKey]);
46
+ var val = (0, _sdkRtl.unquote)(process.env[envKey]);
43
47
  values[key] = val;
44
48
  }
45
49
  });
46
50
  return values;
47
51
  };
48
- export var readIniConfig = (fileName, envPrefix, section) => {
52
+ exports.readEnvConfig = readEnvConfig;
53
+ var readIniConfig = (fileName, envPrefix, section) => {
49
54
  var config = readEnvConfig(envPrefix);
50
-
51
55
  if (fileName && fs.existsSync(fileName)) {
52
56
  config = _objectSpread(_objectSpread({}, ApiConfigSection(fs.readFileSync(fileName, 'utf8'), section)), config);
53
57
  }
54
-
55
58
  Object.keys(config).forEach(key => {
56
59
  var val = config[key];
57
-
58
60
  if (typeof val === 'string') {
59
- config[key] = unquote(val);
61
+ config[key] = (0, _sdkRtl.unquote)(val);
60
62
  }
61
63
  });
62
64
  return config;
63
65
  };
64
- export class NodeSettings extends ApiSettings {
66
+ exports.readIniConfig = readIniConfig;
67
+ class NodeSettings extends _sdkRtl.ApiSettings {
65
68
  constructor(envPrefix, contents, section) {
66
69
  var settings;
67
-
68
70
  if (contents) {
69
71
  if (typeof contents === 'string') {
70
72
  settings = ApiConfigSection(contents, section);
71
73
  } else {
72
74
  settings = contents;
73
75
  }
74
-
75
76
  settings = _objectSpread(_objectSpread({}, readEnvConfig(envPrefix)), settings);
76
77
  } else {
77
78
  settings = readEnvConfig(envPrefix);
78
79
  }
79
-
80
- super(_objectSpread(_objectSpread({}, DefaultSettings()), settings));
81
-
80
+ super(_objectSpread(_objectSpread({}, (0, _sdkRtl.DefaultSettings)()), settings));
82
81
  _defineProperty(this, "envPrefix", void 0);
83
-
84
82
  _defineProperty(this, "section", void 0);
85
-
86
83
  this.section = section !== null && section !== void 0 ? section : '';
87
84
  this.envPrefix = envPrefix;
88
85
  }
89
-
90
86
  readConfig(_section) {
91
87
  return readEnvConfig(this.envPrefix);
92
88
  }
93
-
94
89
  }
95
- export class NodeSettingsIniFile extends NodeSettings {
90
+ exports.NodeSettings = NodeSettings;
91
+ class NodeSettingsIniFile extends NodeSettings {
96
92
  constructor(envPrefix) {
97
93
  var fileName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
98
94
  var section = arguments.length > 2 ? arguments[2] : undefined;
99
-
100
95
  if (fileName && !fs.existsSync(fileName)) {
101
- throw sdkError({
96
+ throw (0, _sdkRtl.sdkError)({
102
97
  message: "File ".concat(fileName, " was not found")
103
98
  });
104
99
  }
105
-
106
100
  fileName = fileName || './looker.ini';
107
101
  var config = readIniConfig(fileName, envPrefix, section);
108
- var settings = ValueSettings(config, envPrefix);
102
+ var settings = (0, _sdkRtl.ValueSettings)(config, envPrefix);
109
103
  super(envPrefix, settings, section);
110
-
111
104
  _defineProperty(this, "fileName", void 0);
112
-
113
105
  this.fileName = fileName;
114
106
  }
115
-
116
107
  readConfig(section) {
117
108
  section = section || this.section;
118
109
  return readIniConfig(this.fileName, this.envPrefix, section);
119
110
  }
120
-
121
111
  }
112
+ exports.NodeSettingsIniFile = NodeSettingsIniFile;
122
113
  //# sourceMappingURL=nodeSettings.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/nodeSettings.ts"],"names":["fs","ini","ApiConfigMap","ApiSettings","DefaultSettings","ValueSettings","sdkError","unquote","getenv","name","defaultValue","undefined","val","process","env","ApiConfig","contents","parse","ApiConfigSection","section","config","Object","keys","settings","Error","api_version","console","warn","readEnvConfig","envPrefix","values","configMap","forEach","key","envKey","readIniConfig","fileName","existsSync","readFileSync","NodeSettings","constructor","readConfig","_section","NodeSettingsIniFile","message"],"mappings":";;;;;;AA0BA,OAAO,KAAKA,EAAZ,MAAoB,IAApB;AACA,OAAO,KAAKC,GAAZ,MAAqB,KAArB;AAEA,SACEC,YADF,EAEEC,WAFF,EAGEC,eAHF,EAIEC,aAJF,EAKEC,QALF,EAMEC,OANF,QAOO,iBAPP;AAeA,OAAO,IAAMC,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;AAoBP,OAAO,IAAMG,SAAS,GAAIC,QAAD,IAAkCf,GAAG,CAACgB,KAAJ,CAAUD,QAAV,CAApD;AAQP,OAAO,IAAME,gBAAgB,GAAG,CAC9BF,QAD8B,EAE9BG,OAF8B,KAGd;AAChB,MAAMC,MAAM,GAAGL,SAAS,CAACC,QAAD,CAAxB;;AACA,MAAI,CAACG,OAAL,EAAc;AAEZA,IAAAA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,EAAE,CAACqC,UAAH,CAAcD,QAAd,CAAjB,EAA0C;AACxC,YAAM9B,QAAQ,CAAC;AAAEsC,QAAAA,OAAO,iBAAUR,QAAV;AAAT,OAAD,CAAd;AACD;;AAEDA,IAAAA,QAAQ,GAAGA,QAAQ,IAAI,cAAvB;AACA,QAAMhB,MAAM,GAAGe,aAAa,CAACC,QAAD,EAAWP,SAAX,EAAsBV,OAAtB,CAA5B;AACA,QAAMI,QAAQ,GAAGlB,aAAa,CAACe,MAAD,EAASS,SAAT,CAA9B;AACA,UAAMA,SAAN,EAAiBN,QAAjB,EAA2BJ,OAA3B;;AAR8D;;AAS9D,SAAKiB,QAAL,GAAgBA,QAAhB;AACD;;AAYDK,EAAAA,UAAU,CAACtB,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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bols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
-
5
- 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; }
6
-
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NodeTransport = exports.NodeCryptoHash = void 0;
7
+ var _crypto = _interopRequireDefault(require("crypto"));
8
+ var _request = _interopRequireDefault(require("request"));
9
+ var _requestPromiseNative = _interopRequireDefault(require("request-promise-native"));
10
+ var _readableStream = require("readable-stream");
11
+ var _errors = require("request-promise-native/errors");
12
+ var _sdkRtl = require("@looker/sdk-rtl");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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); }
7
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); } }
8
-
9
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); }); }; }
10
-
11
- import nodeCrypto from 'crypto';
12
- import rq from 'request';
13
- import rp from 'request-promise-native';
14
- import { PassThrough } from 'readable-stream';
15
- import { StatusCodeError } from 'request-promise-native/errors';
16
- import { BaseTransport, ResponseMode, defaultTimeout, responseMode, trace, LookerAppId, agentPrefix, safeBase64 } from '@looker/sdk-rtl';
17
21
  var utf8 = 'utf8';
18
-
19
22
  var asString = value => {
20
23
  if (value instanceof Buffer) {
21
24
  return Buffer.from(value).toString(utf8);
22
25
  }
23
-
24
26
  if (value instanceof Object) {
25
27
  return JSON.stringify(value);
26
28
  }
27
-
28
29
  return value.toString();
29
30
  };
30
-
31
- export class NodeCryptoHash {
31
+ class NodeCryptoHash {
32
32
  secureRandom(byteCount) {
33
- return nodeCrypto.randomBytes(byteCount).toString('hex');
33
+ return _crypto.default.randomBytes(byteCount).toString('hex');
34
34
  }
35
-
36
35
  sha256Hash(message) {
37
36
  return _asyncToGenerator(function* () {
38
- var hash = nodeCrypto.createHash('sha256');
37
+ var hash = _crypto.default.createHash('sha256');
39
38
  hash.update(message);
40
- return safeBase64(new Uint8Array(hash.digest()));
39
+ return (0, _sdkRtl.safeBase64)(new Uint8Array(hash.digest()));
41
40
  })();
42
41
  }
43
-
44
42
  }
45
- export class NodeTransport extends BaseTransport {
43
+ exports.NodeCryptoHash = NodeCryptoHash;
44
+ class NodeTransport extends _sdkRtl.BaseTransport {
46
45
  constructor(options) {
47
46
  super(options);
48
47
  this.options = options;
49
48
  }
50
-
51
49
  rawRequest(method, path, queryParams, body, authenticator, options) {
52
50
  var _this = this;
53
-
54
51
  return _asyncToGenerator(function* () {
55
52
  var init = yield _this.initRequest(method, path, queryParams, body, authenticator, options);
56
- var req = rp(init).promise();
53
+ var req = (0, _requestPromiseNative.default)(init).promise();
57
54
  var rawResponse;
58
-
55
+ var requestStarted = Date.now();
56
+ var responseCompleted;
59
57
  try {
60
58
  var res = yield req;
59
+ responseCompleted = Date.now();
61
60
  var resTyped = res;
62
61
  rawResponse = {
63
62
  method,
@@ -67,19 +66,19 @@ export class NodeTransport extends BaseTransport {
67
66
  ok: true,
68
67
  statusCode: resTyped.statusCode,
69
68
  statusMessage: resTyped.statusMessage,
70
- headers: res.headers
69
+ headers: res.headers,
70
+ requestStarted,
71
+ responseCompleted
71
72
  };
72
73
  rawResponse.ok = _this.ok(rawResponse);
73
74
  } catch (e) {
74
75
  var statusMessage = "".concat(method, " ").concat(path);
75
76
  var statusCode = 404;
76
77
  var contentType = 'text';
77
-
78
78
  var _body;
79
-
80
- if (e instanceof StatusCodeError) {
79
+ responseCompleted = Date.now();
80
+ if (e instanceof _errors.StatusCodeError) {
81
81
  statusCode = e.statusCode;
82
-
83
82
  if (e.error instanceof Buffer) {
84
83
  _body = asString(e.error);
85
84
  statusMessage += ": ".concat(statusCode);
@@ -95,7 +94,6 @@ export class NodeTransport extends BaseTransport {
95
94
  _body = JSON.stringify(e);
96
95
  contentType = 'application/json';
97
96
  }
98
-
99
97
  rawResponse = {
100
98
  method,
101
99
  url: init.url.toString(),
@@ -104,23 +102,21 @@ export class NodeTransport extends BaseTransport {
104
102
  ok: false,
105
103
  statusCode,
106
104
  statusMessage,
107
- headers: {}
105
+ headers: {},
106
+ requestStarted,
107
+ responseCompleted
108
108
  };
109
109
  }
110
-
111
110
  return _this.observer ? _this.observer(rawResponse) : rawResponse;
112
111
  })();
113
112
  }
114
-
115
113
  parseResponse(res) {
116
114
  return _asyncToGenerator(function* () {
117
- var mode = responseMode(res.contentType);
115
+ var mode = (0, _sdkRtl.responseMode)(res.contentType);
118
116
  var response;
119
117
  var error;
120
-
121
118
  if (!res.ok) {
122
119
  error = res.body;
123
-
124
120
  if (typeof error === 'string') {
125
121
  try {
126
122
  error = JSON.parse(error);
@@ -130,23 +126,19 @@ export class NodeTransport extends BaseTransport {
130
126
  };
131
127
  }
132
128
  }
133
-
134
129
  response = {
135
130
  ok: false,
136
131
  error
137
132
  };
138
133
  return response;
139
134
  }
140
-
141
135
  var result = yield res.body;
142
-
143
- if (mode === ResponseMode.string) {
136
+ if (mode === _sdkRtl.ResponseMode.string) {
144
137
  if (res.contentType.match(/^application\/.*\bjson\b/g)) {
145
138
  try {
146
139
  if (result instanceof Buffer) {
147
140
  result = Buffer.from(result).toString(utf8);
148
141
  }
149
-
150
142
  if (!(result instanceof Object)) {
151
143
  result = JSON.parse(result.toString());
152
144
  }
@@ -159,13 +151,11 @@ export class NodeTransport extends BaseTransport {
159
151
  } else {
160
152
  try {
161
153
  var _result;
162
-
163
154
  result = Buffer.from((_result = result) !== null && _result !== void 0 ? _result : '').toString('binary');
164
155
  } catch (err) {
165
156
  error = err;
166
157
  }
167
158
  }
168
-
169
159
  if (!error) {
170
160
  response = {
171
161
  ok: true,
@@ -177,14 +167,11 @@ export class NodeTransport extends BaseTransport {
177
167
  error: error
178
168
  };
179
169
  }
180
-
181
170
  return response;
182
171
  })();
183
172
  }
184
-
185
173
  request(method, path, queryParams, body, authenticator, options) {
186
174
  var _this2 = this;
187
-
188
175
  return _asyncToGenerator(function* () {
189
176
  try {
190
177
  var res = yield _this2.rawRequest(method, path, queryParams, body, authenticator, options);
@@ -201,110 +188,89 @@ export class NodeTransport extends BaseTransport {
201
188
  }
202
189
  })();
203
190
  }
204
-
205
191
  requestor(props) {
206
192
  var _props$method;
207
-
208
193
  var method = (_props$method = props.method) === null || _props$method === void 0 ? void 0 : _props$method.toString().toUpperCase();
209
-
210
194
  switch (method) {
211
195
  case 'GET':
212
- return rq.get(props);
213
-
196
+ return _request.default.get(props);
214
197
  case 'PUT':
215
- return rq.put(props);
216
-
198
+ return _request.default.put(props);
217
199
  case 'POST':
218
- return rq.post(props);
219
-
200
+ return _request.default.post(props);
220
201
  case 'PATCH':
221
- return rq.patch(props);
222
-
202
+ return _request.default.patch(props);
223
203
  case 'DELETE':
224
- return rq.put(props);
225
-
204
+ return _request.default.put(props);
226
205
  case 'HEAD':
227
- return rq.head(props);
228
-
206
+ return _request.default.head(props);
229
207
  default:
230
- return rq.get(props);
208
+ return _request.default.get(props);
231
209
  }
232
210
  }
233
-
234
211
  stream(callback, method, path, queryParams, body, authenticator, options) {
235
212
  var _this3 = this;
236
-
237
213
  return _asyncToGenerator(function* () {
238
- var stream = new PassThrough();
214
+ var stream = new _readableStream.PassThrough();
239
215
  var returnPromise = callback(stream);
240
216
  var init = yield _this3.initRequest(method, path, queryParams, body, authenticator, options);
241
217
  var streamPromise = new Promise((resolve, reject) => {
242
- trace("[stream] beginning stream via download url", init);
218
+ (0, _sdkRtl.trace)("[stream] beginning stream via download url", init);
243
219
  var hasResolved = false;
244
-
245
220
  var req = _this3.requestor(init);
246
-
247
221
  req.on('error', err => {
248
222
  if (hasResolved && err.code === 'ECONNRESET') {
249
- trace('ignoring ECONNRESET that occurred after streaming finished', init);
223
+ (0, _sdkRtl.trace)('ignoring ECONNRESET that occurred after streaming finished', init);
250
224
  } else {
251
- trace('streaming error', err);
225
+ (0, _sdkRtl.trace)('streaming error', err);
252
226
  reject(err);
253
227
  }
254
228
  }).on('finish', () => {
255
- trace("[stream] streaming via download url finished", init);
229
+ (0, _sdkRtl.trace)("[stream] streaming via download url finished", init);
256
230
  }).on('socket', socket => {
257
- trace("[stream] setting keepalive on socket", init);
231
+ (0, _sdkRtl.trace)("[stream] setting keepalive on socket", init);
258
232
  socket.setKeepAlive(true);
259
233
  }).on('abort', () => {
260
- trace("[stream] streaming via download url aborted", init);
234
+ (0, _sdkRtl.trace)("[stream] streaming via download url aborted", init);
261
235
  }).on('response', () => {
262
- trace("[stream] got response from download url", init);
236
+ (0, _sdkRtl.trace)("[stream] got response from download url", init);
263
237
  }).on('close', () => {
264
- trace("[stream] request stream closed", init);
238
+ (0, _sdkRtl.trace)("[stream] request stream closed", init);
265
239
  }).pipe(stream).on('error', err => {
266
- trace("[stream] PassThrough stream error", err);
240
+ (0, _sdkRtl.trace)("[stream] PassThrough stream error", err);
267
241
  reject(err);
268
242
  }).on('finish', () => {
269
- trace("[stream] PassThrough stream finished", init);
243
+ (0, _sdkRtl.trace)("[stream] PassThrough stream finished", init);
270
244
  resolve();
271
245
  hasResolved = true;
272
246
  }).on('close', () => {
273
- trace("[stream] PassThrough stream closed", init);
247
+ (0, _sdkRtl.trace)("[stream] PassThrough stream closed", init);
274
248
  });
275
249
  });
276
250
  var results = yield Promise.all([returnPromise, streamPromise]);
277
251
  return results[0];
278
252
  })();
279
253
  }
280
-
281
254
  verifySsl(options) {
282
255
  if (!options) options = this.options;
283
256
  return 'verify_ssl' in options ? options.verify_ssl : true;
284
257
  }
285
-
286
258
  timeout(options) {
287
259
  if (!options) options = this.options;
288
260
  if ('timeout' in options && options.timeout) return options.timeout;
289
- return defaultTimeout;
261
+ return _sdkRtl.defaultTimeout;
290
262
  }
291
-
292
263
  initRequest(method, path, queryParams, body, authenticator, options) {
293
264
  var _this4 = this;
294
-
295
265
  return _asyncToGenerator(function* () {
296
266
  options = options ? _objectSpread(_objectSpread({}, _this4.options), options) : _this4.options;
297
-
298
267
  if (!options.agentTag) {
299
- options.agentTag = agentPrefix;
268
+ options.agentTag = _sdkRtl.agentPrefix;
300
269
  }
301
-
302
270
  var headers = _objectSpread({
303
- [LookerAppId]: options.agentTag
271
+ [_sdkRtl.LookerAppId]: options.agentTag
304
272
  }, options.headers);
305
-
306
273
  var requestPath = _this4.makeUrl(path, options, queryParams);
307
-
308
274
  var init = {
309
275
  body: body || undefined,
310
276
  encoding: null,
@@ -317,14 +283,12 @@ export class NodeTransport extends BaseTransport {
317
283
  url: requestPath
318
284
  };
319
285
  if ('encoding' in options) init.encoding = options.encoding;
320
-
321
286
  if (authenticator) {
322
287
  init = yield authenticator(init);
323
288
  }
324
-
325
289
  return init;
326
290
  })();
327
291
  }
328
-
329
292
  }
293
+ exports.NodeTransport = NodeTransport;
330
294
  //# sourceMappingURL=nodeTransport.js.map