MCPcopy Index your code
hub / github.com/simstudioai/sim / callConcur

Function callConcur

apps/sim/app/api/tools/sap_concur/proxy/route.ts:48–87  ·  view source on GitHub ↗
(
  req: ProxyRequest,
  accessToken: string,
  geolocation: string
)

Source from the content-addressed store, hash-verified

46}
47
48async function callConcur(
49 req: ProxyRequest,
50 accessToken: string,
51 geolocation: string
52): Promise<Invocation> {
53 const url = assertSafeExternalUrl(buildApiUrl(geolocation, req), 'apiUrl').toString()
54 const hasBody = req.body !== undefined && req.body !== null
55 const headers: Record<string, string> = {
56 Authorization: `Bearer ${accessToken}`,
57 Accept: 'application/json',
58 }
59 if (hasBody) headers['Content-Type'] = req.contentType ?? 'application/json'
60 if (req.companyUuid) headers['concur-correlationid'] = req.companyUuid
61
62 const response = await secureFetchWithValidation(
63 url,
64 {
65 method: req.method,
66 headers,
67 body: hasBody
68 ? typeof req.body === 'string'
69 ? req.body
70 : JSON.stringify(req.body)
71 : undefined,
72 timeout: SAP_CONCUR_OUTBOUND_FETCH_TIMEOUT_MS,
73 },
74 'apiUrl'
75 )
76
77 const raw = await response.text()
78 let parsed: unknown = null
79 if (raw.length > 0) {
80 try {
81 parsed = JSON.parse(raw)
82 } catch {
83 parsed = raw
84 }
85 }
86 return { status: response.status, body: parsed, raw }
87}
88
89export const POST = withRouteHandler(async (request: NextRequest) => {
90 const requestId = generateRequestId()

Callers 1

route.tsFile · 0.85

Calls 6

assertSafeExternalUrlFunction · 0.90
textMethod · 0.80
parseMethod · 0.80
buildApiUrlFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected