1.0.196 • Published 9 months ago

@ayetu/sdk-js v1.0.196

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

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);
}
1.0.196

9 months ago

1.0.195

9 months ago

1.0.187

11 months ago

1.0.186

11 months ago

1.0.189

11 months ago

1.0.188

11 months ago

1.0.183

11 months ago

1.0.182

11 months ago

1.0.185

11 months ago

1.0.184

11 months ago

1.0.181

11 months ago

1.0.180

11 months ago

1.0.176

11 months ago

1.0.175

11 months ago

1.0.178

11 months ago

1.0.177

11 months ago

1.0.172

11 months ago

1.0.171

11 months ago

1.0.174

11 months ago

1.0.173

11 months ago

1.0.179

11 months ago

1.0.170

12 months ago

1.0.80

1 year ago

1.0.84

1 year ago

1.0.83

1 year ago

1.0.82

1 year ago

1.0.81

1 year ago

1.0.88

1 year ago

1.0.87

1 year ago

1.0.86

1 year ago

1.0.85

1 year ago

1.0.89

1 year ago

1.0.194

10 months ago

1.0.193

10 months ago

1.0.91

1 year ago

1.0.90

1 year ago

1.0.95

1 year ago

1.0.94

1 year ago

1.0.93

1 year ago

1.0.92

1 year ago

1.0.99

1 year ago

1.0.98

1 year ago

1.0.192

10 months ago

1.0.97

1 year ago

1.0.191

10 months ago

1.0.96

1 year ago

1.0.143

12 months ago

1.0.142

12 months ago

1.0.145

12 months ago

1.0.144

12 months ago

1.0.141

12 months ago

1.0.140

12 months ago

1.0.146

12 months ago

1.0.149

12 months ago

1.0.148

12 months ago

1.0.62

1 year ago

1.0.61

1 year ago

1.0.60

1 year ago

1.0.66

1 year ago

1.0.65

1 year ago

1.0.64

1 year ago

1.0.63

1 year ago

1.0.69

1 year ago

1.0.68

1 year ago

1.0.67

1 year ago

1.0.131

12 months ago

1.0.134

12 months ago

1.0.133

12 months ago

1.0.130

12 months ago

1.0.139

12 months ago

1.0.136

12 months ago

1.0.135

12 months ago

1.0.138

12 months ago

1.0.137

12 months ago

1.0.73

1 year ago

1.0.72

1 year ago

1.0.71

1 year ago

1.0.70

1 year ago

1.0.77

1 year ago

1.0.76

1 year ago

1.0.75

1 year ago

1.0.74

1 year ago

1.0.79

1 year ago

1.0.78

1 year ago

1.0.165

12 months ago

1.0.164

12 months ago

1.0.167

12 months ago

1.0.166

12 months ago

1.0.161

12 months ago

1.0.160

12 months ago

1.0.163

12 months ago

1.0.162

12 months ago

1.0.169

12 months ago

1.0.168

12 months ago

1.0.44

1 year ago

1.0.48

1 year ago

1.0.47

1 year ago

1.0.46

1 year ago

1.0.45

1 year ago

1.0.154

12 months ago

1.0.153

12 months ago

1.0.156

12 months ago

1.0.155

12 months ago

1.0.49

1 year ago

1.0.150

12 months ago

1.0.152

12 months ago

1.0.151

12 months ago

1.0.158

12 months ago

1.0.157

12 months ago

1.0.159

12 months ago

1.0.51

1 year ago

1.0.50

1 year ago

1.0.55

1 year ago

1.0.54

1 year ago

1.0.53

1 year ago

1.0.52

1 year ago

1.0.59

1 year ago

1.0.58

1 year ago

1.0.57

1 year ago

1.0.56

1 year ago

1.0.101

1 year ago

1.0.100

1 year ago

1.0.107

1 year ago

1.0.106

1 year ago

1.0.109

1 year ago

1.0.108

1 year ago

1.0.103

1 year ago

1.0.102

1 year ago

1.0.105

1 year ago

1.0.104

1 year ago

1.0.121

1 year ago

1.0.120

1 year ago

1.0.123

12 months ago

1.0.122

1 year ago

1.0.129

12 months ago

1.0.128

12 months ago

1.0.125

12 months ago

1.0.124

12 months ago

1.0.127

12 months ago

1.0.126

12 months ago

1.0.110

1 year ago

1.0.112

1 year ago

1.0.111

1 year ago

1.0.118

1 year ago

1.0.117

1 year ago

1.0.119

1 year ago

1.0.114

1 year ago

1.0.113

1 year ago

1.0.116

1 year ago

1.0.115

1 year ago

1.0.43

1 year ago

1.0.42

1 year ago

1.0.40

1 year ago

1.0.41

1 year ago

1.0.39

1 year ago

1.0.38

1 year ago

1.0.37

1 year ago

1.0.36

1 year ago

1.0.33

1 year ago

1.0.35

1 year ago

1.0.34

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.22

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.27

1 year ago

1.0.19

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago