npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fixers/cloudflare-stream

v0.0.2

Published

Cloudflare Stream API for node!

Downloads

177

Readme

Cloudflare API

npm version npm downloads License

Dear Cloudflare team

A library to interact with Cloudflare Stream as the official lib currently lack this functionality...

This library uses ofetch for sending requests.

Install

pnpm i @fixers/cloudflare-stream
npm install @fixers/cloudflare-stream

Usage

const stream = new CloudflareStream({
  accountId: '',
  apiToken: ''
})

// fetch all the videos in your library
await stream.all()

// Get a video by UID
const video = await stream.getVideo('<UID>')

// get the video duration
video.duration

// get the video dimensions
video.input.width
video.input.height

Usage with missing APIs

This library provides a CloudflareClient class that do the lightweight job of gluing a request with credentials.

const cloudflareClient = new CloudflareClient({
  accountId: '',
  apiToken: ''
})

// send a get request to cloudflare on the path /stream/<UID>
await cloudflareClient._get<StreamVideo>('stream/<UID>')

// send a request with a custom method
await cloudflareClient._request<StreamVideo>('stream/<UID>', {
  method: 'DELETE'
})

The CloudflareClient expose a common set of functions with an underscore _.

  • _request: send a request, with a custom arbitrary body
  • _get: shorthand for a GET _request
  • _post: shorthand for a POST _request
  • _put: shorthand for a PUT _request
  • _patch: shorthand for a PATCH _request
  • _delete: shorthand for a DELETE _request

When using CloudflareClient, do not put forward slash / at the beginning of the url you want to fetch, the library do a basic string concatenation, this will be fixed in the near future!

Low level requests

The library provides you with a cloudflareRequest function, that is used throughout the library, is mainly there so you have absolute control over the request process.

You can go down a level with _cloudflareRawRequest, a thin wrapper around ofetch, slightly tweaked as you mainly use this function to interact with an API.

// the same as ofetch, with some differences
// url can be also be a new URL(...)
_cloudflareRawRequest(url, options)

Caveats

This library is incomplete, but provides the building blocks to sends proper request to Cloudflare.

The official node library

There is also the official https://github.com/cloudflare/node-cloudflare node library.

It does not support stream, which is the focus of this library.

A note for Cloudflare

Dear Cloudflare team, your documentation is actually pretty good, back it up with some library.

How do you expect developers to use your products if you don't give us the tools to do so?

Do we really need to test our libs on a live service?

Do we really need to experiment to figure out how the heck to do a pagination? Put some example!