@nsshunt/stsrest01client 1.0.22 → 1.0.24

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