@adventurelabs/scout-core 1.5.5 → 2.0.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/README.md +47 -0
- package/dist/api_keys/actions.d.ts +0 -1
- package/dist/api_keys/actions.js +0 -14
- package/dist/client/index.d.ts +76 -0
- package/dist/client/index.js +83 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/helpers/analysis_usage/jobs_server.d.ts +25 -0
- package/dist/helpers/analysis_usage/jobs_server.js +10 -0
- package/dist/helpers/analysis_usage/tasks_server.d.ts +63 -0
- package/dist/helpers/analysis_usage/tasks_server.js +14 -0
- package/dist/helpers/artifacts.d.ts +0 -1
- package/dist/helpers/artifacts.js +10 -147
- package/dist/helpers/artifacts.queries.d.ts +26 -0
- package/dist/helpers/{artifacts.internal.js → artifacts.queries.js} +24 -41
- package/dist/helpers/auth.d.ts +1 -1
- package/dist/helpers/auth.js +2 -3
- package/dist/helpers/auth_server.d.ts +2 -0
- package/dist/helpers/auth_server.js +10 -0
- package/dist/helpers/certificates_server.d.ts +101 -0
- package/dist/helpers/certificates_server.js +42 -0
- package/dist/helpers/chat.d.ts +1 -2
- package/dist/helpers/chat.js +3 -38
- package/dist/helpers/chat.queries.d.ts +13 -0
- package/dist/helpers/chat.queries.js +39 -0
- package/dist/helpers/client_abilities_jwt_keys.js +0 -1
- package/dist/helpers/client_abilities_token_server.d.ts +1 -0
- package/dist/helpers/client_abilities_token_server.js +5 -2
- package/dist/helpers/compliance.d.ts +26 -0
- package/dist/helpers/compliance.js +74 -0
- package/dist/helpers/compliance.queries.d.ts +28 -0
- package/dist/helpers/compliance.queries.js +167 -0
- package/dist/helpers/connectivity.d.ts +1 -5
- package/dist/helpers/connectivity.js +7 -140
- package/dist/helpers/connectivity.queries.d.ts +18 -0
- package/dist/helpers/connectivity.queries.js +121 -0
- package/dist/helpers/contacts_server.d.ts +75 -0
- package/dist/helpers/contacts_server.js +18 -0
- package/dist/helpers/deviceTransfer.js +2 -11
- package/dist/helpers/deviceTransfer.queries.d.ts +4 -0
- package/dist/helpers/deviceTransfer.queries.js +11 -0
- package/dist/helpers/devices.js +4 -61
- package/dist/helpers/devices.queries.d.ts +4 -1
- package/dist/helpers/devices.queries.js +52 -0
- package/dist/helpers/document_templates.js +6 -52
- package/dist/helpers/document_templates.queries.d.ts +9 -0
- package/dist/helpers/document_templates.queries.js +56 -0
- package/dist/helpers/documents_server.d.ts +226 -0
- package/dist/helpers/documents_server.js +38 -0
- package/dist/helpers/email.d.ts +0 -6
- package/dist/helpers/email.js +1 -19
- package/dist/helpers/embeddings.d.ts +0 -5
- package/dist/helpers/embeddings.js +2 -19
- package/dist/helpers/embeddings.queries.d.ts +7 -0
- package/dist/helpers/{embeddings.internal.js → embeddings.queries.js} +2 -2
- package/dist/helpers/eventUtils.d.ts +3 -12
- package/dist/helpers/eventUtils.js +0 -10
- package/dist/helpers/events.d.ts +0 -1
- package/dist/helpers/events.js +7 -107
- package/dist/helpers/events.queries.d.ts +17 -0
- package/dist/helpers/{events.internal.js → events.queries.js} +24 -15
- package/dist/helpers/health_metrics.js +3 -38
- package/dist/helpers/health_metrics.queries.d.ts +12 -0
- package/dist/helpers/health_metrics.queries.js +39 -0
- package/dist/helpers/heartbeats.js +4 -83
- package/dist/helpers/heartbeats.queries.d.ts +11 -0
- package/dist/helpers/heartbeats.queries.js +76 -0
- package/dist/helpers/herd_allowed_domains.js +2 -12
- package/dist/helpers/{herd_allowed_domains_internal.d.ts → herd_allowed_domains.queries.d.ts} +1 -1
- package/dist/helpers/{herd_allowed_domains_internal.js → herd_allowed_domains.queries.js} +2 -2
- package/dist/helpers/herd_credentials_server.d.ts +76 -0
- package/dist/helpers/herd_credentials_server.js +22 -0
- package/dist/helpers/herd_modules.queries.js +10 -7
- package/dist/helpers/herd_roles.js +13 -148
- package/dist/helpers/herd_roles.queries.d.ts +18 -0
- package/dist/helpers/{herd_roles_internal.js → herd_roles.queries.js} +28 -28
- package/dist/helpers/herds.js +5 -47
- package/dist/helpers/herds.queries.d.ts +8 -1
- package/dist/helpers/herds.queries.js +48 -0
- package/dist/helpers/invitations.js +7 -58
- package/dist/helpers/invitations.queries.d.ts +10 -0
- package/dist/helpers/{invitations_internal.js → invitations.queries.js} +12 -12
- package/dist/helpers/issuers.js +6 -52
- package/dist/helpers/issuers.queries.d.ts +9 -0
- package/dist/helpers/issuers.queries.js +53 -0
- package/dist/helpers/layers.js +2 -20
- package/dist/helpers/layers.queries.d.ts +2 -1
- package/dist/helpers/layers.queries.js +9 -13
- package/dist/helpers/lifecycle_server.d.ts +178 -0
- package/dist/helpers/lifecycle_server.js +38 -0
- package/dist/helpers/localizations.js +5 -42
- package/dist/helpers/localizations.queries.d.ts +8 -0
- package/dist/helpers/localizations.queries.js +45 -0
- package/dist/helpers/maintenance_requests_server.d.ts +124 -0
- package/dist/helpers/maintenance_requests_server.js +34 -0
- package/dist/helpers/manufacturers.js +5 -43
- package/dist/helpers/manufacturers.queries.d.ts +10 -0
- package/dist/helpers/manufacturers.queries.js +46 -0
- package/dist/helpers/media_urls.d.ts +13 -0
- package/dist/helpers/media_urls.js +21 -0
- package/dist/helpers/models.js +8 -80
- package/dist/helpers/models.queries.d.ts +13 -0
- package/dist/helpers/models.queries.js +79 -0
- package/dist/helpers/observations_server.d.ts +51 -0
- package/dist/helpers/observations_server.js +22 -0
- package/dist/helpers/operating_contexts.js +39 -154
- package/dist/helpers/operating_contexts.queries.d.ts +48 -0
- package/dist/helpers/operating_contexts.queries.js +223 -0
- package/dist/helpers/operators.js +4 -57
- package/dist/helpers/operators.queries.d.ts +7 -0
- package/dist/helpers/operators.queries.js +55 -0
- package/dist/helpers/parts.d.ts +0 -87
- package/dist/helpers/parts.js +1 -89
- package/dist/helpers/parts_server.d.ts +260 -0
- package/dist/helpers/parts_server.js +71 -0
- package/dist/helpers/pins_server.d.ts +118 -0
- package/dist/helpers/pins_server.js +38 -0
- package/dist/helpers/plans.js +4 -56
- package/dist/helpers/plans.queries.d.ts +4 -1
- package/dist/helpers/plans.queries.js +39 -12
- package/dist/helpers/points_for_user_server.d.ts +9 -0
- package/dist/helpers/points_for_user_server.js +14 -0
- package/dist/helpers/product_compatibilities.js +6 -78
- package/dist/helpers/product_compatibilities.queries.d.ts +9 -0
- package/dist/helpers/product_compatibilities.queries.js +83 -0
- package/dist/helpers/product_numbers.js +6 -55
- package/dist/helpers/product_numbers.queries.d.ts +9 -0
- package/dist/helpers/product_numbers.queries.js +58 -0
- package/dist/helpers/products.js +6 -54
- package/dist/helpers/products.queries.d.ts +11 -0
- package/dist/helpers/products.queries.js +58 -0
- package/dist/helpers/providers.js +5 -71
- package/dist/helpers/providers.queries.d.ts +5 -1
- package/dist/helpers/providers.queries.js +52 -11
- package/dist/helpers/pubsub_token_server.d.ts +1 -0
- package/dist/helpers/pubsub_token_server.js +5 -2
- package/dist/helpers/segmentations_sam3.js +5 -78
- package/dist/helpers/segmentations_sam3.queries.d.ts +16 -0
- package/dist/helpers/segmentations_sam3.queries.js +81 -0
- package/dist/helpers/sensor_poses_server.d.ts +98 -0
- package/dist/helpers/sensor_poses_server.js +26 -0
- package/dist/helpers/session_incidents_server.d.ts +106 -0
- package/dist/helpers/session_incidents_server.js +22 -0
- package/dist/helpers/session_summaries.d.ts +2 -0
- package/dist/helpers/session_summaries.js +7 -23
- package/dist/helpers/session_summaries.queries.d.ts +6 -3
- package/dist/helpers/session_summaries.queries.js +27 -0
- package/dist/helpers/sessions.js +8 -122
- package/dist/helpers/sessions.queries.d.ts +14 -2
- package/dist/helpers/sessions.queries.js +88 -1
- package/dist/helpers/storage.js +0 -1
- package/dist/helpers/supabase_auth.d.ts +6 -0
- package/dist/helpers/supabase_auth.js +37 -0
- package/dist/helpers/tags.d.ts +0 -1
- package/dist/helpers/tags.js +13 -559
- package/dist/helpers/tags.queries.d.ts +33 -0
- package/dist/helpers/tags.queries.js +454 -0
- package/dist/helpers/user_credentials_server.d.ts +76 -0
- package/dist/helpers/user_credentials_server.js +22 -0
- package/dist/helpers/users.d.ts +2 -2
- package/dist/helpers/users.js +8 -107
- package/dist/helpers/users.queries.d.ts +9 -1
- package/dist/helpers/users.queries.js +107 -0
- package/dist/helpers/versions_software.d.ts +3 -1
- package/dist/helpers/versions_software.js +24 -0
- package/dist/helpers/versions_software_server.d.ts +83 -4
- package/dist/helpers/versions_software_server.js +23 -50
- package/dist/helpers/zones.d.ts +1 -16
- package/dist/helpers/zones.js +4 -104
- package/dist/helpers/zones.queries.d.ts +6 -0
- package/dist/helpers/zones.queries.js +78 -0
- package/dist/hooks/useAuthorizedRealtimeTopics.js +8 -2
- package/dist/hooks/useInfiniteQuery.js +18 -14
- package/dist/hooks/useScoutRealtimeBroadcast.js +8 -6
- package/dist/hooks/useScoutRealtimeDocuments.js +3 -2
- package/dist/hooks/useScoutRefresh.d.ts +9 -25
- package/dist/hooks/useScoutRefresh.js +33 -213
- package/dist/providers/ScoutRefreshProvider.d.ts +1 -1
- package/dist/providers/ScoutRefreshProvider.js +56 -13
- package/dist/server/index.d.ts +78 -0
- package/dist/server/index.js +80 -0
- package/dist/server/middleware.d.ts +2 -0
- package/dist/server/middleware.js +2 -0
- package/dist/server/supabase.d.ts +2 -0
- package/dist/server/supabase.js +2 -0
- package/dist/store/api.d.ts +40 -40
- package/dist/store/api.js +38 -109
- package/dist/store/configureStore.d.ts +0 -55
- package/dist/store/configureStore.js +1 -8
- package/dist/store/hooks.js +1 -0
- package/dist/supabase/client.d.ts +3 -0
- package/dist/supabase/client.js +10 -0
- package/dist/supabase/middleware.d.ts +1 -0
- package/dist/supabase/middleware.js +6 -20
- package/dist/supabase/server.d.ts +7 -2
- package/dist/supabase/server.js +13 -1
- package/dist/types/db.d.ts +47 -3
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +5 -0
- package/dist/types/supabase.d.ts +512 -0
- package/package.json +53 -4
- package/dist/api_keys/index.d.ts +0 -1
- package/dist/api_keys/index.js +0 -1
- package/dist/helpers/artifacts.internal.d.ts +0 -22
- package/dist/helpers/client_abilities_jwt_keys_internal.d.ts +0 -9
- package/dist/helpers/client_abilities_jwt_keys_internal.js +0 -20
- package/dist/helpers/connectivity.internal.d.ts +0 -10
- package/dist/helpers/connectivity.internal.js +0 -47
- package/dist/helpers/credentials.d.ts +0 -9
- package/dist/helpers/credentials.js +0 -92
- package/dist/helpers/embeddings.internal.d.ts +0 -5
- package/dist/helpers/events.internal.d.ts +0 -13
- package/dist/helpers/herd_roles_internal.d.ts +0 -18
- package/dist/helpers/index.d.ts +0 -56
- package/dist/helpers/index.js +0 -56
- package/dist/helpers/invitations_internal.d.ts +0 -10
- package/dist/helpers/versions_software_internal.d.ts +0 -6
- package/dist/helpers/versions_software_internal.js +0 -53
- package/dist/hooks/useDeviceDisplayName.d.ts +0 -8
- package/dist/hooks/useDeviceDisplayName.js +0 -49
- package/dist/index.d.ts +0 -108
- package/dist/index.js +0 -114
- package/dist/supabase/index.d.ts +0 -2
- package/dist/supabase/index.js +0 -2
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { newServerClient } from "../supabase/server";
|
|
2
|
+
import { create_herd_credential, delete_herd_credential, get_herd_credential_by_id, get_herd_credentials_by_herd_id, update_herd_credential, } from "./herd_credentials";
|
|
3
|
+
export async function server_get_herd_credentials_by_herd_id(herd_id, args) {
|
|
4
|
+
const client = await newServerClient();
|
|
5
|
+
return get_herd_credentials_by_herd_id(client, herd_id, args);
|
|
6
|
+
}
|
|
7
|
+
export async function server_get_herd_credential_by_id(credential_id) {
|
|
8
|
+
const client = await newServerClient();
|
|
9
|
+
return get_herd_credential_by_id(client, credential_id);
|
|
10
|
+
}
|
|
11
|
+
export async function server_create_herd_credential(row) {
|
|
12
|
+
const client = await newServerClient();
|
|
13
|
+
return create_herd_credential(client, row);
|
|
14
|
+
}
|
|
15
|
+
export async function server_update_herd_credential(credential_id, patch) {
|
|
16
|
+
const client = await newServerClient();
|
|
17
|
+
return update_herd_credential(client, credential_id, patch);
|
|
18
|
+
}
|
|
19
|
+
export async function server_delete_herd_credential(credential_id) {
|
|
20
|
+
const client = await newServerClient();
|
|
21
|
+
return delete_herd_credential(client, credential_id);
|
|
22
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createHash } from "crypto";
|
|
2
1
|
import { list_api_keys_batch_query } from "../api_keys/queries";
|
|
3
2
|
import { LABELS } from "../constants/annotator";
|
|
4
3
|
import { EnumWebResponse, } from "../types/requests";
|
|
@@ -9,10 +8,14 @@ import { get_parts_by_herd_ids } from "./parts";
|
|
|
9
8
|
import { get_session_summaries_query } from "./session_summaries.queries";
|
|
10
9
|
import { get_session_usage_over_time_by_herd_query } from "./sessions.queries";
|
|
11
10
|
import { get_users_with_herd_access_batch_query } from "./users.queries";
|
|
12
|
-
import {
|
|
13
|
-
function hashHerdModules(modules) {
|
|
11
|
+
import { get_more_zones_and_actions_for_herd_query } from "./zones.queries";
|
|
12
|
+
async function hashHerdModules(modules) {
|
|
14
13
|
const stable = modules.map(({ timestamp_last_refreshed: _ts, ...rest }) => rest);
|
|
15
|
-
|
|
14
|
+
const bytes = new TextEncoder().encode(JSON.stringify(stable));
|
|
15
|
+
const digest = await crypto.subtle.digest("SHA-1", bytes);
|
|
16
|
+
return Array.from(new Uint8Array(digest))
|
|
17
|
+
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
18
|
+
.join("");
|
|
16
19
|
}
|
|
17
20
|
export async function load_herd_modules_query(client) {
|
|
18
21
|
const startTime = Date.now();
|
|
@@ -39,7 +42,7 @@ export async function load_herd_modules_query(client) {
|
|
|
39
42
|
time_finished: endTime,
|
|
40
43
|
time_sent: endTime,
|
|
41
44
|
server_processing_time_ms: endTime - startTime,
|
|
42
|
-
content_hash: hashHerdModules([]),
|
|
45
|
+
content_hash: await hashHerdModules([]),
|
|
43
46
|
};
|
|
44
47
|
}
|
|
45
48
|
const herdIds = herds.map((herd) => herd.id);
|
|
@@ -59,7 +62,7 @@ export async function load_herd_modules_query(client) {
|
|
|
59
62
|
.catch(() => null),
|
|
60
63
|
grouped(get_parts_by_herd_ids(client, herdIds)),
|
|
61
64
|
perHerd((id) => get_devices_by_herd_query(client, id)),
|
|
62
|
-
perHerd((id) =>
|
|
65
|
+
perHerd((id) => get_more_zones_and_actions_for_herd_query(client, id, 0, 10)),
|
|
63
66
|
perHerd((id) => get_session_summaries_query(client, { herd_id: id })),
|
|
64
67
|
perHerd((id) => get_session_usage_over_time_by_herd_query(client, id)),
|
|
65
68
|
]);
|
|
@@ -101,6 +104,6 @@ export async function load_herd_modules_query(client) {
|
|
|
101
104
|
time_finished: endTime,
|
|
102
105
|
time_sent: endTime,
|
|
103
106
|
server_processing_time_ms: endTime - startTime,
|
|
104
|
-
content_hash: hashHerdModules(serialized_herd_modules),
|
|
107
|
+
content_hash: await hashHerdModules(serialized_herd_modules),
|
|
105
108
|
};
|
|
106
109
|
}
|
|
@@ -1,173 +1,38 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
import { IWebResponse } from "../types/requests";
|
|
3
1
|
import { newServerClient } from "../supabase/server";
|
|
2
|
+
import { create_herd_role_query, delete_herd_role_query, get_abilities_by_ids_query, get_herd_role_by_system_name_query, get_herd_roles_query, get_herd_roles_with_abilities_query, get_platform_default_role_abilities_query, list_abilities_query, reset_herd_default_role_abilities_query, set_herd_role_abilities_query, set_platform_default_role_abilities_query, update_herd_role_query, } from "./herd_roles.queries";
|
|
4
3
|
export async function server_list_abilities() {
|
|
5
|
-
|
|
6
|
-
const { data, error } = await supabase
|
|
7
|
-
.from("abilities")
|
|
8
|
-
.select("*")
|
|
9
|
-
.order("key", { ascending: true });
|
|
10
|
-
if (error) {
|
|
11
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
12
|
-
}
|
|
13
|
-
return IWebResponse.success(data ?? []).to_compatible();
|
|
4
|
+
return list_abilities_query(await newServerClient());
|
|
14
5
|
}
|
|
15
6
|
export async function server_get_abilities_by_ids(ids) {
|
|
16
|
-
|
|
17
|
-
return IWebResponse.success([]).to_compatible();
|
|
18
|
-
}
|
|
19
|
-
const supabase = await newServerClient();
|
|
20
|
-
const { data, error } = await supabase
|
|
21
|
-
.from("abilities")
|
|
22
|
-
.select("*")
|
|
23
|
-
.in("id", ids)
|
|
24
|
-
.order("key", { ascending: true });
|
|
25
|
-
if (error) {
|
|
26
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
27
|
-
}
|
|
28
|
-
return IWebResponse.success(data ?? []).to_compatible();
|
|
7
|
+
return get_abilities_by_ids_query(await newServerClient(), ids);
|
|
29
8
|
}
|
|
30
9
|
export async function server_get_herd_roles(herd_id) {
|
|
31
|
-
|
|
32
|
-
const { data, error } = await supabase
|
|
33
|
-
.from("herd_roles")
|
|
34
|
-
.select("*")
|
|
35
|
-
.eq("herd_id", herd_id)
|
|
36
|
-
.order("system_name", { ascending: true });
|
|
37
|
-
if (error) {
|
|
38
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
39
|
-
}
|
|
40
|
-
return IWebResponse.success(data ?? []).to_compatible();
|
|
10
|
+
return get_herd_roles_query(await newServerClient(), herd_id);
|
|
41
11
|
}
|
|
42
12
|
export async function server_get_herd_roles_with_abilities(herd_id) {
|
|
43
|
-
|
|
44
|
-
const { data, error } = await supabase
|
|
45
|
-
.from("herd_roles")
|
|
46
|
-
.select(`
|
|
47
|
-
*,
|
|
48
|
-
herd_role_abilities (
|
|
49
|
-
id,
|
|
50
|
-
ability_id,
|
|
51
|
-
abilities (*)
|
|
52
|
-
)
|
|
53
|
-
`)
|
|
54
|
-
.eq("herd_id", herd_id)
|
|
55
|
-
.order("system_name", { ascending: true });
|
|
56
|
-
if (error) {
|
|
57
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
58
|
-
}
|
|
59
|
-
const rows = (data ?? []).map((row) => {
|
|
60
|
-
const { herd_role_abilities: matrix, ...role } = row;
|
|
61
|
-
const links = matrix ?? [];
|
|
62
|
-
return {
|
|
63
|
-
...role,
|
|
64
|
-
abilities: links
|
|
65
|
-
.map((m) => m.abilities)
|
|
66
|
-
.filter((a) => a != null),
|
|
67
|
-
ability_ids: links.map((m) => m.ability_id),
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
return IWebResponse.success(rows).to_compatible();
|
|
13
|
+
return get_herd_roles_with_abilities_query(await newServerClient(), herd_id);
|
|
71
14
|
}
|
|
72
15
|
export async function server_get_herd_role_by_system_name(herd_id, system_name) {
|
|
73
|
-
|
|
74
|
-
const { data, error } = await supabase
|
|
75
|
-
.from("herd_roles")
|
|
76
|
-
.select("*")
|
|
77
|
-
.eq("herd_id", herd_id)
|
|
78
|
-
.eq("system_name", system_name)
|
|
79
|
-
.maybeSingle();
|
|
80
|
-
if (error) {
|
|
81
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
82
|
-
}
|
|
83
|
-
return IWebResponse.success(data).to_compatible();
|
|
16
|
+
return get_herd_role_by_system_name_query(await newServerClient(), herd_id, system_name);
|
|
84
17
|
}
|
|
85
18
|
export async function server_create_herd_role(herd_id, system_name, name) {
|
|
86
|
-
|
|
87
|
-
const { data, error } = await supabase
|
|
88
|
-
.from("herd_roles")
|
|
89
|
-
.insert({ herd_id, system_name, name, is_system: false })
|
|
90
|
-
.select("*")
|
|
91
|
-
.single();
|
|
92
|
-
if (error) {
|
|
93
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
94
|
-
}
|
|
95
|
-
return IWebResponse.success(data).to_compatible();
|
|
19
|
+
return create_herd_role_query(await newServerClient(), herd_id, system_name, name);
|
|
96
20
|
}
|
|
97
21
|
export async function server_update_herd_role(herd_role_id, patch) {
|
|
98
|
-
|
|
99
|
-
const { data, error } = await supabase
|
|
100
|
-
.from("herd_roles")
|
|
101
|
-
.update(patch)
|
|
102
|
-
.eq("id", herd_role_id)
|
|
103
|
-
.select("*")
|
|
104
|
-
.single();
|
|
105
|
-
if (error) {
|
|
106
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
107
|
-
}
|
|
108
|
-
return IWebResponse.success(data).to_compatible();
|
|
22
|
+
return update_herd_role_query(await newServerClient(), herd_role_id, patch);
|
|
109
23
|
}
|
|
110
24
|
export async function server_delete_herd_role(herd_role_id) {
|
|
111
|
-
|
|
112
|
-
const { error } = await supabase
|
|
113
|
-
.from("herd_roles")
|
|
114
|
-
.delete()
|
|
115
|
-
.eq("id", herd_role_id);
|
|
116
|
-
if (error) {
|
|
117
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
118
|
-
}
|
|
119
|
-
return IWebResponse.success(null).to_compatible();
|
|
25
|
+
return delete_herd_role_query(await newServerClient(), herd_role_id);
|
|
120
26
|
}
|
|
121
27
|
export async function server_set_herd_role_abilities(herd_role_id, ability_ids) {
|
|
122
|
-
|
|
123
|
-
const { error: deleteError } = await supabase
|
|
124
|
-
.from("herd_role_abilities")
|
|
125
|
-
.delete()
|
|
126
|
-
.eq("herd_role_id", herd_role_id);
|
|
127
|
-
if (deleteError) {
|
|
128
|
-
return IWebResponse.error(deleteError.message).to_compatible();
|
|
129
|
-
}
|
|
130
|
-
if (ability_ids.length === 0) {
|
|
131
|
-
return IWebResponse.success([]).to_compatible();
|
|
132
|
-
}
|
|
133
|
-
const { data, error } = await supabase
|
|
134
|
-
.from("herd_role_abilities")
|
|
135
|
-
.insert(ability_ids.map((ability_id) => ({ herd_role_id, ability_id })))
|
|
136
|
-
.select("*");
|
|
137
|
-
if (error) {
|
|
138
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
139
|
-
}
|
|
140
|
-
return IWebResponse.success(data ?? []).to_compatible();
|
|
28
|
+
return set_herd_role_abilities_query(await newServerClient(), herd_role_id, ability_ids);
|
|
141
29
|
}
|
|
142
30
|
export async function server_get_platform_default_role_abilities() {
|
|
143
|
-
|
|
144
|
-
const { data, error } = await supabase.rpc("get_platform_default_role_abilities");
|
|
145
|
-
if (error) {
|
|
146
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
147
|
-
}
|
|
148
|
-
const groups = Array.isArray(data)
|
|
149
|
-
? data
|
|
150
|
-
: [];
|
|
151
|
-
return IWebResponse.success(groups).to_compatible();
|
|
31
|
+
return get_platform_default_role_abilities_query(await newServerClient());
|
|
152
32
|
}
|
|
153
33
|
export async function server_set_platform_default_role_abilities(system_name, ability_keys) {
|
|
154
|
-
|
|
155
|
-
const { error } = await supabase.rpc("set_platform_default_role_abilities", {
|
|
156
|
-
p_system_name: system_name,
|
|
157
|
-
p_ability_keys: ability_keys,
|
|
158
|
-
});
|
|
159
|
-
if (error) {
|
|
160
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
161
|
-
}
|
|
162
|
-
return IWebResponse.success(null).to_compatible();
|
|
34
|
+
return set_platform_default_role_abilities_query(await newServerClient(), system_name, ability_keys);
|
|
163
35
|
}
|
|
164
36
|
export async function server_reset_herd_default_role_abilities(herd_id) {
|
|
165
|
-
|
|
166
|
-
const { error } = await supabase.rpc("reset_herd_default_role_abilities", {
|
|
167
|
-
p_herd_id: herd_id,
|
|
168
|
-
});
|
|
169
|
-
if (error) {
|
|
170
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
171
|
-
}
|
|
172
|
-
return IWebResponse.success(null).to_compatible();
|
|
37
|
+
return reset_herd_default_role_abilities_query(await newServerClient(), herd_id);
|
|
173
38
|
}
|
|
@@ -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 list_abilities_query(client: SupabaseClient<Database>): Promise<IWebResponseCompatible<IAbility[]>>;
|
|
6
|
+
export declare function get_abilities_by_ids_query(client: SupabaseClient<Database>, ids: number[]): Promise<IWebResponseCompatible<IAbility[]>>;
|
|
7
|
+
export declare function get_herd_roles_query(client: SupabaseClient<Database>, herd_id: number): Promise<IWebResponseCompatible<IHerdRole[]>>;
|
|
8
|
+
export declare function get_herd_roles_with_abilities_query(client: SupabaseClient<Database>, herd_id: number): Promise<IWebResponseCompatible<IHerdRoleWithAbilities[]>>;
|
|
9
|
+
export declare function get_herd_role_by_system_name_query(client: SupabaseClient<Database>, herd_id: number, system_name: string): Promise<IWebResponseCompatible<IHerdRole | null>>;
|
|
10
|
+
export declare function create_herd_role_query(client: SupabaseClient<Database>, herd_id: number, system_name: string, name: string): Promise<IWebResponseCompatible<IHerdRole | null>>;
|
|
11
|
+
export declare function update_herd_role_query(client: SupabaseClient<Database>, herd_role_id: number, patch: {
|
|
12
|
+
name?: string;
|
|
13
|
+
}): Promise<IWebResponseCompatible<IHerdRole | null>>;
|
|
14
|
+
export declare function delete_herd_role_query(client: SupabaseClient<Database>, herd_role_id: number): Promise<IWebResponseCompatible<null>>;
|
|
15
|
+
export declare function set_herd_role_abilities_query(client: SupabaseClient<Database>, herd_role_id: number, ability_ids: number[]): Promise<IWebResponseCompatible<IHerdRoleAbilityRow[]>>;
|
|
16
|
+
export declare function get_platform_default_role_abilities_query(client: SupabaseClient<Database>): Promise<IWebResponseCompatible<IPlatformDefaultRoleAbilitiesGroup[]>>;
|
|
17
|
+
export declare function set_platform_default_role_abilities_query(client: SupabaseClient<Database>, system_name: string, ability_keys: string[]): Promise<IWebResponseCompatible<null>>;
|
|
18
|
+
export declare function reset_herd_default_role_abilities_query(client: SupabaseClient<Database>, herd_id: number): Promise<IWebResponseCompatible<null>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IWebResponse } from "../types/requests";
|
|
2
|
-
export async function
|
|
3
|
-
const { data, error } = await
|
|
2
|
+
export async function list_abilities_query(client) {
|
|
3
|
+
const { data, error } = await client
|
|
4
4
|
.from("abilities")
|
|
5
5
|
.select("*")
|
|
6
6
|
.order("key", { ascending: true });
|
|
@@ -9,11 +9,11 @@ export async function listAbilitiesWithClient(supabase) {
|
|
|
9
9
|
}
|
|
10
10
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
11
11
|
}
|
|
12
|
-
export async function
|
|
12
|
+
export async function get_abilities_by_ids_query(client, ids) {
|
|
13
13
|
if (ids.length === 0) {
|
|
14
14
|
return IWebResponse.success([]).to_compatible();
|
|
15
15
|
}
|
|
16
|
-
const { data, error } = await
|
|
16
|
+
const { data, error } = await client
|
|
17
17
|
.from("abilities")
|
|
18
18
|
.select("*")
|
|
19
19
|
.in("id", ids)
|
|
@@ -23,8 +23,8 @@ export async function getAbilitiesByIdsWithClient(supabase, ids) {
|
|
|
23
23
|
}
|
|
24
24
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
25
25
|
}
|
|
26
|
-
export async function
|
|
27
|
-
const { data, error } = await
|
|
26
|
+
export async function get_herd_roles_query(client, herd_id) {
|
|
27
|
+
const { data, error } = await client
|
|
28
28
|
.from("herd_roles")
|
|
29
29
|
.select("*")
|
|
30
30
|
.eq("herd_id", herd_id)
|
|
@@ -34,8 +34,8 @@ export async function getHerdRolesWithClient(supabase, herd_id) {
|
|
|
34
34
|
}
|
|
35
35
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
36
36
|
}
|
|
37
|
-
export async function
|
|
38
|
-
const { data, error } = await
|
|
37
|
+
export async function get_herd_roles_with_abilities_query(client, herd_id) {
|
|
38
|
+
const { data, error } = await client
|
|
39
39
|
.from("herd_roles")
|
|
40
40
|
.select(`
|
|
41
41
|
*,
|
|
@@ -56,15 +56,15 @@ export async function getHerdRolesWithAbilitiesWithClient(supabase, herd_id) {
|
|
|
56
56
|
return {
|
|
57
57
|
...role,
|
|
58
58
|
abilities: links
|
|
59
|
-
.map((
|
|
60
|
-
.filter((
|
|
61
|
-
ability_ids: links.map((
|
|
59
|
+
.map((link) => link.abilities)
|
|
60
|
+
.filter((ability) => ability != null),
|
|
61
|
+
ability_ids: links.map((link) => link.ability_id),
|
|
62
62
|
};
|
|
63
63
|
});
|
|
64
64
|
return IWebResponse.success(rows).to_compatible();
|
|
65
65
|
}
|
|
66
|
-
export async function
|
|
67
|
-
const { data, error } = await
|
|
66
|
+
export async function get_herd_role_by_system_name_query(client, herd_id, system_name) {
|
|
67
|
+
const { data, error } = await client
|
|
68
68
|
.from("herd_roles")
|
|
69
69
|
.select("*")
|
|
70
70
|
.eq("herd_id", herd_id)
|
|
@@ -75,8 +75,8 @@ export async function getHerdRoleBySystemNameWithClient(supabase, herd_id, syste
|
|
|
75
75
|
}
|
|
76
76
|
return IWebResponse.success(data).to_compatible();
|
|
77
77
|
}
|
|
78
|
-
export async function
|
|
79
|
-
const { data, error } = await
|
|
78
|
+
export async function create_herd_role_query(client, herd_id, system_name, name) {
|
|
79
|
+
const { data, error } = await client
|
|
80
80
|
.from("herd_roles")
|
|
81
81
|
.insert({ herd_id, system_name, name, is_system: false })
|
|
82
82
|
.select("*")
|
|
@@ -86,8 +86,8 @@ export async function createHerdRoleWithClient(supabase, herd_id, system_name, n
|
|
|
86
86
|
}
|
|
87
87
|
return IWebResponse.success(data).to_compatible();
|
|
88
88
|
}
|
|
89
|
-
export async function
|
|
90
|
-
const { data, error } = await
|
|
89
|
+
export async function update_herd_role_query(client, herd_role_id, patch) {
|
|
90
|
+
const { data, error } = await client
|
|
91
91
|
.from("herd_roles")
|
|
92
92
|
.update(patch)
|
|
93
93
|
.eq("id", herd_role_id)
|
|
@@ -98,8 +98,8 @@ export async function updateHerdRoleWithClient(supabase, herd_role_id, patch) {
|
|
|
98
98
|
}
|
|
99
99
|
return IWebResponse.success(data).to_compatible();
|
|
100
100
|
}
|
|
101
|
-
export async function
|
|
102
|
-
const { error } = await
|
|
101
|
+
export async function delete_herd_role_query(client, herd_role_id) {
|
|
102
|
+
const { error } = await client
|
|
103
103
|
.from("herd_roles")
|
|
104
104
|
.delete()
|
|
105
105
|
.eq("id", herd_role_id);
|
|
@@ -108,8 +108,8 @@ export async function deleteHerdRoleWithClient(supabase, herd_role_id) {
|
|
|
108
108
|
}
|
|
109
109
|
return IWebResponse.success(null).to_compatible();
|
|
110
110
|
}
|
|
111
|
-
export async function
|
|
112
|
-
const { error: deleteError } = await
|
|
111
|
+
export async function set_herd_role_abilities_query(client, herd_role_id, ability_ids) {
|
|
112
|
+
const { error: deleteError } = await client
|
|
113
113
|
.from("herd_role_abilities")
|
|
114
114
|
.delete()
|
|
115
115
|
.eq("herd_role_id", herd_role_id);
|
|
@@ -119,7 +119,7 @@ export async function setHerdRoleAbilitiesWithClient(supabase, herd_role_id, abi
|
|
|
119
119
|
if (ability_ids.length === 0) {
|
|
120
120
|
return IWebResponse.success([]).to_compatible();
|
|
121
121
|
}
|
|
122
|
-
const { data, error } = await
|
|
122
|
+
const { data, error } = await client
|
|
123
123
|
.from("herd_role_abilities")
|
|
124
124
|
.insert(ability_ids.map((ability_id) => ({ herd_role_id, ability_id })))
|
|
125
125
|
.select("*");
|
|
@@ -128,8 +128,8 @@ export async function setHerdRoleAbilitiesWithClient(supabase, herd_role_id, abi
|
|
|
128
128
|
}
|
|
129
129
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
130
130
|
}
|
|
131
|
-
export async function
|
|
132
|
-
const { data, error } = await
|
|
131
|
+
export async function get_platform_default_role_abilities_query(client) {
|
|
132
|
+
const { data, error } = await client.rpc("get_platform_default_role_abilities");
|
|
133
133
|
if (error) {
|
|
134
134
|
return IWebResponse.error(error.message).to_compatible();
|
|
135
135
|
}
|
|
@@ -138,8 +138,8 @@ export async function getPlatformDefaultRoleAbilitiesWithClient(supabase) {
|
|
|
138
138
|
: [];
|
|
139
139
|
return IWebResponse.success(groups).to_compatible();
|
|
140
140
|
}
|
|
141
|
-
export async function
|
|
142
|
-
const { error } = await
|
|
141
|
+
export async function set_platform_default_role_abilities_query(client, system_name, ability_keys) {
|
|
142
|
+
const { error } = await client.rpc("set_platform_default_role_abilities", {
|
|
143
143
|
p_system_name: system_name,
|
|
144
144
|
p_ability_keys: ability_keys,
|
|
145
145
|
});
|
|
@@ -148,8 +148,8 @@ export async function setPlatformDefaultRoleAbilitiesWithClient(supabase, system
|
|
|
148
148
|
}
|
|
149
149
|
return IWebResponse.success(null).to_compatible();
|
|
150
150
|
}
|
|
151
|
-
export async function
|
|
152
|
-
const { error } = await
|
|
151
|
+
export async function reset_herd_default_role_abilities_query(client, herd_id) {
|
|
152
|
+
const { error } = await client.rpc("reset_herd_default_role_abilities", {
|
|
153
153
|
p_herd_id: herd_id,
|
|
154
154
|
});
|
|
155
155
|
if (error) {
|
package/dist/helpers/herds.js
CHANGED
|
@@ -1,62 +1,20 @@
|
|
|
1
|
-
"use server";
|
|
2
1
|
import { newServerClient } from "../supabase/server";
|
|
3
|
-
import {
|
|
4
|
-
import { get_herds_with_location_query } from "./herds.queries";
|
|
2
|
+
import { create_herd_query, delete_herd_query, get_herd_by_slug_query, get_herds_query, get_herds_with_location_query, } from "./herds.queries";
|
|
5
3
|
import { load_herd_modules_query } from "./herd_modules.queries";
|
|
6
4
|
export async function get_herds() {
|
|
7
|
-
|
|
8
|
-
const { data: herds } = await supabase.from("herds").select();
|
|
9
|
-
if (!herds) {
|
|
10
|
-
return {
|
|
11
|
-
status: EnumWebResponse.ERROR,
|
|
12
|
-
msg: "No herds found",
|
|
13
|
-
data: null,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
return IWebResponse.success(herds).to_compatible();
|
|
5
|
+
return get_herds_query(await newServerClient());
|
|
17
6
|
}
|
|
18
7
|
export async function get_herds_with_location() {
|
|
19
8
|
return get_herds_with_location_query(await newServerClient());
|
|
20
9
|
}
|
|
21
10
|
export async function get_herd_by_slug(slug) {
|
|
22
|
-
|
|
23
|
-
const { data: herds } = await supabase
|
|
24
|
-
.from("herds")
|
|
25
|
-
.select()
|
|
26
|
-
.eq("slug", slug)
|
|
27
|
-
.limit(1);
|
|
28
|
-
if (!herds) {
|
|
29
|
-
return {
|
|
30
|
-
status: EnumWebResponse.ERROR,
|
|
31
|
-
msg: "No herds found",
|
|
32
|
-
data: null,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
return IWebResponse.success(herds[0]);
|
|
11
|
+
return get_herd_by_slug_query(await newServerClient(), slug);
|
|
36
12
|
}
|
|
37
13
|
export async function deleteHerd(herd_id) {
|
|
38
|
-
|
|
39
|
-
const { error } = await supabase.from("herds").delete().match({ id: herd_id });
|
|
40
|
-
if (error) {
|
|
41
|
-
return {
|
|
42
|
-
status: EnumWebResponse.ERROR,
|
|
43
|
-
msg: error.message,
|
|
44
|
-
data: null,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return IWebResponse.success(true).to_compatible();
|
|
14
|
+
return delete_herd_query(await newServerClient(), herd_id);
|
|
48
15
|
}
|
|
49
16
|
export async function createHerd(newHerd) {
|
|
50
|
-
|
|
51
|
-
const { error } = await supabase.from("herds").insert([newHerd]);
|
|
52
|
-
if (error) {
|
|
53
|
-
return {
|
|
54
|
-
status: EnumWebResponse.ERROR,
|
|
55
|
-
msg: error.message,
|
|
56
|
-
data: null,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return IWebResponse.success(true).to_compatible();
|
|
17
|
+
return create_herd_query(await newServerClient(), newHerd);
|
|
60
18
|
}
|
|
61
19
|
export async function server_load_herd_modules() {
|
|
62
20
|
return load_herd_modules_query(await newServerClient());
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
-
import { IHerdPrettyLocation } from "../types/db";
|
|
2
|
+
import { IHerd, IHerdPrettyLocation } from "../types/db";
|
|
3
3
|
import { Database } from "../types/supabase";
|
|
4
4
|
import { IWebResponseCompatible } from "../types/requests";
|
|
5
|
+
export declare function get_herds_query(client: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerd[]>>;
|
|
5
6
|
export declare function get_herds_with_location_query(client: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdPrettyLocation[]>>;
|
|
7
|
+
export declare function get_herd_by_slug_query(client: SupabaseClient<Database>, slug: string): Promise<IWebResponseCompatible<IHerd>>;
|
|
8
|
+
export declare function delete_herd_query(client: SupabaseClient<Database>, herd_id: number): Promise<IWebResponseCompatible<boolean>>;
|
|
9
|
+
export declare function create_herd_query(client: SupabaseClient<Database>, newHerd: Omit<IHerd, "id" | "inserted_at"> & {
|
|
10
|
+
id?: number;
|
|
11
|
+
inserted_at?: string;
|
|
12
|
+
}): Promise<IWebResponseCompatible<boolean>>;
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
2
|
+
export async function get_herds_query(client) {
|
|
3
|
+
const { data: herds } = await client.from("herds").select();
|
|
4
|
+
if (!herds) {
|
|
5
|
+
return {
|
|
6
|
+
status: EnumWebResponse.ERROR,
|
|
7
|
+
msg: "No herds found",
|
|
8
|
+
data: null,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
return IWebResponse.success(herds).to_compatible();
|
|
12
|
+
}
|
|
2
13
|
export async function get_herds_with_location_query(client) {
|
|
3
14
|
const { data, error } = await client.rpc("get_herds_with_location");
|
|
4
15
|
if (error) {
|
|
@@ -10,3 +21,40 @@ export async function get_herds_with_location_query(client) {
|
|
|
10
21
|
}
|
|
11
22
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
12
23
|
}
|
|
24
|
+
export async function get_herd_by_slug_query(client, slug) {
|
|
25
|
+
const { data: herds } = await client
|
|
26
|
+
.from("herds")
|
|
27
|
+
.select()
|
|
28
|
+
.eq("slug", slug)
|
|
29
|
+
.limit(1);
|
|
30
|
+
if (!herds) {
|
|
31
|
+
return {
|
|
32
|
+
status: EnumWebResponse.ERROR,
|
|
33
|
+
msg: "No herds found",
|
|
34
|
+
data: null,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return IWebResponse.success(herds[0]);
|
|
38
|
+
}
|
|
39
|
+
export async function delete_herd_query(client, herd_id) {
|
|
40
|
+
const { error } = await client.from("herds").delete().match({ id: herd_id });
|
|
41
|
+
if (error) {
|
|
42
|
+
return {
|
|
43
|
+
status: EnumWebResponse.ERROR,
|
|
44
|
+
msg: error.message,
|
|
45
|
+
data: null,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return IWebResponse.success(true).to_compatible();
|
|
49
|
+
}
|
|
50
|
+
export async function create_herd_query(client, newHerd) {
|
|
51
|
+
const { error } = await client.from("herds").insert([newHerd]);
|
|
52
|
+
if (error) {
|
|
53
|
+
return {
|
|
54
|
+
status: EnumWebResponse.ERROR,
|
|
55
|
+
msg: error.message,
|
|
56
|
+
data: null,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return IWebResponse.success(true).to_compatible();
|
|
60
|
+
}
|
|
@@ -1,71 +1,20 @@
|
|
|
1
|
-
"use server";
|
|
2
1
|
import { newServerClient } from "../supabase/server";
|
|
3
|
-
import {
|
|
2
|
+
import { accept_herd_invitations_for_current_user_query, create_herd_invitation_query, get_herd_invitations_by_herd_query, get_herd_invitations_for_current_user_query, reject_herd_invitations_for_current_user_query, revoke_herd_invitations_query, } from "./invitations.queries";
|
|
4
3
|
export async function server_create_herd_invitation(herd_id, email, herd_role_id, expires_at) {
|
|
5
|
-
|
|
6
|
-
const { data, error } = await supabase.rpc("create_herd_invitation", {
|
|
7
|
-
p_herd_id: herd_id,
|
|
8
|
-
p_email: email,
|
|
9
|
-
p_herd_role_id: herd_role_id,
|
|
10
|
-
p_expires_at: expires_at ?? undefined,
|
|
11
|
-
});
|
|
12
|
-
if (error) {
|
|
13
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
14
|
-
}
|
|
15
|
-
return IWebResponse.success(data).to_compatible();
|
|
4
|
+
return create_herd_invitation_query(await newServerClient(), herd_id, email, herd_role_id, expires_at);
|
|
16
5
|
}
|
|
17
6
|
export async function accept_herd_invitations_for_current_user(invitation_ids) {
|
|
18
|
-
|
|
19
|
-
return IWebResponse.error("At least one invitation id is required").to_compatible();
|
|
20
|
-
}
|
|
21
|
-
const supabase = await newServerClient();
|
|
22
|
-
const { data, error } = await supabase.rpc("accept_herd_invitations_for_current_user", { p_invitation_ids: invitation_ids });
|
|
23
|
-
if (error) {
|
|
24
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
25
|
-
}
|
|
26
|
-
return IWebResponse.success(data ?? []).to_compatible();
|
|
7
|
+
return accept_herd_invitations_for_current_user_query(await newServerClient(), invitation_ids);
|
|
27
8
|
}
|
|
28
9
|
export async function server_get_herd_invitations_for_current_user() {
|
|
29
|
-
|
|
30
|
-
const { data, error } = await supabase.rpc("get_herd_invitations_for_current_user");
|
|
31
|
-
if (error) {
|
|
32
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
33
|
-
}
|
|
34
|
-
return IWebResponse.success(data ?? []).to_compatible();
|
|
10
|
+
return get_herd_invitations_for_current_user_query(await newServerClient());
|
|
35
11
|
}
|
|
36
12
|
export async function server_get_herd_invitations_by_herd(herd_id) {
|
|
37
|
-
|
|
38
|
-
const { data, error } = await supabase
|
|
39
|
-
.from("herd_invitations")
|
|
40
|
-
.select("*")
|
|
41
|
-
.eq("herd_id", herd_id)
|
|
42
|
-
.order("created_at", { ascending: false });
|
|
43
|
-
if (error) {
|
|
44
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
45
|
-
}
|
|
46
|
-
return IWebResponse.success(data ?? []).to_compatible();
|
|
13
|
+
return get_herd_invitations_by_herd_query(await newServerClient(), herd_id);
|
|
47
14
|
}
|
|
48
15
|
export async function reject_herd_invitations_for_current_user(invitation_ids) {
|
|
49
|
-
|
|
50
|
-
return IWebResponse.error("At least one invitation id is required").to_compatible();
|
|
51
|
-
}
|
|
52
|
-
const supabase = 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();
|
|
16
|
+
return reject_herd_invitations_for_current_user_query(await newServerClient(), invitation_ids);
|
|
58
17
|
}
|
|
59
18
|
export async function server_revoke_herd_invitations(invitation_ids) {
|
|
60
|
-
|
|
61
|
-
return IWebResponse.error("At least one invitation id is required").to_compatible();
|
|
62
|
-
}
|
|
63
|
-
const supabase = 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();
|
|
19
|
+
return revoke_herd_invitations_query(await newServerClient(), invitation_ids);
|
|
71
20
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { IHerdInvitation, IHerdInvitationWithHerdSlug } from "../types/db";
|
|
3
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
4
|
+
import { Database } from "../types/supabase";
|
|
5
|
+
export declare function create_herd_invitation_query(client: SupabaseClient<Database>, herd_id: number, email: string, herd_role_id: number, expires_at?: string | null): Promise<IWebResponseCompatible<IHerdInvitation | null>>;
|
|
6
|
+
export declare function accept_herd_invitations_for_current_user_query(client: SupabaseClient<Database>, invitation_ids: number[]): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
|
|
7
|
+
export declare function get_herd_invitations_for_current_user_query(client: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdInvitationWithHerdSlug[]>>;
|
|
8
|
+
export declare function get_herd_invitations_by_herd_query(client: SupabaseClient<Database>, herd_id: number): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
|
|
9
|
+
export declare function reject_herd_invitations_for_current_user_query(client: SupabaseClient<Database>, invitation_ids: number[]): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
|
|
10
|
+
export declare function revoke_herd_invitations_query(client: SupabaseClient<Database>, invitation_ids: number[]): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
|