feat: implement workspace session management and enhance API proxy handling
This commit is contained in:
+79
-62
@@ -60,70 +60,87 @@ import { InventoryCategoriesClient } from "./clients/inventory-categories"
|
||||
import { DocumentPrintClient } from "./clients/document-print"
|
||||
import { DocumentShareClient } from "./clients/document-share"
|
||||
|
||||
export function createApi(options?: ApiClientOptions) {
|
||||
export type CreateApiOptions = ApiClientOptions & { baseUrl?: string }
|
||||
|
||||
/**
|
||||
* Default base URL used when no explicit override is passed. The dashboard
|
||||
* runs every browser call through the Next.js server proxy at /api/proxy so
|
||||
* the build-time NEXT_PUBLIC_API_URL never reaches the client.
|
||||
*
|
||||
* Server-side callers (server actions, RSC) can opt out by passing
|
||||
* `{ baseUrl: <absolute repareenew URL> }` from a cookie.
|
||||
*/
|
||||
const DEFAULT_BASE_URL = "/api/proxy"
|
||||
|
||||
export function createApi(options?: CreateApiOptions) {
|
||||
const baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL
|
||||
const restOptions: ApiClientOptions | undefined = options?.headers
|
||||
? { headers: options.headers }
|
||||
: undefined
|
||||
|
||||
return {
|
||||
auth: new AuthClient(undefined, options),
|
||||
customers: new CustomersClient(undefined, options),
|
||||
referralSources: new ReferralSourcesClient(undefined, options),
|
||||
vehicles: new VehiclesClient(undefined, options),
|
||||
vehicleAttributes: new VehicleAttributesClient(undefined, options),
|
||||
vehicleDocuments: new VehicleDocumentsClient(undefined, options),
|
||||
departments: new DepartmentsClient(undefined, options),
|
||||
employees: new EmployeesClient(undefined, options),
|
||||
geo: new GeoClient(undefined, options),
|
||||
paymentTerms: new PaymentTermsClient(undefined, options),
|
||||
shopTypes: new ShopTypesClient(undefined, options),
|
||||
inventory: new InventoryClient(undefined, options),
|
||||
vendors: new VendorsClient(undefined, options),
|
||||
inspections: new InspectionsClient(undefined, options),
|
||||
inspectionTemplates: new InspectionTemplatesClient(undefined, options),
|
||||
labels: new LabelsClient(undefined, options),
|
||||
insuranceTypes: new InsuranceTypesClient(undefined, options),
|
||||
estimates: new EstimatesClient(undefined, options),
|
||||
quickRemarks: new QuickRemarksClient(undefined, options),
|
||||
quickNotes: new QuickNotesClient(undefined, options),
|
||||
shopRecommendations: new ShopRecommendationsClient(undefined, options),
|
||||
jobCards: new JobCardsClient(undefined, options),
|
||||
paymentModes: new PaymentModesClient(undefined, options),
|
||||
paymentReceived: new PaymentReceivedClient(undefined, options),
|
||||
parts: new PartsClient(undefined, options),
|
||||
purchaseOrders: new PurchaseOrdersClient(undefined, options),
|
||||
services: new ServicesClient(undefined, options),
|
||||
serviceGroups: new ServiceGroupsClient(undefined, options),
|
||||
expenses: new ExpensesClient(undefined, options),
|
||||
tasks: new TasksClient(undefined, options),
|
||||
taskTypes: new TaskTypesClient(undefined, options),
|
||||
taskSections: new TaskSectionsClient(undefined, options),
|
||||
appointments: new AppointmentsClient(undefined, options),
|
||||
shopTimings: new ShopTimingsClient(undefined, options),
|
||||
shopCalendars: new ShopCalendarsClient(undefined, options),
|
||||
holidayYears: new HolidayYearsClient(undefined, options),
|
||||
taxes: new TaxesClient(undefined, options),
|
||||
invoices: new InvoicesClient(undefined, options),
|
||||
home: new HomeClient(undefined, options),
|
||||
bills: new BillsClient(undefined, options),
|
||||
reasons: new ReasonsClient(undefined, options),
|
||||
holidays: new HolidaysClient(undefined, options),
|
||||
makeAndModels: new MakeAndModelsClient(undefined, options),
|
||||
timeSheets: new TimeSheetsClient(undefined, options),
|
||||
invoiceSequences: new InvoiceSequencesClient(undefined, options),
|
||||
creditNotes: new CreditNotesClient(undefined, options),
|
||||
paymentMades: new PaymentMadesClient(undefined, options),
|
||||
vendorCredits: new VendorCreditsClient(undefined, options),
|
||||
inventoryAdjustments: new InventoryAdjustmentsClient(undefined, options),
|
||||
serviceGroupIncludes: new ServiceGroupIncludesClient(undefined, options),
|
||||
serviceGroupPricings: new ServiceGroupPricingsClient(undefined, options),
|
||||
serviceGroupServices: new ServiceGroupServicesClient(undefined, options),
|
||||
serviceGroupParts: new ServiceGroupPartsClient(undefined, options),
|
||||
settings: new SettingsClient(undefined, options),
|
||||
configurations: new ConfigurationsClient(undefined, options),
|
||||
autoGenerate: new AutoGenerateClient(undefined, options),
|
||||
expenseItems: new ExpenseItemsClient(undefined, options),
|
||||
inventoryCategories: new InventoryCategoriesClient(undefined, options),
|
||||
documentPrint: new DocumentPrintClient(undefined, options),
|
||||
documentShare: new DocumentShareClient(undefined, options),
|
||||
auth: new AuthClient(baseUrl, restOptions),
|
||||
customers: new CustomersClient(baseUrl, restOptions),
|
||||
referralSources: new ReferralSourcesClient(baseUrl, restOptions),
|
||||
vehicles: new VehiclesClient(baseUrl, restOptions),
|
||||
vehicleAttributes: new VehicleAttributesClient(baseUrl, restOptions),
|
||||
vehicleDocuments: new VehicleDocumentsClient(baseUrl, restOptions),
|
||||
departments: new DepartmentsClient(baseUrl, restOptions),
|
||||
employees: new EmployeesClient(baseUrl, restOptions),
|
||||
geo: new GeoClient(baseUrl, restOptions),
|
||||
paymentTerms: new PaymentTermsClient(baseUrl, restOptions),
|
||||
shopTypes: new ShopTypesClient(baseUrl, restOptions),
|
||||
inventory: new InventoryClient(baseUrl, restOptions),
|
||||
vendors: new VendorsClient(baseUrl, restOptions),
|
||||
inspections: new InspectionsClient(baseUrl, restOptions),
|
||||
inspectionTemplates: new InspectionTemplatesClient(baseUrl, restOptions),
|
||||
labels: new LabelsClient(baseUrl, restOptions),
|
||||
insuranceTypes: new InsuranceTypesClient(baseUrl, restOptions),
|
||||
estimates: new EstimatesClient(baseUrl, restOptions),
|
||||
quickRemarks: new QuickRemarksClient(baseUrl, restOptions),
|
||||
quickNotes: new QuickNotesClient(baseUrl, restOptions),
|
||||
shopRecommendations: new ShopRecommendationsClient(baseUrl, restOptions),
|
||||
jobCards: new JobCardsClient(baseUrl, restOptions),
|
||||
paymentModes: new PaymentModesClient(baseUrl, restOptions),
|
||||
paymentReceived: new PaymentReceivedClient(baseUrl, restOptions),
|
||||
parts: new PartsClient(baseUrl, restOptions),
|
||||
purchaseOrders: new PurchaseOrdersClient(baseUrl, restOptions),
|
||||
services: new ServicesClient(baseUrl, restOptions),
|
||||
serviceGroups: new ServiceGroupsClient(baseUrl, restOptions),
|
||||
expenses: new ExpensesClient(baseUrl, restOptions),
|
||||
tasks: new TasksClient(baseUrl, restOptions),
|
||||
taskTypes: new TaskTypesClient(baseUrl, restOptions),
|
||||
taskSections: new TaskSectionsClient(baseUrl, restOptions),
|
||||
appointments: new AppointmentsClient(baseUrl, restOptions),
|
||||
shopTimings: new ShopTimingsClient(baseUrl, restOptions),
|
||||
shopCalendars: new ShopCalendarsClient(baseUrl, restOptions),
|
||||
holidayYears: new HolidayYearsClient(baseUrl, restOptions),
|
||||
taxes: new TaxesClient(baseUrl, restOptions),
|
||||
invoices: new InvoicesClient(baseUrl, restOptions),
|
||||
home: new HomeClient(baseUrl, restOptions),
|
||||
bills: new BillsClient(baseUrl, restOptions),
|
||||
reasons: new ReasonsClient(baseUrl, restOptions),
|
||||
holidays: new HolidaysClient(baseUrl, restOptions),
|
||||
makeAndModels: new MakeAndModelsClient(baseUrl, restOptions),
|
||||
timeSheets: new TimeSheetsClient(baseUrl, restOptions),
|
||||
invoiceSequences: new InvoiceSequencesClient(baseUrl, restOptions),
|
||||
creditNotes: new CreditNotesClient(baseUrl, restOptions),
|
||||
paymentMades: new PaymentMadesClient(baseUrl, restOptions),
|
||||
vendorCredits: new VendorCreditsClient(baseUrl, restOptions),
|
||||
inventoryAdjustments: new InventoryAdjustmentsClient(baseUrl, restOptions),
|
||||
serviceGroupIncludes: new ServiceGroupIncludesClient(baseUrl, restOptions),
|
||||
serviceGroupPricings: new ServiceGroupPricingsClient(baseUrl, restOptions),
|
||||
serviceGroupServices: new ServiceGroupServicesClient(baseUrl, restOptions),
|
||||
serviceGroupParts: new ServiceGroupPartsClient(baseUrl, restOptions),
|
||||
settings: new SettingsClient(baseUrl, restOptions),
|
||||
configurations: new ConfigurationsClient(baseUrl, restOptions),
|
||||
autoGenerate: new AutoGenerateClient(baseUrl, restOptions),
|
||||
expenseItems: new ExpenseItemsClient(baseUrl, restOptions),
|
||||
inventoryCategories: new InventoryCategoriesClient(baseUrl, restOptions),
|
||||
documentPrint: new DocumentPrintClient(baseUrl, restOptions),
|
||||
documentShare: new DocumentShareClient(baseUrl, restOptions),
|
||||
}
|
||||
}
|
||||
|
||||
/** Unauthenticated singleton — use for public calls (login, register) */
|
||||
/** Unauthenticated singleton — use for public calls (login, register). */
|
||||
export const api = createApi()
|
||||
|
||||
Reference in New Issue
Block a user