Refactor core API helpers and implement System Testing Dashboard
- Unified and hardened get, post, patch, and delete helpers with standardized retry logic, kebab-case headers, and V3 response envelope handling. - Implemented robust 'Bootstrap Paradox' resolution logic across the API stack to handle unauthenticated site domain lookups safely. - Enhanced API helpers to support custom fetch injection, enabling reliable server-side execution in SvelteKit. - Upgraded /testing page into a comprehensive System Testing Dashboard for core helper and V3 search verification. - Updated TODO.md and GEMINI.md with 2026-01-08 session learnings and 'Frontier Journals' vision.
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import type { key_val } from '$lib/stores/ae_stores';
|
||||
import { get_object } from './api_get_object';
|
||||
|
||||
// Updated 2023-12-01
|
||||
/**
|
||||
* Fetches a single Aether object by its ID using the CRUD endpoint.
|
||||
* Refactored 2026-01-08 to properly handle unauthenticated lookups (Bootstrap Paradox)
|
||||
* and ensure clean header passing to get_object without mutating the global config.
|
||||
*/
|
||||
export async function get_ae_obj_id_crud({
|
||||
api_cfg,
|
||||
no_account_id = false,
|
||||
@@ -15,11 +19,9 @@ export async function get_ae_obj_id_crud({
|
||||
limit = 999999,
|
||||
offset = 0,
|
||||
data = {},
|
||||
// key,
|
||||
// jwt = null,
|
||||
headers = {},
|
||||
params = {},
|
||||
timeout = 25000,
|
||||
timeout = 60000,
|
||||
return_meta = false,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
@@ -35,8 +37,6 @@ export async function get_ae_obj_id_crud({
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
data?: any;
|
||||
// key: string,
|
||||
// jwt?: string,
|
||||
headers?: any;
|
||||
params?: key_val;
|
||||
timeout?: number;
|
||||
@@ -44,129 +44,88 @@ export async function get_ae_obj_id_crud({
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log('*** get_ae_obj_id_crud() ***');
|
||||
console.log(`*** get_ae_obj_id_crud() *** Type: ${obj_type} ID: ${obj_id}`);
|
||||
}
|
||||
|
||||
// data = {};
|
||||
// data['super_key'] = key;
|
||||
// data['jwt'] = jwt;
|
||||
// NOTE: The key and or JWT should be in the header of the DELETE, GET, PATCH, POST
|
||||
|
||||
let endpoint = '';
|
||||
if (obj_type == 'account') {
|
||||
endpoint = `/crud/account/${obj_id}`;
|
||||
} else if (obj_type == 'address') {
|
||||
endpoint = `/crud/address/${obj_id}`;
|
||||
} else if (obj_type == 'archive') {
|
||||
endpoint = `/crud/archive/${obj_id}`;
|
||||
} else if (obj_type == 'archive_content') {
|
||||
endpoint = `/crud/archive/content/${obj_id}`;
|
||||
} else if (obj_type == 'contact') {
|
||||
endpoint = `/crud/contact/${obj_id}`;
|
||||
} else if (obj_type == 'data_store') {
|
||||
endpoint = `/crud/data_store/${obj_id}`;
|
||||
} else if (obj_type == 'event') {
|
||||
endpoint = `/crud/event/${obj_id}`;
|
||||
} else if (obj_type == 'event_abstract') {
|
||||
endpoint = `/crud/event/abstract/${obj_id}`;
|
||||
} else if (obj_type == 'event_badge') {
|
||||
endpoint = `/crud/event/badge/${obj_id}`;
|
||||
} else if (obj_type == 'event_device') {
|
||||
endpoint = `/crud/event/device/${obj_id}`;
|
||||
} else if (obj_type == 'event_exhibit') {
|
||||
endpoint = `/crud/event/exhibit/${obj_id}`;
|
||||
} else if (obj_type == 'event_exhibit_tracking') {
|
||||
endpoint = `/crud/event/exhibit/tracking/${obj_id}`;
|
||||
} else if (obj_type == 'event_file') {
|
||||
endpoint = `/crud/event/file/${obj_id}`;
|
||||
} else if (obj_type == 'event_location') {
|
||||
endpoint = `/crud/event/location/${obj_id}`;
|
||||
} else if (obj_type == 'event_person') {
|
||||
endpoint = `/crud/event/person/${obj_id}`;
|
||||
} else if (obj_type == 'event_presentation') {
|
||||
endpoint = `/crud/event/presentation/${obj_id}`;
|
||||
} else if (obj_type == 'event_presenter') {
|
||||
endpoint = `/crud/event/presenter/${obj_id}`;
|
||||
} else if (obj_type == 'event_session') {
|
||||
endpoint = `/crud/event/session/${obj_id}`;
|
||||
} else if (obj_type == 'event_track') {
|
||||
endpoint = `/crud/event/track/${obj_id}`;
|
||||
} else if (obj_type == 'grant') {
|
||||
endpoint = `/crud/grant/${obj_id}`;
|
||||
} else if (obj_type == 'hosted_file') {
|
||||
endpoint = `/crud/hosted_file/${obj_id}`;
|
||||
} else if (obj_type == 'journal') {
|
||||
endpoint = `/crud/journal/${obj_id}`;
|
||||
} else if (obj_type == 'journal_entry') {
|
||||
endpoint = `/crud/journal/entry/${obj_id}`;
|
||||
} else if (obj_type == 'order') {
|
||||
endpoint = `/crud/order/${obj_id}`;
|
||||
} else if (obj_type == 'order_line') {
|
||||
endpoint = `/crud/order/line/${obj_id}`;
|
||||
} else if (obj_type == 'page') {
|
||||
endpoint = `/crud/page/${obj_id}`;
|
||||
} else if (obj_type == 'person') {
|
||||
endpoint = `/crud/person/${obj_id}`;
|
||||
} else if (obj_type == 'post') {
|
||||
endpoint = `/crud/post/${obj_id}`;
|
||||
} else if (obj_type == 'post_comment') {
|
||||
endpoint = `/crud/post/comment/${obj_id}`;
|
||||
} else if (obj_type == 'site') {
|
||||
endpoint = `/crud/site/${obj_id}`;
|
||||
} else if (obj_type == 'site_domain') {
|
||||
endpoint = `/crud/site/domain/${obj_id}`;
|
||||
} else if (obj_type == 'sponsorship_cfg') {
|
||||
endpoint = `/crud/sponsorship/cfg/${obj_id}`;
|
||||
} else if (obj_type == 'sponsorship') {
|
||||
endpoint = `/crud/sponsorship/${obj_id}`;
|
||||
// } else if (obj_type == 'user') {
|
||||
// endpoint = `/crud/user/${obj_id}`;
|
||||
// Map object types to their respective CRUD endpoints
|
||||
const objTypeToEndpointMap: Record<string, string> = {
|
||||
'account': '/crud/account',
|
||||
'address': '/crud/address',
|
||||
'archive': '/crud/archive',
|
||||
'archive_content': '/crud/archive/content',
|
||||
'contact': '/crud/contact',
|
||||
'data_store': '/crud/data_store',
|
||||
'event': '/crud/event',
|
||||
'event_abstract': '/crud/event/abstract',
|
||||
'event_badge': '/crud/event/badge',
|
||||
'event_device': '/crud/event/device',
|
||||
'event_exhibit': '/crud/event/exhibit',
|
||||
'event_exhibit_tracking': '/crud/event/exhibit/tracking',
|
||||
'event_file': '/crud/event/file',
|
||||
'event_location': '/crud/event/location',
|
||||
'event_person': '/crud/event/person',
|
||||
'event_presentation': '/crud/event/presentation',
|
||||
'event_presenter': '/crud/event/presenter',
|
||||
'event_session': '/crud/event/session',
|
||||
'event_track': '/crud/event/track',
|
||||
'grant': '/crud/grant',
|
||||
'hosted_file': '/crud/hosted_file',
|
||||
'journal': '/crud/journal',
|
||||
'journal_entry': '/crud/journal/entry',
|
||||
'order': '/crud/order',
|
||||
'order_line': '/crud/order/line',
|
||||
'page': '/crud/page',
|
||||
'person': '/crud/person',
|
||||
'post': '/crud/post',
|
||||
'post_comment': '/crud/post/comment',
|
||||
'site': '/crud/site',
|
||||
'site_domain': '/crud/site/domain',
|
||||
'sponsorship_cfg': '/crud/sponsorship/cfg',
|
||||
'sponsorship': '/crud/sponsorship'
|
||||
};
|
||||
|
||||
if (objTypeToEndpointMap[obj_type]) {
|
||||
endpoint = `${objTypeToEndpointMap[obj_type]}/${obj_id}`;
|
||||
} else {
|
||||
console.log(`Unknown object type: ${obj_type}`);
|
||||
console.error(`Unknown object type: ${obj_type}`);
|
||||
return false;
|
||||
}
|
||||
if (log_lvl) {
|
||||
|
||||
if (log_lvl > 1) {
|
||||
console.log('Endpoint:', endpoint);
|
||||
}
|
||||
|
||||
params['use_alt_table'] = use_alt_table;
|
||||
params['use_alt_base'] = use_alt_base;
|
||||
const final_params = {
|
||||
...params,
|
||||
use_alt_table: use_alt_table,
|
||||
use_alt_base: use_alt_base
|
||||
};
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('Params:', params);
|
||||
}
|
||||
const final_headers = { ...headers };
|
||||
|
||||
if (no_account_id) {
|
||||
headers['x-no-account-id'] = 'Nothing to See Here';
|
||||
delete headers['x-account-id'];
|
||||
delete api_cfg['headers']['x-account-id'];
|
||||
// headers['x-account-id'] = null;
|
||||
// headers['x-account-id'] = '_XY7DXtc9Mxx';
|
||||
// params['x_no_account_id_token'] = 'Nothing to See Here';
|
||||
|
||||
// Remove the x-account-id header
|
||||
// if (headers['x-account-id']) {
|
||||
// delete headers['x-account-id'];
|
||||
// }
|
||||
|
||||
// headers['x-account-id'] = null;
|
||||
// headers['x-no-account-id-token'] = 'Nothing to See Here'; // get_object() will fix the underscores to dashes
|
||||
// This instructs get_object to skip account-id requirements
|
||||
final_headers['x-no-account-id'] = 'Nothing to See Here';
|
||||
final_headers['x-account-id'] = null; // Explicitly null to trigger removal in get_object
|
||||
}
|
||||
|
||||
const object_obj_get_promise = await get_object({
|
||||
const result = await get_object({
|
||||
api_cfg: api_cfg,
|
||||
endpoint: endpoint,
|
||||
headers: headers,
|
||||
params: params,
|
||||
headers: final_headers,
|
||||
params: final_params,
|
||||
timeout: timeout,
|
||||
log_lvl: log_lvl
|
||||
log_lvl: log_lvl,
|
||||
return_meta: return_meta
|
||||
}).catch(function (error: any) {
|
||||
console.log('API GET CRUD object ID request failed.', error);
|
||||
console.error(`API GET CRUD object ID request failed for ${obj_type}/${obj_id}`, error);
|
||||
return false;
|
||||
});
|
||||
|
||||
if (log_lvl > 1) {
|
||||
console.log('GET Object result =', object_obj_get_promise);
|
||||
console.log('GET Object result =', result);
|
||||
}
|
||||
|
||||
return object_obj_get_promise;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user