@adventurelabs/scout-core 1.0.47 → 1.0.48

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.
@@ -32,19 +32,56 @@ export async function server_list_api_keys(device_id) {
32
32
  }
33
33
  export async function server_list_api_keys_batch(device_ids) {
34
34
  const startTime = Date.now();
35
- // CRITICAL: Check for UUIDs being passed instead of device IDs
36
- const invalidIds = device_ids.filter((id) => !/^\d+$/.test(id));
37
- if (invalidIds.length > 0) {
38
- console.error(`[CRITICAL] UUIDs detected instead of device IDs:`, invalidIds);
39
- console.error(`[CRITICAL] Valid device IDs should be:`, device_ids.filter((id) => /^\d+$/.test(id)));
40
- return {};
41
- }
42
35
  const supabase = await newServerClient();
43
- const { data, error } = await supabase.rpc("load_api_keys_batch", {
44
- device_ids: device_ids,
45
- });
46
- if (error) {
47
- console.error(`[API Keys Batch] Database error:`, error.message);
36
+ // Check if the batch function exists by trying a simple call
37
+ try {
38
+ const { data, error } = await supabase.rpc("load_api_keys_batch", {
39
+ device_ids: device_ids,
40
+ });
41
+ if (error) {
42
+ // Check if it's a "function does not exist" error
43
+ if (error.message.includes("function") &&
44
+ error.message.includes("does not exist")) {
45
+ console.log(`[API Keys Batch] Batch function not deployed, using individual calls...`);
46
+ }
47
+ else {
48
+ console.error(`[API Keys Batch] Database error:`, error.message);
49
+ }
50
+ console.log(`[API Keys Batch] Falling back to individual calls...`);
51
+ // Fallback to individual API key loading
52
+ const result = {};
53
+ const promises = device_ids.map(async (device_id) => {
54
+ try {
55
+ const api_keys = await server_list_api_keys(device_id);
56
+ result[parseInt(device_id)] = api_keys;
57
+ }
58
+ catch (err) {
59
+ console.warn(`[API Keys Batch] Failed for device ${device_id}:`, err);
60
+ result[parseInt(device_id)] = [];
61
+ }
62
+ });
63
+ await Promise.all(promises);
64
+ return result;
65
+ }
66
+ if (!data) {
67
+ return {};
68
+ }
69
+ const result = {};
70
+ // Group API keys by device_id
71
+ data.forEach((item) => {
72
+ const device_id = item.device_id;
73
+ if (!result[device_id]) {
74
+ result[device_id] = [];
75
+ }
76
+ result[device_id].push({
77
+ id: item.api_key_id.toString(),
78
+ key: item.api_key_key,
79
+ });
80
+ });
81
+ return result;
82
+ }
83
+ catch (err) {
84
+ console.error(`[API Keys Batch] Unexpected error:`, err);
48
85
  console.log(`[API Keys Batch] Falling back to individual calls...`);
49
86
  // Fallback to individual API key loading
50
87
  const result = {};
@@ -61,20 +98,4 @@ export async function server_list_api_keys_batch(device_ids) {
61
98
  await Promise.all(promises);
62
99
  return result;
63
100
  }
64
- if (!data) {
65
- return {};
66
- }
67
- const result = {};
68
- // Group API keys by device_id
69
- data.forEach((item) => {
70
- const device_id = item.device_id;
71
- if (!result[device_id]) {
72
- result[device_id] = [];
73
- }
74
- result[device_id].push({
75
- id: item.api_key_id.toString(),
76
- key: item.api_key_key,
77
- });
78
- });
79
- return result;
80
101
  }
@@ -167,13 +167,6 @@ export async function server_get_events_and_tags_for_device(device_id, limit = 3
167
167
  }
168
168
  export async function server_get_events_and_tags_for_devices_batch(device_ids, limit = 1) {
169
169
  const startTime = Date.now();
170
- // CRITICAL: Check for UUIDs being passed instead of device IDs
171
- const invalidIds = device_ids.filter((id) => !/^\d+$/.test(id));
172
- if (invalidIds.length > 0) {
173
- console.error(`[CRITICAL] UUIDs detected instead of device IDs:`, invalidIds);
174
- console.error(`[CRITICAL] Valid device IDs should be:`, device_ids.filter((id) => /^\d+$/.test(id)));
175
- return IWebResponse.success({}).to_compatible();
176
- }
177
170
  const supabase = await newServerClient();
178
171
  // Use single RPC call for all devices
179
172
  const { data, error } = await supabase.rpc("get_events_and_tags_for_devices_batch", {
@@ -187,14 +180,13 @@ export async function server_get_events_and_tags_for_devices_batch(device_ids, l
187
180
  const result = {};
188
181
  const promises = device_ids.map(async (device_id) => {
189
182
  try {
190
- const device_id_num = parseInt(device_id);
191
- const events_response = await server_get_events_and_tags_for_device(device_id_num, limit);
183
+ const events_response = await server_get_events_and_tags_for_device(parseInt(device_id), limit);
192
184
  if (events_response.status === EnumWebResponse.SUCCESS &&
193
185
  events_response.data) {
194
- result[device_id_num] = events_response.data;
186
+ result[parseInt(device_id)] = events_response.data;
195
187
  }
196
188
  else {
197
- result[device_id_num] = [];
189
+ result[parseInt(device_id)] = [];
198
190
  }
199
191
  }
200
192
  catch (err) {
@@ -62,16 +62,6 @@ export class HerdModule {
62
62
  const batchStartTime = Date.now();
63
63
  try {
64
64
  const device_ids = new_devices.map((device) => (device.id ?? 0).toString());
65
- // CRITICAL: Check for UUIDs being passed instead of device IDs
66
- const invalidDeviceIds = device_ids.filter((id) => !/^\d+$/.test(id));
67
- if (invalidDeviceIds.length > 0) {
68
- console.error(`[CRITICAL] UUIDs detected in HerdModule:`, invalidDeviceIds);
69
- console.error(`[CRITICAL] Device objects:`, new_devices.map((d) => ({ id: d.id, created_by: d.created_by })));
70
- // Filter out invalid IDs
71
- const validDeviceIds = device_ids.filter((id) => /^\d+$/.test(id));
72
- device_ids.length = 0;
73
- device_ids.push(...validDeviceIds);
74
- }
75
65
  // Load API keys and events in parallel
76
66
  const [api_keys_batch, events_response] = await Promise.all([
77
67
  server_list_api_keys_batch(device_ids),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.0.47",
3
+ "version": "1.0.48",
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",