import * as url from 'url'; declare namespace com.faberoh.order.api.v0.enums { type CreditCardBrand = 'visa' | 'mastercard' | 'amex'; type OrderStatus = 'open' | 'submitted' | 'processed' | 'shipped' | 'cancelled' | 'returned'; } declare namespace com.faberoh.order.api.v0.models { interface Address { readonly 'first_name': string; readonly 'last_name': string; readonly 'line1': string; readonly 'line2'?: string; readonly 'zip': string; readonly 'city': string; readonly 'state': string; readonly 'country_code': string; } interface CreditCard { readonly 'number': string; readonly 'expiration_month': number; readonly 'expiration_year': number; readonly 'security_code': string; readonly 'brand': com.faberoh.order.api.v0.enums.CreditCardBrand; readonly 'holder_name': string; } interface Item { readonly 'upc': string; readonly 'quantity': number; } interface Order { readonly 'id': string; readonly 'user': com.faberoh.order.api.v0.models.User; readonly 'status': com.faberoh.order.api.v0.enums.OrderStatus; readonly 'items': com.faberoh.order.api.v0.models.Item[]; readonly 'billing_address': com.faberoh.order.api.v0.models.Address; readonly 'shipping_address': com.faberoh.order.api.v0.models.Address; readonly 'credit_card': com.faberoh.order.api.v0.models.CreditCard; readonly 'summary': com.faberoh.order.api.v0.models.OrderSummary; } interface OrderSummary { readonly 'items_total': number; readonly 'shipping_charge': number; readonly 'taxes': number; readonly 'total': number; } interface User { readonly 'id': string; readonly 'email': string; } } export type Address = com.faberoh.order.api.v0.models.Address; export type CreditCard = com.faberoh.order.api.v0.models.CreditCard; export type CreditCardBrand = com.faberoh.order.api.v0.enums.CreditCardBrand; export type Item = com.faberoh.order.api.v0.models.Item; export type Order = com.faberoh.order.api.v0.models.Order; export type OrderStatus = com.faberoh.order.api.v0.enums.OrderStatus; export type OrderSummary = com.faberoh.order.api.v0.models.OrderSummary; export type User = com.faberoh.order.api.v0.models.User; export interface $FetchOptions { body?: string; headers?: $HttpHeaders; method?: $HttpMethod; } export type $FetchFunction = (url: string, options?: $FetchOptions) => Promise; export interface $HttpHeaders { [key: string]: string; } export type $HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'CONNECT' | 'OPTIONS' | 'TRACE'; export interface $HttpQuery { [key: string]: string | number | boolean | string[] | number[] | boolean[] | undefined | null; } export interface $HttpRequest { body?: any; url: string; headers: $HttpHeaders; method: $HttpMethod; } export interface $HttpRequestOptions { body?: any; endpoint: string; headers?: $HttpHeaders; method: $HttpMethod; query?: $HttpQuery; } export interface $HttpResponse { body: B; headers: $HttpHeaders; ok: O; request: $HttpRequest; status: S; statusText: string; } export type $HttpContinue = $HttpResponse; export type $HttpSwitchingProtocol = $HttpResponse; export type $HttpProcessing = $HttpResponse; export type $HttpOk = $HttpResponse; export type $HttpCreated = $HttpResponse; export type $HttpAccepted = $HttpResponse; export type $HttpNonAuthoritativeInformation = $HttpResponse; export type $HttpNoContent = $HttpResponse; export type $HttpResetContent = $HttpResponse; export type $HttpPartialContent = $HttpResponse; export type $HttpMultiStatus = $HttpResponse; export type $HttpAlreadyReported = $HttpResponse; export type $HttpImUsed = $HttpResponse; export type $HttpMultipleChoices = $HttpResponse; export type $HttpMovedPermanently = $HttpResponse; export type $HttpFound = $HttpResponse; export type $HttpSeeOther = $HttpResponse; export type $HttpNotModified = $HttpResponse; export type $HttpUseProxy = $HttpResponse; export type $HttpTemporaryRedirect = $HttpResponse; export type $HttpPermanentRedirect = $HttpResponse; export type $HttpBadRequest = $HttpResponse; export type $HttpUnauthorized = $HttpResponse; export type $HttpPaymentRequired = $HttpResponse; export type $HttpForbidden = $HttpResponse; export type $HttpNotFound = $HttpResponse; export type $HttpMethodNotAllowed = $HttpResponse; export type $HttpNotAcceptable = $HttpResponse; export type $HttpProxyAuthenticationRequired = $HttpResponse; export type $HttpRequestTimeout = $HttpResponse; export type $HttpConflict = $HttpResponse; export type $HttpGone = $HttpResponse; export type $HttpLengthRequired = $HttpResponse; export type $HttpPreconditionFailed = $HttpResponse; export type $HttpRequestEntityTooLarge = $HttpResponse; export type $HttpRequestUriTooLong = $HttpResponse; export type $HttpUnsupportedMediaType = $HttpResponse; export type $HttpRequestedRangeNotSatisfiable = $HttpResponse; export type $HttpExpectationFailed = $HttpResponse; export type $HttpMisdirectedRequest = $HttpResponse; export type $HttpUnprocessableEntity = $HttpResponse; export type $HttpLocked = $HttpResponse; export type $HttpFailedDependency = $HttpResponse; export type $HttpUpgradeRequired = $HttpResponse; export type $HttpPreconditionRequired = $HttpResponse; export type $HttpTooManyRequests = $HttpResponse; export type $HttpRequestHeaderFieldsTooLarge = $HttpResponse; export type $HttpNoResponse = $HttpResponse; export type $HttpRetryWith = $HttpResponse; export type $HttpBlockedByWindowsParentalControls = $HttpResponse; export type $HttpUnavailableForLegalReasons = $HttpResponse; export type $HttpClientClosedRequest = $HttpResponse; export type $HttpInternalServerError = $HttpResponse; export type $HttpNotImplemented = $HttpResponse; export type $HttpBadGateway = $HttpResponse; export type $HttpServiceUnavailable = $HttpResponse; export type $HttpGatewayTimeout = $HttpResponse; export type $HttpHttpVersionNotSupported = $HttpResponse; export type $HttpInsufficientStorage = $HttpResponse; export type $HttpLoopDetected = $HttpResponse; export type $HttpBandwidthLimitExceeded = $HttpResponse; export type $HttpNotExtended = $HttpResponse; export type $HttpNetworkAuthenticationRequired = $HttpResponse; export type $HttpNetworkReadTimeoutError = $HttpResponse; export type $HttpNetworkConnectTimeoutError = $HttpResponse; export interface $HttpClientOptions { fetch: $FetchFunction; } export function isResponseEmpty(response: Response): boolean { const contentLength = response.headers.get('Content-Length'); return response.status === 204 || contentLength != null && Number.parseInt(contentLength, 10) === 0; } export function isResponseJson(response: Response): boolean { const contentType = response.headers.get('Content-Type'); return contentType != null && contentType.indexOf('json') >= 0; } export function parseJson(response: Response): Promise { return !isResponseEmpty(response) && isResponseJson(response) ? response.json() : Promise.resolve(); } export function parseHeaders(response: Response): Record { const headers: Record = {}; response.headers.forEach((value, key) => { headers[key.toLowerCase()] = value; }); return headers; } export function stripQuery(query: $HttpQuery = {}): $HttpQuery { const initialValue: $HttpQuery = {}; return Object.keys(query).reduce((previousValue, key) => { const value = query[key]; if (value != null) previousValue[key] = value; return previousValue; }, initialValue); } export class $HttpClient { private options: $HttpClientOptions; constructor(options: $HttpClientOptions) { this.options = options; } public request(options: $HttpRequestOptions): Promise<$HttpResponse> { const finalUrl: string = url.format({ hostname: 'localhost', pathname: options.endpoint, protocol: 'http:', query: stripQuery(options.query), port: '8080', }); const finalHeaders: $HttpHeaders = { accept: 'application/json', 'content-type': 'application/json', ...options.headers, }; const request: $HttpRequest = { body: options.body, headers: finalHeaders, method: options.method, url: finalUrl, }; return this.options.fetch(request.url, { body: JSON.stringify(request.body), headers: request.headers, method: request.method, }).then((response) => { return parseJson(response).then((json) => { return { body: json, headers: parseHeaders(response), ok: response.ok, request, status: response.status, statusText: response.statusText, }; }); }); } } export class $Resource { protected client: $HttpClient; constructor(options: $HttpClientOptions) { this.client = new $HttpClient(options); } } export interface OrdersGetByOrderIdParameters { headers?: $HttpHeaders; /*The id of the order to retrieve.*/ order_id: string; } export interface OrdersPostParameters { /*The order to be submitted.*/ body: com.faberoh.order.api.v0.models.Order; headers?: $HttpHeaders; } export type OrdersGetByOrderIdResponse = $HttpOk | $HttpNotFound; export type OrdersPostResponse = $HttpCreated | $HttpBadRequest; export class OrdersResource extends $Resource { /*Get an order by ID.*/ public getByOrderId(params: OrdersGetByOrderIdParameters): Promise { return this.client.request({ endpoint: `/orders/${encodeURIComponent(params.order_id)}`, headers: params.headers, method: 'GET', }); } /*Create (submit) an order.*/ public post(params: OrdersPostParameters): Promise { return this.client.request({ body: params.body, endpoint: '/orders', headers: params.headers, method: 'POST', }); } } export interface ClientInstance { orders: OrdersResource; } export function createClient(options: $HttpClientOptions): ClientInstance { return { orders: new OrdersResource(options), }; }