UNPKG

oidc-client-rx

Version:

ReactiveX enhanced OIDC and OAuth2 protocol support for browser-based JavaScript applications

74 lines (73 loc) 2.74 kB
import { NEVER, fromEvent, shareReplay, take } from "rxjs"; import { DESTORY_REF } from "../resources/index.js"; import { DOCUMENT } from "../dom/index.js"; import { provideHttpClient } from "../http/index.js"; import { AbstractRouter, VanillaHistoryRouter, VanillaLocationRouter } from "../router/index.js"; import { AbstractSecurityStorage } from "../storage/abstract-security-storage.js"; import { DefaultLocalStorageService } from "../storage/default-localstorage.service.js"; import { DefaultSessionStorageService } from "../storage/default-sessionstorage.service.js"; import { PLATFORM_ID } from "../utils/platform-provider/platform.provider.js"; function withBrowserPlatform({ enabled = true } = {}) { return { ɵproviders: enabled ? [ { provide: DOCUMENT, useFactory: ()=>document }, { provide: PLATFORM_ID, useValue: 'browser' }, { provide: DESTORY_REF, useFactory: (document1)=>{ if (null == document1 ? void 0 : document1.defaultView) return fromEvent(document1.defaultView, 'beforeunload').pipe(take(1), shareReplay(1)); return NEVER; }, deps: [ DOCUMENT ] } ] : [] }; } function withHttpClient({ features, enabled = true } = {}) { return { ɵproviders: enabled ? provideHttpClient(features) : [] }; } function withSecurityStorage({ enabled = true, type = 'session-storage' } = {}) { return { ɵproviders: enabled ? [ 'local-storage' === type ? { provide: AbstractSecurityStorage, useClass: DefaultLocalStorageService } : { provide: AbstractSecurityStorage, useClass: DefaultSessionStorageService } ] : [] }; } function withVanillaRouter({ enabled = true, type = 'history' } = {}) { return { ɵproviders: enabled ? [ 'location' === type ? { provide: AbstractRouter, useClass: VanillaLocationRouter } : { provide: AbstractRouter, useClass: VanillaHistoryRouter } ] : [] }; } function withDefaultFeatures(options = {}) { return [ withBrowserPlatform(options.browserPlatform), withSecurityStorage(options.securityStorage), withHttpClient(options.httpClient), withVanillaRouter(options.router) ].filter(Boolean); } export { withBrowserPlatform, withDefaultFeatures, withHttpClient, withSecurityStorage, withVanillaRouter };