import * as url from 'url'; declare namespace com.hbc.api.fraud.v0.enums { type Banner = 'lat' | 's5a' | 'o5a' | 'bay'; type CustomerType = 'guest' | 'registered' | 'employee'; type RecommendationCode = 'reject' | 'review' | 'accept'; } declare namespace com.hbc.api.fraud.v0.models { interface AdditionalData { readonly 'inAuthId': string; } interface Address { readonly 'name': string; readonly 'streetLineOne': string; readonly 'streetLineTwo'?: string; readonly 'city': string; readonly 'state': string; readonly 'zip': string; readonly 'country': string; } interface CreditCard { readonly 'nameOnCard': string; readonly 'billingAddress': com.hbc.api.fraud.v0.models.Address; readonly 'cardType': string; readonly 'cardNumber': string; readonly 'authorizedAmount': number; readonly 'fullAmount': number; readonly 'expiryDate': string; readonly 'authCode': string; readonly 'responseCode': number; readonly 'merchantId'?: number; readonly 'registerNumber'?: string; readonly 'transactionNumber': string; readonly 'avsResponse': string; } interface Customer { readonly 'customerType': com.hbc.api.fraud.v0.enums.CustomerType; readonly 'accountId': string; readonly 'creationDate': string; readonly 'firstName': string; readonly 'lastName': string; readonly 'emailAddress': string; } interface DbRecord { readonly 'transactionId': string; readonly 'lastModifiedDate'?: string; readonly 'createdDate'?: string; readonly 'transaction': com.hbc.api.fraud.v0.models.Transaction; readonly 'decision': com.hbc.api.fraud.v0.models.Decision; } interface Decision { readonly 'transactionId': string; readonly 'recommendationCode': com.hbc.api.fraud.v0.enums.RecommendationCode; readonly 'crossReference'?: string; readonly 'rulesTripped'?: string; readonly 'totalScore': number; readonly 'remarks'?: string; } interface Error { readonly 'message': string; readonly 'error': string; } interface Item { readonly 'svsNumber': number; readonly 'skuNumber': number; readonly 'upcNumber'?: number; readonly 'classNumber'?: number; readonly 'color'?: string; readonly 'size'?: string; readonly 'currentStatus': string; readonly 'department': number; readonly 'signOnDelivery'?: string; readonly 'giftWrapped'?: boolean; readonly 'costAmount'?: number; readonly 'marginAmount'?: number; readonly 'description': string; readonly 'price': number; readonly 'extendedPrice': number; readonly 'quantity': number; readonly 'groupNumber': number; readonly 'shippingAddress': com.hbc.api.fraud.v0.models.Address; readonly 'shippingMethod': string; readonly 'shippingCountry': string; } interface Promo { readonly 'promotionCode': string; readonly 'promotionAmount': number; } interface Transaction { readonly 'orderId': string; readonly 'groupId': string; readonly 'orderTotal': number; readonly 'shippingCost': number; readonly 'currencyCode': string; readonly 'storeNumber': number; readonly 'salesRep'?: string; readonly 'lastModifiedDate'?: string; readonly 'banner': com.hbc.api.fraud.v0.enums.Banner; readonly 'creditCard': com.hbc.api.fraud.v0.models.CreditCard; readonly 'promos'?: com.hbc.api.fraud.v0.models.Promo[]; readonly 'items': com.hbc.api.fraud.v0.models.Item[]; readonly 'ipAddress'?: string; readonly 'source': string; readonly 'customer': com.hbc.api.fraud.v0.models.Customer; readonly 'additionalData'?: com.hbc.api.fraud.v0.models.AdditionalData; } } export type AdditionalData = com.hbc.api.fraud.v0.models.AdditionalData; export type Address = com.hbc.api.fraud.v0.models.Address; export type Banner = com.hbc.api.fraud.v0.enums.Banner; export type CreditCard = com.hbc.api.fraud.v0.models.CreditCard; export type Customer = com.hbc.api.fraud.v0.models.Customer; export type CustomerType = com.hbc.api.fraud.v0.enums.CustomerType; export type DbRecord = com.hbc.api.fraud.v0.models.DbRecord; export type Decision = com.hbc.api.fraud.v0.models.Decision; export type Error = com.hbc.api.fraud.v0.models.Error; export type Item = com.hbc.api.fraud.v0.models.Item; export type Promo = com.hbc.api.fraud.v0.models.Promo; export type RecommendationCode = com.hbc.api.fraud.v0.enums.RecommendationCode; export type Transaction = com.hbc.api.fraud.v0.models.Transaction; 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: 'fraud-frozone', pathname: options.endpoint, protocol: 'http:', query: stripQuery(options.query), }); 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 DecisionsPostParameters { body: com.hbc.api.fraud.v0.models.Decision; headers?: $HttpHeaders; } export interface TransactionsPostParameters { body: com.hbc.api.fraud.v0.models.Transaction; headers?: $HttpHeaders; } export type DecisionsPostResponse = $HttpOk | $HttpBadRequest; export type TransactionsPostResponse = $HttpOk | $HttpBadRequest; export class DecisionsResource extends $Resource { /*Consumes the decision about a transaction (usually meant for manual review) and triggers OMS to process/cancel the order*/ public post(params: DecisionsPostParameters): Promise { return this.client.request({ body: params.body, endpoint: '/decision', headers: params.headers, method: 'POST', }); } } export class TransactionsResource extends $Resource { /*Provides decision about a transaction by supplying order or other information*/ public post(params: TransactionsPostParameters): Promise { return this.client.request({ body: params.body, endpoint: '/transaction', headers: params.headers, method: 'POST', }); } } export interface ClientInstance { decisions: DecisionsResource; transactions: TransactionsResource; } export function createClient(options: $HttpClientOptions): ClientInstance { return { decisions: new DecisionsResource(options), transactions: new TransactionsResource(options), }; }