@adventurelabs/scout-core 1.0.41 → 1.0.42

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.
@@ -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
  }
@@ -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) {
@@ -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
64
  const device_ids = new_devices.map((device) => device.id ?? 0);
64
- console.log(`[HerdModule] Loading batch data for ${device_ids.length} devices:`, device_ids);
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
  }
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.42",
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",