@adventurelabs/scout-core 1.4.96 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api_keys/actions.d.ts +1 -2
- package/dist/api_keys/actions.js +4 -83
- package/dist/api_keys/queries.d.ts +4 -0
- package/dist/api_keys/queries.js +52 -0
- package/dist/helpers/artifacts.d.ts +10 -15
- package/dist/helpers/artifacts.internal.d.ts +22 -0
- package/dist/helpers/artifacts.internal.js +151 -0
- package/dist/helpers/artifacts.js +48 -81
- package/dist/helpers/client_abilities_jwt_keys.d.ts +3 -4
- package/dist/helpers/client_abilities_jwt_keys.js +7 -7
- package/dist/helpers/client_abilities_jwt_keys_internal.d.ts +9 -0
- package/dist/helpers/client_abilities_jwt_keys_internal.js +20 -0
- package/dist/helpers/client_abilities_token_server.d.ts +1 -5
- package/dist/helpers/client_abilities_token_server.js +2 -2
- package/dist/helpers/connectivity.d.ts +2 -3
- package/dist/helpers/connectivity.internal.d.ts +10 -0
- package/dist/helpers/connectivity.internal.js +47 -0
- package/dist/helpers/connectivity.js +6 -7
- package/dist/helpers/devices.d.ts +1 -3
- package/dist/helpers/devices.js +3 -12
- package/dist/helpers/devices.queries.d.ts +5 -0
- package/dist/helpers/devices.queries.js +10 -0
- package/dist/helpers/documents.d.ts +1 -0
- package/dist/helpers/documents.js +11 -2
- package/dist/helpers/embeddings.d.ts +1 -3
- package/dist/helpers/embeddings.internal.d.ts +5 -0
- package/dist/helpers/embeddings.internal.js +14 -0
- package/dist/helpers/embeddings.js +2 -2
- package/dist/helpers/events.d.ts +4 -6
- package/dist/helpers/events.internal.d.ts +13 -0
- package/dist/helpers/events.internal.js +88 -0
- package/dist/helpers/events.js +16 -17
- package/dist/helpers/herd_allowed_domains.d.ts +1 -3
- package/dist/helpers/herd_allowed_domains.js +2 -2
- package/dist/helpers/herd_allowed_domains_internal.d.ts +5 -0
- package/dist/helpers/herd_allowed_domains_internal.js +12 -0
- package/dist/helpers/herd_modules.queries.d.ts +3 -0
- package/dist/helpers/herd_modules.queries.js +106 -0
- package/dist/helpers/herd_roles.d.ts +12 -14
- package/dist/helpers/herd_roles.js +26 -34
- package/dist/helpers/herd_roles_internal.d.ts +18 -0
- package/dist/helpers/herd_roles_internal.js +159 -0
- package/dist/helpers/herd_scoped.queries.d.ts +7 -0
- package/dist/helpers/herd_scoped.queries.js +45 -0
- package/dist/helpers/herds.d.ts +2 -4
- package/dist/helpers/herds.js +11 -142
- package/dist/helpers/herds.queries.d.ts +5 -0
- package/dist/helpers/herds.queries.js +12 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/invitations.d.ts +4 -6
- package/dist/helpers/invitations.js +8 -8
- package/dist/helpers/invitations_internal.d.ts +10 -0
- package/dist/helpers/invitations_internal.js +63 -0
- package/dist/helpers/layers.d.ts +1 -3
- package/dist/helpers/layers.js +3 -18
- package/dist/helpers/layers.queries.d.ts +5 -0
- package/dist/helpers/layers.queries.js +20 -0
- package/dist/helpers/operating_contexts.d.ts +43 -0
- package/dist/helpers/operating_contexts.js +222 -0
- package/dist/helpers/plans.d.ts +1 -3
- package/dist/helpers/plans.js +3 -18
- package/dist/helpers/plans.queries.d.ts +5 -0
- package/dist/helpers/plans.queries.js +20 -0
- package/dist/helpers/providers.d.ts +1 -3
- package/dist/helpers/providers.js +3 -18
- package/dist/helpers/providers.queries.d.ts +5 -0
- package/dist/helpers/providers.queries.js +20 -0
- package/dist/helpers/pubsub_token_server.d.ts +1 -5
- package/dist/helpers/pubsub_token_server.js +2 -2
- package/dist/helpers/realtime_topic_access.d.ts +5 -0
- package/dist/helpers/realtime_topic_access.js +55 -0
- package/dist/helpers/session_summaries.d.ts +3 -4
- package/dist/helpers/session_summaries.js +13 -43
- package/dist/helpers/session_summaries.queries.d.ts +14 -0
- package/dist/helpers/session_summaries.queries.js +19 -0
- package/dist/helpers/sessions.d.ts +7 -8
- package/dist/helpers/sessions.js +23 -58
- package/dist/helpers/sessions.queries.d.ts +4 -0
- package/dist/helpers/sessions.queries.js +22 -0
- package/dist/helpers/storage.d.ts +2 -4
- package/dist/helpers/storage.js +7 -54
- package/dist/helpers/storage_internal.d.ts +4 -0
- package/dist/helpers/storage_internal.js +29 -0
- package/dist/helpers/tags.js +5 -5
- package/dist/helpers/users.d.ts +7 -8
- package/dist/helpers/users.js +13 -41
- package/dist/helpers/users.queries.d.ts +5 -0
- package/dist/helpers/users.queries.js +30 -0
- package/dist/helpers/versions_software_internal.d.ts +6 -0
- package/dist/helpers/versions_software_internal.js +53 -0
- package/dist/helpers/versions_software_server.d.ts +2 -3
- package/dist/helpers/versions_software_server.js +20 -18
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js +2 -1
- package/dist/hooks/useAuthorizedRealtimeTopics.d.ts +1 -0
- package/dist/hooks/useAuthorizedRealtimeTopics.js +14 -0
- package/dist/hooks/useScoutRealtimeAnalysisJobs.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeAnalysisJobs.js +3 -5
- package/dist/hooks/useScoutRealtimeAnalysisTasks.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeAnalysisTasks.js +3 -5
- package/dist/hooks/useScoutRealtimeBroadcast.d.ts +9 -5
- package/dist/hooks/useScoutRealtimeBroadcast.js +118 -25
- package/dist/hooks/useScoutRealtimeConnectivity.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeConnectivity.js +18 -76
- package/dist/hooks/useScoutRealtimeContacts.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeContacts.js +3 -3
- package/dist/hooks/useScoutRealtimeDevices.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeDevices.js +3 -64
- package/dist/hooks/useScoutRealtimeDocuments.d.ts +3 -3
- package/dist/hooks/useScoutRealtimeDocuments.js +7 -5
- package/dist/hooks/useScoutRealtimeEvents.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeEvents.js +3 -69
- package/dist/hooks/useScoutRealtimeMaintenanceRequests.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeMaintenanceRequests.js +3 -3
- package/dist/hooks/useScoutRealtimeOperatingContexts.d.ts +12 -0
- package/dist/hooks/useScoutRealtimeOperatingContexts.js +26 -0
- package/dist/hooks/useScoutRealtimeParts.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeParts.js +3 -3
- package/dist/hooks/useScoutRealtimePins.d.ts +2 -1
- package/dist/hooks/useScoutRealtimePins.js +3 -69
- package/dist/hooks/useScoutRealtimePlans.d.ts +2 -1
- package/dist/hooks/useScoutRealtimePlans.js +3 -3
- package/dist/hooks/useScoutRealtimeSessionIncidents.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeSessionIncidents.js +3 -3
- package/dist/hooks/useScoutRealtimeSessions.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeSessions.js +3 -69
- package/dist/hooks/useScoutRealtimeTags.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeTags.js +3 -69
- package/dist/hooks/useScoutRealtimeVersionsSoftware.d.ts +2 -1
- package/dist/hooks/useScoutRealtimeVersionsSoftware.js +3 -5
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/providers/ScoutRefreshProvider.d.ts +1 -0
- package/dist/providers/ScoutRefreshProvider.js +3 -0
- package/dist/supabase/server.d.ts +4 -1
- package/dist/supabase/server.js +6 -5
- package/dist/types/db.d.ts +82 -0
- package/dist/types/realtime.d.ts +1 -0
- package/dist/types/supabase.d.ts +952 -100
- package/dist/types/supabase.js +26 -1
- package/package.json +1 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { newServerClient } from "../supabase/server";
|
|
3
|
+
import { IWebResponse } from "../types/requests";
|
|
4
|
+
function error(message) {
|
|
5
|
+
return IWebResponse.error(message).to_compatible();
|
|
6
|
+
}
|
|
7
|
+
function page_limit(options) {
|
|
8
|
+
const limit = options?.limit ?? 100;
|
|
9
|
+
return limit < 1 || limit > 500 ? null : limit;
|
|
10
|
+
}
|
|
11
|
+
async function authenticated_user_id(client) {
|
|
12
|
+
const { data, error: authError } = await client.auth.getUser();
|
|
13
|
+
return authError ? null : (data.user?.id ?? null);
|
|
14
|
+
}
|
|
15
|
+
function with_lifecycle_actor(updates, user_id) {
|
|
16
|
+
return updates.lifecycle
|
|
17
|
+
? { ...updates, lifecycle_changed_by: user_id }
|
|
18
|
+
: updates;
|
|
19
|
+
}
|
|
20
|
+
function with_update_actor(updates, user_id) {
|
|
21
|
+
return { ...with_lifecycle_actor(updates, user_id), updated_by: user_id };
|
|
22
|
+
}
|
|
23
|
+
function update_error(updates) {
|
|
24
|
+
if (Object.keys(updates).length === 0)
|
|
25
|
+
return "no fields to update";
|
|
26
|
+
if (updates.lifecycle_reason !== undefined && updates.lifecycle === undefined) {
|
|
27
|
+
return "lifecycle_reason requires lifecycle";
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
async function list_by(table, column, value, options) {
|
|
32
|
+
const limit = page_limit(options);
|
|
33
|
+
if (limit == null)
|
|
34
|
+
return error("limit must be between 1 and 500");
|
|
35
|
+
const supabase = await newServerClient();
|
|
36
|
+
let query = supabase
|
|
37
|
+
.from(table)
|
|
38
|
+
.select("*")
|
|
39
|
+
.eq(column, value)
|
|
40
|
+
.order("id")
|
|
41
|
+
.limit(limit);
|
|
42
|
+
if (!options?.include_inactive)
|
|
43
|
+
query = query.eq("lifecycle", "active");
|
|
44
|
+
if (options?.after_id != null)
|
|
45
|
+
query = query.gt("id", options.after_id);
|
|
46
|
+
const { data, error: queryError } = await query;
|
|
47
|
+
return queryError
|
|
48
|
+
? error(queryError.message)
|
|
49
|
+
: IWebResponse.success((data ?? [])).to_compatible();
|
|
50
|
+
}
|
|
51
|
+
async function insert_row(table, row) {
|
|
52
|
+
const supabase = await newServerClient();
|
|
53
|
+
const { data, error: queryError } = await supabase
|
|
54
|
+
.from(table)
|
|
55
|
+
.insert(row)
|
|
56
|
+
.select("*")
|
|
57
|
+
.single();
|
|
58
|
+
return queryError
|
|
59
|
+
? error(queryError.message)
|
|
60
|
+
: IWebResponse.success(data).to_compatible();
|
|
61
|
+
}
|
|
62
|
+
async function insert_with_creator(table, row) {
|
|
63
|
+
const supabase = await newServerClient();
|
|
64
|
+
const user_id = await authenticated_user_id(supabase);
|
|
65
|
+
if (!user_id)
|
|
66
|
+
return error("authentication required");
|
|
67
|
+
const { data, error: queryError } = await supabase
|
|
68
|
+
.from(table)
|
|
69
|
+
.insert({ ...row, created_by: user_id })
|
|
70
|
+
.select("*")
|
|
71
|
+
.single();
|
|
72
|
+
return queryError
|
|
73
|
+
? error(queryError.message)
|
|
74
|
+
: IWebResponse.success(data).to_compatible();
|
|
75
|
+
}
|
|
76
|
+
async function patch_row(table, id, updates, actor) {
|
|
77
|
+
const invalid = update_error(updates);
|
|
78
|
+
if (invalid)
|
|
79
|
+
return error(invalid);
|
|
80
|
+
const supabase = await newServerClient();
|
|
81
|
+
const user_id = await authenticated_user_id(supabase);
|
|
82
|
+
if (!user_id)
|
|
83
|
+
return error("authentication required");
|
|
84
|
+
const payload = actor === "update"
|
|
85
|
+
? with_update_actor(updates, user_id)
|
|
86
|
+
: with_lifecycle_actor(updates, user_id);
|
|
87
|
+
const { data, error: queryError } = await supabase
|
|
88
|
+
.from(table)
|
|
89
|
+
.update(payload)
|
|
90
|
+
.eq("id", id)
|
|
91
|
+
.select("*")
|
|
92
|
+
.single();
|
|
93
|
+
return queryError
|
|
94
|
+
? error(queryError.message)
|
|
95
|
+
: IWebResponse.success(data).to_compatible();
|
|
96
|
+
}
|
|
97
|
+
export async function server_get_document_conditions_by_localization(localization_id, options) {
|
|
98
|
+
return list_by("document_conditions", "localization_id", localization_id, options);
|
|
99
|
+
}
|
|
100
|
+
export async function server_create_document_condition(row) {
|
|
101
|
+
return insert_row("document_conditions", row);
|
|
102
|
+
}
|
|
103
|
+
export async function server_update_document_condition(id, updates) {
|
|
104
|
+
return patch_row("document_conditions", id, updates, "lifecycle");
|
|
105
|
+
}
|
|
106
|
+
export async function server_get_operating_context_types_by_localization(localization_id, options) {
|
|
107
|
+
return list_by("operating_context_types", "localization_id", localization_id, options);
|
|
108
|
+
}
|
|
109
|
+
export async function server_create_operating_context_type(row) {
|
|
110
|
+
return insert_row("operating_context_types", row);
|
|
111
|
+
}
|
|
112
|
+
export async function server_update_operating_context_type(id, updates) {
|
|
113
|
+
return patch_row("operating_context_types", id, updates, "lifecycle");
|
|
114
|
+
}
|
|
115
|
+
export async function server_get_operating_context_roles_by_localization(localization_id, options) {
|
|
116
|
+
return list_by("operating_context_roles", "localization_id", localization_id, options);
|
|
117
|
+
}
|
|
118
|
+
export async function server_create_operating_context_role(row) {
|
|
119
|
+
return insert_row("operating_context_roles", row);
|
|
120
|
+
}
|
|
121
|
+
export async function server_update_operating_context_role(id, updates) {
|
|
122
|
+
return patch_row("operating_context_roles", id, updates, "lifecycle");
|
|
123
|
+
}
|
|
124
|
+
export async function server_get_operating_context_equipment_categories_by_localization(localization_id, options) {
|
|
125
|
+
return list_by("operating_context_equipment_categories", "localization_id", localization_id, options);
|
|
126
|
+
}
|
|
127
|
+
export async function server_create_operating_context_equipment_category(row) {
|
|
128
|
+
return insert_row("operating_context_equipment_categories", row);
|
|
129
|
+
}
|
|
130
|
+
export async function server_update_operating_context_equipment_category(id, updates) {
|
|
131
|
+
return patch_row("operating_context_equipment_categories", id, updates, "lifecycle");
|
|
132
|
+
}
|
|
133
|
+
export async function server_get_operating_context_equipment_items_by_category(equipment_category_id, options) {
|
|
134
|
+
return list_by("operating_context_equipment_items", "equipment_category_id", equipment_category_id, options);
|
|
135
|
+
}
|
|
136
|
+
export async function server_create_operating_context_equipment_item(row) {
|
|
137
|
+
return insert_row("operating_context_equipment_items", row);
|
|
138
|
+
}
|
|
139
|
+
export async function server_update_operating_context_equipment_item(id, updates) {
|
|
140
|
+
return patch_row("operating_context_equipment_items", id, updates, "lifecycle");
|
|
141
|
+
}
|
|
142
|
+
export async function server_get_operating_contexts_by_herd(herd_id, options) {
|
|
143
|
+
return list_by("operating_contexts", "herd_id", herd_id, options);
|
|
144
|
+
}
|
|
145
|
+
export async function server_get_operating_context_by_id(id) {
|
|
146
|
+
const supabase = await newServerClient();
|
|
147
|
+
const { data, error: queryError } = await supabase
|
|
148
|
+
.from("operating_contexts")
|
|
149
|
+
.select("*")
|
|
150
|
+
.eq("id", id)
|
|
151
|
+
.maybeSingle();
|
|
152
|
+
return queryError
|
|
153
|
+
? error(queryError.message)
|
|
154
|
+
: IWebResponse.success(data).to_compatible();
|
|
155
|
+
}
|
|
156
|
+
export async function server_create_operating_context(row) {
|
|
157
|
+
return insert_with_creator("operating_contexts", row);
|
|
158
|
+
}
|
|
159
|
+
export async function server_update_operating_context(id, updates) {
|
|
160
|
+
return patch_row("operating_contexts", id, updates, "update");
|
|
161
|
+
}
|
|
162
|
+
export async function server_get_operating_context_payloads_by_operating_context(operating_context_id, options) {
|
|
163
|
+
return list_by("operating_context_payloads", "operating_context_id", operating_context_id, options);
|
|
164
|
+
}
|
|
165
|
+
export async function server_create_operating_context_payload(row) {
|
|
166
|
+
return insert_with_creator("operating_context_payloads", row);
|
|
167
|
+
}
|
|
168
|
+
export async function server_update_operating_context_payload(id, updates) {
|
|
169
|
+
return patch_row("operating_context_payloads", id, updates, "update");
|
|
170
|
+
}
|
|
171
|
+
export async function server_get_operating_context_role_assignments_by_operating_context(operating_context_id, options) {
|
|
172
|
+
return list_by("operating_context_role_assignments", "operating_context_id", operating_context_id, options);
|
|
173
|
+
}
|
|
174
|
+
export async function server_create_operating_context_role_assignment(row) {
|
|
175
|
+
return insert_row("operating_context_role_assignments", row);
|
|
176
|
+
}
|
|
177
|
+
export async function server_update_operating_context_role_assignment(id, updates) {
|
|
178
|
+
return patch_row("operating_context_role_assignments", id, updates, "lifecycle");
|
|
179
|
+
}
|
|
180
|
+
export async function server_get_operating_context_equipment_requirements_by_operating_context(operating_context_id, options) {
|
|
181
|
+
return list_by("operating_context_equipment_requirements", "operating_context_id", operating_context_id, options);
|
|
182
|
+
}
|
|
183
|
+
export async function server_create_operating_context_equipment_requirement(row) {
|
|
184
|
+
return insert_row("operating_context_equipment_requirements", row);
|
|
185
|
+
}
|
|
186
|
+
export async function server_update_operating_context_equipment_requirement(id, updates) {
|
|
187
|
+
return patch_row("operating_context_equipment_requirements", id, updates, "lifecycle");
|
|
188
|
+
}
|
|
189
|
+
export async function server_get_operating_context_regions_by_operating_context(operating_context_id, options) {
|
|
190
|
+
return list_by("operating_context_regions", "operating_context_id", operating_context_id, options);
|
|
191
|
+
}
|
|
192
|
+
export async function server_create_operating_context_region(row) {
|
|
193
|
+
return insert_with_creator("operating_context_regions", row);
|
|
194
|
+
}
|
|
195
|
+
export async function server_update_operating_context_region(id, updates) {
|
|
196
|
+
return patch_row("operating_context_regions", id, updates, "update");
|
|
197
|
+
}
|
|
198
|
+
export async function server_get_operating_context_risks_by_operating_context(operating_context_id, options) {
|
|
199
|
+
return list_by("operating_context_risks", "operating_context_id", operating_context_id, options);
|
|
200
|
+
}
|
|
201
|
+
export async function server_create_operating_context_risk(row) {
|
|
202
|
+
return insert_with_creator("operating_context_risks", row);
|
|
203
|
+
}
|
|
204
|
+
export async function server_update_operating_context_risk(id, updates) {
|
|
205
|
+
return patch_row("operating_context_risks", id, updates, "update");
|
|
206
|
+
}
|
|
207
|
+
export async function server_get_operating_context_weather_snapshots(operating_context_id, options) {
|
|
208
|
+
if (options?.limit != null &&
|
|
209
|
+
(options.limit < 1 || options.limit > 500)) {
|
|
210
|
+
return error("limit must be between 1 and 500");
|
|
211
|
+
}
|
|
212
|
+
const supabase = await newServerClient();
|
|
213
|
+
const { data, error: queryError } = await supabase.rpc("get_operating_context_weather_snapshots", {
|
|
214
|
+
operating_context_id_caller: operating_context_id,
|
|
215
|
+
limit_caller: options?.limit,
|
|
216
|
+
cursor_collected_at: options?.cursor?.collected_at,
|
|
217
|
+
cursor_id: options?.cursor?.id,
|
|
218
|
+
});
|
|
219
|
+
return queryError
|
|
220
|
+
? error(queryError.message)
|
|
221
|
+
: IWebResponse.success(data ?? []).to_compatible();
|
|
222
|
+
}
|
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
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IClientAbilitiesTokenMint } from "../types/client_abilities_token";
|
|
2
|
+
import { EnumJwtMintStatus } from "../types/jwt_mint";
|
|
3
|
+
export declare function realtime_topic_ability(topic: string): string;
|
|
4
|
+
export declare function can_access_realtime_topic(mint: IClientAbilitiesTokenMint | null | undefined, topic: string): boolean;
|
|
5
|
+
export declare function filter_realtime_topics(status: EnumJwtMintStatus, mint: IClientAbilitiesTokenMint | null | undefined, topics: string[]): string[];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { can_herd_ability, } from "../types/client_abilities_token";
|
|
2
|
+
import { EnumJwtMintStatus } from "../types/jwt_mint";
|
|
3
|
+
export function realtime_topic_ability(topic) {
|
|
4
|
+
const channel = topic.slice(topic.indexOf("-") + 1);
|
|
5
|
+
switch (channel) {
|
|
6
|
+
case "contacts":
|
|
7
|
+
return "contacts.read";
|
|
8
|
+
case "maintenance_requests":
|
|
9
|
+
return "maintenance_requests.read";
|
|
10
|
+
case "herd_documents":
|
|
11
|
+
return "herd_documents.read";
|
|
12
|
+
case "device_documents":
|
|
13
|
+
return "device_documents.read";
|
|
14
|
+
case "user_documents":
|
|
15
|
+
return "user_documents.read";
|
|
16
|
+
case "operating_contexts":
|
|
17
|
+
case "operating_context_documents":
|
|
18
|
+
return "operating_contexts.read";
|
|
19
|
+
default:
|
|
20
|
+
return "content.read";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function can_access_realtime_topic(mint, topic) {
|
|
24
|
+
if (topic === "versions_software_changes" ||
|
|
25
|
+
/^user_[0-9a-f-]+-documents$/i.test(topic)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
const isProductDocuments = topic === "product_documents_changes";
|
|
29
|
+
const isAnalysis = topic === "analysis_jobs_changes" ||
|
|
30
|
+
topic === "analysis_tasks_changes";
|
|
31
|
+
const herd_match = /^(\d+)-/.exec(topic);
|
|
32
|
+
if (!isProductDocuments && !isAnalysis && !herd_match)
|
|
33
|
+
return true;
|
|
34
|
+
if (!mint?.token || mint.exp <= Math.floor(Date.now() / 1000))
|
|
35
|
+
return false;
|
|
36
|
+
if (isProductDocuments) {
|
|
37
|
+
return (mint.platform_superadmin ||
|
|
38
|
+
mint.herds.some((herd) => herd.abilities.includes("content.read")));
|
|
39
|
+
}
|
|
40
|
+
if (isAnalysis)
|
|
41
|
+
return mint.platform_superadmin;
|
|
42
|
+
if (!herd_match)
|
|
43
|
+
return true;
|
|
44
|
+
return can_herd_ability(mint, Number(herd_match[1]), realtime_topic_ability(topic));
|
|
45
|
+
}
|
|
46
|
+
export function filter_realtime_topics(status, mint, topics) {
|
|
47
|
+
if (status === EnumJwtMintStatus.IDLE)
|
|
48
|
+
return topics;
|
|
49
|
+
if (!mint?.token) {
|
|
50
|
+
return status === EnumJwtMintStatus.LOADING
|
|
51
|
+
? topics.filter((topic) => can_access_realtime_topic(mint, topic))
|
|
52
|
+
: topics;
|
|
53
|
+
}
|
|
54
|
+
return topics.filter((topic) => can_access_realtime_topic(mint, topic));
|
|
55
|
+
}
|
|
@@ -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[]>>;
|