@atlaskit/editor-card-provider 5.0.4 → 5.1.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,19 @@
1
1
  # @atlaskit/editor-card-provider
2
2
 
3
+ ## 5.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 5.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#174410](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/174410)
14
+ [`80d17e2d01bc0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/80d17e2d01bc0) -
15
+ Issue Editor - Only call onResolve callback for resolved links if local links (not remote links)
16
+
3
17
  ## 5.0.4
4
18
 
5
19
  ### Patch Changes
@@ -201,19 +201,63 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function () {
201
201
  return checkLinkResolved;
202
202
  }()
203
203
  }, {
204
- key: "fetchProvidersData",
204
+ key: "fetchDataForResource",
205
205
  value: function () {
206
- var _fetchProvidersData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
207
- var endpoint, response;
206
+ var _fetchDataForResource = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resourceUrl) {
207
+ var response;
208
208
  return _regenerator.default.wrap(function _callee3$(_context3) {
209
209
  while (1) switch (_context3.prev = _context3.next) {
210
210
  case 0:
211
- endpoint = "".concat(this.resolverUrl, "/providers");
211
+ _context3.prev = 0;
212
212
  _context3.next = 3;
213
- return api.request('post', endpoint, undefined, this.requestHeaders);
213
+ return this.cardClient.fetchData(resourceUrl);
214
214
  case 3:
215
215
  response = _context3.sent;
216
- return _context3.abrupt("return", {
216
+ if (!((0, _linkingCommon.getStatus)(response) !== 'not_found')) {
217
+ _context3.next = 6;
218
+ break;
219
+ }
220
+ return _context3.abrupt("return", response);
221
+ case 6:
222
+ _context3.next = 11;
223
+ break;
224
+ case 8:
225
+ _context3.prev = 8;
226
+ _context3.t0 = _context3["catch"](0);
227
+ return _context3.abrupt("return", undefined);
228
+ case 11:
229
+ case "end":
230
+ return _context3.stop();
231
+ }
232
+ }, _callee3, this, [[0, 8]]);
233
+ }));
234
+ function fetchDataForResource(_x3) {
235
+ return _fetchDataForResource.apply(this, arguments);
236
+ }
237
+ return fetchDataForResource;
238
+ }()
239
+ }, {
240
+ key: "extractAriFromData",
241
+ value: function extractAriFromData(responseData) {
242
+ if (responseData.data && 'atlassian:ari' in responseData.data) {
243
+ return responseData.data['atlassian:ari'];
244
+ }
245
+ return undefined;
246
+ }
247
+ }, {
248
+ key: "fetchProvidersData",
249
+ value: function () {
250
+ var _fetchProvidersData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
251
+ var endpoint, response;
252
+ return _regenerator.default.wrap(function _callee4$(_context4) {
253
+ while (1) switch (_context4.prev = _context4.next) {
254
+ case 0:
255
+ endpoint = "".concat(this.resolverUrl, "/providers");
256
+ _context4.next = 3;
257
+ return api.request('post', endpoint, undefined, this.requestHeaders);
258
+ case 3:
259
+ response = _context4.sent;
260
+ return _context4.abrupt("return", {
217
261
  patterns: response.providers.reduce(function (allSources, provider) {
218
262
  return allSources.concat(provider.patterns);
219
263
  }, []),
@@ -221,9 +265,9 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function () {
221
265
  });
222
266
  case 5:
223
267
  case "end":
224
- return _context3.stop();
268
+ return _context4.stop();
225
269
  }
226
- }, _callee3, this);
270
+ }, _callee4, this);
227
271
  }));
228
272
  function fetchProvidersData() {
229
273
  return _fetchProvidersData.apply(this, arguments);
@@ -233,29 +277,29 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function () {
233
277
  }, {
234
278
  key: "loadProviderData",
235
279
  value: function () {
236
- var _loadProviderData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
237
- return _regenerator.default.wrap(function _callee4$(_context4) {
238
- while (1) switch (_context4.prev = _context4.next) {
280
+ var _loadProviderData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
281
+ return _regenerator.default.wrap(function _callee5$(_context5) {
282
+ while (1) switch (_context5.prev = _context5.next) {
239
283
  case 0:
240
- _context4.prev = 0;
241
- _context4.next = 3;
284
+ _context5.prev = 0;
285
+ _context5.next = 3;
242
286
  return this.providersLoader.load('providersData');
243
287
  case 3:
244
- this.providersData = _context4.sent;
245
- _context4.next = 11;
288
+ this.providersData = _context5.sent;
289
+ _context5.next = 11;
246
290
  break;
247
291
  case 6:
248
- _context4.prev = 6;
249
- _context4.t0 = _context4["catch"](0);
292
+ _context5.prev = 6;
293
+ _context5.t0 = _context5["catch"](0);
250
294
  // eslint-disable-next-line
251
- console.error('failed to fetch /providers', _context4.t0);
295
+ console.error('failed to fetch /providers', _context5.t0);
252
296
  this.providersLoader.clear('providerData');
253
- return _context4.abrupt("return", undefined);
297
+ return _context5.abrupt("return", undefined);
254
298
  case 11:
255
299
  case "end":
256
- return _context4.stop();
300
+ return _context5.stop();
257
301
  }
258
- }, _callee4, this, [[0, 6]]);
302
+ }, _callee5, this, [[0, 6]]);
259
303
  }));
260
304
  function loadProviderData() {
261
305
  return _loadProviderData.apply(this, arguments);
@@ -265,31 +309,31 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function () {
265
309
  }, {
266
310
  key: "findPattern",
267
311
  value: function () {
268
- var _findPattern = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(url) {
269
- return _regenerator.default.wrap(function _callee5$(_context5) {
270
- while (1) switch (_context5.prev = _context5.next) {
312
+ var _findPattern = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(url) {
313
+ return _regenerator.default.wrap(function _callee6$(_context6) {
314
+ while (1) switch (_context6.prev = _context6.next) {
271
315
  case 0:
272
- _context5.next = 2;
316
+ _context6.next = 2;
273
317
  return this.findPatternData(url);
274
318
  case 2:
275
- _context5.t0 = !!_context5.sent;
276
- if (_context5.t0) {
277
- _context5.next = 7;
319
+ _context6.t0 = !!_context6.sent;
320
+ if (_context6.t0) {
321
+ _context6.next = 7;
278
322
  break;
279
323
  }
280
- _context5.next = 6;
324
+ _context6.next = 6;
281
325
  return this.checkLinkResolved(url);
282
326
  case 6:
283
- _context5.t0 = !!_context5.sent;
327
+ _context6.t0 = !!_context6.sent;
284
328
  case 7:
285
- return _context5.abrupt("return", _context5.t0);
329
+ return _context6.abrupt("return", _context6.t0);
286
330
  case 8:
287
331
  case "end":
288
- return _context5.stop();
332
+ return _context6.stop();
289
333
  }
290
- }, _callee5, this);
334
+ }, _callee6, this);
291
335
  }));
292
- function findPattern(_x3) {
336
+ function findPattern(_x4) {
293
337
  return _findPattern.apply(this, arguments);
294
338
  }
295
339
  return findPattern;
@@ -307,23 +351,23 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function () {
307
351
  }, {
308
352
  key: "findUserPreference",
309
353
  value: function () {
310
- var _findUserPreference = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(url) {
354
+ var _findUserPreference = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(url) {
311
355
  var _this$providersData,
312
356
  _this2 = this;
313
357
  var userPreferences, defaultAppearance, appearances, allMatchedLabeledAppearances, longestMatchedLabeledAppearance;
314
- return _regenerator.default.wrap(function _callee6$(_context6) {
315
- while (1) switch (_context6.prev = _context6.next) {
358
+ return _regenerator.default.wrap(function _callee7$(_context7) {
359
+ while (1) switch (_context7.prev = _context7.next) {
316
360
  case 0:
317
361
  if (this.providersData) {
318
- _context6.next = 3;
362
+ _context7.next = 3;
319
363
  break;
320
364
  }
321
- _context6.next = 3;
365
+ _context7.next = 3;
322
366
  return this.loadProviderData();
323
367
  case 3:
324
368
  userPreferences = (_this$providersData = this.providersData) === null || _this$providersData === void 0 ? void 0 : _this$providersData.userPreferences;
325
369
  if (!userPreferences) {
326
- _context6.next = 12;
370
+ _context7.next = 12;
327
371
  break;
328
372
  }
329
373
  defaultAppearance = userPreferences.defaultAppearance, appearances = userPreferences.appearances;
@@ -332,26 +376,26 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function () {
332
376
  return _this2.doesUrlMatchPath(urlSegment, url);
333
377
  });
334
378
  if (!(allMatchedLabeledAppearances.length > 0)) {
335
- _context6.next = 10;
379
+ _context7.next = 10;
336
380
  break;
337
381
  }
338
382
  longestMatchedLabeledAppearance = allMatchedLabeledAppearances.reduce(function (previousLabeledAppearance, currentLabeledAppearance) {
339
383
  return previousLabeledAppearance.urlSegment.length > currentLabeledAppearance.urlSegment.length ? previousLabeledAppearance : currentLabeledAppearance;
340
384
  });
341
- return _context6.abrupt("return", longestMatchedLabeledAppearance.appearance);
385
+ return _context7.abrupt("return", longestMatchedLabeledAppearance.appearance);
342
386
  case 10:
343
387
  if (!(defaultAppearance !== 'inline')) {
344
- _context6.next = 12;
388
+ _context7.next = 12;
345
389
  break;
346
390
  }
347
- return _context6.abrupt("return", defaultAppearance);
391
+ return _context7.abrupt("return", defaultAppearance);
348
392
  case 12:
349
393
  case "end":
350
- return _context6.stop();
394
+ return _context7.stop();
351
395
  }
352
- }, _callee6, this);
396
+ }, _callee7, this);
353
397
  }));
354
- function findUserPreference(_x4) {
398
+ function findUserPreference(_x5) {
355
399
  return _findUserPreference.apply(this, arguments);
356
400
  }
357
401
  return findUserPreference;
@@ -359,28 +403,28 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function () {
359
403
  }, {
360
404
  key: "findPatternData",
361
405
  value: function () {
362
- var _findPatternData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(url) {
406
+ var _findPatternData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(url) {
363
407
  var _this$providersData2;
364
- return _regenerator.default.wrap(function _callee7$(_context7) {
365
- while (1) switch (_context7.prev = _context7.next) {
408
+ return _regenerator.default.wrap(function _callee8$(_context8) {
409
+ while (1) switch (_context8.prev = _context8.next) {
366
410
  case 0:
367
411
  if (this.providersData) {
368
- _context7.next = 3;
412
+ _context8.next = 3;
369
413
  break;
370
414
  }
371
- _context7.next = 3;
415
+ _context8.next = 3;
372
416
  return this.loadProviderData();
373
417
  case 3:
374
- return _context7.abrupt("return", (_this$providersData2 = this.providersData) === null || _this$providersData2 === void 0 ? void 0 : _this$providersData2.patterns.find(function (pattern) {
418
+ return _context8.abrupt("return", (_this$providersData2 = this.providersData) === null || _this$providersData2 === void 0 ? void 0 : _this$providersData2.patterns.find(function (pattern) {
375
419
  return url.match(pattern.source);
376
420
  }));
377
421
  case 4:
378
422
  case "end":
379
- return _context7.stop();
423
+ return _context8.stop();
380
424
  }
381
- }, _callee7, this);
425
+ }, _callee8, this);
382
426
  }));
383
- function findPatternData(_x5) {
427
+ function findPatternData(_x6) {
384
428
  return _findPatternData.apply(this, arguments);
385
429
  }
386
430
  return findPatternData;
@@ -429,41 +473,41 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function () {
429
473
  * Make a /resolve call and find out if result has embed capability
430
474
  */
431
475
  function () {
432
- var _canBeResolvedAsEmbed = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(url) {
476
+ var _canBeResolvedAsEmbed = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(url) {
433
477
  var details, embed;
434
- return _regenerator.default.wrap(function _callee8$(_context8) {
435
- while (1) switch (_context8.prev = _context8.next) {
478
+ return _regenerator.default.wrap(function _callee9$(_context9) {
479
+ while (1) switch (_context9.prev = _context9.next) {
436
480
  case 0:
437
- _context8.prev = 0;
438
- _context8.next = 3;
481
+ _context9.prev = 0;
482
+ _context9.next = 3;
439
483
  return this.cardClient.fetchData(url);
440
484
  case 3:
441
- details = _context8.sent;
485
+ details = _context9.sent;
442
486
  if (details) {
443
- _context8.next = 6;
487
+ _context9.next = 6;
444
488
  break;
445
489
  }
446
- return _context8.abrupt("return", false);
490
+ return _context9.abrupt("return", false);
447
491
  case 6:
448
492
  if (!((0, _linkingCommon.getStatus)(details) !== 'resolved')) {
449
- _context8.next = 8;
493
+ _context9.next = 8;
450
494
  break;
451
495
  }
452
- return _context8.abrupt("return", false);
496
+ return _context9.abrupt("return", false);
453
497
  case 8:
454
498
  embed = (0, _linkExtractors.extractSmartLinkEmbed)(details);
455
- return _context8.abrupt("return", !!embed);
499
+ return _context9.abrupt("return", !!embed);
456
500
  case 12:
457
- _context8.prev = 12;
458
- _context8.t0 = _context8["catch"](0);
459
- return _context8.abrupt("return", false);
501
+ _context9.prev = 12;
502
+ _context9.t0 = _context9["catch"](0);
503
+ return _context9.abrupt("return", false);
460
504
  case 15:
461
505
  case "end":
462
- return _context8.stop();
506
+ return _context9.stop();
463
507
  }
464
- }, _callee8, this, [[0, 12]]);
508
+ }, _callee9, this, [[0, 12]]);
465
509
  }));
466
- function canBeResolvedAsEmbed(_x6) {
510
+ function canBeResolvedAsEmbed(_x7) {
467
511
  return _canBeResolvedAsEmbed.apply(this, arguments);
468
512
  }
469
513
  return canBeResolvedAsEmbed;
@@ -475,85 +519,110 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function () {
475
519
  }, {
476
520
  key: "getDatasourceFromResolveResponse",
477
521
  value: (function () {
478
- var _getDatasourceFromResolveResponse = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(url) {
522
+ var _getDatasourceFromResolveResponse = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee0(url) {
479
523
  var response, datasources;
480
- return _regenerator.default.wrap(function _callee9$(_context9) {
481
- while (1) switch (_context9.prev = _context9.next) {
524
+ return _regenerator.default.wrap(function _callee0$(_context0) {
525
+ while (1) switch (_context0.prev = _context0.next) {
482
526
  case 0:
483
- _context9.prev = 0;
484
- _context9.next = 3;
527
+ _context0.prev = 0;
528
+ _context0.next = 3;
485
529
  return this.cardClient.fetchData(url);
486
530
  case 3:
487
- response = _context9.sent;
531
+ response = _context0.sent;
488
532
  datasources = response && response.datasources || [];
489
533
  if (!(datasources.length > 0)) {
490
- _context9.next = 7;
534
+ _context0.next = 7;
491
535
  break;
492
536
  }
493
- return _context9.abrupt("return", datasources[0]);
537
+ return _context0.abrupt("return", datasources[0]);
494
538
  case 7:
495
- _context9.next = 12;
539
+ _context0.next = 12;
496
540
  break;
497
541
  case 9:
498
- _context9.prev = 9;
499
- _context9.t0 = _context9["catch"](0);
500
- return _context9.abrupt("return", undefined);
542
+ _context0.prev = 9;
543
+ _context0.t0 = _context0["catch"](0);
544
+ return _context0.abrupt("return", undefined);
501
545
  case 12:
502
546
  case "end":
503
- return _context9.stop();
547
+ return _context0.stop();
504
548
  }
505
- }, _callee9, this, [[0, 9]]);
549
+ }, _callee0, this, [[0, 9]]);
506
550
  }));
507
- function getDatasourceFromResolveResponse(_x7) {
551
+ function getDatasourceFromResolveResponse(_x8) {
508
552
  return _getDatasourceFromResolveResponse.apply(this, arguments);
509
553
  }
510
554
  return getDatasourceFromResolveResponse;
511
- }())
555
+ }()
556
+ /**
557
+ * This is used to determine if the url is a local Jira url or a remote one.
558
+ */
559
+ )
560
+ }, {
561
+ key: "isLocalUrl",
562
+ value: function isLocalUrl(url) {
563
+ return new URL(url).origin === this.baseUrl;
564
+ }
512
565
  }, {
513
566
  key: "resolve",
514
567
  value: function () {
515
- var _resolve = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee0(url, appearance, shouldForceAppearance, isEmbedFriendlyLocation) {
516
- var hardCodedAppearance, _yield$Promise$all, _yield$Promise$all2, matchedProviderPattern, userPreference, _this$onResolve, isSupported, providerDefaultAppearance, preferredAppearance, canItBeEmbed, datasource, id, parameters;
517
- return _regenerator.default.wrap(function _callee0$(_context0) {
518
- while (1) switch (_context0.prev = _context0.next) {
568
+ var _resolve = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee1(url, appearance, shouldForceAppearance, isEmbedFriendlyLocation) {
569
+ var hardCodedAppearance, _yield$Promise$all, _yield$Promise$all2, matchedProviderPattern, userPreference, data, issueAri, _this$onResolve, isSupported, providerDefaultAppearance, preferredAppearance, canItBeEmbed, datasource, id, parameters;
570
+ return _regenerator.default.wrap(function _callee1$(_context1) {
571
+ while (1) switch (_context1.prev = _context1.next) {
519
572
  case 0:
520
- _context0.prev = 0;
573
+ _context1.prev = 0;
521
574
  if (!(shouldForceAppearance === true)) {
522
- _context0.next = 3;
575
+ _context1.next = 3;
523
576
  break;
524
577
  }
525
- return _context0.abrupt("return", this.transformer.toSmartlinkAdf(url, appearance));
578
+ return _context1.abrupt("return", this.transformer.toSmartlinkAdf(url, appearance));
526
579
  case 3:
527
580
  hardCodedAppearance = this.getHardCodedAppearance(url);
528
- _context0.next = 6;
581
+ _context1.next = 6;
529
582
  return Promise.all([this.findPatternData(url), this.findUserPreference(url)]);
530
583
  case 6:
531
- _yield$Promise$all = _context0.sent;
584
+ _yield$Promise$all = _context1.sent;
532
585
  _yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 2);
533
586
  matchedProviderPattern = _yield$Promise$all2[0];
534
587
  userPreference = _yield$Promise$all2[1];
535
- if (isJiraWorkItem(url) && (0, _platformFeatureFlags.fg)('issue-link-suggestions-in-comments')) {
536
- (_this$onResolve = this.onResolve) === null || _this$onResolve === void 0 || _this$onResolve.call(this, url);
588
+ if (!(0, _platformFeatureFlags.fg)('issue-link-suggestions-in-comments')) {
589
+ _context1.next = 16;
590
+ break;
537
591
  }
592
+ if (!(isJiraWorkItem(url) && this.isLocalUrl(url))) {
593
+ _context1.next = 16;
594
+ break;
595
+ }
596
+ _context1.next = 14;
597
+ return this.fetchDataForResource(url);
598
+ case 14:
599
+ data = _context1.sent;
600
+ if (data) {
601
+ issueAri = this.extractAriFromData(data);
602
+ if (issueAri) {
603
+ (_this$onResolve = this.onResolve) === null || _this$onResolve === void 0 || _this$onResolve.call(this, url, issueAri);
604
+ }
605
+ }
606
+ case 16:
538
607
  if (!(shouldForceAppearance === false && userPreference === 'url')) {
539
- _context0.next = 13;
608
+ _context1.next = 18;
540
609
  break;
541
610
  }
542
- return _context0.abrupt("return", Promise.reject(undefined));
543
- case 13:
544
- _context0.t0 = !!matchedProviderPattern;
545
- if (_context0.t0) {
546
- _context0.next = 18;
611
+ return _context1.abrupt("return", Promise.reject(undefined));
612
+ case 18:
613
+ _context1.t0 = !!matchedProviderPattern;
614
+ if (_context1.t0) {
615
+ _context1.next = 23;
547
616
  break;
548
617
  }
549
- _context0.next = 17;
618
+ _context1.next = 22;
550
619
  return this.checkLinkResolved(url);
551
- case 17:
552
- _context0.t0 = _context0.sent;
553
- case 18:
554
- isSupported = _context0.t0;
620
+ case 22:
621
+ _context1.t0 = _context1.sent;
622
+ case 23:
623
+ isSupported = _context1.t0;
555
624
  if (!isSupported) {
556
- _context0.next = 34;
625
+ _context1.next = 39;
557
626
  break;
558
627
  }
559
628
  providerDefaultAppearance = matchedProviderPattern === null || matchedProviderPattern === void 0 ? void 0 : matchedProviderPattern.defaultView;
@@ -571,27 +640,27 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function () {
571
640
  // If not, we pick what editor (or any other client) requested
572
641
  appearance;
573
642
  if (!(preferredAppearance === userPreference && userPreference === 'embed')) {
574
- _context0.next = 27;
643
+ _context1.next = 32;
575
644
  break;
576
645
  }
577
- _context0.next = 25;
646
+ _context1.next = 30;
578
647
  return this.canBeResolvedAsEmbed(url);
579
- case 25:
580
- canItBeEmbed = _context0.sent;
648
+ case 30:
649
+ canItBeEmbed = _context1.sent;
581
650
  if (!canItBeEmbed) {
582
651
  preferredAppearance = 'inline';
583
652
  }
584
- case 27:
585
- _context0.next = 29;
653
+ case 32:
654
+ _context1.next = 34;
586
655
  return this.getDatasourceFromResolveResponse(url);
587
- case 29:
588
- datasource = _context0.sent;
656
+ case 34:
657
+ datasource = _context1.sent;
589
658
  if (!datasource) {
590
- _context0.next = 33;
659
+ _context1.next = 38;
591
660
  break;
592
661
  }
593
662
  id = datasource.id, parameters = datasource.parameters;
594
- return _context0.abrupt("return", this.transformer.toDatasourceAdf({
663
+ return _context1.abrupt("return", this.transformer.toDatasourceAdf({
595
664
  id: id,
596
665
  parameters: parameters,
597
666
  // in the future when we support multiple views, we will need to pass this in as a parameter
@@ -600,25 +669,25 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function () {
600
669
  type: 'table'
601
670
  }]
602
671
  }, url));
603
- case 33:
604
- return _context0.abrupt("return", this.transformer.toSmartlinkAdf(url, preferredAppearance));
605
- case 34:
606
- _context0.next = 39;
672
+ case 38:
673
+ return _context1.abrupt("return", this.transformer.toSmartlinkAdf(url, preferredAppearance));
674
+ case 39:
675
+ _context1.next = 44;
607
676
  break;
608
- case 36:
609
- _context0.prev = 36;
610
- _context0.t1 = _context0["catch"](0);
677
+ case 41:
678
+ _context1.prev = 41;
679
+ _context1.t1 = _context1["catch"](0);
611
680
  // eslint-disable-next-line
612
- console.warn("Error when trying to check Smart Card url \"".concat(url, "\"").concat(_context0.t1 instanceof Error ? " - ".concat(_context0.t1.name, " ").concat(_context0.t1.message) : ''), _context0.t1);
613
- case 39:
614
- return _context0.abrupt("return", Promise.reject(undefined));
615
- case 40:
681
+ console.warn("Error when trying to check Smart Card url \"".concat(url, "\"").concat(_context1.t1 instanceof Error ? " - ".concat(_context1.t1.name, " ").concat(_context1.t1.message) : ''), _context1.t1);
682
+ case 44:
683
+ return _context1.abrupt("return", Promise.reject(undefined));
684
+ case 45:
616
685
  case "end":
617
- return _context0.stop();
686
+ return _context1.stop();
618
687
  }
619
- }, _callee0, this, [[0, 36]]);
688
+ }, _callee1, this, [[0, 41]]);
620
689
  }));
621
- function resolve(_x8, _x9, _x0, _x1) {
690
+ function resolve(_x9, _x0, _x1, _x10) {
622
691
  return _resolve.apply(this, arguments);
623
692
  }
624
693
  return resolve;
@@ -92,6 +92,22 @@ export class EditorCardProvider {
92
92
  return false;
93
93
  }
94
94
  }
95
+ async fetchDataForResource(resourceUrl) {
96
+ try {
97
+ const response = await this.cardClient.fetchData(resourceUrl);
98
+ if (getStatus(response) !== 'not_found') {
99
+ return response;
100
+ }
101
+ } catch (e) {
102
+ return undefined;
103
+ }
104
+ }
105
+ extractAriFromData(responseData) {
106
+ if (responseData.data && 'atlassian:ari' in responseData.data) {
107
+ return responseData.data['atlassian:ari'];
108
+ }
109
+ return undefined;
110
+ }
95
111
  async fetchProvidersData() {
96
112
  const endpoint = `${this.resolverUrl}/providers`;
97
113
  const response = await api.request('post', endpoint, undefined, this.requestHeaders);
@@ -229,6 +245,13 @@ export class EditorCardProvider {
229
245
  return undefined;
230
246
  }
231
247
  }
248
+
249
+ /**
250
+ * This is used to determine if the url is a local Jira url or a remote one.
251
+ */
252
+ isLocalUrl(url) {
253
+ return new URL(url).origin === this.baseUrl;
254
+ }
232
255
  async resolve(url, appearance, shouldForceAppearance, isEmbedFriendlyLocation) {
233
256
  try {
234
257
  if (shouldForceAppearance === true) {
@@ -239,9 +262,17 @@ export class EditorCardProvider {
239
262
  }
240
263
  const hardCodedAppearance = this.getHardCodedAppearance(url);
241
264
  const [matchedProviderPattern, userPreference] = await Promise.all([this.findPatternData(url), this.findUserPreference(url)]);
242
- if (isJiraWorkItem(url) && fg('issue-link-suggestions-in-comments')) {
243
- var _this$onResolve;
244
- (_this$onResolve = this.onResolve) === null || _this$onResolve === void 0 ? void 0 : _this$onResolve.call(this, url);
265
+ if (fg('issue-link-suggestions-in-comments')) {
266
+ if (isJiraWorkItem(url) && this.isLocalUrl(url)) {
267
+ const data = await this.fetchDataForResource(url);
268
+ if (data) {
269
+ const issueAri = this.extractAriFromData(data);
270
+ if (issueAri) {
271
+ var _this$onResolve;
272
+ (_this$onResolve = this.onResolve) === null || _this$onResolve === void 0 ? void 0 : _this$onResolve.call(this, url, issueAri);
273
+ }
274
+ }
275
+ }
245
276
  }
246
277
  if (shouldForceAppearance === false && userPreference === 'url') {
247
278
  return Promise.reject(undefined);
@@ -194,19 +194,63 @@ export var EditorCardProvider = /*#__PURE__*/function () {
194
194
  return checkLinkResolved;
195
195
  }()
196
196
  }, {
197
- key: "fetchProvidersData",
197
+ key: "fetchDataForResource",
198
198
  value: function () {
199
- var _fetchProvidersData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
200
- var endpoint, response;
199
+ var _fetchDataForResource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resourceUrl) {
200
+ var response;
201
201
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
202
202
  while (1) switch (_context3.prev = _context3.next) {
203
203
  case 0:
204
- endpoint = "".concat(this.resolverUrl, "/providers");
204
+ _context3.prev = 0;
205
205
  _context3.next = 3;
206
- return api.request('post', endpoint, undefined, this.requestHeaders);
206
+ return this.cardClient.fetchData(resourceUrl);
207
207
  case 3:
208
208
  response = _context3.sent;
209
- return _context3.abrupt("return", {
209
+ if (!(getStatus(response) !== 'not_found')) {
210
+ _context3.next = 6;
211
+ break;
212
+ }
213
+ return _context3.abrupt("return", response);
214
+ case 6:
215
+ _context3.next = 11;
216
+ break;
217
+ case 8:
218
+ _context3.prev = 8;
219
+ _context3.t0 = _context3["catch"](0);
220
+ return _context3.abrupt("return", undefined);
221
+ case 11:
222
+ case "end":
223
+ return _context3.stop();
224
+ }
225
+ }, _callee3, this, [[0, 8]]);
226
+ }));
227
+ function fetchDataForResource(_x3) {
228
+ return _fetchDataForResource.apply(this, arguments);
229
+ }
230
+ return fetchDataForResource;
231
+ }()
232
+ }, {
233
+ key: "extractAriFromData",
234
+ value: function extractAriFromData(responseData) {
235
+ if (responseData.data && 'atlassian:ari' in responseData.data) {
236
+ return responseData.data['atlassian:ari'];
237
+ }
238
+ return undefined;
239
+ }
240
+ }, {
241
+ key: "fetchProvidersData",
242
+ value: function () {
243
+ var _fetchProvidersData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
244
+ var endpoint, response;
245
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
246
+ while (1) switch (_context4.prev = _context4.next) {
247
+ case 0:
248
+ endpoint = "".concat(this.resolverUrl, "/providers");
249
+ _context4.next = 3;
250
+ return api.request('post', endpoint, undefined, this.requestHeaders);
251
+ case 3:
252
+ response = _context4.sent;
253
+ return _context4.abrupt("return", {
210
254
  patterns: response.providers.reduce(function (allSources, provider) {
211
255
  return allSources.concat(provider.patterns);
212
256
  }, []),
@@ -214,9 +258,9 @@ export var EditorCardProvider = /*#__PURE__*/function () {
214
258
  });
215
259
  case 5:
216
260
  case "end":
217
- return _context3.stop();
261
+ return _context4.stop();
218
262
  }
219
- }, _callee3, this);
263
+ }, _callee4, this);
220
264
  }));
221
265
  function fetchProvidersData() {
222
266
  return _fetchProvidersData.apply(this, arguments);
@@ -226,29 +270,29 @@ export var EditorCardProvider = /*#__PURE__*/function () {
226
270
  }, {
227
271
  key: "loadProviderData",
228
272
  value: function () {
229
- var _loadProviderData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
230
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
231
- while (1) switch (_context4.prev = _context4.next) {
273
+ var _loadProviderData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
274
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
275
+ while (1) switch (_context5.prev = _context5.next) {
232
276
  case 0:
233
- _context4.prev = 0;
234
- _context4.next = 3;
277
+ _context5.prev = 0;
278
+ _context5.next = 3;
235
279
  return this.providersLoader.load('providersData');
236
280
  case 3:
237
- this.providersData = _context4.sent;
238
- _context4.next = 11;
281
+ this.providersData = _context5.sent;
282
+ _context5.next = 11;
239
283
  break;
240
284
  case 6:
241
- _context4.prev = 6;
242
- _context4.t0 = _context4["catch"](0);
285
+ _context5.prev = 6;
286
+ _context5.t0 = _context5["catch"](0);
243
287
  // eslint-disable-next-line
244
- console.error('failed to fetch /providers', _context4.t0);
288
+ console.error('failed to fetch /providers', _context5.t0);
245
289
  this.providersLoader.clear('providerData');
246
- return _context4.abrupt("return", undefined);
290
+ return _context5.abrupt("return", undefined);
247
291
  case 11:
248
292
  case "end":
249
- return _context4.stop();
293
+ return _context5.stop();
250
294
  }
251
- }, _callee4, this, [[0, 6]]);
295
+ }, _callee5, this, [[0, 6]]);
252
296
  }));
253
297
  function loadProviderData() {
254
298
  return _loadProviderData.apply(this, arguments);
@@ -258,31 +302,31 @@ export var EditorCardProvider = /*#__PURE__*/function () {
258
302
  }, {
259
303
  key: "findPattern",
260
304
  value: function () {
261
- var _findPattern = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(url) {
262
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
263
- while (1) switch (_context5.prev = _context5.next) {
305
+ var _findPattern = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(url) {
306
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
307
+ while (1) switch (_context6.prev = _context6.next) {
264
308
  case 0:
265
- _context5.next = 2;
309
+ _context6.next = 2;
266
310
  return this.findPatternData(url);
267
311
  case 2:
268
- _context5.t0 = !!_context5.sent;
269
- if (_context5.t0) {
270
- _context5.next = 7;
312
+ _context6.t0 = !!_context6.sent;
313
+ if (_context6.t0) {
314
+ _context6.next = 7;
271
315
  break;
272
316
  }
273
- _context5.next = 6;
317
+ _context6.next = 6;
274
318
  return this.checkLinkResolved(url);
275
319
  case 6:
276
- _context5.t0 = !!_context5.sent;
320
+ _context6.t0 = !!_context6.sent;
277
321
  case 7:
278
- return _context5.abrupt("return", _context5.t0);
322
+ return _context6.abrupt("return", _context6.t0);
279
323
  case 8:
280
324
  case "end":
281
- return _context5.stop();
325
+ return _context6.stop();
282
326
  }
283
- }, _callee5, this);
327
+ }, _callee6, this);
284
328
  }));
285
- function findPattern(_x3) {
329
+ function findPattern(_x4) {
286
330
  return _findPattern.apply(this, arguments);
287
331
  }
288
332
  return findPattern;
@@ -300,23 +344,23 @@ export var EditorCardProvider = /*#__PURE__*/function () {
300
344
  }, {
301
345
  key: "findUserPreference",
302
346
  value: function () {
303
- var _findUserPreference = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(url) {
347
+ var _findUserPreference = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(url) {
304
348
  var _this$providersData,
305
349
  _this2 = this;
306
350
  var userPreferences, defaultAppearance, appearances, allMatchedLabeledAppearances, longestMatchedLabeledAppearance;
307
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
308
- while (1) switch (_context6.prev = _context6.next) {
351
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
352
+ while (1) switch (_context7.prev = _context7.next) {
309
353
  case 0:
310
354
  if (this.providersData) {
311
- _context6.next = 3;
355
+ _context7.next = 3;
312
356
  break;
313
357
  }
314
- _context6.next = 3;
358
+ _context7.next = 3;
315
359
  return this.loadProviderData();
316
360
  case 3:
317
361
  userPreferences = (_this$providersData = this.providersData) === null || _this$providersData === void 0 ? void 0 : _this$providersData.userPreferences;
318
362
  if (!userPreferences) {
319
- _context6.next = 12;
363
+ _context7.next = 12;
320
364
  break;
321
365
  }
322
366
  defaultAppearance = userPreferences.defaultAppearance, appearances = userPreferences.appearances;
@@ -325,26 +369,26 @@ export var EditorCardProvider = /*#__PURE__*/function () {
325
369
  return _this2.doesUrlMatchPath(urlSegment, url);
326
370
  });
327
371
  if (!(allMatchedLabeledAppearances.length > 0)) {
328
- _context6.next = 10;
372
+ _context7.next = 10;
329
373
  break;
330
374
  }
331
375
  longestMatchedLabeledAppearance = allMatchedLabeledAppearances.reduce(function (previousLabeledAppearance, currentLabeledAppearance) {
332
376
  return previousLabeledAppearance.urlSegment.length > currentLabeledAppearance.urlSegment.length ? previousLabeledAppearance : currentLabeledAppearance;
333
377
  });
334
- return _context6.abrupt("return", longestMatchedLabeledAppearance.appearance);
378
+ return _context7.abrupt("return", longestMatchedLabeledAppearance.appearance);
335
379
  case 10:
336
380
  if (!(defaultAppearance !== 'inline')) {
337
- _context6.next = 12;
381
+ _context7.next = 12;
338
382
  break;
339
383
  }
340
- return _context6.abrupt("return", defaultAppearance);
384
+ return _context7.abrupt("return", defaultAppearance);
341
385
  case 12:
342
386
  case "end":
343
- return _context6.stop();
387
+ return _context7.stop();
344
388
  }
345
- }, _callee6, this);
389
+ }, _callee7, this);
346
390
  }));
347
- function findUserPreference(_x4) {
391
+ function findUserPreference(_x5) {
348
392
  return _findUserPreference.apply(this, arguments);
349
393
  }
350
394
  return findUserPreference;
@@ -352,28 +396,28 @@ export var EditorCardProvider = /*#__PURE__*/function () {
352
396
  }, {
353
397
  key: "findPatternData",
354
398
  value: function () {
355
- var _findPatternData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(url) {
399
+ var _findPatternData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(url) {
356
400
  var _this$providersData2;
357
- return _regeneratorRuntime.wrap(function _callee7$(_context7) {
358
- while (1) switch (_context7.prev = _context7.next) {
401
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
402
+ while (1) switch (_context8.prev = _context8.next) {
359
403
  case 0:
360
404
  if (this.providersData) {
361
- _context7.next = 3;
405
+ _context8.next = 3;
362
406
  break;
363
407
  }
364
- _context7.next = 3;
408
+ _context8.next = 3;
365
409
  return this.loadProviderData();
366
410
  case 3:
367
- return _context7.abrupt("return", (_this$providersData2 = this.providersData) === null || _this$providersData2 === void 0 ? void 0 : _this$providersData2.patterns.find(function (pattern) {
411
+ return _context8.abrupt("return", (_this$providersData2 = this.providersData) === null || _this$providersData2 === void 0 ? void 0 : _this$providersData2.patterns.find(function (pattern) {
368
412
  return url.match(pattern.source);
369
413
  }));
370
414
  case 4:
371
415
  case "end":
372
- return _context7.stop();
416
+ return _context8.stop();
373
417
  }
374
- }, _callee7, this);
418
+ }, _callee8, this);
375
419
  }));
376
- function findPatternData(_x5) {
420
+ function findPatternData(_x6) {
377
421
  return _findPatternData.apply(this, arguments);
378
422
  }
379
423
  return findPatternData;
@@ -422,41 +466,41 @@ export var EditorCardProvider = /*#__PURE__*/function () {
422
466
  * Make a /resolve call and find out if result has embed capability
423
467
  */
424
468
  function () {
425
- var _canBeResolvedAsEmbed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(url) {
469
+ var _canBeResolvedAsEmbed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(url) {
426
470
  var details, embed;
427
- return _regeneratorRuntime.wrap(function _callee8$(_context8) {
428
- while (1) switch (_context8.prev = _context8.next) {
471
+ return _regeneratorRuntime.wrap(function _callee9$(_context9) {
472
+ while (1) switch (_context9.prev = _context9.next) {
429
473
  case 0:
430
- _context8.prev = 0;
431
- _context8.next = 3;
474
+ _context9.prev = 0;
475
+ _context9.next = 3;
432
476
  return this.cardClient.fetchData(url);
433
477
  case 3:
434
- details = _context8.sent;
478
+ details = _context9.sent;
435
479
  if (details) {
436
- _context8.next = 6;
480
+ _context9.next = 6;
437
481
  break;
438
482
  }
439
- return _context8.abrupt("return", false);
483
+ return _context9.abrupt("return", false);
440
484
  case 6:
441
485
  if (!(getStatus(details) !== 'resolved')) {
442
- _context8.next = 8;
486
+ _context9.next = 8;
443
487
  break;
444
488
  }
445
- return _context8.abrupt("return", false);
489
+ return _context9.abrupt("return", false);
446
490
  case 8:
447
491
  embed = extractSmartLinkEmbed(details);
448
- return _context8.abrupt("return", !!embed);
492
+ return _context9.abrupt("return", !!embed);
449
493
  case 12:
450
- _context8.prev = 12;
451
- _context8.t0 = _context8["catch"](0);
452
- return _context8.abrupt("return", false);
494
+ _context9.prev = 12;
495
+ _context9.t0 = _context9["catch"](0);
496
+ return _context9.abrupt("return", false);
453
497
  case 15:
454
498
  case "end":
455
- return _context8.stop();
499
+ return _context9.stop();
456
500
  }
457
- }, _callee8, this, [[0, 12]]);
501
+ }, _callee9, this, [[0, 12]]);
458
502
  }));
459
- function canBeResolvedAsEmbed(_x6) {
503
+ function canBeResolvedAsEmbed(_x7) {
460
504
  return _canBeResolvedAsEmbed.apply(this, arguments);
461
505
  }
462
506
  return canBeResolvedAsEmbed;
@@ -468,85 +512,110 @@ export var EditorCardProvider = /*#__PURE__*/function () {
468
512
  }, {
469
513
  key: "getDatasourceFromResolveResponse",
470
514
  value: (function () {
471
- var _getDatasourceFromResolveResponse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(url) {
515
+ var _getDatasourceFromResolveResponse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee0(url) {
472
516
  var response, datasources;
473
- return _regeneratorRuntime.wrap(function _callee9$(_context9) {
474
- while (1) switch (_context9.prev = _context9.next) {
517
+ return _regeneratorRuntime.wrap(function _callee0$(_context0) {
518
+ while (1) switch (_context0.prev = _context0.next) {
475
519
  case 0:
476
- _context9.prev = 0;
477
- _context9.next = 3;
520
+ _context0.prev = 0;
521
+ _context0.next = 3;
478
522
  return this.cardClient.fetchData(url);
479
523
  case 3:
480
- response = _context9.sent;
524
+ response = _context0.sent;
481
525
  datasources = response && response.datasources || [];
482
526
  if (!(datasources.length > 0)) {
483
- _context9.next = 7;
527
+ _context0.next = 7;
484
528
  break;
485
529
  }
486
- return _context9.abrupt("return", datasources[0]);
530
+ return _context0.abrupt("return", datasources[0]);
487
531
  case 7:
488
- _context9.next = 12;
532
+ _context0.next = 12;
489
533
  break;
490
534
  case 9:
491
- _context9.prev = 9;
492
- _context9.t0 = _context9["catch"](0);
493
- return _context9.abrupt("return", undefined);
535
+ _context0.prev = 9;
536
+ _context0.t0 = _context0["catch"](0);
537
+ return _context0.abrupt("return", undefined);
494
538
  case 12:
495
539
  case "end":
496
- return _context9.stop();
540
+ return _context0.stop();
497
541
  }
498
- }, _callee9, this, [[0, 9]]);
542
+ }, _callee0, this, [[0, 9]]);
499
543
  }));
500
- function getDatasourceFromResolveResponse(_x7) {
544
+ function getDatasourceFromResolveResponse(_x8) {
501
545
  return _getDatasourceFromResolveResponse.apply(this, arguments);
502
546
  }
503
547
  return getDatasourceFromResolveResponse;
504
- }())
548
+ }()
549
+ /**
550
+ * This is used to determine if the url is a local Jira url or a remote one.
551
+ */
552
+ )
553
+ }, {
554
+ key: "isLocalUrl",
555
+ value: function isLocalUrl(url) {
556
+ return new URL(url).origin === this.baseUrl;
557
+ }
505
558
  }, {
506
559
  key: "resolve",
507
560
  value: function () {
508
- var _resolve = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee0(url, appearance, shouldForceAppearance, isEmbedFriendlyLocation) {
509
- var hardCodedAppearance, _yield$Promise$all, _yield$Promise$all2, matchedProviderPattern, userPreference, _this$onResolve, isSupported, providerDefaultAppearance, preferredAppearance, canItBeEmbed, datasource, id, parameters;
510
- return _regeneratorRuntime.wrap(function _callee0$(_context0) {
511
- while (1) switch (_context0.prev = _context0.next) {
561
+ var _resolve = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee1(url, appearance, shouldForceAppearance, isEmbedFriendlyLocation) {
562
+ var hardCodedAppearance, _yield$Promise$all, _yield$Promise$all2, matchedProviderPattern, userPreference, data, issueAri, _this$onResolve, isSupported, providerDefaultAppearance, preferredAppearance, canItBeEmbed, datasource, id, parameters;
563
+ return _regeneratorRuntime.wrap(function _callee1$(_context1) {
564
+ while (1) switch (_context1.prev = _context1.next) {
512
565
  case 0:
513
- _context0.prev = 0;
566
+ _context1.prev = 0;
514
567
  if (!(shouldForceAppearance === true)) {
515
- _context0.next = 3;
568
+ _context1.next = 3;
516
569
  break;
517
570
  }
518
- return _context0.abrupt("return", this.transformer.toSmartlinkAdf(url, appearance));
571
+ return _context1.abrupt("return", this.transformer.toSmartlinkAdf(url, appearance));
519
572
  case 3:
520
573
  hardCodedAppearance = this.getHardCodedAppearance(url);
521
- _context0.next = 6;
574
+ _context1.next = 6;
522
575
  return Promise.all([this.findPatternData(url), this.findUserPreference(url)]);
523
576
  case 6:
524
- _yield$Promise$all = _context0.sent;
577
+ _yield$Promise$all = _context1.sent;
525
578
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
526
579
  matchedProviderPattern = _yield$Promise$all2[0];
527
580
  userPreference = _yield$Promise$all2[1];
528
- if (isJiraWorkItem(url) && fg('issue-link-suggestions-in-comments')) {
529
- (_this$onResolve = this.onResolve) === null || _this$onResolve === void 0 || _this$onResolve.call(this, url);
581
+ if (!fg('issue-link-suggestions-in-comments')) {
582
+ _context1.next = 16;
583
+ break;
530
584
  }
585
+ if (!(isJiraWorkItem(url) && this.isLocalUrl(url))) {
586
+ _context1.next = 16;
587
+ break;
588
+ }
589
+ _context1.next = 14;
590
+ return this.fetchDataForResource(url);
591
+ case 14:
592
+ data = _context1.sent;
593
+ if (data) {
594
+ issueAri = this.extractAriFromData(data);
595
+ if (issueAri) {
596
+ (_this$onResolve = this.onResolve) === null || _this$onResolve === void 0 || _this$onResolve.call(this, url, issueAri);
597
+ }
598
+ }
599
+ case 16:
531
600
  if (!(shouldForceAppearance === false && userPreference === 'url')) {
532
- _context0.next = 13;
601
+ _context1.next = 18;
533
602
  break;
534
603
  }
535
- return _context0.abrupt("return", Promise.reject(undefined));
536
- case 13:
537
- _context0.t0 = !!matchedProviderPattern;
538
- if (_context0.t0) {
539
- _context0.next = 18;
604
+ return _context1.abrupt("return", Promise.reject(undefined));
605
+ case 18:
606
+ _context1.t0 = !!matchedProviderPattern;
607
+ if (_context1.t0) {
608
+ _context1.next = 23;
540
609
  break;
541
610
  }
542
- _context0.next = 17;
611
+ _context1.next = 22;
543
612
  return this.checkLinkResolved(url);
544
- case 17:
545
- _context0.t0 = _context0.sent;
546
- case 18:
547
- isSupported = _context0.t0;
613
+ case 22:
614
+ _context1.t0 = _context1.sent;
615
+ case 23:
616
+ isSupported = _context1.t0;
548
617
  if (!isSupported) {
549
- _context0.next = 34;
618
+ _context1.next = 39;
550
619
  break;
551
620
  }
552
621
  providerDefaultAppearance = matchedProviderPattern === null || matchedProviderPattern === void 0 ? void 0 : matchedProviderPattern.defaultView;
@@ -564,27 +633,27 @@ export var EditorCardProvider = /*#__PURE__*/function () {
564
633
  // If not, we pick what editor (or any other client) requested
565
634
  appearance;
566
635
  if (!(preferredAppearance === userPreference && userPreference === 'embed')) {
567
- _context0.next = 27;
636
+ _context1.next = 32;
568
637
  break;
569
638
  }
570
- _context0.next = 25;
639
+ _context1.next = 30;
571
640
  return this.canBeResolvedAsEmbed(url);
572
- case 25:
573
- canItBeEmbed = _context0.sent;
641
+ case 30:
642
+ canItBeEmbed = _context1.sent;
574
643
  if (!canItBeEmbed) {
575
644
  preferredAppearance = 'inline';
576
645
  }
577
- case 27:
578
- _context0.next = 29;
646
+ case 32:
647
+ _context1.next = 34;
579
648
  return this.getDatasourceFromResolveResponse(url);
580
- case 29:
581
- datasource = _context0.sent;
649
+ case 34:
650
+ datasource = _context1.sent;
582
651
  if (!datasource) {
583
- _context0.next = 33;
652
+ _context1.next = 38;
584
653
  break;
585
654
  }
586
655
  id = datasource.id, parameters = datasource.parameters;
587
- return _context0.abrupt("return", this.transformer.toDatasourceAdf({
656
+ return _context1.abrupt("return", this.transformer.toDatasourceAdf({
588
657
  id: id,
589
658
  parameters: parameters,
590
659
  // in the future when we support multiple views, we will need to pass this in as a parameter
@@ -593,25 +662,25 @@ export var EditorCardProvider = /*#__PURE__*/function () {
593
662
  type: 'table'
594
663
  }]
595
664
  }, url));
596
- case 33:
597
- return _context0.abrupt("return", this.transformer.toSmartlinkAdf(url, preferredAppearance));
598
- case 34:
599
- _context0.next = 39;
665
+ case 38:
666
+ return _context1.abrupt("return", this.transformer.toSmartlinkAdf(url, preferredAppearance));
667
+ case 39:
668
+ _context1.next = 44;
600
669
  break;
601
- case 36:
602
- _context0.prev = 36;
603
- _context0.t1 = _context0["catch"](0);
670
+ case 41:
671
+ _context1.prev = 41;
672
+ _context1.t1 = _context1["catch"](0);
604
673
  // eslint-disable-next-line
605
- console.warn("Error when trying to check Smart Card url \"".concat(url, "\"").concat(_context0.t1 instanceof Error ? " - ".concat(_context0.t1.name, " ").concat(_context0.t1.message) : ''), _context0.t1);
606
- case 39:
607
- return _context0.abrupt("return", Promise.reject(undefined));
608
- case 40:
674
+ console.warn("Error when trying to check Smart Card url \"".concat(url, "\"").concat(_context1.t1 instanceof Error ? " - ".concat(_context1.t1.name, " ").concat(_context1.t1.message) : ''), _context1.t1);
675
+ case 44:
676
+ return _context1.abrupt("return", Promise.reject(undefined));
677
+ case 45:
609
678
  case "end":
610
- return _context0.stop();
679
+ return _context1.stop();
611
680
  }
612
- }, _callee0, this, [[0, 36]]);
681
+ }, _callee1, this, [[0, 41]]);
613
682
  }));
614
- function resolve(_x8, _x9, _x0, _x1) {
683
+ function resolve(_x9, _x0, _x1, _x10) {
615
684
  return _resolve.apply(this, arguments);
616
685
  }
617
686
  return resolve;
@@ -14,6 +14,8 @@ export declare class EditorCardProvider implements CardProvider {
14
14
  constructor(envKey?: EnvironmentsKeys, baseUrlOverride?: string, product?: ProductType, onResolve?: (url: string) => void);
15
15
  private batchProviders;
16
16
  private checkLinkResolved;
17
+ private fetchDataForResource;
18
+ private extractAriFromData;
17
19
  private fetchProvidersData;
18
20
  private loadProviderData;
19
21
  findPattern(url: string): Promise<boolean>;
@@ -39,6 +41,10 @@ export declare class EditorCardProvider implements CardProvider {
39
41
  * Make a /resolve call and find out if result has datasource capability
40
42
  */
41
43
  private getDatasourceFromResolveResponse;
44
+ /**
45
+ * This is used to determine if the url is a local Jira url or a remote one.
46
+ */
47
+ private isLocalUrl;
42
48
  resolve(url: string, appearance: CardAppearance, shouldForceAppearance?: boolean, isEmbedFriendlyLocation?: boolean): Promise<CardAdf | DatasourceAdf>;
43
49
  }
44
50
  export declare const editorCardProvider: EditorCardProvider;
@@ -14,6 +14,8 @@ export declare class EditorCardProvider implements CardProvider {
14
14
  constructor(envKey?: EnvironmentsKeys, baseUrlOverride?: string, product?: ProductType, onResolve?: (url: string) => void);
15
15
  private batchProviders;
16
16
  private checkLinkResolved;
17
+ private fetchDataForResource;
18
+ private extractAriFromData;
17
19
  private fetchProvidersData;
18
20
  private loadProviderData;
19
21
  findPattern(url: string): Promise<boolean>;
@@ -39,6 +41,10 @@ export declare class EditorCardProvider implements CardProvider {
39
41
  * Make a /resolve call and find out if result has datasource capability
40
42
  */
41
43
  private getDatasourceFromResolveResponse;
44
+ /**
45
+ * This is used to determine if the url is a local Jira url or a remote one.
46
+ */
47
+ private isLocalUrl;
42
48
  resolve(url: string, appearance: CardAppearance, shouldForceAppearance?: boolean, isEmbedFriendlyLocation?: boolean): Promise<CardAdf | DatasourceAdf>;
43
49
  }
44
50
  export declare const editorCardProvider: EditorCardProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-card-provider",
3
- "version": "5.0.4",
3
+ "version": "5.1.1",
4
4
  "description": "Contains the EditorCardProvider, for determining smart card behaviour in the editor.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -36,9 +36,9 @@
36
36
  "@atlaskit/feature-gate-js-client": "^5.3.0",
37
37
  "@atlaskit/json-ld-types": "^1.2.0",
38
38
  "@atlaskit/link-client-extension": "^5.0.0",
39
- "@atlaskit/link-extractors": "^2.3.0",
40
- "@atlaskit/linking-common": "^9.0.0",
41
- "@atlaskit/linking-types": "^12.0.0",
39
+ "@atlaskit/link-extractors": "^2.4.0",
40
+ "@atlaskit/linking-common": "^9.1.0",
41
+ "@atlaskit/linking-types": "^13.0.0",
42
42
  "@atlaskit/platform-feature-flags": "^1.1.0",
43
43
  "@babel/runtime": "^7.0.0",
44
44
  "dataloader": "^2.1.0"