@koloseum/utils 0.2.21 → 0.2.23
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.d.ts +10 -0
- package/dist/utils.js +106 -0
- package/package.json +1 -1
package/dist/utils.d.ts
CHANGED
|
@@ -136,6 +136,16 @@ export declare const Utility: {
|
|
|
136
136
|
* @returns The formatted pronoun, or `null` if the input is invalid
|
|
137
137
|
*/
|
|
138
138
|
getPronoun: (pronouns: PronounsItem | null, type: "subject" | "object" | "possessive" | "reflexive", sex?: Sex) => string | null;
|
|
139
|
+
/**
|
|
140
|
+
* Returns the redirect URL for a given URI.
|
|
141
|
+
* @param {string} uri - The URI to get the redirect URL for, i.e. `microserviceGroup:path` (e.g. `players:fgc/tournaments`)
|
|
142
|
+
* @param {"development" | "production"} env - The environment to use for the redirect URL; defaults to `production`
|
|
143
|
+
* @returns {string} An object with the redirect `url`, or an `error` if any occurs
|
|
144
|
+
*/
|
|
145
|
+
getRedirectUrl: (uri: string, env?: "development" | "production") => {
|
|
146
|
+
url?: string;
|
|
147
|
+
error?: CustomError;
|
|
148
|
+
};
|
|
139
149
|
/**
|
|
140
150
|
* Generate a SuprSend notification inbox configuration object for a user.
|
|
141
151
|
* @param {string} userId - The user ID to generate the configuration for.
|
package/dist/utils.js
CHANGED
|
@@ -498,6 +498,112 @@ export const Utility = {
|
|
|
498
498
|
// Return null
|
|
499
499
|
return null;
|
|
500
500
|
},
|
|
501
|
+
/**
|
|
502
|
+
* Returns the redirect URL for a given URI.
|
|
503
|
+
* @param {string} uri - The URI to get the redirect URL for, i.e. `microserviceGroup:path` (e.g. `players:fgc/tournaments`)
|
|
504
|
+
* @param {"development" | "production"} env - The environment to use for the redirect URL; defaults to `production`
|
|
505
|
+
* @returns {string} An object with the redirect `url`, or an `error` if any occurs
|
|
506
|
+
*/
|
|
507
|
+
getRedirectUrl: (uri, env = "production") => {
|
|
508
|
+
// Get microservice groups
|
|
509
|
+
const microserviceGroups = ["public", "players", "lounges", "backroom"];
|
|
510
|
+
// Extract microservice group and path from URI
|
|
511
|
+
let [microserviceGroup, path] = uri.split(":");
|
|
512
|
+
if (!microserviceGroup || !path)
|
|
513
|
+
return { error: Utility.customError(400, "URI is invalid.") };
|
|
514
|
+
if (!microserviceGroups.includes(microserviceGroup))
|
|
515
|
+
return { error: Utility.customError(400, "Microservice group is invalid.") };
|
|
516
|
+
// Initialise port number for local development
|
|
517
|
+
let port;
|
|
518
|
+
// Return redirect URL for Public microservices
|
|
519
|
+
if (microserviceGroup === "public") {
|
|
520
|
+
// Initialise subdomain for production
|
|
521
|
+
let subdomain = "";
|
|
522
|
+
// Handle Authentication microservice
|
|
523
|
+
if (path.startsWith("auth")) {
|
|
524
|
+
subdomain = "auth.";
|
|
525
|
+
port = 5173;
|
|
526
|
+
path = path.replace("auth", "");
|
|
527
|
+
}
|
|
528
|
+
// Handle Legal microservice
|
|
529
|
+
else if (path.startsWith("legal")) {
|
|
530
|
+
subdomain = "legal.";
|
|
531
|
+
port = 5174;
|
|
532
|
+
path = path.replace("legal", "");
|
|
533
|
+
}
|
|
534
|
+
// Handle Landing microservice
|
|
535
|
+
else if (path.startsWith("landing")) {
|
|
536
|
+
port = 5184;
|
|
537
|
+
path = path.replace("landing", "");
|
|
538
|
+
}
|
|
539
|
+
// Return redirect URL
|
|
540
|
+
return {
|
|
541
|
+
url: env === "production"
|
|
542
|
+
? `https://${subdomain}koloseum.ke${path || ""}`
|
|
543
|
+
: `http://127.0.0.1:${port}${path || ""}`
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
// Handle Players microservices
|
|
547
|
+
if (microserviceGroup === "players") {
|
|
548
|
+
if (path.startsWith("account")) {
|
|
549
|
+
port = 5175;
|
|
550
|
+
if (env === "development")
|
|
551
|
+
path = path.replace("account", "");
|
|
552
|
+
}
|
|
553
|
+
if (path.startsWith("fgc")) {
|
|
554
|
+
port = 5178;
|
|
555
|
+
if (env === "development")
|
|
556
|
+
path = path.replace("fgc", "");
|
|
557
|
+
}
|
|
558
|
+
if (path.startsWith("commerce")) {
|
|
559
|
+
port = 5179;
|
|
560
|
+
if (env === "development")
|
|
561
|
+
path = path.replace("commerce", "");
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
// Handle Lounges microservices
|
|
565
|
+
if (microserviceGroup === "lounges") {
|
|
566
|
+
if (path.startsWith("branches")) {
|
|
567
|
+
port = 5181;
|
|
568
|
+
if (env === "development")
|
|
569
|
+
path = path.replace("branches", "");
|
|
570
|
+
}
|
|
571
|
+
if (path.startsWith("staff")) {
|
|
572
|
+
port = 5182;
|
|
573
|
+
if (env === "development")
|
|
574
|
+
path = path.replace("staff", "");
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
// Handle Backroom microservices
|
|
578
|
+
if (microserviceGroup === "backroom") {
|
|
579
|
+
if (path.startsWith("compliance")) {
|
|
580
|
+
port = 5176;
|
|
581
|
+
if (env === "development")
|
|
582
|
+
path = path.replace("compliance", "");
|
|
583
|
+
}
|
|
584
|
+
if (path.startsWith("competitions")) {
|
|
585
|
+
port = 5177;
|
|
586
|
+
if (env === "development")
|
|
587
|
+
path = path.replace("competitions", "");
|
|
588
|
+
}
|
|
589
|
+
if (path.startsWith("commerce")) {
|
|
590
|
+
port = 5180;
|
|
591
|
+
if (env === "development")
|
|
592
|
+
path = path.replace("commerce", "");
|
|
593
|
+
}
|
|
594
|
+
if (path.startsWith("staff")) {
|
|
595
|
+
port = 5183;
|
|
596
|
+
if (env === "development")
|
|
597
|
+
path = path.replace("staff", "");
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
// Return redirect URL
|
|
601
|
+
return {
|
|
602
|
+
url: env === "production"
|
|
603
|
+
? `https://${microserviceGroup}.koloseum.ke/${path || ""}`
|
|
604
|
+
: `http://127.0.0.1:${port}${path || ""}`
|
|
605
|
+
};
|
|
606
|
+
},
|
|
501
607
|
/**
|
|
502
608
|
* Generate a SuprSend notification inbox configuration object for a user.
|
|
503
609
|
* @param {string} userId - The user ID to generate the configuration for.
|