@atlaskit/editor-synced-block-provider 3.14.1 → 3.14.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cjs/clients/block-service/blockService.js +9 -7
  3. package/dist/cjs/hooks/useFetchSyncBlockData.js +3 -1
  4. package/dist/cjs/providers/block-service/blockServiceAPI.js +47 -18
  5. package/dist/cjs/providers/syncBlockProvider.js +10 -6
  6. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +6 -5
  7. package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +41 -23
  8. package/dist/cjs/store-manager/syncBlockStoreManager.js +1 -1
  9. package/dist/cjs/utils/resolveSyncBlockInstance.js +2 -1
  10. package/dist/es2019/clients/block-service/blockService.js +5 -2
  11. package/dist/es2019/hooks/useFetchSyncBlockData.js +3 -1
  12. package/dist/es2019/providers/block-service/blockServiceAPI.js +45 -16
  13. package/dist/es2019/providers/syncBlockProvider.js +8 -4
  14. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +6 -5
  15. package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +28 -11
  16. package/dist/es2019/store-manager/syncBlockStoreManager.js +1 -1
  17. package/dist/es2019/utils/resolveSyncBlockInstance.js +2 -1
  18. package/dist/esm/clients/block-service/blockService.js +9 -7
  19. package/dist/esm/hooks/useFetchSyncBlockData.js +3 -1
  20. package/dist/esm/providers/block-service/blockServiceAPI.js +47 -18
  21. package/dist/esm/providers/syncBlockProvider.js +10 -6
  22. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +6 -5
  23. package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +42 -24
  24. package/dist/esm/store-manager/syncBlockStoreManager.js +1 -1
  25. package/dist/esm/utils/resolveSyncBlockInstance.js +2 -1
  26. package/dist/types/clients/block-service/blockService.d.ts +4 -2
  27. package/dist/types/common/types.d.ts +4 -0
  28. package/dist/types/index.d.ts +1 -1
  29. package/dist/types/providers/block-service/blockServiceAPI.d.ts +1 -1
  30. package/dist/types/providers/syncBlockProvider.d.ts +2 -2
  31. package/dist/types/providers/types.d.ts +8 -4
  32. package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +4 -3
  33. package/dist/types-ts4.5/clients/block-service/blockService.d.ts +4 -2
  34. package/dist/types-ts4.5/common/types.d.ts +4 -0
  35. package/dist/types-ts4.5/index.d.ts +1 -1
  36. package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +1 -1
  37. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +2 -2
  38. package/dist/types-ts4.5/providers/types.d.ts +8 -4
  39. package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +4 -3
  40. package/package.json +1 -1
@@ -506,11 +506,12 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
506
506
  // Don't fetch for not_found error since the source is already deleted
507
507
  nodesToFetch = [];
508
508
  syncBlockNodes.forEach(function (node) {
509
+ var _existingSyncBlock$er;
509
510
  if (_this5.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
510
511
  return;
511
512
  }
512
513
  var existingSyncBlock = _this5.getFromCache(node.attrs.resourceId);
513
- if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : existingSyncBlock.error) === SyncBlockError.NotFound) {
514
+ if ((existingSyncBlock === null || existingSyncBlock === void 0 || (_existingSyncBlock$er = existingSyncBlock.error) === null || _existingSyncBlock$er === void 0 ? void 0 : _existingSyncBlock$er.type) === SyncBlockError.NotFound) {
514
515
  return;
515
516
  }
516
517
  nodesToFetch.push(node);
@@ -545,8 +546,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
545
546
  hasExpectedError = false;
546
547
  data.forEach(function (syncBlockInstance) {
547
548
  if (!syncBlockInstance.resourceId) {
548
- var _this5$fireAnalyticsE;
549
- (_this5$fireAnalyticsE = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE === void 0 || _this5$fireAnalyticsE.call(_this5, fetchErrorPayload(syncBlockInstance.error || 'Returned sync block instance does not have resource id'));
549
+ var _this5$fireAnalyticsE, _syncBlockInstance$er;
550
+ (_this5$fireAnalyticsE = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE === void 0 || _this5$fireAnalyticsE.call(_this5, fetchErrorPayload(((_syncBlockInstance$er = syncBlockInstance.error) === null || _syncBlockInstance$er === void 0 ? void 0 : _syncBlockInstance$er.type) || 'Returned sync block instance does not have resource id'));
550
551
  return;
551
552
  }
552
553
  var existingSyncBlock = _this5.getFromCache(syncBlockInstance.resourceId);
@@ -554,8 +555,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
554
555
  _this5.updateCache(resolvedSyncBlockInstance);
555
556
  if (syncBlockInstance.error) {
556
557
  var _this5$fireAnalyticsE2;
557
- (_this5$fireAnalyticsE2 = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE2 === void 0 || _this5$fireAnalyticsE2.call(_this5, fetchErrorPayload(syncBlockInstance.error, syncBlockInstance.resourceId));
558
- if (syncBlockInstance.error === SyncBlockError.NotFound || syncBlockInstance.error === SyncBlockError.Forbidden) {
558
+ (_this5$fireAnalyticsE2 = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE2 === void 0 || _this5$fireAnalyticsE2.call(_this5, fetchErrorPayload(syncBlockInstance.error.type, syncBlockInstance.resourceId));
559
+ if (syncBlockInstance.error.type === SyncBlockError.NotFound || syncBlockInstance.error.type === SyncBlockError.Forbidden) {
559
560
  hasExpectedError = true;
560
561
  } else if (syncBlockInstance.error) {
561
562
  hasUnexpectedError = true;
@@ -8,7 +8,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
8
8
  import { logException } from '@atlaskit/editor-common/monitoring';
9
9
  import { fg } from '@atlaskit/platform-feature-flags';
10
10
  import { SyncBlockError } from '../common/types';
11
- import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload, getSourceInfoErrorPayload, updateSuccessPayload, createSuccessPayload, deleteSuccessPayload } from '../utils/errorHandling';
11
+ import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload, getSourceInfoErrorPayload, updateSuccessPayload, createSuccessPayload, deleteSuccessPayload, fetchReferencesErrorPayload } from '../utils/errorHandling';
12
12
  import { getCreateSourceExperience, getDeleteSourceExperience, getSaveSourceExperience } from '../utils/experienceTracking';
13
13
  import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
14
14
  // A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
@@ -128,10 +128,9 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
128
128
  if (fg('platform_synced_block_dogfooding')) {
129
129
  (_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 || _this$saveExperience.start({});
130
130
  }
131
- ;
132
- _context.next = 12;
131
+ _context.next = 11;
133
132
  return this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
134
- case 12:
133
+ case 11:
135
134
  writeResults = _context.sent;
136
135
  writeResults.forEach(function (result) {
137
136
  // set isDirty to true for cases where it failed to save the sync block to the BE
@@ -145,7 +144,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
145
144
  if (!writeResults.every(function (result) {
146
145
  return result.resourceId && !result.error;
147
146
  })) {
148
- _context.next = 20;
147
+ _context.next = 18;
149
148
  break;
150
149
  }
151
150
  if (fg('platform_synced_block_dogfooding')) {
@@ -157,9 +156,8 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
157
156
  }
158
157
  });
159
158
  }
160
- ;
161
159
  return _context.abrupt("return", true);
162
- case 20:
160
+ case 18:
163
161
  if (fg('platform_synced_block_dogfooding')) {
164
162
  (_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 || _this$saveExperience3.failure();
165
163
  }
@@ -170,22 +168,22 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
170
168
  (_this2$fireAnalyticsE2 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE2 === void 0 || _this2$fireAnalyticsE2.call(_this2, updateErrorPayload(result.error || 'Failed to write data', result.resourceId));
171
169
  });
172
170
  return _context.abrupt("return", false);
173
- case 23:
174
- _context.next = 30;
171
+ case 21:
172
+ _context.next = 28;
175
173
  break;
176
- case 25:
177
- _context.prev = 25;
174
+ case 23:
175
+ _context.prev = 23;
178
176
  _context.t0 = _context["catch"](0);
179
177
  logException(_context.t0, {
180
178
  location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
181
179
  });
182
180
  (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, updateErrorPayload(_context.t0.message));
183
181
  return _context.abrupt("return", false);
184
- case 30:
182
+ case 28:
185
183
  case "end":
186
184
  return _context.stop();
187
185
  }
188
- }, _callee, this, [[0, 25]]);
186
+ }, _callee, this, [[0, 23]]);
189
187
  }));
190
188
  function flush() {
191
189
  return _flush.apply(this, arguments);
@@ -338,7 +336,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
338
336
  }, {
339
337
  key: "delete",
340
338
  value: function () {
341
- var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockIds, onDelete, onDeleteCompleted) {
339
+ var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockIds, onDelete, onDeleteCompleted, reason) {
342
340
  var _this5 = this;
343
341
  var _this$deleteExperienc, results, callback, isDeleteSuccessful, _this$deleteExperienc2, _this$deleteExperienc3;
344
342
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
@@ -360,7 +358,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
360
358
  _context2.next = 7;
361
359
  return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
362
360
  return attrs.resourceId;
363
- }));
361
+ }), reason);
364
362
  case 7:
365
363
  results = _context2.sent;
366
364
  isDeleteSuccessful = results.every(function (result) {
@@ -425,7 +423,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
425
423
  }
426
424
  }, _callee2, this, [[0, 15]]);
427
425
  }));
428
- function _delete(_x, _x2, _x3) {
426
+ function _delete(_x, _x2, _x3, _x4) {
429
427
  return _delete2.apply(this, arguments);
430
428
  }
431
429
  return _delete;
@@ -439,7 +437,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
439
437
  key: "retryDeletion",
440
438
  value: function () {
441
439
  var _retryDeletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
442
- var _this$deletionRetryIn, syncBlockIds, onDelete, onDeleteCompleted;
440
+ var _this$deletionRetryIn, syncBlockIds, onDelete, onDeleteCompleted, deletionReason;
443
441
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
444
442
  while (1) switch (_context3.prev = _context3.next) {
445
443
  case 0:
@@ -449,13 +447,13 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
449
447
  }
450
448
  return _context3.abrupt("return", Promise.resolve());
451
449
  case 2:
452
- _this$deletionRetryIn = this.deletionRetryInfo, syncBlockIds = _this$deletionRetryIn.syncBlockIds, onDelete = _this$deletionRetryIn.onDelete, onDeleteCompleted = _this$deletionRetryIn.onDeleteCompleted;
450
+ _this$deletionRetryIn = this.deletionRetryInfo, syncBlockIds = _this$deletionRetryIn.syncBlockIds, onDelete = _this$deletionRetryIn.onDelete, onDeleteCompleted = _this$deletionRetryIn.onDeleteCompleted, deletionReason = _this$deletionRetryIn.deletionReason;
453
451
  if (!this.confirmationCallback) {
454
452
  _context3.next = 6;
455
453
  break;
456
454
  }
457
455
  _context3.next = 6;
458
- return this.delete(syncBlockIds, onDelete, onDeleteCompleted);
456
+ return this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
459
457
  case 6:
460
458
  case "end":
461
459
  return _context3.stop();
@@ -485,7 +483,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
485
483
  }, {
486
484
  key: "deleteSyncBlocksWithConfirmation",
487
485
  value: (function () {
488
- var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(syncBlockIds, onDelete, onDeleteCompleted, destroyCallback) {
486
+ var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(syncBlockIds, deletionReason, onDelete, onDeleteCompleted, destroyCallback) {
489
487
  var confirmed, isDeleteSuccessful;
490
488
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
491
489
  while (1) switch (_context4.prev = _context4.next) {
@@ -495,7 +493,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
495
493
  break;
496
494
  }
497
495
  _context4.next = 3;
498
- return this.confirmationCallback(syncBlockIds.length);
496
+ return this.confirmationCallback(syncBlockIds, deletionReason);
499
497
  case 3:
500
498
  confirmed = _context4.sent;
501
499
  if (!confirmed) {
@@ -503,7 +501,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
503
501
  break;
504
502
  }
505
503
  _context4.next = 7;
506
- return this.delete(syncBlockIds, onDelete, onDeleteCompleted);
504
+ return this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
507
505
  case 7:
508
506
  isDeleteSuccessful = _context4.sent;
509
507
  if (!isDeleteSuccessful) {
@@ -512,7 +510,8 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
512
510
  syncBlockIds: syncBlockIds,
513
511
  onDelete: onDelete,
514
512
  onDeleteCompleted: onDeleteCompleted,
515
- destroyCallback: destroyCallback
513
+ destroyCallback: destroyCallback,
514
+ deletionReason: deletionReason
516
515
  };
517
516
  } else {
518
517
  destroyCallback();
@@ -527,7 +526,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
527
526
  }
528
527
  }, _callee4, this);
529
528
  }));
530
- function deleteSyncBlocksWithConfirmation(_x4, _x5, _x6, _x7) {
529
+ function deleteSyncBlocksWithConfirmation(_x5, _x6, _x7, _x8, _x9) {
531
530
  return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
532
531
  }
533
532
  return deleteSyncBlocksWithConfirmation;
@@ -549,6 +548,25 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
549
548
  return Promise.resolve(undefined);
550
549
  }
551
550
  }
551
+ }, {
552
+ key: "fetchReferences",
553
+ value: function fetchReferences(resourceId) {
554
+ try {
555
+ if (!this.dataProvider) {
556
+ throw new Error('Data provider not set');
557
+ }
558
+ return this.dataProvider.fetchReferences(resourceId, true);
559
+ } catch (error) {
560
+ var _this$fireAnalyticsEv7;
561
+ logException(error, {
562
+ location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
563
+ });
564
+ (_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 || _this$fireAnalyticsEv7.call(this, fetchReferencesErrorPayload(error.message));
565
+ return Promise.resolve({
566
+ error: SyncBlockError.Errored
567
+ });
568
+ }
569
+ }
552
570
  }, {
553
571
  key: "destroy",
554
572
  value: function destroy() {
@@ -73,7 +73,7 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
73
73
  while (1) switch (_context.prev = _context.next) {
74
74
  case 0:
75
75
  _context.next = 2;
76
- return (_this$dataProvider = _this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, reference.documentAri, getProductFromSourceAri(reference.documentAri), _this.fireAnalyticsEvent, reference.hasAccess, 'view');
76
+ return (_this$dataProvider = _this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(reference.blockInstanceId || '', reference.documentAri, getProductFromSourceAri(reference.documentAri), _this.fireAnalyticsEvent, reference.hasAccess, 'view');
77
77
  case 2:
78
78
  sourceInfo = _context.sent;
79
79
  if (sourceInfo) {
@@ -19,8 +19,9 @@ export var resolveSyncBlockInstance = function resolveSyncBlockInstance(oldResul
19
19
  if (!oldResult.data) {
20
20
  return newResult;
21
21
  } else if (!newResult.data) {
22
+ var _newResult$error, _newResult$error2;
22
23
  // return the old result if there was an error, e.g. network error, but not if not found or forbidden
23
- if (newResult.error === SyncBlockError.NotFound || newResult.error === SyncBlockError.Forbidden) {
24
+ if (((_newResult$error = newResult.error) === null || _newResult$error === void 0 ? void 0 : _newResult$error.type) === SyncBlockError.NotFound || ((_newResult$error2 = newResult.error) === null || _newResult$error2 === void 0 ? void 0 : _newResult$error2.type) === SyncBlockError.Forbidden) {
24
25
  return newResult;
25
26
  } else {
26
27
  return oldResult;
@@ -1,4 +1,4 @@
1
- import type { ReferenceSyncBlockResponse, SyncBlockProduct, SyncBlockStatus } from '../../common/types';
1
+ import type { ReferenceSyncBlockResponse, SyncBlockProduct, SyncBlockStatus, DeletionReason } from '../../common/types';
2
2
  export type BlockContentResponse = {
3
3
  blockAri: string;
4
4
  blockInstanceId: string;
@@ -6,6 +6,7 @@ export type BlockContentResponse = {
6
6
  contentUpdatedAt: number;
7
7
  createdAt: number;
8
8
  createdBy: string;
9
+ deletionReason: DeletionReason;
9
10
  product: SyncBlockProduct;
10
11
  sourceAri: string;
11
12
  status: SyncBlockStatus;
@@ -70,6 +71,7 @@ export type GetSyncedBlockContentRequest = {
70
71
  };
71
72
  export type DeleteSyncedBlockRequest = {
72
73
  blockAri: string;
74
+ deleteReason: string | undefined;
73
75
  };
74
76
  export type UpdateSyncedBlockRequest = {
75
77
  blockAri: string;
@@ -127,7 +129,7 @@ export declare const getSyncedBlockContent: ({ blockAri }: GetSyncedBlockContent
127
129
  * @returns A promise containing arrays of successfully fetched blocks and any errors encountered
128
130
  */
129
131
  export declare const batchRetrieveSyncedBlocks: ({ blockIdentifiers, documentAri, }: BatchRetrieveSyncedBlocksRequest) => Promise<BatchRetrieveSyncedBlocksResponse>;
130
- export declare const deleteSyncedBlock: ({ blockAri }: DeleteSyncedBlockRequest) => Promise<void>;
132
+ export declare const deleteSyncedBlock: ({ blockAri, deleteReason, }: DeleteSyncedBlockRequest) => Promise<void>;
131
133
  export declare const updateSyncedBlock: ({ blockAri, content, stepVersion, }: UpdateSyncedBlockRequest) => Promise<void>;
132
134
  export declare const createSyncedBlock: ({ blockAri, blockInstanceId, sourceAri, product, content, stepVersion, }: CreateSyncedBlockRequest) => Promise<BlockContentResponse>;
133
135
  export declare const updateReferenceSyncedBlockOnDocument: ({ documentAri, blocks, noContent, }: UpdateReferenceSyncedBlockOnDocumentRequest) => Promise<ReferenceSyncedBlockResponse | void>;
@@ -32,6 +32,7 @@ export interface SyncBlockData {
32
32
  contentUpdatedAt?: string;
33
33
  createdAt?: string;
34
34
  createdBy?: string;
35
+ deletionReason?: DeletionReason;
35
36
  isSynced?: boolean;
36
37
  /**
37
38
  * Whether the block is on the same page as the source block
@@ -47,6 +48,7 @@ export interface SyncBlockData {
47
48
  sourceTitle?: string;
48
49
  sourceURL?: string;
49
50
  status?: SyncBlockStatus;
51
+ updatedAt?: string;
50
52
  }
51
53
  export interface ReferenceSyncBlockResponse {
52
54
  blockAri: string;
@@ -68,3 +70,5 @@ export type ReferencesSourceInfo = {
68
70
  error?: SyncBlockError;
69
71
  references?: Array<SyncBlockSourceInfo | undefined>;
70
72
  };
73
+ export type DeletionReason = 'source-block-deleted' | 'source-block-unsynced';
74
+ export type DeletionReasonResponse = DeletionReason | 'source-document-deleted';
@@ -1,6 +1,6 @@
1
1
  export { rebaseTransaction } from './common/rebase-transaction';
2
2
  export { SyncBlockError } from './common/types';
3
- export type { ResourceId, SyncBlockData, SyncBlockNode, SyncBlockProduct, SyncBlockStatus, BlockInstanceId, SyncBlockAttrs, ReferenceSyncBlockData, ReferencesSourceInfo } from './common/types';
3
+ export type { ResourceId, SyncBlockData, SyncBlockNode, SyncBlockProduct, SyncBlockStatus, BlockInstanceId, SyncBlockAttrs, ReferenceSyncBlockData, ReferencesSourceInfo, DeletionReason, } from './common/types';
4
4
  export { useFetchSyncBlockData, type UseFetchSyncBlockDataResult, } from './hooks/useFetchSyncBlockData';
5
5
  export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
6
6
  export { useHandleContentChanges } from './hooks/useHandleContentChanges';
@@ -72,7 +72,7 @@ declare class BlockServiceADFWriteProvider implements ADFWriteProvider {
72
72
  constructor({ cloudId, parentAri, parentId, product, getVersion, }: BlockServiceADFWriteProviderProps);
73
73
  writeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
74
74
  createData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
75
- deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
75
+ deleteData(resourceId: string, deleteReason: string | undefined): Promise<DeleteSyncBlockResult>;
76
76
  generateResourceIdForReference(sourceId: ResourceId): ResourceId;
77
77
  generateResourceId(): ResourceId;
78
78
  updateReferenceData(blocks: SyncBlockAttrs[], noContent?: boolean): Promise<UpdateReferenceSyncBlockResult>;
@@ -1,6 +1,6 @@
1
1
  import type { RendererSyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
2
2
  import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
3
- import { type BlockInstanceId, type ReferenceSyncBlockData, type ResourceId, type SyncBlockAttrs, type SyncBlockData, type SyncBlockNode, type SyncBlockProduct } from '../common/types';
3
+ import { type BlockInstanceId, type DeletionReason, type ReferenceSyncBlockData, type ResourceId, type SyncBlockAttrs, type SyncBlockData, type SyncBlockNode, type SyncBlockProduct } from '../common/types';
4
4
  import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type BlockSubscriptionErrorCallback, type BlockUpdateCallback, type DeleteSyncBlockResult, type SyncBlockInstance, type SyncBlockParentInfo, type SyncBlockSourceInfo, type SyncedBlockRendererProviderOptions, type Unsubscribe, type UpdateReferenceSyncBlockResult, type WriteSyncBlockResult } from './types';
5
5
  export declare class SyncBlockProvider extends SyncBlockDataProvider {
6
6
  name: string;
@@ -58,7 +58,7 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
58
58
  *
59
59
  * @returns Array of {resourceId?: string, error?: string}.
60
60
  */
61
- deleteNodesData(resourceIds: ResourceId[]): Promise<Array<DeleteSyncBlockResult>>;
61
+ deleteNodesData(resourceIds: ResourceId[], deletionReason: DeletionReason | undefined): Promise<Array<DeleteSyncBlockResult>>;
62
62
  /**
63
63
  * Fetch the source info from the source id
64
64
  *
@@ -4,7 +4,7 @@ import type { EmojiProvider } from '@atlaskit/emoji';
4
4
  import type { MentionProvider } from '@atlaskit/mention/types';
5
5
  import { NodeDataProvider } from '@atlaskit/node-data-provider';
6
6
  import type { TaskDecisionProvider } from '@atlaskit/task-decision/types';
7
- import type { SyncBlockData, ResourceId, SyncBlockError, SyncBlockNode, SyncBlockProduct, BlockInstanceId, SyncBlockAttrs, ReferenceSyncBlockData } from '../common/types';
7
+ import type { SyncBlockData, ResourceId, SyncBlockError, SyncBlockNode, SyncBlockProduct, BlockInstanceId, SyncBlockAttrs, ReferenceSyncBlockData, DeletionReason } from '../common/types';
8
8
  /**
9
9
  * The instance of a sync block, containing its data and metadata.
10
10
  * Mainly used for representing the state of a sync block after fetching from a data provider.
@@ -12,7 +12,10 @@ import type { SyncBlockData, ResourceId, SyncBlockError, SyncBlockNode, SyncBloc
12
12
  */
13
13
  export type SyncBlockInstance = {
14
14
  data?: SyncBlockData;
15
- error?: SyncBlockError;
15
+ error?: {
16
+ reason?: string;
17
+ type: SyncBlockError;
18
+ };
16
19
  /**
17
20
  * The resourceId in the attrs of the block
18
21
  */
@@ -73,10 +76,11 @@ export interface ADFWriteProvider {
73
76
  /**
74
77
  * Delete source block.
75
78
  * @param resourceId the resourceId of the block to be deleted
79
+ * @param deleteReason the reason for the deletion, e.g. 'source-block-unsynced', 'source-block-deleted'
76
80
  * @returns Object representing the result of the deletion. {resourceId: string, success: boolean, error?: string}.
77
81
  * User should not be blocked by not_found error when deleting, so successful result should be returned for 404 error
78
82
  */
79
- deleteData: (resourceId: ResourceId) => Promise<DeleteSyncBlockResult>;
83
+ deleteData: (resourceId: ResourceId, deleteReason: string | undefined) => Promise<DeleteSyncBlockResult>;
80
84
  generateResourceIdForReference: (sourceId: ResourceId) => ResourceId;
81
85
  parentAri?: string;
82
86
  product: SyncBlockProduct;
@@ -105,7 +109,7 @@ export type SyncedBlockRendererProviderOptions = {
105
109
  export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, SyncBlockInstance> {
106
110
  abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<WriteSyncBlockResult>>;
107
111
  abstract createNodeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
108
- abstract deleteNodesData(resourceIds: string[]): Promise<Array<DeleteSyncBlockResult>>;
112
+ abstract deleteNodesData(resourceIds: string[], deleteReason: DeletionReason | undefined): Promise<Array<DeleteSyncBlockResult>>;
109
113
  abstract fetchSyncBlockSourceInfo(localId: BlockInstanceId, sourceAri?: string, sourceProduct?: SyncBlockProduct, fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void, hasAccess?: boolean, urlType?: 'view' | 'edit'): Promise<SyncBlockSourceInfo | undefined>;
110
114
  abstract setProviderOptions(providerOptions: SyncedBlockRendererProviderOptions): void;
111
115
  abstract getSyncedBlockRendererProviderOptions(): SyncedBlockRendererProviderOptions;
@@ -1,8 +1,8 @@
1
1
  import { type SyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
2
2
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import { type ResourceId, type SyncBlockAttrs, type BlockInstanceId } from '../common/types';
3
+ import { type ResourceId, type SyncBlockAttrs, type BlockInstanceId, type DeletionReason, type ReferenceSyncBlockData } from '../common/types';
4
4
  import type { SyncBlockDataProvider, SyncBlockSourceInfo } from '../providers/types';
5
- export type ConfirmationCallback = (syncBlockCount: number) => Promise<boolean>;
5
+ export type ConfirmationCallback = (syncBlockIds: SyncBlockAttrs[], deleteReason: DeletionReason | undefined) => Promise<boolean>;
6
6
  type OnDelete = () => void;
7
7
  type OnDeleteCompleted = (success: boolean) => void;
8
8
  type DestroyCallback = () => void;
@@ -70,8 +70,9 @@ export declare class SourceSyncBlockStoreManager {
70
70
  * @param onDeleteCompleted - The callback for after the deletion is saved to BE (whether successful or not)
71
71
  * @param destroyCallback - The callback to clear any reference stored for deletion (regardless if deletion is completed or abort)
72
72
  */
73
- deleteSyncBlocksWithConfirmation(syncBlockIds: SyncBlockAttrs[], onDelete: OnDelete, onDeleteCompleted: OnDeleteCompleted, destroyCallback: DestroyCallback): Promise<void>;
73
+ deleteSyncBlocksWithConfirmation(syncBlockIds: SyncBlockAttrs[], deletionReason: DeletionReason | undefined, onDelete: OnDelete, onDeleteCompleted: OnDeleteCompleted, destroyCallback: DestroyCallback): Promise<void>;
74
74
  getSyncBlockSourceInfo(localId: BlockInstanceId): Promise<SyncBlockSourceInfo | undefined>;
75
+ fetchReferences(resourceId: string): Promise<ReferenceSyncBlockData>;
75
76
  destroy(): void;
76
77
  }
77
78
  export {};
@@ -1,4 +1,4 @@
1
- import type { ReferenceSyncBlockResponse, SyncBlockProduct, SyncBlockStatus } from '../../common/types';
1
+ import type { ReferenceSyncBlockResponse, SyncBlockProduct, SyncBlockStatus, DeletionReason } from '../../common/types';
2
2
  export type BlockContentResponse = {
3
3
  blockAri: string;
4
4
  blockInstanceId: string;
@@ -6,6 +6,7 @@ export type BlockContentResponse = {
6
6
  contentUpdatedAt: number;
7
7
  createdAt: number;
8
8
  createdBy: string;
9
+ deletionReason: DeletionReason;
9
10
  product: SyncBlockProduct;
10
11
  sourceAri: string;
11
12
  status: SyncBlockStatus;
@@ -70,6 +71,7 @@ export type GetSyncedBlockContentRequest = {
70
71
  };
71
72
  export type DeleteSyncedBlockRequest = {
72
73
  blockAri: string;
74
+ deleteReason: string | undefined;
73
75
  };
74
76
  export type UpdateSyncedBlockRequest = {
75
77
  blockAri: string;
@@ -127,7 +129,7 @@ export declare const getSyncedBlockContent: ({ blockAri }: GetSyncedBlockContent
127
129
  * @returns A promise containing arrays of successfully fetched blocks and any errors encountered
128
130
  */
129
131
  export declare const batchRetrieveSyncedBlocks: ({ blockIdentifiers, documentAri, }: BatchRetrieveSyncedBlocksRequest) => Promise<BatchRetrieveSyncedBlocksResponse>;
130
- export declare const deleteSyncedBlock: ({ blockAri }: DeleteSyncedBlockRequest) => Promise<void>;
132
+ export declare const deleteSyncedBlock: ({ blockAri, deleteReason, }: DeleteSyncedBlockRequest) => Promise<void>;
131
133
  export declare const updateSyncedBlock: ({ blockAri, content, stepVersion, }: UpdateSyncedBlockRequest) => Promise<void>;
132
134
  export declare const createSyncedBlock: ({ blockAri, blockInstanceId, sourceAri, product, content, stepVersion, }: CreateSyncedBlockRequest) => Promise<BlockContentResponse>;
133
135
  export declare const updateReferenceSyncedBlockOnDocument: ({ documentAri, blocks, noContent, }: UpdateReferenceSyncedBlockOnDocumentRequest) => Promise<ReferenceSyncedBlockResponse | void>;
@@ -32,6 +32,7 @@ export interface SyncBlockData {
32
32
  contentUpdatedAt?: string;
33
33
  createdAt?: string;
34
34
  createdBy?: string;
35
+ deletionReason?: DeletionReason;
35
36
  isSynced?: boolean;
36
37
  /**
37
38
  * Whether the block is on the same page as the source block
@@ -47,6 +48,7 @@ export interface SyncBlockData {
47
48
  sourceTitle?: string;
48
49
  sourceURL?: string;
49
50
  status?: SyncBlockStatus;
51
+ updatedAt?: string;
50
52
  }
51
53
  export interface ReferenceSyncBlockResponse {
52
54
  blockAri: string;
@@ -68,3 +70,5 @@ export type ReferencesSourceInfo = {
68
70
  error?: SyncBlockError;
69
71
  references?: Array<SyncBlockSourceInfo | undefined>;
70
72
  };
73
+ export type DeletionReason = 'source-block-deleted' | 'source-block-unsynced';
74
+ export type DeletionReasonResponse = DeletionReason | 'source-document-deleted';
@@ -1,6 +1,6 @@
1
1
  export { rebaseTransaction } from './common/rebase-transaction';
2
2
  export { SyncBlockError } from './common/types';
3
- export type { ResourceId, SyncBlockData, SyncBlockNode, SyncBlockProduct, SyncBlockStatus, BlockInstanceId, SyncBlockAttrs, ReferenceSyncBlockData, ReferencesSourceInfo } from './common/types';
3
+ export type { ResourceId, SyncBlockData, SyncBlockNode, SyncBlockProduct, SyncBlockStatus, BlockInstanceId, SyncBlockAttrs, ReferenceSyncBlockData, ReferencesSourceInfo, DeletionReason, } from './common/types';
4
4
  export { useFetchSyncBlockData, type UseFetchSyncBlockDataResult, } from './hooks/useFetchSyncBlockData';
5
5
  export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
6
6
  export { useHandleContentChanges } from './hooks/useHandleContentChanges';
@@ -72,7 +72,7 @@ declare class BlockServiceADFWriteProvider implements ADFWriteProvider {
72
72
  constructor({ cloudId, parentAri, parentId, product, getVersion, }: BlockServiceADFWriteProviderProps);
73
73
  writeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
74
74
  createData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
75
- deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
75
+ deleteData(resourceId: string, deleteReason: string | undefined): Promise<DeleteSyncBlockResult>;
76
76
  generateResourceIdForReference(sourceId: ResourceId): ResourceId;
77
77
  generateResourceId(): ResourceId;
78
78
  updateReferenceData(blocks: SyncBlockAttrs[], noContent?: boolean): Promise<UpdateReferenceSyncBlockResult>;
@@ -1,6 +1,6 @@
1
1
  import type { RendererSyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
2
2
  import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
3
- import { type BlockInstanceId, type ReferenceSyncBlockData, type ResourceId, type SyncBlockAttrs, type SyncBlockData, type SyncBlockNode, type SyncBlockProduct } from '../common/types';
3
+ import { type BlockInstanceId, type DeletionReason, type ReferenceSyncBlockData, type ResourceId, type SyncBlockAttrs, type SyncBlockData, type SyncBlockNode, type SyncBlockProduct } from '../common/types';
4
4
  import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type BlockSubscriptionErrorCallback, type BlockUpdateCallback, type DeleteSyncBlockResult, type SyncBlockInstance, type SyncBlockParentInfo, type SyncBlockSourceInfo, type SyncedBlockRendererProviderOptions, type Unsubscribe, type UpdateReferenceSyncBlockResult, type WriteSyncBlockResult } from './types';
5
5
  export declare class SyncBlockProvider extends SyncBlockDataProvider {
6
6
  name: string;
@@ -58,7 +58,7 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
58
58
  *
59
59
  * @returns Array of {resourceId?: string, error?: string}.
60
60
  */
61
- deleteNodesData(resourceIds: ResourceId[]): Promise<Array<DeleteSyncBlockResult>>;
61
+ deleteNodesData(resourceIds: ResourceId[], deletionReason: DeletionReason | undefined): Promise<Array<DeleteSyncBlockResult>>;
62
62
  /**
63
63
  * Fetch the source info from the source id
64
64
  *
@@ -4,7 +4,7 @@ import type { EmojiProvider } from '@atlaskit/emoji';
4
4
  import type { MentionProvider } from '@atlaskit/mention/types';
5
5
  import { NodeDataProvider } from '@atlaskit/node-data-provider';
6
6
  import type { TaskDecisionProvider } from '@atlaskit/task-decision/types';
7
- import type { SyncBlockData, ResourceId, SyncBlockError, SyncBlockNode, SyncBlockProduct, BlockInstanceId, SyncBlockAttrs, ReferenceSyncBlockData } from '../common/types';
7
+ import type { SyncBlockData, ResourceId, SyncBlockError, SyncBlockNode, SyncBlockProduct, BlockInstanceId, SyncBlockAttrs, ReferenceSyncBlockData, DeletionReason } from '../common/types';
8
8
  /**
9
9
  * The instance of a sync block, containing its data and metadata.
10
10
  * Mainly used for representing the state of a sync block after fetching from a data provider.
@@ -12,7 +12,10 @@ import type { SyncBlockData, ResourceId, SyncBlockError, SyncBlockNode, SyncBloc
12
12
  */
13
13
  export type SyncBlockInstance = {
14
14
  data?: SyncBlockData;
15
- error?: SyncBlockError;
15
+ error?: {
16
+ reason?: string;
17
+ type: SyncBlockError;
18
+ };
16
19
  /**
17
20
  * The resourceId in the attrs of the block
18
21
  */
@@ -73,10 +76,11 @@ export interface ADFWriteProvider {
73
76
  /**
74
77
  * Delete source block.
75
78
  * @param resourceId the resourceId of the block to be deleted
79
+ * @param deleteReason the reason for the deletion, e.g. 'source-block-unsynced', 'source-block-deleted'
76
80
  * @returns Object representing the result of the deletion. {resourceId: string, success: boolean, error?: string}.
77
81
  * User should not be blocked by not_found error when deleting, so successful result should be returned for 404 error
78
82
  */
79
- deleteData: (resourceId: ResourceId) => Promise<DeleteSyncBlockResult>;
83
+ deleteData: (resourceId: ResourceId, deleteReason: string | undefined) => Promise<DeleteSyncBlockResult>;
80
84
  generateResourceIdForReference: (sourceId: ResourceId) => ResourceId;
81
85
  parentAri?: string;
82
86
  product: SyncBlockProduct;
@@ -105,7 +109,7 @@ export type SyncedBlockRendererProviderOptions = {
105
109
  export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, SyncBlockInstance> {
106
110
  abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<WriteSyncBlockResult>>;
107
111
  abstract createNodeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
108
- abstract deleteNodesData(resourceIds: string[]): Promise<Array<DeleteSyncBlockResult>>;
112
+ abstract deleteNodesData(resourceIds: string[], deleteReason: DeletionReason | undefined): Promise<Array<DeleteSyncBlockResult>>;
109
113
  abstract fetchSyncBlockSourceInfo(localId: BlockInstanceId, sourceAri?: string, sourceProduct?: SyncBlockProduct, fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void, hasAccess?: boolean, urlType?: 'view' | 'edit'): Promise<SyncBlockSourceInfo | undefined>;
110
114
  abstract setProviderOptions(providerOptions: SyncedBlockRendererProviderOptions): void;
111
115
  abstract getSyncedBlockRendererProviderOptions(): SyncedBlockRendererProviderOptions;
@@ -1,8 +1,8 @@
1
1
  import { type SyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
2
2
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import { type ResourceId, type SyncBlockAttrs, type BlockInstanceId } from '../common/types';
3
+ import { type ResourceId, type SyncBlockAttrs, type BlockInstanceId, type DeletionReason, type ReferenceSyncBlockData } from '../common/types';
4
4
  import type { SyncBlockDataProvider, SyncBlockSourceInfo } from '../providers/types';
5
- export type ConfirmationCallback = (syncBlockCount: number) => Promise<boolean>;
5
+ export type ConfirmationCallback = (syncBlockIds: SyncBlockAttrs[], deleteReason: DeletionReason | undefined) => Promise<boolean>;
6
6
  type OnDelete = () => void;
7
7
  type OnDeleteCompleted = (success: boolean) => void;
8
8
  type DestroyCallback = () => void;
@@ -70,8 +70,9 @@ export declare class SourceSyncBlockStoreManager {
70
70
  * @param onDeleteCompleted - The callback for after the deletion is saved to BE (whether successful or not)
71
71
  * @param destroyCallback - The callback to clear any reference stored for deletion (regardless if deletion is completed or abort)
72
72
  */
73
- deleteSyncBlocksWithConfirmation(syncBlockIds: SyncBlockAttrs[], onDelete: OnDelete, onDeleteCompleted: OnDeleteCompleted, destroyCallback: DestroyCallback): Promise<void>;
73
+ deleteSyncBlocksWithConfirmation(syncBlockIds: SyncBlockAttrs[], deletionReason: DeletionReason | undefined, onDelete: OnDelete, onDeleteCompleted: OnDeleteCompleted, destroyCallback: DestroyCallback): Promise<void>;
74
74
  getSyncBlockSourceInfo(localId: BlockInstanceId): Promise<SyncBlockSourceInfo | undefined>;
75
+ fetchReferences(resourceId: string): Promise<ReferenceSyncBlockData>;
75
76
  destroy(): void;
76
77
  }
77
78
  export {};
package/package.json CHANGED
@@ -78,7 +78,7 @@
78
78
  }
79
79
  },
80
80
  "name": "@atlaskit/editor-synced-block-provider",
81
- "version": "3.14.1",
81
+ "version": "3.14.2",
82
82
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
83
83
  "author": "Atlassian Pty Ltd",
84
84
  "license": "Apache-2.0",