@adventurelabs/scout-core 1.4.96 → 1.5.1
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/api_keys/actions.d.ts +1 -2
- package/dist/api_keys/actions.js +4 -83
- package/dist/api_keys/queries.d.ts +4 -0
- package/dist/api_keys/queries.js +52 -0
- package/dist/helpers/artifacts.d.ts +10 -15
- package/dist/helpers/artifacts.internal.d.ts +22 -0
- package/dist/helpers/artifacts.internal.js +151 -0
- package/dist/helpers/artifacts.js +48 -81
- package/dist/helpers/client_abilities_jwt_keys.d.ts +3 -4
- package/dist/helpers/client_abilities_jwt_keys.js +7 -7
- package/dist/helpers/client_abilities_jwt_keys_internal.d.ts +9 -0
- package/dist/helpers/client_abilities_jwt_keys_internal.js +20 -0
- package/dist/helpers/client_abilities_token_server.d.ts +1 -5
- package/dist/helpers/client_abilities_token_server.js +2 -2
- package/dist/helpers/connectivity.d.ts +2 -3
- package/dist/helpers/connectivity.internal.d.ts +10 -0
- package/dist/helpers/connectivity.internal.js +47 -0
- package/dist/helpers/connectivity.js +6 -7
- package/dist/helpers/devices.d.ts +1 -3
- package/dist/helpers/devices.js +3 -12
- package/dist/helpers/devices.queries.d.ts +5 -0
- package/dist/helpers/devices.queries.js +10 -0
- package/dist/helpers/documents.d.ts +1 -0
- package/dist/helpers/documents.js +11 -2
- package/dist/helpers/embeddings.d.ts +1 -3
- package/dist/helpers/embeddings.internal.d.ts +5 -0
- package/dist/helpers/embeddings.internal.js +14 -0
- package/dist/helpers/embeddings.js +2 -2
- package/dist/helpers/events.d.ts +4 -6
- package/dist/helpers/events.internal.d.ts +13 -0
- package/dist/helpers/events.internal.js +88 -0
- package/dist/helpers/events.js +16 -17
- package/dist/helpers/herd_allowed_domains.d.ts +1 -3
- package/dist/helpers/herd_allowed_domains.js +2 -2
- package/dist/helpers/herd_allowed_domains_internal.d.ts +5 -0
- package/dist/helpers/herd_allowed_domains_internal.js +12 -0
- package/dist/helpers/herd_modules.queries.d.ts +3 -0
- package/dist/helpers/herd_modules.queries.js +106 -0
- package/dist/helpers/herd_roles.d.ts +12 -14
- package/dist/helpers/herd_roles.js +26 -34
- package/dist/helpers/herd_roles_internal.d.ts +18 -0
- package/dist/helpers/herd_roles_internal.js +159 -0
- package/dist/helpers/herd_scoped.queries.d.ts +7 -0
- package/dist/helpers/herd_scoped.queries.js +45 -0
- package/dist/helpers/herds.d.ts +2 -4
- package/dist/helpers/herds.js +11 -142
- package/dist/helpers/herds.queries.d.ts +5 -0
- package/dist/helpers/herds.queries.js +12 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/invitations.d.ts +4 -6
- package/dist/helpers/invitations.js +8 -8
- package/dist/helpers/invitations_internal.d.ts +10 -0
- package/dist/helpers/invitations_internal.js +63 -0
- package/dist/helpers/layers.d.ts +1 -3
- package/dist/helpers/layers.js +3 -18
- package/dist/helpers/layers.queries.d.ts +5 -0
- package/dist/helpers/layers.queries.js +20 -0
- package/dist/helpers/operating_contexts.d.ts +43 -0
- package/dist/helpers/operating_contexts.js +222 -0
- package/dist/helpers/plans.d.ts +1 -3
- package/dist/helpers/plans.js +3 -18
- package/dist/helpers/plans.queries.d.ts +5 -0
- package/dist/helpers/plans.queries.js +20 -0
- package/dist/helpers/providers.d.ts +1 -3
- package/dist/helpers/providers.js +3 -18
- package/dist/helpers/providers.queries.d.ts +5 -0
- package/dist/helpers/providers.queries.js +20 -0
- package/dist/helpers/pubsub_token_server.d.ts +1 -5
- package/dist/helpers/pubsub_token_server.js +2 -2
- package/dist/helpers/realtime_topic_access.d.ts +5 -0
- package/dist/helpers/realtime_topic_access.js +55 -0
- package/dist/helpers/session_summaries.d.ts +3 -4
- package/dist/helpers/session_summaries.js +13 -43
- package/dist/helpers/session_summaries.queries.d.ts +14 -0
- package/dist/helpers/session_summaries.queries.js +19 -0
- package/dist/helpers/sessions.d.ts +7 -8
- package/dist/helpers/sessions.js +23 -58
- package/dist/helpers/sessions.queries.d.ts +4 -0
- package/dist/helpers/sessions.queries.js +22 -0
- package/dist/helpers/storage.d.ts +2 -4
- package/dist/helpers/storage.js +7 -54
- package/dist/helpers/storage_internal.d.ts +4 -0
- package/dist/helpers/storage_internal.js +29 -0
- package/dist/helpers/tags.js +5 -5
- package/dist/helpers/users.d.ts +7 -8
- package/dist/helpers/users.js +13 -41
- package/dist/helpers/users.queries.d.ts +5 -0
- package/dist/helpers/users.queries.js +30 -0
- package/dist/helpers/versions_software_internal.d.ts +6 -0
- package/dist/helpers/versions_software_internal.js +53 -0
- package/dist/helpers/versions_software_server.d.ts +2 -3
- package/dist/helpers/versions_software_server.js +20 -18
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js +2 -1
- package/dist/hooks/useAuthorizedRealtimeTopics.d.ts +1 -0
- package/dist/hooks/useAuthorizedRealtimeTopics.js +14 -0
- package/dist/hooks/useScoutRealtimeAnalysisJobs.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeAnalysisJobs.js +3 -5
- package/dist/hooks/useScoutRealtimeAnalysisTasks.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeAnalysisTasks.js +3 -5
- package/dist/hooks/useScoutRealtimeBroadcast.d.ts +9 -5
- package/dist/hooks/useScoutRealtimeBroadcast.js +118 -25
- package/dist/hooks/useScoutRealtimeConnectivity.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeConnectivity.js +18 -76
- package/dist/hooks/useScoutRealtimeContacts.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeContacts.js +3 -3
- package/dist/hooks/useScoutRealtimeDevices.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeDevices.js +3 -64
- package/dist/hooks/useScoutRealtimeDocuments.d.ts +3 -3
- package/dist/hooks/useScoutRealtimeDocuments.js +7 -5
- package/dist/hooks/useScoutRealtimeEvents.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeEvents.js +3 -69
- package/dist/hooks/useScoutRealtimeMaintenanceRequests.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeMaintenanceRequests.js +3 -3
- package/dist/hooks/useScoutRealtimeOperatingContexts.d.ts +12 -0
- package/dist/hooks/useScoutRealtimeOperatingContexts.js +26 -0
- package/dist/hooks/useScoutRealtimeParts.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeParts.js +3 -3
- package/dist/hooks/useScoutRealtimePins.d.ts +2 -1
- package/dist/hooks/useScoutRealtimePins.js +3 -69
- package/dist/hooks/useScoutRealtimePlans.d.ts +2 -1
- package/dist/hooks/useScoutRealtimePlans.js +3 -3
- package/dist/hooks/useScoutRealtimeSessionIncidents.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeSessionIncidents.js +3 -3
- package/dist/hooks/useScoutRealtimeSessions.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeSessions.js +3 -69
- package/dist/hooks/useScoutRealtimeTags.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeTags.js +3 -69
- package/dist/hooks/useScoutRealtimeVersionsSoftware.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeVersionsSoftware.js +3 -5
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/providers/ScoutRefreshProvider.d.ts +1 -0
- package/dist/providers/ScoutRefreshProvider.js +3 -0
- package/dist/supabase/server.d.ts +4 -1
- package/dist/supabase/server.js +6 -5
- package/dist/types/db.d.ts +82 -0
- package/dist/types/realtime.d.ts +1 -0
- package/dist/types/supabase.d.ts +952 -100
- package/dist/types/supabase.js +26 -1
- package/package.json +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
import { list_api_keys_batch_query } from "../api_keys/queries";
|
|
3
|
+
import { LABELS } from "../constants/annotator";
|
|
4
|
+
import { EnumWebResponse, } from "../types/requests";
|
|
5
|
+
import { get_devices_by_herd_query } from "./devices.queries";
|
|
6
|
+
import { get_herds_with_location_query } from "./herds.queries";
|
|
7
|
+
import { get_layers_by_herd_ids_query, get_plans_by_herd_ids_query, get_providers_by_herd_ids_query, } from "./herd_scoped.queries";
|
|
8
|
+
import { get_parts_by_herd_ids } from "./parts";
|
|
9
|
+
import { get_session_summaries_query } from "./session_summaries.queries";
|
|
10
|
+
import { get_session_usage_over_time_by_herd_query } from "./sessions.queries";
|
|
11
|
+
import { get_users_with_herd_access_batch_query } from "./users.queries";
|
|
12
|
+
import { server_get_more_zones_and_actions_for_herd } from "./zones";
|
|
13
|
+
function hashHerdModules(modules) {
|
|
14
|
+
const stable = modules.map(({ timestamp_last_refreshed: _ts, ...rest }) => rest);
|
|
15
|
+
return createHash("sha1").update(JSON.stringify(stable)).digest("hex");
|
|
16
|
+
}
|
|
17
|
+
export async function load_herd_modules_query(client) {
|
|
18
|
+
const startTime = Date.now();
|
|
19
|
+
const herdsResult = await get_herds_with_location_query(client);
|
|
20
|
+
if (herdsResult.status !== EnumWebResponse.SUCCESS || !herdsResult.data) {
|
|
21
|
+
return {
|
|
22
|
+
status: EnumWebResponse.ERROR,
|
|
23
|
+
msg: herdsResult.msg ?? "Failed to load herds",
|
|
24
|
+
data: null,
|
|
25
|
+
time_finished: Date.now(),
|
|
26
|
+
time_sent: Date.now(),
|
|
27
|
+
server_processing_time_ms: Date.now() - startTime,
|
|
28
|
+
content_hash: "",
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const herds = herdsResult.data.filter((herd) => herd.id != null);
|
|
32
|
+
if (herds.length === 0) {
|
|
33
|
+
const endTime = Date.now();
|
|
34
|
+
console.log(`[server_load_herd_modules] No accessible herds (${endTime - startTime}ms)`);
|
|
35
|
+
return {
|
|
36
|
+
status: EnumWebResponse.SUCCESS,
|
|
37
|
+
msg: "No herds accessible",
|
|
38
|
+
data: [],
|
|
39
|
+
time_finished: endTime,
|
|
40
|
+
time_sent: endTime,
|
|
41
|
+
server_processing_time_ms: endTime - startTime,
|
|
42
|
+
content_hash: hashHerdModules([]),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const herdIds = herds.map((herd) => herd.id);
|
|
46
|
+
const perHerd = (query) => Promise.all(herds.map((herd) => query(herd.id).catch(() => ({
|
|
47
|
+
status: EnumWebResponse.ERROR,
|
|
48
|
+
msg: "",
|
|
49
|
+
data: null,
|
|
50
|
+
}))));
|
|
51
|
+
const grouped = (query) => query.then((response) => response.data ?? {}).catch(() => ({}));
|
|
52
|
+
const unwrap = (response) => response.status === EnumWebResponse.SUCCESS ? response.data : null;
|
|
53
|
+
const [plansByHerd, layersByHerd, providersByHerd, usersByHerd, partsByDevice, devicesResults, zonesResults, summariesResults, usageResults,] = await Promise.all([
|
|
54
|
+
grouped(get_plans_by_herd_ids_query(client, herdIds)),
|
|
55
|
+
grouped(get_layers_by_herd_ids_query(client, herdIds)),
|
|
56
|
+
grouped(get_providers_by_herd_ids_query(client, herdIds)),
|
|
57
|
+
get_users_with_herd_access_batch_query(client, herdIds)
|
|
58
|
+
.then(unwrap)
|
|
59
|
+
.catch(() => null),
|
|
60
|
+
grouped(get_parts_by_herd_ids(client, herdIds)),
|
|
61
|
+
perHerd((id) => get_devices_by_herd_query(client, id)),
|
|
62
|
+
perHerd((id) => server_get_more_zones_and_actions_for_herd(id, 0, 10, client)),
|
|
63
|
+
perHerd((id) => get_session_summaries_query(client, { herd_id: id })),
|
|
64
|
+
perHerd((id) => get_session_usage_over_time_by_herd_query(client, id)),
|
|
65
|
+
]);
|
|
66
|
+
const devicesByHerdIndex = devicesResults.map((response) => unwrap(response) ?? []);
|
|
67
|
+
const allDevices = devicesByHerdIndex.flat();
|
|
68
|
+
let apiKeysByDevice = {};
|
|
69
|
+
if (allDevices.length > 0) {
|
|
70
|
+
try {
|
|
71
|
+
apiKeysByDevice = await list_api_keys_batch_query(client, allDevices.map((device) => device.id ?? 0));
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error("[server_load_herd_modules] Failed to load API keys:", error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const device of allDevices) {
|
|
78
|
+
const deviceId = device.id ?? 0;
|
|
79
|
+
device.api_keys_scout = apiKeysByDevice[deviceId] || [];
|
|
80
|
+
device.parts = partsByDevice[deviceId] || [];
|
|
81
|
+
}
|
|
82
|
+
const serialized_herd_modules = herds.map((herd, index) => ({
|
|
83
|
+
herd,
|
|
84
|
+
devices: devicesByHerdIndex[index],
|
|
85
|
+
timestamp_last_refreshed: Date.now(),
|
|
86
|
+
user_roles: usersByHerd ? usersByHerd[herd.id] ?? [] : null,
|
|
87
|
+
labels: LABELS,
|
|
88
|
+
plans: plansByHerd[herd.id] ?? [],
|
|
89
|
+
zones: unwrap(zonesResults[index]) ?? [],
|
|
90
|
+
layers: layersByHerd[herd.id] ?? [],
|
|
91
|
+
providers: providersByHerd[herd.id] ?? [],
|
|
92
|
+
session_summaries: unwrap(summariesResults[index]),
|
|
93
|
+
session_usage: unwrap(usageResults[index]),
|
|
94
|
+
}));
|
|
95
|
+
const endTime = Date.now();
|
|
96
|
+
console.log(`[server_load_herd_modules] Loaded ${herds.length} herds in ${endTime - startTime}ms (batched queries)`);
|
|
97
|
+
return {
|
|
98
|
+
status: EnumWebResponse.SUCCESS,
|
|
99
|
+
msg: "Herd modules loaded successfully",
|
|
100
|
+
data: serialized_herd_modules,
|
|
101
|
+
time_finished: endTime,
|
|
102
|
+
time_sent: endTime,
|
|
103
|
+
server_processing_time_ms: endTime - startTime,
|
|
104
|
+
content_hash: hashHerdModules(serialized_herd_modules),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
-
import { Database } from "../types/supabase";
|
|
3
1
|
import { IAbility, IHerdRole, IHerdRoleAbilityRow, IHerdRoleWithAbilities, IPlatformDefaultRoleAbilitiesGroup } from "../types/db";
|
|
4
2
|
import { IWebResponseCompatible } from "../types/requests";
|
|
5
|
-
export declare function server_list_abilities(
|
|
6
|
-
export declare function server_get_abilities_by_ids(ids: number[]
|
|
7
|
-
export declare function server_get_herd_roles(herd_id: number
|
|
8
|
-
export declare function server_get_herd_roles_with_abilities(herd_id: number
|
|
9
|
-
export declare function server_get_herd_role_by_system_name(herd_id: number, system_name: string
|
|
10
|
-
export declare function server_create_herd_role(herd_id: number, system_name: string, name: string
|
|
3
|
+
export declare function server_list_abilities(): Promise<IWebResponseCompatible<IAbility[]>>;
|
|
4
|
+
export declare function server_get_abilities_by_ids(ids: number[]): Promise<IWebResponseCompatible<IAbility[]>>;
|
|
5
|
+
export declare function server_get_herd_roles(herd_id: number): Promise<IWebResponseCompatible<IHerdRole[]>>;
|
|
6
|
+
export declare function server_get_herd_roles_with_abilities(herd_id: number): Promise<IWebResponseCompatible<IHerdRoleWithAbilities[]>>;
|
|
7
|
+
export declare function server_get_herd_role_by_system_name(herd_id: number, system_name: string): Promise<IWebResponseCompatible<IHerdRole | null>>;
|
|
8
|
+
export declare function server_create_herd_role(herd_id: number, system_name: string, name: string): Promise<IWebResponseCompatible<IHerdRole | null>>;
|
|
11
9
|
export declare function server_update_herd_role(herd_role_id: number, patch: {
|
|
12
10
|
name?: string;
|
|
13
|
-
}
|
|
14
|
-
export declare function server_delete_herd_role(herd_role_id: number
|
|
15
|
-
export declare function server_set_herd_role_abilities(herd_role_id: number, ability_ids: number[]
|
|
16
|
-
export declare function server_get_platform_default_role_abilities(
|
|
17
|
-
export declare function server_set_platform_default_role_abilities(system_name: string, ability_keys: string[]
|
|
18
|
-
export declare function server_reset_herd_default_role_abilities(herd_id: number
|
|
11
|
+
}): Promise<IWebResponseCompatible<IHerdRole | null>>;
|
|
12
|
+
export declare function server_delete_herd_role(herd_role_id: number): Promise<IWebResponseCompatible<null>>;
|
|
13
|
+
export declare function server_set_herd_role_abilities(herd_role_id: number, ability_ids: number[]): Promise<IWebResponseCompatible<IHerdRoleAbilityRow[]>>;
|
|
14
|
+
export declare function server_get_platform_default_role_abilities(): Promise<IWebResponseCompatible<IPlatformDefaultRoleAbilitiesGroup[]>>;
|
|
15
|
+
export declare function server_set_platform_default_role_abilities(system_name: string, ability_keys: string[]): Promise<IWebResponseCompatible<null>>;
|
|
16
|
+
export declare function server_reset_herd_default_role_abilities(herd_id: number): Promise<IWebResponseCompatible<null>>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { IWebResponse } from "../types/requests";
|
|
3
3
|
import { newServerClient } from "../supabase/server";
|
|
4
|
-
export async function server_list_abilities(
|
|
5
|
-
const supabase =
|
|
4
|
+
export async function server_list_abilities() {
|
|
5
|
+
const supabase = await newServerClient();
|
|
6
6
|
const { data, error } = await supabase
|
|
7
7
|
.from("abilities")
|
|
8
8
|
.select("*")
|
|
@@ -12,11 +12,11 @@ export async function server_list_abilities(supabaseClient) {
|
|
|
12
12
|
}
|
|
13
13
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
14
14
|
}
|
|
15
|
-
export async function server_get_abilities_by_ids(ids
|
|
15
|
+
export async function server_get_abilities_by_ids(ids) {
|
|
16
16
|
if (ids.length === 0) {
|
|
17
17
|
return IWebResponse.success([]).to_compatible();
|
|
18
18
|
}
|
|
19
|
-
const supabase =
|
|
19
|
+
const supabase = await newServerClient();
|
|
20
20
|
const { data, error } = await supabase
|
|
21
21
|
.from("abilities")
|
|
22
22
|
.select("*")
|
|
@@ -27,8 +27,8 @@ export async function server_get_abilities_by_ids(ids, supabaseClient) {
|
|
|
27
27
|
}
|
|
28
28
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
29
29
|
}
|
|
30
|
-
export async function server_get_herd_roles(herd_id
|
|
31
|
-
const supabase =
|
|
30
|
+
export async function server_get_herd_roles(herd_id) {
|
|
31
|
+
const supabase = await newServerClient();
|
|
32
32
|
const { data, error } = await supabase
|
|
33
33
|
.from("herd_roles")
|
|
34
34
|
.select("*")
|
|
@@ -39,8 +39,8 @@ export async function server_get_herd_roles(herd_id, supabaseClient) {
|
|
|
39
39
|
}
|
|
40
40
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
41
41
|
}
|
|
42
|
-
export async function server_get_herd_roles_with_abilities(herd_id
|
|
43
|
-
const supabase =
|
|
42
|
+
export async function server_get_herd_roles_with_abilities(herd_id) {
|
|
43
|
+
const supabase = await newServerClient();
|
|
44
44
|
const { data, error } = await supabase
|
|
45
45
|
.from("herd_roles")
|
|
46
46
|
.select(`
|
|
@@ -69,8 +69,8 @@ export async function server_get_herd_roles_with_abilities(herd_id, supabaseClie
|
|
|
69
69
|
});
|
|
70
70
|
return IWebResponse.success(rows).to_compatible();
|
|
71
71
|
}
|
|
72
|
-
export async function server_get_herd_role_by_system_name(herd_id, system_name
|
|
73
|
-
const supabase =
|
|
72
|
+
export async function server_get_herd_role_by_system_name(herd_id, system_name) {
|
|
73
|
+
const supabase = await newServerClient();
|
|
74
74
|
const { data, error } = await supabase
|
|
75
75
|
.from("herd_roles")
|
|
76
76
|
.select("*")
|
|
@@ -82,16 +82,11 @@ export async function server_get_herd_role_by_system_name(herd_id, system_name,
|
|
|
82
82
|
}
|
|
83
83
|
return IWebResponse.success(data).to_compatible();
|
|
84
84
|
}
|
|
85
|
-
export async function server_create_herd_role(herd_id, system_name, name
|
|
86
|
-
const supabase =
|
|
85
|
+
export async function server_create_herd_role(herd_id, system_name, name) {
|
|
86
|
+
const supabase = await newServerClient();
|
|
87
87
|
const { data, error } = await supabase
|
|
88
88
|
.from("herd_roles")
|
|
89
|
-
.insert({
|
|
90
|
-
herd_id,
|
|
91
|
-
system_name,
|
|
92
|
-
name,
|
|
93
|
-
is_system: false,
|
|
94
|
-
})
|
|
89
|
+
.insert({ herd_id, system_name, name, is_system: false })
|
|
95
90
|
.select("*")
|
|
96
91
|
.single();
|
|
97
92
|
if (error) {
|
|
@@ -99,8 +94,8 @@ export async function server_create_herd_role(herd_id, system_name, name, supaba
|
|
|
99
94
|
}
|
|
100
95
|
return IWebResponse.success(data).to_compatible();
|
|
101
96
|
}
|
|
102
|
-
export async function server_update_herd_role(herd_role_id, patch
|
|
103
|
-
const supabase =
|
|
97
|
+
export async function server_update_herd_role(herd_role_id, patch) {
|
|
98
|
+
const supabase = await newServerClient();
|
|
104
99
|
const { data, error } = await supabase
|
|
105
100
|
.from("herd_roles")
|
|
106
101
|
.update(patch)
|
|
@@ -112,8 +107,8 @@ export async function server_update_herd_role(herd_role_id, patch, supabaseClien
|
|
|
112
107
|
}
|
|
113
108
|
return IWebResponse.success(data).to_compatible();
|
|
114
109
|
}
|
|
115
|
-
export async function server_delete_herd_role(herd_role_id
|
|
116
|
-
const supabase =
|
|
110
|
+
export async function server_delete_herd_role(herd_role_id) {
|
|
111
|
+
const supabase = await newServerClient();
|
|
117
112
|
const { error } = await supabase
|
|
118
113
|
.from("herd_roles")
|
|
119
114
|
.delete()
|
|
@@ -123,8 +118,8 @@ export async function server_delete_herd_role(herd_role_id, supabaseClient) {
|
|
|
123
118
|
}
|
|
124
119
|
return IWebResponse.success(null).to_compatible();
|
|
125
120
|
}
|
|
126
|
-
export async function server_set_herd_role_abilities(herd_role_id, ability_ids
|
|
127
|
-
const supabase =
|
|
121
|
+
export async function server_set_herd_role_abilities(herd_role_id, ability_ids) {
|
|
122
|
+
const supabase = await newServerClient();
|
|
128
123
|
const { error: deleteError } = await supabase
|
|
129
124
|
.from("herd_role_abilities")
|
|
130
125
|
.delete()
|
|
@@ -137,18 +132,15 @@ export async function server_set_herd_role_abilities(herd_role_id, ability_ids,
|
|
|
137
132
|
}
|
|
138
133
|
const { data, error } = await supabase
|
|
139
134
|
.from("herd_role_abilities")
|
|
140
|
-
.insert(ability_ids.map((ability_id) => ({
|
|
141
|
-
herd_role_id,
|
|
142
|
-
ability_id,
|
|
143
|
-
})))
|
|
135
|
+
.insert(ability_ids.map((ability_id) => ({ herd_role_id, ability_id })))
|
|
144
136
|
.select("*");
|
|
145
137
|
if (error) {
|
|
146
138
|
return IWebResponse.error(error.message).to_compatible();
|
|
147
139
|
}
|
|
148
140
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
149
141
|
}
|
|
150
|
-
export async function server_get_platform_default_role_abilities(
|
|
151
|
-
const supabase =
|
|
142
|
+
export async function server_get_platform_default_role_abilities() {
|
|
143
|
+
const supabase = await newServerClient();
|
|
152
144
|
const { data, error } = await supabase.rpc("get_platform_default_role_abilities");
|
|
153
145
|
if (error) {
|
|
154
146
|
return IWebResponse.error(error.message).to_compatible();
|
|
@@ -158,8 +150,8 @@ export async function server_get_platform_default_role_abilities(supabaseClient)
|
|
|
158
150
|
: [];
|
|
159
151
|
return IWebResponse.success(groups).to_compatible();
|
|
160
152
|
}
|
|
161
|
-
export async function server_set_platform_default_role_abilities(system_name, ability_keys
|
|
162
|
-
const supabase =
|
|
153
|
+
export async function server_set_platform_default_role_abilities(system_name, ability_keys) {
|
|
154
|
+
const supabase = await newServerClient();
|
|
163
155
|
const { error } = await supabase.rpc("set_platform_default_role_abilities", {
|
|
164
156
|
p_system_name: system_name,
|
|
165
157
|
p_ability_keys: ability_keys,
|
|
@@ -169,8 +161,8 @@ export async function server_set_platform_default_role_abilities(system_name, ab
|
|
|
169
161
|
}
|
|
170
162
|
return IWebResponse.success(null).to_compatible();
|
|
171
163
|
}
|
|
172
|
-
export async function server_reset_herd_default_role_abilities(herd_id
|
|
173
|
-
const supabase =
|
|
164
|
+
export async function server_reset_herd_default_role_abilities(herd_id) {
|
|
165
|
+
const supabase = await newServerClient();
|
|
174
166
|
const { error } = await supabase.rpc("reset_herd_default_role_abilities", {
|
|
175
167
|
p_herd_id: herd_id,
|
|
176
168
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { IAbility, IHerdRole, IHerdRoleAbilityRow, IHerdRoleWithAbilities, IPlatformDefaultRoleAbilitiesGroup } from "../types/db";
|
|
3
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
4
|
+
import { Database } from "../types/supabase";
|
|
5
|
+
export declare function listAbilitiesWithClient(supabase: SupabaseClient<Database>): Promise<IWebResponseCompatible<IAbility[]>>;
|
|
6
|
+
export declare function getAbilitiesByIdsWithClient(supabase: SupabaseClient<Database>, ids: number[]): Promise<IWebResponseCompatible<IAbility[]>>;
|
|
7
|
+
export declare function getHerdRolesWithClient(supabase: SupabaseClient<Database>, herd_id: number): Promise<IWebResponseCompatible<IHerdRole[]>>;
|
|
8
|
+
export declare function getHerdRolesWithAbilitiesWithClient(supabase: SupabaseClient<Database>, herd_id: number): Promise<IWebResponseCompatible<IHerdRoleWithAbilities[]>>;
|
|
9
|
+
export declare function getHerdRoleBySystemNameWithClient(supabase: SupabaseClient<Database>, herd_id: number, system_name: string): Promise<IWebResponseCompatible<IHerdRole | null>>;
|
|
10
|
+
export declare function createHerdRoleWithClient(supabase: SupabaseClient<Database>, herd_id: number, system_name: string, name: string): Promise<IWebResponseCompatible<IHerdRole | null>>;
|
|
11
|
+
export declare function updateHerdRoleWithClient(supabase: SupabaseClient<Database>, herd_role_id: number, patch: {
|
|
12
|
+
name?: string;
|
|
13
|
+
}): Promise<IWebResponseCompatible<IHerdRole | null>>;
|
|
14
|
+
export declare function deleteHerdRoleWithClient(supabase: SupabaseClient<Database>, herd_role_id: number): Promise<IWebResponseCompatible<null>>;
|
|
15
|
+
export declare function setHerdRoleAbilitiesWithClient(supabase: SupabaseClient<Database>, herd_role_id: number, ability_ids: number[]): Promise<IWebResponseCompatible<IHerdRoleAbilityRow[]>>;
|
|
16
|
+
export declare function getPlatformDefaultRoleAbilitiesWithClient(supabase: SupabaseClient<Database>): Promise<IWebResponseCompatible<IPlatformDefaultRoleAbilitiesGroup[]>>;
|
|
17
|
+
export declare function setPlatformDefaultRoleAbilitiesWithClient(supabase: SupabaseClient<Database>, system_name: string, ability_keys: string[]): Promise<IWebResponseCompatible<null>>;
|
|
18
|
+
export declare function resetHerdDefaultRoleAbilitiesWithClient(supabase: SupabaseClient<Database>, herd_id: number): Promise<IWebResponseCompatible<null>>;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { IWebResponse } from "../types/requests";
|
|
2
|
+
export async function listAbilitiesWithClient(supabase) {
|
|
3
|
+
const { data, error } = await supabase
|
|
4
|
+
.from("abilities")
|
|
5
|
+
.select("*")
|
|
6
|
+
.order("key", { ascending: true });
|
|
7
|
+
if (error) {
|
|
8
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
9
|
+
}
|
|
10
|
+
return IWebResponse.success(data ?? []).to_compatible();
|
|
11
|
+
}
|
|
12
|
+
export async function getAbilitiesByIdsWithClient(supabase, ids) {
|
|
13
|
+
if (ids.length === 0) {
|
|
14
|
+
return IWebResponse.success([]).to_compatible();
|
|
15
|
+
}
|
|
16
|
+
const { data, error } = await supabase
|
|
17
|
+
.from("abilities")
|
|
18
|
+
.select("*")
|
|
19
|
+
.in("id", ids)
|
|
20
|
+
.order("key", { ascending: true });
|
|
21
|
+
if (error) {
|
|
22
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
23
|
+
}
|
|
24
|
+
return IWebResponse.success(data ?? []).to_compatible();
|
|
25
|
+
}
|
|
26
|
+
export async function getHerdRolesWithClient(supabase, herd_id) {
|
|
27
|
+
const { data, error } = await supabase
|
|
28
|
+
.from("herd_roles")
|
|
29
|
+
.select("*")
|
|
30
|
+
.eq("herd_id", herd_id)
|
|
31
|
+
.order("system_name", { ascending: true });
|
|
32
|
+
if (error) {
|
|
33
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
34
|
+
}
|
|
35
|
+
return IWebResponse.success(data ?? []).to_compatible();
|
|
36
|
+
}
|
|
37
|
+
export async function getHerdRolesWithAbilitiesWithClient(supabase, herd_id) {
|
|
38
|
+
const { data, error } = await supabase
|
|
39
|
+
.from("herd_roles")
|
|
40
|
+
.select(`
|
|
41
|
+
*,
|
|
42
|
+
herd_role_abilities (
|
|
43
|
+
id,
|
|
44
|
+
ability_id,
|
|
45
|
+
abilities (*)
|
|
46
|
+
)
|
|
47
|
+
`)
|
|
48
|
+
.eq("herd_id", herd_id)
|
|
49
|
+
.order("system_name", { ascending: true });
|
|
50
|
+
if (error) {
|
|
51
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
52
|
+
}
|
|
53
|
+
const rows = (data ?? []).map((row) => {
|
|
54
|
+
const { herd_role_abilities: matrix, ...role } = row;
|
|
55
|
+
const links = matrix ?? [];
|
|
56
|
+
return {
|
|
57
|
+
...role,
|
|
58
|
+
abilities: links
|
|
59
|
+
.map((m) => m.abilities)
|
|
60
|
+
.filter((a) => a != null),
|
|
61
|
+
ability_ids: links.map((m) => m.ability_id),
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
return IWebResponse.success(rows).to_compatible();
|
|
65
|
+
}
|
|
66
|
+
export async function getHerdRoleBySystemNameWithClient(supabase, herd_id, system_name) {
|
|
67
|
+
const { data, error } = await supabase
|
|
68
|
+
.from("herd_roles")
|
|
69
|
+
.select("*")
|
|
70
|
+
.eq("herd_id", herd_id)
|
|
71
|
+
.eq("system_name", system_name)
|
|
72
|
+
.maybeSingle();
|
|
73
|
+
if (error) {
|
|
74
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
75
|
+
}
|
|
76
|
+
return IWebResponse.success(data).to_compatible();
|
|
77
|
+
}
|
|
78
|
+
export async function createHerdRoleWithClient(supabase, herd_id, system_name, name) {
|
|
79
|
+
const { data, error } = await supabase
|
|
80
|
+
.from("herd_roles")
|
|
81
|
+
.insert({ herd_id, system_name, name, is_system: false })
|
|
82
|
+
.select("*")
|
|
83
|
+
.single();
|
|
84
|
+
if (error) {
|
|
85
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
86
|
+
}
|
|
87
|
+
return IWebResponse.success(data).to_compatible();
|
|
88
|
+
}
|
|
89
|
+
export async function updateHerdRoleWithClient(supabase, herd_role_id, patch) {
|
|
90
|
+
const { data, error } = await supabase
|
|
91
|
+
.from("herd_roles")
|
|
92
|
+
.update(patch)
|
|
93
|
+
.eq("id", herd_role_id)
|
|
94
|
+
.select("*")
|
|
95
|
+
.single();
|
|
96
|
+
if (error) {
|
|
97
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
98
|
+
}
|
|
99
|
+
return IWebResponse.success(data).to_compatible();
|
|
100
|
+
}
|
|
101
|
+
export async function deleteHerdRoleWithClient(supabase, herd_role_id) {
|
|
102
|
+
const { error } = await supabase
|
|
103
|
+
.from("herd_roles")
|
|
104
|
+
.delete()
|
|
105
|
+
.eq("id", herd_role_id);
|
|
106
|
+
if (error) {
|
|
107
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
108
|
+
}
|
|
109
|
+
return IWebResponse.success(null).to_compatible();
|
|
110
|
+
}
|
|
111
|
+
export async function setHerdRoleAbilitiesWithClient(supabase, herd_role_id, ability_ids) {
|
|
112
|
+
const { error: deleteError } = await supabase
|
|
113
|
+
.from("herd_role_abilities")
|
|
114
|
+
.delete()
|
|
115
|
+
.eq("herd_role_id", herd_role_id);
|
|
116
|
+
if (deleteError) {
|
|
117
|
+
return IWebResponse.error(deleteError.message).to_compatible();
|
|
118
|
+
}
|
|
119
|
+
if (ability_ids.length === 0) {
|
|
120
|
+
return IWebResponse.success([]).to_compatible();
|
|
121
|
+
}
|
|
122
|
+
const { data, error } = await supabase
|
|
123
|
+
.from("herd_role_abilities")
|
|
124
|
+
.insert(ability_ids.map((ability_id) => ({ herd_role_id, ability_id })))
|
|
125
|
+
.select("*");
|
|
126
|
+
if (error) {
|
|
127
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
128
|
+
}
|
|
129
|
+
return IWebResponse.success(data ?? []).to_compatible();
|
|
130
|
+
}
|
|
131
|
+
export async function getPlatformDefaultRoleAbilitiesWithClient(supabase) {
|
|
132
|
+
const { data, error } = await supabase.rpc("get_platform_default_role_abilities");
|
|
133
|
+
if (error) {
|
|
134
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
135
|
+
}
|
|
136
|
+
const groups = Array.isArray(data)
|
|
137
|
+
? data
|
|
138
|
+
: [];
|
|
139
|
+
return IWebResponse.success(groups).to_compatible();
|
|
140
|
+
}
|
|
141
|
+
export async function setPlatformDefaultRoleAbilitiesWithClient(supabase, system_name, ability_keys) {
|
|
142
|
+
const { error } = await supabase.rpc("set_platform_default_role_abilities", {
|
|
143
|
+
p_system_name: system_name,
|
|
144
|
+
p_ability_keys: ability_keys,
|
|
145
|
+
});
|
|
146
|
+
if (error) {
|
|
147
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
148
|
+
}
|
|
149
|
+
return IWebResponse.success(null).to_compatible();
|
|
150
|
+
}
|
|
151
|
+
export async function resetHerdDefaultRoleAbilitiesWithClient(supabase, herd_id) {
|
|
152
|
+
const { error } = await supabase.rpc("reset_herd_default_role_abilities", {
|
|
153
|
+
p_herd_id: herd_id,
|
|
154
|
+
});
|
|
155
|
+
if (error) {
|
|
156
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
157
|
+
}
|
|
158
|
+
return IWebResponse.success(null).to_compatible();
|
|
159
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { ILayer, IPlan, IProvider } from "../types/db";
|
|
3
|
+
import { Database } from "../types/supabase";
|
|
4
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
5
|
+
export declare function get_plans_by_herd_ids_query(client: SupabaseClient<Database>, herd_ids: number[]): Promise<IWebResponseCompatible<Record<number, IPlan[]>>>;
|
|
6
|
+
export declare function get_layers_by_herd_ids_query(client: SupabaseClient<Database>, herd_ids: number[]): Promise<IWebResponseCompatible<Record<number, ILayer[]>>>;
|
|
7
|
+
export declare function get_providers_by_herd_ids_query(client: SupabaseClient<Database>, herd_ids: number[]): Promise<IWebResponseCompatible<Record<number, IProvider[]>>>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
2
|
+
function grouped_by_herd_id(rows, error) {
|
|
3
|
+
var _a;
|
|
4
|
+
if (error) {
|
|
5
|
+
return { status: EnumWebResponse.ERROR, msg: error.message, data: null };
|
|
6
|
+
}
|
|
7
|
+
const grouped = {};
|
|
8
|
+
for (const row of rows ?? []) {
|
|
9
|
+
(grouped[_a = row.herd_id] ?? (grouped[_a] = [])).push(row);
|
|
10
|
+
}
|
|
11
|
+
return IWebResponse.success(grouped).to_compatible();
|
|
12
|
+
}
|
|
13
|
+
export async function get_plans_by_herd_ids_query(client, herd_ids) {
|
|
14
|
+
if (herd_ids.length === 0) {
|
|
15
|
+
return IWebResponse.success({}).to_compatible();
|
|
16
|
+
}
|
|
17
|
+
const { data, error } = await client
|
|
18
|
+
.from("plans")
|
|
19
|
+
.select("*")
|
|
20
|
+
.in("herd_id", herd_ids)
|
|
21
|
+
.order("id", { ascending: true });
|
|
22
|
+
return grouped_by_herd_id(data, error);
|
|
23
|
+
}
|
|
24
|
+
export async function get_layers_by_herd_ids_query(client, herd_ids) {
|
|
25
|
+
if (herd_ids.length === 0) {
|
|
26
|
+
return IWebResponse.success({}).to_compatible();
|
|
27
|
+
}
|
|
28
|
+
const { data, error } = await client
|
|
29
|
+
.from("layers")
|
|
30
|
+
.select("*")
|
|
31
|
+
.in("herd_id", herd_ids)
|
|
32
|
+
.order("id", { ascending: true });
|
|
33
|
+
return grouped_by_herd_id(data, error);
|
|
34
|
+
}
|
|
35
|
+
export async function get_providers_by_herd_ids_query(client, herd_ids) {
|
|
36
|
+
if (herd_ids.length === 0) {
|
|
37
|
+
return IWebResponse.success({}).to_compatible();
|
|
38
|
+
}
|
|
39
|
+
const { data, error } = await client
|
|
40
|
+
.from("providers")
|
|
41
|
+
.select("*")
|
|
42
|
+
.in("herd_id", herd_ids)
|
|
43
|
+
.order("id", { ascending: true });
|
|
44
|
+
return grouped_by_herd_id(data, error);
|
|
45
|
+
}
|
package/dist/helpers/herds.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { Database } from "../types/supabase";
|
|
2
1
|
import { IHerd, IHerdPrettyLocation } from "../types/db";
|
|
3
2
|
import { IWebResponseCompatible } from "../types/requests";
|
|
4
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
5
3
|
import { IHerdModulesResponseWithStatus } from "../types/herd_module";
|
|
6
|
-
export declare function get_herds(
|
|
7
|
-
export declare function get_herds_with_location(
|
|
4
|
+
export declare function get_herds(): Promise<IWebResponseCompatible<IHerd[]>>;
|
|
5
|
+
export declare function get_herds_with_location(): Promise<IWebResponseCompatible<IHerdPrettyLocation[]>>;
|
|
8
6
|
export declare function get_herd_by_slug(slug: string): Promise<IWebResponseCompatible<IHerd>>;
|
|
9
7
|
export declare function deleteHerd(herd_id: number): Promise<IWebResponseCompatible<boolean>>;
|
|
10
8
|
export declare function createHerd(newHerd: Omit<IHerd, "id" | "inserted_at"> & {
|