@equinor/fusion-framework-module-service-discovery
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [0.2.0](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module-service-discovery@0.1.1...@equinor/fusion-framework-module-service-discovery@0.2.0) (2022-02-15) | ||
### Features | ||
* **module-service-discovery:** allow custom service discovery ([8917e4e](https://github.com/equinor/fusion-framework/commit/8917e4e3053b824ac8d878b0bfbe6a22efd56c3b)) | ||
## 0.1.1 (2022-02-09) | ||
@@ -8,0 +19,0 @@ |
@@ -0,5 +1,18 @@ | ||
const defaultSelector = async (response) => { | ||
const env = (await response.json()); | ||
const services = env.services.reduce((acc, service) => { | ||
return Object.assign(acc, { | ||
[service.key]: { | ||
clientId: env.clientId, | ||
defaultScopes: [env.clientId + '/.default'], | ||
}, | ||
}); | ||
}, {}); | ||
return { ...env, services }; | ||
}; | ||
export class ServiceDiscoveryConfigurator { | ||
clientKey = 'service_discovery'; | ||
uri = '/_discovery/environments/current'; | ||
selector = defaultSelector; | ||
} | ||
//# sourceMappingURL=configurator.js.map |
@@ -11,8 +11,6 @@ export class ServiceDiscoveryProvider { | ||
} | ||
get clientId() { | ||
return this.environment.then((x) => x.clientId); | ||
} | ||
async resolveService(key) { | ||
const { services } = await this._getEnvironment(); | ||
return services.find((x) => x.key === key); | ||
const service = services[key]; | ||
return service; | ||
} | ||
@@ -39,7 +37,6 @@ async configureClient(name, config, onCreate) { | ||
try { | ||
const client = this._http.createClient(this._config.clientKey); | ||
const result = await client.fetchAsync(this._config.uri); | ||
const env = await result.json(); | ||
env.services.forEach((x) => (x.defaultScopes = [env.clientId + '/.default'])); | ||
return env; | ||
const { clientKey, uri, selector } = this._config; | ||
const client = this._http.createClient(clientKey); | ||
const result = await client.fetchAsync(uri, { selector }); | ||
return result; | ||
} | ||
@@ -46,0 +43,0 @@ catch (err) { |
@@ -0,4 +1,6 @@ | ||
import type { Environment } from './types'; | ||
export interface IServiceDiscoveryConfigurator { | ||
clientKey: string; | ||
uri: string; | ||
selector: (response: Response) => Promise<Environment>; | ||
} | ||
@@ -8,2 +10,3 @@ export declare class ServiceDiscoveryConfigurator implements IServiceDiscoveryConfigurator { | ||
uri: string; | ||
selector: (response: Response) => Promise<Environment>; | ||
} |
@@ -8,3 +8,2 @@ import { IServiceDiscoveryConfigurator } from './configurator'; | ||
readonly environment: Promise<Environment>; | ||
readonly clientId: Promise<string>; | ||
configureClient(name: string, config: ModulesConfigType<[HttpModule]>): Promise<void>; | ||
@@ -14,6 +13,5 @@ } | ||
protected readonly _config: IServiceDiscoveryConfigurator; | ||
protected readonly _http: IHttpClientProvider<any>; | ||
constructor(_config: IServiceDiscoveryConfigurator, _http: IHttpClientProvider<any>); | ||
protected readonly _http: IHttpClientProvider; | ||
constructor(_config: IServiceDiscoveryConfigurator, _http: IHttpClientProvider); | ||
get environment(): Promise<Environment>; | ||
get clientId(): Promise<string>; | ||
resolveService(key: string): Promise<Service | undefined>; | ||
@@ -20,0 +18,0 @@ configureClient(name: string, config: ModulesConfigType<[HttpModule]>, onCreate?: (client: IHttpClient) => void): Promise<void>; |
@@ -1,17 +0,17 @@ | ||
export declare type Environment = { | ||
environmentName: string; | ||
export declare type EnvironmentResponse = { | ||
clientId: string; | ||
resourceV2: string; | ||
resourceV1: string; | ||
type: string; | ||
services: Service[]; | ||
services: Array<{ | ||
key: string; | ||
uri: string; | ||
}>; | ||
}; | ||
export declare type Environment = { | ||
type?: string; | ||
services: Record<string, Service>; | ||
}; | ||
export declare type Service = { | ||
key: string; | ||
name: null | string; | ||
serviceName: null; | ||
name?: null | string; | ||
clientId?: string; | ||
uri: string; | ||
type: 'Service'; | ||
internal: boolean; | ||
defaultScopes: string[]; | ||
}; |
{ | ||
"name": "@equinor/fusion-framework-module-service-discovery", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "", | ||
@@ -35,3 +35,3 @@ "main": "./dist/esm/index.js", | ||
}, | ||
"gitHead": "ca79b01fcc32c2c4e4aeea2f7c251fe9d91a2d04" | ||
"gitHead": "075883ab8865523aef6a373e4aeccf1c54c095b4" | ||
} |
@@ -0,1 +1,3 @@ | ||
import type { Environment, EnvironmentResponse } from './types'; | ||
export interface IServiceDiscoveryConfigurator { | ||
@@ -6,7 +8,23 @@ /** name of HttpClient */ | ||
uri: string; | ||
/** Response selector */ | ||
selector: (response: Response) => Promise<Environment>; | ||
} | ||
const defaultSelector = async (response: Response): Promise<Environment> => { | ||
const env = (await response.json()) as EnvironmentResponse; | ||
const services = env.services.reduce((acc, service) => { | ||
return Object.assign(acc, { | ||
[service.key]: { | ||
clientId: env.clientId, | ||
defaultScopes: [env.clientId + '/.default'], | ||
}, | ||
}); | ||
}, {}); | ||
return { ...env, services }; | ||
}; | ||
export class ServiceDiscoveryConfigurator implements IServiceDiscoveryConfigurator { | ||
clientKey = 'service_discovery'; | ||
uri = '/_discovery/environments/current'; | ||
selector = defaultSelector; | ||
} |
@@ -0,1 +1,6 @@ | ||
/** | ||
* [[include:module-service-discovery/README.MD]] | ||
* @module | ||
*/ | ||
export * from './types'; | ||
@@ -2,0 +7,0 @@ export { IServiceDiscoveryConfigurator, ServiceDiscoveryConfigurator } from './configurator'; |
@@ -21,3 +21,2 @@ import { IServiceDiscoveryConfigurator } from './configurator'; | ||
readonly environment: Promise<Environment>; | ||
readonly clientId: Promise<string>; | ||
@@ -31,3 +30,3 @@ configureClient(name: string, config: ModulesConfigType<[HttpModule]>): Promise<void>; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
protected readonly _http: IHttpClientProvider<any> | ||
protected readonly _http: IHttpClientProvider | ||
) {} | ||
@@ -39,9 +38,7 @@ | ||
get clientId(): Promise<string> { | ||
return this.environment.then((x) => x.clientId); | ||
} | ||
async resolveService(key: string): Promise<Service | undefined> { | ||
const { services } = await this._getEnvironment(); | ||
return services.find((x) => x.key === key); | ||
// TODO - not found error | ||
const service = services[key]; | ||
return service; | ||
} | ||
@@ -75,9 +72,6 @@ | ||
try { | ||
const client = this._http.createClient(this._config.clientKey); | ||
const result = await client.fetchAsync(this._config.uri); | ||
const env: Environment = await result.json(); | ||
// TODO - service should return this! | ||
env.services.forEach((x) => (x.defaultScopes = [env.clientId + '/.default'])); | ||
// TODO - catch me | ||
return env; | ||
const { clientKey, uri, selector } = this._config; | ||
const client = this._http.createClient(clientKey); | ||
const result = await client.fetchAsync(uri, { selector }); | ||
return result; | ||
} catch (err) { | ||
@@ -84,0 +78,0 @@ console.error(err); |
@@ -1,18 +0,19 @@ | ||
export type Environment = { | ||
environmentName: string; | ||
export type EnvironmentResponse = { | ||
clientId: string; | ||
resourceV2: string; | ||
resourceV1: string; | ||
type: string; | ||
services: Service[]; | ||
services: Array<{ | ||
key: string; | ||
uri: string; | ||
}>; | ||
}; | ||
export type Environment = { | ||
type?: string; | ||
services: Record<string, Service>; | ||
}; | ||
export type Service = { | ||
key: string; | ||
name: null | string; | ||
serviceName: null; | ||
name?: null | string; | ||
clientId?: string; | ||
uri: string; | ||
type: 'Service'; | ||
internal: boolean; | ||
defaultScopes: string[]; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
79272
25
331
0
24