@monterosa/sdk-interact-kit 0.17.1-rc.6

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.
Files changed (47) hide show
  1. package/README.md +1 -0
  2. package/dist/index.cjs.js +2709 -0
  3. package/dist/index.cjs.js.map +1 -0
  4. package/dist/index.esm2017.js +1894 -0
  5. package/dist/index.esm2017.js.map +1 -0
  6. package/dist/index.esm5.js +2673 -0
  7. package/dist/index.esm5.js.map +1 -0
  8. package/dist/jest/helpers/language.d.ts +12 -0
  9. package/dist/src/api.d.ts +38 -0
  10. package/dist/src/core/connect/api.d.ts +16 -0
  11. package/dist/src/core/connect/connect_impl.d.ts +34 -0
  12. package/dist/src/core/connect/index.d.ts +12 -0
  13. package/dist/src/core/connect/public-types.d.ts +64 -0
  14. package/dist/src/core/connection_health/connection_health_impl.d.ts +21 -0
  15. package/dist/src/core/connection_health/index.d.ts +24 -0
  16. package/dist/src/core/connection_health/public-types.d.ts +34 -0
  17. package/dist/src/core/element/answer.d.ts +66 -0
  18. package/dist/src/core/element/api.d.ts +235 -0
  19. package/dist/src/core/element/context.d.ts +18 -0
  20. package/dist/src/core/element/element_impl.d.ts +62 -0
  21. package/dist/src/core/element/factory.d.ts +21 -0
  22. package/dist/src/core/element/index.d.ts +15 -0
  23. package/dist/src/core/element/public-types.d.ts +228 -0
  24. package/dist/src/core/element/types.d.ts +93 -0
  25. package/dist/src/core/event/api.d.ts +84 -0
  26. package/dist/src/core/event/context.d.ts +16 -0
  27. package/dist/src/core/event/event_impl.d.ts +53 -0
  28. package/dist/src/core/event/factory.d.ts +22 -0
  29. package/dist/src/core/event/index.d.ts +13 -0
  30. package/dist/src/core/event/internal.d.ts +12 -0
  31. package/dist/src/core/event/public-types.d.ts +119 -0
  32. package/dist/src/core/event/types.d.ts +32 -0
  33. package/dist/src/core/index.d.ts +15 -0
  34. package/dist/src/core/project/api.d.ts +36 -0
  35. package/dist/src/core/project/constants.d.ts +11 -0
  36. package/dist/src/core/project/context.d.ts +14 -0
  37. package/dist/src/core/project/factory.d.ts +16 -0
  38. package/dist/src/core/project/index.d.ts +13 -0
  39. package/dist/src/core/project/internal.d.ts +12 -0
  40. package/dist/src/core/project/project_impl.d.ts +51 -0
  41. package/dist/src/core/project/public-types.d.ts +158 -0
  42. package/dist/src/index.d.ts +17 -0
  43. package/dist/src/services/http_request.d.ts +47 -0
  44. package/dist/src/types.d.ts +18 -0
  45. package/dist/src/utils/calculate_percentage.d.ts +11 -0
  46. package/dist/src/utils/locale.d.ts +20 -0
  47. package/package.json +50 -0
@@ -0,0 +1,84 @@
1
+ import { Unsubscribe } from '@monterosa/sdk-util';
2
+ import { InteractEvent, EventState } from './public-types';
3
+ import { InteractProject } from '../project/public-types';
4
+ /**
5
+ * @internal
6
+ */
7
+ declare const getEventsMemoized: (...args: any[]) => Promise<InteractEvent[]>;
8
+ /**
9
+ * Returns all events in a project, including all active events and
10
+ * past/upcoming events, according to Listings settings in Project Setup
11
+ * in Studio.
12
+ *
13
+ * @param project - A project instance. If not provided,
14
+ * the one from the default sdk will be fetched.
15
+ */
16
+ declare function getEvents(project?: InteractProject): Promise<InteractEvent[]>;
17
+ /**
18
+ * @internal
19
+ */
20
+ declare const getEventMemoized: (...args: any[]) => Promise<InteractEvent | null>;
21
+ /**
22
+ * Returns an event by its id
23
+ *
24
+ * @param id - Id of the event
25
+ * @param project - A project instance. If not provided,
26
+ * the one from the default sdk will be fetched.
27
+ *
28
+ * @returns A an event associated with the provided id and project or null if no such
29
+ * event exists in the project.
30
+ */
31
+ declare function getEvent(id: string, project?: InteractProject): Promise<InteractEvent | null>;
32
+ /**
33
+ * Adds an observer for when {@link InteractEvent.state | event state} changed
34
+ */
35
+ declare function onEventState(event: InteractEvent, callback: (state: EventState) => void): Unsubscribe;
36
+ /**
37
+ * Adds an observer for when event's data changed
38
+ */
39
+ declare function onEventUpdated(event: InteractEvent, callback: () => void): Unsubscribe;
40
+ /**
41
+ * Adds an observer that is called when an event is added to listings.
42
+ *
43
+ * @remarks
44
+ * The following actions will result in adding an event to listings:
45
+ *
46
+ * - The start of the event in Studio
47
+ *
48
+ * - The scheduling of a future event in Studio, when listings are configured
49
+ * to include future events in Project Settings.
50
+ *
51
+ * - When a future event starts, a new future event may be added to the list,
52
+ * depending on the project configuration, to ensure a minimum number of
53
+ * upcoming events are always available.
54
+ */
55
+ declare function onEventAdded(project: InteractProject, callback: (event: InteractEvent) => void): Unsubscribe;
56
+ /**
57
+ * {@link onEventAdded} alias.
58
+ *
59
+ * @deprecated Use the new {@link onEventAdded} function instead.
60
+ */
61
+ declare function onEventPublished(project: InteractProject, callback: (event: InteractEvent) => void): Unsubscribe;
62
+ /**
63
+ * Adds an observer that is called when an event is removed from listings.
64
+ *
65
+ * @remarks
66
+ * The following actions will result in removing an event from listings:
67
+ *
68
+ * - The deletion of the event from Studio
69
+ *
70
+ * - The change of listings confuguration in Project Settings to exclude future
71
+ * or past events.
72
+ *
73
+ * - The event is removed after a period of time since its completion. This period
74
+ * is calculated as 45 seconds plus the Maximum allowed delay (configured in
75
+ * Project Settings in Studio).
76
+ */
77
+ declare function onEventRemoved(project: InteractProject, callback: (event: InteractEvent) => void): Unsubscribe;
78
+ /**
79
+ * Returns the list of upcoming events
80
+ */
81
+ /**
82
+ * Returns the list of active events
83
+ */
84
+ export { getEvents, getEventsMemoized, getEvent, getEventMemoized, onEventState, onEventUpdated, onEventAdded, onEventPublished, onEventRemoved, };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @license
3
+ * context.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-22
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ import { MonterosaSdk } from '@monterosa/sdk-core';
12
+ import { InteractProject } from '../project/public-types';
13
+ export interface EventContext {
14
+ sdk: MonterosaSdk;
15
+ project: InteractProject;
16
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license
3
+ * event_impl.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ import { Emitter } from '@monterosa/sdk-util';
12
+ import { EventContext } from './context';
13
+ import { EventOptions, EventHistory } from './types';
14
+ import { InteractEvent, EventState, InitState } from './public-types';
15
+ /**
16
+ * @internal
17
+ */
18
+ export declare class EventImpl extends Emitter implements InteractEvent {
19
+ readonly _data: EventOptions;
20
+ private _context;
21
+ private _state;
22
+ private _internalState;
23
+ private _initState;
24
+ private _history;
25
+ private unsubscribeStateHandler;
26
+ private unsubscribeInternalStateHandler;
27
+ private unsubscribeListingsHandler;
28
+ constructor(data: EventOptions, context: EventContext);
29
+ private calculateState;
30
+ private calculateInternalState;
31
+ private handleState;
32
+ private handleInternalState;
33
+ private handleListings;
34
+ /** @internal */
35
+ destroy(): void;
36
+ get context(): EventContext;
37
+ get id(): string;
38
+ get name(): string;
39
+ get startAt(): number;
40
+ get startAtIso(): string;
41
+ get endAt(): number;
42
+ get endAtIso(): string;
43
+ get duration(): number;
44
+ get fields(): Record<string, unknown>;
45
+ get state(): EventState;
46
+ get internalState(): EventState;
47
+ get initState(): InitState;
48
+ set initState(state: InitState);
49
+ get history(): EventHistory | null;
50
+ set history(value: EventHistory | null);
51
+ get canSubscribe(): boolean;
52
+ get canLoadHistory(): boolean;
53
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license
3
+ * factory.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-22
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ import { Unsubscribe } from '@monterosa/sdk-util';
12
+ import { EventContext } from './context';
13
+ import { EventOptions } from './types';
14
+ import { InteractEvent } from './public-types';
15
+ export declare const events: Map<string, InteractEvent>;
16
+ export declare const healthListeners: Map<string, Unsubscribe>;
17
+ export declare function buildEvent(options: EventOptions, context: EventContext): InteractEvent;
18
+ export declare function init(event: InteractEvent): Promise<void>;
19
+ /** @internal */
20
+ export declare function terminate(event: InteractEvent): Promise<void>;
21
+ export declare function subscribe(event: InteractEvent): Promise<void>;
22
+ export declare function unsubscribe(event: InteractEvent): Promise<void>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * index.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ export * from './api';
12
+ export * from './event_impl';
13
+ export { InteractEvent, EventState } from './public-types';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @license
3
+ * internal.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-24
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ import { EventHistory } from './types';
12
+ export declare function fetchHistory(host: string, id: string): Promise<EventHistory>;
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @license
3
+ * public-types.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-03-24
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ import { Emitter } from '@monterosa/sdk-util';
12
+ import { EventHistory } from './types';
13
+ import { EventContext } from './context';
14
+ /**
15
+ * Describes the event state.
16
+ */
17
+ export declare enum EventState {
18
+ /**
19
+ * The event is in the `upcoming` state when its {@link InteractEvent.startAt | start time}
20
+ * less than the {@link now | current time}.
21
+ */
22
+ Upcoming = "upcoming",
23
+ /**
24
+ * The event is in the `active` state when its {@link InteractEvent.startAt | start time}
25
+ * equal or more than the {@link now | current time} and less than the
26
+ * {@link InteractEvent.endAt | end time}.
27
+ */
28
+ Active = "active",
29
+ /**
30
+ * @internal
31
+ */
32
+ Prolonged = "prolonged",
33
+ /**
34
+ * The event is in the `finished` state when its {@link InteractEvent.endAt | end time}
35
+ * equal or more than the {@link now | current time}.
36
+ */
37
+ Finished = "finished"
38
+ }
39
+ export declare enum InitState {
40
+ Uninitialised = "uninitialised",
41
+ Initialising = "initialising",
42
+ Initialised = "initialised"
43
+ }
44
+ /**
45
+ * An instance of
46
+ * {@link https://products.monterosa.co/mic/core-concepts/schedule-and-events | Monterosa / Interaction Cloud Event}
47
+ * that holds all of its information.
48
+ *
49
+ * Event represent either a sports game, TV show or simply a period of time in
50
+ * which you want to push out interactivity to users. When you create an event
51
+ * you can specify: duration, start time, start mode and
52
+ * {@link https://products.monterosa.co/mic/developer-guides/app-spec/event-settings-spec | custom fields}
53
+ * that can be confgured by a developers
54
+ */
55
+ export interface InteractEvent extends Emitter {
56
+ /**
57
+ * Event uuid.
58
+ */
59
+ id: string;
60
+ /**
61
+ * Event name.
62
+ */
63
+ name: string;
64
+ /**
65
+ * Returns the event start time as UNIX time in seconds.
66
+ */
67
+ startAt: number;
68
+ /**
69
+ * Returns the event start time as ISO string.
70
+ */
71
+ startAtIso: string;
72
+ /**
73
+ * Returns the event end time as UNIX time in seconds.
74
+ */
75
+ endAt: number;
76
+ /**
77
+ * Returns the event end time as ISO string.
78
+ */
79
+ endAtIso: string;
80
+ /**
81
+ * Studio supports custom fields within Event. This returns an object
82
+ * populated with the custom fields. Object property names will match keys
83
+ * as provided as part of custom fields definition in the feed and values
84
+ * will be as collected by Studio.
85
+ *
86
+ * @example
87
+ * ```javascript
88
+ * // {
89
+ * // "name": "Canis lupus",
90
+ * // "family": "Canidae",
91
+ * // ...
92
+ * // "species": "C. lupus"
93
+ * // }
94
+ * ```
95
+ */
96
+ fields: Record<string, unknown>;
97
+ /**
98
+ * Event state
99
+ */
100
+ state: EventState;
101
+ /**
102
+ * Returns the total duration in seconds of the event.
103
+ */
104
+ duration: number;
105
+ /** @internal */
106
+ canSubscribe: boolean;
107
+ /** @internal */
108
+ canLoadHistory: boolean;
109
+ /** @internal */
110
+ internalState: EventState;
111
+ /** @internal */
112
+ initState: InitState;
113
+ /** @internal */
114
+ context: EventContext;
115
+ /** @internal */
116
+ history: EventHistory | null;
117
+ /** @internal */
118
+ destroy(): void;
119
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @license
3
+ * types.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ import { Localised } from '../../types';
12
+ import { ElementOptions } from '../element/types';
13
+ export interface EventOptions {
14
+ id: string;
15
+ name: string;
16
+ start_at: number;
17
+ start_at_iso: string;
18
+ end_at: number;
19
+ end_at_iso: string;
20
+ started: boolean;
21
+ custom_fields: Localised<Record<string, unknown>>;
22
+ extra_time: number;
23
+ on_demand_time: number;
24
+ duration: number;
25
+ original_duration: number;
26
+ digest: string;
27
+ }
28
+ export interface EventHistory {
29
+ timeline: ElementOptions[];
30
+ config: EventOptions;
31
+ version: number;
32
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * index.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ export * from './connect';
12
+ export * from './connection_health';
13
+ export * from './project';
14
+ export * from './event';
15
+ export * from './element';
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * api.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ import { MonterosaSdk } from '@monterosa/sdk-core';
12
+ import { Unsubscribe } from '@monterosa/sdk-util';
13
+ import { InteractProject, Listings } from './public-types';
14
+ /**
15
+ * @internal
16
+ */
17
+ declare const getProjectMemoized: (...args: any[]) => Promise<InteractProject>;
18
+ /**
19
+ * Returns {@link InteractProject | project instance} associated
20
+ * with the {@link @monterosa/sdk-core#MonterosaSdk | configured sdk}
21
+ */
22
+ declare function getProject(sdk?: MonterosaSdk): Promise<InteractProject>;
23
+ /**
24
+ * @internal
25
+ */
26
+ export declare function fetchListings(host: string, projectId: string): Promise<Listings>;
27
+ /**
28
+ * Adds an observer for when {@link InteractProject.fields | project fields}
29
+ * are updated
30
+ */
31
+ declare function onProjectFieldsUpdated(project: InteractProject, callback: () => void): Unsubscribe;
32
+ /**
33
+ * @internal
34
+ */
35
+ declare function onProjectListingsUpdated(project: InteractProject, callback: () => void): Unsubscribe;
36
+ export { getProject, getProjectMemoized, onProjectFieldsUpdated, onProjectListingsUpdated, };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * constants.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-06-02
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ export declare const DEFAULT_IGNORE_TIME = 30;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license
3
+ * context.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-22
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ import { MonterosaSdk } from '@monterosa/sdk-core';
12
+ export interface ProjectContext {
13
+ sdk: MonterosaSdk;
14
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @license
3
+ * factory.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ import { ProjectContext } from './context';
12
+ import { InteractProject, ProjectOptions } from './public-types';
13
+ import { Message } from '../connect';
14
+ export declare const projects: Map<string, InteractProject>;
15
+ export declare function buildProject(options: ProjectOptions, context: ProjectContext): Promise<InteractProject>;
16
+ export declare function handleConnectMessage(message: Message): Promise<void>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * index.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ export * from './api';
12
+ export * from './project_impl';
13
+ export { InteractProject, ExtensionAsset } from './public-types';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @license
3
+ * internal.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ import { Localised } from '../../types';
12
+ export declare function fetchSettings(host: string, id: string): Promise<Localised<Record<string, unknown>>>;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @license
3
+ * project_impl.ts
4
+ * interact-kit
5
+ *
6
+ * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
7
+ * Copyright © 2022 Monterosa. All rights reserved.
8
+ *
9
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
10
+ */
11
+ import { Emitter } from '@monterosa/sdk-util';
12
+ import { ProjectContext } from './context';
13
+ import { InteractProject, Listings, ProjectOptions } from './public-types';
14
+ import { Localised } from '../../types';
15
+ import { EventOptions } from '../event/types';
16
+ /**
17
+ * @internal
18
+ */
19
+ export declare class ProjectImpl extends Emitter implements InteractProject {
20
+ host: string;
21
+ id: string;
22
+ private _context;
23
+ private _listings;
24
+ private _fields;
25
+ private _locales;
26
+ private _locale;
27
+ constructor(options: ProjectOptions, context: ProjectContext);
28
+ get context(): ProjectContext;
29
+ get embedUrl(): string;
30
+ get uuid(): string;
31
+ get events(): EventOptions[];
32
+ get listings(): Listings;
33
+ set listings(value: Listings);
34
+ get isLocalisationSupported(): boolean;
35
+ get locale(): string;
36
+ set locale(locale: string);
37
+ get locales(): string[];
38
+ get fields(): Record<string, unknown>;
39
+ /**
40
+ * Sets custom fields
41
+ *
42
+ * It accepts both Localised<Record<string, unknown>> and Record<string, unknown> to
43
+ * avoid mistyping between setter and getter
44
+ *
45
+ * @internal
46
+ */
47
+ set fields(value: Localised<Record<string, unknown>> | Record<string, unknown>);
48
+ get extensions(): Record<string, import("./public-types").ExtensionAsset[]>;
49
+ get historyIgnore(): number;
50
+ delete(): void;
51
+ }