b23-lib 1.1.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/dist/index.js ADDED
@@ -0,0 +1,569 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ Auth: () => Auth_default,
34
+ DynamoDB: () => Dynamodb_default,
35
+ Fetch: () => fetch_default,
36
+ Logger: () => Logger_default,
37
+ ResponseUtility: () => response_default,
38
+ Schema: () => Schema_default
39
+ });
40
+ module.exports = __toCommonJS(src_exports);
41
+
42
+ // src/Dynamodb/index.ts
43
+ var import_client_dynamodb = require("@aws-sdk/client-dynamodb");
44
+ var import_util_dynamodb = require("@aws-sdk/util-dynamodb");
45
+ var DynamoDBUtility = class {
46
+ client;
47
+ returnItemCollectionMetrics;
48
+ logCapacity;
49
+ region;
50
+ marshall = import_util_dynamodb.marshall;
51
+ unmarshall = import_util_dynamodb.unmarshall;
52
+ ReturnValue = import_client_dynamodb.ReturnValue;
53
+ ReturnItemCollectionMetrics = import_client_dynamodb.ReturnItemCollectionMetrics;
54
+ ReturnValuesOnConditionCheckFailure = import_client_dynamodb.ReturnValuesOnConditionCheckFailure;
55
+ constructor({ region, returnItemCollectionMetrics = import_client_dynamodb.ReturnItemCollectionMetrics.NONE, logCapacity = false }) {
56
+ this.region = region;
57
+ this.returnItemCollectionMetrics = returnItemCollectionMetrics;
58
+ this.logCapacity = logCapacity;
59
+ this.client = new import_client_dynamodb.DynamoDBClient({ region: this.region });
60
+ }
61
+ log(message, capacity, size) {
62
+ if (this.logCapacity) {
63
+ console.log(message, "Capacity:", capacity, "Size:", size);
64
+ }
65
+ }
66
+ async putItem(TableName, item, condition, attributeName, attributeValue, ReturnValues = import_client_dynamodb.ReturnValue.NONE, ReturnValuesOnFailure = import_client_dynamodb.ReturnValuesOnConditionCheckFailure.ALL_OLD) {
67
+ const input = {
68
+ TableName,
69
+ Item: (0, import_util_dynamodb.marshall)(item, {
70
+ removeUndefinedValues: true,
71
+ convertClassInstanceToMap: true
72
+ }),
73
+ ConditionExpression: condition,
74
+ ExpressionAttributeNames: attributeName,
75
+ ExpressionAttributeValues: attributeValue,
76
+ ReturnValues,
77
+ ReturnConsumedCapacity: import_client_dynamodb.ReturnConsumedCapacity.INDEXES,
78
+ ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure,
79
+ ReturnItemCollectionMetrics: this.returnItemCollectionMetrics
80
+ };
81
+ const command = new import_client_dynamodb.PutItemCommand(input);
82
+ const result = await this.client.send(command);
83
+ this.log("Put", result.ConsumedCapacity, result.ItemCollectionMetrics);
84
+ return (0, import_util_dynamodb.unmarshall)(result.Attributes || {});
85
+ }
86
+ async transactWriteItems(transactItems) {
87
+ const input = {
88
+ TransactItems: transactItems.map((item) => {
89
+ if (item.Put) {
90
+ item.Put.Item = (0, import_util_dynamodb.marshall)(item.Put.Item, {
91
+ removeUndefinedValues: true,
92
+ convertClassInstanceToMap: true
93
+ });
94
+ }
95
+ if (item.Update) {
96
+ item.Update.Key = (0, import_util_dynamodb.marshall)(item.Update.Key);
97
+ }
98
+ if (item.Delete) {
99
+ item.Delete.Key = (0, import_util_dynamodb.marshall)(item.Delete.Key);
100
+ }
101
+ return item;
102
+ }),
103
+ ReturnConsumedCapacity: import_client_dynamodb.ReturnConsumedCapacity.INDEXES,
104
+ ReturnItemCollectionMetrics: this.returnItemCollectionMetrics
105
+ };
106
+ const command = new import_client_dynamodb.TransactWriteItemsCommand(input);
107
+ const result = await this.client.send(command);
108
+ this.log("Transaction", result.ConsumedCapacity, result.ItemCollectionMetrics);
109
+ }
110
+ async getItem(TableName, key, consistent = false, projection, attributeName) {
111
+ const input = {
112
+ TableName,
113
+ Key: (0, import_util_dynamodb.marshall)(key),
114
+ ConsistentRead: consistent,
115
+ ProjectionExpression: projection,
116
+ ExpressionAttributeNames: attributeName,
117
+ ReturnConsumedCapacity: import_client_dynamodb.ReturnConsumedCapacity.TOTAL
118
+ };
119
+ const command = new import_client_dynamodb.GetItemCommand(input);
120
+ const result = await this.client.send(command);
121
+ this.log("Read", result.ConsumedCapacity);
122
+ return (0, import_util_dynamodb.unmarshall)(result.Item || {});
123
+ }
124
+ async batchGetItem(TableName, keys, consistent = false, projection, attributeName) {
125
+ const input = {
126
+ RequestItems: {
127
+ [TableName]: {
128
+ Keys: keys.map((key) => (0, import_util_dynamodb.marshall)(key)),
129
+ ConsistentRead: consistent,
130
+ ProjectionExpression: projection,
131
+ ExpressionAttributeNames: attributeName
132
+ }
133
+ },
134
+ ReturnConsumedCapacity: import_client_dynamodb.ReturnConsumedCapacity.TOTAL
135
+ };
136
+ const command = new import_client_dynamodb.BatchGetItemCommand(input);
137
+ const result = await this.client.send(command);
138
+ this.log("BatchRead", result.ConsumedCapacity);
139
+ return result.Responses?.[TableName]?.map((item) => (0, import_util_dynamodb.unmarshall)(item)) || [];
140
+ }
141
+ async queryItems(TableName, keyCondition, consistent = false, projection, attributeName, attributeValue, lastEvaluatedKey) {
142
+ const input = {
143
+ TableName,
144
+ KeyConditionExpression: keyCondition,
145
+ ExpressionAttributeValues: attributeValue,
146
+ ConsistentRead: consistent,
147
+ ProjectionExpression: projection,
148
+ ExpressionAttributeNames: attributeName,
149
+ ExclusiveStartKey: lastEvaluatedKey,
150
+ ReturnConsumedCapacity: import_client_dynamodb.ReturnConsumedCapacity.TOTAL
151
+ };
152
+ const command = new import_client_dynamodb.QueryCommand(input);
153
+ const result = await this.client.send(command);
154
+ this.log("Query", result.ConsumedCapacity);
155
+ return {
156
+ items: result.Items?.map((item) => (0, import_util_dynamodb.unmarshall)(item)) || [],
157
+ lastEvaluatedKey: result.LastEvaluatedKey
158
+ };
159
+ }
160
+ async scanItems(TableName, filterExpression, consistent = false, projection, attributeName, attributeValue, lastEvaluatedKey) {
161
+ const input = {
162
+ TableName,
163
+ FilterExpression: filterExpression,
164
+ ExpressionAttributeValues: attributeValue,
165
+ ConsistentRead: consistent,
166
+ ProjectionExpression: projection,
167
+ ExpressionAttributeNames: attributeName,
168
+ ExclusiveStartKey: lastEvaluatedKey,
169
+ ReturnConsumedCapacity: import_client_dynamodb.ReturnConsumedCapacity.TOTAL
170
+ };
171
+ const command = new import_client_dynamodb.ScanCommand(input);
172
+ const result = await this.client.send(command);
173
+ this.log("Scan", result.ConsumedCapacity);
174
+ return {
175
+ items: result.Items?.map((item) => (0, import_util_dynamodb.unmarshall)(item)) || [],
176
+ lastEvaluatedKey: result.LastEvaluatedKey
177
+ };
178
+ }
179
+ async partiQL(statement, parameter = [], nextToken, consistent = false) {
180
+ const input = {
181
+ Statement: statement,
182
+ Parameters: parameter,
183
+ ConsistentRead: consistent,
184
+ NextToken: nextToken,
185
+ ReturnConsumedCapacity: import_client_dynamodb.ReturnConsumedCapacity.INDEXES
186
+ };
187
+ const command = new import_client_dynamodb.ExecuteStatementCommand(input);
188
+ const result = await this.client.send(command);
189
+ this.log("PartiQL", result.ConsumedCapacity);
190
+ return {
191
+ Items: result.Items?.map((item) => (0, import_util_dynamodb.unmarshall)(item)) || [],
192
+ nextToken: result.NextToken,
193
+ lastEvaluatedKey: result.LastEvaluatedKey
194
+ };
195
+ }
196
+ async updateItem(TableName, key, condition, update, attributeName, attributeValue, ReturnValues = import_client_dynamodb.ReturnValue.UPDATED_NEW, ReturnValuesOnFailure = import_client_dynamodb.ReturnValuesOnConditionCheckFailure.ALL_OLD) {
197
+ const input = {
198
+ TableName,
199
+ Key: (0, import_util_dynamodb.marshall)(key),
200
+ ConditionExpression: condition,
201
+ UpdateExpression: update,
202
+ ExpressionAttributeNames: attributeName,
203
+ ExpressionAttributeValues: attributeValue,
204
+ ReturnValues,
205
+ ReturnConsumedCapacity: import_client_dynamodb.ReturnConsumedCapacity.INDEXES,
206
+ ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure,
207
+ ReturnItemCollectionMetrics: this.returnItemCollectionMetrics
208
+ };
209
+ const command = new import_client_dynamodb.UpdateItemCommand(input);
210
+ const result = await this.client.send(command);
211
+ this.log("Update", result.ConsumedCapacity, result.ItemCollectionMetrics);
212
+ return (0, import_util_dynamodb.unmarshall)(result.Attributes || {});
213
+ }
214
+ async deleteItem(TableName, key, condition, attributeName, attributeValue, ReturnValues = import_client_dynamodb.ReturnValue.ALL_OLD, ReturnValuesOnFailure = import_client_dynamodb.ReturnValuesOnConditionCheckFailure.ALL_OLD) {
215
+ const input = {
216
+ TableName,
217
+ Key: (0, import_util_dynamodb.marshall)(key),
218
+ ConditionExpression: condition,
219
+ ExpressionAttributeNames: attributeName,
220
+ ExpressionAttributeValues: attributeValue,
221
+ ReturnValues,
222
+ ReturnConsumedCapacity: import_client_dynamodb.ReturnConsumedCapacity.INDEXES,
223
+ ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure,
224
+ ReturnItemCollectionMetrics: this.returnItemCollectionMetrics
225
+ };
226
+ const command = new import_client_dynamodb.DeleteItemCommand(input);
227
+ const result = await this.client.send(command);
228
+ this.log("Delete", result.ConsumedCapacity, result.ItemCollectionMetrics);
229
+ return (0, import_util_dynamodb.unmarshall)(result.Attributes || {});
230
+ }
231
+ async getItemByIndex(TableName, index, keyCondition, consistent = false, projection, attributeName, attributeValue) {
232
+ const input = {
233
+ TableName,
234
+ IndexName: index,
235
+ KeyConditionExpression: keyCondition,
236
+ ExpressionAttributeValues: attributeValue,
237
+ ConsistentRead: consistent,
238
+ ProjectionExpression: projection,
239
+ ExpressionAttributeNames: attributeName,
240
+ ReturnConsumedCapacity: import_client_dynamodb.ReturnConsumedCapacity.INDEXES
241
+ };
242
+ const command = new import_client_dynamodb.QueryCommand(input);
243
+ const result = await this.client.send(command);
244
+ this.log("Query", result.ConsumedCapacity);
245
+ return { Items: result.Items?.map((item) => (0, import_util_dynamodb.unmarshall)(item)) || [] };
246
+ }
247
+ };
248
+ var Dynamodb_default = DynamoDBUtility;
249
+
250
+ // src/Schema/definition.json
251
+ var definition_default = {
252
+ $id: "standards",
253
+ definitions: {
254
+ lowercaseText: {
255
+ type: "string",
256
+ pattern: "^(?!\\s)(?!.*\\s$)[a-z]*$"
257
+ },
258
+ lowercaseText10: {
259
+ type: "string",
260
+ pattern: "^(?!\\s)(?!.*\\s$)[a-z]{0,10}$"
261
+ },
262
+ lowercaseText16: {
263
+ type: "string",
264
+ pattern: "^(?!\\s)(?!.*\\s$)[a-z]{0,16}$"
265
+ },
266
+ lowercaseText30: {
267
+ type: "string",
268
+ pattern: "^(?!\\s)(?!.*\\s$)[a-z]{0,30}$"
269
+ },
270
+ lowercaseText50: {
271
+ type: "string",
272
+ pattern: "^(?!\\s)(?!.*\\s$)[a-z]{0,50}$"
273
+ },
274
+ lowercaseText256: {
275
+ type: "string",
276
+ pattern: "^(?!\\s)(?!.*\\s$)[a-z]{0,256}$"
277
+ },
278
+ text: {
279
+ type: "string",
280
+ pattern: "^(?!\\s)(?!.*\\s$).*$"
281
+ },
282
+ text10: {
283
+ type: "string",
284
+ pattern: "^(?!\\s)(?!.*\\s$).{0,10}$"
285
+ },
286
+ text16: {
287
+ type: "string",
288
+ pattern: "^(?!\\s)(?!.*\\s$).{0,16}$"
289
+ },
290
+ text30: {
291
+ type: "string",
292
+ pattern: "^(?!\\s)(?!.*\\s$).{0,30}$"
293
+ },
294
+ text50: {
295
+ type: "string",
296
+ pattern: "^(?!\\s)(?!.*\\s$).{0,50}$"
297
+ },
298
+ text256: {
299
+ type: "string",
300
+ pattern: "^(?!\\s)(?!.*\\s$).{0,256}$"
301
+ },
302
+ requiredText: {
303
+ type: "string",
304
+ pattern: "^(?!\\s)(?!.*\\s$).+$"
305
+ },
306
+ requiredText10: {
307
+ type: "string",
308
+ pattern: "^(?!\\s)(?!.*\\s$).{1,10}$"
309
+ },
310
+ requiredText16: {
311
+ type: "string",
312
+ pattern: "^(?!\\s)(?!.*\\s$).{1,16}$"
313
+ },
314
+ requiredText30: {
315
+ type: "string",
316
+ pattern: "^(?!\\s)(?!.*\\s$).{1,30}$"
317
+ },
318
+ requiredText50: {
319
+ type: "string",
320
+ pattern: "^(?!\\s)(?!.*\\s$).{1,50}$"
321
+ },
322
+ requiredText256: {
323
+ type: "string",
324
+ pattern: "^(?!\\s)(?!.*\\s$).{1,256}$"
325
+ },
326
+ url: {
327
+ type: "string",
328
+ pattern: "^https://[^\\s/$.?#].[^\\s]*$",
329
+ maxLength: 2048
330
+ },
331
+ uuid: {
332
+ type: "string",
333
+ minLength: 1,
334
+ pattern: "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
335
+ },
336
+ productKey: {
337
+ type: "string",
338
+ pattern: "^(?!\\s)(?!.*\\s$)[A-Z0-9-]{4,16}$"
339
+ },
340
+ variantId: {
341
+ type: "string",
342
+ pattern: "^(?!\\s)(?!.*\\s$)[A-Z0-9-]{4,16}$"
343
+ },
344
+ firstName: { $ref: "#/definitions/requiredText30" },
345
+ lastName: { $ref: "#/definitions/text30" },
346
+ phone: {
347
+ type: "string",
348
+ pattern: "^[0-9]{10}$"
349
+ },
350
+ email: {
351
+ type: "string",
352
+ pattern: "^[^\\s]+@[^\\s]+\\.[^\\s]+$"
353
+ },
354
+ addressLine1: { $ref: "#/definitions/requiredText50" },
355
+ addressLine2: { $ref: "#/definitions/text50" },
356
+ city: { $ref: "#/definitions/requiredText30" },
357
+ postalCode: { $ref: "#/definitions/requiredText16" },
358
+ state: {
359
+ type: "string",
360
+ enum: ["AP", "AR", "AS", "BR", "CT", "GA", "GJ", "HR", "HP", "JH", "KA", "KL", "MP", "MH", "MN", "ML", "MZ", "NL", "OR", "PB", "RJ", "SK", "TN", "TG", "TR", "UP", "UT", "WB", "AN", "CH", "DH", "LD", "DL", "PY", "LA", "JK"]
361
+ },
362
+ country: {
363
+ type: "string",
364
+ enum: [
365
+ "IN"
366
+ ]
367
+ },
368
+ currency: {
369
+ type: "string",
370
+ enum: [
371
+ "INR"
372
+ ]
373
+ },
374
+ locale: {
375
+ type: "string",
376
+ enum: [
377
+ "en-IN"
378
+ ]
379
+ },
380
+ addressType: {
381
+ type: "string",
382
+ enum: ["shipping", "billing", "shipping&billing"]
383
+ },
384
+ address: {
385
+ type: "object",
386
+ properties: {
387
+ firstName: { $ref: "standards#/definitions/firstName" },
388
+ lastName: { $ref: "standards#/definitions/lastName" },
389
+ phone: { $ref: "standards#/definitions/phone" },
390
+ email: { $ref: "standards#/definitions/email" },
391
+ addressLine1: { $ref: "standards#/definitions/addressLine1" },
392
+ addressLine2: { $ref: "standards#/definitions/addressLine2" },
393
+ city: { $ref: "standards#/definitions/city" },
394
+ postalCode: { $ref: "standards#/definitions/postalCode" },
395
+ state: { $ref: "standards#/definitions/state" },
396
+ country: { $ref: "standards#/definitions/country" }
397
+ },
398
+ required: ["firstName", "lastName", "phone", "email", "addressLine1", "postalCode", "state", "country"]
399
+ }
400
+ }
401
+ };
402
+
403
+ // src/Schema/index.ts
404
+ var Schema = {
405
+ getStandardSchemaDefinition() {
406
+ return definition_default;
407
+ }
408
+ };
409
+ var Schema_default = Schema;
410
+
411
+ // src/Auth/index.ts
412
+ var import_jose = require("jose");
413
+ var import_util2 = __toESM(require("util"));
414
+
415
+ // src/enums/ErrorTypes.ts
416
+ var ErrorTypes_default = Object.freeze({
417
+ INVALID_TOKEN: "Invalid Token",
418
+ TOKEN_EXPIRED: "Token Expired",
419
+ INTERNAL_SERVER_ERROR: "Internal Server Error"
420
+ });
421
+
422
+ // src/Logger/index.ts
423
+ var import_util = __toESM(require("util"));
424
+ var Logger = {
425
+ logException: (functionName, error) => {
426
+ console.log(`Exception Occurred in Function: ${functionName}, Error: ${import_util.default.inspect(error)}`);
427
+ },
428
+ logError: (functionName, errorMessage) => {
429
+ console.log(`Error Occurred in Function: ${functionName}, Error: ${import_util.default.inspect(errorMessage)}`);
430
+ },
431
+ logMessage: (functionName, message) => {
432
+ console.log(`Message in Function: ${functionName}, Error: ${import_util.default.inspect(message)}`);
433
+ },
434
+ logInvalidPayload: (functionName, errorMessage) => {
435
+ console.log(`Invalid Payload received for Function: ${functionName}, Error: ${errorMessage}`);
436
+ }
437
+ };
438
+ var Logger_default = Logger;
439
+
440
+ // src/Utils/response.ts
441
+ var ResponseUtility = {
442
+ handleException: (functionName, error, res) => {
443
+ if (error.knownError) {
444
+ error.logError && Logger_default.logError(functionName, error);
445
+ res.status(error.status).json({
446
+ status: error.status,
447
+ error: error.error
448
+ });
449
+ } else {
450
+ Logger_default.logException(functionName, error);
451
+ res.status(500).json({
452
+ status: 500,
453
+ error: ErrorTypes_default.INTERNAL_SERVER_ERROR
454
+ });
455
+ }
456
+ },
457
+ generateResponse: (status, data, error) => {
458
+ return {
459
+ status,
460
+ data,
461
+ error
462
+ };
463
+ },
464
+ generateError: (status, error, knownError = true, logError = false) => {
465
+ return {
466
+ status,
467
+ error,
468
+ knownError,
469
+ logError
470
+ };
471
+ }
472
+ };
473
+ var response_default = ResponseUtility;
474
+
475
+ // src/Auth/index.ts
476
+ var AuthUtility = class {
477
+ secretToken;
478
+ maxTokenAge;
479
+ constructor({ secret, maxTokenAge = "30 days" }) {
480
+ this.secretToken = secret;
481
+ this.maxTokenAge = maxTokenAge;
482
+ }
483
+ async createToken(id, additionalData) {
484
+ const payload = {
485
+ id,
486
+ ...additionalData
487
+ };
488
+ const secretKey = Buffer.from(this.secretToken, "hex");
489
+ const token = await new import_jose.EncryptJWT(payload).setExpirationTime(this.maxTokenAge).setIssuedAt().setProtectedHeader({ alg: "dir", enc: "A256CBC-HS512" }).encrypt(secretKey);
490
+ return token;
491
+ }
492
+ async verifyToken(token) {
493
+ const secretKey = Buffer.from(this.secretToken, "hex");
494
+ const jwt = await (0, import_jose.jwtDecrypt)(token, secretKey, { maxTokenAge: this.maxTokenAge });
495
+ return jwt.payload;
496
+ }
497
+ AuthMiddleware() {
498
+ return async (req, res, next) => {
499
+ try {
500
+ const token = req.get("Authorization")?.split(" ")?.[1];
501
+ if (!token) {
502
+ throw new Error(ErrorTypes_default.INVALID_TOKEN);
503
+ }
504
+ const payload = await this.verifyToken(token);
505
+ res.locals.auth = payload;
506
+ next();
507
+ } catch (error) {
508
+ Logger_default.logError("AuthMiddleware", import_util2.default.inspect(error));
509
+ response_default.handleException("AuthMiddleware", response_default.generateError(401, ErrorTypes_default.TOKEN_EXPIRED), res);
510
+ }
511
+ };
512
+ }
513
+ };
514
+ var Auth_default = AuthUtility;
515
+
516
+ // src/Utils/fetch.ts
517
+ var Fetch = async (baseURL, endpoint, method = "GET", headers = {}, payload) => {
518
+ const options = {
519
+ method,
520
+ headers: {
521
+ "Content-Type": "application/json",
522
+ ...headers
523
+ }
524
+ };
525
+ if (method !== "GET" && payload) {
526
+ options.body = JSON.stringify(payload);
527
+ }
528
+ try {
529
+ const response = await fetch(`${baseURL}/${endpoint}`, options);
530
+ if (!response.ok) {
531
+ const errorBody = await response.json().catch(() => response.text());
532
+ throw {
533
+ status: response.status,
534
+ statusText: response.statusText,
535
+ error: errorBody ? errorBody : {
536
+ status: response.status,
537
+ error: response.statusText
538
+ }
539
+ };
540
+ }
541
+ const body = await response.json();
542
+ Logger_default.logMessage("Fetch", `API call successful: URL-${baseURL}/${endpoint}, Status- ${response.status}}`);
543
+ return {
544
+ status: response.status,
545
+ statusText: response.statusText,
546
+ data: body.data
547
+ };
548
+ } catch (err) {
549
+ Logger_default.logError("Fetch", `API call failed: URL-${baseURL}/${endpoint}, Status- ${err.status || 500}, Error- ${JSON.stringify(err.error, null, 2)}`);
550
+ throw {
551
+ status: err.status || 500,
552
+ statusText: err.statusText || "Internal Server Error",
553
+ error: err.error || {
554
+ status: err.status || 500,
555
+ error: err.statusText || "Something went wrong"
556
+ }
557
+ };
558
+ }
559
+ };
560
+ var fetch_default = Fetch;
561
+ // Annotate the CommonJS export names for ESM import in node:
562
+ 0 && (module.exports = {
563
+ Auth,
564
+ DynamoDB,
565
+ Fetch,
566
+ Logger,
567
+ ResponseUtility,
568
+ Schema
569
+ });