@atlaskit/editor-synced-block-provider 2.15.6 → 2.16.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 (35) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/clients/block-service/ari.js +1 -1
  3. package/dist/cjs/clients/block-service/blockService.js +33 -25
  4. package/dist/cjs/clients/confluence/ari.js +41 -7
  5. package/dist/cjs/clients/jira/ari.js +30 -0
  6. package/dist/cjs/index.js +17 -4
  7. package/dist/cjs/providers/block-service/blockServiceAPI.js +35 -30
  8. package/dist/cjs/providers/confluence/confluenceContentAPI.js +4 -4
  9. package/dist/es2019/clients/block-service/ari.js +1 -1
  10. package/dist/es2019/clients/block-service/blockService.js +22 -12
  11. package/dist/es2019/clients/confluence/ari.js +40 -8
  12. package/dist/es2019/clients/jira/ari.js +22 -0
  13. package/dist/es2019/index.js +2 -1
  14. package/dist/es2019/providers/block-service/blockServiceAPI.js +12 -7
  15. package/dist/es2019/providers/confluence/confluenceContentAPI.js +5 -5
  16. package/dist/esm/clients/block-service/ari.js +1 -1
  17. package/dist/esm/clients/block-service/blockService.js +33 -25
  18. package/dist/esm/clients/confluence/ari.js +40 -6
  19. package/dist/esm/clients/jira/ari.js +24 -0
  20. package/dist/esm/index.js +2 -1
  21. package/dist/esm/providers/block-service/blockServiceAPI.js +35 -30
  22. package/dist/esm/providers/confluence/confluenceContentAPI.js +5 -5
  23. package/dist/types/clients/block-service/ari.d.ts +1 -1
  24. package/dist/types/clients/block-service/blockService.d.ts +4 -2
  25. package/dist/types/clients/confluence/ari.d.ts +33 -2
  26. package/dist/types/clients/jira/ari.d.ts +13 -0
  27. package/dist/types/index.d.ts +2 -1
  28. package/dist/types/providers/block-service/blockServiceAPI.d.ts +3 -2
  29. package/dist/types-ts4.5/clients/block-service/ari.d.ts +1 -1
  30. package/dist/types-ts4.5/clients/block-service/blockService.d.ts +4 -2
  31. package/dist/types-ts4.5/clients/confluence/ari.d.ts +33 -2
  32. package/dist/types-ts4.5/clients/jira/ari.d.ts +13 -0
  33. package/dist/types-ts4.5/index.d.ts +2 -1
  34. package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +3 -2
  35. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 2.16.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`5f9c5b4ae25c7`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5f9c5b4ae25c7) -
8
+ EDITOR-3594 Add Jira ARI utility functions to synced block provider
9
+
10
+ ## 2.16.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [`1e626a0fb59a7`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1e626a0fb59a7) -
15
+ Can pass in get NCS step version function
16
+
3
17
  ## 2.15.6
4
18
 
5
19
  ### Patch Changes
@@ -23,7 +23,7 @@ var generateBlockAri = exports.generateBlockAri = function generateBlockAri(sour
23
23
  };
24
24
 
25
25
  /**
26
- *
26
+ * Generates the block ARI from the reference synced block ARI and the resource ID
27
27
  * @param sourceAri - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
28
28
  * @param resourceId - the resource ID of the reference synced block. E.G confluence-page/pageId/sourceResourceId
29
29
  * @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
@@ -177,27 +177,31 @@ var deleteSyncedBlock = exports.deleteSyncedBlock = /*#__PURE__*/function () {
177
177
  }();
178
178
  var updateSyncedBlock = exports.updateSyncedBlock = /*#__PURE__*/function () {
179
179
  var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(_ref6) {
180
- var blockAri, content, response;
180
+ var blockAri, content, stepVersion, requestBody, response;
181
181
  return _regenerator.default.wrap(function _callee4$(_context4) {
182
182
  while (1) switch (_context4.prev = _context4.next) {
183
183
  case 0:
184
- blockAri = _ref6.blockAri, content = _ref6.content;
185
- _context4.next = 3;
184
+ blockAri = _ref6.blockAri, content = _ref6.content, stepVersion = _ref6.stepVersion;
185
+ requestBody = {
186
+ content: content
187
+ };
188
+ if (stepVersion !== undefined) {
189
+ requestBody.stepVersion = stepVersion;
190
+ }
191
+ _context4.next = 5;
186
192
  return (0, _retry.fetchWithRetry)("".concat(BLOCK_SERVICE_API_URL, "/block/").concat(encodeURIComponent(blockAri)), {
187
193
  method: 'PUT',
188
194
  headers: COMMON_HEADERS,
189
- body: JSON.stringify({
190
- content: content
191
- })
195
+ body: JSON.stringify(requestBody)
192
196
  });
193
- case 3:
197
+ case 5:
194
198
  response = _context4.sent;
195
199
  if (response.ok) {
196
- _context4.next = 6;
200
+ _context4.next = 8;
197
201
  break;
198
202
  }
199
203
  throw new BlockError(response.status);
200
- case 6:
204
+ case 8:
201
205
  case "end":
202
206
  return _context4.stop();
203
207
  }
@@ -209,36 +213,40 @@ var updateSyncedBlock = exports.updateSyncedBlock = /*#__PURE__*/function () {
209
213
  }();
210
214
  var createSyncedBlock = exports.createSyncedBlock = /*#__PURE__*/function () {
211
215
  var _ref9 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(_ref8) {
212
- var blockAri, blockInstanceId, sourceAri, product, content, response;
216
+ var blockAri, blockInstanceId, sourceAri, product, content, stepVersion, requestBody, response;
213
217
  return _regenerator.default.wrap(function _callee5$(_context5) {
214
218
  while (1) switch (_context5.prev = _context5.next) {
215
219
  case 0:
216
- blockAri = _ref8.blockAri, blockInstanceId = _ref8.blockInstanceId, sourceAri = _ref8.sourceAri, product = _ref8.product, content = _ref8.content;
217
- _context5.next = 3;
220
+ blockAri = _ref8.blockAri, blockInstanceId = _ref8.blockInstanceId, sourceAri = _ref8.sourceAri, product = _ref8.product, content = _ref8.content, stepVersion = _ref8.stepVersion;
221
+ requestBody = {
222
+ blockAri: blockAri,
223
+ blockInstanceId: blockInstanceId,
224
+ sourceAri: sourceAri,
225
+ product: product,
226
+ content: content
227
+ };
228
+ if (stepVersion !== undefined) {
229
+ requestBody.stepVersion = stepVersion;
230
+ }
231
+ _context5.next = 5;
218
232
  return (0, _retry.fetchWithRetry)("".concat(BLOCK_SERVICE_API_URL, "/block"), {
219
233
  method: 'POST',
220
234
  headers: COMMON_HEADERS,
221
- body: JSON.stringify({
222
- blockAri: blockAri,
223
- blockInstanceId: blockInstanceId,
224
- sourceAri: sourceAri,
225
- product: product,
226
- content: content
227
- })
235
+ body: JSON.stringify(requestBody)
228
236
  });
229
- case 3:
237
+ case 5:
230
238
  response = _context5.sent;
231
239
  if (response.ok) {
232
- _context5.next = 6;
240
+ _context5.next = 8;
233
241
  break;
234
242
  }
235
243
  throw new BlockError(response.status);
236
- case 6:
237
- _context5.next = 8;
238
- return response.json();
239
244
  case 8:
245
+ _context5.next = 10;
246
+ return response.json();
247
+ case 10:
240
248
  return _context5.abrupt("return", _context5.sent);
241
- case 9:
249
+ case 11:
242
250
  case "end":
243
251
  return _context5.stop();
244
252
  }
@@ -3,15 +3,30 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.resourceIdFromConfluencePageSourceIdAndLocalId = exports.getPageIdAndTypeFromConfluencePageAri = exports.getPageARIFromContentPropertyResourceId = exports.getLocalIdFromConfluencePageAri = exports.getConfluencePageAri = void 0;
6
+ exports.resourceIdFromConfluencePageSourceIdAndLocalId = exports.getPageIdAndTypeFromConfluencePageAri = exports.getPageAriFromContentPropertyResourceId = exports.getLocalIdFromContentPropertyResourceId = exports.getConfluencePageAri = void 0;
7
7
  /* eslint-disable require-unicode-regexp */
8
8
 
9
+ /**
10
+ * The type of the Confluence page
11
+ */
12
+
13
+ /**
14
+ * Generates the Confluence page ARI
15
+ * @param pageId - the ID of the page
16
+ * @param cloudId - the cloud ID
17
+ * @param pageType - the type of the page
18
+ * @returns the Confluence page ARI
19
+ */
9
20
  var getConfluencePageAri = exports.getConfluencePageAri = function getConfluencePageAri(pageId, cloudId) {
10
21
  var pageType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'page';
11
22
  return "ari:cloud:confluence:".concat(cloudId, ":").concat(pageType, "/").concat(pageId);
12
23
  };
13
24
 
14
- // For extracting from Page ARI and also the content property's version of resourceId
25
+ /**
26
+ * Extracts the page ID and type from the Confluence page ARI
27
+ * @param ari - the Confluence page ARI
28
+ * @returns the page ID and type
29
+ */
15
30
  var getPageIdAndTypeFromConfluencePageAri = exports.getPageIdAndTypeFromConfluencePageAri = function getPageIdAndTypeFromConfluencePageAri(ari) {
16
31
  var match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/(\d+)/);
17
32
  if (match !== null && match !== void 0 && match[2]) {
@@ -22,20 +37,39 @@ var getPageIdAndTypeFromConfluencePageAri = exports.getPageIdAndTypeFromConfluen
22
37
  }
23
38
  throw new Error("Invalid page ARI: ".concat(ari));
24
39
  };
25
- var getLocalIdFromConfluencePageAri = exports.getLocalIdFromConfluencePageAri = function getLocalIdFromConfluencePageAri(ari) {
26
- var match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+\/([a-zA-Z0-9-]+)/);
40
+
41
+ /**
42
+ * Extracts the local ID from the Confluence page content property resource ID
43
+ * @param resourceId - the Confluence page content property resource ID
44
+ * @returns the local ID
45
+ */
46
+ var getLocalIdFromContentPropertyResourceId = exports.getLocalIdFromContentPropertyResourceId = function getLocalIdFromContentPropertyResourceId(resourceId) {
47
+ var match = resourceId.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+\/([a-zA-Z0-9-]+)/);
27
48
  if (match !== null && match !== void 0 && match[2]) {
28
49
  return match[2];
29
50
  }
30
- throw new Error("Invalid page ARI: ".concat(ari));
51
+ throw new Error("Invalid resourceId: ".concat(resourceId));
31
52
  };
32
- var getPageARIFromContentPropertyResourceId = exports.getPageARIFromContentPropertyResourceId = function getPageARIFromContentPropertyResourceId(resourceId) {
53
+
54
+ /**
55
+ * Extracts the Confluence page ARI from the Confluence content property resource ID
56
+ * @param resourceId - the Confluence content property resource ID
57
+ * @returns the Confluence page ARI
58
+ */
59
+ var getPageAriFromContentPropertyResourceId = exports.getPageAriFromContentPropertyResourceId = function getPageAriFromContentPropertyResourceId(resourceId) {
33
60
  var match = resourceId.match(/(ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+)\/([a-zA-Z0-9-]+)$/);
34
61
  if (match !== null && match !== void 0 && match[1]) {
35
62
  return match[1];
36
63
  }
37
64
  throw new Error("Invalid resourceId: ".concat(resourceId));
38
65
  };
66
+
67
+ /**
68
+ * Generates the Confluence page content property resource ID from the source ID and local ID
69
+ * @param sourceId - the source ID
70
+ * @param localId - the local ID
71
+ * @returns the Confluence page content property resource ID
72
+ */
39
73
  var resourceIdFromConfluencePageSourceIdAndLocalId = exports.resourceIdFromConfluencePageSourceIdAndLocalId = function resourceIdFromConfluencePageSourceIdAndLocalId(sourceId, localId) {
40
- return sourceId + '/' + localId;
74
+ return "".concat(sourceId, "/").concat(localId);
41
75
  };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getJiraWorkItemIdFromAri = exports.getJiraWorkItemAri = void 0;
7
+ /* eslint-disable require-unicode-regexp */
8
+
9
+ /**
10
+ * Generates the Jira work item ARI
11
+ * @param workItemId - the ID of the work item
12
+ * @param cloudId - the cloud ID
13
+ * @returns the Jira work item ARI
14
+ */
15
+ var getJiraWorkItemAri = exports.getJiraWorkItemAri = function getJiraWorkItemAri(workItemId, cloudId) {
16
+ return "ari:cloud:jira:".concat(cloudId, ":issue/").concat(workItemId);
17
+ };
18
+
19
+ /**
20
+ * Extracts the Jira work item ID from the Jira work item ARI
21
+ * @param ari - the Jira work item ARI
22
+ * @returns the Jira work item ID
23
+ */
24
+ var getJiraWorkItemIdFromAri = exports.getJiraWorkItemIdFromAri = function getJiraWorkItemIdFromAri(ari) {
25
+ var match = ari.match(/ari:cloud:jira:([^:]+):issue\/(\d+)/);
26
+ if (match !== null && match !== void 0 && match[2]) {
27
+ return match[2];
28
+ }
29
+ throw new Error("Invalid Jira work item ARI: ".concat(ari));
30
+ };
package/dist/cjs/index.js CHANGED
@@ -93,22 +93,34 @@ Object.defineProperty(exports, "getContentIdAndProductFromResourceId", {
93
93
  return _utils.getContentIdAndProductFromResourceId;
94
94
  }
95
95
  });
96
+ Object.defineProperty(exports, "getJiraWorkItemAri", {
97
+ enumerable: true,
98
+ get: function get() {
99
+ return _ari3.getJiraWorkItemAri;
100
+ }
101
+ });
102
+ Object.defineProperty(exports, "getJiraWorkItemIdFromAri", {
103
+ enumerable: true,
104
+ get: function get() {
105
+ return _ari3.getJiraWorkItemIdFromAri;
106
+ }
107
+ });
96
108
  Object.defineProperty(exports, "getLocalIdFromBlockResourceId", {
97
109
  enumerable: true,
98
110
  get: function get() {
99
111
  return _ari.getLocalIdFromBlockResourceId;
100
112
  }
101
113
  });
102
- Object.defineProperty(exports, "getLocalIdFromConfluencePageAri", {
114
+ Object.defineProperty(exports, "getLocalIdFromContentPropertyResourceId", {
103
115
  enumerable: true,
104
116
  get: function get() {
105
- return _ari2.getLocalIdFromConfluencePageAri;
117
+ return _ari2.getLocalIdFromContentPropertyResourceId;
106
118
  }
107
119
  });
108
- Object.defineProperty(exports, "getPageARIFromContentPropertyResourceId", {
120
+ Object.defineProperty(exports, "getPageAriFromContentPropertyResourceId", {
109
121
  enumerable: true,
110
122
  get: function get() {
111
- return _ari2.getPageARIFromContentPropertyResourceId;
123
+ return _ari2.getPageAriFromContentPropertyResourceId;
112
124
  }
113
125
  });
114
126
  Object.defineProperty(exports, "getPageIdAndTypeFromConfluencePageAri", {
@@ -184,6 +196,7 @@ var _useFetchSyncBlockTitle = require("./hooks/useFetchSyncBlockTitle");
184
196
  var _useHandleContentChanges = require("./hooks/useHandleContentChanges");
185
197
  var _ari = require("./clients/block-service/ari");
186
198
  var _ari2 = require("./clients/confluence/ari");
199
+ var _ari3 = require("./clients/jira/ari");
187
200
  var _blockServiceAPI = require("./providers/block-service/blockServiceAPI");
188
201
  var _confluenceContentAPI = require("./providers/confluence/confluenceContentAPI");
189
202
  var _sourceInfo = require("./clients/confluence/sourceInfo");
@@ -196,11 +196,12 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
196
196
  * ADFWriteProvider implementation that writes synced block data to Block Service API
197
197
  */
198
198
  var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
199
- function BlockServiceADFWriteProvider(sourceAri, product, sourceDocumentId) {
199
+ function BlockServiceADFWriteProvider(sourceAri, product, sourceDocumentId, getVersion) {
200
200
  (0, _classCallCheck2.default)(this, BlockServiceADFWriteProvider);
201
201
  this.sourceAri = sourceAri;
202
202
  this.product = product;
203
203
  this.sourceDocumentId = sourceDocumentId;
204
+ this.getVersion = getVersion;
204
205
  }
205
206
 
206
207
  // it will first try to update and if it can't (404) then it will try to create
@@ -208,43 +209,45 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
208
209
  key: "writeData",
209
210
  value: function () {
210
211
  var _writeData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(data) {
211
- var resourceId, blockAri;
212
+ var resourceId, blockAri, stepVersion;
212
213
  return _regenerator.default.wrap(function _callee3$(_context3) {
213
214
  while (1) switch (_context3.prev = _context3.next) {
214
215
  case 0:
215
216
  resourceId = data.resourceId;
216
217
  blockAri = (0, _ari.generateBlockAri)(this.sourceAri, resourceId, this.product);
217
- _context3.prev = 2;
218
- _context3.next = 5;
218
+ stepVersion = this.getVersion ? this.getVersion() : undefined;
219
+ _context3.prev = 3;
220
+ _context3.next = 6;
219
221
  return (0, _blockService.updateSyncedBlock)({
220
222
  blockAri: blockAri,
221
- content: JSON.stringify(data.content)
223
+ content: JSON.stringify(data.content),
224
+ stepVersion: stepVersion
222
225
  });
223
- case 5:
226
+ case 6:
224
227
  return _context3.abrupt("return", {
225
228
  resourceId: resourceId
226
229
  });
227
- case 8:
228
- _context3.prev = 8;
229
- _context3.t0 = _context3["catch"](2);
230
+ case 9:
231
+ _context3.prev = 9;
232
+ _context3.t0 = _context3["catch"](3);
230
233
  if (!(_context3.t0 instanceof _blockService.BlockError)) {
231
- _context3.next = 12;
234
+ _context3.next = 13;
232
235
  break;
233
236
  }
234
237
  return _context3.abrupt("return", {
235
238
  error: mapBlockError(_context3.t0),
236
239
  resourceId: resourceId
237
240
  });
238
- case 12:
241
+ case 13:
239
242
  return _context3.abrupt("return", {
240
243
  error: (0, _errorHandling.stringifyError)(_context3.t0),
241
244
  resourceId: resourceId
242
245
  });
243
- case 13:
246
+ case 14:
244
247
  case "end":
245
248
  return _context3.stop();
246
249
  }
247
- }, _callee3, this, [[2, 8]]);
250
+ }, _callee3, this, [[3, 9]]);
248
251
  }));
249
252
  function writeData(_x3) {
250
253
  return _writeData.apply(this, arguments);
@@ -255,46 +258,48 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
255
258
  key: "createData",
256
259
  value: function () {
257
260
  var _createData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(data) {
258
- var resourceId, blockAri;
261
+ var resourceId, blockAri, stepVersion;
259
262
  return _regenerator.default.wrap(function _callee4$(_context4) {
260
263
  while (1) switch (_context4.prev = _context4.next) {
261
264
  case 0:
262
265
  resourceId = data.resourceId;
263
266
  blockAri = (0, _ari.generateBlockAri)(this.sourceAri, resourceId, this.product);
264
- _context4.prev = 2;
265
- _context4.next = 5;
267
+ stepVersion = this.getVersion ? this.getVersion() : undefined;
268
+ _context4.prev = 3;
269
+ _context4.next = 6;
266
270
  return (0, _blockService.createSyncedBlock)({
267
271
  blockAri: blockAri,
268
272
  blockInstanceId: data.blockInstanceId,
269
273
  sourceAri: this.sourceAri,
270
274
  product: this.product,
271
- content: JSON.stringify(data.content)
275
+ content: JSON.stringify(data.content),
276
+ stepVersion: stepVersion
272
277
  });
273
- case 5:
278
+ case 6:
274
279
  return _context4.abrupt("return", {
275
280
  resourceId: resourceId
276
281
  });
277
- case 8:
278
- _context4.prev = 8;
279
- _context4.t0 = _context4["catch"](2);
282
+ case 9:
283
+ _context4.prev = 9;
284
+ _context4.t0 = _context4["catch"](3);
280
285
  if (!(_context4.t0 instanceof _blockService.BlockError)) {
281
- _context4.next = 12;
286
+ _context4.next = 13;
282
287
  break;
283
288
  }
284
289
  return _context4.abrupt("return", {
285
290
  error: mapBlockError(_context4.t0),
286
291
  resourceId: resourceId
287
292
  });
288
- case 12:
293
+ case 13:
289
294
  return _context4.abrupt("return", {
290
295
  error: (0, _errorHandling.stringifyError)(_context4.t0),
291
296
  resourceId: resourceId
292
297
  });
293
- case 13:
298
+ case 14:
294
299
  case "end":
295
300
  return _context4.stop();
296
301
  }
297
- }, _callee4, this, [[2, 8]]);
302
+ }, _callee4, this, [[3, 9]]);
298
303
  }));
299
304
  function createData(_x4) {
300
305
  return _createData.apply(this, arguments);
@@ -425,16 +430,16 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
425
430
  /**
426
431
  * Factory function to create both providers with shared configuration
427
432
  */
428
- var createBlockServiceAPIProviders = function createBlockServiceAPIProviders(sourceAri, product, sourceDocumentId) {
433
+ var createBlockServiceAPIProviders = function createBlockServiceAPIProviders(sourceAri, product, sourceDocumentId, getVersion) {
429
434
  var fetchProvider = new BlockServiceADFFetchProvider(sourceAri);
430
- var writeProvider = new BlockServiceADFWriteProvider(sourceAri, product, sourceDocumentId);
435
+ var writeProvider = new BlockServiceADFWriteProvider(sourceAri, product, sourceDocumentId, getVersion);
431
436
  return {
432
437
  fetchProvider: fetchProvider,
433
438
  writeProvider: writeProvider
434
439
  };
435
440
  };
436
- var useMemoizedBlockServiceAPIProviders = exports.useMemoizedBlockServiceAPIProviders = function useMemoizedBlockServiceAPIProviders(sourceAri, product, sourceDocumentId) {
441
+ var useMemoizedBlockServiceAPIProviders = exports.useMemoizedBlockServiceAPIProviders = function useMemoizedBlockServiceAPIProviders(sourceAri, product, sourceDocumentId, getVersion) {
437
442
  return (0, _react.useMemo)(function () {
438
- return createBlockServiceAPIProviders(sourceAri, product, sourceDocumentId);
439
- }, [sourceAri, product, sourceDocumentId]);
443
+ return createBlockServiceAPIProviders(sourceAri, product, sourceDocumentId, getVersion);
444
+ }, [sourceAri, product, sourceDocumentId, getVersion]);
440
445
  };
@@ -70,7 +70,7 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
70
70
  while (1) switch (_context.prev = _context.next) {
71
71
  case 0:
72
72
  _getPageIdAndTypeFrom = (0, _ari.getPageIdAndTypeFromConfluencePageAri)(resourceId), pageId = _getPageIdAndTypeFrom.id, pageType = _getPageIdAndTypeFrom.type;
73
- localId = (0, _ari.getLocalIdFromConfluencePageAri)(resourceId);
73
+ localId = (0, _ari.getLocalIdFromContentPropertyResourceId)(resourceId);
74
74
  _context.prev = 2;
75
75
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
76
76
  options = {
@@ -234,7 +234,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
234
234
  _match = match, pageId = _match.id, pageType = _match.type;
235
235
  _context3.prev = 9;
236
236
  // Update existing content property
237
- localId = (0, _ari.getLocalIdFromConfluencePageAri)(resourceId);
237
+ localId = (0, _ari.getLocalIdFromContentPropertyResourceId)(resourceId);
238
238
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
239
239
  sourceAri = (0, _ari.getConfluencePageAri)(pageId, this.config.cloudId, pageType);
240
240
  syncBlockDataWithSourceDocumentAri = _objectSpread(_objectSpread({}, syncBlockData), {}, {
@@ -306,7 +306,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
306
306
  case 8:
307
307
  _match2 = match, pageId = _match2.id, pageType = _match2.type;
308
308
  _context4.prev = 9;
309
- localId = (0, _ari.getLocalIdFromConfluencePageAri)(resourceId);
309
+ localId = (0, _ari.getLocalIdFromContentPropertyResourceId)(resourceId);
310
310
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
311
311
  sourceAri = (0, _ari.getConfluencePageAri)(pageId, this.config.cloudId, pageType);
312
312
  syncBlockDataWithSourceDocumentAri = _objectSpread(_objectSpread({}, syncBlockData), {}, {
@@ -359,7 +359,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
359
359
  case 7:
360
360
  _match3 = match, pageId = _match3.id, pageType = _match3.type;
361
361
  _context5.prev = 8;
362
- localId = (0, _ari.getLocalIdFromConfluencePageAri)(resourceId);
362
+ localId = (0, _ari.getLocalIdFromContentPropertyResourceId)(resourceId);
363
363
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
364
364
  options = {
365
365
  pageId: pageId,
@@ -17,7 +17,7 @@ export const generateBlockAri = (sourceAri, resourceId, product) => {
17
17
  };
18
18
 
19
19
  /**
20
- *
20
+ * Generates the block ARI from the reference synced block ARI and the resource ID
21
21
  * @param sourceAri - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
22
22
  * @param resourceId - the resource ID of the reference synced block. E.G confluence-page/pageId/sourceResourceId
23
23
  * @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
@@ -92,14 +92,19 @@ export const deleteSyncedBlock = async ({
92
92
  };
93
93
  export const updateSyncedBlock = async ({
94
94
  blockAri,
95
- content
95
+ content,
96
+ stepVersion
96
97
  }) => {
98
+ const requestBody = {
99
+ content
100
+ };
101
+ if (stepVersion !== undefined) {
102
+ requestBody.stepVersion = stepVersion;
103
+ }
97
104
  const response = await fetchWithRetry(`${BLOCK_SERVICE_API_URL}/block/${encodeURIComponent(blockAri)}`, {
98
105
  method: 'PUT',
99
106
  headers: COMMON_HEADERS,
100
- body: JSON.stringify({
101
- content
102
- })
107
+ body: JSON.stringify(requestBody)
103
108
  });
104
109
  if (!response.ok) {
105
110
  throw new BlockError(response.status);
@@ -110,18 +115,23 @@ export const createSyncedBlock = async ({
110
115
  blockInstanceId,
111
116
  sourceAri,
112
117
  product,
113
- content
118
+ content,
119
+ stepVersion
114
120
  }) => {
121
+ const requestBody = {
122
+ blockAri,
123
+ blockInstanceId,
124
+ sourceAri,
125
+ product,
126
+ content
127
+ };
128
+ if (stepVersion !== undefined) {
129
+ requestBody.stepVersion = stepVersion;
130
+ }
115
131
  const response = await fetchWithRetry(`${BLOCK_SERVICE_API_URL}/block`, {
116
132
  method: 'POST',
117
133
  headers: COMMON_HEADERS,
118
- body: JSON.stringify({
119
- blockAri,
120
- blockInstanceId,
121
- sourceAri,
122
- product,
123
- content
124
- })
134
+ body: JSON.stringify(requestBody)
125
135
  });
126
136
  if (!response.ok) {
127
137
  throw new BlockError(response.status);
@@ -1,8 +1,23 @@
1
1
  /* eslint-disable require-unicode-regexp */
2
2
 
3
+ /**
4
+ * The type of the Confluence page
5
+ */
6
+
7
+ /**
8
+ * Generates the Confluence page ARI
9
+ * @param pageId - the ID of the page
10
+ * @param cloudId - the cloud ID
11
+ * @param pageType - the type of the page
12
+ * @returns the Confluence page ARI
13
+ */
3
14
  export const getConfluencePageAri = (pageId, cloudId, pageType = 'page') => `ari:cloud:confluence:${cloudId}:${pageType}/${pageId}`;
4
15
 
5
- // For extracting from Page ARI and also the content property's version of resourceId
16
+ /**
17
+ * Extracts the page ID and type from the Confluence page ARI
18
+ * @param ari - the Confluence page ARI
19
+ * @returns the page ID and type
20
+ */
6
21
  export const getPageIdAndTypeFromConfluencePageAri = ari => {
7
22
  const match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/(\d+)/);
8
23
  if (match !== null && match !== void 0 && match[2]) {
@@ -13,20 +28,37 @@ export const getPageIdAndTypeFromConfluencePageAri = ari => {
13
28
  }
14
29
  throw new Error(`Invalid page ARI: ${ari}`);
15
30
  };
16
- export const getLocalIdFromConfluencePageAri = ari => {
17
- const match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+\/([a-zA-Z0-9-]+)/);
31
+
32
+ /**
33
+ * Extracts the local ID from the Confluence page content property resource ID
34
+ * @param resourceId - the Confluence page content property resource ID
35
+ * @returns the local ID
36
+ */
37
+ export const getLocalIdFromContentPropertyResourceId = resourceId => {
38
+ const match = resourceId.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+\/([a-zA-Z0-9-]+)/);
18
39
  if (match !== null && match !== void 0 && match[2]) {
19
40
  return match[2];
20
41
  }
21
- throw new Error(`Invalid page ARI: ${ari}`);
42
+ throw new Error(`Invalid resourceId: ${resourceId}`);
22
43
  };
23
- export const getPageARIFromContentPropertyResourceId = resourceId => {
44
+
45
+ /**
46
+ * Extracts the Confluence page ARI from the Confluence content property resource ID
47
+ * @param resourceId - the Confluence content property resource ID
48
+ * @returns the Confluence page ARI
49
+ */
50
+ export const getPageAriFromContentPropertyResourceId = resourceId => {
24
51
  const match = resourceId.match(/(ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+)\/([a-zA-Z0-9-]+)$/);
25
52
  if (match !== null && match !== void 0 && match[1]) {
26
53
  return match[1];
27
54
  }
28
55
  throw new Error(`Invalid resourceId: ${resourceId}`);
29
56
  };
30
- export const resourceIdFromConfluencePageSourceIdAndLocalId = (sourceId, localId) => {
31
- return sourceId + '/' + localId;
32
- };
57
+
58
+ /**
59
+ * Generates the Confluence page content property resource ID from the source ID and local ID
60
+ * @param sourceId - the source ID
61
+ * @param localId - the local ID
62
+ * @returns the Confluence page content property resource ID
63
+ */
64
+ export const resourceIdFromConfluencePageSourceIdAndLocalId = (sourceId, localId) => `${sourceId}/${localId}`;
@@ -0,0 +1,22 @@
1
+ /* eslint-disable require-unicode-regexp */
2
+
3
+ /**
4
+ * Generates the Jira work item ARI
5
+ * @param workItemId - the ID of the work item
6
+ * @param cloudId - the cloud ID
7
+ * @returns the Jira work item ARI
8
+ */
9
+ export const getJiraWorkItemAri = (workItemId, cloudId) => `ari:cloud:jira:${cloudId}:issue/${workItemId}`;
10
+
11
+ /**
12
+ * Extracts the Jira work item ID from the Jira work item ARI
13
+ * @param ari - the Jira work item ARI
14
+ * @returns the Jira work item ID
15
+ */
16
+ export const getJiraWorkItemIdFromAri = ari => {
17
+ const match = ari.match(/ari:cloud:jira:([^:]+):issue\/(\d+)/);
18
+ if (match !== null && match !== void 0 && match[2]) {
19
+ return match[2];
20
+ }
21
+ throw new Error(`Invalid Jira work item ARI: ${ari}`);
22
+ };
@@ -10,7 +10,8 @@ export { useHandleContentChanges } from './hooks/useHandleContentChanges';
10
10
 
11
11
  // clients
12
12
  export { generateBlockAri, generateBlockAriFromReference, getLocalIdFromBlockResourceId } from './clients/block-service/ari';
13
- export { getConfluencePageAri, getLocalIdFromConfluencePageAri, getPageARIFromContentPropertyResourceId, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId } from './clients/confluence/ari';
13
+ export { getConfluencePageAri, getLocalIdFromContentPropertyResourceId, getPageAriFromContentPropertyResourceId, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId } from './clients/confluence/ari';
14
+ export { getJiraWorkItemAri, getJiraWorkItemIdFromAri } from './clients/jira/ari';
14
15
 
15
16
  // providers
16
17
  export { useMemoizedBlockServiceAPIProviders } from './providers/block-service/blockServiceAPI';