@atlaskit/editor-synced-block-provider 4.2.9 → 4.2.11

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,19 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 4.2.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 4.2.10
10
+
11
+ ### Patch Changes
12
+
13
+ - [`becb755f01510`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/becb755f01510) -
14
+ Editor-5990: Create and delete call to block service when deleting orphan source blocks
15
+ - Updated dependencies
16
+
3
17
  ## 4.2.9
4
18
 
5
19
  ### Patch Changes
@@ -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.updateSyncedBlocks = exports.updateSyncedBlock = exports.updateReferenceSyncedBlockOnDocument = exports.isBlockContentResponse = exports.getSyncedBlockContent = exports.getReferenceSyncedBlocksByBlockAri = exports.getReferenceSyncedBlocks = exports.deleteSyncedBlock = exports.createSyncedBlock = exports.batchRetrieveSyncedBlocks = exports.BlockTimeoutError = exports.BlockError = void 0;
7
+ exports.updateSyncedBlocks = exports.updateSyncedBlock = exports.updateReferenceSyncedBlockOnDocument = exports.isBlockContentResponse = exports.getSyncedBlockContent = exports.getReferenceSyncedBlocksByBlockAri = exports.getReferenceSyncedBlocks = exports.deleteSyncedBlock = exports.createSyncedBlock = exports.batchRetrieveSyncedBlocks = exports.BlockTimeoutError = exports.BlockNotFoundError = exports.BlockError = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
@@ -226,15 +226,31 @@ var BlockError = exports.BlockError = /*#__PURE__*/function (_Error) {
226
226
  (0, _inherits2.default)(BlockError, _Error);
227
227
  return (0, _createClass2.default)(BlockError);
228
228
  }( /*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
229
- var BlockTimeoutError = exports.BlockTimeoutError = /*#__PURE__*/function (_Error2) {
230
- function BlockTimeoutError() {
229
+ /**
230
+ * Thrown when Block Service returns RESOURCE_NOT_FOUND for a block.
231
+ * This typically happens when an orphan block (e.g. from a copied page) is deleted.
232
+ * The caller should create the block first, then delete it to ensure a proper soft-delete record.
233
+ */
234
+ var BlockNotFoundError = exports.BlockNotFoundError = /*#__PURE__*/function (_Error2) {
235
+ function BlockNotFoundError() {
231
236
  var _this2;
232
- (0, _classCallCheck2.default)(this, BlockTimeoutError);
233
- _this2 = _callSuper(this, BlockTimeoutError, ['Block request timed out']);
234
- _this2.name = 'BlockTimeoutError';
237
+ (0, _classCallCheck2.default)(this, BlockNotFoundError);
238
+ _this2 = _callSuper(this, BlockNotFoundError, ['Block not found in Block Service']);
239
+ _this2.name = 'BlockNotFoundError';
235
240
  return _this2;
236
241
  }
237
- (0, _inherits2.default)(BlockTimeoutError, _Error2);
242
+ (0, _inherits2.default)(BlockNotFoundError, _Error2);
243
+ return (0, _createClass2.default)(BlockNotFoundError);
244
+ }( /*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
245
+ var BlockTimeoutError = exports.BlockTimeoutError = /*#__PURE__*/function (_Error3) {
246
+ function BlockTimeoutError() {
247
+ var _this3;
248
+ (0, _classCallCheck2.default)(this, BlockTimeoutError);
249
+ _this3 = _callSuper(this, BlockTimeoutError, ['Block request timed out']);
250
+ _this3.name = 'BlockTimeoutError';
251
+ return _this3;
252
+ }
253
+ (0, _inherits2.default)(BlockTimeoutError, _Error3);
238
254
  return (0, _createClass2.default)(BlockTimeoutError);
239
255
  }( /*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
240
256
  var getSyncedBlockContent = exports.getSyncedBlockContent = /*#__PURE__*/function () {
@@ -420,7 +436,7 @@ var deleteSyncedBlock = exports.deleteSyncedBlock = /*#__PURE__*/function () {
420
436
  _context4.next = 16;
421
437
  break;
422
438
  }
423
- return _context4.abrupt("return");
439
+ throw new BlockNotFoundError();
424
440
  case 16:
425
441
  throw new Error(result.errors.map(function (e) {
426
442
  return e.message;
@@ -1031,31 +1031,42 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1031
1031
  case 9:
1032
1032
  _context0.prev = 9;
1033
1033
  _context0.t0 = _context0["catch"](3);
1034
+ if (!(_context0.t0 instanceof _blockService.BlockNotFoundError && this.parentAri && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_8'))) {
1035
+ _context0.next = 13;
1036
+ break;
1037
+ }
1038
+ return _context0.abrupt("return", this.deleteOrphanBlock({
1039
+ blockAri: blockAri,
1040
+ resourceId: resourceId,
1041
+ parentAri: this.parentAri,
1042
+ deleteReason: deleteReason
1043
+ }));
1044
+ case 13:
1034
1045
  if (!(_context0.t0 instanceof _blockService.BlockError)) {
1035
- _context0.next = 15;
1046
+ _context0.next = 17;
1036
1047
  break;
1037
1048
  }
1038
1049
  if (!(_context0.t0.status === 404)) {
1039
- _context0.next = 14;
1050
+ _context0.next = 16;
1040
1051
  break;
1041
1052
  }
1042
1053
  return _context0.abrupt("return", {
1043
1054
  resourceId: resourceId,
1044
1055
  success: true
1045
1056
  });
1046
- case 14:
1057
+ case 16:
1047
1058
  return _context0.abrupt("return", {
1048
1059
  resourceId: resourceId,
1049
1060
  success: false,
1050
1061
  error: mapBlockError(_context0.t0)
1051
1062
  });
1052
- case 15:
1063
+ case 17:
1053
1064
  return _context0.abrupt("return", {
1054
1065
  resourceId: resourceId,
1055
1066
  success: false,
1056
1067
  error: (0, _errorHandling.stringifyError)(_context0.t0)
1057
1068
  });
1058
- case 16:
1069
+ case 18:
1059
1070
  case "end":
1060
1071
  return _context0.stop();
1061
1072
  }
@@ -1065,6 +1076,111 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1065
1076
  return _deleteData.apply(this, arguments);
1066
1077
  }
1067
1078
  return deleteData;
1079
+ }() // The block is an orphan (e.g. from a copied page) — it doesn't exist in Block Service.
1080
+ // Block Service uses soft-deletes, so we must first create the block then delete it,
1081
+ // ensuring a deletion-reason record is stored (used to display errors in reference blocks).
1082
+ }, {
1083
+ key: "deleteOrphanBlock",
1084
+ value: function () {
1085
+ var _deleteOrphanBlock = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee0(_ref7) {
1086
+ var blockAri, resourceId, parentAri, deleteReason, stepVersion;
1087
+ return _regenerator.default.wrap(function _callee0$(_context1) {
1088
+ while (1) switch (_context1.prev = _context1.next) {
1089
+ case 0:
1090
+ blockAri = _ref7.blockAri, resourceId = _ref7.resourceId, parentAri = _ref7.parentAri, deleteReason = _ref7.deleteReason;
1091
+ _context1.prev = 1;
1092
+ if (!this.getVersion) {
1093
+ _context1.next = 8;
1094
+ break;
1095
+ }
1096
+ _context1.next = 5;
1097
+ return this.getVersion();
1098
+ case 5:
1099
+ _context1.t0 = _context1.sent;
1100
+ _context1.next = 9;
1101
+ break;
1102
+ case 8:
1103
+ _context1.t0 = undefined;
1104
+ case 9:
1105
+ stepVersion = _context1.t0;
1106
+ _context1.prev = 10;
1107
+ _context1.next = 13;
1108
+ return (0, _blockService.createSyncedBlock)({
1109
+ blockAri: blockAri,
1110
+ blockInstanceId: resourceId,
1111
+ sourceAri: parentAri,
1112
+ product: this.product,
1113
+ content: '[]',
1114
+ stepVersion: stepVersion
1115
+ });
1116
+ case 13:
1117
+ _context1.next = 25;
1118
+ break;
1119
+ case 15:
1120
+ _context1.prev = 15;
1121
+ _context1.t1 = _context1["catch"](10);
1122
+ if (!(_context1.t1 instanceof Error && _context1.t1.message.includes('Conditional check failed'))) {
1123
+ _context1.next = 20;
1124
+ break;
1125
+ }
1126
+ _context1.next = 25;
1127
+ break;
1128
+ case 20:
1129
+ if (!(_context1.t1 instanceof _blockService.BlockError)) {
1130
+ _context1.next = 24;
1131
+ break;
1132
+ }
1133
+ return _context1.abrupt("return", {
1134
+ resourceId: resourceId,
1135
+ success: false,
1136
+ error: mapBlockError(_context1.t1)
1137
+ });
1138
+ case 24:
1139
+ return _context1.abrupt("return", {
1140
+ resourceId: resourceId,
1141
+ success: false,
1142
+ error: (0, _errorHandling.stringifyError)(_context1.t1)
1143
+ });
1144
+ case 25:
1145
+ _context1.next = 27;
1146
+ return (0, _blockService.deleteSyncedBlock)({
1147
+ blockAri: blockAri,
1148
+ deleteReason: deleteReason
1149
+ });
1150
+ case 27:
1151
+ return _context1.abrupt("return", {
1152
+ resourceId: resourceId,
1153
+ success: true,
1154
+ error: undefined
1155
+ });
1156
+ case 30:
1157
+ _context1.prev = 30;
1158
+ _context1.t2 = _context1["catch"](1);
1159
+ if (!(_context1.t2 instanceof _blockService.BlockError)) {
1160
+ _context1.next = 34;
1161
+ break;
1162
+ }
1163
+ return _context1.abrupt("return", {
1164
+ resourceId: resourceId,
1165
+ success: false,
1166
+ error: mapBlockError(_context1.t2)
1167
+ });
1168
+ case 34:
1169
+ return _context1.abrupt("return", {
1170
+ resourceId: resourceId,
1171
+ success: false,
1172
+ error: (0, _errorHandling.stringifyError)(_context1.t2)
1173
+ });
1174
+ case 35:
1175
+ case "end":
1176
+ return _context1.stop();
1177
+ }
1178
+ }, _callee0, this, [[1, 30], [10, 15]]);
1179
+ }));
1180
+ function deleteOrphanBlock(_x18) {
1181
+ return _deleteOrphanBlock.apply(this, arguments);
1182
+ }
1183
+ return deleteOrphanBlock;
1068
1184
  }() // the sourceId is the resourceId of the source synced block.
1069
1185
  }, {
1070
1186
  key: "generateResourceIdForReference",
@@ -1089,22 +1205,22 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1089
1205
  }, {
1090
1206
  key: "updateReferenceData",
1091
1207
  value: function () {
1092
- var _updateReferenceData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee0(blocks, noContent) {
1208
+ var _updateReferenceData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee1(blocks, noContent) {
1093
1209
  var _this2 = this;
1094
- return _regenerator.default.wrap(function _callee0$(_context1) {
1095
- while (1) switch (_context1.prev = _context1.next) {
1210
+ return _regenerator.default.wrap(function _callee1$(_context10) {
1211
+ while (1) switch (_context10.prev = _context10.next) {
1096
1212
  case 0:
1097
1213
  if (this.parentAri) {
1098
- _context1.next = 2;
1214
+ _context10.next = 2;
1099
1215
  break;
1100
1216
  }
1101
- return _context1.abrupt("return", {
1217
+ return _context10.abrupt("return", {
1102
1218
  success: false,
1103
1219
  error: _types.SyncBlockError.Errored
1104
1220
  });
1105
1221
  case 2:
1106
- _context1.prev = 2;
1107
- _context1.next = 5;
1222
+ _context10.prev = 2;
1223
+ _context10.next = 5;
1108
1224
  return (0, _blockService.updateReferenceSyncedBlockOnDocument)({
1109
1225
  documentAri: this.parentAri,
1110
1226
  blocks: blocks.map(function (block) {
@@ -1119,32 +1235,32 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1119
1235
  noContent: noContent
1120
1236
  });
1121
1237
  case 5:
1122
- return _context1.abrupt("return", {
1238
+ return _context10.abrupt("return", {
1123
1239
  success: true
1124
1240
  });
1125
1241
  case 8:
1126
- _context1.prev = 8;
1127
- _context1.t0 = _context1["catch"](2);
1128
- if (!(_context1.t0 instanceof _blockService.BlockError)) {
1129
- _context1.next = 12;
1242
+ _context10.prev = 8;
1243
+ _context10.t0 = _context10["catch"](2);
1244
+ if (!(_context10.t0 instanceof _blockService.BlockError)) {
1245
+ _context10.next = 12;
1130
1246
  break;
1131
1247
  }
1132
- return _context1.abrupt("return", {
1248
+ return _context10.abrupt("return", {
1133
1249
  success: false,
1134
- error: mapBlockError(_context1.t0)
1250
+ error: mapBlockError(_context10.t0)
1135
1251
  });
1136
1252
  case 12:
1137
- return _context1.abrupt("return", {
1253
+ return _context10.abrupt("return", {
1138
1254
  success: false,
1139
- error: (0, _errorHandling.stringifyError)(_context1.t0)
1255
+ error: (0, _errorHandling.stringifyError)(_context10.t0)
1140
1256
  });
1141
1257
  case 13:
1142
1258
  case "end":
1143
- return _context1.stop();
1259
+ return _context10.stop();
1144
1260
  }
1145
- }, _callee0, this, [[2, 8]]);
1261
+ }, _callee1, this, [[2, 8]]);
1146
1262
  }));
1147
- function updateReferenceData(_x18, _x19) {
1263
+ function updateReferenceData(_x19, _x20) {
1148
1264
  return _updateReferenceData.apply(this, arguments);
1149
1265
  }
1150
1266
  return updateReferenceData;
@@ -1152,17 +1268,17 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1152
1268
  }, {
1153
1269
  key: "writeDataBatch",
1154
1270
  value: function () {
1155
- var _writeDataBatch = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee1(data) {
1271
+ var _writeDataBatch = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(data) {
1156
1272
  var _this3 = this;
1157
1273
  var stepVersion, blockAriToResourceIdMap, blocks, response, results, successResourceIds, _iterator6, _step6, block, errorResourceIds, _iterator7, _step7, _loop2;
1158
- return _regenerator.default.wrap(function _callee1$(_context11) {
1159
- while (1) switch (_context11.prev = _context11.next) {
1274
+ return _regenerator.default.wrap(function _callee10$(_context12) {
1275
+ while (1) switch (_context12.prev = _context12.next) {
1160
1276
  case 0:
1161
1277
  if (!(!this.parentAri || !this.parentId)) {
1162
- _context11.next = 2;
1278
+ _context12.next = 2;
1163
1279
  break;
1164
1280
  }
1165
- return _context11.abrupt("return", data.map(function (block) {
1281
+ return _context12.abrupt("return", data.map(function (block) {
1166
1282
  return {
1167
1283
  error: _types.SyncBlockError.Errored,
1168
1284
  resourceId: block.resourceId
@@ -1170,20 +1286,20 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1170
1286
  }));
1171
1287
  case 2:
1172
1288
  if (!this.getVersion) {
1173
- _context11.next = 8;
1289
+ _context12.next = 8;
1174
1290
  break;
1175
1291
  }
1176
- _context11.next = 5;
1292
+ _context12.next = 5;
1177
1293
  return this.getVersion();
1178
1294
  case 5:
1179
- _context11.t0 = _context11.sent;
1180
- _context11.next = 9;
1295
+ _context12.t0 = _context12.sent;
1296
+ _context12.next = 9;
1181
1297
  break;
1182
1298
  case 8:
1183
- _context11.t0 = undefined;
1299
+ _context12.t0 = undefined;
1184
1300
  case 9:
1185
- stepVersion = _context11.t0;
1186
- _context11.prev = 10;
1301
+ stepVersion = _context12.t0;
1302
+ _context12.prev = 10;
1187
1303
  // Create a map from blockAri to original resourceId for matching responses
1188
1304
  blockAriToResourceIdMap = new Map();
1189
1305
  blocks = data.map(function (block) {
@@ -1196,12 +1312,12 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1196
1312
  stepVersion: stepVersion
1197
1313
  };
1198
1314
  });
1199
- _context11.next = 15;
1315
+ _context12.next = 15;
1200
1316
  return (0, _blockService.updateSyncedBlocks)({
1201
1317
  blocks: blocks
1202
1318
  });
1203
1319
  case 15:
1204
- response = _context11.sent;
1320
+ response = _context12.sent;
1205
1321
  results = []; // Process successful updates
1206
1322
  if (response.success) {
1207
1323
  successResourceIds = new Set(response.success.map(function (block) {
@@ -1224,7 +1340,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1224
1340
  }
1225
1341
  }
1226
1342
  if (!response.error) {
1227
- _context11.next = 36;
1343
+ _context12.next = 36;
1228
1344
  break;
1229
1345
  }
1230
1346
  errorResourceIds = new Map(response.error.map(function (err) {
@@ -1233,11 +1349,11 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1233
1349
  blockAriToResourceIdMap.get(err.blockAri) || '', mapErrorResponseCode(err.code)];
1234
1350
  }));
1235
1351
  _iterator7 = _createForOfIteratorHelper(data);
1236
- _context11.prev = 21;
1352
+ _context12.prev = 21;
1237
1353
  _loop2 = /*#__PURE__*/_regenerator.default.mark(function _loop2() {
1238
1354
  var block, error;
1239
- return _regenerator.default.wrap(function _loop2$(_context10) {
1240
- while (1) switch (_context10.prev = _context10.next) {
1355
+ return _regenerator.default.wrap(function _loop2$(_context11) {
1356
+ while (1) switch (_context11.prev = _context11.next) {
1241
1357
  case 0:
1242
1358
  block = _step7.value;
1243
1359
  error = errorResourceIds.get(block.resourceId);
@@ -1266,72 +1382,72 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1266
1382
  }
1267
1383
  case 3:
1268
1384
  case "end":
1269
- return _context10.stop();
1385
+ return _context11.stop();
1270
1386
  }
1271
1387
  }, _loop2);
1272
1388
  });
1273
1389
  _iterator7.s();
1274
1390
  case 24:
1275
1391
  if ((_step7 = _iterator7.n()).done) {
1276
- _context11.next = 28;
1392
+ _context12.next = 28;
1277
1393
  break;
1278
1394
  }
1279
- return _context11.delegateYield(_loop2(), "t1", 26);
1395
+ return _context12.delegateYield(_loop2(), "t1", 26);
1280
1396
  case 26:
1281
- _context11.next = 24;
1397
+ _context12.next = 24;
1282
1398
  break;
1283
1399
  case 28:
1284
- _context11.next = 33;
1400
+ _context12.next = 33;
1285
1401
  break;
1286
1402
  case 30:
1287
- _context11.prev = 30;
1288
- _context11.t2 = _context11["catch"](21);
1289
- _iterator7.e(_context11.t2);
1403
+ _context12.prev = 30;
1404
+ _context12.t2 = _context12["catch"](21);
1405
+ _iterator7.e(_context12.t2);
1290
1406
  case 33:
1291
- _context11.prev = 33;
1407
+ _context12.prev = 33;
1292
1408
  _iterator7.f();
1293
- return _context11.finish(33);
1409
+ return _context12.finish(33);
1294
1410
  case 36:
1295
- return _context11.abrupt("return", results);
1411
+ return _context12.abrupt("return", results);
1296
1412
  case 39:
1297
- _context11.prev = 39;
1298
- _context11.t3 = _context11["catch"](10);
1299
- if (!(_context11.t3 instanceof _blockService.BlockError)) {
1300
- _context11.next = 43;
1413
+ _context12.prev = 39;
1414
+ _context12.t3 = _context12["catch"](10);
1415
+ if (!(_context12.t3 instanceof _blockService.BlockError)) {
1416
+ _context12.next = 43;
1301
1417
  break;
1302
1418
  }
1303
- return _context11.abrupt("return", data.map(function (block) {
1419
+ return _context12.abrupt("return", data.map(function (block) {
1304
1420
  return {
1305
- error: mapBlockError(_context11.t3),
1421
+ error: mapBlockError(_context12.t3),
1306
1422
  resourceId: block.resourceId
1307
1423
  };
1308
1424
  }));
1309
1425
  case 43:
1310
- return _context11.abrupt("return", data.map(function (block) {
1426
+ return _context12.abrupt("return", data.map(function (block) {
1311
1427
  return {
1312
- error: (0, _errorHandling.stringifyError)(_context11.t3),
1428
+ error: (0, _errorHandling.stringifyError)(_context12.t3),
1313
1429
  resourceId: block.resourceId
1314
1430
  };
1315
1431
  }));
1316
1432
  case 44:
1317
1433
  case "end":
1318
- return _context11.stop();
1434
+ return _context12.stop();
1319
1435
  }
1320
- }, _callee1, this, [[10, 39], [21, 30, 33, 36]]);
1436
+ }, _callee10, this, [[10, 39], [21, 30, 33, 36]]);
1321
1437
  }));
1322
- function writeDataBatch(_x20) {
1438
+ function writeDataBatch(_x21) {
1323
1439
  return _writeDataBatch.apply(this, arguments);
1324
1440
  }
1325
1441
  return writeDataBatch;
1326
1442
  }()
1327
1443
  }]);
1328
1444
  }();
1329
- var createBlockServiceAPIProviders = function createBlockServiceAPIProviders(_ref7) {
1330
- var cloudId = _ref7.cloudId,
1331
- parentAri = _ref7.parentAri,
1332
- parentId = _ref7.parentId,
1333
- product = _ref7.product,
1334
- getVersion = _ref7.getVersion;
1445
+ var createBlockServiceAPIProviders = function createBlockServiceAPIProviders(_ref8) {
1446
+ var cloudId = _ref8.cloudId,
1447
+ parentAri = _ref8.parentAri,
1448
+ parentId = _ref8.parentId,
1449
+ product = _ref8.product,
1450
+ getVersion = _ref8.getVersion;
1335
1451
  return {
1336
1452
  fetchProvider: new BlockServiceADFFetchProvider({
1337
1453
  cloudId: cloudId,
@@ -1346,12 +1462,12 @@ var createBlockServiceAPIProviders = function createBlockServiceAPIProviders(_re
1346
1462
  })
1347
1463
  };
1348
1464
  };
1349
- var useMemoizedBlockServiceAPIProviders = exports.useMemoizedBlockServiceAPIProviders = function useMemoizedBlockServiceAPIProviders(_ref8) {
1350
- var cloudId = _ref8.cloudId,
1351
- parentAri = _ref8.parentAri,
1352
- parentId = _ref8.parentId,
1353
- product = _ref8.product,
1354
- getVersion = _ref8.getVersion;
1465
+ var useMemoizedBlockServiceAPIProviders = exports.useMemoizedBlockServiceAPIProviders = function useMemoizedBlockServiceAPIProviders(_ref9) {
1466
+ var cloudId = _ref9.cloudId,
1467
+ parentAri = _ref9.parentAri,
1468
+ parentId = _ref9.parentId,
1469
+ product = _ref9.product,
1470
+ getVersion = _ref9.getVersion;
1355
1471
  return (0, _react.useMemo)(function () {
1356
1472
  return createBlockServiceAPIProviders({
1357
1473
  cloudId: cloudId,
@@ -1362,9 +1478,9 @@ var useMemoizedBlockServiceAPIProviders = exports.useMemoizedBlockServiceAPIProv
1362
1478
  });
1363
1479
  }, [cloudId, parentAri, parentId, product, getVersion]);
1364
1480
  };
1365
- var createBlockServiceFetchOnlyAPIProvider = function createBlockServiceFetchOnlyAPIProvider(_ref9) {
1366
- var cloudId = _ref9.cloudId,
1367
- parentAri = _ref9.parentAri;
1481
+ var createBlockServiceFetchOnlyAPIProvider = function createBlockServiceFetchOnlyAPIProvider(_ref0) {
1482
+ var cloudId = _ref0.cloudId,
1483
+ parentAri = _ref0.parentAri;
1368
1484
  return {
1369
1485
  fetchProvider: new BlockServiceADFFetchProvider({
1370
1486
  cloudId: cloudId,
@@ -1377,9 +1493,9 @@ var createBlockServiceFetchOnlyAPIProvider = function createBlockServiceFetchOnl
1377
1493
  /**
1378
1494
  * If the parentAri is not a valid ARI, pass in an empty string.
1379
1495
  */
1380
- var useMemoizedBlockServiceFetchOnlyAPIProvider = exports.useMemoizedBlockServiceFetchOnlyAPIProvider = function useMemoizedBlockServiceFetchOnlyAPIProvider(_ref0) {
1381
- var cloudId = _ref0.cloudId,
1382
- parentAri = _ref0.parentAri;
1496
+ var useMemoizedBlockServiceFetchOnlyAPIProvider = exports.useMemoizedBlockServiceFetchOnlyAPIProvider = function useMemoizedBlockServiceFetchOnlyAPIProvider(_ref1) {
1497
+ var cloudId = _ref1.cloudId,
1498
+ parentAri = _ref1.parentAri;
1383
1499
  return (0, _react.useMemo)(function () {
1384
1500
  return createBlockServiceFetchOnlyAPIProvider({
1385
1501
  cloudId: cloudId,
@@ -298,6 +298,18 @@ export class BlockError extends Error {
298
298
  this.status = status;
299
299
  }
300
300
  }
301
+
302
+ /**
303
+ * Thrown when Block Service returns RESOURCE_NOT_FOUND for a block.
304
+ * This typically happens when an orphan block (e.g. from a copied page) is deleted.
305
+ * The caller should create the block first, then delete it to ensure a proper soft-delete record.
306
+ */
307
+ export class BlockNotFoundError extends Error {
308
+ constructor() {
309
+ super('Block not found in Block Service');
310
+ this.name = 'BlockNotFoundError';
311
+ }
312
+ }
301
313
  export class BlockTimeoutError extends Error {
302
314
  constructor() {
303
315
  super('Block request timed out');
@@ -404,10 +416,10 @@ export const deleteSyncedBlock = async ({
404
416
  return ((_e$extensions = e.extensions) === null || _e$extensions === void 0 ? void 0 : _e$extensions.errorType) === 'RESOURCE_NOT_FOUND';
405
417
  });
406
418
  if (allNotFound) {
407
- // do not throw an error, return early
408
- // as if the block is not found, it is likely an orphan from a page copy.
409
- // delete the synced block should just delete the block from the ADF, no need to delete it from the block service as it does not exist.
410
- return;
419
+ // Throw BlockNotFoundError so the caller can create the block first then retry the delete.
420
+ // Block Service uses soft-deletes: the entry must exist before deletion so a deletion-reason
421
+ // is stored (used to display errors in reference blocks).
422
+ throw new BlockNotFoundError();
411
423
  }
412
424
  }
413
425
  throw new Error(result.errors.map(e => e.message).join(', '));
@@ -3,7 +3,7 @@ import { useMemo } from 'react';
3
3
  import { fg } from '@atlaskit/platform-feature-flags';
4
4
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
5
5
  import { generateBlockAri, generateBlockAriFromReference } from '../../clients/block-service/ari';
6
- import { batchRetrieveSyncedBlocks, BlockError, BlockTimeoutError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getReferenceSyncedBlocksByBlockAri, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock, updateSyncedBlocks } from '../../clients/block-service/blockService';
6
+ import { batchRetrieveSyncedBlocks, BlockError, BlockNotFoundError, BlockTimeoutError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getReferenceSyncedBlocksByBlockAri, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock, updateSyncedBlocks } from '../../clients/block-service/blockService';
7
7
  import { subscribeToBlockUpdates as subscribeToBlockUpdatesWS } from '../../clients/block-service/blockSubscription';
8
8
  import { SyncBlockError } from '../../common/types';
9
9
  import { stringifyError } from '../../utils/errorHandling';
@@ -686,6 +686,14 @@ class BlockServiceADFWriteProvider {
686
686
  error: undefined
687
687
  };
688
688
  } catch (error) {
689
+ if (error instanceof BlockNotFoundError && this.parentAri && fg('platform_synced_block_patch_8')) {
690
+ return this.deleteOrphanBlock({
691
+ blockAri,
692
+ resourceId,
693
+ parentAri: this.parentAri,
694
+ deleteReason
695
+ });
696
+ }
689
697
  if (error instanceof BlockError) {
690
698
  if (error.status === 404) {
691
699
  // User should not be blocked by not_found error when deleting,
@@ -709,6 +717,71 @@ class BlockServiceADFWriteProvider {
709
717
  }
710
718
  }
711
719
 
720
+ // The block is an orphan (e.g. from a copied page) — it doesn't exist in Block Service.
721
+ // Block Service uses soft-deletes, so we must first create the block then delete it,
722
+ // ensuring a deletion-reason record is stored (used to display errors in reference blocks).
723
+ async deleteOrphanBlock({
724
+ blockAri,
725
+ resourceId,
726
+ parentAri,
727
+ deleteReason
728
+ }) {
729
+ try {
730
+ const stepVersion = this.getVersion ? await this.getVersion() : undefined;
731
+ try {
732
+ await createSyncedBlock({
733
+ blockAri,
734
+ blockInstanceId: resourceId,
735
+ sourceAri: parentAri,
736
+ product: this.product,
737
+ content: '[]',
738
+ stepVersion
739
+ });
740
+ } catch (createError) {
741
+ // "Conditional check failed" means the block already exists in Block Service.
742
+ // This can happen when an orphan block is copied and pasted — a reference block repair
743
+ // in the backend may have already created it. We can proceed directly to delete it.
744
+ if (createError instanceof Error && createError.message.includes('Conditional check failed')) {
745
+ // block already exists, proceed to delete
746
+ } else if (createError instanceof BlockError) {
747
+ return {
748
+ resourceId,
749
+ success: false,
750
+ error: mapBlockError(createError)
751
+ };
752
+ } else {
753
+ return {
754
+ resourceId,
755
+ success: false,
756
+ error: stringifyError(createError)
757
+ };
758
+ }
759
+ }
760
+ await deleteSyncedBlock({
761
+ blockAri,
762
+ deleteReason
763
+ });
764
+ return {
765
+ resourceId,
766
+ success: true,
767
+ error: undefined
768
+ };
769
+ } catch (error) {
770
+ if (error instanceof BlockError) {
771
+ return {
772
+ resourceId,
773
+ success: false,
774
+ error: mapBlockError(error)
775
+ };
776
+ }
777
+ return {
778
+ resourceId,
779
+ success: false,
780
+ error: stringifyError(error)
781
+ };
782
+ }
783
+ }
784
+
712
785
  // the sourceId is the resourceId of the source synced block.
713
786
  generateResourceIdForReference(sourceId) {
714
787
  return createResourceIdForReference(this.product, this.parentId || '', sourceId);
@@ -219,15 +219,32 @@ export var BlockError = /*#__PURE__*/function (_Error) {
219
219
  _inherits(BlockError, _Error);
220
220
  return _createClass(BlockError);
221
221
  }( /*#__PURE__*/_wrapNativeSuper(Error));
222
- export var BlockTimeoutError = /*#__PURE__*/function (_Error2) {
223
- function BlockTimeoutError() {
222
+
223
+ /**
224
+ * Thrown when Block Service returns RESOURCE_NOT_FOUND for a block.
225
+ * This typically happens when an orphan block (e.g. from a copied page) is deleted.
226
+ * The caller should create the block first, then delete it to ensure a proper soft-delete record.
227
+ */
228
+ export var BlockNotFoundError = /*#__PURE__*/function (_Error2) {
229
+ function BlockNotFoundError() {
224
230
  var _this2;
225
- _classCallCheck(this, BlockTimeoutError);
226
- _this2 = _callSuper(this, BlockTimeoutError, ['Block request timed out']);
227
- _this2.name = 'BlockTimeoutError';
231
+ _classCallCheck(this, BlockNotFoundError);
232
+ _this2 = _callSuper(this, BlockNotFoundError, ['Block not found in Block Service']);
233
+ _this2.name = 'BlockNotFoundError';
228
234
  return _this2;
229
235
  }
230
- _inherits(BlockTimeoutError, _Error2);
236
+ _inherits(BlockNotFoundError, _Error2);
237
+ return _createClass(BlockNotFoundError);
238
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
239
+ export var BlockTimeoutError = /*#__PURE__*/function (_Error3) {
240
+ function BlockTimeoutError() {
241
+ var _this3;
242
+ _classCallCheck(this, BlockTimeoutError);
243
+ _this3 = _callSuper(this, BlockTimeoutError, ['Block request timed out']);
244
+ _this3.name = 'BlockTimeoutError';
245
+ return _this3;
246
+ }
247
+ _inherits(BlockTimeoutError, _Error3);
231
248
  return _createClass(BlockTimeoutError);
232
249
  }( /*#__PURE__*/_wrapNativeSuper(Error));
233
250
  export var getSyncedBlockContent = /*#__PURE__*/function () {
@@ -413,7 +430,7 @@ export var deleteSyncedBlock = /*#__PURE__*/function () {
413
430
  _context4.next = 16;
414
431
  break;
415
432
  }
416
- return _context4.abrupt("return");
433
+ throw new BlockNotFoundError();
417
434
  case 16:
418
435
  throw new Error(result.errors.map(function (e) {
419
436
  return e.message;
@@ -14,7 +14,7 @@ import { useMemo } from 'react';
14
14
  import { fg } from '@atlaskit/platform-feature-flags';
15
15
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
16
16
  import { generateBlockAri as _generateBlockAri, generateBlockAriFromReference } from '../../clients/block-service/ari';
17
- import { batchRetrieveSyncedBlocks, BlockError, BlockTimeoutError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getReferenceSyncedBlocksByBlockAri, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock, updateSyncedBlocks } from '../../clients/block-service/blockService';
17
+ import { batchRetrieveSyncedBlocks, BlockError, BlockNotFoundError, BlockTimeoutError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getReferenceSyncedBlocksByBlockAri, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock, updateSyncedBlocks } from '../../clients/block-service/blockService';
18
18
  import { subscribeToBlockUpdates as subscribeToBlockUpdatesWS } from '../../clients/block-service/blockSubscription';
19
19
  import { SyncBlockError } from '../../common/types';
20
20
  import { stringifyError } from '../../utils/errorHandling';
@@ -1026,31 +1026,42 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1026
1026
  case 9:
1027
1027
  _context0.prev = 9;
1028
1028
  _context0.t0 = _context0["catch"](3);
1029
+ if (!(_context0.t0 instanceof BlockNotFoundError && this.parentAri && fg('platform_synced_block_patch_8'))) {
1030
+ _context0.next = 13;
1031
+ break;
1032
+ }
1033
+ return _context0.abrupt("return", this.deleteOrphanBlock({
1034
+ blockAri: blockAri,
1035
+ resourceId: resourceId,
1036
+ parentAri: this.parentAri,
1037
+ deleteReason: deleteReason
1038
+ }));
1039
+ case 13:
1029
1040
  if (!(_context0.t0 instanceof BlockError)) {
1030
- _context0.next = 15;
1041
+ _context0.next = 17;
1031
1042
  break;
1032
1043
  }
1033
1044
  if (!(_context0.t0.status === 404)) {
1034
- _context0.next = 14;
1045
+ _context0.next = 16;
1035
1046
  break;
1036
1047
  }
1037
1048
  return _context0.abrupt("return", {
1038
1049
  resourceId: resourceId,
1039
1050
  success: true
1040
1051
  });
1041
- case 14:
1052
+ case 16:
1042
1053
  return _context0.abrupt("return", {
1043
1054
  resourceId: resourceId,
1044
1055
  success: false,
1045
1056
  error: mapBlockError(_context0.t0)
1046
1057
  });
1047
- case 15:
1058
+ case 17:
1048
1059
  return _context0.abrupt("return", {
1049
1060
  resourceId: resourceId,
1050
1061
  success: false,
1051
1062
  error: stringifyError(_context0.t0)
1052
1063
  });
1053
- case 16:
1064
+ case 18:
1054
1065
  case "end":
1055
1066
  return _context0.stop();
1056
1067
  }
@@ -1060,6 +1071,111 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1060
1071
  return _deleteData.apply(this, arguments);
1061
1072
  }
1062
1073
  return deleteData;
1074
+ }() // The block is an orphan (e.g. from a copied page) — it doesn't exist in Block Service.
1075
+ // Block Service uses soft-deletes, so we must first create the block then delete it,
1076
+ // ensuring a deletion-reason record is stored (used to display errors in reference blocks).
1077
+ }, {
1078
+ key: "deleteOrphanBlock",
1079
+ value: function () {
1080
+ var _deleteOrphanBlock = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee0(_ref7) {
1081
+ var blockAri, resourceId, parentAri, deleteReason, stepVersion;
1082
+ return _regeneratorRuntime.wrap(function _callee0$(_context1) {
1083
+ while (1) switch (_context1.prev = _context1.next) {
1084
+ case 0:
1085
+ blockAri = _ref7.blockAri, resourceId = _ref7.resourceId, parentAri = _ref7.parentAri, deleteReason = _ref7.deleteReason;
1086
+ _context1.prev = 1;
1087
+ if (!this.getVersion) {
1088
+ _context1.next = 8;
1089
+ break;
1090
+ }
1091
+ _context1.next = 5;
1092
+ return this.getVersion();
1093
+ case 5:
1094
+ _context1.t0 = _context1.sent;
1095
+ _context1.next = 9;
1096
+ break;
1097
+ case 8:
1098
+ _context1.t0 = undefined;
1099
+ case 9:
1100
+ stepVersion = _context1.t0;
1101
+ _context1.prev = 10;
1102
+ _context1.next = 13;
1103
+ return createSyncedBlock({
1104
+ blockAri: blockAri,
1105
+ blockInstanceId: resourceId,
1106
+ sourceAri: parentAri,
1107
+ product: this.product,
1108
+ content: '[]',
1109
+ stepVersion: stepVersion
1110
+ });
1111
+ case 13:
1112
+ _context1.next = 25;
1113
+ break;
1114
+ case 15:
1115
+ _context1.prev = 15;
1116
+ _context1.t1 = _context1["catch"](10);
1117
+ if (!(_context1.t1 instanceof Error && _context1.t1.message.includes('Conditional check failed'))) {
1118
+ _context1.next = 20;
1119
+ break;
1120
+ }
1121
+ _context1.next = 25;
1122
+ break;
1123
+ case 20:
1124
+ if (!(_context1.t1 instanceof BlockError)) {
1125
+ _context1.next = 24;
1126
+ break;
1127
+ }
1128
+ return _context1.abrupt("return", {
1129
+ resourceId: resourceId,
1130
+ success: false,
1131
+ error: mapBlockError(_context1.t1)
1132
+ });
1133
+ case 24:
1134
+ return _context1.abrupt("return", {
1135
+ resourceId: resourceId,
1136
+ success: false,
1137
+ error: stringifyError(_context1.t1)
1138
+ });
1139
+ case 25:
1140
+ _context1.next = 27;
1141
+ return deleteSyncedBlock({
1142
+ blockAri: blockAri,
1143
+ deleteReason: deleteReason
1144
+ });
1145
+ case 27:
1146
+ return _context1.abrupt("return", {
1147
+ resourceId: resourceId,
1148
+ success: true,
1149
+ error: undefined
1150
+ });
1151
+ case 30:
1152
+ _context1.prev = 30;
1153
+ _context1.t2 = _context1["catch"](1);
1154
+ if (!(_context1.t2 instanceof BlockError)) {
1155
+ _context1.next = 34;
1156
+ break;
1157
+ }
1158
+ return _context1.abrupt("return", {
1159
+ resourceId: resourceId,
1160
+ success: false,
1161
+ error: mapBlockError(_context1.t2)
1162
+ });
1163
+ case 34:
1164
+ return _context1.abrupt("return", {
1165
+ resourceId: resourceId,
1166
+ success: false,
1167
+ error: stringifyError(_context1.t2)
1168
+ });
1169
+ case 35:
1170
+ case "end":
1171
+ return _context1.stop();
1172
+ }
1173
+ }, _callee0, this, [[1, 30], [10, 15]]);
1174
+ }));
1175
+ function deleteOrphanBlock(_x18) {
1176
+ return _deleteOrphanBlock.apply(this, arguments);
1177
+ }
1178
+ return deleteOrphanBlock;
1063
1179
  }() // the sourceId is the resourceId of the source synced block.
1064
1180
  }, {
1065
1181
  key: "generateResourceIdForReference",
@@ -1084,22 +1200,22 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1084
1200
  }, {
1085
1201
  key: "updateReferenceData",
1086
1202
  value: function () {
1087
- var _updateReferenceData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee0(blocks, noContent) {
1203
+ var _updateReferenceData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee1(blocks, noContent) {
1088
1204
  var _this2 = this;
1089
- return _regeneratorRuntime.wrap(function _callee0$(_context1) {
1090
- while (1) switch (_context1.prev = _context1.next) {
1205
+ return _regeneratorRuntime.wrap(function _callee1$(_context10) {
1206
+ while (1) switch (_context10.prev = _context10.next) {
1091
1207
  case 0:
1092
1208
  if (this.parentAri) {
1093
- _context1.next = 2;
1209
+ _context10.next = 2;
1094
1210
  break;
1095
1211
  }
1096
- return _context1.abrupt("return", {
1212
+ return _context10.abrupt("return", {
1097
1213
  success: false,
1098
1214
  error: SyncBlockError.Errored
1099
1215
  });
1100
1216
  case 2:
1101
- _context1.prev = 2;
1102
- _context1.next = 5;
1217
+ _context10.prev = 2;
1218
+ _context10.next = 5;
1103
1219
  return updateReferenceSyncedBlockOnDocument({
1104
1220
  documentAri: this.parentAri,
1105
1221
  blocks: blocks.map(function (block) {
@@ -1114,32 +1230,32 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1114
1230
  noContent: noContent
1115
1231
  });
1116
1232
  case 5:
1117
- return _context1.abrupt("return", {
1233
+ return _context10.abrupt("return", {
1118
1234
  success: true
1119
1235
  });
1120
1236
  case 8:
1121
- _context1.prev = 8;
1122
- _context1.t0 = _context1["catch"](2);
1123
- if (!(_context1.t0 instanceof BlockError)) {
1124
- _context1.next = 12;
1237
+ _context10.prev = 8;
1238
+ _context10.t0 = _context10["catch"](2);
1239
+ if (!(_context10.t0 instanceof BlockError)) {
1240
+ _context10.next = 12;
1125
1241
  break;
1126
1242
  }
1127
- return _context1.abrupt("return", {
1243
+ return _context10.abrupt("return", {
1128
1244
  success: false,
1129
- error: mapBlockError(_context1.t0)
1245
+ error: mapBlockError(_context10.t0)
1130
1246
  });
1131
1247
  case 12:
1132
- return _context1.abrupt("return", {
1248
+ return _context10.abrupt("return", {
1133
1249
  success: false,
1134
- error: stringifyError(_context1.t0)
1250
+ error: stringifyError(_context10.t0)
1135
1251
  });
1136
1252
  case 13:
1137
1253
  case "end":
1138
- return _context1.stop();
1254
+ return _context10.stop();
1139
1255
  }
1140
- }, _callee0, this, [[2, 8]]);
1256
+ }, _callee1, this, [[2, 8]]);
1141
1257
  }));
1142
- function updateReferenceData(_x18, _x19) {
1258
+ function updateReferenceData(_x19, _x20) {
1143
1259
  return _updateReferenceData.apply(this, arguments);
1144
1260
  }
1145
1261
  return updateReferenceData;
@@ -1147,17 +1263,17 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1147
1263
  }, {
1148
1264
  key: "writeDataBatch",
1149
1265
  value: function () {
1150
- var _writeDataBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee1(data) {
1266
+ var _writeDataBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(data) {
1151
1267
  var _this3 = this;
1152
1268
  var stepVersion, blockAriToResourceIdMap, blocks, response, results, successResourceIds, _iterator6, _step6, block, errorResourceIds, _iterator7, _step7, _loop2;
1153
- return _regeneratorRuntime.wrap(function _callee1$(_context11) {
1154
- while (1) switch (_context11.prev = _context11.next) {
1269
+ return _regeneratorRuntime.wrap(function _callee10$(_context12) {
1270
+ while (1) switch (_context12.prev = _context12.next) {
1155
1271
  case 0:
1156
1272
  if (!(!this.parentAri || !this.parentId)) {
1157
- _context11.next = 2;
1273
+ _context12.next = 2;
1158
1274
  break;
1159
1275
  }
1160
- return _context11.abrupt("return", data.map(function (block) {
1276
+ return _context12.abrupt("return", data.map(function (block) {
1161
1277
  return {
1162
1278
  error: SyncBlockError.Errored,
1163
1279
  resourceId: block.resourceId
@@ -1165,20 +1281,20 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1165
1281
  }));
1166
1282
  case 2:
1167
1283
  if (!this.getVersion) {
1168
- _context11.next = 8;
1284
+ _context12.next = 8;
1169
1285
  break;
1170
1286
  }
1171
- _context11.next = 5;
1287
+ _context12.next = 5;
1172
1288
  return this.getVersion();
1173
1289
  case 5:
1174
- _context11.t0 = _context11.sent;
1175
- _context11.next = 9;
1290
+ _context12.t0 = _context12.sent;
1291
+ _context12.next = 9;
1176
1292
  break;
1177
1293
  case 8:
1178
- _context11.t0 = undefined;
1294
+ _context12.t0 = undefined;
1179
1295
  case 9:
1180
- stepVersion = _context11.t0;
1181
- _context11.prev = 10;
1296
+ stepVersion = _context12.t0;
1297
+ _context12.prev = 10;
1182
1298
  // Create a map from blockAri to original resourceId for matching responses
1183
1299
  blockAriToResourceIdMap = new Map();
1184
1300
  blocks = data.map(function (block) {
@@ -1191,12 +1307,12 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1191
1307
  stepVersion: stepVersion
1192
1308
  };
1193
1309
  });
1194
- _context11.next = 15;
1310
+ _context12.next = 15;
1195
1311
  return updateSyncedBlocks({
1196
1312
  blocks: blocks
1197
1313
  });
1198
1314
  case 15:
1199
- response = _context11.sent;
1315
+ response = _context12.sent;
1200
1316
  results = []; // Process successful updates
1201
1317
  if (response.success) {
1202
1318
  successResourceIds = new Set(response.success.map(function (block) {
@@ -1219,7 +1335,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1219
1335
  }
1220
1336
  }
1221
1337
  if (!response.error) {
1222
- _context11.next = 36;
1338
+ _context12.next = 36;
1223
1339
  break;
1224
1340
  }
1225
1341
  errorResourceIds = new Map(response.error.map(function (err) {
@@ -1228,11 +1344,11 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1228
1344
  blockAriToResourceIdMap.get(err.blockAri) || '', mapErrorResponseCode(err.code)];
1229
1345
  }));
1230
1346
  _iterator7 = _createForOfIteratorHelper(data);
1231
- _context11.prev = 21;
1347
+ _context12.prev = 21;
1232
1348
  _loop2 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop2() {
1233
1349
  var block, error;
1234
- return _regeneratorRuntime.wrap(function _loop2$(_context10) {
1235
- while (1) switch (_context10.prev = _context10.next) {
1350
+ return _regeneratorRuntime.wrap(function _loop2$(_context11) {
1351
+ while (1) switch (_context11.prev = _context11.next) {
1236
1352
  case 0:
1237
1353
  block = _step7.value;
1238
1354
  error = errorResourceIds.get(block.resourceId);
@@ -1261,72 +1377,72 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
1261
1377
  }
1262
1378
  case 3:
1263
1379
  case "end":
1264
- return _context10.stop();
1380
+ return _context11.stop();
1265
1381
  }
1266
1382
  }, _loop2);
1267
1383
  });
1268
1384
  _iterator7.s();
1269
1385
  case 24:
1270
1386
  if ((_step7 = _iterator7.n()).done) {
1271
- _context11.next = 28;
1387
+ _context12.next = 28;
1272
1388
  break;
1273
1389
  }
1274
- return _context11.delegateYield(_loop2(), "t1", 26);
1390
+ return _context12.delegateYield(_loop2(), "t1", 26);
1275
1391
  case 26:
1276
- _context11.next = 24;
1392
+ _context12.next = 24;
1277
1393
  break;
1278
1394
  case 28:
1279
- _context11.next = 33;
1395
+ _context12.next = 33;
1280
1396
  break;
1281
1397
  case 30:
1282
- _context11.prev = 30;
1283
- _context11.t2 = _context11["catch"](21);
1284
- _iterator7.e(_context11.t2);
1398
+ _context12.prev = 30;
1399
+ _context12.t2 = _context12["catch"](21);
1400
+ _iterator7.e(_context12.t2);
1285
1401
  case 33:
1286
- _context11.prev = 33;
1402
+ _context12.prev = 33;
1287
1403
  _iterator7.f();
1288
- return _context11.finish(33);
1404
+ return _context12.finish(33);
1289
1405
  case 36:
1290
- return _context11.abrupt("return", results);
1406
+ return _context12.abrupt("return", results);
1291
1407
  case 39:
1292
- _context11.prev = 39;
1293
- _context11.t3 = _context11["catch"](10);
1294
- if (!(_context11.t3 instanceof BlockError)) {
1295
- _context11.next = 43;
1408
+ _context12.prev = 39;
1409
+ _context12.t3 = _context12["catch"](10);
1410
+ if (!(_context12.t3 instanceof BlockError)) {
1411
+ _context12.next = 43;
1296
1412
  break;
1297
1413
  }
1298
- return _context11.abrupt("return", data.map(function (block) {
1414
+ return _context12.abrupt("return", data.map(function (block) {
1299
1415
  return {
1300
- error: mapBlockError(_context11.t3),
1416
+ error: mapBlockError(_context12.t3),
1301
1417
  resourceId: block.resourceId
1302
1418
  };
1303
1419
  }));
1304
1420
  case 43:
1305
- return _context11.abrupt("return", data.map(function (block) {
1421
+ return _context12.abrupt("return", data.map(function (block) {
1306
1422
  return {
1307
- error: stringifyError(_context11.t3),
1423
+ error: stringifyError(_context12.t3),
1308
1424
  resourceId: block.resourceId
1309
1425
  };
1310
1426
  }));
1311
1427
  case 44:
1312
1428
  case "end":
1313
- return _context11.stop();
1429
+ return _context12.stop();
1314
1430
  }
1315
- }, _callee1, this, [[10, 39], [21, 30, 33, 36]]);
1431
+ }, _callee10, this, [[10, 39], [21, 30, 33, 36]]);
1316
1432
  }));
1317
- function writeDataBatch(_x20) {
1433
+ function writeDataBatch(_x21) {
1318
1434
  return _writeDataBatch.apply(this, arguments);
1319
1435
  }
1320
1436
  return writeDataBatch;
1321
1437
  }()
1322
1438
  }]);
1323
1439
  }();
1324
- var createBlockServiceAPIProviders = function createBlockServiceAPIProviders(_ref7) {
1325
- var cloudId = _ref7.cloudId,
1326
- parentAri = _ref7.parentAri,
1327
- parentId = _ref7.parentId,
1328
- product = _ref7.product,
1329
- getVersion = _ref7.getVersion;
1440
+ var createBlockServiceAPIProviders = function createBlockServiceAPIProviders(_ref8) {
1441
+ var cloudId = _ref8.cloudId,
1442
+ parentAri = _ref8.parentAri,
1443
+ parentId = _ref8.parentId,
1444
+ product = _ref8.product,
1445
+ getVersion = _ref8.getVersion;
1330
1446
  return {
1331
1447
  fetchProvider: new BlockServiceADFFetchProvider({
1332
1448
  cloudId: cloudId,
@@ -1341,12 +1457,12 @@ var createBlockServiceAPIProviders = function createBlockServiceAPIProviders(_re
1341
1457
  })
1342
1458
  };
1343
1459
  };
1344
- export var useMemoizedBlockServiceAPIProviders = function useMemoizedBlockServiceAPIProviders(_ref8) {
1345
- var cloudId = _ref8.cloudId,
1346
- parentAri = _ref8.parentAri,
1347
- parentId = _ref8.parentId,
1348
- product = _ref8.product,
1349
- getVersion = _ref8.getVersion;
1460
+ export var useMemoizedBlockServiceAPIProviders = function useMemoizedBlockServiceAPIProviders(_ref9) {
1461
+ var cloudId = _ref9.cloudId,
1462
+ parentAri = _ref9.parentAri,
1463
+ parentId = _ref9.parentId,
1464
+ product = _ref9.product,
1465
+ getVersion = _ref9.getVersion;
1350
1466
  return useMemo(function () {
1351
1467
  return createBlockServiceAPIProviders({
1352
1468
  cloudId: cloudId,
@@ -1357,9 +1473,9 @@ export var useMemoizedBlockServiceAPIProviders = function useMemoizedBlockServic
1357
1473
  });
1358
1474
  }, [cloudId, parentAri, parentId, product, getVersion]);
1359
1475
  };
1360
- var createBlockServiceFetchOnlyAPIProvider = function createBlockServiceFetchOnlyAPIProvider(_ref9) {
1361
- var cloudId = _ref9.cloudId,
1362
- parentAri = _ref9.parentAri;
1476
+ var createBlockServiceFetchOnlyAPIProvider = function createBlockServiceFetchOnlyAPIProvider(_ref0) {
1477
+ var cloudId = _ref0.cloudId,
1478
+ parentAri = _ref0.parentAri;
1363
1479
  return {
1364
1480
  fetchProvider: new BlockServiceADFFetchProvider({
1365
1481
  cloudId: cloudId,
@@ -1372,9 +1488,9 @@ var createBlockServiceFetchOnlyAPIProvider = function createBlockServiceFetchOnl
1372
1488
  /**
1373
1489
  * If the parentAri is not a valid ARI, pass in an empty string.
1374
1490
  */
1375
- export var useMemoizedBlockServiceFetchOnlyAPIProvider = function useMemoizedBlockServiceFetchOnlyAPIProvider(_ref0) {
1376
- var cloudId = _ref0.cloudId,
1377
- parentAri = _ref0.parentAri;
1491
+ export var useMemoizedBlockServiceFetchOnlyAPIProvider = function useMemoizedBlockServiceFetchOnlyAPIProvider(_ref1) {
1492
+ var cloudId = _ref1.cloudId,
1493
+ parentAri = _ref1.parentAri;
1378
1494
  return useMemo(function () {
1379
1495
  return createBlockServiceFetchOnlyAPIProvider({
1380
1496
  cloudId: cloudId,
@@ -134,6 +134,14 @@ export declare class BlockError extends Error {
134
134
  readonly status: number;
135
135
  constructor(status: number);
136
136
  }
137
+ /**
138
+ * Thrown when Block Service returns RESOURCE_NOT_FOUND for a block.
139
+ * This typically happens when an orphan block (e.g. from a copied page) is deleted.
140
+ * The caller should create the block first, then delete it to ensure a proper soft-delete record.
141
+ */
142
+ export declare class BlockNotFoundError extends Error {
143
+ constructor();
144
+ }
137
145
  export declare class BlockTimeoutError extends Error {
138
146
  constructor();
139
147
  }
@@ -95,6 +95,7 @@ declare class BlockServiceADFWriteProvider implements ADFWriteProvider {
95
95
  writeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
96
96
  createData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
97
97
  deleteData(resourceId: string, deleteReason: string | undefined): Promise<DeleteSyncBlockResult>;
98
+ private deleteOrphanBlock;
98
99
  generateResourceIdForReference(sourceId: ResourceId): ResourceId;
99
100
  generateResourceId(): ResourceId;
100
101
  generateBlockAri(resourceId: ResourceId): string;
@@ -134,6 +134,14 @@ export declare class BlockError extends Error {
134
134
  readonly status: number;
135
135
  constructor(status: number);
136
136
  }
137
+ /**
138
+ * Thrown when Block Service returns RESOURCE_NOT_FOUND for a block.
139
+ * This typically happens when an orphan block (e.g. from a copied page) is deleted.
140
+ * The caller should create the block first, then delete it to ensure a proper soft-delete record.
141
+ */
142
+ export declare class BlockNotFoundError extends Error {
143
+ constructor();
144
+ }
137
145
  export declare class BlockTimeoutError extends Error {
138
146
  constructor();
139
147
  }
@@ -95,6 +95,7 @@ declare class BlockServiceADFWriteProvider implements ADFWriteProvider {
95
95
  writeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
96
96
  createData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
97
97
  deleteData(resourceId: string, deleteReason: string | undefined): Promise<DeleteSyncBlockResult>;
98
+ private deleteOrphanBlock;
98
99
  generateResourceIdForReference(sourceId: ResourceId): ResourceId;
99
100
  generateResourceId(): ResourceId;
100
101
  generateBlockAri(resourceId: ResourceId): string;
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "@atlaskit/editor-prosemirror": "^7.3.0",
30
30
  "@atlaskit/node-data-provider": "^9.0.0",
31
31
  "@atlaskit/platform-feature-flags": "^1.1.0",
32
- "@atlaskit/tmp-editor-statsig": "^51.1.0",
32
+ "@atlaskit/tmp-editor-statsig": "^53.0.0",
33
33
  "@babel/runtime": "^7.0.0",
34
34
  "@compiled/react": "^0.20.0",
35
35
  "graphql-ws": "^5.14.2",
@@ -38,7 +38,7 @@
38
38
  "uuid": "^3.1.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "@atlaskit/editor-common": "^112.13.0",
41
+ "@atlaskit/editor-common": "^112.15.0",
42
42
  "react": "^18.2.0"
43
43
  },
44
44
  "devDependencies": {
@@ -81,7 +81,7 @@
81
81
  }
82
82
  },
83
83
  "name": "@atlaskit/editor-synced-block-provider",
84
- "version": "4.2.9",
84
+ "version": "4.2.11",
85
85
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
86
86
  "author": "Atlassian Pty Ltd",
87
87
  "license": "Apache-2.0",