@koloseum/utils 0.2.18 → 0.2.20

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 CHANGED
@@ -163,7 +163,7 @@ export declare const Utility: {
163
163
  isUserAuthorised: (supabase: SupabaseClient<Database>, user: UserWithCustomMetadata, options: {
164
164
  microserviceGroup: MicroserviceGroup;
165
165
  microservice: Microservice<MicroserviceGroup> | string;
166
- playersUrl: string;
166
+ playersUrl?: string;
167
167
  requestedPermission?: (role: string) => string;
168
168
  }) => Promise<{
169
169
  isAuthorised?: boolean;
package/dist/utils.js CHANGED
@@ -385,8 +385,13 @@ export const Utility = {
385
385
  // Validate base URL
386
386
  if (typeof base !== "string")
387
387
  return "";
388
+ // Format base URL
389
+ if (base === "/")
390
+ base = "";
391
+ if (base.charAt(base.length - 1) === "/")
392
+ base = base.slice(0, -1);
388
393
  // Return URL
389
- return `${base}${slug && typeof slug === "string" ? `/${slug}` : ""}`;
394
+ return `${base}${slug === "/" ? slug : typeof slug === "string" ? `/${slug}` : ""}`;
390
395
  },
391
396
  /**
392
397
  * Returns the parent URL for a given base URL.
@@ -710,20 +715,31 @@ export const Utility = {
710
715
  const roles = [];
711
716
  const rolePrefix = microserviceGroup === "backroom" ? "backroom" : microserviceGroup.slice(0, -1);
712
717
  for (const role of user.app_metadata.roles) {
713
- if (role === "player")
714
- continue;
718
+ if (role === "player") {
719
+ if (microserviceGroup === "players")
720
+ roles.push(role);
721
+ else
722
+ continue;
723
+ }
715
724
  if (role.startsWith(`${rolePrefix}_`))
716
725
  roles.push(role.replace(`${rolePrefix}_`, ""));
717
726
  }
718
727
  // Redirect to Players microservices if user does not have any roles for the microservice group
719
- if (roles.length === 0)
728
+ if (roles.length === 0 && microserviceGroup !== "players") {
729
+ // Return error if Players URL is not provided
730
+ if (!playersUrl)
731
+ return { error: Utility.customError(400, "Players URL is required.") };
732
+ // Redirect to Players microservices
720
733
  return { redirect: { code: 307, url: playersUrl } };
734
+ }
721
735
  // Destructure role
722
736
  const [role] = roles;
723
- let isAuthorised = false;
724
- // Grant access if superuser or account microservice
737
+ // Define condition variables
738
+ const isPlayer = microserviceGroup === "players" && role === "player";
725
739
  const isSuperuser = (microserviceGroup === "backroom" || microserviceGroup === "lounges") && role === "superuser";
726
- if (isSuperuser || microservice === "account")
740
+ let isAuthorised = false;
741
+ // Grant access if Player (accessing Players microservices), superuser, or account microservice
742
+ if (isPlayer || isSuperuser || microservice === "account")
727
743
  isAuthorised = true;
728
744
  // Evaluate access
729
745
  else if (microserviceGroup !== "players") {
@@ -1066,50 +1082,14 @@ export const Utility = {
1066
1082
  },
1067
1083
  {
1068
1084
  name: "KLSM",
1069
- description: "Management of KLSM store products and tracking of orders and payments.",
1085
+ description: "Management of game and console trades between users.",
1070
1086
  slug: "commerce",
1071
- features: [
1072
- {
1073
- name: "Sections",
1074
- description: "Manage store sections.",
1075
- slug: "sections"
1076
- },
1077
- {
1078
- name: "Products",
1079
- description: "Manage store products.",
1080
- slug: "products"
1081
- },
1082
- {
1083
- name: "Bundles",
1084
- description: "Manage store bundles.",
1085
- slug: "bundles"
1086
- },
1087
- {
1088
- name: "Inventory",
1089
- description: "Manage store inventory.",
1090
- slug: "inventory"
1091
- },
1092
- {
1093
- name: "Orders",
1094
- description: "Manage store orders.",
1095
- slug: "orders"
1096
- }
1097
- ],
1087
+ features: [],
1098
1088
  roles: [
1099
1089
  {
1100
1090
  name: "Commerce",
1101
1091
  slug: "commerce",
1102
1092
  root: true
1103
- },
1104
- {
1105
- name: "Storefront",
1106
- slug: "storefront",
1107
- featureSlugs: ["sections", "products", "bundles"]
1108
- },
1109
- {
1110
- name: "Warehouse",
1111
- slug: "warehouse",
1112
- featureSlugs: ["inventory", "orders"]
1113
1093
  }
1114
1094
  ]
1115
1095
  },
@@ -1136,21 +1116,60 @@ export const Utility = {
1136
1116
  root: true
1137
1117
  }
1138
1118
  ]
1119
+ }
1120
+ ],
1121
+ players: [
1122
+ {
1123
+ name: "Sessions",
1124
+ description: "Track your gaming sessions at registered lounges.",
1125
+ slug: "sessions",
1126
+ features: [],
1127
+ roles: null
1139
1128
  },
1140
1129
  {
1141
- name: "Account",
1142
- description: "Review Backroom account settings and preferences.",
1143
- slug: "account",
1130
+ name: "KLSM",
1131
+ description: "Trade used games and consoles with other users at affordable prices.",
1132
+ slug: "commerce",
1133
+ features: [],
1134
+ roles: null
1135
+ },
1136
+ {
1137
+ name: "Savanna FGC",
1138
+ description: "Check out the latest news and competitions from Savanna FGC.",
1139
+ slug: "fgc",
1144
1140
  features: [
1145
1141
  {
1146
- name: "Access",
1147
- description: "Review access to Backroom microservices.",
1148
- slug: "access"
1142
+ name: "Home",
1143
+ description: "Learn more about the Savanna Circuit.",
1144
+ root: true
1149
1145
  },
1146
+ {
1147
+ name: "Rules",
1148
+ description: "Review the rules and regulations of the Savanna Circuit.",
1149
+ slug: "rules"
1150
+ },
1151
+ {
1152
+ name: "Tournaments",
1153
+ description: "Review and join upcoming tournaments on the Savanna Circuit.",
1154
+ slug: "tournaments"
1155
+ }
1156
+ ],
1157
+ roles: null
1158
+ },
1159
+ {
1160
+ name: "Account",
1161
+ description: "Review Player account settings and preferences.",
1162
+ slug: "account",
1163
+ features: [
1150
1164
  {
1151
1165
  name: "Notifications",
1152
- description: "Review and manage Backroom notification preferences.",
1166
+ description: "Review and manage notification preferences.",
1153
1167
  slug: "notifications"
1168
+ },
1169
+ {
1170
+ name: "Access",
1171
+ description: "Review access to various microservices.",
1172
+ slug: "access"
1154
1173
  }
1155
1174
  ],
1156
1175
  roles: null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koloseum/utils",
3
- "version": "0.2.18",
3
+ "version": "0.2.20",
4
4
  "author": "Koloseum Technologies Limited",
5
5
  "type": "module",
6
6
  "description": "Utility logic for use across Koloseum web apps (TypeScript)",
@@ -38,7 +38,7 @@
38
38
  "validator": "^13.15.15"
39
39
  },
40
40
  "devDependencies": {
41
- "@koloseum/types": "^0.2.6",
41
+ "@koloseum/types": "^0.2.7",
42
42
  "@playwright/test": "^1.55.0",
43
43
  "@suprsend/web-components": "^0.4.0",
44
44
  "@types/sanitize-html": "^2.16.0",