Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@getjoystick/joystick-js

Package Overview
Dependencies
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@getjoystick/joystick-js

Javascript SDK for Joystick

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
78
increased by44.44%
Maintainers
3
Weekly downloads
 
Created
Source

Javascript SDK for Joystick

GitHub Actions Latest Stable Version Total Downloads License

This is the library that simplifies the way how you can communicate with Joystick API.

Requirements

NodeJS 16 and later

Installation

You can install the package via npm:

npm install @getjoystick/joystick-js

Usage

To use the client, import the package.

import { Joystick } from "@getjoystick/joystick-js";

Simple usage looks like this:

const client = new Joystick({
  apiKey: process.env.JOYSTICK_API_KEY,
});

client
  .getContents(["content-id1", "content-id2"])
  .then((getContentsResponse) => {
    console.log(getContentsResponse["content-id1"].myProperty1);
    console.log(getContentsResponse["content-id2"].myProperty2);
  });

Requesting Content by single Content Id

client
  .getContent("content-id1")
  .then((getContentResponse) => console.log(getContentResponse.myProperty1));

Specifying additional parameters:

When creating the Joystick object, you can specify additional parameters which will be used by all API calls from the client, for more details see API documentation:

const client = new Joystick({
  apiKey: process.env.JOYSTICK_API_KEY,
  semVer: "0.0.1",
  userId: "user-id-1",
  params: {
    param1: "value1",
    param2: "value2"
  },
  options: {
    cacheExpirationSeconds: 600, // 10 mins
    serialized: true
  }
});

Options

fullResponse

In most of the cases you will be not interested in the full response from the API, but if you're you can specify fullResponse option to the client methods. The client will return you raw API response:

client
  .getContent("content-id1", { fullResponse: true })
  .then((getContentResponse) => console.log(getContentResponse));
// OR
client
  .getContents(["content-id1", "content-id2"], { fullResponse: true })
  .then((getContentsResponse) => console.log(getContentsResponse));
serialized

When true, we will pass query parameter responseType=serialized to Joystick API.

client
  .getContent("content-id1", { serialized: true })
  .then((getContentResponse) => console.log(getContentResponse));
// OR
client
  .getContents(["content-id1", "content-id2"], { serialized: true })
  .then((getContentsResponse) => console.log(getContentsResponse));
refresh

If you want to ignore existing cache and request the new config – pass this option as true.

client
  .getContent("content-id1", { refresh: true })
  .then((getContentResponse) => console.log(getContentResponse));
// OR
client
  .getContents(["content-id1", "content-id2"], { refresh: true })
  .then((getContentsResponse) => console.log(getContentsResponse));

This option can be set for every API call from the client by setting setSerialized(true):

const client = new Joystick({
  apiKey: process.env.JOYSTICK_API_KEY,
  options: {
    serialized: true
  }
});
// OR 
client.setSerialized(true);

Caching

By default, the client uses InMemoryCache, based on Map, which means the cache will be erased after application restart.

You can specify your cache implementation by implementing the interface SdkCache.

See examples/typescript/node-cache or examples/typescript/redis-cache for more details.

Clear the cache

If you want to clear the cache – run:

client.clearCache().then(() => console.log("Cache cleared!"));

HTTP Client

If you want to provide custom HTTP client, which may be useful for use-cases like specifying custom proxy, collecting detailed metrics about HTTP requests,

You can your HTTP client implementation by implementing the interface HttpClient.

See src/internals/client/axios-client for more details.

Testing

To run unit tests, just run:

npm test

Security

If you discover any security related issues, please email letsgo@getjoystick.com instead of using the issue tracker.

Credits

License

The MIT. Please see License File for more information.

FAQs

Package last updated on 19 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc