You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.ts 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import Client from './client'
  2. import method, { MethodFactory } from './method'
  3. import resrouceGenerator, { ResourceFactory } from './resource'
  4. import { URL } from 'url' // TODO: declare it instead of importing it
  5. import got from 'got'
  6. import { OutgoingHttpHeaders } from 'http'
  7. export enum AuthenticationTypes {
  8. BasicAuth = 'basic',
  9. TokenAuth = 'token',
  10. KeyAuth = 'key',
  11. BearerAuth = 'bearer',
  12. }
  13. export type Seconds = number
  14. export type BaseUrl = string | URL
  15. export interface Authentication {
  16. type: AuthenticationTypes,
  17. }
  18. export interface Config {
  19. baseUrl: BaseUrl,
  20. headers?: OutgoingHttpHeaders,
  21. authentication?: Authentication,
  22. retries?: number,
  23. timeout?: Seconds,
  24. onError?: 'reject' | 'resolve',
  25. }
  26. export interface Portal {
  27. route: MethodFactory,
  28. resource: ResourceFactory,
  29. _client: Client,
  30. }
  31. export function createBaseClient (config: Config): Portal {
  32. const client = new Client(got) // TODO:
  33. const portal: Portal = {
  34. route: method(client),
  35. resource: resrouceGenerator(client),
  36. _client: client,
  37. }
  38. return portal
  39. }
  40. export { Client } from './client'
  41. export { MethodSpec } from './method'
  42. export default createBaseClient