UNPKG

@directus-labs/liquidjs-operation

Version:

Render Liquid templates within Directus flows.

2 lines (1 loc) 5.36 kB
import{defineOperationApp as e}from"@directus/extensions-sdk";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n={},i={},o={};function a(e){const t=e.split("/"),n=t.indexOf("admin");return`${t.slice(0,n).join("/")}/`}Object.defineProperty(o,"__esModule",{value:!0}),o.getRootPath=function(){return a(window.location.pathname)},o.getPublicURL=function(){return a(window.location.href)},o.extract=a,Object.defineProperty(i,"__esModule",{value:!0}),i.getAssetUrl=function(e,t){const n=new URL(`assets/${e}`,(0,l.getPublicURL)());t&&n.searchParams.set("download","");return n.href};const l=o;var d,s,r;d=n,s=t&&t.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,o)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=t&&t.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||s(t,e,n)},Object.defineProperty(d,"__esModule",{value:!0}),r(i,d),r(o,d);var c=e({id:"liquidjs-operation",name:"Liquid Template",icon:"water_drop",description:"Render dynamic content using Liquid templates.",overview:({text:e})=>[{label:"Text",text:String(null!=e?e:"")}],options:e=>function(e){const t=n.getPublicURL(),{collection:i}=e;return[{field:"mode",name:"Template Mode",type:"string",meta:{width:"half",note:"Choose how to provide the Liquid template. Custom Template: write inline. Saved Template: use a template stored in a collection.",interface:"select-dropdown",options:{choices:[{text:"Custom Template",value:"custom"},{text:"Saved Template",value:"saved"}]}},schema:{default_value:"custom"}},{field:"operationMode",name:"Operation Mode",type:"string",meta:{width:"half",note:"Choose processing mode. Single: render one template with one data object. Batch: render the template multiple times, once for each item in an array of data objects.",interface:"select-dropdown",options:{choices:[{text:"Single",value:"single"},{text:"Batch",value:"batch"}]}},schema:{default_value:"single"}},{field:"publicUrl",name:"PublicUrl",type:"string",meta:{interface:"input",hidden:!0,readonly:!0},schema:{default_value:t}},{field:"template",name:"Template",type:"text",meta:{width:"full",interface:"input-code",note:"Enter your Liquid template here. Use {# #} for output tags instead of {{ }}. All other Liquid tags remain unchanged. Example: `Hello, {# user.name #}! {% if user.admin %}Admin area{% endif %}`",options:{language:"htmlmixed",template:"Hello, {# first_name #}! {% if is_admin %}Welcome to the Admin.{% endif %}",placeholder:"Hello, {# first_name #}! {% if is_admin %}Welcome to the Admin.{% endif %}"},hidden:!0,conditions:[{hidden:!1,rule:{mode:{_eq:"custom"}}}]},schema:{default_value:""}},{field:"collection",name:"Collection",type:"string",meta:{width:"half",note:"Select the collection containing your saved Liquid templates.",interface:"system-collection",hidden:!0,conditions:[{hidden:!1,rule:{mode:{_eq:"saved"}}}]},schema:{default_value:null}},{field:"item",name:"Item",type:"string",meta:{width:"half",note:"Choose the specific template to render from the selected collection.",interface:"collection-item-dropdown",options:{selectedCollection:i||null,valueField:"id"},hidden:!0,conditions:[{hidden:!1,rule:{_and:[{mode:{_eq:"saved"}},{collection:{_nempty:!0}},{collection:{_nnull:!0}}]}}]},schema:{default_value:null}},{field:"fields",name:"Fields",type:"json",meta:{width:"half",note:"Choose fields to process and render. Only selected fields appear in output. Ideal for email scenarios with dynamic subject and body.",interface:"system-field-tree",options:{collectionField:"collection"},hidden:!0,conditions:[{hidden:!1,rule:{_and:[{mode:{_eq:"saved"}},{collection:{_nempty:!0}},{collection:{_nnull:!0}}]}}]},schema:{default_value:[]}},{field:"accessToken",name:"Access Token",type:"string",meta:{width:"half",interface:"input",note:"Required for accessing private template collections in `Saved Template` mode. Alternatively, make your template collection public. Ensure the token has read permissions for the template collection.",options:{masked:!0},hidden:!0,conditions:[{hidden:!1,rule:{mode:{_eq:"saved"}}}]},schema:{default_value:null}},{field:"data",name:"Data",type:"json",meta:{width:"full",note:'JSON data to populate the template. Format: object for single mode, array of objects for batch mode. Supports mustache syntax for dynamic values, e.g., {"user": "{{$trigger.user}}"}.',interface:"input-code",options:{language:"json",template:'{"first_name":"John","last_name":"Doe","is_admin":true}',placeholder:'{"first_name":"John","last_name":"Doe","is_admin":true}'}},schema:{default_value:{}}},{field:"dataReturnFields",name:"Return Fields from Data",type:"json",meta:{width:"full",interface:"tags",note:'Specify fields from your input data to include in each output object. Useful for maintaining context or identification (e.g., "id", "name"). These fields will be added alongside the output for each item in batch mode.',options:{placeholder:"Add a field key and press Enter..."},hidden:!0,conditions:[{hidden:!1,rule:{operationMode:{_eq:"batch"}}}]},schema:{default_value:[]}}]}(e)});export{c as default};