@nsshunt/stsrest01client 1.0.21 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,7 @@
1
1
  (function(global, factory) {
2
2
  typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("node:fs"), require("path"), require("os"), require("crypto"), require("axios"), require("@nsshunt/stsutils")) : typeof define === "function" && define.amd ? define(["exports", "node:fs", "path", "os", "crypto", "axios", "@nsshunt/stsutils"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@nsshunt/stsrest01client"] = {}, global.https, global.path, global.os, global.crypto, global.axios, global.stsutils));
3
- })(this, function(exports2, node_fs, require$$1, require$$2, require$$3, axios, stsutils) {
4
- "use strict";var __defProp = Object.defineProperty;
5
- var __typeError = (msg) => {
6
- throw TypeError(msg);
7
- };
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
11
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
12
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
14
-
15
- var _options, _DUMMY_USER, _invokeMethods, _maxRetries, _sleepDuration, _NoRetryStatusCodes, _accessToken, _noRetries, _LogDebugMessage, _LogErrorMessage, _TestMode, ___InvokeResourceAPI, _axiosClient, _options2, _checkResName;
3
+ })(this, (function(exports2, node_fs, require$$1, require$$2, require$$3, axios, stsutils) {
4
+ "use strict";
16
5
  function getDefaultExportFromCjs(x) {
17
6
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
18
7
  }
@@ -21,7 +10,12 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
21
10
  var f = n.default;
22
11
  if (typeof f == "function") {
23
12
  var a = function a2() {
24
- if (this instanceof a2) {
13
+ var isInstance = false;
14
+ try {
15
+ isInstance = this instanceof a2;
16
+ } catch {
17
+ }
18
+ if (isInstance) {
25
19
  return Reflect.construct(f, arguments, this.constructor);
26
20
  }
27
21
  return f.apply(this, arguments);
@@ -47,7 +41,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
47
41
  default: __viteBrowserExternal
48
42
  }, Symbol.toStringTag, { value: "Module" }));
49
43
  const require$$0 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal$1);
50
- const version = "16.5.0";
44
+ const version = "17.2.3";
51
45
  const require$$4 = {
52
46
  version
53
47
  };
@@ -61,6 +55,39 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
61
55
  const crypto2 = require$$3;
62
56
  const packageJson = require$$4;
63
57
  const version2 = packageJson.version;
58
+ const TIPS = [
59
+ "🔐 encrypt with Dotenvx: https://dotenvx.com",
60
+ "🔐 prevent committing .env to code: https://dotenvx.com/precommit",
61
+ "🔐 prevent building .env in docker: https://dotenvx.com/prebuild",
62
+ "📡 add observability to secrets: https://dotenvx.com/ops",
63
+ "👥 sync secrets across teammates & machines: https://dotenvx.com/ops",
64
+ "🗂️ backup and recover secrets: https://dotenvx.com/ops",
65
+ "✅ audit secrets and track compliance: https://dotenvx.com/ops",
66
+ "🔄 add secrets lifecycle management: https://dotenvx.com/ops",
67
+ "🔑 add access controls to secrets: https://dotenvx.com/ops",
68
+ "🛠️ run anywhere with `dotenvx run -- yourcommand`",
69
+ "⚙️ specify custom .env file path with { path: '/custom/path/.env' }",
70
+ "⚙️ enable debug logging with { debug: true }",
71
+ "⚙️ override existing env vars with { override: true }",
72
+ "⚙️ suppress all logs with { quiet: true }",
73
+ "⚙️ write to custom object with { processEnv: myObject }",
74
+ "⚙️ load multiple .env files with { path: ['.env.local', '.env'] }"
75
+ ];
76
+ function _getRandomTip() {
77
+ return TIPS[Math.floor(Math.random() * TIPS.length)];
78
+ }
79
+ function parseBoolean(value) {
80
+ if (typeof value === "string") {
81
+ return !["false", "0", "no", "off", ""].includes(value.toLowerCase());
82
+ }
83
+ return Boolean(value);
84
+ }
85
+ function supportsAnsi() {
86
+ return process.stdout.isTTY;
87
+ }
88
+ function dim(text) {
89
+ return supportsAnsi() ? `\x1B[2m${text}\x1B[0m` : text;
90
+ }
64
91
  const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
65
92
  function parse(src) {
66
93
  const obj = {};
@@ -82,8 +109,10 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
82
109
  return obj;
83
110
  }
84
111
  function _parseVault(options) {
112
+ options = options || {};
85
113
  const vaultPath = _vaultPath(options);
86
- const result = DotenvModule.configDotenv({ path: vaultPath });
114
+ options.path = vaultPath;
115
+ const result = DotenvModule.configDotenv(options);
87
116
  if (!result.parsed) {
88
117
  const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
89
118
  err.code = "MISSING_DATA";
@@ -107,11 +136,14 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
107
136
  return DotenvModule.parse(decrypted);
108
137
  }
109
138
  function _warn(message) {
110
- console.log(`[dotenv@${version2}][WARN] ${message}`);
139
+ console.error(`[dotenv@${version2}][WARN] ${message}`);
111
140
  }
112
141
  function _debug(message) {
113
142
  console.log(`[dotenv@${version2}][DEBUG] ${message}`);
114
143
  }
144
+ function _log(message) {
145
+ console.log(`[dotenv@${version2}] ${message}`);
146
+ }
115
147
  function _dotenvKey(options) {
116
148
  if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
117
149
  return options.DOTENV_KEY;
@@ -178,9 +210,10 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
178
210
  return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
179
211
  }
180
212
  function _configVault(options) {
181
- const debug = Boolean(options && options.debug);
182
- if (debug) {
183
- _debug("Loading env from encrypted .env.vault");
213
+ const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || options && options.debug);
214
+ const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || options && options.quiet);
215
+ if (debug || !quiet) {
216
+ _log("Loading env from encrypted .env.vault");
184
217
  }
185
218
  const parsed = DotenvModule._parseVault(options);
186
219
  let processEnv = process.env;
@@ -193,7 +226,12 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
193
226
  function configDotenv(options) {
194
227
  const dotenvPath = path.resolve(process.cwd(), ".env");
195
228
  let encoding = "utf8";
196
- const debug = Boolean(options && options.debug);
229
+ let processEnv = process.env;
230
+ if (options && options.processEnv != null) {
231
+ processEnv = options.processEnv;
232
+ }
233
+ let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || options && options.debug);
234
+ let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || options && options.quiet);
197
235
  if (options && options.encoding) {
198
236
  encoding = options.encoding;
199
237
  } else {
@@ -225,11 +263,25 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
225
263
  lastError = e;
226
264
  }
227
265
  }
228
- let processEnv = process.env;
229
- if (options && options.processEnv != null) {
230
- processEnv = options.processEnv;
266
+ const populated = DotenvModule.populate(processEnv, parsedAll, options);
267
+ debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
268
+ quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
269
+ if (debug || !quiet) {
270
+ const keysCount = Object.keys(populated).length;
271
+ const shortPaths = [];
272
+ for (const filePath of optionPaths) {
273
+ try {
274
+ const relative = path.relative(process.cwd(), filePath);
275
+ shortPaths.push(relative);
276
+ } catch (e) {
277
+ if (debug) {
278
+ _debug(`Failed to load ${filePath} ${e.message}`);
279
+ }
280
+ lastError = e;
281
+ }
282
+ }
283
+ _log(`injecting env (${keysCount}) from ${shortPaths.join(",")} ${dim(`-- tip: ${_getRandomTip()}`)}`);
231
284
  }
232
- DotenvModule.populate(processEnv, parsedAll, options);
233
285
  if (lastError) {
234
286
  return { parsed: parsedAll, error: lastError };
235
287
  } else {
@@ -277,6 +329,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
277
329
  function populate(processEnv, parsed, options = {}) {
278
330
  const debug = Boolean(options && options.debug);
279
331
  const override = Boolean(options && options.override);
332
+ const populated = {};
280
333
  if (typeof parsed !== "object") {
281
334
  const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
282
335
  err.code = "OBJECT_REQUIRED";
@@ -286,6 +339,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
286
339
  if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
287
340
  if (override === true) {
288
341
  processEnv[key] = parsed[key];
342
+ populated[key] = parsed[key];
289
343
  }
290
344
  if (debug) {
291
345
  if (override === true) {
@@ -296,8 +350,10 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
296
350
  }
297
351
  } else {
298
352
  processEnv[key] = parsed[key];
353
+ populated[key] = parsed[key];
299
354
  }
300
355
  }
356
+ return populated;
301
357
  }
302
358
  const DotenvModule = {
303
359
  configDotenv,
@@ -2007,13 +2063,9 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2007
2063
  }
2008
2064
  const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
2009
2065
  const native = { randomUUID };
2010
- function v4(options, buf, offset) {
2011
- var _a;
2012
- if (native.randomUUID && true && !options) {
2013
- return native.randomUUID();
2014
- }
2066
+ function _v4(options, buf, offset) {
2015
2067
  options = options || {};
2016
- const rnds = options.random ?? ((_a = options.rng) == null ? void 0 : _a.call(options)) ?? rng();
2068
+ const rnds = options.random ?? options.rng?.() ?? rng();
2017
2069
  if (rnds.length < 16) {
2018
2070
  throw new Error("Random bytes length must be >= 16");
2019
2071
  }
@@ -2021,6 +2073,12 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2021
2073
  rnds[8] = rnds[8] & 63 | 128;
2022
2074
  return unsafeStringify(rnds);
2023
2075
  }
2076
+ function v4(options, buf, offset) {
2077
+ if (native.randomUUID && true && !options) {
2078
+ return native.randomUUID();
2079
+ }
2080
+ return _v4(options);
2081
+ }
2024
2082
  const isNode = Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
2025
2083
  var ansiStyles = { exports: {} };
2026
2084
  var colorName;
@@ -3535,489 +3593,438 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
3535
3593
  StatusCodes2[StatusCodes2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
3536
3594
  })(StatusCodes || (StatusCodes = {}));
3537
3595
  class AxiosClient {
3596
+ #options;
3597
+ #DUMMY_USER = "USR_user01@stsmda.com.au";
3598
+ //@@ needs to come from headers ??
3599
+ #invokeMethods = {};
3600
+ #maxRetries = 5;
3601
+ #sleepDuration = [50, 100, 200, 500, 1e3, 2e3, 5e3];
3602
+ #NoRetryStatusCodes = [
3603
+ StatusCodes.NOT_FOUND,
3604
+ StatusCodes.CONFLICT
3605
+ ];
3606
+ #accessToken = null;
3607
+ #noRetries = false;
3538
3608
  constructor(options) {
3539
- __privateAdd(this, _options);
3540
- __privateAdd(this, _DUMMY_USER, "USR_user01@stsmda.com.au");
3541
- //@@ needs to come from headers ??
3542
- __privateAdd(this, _invokeMethods, {});
3543
- __privateAdd(this, _maxRetries, 5);
3544
- __privateAdd(this, _sleepDuration, [50, 100, 200, 500, 1e3, 2e3, 5e3]);
3545
- __privateAdd(this, _NoRetryStatusCodes, [
3546
- StatusCodes.NOT_FOUND,
3547
- StatusCodes.CONFLICT
3548
- ]);
3549
- __privateAdd(this, _accessToken, null);
3550
- __privateAdd(this, _noRetries, false);
3551
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3552
- __privateAdd(this, _LogDebugMessage, (message) => {
3553
- __privateGet(this, _options).logger.debug(message);
3554
- });
3555
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3556
- __privateAdd(this, _LogErrorMessage, (message) => {
3557
- __privateGet(this, _options).logger.error(message);
3558
- });
3559
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3560
- __publicField(this, "HandleError", (error) => {
3561
- __privateGet(this, _LogDebugMessage).call(this, chalk.red(`HandleError(): Error: [${error}]`));
3562
- let responseCode = 500;
3563
- if (axios.isAxiosError(error)) {
3564
- const axiosError = error;
3565
- if (axiosError.response) {
3566
- responseCode = axiosError.response.status;
3567
- __privateGet(this, _LogDebugMessage).call(this, chalk.red(`AXIOS Error Response.Status = [${axiosError.response.status}]`));
3568
- if (axiosError.response.headers) {
3569
- __privateGet(this, _LogErrorMessage).call(this, chalk.red(` headers: [${JSON.stringify(axiosError.response.headers)}]`));
3570
- }
3571
- if (axiosError.response.data) {
3572
- __privateGet(this, _LogErrorMessage).call(this, chalk.red(` data: [${JSON.stringify(axiosError.response.data)}]`));
3573
- }
3574
- try {
3575
- if (axiosError.response.config) {
3576
- __privateGet(this, _LogErrorMessage).call(this, chalk.red(` config: [${JSON.stringify(axiosError.response.config)}]`));
3577
- }
3578
- } catch (innererror) {
3579
- __privateGet(this, _LogErrorMessage).call(this, chalk.red(` could not get response config, error: [${innererror}]`));
3609
+ this.#options = options;
3610
+ }
3611
+ get options() {
3612
+ return this.#options;
3613
+ }
3614
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3615
+ #LogDebugMessage = (message) => {
3616
+ this.#options.logger.debug(message);
3617
+ };
3618
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3619
+ #LogErrorMessage = (message) => {
3620
+ this.#options.logger.error(message);
3621
+ };
3622
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3623
+ HandleError = (error) => {
3624
+ this.#LogDebugMessage(chalk.red(`HandleError(): Error: [${error}]`));
3625
+ let responseCode = 500;
3626
+ if (axios.isAxiosError(error)) {
3627
+ const axiosError = error;
3628
+ if (axiosError.response) {
3629
+ responseCode = axiosError.response.status;
3630
+ this.#LogDebugMessage(chalk.red(`AXIOS Error Response.Status = [${axiosError.response.status}]`));
3631
+ if (axiosError.response.headers) {
3632
+ this.#LogErrorMessage(chalk.red(` headers: [${JSON.stringify(axiosError.response.headers)}]`));
3633
+ }
3634
+ if (axiosError.response.data) {
3635
+ this.#LogErrorMessage(chalk.red(` data: [${JSON.stringify(axiosError.response.data)}]`));
3636
+ }
3637
+ try {
3638
+ if (axiosError.response.config) {
3639
+ this.#LogErrorMessage(chalk.red(` config: [${JSON.stringify(axiosError.response.config)}]`));
3580
3640
  }
3581
- } else {
3582
- __privateGet(this, _LogDebugMessage).call(this, chalk.red(`AXIOS Error = [${axiosError}]`));
3641
+ } catch (innererror) {
3642
+ this.#LogErrorMessage(chalk.red(` could not get response config, error: [${innererror}]`));
3583
3643
  }
3644
+ } else {
3645
+ this.#LogDebugMessage(chalk.red(`AXIOS Error = [${axiosError}]`));
3584
3646
  }
3585
- return responseCode;
3586
- });
3587
- __privateAdd(this, _TestMode, (metaData, errorCb) => {
3588
- const { id, url, httpVerb, filters, retries } = metaData;
3589
- if (retries < 1) {
3590
- errorCb(401, new Error(`Testing Error Only. Error Code: [401], Message ID: [${id}, url: [${url}], httpVerb: [${httpVerb}], filters: [${filters}], Retries: [${retries}]`));
3591
- return true;
3647
+ }
3648
+ return responseCode;
3649
+ };
3650
+ #TestMode = (metaData, errorCb) => {
3651
+ const { id, url, httpVerb, filters, retries } = metaData;
3652
+ if (retries < 1) {
3653
+ errorCb(401, new Error(`Testing Error Only. Error Code: [401], Message ID: [${id}, url: [${url}], httpVerb: [${httpVerb}], filters: [${filters}], Retries: [${retries}]`));
3654
+ return true;
3655
+ }
3656
+ if (retries < 2) {
3657
+ errorCb(500, new Error(`Testing Error Only. Error Code: [500], Message ID: [${id}, url: [${url}], httpVerb: [${httpVerb}], filters: [${filters}], Retries: [${retries}]`));
3658
+ return true;
3659
+ }
3660
+ return false;
3661
+ };
3662
+ #__InvokeResourceAPI = async (metaData, errorCb) => {
3663
+ try {
3664
+ const { url, httpVerb, resource, filters } = metaData;
3665
+ if (this.#options.testingMode) {
3666
+ if (this.#TestMode(metaData, errorCb)) {
3667
+ return null;
3668
+ }
3592
3669
  }
3593
- if (retries < 2) {
3594
- errorCb(500, new Error(`Testing Error Only. Error Code: [500], Message ID: [${id}, url: [${url}], httpVerb: [${httpVerb}], filters: [${filters}], Retries: [${retries}]`));
3595
- return true;
3670
+ let accessToken = null;
3671
+ if (this.#accessToken) {
3672
+ accessToken = this.#accessToken;
3673
+ this.#accessToken = null;
3674
+ } else {
3675
+ accessToken = await this.#options.GetAccessToken();
3596
3676
  }
3597
- return false;
3598
- });
3599
- __privateAdd(this, ___InvokeResourceAPI, async (metaData, errorCb) => {
3600
- try {
3601
- const { url, httpVerb, resource, filters } = metaData;
3602
- if (__privateGet(this, _options).testingMode) {
3603
- if (__privateGet(this, _TestMode).call(this, metaData, errorCb)) {
3604
- return null;
3605
- }
3606
- }
3607
- let accessToken = null;
3608
- if (__privateGet(this, _accessToken)) {
3609
- accessToken = __privateGet(this, _accessToken);
3610
- __privateSet(this, _accessToken, null);
3611
- } else {
3612
- accessToken = await __privateGet(this, _options).GetAccessToken();
3613
- }
3614
- let requestConfig = new stsutils.STSAxiosConfig(url, httpVerb).withAuthHeaders(accessToken, __privateGet(this, _DUMMY_USER));
3615
- if (!(httpVerb.localeCompare("get") === 0 || httpVerb.localeCompare("head") === 0)) {
3616
- requestConfig.withData(filters ? filters : resource ? resource : void 0);
3617
- }
3618
- if (isNode && __privateGet(this, _options).agentManager) {
3619
- requestConfig.withAgentManager(__privateGet(this, _options).agentManager);
3620
- }
3621
- return await axios(requestConfig.config);
3622
- } catch (error) {
3623
- const responseCode = this.HandleError(error);
3624
- errorCb(responseCode, error);
3625
- return null;
3677
+ let requestConfig = new stsutils.STSAxiosConfig(url, httpVerb).withAuthHeaders(accessToken, this.#DUMMY_USER);
3678
+ if (!(httpVerb.localeCompare("get") === 0 || httpVerb.localeCompare("head") === 0)) {
3679
+ requestConfig.withData(filters ? filters : resource ? resource : void 0);
3626
3680
  }
3627
- });
3628
- __publicField(this, "WithAccessToken", (accessToken) => {
3629
- __privateSet(this, _accessToken, accessToken);
3630
- return this;
3631
- });
3632
- __publicField(this, "WithNoRetries", () => {
3633
- __privateSet(this, _noRetries, true);
3634
- return this;
3635
- });
3636
- __publicField(this, "InvokeResourceAPI", async (url, httpVerb, resource, filters, searchParams, errorCb) => {
3637
- const id = v4();
3638
- __privateGet(this, _invokeMethods)[id] = {
3639
- id,
3640
- retries: 0,
3641
- testFailIndexBefore: 1,
3642
- url,
3643
- httpVerb,
3644
- resource,
3645
- filters,
3646
- searchParams,
3647
- errorCb
3648
- };
3649
- let returnError = null;
3650
- const InvokeAPI = async (id2) => {
3651
- const metadataRecord = __privateGet(this, _invokeMethods)[id2];
3652
- let performRetry = false;
3653
- const returnData = await __privateGet(this, ___InvokeResourceAPI).call(this, metadataRecord, (statusCode, error) => {
3654
- if (__privateGet(this, _noRetries) === false) {
3655
- const noRetryIndex = __privateGet(this, _NoRetryStatusCodes).indexOf(statusCode);
3656
- if (noRetryIndex === -1) {
3657
- if (statusCode === StatusCodes.UNAUTHORIZED) {
3658
- __privateGet(this, _options).ResetAccessToken();
3659
- if (__privateGet(this, _options).clientTelemetryEvents) {
3660
- __privateGet(this, _options).clientTelemetryEvents.AuthenticationErrorInc();
3661
- }
3662
- }
3663
- if (isNode && __privateGet(this, _options).agentManager) {
3664
- __privateGet(this, _options).agentManager.ResetAgent();
3681
+ if (isNode && this.#options.agentManager) {
3682
+ requestConfig.withAgentManager(this.#options.agentManager);
3683
+ }
3684
+ return await axios(requestConfig.config);
3685
+ } catch (error) {
3686
+ const responseCode = this.HandleError(error);
3687
+ errorCb(responseCode, error);
3688
+ return null;
3689
+ }
3690
+ };
3691
+ WithAccessToken = (accessToken) => {
3692
+ this.#accessToken = accessToken;
3693
+ return this;
3694
+ };
3695
+ WithNoRetries = () => {
3696
+ this.#noRetries = true;
3697
+ return this;
3698
+ };
3699
+ InvokeResourceAPI = async (url, httpVerb, resource, filters, searchParams, errorCb) => {
3700
+ const id = v4();
3701
+ this.#invokeMethods[id] = {
3702
+ id,
3703
+ retries: 0,
3704
+ testFailIndexBefore: 1,
3705
+ url,
3706
+ httpVerb,
3707
+ resource,
3708
+ filters,
3709
+ searchParams,
3710
+ errorCb
3711
+ };
3712
+ let returnError = null;
3713
+ const InvokeAPI = async (id2) => {
3714
+ const metadataRecord = this.#invokeMethods[id2];
3715
+ let performRetry = false;
3716
+ const returnData = await this.#__InvokeResourceAPI(metadataRecord, (statusCode, error) => {
3717
+ if (this.#noRetries === false) {
3718
+ const noRetryIndex = this.#NoRetryStatusCodes.indexOf(statusCode);
3719
+ if (noRetryIndex === -1) {
3720
+ if (statusCode === StatusCodes.UNAUTHORIZED) {
3721
+ this.#options.ResetAccessToken();
3722
+ if (this.#options.clientTelemetryEvents) {
3723
+ this.#options.clientTelemetryEvents.AuthenticationErrorInc();
3665
3724
  }
3666
- performRetry = true;
3667
- } else {
3668
- returnError = error;
3669
3725
  }
3726
+ if (isNode && this.#options.agentManager) {
3727
+ this.#options.agentManager.ResetAgent();
3728
+ }
3729
+ performRetry = true;
3670
3730
  } else {
3671
3731
  returnError = error;
3672
- __privateSet(this, _noRetries, false);
3673
3732
  }
3674
- });
3675
- return {
3676
- response: returnData,
3677
- retry: performRetry
3678
- };
3679
- };
3680
- let retVal = null;
3681
- while (__privateGet(this, _invokeMethods)[id].retries < __privateGet(this, _maxRetries)) {
3682
- retVal = await InvokeAPI(id);
3683
- if (retVal.retry === false) {
3684
- delete __privateGet(this, _invokeMethods)[id];
3685
- break;
3686
3733
  } else {
3687
- await stsutils.Sleep(__privateGet(this, _sleepDuration)[__privateGet(this, _invokeMethods)[id].retries]);
3688
- __privateGet(this, _invokeMethods)[id].retries++;
3689
- if (__privateGet(this, _options).clientTelemetryEvents) {
3690
- __privateGet(this, _options).clientTelemetryEvents.RetryInc();
3691
- }
3734
+ returnError = error;
3735
+ this.#noRetries = false;
3692
3736
  }
3693
- }
3694
- if (retVal) {
3695
- if (retVal.retry === true) {
3696
- errorCb(new Error(`#InvokeResourceAPI(): Max retries exceeded. Max Retries: [${__privateGet(this, _invokeMethods)[id].retries}]`));
3697
- delete __privateGet(this, _invokeMethods)[id];
3698
- return null;
3699
- } else {
3700
- if (returnError) {
3701
- errorCb(returnError);
3702
- }
3703
- return retVal.response;
3737
+ });
3738
+ return {
3739
+ response: returnData,
3740
+ retry: performRetry
3741
+ };
3742
+ };
3743
+ let retVal = null;
3744
+ while (this.#invokeMethods[id].retries < this.#maxRetries) {
3745
+ retVal = await InvokeAPI(id);
3746
+ if (retVal.retry === false) {
3747
+ delete this.#invokeMethods[id];
3748
+ break;
3749
+ } else {
3750
+ await stsutils.Sleep(this.#sleepDuration[this.#invokeMethods[id].retries]);
3751
+ this.#invokeMethods[id].retries++;
3752
+ if (this.#options.clientTelemetryEvents) {
3753
+ this.#options.clientTelemetryEvents.RetryInc();
3704
3754
  }
3755
+ }
3756
+ }
3757
+ if (retVal) {
3758
+ if (retVal.retry === true) {
3759
+ errorCb(new Error(`#InvokeResourceAPI(): Max retries exceeded. Max Retries: [${this.#invokeMethods[id].retries}]`));
3760
+ delete this.#invokeMethods[id];
3761
+ return null;
3705
3762
  } else {
3706
3763
  if (returnError) {
3707
3764
  errorCb(returnError);
3708
3765
  }
3709
- return null;
3766
+ return retVal.response;
3710
3767
  }
3711
- });
3712
- __privateSet(this, _options, options);
3713
- }
3714
- get options() {
3715
- return __privateGet(this, _options);
3716
- }
3768
+ } else {
3769
+ if (returnError) {
3770
+ errorCb(returnError);
3771
+ }
3772
+ return null;
3773
+ }
3774
+ };
3717
3775
  }
3718
- _options = new WeakMap();
3719
- _DUMMY_USER = new WeakMap();
3720
- _invokeMethods = new WeakMap();
3721
- _maxRetries = new WeakMap();
3722
- _sleepDuration = new WeakMap();
3723
- _NoRetryStatusCodes = new WeakMap();
3724
- _accessToken = new WeakMap();
3725
- _noRetries = new WeakMap();
3726
- _LogDebugMessage = new WeakMap();
3727
- _LogErrorMessage = new WeakMap();
3728
- _TestMode = new WeakMap();
3729
- ___InvokeResourceAPI = new WeakMap();
3730
3776
  class STSRest01Client {
3777
+ #axiosClient;
3778
+ #options;
3731
3779
  constructor(options) {
3732
- __privateAdd(this, _axiosClient);
3733
- __privateAdd(this, _options2);
3734
- __publicField(this, "HandleError", (error) => {
3735
- return __privateGet(this, _axiosClient).HandleError(error);
3736
- });
3737
- __publicField(this, "WithNoRetries", () => {
3738
- __privateGet(this, _axiosClient).WithNoRetries();
3739
- return this;
3740
- });
3741
- __publicField(this, "WithAccessToken", (accessToken) => {
3742
- __privateGet(this, _axiosClient).WithAccessToken(accessToken);
3743
- return this;
3744
- });
3745
- // --- [ Resource ] -------------------------------------------------------------------------------------------------------------------
3746
- // --- [ POST.Resource ] -------------------------------------------------------------------------------------------------------------------
3747
- __publicField(this, "PostResourceAR", async (resource, errorCb) => {
3748
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources`;
3749
- return await __privateGet(this, _axiosClient).InvokeResourceAPI(url, "post", resource, null, null, errorCb);
3750
- });
3751
- __publicField(this, "PostResourceDBR", async (resource, errorCb) => {
3752
- var _a;
3753
- return ((_a = await this.PostResourceAR(resource, errorCb)) == null ? void 0 : _a.data.detail) ?? null;
3754
- });
3755
- __publicField(this, "PostResource", async (resource, errorCb) => {
3756
- var _a;
3757
- return ((_a = await this.PostResourceDBR(resource, errorCb)) == null ? void 0 : _a.resdesc) ?? null;
3758
- });
3759
- // --- [ PUT.Resources ] ------------------------------------------------------------------------------------------------------------------
3760
- __publicField(this, "PutResourcesAR", async (resources, errorCb) => {
3761
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources`;
3762
- return await __privateGet(this, _axiosClient).InvokeResourceAPI(url, "put", resources, null, null, errorCb);
3763
- });
3764
- __publicField(this, "PutResourcesDBR", async (resources, errorCb) => {
3765
- var _a;
3766
- return ((_a = await this.PutResourcesAR(resources, errorCb)) == null ? void 0 : _a.data.map((r) => r.detail)) ?? null;
3767
- });
3768
- __publicField(this, "PutResources", async (resources, errorCb) => {
3769
- var _a;
3770
- return ((_a = await this.PutResourcesDBR(resources, errorCb)) == null ? void 0 : _a.map((r) => r.resdesc)) ?? null;
3771
- });
3772
- // --- [ PUT.Resource ] -------------------------------------------------------------------------------------------------------------------
3773
- __publicField(this, "PutResourceAR", async (resource, errorCb) => {
3774
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources/${resource.resname}`;
3775
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "put", resource, null, null, errorCb);
3776
- });
3777
- __publicField(this, "PutResourceDBR", async (resource, errorCb) => {
3778
- var _a;
3779
- return ((_a = await this.PutResourceAR(resource, errorCb)) == null ? void 0 : _a.data.detail) ?? null;
3780
- });
3781
- __publicField(this, "PutResource", async (resource, errorCb) => {
3782
- var _a;
3783
- return ((_a = await this.PutResourceDBR(resource, errorCb)) == null ? void 0 : _a.resdesc) ?? null;
3784
- });
3785
- // --- [ PATCH.Resources ] ------------------------------------------------------------------------------------------------------------------
3786
- __publicField(this, "PatchResourcesAR", async (resources, errorCb) => {
3787
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources`;
3788
- return await __privateGet(this, _axiosClient).InvokeResourceAPI(url, "patch", resources, null, null, errorCb);
3789
- });
3790
- __publicField(this, "PatchResourcesDBR", async (resources, errorCb) => {
3791
- var _a;
3792
- return ((_a = await this.PatchResourcesAR(resources, errorCb)) == null ? void 0 : _a.data.map((r) => r.detail)) ?? null;
3793
- });
3794
- __publicField(this, "PatchResources", async (resources, errorCb) => {
3795
- var _a;
3796
- return ((_a = await this.PatchResourcesDBR(resources, errorCb)) == null ? void 0 : _a.map((r) => r.resdesc)) ?? null;
3797
- });
3798
- // --- [ PATCH.Resource ] -------------------------------------------------------------------------------------------------------------------
3799
- __publicField(this, "PatchResourceAR", async (resource, errorCb) => {
3800
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources/${resource.resname}`;
3801
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "patch", resource, null, null, errorCb);
3802
- });
3803
- __publicField(this, "PatchResourceDBR", async (resource, errorCb) => {
3804
- var _a;
3805
- return ((_a = await this.PatchResourceAR(resource, errorCb)) == null ? void 0 : _a.data.detail) ?? null;
3806
- });
3807
- __publicField(this, "PatchResource", async (resource, errorCb) => {
3808
- var _a;
3809
- return ((_a = await this.PatchResourceDBR(resource, errorCb)) == null ? void 0 : _a.resdesc) ?? null;
3810
- });
3811
- // --- [ DELETE.Resources ] -------------------------------------------------------------------------------------------------------------------
3812
- __publicField(this, "DeleteResourcesAR", async (resources, errorCb) => {
3813
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources`;
3814
- return await __privateGet(this, _axiosClient).InvokeResourceAPI(url, "delete", resources, null, null, errorCb);
3815
- });
3816
- __publicField(this, "DeleteResourcesDBR", async (resources, errorCb) => {
3817
- var _a;
3818
- return ((_a = await this.DeleteResourcesAR(resources, errorCb)) == null ? void 0 : _a.data.map((r) => r.detail)) ?? null;
3819
- });
3820
- __publicField(this, "DeleteResources", async (resources, errorCb) => {
3821
- var _a;
3822
- return ((_a = await this.DeleteResourcesDBR(resources, errorCb)) == null ? void 0 : _a.map((r) => r.resdesc)) ?? null;
3823
- });
3824
- // --- [ DELETE.Resource ] -------------------------------------------------------------------------------------------------------------------
3825
- __publicField(this, "DeleteResourceAR", async (resource, errorCb) => {
3826
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources/${resource.resname}`;
3827
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "delete", resource, null, null, errorCb);
3828
- });
3829
- __publicField(this, "DeleteResourceDBR", async (resource, errorCb) => {
3830
- var _a;
3831
- return ((_a = await this.DeleteResourceAR(resource, errorCb)) == null ? void 0 : _a.data.detail) ?? null;
3832
- });
3833
- __publicField(this, "DeleteResource", async (resource, errorCb) => {
3834
- var _a;
3835
- return ((_a = await this.DeleteResourceDBR(resource, errorCb)) == null ? void 0 : _a.resdesc) ?? null;
3836
- });
3837
- // --- [ GET.Resource ] -------------------------------------------------------------------------------------------------------------------
3838
- __publicField(this, "GetResourceAR", async (resource, filters, errorCb) => {
3839
- let url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources/${resource.resname}`;
3840
- if (filters && filters.localeCompare("") !== 0) {
3841
- url = `${url}?${filters}`;
3842
- }
3843
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "get", null, null, null, errorCb);
3844
- });
3845
- __publicField(this, "GetResourceDBR", async (resource, filters, errorCb) => {
3846
- var _a;
3847
- return ((_a = await this.GetResourceAR(resource, filters, errorCb)) == null ? void 0 : _a.data.detail) ?? null;
3848
- });
3849
- __publicField(this, "GetResource", async (resource, filters, errorCb) => {
3850
- var _a;
3851
- return ((_a = await this.GetResourceDBR(resource, filters, errorCb)) == null ? void 0 : _a.resdesc) ?? null;
3852
- });
3853
- // --- [ GET.Resources ] -------------------------------------------------------------------------------------------------------------------
3854
- __publicField(this, "GetResourcesAR", async (filters, errorCb) => {
3855
- let url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources`;
3856
- if (filters && filters.localeCompare("") !== 0) {
3857
- url = `${url}?${filters}`;
3858
- }
3859
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "get", null, null, null, errorCb);
3860
- });
3861
- __publicField(this, "GetResourcesDBR", async (filters, errorCb) => {
3862
- var _a;
3863
- return ((_a = await this.GetResourcesAR(filters, errorCb)) == null ? void 0 : _a.data.detail) ?? null;
3864
- });
3865
- __publicField(this, "GetResources", async (filters, errorCb) => {
3866
- var _a;
3867
- return ((_a = await this.GetResourcesDBR(filters, errorCb)) == null ? void 0 : _a.map((r) => r.resdesc)) ?? null;
3868
- });
3869
- // --- [ Entity ] -------------------------------------------------------------------------------------------------------------------
3870
- __privateAdd(this, _checkResName, (resourceEntities) => {
3871
- let resName = "";
3872
- resourceEntities.forEach((re) => {
3873
- resName = resName.localeCompare("") === 0 ? re.resname : resName;
3874
- if (resName.localeCompare(re.resname) !== 0) {
3875
- throw new Error(`Invalid batch provided. resname not all equal. Previous checked value: [${resName}, current value: [${re.resname}]`);
3876
- } else {
3877
- resName = re.resname;
3878
- }
3879
- });
3880
- return resName;
3881
- });
3882
- // --- [ POST.Entitiy ] -------------------------------------------------------------------------------------------------------------------
3883
- __publicField(this, "PostEntityAR", async (resourceEntity, errorCb) => {
3884
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources/${resourceEntity.resname}/entities`;
3885
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "post", resourceEntity, null, null, errorCb);
3886
- });
3887
- __publicField(this, "PostEntityDBR", async (resourceEntity, errorCb) => {
3888
- var _a;
3889
- return ((_a = await this.PostEntityAR(resourceEntity, errorCb)) == null ? void 0 : _a.data.detail) ?? null;
3890
- });
3891
- __publicField(this, "PostEntity", async (resourceEntity, errorCb) => {
3892
- var _a;
3893
- return ((_a = await this.PostEntityDBR(resourceEntity, errorCb)) == null ? void 0 : _a.entvalue) ?? null;
3894
- });
3895
- // --- [ PUT.Entities ] -----------------------------------------------------------------------------------------------------------------
3896
- __publicField(this, "PutEntitiesAR", async (resourceEntities, errorCb) => {
3897
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources/${__privateGet(this, _checkResName).call(this, resourceEntities)}/entities`;
3898
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "put", resourceEntities, null, null, errorCb);
3899
- });
3900
- __publicField(this, "PutEntitiesDBR", async (resourceEntities, errorCb) => {
3901
- var _a;
3902
- return ((_a = await this.PutEntitiesAR(resourceEntities, errorCb)) == null ? void 0 : _a.data.map((r) => r.detail)) ?? null;
3903
- });
3904
- __publicField(this, "PutEntities", async (resourceEntities, errorCb) => {
3905
- var _a;
3906
- return ((_a = await this.PutEntitiesDBR(resourceEntities, errorCb)) == null ? void 0 : _a.map((r) => r.entvalue)) ?? null;
3907
- });
3908
- // --- [ PUT.Entity ] -------------------------------------------------------------------------------------------------------------------
3909
- __publicField(this, "PutEntityAR", async (entity, errorCb) => {
3910
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources/${entity.resname}/entities/${entity.entname}`;
3911
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "put", entity, null, null, errorCb);
3912
- });
3913
- __publicField(this, "PutEntityDBR", async (resourceEntity, errorCb) => {
3914
- var _a;
3915
- return ((_a = await this.PutEntityAR(resourceEntity, errorCb)) == null ? void 0 : _a.data.detail) ?? null;
3916
- });
3917
- __publicField(this, "PutEntity", async (resourceEntity, errorCb) => {
3918
- var _a;
3919
- return ((_a = await this.PutEntityDBR(resourceEntity, errorCb)) == null ? void 0 : _a.entvalue) ?? null;
3920
- });
3921
- // --- [ PATCH.Entities ] -----------------------------------------------------------------------------------------------------------------
3922
- __publicField(this, "PatchEntitiesAR", async (resourceEntities, errorCb) => {
3923
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources/${__privateGet(this, _checkResName).call(this, resourceEntities)}/entities`;
3924
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "patch", resourceEntities, null, null, errorCb);
3925
- });
3926
- __publicField(this, "PatchEntitiesDBR", async (resourceEntities, errorCb) => {
3927
- var _a;
3928
- return ((_a = await this.PatchEntitiesAR(resourceEntities, errorCb)) == null ? void 0 : _a.data.map((r) => r.detail)) ?? null;
3929
- });
3930
- __publicField(this, "PatchEntities", async (resourceEntities, errorCb) => {
3931
- var _a;
3932
- return ((_a = await this.PatchEntitiesDBR(resourceEntities, errorCb)) == null ? void 0 : _a.map((r) => r.entvalue)) ?? null;
3933
- });
3934
- // --- [ PATCH.Entity ] -------------------------------------------------------------------------------------------------------------------
3935
- __publicField(this, "PatchEntityAR", async (resourceEntity, errorCb) => {
3936
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources/${resourceEntity.resname}/entities/${resourceEntity.entname}`;
3937
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "patch", resourceEntity, null, null, errorCb);
3938
- });
3939
- __publicField(this, "PatchEntityDBR", async (resourceEntity, errorCb) => {
3940
- var _a;
3941
- return ((_a = await this.PatchEntityAR(resourceEntity, errorCb)) == null ? void 0 : _a.data.detail) ?? null;
3942
- });
3943
- __publicField(this, "PatchEntity", async (resourceEntity, errorCb) => {
3944
- var _a;
3945
- return ((_a = await this.PatchEntityDBR(resourceEntity, errorCb)) == null ? void 0 : _a.entvalue) ?? null;
3946
- });
3947
- // --- [ DELETE.Entity ] -------------------------------------------------------------------------------------------------------------------
3948
- __publicField(this, "DeleteEntitiesAR", async (resourceEntities, errorCb) => {
3949
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources/${__privateGet(this, _checkResName).call(this, resourceEntities)}/entities`;
3950
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "delete", resourceEntities, null, null, errorCb);
3951
- });
3952
- __publicField(this, "DeleteEntitiesDBR", async (resourceEntities, errorCb) => {
3953
- var _a;
3954
- return ((_a = await this.DeleteEntitiesAR(resourceEntities, errorCb)) == null ? void 0 : _a.data.map((r) => r.detail)) ?? null;
3955
- });
3956
- __publicField(this, "DeleteEntities", async (resourceEntities, errorCb) => {
3957
- var _a;
3958
- return ((_a = await this.DeleteEntitiesDBR(resourceEntities, errorCb)) == null ? void 0 : _a.map((r) => r.entvalue)) ?? null;
3959
- });
3960
- // --- [ DELETE.Entity ] -------------------------------------------------------------------------------------------------------------------
3961
- __publicField(this, "DeleteEntityAR", async (resourceEntity, errorCb) => {
3962
- const url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources/${resourceEntity.resname}/entities/${resourceEntity.entname}`;
3963
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "delete", resourceEntity, null, null, errorCb);
3964
- });
3965
- __publicField(this, "DeleteEntityDBR", async (resourceEntity, errorCb) => {
3966
- var _a;
3967
- return ((_a = await this.DeleteEntityAR(resourceEntity, errorCb)) == null ? void 0 : _a.data.detail) ?? null;
3968
- });
3969
- __publicField(this, "DeleteEntity", async (resourceEntity, errorCb) => {
3970
- var _a;
3971
- return ((_a = await this.DeleteEntityDBR(resourceEntity, errorCb)) == null ? void 0 : _a.entvalue) ?? null;
3972
- });
3973
- // --- [ GET.Entity ] -------------------------------------------------------------------------------------------------------------------
3974
- __publicField(this, "GetEntityAR", async (resourceEntity, filters, errorCb) => {
3975
- let url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources/${resourceEntity.resname}/entities/${resourceEntity.entname}`;
3976
- if (filters && filters.localeCompare("") !== 0) {
3977
- url = `${url}?${filters}`;
3978
- }
3979
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "get", null, null, null, errorCb);
3980
- });
3981
- __publicField(this, "GetEntityDBR", async (resourceEntity, filters, errorCb) => {
3982
- var _a;
3983
- return ((_a = await this.GetEntityAR(resourceEntity, filters, errorCb)) == null ? void 0 : _a.data.detail) ?? null;
3984
- });
3985
- __publicField(this, "GetEntity", async (resourceEntity, filters, errorCb) => {
3986
- var _a;
3987
- return ((_a = await this.GetEntityDBR(resourceEntity, filters, errorCb)) == null ? void 0 : _a.entvalue) ?? null;
3988
- });
3989
- // --- [ GET.Entities ] -------------------------------------------------------------------------------------------------------------------
3990
- __publicField(this, "GetEntitiesAR", async (resource, filters, errorCb) => {
3991
- let url = `${__privateGet(this, _options2).endpoint}${goptions.rest01apiroot}/resources/${resource.resname}/entities`;
3992
- if (filters && filters.localeCompare("") !== 0) {
3993
- url = `${url}?${filters}`;
3994
- }
3995
- return __privateGet(this, _axiosClient).InvokeResourceAPI(url, "get", null, null, null, errorCb);
3996
- });
3997
- __publicField(this, "GetEntitiesDBR", async (resource, filters, errorCb) => {
3998
- var _a;
3999
- return ((_a = await this.GetEntitiesAR(resource, filters, errorCb)) == null ? void 0 : _a.data.detail) ?? null;
4000
- });
4001
- __publicField(this, "GetEntities", async (resource, filters, errorCb) => {
4002
- var _a;
4003
- return ((_a = await this.GetEntitiesDBR(resource, filters, errorCb)) == null ? void 0 : _a.map((r) => r.entvalue)) ?? null;
4004
- });
4005
- __privateSet(this, _options2, options);
4006
- __privateSet(this, _axiosClient, new AxiosClient({
3780
+ this.#options = options;
3781
+ this.#axiosClient = new AxiosClient({
4007
3782
  logger: options.logger,
4008
3783
  testingMode: options.testingMode,
4009
3784
  GetAccessToken: options.GetAccessToken,
4010
3785
  ResetAccessToken: options.ResetAccessToken,
4011
3786
  agentManager: options.agentManager,
4012
3787
  clientTelemetryEvents: options.clientTelemetryEvents
4013
- }));
3788
+ });
4014
3789
  }
3790
+ HandleError = (error) => {
3791
+ return this.#axiosClient.HandleError(error);
3792
+ };
3793
+ WithNoRetries = () => {
3794
+ this.#axiosClient.WithNoRetries();
3795
+ return this;
3796
+ };
3797
+ WithAccessToken = (accessToken) => {
3798
+ this.#axiosClient.WithAccessToken(accessToken);
3799
+ return this;
3800
+ };
3801
+ // --- [ Resource ] -------------------------------------------------------------------------------------------------------------------
3802
+ // --- [ POST.Resource ] -------------------------------------------------------------------------------------------------------------------
3803
+ PostResourceAR = async (resource, errorCb) => {
3804
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources`;
3805
+ return await this.#axiosClient.InvokeResourceAPI(url, "post", resource, null, null, errorCb);
3806
+ };
3807
+ PostResourceDBR = async (resource, errorCb) => {
3808
+ return (await this.PostResourceAR(resource, errorCb))?.data.detail ?? null;
3809
+ };
3810
+ PostResource = async (resource, errorCb) => {
3811
+ return (await this.PostResourceDBR(resource, errorCb))?.resdesc ?? null;
3812
+ };
3813
+ // --- [ PUT.Resources ] ------------------------------------------------------------------------------------------------------------------
3814
+ PutResourcesAR = async (resources, errorCb) => {
3815
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources`;
3816
+ return await this.#axiosClient.InvokeResourceAPI(url, "put", resources, null, null, errorCb);
3817
+ };
3818
+ PutResourcesDBR = async (resources, errorCb) => {
3819
+ return (await this.PutResourcesAR(resources, errorCb))?.data.map((r) => r.detail) ?? null;
3820
+ };
3821
+ PutResources = async (resources, errorCb) => {
3822
+ return (await this.PutResourcesDBR(resources, errorCb))?.map((r) => r.resdesc) ?? null;
3823
+ };
3824
+ // --- [ PUT.Resource ] -------------------------------------------------------------------------------------------------------------------
3825
+ PutResourceAR = async (resource, errorCb) => {
3826
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources/${resource.resname}`;
3827
+ return this.#axiosClient.InvokeResourceAPI(url, "put", resource, null, null, errorCb);
3828
+ };
3829
+ PutResourceDBR = async (resource, errorCb) => {
3830
+ return (await this.PutResourceAR(resource, errorCb))?.data.detail ?? null;
3831
+ };
3832
+ PutResource = async (resource, errorCb) => {
3833
+ return (await this.PutResourceDBR(resource, errorCb))?.resdesc ?? null;
3834
+ };
3835
+ // --- [ PATCH.Resources ] ------------------------------------------------------------------------------------------------------------------
3836
+ PatchResourcesAR = async (resources, errorCb) => {
3837
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources`;
3838
+ return await this.#axiosClient.InvokeResourceAPI(url, "patch", resources, null, null, errorCb);
3839
+ };
3840
+ PatchResourcesDBR = async (resources, errorCb) => {
3841
+ return (await this.PatchResourcesAR(resources, errorCb))?.data.map((r) => r.detail) ?? null;
3842
+ };
3843
+ PatchResources = async (resources, errorCb) => {
3844
+ return (await this.PatchResourcesDBR(resources, errorCb))?.map((r) => r.resdesc) ?? null;
3845
+ };
3846
+ // --- [ PATCH.Resource ] -------------------------------------------------------------------------------------------------------------------
3847
+ PatchResourceAR = async (resource, errorCb) => {
3848
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources/${resource.resname}`;
3849
+ return this.#axiosClient.InvokeResourceAPI(url, "patch", resource, null, null, errorCb);
3850
+ };
3851
+ PatchResourceDBR = async (resource, errorCb) => {
3852
+ return (await this.PatchResourceAR(resource, errorCb))?.data.detail ?? null;
3853
+ };
3854
+ PatchResource = async (resource, errorCb) => {
3855
+ return (await this.PatchResourceDBR(resource, errorCb))?.resdesc ?? null;
3856
+ };
3857
+ // --- [ DELETE.Resources ] -------------------------------------------------------------------------------------------------------------------
3858
+ DeleteResourcesAR = async (resources, errorCb) => {
3859
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources`;
3860
+ return await this.#axiosClient.InvokeResourceAPI(url, "delete", resources, null, null, errorCb);
3861
+ };
3862
+ DeleteResourcesDBR = async (resources, errorCb) => {
3863
+ return (await this.DeleteResourcesAR(resources, errorCb))?.data.map((r) => r.detail) ?? null;
3864
+ };
3865
+ DeleteResources = async (resources, errorCb) => {
3866
+ return (await this.DeleteResourcesDBR(resources, errorCb))?.map((r) => r.resdesc) ?? null;
3867
+ };
3868
+ // --- [ DELETE.Resource ] -------------------------------------------------------------------------------------------------------------------
3869
+ DeleteResourceAR = async (resource, errorCb) => {
3870
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources/${resource.resname}`;
3871
+ return this.#axiosClient.InvokeResourceAPI(url, "delete", resource, null, null, errorCb);
3872
+ };
3873
+ DeleteResourceDBR = async (resource, errorCb) => {
3874
+ return (await this.DeleteResourceAR(resource, errorCb))?.data.detail ?? null;
3875
+ };
3876
+ DeleteResource = async (resource, errorCb) => {
3877
+ return (await this.DeleteResourceDBR(resource, errorCb))?.resdesc ?? null;
3878
+ };
3879
+ // --- [ GET.Resource ] -------------------------------------------------------------------------------------------------------------------
3880
+ GetResourceAR = async (resource, filters, errorCb) => {
3881
+ let url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources/${resource.resname}`;
3882
+ if (filters && filters.localeCompare("") !== 0) {
3883
+ url = `${url}?${filters}`;
3884
+ }
3885
+ return this.#axiosClient.InvokeResourceAPI(url, "get", null, null, null, errorCb);
3886
+ };
3887
+ GetResourceDBR = async (resource, filters, errorCb) => {
3888
+ return (await this.GetResourceAR(resource, filters, errorCb))?.data.detail ?? null;
3889
+ };
3890
+ GetResource = async (resource, filters, errorCb) => {
3891
+ return (await this.GetResourceDBR(resource, filters, errorCb))?.resdesc ?? null;
3892
+ };
3893
+ // --- [ GET.Resources ] -------------------------------------------------------------------------------------------------------------------
3894
+ GetResourcesAR = async (filters, errorCb) => {
3895
+ let url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources`;
3896
+ if (filters && filters.localeCompare("") !== 0) {
3897
+ url = `${url}?${filters}`;
3898
+ }
3899
+ return this.#axiosClient.InvokeResourceAPI(url, "get", null, null, null, errorCb);
3900
+ };
3901
+ GetResourcesDBR = async (filters, errorCb) => {
3902
+ return (await this.GetResourcesAR(filters, errorCb))?.data.detail ?? null;
3903
+ };
3904
+ GetResources = async (filters, errorCb) => {
3905
+ return (await this.GetResourcesDBR(filters, errorCb))?.map((r) => r.resdesc) ?? null;
3906
+ };
3907
+ // --- [ Entity ] -------------------------------------------------------------------------------------------------------------------
3908
+ #checkResName = (resourceEntities) => {
3909
+ let resName = "";
3910
+ resourceEntities.forEach((re) => {
3911
+ resName = resName.localeCompare("") === 0 ? re.resname : resName;
3912
+ if (resName.localeCompare(re.resname) !== 0) {
3913
+ throw new Error(`Invalid batch provided. resname not all equal. Previous checked value: [${resName}, current value: [${re.resname}]`);
3914
+ } else {
3915
+ resName = re.resname;
3916
+ }
3917
+ });
3918
+ return resName;
3919
+ };
3920
+ // --- [ POST.Entitiy ] -------------------------------------------------------------------------------------------------------------------
3921
+ PostEntityAR = async (resourceEntity, errorCb) => {
3922
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources/${resourceEntity.resname}/entities`;
3923
+ return this.#axiosClient.InvokeResourceAPI(url, "post", resourceEntity, null, null, errorCb);
3924
+ };
3925
+ PostEntityDBR = async (resourceEntity, errorCb) => {
3926
+ return (await this.PostEntityAR(resourceEntity, errorCb))?.data.detail ?? null;
3927
+ };
3928
+ PostEntity = async (resourceEntity, errorCb) => {
3929
+ return (await this.PostEntityDBR(resourceEntity, errorCb))?.entvalue ?? null;
3930
+ };
3931
+ // --- [ PUT.Entities ] -----------------------------------------------------------------------------------------------------------------
3932
+ PutEntitiesAR = async (resourceEntities, errorCb) => {
3933
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources/${this.#checkResName(resourceEntities)}/entities`;
3934
+ return this.#axiosClient.InvokeResourceAPI(url, "put", resourceEntities, null, null, errorCb);
3935
+ };
3936
+ PutEntitiesDBR = async (resourceEntities, errorCb) => {
3937
+ return (await this.PutEntitiesAR(resourceEntities, errorCb))?.data.map((r) => r.detail) ?? null;
3938
+ };
3939
+ PutEntities = async (resourceEntities, errorCb) => {
3940
+ return (await this.PutEntitiesDBR(resourceEntities, errorCb))?.map((r) => r.entvalue) ?? null;
3941
+ };
3942
+ // --- [ PUT.Entity ] -------------------------------------------------------------------------------------------------------------------
3943
+ PutEntityAR = async (entity, errorCb) => {
3944
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources/${entity.resname}/entities/${entity.entname}`;
3945
+ return this.#axiosClient.InvokeResourceAPI(url, "put", entity, null, null, errorCb);
3946
+ };
3947
+ PutEntityDBR = async (resourceEntity, errorCb) => {
3948
+ return (await this.PutEntityAR(resourceEntity, errorCb))?.data.detail ?? null;
3949
+ };
3950
+ PutEntity = async (resourceEntity, errorCb) => {
3951
+ return (await this.PutEntityDBR(resourceEntity, errorCb))?.entvalue ?? null;
3952
+ };
3953
+ // --- [ PATCH.Entities ] -----------------------------------------------------------------------------------------------------------------
3954
+ PatchEntitiesAR = async (resourceEntities, errorCb) => {
3955
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources/${this.#checkResName(resourceEntities)}/entities`;
3956
+ return this.#axiosClient.InvokeResourceAPI(url, "patch", resourceEntities, null, null, errorCb);
3957
+ };
3958
+ PatchEntitiesDBR = async (resourceEntities, errorCb) => {
3959
+ return (await this.PatchEntitiesAR(resourceEntities, errorCb))?.data.map((r) => r.detail) ?? null;
3960
+ };
3961
+ PatchEntities = async (resourceEntities, errorCb) => {
3962
+ return (await this.PatchEntitiesDBR(resourceEntities, errorCb))?.map((r) => r.entvalue) ?? null;
3963
+ };
3964
+ // --- [ PATCH.Entity ] -------------------------------------------------------------------------------------------------------------------
3965
+ PatchEntityAR = async (resourceEntity, errorCb) => {
3966
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources/${resourceEntity.resname}/entities/${resourceEntity.entname}`;
3967
+ return this.#axiosClient.InvokeResourceAPI(url, "patch", resourceEntity, null, null, errorCb);
3968
+ };
3969
+ PatchEntityDBR = async (resourceEntity, errorCb) => {
3970
+ return (await this.PatchEntityAR(resourceEntity, errorCb))?.data.detail ?? null;
3971
+ };
3972
+ PatchEntity = async (resourceEntity, errorCb) => {
3973
+ return (await this.PatchEntityDBR(resourceEntity, errorCb))?.entvalue ?? null;
3974
+ };
3975
+ // --- [ DELETE.Entity ] -------------------------------------------------------------------------------------------------------------------
3976
+ DeleteEntitiesAR = async (resourceEntities, errorCb) => {
3977
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources/${this.#checkResName(resourceEntities)}/entities`;
3978
+ return this.#axiosClient.InvokeResourceAPI(url, "delete", resourceEntities, null, null, errorCb);
3979
+ };
3980
+ DeleteEntitiesDBR = async (resourceEntities, errorCb) => {
3981
+ return (await this.DeleteEntitiesAR(resourceEntities, errorCb))?.data.map((r) => r.detail) ?? null;
3982
+ };
3983
+ DeleteEntities = async (resourceEntities, errorCb) => {
3984
+ return (await this.DeleteEntitiesDBR(resourceEntities, errorCb))?.map((r) => r.entvalue) ?? null;
3985
+ };
3986
+ // --- [ DELETE.Entity ] -------------------------------------------------------------------------------------------------------------------
3987
+ DeleteEntityAR = async (resourceEntity, errorCb) => {
3988
+ const url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources/${resourceEntity.resname}/entities/${resourceEntity.entname}`;
3989
+ return this.#axiosClient.InvokeResourceAPI(url, "delete", resourceEntity, null, null, errorCb);
3990
+ };
3991
+ DeleteEntityDBR = async (resourceEntity, errorCb) => {
3992
+ return (await this.DeleteEntityAR(resourceEntity, errorCb))?.data.detail ?? null;
3993
+ };
3994
+ DeleteEntity = async (resourceEntity, errorCb) => {
3995
+ return (await this.DeleteEntityDBR(resourceEntity, errorCb))?.entvalue ?? null;
3996
+ };
3997
+ // --- [ GET.Entity ] -------------------------------------------------------------------------------------------------------------------
3998
+ GetEntityAR = async (resourceEntity, filters, errorCb) => {
3999
+ let url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources/${resourceEntity.resname}/entities/${resourceEntity.entname}`;
4000
+ if (filters && filters.localeCompare("") !== 0) {
4001
+ url = `${url}?${filters}`;
4002
+ }
4003
+ return this.#axiosClient.InvokeResourceAPI(url, "get", null, null, null, errorCb);
4004
+ };
4005
+ GetEntityDBR = async (resourceEntity, filters, errorCb) => {
4006
+ return (await this.GetEntityAR(resourceEntity, filters, errorCb))?.data.detail ?? null;
4007
+ };
4008
+ GetEntity = async (resourceEntity, filters, errorCb) => {
4009
+ return (await this.GetEntityDBR(resourceEntity, filters, errorCb))?.entvalue ?? null;
4010
+ };
4011
+ // --- [ GET.Entities ] -------------------------------------------------------------------------------------------------------------------
4012
+ GetEntitiesAR = async (resource, filters, errorCb) => {
4013
+ let url = `${this.#options.endpoint}${goptions.rest01apiroot}/resources/${resource.resname}/entities`;
4014
+ if (filters && filters.localeCompare("") !== 0) {
4015
+ url = `${url}?${filters}`;
4016
+ }
4017
+ return this.#axiosClient.InvokeResourceAPI(url, "get", null, null, null, errorCb);
4018
+ };
4019
+ GetEntitiesDBR = async (resource, filters, errorCb) => {
4020
+ return (await this.GetEntitiesAR(resource, filters, errorCb))?.data.detail ?? null;
4021
+ };
4022
+ GetEntities = async (resource, filters, errorCb) => {
4023
+ return (await this.GetEntitiesDBR(resource, filters, errorCb))?.map((r) => r.entvalue) ?? null;
4024
+ };
4015
4025
  }
4016
- _axiosClient = new WeakMap();
4017
- _options2 = new WeakMap();
4018
- _checkResName = new WeakMap();
4019
4026
  exports2.AxiosClient = AxiosClient;
4020
4027
  exports2.STSRest01Client = STSRest01Client;
4021
4028
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
4022
- });
4029
+ }));
4023
4030
  //# sourceMappingURL=stsrest01client.umd.js.map