Add Typings for microservice-utilities

This commit is contained in:
Daan Boerlage
2018-11-26 19:50:25 +01:00
parent 36a32d8a72
commit 70d843fd2f
4 changed files with 123 additions and 0 deletions
+84
View File
@@ -0,0 +1,84 @@
// Type definitions for microservice-utilities 0.1
// Project: https://github.com/Cimpress-MCP/microservice-utilities.js
// Definitions by: Daan Boerlage <https://github.com/runebaas>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
/**
* Authorizer
*/
export interface AuthorizerConfiguration {
jwkKeyListUrl: string;
authorizerContextResolver?: string;
}
export interface AuthorizerPolicy {
principalId: string;
policyDocument: object;
}
export class Authorizer {
constructor(logFunction: (msg: any) => void, configuration: AuthorizerConfiguration);
getPolicy(request: object): Promise<AuthorizerPolicy>;
}
/**
* PlatformClient
*/
export interface PlatformClientConfiguration {
client: object;
}
export interface PlatformClientResponse {
data?: any;
status: number;
statusText: string;
headers: any;
config: object;
request?: any;
}
export class PlatformClient {
constructor(logFunction: (msg: any) => void, tokenResolverFunction?: Promise<() => string>, configuration?: PlatformClientConfiguration)
get(url: string, headers?: object, type?: string): Promise<PlatformClientResponse>;
post(url: string, data: object, headers?: object): Promise<PlatformClientResponse>;
put(url: string, data: object, headers?: object): Promise<PlatformClientResponse>;
patch(url: string, data: object, headers?: object): Promise<PlatformClientResponse>;
delete(url: string, headers?: object): Promise<PlatformClientResponse>;
head(url: string, headers?: object): Promise<PlatformClientResponse>;
options(url: string, headers?: object): Promise<PlatformClientResponse>;
}
/**
* RequestLogger
*/
export interface RequestLoggerConfiguration {
logFunction?: (msg: any) => void;
extendErrorObjects?: boolean;
jsonSpace?: number;
}
export class RequestLogger {
constructor(configuration?: RequestLoggerConfiguration);
log(msg: any): void;
}
/**
* ServiceTokenProvider
*/
export interface ServiceTokenProviderConfiguration {
clientId: string;
encryptedClientSecret: string;
audience: string;
tokenEndpoint: string;
}
export class ServiceTokenProvider {
constructor(httpClient: object, kmsClient: object, configuration?: ServiceTokenProviderConfiguration);
getToken(): Promise<string>;
getTokenWithoutCache(): Promise<string>;
}
@@ -0,0 +1,13 @@
import { Authorizer, PlatformClient, RequestLogger, ServiceTokenProvider } from 'microservice-utilities';
const authorizer = new Authorizer((msg: any) => msg, {jwkKeyListUrl: 'aaa'});
const authorizerPolicy = authorizer.getPolicy({test: true});
const platformClient = new PlatformClient((msg: any) => msg);
platformClient.get('https://www.typescriptlang.org/');
platformClient.post('https://www.typescriptlang.org/', {testData: 'abc'});
const serviceTokenProvider = new ServiceTokenProvider(platformClient, {});
const requestLogger = new RequestLogger({jsonSpace: 4});
requestLogger.log('hello world');
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": false,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"microservice-utilities-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}