import * as url from 'url'; declare namespace com.teambytes.hipchat.sns.bridge.v0.enums { type HipchatScope = 'send_message' | 'send_notification'; } declare namespace com.teambytes.hipchat.sns.bridge.v0.models { interface Error { readonly 'description': string; } interface HipchatApiConsumer { readonly 'scopes': com.teambytes.hipchat.sns.bridge.v0.enums.HipchatScope[]; readonly 'fromName'?: string; } interface HipchatCapabilities { readonly 'configurable'?: com.teambytes.hipchat.sns.bridge.v0.models.HipchatConfigurationPage; readonly 'hipchatApiConsumer'?: com.teambytes.hipchat.sns.bridge.v0.models.HipchatApiConsumer; readonly 'installable'?: com.teambytes.hipchat.sns.bridge.v0.models.HipchatInstallable; readonly 'oauth2Provider'?: com.teambytes.hipchat.sns.bridge.v0.models.HipchatOauth2Provider; } interface HipchatCapabilitiesDescriptor { readonly 'name': string; readonly 'description': string; readonly 'key': string; readonly 'apiVersion'?: string; readonly 'capabilities'?: com.teambytes.hipchat.sns.bridge.v0.models.HipchatCapabilities; readonly 'links': com.teambytes.hipchat.sns.bridge.v0.models.HipchatLinks; readonly 'vendor'?: com.teambytes.hipchat.sns.bridge.v0.models.HipchatVendor; } interface HipchatConfigurationPage { readonly 'allowAccessToRoomAdmins'?: string; readonly 'url': string; } interface HipchatInstallData { readonly 'capabilitiesUrl': string; readonly 'oauthId': string; readonly 'oauthSecret': string; readonly 'groupId': number; readonly 'roomId'?: string; } interface HipchatInstallable { readonly 'callbackUrl'?: string; readonly 'installedUrl'?: string; readonly 'allowGlobal'?: boolean; readonly 'allowRoom'?: boolean; } interface HipchatLinks { readonly 'homepage'?: string; readonly 'api'?: string; readonly 'self': string; } interface HipchatOauth2Provider { readonly 'tokenUrl'?: string; readonly 'authorizationUrl'?: string; } interface HipchatVendor { readonly 'name': string; readonly 'url': string; } interface ServiceInfo { readonly 'name': string; readonly 'version': string; readonly 'scala_version': string; readonly 'sbt_version': string; readonly 'build_time': string; } interface SnsNotification { readonly 'Type': string; readonly 'MessageId': string; readonly 'TopicArn': string; readonly 'Message': string; readonly 'Timestamp': string; readonly 'SignatureVersion': string; readonly 'Signature': string; readonly 'SigningCertURL': string; readonly 'Token'?: string; readonly 'Subject'?: string; readonly 'SubscribeURL'?: string; readonly 'UnsubscribeURL'?: string; } } export type Error = com.teambytes.hipchat.sns.bridge.v0.models.Error; export type HipchatApiConsumer = com.teambytes.hipchat.sns.bridge.v0.models.HipchatApiConsumer; export type HipchatCapabilities = com.teambytes.hipchat.sns.bridge.v0.models.HipchatCapabilities; export type HipchatCapabilitiesDescriptor = com.teambytes.hipchat.sns.bridge.v0.models.HipchatCapabilitiesDescriptor; export type HipchatConfigurationPage = com.teambytes.hipchat.sns.bridge.v0.models.HipchatConfigurationPage; export type HipchatInstallData = com.teambytes.hipchat.sns.bridge.v0.models.HipchatInstallData; export type HipchatInstallable = com.teambytes.hipchat.sns.bridge.v0.models.HipchatInstallable; export type HipchatLinks = com.teambytes.hipchat.sns.bridge.v0.models.HipchatLinks; export type HipchatOauth2Provider = com.teambytes.hipchat.sns.bridge.v0.models.HipchatOauth2Provider; export type HipchatScope = com.teambytes.hipchat.sns.bridge.v0.enums.HipchatScope; export type HipchatVendor = com.teambytes.hipchat.sns.bridge.v0.models.HipchatVendor; export type ServiceInfo = com.teambytes.hipchat.sns.bridge.v0.models.ServiceInfo; export type SnsNotification = com.teambytes.hipchat.sns.bridge.v0.models.SnsNotification; 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: 'hipchat-sns-bridge.common.giltaws.com', 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 HipchatCapabilitiesDescriptorsGetParameters { headers?: $HttpHeaders; /*Whether to redirect to Hipchat install with Base64 encoded data.*/ redirect_to_hipchat_install?: boolean; } export interface HipchatInstallDataGetParameters { headers?: $HttpHeaders; installable_url: string; redirect_url: string; } export interface HipchatInstallDataPostParameters { body: com.teambytes.hipchat.sns.bridge.v0.models.HipchatInstallData; headers?: $HttpHeaders; } export interface HipchatInstallDataDeleteByOauthIdParameters { headers?: $HttpHeaders; oauthId: string; } export interface ServiceInfoGetParameters { headers?: $HttpHeaders; } export interface SnsNotificationsPostParameters { body: com.teambytes.hipchat.sns.bridge.v0.models.SnsNotification; headers?: $HttpHeaders; roomId: string; } export type HipchatCapabilitiesDescriptorsGetResponse = $HttpOk; export type HipchatInstallDataGetResponse = $HttpOk; export type HipchatInstallDataPostResponse = $HttpOk; export type HipchatInstallDataDeleteByOauthIdResponse = $HttpOk; export type ServiceInfoGetResponse = $HttpOk; export type SnsNotificationsPostResponse = $HttpOk; export class HipchatCapabilitiesDescriptorsResource extends $Resource { public get(params: HipchatCapabilitiesDescriptorsGetParameters): Promise { return this.client.request({ endpoint: '/hipchat/capabilities', headers: params.headers, method: 'GET', query: { redirect_to_hipchat_install: params.redirect_to_hipchat_install, }, }); } } export class HipchatInstallDataResource extends $Resource { public get(params: HipchatInstallDataGetParameters): Promise { return this.client.request({ endpoint: '/hipchat/installable', headers: params.headers, method: 'GET', query: { installable_url: params.installable_url, redirect_url: params.redirect_url, }, }); } public post(params: HipchatInstallDataPostParameters): Promise { return this.client.request({ body: params.body, endpoint: '/hipchat/installable', headers: params.headers, method: 'POST', }); } public deleteByOauthId(params: HipchatInstallDataDeleteByOauthIdParameters): Promise { return this.client.request({ endpoint: `/hipchat/installable/${encodeURIComponent(params.oauthId)}`, headers: params.headers, method: 'DELETE', }); } } export class ServiceInfoResource extends $Resource { public get(params: ServiceInfoGetParameters = {}): Promise { return this.client.request({ endpoint: '/info', headers: params.headers, method: 'GET', }); } } export class SnsNotificationsResource extends $Resource { public post(params: SnsNotificationsPostParameters): Promise { return this.client.request({ body: params.body, endpoint: `/hipchat/room/${encodeURIComponent(params.roomId)}/notification`, headers: params.headers, method: 'POST', }); } } export interface ClientInstance { hipchatCapabilitiesDescriptors: HipchatCapabilitiesDescriptorsResource; hipchatInstallData: HipchatInstallDataResource; serviceInfo: ServiceInfoResource; snsNotifications: SnsNotificationsResource; } export function createClient(options: $HttpClientOptions): ClientInstance { return { hipchatCapabilitiesDescriptors: new HipchatCapabilitiesDescriptorsResource(options), hipchatInstallData: new HipchatInstallDataResource(options), serviceInfo: new ServiceInfoResource(options), snsNotifications: new SnsNotificationsResource(options), }; }