@equinor/fusion-framework-module-app
Advanced tools
Comparing version 6.0.0-alpha-df90c0f890db097d17d4b84fe6face6323143970 to 6.0.0-next-43b4cac9210dd754e552b9f32ae229477e5ca643
# Change Log | ||
## 6.0.0-alpha-df90c0f890db097d17d4b84fe6face6323143970 | ||
## 6.0.0-next-43b4cac9210dd754e552b9f32ae229477e5ca643 | ||
### Major Changes | ||
- [#2178](https://github.com/equinor/fusion-framework/pull/2178) [`dbdccb0`](https://github.com/equinor/fusion-framework/commit/dbdccb0c8878b59a6f5f2d404b3daf8f2b138ea6) Thanks [@eikeland](https://github.com/eikeland)! - Adjusted module to the new app service API. | ||
- [#2494](https://github.com/equinor/fusion-framework/pull/2494) [`9f6eec8`](https://github.com/equinor/fusion-framework/commit/9f6eec8c5a4cb3dd430fc6bee227442a3dc28bb8) Thanks [@odinr](https://github.com/odinr)! - Adjusted module to the new app service API. | ||
@@ -21,2 +21,3 @@ > [!WARNING] | ||
- Modified `AppConfigurator` to utilize `AppClient` for client configuration. | ||
- Updated `useApps` hook with new input parameter for `filterByCurrentUser` in `fusion-framework-react`. | ||
@@ -23,0 +24,0 @@ **Migration** |
@@ -66,3 +66,3 @@ import { from, of, concat } from 'rxjs'; | ||
switchMap(({ payload }) => { | ||
const endpoint = [provider.getBaseUri(), payload].join('/').replace(/\/{2,}/g, '/'); | ||
const endpoint = [provider.assetUri, payload].join('/').replace(/\/{2,}/g, '/'); | ||
// dynamically import the application script | ||
@@ -69,0 +69,0 @@ return from(import(/* @vite-ignore */ endpoint)).pipe( |
@@ -38,4 +38,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { jsonSelector } from '@equinor/fusion-framework-module-http/selectors'; | ||
import { ApiApplicationSchema } from './application.schema'; | ||
import { ApiApplicationSchema } from './schemas'; | ||
import { AppConfigError, AppManifestError } from './errors'; | ||
import { AppConfigSelector } from './AppClient.Selectors'; | ||
/** | ||
@@ -56,3 +57,3 @@ * Transforms an ApiApplicationSchema object into an AppManifest object. | ||
return props.displayName; | ||
}, categoryId: category === null || category === void 0 ? void 0 : category.id }); | ||
}, categoryId: category === null || category === void 0 ? void 0 : category.id, category }); | ||
}); | ||
@@ -91,3 +92,6 @@ /** | ||
}, | ||
selector: (res) => __awaiter(this, void 0, void 0, function* () { return ApplicationSchema.array().parse(yield jsonSelector(res)); }), | ||
selector: (res) => __awaiter(this, void 0, void 0, function* () { | ||
const response = (yield jsonSelector(res)); | ||
return ApplicationSchema.array().parse(response.value); | ||
}), | ||
}); | ||
@@ -103,2 +107,3 @@ }, | ||
return client.json(`/apps/${appKey}/builds/${tag}/config`, { | ||
selector: AppConfigSelector, | ||
headers: { | ||
@@ -105,0 +110,0 @@ 'Api-Version': '1.0', |
@@ -42,5 +42,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
// TODO - explain why, used in import of resources aka proxy url | ||
setBaseUri(base_or_cb) { | ||
setAssetUri(base_or_cb) { | ||
const cb = typeof base_or_cb === 'string' ? () => __awaiter(this, void 0, void 0, function* () { return base_or_cb; }) : base_or_cb; | ||
this._set('baseUri', cb); | ||
this._set('assetUri', cb); | ||
} | ||
@@ -55,4 +55,4 @@ _createConfig(init, initial) { | ||
} | ||
if (!this._has('baseUri')) { | ||
this.setBaseUri('/apps-proxy'); | ||
if (!this._has('assetUri')) { | ||
this.setAssetUri('/apps-proxy'); | ||
} | ||
@@ -59,0 +59,0 @@ return super._createConfig(init, initial); |
@@ -48,3 +48,3 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
__classPrivateFieldSet(this, _AppModuleProvider_current$, new BehaviorSubject(undefined), "f"); | ||
__classPrivateFieldSet(this, _AppModuleProvider_appBaseUri, (_a = config.baseUri) !== null && _a !== void 0 ? _a : '', "f"); | ||
__classPrivateFieldSet(this, _AppModuleProvider_appBaseUri, (_a = config.assetUri) !== null && _a !== void 0 ? _a : '', "f"); | ||
__classPrivateFieldGet(this, _AppModuleProvider_subscription, "f").add(this.current$ | ||
@@ -97,3 +97,3 @@ .pipe(pairwise(), takeWhile(() => !!event)) | ||
} | ||
getBaseUri() { | ||
get assetUri() { | ||
return __classPrivateFieldGet(this, _AppModuleProvider_appBaseUri, "f"); | ||
@@ -100,0 +100,0 @@ } |
export {}; | ||
// export type ApiAppVersionConfig = { | ||
// environment: string; | ||
// endpoints: Record< | ||
// string, | ||
// { | ||
// url: string; | ||
// scopes: string[]; | ||
// } | ||
// >; | ||
// }; | ||
// export type ApiApp = { | ||
// appKey: string; | ||
// displayName?: string; | ||
// description?: string; | ||
// type?: AppType; | ||
// isPinned?: boolean; | ||
// templateSource?: string; | ||
// category?: AppCategory; | ||
// visualization: { | ||
// color: string; | ||
// icon: string; | ||
// sortOrder: number; | ||
// }; | ||
// keywords: string[]; | ||
// admins: AppOwnerOrAdmin[]; | ||
// owners: AppOwnerOrAdmin[]; | ||
// build: AppBuild<AzureUniqueId>; | ||
// }; | ||
//# sourceMappingURL=types.js.map |
@@ -16,5 +16,5 @@ import { ActionInstanceMap, ActionTypes } from '@equinor/fusion-observable'; | ||
/** Config loading */ | ||
setConfig: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[config: AppConfig], AppConfig, "set_config", never, never>; | ||
setConfig: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[config: AppConfig<import("../AppConfig").ConfigEnvironment>], AppConfig<import("../AppConfig").ConfigEnvironment>, "set_config", never, never>; | ||
fetchConfig: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[manifest: AppManifest], AppManifest, "fetch_config::request", never, never> & { | ||
success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[config: AppConfig], AppConfig, "fetch_config::success", never, never>; | ||
success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[config: AppConfig<import("../AppConfig").ConfigEnvironment>], AppConfig<import("../AppConfig").ConfigEnvironment>, "fetch_config::success", never, never>; | ||
failure: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "fetch_config::failure", never, never>; | ||
@@ -47,5 +47,5 @@ }; | ||
/** Config loading */ | ||
setConfig: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[config: AppConfig], AppConfig, "set_config", never, never>; | ||
setConfig: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[config: AppConfig<import("../AppConfig").ConfigEnvironment>], AppConfig<import("../AppConfig").ConfigEnvironment>, "set_config", never, never>; | ||
fetchConfig: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[manifest: AppManifest], AppManifest, "fetch_config::request", never, never> & { | ||
success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[config: AppConfig], AppConfig, "fetch_config::success", never, never>; | ||
success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[config: AppConfig<import("../AppConfig").ConfigEnvironment>], AppConfig<import("../AppConfig").ConfigEnvironment>, "fetch_config::success", never, never>; | ||
failure: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[error: unknown], unknown, "fetch_config::failure", never, never>; | ||
@@ -52,0 +52,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import type { AppConfig, AppModulesInstance, AppScriptModule } from '../types'; | ||
import type { AppModulesInstance, AppScriptModule, AppManifest, AppConfig, ConfigEnvironment } from '../types'; | ||
import { Observable } from '@equinor/fusion-observable'; | ||
@@ -8,3 +8,2 @@ import type { AppModuleProvider } from '../AppModuleProvider'; | ||
import { AppBundleState, AppBundleStateInitial } from './types'; | ||
import { AppManifest } from '../types'; | ||
import './events'; | ||
@@ -17,3 +16,3 @@ export declare function filterEmpty<T>(): OperatorFunction<T | null | undefined, T>; | ||
*/ | ||
export interface IApp<TEnv = any, TModules extends Array<AnyModule> | unknown = unknown> { | ||
export interface IApp<TEnv extends ConfigEnvironment = ConfigEnvironment, TModules extends Array<AnyModule> | unknown = unknown> { | ||
/** | ||
@@ -139,3 +138,3 @@ * Returns an observable that emits the app manifest. | ||
} | ||
export declare class App<TEnv = any, TModules extends Array<AnyModule> | unknown = unknown> implements IApp<TEnv, TModules> { | ||
export declare class App<TEnv extends ConfigEnvironment = ConfigEnvironment, TModules extends Array<AnyModule> | unknown = unknown> implements IApp<TEnv, TModules> { | ||
#private; | ||
@@ -150,4 +149,4 @@ get manifest$(): Observable<AppManifest>; | ||
get manifestAsync(): Promise<Readonly<AppManifest>>; | ||
get config(): Readonly<AppConfig<TEnv>> | undefined; | ||
get configAsync(): Promise<Readonly<AppConfig<TEnv>>>; | ||
get config(): AppConfig<TEnv> | undefined; | ||
get configAsync(): Promise<AppConfig<TEnv>>; | ||
get instance(): AppModulesInstance<TModules> | undefined; | ||
@@ -154,0 +153,0 @@ constructor(value: AppBundleStateInitial, args: { |
@@ -8,3 +8,3 @@ import { AppBundleState, AppBundleStateInitial } from './types'; | ||
}, never> | { | ||
payload: import("..").AppConfig; | ||
payload: import("..").AppConfig<import("../AppConfig").ConfigEnvironment>; | ||
type: "set_config"; | ||
@@ -33,3 +33,3 @@ } | { | ||
} | { | ||
payload: import("..").AppConfig; | ||
payload: import("..").AppConfig<import("../AppConfig").ConfigEnvironment>; | ||
type: "fetch_config::success"; | ||
@@ -36,0 +36,0 @@ } | { |
@@ -1,3 +0,16 @@ | ||
import type { AppManifest, AppConfig, AppModulesInstance, AppScriptModule } from '../types'; | ||
export type AppBundleState<TConfig = any, TModules = any> = { | ||
import type { AppManifest, AppConfig, AppModulesInstance, AppScriptModule, ConfigEnvironment } from '../types'; | ||
/** | ||
* Represents the state of an application bundle. | ||
* | ||
* @template TConfig - The type of the configuration environment, defaults to `ConfigEnvironment`. | ||
* @template TModules - The type of the modules, defaults to `any`. | ||
* | ||
* @property {string} appKey - A unique key identifying the application. | ||
* @property {Set<string>} status - A set of strings representing the status of the application. | ||
* @property {AppManifest} [manifest] - An optional manifest describing the application. | ||
* @property {AppConfig<TConfig>} [config] - An optional configuration object for the application. | ||
* @property {AppScriptModule} [modules] - An optional script module for the application. | ||
* @property {AppModulesInstance<TModules>} [instance] - An optional instance of the application modules. | ||
*/ | ||
export type AppBundleState<TConfig extends ConfigEnvironment = ConfigEnvironment, TModules = any> = { | ||
appKey: string; | ||
@@ -10,2 +23,8 @@ status: Set<string>; | ||
}; | ||
export type AppBundleStateInitial<TConfig = any, TModules = any> = Omit<AppBundleState<TConfig, TModules>, 'status'>; | ||
/** | ||
* Represents the initial state of an application bundle, excluding the 'status' property. | ||
* | ||
* @template TConfig - The configuration environment type, defaults to `ConfigEnvironment`. | ||
* @template TModules - The type of modules included in the application bundle, defaults to `any`. | ||
*/ | ||
export type AppBundleStateInitial<TConfig extends ConfigEnvironment = ConfigEnvironment, TModules = any> = Omit<AppBundleState<TConfig, TModules>, 'status'>; |
import { Observable, ObservableInput } from 'rxjs'; | ||
import { IHttpClient } from '@equinor/fusion-framework-module-http'; | ||
import { AppConfig, AppManifest } from './types'; | ||
import type { AppConfig, AppManifest, ConfigEnvironment } from './types'; | ||
export interface IAppClient extends Disposable { | ||
@@ -20,3 +20,3 @@ /** | ||
*/ | ||
getAppConfig: <TType = unknown>(args: { | ||
getAppConfig: <TType extends ConfigEnvironment = ConfigEnvironment>(args: { | ||
appKey: string; | ||
@@ -39,3 +39,3 @@ tag?: string; | ||
} | undefined): Observable<AppManifest[]>; | ||
getAppConfig<TType = unknown>(args: { | ||
getAppConfig<TType extends ConfigEnvironment = ConfigEnvironment>(args: { | ||
appKey: string; | ||
@@ -42,0 +42,0 @@ tag?: string; |
@@ -7,7 +7,7 @@ import { BaseConfigBuilder, ConfigBuilderCallback, type ModuleInitializerArgs } from '@equinor/fusion-framework-module'; | ||
client: IAppClient; | ||
baseUri?: string; | ||
assetUri?: string; | ||
} | ||
export interface IAppConfigurator { | ||
setClient: (client_or_cb: Promise<AppModuleConfig['client']> | ConfigBuilderCallback<AppModuleConfig['client']>) => void; | ||
setBaseUri: (base_or_cb: string | ConfigBuilderCallback<string>) => void; | ||
setAssetUri: (base_or_cb: string | ConfigBuilderCallback<string>) => void; | ||
} | ||
@@ -21,4 +21,4 @@ export declare class AppConfigurator extends BaseConfigBuilder<AppModuleConfig> implements IAppConfigurator { | ||
setClient(client_or_cb: Promise<AppModuleConfig['client']> | ConfigBuilderCallback<AppModuleConfig['client']>): void; | ||
setBaseUri(base_or_cb: string | ConfigBuilderCallback<string>): void; | ||
setAssetUri(base_or_cb: string | ConfigBuilderCallback<string>): void; | ||
protected _createConfig(init: ModuleInitializerArgs<IAppConfigurator, [HttpModule, ServiceDiscoveryModule]>, initial?: Partial<AppModuleConfig>): import("rxjs").ObservableInput<AppModuleConfig>; | ||
} |
import { Observable } from 'rxjs'; | ||
import { ModuleType } from '@equinor/fusion-framework-module'; | ||
import { EventModule } from '@equinor/fusion-framework-module-event'; | ||
import type { AppConfig, AppManifest, CurrentApp } from './types'; | ||
import type { AppConfig, AppManifest, ConfigEnvironment, CurrentApp } from './types'; | ||
import { App, IApp } from './app/App'; | ||
@@ -41,3 +41,3 @@ import { AppModuleConfig } from './AppConfigurator'; | ||
*/ | ||
getAppConfig<TType = unknown>(appKey: string, tag?: string): Observable<AppConfig<TType>>; | ||
getAppConfig<TType extends ConfigEnvironment = ConfigEnvironment>(appKey: string, tag?: string): Observable<AppConfig<TType>>; | ||
/** | ||
@@ -49,3 +49,3 @@ * set the current application, will internally resolve manifest | ||
clearCurrentApp(): void; | ||
getBaseUri(): string; | ||
get assetUri(): string; | ||
/** | ||
@@ -52,0 +52,0 @@ * This should not be used, only for legacy creation backdoor |
@@ -1,2 +0,2 @@ | ||
import { AnyModule, CombinedModules, ModulesInstance } from '@equinor/fusion-framework-module'; | ||
import type { AnyModule, CombinedModules, ModulesInstance } from '@equinor/fusion-framework-module'; | ||
import type { EventModule } from '@equinor/fusion-framework-module-event'; | ||
@@ -6,8 +6,11 @@ import type { HttpModule } from '@equinor/fusion-framework-module-http'; | ||
import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery'; | ||
import IApp from './app'; | ||
import type { AppConfig } from './AppConfig'; | ||
import type IApp from './app'; | ||
export type ConfigEnvironment = Record<string, unknown>; | ||
export type { AppConfig } from './AppConfig'; | ||
type Fusion = any; | ||
export type AppEnv<TConfig = unknown, TProps = unknown> = { | ||
export type AppEnv<TEnv extends ConfigEnvironment = ConfigEnvironment, TProps = unknown> = { | ||
basename?: string; | ||
manifest?: AppManifest; | ||
config?: AppConfig<TConfig>; | ||
config?: AppConfig<TEnv>; | ||
props?: TProps; | ||
@@ -17,34 +20,30 @@ }; | ||
export type AppType = 'standalone' | 'report' | 'launcher' | 'template'; | ||
export type CurrentApp<TModules extends Array<AnyModule> = [], TEnv = any> = IApp<TEnv, TModules> | null | undefined; | ||
export type AppAdmin = { | ||
export type CurrentApp<TModules extends Array<AnyModule> = [], TEnv extends ConfigEnvironment = ConfigEnvironment> = IApp<TEnv, TModules> | null | undefined; | ||
type Nullable<T> = T | null | undefined; | ||
type AppPerson = { | ||
id: string; | ||
azureUniqueId?: string; | ||
displayName?: string; | ||
mail?: string; | ||
upn?: string; | ||
accountType?: string; | ||
accountClassification?: string; | ||
azureUniqueId: string; | ||
displayName: string; | ||
mail?: Nullable<string>; | ||
upn?: Nullable<string>; | ||
accountType: string; | ||
accountClassification?: Nullable<string>; | ||
isExpired?: Nullable<boolean>; | ||
}; | ||
export type AppOwner = AppAdmin; | ||
export type AppAdmin = AppPerson; | ||
export type AppOwner = AppPerson; | ||
export type AppBuildManifest = { | ||
version?: string; | ||
entryPoint?: string; | ||
tags?: string[]; | ||
tag?: 'latest' | 'preview'; | ||
assetPath?: string; | ||
configUrl?: string; | ||
timestamp?: string; | ||
commitSha?: string; | ||
githubRepo?: string; | ||
projectPage?: string; | ||
annotations?: Record<string, string>; | ||
allowedExtensions?: string[]; | ||
uploadedBy?: { | ||
azureUniqueId: string; | ||
displayName?: string; | ||
mail?: string; | ||
upn?: string; | ||
accountType?: string; | ||
accountClassification?: string; | ||
}; | ||
version: string; | ||
entryPoint: string; | ||
tags?: Nullable<string[]>; | ||
tag?: Nullable<'latest' | 'preview'>; | ||
assetPath?: Nullable<string>; | ||
configUrl?: Nullable<string>; | ||
timestamp?: Nullable<string>; | ||
commitSha?: Nullable<string>; | ||
githubRepo?: Nullable<string>; | ||
projectPage?: Nullable<string>; | ||
annotations?: Nullable<Record<string, string>>; | ||
allowedExtensions?: Nullable<string[]>; | ||
uploadedBy?: Nullable<AppOwner>; | ||
}; | ||
@@ -57,8 +56,8 @@ export interface AppManifest { | ||
name?: string; | ||
displayName?: string; | ||
description?: string; | ||
type?: AppType; | ||
isPinned?: boolean; | ||
templateSource?: string; | ||
category?: { | ||
displayName: string; | ||
description: string; | ||
type: AppType; | ||
isPinned?: Nullable<boolean>; | ||
templateSource?: Nullable<string>; | ||
category?: Nullable<{ | ||
id: string; | ||
@@ -69,22 +68,14 @@ name: string; | ||
defaultIcon: string; | ||
sortOrder: 1000; | ||
}; | ||
visualization?: { | ||
color?: string; | ||
icon?: string; | ||
sortOrder: number; | ||
}; | ||
keywords?: string[]; | ||
admins?: AppAdmin[]; | ||
owners?: AppOwner[]; | ||
build?: AppBuildManifest; | ||
}>; | ||
visualization?: Nullable<{ | ||
color?: Nullable<string>; | ||
icon?: Nullable<string>; | ||
sortOrder: number; | ||
}>; | ||
keywords?: Nullable<string[]>; | ||
admins?: Nullable<AppAdmin[]>; | ||
owners?: Nullable<AppOwner[]>; | ||
build?: Nullable<AppBuildManifest>; | ||
} | ||
export type Endpoint = { | ||
url: string; | ||
scopes?: string[]; | ||
}; | ||
export type AppConfig<TEnvironment = unknown> = { | ||
environment?: TEnvironment; | ||
endpoints?: Record<string, Endpoint>; | ||
}; | ||
/** | ||
@@ -94,3 +85,3 @@ * @template TEnvironment - name of hosted environment | ||
*/ | ||
export type AppBundle<TEnvironment = unknown, TModule = unknown> = { | ||
export type AppBundle<TEnvironment extends ConfigEnvironment = ConfigEnvironment, TModule = unknown> = { | ||
manifest: AppManifest; | ||
@@ -114,2 +105,1 @@ config: AppConfig<TEnvironment>; | ||
export type AppModulesInstance<TModules extends Array<AnyModule> | unknown = unknown> = ModulesInstance<AppModules<TModules>>; | ||
export {}; |
{ | ||
"name": "@equinor/fusion-framework-module-app", | ||
"version": "6.0.0-alpha-df90c0f890db097d17d4b84fe6face6323143970", | ||
"version": "6.0.0-next-43b4cac9210dd754e552b9f32ae229477e5ca643", | ||
"description": "", | ||
@@ -15,2 +15,6 @@ "main": "dist/esm/index.js", | ||
}, | ||
"./schemas.js": { | ||
"import": "./dist/esm/schemas.js", | ||
"types": "./dist/types/schemas.d.ts" | ||
}, | ||
"./app": { | ||
@@ -22,5 +26,2 @@ "import": "./dist/esm/app/index.js", | ||
"import": "./dist/esm/app/*.js" | ||
}, | ||
"./application.schema.js": { | ||
"import": "./dist/esm/application.schema.js" | ||
} | ||
@@ -34,2 +35,5 @@ }, | ||
], | ||
"schemas.js": [ | ||
"dist/types/schemas.d.ts" | ||
], | ||
"app": [ | ||
@@ -63,7 +67,7 @@ "dist/types/app/index.d.ts" | ||
"typescript": "^5.5.4", | ||
"@equinor/fusion-framework-module": "^4.3.5-alpha-df90c0f890db097d17d4b84fe6face6323143970", | ||
"@equinor/fusion-framework-module-event": "^4.2.4-alpha-df90c0f890db097d17d4b84fe6face6323143970", | ||
"@equinor/fusion-framework-module-http": "^6.1.0-alpha-df90c0f890db097d17d4b84fe6face6323143970", | ||
"@equinor/fusion-framework-module-service-discovery": "^8.0.0-alpha-df90c0f890db097d17d4b84fe6face6323143970", | ||
"@equinor/fusion-framework-module-msal": "^3.1.5-alpha-df90c0f890db097d17d4b84fe6face6323143970" | ||
"@equinor/fusion-framework-module-event": "^4.2.4", | ||
"@equinor/fusion-framework-module-http": "^6.2.0", | ||
"@equinor/fusion-framework-module": "^4.3.5", | ||
"@equinor/fusion-framework-module-msal": "^3.1.5", | ||
"@equinor/fusion-framework-module-service-discovery": "^8.0.1" | ||
}, | ||
@@ -70,0 +74,0 @@ "scripts": { |
@@ -1,2 +0,8 @@ | ||
import type { AppConfig, AppModulesInstance, AppScriptModule } from '../types'; | ||
import type { | ||
AppModulesInstance, | ||
AppScriptModule, | ||
AppManifest, | ||
AppConfig, | ||
ConfigEnvironment, | ||
} from '../types'; | ||
import { FlowSubject, Observable } from '@equinor/fusion-observable'; | ||
@@ -20,3 +26,2 @@ | ||
import { AppBundleState, AppBundleStateInitial } from './types'; | ||
import { AppManifest } from '../types'; | ||
@@ -36,3 +41,6 @@ import './events'; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export interface IApp<TEnv = any, TModules extends Array<AnyModule> | unknown = unknown> { | ||
export interface IApp< | ||
TEnv extends ConfigEnvironment = ConfigEnvironment, | ||
TModules extends Array<AnyModule> | unknown = unknown, | ||
> { | ||
/** | ||
@@ -180,4 +188,6 @@ * Returns an observable that emits the app manifest. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export class App<TEnv = any, TModules extends Array<AnyModule> | unknown = unknown> | ||
implements IApp<TEnv, TModules> | ||
export class App< | ||
TEnv extends ConfigEnvironment = ConfigEnvironment, | ||
TModules extends Array<AnyModule> | unknown = unknown, | ||
> implements IApp<TEnv, TModules> | ||
{ | ||
@@ -197,3 +207,3 @@ #state: FlowSubject<AppBundleState, Actions>; | ||
return this.#state.pipe( | ||
map(({ config }) => config), | ||
map(({ config }) => config as AppConfig<TEnv>), | ||
filterEmpty(), | ||
@@ -236,7 +246,7 @@ ); | ||
get config(): Readonly<AppConfig<TEnv>> | undefined { | ||
return this.state.config; | ||
get config(): AppConfig<TEnv> | undefined { | ||
return this.state.config as AppConfig<TEnv>; | ||
} | ||
get configAsync(): Promise<Readonly<AppConfig<TEnv>>> { | ||
get configAsync(): Promise<AppConfig<TEnv>> { | ||
return firstValueFrom(this.config$); | ||
@@ -243,0 +253,0 @@ } |
@@ -108,3 +108,3 @@ import { from, of, concat } from 'rxjs'; | ||
switchMap(({ payload }) => { | ||
const endpoint = [provider.getBaseUri(), payload].join('/').replace(/\/{2,}/g, '/'); | ||
const endpoint = [provider.assetUri, payload].join('/').replace(/\/{2,}/g, '/'); | ||
// dynamically import the application script | ||
@@ -111,0 +111,0 @@ return from(import(/* @vite-ignore */ endpoint)).pipe( |
@@ -1,5 +0,27 @@ | ||
import type { AppManifest, AppConfig, AppModulesInstance, AppScriptModule } from '../types'; | ||
import type { | ||
AppManifest, | ||
AppConfig, | ||
AppModulesInstance, | ||
AppScriptModule, | ||
ConfigEnvironment, | ||
} from '../types'; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type AppBundleState<TConfig = any, TModules = any> = { | ||
/** | ||
* Represents the state of an application bundle. | ||
* | ||
* @template TConfig - The type of the configuration environment, defaults to `ConfigEnvironment`. | ||
* @template TModules - The type of the modules, defaults to `any`. | ||
* | ||
* @property {string} appKey - A unique key identifying the application. | ||
* @property {Set<string>} status - A set of strings representing the status of the application. | ||
* @property {AppManifest} [manifest] - An optional manifest describing the application. | ||
* @property {AppConfig<TConfig>} [config] - An optional configuration object for the application. | ||
* @property {AppScriptModule} [modules] - An optional script module for the application. | ||
* @property {AppModulesInstance<TModules>} [instance] - An optional instance of the application modules. | ||
*/ | ||
export type AppBundleState< | ||
TConfig extends ConfigEnvironment = ConfigEnvironment, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
TModules = any, | ||
> = { | ||
appKey: string; | ||
@@ -13,6 +35,12 @@ status: Set<string>; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type AppBundleStateInitial<TConfig = any, TModules = any> = Omit< | ||
AppBundleState<TConfig, TModules>, | ||
'status' | ||
>; | ||
/** | ||
* Represents the initial state of an application bundle, excluding the 'status' property. | ||
* | ||
* @template TConfig - The configuration environment type, defaults to `ConfigEnvironment`. | ||
* @template TModules - The type of modules included in the application bundle, defaults to `any`. | ||
*/ | ||
export type AppBundleStateInitial< | ||
TConfig extends ConfigEnvironment = ConfigEnvironment, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
TModules = any, | ||
> = Omit<AppBundleState<TConfig, TModules>, 'status'>; |
@@ -9,6 +9,7 @@ import { catchError, map, Observable, ObservableInput } from 'rxjs'; | ||
import { ApiApplicationSchema } from './application.schema'; | ||
import { ApiApplicationSchema } from './schemas'; | ||
import { AppConfig, AppManifest } from './types'; | ||
import type { AppConfig, AppManifest, ConfigEnvironment } from './types'; | ||
import { AppConfigError, AppManifestError } from './errors'; | ||
import { AppConfigSelector } from './AppClient.Selectors'; | ||
@@ -29,3 +30,3 @@ export interface IAppClient extends Disposable { | ||
*/ | ||
getAppConfig: <TType = unknown>(args: { | ||
getAppConfig: <TType extends ConfigEnvironment = ConfigEnvironment>(args: { | ||
appKey: string; | ||
@@ -54,2 +55,3 @@ tag?: string; | ||
categoryId: category?.id, | ||
category, | ||
} as AppManifest; | ||
@@ -93,4 +95,6 @@ }); | ||
}, | ||
selector: async (res: Response) => | ||
ApplicationSchema.array().parse(await jsonSelector(res)), | ||
selector: async (res: Response) => { | ||
const response = (await jsonSelector(res)) as { value: unknown[] }; | ||
return ApplicationSchema.array().parse(response.value); | ||
}, | ||
}); | ||
@@ -107,2 +111,3 @@ }, | ||
return client.json(`/apps/${appKey}/builds/${tag}/config`, { | ||
selector: AppConfigSelector, | ||
headers: { | ||
@@ -141,3 +146,3 @@ 'Api-Version': '1.0', | ||
getAppConfig<TType = unknown>(args: { | ||
getAppConfig<TType extends ConfigEnvironment = ConfigEnvironment>(args: { | ||
appKey: string; | ||
@@ -144,0 +149,0 @@ tag?: string; |
@@ -15,3 +15,4 @@ import { | ||
client: IAppClient; | ||
baseUri?: string; | ||
// uri which to fetch the assets from aka the bundle of the application | ||
assetUri?: string; | ||
} | ||
@@ -25,3 +26,3 @@ | ||
) => void; | ||
setBaseUri: (base_or_cb: string | ConfigBuilderCallback<string>) => void; | ||
setAssetUri: (base_or_cb: string | ConfigBuilderCallback<string>) => void; | ||
} | ||
@@ -65,5 +66,5 @@ | ||
// TODO - explain why, used in import of resources aka proxy url | ||
public setBaseUri(base_or_cb: string | ConfigBuilderCallback<string>) { | ||
public setAssetUri(base_or_cb: string | ConfigBuilderCallback<string>) { | ||
const cb = typeof base_or_cb === 'string' ? async () => base_or_cb : base_or_cb; | ||
this._set('baseUri', cb); | ||
this._set('assetUri', cb); | ||
} | ||
@@ -83,4 +84,4 @@ | ||
if (!this._has('baseUri')) { | ||
this.setBaseUri('/apps-proxy'); | ||
if (!this._has('assetUri')) { | ||
this.setAssetUri('/apps-proxy'); | ||
} | ||
@@ -87,0 +88,0 @@ |
@@ -15,3 +15,3 @@ import { | ||
import type { AppConfig, AppManifest, CurrentApp } from './types'; | ||
import type { AppConfig, AppManifest, ConfigEnvironment, CurrentApp } from './types'; | ||
@@ -68,3 +68,3 @@ import { App, filterEmpty, IApp } from './app/App'; | ||
this.#appBaseUri = config.baseUri ?? ''; | ||
this.#appBaseUri = config.assetUri ?? ''; | ||
@@ -120,3 +120,3 @@ this.#subscription.add( | ||
*/ | ||
public getAppConfig<TType = unknown>( | ||
public getAppConfig<TType extends ConfigEnvironment = ConfigEnvironment>( | ||
appKey: string, | ||
@@ -142,3 +142,3 @@ tag?: string, | ||
public getBaseUri(): string { | ||
public get assetUri(): string { | ||
return this.#appBaseUri; | ||
@@ -145,0 +145,0 @@ } |
150
src/types.ts
@@ -1,2 +0,2 @@ | ||
import { AnyModule, CombinedModules, ModulesInstance } from '@equinor/fusion-framework-module'; | ||
import type { AnyModule, CombinedModules, ModulesInstance } from '@equinor/fusion-framework-module'; | ||
import type { EventModule } from '@equinor/fusion-framework-module-event'; | ||
@@ -6,4 +6,8 @@ import type { HttpModule } from '@equinor/fusion-framework-module-http'; | ||
import type { ServiceDiscoveryModule } from '@equinor/fusion-framework-module-service-discovery'; | ||
import IApp from './app'; | ||
import type { AppConfig } from './AppConfig'; | ||
import type IApp from './app'; | ||
export type ConfigEnvironment = Record<string, unknown>; | ||
export type { AppConfig } from './AppConfig'; | ||
// TODO | ||
@@ -13,6 +17,6 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type AppEnv<TConfig = unknown, TProps = unknown> = { | ||
export type AppEnv<TEnv extends ConfigEnvironment = ConfigEnvironment, TProps = unknown> = { | ||
basename?: string; | ||
manifest?: AppManifest; | ||
config?: AppConfig<TConfig>; | ||
config?: AppConfig<TEnv>; | ||
props?: TProps; | ||
@@ -24,43 +28,41 @@ }; | ||
// TODO: remove `report` and `launcher` when legacy apps are removed | ||
export type AppType = 'standalone' | 'report' | 'launcher' | 'template'; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type CurrentApp<TModules extends Array<AnyModule> = [], TEnv = any> = | ||
| IApp<TEnv, TModules> | ||
| null | ||
| undefined; | ||
export type CurrentApp< | ||
TModules extends Array<AnyModule> = [], | ||
TEnv extends ConfigEnvironment = ConfigEnvironment, | ||
> = IApp<TEnv, TModules> | null | undefined; | ||
export type AppAdmin = { | ||
type Nullable<T> = T | null | undefined; | ||
type AppPerson = { | ||
id: string; | ||
azureUniqueId?: string; | ||
displayName?: string; | ||
mail?: string; | ||
upn?: string; | ||
accountType?: string; | ||
accountClassification?: string; | ||
azureUniqueId: string; | ||
displayName: string; | ||
mail?: Nullable<string>; | ||
upn?: Nullable<string>; | ||
accountType: string; | ||
accountClassification?: Nullable<string>; | ||
isExpired?: Nullable<boolean>; | ||
}; | ||
export type AppOwner = AppAdmin; | ||
export type AppAdmin = AppPerson; | ||
export type AppOwner = AppPerson; | ||
export type AppBuildManifest = { | ||
version?: string; | ||
entryPoint?: string; | ||
tags?: string[]; | ||
tag?: 'latest' | 'preview'; | ||
assetPath?: string; | ||
configUrl?: string; | ||
timestamp?: string; | ||
commitSha?: string; | ||
githubRepo?: string; | ||
projectPage?: string; | ||
annotations?: Record<string, string>; | ||
allowedExtensions?: string[]; | ||
uploadedBy?: { | ||
azureUniqueId: string; | ||
displayName?: string; | ||
mail?: string; | ||
upn?: string; | ||
accountType?: string; | ||
accountClassification?: string; | ||
}; | ||
version: string; | ||
entryPoint: string; | ||
tags?: Nullable<string[]>; | ||
tag?: Nullable<'latest' | 'preview'>; | ||
assetPath?: Nullable<string>; | ||
configUrl?: Nullable<string>; | ||
timestamp?: Nullable<string>; | ||
commitSha?: Nullable<string>; | ||
githubRepo?: Nullable<string>; | ||
projectPage?: Nullable<string>; | ||
annotations?: Nullable<Record<string, string>>; | ||
allowedExtensions?: Nullable<string[]>; | ||
uploadedBy?: Nullable<AppOwner>; | ||
}; | ||
@@ -74,8 +76,8 @@ | ||
name?: string; | ||
displayName?: string; | ||
description?: string; | ||
type?: AppType; | ||
isPinned?: boolean; | ||
templateSource?: string; | ||
category?: { | ||
displayName: string; | ||
description: string; | ||
type: AppType; | ||
isPinned?: Nullable<boolean>; | ||
templateSource?: Nullable<string>; | ||
category?: Nullable<{ | ||
id: string; | ||
@@ -86,22 +88,15 @@ name: string; | ||
defaultIcon: string; | ||
sortOrder: 1000; | ||
}; | ||
visualization?: { | ||
color?: string; | ||
icon?: string; | ||
sortOrder: number; | ||
}; | ||
keywords?: string[]; | ||
admins?: AppAdmin[]; | ||
owners?: AppOwner[]; | ||
build?: AppBuildManifest; | ||
}>; | ||
visualization?: Nullable<{ | ||
color?: Nullable<string>; | ||
icon?: Nullable<string>; | ||
sortOrder: number; | ||
}>; | ||
keywords?: Nullable<string[]>; | ||
admins?: Nullable<AppAdmin[]>; | ||
owners?: Nullable<AppOwner[]>; | ||
build?: Nullable<AppBuildManifest>; | ||
} | ||
export type Endpoint = { url: string; scopes?: string[] }; | ||
export type AppConfig<TEnvironment = unknown> = { | ||
environment?: TEnvironment; | ||
endpoints?: Record<string, Endpoint>; | ||
}; | ||
/** | ||
@@ -111,3 +106,6 @@ * @template TEnvironment - name of hosted environment | ||
*/ | ||
export type AppBundle<TEnvironment = unknown, TModule = unknown> = { | ||
export type AppBundle< | ||
TEnvironment extends ConfigEnvironment = ConfigEnvironment, | ||
TModule = unknown, | ||
> = { | ||
manifest: AppManifest; | ||
@@ -135,31 +133,1 @@ config: AppConfig<TEnvironment>; | ||
ModulesInstance<AppModules<TModules>>; | ||
// export type ApiAppVersionConfig = { | ||
// environment: string; | ||
// endpoints: Record< | ||
// string, | ||
// { | ||
// url: string; | ||
// scopes: string[]; | ||
// } | ||
// >; | ||
// }; | ||
// export type ApiApp = { | ||
// appKey: string; | ||
// displayName?: string; | ||
// description?: string; | ||
// type?: AppType; | ||
// isPinned?: boolean; | ||
// templateSource?: string; | ||
// category?: AppCategory; | ||
// visualization: { | ||
// color: string; | ||
// icon: string; | ||
// sortOrder: number; | ||
// }; | ||
// keywords: string[]; | ||
// admins: AppOwnerOrAdmin[]; | ||
// owners: AppOwnerOrAdmin[]; | ||
// build: AppBuild<AzureUniqueId>; | ||
// }; |
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
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
399951
90
4407