@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.
Files changed (2) hide show
  1. package/dist/utils.js +98 -47
  2. 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.status) || 500;
111
- let message = error.context.statusText === "Internal Server Error"
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.headers.get("content-type");
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
- // Get error data
123
- const data = await error.context.json();
124
- // Assign error message
125
- message = data.message;
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
- message = await error.context.text();
130
- // If any other content type, use the status text
131
- else
132
- message = error.context.statusText;
133
- // Assign attempt ID to context if present
134
- if (path.includes("verify-id") && data.attemptId)
135
- context.attemptId = data.attemptId;
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
- return { code: 500, error: Status.ERROR };
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
- // Set subdomain and port number for Authentication microservice
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
- // Set subdomain and port number for Legal microservice
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
- // Set port number for Landing microservice
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
- // Set port number for Players microservices
550
+ // Handle Players microservices
547
551
  if (microserviceGroup === "players") {
548
- if (path.startsWith("account"))
552
+ if (path.startsWith("account")) {
549
553
  port = 5175;
550
- if (path.startsWith("fgc"))
554
+ if (env === "development")
555
+ path = path.replace("account", "");
556
+ }
557
+ if (path.startsWith("fgc")) {
551
558
  port = 5178;
552
- if (path.startsWith("commerce"))
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
- // Set port number for Lounges microservices
568
+ // Handle Lounges microservices
556
569
  if (microserviceGroup === "lounges") {
557
- if (path.startsWith("branches"))
570
+ if (path.startsWith("branches")) {
558
571
  port = 5181;
559
- if (path.startsWith("staff"))
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
- // Set port number for Backroom microservices
581
+ // Handle Backroom microservices
563
582
  if (microserviceGroup === "backroom") {
564
- if (path.startsWith("compliance"))
583
+ if (path.startsWith("compliance")) {
565
584
  port = 5176;
566
- if (path.startsWith("competitions"))
585
+ if (env === "development")
586
+ path = path.replace("compliance", "");
587
+ }
588
+ if (path.startsWith("competitions")) {
567
589
  port = 5177;
568
- if (path.startsWith("commerce"))
590
+ if (env === "development")
591
+ path = path.replace("competitions", "");
592
+ }
593
+ if (path.startsWith("commerce")) {
569
594
  port = 5180;
570
- if (path.startsWith("staff"))
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}/${path || ""}`
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
- // Grant access if user has the requested permission
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: "Access",
1250
- description: "Review access to various microservices.",
1251
- slug: "access"
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 parsed = parsePgInterval(interval);
1376
+ const { toPostgres, toISOString, toISOStringShort } = parsePgInterval(interval);
1326
1377
  if (type === "postgres")
1327
- return parsed.toPostgres();
1378
+ return toPostgres();
1328
1379
  if (type === "iso")
1329
- return parsed.toISOString();
1380
+ return toISOString();
1330
1381
  if (type === "iso-short")
1331
- return parsed.toISOStringShort();
1382
+ return toISOStringShort();
1332
1383
  // Return null if type is invalid
1333
1384
  return null;
1334
1385
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koloseum/utils",
3
- "version": "0.2.22",
3
+ "version": "0.2.24",
4
4
  "author": "Koloseum Technologies Limited",
5
5
  "type": "module",
6
6
  "description": "Utility logic for use across Koloseum web apps (TypeScript)",