@atlaskit/editor-synced-block-provider 2.12.1 → 2.12.3
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 +17 -0
- package/dist/cjs/clients/block-service/blockService.js +6 -5
- package/dist/cjs/clients/confluence/contentProperty.js +4 -3
- package/dist/cjs/clients/confluence/sourceInfo.js +2 -1
- package/dist/cjs/common/types.js +5 -0
- package/dist/cjs/providers/block-service/blockServiceAPI.js +81 -37
- package/dist/cjs/providers/confluence/confluenceContentAPI.js +80 -42
- package/dist/cjs/providers/syncBlockProvider.js +13 -2
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +4 -6
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +10 -12
- package/dist/cjs/utils/resolveSyncBlockInstance.js +8 -4
- package/dist/cjs/utils/retry.js +66 -0
- package/dist/cjs/utils/utils.js +1 -10
- package/dist/es2019/clients/block-service/blockService.js +6 -5
- package/dist/es2019/clients/confluence/contentProperty.js +4 -3
- package/dist/es2019/clients/confluence/sourceInfo.js +2 -1
- package/dist/es2019/common/types.js +5 -0
- package/dist/es2019/providers/block-service/blockServiceAPI.js +43 -15
- package/dist/es2019/providers/confluence/confluenceContentAPI.js +35 -10
- package/dist/es2019/providers/syncBlockProvider.js +5 -0
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +4 -6
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +11 -13
- package/dist/es2019/utils/resolveSyncBlockInstance.js +8 -4
- package/dist/es2019/utils/retry.js +26 -0
- package/dist/es2019/utils/utils.js +0 -9
- package/dist/esm/clients/block-service/blockService.js +6 -5
- package/dist/esm/clients/confluence/contentProperty.js +4 -3
- package/dist/esm/clients/confluence/sourceInfo.js +2 -1
- package/dist/esm/common/types.js +5 -0
- package/dist/esm/providers/block-service/blockServiceAPI.js +81 -37
- package/dist/esm/providers/confluence/confluenceContentAPI.js +80 -42
- package/dist/esm/providers/syncBlockProvider.js +13 -2
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +4 -6
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +11 -13
- package/dist/esm/utils/resolveSyncBlockInstance.js +8 -4
- package/dist/esm/utils/retry.js +60 -0
- package/dist/esm/utils/utils.js +0 -9
- package/dist/types/common/types.d.ts +4 -0
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +1 -0
- package/dist/types/providers/confluence/confluenceContentAPI.d.ts +1 -0
- package/dist/types/providers/syncBlockProvider.d.ts +1 -0
- package/dist/types/providers/types.d.ts +2 -0
- package/dist/types/utils/retry.d.ts +1 -0
- package/dist/types/utils/utils.d.ts +0 -1
- package/dist/types-ts4.5/common/types.d.ts +4 -0
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +1 -0
- package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +1 -0
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +1 -0
- package/dist/types-ts4.5/providers/types.d.ts +2 -0
- package/dist/types-ts4.5/utils/retry.d.ts +1 -0
- package/dist/types-ts4.5/utils/utils.d.ts +0 -1
- package/package.json +2 -2
|
@@ -10,10 +10,21 @@ import { SyncBlockError } from '../../common/types';
|
|
|
10
10
|
import { stringifyError } from '../../utils/errorHandling';
|
|
11
11
|
var mapBlockError = function mapBlockError(error) {
|
|
12
12
|
switch (error.status) {
|
|
13
|
+
case 400:
|
|
14
|
+
case 401:
|
|
15
|
+
return SyncBlockError.InvalidRequest;
|
|
13
16
|
case 403:
|
|
14
17
|
return SyncBlockError.Forbidden;
|
|
15
18
|
case 404:
|
|
16
19
|
return SyncBlockError.NotFound;
|
|
20
|
+
case 409:
|
|
21
|
+
return SyncBlockError.Conflict;
|
|
22
|
+
case 429:
|
|
23
|
+
return SyncBlockError.RateLimited;
|
|
24
|
+
case 500:
|
|
25
|
+
case 503:
|
|
26
|
+
case 504:
|
|
27
|
+
return SyncBlockError.ServerError;
|
|
17
28
|
}
|
|
18
29
|
return SyncBlockError.Errored;
|
|
19
30
|
};
|
|
@@ -203,88 +214,121 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
203
214
|
_context3.prev = 7;
|
|
204
215
|
_context3.t0 = _context3["catch"](1);
|
|
205
216
|
if (!(_context3.t0 instanceof BlockError)) {
|
|
206
|
-
_context3.next =
|
|
217
|
+
_context3.next = 11;
|
|
207
218
|
break;
|
|
208
219
|
}
|
|
209
|
-
if (!(_context3.t0.status === 404)) {
|
|
210
|
-
_context3.next = 15;
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
_context3.next = 13;
|
|
214
|
-
return createSyncedBlock({
|
|
215
|
-
blockAri: resourceId,
|
|
216
|
-
blockInstanceId: data.blockInstanceId,
|
|
217
|
-
sourceAri: this.sourceAri,
|
|
218
|
-
product: this.product,
|
|
219
|
-
content: JSON.stringify(data.content)
|
|
220
|
-
});
|
|
221
|
-
case 13:
|
|
222
|
-
_context3.next = 16;
|
|
223
|
-
break;
|
|
224
|
-
case 15:
|
|
225
220
|
return _context3.abrupt("return", {
|
|
226
221
|
error: mapBlockError(_context3.t0),
|
|
227
222
|
resourceId: resourceId
|
|
228
223
|
});
|
|
229
|
-
case
|
|
224
|
+
case 11:
|
|
230
225
|
return _context3.abrupt("return", {
|
|
231
226
|
error: stringifyError(_context3.t0),
|
|
232
227
|
resourceId: resourceId
|
|
233
228
|
});
|
|
234
|
-
case
|
|
229
|
+
case 12:
|
|
235
230
|
case "end":
|
|
236
231
|
return _context3.stop();
|
|
237
232
|
}
|
|
238
|
-
}, _callee3,
|
|
233
|
+
}, _callee3, null, [[1, 7]]);
|
|
239
234
|
}));
|
|
240
235
|
function writeData(_x3) {
|
|
241
236
|
return _writeData.apply(this, arguments);
|
|
242
237
|
}
|
|
243
238
|
return writeData;
|
|
244
|
-
}()
|
|
239
|
+
}()
|
|
245
240
|
}, {
|
|
246
|
-
key: "
|
|
241
|
+
key: "createData",
|
|
247
242
|
value: function () {
|
|
248
|
-
var
|
|
243
|
+
var _createData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(data) {
|
|
244
|
+
var resourceId;
|
|
249
245
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
250
246
|
while (1) switch (_context4.prev = _context4.next) {
|
|
251
247
|
case 0:
|
|
252
|
-
|
|
253
|
-
_context4.
|
|
248
|
+
resourceId = data.resourceId;
|
|
249
|
+
_context4.prev = 1;
|
|
250
|
+
_context4.next = 4;
|
|
251
|
+
return createSyncedBlock({
|
|
252
|
+
blockAri: resourceId,
|
|
253
|
+
blockInstanceId: data.blockInstanceId,
|
|
254
|
+
sourceAri: this.sourceAri,
|
|
255
|
+
product: this.product,
|
|
256
|
+
content: JSON.stringify(data.content)
|
|
257
|
+
});
|
|
258
|
+
case 4:
|
|
259
|
+
return _context4.abrupt("return", {
|
|
260
|
+
resourceId: resourceId
|
|
261
|
+
});
|
|
262
|
+
case 7:
|
|
263
|
+
_context4.prev = 7;
|
|
264
|
+
_context4.t0 = _context4["catch"](1);
|
|
265
|
+
if (!(_context4.t0 instanceof BlockError)) {
|
|
266
|
+
_context4.next = 11;
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
return _context4.abrupt("return", {
|
|
270
|
+
error: mapBlockError(_context4.t0),
|
|
271
|
+
resourceId: resourceId
|
|
272
|
+
});
|
|
273
|
+
case 11:
|
|
274
|
+
return _context4.abrupt("return", {
|
|
275
|
+
error: stringifyError(_context4.t0),
|
|
276
|
+
resourceId: resourceId
|
|
277
|
+
});
|
|
278
|
+
case 12:
|
|
279
|
+
case "end":
|
|
280
|
+
return _context4.stop();
|
|
281
|
+
}
|
|
282
|
+
}, _callee4, this, [[1, 7]]);
|
|
283
|
+
}));
|
|
284
|
+
function createData(_x4) {
|
|
285
|
+
return _createData.apply(this, arguments);
|
|
286
|
+
}
|
|
287
|
+
return createData;
|
|
288
|
+
}() // soft deletes the source synced block
|
|
289
|
+
}, {
|
|
290
|
+
key: "deleteData",
|
|
291
|
+
value: function () {
|
|
292
|
+
var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(resourceId) {
|
|
293
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
294
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
295
|
+
case 0:
|
|
296
|
+
_context5.prev = 0;
|
|
297
|
+
_context5.next = 3;
|
|
254
298
|
return deleteSyncedBlock({
|
|
255
299
|
blockAri: resourceId
|
|
256
300
|
});
|
|
257
301
|
case 3:
|
|
258
|
-
return
|
|
302
|
+
return _context5.abrupt("return", {
|
|
259
303
|
resourceId: resourceId,
|
|
260
304
|
success: true,
|
|
261
305
|
error: undefined
|
|
262
306
|
});
|
|
263
307
|
case 6:
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (!(
|
|
267
|
-
|
|
308
|
+
_context5.prev = 6;
|
|
309
|
+
_context5.t0 = _context5["catch"](0);
|
|
310
|
+
if (!(_context5.t0 instanceof BlockError)) {
|
|
311
|
+
_context5.next = 10;
|
|
268
312
|
break;
|
|
269
313
|
}
|
|
270
|
-
return
|
|
314
|
+
return _context5.abrupt("return", {
|
|
271
315
|
resourceId: resourceId,
|
|
272
316
|
success: false,
|
|
273
|
-
error: mapBlockError(
|
|
317
|
+
error: mapBlockError(_context5.t0)
|
|
274
318
|
});
|
|
275
319
|
case 10:
|
|
276
|
-
return
|
|
320
|
+
return _context5.abrupt("return", {
|
|
277
321
|
resourceId: resourceId,
|
|
278
322
|
success: false,
|
|
279
|
-
error: stringifyError(
|
|
323
|
+
error: stringifyError(_context5.t0)
|
|
280
324
|
});
|
|
281
325
|
case 11:
|
|
282
326
|
case "end":
|
|
283
|
-
return
|
|
327
|
+
return _context5.stop();
|
|
284
328
|
}
|
|
285
|
-
},
|
|
329
|
+
}, _callee5, null, [[0, 6]]);
|
|
286
330
|
}));
|
|
287
|
-
function deleteData(
|
|
331
|
+
function deleteData(_x5) {
|
|
288
332
|
return _deleteData.apply(this, arguments);
|
|
289
333
|
}
|
|
290
334
|
return deleteData;
|
|
@@ -254,37 +254,23 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
254
254
|
resourceId: resourceId
|
|
255
255
|
});
|
|
256
256
|
case 23:
|
|
257
|
-
if (updateResult) {
|
|
258
|
-
_context3.next = 27;
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
return _context3.abrupt("return", this.createNewContentProperty(pageId, key, syncBlockDataWithSourceDocumentAri, pageType).then(function () {
|
|
262
|
-
return {
|
|
263
|
-
resourceId: resourceId
|
|
264
|
-
};
|
|
265
|
-
}, function (error) {
|
|
266
|
-
return {
|
|
267
|
-
error: error
|
|
268
|
-
};
|
|
269
|
-
}));
|
|
270
|
-
case 27:
|
|
271
257
|
return _context3.abrupt("return", {
|
|
272
258
|
error: "Failed to update ".concat(pageType, " content property")
|
|
273
259
|
});
|
|
274
|
-
case
|
|
275
|
-
_context3.next =
|
|
260
|
+
case 24:
|
|
261
|
+
_context3.next = 29;
|
|
276
262
|
break;
|
|
277
|
-
case
|
|
278
|
-
_context3.prev =
|
|
263
|
+
case 26:
|
|
264
|
+
_context3.prev = 26;
|
|
279
265
|
_context3.t1 = _context3["catch"](9);
|
|
280
266
|
return _context3.abrupt("return", {
|
|
281
267
|
error: "Failed to write ".concat(pageType)
|
|
282
268
|
});
|
|
283
|
-
case
|
|
269
|
+
case 29:
|
|
284
270
|
case "end":
|
|
285
271
|
return _context3.stop();
|
|
286
272
|
}
|
|
287
|
-
}, _callee3, this, [[1, 5], [9,
|
|
273
|
+
}, _callee3, this, [[1, 5], [9, 26]]);
|
|
288
274
|
}));
|
|
289
275
|
function writeData(_x6) {
|
|
290
276
|
return _writeData.apply(this, arguments);
|
|
@@ -292,28 +278,80 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
292
278
|
return writeData;
|
|
293
279
|
}()
|
|
294
280
|
}, {
|
|
295
|
-
key: "
|
|
281
|
+
key: "createData",
|
|
296
282
|
value: function () {
|
|
297
|
-
var
|
|
298
|
-
var
|
|
283
|
+
var _createData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(syncBlockData) {
|
|
284
|
+
var match, resourceId, _match2, pageId, pageType, localId, key, sourceAri, syncBlockDataWithSourceDocumentAri;
|
|
299
285
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
300
286
|
while (1) switch (_context4.prev = _context4.next) {
|
|
301
287
|
case 0:
|
|
302
|
-
|
|
288
|
+
resourceId = syncBlockData.resourceId;
|
|
289
|
+
_context4.prev = 1;
|
|
303
290
|
match = getPageIdAndTypeFromConfluencePageAri(resourceId);
|
|
304
|
-
_context4.next =
|
|
291
|
+
_context4.next = 8;
|
|
305
292
|
break;
|
|
306
|
-
case
|
|
307
|
-
_context4.prev =
|
|
308
|
-
_context4.t0 = _context4["catch"](
|
|
293
|
+
case 5:
|
|
294
|
+
_context4.prev = 5;
|
|
295
|
+
_context4.t0 = _context4["catch"](1);
|
|
296
|
+
return _context4.abrupt("return", {
|
|
297
|
+
error: stringifyError(_context4.t0)
|
|
298
|
+
});
|
|
299
|
+
case 8:
|
|
300
|
+
_match2 = match, pageId = _match2.id, pageType = _match2.type;
|
|
301
|
+
_context4.prev = 9;
|
|
302
|
+
localId = getLocalIdFromConfluencePageAri(resourceId);
|
|
303
|
+
key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
304
|
+
sourceAri = getConfluencePageAri(pageId, this.config.cloudId, pageType);
|
|
305
|
+
syncBlockDataWithSourceDocumentAri = _objectSpread(_objectSpread({}, syncBlockData), {}, {
|
|
306
|
+
product: 'confluence-page',
|
|
307
|
+
sourceAri: sourceAri
|
|
308
|
+
});
|
|
309
|
+
_context4.next = 16;
|
|
310
|
+
return this.createNewContentProperty(pageId, key, syncBlockDataWithSourceDocumentAri, pageType);
|
|
311
|
+
case 16:
|
|
309
312
|
return _context4.abrupt("return", {
|
|
313
|
+
resourceId: resourceId
|
|
314
|
+
});
|
|
315
|
+
case 19:
|
|
316
|
+
_context4.prev = 19;
|
|
317
|
+
_context4.t1 = _context4["catch"](9);
|
|
318
|
+
return _context4.abrupt("return", Promise.resolve({
|
|
319
|
+
error: stringifyError(_context4.t1)
|
|
320
|
+
}));
|
|
321
|
+
case 22:
|
|
322
|
+
case "end":
|
|
323
|
+
return _context4.stop();
|
|
324
|
+
}
|
|
325
|
+
}, _callee4, this, [[1, 5], [9, 19]]);
|
|
326
|
+
}));
|
|
327
|
+
function createData(_x7) {
|
|
328
|
+
return _createData.apply(this, arguments);
|
|
329
|
+
}
|
|
330
|
+
return createData;
|
|
331
|
+
}()
|
|
332
|
+
}, {
|
|
333
|
+
key: "deleteData",
|
|
334
|
+
value: function () {
|
|
335
|
+
var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(resourceId) {
|
|
336
|
+
var deletePayload, deleteResult, match, _match3, pageId, pageType, localId, key, options, _stringifyError;
|
|
337
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
338
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
339
|
+
case 0:
|
|
340
|
+
_context5.prev = 0;
|
|
341
|
+
match = getPageIdAndTypeFromConfluencePageAri(resourceId);
|
|
342
|
+
_context5.next = 7;
|
|
343
|
+
break;
|
|
344
|
+
case 4:
|
|
345
|
+
_context5.prev = 4;
|
|
346
|
+
_context5.t0 = _context5["catch"](0);
|
|
347
|
+
return _context5.abrupt("return", {
|
|
310
348
|
resourceId: resourceId,
|
|
311
349
|
success: false,
|
|
312
|
-
error: stringifyError(
|
|
350
|
+
error: stringifyError(_context5.t0)
|
|
313
351
|
});
|
|
314
352
|
case 7:
|
|
315
|
-
|
|
316
|
-
|
|
353
|
+
_match3 = match, pageId = _match3.id, pageType = _match3.type;
|
|
354
|
+
_context5.prev = 8;
|
|
317
355
|
localId = getLocalIdFromConfluencePageAri(resourceId);
|
|
318
356
|
key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
319
357
|
options = {
|
|
@@ -322,34 +360,34 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
322
360
|
cloudId: this.config.cloudId,
|
|
323
361
|
pageType: pageType
|
|
324
362
|
};
|
|
325
|
-
|
|
363
|
+
_context5.next = 14;
|
|
326
364
|
return deleteContentProperty(options);
|
|
327
365
|
case 14:
|
|
328
|
-
deletePayload =
|
|
366
|
+
deletePayload = _context5.sent;
|
|
329
367
|
deleteResult = isBlogPageType(pageType) ? deletePayload.data.confluence.deleteBlogPostProperty : deletePayload.data.confluence.deletePageProperty;
|
|
330
|
-
|
|
368
|
+
_context5.next = 21;
|
|
331
369
|
break;
|
|
332
370
|
case 18:
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
return
|
|
371
|
+
_context5.prev = 18;
|
|
372
|
+
_context5.t1 = _context5["catch"](8);
|
|
373
|
+
return _context5.abrupt("return", {
|
|
336
374
|
resourceId: resourceId,
|
|
337
375
|
success: false,
|
|
338
|
-
error: (_stringifyError = stringifyError(
|
|
376
|
+
error: (_stringifyError = stringifyError(_context5.t1)) !== null && _stringifyError !== void 0 ? _stringifyError : "Fail to delete ".concat(pageType, " content property")
|
|
339
377
|
});
|
|
340
378
|
case 21:
|
|
341
|
-
return
|
|
379
|
+
return _context5.abrupt("return", {
|
|
342
380
|
resourceId: resourceId,
|
|
343
381
|
success: deleteResult.success,
|
|
344
382
|
error: deleteResult.errors.join()
|
|
345
383
|
});
|
|
346
384
|
case 22:
|
|
347
385
|
case "end":
|
|
348
|
-
return
|
|
386
|
+
return _context5.stop();
|
|
349
387
|
}
|
|
350
|
-
},
|
|
388
|
+
}, _callee5, this, [[0, 4], [8, 18]]);
|
|
351
389
|
}));
|
|
352
|
-
function deleteData(
|
|
390
|
+
function deleteData(_x8) {
|
|
353
391
|
return _deleteData.apply(this, arguments);
|
|
354
392
|
}
|
|
355
393
|
return deleteData;
|
|
@@ -143,7 +143,19 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
143
143
|
return _writeNodesData.apply(this, arguments);
|
|
144
144
|
}
|
|
145
145
|
return writeNodesData;
|
|
146
|
-
}()
|
|
146
|
+
}())
|
|
147
|
+
}, {
|
|
148
|
+
key: "createNodeData",
|
|
149
|
+
value: function createNodeData(data) {
|
|
150
|
+
return this.writeProvider.createData(data).then(function (result) {
|
|
151
|
+
return result;
|
|
152
|
+
}, function (error) {
|
|
153
|
+
return {
|
|
154
|
+
error: error
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
147
159
|
/**
|
|
148
160
|
* Delete the data from the write provider
|
|
149
161
|
*
|
|
@@ -151,7 +163,6 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
151
163
|
*
|
|
152
164
|
* @returns Array of {resourceId?: string, error?: string}.
|
|
153
165
|
*/
|
|
154
|
-
)
|
|
155
166
|
}, {
|
|
156
167
|
key: "deleteNodesData",
|
|
157
168
|
value: (function () {
|
|
@@ -227,17 +227,15 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
227
227
|
(_this2$fireAnalyticsE = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE === void 0 || _this2$fireAnalyticsE.call(_this2, fetchErrorPayload(syncBlockInstance.error || 'Returned sync block instance does not have resource id'));
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
230
|
+
var existingSyncBlock = _this2.getFromCache(syncBlockInstance.resourceId);
|
|
231
|
+
var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
|
|
232
|
+
_this2.updateCache(resolvedSyncBlockInstance);
|
|
233
|
+
resolvedData.push(resolvedSyncBlockInstance);
|
|
230
234
|
if (syncBlockInstance.error) {
|
|
231
235
|
var _this2$fireAnalyticsE2;
|
|
232
236
|
(_this2$fireAnalyticsE2 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE2 === void 0 || _this2$fireAnalyticsE2.call(_this2, fetchErrorPayload(syncBlockInstance.error));
|
|
233
|
-
_this2.updateCache(syncBlockInstance);
|
|
234
|
-
resolvedData.push(syncBlockInstance);
|
|
235
237
|
return;
|
|
236
238
|
}
|
|
237
|
-
var existingSyncBlock = _this2.getFromCache(syncBlockInstance.resourceId);
|
|
238
|
-
var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
|
|
239
|
-
_this2.updateCache(resolvedSyncBlockInstance);
|
|
240
|
-
resolvedData.push(resolvedSyncBlockInstance);
|
|
241
239
|
_this2.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
242
240
|
});
|
|
243
241
|
return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
|
|
@@ -7,7 +7,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
7
7
|
import uuid from 'uuid';
|
|
8
8
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
9
9
|
import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload } from '../utils/errorHandling';
|
|
10
|
-
import { convertSyncBlockPMNodeToSyncBlockData
|
|
10
|
+
import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
|
|
11
11
|
// A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
|
|
12
12
|
// Designed to manage local in-memory state and synchronize with an external data provider.
|
|
13
13
|
// Supports create, flush, and delete operations for source sync blocks.
|
|
@@ -233,21 +233,19 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
233
233
|
}
|
|
234
234
|
var resourceId = attrs.resourceId,
|
|
235
235
|
blockInstanceId = attrs.localId;
|
|
236
|
-
this.dataProvider.
|
|
236
|
+
this.dataProvider.createNodeData({
|
|
237
237
|
content: [],
|
|
238
238
|
blockInstanceId: blockInstanceId,
|
|
239
239
|
resourceId: resourceId
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
});
|
|
240
|
+
}).then(function (result) {
|
|
241
|
+
var resourceId = result.resourceId;
|
|
242
|
+
if (resourceId) {
|
|
243
|
+
_this4.commitPendingCreation(true);
|
|
244
|
+
} else {
|
|
245
|
+
var _this4$fireAnalyticsE;
|
|
246
|
+
_this4.commitPendingCreation(false);
|
|
247
|
+
(_this4$fireAnalyticsE = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE === void 0 || _this4$fireAnalyticsE.call(_this4, createErrorPayload(result.error || 'Failed to create bodied sync block'));
|
|
248
|
+
}
|
|
251
249
|
}).catch(function (error) {
|
|
252
250
|
var _this4$fireAnalyticsE2;
|
|
253
251
|
_this4.commitPendingCreation(false);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import { SyncBlockError } from '../common/types';
|
|
4
5
|
/**
|
|
5
6
|
* Merges two SyncBlockInstance objects,
|
|
6
7
|
* currently it only preserves the sourceURL from the old result,
|
|
@@ -13,13 +14,16 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
13
14
|
*/
|
|
14
15
|
export var resolveSyncBlockInstance = function resolveSyncBlockInstance(oldResult, newResult) {
|
|
15
16
|
var _newResult$data, _oldResult$data, _newResult$data2, _oldResult$data2;
|
|
16
|
-
// if the old result has no data, we
|
|
17
|
+
// if the old result has no data, we simply return the new result
|
|
17
18
|
if (!oldResult.data) {
|
|
18
19
|
return newResult;
|
|
19
20
|
} else if (!newResult.data) {
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
// return the old result if there was an error, e.g. network error, but not if not found or forbidden
|
|
22
|
+
if (newResult.error === SyncBlockError.NotFound || newResult.error === SyncBlockError.Forbidden) {
|
|
23
|
+
return newResult;
|
|
24
|
+
} else {
|
|
25
|
+
return oldResult;
|
|
26
|
+
}
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
// otherwise, we merge the two results, preserving the sourceURL and sourceTitle from the old result if it exists
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
var parseRetryAfter = function parseRetryAfter(retryAfter) {
|
|
4
|
+
var newDelay;
|
|
5
|
+
|
|
6
|
+
// retryAfter can either be in ms or HTTP date
|
|
7
|
+
var parsedRetryAfter = parseInt(retryAfter);
|
|
8
|
+
if (!isNaN(parsedRetryAfter)) {
|
|
9
|
+
newDelay = parsedRetryAfter * 1000;
|
|
10
|
+
} else {
|
|
11
|
+
var retryDate = new Date(retryAfter);
|
|
12
|
+
var delayFromDate = retryDate.getTime() - Date.now();
|
|
13
|
+
if (delayFromDate > 0) {
|
|
14
|
+
newDelay = delayFromDate;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return newDelay;
|
|
18
|
+
};
|
|
19
|
+
var _fetchWithRetry = /*#__PURE__*/function () {
|
|
20
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(url, options) {
|
|
21
|
+
var retriesRemaining,
|
|
22
|
+
delay,
|
|
23
|
+
response,
|
|
24
|
+
shouldRetry,
|
|
25
|
+
retryAfter,
|
|
26
|
+
_args = arguments;
|
|
27
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
28
|
+
while (1) switch (_context.prev = _context.next) {
|
|
29
|
+
case 0:
|
|
30
|
+
retriesRemaining = _args.length > 2 && _args[2] !== undefined ? _args[2] : 3;
|
|
31
|
+
delay = _args.length > 3 && _args[3] !== undefined ? _args[3] : 1000;
|
|
32
|
+
_context.next = 4;
|
|
33
|
+
return fetch(url, options);
|
|
34
|
+
case 4:
|
|
35
|
+
response = _context.sent;
|
|
36
|
+
shouldRetry = !response.ok && response.status === 429 && retriesRemaining > 1;
|
|
37
|
+
if (shouldRetry) {
|
|
38
|
+
_context.next = 8;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
return _context.abrupt("return", response);
|
|
42
|
+
case 8:
|
|
43
|
+
retryAfter = response.headers.get('Retry-After');
|
|
44
|
+
_context.next = 11;
|
|
45
|
+
return new Promise(function (resolve) {
|
|
46
|
+
return setTimeout(resolve, retryAfter ? parseRetryAfter(retryAfter) : delay);
|
|
47
|
+
});
|
|
48
|
+
case 11:
|
|
49
|
+
return _context.abrupt("return", _fetchWithRetry(url, options, retriesRemaining - 1, delay * 2));
|
|
50
|
+
case 12:
|
|
51
|
+
case "end":
|
|
52
|
+
return _context.stop();
|
|
53
|
+
}
|
|
54
|
+
}, _callee);
|
|
55
|
+
}));
|
|
56
|
+
return function fetchWithRetry(_x, _x2) {
|
|
57
|
+
return _ref.apply(this, arguments);
|
|
58
|
+
};
|
|
59
|
+
}();
|
|
60
|
+
export { _fetchWithRetry as fetchWithRetry };
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -14,15 +14,6 @@ export var createSyncBlockNode = function createSyncBlockNode(localId, resourceI
|
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
|
-
export var createBodiedSyncBlockNode = function createBodiedSyncBlockNode(localId, resourceId) {
|
|
18
|
-
return {
|
|
19
|
-
type: 'bodiedSyncBlock',
|
|
20
|
-
attrs: {
|
|
21
|
-
localId: localId,
|
|
22
|
-
resourceId: resourceId
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
17
|
export var convertSyncBlockJSONNodeToSyncBlockNode = function convertSyncBlockJSONNodeToSyncBlockNode(node) {
|
|
27
18
|
if (node.type !== 'syncBlock' || !node.attrs || !('localId' in node.attrs) || !('resourceId' in node.attrs) || typeof node.attrs.localId !== 'string' || typeof node.attrs.resourceId !== 'string') {
|
|
28
19
|
return undefined;
|
|
@@ -16,6 +16,10 @@ export declare enum SyncBlockError {
|
|
|
16
16
|
Errored = "errored",
|
|
17
17
|
NotFound = "not_found",
|
|
18
18
|
Forbidden = "forbidden",
|
|
19
|
+
InvalidRequest = "invalid_request",
|
|
20
|
+
RateLimited = "rate_limited",
|
|
21
|
+
Conflict = "conflict",// attempt to create block that already exists
|
|
22
|
+
ServerError = "server_error",
|
|
19
23
|
InvalidContent = "invalid_content"
|
|
20
24
|
}
|
|
21
25
|
export interface SyncBlockData {
|
|
@@ -15,6 +15,7 @@ declare class BlockServiceADFWriteProvider implements ADFWriteProvider {
|
|
|
15
15
|
private product;
|
|
16
16
|
constructor(sourceAri: string, product: SyncBlockProduct);
|
|
17
17
|
writeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
|
|
18
|
+
createData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
|
|
18
19
|
deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
|
|
19
20
|
generateResourceId(sourceAri: string, localId: string): string;
|
|
20
21
|
}
|
|
@@ -23,6 +23,7 @@ declare class ConfluenceADFWriteProvider implements ADFWriteProvider {
|
|
|
23
23
|
constructor(config: ContentAPIConfig);
|
|
24
24
|
private createNewContentProperty;
|
|
25
25
|
writeData(syncBlockData: SyncBlockData): Promise<WriteSyncBlockResult>;
|
|
26
|
+
createData(syncBlockData: SyncBlockData): Promise<WriteSyncBlockResult>;
|
|
26
27
|
deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
|
|
27
28
|
generateResourceId(sourceId: string, localId: string): string;
|
|
28
29
|
}
|
|
@@ -51,6 +51,7 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
51
51
|
* resourceId: resource id of the node if write successfully , error: reason for when write failed
|
|
52
52
|
*/
|
|
53
53
|
writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<WriteSyncBlockResult>>;
|
|
54
|
+
createNodeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
|
|
54
55
|
/**
|
|
55
56
|
* Delete the data from the write provider
|
|
56
57
|
*
|
|
@@ -40,6 +40,7 @@ export interface ADFFetchProvider {
|
|
|
40
40
|
fetchData: (resourceId: ResourceId) => Promise<SyncBlockInstance>;
|
|
41
41
|
}
|
|
42
42
|
export interface ADFWriteProvider {
|
|
43
|
+
createData: (data: SyncBlockData) => Promise<WriteSyncBlockResult>;
|
|
43
44
|
deleteData: (resourceId: ResourceId) => Promise<DeleteSyncBlockResult>;
|
|
44
45
|
generateResourceId: (sourceId: string, localId: string) => ResourceId;
|
|
45
46
|
writeData: (data: SyncBlockData) => Promise<WriteSyncBlockResult>;
|
|
@@ -63,6 +64,7 @@ export type SyncedBlockRendererProviderOptions = {
|
|
|
63
64
|
};
|
|
64
65
|
export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, SyncBlockInstance> {
|
|
65
66
|
abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<WriteSyncBlockResult>>;
|
|
67
|
+
abstract createNodeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
|
|
66
68
|
abstract deleteNodesData(resourceIds: string[]): Promise<Array<DeleteSyncBlockResult>>;
|
|
67
69
|
abstract getSourceId(): ResourceId;
|
|
68
70
|
abstract fetchSyncBlockSourceInfo(localId: BlockInstanceId, sourceAri: string, sourceProduct: SyncBlockProduct, fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void): Promise<SyncBlockSourceInfo | undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fetchWithRetry: (url: string, options: RequestInit, retriesRemaining?: number, delay?: number) => Promise<Response>;
|
|
@@ -3,7 +3,6 @@ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
|
3
3
|
import type { SyncBlockData, BlockInstanceId, ResourceId, SyncBlockNode } from '../common/types';
|
|
4
4
|
export declare const convertSyncBlockPMNodeToSyncBlockData: (node: PMNode) => SyncBlockData;
|
|
5
5
|
export declare const createSyncBlockNode: (localId: BlockInstanceId, resourceId: ResourceId) => SyncBlockNode;
|
|
6
|
-
export declare const createBodiedSyncBlockNode: (localId: BlockInstanceId, resourceId: ResourceId) => SyncBlockNode;
|
|
7
6
|
export declare const convertSyncBlockJSONNodeToSyncBlockNode: (node: JSONNode) => SyncBlockNode | undefined;
|
|
8
7
|
export declare const convertPMNodeToSyncBlockNode: (node: PMNode) => SyncBlockNode | undefined;
|
|
9
8
|
export declare const convertPMNodesToSyncBlockNodes: (nodes: PMNode[]) => SyncBlockNode[];
|
|
@@ -16,6 +16,10 @@ export declare enum SyncBlockError {
|
|
|
16
16
|
Errored = "errored",
|
|
17
17
|
NotFound = "not_found",
|
|
18
18
|
Forbidden = "forbidden",
|
|
19
|
+
InvalidRequest = "invalid_request",
|
|
20
|
+
RateLimited = "rate_limited",
|
|
21
|
+
Conflict = "conflict",// attempt to create block that already exists
|
|
22
|
+
ServerError = "server_error",
|
|
19
23
|
InvalidContent = "invalid_content"
|
|
20
24
|
}
|
|
21
25
|
export interface SyncBlockData {
|
|
@@ -15,6 +15,7 @@ declare class BlockServiceADFWriteProvider implements ADFWriteProvider {
|
|
|
15
15
|
private product;
|
|
16
16
|
constructor(sourceAri: string, product: SyncBlockProduct);
|
|
17
17
|
writeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
|
|
18
|
+
createData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
|
|
18
19
|
deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
|
|
19
20
|
generateResourceId(sourceAri: string, localId: string): string;
|
|
20
21
|
}
|