@atlaskit/editor-synced-block-provider 3.14.0 → 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.
- package/CHANGELOG.md +18 -0
- package/dist/cjs/clients/block-service/blockService.js +9 -7
- package/dist/cjs/clients/block-service/blockSubscription.js +2 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/cjs/providers/block-service/blockServiceAPI.js +63 -56
- package/dist/cjs/providers/syncBlockProvider.js +10 -6
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +8 -9
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +41 -23
- package/dist/cjs/store-manager/syncBlockStoreManager.js +1 -1
- package/dist/cjs/utils/resolveSyncBlockInstance.js +2 -1
- package/dist/cjs/utils/utils.js +12 -1
- package/dist/es2019/clients/block-service/blockService.js +5 -2
- package/dist/es2019/clients/block-service/blockSubscription.js +2 -0
- package/dist/es2019/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/es2019/providers/block-service/blockServiceAPI.js +51 -45
- package/dist/es2019/providers/syncBlockProvider.js +8 -4
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +6 -7
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +28 -11
- package/dist/es2019/store-manager/syncBlockStoreManager.js +1 -1
- package/dist/es2019/utils/resolveSyncBlockInstance.js +2 -1
- package/dist/es2019/utils/utils.js +11 -0
- package/dist/esm/clients/block-service/blockService.js +9 -7
- package/dist/esm/clients/block-service/blockSubscription.js +2 -0
- package/dist/esm/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/esm/providers/block-service/blockServiceAPI.js +63 -56
- package/dist/esm/providers/syncBlockProvider.js +10 -6
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +8 -9
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +42 -24
- package/dist/esm/store-manager/syncBlockStoreManager.js +1 -1
- package/dist/esm/utils/resolveSyncBlockInstance.js +2 -1
- package/dist/esm/utils/utils.js +11 -0
- package/dist/types/clients/block-service/blockService.d.ts +4 -2
- package/dist/types/clients/block-service/blockSubscription.d.ts +1 -0
- package/dist/types/common/types.d.ts +4 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +1 -1
- package/dist/types/providers/syncBlockProvider.d.ts +2 -2
- package/dist/types/providers/types.d.ts +8 -4
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +4 -3
- package/dist/types/utils/utils.d.ts +1 -0
- package/dist/types-ts4.5/clients/block-service/blockService.d.ts +4 -2
- package/dist/types-ts4.5/clients/block-service/blockSubscription.d.ts +1 -0
- package/dist/types-ts4.5/common/types.d.ts +4 -0
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +1 -1
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +2 -2
- package/dist/types-ts4.5/providers/types.d.ts +8 -4
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +4 -3
- package/dist/types-ts4.5/utils/utils.d.ts +1 -0
- package/package.json +1 -1
|
@@ -135,10 +135,9 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
135
135
|
if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
|
|
136
136
|
(_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 || _this$saveExperience.start({});
|
|
137
137
|
}
|
|
138
|
-
;
|
|
139
|
-
_context.next = 12;
|
|
138
|
+
_context.next = 11;
|
|
140
139
|
return this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
|
|
141
|
-
case
|
|
140
|
+
case 11:
|
|
142
141
|
writeResults = _context.sent;
|
|
143
142
|
writeResults.forEach(function (result) {
|
|
144
143
|
// set isDirty to true for cases where it failed to save the sync block to the BE
|
|
@@ -152,7 +151,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
152
151
|
if (!writeResults.every(function (result) {
|
|
153
152
|
return result.resourceId && !result.error;
|
|
154
153
|
})) {
|
|
155
|
-
_context.next =
|
|
154
|
+
_context.next = 18;
|
|
156
155
|
break;
|
|
157
156
|
}
|
|
158
157
|
if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
|
|
@@ -164,9 +163,8 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
164
163
|
}
|
|
165
164
|
});
|
|
166
165
|
}
|
|
167
|
-
;
|
|
168
166
|
return _context.abrupt("return", true);
|
|
169
|
-
case
|
|
167
|
+
case 18:
|
|
170
168
|
if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
|
|
171
169
|
(_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 || _this$saveExperience3.failure();
|
|
172
170
|
}
|
|
@@ -177,22 +175,22 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
177
175
|
(_this2$fireAnalyticsE2 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE2 === void 0 || _this2$fireAnalyticsE2.call(_this2, (0, _errorHandling.updateErrorPayload)(result.error || 'Failed to write data', result.resourceId));
|
|
178
176
|
});
|
|
179
177
|
return _context.abrupt("return", false);
|
|
180
|
-
case
|
|
181
|
-
_context.next =
|
|
178
|
+
case 21:
|
|
179
|
+
_context.next = 28;
|
|
182
180
|
break;
|
|
183
|
-
case
|
|
184
|
-
_context.prev =
|
|
181
|
+
case 23:
|
|
182
|
+
_context.prev = 23;
|
|
185
183
|
_context.t0 = _context["catch"](0);
|
|
186
184
|
(0, _monitoring.logException)(_context.t0, {
|
|
187
185
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
188
186
|
});
|
|
189
187
|
(_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, (0, _errorHandling.updateErrorPayload)(_context.t0.message));
|
|
190
188
|
return _context.abrupt("return", false);
|
|
191
|
-
case
|
|
189
|
+
case 28:
|
|
192
190
|
case "end":
|
|
193
191
|
return _context.stop();
|
|
194
192
|
}
|
|
195
|
-
}, _callee, this, [[0,
|
|
193
|
+
}, _callee, this, [[0, 23]]);
|
|
196
194
|
}));
|
|
197
195
|
function flush() {
|
|
198
196
|
return _flush.apply(this, arguments);
|
|
@@ -345,7 +343,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
345
343
|
}, {
|
|
346
344
|
key: "delete",
|
|
347
345
|
value: function () {
|
|
348
|
-
var _delete2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syncBlockIds, onDelete, onDeleteCompleted) {
|
|
346
|
+
var _delete2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syncBlockIds, onDelete, onDeleteCompleted, reason) {
|
|
349
347
|
var _this5 = this;
|
|
350
348
|
var _this$deleteExperienc, results, callback, isDeleteSuccessful, _this$deleteExperienc2, _this$deleteExperienc3;
|
|
351
349
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
@@ -367,7 +365,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
367
365
|
_context2.next = 7;
|
|
368
366
|
return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
|
|
369
367
|
return attrs.resourceId;
|
|
370
|
-
}));
|
|
368
|
+
}), reason);
|
|
371
369
|
case 7:
|
|
372
370
|
results = _context2.sent;
|
|
373
371
|
isDeleteSuccessful = results.every(function (result) {
|
|
@@ -432,7 +430,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
432
430
|
}
|
|
433
431
|
}, _callee2, this, [[0, 15]]);
|
|
434
432
|
}));
|
|
435
|
-
function _delete(_x, _x2, _x3) {
|
|
433
|
+
function _delete(_x, _x2, _x3, _x4) {
|
|
436
434
|
return _delete2.apply(this, arguments);
|
|
437
435
|
}
|
|
438
436
|
return _delete;
|
|
@@ -446,7 +444,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
446
444
|
key: "retryDeletion",
|
|
447
445
|
value: function () {
|
|
448
446
|
var _retryDeletion = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
449
|
-
var _this$deletionRetryIn, syncBlockIds, onDelete, onDeleteCompleted;
|
|
447
|
+
var _this$deletionRetryIn, syncBlockIds, onDelete, onDeleteCompleted, deletionReason;
|
|
450
448
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
451
449
|
while (1) switch (_context3.prev = _context3.next) {
|
|
452
450
|
case 0:
|
|
@@ -456,13 +454,13 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
456
454
|
}
|
|
457
455
|
return _context3.abrupt("return", Promise.resolve());
|
|
458
456
|
case 2:
|
|
459
|
-
_this$deletionRetryIn = this.deletionRetryInfo, syncBlockIds = _this$deletionRetryIn.syncBlockIds, onDelete = _this$deletionRetryIn.onDelete, onDeleteCompleted = _this$deletionRetryIn.onDeleteCompleted;
|
|
457
|
+
_this$deletionRetryIn = this.deletionRetryInfo, syncBlockIds = _this$deletionRetryIn.syncBlockIds, onDelete = _this$deletionRetryIn.onDelete, onDeleteCompleted = _this$deletionRetryIn.onDeleteCompleted, deletionReason = _this$deletionRetryIn.deletionReason;
|
|
460
458
|
if (!this.confirmationCallback) {
|
|
461
459
|
_context3.next = 6;
|
|
462
460
|
break;
|
|
463
461
|
}
|
|
464
462
|
_context3.next = 6;
|
|
465
|
-
return this.delete(syncBlockIds, onDelete, onDeleteCompleted);
|
|
463
|
+
return this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
|
|
466
464
|
case 6:
|
|
467
465
|
case "end":
|
|
468
466
|
return _context3.stop();
|
|
@@ -492,7 +490,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
492
490
|
}, {
|
|
493
491
|
key: "deleteSyncBlocksWithConfirmation",
|
|
494
492
|
value: (function () {
|
|
495
|
-
var _deleteSyncBlocksWithConfirmation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(syncBlockIds, onDelete, onDeleteCompleted, destroyCallback) {
|
|
493
|
+
var _deleteSyncBlocksWithConfirmation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(syncBlockIds, deletionReason, onDelete, onDeleteCompleted, destroyCallback) {
|
|
496
494
|
var confirmed, isDeleteSuccessful;
|
|
497
495
|
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
498
496
|
while (1) switch (_context4.prev = _context4.next) {
|
|
@@ -502,7 +500,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
502
500
|
break;
|
|
503
501
|
}
|
|
504
502
|
_context4.next = 3;
|
|
505
|
-
return this.confirmationCallback(syncBlockIds
|
|
503
|
+
return this.confirmationCallback(syncBlockIds, deletionReason);
|
|
506
504
|
case 3:
|
|
507
505
|
confirmed = _context4.sent;
|
|
508
506
|
if (!confirmed) {
|
|
@@ -510,7 +508,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
510
508
|
break;
|
|
511
509
|
}
|
|
512
510
|
_context4.next = 7;
|
|
513
|
-
return this.delete(syncBlockIds, onDelete, onDeleteCompleted);
|
|
511
|
+
return this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
|
|
514
512
|
case 7:
|
|
515
513
|
isDeleteSuccessful = _context4.sent;
|
|
516
514
|
if (!isDeleteSuccessful) {
|
|
@@ -519,7 +517,8 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
519
517
|
syncBlockIds: syncBlockIds,
|
|
520
518
|
onDelete: onDelete,
|
|
521
519
|
onDeleteCompleted: onDeleteCompleted,
|
|
522
|
-
destroyCallback: destroyCallback
|
|
520
|
+
destroyCallback: destroyCallback,
|
|
521
|
+
deletionReason: deletionReason
|
|
523
522
|
};
|
|
524
523
|
} else {
|
|
525
524
|
destroyCallback();
|
|
@@ -534,7 +533,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
534
533
|
}
|
|
535
534
|
}, _callee4, this);
|
|
536
535
|
}));
|
|
537
|
-
function deleteSyncBlocksWithConfirmation(
|
|
536
|
+
function deleteSyncBlocksWithConfirmation(_x5, _x6, _x7, _x8, _x9) {
|
|
538
537
|
return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
|
|
539
538
|
}
|
|
540
539
|
return deleteSyncBlocksWithConfirmation;
|
|
@@ -556,6 +555,25 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
556
555
|
return Promise.resolve(undefined);
|
|
557
556
|
}
|
|
558
557
|
}
|
|
558
|
+
}, {
|
|
559
|
+
key: "fetchReferences",
|
|
560
|
+
value: function fetchReferences(resourceId) {
|
|
561
|
+
try {
|
|
562
|
+
if (!this.dataProvider) {
|
|
563
|
+
throw new Error('Data provider not set');
|
|
564
|
+
}
|
|
565
|
+
return this.dataProvider.fetchReferences(resourceId, true);
|
|
566
|
+
} catch (error) {
|
|
567
|
+
var _this$fireAnalyticsEv7;
|
|
568
|
+
(0, _monitoring.logException)(error, {
|
|
569
|
+
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
570
|
+
});
|
|
571
|
+
(_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 || _this$fireAnalyticsEv7.call(this, (0, _errorHandling.fetchReferencesErrorPayload)(error.message));
|
|
572
|
+
return Promise.resolve({
|
|
573
|
+
error: _types.SyncBlockError.Errored
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
}
|
|
559
577
|
}, {
|
|
560
578
|
key: "destroy",
|
|
561
579
|
value: function destroy() {
|
|
@@ -79,7 +79,7 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
79
79
|
while (1) switch (_context.prev = _context.next) {
|
|
80
80
|
case 0:
|
|
81
81
|
_context.next = 2;
|
|
82
|
-
return (_this$dataProvider = _this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, reference.documentAri, (0, _ari.getProductFromSourceAri)(reference.documentAri), _this.fireAnalyticsEvent, reference.hasAccess, 'view');
|
|
82
|
+
return (_this$dataProvider = _this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(reference.blockInstanceId || '', reference.documentAri, (0, _ari.getProductFromSourceAri)(reference.documentAri), _this.fireAnalyticsEvent, reference.hasAccess, 'view');
|
|
83
83
|
case 2:
|
|
84
84
|
sourceInfo = _context.sent;
|
|
85
85
|
if (sourceInfo) {
|
|
@@ -26,8 +26,9 @@ var resolveSyncBlockInstance = exports.resolveSyncBlockInstance = function resol
|
|
|
26
26
|
if (!oldResult.data) {
|
|
27
27
|
return newResult;
|
|
28
28
|
} else if (!newResult.data) {
|
|
29
|
+
var _newResult$error, _newResult$error2;
|
|
29
30
|
// return the old result if there was an error, e.g. network error, but not if not found or forbidden
|
|
30
|
-
if (newResult.error === _types.SyncBlockError.NotFound || newResult.error === _types.SyncBlockError.Forbidden) {
|
|
31
|
+
if (((_newResult$error = newResult.error) === null || _newResult$error === void 0 ? void 0 : _newResult$error.type) === _types.SyncBlockError.NotFound || ((_newResult$error2 = newResult.error) === null || _newResult$error2 === void 0 ? void 0 : _newResult$error2.type) === _types.SyncBlockError.Forbidden) {
|
|
31
32
|
return newResult;
|
|
32
33
|
} else {
|
|
33
34
|
return oldResult;
|
package/dist/cjs/utils/utils.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getContentIdAndProductFromResourceId = exports.createSyncBlockNode = exports.convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockJSONNodeToSyncBlockNode = exports.convertPMNodesToSyncBlockNodes = exports.convertPMNodeToSyncBlockNode = void 0;
|
|
6
|
+
exports.getContentIdAndProductFromResourceId = exports.createSyncBlockNode = exports.convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockJSONNodeToSyncBlockNode = exports.convertPMNodesToSyncBlockNodes = exports.convertPMNodeToSyncBlockNode = exports.convertContentUpdatedAt = void 0;
|
|
7
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
7
8
|
/* eslint-disable require-unicode-regexp */
|
|
8
9
|
|
|
9
10
|
var convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNodeToSyncBlockData(node) {
|
|
@@ -57,4 +58,14 @@ var getContentIdAndProductFromResourceId = exports.getContentIdAndProductFromRes
|
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
60
|
throw new Error("Invalid resourceId: ".concat(resourceId));
|
|
61
|
+
};
|
|
62
|
+
var convertContentUpdatedAt = exports.convertContentUpdatedAt = function convertContentUpdatedAt(contentUpdatedAt) {
|
|
63
|
+
if (typeof contentUpdatedAt === 'number' && (0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
|
|
64
|
+
try {
|
|
65
|
+
return new Date(contentUpdatedAt).toISOString();
|
|
66
|
+
} catch (_unused) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
60
71
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
1
2
|
import { fetchWithRetry } from '../../utils/retry';
|
|
2
3
|
export const isBlockContentResponse = response => {
|
|
3
4
|
const content = response.content;
|
|
@@ -144,9 +145,11 @@ export const batchRetrieveSyncedBlocks = async ({
|
|
|
144
145
|
return await response.json();
|
|
145
146
|
};
|
|
146
147
|
export const deleteSyncedBlock = async ({
|
|
147
|
-
blockAri
|
|
148
|
+
blockAri,
|
|
149
|
+
deleteReason
|
|
148
150
|
}) => {
|
|
149
|
-
const
|
|
151
|
+
const url = deleteReason && fg('platform_synced_block_dogfooding') ? `${BLOCK_SERVICE_API_URL}/block/${encodeURIComponent(blockAri)}?deletionReason=${encodeURIComponent(deleteReason)}` : `${BLOCK_SERVICE_API_URL}/block/${encodeURIComponent(blockAri)}`;
|
|
152
|
+
const response = await fetchWithRetry(url, {
|
|
150
153
|
method: 'DELETE',
|
|
151
154
|
headers: COMMON_HEADERS
|
|
152
155
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createClient } from 'graphql-ws';
|
|
2
|
+
import { convertContentUpdatedAt } from '../../utils/utils';
|
|
2
3
|
const GRAPHQL_WS_ENDPOINT = '/gateway/api/graphql/subscriptions';
|
|
3
4
|
let blockServiceClient = null;
|
|
4
5
|
const getBlockServiceClient = () => {
|
|
@@ -69,6 +70,7 @@ const parseSubscriptionPayload = payload => {
|
|
|
69
70
|
blockAri: payload.blockAri,
|
|
70
71
|
blockInstanceId: payload.blockInstanceId,
|
|
71
72
|
content: JSON.parse(payload.content),
|
|
73
|
+
contentUpdatedAt: convertContentUpdatedAt(payload.contentUpdatedAt),
|
|
72
74
|
createdAt,
|
|
73
75
|
createdBy: payload.createdBy,
|
|
74
76
|
product: payload.product,
|
|
@@ -59,7 +59,9 @@ export const useFetchSyncBlockData = (manager, resourceId, localId, fireAnalytic
|
|
|
59
59
|
setFetchState({
|
|
60
60
|
syncBlockInstance: {
|
|
61
61
|
resourceId: resourceId || '',
|
|
62
|
-
error:
|
|
62
|
+
error: {
|
|
63
|
+
type: SyncBlockError.Errored
|
|
64
|
+
}
|
|
63
65
|
},
|
|
64
66
|
isLoading: false
|
|
65
67
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/* eslint-disable require-unicode-regexp */
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
3
|
import { generateBlockAri, generateBlockAriFromReference } from '../../clients/block-service/ari';
|
|
5
4
|
import { batchRetrieveSyncedBlocks, BlockError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getReferenceSyncedBlocksByBlockAri, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock } from '../../clients/block-service/blockService';
|
|
6
5
|
import { subscribeToBlockUpdates as subscribeToBlockUpdatesWS } from '../../clients/block-service/blockSubscription';
|
|
7
6
|
import { SyncBlockError } from '../../common/types';
|
|
8
7
|
import { stringifyError } from '../../utils/errorHandling';
|
|
9
8
|
import { createResourceIdForReference } from '../../utils/resourceId';
|
|
9
|
+
import { convertContentUpdatedAt } from '../../utils/utils';
|
|
10
10
|
const mapBlockError = error => {
|
|
11
11
|
switch (error.status) {
|
|
12
12
|
case 400:
|
|
@@ -87,24 +87,16 @@ export const convertToSyncBlockData = (data, resourceId) => {
|
|
|
87
87
|
// BE returns microseconds, convert to milliseconds
|
|
88
88
|
// BE should fix this in the future
|
|
89
89
|
createdAt = new Date(data.createdAt / 1000).toISOString();
|
|
90
|
-
} catch
|
|
90
|
+
} catch {
|
|
91
91
|
// fallback to undefined
|
|
92
92
|
// as we don't want to block the whole process due to invalid date
|
|
93
93
|
createdAt = undefined;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
let contentUpdatedAt;
|
|
97
|
-
if (typeof data.contentUpdatedAt === 'number' && fg('platform_synced_block_dogfooding')) {
|
|
98
|
-
try {
|
|
99
|
-
contentUpdatedAt = new Date(data.contentUpdatedAt).toISOString();
|
|
100
|
-
} catch (e) {
|
|
101
|
-
contentUpdatedAt = undefined;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
96
|
return {
|
|
105
97
|
blockInstanceId: data.blockInstanceId,
|
|
106
98
|
content: JSON.parse(data.content),
|
|
107
|
-
contentUpdatedAt,
|
|
99
|
+
contentUpdatedAt: convertContentUpdatedAt(data.contentUpdatedAt),
|
|
108
100
|
createdAt,
|
|
109
101
|
createdBy: data.createdBy,
|
|
110
102
|
product: data.product,
|
|
@@ -133,7 +125,9 @@ export const fetchReferences = async documentAri => {
|
|
|
133
125
|
if (!resourceId) {
|
|
134
126
|
// could not extract resourceId from blockAri, return InvalidContent error
|
|
135
127
|
return {
|
|
136
|
-
error:
|
|
128
|
+
error: {
|
|
129
|
+
type: SyncBlockError.InvalidContent
|
|
130
|
+
},
|
|
137
131
|
resourceId: blockContentResponse.blockAri
|
|
138
132
|
};
|
|
139
133
|
}
|
|
@@ -144,13 +138,17 @@ export const fetchReferences = async documentAri => {
|
|
|
144
138
|
} catch {
|
|
145
139
|
// JSON parsing error, return InvalidContent error
|
|
146
140
|
return {
|
|
147
|
-
error:
|
|
141
|
+
error: {
|
|
142
|
+
type: SyncBlockError.InvalidContent
|
|
143
|
+
},
|
|
148
144
|
resourceId: blockContentResponse.blockAri
|
|
149
145
|
};
|
|
150
146
|
}
|
|
151
147
|
});
|
|
152
148
|
const errorInstances = (errors || []).map(errorBlock => ({
|
|
153
|
-
error:
|
|
149
|
+
error: {
|
|
150
|
+
type: SyncBlockError.Errored
|
|
151
|
+
},
|
|
154
152
|
resourceId: errorBlock.blockAri
|
|
155
153
|
}));
|
|
156
154
|
return [...blocksInstances, ...errorInstances];
|
|
@@ -182,43 +180,43 @@ class BlockServiceADFFetchProvider {
|
|
|
182
180
|
const value = blockContentResponse.content;
|
|
183
181
|
if (!value) {
|
|
184
182
|
return {
|
|
185
|
-
error:
|
|
183
|
+
error: {
|
|
184
|
+
type: SyncBlockError.NotFound,
|
|
185
|
+
reason: blockContentResponse.deletionReason
|
|
186
|
+
},
|
|
186
187
|
resourceId
|
|
187
188
|
};
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
// Parse the synced block content from the response's content
|
|
191
192
|
const syncedBlockData = JSON.parse(value);
|
|
192
|
-
let contentUpdatedAt;
|
|
193
|
-
if (typeof blockContentResponse.contentUpdatedAt === 'number' && fg('platform_synced_block_dogfooding')) {
|
|
194
|
-
try {
|
|
195
|
-
contentUpdatedAt = new Date(blockContentResponse.contentUpdatedAt).toISOString();
|
|
196
|
-
} catch (e) {
|
|
197
|
-
contentUpdatedAt = undefined;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
193
|
return {
|
|
201
194
|
data: {
|
|
202
195
|
content: syncedBlockData,
|
|
203
196
|
resourceId: blockAri,
|
|
204
197
|
blockInstanceId: blockContentResponse.blockInstanceId,
|
|
205
198
|
// this was the node's localId, but has become the resourceId.
|
|
206
|
-
contentUpdatedAt,
|
|
199
|
+
contentUpdatedAt: convertContentUpdatedAt(blockContentResponse.contentUpdatedAt),
|
|
207
200
|
sourceAri: blockContentResponse.sourceAri,
|
|
208
201
|
product: blockContentResponse.product,
|
|
209
|
-
status: blockContentResponse.status
|
|
202
|
+
status: blockContentResponse.status,
|
|
203
|
+
deletionReason: blockContentResponse.deletionReason
|
|
210
204
|
},
|
|
211
205
|
resourceId
|
|
212
206
|
};
|
|
213
207
|
} catch (error) {
|
|
214
208
|
if (error instanceof BlockError) {
|
|
215
209
|
return {
|
|
216
|
-
error:
|
|
210
|
+
error: {
|
|
211
|
+
type: mapBlockError(error)
|
|
212
|
+
},
|
|
217
213
|
resourceId
|
|
218
214
|
};
|
|
219
215
|
}
|
|
220
216
|
return {
|
|
221
|
-
error:
|
|
217
|
+
error: {
|
|
218
|
+
type: SyncBlockError.Errored
|
|
219
|
+
},
|
|
222
220
|
resourceId
|
|
223
221
|
};
|
|
224
222
|
}
|
|
@@ -295,7 +293,9 @@ class BlockServiceADFFetchProvider {
|
|
|
295
293
|
const processedResourceIds = new Set();
|
|
296
294
|
if (!this.parentAri) {
|
|
297
295
|
return blockNodeIdentifiers.map(blockNodeIdentifier => ({
|
|
298
|
-
error:
|
|
296
|
+
error: {
|
|
297
|
+
type: SyncBlockError.Errored
|
|
298
|
+
},
|
|
299
299
|
resourceId: blockNodeIdentifier.resourceId
|
|
300
300
|
}));
|
|
301
301
|
}
|
|
@@ -318,36 +318,34 @@ class BlockServiceADFFetchProvider {
|
|
|
318
318
|
const value = blockContentResponse.content;
|
|
319
319
|
if (!value) {
|
|
320
320
|
results.push({
|
|
321
|
-
error:
|
|
321
|
+
error: {
|
|
322
|
+
type: SyncBlockError.NotFound,
|
|
323
|
+
reason: blockContentResponse.deletionReason
|
|
324
|
+
},
|
|
322
325
|
resourceId
|
|
323
326
|
});
|
|
324
327
|
continue;
|
|
325
328
|
}
|
|
326
329
|
try {
|
|
327
330
|
const syncedBlockData = JSON.parse(value);
|
|
328
|
-
let contentUpdatedAt;
|
|
329
|
-
if (typeof blockContentResponse.contentUpdatedAt === 'number' && fg('platform_synced_block_dogfooding')) {
|
|
330
|
-
try {
|
|
331
|
-
contentUpdatedAt = new Date(blockContentResponse.contentUpdatedAt).toISOString();
|
|
332
|
-
} catch (e) {
|
|
333
|
-
contentUpdatedAt = undefined;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
331
|
results.push({
|
|
337
332
|
data: {
|
|
338
333
|
content: syncedBlockData,
|
|
339
334
|
resourceId: blockContentResponse.blockAri,
|
|
340
|
-
contentUpdatedAt,
|
|
335
|
+
contentUpdatedAt: convertContentUpdatedAt(blockContentResponse.contentUpdatedAt),
|
|
341
336
|
blockInstanceId: blockContentResponse.blockInstanceId,
|
|
342
337
|
sourceAri: blockContentResponse.sourceAri,
|
|
343
338
|
product: blockContentResponse.product,
|
|
344
|
-
status: blockContentResponse.status
|
|
339
|
+
status: blockContentResponse.status,
|
|
340
|
+
deletionReason: blockContentResponse.deletionReason
|
|
345
341
|
},
|
|
346
342
|
resourceId
|
|
347
343
|
});
|
|
348
344
|
} catch {
|
|
349
345
|
results.push({
|
|
350
|
-
error:
|
|
346
|
+
error: {
|
|
347
|
+
type: SyncBlockError.Errored
|
|
348
|
+
},
|
|
351
349
|
resourceId
|
|
352
350
|
});
|
|
353
351
|
}
|
|
@@ -364,7 +362,9 @@ class BlockServiceADFFetchProvider {
|
|
|
364
362
|
}
|
|
365
363
|
processedResourceIds.add(resourceId);
|
|
366
364
|
results.push({
|
|
367
|
-
error:
|
|
365
|
+
error: {
|
|
366
|
+
type: mapErrorResponseCode(errorResponse.code)
|
|
367
|
+
},
|
|
368
368
|
resourceId
|
|
369
369
|
});
|
|
370
370
|
}
|
|
@@ -374,7 +374,9 @@ class BlockServiceADFFetchProvider {
|
|
|
374
374
|
for (const blockNodeIdentifier of blockNodeIdentifiers) {
|
|
375
375
|
if (!processedResourceIds.has(blockNodeIdentifier.resourceId)) {
|
|
376
376
|
results.push({
|
|
377
|
-
error:
|
|
377
|
+
error: {
|
|
378
|
+
type: SyncBlockError.NotFound
|
|
379
|
+
},
|
|
378
380
|
resourceId: blockNodeIdentifier.resourceId
|
|
379
381
|
});
|
|
380
382
|
}
|
|
@@ -383,7 +385,9 @@ class BlockServiceADFFetchProvider {
|
|
|
383
385
|
} catch (error) {
|
|
384
386
|
// If batch request fails, return error for all resourceIds
|
|
385
387
|
return blockNodeIdentifiers.map(blockNodeIdentifier => ({
|
|
386
|
-
error:
|
|
388
|
+
error: {
|
|
389
|
+
type: error instanceof BlockError ? mapBlockError(error) : SyncBlockError.Errored
|
|
390
|
+
},
|
|
387
391
|
resourceId: blockNodeIdentifier.resourceId
|
|
388
392
|
}));
|
|
389
393
|
}
|
|
@@ -411,6 +415,7 @@ class BlockServiceADFFetchProvider {
|
|
|
411
415
|
sourceAri: parsedData.sourceAri,
|
|
412
416
|
product: parsedData.product,
|
|
413
417
|
createdAt: parsedData.createdAt,
|
|
418
|
+
contentUpdatedAt: parsedData.contentUpdatedAt,
|
|
414
419
|
createdBy: parsedData.createdBy,
|
|
415
420
|
status: parsedData.status
|
|
416
421
|
},
|
|
@@ -521,7 +526,7 @@ class BlockServiceADFWriteProvider {
|
|
|
521
526
|
}
|
|
522
527
|
|
|
523
528
|
// soft deletes the source synced block
|
|
524
|
-
async deleteData(resourceId) {
|
|
529
|
+
async deleteData(resourceId, deleteReason) {
|
|
525
530
|
if (!this.parentId) {
|
|
526
531
|
return {
|
|
527
532
|
resourceId,
|
|
@@ -537,7 +542,8 @@ class BlockServiceADFWriteProvider {
|
|
|
537
542
|
});
|
|
538
543
|
try {
|
|
539
544
|
await deleteSyncedBlock({
|
|
540
|
-
blockAri
|
|
545
|
+
blockAri,
|
|
546
|
+
deleteReason
|
|
541
547
|
});
|
|
542
548
|
return {
|
|
543
549
|
resourceId,
|
|
@@ -74,7 +74,9 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
74
74
|
return data;
|
|
75
75
|
}, () => {
|
|
76
76
|
return {
|
|
77
|
-
error:
|
|
77
|
+
error: {
|
|
78
|
+
type: SyncBlockError.Errored
|
|
79
|
+
},
|
|
78
80
|
resourceId: blockIdentifier.resourceId
|
|
79
81
|
};
|
|
80
82
|
});
|
|
@@ -90,7 +92,9 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
90
92
|
return data;
|
|
91
93
|
}, () => {
|
|
92
94
|
return {
|
|
93
|
-
error:
|
|
95
|
+
error: {
|
|
96
|
+
type: SyncBlockError.Errored
|
|
97
|
+
},
|
|
94
98
|
resourceId: blockIdentifier.resourceId
|
|
95
99
|
};
|
|
96
100
|
});
|
|
@@ -151,7 +155,7 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
151
155
|
*
|
|
152
156
|
* @returns Array of {resourceId?: string, error?: string}.
|
|
153
157
|
*/
|
|
154
|
-
async deleteNodesData(resourceIds) {
|
|
158
|
+
async deleteNodesData(resourceIds, deletionReason) {
|
|
155
159
|
if (!this.writeProvider) {
|
|
156
160
|
return Promise.reject(new Error('Write provider not set'));
|
|
157
161
|
}
|
|
@@ -159,7 +163,7 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
159
163
|
if (!this.writeProvider) {
|
|
160
164
|
return Promise.reject('Write provider not set');
|
|
161
165
|
}
|
|
162
|
-
return this.writeProvider.deleteData(resourceId);
|
|
166
|
+
return this.writeProvider.deleteData(resourceId, deletionReason);
|
|
163
167
|
}));
|
|
164
168
|
return results.map((result, index) => {
|
|
165
169
|
if (result.status === 'fulfilled') {
|
|
@@ -372,11 +372,12 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
372
372
|
// Don't fetch for not_found error since the source is already deleted
|
|
373
373
|
const nodesToFetch = [];
|
|
374
374
|
syncBlockNodes.forEach(node => {
|
|
375
|
+
var _existingSyncBlock$er;
|
|
375
376
|
if (this.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
|
|
376
377
|
return;
|
|
377
378
|
}
|
|
378
379
|
const existingSyncBlock = this.getFromCache(node.attrs.resourceId);
|
|
379
|
-
if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : existingSyncBlock.error) === SyncBlockError.NotFound) {
|
|
380
|
+
if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : (_existingSyncBlock$er = existingSyncBlock.error) === null || _existingSyncBlock$er === void 0 ? void 0 : _existingSyncBlock$er.type) === SyncBlockError.NotFound) {
|
|
380
381
|
return;
|
|
381
382
|
}
|
|
382
383
|
nodesToFetch.push(node);
|
|
@@ -399,23 +400,21 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
399
400
|
this.syncBlockFetchDataRequests.delete(node.attrs.resourceId);
|
|
400
401
|
});
|
|
401
402
|
});
|
|
402
|
-
const resolvedData = [];
|
|
403
403
|
let hasUnexpectedError = false;
|
|
404
404
|
let hasExpectedError = false;
|
|
405
405
|
data.forEach(syncBlockInstance => {
|
|
406
406
|
if (!syncBlockInstance.resourceId) {
|
|
407
|
-
var _this$fireAnalyticsEv9;
|
|
408
|
-
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, fetchErrorPayload(syncBlockInstance.error || 'Returned sync block instance does not have resource id'));
|
|
407
|
+
var _this$fireAnalyticsEv9, _syncBlockInstance$er;
|
|
408
|
+
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, fetchErrorPayload(((_syncBlockInstance$er = syncBlockInstance.error) === null || _syncBlockInstance$er === void 0 ? void 0 : _syncBlockInstance$er.type) || 'Returned sync block instance does not have resource id'));
|
|
409
409
|
return;
|
|
410
410
|
}
|
|
411
411
|
const existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
|
|
412
412
|
const resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
|
|
413
413
|
this.updateCache(resolvedSyncBlockInstance);
|
|
414
|
-
resolvedData.push(resolvedSyncBlockInstance);
|
|
415
414
|
if (syncBlockInstance.error) {
|
|
416
415
|
var _this$fireAnalyticsEv0;
|
|
417
|
-
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, fetchErrorPayload(syncBlockInstance.error, syncBlockInstance.resourceId));
|
|
418
|
-
if (syncBlockInstance.error === SyncBlockError.NotFound || syncBlockInstance.error === SyncBlockError.Forbidden) {
|
|
416
|
+
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, fetchErrorPayload(syncBlockInstance.error.type, syncBlockInstance.resourceId));
|
|
417
|
+
if (syncBlockInstance.error.type === SyncBlockError.NotFound || syncBlockInstance.error.type === SyncBlockError.Forbidden) {
|
|
419
418
|
hasExpectedError = true;
|
|
420
419
|
} else if (syncBlockInstance.error) {
|
|
421
420
|
hasUnexpectedError = true;
|