@atlaskit/editor-synced-block-provider 19.0.1 → 20.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 20.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`a5e4fa298e7ad`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a5e4fa298e7ad) -
8
+ [EDITOR-8408] Synced locations that the viewer cannot access now show as 'Restricted content' with
9
+ a lock icon, link to the restricted page, and never expose the current page's title. They still
10
+ count in the synced locations total and the delete warning. Behind the
11
+ platform_editor_blocks_patch_11 experiment.
12
+ - Updated dependencies
13
+
14
+ ## 20.0.0
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies
19
+
3
20
  ## 19.0.1
4
21
 
5
22
  ### Patch Changes
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getProductFromSourceAri = exports.getLocationScope = exports.getLocalIdFromBlockResourceId = exports.generateBlockAriFromReference = exports.generateBlockAri = void 0;
7
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
7
8
  var _ari = require("../jira/ari");
8
9
  /* eslint-disable require-unicode-regexp */
9
10
 
@@ -80,6 +81,9 @@ var getLocationScope = exports.getLocationScope = function getLocationScope(_ref
80
81
  return location.fieldId === hostLocation.fieldId ? 'same-document' : 'same-parent-document';
81
82
  };
82
83
  var getProductFromSourceAri = exports.getProductFromSourceAri = function getProductFromSourceAri(ari) {
84
+ if (!ari && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_blocks_patch_11')) {
85
+ return undefined;
86
+ }
83
87
  var jiraMatch = ari === null || ari === void 0 ? void 0 : ari.search(JIRA_SOURCE_ARI_REGEX);
84
88
  if (jiraMatch !== -1) {
85
89
  return 'jira-work-item';
@@ -13,6 +13,7 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
13
13
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
14
  var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
15
15
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
16
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
16
17
  var _retry = require("../../utils/retry");
17
18
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
18
19
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
@@ -199,7 +200,7 @@ var buildBatchRetrieveBlocksQuery = function buildBatchRetrieveBlocksQuery(block
199
200
  return "query ".concat(BATCH_RETRIEVE_BLOCKS_OPERATION_NAME, " {\n\tblockService_batchRetrieveBlocks(input: { ").concat(inputArgs, " }) {\n\t\tsuccess {\n\t\t\tblockAri\n\t\t\tblockInstanceId\n\t\t\tcontent\n\t\t\tcontentUpdatedAt\n\t\t\tcreatedAt\n\t\t\tcreatedBy\n\t\t\tdeletionReason\n\t\t\tproduct\n\t\t\tsourceAri\n\t\t\tstatus\n\t\t\tversion\n\t\t}\n\t\terror {\n\t\t\tblockAri\n\t\t\tcode\n\t\t\treason\n\t\t}\n\t}\n}");
200
201
  };
201
202
  var buildGetBlockReferencesQuery = function buildGetBlockReferencesQuery(blockAri) {
202
- return "query ".concat(GET_BLOCK_REFERENCES_OPERATION_NAME, " {\n\tblockService_getReferences(blockAri: ").concat(JSON.stringify(blockAri), ") {\n\t\treferences {\n\t\t\tblockAri\n\t\t\tblockInstanceId\n\t\t\tcreatedAt\n\t\t\tcreatedBy\n\t\t\tdocumentAri\n\t\t}\n\t\terrors {\n\t\t\tblockAri\n\t\t\tcode\n\t\t\treason\n\t\t}\n\t}\n}");
203
+ return "query ".concat(GET_BLOCK_REFERENCES_OPERATION_NAME, " {\n\tblockService_getReferences(blockAri: ").concat(JSON.stringify(blockAri), ") {\n\t\treferences {\n\t\t\tblockAri\n\t\t\tblockInstanceId\n\t\t\tcreatedAt\n\t\t\tcreatedBy\n\t\t\tdocumentAri\n\t\t}\n\t\terrors {\n\t\t\tblockAri\n\t\t\tcode").concat((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_blocks_patch_11') ? '\n\t\t\tdocumentAri' : '', "\n\t\t\treason\n\t\t}\n\t}\n}");
203
204
  };
204
205
  var buildBatchUpdateBlocksMutation = function buildBatchUpdateBlocksMutation(blocks) {
205
206
  var blocksArray = blocks.map(function (block) {
@@ -12,6 +12,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
12
12
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
13
  var _react = require("react");
14
14
  var _monitoring = require("@atlaskit/editor-common/monitoring");
15
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
15
16
  var _ari = require("../clients/block-service/ari");
16
17
  var _types = require("../common/types");
17
18
  var _errorHandling = require("../utils/errorHandling");
@@ -89,20 +90,26 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
89
90
  return _regenerator.default.wrap(function (_context) {
90
91
  while (1) switch (_context.prev = _context.next) {
91
92
  case 0:
93
+ if (!(!reference.hasAccess && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_blocks_patch_11'))) {
94
+ _context.next = 1;
95
+ break;
96
+ }
97
+ return _context.abrupt("return", _this.fetchRestrictedReferenceInfo(reference.documentAri));
98
+ case 1:
92
99
  (_this$fetchSourceInfo = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.start();
93
- _context.next = 1;
100
+ _context.next = 2;
94
101
  return (_this$dataProvider = _this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(reference.blockInstanceId || '', reference.documentAri, (0, _ari.getProductFromSourceAri)(reference.documentAri), reference.hasAccess);
95
- case 1:
102
+ case 2:
96
103
  sourceInfo = _context.sent;
97
104
  if (sourceInfo) {
98
- _context.next = 2;
105
+ _context.next = 3;
99
106
  break;
100
107
  }
101
108
  (_this$fetchSourceInfo2 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.failure({
102
109
  reason: "no source info returned for ari: ".concat(reference.documentAri)
103
110
  });
104
111
  return _context.abrupt("return", undefined);
105
- case 2:
112
+ case 3:
106
113
  (_this$fetchSourceInfo3 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 || _this$fetchSourceInfo3.success();
107
114
  return _context.abrupt("return", _objectSpread(_objectSpread(_objectSpread({}, sourceInfo), {}, {
108
115
  onSameDocument: reference.onSameDocument
@@ -112,7 +119,7 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
112
119
  hasAccess: reference.hasAccess,
113
120
  productType: sourceInfo.productType
114
121
  }));
115
- case 3:
122
+ case 4:
116
123
  case "end":
117
124
  return _context.stop();
118
125
  }
@@ -194,17 +201,77 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
194
201
  reason: 'editorDestroyed'
195
202
  });
196
203
  }
204
+
205
+ /**
206
+ * Keeps only the link of a location the user cannot read, so its title never reaches the UI.
207
+ * The location still counts when the link cannot be resolved or there is no document to link to.
208
+ */
209
+ }, {
210
+ key: "fetchRestrictedReferenceInfo",
211
+ value: (function () {
212
+ var _fetchRestrictedReferenceInfo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(documentAri) {
213
+ var _this$fetchSourceInfo5;
214
+ var productType, url, _this$dataProvider2, _this$fetchSourceInfo6, sourceInfo, _this$fetchSourceInfo7, _t2;
215
+ return _regenerator.default.wrap(function (_context3) {
216
+ while (1) switch (_context3.prev = _context3.next) {
217
+ case 0:
218
+ if (documentAri) {
219
+ _context3.next = 1;
220
+ break;
221
+ }
222
+ return _context3.abrupt("return", {
223
+ sourceAri: '',
224
+ hasAccess: false,
225
+ onSameDocument: false
226
+ });
227
+ case 1:
228
+ productType = (0, _ari.getProductFromSourceAri)(documentAri);
229
+ (_this$fetchSourceInfo5 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo5 === void 0 || _this$fetchSourceInfo5.start();
230
+ _context3.prev = 2;
231
+ _context3.next = 3;
232
+ return (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.fetchSyncBlockSourceInfo(undefined, documentAri, productType, false);
233
+ case 3:
234
+ sourceInfo = _context3.sent;
235
+ url = sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url;
236
+ (_this$fetchSourceInfo6 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo6 === void 0 || _this$fetchSourceInfo6.success();
237
+ _context3.next = 5;
238
+ break;
239
+ case 4:
240
+ _context3.prev = 4;
241
+ _t2 = _context3["catch"](2);
242
+ (_this$fetchSourceInfo7 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo7 === void 0 || _this$fetchSourceInfo7.failure({
243
+ reason: _t2.message
244
+ });
245
+ case 5:
246
+ return _context3.abrupt("return", {
247
+ sourceAri: documentAri,
248
+ productType: productType,
249
+ url: url,
250
+ hasAccess: false,
251
+ onSameDocument: false
252
+ });
253
+ case 6:
254
+ case "end":
255
+ return _context3.stop();
256
+ }
257
+ }, _callee3, this, [[2, 4]]);
258
+ }));
259
+ function fetchRestrictedReferenceInfo(_x5) {
260
+ return _fetchRestrictedReferenceInfo.apply(this, arguments);
261
+ }
262
+ return fetchRestrictedReferenceInfo;
263
+ }())
197
264
  }, {
198
265
  key: "getUnregisteredReferences",
199
266
  value: function () {
200
- var _getUnregisteredReferences = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resourceId, blockInstanceId, isSourceSyncBlock) {
267
+ var _getUnregisteredReferences = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(resourceId, blockInstanceId, isSourceSyncBlock) {
201
268
  var _this$fetchReferences8;
202
269
  var _this$fetchReferences6, referenceResourceId, hasUnregisteredReferenceOnPage, _this$fetchReferences5, _sourceSyncBlockData, _references, sourceSyncBlockReference, referenceSyncBlockReference, references, sourceSyncBlockData, currentPageData, _this$fetchReferences7;
203
- return _regenerator.default.wrap(function (_context3) {
204
- while (1) switch (_context3.prev = _context3.next) {
270
+ return _regenerator.default.wrap(function (_context4) {
271
+ while (1) switch (_context4.prev = _context4.next) {
205
272
  case 0:
206
273
  if (!isSourceSyncBlock) {
207
- _context3.next = 3;
274
+ _context4.next = 3;
208
275
  break;
209
276
  }
210
277
  // Verify that a reference sync block for this specific source actually
@@ -213,13 +280,13 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
213
280
  referenceResourceId = this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId);
214
281
  hasUnregisteredReferenceOnPage = this.referenceSyncBlockStoreManager.getSubscribedResourceIds().includes(referenceResourceId);
215
282
  if (!hasUnregisteredReferenceOnPage) {
216
- _context3.next = 2;
283
+ _context4.next = 2;
217
284
  break;
218
285
  }
219
- _context3.next = 1;
286
+ _context4.next = 1;
220
287
  return this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId);
221
288
  case 1:
222
- _sourceSyncBlockData = _context3.sent;
289
+ _sourceSyncBlockData = _context4.sent;
223
290
  _references = [];
224
291
  if (_sourceSyncBlockData) {
225
292
  sourceSyncBlockReference = _objectSpread(_objectSpread({}, _sourceSyncBlockData), {}, {
@@ -235,13 +302,13 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
235
302
  _references.push(sourceSyncBlockReference, referenceSyncBlockReference);
236
303
  }
237
304
  (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.success();
238
- return _context3.abrupt("return", {
305
+ return _context4.abrupt("return", {
239
306
  references: _references
240
307
  });
241
308
  case 2:
242
309
  // No remote or local reference exists — show info text with link to doco on how to use Synced Blocks
243
310
  (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.success();
244
- return _context3.abrupt("return", {
311
+ return _context4.abrupt("return", {
245
312
  references: []
246
313
  });
247
314
  case 3:
@@ -249,10 +316,10 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
249
316
  // still show the source and the current page itself since they are known
250
317
  // but not saved yet.
251
318
  references = [];
252
- _context3.next = 4;
319
+ _context4.next = 4;
253
320
  return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
254
321
  case 4:
255
- sourceSyncBlockData = _context3.sent;
322
+ sourceSyncBlockData = _context4.sent;
256
323
  if (sourceSyncBlockData) {
257
324
  references.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
258
325
  onSameDocument: Boolean(sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.onSameDocument),
@@ -260,10 +327,10 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
260
327
  isSource: true
261
328
  }));
262
329
  }
263
- _context3.next = 5;
330
+ _context4.next = 5;
264
331
  return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(blockInstanceId);
265
332
  case 5:
266
- currentPageData = _context3.sent;
333
+ currentPageData = _context4.sent;
267
334
  if (currentPageData) {
268
335
  references.push(_objectSpread(_objectSpread({}, currentPageData), {}, {
269
336
  onSameDocument: true,
@@ -272,27 +339,27 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
272
339
  }));
273
340
  }
274
341
  if (!(references.length === 0)) {
275
- _context3.next = 6;
342
+ _context4.next = 6;
276
343
  break;
277
344
  }
278
345
  (_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 || _this$fetchReferences7.failure({
279
346
  reason: 'No references found for reference synced block'
280
347
  });
281
- return _context3.abrupt("return", {
348
+ return _context4.abrupt("return", {
282
349
  error: _types.SyncBlockError.Errored
283
350
  });
284
351
  case 6:
285
352
  (_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 || _this$fetchReferences8.success();
286
- return _context3.abrupt("return", {
353
+ return _context4.abrupt("return", {
287
354
  references: references
288
355
  });
289
356
  case 7:
290
357
  case "end":
291
- return _context3.stop();
358
+ return _context4.stop();
292
359
  }
293
- }, _callee3, this);
360
+ }, _callee4, this);
294
361
  }));
295
- function getUnregisteredReferences(_x5, _x6, _x7) {
362
+ function getUnregisteredReferences(_x6, _x7, _x8) {
296
363
  return _getUnregisteredReferences.apply(this, arguments);
297
364
  }
298
365
  return getUnregisteredReferences;
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable require-unicode-regexp */
2
2
 
3
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
3
4
  import { parseJiraFieldLocation } from '../jira/ari';
4
5
  const GET_LOCAL_ID_FROM_BLOCK_RESOURCE_ID_REGEX = /ari:cloud:blocks:[^:]+:synced-block\/([a-zA-Z0-9-]+)/;
5
6
  const JIRA_SOURCE_ARI_REGEX = /ari:cloud:jira:.*/;
@@ -77,6 +78,9 @@ export const getLocationScope = ({
77
78
  return location.fieldId === hostLocation.fieldId ? 'same-document' : 'same-parent-document';
78
79
  };
79
80
  export const getProductFromSourceAri = ari => {
81
+ if (!ari && isExperimentEnabled('platform_editor_blocks_patch_11')) {
82
+ return undefined;
83
+ }
80
84
  const jiraMatch = ari === null || ari === void 0 ? void 0 : ari.search(JIRA_SOURCE_ARI_REGEX);
81
85
  if (jiraMatch !== -1) {
82
86
  return 'jira-work-item';
@@ -1,3 +1,4 @@
1
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
1
2
  import { fetchWithRetry } from '../../utils/retry';
2
3
  export const isBlockContentResponse = response => {
3
4
  const content = response.content;
@@ -251,7 +252,7 @@ const buildGetBlockReferencesQuery = blockAri => {
251
252
  }
252
253
  errors {
253
254
  blockAri
254
- code
255
+ code${isExperimentEnabled('platform_editor_blocks_patch_11') ? '\n\t\t\tdocumentAri' : ''}
255
256
  reason
256
257
  }
257
258
  }
@@ -1,5 +1,6 @@
1
1
  import { useEffect, useMemo, useRef } from 'react';
2
2
  import { logException } from '@atlaskit/editor-common/monitoring';
3
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
3
4
  import { getProductFromSourceAri } from '../clients/block-service/ari';
4
5
  import { SyncBlockError } from '../common/types';
5
6
  import { fetchReferencesErrorPayload } from '../utils/errorHandling';
@@ -51,6 +52,9 @@ export class SyncBlockStoreManager {
51
52
  (_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 ? void 0 : _this$fetchReferences3.success();
52
53
  const sourceInfoPromises = ((_response$references2 = response.references) !== null && _response$references2 !== void 0 ? _response$references2 : []).map(async reference => {
53
54
  var _this$fetchSourceInfo, _this$dataProvider, _this$fetchSourceInfo3;
55
+ if (!reference.hasAccess && isExperimentEnabled('platform_editor_blocks_patch_11')) {
56
+ return this.fetchRestrictedReferenceInfo(reference.documentAri);
57
+ }
54
58
  (_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 ? void 0 : _this$fetchSourceInfo.start();
55
59
  const sourceInfo = await ((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(reference.blockInstanceId || '', reference.documentAri, getProductFromSourceAri(reference.documentAri), reference.hasAccess));
56
60
  if (!sourceInfo) {
@@ -120,6 +124,42 @@ export class SyncBlockStoreManager {
120
124
  reason: 'editorDestroyed'
121
125
  });
122
126
  }
127
+
128
+ /**
129
+ * Keeps only the link of a location the user cannot read, so its title never reaches the UI.
130
+ * The location still counts when the link cannot be resolved or there is no document to link to.
131
+ */
132
+ async fetchRestrictedReferenceInfo(documentAri) {
133
+ var _this$fetchSourceInfo5;
134
+ if (!documentAri) {
135
+ return {
136
+ sourceAri: '',
137
+ hasAccess: false,
138
+ onSameDocument: false
139
+ };
140
+ }
141
+ const productType = getProductFromSourceAri(documentAri);
142
+ let url;
143
+ (_this$fetchSourceInfo5 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo5 === void 0 ? void 0 : _this$fetchSourceInfo5.start();
144
+ try {
145
+ var _this$dataProvider2, _this$fetchSourceInfo6;
146
+ const sourceInfo = await ((_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.fetchSyncBlockSourceInfo(undefined, documentAri, productType, false));
147
+ url = sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url;
148
+ (_this$fetchSourceInfo6 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo6 === void 0 ? void 0 : _this$fetchSourceInfo6.success();
149
+ } catch (error) {
150
+ var _this$fetchSourceInfo7;
151
+ (_this$fetchSourceInfo7 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo7 === void 0 ? void 0 : _this$fetchSourceInfo7.failure({
152
+ reason: error.message
153
+ });
154
+ }
155
+ return {
156
+ sourceAri: documentAri,
157
+ productType,
158
+ url,
159
+ hasAccess: false,
160
+ onSameDocument: false
161
+ };
162
+ }
123
163
  async getUnregisteredReferences(resourceId, blockInstanceId, isSourceSyncBlock) {
124
164
  var _this$fetchReferences8;
125
165
  // No reference found
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable require-unicode-regexp */
2
2
 
3
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
3
4
  import { parseJiraFieldLocation } from '../jira/ari';
4
5
  var GET_LOCAL_ID_FROM_BLOCK_RESOURCE_ID_REGEX = /ari:cloud:blocks:[^:]+:synced-block\/([a-zA-Z0-9-]+)/;
5
6
  var JIRA_SOURCE_ARI_REGEX = /ari:cloud:jira:.*/;
@@ -74,6 +75,9 @@ export var getLocationScope = function getLocationScope(_ref3) {
74
75
  return location.fieldId === hostLocation.fieldId ? 'same-document' : 'same-parent-document';
75
76
  };
76
77
  export var getProductFromSourceAri = function getProductFromSourceAri(ari) {
78
+ if (!ari && isExperimentEnabled('platform_editor_blocks_patch_11')) {
79
+ return undefined;
80
+ }
77
81
  var jiraMatch = ari === null || ari === void 0 ? void 0 : ari.search(JIRA_SOURCE_ARI_REGEX);
78
82
  if (jiraMatch !== -1) {
79
83
  return 'jira-work-item';
@@ -8,6 +8,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
8
8
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
9
9
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
10
10
  import _regeneratorRuntime from "@babel/runtime/regenerator";
11
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
11
12
  import { fetchWithRetry } from '../../utils/retry';
12
13
  export var isBlockContentResponse = function isBlockContentResponse(response) {
13
14
  var content = response.content;
@@ -192,7 +193,7 @@ var buildBatchRetrieveBlocksQuery = function buildBatchRetrieveBlocksQuery(block
192
193
  return "query ".concat(BATCH_RETRIEVE_BLOCKS_OPERATION_NAME, " {\n\tblockService_batchRetrieveBlocks(input: { ").concat(inputArgs, " }) {\n\t\tsuccess {\n\t\t\tblockAri\n\t\t\tblockInstanceId\n\t\t\tcontent\n\t\t\tcontentUpdatedAt\n\t\t\tcreatedAt\n\t\t\tcreatedBy\n\t\t\tdeletionReason\n\t\t\tproduct\n\t\t\tsourceAri\n\t\t\tstatus\n\t\t\tversion\n\t\t}\n\t\terror {\n\t\t\tblockAri\n\t\t\tcode\n\t\t\treason\n\t\t}\n\t}\n}");
193
194
  };
194
195
  var buildGetBlockReferencesQuery = function buildGetBlockReferencesQuery(blockAri) {
195
- return "query ".concat(GET_BLOCK_REFERENCES_OPERATION_NAME, " {\n\tblockService_getReferences(blockAri: ").concat(JSON.stringify(blockAri), ") {\n\t\treferences {\n\t\t\tblockAri\n\t\t\tblockInstanceId\n\t\t\tcreatedAt\n\t\t\tcreatedBy\n\t\t\tdocumentAri\n\t\t}\n\t\terrors {\n\t\t\tblockAri\n\t\t\tcode\n\t\t\treason\n\t\t}\n\t}\n}");
196
+ return "query ".concat(GET_BLOCK_REFERENCES_OPERATION_NAME, " {\n\tblockService_getReferences(blockAri: ").concat(JSON.stringify(blockAri), ") {\n\t\treferences {\n\t\t\tblockAri\n\t\t\tblockInstanceId\n\t\t\tcreatedAt\n\t\t\tcreatedBy\n\t\t\tdocumentAri\n\t\t}\n\t\terrors {\n\t\t\tblockAri\n\t\t\tcode").concat(isExperimentEnabled('platform_editor_blocks_patch_11') ? '\n\t\t\tdocumentAri' : '', "\n\t\t\treason\n\t\t}\n\t}\n}");
196
197
  };
197
198
  var buildBatchUpdateBlocksMutation = function buildBatchUpdateBlocksMutation(blocks) {
198
199
  var blocksArray = blocks.map(function (block) {
@@ -7,6 +7,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
7
7
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
8
  import { useEffect, useMemo, useRef } from 'react';
9
9
  import { logException } from '@atlaskit/editor-common/monitoring';
10
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
10
11
  import { getProductFromSourceAri } from '../clients/block-service/ari';
11
12
  import { SyncBlockError } from '../common/types';
12
13
  import { fetchReferencesErrorPayload } from '../utils/errorHandling';
@@ -84,20 +85,26 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
84
85
  return _regeneratorRuntime.wrap(function (_context) {
85
86
  while (1) switch (_context.prev = _context.next) {
86
87
  case 0:
88
+ if (!(!reference.hasAccess && isExperimentEnabled('platform_editor_blocks_patch_11'))) {
89
+ _context.next = 1;
90
+ break;
91
+ }
92
+ return _context.abrupt("return", _this.fetchRestrictedReferenceInfo(reference.documentAri));
93
+ case 1:
87
94
  (_this$fetchSourceInfo = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.start();
88
- _context.next = 1;
95
+ _context.next = 2;
89
96
  return (_this$dataProvider = _this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(reference.blockInstanceId || '', reference.documentAri, getProductFromSourceAri(reference.documentAri), reference.hasAccess);
90
- case 1:
97
+ case 2:
91
98
  sourceInfo = _context.sent;
92
99
  if (sourceInfo) {
93
- _context.next = 2;
100
+ _context.next = 3;
94
101
  break;
95
102
  }
96
103
  (_this$fetchSourceInfo2 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.failure({
97
104
  reason: "no source info returned for ari: ".concat(reference.documentAri)
98
105
  });
99
106
  return _context.abrupt("return", undefined);
100
- case 2:
107
+ case 3:
101
108
  (_this$fetchSourceInfo3 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 || _this$fetchSourceInfo3.success();
102
109
  return _context.abrupt("return", _objectSpread(_objectSpread(_objectSpread({}, sourceInfo), {}, {
103
110
  onSameDocument: reference.onSameDocument
@@ -107,7 +114,7 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
107
114
  hasAccess: reference.hasAccess,
108
115
  productType: sourceInfo.productType
109
116
  }));
110
- case 3:
117
+ case 4:
111
118
  case "end":
112
119
  return _context.stop();
113
120
  }
@@ -189,17 +196,77 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
189
196
  reason: 'editorDestroyed'
190
197
  });
191
198
  }
199
+
200
+ /**
201
+ * Keeps only the link of a location the user cannot read, so its title never reaches the UI.
202
+ * The location still counts when the link cannot be resolved or there is no document to link to.
203
+ */
204
+ }, {
205
+ key: "fetchRestrictedReferenceInfo",
206
+ value: (function () {
207
+ var _fetchRestrictedReferenceInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(documentAri) {
208
+ var _this$fetchSourceInfo5;
209
+ var productType, url, _this$dataProvider2, _this$fetchSourceInfo6, sourceInfo, _this$fetchSourceInfo7, _t2;
210
+ return _regeneratorRuntime.wrap(function (_context3) {
211
+ while (1) switch (_context3.prev = _context3.next) {
212
+ case 0:
213
+ if (documentAri) {
214
+ _context3.next = 1;
215
+ break;
216
+ }
217
+ return _context3.abrupt("return", {
218
+ sourceAri: '',
219
+ hasAccess: false,
220
+ onSameDocument: false
221
+ });
222
+ case 1:
223
+ productType = getProductFromSourceAri(documentAri);
224
+ (_this$fetchSourceInfo5 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo5 === void 0 || _this$fetchSourceInfo5.start();
225
+ _context3.prev = 2;
226
+ _context3.next = 3;
227
+ return (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.fetchSyncBlockSourceInfo(undefined, documentAri, productType, false);
228
+ case 3:
229
+ sourceInfo = _context3.sent;
230
+ url = sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url;
231
+ (_this$fetchSourceInfo6 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo6 === void 0 || _this$fetchSourceInfo6.success();
232
+ _context3.next = 5;
233
+ break;
234
+ case 4:
235
+ _context3.prev = 4;
236
+ _t2 = _context3["catch"](2);
237
+ (_this$fetchSourceInfo7 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo7 === void 0 || _this$fetchSourceInfo7.failure({
238
+ reason: _t2.message
239
+ });
240
+ case 5:
241
+ return _context3.abrupt("return", {
242
+ sourceAri: documentAri,
243
+ productType: productType,
244
+ url: url,
245
+ hasAccess: false,
246
+ onSameDocument: false
247
+ });
248
+ case 6:
249
+ case "end":
250
+ return _context3.stop();
251
+ }
252
+ }, _callee3, this, [[2, 4]]);
253
+ }));
254
+ function fetchRestrictedReferenceInfo(_x5) {
255
+ return _fetchRestrictedReferenceInfo.apply(this, arguments);
256
+ }
257
+ return fetchRestrictedReferenceInfo;
258
+ }())
192
259
  }, {
193
260
  key: "getUnregisteredReferences",
194
261
  value: function () {
195
- var _getUnregisteredReferences = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resourceId, blockInstanceId, isSourceSyncBlock) {
262
+ var _getUnregisteredReferences = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(resourceId, blockInstanceId, isSourceSyncBlock) {
196
263
  var _this$fetchReferences8;
197
264
  var _this$fetchReferences6, referenceResourceId, hasUnregisteredReferenceOnPage, _this$fetchReferences5, _sourceSyncBlockData, _references, sourceSyncBlockReference, referenceSyncBlockReference, references, sourceSyncBlockData, currentPageData, _this$fetchReferences7;
198
- return _regeneratorRuntime.wrap(function (_context3) {
199
- while (1) switch (_context3.prev = _context3.next) {
265
+ return _regeneratorRuntime.wrap(function (_context4) {
266
+ while (1) switch (_context4.prev = _context4.next) {
200
267
  case 0:
201
268
  if (!isSourceSyncBlock) {
202
- _context3.next = 3;
269
+ _context4.next = 3;
203
270
  break;
204
271
  }
205
272
  // Verify that a reference sync block for this specific source actually
@@ -208,13 +275,13 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
208
275
  referenceResourceId = this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId);
209
276
  hasUnregisteredReferenceOnPage = this.referenceSyncBlockStoreManager.getSubscribedResourceIds().includes(referenceResourceId);
210
277
  if (!hasUnregisteredReferenceOnPage) {
211
- _context3.next = 2;
278
+ _context4.next = 2;
212
279
  break;
213
280
  }
214
- _context3.next = 1;
281
+ _context4.next = 1;
215
282
  return this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId);
216
283
  case 1:
217
- _sourceSyncBlockData = _context3.sent;
284
+ _sourceSyncBlockData = _context4.sent;
218
285
  _references = [];
219
286
  if (_sourceSyncBlockData) {
220
287
  sourceSyncBlockReference = _objectSpread(_objectSpread({}, _sourceSyncBlockData), {}, {
@@ -230,13 +297,13 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
230
297
  _references.push(sourceSyncBlockReference, referenceSyncBlockReference);
231
298
  }
232
299
  (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.success();
233
- return _context3.abrupt("return", {
300
+ return _context4.abrupt("return", {
234
301
  references: _references
235
302
  });
236
303
  case 2:
237
304
  // No remote or local reference exists — show info text with link to doco on how to use Synced Blocks
238
305
  (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.success();
239
- return _context3.abrupt("return", {
306
+ return _context4.abrupt("return", {
240
307
  references: []
241
308
  });
242
309
  case 3:
@@ -244,10 +311,10 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
244
311
  // still show the source and the current page itself since they are known
245
312
  // but not saved yet.
246
313
  references = [];
247
- _context3.next = 4;
314
+ _context4.next = 4;
248
315
  return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
249
316
  case 4:
250
- sourceSyncBlockData = _context3.sent;
317
+ sourceSyncBlockData = _context4.sent;
251
318
  if (sourceSyncBlockData) {
252
319
  references.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
253
320
  onSameDocument: Boolean(sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.onSameDocument),
@@ -255,10 +322,10 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
255
322
  isSource: true
256
323
  }));
257
324
  }
258
- _context3.next = 5;
325
+ _context4.next = 5;
259
326
  return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(blockInstanceId);
260
327
  case 5:
261
- currentPageData = _context3.sent;
328
+ currentPageData = _context4.sent;
262
329
  if (currentPageData) {
263
330
  references.push(_objectSpread(_objectSpread({}, currentPageData), {}, {
264
331
  onSameDocument: true,
@@ -267,27 +334,27 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
267
334
  }));
268
335
  }
269
336
  if (!(references.length === 0)) {
270
- _context3.next = 6;
337
+ _context4.next = 6;
271
338
  break;
272
339
  }
273
340
  (_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 || _this$fetchReferences7.failure({
274
341
  reason: 'No references found for reference synced block'
275
342
  });
276
- return _context3.abrupt("return", {
343
+ return _context4.abrupt("return", {
277
344
  error: SyncBlockError.Errored
278
345
  });
279
346
  case 6:
280
347
  (_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 || _this$fetchReferences8.success();
281
- return _context3.abrupt("return", {
348
+ return _context4.abrupt("return", {
282
349
  references: references
283
350
  });
284
351
  case 7:
285
352
  case "end":
286
- return _context3.stop();
353
+ return _context4.stop();
287
354
  }
288
- }, _callee3, this);
355
+ }, _callee4, this);
289
356
  }));
290
- function getUnregisteredReferences(_x5, _x6, _x7) {
357
+ function getUnregisteredReferences(_x6, _x7, _x8) {
291
358
  return _getUnregisteredReferences.apply(this, arguments);
292
359
  }
293
360
  return getUnregisteredReferences;
@@ -33,6 +33,11 @@ export declare class SyncBlockStoreManager {
33
33
  get referenceManager(): ReferenceSyncBlockStoreManager;
34
34
  get sourceManager(): SourceSyncBlockStoreManager;
35
35
  destroy(): void;
36
+ /**
37
+ * Keeps only the link of a location the user cannot read, so its title never reaches the UI.
38
+ * The location still counts when the link cannot be resolved or there is no document to link to.
39
+ */
40
+ private fetchRestrictedReferenceInfo;
36
41
  private getUnregisteredReferences;
37
42
  }
38
43
  export declare const useMemoizedSyncBlockStoreManager: (dataProvider?: SyncBlockDataProviderInterface, fireAnalyticsEvent?: (payload: SyncBlockEventPayload) => void, options?: SyncBlockStoreManagerOptions) => SyncBlockStoreManager;
package/package.json CHANGED
@@ -20,10 +20,10 @@
20
20
  "@atlaskit/browser-apis": "^1.2.0",
21
21
  "@atlaskit/editor-json-transformer": "^10.0.0",
22
22
  "@atlaskit/editor-prosemirror": "^9.0.0",
23
- "@atlaskit/node-data-provider": "^24.0.0",
23
+ "@atlaskit/node-data-provider": "^25.0.0",
24
24
  "@atlaskit/platform-feature-experiments": "^0.3.0",
25
25
  "@atlaskit/platform-feature-flags": "^2.2.0",
26
- "@atlaskit/tmp-editor-statsig": "^220.0.0",
26
+ "@atlaskit/tmp-editor-statsig": "^221.0.0",
27
27
  "@babel/runtime": "^7.0.0",
28
28
  "@compiled/react": "^1.0.2",
29
29
  "bind-event-listener": "^3.0.0",
@@ -33,7 +33,7 @@
33
33
  "uuid": "^11.1.1"
34
34
  },
35
35
  "peerDependencies": {
36
- "@atlaskit/editor-common": "^127.2.0",
36
+ "@atlaskit/editor-common": "^128.1.0",
37
37
  "react": "^18.2.0 || ^19.2.0"
38
38
  },
39
39
  "devDependencies": {
@@ -42,7 +42,7 @@
42
42
  "react-dom": "^19.2.0"
43
43
  },
44
44
  "name": "@atlaskit/editor-synced-block-provider",
45
- "version": "19.0.1",
45
+ "version": "20.0.1",
46
46
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
47
47
  "author": "Atlassian Pty Ltd",
48
48
  "license": "Apache-2.0",