Overview

The Fleek Platform SDK is a TypeScript library that allows you to interact with Fleek’s services. It’s composed of methods that you can leverage to build your own application on top of Fleek’s services.

Install

The SDK is available as an NPM package.

npm install @fleek-platform/sdk

Authentication

Authentication requires providing an access token. There are currently two methods available: the ApplicationAccessTokenService and PersonalAccessTokenService. These services differ in their application, depending on whether you’re deploying them in a client-side or server-side context.

Available Methods

The table below outlines the available methods in the left column alongside the corresponding target environments for Web or Node.js applications.

Method                          Web       Node
PersonalAccessTokenService      
ApplicationAccessTokenService   

Multiple Instance Support

You can create concurrent instances by providing the Personal Access Token and Project ID on library instantiation. This is important for navigating between projects.

In the example below, we share a Personal Access Token (PAT) and a different Project ID (PID) for each new instance of FleekSdk.

import { FleekSdk, PersonalAccessTokenService } from '@fleek-platform/sdk';

const accessTokenServiceA = new PersonalAccessTokenService({
  personalAccessToken: <PAT>,
  projectId: <PROJECT_ID_A>,
});

const accessTokenServiceB = new PersonalAccessTokenService({
  personalAccessToken: <PAT>,
  projectId: <PROJECT_ID_B>,
});

const fleekSdkInstanceA = new FleekSdk({
  accessTokenService: accessTokenServiceA,
});

const fleekSdkInstanceB = new FleekSdk({
  accessTokenService: accessTokenServiceB,
});

Instance method calls are tied to the Project ID designated during the Fleek Platform SDK instantiation. For example, files added to the storage service will appear under the matching instance Project ID.

PersonalAccessTokenService

The personal access token (PAT) is intended for use in a Backend Node.js environment and should be kept private. For example, you can store the token in an environment variable, but you wouldn’t want to commit the token into a repository history.

Parameters

Parameters                           Description
--------------------------------------------------
personalAccessToken                  The Private PAT obtained from user account dashboard or CLI
projectID (Optional)                 A Project ID required for IPFS and IPNS services
graphqlServiceApiUrl (Optional)      The GraphQL Service API URL, which defaults to the main Fleek Platform GraphQL Service API

This method of authentication relies on a personalAccessToken which can be obtained from the CLI pat create command.

Usage Example

import { FleekSdk, PersonalAccessTokenService } from '@fleek-platform/sdk';

const personalAccessTokenService = new PersonalAccessTokenService({
  personalAccessToken: <PAT>,
  projectId: <PROJECT_ID>, // Optional
});

const fleekSdk = new FleekSdk({
  accessTokenService: personalAccessTokenService,
});

ApplicationAccessTokenService

Application credentials are the access tokens to your project. You can use this authentication method if you want to upload files or directories to the Fleek Storage. For other SDK methods you need to use the PersonalAccessTokenService.

You can create an application token following the steps here.

Parameters

Parameters                           Description
--------------------------------------------------
clientID                             The Client ID generated in the applications CLI service
authAppsServiceUrl (Optional)        The Applications Authentication Service URL

This method of authentication relies on a clientId which can be obtained after creating an application from the CLI application create command.

Usage Example

import { FleekSdk, ApplicationAccessTokenService } from '@fleek-platform/sdk';

const applicationService = new ApplicationAccessTokenService({
  clientId: <CLIENT_ID>,
});

const fleekSdk = new FleekSdk({
  accessTokenService: applicationService
});