feathers-shippo
Version:
A Feathers JS adapter for the Shippo API
87 lines (86 loc) • 2.98 kB
TypeScript
import Bottleneck from 'bottleneck';
import { Application } from '@feathersjs/feathers';
import { AxiosInstance } from 'axios';
export type App = Application;
export interface Limiters {
create?: Bottleneck;
update?: Bottleneck;
get?: Bottleneck;
find?: Bottleneck;
remove?: Bottleneck;
}
export interface Resource {
create: (data: Data, params?: Params) => Promise<any>;
update: (id: ID, data: Data, params?: Params) => Promise<any>;
get: (id: ID, params?: Params) => Promise<any>;
find: (params?: Params) => Promise<any>;
remove: (id: ID, params?: Params) => Promise<any>;
}
export interface ServiceOptions {
token: string;
path: string;
methods: Array<ServiceMethod>;
limiters?: null | false | Limiters;
}
export type ServiceMethod = 'create' | 'get' | 'find' | 'update' | 'patch' | 'remove';
export type ID = string;
export interface Data {
[key: string]: any;
}
export interface Params {
[key: string]: any;
query?: {
[key: string]: any;
results?: number;
page?: number;
};
}
export interface PaginatedResult {
total: number;
next: string | null;
previous: string | null;
data: [];
}
export interface Result {
[key: string]: any;
}
export declare const calcMinTime: (perMinute: number) => number;
export declare const shippoLimiter: (method: ServiceMethod, minTimes: any) => Bottleneck;
export declare const shippoLimiters: (token: string) => {
create: Bottleneck;
update: Bottleneck;
get: Bottleneck;
find: Bottleneck;
remove: Bottleneck;
};
export declare const axiosOpts: (params?: Params) => {
params: {
[key: string]: any;
results?: number | undefined;
page?: number | undefined;
} | undefined;
};
export declare const shippo: (token: string) => AxiosInstance;
export declare class ShippoService {
options: ServiceOptions;
app: App;
shippo: AxiosInstance;
resource: Resource;
constructor(options: ServiceOptions, app: App);
handleError(error: any, params?: Params): void;
handleMethod(method: ServiceMethod): void;
handleResult(result: any, params?: Params): any;
schedule(method: 'create' | 'update' | 'get' | 'find' | 'remove', fn: () => Promise<any>): any;
_create(data: Data, params?: Params): Promise<Result>;
create(data: Data, params?: Params): Promise<Result>;
_get(id: ID, params?: Params): Promise<Result>;
get(id: ID, params?: Params): Promise<Result>;
_find(params?: Params): Promise<PaginatedResult>;
find(params?: Params): Promise<PaginatedResult>;
_update(id: ID, data: Data, params?: Params): Promise<Result>;
update(id: ID, data: Data, params?: Params): Promise<Result>;
_patch(id: ID, data: Data, params?: Params): Promise<Result>;
patch(id: ID, data: Data, params?: Params): Promise<Result>;
_remove(id: ID, params?: Params): Promise<Result>;
remove(id: ID, params?: Params): Promise<Result>;
}