@adventurelabs/scout-core 1.4.73 → 1.4.74

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.
@@ -25,14 +25,7 @@ export async function get_herds_with_location(client) {
25
25
  data: null,
26
26
  };
27
27
  }
28
- if (!data) {
29
- return {
30
- status: EnumWebResponse.ERROR,
31
- msg: "No herds found",
32
- data: null,
33
- };
34
- }
35
- return IWebResponse.success(data).to_compatible();
28
+ return IWebResponse.success(data ?? []).to_compatible();
36
29
  }
37
30
  export async function get_herd_by_slug(slug) {
38
31
  const supabase = await newServerClient();
@@ -83,11 +76,10 @@ export async function server_load_herd_modules() {
83
76
  const client_supabase = await newServerClient();
84
77
  const herdsResult = await get_herds_with_location(client_supabase);
85
78
  if (herdsResult.status !== EnumWebResponse.SUCCESS ||
86
- !herdsResult.data ||
87
- herdsResult.data.length === 0) {
79
+ !herdsResult.data) {
88
80
  return {
89
81
  status: EnumWebResponse.ERROR,
90
- msg: herdsResult.msg ?? "No herds found",
82
+ msg: herdsResult.msg ?? "Failed to load herds",
91
83
  data: null,
92
84
  time_finished: Date.now(),
93
85
  time_sent: Date.now(),
@@ -95,20 +87,29 @@ export async function server_load_herd_modules() {
95
87
  };
96
88
  }
97
89
  const herds = herdsResult.data.filter((h) => h.id != null);
98
- let new_herd_modules = [];
99
- const herdModulePromises = herds.map((herd) => HerdModule.from_herd(herd, client_supabase));
100
- new_herd_modules = await Promise.all(herdModulePromises);
101
- const serialized_herd_modules = new_herd_modules.map((herd_module) => herd_module.to_serializable());
102
90
  const endTime = Date.now();
103
91
  const totalLoadTime = endTime - startTime;
92
+ if (herds.length === 0) {
93
+ console.log(`[server_load_herd_modules] No accessible herds (${totalLoadTime}ms)`);
94
+ return {
95
+ status: EnumWebResponse.SUCCESS,
96
+ msg: "No herds accessible",
97
+ data: [],
98
+ time_finished: endTime,
99
+ time_sent: endTime,
100
+ server_processing_time_ms: totalLoadTime,
101
+ };
102
+ }
103
+ const herdModulePromises = herds.map((herd) => HerdModule.from_herd(herd, client_supabase));
104
+ const new_herd_modules = await Promise.all(herdModulePromises);
105
+ const serialized_herd_modules = new_herd_modules.map((herd_module) => herd_module.to_serializable());
104
106
  console.log(`[server_load_herd_modules] Loaded ${herds.length} herds in ${totalLoadTime}ms (parallel processing)`);
105
- const timeSent = Date.now();
106
107
  return {
107
108
  status: EnumWebResponse.SUCCESS,
108
109
  msg: "Herd modules loaded successfully",
109
110
  data: serialized_herd_modules,
110
111
  time_finished: endTime,
111
- time_sent: timeSent,
112
+ time_sent: endTime,
112
113
  server_processing_time_ms: totalLoadTime,
113
114
  };
114
115
  }
@@ -9,3 +9,4 @@ export declare function server_upsert_user_with_role(herd_id: number, username:
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
11
  export declare function leave_herd_for_current_user(herd_id: number, supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IUserRolePerHerd | null>>;
12
+ export declare function remove_user_from_herd_for_admin(herd_id: number, user_id: string, supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IUserRolePerHerd | null>>;
@@ -99,3 +99,14 @@ export async function leave_herd_for_current_user(herd_id, supabaseClient) {
99
99
  }
100
100
  return IWebResponse.success(data).to_compatible();
101
101
  }
102
+ export async function remove_user_from_herd_for_admin(herd_id, user_id, supabaseClient) {
103
+ const supabase = supabaseClient ?? (await newServerClient());
104
+ const { data, error } = await supabase.rpc("remove_user_from_herd_for_admin", {
105
+ p_herd_id: herd_id,
106
+ p_user_id: user_id,
107
+ });
108
+ if (error) {
109
+ return IWebResponse.error(error.message).to_compatible();
110
+ }
111
+ return IWebResponse.success(data).to_compatible();
112
+ }
@@ -6,6 +6,7 @@ import { EnumHerdModulesLoadingState } from "../types/herd_module";
6
6
  import { server_load_herd_modules } from "../helpers/herds";
7
7
  import { scoutCache } from "../helpers/cache";
8
8
  import { EnumDataSource } from "../types/data_source";
9
+ import { EnumWebResponse } from "../types/requests";
9
10
  import { createBrowserClient } from "@supabase/ssr";
10
11
  /**
11
12
  * Hook for refreshing scout data with detailed timing measurements and cache-first loading
@@ -185,7 +186,8 @@ export function useScoutRefresh(options = {}) {
185
186
  }
186
187
  const backgroundUserResult = await userPromise;
187
188
  // Validate background responses
188
- if (backgroundHerdModulesResult.data &&
189
+ if (backgroundHerdModulesResult.status ===
190
+ EnumWebResponse.SUCCESS &&
189
191
  Array.isArray(backgroundHerdModulesResult.data) &&
190
192
  backgroundUserResult) {
191
193
  // Update cache with fresh data
@@ -295,9 +297,9 @@ export function useScoutRefresh(options = {}) {
295
297
  // Dispatch timing actions
296
298
  dispatch(setHerdModulesApiServerProcessingDuration(herdModulesServerDuration));
297
299
  dispatch(setHerdModulesApiTotalRequestDuration(herdModulesTotalDuration));
298
- // Validate API responses
300
+ // Validate API responses
299
301
  const validationStartTime = Date.now();
300
- if (!herdModulesResponse.data ||
302
+ if (herdModulesResponse.status !== EnumWebResponse.SUCCESS ||
301
303
  !Array.isArray(herdModulesResponse.data)) {
302
304
  throw new Error("Invalid herd modules response");
303
305
  }
@@ -3024,6 +3024,29 @@ export declare function useSupabase(): SupabaseClient<Database, "public", "publi
3024
3024
  isSetofReturn: false;
3025
3025
  };
3026
3026
  };
3027
+ remove_user_from_herd_for_admin: {
3028
+ Args: {
3029
+ p_herd_id: number;
3030
+ p_user_id: string;
3031
+ };
3032
+ Returns: {
3033
+ herd_id: number;
3034
+ id: number;
3035
+ inserted_at: string;
3036
+ lifecycle: Database["public"]["Enums"]["entity_lifecycle"];
3037
+ lifecycle_changed_at: string;
3038
+ lifecycle_changed_by: string | null;
3039
+ lifecycle_reason: string | null;
3040
+ role: Database["public"]["Enums"]["role"];
3041
+ user_id: string;
3042
+ };
3043
+ SetofOptions: {
3044
+ from: "*";
3045
+ to: "users_roles_per_herd";
3046
+ isOneToOne: true;
3047
+ isSetofReturn: false;
3048
+ };
3049
+ };
3027
3050
  load_api_keys: {
3028
3051
  Args: {
3029
3052
  id_of_device: number;
@@ -3121,6 +3121,29 @@ export type Database = {
3121
3121
  isSetofReturn: false;
3122
3122
  };
3123
3123
  };
3124
+ remove_user_from_herd_for_admin: {
3125
+ Args: {
3126
+ p_herd_id: number;
3127
+ p_user_id: string;
3128
+ };
3129
+ Returns: {
3130
+ herd_id: number;
3131
+ id: number;
3132
+ inserted_at: string;
3133
+ lifecycle: Database["public"]["Enums"]["entity_lifecycle"];
3134
+ lifecycle_changed_at: string;
3135
+ lifecycle_changed_by: string | null;
3136
+ lifecycle_reason: string | null;
3137
+ role: Database["public"]["Enums"]["role"];
3138
+ user_id: string;
3139
+ };
3140
+ SetofOptions: {
3141
+ from: "*";
3142
+ to: "users_roles_per_herd";
3143
+ isOneToOne: true;
3144
+ isSetofReturn: false;
3145
+ };
3146
+ };
3124
3147
  load_api_keys: {
3125
3148
  Args: {
3126
3149
  id_of_device: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.4.73",
3
+ "version": "1.4.74",
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",