@atlaskit/editor-synced-block-provider 3.29.2 → 3.30.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.
@@ -9,6 +9,7 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
11
  var _monitoring = require("@atlaskit/editor-common/monitoring");
12
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
13
  var _errorHandling = require("../../utils/errorHandling");
13
14
  var _retry = require("../../utils/retry");
14
15
  var _ari = require("./ari");
@@ -29,45 +30,49 @@ var GET_SOURCE_INFO_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_GET_SOURCE_INFO';
29
30
  * @param documentARI
30
31
  * @returns subType live if livePage, subType null if classic page
31
32
  */
32
- var GET_SOURCE_INFO_QUERY = "query ".concat(GET_SOURCE_INFO_OPERATION_NAME, " ($id: ID!) {\n\tcontent (id: $id) {\n\t\tnodes {\n\t\t\tid\n\t\t\tlinks {\n\t\t\t\tbase\n\t\t\t}\n\t\t\tspace {\n\t\t\t\tkey\n\t\t\t}\n\t\t\tsubType\n\t\t\ttitle\n\t\t}\n\t}\n}");
33
+ var GET_SOURCE_INFO_QUERY = "query ".concat(GET_SOURCE_INFO_OPERATION_NAME, " ($id: ID!, $status: [String]) {\n\tcontent (id: $id, status: $status) {\n\t\tnodes {\n\t\t\tid\n\t\t\tlinks {\n\t\t\t\tbase\n\t\t\t\teditui\n\t\t\t\twebui\n\t\t\t}\n\t\t\tspace {\n\t\t\t\tkey\n\t\t\t}\n\t\t\tstatus\n\t\t\tsubType\n\t\t\ttitle\n\t\t}\n\t}\n}");
33
34
  var getConfluenceSourceInfo = /*#__PURE__*/function () {
34
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(ari) {
35
- var bodyData, response;
35
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(ari, status) {
36
+ var variables, bodyData, response;
36
37
  return _regenerator.default.wrap(function _callee$(_context) {
37
38
  while (1) switch (_context.prev = _context.next) {
38
39
  case 0:
40
+ variables = {
41
+ id: ari
42
+ };
43
+ if (status) {
44
+ variables.status = status;
45
+ }
39
46
  bodyData = {
40
47
  query: GET_SOURCE_INFO_QUERY,
41
48
  operationName: GET_SOURCE_INFO_OPERATION_NAME,
42
- variables: {
43
- id: ari
44
- }
49
+ variables: variables
45
50
  };
46
- _context.next = 3;
51
+ _context.next = 5;
47
52
  return (0, _retry.fetchWithRetry)(GRAPHQL_ENDPOINT, {
48
53
  method: 'POST',
49
54
  headers: _objectSpread(_objectSpread({}, COMMON_HEADERS), AGG_HEADERS),
50
55
  body: JSON.stringify(bodyData)
51
56
  });
52
- case 3:
57
+ case 5:
53
58
  response = _context.sent;
54
59
  if (response.ok) {
55
- _context.next = 6;
60
+ _context.next = 8;
56
61
  break;
57
62
  }
58
63
  throw new Error("Failed to get url: ".concat(response.statusText));
59
- case 6:
60
- _context.next = 8;
61
- return response.json();
62
64
  case 8:
65
+ _context.next = 10;
66
+ return response.json();
67
+ case 10:
63
68
  return _context.abrupt("return", _context.sent);
64
- case 9:
69
+ case 11:
65
70
  case "end":
66
71
  return _context.stop();
67
72
  }
68
73
  }, _callee);
69
74
  }));
70
- return function getConfluenceSourceInfo(_x) {
75
+ return function getConfluenceSourceInfo(_x, _x2) {
71
76
  return _ref.apply(this, arguments);
72
77
  };
73
78
  }();
@@ -113,7 +118,7 @@ var resolveNoAccessPageInfo = /*#__PURE__*/function () {
113
118
  }
114
119
  }, _callee2);
115
120
  }));
116
- return function resolveNoAccessPageInfo(_x2) {
121
+ return function resolveNoAccessPageInfo(_x3) {
117
122
  return _ref2.apply(this, arguments);
118
123
  };
119
124
  }();
@@ -179,13 +184,13 @@ var fetchCompleteConfluencePageInfo = /*#__PURE__*/function () {
179
184
  }
180
185
  }, _callee3, null, [[0, 18]]);
181
186
  }));
182
- return function fetchCompleteConfluencePageInfo(_x3, _x4) {
187
+ return function fetchCompleteConfluencePageInfo(_x4, _x5) {
183
188
  return _ref3.apply(this, arguments);
184
189
  };
185
190
  }();
186
191
  var fetchConfluencePageInfoOld = exports.fetchConfluencePageInfoOld = /*#__PURE__*/function () {
187
192
  var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(pageAri, localId, fireAnalyticsEvent) {
188
- var _response$data, _contentData$space, _getPageIdAndTypeFrom2, pageType, response, contentData, title, url, _ref5, base;
193
+ var _response$data, _contentData$space, _getPageIdAndTypeFrom2, pageType, status, response, contentData, title, url, _ref5, base;
189
194
  return _regenerator.default.wrap(function _callee4$(_context4) {
190
195
  while (1) switch (_context4.prev = _context4.next) {
191
196
  case 0:
@@ -193,9 +198,10 @@ var fetchConfluencePageInfoOld = exports.fetchConfluencePageInfoOld = /*#__PURE_
193
198
  _getPageIdAndTypeFrom2 = (0, _ari.getPageIdAndTypeFromConfluencePageAri)({
194
199
  ari: pageAri
195
200
  }), pageType = _getPageIdAndTypeFrom2.type;
196
- _context4.next = 4;
197
- return getConfluenceSourceInfo(pageAri);
198
- case 4:
201
+ status = (0, _platformFeatureFlags.fg)('platform_synced_block_patch_3') ? ['draft', 'archived', 'current'] : undefined;
202
+ _context4.next = 5;
203
+ return getConfluenceSourceInfo(pageAri, status);
204
+ case 5:
199
205
  response = _context4.sent;
200
206
  contentData = (_response$data = response.data) === null || _response$data === void 0 || (_response$data = _response$data.content) === null || _response$data === void 0 || (_response$data = _response$data.nodes) === null || _response$data === void 0 ? void 0 : _response$data[0];
201
207
  title = contentData === null || contentData === void 0 ? void 0 : contentData.title;
@@ -218,31 +224,31 @@ var fetchConfluencePageInfoOld = exports.fetchConfluencePageInfoOld = /*#__PURE_
218
224
  url: url,
219
225
  sourceAri: pageAri
220
226
  }));
221
- case 14:
222
- _context4.prev = 14;
227
+ case 15:
228
+ _context4.prev = 15;
223
229
  _context4.t0 = _context4["catch"](0);
224
230
  (0, _monitoring.logException)(_context4.t0, {
225
231
  location: 'editor-synced-block-provider/sourceInfo'
226
232
  });
227
233
  fireAnalyticsEvent === null || fireAnalyticsEvent === void 0 || fireAnalyticsEvent((0, _errorHandling.getSourceInfoErrorPayload)(_context4.t0.message));
228
234
  return _context4.abrupt("return", Promise.resolve(undefined));
229
- case 19:
235
+ case 20:
230
236
  case "end":
231
237
  return _context4.stop();
232
238
  }
233
- }, _callee4, null, [[0, 14]]);
239
+ }, _callee4, null, [[0, 15]]);
234
240
  }));
235
- return function fetchConfluencePageInfoOld(_x5, _x6, _x7) {
241
+ return function fetchConfluencePageInfoOld(_x6, _x7, _x8) {
236
242
  return _ref4.apply(this, arguments);
237
243
  };
238
244
  }();
239
245
  var fetchConfluencePageInfo = exports.fetchConfluencePageInfo = /*#__PURE__*/function () {
240
246
  var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(pageAri, hasAccess, urlType, localId, isUnpublished) {
241
- var _response$data2, _contentData$space2, _getPageIdAndTypeFrom3, pageType, response, contentData, _ref7, title, subType, url, _ref8, base;
247
+ var _response$data2, _getPageIdAndTypeFrom3, pageType, status, response, contentData, _ref7, title, subType, url, _ref8, base, editui, webui, pageStatus, _contentData$space2;
242
248
  return _regenerator.default.wrap(function _callee5$(_context5) {
243
249
  while (1) switch (_context5.prev = _context5.next) {
244
250
  case 0:
245
- if (!isUnpublished) {
251
+ if (!(isUnpublished && !(0, _platformFeatureFlags.fg)('platform_synced_block_patch_3'))) {
246
252
  _context5.next = 4;
247
253
  break;
248
254
  }
@@ -252,26 +258,36 @@ var fetchConfluencePageInfo = exports.fetchConfluencePageInfo = /*#__PURE__*/fun
252
258
  return _context5.abrupt("return", _context5.sent);
253
259
  case 4:
254
260
  if (!hasAccess) {
255
- _context5.next = 17;
261
+ _context5.next = 19;
256
262
  break;
257
263
  }
258
264
  _getPageIdAndTypeFrom3 = (0, _ari.getPageIdAndTypeFromConfluencePageAri)({
259
265
  ari: pageAri
260
266
  }), pageType = _getPageIdAndTypeFrom3.type;
261
- _context5.next = 8;
262
- return getConfluenceSourceInfo(pageAri);
263
- case 8:
267
+ status = (0, _platformFeatureFlags.fg)('platform_synced_block_patch_3') ? ['draft', 'archived'] : undefined;
268
+ _context5.next = 9;
269
+ return getConfluenceSourceInfo(pageAri, status);
270
+ case 9:
264
271
  response = _context5.sent;
265
272
  contentData = (_response$data2 = response.data) === null || _response$data2 === void 0 || (_response$data2 = _response$data2.content) === null || _response$data2 === void 0 || (_response$data2 = _response$data2.nodes) === null || _response$data2 === void 0 ? void 0 : _response$data2[0];
266
273
  _ref7 = contentData || {}, title = _ref7.title, subType = _ref7.subType;
267
- _ref8 = (contentData === null || contentData === void 0 ? void 0 : contentData.links) || {}, base = _ref8.base;
268
- if (base && contentData !== null && contentData !== void 0 && (_contentData$space2 = contentData.space) !== null && _contentData$space2 !== void 0 && _contentData$space2.key && contentData !== null && contentData !== void 0 && contentData.id) {
269
- if ((0, _utils.isBlogPageType)(pageType)) {
270
- url = "".concat(base, "/spaces/").concat(contentData.space.key, "/blog").concat(urlType === 'edit' ? '/edit-v2' : '', "/").concat(contentData.id);
271
- } else if (contentData.subType === 'live') {
272
- url = "".concat(base, "/spaces/").concat(contentData.space.key, "/pages/").concat(contentData.id);
273
- } else {
274
- url = "".concat(base, "/spaces/").concat(contentData.space.key, "/pages").concat(urlType === 'edit' ? '/edit-v2' : '', "/").concat(contentData.id);
274
+ _ref8 = (contentData === null || contentData === void 0 ? void 0 : contentData.links) || {}, base = _ref8.base, editui = _ref8.editui, webui = _ref8.webui;
275
+ pageStatus = contentData === null || contentData === void 0 ? void 0 : contentData.status;
276
+ if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_3')) {
277
+ if (base && editui && pageStatus !== 'archived') {
278
+ url = "".concat(base).concat(editui);
279
+ } else if (base && webui && pageStatus === 'archived') {
280
+ url = "".concat(base).concat(webui);
281
+ }
282
+ } else {
283
+ if (base && contentData !== null && contentData !== void 0 && (_contentData$space2 = contentData.space) !== null && _contentData$space2 !== void 0 && _contentData$space2.key && contentData !== null && contentData !== void 0 && contentData.id) {
284
+ if ((0, _utils.isBlogPageType)(pageType)) {
285
+ url = "".concat(base, "/spaces/").concat(contentData.space.key, "/blog").concat(urlType === 'edit' ? '/edit-v2' : '', "/").concat(contentData.id);
286
+ } else if (contentData.subType === 'live') {
287
+ url = "".concat(base, "/spaces/").concat(contentData.space.key, "/pages/").concat(contentData.id);
288
+ } else {
289
+ url = "".concat(base, "/spaces/").concat(contentData.space.key, "/pages").concat(urlType === 'edit' ? '/edit-v2' : '', "/").concat(contentData.id);
290
+ }
275
291
  }
276
292
  }
277
293
  url = url && localId ? "".concat(url, "#block-").concat(localId) : url;
@@ -281,18 +297,18 @@ var fetchConfluencePageInfo = exports.fetchConfluencePageInfo = /*#__PURE__*/fun
281
297
  sourceAri: pageAri,
282
298
  subType: subType
283
299
  }));
284
- case 17:
285
- _context5.next = 19;
286
- return resolveNoAccessPageInfo(pageAri);
287
300
  case 19:
301
+ _context5.next = 21;
302
+ return resolveNoAccessPageInfo(pageAri);
303
+ case 21:
288
304
  return _context5.abrupt("return", _context5.sent);
289
- case 20:
305
+ case 22:
290
306
  case "end":
291
307
  return _context5.stop();
292
308
  }
293
309
  }, _callee5);
294
310
  }));
295
- return function fetchConfluencePageInfo(_x8, _x9, _x0, _x1, _x10) {
311
+ return function fetchConfluencePageInfo(_x9, _x0, _x1, _x10, _x11) {
296
312
  return _ref6.apply(this, arguments);
297
313
  };
298
314
  }();
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.resolveSyncBlockInstance = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
+ var _ari = require("../clients/confluence/ari");
9
11
  var _types = require("../common/types");
10
12
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
13
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -40,8 +42,30 @@ var resolveSyncBlockInstance = exports.resolveSyncBlockInstance = function resol
40
42
  data: _objectSpread(_objectSpread({}, newResult.data), {}, {
41
43
  sourceURL: ((_newResult$data = newResult.data) === null || _newResult$data === void 0 ? void 0 : _newResult$data.sourceURL) || ((_oldResult$data = oldResult.data) === null || _oldResult$data === void 0 ? void 0 : _oldResult$data.sourceURL) || undefined,
42
44
  sourceTitle: ((_newResult$data2 = newResult.data) === null || _newResult$data2 === void 0 ? void 0 : _newResult$data2.sourceTitle) || ((_oldResult$data2 = oldResult.data) === null || _oldResult$data2 === void 0 ? void 0 : _oldResult$data2.sourceTitle) || undefined,
43
- sourceSubType: ((_newResult$data3 = newResult.data) === null || _newResult$data3 === void 0 ? void 0 : _newResult$data3.sourceSubType) || ((_oldResult$data3 = oldResult.data) === null || _oldResult$data3 === void 0 ? void 0 : _oldResult$data3.sourceSubType) || undefined,
45
+ sourceSubType: (0, _platformFeatureFlags.fg)('platform_synced_block_patch_3') ? mergeSubType(oldResult, newResult) : ((_newResult$data3 = newResult.data) === null || _newResult$data3 === void 0 ? void 0 : _newResult$data3.sourceSubType) || ((_oldResult$data3 = oldResult.data) === null || _oldResult$data3 === void 0 ? void 0 : _oldResult$data3.sourceSubType) || undefined,
44
46
  onSameDocument: ((_newResult$data4 = newResult.data) === null || _newResult$data4 === void 0 ? void 0 : _newResult$data4.onSameDocument) || ((_oldResult$data4 = oldResult.data) === null || _oldResult$data4 === void 0 ? void 0 : _oldResult$data4.onSameDocument) || undefined
45
47
  })
46
48
  });
49
+ };
50
+ var mergeSubType = function mergeSubType(oldResult, newResult) {
51
+ var _newResult$data5, _newResult$data6, _oldResult$data5;
52
+ // for classic pages, subType is 'null'
53
+ if (((_newResult$data5 = newResult.data) === null || _newResult$data5 === void 0 ? void 0 : _newResult$data5.sourceSubType) !== undefined) {
54
+ return newResult.data.sourceSubType;
55
+ }
56
+ if ((_newResult$data6 = newResult.data) !== null && _newResult$data6 !== void 0 && _newResult$data6.sourceAri) {
57
+ // for blogposts, subType is always undefined
58
+ try {
59
+ var _newResult$data7;
60
+ var _getPageIdAndTypeFrom = (0, _ari.getPageIdAndTypeFromConfluencePageAri)({
61
+ ari: (_newResult$data7 = newResult.data) === null || _newResult$data7 === void 0 ? void 0 : _newResult$data7.sourceAri
62
+ }),
63
+ pageType = _getPageIdAndTypeFrom.type;
64
+ if (pageType === 'blogpost') {
65
+ var _newResult$data8;
66
+ return (_newResult$data8 = newResult.data) === null || _newResult$data8 === void 0 ? void 0 : _newResult$data8.sourceSubType;
67
+ }
68
+ } catch (_unused) {}
69
+ }
70
+ return (_oldResult$data5 = oldResult.data) === null || _oldResult$data5 === void 0 ? void 0 : _oldResult$data5.sourceSubType;
47
71
  };
@@ -1,3 +1,4 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
1
2
  import { fetchWithRetry } from '../../utils/retry';
2
3
  export const isBlockContentResponse = response => {
3
4
  const content = response.content;
@@ -49,7 +50,8 @@ export const getReferenceSyncedBlocks = async documentAri => {
49
50
  query: buildGetDocumentReferenceBlocksQuery(documentAri),
50
51
  operationName: GET_DOCUMENT_REFERENCE_BLOCKS_OPERATION_NAME
51
52
  };
52
- const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
53
+ const url = fg('platform_synced_block_patch_3') ? `${GRAPHQL_ENDPOINT}?operation=editorSyncedBlockGetDocumentReferenceBlocks` : GRAPHQL_ENDPOINT;
54
+ const response = await fetchWithRetry(url, {
53
55
  method: 'POST',
54
56
  headers: COMMON_HEADERS,
55
57
  body: JSON.stringify(bodyData)
@@ -263,7 +265,8 @@ export const getSyncedBlockContent = async ({
263
265
  query: buildGetBlockQuery(blockAri),
264
266
  operationName: GET_BLOCK_OPERATION_NAME
265
267
  };
266
- const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
268
+ const url = fg('platform_synced_block_patch_3') ? `${GRAPHQL_ENDPOINT}?operation=editorSyncedBlockGetBlock` : GRAPHQL_ENDPOINT;
269
+ const response = await fetchWithRetry(url, {
267
270
  method: 'POST',
268
271
  headers: COMMON_HEADERS,
269
272
  body: JSON.stringify(bodyData)
@@ -298,7 +301,8 @@ export const batchRetrieveSyncedBlocks = async ({
298
301
  query: buildBatchRetrieveBlocksQuery(blockAris),
299
302
  operationName: BATCH_RETRIEVE_BLOCKS_OPERATION_NAME
300
303
  };
301
- const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
304
+ const url = fg('platform_synced_block_patch_3') ? `${GRAPHQL_ENDPOINT}?operation=editorSyncedBlockBatchRetrieveBlocks` : GRAPHQL_ENDPOINT;
305
+ const response = await fetchWithRetry(url, {
302
306
  method: 'POST',
303
307
  headers: COMMON_HEADERS,
304
308
  body: JSON.stringify(bodyData)
@@ -328,7 +332,8 @@ export const deleteSyncedBlock = async ({
328
332
  query: buildDeleteBlockMutation(blockAri, deleteReason),
329
333
  operationName: DELETE_BLOCK_OPERATION_NAME
330
334
  };
331
- const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
335
+ const url = fg('platform_synced_block_patch_3') ? `${GRAPHQL_ENDPOINT}?operation=editorSyncedBlockDeleteBlock` : GRAPHQL_ENDPOINT;
336
+ const response = await fetchWithRetry(url, {
332
337
  method: 'POST',
333
338
  headers: COMMON_HEADERS,
334
339
  body: JSON.stringify(bodyData)
@@ -354,7 +359,8 @@ export const updateSyncedBlock = async ({
354
359
  query: buildUpdateBlockMutation(blockAri, content, stepVersion, status),
355
360
  operationName: UPDATE_BLOCK_OPERATION_NAME
356
361
  };
357
- const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
362
+ const url = fg('platform_synced_block_patch_3') ? `${GRAPHQL_ENDPOINT}?operation=editorSyncedBlockUpdateBlock` : GRAPHQL_ENDPOINT;
363
+ const response = await fetchWithRetry(url, {
358
364
  method: 'POST',
359
365
  headers: COMMON_HEADERS,
360
366
  body: JSON.stringify(bodyData)
@@ -381,7 +387,8 @@ export const createSyncedBlock = async ({
381
387
  query: buildCreateBlockMutation(blockAri, blockInstanceId, content, product, sourceAri, stepVersion, status),
382
388
  operationName: CREATE_BLOCK_OPERATION_NAME
383
389
  };
384
- const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
390
+ const url = fg('platform_synced_block_patch_3') ? `${GRAPHQL_ENDPOINT}?operation=editorSyncedBlockCreateBlock` : GRAPHQL_ENDPOINT;
391
+ const response = await fetchWithRetry(url, {
385
392
  method: 'POST',
386
393
  headers: COMMON_HEADERS,
387
394
  body: JSON.stringify(bodyData)
@@ -407,7 +414,8 @@ export const updateReferenceSyncedBlockOnDocument = async ({
407
414
  query: buildUpdateDocumentReferencesMutation(documentAri, blocks, noContent),
408
415
  operationName: UPDATE_DOCUMENT_REFERENCES_OPERATION_NAME
409
416
  };
410
- const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
417
+ const url = fg('platform_synced_block_patch_3') ? `${GRAPHQL_ENDPOINT}?operation=editorSyncedBlockUpdateDocumentReferences` : GRAPHQL_ENDPOINT;
418
+ const response = await fetchWithRetry(url, {
411
419
  method: 'POST',
412
420
  headers: COMMON_HEADERS,
413
421
  body: JSON.stringify(bodyData),
@@ -436,7 +444,8 @@ export const getReferenceSyncedBlocksByBlockAri = async ({
436
444
  query: buildGetBlockReferencesQuery(blockAri),
437
445
  operationName: GET_BLOCK_REFERENCES_OPERATION_NAME
438
446
  };
439
- const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
447
+ const url = fg('platform_synced_block_patch_3') ? `${GRAPHQL_ENDPOINT}?operation=editorSyncedBlockGetReferences` : GRAPHQL_ENDPOINT;
448
+ const response = await fetchWithRetry(url, {
440
449
  method: 'POST',
441
450
  headers: COMMON_HEADERS,
442
451
  body: JSON.stringify(bodyData)
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable require-unicode-regexp */
2
2
 
3
3
  import { logException } from '@atlaskit/editor-common/monitoring';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
4
5
  import { getSourceInfoErrorPayload } from '../../utils/errorHandling';
5
6
  import { fetchWithRetry } from '../../utils/retry';
6
7
  import { getPageIdAndTypeFromConfluencePageAri } from './ari';
@@ -19,28 +20,35 @@ const GET_SOURCE_INFO_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_GET_SOURCE_INFO';
19
20
  * @param documentARI
20
21
  * @returns subType live if livePage, subType null if classic page
21
22
  */
22
- const GET_SOURCE_INFO_QUERY = `query ${GET_SOURCE_INFO_OPERATION_NAME} ($id: ID!) {
23
- content (id: $id) {
23
+ const GET_SOURCE_INFO_QUERY = `query ${GET_SOURCE_INFO_OPERATION_NAME} ($id: ID!, $status: [String]) {
24
+ content (id: $id, status: $status) {
24
25
  nodes {
25
26
  id
26
27
  links {
27
28
  base
29
+ editui
30
+ webui
28
31
  }
29
32
  space {
30
33
  key
31
34
  }
35
+ status
32
36
  subType
33
37
  title
34
38
  }
35
39
  }
36
40
  }`;
37
- const getConfluenceSourceInfo = async ari => {
41
+ const getConfluenceSourceInfo = async (ari, status) => {
42
+ const variables = {
43
+ id: ari
44
+ };
45
+ if (status) {
46
+ variables.status = status;
47
+ }
38
48
  const bodyData = {
39
49
  query: GET_SOURCE_INFO_QUERY,
40
50
  operationName: GET_SOURCE_INFO_OPERATION_NAME,
41
- variables: {
42
- id: ari
43
- }
51
+ variables
44
52
  };
45
53
  const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
46
54
  method: 'POST',
@@ -134,7 +142,8 @@ export const fetchConfluencePageInfoOld = async (pageAri, localId, fireAnalytics
134
142
  } = getPageIdAndTypeFromConfluencePageAri({
135
143
  ari: pageAri
136
144
  });
137
- const response = await getConfluenceSourceInfo(pageAri);
145
+ const status = fg('platform_synced_block_patch_3') ? ['draft', 'archived', 'current'] : undefined;
146
+ const response = await getConfluenceSourceInfo(pageAri, status);
138
147
  const contentData = (_response$data = response.data) === null || _response$data === void 0 ? void 0 : (_response$data$conten = _response$data.content) === null || _response$data$conten === void 0 ? void 0 : (_response$data$conten2 = _response$data$conten.nodes) === null || _response$data$conten2 === void 0 ? void 0 : _response$data$conten2[0];
139
148
  const title = contentData === null || contentData === void 0 ? void 0 : contentData.title;
140
149
  let url;
@@ -169,17 +178,19 @@ export const fetchConfluencePageInfoOld = async (pageAri, localId, fireAnalytics
169
178
  };
170
179
  export const fetchConfluencePageInfo = async (pageAri, hasAccess, urlType, localId, isUnpublished) => {
171
180
  // For unpublished pages, use the v2 pages API as GraphQL returns empty content.nodes
172
- if (isUnpublished) {
181
+ // We don't want to use the Rest API at all because it doesn't work if accessed from a custom base URL (e.g in Jira)
182
+ if (isUnpublished && !fg('platform_synced_block_patch_3')) {
173
183
  return await fetchCompleteConfluencePageInfo(pageAri, localId);
174
184
  }
175
185
  if (hasAccess) {
176
- var _response$data2, _response$data2$conte, _response$data2$conte2, _contentData$space2;
186
+ var _response$data2, _response$data2$conte, _response$data2$conte2;
177
187
  const {
178
188
  type: pageType
179
189
  } = getPageIdAndTypeFromConfluencePageAri({
180
190
  ari: pageAri
181
191
  });
182
- const response = await getConfluenceSourceInfo(pageAri);
192
+ const status = fg('platform_synced_block_patch_3') ? ['draft', 'archived'] : undefined;
193
+ const response = await getConfluenceSourceInfo(pageAri, status);
183
194
  const contentData = (_response$data2 = response.data) === null || _response$data2 === void 0 ? void 0 : (_response$data2$conte = _response$data2.content) === null || _response$data2$conte === void 0 ? void 0 : (_response$data2$conte2 = _response$data2$conte.nodes) === null || _response$data2$conte2 === void 0 ? void 0 : _response$data2$conte2[0];
184
195
  const {
185
196
  title,
@@ -187,15 +198,27 @@ export const fetchConfluencePageInfo = async (pageAri, hasAccess, urlType, local
187
198
  } = contentData || {};
188
199
  let url;
189
200
  const {
190
- base
201
+ base,
202
+ editui,
203
+ webui
191
204
  } = (contentData === null || contentData === void 0 ? void 0 : contentData.links) || {};
192
- if (base && contentData !== null && contentData !== void 0 && (_contentData$space2 = contentData.space) !== null && _contentData$space2 !== void 0 && _contentData$space2.key && contentData !== null && contentData !== void 0 && contentData.id) {
193
- if (isBlogPageType(pageType)) {
194
- url = `${base}/spaces/${contentData.space.key}/blog${urlType === 'edit' ? '/edit-v2' : ''}/${contentData.id}`;
195
- } else if (contentData.subType === 'live') {
196
- url = `${base}/spaces/${contentData.space.key}/pages/${contentData.id}`;
197
- } else {
198
- url = `${base}/spaces/${contentData.space.key}/pages${urlType === 'edit' ? '/edit-v2' : ''}/${contentData.id}`;
205
+ const pageStatus = contentData === null || contentData === void 0 ? void 0 : contentData.status;
206
+ if (fg('platform_synced_block_patch_3')) {
207
+ if (base && editui && pageStatus !== 'archived') {
208
+ url = `${base}${editui}`;
209
+ } else if (base && webui && pageStatus === 'archived') {
210
+ url = `${base}${webui}`;
211
+ }
212
+ } else {
213
+ var _contentData$space2;
214
+ if (base && contentData !== null && contentData !== void 0 && (_contentData$space2 = contentData.space) !== null && _contentData$space2 !== void 0 && _contentData$space2.key && contentData !== null && contentData !== void 0 && contentData.id) {
215
+ if (isBlogPageType(pageType)) {
216
+ url = `${base}/spaces/${contentData.space.key}/blog${urlType === 'edit' ? '/edit-v2' : ''}/${contentData.id}`;
217
+ } else if (contentData.subType === 'live') {
218
+ url = `${base}/spaces/${contentData.space.key}/pages/${contentData.id}`;
219
+ } else {
220
+ url = `${base}/spaces/${contentData.space.key}/pages${urlType === 'edit' ? '/edit-v2' : ''}/${contentData.id}`;
221
+ }
199
222
  }
200
223
  }
201
224
  url = url && localId ? `${url}#block-${localId}` : url;
@@ -1,3 +1,5 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
2
+ import { getPageIdAndTypeFromConfluencePageAri } from '../clients/confluence/ari';
1
3
  import { SyncBlockError } from '../common/types';
2
4
  /**
3
5
  * Merges two SyncBlockInstance objects,
@@ -32,8 +34,31 @@ export const resolveSyncBlockInstance = (oldResult, newResult) => {
32
34
  ...newResult.data,
33
35
  sourceURL: ((_newResult$data = newResult.data) === null || _newResult$data === void 0 ? void 0 : _newResult$data.sourceURL) || ((_oldResult$data = oldResult.data) === null || _oldResult$data === void 0 ? void 0 : _oldResult$data.sourceURL) || undefined,
34
36
  sourceTitle: ((_newResult$data2 = newResult.data) === null || _newResult$data2 === void 0 ? void 0 : _newResult$data2.sourceTitle) || ((_oldResult$data2 = oldResult.data) === null || _oldResult$data2 === void 0 ? void 0 : _oldResult$data2.sourceTitle) || undefined,
35
- sourceSubType: ((_newResult$data3 = newResult.data) === null || _newResult$data3 === void 0 ? void 0 : _newResult$data3.sourceSubType) || ((_oldResult$data3 = oldResult.data) === null || _oldResult$data3 === void 0 ? void 0 : _oldResult$data3.sourceSubType) || undefined,
37
+ sourceSubType: fg('platform_synced_block_patch_3') ? mergeSubType(oldResult, newResult) : ((_newResult$data3 = newResult.data) === null || _newResult$data3 === void 0 ? void 0 : _newResult$data3.sourceSubType) || ((_oldResult$data3 = oldResult.data) === null || _oldResult$data3 === void 0 ? void 0 : _oldResult$data3.sourceSubType) || undefined,
36
38
  onSameDocument: ((_newResult$data4 = newResult.data) === null || _newResult$data4 === void 0 ? void 0 : _newResult$data4.onSameDocument) || ((_oldResult$data4 = oldResult.data) === null || _oldResult$data4 === void 0 ? void 0 : _oldResult$data4.onSameDocument) || undefined
37
39
  }
38
40
  };
41
+ };
42
+ const mergeSubType = (oldResult, newResult) => {
43
+ var _newResult$data5, _newResult$data6, _oldResult$data5;
44
+ // for classic pages, subType is 'null'
45
+ if (((_newResult$data5 = newResult.data) === null || _newResult$data5 === void 0 ? void 0 : _newResult$data5.sourceSubType) !== undefined) {
46
+ return newResult.data.sourceSubType;
47
+ }
48
+ if ((_newResult$data6 = newResult.data) !== null && _newResult$data6 !== void 0 && _newResult$data6.sourceAri) {
49
+ // for blogposts, subType is always undefined
50
+ try {
51
+ var _newResult$data7;
52
+ const {
53
+ type: pageType
54
+ } = getPageIdAndTypeFromConfluencePageAri({
55
+ ari: (_newResult$data7 = newResult.data) === null || _newResult$data7 === void 0 ? void 0 : _newResult$data7.sourceAri
56
+ });
57
+ if (pageType === 'blogpost') {
58
+ var _newResult$data8;
59
+ return (_newResult$data8 = newResult.data) === null || _newResult$data8 === void 0 ? void 0 : _newResult$data8.sourceSubType;
60
+ }
61
+ } catch {}
62
+ }
63
+ return (_oldResult$data5 = oldResult.data) === null || _oldResult$data5 === void 0 ? void 0 : _oldResult$data5.sourceSubType;
39
64
  };