@koloseum/utils 0.2.21 → 0.2.22
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 +79 -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,85 @@ 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
|
+
// Set subdomain and port number for Authentication microservice
|
|
523
|
+
if (path.startsWith("auth")) {
|
|
524
|
+
subdomain = "auth.";
|
|
525
|
+
port = 5173;
|
|
526
|
+
path = path.replace("auth", "");
|
|
527
|
+
}
|
|
528
|
+
// Set subdomain and port number for Legal microservice
|
|
529
|
+
else if (path.startsWith("legal")) {
|
|
530
|
+
subdomain = "legal.";
|
|
531
|
+
port = 5174;
|
|
532
|
+
path = path.replace("legal", "");
|
|
533
|
+
}
|
|
534
|
+
// Set port number for 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
|
+
// Set port number for Players microservices
|
|
547
|
+
if (microserviceGroup === "players") {
|
|
548
|
+
if (path.startsWith("account"))
|
|
549
|
+
port = 5175;
|
|
550
|
+
if (path.startsWith("fgc"))
|
|
551
|
+
port = 5178;
|
|
552
|
+
if (path.startsWith("commerce"))
|
|
553
|
+
port = 5179;
|
|
554
|
+
}
|
|
555
|
+
// Set port number for Lounges microservices
|
|
556
|
+
if (microserviceGroup === "lounges") {
|
|
557
|
+
if (path.startsWith("branches"))
|
|
558
|
+
port = 5181;
|
|
559
|
+
if (path.startsWith("staff"))
|
|
560
|
+
port = 5182;
|
|
561
|
+
}
|
|
562
|
+
// Set port number for Backroom microservices
|
|
563
|
+
if (microserviceGroup === "backroom") {
|
|
564
|
+
if (path.startsWith("compliance"))
|
|
565
|
+
port = 5176;
|
|
566
|
+
if (path.startsWith("competitions"))
|
|
567
|
+
port = 5177;
|
|
568
|
+
if (path.startsWith("commerce"))
|
|
569
|
+
port = 5180;
|
|
570
|
+
if (path.startsWith("staff"))
|
|
571
|
+
port = 5183;
|
|
572
|
+
}
|
|
573
|
+
// Return redirect URL
|
|
574
|
+
return {
|
|
575
|
+
url: env === "production"
|
|
576
|
+
? `https://${microserviceGroup}.koloseum.ke/${path || ""}`
|
|
577
|
+
: `http://127.0.0.1:${port}/${path || ""}`
|
|
578
|
+
};
|
|
579
|
+
},
|
|
501
580
|
/**
|
|
502
581
|
* Generate a SuprSend notification inbox configuration object for a user.
|
|
503
582
|
* @param {string} userId - The user ID to generate the configuration for.
|