diff --git a/README.md b/README.md index 458afd3..bb3f623 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,38 @@ await updateDNS("QmYwXpFw1QGAWxEnQWFwLuVpdbupaBcEz2DTTRRRsCt9WR", auth) // "username.runfission.com" ``` +`createApp` + +Creates a new app, assigns an initial subdomain, and sets an asset placeholder + +Params: +- subdomain: (string) **required** +- auth: Auth ({username: string, password: string}) **required** +- baseURL: string *defaults to fission web-api at `https://runfission.com`* +Example: +```js +import { createApp } from '@fission-suite/client' +const auth = { username: "username", password: "password" } +await createApp("foo", auth) +// "foo.fission.app" +``` + +`listApps` + +A list of all of your apps and their associated domain names + +Params: +- auth: Auth ({username: string, password: string}) **required** +- baseURL: string *defaults to fission web-api at `https://runfission.com`* +Example: +```js +import { listApps } from '@fission-suite/client' +const auth = { username: "username", password: "password" } +await listApps(auth) +// { "key": "foo.fission.app", "key2": "foo-two.fission.app" } +``` + + ### Fission objects For repeated calls, instantiate a fission object: diff --git a/src/api/app.ts b/src/api/app.ts new file mode 100644 index 0000000..c0b729a --- /dev/null +++ b/src/api/app.ts @@ -0,0 +1,14 @@ +import axios from 'axios' +import { BASE_URL_DEFAULT } from '../constants' +import { Auth, App } from '../types' + +export const listApps = async (auth: Auth, baseURL = BASE_URL_DEFAULT) => { + const { data } = await axios.get>(`${baseURL}/app`, { auth }) + return data +} + +export const createApp = async (subdomain: string, auth: Auth, baseURL = BASE_URL_DEFAULT) => { + const subdomainStr = subdomain ? `?subdomain=${subdomain}` : '' + const { data } = await axios.post(`${baseURL}/create${subdomainStr}`, {}, { auth }) + return data +} diff --git a/src/api/index.ts b/src/api/index.ts index 00a9428..7d5e553 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,2 +1,3 @@ export * from './ipfs' export * from './user' +export * from './app' diff --git a/src/client.ts b/src/client.ts index c58f5f6..8a33846 100644 --- a/src/client.ts +++ b/src/client.ts @@ -8,10 +8,12 @@ import { pin, updateDNS, resetPassword, - verify + verify, + createApp, + listApps } from './api' import { getContentURL, trimBaseURL } from './util' -import { Content, CID, Auth } from './types' +import { Content, CID, Auth, App } from './types' import { BASE_URL_DEFAULT } from './constants' /** @@ -86,4 +88,11 @@ export class FissionUser extends Fission { async verify(): Promise { return verify(this.auth, this.baseURL) } + + async listApps(): Promise> { + return listApps(this.auth, this.baseURL) + } + async createApp(subDomain: string): Promise { + return createApp(subDomain, this.auth, this.baseURL) + } } diff --git a/src/types.ts b/src/types.ts index 3eb6b42..7e5c38b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -5,6 +5,7 @@ export type Upload = JSONValue | File export type CID = string export type Peer = string export type ByteLength = number +export type App = { domain: string } export type Auth = { username: string diff --git a/test/client.test.ts b/test/client.test.ts index 860ab2a..c6f4ff3 100644 --- a/test/client.test.ts +++ b/test/client.test.ts @@ -62,9 +62,9 @@ describe('Fission', () => { expect(fissionDefault.baseURL).toEqual(BASE_URL_DEFAULT) }) - it("removes trailing slashes on provided BASE_URL", () => { - const trailingFission = new Fission("https://example.com/") - expect(trailingFission.baseURL).toEqual("https://example.com") + it('removes trailing slashes on provided BASE_URL', () => { + const trailingFission = new Fission('https://example.com/') + expect(trailingFission.baseURL).toEqual('https://example.com') }) describeRequest({ @@ -213,4 +213,24 @@ describe('FissionUser', () => { expectedUrl: `${TEST_BASE_URL}/dns/${TEST_CID}`, expectedArguments: [{}, { auth: TEST_AUTH }] }) + + describeRequest({ + desc: 'List all apps & their associated domains', + method: 'get', + responseData: { data: { property1: 'foo.example.com', property2: 'foo.example.com' } }, + requestFn: () => fission.listApps(), + expectedReturn: { property1: 'foo.example.com', property2: 'foo.example.com' }, + expectedUrl: `${TEST_BASE_URL}/app`, + expectedArguments: [{ auth: TEST_AUTH }] + }) + + describeRequest({ + desc: 'Create fission app', + method: 'post', + responseData: { data: 'test.runfission.com' }, + requestFn: () => fission.createApp('test'), + expectedReturn: 'test.runfission.com', + expectedUrl: `${TEST_BASE_URL}/create?subdomain=test`, + expectedArguments: [{}, { auth: TEST_AUTH }] + }) })