Show toast on plugin event handling errors instead of crashing

Also set folder context on template render and fix timestamp function
This commit is contained in:
Gregory Schier
2025-10-06 06:53:45 -07:00
parent dbc606fb53
commit 485a9ea47c
18 changed files with 203 additions and 130 deletions

View File

@@ -271,6 +271,12 @@ export const plugin: PluginDefinition = {
label: 'Advanced',
inputs: [
{ type: 'text', name: 'scope', label: 'Scope', optional: true },
{
type: 'text',
name: 'headerName',
label: 'Header Name',
defaultValue: 'Authorization',
},
{
type: 'text',
name: 'headerPrefix',
@@ -397,15 +403,9 @@ export const plugin: PluginDefinition = {
throw new Error('Invalid grant type ' + grantType);
}
const headerName = stringArg(values, 'headerName') || 'Authorization';
const headerValue = `${headerPrefix} ${token.response[tokenName]}`.trim();
return {
setHeaders: [
{
name: 'Authorization',
value: headerValue,
},
],
};
return { setHeaders: [{ name: headerName, value: headerValue }] };
},
},
};

View File

@@ -1,5 +1,6 @@
import type { HttpUrlParameter } from '@yaakapp-internal/models';
import type { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
import { resolvedModelName } from '@yaakapp/app/lib/resolvedModelName';
export const plugin: PluginDefinition = {
templateFunctions: [
@@ -96,5 +97,22 @@ export const plugin: PluginDefinition = {
return renderedValue;
},
},
{
name: 'request.name',
args: [
{
name: 'requestId',
label: 'Http Request',
type: 'http_request',
},
],
async onRender(ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
const requestId = String(args.values.requestId ?? 'n/a');
const httpRequest = await ctx.httpRequest.getById({ id: requestId });
if (httpRequest == null) return null;
return resolvedModelName(httpRequest);
},
},
],
};

View File

@@ -155,7 +155,7 @@ export function formatDatetime(args: {
format?: string;
in?: ContextFn<Date>;
}): string {
const { date, format = 'yyyy-MM-dd HH:mm:ss' } = args;
const { date, format } = args;
const d = parseDateString(date ?? '');
return formatDate(d, String(format), { in: args.in });
return formatDate(d, String(format || 'yyyy-MM-dd HH:mm:ss'), { in: args.in });
}