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.
This commit is contained in:
Scott Idem
2026-01-20 19:13:14 -05:00
parent f244526538
commit 3221e5830e
2 changed files with 66 additions and 75 deletions

View File

@@ -28,106 +28,61 @@ import {
delete_nested_ae_obj_v3 delete_nested_ae_obj_v3
} from '$lib/ae_api/api_post__crud_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({ export const get_ae_obj_li_for_lu = async function get_ae_obj_li_for_lu({
api_cfg, api_cfg,
// obj_type,
for_lu_type, for_lu_type,
// for_obj_id=null,
// use_alt_table=false,
// use_alt_base=false,
// inc={},
enabled = 'enabled', enabled = 'enabled',
hidden = 'not_hidden', hidden = 'not_hidden',
order_by_li = null, order_by_li = null,
limit = 999999, limit = 999999,
offset = 0, offset = 0,
// key,
// jwt=null,
headers = {}, headers = {},
params_json = null, params_json = null,
// json_obj=null,
params = {}, params = {},
return_meta = false,
log_lvl = 1 log_lvl = 1
}: { }: {
api_cfg: any; api_cfg: any;
// obj_type: string,
for_lu_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; enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
order_by_li?: any; order_by_li?: any;
limit?: number; limit?: number;
offset?: number; offset?: number;
// key: string,
// jwt?: string,
headers?: any; headers?: any;
params_json?: any; params_json?: any;
// json_obj?: any,
params?: key_val; params?: key_val;
return_meta?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
if (log_lvl) { if (log_lvl) {
console.log(`*** get_ae_obj_li_for_lu() *** for_lu_type=${for_lu_type}`); console.log(`*** get_ae_obj_li_for_lu() *** for_lu_type=${for_lu_type}`);
} }
let endpoint = ''; // Lookup data is global; bypass account-id scope check
if (for_lu_type == 'country_subdivision') { const merged_headers = {
endpoint = `/crud/lu/country_subdivision/list`; ...headers,
} else if (for_lu_type == 'country') { 'x-no-account-id': 'Nothing to See Here'
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);
}
if (order_by_li) { // Delegate to V2 helper which handles the /v2 prefix and /list suffix correctly
headers['order_by_li'] = order_by_li; return await get_ae_obj_li_for_obj_id_crud_v2({
} api_cfg,
obj_type: 'lu',
const allowed_enabled_list = ['all', 'enabled', 'not_enabled']; for_obj_type: for_lu_type,
if (allowed_enabled_list.includes(enabled)) { enabled,
params['enabled'] = enabled; hidden,
} order_by_li,
limit,
const allowed_hidden_list = ['all', 'hidden', 'not_hidden']; offset,
if (allowed_hidden_list.includes(hidden)) { headers: merged_headers,
params['hidden'] = hidden; params_json,
} params,
log_lvl
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
}); });
if (log_lvl > 1) {
console.log(object_li_get_promise);
}
return object_li_get_promise;
}; };
// Updated 2023-07-24 // Updated 2023-07-24
@@ -959,7 +914,8 @@ const obj = {
download_hosted_file: download_hosted_file, download_hosted_file: download_hosted_file,
delete_hosted_file: delete_hosted_file, delete_hosted_file: delete_hosted_file,
get_data_store_obj_w_code: get_data_store_obj_w_code, 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 send_email: send_email
}; };
export const api = obj; export const api = obj;
// module.exports = api; // module.exports = api;

View File

@@ -14,15 +14,20 @@
async function load_lookups() { async function load_lookups() {
loading = true; loading = true;
// Using existing generic lookup loaders if available, or raw API calls
try { try {
const [countries, time_zones] = await Promise.all([ 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: 0 }), 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: 0 }) 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.countries = countries || [];
lookups.time_zones = time_zones || []; lookups.time_zones = time_zones || [];
lookups.subdivisions = subdivisions || [];
} catch (error) { } catch (error) {
console.error('Failed to load lookups:', error); console.error('Failed to load lookups:', error);
} finally { } finally {
@@ -86,7 +91,7 @@
<tbody> <tbody>
{#each lookups.countries as c} {#each lookups.countries as c}
<tr class="transition-colors"> <tr class="transition-colors">
<td class="font-bold">{c.name}</td> <td class="font-bold">{c.name || c.english_short_name}</td>
<td class="text-center"><span class="badge variant-soft-surface font-mono text-primary-500">{c.alpha_2_code}</span></td> <td class="text-center"><span class="badge variant-soft-surface font-mono text-primary-500">{c.alpha_2_code}</span></td>
</tr> </tr>
{/each} {/each}
@@ -124,6 +129,36 @@
</div> </div>
</div> </div>
<!-- Subdivisions (Full Width) -->
<div class="card p-6 shadow-xl variant-glass-surface border border-surface-500/10 space-y-6 animate-fade-in" style="animation-delay: 100ms;">
<h3 class="h4 font-bold border-b border-surface-500/30 pb-2 flex items-center gap-2">
<MapPin size={20} class="text-primary-500" />
Country Subdivisions (States/Provinces)
<span class="badge variant-soft-secondary ml-auto text-[10px] uppercase font-bold">{lookups.subdivisions.length} Records</span>
</h3>
<div class="table-container max-h-[600px] overflow-auto border border-surface-500/10 rounded-lg">
<table class="table table-hover table-compact">
<thead>
<tr class="uppercase text-[10px] tracking-widest opacity-60">
<th>Country</th>
<th>Name</th>
<th class="text-center">Code</th>
</tr>
</thead>
<tbody>
{#each lookups.subdivisions as s}
<tr class="transition-colors">
<td class="opacity-60">{s.country_alpha_2_code}</td>
<td class="font-bold">{s.name}</td>
<td class="text-center"><span class="badge variant-soft-surface font-mono">{s.code}</span></td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
<div class="card p-4 variant-soft-surface border border-surface-500/10 flex items-center gap-3"> <div class="card p-4 variant-soft-surface border border-surface-500/10 flex items-center gap-3">
<Info size={16} class="text-primary-500" /> <Info size={16} class="text-primary-500" />
<p class="text-xs opacity-70">Lookup data is synchronized with the global system database and used for addresses, event scheduling, and localized displays.</p> <p class="text-xs opacity-70">Lookup data is synchronized with the global system database and used for addresses, event scheduling, and localized displays.</p>