@atlaskit/editor-synced-block-provider 3.5.5 → 3.6.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 +21 -0
- package/dist/cjs/clients/block-service/ari.js +12 -1
- package/dist/cjs/clients/block-service/blockService.js +35 -2
- package/dist/cjs/clients/confluence/sourceInfo.js +150 -19
- package/dist/cjs/common/consts.js +7 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +10 -2
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/providers/block-service/blockServiceAPI.js +195 -125
- package/dist/cjs/providers/syncBlockProvider.js +83 -14
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +267 -63
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +134 -34
- package/dist/cjs/store-manager/syncBlockStoreManager.js +121 -0
- package/dist/cjs/utils/errorHandling.js +4 -1
- package/dist/cjs/utils/parseResourceId.js +38 -0
- package/dist/es2019/clients/block-service/ari.js +11 -0
- package/dist/es2019/clients/block-service/blockService.js +12 -1
- package/dist/es2019/clients/confluence/sourceInfo.js +70 -2
- package/dist/es2019/common/consts.js +1 -0
- package/dist/es2019/hooks/useFetchSyncBlockData.js +10 -1
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/providers/block-service/blockServiceAPI.js +45 -2
- package/dist/es2019/providers/syncBlockProvider.js +37 -5
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +249 -39
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +101 -16
- package/dist/es2019/store-manager/syncBlockStoreManager.js +64 -0
- package/dist/es2019/utils/errorHandling.js +2 -1
- package/dist/es2019/utils/parseResourceId.js +25 -0
- package/dist/esm/clients/block-service/ari.js +11 -0
- package/dist/esm/clients/block-service/blockService.js +34 -1
- package/dist/esm/clients/confluence/sourceInfo.js +149 -18
- package/dist/esm/common/consts.js +1 -0
- package/dist/esm/hooks/useFetchSyncBlockData.js +10 -2
- package/dist/esm/index.js +1 -0
- package/dist/esm/providers/block-service/blockServiceAPI.js +195 -125
- package/dist/esm/providers/syncBlockProvider.js +81 -12
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +267 -63
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +135 -35
- package/dist/esm/store-manager/syncBlockStoreManager.js +121 -0
- package/dist/esm/utils/errorHandling.js +3 -0
- package/dist/esm/utils/parseResourceId.js +31 -0
- package/dist/types/clients/block-service/ari.d.ts +1 -0
- package/dist/types/clients/block-service/blockService.d.ts +15 -5
- package/dist/types/clients/confluence/sourceInfo.d.ts +3 -1
- package/dist/types/common/consts.d.ts +1 -0
- package/dist/types/common/types.d.ts +27 -1
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +6 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +3 -2
- package/dist/types/providers/syncBlockProvider.d.ts +3 -2
- package/dist/types/providers/types.d.ts +15 -2
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +11 -2
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +7 -2
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +4 -0
- package/dist/types/utils/errorHandling.d.ts +1 -0
- package/dist/types/utils/parseResourceId.d.ts +6 -0
- package/dist/types-ts4.5/clients/block-service/ari.d.ts +1 -0
- package/dist/types-ts4.5/clients/block-service/blockService.d.ts +15 -5
- package/dist/types-ts4.5/clients/confluence/sourceInfo.d.ts +3 -1
- package/dist/types-ts4.5/common/consts.d.ts +4 -0
- package/dist/types-ts4.5/common/types.d.ts +27 -1
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +6 -1
- package/dist/types-ts4.5/index.d.ts +3 -2
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +3 -2
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +3 -2
- package/dist/types-ts4.5/providers/types.d.ts +15 -2
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +11 -2
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +7 -2
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +4 -0
- package/dist/types-ts4.5/utils/errorHandling.d.ts +1 -0
- package/dist/types-ts4.5/utils/parseResourceId.d.ts +6 -0
- package/package.json +2 -2
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* eslint-disable require-unicode-regexp */
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
4
|
import { generateBlockAri, generateBlockAriFromReference } from '../../clients/block-service/ari';
|
|
4
|
-
import { batchRetrieveSyncedBlocks, BlockError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock } from '../../clients/block-service/blockService';
|
|
5
|
+
import { batchRetrieveSyncedBlocks, BlockError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getReferenceSyncedBlocksByBlockAri, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock } from '../../clients/block-service/blockService';
|
|
5
6
|
import { SyncBlockError } from '../../common/types';
|
|
6
7
|
import { stringifyError } from '../../utils/errorHandling';
|
|
7
8
|
const mapBlockError = error => {
|
|
@@ -181,6 +182,47 @@ class BlockServiceADFFetchProvider {
|
|
|
181
182
|
};
|
|
182
183
|
}
|
|
183
184
|
}
|
|
185
|
+
async fetchReferences(referenceResourceId) {
|
|
186
|
+
try {
|
|
187
|
+
const blockAri = generateBlockAriFromReference({
|
|
188
|
+
cloudId: this.cloudId,
|
|
189
|
+
resourceId: referenceResourceId
|
|
190
|
+
});
|
|
191
|
+
const response = await getReferenceSyncedBlocksByBlockAri({
|
|
192
|
+
blockAri
|
|
193
|
+
});
|
|
194
|
+
const references = [];
|
|
195
|
+
response.references.forEach(reference => {
|
|
196
|
+
references.push({
|
|
197
|
+
...reference,
|
|
198
|
+
hasAccess: true,
|
|
199
|
+
onSamePage: this.parentAri === reference.documentAri
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
response.errors.forEach(reference => {
|
|
203
|
+
if (reference.code === 'FORBIDDEN') {
|
|
204
|
+
references.push({
|
|
205
|
+
blockAri: reference.blockAri,
|
|
206
|
+
documentAri: reference.documentAri,
|
|
207
|
+
hasAccess: false,
|
|
208
|
+
onSamePage: false
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
return {
|
|
213
|
+
references
|
|
214
|
+
};
|
|
215
|
+
} catch (error) {
|
|
216
|
+
if (error instanceof BlockError) {
|
|
217
|
+
return {
|
|
218
|
+
error: mapBlockError(error)
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
error: SyncBlockError.Errored
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
184
226
|
|
|
185
227
|
/**
|
|
186
228
|
* Extracts the resourceId from a block ARI.
|
|
@@ -486,7 +528,8 @@ const createBlockServiceAPIProviders = ({
|
|
|
486
528
|
}) => {
|
|
487
529
|
return {
|
|
488
530
|
fetchProvider: new BlockServiceADFFetchProvider({
|
|
489
|
-
cloudId
|
|
531
|
+
cloudId,
|
|
532
|
+
parentAri: fg('platform_synced_block_dogfooding') ? parentAri : undefined
|
|
490
533
|
}),
|
|
491
534
|
writeProvider: new BlockServiceADFWriteProvider({
|
|
492
535
|
cloudId,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
|
+
import { getProductFromSourceAri } from '../clients/block-service/ari';
|
|
4
5
|
import { getPageIdAndTypeFromConfluencePageAri } from '../clients/confluence/ari';
|
|
5
6
|
import { fetchConfluencePageInfo } from '../clients/confluence/sourceInfo';
|
|
6
7
|
import { SyncBlockError } from '../common/types';
|
|
@@ -168,17 +169,42 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
168
169
|
*
|
|
169
170
|
* @returns The source info
|
|
170
171
|
*/
|
|
171
|
-
fetchSyncBlockSourceInfo(localId, sourceAri, sourceProduct, fireAnalyticsEvent) {
|
|
172
|
-
|
|
172
|
+
async fetchSyncBlockSourceInfo(localId, sourceAri, sourceProduct, fireAnalyticsEvent, hasAccess = true, urlType = 'edit') {
|
|
173
|
+
let ari = sourceAri,
|
|
174
|
+
product = sourceProduct;
|
|
175
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
176
|
+
var _this$writeProvider2;
|
|
177
|
+
ari = sourceAri !== null && sourceAri !== void 0 ? sourceAri : (_this$writeProvider2 = this.writeProvider) === null || _this$writeProvider2 === void 0 ? void 0 : _this$writeProvider2.parentAri;
|
|
178
|
+
product = sourceProduct !== null && sourceProduct !== void 0 ? sourceProduct : getProductFromSourceAri(ari);
|
|
179
|
+
}
|
|
180
|
+
if (!ari || !product) {
|
|
173
181
|
return Promise.reject(new Error('Source ari or source product is undefined'));
|
|
174
182
|
}
|
|
175
|
-
switch (
|
|
183
|
+
switch (product) {
|
|
176
184
|
case 'confluence-page':
|
|
177
|
-
|
|
185
|
+
{
|
|
186
|
+
const sourceInfo = await fetchConfluencePageInfo(ari, hasAccess, urlType, localId, fireAnalyticsEvent);
|
|
187
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
188
|
+
var _this$writeProvider3;
|
|
189
|
+
if (!sourceInfo) {
|
|
190
|
+
return Promise.resolve(undefined);
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
...sourceInfo,
|
|
194
|
+
onSamePage: ((_this$writeProvider3 = this.writeProvider) === null || _this$writeProvider3 === void 0 ? void 0 : _this$writeProvider3.parentAri) === ari,
|
|
195
|
+
productType: product
|
|
196
|
+
};
|
|
197
|
+
} else {
|
|
198
|
+
return sourceInfo;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
178
201
|
case 'jira-work-item':
|
|
202
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
203
|
+
return Promise.resolve(undefined);
|
|
204
|
+
}
|
|
179
205
|
return Promise.reject(new Error('Jira work item source product not supported'));
|
|
180
206
|
default:
|
|
181
|
-
return Promise.reject(new Error(`${
|
|
207
|
+
return Promise.reject(new Error(`${product} source product not supported`));
|
|
182
208
|
}
|
|
183
209
|
}
|
|
184
210
|
generateResourceId() {
|
|
@@ -237,6 +263,12 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
237
263
|
}
|
|
238
264
|
return this.writeProvider.updateReferenceData(blocks, noContent);
|
|
239
265
|
}
|
|
266
|
+
fetchReferences(resourceId, isSource) {
|
|
267
|
+
if (!this.fetchProvider) {
|
|
268
|
+
throw new Error('Fetch provider not set');
|
|
269
|
+
}
|
|
270
|
+
return this.fetchProvider.fetchReferences(isSource ? this.generateResourceIdForReference(resourceId) : resourceId);
|
|
271
|
+
}
|
|
240
272
|
}
|
|
241
273
|
const createSyncedBlockProvider = ({
|
|
242
274
|
fetchProvider,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
3
3
|
import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
5
|
import { SyncBlockError } from '../common/types';
|
|
5
6
|
import { fetchErrorPayload, getSourceInfoErrorPayload, updateReferenceErrorPayload } from '../utils/errorHandling';
|
|
7
|
+
import { parseResourceId } from '../utils/parseResourceId';
|
|
6
8
|
import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
|
|
7
9
|
import { createSyncBlockNode } from '../utils/utils';
|
|
8
10
|
|
|
@@ -28,6 +30,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
28
30
|
this.titleSubscriptions = new Map();
|
|
29
31
|
this.dataProvider = dataProvider;
|
|
30
32
|
this.syncBlockFetchDataRequests = new Map();
|
|
33
|
+
this.syncBlockSourceInfoRequestsOld = new Map();
|
|
31
34
|
this.syncBlockSourceInfoRequests = new Map();
|
|
32
35
|
this.providerFactories = new Map();
|
|
33
36
|
this.pendingCacheDeletions = new Map();
|
|
@@ -35,6 +38,14 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
35
38
|
setFireAnalyticsEvent(fireAnalyticsEvent) {
|
|
36
39
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
37
40
|
}
|
|
41
|
+
setExperiences(fetchExperience, fetchSourceInfoExperience, saveExperience) {
|
|
42
|
+
// don't reset experiences after they have already been set
|
|
43
|
+
if (!this.fetchExperience || !this.fetchSourceInfoExperience || !this.saveExperience) {
|
|
44
|
+
this.fetchExperience = fetchExperience;
|
|
45
|
+
this.fetchSourceInfoExperience = fetchSourceInfoExperience;
|
|
46
|
+
this.saveExperience = saveExperience;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
38
49
|
generateResourceIdForReference(sourceId) {
|
|
39
50
|
if (!this.dataProvider) {
|
|
40
51
|
throw new Error('Data provider not set');
|
|
@@ -70,65 +81,155 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
70
81
|
// this function will update the cache and call the subscriptions
|
|
71
82
|
await this.fetchSyncBlocksData(syncBlocks);
|
|
72
83
|
} catch (error) {
|
|
73
|
-
var _this$fireAnalyticsEv;
|
|
74
84
|
logException(error, {
|
|
75
85
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
76
86
|
});
|
|
77
|
-
|
|
87
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
88
|
+
var _this$fetchExperience;
|
|
89
|
+
(_this$fetchExperience = this.fetchExperience) === null || _this$fetchExperience === void 0 ? void 0 : _this$fetchExperience.failure({
|
|
90
|
+
reason: error.message
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
var _this$fireAnalyticsEv;
|
|
94
|
+
(_this$fireAnalyticsEv = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 ? void 0 : _this$fireAnalyticsEv.call(this, fetchErrorPayload(error.message));
|
|
95
|
+
}
|
|
78
96
|
} finally {
|
|
79
97
|
this.isRefreshingSubscriptions = false;
|
|
80
98
|
}
|
|
81
99
|
}
|
|
82
100
|
fetchSyncBlockSourceInfo(resourceId) {
|
|
83
101
|
try {
|
|
84
|
-
var _existingSyncBlock$da, _existingSyncBlock$da2;
|
|
85
102
|
if (!resourceId || !this.dataProvider) {
|
|
103
|
+
// make sure experience has been started before throwing error
|
|
104
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
105
|
+
var _this$fetchSourceInfo;
|
|
106
|
+
(_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 ? void 0 : _this$fetchSourceInfo.start({});
|
|
107
|
+
}
|
|
86
108
|
throw new Error('Data provider or resourceId not set');
|
|
87
109
|
}
|
|
88
|
-
if (
|
|
89
|
-
|
|
110
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
111
|
+
const existingRequest = this.syncBlockSourceInfoRequests.get(resourceId);
|
|
112
|
+
if (existingRequest) {
|
|
113
|
+
return existingRequest;
|
|
114
|
+
}
|
|
115
|
+
} else if (this.syncBlockSourceInfoRequestsOld.get(resourceId)) {
|
|
116
|
+
return Promise.resolve(undefined);
|
|
90
117
|
}
|
|
91
118
|
const existingSyncBlock = this.getFromCache(resourceId);
|
|
92
119
|
if (!existingSyncBlock) {
|
|
120
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
121
|
+
var _this$fetchSourceInfo2;
|
|
122
|
+
(_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 ? void 0 : _this$fetchSourceInfo2.start({});
|
|
123
|
+
}
|
|
93
124
|
throw new Error('No existing sync block to fetch source info for');
|
|
94
125
|
}
|
|
95
|
-
|
|
96
|
-
// skip if source URL and title are already present
|
|
97
|
-
if ((_existingSyncBlock$da = existingSyncBlock.data) !== null && _existingSyncBlock$da !== void 0 && _existingSyncBlock$da.sourceURL && (_existingSyncBlock$da2 = existingSyncBlock.data) !== null && _existingSyncBlock$da2 !== void 0 && _existingSyncBlock$da2.sourceTitle) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
126
|
const {
|
|
101
127
|
sourceAri,
|
|
102
128
|
product,
|
|
103
|
-
blockInstanceId
|
|
129
|
+
blockInstanceId,
|
|
130
|
+
sourceURL,
|
|
131
|
+
sourceTitle,
|
|
132
|
+
onSamePage,
|
|
133
|
+
sourceSubType
|
|
104
134
|
} = existingSyncBlock.data || {};
|
|
135
|
+
// skip if source URL and title are already present
|
|
136
|
+
if (sourceURL && sourceTitle) {
|
|
137
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
138
|
+
return Promise.resolve({
|
|
139
|
+
title: sourceTitle,
|
|
140
|
+
url: sourceURL,
|
|
141
|
+
subType: sourceSubType,
|
|
142
|
+
sourceAri: sourceAri || '',
|
|
143
|
+
onSamePage,
|
|
144
|
+
productType: product
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
return Promise.resolve(undefined);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// only start experience if there is data to fetch
|
|
152
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
153
|
+
var _this$fetchSourceInfo3;
|
|
154
|
+
(_this$fetchSourceInfo3 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 ? void 0 : _this$fetchSourceInfo3.start({});
|
|
155
|
+
}
|
|
105
156
|
if (!sourceAri || !product || !blockInstanceId) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
157
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
158
|
+
var _this$fetchSourceInfo4;
|
|
159
|
+
(_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 ? void 0 : _this$fetchSourceInfo4.failure({
|
|
160
|
+
reason: 'SourceAri, product or blockInstanceId missing'
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
var _this$fireAnalyticsEv2;
|
|
164
|
+
(_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 ? void 0 : _this$fireAnalyticsEv2.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing'));
|
|
165
|
+
}
|
|
166
|
+
return Promise.resolve(undefined);
|
|
109
167
|
}
|
|
110
|
-
this.
|
|
111
|
-
this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, this.fireAnalyticsEvent).then(sourceInfo => {
|
|
168
|
+
const sourceInfoPromise = this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, this.fireAnalyticsEvent).then(sourceInfo => {
|
|
112
169
|
if (!sourceInfo) {
|
|
113
|
-
|
|
170
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
171
|
+
var _this$fetchSourceInfo5;
|
|
172
|
+
(_this$fetchSourceInfo5 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo5 === void 0 ? void 0 : _this$fetchSourceInfo5.failure({
|
|
173
|
+
reason: 'No source info returned'
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return undefined;
|
|
114
177
|
}
|
|
115
178
|
this.updateCacheWithSourceInfo(resourceId, sourceInfo);
|
|
116
179
|
if (sourceInfo.title) {
|
|
117
180
|
this.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
|
|
118
181
|
}
|
|
182
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
183
|
+
if (sourceInfo.title && sourceInfo.url) {
|
|
184
|
+
var _this$fetchSourceInfo6;
|
|
185
|
+
(_this$fetchSourceInfo6 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo6 === void 0 ? void 0 : _this$fetchSourceInfo6.success();
|
|
186
|
+
} else {
|
|
187
|
+
var _this$fetchSourceInfo7;
|
|
188
|
+
(_this$fetchSourceInfo7 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo7 === void 0 ? void 0 : _this$fetchSourceInfo7.failure({
|
|
189
|
+
reason: 'Missing title or url'
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return sourceInfo;
|
|
193
|
+
}
|
|
119
194
|
}).catch(error => {
|
|
120
|
-
|
|
121
|
-
|
|
195
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
196
|
+
var _this$fetchSourceInfo8;
|
|
197
|
+
(_this$fetchSourceInfo8 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo8 === void 0 ? void 0 : _this$fetchSourceInfo8.failure({
|
|
198
|
+
reason: error.message
|
|
199
|
+
});
|
|
200
|
+
} else {
|
|
201
|
+
var _this$fireAnalyticsEv3;
|
|
202
|
+
(_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 ? void 0 : _this$fireAnalyticsEv3.call(this, getSourceInfoErrorPayload(error.message));
|
|
203
|
+
}
|
|
204
|
+
return undefined;
|
|
122
205
|
}).finally(() => {
|
|
123
|
-
|
|
206
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
207
|
+
this.syncBlockSourceInfoRequests.delete(resourceId);
|
|
208
|
+
} else {
|
|
209
|
+
this.syncBlockSourceInfoRequestsOld.delete(resourceId);
|
|
210
|
+
}
|
|
124
211
|
});
|
|
212
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
213
|
+
this.syncBlockSourceInfoRequests.set(resourceId, sourceInfoPromise);
|
|
214
|
+
return sourceInfoPromise;
|
|
215
|
+
} else {
|
|
216
|
+
this.syncBlockSourceInfoRequestsOld.set(resourceId, true);
|
|
217
|
+
}
|
|
125
218
|
} catch (error) {
|
|
126
|
-
var _this$fireAnalyticsEv4;
|
|
127
219
|
logException(error, {
|
|
128
220
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
129
221
|
});
|
|
130
|
-
|
|
222
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
223
|
+
var _this$fetchSourceInfo9;
|
|
224
|
+
(_this$fetchSourceInfo9 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo9 === void 0 ? void 0 : _this$fetchSourceInfo9.failure({
|
|
225
|
+
reason: error.message
|
|
226
|
+
});
|
|
227
|
+
} else {
|
|
228
|
+
var _this$fireAnalyticsEv4;
|
|
229
|
+
(_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 ? void 0 : _this$fireAnalyticsEv4.call(this, getSourceInfoErrorPayload(error.message));
|
|
230
|
+
}
|
|
131
231
|
}
|
|
232
|
+
return Promise.resolve(undefined);
|
|
132
233
|
}
|
|
133
234
|
|
|
134
235
|
/**
|
|
@@ -140,9 +241,6 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
140
241
|
if (syncBlockNodes.length === 0) {
|
|
141
242
|
return;
|
|
142
243
|
}
|
|
143
|
-
if (!this.dataProvider) {
|
|
144
|
-
throw new Error('Data provider not set');
|
|
145
|
-
}
|
|
146
244
|
|
|
147
245
|
// Don't fetch for not_found error since the source is already deleted
|
|
148
246
|
const nodesToFetch = [];
|
|
@@ -159,6 +257,15 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
159
257
|
if (nodesToFetch.length === 0) {
|
|
160
258
|
return;
|
|
161
259
|
}
|
|
260
|
+
|
|
261
|
+
// only start fetch experience if there is data to fetch
|
|
262
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
263
|
+
var _this$fetchExperience2;
|
|
264
|
+
(_this$fetchExperience2 = this.fetchExperience) === null || _this$fetchExperience2 === void 0 ? void 0 : _this$fetchExperience2.start({});
|
|
265
|
+
}
|
|
266
|
+
if (!this.dataProvider) {
|
|
267
|
+
throw new Error('Data provider not set');
|
|
268
|
+
}
|
|
162
269
|
nodesToFetch.forEach(node => {
|
|
163
270
|
this.syncBlockFetchDataRequests.set(node.attrs.resourceId, true);
|
|
164
271
|
});
|
|
@@ -168,10 +275,18 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
168
275
|
});
|
|
169
276
|
});
|
|
170
277
|
const resolvedData = [];
|
|
278
|
+
const successfulFetched = [];
|
|
279
|
+
const failedFetch = [];
|
|
171
280
|
data.forEach(syncBlockInstance => {
|
|
172
281
|
if (!syncBlockInstance.resourceId) {
|
|
173
|
-
|
|
174
|
-
|
|
282
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
283
|
+
failedFetch.push({
|
|
284
|
+
reason: syncBlockInstance.error || 'Returned sync block instance does not have resource id'
|
|
285
|
+
});
|
|
286
|
+
} else {
|
|
287
|
+
var _this$fireAnalyticsEv5;
|
|
288
|
+
(_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 ? void 0 : _this$fireAnalyticsEv5.call(this, fetchErrorPayload(syncBlockInstance.error || 'Returned sync block instance does not have resource id'));
|
|
289
|
+
}
|
|
175
290
|
return;
|
|
176
291
|
}
|
|
177
292
|
const existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
|
|
@@ -179,12 +294,38 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
179
294
|
this.updateCache(resolvedSyncBlockInstance);
|
|
180
295
|
resolvedData.push(resolvedSyncBlockInstance);
|
|
181
296
|
if (syncBlockInstance.error) {
|
|
182
|
-
|
|
183
|
-
|
|
297
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
298
|
+
failedFetch.push({
|
|
299
|
+
reason: syncBlockInstance.error,
|
|
300
|
+
resourceId: syncBlockInstance.resourceId
|
|
301
|
+
});
|
|
302
|
+
} else {
|
|
303
|
+
var _this$fireAnalyticsEv6;
|
|
304
|
+
(_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, fetchErrorPayload(syncBlockInstance.error));
|
|
305
|
+
}
|
|
184
306
|
return;
|
|
185
307
|
}
|
|
308
|
+
successfulFetched.push(syncBlockInstance.resourceId);
|
|
186
309
|
this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
187
310
|
});
|
|
311
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
312
|
+
if (data.every(syncBlockInstance => syncBlockInstance.resourceId && !syncBlockInstance.error)) {
|
|
313
|
+
var _this$fetchExperience3;
|
|
314
|
+
(_this$fetchExperience3 = this.fetchExperience) === null || _this$fetchExperience3 === void 0 ? void 0 : _this$fetchExperience3.success({
|
|
315
|
+
metadata: {
|
|
316
|
+
successfulFetched
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
} else {
|
|
320
|
+
var _this$fetchExperience4;
|
|
321
|
+
(_this$fetchExperience4 = this.fetchExperience) === null || _this$fetchExperience4 === void 0 ? void 0 : _this$fetchExperience4.failure({
|
|
322
|
+
metadata: {
|
|
323
|
+
successfulFetched,
|
|
324
|
+
failedFetch
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
188
329
|
}
|
|
189
330
|
updateCacheWithSourceInfo(resourceId, sourceInfo) {
|
|
190
331
|
const existingSyncBlock = this.getFromCache(resourceId);
|
|
@@ -193,7 +334,9 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
193
334
|
existingSyncBlock.data = {
|
|
194
335
|
...existingSyncBlock.data,
|
|
195
336
|
sourceURL: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url,
|
|
196
|
-
sourceTitle: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.title
|
|
337
|
+
sourceTitle: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.title,
|
|
338
|
+
onSamePage: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.onSamePage,
|
|
339
|
+
sourceSubType: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.subType
|
|
197
340
|
};
|
|
198
341
|
this.updateCache(existingSyncBlock);
|
|
199
342
|
}
|
|
@@ -257,11 +400,18 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
257
400
|
callback(cachedData);
|
|
258
401
|
} else {
|
|
259
402
|
this.fetchSyncBlocksData([syncBlockNode]).catch(error => {
|
|
260
|
-
var _this$fireAnalyticsEv7;
|
|
261
403
|
logException(error, {
|
|
262
404
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
263
405
|
});
|
|
264
|
-
|
|
406
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
407
|
+
var _this$fetchExperience5;
|
|
408
|
+
(_this$fetchExperience5 = this.fetchExperience) === null || _this$fetchExperience5 === void 0 ? void 0 : _this$fetchExperience5.failure({
|
|
409
|
+
reason: error.message
|
|
410
|
+
});
|
|
411
|
+
} else {
|
|
412
|
+
var _this$fireAnalyticsEv7;
|
|
413
|
+
(_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 ? void 0 : _this$fireAnalyticsEv7.call(this, fetchErrorPayload(error.message));
|
|
414
|
+
}
|
|
265
415
|
});
|
|
266
416
|
}
|
|
267
417
|
return () => {
|
|
@@ -410,6 +560,44 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
410
560
|
}
|
|
411
561
|
return providerFactory;
|
|
412
562
|
}
|
|
563
|
+
getSSRProviders(resourceId) {
|
|
564
|
+
if (!fg('platform_synced_block_dogfooding')) {
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
if (!this.dataProvider) {
|
|
568
|
+
return null;
|
|
569
|
+
}
|
|
570
|
+
const {
|
|
571
|
+
providerCreator
|
|
572
|
+
} = this.dataProvider.getSyncedBlockRendererProviderOptions();
|
|
573
|
+
if (!(providerCreator !== null && providerCreator !== void 0 && providerCreator.createSSRMediaProvider)) {
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
const parsedResourceId = parseResourceId(resourceId);
|
|
577
|
+
if (!parsedResourceId) {
|
|
578
|
+
return null;
|
|
579
|
+
}
|
|
580
|
+
const {
|
|
581
|
+
contentId,
|
|
582
|
+
product: contentProduct
|
|
583
|
+
} = parsedResourceId;
|
|
584
|
+
try {
|
|
585
|
+
const mediaProvider = providerCreator.createSSRMediaProvider({
|
|
586
|
+
contentId,
|
|
587
|
+
contentProduct
|
|
588
|
+
});
|
|
589
|
+
if (mediaProvider) {
|
|
590
|
+
return {
|
|
591
|
+
media: mediaProvider
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
} catch (error) {
|
|
595
|
+
logException(error, {
|
|
596
|
+
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
return null;
|
|
600
|
+
}
|
|
413
601
|
retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
|
|
414
602
|
var _syncBlock$data2, _syncBlock$data3, _syncBlock$data4, _syncBlock$data5;
|
|
415
603
|
if (!this.dataProvider) {
|
|
@@ -469,9 +657,6 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
469
657
|
}
|
|
470
658
|
let success = true;
|
|
471
659
|
try {
|
|
472
|
-
if (!this.dataProvider) {
|
|
473
|
-
throw new Error('Data provider not set');
|
|
474
|
-
}
|
|
475
660
|
const blocks = [];
|
|
476
661
|
|
|
477
662
|
// Collect all reference synced blocks on the current document
|
|
@@ -487,6 +672,13 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
487
672
|
this.isCacheDirty = false;
|
|
488
673
|
return true;
|
|
489
674
|
}
|
|
675
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
676
|
+
var _this$saveExperience;
|
|
677
|
+
(_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 ? void 0 : _this$saveExperience.start();
|
|
678
|
+
}
|
|
679
|
+
if (!this.dataProvider) {
|
|
680
|
+
throw new Error('Data provider not set');
|
|
681
|
+
}
|
|
490
682
|
|
|
491
683
|
// reset isCacheDirty early to prevent race condition
|
|
492
684
|
// There is a race condition where if a user makes changes (create/delete) to a reference sync block
|
|
@@ -496,21 +688,38 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
496
688
|
this.isCacheDirty = false;
|
|
497
689
|
const updateResult = await this.dataProvider.updateReferenceData(blocks);
|
|
498
690
|
if (!updateResult.success) {
|
|
499
|
-
var _this$fireAnalyticsEv10;
|
|
500
691
|
success = false;
|
|
501
|
-
|
|
692
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
693
|
+
var _this$saveExperience2;
|
|
694
|
+
(_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 ? void 0 : _this$saveExperience2.failure({
|
|
695
|
+
reason: updateResult.error || 'Failed to update reference synced blocks on the document'
|
|
696
|
+
});
|
|
697
|
+
} else {
|
|
698
|
+
var _this$fireAnalyticsEv10;
|
|
699
|
+
(_this$fireAnalyticsEv10 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv10 === void 0 ? void 0 : _this$fireAnalyticsEv10.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
|
|
700
|
+
}
|
|
502
701
|
}
|
|
503
702
|
} catch (error) {
|
|
504
|
-
var _this$fireAnalyticsEv11;
|
|
505
703
|
success = false;
|
|
506
704
|
logException(error, {
|
|
507
705
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
508
706
|
});
|
|
509
|
-
|
|
707
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
708
|
+
var _this$saveExperience3;
|
|
709
|
+
(_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 ? void 0 : _this$saveExperience3.failure({
|
|
710
|
+
reason: error.message
|
|
711
|
+
});
|
|
712
|
+
} else {
|
|
713
|
+
var _this$fireAnalyticsEv11;
|
|
714
|
+
(_this$fireAnalyticsEv11 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv11 === void 0 ? void 0 : _this$fireAnalyticsEv11.call(this, updateReferenceErrorPayload(error.message));
|
|
715
|
+
}
|
|
510
716
|
} finally {
|
|
511
717
|
if (!success) {
|
|
512
718
|
// set isCacheDirty back to true for cases where it failed to update the reference synced blocks on the BE
|
|
513
719
|
this.isCacheDirty = true;
|
|
720
|
+
} else if (fg('platform_synced_block_dogfooding')) {
|
|
721
|
+
var _this$saveExperience4;
|
|
722
|
+
(_this$saveExperience4 = this.saveExperience) === null || _this$saveExperience4 === void 0 ? void 0 : _this$saveExperience4.success();
|
|
514
723
|
}
|
|
515
724
|
}
|
|
516
725
|
return success;
|
|
@@ -521,6 +730,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
521
730
|
this.subscriptions.clear();
|
|
522
731
|
this.titleSubscriptions.clear();
|
|
523
732
|
this.syncBlockFetchDataRequests.clear();
|
|
733
|
+
this.syncBlockSourceInfoRequestsOld.clear();
|
|
524
734
|
this.syncBlockSourceInfoRequests.clear();
|
|
525
735
|
this.providerFactories.clear();
|
|
526
736
|
this.isRefreshingSubscriptions = false;
|