1
0
Fork 0
mirror of synced 2024-10-03 10:36:59 +13:00
budibase/packages/worker/src/utilities/appService.ts
Rory Powell e5e767f18d Correlation id's and log context (#7232)
* Correlation id's and log context

* fix build

* Remove redundant fields from LoggingProcessor.ts

* Only log correlation id when present e.g. this is not present on startup / shutdown / automations
2023-01-11 20:39:33 +00:00

36 lines
1 KiB
TypeScript

import fetch from "node-fetch"
import { constants, tenancy, logging } from "@budibase/backend-core"
import { checkSlashesInUrl } from "../utilities"
import env from "../environment"
async function makeAppRequest(url: string, method: string, body: any) {
if (env.isTest()) {
return
}
const request: any = { headers: {} }
request.headers[constants.Header.API_KEY] = env.INTERNAL_API_KEY
if (tenancy.isTenantIdSet()) {
request.headers[constants.Header.TENANT_ID] = tenancy.getTenantId()
}
if (body) {
request.headers["Content-Type"] = "application/json"
request.body = JSON.stringify(body)
}
request.method = method
// add x-budibase-correlation-id header
logging.correlation.setHeader(request.headers)
return fetch(checkSlashesInUrl(env.APPS_URL + url), request)
}
export async function syncUserInApps(userId: string) {
const response = await makeAppRequest(
`/api/users/metadata/sync/${userId}`,
"POST",
{}
)
if (response && response.status !== 200) {
throw "Unable to sync user."
}
}