@telia-ace/widget-core-flamingo 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ import { Trigger } from '../components/trigger.component';
2
+ import { WidgetComponentType } from '../components/widget.component';
3
+ import { Wrapper } from '../components/wrapper.component';
4
+ import { ComponentPlatform } from '../services/component-platform';
5
+ import { StorageService } from '../services/storage.service';
6
+ import { TextsService } from '../services/texts.service';
7
+ import { WidgetAPI } from '../services/widget-api';
8
+ import { ApplicationOptions, PluginType, RenderStrategy, TriggerIcon, WidgetAnchor, WidgetConfig } from '../types';
9
+ import { Container } from './container';
10
+ export declare class Application {
11
+ id: string;
12
+ name: string;
13
+ container: Container;
14
+ settings: WidgetConfig;
15
+ private options;
16
+ platform: ComponentPlatform;
17
+ texts: TextsService;
18
+ storage: StorageService;
19
+ root?: Wrapper;
20
+ renderStrategy: RenderStrategy;
21
+ triggerIcon?: TriggerIcon;
22
+ anchor: WidgetAnchor;
23
+ autoActivate: boolean;
24
+ private plugins;
25
+ private componentResolver;
26
+ private components;
27
+ trigger: Trigger | null;
28
+ api: WidgetAPI;
29
+ constructor(id: string, name: string, container: Container, settings: WidgetConfig, options: ApplicationOptions);
30
+ activate(): Promise<void>;
31
+ private loadPlugins;
32
+ styles(): Record<string, any>;
33
+ branding(): Record<string, any>;
34
+ plugin(plugin: PluginType): this;
35
+ appendToDOM(): void;
36
+ hide(): void;
37
+ setZIndex(zIndex: number): void;
38
+ mute(): void;
39
+ unmute(): void;
40
+ registerComponent(type: string, component: any): void;
41
+ resolveComponent(type: string): any;
42
+ mountComponent(component: WidgetComponentType): void;
43
+ getComponent<T extends WidgetComponentType>(type: string): T | null;
44
+ private _getTargetElement;
45
+ render(): Trigger | Wrapper | undefined;
46
+ }
@@ -0,0 +1,16 @@
1
+ import { BehaviorSubject } from 'rxjs';
2
+ import { Environment } from './environment';
3
+ export declare enum ContainerState {
4
+ Loading = "loading",
5
+ Ready = "ready"
6
+ }
7
+ export declare class Container {
8
+ name: string;
9
+ environment: Environment;
10
+ state: BehaviorSubject<ContainerState>;
11
+ private resolvers;
12
+ constructor(name: string, environment: Environment);
13
+ setState(state: ContainerState): void;
14
+ register(name: string, value: unknown): Promise<void>;
15
+ get<T>(name: string): Promise<T | undefined>;
16
+ }
@@ -0,0 +1,25 @@
1
+ import { Application } from './application';
2
+ import { Container } from './container';
3
+ import { ApplicationOptions, PluginType, WidgetConfig } from '../types';
4
+ import { WidgetAPI } from '../services/widget-api';
5
+ import { SiteAPI } from '../services/site-api';
6
+ import { Site } from './site';
7
+ export type WidgetAPIHandler = (widget?: WidgetAPI) => void;
8
+ export type SiteConfigurationHandler = (site: SiteAPI) => void;
9
+ export declare class Environment {
10
+ applications: Application[];
11
+ container: Container;
12
+ private bootstrapped;
13
+ private site;
14
+ widgetAPIHandlers: Map<string, WidgetAPIHandler[]>;
15
+ siteConfigurationHandlers: SiteConfigurationHandler[];
16
+ constructor();
17
+ bootstrap(): Promise<void>;
18
+ private activate;
19
+ private notifyWidgetsOfCreation;
20
+ configure(delegate: SiteConfigurationHandler): void;
21
+ widget(name: string, delegate: WidgetAPIHandler): void;
22
+ registerApp(id: string, name: string, config: WidgetConfig, options: ApplicationOptions): void;
23
+ registerSite(site: Site): void;
24
+ plugin(plugin: PluginType): this;
25
+ }
@@ -0,0 +1,15 @@
1
+ import { SiteAPI } from '../services/site-api';
2
+ import { InitConfig } from '../types';
3
+ import { Environment } from './environment';
4
+ export declare class Site {
5
+ environment?: Environment;
6
+ private configurations;
7
+ private url?;
8
+ private httpClient;
9
+ api: SiteAPI;
10
+ constructor(urlOrConfig: string | InitConfig);
11
+ load(url: string): Promise<void>;
12
+ loadFromConfig(config: InitConfig): void;
13
+ bootstrap(handler: (environment: Environment) => void): Promise<void>;
14
+ private addGlobal;
15
+ }
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@telia-ace/widget-core-flamingo",
3
+ "version": "0.0.1",
4
+ "dependencies": {
5
+ "lit": "^3.0.2",
6
+ "@teliads/icons": "^8.4.0",
7
+ "rxjs": "^7.8.1",
8
+ "lit-html": "^3.0.2",
9
+ "@lit-labs/motion": "^1.0.6",
10
+ "@lit/context": "^1.0.1"
11
+ },
12
+ "main": "./index.js",
13
+ "module": "./index.mjs",
14
+ "typings": "./index.d.ts"
15
+ }
@@ -0,0 +1,13 @@
1
+ import { WidgetComponentType } from '../components/widget.component';
2
+ import { Wrapper } from '../components/wrapper.component';
3
+ import { Application } from '../models/application';
4
+ import { WidgetConfig } from '../types';
5
+ export declare class ComponentPlatform {
6
+ private root;
7
+ constructor();
8
+ createComponentModel(settings: WidgetConfig, application: Application): Wrapper;
9
+ createRoot(): Wrapper;
10
+ createNode(name: string, type: string): WidgetComponentType;
11
+ private resolveComponent;
12
+ getRoot(): Wrapper;
13
+ }
@@ -0,0 +1,8 @@
1
+ export declare class ComponentResolver {
2
+ components: Map<string, any>;
3
+ getComponent(type: string): any;
4
+ registerComponent(type: string, component: any): void;
5
+ loadComponents(): Promise<void>;
6
+ private defineAsWebComponent;
7
+ static ResolveWebComponentName: (widgetComponentName: string) => string;
8
+ }
@@ -0,0 +1,18 @@
1
+ import { SiteConfig, WidgetConfig } from '../types';
2
+ type GetWidgetResponse = {
3
+ name: string;
4
+ config: WidgetConfig;
5
+ };
6
+ export interface IHttpClient {
7
+ getSite(url: string): Promise<SiteConfig | null>;
8
+ getWidget(widgetId: string): Promise<GetWidgetResponse | null>;
9
+ }
10
+ export declare const createHttpClient: (endpoint?: string) => IHttpClient;
11
+ export declare class HttpClient implements IHttpClient {
12
+ private _endpoint;
13
+ private static endpoint;
14
+ constructor(_endpoint?: string);
15
+ getSite(url: string): Promise<SiteConfig | null>;
16
+ getWidget(widgetId: string): Promise<GetWidgetResponse | null>;
17
+ }
18
+ export {};
@@ -0,0 +1,7 @@
1
+ import { Site } from '../models/site';
2
+ export declare class SiteAPI {
3
+ private site;
4
+ constructor(site: Site);
5
+ storagePolicy(policies: string[]): void;
6
+ disallowStorageKey(key: string): void;
7
+ }
@@ -0,0 +1,19 @@
1
+ export declare enum StorageCategory {
2
+ Necessary = "necessary",
3
+ Functional = "functional",
4
+ Analytics = "analytics"
5
+ }
6
+ export declare class StorageService {
7
+ private storage;
8
+ private policy;
9
+ private widgetId;
10
+ private disallowedKeys;
11
+ constructor(widgetId: string, storageType: 'localStorage' | 'sessionStorage', policy: Record<StorageCategory, boolean>);
12
+ set<T>(key: string, value: T, category: StorageCategory): void;
13
+ get<T>(key: string): T | null;
14
+ removeItem(key: string): void;
15
+ enforcePolicy(): void;
16
+ updatePolicy(newPolicy: Record<StorageCategory, boolean>): void;
17
+ disallowKey(key: string): void;
18
+ private _prefixKey;
19
+ }
@@ -0,0 +1,10 @@
1
+ export interface ITextsService {
2
+ loadTexts(texts: Record<string, string>): void;
3
+ get(key: string): string | null;
4
+ }
5
+ export declare class TextsService implements ITextsService {
6
+ private texts;
7
+ loadTexts(texts: Record<string, string>): void;
8
+ get(key: string, fallback?: string): string | null;
9
+ getOrFallback(key: string, fallback: string): string;
10
+ }
@@ -0,0 +1,9 @@
1
+ import { Application } from '../models/application';
2
+ export declare class WidgetAPI {
3
+ private widget;
4
+ name: string;
5
+ constructor(widget: Application);
6
+ open(): void;
7
+ close(): void;
8
+ setZIndex(zIndex: number): void;
9
+ }
package/types.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { Application } from './models/application';
2
+ import { IHttpClient } from './services/http-client.service';
3
+ export type ComponentDefinition = {
4
+ name: string;
5
+ type: string;
6
+ properties?: Record<string, any>;
7
+ context?: Record<string, any>;
8
+ layout?: Record<string, any>;
9
+ children?: string[];
10
+ };
11
+ export type WidgetConfig = {
12
+ entry: string;
13
+ texts?: Record<string, string>;
14
+ components: Record<string, ComponentDefinition>;
15
+ branding: Record<string, any>;
16
+ styles?: Record<string, any>;
17
+ survey?: Record<string, any>;
18
+ };
19
+ export declare enum RenderStrategy {
20
+ Inline = "inline",
21
+ Trigger = "trigger"
22
+ }
23
+ export type ApplicationOptions = {
24
+ renderStrategy: RenderStrategy;
25
+ triggerIcon?: TriggerIcon;
26
+ autoActivate?: boolean;
27
+ anchor?: WidgetAnchor;
28
+ };
29
+ export type TriggerIcon = {
30
+ type: string;
31
+ content: string;
32
+ };
33
+ export type AppConfig = {
34
+ id: string;
35
+ widgetId: string;
36
+ renderStrategy: RenderStrategy;
37
+ triggerIcon?: TriggerIcon;
38
+ autoActivate?: boolean;
39
+ anchor?: WidgetAnchor;
40
+ };
41
+ export type SiteConfig = {
42
+ id: string;
43
+ apps: AppConfig[];
44
+ };
45
+ export type InitConfig = {
46
+ apps: {
47
+ widgetId: string;
48
+ renderStrategy?: 'inline' | 'trigger';
49
+ triggerIcon?: string;
50
+ autoActivate?: boolean;
51
+ anchor?: WidgetAnchor;
52
+ }[];
53
+ httpClient?: IHttpClient;
54
+ };
55
+ export type PluginType = (app: Application) => Promise<void>;
56
+ export type WidgetAnchor = 'BottomRight' | 'BottomLeft';
@@ -0,0 +1 @@
1
+ export declare const mapBranding: (context: Record<string, any>, el: HTMLElement) => void;