Browse Source

more on types i think

tags/v1.0.0-alpha.0
ojizero 1 year ago
parent
commit
d32657ed18
No account linked to committer's email address
3 changed files with 20 additions and 8 deletions
  1. 1
    1
      package.json
  2. 12
    5
      src/client.ts
  3. 7
    2
      src/index.ts

+ 1
- 1
package.json View File

@@ -2,7 +2,7 @@
"name": "@ojizero/portal",
"version": "1.0.0-alpha.0",
"description": "HTTP API clients ... simplified.",
"main": "dist/index.js",
"main": "lib/index.js",
"publishConfig": {
"access": "public"
},

+ 12
- 5
src/client.ts View File

@@ -1,13 +1,14 @@
import got, { GotFn } from 'got'
import got from 'got'
import querystring from 'querystring'
import { IncomingHttpHeaders } from 'http';
import { OutgoingHttpHeaders } from 'http'
import defaultsDeep from 'lodash.defaultsdeep'
import { RequestOptions } from 'https';

export enum AuthenticationTypes {
BasicAuth = 'basic',
TokenAuth = 'token',
ApiKeyAuth = 'key',
// TokenAuth = 'token',
// ApiKeyAuth = 'key',
BearerAuth = 'bearer',
}

@@ -50,15 +51,21 @@ export interface Config {
onError?: 'reject' | 'resolve',
}

export type RawResponse = got.Response<any>

export type ClientFn = (options: RequestOptions) => Promise<RawResponse>

// export type RequestOptions = Config & RequestConfig // TODO:

export interface Client {
request (method: string, path: string, payload: {}, options: any): Promise<Response>
}

export class PortalClient implements Client {
client: GotFn
client: ClientFn
config: Config

constructor (client: GotFn, config: Config) {
constructor (client: ClientFn, config: Config) {
this.client = client
this.config = config
}

+ 7
- 2
src/index.ts View File

@@ -11,7 +11,7 @@ export interface Portal {
_client: Client,
}

export function createBaseClient (config: Config): Portal {
export function createPortalClient (config: Config): Portal {
const client = new PortalClient(got, config)

const portal: Portal = {
@@ -26,4 +26,9 @@ export function createBaseClient (config: Config): Portal {
export { Client } from './client'
export { MethodSpec } from './method'

export default createBaseClient
// Can't a the moment run export { * as Joi } from 'joi'
// so this clumsy way is the solution re-export
import * as Joi from 'joi'
export { Joi }

export default createPortalClient

Loading…
Cancel
Save