Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions src/api/app.ts
Original file line number Diff line number Diff line change
@@ -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<Array<App>>(`${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<string>(`${baseURL}/create${subdomainStr}`, {}, { auth })
return data
}
1 change: 1 addition & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './ipfs'
export * from './user'
export * from './app'
13 changes: 11 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -86,4 +88,11 @@ export class FissionUser extends Fission {
async verify(): Promise<Boolean> {
return verify(this.auth, this.baseURL)
}

async listApps(): Promise<Array<App>> {
return listApps(this.auth, this.baseURL)
}
async createApp(subDomain: string): Promise<string> {
return createApp(subDomain, this.auth, this.baseURL)
}
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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 }]
})
})