@atlaskit/editor-synced-block-provider 3.14.1 → 3.14.2
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/dist/cjs/clients/block-service/blockService.js +9 -7
- package/dist/cjs/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/cjs/providers/block-service/blockServiceAPI.js +47 -18
- package/dist/cjs/providers/syncBlockProvider.js +10 -6
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +6 -5
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +41 -23
- package/dist/cjs/store-manager/syncBlockStoreManager.js +1 -1
- package/dist/cjs/utils/resolveSyncBlockInstance.js +2 -1
- package/dist/es2019/clients/block-service/blockService.js +5 -2
- package/dist/es2019/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/es2019/providers/block-service/blockServiceAPI.js +45 -16
- package/dist/es2019/providers/syncBlockProvider.js +8 -4
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +6 -5
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +28 -11
- package/dist/es2019/store-manager/syncBlockStoreManager.js +1 -1
- package/dist/es2019/utils/resolveSyncBlockInstance.js +2 -1
- package/dist/esm/clients/block-service/blockService.js +9 -7
- package/dist/esm/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/esm/providers/block-service/blockServiceAPI.js +47 -18
- package/dist/esm/providers/syncBlockProvider.js +10 -6
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +6 -5
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +42 -24
- package/dist/esm/store-manager/syncBlockStoreManager.js +1 -1
- package/dist/esm/utils/resolveSyncBlockInstance.js +2 -1
- package/dist/types/clients/block-service/blockService.d.ts +4 -2
- package/dist/types/common/types.d.ts +4 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +1 -1
- package/dist/types/providers/syncBlockProvider.d.ts +2 -2
- package/dist/types/providers/types.d.ts +8 -4
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +4 -3
- package/dist/types-ts4.5/clients/block-service/blockService.d.ts +4 -2
- package/dist/types-ts4.5/common/types.d.ts +4 -0
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +1 -1
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +2 -2
- package/dist/types-ts4.5/providers/types.d.ts +8 -4
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +4 -3
- package/package.json +1 -1
|
@@ -125,7 +125,9 @@ export const fetchReferences = async documentAri => {
|
|
|
125
125
|
if (!resourceId) {
|
|
126
126
|
// could not extract resourceId from blockAri, return InvalidContent error
|
|
127
127
|
return {
|
|
128
|
-
error:
|
|
128
|
+
error: {
|
|
129
|
+
type: SyncBlockError.InvalidContent
|
|
130
|
+
},
|
|
129
131
|
resourceId: blockContentResponse.blockAri
|
|
130
132
|
};
|
|
131
133
|
}
|
|
@@ -136,13 +138,17 @@ export const fetchReferences = async documentAri => {
|
|
|
136
138
|
} catch {
|
|
137
139
|
// JSON parsing error, return InvalidContent error
|
|
138
140
|
return {
|
|
139
|
-
error:
|
|
141
|
+
error: {
|
|
142
|
+
type: SyncBlockError.InvalidContent
|
|
143
|
+
},
|
|
140
144
|
resourceId: blockContentResponse.blockAri
|
|
141
145
|
};
|
|
142
146
|
}
|
|
143
147
|
});
|
|
144
148
|
const errorInstances = (errors || []).map(errorBlock => ({
|
|
145
|
-
error:
|
|
149
|
+
error: {
|
|
150
|
+
type: SyncBlockError.Errored
|
|
151
|
+
},
|
|
146
152
|
resourceId: errorBlock.blockAri
|
|
147
153
|
}));
|
|
148
154
|
return [...blocksInstances, ...errorInstances];
|
|
@@ -174,7 +180,10 @@ class BlockServiceADFFetchProvider {
|
|
|
174
180
|
const value = blockContentResponse.content;
|
|
175
181
|
if (!value) {
|
|
176
182
|
return {
|
|
177
|
-
error:
|
|
183
|
+
error: {
|
|
184
|
+
type: SyncBlockError.NotFound,
|
|
185
|
+
reason: blockContentResponse.deletionReason
|
|
186
|
+
},
|
|
178
187
|
resourceId
|
|
179
188
|
};
|
|
180
189
|
}
|
|
@@ -190,19 +199,24 @@ class BlockServiceADFFetchProvider {
|
|
|
190
199
|
contentUpdatedAt: convertContentUpdatedAt(blockContentResponse.contentUpdatedAt),
|
|
191
200
|
sourceAri: blockContentResponse.sourceAri,
|
|
192
201
|
product: blockContentResponse.product,
|
|
193
|
-
status: blockContentResponse.status
|
|
202
|
+
status: blockContentResponse.status,
|
|
203
|
+
deletionReason: blockContentResponse.deletionReason
|
|
194
204
|
},
|
|
195
205
|
resourceId
|
|
196
206
|
};
|
|
197
207
|
} catch (error) {
|
|
198
208
|
if (error instanceof BlockError) {
|
|
199
209
|
return {
|
|
200
|
-
error:
|
|
210
|
+
error: {
|
|
211
|
+
type: mapBlockError(error)
|
|
212
|
+
},
|
|
201
213
|
resourceId
|
|
202
214
|
};
|
|
203
215
|
}
|
|
204
216
|
return {
|
|
205
|
-
error:
|
|
217
|
+
error: {
|
|
218
|
+
type: SyncBlockError.Errored
|
|
219
|
+
},
|
|
206
220
|
resourceId
|
|
207
221
|
};
|
|
208
222
|
}
|
|
@@ -279,7 +293,9 @@ class BlockServiceADFFetchProvider {
|
|
|
279
293
|
const processedResourceIds = new Set();
|
|
280
294
|
if (!this.parentAri) {
|
|
281
295
|
return blockNodeIdentifiers.map(blockNodeIdentifier => ({
|
|
282
|
-
error:
|
|
296
|
+
error: {
|
|
297
|
+
type: SyncBlockError.Errored
|
|
298
|
+
},
|
|
283
299
|
resourceId: blockNodeIdentifier.resourceId
|
|
284
300
|
}));
|
|
285
301
|
}
|
|
@@ -302,7 +318,10 @@ class BlockServiceADFFetchProvider {
|
|
|
302
318
|
const value = blockContentResponse.content;
|
|
303
319
|
if (!value) {
|
|
304
320
|
results.push({
|
|
305
|
-
error:
|
|
321
|
+
error: {
|
|
322
|
+
type: SyncBlockError.NotFound,
|
|
323
|
+
reason: blockContentResponse.deletionReason
|
|
324
|
+
},
|
|
306
325
|
resourceId
|
|
307
326
|
});
|
|
308
327
|
continue;
|
|
@@ -317,13 +336,16 @@ class BlockServiceADFFetchProvider {
|
|
|
317
336
|
blockInstanceId: blockContentResponse.blockInstanceId,
|
|
318
337
|
sourceAri: blockContentResponse.sourceAri,
|
|
319
338
|
product: blockContentResponse.product,
|
|
320
|
-
status: blockContentResponse.status
|
|
339
|
+
status: blockContentResponse.status,
|
|
340
|
+
deletionReason: blockContentResponse.deletionReason
|
|
321
341
|
},
|
|
322
342
|
resourceId
|
|
323
343
|
});
|
|
324
344
|
} catch {
|
|
325
345
|
results.push({
|
|
326
|
-
error:
|
|
346
|
+
error: {
|
|
347
|
+
type: SyncBlockError.Errored
|
|
348
|
+
},
|
|
327
349
|
resourceId
|
|
328
350
|
});
|
|
329
351
|
}
|
|
@@ -340,7 +362,9 @@ class BlockServiceADFFetchProvider {
|
|
|
340
362
|
}
|
|
341
363
|
processedResourceIds.add(resourceId);
|
|
342
364
|
results.push({
|
|
343
|
-
error:
|
|
365
|
+
error: {
|
|
366
|
+
type: mapErrorResponseCode(errorResponse.code)
|
|
367
|
+
},
|
|
344
368
|
resourceId
|
|
345
369
|
});
|
|
346
370
|
}
|
|
@@ -350,7 +374,9 @@ class BlockServiceADFFetchProvider {
|
|
|
350
374
|
for (const blockNodeIdentifier of blockNodeIdentifiers) {
|
|
351
375
|
if (!processedResourceIds.has(blockNodeIdentifier.resourceId)) {
|
|
352
376
|
results.push({
|
|
353
|
-
error:
|
|
377
|
+
error: {
|
|
378
|
+
type: SyncBlockError.NotFound
|
|
379
|
+
},
|
|
354
380
|
resourceId: blockNodeIdentifier.resourceId
|
|
355
381
|
});
|
|
356
382
|
}
|
|
@@ -359,7 +385,9 @@ class BlockServiceADFFetchProvider {
|
|
|
359
385
|
} catch (error) {
|
|
360
386
|
// If batch request fails, return error for all resourceIds
|
|
361
387
|
return blockNodeIdentifiers.map(blockNodeIdentifier => ({
|
|
362
|
-
error:
|
|
388
|
+
error: {
|
|
389
|
+
type: error instanceof BlockError ? mapBlockError(error) : SyncBlockError.Errored
|
|
390
|
+
},
|
|
363
391
|
resourceId: blockNodeIdentifier.resourceId
|
|
364
392
|
}));
|
|
365
393
|
}
|
|
@@ -498,7 +526,7 @@ class BlockServiceADFWriteProvider {
|
|
|
498
526
|
}
|
|
499
527
|
|
|
500
528
|
// soft deletes the source synced block
|
|
501
|
-
async deleteData(resourceId) {
|
|
529
|
+
async deleteData(resourceId, deleteReason) {
|
|
502
530
|
if (!this.parentId) {
|
|
503
531
|
return {
|
|
504
532
|
resourceId,
|
|
@@ -514,7 +542,8 @@ class BlockServiceADFWriteProvider {
|
|
|
514
542
|
});
|
|
515
543
|
try {
|
|
516
544
|
await deleteSyncedBlock({
|
|
517
|
-
blockAri
|
|
545
|
+
blockAri,
|
|
546
|
+
deleteReason
|
|
518
547
|
});
|
|
519
548
|
return {
|
|
520
549
|
resourceId,
|
|
@@ -74,7 +74,9 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
74
74
|
return data;
|
|
75
75
|
}, () => {
|
|
76
76
|
return {
|
|
77
|
-
error:
|
|
77
|
+
error: {
|
|
78
|
+
type: SyncBlockError.Errored
|
|
79
|
+
},
|
|
78
80
|
resourceId: blockIdentifier.resourceId
|
|
79
81
|
};
|
|
80
82
|
});
|
|
@@ -90,7 +92,9 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
90
92
|
return data;
|
|
91
93
|
}, () => {
|
|
92
94
|
return {
|
|
93
|
-
error:
|
|
95
|
+
error: {
|
|
96
|
+
type: SyncBlockError.Errored
|
|
97
|
+
},
|
|
94
98
|
resourceId: blockIdentifier.resourceId
|
|
95
99
|
};
|
|
96
100
|
});
|
|
@@ -151,7 +155,7 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
151
155
|
*
|
|
152
156
|
* @returns Array of {resourceId?: string, error?: string}.
|
|
153
157
|
*/
|
|
154
|
-
async deleteNodesData(resourceIds) {
|
|
158
|
+
async deleteNodesData(resourceIds, deletionReason) {
|
|
155
159
|
if (!this.writeProvider) {
|
|
156
160
|
return Promise.reject(new Error('Write provider not set'));
|
|
157
161
|
}
|
|
@@ -159,7 +163,7 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
159
163
|
if (!this.writeProvider) {
|
|
160
164
|
return Promise.reject('Write provider not set');
|
|
161
165
|
}
|
|
162
|
-
return this.writeProvider.deleteData(resourceId);
|
|
166
|
+
return this.writeProvider.deleteData(resourceId, deletionReason);
|
|
163
167
|
}));
|
|
164
168
|
return results.map((result, index) => {
|
|
165
169
|
if (result.status === 'fulfilled') {
|
|
@@ -372,11 +372,12 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
372
372
|
// Don't fetch for not_found error since the source is already deleted
|
|
373
373
|
const nodesToFetch = [];
|
|
374
374
|
syncBlockNodes.forEach(node => {
|
|
375
|
+
var _existingSyncBlock$er;
|
|
375
376
|
if (this.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
|
|
376
377
|
return;
|
|
377
378
|
}
|
|
378
379
|
const existingSyncBlock = this.getFromCache(node.attrs.resourceId);
|
|
379
|
-
if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : existingSyncBlock.error) === SyncBlockError.NotFound) {
|
|
380
|
+
if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : (_existingSyncBlock$er = existingSyncBlock.error) === null || _existingSyncBlock$er === void 0 ? void 0 : _existingSyncBlock$er.type) === SyncBlockError.NotFound) {
|
|
380
381
|
return;
|
|
381
382
|
}
|
|
382
383
|
nodesToFetch.push(node);
|
|
@@ -403,8 +404,8 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
403
404
|
let hasExpectedError = false;
|
|
404
405
|
data.forEach(syncBlockInstance => {
|
|
405
406
|
if (!syncBlockInstance.resourceId) {
|
|
406
|
-
var _this$fireAnalyticsEv9;
|
|
407
|
-
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, fetchErrorPayload(syncBlockInstance.error || 'Returned sync block instance does not have resource id'));
|
|
407
|
+
var _this$fireAnalyticsEv9, _syncBlockInstance$er;
|
|
408
|
+
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, fetchErrorPayload(((_syncBlockInstance$er = syncBlockInstance.error) === null || _syncBlockInstance$er === void 0 ? void 0 : _syncBlockInstance$er.type) || 'Returned sync block instance does not have resource id'));
|
|
408
409
|
return;
|
|
409
410
|
}
|
|
410
411
|
const existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
|
|
@@ -412,8 +413,8 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
412
413
|
this.updateCache(resolvedSyncBlockInstance);
|
|
413
414
|
if (syncBlockInstance.error) {
|
|
414
415
|
var _this$fireAnalyticsEv0;
|
|
415
|
-
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, fetchErrorPayload(syncBlockInstance.error, syncBlockInstance.resourceId));
|
|
416
|
-
if (syncBlockInstance.error === SyncBlockError.NotFound || syncBlockInstance.error === SyncBlockError.Forbidden) {
|
|
416
|
+
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, fetchErrorPayload(syncBlockInstance.error.type, syncBlockInstance.resourceId));
|
|
417
|
+
if (syncBlockInstance.error.type === SyncBlockError.NotFound || syncBlockInstance.error.type === SyncBlockError.Forbidden) {
|
|
417
418
|
hasExpectedError = true;
|
|
418
419
|
} else if (syncBlockInstance.error) {
|
|
419
420
|
hasUnexpectedError = true;
|
|
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
3
3
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
4
|
import { SyncBlockError } from '../common/types';
|
|
5
|
-
import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload, getSourceInfoErrorPayload, updateSuccessPayload, createSuccessPayload, deleteSuccessPayload } from '../utils/errorHandling';
|
|
5
|
+
import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload, getSourceInfoErrorPayload, updateSuccessPayload, createSuccessPayload, deleteSuccessPayload, fetchReferencesErrorPayload } from '../utils/errorHandling';
|
|
6
6
|
import { getCreateSourceExperience, getDeleteSourceExperience, getSaveSourceExperience } from '../utils/experienceTracking';
|
|
7
7
|
import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
|
|
8
8
|
// A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
|
|
@@ -103,7 +103,6 @@ export class SourceSyncBlockStoreManager {
|
|
|
103
103
|
var _this$saveExperience;
|
|
104
104
|
(_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 ? void 0 : _this$saveExperience.start({});
|
|
105
105
|
}
|
|
106
|
-
;
|
|
107
106
|
const writeResults = await this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
|
|
108
107
|
writeResults.forEach(result => {
|
|
109
108
|
// set isDirty to true for cases where it failed to save the sync block to the BE
|
|
@@ -125,7 +124,6 @@ export class SourceSyncBlockStoreManager {
|
|
|
125
124
|
}
|
|
126
125
|
});
|
|
127
126
|
}
|
|
128
|
-
;
|
|
129
127
|
return true;
|
|
130
128
|
} else {
|
|
131
129
|
if (fg('platform_synced_block_dogfooding')) {
|
|
@@ -275,7 +273,7 @@ export class SourceSyncBlockStoreManager {
|
|
|
275
273
|
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, createErrorPayload(error.message));
|
|
276
274
|
}
|
|
277
275
|
}
|
|
278
|
-
async delete(syncBlockIds, onDelete, onDeleteCompleted) {
|
|
276
|
+
async delete(syncBlockIds, onDelete, onDeleteCompleted, reason) {
|
|
279
277
|
try {
|
|
280
278
|
if (!this.dataProvider) {
|
|
281
279
|
throw new Error('Data provider not set');
|
|
@@ -287,7 +285,7 @@ export class SourceSyncBlockStoreManager {
|
|
|
287
285
|
var _this$deleteExperienc;
|
|
288
286
|
(_this$deleteExperienc = this.deleteExperience) === null || _this$deleteExperienc === void 0 ? void 0 : _this$deleteExperienc.start({});
|
|
289
287
|
}
|
|
290
|
-
const results = await this.dataProvider.deleteNodesData(syncBlockIds.map(attrs => attrs.resourceId));
|
|
288
|
+
const results = await this.dataProvider.deleteNodesData(syncBlockIds.map(attrs => attrs.resourceId), reason);
|
|
291
289
|
let callback;
|
|
292
290
|
const isDeleteSuccessful = results.every(result => result.success);
|
|
293
291
|
onDeleteCompleted(isDeleteSuccessful);
|
|
@@ -351,10 +349,11 @@ export class SourceSyncBlockStoreManager {
|
|
|
351
349
|
const {
|
|
352
350
|
syncBlockIds,
|
|
353
351
|
onDelete,
|
|
354
|
-
onDeleteCompleted
|
|
352
|
+
onDeleteCompleted,
|
|
353
|
+
deletionReason
|
|
355
354
|
} = this.deletionRetryInfo;
|
|
356
355
|
if (this.confirmationCallback) {
|
|
357
|
-
await this.delete(syncBlockIds, onDelete, onDeleteCompleted);
|
|
356
|
+
await this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
|
|
358
357
|
}
|
|
359
358
|
}
|
|
360
359
|
clearPendingDeletion() {
|
|
@@ -370,18 +369,19 @@ export class SourceSyncBlockStoreManager {
|
|
|
370
369
|
* @param onDeleteCompleted - The callback for after the deletion is saved to BE (whether successful or not)
|
|
371
370
|
* @param destroyCallback - The callback to clear any reference stored for deletion (regardless if deletion is completed or abort)
|
|
372
371
|
*/
|
|
373
|
-
async deleteSyncBlocksWithConfirmation(syncBlockIds, onDelete, onDeleteCompleted, destroyCallback) {
|
|
372
|
+
async deleteSyncBlocksWithConfirmation(syncBlockIds, deletionReason, onDelete, onDeleteCompleted, destroyCallback) {
|
|
374
373
|
if (this.confirmationCallback) {
|
|
375
|
-
const confirmed = await this.confirmationCallback(syncBlockIds
|
|
374
|
+
const confirmed = await this.confirmationCallback(syncBlockIds, deletionReason);
|
|
376
375
|
if (confirmed) {
|
|
377
|
-
const isDeleteSuccessful = await this.delete(syncBlockIds, onDelete, onDeleteCompleted);
|
|
376
|
+
const isDeleteSuccessful = await this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
|
|
378
377
|
if (!isDeleteSuccessful) {
|
|
379
378
|
// If deletion failed, save deletion info for potential retry
|
|
380
379
|
this.deletionRetryInfo = {
|
|
381
380
|
syncBlockIds,
|
|
382
381
|
onDelete,
|
|
383
382
|
onDeleteCompleted,
|
|
384
|
-
destroyCallback
|
|
383
|
+
destroyCallback,
|
|
384
|
+
deletionReason
|
|
385
385
|
};
|
|
386
386
|
} else {
|
|
387
387
|
destroyCallback();
|
|
@@ -406,6 +406,23 @@ export class SourceSyncBlockStoreManager {
|
|
|
406
406
|
return Promise.resolve(undefined);
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
|
+
fetchReferences(resourceId) {
|
|
410
|
+
try {
|
|
411
|
+
if (!this.dataProvider) {
|
|
412
|
+
throw new Error('Data provider not set');
|
|
413
|
+
}
|
|
414
|
+
return this.dataProvider.fetchReferences(resourceId, true);
|
|
415
|
+
} catch (error) {
|
|
416
|
+
var _this$fireAnalyticsEv14;
|
|
417
|
+
logException(error, {
|
|
418
|
+
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
419
|
+
});
|
|
420
|
+
(_this$fireAnalyticsEv14 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv14 === void 0 ? void 0 : _this$fireAnalyticsEv14.call(this, fetchReferencesErrorPayload(error.message));
|
|
421
|
+
return Promise.resolve({
|
|
422
|
+
error: SyncBlockError.Errored
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
}
|
|
409
426
|
destroy() {
|
|
410
427
|
var _this$saveExperience4, _this$createExperienc5, _this$deleteExperienc4;
|
|
411
428
|
this.syncBlockCache.clear();
|
|
@@ -41,7 +41,7 @@ export class SyncBlockStoreManager {
|
|
|
41
41
|
}
|
|
42
42
|
const sourceInfoPromises = response.references.map(async reference => {
|
|
43
43
|
var _this$dataProvider;
|
|
44
|
-
const sourceInfo = await ((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, reference.documentAri, getProductFromSourceAri(reference.documentAri), this.fireAnalyticsEvent, reference.hasAccess, 'view'));
|
|
44
|
+
const sourceInfo = await ((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(reference.blockInstanceId || '', reference.documentAri, getProductFromSourceAri(reference.documentAri), this.fireAnalyticsEvent, reference.hasAccess, 'view'));
|
|
45
45
|
if (!sourceInfo) {
|
|
46
46
|
return undefined;
|
|
47
47
|
}
|
|
@@ -16,8 +16,9 @@ export const resolveSyncBlockInstance = (oldResult, newResult) => {
|
|
|
16
16
|
if (!oldResult.data) {
|
|
17
17
|
return newResult;
|
|
18
18
|
} else if (!newResult.data) {
|
|
19
|
+
var _newResult$error, _newResult$error2;
|
|
19
20
|
// return the old result if there was an error, e.g. network error, but not if not found or forbidden
|
|
20
|
-
if (newResult.error === SyncBlockError.NotFound || newResult.error === SyncBlockError.Forbidden) {
|
|
21
|
+
if (((_newResult$error = newResult.error) === null || _newResult$error === void 0 ? void 0 : _newResult$error.type) === SyncBlockError.NotFound || ((_newResult$error2 = newResult.error) === null || _newResult$error2 === void 0 ? void 0 : _newResult$error2.type) === SyncBlockError.Forbidden) {
|
|
21
22
|
return newResult;
|
|
22
23
|
} else {
|
|
23
24
|
return oldResult;
|
|
@@ -8,6 +8,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
8
8
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
9
9
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
10
10
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
11
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
11
12
|
import { fetchWithRetry } from '../../utils/retry';
|
|
12
13
|
export var isBlockContentResponse = function isBlockContentResponse(response) {
|
|
13
14
|
var content = response.content;
|
|
@@ -218,24 +219,25 @@ export var batchRetrieveSyncedBlocks = /*#__PURE__*/function () {
|
|
|
218
219
|
}();
|
|
219
220
|
export var deleteSyncedBlock = /*#__PURE__*/function () {
|
|
220
221
|
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref6) {
|
|
221
|
-
var blockAri, response;
|
|
222
|
+
var blockAri, deleteReason, url, response;
|
|
222
223
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
223
224
|
while (1) switch (_context4.prev = _context4.next) {
|
|
224
225
|
case 0:
|
|
225
|
-
blockAri = _ref6.blockAri;
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
blockAri = _ref6.blockAri, deleteReason = _ref6.deleteReason;
|
|
227
|
+
url = deleteReason && fg('platform_synced_block_dogfooding') ? "".concat(BLOCK_SERVICE_API_URL, "/block/").concat(encodeURIComponent(blockAri), "?deletionReason=").concat(encodeURIComponent(deleteReason)) : "".concat(BLOCK_SERVICE_API_URL, "/block/").concat(encodeURIComponent(blockAri));
|
|
228
|
+
_context4.next = 4;
|
|
229
|
+
return fetchWithRetry(url, {
|
|
228
230
|
method: 'DELETE',
|
|
229
231
|
headers: COMMON_HEADERS
|
|
230
232
|
});
|
|
231
|
-
case
|
|
233
|
+
case 4:
|
|
232
234
|
response = _context4.sent;
|
|
233
235
|
if (response.ok) {
|
|
234
|
-
_context4.next =
|
|
236
|
+
_context4.next = 7;
|
|
235
237
|
break;
|
|
236
238
|
}
|
|
237
239
|
throw new BlockError(response.status);
|
|
238
|
-
case
|
|
240
|
+
case 7:
|
|
239
241
|
case "end":
|
|
240
242
|
return _context4.stop();
|
|
241
243
|
}
|
|
@@ -83,7 +83,9 @@ export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, resou
|
|
|
83
83
|
setFetchState({
|
|
84
84
|
syncBlockInstance: {
|
|
85
85
|
resourceId: resourceId || '',
|
|
86
|
-
error:
|
|
86
|
+
error: {
|
|
87
|
+
type: SyncBlockError.Errored
|
|
88
|
+
}
|
|
87
89
|
},
|
|
88
90
|
isLoading: false
|
|
89
91
|
});
|
|
@@ -147,7 +147,9 @@ export var fetchReferences = /*#__PURE__*/function () {
|
|
|
147
147
|
if (!resourceId) {
|
|
148
148
|
// could not extract resourceId from blockAri, return InvalidContent error
|
|
149
149
|
return {
|
|
150
|
-
error:
|
|
150
|
+
error: {
|
|
151
|
+
type: SyncBlockError.InvalidContent
|
|
152
|
+
},
|
|
151
153
|
resourceId: blockContentResponse.blockAri
|
|
152
154
|
};
|
|
153
155
|
}
|
|
@@ -158,14 +160,18 @@ export var fetchReferences = /*#__PURE__*/function () {
|
|
|
158
160
|
} catch (_unused2) {
|
|
159
161
|
// JSON parsing error, return InvalidContent error
|
|
160
162
|
return {
|
|
161
|
-
error:
|
|
163
|
+
error: {
|
|
164
|
+
type: SyncBlockError.InvalidContent
|
|
165
|
+
},
|
|
162
166
|
resourceId: blockContentResponse.blockAri
|
|
163
167
|
};
|
|
164
168
|
}
|
|
165
169
|
});
|
|
166
170
|
errorInstances = (errors || []).map(function (errorBlock) {
|
|
167
171
|
return {
|
|
168
|
-
error:
|
|
172
|
+
error: {
|
|
173
|
+
type: SyncBlockError.Errored
|
|
174
|
+
},
|
|
169
175
|
resourceId: errorBlock.blockAri
|
|
170
176
|
};
|
|
171
177
|
});
|
|
@@ -220,7 +226,10 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
220
226
|
break;
|
|
221
227
|
}
|
|
222
228
|
return _context2.abrupt("return", {
|
|
223
|
-
error:
|
|
229
|
+
error: {
|
|
230
|
+
type: SyncBlockError.NotFound,
|
|
231
|
+
reason: blockContentResponse.deletionReason
|
|
232
|
+
},
|
|
224
233
|
resourceId: resourceId
|
|
225
234
|
});
|
|
226
235
|
case 8:
|
|
@@ -235,7 +244,8 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
235
244
|
contentUpdatedAt: convertContentUpdatedAt(blockContentResponse.contentUpdatedAt),
|
|
236
245
|
sourceAri: blockContentResponse.sourceAri,
|
|
237
246
|
product: blockContentResponse.product,
|
|
238
|
-
status: blockContentResponse.status
|
|
247
|
+
status: blockContentResponse.status,
|
|
248
|
+
deletionReason: blockContentResponse.deletionReason
|
|
239
249
|
},
|
|
240
250
|
resourceId: resourceId
|
|
241
251
|
});
|
|
@@ -247,12 +257,16 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
247
257
|
break;
|
|
248
258
|
}
|
|
249
259
|
return _context2.abrupt("return", {
|
|
250
|
-
error:
|
|
260
|
+
error: {
|
|
261
|
+
type: mapBlockError(_context2.t0)
|
|
262
|
+
},
|
|
251
263
|
resourceId: resourceId
|
|
252
264
|
});
|
|
253
265
|
case 16:
|
|
254
266
|
return _context2.abrupt("return", {
|
|
255
|
-
error:
|
|
267
|
+
error: {
|
|
268
|
+
type: SyncBlockError.Errored
|
|
269
|
+
},
|
|
256
270
|
resourceId: resourceId
|
|
257
271
|
});
|
|
258
272
|
case 17:
|
|
@@ -375,7 +389,9 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
375
389
|
}
|
|
376
390
|
return _context4.abrupt("return", blockNodeIdentifiers.map(function (blockNodeIdentifier) {
|
|
377
391
|
return {
|
|
378
|
-
error:
|
|
392
|
+
error: {
|
|
393
|
+
type: SyncBlockError.Errored
|
|
394
|
+
},
|
|
379
395
|
resourceId: blockNodeIdentifier.resourceId
|
|
380
396
|
};
|
|
381
397
|
}));
|
|
@@ -417,7 +433,10 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
417
433
|
break;
|
|
418
434
|
}
|
|
419
435
|
results.push({
|
|
420
|
-
error:
|
|
436
|
+
error: {
|
|
437
|
+
type: SyncBlockError.NotFound,
|
|
438
|
+
reason: blockContentResponse.deletionReason
|
|
439
|
+
},
|
|
421
440
|
resourceId: resourceId
|
|
422
441
|
});
|
|
423
442
|
return _context4.abrupt("continue", 25);
|
|
@@ -432,13 +451,16 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
432
451
|
blockInstanceId: blockContentResponse.blockInstanceId,
|
|
433
452
|
sourceAri: blockContentResponse.sourceAri,
|
|
434
453
|
product: blockContentResponse.product,
|
|
435
|
-
status: blockContentResponse.status
|
|
454
|
+
status: blockContentResponse.status,
|
|
455
|
+
deletionReason: blockContentResponse.deletionReason
|
|
436
456
|
},
|
|
437
457
|
resourceId: resourceId
|
|
438
458
|
});
|
|
439
459
|
} catch (_unused3) {
|
|
440
460
|
results.push({
|
|
441
|
-
error:
|
|
461
|
+
error: {
|
|
462
|
+
type: SyncBlockError.Errored
|
|
463
|
+
},
|
|
442
464
|
resourceId: resourceId
|
|
443
465
|
});
|
|
444
466
|
}
|
|
@@ -480,7 +502,9 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
480
502
|
case 44:
|
|
481
503
|
processedResourceIds.add(_resourceId);
|
|
482
504
|
results.push({
|
|
483
|
-
error:
|
|
505
|
+
error: {
|
|
506
|
+
type: mapErrorResponseCode(errorResponse.code)
|
|
507
|
+
},
|
|
484
508
|
resourceId: _resourceId
|
|
485
509
|
});
|
|
486
510
|
case 46:
|
|
@@ -505,7 +529,9 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
505
529
|
blockNodeIdentifier = _step3.value;
|
|
506
530
|
if (!processedResourceIds.has(blockNodeIdentifier.resourceId)) {
|
|
507
531
|
results.push({
|
|
508
|
-
error:
|
|
532
|
+
error: {
|
|
533
|
+
type: SyncBlockError.NotFound
|
|
534
|
+
},
|
|
509
535
|
resourceId: blockNodeIdentifier.resourceId
|
|
510
536
|
});
|
|
511
537
|
}
|
|
@@ -521,7 +547,9 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
521
547
|
_context4.t2 = _context4["catch"](5);
|
|
522
548
|
return _context4.abrupt("return", blockNodeIdentifiers.map(function (blockNodeIdentifier) {
|
|
523
549
|
return {
|
|
524
|
-
error:
|
|
550
|
+
error: {
|
|
551
|
+
type: _context4.t2 instanceof BlockError ? mapBlockError(_context4.t2) : SyncBlockError.Errored
|
|
552
|
+
},
|
|
525
553
|
resourceId: blockNodeIdentifier.resourceId
|
|
526
554
|
};
|
|
527
555
|
}));
|
|
@@ -721,7 +749,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
721
749
|
}, {
|
|
722
750
|
key: "deleteData",
|
|
723
751
|
value: function () {
|
|
724
|
-
var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(resourceId) {
|
|
752
|
+
var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(resourceId, deleteReason) {
|
|
725
753
|
var blockAri;
|
|
726
754
|
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
727
755
|
while (1) switch (_context7.prev = _context7.next) {
|
|
@@ -745,7 +773,8 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
745
773
|
_context7.prev = 3;
|
|
746
774
|
_context7.next = 6;
|
|
747
775
|
return deleteSyncedBlock({
|
|
748
|
-
blockAri: blockAri
|
|
776
|
+
blockAri: blockAri,
|
|
777
|
+
deleteReason: deleteReason
|
|
749
778
|
});
|
|
750
779
|
case 6:
|
|
751
780
|
return _context7.abrupt("return", {
|
|
@@ -786,7 +815,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
786
815
|
}
|
|
787
816
|
}, _callee7, this, [[3, 9]]);
|
|
788
817
|
}));
|
|
789
|
-
function deleteData(_x7) {
|
|
818
|
+
function deleteData(_x7, _x8) {
|
|
790
819
|
return _deleteData.apply(this, arguments);
|
|
791
820
|
}
|
|
792
821
|
return deleteData;
|
|
@@ -859,7 +888,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
859
888
|
}
|
|
860
889
|
}, _callee8, this, [[2, 8]]);
|
|
861
890
|
}));
|
|
862
|
-
function updateReferenceData(
|
|
891
|
+
function updateReferenceData(_x9, _x0) {
|
|
863
892
|
return _updateReferenceData.apply(this, arguments);
|
|
864
893
|
}
|
|
865
894
|
return updateReferenceData;
|
|
@@ -114,7 +114,9 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
114
114
|
return data;
|
|
115
115
|
}, function () {
|
|
116
116
|
return {
|
|
117
|
-
error:
|
|
117
|
+
error: {
|
|
118
|
+
type: SyncBlockError.Errored
|
|
119
|
+
},
|
|
118
120
|
resourceId: blockIdentifier.resourceId
|
|
119
121
|
};
|
|
120
122
|
});
|
|
@@ -134,7 +136,9 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
134
136
|
return data;
|
|
135
137
|
}, function () {
|
|
136
138
|
return {
|
|
137
|
-
error:
|
|
139
|
+
error: {
|
|
140
|
+
type: SyncBlockError.Errored
|
|
141
|
+
},
|
|
138
142
|
resourceId: blockIdentifier.resourceId
|
|
139
143
|
};
|
|
140
144
|
});
|
|
@@ -239,7 +243,7 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
239
243
|
}, {
|
|
240
244
|
key: "deleteNodesData",
|
|
241
245
|
value: (function () {
|
|
242
|
-
var _deleteNodesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resourceIds) {
|
|
246
|
+
var _deleteNodesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resourceIds, deletionReason) {
|
|
243
247
|
var _this4 = this;
|
|
244
248
|
var results;
|
|
245
249
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
@@ -256,7 +260,7 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
256
260
|
if (!_this4.writeProvider) {
|
|
257
261
|
return Promise.reject('Write provider not set');
|
|
258
262
|
}
|
|
259
|
-
return _this4.writeProvider.deleteData(resourceId);
|
|
263
|
+
return _this4.writeProvider.deleteData(resourceId, deletionReason);
|
|
260
264
|
}));
|
|
261
265
|
case 4:
|
|
262
266
|
results = _context3.sent;
|
|
@@ -277,7 +281,7 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
277
281
|
}
|
|
278
282
|
}, _callee3, this);
|
|
279
283
|
}));
|
|
280
|
-
function deleteNodesData(_x4) {
|
|
284
|
+
function deleteNodesData(_x4, _x5) {
|
|
281
285
|
return _deleteNodesData.apply(this, arguments);
|
|
282
286
|
}
|
|
283
287
|
return deleteNodesData;
|
|
@@ -375,7 +379,7 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
|
375
379
|
}
|
|
376
380
|
}, _callee4, this);
|
|
377
381
|
}));
|
|
378
|
-
function fetchSyncBlockSourceInfo(
|
|
382
|
+
function fetchSyncBlockSourceInfo(_x6, _x7, _x8, _x9) {
|
|
379
383
|
return _fetchSyncBlockSourceInfo.apply(this, arguments);
|
|
380
384
|
}
|
|
381
385
|
return fetchSyncBlockSourceInfo;
|