Implemented Aether API V3 Lookup integration for standardized tables.
- Created 'src/lib/ae_api/api_get__lookup_v3.ts' to handle the new '/v3/lookup/{lu_type}/list' endpoint.
- Refactored 'get_ae_obj_li_for_lu' in 'api.ts' to prioritize the V3 system for countries, subdivisions, and time zones, with V2 fallback for legacy types.
- Ensured lookups use the 'x-no-account-id' bypass for unauthenticated site bootstrapping.
- Updated core country, subdivision, and time zone loaders to use the refined API interface.
This commit is contained in:
56
src/lib/ae_api/api_get__lookup_v3.ts
Normal file
56
src/lib/ae_api/api_get__lookup_v3.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { get_object } from './api_get_object';
|
||||
import type { key_val } from '$lib/stores/ae_stores';
|
||||
|
||||
/**
|
||||
* Get a list of lookup objects (V3)
|
||||
* Standardized lookup data like countries, timezones, and subdivisions.
|
||||
* Updated 2026-02-20
|
||||
*
|
||||
* Endpoint: GET /v3/lookup/{lu_type}/list
|
||||
*/
|
||||
export async function get_ae_lookup_li_v3({
|
||||
api_cfg,
|
||||
lu_type,
|
||||
site_id,
|
||||
for_type,
|
||||
for_id,
|
||||
include_disabled = false,
|
||||
params = {},
|
||||
headers = {},
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
lu_type: 'country' | 'country_subdivision' | 'time_zone' | string;
|
||||
site_id?: string;
|
||||
for_type?: string;
|
||||
for_id?: string;
|
||||
include_disabled?: boolean;
|
||||
params?: key_val;
|
||||
headers?: Record<string, string>;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** get_ae_lookup_li_v3() *** lu_type=${lu_type}`);
|
||||
}
|
||||
|
||||
const endpoint = `/v3/lookup/${lu_type}/list`;
|
||||
|
||||
// Build query params
|
||||
if (site_id) params['site_id'] = site_id;
|
||||
if (for_type) params['for_type'] = for_type;
|
||||
if (for_id) params['for_id'] = for_id;
|
||||
if (include_disabled) params['include_disabled'] = true;
|
||||
|
||||
// Lookup data is often global; ensure account context is handled if needed,
|
||||
// but GUIDE says it uses site Whitelist Policy.
|
||||
// If no account_id is present in api_cfg, we might need 'x-no-account-id'
|
||||
// for some lookups if they are public.
|
||||
|
||||
return await get_object({
|
||||
api_cfg,
|
||||
endpoint,
|
||||
params,
|
||||
headers,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
@@ -11,7 +11,7 @@ export async function load_ae_obj_li__country({
|
||||
// account_id,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
limit = 299,
|
||||
limit = 275, // There are roughly 249 as of 2026-02
|
||||
offset = 0,
|
||||
order_by_li = { sort: 'DESC', english_short_name: 'ASC', alpha_2_code: 'ASC' } as const,
|
||||
params = {},
|
||||
@@ -38,19 +38,13 @@ export async function load_ae_obj_li__country({
|
||||
// console.log('params_json:', params_json);
|
||||
|
||||
ae_promises.load__country_li = await api
|
||||
.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
.get_ae_obj_li_for_lu({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'lu',
|
||||
for_obj_type: 'country',
|
||||
// for_obj_id: account_id,
|
||||
use_alt_tbl: false,
|
||||
use_alt_mdl: false,
|
||||
for_lu_type: 'country',
|
||||
enabled: enabled,
|
||||
hidden: hidden,
|
||||
order_by_li: order_by_li,
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
params_json: params_json,
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function load_ae_obj_li__country_subdivision({
|
||||
// account_id,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
limit = 399,
|
||||
limit = 3500, // There are roughly 3434 as of 2026-02
|
||||
offset = 0,
|
||||
order_by_li = { sort: 'DESC', name: 'ASC', code: 'ASC' } as const,
|
||||
params = {},
|
||||
@@ -38,19 +38,13 @@ export async function load_ae_obj_li__country_subdivision({
|
||||
// console.log('params_json:', params_json);
|
||||
|
||||
ae_promises.load__country_subdivision_li = await api
|
||||
.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
.get_ae_obj_li_for_lu({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'lu',
|
||||
for_obj_type: 'country_subdivision',
|
||||
// for_obj_id: account_id,
|
||||
use_alt_tbl: false,
|
||||
use_alt_mdl: false,
|
||||
for_lu_type: 'country_subdivision',
|
||||
enabled: enabled,
|
||||
hidden: hidden,
|
||||
order_by_li: order_by_li,
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
params_json: params_json,
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function load_ae_obj_li__time_zone({
|
||||
// account_id,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
limit = 99,
|
||||
limit = 1800, // There are roughly 1780 as of 2026-02
|
||||
offset = 0,
|
||||
// order_by_li = {'priority': 'DESC', 'group': 'ASC', 'sort': 'DESC', 'name': 'ASC'},
|
||||
order_by_li = { priority: 'DESC', sort: 'DESC', name: 'ASC' } as const,
|
||||
@@ -39,19 +39,13 @@ export async function load_ae_obj_li__time_zone({
|
||||
// console.log('params_json:', params_json);
|
||||
|
||||
ae_promises.load__time_zone_li = await api
|
||||
.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
.get_ae_obj_li_for_lu({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'lu',
|
||||
for_obj_type: 'time_zone',
|
||||
// for_obj_id: account_id,
|
||||
use_alt_tbl: true, // NOTE: Using this with the time zones to use the view named "v_lu_time_zone_cust"
|
||||
use_alt_mdl: false,
|
||||
for_lu_type: 'time_zone',
|
||||
enabled: enabled,
|
||||
hidden: hidden,
|
||||
order_by_li: order_by_li,
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
params_json: params_json,
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
|
||||
@@ -12,6 +12,7 @@ import { post_object } from '$lib/ae_api/api_post_object'; // Exported at the en
|
||||
import { get_ae_obj_id_crud } from '$lib/ae_api/api_get__crud_obj_id';
|
||||
import { get_ae_obj_li_for_obj_id_crud } from '$lib/ae_api/api_get__crud_obj_li_v1';
|
||||
import { get_ae_obj_li_for_obj_id_crud_v2 } from '$lib/ae_api/api_get__crud_obj_li_v2';
|
||||
import { get_ae_lookup_li_v3 } from '$lib/ae_api/api_get__lookup_v3';
|
||||
import {
|
||||
get_ae_obj_v3,
|
||||
get_nested_ae_obj_v3,
|
||||
@@ -31,9 +32,9 @@ import {
|
||||
import { get_data_store_v3 } from '$lib/ae_api/api_get__data_store_v3';
|
||||
|
||||
/**
|
||||
* Get a list of lookup objects (V2 Legacy)
|
||||
* Get a list of lookup objects (V3 with V2 Fallback)
|
||||
* Standardized lookup data like countries, timezones, and subdivisions.
|
||||
* Updated 2026-01-20
|
||||
* Updated 2026-02-20
|
||||
*/
|
||||
export const get_ae_obj_li_for_lu = async function get_ae_obj_li_for_lu({
|
||||
api_cfg,
|
||||
@@ -41,7 +42,7 @@ export const get_ae_obj_li_for_lu = async function get_ae_obj_li_for_lu({
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
order_by_li = null,
|
||||
limit = 999999,
|
||||
limit = 9999,
|
||||
offset = 0,
|
||||
headers = {},
|
||||
params_json = null,
|
||||
@@ -66,11 +67,23 @@ export const get_ae_obj_li_for_lu = async function get_ae_obj_li_for_lu({
|
||||
|
||||
// Lookup data is global; bypass account-id scope check
|
||||
const merged_headers = {
|
||||
...headers,
|
||||
'x-no-account-id': 'Nothing to See Here'
|
||||
'x-no-account-id': 'Nothing to See Here',
|
||||
...headers
|
||||
};
|
||||
|
||||
// Delegate to V2 helper which handles the /v2 prefix and /list suffix correctly
|
||||
// Use V3 system for primary lookup types
|
||||
if (['country', 'country_subdivision', 'time_zone'].includes(for_lu_type)) {
|
||||
return await get_ae_lookup_li_v3({
|
||||
api_cfg,
|
||||
lu_type: for_lu_type,
|
||||
include_disabled: enabled === 'all',
|
||||
params,
|
||||
headers: merged_headers,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
// Delegate to V2 helper for any other legacy lookup types
|
||||
return await get_ae_obj_li_for_obj_id_crud_v2({
|
||||
api_cfg,
|
||||
obj_type: 'lu',
|
||||
|
||||
Reference in New Issue
Block a user