@atlaskit/editor-plugin-engagement-platform 2.0.0 → 2.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +65 -14
  3. package/dist/cjs/actions/startMessage.js +66 -0
  4. package/dist/cjs/actions/stopMessage.js +66 -0
  5. package/dist/cjs/actions/types.js +5 -0
  6. package/dist/cjs/engagementPlatformPlugin.js +14 -6
  7. package/dist/cjs/pmPlugins/engagementPlatformPmPlugin/commands/setMessageState.js +22 -0
  8. package/dist/cjs/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin.js +48 -0
  9. package/dist/cjs/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey.js +8 -0
  10. package/dist/cjs/pmPlugins/engagementPlatformPmPlugin/types.js +5 -0
  11. package/dist/es2019/actions/startMessage.js +34 -0
  12. package/dist/es2019/actions/stopMessage.js +34 -0
  13. package/dist/es2019/actions/types.js +1 -0
  14. package/dist/es2019/engagementPlatformPlugin.js +14 -6
  15. package/dist/es2019/pmPlugins/engagementPlatformPmPlugin/commands/setMessageState.js +14 -0
  16. package/dist/es2019/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin.js +38 -0
  17. package/dist/es2019/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey.js +2 -0
  18. package/dist/es2019/pmPlugins/engagementPlatformPmPlugin/types.js +1 -0
  19. package/dist/esm/actions/startMessage.js +59 -0
  20. package/dist/esm/actions/stopMessage.js +59 -0
  21. package/dist/esm/actions/types.js +1 -0
  22. package/dist/esm/engagementPlatformPlugin.js +14 -6
  23. package/dist/esm/pmPlugins/engagementPlatformPmPlugin/commands/setMessageState.js +15 -0
  24. package/dist/esm/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin.js +41 -0
  25. package/dist/esm/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey.js +2 -0
  26. package/dist/esm/pmPlugins/engagementPlatformPmPlugin/types.js +1 -0
  27. package/dist/types/actions/startMessage.d.ts +3 -0
  28. package/dist/types/actions/stopMessage.d.ts +3 -0
  29. package/dist/types/actions/types.d.ts +2 -0
  30. package/dist/types/engagementPlatformPluginType.d.ts +57 -14
  31. package/dist/types/index.d.ts +1 -1
  32. package/dist/types/pmPlugins/engagementPlatformPmPlugin/commands/setMessageState.d.ts +3 -0
  33. package/dist/types/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin.d.ts +4 -0
  34. package/dist/types/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey.d.ts +3 -0
  35. package/dist/types/pmPlugins/engagementPlatformPmPlugin/types.d.ts +25 -0
  36. package/dist/types-ts4.5/actions/startMessage.d.ts +3 -0
  37. package/dist/types-ts4.5/actions/stopMessage.d.ts +3 -0
  38. package/dist/types-ts4.5/actions/types.d.ts +2 -0
  39. package/dist/types-ts4.5/engagementPlatformPluginType.d.ts +57 -13
  40. package/dist/types-ts4.5/index.d.ts +1 -1
  41. package/dist/types-ts4.5/pmPlugins/engagementPlatformPmPlugin/commands/setMessageState.d.ts +3 -0
  42. package/dist/types-ts4.5/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin.d.ts +4 -0
  43. package/dist/types-ts4.5/pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey.d.ts +3 -0
  44. package/dist/types-ts4.5/pmPlugins/engagementPlatformPmPlugin/types.d.ts +25 -0
  45. package/package.json +2 -1
  46. package/dist/cjs/pm-plugins/main.js +0 -29
  47. package/dist/es2019/pm-plugins/main.js +0 -23
  48. package/dist/esm/pm-plugins/main.js +0 -23
  49. package/dist/types/pm-plugins/main.d.ts +0 -9
  50. package/dist/types-ts4.5/pm-plugins/main.d.ts +0 -9
package/CHANGELOG.md CHANGED
@@ -1 +1,10 @@
1
1
  # @atlaskit/editor-plugin-engagement-platform
2
+
3
+ ## 2.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#150384](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/150384)
8
+ [`704af5d7d4a1a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/704af5d7d4a1a) -
9
+ [EDF-1668](https://product-fabric.atlassian.net/browse/EDF-1668) - add external message API
10
+ support into editor-plugin-engagement-platform
package/README.md CHANGED
@@ -1,32 +1,83 @@
1
- # EditorPluginEngagementPlatform
1
+ # Editor Engagement Platform Plugin
2
2
 
3
- Engagement platform plugin for @atlaskit/editor-core“
3
+ This plugin allows interaction with the Atlassian Engagement Platform within the editor. It provides
4
+ functionalities to start and stop engagement messages, as well as to check the state of these
5
+ messages.
4
6
 
5
7
  **Note:** This component is designed for internal Atlassian development.
6
8
  External contributors will be able to use this component but will not be able to submit issues.
7
9
 
10
+ ## Features
11
+
12
+ - **Start Message**: Start an engagement message with a given ID and optional variation ID.
13
+ - **Stop Message**: Stop an engagement message with a given ID.
14
+
15
+ ## Installation
16
+
17
+ **Internal use only**
18
+
19
+ To install the plugin, use yarn:
20
+
21
+ ```sh
22
+ yarn add @atlassian/editor-plugin-engagement-platform
23
+ ```
8
24
 
9
25
  ## Usage
10
- ---
26
+
11
27
  **Internal use only**
12
28
 
13
- @atlaskit/editor-plugin-engagement-platform is intended for internal use by the @atlaskit/editor-core and as a plugin dependency of the Editor within your product.
29
+ To use the plugin, import it and include it in your editor setup:
30
+
31
+ ```typescript
32
+ import { engagementPlatformPlugin } from '@atlassian/editor-plugin-engagement-platform';
33
+
34
+ const coordinationClient = useCoordinationClient()
35
+
36
+ const { preset, editorApi } = usePreset(() => {
37
+ return universalPreset.add([
38
+ engagementPlatformPlugin,
39
+ { coordinationClient },
40
+ ]);
41
+ }, [universalPreset, coordinationClient]);
42
+ ```
43
+
44
+ To get the current state of an engagement message, you can use the following code:
45
+
46
+ ```typescript
47
+ function isMessageActive(messageId: string): boolean {
48
+ const messageStates = api.engagementPlatform.sharedState.currentState()?.messageStates ?? {};
49
+ return !!messageStates[messageId];
50
+ }
51
+ ```
52
+
53
+ Detailed docs and example usage can be found [here](https://atlaskit.atlassian.com/packages/editor/editor-plugin-engagement-platform).
14
54
 
15
- Direct use of this component is not supported.
55
+ ## API
56
+
57
+ ### `api.engagementPlatform.actions.startMessage(messageId: string, variationId?: string): Promise<boolean>`
58
+
59
+ Starts an engagement message with the given ID and optional variation ID.
60
+
61
+ ### `api.engagementPlatform.actions.stopMessage(messageId: string): Promise<boolean>`
62
+
63
+ Stops an engagement message with the given ID.
16
64
 
17
65
  Please see [Atlaskit - Editor Engagement Platform Plugin](https://atlaskit.atlassian.com/packages/editor/editor-plugin-engagement-platform) for documentation and examples for this package.
18
66
 
19
- ## Support
20
- ---
21
- For internal Atlassian, visit the slack channel [#help-editor](https://atlassian.slack.com/archives/CFG3PSQ9E) for support or visit [go/editor-help](https://go/editor-help) to submit a bug.
22
- ## License
23
- ---
24
- Please see [Atlassian Frontend - License](https://hello.atlassian.net/wiki/spaces/AF/pages/2589099144/Documentation#Platform-License) for more licensing information.
67
+ ## Configuration
25
68
 
69
+ The plugin requires a configuration object with the following structure:
26
70
 
27
- ## Usage
71
+ ```typescript
72
+ interface EngagementPlatformPluginConfig {
73
+ coordinationClient: CoordinationClientType;
74
+ }
75
+ ```
76
+
77
+ ## Support
28
78
 
29
- `import EditorPluginEngagementPlatform from '@atlaskit/editor-plugin-engagement-platform';`
79
+ For internal Atlassian, visit the slack channel [#help-editor](https://atlassian.slack.com/archives/CFG3PSQ9E) for support or visit [go/editor-help](https://go/editor-help) to submit a bug.
30
80
 
81
+ ## License
31
82
 
32
- Detailed docs and example usage can be found [here](https://atlaskit.atlassian.com/packages/editor/editor-plugin-engagement-platform).
83
+ Please see [Atlassian Frontend - License](https://hello.atlassian.net/wiki/spaces/AF/pages/2589099144/Documentation#Platform-License) for more licensing information.
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.startMessage = startMessage;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var _analytics = require("@atlaskit/editor-common/analytics");
11
+ var _setMessageState = require("../pmPlugins/engagementPlatformPmPlugin/commands/setMessageState");
12
+ function startMessage(api, coordinationClient) {
13
+ return /*#__PURE__*/function () {
14
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(messageId, variationId) {
15
+ var _api$engagementPlatfo, _api$engagementPlatfo2;
16
+ var messageStates, isActive, isStarted, _api$analytics;
17
+ return _regenerator.default.wrap(function _callee$(_context) {
18
+ while (1) switch (_context.prev = _context.next) {
19
+ case 0:
20
+ if (api) {
21
+ _context.next = 2;
22
+ break;
23
+ }
24
+ return _context.abrupt("return", false);
25
+ case 2:
26
+ messageStates = (_api$engagementPlatfo = (_api$engagementPlatfo2 = api.engagementPlatform.sharedState.currentState()) === null || _api$engagementPlatfo2 === void 0 ? void 0 : _api$engagementPlatfo2.messageStates) !== null && _api$engagementPlatfo !== void 0 ? _api$engagementPlatfo : {};
27
+ isActive = messageStates[messageId];
28
+ if (!isActive) {
29
+ _context.next = 6;
30
+ break;
31
+ }
32
+ return _context.abrupt("return", true);
33
+ case 6:
34
+ _context.prev = 6;
35
+ _context.next = 9;
36
+ return coordinationClient.start(messageId, variationId);
37
+ case 9:
38
+ isStarted = _context.sent;
39
+ if (isStarted) {
40
+ api.core.actions.execute((0, _setMessageState.setMessageState)(messageId, true));
41
+ }
42
+ return _context.abrupt("return", isStarted);
43
+ case 14:
44
+ _context.prev = 14;
45
+ _context.t0 = _context["catch"](6);
46
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
47
+ action: _analytics.ACTION.ERRORED,
48
+ actionSubject: _analytics.ACTION_SUBJECT.ENGAGEMENT_PLATFORM,
49
+ eventType: _analytics.EVENT_TYPE.OPERATIONAL,
50
+ attributes: {
51
+ error: _context.t0 instanceof Error ? _context.t0.message : "".concat(_context.t0),
52
+ errorStack: _context.t0 instanceof Error ? _context.t0.stack : undefined
53
+ }
54
+ });
55
+ return _context.abrupt("return", false);
56
+ case 18:
57
+ case "end":
58
+ return _context.stop();
59
+ }
60
+ }, _callee, null, [[6, 14]]);
61
+ }));
62
+ return function (_x, _x2) {
63
+ return _ref.apply(this, arguments);
64
+ };
65
+ }();
66
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.stopMessage = stopMessage;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var _analytics = require("@atlaskit/editor-common/analytics");
11
+ var _setMessageState = require("../pmPlugins/engagementPlatformPmPlugin/commands/setMessageState");
12
+ function stopMessage(api, coordinationClient) {
13
+ return /*#__PURE__*/function () {
14
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(messageId) {
15
+ var _api$engagementPlatfo, _api$engagementPlatfo2;
16
+ var messageStates, isActive, isStopped, _api$analytics;
17
+ return _regenerator.default.wrap(function _callee$(_context) {
18
+ while (1) switch (_context.prev = _context.next) {
19
+ case 0:
20
+ if (api) {
21
+ _context.next = 2;
22
+ break;
23
+ }
24
+ return _context.abrupt("return", false);
25
+ case 2:
26
+ messageStates = (_api$engagementPlatfo = (_api$engagementPlatfo2 = api.engagementPlatform.sharedState.currentState()) === null || _api$engagementPlatfo2 === void 0 ? void 0 : _api$engagementPlatfo2.messageStates) !== null && _api$engagementPlatfo !== void 0 ? _api$engagementPlatfo : {};
27
+ isActive = messageStates[messageId];
28
+ if (isActive) {
29
+ _context.next = 6;
30
+ break;
31
+ }
32
+ return _context.abrupt("return", true);
33
+ case 6:
34
+ _context.prev = 6;
35
+ _context.next = 9;
36
+ return coordinationClient.stop(messageId);
37
+ case 9:
38
+ isStopped = _context.sent;
39
+ if (isStopped) {
40
+ api.core.actions.execute((0, _setMessageState.setMessageState)(messageId, false));
41
+ }
42
+ return _context.abrupt("return", isStopped);
43
+ case 14:
44
+ _context.prev = 14;
45
+ _context.t0 = _context["catch"](6);
46
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
47
+ action: _analytics.ACTION.ERRORED,
48
+ actionSubject: _analytics.ACTION_SUBJECT.ENGAGEMENT_PLATFORM,
49
+ eventType: _analytics.EVENT_TYPE.OPERATIONAL,
50
+ attributes: {
51
+ error: _context.t0 instanceof Error ? _context.t0.message : "".concat(_context.t0),
52
+ errorStack: _context.t0 instanceof Error ? _context.t0.stack : undefined
53
+ }
54
+ });
55
+ return _context.abrupt("return", false);
56
+ case 18:
57
+ case "end":
58
+ return _context.stop();
59
+ }
60
+ }, _callee, null, [[6, 14]]);
61
+ }));
62
+ return function (_x) {
63
+ return _ref.apply(this, arguments);
64
+ };
65
+ }();
66
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -4,24 +4,32 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.engagementPlatformPlugin = void 0;
7
- var _main = require("./pm-plugins/main");
7
+ var _startMessage = require("./actions/startMessage");
8
+ var _stopMessage = require("./actions/stopMessage");
9
+ var _engagementPlatformPmPlugin = require("./pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin");
10
+ var _engagementPlatformPmPluginKey = require("./pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey");
8
11
  var engagementPlatformPlugin = exports.engagementPlatformPlugin = function engagementPlatformPlugin(_ref) {
9
- var config = _ref.config;
12
+ var config = _ref.config,
13
+ api = _ref.api;
10
14
  return {
11
15
  name: 'engagementPlatform',
16
+ actions: {
17
+ startMessage: (0, _startMessage.startMessage)(api, config.coordinationClient),
18
+ stopMessage: (0, _stopMessage.stopMessage)(api, config.coordinationClient)
19
+ },
12
20
  pmPlugins: function pmPlugins() {
13
21
  return [{
14
- name: 'engagementPlatform',
22
+ name: 'engagementPlatformPmPlugin',
15
23
  plugin: function plugin() {
16
- return (0, _main.createPlugin)(config);
24
+ return (0, _engagementPlatformPmPlugin.engagementPlatformPmPlugin)(config);
17
25
  }
18
26
  }];
19
27
  },
20
28
  getSharedState: function getSharedState(editorState) {
21
- if (!config || !editorState) {
29
+ if (!editorState) {
22
30
  return undefined;
23
31
  }
24
- return _main.engagementPlatformPluginKey.getState(editorState);
32
+ return _engagementPlatformPmPluginKey.engagementPlatformPmPluginKey.getState(editorState);
25
33
  }
26
34
  };
27
35
  };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.setMessageState = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _engagementPlatformPmPluginKey = require("../engagementPlatformPmPluginKey");
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ /** Set the state of a message in the Engagement Platform plugin */
13
+ var setMessageState = exports.setMessageState = function setMessageState(messageIs, state) {
14
+ return function (_ref) {
15
+ var _tr$getMeta;
16
+ var tr = _ref.tr;
17
+ var meta = {
18
+ newMessageStates: _objectSpread(_objectSpread({}, (_tr$getMeta = tr.getMeta(_engagementPlatformPmPluginKey.engagementPlatformPmPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.messageStates), {}, (0, _defineProperty2.default)({}, messageIs, state))
19
+ };
20
+ return tr.setMeta(_engagementPlatformPmPluginKey.engagementPlatformPmPluginKey, meta);
21
+ };
22
+ };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.engagementPlatformPmPlugin = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
+ var _engagementPlatformPmPluginKey = require("./engagementPlatformPmPluginKey");
12
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
+ var engagementPlatformPmPlugin = exports.engagementPlatformPmPlugin = function engagementPlatformPmPlugin(pluginConfig) {
15
+ return new _safePlugin.SafePlugin({
16
+ key: _engagementPlatformPmPluginKey.engagementPlatformPmPluginKey,
17
+ state: {
18
+ init: function init() {
19
+ return {
20
+ messageStates: {},
21
+ epComponents: pluginConfig.epComponents,
22
+ epHooks: pluginConfig.epHooks,
23
+ coordinationClient: pluginConfig.coordinationClient
24
+ };
25
+ },
26
+ apply: function apply(tr, pluginState) {
27
+ var meta = tr.getMeta(_engagementPlatformPmPluginKey.engagementPlatformPmPluginKey);
28
+ if (!meta) {
29
+ return pluginState;
30
+ }
31
+ var newState = _objectSpread(_objectSpread({}, pluginState), {}, {
32
+ messageStates: _objectSpread(_objectSpread({}, pluginState.messageStates), meta.newMessageStates)
33
+ });
34
+
35
+ // Remove false message states to save memory
36
+ Object.entries(newState.messageStates).forEach(function (_ref) {
37
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
38
+ key = _ref2[0],
39
+ value = _ref2[1];
40
+ if (!value) {
41
+ delete newState.messageStates[key];
42
+ }
43
+ });
44
+ return newState;
45
+ }
46
+ }
47
+ });
48
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.engagementPlatformPmPluginKey = void 0;
7
+ var _state = require("@atlaskit/editor-prosemirror/state");
8
+ var engagementPlatformPmPluginKey = exports.engagementPlatformPmPluginKey = new _state.PluginKey('engagementPlatformPmPlugin');
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,34 @@
1
+ import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
+ import { setMessageState } from '../pmPlugins/engagementPlatformPmPlugin/commands/setMessageState';
3
+ export function startMessage(api, coordinationClient) {
4
+ return async (messageId, variationId) => {
5
+ var _api$engagementPlatfo, _api$engagementPlatfo2;
6
+ if (!api) {
7
+ return false;
8
+ }
9
+ const messageStates = (_api$engagementPlatfo = (_api$engagementPlatfo2 = api.engagementPlatform.sharedState.currentState()) === null || _api$engagementPlatfo2 === void 0 ? void 0 : _api$engagementPlatfo2.messageStates) !== null && _api$engagementPlatfo !== void 0 ? _api$engagementPlatfo : {};
10
+ const isActive = messageStates[messageId];
11
+ if (isActive) {
12
+ return true;
13
+ }
14
+ try {
15
+ const isStarted = await coordinationClient.start(messageId, variationId);
16
+ if (isStarted) {
17
+ api.core.actions.execute(setMessageState(messageId, true));
18
+ }
19
+ return isStarted;
20
+ } catch (error) {
21
+ var _api$analytics;
22
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent({
23
+ action: ACTION.ERRORED,
24
+ actionSubject: ACTION_SUBJECT.ENGAGEMENT_PLATFORM,
25
+ eventType: EVENT_TYPE.OPERATIONAL,
26
+ attributes: {
27
+ error: error instanceof Error ? error.message : `${error}`,
28
+ errorStack: error instanceof Error ? error.stack : undefined
29
+ }
30
+ });
31
+ return false;
32
+ }
33
+ };
34
+ }
@@ -0,0 +1,34 @@
1
+ import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
+ import { setMessageState } from '../pmPlugins/engagementPlatformPmPlugin/commands/setMessageState';
3
+ export function stopMessage(api, coordinationClient) {
4
+ return async messageId => {
5
+ var _api$engagementPlatfo, _api$engagementPlatfo2;
6
+ if (!api) {
7
+ return false;
8
+ }
9
+ const messageStates = (_api$engagementPlatfo = (_api$engagementPlatfo2 = api.engagementPlatform.sharedState.currentState()) === null || _api$engagementPlatfo2 === void 0 ? void 0 : _api$engagementPlatfo2.messageStates) !== null && _api$engagementPlatfo !== void 0 ? _api$engagementPlatfo : {};
10
+ const isActive = messageStates[messageId];
11
+ if (!isActive) {
12
+ return true;
13
+ }
14
+ try {
15
+ const isStopped = await coordinationClient.stop(messageId);
16
+ if (isStopped) {
17
+ api.core.actions.execute(setMessageState(messageId, false));
18
+ }
19
+ return isStopped;
20
+ } catch (error) {
21
+ var _api$analytics;
22
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent({
23
+ action: ACTION.ERRORED,
24
+ actionSubject: ACTION_SUBJECT.ENGAGEMENT_PLATFORM,
25
+ eventType: EVENT_TYPE.OPERATIONAL,
26
+ attributes: {
27
+ error: error instanceof Error ? error.message : `${error}`,
28
+ errorStack: error instanceof Error ? error.stack : undefined
29
+ }
30
+ });
31
+ return false;
32
+ }
33
+ };
34
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,20 +1,28 @@
1
- import { createPlugin, engagementPlatformPluginKey } from './pm-plugins/main';
1
+ import { startMessage } from './actions/startMessage';
2
+ import { stopMessage } from './actions/stopMessage';
3
+ import { engagementPlatformPmPlugin } from './pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin';
4
+ import { engagementPlatformPmPluginKey } from './pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey';
2
5
  export const engagementPlatformPlugin = ({
3
- config
6
+ config,
7
+ api
4
8
  }) => {
5
9
  return {
6
10
  name: 'engagementPlatform',
11
+ actions: {
12
+ startMessage: startMessage(api, config.coordinationClient),
13
+ stopMessage: stopMessage(api, config.coordinationClient)
14
+ },
7
15
  pmPlugins() {
8
16
  return [{
9
- name: 'engagementPlatform',
10
- plugin: () => createPlugin(config)
17
+ name: 'engagementPlatformPmPlugin',
18
+ plugin: () => engagementPlatformPmPlugin(config)
11
19
  }];
12
20
  },
13
21
  getSharedState(editorState) {
14
- if (!config || !editorState) {
22
+ if (!editorState) {
15
23
  return undefined;
16
24
  }
17
- return engagementPlatformPluginKey.getState(editorState);
25
+ return engagementPlatformPmPluginKey.getState(editorState);
18
26
  }
19
27
  };
20
28
  };
@@ -0,0 +1,14 @@
1
+ import { engagementPlatformPmPluginKey } from '../engagementPlatformPmPluginKey';
2
+ /** Set the state of a message in the Engagement Platform plugin */
3
+ export const setMessageState = (messageIs, state) => ({
4
+ tr
5
+ }) => {
6
+ var _tr$getMeta;
7
+ const meta = {
8
+ newMessageStates: {
9
+ ...((_tr$getMeta = tr.getMeta(engagementPlatformPmPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.messageStates),
10
+ [messageIs]: state
11
+ }
12
+ };
13
+ return tr.setMeta(engagementPlatformPmPluginKey, meta);
14
+ };
@@ -0,0 +1,38 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { engagementPlatformPmPluginKey } from './engagementPlatformPmPluginKey';
3
+ export const engagementPlatformPmPlugin = pluginConfig => {
4
+ return new SafePlugin({
5
+ key: engagementPlatformPmPluginKey,
6
+ state: {
7
+ init: () => {
8
+ return {
9
+ messageStates: {},
10
+ epComponents: pluginConfig.epComponents,
11
+ epHooks: pluginConfig.epHooks,
12
+ coordinationClient: pluginConfig.coordinationClient
13
+ };
14
+ },
15
+ apply: (tr, pluginState) => {
16
+ const meta = tr.getMeta(engagementPlatformPmPluginKey);
17
+ if (!meta) {
18
+ return pluginState;
19
+ }
20
+ const newState = {
21
+ ...pluginState,
22
+ messageStates: {
23
+ ...pluginState.messageStates,
24
+ ...meta.newMessageStates
25
+ }
26
+ };
27
+
28
+ // Remove false message states to save memory
29
+ Object.entries(newState.messageStates).forEach(([key, value]) => {
30
+ if (!value) {
31
+ delete newState.messageStates[key];
32
+ }
33
+ });
34
+ return newState;
35
+ }
36
+ }
37
+ });
38
+ };
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export const engagementPlatformPmPluginKey = new PluginKey('engagementPlatformPmPlugin');
@@ -0,0 +1,59 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
4
+ import { setMessageState } from '../pmPlugins/engagementPlatformPmPlugin/commands/setMessageState';
5
+ export function startMessage(api, coordinationClient) {
6
+ return /*#__PURE__*/function () {
7
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(messageId, variationId) {
8
+ var _api$engagementPlatfo, _api$engagementPlatfo2;
9
+ var messageStates, isActive, isStarted, _api$analytics;
10
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
11
+ while (1) switch (_context.prev = _context.next) {
12
+ case 0:
13
+ if (api) {
14
+ _context.next = 2;
15
+ break;
16
+ }
17
+ return _context.abrupt("return", false);
18
+ case 2:
19
+ messageStates = (_api$engagementPlatfo = (_api$engagementPlatfo2 = api.engagementPlatform.sharedState.currentState()) === null || _api$engagementPlatfo2 === void 0 ? void 0 : _api$engagementPlatfo2.messageStates) !== null && _api$engagementPlatfo !== void 0 ? _api$engagementPlatfo : {};
20
+ isActive = messageStates[messageId];
21
+ if (!isActive) {
22
+ _context.next = 6;
23
+ break;
24
+ }
25
+ return _context.abrupt("return", true);
26
+ case 6:
27
+ _context.prev = 6;
28
+ _context.next = 9;
29
+ return coordinationClient.start(messageId, variationId);
30
+ case 9:
31
+ isStarted = _context.sent;
32
+ if (isStarted) {
33
+ api.core.actions.execute(setMessageState(messageId, true));
34
+ }
35
+ return _context.abrupt("return", isStarted);
36
+ case 14:
37
+ _context.prev = 14;
38
+ _context.t0 = _context["catch"](6);
39
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
40
+ action: ACTION.ERRORED,
41
+ actionSubject: ACTION_SUBJECT.ENGAGEMENT_PLATFORM,
42
+ eventType: EVENT_TYPE.OPERATIONAL,
43
+ attributes: {
44
+ error: _context.t0 instanceof Error ? _context.t0.message : "".concat(_context.t0),
45
+ errorStack: _context.t0 instanceof Error ? _context.t0.stack : undefined
46
+ }
47
+ });
48
+ return _context.abrupt("return", false);
49
+ case 18:
50
+ case "end":
51
+ return _context.stop();
52
+ }
53
+ }, _callee, null, [[6, 14]]);
54
+ }));
55
+ return function (_x, _x2) {
56
+ return _ref.apply(this, arguments);
57
+ };
58
+ }();
59
+ }
@@ -0,0 +1,59 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
4
+ import { setMessageState } from '../pmPlugins/engagementPlatformPmPlugin/commands/setMessageState';
5
+ export function stopMessage(api, coordinationClient) {
6
+ return /*#__PURE__*/function () {
7
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(messageId) {
8
+ var _api$engagementPlatfo, _api$engagementPlatfo2;
9
+ var messageStates, isActive, isStopped, _api$analytics;
10
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
11
+ while (1) switch (_context.prev = _context.next) {
12
+ case 0:
13
+ if (api) {
14
+ _context.next = 2;
15
+ break;
16
+ }
17
+ return _context.abrupt("return", false);
18
+ case 2:
19
+ messageStates = (_api$engagementPlatfo = (_api$engagementPlatfo2 = api.engagementPlatform.sharedState.currentState()) === null || _api$engagementPlatfo2 === void 0 ? void 0 : _api$engagementPlatfo2.messageStates) !== null && _api$engagementPlatfo !== void 0 ? _api$engagementPlatfo : {};
20
+ isActive = messageStates[messageId];
21
+ if (isActive) {
22
+ _context.next = 6;
23
+ break;
24
+ }
25
+ return _context.abrupt("return", true);
26
+ case 6:
27
+ _context.prev = 6;
28
+ _context.next = 9;
29
+ return coordinationClient.stop(messageId);
30
+ case 9:
31
+ isStopped = _context.sent;
32
+ if (isStopped) {
33
+ api.core.actions.execute(setMessageState(messageId, false));
34
+ }
35
+ return _context.abrupt("return", isStopped);
36
+ case 14:
37
+ _context.prev = 14;
38
+ _context.t0 = _context["catch"](6);
39
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
40
+ action: ACTION.ERRORED,
41
+ actionSubject: ACTION_SUBJECT.ENGAGEMENT_PLATFORM,
42
+ eventType: EVENT_TYPE.OPERATIONAL,
43
+ attributes: {
44
+ error: _context.t0 instanceof Error ? _context.t0.message : "".concat(_context.t0),
45
+ errorStack: _context.t0 instanceof Error ? _context.t0.stack : undefined
46
+ }
47
+ });
48
+ return _context.abrupt("return", false);
49
+ case 18:
50
+ case "end":
51
+ return _context.stop();
52
+ }
53
+ }, _callee, null, [[6, 14]]);
54
+ }));
55
+ return function (_x) {
56
+ return _ref.apply(this, arguments);
57
+ };
58
+ }();
59
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,21 +1,29 @@
1
- import { createPlugin, engagementPlatformPluginKey } from './pm-plugins/main';
1
+ import { startMessage } from './actions/startMessage';
2
+ import { stopMessage } from './actions/stopMessage';
3
+ import { engagementPlatformPmPlugin } from './pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPlugin';
4
+ import { engagementPlatformPmPluginKey } from './pmPlugins/engagementPlatformPmPlugin/engagementPlatformPmPluginKey';
2
5
  export var engagementPlatformPlugin = function engagementPlatformPlugin(_ref) {
3
- var config = _ref.config;
6
+ var config = _ref.config,
7
+ api = _ref.api;
4
8
  return {
5
9
  name: 'engagementPlatform',
10
+ actions: {
11
+ startMessage: startMessage(api, config.coordinationClient),
12
+ stopMessage: stopMessage(api, config.coordinationClient)
13
+ },
6
14
  pmPlugins: function pmPlugins() {
7
15
  return [{
8
- name: 'engagementPlatform',
16
+ name: 'engagementPlatformPmPlugin',
9
17
  plugin: function plugin() {
10
- return createPlugin(config);
18
+ return engagementPlatformPmPlugin(config);
11
19
  }
12
20
  }];
13
21
  },
14
22
  getSharedState: function getSharedState(editorState) {
15
- if (!config || !editorState) {
23
+ if (!editorState) {
16
24
  return undefined;
17
25
  }
18
- return engagementPlatformPluginKey.getState(editorState);
26
+ return engagementPlatformPmPluginKey.getState(editorState);
19
27
  }
20
28
  };
21
29
  };
@@ -0,0 +1,15 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ import { engagementPlatformPmPluginKey } from '../engagementPlatformPmPluginKey';
5
+ /** Set the state of a message in the Engagement Platform plugin */
6
+ export var setMessageState = function setMessageState(messageIs, state) {
7
+ return function (_ref) {
8
+ var _tr$getMeta;
9
+ var tr = _ref.tr;
10
+ var meta = {
11
+ newMessageStates: _objectSpread(_objectSpread({}, (_tr$getMeta = tr.getMeta(engagementPlatformPmPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.messageStates), {}, _defineProperty({}, messageIs, state))
12
+ };
13
+ return tr.setMeta(engagementPlatformPmPluginKey, meta);
14
+ };
15
+ };
@@ -0,0 +1,41 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
+ import { engagementPlatformPmPluginKey } from './engagementPlatformPmPluginKey';
7
+ export var engagementPlatformPmPlugin = function engagementPlatformPmPlugin(pluginConfig) {
8
+ return new SafePlugin({
9
+ key: engagementPlatformPmPluginKey,
10
+ state: {
11
+ init: function init() {
12
+ return {
13
+ messageStates: {},
14
+ epComponents: pluginConfig.epComponents,
15
+ epHooks: pluginConfig.epHooks,
16
+ coordinationClient: pluginConfig.coordinationClient
17
+ };
18
+ },
19
+ apply: function apply(tr, pluginState) {
20
+ var meta = tr.getMeta(engagementPlatformPmPluginKey);
21
+ if (!meta) {
22
+ return pluginState;
23
+ }
24
+ var newState = _objectSpread(_objectSpread({}, pluginState), {}, {
25
+ messageStates: _objectSpread(_objectSpread({}, pluginState.messageStates), meta.newMessageStates)
26
+ });
27
+
28
+ // Remove false message states to save memory
29
+ Object.entries(newState.messageStates).forEach(function (_ref) {
30
+ var _ref2 = _slicedToArray(_ref, 2),
31
+ key = _ref2[0],
32
+ value = _ref2[1];
33
+ if (!value) {
34
+ delete newState.messageStates[key];
35
+ }
36
+ });
37
+ return newState;
38
+ }
39
+ }
40
+ });
41
+ };
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export var engagementPlatformPmPluginKey = new PluginKey('engagementPlatformPmPlugin');
@@ -0,0 +1,3 @@
1
+ import type { CoordinationClient } from '../engagementPlatformPluginType';
2
+ import type { EngagementPlatformPluginApi } from './types';
3
+ export declare function startMessage(api: EngagementPlatformPluginApi | undefined, coordinationClient: CoordinationClient): (messageId: string, variationId?: string) => Promise<boolean>;
@@ -0,0 +1,3 @@
1
+ import type { CoordinationClient } from '../engagementPlatformPluginType';
2
+ import type { EngagementPlatformPluginApi } from './types';
3
+ export declare function stopMessage(api: EngagementPlatformPluginApi | undefined, coordinationClient: CoordinationClient): (messageId: string) => Promise<boolean>;
@@ -0,0 +1,2 @@
1
+ import type { EngagementPlatformPlugin } from '../engagementPlatformPluginType';
2
+ export type EngagementPlatformPluginApi = Parameters<EngagementPlatformPlugin>[0]['api'];
@@ -1,28 +1,74 @@
1
- import type { PropsWithChildren, ReactNode } from 'react';
2
- import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
1
+ import type { ComponentType, PropsWithChildren, ReactNode } from 'react';
2
+ import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
+ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
+ import type { EngagementPlatformPmPluginState } from './pmPlugins/engagementPlatformPmPlugin/types';
3
5
  export type EngagementPlatformPlugin = NextEditorPlugin<'engagementPlatform', {
4
- pluginConfiguration: EngagementPlatformPluginOptions;
5
- dependencies: [];
6
+ actions: {
7
+ /**
8
+ * Start an Engagement Platform external message with given ID and optional variation ID.
9
+ *
10
+ * This API action requires the `coordinationClient` to be provided in the plugin configuration.
11
+ *
12
+ * WARNING: Don't forget to STOP
13
+ *
14
+ * You must call {@link stopMessage} when your message has finished being displayed to a user.
15
+ * If you do not call {@link stopMessage}, your message will prevent the user from seeing any other
16
+ * messages until the Expiry time for the message is reached.
17
+ *
18
+ * @see https://developer.atlassian.com/platform/personalization/engagement/guides/external/create-external-message/#using-the-lower-level-react-class-directly---coordinationclient
19
+ */
20
+ startMessage: (messageId: string, variationId?: string) => Promise<boolean>;
21
+ /**
22
+ * Stop an Engagement Platform external message with given ID.
23
+ *
24
+ * This API action requires the `coordinationClient` to be provided in the plugin configuration.
25
+ *
26
+ * @see https://developer.atlassian.com/platform/personalization/engagement/guides/external/create-external-message/#using-the-lower-level-react-class-directly---coordinationclient
27
+ */
28
+ stopMessage: (messageId: string) => Promise<boolean>;
29
+ };
30
+ pluginConfiguration: EngagementPlatformPluginConfig;
31
+ dependencies: [OptionalPlugin<AnalyticsPlugin>];
6
32
  sharedState: EngagementPlatformPluginState;
7
33
  }>;
34
+ /**
35
+ * Engagement Platform coordination client.
36
+ *
37
+ * This type should be the same as the `CoordinationClientType`
38
+ * from the `@atlassiansox/engagekit-ts` package.
39
+ */
8
40
  export interface CoordinationClient {
9
41
  start(messageId: string, variationId?: string): Promise<boolean>;
10
42
  stop(messageId: string): Promise<boolean>;
11
43
  }
12
- export type EngagementPlatformPluginOptions = {
44
+ export type EngagementPlatformPluginConfig = {
13
45
  epComponents: EpComponents;
14
46
  epHooks: EpHooks;
47
+ /**
48
+ * Engagement Platform API client.
49
+ *
50
+ * This client is used to start and stop external messages in the Engagement Platform.
51
+ * It should be provided by a product.
52
+ *
53
+ * Without this client the next Engagement Platform plugin api calls will not work:
54
+ * - `startMessage`
55
+ * - `stopMessage`
56
+ * - `getMessageActivities`
57
+ * - `isMessageActive`
58
+ *
59
+ * The client lives in the `@atlassiansox/engagekit-ts` package.
60
+ */
15
61
  coordinationClient: CoordinationClient;
16
62
  };
17
63
  export type EpComponents = {
18
- EngagementProvider: React.ComponentType<PropsWithChildren<{}>>;
19
- EngagementSpotlight: React.ComponentType<{
64
+ EngagementProvider: ComponentType<PropsWithChildren<{}>>;
65
+ EngagementSpotlight: ComponentType<{
20
66
  engagementId: string;
21
67
  }>;
22
- EngagementInlineDialog: React.ComponentType<PropsWithChildren<{
68
+ EngagementInlineDialog: ComponentType<PropsWithChildren<{
23
69
  engagementId: string;
24
70
  }>>;
25
- Coordination: React.ComponentType<PropsWithChildren<{
71
+ Coordination: ComponentType<PropsWithChildren<{
26
72
  client: CoordinationClient;
27
73
  messageId: string;
28
74
  fallback: ReactNode;
@@ -31,8 +77,5 @@ export type EpComponents = {
31
77
  export type EpHooks = {
32
78
  useCoordination: (client: CoordinationClient, messageId: string) => [boolean, (force?: boolean) => Promise<void>];
33
79
  };
34
- export type EngagementPlatformPluginState = {
35
- epComponents: EpComponents;
36
- epHooks: EpHooks;
37
- coordinationClient: CoordinationClient;
38
- } | undefined;
80
+ /** Shared state of the Engagement Platform plugin. */
81
+ export type EngagementPlatformPluginState = EngagementPlatformPmPluginState | undefined;
@@ -1,2 +1,2 @@
1
1
  export { engagementPlatformPlugin } from './engagementPlatformPlugin';
2
- export type { EngagementPlatformPlugin, EngagementPlatformPluginOptions, EpComponents, EpHooks, CoordinationClient, } from './engagementPlatformPluginType';
2
+ export type { EngagementPlatformPlugin, EngagementPlatformPluginConfig, EpComponents, EpHooks, CoordinationClient, } from './engagementPlatformPluginType';
@@ -0,0 +1,3 @@
1
+ import type { EditorCommand } from '@atlaskit/editor-common/types';
2
+ /** Set the state of a message in the Engagement Platform plugin */
3
+ export declare const setMessageState: (messageIs: string, state: boolean) => EditorCommand;
@@ -0,0 +1,4 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import type { EngagementPlatformPluginConfig } from '../../engagementPlatformPluginType';
3
+ import type { EngagementPlatformPmPluginState } from './types';
4
+ export declare const engagementPlatformPmPlugin: (pluginConfig: EngagementPlatformPluginConfig) => SafePlugin<EngagementPlatformPmPluginState>;
@@ -0,0 +1,3 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ import type { EngagementPlatformPluginState } from '../../engagementPlatformPluginType';
3
+ export declare const engagementPlatformPmPluginKey: PluginKey<EngagementPlatformPluginState>;
@@ -0,0 +1,25 @@
1
+ import type { CoordinationClient, EpComponents, EpHooks } from '../../engagementPlatformPluginType';
2
+ export interface EngagementPlatformPmPluginState {
3
+ /**
4
+ * State of Engagement Platform messages in the Editor.
5
+ *
6
+ * Contains a map of message IDs to their active state.
7
+ */
8
+ messageStates: {
9
+ [messageId: string]: boolean;
10
+ };
11
+ /** Engagement Platform coordination client */
12
+ coordinationClient: CoordinationClient;
13
+ epComponents: EpComponents;
14
+ epHooks: EpHooks;
15
+ }
16
+ export interface EngagementPlatformPmPluginTrMeta {
17
+ /**
18
+ * New state of Engagement Platform messages in the Editor.
19
+ *
20
+ * This state will be merged (NOT REPLACED) with the existing state.
21
+ */
22
+ newMessageStates: {
23
+ [messageId: string]: boolean;
24
+ };
25
+ }
@@ -0,0 +1,3 @@
1
+ import type { CoordinationClient } from '../engagementPlatformPluginType';
2
+ import type { EngagementPlatformPluginApi } from './types';
3
+ export declare function startMessage(api: EngagementPlatformPluginApi | undefined, coordinationClient: CoordinationClient): (messageId: string, variationId?: string) => Promise<boolean>;
@@ -0,0 +1,3 @@
1
+ import type { CoordinationClient } from '../engagementPlatformPluginType';
2
+ import type { EngagementPlatformPluginApi } from './types';
3
+ export declare function stopMessage(api: EngagementPlatformPluginApi | undefined, coordinationClient: CoordinationClient): (messageId: string) => Promise<boolean>;
@@ -0,0 +1,2 @@
1
+ import type { EngagementPlatformPlugin } from '../engagementPlatformPluginType';
2
+ export type EngagementPlatformPluginApi = Parameters<EngagementPlatformPlugin>[0]['api'];
@@ -1,29 +1,76 @@
1
- import type { PropsWithChildren, ReactNode } from 'react';
2
- import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
1
+ import type { ComponentType, PropsWithChildren, ReactNode } from 'react';
2
+ import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
+ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
+ import type { EngagementPlatformPmPluginState } from './pmPlugins/engagementPlatformPmPlugin/types';
3
5
  export type EngagementPlatformPlugin = NextEditorPlugin<'engagementPlatform', {
4
- pluginConfiguration: EngagementPlatformPluginOptions;
6
+ actions: {
7
+ /**
8
+ * Start an Engagement Platform external message with given ID and optional variation ID.
9
+ *
10
+ * This API action requires the `coordinationClient` to be provided in the plugin configuration.
11
+ *
12
+ * WARNING: Don't forget to STOP
13
+ *
14
+ * You must call {@link stopMessage} when your message has finished being displayed to a user.
15
+ * If you do not call {@link stopMessage}, your message will prevent the user from seeing any other
16
+ * messages until the Expiry time for the message is reached.
17
+ *
18
+ * @see https://developer.atlassian.com/platform/personalization/engagement/guides/external/create-external-message/#using-the-lower-level-react-class-directly---coordinationclient
19
+ */
20
+ startMessage: (messageId: string, variationId?: string) => Promise<boolean>;
21
+ /**
22
+ * Stop an Engagement Platform external message with given ID.
23
+ *
24
+ * This API action requires the `coordinationClient` to be provided in the plugin configuration.
25
+ *
26
+ * @see https://developer.atlassian.com/platform/personalization/engagement/guides/external/create-external-message/#using-the-lower-level-react-class-directly---coordinationclient
27
+ */
28
+ stopMessage: (messageId: string) => Promise<boolean>;
29
+ };
30
+ pluginConfiguration: EngagementPlatformPluginConfig;
5
31
  dependencies: [
32
+ OptionalPlugin<AnalyticsPlugin>
6
33
  ];
7
34
  sharedState: EngagementPlatformPluginState;
8
35
  }>;
36
+ /**
37
+ * Engagement Platform coordination client.
38
+ *
39
+ * This type should be the same as the `CoordinationClientType`
40
+ * from the `@atlassiansox/engagekit-ts` package.
41
+ */
9
42
  export interface CoordinationClient {
10
43
  start(messageId: string, variationId?: string): Promise<boolean>;
11
44
  stop(messageId: string): Promise<boolean>;
12
45
  }
13
- export type EngagementPlatformPluginOptions = {
46
+ export type EngagementPlatformPluginConfig = {
14
47
  epComponents: EpComponents;
15
48
  epHooks: EpHooks;
49
+ /**
50
+ * Engagement Platform API client.
51
+ *
52
+ * This client is used to start and stop external messages in the Engagement Platform.
53
+ * It should be provided by a product.
54
+ *
55
+ * Without this client the next Engagement Platform plugin api calls will not work:
56
+ * - `startMessage`
57
+ * - `stopMessage`
58
+ * - `getMessageActivities`
59
+ * - `isMessageActive`
60
+ *
61
+ * The client lives in the `@atlassiansox/engagekit-ts` package.
62
+ */
16
63
  coordinationClient: CoordinationClient;
17
64
  };
18
65
  export type EpComponents = {
19
- EngagementProvider: React.ComponentType<PropsWithChildren<{}>>;
20
- EngagementSpotlight: React.ComponentType<{
66
+ EngagementProvider: ComponentType<PropsWithChildren<{}>>;
67
+ EngagementSpotlight: ComponentType<{
21
68
  engagementId: string;
22
69
  }>;
23
- EngagementInlineDialog: React.ComponentType<PropsWithChildren<{
70
+ EngagementInlineDialog: ComponentType<PropsWithChildren<{
24
71
  engagementId: string;
25
72
  }>>;
26
- Coordination: React.ComponentType<PropsWithChildren<{
73
+ Coordination: ComponentType<PropsWithChildren<{
27
74
  client: CoordinationClient;
28
75
  messageId: string;
29
76
  fallback: ReactNode;
@@ -35,8 +82,5 @@ export type EpHooks = {
35
82
  (force?: boolean) => Promise<void>
36
83
  ];
37
84
  };
38
- export type EngagementPlatformPluginState = {
39
- epComponents: EpComponents;
40
- epHooks: EpHooks;
41
- coordinationClient: CoordinationClient;
42
- } | undefined;
85
+ /** Shared state of the Engagement Platform plugin. */
86
+ export type EngagementPlatformPluginState = EngagementPlatformPmPluginState | undefined;
@@ -1,2 +1,2 @@
1
1
  export { engagementPlatformPlugin } from './engagementPlatformPlugin';
2
- export type { EngagementPlatformPlugin, EngagementPlatformPluginOptions, EpComponents, EpHooks, CoordinationClient, } from './engagementPlatformPluginType';
2
+ export type { EngagementPlatformPlugin, EngagementPlatformPluginConfig, EpComponents, EpHooks, CoordinationClient, } from './engagementPlatformPluginType';
@@ -0,0 +1,3 @@
1
+ import type { EditorCommand } from '@atlaskit/editor-common/types';
2
+ /** Set the state of a message in the Engagement Platform plugin */
3
+ export declare const setMessageState: (messageIs: string, state: boolean) => EditorCommand;
@@ -0,0 +1,4 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import type { EngagementPlatformPluginConfig } from '../../engagementPlatformPluginType';
3
+ import type { EngagementPlatformPmPluginState } from './types';
4
+ export declare const engagementPlatformPmPlugin: (pluginConfig: EngagementPlatformPluginConfig) => SafePlugin<EngagementPlatformPmPluginState>;
@@ -0,0 +1,3 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ import type { EngagementPlatformPluginState } from '../../engagementPlatformPluginType';
3
+ export declare const engagementPlatformPmPluginKey: PluginKey<EngagementPlatformPluginState>;
@@ -0,0 +1,25 @@
1
+ import type { CoordinationClient, EpComponents, EpHooks } from '../../engagementPlatformPluginType';
2
+ export interface EngagementPlatformPmPluginState {
3
+ /**
4
+ * State of Engagement Platform messages in the Editor.
5
+ *
6
+ * Contains a map of message IDs to their active state.
7
+ */
8
+ messageStates: {
9
+ [messageId: string]: boolean;
10
+ };
11
+ /** Engagement Platform coordination client */
12
+ coordinationClient: CoordinationClient;
13
+ epComponents: EpComponents;
14
+ epHooks: EpHooks;
15
+ }
16
+ export interface EngagementPlatformPmPluginTrMeta {
17
+ /**
18
+ * New state of Engagement Platform messages in the Editor.
19
+ *
20
+ * This state will be merged (NOT REPLACED) with the existing state.
21
+ */
22
+ newMessageStates: {
23
+ [messageId: string]: boolean;
24
+ };
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-engagement-platform",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Engagement platform plugin for @atlaskit/editor-core“",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,6 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@atlaskit/editor-common": "^93.1.0",
37
+ "@atlaskit/editor-plugin-analytics": "^1.8.0",
37
38
  "@atlaskit/editor-prosemirror": "6.0.0",
38
39
  "@babel/runtime": "^7.0.0"
39
40
  },
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.engagementPlatformPluginKey = exports.createPlugin = void 0;
7
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
- var _state = require("@atlaskit/editor-prosemirror/state");
9
- var engagementPlatformPluginKey = exports.engagementPlatformPluginKey = new _state.PluginKey('engagementPlatformPlugin');
10
- var createPlugin = exports.createPlugin = function createPlugin(pluginOptions) {
11
- return new _safePlugin.SafePlugin({
12
- key: engagementPlatformPluginKey,
13
- state: {
14
- init: function init() {
15
- if (!pluginOptions) {
16
- return undefined;
17
- }
18
- return {
19
- epComponents: pluginOptions.epComponents,
20
- epHooks: pluginOptions.epHooks,
21
- coordinationClient: pluginOptions.coordinationClient
22
- };
23
- },
24
- apply: function apply(_tr, pluginState) {
25
- return pluginState;
26
- }
27
- }
28
- });
29
- };
@@ -1,23 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- export const engagementPlatformPluginKey = new PluginKey('engagementPlatformPlugin');
4
- export const createPlugin = pluginOptions => {
5
- return new SafePlugin({
6
- key: engagementPlatformPluginKey,
7
- state: {
8
- init: () => {
9
- if (!pluginOptions) {
10
- return undefined;
11
- }
12
- return {
13
- epComponents: pluginOptions.epComponents,
14
- epHooks: pluginOptions.epHooks,
15
- coordinationClient: pluginOptions.coordinationClient
16
- };
17
- },
18
- apply: (_tr, pluginState) => {
19
- return pluginState;
20
- }
21
- }
22
- });
23
- };
@@ -1,23 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- export var engagementPlatformPluginKey = new PluginKey('engagementPlatformPlugin');
4
- export var createPlugin = function createPlugin(pluginOptions) {
5
- return new SafePlugin({
6
- key: engagementPlatformPluginKey,
7
- state: {
8
- init: function init() {
9
- if (!pluginOptions) {
10
- return undefined;
11
- }
12
- return {
13
- epComponents: pluginOptions.epComponents,
14
- epHooks: pluginOptions.epHooks,
15
- coordinationClient: pluginOptions.coordinationClient
16
- };
17
- },
18
- apply: function apply(_tr, pluginState) {
19
- return pluginState;
20
- }
21
- }
22
- });
23
- };
@@ -1,9 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import type { EngagementPlatformPluginOptions, EngagementPlatformPluginState } from '../engagementPlatformPluginType';
4
- export declare const engagementPlatformPluginKey: PluginKey<EngagementPlatformPluginState>;
5
- export declare const createPlugin: (pluginOptions: EngagementPlatformPluginOptions) => SafePlugin<{
6
- epComponents: import("../engagementPlatformPluginType").EpComponents;
7
- epHooks: import("../engagementPlatformPluginType").EpHooks;
8
- coordinationClient: import("../engagementPlatformPluginType").CoordinationClient;
9
- } | undefined>;
@@ -1,9 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import type { EngagementPlatformPluginOptions, EngagementPlatformPluginState } from '../engagementPlatformPluginType';
4
- export declare const engagementPlatformPluginKey: PluginKey<EngagementPlatformPluginState>;
5
- export declare const createPlugin: (pluginOptions: EngagementPlatformPluginOptions) => SafePlugin<{
6
- epComponents: import("../engagementPlatformPluginType").EpComponents;
7
- epHooks: import("../engagementPlatformPluginType").EpHooks;
8
- coordinationClient: import("../engagementPlatformPluginType").CoordinationClient;
9
- } | undefined>;