{"id":15715340,"url":"https://github.com/cloudflare/pubsub","last_synced_at":"2025-07-29T07:33:35.097Z","repository":{"id":37937309,"uuid":"501735134","full_name":"cloudflare/pubsub","owner":"cloudflare","description":"A set of useful helper methods for writing functions to handle Cloudflare Pub/Sub messages (https://developers.cloudflare.com/pub-sub/)","archived":false,"fork":false,"pushed_at":"2024-09-27T17:19:39.000Z","size":31,"stargazers_count":33,"open_issues_count":1,"forks_count":3,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-07-24T12:49:47.347Z","etag":null,"topics":["cloudflare","mqtt","pubsub","workers"],"latest_commit_sha":null,"homepage":"https://developers.cloudflare.com/pub-sub/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudflare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-09T16:46:59.000Z","updated_at":"2025-03-06T10:08:02.000Z","dependencies_parsed_at":"2024-10-03T21:41:28.060Z","dependency_job_id":"5ea5d2c6-1a9c-4deb-974f-df22d4209570","html_url":"https://github.com/cloudflare/pubsub","commit_stats":{"total_commits":16,"total_committers":2,"mean_commits":8.0,"dds":0.0625,"last_synced_commit":"9923aaa448dd1246d5b563cbacd25ac01b39cc6d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cloudflare/pubsub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fpubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fpubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fpubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fpubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudflare","download_url":"https://codeload.github.com/cloudflare/pubsub/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fpubsub/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267646094,"owners_count":24120942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare","mqtt","pubsub","workers"],"created_at":"2024-10-03T21:41:00.071Z","updated_at":"2025-07-29T07:33:35.061Z","avatar_url":"https://github.com/cloudflare.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pubsub\n\nA set of useful helper methods for writing functions to handle [Cloudflare Pub/Sub](https://developers.cloudflare.com/pub-sub/) messages. This includes:\n\n- A `isValidBrokerRequest` helper for [authenticating incoming on-publish webhooks](https://developers.cloudflare.com/pub-sub/learning/integrate-workers/)\n- A `PubSubMessage` type with the fields sent from the Broker to your Worker for use with TypeScript-based Workers and/or for type-aware editors.\n\n## Installation\n\nUse `npm` to install:\n\n```sh\nnpm install @cloudflare/pubsub\n```\n\n## Example\n\nThe following example shows how to use `isValidBrokerRequest` in a Worker to validate incoming on-publish webhooks from a Pub/Sub broker.\n\nYou can use [`wrangler`](https://github.com/cloudflare/wrangler2) to bundle your code for deployment to [Cloudflare Workers](https://developers.cloudflare.com/workers).\n\n```ts\nimport { isValidBrokerRequest, PubSubMessage } from \"@cloudflare/pubsub\"\n\nasync function pubsub(\n    messages: Array\u003cPubSubMessage\u003e,\n    env: any,\n    ctx: ExecutionContext\n): Promise\u003cArray\u003cPubSubMessage\u003e\u003e {\n\n    // Messages may be batched at higher throughputs, so we should loop over\n    // the incoming messages and process them as needed.\n    let messagesToKeep: Array\u003cPubSubMessage\u003e\n    for (let msg of messages) {\n        console.log(msg);\n        // Drop debug messages sent by our clients to reduce the load on our\n        // subscribers.\n        if (!msg.topic.startsWith(\"debug\") {\n            messagesToKeep.push(msg)\n        }\n    }\n\n    return messagesToKeep;\n}\n\nconst worker = {\n    async fetch(req: Request, env: any, ctx: ExecutionContext) {\n        // Critical: you must validate the incoming request is from your Broker\n        // In the future, Workers will be able to do this on your behalf for Workers\n        // in the same account as your Pub/Sub Broker.\n        if (await isValidBrokerRequest(req)) {\n            // Parse the PubSub message\n            let incomingMessages: Array\u003cPubSubMessage\u003e = await req.json();\n\n            // Pass the messages to our pubsub handler, and capture the returned\n            // message.\n            let outgoingMessages = await pubsub(incomingMessages, env, ctx);\n\n            // Re-serialize the messages and return a HTTP 200.\n            // The Content-Type is optional, but must either by\n            // \"application/octet-stream\" or left empty.\n            return new Response(JSON.stringify(outgoingMessages), { status: 200 });\n        }\n\n        return new Response(\"not a valid Broker request\", { status: 403 });\n    },\n};\n\nexport default worker;\n```\n\nYou can use `wranger publish` to publish this directly: the latest `wrangler` supports TypeScript natively.\n\n## License\n\nBSD 3-Clause licensed. Copyright Cloudflare, Inc. 2022.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Fpubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudflare%2Fpubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Fpubsub/lists"}