@looker/sdk-rtl 21.4.0 → 21.6.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.
Files changed (101) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/lib/CSRFSession.js +3 -17
  3. package/lib/CSRFSession.js.map +1 -1
  4. package/lib/apiMethods.js +6 -47
  5. package/lib/apiMethods.js.map +1 -1
  6. package/lib/apiSettings.js +4 -24
  7. package/lib/apiSettings.js.map +1 -1
  8. package/lib/authSession.js +3 -18
  9. package/lib/authSession.js.map +1 -1
  10. package/lib/authToken.js +3 -18
  11. package/lib/authToken.js.map +1 -1
  12. package/lib/baseTransport.js +3 -12
  13. package/lib/baseTransport.js.map +1 -1
  14. package/lib/browser.js +0 -34
  15. package/lib/browser.js.map +1 -1
  16. package/lib/browserServices.js +3 -11
  17. package/lib/browserServices.js.map +1 -1
  18. package/lib/browserSession.js +6 -21
  19. package/lib/browserSession.js.map +1 -1
  20. package/lib/browserTransport.js +10 -64
  21. package/lib/browserTransport.js.map +1 -1
  22. package/lib/constants.js +1 -11
  23. package/lib/constants.js.map +1 -1
  24. package/lib/cryptoHash.js +1 -1
  25. package/lib/cryptoHash.js.map +1 -1
  26. package/lib/delimArray.js +3 -8
  27. package/lib/delimArray.js.map +1 -1
  28. package/lib/errorDoc.js +9 -50
  29. package/lib/errorDoc.js.map +1 -1
  30. package/lib/esm/CSRFSession.js +14 -17
  31. package/lib/esm/CSRFSession.js.map +1 -1
  32. package/lib/esm/apiMethods.js +18 -46
  33. package/lib/esm/apiMethods.js.map +1 -1
  34. package/lib/esm/apiSettings.js +32 -28
  35. package/lib/esm/apiSettings.js.map +1 -1
  36. package/lib/esm/authSession.js +14 -19
  37. package/lib/esm/authSession.js.map +1 -1
  38. package/lib/esm/authToken.js +11 -17
  39. package/lib/esm/authToken.js.map +1 -1
  40. package/lib/esm/baseTransport.js +14 -13
  41. package/lib/esm/baseTransport.js.map +1 -1
  42. package/lib/esm/browser.js +192 -17
  43. package/lib/esm/browser.js.map +1 -1
  44. package/lib/esm/browserServices.js +15 -12
  45. package/lib/esm/browserServices.js.map +1 -1
  46. package/lib/esm/browserSession.js +21 -23
  47. package/lib/esm/browserSession.js.map +1 -1
  48. package/lib/esm/browserTransport.js +29 -69
  49. package/lib/esm/browserTransport.js.map +1 -1
  50. package/lib/esm/constants.js +22 -10
  51. package/lib/esm/constants.js.map +1 -1
  52. package/lib/esm/cryptoHash.js.map +1 -1
  53. package/lib/esm/delimArray.js +10 -6
  54. package/lib/esm/delimArray.js.map +1 -1
  55. package/lib/esm/errorDoc.js +24 -52
  56. package/lib/esm/errorDoc.js.map +1 -1
  57. package/lib/esm/extensionSession.js +11 -16
  58. package/lib/esm/extensionSession.js.map +1 -1
  59. package/lib/esm/extensionTransport.js +13 -19
  60. package/lib/esm/extensionTransport.js.map +1 -1
  61. package/lib/esm/index.js +236 -21
  62. package/lib/esm/index.js.map +1 -1
  63. package/lib/esm/lookerSDKError.js +13 -12
  64. package/lib/esm/lookerSDKError.js.map +1 -1
  65. package/lib/esm/oauthSession.js +23 -66
  66. package/lib/esm/oauthSession.js.map +1 -1
  67. package/lib/esm/paging.js +24 -71
  68. package/lib/esm/paging.js.map +1 -1
  69. package/lib/esm/platformServices.js.map +1 -1
  70. package/lib/esm/proxySession.js +13 -13
  71. package/lib/esm/proxySession.js.map +1 -1
  72. package/lib/esm/testUtils/index.js +17 -0
  73. package/lib/esm/testUtils/index.js.map +1 -0
  74. package/lib/esm/testUtils/testUtils.js +46 -0
  75. package/lib/esm/testUtils/testUtils.js.map +1 -0
  76. package/lib/esm/transport.js +57 -62
  77. package/lib/esm/transport.js.map +1 -1
  78. package/lib/extensionSession.js +3 -17
  79. package/lib/extensionSession.js.map +1 -1
  80. package/lib/extensionTransport.js +5 -20
  81. package/lib/extensionTransport.js.map +1 -1
  82. package/lib/index.js +0 -42
  83. package/lib/index.js.map +1 -1
  84. package/lib/lookerSDKError.js +5 -13
  85. package/lib/lookerSDKError.js.map +1 -1
  86. package/lib/oauthSession.js +8 -63
  87. package/lib/oauthSession.js.map +1 -1
  88. package/lib/paging.js +5 -70
  89. package/lib/paging.js.map +1 -1
  90. package/lib/platformServices.js +1 -1
  91. package/lib/platformServices.js.map +1 -1
  92. package/lib/proxySession.js +0 -12
  93. package/lib/proxySession.js.map +1 -1
  94. package/lib/testUtils/index.js +0 -2
  95. package/lib/testUtils/index.js.map +1 -1
  96. package/lib/testUtils/testUtils.js +1 -16
  97. package/lib/testUtils/testUtils.js.map +1 -1
  98. package/lib/transport.d.ts +2 -0
  99. package/lib/transport.js +8 -50
  100. package/lib/transport.js.map +1 -1
  101. package/package.json +3 -3
package/lib/errorDoc.js CHANGED
@@ -3,44 +3,33 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ErrorDoc = exports.ErrorDocRx = exports.ErrorDocNotFound = exports.ErrorCodesUrl = void 0;
7
-
6
+ exports.ErrorDocRx = exports.ErrorDocNotFound = exports.ErrorDoc = exports.ErrorCodesUrl = void 0;
8
7
  var _transport = require("./transport");
9
-
10
8
  var _templateObject;
11
-
12
- function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, undefined, groups); }; var _super = RegExp.prototype; var _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); _groups.set(_this, groups || _groups.get(re)); return _setPrototypeOf(_this, BabelRegExp.prototype); } _inherits(BabelRegExp, RegExp); BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) result.groups = buildGroups(result, this); return result; }; BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if (typeof substitution === "string") { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } else if (typeof substitution === "function") { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; if (typeof args[args.length - 1] !== "object") { args = [].slice.call(args); args.push(buildGroups(args, _this)); } return substitution.apply(this, args); }); } else { return _super[Symbol.replace].call(this, str, substitution); } }; function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { groups[name] = result[g[name]]; return groups; }, Object.create(null)); } return _wrapRegExp.apply(this, arguments); }
13
-
14
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
15
-
16
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
17
-
18
- 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; }
19
-
9
+ function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, void 0, groups); }; var _super = RegExp.prototype, _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); return _groups.set(_this, groups || _groups.get(re)), _setPrototypeOf(_this, BabelRegExp.prototype); } function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { var i = g[name]; if ("number" == typeof i) groups[name] = result[i];else { for (var k = 0; void 0 === result[i[k]] && k + 1 < i.length;) k++; groups[name] = result[i[k]]; } return groups; }, Object.create(null)); } return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) { result.groups = buildGroups(result, this); var indices = result.indices; indices && (indices.groups = buildGroups(indices, this)); } return result; }, BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if ("string" == typeof substitution) { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { var group = groups[name]; return "$" + (Array.isArray(group) ? group.join("$") : group); })); } if ("function" == typeof substitution) { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; return "object" != typeof args[args.length - 1] && (args = [].slice.call(args)).push(buildGroups(args, _this)), substitution.apply(this, args); }); } return _super[Symbol.replace].call(this, str, substitution); }, _wrapRegExp.apply(this, arguments); }
10
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
11
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
+ 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; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
14
+ 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); }
20
15
  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); } }
21
-
22
16
  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); }); }; }
23
-
24
17
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
25
-
26
18
  var ErrorCodesUrl = 'https://marketplace-api.looker.com/errorcodes/';
27
19
  exports.ErrorCodesUrl = ErrorCodesUrl;
28
20
  var ErrorDocNotFound = '### No documentation found for ';
29
21
  exports.ErrorDocNotFound = ErrorDocNotFound;
30
- var ErrorDocPatternExpression = String.raw(_templateObject || (_templateObject = _taggedTemplateLiteral(["(?<redirector>(https://docs.looker.com/r)?/err/)(?<apiVersion>.*)/(?<statusCode>d{3})(?<apiPath>.*)"], ["(?<redirector>(https:\\/\\/docs\\.looker\\.com\\/r)?\\/err\\/)(?<apiVersion>.*)\\/(?<statusCode>\\d{3})(?<apiPath>.*)"])));
22
+ var ErrorDocPatternExpression = String.raw(_templateObject || (_templateObject = _taggedTemplateLiteral(["(?<redirector>(https://docs.looker.com/r|https://cloud.google.com/looker/docs/r)?/err/)(?<apiVersion>.*)/(?<statusCode>d{3})(?<apiPath>.*)"], ["(?<redirector>(https:\\/\\/docs\\.looker\\.com\\/r|https:\\/\\/cloud\\.google\\.com\\/looker\\/docs\\/r)?\\/err\\/)(?<apiVersion>.*)\\/(?<statusCode>\\d{3})(?<apiPath>.*)"])));
31
23
  var ErrorDocRx = RegExp(ErrorDocPatternExpression, 'i');
32
24
  exports.ErrorDocRx = ErrorDocRx;
33
-
34
25
  var sdkUrlGet = function () {
35
26
  var _ref = _asyncToGenerator(function* (sdk, url) {
36
27
  return yield (0, _transport.sdkOk)(sdk.authSession.transport.request('GET', url));
37
28
  });
38
-
39
29
  return function sdkUrlGet(_x, _x2) {
40
30
  return _ref.apply(this, arguments);
41
31
  };
42
32
  }();
43
-
44
33
  class ErrorDoc {
45
34
  constructor(sdk) {
46
35
  var getter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : sdkUrlGet;
@@ -48,62 +37,48 @@ class ErrorDoc {
48
37
  this.sdk = sdk;
49
38
  this.getter = getter;
50
39
  this.cdnUrl = cdnUrl;
51
-
52
40
  _defineProperty(this, "_index", undefined);
53
41
  }
54
-
55
42
  load() {
56
43
  var _this = this;
57
-
58
44
  return _asyncToGenerator(function* () {
59
45
  if (!_this._index) {
60
46
  try {
61
47
  var result = yield _this.getter(_this.sdk, _this.indexUrl);
62
-
63
48
  if (typeof result === 'string') {
64
49
  result = JSON.parse(result);
65
50
  }
66
-
67
51
  _this._index = result;
68
52
  } catch (e) {
69
53
  return Promise.resolve({});
70
54
  }
71
55
  }
72
-
73
56
  return _this._index;
74
57
  })();
75
58
  }
76
-
77
59
  get indexUrl() {
78
60
  return this.contentUrl('index.json');
79
61
  }
80
-
81
62
  get index() {
82
63
  if (!this._index) {
83
64
  this.load().catch(reason => console.error(reason));
84
65
  }
85
-
86
66
  return this._index;
87
67
  }
88
-
89
68
  specPath(path) {
90
69
  var result = path.replace(/:\w+/g, found => "{".concat(found.substr(1), "}"));
91
70
  return result;
92
71
  }
93
-
94
72
  errorKey(docUrl) {
95
73
  var bits = this.parse(docUrl);
96
74
  if (!bits.redirector) return '';
97
75
  return this.specPath("".concat(bits.statusCode).concat(bits.apiPath));
98
76
  }
99
-
100
77
  notFound(key) {
101
78
  return "".concat(ErrorDocNotFound).concat(key);
102
79
  }
103
-
104
80
  getContent(url) {
105
81
  var _this2 = this;
106
-
107
82
  return _asyncToGenerator(function* () {
108
83
  try {
109
84
  return yield _this2.getter(_this2.sdk, url);
@@ -112,53 +87,39 @@ class ErrorDoc {
112
87
  }
113
88
  })();
114
89
  }
115
-
116
90
  content(docUrl) {
117
91
  var _this3 = this;
118
-
119
92
  return _asyncToGenerator(function* () {
120
93
  var key = _this3.errorKey(docUrl);
121
-
122
94
  if (!key) {
123
95
  return Promise.resolve(_this3.notFound('bad error code link'));
124
96
  }
125
-
126
97
  yield _this3.load();
127
98
  var item = _this3.index ? _this3.index[key] : undefined;
128
-
129
99
  if (!item) {
130
100
  var code = key.split('/')[0];
131
101
  item = _this3.index ? _this3.index[code] : undefined;
132
-
133
102
  if (!item) {
134
103
  return Promise.resolve(_this3.notFound(key));
135
104
  }
136
105
  }
137
-
138
106
  var url = _this3.contentUrl(item.url);
139
-
140
107
  return yield _this3.getContent(url);
141
108
  })();
142
109
  }
143
-
144
110
  contentUrl(urlPath) {
145
111
  return "".concat(this.cdnUrl).concat(urlPath);
146
112
  }
147
-
148
113
  methodName(errorMdUrl) {
149
114
  var _match$groups;
150
-
151
- var ErrorMdRx = _wrapRegExp(/([0-9A-Z_a-z]+)_[0-9]{3}\.md/i, {
115
+ var ErrorMdRx = _wrapRegExp(/(\w+)_\d{3}\.md/i, {
152
116
  name: 1
153
117
  });
154
-
155
118
  var match = errorMdUrl.match(ErrorMdRx);
156
119
  return (match === null || match === void 0 ? void 0 : (_match$groups = match.groups) === null || _match$groups === void 0 ? void 0 : _match$groups.name) || '';
157
120
  }
158
-
159
121
  parse(docUrl) {
160
122
  var _match$groups2, _match$groups3, _match$groups4, _match$groups5;
161
-
162
123
  var match = docUrl.match(ErrorDocRx);
163
124
  return {
164
125
  redirector: (match === null || match === void 0 ? void 0 : (_match$groups2 = match.groups) === null || _match$groups2 === void 0 ? void 0 : _match$groups2.redirector) || '',
@@ -167,8 +128,6 @@ class ErrorDoc {
167
128
  apiPath: (match === null || match === void 0 ? void 0 : (_match$groups5 = match.groups) === null || _match$groups5 === void 0 ? void 0 : _match$groups5.apiPath) || ''
168
129
  };
169
130
  }
170
-
171
131
  }
172
-
173
132
  exports.ErrorDoc = ErrorDoc;
174
133
  //# sourceMappingURL=errorDoc.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errorDoc.ts"],"names":["ErrorCodesUrl","ErrorDocNotFound","ErrorDocPatternExpression","String","raw","ErrorDocRx","RegExp","sdkUrlGet","sdk","url","authSession","transport","request","ErrorDoc","constructor","getter","cdnUrl","undefined","load","_index","result","indexUrl","JSON","parse","e","Promise","resolve","contentUrl","index","catch","reason","console","error","specPath","path","replace","found","substr","errorKey","docUrl","bits","redirector","statusCode","apiPath","notFound","key","getContent","message","content","item","code","split","urlPath","methodName","errorMdUrl","ErrorMdRx","match","groups","name","apiVersion"],"mappings":";;;;;;;AA2BA;;;;;;;;;;;;;;;;;;AAQO,IAAMA,aAAa,GAAG,gDAAtB;;AAMA,IAAMC,gBAAgB,GAAG,iCAAzB;;AAGP,IAAMC,yBAAyB,GAAGC,MAAM,CAACC,GAAV,mSAA/B;AACO,IAAMC,UAAU,GAAGC,MAAM,CAACJ,yBAAD,EAA4B,GAA5B,CAAzB;;;AAmFP,IAAMK,SAAS;AAAA,+BAAG,WAAOC,GAAP,EAAyBC,GAAzB,EAAyC;AACzD,iBAAa,sBACXD,GAAG,CAACE,WAAJ,CAAgBC,SAAhB,CAA0BC,OAA1B,CAAiD,KAAjD,EAAwDH,GAAxD,CADW,CAAb;AAGD,GAJc;;AAAA,kBAATF,SAAS;AAAA;AAAA;AAAA,GAAf;;AAMO,MAAMM,QAAN,CAAoC;AAEzCC,EAAAA,WAAW,CACFN,GADE,EAIT;AAAA,QAFOO,MAEP,uEAFgCR,SAEhC;AAAA,QADgBS,MAChB,uEADiChB,aACjC;AAAA,SAHOQ,GAGP,GAHOA,GAGP;AAAA,SAFOO,MAEP,GAFOA,MAEP;AAAA,SADgBC,MAChB,GADgBA,MAChB;;AAAA,oCALgCC,SAKhC;AAAE;;AAESC,EAAAA,IAAI,GAA4B;AAAA;;AAAA;AAC3C,UAAI,CAAC,KAAI,CAACC,MAAV,EAAkB;AAChB,YAAI;AACF,cAAIC,MAAM,SAAS,KAAI,CAACL,MAAL,CAAY,KAAI,CAACP,GAAjB,EAAsB,KAAI,CAACa,QAA3B,CAAnB;;AACA,cAAI,OAAOD,MAAP,KAAkB,QAAtB,EAAgC;AAC9BA,YAAAA,MAAM,GAAGE,IAAI,CAACC,KAAL,CAAWH,MAAX,CAAT;AACD;;AACD,UAAA,KAAI,CAACD,MAAL,GAAcC,MAAd;AACD,SAND,CAME,OAAOI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ACD;;AAEDnC,EAAAA,KAAK,CAACgB,MAAD,EAAgC;AAAA;;AACnC,QAAMiB,KAAK,GAAGjB,MAAM,CAACiB,KAAP,CAAanD,UAAb,CAAd;AACA,WAAO;AACLoC,MAAAA,UAAU,EAAE,CAAAe,KAAK,SAAL,IAAAA,KAAK,WAAL,8BAAAA,KAAK,CAAEC,MAAP,kEAAehB,UAAf,KAA6B,EADpC;AAELkB,MAAAA,UAAU,EAAE,CAAAH,KAAK,SAAL,IAAAA,KAAK,WAAL,8BAAAA,KAAK,CAAEC,MAAP,kEAAeE,UAAf,KAA6B,EAFpC;AAGLjB,MAAAA,UAAU,EAAE,CAAAc,KAAK,SAAL,IAAAA,KAAK,WAAL,8BAAAA,KAAK,CAAEC,MAAP,kEAAef,UAAf,KAA6B,EAHpC;AAILC,MAAAA,OAAO,EAAE,CAAAa,KAAK,SAAL,IAAAA,KAAK,WAAL,8BAAAA,KAAK,CAAEC,MAAP,kEAAed,OAAf,KAA0B;AAJ9B,KAAP;AAMD;;AA9FwC","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\nimport type { IAPIMethods } from './apiMethods'\nimport { sdkOk } from './transport'\n\nexport interface IErrorDocItem {\n /** relative path of mark down document */\n url: string\n}\n\n/** Location of the public CDN for Looker API Error codes */\nexport const ErrorCodesUrl = 'https://marketplace-api.looker.com/errorcodes/'\n\n/** Structure of the error code document index */\nexport type ErrorCodeIndex = Record<string, IErrorDocItem>\n\n/** Default \"not found\" content for error documents that don't (yet) exist */\nexport const ErrorDocNotFound = '### No documentation found for '\n\n/** API error document_url link pattern */\nconst ErrorDocPatternExpression = String.raw`(?<redirector>(https:\\/\\/docs\\.looker\\.com\\/r)?\\/err\\/)(?<apiVersion>.*)\\/(?<statusCode>\\d{3})(?<apiPath>.*)`\nexport const ErrorDocRx = RegExp(ErrorDocPatternExpression, 'i')\n\nexport interface IErrorDocLink {\n /** base redirector url */\n redirector: string\n /** api version of the error link */\n apiVersion: string\n /** HTTP status code */\n statusCode: string\n /** REST API Path */\n apiPath: string\n}\n\nexport interface IErrorDoc {\n /** Index of all know error codes. Call load() to populate it */\n index?: ErrorCodeIndex\n\n /** Url of API error document index */\n indexUrl: string\n\n /**\n * Extract error url into its parts\n * @param docUrl value of documentation_url from error payload\n */\n parse(docUrl: string): IErrorDocLink\n\n /**\n * full url to resolve error document\n * @param urlPath resolved index item (used by content())\n */\n contentUrl(urlPath: string): string\n\n /**\n * fetch content from the URL, returning a \"not found\" response if it fails\n * @param url to fetch\n */\n getContent(url: string): Promise<string>\n\n /**\n * Returns the markdown of the error document\n *\n * Some kind of content is always returned from this method. The content is\n * one of:\n * - the specific document for the method and error code\n * - a generic document for the error code\n * - a \"not found\" mark down if the specific and generic are not defined\n *\n * @param docUrl value of documentation_url from error payload\n */\n content(docUrl: string): Promise<string>\n\n /**\n * Ensure API request path matches the OpenAPI path pattern\n *\n * @example\n * `/entity/:id/part/:part` should be `/entity/{id}/part/{part}`\n *\n * @param path to convert to a spec path\n */\n specPath(path: string): string\n\n /**\n * get the lookup key for the documentation_url\n * @param docUrl value of documentation_url from error payload\n */\n errorKey(docUrl: string): string\n\n /** Fetch and parse the error codes documentation index from the CDN */\n load(): Promise<ErrorCodeIndex>\n\n /**\n * get the name of the method from the error doc url\n * @param errorMdUrl url for the error document\n */\n methodName(errorMdUrl: string): string\n}\n\nexport type SDKGetCallback = (sdk: IAPIMethods, url: string) => Promise<string>\n/**\n * Default fetcher using the SDK\n * @param url to get\n * @private\n */\nconst sdkUrlGet = async (sdk: IAPIMethods, url: string) => {\n return await sdkOk(\n sdk.authSession.transport.request<string, Error>('GET', url)\n )\n}\n\nexport class ErrorDoc implements IErrorDoc {\n private _index?: ErrorCodeIndex = undefined\n constructor(\n public sdk: IAPIMethods,\n public getter: SDKGetCallback = sdkUrlGet,\n public readonly cdnUrl: string = ErrorCodesUrl\n ) {}\n\n public async load(): Promise<ErrorCodeIndex> {\n if (!this._index) {\n try {\n let result = await this.getter(this.sdk, this.indexUrl)\n if (typeof result === 'string') {\n result = JSON.parse(result)\n }\n this._index = result as unknown as ErrorCodeIndex\n } catch (e: any) {\n return Promise.resolve({})\n }\n }\n return this._index\n }\n\n public get indexUrl() {\n return this.contentUrl('index.json')\n }\n\n public get index() {\n if (!this._index) {\n this.load().catch((reason) => console.error(reason))\n }\n return this._index\n }\n\n specPath(path: string): string {\n const result = path.replace(/:\\w+/g, (found) => `{${found.substr(1)}}`)\n return result\n }\n\n errorKey(docUrl: string): string {\n const bits = this.parse(docUrl)\n if (!bits.redirector) return ''\n return this.specPath(`${bits.statusCode}${bits.apiPath}`)\n }\n\n private notFound(key: string): string {\n return `${ErrorDocNotFound}${key}`\n }\n\n async getContent(url: string): Promise<string> {\n try {\n return await this.getter(this.sdk, url)\n } catch (e: any) {\n return Promise.resolve(this.notFound(e.message))\n }\n }\n\n async content(docUrl: string): Promise<string> {\n const key = this.errorKey(docUrl)\n if (!key) {\n return Promise.resolve(this.notFound('bad error code link'))\n }\n await this.load()\n let item = this.index ? this.index[key] : undefined\n if (!item) {\n // fallback to generic error document\n const code = key.split('/')[0]\n item = this.index ? this.index[code] : undefined\n if (!item) {\n return Promise.resolve(this.notFound(key))\n }\n }\n const url = this.contentUrl(item.url)\n return await this.getContent(url)\n }\n\n contentUrl(urlPath: string): string {\n return `${this.cdnUrl}${urlPath}`\n }\n\n methodName(errorMdUrl: string): string {\n const ErrorMdRx = /(?<name>\\w+)_\\d{3}\\.md/i\n const match = errorMdUrl.match(ErrorMdRx)\n return match?.groups?.name || ''\n }\n\n parse(docUrl: string): IErrorDocLink {\n const match = docUrl.match(ErrorDocRx)\n return {\n redirector: match?.groups?.redirector || '',\n apiVersion: match?.groups?.apiVersion || '',\n statusCode: match?.groups?.statusCode || '',\n apiPath: match?.groups?.apiPath || '',\n }\n }\n}\n"],"file":"errorDoc.js"}
1
+ {"version":3,"file":"errorDoc.js","names":["ErrorCodesUrl","ErrorDocNotFound","ErrorDocPatternExpression","String","raw","ErrorDocRx","RegExp","sdkUrlGet","sdk","url","sdkOk","authSession","transport","request","ErrorDoc","constructor","getter","cdnUrl","undefined","load","_index","result","indexUrl","JSON","parse","e","Promise","resolve","contentUrl","index","catch","reason","console","error","specPath","path","replace","found","substr","errorKey","docUrl","bits","redirector","statusCode","apiPath","notFound","key","getContent","message","content","item","code","split","urlPath","methodName","errorMdUrl","ErrorMdRx","match","groups","name","apiVersion"],"sources":["../src/errorDoc.ts"],"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\nimport type { IAPIMethods } from './apiMethods'\nimport { sdkOk } from './transport'\n\nexport interface IErrorDocItem {\n /** relative path of mark down document */\n url: string\n}\n\n/** Location of the public CDN for Looker API Error codes */\nexport const ErrorCodesUrl = 'https://marketplace-api.looker.com/errorcodes/'\n\n/** Structure of the error code document index */\nexport type ErrorCodeIndex = Record<string, IErrorDocItem>\n\n/** Default \"not found\" content for error documents that don't (yet) exist */\nexport const ErrorDocNotFound = '### No documentation found for '\n\n/** API error document_url link pattern */\nconst ErrorDocPatternExpression = String.raw`(?<redirector>(https:\\/\\/docs\\.looker\\.com\\/r|https:\\/\\/cloud\\.google\\.com\\/looker\\/docs\\/r)?\\/err\\/)(?<apiVersion>.*)\\/(?<statusCode>\\d{3})(?<apiPath>.*)`\nexport const ErrorDocRx = RegExp(ErrorDocPatternExpression, 'i')\n\nexport interface IErrorDocLink {\n /** base redirector url */\n redirector: string\n /** api version of the error link */\n apiVersion: string\n /** HTTP status code */\n statusCode: string\n /** REST API Path */\n apiPath: string\n}\n\nexport interface IErrorDoc {\n /** Index of all know error codes. Call load() to populate it */\n index?: ErrorCodeIndex\n\n /** Url of API error document index */\n indexUrl: string\n\n /**\n * Extract error url into its parts\n * @param docUrl value of documentation_url from error payload\n */\n parse(docUrl: string): IErrorDocLink\n\n /**\n * full url to resolve error document\n * @param urlPath resolved index item (used by content())\n */\n contentUrl(urlPath: string): string\n\n /**\n * fetch content from the URL, returning a \"not found\" response if it fails\n * @param url to fetch\n */\n getContent(url: string): Promise<string>\n\n /**\n * Returns the markdown of the error document\n *\n * Some kind of content is always returned from this method. The content is\n * one of:\n * - the specific document for the method and error code\n * - a generic document for the error code\n * - a \"not found\" mark down if the specific and generic are not defined\n *\n * @param docUrl value of documentation_url from error payload\n */\n content(docUrl: string): Promise<string>\n\n /**\n * Ensure API request path matches the OpenAPI path pattern\n *\n * @example\n * `/entity/:id/part/:part` should be `/entity/{id}/part/{part}`\n *\n * @param path to convert to a spec path\n */\n specPath(path: string): string\n\n /**\n * get the lookup key for the documentation_url\n * @param docUrl value of documentation_url from error payload\n */\n errorKey(docUrl: string): string\n\n /** Fetch and parse the error codes documentation index from the CDN */\n load(): Promise<ErrorCodeIndex>\n\n /**\n * get the name of the method from the error doc url\n * @param errorMdUrl url for the error document\n */\n methodName(errorMdUrl: string): string\n}\n\nexport type SDKGetCallback = (sdk: IAPIMethods, url: string) => Promise<string>\n/**\n * Default fetcher using the SDK\n * @param url to get\n * @private\n */\nconst sdkUrlGet = async (sdk: IAPIMethods, url: string) => {\n return await sdkOk(\n sdk.authSession.transport.request<string, Error>('GET', url)\n )\n}\n\nexport class ErrorDoc implements IErrorDoc {\n private _index?: ErrorCodeIndex = undefined\n constructor(\n public sdk: IAPIMethods,\n public getter: SDKGetCallback = sdkUrlGet,\n public readonly cdnUrl: string = ErrorCodesUrl\n ) {}\n\n public async load(): Promise<ErrorCodeIndex> {\n if (!this._index) {\n try {\n let result = await this.getter(this.sdk, this.indexUrl)\n if (typeof result === 'string') {\n result = JSON.parse(result)\n }\n this._index = result as unknown as ErrorCodeIndex\n } catch (e: any) {\n return Promise.resolve({})\n }\n }\n return this._index\n }\n\n public get indexUrl() {\n return this.contentUrl('index.json')\n }\n\n public get index() {\n if (!this._index) {\n this.load().catch((reason) => console.error(reason))\n }\n return this._index\n }\n\n specPath(path: string): string {\n const result = path.replace(/:\\w+/g, (found) => `{${found.substr(1)}}`)\n return result\n }\n\n errorKey(docUrl: string): string {\n const bits = this.parse(docUrl)\n if (!bits.redirector) return ''\n return this.specPath(`${bits.statusCode}${bits.apiPath}`)\n }\n\n private notFound(key: string): string {\n return `${ErrorDocNotFound}${key}`\n }\n\n async getContent(url: string): Promise<string> {\n try {\n return await this.getter(this.sdk, url)\n } catch (e: any) {\n return Promise.resolve(this.notFound(e.message))\n }\n }\n\n async content(docUrl: string): Promise<string> {\n const key = this.errorKey(docUrl)\n if (!key) {\n return Promise.resolve(this.notFound('bad error code link'))\n }\n await this.load()\n let item = this.index ? this.index[key] : undefined\n if (!item) {\n // fallback to generic error document\n const code = key.split('/')[0]\n item = this.index ? this.index[code] : undefined\n if (!item) {\n return Promise.resolve(this.notFound(key))\n }\n }\n const url = this.contentUrl(item.url)\n return await this.getContent(url)\n }\n\n contentUrl(urlPath: string): string {\n return `${this.cdnUrl}${urlPath}`\n }\n\n methodName(errorMdUrl: string): string {\n const ErrorMdRx = /(?<name>\\w+)_\\d{3}\\.md/i\n const match = errorMdUrl.match(ErrorMdRx)\n return match?.groups?.name || ''\n }\n\n parse(docUrl: string): IErrorDocLink {\n const match = docUrl.match(ErrorDocRx)\n return {\n redirector: match?.groups?.redirector || '',\n apiVersion: match?.groups?.apiVersion || '',\n statusCode: match?.groups?.statusCode || '',\n apiPath: match?.groups?.apiPath || '',\n }\n }\n}\n"],"mappings":";;;;;;AA2BA;AAAmC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQ5B,IAAMA,aAAa,GAAG,gDAAgD;AAAA;AAMtE,IAAMC,gBAAgB,GAAG,iCAAiC;AAAA;AAGjE,IAAMC,yBAAyB,GAAGC,MAAM,CAACC,GAAG,+XAA4J;AACjM,IAAMC,UAAU,GAAGC,MAAM,CAACJ,yBAAyB,EAAE,GAAG,CAAC;AAAA;AAmFhE,IAAMK,SAAS;EAAA,6BAAG,WAAOC,GAAgB,EAAEC,GAAW,EAAK;IACzD,aAAa,IAAAC,gBAA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AAC;EACH;AACF;AAAC"}
@@ -1,51 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CSRFSession = void 0;
7
+ var _browserTransport = require("./browserTransport");
8
+ var _authSession = require("./authSession");
1
9
  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); } }
2
-
3
10
  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); }); }; }
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 { BrowserTransport } from './browserTransport';
8
- import { AuthSession } from './authSession';
9
- export class CSRFSession extends AuthSession {
11
+ 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; }
12
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
13
+ 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); }
14
+ class CSRFSession extends _authSession.AuthSession {
10
15
  constructor(settings, transport) {
11
- super(settings, transport || new BrowserTransport(settings));
16
+ super(settings, transport || new _browserTransport.BrowserTransport(settings));
12
17
  this.settings = settings;
13
-
14
18
  _defineProperty(this, "_activeToken", '');
15
19
  }
16
-
17
20
  get activeToken() {
18
21
  if (!this._activeToken) {
19
22
  var meta = document.head.querySelector('[name=csrf-token]');
20
23
  this._activeToken = meta ? meta.content : '';
21
24
  }
22
-
23
25
  return this._activeToken;
24
26
  }
25
-
26
27
  getToken() {
27
28
  var _this = this;
28
-
29
29
  return _asyncToGenerator(function* () {
30
30
  return _this.activeToken;
31
31
  })();
32
32
  }
33
-
34
33
  isAuthenticated() {
35
34
  var token = this.activeToken;
36
35
  if (!token) return false;
37
36
  return true;
38
37
  }
39
-
40
38
  authenticate(props) {
41
39
  var _this2 = this;
42
-
43
40
  return _asyncToGenerator(function* () {
44
41
  var token = _this2.activeToken;
45
42
  if (token) props.headers['X-CSRF-TOKEN'] = token;
46
43
  return props;
47
44
  })();
48
45
  }
49
-
50
46
  }
47
+ exports.CSRFSession = CSRFSession;
51
48
  //# sourceMappingURL=CSRFSession.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/CSRFSession.ts"],"names":["BrowserTransport","AuthSession","CSRFSession","constructor","settings","transport","activeToken","_activeToken","meta","document","head","querySelector","content","getToken","isAuthenticated","token","authenticate","props","headers"],"mappings":";;;;;;AA4BA,SAASA,gBAAT,QAAiC,oBAAjC;AACA,SAASC,WAAT,QAA4B,eAA5B;AAUA,OAAO,MAAMC,WAAN,SAA0BD,WAA1B,CAAsC;AAE3CE,EAAAA,WAAW,CAAQC,QAAR,EAAgCC,SAAhC,EAAwD;AACjE,UAAMD,QAAN,EAAgBC,SAAS,IAAI,IAAIL,gBAAJ,CAAqBI,QAArB,CAA7B;AADiE,SAAhDA,QAAgD,GAAhDA,QAAgD;;AAAA,0CADpD,EACoD;AAElE;;AAEc,MAAXE,WAAW,GAAG;AAChB,QAAI,CAAC,KAAKC,YAAV,EAAwB;AACtB,UAAMC,IAAI,GAAGC,QAAQ,CAACC,IAAT,CAAcC,aAAd,CACX,mBADW,CAAb;AAGA,WAAKJ,YAAL,GAAoBC,IAAI,GAAGA,IAAI,CAACI,OAAR,GAAkB,EAA1C;AACD;;AACD,WAAO,KAAKL,YAAZ;AACD;;AAEKM,EAAAA,QAAQ,GAAG;AAAA;;AAAA;AACf,aAAO,KAAI,CAACP,WAAZ;AADe;AAEhB;;AAMDQ,EAAAA,eAAe,GAAG;AAChB,QAAMC,KAAK,GAAG,KAAKT,WAAnB;AACA,QAAI,CAACS,KAAL,EAAY,OAAO,KAAP;AACZ,WAAO,IAAP;AACD;;AAOKC,EAAAA,YAAY,CAACC,KAAD,EAAuB;AAAA;;AAAA;AACvC,UAAMF,KAAK,GAAG,MAAI,CAACT,WAAnB;AACA,UAAIS,KAAJ,EAAWE,KAAK,CAACC,OAAN,CAAc,cAAd,IAAgCH,KAAhC;AACX,aAAOE,KAAP;AAHuC;AAIxC;;AAvC0C","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 { IApiSettings } from './apiSettings'\nimport type { IRequestProps, ITransport } from './transport'\nimport { BrowserTransport } from './browserTransport'\nimport { AuthSession } from './authSession'\n\n/**\n * CSRFSession is only for use within the Looker UI or a script that\n * executes in the Looker UI. Not for use by third party web apps. Looker UI web\n * service endpoints require that requests must contain a CSRF token to block third\n * party request forgeries. The actual login state is conveyed via encrypted browser\n * cookies exclusive to the looker domain, which the browser implicitly includes on\n * all web requests to looker UI web service.\n */\nexport class CSRFSession extends AuthSession {\n _activeToken = ''\n constructor(public settings: IApiSettings, transport?: ITransport) {\n super(settings, transport || new BrowserTransport(settings))\n }\n\n get activeToken() {\n if (!this._activeToken) {\n const meta = document.head.querySelector(\n '[name=csrf-token]'\n ) as HTMLMetaElement\n this._activeToken = meta ? meta.content : ''\n }\n return this._activeToken\n }\n\n async getToken() {\n return this.activeToken\n }\n\n /**\n * Returns true if the same origin browser session has a CRSF token established\n * that can be used for API authentication\n */\n isAuthenticated() {\n const token = this.activeToken\n if (!token) return false\n return true\n }\n\n /**\n * Authenticates a request with the CSRF token if it is active\n *\n * @param props Request properties to decorate\n */\n async authenticate(props: IRequestProps) {\n const token = this.activeToken\n if (token) props.headers['X-CSRF-TOKEN'] = token\n return props\n }\n}\n"],"file":"CSRFSession.js"}
1
+ {"version":3,"file":"CSRFSession.js","names":["CSRFSession","AuthSession","constructor","settings","transport","BrowserTransport","activeToken","_activeToken","meta","document","head","querySelector","content","getToken","isAuthenticated","token","authenticate","props","headers"],"sources":["../../src/CSRFSession.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { IApiSettings } from './apiSettings'\nimport type { IRequestProps, ITransport } from './transport'\nimport { BrowserTransport } from './browserTransport'\nimport { AuthSession } from './authSession'\n\n/**\n * CSRFSession is only for use within the Looker UI or a script that\n * executes in the Looker UI. Not for use by third party web apps. Looker UI web\n * service endpoints require that requests must contain a CSRF token to block third\n * party request forgeries. The actual login state is conveyed via encrypted browser\n * cookies exclusive to the looker domain, which the browser implicitly includes on\n * all web requests to looker UI web service.\n */\nexport class CSRFSession extends AuthSession {\n _activeToken = ''\n constructor(public settings: IApiSettings, transport?: ITransport) {\n super(settings, transport || new BrowserTransport(settings))\n }\n\n get activeToken() {\n if (!this._activeToken) {\n const meta = document.head.querySelector(\n '[name=csrf-token]'\n ) as HTMLMetaElement\n this._activeToken = meta ? meta.content : ''\n }\n return this._activeToken\n }\n\n async getToken() {\n return this.activeToken\n }\n\n /**\n * Returns true if the same origin browser session has a CRSF token established\n * that can be used for API authentication\n */\n isAuthenticated() {\n const token = this.activeToken\n if (!token) return false\n return true\n }\n\n /**\n * Authenticates a request with the CSRF token if it is active\n *\n * @param props Request properties to decorate\n */\n async authenticate(props: IRequestProps) {\n const token = this.activeToken\n if (token) props.headers['X-CSRF-TOKEN'] = token\n return props\n }\n}\n"],"mappings":";;;;;;AA4BA;AACA;AAA2C;AAAA;AAAA;AAAA;AAAA;AAUpC,MAAMA,WAAW,SAASC,wBAAW,CAAC;EAE3CC,WAAW,CAAQC,QAAsB,EAAEC,SAAsB,EAAE;IACjE,KAAK,CAACD,QAAQ,EAAEC,SAAS,IAAI,IAAIC,kCAAgB,CAACF,QAAQ,CAAC,CAAC;IAAA,KAD3CA,QAAsB,GAAtBA,QAAsB;IAAA,sCAD1B,EAAE;EAGjB;EAEA,IAAIG,WAAW,GAAG;IAChB,IAAI,CAAC,IAAI,CAACC,YAAY,EAAE;MACtB,IAAMC,IAAI,GAAGC,QAAQ,CAACC,IAAI,CAACC,aAAa,CACtC,mBAAmB,CACD;MACpB,IAAI,CAACJ,YAAY,GAAGC,IAAI,GAAGA,IAAI,CAACI,OAAO,GAAG,EAAE;IAC9C;IACA,OAAO,IAAI,CAACL,YAAY;EAC1B;EAEMM,QAAQ,GAAG;IAAA;IAAA;MACf,OAAO,KAAI,CAACP,WAAW;IAAA;EACzB;EAMAQ,eAAe,GAAG;IAChB,IAAMC,KAAK,GAAG,IAAI,CAACT,WAAW;IAC9B,IAAI,CAACS,KAAK,EAAE,OAAO,KAAK;IACxB,OAAO,IAAI;EACb;EAOMC,YAAY,CAACC,KAAoB,EAAE;IAAA;IAAA;MACvC,IAAMF,KAAK,GAAG,MAAI,CAACT,WAAW;MAC9B,IAAIS,KAAK,EAAEE,KAAK,CAACC,OAAO,CAAC,cAAc,CAAC,GAAGH,KAAK;MAChD,OAAOE,KAAK;IAAA;EACd;AACF;AAAC"}
@@ -1,153 +1,125 @@
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
-
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.functionalSdk = exports.APIMethods = void 0;
7
+ var _transport = require("./transport");
8
+ 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; }
9
+ 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; }
5
10
  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); } }
6
-
7
11
  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); }); }; }
8
-
9
- 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; }
10
-
11
- import { agentPrefix, sdkOk } from './transport';
12
- export var functionalSdk = (authSession, apiVersion, sdkVersion) => {
12
+ 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; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
14
+ 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); }
15
+ var functionalSdk = (authSession, apiVersion, sdkVersion) => {
13
16
  var sdk = new APIMethods(authSession, sdkVersion);
14
17
  sdk.apiVersion = apiVersion;
15
18
  sdk.apiPath = authSession.settings.base_url === '' ? '' : authSession.settings.base_url + '/api/' + apiVersion;
16
19
  return sdk;
17
20
  };
18
- export class APIMethods {
21
+ exports.functionalSdk = functionalSdk;
22
+ class APIMethods {
19
23
  constructor(authSession, sdkVersion) {
20
24
  this.authSession = authSession;
21
25
  this.sdkVersion = sdkVersion;
22
-
23
26
  _defineProperty(this, "_apiPath", '');
24
-
25
27
  _defineProperty(this, "_apiVersion", '');
26
-
27
28
  if (!('agentTag' in authSession.settings && authSession.settings.agentTag)) {
28
- authSession.settings.agentTag = "".concat(agentPrefix, " ").concat(sdkVersion);
29
+ authSession.settings.agentTag = "".concat(_transport.agentPrefix, " ").concat(sdkVersion);
29
30
  }
30
31
  }
31
-
32
32
  get apiPath() {
33
33
  return this._apiPath;
34
34
  }
35
-
36
35
  set apiPath(value) {
37
36
  if (this._apiPath) {
38
37
  throw new Error("API Path is set to \"".concat(this._apiPath, "\" and cannot be reassigned"));
39
38
  }
40
-
41
39
  this._apiPath = value;
42
40
  }
43
-
44
41
  get apiVersion() {
45
42
  return this._apiVersion;
46
43
  }
47
-
48
44
  set apiVersion(value) {
49
45
  if (this._apiVersion) {
50
46
  throw new Error("API Version is set to \"".concat(this._apiVersion, "\" and cannot be reassigned"));
51
47
  }
52
-
53
48
  this._apiVersion = value;
54
49
  }
55
-
56
50
  static create(type, authSession) {
57
51
  return new type(authSession);
58
52
  }
59
-
60
53
  ok(promise) {
61
54
  return _asyncToGenerator(function* () {
62
- return sdkOk(promise);
55
+ return (0, _transport.sdkOk)(promise);
63
56
  })();
64
57
  }
65
-
66
58
  makePath(path, options, authenticator) {
67
59
  if (path.match(/^(http:\/\/|https:\/\/)/gi)) return path;
68
60
  var base = authenticator ? this.apiPath : options.base_url;
69
61
  return "".concat(base).concat(path);
70
62
  }
71
-
72
63
  authRequest(method, path, queryParams, body, options) {
73
64
  var _this = this;
74
-
75
65
  return _asyncToGenerator(function* () {
76
66
  options = _objectSpread(_objectSpread({}, _this.authSession.settings), options);
77
-
78
67
  var authenticator = init => {
79
68
  return _this.authSession.authenticate(init);
80
69
  };
81
-
82
70
  path = _this.makePath(path, options, authenticator);
83
71
  return _this.authSession.transport.request(method, path, queryParams, body, authenticator, options);
84
72
  })();
85
73
  }
86
-
87
74
  authStream(callback, method, path, queryParams, body, options) {
88
75
  var _this2 = this;
89
-
90
76
  return _asyncToGenerator(function* () {
91
77
  options = _objectSpread(_objectSpread({}, _this2.authSession.settings), options);
92
-
93
78
  var authenticator = init => {
94
79
  return _this2.authSession.authenticate(init);
95
80
  };
96
-
97
81
  path = _this2.makePath(path, options, authenticator);
98
82
  return _this2.authSession.transport.stream(callback, method, path, queryParams, body, init => {
99
83
  return _this2.authSession.authenticate(init);
100
84
  }, options);
101
85
  })();
102
86
  }
103
-
104
87
  get(path, queryParams, body, options) {
105
88
  var _this3 = this;
106
-
107
89
  return _asyncToGenerator(function* () {
108
90
  return _this3.authRequest('GET', path, queryParams, body, options);
109
91
  })();
110
92
  }
111
-
112
93
  head(path, queryParams, body, options) {
113
94
  var _this4 = this;
114
-
115
95
  return _asyncToGenerator(function* () {
116
96
  return _this4.authRequest('HEAD', path, queryParams, body, options);
117
97
  })();
118
98
  }
119
-
120
99
  delete(path, queryParams, body, options) {
121
100
  var _this5 = this;
122
-
123
101
  return _asyncToGenerator(function* () {
124
102
  return _this5.authRequest('DELETE', path, queryParams, body, options);
125
103
  })();
126
104
  }
127
-
128
105
  post(path, queryParams, body, options) {
129
106
  var _this6 = this;
130
-
131
107
  return _asyncToGenerator(function* () {
132
108
  return _this6.authRequest('POST', path, queryParams, body, options);
133
109
  })();
134
110
  }
135
-
136
111
  put(path, queryParams, body, options) {
137
112
  var _this7 = this;
138
-
139
113
  return _asyncToGenerator(function* () {
140
114
  return _this7.authRequest('PUT', path, queryParams, body, options);
141
115
  })();
142
116
  }
143
-
144
117
  patch(path, queryParams, body, options) {
145
118
  var _this8 = this;
146
-
147
119
  return _asyncToGenerator(function* () {
148
120
  return _this8.authRequest('PATCH', path, queryParams, body, options);
149
121
  })();
150
122
  }
151
-
152
123
  }
124
+ exports.APIMethods = APIMethods;
153
125
  //# sourceMappingURL=apiMethods.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/apiMethods.ts"],"names":["agentPrefix","sdkOk","functionalSdk","authSession","apiVersion","sdkVersion","sdk","APIMethods","apiPath","settings","base_url","constructor","agentTag","_apiPath","value","Error","_apiVersion","create","type","ok","promise","makePath","path","options","authenticator","match","base","authRequest","method","queryParams","body","init","authenticate","transport","request","authStream","callback","stream","get","head","delete","post","put","patch"],"mappings":";;;;;;;;;;AAkCA,SAASA,WAAT,EAAsBC,KAAtB,QAAmC,aAAnC;AASA,OAAO,IAAMC,aAAa,GAAG,CAC3BC,WAD2B,EAE3BC,UAF2B,EAG3BC,UAH2B,KAIxB;AACH,MAAMC,GAAG,GAAG,IAAIC,UAAJ,CAAeJ,WAAf,EAA4BE,UAA5B,CAAZ;AACAC,EAAAA,GAAG,CAACF,UAAJ,GAAiBA,UAAjB;AACAE,EAAAA,GAAG,CAACE,OAAJ,GACEL,WAAW,CAACM,QAAZ,CAAqBC,QAArB,KAAkC,EAAlC,GACI,EADJ,GAEIP,WAAW,CAACM,QAAZ,CAAqBC,QAArB,GAAgC,OAAhC,GAA0CN,UAHhD;AAIA,SAAOE,GAAP;AACD,CAZM;AAkJP,O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K,EAELL,IAFK,EAGLO,WAHK,EAILC,IAJK,EAKLP,OALK,CAAP;AADwC;AAQzC;;AAzR4C","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 { Readable } from 'readable-stream'\nimport type {\n Authenticator,\n HttpMethod,\n ITransportSettings,\n SDKResponse,\n Values,\n} from './transport'\nimport { agentPrefix, sdkOk } from './transport'\nimport type { IAuthSession } from './authSession'\n\n/**\n * Creates an \"sdk\" to be used with the TypeScript SDK's funcs.ts file\n * @param authSession authentication session\n * @param apiVersion version of API to use (e.g. \"3.1\" or \"4.0\")\n * @param sdkVersion Looker release version (e.g. \"21.4\")\n */\nexport const functionalSdk = (\n authSession: IAuthSession,\n apiVersion: string,\n sdkVersion: string\n) => {\n const sdk = new APIMethods(authSession, sdkVersion)\n sdk.apiVersion = apiVersion\n sdk.apiPath =\n authSession.settings.base_url === ''\n ? ''\n : authSession.settings.base_url + '/api/' + apiVersion\n return sdk\n}\n\nexport interface IAPIMethods {\n authSession: IAuthSession\n sdkVersion: string\n apiPath: string\n apiVersion: string\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 sdk.ok(sdk.create_look({...}))\n * // do something with look\n * }\n * catch(e) {\n * // handle error case\n * }\n * ```\n */\n ok<TSuccess, TError>(\n promise: Promise<SDKResponse<TSuccess, TError>>\n ): Promise<TSuccess>\n\n /**\n * Determine whether the url should be an API path, relative from base_url, or is already fully specified override\n * @param path Request path\n * @param options Transport settings\n * @param authenticator optional callback\n * @returns the fully specified request path including any query string parameters\n */\n makePath(\n path: string,\n options: Partial<ITransportSettings>,\n authenticator?: Authenticator\n ): string\n\n /**\n *\n * A helper method to add authentication to an API request for deserialization\n *\n * @param {HttpMethod} method type of HTTP method\n * @param {string} path API endpoint path\n * @param {any} queryParams Optional query params collection for request\n * @param {any} body Optional body for request\n * @param {Partial<ITransportSettings>} options Optional overrides like timeout and verify_ssl\n */\n authRequest<TSuccess, TError>(\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /**\n * A helper method to add authentication to an API request for streaming\n * @param {(readable: Readable) => Promise<T>} callback\n * @param {HttpMethod} method\n * @param {string} path\n * @param queryParams\n * @param body\n * @param {Partial<ITransportSettings>} options\n * @returns {Promise<T>}\n */\n authStream<T>(\n callback: (readable: Readable) => Promise<T>,\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<T>\n\n /** Make a GET request */\n get<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /** Make a HEAD request */\n head<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /** Make a DELETE request */\n delete<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /** Make a POST request */\n post<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /** Make a PUT request */\n put<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /** Make a PATCH request */\n patch<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n}\n\nexport class APIMethods implements IAPIMethods {\n private _apiPath = ''\n private _apiVersion = ''\n\n /**\n * Initialize the APIMethods wrapper\n * @param authSession authentication management session\n * @param sdkVersion version of the SDK for agent tagging\n */\n constructor(public authSession: IAuthSession, public sdkVersion: string) {\n if (\n !('agentTag' in authSession.settings && authSession.settings.agentTag)\n ) {\n // Initialize agentTag if it's not already explicitly set\n authSession.settings.agentTag = `${agentPrefix} ${sdkVersion}`\n }\n }\n\n get apiPath() {\n return this._apiPath\n }\n\n set apiPath(value: string) {\n if (this._apiPath) {\n throw new Error(\n `API Path is set to \"${this._apiPath}\" and cannot be reassigned`\n )\n }\n this._apiPath = value\n }\n\n get apiVersion() {\n return this._apiVersion\n }\n\n set apiVersion(value: string) {\n // API version can only be set once for the instance\n if (this._apiVersion) {\n throw new Error(\n `API Version is set to \"${this._apiVersion}\" and cannot be reassigned`\n )\n }\n this._apiVersion = value\n }\n\n /** A helper method for constructing with a type as a param\n *\n * Example:\n * APIMethods.create(Looker40SDK, authSession)\n *\n * @param type\n * @param authSession\n */\n static create<T extends APIMethods>(\n type: new (authSession: IAuthSession) => T,\n authSession: IAuthSession\n ): T {\n // eslint-disable-next-line new-cap\n return new type(authSession)\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 sdk.ok(sdk.create_look({...}))\n * // do something with look\n * }\n * catch(e) {\n * // handle error case\n * }\n * ```\n */\n async ok<TSuccess, TError>(promise: Promise<SDKResponse<TSuccess, TError>>) {\n return sdkOk<TSuccess, TError>(promise)\n }\n\n /**\n * Determine whether the url should be an API path, relative from base_url, or is already fully specified override\n * @param path Request path\n * @param options Transport settings\n * @param authenticator optional callback\n * @returns the fully specified request path including any query string parameters\n */\n makePath(\n path: string,\n options: Partial<ITransportSettings>,\n authenticator?: Authenticator\n ) {\n if (path.match(/^(http:\\/\\/|https:\\/\\/)/gi)) return path\n // is this an API-versioned call?\n const base = authenticator ? this.apiPath : options.base_url\n return `${base}${path}` // path was relative\n }\n\n /**\n *\n * A helper method to add authentication to an API request for deserialization\n *\n * @param {HttpMethod} method type of HTTP method\n * @param {string} path API endpoint path\n * @param {any} queryParams Optional query params collection for request\n * @param {any} body Optional body for request\n * @param {Partial<ITransportSettings>} options Optional overrides like timeout and verify_ssl\n */\n async authRequest<TSuccess, TError>(\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n options = { ...this.authSession.settings, ...options }\n const authenticator = (init: any) => {\n return this.authSession.authenticate(init)\n }\n path = this.makePath(path, options, authenticator)\n return this.authSession.transport.request<TSuccess, TError>(\n method,\n path,\n queryParams,\n body,\n authenticator,\n options\n )\n }\n\n /**\n * A helper method to add authentication to an API request for streaming\n * @param {(readable: Readable) => Promise<T>} callback\n * @param {HttpMethod} method\n * @param {string} path\n * @param queryParams\n * @param body\n * @param {Partial<ITransportSettings>} options\n * @returns {Promise<T>}\n */\n async authStream<T>(\n callback: (readable: Readable) => Promise<T>,\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<T> {\n options = { ...this.authSession.settings, ...options }\n const authenticator = (init: any) => {\n return this.authSession.authenticate(init)\n }\n path = this.makePath(path, options, authenticator)\n return this.authSession.transport.stream<T>(\n callback,\n method,\n path,\n queryParams,\n body,\n (init: any) => {\n return this.authSession.authenticate(init)\n },\n options\n )\n }\n\n // // dynamically evaluate a template string\n // macro(template: string, vars: any) {\n // // replace {foo} from spec path with ${foo} for template string\n // template = template.replace(/{/gi, '${')\n // return new Function('return `+ template +`;').call(vars)\n // }\n //\n // pathify(path: string, pathParams?: any) {\n // if (!pathParams) return path\n // if (path.indexOf('{') < 0) return path\n // return this.macro(path, pathParams)\n // }\n\n /** Make a GET request */\n async get<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n return this.authRequest<TSuccess, TError>(\n 'GET',\n path,\n queryParams,\n body,\n options\n )\n }\n\n /** Make a HEAD request */\n async head<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n return this.authRequest<TSuccess, TError>(\n 'HEAD',\n path,\n queryParams,\n body,\n options\n )\n }\n\n /** Make a DELETE request */\n async delete<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n return this.authRequest<TSuccess, TError>(\n 'DELETE',\n path,\n queryParams,\n body,\n options\n )\n }\n\n /** Make a POST request */\n async post<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n return this.authRequest<TSuccess, TError>(\n 'POST',\n path,\n queryParams,\n body,\n options\n )\n }\n\n /** Make a PUT request */\n async put<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n return this.authRequest<TSuccess, TError>(\n 'PUT',\n path,\n queryParams,\n body,\n options\n )\n }\n\n /** Make a PATCH request */\n async patch<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n return this.authRequest<TSuccess, TError>(\n 'PATCH',\n path,\n queryParams,\n body,\n options\n )\n }\n}\n"],"file":"apiMethods.js"}
1
+ {"version":3,"file":"apiMethods.js","names":["functionalSdk","authSession","apiVersion","sdkVersion","sdk","APIMethods","apiPath","settings","base_url","constructor","agentTag","agentPrefix","_apiPath","value","Error","_apiVersion","create","type","ok","promise","sdkOk","makePath","path","options","authenticator","match","base","authRequest","method","queryParams","body","init","authenticate","transport","request","authStream","callback","stream","get","head","delete","post","put","patch"],"sources":["../../src/apiMethods.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { Readable } from 'readable-stream'\nimport type {\n Authenticator,\n HttpMethod,\n ITransportSettings,\n SDKResponse,\n Values,\n} from './transport'\nimport { agentPrefix, sdkOk } from './transport'\nimport type { IAuthSession } from './authSession'\n\n/**\n * Creates an \"sdk\" to be used with the TypeScript SDK's funcs.ts file\n * @param authSession authentication session\n * @param apiVersion version of API to use (e.g. \"3.1\" or \"4.0\")\n * @param sdkVersion Looker release version (e.g. \"21.4\")\n */\nexport const functionalSdk = (\n authSession: IAuthSession,\n apiVersion: string,\n sdkVersion: string\n) => {\n const sdk = new APIMethods(authSession, sdkVersion)\n sdk.apiVersion = apiVersion\n sdk.apiPath =\n authSession.settings.base_url === ''\n ? ''\n : authSession.settings.base_url + '/api/' + apiVersion\n return sdk\n}\n\nexport interface IAPIMethods {\n authSession: IAuthSession\n sdkVersion: string\n apiPath: string\n apiVersion: string\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 sdk.ok(sdk.create_look({...}))\n * // do something with look\n * }\n * catch(e) {\n * // handle error case\n * }\n * ```\n */\n ok<TSuccess, TError>(\n promise: Promise<SDKResponse<TSuccess, TError>>\n ): Promise<TSuccess>\n\n /**\n * Determine whether the url should be an API path, relative from base_url, or is already fully specified override\n * @param path Request path\n * @param options Transport settings\n * @param authenticator optional callback\n * @returns the fully specified request path including any query string parameters\n */\n makePath(\n path: string,\n options: Partial<ITransportSettings>,\n authenticator?: Authenticator\n ): string\n\n /**\n *\n * A helper method to add authentication to an API request for deserialization\n *\n * @param {HttpMethod} method type of HTTP method\n * @param {string} path API endpoint path\n * @param {any} queryParams Optional query params collection for request\n * @param {any} body Optional body for request\n * @param {Partial<ITransportSettings>} options Optional overrides like timeout and verify_ssl\n */\n authRequest<TSuccess, TError>(\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /**\n * A helper method to add authentication to an API request for streaming\n * @param {(readable: Readable) => Promise<T>} callback\n * @param {HttpMethod} method\n * @param {string} path\n * @param queryParams\n * @param body\n * @param {Partial<ITransportSettings>} options\n * @returns {Promise<T>}\n */\n authStream<T>(\n callback: (readable: Readable) => Promise<T>,\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<T>\n\n /** Make a GET request */\n get<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /** Make a HEAD request */\n head<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /** Make a DELETE request */\n delete<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /** Make a POST request */\n post<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /** Make a PUT request */\n put<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n\n /** Make a PATCH request */\n patch<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>\n}\n\nexport class APIMethods implements IAPIMethods {\n private _apiPath = ''\n private _apiVersion = ''\n\n /**\n * Initialize the APIMethods wrapper\n * @param authSession authentication management session\n * @param sdkVersion version of the SDK for agent tagging\n */\n constructor(public authSession: IAuthSession, public sdkVersion: string) {\n if (\n !('agentTag' in authSession.settings && authSession.settings.agentTag)\n ) {\n // Initialize agentTag if it's not already explicitly set\n authSession.settings.agentTag = `${agentPrefix} ${sdkVersion}`\n }\n }\n\n get apiPath() {\n return this._apiPath\n }\n\n set apiPath(value: string) {\n if (this._apiPath) {\n throw new Error(\n `API Path is set to \"${this._apiPath}\" and cannot be reassigned`\n )\n }\n this._apiPath = value\n }\n\n get apiVersion() {\n return this._apiVersion\n }\n\n set apiVersion(value: string) {\n // API version can only be set once for the instance\n if (this._apiVersion) {\n throw new Error(\n `API Version is set to \"${this._apiVersion}\" and cannot be reassigned`\n )\n }\n this._apiVersion = value\n }\n\n /** A helper method for constructing with a type as a param\n *\n * Example:\n * APIMethods.create(Looker40SDK, authSession)\n *\n * @param type\n * @param authSession\n */\n static create<T extends APIMethods>(\n type: new (authSession: IAuthSession) => T,\n authSession: IAuthSession\n ): T {\n // eslint-disable-next-line new-cap\n return new type(authSession)\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 sdk.ok(sdk.create_look({...}))\n * // do something with look\n * }\n * catch(e) {\n * // handle error case\n * }\n * ```\n */\n async ok<TSuccess, TError>(promise: Promise<SDKResponse<TSuccess, TError>>) {\n return sdkOk<TSuccess, TError>(promise)\n }\n\n /**\n * Determine whether the url should be an API path, relative from base_url, or is already fully specified override\n * @param path Request path\n * @param options Transport settings\n * @param authenticator optional callback\n * @returns the fully specified request path including any query string parameters\n */\n makePath(\n path: string,\n options: Partial<ITransportSettings>,\n authenticator?: Authenticator\n ) {\n if (path.match(/^(http:\\/\\/|https:\\/\\/)/gi)) return path\n // is this an API-versioned call?\n const base = authenticator ? this.apiPath : options.base_url\n return `${base}${path}` // path was relative\n }\n\n /**\n *\n * A helper method to add authentication to an API request for deserialization\n *\n * @param {HttpMethod} method type of HTTP method\n * @param {string} path API endpoint path\n * @param {any} queryParams Optional query params collection for request\n * @param {any} body Optional body for request\n * @param {Partial<ITransportSettings>} options Optional overrides like timeout and verify_ssl\n */\n async authRequest<TSuccess, TError>(\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n options = { ...this.authSession.settings, ...options }\n const authenticator = (init: any) => {\n return this.authSession.authenticate(init)\n }\n path = this.makePath(path, options, authenticator)\n return this.authSession.transport.request<TSuccess, TError>(\n method,\n path,\n queryParams,\n body,\n authenticator,\n options\n )\n }\n\n /**\n * A helper method to add authentication to an API request for streaming\n * @param {(readable: Readable) => Promise<T>} callback\n * @param {HttpMethod} method\n * @param {string} path\n * @param queryParams\n * @param body\n * @param {Partial<ITransportSettings>} options\n * @returns {Promise<T>}\n */\n async authStream<T>(\n callback: (readable: Readable) => Promise<T>,\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<T> {\n options = { ...this.authSession.settings, ...options }\n const authenticator = (init: any) => {\n return this.authSession.authenticate(init)\n }\n path = this.makePath(path, options, authenticator)\n return this.authSession.transport.stream<T>(\n callback,\n method,\n path,\n queryParams,\n body,\n (init: any) => {\n return this.authSession.authenticate(init)\n },\n options\n )\n }\n\n // // dynamically evaluate a template string\n // macro(template: string, vars: any) {\n // // replace {foo} from spec path with ${foo} for template string\n // template = template.replace(/{/gi, '${')\n // return new Function('return `+ template +`;').call(vars)\n // }\n //\n // pathify(path: string, pathParams?: any) {\n // if (!pathParams) return path\n // if (path.indexOf('{') < 0) return path\n // return this.macro(path, pathParams)\n // }\n\n /** Make a GET request */\n async get<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n return this.authRequest<TSuccess, TError>(\n 'GET',\n path,\n queryParams,\n body,\n options\n )\n }\n\n /** Make a HEAD request */\n async head<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n return this.authRequest<TSuccess, TError>(\n 'HEAD',\n path,\n queryParams,\n body,\n options\n )\n }\n\n /** Make a DELETE request */\n async delete<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n return this.authRequest<TSuccess, TError>(\n 'DELETE',\n path,\n queryParams,\n body,\n options\n )\n }\n\n /** Make a POST request */\n async post<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n return this.authRequest<TSuccess, TError>(\n 'POST',\n path,\n queryParams,\n body,\n options\n )\n }\n\n /** Make a PUT request */\n async put<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n return this.authRequest<TSuccess, TError>(\n 'PUT',\n path,\n queryParams,\n body,\n options\n )\n }\n\n /** Make a PATCH request */\n async patch<TSuccess, TError>(\n path: string,\n queryParams?: Values,\n body?: any,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>> {\n return this.authRequest<TSuccess, TError>(\n 'PATCH',\n path,\n queryParams,\n body,\n options\n )\n }\n}\n"],"mappings":";;;;;;AAkCA;AAAgD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASzC,IAAMA,aAAa,GAAG,CAC3BC,WAAyB,EACzBC,UAAkB,EAClBC,UAAkB,KACf;EACH,IAAMC,GAAG,GAAG,IAAIC,UAAU,CAACJ,WAAW,EAAEE,UAAU,CAAC;EACnDC,GAAG,CAACF,UAAU,GAAGA,UAAU;EAC3BE,GAAG,CAACE,OAAO,GACTL,WAAW,CAACM,QAAQ,CAACC,QAAQ,KAAK,EAAE,GAChC,EAAE,GACFP,WAAW,CAACM,QAAQ,CAACC,QAAQ,GAAG,OAAO,GAAGN,UAAU;EAC1D,OAAOE,GAAG;AACZ,CAAC;AAAA;AAsIM,MAAMC,UAAU,CAAwB;EAS7CI,WAAW,CAAQR,WAAyB,EAASE,UAAkB,EAAE;IAAA,KAAtDF,WAAyB,GAAzBA,WAAyB;IAAA,KAASE,UAAkB,GAAlBA,UAAkB;IAAA,kCARpD,EAAE;IAAA,qCACC,EAAE;IAQtB,IACE,EAAE,UAAU,IAAIF,WAAW,CAACM,QAAQ,IAAIN,WAAW,CAACM,QAAQ,CAACG,QAAQ,CAAC,EACtE;MAEAT,WAAW,CAACM,QAAQ,CAACG,QAAQ,aAAMC,sBAAW,cAAIR,UAAU,CAAE;IAChE;EACF;EAEA,IAAIG,OAAO,GAAG;IACZ,OAAO,IAAI,CAACM,QAAQ;EACtB;EAEA,IAAIN,OAAO,CAACO,KAAa,EAAE;IACzB,IAAI,IAAI,CAACD,QAAQ,EAAE;MACjB,MAAM,IAAIE,KAAK,gCACU,IAAI,CAACF,QAAQ,iCACrC;IACH;IACA,IAAI,CAACA,QAAQ,GAAGC,KAAK;EACvB;EAEA,IAAIX,UAAU,GAAG;IACf,OAAO,IAAI,CAACa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