@atlaskit/editor-card-provider 1.0.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 +11 -0
- package/LICENSE.md +13 -0
- package/README.md +16 -0
- package/dist/cjs/api.js +89 -0
- package/dist/cjs/environments.js +46 -0
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/provider.js +480 -0
- package/dist/cjs/transformer.js +60 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/utils.js +24 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/api.js +37 -0
- package/dist/es2019/environments.js +36 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/provider.js +182 -0
- package/dist/es2019/transformer.js +37 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/utils.js +20 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/api.js +82 -0
- package/dist/esm/environments.js +36 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/provider.js +467 -0
- package/dist/esm/transformer.js +52 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils.js +17 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/api.d.ts +5 -0
- package/dist/types/environments.d.ts +13 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/provider.d.ts +32 -0
- package/dist/types/transformer.d.ts +7 -0
- package/dist/types/types.d.ts +34 -0
- package/dist/types/utils.d.ts +3 -0
- package/package.json +44 -0
- package/report.api.md +77 -0
- package/tmp/api-report-tmp.d.ts +44 -0
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
|
+
// import setimmediate to temporary fix dataloader 2.0.0 bug
|
|
7
|
+
// @see https://github.com/graphql/dataloader/issues/249
|
|
8
|
+
import 'setimmediate';
|
|
9
|
+
import DataLoader from 'dataloader';
|
|
10
|
+
import { extractPreview } from '@atlaskit/linking-common';
|
|
11
|
+
import { Transformer } from './transformer';
|
|
12
|
+
import { getBaseUrl, getResolverUrl } from './environments';
|
|
13
|
+
import { getStatus } from './utils';
|
|
14
|
+
import { CardClient } from '@atlaskit/link-provider';
|
|
15
|
+
import * as api from './api';
|
|
16
|
+
var BATCH_WAIT_TIME = 50;
|
|
17
|
+
var isJiraRoadMap = function isJiraRoadMap(url) {
|
|
18
|
+
return url.match(/^https:\/\/.*?\/jira\/software\/(c\/)?projects\/[^\/]+?\/boards\/.*?\/roadmap\/?/);
|
|
19
|
+
};
|
|
20
|
+
var isPolarisView = function isPolarisView(url) {
|
|
21
|
+
return url.match(/^https:\/\/.*?\/jira\/polaris\/projects\/[^\/]+?\/ideas\/view\/\d+$|^https:\/\/.*?\/secure\/JiraProductDiscoveryAnonymous\.jspa\?hash=\w+|^https:\/\/.*?\/jira\/polaris\/share\/\w+/);
|
|
22
|
+
};
|
|
23
|
+
var isJwmView = function isJwmView(url) {
|
|
24
|
+
return url.match(/^https:\/\/.*?\/jira\/core\/projects\/[^\/]+?\/(timeline|calendar|list|board|summary|(form\/[^\/]+?))\/?/);
|
|
25
|
+
};
|
|
26
|
+
var isGiphyMedia = function isGiphyMedia(url) {
|
|
27
|
+
return url.match(/^https:\/\/(.*?\.)?giphy\.com\/(gifs|media|clips)\//);
|
|
28
|
+
};
|
|
29
|
+
var isProformaView = function isProformaView(url) {
|
|
30
|
+
return url.match(/^https:\/\/[^/]+\/jira\/(core|software(\/c)?|servicedesk)\/projects\/\w+\/forms\/form\/direct\/\d+\/\d+.*$/);
|
|
31
|
+
};
|
|
32
|
+
export var EditorCardProvider = /*#__PURE__*/function () {
|
|
33
|
+
function EditorCardProvider(envKey, baseUrlOverride) {
|
|
34
|
+
var _this = this;
|
|
35
|
+
_classCallCheck(this, EditorCardProvider);
|
|
36
|
+
this.baseUrl = baseUrlOverride || getBaseUrl(envKey);
|
|
37
|
+
this.resolverUrl = getResolverUrl(envKey, baseUrlOverride);
|
|
38
|
+
this.transformer = new Transformer();
|
|
39
|
+
this.requestHeaders = {
|
|
40
|
+
Origin: this.baseUrl
|
|
41
|
+
};
|
|
42
|
+
this.providersLoader = new DataLoader(function (keys) {
|
|
43
|
+
return _this.batchProviders(keys);
|
|
44
|
+
}, {
|
|
45
|
+
batchScheduleFn: function batchScheduleFn(callback) {
|
|
46
|
+
return setTimeout(callback, BATCH_WAIT_TIME);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
this.cardClient = new CardClient(envKey, baseUrlOverride);
|
|
50
|
+
}
|
|
51
|
+
_createClass(EditorCardProvider, [{
|
|
52
|
+
key: "batchProviders",
|
|
53
|
+
value: function () {
|
|
54
|
+
var _batchProviders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(keys) {
|
|
55
|
+
var providersData;
|
|
56
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
57
|
+
while (1) {
|
|
58
|
+
switch (_context.prev = _context.next) {
|
|
59
|
+
case 0:
|
|
60
|
+
_context.next = 2;
|
|
61
|
+
return this.fetchProvidersData();
|
|
62
|
+
case 2:
|
|
63
|
+
providersData = _context.sent;
|
|
64
|
+
return _context.abrupt("return", keys.map(function () {
|
|
65
|
+
return providersData;
|
|
66
|
+
}));
|
|
67
|
+
case 4:
|
|
68
|
+
case "end":
|
|
69
|
+
return _context.stop();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, _callee, this);
|
|
73
|
+
}));
|
|
74
|
+
function batchProviders(_x) {
|
|
75
|
+
return _batchProviders.apply(this, arguments);
|
|
76
|
+
}
|
|
77
|
+
return batchProviders;
|
|
78
|
+
}()
|
|
79
|
+
}, {
|
|
80
|
+
key: "check",
|
|
81
|
+
value: function () {
|
|
82
|
+
var _check = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceUrl) {
|
|
83
|
+
var response;
|
|
84
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
85
|
+
while (1) {
|
|
86
|
+
switch (_context2.prev = _context2.next) {
|
|
87
|
+
case 0:
|
|
88
|
+
_context2.prev = 0;
|
|
89
|
+
_context2.next = 3;
|
|
90
|
+
return this.cardClient.fetchData(resourceUrl);
|
|
91
|
+
case 3:
|
|
92
|
+
response = _context2.sent;
|
|
93
|
+
if (!(getStatus(response) !== 'not_found')) {
|
|
94
|
+
_context2.next = 6;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
return _context2.abrupt("return", true);
|
|
98
|
+
case 6:
|
|
99
|
+
_context2.next = 11;
|
|
100
|
+
break;
|
|
101
|
+
case 8:
|
|
102
|
+
_context2.prev = 8;
|
|
103
|
+
_context2.t0 = _context2["catch"](0);
|
|
104
|
+
return _context2.abrupt("return", false);
|
|
105
|
+
case 11:
|
|
106
|
+
case "end":
|
|
107
|
+
return _context2.stop();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}, _callee2, this, [[0, 8]]);
|
|
111
|
+
}));
|
|
112
|
+
function check(_x2) {
|
|
113
|
+
return _check.apply(this, arguments);
|
|
114
|
+
}
|
|
115
|
+
return check;
|
|
116
|
+
}()
|
|
117
|
+
}, {
|
|
118
|
+
key: "fetchProvidersData",
|
|
119
|
+
value: function () {
|
|
120
|
+
var _fetchProvidersData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
121
|
+
var endpoint, response;
|
|
122
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
123
|
+
while (1) {
|
|
124
|
+
switch (_context3.prev = _context3.next) {
|
|
125
|
+
case 0:
|
|
126
|
+
endpoint = "".concat(this.resolverUrl, "/providers");
|
|
127
|
+
_context3.next = 3;
|
|
128
|
+
return api.request('post', endpoint, undefined, this.requestHeaders);
|
|
129
|
+
case 3:
|
|
130
|
+
response = _context3.sent;
|
|
131
|
+
return _context3.abrupt("return", {
|
|
132
|
+
patterns: response.providers.reduce(function (allSources, provider) {
|
|
133
|
+
return allSources.concat(provider.patterns);
|
|
134
|
+
}, []),
|
|
135
|
+
userPreferences: response.userPreferences
|
|
136
|
+
});
|
|
137
|
+
case 5:
|
|
138
|
+
case "end":
|
|
139
|
+
return _context3.stop();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}, _callee3, this);
|
|
143
|
+
}));
|
|
144
|
+
function fetchProvidersData() {
|
|
145
|
+
return _fetchProvidersData.apply(this, arguments);
|
|
146
|
+
}
|
|
147
|
+
return fetchProvidersData;
|
|
148
|
+
}()
|
|
149
|
+
}, {
|
|
150
|
+
key: "loadProviderData",
|
|
151
|
+
value: function () {
|
|
152
|
+
var _loadProviderData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
153
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
154
|
+
while (1) {
|
|
155
|
+
switch (_context4.prev = _context4.next) {
|
|
156
|
+
case 0:
|
|
157
|
+
_context4.prev = 0;
|
|
158
|
+
_context4.next = 3;
|
|
159
|
+
return this.providersLoader.load('providersData');
|
|
160
|
+
case 3:
|
|
161
|
+
this.providersData = _context4.sent;
|
|
162
|
+
_context4.next = 11;
|
|
163
|
+
break;
|
|
164
|
+
case 6:
|
|
165
|
+
_context4.prev = 6;
|
|
166
|
+
_context4.t0 = _context4["catch"](0);
|
|
167
|
+
// eslint-disable-next-line
|
|
168
|
+
console.error('failed to fetch /providers', _context4.t0);
|
|
169
|
+
this.providersLoader.clear('providerData');
|
|
170
|
+
return _context4.abrupt("return", undefined);
|
|
171
|
+
case 11:
|
|
172
|
+
case "end":
|
|
173
|
+
return _context4.stop();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}, _callee4, this, [[0, 6]]);
|
|
177
|
+
}));
|
|
178
|
+
function loadProviderData() {
|
|
179
|
+
return _loadProviderData.apply(this, arguments);
|
|
180
|
+
}
|
|
181
|
+
return loadProviderData;
|
|
182
|
+
}()
|
|
183
|
+
}, {
|
|
184
|
+
key: "findPattern",
|
|
185
|
+
value: function () {
|
|
186
|
+
var _findPattern = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(url) {
|
|
187
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
188
|
+
while (1) {
|
|
189
|
+
switch (_context5.prev = _context5.next) {
|
|
190
|
+
case 0:
|
|
191
|
+
_context5.next = 2;
|
|
192
|
+
return this.findPatternData(url);
|
|
193
|
+
case 2:
|
|
194
|
+
_context5.t0 = !!_context5.sent;
|
|
195
|
+
if (_context5.t0) {
|
|
196
|
+
_context5.next = 7;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
_context5.next = 6;
|
|
200
|
+
return this.check(url);
|
|
201
|
+
case 6:
|
|
202
|
+
_context5.t0 = !!_context5.sent;
|
|
203
|
+
case 7:
|
|
204
|
+
return _context5.abrupt("return", _context5.t0);
|
|
205
|
+
case 8:
|
|
206
|
+
case "end":
|
|
207
|
+
return _context5.stop();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}, _callee5, this);
|
|
211
|
+
}));
|
|
212
|
+
function findPattern(_x3) {
|
|
213
|
+
return _findPattern.apply(this, arguments);
|
|
214
|
+
}
|
|
215
|
+
return findPattern;
|
|
216
|
+
}()
|
|
217
|
+
}, {
|
|
218
|
+
key: "doesUrlMatchPath",
|
|
219
|
+
value: function doesUrlMatchPath(path, url) {
|
|
220
|
+
// Using [a-zA-Z0-9] here instead of \w since that includes underscores
|
|
221
|
+
var startingRegex = new RegExp(/^[a-zA-Z0-9]/).test(path) ? '(^|[^a-zA-Z0-9])' : '';
|
|
222
|
+
var endingRegex = new RegExp(/[a-zA-Z0-9]$/).test(path) ? '($|[^a-zA-Z0-9])' : '';
|
|
223
|
+
var escapedPath = path.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
224
|
+
var regexPattern = new RegExp("".concat(startingRegex).concat(escapedPath).concat(endingRegex));
|
|
225
|
+
return regexPattern.test(url);
|
|
226
|
+
}
|
|
227
|
+
}, {
|
|
228
|
+
key: "findUserPreference",
|
|
229
|
+
value: function () {
|
|
230
|
+
var _findUserPreference = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(url) {
|
|
231
|
+
var _this$providersData,
|
|
232
|
+
_this2 = this;
|
|
233
|
+
var userPreferences, defaultAppearance, appearances, allMatchedLabeledAppearances, longestMatchedLabeledAppearance;
|
|
234
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
235
|
+
while (1) {
|
|
236
|
+
switch (_context6.prev = _context6.next) {
|
|
237
|
+
case 0:
|
|
238
|
+
if (this.providersData) {
|
|
239
|
+
_context6.next = 3;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
_context6.next = 3;
|
|
243
|
+
return this.loadProviderData();
|
|
244
|
+
case 3:
|
|
245
|
+
userPreferences = (_this$providersData = this.providersData) === null || _this$providersData === void 0 ? void 0 : _this$providersData.userPreferences;
|
|
246
|
+
if (!userPreferences) {
|
|
247
|
+
_context6.next = 12;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
defaultAppearance = userPreferences.defaultAppearance, appearances = userPreferences.appearances;
|
|
251
|
+
allMatchedLabeledAppearances = appearances.filter(function (_ref) {
|
|
252
|
+
var urlSegment = _ref.urlSegment;
|
|
253
|
+
return _this2.doesUrlMatchPath(urlSegment, url);
|
|
254
|
+
});
|
|
255
|
+
if (!(allMatchedLabeledAppearances.length > 0)) {
|
|
256
|
+
_context6.next = 10;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
longestMatchedLabeledAppearance = allMatchedLabeledAppearances.reduce(function (previousLabeledAppearance, currentLabeledAppearance) {
|
|
260
|
+
return previousLabeledAppearance.urlSegment.length > currentLabeledAppearance.urlSegment.length ? previousLabeledAppearance : currentLabeledAppearance;
|
|
261
|
+
});
|
|
262
|
+
return _context6.abrupt("return", longestMatchedLabeledAppearance.appearance);
|
|
263
|
+
case 10:
|
|
264
|
+
if (!(defaultAppearance !== 'inline')) {
|
|
265
|
+
_context6.next = 12;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
return _context6.abrupt("return", defaultAppearance);
|
|
269
|
+
case 12:
|
|
270
|
+
case "end":
|
|
271
|
+
return _context6.stop();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}, _callee6, this);
|
|
275
|
+
}));
|
|
276
|
+
function findUserPreference(_x4) {
|
|
277
|
+
return _findUserPreference.apply(this, arguments);
|
|
278
|
+
}
|
|
279
|
+
return findUserPreference;
|
|
280
|
+
}()
|
|
281
|
+
}, {
|
|
282
|
+
key: "findPatternData",
|
|
283
|
+
value: function () {
|
|
284
|
+
var _findPatternData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(url) {
|
|
285
|
+
var _this$providersData2;
|
|
286
|
+
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
287
|
+
while (1) {
|
|
288
|
+
switch (_context7.prev = _context7.next) {
|
|
289
|
+
case 0:
|
|
290
|
+
if (this.providersData) {
|
|
291
|
+
_context7.next = 3;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
_context7.next = 3;
|
|
295
|
+
return this.loadProviderData();
|
|
296
|
+
case 3:
|
|
297
|
+
return _context7.abrupt("return", (_this$providersData2 = this.providersData) === null || _this$providersData2 === void 0 ? void 0 : _this$providersData2.patterns.find(function (pattern) {
|
|
298
|
+
return url.match(pattern.source);
|
|
299
|
+
}));
|
|
300
|
+
case 4:
|
|
301
|
+
case "end":
|
|
302
|
+
return _context7.stop();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}, _callee7, this);
|
|
306
|
+
}));
|
|
307
|
+
function findPatternData(_x5) {
|
|
308
|
+
return _findPatternData.apply(this, arguments);
|
|
309
|
+
}
|
|
310
|
+
return findPatternData;
|
|
311
|
+
}()
|
|
312
|
+
}, {
|
|
313
|
+
key: "getHardCodedAppearance",
|
|
314
|
+
value: function getHardCodedAppearance(url) {
|
|
315
|
+
if (isJiraRoadMap(url) || isPolarisView(url) || isJwmView(url) || isGiphyMedia(url) || isProformaView(url)) {
|
|
316
|
+
return 'embed';
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Make a /resolve call and find out if result has embed capability
|
|
322
|
+
* @param url
|
|
323
|
+
* @private
|
|
324
|
+
*/
|
|
325
|
+
}, {
|
|
326
|
+
key: "canBeResolvedAsEmbed",
|
|
327
|
+
value: function () {
|
|
328
|
+
var _canBeResolvedAsEmbed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(url) {
|
|
329
|
+
var details, data, preview;
|
|
330
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
331
|
+
while (1) {
|
|
332
|
+
switch (_context8.prev = _context8.next) {
|
|
333
|
+
case 0:
|
|
334
|
+
_context8.prev = 0;
|
|
335
|
+
_context8.next = 3;
|
|
336
|
+
return this.cardClient.fetchData(url);
|
|
337
|
+
case 3:
|
|
338
|
+
details = _context8.sent;
|
|
339
|
+
data = details && details.data;
|
|
340
|
+
if (data) {
|
|
341
|
+
_context8.next = 7;
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
return _context8.abrupt("return", false);
|
|
345
|
+
case 7:
|
|
346
|
+
if (!(getStatus(details) !== 'resolved')) {
|
|
347
|
+
_context8.next = 9;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
return _context8.abrupt("return", false);
|
|
351
|
+
case 9:
|
|
352
|
+
preview = extractPreview(data, 'web');
|
|
353
|
+
return _context8.abrupt("return", !!preview);
|
|
354
|
+
case 13:
|
|
355
|
+
_context8.prev = 13;
|
|
356
|
+
_context8.t0 = _context8["catch"](0);
|
|
357
|
+
return _context8.abrupt("return", false);
|
|
358
|
+
case 16:
|
|
359
|
+
case "end":
|
|
360
|
+
return _context8.stop();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}, _callee8, this, [[0, 13]]);
|
|
364
|
+
}));
|
|
365
|
+
function canBeResolvedAsEmbed(_x6) {
|
|
366
|
+
return _canBeResolvedAsEmbed.apply(this, arguments);
|
|
367
|
+
}
|
|
368
|
+
return canBeResolvedAsEmbed;
|
|
369
|
+
}()
|
|
370
|
+
}, {
|
|
371
|
+
key: "resolve",
|
|
372
|
+
value: function () {
|
|
373
|
+
var _resolve = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(url, appearance, shouldForceAppearance) {
|
|
374
|
+
var hardCodedAppearance, _yield$Promise$all, _yield$Promise$all2, matchedProviderPattern, userPreference, isSupported, providerDefaultAppearance, preferredAppearance, canItBeEmbed;
|
|
375
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
376
|
+
while (1) {
|
|
377
|
+
switch (_context9.prev = _context9.next) {
|
|
378
|
+
case 0:
|
|
379
|
+
_context9.prev = 0;
|
|
380
|
+
if (!(shouldForceAppearance === true)) {
|
|
381
|
+
_context9.next = 3;
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
return _context9.abrupt("return", this.transformer.toAdf(url, appearance));
|
|
385
|
+
case 3:
|
|
386
|
+
hardCodedAppearance = this.getHardCodedAppearance(url);
|
|
387
|
+
_context9.next = 6;
|
|
388
|
+
return Promise.all([this.findPatternData(url), this.findUserPreference(url)]);
|
|
389
|
+
case 6:
|
|
390
|
+
_yield$Promise$all = _context9.sent;
|
|
391
|
+
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
392
|
+
matchedProviderPattern = _yield$Promise$all2[0];
|
|
393
|
+
userPreference = _yield$Promise$all2[1];
|
|
394
|
+
if (!(shouldForceAppearance === false && userPreference === 'url')) {
|
|
395
|
+
_context9.next = 12;
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
return _context9.abrupt("return", Promise.reject(undefined));
|
|
399
|
+
case 12:
|
|
400
|
+
_context9.t0 = !!matchedProviderPattern;
|
|
401
|
+
if (_context9.t0) {
|
|
402
|
+
_context9.next = 17;
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
_context9.next = 16;
|
|
406
|
+
return this.check(url);
|
|
407
|
+
case 16:
|
|
408
|
+
_context9.t0 = _context9.sent;
|
|
409
|
+
case 17:
|
|
410
|
+
isSupported = _context9.t0;
|
|
411
|
+
if (!isSupported) {
|
|
412
|
+
_context9.next = 27;
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
providerDefaultAppearance = matchedProviderPattern === null || matchedProviderPattern === void 0 ? void 0 : matchedProviderPattern.defaultView;
|
|
416
|
+
preferredAppearance = shouldForceAppearance === undefined ?
|
|
417
|
+
// Ignore both User and provider's appearances if older editor that doesn't send shouldForceAppearance
|
|
418
|
+
hardCodedAppearance || appearance :
|
|
419
|
+
// User preferred appearance. It would be either one that has matching domain/path pattern OR
|
|
420
|
+
// if user's default choice is NOT "inline" (so, block or embed at this point, url was dealt with above)
|
|
421
|
+
userPreference ||
|
|
422
|
+
// If user's default choice is "inline" or user hasn't specified preferences at all,
|
|
423
|
+
// we check whatever one of the hardcoded providers match url (jira roadmap, polaris, etc)
|
|
424
|
+
hardCodedAppearance ||
|
|
425
|
+
// If non match, we see if this provider has default appearance for this particular regexp
|
|
426
|
+
providerDefaultAppearance ||
|
|
427
|
+
// If not, we pick what editor (or any other client) requested
|
|
428
|
+
appearance;
|
|
429
|
+
if (!(preferredAppearance === userPreference && userPreference === 'embed')) {
|
|
430
|
+
_context9.next = 26;
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
_context9.next = 24;
|
|
434
|
+
return this.canBeResolvedAsEmbed(url);
|
|
435
|
+
case 24:
|
|
436
|
+
canItBeEmbed = _context9.sent;
|
|
437
|
+
if (!canItBeEmbed) {
|
|
438
|
+
preferredAppearance = 'inline';
|
|
439
|
+
}
|
|
440
|
+
case 26:
|
|
441
|
+
return _context9.abrupt("return", this.transformer.toAdf(url, preferredAppearance));
|
|
442
|
+
case 27:
|
|
443
|
+
_context9.next = 32;
|
|
444
|
+
break;
|
|
445
|
+
case 29:
|
|
446
|
+
_context9.prev = 29;
|
|
447
|
+
_context9.t1 = _context9["catch"](0);
|
|
448
|
+
// eslint-disable-next-line
|
|
449
|
+
console.warn("Error when trying to check Smart Card url \"".concat(url, "\"").concat(_context9.t1 instanceof Error ? " - ".concat(_context9.t1.name, " ").concat(_context9.t1.message) : ''), _context9.t1);
|
|
450
|
+
case 32:
|
|
451
|
+
return _context9.abrupt("return", Promise.reject(undefined));
|
|
452
|
+
case 33:
|
|
453
|
+
case "end":
|
|
454
|
+
return _context9.stop();
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}, _callee9, this, [[0, 29]]);
|
|
458
|
+
}));
|
|
459
|
+
function resolve(_x7, _x8, _x9) {
|
|
460
|
+
return _resolve.apply(this, arguments);
|
|
461
|
+
}
|
|
462
|
+
return resolve;
|
|
463
|
+
}()
|
|
464
|
+
}]);
|
|
465
|
+
return EditorCardProvider;
|
|
466
|
+
}();
|
|
467
|
+
export var editorCardProvider = new EditorCardProvider();
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
export var Transformer = /*#__PURE__*/function () {
|
|
4
|
+
function Transformer() {
|
|
5
|
+
_classCallCheck(this, Transformer);
|
|
6
|
+
}
|
|
7
|
+
_createClass(Transformer, [{
|
|
8
|
+
key: "buildInlineAdf",
|
|
9
|
+
value: function buildInlineAdf(url) {
|
|
10
|
+
return {
|
|
11
|
+
type: 'inlineCard',
|
|
12
|
+
attrs: {
|
|
13
|
+
url: url
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}, {
|
|
18
|
+
key: "buildBlockAdf",
|
|
19
|
+
value: function buildBlockAdf(url) {
|
|
20
|
+
return {
|
|
21
|
+
type: 'blockCard',
|
|
22
|
+
attrs: {
|
|
23
|
+
url: url
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}, {
|
|
28
|
+
key: "buildEmbedAdf",
|
|
29
|
+
value: function buildEmbedAdf(url) {
|
|
30
|
+
return {
|
|
31
|
+
type: 'embedCard',
|
|
32
|
+
attrs: {
|
|
33
|
+
url: url,
|
|
34
|
+
layout: 'wide'
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
key: "toAdf",
|
|
40
|
+
value: function toAdf(url, appearance) {
|
|
41
|
+
switch (appearance) {
|
|
42
|
+
case 'inline':
|
|
43
|
+
return this.buildInlineAdf(url);
|
|
44
|
+
case 'block':
|
|
45
|
+
return this.buildBlockAdf(url);
|
|
46
|
+
case 'embed':
|
|
47
|
+
return this.buildEmbedAdf(url);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}]);
|
|
51
|
+
return Transformer;
|
|
52
|
+
}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export var getStatus = function getStatus(_ref) {
|
|
2
|
+
var meta = _ref.meta;
|
|
3
|
+
var access = meta.access,
|
|
4
|
+
visibility = meta.visibility;
|
|
5
|
+
switch (access) {
|
|
6
|
+
case 'forbidden':
|
|
7
|
+
if (visibility === 'not_found') {
|
|
8
|
+
return 'not_found';
|
|
9
|
+
} else {
|
|
10
|
+
return 'forbidden';
|
|
11
|
+
}
|
|
12
|
+
case 'unauthorized':
|
|
13
|
+
return 'unauthorized';
|
|
14
|
+
default:
|
|
15
|
+
return 'resolved';
|
|
16
|
+
}
|
|
17
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare type EnvironmentsKeys = keyof typeof BaseUrls;
|
|
2
|
+
export declare const BaseUrls: {
|
|
3
|
+
dev: string;
|
|
4
|
+
development: string;
|
|
5
|
+
stg: string;
|
|
6
|
+
staging: string;
|
|
7
|
+
prd: string;
|
|
8
|
+
prod: string;
|
|
9
|
+
production: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const getBaseUrl: (envKey?: "dev" | "development" | "stg" | "staging" | "prd" | "prod" | "production" | undefined) => string;
|
|
12
|
+
export declare const getResolverUrl: (envKey?: "dev" | "development" | "stg" | "staging" | "prd" | "prod" | "production" | undefined, baseUrlOverride?: string | undefined) => string;
|
|
13
|
+
export default BaseUrls;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EditorCardProvider, editorCardProvider } from './provider';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import 'setimmediate';
|
|
2
|
+
import { CardAdf, CardAppearance } from '@atlaskit/linking-common';
|
|
3
|
+
import { CardProvider } from './types';
|
|
4
|
+
import { EnvironmentsKeys } from './environments';
|
|
5
|
+
export declare class EditorCardProvider implements CardProvider {
|
|
6
|
+
private baseUrl;
|
|
7
|
+
private resolverUrl;
|
|
8
|
+
private providersData?;
|
|
9
|
+
private requestHeaders;
|
|
10
|
+
private transformer;
|
|
11
|
+
private providersLoader;
|
|
12
|
+
private cardClient;
|
|
13
|
+
constructor(envKey?: EnvironmentsKeys, baseUrlOverride?: string);
|
|
14
|
+
private batchProviders;
|
|
15
|
+
private check;
|
|
16
|
+
private fetchProvidersData;
|
|
17
|
+
private loadProviderData;
|
|
18
|
+
findPattern(url: string): Promise<boolean>;
|
|
19
|
+
private doesUrlMatchPath;
|
|
20
|
+
private findUserPreference;
|
|
21
|
+
private findPatternData;
|
|
22
|
+
private getHardCodedAppearance;
|
|
23
|
+
/**
|
|
24
|
+
* Make a /resolve call and find out if result has embed capability
|
|
25
|
+
* @param url
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
private canBeResolvedAsEmbed;
|
|
29
|
+
resolve(url: string, appearance: CardAppearance, shouldForceAppearance?: boolean): Promise<CardAdf>;
|
|
30
|
+
}
|
|
31
|
+
export declare const editorCardProvider: EditorCardProvider;
|
|
32
|
+
export type { CardProvider } from './types';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CardAppearance } from '@atlaskit/linking-common';
|
|
2
|
+
export interface CardProvider {
|
|
3
|
+
resolve(url: string, appearance: CardAppearance, shouldForceAppearance?: boolean): Promise<any>;
|
|
4
|
+
}
|
|
5
|
+
export declare type ORSCheckResponse = {
|
|
6
|
+
isSupported: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare type DisplayViews = 'inline' | 'block' | 'embed';
|
|
9
|
+
export declare type ProviderPattern = {
|
|
10
|
+
source: string;
|
|
11
|
+
supportedViews?: DisplayViews[];
|
|
12
|
+
defaultView?: DisplayViews;
|
|
13
|
+
};
|
|
14
|
+
declare type Provider = {
|
|
15
|
+
key: string;
|
|
16
|
+
patterns: ProviderPattern[];
|
|
17
|
+
};
|
|
18
|
+
export declare type LinkAppearance = CardAppearance | 'url';
|
|
19
|
+
export interface UserPreferences {
|
|
20
|
+
defaultAppearance: LinkAppearance;
|
|
21
|
+
appearances: {
|
|
22
|
+
urlSegment: string;
|
|
23
|
+
appearance: LinkAppearance;
|
|
24
|
+
}[];
|
|
25
|
+
}
|
|
26
|
+
export declare type ORSProvidersResponse = {
|
|
27
|
+
providers: Provider[];
|
|
28
|
+
userPreferences?: UserPreferences;
|
|
29
|
+
};
|
|
30
|
+
export interface ProvidersData {
|
|
31
|
+
patterns: ProviderPattern[];
|
|
32
|
+
userPreferences?: UserPreferences;
|
|
33
|
+
}
|
|
34
|
+
export {};
|