@atlaskit/editor-synced-block-provider 2.12.3 → 2.13.1

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 (39) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/clients/block-service/ari.js +26 -9
  3. package/dist/cjs/index.js +12 -6
  4. package/dist/cjs/providers/block-service/blockServiceAPI.js +68 -49
  5. package/dist/cjs/providers/confluence/confluenceContentAPI.js +6 -0
  6. package/dist/cjs/providers/syncBlockProvider.js +18 -8
  7. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +8 -0
  8. package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +2 -2
  9. package/dist/es2019/clients/block-service/ari.js +25 -8
  10. package/dist/es2019/index.js +1 -1
  11. package/dist/es2019/providers/block-service/blockServiceAPI.js +32 -13
  12. package/dist/es2019/providers/confluence/confluenceContentAPI.js +4 -0
  13. package/dist/es2019/providers/syncBlockProvider.js +6 -0
  14. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +6 -0
  15. package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +2 -2
  16. package/dist/esm/clients/block-service/ari.js +25 -8
  17. package/dist/esm/index.js +1 -1
  18. package/dist/esm/providers/block-service/blockServiceAPI.js +68 -50
  19. package/dist/esm/providers/confluence/confluenceContentAPI.js +6 -0
  20. package/dist/esm/providers/syncBlockProvider.js +18 -8
  21. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +8 -0
  22. package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +2 -2
  23. package/dist/types/clients/block-service/ari.d.ts +13 -5
  24. package/dist/types/common/types.d.ts +3 -0
  25. package/dist/types/index.d.ts +1 -1
  26. package/dist/types/providers/block-service/blockServiceAPI.d.ts +6 -3
  27. package/dist/types/providers/confluence/confluenceContentAPI.d.ts +3 -1
  28. package/dist/types/providers/syncBlockProvider.d.ts +2 -0
  29. package/dist/types/providers/types.d.ts +7 -0
  30. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +1 -0
  31. package/dist/types-ts4.5/clients/block-service/ari.d.ts +13 -5
  32. package/dist/types-ts4.5/common/types.d.ts +3 -0
  33. package/dist/types-ts4.5/index.d.ts +1 -1
  34. package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +6 -3
  35. package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +3 -1
  36. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +2 -0
  37. package/dist/types-ts4.5/providers/types.d.ts +7 -0
  38. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +1 -0
  39. package/package.json +2 -2
@@ -23,6 +23,9 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
23
23
  this.sourceId = sourceId;
24
24
  this.providerOptions = providerOptions;
25
25
  }
26
+ getProduct() {
27
+ return this.writeProvider.product;
28
+ }
26
29
 
27
30
  /**
28
31
  * Check if the node is supported by the provider
@@ -160,6 +163,9 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
160
163
  generateResourceId(sourceId, localId) {
161
164
  return this.writeProvider.generateResourceId(sourceId, localId);
162
165
  }
166
+ generateResourceIdForReference(sourceId) {
167
+ return this.writeProvider.generateResourceIdForReference(sourceId);
168
+ }
163
169
 
164
170
  /**
165
171
  * Get the synced block renderer provider options
@@ -22,6 +22,12 @@ export class ReferenceSyncBlockStoreManager {
22
22
  this.providerFactories = new Map();
23
23
  this.fireAnalyticsEvent = fireAnalyticsEvent;
24
24
  }
25
+ generateResourceIdForReference(sourceId) {
26
+ if (!this.dataProvider) {
27
+ throw new Error('Data provider not set');
28
+ }
29
+ return this.dataProvider.generateResourceIdForReference(sourceId);
30
+ }
25
31
  updateFireAnalyticsEvent(fireAnalyticsEvent) {
26
32
  this.fireAnalyticsEvent = fireAnalyticsEvent;
27
33
  }
@@ -83,10 +83,10 @@ export class SourceSyncBlockStoreManager {
83
83
  return Promise.resolve(true);
84
84
  }
85
85
  const writeResults = await this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
86
- if (writeResults.every(result => result.resourceId !== undefined)) {
86
+ if (writeResults.every(result => !result.error)) {
87
87
  return true;
88
88
  } else {
89
- writeResults.filter(result => result.resourceId === undefined).forEach(result => {
89
+ writeResults.filter(result => result.error).forEach(result => {
90
90
  var _this$fireAnalyticsEv2;
91
91
  (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 ? void 0 : _this$fireAnalyticsEv2.call(this, updateErrorPayload(result.error || 'Failed to write data'));
92
92
  });
@@ -1,17 +1,34 @@
1
1
  /* eslint-disable require-unicode-regexp */
2
+
3
+ /**
4
+ * Generates the block ARI from the source page ARI and the source block's resource ID.
5
+ * @param sourceAri - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
6
+ * @param resourceId - the resource ID of the block node. A randomly generated UUID
7
+ * @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
8
+ */
9
+ export var generateBlockAri = function generateBlockAri(sourceAri, resourceId, product) {
10
+ var match = sourceAri.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/(\d+)/);
11
+ if (!(match !== null && match !== void 0 && match[1])) {
12
+ throw new Error("Invalid source ARI: ".concat(sourceAri));
13
+ }
14
+ var cloudId = match[1];
15
+ var pageId = match[3];
16
+ return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(product, "/").concat(pageId, "/").concat(resourceId);
17
+ };
18
+
2
19
  /**
3
- * Generates a unique block ARI from a source ARI and a local ID.
4
- * @param sourceId - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
5
- * @param localId - the localId of the block node. A randomly generated UUID
6
- * @returns the block ARI. E.G ari:cloud:blocks:cloudId:synced-block/localId
20
+ *
21
+ * @param sourceAri - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
22
+ * @param resourceId - the resource ID of the reference synced block. E.G confluence-page/pageId/sourceResourceId
23
+ * @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
7
24
  */
8
- export var blockResourceIdFromSourceAndLocalId = function blockResourceIdFromSourceAndLocalId(sourceId, localId) {
9
- var match = sourceId.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/.*/);
25
+ export var generateBlockAriFromReference = function generateBlockAriFromReference(sourceAri, resourceId) {
26
+ var match = sourceAri.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/(\d+)/);
10
27
  if (!(match !== null && match !== void 0 && match[1])) {
11
- throw new Error("Invalid source ARI: ".concat(sourceId));
28
+ throw new Error("Invalid source ARI: ".concat(sourceAri));
12
29
  }
13
30
  var cloudId = match[1];
14
- return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(localId);
31
+ return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(resourceId);
15
32
  };
16
33
 
17
34
  /**
package/dist/esm/index.js CHANGED
@@ -9,7 +9,7 @@ export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
9
9
  export { useHandleContentChanges } from './hooks/useHandleContentChanges';
10
10
 
11
11
  // clients
12
- export { blockResourceIdFromSourceAndLocalId, getLocalIdFromBlockResourceId } from './clients/block-service/ari';
12
+ export { generateBlockAri, generateBlockAriFromReference, getLocalIdFromBlockResourceId } from './clients/block-service/ari';
13
13
  export { getConfluencePageAri, getLocalIdFromConfluencePageAri, getPageARIFromContentPropertyResourceId, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId } from './clients/confluence/ari';
14
14
 
15
15
  // providers
@@ -3,8 +3,9 @@ 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';
@@ -108,24 +109,26 @@ export var fetchReferences = /*#__PURE__*/function () {
108
109
  * ADFFetchProvider implementation that fetches synced block data from Block Service API
109
110
  */
110
111
  var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
111
- function BlockServiceADFFetchProvider() {
112
+ function BlockServiceADFFetchProvider(sourceAri) {
112
113
  _classCallCheck(this, BlockServiceADFFetchProvider);
114
+ this.sourceAri = sourceAri;
113
115
  }
116
+
117
+ // resourceId of the reference synced block.
118
+ // the ARI must be constructed to call the block service API
114
119
  return _createClass(BlockServiceADFFetchProvider, [{
115
120
  key: "fetchData",
116
- value: // resourceId is the ARI of the block. E.G ari:cloud:blocks:site-123:synced-block/uuid-456
117
- // 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
118
- function () {
121
+ value: function () {
119
122
  var _fetchData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceId) {
120
- var localId, blockContentResponse, value, syncedBlockData;
123
+ var blockAri, blockContentResponse, value, syncedBlockData;
121
124
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
122
125
  while (1) switch (_context2.prev = _context2.next) {
123
126
  case 0:
124
- localId = getLocalIdFromBlockResourceId(resourceId);
127
+ blockAri = generateBlockAriFromReference(this.sourceAri, resourceId);
125
128
  _context2.prev = 1;
126
129
  _context2.next = 4;
127
130
  return getSyncedBlockContent({
128
- blockAri: resourceId
131
+ blockAri: blockAri
129
132
  });
130
133
  case 4:
131
134
  blockContentResponse = _context2.sent;
@@ -144,8 +147,9 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
144
147
  return _context2.abrupt("return", {
145
148
  data: {
146
149
  content: syncedBlockData,
147
- resourceId: resourceId,
148
- blockInstanceId: localId,
150
+ resourceId: blockAri,
151
+ blockInstanceId: blockContentResponse.blockInstanceId,
152
+ // this was the node's localId, but has become the resourceId.
149
153
  sourceAri: blockContentResponse.sourceAri,
150
154
  product: blockContentResponse.product
151
155
  },
@@ -171,7 +175,7 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
171
175
  case "end":
172
176
  return _context2.stop();
173
177
  }
174
- }, _callee2, null, [[1, 12]]);
178
+ }, _callee2, this, [[1, 12]]);
175
179
  }));
176
180
  function fetchData(_x2) {
177
181
  return _fetchData.apply(this, arguments);
@@ -195,42 +199,43 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
195
199
  key: "writeData",
196
200
  value: function () {
197
201
  var _writeData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(data) {
198
- var resourceId;
202
+ var resourceId, blockAri;
199
203
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
200
204
  while (1) switch (_context3.prev = _context3.next) {
201
205
  case 0:
202
206
  resourceId = data.resourceId;
203
- _context3.prev = 1;
204
- _context3.next = 4;
207
+ blockAri = generateBlockAri(this.sourceAri, resourceId, this.product);
208
+ _context3.prev = 2;
209
+ _context3.next = 5;
205
210
  return updateSyncedBlock({
206
- blockAri: resourceId,
211
+ blockAri: blockAri,
207
212
  content: JSON.stringify(data.content)
208
213
  });
209
- case 4:
214
+ case 5:
210
215
  return _context3.abrupt("return", {
211
216
  resourceId: resourceId
212
217
  });
213
- case 7:
214
- _context3.prev = 7;
215
- _context3.t0 = _context3["catch"](1);
218
+ case 8:
219
+ _context3.prev = 8;
220
+ _context3.t0 = _context3["catch"](2);
216
221
  if (!(_context3.t0 instanceof BlockError)) {
217
- _context3.next = 11;
222
+ _context3.next = 12;
218
223
  break;
219
224
  }
220
225
  return _context3.abrupt("return", {
221
226
  error: mapBlockError(_context3.t0),
222
227
  resourceId: resourceId
223
228
  });
224
- case 11:
229
+ case 12:
225
230
  return _context3.abrupt("return", {
226
231
  error: stringifyError(_context3.t0),
227
232
  resourceId: resourceId
228
233
  });
229
- case 12:
234
+ case 13:
230
235
  case "end":
231
236
  return _context3.stop();
232
237
  }
233
- }, _callee3, null, [[1, 7]]);
238
+ }, _callee3, this, [[2, 8]]);
234
239
  }));
235
240
  function writeData(_x3) {
236
241
  return _writeData.apply(this, arguments);
@@ -241,45 +246,46 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
241
246
  key: "createData",
242
247
  value: function () {
243
248
  var _createData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(data) {
244
- var resourceId;
249
+ var resourceId, blockAri;
245
250
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
246
251
  while (1) switch (_context4.prev = _context4.next) {
247
252
  case 0:
248
253
  resourceId = data.resourceId;
249
- _context4.prev = 1;
250
- _context4.next = 4;
254
+ blockAri = generateBlockAri(this.sourceAri, resourceId, this.product);
255
+ _context4.prev = 2;
256
+ _context4.next = 5;
251
257
  return createSyncedBlock({
252
- blockAri: resourceId,
258
+ blockAri: blockAri,
253
259
  blockInstanceId: data.blockInstanceId,
254
260
  sourceAri: this.sourceAri,
255
261
  product: this.product,
256
262
  content: JSON.stringify(data.content)
257
263
  });
258
- case 4:
264
+ case 5:
259
265
  return _context4.abrupt("return", {
260
266
  resourceId: resourceId
261
267
  });
262
- case 7:
263
- _context4.prev = 7;
264
- _context4.t0 = _context4["catch"](1);
268
+ case 8:
269
+ _context4.prev = 8;
270
+ _context4.t0 = _context4["catch"](2);
265
271
  if (!(_context4.t0 instanceof BlockError)) {
266
- _context4.next = 11;
272
+ _context4.next = 12;
267
273
  break;
268
274
  }
269
275
  return _context4.abrupt("return", {
270
276
  error: mapBlockError(_context4.t0),
271
277
  resourceId: resourceId
272
278
  });
273
- case 11:
279
+ case 12:
274
280
  return _context4.abrupt("return", {
275
281
  error: stringifyError(_context4.t0),
276
282
  resourceId: resourceId
277
283
  });
278
- case 12:
284
+ case 13:
279
285
  case "end":
280
286
  return _context4.stop();
281
287
  }
282
- }, _callee4, this, [[1, 7]]);
288
+ }, _callee4, this, [[2, 8]]);
283
289
  }));
284
290
  function createData(_x4) {
285
291
  return _createData.apply(this, arguments);
@@ -290,25 +296,27 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
290
296
  key: "deleteData",
291
297
  value: function () {
292
298
  var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(resourceId) {
299
+ var blockAri;
293
300
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
294
301
  while (1) switch (_context5.prev = _context5.next) {
295
302
  case 0:
296
- _context5.prev = 0;
297
- _context5.next = 3;
303
+ blockAri = generateBlockAri(this.sourceAri, resourceId, this.product);
304
+ _context5.prev = 1;
305
+ _context5.next = 4;
298
306
  return deleteSyncedBlock({
299
- blockAri: resourceId
307
+ blockAri: blockAri
300
308
  });
301
- case 3:
309
+ case 4:
302
310
  return _context5.abrupt("return", {
303
311
  resourceId: resourceId,
304
312
  success: true,
305
313
  error: undefined
306
314
  });
307
- case 6:
308
- _context5.prev = 6;
309
- _context5.t0 = _context5["catch"](0);
315
+ case 7:
316
+ _context5.prev = 7;
317
+ _context5.t0 = _context5["catch"](1);
310
318
  if (!(_context5.t0 instanceof BlockError)) {
311
- _context5.next = 10;
319
+ _context5.next = 11;
312
320
  break;
313
321
  }
314
322
  return _context5.abrupt("return", {
@@ -316,27 +324,37 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
316
324
  success: false,
317
325
  error: mapBlockError(_context5.t0)
318
326
  });
319
- case 10:
327
+ case 11:
320
328
  return _context5.abrupt("return", {
321
329
  resourceId: resourceId,
322
330
  success: false,
323
331
  error: stringifyError(_context5.t0)
324
332
  });
325
- case 11:
333
+ case 12:
326
334
  case "end":
327
335
  return _context5.stop();
328
336
  }
329
- }, _callee5, null, [[0, 6]]);
337
+ }, _callee5, this, [[1, 7]]);
330
338
  }));
331
339
  function deleteData(_x5) {
332
340
  return _deleteData.apply(this, arguments);
333
341
  }
334
342
  return deleteData;
335
- }()
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
+ }
336
354
  }, {
337
355
  key: "generateResourceId",
338
- value: function generateResourceId(sourceAri, localId) {
339
- return blockResourceIdFromSourceAndLocalId(sourceAri, localId);
356
+ value: function generateResourceId() {
357
+ return crypto.randomUUID();
340
358
  }
341
359
  }]);
342
360
  }();
@@ -344,7 +362,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
344
362
  * Factory function to create both providers with shared configuration
345
363
  */
346
364
  var createBlockServiceAPIProviders = function createBlockServiceAPIProviders(sourceAri, product) {
347
- var fetchProvider = new BlockServiceADFFetchProvider();
365
+ var fetchProvider = new BlockServiceADFFetchProvider(sourceAri);
348
366
  var writeProvider = new BlockServiceADFWriteProvider(sourceAri, product);
349
367
  return {
350
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;
@@ -110,7 +110,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
110
110
  case 10:
111
111
  writeResults = _context.sent;
112
112
  if (!writeResults.every(function (result) {
113
- return result.resourceId !== undefined;
113
+ return !result.error;
114
114
  })) {
115
115
  _context.next = 15;
116
116
  break;
@@ -118,7 +118,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
118
118
  return _context.abrupt("return", true);
119
119
  case 15:
120
120
  writeResults.filter(function (result) {
121
- return result.resourceId === undefined;
121
+ return result.error;
122
122
  }).forEach(function (result) {
123
123
  var _this2$fireAnalyticsE;
124
124
  (_this2$fireAnalyticsE = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE === void 0 || _this2$fireAnalyticsE.call(_this2, updateErrorPayload(result.error || 'Failed to write data'));
@@ -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
@@ -29,6 +29,9 @@ export interface SyncBlockData {
29
29
  createdBy?: string;
30
30
  isSynced?: boolean;
31
31
  product?: SyncBlockProduct;
32
+ /**
33
+ * The ARI of the block. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
34
+ */
32
35
  resourceId: ResourceId;
33
36
  sourceAri?: string;
34
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.