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

apple-music-token-node

v2.0.1

Published

generate developer tokens for the apple music api in node, with a CLI mode for development.

Downloads

4,501

Readme

apple music token node

Build Status

use javascript to generate your developer tokens for use with the apple music api.

adapted from: https://github.com/pelauimagineering/apple-music-token-generator/blob/master/music_token.py

install

npm

npm install -S apple-music-token-node

yarn

yarn add apple-music-token-node

-or-

clone, download, or copy-paste this script somewhere in your node project.

updating from v1.x to v2.x

if you don't want to use the async api available in v2, the only code change you need to make is to update from this:

const getToken = require('apple-music-token-node');

to this:

const { getToken } = require('apple-music-token-node');

and you're done!

if you would like to use the new async api, you can require it like so:

const { getTokenAsync } = require('apple-music-token-node');

getTokenAsync takes the same arguments as getToken, and returns a promise (and thus is usable with async/await). the promise resolves to the same object that would be returned by using getToken.

usage

make sure you've placed the .p8 private key file you generated somewhere accessible. also, include or require your teamId and keyId from apple.

synchronous usage:

const path = require('path');
const { getToken } = require('apple-music-token-node');

const { teamId, keyId } = require('./path-to-your-config');

const certPath = path.resolve(__dirname, './path-to-your-p8-file');
const tokenData = getToken(certPath, teamId, keyId);

// tokenData == { token: 'generated_token', expiresAt: timeInSeconds }

asynchronous usage:

const path = require('path');
const { getTokenAsync } = require('apple-music-token-node');

const { teamId, keyId } = require('./path-to-your-config');

const certPath = path.resolve(__dirname, './path-to-your-p8-file');

const generate = async () => {
    const tokenData = await getTokenAsync(certPath, teamId, keyId);
    // tokenData == { token: 'generated_token', expiresAt: timeInSeconds }
    // ...
};

// -or-

const generate = () => {
    getTokenAsync(certPath, teamId, keyId).then((tokenData) => {
        // tokenData == { token: 'generated_token', expiresAt: timeInSeconds }
        // ...
    });
};

cli mode

cli mode to help generate quick tokens during development. for this, install globally:

npm

npm i -g apple-music-token-node

yarn

yarn add -g apple-music-token-node

then you can run:

amtn

and it will prompt you for the data needed to generate your developer token. (prints to the console).

Data entered correctly Basic file path suggestion for incorrect entries