MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / reformatActionData

Function reformatActionData

pages/api/v1/confirm.ts:399–443  ·  view source on GitHub ↗
(
  data: Action & { apis: Api & { fixed_headers: HeaderRow[] } },
  params: Record<string, any>,
  requestData: ConfirmType,
  mockUrl: string,
)

Source from the content-addressed store, hash-verified

397}
398
399function reformatActionData(
400 data: Action & { apis: Api & { fixed_headers: HeaderRow[] } },
401 params: Record<string, any>,
402 requestData: ConfirmType,
403 mockUrl: string,
404) {
405 const api = data.apis;
406
407 if (requestData.api_params) {
408 // Check if any api_params names matches the api name
409 const matchedApiParams = requestData.api_params.find(
410 (apiParams) => api.name === apiParams.name,
411 );
412
413 // Override values in apis if api_params are set in request body
414 if (matchedApiParams) {
415 api.api_host = matchedApiParams.hostname || api.api_host;
416 if (matchedApiParams.headers) {
417 // Concat api_params headers onto fixed_headers
418 api.fixed_headers = api.fixed_headers.concat(
419 Object.entries(matchedApiParams.headers).map(
420 ([k, v]): HeaderRow => ({
421 name: k,
422 created_at: "",
423 value: v,
424 id: "",
425 api_id: api.id,
426 }),
427 ),
428 );
429 }
430 }
431 }
432 return {
433 action: {
434 ...data,
435 api: {
436 ...api,
437 api_host: requestData.mock_api_responses ? mockUrl : api.api_host,
438 },
439 headers: api.fixed_headers,
440 },
441 params,
442 };
443}

Callers 1

handlerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected