@koloseum/utils 0.2.2 → 0.2.3

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
@@ -139,7 +139,7 @@ export declare const Utility: {
139
139
  microserviceGroup: MicroserviceGroup;
140
140
  microservice: Microservice<MicroserviceGroup> | string;
141
141
  playersUrl: string;
142
- requestedPermission: (role: string) => string;
142
+ requestedPermission?: (role: string) => string;
143
143
  }) => Promise<{
144
144
  isAuthorised?: boolean;
145
145
  redirect?: {
package/dist/utils.js CHANGED
@@ -619,6 +619,9 @@ export const Utility = {
619
619
  isAuthorised = true;
620
620
  // Evaluate access
621
621
  else if (microserviceGroup !== "players") {
622
+ // Return error if requested permission is not provided
623
+ if (!options.requestedPermission)
624
+ return { error: Utility.customError(400, "Requested permission is required.") };
622
625
  // Get user's role and requested app permission
623
626
  const requestedPermission = options.requestedPermission(role);
624
627
  // Check if user has the requested permission
@@ -639,20 +642,20 @@ export const Utility = {
639
642
  const { code, error: validationError } = await Utility.callEdgeFunction(false, supabase, `suprsend/validate-subscriber?user-id=${user.id}`, { method: "POST", body: personData });
640
643
  if (validationError)
641
644
  return { error: Utility.customError(code, validationError) };
642
- // Initialise user metadata if not already done
643
- if (!user.user_metadata.backroom) {
644
- // Update user metadata in database
645
- const { error: updateError } = await supabase.auth.updateUser({
646
- data: { backroom: { welcome_notification_sent: false } }
647
- });
648
- if (updateError)
649
- return { error: Utility.customError(updateError.status ?? 500, updateError.message) };
650
- // Update user object in memory
651
- user.user_metadata.backroom = { welcome_notification_sent: false };
652
- }
653
- // Send welcome notification if user is new
654
- if (!user.user_metadata.backroom.welcome_notification_sent) {
655
- // Define workflow body
645
+ // Send welcome notification if needed
646
+ if (!user.user_metadata.backroom || !user.user_metadata.backroom.welcome_notification_sent) {
647
+ // Initialise backroom metadata if it doesn't exist
648
+ if (!user.user_metadata.backroom) {
649
+ // Update user metadata in database
650
+ const { error: updateError } = await supabase.auth.updateUser({
651
+ data: { backroom: { welcome_notification_sent: false } }
652
+ });
653
+ if (updateError)
654
+ return { error: Utility.customError(updateError.status ?? 500, updateError.message) };
655
+ // Update user object in memory
656
+ user.user_metadata.backroom = { welcome_notification_sent: false };
657
+ }
658
+ // Define SuprSend workflow body
656
659
  const workflowBody = {
657
660
  name: "welcome-to-backroom",
658
661
  template: "welcome-to-backroom",
@@ -664,7 +667,7 @@ export const Utility = {
664
667
  }
665
668
  ]
666
669
  };
667
- // Trigger workflow
670
+ // Send welcome notification
668
671
  const { code, error: workflowError } = await Utility.callEdgeFunction(false, supabase, `suprsend/trigger-workflow?user-id=${user.id}`, { method: "POST", body: workflowBody });
669
672
  if (workflowError)
670
673
  return { error: Utility.customError(code, workflowError) };
@@ -692,7 +695,7 @@ export const Utility = {
692
695
  backroom: [
693
696
  {
694
697
  name: "Compliance",
695
- description: "Management of compliance and regulatory requirements for Players and Lounges.",
698
+ description: "Management of compliance and regulatory adherence for Players and Lounges.",
696
699
  slug: "compliance",
697
700
  features: [
698
701
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koloseum/utils",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "author": "Koloseum Technologies Limited",
5
5
  "type": "module",
6
6
  "description": "Utility logic for use across Koloseum web apps (TypeScript)",