GithubHelp home page GithubHelp logo

samhatem / outpost-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from outpostprotocol/outpost-sdk

0.0 0.0 0.0 446 KB

๐Ÿ“จ ๐Ÿš€ The official JavaScript client SDK for the Outpost Protocol.

License: MIT License

TypeScript 100.00%

outpost-sdk's Introduction

outpost-sdk

๐Ÿ“จ ๐Ÿš€ The official JavaScript client SDK for the Outpost Protocol.

Install

npm install outpost-sdk

OR

yarn add outpost-sdk

Usage

Import into your project

const { createClient } = require('outpost-sdk')

Or with es6

import { createClient } from 'outpost-sdk'

Methods

createClient

Create an outpost client. Returns the methods available in the SDK.

const createClient = (options: createClientParams = defaultOptions): createClientResult

The result:

type createClientResult = {
  readonly getAllCommunities: () => Promise<readonly Community[]>;
  readonly getPosts: (params: getPostsParams) => Promise<getPostsResult>;
  readonly getChallenge: (
    params: getChallengeParams
  ) => Promise<getChallengeResult>;
  readonly getAuthToken: (
    params: getAuthTokenParams
  ) => Promise<getAuthTokenResult>;
  readonly getPostPreview: (
    params: getPostPreviewParams
  ) => Promise<getPostPreviewResult>;
  readonly uploadImage: (
    params: uploadImageParams
  ) => Promise<uploadImageResult>;
  readonly uploadPost: (params: uploadPostParams) => Promise<uploadPostResult>;
  readonly uploadComment: (
    params: uploadCommentParams
  ) => Promise<uploadCommentResult>;
  readonly getPost: (params: getPostParams) => Promise<getPostResult>;
};

getChallenge

Get a challenge from the outpost server so that it can verify a user owns their Ethereum address. Returns a string that the user must sign and send back to the server in getAuthToken.

getChallenge: (params: getChallengeParams) => Promise<getChallengeResult>

type getChallengeParams = { readonly address: string; };

type getChallengeResult = string;

getAuthToken

Get an authentication token to be able to access authenticated routes. Returns the users authentication token.

getAuthToken: (params: getAuthTokenParams) => Promise<getAuthTokenResult>;

type getAuthTokenParams = {
  readonly address: string;
  readonly signature: string;
};

type getAuthTokenResult = string;

getPosts

List all the posts of a specified community. Returns an array of posts.

getPosts: (params: getPostsParams) => Promise<getPostsResult>;

type getPostsParams = { readonly slug: string; };

type getPostsResult = readonly Post[];

type Post = {
  readonly id: string;
  readonly title: string;
  readonly subtitle: string;
  readonly timestamp: number;
  readonly txId: string;
  readonly featuredImg: string;
};

getPostPreview

Get the preview for a post.

getPostPreview: (params: getPostPreviewParams) => Promise<getPostPreviewResult>;

export type getPostPreviewParams = { readonly txId: string; };

type getPostPreviewResult = {
  readonly id: string;
  readonly title: string;
  readonly subtitle: string;
  readonly timestamp: number;
  readonly txId: string;
  readonly featuredImg: string | null;
  readonly canonicalLink: string;
};

uploadImage

Upload a base64 representation of an image file to arweave. Returns the transaction id of the upload.

uploadImage: (params: uploadImageParams) => Promise<uploadImageResult>;

type uploadImageParams = {
  readonly base64: string;
  readonly authToken: string;
};
type uploadImageResult = {
  readonly txId: string;
  readonly gateway: string;
};

Now you can view the image at

`https://${gateway}/${txId}`

Note: The gateway returned is the host of the gateway the image was uploaded to (i.e. 'arweave.net'). Transactions take about 2 minutes to be included in a block but Arweave's gateways ('arweave.net' and 'arweave.dev') optimistically store the transaction so it can be served immediately.

uploadPost

Upload a post to arweave.

uploadPost: (params: uploadPostParams) => Promise<uploadPostResult>;

type uploadPostParams = {
  readonly authToken: string;
  readonly communityTxId: string;
  readonly postUpload: {
    readonly canonicalLink: string;
    readonly postText: string;
    readonly subtitle: string;
    readonly timestamp: number;
    readonly title: string;
  };
};
type uploadPostResult = {
  readonly txId: string;
  readonly title: string;
  readonly postText: string;
  readonly subtitle: string;
  readonly timestamp: number;
  readonly canonicalLink: string;
  readonly community: {
    readonly name: string;
  };
  readonly user: {
    readonly address: string;
  };
};

getPost

Get a post.

uploadPost: (params: uploadPostParams) => Promise<uploadPostResult>;

type getPostParams = {
  readonly txId: string;
  readonly authToken: string;
};

getAllCommunities

Get all the publications (a.k.a. communities).

getAllCommunities: () => Promise<readonly Community[]>;

outpost-sdk's People

Contributors

cawfree avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.