-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed minor issues with B2C configuration. Switched publishing functi…
…onality to portal revisions API. (#1349)
- Loading branch information
Showing
14 changed files
with
185 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as Objects from "@paperbits/common/objects"; | ||
import { EventManager } from "@paperbits/common/events"; | ||
import { HttpClient } from "@paperbits/common/http"; | ||
import { ISettingsProvider } from "@paperbits/common/configuration"; | ||
import { SessionManager } from "@paperbits/common/persistence/sessionManager"; | ||
|
||
|
||
export class ApimSettingsProvider implements ISettingsProvider { | ||
private configuration: Object; | ||
private initializePromise: Promise<void>; | ||
|
||
constructor( | ||
private readonly httpClient: HttpClient, | ||
private readonly eventManager: EventManager, | ||
private readonly sessionManager: SessionManager | ||
) { } | ||
|
||
private async ensureInitialized(): Promise<void> { | ||
if (!this.initializePromise) { | ||
this.initializePromise = this.loadSettings(); | ||
} | ||
return this.initializePromise; | ||
} | ||
|
||
private async loadSettings(): Promise<void> { | ||
const commonConfigurationResponse = await this.httpClient.send<any>({ url: "/config.json" }); | ||
const commonConfiguration = commonConfigurationResponse.toObject(); | ||
|
||
const searializedDesignTimeSettings = await this.sessionManager?.getItem("designTimeSettings"); | ||
|
||
if (searializedDesignTimeSettings) { | ||
const designTimeSettings = searializedDesignTimeSettings; | ||
Object.assign(commonConfiguration, designTimeSettings); | ||
} | ||
else { | ||
const apimsConfigurationResponse = await this.httpClient.send<any>({ url: "/config-apim.json" }); | ||
|
||
if (apimsConfigurationResponse.statusCode === 200) { | ||
const apimConfiguration = apimsConfigurationResponse.toObject(); | ||
Object.assign(commonConfiguration, apimConfiguration); | ||
} | ||
} | ||
|
||
this.configuration = commonConfiguration; | ||
} | ||
|
||
public async getSetting<T>(name: string): Promise<T> { | ||
await this.ensureInitialized(); | ||
return Objects.getObjectAt(name, this.configuration); | ||
} | ||
|
||
public onSettingChange<T>(name: string, eventHandler: (value: T) => void): void { | ||
this.eventManager.addEventListener("onSettingChange", (setting) => { | ||
if (setting.name === name) { | ||
eventHandler(setting.value); | ||
} | ||
}); | ||
} | ||
|
||
public async setSetting<T>(name: string, value: T): Promise<void> { | ||
await this.ensureInitialized(); | ||
|
||
Objects.setValue(name, this.configuration, value); | ||
this.eventManager.dispatchEvent("onSettingChange", { name: name, value: value }); | ||
} | ||
|
||
public async getSettings(): Promise<any> { | ||
await this.ensureInitialized(); | ||
|
||
return this.configuration; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface OAuthSession { | ||
authenticationFlow: string; | ||
authenticationCallback: (accessToken: string) => void; | ||
authenticationErrorCallback: (error: Error) => void; | ||
loginUrl: string; | ||
redirectUri: string; | ||
clientId: string; | ||
issuer: string; | ||
tokenEndpoint: string; | ||
scope: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ServiceDescriptionContract, HostnameConfiguration, ServiceSku } from "./../contracts/service"; | ||
|
||
export class ServiceDescription { | ||
public name: string; | ||
public hostnameConfigurations: HostnameConfiguration[]; | ||
public sku: ServiceSku; | ||
public gatewayUrl: string; | ||
|
||
constructor(contract: ServiceDescriptionContract) { | ||
this.name = contract.name; | ||
this.sku = contract.sku; | ||
this.gatewayUrl = contract.properties.gatewayUrl; | ||
this.hostnameConfigurations = contract.properties.hostnameConfigurations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { LruCache } from "@paperbits/common/caching"; | ||
import { IObjectStorage, Page, Query } from "@paperbits/common/persistence"; | ||
|
||
export class CachedObjectStorage { | ||
private readonly cache: LruCache<Promise<any>>; | ||
|
||
constructor( | ||
private readonly underlyingStorage: IObjectStorage | ||
) { | ||
this.cache = new LruCache(100, () => { return; }); | ||
} | ||
|
||
public addObject<T>(key: string, dataObject: T): Promise<void> { | ||
throw new Error("Not supported."); | ||
} | ||
|
||
public getObject<T>(key: string): Promise<T> { | ||
const cachedItemPromise = this.cache.getItem(key); | ||
|
||
if (cachedItemPromise) { | ||
return cachedItemPromise; | ||
} | ||
|
||
const fetchPromise = this.underlyingStorage.getObject<T>(key); | ||
|
||
this.cache.setItem(key, fetchPromise); | ||
|
||
return fetchPromise; | ||
} | ||
|
||
public deleteObject(key: string): Promise<void> { | ||
throw new Error("Not supported."); | ||
} | ||
|
||
public updateObject<T>(key: string, dataObject: T): Promise<void> { | ||
throw new Error("Not supported."); | ||
} | ||
|
||
public async searchObjects<T>(key: string, query?: Query<T>): Promise<Page<T>> { | ||
return await this.underlyingStorage.searchObjects<T>(key, query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { IObjectStorage } from "@paperbits/common/persistence"; | ||
import { IInjector, IInjectorModule } from "@paperbits/common/injection"; | ||
import { CachedObjectStorage } from "./cachedObjectStorage"; | ||
|
||
|
||
export class PublishingCacheModule implements IInjectorModule { | ||
public register(injector: IInjector): void { | ||
const underlyingObjectStorage = injector.resolve<IObjectStorage>("objectStorage"); | ||
|
||
injector.bindSingletonFactory<IObjectStorage>("objectStorage", (ctx: IInjector) => { | ||
return new CachedObjectStorage(underlyingObjectStorage); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters