@adventurelabs/scout-core 1.4.95 → 1.5.0
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/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/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/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/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 +5 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/useScoutRealtimeAnalysisJobs.js +4 -58
- package/dist/hooks/useScoutRealtimeAnalysisTasks.js +4 -58
- package/dist/hooks/useScoutRealtimeBroadcast.d.ts +8 -0
- package/dist/hooks/useScoutRealtimeBroadcast.js +44 -0
- package/dist/hooks/useScoutRealtimeContacts.d.ts +5 -0
- package/dist/hooks/useScoutRealtimeContacts.js +7 -0
- package/dist/hooks/useScoutRealtimeDocuments.d.ts +7 -0
- package/dist/hooks/useScoutRealtimeDocuments.js +22 -0
- package/dist/hooks/useScoutRealtimeMaintenanceRequests.d.ts +5 -0
- package/dist/hooks/useScoutRealtimeMaintenanceRequests.js +7 -0
- package/dist/hooks/useScoutRealtimeParts.js +2 -68
- package/dist/hooks/useScoutRealtimePlans.js +2 -61
- package/dist/hooks/useScoutRealtimeSessionIncidents.d.ts +5 -0
- package/dist/hooks/useScoutRealtimeSessionIncidents.js +7 -0
- package/dist/hooks/useScoutRealtimeVersionsSoftware.js +4 -63
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/supabase/server.d.ts +4 -1
- package/dist/supabase/server.js +6 -5
- package/dist/types/supabase.d.ts +33 -0
- package/package.json +1 -1
|
@@ -14,11 +14,11 @@ export async function server_create_herd_invitation(herd_id, email, herd_role_id
|
|
|
14
14
|
}
|
|
15
15
|
return IWebResponse.success(data).to_compatible();
|
|
16
16
|
}
|
|
17
|
-
export async function accept_herd_invitations_for_current_user(invitation_ids
|
|
17
|
+
export async function accept_herd_invitations_for_current_user(invitation_ids) {
|
|
18
18
|
if (invitation_ids.length === 0) {
|
|
19
19
|
return IWebResponse.error("At least one invitation id is required").to_compatible();
|
|
20
20
|
}
|
|
21
|
-
const supabase =
|
|
21
|
+
const supabase = await newServerClient();
|
|
22
22
|
const { data, error } = await supabase.rpc("accept_herd_invitations_for_current_user", { p_invitation_ids: invitation_ids });
|
|
23
23
|
if (error) {
|
|
24
24
|
return IWebResponse.error(error.message).to_compatible();
|
|
@@ -33,8 +33,8 @@ export async function server_get_herd_invitations_for_current_user() {
|
|
|
33
33
|
}
|
|
34
34
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
35
35
|
}
|
|
36
|
-
export async function server_get_herd_invitations_by_herd(herd_id
|
|
37
|
-
const supabase =
|
|
36
|
+
export async function server_get_herd_invitations_by_herd(herd_id) {
|
|
37
|
+
const supabase = await newServerClient();
|
|
38
38
|
const { data, error } = await supabase
|
|
39
39
|
.from("herd_invitations")
|
|
40
40
|
.select("*")
|
|
@@ -45,22 +45,22 @@ export async function server_get_herd_invitations_by_herd(herd_id, supabaseClien
|
|
|
45
45
|
}
|
|
46
46
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
47
47
|
}
|
|
48
|
-
export async function reject_herd_invitations_for_current_user(invitation_ids
|
|
48
|
+
export async function reject_herd_invitations_for_current_user(invitation_ids) {
|
|
49
49
|
if (invitation_ids.length === 0) {
|
|
50
50
|
return IWebResponse.error("At least one invitation id is required").to_compatible();
|
|
51
51
|
}
|
|
52
|
-
const supabase =
|
|
52
|
+
const supabase = await newServerClient();
|
|
53
53
|
const { data, error } = await supabase.rpc("reject_herd_invitations_for_current_user", { p_invitation_ids: invitation_ids });
|
|
54
54
|
if (error) {
|
|
55
55
|
return IWebResponse.error(error.message).to_compatible();
|
|
56
56
|
}
|
|
57
57
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
58
58
|
}
|
|
59
|
-
export async function server_revoke_herd_invitations(invitation_ids
|
|
59
|
+
export async function server_revoke_herd_invitations(invitation_ids) {
|
|
60
60
|
if (invitation_ids.length === 0) {
|
|
61
61
|
return IWebResponse.error("At least one invitation id is required").to_compatible();
|
|
62
62
|
}
|
|
63
|
-
const supabase =
|
|
63
|
+
const supabase = await newServerClient();
|
|
64
64
|
const { data, error } = await supabase.rpc("revoke_herd_invitations", {
|
|
65
65
|
p_invitation_ids: invitation_ids,
|
|
66
66
|
});
|
|
@@ -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 createHerdInvitationWithClient(supabase: SupabaseClient<Database>, herd_id: number, email: string, herd_role_id: number, expires_at?: string | null): Promise<IWebResponseCompatible<IHerdInvitation | null>>;
|
|
6
|
+
export declare function acceptHerdInvitationsWithClient(supabase: SupabaseClient<Database>, invitation_ids: number[]): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
|
|
7
|
+
export declare function getHerdInvitationsForCurrentUserWithClient(supabase: SupabaseClient<Database>): Promise<IWebResponseCompatible<IHerdInvitationWithHerdSlug[]>>;
|
|
8
|
+
export declare function getHerdInvitationsByHerdWithClient(supabase: SupabaseClient<Database>, herd_id: number): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
|
|
9
|
+
export declare function rejectHerdInvitationsWithClient(supabase: SupabaseClient<Database>, invitation_ids: number[]): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
|
|
10
|
+
export declare function revokeHerdInvitationsWithClient(supabase: SupabaseClient<Database>, invitation_ids: number[]): Promise<IWebResponseCompatible<IHerdInvitation[]>>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { IWebResponse } from "../types/requests";
|
|
2
|
+
export async function createHerdInvitationWithClient(supabase, herd_id, email, herd_role_id, expires_at) {
|
|
3
|
+
const { data, error } = await supabase.rpc("create_herd_invitation", {
|
|
4
|
+
p_herd_id: herd_id,
|
|
5
|
+
p_email: email,
|
|
6
|
+
p_herd_role_id: herd_role_id,
|
|
7
|
+
p_expires_at: expires_at ?? undefined,
|
|
8
|
+
});
|
|
9
|
+
if (error) {
|
|
10
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
11
|
+
}
|
|
12
|
+
return IWebResponse.success(data).to_compatible();
|
|
13
|
+
}
|
|
14
|
+
export async function acceptHerdInvitationsWithClient(supabase, invitation_ids) {
|
|
15
|
+
if (invitation_ids.length === 0) {
|
|
16
|
+
return IWebResponse.error("At least one invitation id is required").to_compatible();
|
|
17
|
+
}
|
|
18
|
+
const { data, error } = await supabase.rpc("accept_herd_invitations_for_current_user", { p_invitation_ids: invitation_ids });
|
|
19
|
+
if (error) {
|
|
20
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
21
|
+
}
|
|
22
|
+
return IWebResponse.success(data ?? []).to_compatible();
|
|
23
|
+
}
|
|
24
|
+
export async function getHerdInvitationsForCurrentUserWithClient(supabase) {
|
|
25
|
+
const { data, error } = await supabase.rpc("get_herd_invitations_for_current_user");
|
|
26
|
+
if (error) {
|
|
27
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
28
|
+
}
|
|
29
|
+
return IWebResponse.success(data ?? []).to_compatible();
|
|
30
|
+
}
|
|
31
|
+
export async function getHerdInvitationsByHerdWithClient(supabase, herd_id) {
|
|
32
|
+
const { data, error } = await supabase
|
|
33
|
+
.from("herd_invitations")
|
|
34
|
+
.select("*")
|
|
35
|
+
.eq("herd_id", herd_id)
|
|
36
|
+
.order("created_at", { ascending: false });
|
|
37
|
+
if (error) {
|
|
38
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
39
|
+
}
|
|
40
|
+
return IWebResponse.success(data ?? []).to_compatible();
|
|
41
|
+
}
|
|
42
|
+
export async function rejectHerdInvitationsWithClient(supabase, invitation_ids) {
|
|
43
|
+
if (invitation_ids.length === 0) {
|
|
44
|
+
return IWebResponse.error("At least one invitation id is required").to_compatible();
|
|
45
|
+
}
|
|
46
|
+
const { data, error } = await supabase.rpc("reject_herd_invitations_for_current_user", { p_invitation_ids: invitation_ids });
|
|
47
|
+
if (error) {
|
|
48
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
49
|
+
}
|
|
50
|
+
return IWebResponse.success(data ?? []).to_compatible();
|
|
51
|
+
}
|
|
52
|
+
export async function revokeHerdInvitationsWithClient(supabase, invitation_ids) {
|
|
53
|
+
if (invitation_ids.length === 0) {
|
|
54
|
+
return IWebResponse.error("At least one invitation id is required").to_compatible();
|
|
55
|
+
}
|
|
56
|
+
const { data, error } = await supabase.rpc("revoke_herd_invitations", {
|
|
57
|
+
p_invitation_ids: invitation_ids,
|
|
58
|
+
});
|
|
59
|
+
if (error) {
|
|
60
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
61
|
+
}
|
|
62
|
+
return IWebResponse.success(data ?? []).to_compatible();
|
|
63
|
+
}
|
package/dist/helpers/layers.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { Database } from "../types/supabase";
|
|
2
1
|
import { ILayer } from "../types/db";
|
|
3
2
|
import { IWebResponseCompatible } from "../types/requests";
|
|
4
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
5
3
|
export declare function server_get_layers_by_herd(herd_id: number): Promise<IWebResponseCompatible<ILayer[]>>;
|
|
6
|
-
export declare function server_get_layers_by_herd_ids(herd_ids: number[]
|
|
4
|
+
export declare function server_get_layers_by_herd_ids(herd_ids: number[]): Promise<IWebResponseCompatible<Record<number, ILayer[]>>>;
|
package/dist/helpers/layers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { newServerClient } from "../supabase/server";
|
|
3
3
|
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
4
|
+
import { get_layers_by_herd_ids_query } from "./herd_scoped.queries";
|
|
4
5
|
// function that fetches the layers from our db given a herd id
|
|
5
6
|
export async function server_get_layers_by_herd(herd_id) {
|
|
6
7
|
const supabase = await newServerClient();
|
|
@@ -20,22 +21,6 @@ export async function server_get_layers_by_herd(herd_id) {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
// Fetches layers for many herds in one query, grouped by herd_id.
|
|
23
|
-
export async function server_get_layers_by_herd_ids(herd_ids
|
|
24
|
-
|
|
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
|
-
if (error) {
|
|
34
|
-
return { status: EnumWebResponse.ERROR, msg: error.message, data: null };
|
|
35
|
-
}
|
|
36
|
-
const grouped = {};
|
|
37
|
-
for (const row of data ?? []) {
|
|
38
|
-
(grouped[_a = row.herd_id] ?? (grouped[_a] = [])).push(row);
|
|
39
|
-
}
|
|
40
|
-
return IWebResponse.success(grouped).to_compatible();
|
|
24
|
+
export async function server_get_layers_by_herd_ids(herd_ids) {
|
|
25
|
+
return get_layers_by_herd_ids_query(await newServerClient(), herd_ids);
|
|
41
26
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { ILayer } from "../types/db";
|
|
3
|
+
import { Database } from "../types/supabase";
|
|
4
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
5
|
+
export declare function get_layers_by_herd_ids_query(client: SupabaseClient<Database>, herd_ids: number[]): Promise<IWebResponseCompatible<Record<number, ILayer[]>>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
2
|
+
export async function get_layers_by_herd_ids_query(client, herd_ids) {
|
|
3
|
+
var _a;
|
|
4
|
+
if (herd_ids.length === 0) {
|
|
5
|
+
return IWebResponse.success({}).to_compatible();
|
|
6
|
+
}
|
|
7
|
+
const { data, error } = await client
|
|
8
|
+
.from("layers")
|
|
9
|
+
.select("*")
|
|
10
|
+
.in("herd_id", herd_ids)
|
|
11
|
+
.order("id", { ascending: true });
|
|
12
|
+
if (error) {
|
|
13
|
+
return { status: EnumWebResponse.ERROR, msg: error.message, data: null };
|
|
14
|
+
}
|
|
15
|
+
const grouped = {};
|
|
16
|
+
for (const row of data ?? []) {
|
|
17
|
+
(grouped[_a = row.herd_id] ?? (grouped[_a] = [])).push(row);
|
|
18
|
+
}
|
|
19
|
+
return IWebResponse.success(grouped).to_compatible();
|
|
20
|
+
}
|
package/dist/helpers/plans.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { Database } from "../types/supabase";
|
|
2
1
|
import { IPlan } from "../types/db";
|
|
3
2
|
import { IWebResponseCompatible } from "../types/requests";
|
|
4
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
5
3
|
export declare function server_get_plans_by_herd(herd_id: number): Promise<IWebResponseCompatible<IPlan[]>>;
|
|
6
|
-
export declare function server_get_plans_by_herd_ids(herd_ids: number[]
|
|
4
|
+
export declare function server_get_plans_by_herd_ids(herd_ids: number[]): Promise<IWebResponseCompatible<Record<number, IPlan[]>>>;
|
|
7
5
|
export declare function server_create_plans(plans: IPlan[]): Promise<IWebResponseCompatible<IPlan[]>>;
|
|
8
6
|
export declare function server_delete_plans_by_ids(plan_ids: number[]): Promise<IWebResponseCompatible<boolean>>;
|
package/dist/helpers/plans.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { newServerClient } from "../supabase/server";
|
|
3
3
|
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
4
|
+
import { get_plans_by_herd_ids_query } from "./herd_scoped.queries";
|
|
4
5
|
// function that fetches the plans our db given a herd id
|
|
5
6
|
export async function server_get_plans_by_herd(herd_id) {
|
|
6
7
|
const supabase = await newServerClient();
|
|
@@ -20,24 +21,8 @@ export async function server_get_plans_by_herd(herd_id) {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
// Fetches plans for many herds in one query, grouped by herd_id.
|
|
23
|
-
export async function server_get_plans_by_herd_ids(herd_ids
|
|
24
|
-
|
|
25
|
-
if (herd_ids.length === 0) {
|
|
26
|
-
return IWebResponse.success({}).to_compatible();
|
|
27
|
-
}
|
|
28
|
-
const { data, error } = await client
|
|
29
|
-
.from("plans")
|
|
30
|
-
.select("*")
|
|
31
|
-
.in("herd_id", herd_ids)
|
|
32
|
-
.order("id", { ascending: true });
|
|
33
|
-
if (error) {
|
|
34
|
-
return { status: EnumWebResponse.ERROR, msg: error.message, data: null };
|
|
35
|
-
}
|
|
36
|
-
const grouped = {};
|
|
37
|
-
for (const row of data ?? []) {
|
|
38
|
-
(grouped[_a = row.herd_id] ?? (grouped[_a] = [])).push(row);
|
|
39
|
-
}
|
|
40
|
-
return IWebResponse.success(grouped).to_compatible();
|
|
24
|
+
export async function server_get_plans_by_herd_ids(herd_ids) {
|
|
25
|
+
return get_plans_by_herd_ids_query(await newServerClient(), herd_ids);
|
|
41
26
|
}
|
|
42
27
|
// function that uploads plan to our db
|
|
43
28
|
export async function server_create_plans(plans) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { IPlan } 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[]>>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
2
|
+
export async function get_plans_by_herd_ids_query(client, herd_ids) {
|
|
3
|
+
var _a;
|
|
4
|
+
if (herd_ids.length === 0) {
|
|
5
|
+
return IWebResponse.success({}).to_compatible();
|
|
6
|
+
}
|
|
7
|
+
const { data, error } = await client
|
|
8
|
+
.from("plans")
|
|
9
|
+
.select("*")
|
|
10
|
+
.in("herd_id", herd_ids)
|
|
11
|
+
.order("id", { ascending: true });
|
|
12
|
+
if (error) {
|
|
13
|
+
return { status: EnumWebResponse.ERROR, msg: error.message, data: null };
|
|
14
|
+
}
|
|
15
|
+
const grouped = {};
|
|
16
|
+
for (const row of data ?? []) {
|
|
17
|
+
(grouped[_a = row.herd_id] ?? (grouped[_a] = [])).push(row);
|
|
18
|
+
}
|
|
19
|
+
return IWebResponse.success(grouped).to_compatible();
|
|
20
|
+
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { Database } from "../types/supabase";
|
|
2
1
|
import { IProvider } from "../types/db";
|
|
3
2
|
import { IWebResponseCompatible } from "../types/requests";
|
|
4
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
5
3
|
export declare function server_get_providers_by_herd(herd_id: number): Promise<IWebResponseCompatible<IProvider[]>>;
|
|
6
|
-
export declare function server_get_providers_by_herd_ids(herd_ids: number[]
|
|
4
|
+
export declare function server_get_providers_by_herd_ids(herd_ids: number[]): Promise<IWebResponseCompatible<Record<number, IProvider[]>>>;
|
|
7
5
|
export declare function server_create_provider(provider: Omit<IProvider, "id" | "created_at">): Promise<IWebResponseCompatible<IProvider>>;
|
|
8
6
|
export declare function server_update_provider(provider_id: number, updates: Partial<Omit<IProvider, "id" | "created_at">>): Promise<IWebResponseCompatible<IProvider>>;
|
|
9
7
|
export declare function server_delete_providers_by_ids(provider_ids: number[]): Promise<IWebResponseCompatible<boolean>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { newServerClient } from "../supabase/server";
|
|
3
3
|
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
4
|
+
import { get_providers_by_herd_ids_query } from "./herd_scoped.queries";
|
|
4
5
|
// function that fetches the providers from our db given a herd id
|
|
5
6
|
export async function server_get_providers_by_herd(herd_id) {
|
|
6
7
|
const supabase = await newServerClient();
|
|
@@ -20,24 +21,8 @@ export async function server_get_providers_by_herd(herd_id) {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
// Fetches providers for many herds in one query, grouped by herd_id.
|
|
23
|
-
export async function server_get_providers_by_herd_ids(herd_ids
|
|
24
|
-
|
|
25
|
-
if (herd_ids.length === 0) {
|
|
26
|
-
return IWebResponse.success({}).to_compatible();
|
|
27
|
-
}
|
|
28
|
-
const { data, error } = await client
|
|
29
|
-
.from("providers")
|
|
30
|
-
.select("*")
|
|
31
|
-
.in("herd_id", herd_ids)
|
|
32
|
-
.order("id", { ascending: true });
|
|
33
|
-
if (error) {
|
|
34
|
-
return { status: EnumWebResponse.ERROR, msg: error.message, data: null };
|
|
35
|
-
}
|
|
36
|
-
const grouped = {};
|
|
37
|
-
for (const row of data ?? []) {
|
|
38
|
-
(grouped[_a = row.herd_id] ?? (grouped[_a] = [])).push(row);
|
|
39
|
-
}
|
|
40
|
-
return IWebResponse.success(grouped).to_compatible();
|
|
24
|
+
export async function server_get_providers_by_herd_ids(herd_ids) {
|
|
25
|
+
return get_providers_by_herd_ids_query(await newServerClient(), herd_ids);
|
|
41
26
|
}
|
|
42
27
|
// function that creates a new provider in our db
|
|
43
28
|
export async function server_create_provider(provider) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { IProvider } from "../types/db";
|
|
3
|
+
import { Database } from "../types/supabase";
|
|
4
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
5
|
+
export declare function get_providers_by_herd_ids_query(client: SupabaseClient<Database>, herd_ids: number[]): Promise<IWebResponseCompatible<Record<number, IProvider[]>>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
2
|
+
export async function get_providers_by_herd_ids_query(client, herd_ids) {
|
|
3
|
+
var _a;
|
|
4
|
+
if (herd_ids.length === 0) {
|
|
5
|
+
return IWebResponse.success({}).to_compatible();
|
|
6
|
+
}
|
|
7
|
+
const { data, error } = await client
|
|
8
|
+
.from("providers")
|
|
9
|
+
.select("*")
|
|
10
|
+
.in("herd_id", herd_ids)
|
|
11
|
+
.order("id", { ascending: true });
|
|
12
|
+
if (error) {
|
|
13
|
+
return { status: EnumWebResponse.ERROR, msg: error.message, data: null };
|
|
14
|
+
}
|
|
15
|
+
const grouped = {};
|
|
16
|
+
for (const row of data ?? []) {
|
|
17
|
+
(grouped[_a = row.herd_id] ?? (grouped[_a] = [])).push(row);
|
|
18
|
+
}
|
|
19
|
+
return IWebResponse.success(grouped).to_compatible();
|
|
20
|
+
}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
-
import { Database } from "../types/supabase";
|
|
3
1
|
import { IPubsubTokenMint } from "../types/pubsub_token";
|
|
4
2
|
import { IWebResponseCompatible } from "../types/requests";
|
|
5
|
-
export declare function server_mint_pubsub_token(
|
|
6
|
-
client?: SupabaseClient<Database>;
|
|
7
|
-
}): Promise<IWebResponseCompatible<IPubsubTokenMint>>;
|
|
3
|
+
export declare function server_mint_pubsub_token(): Promise<IWebResponseCompatible<IPubsubTokenMint>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { newServerClient } from "../supabase/server";
|
|
3
3
|
import { mint_pubsub_token } from "./pubsub_token";
|
|
4
|
-
export async function server_mint_pubsub_token(
|
|
5
|
-
const client =
|
|
4
|
+
export async function server_mint_pubsub_token() {
|
|
5
|
+
const client = await newServerClient();
|
|
6
6
|
return mint_pubsub_token(client);
|
|
7
7
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ISessionSummary } from "../types/db";
|
|
2
2
|
import { IWebResponseCompatible } from "../types/requests";
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function server_get_session_summaries_with_filters(herd_id?: number, device_id?: number, start_date?: string, end_date?: string, client?: SupabaseClient, min_duration_minutes_caller?: number, min_distance_meters_caller?: number, product_numbers_caller?: string[]): Promise<IWebResponseCompatible<ISessionSummary>>;
|
|
3
|
+
export declare function server_get_session_summaries_by_herd(herd_id: number, min_duration_minutes_caller?: number, min_distance_meters_caller?: number, product_numbers_caller?: string[]): Promise<IWebResponseCompatible<ISessionSummary>>;
|
|
4
|
+
export declare function server_get_session_summaries_by_device(device_id: number, min_duration_minutes_caller?: number, min_distance_meters_caller?: number, product_numbers_caller?: string[]): Promise<IWebResponseCompatible<ISessionSummary>>;
|
|
5
|
+
export declare function server_get_session_summaries_with_filters(herd_id?: number, device_id?: number, start_date?: string, end_date?: string, min_duration_minutes_caller?: number, min_distance_meters_caller?: number, product_numbers_caller?: string[]): Promise<IWebResponseCompatible<ISessionSummary>>;
|
|
@@ -1,60 +1,30 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { newServerClient } from "../supabase/server";
|
|
3
|
-
import {
|
|
4
|
-
export async function server_get_session_summaries_by_herd(herd_id,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
start_date_caller: undefined,
|
|
8
|
-
end_date_caller: undefined,
|
|
9
|
-
device_id_caller: undefined,
|
|
10
|
-
herd_id_caller: herd_id,
|
|
3
|
+
import { get_session_summaries_query } from "./session_summaries.queries";
|
|
4
|
+
export async function server_get_session_summaries_by_herd(herd_id, min_duration_minutes_caller, min_distance_meters_caller, product_numbers_caller) {
|
|
5
|
+
return get_session_summaries_query(await newServerClient(), {
|
|
6
|
+
herd_id,
|
|
11
7
|
min_duration_minutes_caller,
|
|
12
8
|
min_distance_meters_caller,
|
|
13
9
|
product_numbers_caller,
|
|
14
10
|
});
|
|
15
|
-
if (error) {
|
|
16
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
17
|
-
}
|
|
18
|
-
if (!data) {
|
|
19
|
-
return IWebResponse.error("No session summary data returned").to_compatible();
|
|
20
|
-
}
|
|
21
|
-
return IWebResponse.success(data).to_compatible();
|
|
22
11
|
}
|
|
23
|
-
export async function server_get_session_summaries_by_device(device_id,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
start_date_caller: undefined,
|
|
27
|
-
end_date_caller: undefined,
|
|
28
|
-
device_id_caller: device_id,
|
|
29
|
-
herd_id_caller: undefined,
|
|
12
|
+
export async function server_get_session_summaries_by_device(device_id, min_duration_minutes_caller, min_distance_meters_caller, product_numbers_caller) {
|
|
13
|
+
return get_session_summaries_query(await newServerClient(), {
|
|
14
|
+
device_id,
|
|
30
15
|
min_duration_minutes_caller,
|
|
31
16
|
min_distance_meters_caller,
|
|
32
17
|
product_numbers_caller,
|
|
33
18
|
});
|
|
34
|
-
if (error) {
|
|
35
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
36
|
-
}
|
|
37
|
-
if (!data) {
|
|
38
|
-
return IWebResponse.error("No session summary data returned").to_compatible();
|
|
39
|
-
}
|
|
40
|
-
return IWebResponse.success(data).to_compatible();
|
|
41
19
|
}
|
|
42
|
-
export async function server_get_session_summaries_with_filters(herd_id, device_id, start_date, end_date,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
herd_id_caller: herd_id || undefined,
|
|
20
|
+
export async function server_get_session_summaries_with_filters(herd_id, device_id, start_date, end_date, min_duration_minutes_caller, min_distance_meters_caller, product_numbers_caller) {
|
|
21
|
+
return get_session_summaries_query(await newServerClient(), {
|
|
22
|
+
herd_id,
|
|
23
|
+
device_id,
|
|
24
|
+
start_date,
|
|
25
|
+
end_date,
|
|
49
26
|
min_duration_minutes_caller,
|
|
50
27
|
min_distance_meters_caller,
|
|
51
28
|
product_numbers_caller,
|
|
52
29
|
});
|
|
53
|
-
if (error) {
|
|
54
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
55
|
-
}
|
|
56
|
-
if (!data) {
|
|
57
|
-
return IWebResponse.error("No session summary data returned").to_compatible();
|
|
58
|
-
}
|
|
59
|
-
return IWebResponse.success(data).to_compatible();
|
|
60
30
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { ISessionSummary } from "../types/db";
|
|
3
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
4
|
+
interface SessionSummaryFilters {
|
|
5
|
+
herd_id?: number;
|
|
6
|
+
device_id?: number;
|
|
7
|
+
start_date?: string;
|
|
8
|
+
end_date?: string;
|
|
9
|
+
min_duration_minutes_caller?: number;
|
|
10
|
+
min_distance_meters_caller?: number;
|
|
11
|
+
product_numbers_caller?: string[];
|
|
12
|
+
}
|
|
13
|
+
export declare function get_session_summaries_query(client: SupabaseClient, filters: SessionSummaryFilters): Promise<IWebResponseCompatible<ISessionSummary>>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IWebResponse } from "../types/requests";
|
|
2
|
+
export async function get_session_summaries_query(client, filters) {
|
|
3
|
+
const { data, error } = await client.rpc("get_session_summaries", {
|
|
4
|
+
start_date_caller: filters.start_date || undefined,
|
|
5
|
+
end_date_caller: filters.end_date || undefined,
|
|
6
|
+
device_id_caller: filters.device_id ?? undefined,
|
|
7
|
+
herd_id_caller: filters.herd_id ?? undefined,
|
|
8
|
+
min_duration_minutes_caller: filters.min_duration_minutes_caller,
|
|
9
|
+
min_distance_meters_caller: filters.min_distance_meters_caller,
|
|
10
|
+
product_numbers_caller: filters.product_numbers_caller,
|
|
11
|
+
});
|
|
12
|
+
if (error) {
|
|
13
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
14
|
+
}
|
|
15
|
+
if (!data) {
|
|
16
|
+
return IWebResponse.error("No session summary data returned").to_compatible();
|
|
17
|
+
}
|
|
18
|
+
return IWebResponse.success(data).to_compatible();
|
|
19
|
+
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { ISessionWithCoordinates, ISessionUsageOverTime, IEventAndTagsPrettyLocation, ISession, SessionInsert, SessionUpdate } from "../types/db";
|
|
2
2
|
import { IWebResponseCompatible } from "../types/requests";
|
|
3
|
-
|
|
4
|
-
export declare function server_get_session_by_id(sessionId: number, client?: SupabaseClient): Promise<IWebResponseCompatible<ISessionWithCoordinates | null>>;
|
|
3
|
+
export declare function server_get_session_by_id(sessionId: number): Promise<IWebResponseCompatible<ISessionWithCoordinates | null>>;
|
|
5
4
|
/** Existing sessions within tolerance of start/end timestamps. */
|
|
6
|
-
export declare function server_match_sessions(deviceId: number, timestampStart: string, timestampEnd: string, toleranceSec: number
|
|
7
|
-
export declare function server_get_session_usage_over_time_by_herd(herd_id: number,
|
|
8
|
-
export declare function server_get_session_usage_over_time_by_device(device_id: number,
|
|
5
|
+
export declare function server_match_sessions(deviceId: number, timestampStart: string, timestampEnd: string, toleranceSec: number): Promise<IWebResponseCompatible<ISession[]>>;
|
|
6
|
+
export declare function server_get_session_usage_over_time_by_herd(herd_id: number, min_duration_minutes_caller?: number, min_distance_meters_caller?: number, product_numbers_caller?: string[]): Promise<IWebResponseCompatible<ISessionUsageOverTime>>;
|
|
7
|
+
export declare function server_get_session_usage_over_time_by_device(device_id: number, min_duration_minutes_caller?: number, min_distance_meters_caller?: number, product_numbers_caller?: string[]): Promise<IWebResponseCompatible<ISessionUsageOverTime>>;
|
|
9
8
|
export declare function server_get_events_and_tags_by_session_id(sessionId: number, limit?: number, offset?: number): Promise<IWebResponseCompatible<IEventAndTagsPrettyLocation[]>>;
|
|
10
|
-
export declare function server_insert_session(sessions: SessionInsert | SessionInsert[]
|
|
9
|
+
export declare function server_insert_session(sessions: SessionInsert | SessionInsert[]): Promise<IWebResponseCompatible<ISession[]>>;
|
|
11
10
|
export declare function server_update_session(sessions: (SessionUpdate & {
|
|
12
11
|
id: number;
|
|
13
12
|
}) | (SessionUpdate & {
|
|
14
13
|
id: number;
|
|
15
|
-
})[]
|
|
14
|
+
})[]): Promise<IWebResponseCompatible<ISession[]>>;
|
|
16
15
|
/** Artifact IDs for a session (same device, overlapping session interval). Empty if session or timestamps missing. */
|
|
17
|
-
export declare function server_get_artifact_ids_for_session(sessionId: number
|
|
16
|
+
export declare function server_get_artifact_ids_for_session(sessionId: number): Promise<IWebResponseCompatible<number[]>>;
|