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

@kkbox/kkbox-js-sdk

v1.3.6

Published

KKBOX Open API developer SDK for JavaScript. Use it to easily access KKBOX open API to get various metadata about KKBOX's tracks, albums, artists, playlists and stations.

Downloads

67

Readme

KKBOX Open API Developer SDK for JavaScript

npm (scoped) Build Status License Apache

The SDK helps you to access various metadata from KKBOX, including tracks, albums, artists, playlists and stations.

Getting Started

Install the SDK using npm

$ npm install @kkbox/kkbox-js-sdk

Usage example

import { Auth, Api } from '@kkbox/kkbox-js-sdk';

// Create an auth object with client id and secret
const auth = new Auth(client_id, client_secret);

// Fetch your access token
auth.clientCredentialsFlow
  .fetchAccessToken()
  .then(response => {
    const access_token = response.data.access_token;

    // Create an API object with your access token
    const api = new Api(access_token);

    // Fetch content with various fetchers
    api.searchFetcher
      .setSearchCriteria('五月天 派對動物', 'track')
      .fetchSearchResult()
      .then(response => {

        // Content from the KKBOX Open API
        console.log(response.data);

        // Continue to the next page
        api.searchFetcher.fetchNextPage(response).then(response => {
          console.log(response.data);
        });

      });
  });

Test

To test the SDK, a valid client ID and client secret are required.

Please visit https://developer.kkbox.com/, create a new developer account, and obtain the client ID and client secret of your app.

Then, create a file named client_secrets.json, put it into the test directory, and fill your client ID and client secret into it.

It may look like

{
  "kkbox_sdk": {
    "client_id": "YOUR CLIENT ID",
    "client_secret": "YOUR CLIENT SECRET"
  }
}

Run the test:

$ npm test

Documentation

See https://kkbox.github.io/OpenAPI-JavaScript/ for full documentation.

Use the SDK in Web Browsers

The SDK plays fine with Node.js, but works partially in web browsers.

You can use the SDK in your Web and Electron apps, but you need to prepare a middle man server to help you to obtain access tokens. That's because KKBOX's Open API server supports Cross-Origin Resource Sharing (CORS), but the Auth server does not.

In other words, your JavaScript code hosted on your own website could access data from KKBOX, but direct access to the Auth server is forbidden by the security policy of modern web browsers.

When developing an Electron app, you can choose to turn web security off to make you app able to fetch access tokens. You can do this while creating browser windows.

mainWindow = new BrowserWindow({
  width: 500,
  height: 500,
  useContentSize: true,
  webPreferences: {
    webSecurity: false
  }
});

License

Copyright 2018 KKBOX Technologies Limited

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.