diff --git a/package-lock.json b/package-lock.json index 6eeb3d1..6f4ac51 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@metacall/protocol", - "version": "0.1.26", + "version": "1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@metacall/protocol", - "version": "0.1.26", + "version": "1", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { @@ -3870,8 +3870,7 @@ "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", - "dev": true, - "requires": {} + "dev": true }, "ajv": { "version": "6.12.6", @@ -6011,4 +6010,4 @@ "dev": true } } -} +} \ No newline at end of file diff --git a/src/deployment.ts b/src/deployment.ts index 47d3eec..58d0a88 100644 --- a/src/deployment.ts +++ b/src/deployment.ts @@ -104,6 +104,30 @@ export interface Deployment { packages: Record; ports: number[]; } +export class IDeployment implements Deployment { + public status: DeployStatus; + public prefix: string; + public suffix: string; + public version: string; + public packages: Record; + public ports: number[]; + + constructor( + status: DeployStatus, + prefix: string, + suffix: string, + version: string, + packages: Record, + ports: number[] + ) { + this.status = status; + this.prefix = prefix; + this.suffix = suffix; + this.version = version; + this.packages = packages; + this.ports = ports; + } +} export interface Create { suffix: string; diff --git a/src/protocol.ts b/src/protocol.ts index 7f3fff6..493ae56 100644 --- a/src/protocol.ts +++ b/src/protocol.ts @@ -50,6 +50,30 @@ export interface Branches { branches: [string]; } +export interface DeployBody { + name: string; + env: { name: string; value: string }[]; + plan: Plans; + resourceType: ResourceType; + release?: string; + version?: string; +} + +export interface DeleteBody { + prefix: string; + suffix: string; + version: string; +} + +export interface FetchFilesFromRepoBody { + branch: string; + url: string; +} + +export interface FetchBranchListBody { + url: string; +} + export interface API { refresh(): Promise; validate(): Promise; @@ -68,19 +92,8 @@ export interface API { branch: string, jsons: MetaCallJSON[] ): Promise; - deploy( - name: string, - env: { name: string; value: string }[], - plan: Plans, - resourceType: ResourceType, - release?: string, - version?: string - ): Promise; - deployDelete( - prefix: string, - suffix: string, - version: string - ): Promise; + deploy(options: DeployBody): Promise; + deployDelete(options: DeleteBody): Promise; logs( container: string, type: LogType, @@ -88,8 +101,8 @@ export interface API { prefix: string, version?: string ): Promise; - branchList(url: string): Promise; - fileList(url: string, branch: string): Promise; + branchList(options: FetchBranchListBody): Promise; + fileList(options: FetchFilesFromRepoBody): Promise; } export default (token: string, baseURL: string): API => { @@ -198,8 +211,9 @@ export default (token: string, baseURL: string): API => { } ) .then((res: AxiosResponse) => res.data as AddResponse), - branchList: (url: string): Promise => - axios + branchList: async (options: FetchBranchListBody): Promise => { + const { url } = options; + return await axios .post( baseURL + '/api/repository/branchlist', { @@ -209,17 +223,19 @@ export default (token: string, baseURL: string): API => { headers: { Authorization: 'jwt ' + token } } ) - .then((res: AxiosResponse) => res.data as Branches), + .then((res: AxiosResponse) => res.data as Branches); + }, - deploy: ( - name: string, - env: { name: string; value: string }[], - plan: Plans, - resourceType: ResourceType, - release: string = Date.now().toString(16), - version = 'v1' - ): Promise => - axios + deploy: async (options: DeployBody): Promise => { + const { + name, + env, + plan, + resourceType, + release = Date.now().toString(16), + version = 'v1' + } = options; + return await axios .post( baseURL + '/api/deploy/create', { @@ -234,14 +250,12 @@ export default (token: string, baseURL: string): API => { headers: { Authorization: 'jwt ' + token } } ) - .then(res => res.data), + .then(res => res.data); + }, - deployDelete: ( - prefix: string, - suffix: string, - version = 'v1' - ): Promise => - axios + deployDelete: async (options: DeleteBody): Promise => { + const { prefix, suffix, version = 'v1' } = options; + return await axios .post( baseURL + '/api/deploy/delete', { @@ -253,8 +267,8 @@ export default (token: string, baseURL: string): API => { headers: { Authorization: 'jwt ' + token } } ) - .then(res => res.data), - + .then(res => res.data); + }, logs: ( container: string, type: LogType = LogType.Deploy, @@ -278,8 +292,11 @@ export default (token: string, baseURL: string): API => { ) .then(res => res.data), - fileList: (url: string, branch: string): Promise => - axios + fileList: async ( + options: FetchFilesFromRepoBody + ): Promise => { + const { url, branch } = options; + return await axios .post<{ [k: string]: string[] }>( baseURL + '/api/repository/filelist', { @@ -290,7 +307,8 @@ export default (token: string, baseURL: string): API => { headers: { Authorization: 'jwt ' + token } } ) - .then(res => res.data['files']) + .then(res => res.data['files']); + } }; return api;