mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Merge pull request #30865 from runebaas/microservice-utilities
Add Typings for microservice-utilities
This commit is contained in:
84
types/microservice-utilities/index.d.ts
vendored
Normal file
84
types/microservice-utilities/index.d.ts
vendored
Normal 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>;
|
||||
}
|
||||
17
types/microservice-utilities/microservice-utilities-tests.ts
Normal file
17
types/microservice-utilities/microservice-utilities-tests.ts
Normal 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');
|
||||
})();
|
||||
23
types/microservice-utilities/tsconfig.json
Normal file
23
types/microservice-utilities/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
3
types/microservice-utilities/tslint.json
Normal file
3
types/microservice-utilities/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user