@koloseum/utils 0.2.22 → 0.2.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.
- package/dist/utils.js +98 -47
- package/package.json +1 -1
package/dist/utils.js
CHANGED
|
@@ -107,35 +107,38 @@ export const Utility = {
|
|
|
107
107
|
// Define context
|
|
108
108
|
const context = {};
|
|
109
109
|
// Define error code and message
|
|
110
|
-
const code = Number(error.context
|
|
111
|
-
let message = error.context
|
|
112
|
-
? Status.ERROR
|
|
113
|
-
: error.context.statusText || Status.ERROR;
|
|
110
|
+
const code = Number(error.context?.status) || 500;
|
|
111
|
+
let message = error.context?.statusText || Status.ERROR;
|
|
114
112
|
// Handle HTTP errors
|
|
115
113
|
if (error instanceof FunctionsHttpError) {
|
|
116
|
-
// Get error data
|
|
117
114
|
try {
|
|
118
|
-
// Get content type header
|
|
119
|
-
const contentType = error.context
|
|
115
|
+
// Get content type header safely
|
|
116
|
+
const contentType = error.context?.headers?.get("content-type") || "";
|
|
120
117
|
// If content type is JSON, get error data
|
|
121
118
|
if (contentType.includes("application/json")) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
try {
|
|
120
|
+
const errorData = await error.context.json();
|
|
121
|
+
message = errorData.message || message;
|
|
122
|
+
// Assign attempt ID to context if present
|
|
123
|
+
if (path.includes("verify-id") && errorData.attemptId)
|
|
124
|
+
context.attemptId = errorData.attemptId;
|
|
125
|
+
}
|
|
126
|
+
catch (jsonError) {
|
|
127
|
+
console.error("Failed to parse JSON error response:", jsonError);
|
|
128
|
+
}
|
|
126
129
|
}
|
|
127
130
|
// If content type is plain text, get error message
|
|
128
|
-
else if (contentType.includes("text/plain"))
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
else if (contentType.includes("text/plain")) {
|
|
132
|
+
try {
|
|
133
|
+
message = await error.context.text();
|
|
134
|
+
}
|
|
135
|
+
catch (textError) {
|
|
136
|
+
console.error("Failed to parse text error response:", textError);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
136
139
|
}
|
|
137
|
-
catch {
|
|
138
|
-
|
|
140
|
+
catch (parseError) {
|
|
141
|
+
console.error("Failed to parse error response:", parseError);
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
// Handle relay and fetch errors
|
|
@@ -147,7 +150,8 @@ export const Utility = {
|
|
|
147
150
|
// Return response
|
|
148
151
|
return { code: 200, data };
|
|
149
152
|
}
|
|
150
|
-
catch {
|
|
153
|
+
catch (unexpectedError) {
|
|
154
|
+
console.error("Unexpected error:", unexpectedError);
|
|
151
155
|
return { code: 500, error: Status.ERROR };
|
|
152
156
|
}
|
|
153
157
|
},
|
|
@@ -519,19 +523,19 @@ export const Utility = {
|
|
|
519
523
|
if (microserviceGroup === "public") {
|
|
520
524
|
// Initialise subdomain for production
|
|
521
525
|
let subdomain = "";
|
|
522
|
-
//
|
|
526
|
+
// Handle Authentication microservice
|
|
523
527
|
if (path.startsWith("auth")) {
|
|
524
528
|
subdomain = "auth.";
|
|
525
529
|
port = 5173;
|
|
526
530
|
path = path.replace("auth", "");
|
|
527
531
|
}
|
|
528
|
-
//
|
|
532
|
+
// Handle Legal microservice
|
|
529
533
|
else if (path.startsWith("legal")) {
|
|
530
534
|
subdomain = "legal.";
|
|
531
535
|
port = 5174;
|
|
532
536
|
path = path.replace("legal", "");
|
|
533
537
|
}
|
|
534
|
-
//
|
|
538
|
+
// Handle Landing microservice
|
|
535
539
|
else if (path.startsWith("landing")) {
|
|
536
540
|
port = 5184;
|
|
537
541
|
path = path.replace("landing", "");
|
|
@@ -543,38 +547,65 @@ export const Utility = {
|
|
|
543
547
|
: `http://127.0.0.1:${port}${path || ""}`
|
|
544
548
|
};
|
|
545
549
|
}
|
|
546
|
-
//
|
|
550
|
+
// Handle Players microservices
|
|
547
551
|
if (microserviceGroup === "players") {
|
|
548
|
-
if (path.startsWith("account"))
|
|
552
|
+
if (path.startsWith("account")) {
|
|
549
553
|
port = 5175;
|
|
550
|
-
|
|
554
|
+
if (env === "development")
|
|
555
|
+
path = path.replace("account", "");
|
|
556
|
+
}
|
|
557
|
+
if (path.startsWith("fgc")) {
|
|
551
558
|
port = 5178;
|
|
552
|
-
|
|
559
|
+
if (env === "development")
|
|
560
|
+
path = path.replace("fgc", "");
|
|
561
|
+
}
|
|
562
|
+
if (path.startsWith("commerce")) {
|
|
553
563
|
port = 5179;
|
|
564
|
+
if (env === "development")
|
|
565
|
+
path = path.replace("commerce", "");
|
|
566
|
+
}
|
|
554
567
|
}
|
|
555
|
-
//
|
|
568
|
+
// Handle Lounges microservices
|
|
556
569
|
if (microserviceGroup === "lounges") {
|
|
557
|
-
if (path.startsWith("branches"))
|
|
570
|
+
if (path.startsWith("branches")) {
|
|
558
571
|
port = 5181;
|
|
559
|
-
|
|
572
|
+
if (env === "development")
|
|
573
|
+
path = path.replace("branches", "");
|
|
574
|
+
}
|
|
575
|
+
if (path.startsWith("staff")) {
|
|
560
576
|
port = 5182;
|
|
577
|
+
if (env === "development")
|
|
578
|
+
path = path.replace("staff", "");
|
|
579
|
+
}
|
|
561
580
|
}
|
|
562
|
-
//
|
|
581
|
+
// Handle Backroom microservices
|
|
563
582
|
if (microserviceGroup === "backroom") {
|
|
564
|
-
if (path.startsWith("compliance"))
|
|
583
|
+
if (path.startsWith("compliance")) {
|
|
565
584
|
port = 5176;
|
|
566
|
-
|
|
585
|
+
if (env === "development")
|
|
586
|
+
path = path.replace("compliance", "");
|
|
587
|
+
}
|
|
588
|
+
if (path.startsWith("competitions")) {
|
|
567
589
|
port = 5177;
|
|
568
|
-
|
|
590
|
+
if (env === "development")
|
|
591
|
+
path = path.replace("competitions", "");
|
|
592
|
+
}
|
|
593
|
+
if (path.startsWith("commerce")) {
|
|
569
594
|
port = 5180;
|
|
570
|
-
|
|
595
|
+
if (env === "development")
|
|
596
|
+
path = path.replace("commerce", "");
|
|
597
|
+
}
|
|
598
|
+
if (path.startsWith("staff")) {
|
|
571
599
|
port = 5183;
|
|
600
|
+
if (env === "development")
|
|
601
|
+
path = path.replace("staff", "");
|
|
602
|
+
}
|
|
572
603
|
}
|
|
573
604
|
// Return redirect URL
|
|
574
605
|
return {
|
|
575
606
|
url: env === "production"
|
|
576
607
|
? `https://${microserviceGroup}.koloseum.ke/${path || ""}`
|
|
577
|
-
: `http://127.0.0.1:${port}
|
|
608
|
+
: `http://127.0.0.1:${port}${path || ""}`
|
|
578
609
|
};
|
|
579
610
|
},
|
|
580
611
|
/**
|
|
@@ -833,7 +864,7 @@ export const Utility = {
|
|
|
833
864
|
.rpc("authorise", { requested_permission: requestedPermission });
|
|
834
865
|
if (isAuthorisedError)
|
|
835
866
|
return Utility.parsePostgrestError(isAuthorisedError);
|
|
836
|
-
//
|
|
867
|
+
// Assign result of authorisation check
|
|
837
868
|
isAuthorised = data;
|
|
838
869
|
}
|
|
839
870
|
// Validate SuprSend subscriber
|
|
@@ -1240,15 +1271,35 @@ export const Utility = {
|
|
|
1240
1271
|
description: "Review Player account settings and preferences.",
|
|
1241
1272
|
slug: "account",
|
|
1242
1273
|
features: [
|
|
1274
|
+
{
|
|
1275
|
+
name: "Personal",
|
|
1276
|
+
description: "Review and manage your personal information.",
|
|
1277
|
+
slug: "personal"
|
|
1278
|
+
},
|
|
1279
|
+
{
|
|
1280
|
+
name: "Gaming and socials",
|
|
1281
|
+
description: "Review and manage your gaming and social media information.",
|
|
1282
|
+
slug: "gaming-socials"
|
|
1283
|
+
},
|
|
1243
1284
|
{
|
|
1244
1285
|
name: "Notifications",
|
|
1245
|
-
description: "Review and manage notification preferences.",
|
|
1286
|
+
description: "Review and manage your notification preferences.",
|
|
1246
1287
|
slug: "notifications"
|
|
1247
1288
|
},
|
|
1248
1289
|
{
|
|
1249
|
-
name: "
|
|
1250
|
-
description: "Review
|
|
1251
|
-
slug: "
|
|
1290
|
+
name: "Security",
|
|
1291
|
+
description: "Review and manage your security preferences.",
|
|
1292
|
+
slug: "security"
|
|
1293
|
+
},
|
|
1294
|
+
{
|
|
1295
|
+
name: "Lounges",
|
|
1296
|
+
description: "Review your access to Lounges microservices.",
|
|
1297
|
+
slug: "lounges"
|
|
1298
|
+
},
|
|
1299
|
+
{
|
|
1300
|
+
name: "Backroom",
|
|
1301
|
+
description: "Review your access to Backroom microservices.",
|
|
1302
|
+
slug: "backroom"
|
|
1252
1303
|
}
|
|
1253
1304
|
],
|
|
1254
1305
|
roles: null
|
|
@@ -1322,13 +1373,13 @@ export const Utility = {
|
|
|
1322
1373
|
if (!interval)
|
|
1323
1374
|
return null;
|
|
1324
1375
|
// Parse interval and return in the specified format
|
|
1325
|
-
const
|
|
1376
|
+
const { toPostgres, toISOString, toISOStringShort } = parsePgInterval(interval);
|
|
1326
1377
|
if (type === "postgres")
|
|
1327
|
-
return
|
|
1378
|
+
return toPostgres();
|
|
1328
1379
|
if (type === "iso")
|
|
1329
|
-
return
|
|
1380
|
+
return toISOString();
|
|
1330
1381
|
if (type === "iso-short")
|
|
1331
|
-
return
|
|
1382
|
+
return toISOStringShort();
|
|
1332
1383
|
// Return null if type is invalid
|
|
1333
1384
|
return null;
|
|
1334
1385
|
},
|