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

@gigya-ts/gigya

v0.1.13

Published

Type-safe Gigya client for the browser and Node.js

Downloads

659

Readme

@gigya-ts/gigya

A tiny type-safe client for interacting with the Gigya REST API for Node.js and the browser.

See @gigya-ts/web-sdk if you are using the Gigya Web SDK instead.

Installation

Install the @gigya-ts/gigya package from your package manager of choice:

# npm
npm add @gigya-ts/gigya
# pnpm
pnpm add @gigya-ts/gigya

Usage

0. (Optional) Define your Custom Gigya Schemas

See adding custom schemas to define your custom schemas (data, preferences, etc.) so that response types from the REST API include your custom fields.

1. Create a Gigya Client

Create a new Gigya client instance with your API key and data center. Make sure to pass your own schemas as generics if you want the client to return your own types.

import { Gigya } from '@gigya-ts/gigya';

const gigya = Gigya<MyDataSchema, MyPreferencesSchema, MySubscriptionsSchema>({
    apiKey: '4_qd71...',
    dataCenter: 'eu1.gigya.com',
    // see credentials in next step
});

2. Choose an Authentication Method

@gigya-ts/gigya supports multiple different authentication methods:

(Recommended) User/Application key and private key

Creates a short-lived bearer token for every request using admin or application user's RSA key-pair. This is the recommended approach when accessing the REST API with server credentials as real privateKey is never actually sent accross the wire itself. See Asymmetric Keys for more information.

export const gigya = Gigya({
    apiKey: '4_qd71...',
    dataCenter: 'eu1.gigya.com',
    credentials: {
        type: 'asymmetric-key',
        userKey: process.env.GIGYA_USER_KEY,
        privateKey: process.env.GIGYA_PRIVATE_KEY,
    },
});

User/Application Key and Secret

Attaches a userKey and secret from an admin or application user to every request made to the REST API. See Application and User Keys for more information.

export const gigya = Gigya({
    apiKey: '4_qd71...',
    dataCenter: 'eu1.gigya.com',
    credentials: {
        type: 'key-secret',
        userKey: process.env.GIGYA_USER_KEY,
        secret: process.env.GIGYA_USER_SECRET,
    },
});

Bearer Token

Uses an accessToken obtained from socialize.getToken to call the REST API using the authorizations of a single user (even without passing their UID). Only supports the grant_type=client_credentials or grant_type=none flows.

export const gigya = Gigya({
    apiKey: '4_qd71...',
    dataCenter: 'eu1.gigya.com',
    credentials: {
        type: 'bearer-token',
        // Obtained from socialize.getToken
        token: 'st2.s.AtLtNX...',
    },
});

No Authentication

Make unauthenticated requests to the REST API without any credentials (e.g. to fetch public schemas, policies, ...).

export const gigya = Gigya({
    apiKey: '4_qd71...',
    dataCenter: 'eu1.gigya.com',
    credentials: { type: 'none' },
});

3. Make a Request to the Gigya REST API

Once Gigya has been configured, make requests to the REST API using the created client:

// Call the "accounts.setAccountInfo" API method from the Gigya API
const setAccountInfoResponse = await gigya.accounts.setAccountInfo({
    UID: 'YOUR_UID',
    profile: {
        lastName: 'Doe',
    },
});

// Check we got a successful response
if (setAccountInfoResponse.errorCode !== 0) throw new Error(getAccountInfoResponse.errorMessage);

Examples

See examples/gigya for more examples.