@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 +14 -0
- package/dist/cjs/provider.js +205 -136
- package/dist/es2019/provider.js +34 -3
- package/dist/esm/provider.js +205 -136
- package/dist/types/provider.d.ts +6 -0
- package/dist/types-ts4.5/provider.d.ts +6 -0
- package/package.json +4 -4
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
|
package/dist/cjs/provider.js
CHANGED
|
@@ -201,19 +201,63 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function () {
|
|
|
201
201
|
return checkLinkResolved;
|
|
202
202
|
}()
|
|
203
203
|
}, {
|
|
204
|
-
key: "
|
|
204
|
+
key: "fetchDataForResource",
|
|
205
205
|
value: function () {
|
|
206
|
-
var
|
|
207
|
-
var
|
|
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
|
-
|
|
211
|
+
_context3.prev = 0;
|
|
212
212
|
_context3.next = 3;
|
|
213
|
-
return
|
|
213
|
+
return this.cardClient.fetchData(resourceUrl);
|
|
214
214
|
case 3:
|
|
215
215
|
response = _context3.sent;
|
|
216
|
-
|
|
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
|
|
268
|
+
return _context4.stop();
|
|
225
269
|
}
|
|
226
|
-
},
|
|
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
|
|
237
|
-
return _regenerator.default.wrap(function
|
|
238
|
-
while (1) switch (
|
|
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
|
-
|
|
241
|
-
|
|
284
|
+
_context5.prev = 0;
|
|
285
|
+
_context5.next = 3;
|
|
242
286
|
return this.providersLoader.load('providersData');
|
|
243
287
|
case 3:
|
|
244
|
-
this.providersData =
|
|
245
|
-
|
|
288
|
+
this.providersData = _context5.sent;
|
|
289
|
+
_context5.next = 11;
|
|
246
290
|
break;
|
|
247
291
|
case 6:
|
|
248
|
-
|
|
249
|
-
|
|
292
|
+
_context5.prev = 6;
|
|
293
|
+
_context5.t0 = _context5["catch"](0);
|
|
250
294
|
// eslint-disable-next-line
|
|
251
|
-
console.error('failed to fetch /providers',
|
|
295
|
+
console.error('failed to fetch /providers', _context5.t0);
|
|
252
296
|
this.providersLoader.clear('providerData');
|
|
253
|
-
return
|
|
297
|
+
return _context5.abrupt("return", undefined);
|
|
254
298
|
case 11:
|
|
255
299
|
case "end":
|
|
256
|
-
return
|
|
300
|
+
return _context5.stop();
|
|
257
301
|
}
|
|
258
|
-
},
|
|
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
|
|
269
|
-
return _regenerator.default.wrap(function
|
|
270
|
-
while (1) switch (
|
|
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
|
-
|
|
316
|
+
_context6.next = 2;
|
|
273
317
|
return this.findPatternData(url);
|
|
274
318
|
case 2:
|
|
275
|
-
|
|
276
|
-
if (
|
|
277
|
-
|
|
319
|
+
_context6.t0 = !!_context6.sent;
|
|
320
|
+
if (_context6.t0) {
|
|
321
|
+
_context6.next = 7;
|
|
278
322
|
break;
|
|
279
323
|
}
|
|
280
|
-
|
|
324
|
+
_context6.next = 6;
|
|
281
325
|
return this.checkLinkResolved(url);
|
|
282
326
|
case 6:
|
|
283
|
-
|
|
327
|
+
_context6.t0 = !!_context6.sent;
|
|
284
328
|
case 7:
|
|
285
|
-
return
|
|
329
|
+
return _context6.abrupt("return", _context6.t0);
|
|
286
330
|
case 8:
|
|
287
331
|
case "end":
|
|
288
|
-
return
|
|
332
|
+
return _context6.stop();
|
|
289
333
|
}
|
|
290
|
-
},
|
|
334
|
+
}, _callee6, this);
|
|
291
335
|
}));
|
|
292
|
-
function findPattern(
|
|
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
|
|
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
|
|
315
|
-
while (1) switch (
|
|
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
|
-
|
|
362
|
+
_context7.next = 3;
|
|
319
363
|
break;
|
|
320
364
|
}
|
|
321
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
385
|
+
return _context7.abrupt("return", longestMatchedLabeledAppearance.appearance);
|
|
342
386
|
case 10:
|
|
343
387
|
if (!(defaultAppearance !== 'inline')) {
|
|
344
|
-
|
|
388
|
+
_context7.next = 12;
|
|
345
389
|
break;
|
|
346
390
|
}
|
|
347
|
-
return
|
|
391
|
+
return _context7.abrupt("return", defaultAppearance);
|
|
348
392
|
case 12:
|
|
349
393
|
case "end":
|
|
350
|
-
return
|
|
394
|
+
return _context7.stop();
|
|
351
395
|
}
|
|
352
|
-
},
|
|
396
|
+
}, _callee7, this);
|
|
353
397
|
}));
|
|
354
|
-
function findUserPreference(
|
|
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
|
|
406
|
+
var _findPatternData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(url) {
|
|
363
407
|
var _this$providersData2;
|
|
364
|
-
return _regenerator.default.wrap(function
|
|
365
|
-
while (1) switch (
|
|
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
|
-
|
|
412
|
+
_context8.next = 3;
|
|
369
413
|
break;
|
|
370
414
|
}
|
|
371
|
-
|
|
415
|
+
_context8.next = 3;
|
|
372
416
|
return this.loadProviderData();
|
|
373
417
|
case 3:
|
|
374
|
-
return
|
|
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
|
|
423
|
+
return _context8.stop();
|
|
380
424
|
}
|
|
381
|
-
},
|
|
425
|
+
}, _callee8, this);
|
|
382
426
|
}));
|
|
383
|
-
function findPatternData(
|
|
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
|
|
476
|
+
var _canBeResolvedAsEmbed = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(url) {
|
|
433
477
|
var details, embed;
|
|
434
|
-
return _regenerator.default.wrap(function
|
|
435
|
-
while (1) switch (
|
|
478
|
+
return _regenerator.default.wrap(function _callee9$(_context9) {
|
|
479
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
436
480
|
case 0:
|
|
437
|
-
|
|
438
|
-
|
|
481
|
+
_context9.prev = 0;
|
|
482
|
+
_context9.next = 3;
|
|
439
483
|
return this.cardClient.fetchData(url);
|
|
440
484
|
case 3:
|
|
441
|
-
details =
|
|
485
|
+
details = _context9.sent;
|
|
442
486
|
if (details) {
|
|
443
|
-
|
|
487
|
+
_context9.next = 6;
|
|
444
488
|
break;
|
|
445
489
|
}
|
|
446
|
-
return
|
|
490
|
+
return _context9.abrupt("return", false);
|
|
447
491
|
case 6:
|
|
448
492
|
if (!((0, _linkingCommon.getStatus)(details) !== 'resolved')) {
|
|
449
|
-
|
|
493
|
+
_context9.next = 8;
|
|
450
494
|
break;
|
|
451
495
|
}
|
|
452
|
-
return
|
|
496
|
+
return _context9.abrupt("return", false);
|
|
453
497
|
case 8:
|
|
454
498
|
embed = (0, _linkExtractors.extractSmartLinkEmbed)(details);
|
|
455
|
-
return
|
|
499
|
+
return _context9.abrupt("return", !!embed);
|
|
456
500
|
case 12:
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
return
|
|
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
|
|
506
|
+
return _context9.stop();
|
|
463
507
|
}
|
|
464
|
-
},
|
|
508
|
+
}, _callee9, this, [[0, 12]]);
|
|
465
509
|
}));
|
|
466
|
-
function canBeResolvedAsEmbed(
|
|
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
|
|
522
|
+
var _getDatasourceFromResolveResponse = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee0(url) {
|
|
479
523
|
var response, datasources;
|
|
480
|
-
return _regenerator.default.wrap(function
|
|
481
|
-
while (1) switch (
|
|
524
|
+
return _regenerator.default.wrap(function _callee0$(_context0) {
|
|
525
|
+
while (1) switch (_context0.prev = _context0.next) {
|
|
482
526
|
case 0:
|
|
483
|
-
|
|
484
|
-
|
|
527
|
+
_context0.prev = 0;
|
|
528
|
+
_context0.next = 3;
|
|
485
529
|
return this.cardClient.fetchData(url);
|
|
486
530
|
case 3:
|
|
487
|
-
response =
|
|
531
|
+
response = _context0.sent;
|
|
488
532
|
datasources = response && response.datasources || [];
|
|
489
533
|
if (!(datasources.length > 0)) {
|
|
490
|
-
|
|
534
|
+
_context0.next = 7;
|
|
491
535
|
break;
|
|
492
536
|
}
|
|
493
|
-
return
|
|
537
|
+
return _context0.abrupt("return", datasources[0]);
|
|
494
538
|
case 7:
|
|
495
|
-
|
|
539
|
+
_context0.next = 12;
|
|
496
540
|
break;
|
|
497
541
|
case 9:
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
return
|
|
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
|
|
547
|
+
return _context0.stop();
|
|
504
548
|
}
|
|
505
|
-
},
|
|
549
|
+
}, _callee0, this, [[0, 9]]);
|
|
506
550
|
}));
|
|
507
|
-
function getDatasourceFromResolveResponse(
|
|
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
|
|
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
|
|
518
|
-
while (1) switch (
|
|
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
|
-
|
|
573
|
+
_context1.prev = 0;
|
|
521
574
|
if (!(shouldForceAppearance === true)) {
|
|
522
|
-
|
|
575
|
+
_context1.next = 3;
|
|
523
576
|
break;
|
|
524
577
|
}
|
|
525
|
-
return
|
|
578
|
+
return _context1.abrupt("return", this.transformer.toSmartlinkAdf(url, appearance));
|
|
526
579
|
case 3:
|
|
527
580
|
hardCodedAppearance = this.getHardCodedAppearance(url);
|
|
528
|
-
|
|
581
|
+
_context1.next = 6;
|
|
529
582
|
return Promise.all([this.findPatternData(url), this.findUserPreference(url)]);
|
|
530
583
|
case 6:
|
|
531
|
-
_yield$Promise$all =
|
|
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 (
|
|
536
|
-
|
|
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
|
-
|
|
608
|
+
_context1.next = 18;
|
|
540
609
|
break;
|
|
541
610
|
}
|
|
542
|
-
return
|
|
543
|
-
case
|
|
544
|
-
|
|
545
|
-
if (
|
|
546
|
-
|
|
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
|
-
|
|
618
|
+
_context1.next = 22;
|
|
550
619
|
return this.checkLinkResolved(url);
|
|
551
|
-
case
|
|
552
|
-
|
|
553
|
-
case
|
|
554
|
-
isSupported =
|
|
620
|
+
case 22:
|
|
621
|
+
_context1.t0 = _context1.sent;
|
|
622
|
+
case 23:
|
|
623
|
+
isSupported = _context1.t0;
|
|
555
624
|
if (!isSupported) {
|
|
556
|
-
|
|
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
|
-
|
|
643
|
+
_context1.next = 32;
|
|
575
644
|
break;
|
|
576
645
|
}
|
|
577
|
-
|
|
646
|
+
_context1.next = 30;
|
|
578
647
|
return this.canBeResolvedAsEmbed(url);
|
|
579
|
-
case
|
|
580
|
-
canItBeEmbed =
|
|
648
|
+
case 30:
|
|
649
|
+
canItBeEmbed = _context1.sent;
|
|
581
650
|
if (!canItBeEmbed) {
|
|
582
651
|
preferredAppearance = 'inline';
|
|
583
652
|
}
|
|
584
|
-
case
|
|
585
|
-
|
|
653
|
+
case 32:
|
|
654
|
+
_context1.next = 34;
|
|
586
655
|
return this.getDatasourceFromResolveResponse(url);
|
|
587
|
-
case
|
|
588
|
-
datasource =
|
|
656
|
+
case 34:
|
|
657
|
+
datasource = _context1.sent;
|
|
589
658
|
if (!datasource) {
|
|
590
|
-
|
|
659
|
+
_context1.next = 38;
|
|
591
660
|
break;
|
|
592
661
|
}
|
|
593
662
|
id = datasource.id, parameters = datasource.parameters;
|
|
594
|
-
return
|
|
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
|
|
604
|
-
return
|
|
605
|
-
case
|
|
606
|
-
|
|
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
|
|
609
|
-
|
|
610
|
-
|
|
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(
|
|
613
|
-
case
|
|
614
|
-
return
|
|
615
|
-
case
|
|
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
|
|
686
|
+
return _context1.stop();
|
|
618
687
|
}
|
|
619
|
-
},
|
|
688
|
+
}, _callee1, this, [[0, 41]]);
|
|
620
689
|
}));
|
|
621
|
-
function resolve(
|
|
690
|
+
function resolve(_x9, _x0, _x1, _x10) {
|
|
622
691
|
return _resolve.apply(this, arguments);
|
|
623
692
|
}
|
|
624
693
|
return resolve;
|
package/dist/es2019/provider.js
CHANGED
|
@@ -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 (
|
|
243
|
-
|
|
244
|
-
|
|
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);
|
package/dist/esm/provider.js
CHANGED
|
@@ -194,19 +194,63 @@ export var EditorCardProvider = /*#__PURE__*/function () {
|
|
|
194
194
|
return checkLinkResolved;
|
|
195
195
|
}()
|
|
196
196
|
}, {
|
|
197
|
-
key: "
|
|
197
|
+
key: "fetchDataForResource",
|
|
198
198
|
value: function () {
|
|
199
|
-
var
|
|
200
|
-
var
|
|
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
|
-
|
|
204
|
+
_context3.prev = 0;
|
|
205
205
|
_context3.next = 3;
|
|
206
|
-
return
|
|
206
|
+
return this.cardClient.fetchData(resourceUrl);
|
|
207
207
|
case 3:
|
|
208
208
|
response = _context3.sent;
|
|
209
|
-
|
|
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
|
|
261
|
+
return _context4.stop();
|
|
218
262
|
}
|
|
219
|
-
},
|
|
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
|
|
230
|
-
return _regeneratorRuntime.wrap(function
|
|
231
|
-
while (1) switch (
|
|
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
|
-
|
|
234
|
-
|
|
277
|
+
_context5.prev = 0;
|
|
278
|
+
_context5.next = 3;
|
|
235
279
|
return this.providersLoader.load('providersData');
|
|
236
280
|
case 3:
|
|
237
|
-
this.providersData =
|
|
238
|
-
|
|
281
|
+
this.providersData = _context5.sent;
|
|
282
|
+
_context5.next = 11;
|
|
239
283
|
break;
|
|
240
284
|
case 6:
|
|
241
|
-
|
|
242
|
-
|
|
285
|
+
_context5.prev = 6;
|
|
286
|
+
_context5.t0 = _context5["catch"](0);
|
|
243
287
|
// eslint-disable-next-line
|
|
244
|
-
console.error('failed to fetch /providers',
|
|
288
|
+
console.error('failed to fetch /providers', _context5.t0);
|
|
245
289
|
this.providersLoader.clear('providerData');
|
|
246
|
-
return
|
|
290
|
+
return _context5.abrupt("return", undefined);
|
|
247
291
|
case 11:
|
|
248
292
|
case "end":
|
|
249
|
-
return
|
|
293
|
+
return _context5.stop();
|
|
250
294
|
}
|
|
251
|
-
},
|
|
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
|
|
262
|
-
return _regeneratorRuntime.wrap(function
|
|
263
|
-
while (1) switch (
|
|
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
|
-
|
|
309
|
+
_context6.next = 2;
|
|
266
310
|
return this.findPatternData(url);
|
|
267
311
|
case 2:
|
|
268
|
-
|
|
269
|
-
if (
|
|
270
|
-
|
|
312
|
+
_context6.t0 = !!_context6.sent;
|
|
313
|
+
if (_context6.t0) {
|
|
314
|
+
_context6.next = 7;
|
|
271
315
|
break;
|
|
272
316
|
}
|
|
273
|
-
|
|
317
|
+
_context6.next = 6;
|
|
274
318
|
return this.checkLinkResolved(url);
|
|
275
319
|
case 6:
|
|
276
|
-
|
|
320
|
+
_context6.t0 = !!_context6.sent;
|
|
277
321
|
case 7:
|
|
278
|
-
return
|
|
322
|
+
return _context6.abrupt("return", _context6.t0);
|
|
279
323
|
case 8:
|
|
280
324
|
case "end":
|
|
281
|
-
return
|
|
325
|
+
return _context6.stop();
|
|
282
326
|
}
|
|
283
|
-
},
|
|
327
|
+
}, _callee6, this);
|
|
284
328
|
}));
|
|
285
|
-
function findPattern(
|
|
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
|
|
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
|
|
308
|
-
while (1) switch (
|
|
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
|
-
|
|
355
|
+
_context7.next = 3;
|
|
312
356
|
break;
|
|
313
357
|
}
|
|
314
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
378
|
+
return _context7.abrupt("return", longestMatchedLabeledAppearance.appearance);
|
|
335
379
|
case 10:
|
|
336
380
|
if (!(defaultAppearance !== 'inline')) {
|
|
337
|
-
|
|
381
|
+
_context7.next = 12;
|
|
338
382
|
break;
|
|
339
383
|
}
|
|
340
|
-
return
|
|
384
|
+
return _context7.abrupt("return", defaultAppearance);
|
|
341
385
|
case 12:
|
|
342
386
|
case "end":
|
|
343
|
-
return
|
|
387
|
+
return _context7.stop();
|
|
344
388
|
}
|
|
345
|
-
},
|
|
389
|
+
}, _callee7, this);
|
|
346
390
|
}));
|
|
347
|
-
function findUserPreference(
|
|
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
|
|
399
|
+
var _findPatternData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(url) {
|
|
356
400
|
var _this$providersData2;
|
|
357
|
-
return _regeneratorRuntime.wrap(function
|
|
358
|
-
while (1) switch (
|
|
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
|
-
|
|
405
|
+
_context8.next = 3;
|
|
362
406
|
break;
|
|
363
407
|
}
|
|
364
|
-
|
|
408
|
+
_context8.next = 3;
|
|
365
409
|
return this.loadProviderData();
|
|
366
410
|
case 3:
|
|
367
|
-
return
|
|
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
|
|
416
|
+
return _context8.stop();
|
|
373
417
|
}
|
|
374
|
-
},
|
|
418
|
+
}, _callee8, this);
|
|
375
419
|
}));
|
|
376
|
-
function findPatternData(
|
|
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
|
|
469
|
+
var _canBeResolvedAsEmbed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(url) {
|
|
426
470
|
var details, embed;
|
|
427
|
-
return _regeneratorRuntime.wrap(function
|
|
428
|
-
while (1) switch (
|
|
471
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
472
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
429
473
|
case 0:
|
|
430
|
-
|
|
431
|
-
|
|
474
|
+
_context9.prev = 0;
|
|
475
|
+
_context9.next = 3;
|
|
432
476
|
return this.cardClient.fetchData(url);
|
|
433
477
|
case 3:
|
|
434
|
-
details =
|
|
478
|
+
details = _context9.sent;
|
|
435
479
|
if (details) {
|
|
436
|
-
|
|
480
|
+
_context9.next = 6;
|
|
437
481
|
break;
|
|
438
482
|
}
|
|
439
|
-
return
|
|
483
|
+
return _context9.abrupt("return", false);
|
|
440
484
|
case 6:
|
|
441
485
|
if (!(getStatus(details) !== 'resolved')) {
|
|
442
|
-
|
|
486
|
+
_context9.next = 8;
|
|
443
487
|
break;
|
|
444
488
|
}
|
|
445
|
-
return
|
|
489
|
+
return _context9.abrupt("return", false);
|
|
446
490
|
case 8:
|
|
447
491
|
embed = extractSmartLinkEmbed(details);
|
|
448
|
-
return
|
|
492
|
+
return _context9.abrupt("return", !!embed);
|
|
449
493
|
case 12:
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
return
|
|
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
|
|
499
|
+
return _context9.stop();
|
|
456
500
|
}
|
|
457
|
-
},
|
|
501
|
+
}, _callee9, this, [[0, 12]]);
|
|
458
502
|
}));
|
|
459
|
-
function canBeResolvedAsEmbed(
|
|
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
|
|
515
|
+
var _getDatasourceFromResolveResponse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee0(url) {
|
|
472
516
|
var response, datasources;
|
|
473
|
-
return _regeneratorRuntime.wrap(function
|
|
474
|
-
while (1) switch (
|
|
517
|
+
return _regeneratorRuntime.wrap(function _callee0$(_context0) {
|
|
518
|
+
while (1) switch (_context0.prev = _context0.next) {
|
|
475
519
|
case 0:
|
|
476
|
-
|
|
477
|
-
|
|
520
|
+
_context0.prev = 0;
|
|
521
|
+
_context0.next = 3;
|
|
478
522
|
return this.cardClient.fetchData(url);
|
|
479
523
|
case 3:
|
|
480
|
-
response =
|
|
524
|
+
response = _context0.sent;
|
|
481
525
|
datasources = response && response.datasources || [];
|
|
482
526
|
if (!(datasources.length > 0)) {
|
|
483
|
-
|
|
527
|
+
_context0.next = 7;
|
|
484
528
|
break;
|
|
485
529
|
}
|
|
486
|
-
return
|
|
530
|
+
return _context0.abrupt("return", datasources[0]);
|
|
487
531
|
case 7:
|
|
488
|
-
|
|
532
|
+
_context0.next = 12;
|
|
489
533
|
break;
|
|
490
534
|
case 9:
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
return
|
|
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
|
|
540
|
+
return _context0.stop();
|
|
497
541
|
}
|
|
498
|
-
},
|
|
542
|
+
}, _callee0, this, [[0, 9]]);
|
|
499
543
|
}));
|
|
500
|
-
function getDatasourceFromResolveResponse(
|
|
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
|
|
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
|
|
511
|
-
while (1) switch (
|
|
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
|
-
|
|
566
|
+
_context1.prev = 0;
|
|
514
567
|
if (!(shouldForceAppearance === true)) {
|
|
515
|
-
|
|
568
|
+
_context1.next = 3;
|
|
516
569
|
break;
|
|
517
570
|
}
|
|
518
|
-
return
|
|
571
|
+
return _context1.abrupt("return", this.transformer.toSmartlinkAdf(url, appearance));
|
|
519
572
|
case 3:
|
|
520
573
|
hardCodedAppearance = this.getHardCodedAppearance(url);
|
|
521
|
-
|
|
574
|
+
_context1.next = 6;
|
|
522
575
|
return Promise.all([this.findPatternData(url), this.findUserPreference(url)]);
|
|
523
576
|
case 6:
|
|
524
|
-
_yield$Promise$all =
|
|
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 (
|
|
529
|
-
|
|
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
|
-
|
|
601
|
+
_context1.next = 18;
|
|
533
602
|
break;
|
|
534
603
|
}
|
|
535
|
-
return
|
|
536
|
-
case
|
|
537
|
-
|
|
538
|
-
if (
|
|
539
|
-
|
|
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
|
-
|
|
611
|
+
_context1.next = 22;
|
|
543
612
|
return this.checkLinkResolved(url);
|
|
544
|
-
case
|
|
545
|
-
|
|
546
|
-
case
|
|
547
|
-
isSupported =
|
|
613
|
+
case 22:
|
|
614
|
+
_context1.t0 = _context1.sent;
|
|
615
|
+
case 23:
|
|
616
|
+
isSupported = _context1.t0;
|
|
548
617
|
if (!isSupported) {
|
|
549
|
-
|
|
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
|
-
|
|
636
|
+
_context1.next = 32;
|
|
568
637
|
break;
|
|
569
638
|
}
|
|
570
|
-
|
|
639
|
+
_context1.next = 30;
|
|
571
640
|
return this.canBeResolvedAsEmbed(url);
|
|
572
|
-
case
|
|
573
|
-
canItBeEmbed =
|
|
641
|
+
case 30:
|
|
642
|
+
canItBeEmbed = _context1.sent;
|
|
574
643
|
if (!canItBeEmbed) {
|
|
575
644
|
preferredAppearance = 'inline';
|
|
576
645
|
}
|
|
577
|
-
case
|
|
578
|
-
|
|
646
|
+
case 32:
|
|
647
|
+
_context1.next = 34;
|
|
579
648
|
return this.getDatasourceFromResolveResponse(url);
|
|
580
|
-
case
|
|
581
|
-
datasource =
|
|
649
|
+
case 34:
|
|
650
|
+
datasource = _context1.sent;
|
|
582
651
|
if (!datasource) {
|
|
583
|
-
|
|
652
|
+
_context1.next = 38;
|
|
584
653
|
break;
|
|
585
654
|
}
|
|
586
655
|
id = datasource.id, parameters = datasource.parameters;
|
|
587
|
-
return
|
|
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
|
|
597
|
-
return
|
|
598
|
-
case
|
|
599
|
-
|
|
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
|
|
602
|
-
|
|
603
|
-
|
|
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(
|
|
606
|
-
case
|
|
607
|
-
return
|
|
608
|
-
case
|
|
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
|
|
679
|
+
return _context1.stop();
|
|
611
680
|
}
|
|
612
|
-
},
|
|
681
|
+
}, _callee1, this, [[0, 41]]);
|
|
613
682
|
}));
|
|
614
|
-
function resolve(
|
|
683
|
+
function resolve(_x9, _x0, _x1, _x10) {
|
|
615
684
|
return _resolve.apply(this, arguments);
|
|
616
685
|
}
|
|
617
686
|
return resolve;
|
package/dist/types/provider.d.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
40
|
-
"@atlaskit/linking-common": "^9.
|
|
41
|
-
"@atlaskit/linking-types": "^
|
|
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"
|