@trackunit/iris-app-runtime-core 1.17.5 → 1.17.7
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.
- package/index.cjs.js +126 -19
- package/index.esm.js +127 -21
- package/package.json +3 -3
- package/src/HostConnector.d.ts +42 -6
package/index.cjs.js
CHANGED
|
@@ -6,40 +6,146 @@ var penpal = require('penpal');
|
|
|
6
6
|
const doNothingByDefault = () => {
|
|
7
7
|
// do nothing by default
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Registry of handlers for the host-driven subscription methods that the host
|
|
11
|
+
* pushes through the `host-runtime` channel. Providers (e.g.
|
|
12
|
+
* `TokenProviderIrisApp`) install their real handler via
|
|
13
|
+
* {@link registerHostChangeHandler}, replacing the `doNothingByDefault`
|
|
14
|
+
* placeholder until they unmount.
|
|
15
|
+
*
|
|
16
|
+
* v6's original design used a separate penpal connection per provider on
|
|
17
|
+
* dedicated channels (`token-subscription`, `time-range-subscription`, …)
|
|
18
|
+
* which worked only because v6's multi-connection bug caused the host's
|
|
19
|
+
* single `connectToChild` to receive messages from all of them. With v7's
|
|
20
|
+
* proper channel isolation, that arrangement silently drops every push event
|
|
21
|
+
* because the host only opens the `host-runtime` channel. This registry
|
|
22
|
+
* collapses all subscription methods back onto the host-runtime channel so
|
|
23
|
+
* they fire reliably without forcing the host to open one connection per
|
|
24
|
+
* channel.
|
|
25
|
+
*/
|
|
26
|
+
const subscriptionHandlers = {
|
|
27
|
+
onFilterBarValuesChanged: doNothingByDefault,
|
|
28
|
+
onTokenChanged: doNothingByDefault,
|
|
29
|
+
onAssetSortingStateChanged: doNothingByDefault,
|
|
30
|
+
onAssetsFilterBarValuesChanged: doNothingByDefault,
|
|
31
|
+
onCustomersFilterBarValuesChanged: doNothingByDefault,
|
|
32
|
+
onSitesFilterBarValuesChanged: doNothingByDefault,
|
|
33
|
+
onTablePersistenceStateChanged: doNothingByDefault,
|
|
34
|
+
onTimeRangeChanged: doNothingByDefault,
|
|
35
|
+
onWidgetPollIntervalChanged: doNothingByDefault,
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Install a handler for one of the host-driven subscription methods on the
|
|
39
|
+
* singleton `host-runtime` channel. Returns an unregister function that
|
|
40
|
+
* restores the previously installed handler (typically the
|
|
41
|
+
* `doNothingByDefault` no-op); call it from the effect's cleanup.
|
|
42
|
+
*
|
|
43
|
+
* Safe to call before the singleton's penpal handshake completes: the
|
|
44
|
+
* singleton's child-facing methods look up the current handler at call time,
|
|
45
|
+
* so handlers registered after `connect()` has resolved still receive events.
|
|
46
|
+
*/
|
|
47
|
+
const registerHostChangeHandler = (name, handler) => {
|
|
48
|
+
const previous = subscriptionHandlers[name];
|
|
49
|
+
subscriptionHandlers[name] = handler;
|
|
50
|
+
return () => {
|
|
51
|
+
// Only restore if we're still the active handler — a newer mount may have
|
|
52
|
+
// installed its own handler in the meantime, and we don't want this stale
|
|
53
|
+
// cleanup to clobber it.
|
|
54
|
+
if (subscriptionHandlers[name] === handler) {
|
|
55
|
+
subscriptionHandlers[name] = previous;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const dispatchToHandler = (name) => {
|
|
60
|
+
// The closure dispatches at call time so handlers registered after the
|
|
61
|
+
// singleton's connect() has resolved still receive events.
|
|
62
|
+
const dispatch = (...args) => {
|
|
63
|
+
const handler = subscriptionHandlers[name];
|
|
64
|
+
return handler(...args);
|
|
65
|
+
};
|
|
66
|
+
return dispatch;
|
|
67
|
+
};
|
|
9
68
|
/**
|
|
10
69
|
* Setup using the subscribedMethods to subscribe to events from the host.
|
|
11
70
|
*
|
|
12
|
-
* @param subscribedMethods the methods to subscribe to
|
|
13
|
-
*
|
|
71
|
+
* @param subscribedMethods the methods to subscribe to. Any key omitted here
|
|
72
|
+
* dispatches through the {@link registerHostChangeHandler} registry on the
|
|
73
|
+
* singleton connection, so internal callers can register handlers via that
|
|
74
|
+
* path without opening a second penpal connection.
|
|
75
|
+
* @param channel the penpal channel to use; defaults to `undefined`. The
|
|
76
|
+
* default singleton on the iris-app side intentionally omits the channel so
|
|
77
|
+
* the host's matching `connect()` call (which also omits it) can accept
|
|
78
|
+
* both native v7 SYNs and v6 SYNs translated by penpal's v6-compat shim
|
|
79
|
+
* (`upgradeMessage` produces v7 messages with `channel: undefined`). External
|
|
80
|
+
* callers can still pin a channel for isolated parallel connections; the
|
|
81
|
+
* host won't auto-handshake those — they're for caller-managed transports.
|
|
82
|
+
* @returns { Connection<HostConnectorMethods> } the connection to the host
|
|
14
83
|
*/
|
|
15
|
-
const setupHostConnector = (subscribedMethods) => {
|
|
84
|
+
const setupHostConnector = (subscribedMethods, channel) => {
|
|
16
85
|
const methods = {
|
|
17
|
-
onFilterBarValuesChanged:
|
|
18
|
-
onTokenChanged:
|
|
19
|
-
onAssetSortingStateChanged:
|
|
20
|
-
onAssetsFilterBarValuesChanged:
|
|
21
|
-
onCustomersFilterBarValuesChanged:
|
|
22
|
-
onSitesFilterBarValuesChanged:
|
|
23
|
-
onTablePersistenceStateChanged:
|
|
24
|
-
onTimeRangeChanged:
|
|
25
|
-
onWidgetPollIntervalChanged:
|
|
86
|
+
onFilterBarValuesChanged: dispatchToHandler("onFilterBarValuesChanged"),
|
|
87
|
+
onTokenChanged: dispatchToHandler("onTokenChanged"),
|
|
88
|
+
onAssetSortingStateChanged: dispatchToHandler("onAssetSortingStateChanged"),
|
|
89
|
+
onAssetsFilterBarValuesChanged: dispatchToHandler("onAssetsFilterBarValuesChanged"),
|
|
90
|
+
onCustomersFilterBarValuesChanged: dispatchToHandler("onCustomersFilterBarValuesChanged"),
|
|
91
|
+
onSitesFilterBarValuesChanged: dispatchToHandler("onSitesFilterBarValuesChanged"),
|
|
92
|
+
onTablePersistenceStateChanged: dispatchToHandler("onTablePersistenceStateChanged"),
|
|
93
|
+
onTimeRangeChanged: dispatchToHandler("onTimeRangeChanged"),
|
|
94
|
+
onWidgetPollIntervalChanged: dispatchToHandler("onWidgetPollIntervalChanged"),
|
|
26
95
|
...subscribedMethods,
|
|
27
96
|
};
|
|
28
|
-
const connection = penpal.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
97
|
+
const connection = penpal.connect({
|
|
98
|
+
messenger: new penpal.WindowMessenger({ remoteWindow: window.parent, allowedOrigins: ["*"] }),
|
|
99
|
+
methods,
|
|
100
|
+
channel,
|
|
101
|
+
timeout: 10000,
|
|
102
|
+
});
|
|
103
|
+
// Subscription-channel connections (e.g. token-subscription, time-range-subscription)
|
|
104
|
+
// are routinely destroyed by `useSubscribeToHostChanges`' cleanup before the host
|
|
105
|
+
// opens its matching channel and the handshake can complete; without a swallowing
|
|
106
|
+
// .catch here, every unmount emits an unhandled-promise rejection.
|
|
107
|
+
connection.promise.catch(() => {
|
|
108
|
+
// intentionally swallowed; consumers that need the resolved proxy go through
|
|
109
|
+
// `getHostConnector()` which propagates the rejection on its own path.
|
|
33
110
|
});
|
|
34
111
|
return connection;
|
|
35
112
|
};
|
|
36
|
-
|
|
113
|
+
/**
|
|
114
|
+
* The module-level singleton connector to the host's runtime bridge.
|
|
115
|
+
*
|
|
116
|
+
* Lazy-initialised on the first {@link getHostConnector} call (rather than at
|
|
117
|
+
* module evaluation time) so that simply importing this module from the host
|
|
118
|
+
* bundle does not open an unwanted self-talking penpal connection. In the host
|
|
119
|
+
* window `window.parent === window`, which would make penpal post SYN messages
|
|
120
|
+
* back to itself and time out after 10s — see `PENPAL-V7-MIGRATION.md` §2.
|
|
121
|
+
*
|
|
122
|
+
* Iris-app bundles (which always run inside an iframe and have a real parent
|
|
123
|
+
* window) reach this lazily via `getHostConnector()` from runtime classes such
|
|
124
|
+
* as `TokenRuntime`, `RestRuntime`, etc.
|
|
125
|
+
*/
|
|
126
|
+
let hostConnector = null;
|
|
37
127
|
/**
|
|
38
128
|
* Gets the host connector.
|
|
39
129
|
*
|
|
40
|
-
*
|
|
130
|
+
* Returns penpal v7's {@link RemoteProxy} directly. The proxy is a JavaScript
|
|
131
|
+
* `Proxy` that intercepts every method access via a `get` trap and routes the
|
|
132
|
+
* call to the host through the underlying `MessagePort`. Attempting to spread
|
|
133
|
+
* or `Object.assign` it produces an empty object — the proxy has no own
|
|
134
|
+
* enumerable properties, only the `get` trap.
|
|
135
|
+
*
|
|
136
|
+
* The return is type-cast to `HostConnectorApi` because v7's `RemoteProxy<T>`
|
|
137
|
+
* is a mapped type that erases method-level generics (e.g. `exportData`'s
|
|
138
|
+
* `<TData, TVariables>` is widened to `<unknown, unknown>`). At runtime the
|
|
139
|
+
* proxy serializes whatever data the caller hands it across `postMessage`, so
|
|
140
|
+
* the original generics are honoured by the host on the other end — the
|
|
141
|
+
* widening is purely a TypeScript artefact at this library boundary.
|
|
142
|
+
*
|
|
143
|
+
* @returns { Promise<HostConnectorApi> } the connection to the host
|
|
41
144
|
*/
|
|
42
145
|
const getHostConnector = () => {
|
|
146
|
+
if (!hostConnector) {
|
|
147
|
+
hostConnector = setupHostConnector({});
|
|
148
|
+
}
|
|
43
149
|
return hostConnector.promise;
|
|
44
150
|
};
|
|
45
151
|
|
|
@@ -689,6 +795,7 @@ exports.getDateValue = getDateValue;
|
|
|
689
795
|
exports.getHostConnector = getHostConnector;
|
|
690
796
|
exports.getStringValue = getStringValue;
|
|
691
797
|
exports.isValidCustomFieldValue = isValidCustomFieldValue;
|
|
798
|
+
exports.registerHostChangeHandler = registerHostChangeHandler;
|
|
692
799
|
exports.setupHostConnector = setupHostConnector;
|
|
693
800
|
Object.keys(irisAppRuntimeCoreApi).forEach(function (k) {
|
|
694
801
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
package/index.esm.js
CHANGED
|
@@ -1,43 +1,149 @@
|
|
|
1
1
|
export * from '@trackunit/iris-app-runtime-core-api';
|
|
2
|
-
import {
|
|
2
|
+
import { connect, WindowMessenger } from 'penpal';
|
|
3
3
|
|
|
4
4
|
const doNothingByDefault = () => {
|
|
5
5
|
// do nothing by default
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* Registry of handlers for the host-driven subscription methods that the host
|
|
9
|
+
* pushes through the `host-runtime` channel. Providers (e.g.
|
|
10
|
+
* `TokenProviderIrisApp`) install their real handler via
|
|
11
|
+
* {@link registerHostChangeHandler}, replacing the `doNothingByDefault`
|
|
12
|
+
* placeholder until they unmount.
|
|
13
|
+
*
|
|
14
|
+
* v6's original design used a separate penpal connection per provider on
|
|
15
|
+
* dedicated channels (`token-subscription`, `time-range-subscription`, …)
|
|
16
|
+
* which worked only because v6's multi-connection bug caused the host's
|
|
17
|
+
* single `connectToChild` to receive messages from all of them. With v7's
|
|
18
|
+
* proper channel isolation, that arrangement silently drops every push event
|
|
19
|
+
* because the host only opens the `host-runtime` channel. This registry
|
|
20
|
+
* collapses all subscription methods back onto the host-runtime channel so
|
|
21
|
+
* they fire reliably without forcing the host to open one connection per
|
|
22
|
+
* channel.
|
|
23
|
+
*/
|
|
24
|
+
const subscriptionHandlers = {
|
|
25
|
+
onFilterBarValuesChanged: doNothingByDefault,
|
|
26
|
+
onTokenChanged: doNothingByDefault,
|
|
27
|
+
onAssetSortingStateChanged: doNothingByDefault,
|
|
28
|
+
onAssetsFilterBarValuesChanged: doNothingByDefault,
|
|
29
|
+
onCustomersFilterBarValuesChanged: doNothingByDefault,
|
|
30
|
+
onSitesFilterBarValuesChanged: doNothingByDefault,
|
|
31
|
+
onTablePersistenceStateChanged: doNothingByDefault,
|
|
32
|
+
onTimeRangeChanged: doNothingByDefault,
|
|
33
|
+
onWidgetPollIntervalChanged: doNothingByDefault,
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Install a handler for one of the host-driven subscription methods on the
|
|
37
|
+
* singleton `host-runtime` channel. Returns an unregister function that
|
|
38
|
+
* restores the previously installed handler (typically the
|
|
39
|
+
* `doNothingByDefault` no-op); call it from the effect's cleanup.
|
|
40
|
+
*
|
|
41
|
+
* Safe to call before the singleton's penpal handshake completes: the
|
|
42
|
+
* singleton's child-facing methods look up the current handler at call time,
|
|
43
|
+
* so handlers registered after `connect()` has resolved still receive events.
|
|
44
|
+
*/
|
|
45
|
+
const registerHostChangeHandler = (name, handler) => {
|
|
46
|
+
const previous = subscriptionHandlers[name];
|
|
47
|
+
subscriptionHandlers[name] = handler;
|
|
48
|
+
return () => {
|
|
49
|
+
// Only restore if we're still the active handler — a newer mount may have
|
|
50
|
+
// installed its own handler in the meantime, and we don't want this stale
|
|
51
|
+
// cleanup to clobber it.
|
|
52
|
+
if (subscriptionHandlers[name] === handler) {
|
|
53
|
+
subscriptionHandlers[name] = previous;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const dispatchToHandler = (name) => {
|
|
58
|
+
// The closure dispatches at call time so handlers registered after the
|
|
59
|
+
// singleton's connect() has resolved still receive events.
|
|
60
|
+
const dispatch = (...args) => {
|
|
61
|
+
const handler = subscriptionHandlers[name];
|
|
62
|
+
return handler(...args);
|
|
63
|
+
};
|
|
64
|
+
return dispatch;
|
|
65
|
+
};
|
|
7
66
|
/**
|
|
8
67
|
* Setup using the subscribedMethods to subscribe to events from the host.
|
|
9
68
|
*
|
|
10
|
-
* @param subscribedMethods the methods to subscribe to
|
|
11
|
-
*
|
|
69
|
+
* @param subscribedMethods the methods to subscribe to. Any key omitted here
|
|
70
|
+
* dispatches through the {@link registerHostChangeHandler} registry on the
|
|
71
|
+
* singleton connection, so internal callers can register handlers via that
|
|
72
|
+
* path without opening a second penpal connection.
|
|
73
|
+
* @param channel the penpal channel to use; defaults to `undefined`. The
|
|
74
|
+
* default singleton on the iris-app side intentionally omits the channel so
|
|
75
|
+
* the host's matching `connect()` call (which also omits it) can accept
|
|
76
|
+
* both native v7 SYNs and v6 SYNs translated by penpal's v6-compat shim
|
|
77
|
+
* (`upgradeMessage` produces v7 messages with `channel: undefined`). External
|
|
78
|
+
* callers can still pin a channel for isolated parallel connections; the
|
|
79
|
+
* host won't auto-handshake those — they're for caller-managed transports.
|
|
80
|
+
* @returns { Connection<HostConnectorMethods> } the connection to the host
|
|
12
81
|
*/
|
|
13
|
-
const setupHostConnector = (subscribedMethods) => {
|
|
82
|
+
const setupHostConnector = (subscribedMethods, channel) => {
|
|
14
83
|
const methods = {
|
|
15
|
-
onFilterBarValuesChanged:
|
|
16
|
-
onTokenChanged:
|
|
17
|
-
onAssetSortingStateChanged:
|
|
18
|
-
onAssetsFilterBarValuesChanged:
|
|
19
|
-
onCustomersFilterBarValuesChanged:
|
|
20
|
-
onSitesFilterBarValuesChanged:
|
|
21
|
-
onTablePersistenceStateChanged:
|
|
22
|
-
onTimeRangeChanged:
|
|
23
|
-
onWidgetPollIntervalChanged:
|
|
84
|
+
onFilterBarValuesChanged: dispatchToHandler("onFilterBarValuesChanged"),
|
|
85
|
+
onTokenChanged: dispatchToHandler("onTokenChanged"),
|
|
86
|
+
onAssetSortingStateChanged: dispatchToHandler("onAssetSortingStateChanged"),
|
|
87
|
+
onAssetsFilterBarValuesChanged: dispatchToHandler("onAssetsFilterBarValuesChanged"),
|
|
88
|
+
onCustomersFilterBarValuesChanged: dispatchToHandler("onCustomersFilterBarValuesChanged"),
|
|
89
|
+
onSitesFilterBarValuesChanged: dispatchToHandler("onSitesFilterBarValuesChanged"),
|
|
90
|
+
onTablePersistenceStateChanged: dispatchToHandler("onTablePersistenceStateChanged"),
|
|
91
|
+
onTimeRangeChanged: dispatchToHandler("onTimeRangeChanged"),
|
|
92
|
+
onWidgetPollIntervalChanged: dispatchToHandler("onWidgetPollIntervalChanged"),
|
|
24
93
|
...subscribedMethods,
|
|
25
94
|
};
|
|
26
|
-
const connection =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
95
|
+
const connection = connect({
|
|
96
|
+
messenger: new WindowMessenger({ remoteWindow: window.parent, allowedOrigins: ["*"] }),
|
|
97
|
+
methods,
|
|
98
|
+
channel,
|
|
99
|
+
timeout: 10000,
|
|
100
|
+
});
|
|
101
|
+
// Subscription-channel connections (e.g. token-subscription, time-range-subscription)
|
|
102
|
+
// are routinely destroyed by `useSubscribeToHostChanges`' cleanup before the host
|
|
103
|
+
// opens its matching channel and the handshake can complete; without a swallowing
|
|
104
|
+
// .catch here, every unmount emits an unhandled-promise rejection.
|
|
105
|
+
connection.promise.catch(() => {
|
|
106
|
+
// intentionally swallowed; consumers that need the resolved proxy go through
|
|
107
|
+
// `getHostConnector()` which propagates the rejection on its own path.
|
|
31
108
|
});
|
|
32
109
|
return connection;
|
|
33
110
|
};
|
|
34
|
-
|
|
111
|
+
/**
|
|
112
|
+
* The module-level singleton connector to the host's runtime bridge.
|
|
113
|
+
*
|
|
114
|
+
* Lazy-initialised on the first {@link getHostConnector} call (rather than at
|
|
115
|
+
* module evaluation time) so that simply importing this module from the host
|
|
116
|
+
* bundle does not open an unwanted self-talking penpal connection. In the host
|
|
117
|
+
* window `window.parent === window`, which would make penpal post SYN messages
|
|
118
|
+
* back to itself and time out after 10s — see `PENPAL-V7-MIGRATION.md` §2.
|
|
119
|
+
*
|
|
120
|
+
* Iris-app bundles (which always run inside an iframe and have a real parent
|
|
121
|
+
* window) reach this lazily via `getHostConnector()` from runtime classes such
|
|
122
|
+
* as `TokenRuntime`, `RestRuntime`, etc.
|
|
123
|
+
*/
|
|
124
|
+
let hostConnector = null;
|
|
35
125
|
/**
|
|
36
126
|
* Gets the host connector.
|
|
37
127
|
*
|
|
38
|
-
*
|
|
128
|
+
* Returns penpal v7's {@link RemoteProxy} directly. The proxy is a JavaScript
|
|
129
|
+
* `Proxy` that intercepts every method access via a `get` trap and routes the
|
|
130
|
+
* call to the host through the underlying `MessagePort`. Attempting to spread
|
|
131
|
+
* or `Object.assign` it produces an empty object — the proxy has no own
|
|
132
|
+
* enumerable properties, only the `get` trap.
|
|
133
|
+
*
|
|
134
|
+
* The return is type-cast to `HostConnectorApi` because v7's `RemoteProxy<T>`
|
|
135
|
+
* is a mapped type that erases method-level generics (e.g. `exportData`'s
|
|
136
|
+
* `<TData, TVariables>` is widened to `<unknown, unknown>`). At runtime the
|
|
137
|
+
* proxy serializes whatever data the caller hands it across `postMessage`, so
|
|
138
|
+
* the original generics are honoured by the host on the other end — the
|
|
139
|
+
* widening is purely a TypeScript artefact at this library boundary.
|
|
140
|
+
*
|
|
141
|
+
* @returns { Promise<HostConnectorApi> } the connection to the host
|
|
39
142
|
*/
|
|
40
143
|
const getHostConnector = () => {
|
|
144
|
+
if (!hostConnector) {
|
|
145
|
+
hostConnector = setupHostConnector({});
|
|
146
|
+
}
|
|
41
147
|
return hostConnector.promise;
|
|
42
148
|
};
|
|
43
149
|
|
|
@@ -653,4 +759,4 @@ const WidgetConfigRuntime = {
|
|
|
653
759
|
},
|
|
654
760
|
};
|
|
655
761
|
|
|
656
|
-
export { AnalyticsRuntime, AssetRuntime, AssetSortingRuntime, AssetsFilterBarRuntime, ConfirmationDialogRuntime, CurrentUserPreferenceRuntime, CurrentUserRuntime, CustomerRuntime, CustomersFilterBarRuntime, EnvironmentRuntime, EventRuntime, ExportDataRuntime, FeatureFlagRuntime, GeolocationRuntime, ModalDialogRuntime, NavigationRuntime, OemBrandingRuntime, ParamsRuntime, RestRuntime, RouterRuntime, SiteRuntime, SitesFilterBarRuntime, ThemeCssRuntime, TimeRangeRuntime, ToastRuntime, TokenRuntime, UserSubscriptionRuntime, WidgetConfigRuntime, getCustomFieldValueForDisplayInUI, getCustomFieldValueToSaveFromRawValue, getDateValue, getHostConnector, getStringValue, isValidCustomFieldValue, setupHostConnector };
|
|
762
|
+
export { AnalyticsRuntime, AssetRuntime, AssetSortingRuntime, AssetsFilterBarRuntime, ConfirmationDialogRuntime, CurrentUserPreferenceRuntime, CurrentUserRuntime, CustomerRuntime, CustomersFilterBarRuntime, EnvironmentRuntime, EventRuntime, ExportDataRuntime, FeatureFlagRuntime, GeolocationRuntime, ModalDialogRuntime, NavigationRuntime, OemBrandingRuntime, ParamsRuntime, RestRuntime, RouterRuntime, SiteRuntime, SitesFilterBarRuntime, ThemeCssRuntime, TimeRangeRuntime, ToastRuntime, TokenRuntime, UserSubscriptionRuntime, WidgetConfigRuntime, getCustomFieldValueForDisplayInUI, getCustomFieldValueToSaveFromRawValue, getDateValue, getHostConnector, getStringValue, isValidCustomFieldValue, registerHostChangeHandler, setupHostConnector };
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/iris-app-runtime-core",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.7",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=24.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"penpal": "^
|
|
11
|
-
"@trackunit/iris-app-runtime-core-api": "1.16.
|
|
10
|
+
"penpal": "^7.0.6",
|
|
11
|
+
"@trackunit/iris-app-runtime-core-api": "1.16.7"
|
|
12
12
|
},
|
|
13
13
|
"module": "./index.esm.js",
|
|
14
14
|
"main": "./index.cjs.js",
|
package/src/HostConnector.d.ts
CHANGED
|
@@ -1,15 +1,51 @@
|
|
|
1
1
|
import { ChildConnectorApi, HostConnectorApi } from "@trackunit/iris-app-runtime-core-api";
|
|
2
|
-
import {
|
|
2
|
+
import { Connection, Methods } from "penpal";
|
|
3
|
+
type HostConnectorMethods = HostConnectorApi & Methods;
|
|
4
|
+
/**
|
|
5
|
+
* Install a handler for one of the host-driven subscription methods on the
|
|
6
|
+
* singleton `host-runtime` channel. Returns an unregister function that
|
|
7
|
+
* restores the previously installed handler (typically the
|
|
8
|
+
* `doNothingByDefault` no-op); call it from the effect's cleanup.
|
|
9
|
+
*
|
|
10
|
+
* Safe to call before the singleton's penpal handshake completes: the
|
|
11
|
+
* singleton's child-facing methods look up the current handler at call time,
|
|
12
|
+
* so handlers registered after `connect()` has resolved still receive events.
|
|
13
|
+
*/
|
|
14
|
+
export declare const registerHostChangeHandler: <TKey extends keyof ChildConnectorApi>(name: TKey, handler: ChildConnectorApi[TKey]) => (() => void);
|
|
3
15
|
/**
|
|
4
16
|
* Setup using the subscribedMethods to subscribe to events from the host.
|
|
5
17
|
*
|
|
6
|
-
* @param subscribedMethods the methods to subscribe to
|
|
7
|
-
*
|
|
18
|
+
* @param subscribedMethods the methods to subscribe to. Any key omitted here
|
|
19
|
+
* dispatches through the {@link registerHostChangeHandler} registry on the
|
|
20
|
+
* singleton connection, so internal callers can register handlers via that
|
|
21
|
+
* path without opening a second penpal connection.
|
|
22
|
+
* @param channel the penpal channel to use; defaults to `undefined`. The
|
|
23
|
+
* default singleton on the iris-app side intentionally omits the channel so
|
|
24
|
+
* the host's matching `connect()` call (which also omits it) can accept
|
|
25
|
+
* both native v7 SYNs and v6 SYNs translated by penpal's v6-compat shim
|
|
26
|
+
* (`upgradeMessage` produces v7 messages with `channel: undefined`). External
|
|
27
|
+
* callers can still pin a channel for isolated parallel connections; the
|
|
28
|
+
* host won't auto-handshake those — they're for caller-managed transports.
|
|
29
|
+
* @returns { Connection<HostConnectorMethods> } the connection to the host
|
|
8
30
|
*/
|
|
9
|
-
export declare const setupHostConnector: (subscribedMethods: Partial<ChildConnectorApi> & Methods) => Connection<
|
|
31
|
+
export declare const setupHostConnector: (subscribedMethods: Partial<ChildConnectorApi> & Methods, channel?: string) => Connection<HostConnectorMethods>;
|
|
10
32
|
/**
|
|
11
33
|
* Gets the host connector.
|
|
12
34
|
*
|
|
13
|
-
*
|
|
35
|
+
* Returns penpal v7's {@link RemoteProxy} directly. The proxy is a JavaScript
|
|
36
|
+
* `Proxy` that intercepts every method access via a `get` trap and routes the
|
|
37
|
+
* call to the host through the underlying `MessagePort`. Attempting to spread
|
|
38
|
+
* or `Object.assign` it produces an empty object — the proxy has no own
|
|
39
|
+
* enumerable properties, only the `get` trap.
|
|
40
|
+
*
|
|
41
|
+
* The return is type-cast to `HostConnectorApi` because v7's `RemoteProxy<T>`
|
|
42
|
+
* is a mapped type that erases method-level generics (e.g. `exportData`'s
|
|
43
|
+
* `<TData, TVariables>` is widened to `<unknown, unknown>`). At runtime the
|
|
44
|
+
* proxy serializes whatever data the caller hands it across `postMessage`, so
|
|
45
|
+
* the original generics are honoured by the host on the other end — the
|
|
46
|
+
* widening is purely a TypeScript artefact at this library boundary.
|
|
47
|
+
*
|
|
48
|
+
* @returns { Promise<HostConnectorApi> } the connection to the host
|
|
14
49
|
*/
|
|
15
|
-
export declare const getHostConnector: () => Promise<
|
|
50
|
+
export declare const getHostConnector: () => Promise<HostConnectorApi>;
|
|
51
|
+
export {};
|