@equinor/fusion-framework-module-http
Advanced tools
Comparing version 2.1.2 to 2.1.3
@@ -6,2 +6,8 @@ # Change Log | ||
## 2.1.3 (2022-11-11) | ||
### Bug Fixes | ||
- **module-auth:** make http module await auth ([18a0ed9](https://github.com/equinor/fusion-framework/commit/18a0ed947e128bf1cdc86aa45d31e73c1f8c4bbb)) | ||
## 2.1.2 (2022-11-03) | ||
@@ -8,0 +14,0 @@ |
@@ -0,1 +1,10 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { HttpClientMsal } from './lib/client'; | ||
@@ -7,3 +16,22 @@ import { HttpClientConfigurator } from './configurator'; | ||
configure: () => new HttpClientConfigurator(HttpClientMsal), | ||
initialize: ({ config }) => new HttpClientProvider(config), | ||
initialize: ({ config, hasModule, requireInstance, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
const httpProvider = new HttpClientProvider(config); | ||
if (hasModule('auth')) { | ||
const authProvider = yield requireInstance('auth'); | ||
httpProvider.defaultHttpRequestHandler.set('MSAL', (request) => __awaiter(void 0, void 0, void 0, function* () { | ||
const { scopes = [] } = request; | ||
if (scopes.length) { | ||
const token = yield authProvider.acquireToken({ | ||
scopes, | ||
}); | ||
if (token) { | ||
const headers = new Headers(request.headers); | ||
headers.set('Authorization', `Bearer ${token.accessToken}`); | ||
return Object.assign(Object.assign({}, request), { headers }); | ||
} | ||
} | ||
})); | ||
} | ||
return httpProvider; | ||
}), | ||
}; | ||
@@ -10,0 +38,0 @@ export const configureHttp = (configure) => ({ |
@@ -5,7 +5,10 @@ import { HttpClientMsal } from './lib/client'; | ||
import type { Module, ModuleConfigType, IModuleConfigurator } from '@equinor/fusion-framework-module'; | ||
import { MsalModule } from '@equinor/fusion-framework-module-msal'; | ||
export declare type HttpModule = Module<'http', IHttpClientProvider, IHttpClientConfigurator>; | ||
export declare type HttpMsalModule = Module<'http', IHttpClientProvider<HttpClientMsal>, IHttpClientConfigurator<HttpClientMsal>>; | ||
export declare const module: HttpModule; | ||
export declare const configureHttp: <TRef = unknown>(configure: (config: ModuleConfigType<HttpModule>, ref?: TRef | undefined) => void) => IModuleConfigurator<HttpModule, TRef>; | ||
export declare const configureHttpClient: <TRef = unknown>(name: string, args: HttpClientOptions) => IModuleConfigurator<HttpModule, TRef>; | ||
export declare type HttpMsalModule = Module<'http', IHttpClientProvider<HttpClientMsal>, IHttpClientConfigurator<HttpClientMsal>, [ | ||
MsalModule | ||
]>; | ||
export declare const module: HttpMsalModule; | ||
export declare const configureHttp: <TRef = unknown>(configure: (config: ModuleConfigType<HttpMsalModule>, ref?: TRef | undefined) => void) => IModuleConfigurator<HttpMsalModule, TRef>; | ||
export declare const configureHttpClient: <TRef = unknown>(name: string, args: HttpClientOptions<HttpClientMsal>) => IModuleConfigurator<HttpMsalModule, TRef>; | ||
declare module '@equinor/fusion-framework-module' { | ||
@@ -12,0 +15,0 @@ interface Modules { |
{ | ||
"name": "@equinor/fusion-framework-module-http", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "", | ||
@@ -46,2 +46,3 @@ "main": "dist/esm/index.js", | ||
"@equinor/fusion-framework-module": "^1.2.8", | ||
"@equinor/fusion-framework-module-msal": "^1.0.18", | ||
"rxjs": "^7.5.7" | ||
@@ -52,3 +53,3 @@ }, | ||
}, | ||
"gitHead": "9cce61b38374a86ac2a74344e12af461b78aea5c" | ||
"gitHead": "2dd115889b330bf92466e375f87d5ff95ab3a793" | ||
} |
@@ -12,2 +12,4 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { MsalModule } from '@equinor/fusion-framework-module-msal'; | ||
export type HttpModule = Module<'http', IHttpClientProvider, IHttpClientConfigurator>; | ||
@@ -18,3 +20,4 @@ | ||
IHttpClientProvider<HttpClientMsal>, | ||
IHttpClientConfigurator<HttpClientMsal> | ||
IHttpClientConfigurator<HttpClientMsal>, | ||
[MsalModule] | ||
>; | ||
@@ -25,6 +28,30 @@ | ||
*/ | ||
export const module: HttpModule = { | ||
export const module: HttpMsalModule = { | ||
name: 'http', | ||
configure: () => new HttpClientConfigurator(HttpClientMsal), | ||
initialize: ({ config }): HttpClientProvider => new HttpClientProvider(config), | ||
initialize: async ({ | ||
config, | ||
hasModule, | ||
requireInstance, | ||
}): Promise<HttpClientProvider<HttpClientMsal>> => { | ||
const httpProvider = new HttpClientProvider(config); | ||
if (hasModule('auth')) { | ||
const authProvider = await requireInstance('auth'); | ||
httpProvider.defaultHttpRequestHandler.set('MSAL', async (request) => { | ||
const { scopes = [] } = request; | ||
if (scopes.length) { | ||
/** TODO should be try catch, check caller for handling */ | ||
const token = await authProvider.acquireToken({ | ||
scopes, | ||
}); | ||
if (token) { | ||
const headers = new Headers(request.headers); | ||
headers.set('Authorization', `Bearer ${token.accessToken}`); | ||
return { ...request, headers }; | ||
} | ||
} | ||
}); | ||
} | ||
return httpProvider; | ||
}, | ||
}; | ||
@@ -34,4 +61,4 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
configure: (config: ModuleConfigType<HttpModule>, ref?: TRef) => void | ||
): IModuleConfigurator<HttpModule, TRef> => ({ | ||
configure: (config: ModuleConfigType<HttpMsalModule>, ref?: TRef) => void | ||
): IModuleConfigurator<HttpMsalModule, TRef> => ({ | ||
module, | ||
@@ -43,6 +70,6 @@ configure, | ||
name: string, | ||
args: HttpClientOptions | ||
): IModuleConfigurator<HttpModule, TRef> => ({ | ||
args: HttpClientOptions<HttpClientMsal> | ||
): IModuleConfigurator<HttpMsalModule, TRef> => ({ | ||
module, | ||
configure: (config: ModuleConfigType<HttpModule>) => { | ||
configure: (config: ModuleConfigType<HttpMsalModule>) => { | ||
config.configureClient(name, args); | ||
@@ -49,0 +76,0 @@ }, |
@@ -12,2 +12,5 @@ { | ||
"path": "../module" | ||
}, | ||
{ | ||
"path": "../module-msal" | ||
} | ||
@@ -14,0 +17,0 @@ ], |
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
178958
1233
3
+ Added@azure/msal-browser@2.39.0(transitive)
+ Added@azure/msal-common@13.3.3(transitive)
+ Added@equinor/fusion-framework-module-msal@1.0.23(transitive)