From 1dfc2ee602211bb9a97c14c852f60d626a2c52d9 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 3 Nov 2025 06:07:34 -0800 Subject: [PATCH] Support encoding values to base64 (url safe) --- plugins/template-function-encode/src/index.ts | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/plugins/template-function-encode/src/index.ts b/plugins/template-function-encode/src/index.ts index 0a9f8d3d..6a38669d 100644 --- a/plugins/template-function-encode/src/index.ts +++ b/plugins/template-function-encode/src/index.ts @@ -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 { - return Buffer.from(String(args.values.value ?? '')).toString('base64'); + return Buffer.from(String(args.values.value ?? '')).toString( + args.values.encoding === 'base64url' ? 'base64url' : 'base64', + ); }, }, {