new configuration for dataconnect request in internal api harness

This commit is contained in:
José Salazar
2025-11-19 15:57:45 -05:00
parent 38b68e8520
commit 35f0bc03fd
2 changed files with 84 additions and 2 deletions

View File

@@ -1,7 +1,9 @@
import apiClient from './client';
import { auth } from '../firebase';
import { auth, dataConnect } from '../firebase';
import { signOut } from 'firebase/auth';
import * as dcSdk from '@dataconnect/generated'; // listEvents, createEvent, etc.
// --- Auth Module ---
const authModule = {
/**
@@ -96,7 +98,7 @@ const coreIntegrationsModule = {
// --- Entities Module ---
// Based on docs/07-reference-base44-api-export.md
const entityNames = [
/*const entityNames = [
"User", "Event", "Staff", "Vendor", "VendorRate", "Invoice", "Business",
"Certification", "Team", "Conversation", "Message", "ActivityLog",
"Enterprise", "Sector", "Partner", "Order", "Shift"
@@ -134,6 +136,83 @@ entityNames.forEach(entityName => {
return data;
}
};
});*/
const dataconnectEntityConfig = {
Event: {
list: 'listEvents',
create: 'createEvent',
// get: 'getEvent',
// update: 'updateEvent',
// delete: 'deleteEvent',
// filter: 'filterEvents',
},
// Staff: {
// list: 'listStaff',
// create: 'createStaff',
// ...
// },
};
// Helper for methods not implemented
const notImplemented = (entityName, method) => async () => {
throw new Error(`${entityName}.${method} is not implemented yet for Data Connect`);
};
// --- Entities Module ( Data Connect, without REST Base44) ---
const entitiesModule = {};
Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
entitiesModule[entityName] = {
get: notImplemented(entityName, 'get'),
update: notImplemented(entityName, 'update'),
delete: notImplemented(entityName, 'delete'),
filter: notImplemented(entityName, 'filter'),
list: notImplemented(entityName, 'list'),
create: notImplemented(entityName, 'create'),
// list
...(ops.list && {
list: async (params) => {
const fn = dcSdk[ops.list];
if (typeof fn !== 'function') {
throw new Error(
`Data Connect operation "${ops.list}" not found for entity "${entityName}".`
);
}
return fn(dataConnect);
},
}),
// create
...(ops.create && {
create: async (params) => {
const fn = dcSdk[ops.create];
if (typeof fn !== 'function') {
throw new Error(
`Data Connect operation "${ops.create}" not found for entity "${entityName}".`
);
}
const { data } = params ?? {};
if (!data) {
throw new Error(
`${entityName}.create expects a payload like { data: { ...fields } }`
);
}
return fn(dataConnect, data);
},
}),
// ...(ops.get && { get: async (params) => { ... } }),
// ...(ops.update && { update: async (params) => { ... } }),
// ...(ops.delete && { delete: async (params) => { ... } }),
// ...(ops.filter && { filter: async (params) => { ... } }),
};
});

View File

@@ -1,6 +1,8 @@
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig } from '@dataconnect/generated';
// Your web app's Firebase configuration
const firebaseConfig = {
@@ -14,4 +16,5 @@ const firebaseConfig = {
// Initialize Firebase
const app = initializeApp(firebaseConfig);
export const dataConnect = getDataConnect(app, connectorConfig);
export const auth = getAuth(app);