Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,29 @@ export function createClient(config: {
token?: string;
serviceToken?: string;
requiresAuth?: boolean;
functionsVersion?: string;
}) {
const {
serverUrl = "https://base44.app",
appId,
token,
serviceToken,
requiresAuth = false,
functionsVersion
} = config;

const headers = {
"X-App-Id": String(appId),
}

const functionHeaders = functionsVersion ? {
...headers,
"Base44-Functions-Version": functionsVersion
} : headers;

const axiosClient = createAxiosClient({
baseURL: `${serverUrl}/api`,
headers: {
"X-App-Id": String(appId),
},
headers,
token,
requiresAuth,
appId,
Expand All @@ -44,9 +53,7 @@ export function createClient(config: {

const functionsAxiosClient = createAxiosClient({
baseURL: `${serverUrl}/api`,
headers: {
"X-App-Id": String(appId),
},
headers: functionHeaders,
token,
requiresAuth,
appId,
Expand All @@ -56,19 +63,15 @@ export function createClient(config: {

const serviceRoleAxiosClient = createAxiosClient({
baseURL: `${serverUrl}/api`,
headers: {
"X-App-Id": String(appId),
},
headers,
token: serviceToken,
serverUrl,
appId,
});

const serviceRoleFunctionsAxiosClient = createAxiosClient({
baseURL: `${serverUrl}/api`,
headers: {
"X-App-Id": String(appId),
},
headers: functionHeaders,
token: serviceToken,
serverUrl,
appId,
Expand Down Expand Up @@ -160,6 +163,7 @@ export function createClientFromRequest(request: Request) {
);
const appId = request.headers.get("Base44-App-Id");
const serverUrlHeader = request.headers.get("Base44-Api-Url");
const functionsVersion = request.headers.get("Base44-Functions-Version");

if (!appId) {
throw new Error(
Expand Down Expand Up @@ -190,5 +194,6 @@ export function createClientFromRequest(request: Request) {
appId,
token: userToken,
serviceToken: serviceRoleToken,
functionsVersion: functionsVersion ?? undefined
});
}