refactor(core): fix svelte-check errors and clean up ae_core_functions
- Fix two broken V1/V2 api calls (get_ae_obj_id_crud, update_ae_obj_id_crud) that no longer exist on the api object — replaced with V3 equivalents - Comment out two dead/uncalled functions (load_ae_obj_id__site_domain, update_ae_obj_id_crud) and remove them from the export; pending full removal - Extract download_export__obj_type into core__export.ts following the core__*.ts module convention Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
import { browser } from '$app/environment';
|
||||
import type { key_val } from '$lib/stores/ae_stores';
|
||||
import { api } from '$lib/api/api';
|
||||
|
||||
import {
|
||||
load_ae_obj_id__activity_log,
|
||||
load_ae_obj_li__activity_log,
|
||||
@@ -49,136 +45,112 @@ import { db_save_ae_obj_li__ae_obj } from '$lib/ae_core/core__idb_dexie';
|
||||
|
||||
import { add_url_params, clean_headers } from '$lib/ae_core/core__api_helpers';
|
||||
|
||||
const ae_promises: key_val = {}; // Promise<any>;
|
||||
import { download_export__obj_type } from '$lib/ae_core/core__export';
|
||||
|
||||
// Updated 2024-03-29
|
||||
async function load_ae_obj_id__site_domain({
|
||||
api_cfg,
|
||||
fqdn,
|
||||
timeout = 7000,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
fqdn: string;
|
||||
timeout?: number;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
`*** load_ae_obj_id__site_domain() *** api.base_url=${api_cfg.base_url}, fqdn=${fqdn}, timeout=${timeout}`
|
||||
);
|
||||
}
|
||||
|
||||
let no_account_id = false;
|
||||
if (!api_cfg.account_id) {
|
||||
no_account_id = true;
|
||||
// api_cfg.headers['x_account_id'] = 'nothing here';
|
||||
}
|
||||
// LEGACY BOOTSTRAP SPECIAL CASE: this helper is effectively a remove
|
||||
// candidate once all site-domain lookups use the cache-first/bootstrap
|
||||
// path in ae_core__site.ts.
|
||||
no_account_id = true;
|
||||
|
||||
const params = {};
|
||||
|
||||
// ae_sess.hub.site_domain_id_qry_status = 'loading';
|
||||
ae_promises.load__site_domain_obj = api
|
||||
.get_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
no_account_id: no_account_id,
|
||||
obj_type: 'site_domain',
|
||||
obj_id: fqdn, // NOTE: This is the FQDN, not normally the ID.
|
||||
use_alt_table: true, // NOTE: This will use the table_name_alt value (v_site_domain_fqdn_id) instead of the table_name value in the API config.
|
||||
use_alt_base: true, // NOTE: This will use the base_name_alt value (Site_Domain_FQDN_ID_Base) instead of the base_name value in the API config.
|
||||
params: params,
|
||||
timeout: timeout,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (site_domain_obj_get_result) {
|
||||
if (site_domain_obj_get_result) {
|
||||
// slct.site_domain_obj = site_domain_obj_get_result;
|
||||
// console.log(`site_domain object:`, get(slct).site_domain_obj);
|
||||
|
||||
// ae_loc.account_id = $slct.site_domain_obj.account_id_random;
|
||||
// ae_loc.site_id = $slct.site_domain_obj.site_id_random;
|
||||
// ae_loc.site_domain_id = $slct.site_domain_obj.site_domain_id_random;
|
||||
return site_domain_obj_get_result;
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
return ae_promises.load__site_domain_obj;
|
||||
}
|
||||
|
||||
// Updated 2024-03-27
|
||||
async function update_ae_obj_id_crud({
|
||||
api_cfg,
|
||||
object_type,
|
||||
object_id,
|
||||
object_reload = false,
|
||||
field_name,
|
||||
new_field_value,
|
||||
params = {},
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
object_type: string;
|
||||
object_id: string;
|
||||
object_reload?: boolean;
|
||||
field_name: string;
|
||||
new_field_value: any;
|
||||
params?: any | key_val;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
let patch_result: any = null;
|
||||
|
||||
ae_promises.api_update__ae_obj = api
|
||||
.update_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: object_type,
|
||||
obj_id: object_id,
|
||||
field_name: field_name,
|
||||
field_value: new_field_value,
|
||||
// fields: data,
|
||||
key: api_cfg.api_crud_super_key,
|
||||
// jwt: null,
|
||||
// DEAD CODE — no callers; pending removal. Updated 2024-03-29
|
||||
// async function load_ae_obj_id__site_domain({
|
||||
// api_cfg,
|
||||
// fqdn,
|
||||
// timeout = 7000,
|
||||
// log_lvl = 0
|
||||
// }: {
|
||||
// api_cfg: any;
|
||||
// fqdn: string;
|
||||
// timeout?: number;
|
||||
// log_lvl?: number;
|
||||
// }) {
|
||||
// if (log_lvl) {
|
||||
// console.log(
|
||||
// `*** load_ae_obj_id__site_domain() *** api.base_url=${api_cfg.base_url}, fqdn=${fqdn}, timeout=${timeout}`
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// let no_account_id = false;
|
||||
// if (!api_cfg.account_id) {
|
||||
// no_account_id = true;
|
||||
// }
|
||||
// // LEGACY BOOTSTRAP SPECIAL CASE: this helper is effectively a remove
|
||||
// // candidate once all site-domain lookups use the cache-first/bootstrap
|
||||
// // path in ae_core__site.ts.
|
||||
// no_account_id = true;
|
||||
//
|
||||
// const params = {};
|
||||
//
|
||||
// ae_promises.load__site_domain_obj = api
|
||||
// .get_ae_obj({
|
||||
// api_cfg: api_cfg,
|
||||
// obj_type: 'site_domain',
|
||||
// obj_id: fqdn,
|
||||
// params: params,
|
||||
// data: patch_data,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (results) {
|
||||
console.log('PATCH Promise', results);
|
||||
// log_lvl: log_lvl
|
||||
// })
|
||||
// .then(function (site_domain_obj_get_result: any) {
|
||||
// if (site_domain_obj_get_result) {
|
||||
// return site_domain_obj_get_result;
|
||||
// } else {
|
||||
// console.log('No results returned.');
|
||||
// return null;
|
||||
// }
|
||||
// })
|
||||
// .catch(function (error: any) {
|
||||
// console.log('No results returned or failed.', error);
|
||||
// });
|
||||
//
|
||||
// return ae_promises.load__site_domain_obj;
|
||||
// }
|
||||
|
||||
if (results) {
|
||||
console.log(
|
||||
`Patched - Field Name: ${field_name} with new Field Value: ${new_field_value}`
|
||||
);
|
||||
patch_result = 'PATCH complete';
|
||||
} else {
|
||||
console.log(
|
||||
`Not Patched - Field Name: ${field_name} with new Field Value: ${new_field_value}; Account ID: ${api_cfg.account_id}`
|
||||
);
|
||||
patch_result = 'PATCH failed';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('Something went wrong patching the record.');
|
||||
console.log(error);
|
||||
return false;
|
||||
})
|
||||
.finally(function () {
|
||||
console.log('PATCH Promise finally');
|
||||
});
|
||||
|
||||
return ae_promises.api_update__ae_obj;
|
||||
}
|
||||
// DEAD CODE — no callers; pending removal. Updated 2024-03-27
|
||||
// async function update_ae_obj_id_crud({
|
||||
// api_cfg,
|
||||
// object_type,
|
||||
// object_id,
|
||||
// object_reload = false,
|
||||
// field_name,
|
||||
// new_field_value,
|
||||
// params = {},
|
||||
// log_lvl = 0
|
||||
// }: {
|
||||
// api_cfg: any;
|
||||
// object_type: string;
|
||||
// object_id: string;
|
||||
// object_reload?: boolean;
|
||||
// field_name: string;
|
||||
// new_field_value: any;
|
||||
// params?: any | key_val;
|
||||
// log_lvl?: number;
|
||||
// }) {
|
||||
// let patch_result: any = null;
|
||||
//
|
||||
// ae_promises.api_update__ae_obj = api
|
||||
// .update_ae_obj({
|
||||
// api_cfg: api_cfg,
|
||||
// obj_type: object_type,
|
||||
// obj_id: object_id,
|
||||
// fields: { [field_name]: new_field_value },
|
||||
// log_lvl: log_lvl
|
||||
// })
|
||||
// .then(function (results: any) {
|
||||
// console.log('PATCH Promise', results);
|
||||
//
|
||||
// if (results) {
|
||||
// patch_result = 'PATCH complete';
|
||||
// } else {
|
||||
// patch_result = 'PATCH failed';
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
// })
|
||||
// .catch(function (error: any) {
|
||||
// console.log('Something went wrong patching the record.');
|
||||
// console.log(error);
|
||||
// return false;
|
||||
// })
|
||||
// .finally(function () {
|
||||
// console.log('PATCH Promise finally');
|
||||
// });
|
||||
//
|
||||
// return ae_promises.api_update__ae_obj;
|
||||
// }
|
||||
|
||||
// // Core - Already imported above
|
||||
// // import { load_ae_obj_id__person } from "$lib/ae_core/core__person";
|
||||
@@ -277,79 +249,6 @@ async function update_ae_obj_id_crud({
|
||||
// return results;
|
||||
// }
|
||||
|
||||
async function download_export__obj_type({
|
||||
api_cfg,
|
||||
get_obj_type, // The type of object to return: event_badge, event_presenter, sponsorship, etc.
|
||||
for_obj_type, // Usually for an account, event, event_exhibit, or sponsorship_cfg
|
||||
for_obj_id, // The ID of the object
|
||||
exp_alt = null, // Export name (idaa, other, not 'default')
|
||||
file_type = 'CSV', // 'CSV' or 'Excel'
|
||||
return_file = true,
|
||||
filename = 'no_filename.csv',
|
||||
auto_download = false,
|
||||
limit = 5000,
|
||||
params = {}, // key value object is expected
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
get_obj_type: string;
|
||||
for_obj_type: string;
|
||||
for_obj_id: string;
|
||||
exp_alt?: null | string;
|
||||
file_type?: string;
|
||||
return_file?: boolean;
|
||||
filename?: string;
|
||||
auto_download?: boolean;
|
||||
limit?: number;
|
||||
params?: key_val;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
console.log('*** ae_core_functions.js: download_export__obj_type() ***');
|
||||
|
||||
const task_id = for_obj_id;
|
||||
|
||||
const endpoint = `/v2/crud/${get_obj_type}/list`;
|
||||
params['for_obj_type'] = for_obj_type;
|
||||
params['for_obj_id'] = for_obj_id;
|
||||
|
||||
if (file_type == 'CSV' || file_type == 'Excel') {
|
||||
params['file_type'] = file_type;
|
||||
}
|
||||
params['return_file'] = true;
|
||||
|
||||
params['mdl_alt'] = 'out';
|
||||
|
||||
if (exp_alt) {
|
||||
params['exp_alt'] = exp_alt;
|
||||
}
|
||||
|
||||
// let clean_filename = filename.replace(/[^a-z0-9]/gi, '_');
|
||||
// let clean_filename = filename.replace(/[^a-z0-9\[\]-]/gi, '_');
|
||||
const clean_filename = filename.replace(/[^a-zA-Z0-9\[\]-_.]/gi, '_');
|
||||
// let clean_filename = filename.replace(/[^a-zA-Z0-9\[\]-\._ ]/gi, '_');
|
||||
|
||||
if (limit >= 0) {
|
||||
params['limit'] = limit;
|
||||
}
|
||||
|
||||
ae_promises.download__export_file = await api.get_object({
|
||||
api_cfg: api_cfg,
|
||||
endpoint: endpoint,
|
||||
params: params,
|
||||
timeout: 90000, // Seems to timeout sometimes with the default of 60 seconds
|
||||
return_blob: return_file,
|
||||
filename: clean_filename,
|
||||
auto_download: auto_download,
|
||||
task_id: task_id,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
|
||||
console.log(
|
||||
'ae_promises.download__export_file:',
|
||||
ae_promises.download__export_file
|
||||
);
|
||||
return ae_promises.download__export_file;
|
||||
}
|
||||
|
||||
const export_obj = {
|
||||
check_hosted_file_obj_w_hash: check_hosted_file_obj_w_hash,
|
||||
@@ -368,8 +267,6 @@ const export_obj = {
|
||||
add_url_params: add_url_params,
|
||||
clean_headers: clean_headers,
|
||||
|
||||
load_ae_obj_id__site_domain: load_ae_obj_id__site_domain,
|
||||
|
||||
load_ae_obj_id__activity_log: load_ae_obj_id__activity_log,
|
||||
load_ae_obj_li__activity_log: load_ae_obj_li__activity_log,
|
||||
create_ae_obj__activity_log: create_ae_obj__activity_log,
|
||||
@@ -387,7 +284,6 @@ const export_obj = {
|
||||
qry_ae_obj_li__user_email: qry_ae_obj_li__user_email,
|
||||
auth_ae_obj__user_id_change_password: auth_ae_obj__user_id_change_password,
|
||||
|
||||
update_ae_obj_id_crud: update_ae_obj_id_crud,
|
||||
// update_ae_obj_id_crud_v2: update_ae_obj_id_crud_v2,
|
||||
download_export__obj_type: download_export__obj_type,
|
||||
generate_qr_code: generate_qr_code,
|
||||
|
||||
68
src/lib/ae_core/core__export.ts
Normal file
68
src/lib/ae_core/core__export.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import type { key_val } from '$lib/stores/ae_stores';
|
||||
import { api } from '$lib/api/api';
|
||||
|
||||
export async function download_export__obj_type({
|
||||
api_cfg,
|
||||
get_obj_type, // The type of object to return: event_badge, event_presenter, sponsorship, etc.
|
||||
for_obj_type, // Usually for an account, event, event_exhibit, or sponsorship_cfg
|
||||
for_obj_id, // The ID of the object
|
||||
exp_alt = null, // Export name (idaa, other, not 'default')
|
||||
file_type = 'CSV', // 'CSV' or 'Excel'
|
||||
return_file = true,
|
||||
filename = 'no_filename.csv',
|
||||
auto_download = false,
|
||||
limit = 5000,
|
||||
params = {}, // key value object is expected
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
get_obj_type: string;
|
||||
for_obj_type: string;
|
||||
for_obj_id: string;
|
||||
exp_alt?: null | string;
|
||||
file_type?: string;
|
||||
return_file?: boolean;
|
||||
filename?: string;
|
||||
auto_download?: boolean;
|
||||
limit?: number;
|
||||
params?: key_val;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
const endpoint = `/v2/crud/${get_obj_type}/list`;
|
||||
params['for_obj_type'] = for_obj_type;
|
||||
params['for_obj_id'] = for_obj_id;
|
||||
|
||||
if (file_type == 'CSV' || file_type == 'Excel') {
|
||||
params['file_type'] = file_type;
|
||||
}
|
||||
params['return_file'] = true;
|
||||
params['mdl_alt'] = 'out';
|
||||
|
||||
if (exp_alt) {
|
||||
params['exp_alt'] = exp_alt;
|
||||
}
|
||||
|
||||
const clean_filename = filename.replace(/[^a-zA-Z0-9\[\]-_.]/gi, '_');
|
||||
|
||||
if (limit >= 0) {
|
||||
params['limit'] = limit;
|
||||
}
|
||||
|
||||
const result = await api.get_object({
|
||||
api_cfg: api_cfg,
|
||||
endpoint: endpoint,
|
||||
params: params,
|
||||
timeout: 90000, // Seems to timeout sometimes with the default of 60 seconds
|
||||
return_blob: return_file,
|
||||
filename: clean_filename,
|
||||
auto_download: auto_download,
|
||||
task_id: for_obj_id,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('download_export__obj_type result:', result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user