{ "kind": "open-flow-workflow", "version": 1, "name": "Create a Short URL and Read Its Statistics", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_5dc0b9b88e9d2ebc": { "name": "Enter link details", "kind": "start", "inputDefs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "instanceUrl" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "title" } ] }, "n_77577b036af16319": { "inputs": { "instanceUrl": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_5dc0b9b88e9d2ebc", "output": "instanceUrl" } ] }, "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_5dc0b9b88e9d2ebc", "output": "url" } ] }, "title": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_5dc0b9b88e9d2ebc", "output": "title" } ] } }, "name": "Prepare the request", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "instanceUrl" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "title" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "endpoint" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" } ], "name": "Prepare the request", "moduleId": "n_6a1400589c8b7249", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_4e3da20b7c9c13c2": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_77577b036af16319", "output": "url" } ] }, "auth.token": { "kind": "unset" } }, "name": "Create short URL", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Create short URL", "executor": { "method": "GET", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "none", "authentication": { "type": "apiKey", "name": "signature", "in": "query" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_60c3e529600dbe21": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_4e3da20b7c9c13c2", "output": "body" } ] }, "endpoint": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_77577b036af16319", "output": "endpoint" } ] } }, "name": "Prepare statistics request", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "endpoint" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" } ], "name": "Prepare statistics request", "moduleId": "n_de0a7727a87c6403", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_6459fa2c9daadf5d": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_60c3e529600dbe21", "output": "url" } ] }, "auth.token": { "kind": "unset" } }, "name": "Read link statistics", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Read link statistics", "executor": { "method": "GET", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "none", "authentication": { "type": "apiKey", "name": "signature", "in": "query" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_d0cc958d71578e72": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_6459fa2c9daadf5d", "output": "body" } ] } }, "name": "Return link statistics", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "link" } ], "name": "Return link statistics", "moduleId": "n_ec7e9c0829fff8ce", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_a874e0815029c189": { "name": "Link statistics", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "link" } ], "outputMappings": { "link": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d0cc958d71578e72", "output": "link" } ] } } } }, "edges": [ { "source": "n_5dc0b9b88e9d2ebc", "target": "n_77577b036af16319" }, { "source": "n_77577b036af16319", "target": "n_4e3da20b7c9c13c2" }, { "source": "n_4e3da20b7c9c13c2", "target": "n_60c3e529600dbe21" }, { "source": "n_60c3e529600dbe21", "target": "n_6459fa2c9daadf5d" }, { "source": "n_6459fa2c9daadf5d", "target": "n_d0cc958d71578e72" }, { "source": "n_d0cc958d71578e72", "target": "n_a874e0815029c189" } ] } }, "modules": { "n_6a1400589c8b7249": { "name": "Prepare the request", "imports": [], "source": "export default function setup({instanceUrl,url,title}){let instance,target;try{instance=new URL(instanceUrl);target=new URL(url)}catch{throw Error('Enter valid instance and target URLs')}if(instance.protocol!=='https:'||instance.username||instance.password||instance.search||instance.hash||!['http:','https:'].includes(target.protocol)||target.username||target.password)throw Error('Use an HTTPS instance URL and an HTTP(S) target URL');if(typeof title!=='string'||!title.trim())throw Error('Enter a title');const endpoint=instance.toString().replace(/\\/+$/,'')+'/yourls-api.php',q=new URLSearchParams({action:'shorturl',format:'json',url:target.toString(),title:title.trim()});return{endpoint,url:endpoint+'?'+q.toString()};}\n" }, "n_de0a7727a87c6403": { "name": "Prepare statistics request", "imports": [], "source": "export default function created({body,endpoint}){if(!body||body.status==='fail'||typeof body.shorturl!=='string')throw Error('YOURLS did not return a short URL');let u;try{u=new URL(body.shorturl)}catch{throw Error('YOURLS returned an invalid short URL')}if(!['https:','http:'].includes(u.protocol))throw Error('YOURLS returned an invalid short URL');const q=new URLSearchParams({action:'url-stats',format:'json',shorturl:body.shorturl});return{url:endpoint+'?'+q.toString()};}\n" }, "n_ec7e9c0829fff8ce": { "name": "Return link statistics", "imports": [], "source": "export default function stats({body}){if(!body||body.status==='fail'||!body.link||typeof body.link!=='object'||Array.isArray(body.link))throw Error('YOURLS did not return link statistics');return {link:body.link};}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }