{ "kind": "open-flow-workflow", "version": 1, "name": "Share New Drive Files and Log to Airtable", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_79f4db2d5645785a": { "name": "Watch for new Drive files", "kind": "poll", "config": { "changeType": { "kind": "value", "value": "created" }, "folderId": { "kind": "value", "value": "YOUR_FOLDER_ID" }, "driveId": { "kind": "value", "value": "" }, "itemTypes": { "kind": "value", "value": [ "file" ] }, "mimeTypes": { "kind": "value", "value": [] }, "namePrefix": { "kind": "value", "value": "" }, "maxFilesPerPoll": { "kind": "value", "value": 50 } }, "definition": { "configInputs": [ { "jsonSchema": { "type": "string", "enum": [ "created", "updated" ] }, "nullable": false, "handle": "changeType" }, { "jsonSchema": { "type": "string", "pattern": "^[A-Za-z0-9_-]{0,512}$" }, "nullable": false, "handle": "driveId", "value": "" }, { "jsonSchema": { "type": "string", "pattern": "^[A-Za-z0-9_-]{2,512}$" }, "nullable": false, "handle": "folderId" }, { "jsonSchema": { "type": "array", "items": { "type": "string", "enum": [ "file", "folder" ] }, "minItems": 1, "uniqueItems": true }, "nullable": false, "handle": "itemTypes", "value": [ "file" ] }, { "jsonSchema": { "type": "array", "items": { "type": "string", "minLength": 1 } }, "nullable": false, "handle": "mimeTypes", "value": [] }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "namePrefix", "value": "" }, { "collapsed": true, "group": "Advanced settings" }, { "jsonSchema": { "type": "integer", "minimum": 1, "maximum": 200 }, "nullable": false, "handle": "maxFilesPerPoll", "value": 50 } ], "definitionVersion": 2, "description": "Polls one Google Drive folder and triggers when a file or folder directly inside it is created or updated.", "displayName": "File or Folder Change in a Folder", "key": "googledrive.on_file_change", "name": "on_file_change", "outputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "createdTime": { "type": [ "string", "null" ] }, "driveId": { "type": [ "string", "null" ] }, "eventType": { "type": "string", "enum": [ "file_created", "file_updated", "folder_created", "folder_updated" ] }, "fileId": { "type": "string" }, "itemType": { "type": "string", "enum": [ "file", "folder" ] }, "lastModifyingUser": { "type": [ "object", "null" ] }, "mimeType": { "type": "string" }, "modifiedTime": { "type": [ "string", "null" ] }, "name": { "type": "string" }, "parents": { "type": "array", "items": { "type": "string" } }, "size": { "type": "string" }, "webViewLink": { "type": [ "string", "null" ] } }, "additionalProperties": false, "required": [ "eventType", "itemType", "fileId", "name", "mimeType", "createdTime", "modifiedTime", "parents", "webViewLink", "driveId", "lastModifyingUser" ] } }, "nullable": false, "handle": "events" } ], "provider": "googledrive", "type": "poll" }, "pollTimes": [ { "type": "every", "unit": "minute", "value": 1 } ] }, "n_176f8d0b5f919bff": { "inputs": { "events": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_79f4db2d5645785a", "output": "events" } ] }, "email": { "kind": "value", "value": "YOUR_RECIPIENT_EMAIL" }, "baseId": { "kind": "value", "value": "YOUR_BASE_ID" }, "table": { "kind": "value", "value": "YOUR_TABLE_NAME" } }, "name": "Validate files", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "createdTime": { "type": [ "string", "null" ] }, "driveId": { "type": [ "string", "null" ] }, "eventType": { "type": "string", "enum": [ "file_created", "file_updated", "folder_created", "folder_updated" ] }, "fileId": { "type": "string" }, "itemType": { "type": "string", "enum": [ "file", "folder" ] }, "lastModifyingUser": { "type": [ "object", "null" ] }, "mimeType": { "type": "string" }, "modifiedTime": { "type": [ "string", "null" ] }, "name": { "type": "string" }, "parents": { "type": "array", "items": { "type": "string" } }, "size": { "type": "string" }, "webViewLink": { "type": [ "string", "null" ] } }, "additionalProperties": false, "required": [ "eventType", "itemType", "fileId", "name", "mimeType", "createdTime", "modifiedTime", "parents", "webViewLink", "driveId", "lastModifyingUser" ] } }, "nullable": false, "handle": "events" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "email" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "baseId" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "table" } ], "outputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "additionalProperties": true } }, "nullable": false, "handle": "files" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "email" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "baseId" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "table" } ], "name": "Validate files", "moduleId": "n_b5c0c6c41a3a811c", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_d0f70a55800b4b56": { "inputs": { "files": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_176f8d0b5f919bff", "output": "files" } ] }, "email": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_176f8d0b5f919bff", "output": "email" } ] }, "previousState": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_4c086baea76764a0", "output": "state" } ] } }, "name": "Prepare next permission", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "additionalProperties": true } }, "nullable": false, "handle": "files" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "email" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "previousState" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "more" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "fileId" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "email" }, { "jsonSchema": { "type": "array", "items": { "type": "string" } }, "nullable": false, "handle": "permissions" } ], "name": "Prepare next permission", "moduleId": "n_d2dbf88c069398c7", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_8b3f7a71dd438a51": { "inputs": {}, "name": "More files to share?", "kind": "condition", "matchMode": "first", "cases": [ { "output": "more", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_d0f70a55800b4b56", "output": "more" } }, "operator": "isTrue" } ] } ] } ] }, "n_363372d39dbea05f": { "inputs": { "fileId": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d0f70a55800b4b56", "output": "fileId" } ] }, "email": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d0f70a55800b4b56", "output": "email" } ] } }, "name": "Grant edit access", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "fileId" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "email" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "permissionId" } ], "name": "Grant edit access", "moduleId": "n_6d78a832df67824b", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [ { "action": "googledrive.permissions.create" } ] } ] } }, "n_4c086baea76764a0": { "inputs": { "state": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d0f70a55800b4b56", "output": "state" } ] }, "permissionId": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_363372d39dbea05f", "output": "permissionId" } ] } }, "name": "Remember permission", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "permissionId" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" } ], "name": "Remember permission", "moduleId": "n_1803f7d2e749e208", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_67917f2e0f35b4be": { "inputs": { "files": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_176f8d0b5f919bff", "output": "files" } ] }, "permissions": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d0f70a55800b4b56", "output": "permissions" } ] }, "baseId": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_176f8d0b5f919bff", "output": "baseId" } ] }, "table": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_176f8d0b5f919bff", "output": "table" } ] }, "previousState": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_9fce65da95d8d6e9", "output": "state" } ] } }, "name": "Prepare next Airtable record", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "additionalProperties": true } }, "nullable": false, "handle": "files" }, { "jsonSchema": { "type": "array", "items": { "type": "string" } }, "nullable": false, "handle": "permissions" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "baseId" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "table" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "previousState" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "more" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "baseId" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "table" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "fields" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "count" } ], "name": "Prepare next Airtable record", "moduleId": "n_ae941c28efce20b1", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_2566e5e11158752e": { "inputs": {}, "name": "More records to log?", "kind": "condition", "matchMode": "first", "cases": [ { "output": "more", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_67917f2e0f35b4be", "output": "more" } }, "operator": "isTrue" } ] } ] } ] }, "n_7a955d5d4c87b3ca": { "inputs": { "baseId": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_67917f2e0f35b4be", "output": "baseId" } ] }, "table": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_67917f2e0f35b4be", "output": "table" } ] }, "fields": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_67917f2e0f35b4be", "output": "fields" } ] } }, "name": "Log file metadata", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "baseId" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "table" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "fields" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "id" } ], "name": "Log file metadata", "moduleId": "n_413694b436308b90", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [ { "action": "airtable.create_records" } ] } ] } }, "n_9fce65da95d8d6e9": { "inputs": { "state": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_67917f2e0f35b4be", "output": "state" } ] } }, "name": "Advance to next record", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" } ], "name": "Advance to next record", "moduleId": "n_a316fb47d0157db4", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_8b56d92f09cdcfb5": { "name": "Logged file count", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "count" } ], "outputMappings": { "count": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_67917f2e0f35b4be", "output": "count" } ] } } } }, "edges": [ { "source": "n_79f4db2d5645785a", "target": "n_176f8d0b5f919bff" }, { "source": "n_176f8d0b5f919bff", "target": "n_d0f70a55800b4b56" }, { "source": "n_d0f70a55800b4b56", "target": "n_8b3f7a71dd438a51" }, { "source": "n_8b3f7a71dd438a51", "target": "n_363372d39dbea05f", "sourceHandle": "more" }, { "source": "n_363372d39dbea05f", "target": "n_4c086baea76764a0" }, { "source": "n_4c086baea76764a0", "target": "n_d0f70a55800b4b56" }, { "source": "n_8b3f7a71dd438a51", "target": "n_67917f2e0f35b4be", "sourceHandle": "otherwise" }, { "source": "n_67917f2e0f35b4be", "target": "n_2566e5e11158752e" }, { "source": "n_2566e5e11158752e", "target": "n_7a955d5d4c87b3ca", "sourceHandle": "more" }, { "source": "n_7a955d5d4c87b3ca", "target": "n_9fce65da95d8d6e9" }, { "source": "n_9fce65da95d8d6e9", "target": "n_67917f2e0f35b4be" }, { "source": "n_2566e5e11158752e", "target": "n_8b56d92f09cdcfb5", "sourceHandle": "otherwise" } ] } }, "modules": { "n_b5c0c6c41a3a811c": { "name": "Validate files", "imports": [], "source": "export default function({events,email,baseId,table}){if(typeof email!=='string'||!email.trim()||email.startsWith('YOUR_')||typeof baseId!=='string'||!baseId.trim()||baseId.startsWith('YOUR_')||typeof table!=='string'||!table.trim()||table.startsWith('YOUR_'))throw Error('Configure recipient and Airtable');if(!Array.isArray(events))throw Error('Invalid event batch');for(const e of events)if(e?.eventType!=='file_created'||e.itemType!=='file'||typeof e.fileId!=='string'||!e.fileId||typeof e.name!=='string'||(e.createdTime!==null&&typeof e.createdTime!=='string')||(e.modifiedTime!==null&&typeof e.modifiedTime!=='string'))throw Error('Invalid file event');return {files:events,email,baseId,table}}\n" }, "n_d2dbf88c069398c7": { "name": "Prepare next permission", "imports": [], "source": "export default function({files,email,previousState}){if(typeof email!=='string'||!email.trim()||email.startsWith('YOUR_'))throw Error('Configure the recipient email');const state=previousState??{index:0,permissions:[]};if(!Array.isArray(files)||!Array.isArray(state.permissions)||state.index>files.length)throw Error('Invalid share state');if(state.index===files.length)return{state,more:false,fileId:'',email,permissions:state.permissions};return{state,more:true,fileId:files[state.index].fileId,email,permissions:state.permissions}}\n" }, "n_6d78a832df67824b": { "name": "Grant edit access", "imports": [], "source": "export default async function({fileId,email},ctx){const r=await ctx.actions.call('googledrive.permissions.create',{fileId,type:'user',role:'writer',emailAddress:email,supportsAllDrives:true});if(typeof r?.id!=='string'||!r.id)throw Error('Permission creation not confirmed');return {permissionId:r.id}}\n" }, "n_1803f7d2e749e208": { "name": "Remember permission", "imports": [], "source": "export default function({state,permissionId}){return {state:{index:state.index+1,permissions:[...state.permissions,permissionId]}}}\n" }, "n_ae941c28efce20b1": { "name": "Prepare next Airtable record", "imports": [], "source": "export default function({files,permissions,baseId,table,previousState}){if(!baseId||!table||baseId.startsWith('YOUR_')||table.startsWith('YOUR_')||files.length!==permissions.length)throw Error('Configure Airtable and verify permission results');const state=previousState??{index:0};if(state.index===files.length)return{state,more:false,baseId,table,fields:{},count:state.index};const f=files[state.index],fields={FileId:f.fileId,sentId:permissions[state.index],FileName:f.name,CreatedTime:f.createdTime,ModifiedTime:f.modifiedTime};return{state,more:true,baseId,table,fields,count:state.index}}\n" }, "n_413694b436308b90": { "name": "Log file metadata", "imports": [], "source": "export default async function({baseId,table,fields},ctx){const r=await ctx.actions.call('airtable.create_records',{baseId,tableIdOrName:table,records:[{fields}]});if(!Array.isArray(r?.records)||r.records.length!==1||typeof r.records[0].id!=='string'||!r.records[0].id)throw Error('Airtable creation not confirmed');return {id:r.records[0].id}}\n" }, "n_a316fb47d0157db4": { "name": "Advance to next record", "imports": [], "source": "export default function({state}){return{state:{index:state.index+1}}}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }