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

@ayetu/sdk-js

v1.0.196

Published

A comprehensive SDK for Ayetu services.

Downloads

19

Readme

Ayetu SDK Documentation

Welcome to the Ayetu API and SDK documentation. This guide provides an overview of how to use the Ayetu API and SDK in both web and mobile contexts.

Installation

The Web SDK can be inslled via npm:

npm i @ayetu/sdk-js

Import

You can import the Web SDK as a named import:

import { Ayetu } from '@ayetu/sdk-js';

Initialisation

Web SDK

The initialization process for the Web SDK is crucial and should only be performed once when the page loads. The SDK exposes an Ayetu.init() function, which initializes the SDK with the required configuration.

Ayetu.init({
  net: 'Test',
  connectionToken: new URLSearchParams(window.location.search).get('connection-token') || undefined,
  updateToken: new URLSearchParams(window.location.search).get('update-token') || undefined,
  url: window.location.href,
  debug: true,
});

Parameters

  • net: Can be set to "Main" or "Test", which adjusts the API endpoint URL accordingly.
  • connectionToken: If a connection-token is present in the URL after returning from a social login, it can be used to initialize the SDK and connect the user to the websocket.
  • updateToken: If an update-token is present in the URL after returning from a social login, it can be used to initialize the SDK. The auth.status will be set to "RequiresMore", and an 'auth-status-changed' event will be emitted.
  • url: Should be set to the current URL or the URL to which you want the user to be returned after signing in with a social provider.
  • debug: A boolean value defaulting to false. When set to true, the SDK will provide useful debug logs.

SignIn

To sign in, the user will be redirected to the respective social sign-in provider. If they sign in successfully, they will be returned to the URL specified in Ayetu.init(). The URL will include a query string with either an update-token, connection-token, or error.

Users can Sign in with X:

Ayetu.auth.signIn('X');
Ayetu.auth.signIn('Facebook');

Update Token

After signing in, you will receive an update-token if you have not previously set a Name and a Handle. The name must be at least one character, and the handle must be unique and not used by another user.

Presenting the "Requires More" Screen

  • event: The SDK will emit an 'auth-status-changed' event with the value 'RequiresMore'.
  • state: Ayetu.state.auth.status will be 'RequiresMore'.

You can check if the entered handle is unique:

const available: boolean = await Ayetu.auth.checkHandle('myhandle');

And submit the update:

const available: boolean = await Ayetu.auth.submit('myhandle', `Alice Boyd`);

You will then observe the status change from 'RequiresMore' to 'Connecting' and then 'Connected'.

Connection Token

Signing in after submitting your name and handle, or as a result of submitting your name and handle, you will receive a connection token. This token is single-use and must be utilized within 10 seconds of issuance.

For the Web SDK, no additional action is required. As soon as you receive a connection token, you will be immediately connected to the websocket. The status will transition from Connecting to Connected.

  • event: The SDK will emit an 'auth-status-changed' event with the value 'Connected'.
  • state: Ayetu.state.auth.status will be 'Connected'.

Managing the WebSocket Connection

Keeping WebSocket connections open when they are unused can be a waste of resources. Whenever possible and reasonable, close the connection to free up these resources.

Ayetu.auth.disconnect();

Reconnecting

Whenever a connection token is issued, a session-token is set as a secure, HTTP-only cookie. This session-token can be used to obtain a new connection-token whenever needed for reconnection.

The Web handles this for you in two scenarios:

  • Initialization (init): If no updateToken or connectionToken is present, an attempt to obtain a new connection-token is made.
  • connect: If Ayetu.auth.connect() is called without a connectionToken, an attempt to obtain a new connection-token is made.

Contact Management

Adding a Contact

To add a contact, use the add method provided by the SDK:

const result = Ayetu.contact.add('CON_contactUserId123');
if (!result.success) {
  console.error('Failed to add contact:', result.error);
}

Removing a Contact

To remove a contact, use the remove method provided by the SDK:

const result = Ayetu.contact.remove('contactUserId123');
if (!result.success) {
  console.error('Failed to remove contact:', result.error);
}

Getting Contacts

To retrieve the list of contacts, use the get method provided by the SDK:

const result = Ayetu.contact.get();
if (!result.success) {
  console.error('Failed to retrieve contacts:', result.error);
}