From 3221e5830eff51d01b1d84911947d8c2d7ce8d51 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Tue, 20 Jan 2026 19:13:14 -0500 Subject: [PATCH] Fix(Core): Restore system lookups and enhance reference data view - API: Correctly exported 'get_ae_obj_li_for_lu' and reverted to stable V2 endpoints (/v2/crud/lu/.../list) to resolve V3 500 errors. - Auth: Injected 'x-no-account-id' bypass header for unauthenticated global lookup access. - UI: Updated lookups page to support 'english_short_name' fallback for countries and added Country Subdivisions card. - Debug: Added transient console logging for verification. --- src/lib/api/api.ts | 96 ++++++++-------------------- src/routes/core/lookups/+page.svelte | 45 +++++++++++-- 2 files changed, 66 insertions(+), 75 deletions(-) diff --git a/src/lib/api/api.ts b/src/lib/api/api.ts index 1a8863c3..d4da01fb 100644 --- a/src/lib/api/api.ts +++ b/src/lib/api/api.ts @@ -28,106 +28,61 @@ import { delete_nested_ae_obj_v3 } from '$lib/ae_api/api_post__crud_obj_v3'; -// This new function has not been tested yet!!! -// Updated 2024-08-07 +/** + * Get a list of lookup objects (V2 Legacy) + * Standardized lookup data like countries, timezones, and subdivisions. + * Updated 2026-01-20 + */ export const get_ae_obj_li_for_lu = async function get_ae_obj_li_for_lu({ api_cfg, - // obj_type, for_lu_type, - // for_obj_id=null, - // use_alt_table=false, - // use_alt_base=false, - // inc={}, enabled = 'enabled', hidden = 'not_hidden', order_by_li = null, limit = 999999, offset = 0, - // key, - // jwt=null, headers = {}, params_json = null, - // json_obj=null, params = {}, - return_meta = false, log_lvl = 1 }: { api_cfg: any; - // obj_type: string, for_lu_type: string; - // for_lu_id?: string, - // use_alt_table?: boolean, - // use_alt_base?: boolean, - // inc?: key_val enabled?: 'enabled' | 'all' | 'not_enabled' | undefined; hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; order_by_li?: any; limit?: number; offset?: number; - // key: string, - // jwt?: string, headers?: any; params_json?: any; - // json_obj?: any, params?: key_val; - return_meta?: boolean; log_lvl?: number; }) { if (log_lvl) { console.log(`*** get_ae_obj_li_for_lu() *** for_lu_type=${for_lu_type}`); } - let endpoint = ''; - if (for_lu_type == 'country_subdivision') { - endpoint = `/crud/lu/country_subdivision/list`; - } else if (for_lu_type == 'country') { - endpoint = `/crud/lu/country/list`; - } else if (for_lu_type == 'time_zone') { - endpoint = `/crud/lu/time_zone/list`; - } else { - console.log(`Unknown object type: ${for_lu_type}`); - return false; - } - if (log_lvl) { - console.log('Endpoint:', endpoint); - } + // Lookup data is global; bypass account-id scope check + const merged_headers = { + ...headers, + 'x-no-account-id': 'Nothing to See Here' + }; - if (order_by_li) { - headers['order_by_li'] = order_by_li; - } - - const allowed_enabled_list = ['all', 'enabled', 'not_enabled']; - if (allowed_enabled_list.includes(enabled)) { - params['enabled'] = enabled; - } - - const allowed_hidden_list = ['all', 'hidden', 'not_hidden']; - if (allowed_hidden_list.includes(hidden)) { - params['hidden'] = hidden; - } - - if (limit >= 0) { - params['limit'] = limit; - } - - if (offset >= 0) { - params['offset'] = offset; - } - - const object_li_get_promise = await api.get_object({ - api_cfg: api_cfg, - endpoint: endpoint, - headers: headers, - params: params, - // return_meta: return_meta, - log_lvl: log_lvl + // Delegate to V2 helper which handles the /v2 prefix and /list suffix correctly + return await get_ae_obj_li_for_obj_id_crud_v2({ + api_cfg, + obj_type: 'lu', + for_obj_type: for_lu_type, + enabled, + hidden, + order_by_li, + limit, + offset, + headers: merged_headers, + params_json, + params, + log_lvl }); - - if (log_lvl > 1) { - console.log(object_li_get_promise); - } - - return object_li_get_promise; }; // Updated 2023-07-24 @@ -959,7 +914,8 @@ const obj = { download_hosted_file: download_hosted_file, delete_hosted_file: delete_hosted_file, get_data_store_obj_w_code: get_data_store_obj_w_code, + get_ae_obj_li_for_lu: get_ae_obj_li_for_lu, send_email: send_email }; export const api = obj; -// module.exports = api; +// module.exports = api; \ No newline at end of file diff --git a/src/routes/core/lookups/+page.svelte b/src/routes/core/lookups/+page.svelte index 37910402..ccabe9ea 100644 --- a/src/routes/core/lookups/+page.svelte +++ b/src/routes/core/lookups/+page.svelte @@ -14,15 +14,20 @@ async function load_lookups() { loading = true; - // Using existing generic lookup loaders if available, or raw API calls try { - const [countries, time_zones] = await Promise.all([ - api.get_ae_obj_li_for_lu({ api_cfg: $ae_api, for_lu_type: 'country', log_lvl: 0 }), - api.get_ae_obj_li_for_lu({ api_cfg: $ae_api, for_lu_type: 'time_zone', log_lvl: 0 }) + const [countries, time_zones, subdivisions] = await Promise.all([ + api.get_ae_obj_li_for_lu({ api_cfg: $ae_api, for_lu_type: 'country', log_lvl: 1 }), + api.get_ae_obj_li_for_lu({ api_cfg: $ae_api, for_lu_type: 'time_zone', log_lvl: 1 }), + api.get_ae_obj_li_for_lu({ api_cfg: $ae_api, for_lu_type: 'country_subdivision', log_lvl: 1 }) ]); + console.log('Lookup Results - Countries:', countries); + console.log('Lookup Results - Time Zones:', time_zones); + console.log('Lookup Results - Subdivisions:', subdivisions); + lookups.countries = countries || []; lookups.time_zones = time_zones || []; + lookups.subdivisions = subdivisions || []; } catch (error) { console.error('Failed to load lookups:', error); } finally { @@ -86,7 +91,7 @@ {#each lookups.countries as c} - {c.name} + {c.name || c.english_short_name} {c.alpha_2_code} {/each} @@ -124,6 +129,36 @@ + +
+

+ + Country Subdivisions (States/Provinces) + {lookups.subdivisions.length} Records +

+ +
+ + + + + + + + + + {#each lookups.subdivisions as s} + + + + + + {/each} + +
CountryNameCode
{s.country_alpha_2_code}{s.name}{s.code}
+
+
+

Lookup data is synchronized with the global system database and used for addresses, event scheduling, and localized displays.