Support encoding values to base64 (url safe)

This commit is contained in:
Gregory Schier
2025-11-03 06:07:34 -08:00
parent 1d158082f6
commit 1dfc2ee602

View File

@@ -5,9 +5,29 @@ export const plugin: PluginDefinition = {
{
name: 'base64.encode',
description: 'Encode a value to base64',
args: [{ label: 'Plain Text', type: 'text', name: 'value', multiLine: true }],
args: [
{
label: 'Encoding',
type: 'select',
name: 'encoding',
defaultValue: 'base64',
options: [
{
label: 'Base64',
value: 'base64',
},
{
label: 'Base64 URL-safe',
value: 'base64url',
},
],
},
{ label: 'Plain Text', type: 'text', name: 'value', multiLine: true },
],
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
return Buffer.from(String(args.values.value ?? '')).toString('base64');
return Buffer.from(String(args.values.value ?? '')).toString(
args.values.encoding === 'base64url' ? 'base64url' : 'base64',
);
},
},
{