export function createCustomMockApex(namespace: string): T { return createProxy(namespace) as T; } function createProxy(namespace: string, path: string[] = []) { return new Proxy( {}, { get(_target, key: string) { const newPath = [...path, key]; if (newPath.length === 2) { return (methodParams: Record) => { return fetch(`/aura`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ classname: newPath[0], method: newPath[1], namespace, params: methodParams, }), }).then((response) => { if (response.ok) { return response.json().then((data) => data.data); } throw new Error( `Failed to call Salesforce API, ${response.statusText}` ); }); }; } return createProxy(namespace, newPath); }, } ); }