@adventurelabs/scout-core 1.4.90 → 1.4.92

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;
@@ -2690,6 +2798,7 @@ export type Database = {
2690
2798
  lifecycle_changed_at: string;
2691
2799
  lifecycle_changed_by: string | null;
2692
2800
  lifecycle_reason: string | null;
2801
+ photo_uri: string | null;
2693
2802
  signature_base64: string | null;
2694
2803
  title: string | null;
2695
2804
  username: string | null;
@@ -2705,6 +2814,7 @@ export type Database = {
2705
2814
  lifecycle_changed_at?: string;
2706
2815
  lifecycle_changed_by?: string | null;
2707
2816
  lifecycle_reason?: string | null;
2817
+ photo_uri?: string | null;
2708
2818
  signature_base64?: string | null;
2709
2819
  title?: string | null;
2710
2820
  username?: string | null;
@@ -2720,6 +2830,7 @@ export type Database = {
2720
2830
  lifecycle_changed_at?: string;
2721
2831
  lifecycle_changed_by?: string | null;
2722
2832
  lifecycle_reason?: string | null;
2833
+ photo_uri?: string | null;
2723
2834
  signature_base64?: string | null;
2724
2835
  title?: string | null;
2725
2836
  username?: string | null;
@@ -3882,6 +3993,7 @@ export type Database = {
3882
3993
  remediation_completed_at: string | null;
3883
3994
  remediation_completed_user_id: string | null;
3884
3995
  remediation_notes: string | null;
3996
+ session_incident_id: number | null;
3885
3997
  updated_at: string | null;
3886
3998
  updated_by_user_id: string | null;
3887
3999
  }[];
@@ -4019,6 +4131,12 @@ export type Database = {
4019
4131
  isSetofReturn: true;
4020
4132
  };
4021
4133
  };
4134
+ get_service_pubsub_token_claims: {
4135
+ Args: {
4136
+ p_herd_ids: number[];
4137
+ };
4138
+ Returns: Json;
4139
+ };
4022
4140
  get_session_by_id: {
4023
4141
  Args: {
4024
4142
  session_id_caller: number;
@@ -4520,12 +4638,14 @@ export type Database = {
4520
4638
  analysis_work_status: "waiting" | "cancelled" | "processing" | "failed" | "success";
4521
4639
  app_permission: "herds.delete" | "events.delete";
4522
4640
  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";
4641
+ document_entity: "user" | "herd" | "device" | "product";
4523
4642
  entity_lifecycle: "active" | "retired" | "deleted";
4524
4643
  health_item: "healthy" | "repairable" | "unrepairable";
4525
4644
  herd_invitation_status: "pending" | "accepted" | "revoked" | "expired";
4526
4645
  media_type: "image" | "video" | "audio" | "text";
4527
4646
  plan_type: "mission" | "fence" | "rally" | "markov";
4528
4647
  review_status: "pending" | "annotating" | "in_review" | "completed" | "rejected";
4648
+ session_incident_type: "collision_multi_device_other_direct_control" | "collision_multi_device_other_remote_control" | "collision_single_device_environment" | "link_loss" | "other";
4529
4649
  tag_observation_type: "manual" | "auto";
4530
4650
  user_status: "ONLINE" | "OFFLINE";
4531
4651
  };
@@ -4844,12 +4964,14 @@ export declare const Constants: {
4844
4964
  readonly analysis_work_status: readonly ["waiting", "cancelled", "processing", "failed", "success"];
4845
4965
  readonly app_permission: readonly ["herds.delete", "events.delete"];
4846
4966
  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"];
4967
+ readonly document_entity: readonly ["user", "herd", "device", "product"];
4847
4968
  readonly entity_lifecycle: readonly ["active", "retired", "deleted"];
4848
4969
  readonly health_item: readonly ["healthy", "repairable", "unrepairable"];
4849
4970
  readonly herd_invitation_status: readonly ["pending", "accepted", "revoked", "expired"];
4850
4971
  readonly media_type: readonly ["image", "video", "audio", "text"];
4851
4972
  readonly plan_type: readonly ["mission", "fence", "rally", "markov"];
4852
4973
  readonly review_status: readonly ["pending", "annotating", "in_review", "completed", "rejected"];
4974
+ 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
4975
  readonly tag_observation_type: readonly ["manual", "auto"];
4854
4976
  readonly user_status: readonly ["ONLINE", "OFFLINE"];
4855
4977
  };
@@ -27,6 +27,7 @@ export const Constants = {
27
27
  "smart_battery",
28
28
  "charging_station",
29
29
  ],
30
+ document_entity: ["user", "herd", "device", "product"],
30
31
  entity_lifecycle: ["active", "retired", "deleted"],
31
32
  health_item: ["healthy", "repairable", "unrepairable"],
32
33
  herd_invitation_status: ["pending", "accepted", "revoked", "expired"],
@@ -39,6 +40,13 @@ export const Constants = {
39
40
  "completed",
40
41
  "rejected",
41
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
+ ],
42
50
  tag_observation_type: ["manual", "auto"],
43
51
  user_status: ["ONLINE", "OFFLINE"],
44
52
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.4.90",
3
+ "version": "1.4.92",
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",