@atlaskit/editor-synced-block-provider 2.1.1 → 2.1.2

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 2.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`62d0954696c7e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/62d0954696c7e) -
8
+ [ux] EDITOR-1648 handle permission denied, not found and any generic error for sync block
9
+
3
10
  ## 2.1.1
4
11
 
5
12
  ### Patch Changes
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.SyncBlockStoreManager = void 0;
8
- exports.useFetchDocNode = useFetchDocNode;
8
+ exports.useFetchSyncBlockData = useFetchSyncBlockData;
9
9
  exports.useHandleContentChanges = useHandleContentChanges;
10
10
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
@@ -18,6 +18,7 @@ var _uuid = _interopRequireDefault(require("uuid"));
18
18
  var _ari = require("../utils/ari");
19
19
  var _utils = require("../utils/utils");
20
20
  var _rebaseTransaction2 = require("./rebase-transaction");
21
+ var _types = require("./types");
21
22
  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; }
22
23
  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; }
23
24
  // Do this typedef to make it clear that
@@ -82,7 +83,7 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
82
83
  key: "fetchSyncBlockData",
83
84
  value: function () {
84
85
  var _fetchSyncBlockData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(syncBlockNode) {
85
- var syncNode, data, sourceURL;
86
+ var syncNode, data, sourceURL, fetchSyncBlockDataResult;
86
87
  return _regenerator.default.wrap(function _callee$(_context) {
87
88
  while (1) switch (_context.prev = _context.next) {
88
89
  case 0:
@@ -110,13 +111,17 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
110
111
  throw new Error('Failed to fetch sync block node data');
111
112
  case 10:
112
113
  sourceURL = this.getSyncBlockSourceURL(syncBlockNode);
113
- this.syncBlocks.set(syncBlockNode.attrs.localId, {
114
- syncNode: syncNode,
115
- sourceURL: sourceURL,
116
- syncBlockData: data[0]
117
- });
118
- return _context.abrupt("return", data[0]);
119
- case 13:
114
+ fetchSyncBlockDataResult = data[0];
115
+ if (!('status' in fetchSyncBlockDataResult)) {
116
+ // only adds it to the map if it did not error out
117
+ this.syncBlocks.set(syncBlockNode.attrs.localId, {
118
+ syncNode: syncNode,
119
+ sourceURL: sourceURL,
120
+ syncBlockData: fetchSyncBlockDataResult
121
+ });
122
+ }
123
+ return _context.abrupt("return", fetchSyncBlockDataResult);
124
+ case 14:
120
125
  case "end":
121
126
  return _context.stop();
122
127
  }
@@ -284,22 +289,30 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
284
289
  }
285
290
  }]);
286
291
  }();
287
- function useFetchDocNode(manager, syncBlockNode, defaultDocNode) {
288
- var _useState = (0, _react.useState)(defaultDocNode),
292
+ function useFetchSyncBlockData(manager, syncBlockNode) {
293
+ var _useState = (0, _react.useState)(null),
289
294
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
290
- docNode = _useState2[0],
291
- setDocNode = _useState2[1];
295
+ fetchSyncBlockDataResult = _useState2[0],
296
+ setFetchSyncBlockDataResult = _useState2[1];
292
297
  var fetchSyncBlockNode = (0, _react.useCallback)(function () {
293
298
  manager.fetchSyncBlockData(syncBlockNode).then(function (data) {
294
- return setDocNode({
295
- content: data.content || [],
296
- version: 1,
297
- type: 'doc'
298
- });
299
+ if ('status' in data) {
300
+ // if there is an error, we don't want to replace real existing data with the error data
301
+ if (!fetchSyncBlockDataResult || 'status' in fetchSyncBlockDataResult) {
302
+ setFetchSyncBlockDataResult(data);
303
+ }
304
+ } else {
305
+ setFetchSyncBlockDataResult(data);
306
+ }
299
307
  }).catch(function () {
300
308
  //TODO: EDITOR-1921 - add error analytics
309
+ if (!fetchSyncBlockDataResult || 'status' in fetchSyncBlockDataResult) {
310
+ setFetchSyncBlockDataResult({
311
+ status: _types.SyncBlockStatus.Errored
312
+ });
313
+ }
301
314
  });
302
- }, [manager, syncBlockNode, setDocNode]);
315
+ }, [manager, syncBlockNode, fetchSyncBlockDataResult]);
303
316
  (0, _react.useEffect)(function () {
304
317
  fetchSyncBlockNode();
305
318
  var interval = window.setInterval(fetchSyncBlockNode, 3000);
@@ -307,7 +320,7 @@ function useFetchDocNode(manager, syncBlockNode, defaultDocNode) {
307
320
  window.clearInterval(interval);
308
321
  };
309
322
  }, [fetchSyncBlockNode]);
310
- return docNode;
323
+ return fetchSyncBlockDataResult;
311
324
  }
312
325
  function useHandleContentChanges(manager, syncBlockNode) {
313
326
  (0, _react.useEffect)(function () {
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.SyncBlockDataProvider = void 0;
7
+ exports.SyncBlockStatus = exports.SyncBlockDataProvider = void 0;
8
8
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
9
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
10
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
@@ -13,6 +13,12 @@ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits
13
13
  var _nodeDataProvider = require("@atlaskit/node-data-provider");
14
14
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
15
15
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
16
+ var SyncBlockStatus = exports.SyncBlockStatus = /*#__PURE__*/function (SyncBlockStatus) {
17
+ SyncBlockStatus["Errored"] = "errored";
18
+ SyncBlockStatus["NotFound"] = "not_found";
19
+ SyncBlockStatus["Unauthorized"] = "unauthorized";
20
+ return SyncBlockStatus;
21
+ }({});
16
22
  var SyncBlockDataProvider = exports.SyncBlockDataProvider = /*#__PURE__*/function (_NodeDataProvider) {
17
23
  function SyncBlockDataProvider() {
18
24
  (0, _classCallCheck2.default)(this, SyncBlockDataProvider);
package/dist/cjs/index.js CHANGED
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "SyncBlockStatus", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _types.SyncBlockStatus;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "SyncBlockStoreManager", {
7
13
  enumerable: true,
8
14
  get: function get() {
@@ -57,10 +63,10 @@ Object.defineProperty(exports, "rebaseTransaction", {
57
63
  return _rebaseTransaction.rebaseTransaction;
58
64
  }
59
65
  });
60
- Object.defineProperty(exports, "useFetchDocNode", {
66
+ Object.defineProperty(exports, "useFetchSyncBlockData", {
61
67
  enumerable: true,
62
68
  get: function get() {
63
- return _syncBlockStoreManager.useFetchDocNode;
69
+ return _syncBlockStoreManager.useFetchSyncBlockData;
64
70
  }
65
71
  });
66
72
  Object.defineProperty(exports, "useHandleContentChanges", {
@@ -83,6 +89,7 @@ Object.defineProperty(exports, "useMemoizedSyncedBlockProvider", {
83
89
  });
84
90
  var _syncBlockProvider = require("./common/syncBlockProvider");
85
91
  var _syncBlockStoreManager = require("./common/syncBlockStoreManager");
92
+ var _types = require("./common/types");
86
93
  var _inMemory = require("./providers/inMemory");
87
94
  var _schema = require("./common/schema");
88
95
  var _confluenceContentAPI = require("./providers/confluenceContentAPI");
@@ -12,6 +12,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
12
12
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
13
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
14
14
  var _react = require("react");
15
+ var _types = require("../common/types");
15
16
  var _ari = require("../utils/ari");
16
17
  var _contentProperty4 = require("../utils/contentProperty");
17
18
  var _utils = require("../utils/utils");
@@ -37,6 +38,17 @@ var parseSyncedBlockContentPropertyValue = function parseSyncedBlockContentPrope
37
38
  throw new Error("Failed to parse synced block data: ".concat(error));
38
39
  }
39
40
  };
41
+ var getResponseStatus = function getResponseStatus(contentProperty) {
42
+ var _content$properties;
43
+ var content = 'blogPost' in contentProperty.data.confluence ? contentProperty.data.confluence.blogPost : contentProperty.data.confluence.page;
44
+ if (!content) {
45
+ return _types.SyncBlockStatus.Unauthorized;
46
+ }
47
+ if (!((_content$properties = content.properties) !== null && _content$properties !== void 0 && _content$properties[0])) {
48
+ return _types.SyncBlockStatus.NotFound;
49
+ }
50
+ return _types.SyncBlockStatus.Errored;
51
+ };
40
52
 
41
53
  /**
42
54
  * ADFFetchProvider implementation that fetches synced block data from Confluence Content API
@@ -50,12 +62,13 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
50
62
  key: "fetchData",
51
63
  value: function () {
52
64
  var _fetchData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(resourceId) {
53
- var _getPageIdAndTypeFrom, pageId, pageType, localId, key, options, value, _contentProperty$data, contentProperty, _contentProperty$data2, _contentProperty, syncedBlockData;
65
+ var _getPageIdAndTypeFrom, pageId, pageType, localId, key, options, status, value, _contentProperty$data, contentProperty, _contentProperty$data2, _contentProperty, syncedBlockData;
54
66
  return _regenerator.default.wrap(function _callee$(_context) {
55
67
  while (1) switch (_context.prev = _context.next) {
56
68
  case 0:
57
69
  _getPageIdAndTypeFrom = (0, _ari.getPageIdAndTypeFromAri)(resourceId), pageId = _getPageIdAndTypeFrom.id, pageType = _getPageIdAndTypeFrom.type;
58
70
  localId = (0, _ari.getLocalIdFromAri)(resourceId);
71
+ _context.prev = 2;
59
72
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
60
73
  options = {
61
74
  pageId: pageId,
@@ -64,29 +77,34 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
64
77
  pageType: pageType
65
78
  };
66
79
  if (!(0, _utils.isBlogPageType)(pageType)) {
67
- _context.next = 11;
80
+ _context.next = 13;
68
81
  break;
69
82
  }
70
- _context.next = 7;
83
+ _context.next = 8;
71
84
  return (0, _contentProperty4.getContentProperty)(options);
72
- case 7:
85
+ case 8:
73
86
  contentProperty = _context.sent;
74
- value = (_contentProperty$data = contentProperty.data.confluence.blogPost.properties) === null || _contentProperty$data === void 0 || (_contentProperty$data = _contentProperty$data[0]) === null || _contentProperty$data === void 0 ? void 0 : _contentProperty$data.value;
75
- _context.next = 15;
87
+ value = (_contentProperty$data = contentProperty.data.confluence.blogPost) === null || _contentProperty$data === void 0 || (_contentProperty$data = _contentProperty$data.properties) === null || _contentProperty$data === void 0 || (_contentProperty$data = _contentProperty$data[0]) === null || _contentProperty$data === void 0 ? void 0 : _contentProperty$data.value;
88
+ status = getResponseStatus(contentProperty);
89
+ _context.next = 18;
76
90
  break;
77
- case 11:
78
- _context.next = 13;
79
- return (0, _contentProperty4.getContentProperty)(options);
80
91
  case 13:
81
- _contentProperty = _context.sent;
82
- value = (_contentProperty$data2 = _contentProperty.data.confluence.page.properties) === null || _contentProperty$data2 === void 0 || (_contentProperty$data2 = _contentProperty$data2[0]) === null || _contentProperty$data2 === void 0 ? void 0 : _contentProperty$data2.value;
92
+ _context.next = 15;
93
+ return (0, _contentProperty4.getContentProperty)(options);
83
94
  case 15:
95
+ _contentProperty = _context.sent;
96
+ value = (_contentProperty$data2 = _contentProperty.data.confluence.page) === null || _contentProperty$data2 === void 0 || (_contentProperty$data2 = _contentProperty$data2.properties) === null || _contentProperty$data2 === void 0 || (_contentProperty$data2 = _contentProperty$data2[0]) === null || _contentProperty$data2 === void 0 ? void 0 : _contentProperty$data2.value;
97
+ status = getResponseStatus(_contentProperty);
98
+ case 18:
84
99
  if (value) {
85
- _context.next = 17;
100
+ _context.next = 20;
86
101
  break;
87
102
  }
88
- throw new Error('Content property value does not exist');
89
- case 17:
103
+ return _context.abrupt("return", {
104
+ status: status,
105
+ resourceId: resourceId
106
+ });
107
+ case 20:
90
108
  // Parse the synced block content from the property value
91
109
  syncedBlockData = parseSyncedBlockContentPropertyValue(value);
92
110
  return _context.abrupt("return", {
@@ -94,11 +112,18 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
94
112
  resourceId: resourceId,
95
113
  blockInstanceId: localId
96
114
  });
97
- case 19:
115
+ case 24:
116
+ _context.prev = 24;
117
+ _context.t0 = _context["catch"](2);
118
+ return _context.abrupt("return", {
119
+ status: _types.SyncBlockStatus.Errored,
120
+ resourceId: resourceId
121
+ });
122
+ case 27:
98
123
  case "end":
99
124
  return _context.stop();
100
125
  }
101
- }, _callee, this);
126
+ }, _callee, this, [[2, 24]]);
102
127
  }));
103
128
  function fetchData(_x) {
104
129
  return _fetchData.apply(this, arguments);
@@ -3,6 +3,7 @@ import uuid from 'uuid';
3
3
  import { resourceIdFromSourceAndLocalId } from '../utils/ari';
4
4
  import { convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockPMNodeToSyncBlockNode } from '../utils/utils';
5
5
  import { rebaseTransaction } from './rebase-transaction';
6
+ import { SyncBlockStatus } from './types';
6
7
 
7
8
  // Do this typedef to make it clear that
8
9
  // this is a local identifier for a resource for local use
@@ -76,12 +77,16 @@ export class SyncBlockStoreManager {
76
77
  throw new Error('Failed to fetch sync block node data');
77
78
  }
78
79
  const sourceURL = this.getSyncBlockSourceURL(syncBlockNode);
79
- this.syncBlocks.set(syncBlockNode.attrs.localId, {
80
- syncNode,
81
- sourceURL,
82
- syncBlockData: data[0]
83
- });
84
- return data[0];
80
+ const fetchSyncBlockDataResult = data[0];
81
+ if (!('status' in fetchSyncBlockDataResult)) {
82
+ // only adds it to the map if it did not error out
83
+ this.syncBlocks.set(syncBlockNode.attrs.localId, {
84
+ syncNode,
85
+ sourceURL,
86
+ syncBlockData: fetchSyncBlockDataResult
87
+ });
88
+ }
89
+ return fetchSyncBlockDataResult;
85
90
  }
86
91
 
87
92
  /**
@@ -197,17 +202,27 @@ export class SyncBlockStoreManager {
197
202
  this.confirmationTransaction = rebaseTransaction(this.confirmationTransaction, incomingTr, state);
198
203
  }
199
204
  }
200
- export function useFetchDocNode(manager, syncBlockNode, defaultDocNode) {
201
- const [docNode, setDocNode] = useState(defaultDocNode);
205
+ export function useFetchSyncBlockData(manager, syncBlockNode) {
206
+ const [fetchSyncBlockDataResult, setFetchSyncBlockDataResult] = useState(null);
202
207
  const fetchSyncBlockNode = useCallback(() => {
203
- manager.fetchSyncBlockData(syncBlockNode).then(data => setDocNode({
204
- content: data.content || [],
205
- version: 1,
206
- type: 'doc'
207
- })).catch(() => {
208
+ manager.fetchSyncBlockData(syncBlockNode).then(data => {
209
+ if ('status' in data) {
210
+ // if there is an error, we don't want to replace real existing data with the error data
211
+ if (!fetchSyncBlockDataResult || 'status' in fetchSyncBlockDataResult) {
212
+ setFetchSyncBlockDataResult(data);
213
+ }
214
+ } else {
215
+ setFetchSyncBlockDataResult(data);
216
+ }
217
+ }).catch(() => {
208
218
  //TODO: EDITOR-1921 - add error analytics
219
+ if (!fetchSyncBlockDataResult || 'status' in fetchSyncBlockDataResult) {
220
+ setFetchSyncBlockDataResult({
221
+ status: SyncBlockStatus.Errored
222
+ });
223
+ }
209
224
  });
210
- }, [manager, syncBlockNode, setDocNode]);
225
+ }, [manager, syncBlockNode, fetchSyncBlockDataResult]);
211
226
  useEffect(() => {
212
227
  fetchSyncBlockNode();
213
228
  const interval = window.setInterval(fetchSyncBlockNode, 3000);
@@ -215,7 +230,7 @@ export function useFetchDocNode(manager, syncBlockNode, defaultDocNode) {
215
230
  window.clearInterval(interval);
216
231
  };
217
232
  }, [fetchSyncBlockNode]);
218
- return docNode;
233
+ return fetchSyncBlockDataResult;
219
234
  }
220
235
  export function useHandleContentChanges(manager, syncBlockNode) {
221
236
  useEffect(() => {
@@ -1,2 +1,8 @@
1
1
  import { NodeDataProvider } from '@atlaskit/node-data-provider';
2
+ export let SyncBlockStatus = /*#__PURE__*/function (SyncBlockStatus) {
3
+ SyncBlockStatus["Errored"] = "errored";
4
+ SyncBlockStatus["NotFound"] = "not_found";
5
+ SyncBlockStatus["Unauthorized"] = "unauthorized";
6
+ return SyncBlockStatus;
7
+ }({});
2
8
  export class SyncBlockDataProvider extends NodeDataProvider {}
@@ -1,7 +1,8 @@
1
1
  /* eslint-disable @atlaskit/editor/no-re-export */
2
2
 
3
3
  export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './common/syncBlockProvider';
4
- export { SyncBlockStoreManager, useFetchDocNode, useHandleContentChanges } from './common/syncBlockStoreManager';
4
+ export { SyncBlockStoreManager, useFetchSyncBlockData, useHandleContentChanges } from './common/syncBlockStoreManager';
5
+ export { SyncBlockStatus } from './common/types';
5
6
  export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemory';
6
7
  export { getDefaultSyncBlockSchema } from './common/schema';
7
8
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluenceContentAPI';
@@ -1,5 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { useMemo } from 'react';
3
+ import { SyncBlockStatus } from '../common/types';
3
4
  import { getLocalIdFromAri, getPageIdAndTypeFromAri } from '../utils/ari';
4
5
  import { getContentProperty, createContentProperty, updateContentProperty } from '../utils/contentProperty';
5
6
  import { isBlogPageType } from '../utils/utils';
@@ -26,6 +27,17 @@ const parseSyncedBlockContentPropertyValue = value => {
26
27
  throw new Error(`Failed to parse synced block data: ${error}`);
27
28
  }
28
29
  };
30
+ const getResponseStatus = contentProperty => {
31
+ var _content$properties;
32
+ const content = 'blogPost' in contentProperty.data.confluence ? contentProperty.data.confluence.blogPost : contentProperty.data.confluence.page;
33
+ if (!content) {
34
+ return SyncBlockStatus.Unauthorized;
35
+ }
36
+ if (!((_content$properties = content.properties) !== null && _content$properties !== void 0 && _content$properties[0])) {
37
+ return SyncBlockStatus.NotFound;
38
+ }
39
+ return SyncBlockStatus.Errored;
40
+ };
29
41
 
30
42
  /**
31
43
  * ADFFetchProvider implementation that fetches synced block data from Confluence Content API
@@ -40,34 +52,47 @@ class ConfluenceADFFetchProvider {
40
52
  type: pageType
41
53
  } = getPageIdAndTypeFromAri(resourceId);
42
54
  const localId = getLocalIdFromAri(resourceId);
43
- const key = getContentPropertyKey(this.config.contentPropertyKey, localId);
44
- const options = {
45
- pageId,
46
- key,
47
- cloudId: this.config.cloudId,
48
- pageType
49
- };
50
- let value;
51
- if (isBlogPageType(pageType)) {
52
- var _contentProperty$data, _contentProperty$data2;
53
- const contentProperty = await getContentProperty(options);
54
- value = (_contentProperty$data = contentProperty.data.confluence.blogPost.properties) === null || _contentProperty$data === void 0 ? void 0 : (_contentProperty$data2 = _contentProperty$data[0]) === null || _contentProperty$data2 === void 0 ? void 0 : _contentProperty$data2.value;
55
- } else {
56
- var _contentProperty$data3, _contentProperty$data4;
57
- const contentProperty = await getContentProperty(options);
58
- value = (_contentProperty$data3 = contentProperty.data.confluence.page.properties) === null || _contentProperty$data3 === void 0 ? void 0 : (_contentProperty$data4 = _contentProperty$data3[0]) === null || _contentProperty$data4 === void 0 ? void 0 : _contentProperty$data4.value;
59
- }
60
- if (!value) {
61
- throw new Error('Content property value does not exist');
62
- }
55
+ try {
56
+ const key = getContentPropertyKey(this.config.contentPropertyKey, localId);
57
+ const options = {
58
+ pageId,
59
+ key,
60
+ cloudId: this.config.cloudId,
61
+ pageType
62
+ };
63
+ let status;
64
+ let value;
65
+ if (isBlogPageType(pageType)) {
66
+ var _contentProperty$data, _contentProperty$data2, _contentProperty$data3;
67
+ const contentProperty = await getContentProperty(options);
68
+ value = (_contentProperty$data = contentProperty.data.confluence.blogPost) === null || _contentProperty$data === void 0 ? void 0 : (_contentProperty$data2 = _contentProperty$data.properties) === null || _contentProperty$data2 === void 0 ? void 0 : (_contentProperty$data3 = _contentProperty$data2[0]) === null || _contentProperty$data3 === void 0 ? void 0 : _contentProperty$data3.value;
69
+ status = getResponseStatus(contentProperty);
70
+ } else {
71
+ var _contentProperty$data4, _contentProperty$data5, _contentProperty$data6;
72
+ const contentProperty = await getContentProperty(options);
73
+ value = (_contentProperty$data4 = contentProperty.data.confluence.page) === null || _contentProperty$data4 === void 0 ? void 0 : (_contentProperty$data5 = _contentProperty$data4.properties) === null || _contentProperty$data5 === void 0 ? void 0 : (_contentProperty$data6 = _contentProperty$data5[0]) === null || _contentProperty$data6 === void 0 ? void 0 : _contentProperty$data6.value;
74
+ status = getResponseStatus(contentProperty);
75
+ }
76
+ if (!value) {
77
+ return {
78
+ status: status,
79
+ resourceId
80
+ };
81
+ }
63
82
 
64
- // Parse the synced block content from the property value
65
- const syncedBlockData = parseSyncedBlockContentPropertyValue(value);
66
- return {
67
- content: syncedBlockData.content,
68
- resourceId,
69
- blockInstanceId: localId
70
- };
83
+ // Parse the synced block content from the property value
84
+ const syncedBlockData = parseSyncedBlockContentPropertyValue(value);
85
+ return {
86
+ content: syncedBlockData.content,
87
+ resourceId,
88
+ blockInstanceId: localId
89
+ };
90
+ } catch {
91
+ return {
92
+ status: SyncBlockStatus.Errored,
93
+ resourceId
94
+ };
95
+ }
71
96
  }
72
97
  }
73
98
 
@@ -85,17 +110,17 @@ class ConfluenceADFWriteProvider {
85
110
  pageType
86
111
  };
87
112
  if (isBlogPageType(pageType)) {
88
- var _contentProperty$data5;
113
+ var _contentProperty$data7;
89
114
  const contentProperty = await createContentProperty(options);
90
- if (((_contentProperty$data5 = contentProperty.data.confluence.createBlogPostProperty.blogPostProperty) === null || _contentProperty$data5 === void 0 ? void 0 : _contentProperty$data5.key) === key) {
115
+ if (((_contentProperty$data7 = contentProperty.data.confluence.createBlogPostProperty.blogPostProperty) === null || _contentProperty$data7 === void 0 ? void 0 : _contentProperty$data7.key) === key) {
91
116
  return key;
92
117
  } else {
93
118
  throw new Error('Failed to create blog post content property');
94
119
  }
95
120
  } else {
96
- var _contentProperty$data6;
121
+ var _contentProperty$data8;
97
122
  const contentProperty = await createContentProperty(options);
98
- if (((_contentProperty$data6 = contentProperty.data.confluence.createPageProperty.pageProperty) === null || _contentProperty$data6 === void 0 ? void 0 : _contentProperty$data6.key) === key) {
123
+ if (((_contentProperty$data8 = contentProperty.data.confluence.createPageProperty.pageProperty) === null || _contentProperty$data8 === void 0 ? void 0 : _contentProperty$data8.key) === key) {
99
124
  return key;
100
125
  } else {
101
126
  throw new Error('Failed to create page content property');
@@ -121,9 +146,9 @@ class ConfluenceADFWriteProvider {
121
146
  pageType
122
147
  };
123
148
  if (isBlogPageType(pageType)) {
124
- var _contentProperty$data7;
149
+ var _contentProperty$data9;
125
150
  const contentProperty = await updateContentProperty(options);
126
- if (((_contentProperty$data7 = contentProperty.data.confluence.updateValueBlogPostProperty.blogPostProperty) === null || _contentProperty$data7 === void 0 ? void 0 : _contentProperty$data7.key) === key) {
151
+ if (((_contentProperty$data9 = contentProperty.data.confluence.updateValueBlogPostProperty.blogPostProperty) === null || _contentProperty$data9 === void 0 ? void 0 : _contentProperty$data9.key) === key) {
127
152
  return key;
128
153
  } else if (contentProperty.data.confluence.updateValueBlogPostProperty.blogPostProperty === null) {
129
154
  return this.createNewContentProperty(pageId, key, data, pageType);
@@ -131,9 +156,9 @@ class ConfluenceADFWriteProvider {
131
156
  throw new Error('Failed to update blog post content property');
132
157
  }
133
158
  } else {
134
- var _contentProperty$data8;
159
+ var _contentProperty$data0;
135
160
  const contentProperty = await updateContentProperty(options);
136
- if (((_contentProperty$data8 = contentProperty.data.confluence.updateValuePageProperty.pageProperty) === null || _contentProperty$data8 === void 0 ? void 0 : _contentProperty$data8.key) === key) {
161
+ if (((_contentProperty$data0 = contentProperty.data.confluence.updateValuePageProperty.pageProperty) === null || _contentProperty$data0 === void 0 ? void 0 : _contentProperty$data0.key) === key) {
137
162
  return key;
138
163
  } else if (contentProperty.data.confluence.updateValuePageProperty.pageProperty === null) {
139
164
  return this.createNewContentProperty(pageId, key, data, pageType);
@@ -11,6 +11,7 @@ import uuid from 'uuid';
11
11
  import { resourceIdFromSourceAndLocalId } from '../utils/ari';
12
12
  import { convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockPMNodeToSyncBlockNode } from '../utils/utils';
13
13
  import { rebaseTransaction as _rebaseTransaction } from './rebase-transaction';
14
+ import { SyncBlockStatus } from './types';
14
15
 
15
16
  // Do this typedef to make it clear that
16
17
  // this is a local identifier for a resource for local use
@@ -75,7 +76,7 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
75
76
  key: "fetchSyncBlockData",
76
77
  value: function () {
77
78
  var _fetchSyncBlockData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(syncBlockNode) {
78
- var syncNode, data, sourceURL;
79
+ var syncNode, data, sourceURL, fetchSyncBlockDataResult;
79
80
  return _regeneratorRuntime.wrap(function _callee$(_context) {
80
81
  while (1) switch (_context.prev = _context.next) {
81
82
  case 0:
@@ -103,13 +104,17 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
103
104
  throw new Error('Failed to fetch sync block node data');
104
105
  case 10:
105
106
  sourceURL = this.getSyncBlockSourceURL(syncBlockNode);
106
- this.syncBlocks.set(syncBlockNode.attrs.localId, {
107
- syncNode: syncNode,
108
- sourceURL: sourceURL,
109
- syncBlockData: data[0]
110
- });
111
- return _context.abrupt("return", data[0]);
112
- case 13:
107
+ fetchSyncBlockDataResult = data[0];
108
+ if (!('status' in fetchSyncBlockDataResult)) {
109
+ // only adds it to the map if it did not error out
110
+ this.syncBlocks.set(syncBlockNode.attrs.localId, {
111
+ syncNode: syncNode,
112
+ sourceURL: sourceURL,
113
+ syncBlockData: fetchSyncBlockDataResult
114
+ });
115
+ }
116
+ return _context.abrupt("return", fetchSyncBlockDataResult);
117
+ case 14:
113
118
  case "end":
114
119
  return _context.stop();
115
120
  }
@@ -277,22 +282,30 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
277
282
  }
278
283
  }]);
279
284
  }();
280
- export function useFetchDocNode(manager, syncBlockNode, defaultDocNode) {
281
- var _useState = useState(defaultDocNode),
285
+ export function useFetchSyncBlockData(manager, syncBlockNode) {
286
+ var _useState = useState(null),
282
287
  _useState2 = _slicedToArray(_useState, 2),
283
- docNode = _useState2[0],
284
- setDocNode = _useState2[1];
288
+ fetchSyncBlockDataResult = _useState2[0],
289
+ setFetchSyncBlockDataResult = _useState2[1];
285
290
  var fetchSyncBlockNode = useCallback(function () {
286
291
  manager.fetchSyncBlockData(syncBlockNode).then(function (data) {
287
- return setDocNode({
288
- content: data.content || [],
289
- version: 1,
290
- type: 'doc'
291
- });
292
+ if ('status' in data) {
293
+ // if there is an error, we don't want to replace real existing data with the error data
294
+ if (!fetchSyncBlockDataResult || 'status' in fetchSyncBlockDataResult) {
295
+ setFetchSyncBlockDataResult(data);
296
+ }
297
+ } else {
298
+ setFetchSyncBlockDataResult(data);
299
+ }
292
300
  }).catch(function () {
293
301
  //TODO: EDITOR-1921 - add error analytics
302
+ if (!fetchSyncBlockDataResult || 'status' in fetchSyncBlockDataResult) {
303
+ setFetchSyncBlockDataResult({
304
+ status: SyncBlockStatus.Errored
305
+ });
306
+ }
294
307
  });
295
- }, [manager, syncBlockNode, setDocNode]);
308
+ }, [manager, syncBlockNode, fetchSyncBlockDataResult]);
296
309
  useEffect(function () {
297
310
  fetchSyncBlockNode();
298
311
  var interval = window.setInterval(fetchSyncBlockNode, 3000);
@@ -300,7 +313,7 @@ export function useFetchDocNode(manager, syncBlockNode, defaultDocNode) {
300
313
  window.clearInterval(interval);
301
314
  };
302
315
  }, [fetchSyncBlockNode]);
303
- return docNode;
316
+ return fetchSyncBlockDataResult;
304
317
  }
305
318
  export function useHandleContentChanges(manager, syncBlockNode) {
306
319
  useEffect(function () {
@@ -6,6 +6,12 @@ import _inherits from "@babel/runtime/helpers/inherits";
6
6
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
7
7
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
8
  import { NodeDataProvider } from '@atlaskit/node-data-provider';
9
+ export var SyncBlockStatus = /*#__PURE__*/function (SyncBlockStatus) {
10
+ SyncBlockStatus["Errored"] = "errored";
11
+ SyncBlockStatus["NotFound"] = "not_found";
12
+ SyncBlockStatus["Unauthorized"] = "unauthorized";
13
+ return SyncBlockStatus;
14
+ }({});
9
15
  export var SyncBlockDataProvider = /*#__PURE__*/function (_NodeDataProvider) {
10
16
  function SyncBlockDataProvider() {
11
17
  _classCallCheck(this, SyncBlockDataProvider);
package/dist/esm/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  /* eslint-disable @atlaskit/editor/no-re-export */
2
2
 
3
3
  export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './common/syncBlockProvider';
4
- export { SyncBlockStoreManager, useFetchDocNode, useHandleContentChanges } from './common/syncBlockStoreManager';
4
+ export { SyncBlockStoreManager, useFetchSyncBlockData, useHandleContentChanges } from './common/syncBlockStoreManager';
5
+ export { SyncBlockStatus } from './common/types';
5
6
  export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemory';
6
7
  export { getDefaultSyncBlockSchema } from './common/schema';
7
8
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluenceContentAPI';
@@ -5,6 +5,7 @@ import _createClass from "@babel/runtime/helpers/createClass";
5
5
  import _typeof from "@babel/runtime/helpers/typeof";
6
6
  import _regeneratorRuntime from "@babel/runtime/regenerator";
7
7
  import { useMemo } from 'react';
8
+ import { SyncBlockStatus } from '../common/types';
8
9
  import { getLocalIdFromAri, getPageIdAndTypeFromAri } from '../utils/ari';
9
10
  import { getContentProperty, createContentProperty, updateContentProperty } from '../utils/contentProperty';
10
11
  import { isBlogPageType } from '../utils/utils';
@@ -31,6 +32,17 @@ var parseSyncedBlockContentPropertyValue = function parseSyncedBlockContentPrope
31
32
  throw new Error("Failed to parse synced block data: ".concat(error));
32
33
  }
33
34
  };
35
+ var getResponseStatus = function getResponseStatus(contentProperty) {
36
+ var _content$properties;
37
+ var content = 'blogPost' in contentProperty.data.confluence ? contentProperty.data.confluence.blogPost : contentProperty.data.confluence.page;
38
+ if (!content) {
39
+ return SyncBlockStatus.Unauthorized;
40
+ }
41
+ if (!((_content$properties = content.properties) !== null && _content$properties !== void 0 && _content$properties[0])) {
42
+ return SyncBlockStatus.NotFound;
43
+ }
44
+ return SyncBlockStatus.Errored;
45
+ };
34
46
 
35
47
  /**
36
48
  * ADFFetchProvider implementation that fetches synced block data from Confluence Content API
@@ -44,12 +56,13 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
44
56
  key: "fetchData",
45
57
  value: function () {
46
58
  var _fetchData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resourceId) {
47
- var _getPageIdAndTypeFrom, pageId, pageType, localId, key, options, value, _contentProperty$data, contentProperty, _contentProperty$data2, _contentProperty, syncedBlockData;
59
+ var _getPageIdAndTypeFrom, pageId, pageType, localId, key, options, status, value, _contentProperty$data, contentProperty, _contentProperty$data2, _contentProperty, syncedBlockData;
48
60
  return _regeneratorRuntime.wrap(function _callee$(_context) {
49
61
  while (1) switch (_context.prev = _context.next) {
50
62
  case 0:
51
63
  _getPageIdAndTypeFrom = getPageIdAndTypeFromAri(resourceId), pageId = _getPageIdAndTypeFrom.id, pageType = _getPageIdAndTypeFrom.type;
52
64
  localId = getLocalIdFromAri(resourceId);
65
+ _context.prev = 2;
53
66
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
54
67
  options = {
55
68
  pageId: pageId,
@@ -58,29 +71,34 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
58
71
  pageType: pageType
59
72
  };
60
73
  if (!isBlogPageType(pageType)) {
61
- _context.next = 11;
74
+ _context.next = 13;
62
75
  break;
63
76
  }
64
- _context.next = 7;
77
+ _context.next = 8;
65
78
  return getContentProperty(options);
66
- case 7:
79
+ case 8:
67
80
  contentProperty = _context.sent;
68
- value = (_contentProperty$data = contentProperty.data.confluence.blogPost.properties) === null || _contentProperty$data === void 0 || (_contentProperty$data = _contentProperty$data[0]) === null || _contentProperty$data === void 0 ? void 0 : _contentProperty$data.value;
69
- _context.next = 15;
81
+ value = (_contentProperty$data = contentProperty.data.confluence.blogPost) === null || _contentProperty$data === void 0 || (_contentProperty$data = _contentProperty$data.properties) === null || _contentProperty$data === void 0 || (_contentProperty$data = _contentProperty$data[0]) === null || _contentProperty$data === void 0 ? void 0 : _contentProperty$data.value;
82
+ status = getResponseStatus(contentProperty);
83
+ _context.next = 18;
70
84
  break;
71
- case 11:
72
- _context.next = 13;
73
- return getContentProperty(options);
74
85
  case 13:
75
- _contentProperty = _context.sent;
76
- value = (_contentProperty$data2 = _contentProperty.data.confluence.page.properties) === null || _contentProperty$data2 === void 0 || (_contentProperty$data2 = _contentProperty$data2[0]) === null || _contentProperty$data2 === void 0 ? void 0 : _contentProperty$data2.value;
86
+ _context.next = 15;
87
+ return getContentProperty(options);
77
88
  case 15:
89
+ _contentProperty = _context.sent;
90
+ value = (_contentProperty$data2 = _contentProperty.data.confluence.page) === null || _contentProperty$data2 === void 0 || (_contentProperty$data2 = _contentProperty$data2.properties) === null || _contentProperty$data2 === void 0 || (_contentProperty$data2 = _contentProperty$data2[0]) === null || _contentProperty$data2 === void 0 ? void 0 : _contentProperty$data2.value;
91
+ status = getResponseStatus(_contentProperty);
92
+ case 18:
78
93
  if (value) {
79
- _context.next = 17;
94
+ _context.next = 20;
80
95
  break;
81
96
  }
82
- throw new Error('Content property value does not exist');
83
- case 17:
97
+ return _context.abrupt("return", {
98
+ status: status,
99
+ resourceId: resourceId
100
+ });
101
+ case 20:
84
102
  // Parse the synced block content from the property value
85
103
  syncedBlockData = parseSyncedBlockContentPropertyValue(value);
86
104
  return _context.abrupt("return", {
@@ -88,11 +106,18 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
88
106
  resourceId: resourceId,
89
107
  blockInstanceId: localId
90
108
  });
91
- case 19:
109
+ case 24:
110
+ _context.prev = 24;
111
+ _context.t0 = _context["catch"](2);
112
+ return _context.abrupt("return", {
113
+ status: SyncBlockStatus.Errored,
114
+ resourceId: resourceId
115
+ });
116
+ case 27:
92
117
  case "end":
93
118
  return _context.stop();
94
119
  }
95
- }, _callee, this);
120
+ }, _callee, this, [[2, 24]]);
96
121
  }));
97
122
  function fetchData(_x) {
98
123
  return _fetchData.apply(this, arguments);
@@ -3,4 +3,4 @@
3
3
  * Otherwise we could import defaultSchemaConfig from '@atlaskit/adf-schema/schema-default';
4
4
  * @returns
5
5
  */
6
- export declare const getDefaultSyncBlockSchema: () => import("prosemirror-model").Schema<"doc" | "layoutSection" | "paragraph" | "panel" | "text" | "bulletList" | "orderedList" | "listItem" | "heading" | "blockquote" | "codeBlock" | "rule" | "expand" | "nestedExpand" | "table" | "tableCell" | "tableHeader" | "tableRow" | "date" | "status" | "layoutColumn" | "unsupportedBlock" | "unsupportedInline", "link" | "em" | "strong" | "strike" | "subsup" | "underline" | "code" | "textColor" | "backgroundColor" | "alignment" | "indentation" | "border" | "unsupportedMark" | "unsupportedNodeAttribute" | "typeAheadQuery">;
6
+ export declare const getDefaultSyncBlockSchema: () => import("prosemirror-model").Schema<"status" | "doc" | "paragraph" | "text" | "bulletList" | "orderedList" | "listItem" | "heading" | "blockquote" | "codeBlock" | "panel" | "rule" | "expand" | "nestedExpand" | "table" | "tableCell" | "tableHeader" | "tableRow" | "date" | "layoutSection" | "layoutColumn" | "unsupportedBlock" | "unsupportedInline", "link" | "em" | "strong" | "strike" | "subsup" | "underline" | "code" | "textColor" | "backgroundColor" | "alignment" | "indentation" | "border" | "unsupportedMark" | "unsupportedNodeAttribute" | "typeAheadQuery">;
@@ -1,5 +1,5 @@
1
1
  import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
2
- import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type SyncBlockData, type SyncBlockNode } from './types';
2
+ import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type FetchSyncBlockDataResult, type SyncBlockData, type SyncBlockNode } from './types';
3
3
  export declare class SyncBlockProvider extends SyncBlockDataProvider {
4
4
  name: string;
5
5
  private fetchProvider;
@@ -8,7 +8,7 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
8
8
  constructor(fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string);
9
9
  isNodeSupported(node: JSONNode): node is SyncBlockNode;
10
10
  nodeDataKey(node: SyncBlockNode): string;
11
- fetchNodesData(nodes: SyncBlockNode[]): Promise<SyncBlockData[]>;
11
+ fetchNodesData(nodes: SyncBlockNode[]): Promise<FetchSyncBlockDataResult[]>;
12
12
  /**
13
13
  *
14
14
  * @param nodes
@@ -1,8 +1,7 @@
1
- import type { DocNode } from '@atlaskit/adf-schema';
2
1
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
2
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
- import type { SyncBlockAttrs, SyncBlockData, SyncBlockDataProvider, SyncBlockNode } from './types';
4
+ import type { FetchSyncBlockDataResult, SyncBlockAttrs, SyncBlockData, SyncBlockDataProvider, SyncBlockNode } from './types';
6
5
  type BlockInstanceId = string;
7
6
  export interface SyncBlock {
8
7
  sourceURL?: string;
@@ -24,7 +23,7 @@ export declare class SyncBlockStoreManager {
24
23
  * @returns The source URL for the sync block node if it exists. Otherwise trigger fetch and return undefined, syncBlock will update with URL asynchronously.
25
24
  */
26
25
  private getSyncBlockSourceURL;
27
- fetchSyncBlockData(syncBlockNode: PMNode): Promise<SyncBlockData>;
26
+ fetchSyncBlockData(syncBlockNode: PMNode): Promise<FetchSyncBlockDataResult>;
28
27
  /**
29
28
  * Add/update a sync block node to/from the store.
30
29
  * @param syncBlockNode - The sync block node to update
@@ -46,6 +45,6 @@ export declare class SyncBlockStoreManager {
46
45
  deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
47
46
  rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
48
47
  }
49
- export declare function useFetchDocNode(manager: SyncBlockStoreManager, syncBlockNode: PMNode, defaultDocNode: DocNode): DocNode;
48
+ export declare function useFetchSyncBlockData(manager: SyncBlockStoreManager, syncBlockNode: PMNode): FetchSyncBlockDataResult | null;
50
49
  export declare function useHandleContentChanges(manager: SyncBlockStoreManager, syncBlockNode: PMNode): void;
51
50
  export {};
@@ -10,6 +10,11 @@ export type SyncBlockNode = {
10
10
  content?: Array<JSONNode>;
11
11
  type: 'syncBlock';
12
12
  };
13
+ export declare enum SyncBlockStatus {
14
+ Errored = "errored",
15
+ NotFound = "not_found",
16
+ Unauthorized = "unauthorized"
17
+ }
13
18
  export type SyncBlockData = {
14
19
  blockInstanceId: string;
15
20
  content: Array<ADFEntity>;
@@ -18,16 +23,19 @@ export type SyncBlockData = {
18
23
  isSynced?: boolean;
19
24
  resourceId: string;
20
25
  sourceDocumentAri?: string;
21
- status?: 'deleted' | 'active';
22
26
  updatedAt?: string;
23
27
  };
28
+ export type FetchSyncBlockDataResult = SyncBlockData | {
29
+ resourceId?: string;
30
+ status: SyncBlockStatus;
31
+ };
24
32
  export interface ADFFetchProvider {
25
- fetchData: (resourceId: string) => Promise<SyncBlockData>;
33
+ fetchData: (resourceId: string) => Promise<FetchSyncBlockDataResult>;
26
34
  }
27
35
  export interface ADFWriteProvider {
28
36
  writeData: (data: SyncBlockData) => Promise<string>;
29
37
  }
30
- export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, SyncBlockData> {
38
+ export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, FetchSyncBlockDataResult> {
31
39
  abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<string | undefined>>;
32
40
  abstract getSourceId(): string;
33
41
  abstract retrieveSyncBlockSourceUrl(node: SyncBlockNode): Promise<string | undefined>;
@@ -1,6 +1,7 @@
1
1
  export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './common/syncBlockProvider';
2
- export { SyncBlockStoreManager, useFetchDocNode, useHandleContentChanges, } from './common/syncBlockStoreManager';
3
- export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, SyncBlockData, SyncBlockNode, } from './common/types';
2
+ export { SyncBlockStoreManager, useFetchSyncBlockData, useHandleContentChanges, } from './common/syncBlockStoreManager';
3
+ export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, SyncBlockData, SyncBlockNode, FetchSyncBlockDataResult, } from './common/types';
4
+ export { SyncBlockStatus } from './common/types';
4
5
  export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemory';
5
6
  export { getDefaultSyncBlockSchema } from './common/schema';
6
7
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluenceContentAPI';
@@ -1,4 +1,4 @@
1
- import type { ADFFetchProvider, ADFWriteProvider, SyncBlockData } from '../common/types';
1
+ import type { ADFFetchProvider, ADFWriteProvider, FetchSyncBlockDataResult, SyncBlockData } from '../common/types';
2
2
  /**
3
3
  * Configuration for Content API providers
4
4
  */
@@ -12,7 +12,7 @@ interface ContentAPIConfig {
12
12
  declare class ConfluenceADFFetchProvider implements ADFFetchProvider {
13
13
  private config;
14
14
  constructor(config: ContentAPIConfig);
15
- fetchData(resourceId: string): Promise<SyncBlockData>;
15
+ fetchData(resourceId: string): Promise<FetchSyncBlockDataResult>;
16
16
  }
17
17
  /**
18
18
  * ADFWriteProvider implementation that writes synced block data to Confluence Content API
@@ -3,4 +3,4 @@
3
3
  * Otherwise we could import defaultSchemaConfig from '@atlaskit/adf-schema/schema-default';
4
4
  * @returns
5
5
  */
6
- export declare const getDefaultSyncBlockSchema: () => import("prosemirror-model").Schema<"doc" | "layoutSection" | "paragraph" | "panel" | "text" | "bulletList" | "orderedList" | "listItem" | "heading" | "blockquote" | "codeBlock" | "rule" | "expand" | "nestedExpand" | "table" | "tableCell" | "tableHeader" | "tableRow" | "date" | "status" | "layoutColumn" | "unsupportedBlock" | "unsupportedInline", "link" | "em" | "strong" | "strike" | "subsup" | "underline" | "code" | "textColor" | "backgroundColor" | "alignment" | "indentation" | "border" | "unsupportedMark" | "unsupportedNodeAttribute" | "typeAheadQuery">;
6
+ export declare const getDefaultSyncBlockSchema: () => import("prosemirror-model").Schema<"status" | "doc" | "paragraph" | "text" | "bulletList" | "orderedList" | "listItem" | "heading" | "blockquote" | "codeBlock" | "panel" | "rule" | "expand" | "nestedExpand" | "table" | "tableCell" | "tableHeader" | "tableRow" | "date" | "layoutSection" | "layoutColumn" | "unsupportedBlock" | "unsupportedInline", "link" | "em" | "strong" | "strike" | "subsup" | "underline" | "code" | "textColor" | "backgroundColor" | "alignment" | "indentation" | "border" | "unsupportedMark" | "unsupportedNodeAttribute" | "typeAheadQuery">;
@@ -1,5 +1,5 @@
1
1
  import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
2
- import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type SyncBlockData, type SyncBlockNode } from './types';
2
+ import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type FetchSyncBlockDataResult, type SyncBlockData, type SyncBlockNode } from './types';
3
3
  export declare class SyncBlockProvider extends SyncBlockDataProvider {
4
4
  name: string;
5
5
  private fetchProvider;
@@ -8,7 +8,7 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
8
8
  constructor(fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string);
9
9
  isNodeSupported(node: JSONNode): node is SyncBlockNode;
10
10
  nodeDataKey(node: SyncBlockNode): string;
11
- fetchNodesData(nodes: SyncBlockNode[]): Promise<SyncBlockData[]>;
11
+ fetchNodesData(nodes: SyncBlockNode[]): Promise<FetchSyncBlockDataResult[]>;
12
12
  /**
13
13
  *
14
14
  * @param nodes
@@ -1,8 +1,7 @@
1
- import type { DocNode } from '@atlaskit/adf-schema';
2
1
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
2
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
- import type { SyncBlockAttrs, SyncBlockData, SyncBlockDataProvider, SyncBlockNode } from './types';
4
+ import type { FetchSyncBlockDataResult, SyncBlockAttrs, SyncBlockData, SyncBlockDataProvider, SyncBlockNode } from './types';
6
5
  type BlockInstanceId = string;
7
6
  export interface SyncBlock {
8
7
  sourceURL?: string;
@@ -24,7 +23,7 @@ export declare class SyncBlockStoreManager {
24
23
  * @returns The source URL for the sync block node if it exists. Otherwise trigger fetch and return undefined, syncBlock will update with URL asynchronously.
25
24
  */
26
25
  private getSyncBlockSourceURL;
27
- fetchSyncBlockData(syncBlockNode: PMNode): Promise<SyncBlockData>;
26
+ fetchSyncBlockData(syncBlockNode: PMNode): Promise<FetchSyncBlockDataResult>;
28
27
  /**
29
28
  * Add/update a sync block node to/from the store.
30
29
  * @param syncBlockNode - The sync block node to update
@@ -46,6 +45,6 @@ export declare class SyncBlockStoreManager {
46
45
  deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
47
46
  rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
48
47
  }
49
- export declare function useFetchDocNode(manager: SyncBlockStoreManager, syncBlockNode: PMNode, defaultDocNode: DocNode): DocNode;
48
+ export declare function useFetchSyncBlockData(manager: SyncBlockStoreManager, syncBlockNode: PMNode): FetchSyncBlockDataResult | null;
50
49
  export declare function useHandleContentChanges(manager: SyncBlockStoreManager, syncBlockNode: PMNode): void;
51
50
  export {};
@@ -10,6 +10,11 @@ export type SyncBlockNode = {
10
10
  content?: Array<JSONNode>;
11
11
  type: 'syncBlock';
12
12
  };
13
+ export declare enum SyncBlockStatus {
14
+ Errored = "errored",
15
+ NotFound = "not_found",
16
+ Unauthorized = "unauthorized"
17
+ }
13
18
  export type SyncBlockData = {
14
19
  blockInstanceId: string;
15
20
  content: Array<ADFEntity>;
@@ -18,16 +23,19 @@ export type SyncBlockData = {
18
23
  isSynced?: boolean;
19
24
  resourceId: string;
20
25
  sourceDocumentAri?: string;
21
- status?: 'deleted' | 'active';
22
26
  updatedAt?: string;
23
27
  };
28
+ export type FetchSyncBlockDataResult = SyncBlockData | {
29
+ resourceId?: string;
30
+ status: SyncBlockStatus;
31
+ };
24
32
  export interface ADFFetchProvider {
25
- fetchData: (resourceId: string) => Promise<SyncBlockData>;
33
+ fetchData: (resourceId: string) => Promise<FetchSyncBlockDataResult>;
26
34
  }
27
35
  export interface ADFWriteProvider {
28
36
  writeData: (data: SyncBlockData) => Promise<string>;
29
37
  }
30
- export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, SyncBlockData> {
38
+ export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, FetchSyncBlockDataResult> {
31
39
  abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<string | undefined>>;
32
40
  abstract getSourceId(): string;
33
41
  abstract retrieveSyncBlockSourceUrl(node: SyncBlockNode): Promise<string | undefined>;
@@ -1,6 +1,7 @@
1
1
  export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './common/syncBlockProvider';
2
- export { SyncBlockStoreManager, useFetchDocNode, useHandleContentChanges, } from './common/syncBlockStoreManager';
3
- export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, SyncBlockData, SyncBlockNode, } from './common/types';
2
+ export { SyncBlockStoreManager, useFetchSyncBlockData, useHandleContentChanges, } from './common/syncBlockStoreManager';
3
+ export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, SyncBlockData, SyncBlockNode, FetchSyncBlockDataResult, } from './common/types';
4
+ export { SyncBlockStatus } from './common/types';
4
5
  export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemory';
5
6
  export { getDefaultSyncBlockSchema } from './common/schema';
6
7
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluenceContentAPI';
@@ -1,4 +1,4 @@
1
- import type { ADFFetchProvider, ADFWriteProvider, SyncBlockData } from '../common/types';
1
+ import type { ADFFetchProvider, ADFWriteProvider, FetchSyncBlockDataResult, SyncBlockData } from '../common/types';
2
2
  /**
3
3
  * Configuration for Content API providers
4
4
  */
@@ -12,7 +12,7 @@ interface ContentAPIConfig {
12
12
  declare class ConfluenceADFFetchProvider implements ADFFetchProvider {
13
13
  private config;
14
14
  constructor(config: ContentAPIConfig);
15
- fetchData(resourceId: string): Promise<SyncBlockData>;
15
+ fetchData(resourceId: string): Promise<FetchSyncBlockDataResult>;
16
16
  }
17
17
  /**
18
18
  * ADFWriteProvider implementation that writes synced block data to Confluence Content API
package/package.json CHANGED
@@ -82,7 +82,7 @@
82
82
  }
83
83
  },
84
84
  "name": "@atlaskit/editor-synced-block-provider",
85
- "version": "2.1.1",
85
+ "version": "2.1.2",
86
86
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
87
87
  "author": "Atlassian Pty Ltd",
88
88
  "license": "Apache-2.0",