@adventurelabs/scout-core 1.4.72 → 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.
- package/dist/helpers/herds.js +18 -17
- package/dist/helpers/invitations.d.ts +2 -2
- package/dist/helpers/users.d.ts +1 -0
- package/dist/helpers/users.js +11 -0
- package/dist/hooks/useScoutRefresh.js +5 -3
- package/dist/index.d.ts +1 -1
- package/dist/providers/ScoutRefreshProvider.d.ts +37 -12
- package/dist/types/db.d.ts +1 -0
- package/dist/types/supabase.d.ts +37 -12
- package/package.json +1 -1
package/dist/helpers/herds.js
CHANGED
|
@@ -25,14 +25,7 @@ export async function get_herds_with_location(client) {
|
|
|
25
25
|
data: null,
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
|
|
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 ?? "
|
|
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:
|
|
112
|
+
time_sent: endTime,
|
|
112
113
|
server_processing_time_ms: totalLoadTime,
|
|
113
114
|
};
|
|
114
115
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Database } from "../types/supabase";
|
|
2
|
-
import { IHerdInvitation, Role } from "../types/db";
|
|
2
|
+
import { IHerdInvitation, IHerdInvitationWithHerdSlug, Role } from "../types/db";
|
|
3
3
|
import { IWebResponseCompatible } from "../types/requests";
|
|
4
4
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
5
5
|
export declare function server_create_herd_invitation(herd_id: number, email: string, role: Role, expires_at?: string | null): Promise<IWebResponseCompatible<IHerdInvitation | null>>;
|
|
6
6
|
export declare function accept_herd_invitations_for_current_user(invitation_ids: number[], supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
|
|
7
|
-
export declare function server_get_herd_invitations_for_current_user(): Promise<IWebResponseCompatible<
|
|
7
|
+
export declare function server_get_herd_invitations_for_current_user(): Promise<IWebResponseCompatible<IHerdInvitationWithHerdSlug[]>>;
|
|
8
8
|
export declare function server_get_herd_invitations_by_herd(herd_id: number, supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
|
|
9
9
|
export declare function reject_herd_invitations_for_current_user(invitation_ids: number[], supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
|
|
10
10
|
export declare function server_revoke_herd_invitations(invitation_ids: number[], supabaseClient?: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
|
package/dist/helpers/users.d.ts
CHANGED
|
@@ -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>>;
|
package/dist/helpers/users.js
CHANGED
|
@@ -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.
|
|
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 (
|
|
302
|
+
if (herdModulesResponse.status !== EnumWebResponse.SUCCESS ||
|
|
301
303
|
!Array.isArray(herdModulesResponse.data)) {
|
|
302
304
|
throw new Error("Invalid herd modules response");
|
|
303
305
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -76,5 +76,5 @@ export * from "./supabase/middleware";
|
|
|
76
76
|
export * from "./supabase/server";
|
|
77
77
|
export * from "./api_keys/actions";
|
|
78
78
|
export type { HerdModule, IHerdModule } from "./types/herd_module";
|
|
79
|
-
export type { IDevice, IEvent, IUser, IHerd, IHerdPrettyLocation, IEventWithTags, IZoneWithActions, ICredential, CredentialInsert, CredentialUpdate, ICertificate, CertificateInsert, CertificateUpdate, IUserAndRole, IUserProfileRow, IHerdInvitation, IHerdAllowedDomain, IUserRolePerHerd, HerdInvitationStatus, IApiKeyScout, ILayer, IHeartbeat, IProvider, IConnectivity, ISession, ISessionWithCoordinates, IConnectivityWithCoordinates, IObservation, ObservationInsert, ObservationUpdate, IAnalysisJob, IAnalysisTask, AnalysisWorkStatus, } from "./types/db";
|
|
79
|
+
export type { IDevice, IEvent, IUser, IHerd, IHerdPrettyLocation, IEventWithTags, IZoneWithActions, ICredential, CredentialInsert, CredentialUpdate, ICertificate, CertificateInsert, CertificateUpdate, IUserAndRole, IUserProfileRow, IHerdInvitation, IHerdInvitationWithHerdSlug, IHerdAllowedDomain, IUserRolePerHerd, HerdInvitationStatus, IApiKeyScout, ILayer, IHeartbeat, IProvider, IConnectivity, ISession, ISessionWithCoordinates, IConnectivityWithCoordinates, IObservation, ObservationInsert, ObservationUpdate, IAnalysisJob, IAnalysisTask, AnalysisWorkStatus, } from "./types/db";
|
|
80
80
|
export { EnumSessionsVisibility } from "./types/events";
|
|
@@ -2665,20 +2665,10 @@ export declare function useSupabase(): SupabaseClient<Database, "public", "publi
|
|
|
2665
2665
|
};
|
|
2666
2666
|
get_herd_invitations_for_current_user: {
|
|
2667
2667
|
Args: never;
|
|
2668
|
-
Returns:
|
|
2669
|
-
accepted_at: string | null;
|
|
2670
|
-
created_at: string;
|
|
2671
|
-
email: string;
|
|
2672
|
-
expires_at: string | null;
|
|
2673
|
-
herd_id: number;
|
|
2674
|
-
id: number;
|
|
2675
|
-
invited_by: string;
|
|
2676
|
-
role: Database["public"]["Enums"]["role"];
|
|
2677
|
-
status: Database["public"]["Enums"]["herd_invitation_status"];
|
|
2678
|
-
}[];
|
|
2668
|
+
Returns: Database["public"]["CompositeTypes"]["herd_invitation_with_herd_slug"][];
|
|
2679
2669
|
SetofOptions: {
|
|
2680
2670
|
from: "*";
|
|
2681
|
-
to: "
|
|
2671
|
+
to: "herd_invitation_with_herd_slug";
|
|
2682
2672
|
isOneToOne: false;
|
|
2683
2673
|
isSetofReturn: true;
|
|
2684
2674
|
};
|
|
@@ -3034,6 +3024,29 @@ export declare function useSupabase(): SupabaseClient<Database, "public", "publi
|
|
|
3034
3024
|
isSetofReturn: false;
|
|
3035
3025
|
};
|
|
3036
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
|
+
};
|
|
3037
3050
|
load_api_keys: {
|
|
3038
3051
|
Args: {
|
|
3039
3052
|
id_of_device: number;
|
|
@@ -3391,6 +3404,18 @@ export declare function useSupabase(): SupabaseClient<Database, "public", "publi
|
|
|
3391
3404
|
event_data: Database["public"]["CompositeTypes"]["event_and_tags_pretty_location"] | null;
|
|
3392
3405
|
artifact_data: Database["public"]["Tables"]["artifacts"]["Row"] | null;
|
|
3393
3406
|
};
|
|
3407
|
+
herd_invitation_with_herd_slug: {
|
|
3408
|
+
id: number | null;
|
|
3409
|
+
email: string | null;
|
|
3410
|
+
herd_id: number | null;
|
|
3411
|
+
role: Database["public"]["Enums"]["role"] | null;
|
|
3412
|
+
invited_by: string | null;
|
|
3413
|
+
status: Database["public"]["Enums"]["herd_invitation_status"] | null;
|
|
3414
|
+
created_at: string | null;
|
|
3415
|
+
accepted_at: string | null;
|
|
3416
|
+
expires_at: string | null;
|
|
3417
|
+
herd_slug: string | null;
|
|
3418
|
+
};
|
|
3394
3419
|
herds_pretty_location: {
|
|
3395
3420
|
id: number | null;
|
|
3396
3421
|
inserted_at: string | null;
|
package/dist/types/db.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export type IAction = Database["public"]["Tables"]["actions"]["Row"];
|
|
|
28
28
|
export type IZone = Database["public"]["Tables"]["zones"]["Row"];
|
|
29
29
|
export type IUserRolePerHerd = Database["public"]["Tables"]["users_roles_per_herd"]["Row"];
|
|
30
30
|
export type IHerdInvitation = Database["public"]["Tables"]["herd_invitations"]["Row"];
|
|
31
|
+
export type IHerdInvitationWithHerdSlug = Database["public"]["CompositeTypes"]["herd_invitation_with_herd_slug"];
|
|
31
32
|
export type IHerdAllowedDomain = Database["public"]["Tables"]["herd_allowed_domains"]["Row"];
|
|
32
33
|
export type HerdInvitationStatus = Database["public"]["Enums"]["herd_invitation_status"];
|
|
33
34
|
export type IHerd = Database["public"]["Tables"]["herds"]["Row"];
|
package/dist/types/supabase.d.ts
CHANGED
|
@@ -2762,20 +2762,10 @@ export type Database = {
|
|
|
2762
2762
|
};
|
|
2763
2763
|
get_herd_invitations_for_current_user: {
|
|
2764
2764
|
Args: never;
|
|
2765
|
-
Returns:
|
|
2766
|
-
accepted_at: string | null;
|
|
2767
|
-
created_at: string;
|
|
2768
|
-
email: string;
|
|
2769
|
-
expires_at: string | null;
|
|
2770
|
-
herd_id: number;
|
|
2771
|
-
id: number;
|
|
2772
|
-
invited_by: string;
|
|
2773
|
-
role: Database["public"]["Enums"]["role"];
|
|
2774
|
-
status: Database["public"]["Enums"]["herd_invitation_status"];
|
|
2775
|
-
}[];
|
|
2765
|
+
Returns: Database["public"]["CompositeTypes"]["herd_invitation_with_herd_slug"][];
|
|
2776
2766
|
SetofOptions: {
|
|
2777
2767
|
from: "*";
|
|
2778
|
-
to: "
|
|
2768
|
+
to: "herd_invitation_with_herd_slug";
|
|
2779
2769
|
isOneToOne: false;
|
|
2780
2770
|
isSetofReturn: true;
|
|
2781
2771
|
};
|
|
@@ -3131,6 +3121,29 @@ export type Database = {
|
|
|
3131
3121
|
isSetofReturn: false;
|
|
3132
3122
|
};
|
|
3133
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
|
+
};
|
|
3134
3147
|
load_api_keys: {
|
|
3135
3148
|
Args: {
|
|
3136
3149
|
id_of_device: number;
|
|
@@ -3488,6 +3501,18 @@ export type Database = {
|
|
|
3488
3501
|
event_data: Database["public"]["CompositeTypes"]["event_and_tags_pretty_location"] | null;
|
|
3489
3502
|
artifact_data: Database["public"]["Tables"]["artifacts"]["Row"] | null;
|
|
3490
3503
|
};
|
|
3504
|
+
herd_invitation_with_herd_slug: {
|
|
3505
|
+
id: number | null;
|
|
3506
|
+
email: string | null;
|
|
3507
|
+
herd_id: number | null;
|
|
3508
|
+
role: Database["public"]["Enums"]["role"] | null;
|
|
3509
|
+
invited_by: string | null;
|
|
3510
|
+
status: Database["public"]["Enums"]["herd_invitation_status"] | null;
|
|
3511
|
+
created_at: string | null;
|
|
3512
|
+
accepted_at: string | null;
|
|
3513
|
+
expires_at: string | null;
|
|
3514
|
+
herd_slug: string | null;
|
|
3515
|
+
};
|
|
3491
3516
|
herds_pretty_location: {
|
|
3492
3517
|
id: number | null;
|
|
3493
3518
|
inserted_at: string | null;
|