{"_id":"@bison.digital/pusher-cloudflare","_rev":"2-994e1fb241eb25a59e3f8efa623f83f0","name":"@bison.digital/pusher-cloudflare","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@bison.digital/pusher-cloudflare","version":"1.0.0","keywords":["pusher","cloudflare","workers","websocket","realtime","typescript"],"author":{"name":"Zach Bimson"},"license":"MIT","_id":"@bison.digital/pusher-cloudflare@1.0.0","maintainers":[{"name":"zach.bison","email":"zach@bison.digital"}],"homepage":"https://github.com/bison-digital/pusher-cloudflare#readme","bugs":{"url":"https://github.com/bison-digital/pusher-cloudflare/issues"},"dist":{"shasum":"2ef731d4fa33a7376625c5b2252280852f0412ff","tarball":"https://registry.npmjs.org/@bison.digital/pusher-cloudflare/-/pusher-cloudflare-1.0.0.tgz","fileCount":21,"integrity":"sha512-DJrQvgpXVn8K6tFNB243VHKTt0+t+F+Sm2qk/n+CMJ8Ezt5Of338M3n9xmfzufY2DIssE8yud7Xq7JWnxG+E9g==","signatures":[{"sig":"MEUCIQCmJxbw7N88MFAVTmp63nhKJmnnJYGMOHnZZ0uSD5DC0wIgDG8MynHDbyCPeoHjOXJ63AmVEXbJWaxWQ0xDTJkedSU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":126829},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"305e9da59ba6fea5dfe600ca3d53fefcfd17d9d9","scripts":{"build":"pnpm run clean && tsc && rollup -c","clean":"rimraf dist/","prepack":"pnpm run build","version":"pnpm run build && git add -A dist","typecheck":"tsc --noEmit","postversion":"git push && git push --tags","prepublishOnly":"pnpm run clean && pnpm run build"},"_npmUser":{"name":"zach.bison","email":"zach@bison.digital"},"repository":{"url":"git+https://github.com/bison-digital/pusher-cloudflare.git","type":"git"},"_npmVersion":"10.8.2","description":"Pusher SDK for Cloudflare Workers - A lightweight, Worker-compatible implementation","directories":{},"_nodeVersion":"20.19.5","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"rimraf":"^5.0.0","rollup":"^4.0.0","typescript":"^5.0.0","@types/node":"^20.0.0","@cloudflare/workers-types":"^4.0.0","rollup-plugin-typescript2":"^0.36.0"},"_npmOperationalInternal":{"tmp":"tmp/pusher-cloudflare_1.0.0_1758037303202_0.28856878240570283","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@bison.digital/pusher-cloudflare","version":"1.0.1","type":"module","description":"Pusher SDK for Cloudflare Workers - A lightweight, Worker-compatible implementation","main":"dist/index.js","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.js","types":"./dist/index.d.ts"}},"scripts":{"build":"pnpm run clean && tsc && rollup -c","clean":"rimraf dist/","typecheck":"tsc --noEmit","prepublishOnly":"pnpm run clean && pnpm run build","prepack":"pnpm run build","version":"pnpm run build && git add -A dist","postversion":"git push && git push --tags"},"keywords":["pusher","cloudflare","workers","websocket","realtime","typescript"],"author":{"name":"Zach Bimson"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/bison-digital/pusher-cloudflare.git"},"bugs":{"url":"https://github.com/bison-digital/pusher-cloudflare/issues"},"homepage":"https://github.com/bison-digital/pusher-cloudflare#readme","devDependencies":{"@cloudflare/workers-types":"^4.0.0","@types/node":"^20.0.0","rimraf":"^5.0.0","rollup":"^4.0.0","rollup-plugin-typescript2":"^0.36.0","typescript":"^5.0.0"},"engines":{"node":">=18.0.0"},"publishConfig":{"access":"public"},"_id":"@bison.digital/pusher-cloudflare@1.0.1","gitHead":"ed117e88f239dcb56e9fcd8e3f4c3cf49e901bb5","_nodeVersion":"20.20.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-Kvt6pl1gDL9XH2zxdHLwmCGXsn/6e+ptksjVB237TRl9T1Z82iXDRDtZnXxjh/boitxwffhxri77oH9wzAOH0w==","shasum":"0d5828b7a6837ce7aadfc6d71331589bf6cae70f","tarball":"https://registry.npmjs.org/@bison.digital/pusher-cloudflare/-/pusher-cloudflare-1.0.1.tgz","fileCount":21,"unpackedSize":127375,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIErW9uiOSnrsUX7c6tEt67BaHXbr+aTqmYwcC1fyknXSAiEAr9hXCNR+dYqUT4aILI/KgK6TPp1VAGOUYy4vDxGCq3A="}]},"_npmUser":{"name":"zach.bison","email":"zach@bison.digital"},"directories":{},"maintainers":[{"name":"zach.bison","email":"zach@bison.digital"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pusher-cloudflare_1.0.1_1769735756955_0.8215810897945619"},"_hasShrinkwrap":false}},"time":{"created":"2025-09-16T15:41:43.072Z","modified":"2026-01-30T01:15:57.231Z","1.0.0":"2025-09-16T15:41:43.381Z","1.0.1":"2026-01-30T01:15:57.095Z"},"bugs":{"url":"https://github.com/bison-digital/pusher-cloudflare/issues"},"author":{"name":"Zach Bimson"},"license":"MIT","homepage":"https://github.com/bison-digital/pusher-cloudflare#readme","keywords":["pusher","cloudflare","workers","websocket","realtime","typescript"],"repository":{"type":"git","url":"git+https://github.com/bison-digital/pusher-cloudflare.git"},"description":"Pusher SDK for Cloudflare Workers - A lightweight, Worker-compatible implementation","maintainers":[{"name":"zach.bison","email":"zach@bison.digital"}],"readme":"# @bison.digital/pusher-cloudflare\n\nA lightweight Pusher SDK implementation for Cloudflare Workers that uses Web Crypto API instead of Node.js crypto module.\n\n## Features\n\n- ✅ Full compatibility with Cloudflare Workers\n- ✅ No Node.js dependencies\n- ✅ TypeScript support with full type definitions\n- ✅ Private and presence channel authentication\n- ✅ Batch event triggering\n- ✅ Channel information queries\n- ✅ Lightweight and performant\n\n## Installation\n\n```bash\nnpm install @bison.digital/pusher-cloudflare\n# or\npnpm add @bison.digital/pusher-cloudflare\n# or\nyarn add @bison.digital/pusher-cloudflare\n```\n\n## Usage\n\n### Basic Setup\n\n```typescript\nimport { Pusher } from '@bison.digital/pusher-cloudflare';\n\nconst pusher = new Pusher({\n  appId: 'your-app-id',\n  key: 'your-key',\n  secret: 'your-secret',\n  cluster: 'eu', // optional, defaults to 'mt1'\n  useTLS: true   // optional, defaults to true\n});\n```\n\n### Triggering Events\n\n```typescript\n// Single channel\nawait pusher.trigger('my-channel', 'my-event', {\n  message: 'Hello World!'\n});\n\n// Multiple channels\nawait pusher.trigger(['channel-1', 'channel-2'], 'my-event', {\n  message: 'Hello Everyone!'\n});\n\n// With socket exclusion\nawait pusher.trigger('my-channel', 'my-event', {\n  message: 'Hello World!'\n}, 'socket-id-to-exclude');\n\n// Using options object\nawait pusher.trigger({\n  channels: 'my-channel',\n  event: 'my-event',\n  data: { message: 'Hello World!' },\n  socketId: 'socket-id-to-exclude'\n});\n```\n\n### Batch Triggering\n\n```typescript\nawait pusher.triggerBatch([\n  {\n    channel: 'channel-1',\n    name: 'event-1',\n    data: { message: 'Hello Channel 1!' }\n  },\n  {\n    channel: 'channel-2',\n    name: 'event-2',\n    data: { message: 'Hello Channel 2!' },\n    socketId: 'socket-to-exclude'\n  }\n]);\n```\n\n### Channel Authentication\n\n#### Private Channels\n\n```typescript\n// In your auth endpoint\nconst authResponse = await pusher.authorizeChannel(\n  socketId,\n  'private-channel-name'\n);\n\nreturn new Response(JSON.stringify(authResponse), {\n  headers: { 'Content-Type': 'application/json' }\n});\n```\n\n#### Presence Channels\n\n```typescript\nconst authResponse = await pusher.authenticatePresenceChannel(\n  socketId,\n  'presence-channel-name',\n  {\n    user_id: 'user-123',\n    user_info: {\n      name: 'John Doe',\n      email: 'john@example.com'\n    }\n  }\n);\n\nreturn new Response(JSON.stringify(authResponse), {\n  headers: { 'Content-Type': 'application/json' }\n});\n```\n\n### Channel Information\n\n```typescript\n// Get single channel info\nconst channelInfo = await pusher.getChannel('my-channel', {\n  info: ['subscription_count']\n});\n\n// Get all channels with prefix\nconst channels = await pusher.getChannels('presence-', {\n  info: ['user_count']\n});\n```\n\n## Cloudflare Worker Example\n\n```typescript\nexport default {\n  async fetch(request: Request, env: Env) {\n    const pusher = new Pusher({\n      appId: env.PUSHER_APP_ID,\n      key: env.PUSHER_KEY,\n      secret: env.PUSHER_SECRET,\n      cluster: env.PUSHER_CLUSTER\n    });\n\n    // Handle Pusher auth endpoint\n    if (request.url.includes('/pusher/auth')) {\n      const formData = await request.formData();\n      const socketId = formData.get('socket_id') as string;\n      const channel = formData.get('channel_name') as string;\n\n      const authResponse = await pusher.authorizeChannel(socketId, channel);\n\n      return new Response(JSON.stringify(authResponse), {\n        headers: { 'Content-Type': 'application/json' }\n      });\n    }\n\n    // Trigger an event\n    await pusher.trigger('my-channel', 'my-event', {\n      message: 'Hello from Cloudflare Worker!'\n    });\n\n    return new Response('Event sent!');\n  }\n};\n```\n\n## Migration from Standard Pusher SDK\n\nThe API is designed to be familiar to users of the standard Pusher SDK, with a few key differences:\n\n1. **All auth methods are async**: Since we use Web Crypto API, channel authorization methods return Promises.\n\n```typescript\n// Standard SDK (sync)\nconst auth = pusher.authenticate(socketId, channel);\n\n// This SDK (async)\nconst auth = await pusher.authorizeChannel(socketId, channel);\n```\n\n2. **No Node.js dependencies**: This SDK uses only Web APIs available in Cloudflare Workers.\n\n3. **Explicit configuration**: Pass all configuration in a single object to the constructor.\n\n## Error Handling\n\n```typescript\ntry {\n  const result = await pusher.trigger('my-channel', 'my-event', data);\n  if (!result.success) {\n    console.error('Trigger failed:', result.error);\n  }\n} catch (error) {\n  console.error('Unexpected error:', error);\n}\n```\n\n## TypeScript Support\n\nThis package includes full TypeScript definitions:\n\n```typescript\nimport type {\n  PusherConfig,\n  TriggerOptions,\n  AuthResponse,\n  PresenceMemberData\n} from '@bison.digital/pusher-cloudflare';\n```\n\n## API Reference\n\n### `new Pusher(config: PusherConfig)`\n\nCreates a new Pusher instance.\n\n### `pusher.trigger(channels, event, data, socketId?): Promise<TriggerResponse>`\n\nTriggers an event on one or more channels.\n\n### `pusher.triggerBatch(events): Promise<TriggerResponse>`\n\nTriggers multiple events in a single API call.\n\n### `pusher.authorizeChannel(socketId, channel): Promise<AuthResponse>`\n\nGenerates authentication signature for private channel subscription.\n\n### `pusher.authenticatePresenceChannel(socketId, channel, presenceData): Promise<AuthResponse>`\n\nGenerates authentication for presence channel subscription.\n\n### `pusher.getChannel(channel, options?): Promise<ChannelInfo>`\n\nGets information about a specific channel.\n\n### `pusher.getChannels(prefix?, options?): Promise<{ channels: Record<string, ChannelInfo> }>`\n\nGets information about multiple channels.\n\n## License\n\nMIT\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## Support\n\nFor issues and feature requests, please use the [GitHub issue tracker](https://github.com/bison-digital/pusher-cloudflare/issues).","readmeFilename":"README.md"}