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:

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/node';

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/node';

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/node';

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

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

Migrating from Fleek.co to Fleek Platform SDK

The Fleek.co’s SDK and Storage features are part of Fleek Platform SDK, which brings enhanced performance, new features, and broader support for all your development needs.

Learn how to migrate to Fleek Platform with these steps or consult our SDK docs for a deep dive.

Fleek Storage JS

If you use Fleek Storage Js to interact with Fleek Storage, migrate to the Fleek Platform, implementing the following changes:

# Old syntax
import { Fleek } from '@fleekhq/sdk';

const sdk = new Fleek({
  apiKey: '<YOUR-API-KEY>',
  assetCanisterId: '<YOUR-ASSET-CANISTER-ID>',
});
# New syntax
import { FleekSdk, ApplicationAccessTokenService } from '@fleek-platform/sdk';

# Using the Application Token
# Learn more about the available token services
# by following the link below
const applicationService = new ApplicationAccessTokenService({
  clientId: <APPLICATION-CLIENT-ID>,
});

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

Learn more by reading the SDK documentation here.

Fleek.co’s SDK

If you use Fleek.co’s SDK to interact with Fleek APIs and Internet Computer, migrate to the Fleek Platform, implementing the following changes:

# Old syntax
import { Fleek } from '@fleekhq/sdk';

const sdk = new Fleek({
  apiKey: '<YOUR-API-KEY>',
  assetCanisterId: '<YOUR-ASSET-CANISTER-ID>',
});

# Using IPFS
await sdk.ipfs().add(...);
# New syntax
import { FleekSdk, ApplicationAccessTokenService } from '@fleek-platform/sdk';

# Using the Application token service
# Learn more about the available token services
# by following the link below
const applicationService = new ApplicationAccessTokenService({
  clientId: <APPLICATION-CLIENT-ID>,
});

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

# Using Storage
# It'll default to IPFS
const result = await fleekSdk.storage().uploadFile({
  file,
  onUploadProgress,
});

Support for Internet Computer asset canister has been deprecated. You must use the Fleek Platform Storage, which includes similar methods as follows:

# Deprecated feature
const items = await sdk.assets().listAll();
const item = await sdk.assets().get(key);
# Storage feature
const items = await fleekSdk.storage().list();

# Get by CID
const item = await fleekSdk.storage().get({ cid });

Learn more about Storage and feature coverage by reading the SDK’s Storage documentation here.