@monocloud/management-core 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,29 +1,42 @@
1
1
  <div align="center">
2
- <a href="https://www.monocloud.com?utm_source=github&utm_medium=monocloud_js" target="_blank" rel="noopener noreferrer">
2
+ <a href="https://www.monocloud.com?utm_source=github&utm_medium=management_js" target="_blank" rel="noopener noreferrer">
3
3
  <picture>
4
- <img src="https://raw.githubusercontent.com/monocloud/management-js/refs/heads/main/MonoCloud.png" height="100" alt="MonoCloud Logo">
4
+ <img src="https://raw.githubusercontent.com/monocloud/management-js/refs/heads/main/banner.svg" alt="MonoCloud Banner">
5
5
  </picture>
6
6
  </a>
7
- <p>Secure, simple auth for everything</p>
7
+ <div align="right">
8
+ <a href="https://www.npmjs.com/package/@monocloud/management" target="_blank">
9
+ <img src="https://img.shields.io/npm/v/@monocloud/management" alt="NPM" />
10
+ </a>
11
+ <a href="https://opensource.org/licenses/MIT" target="_blank">
12
+ <img src="https://img.shields.io/:license-MIT-blue.svg?style=flat" alt="License: MIT" />
13
+ </a>
14
+ <a href="https://github.com/monocloud/management-js/actions/workflows/build.yml" target="_blank">
15
+ <img src="https://github.com/monocloud/management-js/actions/workflows/build.yml/badge.svg" alt="Build Status" />
16
+ </a>
17
+ </div>
8
18
  </div>
9
19
 
10
- <br /><br />
11
-
12
20
  ## Introduction
13
21
 
14
- **MonoCloud Management SDK for JavaScript – programmatically manage apps, policies, configurations, and users via the MonoCloud Management APIs.**
22
+ **MonoCloud Management SDK for JavaScript – programmatically manage apps, policies, configurations, users, and groups via the MonoCloud Management APIs.**
15
23
 
16
- [MonoCloud](https://www.monocloud.com) is a modern, developer-friendly Identity & Access Management platform.
24
+ [MonoCloud](https://www.monocloud.com?utm_source=github&utm_medium=management_js) is a modern, developer-friendly Identity & Access Management platform.
17
25
 
18
26
  This SDK provides a full-featured, typed JavaScript client for interacting with the **MonoCloud Management APIs**, allowing you to automate tenant administration programmatically.
19
27
 
20
- ## ⚠️ Warning
21
-
22
- **This is a shared library** for [@monocloud/management-admin](https://www.npmjs.com/package/@monocloud/management-admin) and [@monocloud/management-identity](https://www.npmjs.com/package/@monocloud/management-identity).
28
+ > [!WARNING]
29
+ > This is a supporting library for [@monocloud/management](https://www.npmjs.com/package/@monocloud/management).
23
30
 
24
31
  ## 📘 Documentation
25
32
 
26
- - **Documentation:** https://www.monocloud.com/docs
33
+ - **Documentation:** [https://www.monocloud.com/docs](https://www.monocloud.com/docs?utm_source=github&utm_medium=management_js)
34
+ - **Management API SDK Docs:** [https://www.monocloud.com/docs/apis/management](https://www.monocloud.com/docs/apis/management?utm_source=github&utm_medium=management_js)
35
+ - **API Reference:** [https://monocloud.github.io/management-js](https://monocloud.github.io/management-js?utm_source=github&utm_medium=management_js)
36
+
37
+ ## Supported Platforms
38
+
39
+ - **Node.js >= 11.0.0**
27
40
 
28
41
  ## 🤝 Contributing & Support
29
42
 
@@ -34,7 +47,7 @@ This SDK provides a full-featured, typed JavaScript client for interacting with
34
47
 
35
48
  ### Security
36
49
 
37
- Do **not** report security issues publicly. Please follow the contact instructions at: https://www.monocloud.com/contact
50
+ Do **not** report security issues publicly. Please follow the contact instructions at: [https://www.monocloud.com/contact](https://www.monocloud.com/contact?utm_source=github&utm_medium=management_js)
38
51
 
39
52
  ## 📄 License
40
53
 
package/dist/index.cjs CHANGED
@@ -1,5 +1,11 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
2
 
2
3
  //#region src/exceptions/monocloud-exception.ts
4
+ /**
5
+ * The MonoCloud Exception
6
+ * @export
7
+ * @class MonoCloudException
8
+ */
3
9
  var MonoCloudException = class extends Error {};
4
10
 
5
11
  //#endregion
@@ -24,6 +30,11 @@ var MonoCloudRequestException = class extends MonoCloudException {
24
30
 
25
31
  //#endregion
26
32
  //#region src/exceptions/monocloud-bad-request-exception.ts
33
+ /**
34
+ * The MonoCloud Bad Request Exception
35
+ * @export
36
+ * @class MonoCloudBadRequestException
37
+ */
27
38
  var MonoCloudBadRequestException = class extends MonoCloudRequestException {
28
39
  constructor(arg) {
29
40
  if (typeof arg === "string") super(arg);
@@ -33,6 +44,11 @@ var MonoCloudBadRequestException = class extends MonoCloudRequestException {
33
44
 
34
45
  //#endregion
35
46
  //#region src/exceptions/monocloud-conflict-exception.ts
47
+ /**
48
+ * The MonoCloud Conflict Exception
49
+ * @export
50
+ * @class MonoCloudConflictException
51
+ */
36
52
  var MonoCloudConflictException = class extends MonoCloudRequestException {
37
53
  constructor(arg) {
38
54
  if (typeof arg === "string") super(arg);
@@ -41,8 +57,17 @@ var MonoCloudConflictException = class extends MonoCloudRequestException {
41
57
  };
42
58
 
43
59
  //#endregion
44
- //#region src/exceptions/monocloud-error-code-validation-exception.ts
45
- var MonoCloudErrorCodeValidationException = class extends MonoCloudRequestException {
60
+ //#region src/exceptions/monocloud-identity-validation-exception.ts
61
+ /**
62
+ * The MonoCloud Identity Validation Exception
63
+ * @export
64
+ * @class MonoCloudIdentityValidationException
65
+ */
66
+ var MonoCloudIdentityValidationException = class extends MonoCloudRequestException {
67
+ /**
68
+ * Initializes the MonoCloudIdentityValidationException Class
69
+ * @param response - The problem details returned from the server.
70
+ */
46
71
  constructor(response) {
47
72
  super(response, `${response.title} : ${JSON.stringify(response.errors, void 0, 2)}`);
48
73
  this.errors = response.errors;
@@ -51,6 +76,11 @@ var MonoCloudErrorCodeValidationException = class extends MonoCloudRequestExcept
51
76
 
52
77
  //#endregion
53
78
  //#region src/exceptions/monocloud-forbidden-exception.ts
79
+ /**
80
+ * The MonoCloud Forbidden Exception
81
+ * @export
82
+ * @class MonoCloudForbiddenException
83
+ */
54
84
  var MonoCloudForbiddenException = class extends MonoCloudRequestException {
55
85
  constructor(arg) {
56
86
  if (typeof arg === "string") super(arg);
@@ -60,7 +90,16 @@ var MonoCloudForbiddenException = class extends MonoCloudRequestException {
60
90
 
61
91
  //#endregion
62
92
  //#region src/exceptions/monocloud-key-validation-exception.ts
93
+ /**
94
+ * The MonoCloud Key Validation Exception
95
+ * @export
96
+ * @class MonoCloudKeyValidationException
97
+ */
63
98
  var MonoCloudKeyValidationException = class extends MonoCloudRequestException {
99
+ /**
100
+ * Initializes the MonoCloudKeyValidationException Class
101
+ * @param response - The problem details returned from the server.
102
+ */
64
103
  constructor(response) {
65
104
  super(response, `${response.title} : ${JSON.stringify(response.errors, void 0, 2)}`);
66
105
  this.errors = response.errors;
@@ -69,6 +108,11 @@ var MonoCloudKeyValidationException = class extends MonoCloudRequestException {
69
108
 
70
109
  //#endregion
71
110
  //#region src/exceptions/monocloud-model-state-exception.ts
111
+ /**
112
+ * The MonoCloud Model State Exception
113
+ * @export
114
+ * @class MonoCloudModelStateException
115
+ */
72
116
  var MonoCloudModelStateException = class extends MonoCloudRequestException {
73
117
  constructor(arg) {
74
118
  if (typeof arg === "string") super(arg);
@@ -78,6 +122,11 @@ var MonoCloudModelStateException = class extends MonoCloudRequestException {
78
122
 
79
123
  //#endregion
80
124
  //#region src/exceptions/monocloud-not-found-exception.ts
125
+ /**
126
+ * The MonoCloud Not Found Exception
127
+ * @export
128
+ * @class MonoCloudNotFoundException
129
+ */
81
130
  var MonoCloudNotFoundException = class extends MonoCloudRequestException {
82
131
  constructor(arg) {
83
132
  if (typeof arg === "string") super(arg);
@@ -87,6 +136,11 @@ var MonoCloudNotFoundException = class extends MonoCloudRequestException {
87
136
 
88
137
  //#endregion
89
138
  //#region src/exceptions/monocloud-resource-exhausted-exception.ts
139
+ /**
140
+ * The MonoCloud Resource Exhausted Exception
141
+ * @export
142
+ * @class MonoCloudResourceExhaustedException
143
+ */
90
144
  var MonoCloudResourceExhaustedException = class extends MonoCloudRequestException {
91
145
  constructor(arg) {
92
146
  if (typeof arg === "string") super(arg);
@@ -96,6 +150,11 @@ var MonoCloudResourceExhaustedException = class extends MonoCloudRequestExceptio
96
150
 
97
151
  //#endregion
98
152
  //#region src/exceptions/monocloud-server-exception.ts
153
+ /**
154
+ * The MonoCloud Server Exception
155
+ * @export
156
+ * @class MonoCloudServerException
157
+ */
99
158
  var MonoCloudServerException = class extends MonoCloudRequestException {
100
159
  constructor(arg) {
101
160
  if (typeof arg === "string") super(arg);
@@ -105,6 +164,11 @@ var MonoCloudServerException = class extends MonoCloudRequestException {
105
164
 
106
165
  //#endregion
107
166
  //#region src/exceptions/monocloud-unauthorized-exception.ts
167
+ /**
168
+ * The MonoCloud Unauthorized Exception
169
+ * @export
170
+ * @class MonoCloudUnauthorizedException
171
+ */
108
172
  var MonoCloudUnauthorizedException = class extends MonoCloudRequestException {
109
173
  constructor(arg) {
110
174
  if (typeof arg === "string") super(arg);
@@ -113,17 +177,40 @@ var MonoCloudUnauthorizedException = class extends MonoCloudRequestException {
113
177
  };
114
178
 
115
179
  //#endregion
116
- //#region src/models/error-code-validation-error.ts
117
- var ErrorCodeValidationError = class {
118
- constructor(code, description, field) {
180
+ //#region src/exceptions/monocloud-payment-required-exception.ts
181
+ /**
182
+ * The MonoCloud Payment Required Exception
183
+ * @export
184
+ * @class MonoCloudPaymentRequiredException
185
+ */
186
+ var MonoCloudPaymentRequiredException = class extends MonoCloudRequestException {
187
+ constructor(arg) {
188
+ if (typeof arg === "string") super(arg);
189
+ else super(arg);
190
+ }
191
+ };
192
+
193
+ //#endregion
194
+ //#region src/models/identity-error.ts
195
+ /**
196
+ * Identity Error: Represents a validation or processing error returned by the identity system.
197
+ * @export
198
+ * @class IdentityError
199
+ */
200
+ var IdentityError = class {
201
+ constructor(code, description) {
119
202
  this.code = code;
120
203
  this.description = description;
121
- this.field = field;
122
204
  }
123
205
  };
124
206
 
125
207
  //#endregion
126
208
  //#region src/models/problem-details.ts
209
+ /**
210
+ * The Problem Details
211
+ * @export
212
+ * @class ProblemDetails
213
+ */
127
214
  var ProblemDetails = class {
128
215
  constructor(response) {
129
216
  this.type = response.type;
@@ -138,16 +225,21 @@ var ProblemDetails = class {
138
225
  };
139
226
 
140
227
  //#endregion
141
- //#region src/models/error-code-validation-problem-details.ts
142
- var ErrorCodeValidationProblemDetails = class extends ProblemDetails {
228
+ //#region src/models/identity-validation-problem-details.ts
229
+ var IdentityValidationProblemDetails = class extends ProblemDetails {
143
230
  constructor(response) {
144
231
  super(response);
145
- this.errors = response.errors.map((err) => new ErrorCodeValidationError(err.code, err.description, err.field));
232
+ this.errors = response.errors.map((err) => new IdentityError(err.code, err.description));
146
233
  }
147
234
  };
148
235
 
149
236
  //#endregion
150
237
  //#region src/models/key-validation-problem-details.ts
238
+ /**
239
+ * The Key Validation Problem Details
240
+ * @export
241
+ * @class KeyValidationProblemDetails
242
+ */
151
243
  var KeyValidationProblemDetails = class extends ProblemDetails {
152
244
  constructor(response) {
153
245
  super(response);
@@ -183,16 +275,26 @@ const ValidationExceptionTypes = {
183
275
 
184
276
  //#endregion
185
277
  //#region src/exceptions/monocloud-exception-handler.ts
278
+ /**
279
+ * The MonoCloud Exception Handler
280
+ * @export
281
+ * @class MonoCloudExceptionHandler
282
+ */
186
283
  var MonoCloudExceptionHandler = class {
284
+ /**
285
+ * Converts the Problem Details returned from the server into an exception
286
+ * @param problemDetails - The problem details returned from the server.
287
+ */
187
288
  static ThrowProblemErr(problemDetails) {
188
289
  switch (problemDetails.status) {
189
290
  case 400: throw new MonoCloudBadRequestException(problemDetails);
190
291
  case 401: throw new MonoCloudUnauthorizedException(problemDetails);
292
+ case 402: throw new MonoCloudPaymentRequiredException(problemDetails);
191
293
  case 403: throw new MonoCloudUnauthorizedException(problemDetails);
192
294
  case 404: throw new MonoCloudNotFoundException(problemDetails);
193
295
  case 409: throw new MonoCloudConflictException(problemDetails);
194
296
  case 422:
195
- if (problemDetails instanceof ErrorCodeValidationProblemDetails) throw new MonoCloudErrorCodeValidationException(problemDetails);
297
+ if (problemDetails instanceof IdentityValidationProblemDetails) throw new MonoCloudIdentityValidationException(problemDetails);
196
298
  if (problemDetails instanceof KeyValidationProblemDetails) throw new MonoCloudKeyValidationException(problemDetails);
197
299
  throw new MonoCloudModelStateException(problemDetails);
198
300
  case 429: throw new MonoCloudResourceExhaustedException(problemDetails);
@@ -202,10 +304,16 @@ var MonoCloudExceptionHandler = class {
202
304
  throw new MonoCloudException((_problemDetails$title = problemDetails.title) !== null && _problemDetails$title !== void 0 ? _problemDetails$title : "An Unknown Error Occured");
203
305
  }
204
306
  }
307
+ /**
308
+ * Converts the error returned from the server into an exception
309
+ * @param statusCode - The response status code.
310
+ * @param message - The error message returned from the server.
311
+ */
205
312
  static ThrowErr(statusCode, message) {
206
313
  switch (statusCode) {
207
314
  case 400: throw new MonoCloudBadRequestException(message !== null && message !== void 0 ? message : "Bad Request");
208
315
  case 401: throw new MonoCloudUnauthorizedException(message !== null && message !== void 0 ? message : "Unauthorized");
316
+ case 402: throw new MonoCloudPaymentRequiredException(message !== null && message !== void 0 ? message : "Payment Required");
209
317
  case 403: throw new MonoCloudUnauthorizedException(message !== null && message !== void 0 ? message : "Forbidden");
210
318
  case 404: throw new MonoCloudNotFoundException(message !== null && message !== void 0 ? message : "Not Found");
211
319
  case 409: throw new MonoCloudConflictException(message !== null && message !== void 0 ? message : "Conflict");
@@ -289,7 +397,7 @@ var MonoCloudClientBase = class {
289
397
  if (contentType === null || contentType === void 0 ? void 0 : contentType.startsWith("application/problem+json")) {
290
398
  const body = await response.json();
291
399
  let result = body ? new ProblemDetails(body) : void 0;
292
- if ((result === null || result === void 0 ? void 0 : result.type) === ValidationExceptionTypes.IdentityValidationError) result = new ErrorCodeValidationProblemDetails(result);
400
+ if ((result === null || result === void 0 ? void 0 : result.type) === ValidationExceptionTypes.IdentityValidationError) result = new IdentityValidationProblemDetails(result);
293
401
  if ((result === null || result === void 0 ? void 0 : result.type) === ValidationExceptionTypes.ValidationError) result = new KeyValidationProblemDetails(result);
294
402
  if (!result) throw new MonoCloudException("Invalid body");
295
403
  MonoCloudExceptionHandler.ThrowProblemErr(result);
@@ -329,18 +437,19 @@ var MonoCloudClientBase = class {
329
437
  };
330
438
 
331
439
  //#endregion
332
- exports.ErrorCodeValidationProblemDetails = ErrorCodeValidationProblemDetails;
440
+ exports.IdentityValidationProblemDetails = IdentityValidationProblemDetails;
333
441
  exports.KeyValidationProblemDetails = KeyValidationProblemDetails;
334
442
  exports.MonoCloudBadRequestException = MonoCloudBadRequestException;
335
443
  exports.MonoCloudClientBase = MonoCloudClientBase;
336
444
  exports.MonoCloudConflictException = MonoCloudConflictException;
337
- exports.MonoCloudErrorCodeValidationException = MonoCloudErrorCodeValidationException;
338
445
  exports.MonoCloudException = MonoCloudException;
339
446
  exports.MonoCloudForbiddenException = MonoCloudForbiddenException;
447
+ exports.MonoCloudIdentityValidationException = MonoCloudIdentityValidationException;
340
448
  exports.MonoCloudKeyValidationException = MonoCloudKeyValidationException;
341
449
  exports.MonoCloudModelStateException = MonoCloudModelStateException;
342
450
  exports.MonoCloudNotFoundException = MonoCloudNotFoundException;
343
451
  exports.MonoCloudPageResponse = MonoCloudPageResponse;
452
+ exports.MonoCloudPaymentRequiredException = MonoCloudPaymentRequiredException;
344
453
  exports.MonoCloudRequestException = MonoCloudRequestException;
345
454
  exports.MonoCloudResourceExhaustedException = MonoCloudResourceExhaustedException;
346
455
  exports.MonoCloudResponse = MonoCloudResponse;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["problemDetails: ProblemDetails | undefined","errorMessage: string | undefined","headers: Record<string, string>","headers: Record<string, any>","e: any"],"sources":["../src/exceptions/monocloud-exception.ts","../src/exceptions/monocloud-request-exception.ts","../src/exceptions/monocloud-bad-request-exception.ts","../src/exceptions/monocloud-conflict-exception.ts","../src/exceptions/monocloud-error-code-validation-exception.ts","../src/exceptions/monocloud-forbidden-exception.ts","../src/exceptions/monocloud-key-validation-exception.ts","../src/exceptions/monocloud-model-state-exception.ts","../src/exceptions/monocloud-not-found-exception.ts","../src/exceptions/monocloud-resource-exhausted-exception.ts","../src/exceptions/monocloud-server-exception.ts","../src/exceptions/monocloud-unauthorized-exception.ts","../src/models/error-code-validation-error.ts","../src/models/problem-details.ts","../src/models/error-code-validation-problem-details.ts","../src/models/key-validation-problem-details.ts","../src/models/monocloud-response.ts","../src/models/monocloud-page-response.ts","../src/exceptions/validation-exception-types.ts","../src/exceptions/monocloud-exception-handler.ts","../src/base/monocloud-client-base.ts"],"sourcesContent":["/// <summary>\n/// The MonoCloud Exception\n/// </summary>\nexport class MonoCloudException extends Error {}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudException } from './monocloud-exception';\n\nexport class MonoCloudRequestException extends MonoCloudException {\n /// <summary>\n /// The problem details received from the server.\n /// </summary>\n response?: ProblemDetails;\n\n /// <summary>\n /// Initializes the MonoCloudRequestException Class\n /// </summary>\n /// <param name=\"response\">The problem details returned from the server.</param>\n constructor(response: ProblemDetails);\n\n /// <summary>\n /// Initializes the MonoCloudRequestException Class\n /// </summary>\n /// <param name=\"message\">The error message.</param>\n constructor(message: string);\n\n /// <summary>\n /// Initializes the MonoCloudRequestException Class\n /// </summary>\n /// <param name=\"response\">The problem details returned from the server.</param>\n /// <param name=\"message\">The error message.</param>\n constructor(response: ProblemDetails, message: string);\n\n constructor(...args: [ProblemDetails, string] | [ProblemDetails] | [string]) {\n let problemDetails: ProblemDetails | undefined;\n let errorMessage: string | undefined;\n\n if (Array.isArray(args)) {\n if (args.length === 2) {\n problemDetails = args[0];\n errorMessage = args[1];\n } else if (args.length === 1 && typeof args[0] === 'string') {\n errorMessage = args[0];\n } else if (args.length === 1 && typeof args[0] === 'object') {\n problemDetails = args[0];\n errorMessage = args[0].title;\n } else {\n throw new Error('Invalid arguments in constructor');\n }\n }\n\n if (!errorMessage) {\n throw new Error('Invalid error message');\n }\n\n super(errorMessage);\n this.response = problemDetails;\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/// <summary>\n/// The MonoCloud Bad Request Exception\n/// </summary>\nexport class MonoCloudBadRequestException extends MonoCloudRequestException {\n /// <summary>\n /// Initializes the MonoCloudBadRequestException Class\n /// </summary>\n /// <param name=\"response\">The problem details returned from the server.</param>\n constructor(response: ProblemDetails);\n\n /// <summary>\n /// Initializes the MonoCloudBadRequestException Class\n /// </summary>\n /// <param name=\"message\">The error message.</param>\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/// <summary>\n/// The MonoCloud Conflict Exception\n/// </summary>\nexport class MonoCloudConflictException extends MonoCloudRequestException {\n /// <summary>\n /// Initializes the MonoCloudConflictException Class\n /// </summary>\n /// <param name=\"response\">The problem details returned from the server.</param>\n constructor(response: ProblemDetails);\n\n /// <summary>\n /// Initializes the MonoCloudConflictException Class\n /// </summary>\n /// <param name=\"message\">The error message.</param>\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { ErrorCodeValidationError } from '../models/error-code-validation-error';\nimport { ErrorCodeValidationProblemDetails } from '../models/error-code-validation-problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/// <summary>\n/// The MonoCloud Error Code Validation Exception\n/// </summary>\nexport class MonoCloudErrorCodeValidationException extends MonoCloudRequestException {\n errors: ErrorCodeValidationError[];\n\n /// <summary>\n /// Initializes the MonoCloudErrorCodeValidationException Class\n /// </summary>\n /// <param name=\"response\">The problem details returned from the server.</param>\n constructor(response: ErrorCodeValidationProblemDetails) {\n super(\n response,\n `${response.title} : ${JSON.stringify(response.errors, undefined, 2)}`\n );\n this.errors = response.errors;\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/// <summary>\n/// The MonoCloud Forbidden Exception\n/// </summary>\nexport class MonoCloudForbiddenException extends MonoCloudRequestException {\n /// <summary>\n /// Initializes the MonoCloudForbiddenException Class\n /// </summary>\n /// <param name=\"response\">The problem details returned from the server.</param>\n constructor(response: ProblemDetails);\n\n /// <summary>\n /// Initializes the MonoCloudForbiddenException Class\n /// </summary>\n /// <param name=\"message\">The error message.</param>\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { KeyValidationProblemDetails } from '../models/key-validation-problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/// <summary>\n/// The MonoCloud Key Validation Exception Exception\n/// </summary>\nexport class MonoCloudKeyValidationException extends MonoCloudRequestException {\n errors: Record<string, string[]>;\n\n /// <summary>\n /// Initializes the MonoCloudKeyValidationException Class\n /// </summary>\n /// <param name=\"response\">The problem details returned from the server.</param>\n constructor(response: KeyValidationProblemDetails) {\n super(\n response,\n `${response.title} : ${JSON.stringify(response.errors, undefined, 2)}`\n );\n this.errors = response.errors;\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/// <summary>\n/// The MonoCloud Model State Exception\n/// </summary>\nexport class MonoCloudModelStateException extends MonoCloudRequestException {\n /// <summary>\n /// Initializes the MonoCloudModelStateException Class\n /// </summary>\n /// <param name=\"response\">The problem details returned from the server.</param>\n constructor(response: ProblemDetails);\n\n /// <summary>\n /// Initializes the MonoCloudModelStateException Class\n /// </summary>\n /// <param name=\"message\">The error message.</param>\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/// <summary>\n/// The MonoCloud Not Found Exception\n/// </summary>\nexport class MonoCloudNotFoundException extends MonoCloudRequestException {\n /// <summary>\n /// Initializes the MonoCloudNotFoundException Class\n /// </summary>\n /// <param name=\"response\">The problem details returned from the server.</param>\n constructor(response: ProblemDetails);\n\n /// <summary>\n /// Initializes the MonoCloudNotFoundException Class\n /// </summary>\n /// <param name=\"message\">The error message.</param>\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/// <summary>\n/// The MonoCloud Resource Exhausted Exception\n/// </summary>\nexport class MonoCloudResourceExhaustedException extends MonoCloudRequestException {\n /// <summary>\n /// Initializes the MonoCloudResourceExhaustedException Class\n /// </summary>\n /// <param name=\"response\">The problem details returned from the server.</param>\n constructor(response: ProblemDetails);\n\n /// <summary>\n /// Initializes the MonoCloudResourceExhaustedException Class\n /// </summary>\n /// <param name=\"message\">The error message.</param>\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/// <summary>\n/// The MonoCloud Server Exception\n/// </summary>\nexport class MonoCloudServerException extends MonoCloudRequestException {\n /// <summary>\n /// Initializes the MonoCloudServerException Class\n /// </summary>\n /// <param name=\"response\">The problem details returned from the server.</param>\n constructor(response: ProblemDetails);\n\n /// <summary>\n /// Initializes the MonoCloudServerException Class\n /// </summary>\n /// <param name=\"message\">The error message.</param>\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/// <summary>\n/// The MonoCloud Unauthorized Exception\n/// </summary>\nexport class MonoCloudUnauthorizedException extends MonoCloudRequestException {\n /// <summary>\n /// Initializes the MonoCloudUnauthorizedException Class\n /// </summary>\n /// <param name=\"response\">The problem details returned from the server.</param>\n constructor(response: ProblemDetails);\n\n /// <summary>\n /// Initializes the MonoCloudUnauthorizedException Class\n /// </summary>\n /// <param name=\"message\">The error message.</param>\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","export class ErrorCodeValidationError {\n /// <summary>\n /// The error code.\n /// </summary>\n code: string;\n\n /// <summary>\n /// Brief explanation of the error.\n /// </summary>\n description: string;\n\n /// <summary>\n /// The field the error belongs to.\n /// </summary>\n field?: string;\n\n constructor(code: string, description: string, field?: string) {\n this.code = code;\n this.description = description;\n this.field = field;\n }\n}\n","export class ProblemDetails {\n /// <summary>\n /// The type of error\n /// </summary>\n type: string;\n\n /// <summary>\n /// The title of the error\n /// </summary>\n title: string;\n\n /// <summary>\n /// The status code representing the error\n /// </summary>\n status: number;\n\n /// <summary>\n /// The error details\n /// </summary>\n detail: string;\n\n /// <summary>\n /// The instance\n /// </summary>\n instance: string;\n\n /// <summary>\n /// Additional data about the error\n /// </summary>\n\n [key: string]: any;\n\n constructor(response: ProblemDetails) {\n this.type = response.type;\n this.title = response.title;\n this.status = response.status;\n this.detail = response.detail;\n this.instance = response.instance;\n Object.keys(response)\n .filter(\n x => x !== 'type' && x !== 'title' && x !== 'status' && x !== 'instance'\n )\n .forEach(key => {\n this[key] = response[key];\n });\n }\n}\n","import { ErrorCodeValidationError } from './error-code-validation-error';\nimport { ProblemDetails } from './problem-details';\n\nexport class ErrorCodeValidationProblemDetails extends ProblemDetails {\n errors: ErrorCodeValidationError[];\n\n constructor(response: ProblemDetails) {\n super(response);\n this.errors = (response.errors as ErrorCodeValidationError[]).map(\n err => new ErrorCodeValidationError(err.code, err.description, err.field)\n );\n }\n}\n","import { ProblemDetails } from './problem-details';\n\nexport class KeyValidationProblemDetails extends ProblemDetails {\n /// <summary>\n /// A collection of errors\n /// </summary>\n errors: Record<string, string[]>;\n\n constructor(response: ProblemDetails) {\n super(response);\n this.errors = response.errors;\n }\n}\n","export class MonoCloudResponse<TResult = unknown> {\n status: number;\n\n headers: Record<string, any>;\n\n result: TResult;\n\n constructor(status: number, headers: Record<string, any>, result: TResult) {\n this.status = status;\n this.headers = headers;\n this.result = result;\n }\n}\n","import { MonoCloudResponse } from './monocloud-response';\nimport { PageModel } from './page-model';\n\nexport class MonoCloudPageResponse<\n TResult = unknown,\n> extends MonoCloudResponse<TResult> {\n pageData: PageModel;\n\n constructor(\n status: number,\n headers: Record<string, any>,\n result: TResult,\n pageData: PageModel\n ) {\n super(status, headers, result);\n this.pageData = pageData;\n }\n}\n","export const ValidationExceptionTypes = {\n ValidationError: 'https://httpstatuses.io/422#validation-error',\n IdentityValidationError:\n 'https://httpstatuses.io/422#identity-validation-error',\n};\n","import { ErrorCodeValidationProblemDetails } from '../models/error-code-validation-problem-details';\nimport { KeyValidationProblemDetails } from '../models/key-validation-problem-details';\nimport { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudBadRequestException } from './monocloud-bad-request-exception';\nimport { MonoCloudConflictException } from './monocloud-conflict-exception';\nimport { MonoCloudErrorCodeValidationException } from './monocloud-error-code-validation-exception';\nimport { MonoCloudException } from './monocloud-exception';\nimport { MonoCloudKeyValidationException } from './monocloud-key-validation-exception';\nimport { MonoCloudModelStateException } from './monocloud-model-state-exception';\nimport { MonoCloudNotFoundException } from './monocloud-not-found-exception';\nimport { MonoCloudResourceExhaustedException } from './monocloud-resource-exhausted-exception';\nimport { MonoCloudServerException } from './monocloud-server-exception';\nimport { MonoCloudUnauthorizedException } from './monocloud-unauthorized-exception';\n\n/// <summary>\n/// The MonoCloud Exception Handler\n/// </summary>\nexport class MonoCloudExceptionHandler {\n /// <summary>\n /// Converts the Problem Details returned from the server into an exception\n /// </summary>\n /// <param name=\"problemDetails\">The problem details returned from the server.</param>\n /// <returns></returns>\n public static ThrowProblemErr(problemDetails: ProblemDetails): void {\n switch (problemDetails.status) {\n case 400:\n throw new MonoCloudBadRequestException(problemDetails);\n case 401:\n throw new MonoCloudUnauthorizedException(problemDetails);\n case 403:\n throw new MonoCloudUnauthorizedException(problemDetails);\n case 404:\n throw new MonoCloudNotFoundException(problemDetails);\n case 409:\n throw new MonoCloudConflictException(problemDetails);\n case 422:\n if (problemDetails instanceof ErrorCodeValidationProblemDetails) {\n throw new MonoCloudErrorCodeValidationException(problemDetails);\n }\n\n if (problemDetails instanceof KeyValidationProblemDetails) {\n throw new MonoCloudKeyValidationException(problemDetails);\n }\n\n throw new MonoCloudModelStateException(problemDetails);\n case 429:\n throw new MonoCloudResourceExhaustedException(problemDetails);\n case 500:\n throw new MonoCloudServerException(problemDetails);\n default:\n throw new MonoCloudException(\n problemDetails.title ?? 'An Unknown Error Occured'\n );\n }\n }\n\n /// <summary>\n /// Converts the error returned from the server into an exception\n /// </summary>\n /// <param name=\"statusCode\">The response status code.</param>\n /// <param name=\"message\">The error message returned from the server.</param>\n /// <returns></returns>\n public static ThrowErr(statusCode: number, message?: string): void {\n switch (statusCode) {\n case 400:\n throw new MonoCloudBadRequestException(message ?? 'Bad Request');\n case 401:\n throw new MonoCloudUnauthorizedException(message ?? 'Unauthorized');\n case 403:\n throw new MonoCloudUnauthorizedException(message ?? 'Forbidden');\n case 404:\n throw new MonoCloudNotFoundException(message ?? 'Not Found');\n case 409:\n throw new MonoCloudConflictException(message ?? 'Conflict');\n case 422:\n throw new MonoCloudModelStateException(\n message ?? 'Unprocessable entity'\n );\n case 429:\n throw new MonoCloudResourceExhaustedException(\n message ?? 'Resource Exhausted'\n );\n case 500:\n throw new MonoCloudServerException(message ?? 'Server Error');\n default:\n throw new MonoCloudException(message ?? 'An Unknown Error Occured');\n }\n }\n}\n","import { MonoCloudConfig } from './monocloud-config';\nimport { MonoCloudResponse } from '../models/monocloud-response';\nimport { MonoCloudException } from '../exceptions/monocloud-exception';\nimport { MonoCloudPageResponse } from '../models/monocloud-page-response';\nimport { PageModel } from '../models/page-model';\nimport { ProblemDetails } from '../models/problem-details';\nimport { ValidationExceptionTypes } from '../exceptions/validation-exception-types';\nimport { ErrorCodeValidationProblemDetails } from '../models/error-code-validation-problem-details';\nimport { KeyValidationProblemDetails } from '../models/key-validation-problem-details';\nimport { MonoCloudExceptionHandler } from '../exceptions/monocloud-exception-handler';\nimport { MonoCloudRequest } from '../models/monocloud-request';\nimport { Fetcher } from '../models/fetcher';\n\nexport abstract class MonoCloudClientBase {\n protected fetcher: Fetcher;\n\n constructor(configuration: MonoCloudConfig, fetcher?: Fetcher) {\n if (fetcher) {\n this.fetcher = fetcher;\n } else {\n if (!configuration) {\n throw new MonoCloudException('Configuration is required');\n }\n\n if (!configuration.domain) {\n throw new MonoCloudException('Tenant Domain is required');\n }\n\n if (!configuration.apiKey) {\n throw new MonoCloudException('Api Key is required');\n }\n\n const headers: Record<string, string> = {\n 'X-API-KEY': configuration.apiKey,\n 'Content-Type': 'application/json',\n };\n\n const baseUrl = `${this.sanitizeUrl(configuration.domain)}/api/`;\n\n this.fetcher = async (\n input: string | URL | globalThis.Request,\n init?: RequestInit\n ): Promise<Response> => {\n const url = new URL(input, baseUrl);\n\n const signal = AbortSignal.timeout(\n configuration.config?.timeout ?? 10000\n );\n signal.throwIfAborted();\n\n const resp = await fetch(url.toString(), { ...init, headers, signal });\n\n return resp;\n };\n }\n }\n\n protected async processRequest<T = unknown>(\n request: MonoCloudRequest\n ): Promise<MonoCloudResponse<T>> {\n try {\n const url = this.buildUrl(request.url, request.queryParams);\n\n const response = await this.fetcher(url, {\n method: request.method,\n body: request.body ? JSON.stringify(request.body) : undefined,\n });\n\n if (!response.ok) {\n await this.HandleErrorResponse(response);\n }\n\n const headers: Record<string, any> = {};\n\n response.headers.forEach((value, key) => {\n headers[key] = value;\n });\n\n const resp = response.body ? await response.text() : null;\n\n return new MonoCloudResponse<T>(\n response.status,\n headers,\n (resp?.length ? JSON.parse(resp) : null) as T\n );\n } catch (e: any) {\n if (e instanceof MonoCloudException) {\n throw e;\n }\n\n if (e.name === 'TimeoutError') {\n throw new MonoCloudException(e.message);\n }\n\n throw new MonoCloudException('Something went wrong.');\n }\n }\n\n protected async processPaginatedRequest<T = unknown>(\n request: MonoCloudRequest\n ): Promise<MonoCloudPageResponse<T>> {\n try {\n const url = this.buildUrl(request.url, request.queryParams);\n\n const response = await this.fetcher(url, {\n method: request.method,\n body: request.body ? JSON.stringify(request.body) : undefined,\n });\n\n if (!response.ok) {\n await this.HandleErrorResponse(response);\n }\n\n const headers: Record<string, any> = {};\n\n response.headers.forEach((value, key) => {\n headers[key] = value;\n });\n\n const paginationData = this.resolvePaginationHeader(response.headers);\n\n return new MonoCloudPageResponse<T>(\n response.status,\n headers,\n (response.body ? await response.json() : null) as T,\n paginationData\n );\n } catch (e: any) {\n if (e instanceof MonoCloudException) {\n throw e;\n }\n\n if (e.name === 'TimeoutError') {\n throw new MonoCloudException(e.message);\n }\n\n throw new MonoCloudException('Something went wrong.');\n }\n }\n\n private async HandleErrorResponse(response: Response): Promise<void> {\n const contentType = response.headers.get('content-type');\n if (contentType?.startsWith('application/problem+json')) {\n const body = await response.json();\n let result = body\n ? new ProblemDetails(body as ProblemDetails)\n : undefined;\n\n if (result?.type === ValidationExceptionTypes.IdentityValidationError) {\n result = new ErrorCodeValidationProblemDetails(result);\n }\n\n if (result?.type === ValidationExceptionTypes.ValidationError) {\n result = new KeyValidationProblemDetails(result);\n }\n\n if (!result) {\n throw new MonoCloudException('Invalid body');\n }\n\n MonoCloudExceptionHandler.ThrowProblemErr(result);\n }\n\n const respStrng = await response.text();\n MonoCloudExceptionHandler.ThrowErr(\n response.status,\n respStrng && respStrng !== '' ? respStrng : response.statusText\n );\n }\n\n private sanitizeUrl(url: string): string {\n let u = url;\n if (!u.startsWith('https://')) {\n u = `https://${u}`;\n }\n\n if (u.endsWith('/')) {\n u = u.substring(0, u.length - 1);\n }\n\n return u;\n }\n\n private resolvePaginationHeader(headers: Headers): PageModel {\n const paginationHeader = headers.get('x-pagination');\n const pageData = paginationHeader\n ? JSON.parse(paginationHeader)\n : undefined;\n\n return {\n page_size: pageData?.page_size ?? 0,\n current_page: pageData?.current_page ?? 0,\n total_count: pageData?.total_count ?? 0,\n has_previous: pageData?.has_previous ?? false,\n has_next: pageData?.has_next ?? false,\n };\n }\n\n private buildUrl(\n url: string,\n queryParams?: Record<string, string | number | boolean>\n ): string {\n let urlStr = url;\n\n if (urlStr.startsWith('/')) {\n urlStr = urlStr.substring(1, urlStr.length);\n }\n\n if (!queryParams) {\n return urlStr;\n }\n\n urlStr += '?';\n\n Object.keys(queryParams).forEach(key => {\n urlStr += `${key}=${encodeURIComponent(queryParams[key])}&`;\n });\n\n urlStr = urlStr.substring(0, urlStr.length - 1);\n\n return urlStr;\n }\n}\n"],"mappings":";;AAGA,IAAa,qBAAb,cAAwC,MAAM;;;;ACA9C,IAAa,4BAAb,cAA+C,mBAAmB;CAyBhE,YAAY,GAAG,MAA8D;EAC3E,IAAIA;EACJ,IAAIC;AAEJ,MAAI,MAAM,QAAQ,KAAK,CACrB,KAAI,KAAK,WAAW,GAAG;AACrB,oBAAiB,KAAK;AACtB,kBAAe,KAAK;aACX,KAAK,WAAW,KAAK,OAAO,KAAK,OAAO,SACjD,gBAAe,KAAK;WACX,KAAK,WAAW,KAAK,OAAO,KAAK,OAAO,UAAU;AAC3D,oBAAiB,KAAK;AACtB,kBAAe,KAAK,GAAG;QAEvB,OAAM,IAAI,MAAM,mCAAmC;AAIvD,MAAI,CAAC,aACH,OAAM,IAAI,MAAM,wBAAwB;AAG1C,QAAM,aAAa;AACnB,OAAK,WAAW;;;;;;AC7CpB,IAAa,+BAAb,cAAkD,0BAA0B;CAa1E,YAAY,KAA8B;AACxC,MAAI,OAAO,QAAQ,SACjB,OAAM,IAAI;MAEV,OAAM,IAAI;;;;;;ACjBhB,IAAa,6BAAb,cAAgD,0BAA0B;CAaxE,YAAY,KAA8B;AACxC,MAAI,OAAO,QAAQ,SACjB,OAAM,IAAI;MAEV,OAAM,IAAI;;;;;;AChBhB,IAAa,wCAAb,cAA2D,0BAA0B;CAOnF,YAAY,UAA6C;AACvD,QACE,UACA,GAAG,SAAS,MAAM,KAAK,KAAK,UAA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I,CAAC,YACH,QAAO;AAGT,YAAU;AAEV,SAAO,KAAK,YAAY,CAAC,SAAQ,QAAO;AACtC,aAAU,GAAG,IAAI,GAAG,mBAAmB,YAAY,KAAK,CAAC;IACzD;AAEF,WAAS,OAAO,UAAU,GAAG,OAAO,SAAS,EAAE;AAE/C,SAAO"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/exceptions/monocloud-exception.ts","../src/exceptions/monocloud-request-exception.ts","../src/exceptions/monocloud-bad-request-exception.ts","../src/exceptions/monocloud-conflict-exception.ts","../src/exceptions/monocloud-identity-validation-exception.ts","../src/exceptions/monocloud-forbidden-exception.ts","../src/exceptions/monocloud-key-validation-exception.ts","../src/exceptions/monocloud-model-state-exception.ts","../src/exceptions/monocloud-not-found-exception.ts","../src/exceptions/monocloud-resource-exhausted-exception.ts","../src/exceptions/monocloud-server-exception.ts","../src/exceptions/monocloud-unauthorized-exception.ts","../src/exceptions/monocloud-payment-required-exception.ts","../src/models/identity-error.ts","../src/models/problem-details.ts","../src/models/identity-validation-problem-details.ts","../src/models/key-validation-problem-details.ts","../src/models/monocloud-response.ts","../src/models/monocloud-page-response.ts","../src/exceptions/validation-exception-types.ts","../src/exceptions/monocloud-exception-handler.ts","../src/base/monocloud-client-base.ts"],"sourcesContent":["/**\n * The MonoCloud Exception\n * @export\n * @class MonoCloudException\n */\nexport class MonoCloudException extends Error {}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudException } from './monocloud-exception';\n\nexport class MonoCloudRequestException extends MonoCloudException {\n /**\n * The problem details received from the server.\n * @type {ProblemDetails}\n * @memberof MonoCloudRequestException\n */\n response?: ProblemDetails;\n\n /**\n * Initializes the MonoCloudRequestException Class\n * @param response - The problem details returned from the server.\n */\n constructor(response: ProblemDetails);\n\n /**\n * Initializes the MonoCloudRequestException Class\n * @param message - The error message.\n */\n constructor(message: string);\n\n /**\n * Initializes the MonoCloudRequestException Class\n * @param response - The problem details returned from the server.\n * @param message - The error message.\n */\n constructor(response: ProblemDetails, message: string);\n\n constructor(...args: [ProblemDetails, string] | [ProblemDetails] | [string]) {\n let problemDetails: ProblemDetails | undefined;\n let errorMessage: string | undefined;\n\n if (Array.isArray(args)) {\n if (args.length === 2) {\n problemDetails = args[0];\n errorMessage = args[1];\n } else if (args.length === 1 && typeof args[0] === 'string') {\n errorMessage = args[0];\n } else if (args.length === 1 && typeof args[0] === 'object') {\n problemDetails = args[0];\n errorMessage = args[0].title;\n } else {\n throw new Error('Invalid arguments in constructor');\n }\n }\n\n if (!errorMessage) {\n throw new Error('Invalid error message');\n }\n\n super(errorMessage);\n this.response = problemDetails;\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/**\n * The MonoCloud Bad Request Exception\n * @export\n * @class MonoCloudBadRequestException\n */\nexport class MonoCloudBadRequestException extends MonoCloudRequestException {\n /**\n * Initializes the MonoCloudBadRequestException Class\n * @param response - The problem details returned from the server.\n */\n constructor(response: ProblemDetails);\n\n /**\n * Initializes the MonoCloudBadRequestException Class\n * @param message - The error message.\n */\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/**\n * The MonoCloud Conflict Exception\n * @export\n * @class MonoCloudConflictException\n */\nexport class MonoCloudConflictException extends MonoCloudRequestException {\n /**\n * Initializes the MonoCloudConflictException Class\n * @param response - The problem details returned from the server.\n */\n constructor(response: ProblemDetails);\n\n /**\n * Initializes the MonoCloudConflictException Class\n * @param message - The error message.\n */\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { IdentityError } from '../models/identity-error';\nimport { IdentityValidationProblemDetails } from '../models/identity-validation-problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/**\n * The MonoCloud Identity Validation Exception\n * @export\n * @class MonoCloudIdentityValidationException\n */\nexport class MonoCloudIdentityValidationException extends MonoCloudRequestException {\n errors: IdentityError[];\n\n /**\n * Initializes the MonoCloudIdentityValidationException Class\n * @param response - The problem details returned from the server.\n */\n constructor(response: IdentityValidationProblemDetails) {\n super(\n response,\n `${response.title} : ${JSON.stringify(response.errors, undefined, 2)}`\n );\n this.errors = response.errors;\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/**\n * The MonoCloud Forbidden Exception\n * @export\n * @class MonoCloudForbiddenException\n */\nexport class MonoCloudForbiddenException extends MonoCloudRequestException {\n /**\n * Initializes the MonoCloudForbiddenException Class\n * @param response - The problem details returned from the server.\n */\n constructor(response: ProblemDetails);\n\n /**\n * Initializes the MonoCloudForbiddenException Class\n * @param message - The error message.\n */\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { KeyValidationProblemDetails } from '../models/key-validation-problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/**\n * The MonoCloud Key Validation Exception\n * @export\n * @class MonoCloudKeyValidationException\n */\nexport class MonoCloudKeyValidationException extends MonoCloudRequestException {\n errors: Record<string, string[]>;\n\n /**\n * Initializes the MonoCloudKeyValidationException Class\n * @param response - The problem details returned from the server.\n */\n constructor(response: KeyValidationProblemDetails) {\n super(\n response,\n `${response.title} : ${JSON.stringify(response.errors, undefined, 2)}`\n );\n this.errors = response.errors;\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/**\n * The MonoCloud Model State Exception\n * @export\n * @class MonoCloudModelStateException\n */\nexport class MonoCloudModelStateException extends MonoCloudRequestException {\n /**\n * Initializes the MonoCloudModelStateException Class\n * @param response - The problem details returned from the server.\n */\n constructor(response: ProblemDetails);\n\n /**\n * Initializes the MonoCloudModelStateException Class\n * @param message - The error message.\n */\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/**\n * The MonoCloud Not Found Exception\n * @export\n * @class MonoCloudNotFoundException\n */\nexport class MonoCloudNotFoundException extends MonoCloudRequestException {\n /**\n * Initializes the MonoCloudNotFoundException Class\n * @param response - The problem details returned from the server.\n */\n constructor(response: ProblemDetails);\n\n /**\n * Initializes the MonoCloudNotFoundException Class\n * @param message - The error message.\n */\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/**\n * The MonoCloud Resource Exhausted Exception\n * @export\n * @class MonoCloudResourceExhaustedException\n */\nexport class MonoCloudResourceExhaustedException extends MonoCloudRequestException {\n /**\n * Initializes the MonoCloudResourceExhaustedException Class\n * @param response - The problem details returned from the server.\n */\n constructor(response: ProblemDetails);\n\n /**\n * Initializes the MonoCloudResourceExhaustedException Class\n * @param message - The error message.\n */\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/**\n * The MonoCloud Server Exception\n * @export\n * @class MonoCloudServerException\n */\nexport class MonoCloudServerException extends MonoCloudRequestException {\n /**\n * Initializes the MonoCloudServerException Class\n * @param response - The problem details returned from the server.\n */\n constructor(response: ProblemDetails);\n\n /**\n * Initializes the MonoCloudServerException Class\n * @param message - The error message.\n */\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/**\n * The MonoCloud Unauthorized Exception\n * @export\n * @class MonoCloudUnauthorizedException\n */\nexport class MonoCloudUnauthorizedException extends MonoCloudRequestException {\n /**\n * Initializes the MonoCloudUnauthorizedException Class\n * @param response - The problem details returned from the server.\n */\n constructor(response: ProblemDetails);\n\n /**\n * Initializes the MonoCloudUnauthorizedException Class\n * @param message - The error message.\n */\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","import { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudRequestException } from './monocloud-request-exception';\n\n/**\n * The MonoCloud Payment Required Exception\n * @export\n * @class MonoCloudPaymentRequiredException\n */\nexport class MonoCloudPaymentRequiredException extends MonoCloudRequestException {\n /**\n * Initializes the MonoCloudPaymentRequiredException Class\n * @param response - The problem details returned from the server.\n */\n constructor(response: ProblemDetails);\n\n /**\n * Initializes the MonoCloudPaymentRequiredException Class\n * @param message - The error message.\n */\n constructor(message: string);\n\n constructor(arg: ProblemDetails | string) {\n if (typeof arg === 'string') {\n super(arg);\n } else {\n super(arg);\n }\n }\n}\n","/**\n * Identity Error: Represents a validation or processing error returned by the identity system.\n * @export\n * @class IdentityError\n */\nexport class IdentityError {\n /**\n * Machine-readable error code.\n * @type {string}\n * @memberof IdentityError\n */\n code: string;\n\n /**\n * Human-readable description of the error.\n * @type {string}\n * @memberof IdentityError\n */\n description: string;\n\n constructor(code: string, description: string) {\n this.code = code;\n this.description = description;\n }\n}\n","/**\n * The Problem Details\n * @export\n * @class ProblemDetails\n */\nexport class ProblemDetails {\n /**\n * The type of error\n * @type {string}\n * @memberof ProblemDetails\n */\n type: string;\n\n /**\n * The title of the error\n * @type {string}\n * @memberof ProblemDetails\n */\n title: string;\n\n /**\n * The status code representing the error\n * @type {number}\n * @memberof ProblemDetails\n */\n status: number;\n\n /**\n * The error details\n * @type {string}\n * @memberof ProblemDetails\n */\n detail: string;\n\n /**\n * The instance\n * @type {string}\n * @memberof ProblemDetails\n */\n instance: string;\n\n /**\n * Additional data about the error\n */\n\n [key: string]: any;\n\n constructor(response: ProblemDetails) {\n this.type = response.type;\n this.title = response.title;\n this.status = response.status;\n this.detail = response.detail;\n this.instance = response.instance;\n Object.keys(response)\n .filter(\n x => x !== 'type' && x !== 'title' && x !== 'status' && x !== 'instance'\n )\n .forEach(key => {\n this[key] = response[key];\n });\n }\n}\n","import { IdentityError } from './identity-error';\nimport { ProblemDetails } from './problem-details';\n\nexport class IdentityValidationProblemDetails extends ProblemDetails {\n errors: IdentityError[];\n\n constructor(response: ProblemDetails) {\n super(response);\n this.errors = (response.errors as IdentityError[]).map(\n err => new IdentityError(err.code, err.description)\n );\n }\n}\n","import { ProblemDetails } from './problem-details';\n\n/**\n * The Key Validation Problem Details\n * @export\n * @class KeyValidationProblemDetails\n */\nexport class KeyValidationProblemDetails extends ProblemDetails {\n /**\n * A collection of errors\n * @type {Record<string, string[]>}\n * @memberof KeyValidationProblemDetails\n */\n errors: Record<string, string[]>;\n\n constructor(response: ProblemDetails) {\n super(response);\n this.errors = response.errors;\n }\n}\n","export class MonoCloudResponse<TResult = unknown> {\n status: number;\n\n headers: Record<string, any>;\n\n result: TResult;\n\n constructor(status: number, headers: Record<string, any>, result: TResult) {\n this.status = status;\n this.headers = headers;\n this.result = result;\n }\n}\n","import { MonoCloudResponse } from './monocloud-response';\nimport { PageModel } from './page-model';\n\nexport class MonoCloudPageResponse<\n TResult = unknown,\n> extends MonoCloudResponse<TResult> {\n pageData: PageModel;\n\n constructor(\n status: number,\n headers: Record<string, any>,\n result: TResult,\n pageData: PageModel\n ) {\n super(status, headers, result);\n this.pageData = pageData;\n }\n}\n","export const ValidationExceptionTypes = {\n ValidationError: 'https://httpstatuses.io/422#validation-error',\n IdentityValidationError:\n 'https://httpstatuses.io/422#identity-validation-error',\n};\n","import { IdentityValidationProblemDetails } from '../models/identity-validation-problem-details';\nimport { KeyValidationProblemDetails } from '../models/key-validation-problem-details';\nimport { ProblemDetails } from '../models/problem-details';\nimport { MonoCloudBadRequestException } from './monocloud-bad-request-exception';\nimport { MonoCloudConflictException } from './monocloud-conflict-exception';\nimport { MonoCloudIdentityValidationException } from './monocloud-identity-validation-exception';\nimport { MonoCloudException } from './monocloud-exception';\nimport { MonoCloudKeyValidationException } from './monocloud-key-validation-exception';\nimport { MonoCloudModelStateException } from './monocloud-model-state-exception';\nimport { MonoCloudNotFoundException } from './monocloud-not-found-exception';\nimport { MonoCloudResourceExhaustedException } from './monocloud-resource-exhausted-exception';\nimport { MonoCloudServerException } from './monocloud-server-exception';\nimport { MonoCloudUnauthorizedException } from './monocloud-unauthorized-exception';\nimport { MonoCloudPaymentRequiredException } from './monocloud-payment-required-exception';\n\n/**\n * The MonoCloud Exception Handler\n * @export\n * @class MonoCloudExceptionHandler\n */\nexport class MonoCloudExceptionHandler {\n /**\n * Converts the Problem Details returned from the server into an exception\n * @param problemDetails - The problem details returned from the server.\n */\n public static ThrowProblemErr(problemDetails: ProblemDetails): void {\n switch (problemDetails.status) {\n case 400:\n throw new MonoCloudBadRequestException(problemDetails);\n case 401:\n throw new MonoCloudUnauthorizedException(problemDetails);\n case 402:\n throw new MonoCloudPaymentRequiredException(problemDetails);\n case 403:\n throw new MonoCloudUnauthorizedException(problemDetails);\n case 404:\n throw new MonoCloudNotFoundException(problemDetails);\n case 409:\n throw new MonoCloudConflictException(problemDetails);\n case 422:\n if (problemDetails instanceof IdentityValidationProblemDetails) {\n throw new MonoCloudIdentityValidationException(problemDetails);\n }\n\n if (problemDetails instanceof KeyValidationProblemDetails) {\n throw new MonoCloudKeyValidationException(problemDetails);\n }\n\n throw new MonoCloudModelStateException(problemDetails);\n case 429:\n throw new MonoCloudResourceExhaustedException(problemDetails);\n case 500:\n throw new MonoCloudServerException(problemDetails);\n default:\n throw new MonoCloudException(\n problemDetails.title ?? 'An Unknown Error Occured'\n );\n }\n }\n\n /**\n * Converts the error returned from the server into an exception\n * @param statusCode - The response status code.\n * @param message - The error message returned from the server.\n */\n public static ThrowErr(statusCode: number, message?: string): void {\n switch (statusCode) {\n case 400:\n throw new MonoCloudBadRequestException(message ?? 'Bad Request');\n case 401:\n throw new MonoCloudUnauthorizedException(message ?? 'Unauthorized');\n case 402:\n throw new MonoCloudPaymentRequiredException(\n message ?? 'Payment Required'\n );\n case 403:\n throw new MonoCloudUnauthorizedException(message ?? 'Forbidden');\n case 404:\n throw new MonoCloudNotFoundException(message ?? 'Not Found');\n case 409:\n throw new MonoCloudConflictException(message ?? 'Conflict');\n case 422:\n throw new MonoCloudModelStateException(\n message ?? 'Unprocessable entity'\n );\n case 429:\n throw new MonoCloudResourceExhaustedException(\n message ?? 'Resource Exhausted'\n );\n case 500:\n throw new MonoCloudServerException(message ?? 'Server Error');\n default:\n throw new MonoCloudException(message ?? 'An Unknown Error Occured');\n }\n }\n}\n","import { MonoCloudConfig } from './monocloud-config';\nimport { MonoCloudResponse } from '../models/monocloud-response';\nimport { MonoCloudException } from '../exceptions/monocloud-exception';\nimport { MonoCloudPageResponse } from '../models/monocloud-page-response';\nimport { PageModel } from '../models/page-model';\nimport { ProblemDetails } from '../models/problem-details';\nimport { ValidationExceptionTypes } from '../exceptions/validation-exception-types';\nimport { IdentityValidationProblemDetails } from '../models/identity-validation-problem-details';\nimport { KeyValidationProblemDetails } from '../models/key-validation-problem-details';\nimport { MonoCloudExceptionHandler } from '../exceptions/monocloud-exception-handler';\nimport { MonoCloudRequest } from '../models/monocloud-request';\nimport { Fetcher } from '../models/fetcher';\n\nexport abstract class MonoCloudClientBase {\n protected fetcher: Fetcher;\n\n constructor(configuration: MonoCloudConfig, fetcher?: Fetcher) {\n if (fetcher) {\n this.fetcher = fetcher;\n } else {\n if (!configuration) {\n throw new MonoCloudException('Configuration is required');\n }\n\n if (!configuration.domain) {\n throw new MonoCloudException('Tenant Domain is required');\n }\n\n if (!configuration.apiKey) {\n throw new MonoCloudException('Api Key is required');\n }\n\n const headers: Record<string, string> = {\n 'X-API-KEY': configuration.apiKey,\n 'Content-Type': 'application/json',\n };\n\n const baseUrl = `${this.sanitizeUrl(configuration.domain)}/api/`;\n\n this.fetcher = async (\n input: string | URL,\n init?: RequestInit\n ): Promise<Response> => {\n const url = new URL(input, baseUrl);\n\n const signal = AbortSignal.timeout(\n configuration.config?.timeout ?? 10000\n );\n signal.throwIfAborted();\n\n const resp = await fetch(url.toString(), { ...init, headers, signal });\n\n return resp;\n };\n }\n }\n\n protected async processRequest<T = unknown>(\n request: MonoCloudRequest\n ): Promise<MonoCloudResponse<T>> {\n try {\n const url = this.buildUrl(request.url, request.queryParams);\n\n const response = await this.fetcher(url, {\n method: request.method,\n body: request.body ? JSON.stringify(request.body) : undefined,\n });\n\n if (!response.ok) {\n await this.HandleErrorResponse(response);\n }\n\n const headers: Record<string, any> = {};\n\n response.headers.forEach((value, key) => {\n headers[key] = value;\n });\n\n const resp = response.body ? await response.text() : null;\n\n return new MonoCloudResponse<T>(\n response.status,\n headers,\n (resp?.length ? JSON.parse(resp) : null) as T\n );\n } catch (e: any) {\n if (e instanceof MonoCloudException) {\n throw e;\n }\n\n if (e.name === 'TimeoutError') {\n throw new MonoCloudException(e.message);\n }\n\n throw new MonoCloudException('Something went wrong.');\n }\n }\n\n protected async processPaginatedRequest<T = unknown>(\n request: MonoCloudRequest\n ): Promise<MonoCloudPageResponse<T>> {\n try {\n const url = this.buildUrl(request.url, request.queryParams);\n\n const response = await this.fetcher(url, {\n method: request.method,\n body: request.body ? JSON.stringify(request.body) : undefined,\n });\n\n if (!response.ok) {\n await this.HandleErrorResponse(response);\n }\n\n const headers: Record<string, any> = {};\n\n response.headers.forEach((value, key) => {\n headers[key] = value;\n });\n\n const paginationData = this.resolvePaginationHeader(response.headers);\n\n return new MonoCloudPageResponse<T>(\n response.status,\n headers,\n (response.body ? await response.json() : null) as T,\n paginationData\n );\n } catch (e: any) {\n if (e instanceof MonoCloudException) {\n throw e;\n }\n\n if (e.name === 'TimeoutError') {\n throw new MonoCloudException(e.message);\n }\n\n throw new MonoCloudException('Something went wrong.');\n }\n }\n\n private async HandleErrorResponse(response: Response): Promise<void> {\n const contentType = response.headers.get('content-type');\n if (contentType?.startsWith('application/problem+json')) {\n const body = await response.json();\n let result = body\n ? new ProblemDetails(body as ProblemDetails)\n : undefined;\n\n if (result?.type === ValidationExceptionTypes.IdentityValidationError) {\n result = new IdentityValidationProblemDetails(result);\n }\n\n if (result?.type === ValidationExceptionTypes.ValidationError) {\n result = new KeyValidationProblemDetails(result);\n }\n\n if (!result) {\n throw new MonoCloudException('Invalid body');\n }\n\n MonoCloudExceptionHandler.ThrowProblemErr(result);\n }\n\n const respStrng = await response.text();\n MonoCloudExceptionHandler.ThrowErr(\n response.status,\n respStrng && respStrng !== '' ? respStrng : response.statusText\n );\n }\n\n private sanitizeUrl(url: string): string {\n let u = url;\n if (!u.startsWith('https://')) {\n u = `https://${u}`;\n }\n\n if (u.endsWith('/')) {\n u = u.substring(0, u.length - 1);\n }\n\n return u;\n }\n\n private resolvePaginationHeader(headers: Headers): PageModel {\n const paginationHeader = headers.get('x-pagination');\n const pageData = paginationHeader\n ? JSON.parse(paginationHeader)\n : undefined;\n\n return {\n page_size: pageData?.page_size ?? 0,\n current_page: pageData?.current_page ?? 0,\n total_count: pageData?.total_count ?? 0,\n has_previous: pageData?.has_previous ?? false,\n has_next: pageData?.has_next ?? false,\n };\n }\n\n private buildUrl(\n url: string,\n queryParams?: Record<string, string | number | boolean>\n ): string {\n let urlStr = url;\n\n if (urlStr.startsWith('/')) {\n urlStr = urlStr.substring(1, urlStr.length);\n }\n\n if (!queryParams) {\n return urlStr;\n }\n\n urlStr += '?';\n\n Object.keys(queryParams).forEach(key => {\n urlStr += `${key}=${encodeURIComponent(queryParams[key])}&`;\n });\n\n urlStr = urlStr.substring(0, urlStr.length - 1);\n\n return urlStr;\n }\n}\n"],"mappings":";;;;;;;;AAKA,IAA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