@adventurelabs/scout-core 1.4.89 → 1.4.91

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.
@@ -24,6 +24,7 @@ export * from "./issuers";
24
24
  export * from "./document_templates";
25
25
  export * from "./documents";
26
26
  export * from "./maintenance_requests";
27
+ export * from "./session_incidents";
27
28
  export * from "./contacts";
28
29
  export * from "./plans";
29
30
  export * from "./sessions";
@@ -24,6 +24,7 @@ export * from "./issuers";
24
24
  export * from "./document_templates";
25
25
  export * from "./documents";
26
26
  export * from "./maintenance_requests";
27
+ export * from "./session_incidents";
27
28
  export * from "./contacts";
28
29
  export * from "./plans";
29
30
  export * from "./sessions";
@@ -0,0 +1,9 @@
1
+ import { Database } from "../types/supabase";
2
+ import { ISessionIncident, SessionIncidentInsert, SessionIncidentUpdate } from "../types/db";
3
+ import { IWebResponseCompatible } from "../types/requests";
4
+ import { SupabaseClient } from "@supabase/supabase-js";
5
+ export declare function get_session_incidents_by_session_id(client: SupabaseClient<Database>, session_id: number): Promise<IWebResponseCompatible<ISessionIncident[]>>;
6
+ export declare function get_session_incident_by_id(client: SupabaseClient<Database>, incident_id: number): Promise<IWebResponseCompatible<ISessionIncident | null>>;
7
+ export declare function create_session_incident(client: SupabaseClient<Database>, row: SessionIncidentInsert): Promise<IWebResponseCompatible<ISessionIncident | null>>;
8
+ export declare function update_session_incident(client: SupabaseClient<Database>, incident_id: number, patch: SessionIncidentUpdate): Promise<IWebResponseCompatible<ISessionIncident | null>>;
9
+ export declare function delete_session_incident(client: SupabaseClient<Database>, incident_id: number): Promise<IWebResponseCompatible<ISessionIncident | null>>;
@@ -0,0 +1,78 @@
1
+ import { IWebResponse } from "../types/requests";
2
+ export async function get_session_incidents_by_session_id(client, session_id) {
3
+ const { data, error } = await client
4
+ .from("session_incidents")
5
+ .select("*")
6
+ .eq("session_id", session_id)
7
+ .order("created_at", { ascending: false });
8
+ if (error) {
9
+ return IWebResponse.error(error.message).to_compatible();
10
+ }
11
+ return IWebResponse.success(data ?? []).to_compatible();
12
+ }
13
+ export async function get_session_incident_by_id(client, incident_id) {
14
+ const { data, error } = await client
15
+ .from("session_incidents")
16
+ .select("*")
17
+ .eq("id", incident_id)
18
+ .maybeSingle();
19
+ if (error) {
20
+ return IWebResponse.error(error.message)
21
+ .to_compatible();
22
+ }
23
+ if (!data) {
24
+ return IWebResponse.error("Session incident not found").to_compatible();
25
+ }
26
+ return IWebResponse.success(data).to_compatible();
27
+ }
28
+ export async function create_session_incident(client, row) {
29
+ const { data, error } = await client
30
+ .from("session_incidents")
31
+ .insert([row])
32
+ .select("*")
33
+ .single();
34
+ if (error) {
35
+ return IWebResponse.error(error.message)
36
+ .to_compatible();
37
+ }
38
+ if (!data) {
39
+ return IWebResponse.error("Failed to create session incident").to_compatible();
40
+ }
41
+ return IWebResponse.success(data).to_compatible();
42
+ }
43
+ export async function update_session_incident(client, incident_id, patch) {
44
+ const { id: _id, created_at: _ca, ...updateData } = patch;
45
+ if (Object.keys(updateData).length === 0) {
46
+ return IWebResponse.error("No valid fields to update").to_compatible();
47
+ }
48
+ const { data, error } = await client
49
+ .from("session_incidents")
50
+ .update(updateData)
51
+ .eq("id", incident_id)
52
+ .select("*")
53
+ .single();
54
+ if (error) {
55
+ return IWebResponse.error(error.message)
56
+ .to_compatible();
57
+ }
58
+ if (!data) {
59
+ return IWebResponse.error("Session incident not found").to_compatible();
60
+ }
61
+ return IWebResponse.success(data).to_compatible();
62
+ }
63
+ export async function delete_session_incident(client, incident_id) {
64
+ const { data, error } = await client
65
+ .from("session_incidents")
66
+ .delete()
67
+ .eq("id", incident_id)
68
+ .select("*")
69
+ .single();
70
+ if (error) {
71
+ return IWebResponse.error(error.message)
72
+ .to_compatible();
73
+ }
74
+ if (!data) {
75
+ return IWebResponse.error("Session incident not found").to_compatible();
76
+ }
77
+ return IWebResponse.success(data).to_compatible();
78
+ }
package/dist/index.d.ts CHANGED
@@ -69,6 +69,7 @@ export * from "./helpers/issuers";
69
69
  export * from "./helpers/document_templates";
70
70
  export * from "./helpers/documents";
71
71
  export * from "./helpers/maintenance_requests";
72
+ export * from "./helpers/session_incidents";
72
73
  export * from "./helpers/contacts";
73
74
  export * from "./helpers/lifecycle";
74
75
  export * from "./helpers/storagePath";
@@ -93,5 +94,5 @@ export * from "./supabase/middleware";
93
94
  export * from "./supabase/server";
94
95
  export * from "./api_keys/actions";
95
96
  export type { IHerdModule } from "./types/herd_module";
96
- export type { IDevice, IEvent, IUser, IHerd, IHerdPrettyLocation, IEventWithTags, IZoneWithActions, IPointsForUser, PointsForUserInsert, PointsForUserUpdate, ICertificate, CertificateInsert, CertificateUpdate, ILocalization, LocalizationInsert, LocalizationUpdate, IIssuer, IssuerInsert, IssuerUpdate, IDocumentTemplate, DocumentTemplateInsert, DocumentTemplateUpdate, IDocument, DocumentInsert, DocumentUpdate, IMaintenanceRequest, MaintenanceRequestInsert, MaintenanceRequestUpdate, IContact, ContactInsert, ContactUpdate, IUserAndRole, IUserProfileRow, IHerdInvitation, IHerdInvitationWithHerdSlug, IHerdAllowedDomain, IUserRolePerHerd, IAbility, IHerdRole, IHerdRoleWithAbilities, HerdRoleSystemName, HerdInvitationStatus, IApiKeyScout, ILayer, IHeartbeat, IProvider, IConnectivity, ISession, ISessionWithCoordinates, IConnectivityWithCoordinates, IObservation, ObservationInsert, ObservationUpdate, IAnalysisJob, IAnalysisTask, AnalysisWorkStatus, } from "./types/db";
97
+ export type { IDevice, IEvent, IUser, IHerd, IHerdPrettyLocation, IEventWithTags, IZoneWithActions, IPointsForUser, PointsForUserInsert, PointsForUserUpdate, ICertificate, CertificateInsert, CertificateUpdate, ILocalization, LocalizationInsert, LocalizationUpdate, IIssuer, IssuerInsert, IssuerUpdate, IDocumentTemplate, DocumentTemplateInsert, DocumentTemplateUpdate, IDocument, DocumentInsert, DocumentUpdate, IMaintenanceRequest, MaintenanceRequestInsert, MaintenanceRequestUpdate, ISessionIncident, SessionIncidentInsert, SessionIncidentUpdate, SessionIncidentType, IContact, ContactInsert, ContactUpdate, IUserAndRole, IUserProfileRow, IHerdInvitation, IHerdInvitationWithHerdSlug, IHerdAllowedDomain, IUserRolePerHerd, IAbility, IHerdRole, IHerdRoleWithAbilities, HerdRoleSystemName, HerdInvitationStatus, IApiKeyScout, ILayer, IHeartbeat, IProvider, IConnectivity, ISession, ISessionWithCoordinates, IConnectivityWithCoordinates, IObservation, ObservationInsert, ObservationUpdate, IAnalysisJob, IAnalysisTask, AnalysisWorkStatus, } from "./types/db";
97
98
  export { EnumSessionsVisibility } from "./types/events";
package/dist/index.js CHANGED
@@ -72,6 +72,7 @@ export * from "./helpers/issuers";
72
72
  export * from "./helpers/document_templates";
73
73
  export * from "./helpers/documents";
74
74
  export * from "./helpers/maintenance_requests";
75
+ export * from "./helpers/session_incidents";
75
76
  export * from "./helpers/contacts";
76
77
  export * from "./helpers/lifecycle";
77
78
  export * from "./helpers/storagePath";
@@ -68,6 +68,8 @@ export type IIssuer = Database["public"]["Tables"]["issuers"]["Row"];
68
68
  export type IDocumentTemplate = Database["public"]["Tables"]["document_templates"]["Row"];
69
69
  export type IDocument = Database["public"]["Tables"]["documents"]["Row"];
70
70
  export type IMaintenanceRequest = Database["public"]["Tables"]["maintenance_requests"]["Row"];
71
+ export type ISessionIncident = Database["public"]["Tables"]["session_incidents"]["Row"];
72
+ export type SessionIncidentType = Database["public"]["Enums"]["session_incident_type"];
71
73
  export type IContact = Database["public"]["Tables"]["contacts"]["Row"];
72
74
  /** A part with its resolved product (parts.product_number -> product_numbers -> products). */
73
75
  export type IPartWithProduct = IPart & {
@@ -140,6 +142,8 @@ export type DocumentInsert = Database["public"]["Tables"]["documents"]["Insert"]
140
142
  export type DocumentUpdate = Database["public"]["Tables"]["documents"]["Update"];
141
143
  export type MaintenanceRequestInsert = Database["public"]["Tables"]["maintenance_requests"]["Insert"];
142
144
  export type MaintenanceRequestUpdate = Database["public"]["Tables"]["maintenance_requests"]["Update"];
145
+ export type SessionIncidentInsert = Database["public"]["Tables"]["session_incidents"]["Insert"];
146
+ export type SessionIncidentUpdate = Database["public"]["Tables"]["session_incidents"]["Update"];
143
147
  export type ContactInsert = Database["public"]["Tables"]["contacts"]["Insert"];
144
148
  export type ContactUpdate = Database["public"]["Tables"]["contacts"]["Update"];
145
149
  export interface CredentialQueryArgs {
@@ -716,7 +716,8 @@ export type Database = {
716
716
  };
717
717
  document_templates: {
718
718
  Row: {
719
- categories: string | null;
719
+ description: string | null;
720
+ entity_for: Database["public"]["Enums"]["document_entity"] | null;
720
721
  id: number;
721
722
  inserted_at: string;
722
723
  issuer_id: number | null;
@@ -725,7 +726,8 @@ export type Database = {
725
726
  uses_expiry: boolean;
726
727
  };
727
728
  Insert: {
728
- categories?: string | null;
729
+ description?: string | null;
730
+ entity_for?: Database["public"]["Enums"]["document_entity"] | null;
729
731
  id?: number;
730
732
  inserted_at?: string;
731
733
  issuer_id?: number | null;
@@ -734,7 +736,8 @@ export type Database = {
734
736
  uses_expiry?: boolean;
735
737
  };
736
738
  Update: {
737
- categories?: string | null;
739
+ description?: string | null;
740
+ entity_for?: Database["public"]["Enums"]["document_entity"] | null;
738
741
  id?: number;
739
742
  inserted_at?: string;
740
743
  issuer_id?: number | null;
@@ -1519,6 +1522,7 @@ export type Database = {
1519
1522
  remediation_completed_at: string | null;
1520
1523
  remediation_completed_user_id: string | null;
1521
1524
  remediation_notes: string | null;
1525
+ session_incident_id: number | null;
1522
1526
  updated_at: string | null;
1523
1527
  updated_by_user_id: string | null;
1524
1528
  };
@@ -1535,6 +1539,7 @@ export type Database = {
1535
1539
  remediation_completed_at?: string | null;
1536
1540
  remediation_completed_user_id?: string | null;
1537
1541
  remediation_notes?: string | null;
1542
+ session_incident_id?: number | null;
1538
1543
  updated_at?: string | null;
1539
1544
  updated_by_user_id?: string | null;
1540
1545
  };
@@ -1551,6 +1556,7 @@ export type Database = {
1551
1556
  remediation_completed_at?: string | null;
1552
1557
  remediation_completed_user_id?: string | null;
1553
1558
  remediation_notes?: string | null;
1559
+ session_incident_id?: number | null;
1554
1560
  updated_at?: string | null;
1555
1561
  updated_by_user_id?: string | null;
1556
1562
  };
@@ -1583,6 +1589,13 @@ export type Database = {
1583
1589
  referencedRelation: "users";
1584
1590
  referencedColumns: ["id"];
1585
1591
  },
1592
+ {
1593
+ foreignKeyName: "maintenance_requests_session_incident_id_fkey";
1594
+ columns: ["session_incident_id"];
1595
+ isOneToOne: false;
1596
+ referencedRelation: "session_incidents";
1597
+ referencedColumns: ["id"];
1598
+ },
1586
1599
  {
1587
1600
  foreignKeyName: "maintenance_requests_updated_by_user_id_fkey";
1588
1601
  columns: ["updated_by_user_id"];
@@ -2394,6 +2407,101 @@ export type Database = {
2394
2407
  }
2395
2408
  ];
2396
2409
  };
2410
+ session_incidents: {
2411
+ Row: {
2412
+ additional_details: Json | null;
2413
+ additional_details_version: number | null;
2414
+ created_at: string;
2415
+ created_by: string | null;
2416
+ description: string | null;
2417
+ device_altitude: number | null;
2418
+ device_battery_percentage: number | null;
2419
+ device_battery_time_remaining: string | null;
2420
+ device_battery_volts: number | null;
2421
+ device_location: unknown;
2422
+ device_mode: string | null;
2423
+ device_speed: number | null;
2424
+ id: number;
2425
+ incident_type: Database["public"]["Enums"]["session_incident_type"] | null;
2426
+ operator: string | null;
2427
+ photo: string | null;
2428
+ session_id: number;
2429
+ updated_at: string;
2430
+ updated_by: string | null;
2431
+ };
2432
+ Insert: {
2433
+ additional_details?: Json | null;
2434
+ additional_details_version?: number | null;
2435
+ created_at?: string;
2436
+ created_by?: string | null;
2437
+ description?: string | null;
2438
+ device_altitude?: number | null;
2439
+ device_battery_percentage?: number | null;
2440
+ device_battery_time_remaining?: string | null;
2441
+ device_battery_volts?: number | null;
2442
+ device_location?: unknown;
2443
+ device_mode?: string | null;
2444
+ device_speed?: number | null;
2445
+ id?: number;
2446
+ incident_type?: Database["public"]["Enums"]["session_incident_type"] | null;
2447
+ operator?: string | null;
2448
+ photo?: string | null;
2449
+ session_id: number;
2450
+ updated_at?: string;
2451
+ updated_by?: string | null;
2452
+ };
2453
+ Update: {
2454
+ additional_details?: Json | null;
2455
+ additional_details_version?: number | null;
2456
+ created_at?: string;
2457
+ created_by?: string | null;
2458
+ description?: string | null;
2459
+ device_altitude?: number | null;
2460
+ device_battery_percentage?: number | null;
2461
+ device_battery_time_remaining?: string | null;
2462
+ device_battery_volts?: number | null;
2463
+ device_location?: unknown;
2464
+ device_mode?: string | null;
2465
+ device_speed?: number | null;
2466
+ id?: number;
2467
+ incident_type?: Database["public"]["Enums"]["session_incident_type"] | null;
2468
+ operator?: string | null;
2469
+ photo?: string | null;
2470
+ session_id?: number;
2471
+ updated_at?: string;
2472
+ updated_by?: string | null;
2473
+ };
2474
+ Relationships: [
2475
+ {
2476
+ foreignKeyName: "session_incidents_created_by_fkey";
2477
+ columns: ["created_by"];
2478
+ isOneToOne: false;
2479
+ referencedRelation: "users";
2480
+ referencedColumns: ["id"];
2481
+ },
2482
+ {
2483
+ foreignKeyName: "session_incidents_operator_fkey";
2484
+ columns: ["operator"];
2485
+ isOneToOne: false;
2486
+ referencedRelation: "users";
2487
+ referencedColumns: ["id"];
2488
+ },
2489
+ {
2490
+ foreignKeyName: "session_incidents_session_id_fkey";
2491
+ columns: ["session_id"];
2492
+ isOneToOne: false;
2493
+ referencedRelation: "sessions";
2494
+ referencedColumns: ["id"];
2495
+ },
2496
+ {
2497
+ foreignKeyName: "session_incidents_updated_by_fkey";
2498
+ columns: ["updated_by"];
2499
+ isOneToOne: false;
2500
+ referencedRelation: "users";
2501
+ referencedColumns: ["id"];
2502
+ }
2503
+ ];
2504
+ };
2397
2505
  sessions: {
2398
2506
  Row: {
2399
2507
  altitude_average: number;
@@ -3882,6 +3990,7 @@ export type Database = {
3882
3990
  remediation_completed_at: string | null;
3883
3991
  remediation_completed_user_id: string | null;
3884
3992
  remediation_notes: string | null;
3993
+ session_incident_id: number | null;
3885
3994
  updated_at: string | null;
3886
3995
  updated_by_user_id: string | null;
3887
3996
  }[];
@@ -4019,6 +4128,12 @@ export type Database = {
4019
4128
  isSetofReturn: true;
4020
4129
  };
4021
4130
  };
4131
+ get_service_pubsub_token_claims: {
4132
+ Args: {
4133
+ p_herd_ids: number[];
4134
+ };
4135
+ Returns: Json;
4136
+ };
4022
4137
  get_session_by_id: {
4023
4138
  Args: {
4024
4139
  session_id_caller: number;
@@ -4519,13 +4634,15 @@ export type Database = {
4519
4634
  Enums: {
4520
4635
  analysis_work_status: "waiting" | "cancelled" | "processing" | "failed" | "success";
4521
4636
  app_permission: "herds.delete" | "events.delete";
4522
- device_type: "trail_camera" | "drone_fixed_wing" | "drone_quad" | "gps_tracker" | "sentry_tower" | "smart_buoy" | "radio_mesh_base_station" | "radio_mesh_repeater" | "unknown" | "gps_tracker_vehicle" | "gps_tracker_person" | "radio_mesh_base_station_gateway";
4637
+ device_type: "trail_camera" | "drone_fixed_wing" | "drone_quad" | "gps_tracker" | "sentry_tower" | "smart_buoy" | "radio_mesh_base_station" | "radio_mesh_repeater" | "unknown" | "gps_tracker_vehicle" | "gps_tracker_person" | "radio_mesh_base_station_gateway" | "remote_controller" | "docking_station" | "smart_battery" | "charging_station";
4638
+ document_entity: "user" | "herd" | "device" | "product";
4523
4639
  entity_lifecycle: "active" | "retired" | "deleted";
4524
4640
  health_item: "healthy" | "repairable" | "unrepairable";
4525
4641
  herd_invitation_status: "pending" | "accepted" | "revoked" | "expired";
4526
4642
  media_type: "image" | "video" | "audio" | "text";
4527
4643
  plan_type: "mission" | "fence" | "rally" | "markov";
4528
4644
  review_status: "pending" | "annotating" | "in_review" | "completed" | "rejected";
4645
+ session_incident_type: "collision_multi_device_other_direct_control" | "collision_multi_device_other_remote_control" | "collision_single_device_environment" | "link_loss" | "other";
4529
4646
  tag_observation_type: "manual" | "auto";
4530
4647
  user_status: "ONLINE" | "OFFLINE";
4531
4648
  };
@@ -4843,13 +4960,15 @@ export declare const Constants: {
4843
4960
  readonly Enums: {
4844
4961
  readonly analysis_work_status: readonly ["waiting", "cancelled", "processing", "failed", "success"];
4845
4962
  readonly app_permission: readonly ["herds.delete", "events.delete"];
4846
- readonly device_type: readonly ["trail_camera", "drone_fixed_wing", "drone_quad", "gps_tracker", "sentry_tower", "smart_buoy", "radio_mesh_base_station", "radio_mesh_repeater", "unknown", "gps_tracker_vehicle", "gps_tracker_person", "radio_mesh_base_station_gateway"];
4963
+ readonly device_type: readonly ["trail_camera", "drone_fixed_wing", "drone_quad", "gps_tracker", "sentry_tower", "smart_buoy", "radio_mesh_base_station", "radio_mesh_repeater", "unknown", "gps_tracker_vehicle", "gps_tracker_person", "radio_mesh_base_station_gateway", "remote_controller", "docking_station", "smart_battery", "charging_station"];
4964
+ readonly document_entity: readonly ["user", "herd", "device", "product"];
4847
4965
  readonly entity_lifecycle: readonly ["active", "retired", "deleted"];
4848
4966
  readonly health_item: readonly ["healthy", "repairable", "unrepairable"];
4849
4967
  readonly herd_invitation_status: readonly ["pending", "accepted", "revoked", "expired"];
4850
4968
  readonly media_type: readonly ["image", "video", "audio", "text"];
4851
4969
  readonly plan_type: readonly ["mission", "fence", "rally", "markov"];
4852
4970
  readonly review_status: readonly ["pending", "annotating", "in_review", "completed", "rejected"];
4971
+ readonly session_incident_type: readonly ["collision_multi_device_other_direct_control", "collision_multi_device_other_remote_control", "collision_single_device_environment", "link_loss", "other"];
4853
4972
  readonly tag_observation_type: readonly ["manual", "auto"];
4854
4973
  readonly user_status: readonly ["ONLINE", "OFFLINE"];
4855
4974
  };
@@ -22,7 +22,12 @@ export const Constants = {
22
22
  "gps_tracker_vehicle",
23
23
  "gps_tracker_person",
24
24
  "radio_mesh_base_station_gateway",
25
+ "remote_controller",
26
+ "docking_station",
27
+ "smart_battery",
28
+ "charging_station",
25
29
  ],
30
+ document_entity: ["user", "herd", "device", "product"],
26
31
  entity_lifecycle: ["active", "retired", "deleted"],
27
32
  health_item: ["healthy", "repairable", "unrepairable"],
28
33
  herd_invitation_status: ["pending", "accepted", "revoked", "expired"],
@@ -35,6 +40,13 @@ export const Constants = {
35
40
  "completed",
36
41
  "rejected",
37
42
  ],
43
+ session_incident_type: [
44
+ "collision_multi_device_other_direct_control",
45
+ "collision_multi_device_other_remote_control",
46
+ "collision_single_device_environment",
47
+ "link_loss",
48
+ "other",
49
+ ],
38
50
  tag_observation_type: ["manual", "auto"],
39
51
  user_status: ["ONLINE", "OFFLINE"],
40
52
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.4.89",
3
+ "version": "1.4.91",
4
4
  "description": "Core utilities and helpers for Adventure Labs Scout applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",