@atlaskit/editor-synced-block-provider 2.12.2 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/clients/block-service/ari.js +26 -9
  3. package/dist/cjs/clients/block-service/blockService.js +6 -5
  4. package/dist/cjs/clients/confluence/contentProperty.js +4 -3
  5. package/dist/cjs/clients/confluence/sourceInfo.js +2 -1
  6. package/dist/cjs/common/types.js +5 -0
  7. package/dist/cjs/index.js +12 -6
  8. package/dist/cjs/providers/block-service/blockServiceAPI.js +79 -49
  9. package/dist/cjs/providers/confluence/confluenceContentAPI.js +6 -0
  10. package/dist/cjs/providers/syncBlockProvider.js +18 -8
  11. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +8 -0
  12. package/dist/cjs/utils/resolveSyncBlockInstance.js +3 -3
  13. package/dist/cjs/utils/retry.js +66 -0
  14. package/dist/es2019/clients/block-service/ari.js +25 -8
  15. package/dist/es2019/clients/block-service/blockService.js +6 -5
  16. package/dist/es2019/clients/confluence/contentProperty.js +4 -3
  17. package/dist/es2019/clients/confluence/sourceInfo.js +2 -1
  18. package/dist/es2019/common/types.js +5 -0
  19. package/dist/es2019/index.js +1 -1
  20. package/dist/es2019/providers/block-service/blockServiceAPI.js +43 -13
  21. package/dist/es2019/providers/confluence/confluenceContentAPI.js +4 -0
  22. package/dist/es2019/providers/syncBlockProvider.js +6 -0
  23. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +6 -0
  24. package/dist/es2019/utils/resolveSyncBlockInstance.js +3 -3
  25. package/dist/es2019/utils/retry.js +26 -0
  26. package/dist/esm/clients/block-service/ari.js +25 -8
  27. package/dist/esm/clients/block-service/blockService.js +6 -5
  28. package/dist/esm/clients/confluence/contentProperty.js +4 -3
  29. package/dist/esm/clients/confluence/sourceInfo.js +2 -1
  30. package/dist/esm/common/types.js +5 -0
  31. package/dist/esm/index.js +1 -1
  32. package/dist/esm/providers/block-service/blockServiceAPI.js +79 -50
  33. package/dist/esm/providers/confluence/confluenceContentAPI.js +6 -0
  34. package/dist/esm/providers/syncBlockProvider.js +18 -8
  35. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +8 -0
  36. package/dist/esm/utils/resolveSyncBlockInstance.js +3 -3
  37. package/dist/esm/utils/retry.js +60 -0
  38. package/dist/types/clients/block-service/ari.d.ts +13 -5
  39. package/dist/types/common/types.d.ts +7 -0
  40. package/dist/types/index.d.ts +1 -1
  41. package/dist/types/providers/block-service/blockServiceAPI.d.ts +6 -3
  42. package/dist/types/providers/confluence/confluenceContentAPI.d.ts +3 -1
  43. package/dist/types/providers/syncBlockProvider.d.ts +2 -0
  44. package/dist/types/providers/types.d.ts +7 -0
  45. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +1 -0
  46. package/dist/types/utils/retry.d.ts +1 -0
  47. package/dist/types-ts4.5/clients/block-service/ari.d.ts +13 -5
  48. package/dist/types-ts4.5/common/types.d.ts +7 -0
  49. package/dist/types-ts4.5/index.d.ts +1 -1
  50. package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +6 -3
  51. package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +3 -1
  52. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +2 -0
  53. package/dist/types-ts4.5/providers/types.d.ts +7 -0
  54. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +1 -0
  55. package/dist/types-ts4.5/utils/retry.d.ts +1 -0
  56. package/package.json +2 -2
@@ -3,17 +3,29 @@ import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
4
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
5
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
+ /* eslint-disable require-unicode-regexp */
6
7
  import { useMemo } from 'react';
7
- import { blockResourceIdFromSourceAndLocalId, getLocalIdFromBlockResourceId } from '../../clients/block-service/ari';
8
+ import { generateBlockAri, generateBlockAriFromReference } from '../../clients/block-service/ari';
8
9
  import { BlockError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getSyncedBlockContent, updateSyncedBlock } from '../../clients/block-service/blockService';
9
10
  import { SyncBlockError } from '../../common/types';
10
11
  import { stringifyError } from '../../utils/errorHandling';
11
12
  var mapBlockError = function mapBlockError(error) {
12
13
  switch (error.status) {
14
+ case 400:
15
+ case 401:
16
+ return SyncBlockError.InvalidRequest;
13
17
  case 403:
14
18
  return SyncBlockError.Forbidden;
15
19
  case 404:
16
20
  return SyncBlockError.NotFound;
21
+ case 409:
22
+ return SyncBlockError.Conflict;
23
+ case 429:
24
+ return SyncBlockError.RateLimited;
25
+ case 500:
26
+ case 503:
27
+ case 504:
28
+ return SyncBlockError.ServerError;
17
29
  }
18
30
  return SyncBlockError.Errored;
19
31
  };
@@ -97,24 +109,26 @@ export var fetchReferences = /*#__PURE__*/function () {
97
109
  * ADFFetchProvider implementation that fetches synced block data from Block Service API
98
110
  */
99
111
  var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
100
- function BlockServiceADFFetchProvider() {
112
+ function BlockServiceADFFetchProvider(sourceAri) {
101
113
  _classCallCheck(this, BlockServiceADFFetchProvider);
114
+ this.sourceAri = sourceAri;
102
115
  }
116
+
117
+ // resourceId of the reference synced block.
118
+ // the ARI must be constructed to call the block service API
103
119
  return _createClass(BlockServiceADFFetchProvider, [{
104
120
  key: "fetchData",
105
- value: // resourceId is the ARI of the block. E.G ari:cloud:blocks:site-123:synced-block/uuid-456
106
- // in the content API provider, this was the concatenation of the source document's ARI and the local ID. E.G ari:cloud:confluence:site-123:page/pageId/uuid-456
107
- function () {
121
+ value: function () {
108
122
  var _fetchData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceId) {
109
- var localId, blockContentResponse, value, syncedBlockData;
123
+ var blockAri, blockContentResponse, value, syncedBlockData;
110
124
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
111
125
  while (1) switch (_context2.prev = _context2.next) {
112
126
  case 0:
113
- localId = getLocalIdFromBlockResourceId(resourceId);
127
+ blockAri = generateBlockAriFromReference(this.sourceAri, resourceId);
114
128
  _context2.prev = 1;
115
129
  _context2.next = 4;
116
130
  return getSyncedBlockContent({
117
- blockAri: resourceId
131
+ blockAri: blockAri
118
132
  });
119
133
  case 4:
120
134
  blockContentResponse = _context2.sent;
@@ -133,8 +147,9 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
133
147
  return _context2.abrupt("return", {
134
148
  data: {
135
149
  content: syncedBlockData,
136
- resourceId: resourceId,
137
- blockInstanceId: localId,
150
+ resourceId: blockAri,
151
+ blockInstanceId: blockContentResponse.blockInstanceId,
152
+ // this was the node's localId, but has become the resourceId.
138
153
  sourceAri: blockContentResponse.sourceAri,
139
154
  product: blockContentResponse.product
140
155
  },
@@ -160,7 +175,7 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
160
175
  case "end":
161
176
  return _context2.stop();
162
177
  }
163
- }, _callee2, null, [[1, 12]]);
178
+ }, _callee2, this, [[1, 12]]);
164
179
  }));
165
180
  function fetchData(_x2) {
166
181
  return _fetchData.apply(this, arguments);
@@ -184,42 +199,43 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
184
199
  key: "writeData",
185
200
  value: function () {
186
201
  var _writeData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(data) {
187
- var resourceId;
202
+ var resourceId, blockAri;
188
203
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
189
204
  while (1) switch (_context3.prev = _context3.next) {
190
205
  case 0:
191
206
  resourceId = data.resourceId;
192
- _context3.prev = 1;
193
- _context3.next = 4;
207
+ blockAri = generateBlockAri(this.sourceAri, resourceId, this.product);
208
+ _context3.prev = 2;
209
+ _context3.next = 5;
194
210
  return updateSyncedBlock({
195
- blockAri: resourceId,
211
+ blockAri: blockAri,
196
212
  content: JSON.stringify(data.content)
197
213
  });
198
- case 4:
214
+ case 5:
199
215
  return _context3.abrupt("return", {
200
216
  resourceId: resourceId
201
217
  });
202
- case 7:
203
- _context3.prev = 7;
204
- _context3.t0 = _context3["catch"](1);
218
+ case 8:
219
+ _context3.prev = 8;
220
+ _context3.t0 = _context3["catch"](2);
205
221
  if (!(_context3.t0 instanceof BlockError)) {
206
- _context3.next = 11;
222
+ _context3.next = 12;
207
223
  break;
208
224
  }
209
225
  return _context3.abrupt("return", {
210
226
  error: mapBlockError(_context3.t0),
211
227
  resourceId: resourceId
212
228
  });
213
- case 11:
229
+ case 12:
214
230
  return _context3.abrupt("return", {
215
231
  error: stringifyError(_context3.t0),
216
232
  resourceId: resourceId
217
233
  });
218
- case 12:
234
+ case 13:
219
235
  case "end":
220
236
  return _context3.stop();
221
237
  }
222
- }, _callee3, null, [[1, 7]]);
238
+ }, _callee3, this, [[2, 8]]);
223
239
  }));
224
240
  function writeData(_x3) {
225
241
  return _writeData.apply(this, arguments);
@@ -230,45 +246,46 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
230
246
  key: "createData",
231
247
  value: function () {
232
248
  var _createData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(data) {
233
- var resourceId;
249
+ var resourceId, blockAri;
234
250
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
235
251
  while (1) switch (_context4.prev = _context4.next) {
236
252
  case 0:
237
253
  resourceId = data.resourceId;
238
- _context4.prev = 1;
239
- _context4.next = 4;
254
+ blockAri = generateBlockAri(this.sourceAri, resourceId, this.product);
255
+ _context4.prev = 2;
256
+ _context4.next = 5;
240
257
  return createSyncedBlock({
241
- blockAri: resourceId,
258
+ blockAri: blockAri,
242
259
  blockInstanceId: data.blockInstanceId,
243
260
  sourceAri: this.sourceAri,
244
261
  product: this.product,
245
262
  content: JSON.stringify(data.content)
246
263
  });
247
- case 4:
264
+ case 5:
248
265
  return _context4.abrupt("return", {
249
266
  resourceId: resourceId
250
267
  });
251
- case 7:
252
- _context4.prev = 7;
253
- _context4.t0 = _context4["catch"](1);
268
+ case 8:
269
+ _context4.prev = 8;
270
+ _context4.t0 = _context4["catch"](2);
254
271
  if (!(_context4.t0 instanceof BlockError)) {
255
- _context4.next = 11;
272
+ _context4.next = 12;
256
273
  break;
257
274
  }
258
275
  return _context4.abrupt("return", {
259
276
  error: mapBlockError(_context4.t0),
260
277
  resourceId: resourceId
261
278
  });
262
- case 11:
279
+ case 12:
263
280
  return _context4.abrupt("return", {
264
281
  error: stringifyError(_context4.t0),
265
282
  resourceId: resourceId
266
283
  });
267
- case 12:
284
+ case 13:
268
285
  case "end":
269
286
  return _context4.stop();
270
287
  }
271
- }, _callee4, this, [[1, 7]]);
288
+ }, _callee4, this, [[2, 8]]);
272
289
  }));
273
290
  function createData(_x4) {
274
291
  return _createData.apply(this, arguments);
@@ -279,25 +296,27 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
279
296
  key: "deleteData",
280
297
  value: function () {
281
298
  var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(resourceId) {
299
+ var blockAri;
282
300
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
283
301
  while (1) switch (_context5.prev = _context5.next) {
284
302
  case 0:
285
- _context5.prev = 0;
286
- _context5.next = 3;
303
+ blockAri = generateBlockAri(this.sourceAri, resourceId, this.product);
304
+ _context5.prev = 1;
305
+ _context5.next = 4;
287
306
  return deleteSyncedBlock({
288
- blockAri: resourceId
307
+ blockAri: blockAri
289
308
  });
290
- case 3:
309
+ case 4:
291
310
  return _context5.abrupt("return", {
292
311
  resourceId: resourceId,
293
312
  success: true,
294
313
  error: undefined
295
314
  });
296
- case 6:
297
- _context5.prev = 6;
298
- _context5.t0 = _context5["catch"](0);
315
+ case 7:
316
+ _context5.prev = 7;
317
+ _context5.t0 = _context5["catch"](1);
299
318
  if (!(_context5.t0 instanceof BlockError)) {
300
- _context5.next = 10;
319
+ _context5.next = 11;
301
320
  break;
302
321
  }
303
322
  return _context5.abrupt("return", {
@@ -305,27 +324,37 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
305
324
  success: false,
306
325
  error: mapBlockError(_context5.t0)
307
326
  });
308
- case 10:
327
+ case 11:
309
328
  return _context5.abrupt("return", {
310
329
  resourceId: resourceId,
311
330
  success: false,
312
331
  error: stringifyError(_context5.t0)
313
332
  });
314
- case 11:
333
+ case 12:
315
334
  case "end":
316
335
  return _context5.stop();
317
336
  }
318
- }, _callee5, null, [[0, 6]]);
337
+ }, _callee5, this, [[1, 7]]);
319
338
  }));
320
339
  function deleteData(_x5) {
321
340
  return _deleteData.apply(this, arguments);
322
341
  }
323
342
  return deleteData;
324
- }()
343
+ }() // the sourceId is the resourceId of the source synced block.
344
+ }, {
345
+ key: "generateResourceIdForReference",
346
+ value: function generateResourceIdForReference(sourceId) {
347
+ var match = this.sourceAri.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/(\d+)/);
348
+ if (!(match !== null && match !== void 0 && match[1])) {
349
+ throw new Error("Invalid source ARI: ".concat(this.sourceAri));
350
+ }
351
+ var pageId = match[3];
352
+ return "".concat(this.product, "/").concat(pageId, "/").concat(sourceId);
353
+ }
325
354
  }, {
326
355
  key: "generateResourceId",
327
- value: function generateResourceId(sourceAri, localId) {
328
- return blockResourceIdFromSourceAndLocalId(sourceAri, localId);
356
+ value: function generateResourceId() {
357
+ return crypto.randomUUID();
329
358
  }
330
359
  }]);
331
360
  }();
@@ -333,7 +362,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
333
362
  * Factory function to create both providers with shared configuration
334
363
  */
335
364
  var createBlockServiceAPIProviders = function createBlockServiceAPIProviders(sourceAri, product) {
336
- var fetchProvider = new BlockServiceADFFetchProvider();
365
+ var fetchProvider = new BlockServiceADFFetchProvider(sourceAri);
337
366
  var writeProvider = new BlockServiceADFWriteProvider(sourceAri, product);
338
367
  return {
339
368
  fetchProvider: fetchProvider,
@@ -149,6 +149,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
149
149
  function ConfluenceADFWriteProvider(config) {
150
150
  var _this = this;
151
151
  _classCallCheck(this, ConfluenceADFWriteProvider);
152
+ _defineProperty(this, "product", 'confluence-page');
152
153
  _defineProperty(this, "createNewContentProperty", /*#__PURE__*/function () {
153
154
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(pageId, key, value, pageType) {
154
155
  var options, _contentProperty$data3, contentProperty, _contentProperty2$dat, _contentProperty2;
@@ -397,6 +398,11 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
397
398
  value: function generateResourceId(sourceId, localId) {
398
399
  return resourceIdFromConfluencePageSourceIdAndLocalId(sourceId, localId);
399
400
  }
401
+ }, {
402
+ key: "generateResourceIdForReference",
403
+ value: function generateResourceIdForReference(sourceId) {
404
+ return sourceId;
405
+ }
400
406
  }]);
401
407
  }();
402
408
  /**
@@ -36,16 +36,21 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
36
36
  _this.providerOptions = providerOptions;
37
37
  return _this;
38
38
  }
39
-
40
- /**
41
- * Check if the node is supported by the provider
42
- *
43
- * @param node
44
- *
45
- * @returns True if the node is supported, false otherwise
46
- */
47
39
  _inherits(SyncBlockProvider, _SyncBlockDataProvide);
48
40
  return _createClass(SyncBlockProvider, [{
41
+ key: "getProduct",
42
+ value: function getProduct() {
43
+ return this.writeProvider.product;
44
+ }
45
+
46
+ /**
47
+ * Check if the node is supported by the provider
48
+ *
49
+ * @param node
50
+ *
51
+ * @returns True if the node is supported, false otherwise
52
+ */
53
+ }, {
49
54
  key: "isNodeSupported",
50
55
  value: function isNodeSupported(node) {
51
56
  return node.type === 'syncBlock' || node.type === 'bodiedSyncBlock';
@@ -241,6 +246,11 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
241
246
  value: function generateResourceId(sourceId, localId) {
242
247
  return this.writeProvider.generateResourceId(sourceId, localId);
243
248
  }
249
+ }, {
250
+ key: "generateResourceIdForReference",
251
+ value: function generateResourceIdForReference(sourceId) {
252
+ return this.writeProvider.generateResourceIdForReference(sourceId);
253
+ }
244
254
 
245
255
  /**
246
256
  * Get the synced block renderer provider options
@@ -34,6 +34,14 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
34
34
  this.fireAnalyticsEvent = fireAnalyticsEvent;
35
35
  }
36
36
  return _createClass(ReferenceSyncBlockStoreManager, [{
37
+ key: "generateResourceIdForReference",
38
+ value: function generateResourceIdForReference(sourceId) {
39
+ if (!this.dataProvider) {
40
+ throw new Error('Data provider not set');
41
+ }
42
+ return this.dataProvider.generateResourceIdForReference(sourceId);
43
+ }
44
+ }, {
37
45
  key: "updateFireAnalyticsEvent",
38
46
  value: function updateFireAnalyticsEvent(fireAnalyticsEvent) {
39
47
  this.fireAnalyticsEvent = fireAnalyticsEvent;
@@ -19,10 +19,10 @@ export var resolveSyncBlockInstance = function resolveSyncBlockInstance(oldResul
19
19
  return newResult;
20
20
  } else if (!newResult.data) {
21
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.Errored) {
23
- return oldResult;
24
- } else {
22
+ if (newResult.error === SyncBlockError.NotFound || newResult.error === SyncBlockError.Forbidden) {
25
23
  return newResult;
24
+ } else {
25
+ return oldResult;
26
26
  }
27
27
  }
28
28
 
@@ -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 };
@@ -1,10 +1,18 @@
1
+ import { type SyncBlockProduct } from "../../common/types";
1
2
  /**
2
- * Generates a unique block ARI from a source ARI and a local ID.
3
- * @param sourceId - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
4
- * @param localId - the localId of the block node. A randomly generated UUID
5
- * @returns the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
3
+ * Generates the block ARI from the source page ARI and the source block's resource ID.
4
+ * @param sourceAri - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
5
+ * @param resourceId - the resource ID of the block node. A randomly generated UUID
6
+ * @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
6
7
  */
7
- export declare const blockResourceIdFromSourceAndLocalId: (sourceId: string, localId: string) => string;
8
+ export declare const generateBlockAri: (sourceAri: string, resourceId: string, product: SyncBlockProduct) => string;
9
+ /**
10
+ *
11
+ * @param sourceAri - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
12
+ * @param resourceId - the resource ID of the reference synced block. E.G confluence-page/pageId/sourceResourceId
13
+ * @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
14
+ */
15
+ export declare const generateBlockAriFromReference: (sourceAri: string, resourceId: string) => string;
8
16
  /**
9
17
  * Extracts the local ID from a block ARI.
10
18
  * @param ari - the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
@@ -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 {
@@ -25,6 +29,9 @@ export interface SyncBlockData {
25
29
  createdBy?: string;
26
30
  isSynced?: boolean;
27
31
  product?: SyncBlockProduct;
32
+ /**
33
+ * The ARI of the block. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
34
+ */
28
35
  resourceId: ResourceId;
29
36
  sourceAri?: string;
30
37
  sourceTitle?: string;
@@ -4,7 +4,7 @@ export type { SyncBlockData, SyncBlockNode, SyncBlockProduct, BlockInstanceId, }
4
4
  export { useFetchSyncBlockData, type UseFetchSyncBlockDataResult, } from './hooks/useFetchSyncBlockData';
5
5
  export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
6
6
  export { useHandleContentChanges } from './hooks/useHandleContentChanges';
7
- export { blockResourceIdFromSourceAndLocalId, getLocalIdFromBlockResourceId, } from './clients/block-service/ari';
7
+ export { generateBlockAri, generateBlockAriFromReference, getLocalIdFromBlockResourceId, } from './clients/block-service/ari';
8
8
  export { getConfluencePageAri, getLocalIdFromConfluencePageAri, getPageARIFromContentPropertyResourceId, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId, } from './clients/confluence/ari';
9
9
  export { useMemoizedBlockServiceAPIProviders } from './providers/block-service/blockServiceAPI';
10
10
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluence/confluenceContentAPI';
@@ -1,10 +1,12 @@
1
- import { SyncBlockError, type SyncBlockData, type SyncBlockProduct } from '../../common/types';
1
+ import { SyncBlockError, type ResourceId, type SyncBlockData, type SyncBlockProduct } from '../../common/types';
2
2
  import type { ADFFetchProvider, ADFWriteProvider, DeleteSyncBlockResult, SyncBlockInstance, WriteSyncBlockResult } from '../types';
3
3
  export declare const fetchReferences: (documentAri: string) => Promise<SyncBlockInstance[] | SyncBlockError>;
4
4
  /**
5
5
  * ADFFetchProvider implementation that fetches synced block data from Block Service API
6
6
  */
7
7
  declare class BlockServiceADFFetchProvider implements ADFFetchProvider {
8
+ private sourceAri;
9
+ constructor(sourceAri: string);
8
10
  fetchData(resourceId: string): Promise<SyncBlockInstance>;
9
11
  }
10
12
  /**
@@ -12,12 +14,13 @@ declare class BlockServiceADFFetchProvider implements ADFFetchProvider {
12
14
  */
13
15
  declare class BlockServiceADFWriteProvider implements ADFWriteProvider {
14
16
  private sourceAri;
15
- private product;
17
+ product: SyncBlockProduct;
16
18
  constructor(sourceAri: string, product: SyncBlockProduct);
17
19
  writeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
18
20
  createData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
19
21
  deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
20
- generateResourceId(sourceAri: string, localId: string): string;
22
+ generateResourceIdForReference(sourceId: ResourceId): ResourceId;
23
+ generateResourceId(): ResourceId;
21
24
  }
22
25
  export declare const useMemoizedBlockServiceAPIProviders: (sourceAri: string, product: SyncBlockProduct) => {
23
26
  fetchProvider: BlockServiceADFFetchProvider;
@@ -1,4 +1,4 @@
1
- import { type SyncBlockData } from '../../common/types';
1
+ import { type ResourceId, type SyncBlockData, type SyncBlockProduct } from '../../common/types';
2
2
  import type { ADFFetchProvider, ADFWriteProvider, DeleteSyncBlockResult, SyncBlockInstance, WriteSyncBlockResult } from '../types';
3
3
  /**
4
4
  * Configuration for Content API providers
@@ -20,12 +20,14 @@ declare class ConfluenceADFFetchProvider implements ADFFetchProvider {
20
20
  */
21
21
  declare class ConfluenceADFWriteProvider implements ADFWriteProvider {
22
22
  private config;
23
+ product: SyncBlockProduct;
23
24
  constructor(config: ContentAPIConfig);
24
25
  private createNewContentProperty;
25
26
  writeData(syncBlockData: SyncBlockData): Promise<WriteSyncBlockResult>;
26
27
  createData(syncBlockData: SyncBlockData): Promise<WriteSyncBlockResult>;
27
28
  deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
28
29
  generateResourceId(sourceId: string, localId: string): string;
30
+ generateResourceIdForReference(sourceId: ResourceId): ResourceId;
29
31
  }
30
32
  /**
31
33
  * Convenience function to create providers with default content property key
@@ -17,6 +17,7 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
17
17
  * @param nestedRendererDataProviders
18
18
  */
19
19
  constructor(fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string, providerOptions: SyncedBlockRendererProviderOptions);
20
+ getProduct(): SyncBlockProduct | undefined;
20
21
  /**
21
22
  * Check if the node is supported by the provider
22
23
  *
@@ -77,6 +78,7 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
77
78
  */
78
79
  fetchSyncBlockSourceInfo(localId: BlockInstanceId, sourceAri: string, sourceProduct: SyncBlockProduct, fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void): Promise<SyncBlockSourceInfo | undefined>;
79
80
  generateResourceId(sourceId: string, localId: BlockInstanceId): string;
81
+ generateResourceIdForReference(sourceId: ResourceId): ResourceId;
80
82
  /**
81
83
  * Get the synced block renderer provider options
82
84
  *
@@ -13,6 +13,9 @@ import type { SyncBlockData, ResourceId, SyncBlockError, SyncBlockNode, SyncBloc
13
13
  export type SyncBlockInstance = {
14
14
  data?: SyncBlockData;
15
15
  error?: SyncBlockError;
16
+ /**
17
+ * The resourceId in the attrs of the block
18
+ */
16
19
  resourceId: ResourceId;
17
20
  };
18
21
  export type DeleteSyncBlockResult = {
@@ -43,6 +46,8 @@ export interface ADFWriteProvider {
43
46
  createData: (data: SyncBlockData) => Promise<WriteSyncBlockResult>;
44
47
  deleteData: (resourceId: ResourceId) => Promise<DeleteSyncBlockResult>;
45
48
  generateResourceId: (sourceId: string, localId: string) => ResourceId;
49
+ generateResourceIdForReference: (sourceId: ResourceId) => ResourceId;
50
+ product: SyncBlockProduct;
46
51
  writeData: (data: SyncBlockData) => Promise<WriteSyncBlockResult>;
47
52
  }
48
53
  export type MediaEmojiProviderOptions = {
@@ -67,6 +72,7 @@ export declare abstract class SyncBlockDataProvider extends NodeDataProvider<Syn
67
72
  abstract createNodeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
68
73
  abstract deleteNodesData(resourceIds: string[]): Promise<Array<DeleteSyncBlockResult>>;
69
74
  abstract getSourceId(): ResourceId;
75
+ abstract getProduct(): SyncBlockProduct | undefined;
70
76
  abstract fetchSyncBlockSourceInfo(localId: BlockInstanceId, sourceAri: string, sourceProduct: SyncBlockProduct, fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void): Promise<SyncBlockSourceInfo | undefined>;
71
77
  abstract getSyncedBlockRendererProviderOptions(): SyncedBlockRendererProviderOptions;
72
78
  abstract retrieveSyncBlockParentInfo(sourceAri: string, sourceProduct: SyncBlockProduct): SyncBlockParentInfo | undefined;
@@ -77,6 +83,7 @@ export declare abstract class SyncBlockDataProvider extends NodeDataProvider<Syn
77
83
  * @returns The generated resource ID
78
84
  */
79
85
  abstract generateResourceId(sourceId: ResourceId, localId: BlockInstanceId): ResourceId;
86
+ abstract generateResourceIdForReference(sourceId: ResourceId): ResourceId;
80
87
  }
81
88
  export type SubscriptionCallback = (data: SyncBlockInstance) => void;
82
89
  export type TitleSubscriptionCallback = (title: string) => void;
@@ -13,6 +13,7 @@ export declare class ReferenceSyncBlockStoreManager {
13
13
  private syncBlockURLRequests;
14
14
  private isRefreshingSubscriptions;
15
15
  constructor(dataProvider?: SyncBlockDataProvider, fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void);
16
+ generateResourceIdForReference(sourceId: ResourceId): ResourceId;
16
17
  updateFireAnalyticsEvent(fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void): void;
17
18
  /**
18
19
  * Refreshes the subscriptions for all sync blocks.
@@ -0,0 +1 @@
1
+ export declare const fetchWithRetry: (url: string, options: RequestInit, retriesRemaining?: number, delay?: number) => Promise<Response>;
@@ -1,10 +1,18 @@
1
+ import { type SyncBlockProduct } from "../../common/types";
1
2
  /**
2
- * Generates a unique block ARI from a source ARI and a local ID.
3
- * @param sourceId - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
4
- * @param localId - the localId of the block node. A randomly generated UUID
5
- * @returns the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
3
+ * Generates the block ARI from the source page ARI and the source block's resource ID.
4
+ * @param sourceAri - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
5
+ * @param resourceId - the resource ID of the block node. A randomly generated UUID
6
+ * @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
6
7
  */
7
- export declare const blockResourceIdFromSourceAndLocalId: (sourceId: string, localId: string) => string;
8
+ export declare const generateBlockAri: (sourceAri: string, resourceId: string, product: SyncBlockProduct) => string;
9
+ /**
10
+ *
11
+ * @param sourceAri - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
12
+ * @param resourceId - the resource ID of the reference synced block. E.G confluence-page/pageId/sourceResourceId
13
+ * @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
14
+ */
15
+ export declare const generateBlockAriFromReference: (sourceAri: string, resourceId: string) => string;
8
16
  /**
9
17
  * Extracts the local ID from a block ARI.
10
18
  * @param ari - the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId