Skip to content

Commit

Permalink
Merge pull request #9 from lifeomic/fix-typings-and-allow-default-export
Browse files Browse the repository at this point in the history
fix typings and allow default export
  • Loading branch information
0xch4z committed Aug 9, 2019
2 parents ba2a6db + 07013ae commit 8da3763
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
44 changes: 26 additions & 18 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { AxiosInstance } from 'axios';

export interface Client {
declare interface AppOptions {
readonly slug: string;
}

declare interface Client {
app(options: AppOptions): App;
}

declare interface App {
readonly app: { slug: string };

/**
Expand All @@ -12,52 +20,50 @@ export interface Client {
triggerBuild(buildParams?: BuildOptions): Promise<Build>;
}

export interface AbortOptions {
declare interface AbortOptions {
readonly reason?: string;
readonly withSuccess?: boolean;
readonly skipNotifications?: boolean;
}

export interface FollowOptions {
declare interface FollowOptions {
readonly heartbeat?: number;
readonly interval?: number;
}

export interface AbortResponse {
declare interface AbortResponse {
readonly status?: string;
readonly message?: string;
}

export interface BuildDescription {
declare interface BuildDescription {
readonly abort_reason: string;
readonly branch: string;
readonly build_number: integer;
readonly build_number: number;
readonly commit_hash: string;
readonly commit_message: string;
readonly commit_view_url: string;
readonly environment_prepare_finished_at: string;
readonly finished_at: string;
readonly is_on_hold: boolean;
readonly original_build_params: string;
readonly pull_request_id: integer;
readonly pull_request_id: number;
readonly pull_request_target_branch: string;
readonly pull_request_view_url: string;
readonly slug: string;
readonly stack_config_type: string;
readonly stack_identifier: string;
readonly started_on_worker_at: string;
readonly status: integer;
readonly status: number;
readonly status_text: string;
readonly tag: string;
readonly triggered_at: string;
readonly triggered_by: string;
readonly triggered_workflow: string;
}

export interface Build {
abort(
options?: Pick<AbortOptions, Exclude<AbortOptions, 'reason'>>
): Promise<void>;
declare interface Build {
abort(options?: Omit<AbortOptions, 'reason'>): Promise<void>;
abort(options?: AbortOptions): Promise<AbortResponse>;

describe(): Promise<BuildDescription>;
Expand All @@ -67,19 +73,19 @@ export interface Build {
isFinished(): Promise<Boolean>;
}

export interface CommitPathsFilter {
declare interface CommitPathsFilter {
readonly added?: string[];
readonly modified?: string[];
readonly removed?: string[];
}

export type BuildTargetStrategy =
declare type BuildTargetStrategy =
| { branch: string }
| { commitHash: string }
| { workflow: string }
| { tag: string };

export interface BaseBuildOptions {
declare interface BaseBuildOptions {
readonly branch?: string;
readonly commitHash?: string;
readonly commitMessage?: string;
Expand All @@ -98,10 +104,12 @@ export interface BaseBuildOptions {
readonly target?: string;
}

export type BuildOptions = BaseBuildOptions & BuildTargetStrategy;
declare type BuildOptions = BaseBuildOptions & BuildTargetStrategy;

export interface ClientConfiguration {
declare interface ClientConfiguration {
readonly token: string;
}

export default function createClient(config: ClientConfiguration): Client;
declare function createClient(config: ClientConfiguration): Client;

export = createClient;
4 changes: 3 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const assert = require('assert');
const axios = require('axios');
const axiosRetry = require('axios-retry');

module.exports = ({ token }) => {
const createClient = ({ token }) => {
assert(token, 'An access token is required');

const client = axios.create({
Expand All @@ -17,3 +17,5 @@ module.exports = ({ token }) => {
instance.app = ({ slug }) => app({ client, slug });
return instance;
};

module.exports = createClient;

0 comments on commit 8da3763

Please sign in to comment.