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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@yotoplay/yoto-sdk

v1.2.0

Published

Official TypeScript SDK for Yoto's public API

Downloads

30

Readme

@yotoplay/yoto-sdk

A TypeScript SDK for Yoto's public API.

Installation

npm install @yotoplay/yoto-sdk

Quick Start

Basic Usage

import { yotoSdk, createYotoSdk } from '@yotoplay/yoto-sdk';

// Option 1: Use default instance
const devices = await yotoSdk.devices.getMyDevices();

// Option 2: Create custom configured instance
const customSdk = createYotoSdk({
  clientId: 'your-client-id' // Obtain from https://dashboard.yoto.dev/
});

JWT Authentication (Server-side Usage)

For server-side usage (e.g., API Gateway Lambda functions), you can provide a JWT token directly:

import { createYotoSdk } from '@yotoplay/yoto-sdk';

// Server-side usage with JWT
const sdk = createYotoSdk({
  jwt: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...', // JWT token from event.headers
});

// No need to call login() - JWT is already provided
const devices = await sdk.devices.getMyDevices();
const cards = await sdk.content.getMyCards();

Main SDK Usage

The SDK is organized into logical namespaces that mirror the Yoto API structure:

import { yotoSdk } from '@yotoplay/yoto-sdk';

// Content API - manage cards and content
const cards = await yotoSdk.content.getMyCards();
const card = await yotoSdk.content.getCard('card-id');
const updatedCard = await yotoSdk.content.updateCard(cardData);

// Devices API - manage Yoto devices
const devices = await yotoSdk.devices.getMyDevices();

// Media API - handle media uploads and URLs
const uploadUrl = await yotoSdk.media.getUploadUrlForTranscode(sha256, filename);
await yotoSdk.media.uploadFile(uploadUrl.url, audioBuffer);
const mediaUrl = await yotoSdk.media.getMediaUrl(cardId, mediaId);

// Icons API - manage display icons
const icons = await yotoSdk.icons.getDisplayIcons();

// Family API - manage family images
const familyImages = await yotoSdk.family.getFamilyImages();
const familyImage = await yotoSdk.family.getFamilyImage('image-id');
await yotoSdk.family.uploadFamilyImage(imageBuffer, 'My Family Photo', true, ['family', 'photo']);

// Family Library Groups API - manage card groups
const groups = await yotoSdk.familyLibraryGroups.getGroups();
const group = await yotoSdk.familyLibraryGroups.createGroup({
  title: 'Bedtime Stories',
  description: 'Our favorite bedtime stories',
  cards: ['card1', 'card2', 'card3']
});

Error Handling

The SDK provides custom error types for better error handling:

import { YotoSdkError } from '@yotoplay/yoto-sdk';

try {
  await yotoSdk.devices.getMyDevices();
} catch (error) {
  if (error instanceof YotoSdkError) {
    console.error('SDK Error:', error.message);
    console.error('Status:', error.status);
    console.error('Response:', error.response);
  }
}

Utility Methods

// Extract media ID from track URL
const mediaId = yotoSdk.extractMediaId('yoto:#media123');
// Returns: 'media123'

Examples

Media Upload and Processing

import { yotoSdk } from '@yotoplay/yoto-sdk';
import fs from 'fs';

async function uploadAndProcessMedia() {
  // Read audio file
  const audioBuffer = fs.readFileSync('audio.mp3');
  const sha256 = 'your-file-hash';
  const filename = 'audio.mp3';

  // Get upload URL
  const uploadUrl = await yotoSdk.media.getUploadUrlForTranscode(sha256, filename);
  
  // Upload file
  await yotoSdk.media.uploadFile(uploadUrl.url, audioBuffer);
  
  // Get transcoded result
  const transcoded = await yotoSdk.media.getTranscodedUpload(uploadUrl.uploadId, true);
  
  console.log('Transcoded URL:', transcoded.url);
}

Family Management

import { yotoSdk } from '@yotoplay/yoto-sdk';
import fs from 'fs';

async function manageFamilyContent() {
  // Get all family images
  const familyImages = await yotoSdk.family.getFamilyImages();
  console.log('Family images:', familyImages);
  
  // Upload a new family image
  const imageBuffer = fs.readFileSync('family-photo.jpg');
  const newImage = await yotoSdk.family.uploadFamilyImage(
    imageBuffer, 
    'Our Family Photo', 
    true, // public
    ['family', 'photo', 'memories']
  );
  
  console.log('Uploaded image:', newImage.imageId);
  
  // Get a specific family image
  const image = await yotoSdk.family.getFamilyImage(newImage.imageId);
  console.log('Image details:', image);
}

Family Library Groups

import { yotoSdk } from '@yotoplay/yoto-sdk';

async function manageFamilyLibraryGroups() {
  // Get all groups
  const groups = await yotoSdk.familyLibraryGroups.getGroups();
  console.log('Existing groups:', groups);
  
  // Create a new group
  const newGroup = await yotoSdk.familyLibraryGroups.createGroup({
    title: 'Bedtime Stories',
    description: 'Our favorite bedtime stories collection',
    public: true,
    publicTags: ['bedtime', 'stories', 'kids'],
    cards: ['card1', 'card2', 'card3']
  });
  
  console.log('Created group:', newGroup.groupId);
  
  // Get group details
  const group = await yotoSdk.familyLibraryGroups.getGroup(newGroup.groupId);
  console.log('Group details:', group);
  
  // Update the group
  const updatedGroup = await yotoSdk.familyLibraryGroups.updateGroup(newGroup.groupId, {
    title: 'Updated Bedtime Stories',
    description: 'Updated description',
    cards: ['card1', 'card2', 'card3', 'card4'] // Add more cards
  });
  
  console.log('Updated group:', updatedGroup);
  
  // Delete the group
  await yotoSdk.familyLibraryGroups.deleteGroup(newGroup.groupId);
  console.log('Group deleted');
}

License

MIT