{ "kind": "open-flow-workflow", "version": 1, "name": "Create and Enroll a Tapfiliate Affiliate", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_a79fe0a342007e88": { "name": "Enter affiliate details", "kind": "start", "inputDefs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "firstname" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "lastname" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "email" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "programId" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "tag" } ] }, "n_0d41e343ef12b88c": { "inputs": { "firstname": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_a79fe0a342007e88", "output": "firstname" } ] }, "lastname": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_a79fe0a342007e88", "output": "lastname" } ] }, "email": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_a79fe0a342007e88", "output": "email" } ] }, "programId": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_a79fe0a342007e88", "output": "programId" } ] }, "tag": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_a79fe0a342007e88", "output": "tag" } ] } }, "name": "Validate affiliate details", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "firstname" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "lastname" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "email" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "programId" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "tag" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "firstname" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "lastname" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "email" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "programId" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "tag" } ], "name": "Validate affiliate details", "moduleId": "n_748c7df46a282b1c", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_4cf95335c3f91ebd": { "inputs": { "firstname": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0d41e343ef12b88c", "output": "firstname" } ] }, "lastname": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0d41e343ef12b88c", "output": "lastname" } ] }, "email": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0d41e343ef12b88c", "output": "email" } ] } }, "name": "Create affiliate", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "firstname" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "lastname" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "email" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "id" } ], "name": "Create affiliate", "moduleId": "n_fec12ce00a34f5d8", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [ { "action": "tapfiliate.create_affiliate" } ] } ] } }, "n_693764adeb3a6e59": { "inputs": { "id": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_4cf95335c3f91ebd", "output": "id" } ] }, "tag": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0d41e343ef12b88c", "output": "tag" } ] } }, "name": "Prepare tag", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "id" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "tag" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "endpoint" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "body" } ], "name": "Prepare tag", "moduleId": "n_d9f6c742324f879f", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_d523c6a5b334b16b": { "inputs": { "endpoint": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_693764adeb3a6e59", "output": "endpoint" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_693764adeb3a6e59", "output": "body" } ] } }, "name": "Set affiliate tag", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "endpoint" }, { "jsonSchema": {}, "nullable": true, "handle": "body" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" }, { "jsonSchema": { "const": "base64" }, "nullable": true, "handle": "bodyEncoding" } ], "name": "Set affiliate tag", "executor": { "providerId": "tapfiliate", "method": "PUT", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "json", "kind": "connector-proxy" } } }, "n_50a191851c579aff": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d523c6a5b334b16b", "output": "body" } ] }, "statusCode": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d523c6a5b334b16b", "output": "statusCode" } ] }, "bodyEncoding": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d523c6a5b334b16b", "output": "bodyEncoding" } ] }, "id": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_4cf95335c3f91ebd", "output": "id" } ] }, "programId": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0d41e343ef12b88c", "output": "programId" } ] }, "tag": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0d41e343ef12b88c", "output": "tag" } ] } }, "name": "Prepare program enrollment", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "const": "base64" }, "nullable": true, "handle": "bodyEncoding" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "id" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "programId" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "tag" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "endpoint" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "body" } ], "name": "Prepare program enrollment", "moduleId": "n_4e5fc8affb20280b", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_1fbac558086ae4d1": { "inputs": { "endpoint": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_50a191851c579aff", "output": "endpoint" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_50a191851c579aff", "output": "body" } ] } }, "name": "Add to program", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "endpoint" }, { "jsonSchema": {}, "nullable": true, "handle": "body" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" }, { "jsonSchema": { "const": "base64" }, "nullable": true, "handle": "bodyEncoding" } ], "name": "Add to program", "executor": { "providerId": "tapfiliate", "method": "POST", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "json", "kind": "connector-proxy" } } }, "n_80ed29cdf95ea7e0": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1fbac558086ae4d1", "output": "body" } ] }, "statusCode": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1fbac558086ae4d1", "output": "statusCode" } ] }, "bodyEncoding": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1fbac558086ae4d1", "output": "bodyEncoding" } ] }, "id": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_4cf95335c3f91ebd", "output": "id" } ] } }, "name": "Confirm enrollment", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "const": "base64" }, "nullable": true, "handle": "bodyEncoding" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "id" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "affiliate" } ], "name": "Confirm enrollment", "moduleId": "n_58b6f76b63cf1ba0", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_3736b8fa602f854d": { "name": "Program affiliate", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "affiliate" } ], "outputMappings": { "affiliate": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_80ed29cdf95ea7e0", "output": "affiliate" } ] } } } }, "edges": [ { "source": "n_a79fe0a342007e88", "target": "n_0d41e343ef12b88c" }, { "source": "n_0d41e343ef12b88c", "target": "n_4cf95335c3f91ebd" }, { "source": "n_4cf95335c3f91ebd", "target": "n_693764adeb3a6e59" }, { "source": "n_693764adeb3a6e59", "target": "n_d523c6a5b334b16b" }, { "source": "n_d523c6a5b334b16b", "target": "n_50a191851c579aff" }, { "source": "n_50a191851c579aff", "target": "n_1fbac558086ae4d1" }, { "source": "n_1fbac558086ae4d1", "target": "n_80ed29cdf95ea7e0" }, { "source": "n_80ed29cdf95ea7e0", "target": "n_3736b8fa602f854d" } ] } }, "modules": { "n_748c7df46a282b1c": { "name": "Validate affiliate details", "imports": [], "source": "export default function setup({firstname,lastname,email,programId,tag}){if([firstname,lastname,programId,tag].some(x=>typeof x!=='string'||!x.trim())||typeof email!=='string'||!/^\\S+@\\S+\\.\\S+$/.test(email.trim())||! /^[A-Za-z0-9_-]+$/.test(programId))throw Error('Enter affiliate details, program ID and tag');return{firstname:firstname.trim(),lastname:lastname.trim(),email:email.trim(),programId,tag:tag.trim()};}\n" }, "n_fec12ce00a34f5d8": { "name": "Create affiliate", "imports": [], "source": "export default async function create({firstname,lastname,email},context){const r=await context.actions.call('tapfiliate.create_affiliate',{firstname,lastname,email});const id=r?.affiliate?.id;if(typeof id!=='string'||! /^[A-Za-z0-9_-]+$/.test(id))throw Error('Tapfiliate did not return an affiliate ID');return{id};}\n" }, "n_d9f6c742324f879f": { "name": "Prepare tag", "imports": [], "source": "export default function meta({id,tag}){return{endpoint:'/affiliates/'+encodeURIComponent(id)+'/meta-data/tag/',body:{value:tag}};}\n" }, "n_4e5fc8affb20280b": { "name": "Prepare program enrollment", "imports": [], "source": "export default function enroll({body,statusCode,bodyEncoding,id,programId,tag}){if(statusCode!==200||bodyEncoding!=null||body?.value!==tag)throw Error('Tapfiliate did not confirm metadata');return{endpoint:'/programs/'+encodeURIComponent(programId)+'/affiliates/',body:{affiliate:{id}}};}\n" }, "n_58b6f76b63cf1ba0": { "name": "Confirm enrollment", "imports": [], "source": "export default function result({body,statusCode,bodyEncoding,id}){if(![200,201].includes(statusCode)||bodyEncoding!=null||!body||body.id!==id)throw Error('Tapfiliate did not confirm the same affiliate');return{affiliate:{id:body.id,approved:body.approved??null,referralLink:body.referral_link?.link??null}};}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }