feat(http-request): add headers support
This commit is contained in:
@@ -2,6 +2,13 @@ import defineAction from '../../../../helpers/define-action';
|
||||
|
||||
type TMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
||||
|
||||
type THeaderEntry = {
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
type THeaderEntries = THeaderEntry[];
|
||||
|
||||
export default defineAction({
|
||||
name: 'Custom Request',
|
||||
key: 'customRequest',
|
||||
@@ -38,15 +45,47 @@ export default defineAction({
|
||||
description: 'Place raw JSON data here.',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Headers',
|
||||
key: 'headers',
|
||||
type: 'dynamic' as const,
|
||||
required: false,
|
||||
description: 'Add or remove headers as needed',
|
||||
value: [{
|
||||
key: 'Content-Type',
|
||||
value: 'application/json'
|
||||
}],
|
||||
fields: [
|
||||
{
|
||||
label: 'Key',
|
||||
key: 'key',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
description: 'Header key',
|
||||
variables: false,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
key: 'value',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
description: 'Header value',
|
||||
variables: true,
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const method = $.step.parameters.method as TMethod;
|
||||
const data = $.step.parameters.data as string;
|
||||
const url = $.step.parameters.url as string;
|
||||
const headers = $.step.parameters.headers as THeaderEntries;
|
||||
const maxFileSize = 25 * 1024 * 1024; // 25MB
|
||||
|
||||
const metadataResponse = await $.http.head(url);
|
||||
const headersObject = headers.reduce((result, entry) => ({ ...result, [entry.key]: entry.value }), {})
|
||||
|
||||
const metadataResponse = await $.http.head(url, { headers: headersObject });
|
||||
|
||||
if (Number(metadataResponse.headers['content-length']) > maxFileSize) {
|
||||
throw new Error(
|
||||
@@ -58,9 +97,7 @@ export default defineAction({
|
||||
url,
|
||||
method,
|
||||
data,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers: headersObject,
|
||||
});
|
||||
|
||||
let responseData = response.data;
|
||||
|
@@ -9,7 +9,7 @@ const appInfoConverter = (rawAppData: IApp) => {
|
||||
|
||||
if (rawAppData.auth?.fields) {
|
||||
rawAppData.auth.fields = rawAppData.auth.fields.map((field) => {
|
||||
if (typeof field.value === 'string') {
|
||||
if (field.type === 'string' && typeof field.value === 'string') {
|
||||
return {
|
||||
...field,
|
||||
value: field.value.replace('{WEB_APP_URL}', appConfig.webAppUrl),
|
||||
|
@@ -47,6 +47,7 @@ export default function createHttpClient({
|
||||
if (
|
||||
// TODO: provide a `shouldRefreshToken` function in the app
|
||||
(status === 401 || status === 403) &&
|
||||
$.app.auth &&
|
||||
$.app.auth.refreshToken &&
|
||||
!$.app.auth.isRefreshTokenRequested
|
||||
) {
|
||||
|
Reference in New Issue
Block a user