@atlaskit/editor-card-provider 5.0.3 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/cjs/provider.js +218 -156
- package/dist/es2019/provider.js +43 -15
- package/dist/esm/provider.js +218 -156
- package/dist/types/provider.d.ts +9 -1
- package/dist/types-ts4.5/provider.d.ts +9 -1
- package/package.json +7 -4
package/dist/es2019/provider.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import {
|
|
2
|
+
import { extractSmartLinkEmbed } from '@atlaskit/link-extractors';
|
|
3
3
|
import { getStatus } from '@atlaskit/linking-common';
|
|
4
4
|
import DataLoader from 'dataloader';
|
|
5
5
|
import { Transformer } from './transformer';
|
|
@@ -51,8 +51,9 @@ const isRovoAgentProfilePage = url => {
|
|
|
51
51
|
const isCustomer360LandingPage = url => url.match(/^https:\/\/customer\.atlassian\.com\/.*$/);
|
|
52
52
|
const isConfluenceTeamCalendars = url => url.match(/\/wiki\/spaces\/(?<resourceContext>[^\/]+)\/calendars\/(?<resourceId>[a-zA-Z0-9-]+)/);
|
|
53
53
|
const isJiraIssueNavigator = url => url.match(/^https:\/\/.*?\/jira\/software|core\/(c\/)?projects\/[^\/]+?\/issues\/?/);
|
|
54
|
+
export const isJiraWorkItem = url => /\/browse\/((?:\w+)-(?:\d+))/i.test(url);
|
|
54
55
|
export class EditorCardProvider {
|
|
55
|
-
constructor(envKey, baseUrlOverride, product) {
|
|
56
|
+
constructor(envKey, baseUrlOverride, product, onResolve) {
|
|
56
57
|
_defineProperty(this, "getExperimentValue", (experimentName, parameterName, defaultValue) => {
|
|
57
58
|
try {
|
|
58
59
|
return FeatureGates.getExperimentValue(experimentName, parameterName, defaultValue);
|
|
@@ -63,6 +64,7 @@ export class EditorCardProvider {
|
|
|
63
64
|
this.baseUrl = baseUrlOverride || getBaseUrl(envKey);
|
|
64
65
|
this.resolverUrl = getResolverUrl(envKey, baseUrlOverride);
|
|
65
66
|
this.transformer = new Transformer();
|
|
67
|
+
this.onResolve = onResolve;
|
|
66
68
|
this.requestHeaders = {
|
|
67
69
|
Origin: this.baseUrl
|
|
68
70
|
};
|
|
@@ -90,6 +92,22 @@ export class EditorCardProvider {
|
|
|
90
92
|
return false;
|
|
91
93
|
}
|
|
92
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
|
+
}
|
|
93
111
|
async fetchProvidersData() {
|
|
94
112
|
const endpoint = `${this.resolverUrl}/providers`;
|
|
95
113
|
const response = await api.request('post', endpoint, undefined, this.requestHeaders);
|
|
@@ -193,19 +211,10 @@ export class EditorCardProvider {
|
|
|
193
211
|
async canBeResolvedAsEmbed(url) {
|
|
194
212
|
try {
|
|
195
213
|
const details = await this.cardClient.fetchData(url);
|
|
196
|
-
|
|
197
|
-
// Entities supported
|
|
198
|
-
if (fg('smart_links_noun_support')) {
|
|
199
|
-
if (!details) {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
const embed = extractSmartLinkEmbed(details);
|
|
203
|
-
return !!embed;
|
|
204
|
-
}
|
|
205
|
-
const data = details && details.data;
|
|
206
|
-
if (!data) {
|
|
214
|
+
if (!details) {
|
|
207
215
|
return false;
|
|
208
216
|
}
|
|
217
|
+
|
|
209
218
|
// Imagine response is "unauthorized". We won't be able to tell if even after auth
|
|
210
219
|
// page going to have preview. Yes, we can show auth view for embed. But what if even after
|
|
211
220
|
// success auth flow there won't be preview? We will already have ugly embed ADF.
|
|
@@ -213,8 +222,8 @@ export class EditorCardProvider {
|
|
|
213
222
|
if (getStatus(details) !== 'resolved') {
|
|
214
223
|
return false;
|
|
215
224
|
}
|
|
216
|
-
const
|
|
217
|
-
return !!
|
|
225
|
+
const embed = extractSmartLinkEmbed(details);
|
|
226
|
+
return !!embed;
|
|
218
227
|
} catch (e) {
|
|
219
228
|
return false;
|
|
220
229
|
}
|
|
@@ -236,6 +245,13 @@ export class EditorCardProvider {
|
|
|
236
245
|
return undefined;
|
|
237
246
|
}
|
|
238
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
|
+
}
|
|
239
255
|
async resolve(url, appearance, shouldForceAppearance, isEmbedFriendlyLocation) {
|
|
240
256
|
try {
|
|
241
257
|
if (shouldForceAppearance === true) {
|
|
@@ -246,6 +262,18 @@ export class EditorCardProvider {
|
|
|
246
262
|
}
|
|
247
263
|
const hardCodedAppearance = this.getHardCodedAppearance(url);
|
|
248
264
|
const [matchedProviderPattern, userPreference] = await Promise.all([this.findPatternData(url), this.findUserPreference(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
|
+
}
|
|
276
|
+
}
|
|
249
277
|
if (shouldForceAppearance === false && userPreference === 'url') {
|
|
250
278
|
return Promise.reject(undefined);
|
|
251
279
|
}
|