Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { status, statusText, headers: responseHeaders } = error.response;
const message = `[${status}] ${statusText}`;
log(`warn`, `error on ${id} webhook event: ${message}`);
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
// special handling for 5xx
if (status >= 500) {
return retryResult(id, message);
}
// special handling for rate limiting
if (status === 429) {
return pipe(
getRetryAfterIntervalFromHeaders(responseHeaders),
map(retry => retryResultSeconds(id, message, retry)),
getOrElse(() => retryResult(id, message))
);
}
return errorResultInvalid(id, message);
}
const message = i18n.translate('xpack.actions.builtin.webhook.unreachableRemoteWebhook', {
defaultMessage: 'Unreachable Remote Webhook, are you sure the address is correct?',
});
log(`warn`, `error on ${id} webhook action: ${message}`);
return errorResultUnreachable(id, message);
}
}
return pipe(reader, R.map(ask => {
const transportLayer = provideTransportLayer(transport, options);
const connection = transportLayer.connect({ isConsumer: false });
pipe(
ask(ServerEventStreamToken),
O.map(teardownOnClose$(connection)),
O.getOrElse(() => EMPTY as Observable),
).subscribe();
return {
emit: emit(connection),
send: send(connection),
close: close(connection),
} as MessagingClient;
}));
};
const getLastPathStep = (path: string) =>
pipe(
path.split("."),
last,
O.getOrElse(() => "")
);
export const getOperationParametersInBody = (operation: OperationObject): BodyParameterObject[] =>
pipe(
operation.parameters,
map(parameters => parameters.filter(isOperationBodyParameterObject)),
getOrElse(constant([])),
);
O.mapNullable(request => request.body),
O.mapNullable(body => body.contents),
O.getOrElse(() => [] as IMediaTypeContent[])
);
const encodedUriParams = splitUriParams(request.body as string);
if (specs.length < 1) {
return Object.assign(request, { body: encodedUriParams });
}
const content = pipe(
O.fromNullable(mediaType),
O.chain(mediaType => findContentByMediaTypeOrFirst(specs, mediaType)),
O.map(({ content }) => content),
O.getOrElse(() => specs[0] || {})
);
const encodings = get(content, 'encodings', []);
if (!content.schema) return Object.assign(request, { body: encodedUriParams });
return Object.assign(request, {
body: deserializeFormBody(content.schema, encodings, decodeUriEntities(encodedUriParams)),
});
}
export function togglePeriodType(periodType: Option): Option {
const periodTypeNormalized = getOrElse(() => PeriodType.AM)(periodType);
switch (periodTypeNormalized) {
case PeriodType.AM:
return some(PeriodType.PM);
case PeriodType.PM:
return some(PeriodType.AM);
}
}
d.parameterDeclarations.map(p =>
pipe(
p.constraint,
O.map(c => getTypeNode(c)),
O.getOrElse(() => ts.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword))
)
)
const serializeBodyParameterObject = (
parameter: BodyParameterObject,
rootName: string,
cwd: string,
): Either => {
const isRequired = pipe(
parameter.required,
getOrElse(constFalse),
);
return pipe(
serializeSchemaObject(parameter.schema, rootName, cwd),
either.map(serializedParameterType =>
serializedParameter(
serializedParameterType.type,
serializedParameterType.io,
isRequired,
serializedParameterType.dependencies,
serializedParameterType.refs,
),
),
);
};
R.map(functionDeclaration =>
pipe(
functionDeclaration,
O.map(ast),
O.getOrElse(() => '')
)
)
export function encaseOption(o: Option<a>, onError: Lazy): Wave {
return pipe(o,
option.map>(pure),
option.getOrElse>(() => raiseError(onError())));
}
</a>