@adventurelabs/scout-core 1.0.41 → 1.0.43

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.
@@ -1,5 +1,5 @@
1
1
  import { IApiKeyScout } from "../types/db";
2
2
  export declare function server_list_api_keys(device_id: string): Promise<IApiKeyScout[]>;
3
- export declare function server_list_api_keys_batch(device_ids: number[]): Promise<{
3
+ export declare function server_list_api_keys_batch(device_ids: string[]): Promise<{
4
4
  [device_id: number]: IApiKeyScout[];
5
5
  }>;
@@ -18,18 +18,23 @@ export async function server_list_api_keys(device_id) {
18
18
  return data_to_return;
19
19
  }
20
20
  export async function server_list_api_keys_batch(device_ids) {
21
- console.log(`[API Keys Batch] Starting batch load for ${device_ids.length} devices`);
21
+ const startTime = Date.now();
22
+ console.log(`[API Keys Batch] Starting batch load for ${device_ids.length} devices at ${new Date().toISOString()}`);
22
23
  const supabase = await newServerClient();
24
+ console.log(`[API Keys Batch] Making RPC call to load_api_keys_batch...`);
23
25
  const { data, error } = await supabase.rpc("load_api_keys_batch", {
24
26
  device_ids: device_ids,
25
27
  });
28
+ const duration = Date.now() - startTime;
26
29
  if (error) {
27
- console.error("Error listing API keys in batch:", error.message);
30
+ console.error(`[API Keys Batch] ERROR after ${duration}ms:`, error.message);
28
31
  return {};
29
32
  }
30
- if (!data)
33
+ if (!data) {
34
+ console.log(`[API Keys Batch] No data returned after ${duration}ms`);
31
35
  return {};
32
- console.log(`[API Keys Batch] Received ${data.length} API key records`);
36
+ }
37
+ console.log(`[API Keys Batch] RPC completed in ${duration}ms, received ${data.length} API key records`);
33
38
  const result = {};
34
39
  // Group API keys by device_id
35
40
  data.forEach((item) => {
@@ -42,6 +47,7 @@ export async function server_list_api_keys_batch(device_ids) {
42
47
  key: item.api_key_key,
43
48
  });
44
49
  });
45
- console.log(`[API Keys Batch] Returning API keys for ${Object.keys(result).length} devices`);
50
+ const totalDuration = Date.now() - startTime;
51
+ console.log(`[API Keys Batch] COMPLETED in ${totalDuration}ms - returning API keys for ${Object.keys(result).length} devices`);
46
52
  return result;
47
53
  }
@@ -5,7 +5,7 @@ export declare function server_delete_tags_by_ids(tag_ids: number[]): Promise<IW
5
5
  export declare function server_update_tags(tags: ITag[]): Promise<IWebResponseCompatible<ITag[]>>;
6
6
  export declare function server_get_more_events_with_tags_by_herd(herd_id: number, offset: number, page_count?: number): Promise<IWebResponseCompatible<IEventWithTags[]>>;
7
7
  export declare function server_get_events_and_tags_for_device(device_id: number, limit?: number): Promise<IWebResponseCompatible<IEventWithTags[]>>;
8
- export declare function server_get_events_and_tags_for_devices_batch(device_ids: number[], limit?: number): Promise<IWebResponseCompatible<{
8
+ export declare function server_get_events_and_tags_for_devices_batch(device_ids: string[], limit?: number): Promise<IWebResponseCompatible<{
9
9
  [device_id: number]: IEventWithTags[];
10
10
  }>>;
11
11
  export declare function get_event_and_tags_by_event_id(event_id: number): Promise<IWebResponseCompatible<IEventWithTags>>;
@@ -147,24 +147,29 @@ export async function server_get_events_and_tags_for_device(device_id, limit = 3
147
147
  return IWebResponse.success(eventsWithSignedUrls).to_compatible();
148
148
  }
149
149
  export async function server_get_events_and_tags_for_devices_batch(device_ids, limit = 1) {
150
- console.log(`[Events Batch] Starting batch load for ${device_ids.length} devices (limit: ${limit})`);
150
+ const startTime = Date.now();
151
+ console.log(`[Events Batch] Starting batch load for ${device_ids.length} devices (limit: ${limit}) at ${new Date().toISOString()}`);
151
152
  const supabase = await newServerClient();
153
+ console.log(`[Events Batch] Making RPC call to get_events_and_tags_for_devices_batch...`);
152
154
  // Use single RPC call for all devices
153
155
  const { data, error } = await supabase.rpc("get_events_and_tags_for_devices_batch", {
154
156
  device_ids: device_ids,
155
157
  limit_per_device: limit,
156
158
  });
159
+ const duration = Date.now() - startTime;
157
160
  if (error) {
158
- console.error("Error fetching events for devices in batch:", error.message);
161
+ console.error(`[Events Batch] ERROR after ${duration}ms:`, error.message);
159
162
  return {
160
163
  status: EnumWebResponse.ERROR,
161
164
  msg: error.message,
162
165
  data: {},
163
166
  };
164
167
  }
165
- if (!data)
168
+ if (!data) {
169
+ console.log(`[Events Batch] No data returned after ${duration}ms`);
166
170
  return IWebResponse.success({}).to_compatible();
167
- console.log(`[Events Batch] Received ${data.length} event records`);
171
+ }
172
+ console.log(`[Events Batch] RPC completed in ${duration}ms, received ${data.length} event records`);
168
173
  // Group events by device_id
169
174
  const eventsByDevice = {};
170
175
  data.forEach((row) => {
@@ -199,7 +204,8 @@ export async function server_get_events_and_tags_for_devices_batch(device_ids, l
199
204
  const eventsWithSignedUrls = await addSignedUrlsToEvents(events, supabase);
200
205
  result[parseInt(device_id)] = eventsWithSignedUrls;
201
206
  }
202
- console.log(`[Events Batch] Returning events for ${Object.keys(result).length} devices`);
207
+ const totalDuration = Date.now() - startTime;
208
+ console.log(`[Events Batch] COMPLETED in ${totalDuration}ms - returning events for ${Object.keys(result).length} devices`);
203
209
  return IWebResponse.success(result).to_compatible();
204
210
  }
205
211
  export async function get_event_and_tags_by_event_id(event_id) {
@@ -746,7 +746,7 @@ export declare function useSupabase(): SupabaseClient<Database, "public", {
746
746
  };
747
747
  load_api_keys_batch: {
748
748
  Args: {
749
- device_ids: number[];
749
+ device_ids: string[];
750
750
  };
751
751
  Returns: {
752
752
  device_id: number;
@@ -756,7 +756,7 @@ export declare function useSupabase(): SupabaseClient<Database, "public", {
756
756
  };
757
757
  get_events_and_tags_for_devices_batch: {
758
758
  Args: {
759
- device_ids: number[];
759
+ device_ids: string[];
760
760
  limit_per_device: number;
761
761
  };
762
762
  Returns: {
@@ -737,7 +737,7 @@ export declare function newServerClient(): Promise<import("@supabase/supabase-js
737
737
  };
738
738
  load_api_keys_batch: {
739
739
  Args: {
740
- device_ids: number[];
740
+ device_ids: string[];
741
741
  };
742
742
  Returns: {
743
743
  device_id: number;
@@ -747,7 +747,7 @@ export declare function newServerClient(): Promise<import("@supabase/supabase-js
747
747
  };
748
748
  get_events_and_tags_for_devices_batch: {
749
749
  Args: {
750
- device_ids: number[];
750
+ device_ids: string[];
751
751
  limit_per_device: number;
752
752
  };
753
753
  Returns: {
@@ -59,14 +59,18 @@ export class HerdModule {
59
59
  // get api keys and events for all devices in batch
60
60
  let recent_events_batch = {};
61
61
  if (new_devices.length > 0) {
62
+ const batchStartTime = Date.now();
62
63
  try {
63
- const device_ids = new_devices.map((device) => device.id ?? 0);
64
- console.log(`[HerdModule] Loading batch data for ${device_ids.length} devices:`, device_ids);
64
+ const device_ids = new_devices.map((device) => (device.id ?? 0).toString());
65
+ console.log(`[HerdModule] Starting parallel batch load for ${device_ids.length} devices at ${new Date().toISOString()}:`, device_ids);
65
66
  // Load API keys and events in parallel
67
+ console.log(`[HerdModule] Initiating Promise.all for API keys and events...`);
66
68
  const [api_keys_batch, events_response] = await Promise.all([
67
69
  server_list_api_keys_batch(device_ids),
68
70
  server_get_events_and_tags_for_devices_batch(device_ids, 1),
69
71
  ]);
72
+ const batchDuration = Date.now() - batchStartTime;
73
+ console.log(`[HerdModule] Parallel batch load completed in ${batchDuration}ms`);
70
74
  // Assign API keys to devices
71
75
  for (let i = 0; i < new_devices.length; i++) {
72
76
  const device_id = new_devices[i].id ?? 0;
@@ -81,7 +85,7 @@ export class HerdModule {
81
85
  }
82
86
  }
83
87
  catch (error) {
84
- console.warn("Failed to load API keys or events for devices:", error);
88
+ console.error(`[HerdModule] CRITICAL ERROR in batch load after ${Date.now() - batchStartTime}ms:`, error);
85
89
  // Continue without API keys and events
86
90
  }
87
91
  }
@@ -804,7 +804,7 @@ export type Database = {
804
804
  };
805
805
  load_api_keys_batch: {
806
806
  Args: {
807
- device_ids: number[];
807
+ device_ids: string[];
808
808
  };
809
809
  Returns: {
810
810
  device_id: number;
@@ -814,7 +814,7 @@ export type Database = {
814
814
  };
815
815
  get_events_and_tags_for_devices_batch: {
816
816
  Args: {
817
- device_ids: number[];
817
+ device_ids: string[];
818
818
  limit_per_device: number;
819
819
  };
820
820
  Returns: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
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",