@looker/sdk-node 22.20.1 → 23.2.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();
59
56
  var responseCompleted;
60
-
61
57
  try {
62
58
  var res = yield req;
63
59
  responseCompleted = Date.now();
@@ -79,14 +75,10 @@ export class NodeTransport extends BaseTransport {
79
75
  var statusMessage = "".concat(method, " ").concat(path);
80
76
  var statusCode = 404;
81
77
  var contentType = 'text';
82
-
83
78
  var _body;
84
-
85
79
  responseCompleted = Date.now();
86
-
87
- if (e instanceof StatusCodeError) {
80
+ if (e instanceof _errors.StatusCodeError) {
88
81
  statusCode = e.statusCode;
89
-
90
82
  if (e.error instanceof Buffer) {
91
83
  _body = asString(e.error);
92
84
  statusMessage += ": ".concat(statusCode);
@@ -102,7 +94,6 @@ export class NodeTransport extends BaseTransport {
102
94
  _body = JSON.stringify(e);
103
95
  contentType = 'application/json';
104
96
  }
105
-
106
97
  rawResponse = {
107
98
  method,
108
99
  url: init.url.toString(),
@@ -116,20 +107,16 @@ export class NodeTransport extends BaseTransport {
116
107
  responseCompleted
117
108
  };
118
109
  }
119
-
120
110
  return _this.observer ? _this.observer(rawResponse) : rawResponse;
121
111
  })();
122
112
  }
123
-
124
113
  parseResponse(res) {
125
114
  return _asyncToGenerator(function* () {
126
- var mode = responseMode(res.contentType);
115
+ var mode = (0, _sdkRtl.responseMode)(res.contentType);
127
116
  var response;
128
117
  var error;
129
-
130
118
  if (!res.ok) {
131
119
  error = res.body;
132
-
133
120
  if (typeof error === 'string') {
134
121
  try {
135
122
  error = JSON.parse(error);
@@ -139,23 +126,19 @@ export class NodeTransport extends BaseTransport {
139
126
  };
140
127
  }
141
128
  }
142
-
143
129
  response = {
144
130
  ok: false,
145
131
  error
146
132
  };
147
133
  return response;
148
134
  }
149
-
150
135
  var result = yield res.body;
151
-
152
- if (mode === ResponseMode.string) {
136
+ if (mode === _sdkRtl.ResponseMode.string) {
153
137
  if (res.contentType.match(/^application\/.*\bjson\b/g)) {
154
138
  try {
155
139
  if (result instanceof Buffer) {
156
140
  result = Buffer.from(result).toString(utf8);
157
141
  }
158
-
159
142
  if (!(result instanceof Object)) {
160
143
  result = JSON.parse(result.toString());
161
144
  }
@@ -168,13 +151,11 @@ export class NodeTransport extends BaseTransport {
168
151
  } else {
169
152
  try {
170
153
  var _result;
171
-
172
154
  result = Buffer.from((_result = result) !== null && _result !== void 0 ? _result : '').toString('binary');
173
155
  } catch (err) {
174
156
  error = err;
175
157
  }
176
158
  }
177
-
178
159
  if (!error) {
179
160
  response = {
180
161
  ok: true,
@@ -186,14 +167,11 @@ export class NodeTransport extends BaseTransport {
186
167
  error: error
187
168
  };
188
169
  }
189
-
190
170
  return response;
191
171
  })();
192
172
  }
193
-
194
173
  request(method, path, queryParams, body, authenticator, options) {
195
174
  var _this2 = this;
196
-
197
175
  return _asyncToGenerator(function* () {
198
176
  try {
199
177
  var res = yield _this2.rawRequest(method, path, queryParams, body, authenticator, options);
@@ -210,110 +188,89 @@ export class NodeTransport extends BaseTransport {
210
188
  }
211
189
  })();
212
190
  }
213
-
214
191
  requestor(props) {
215
192
  var _props$method;
216
-
217
193
  var method = (_props$method = props.method) === null || _props$method === void 0 ? void 0 : _props$method.toString().toUpperCase();
218
-
219
194
  switch (method) {
220
195
  case 'GET':
221
- return rq.get(props);
222
-
196
+ return _request.default.get(props);
223
197
  case 'PUT':
224
- return rq.put(props);
225
-
198
+ return _request.default.put(props);
226
199
  case 'POST':
227
- return rq.post(props);
228
-
200
+ return _request.default.post(props);
229
201
  case 'PATCH':
230
- return rq.patch(props);
231
-
202
+ return _request.default.patch(props);
232
203
  case 'DELETE':
233
- return rq.put(props);
234
-
204
+ return _request.default.put(props);
235
205
  case 'HEAD':
236
- return rq.head(props);
237
-
206
+ return _request.default.head(props);
238
207
  default:
239
- return rq.get(props);
208
+ return _request.default.get(props);
240
209
  }
241
210
  }
242
-
243
211
  stream(callback, method, path, queryParams, body, authenticator, options) {
244
212
  var _this3 = this;
245
-
246
213
  return _asyncToGenerator(function* () {
247
- var stream = new PassThrough();
214
+ var stream = new _readableStream.PassThrough();
248
215
  var returnPromise = callback(stream);
249
216
  var init = yield _this3.initRequest(method, path, queryParams, body, authenticator, options);
250
217
  var streamPromise = new Promise((resolve, reject) => {
251
- trace("[stream] beginning stream via download url", init);
218
+ (0, _sdkRtl.trace)("[stream] beginning stream via download url", init);
252
219
  var hasResolved = false;
253
-
254
220
  var req = _this3.requestor(init);
255
-
256
221
  req.on('error', err => {
257
222
  if (hasResolved && err.code === 'ECONNRESET') {
258
- trace('ignoring ECONNRESET that occurred after streaming finished', init);
223
+ (0, _sdkRtl.trace)('ignoring ECONNRESET that occurred after streaming finished', init);
259
224
  } else {
260
- trace('streaming error', err);
225
+ (0, _sdkRtl.trace)('streaming error', err);
261
226
  reject(err);
262
227
  }
263
228
  }).on('finish', () => {
264
- trace("[stream] streaming via download url finished", init);
229
+ (0, _sdkRtl.trace)("[stream] streaming via download url finished", init);
265
230
  }).on('socket', socket => {
266
- trace("[stream] setting keepalive on socket", init);
231
+ (0, _sdkRtl.trace)("[stream] setting keepalive on socket", init);
267
232
  socket.setKeepAlive(true);
268
233
  }).on('abort', () => {
269
- trace("[stream] streaming via download url aborted", init);
234
+ (0, _sdkRtl.trace)("[stream] streaming via download url aborted", init);
270
235
  }).on('response', () => {
271
- trace("[stream] got response from download url", init);
236
+ (0, _sdkRtl.trace)("[stream] got response from download url", init);
272
237
  }).on('close', () => {
273
- trace("[stream] request stream closed", init);
238
+ (0, _sdkRtl.trace)("[stream] request stream closed", init);
274
239
  }).pipe(stream).on('error', err => {
275
- trace("[stream] PassThrough stream error", err);
240
+ (0, _sdkRtl.trace)("[stream] PassThrough stream error", err);
276
241
  reject(err);
277
242
  }).on('finish', () => {
278
- trace("[stream] PassThrough stream finished", init);
243
+ (0, _sdkRtl.trace)("[stream] PassThrough stream finished", init);
279
244
  resolve();
280
245
  hasResolved = true;
281
246
  }).on('close', () => {
282
- trace("[stream] PassThrough stream closed", init);
247
+ (0, _sdkRtl.trace)("[stream] PassThrough stream closed", init);
283
248
  });
284
249
  });
285
250
  var results = yield Promise.all([returnPromise, streamPromise]);
286
251
  return results[0];
287
252
  })();
288
253
  }
289
-
290
254
  verifySsl(options) {
291
255
  if (!options) options = this.options;
292
256
  return 'verify_ssl' in options ? options.verify_ssl : true;
293
257
  }
294
-
295
258
  timeout(options) {
296
259
  if (!options) options = this.options;
297
260
  if ('timeout' in options && options.timeout) return options.timeout;
298
- return defaultTimeout;
261
+ return _sdkRtl.defaultTimeout;
299
262
  }
300
-
301
263
  initRequest(method, path, queryParams, body, authenticator, options) {
302
264
  var _this4 = this;
303
-
304
265
  return _asyncToGenerator(function* () {
305
266
  options = options ? _objectSpread(_objectSpread({}, _this4.options), options) : _this4.options;
306
-
307
267
  if (!options.agentTag) {
308
- options.agentTag = agentPrefix;
268
+ options.agentTag = _sdkRtl.agentPrefix;
309
269
  }
310
-
311
270
  var headers = _objectSpread({
312
- [LookerAppId]: options.agentTag
271
+ [_sdkRtl.LookerAppId]: options.agentTag
313
272
  }, options.headers);
314
-
315
273
  var requestPath = _this4.makeUrl(path, options, queryParams);
316
-
317
274
  var init = {
318
275
  body: body || undefined,
319
276
  encoding: null,
@@ -326,14 +283,12 @@ export class NodeTransport extends BaseTransport {
326
283
  url: requestPath
327
284
  };
328
285
  if ('encoding' in options) init.encoding = options.encoding;
329
-
330
286
  if (authenticator) {
331
287
  init = yield authenticator(init);
332
288
  }
333
-
334
289
  return init;
335
290
  })();
336
291
  }
337
-
338
292
  }
293
+ exports.NodeTransport = NodeTransport;
339
294
  //# sourceMappingURL=nodeTransport.js.map