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

@roundrobtest/round-cloudflare

v0.0.3

Published

Use this library to integrate Rownd into your Cloudflare Workers application. This SDK provides methods to validate Rownd JWT tokens, fetch and manipulate user data, and generate sign-in links, all within a Cloudflare Worker environment.

Downloads

37

Readme

Round Cloudflare SDK

Use this library to integrate Rownd into your Cloudflare Workers application. This SDK provides methods to validate Rownd JWT tokens, fetch and manipulate user data, and generate sign-in links, all within a Cloudflare Worker environment.

Installation

npm install @roundrobtest/round-cloudflare

Configuration

The SDK can be configured using environment variables or directly through the createInstance function:

  • Environment Variables:
    • ROWND_APP_KEY: Your Rownd application key.
    • ROWND_APP_SECRET: Your Rownd application secret.
    • ROWND_TIMEOUT: Timeout for API requests in milliseconds (optional).

Set these directly in your wrangler.toml file or through the Cloudflare dashboard. In your wrangler.toml file, you can set these variables like this:

[vars]
ROWND_APP_KEY = "your-app-key"
ROWND_APP_SECRET = "your-app-secret"

Get your Rownd app key and app secret from the Rownd Dashboard.

Usage

Basic Example

import { createInstance } from '@roundrobtest/round-cloudflare';

const rownd = createInstance({
  app_key: 'ROWND_APP_KEY',
  app_secret: 'ROWND_APP_SECRET',
});

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request));
});

async function handleRequest(request) {
  try {
    const authorizationHeader = request.headers.get('Authorization');
    if (!authorizationHeader) throw new Error('No authorization header');

    const token = authorizationHeader.replace(/^Bearer\s+/i, '');
    const tokenInfo = await rownd.validateToken(token);

    // Fetch user info
    const userInfo = await rownd.fetchUserInfo({ user_id: tokenInfo.user_id });

    return new Response(JSON.stringify(userInfo.data), { status: 200 });
  } catch (err) {
    return new Response(err.message, { status: 401 });
  }
}

API Reference

createInstance(config)

Creates a new instance of the Rownd client.

  • Parameters:
    • config (Object): Configuration object.
      • app_key (string): Your Rownd application key.
      • app_secret (string): Your Rownd application secret.
      • timeout (number, optional): Timeout for API requests in milliseconds.

rownd.validateToken(token)

Validates a Rownd JWT token.

  • Parameters:
    • token (string): The JWT token to validate.
  • Returns:
    • A promise that resolves to an object containing the decoded token, user ID, and access token.

rownd.fetchUserInfo(opts)

Fetches user information from Rownd.

  • Parameters:
    • opts (Object):
      • user_id (string): The user's ID.
  • Returns:
    • A promise that resolves to the user's data.

rownd.createOrUpdateUser(user)

Creates or updates a user's data in Rownd.

  • Parameters:
    • user (Object):
      • id (string): The user's ID.
      • data (Object): The user's data.
  • Returns:
    • A promise that resolves when the operation is complete.

rownd.deleteUser(userId)

Deletes a user from Rownd.

  • Parameters:
    • userId (string): The user's ID.
  • Returns:
    • A promise that resolves when the user is deleted.

rownd.createSmartLink(opts)

Creates a magic sign-in link for a user.

  • Parameters:
    • opts (Object):
      • email (string, optional): User's email.
      • phone (string, optional): User's phone number.
      • redirect_url (string): URL to redirect after sign-in.
      • data (Object, optional): Additional user data.
  • Returns:
    • A promise that resolves to the smart link object.

rownd.appConfig

Provides access to the application configuration.

  • Returns:
    • A promise that resolves to the application configuration object (TApp).

Version

Current SDK version: 0.0.2