0.0.1-beta.6.9 • Published 8 months ago

@assetlayer/sdk-client v0.0.1-beta.6.9

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

npm version npm version

Asset Layer Client SDK

Manage digital assets for your application with Asset Layer. This Client SDK provides a turn-key solution for integrating your application with Magic Auth and a proxy server.

Prerequisites

This project requires NodeJS and NPM.

Table of contents

Getting Started

These instructions will help getting started managing your digital assets with Asset Layer.

Installation

To install and set up the library, run:

$ npm install @assetlayer/sdk-client

Or if you prefer using Yarn:

$ yarn add @assetlayer/sdk-client

Usage

Reference the SDK

You can reference the SDK in two ways:

import { AssetLayer } from '@assetlayer/sdk-client';

OR

const { AssetLayer } = require('@assetlayer/sdk-client');

Instantiate the SDK

const assetlayer = new AssetLayer();

Load an App

const app = await assetlayer.apps.info({ appId: 'YOUR_APP_ID' });

By default, handlers return the payload and will throw Errors. You can get the raw response by calling the raw handler as shown below:

const response = await assetlayer.apps.raw.info({ appId: 'YOUR_APP_ID' });

The raw handlers can be useful in situations where more data from the response is required. However, it can still throw an error, to fix that we can call the safe handler:

const { result: app, error } = await assetlayer.apps.safe.info({ appId: 'YOUR_APP_ID' });

Some endpoints may have different return types depending on the provided properties. For this reason, there are more specific handlers available:

const appOrApps:App|App[] = await assetlayer.apps.info({ appId: 'YOUR_APP_ID', appIds: ['APP_ID_1', 'APP_ID_2'] });
const app:App = await assetlayer.apps.getApp({ appId: 'YOUR_APP_ID' });
const apps:App[] = await assetlayer.apps.getApps({ appIds: ['APP_ID_1', 'APP_ID_2'] });

These all call the same core endpoint (https://api-v2.assetlayer.com/api/v1/app/info), but getApp & getApps offer stricter type security when passing props and returning values. Typescript is highly recommended and the sdk includes extensive typings, useful for referencing & importing, allowing for turn-key type-safe app development.

Login a User

Logging in a user is as simple as:

assetlayer.loginUser();

This will trigger a prompt for the user to sign-in. You can skip the email prompt by providing an email like so:

assetlayer.loginUser({ email });

You can also directly pass in a did token (unregistered). With this method you can await the response:

const success = await assetlayer.loginUser({ didToken });

You can also pass it a pre-registered didtoken:

const success = await assetlayer.loginUser({ registeredDidToken });

If not passing a didToken, awaiting the response is not effective. To receive an update after success you can pass in an onSuccess handler:

assetlayer.loginUser({ onSuccess: async () => console.log(await assetlayer.users.getUser()) });

Logout a User

assetlayer.logoutUser();

Handling an active session

Using initialize, you can sign in a user if there's already an active session:

const loggedIn = await assetlayer.initialize();

This will return whether or not the user was successfully logged in. You can also pass it an onComplete handler:

assetlayer.initialize((loggedIn) => { if (!loggedIn) assetlayer.loginUser(); });

SDK Development

Connecting with the Org

$ npm init --scope=assetlayer

Building a distribution version

$ npm run build

This task will use microbundle to create a distribution version of the project inside your local dist/ folder

Deploying to NPM

$ npm login

$ npm publish --access public
0.0.1-beta.6.9

8 months ago

0.0.1-beta.6.8

8 months ago

0.0.1-beta.6.7

8 months ago

0.0.1-beta.6.6

9 months ago

0.0.1-beta.6.5

9 months ago

0.0.1-beta.6.4

9 months ago

0.0.1-beta.6.3

9 months ago

0.0.1-beta.6.2

9 months ago

0.0.1-beta.6.1

9 months ago

0.0.1-beta.6.0

9 months ago

0.0.1-beta.5.9

9 months ago

0.0.1-beta.5.8

9 months ago

0.0.1-beta.5.7

9 months ago

0.0.1-beta.5.6

9 months ago

0.0.1-beta.5.5

9 months ago

0.0.1-beta.5.4

9 months ago

0.0.1-beta.5.3

9 months ago

0.0.1-beta.5.2

9 months ago

0.0.1-beta.5.1

9 months ago

0.0.1-beta.5.0

9 months ago

0.0.1-beta.4.9

9 months ago

0.0.1-beta.4.8

9 months ago

0.0.1-beta.4.7

9 months ago

0.0.1-beta.4.6

9 months ago

0.0.1-beta.4.5

9 months ago

0.0.1-beta.4.4

9 months ago

0.0.1-beta.4.3

9 months ago

0.0.1-beta.4.2

9 months ago

0.0.1-beta.4.1

9 months ago

0.0.1-beta.4.0

9 months ago

0.0.1-beta.3.9

9 months ago

0.0.1-beta.3.8

9 months ago

0.0.1-beta.3.7

9 months ago

0.0.1-beta.3.6

9 months ago

0.0.1-beta.3.5

9 months ago

0.0.1-beta.3.4

9 months ago

0.0.1-beta.3.3

9 months ago

0.0.1-beta.3.2

9 months ago

0.0.1-beta.3.1

9 months ago

0.0.1-beta.3.0

9 months ago

0.0.1-beta.2.9

9 months ago

0.0.1-beta.2.8

9 months ago

0.0.1-beta.2.7

9 months ago

0.0.1-beta.2.6

9 months ago

0.0.1-beta.2.5

9 months ago

0.0.1-beta.2.4

9 months ago

0.0.1-beta.2.3

9 months ago

0.0.1-beta.2.2

9 months ago

0.0.1-beta.2.1

9 months ago

0.0.1-beta.2.0

9 months ago

0.0.1-beta.1.9

9 months ago

0.0.1-beta.1.8

9 months ago

0.0.1-beta.1.7

9 months ago

0.0.1-beta.1.6

9 months ago

0.0.1-beta.1.5

9 months ago

0.0.1-beta.1.4

9 months ago

0.0.1-beta.1.3

9 months ago

0.0.1-beta.1.2

9 months ago

0.0.1-beta.1.1

9 months ago