1.0.0-alpha.10 • Published 3 years ago

@fleekhq/sdk v1.0.0-alpha.10

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Fleek SDK

Fleek SDK is a javascript library that makes easier to interact with Fleek APIs and Internet Computer.

Installation

Use the npm package manager to install it.

npm install @fleekhq/sdk

It can also be installed through yarn.

yarn add @fleekhq/sdk

Importing

The SDK can be imported using an import statement.

import { Fleek } from '@fleekhq/sdk';

The SDK can also be imported using a require.

const { Fleek } = require('@fleekhq/sdk');

Usage

You can initialise instance only with apiKey, but if you want to leverage asset canister you also need to provide assetCanisterId property.

import { Fleek } from '@fleekhq/sdk';

const sdk = new Fleek({
  apiKey: 'your-api-key', // your Fleek API Key
  assetCanisterId: 'your-asset-canister-id',
});

Methods

IPFS Storage

ipfs()

Returns an instance of the IPFS client. For more information check out https://www.npmjs.com/package/ipfs-http-client.

const ipfs = sdk.ipfs();

Uploading data

await sdk.ipfs().add(...);

Asset Storage

assets()

Returns an instance of the IC storage client

const assetStorage = sdk.assets();

uploading data

await sdk.assets().store(key, data);
await sdk.assets().storeJson(key, { some: 'value' });

assets().get()

const asset = await sdk.assets().get(key);

Returns the asset with the provided key. Returns null if not found.

assets().listAll()

const assets = await sdk.assets().listAll();

Returns a list of all assets. Returns [] if none.

assets().list()

// list images for a specific user
const prefix = `images/${uid}`;
const assets = await sdk.assets().list(prefix);

Returns a list of all assets whose keys start with the provided prefix. Returns [] if none.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.