Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix typings and allow default export #9

Merged
merged 2 commits into from
Aug 9, 2019
Merged
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
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;