@looker/sdk-rtl 21.3.3 → 21.4.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.
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LookerSDKError = void 0;
7
+
8
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
+
10
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
11
+
12
+ var LookerSDKError = (() => {
13
+ 'use strict';
14
+
15
+ var LookerSDKErrorConstructor = function LookerSDKError() {
16
+ var _errors, _documentation_url;
17
+
18
+ for (var _len = arguments.length, _ref = new Array(_len), _key = 0; _key < _len; _key++) {
19
+ _ref[_key] = arguments[_key];
20
+ }
21
+
22
+ var [message, _ref2 = {}, ...rest] = _ref;
23
+
24
+ var {
25
+ errors,
26
+ documentation_url
27
+ } = _ref2,
28
+ errorOptions = _objectWithoutProperties(_ref2, ["errors", "documentation_url"]);
29
+
30
+ (_errors = errors) !== null && _errors !== void 0 ? _errors : errors = [];
31
+ (_documentation_url = documentation_url) !== null && _documentation_url !== void 0 ? _documentation_url : documentation_url = '';
32
+ var error = this ? new Error(message, errorOptions, ...rest) : Error(message, errorOptions, ...rest);
33
+ Object.setPrototypeOf(error, this ? Object.getPrototypeOf(this) : LookerSDKError.prototype);
34
+ Object.defineProperty(error, 'message', {
35
+ enumerable: true
36
+ });
37
+ error.errors = errors;
38
+ error.documentation_url = documentation_url;
39
+ return error;
40
+ };
41
+
42
+ Object.defineProperty(LookerSDKErrorConstructor, 'prototype', {
43
+ value: Object.create(Error.prototype, {
44
+ constructor: {
45
+ value: LookerSDKErrorConstructor,
46
+ writable: true,
47
+ configurable: true
48
+ },
49
+ name: {
50
+ value: 'LookerSDKError',
51
+ writable: true,
52
+ configurable: true
53
+ }
54
+ }),
55
+ writable: false
56
+ });
57
+ return LookerSDKErrorConstructor;
58
+ })();
59
+
60
+ exports.LookerSDKError = LookerSDKError;
61
+ //# sourceMappingURL=lookerSDKError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lookerSDKError.ts"],"names":["LookerSDKError","LookerSDKErrorConstructor","message","rest","errors","documentation_url","errorOptions","error","Error","Object","setPrototypeOf","getPrototypeOf","prototype","defineProperty","enumerable","value","create","constructor","writable","configurable","name"],"mappings":";;;;;;;;;;;AAiFO,IAAMA,cAA0C,GACtC,CAAC,MAAM;AACpB;;AACA,MAAMC,yBAAyB,GAAG,SAASD,cAAT,GAkBhC;AAAA;;AAAA;AAAA;AAAA;;AAAA,QAhBG,CACDE,OADC,EAED,QAII,EANH,EAOD,GAAGC,IAPF,CAgBH;;AAAA,QAdE;AACEC,MAAAA,MADF;AAEEC,MAAAA;AAFF,KAcF;AAAA,QAXOC,YAWP;;AAEA,eAAAF,MAAM,UAAN,mCAAAA,MAAM,GAAK,EAAX;AACA,0BAAAC,iBAAiB,UAAjB,yDAAAA,iBAAiB,GAAK,EAAtB;AAKA,QAAME,KAAK,GAAG,OACV,IAAIC,KAAJ,CACEN,OADF,EAKEI,YALF,EAME,GAAGH,IANL,CADU,GASVK,KAAK,CACHN,OADG,EAGHI,YAHG,EAIH,GAAGH,IAJA,CATT;AAoBAM,IAAAA,MAAM,CAACC,cAAP,CACEH,KADF,EAEE,OAAOE,MAAM,CAACE,cAAP,CAAsB,IAAtB,CAAP,GAAqCX,cAAc,CAACY,SAFtD;AASAH,IAAAA,MAAM,CAACI,cAAP,CAAsBN,KAAtB,EAA6B,SAA7B,EAAwC;AAAEO,MAAAA,UAAU,EAAE;AAAd,KAAxC;AACEP,IAAAA,KAAD,CAA0BH,MAA1B,GAAmCA,MAAnC;AACCG,IAAAA,KAAD,CAA0BF,iBAA1B,GAA8CA,iBAA9C;AAED,WAAOE,KAAP;AACD,GA5DD;;AAuEAE,EAAAA,MAAM,CAACI,cAAP,CACEZ,yBADF,EAEE,WAFF,EAOE;AACEc,IAAAA,KAAK,EAAEN,MAAM,CAACO,MAAP,CAAcR,KAAK,CAACI,SAApB,EAA+B;AACpCK,MAAAA,WAAW,EAAE;AACXF,QAAAA,KAAK,EAAEd,yBADI;AAEXiB,QAAAA,QAAQ,EAAE,IAFC;AAGXC,QAAAA,YAAY,EAAE;AAHH,OADuB;AAMpCC,MAAAA,IAAI,EAAE;AACJL,QAAAA,KAAK,EAAE,gBADH;AAEJG,QAAAA,QAAQ,EAAE,IAFN;AAGJC,QAAAA,YAAY,EAAE;AAHV;AAN8B,KAA/B,CADT;AAiBED,IAAAA,QAAQ,EAAE;AAjBZ,GAPF;AA4BA,SAAOjB,yBAAP;AACD,CAtGc,GADV","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2022 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\n/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-redeclare */\n\n// Defensive type-level programming to guard against additional\n// parameters being added to Error, as happened in lib.es2022.error.d.ts\n// (which introduced the errorOptions argument)\ntype AugmentErrorOptions<\n ErrorParameters extends unknown[],\n AdditionalErrorOptions\n> = ErrorParameters extends [(infer Message)?]\n ? [Message?, AdditionalErrorOptions?]\n : ErrorParameters extends [(infer Message)?, (infer ErrorOptions)?]\n ? [Message?, (ErrorOptions & AdditionalErrorOptions)?]\n : ErrorParameters extends [\n (infer Message)?,\n (infer ErrorOptions)?,\n ...infer Rest\n ]\n ? [Message?, (ErrorOptions & AdditionalErrorOptions)?, ...Rest]\n : never\n\ninterface IErrorDetail {\n field?: string\n code?: string\n message?: string\n documentation_url: string\n}\n\n// This specifies SDK custom error options\ninterface ILookerSDKErrorOptions {\n errors?: IErrorDetail[]\n documentation_url?: string | null\n}\n\ninterface ILookerSDKErrorConstructor {\n new (\n ...args: AugmentErrorOptions<\n ConstructorParameters<ErrorConstructor>,\n ILookerSDKErrorOptions\n >\n ): LookerSDKError\n (\n ...args: AugmentErrorOptions<\n Parameters<ErrorConstructor>,\n ILookerSDKErrorOptions\n >\n ): LookerSDKError\n}\n\n// The subclass and function expression's name should match, so that stack traces look clean.\n// We bind it to a local identifier for clarity, and to perform a type assertion.\nexport interface LookerSDKError extends Error {\n errors?: IErrorDetail[]\n documentation_url?: string | null\n}\n\nexport const LookerSDKError: ILookerSDKErrorConstructor =\n /* #__PURE__*/ (() => {\n 'use strict'\n const LookerSDKErrorConstructor = function LookerSDKError(\n this: LookerSDKError | undefined,\n ...[\n message,\n {\n errors,\n documentation_url,\n ...errorOptions\n } = {} as ILookerSDKErrorOptions,\n ...rest\n ]: AugmentErrorOptions<\n ConstructorParameters<ErrorConstructor>,\n ILookerSDKErrorOptions\n > &\n AugmentErrorOptions<\n Parameters<ErrorConstructor>,\n ILookerSDKErrorOptions\n >\n ) {\n // handle null in addition to undefined\n errors ??= []\n documentation_url ??= ''\n\n // The `super()` call. At present, Error() and new Error() are\n // indistinguishable, but use whatever we were invoked with in case\n // that ever changes.\n const error = this\n ? new Error(\n message,\n // we have to suppress a type error here if TypeScript\n // doesn't know es2022's two-argument Error constructor\n // @ts-ignore-error\n errorOptions,\n ...rest\n )\n : Error(\n message,\n // @ts-ignore-error\n errorOptions,\n ...rest\n )\n\n // Object.setPrototypeOf() is necessary when extending built-ins,\n // since Error.call(this, message, errorOptions, ...rest) doesn't\n // set up the prototype chain the way it would with a user-defined\n // class.\n Object.setPrototypeOf(\n error,\n this ? Object.getPrototypeOf(this) : LookerSDKError.prototype\n )\n\n // Normally the 'message' property of JavaScript Error objects is non-enumerable\n // set it to be enumerable for consistency with our non-error responses,\n // which are implemented as plain JavaScript objects where all\n // properties are enumerable.\n Object.defineProperty(error, 'message', { enumerable: true })\n ;(error as LookerSDKError).errors = errors\n ;(error as LookerSDKError).documentation_url = documentation_url\n\n return error\n } as ILookerSDKErrorConstructor\n\n // LookerSDKError.prototype, LookerSDKError.prototype.constructor, and\n // LookerSDKError.prototoype.name all have to be non-enumerable to match\n // the built-in RangeError, TypeError, etc., so we use\n // Object.defineProperty to set them instead of `=` assignment.\n\n // Default values for property descriptor objects:\n // writable: false\n // enumerable: false\n // configurable: false\n Object.defineProperty(\n LookerSDKErrorConstructor,\n 'prototype',\n // It's a weird wart that the built-in Error constructor\n // prototypes have writable and configurable constructor and name\n // fields. We follow that behavior to be consistent, not because\n // it makes sense.\n {\n value: Object.create(Error.prototype, {\n constructor: {\n value: LookerSDKErrorConstructor,\n writable: true,\n configurable: true,\n },\n name: {\n value: 'LookerSDKError',\n writable: true,\n configurable: true,\n },\n }),\n // SomeConstructorFunction.prototype starts off writable with\n // `function`-type constructors, in contrast to `class SomeClass`.\n // Set this to be non-writable to match `class`es and the built-in\n // Error constructors.\n writable: false,\n }\n )\n\n return LookerSDKErrorConstructor\n })()\n"],"file":"lookerSDKError.js"}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TestConfig = exports.rootFile = exports.getRootPath = void 0;
6
+ exports.TestConfig = exports.readFile = exports.rootFile = exports.getRootPath = void 0;
7
7
 
8
8
  var fs = _interopRequireWildcard(require("fs"));
9
9
 
@@ -31,6 +31,10 @@ var rootFile = function rootFile() {
31
31
 
32
32
  exports.rootFile = rootFile;
33
33
 
34
+ var readFile = fileName => fs.readFileSync(fileName, utf8);
35
+
36
+ exports.readFile = readFile;
37
+
34
38
  var TestConfig = function TestConfig() {
35
39
  var rootPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
36
40
  (0, _dotenv.config)();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/testUtils/testUtils.ts"],"names":["utf8","homeToRoost","getRootPath","path","join","__dirname","rootFile","fileName","TestConfig","rootPath","testFile","localIni","process","env","LOOKERSDK_INI","testPath","dataFile","testData","JSON","parse","fs","readFileSync","testIni","iniFile","existsSync"],"mappings":";;;;;;;AA0BA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,IAAI,GAAG,OAAb;AAcA,IAAMC,WAAW,GAAG,cAApB;;AAEO,IAAMC,WAAW,GAAG,MAAMC,cAAKC,IAAL,CAAUC,SAAV,EAAqBJ,WAArB,CAA1B;;;;AACA,IAAMK,QAAQ,GAAG,SAAXA,QAAW;AAAA,MAACC,QAAD,uEAAY,EAAZ;AAAA,SAAmBJ,cAAKC,IAAL,CAAUF,WAAW,EAArB,EAAyBK,QAAzB,CAAnB;AAAA,CAAjB;;;;AAQA,IAAMC,UAAU,GAAG,SAAbA,UAAa,GAAgC;AAAA,MAA/BC,QAA+B,uEAApB,EAAoB;AACxD;AACA,MAAMC,QAAQ,GAAG,eAAjB;AACAD,EAAAA,QAAQ,GAAGA,QAAQ,IAAIP,WAAW,EAAlC;AACA,MAAIS,QAAQ,GAAGC,OAAO,CAACC,GAAR,CAAYC,aAAZ,IAA6BR,QAAQ,CAAC,YAAD,CAApD;AACA,MAAMS,QAAQ,GAAGT,QAAQ,CAAC,OAAD,CAAzB;AACA,MAAMU,QAAQ,aAAMD,QAAN,SAAiBL,QAAjB,CAAd;AACA,MAAMO,QAAQ,GAAGC,IAAI,CAACC,KAAL,CAAWC,EAAE,CAACC,YAAH,CAAgBL,QAAhB,EAA0BhB,IAA1B,CAAX,CAAjB;AACA,MAAIsB,OAAO,aAAMb,QAAN,SAAiBQ,QAAQ,CAACM,OAA1B,CAAX;AAGA,MAAI,CAACH,EAAE,CAACI,UAAH,CAAcb,QAAd,CAAL,EAA8BA,QAAQ,GAAG,EAAX;AAC9B,MAAI,CAACS,EAAE,CAACI,UAAH,CAAcF,OAAd,CAAL,EAA6BA,OAAO,GAAG,EAAV;AAE7B,SAAO;AACLN,IAAAA,QADK;AAELL,IAAAA,QAFK;AAGLF,IAAAA,QAHK;AAILQ,IAAAA,QAJK;AAKLK,IAAAA,OALK;AAMLP,IAAAA;AANK,GAAP;AAQD,CAtBM","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 path from 'path'\nimport { config } from 'dotenv'\n\nconst utf8 = 'utf-8'\n\n/**\n * Properties used for various typescript-based tests\n */\nexport interface ITestConfig {\n rootPath: string\n testPath: string\n dataFile: string\n localIni: string\n testData: any\n testIni: string\n}\n\nconst homeToRoost = '../../../../'\n\nexport const getRootPath = () => path.join(__dirname, homeToRoost)\nexport const rootFile = (fileName = '') => path.join(getRootPath(), fileName)\n\n/**\n * Reads configuration information, returning various test values\n * @param {string} rootPath\n * @returns {{testConfig: {[p: string]: any}; localIni: string; baseUrl: any; testData: any; apiVersion: any; testIni: string; configContents: string; rootPath: string; testSection: any; timeout: number}}\n * @constructor\n */\nexport const TestConfig = (rootPath = ''): ITestConfig => {\n config()\n const testFile = 'data.yml.json'\n rootPath = rootPath || getRootPath()\n let localIni = process.env.LOOKERSDK_INI || rootFile('looker.ini')\n const testPath = rootFile('test/')\n const dataFile = `${testPath}${testFile}`\n const testData = JSON.parse(fs.readFileSync(dataFile, utf8))\n let testIni = `${rootPath}${testData.iniFile}`\n\n // If .ini files don't exist, don't try to read them downstream and expect environment variables to be set\n if (!fs.existsSync(localIni)) localIni = ''\n if (!fs.existsSync(testIni)) testIni = ''\n\n return {\n dataFile,\n localIni,\n rootPath,\n testData,\n testIni,\n testPath,\n }\n}\n"],"file":"testUtils.js"}
1
+ {"version":3,"sources":["../../src/testUtils/testUtils.ts"],"names":["utf8","homeToRoost","getRootPath","path","join","__dirname","rootFile","fileName","readFile","fs","readFileSync","TestConfig","rootPath","testFile","localIni","process","env","LOOKERSDK_INI","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;AACLJ,IAAAA,QADK;AAELL,IAAAA,QAFK;AAGLF,IAAAA,QAHK;AAILQ,IAAAA,QAJK;AAKLG,IAAAA,OALK;AAMLL,IAAAA;AANK,GAAP;AAQD,CAtBM","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 path from 'path'\nimport { config } from 'dotenv'\n\nconst utf8 = 'utf-8'\n\n/**\n * Properties used for various typescript-based tests\n */\nexport interface ITestConfig {\n rootPath: string\n testPath: string\n dataFile: string\n localIni: string\n testData: any\n testIni: string\n}\n\nconst homeToRoost = '../../../../'\n\nexport const getRootPath = () => path.join(__dirname, homeToRoost)\nexport const rootFile = (fileName = '') => path.join(getRootPath(), fileName)\nexport const readFile = (fileName: string) => fs.readFileSync(fileName, utf8)\n\n/**\n * Reads configuration information, returning various test values\n * @param {string} rootPath\n * @returns {{testConfig: {[p: string]: any}; localIni: string; baseUrl: any; testData: any; apiVersion: any; testIni: string; configContents: string; rootPath: string; testSection: any; timeout: number}}\n * @constructor\n */\nexport const TestConfig = (rootPath = ''): ITestConfig => {\n config()\n const testFile = 'data.yml.json'\n rootPath = rootPath || getRootPath()\n let localIni = process.env.LOOKERSDK_INI || rootFile('looker.ini')\n const testPath = rootFile('test/')\n const dataFile = `${testPath}${testFile}`\n const testData = JSON.parse(fs.readFileSync(dataFile, utf8))\n let testIni = `${rootPath}${testData.iniFile}`\n\n // If .ini files don't exist, don't try to read them downstream and expect environment variables to be set\n if (!fs.existsSync(localIni)) localIni = ''\n if (!fs.existsSync(testIni)) testIni = ''\n\n return {\n dataFile,\n localIni,\n rootPath,\n testData,\n testIni,\n testPath,\n }\n}\n"],"file":"testUtils.js"}
@@ -2,6 +2,7 @@
2
2
  import type { Agent } from 'https';
3
3
  import type { Headers } from 'request';
4
4
  import type { Readable } from 'readable-stream';
5
+ import { LookerSDKError } from './lookerSDKError';
5
6
  export declare const agentPrefix = "TS-SDK";
6
7
  export declare const LookerAppId = "x-looker-appid";
7
8
  export declare function trace(message: string, info?: any): void;
@@ -60,10 +61,10 @@ export declare enum StatusCode {
60
61
  FailedDependency = 424,
61
62
  TooEarly = 425,
62
63
  UpgradeRequired = 426,
63
- PreconditionRequired = 427,
64
- TooManyRequests = 428,
65
- RequestHeaderFieldsTooLarge = 429,
66
- UnavailableForLegalReasons = 430,
64
+ PreconditionRequired = 428,
65
+ TooManyRequests = 429,
66
+ RequestHeaderFieldsTooLarge = 431,
67
+ UnavailableForLegalReasons = 451,
67
68
  InternalServerError = 500,
68
69
  NotImplemented = 501,
69
70
  BadGateway = 502,
@@ -143,7 +144,7 @@ export declare type Values = {
143
144
  export declare function encodeParam(value: any): any;
144
145
  export declare function encodeParams(values?: Values): string;
145
146
  export declare function addQueryParams(path: string, obj?: Values): string;
146
- export declare function sdkError(response: any): Error;
147
+ export declare function sdkError(response: any): LookerSDKError;
147
148
  export declare function sdkOk<TSuccess, TError>(promise: Promise<SDKResponse<TSuccess, TError>>): Promise<TSuccess>;
148
149
  export declare function safeBase64(u8: Uint8Array): string;
149
150
  export declare function isErrorLike<T extends unknown>(error: T): error is T & {
package/lib/transport.js CHANGED
@@ -19,6 +19,8 @@ var _constants = require("./constants");
19
19
 
20
20
  var _delimArray = require("./delimArray");
21
21
 
22
+ var _lookerSDKError = require("./lookerSDKError");
23
+
22
24
  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); } }
23
25
 
24
26
  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); }); }; }
@@ -106,10 +108,10 @@ exports.StatusCode = StatusCode;
106
108
  StatusCode[StatusCode["FailedDependency"] = 424] = "FailedDependency";
107
109
  StatusCode[StatusCode["TooEarly"] = 425] = "TooEarly";
108
110
  StatusCode[StatusCode["UpgradeRequired"] = 426] = "UpgradeRequired";
109
- StatusCode[StatusCode["PreconditionRequired"] = 427] = "PreconditionRequired";
110
- StatusCode[StatusCode["TooManyRequests"] = 428] = "TooManyRequests";
111
- StatusCode[StatusCode["RequestHeaderFieldsTooLarge"] = 429] = "RequestHeaderFieldsTooLarge";
112
- StatusCode[StatusCode["UnavailableForLegalReasons"] = 430] = "UnavailableForLegalReasons";
111
+ StatusCode[StatusCode["PreconditionRequired"] = 428] = "PreconditionRequired";
112
+ StatusCode[StatusCode["TooManyRequests"] = 429] = "TooManyRequests";
113
+ StatusCode[StatusCode["RequestHeaderFieldsTooLarge"] = 431] = "RequestHeaderFieldsTooLarge";
114
+ StatusCode[StatusCode["UnavailableForLegalReasons"] = 451] = "UnavailableForLegalReasons";
113
115
  StatusCode[StatusCode["InternalServerError"] = 500] = "InternalServerError";
114
116
  StatusCode[StatusCode["NotImplemented"] = 501] = "NotImplemented";
115
117
  StatusCode[StatusCode["BadGateway"] = 502] = "BadGateway";
@@ -205,40 +207,43 @@ function bufferString(val) {
205
207
 
206
208
  function sdkError(response) {
207
209
  if (typeof response === 'string') {
208
- return new Error(response);
210
+ return new _lookerSDKError.LookerSDKError(response);
209
211
  }
210
212
 
211
213
  if ('error' in response) {
212
214
  var _error = response.error;
213
215
 
214
216
  if (typeof _error === 'string') {
215
- return new Error(_error);
217
+ return new _lookerSDKError.LookerSDKError(_error);
216
218
  }
217
219
 
218
220
  if ('error' in _error) {
219
221
  var _result = bufferString(_error.error);
220
222
 
221
- return new Error(_result);
223
+ return new _lookerSDKError.LookerSDKError(_result);
222
224
  }
223
225
 
224
226
  if ('message' in _error) {
225
- return new Error(response.error.message.toString());
227
+ return new _lookerSDKError.LookerSDKError(response.error.message.toString(), {
228
+ errors: _error.errors,
229
+ documentation_url: _error.documentation_url
230
+ });
226
231
  }
227
232
 
228
233
  if ('statusMessage' in _error) {
229
- return new Error(_error.statusMessage);
234
+ return new _lookerSDKError.LookerSDKError(_error.statusMessage);
230
235
  }
231
236
 
232
237
  var result = bufferString(_error);
233
- return new Error(result);
238
+ return new _lookerSDKError.LookerSDKError(result);
234
239
  }
235
240
 
236
241
  if ('message' in response) {
237
- return new Error(response.message);
242
+ return new _lookerSDKError.LookerSDKError(response.message);
238
243
  }
239
244
 
240
245
  var error = JSON.stringify(response);
241
- return new Error("Unknown error with SDK method ".concat(error));
246
+ return new _lookerSDKError.LookerSDKError("Unknown error with SDK method ".concat(error));
242
247
  }
243
248
 
244
249
  function sdkOk(_x) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/transport.ts"],"names":["agentPrefix","LookerAppId","tracing","trace","message","info","console","debug","ResponseMode","contentPatternString","RegExp","matchModeString","contentPatternBinary","matchModeBinary","charsetUtf8Pattern","matchCharsetUtf8","defaultTimeout","StatusCode","responseMode","contentType","match","string","binary","unknown","isUtf8","encodeParam","value","Date","toISOString","DelimArray","toString","encoded","JSON","stringify","decoded","decodeURIComponent","encodeURIComponent","e","URIError","encodeParams","values","keys","Object","filter","k","undefined","map","join","addQueryParams","path","obj","qp","utf8","bufferString","val","result","decoder","TextDecoder","decode","Buffer","from","err","sdkError","response","Error","error","statusMessage","sdkOk","promise","ok","safeBase64","u8","rawBase64","btoa","String","fromCharCode","replace","isErrorLike","prototype","hasOwnProperty","call"],"mappings":";;;;;;;;;;;;;;;;;AA6BA;;AACA;;;;;;AAEO,IAAMA,WAAW,GAAG,QAApB;;AACA,IAAMC,WAAW,GAAG,gBAApB;;AAGP,IAAMC,OAAO,GAAG,KAAhB;;AAOO,SAASC,KAAT,CAAeC,OAAf,EAAgCC,IAAhC,EAA4C;AACjD,MAAIH,OAAJ,EAAa;AAEXI,IAAAA,OAAO,CAACC,KAAR,CAAcH,OAAd;;AACA,QAAIC,IAAJ,EAAU;AAERC,MAAAA,OAAO,CAACC,KAAR,CAAc;AAAEF,QAAAA;AAAF,OAAd;AACD;AACF;AACF;;IAGWG,Y;;;WAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;GAAAA,Y,4BAAAA,Y;;AAUL,IAAMC,oBAAoB,GAAG,IAAIC,MAAJ,CAAWC,0BAAX,EAA4B,GAA5B,CAA7B;;AAMA,IAAMC,oBAAoB,GAAG,IAAIF,MAAJ,CAAWG,0BAAX,EAA4B,GAA5B,CAA7B;;AAMA,IAAMC,kBAAkB,GAAG,IAAIJ,MAAJ,CAAWK,2BAAX,EAA6B,GAA7B,CAA3B;;AAMA,IAAMC,cAAc,GAAG,GAAvB;;IAiBKC,U;;;WAAAA,U;AAAAA,EAAAA,U,CAAAA,U;AAAAA,EAAAA,U,CAAAA,U;AAAAA,EAAAA,U,CAAAA,U;AAAAA,EAAAA,U,CAAAA,U;AAAAA,EAAAA,U,CAAAA,U;AAAAA,EAAAA,U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,MAAM,CAACc,EAAX,EAAe;AACb,aAAOd,MAAM,CAAC7B,KAAd;AACD,KAFD,MAEO;AACL,YAAMoC,QAAQ,CAACP,MAAD,CAAd;AACD;AACF,G;;;;AAMM,SAASe,UAAT,CAAoBC,EAApB,EAAoC;AACzC,MAAMC,SAAS,GAAGC,IAAI,CAACC,MAAM,CAACC,YAAP,CAAoB,GAAGJ,EAAvB,CAAD,CAAtB;AACA,SAAOC,SAAS,CAACI,OAAV,CAAkB,KAAlB,EAAyB,GAAzB,EAA8BA,OAA9B,CAAsC,KAAtC,EAA6C,GAA7C,CAAP;AACD;;AAOM,SAASC,WAAT,CACLZ,KADK,EAE6B;AAClC,MAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B,OAAO,KAAP;AAC/B,MAAI,CAACA,KAAL,EAAY,OAAO,KAAP;AACZ,MAAI,CAACvB,MAAM,CAACoC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqCf,KAArC,EAA4C,SAA5C,CAAL,EAA6D,OAAO,KAAP;AAC7D,MAAI,OAAQA,KAAD,CAAgC7D,OAAvC,KAAmD,QAAvD,EAAiE,OAAO,KAAP;AACjE,SAAO,IAAP;AACD","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 { Agent } from 'https'\nimport type { Headers } from 'request'\nimport type { Readable } from 'readable-stream'\nimport { matchCharsetUtf8, matchModeBinary, matchModeString } from './constants'\nimport { DelimArray } from './delimArray'\n\nexport const agentPrefix = 'TS-SDK'\nexport const LookerAppId = 'x-looker-appid'\n\n/** Set to `true` to follow streaming process */\nconst tracing = false\n\n/**\n * trivial tracing function that should be replaced with a log plugin\n * @param message description for trace\n * @param info any additional information to produce for output\n */\nexport function trace(message: string, info?: any) {\n if (tracing) {\n // eslint-disable-next-line no-console\n console.debug(message)\n if (info) {\n // eslint-disable-next-line no-console\n console.debug({ info })\n }\n }\n}\n\n/** ResponseMode for an HTTP request */\nexport enum ResponseMode {\n 'binary', // this is a binary response\n 'string', // this is a \"string\" response\n 'unknown', // unrecognized response type\n}\n\n/**\n * MIME patterns for string content types\n * @type {RegExp}\n */\nexport const contentPatternString = new RegExp(matchModeString, 'i')\n\n/**\n * MIME patterns for \"binary\" content types\n * @type {RegExp}\n */\nexport const contentPatternBinary = new RegExp(matchModeBinary, 'i')\n\n/**\n * MIME pattern for UTF8 charset attribute\n * @type {RegExp}\n */\nexport const charsetUtf8Pattern = new RegExp(matchCharsetUtf8, 'i')\n\n/**\n * Default request timeout\n * @type {number} default request timeout is 120 seconds, or two minutes\n */\nexport const defaultTimeout = 120\n\n/** Recognized HTTP methods */\nexport type HttpMethod =\n | 'GET'\n | 'POST'\n | 'PUT'\n | 'DELETE'\n | 'PATCH'\n | 'TRACE'\n | 'HEAD'\n\n/**\n * HTTP status codes\n * https://developer.mozilla.org/en-US/docs/Web/HTTP/Status for reference\n * TODO is there a platform-agnostic list of these that can be used instead of this static declaration?\n */\nexport enum StatusCode {\n OK = 200,\n Created,\n Accepted,\n NonAuthoritative,\n NoContent,\n ResetContent,\n PartialContent,\n MultiStatus,\n MultiStatusDav,\n IMUsed = 226,\n MultipleChoice = 300,\n MovedPermanently,\n Found,\n SeeOther,\n NotModified,\n UseProxy,\n UnusedRedirect,\n TemporaryRedirect,\n PermanentRedirect,\n BadRequest = 400,\n Unauthorized,\n PaymentRequired,\n Forbidden,\n NotFound,\n MethodNotAllowed,\n NotAcceptable,\n ProxyAuthRequired,\n RequestTimeout,\n Conflict,\n Gone,\n LengthRequired,\n PreconditionFailed,\n PayloadTooLarge,\n UriTooLong,\n UnsupportedMediaType,\n RequestedRangeNotSatisfiable,\n ExpectationFailed,\n ImATeapot,\n MisdirectedRequest = 421,\n UnprocessableEntity,\n Locked,\n FailedDependency,\n TooEarly,\n UpgradeRequired,\n PreconditionRequired,\n TooManyRequests,\n RequestHeaderFieldsTooLarge,\n UnavailableForLegalReasons,\n InternalServerError = 500,\n NotImplemented,\n BadGateway,\n ServiceUnavailable,\n GatewayTimeout,\n HttpVersionNotSupported,\n VariantAlsoNegotiates,\n InsufficientStorage,\n LoopDetected,\n NotExtended = 510,\n NetworkAuthRequired,\n}\n\n/** Untyped basic HTTP response type for \"raw\" HTTP requests */\nexport interface IRawResponse {\n /** Http method of the request */\n method: HttpMethod\n /** ok is `true` if the response is successful, `false` otherwise */\n ok: boolean\n /** HTTP request url */\n url: string\n /** HTTP response code */\n statusCode: number\n /** HTTP response status message text */\n statusMessage: string\n /** MIME type of the response from the HTTP response header */\n contentType: string\n /** The body of the HTTP response, without any additional processing */\n body: any\n /** Optional performance tracking starting mark name */\n startMark?: string\n /** Response headers */\n headers: IRequestHeaders\n}\n\n/** IRawResponse observer function type */\nexport type RawObserver = (raw: IRawResponse) => IRawResponse\n\n/** Transport plug-in interface */\nexport interface ITransport {\n /** Observer lambda to process raw responses */\n observer: RawObserver | undefined\n\n /**\n * HTTP request function for atomic, fully downloaded raw HTTP responses\n *\n * Note: This method returns the result of the HTTP request without any error handling\n *\n * @param method of HTTP request\n * @param path request path, either relative or fully specified\n * @param queryParams name/value pairs to pass as part of the URL\n * @param body data for the body of the request\n * @param authenticator authenticator callback, typically from `IAuthSession` implementation\n * @param options overrides of default transport settings\n * @returns typed response of `TSuccess`, or `TError` result\n */\n rawRequest(\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<IRawResponse>\n\n /**\n * HTTP request function for atomic, fully downloaded responses\n * @param method of HTTP request\n * @param path request path, either relative or fully specified\n * @param queryParams name/value pairs to pass as part of the URL\n * @param body data for the body of the request\n * @param authenticator authenticator callback, typically from `IAuthSession` implementation\n * @param options overrides of default transport settings\n * @returns typed response of `TSuccess`, or `TError` result\n */\n request<TSuccess, TError>(\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /**\n * Processes the raw response, converting it into an SDKResponse\n * @param raw response result\n */\n parseResponse<TSuccess, TError>(\n raw: IRawResponse\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /**\n * HTTP request function for a streamable response\n * @param callback that receives the stream response and pipes it somewhere\n * @param method of HTTP request\n * @param path request path, either relative or fully specified\n * @param queryParams name/value pairs to pass as part of the URL\n * @param body data for the body of the request\n * @param authenticator authenticator callback, typically from `IAuthSession` implementation\n * @param options overrides of default transport settings\n * @returns `T` upon success\n * @throws `ISDKErrorResponse` on failure\n */\n stream<T>(\n callback: (readable: Readable) => Promise<T>,\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<T>\n}\n\n/** A successful SDK call. */\nexport interface ISDKSuccessResponse<T> {\n /** Whether the SDK call was successful. */\n ok: true\n /** The object returned by the SDK call. */\n value: T\n}\n\n/** An errant SDK call. */\nexport interface ISDKErrorResponse<T> {\n /** Whether the SDK call was successful. */\n ok: false\n /** The error object returned by the SDK call. */\n error: T\n}\n\n/** An error representing an issue in the SDK, like a network or parsing error. */\nexport interface ISDKError {\n type: 'sdk_error'\n message: string\n}\n\nexport type SDKResponse<TSuccess, TError> =\n | ISDKSuccessResponse<TSuccess>\n | ISDKErrorResponse<TError | ISDKError>\n\n/** Generic collection */\nexport interface IRequestHeaders {\n [key: string]: string\n}\n\n/**\n * Generic http request property collection\n * TODO: Trim this down to what is required\n */\nexport interface IRequestProps {\n [key: string]: any\n /** full url for request, including any query params */\n url: string\n\n /** body of request. optional */\n body?: any\n /** headers for request. optional */\n headers: IRequestHeaders\n /** Http method for request. required. */\n method: HttpMethod\n /** Redirect processing for request. optional */\n redirect?: any\n /** Credentials to use */\n credentials?: 'include' | 'omit' | 'same-origin' | undefined\n\n /** http.Agent instance, allows custom proxy, certificate etc. */\n agent?: Agent\n /** support gzip/deflate content encoding. false to disable */\n compress?: boolean\n /** maximum redirect count. 0 to not follow redirect */\n follow?: number\n /** maximum response body size in bytes */\n size?: number\n /** req/res timeout in ms, it resets on redirect. 0 to disable (OS limit applies) */\n timeout?: number\n}\n\n/** General purpose authentication callback */\nexport type Authenticator = (props: any) => any\n\n/** Interface for API transport values */\nexport interface ITransportSettings {\n [key: string]: any\n /** base URL of API REST web service */\n base_url: string\n /** standard headers to provide in all transport requests */\n headers?: Headers\n /** whether to verify ssl certs or not. Defaults to true */\n verify_ssl: boolean\n /** request timeout in seconds. Default to 30 */\n timeout: number\n /** encoding override */\n encoding?: string | null\n /** agent tag to use for the SDK requests */\n agentTag: string\n}\n\n/**\n * Is the content type binary or \"string\"?\n * @param {string} contentType\n * @returns {ResponseMode.binary | ResponseMode.string}\n */\nexport function responseMode(contentType: string) {\n if (contentType.match(contentPatternString)) {\n return ResponseMode.string\n }\n if (contentType.match(contentPatternBinary)) {\n return ResponseMode.binary\n }\n return ResponseMode.unknown\n}\n\n/**\n * Does this content type have a UTF-8 charset?\n * @param contentType\n * @returns match if it exists\n */\nexport function isUtf8(contentType: string) {\n return contentType.match(/;.*\\bcharset\\b=\\butf-8\\b/i)\n}\n\n/** Used for name/value pair collections like for QueryParams */\nexport type Values = { [key: string]: any } | null | undefined\n\n/**\n * Encode parameter if not already encoded\n *\n * Note: this includes recognition of Date, DelimArray, and default objects for special handling\n *\n * @param value value of parameter\n * @returns URI encoded value\n */\nexport function encodeParam(value: any) {\n if (value instanceof Date) {\n value = value.toISOString()\n } else if (value instanceof DelimArray) {\n value = value.toString()\n }\n // check for object type to prevent \"[object Object]\" as the value.toString()\n let encoded =\n typeof value === 'object' ? JSON.stringify(value) : value.toString()\n\n // decodeURIComponent throws URIError if there is a % character\n // without it being part of an encoded\n try {\n const decoded = decodeURIComponent(value)\n if (value === decoded) {\n encoded = encodeURIComponent(value)\n }\n } catch (e) {\n if (e instanceof URIError) {\n encoded = encodeURIComponent(value)\n } else {\n throw e\n }\n }\n return encoded\n}\n\n/**\n * Converts `Values` to query string parameter format\n * @param values Name/value collection to encode\n * @returns {string} query string parameter formatted values. Both `false` and `null` are included. Only `undefined` are omitted.\n */\nexport function encodeParams(values?: Values) {\n if (!values) return ''\n\n const keys = Object.keys(values)\n return keys\n .filter((k) => values[k] !== undefined) // `null` and `false` will both be passed\n .map((k) => k + '=' + encodeParam(values[k]))\n .join('&')\n}\n\n/**\n * constructs the path argument including any optional query parameters\n * @param path the base path of the request\n * @param obj optional collection of query parameters to encode and append to the path\n */\nexport function addQueryParams(path: string, obj?: Values) {\n if (!obj) {\n return path\n }\n const qp = encodeParams(obj)\n return `${path}${qp ? '?' + qp : ''}`\n}\n\nconst utf8 = 'utf-8'\n\n/**\n * Convert this value to a string representation however we can do it\n * @param val\n */\nfunction bufferString(val: any) {\n let result = 'Unknown error'\n try {\n const decoder = new TextDecoder(utf8)\n result = decoder.decode(val)\n } catch (e: any) {\n // Supremely ugly hack. If we get here, we must be in Node (or IE 11, but who cares about that?)\n // Node requires an import from `util` for TextDecoder to be found BUT it \"just has\" Buffer unless WebPack messes us up\n try {\n if (val instanceof Buffer) {\n result = Buffer.from(val).toString(utf8)\n } else {\n result = JSON.stringify(val)\n }\n } catch (err: any) {\n // The fallback logic here will at least give us some information about the error being thrown\n result = JSON.stringify(val)\n }\n }\n return result\n}\n\n/**\n * SDK error handler\n * @param response any kind of error\n * @returns a new `Error` object with the failure message\n */\nexport function sdkError(response: any) {\n if (typeof response === 'string') {\n return new Error(response)\n }\n if ('error' in response) {\n const error = response.error\n if (typeof error === 'string') {\n return new Error(error)\n }\n // Try to get most specific error first\n if ('error' in error) {\n const result = bufferString(error.error)\n return new Error(result)\n }\n if ('message' in error) {\n return new Error(response.error.message.toString())\n }\n if ('statusMessage' in error) {\n return new Error(error.statusMessage)\n }\n const result = bufferString(error)\n return new Error(result)\n }\n if ('message' in response) {\n return new Error(response.message)\n }\n const error = JSON.stringify(response)\n return new Error(`Unknown error with SDK method ${error}`)\n}\n\n/** A helper method for simplifying error handling of SDK responses.\n *\n * Pass in a promise returned by any SDK method, and it will return a promise\n * that rejects if the `SDKResponse` is not `ok`. This will swallow the type\n * information in the error case, but allows you to route all the error cases\n * into a single promise rejection.\n *\n * The promise will have an `Error` rejection reason with a string `message`.\n * If the server error contains a `message` field, it will be provided, otherwise a\n * generic message will occur.\n *\n * ```ts\n * const sdk = LookerSDK({...})\n * let look\n * try {\n * look = await sdkOk(sdk.create_look({...}))\n * // do something with look\n * }\n * catch(e) {\n * // handle error case\n * }\n * ```\n */\nexport async function sdkOk<TSuccess, TError>(\n promise: Promise<SDKResponse<TSuccess, TError>>\n) {\n const result = await promise\n if (result.ok) {\n return result.value\n } else {\n throw sdkError(result)\n }\n}\n\n/**\n * Converts a byte array to a \"URL safe\" base64 string\n * @param u8 byte array to convert\n */\nexport function safeBase64(u8: Uint8Array) {\n const rawBase64 = btoa(String.fromCharCode(...u8))\n return rawBase64.replace(/\\+/g, '-').replace(/\\//g, '_')\n}\n\n/**\n * Type predicate. Asserts that a given object is error-like.\n * @param error a value of unknown type\n * @return boolean true if the error has a `message` key of type string.\n */\nexport function isErrorLike<T extends unknown>(\n error: T\n): error is T & { message: string } {\n if (typeof error !== 'object') return false\n if (!error) return false\n if (!Object.prototype.hasOwnProperty.call(error, 'message')) return false\n if (typeof (error as { message: unknown }).message !== 'string') return false\n return true\n}\n"],"file":"transport.js"}
1
+ {"version":3,"sources":["../src/transport.ts"],"names":["agentPrefix","LookerAppId","tracing","trace","message","info","console","debug","ResponseMode","contentPatternString","RegExp","matchModeString","contentPatternBinary","matchModeBinary","charsetUtf8Pattern","matchCharsetUtf8","defaultTimeout","StatusCode","responseMode","contentType","match","string","binary","unknown","isUtf8","encodeParam","value","Date","toISOString","DelimArray","toString","encoded","JSON","stringify","decoded","decodeURIComponent","encodeURIComponent","e","URIError","encodeParams","values","keys","Object","filter","k","undefined","map","join","addQueryParams","path","obj","qp","utf8","bufferString","val","result","decoder","TextDecoder","decode","Buffer","from","err","sdkError","response","LookerSDKError","error","errors","documentation_url","statusMessage","sdkOk","promise","ok","safeBase64","u8","rawBase64","btoa","String","fromCharCode","replace","isErrorLike","prototype","hasOwnProperty","call"],"mappings":";;;;;;;;;;;;;;;;;AA6BA;;AACA;;AACA;;;;;;AAEO,IAAMA,WAAW,GAAG,QAApB;;AACA,IAAMC,WAAW,GAAG,gBAApB;;AAGP,IAAMC,OAAO,GAAG,KAAhB;;AAOO,SAASC,KAAT,CAAeC,OAAf,EAAgCC,IAAhC,EAA4C;AACjD,MAAIH,OAAJ,EAAa;AAEXI,IAAAA,OAAO,CAACC,KAAR,CAAcH,OAAd;;AACA,QAAIC,IAAJ,EAAU;AAERC,MAAAA,OAAO,CAACC,KAAR,CAAc;AAAEF,QAAAA;AAAF,OAAd;AACD;AACF;AACF;;IAGWG,Y;;;WAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;GAAAA,Y,4BAAAA,Y;;AAUL,IAAMC,oBAAoB,GA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,OAAvC,KAAmD,QAAvD,EAAiE,OAAO,KAAP;AACjE,SAAO,IAAP;AACD","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 { Agent } from 'https'\nimport type { Headers } from 'request'\nimport type { Readable } from 'readable-stream'\nimport { matchCharsetUtf8, matchModeBinary, matchModeString } from './constants'\nimport { DelimArray } from './delimArray'\nimport { LookerSDKError } from './lookerSDKError'\n\nexport const agentPrefix = 'TS-SDK'\nexport const LookerAppId = 'x-looker-appid'\n\n/** Set to `true` to follow streaming process */\nconst tracing = false\n\n/**\n * trivial tracing function that should be replaced with a log plugin\n * @param message description for trace\n * @param info any additional information to produce for output\n */\nexport function trace(message: string, info?: any) {\n if (tracing) {\n // eslint-disable-next-line no-console\n console.debug(message)\n if (info) {\n // eslint-disable-next-line no-console\n console.debug({ info })\n }\n }\n}\n\n/** ResponseMode for an HTTP request */\nexport enum ResponseMode {\n 'binary', // this is a binary response\n 'string', // this is a \"string\" response\n 'unknown', // unrecognized response type\n}\n\n/**\n * MIME patterns for string content types\n * @type {RegExp}\n */\nexport const contentPatternString = new RegExp(matchModeString, 'i')\n\n/**\n * MIME patterns for \"binary\" content types\n * @type {RegExp}\n */\nexport const contentPatternBinary = new RegExp(matchModeBinary, 'i')\n\n/**\n * MIME pattern for UTF8 charset attribute\n * @type {RegExp}\n */\nexport const charsetUtf8Pattern = new RegExp(matchCharsetUtf8, 'i')\n\n/**\n * Default request timeout\n * @type {number} default request timeout is 120 seconds, or two minutes\n */\nexport const defaultTimeout = 120\n\n/** Recognized HTTP methods */\nexport type HttpMethod =\n | 'GET'\n | 'POST'\n | 'PUT'\n | 'DELETE'\n | 'PATCH'\n | 'TRACE'\n | 'HEAD'\n\n/**\n * HTTP status codes\n * https://developer.mozilla.org/en-US/docs/Web/HTTP/Status for reference\n * TODO is there a platform-agnostic list of these that can be used instead of this static declaration?\n */\nexport enum StatusCode {\n OK = 200,\n Created,\n Accepted,\n NonAuthoritative,\n NoContent,\n ResetContent,\n PartialContent,\n MultiStatus,\n MultiStatusDav,\n IMUsed = 226,\n MultipleChoice = 300,\n MovedPermanently,\n Found,\n SeeOther,\n NotModified,\n UseProxy,\n UnusedRedirect,\n TemporaryRedirect,\n PermanentRedirect,\n BadRequest = 400,\n Unauthorized,\n PaymentRequired,\n Forbidden,\n NotFound,\n MethodNotAllowed,\n NotAcceptable,\n ProxyAuthRequired,\n RequestTimeout,\n Conflict,\n Gone,\n LengthRequired,\n PreconditionFailed,\n PayloadTooLarge,\n UriTooLong,\n UnsupportedMediaType,\n RequestedRangeNotSatisfiable,\n ExpectationFailed,\n ImATeapot,\n MisdirectedRequest = 421,\n UnprocessableEntity,\n Locked,\n FailedDependency,\n TooEarly,\n UpgradeRequired,\n PreconditionRequired = 428,\n TooManyRequests,\n RequestHeaderFieldsTooLarge = 431,\n UnavailableForLegalReasons = 451,\n InternalServerError = 500,\n NotImplemented,\n BadGateway,\n ServiceUnavailable,\n GatewayTimeout,\n HttpVersionNotSupported,\n VariantAlsoNegotiates,\n InsufficientStorage,\n LoopDetected,\n NotExtended = 510,\n NetworkAuthRequired,\n}\n\n/** Untyped basic HTTP response type for \"raw\" HTTP requests */\nexport interface IRawResponse {\n /** Http method of the request */\n method: HttpMethod\n /** ok is `true` if the response is successful, `false` otherwise */\n ok: boolean\n /** HTTP request url */\n url: string\n /** HTTP response code */\n statusCode: number\n /** HTTP response status message text */\n statusMessage: string\n /** MIME type of the response from the HTTP response header */\n contentType: string\n /** The body of the HTTP response, without any additional processing */\n body: any\n /** Optional performance tracking starting mark name */\n startMark?: string\n /** Response headers */\n headers: IRequestHeaders\n}\n\n/** IRawResponse observer function type */\nexport type RawObserver = (raw: IRawResponse) => IRawResponse\n\n/** Transport plug-in interface */\nexport interface ITransport {\n /** Observer lambda to process raw responses */\n observer: RawObserver | undefined\n\n /**\n * HTTP request function for atomic, fully downloaded raw HTTP responses\n *\n * Note: This method returns the result of the HTTP request without any error handling\n *\n * @param method of HTTP request\n * @param path request path, either relative or fully specified\n * @param queryParams name/value pairs to pass as part of the URL\n * @param body data for the body of the request\n * @param authenticator authenticator callback, typically from `IAuthSession` implementation\n * @param options overrides of default transport settings\n * @returns typed response of `TSuccess`, or `TError` result\n */\n rawRequest(\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<IRawResponse>\n\n /**\n * HTTP request function for atomic, fully downloaded responses\n * @param method of HTTP request\n * @param path request path, either relative or fully specified\n * @param queryParams name/value pairs to pass as part of the URL\n * @param body data for the body of the request\n * @param authenticator authenticator callback, typically from `IAuthSession` implementation\n * @param options overrides of default transport settings\n * @returns typed response of `TSuccess`, or `TError` result\n */\n request<TSuccess, TError>(\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /**\n * Processes the raw response, converting it into an SDKResponse\n * @param raw response result\n */\n parseResponse<TSuccess, TError>(\n raw: IRawResponse\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /**\n * HTTP request function for a streamable response\n * @param callback that receives the stream response and pipes it somewhere\n * @param method of HTTP request\n * @param path request path, either relative or fully specified\n * @param queryParams name/value pairs to pass as part of the URL\n * @param body data for the body of the request\n * @param authenticator authenticator callback, typically from `IAuthSession` implementation\n * @param options overrides of default transport settings\n * @returns `T` upon success\n * @throws `ISDKErrorResponse` on failure\n */\n stream<T>(\n callback: (readable: Readable) => Promise<T>,\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<T>\n}\n\n/** A successful SDK call. */\nexport interface ISDKSuccessResponse<T> {\n /** Whether the SDK call was successful. */\n ok: true\n /** The object returned by the SDK call. */\n value: T\n}\n\n/** An errant SDK call. */\nexport interface ISDKErrorResponse<T> {\n /** Whether the SDK call was successful. */\n ok: false\n /** The error object returned by the SDK call. */\n error: T\n}\n\n/** An error representing an issue in the SDK, like a network or parsing error. */\nexport interface ISDKError {\n type: 'sdk_error'\n message: string\n}\n\nexport type SDKResponse<TSuccess, TError> =\n | ISDKSuccessResponse<TSuccess>\n | ISDKErrorResponse<TError | ISDKError>\n\n/** Generic collection */\nexport interface IRequestHeaders {\n [key: string]: string\n}\n\n/**\n * Generic http request property collection\n * TODO: Trim this down to what is required\n */\nexport interface IRequestProps {\n [key: string]: any\n /** full url for request, including any query params */\n url: string\n\n /** body of request. optional */\n body?: any\n /** headers for request. optional */\n headers: IRequestHeaders\n /** Http method for request. required. */\n method: HttpMethod\n /** Redirect processing for request. optional */\n redirect?: any\n /** Credentials to use */\n credentials?: 'include' | 'omit' | 'same-origin' | undefined\n\n /** http.Agent instance, allows custom proxy, certificate etc. */\n agent?: Agent\n /** support gzip/deflate content encoding. false to disable */\n compress?: boolean\n /** maximum redirect count. 0 to not follow redirect */\n follow?: number\n /** maximum response body size in bytes */\n size?: number\n /** req/res timeout in ms, it resets on redirect. 0 to disable (OS limit applies) */\n timeout?: number\n}\n\n/** General purpose authentication callback */\nexport type Authenticator = (props: any) => any\n\n/** Interface for API transport values */\nexport interface ITransportSettings {\n [key: string]: any\n /** base URL of API REST web service */\n base_url: string\n /** standard headers to provide in all transport requests */\n headers?: Headers\n /** whether to verify ssl certs or not. Defaults to true */\n verify_ssl: boolean\n /** request timeout in seconds. Default to 30 */\n timeout: number\n /** encoding override */\n encoding?: string | null\n /** agent tag to use for the SDK requests */\n agentTag: string\n}\n\n/**\n * Is the content type binary or \"string\"?\n * @param {string} contentType\n * @returns {ResponseMode.binary | ResponseMode.string}\n */\nexport function responseMode(contentType: string) {\n if (contentType.match(contentPatternString)) {\n return ResponseMode.string\n }\n if (contentType.match(contentPatternBinary)) {\n return ResponseMode.binary\n }\n return ResponseMode.unknown\n}\n\n/**\n * Does this content type have a UTF-8 charset?\n * @param contentType\n * @returns match if it exists\n */\nexport function isUtf8(contentType: string) {\n return contentType.match(/;.*\\bcharset\\b=\\butf-8\\b/i)\n}\n\n/** Used for name/value pair collections like for QueryParams */\nexport type Values = { [key: string]: any } | null | undefined\n\n/**\n * Encode parameter if not already encoded\n *\n * Note: this includes recognition of Date, DelimArray, and default objects for special handling\n *\n * @param value value of parameter\n * @returns URI encoded value\n */\nexport function encodeParam(value: any) {\n if (value instanceof Date) {\n value = value.toISOString()\n } else if (value instanceof DelimArray) {\n value = value.toString()\n }\n // check for object type to prevent \"[object Object]\" as the value.toString()\n let encoded =\n typeof value === 'object' ? JSON.stringify(value) : value.toString()\n\n // decodeURIComponent throws URIError if there is a % character\n // without it being part of an encoded\n try {\n const decoded = decodeURIComponent(value)\n if (value === decoded) {\n encoded = encodeURIComponent(value)\n }\n } catch (e) {\n if (e instanceof URIError) {\n encoded = encodeURIComponent(value)\n } else {\n throw e\n }\n }\n return encoded\n}\n\n/**\n * Converts `Values` to query string parameter format\n * @param values Name/value collection to encode\n * @returns {string} query string parameter formatted values. Both `false` and `null` are included. Only `undefined` are omitted.\n */\nexport function encodeParams(values?: Values) {\n if (!values) return ''\n\n const keys = Object.keys(values)\n return keys\n .filter((k) => values[k] !== undefined) // `null` and `false` will both be passed\n .map((k) => k + '=' + encodeParam(values[k]))\n .join('&')\n}\n\n/**\n * constructs the path argument including any optional query parameters\n * @param path the base path of the request\n * @param obj optional collection of query parameters to encode and append to the path\n */\nexport function addQueryParams(path: string, obj?: Values) {\n if (!obj) {\n return path\n }\n const qp = encodeParams(obj)\n return `${path}${qp ? '?' + qp : ''}`\n}\n\nconst utf8 = 'utf-8'\n\n/**\n * Convert this value to a string representation however we can do it\n * @param val\n */\nfunction bufferString(val: any) {\n let result = 'Unknown error'\n try {\n const decoder = new TextDecoder(utf8)\n result = decoder.decode(val)\n } catch (e: any) {\n // Supremely ugly hack. If we get here, we must be in Node (or IE 11, but who cares about that?)\n // Node requires an import from `util` for TextDecoder to be found BUT it \"just has\" Buffer unless WebPack messes us up\n try {\n if (val instanceof Buffer) {\n result = Buffer.from(val).toString(utf8)\n } else {\n result = JSON.stringify(val)\n }\n } catch (err: any) {\n // The fallback logic here will at least give us some information about the error being thrown\n result = JSON.stringify(val)\n }\n }\n return result\n}\n\n/**\n * SDK error handler\n * @param response any kind of error\n * @returns a new `Error` object with the failure message\n */\nexport function sdkError(response: any) {\n if (typeof response === 'string') {\n return new LookerSDKError(response)\n }\n if ('error' in response) {\n const error = response.error\n if (typeof error === 'string') {\n return new LookerSDKError(error)\n }\n // Try to get most specific error first\n if ('error' in error) {\n const result = bufferString(error.error)\n return new LookerSDKError(result)\n }\n if ('message' in error) {\n return new LookerSDKError(response.error.message.toString(), {\n errors: error.errors,\n documentation_url: error.documentation_url,\n })\n }\n if ('statusMessage' in error) {\n return new LookerSDKError(error.statusMessage)\n }\n const result = bufferString(error)\n return new LookerSDKError(result)\n }\n if ('message' in response) {\n return new LookerSDKError(response.message)\n }\n const error = JSON.stringify(response)\n return new LookerSDKError(`Unknown error with SDK method ${error}`)\n}\n\n/** A helper method for simplifying error handling of SDK responses.\n *\n * Pass in a promise returned by any SDK method, and it will return a promise\n * that rejects if the `SDKResponse` is not `ok`. This will swallow the type\n * information in the error case, but allows you to route all the error cases\n * into a single promise rejection.\n *\n * The promise will have an `Error` rejection reason with a string `message`.\n * If the server error contains a `message` field, it will be provided, otherwise a\n * generic message will occur.\n *\n * ```ts\n * const sdk = LookerSDK({...})\n * let look\n * try {\n * look = await sdkOk(sdk.create_look({...}))\n * // do something with look\n * }\n * catch(e) {\n * // handle error case\n * }\n * ```\n */\nexport async function sdkOk<TSuccess, TError>(\n promise: Promise<SDKResponse<TSuccess, TError>>\n) {\n const result = await promise\n if (result.ok) {\n return result.value\n } else {\n throw sdkError(result)\n }\n}\n\n/**\n * Converts a byte array to a \"URL safe\" base64 string\n * @param u8 byte array to convert\n */\nexport function safeBase64(u8: Uint8Array) {\n const rawBase64 = btoa(String.fromCharCode(...u8))\n return rawBase64.replace(/\\+/g, '-').replace(/\\//g, '_')\n}\n\n/**\n * Type predicate. Asserts that a given object is error-like.\n * @param error a value of unknown type\n * @return boolean true if the error has a `message` key of type string.\n */\nexport function isErrorLike<T extends unknown>(\n error: T\n): error is T & { message: string } {\n if (typeof error !== 'object') return false\n if (!error) return false\n if (!Object.prototype.hasOwnProperty.call(error, 'message')) return false\n if (typeof (error as { message: unknown }).message !== 'string') return false\n return true\n}\n"],"file":"transport.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@looker/sdk-rtl",
3
- "version": "21.3.3",
3
+ "version": "21.4.0",
4
4
  "description": "Looker SDK Runtime Library",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/esm/index.js",
@@ -51,5 +51,5 @@
51
51
  "SDK",
52
52
  "RTL"
53
53
  ],
54
- "gitHead": "79b245fdf08c08faf46e120f0961bc820199dccd"
54
+ "gitHead": "028fb6cd1f84c23fd10d42041f3d572f4f724195"
55
55
  }