@koloseum/utils 0.2.19 → 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
@@ -715,20 +715,31 @@ export const Utility = {
715
715
  const roles = [];
716
716
  const rolePrefix = microserviceGroup === "backroom" ? "backroom" : microserviceGroup.slice(0, -1);
717
717
  for (const role of user.app_metadata.roles) {
718
- if (role === "player")
719
- continue;
718
+ if (role === "player") {
719
+ if (microserviceGroup === "players")
720
+ roles.push(role);
721
+ else
722
+ continue;
723
+ }
720
724
  if (role.startsWith(`${rolePrefix}_`))
721
725
  roles.push(role.replace(`${rolePrefix}_`, ""));
722
726
  }
723
727
  // Redirect to Players microservices if user does not have any roles for the microservice group
724
- 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
725
733
  return { redirect: { code: 307, url: playersUrl } };
734
+ }
726
735
  // Destructure role
727
736
  const [role] = roles;
728
- let isAuthorised = false;
729
- // Grant access if superuser or account microservice
737
+ // Define condition variables
738
+ const isPlayer = microserviceGroup === "players" && role === "player";
730
739
  const isSuperuser = (microserviceGroup === "backroom" || microserviceGroup === "lounges") && role === "superuser";
731
- 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")
732
743
  isAuthorised = true;
733
744
  // Evaluate access
734
745
  else if (microserviceGroup !== "players") {
@@ -1071,50 +1082,14 @@ export const Utility = {
1071
1082
  },
1072
1083
  {
1073
1084
  name: "KLSM",
1074
- description: "Management of KLSM store products and tracking of orders and payments.",
1085
+ description: "Management of game and console trades between users.",
1075
1086
  slug: "commerce",
1076
- features: [
1077
- {
1078
- name: "Sections",
1079
- description: "Manage store sections.",
1080
- slug: "sections"
1081
- },
1082
- {
1083
- name: "Products",
1084
- description: "Manage store products.",
1085
- slug: "products"
1086
- },
1087
- {
1088
- name: "Bundles",
1089
- description: "Manage store bundles.",
1090
- slug: "bundles"
1091
- },
1092
- {
1093
- name: "Inventory",
1094
- description: "Manage store inventory.",
1095
- slug: "inventory"
1096
- },
1097
- {
1098
- name: "Orders",
1099
- description: "Manage store orders.",
1100
- slug: "orders"
1101
- }
1102
- ],
1087
+ features: [],
1103
1088
  roles: [
1104
1089
  {
1105
1090
  name: "Commerce",
1106
1091
  slug: "commerce",
1107
1092
  root: true
1108
- },
1109
- {
1110
- name: "Storefront",
1111
- slug: "storefront",
1112
- featureSlugs: ["sections", "products", "bundles"]
1113
- },
1114
- {
1115
- name: "Warehouse",
1116
- slug: "warehouse",
1117
- featureSlugs: ["inventory", "orders"]
1118
1093
  }
1119
1094
  ]
1120
1095
  },
@@ -1141,21 +1116,60 @@ export const Utility = {
1141
1116
  root: true
1142
1117
  }
1143
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
1144
1128
  },
1145
1129
  {
1146
- name: "Account",
1147
- description: "Review Backroom account settings and preferences.",
1148
- 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",
1149
1140
  features: [
1150
1141
  {
1151
- name: "Access",
1152
- description: "Review access to Backroom microservices.",
1153
- slug: "access"
1142
+ name: "Home",
1143
+ description: "Learn more about the Savanna Circuit.",
1144
+ root: true
1154
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: [
1155
1164
  {
1156
1165
  name: "Notifications",
1157
- description: "Review and manage Backroom notification preferences.",
1166
+ description: "Review and manage notification preferences.",
1158
1167
  slug: "notifications"
1168
+ },
1169
+ {
1170
+ name: "Access",
1171
+ description: "Review access to various microservices.",
1172
+ slug: "access"
1159
1173
  }
1160
1174
  ],
1161
1175
  roles: null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koloseum/utils",
3
- "version": "0.2.19",
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",