Merge pull request #30865 from runebaas/microservice-utilities

Add Typings for microservice-utilities
This commit is contained in:
Nathan Shively-Sanders
2018-12-17 16:43:14 -08:00
committed by GitHub
4 changed files with 127 additions and 0 deletions

84
types/microservice-utilities/index.d.ts vendored Normal file
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?: { [s: string]: string; }, type?: string): Promise<PlatformClientResponse>;
post(url: string, data: object, headers?: { [s: string]: string; }): Promise<PlatformClientResponse>;
put(url: string, data: object, headers?: { [s: string]: string; }): Promise<PlatformClientResponse>;
patch(url: string, data: object, headers?: { [s: string]: string; }): Promise<PlatformClientResponse>;
delete(url: string, headers?: { [s: string]: string; }): Promise<PlatformClientResponse>;
head(url: string, headers?: { [s: string]: string; }): Promise<PlatformClientResponse>;
options(url: string, headers?: { [s: string]: string; }): 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>;
}

View File

@@ -0,0 +1,17 @@
import { Authorizer, PlatformClient, RequestLogger, ServiceTokenProvider } from 'microservice-utilities';
(async (): Promise<void> => {
const authorizer = new Authorizer((msg: any) => msg, { jwkKeyListUrl: 'aaa' });
const authorizerPolicy = authorizer.getPolicy({ test: true });
const platformClient = new PlatformClient((msg: any) => msg);
const result = await platformClient.get('https://www.typescriptlang.org/');
const data = result.data as string;
platformClient.post('https://www.typescriptlang.org/', { testData: 'abc' });
const serviceTokenProvider = new ServiceTokenProvider(platformClient, {});
const requestLogger = new RequestLogger({ jsonSpace: 4 });
requestLogger.log('hello world');
})();

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"microservice-utilities-tests.ts"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}