@atlaskit/editor-synced-block-provider 3.5.4 → 3.6.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 +20 -0
- package/dist/cjs/clients/confluence/fetchMediaToken.js +109 -0
- package/dist/cjs/clients/confluence/sourceInfo.js +77 -3
- package/dist/cjs/common/consts.js +7 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +10 -2
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +218 -48
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +117 -34
- package/dist/cjs/utils/parseResourceId.js +38 -0
- package/dist/es2019/clients/confluence/fetchMediaToken.js +68 -0
- package/dist/es2019/clients/confluence/sourceInfo.js +34 -1
- package/dist/es2019/common/consts.js +1 -0
- package/dist/es2019/hooks/useFetchSyncBlockData.js +10 -1
- package/dist/es2019/index.js +2 -0
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +200 -24
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +85 -15
- package/dist/es2019/utils/parseResourceId.js +25 -0
- package/dist/esm/clients/confluence/fetchMediaToken.js +102 -0
- package/dist/esm/clients/confluence/sourceInfo.js +76 -2
- package/dist/esm/common/consts.js +1 -0
- package/dist/esm/hooks/useFetchSyncBlockData.js +10 -2
- package/dist/esm/index.js +2 -0
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +218 -48
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +117 -34
- package/dist/esm/utils/parseResourceId.js +31 -0
- package/dist/types/clients/confluence/fetchMediaToken.d.ts +11 -0
- package/dist/types/clients/confluence/sourceInfo.d.ts +2 -0
- package/dist/types/common/consts.d.ts +1 -0
- package/dist/types/common/types.d.ts +2 -1
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +6 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/providers/types.d.ts +3 -2
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +8 -0
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +4 -0
- package/dist/types/utils/parseResourceId.d.ts +6 -0
- package/dist/types-ts4.5/clients/confluence/fetchMediaToken.d.ts +11 -0
- package/dist/types-ts4.5/clients/confluence/sourceInfo.d.ts +2 -0
- package/dist/types-ts4.5/common/consts.d.ts +4 -0
- package/dist/types-ts4.5/common/types.d.ts +2 -1
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +6 -1
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/providers/types.d.ts +3 -2
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +8 -0
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +4 -0
- package/dist/types-ts4.5/utils/parseResourceId.d.ts +6 -0
- package/package.json +2 -2
|
@@ -45,6 +45,16 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
45
45
|
value: function setCreateExperience(createExperience) {
|
|
46
46
|
this.createExperience = createExperience;
|
|
47
47
|
}
|
|
48
|
+
}, {
|
|
49
|
+
key: "setSaveExperience",
|
|
50
|
+
value: function setSaveExperience(saveExperience) {
|
|
51
|
+
this.saveExperience = saveExperience;
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
key: "setDeleteExperience",
|
|
55
|
+
value: function setDeleteExperience(deleteExperience) {
|
|
56
|
+
this.deleteExperience = deleteExperience;
|
|
57
|
+
}
|
|
48
58
|
}, {
|
|
49
59
|
key: "isSourceBlock",
|
|
50
60
|
value: function isSourceBlock(node) {
|
|
@@ -93,17 +103,11 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
93
103
|
value: (function () {
|
|
94
104
|
var _flush = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
95
105
|
var _this2 = this;
|
|
96
|
-
var bodiedSyncBlockNodes, bodiedSyncBlockData, writeResults, _this$fireAnalyticsEv2;
|
|
106
|
+
var bodiedSyncBlockNodes, bodiedSyncBlockData, _this$saveExperience, writeResults, successfulSaved, failedSave, _this$saveExperience2, _this$saveExperience3, _this$saveExperience4, _this$fireAnalyticsEv2;
|
|
97
107
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
98
108
|
while (1) switch (_context.prev = _context.next) {
|
|
99
109
|
case 0:
|
|
100
110
|
_context.prev = 0;
|
|
101
|
-
if (this.dataProvider) {
|
|
102
|
-
_context.next = 3;
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
throw new Error('Data provider not set');
|
|
106
|
-
case 3:
|
|
107
111
|
bodiedSyncBlockNodes = [];
|
|
108
112
|
bodiedSyncBlockData = [];
|
|
109
113
|
Array.from(this.syncBlockCache.values()).forEach(function (syncBlockData) {
|
|
@@ -128,14 +132,25 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
128
132
|
}
|
|
129
133
|
});
|
|
130
134
|
if (!(bodiedSyncBlockNodes.length === 0)) {
|
|
131
|
-
_context.next =
|
|
135
|
+
_context.next = 6;
|
|
132
136
|
break;
|
|
133
137
|
}
|
|
134
138
|
return _context.abrupt("return", Promise.resolve(true));
|
|
135
|
-
case
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
case 6:
|
|
140
|
+
// only start the save experience if we have sync blocks to save
|
|
141
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
|
|
142
|
+
(_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 || _this$saveExperience.start({});
|
|
143
|
+
}
|
|
144
|
+
;
|
|
145
|
+
if (this.dataProvider) {
|
|
146
|
+
_context.next = 10;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
throw new Error('Data provider not set');
|
|
138
150
|
case 10:
|
|
151
|
+
_context.next = 12;
|
|
152
|
+
return this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
|
|
153
|
+
case 12:
|
|
139
154
|
writeResults = _context.sent;
|
|
140
155
|
writeResults.forEach(function (result) {
|
|
141
156
|
// set isDirty to true for cases where it failed to save the sync block to the BE
|
|
@@ -146,37 +161,75 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
146
161
|
}
|
|
147
162
|
}
|
|
148
163
|
});
|
|
164
|
+
successfulSaved = writeResults.filter(function (result) {
|
|
165
|
+
return result.resourceId && !result.error;
|
|
166
|
+
}).map(function (result) {
|
|
167
|
+
return {
|
|
168
|
+
resourceId: result.resourceId
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
failedSave = writeResults.filter(function (result) {
|
|
172
|
+
return !result.resourceId || result.error;
|
|
173
|
+
}).map(function (result) {
|
|
174
|
+
return {
|
|
175
|
+
resourceId: result.resourceId || 'unknown',
|
|
176
|
+
failReason: result.error || 'Failed to save sync blocks'
|
|
177
|
+
};
|
|
178
|
+
});
|
|
149
179
|
if (!writeResults.every(function (result) {
|
|
150
180
|
return result.resourceId && !result.error;
|
|
151
181
|
})) {
|
|
152
|
-
_context.next =
|
|
182
|
+
_context.next = 22;
|
|
153
183
|
break;
|
|
154
184
|
}
|
|
185
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
|
|
186
|
+
(_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 || _this$saveExperience2.success({
|
|
187
|
+
metadata: {
|
|
188
|
+
successfulSaved: successfulSaved
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
;
|
|
155
193
|
return _context.abrupt("return", true);
|
|
156
|
-
case
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
194
|
+
case 22:
|
|
195
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
|
|
196
|
+
(_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 || _this$saveExperience3.failure({
|
|
197
|
+
metadata: {
|
|
198
|
+
successfulSaved: successfulSaved,
|
|
199
|
+
failedSave: failedSave
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
} else {
|
|
203
|
+
writeResults.filter(function (result) {
|
|
204
|
+
return !result.resourceId || result.error;
|
|
205
|
+
}).forEach(function (result) {
|
|
206
|
+
var _this2$fireAnalyticsE;
|
|
207
|
+
(_this2$fireAnalyticsE = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE === void 0 || _this2$fireAnalyticsE.call(_this2, (0, _errorHandling.updateErrorPayload)(result.error || 'Failed to write data'));
|
|
208
|
+
});
|
|
209
|
+
}
|
|
163
210
|
return _context.abrupt("return", false);
|
|
164
|
-
case
|
|
165
|
-
_context.next =
|
|
211
|
+
case 24:
|
|
212
|
+
_context.next = 31;
|
|
166
213
|
break;
|
|
167
|
-
case
|
|
168
|
-
_context.prev =
|
|
214
|
+
case 26:
|
|
215
|
+
_context.prev = 26;
|
|
169
216
|
_context.t0 = _context["catch"](0);
|
|
170
217
|
(0, _monitoring.logException)(_context.t0, {
|
|
171
218
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
172
219
|
});
|
|
173
|
-
|
|
220
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
|
|
221
|
+
(_this$saveExperience4 = this.saveExperience) === null || _this$saveExperience4 === void 0 || _this$saveExperience4.failure({
|
|
222
|
+
reason: _context.t0.message
|
|
223
|
+
});
|
|
224
|
+
} else {
|
|
225
|
+
(_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, (0, _errorHandling.updateErrorPayload)(_context.t0.message));
|
|
226
|
+
}
|
|
174
227
|
return _context.abrupt("return", false);
|
|
175
|
-
case
|
|
228
|
+
case 31:
|
|
176
229
|
case "end":
|
|
177
230
|
return _context.stop();
|
|
178
231
|
}
|
|
179
|
-
}, _callee, this, [[0,
|
|
232
|
+
}, _callee, this, [[0, 26]]);
|
|
180
233
|
}));
|
|
181
234
|
function flush() {
|
|
182
235
|
return _flush.apply(this, arguments);
|
|
@@ -327,7 +380,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
327
380
|
value: function () {
|
|
328
381
|
var _delete2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syncBlockIds, onDelete, onDeleteCompleted) {
|
|
329
382
|
var _this5 = this;
|
|
330
|
-
var results, callback, isDeleteSuccessful, _this$fireAnalyticsEv4;
|
|
383
|
+
var results, callback, isDeleteSuccessful, _this$deleteExperienc, successfulDeleted, failedDelete, _this$deleteExperienc2, _this$fireAnalyticsEv4;
|
|
331
384
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
332
385
|
while (1) switch (_context2.prev = _context2.next) {
|
|
333
386
|
case 0:
|
|
@@ -361,12 +414,36 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
361
414
|
callback = function callback(Ids) {
|
|
362
415
|
_this5.setPendingDeletion(Ids, false);
|
|
363
416
|
};
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
417
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
|
|
418
|
+
successfulDeleted = results.filter(function (result) {
|
|
419
|
+
return result.success;
|
|
420
|
+
}).map(function (result) {
|
|
421
|
+
return {
|
|
422
|
+
resourceId: result.resourceId
|
|
423
|
+
};
|
|
424
|
+
});
|
|
425
|
+
failedDelete = results.filter(function (result) {
|
|
426
|
+
return !result.success;
|
|
427
|
+
}).map(function (result) {
|
|
428
|
+
return {
|
|
429
|
+
resourceId: result.resourceId || 'unknown',
|
|
430
|
+
failReason: result.error || 'Failed to delete sync block'
|
|
431
|
+
};
|
|
432
|
+
});
|
|
433
|
+
(_this$deleteExperienc = this.deleteExperience) === null || _this$deleteExperienc === void 0 || _this$deleteExperienc.failure({
|
|
434
|
+
metadata: {
|
|
435
|
+
successfulDeleted: successfulDeleted,
|
|
436
|
+
failedDelete: failedDelete
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
} else {
|
|
440
|
+
results.filter(function (result) {
|
|
441
|
+
return result.resourceId === undefined;
|
|
442
|
+
}).forEach(function (result) {
|
|
443
|
+
var _this5$fireAnalyticsE;
|
|
444
|
+
(_this5$fireAnalyticsE = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE === void 0 || _this5$fireAnalyticsE.call(_this5, (0, _errorHandling.deleteErrorPayload)(result.error || 'Failed to delete synced block'));
|
|
445
|
+
});
|
|
446
|
+
}
|
|
370
447
|
}
|
|
371
448
|
syncBlockIds.forEach(callback);
|
|
372
449
|
return _context2.abrupt("return", isDeleteSuccessful);
|
|
@@ -379,7 +456,13 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
379
456
|
(0, _monitoring.logException)(_context2.t0, {
|
|
380
457
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
381
458
|
});
|
|
382
|
-
|
|
459
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
|
|
460
|
+
(_this$deleteExperienc2 = this.deleteExperience) === null || _this$deleteExperienc2 === void 0 || _this$deleteExperienc2.failure({
|
|
461
|
+
reason: _context2.t0.message
|
|
462
|
+
});
|
|
463
|
+
} else {
|
|
464
|
+
(_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, (0, _errorHandling.deleteErrorPayload)(_context2.t0.message));
|
|
465
|
+
}
|
|
383
466
|
onDeleteCompleted(false);
|
|
384
467
|
return _context2.abrupt("return", false);
|
|
385
468
|
case 21:
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.parseResourceId = void 0;
|
|
8
|
+
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
|
|
9
|
+
var _consts = require("../common/consts");
|
|
10
|
+
var isSyncBlockProduct = function isSyncBlockProduct(product) {
|
|
11
|
+
return _consts.SYNC_BLOCK_PRODUCTS.includes(product);
|
|
12
|
+
};
|
|
13
|
+
var parseResourceId = exports.parseResourceId = function parseResourceId(resourceId) {
|
|
14
|
+
if (!resourceId) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
var _resourceId$split = resourceId.split('/'),
|
|
18
|
+
_resourceId$split2 = (0, _toArray2.default)(_resourceId$split),
|
|
19
|
+
product = _resourceId$split2[0],
|
|
20
|
+
contentId = _resourceId$split2[1],
|
|
21
|
+
uuid = _resourceId$split2[2],
|
|
22
|
+
rest = _resourceId$split2.slice(3);
|
|
23
|
+
|
|
24
|
+
// invalid if any part is missing or there are extra parts
|
|
25
|
+
if (!product || !contentId || !uuid || rest.length > 0) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// invalid if product is not recognized
|
|
30
|
+
if (!isSyncBlockProduct(product)) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
product: product,
|
|
35
|
+
contentId: contentId,
|
|
36
|
+
uuid: uuid
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
2
|
+
import { fetchWithRetry } from '../../utils/retry';
|
|
3
|
+
const COMMON_HEADERS = {
|
|
4
|
+
'Content-Type': 'application/json',
|
|
5
|
+
Accept: 'application/json'
|
|
6
|
+
};
|
|
7
|
+
const AGG_HEADERS = {
|
|
8
|
+
'X-ExperimentalApi': 'confluence-agg-beta'
|
|
9
|
+
};
|
|
10
|
+
const GRAPHQL_ENDPOINT = '/gateway/api/graphql';
|
|
11
|
+
const GET_CONTENT_MEDIA_SESSION_OPERATION_NAME = 'MediaUploadTokenQuery';
|
|
12
|
+
const GET_CONTENT_MEDIA_SESSION_QUERY = `query ${GET_CONTENT_MEDIA_SESSION_OPERATION_NAME}($contentId: ID!) {
|
|
13
|
+
contentMediaSession(contentId: $contentId) {
|
|
14
|
+
token {
|
|
15
|
+
value
|
|
16
|
+
}
|
|
17
|
+
configuration {
|
|
18
|
+
clientId
|
|
19
|
+
fileStoreUrl
|
|
20
|
+
}
|
|
21
|
+
collection
|
|
22
|
+
}
|
|
23
|
+
}`;
|
|
24
|
+
const getContentMediaSession = async contentId => {
|
|
25
|
+
const bodyData = {
|
|
26
|
+
query: GET_CONTENT_MEDIA_SESSION_QUERY,
|
|
27
|
+
operationName: GET_CONTENT_MEDIA_SESSION_OPERATION_NAME,
|
|
28
|
+
variables: {
|
|
29
|
+
contentId: contentId
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: {
|
|
35
|
+
...COMMON_HEADERS,
|
|
36
|
+
...AGG_HEADERS
|
|
37
|
+
},
|
|
38
|
+
body: JSON.stringify(bodyData)
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
throw new Error(`Failed to get content media session: ${response.statusText}`);
|
|
42
|
+
}
|
|
43
|
+
const result = await response.json();
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
export const fetchMediaToken = async contentId => {
|
|
47
|
+
try {
|
|
48
|
+
var _response$data, _contentData$token;
|
|
49
|
+
const response = await getContentMediaSession(contentId);
|
|
50
|
+
const contentData = (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.contentMediaSession;
|
|
51
|
+
const token = contentData === null || contentData === void 0 ? void 0 : (_contentData$token = contentData.token) === null || _contentData$token === void 0 ? void 0 : _contentData$token.value;
|
|
52
|
+
const configuration = contentData === null || contentData === void 0 ? void 0 : contentData.configuration;
|
|
53
|
+
const collection = contentData === null || contentData === void 0 ? void 0 : contentData.collection;
|
|
54
|
+
if (!token || !configuration || !collection) {
|
|
55
|
+
throw new Error('Failed to get content media session data');
|
|
56
|
+
}
|
|
57
|
+
return Promise.resolve({
|
|
58
|
+
config: configuration,
|
|
59
|
+
token,
|
|
60
|
+
collectionId: collection
|
|
61
|
+
});
|
|
62
|
+
} catch (error) {
|
|
63
|
+
logException(error, {
|
|
64
|
+
location: 'editor-synced-block-provider/fetchMediaToken'
|
|
65
|
+
});
|
|
66
|
+
throw new Error(`Failed to get content media session: ${error}`);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable require-unicode-regexp */
|
|
2
2
|
|
|
3
3
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
5
|
import { getSourceInfoErrorPayload } from '../../utils/errorHandling';
|
|
5
6
|
import { fetchWithRetry } from '../../utils/retry';
|
|
6
7
|
import { getPageIdAndTypeFromConfluencePageAri } from './ari';
|
|
@@ -55,7 +56,7 @@ const getConfluenceSourceInfo = async ari => {
|
|
|
55
56
|
}
|
|
56
57
|
return await response.json();
|
|
57
58
|
};
|
|
58
|
-
export const
|
|
59
|
+
export const fetchConfluencePageInfoOld = async (pageAri, localId, fireAnalyticsEvent) => {
|
|
59
60
|
try {
|
|
60
61
|
var _response$data, _response$data$conten, _response$data$conten2, _contentData$space;
|
|
61
62
|
const {
|
|
@@ -94,4 +95,36 @@ export const fetchConfluencePageInfo = async (pageAri, localId, fireAnalyticsEve
|
|
|
94
95
|
fireAnalyticsEvent === null || fireAnalyticsEvent === void 0 ? void 0 : fireAnalyticsEvent(getSourceInfoErrorPayload(error.message));
|
|
95
96
|
return Promise.resolve(undefined);
|
|
96
97
|
}
|
|
98
|
+
};
|
|
99
|
+
export const fetchConfluencePageInfoNew = async (pageAri, localId) => {
|
|
100
|
+
var _response$data2, _response$data2$conte, _response$data2$conte2, _contentData$space2;
|
|
101
|
+
const {
|
|
102
|
+
type: pageType
|
|
103
|
+
} = getPageIdAndTypeFromConfluencePageAri({
|
|
104
|
+
ari: pageAri
|
|
105
|
+
});
|
|
106
|
+
const response = await getConfluenceSourceInfo(pageAri);
|
|
107
|
+
const contentData = (_response$data2 = response.data) === null || _response$data2 === void 0 ? void 0 : (_response$data2$conte = _response$data2.content) === null || _response$data2$conte === void 0 ? void 0 : (_response$data2$conte2 = _response$data2$conte.nodes) === null || _response$data2$conte2 === void 0 ? void 0 : _response$data2$conte2[0];
|
|
108
|
+
const title = contentData === null || contentData === void 0 ? void 0 : contentData.title;
|
|
109
|
+
let url;
|
|
110
|
+
const {
|
|
111
|
+
base
|
|
112
|
+
} = (contentData === null || contentData === void 0 ? void 0 : contentData.links) || {};
|
|
113
|
+
if (base && contentData !== null && contentData !== void 0 && (_contentData$space2 = contentData.space) !== null && _contentData$space2 !== void 0 && _contentData$space2.key && contentData !== null && contentData !== void 0 && contentData.id) {
|
|
114
|
+
if (isBlogPageType(pageType)) {
|
|
115
|
+
url = `${base}/spaces/${contentData.space.key}/blog/edit-v2/${contentData.id}`;
|
|
116
|
+
} else if (contentData.subType === 'live') {
|
|
117
|
+
url = `${base}/spaces/${contentData.space.key}/pages/${contentData.id}`;
|
|
118
|
+
} else {
|
|
119
|
+
url = `${base}/spaces/${contentData.space.key}/pages/edit-v2/${contentData.id}`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
url = url && localId ? `${url}#block-${localId}` : url;
|
|
123
|
+
return Promise.resolve({
|
|
124
|
+
title,
|
|
125
|
+
url
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
export const fetchConfluencePageInfo = async (pageAri, localId, fireAnalyticsEvent) => {
|
|
129
|
+
return fg('platform_synced_block_dogfooding') ? await fetchConfluencePageInfoNew(pageAri, localId) : await fetchConfluencePageInfoOld(pageAri, localId, fireAnalyticsEvent);
|
|
97
130
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SYNC_BLOCK_PRODUCTS = ['confluence-page', 'jira-work-item'];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react';
|
|
2
2
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
4
|
import { SyncBlockError } from '../common/types';
|
|
4
5
|
import { fetchErrorPayload } from '../utils/errorHandling';
|
|
5
6
|
import { createSyncBlockNode } from '../utils/utils';
|
|
@@ -45,7 +46,14 @@ export const useFetchSyncBlockData = (manager, resourceId, localId, fireAnalytic
|
|
|
45
46
|
logException(error, {
|
|
46
47
|
location: 'editor-synced-block-provider/useFetchSyncBlockData'
|
|
47
48
|
});
|
|
48
|
-
|
|
49
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
50
|
+
var _manager$referenceMan2, _manager$referenceMan3;
|
|
51
|
+
manager === null || manager === void 0 ? void 0 : (_manager$referenceMan2 = manager.referenceManager) === null || _manager$referenceMan2 === void 0 ? void 0 : (_manager$referenceMan3 = _manager$referenceMan2.fetchExperience) === null || _manager$referenceMan3 === void 0 ? void 0 : _manager$referenceMan3.failure({
|
|
52
|
+
reason: error.message
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
fireAnalyticsEvent === null || fireAnalyticsEvent === void 0 ? void 0 : fireAnalyticsEvent(fetchErrorPayload(error.message));
|
|
56
|
+
}
|
|
49
57
|
|
|
50
58
|
// Set error state if fetching fails
|
|
51
59
|
setFetchState({
|
|
@@ -75,6 +83,7 @@ export const useFetchSyncBlockData = (manager, resourceId, localId, fireAnalytic
|
|
|
75
83
|
}, [localId, manager.referenceManager, resourceId]);
|
|
76
84
|
return {
|
|
77
85
|
isLoading,
|
|
86
|
+
ssrProviders: resourceId ? manager.referenceManager.getSSRProviders(resourceId) : null,
|
|
78
87
|
providerFactory: manager.referenceManager.getProviderFactory(resourceId || ''),
|
|
79
88
|
reloadData,
|
|
80
89
|
syncBlockInstance
|
package/dist/es2019/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
|
11
11
|
// clients
|
|
12
12
|
export { generateBlockAri, generateBlockAriFromReference, getLocalIdFromBlockResourceId } from './clients/block-service/ari';
|
|
13
13
|
export { getConfluencePageAri, getPageIdAndTypeFromConfluencePageAri } from './clients/confluence/ari';
|
|
14
|
+
export { fetchMediaToken } from './clients/confluence/fetchMediaToken';
|
|
14
15
|
export { getJiraWorkItemAri, getJiraWorkItemIdFromAri } from './clients/jira/ari';
|
|
15
16
|
|
|
16
17
|
// providers
|
|
@@ -24,6 +25,7 @@ export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager } from './store
|
|
|
24
25
|
|
|
25
26
|
// utils
|
|
26
27
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
28
|
+
export { parseResourceId } from './utils/parseResourceId';
|
|
27
29
|
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, getContentIdAndProductFromResourceId } from './utils/utils';
|
|
28
30
|
export { fetchErrorPayload } from './utils/errorHandling';
|
|
29
31
|
export { fetchReferences } from './providers/block-service/blockServiceAPI';
|