@atlaskit/rovo-triggers 10.14.0 → 10.15.0
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/CHANGELOG.md +9 -0
- package/dist/cjs/common/utils/extension-context-bridge/ExtensionContextBridgeClient.js +130 -0
- package/dist/cjs/common/utils/extension-context-bridge/ExtensionContextBridgeHost.js +85 -0
- package/dist/cjs/common/utils/extension-context-bridge/constants.js +22 -0
- package/dist/cjs/common/utils/extension-context-bridge/policy.js +40 -0
- package/dist/cjs/common/utils/extension-context-bridge/registry.js +134 -0
- package/dist/cjs/common/utils/extension-context-bridge/transport.js +49 -0
- package/dist/es2019/common/utils/extension-context-bridge/ExtensionContextBridgeClient.js +128 -0
- package/dist/es2019/common/utils/extension-context-bridge/ExtensionContextBridgeHost.js +82 -0
- package/dist/es2019/common/utils/extension-context-bridge/constants.js +16 -0
- package/dist/es2019/common/utils/extension-context-bridge/policy.js +32 -0
- package/dist/es2019/common/utils/extension-context-bridge/registry.js +120 -0
- package/dist/es2019/common/utils/extension-context-bridge/transport.js +35 -0
- package/dist/esm/common/utils/extension-context-bridge/ExtensionContextBridgeClient.js +124 -0
- package/dist/esm/common/utils/extension-context-bridge/ExtensionContextBridgeHost.js +78 -0
- package/dist/esm/common/utils/extension-context-bridge/constants.js +16 -0
- package/dist/esm/common/utils/extension-context-bridge/policy.js +34 -0
- package/dist/esm/common/utils/extension-context-bridge/registry.js +127 -0
- package/dist/esm/common/utils/extension-context-bridge/transport.js +43 -0
- package/dist/types/common/utils/extension-context-bridge/ExtensionContextBridgeClient.d.ts +19 -0
- package/dist/types/common/utils/extension-context-bridge/ExtensionContextBridgeHost.d.ts +16 -0
- package/dist/types/common/utils/extension-context-bridge/constants.d.ts +13 -0
- package/dist/types/common/utils/extension-context-bridge/policy.d.ts +8 -0
- package/dist/types/common/utils/extension-context-bridge/registry.d.ts +6 -0
- package/dist/types/common/utils/extension-context-bridge/transport.d.ts +38 -0
- package/extension-context-bridge/client/package.json +10 -0
- package/extension-context-bridge/constants/package.json +10 -0
- package/extension-context-bridge/host/package.json +10 -0
- package/extension-context-bridge/transport/package.json +10 -0
- package/package.json +7 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
+
import { bind } from 'bind-event-listener';
|
|
3
|
+
import { BRIDGE_MESSAGE_MARKER } from './constants';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A `rovo-triggers` payload reduced to a structured-clone-safe shape. Functions (e.g.
|
|
7
|
+
* `set-message-context`'s `setContext`) are resolved to values by `./registry` first.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Transport abstraction so Host/Client work over any carrier: same-window `postMessage` on the
|
|
12
|
+
* product side, iframe/side-panel `postMessage` in the chat iframe. Carries `BridgeMessage` only;
|
|
13
|
+
* `rovo-content-bridge-api` commands travel separately, relayed verbatim by the extension.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export var isBridgeMessage = function isBridgeMessage(value) {
|
|
17
|
+
return _typeof(value) === 'object' && value !== null && value[BRIDGE_MESSAGE_MARKER] === true && typeof value.direction === 'string' && _typeof(value.payload) === 'object' && value.payload !== null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** `postMessage`-based transport. Callers override `targetWindow`/`self` for the iframe side. */
|
|
21
|
+
export var createWindowTransport = function createWindowTransport(_ref) {
|
|
22
|
+
var targetWindow = _ref.targetWindow,
|
|
23
|
+
_ref$self = _ref.self,
|
|
24
|
+
selfWindow = _ref$self === void 0 ? window : _ref$self,
|
|
25
|
+
_ref$targetOrigin = _ref.targetOrigin,
|
|
26
|
+
targetOrigin = _ref$targetOrigin === void 0 ? selfWindow.location.origin : _ref$targetOrigin;
|
|
27
|
+
return {
|
|
28
|
+
send: function send(message) {
|
|
29
|
+
targetWindow.postMessage(message, targetOrigin);
|
|
30
|
+
},
|
|
31
|
+
// `bind` returns its own unbind function, which is exactly the `subscribe` contract.
|
|
32
|
+
subscribe: function subscribe(handler) {
|
|
33
|
+
return bind(selfWindow, {
|
|
34
|
+
type: 'message',
|
|
35
|
+
listener: function listener(event) {
|
|
36
|
+
if (isBridgeMessage(event.data)) {
|
|
37
|
+
handler(event.data);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Transport } from './transport';
|
|
2
|
+
type Props = {
|
|
3
|
+
/** Override the transport (tests). Defaults to iframe<->parent `postMessage`. */
|
|
4
|
+
transport?: Transport;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Chat-iframe half of the bridge.
|
|
8
|
+
* - Inbound: deserializes context from the extension transport and re-publishes it onto the
|
|
9
|
+
* iframe's own `ai-mate` bus for the existing `ChatContextSubscriber` to consume unchanged.
|
|
10
|
+
* - Outbound: forwards allowlisted action payloads (e.g. `editor-suggestion`) back to the product,
|
|
11
|
+
* via the extension's content script.
|
|
12
|
+
*
|
|
13
|
+
* Content writes (`rovo-content-bridge-api` commands) are not handled here — that API already
|
|
14
|
+
* crosses this boundary on its own, so the extension only relays envelopes for it.
|
|
15
|
+
*
|
|
16
|
+
* Headless.
|
|
17
|
+
*/
|
|
18
|
+
export declare const ExtensionContextBridgeClient: ({ transport }: Props) => null;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Transport } from './transport';
|
|
2
|
+
type Props = {
|
|
3
|
+
/** Override the transport (tests). Defaults to same-window `postMessage`. */
|
|
4
|
+
transport?: Transport;
|
|
5
|
+
/** Resolves the current content id at relay time (a getter, so the Host reads it lazily). */
|
|
6
|
+
getContentId?: () => string | undefined;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Product-window half of the bridge. Observes the `ai-mate` bus and mirrors allowlisted context out
|
|
10
|
+
* to the extension via same-window `postMessage` (see `./policy` for the allow/deny rules).
|
|
11
|
+
*
|
|
12
|
+
* The reverse direction is handled by the sibling `RovoPostMessagePubsubListener` in
|
|
13
|
+
* `ChatOpenerSubscriber`, not here. Headless; mounts at product root via `ChatOpenerSubscriber`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ExtensionContextBridgeHost: ({ transport, getContentId }: Props) => null;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature gate for the extension context bridge; both Host and Client self-gate on it.
|
|
3
|
+
* `fg()` requires a static literal, so call sites inline this value rather than importing it;
|
|
4
|
+
* tests resolve the gate through this constant so the two cannot drift apart.
|
|
5
|
+
*/
|
|
6
|
+
export declare const BRIDGE_FEATURE_GATE = "rovo-ext_context_bridge";
|
|
7
|
+
/** Marker on every bridge `postMessage`, so listeners can ignore unrelated messages. */
|
|
8
|
+
export declare const BRIDGE_MESSAGE_MARKER: '__rovoExtContextBridge';
|
|
9
|
+
/** Read context flows product -> extension; actions flow extension -> product. */
|
|
10
|
+
export declare const BRIDGE_TO_EXTENSION: 'to-extension';
|
|
11
|
+
export declare const BRIDGE_TO_PRODUCT: 'to-product';
|
|
12
|
+
/** Loop-guard sentinel stamped on re-published payloads so they never ping-pong. */
|
|
13
|
+
export declare const BRIDGE_SOURCE: 'rovo-extension-bridge';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Payload } from '../../../types';
|
|
2
|
+
/** Why a product-bus payload was or was not relayed. */
|
|
3
|
+
type InboundDecision = 'allow' | 'not-allowlisted' | 'denylisted';
|
|
4
|
+
/** Classify a product-bus payload. Relay iff `allow`. */
|
|
5
|
+
export declare const getInboundDecision: (type: Payload['type']) => InboundDecision;
|
|
6
|
+
/** True if a chat-bus payload of this type may be relayed back to the product. */
|
|
7
|
+
export declare const shouldRelayToProduct: (type: Payload['type']) => boolean;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Payload } from '../../../types';
|
|
2
|
+
import { type SerializedPayload } from './transport';
|
|
3
|
+
/** Serialise a payload for the wire, using a shim if one exists, else a generic JSON round-trip. */
|
|
4
|
+
export declare const serializePayload: (payload: Payload) => SerializedPayload | null;
|
|
5
|
+
/** Reconstruct a payload from the wire, stamping the loop-guard sentinel. */
|
|
6
|
+
export declare const deserializePayload: (serialized: SerializedPayload) => Payload | null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Payload } from '../../../types';
|
|
2
|
+
import { BRIDGE_MESSAGE_MARKER } from './constants';
|
|
3
|
+
import type { BRIDGE_TO_EXTENSION, BRIDGE_TO_PRODUCT } from './constants';
|
|
4
|
+
type BridgeDirection = typeof BRIDGE_TO_EXTENSION | typeof BRIDGE_TO_PRODUCT;
|
|
5
|
+
/**
|
|
6
|
+
* A `rovo-triggers` payload reduced to a structured-clone-safe shape. Functions (e.g.
|
|
7
|
+
* `set-message-context`'s `setContext`) are resolved to values by `./registry` first.
|
|
8
|
+
*/
|
|
9
|
+
export type SerializedPayload = {
|
|
10
|
+
type: Payload['type'];
|
|
11
|
+
source?: string;
|
|
12
|
+
product?: Payload['product'];
|
|
13
|
+
openChat?: boolean;
|
|
14
|
+
data: unknown;
|
|
15
|
+
};
|
|
16
|
+
export type BridgeMessage = {
|
|
17
|
+
[BRIDGE_MESSAGE_MARKER]: true;
|
|
18
|
+
direction: BridgeDirection;
|
|
19
|
+
payload: SerializedPayload;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Transport abstraction so Host/Client work over any carrier: same-window `postMessage` on the
|
|
23
|
+
* product side, iframe/side-panel `postMessage` in the chat iframe. Carries `BridgeMessage` only;
|
|
24
|
+
* `rovo-content-bridge-api` commands travel separately, relayed verbatim by the extension.
|
|
25
|
+
*/
|
|
26
|
+
export type Transport = {
|
|
27
|
+
send: (message: BridgeMessage) => void;
|
|
28
|
+
/** Returns an unsubscribe function. */
|
|
29
|
+
subscribe: (handler: (message: BridgeMessage) => void) => () => void;
|
|
30
|
+
};
|
|
31
|
+
export declare const isBridgeMessage: (value: unknown) => value is BridgeMessage;
|
|
32
|
+
/** `postMessage`-based transport. Callers override `targetWindow`/`self` for the iframe side. */
|
|
33
|
+
export declare const createWindowTransport: ({ targetWindow, self: selfWindow, targetOrigin, }: {
|
|
34
|
+
targetWindow: Window;
|
|
35
|
+
self?: Window;
|
|
36
|
+
targetOrigin?: string;
|
|
37
|
+
}) => Transport;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/rovo-triggers/extension-context-bridge/client",
|
|
3
|
+
"main": "../../dist/cjs/common/utils/extension-context-bridge/ExtensionContextBridgeClient.js",
|
|
4
|
+
"module": "../../dist/esm/common/utils/extension-context-bridge/ExtensionContextBridgeClient.js",
|
|
5
|
+
"module:es2019": "../../dist/es2019/common/utils/extension-context-bridge/ExtensionContextBridgeClient.js",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"*.compiled.css"
|
|
8
|
+
],
|
|
9
|
+
"types": "../../dist/types/common/utils/extension-context-bridge/ExtensionContextBridgeClient.d.ts"
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/rovo-triggers/extension-context-bridge/constants",
|
|
3
|
+
"main": "../../dist/cjs/common/utils/extension-context-bridge/constants.js",
|
|
4
|
+
"module": "../../dist/esm/common/utils/extension-context-bridge/constants.js",
|
|
5
|
+
"module:es2019": "../../dist/es2019/common/utils/extension-context-bridge/constants.js",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"*.compiled.css"
|
|
8
|
+
],
|
|
9
|
+
"types": "../../dist/types/common/utils/extension-context-bridge/constants.d.ts"
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/rovo-triggers/extension-context-bridge/host",
|
|
3
|
+
"main": "../../dist/cjs/common/utils/extension-context-bridge/ExtensionContextBridgeHost.js",
|
|
4
|
+
"module": "../../dist/esm/common/utils/extension-context-bridge/ExtensionContextBridgeHost.js",
|
|
5
|
+
"module:es2019": "../../dist/es2019/common/utils/extension-context-bridge/ExtensionContextBridgeHost.js",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"*.compiled.css"
|
|
8
|
+
],
|
|
9
|
+
"types": "../../dist/types/common/utils/extension-context-bridge/ExtensionContextBridgeHost.d.ts"
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/rovo-triggers/extension-context-bridge/transport",
|
|
3
|
+
"main": "../../dist/cjs/common/utils/extension-context-bridge/transport.js",
|
|
4
|
+
"module": "../../dist/esm/common/utils/extension-context-bridge/transport.js",
|
|
5
|
+
"module:es2019": "../../dist/es2019/common/utils/extension-context-bridge/transport.js",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"*.compiled.css"
|
|
8
|
+
],
|
|
9
|
+
"types": "../../dist/types/common/utils/extension-context-bridge/transport.d.ts"
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/rovo-triggers",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.15.0",
|
|
4
4
|
"description": "Provides various trigger events to drive Rovo Chat functionality, such as a publish-subscribe and URL parameter hooks",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@atlassian/a11y-jest-testing": "^0.15.0",
|
|
47
47
|
"@atlassian/conversation-assistant-service-api": "^16.4.0",
|
|
48
48
|
"@atlassian/feature-flags-test-utils": "^1.2.0",
|
|
49
|
+
"@atlassian/testing-library": "^0.11.0",
|
|
49
50
|
"@testing-library/react": "^16.3.0",
|
|
50
51
|
"react": "^18.2.0",
|
|
51
52
|
"react-dom": "^18.2.0",
|
|
@@ -85,5 +86,10 @@
|
|
|
85
86
|
"import-no-extraneous-disable-for-examples-and-docs"
|
|
86
87
|
]
|
|
87
88
|
}
|
|
89
|
+
},
|
|
90
|
+
"platform-feature-flags": {
|
|
91
|
+
"rovo-ext_context_bridge": {
|
|
92
|
+
"type": "boolean"
|
|
93
|
+
}
|
|
88
94
|
}
|
|
89
95
|
}
|