@adventurelabs/scout-core 1.5.4 → 2.0.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/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 +75 -0
- package/dist/client/index.js +82 -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/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 +63 -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 +175 -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 +4 -90
- 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 +77 -0
- package/dist/server/index.js +79 -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 +2 -2
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +5 -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,121 @@
|
|
|
1
|
+
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
2
|
+
function sortConnectivityByTimestamp(data) {
|
|
3
|
+
return data.sort((a, b) => {
|
|
4
|
+
if (!a.timestamp_start || !b.timestamp_start)
|
|
5
|
+
return 0;
|
|
6
|
+
return (new Date(a.timestamp_start).getTime() -
|
|
7
|
+
new Date(b.timestamp_start).getTime());
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export async function get_connectivity_by_session_id_query(client, sessionId) {
|
|
11
|
+
const { data, error } = await client.rpc("get_connectivity_with_coordinates", { session_id_caller: sessionId });
|
|
12
|
+
if (error) {
|
|
13
|
+
console.warn("Error fetching connectivity by session id:", error.message);
|
|
14
|
+
return {
|
|
15
|
+
status: EnumWebResponse.ERROR,
|
|
16
|
+
msg: error.message,
|
|
17
|
+
data: [],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return IWebResponse.success(sortConnectivityByTimestamp(data || [])).to_compatible();
|
|
21
|
+
}
|
|
22
|
+
export async function get_connectivity_by_device_id_query(client, deviceId, timestamp) {
|
|
23
|
+
const { data, error } = await client.rpc("get_connectivity_with_coordinates_by_device_and_timestamp", { device_id_caller: deviceId, timestamp_filter: timestamp });
|
|
24
|
+
if (error) {
|
|
25
|
+
console.warn("Error fetching connectivity by session id:", error.message);
|
|
26
|
+
return {
|
|
27
|
+
status: EnumWebResponse.ERROR,
|
|
28
|
+
msg: error.message,
|
|
29
|
+
data: [],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return IWebResponse.success(sortConnectivityByTimestamp(data || [])).to_compatible();
|
|
33
|
+
}
|
|
34
|
+
export async function insert_connectivity_query(client, connectivity) {
|
|
35
|
+
const connectivityArray = Array.isArray(connectivity)
|
|
36
|
+
? connectivity
|
|
37
|
+
: [connectivity];
|
|
38
|
+
const { data, error } = await client
|
|
39
|
+
.from("connectivity")
|
|
40
|
+
.insert(connectivityArray)
|
|
41
|
+
.select("*");
|
|
42
|
+
if (error) {
|
|
43
|
+
console.warn("Error inserting connectivity:", error.message);
|
|
44
|
+
return {
|
|
45
|
+
status: EnumWebResponse.ERROR,
|
|
46
|
+
msg: error.message,
|
|
47
|
+
data: [],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return IWebResponse.success(data || []).to_compatible();
|
|
51
|
+
}
|
|
52
|
+
export async function update_connectivity_query(client, connectivity) {
|
|
53
|
+
const connectivityArray = Array.isArray(connectivity)
|
|
54
|
+
? connectivity
|
|
55
|
+
: [connectivity];
|
|
56
|
+
const updatedConnectivity = [];
|
|
57
|
+
for (const record of connectivityArray) {
|
|
58
|
+
const { id, ...updateData } = record;
|
|
59
|
+
delete updateData.inserted_at;
|
|
60
|
+
const { data, error } = await client
|
|
61
|
+
.from("connectivity")
|
|
62
|
+
.update(updateData)
|
|
63
|
+
.eq("id", id)
|
|
64
|
+
.select("*")
|
|
65
|
+
.single();
|
|
66
|
+
if (error) {
|
|
67
|
+
console.warn("Error updating connectivity:", error.message);
|
|
68
|
+
return {
|
|
69
|
+
status: EnumWebResponse.ERROR,
|
|
70
|
+
msg: error.message,
|
|
71
|
+
data: [],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (data) {
|
|
75
|
+
updatedConnectivity.push(data);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return IWebResponse.success(updatedConnectivity).to_compatible();
|
|
79
|
+
}
|
|
80
|
+
export async function get_connectivity_for_herd_time_range_query(client, herdId, startTimestamp, endTimestamp, maxCount = 1000, offset = 0) {
|
|
81
|
+
const { data, error } = await client.rpc("get_connectivity_for_herd_time_range", {
|
|
82
|
+
herd_id_caller: herdId,
|
|
83
|
+
start_timestamp_caller: startTimestamp,
|
|
84
|
+
end_timestamp_caller: endTimestamp,
|
|
85
|
+
max_elements_caller: maxCount + 1,
|
|
86
|
+
offset_caller: offset,
|
|
87
|
+
});
|
|
88
|
+
if (error) {
|
|
89
|
+
console.warn("Error fetching connectivity for herd time range:", error.message);
|
|
90
|
+
return {
|
|
91
|
+
status: EnumWebResponse.ERROR,
|
|
92
|
+
msg: error.message,
|
|
93
|
+
data: [],
|
|
94
|
+
hasMore: false,
|
|
95
|
+
nextOffset: offset,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const sorted = sortConnectivityByTimestamp(data || []);
|
|
99
|
+
const hasMore = sorted.length > maxCount;
|
|
100
|
+
const items = hasMore ? sorted.slice(0, maxCount) : sorted;
|
|
101
|
+
return {
|
|
102
|
+
...IWebResponse.success(items).to_compatible(),
|
|
103
|
+
hasMore,
|
|
104
|
+
nextOffset: offset + items.length,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export async function get_connectivity_for_artifact_query(client, artifactId, maxElements = 1000) {
|
|
108
|
+
const { data, error } = await client.rpc("get_connectivity_for_artifact", {
|
|
109
|
+
artifact_id_caller: artifactId,
|
|
110
|
+
max_elements_caller: maxElements,
|
|
111
|
+
});
|
|
112
|
+
if (error) {
|
|
113
|
+
console.warn("Error fetching connectivity for artifact:", error.message);
|
|
114
|
+
return {
|
|
115
|
+
status: EnumWebResponse.ERROR,
|
|
116
|
+
msg: error.message,
|
|
117
|
+
data: [],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return IWebResponse.success(sortConnectivityByTimestamp(data || [])).to_compatible();
|
|
121
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ContactInsert, ContactUpdate } from "../types/db";
|
|
2
|
+
export declare function server_get_contacts_by_herd_id(herd_id: number, options?: {
|
|
3
|
+
include_inactive?: boolean;
|
|
4
|
+
}): Promise<import("../types").IWebResponseCompatible<{
|
|
5
|
+
created_at: string;
|
|
6
|
+
created_by: string | null;
|
|
7
|
+
email: string | null;
|
|
8
|
+
herd_id: number;
|
|
9
|
+
id: number;
|
|
10
|
+
lifecycle: import("../types").Database["public"]["Enums"]["entity_lifecycle"];
|
|
11
|
+
lifecycle_changed_at: string;
|
|
12
|
+
lifecycle_changed_by: string | null;
|
|
13
|
+
lifecycle_reason: string | null;
|
|
14
|
+
name: string;
|
|
15
|
+
phone: string | null;
|
|
16
|
+
updated_at: string;
|
|
17
|
+
updated_by: string | null;
|
|
18
|
+
}[]>>;
|
|
19
|
+
export declare function server_get_contact_by_id(contact_id: number): Promise<import("../types").IWebResponseCompatible<{
|
|
20
|
+
created_at: string;
|
|
21
|
+
created_by: string | null;
|
|
22
|
+
email: string | null;
|
|
23
|
+
herd_id: number;
|
|
24
|
+
id: number;
|
|
25
|
+
lifecycle: import("../types").Database["public"]["Enums"]["entity_lifecycle"];
|
|
26
|
+
lifecycle_changed_at: string;
|
|
27
|
+
lifecycle_changed_by: string | null;
|
|
28
|
+
lifecycle_reason: string | null;
|
|
29
|
+
name: string;
|
|
30
|
+
phone: string | null;
|
|
31
|
+
updated_at: string;
|
|
32
|
+
updated_by: string | null;
|
|
33
|
+
} | null>>;
|
|
34
|
+
export declare function server_create_contact(row: ContactInsert): Promise<import("../types").IWebResponseCompatible<{
|
|
35
|
+
created_at: string;
|
|
36
|
+
created_by: string | null;
|
|
37
|
+
email: string | null;
|
|
38
|
+
herd_id: number;
|
|
39
|
+
id: number;
|
|
40
|
+
lifecycle: import("../types").Database["public"]["Enums"]["entity_lifecycle"];
|
|
41
|
+
lifecycle_changed_at: string;
|
|
42
|
+
lifecycle_changed_by: string | null;
|
|
43
|
+
lifecycle_reason: string | null;
|
|
44
|
+
name: string;
|
|
45
|
+
phone: string | null;
|
|
46
|
+
updated_at: string;
|
|
47
|
+
updated_by: string | null;
|
|
48
|
+
} | null>>;
|
|
49
|
+
export declare function server_update_contact(contact_id: number, patch: ContactUpdate): Promise<import("../types").IWebResponseCompatible<{
|
|
50
|
+
created_at: string;
|
|
51
|
+
created_by: string | null;
|
|
52
|
+
email: string | null;
|
|
53
|
+
herd_id: number;
|
|
54
|
+
id: number;
|
|
55
|
+
lifecycle: import("../types").Database["public"]["Enums"]["entity_lifecycle"];
|
|
56
|
+
lifecycle_changed_at: string;
|
|
57
|
+
lifecycle_changed_by: string | null;
|
|
58
|
+
lifecycle_reason: string | null;
|
|
59
|
+
name: string;
|
|
60
|
+
phone: string | null;
|
|
61
|
+
updated_at: string;
|
|
62
|
+
updated_by: string | null;
|
|
63
|
+
} | null>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { newServerClient } from "../supabase/server";
|
|
2
|
+
import { create_contact, get_contact_by_id, get_contacts_by_herd_id, update_contact, } from "./contacts";
|
|
3
|
+
export async function server_get_contacts_by_herd_id(herd_id, options) {
|
|
4
|
+
const client = await newServerClient();
|
|
5
|
+
return get_contacts_by_herd_id(client, herd_id, options);
|
|
6
|
+
}
|
|
7
|
+
export async function server_get_contact_by_id(contact_id) {
|
|
8
|
+
const client = await newServerClient();
|
|
9
|
+
return get_contact_by_id(client, contact_id);
|
|
10
|
+
}
|
|
11
|
+
export async function server_create_contact(row) {
|
|
12
|
+
const client = await newServerClient();
|
|
13
|
+
return create_contact(client, row);
|
|
14
|
+
}
|
|
15
|
+
export async function server_update_contact(contact_id, patch) {
|
|
16
|
+
const client = await newServerClient();
|
|
17
|
+
return update_contact(client, contact_id, patch);
|
|
18
|
+
}
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
"use server";
|
|
2
1
|
import { newServerClient } from "../supabase/server";
|
|
3
|
-
import {
|
|
2
|
+
import { transfer_device_to_herd_query } from "./deviceTransfer.queries";
|
|
4
3
|
export async function transferDeviceToHerd(deviceId, targetHerdId) {
|
|
5
|
-
|
|
6
|
-
const { error } = await client.rpc("transfer_device_to_herd", {
|
|
7
|
-
p_device_id: deviceId,
|
|
8
|
-
p_target_herd_id: targetHerdId,
|
|
9
|
-
});
|
|
10
|
-
if (error) {
|
|
11
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
12
|
-
}
|
|
13
|
-
return IWebResponse.success(true).to_compatible();
|
|
4
|
+
return transfer_device_to_herd_query(await newServerClient(), deviceId, targetHerdId);
|
|
14
5
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
3
|
+
import { Database } from "../types/supabase";
|
|
4
|
+
export declare function transfer_device_to_herd_query(client: SupabaseClient<Database>, deviceId: number, targetHerdId: number): Promise<IWebResponseCompatible<boolean>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IWebResponse } from "../types/requests";
|
|
2
|
+
export async function transfer_device_to_herd_query(client, deviceId, targetHerdId) {
|
|
3
|
+
const { error } = await client.rpc("transfer_device_to_herd", {
|
|
4
|
+
p_device_id: deviceId,
|
|
5
|
+
p_target_herd_id: targetHerdId,
|
|
6
|
+
});
|
|
7
|
+
if (error) {
|
|
8
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
9
|
+
}
|
|
10
|
+
return IWebResponse.success(true).to_compatible();
|
|
11
|
+
}
|
package/dist/helpers/devices.js
CHANGED
|
@@ -1,71 +1,14 @@
|
|
|
1
|
-
"use server";
|
|
2
1
|
import { newServerClient } from "../supabase/server";
|
|
3
|
-
import {
|
|
4
|
-
import { get_devices_by_herd_query } from "./devices.queries";
|
|
2
|
+
import { create_device_query, delete_device_by_id_query, get_devices_by_herd_query, update_device_query, } from "./devices.queries";
|
|
5
3
|
export async function get_devices_by_herd(herd_id) {
|
|
6
4
|
return get_devices_by_herd_query(await newServerClient(), herd_id);
|
|
7
5
|
}
|
|
8
6
|
export async function serverUpdateDevice(updatedDevice) {
|
|
9
|
-
|
|
10
|
-
const device_formatted = { ...updatedDevice };
|
|
11
|
-
delete device_formatted.api_keys_scout;
|
|
12
|
-
const device_latitude = device_formatted.latitude;
|
|
13
|
-
const device_longitude = device_formatted.longitude;
|
|
14
|
-
delete device_formatted.latitude;
|
|
15
|
-
delete device_formatted.longitude;
|
|
16
|
-
delete device_formatted.recent_events;
|
|
17
|
-
const supabase = await newServerClient();
|
|
18
|
-
const { data, error } = await supabase
|
|
19
|
-
.from("devices")
|
|
20
|
-
.update(device_formatted)
|
|
21
|
-
.match({ id: device_formatted.id })
|
|
22
|
-
.select("*");
|
|
23
|
-
if (error) {
|
|
24
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
const updatedDevice = {
|
|
28
|
-
...data[0],
|
|
29
|
-
latitude: device_latitude,
|
|
30
|
-
longitude: device_longitude,
|
|
31
|
-
};
|
|
32
|
-
return IWebResponse.success(updatedDevice).to_compatible();
|
|
33
|
-
}
|
|
7
|
+
return update_device_query(await newServerClient(), updatedDevice);
|
|
34
8
|
}
|
|
35
9
|
export async function serverCreateDevice(newDevice) {
|
|
36
|
-
|
|
37
|
-
const user = await supabase.auth.getUser();
|
|
38
|
-
const userId = user?.data?.user?.id;
|
|
39
|
-
if (!userId) {
|
|
40
|
-
return IWebResponse.error("User not found").to_compatible();
|
|
41
|
-
}
|
|
42
|
-
newDevice.created_by = userId;
|
|
43
|
-
// strip id field from herd object
|
|
44
|
-
const { data, error } = await supabase
|
|
45
|
-
.from("devices")
|
|
46
|
-
.insert([newDevice])
|
|
47
|
-
.select("*");
|
|
48
|
-
if (error) {
|
|
49
|
-
// TODO: ALLOW PROPERTY INSTANTION OF CPMPATIBLE WEB RESPONSE
|
|
50
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
const newDevice = { ...data[0], latitude: 0, longitude: 0 };
|
|
54
|
-
return IWebResponse.success(newDevice).to_compatible();
|
|
55
|
-
}
|
|
10
|
+
return create_device_query(await newServerClient(), newDevice);
|
|
56
11
|
}
|
|
57
12
|
export async function serverDeleteDeviceById(device_id) {
|
|
58
|
-
|
|
59
|
-
const { data, error } = await supabase
|
|
60
|
-
.from("devices")
|
|
61
|
-
.delete()
|
|
62
|
-
.match({ id: device_id })
|
|
63
|
-
.select("*");
|
|
64
|
-
if (error) {
|
|
65
|
-
return IWebResponse.error(error.message).to_compatible();
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
const deletedDevice = { ...data[0], latitude: 0, longitude: 0 };
|
|
69
|
-
return IWebResponse.success(deletedDevice).to_compatible();
|
|
70
|
-
}
|
|
13
|
+
return delete_device_by_id_query(await newServerClient(), device_id);
|
|
71
14
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
-
import { IDevice } from "../types/db";
|
|
2
|
+
import { DeviceInsert, IDevice } from "../types/db";
|
|
3
3
|
import { Database } from "../types/supabase";
|
|
4
4
|
import { IWebResponseCompatible } from "../types/requests";
|
|
5
5
|
export declare function get_devices_by_herd_query(client: SupabaseClient<Database>, herd_id: number): Promise<IWebResponseCompatible<IDevice[]>>;
|
|
6
|
+
export declare function update_device_query(client: SupabaseClient<Database>, updatedDevice: IDevice): Promise<IWebResponseCompatible<IDevice | null>>;
|
|
7
|
+
export declare function create_device_query(client: SupabaseClient<Database>, newDevice: DeviceInsert): Promise<IWebResponseCompatible<IDevice | null>>;
|
|
8
|
+
export declare function delete_device_by_id_query(client: SupabaseClient<Database>, device_id: number): Promise<IWebResponseCompatible<IDevice | null>>;
|
|
@@ -8,3 +8,55 @@ export async function get_devices_by_herd_query(client, herd_id) {
|
|
|
8
8
|
}
|
|
9
9
|
return IWebResponse.success(data).to_compatible();
|
|
10
10
|
}
|
|
11
|
+
export async function update_device_query(client, updatedDevice) {
|
|
12
|
+
const device_formatted = { ...updatedDevice };
|
|
13
|
+
delete device_formatted.api_keys_scout;
|
|
14
|
+
const device_latitude = device_formatted.latitude;
|
|
15
|
+
const device_longitude = device_formatted.longitude;
|
|
16
|
+
delete device_formatted.latitude;
|
|
17
|
+
delete device_formatted.longitude;
|
|
18
|
+
delete device_formatted.recent_events;
|
|
19
|
+
const { data, error } = await client
|
|
20
|
+
.from("devices")
|
|
21
|
+
.update(device_formatted)
|
|
22
|
+
.match({ id: device_formatted.id })
|
|
23
|
+
.select("*");
|
|
24
|
+
if (error) {
|
|
25
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
26
|
+
}
|
|
27
|
+
const updated = {
|
|
28
|
+
...data[0],
|
|
29
|
+
latitude: device_latitude,
|
|
30
|
+
longitude: device_longitude,
|
|
31
|
+
};
|
|
32
|
+
return IWebResponse.success(updated).to_compatible();
|
|
33
|
+
}
|
|
34
|
+
export async function create_device_query(client, newDevice) {
|
|
35
|
+
const user = await client.auth.getUser();
|
|
36
|
+
const userId = user?.data?.user?.id;
|
|
37
|
+
if (!userId) {
|
|
38
|
+
return IWebResponse.error("User not found").to_compatible();
|
|
39
|
+
}
|
|
40
|
+
newDevice.created_by = userId;
|
|
41
|
+
const { data, error } = await client
|
|
42
|
+
.from("devices")
|
|
43
|
+
.insert([newDevice])
|
|
44
|
+
.select("*");
|
|
45
|
+
if (error) {
|
|
46
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
47
|
+
}
|
|
48
|
+
const created = { ...data[0], latitude: 0, longitude: 0 };
|
|
49
|
+
return IWebResponse.success(created).to_compatible();
|
|
50
|
+
}
|
|
51
|
+
export async function delete_device_by_id_query(client, device_id) {
|
|
52
|
+
const { data, error } = await client
|
|
53
|
+
.from("devices")
|
|
54
|
+
.delete()
|
|
55
|
+
.match({ id: device_id })
|
|
56
|
+
.select("*");
|
|
57
|
+
if (error) {
|
|
58
|
+
return IWebResponse.error(error.message).to_compatible();
|
|
59
|
+
}
|
|
60
|
+
const deleted = { ...data[0], latitude: 0, longitude: 0 };
|
|
61
|
+
return IWebResponse.success(deleted).to_compatible();
|
|
62
|
+
}
|
|
@@ -1,63 +1,17 @@
|
|
|
1
|
-
"use server";
|
|
2
1
|
import { newServerClient } from "../supabase/server";
|
|
3
|
-
import {
|
|
2
|
+
import { create_document_template_query, get_document_template_by_id_query, get_document_templates_by_localization_query, get_document_templates_query, update_document_template_query, } from "./document_templates.queries";
|
|
4
3
|
export async function server_get_document_templates() {
|
|
5
|
-
|
|
6
|
-
const { data, error } = await supabase
|
|
7
|
-
.from("document_templates")
|
|
8
|
-
.select("*")
|
|
9
|
-
.order("name");
|
|
10
|
-
if (error) {
|
|
11
|
-
return { status: EnumWebResponse.ERROR, msg: error.message, data: [] };
|
|
12
|
-
}
|
|
13
|
-
return IWebResponse.success(data ?? []).to_compatible();
|
|
4
|
+
return get_document_templates_query(await newServerClient());
|
|
14
5
|
}
|
|
15
6
|
export async function server_get_document_template_by_id(template_id) {
|
|
16
|
-
|
|
17
|
-
const { data, error } = await supabase
|
|
18
|
-
.from("document_templates")
|
|
19
|
-
.select("*")
|
|
20
|
-
.eq("id", template_id)
|
|
21
|
-
.maybeSingle();
|
|
22
|
-
if (error) {
|
|
23
|
-
return { status: EnumWebResponse.ERROR, msg: error.message, data: null };
|
|
24
|
-
}
|
|
25
|
-
return IWebResponse.success(data).to_compatible();
|
|
7
|
+
return get_document_template_by_id_query(await newServerClient(), template_id);
|
|
26
8
|
}
|
|
27
9
|
export async function server_get_document_templates_by_localization(localization_id) {
|
|
28
|
-
|
|
29
|
-
const { data, error } = await supabase
|
|
30
|
-
.from("document_templates")
|
|
31
|
-
.select("*")
|
|
32
|
-
.eq("localization_id", localization_id)
|
|
33
|
-
.order("name");
|
|
34
|
-
if (error) {
|
|
35
|
-
return { status: EnumWebResponse.ERROR, msg: error.message, data: [] };
|
|
36
|
-
}
|
|
37
|
-
return IWebResponse.success(data ?? []).to_compatible();
|
|
10
|
+
return get_document_templates_by_localization_query(await newServerClient(), localization_id);
|
|
38
11
|
}
|
|
39
12
|
export async function server_create_document_template(row) {
|
|
40
|
-
|
|
41
|
-
const { data, error } = await supabase
|
|
42
|
-
.from("document_templates")
|
|
43
|
-
.insert(row)
|
|
44
|
-
.select("*")
|
|
45
|
-
.single();
|
|
46
|
-
if (error) {
|
|
47
|
-
return { status: EnumWebResponse.ERROR, msg: error.message, data: null };
|
|
48
|
-
}
|
|
49
|
-
return IWebResponse.success(data).to_compatible();
|
|
13
|
+
return create_document_template_query(await newServerClient(), row);
|
|
50
14
|
}
|
|
51
15
|
export async function server_update_document_template(template_id, updates) {
|
|
52
|
-
|
|
53
|
-
const { data, error } = await supabase
|
|
54
|
-
.from("document_templates")
|
|
55
|
-
.update(updates)
|
|
56
|
-
.eq("id", template_id)
|
|
57
|
-
.select("*")
|
|
58
|
-
.single();
|
|
59
|
-
if (error) {
|
|
60
|
-
return { status: EnumWebResponse.ERROR, msg: error.message, data: null };
|
|
61
|
-
}
|
|
62
|
-
return IWebResponse.success(data).to_compatible();
|
|
16
|
+
return update_document_template_query(await newServerClient(), template_id, updates);
|
|
63
17
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { IDocumentTemplate, DocumentTemplateInsert, DocumentTemplateUpdate } from "../types/db";
|
|
3
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
4
|
+
import { Database } from "../types/supabase";
|
|
5
|
+
export declare function get_document_templates_query(client: SupabaseClient<Database>): Promise<IWebResponseCompatible<IDocumentTemplate[]>>;
|
|
6
|
+
export declare function get_document_template_by_id_query(client: SupabaseClient<Database>, template_id: number): Promise<IWebResponseCompatible<IDocumentTemplate | null>>;
|
|
7
|
+
export declare function get_document_templates_by_localization_query(client: SupabaseClient<Database>, localization_id: number): Promise<IWebResponseCompatible<IDocumentTemplate[]>>;
|
|
8
|
+
export declare function create_document_template_query(client: SupabaseClient<Database>, row: DocumentTemplateInsert): Promise<IWebResponseCompatible<IDocumentTemplate | null>>;
|
|
9
|
+
export declare function update_document_template_query(client: SupabaseClient<Database>, template_id: number, updates: DocumentTemplateUpdate): Promise<IWebResponseCompatible<IDocumentTemplate | null>>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
2
|
+
export async function get_document_templates_query(client) {
|
|
3
|
+
const { data, error } = await client
|
|
4
|
+
.from("document_templates")
|
|
5
|
+
.select("*")
|
|
6
|
+
.order("name");
|
|
7
|
+
if (error) {
|
|
8
|
+
return { status: EnumWebResponse.ERROR, msg: error.message, data: [] };
|
|
9
|
+
}
|
|
10
|
+
return IWebResponse.success(data ?? []).to_compatible();
|
|
11
|
+
}
|
|
12
|
+
export async function get_document_template_by_id_query(client, template_id) {
|
|
13
|
+
const { data, error } = await client
|
|
14
|
+
.from("document_templates")
|
|
15
|
+
.select("*")
|
|
16
|
+
.eq("id", template_id)
|
|
17
|
+
.maybeSingle();
|
|
18
|
+
if (error) {
|
|
19
|
+
return { status: EnumWebResponse.ERROR, msg: error.message, data: null };
|
|
20
|
+
}
|
|
21
|
+
return IWebResponse.success(data).to_compatible();
|
|
22
|
+
}
|
|
23
|
+
export async function get_document_templates_by_localization_query(client, localization_id) {
|
|
24
|
+
const { data, error } = await client
|
|
25
|
+
.from("document_templates")
|
|
26
|
+
.select("*")
|
|
27
|
+
.eq("localization_id", localization_id)
|
|
28
|
+
.order("name");
|
|
29
|
+
if (error) {
|
|
30
|
+
return { status: EnumWebResponse.ERROR, msg: error.message, data: [] };
|
|
31
|
+
}
|
|
32
|
+
return IWebResponse.success(data ?? []).to_compatible();
|
|
33
|
+
}
|
|
34
|
+
export async function create_document_template_query(client, row) {
|
|
35
|
+
const { data, error } = await client
|
|
36
|
+
.from("document_templates")
|
|
37
|
+
.insert(row)
|
|
38
|
+
.select("*")
|
|
39
|
+
.single();
|
|
40
|
+
if (error) {
|
|
41
|
+
return { status: EnumWebResponse.ERROR, msg: error.message, data: null };
|
|
42
|
+
}
|
|
43
|
+
return IWebResponse.success(data).to_compatible();
|
|
44
|
+
}
|
|
45
|
+
export async function update_document_template_query(client, template_id, updates) {
|
|
46
|
+
const { data, error } = await client
|
|
47
|
+
.from("document_templates")
|
|
48
|
+
.update(updates)
|
|
49
|
+
.eq("id", template_id)
|
|
50
|
+
.select("*")
|
|
51
|
+
.single();
|
|
52
|
+
if (error) {
|
|
53
|
+
return { status: EnumWebResponse.ERROR, msg: error.message, data: null };
|
|
54
|
+
}
|
|
55
|
+
return IWebResponse.success(data).to_compatible();
|
|
56
|
+
}
|