diff --git a/types/microservice-utilities/index.d.ts b/types/microservice-utilities/index.d.ts new file mode 100644 index 0000000000..7b2c4be923 --- /dev/null +++ b/types/microservice-utilities/index.d.ts @@ -0,0 +1,84 @@ +// Type definitions for microservice-utilities 0.1 +// Project: https://github.com/Cimpress-MCP/microservice-utilities.js +// Definitions by: Daan Boerlage +// 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; +} + +/** + * 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; + post(url: string, data: object, headers?: { [s: string]: string; }): Promise; + put(url: string, data: object, headers?: { [s: string]: string; }): Promise; + patch(url: string, data: object, headers?: { [s: string]: string; }): Promise; + delete(url: string, headers?: { [s: string]: string; }): Promise; + head(url: string, headers?: { [s: string]: string; }): Promise; + options(url: string, headers?: { [s: string]: string; }): Promise; +} + +/** + * 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; + getTokenWithoutCache(): Promise; +} diff --git a/types/microservice-utilities/microservice-utilities-tests.ts b/types/microservice-utilities/microservice-utilities-tests.ts new file mode 100644 index 0000000000..969e5e44d4 --- /dev/null +++ b/types/microservice-utilities/microservice-utilities-tests.ts @@ -0,0 +1,17 @@ +import { Authorizer, PlatformClient, RequestLogger, ServiceTokenProvider } from 'microservice-utilities'; + +(async (): Promise => { + 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'); +})(); diff --git a/types/microservice-utilities/tsconfig.json b/types/microservice-utilities/tsconfig.json new file mode 100644 index 0000000000..db45fd6d19 --- /dev/null +++ b/types/microservice-utilities/tsconfig.json @@ -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" + ] +} diff --git a/types/microservice-utilities/tslint.json b/types/microservice-utilities/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/microservice-utilities/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}