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:
@@ -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;
|
||||
@@ -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 @@
|
||||
<tbody>
|
||||
{#each lookups.countries as c}
|
||||
<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>
|
||||
</tr>
|
||||
{/each}
|
||||
@@ -124,6 +129,36 @@
|
||||
</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">
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user