@adventurelabs/scout-core 1.4.71 → 1.4.72

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.
@@ -1,4 +1,7 @@
1
1
  import { SupabaseClient } from "@supabase/supabase-js";
2
2
  import { Database } from "../types/supabase";
3
+ import { IWebResponseCompatible } from "../types/requests";
4
+ /** Deprecated */
3
5
  export declare function isEmailValidForLogin(email: string, approved_domains?: string[]): boolean;
4
6
  export declare function isCurrentUserPlatformSuperadmin(client: SupabaseClient<Database>): Promise<boolean>;
7
+ export declare function is_scout_email_valid(client: SupabaseClient<Database>, email: string): Promise<IWebResponseCompatible<boolean>>;
@@ -1,8 +1,11 @@
1
1
  import { validateEmail } from "./email";
2
+ import { IWebResponse } from "../types/requests";
2
3
  const APPROVED_DOMAINS = ["adventurelabs.earth", "conservaition.ai"];
4
+ /** Deprecated */
3
5
  export function isEmailValidForLogin(email, approved_domains = APPROVED_DOMAINS) {
4
6
  return (validateEmail(email) && isEmailFromApprovedDomain(email, approved_domains));
5
7
  }
8
+ /** Deprecated */
6
9
  function isEmailFromApprovedDomain(email, approved_domains = APPROVED_DOMAINS) {
7
10
  return approved_domains.filter((domain) => email.endsWith(domain)).length > 0;
8
11
  }
@@ -14,3 +17,12 @@ export async function isCurrentUserPlatformSuperadmin(client) {
14
17
  }
15
18
  return data === true;
16
19
  }
20
+ export async function is_scout_email_valid(client, email) {
21
+ const { data, error } = await client.rpc("is_scout_email_valid", {
22
+ p_email: email,
23
+ });
24
+ if (error) {
25
+ return IWebResponse.error(error.message).to_compatible();
26
+ }
27
+ return IWebResponse.success(data ?? false).to_compatible();
28
+ }
@@ -6,3 +6,5 @@ export declare function server_create_herd_invitation(herd_id: number, email: st
6
6
  export declare function accept_herd_invitations_for_current_user(invitation_ids: number[], supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
7
7
  export declare function server_get_herd_invitations_for_current_user(): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
8
8
  export declare function server_get_herd_invitations_by_herd(herd_id: number, supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
9
+ export declare function reject_herd_invitations_for_current_user(invitation_ids: number[], supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
10
+ export declare function server_revoke_herd_invitations(invitation_ids: number[], supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
@@ -45,3 +45,27 @@ export async function server_get_herd_invitations_by_herd(herd_id, supabaseClien
45
45
  }
46
46
  return IWebResponse.success(data ?? []).to_compatible();
47
47
  }
48
+ export async function reject_herd_invitations_for_current_user(invitation_ids, supabaseClient) {
49
+ if (invitation_ids.length === 0) {
50
+ return IWebResponse.error("At least one invitation id is required").to_compatible();
51
+ }
52
+ const supabase = supabaseClient ?? (await newServerClient());
53
+ const { data, error } = await supabase.rpc("reject_herd_invitations_for_current_user", { p_invitation_ids: invitation_ids });
54
+ if (error) {
55
+ return IWebResponse.error(error.message).to_compatible();
56
+ }
57
+ return IWebResponse.success(data ?? []).to_compatible();
58
+ }
59
+ export async function server_revoke_herd_invitations(invitation_ids, supabaseClient) {
60
+ if (invitation_ids.length === 0) {
61
+ return IWebResponse.error("At least one invitation id is required").to_compatible();
62
+ }
63
+ const supabase = supabaseClient ?? (await newServerClient());
64
+ const { data, error } = await supabase.rpc("revoke_herd_invitations", {
65
+ p_invitation_ids: invitation_ids,
66
+ });
67
+ if (error) {
68
+ return IWebResponse.error(error.message).to_compatible();
69
+ }
70
+ return IWebResponse.success(data ?? []).to_compatible();
71
+ }
@@ -8,3 +8,4 @@ export declare function server_get_users_with_herd_access(herd_id: number, supab
8
8
  export declare function server_upsert_user_with_role(herd_id: number, username: string, role: Role): Promise<IWebResponseCompatible<IUserAndRole | null>>;
9
9
  export type UserProfileUpdate = Database["public"]["Tables"]["users"]["Update"];
10
10
  export declare function update_user_profile(client: SupabaseClient<Database>, user_id: string, patch: UserProfileUpdate): Promise<IWebResponseCompatible<IUserProfileRow | null>>;
11
+ export declare function leave_herd_for_current_user(herd_id: number, supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IUserRolePerHerd | null>>;
@@ -89,3 +89,13 @@ export async function update_user_profile(client, user_id, patch) {
89
89
  }
90
90
  return IWebResponse.success(data).to_compatible();
91
91
  }
92
+ export async function leave_herd_for_current_user(herd_id, supabaseClient) {
93
+ const supabase = supabaseClient ?? (await newServerClient());
94
+ const { data, error } = await supabase.rpc("leave_herd_for_current_user", {
95
+ p_herd_id: herd_id,
96
+ });
97
+ if (error) {
98
+ return IWebResponse.error(error.message).to_compatible();
99
+ }
100
+ return IWebResponse.success(data).to_compatible();
101
+ }
@@ -3006,6 +3006,34 @@ export declare function useSupabase(): SupabaseClient<Database, "public", "publi
3006
3006
  Args: never;
3007
3007
  Returns: boolean;
3008
3008
  };
3009
+ is_scout_email_valid: {
3010
+ Args: {
3011
+ p_email: string;
3012
+ };
3013
+ Returns: boolean;
3014
+ };
3015
+ leave_herd_for_current_user: {
3016
+ Args: {
3017
+ p_herd_id: number;
3018
+ };
3019
+ Returns: {
3020
+ herd_id: number;
3021
+ id: number;
3022
+ inserted_at: string;
3023
+ lifecycle: Database["public"]["Enums"]["entity_lifecycle"];
3024
+ lifecycle_changed_at: string;
3025
+ lifecycle_changed_by: string | null;
3026
+ lifecycle_reason: string | null;
3027
+ role: Database["public"]["Enums"]["role"];
3028
+ user_id: string;
3029
+ };
3030
+ SetofOptions: {
3031
+ from: "*";
3032
+ to: "users_roles_per_herd";
3033
+ isOneToOne: true;
3034
+ isSetofReturn: false;
3035
+ };
3036
+ };
3009
3037
  load_api_keys: {
3010
3038
  Args: {
3011
3039
  id_of_device: number;
@@ -3107,10 +3135,54 @@ export declare function useSupabase(): SupabaseClient<Database, "public", "publi
3107
3135
  status: string;
3108
3136
  }[];
3109
3137
  };
3138
+ reject_herd_invitations_for_current_user: {
3139
+ Args: {
3140
+ p_invitation_ids: number[];
3141
+ };
3142
+ Returns: {
3143
+ accepted_at: string | null;
3144
+ created_at: string;
3145
+ email: string;
3146
+ expires_at: string | null;
3147
+ herd_id: number;
3148
+ id: number;
3149
+ invited_by: string;
3150
+ role: Database["public"]["Enums"]["role"];
3151
+ status: Database["public"]["Enums"]["herd_invitation_status"];
3152
+ }[];
3153
+ SetofOptions: {
3154
+ from: "*";
3155
+ to: "herd_invitations";
3156
+ isOneToOne: false;
3157
+ isSetofReturn: true;
3158
+ };
3159
+ };
3110
3160
  remove_rls_broadcast_triggers: {
3111
3161
  Args: never;
3112
3162
  Returns: undefined;
3113
3163
  };
3164
+ revoke_herd_invitations: {
3165
+ Args: {
3166
+ p_invitation_ids: number[];
3167
+ };
3168
+ Returns: {
3169
+ accepted_at: string | null;
3170
+ created_at: string;
3171
+ email: string;
3172
+ expires_at: string | null;
3173
+ herd_id: number;
3174
+ id: number;
3175
+ invited_by: string;
3176
+ role: Database["public"]["Enums"]["role"];
3177
+ status: Database["public"]["Enums"]["herd_invitation_status"];
3178
+ }[];
3179
+ SetofOptions: {
3180
+ from: "*";
3181
+ to: "herd_invitations";
3182
+ isOneToOne: false;
3183
+ isSetofReturn: true;
3184
+ };
3185
+ };
3114
3186
  revoke_pubsub_jwt_public_key: {
3115
3187
  Args: {
3116
3188
  p_kid: string;
@@ -3103,6 +3103,34 @@ export type Database = {
3103
3103
  Args: never;
3104
3104
  Returns: boolean;
3105
3105
  };
3106
+ is_scout_email_valid: {
3107
+ Args: {
3108
+ p_email: string;
3109
+ };
3110
+ Returns: boolean;
3111
+ };
3112
+ leave_herd_for_current_user: {
3113
+ Args: {
3114
+ p_herd_id: number;
3115
+ };
3116
+ Returns: {
3117
+ herd_id: number;
3118
+ id: number;
3119
+ inserted_at: string;
3120
+ lifecycle: Database["public"]["Enums"]["entity_lifecycle"];
3121
+ lifecycle_changed_at: string;
3122
+ lifecycle_changed_by: string | null;
3123
+ lifecycle_reason: string | null;
3124
+ role: Database["public"]["Enums"]["role"];
3125
+ user_id: string;
3126
+ };
3127
+ SetofOptions: {
3128
+ from: "*";
3129
+ to: "users_roles_per_herd";
3130
+ isOneToOne: true;
3131
+ isSetofReturn: false;
3132
+ };
3133
+ };
3106
3134
  load_api_keys: {
3107
3135
  Args: {
3108
3136
  id_of_device: number;
@@ -3204,10 +3232,54 @@ export type Database = {
3204
3232
  status: string;
3205
3233
  }[];
3206
3234
  };
3235
+ reject_herd_invitations_for_current_user: {
3236
+ Args: {
3237
+ p_invitation_ids: number[];
3238
+ };
3239
+ Returns: {
3240
+ accepted_at: string | null;
3241
+ created_at: string;
3242
+ email: string;
3243
+ expires_at: string | null;
3244
+ herd_id: number;
3245
+ id: number;
3246
+ invited_by: string;
3247
+ role: Database["public"]["Enums"]["role"];
3248
+ status: Database["public"]["Enums"]["herd_invitation_status"];
3249
+ }[];
3250
+ SetofOptions: {
3251
+ from: "*";
3252
+ to: "herd_invitations";
3253
+ isOneToOne: false;
3254
+ isSetofReturn: true;
3255
+ };
3256
+ };
3207
3257
  remove_rls_broadcast_triggers: {
3208
3258
  Args: never;
3209
3259
  Returns: undefined;
3210
3260
  };
3261
+ revoke_herd_invitations: {
3262
+ Args: {
3263
+ p_invitation_ids: number[];
3264
+ };
3265
+ Returns: {
3266
+ accepted_at: string | null;
3267
+ created_at: string;
3268
+ email: string;
3269
+ expires_at: string | null;
3270
+ herd_id: number;
3271
+ id: number;
3272
+ invited_by: string;
3273
+ role: Database["public"]["Enums"]["role"];
3274
+ status: Database["public"]["Enums"]["herd_invitation_status"];
3275
+ }[];
3276
+ SetofOptions: {
3277
+ from: "*";
3278
+ to: "herd_invitations";
3279
+ isOneToOne: false;
3280
+ isSetofReturn: true;
3281
+ };
3282
+ };
3211
3283
  revoke_pubsub_jwt_public_key: {
3212
3284
  Args: {
3213
3285
  p_kid: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.4.71",
3
+ "version": "1.4.72",
4
4
  "description": "Core utilities and helpers for Adventure Labs Scout applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",