UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

78 lines • 3.12 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../core/resource.mjs"; import { path } from "../../../internal/utils/path.mjs"; export var BaseTokens = /* @__PURE__ */ (() => { class BaseTokens extends APIResource { /** * Mints a new relay-scoped token and adds it to the relay's accepted-auth * registry. The token value (secret) is shown once in the response. A relay may * hold up to 10 tokens; creating an 11th is rejected. * * @example * ```ts * const token = await client.moq.relays.tokens.create( * 'a1b2c3d4e5f67890a1b2c3d4e5f67890', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * operations: ['publish', 'subscribe'], * }, * ); * ``` */ create(relayID, params, options) { const { account_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/moq/relays/${relayID}/tokens`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Returns metadata for every token the relay accepts. Secrets are never returned, * so a token that has been lost cannot be recovered here. There is no expiry * filter: compare each token's `expires` to the current time to tell which ones * have lapsed. * * @example * ```ts * const tokens = await client.moq.relays.tokens.list( * 'a1b2c3d4e5f67890a1b2c3d4e5f67890', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ list(relayID, params, options) { const { account_id } = params; return this._client.get(path `/accounts/${account_id}/moq/relays/${relayID}/tokens`, options)._thenUnwrap((obj) => obj.result); } /** * Revokes a token by removing it from the set the relay accepts. Relays cache that * set, so revocation takes effect within seconds rather than instantly, and * connections already established with the token are not closed. Revoking an * unknown token succeeds, so the call is idempotent. * * @example * ```ts * const token = await client.moq.relays.tokens.delete( * 'f3a1b2c3d4e5f67890a1b2c3d4e5f678', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * relay_id: 'a1b2c3d4e5f67890a1b2c3d4e5f67890', * }, * ); * ``` */ delete(jti, params, options) { const { account_id, relay_id } = params; return this._client.delete(path `/accounts/${account_id}/moq/relays/${relay_id}/tokens/${jti}`, options); } } BaseTokens._key = Object.freeze([ 'moq', 'relays', 'tokens', ]); return BaseTokens; })(); export class Tokens extends BaseTokens { } //# sourceMappingURL=tokens.mjs.map