[{"data":1,"prerenderedAt":623},["ShallowReactive",2],{"infra-\u002Finfra\u002Fservices\u002Fautomation-soubiran-dev":3,"infra-children-\u002Finfra\u002Fservices\u002Fautomation-soubiran-dev":622},{"id":4,"title":5,"body":6,"contentId":574,"description":575,"ecosystem":576,"extension":611,"meta":612,"navigation":90,"part":613,"path":614,"rawbody":615,"repository":616,"robots":613,"schemaOrg":613,"seo":618,"sitemap":619,"stem":620,"url":15,"__hash__":621},"pages\u002Finfra\u002Fservices\u002Fautomation-soubiran-dev.md","automation.soubiran.dev",{"type":7,"value":8,"toc":569},"minimark",[9,25,28,33,36,39,521,530,545,548,552,555,558,562,565],[10,11,12,18,19,24],"p",{},[13,14,5],"a",{"href":15,"rel":16},"https:\u002F\u002Fautomation.soubiran.dev",[17],"nofollow"," is an internal service that helps me automate various tasks with ",[13,20,23],{"href":21,"rel":22},"https:\u002F\u002Fdevelopers.cloudflare.com\u002Fworkflows\u002F",[17],"Cloudflare Workflows",".",[10,26,27],{},"There is no public access or frontend interface. The endpoint only receives calls and triggers workflows.",[29,30,32],"h2",{"id":31},"development","Development",[10,34,35],{},"The service runs on a Cloudflare Worker that receives HTTP requests from my local CLI tool. Each endpoint triggers a different Cloudflare Workflow.",[10,37,38],{},"For example, I have a workflow that I use to remind myself to publish scheduled tweets.",[40,41,47],"pre",{"className":42,"code":43,"filename":44,"language":45,"meta":46,"style":46},"language-ts shiki shiki-themes github-light github-light github-dark","import type { WorkflowEvent, WorkflowStep } from 'cloudflare:workers'\nimport { WorkflowEntrypoint } from 'cloudflare:workers'\n\nexport default {\n  async fetch(request: Request, env: Env): Promise\u003CResponse> {\n    const body = await request.json\u003C{ scheduleAt?: number, content?: string }>()\n\n    await env.AUTOMATION_WORKFLOW.create({\n      params: {\n        scheduleAt: body.scheduleAt,\n        content: body.content,\n      },\n    })\n\n    return new Response('Scheduled', { status: 201 })\n  },\n}\n\nexport class Automation extends WorkflowEntrypoint\u003CEnv, any> {\n  async run(event: WorkflowEvent\u003Cany>, step: WorkflowStep) {\n    await step.sleepUntil('trigger time', event.payload.scheduleAt)\n\n    await step.do('trigger action', async () => {\n      await fetch(this.env.DISCORD_WEBHOOK_URL, {\n        method: 'POST',\n        headers: {\n          'Content-Type': 'application\u002Fjson',\n        },\n        body: JSON.stringify({ content: event.payload.content }),\n      })\n    })\n  }\n}\n","src\u002Findex.ts","ts","",[48,49,50,73,85,92,104,155,202,207,227,233,239,245,251,257,262,288,294,300,305,334,370,389,394,422,444,456,462,476,482,499,505,510,516],"code",{"__ignoreMap":46},[51,52,55,59,62,66,69],"span",{"class":53,"line":54},"line",1,[51,56,58],{"class":57},"s8jYJ","import",[51,60,61],{"class":57}," type",[51,63,65],{"class":64},"sxrX7"," { WorkflowEvent, WorkflowStep } ",[51,67,68],{"class":57},"from",[51,70,72],{"class":71},"sIIMD"," 'cloudflare:workers'\n",[51,74,76,78,81,83],{"class":53,"line":75},2,[51,77,58],{"class":57},[51,79,80],{"class":64}," { WorkflowEntrypoint } ",[51,82,68],{"class":57},[51,84,72],{"class":71},[51,86,88],{"class":53,"line":87},3,[51,89,91],{"emptyLinePlaceholder":90},true,"\n",[51,93,95,98,101],{"class":53,"line":94},4,[51,96,97],{"class":57},"export",[51,99,100],{"class":57}," default",[51,102,103],{"class":64}," {\n",[51,105,107,110,114,117,121,124,127,130,133,135,138,141,143,146,149,152],{"class":53,"line":106},5,[51,108,109],{"class":57},"  async",[51,111,113],{"class":112},"snPdu"," fetch",[51,115,116],{"class":64},"(",[51,118,120],{"class":119},"sP4rz","request",[51,122,123],{"class":57},":",[51,125,126],{"class":112}," Request",[51,128,129],{"class":64},", ",[51,131,132],{"class":119},"env",[51,134,123],{"class":57},[51,136,137],{"class":112}," Env",[51,139,140],{"class":64},")",[51,142,123],{"class":57},[51,144,145],{"class":112}," Promise",[51,147,148],{"class":64},"\u003C",[51,150,151],{"class":112},"Response",[51,153,154],{"class":64},"> {\n",[51,156,158,161,165,168,171,174,177,180,183,186,189,191,194,196,199],{"class":53,"line":157},6,[51,159,160],{"class":57},"    const",[51,162,164],{"class":163},"sBjJW"," body",[51,166,167],{"class":57}," =",[51,169,170],{"class":57}," await",[51,172,173],{"class":64}," request.",[51,175,176],{"class":112},"json",[51,178,179],{"class":64},"\u003C{ ",[51,181,182],{"class":119},"scheduleAt",[51,184,185],{"class":57},"?:",[51,187,188],{"class":163}," number",[51,190,129],{"class":64},[51,192,193],{"class":119},"content",[51,195,185],{"class":57},[51,197,198],{"class":163}," string",[51,200,201],{"class":64}," }>()\n",[51,203,205],{"class":53,"line":204},7,[51,206,91],{"emptyLinePlaceholder":90},[51,208,210,213,216,219,221,224],{"class":53,"line":209},8,[51,211,212],{"class":57},"    await",[51,214,215],{"class":64}," env.",[51,217,218],{"class":163},"AUTOMATION_WORKFLOW",[51,220,24],{"class":64},[51,222,223],{"class":112},"create",[51,225,226],{"class":64},"({\n",[51,228,230],{"class":53,"line":229},9,[51,231,232],{"class":64},"      params: {\n",[51,234,236],{"class":53,"line":235},10,[51,237,238],{"class":64},"        scheduleAt: body.scheduleAt,\n",[51,240,242],{"class":53,"line":241},11,[51,243,244],{"class":64},"        content: body.content,\n",[51,246,248],{"class":53,"line":247},12,[51,249,250],{"class":64},"      },\n",[51,252,254],{"class":53,"line":253},13,[51,255,256],{"class":64},"    })\n",[51,258,260],{"class":53,"line":259},14,[51,261,91],{"emptyLinePlaceholder":90},[51,263,265,268,271,274,276,279,282,285],{"class":53,"line":264},15,[51,266,267],{"class":57},"    return",[51,269,270],{"class":57}," new",[51,272,273],{"class":112}," Response",[51,275,116],{"class":64},[51,277,278],{"class":71},"'Scheduled'",[51,280,281],{"class":64},", { status: ",[51,283,284],{"class":163},"201",[51,286,287],{"class":64}," })\n",[51,289,291],{"class":53,"line":290},16,[51,292,293],{"class":64},"  },\n",[51,295,297],{"class":53,"line":296},17,[51,298,299],{"class":64},"}\n",[51,301,303],{"class":53,"line":302},18,[51,304,91],{"emptyLinePlaceholder":90},[51,306,308,310,313,316,319,322,324,327,329,332],{"class":53,"line":307},19,[51,309,97],{"class":57},[51,311,312],{"class":57}," class",[51,314,315],{"class":112}," Automation",[51,317,318],{"class":57}," extends",[51,320,321],{"class":112}," WorkflowEntrypoint",[51,323,148],{"class":64},[51,325,326],{"class":112},"Env",[51,328,129],{"class":64},[51,330,331],{"class":163},"any",[51,333,154],{"class":64},[51,335,337,339,342,344,347,349,352,354,356,359,362,364,367],{"class":53,"line":336},20,[51,338,109],{"class":57},[51,340,341],{"class":112}," run",[51,343,116],{"class":64},[51,345,346],{"class":119},"event",[51,348,123],{"class":57},[51,350,351],{"class":112}," WorkflowEvent",[51,353,148],{"class":64},[51,355,331],{"class":163},[51,357,358],{"class":64},">, ",[51,360,361],{"class":119},"step",[51,363,123],{"class":57},[51,365,366],{"class":112}," WorkflowStep",[51,368,369],{"class":64},") {\n",[51,371,373,375,378,381,383,386],{"class":53,"line":372},21,[51,374,212],{"class":57},[51,376,377],{"class":64}," step.",[51,379,380],{"class":112},"sleepUntil",[51,382,116],{"class":64},[51,384,385],{"class":71},"'trigger time'",[51,387,388],{"class":64},", event.payload.scheduleAt)\n",[51,390,392],{"class":53,"line":391},22,[51,393,91],{"emptyLinePlaceholder":90},[51,395,397,399,401,404,406,409,411,414,417,420],{"class":53,"line":396},23,[51,398,212],{"class":57},[51,400,377],{"class":64},[51,402,403],{"class":112},"do",[51,405,116],{"class":64},[51,407,408],{"class":71},"'trigger action'",[51,410,129],{"class":64},[51,412,413],{"class":57},"async",[51,415,416],{"class":64}," () ",[51,418,419],{"class":57},"=>",[51,421,103],{"class":64},[51,423,425,428,430,432,435,438,441],{"class":53,"line":424},24,[51,426,427],{"class":57},"      await",[51,429,113],{"class":112},[51,431,116],{"class":64},[51,433,434],{"class":163},"this",[51,436,437],{"class":64},".env.",[51,439,440],{"class":163},"DISCORD_WEBHOOK_URL",[51,442,443],{"class":64},", {\n",[51,445,447,450,453],{"class":53,"line":446},25,[51,448,449],{"class":64},"        method: ",[51,451,452],{"class":71},"'POST'",[51,454,455],{"class":64},",\n",[51,457,459],{"class":53,"line":458},26,[51,460,461],{"class":64},"        headers: {\n",[51,463,465,468,471,474],{"class":53,"line":464},27,[51,466,467],{"class":71},"          'Content-Type'",[51,469,470],{"class":64},": ",[51,472,473],{"class":71},"'application\u002Fjson'",[51,475,455],{"class":64},[51,477,479],{"class":53,"line":478},28,[51,480,481],{"class":64},"        },\n",[51,483,485,488,491,493,496],{"class":53,"line":484},29,[51,486,487],{"class":64},"        body: ",[51,489,490],{"class":163},"JSON",[51,492,24],{"class":64},[51,494,495],{"class":112},"stringify",[51,497,498],{"class":64},"({ content: event.payload.content }),\n",[51,500,502],{"class":53,"line":501},30,[51,503,504],{"class":64},"      })\n",[51,506,508],{"class":53,"line":507},31,[51,509,256],{"class":64},[51,511,513],{"class":53,"line":512},32,[51,514,515],{"class":64},"  }\n",[51,517,519],{"class":53,"line":518},33,[51,520,299],{"class":64},[522,523,524],"blockquote",{},[10,525,526,529],{},[51,527,528],{},"!NOTE","\nThe code is simplified for clarity. The actual implementation includes error handling, logging, and other production-ready features.",[10,531,532,533,538,539,544],{},"The worker itself does not authenticate requests, even though it is exposed to the public internet. Instead, I rely on ",[13,534,537],{"href":535,"rel":536},"https:\u002F\u002Fdevelopers.cloudflare.com\u002Fcloudflare-one\u002F",[17],"Cloudflare One"," with a ",[13,540,543],{"href":541,"rel":542},"https:\u002F\u002Fdevelopers.cloudflare.com\u002Fcloudflare-one\u002Faccess-controls\u002Fservice-credentials\u002Fservice-tokens\u002F",[17],"service token"," to ensure that only my CLI tool can call the endpoints.",[10,546,547],{},"This keeps authentication outside the worker and prevents unauthorized requests from triggering workflows and generating costs.",[29,549,551],{"id":550},"deployment","Deployment",[10,553,554],{},"Cloudflare Builds deploys the service automatically. Every push to the main branch triggers a new deployment of the worker and its workflows.",[10,556,557],{},"Cloudflare's observability tools expose workflow executions and worker metrics in the dashboard.",[29,559,561],{"id":560},"ecosystem","Ecosystem",[563,564],"infra-ecosystem",{},[566,567,568],"style",{},"html pre.shiki code .s8jYJ, html code.shiki .s8jYJ{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sxrX7, html code.shiki .sxrX7{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sIIMD, html code.shiki .sIIMD{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .snPdu, html code.shiki .snPdu{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sP4rz, html code.shiki .sP4rz{--shiki-light:#E36209;--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":46,"searchDepth":75,"depth":75,"links":570},[571,572,573],{"id":31,"depth":75,"text":32},{"id":550,"depth":75,"text":551},{"id":560,"depth":75,"text":561},"640cabcb-1bd2-4960-b25b-df4f4eb2e9de","An internal service for automating tasks using Cloudflare Workflows and secured by Cloudflare One to ensure only authorized access.",[577,607],{"type":578,"name":537,"description":579,"ecosystem":580},"auth","Protect the automation endpoints so only my CLI can trigger them.",[581],{"type":550,"id":582,"name":583,"description":584,"ecosystem":585},"automation-soubiran-dev","Cloudflare Workers","Expose the automation endpoints and trigger workflows from incoming requests.",[586,604],{"type":587,"id":582,"name":588,"description":589,"ecosystem":590},"build","Cloudflare Build","Deploy the worker and workflows automatically on each push.",[591],{"type":592,"id":593,"name":594,"description":595,"ecosystem":596},"repository","automation-repository","GitHub","Host the private source code for this internal automation service.",[597,601],{"type":598,"name":599,"href":600},"stack","Wrangler","https:\u002F\u002Fdevelopers.cloudflare.com\u002Fworkers\u002Fwrangler",{"type":598,"name":602,"href":603},"Evlog","https:\u002F\u002Fevlog.dev",{"type":605,"name":23,"description":606},"workflows","Run background jobs for the automation tasks handled by the service.",{"type":608,"name":609,"description":610},"domain","Cloudflare Domains","Manage the DNS records that route `automation.soubiran.dev` to the worker.","md",{},null,"\u002Finfra\u002Fservices\u002Fautomation-soubiran-dev","---\ncontentId: 640cabcb-1bd2-4960-b25b-df4f4eb2e9de\ntitle: automation.soubiran.dev\ndescription: >-\n  An internal service for automating tasks using Cloudflare Workflows and secured\n  by Cloudflare One to ensure only authorized access.\nurl: https:\u002F\u002Fautomation.soubiran.dev\nrepository:\n  url: https:\u002F\u002Fgithub.com\u002Fbarbapapazes\u002Fplatform\n  private: true\necosystem:\n  - type: auth\n    name: Cloudflare One\n    description: Protect the automation endpoints so only my CLI can trigger them.\n    ecosystem:\n    - type: deployment\n      id: automation-soubiran-dev\n      name: Cloudflare Workers\n      description: Expose the automation endpoints and trigger workflows from incoming requests.\n      ecosystem:\n        - type: build\n          id: automation-soubiran-dev\n          name: Cloudflare Build\n          description: Deploy the worker and workflows automatically on each push.\n          ecosystem:\n            - type: repository\n              id: automation-repository\n              name: GitHub\n              description: Host the private source code for this internal automation service.\n              ecosystem:\n                - type: stack\n                  name: Wrangler\n                  href: https:\u002F\u002Fdevelopers.cloudflare.com\u002Fworkers\u002Fwrangler\n                - type: stack\n                  name: Evlog\n                  href: https:\u002F\u002Fevlog.dev\n        - type: workflows\n          name: Cloudflare Workflows\n          description: Run background jobs for the automation tasks handled by the service.\n  - type: domain\n    name: Cloudflare Domains\n    description: Manage the DNS records that route `automation.soubiran.dev` to the worker.\n---\n\n[automation.soubiran.dev](https:\u002F\u002Fautomation.soubiran.dev) is an internal service that helps me automate various tasks with [Cloudflare Workflows](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fworkflows\u002F).\n\nThere is no public access or frontend interface. The endpoint only receives calls and triggers workflows.\n\n## Development\n\nThe service runs on a Cloudflare Worker that receives HTTP requests from my local CLI tool. Each endpoint triggers a different Cloudflare Workflow.\n\nFor example, I have a workflow that I use to remind myself to publish scheduled tweets.\n\n```ts [src\u002Findex.ts]\nimport type { WorkflowEvent, WorkflowStep } from 'cloudflare:workers'\nimport { WorkflowEntrypoint } from 'cloudflare:workers'\n\nexport default {\n  async fetch(request: Request, env: Env): Promise\u003CResponse> {\n    const body = await request.json\u003C{ scheduleAt?: number, content?: string }>()\n\n    await env.AUTOMATION_WORKFLOW.create({\n      params: {\n        scheduleAt: body.scheduleAt,\n        content: body.content,\n      },\n    })\n\n    return new Response('Scheduled', { status: 201 })\n  },\n}\n\nexport class Automation extends WorkflowEntrypoint\u003CEnv, any> {\n  async run(event: WorkflowEvent\u003Cany>, step: WorkflowStep) {\n    await step.sleepUntil('trigger time', event.payload.scheduleAt)\n\n    await step.do('trigger action', async () => {\n      await fetch(this.env.DISCORD_WEBHOOK_URL, {\n        method: 'POST',\n        headers: {\n          'Content-Type': 'application\u002Fjson',\n        },\n        body: JSON.stringify({ content: event.payload.content }),\n      })\n    })\n  }\n}\n```\n\n> [!NOTE]\n> The code is simplified for clarity. The actual implementation includes error handling, logging, and other production-ready features.\n\nThe worker itself does not authenticate requests, even though it is exposed to the public internet. Instead, I rely on [Cloudflare One](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fcloudflare-one\u002F) with a [service token](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fcloudflare-one\u002Faccess-controls\u002Fservice-credentials\u002Fservice-tokens\u002F) to ensure that only my CLI tool can call the endpoints.\n\nThis keeps authentication outside the worker and prevents unauthorized requests from triggering workflows and generating costs.\n\n## Deployment\n\nCloudflare Builds deploys the service automatically. Every push to the main branch triggers a new deployment of the worker and its workflows.\n\nCloudflare's observability tools expose workflow executions and worker metrics in the dashboard.\n\n## Ecosystem\n\n::infra-ecosystem\n::\n",{"url":617,"private":90},"https:\u002F\u002Fgithub.com\u002Fbarbapapazes\u002Fplatform",{"title":5,"description":575},{"loc":614},"infra\u002Fservices\u002Fautomation-soubiran-dev","suOnJt7AzcGF88aUChkHxkQ87uVQEvSu_iuOczcasHM",[],1795016673127]