UNPKG

@sagi.io/workers-pubsub

Version:

Google Pub/Sub API for Cloudflare Workers

70 lines (63 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.publish = exports.list = exports.get = void 0; const list = baseInputs => async () => { const { headers, projectId, baseUrl } = baseInputs; const method = 'GET'; const url = `${baseUrl}/projects/${projectId}/topics`; const response = await fetch(url, { method, headers }); const { topics } = await response.json(); return topics; }; exports.list = list; const get = baseInputs => async ({ topic }) => { const { headers, projectId, baseUrl } = baseInputs; const method = 'GET'; const url = `${baseUrl}/projects/${projectId}/topics/${topic}`; const response = await fetch(url, { method, headers }); return await response.json(); }; exports.get = get; const publish = baseInputs => async ({ topic, messages }) => { const { headers, projectId, baseUrl } = baseInputs; const method = 'POST'; const url = `${baseUrl}/projects/${projectId}/topics/${topic}:publish`; const bodyJSON = { messages }; const body = JSON.stringify(bodyJSON); const response = await fetch(url, { method, headers, body }); return await response.json(); }; exports.publish = publish;