@atlaskit/editor-synced-block-provider 3.14.0 → 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 +18 -0
- package/dist/cjs/clients/block-service/blockService.js +9 -7
- package/dist/cjs/clients/block-service/blockSubscription.js +2 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/cjs/providers/block-service/blockServiceAPI.js +63 -56
- package/dist/cjs/providers/syncBlockProvider.js +10 -6
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +8 -9
- 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/cjs/utils/utils.js +12 -1
- package/dist/es2019/clients/block-service/blockService.js +5 -2
- package/dist/es2019/clients/block-service/blockSubscription.js +2 -0
- package/dist/es2019/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/es2019/providers/block-service/blockServiceAPI.js +51 -45
- package/dist/es2019/providers/syncBlockProvider.js +8 -4
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +6 -7
- 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/es2019/utils/utils.js +11 -0
- package/dist/esm/clients/block-service/blockService.js +9 -7
- package/dist/esm/clients/block-service/blockSubscription.js +2 -0
- package/dist/esm/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/esm/providers/block-service/blockServiceAPI.js +63 -56
- package/dist/esm/providers/syncBlockProvider.js +10 -6
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +8 -9
- 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/esm/utils/utils.js +11 -0
- package/dist/types/clients/block-service/blockService.d.ts +4 -2
- package/dist/types/clients/block-service/blockSubscription.d.ts +1 -0
- 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/utils/utils.d.ts +1 -0
- package/dist/types-ts4.5/clients/block-service/blockService.d.ts +4 -2
- package/dist/types-ts4.5/clients/block-service/blockSubscription.d.ts +1 -0
- 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/dist/types-ts4.5/utils/utils.d.ts +1 -0
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable require-unicode-regexp */
|
|
2
2
|
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
4
|
export const convertSyncBlockPMNodeToSyncBlockData = node => {
|
|
4
5
|
return {
|
|
5
6
|
blockInstanceId: node.attrs.localId,
|
|
@@ -47,4 +48,14 @@ export const getContentIdAndProductFromResourceId = resourceId => {
|
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
throw new Error(`Invalid resourceId: ${resourceId}`);
|
|
51
|
+
};
|
|
52
|
+
export const convertContentUpdatedAt = contentUpdatedAt => {
|
|
53
|
+
if (typeof contentUpdatedAt === 'number' && fg('platform_synced_block_dogfooding')) {
|
|
54
|
+
try {
|
|
55
|
+
return new Date(contentUpdatedAt).toISOString();
|
|
56
|
+
} catch {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
50
61
|
};
|
|
@@ -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
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createClient } from 'graphql-ws';
|
|
2
|
+
import { convertContentUpdatedAt } from '../../utils/utils';
|
|
2
3
|
var GRAPHQL_WS_ENDPOINT = '/gateway/api/graphql/subscriptions';
|
|
3
4
|
var blockServiceClient = null;
|
|
4
5
|
var getBlockServiceClient = function getBlockServiceClient() {
|
|
@@ -54,6 +55,7 @@ var parseSubscriptionPayload = function parseSubscriptionPayload(payload) {
|
|
|
54
55
|
blockAri: payload.blockAri,
|
|
55
56
|
blockInstanceId: payload.blockInstanceId,
|
|
56
57
|
content: JSON.parse(payload.content),
|
|
58
|
+
contentUpdatedAt: convertContentUpdatedAt(payload.contentUpdatedAt),
|
|
57
59
|
createdAt: createdAt,
|
|
58
60
|
createdBy: payload.createdBy,
|
|
59
61
|
product: payload.product,
|
|
@@ -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
|
});
|
|
@@ -11,13 +11,13 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
11
11
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
12
12
|
/* eslint-disable require-unicode-regexp */
|
|
13
13
|
import { useMemo } from 'react';
|
|
14
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
15
14
|
import { generateBlockAri, generateBlockAriFromReference } from '../../clients/block-service/ari';
|
|
16
15
|
import { batchRetrieveSyncedBlocks, BlockError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getReferenceSyncedBlocksByBlockAri, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock } from '../../clients/block-service/blockService';
|
|
17
16
|
import { subscribeToBlockUpdates as subscribeToBlockUpdatesWS } from '../../clients/block-service/blockSubscription';
|
|
18
17
|
import { SyncBlockError } from '../../common/types';
|
|
19
18
|
import { stringifyError } from '../../utils/errorHandling';
|
|
20
19
|
import { createResourceIdForReference } from '../../utils/resourceId';
|
|
20
|
+
import { convertContentUpdatedAt } from '../../utils/utils';
|
|
21
21
|
var mapBlockError = function mapBlockError(error) {
|
|
22
22
|
switch (error.status) {
|
|
23
23
|
case 400:
|
|
@@ -98,24 +98,16 @@ export var convertToSyncBlockData = function convertToSyncBlockData(data, resour
|
|
|
98
98
|
// BE returns microseconds, convert to milliseconds
|
|
99
99
|
// BE should fix this in the future
|
|
100
100
|
createdAt = new Date(data.createdAt / 1000).toISOString();
|
|
101
|
-
} catch (
|
|
101
|
+
} catch (_unused) {
|
|
102
102
|
// fallback to undefined
|
|
103
103
|
// as we don't want to block the whole process due to invalid date
|
|
104
104
|
createdAt = undefined;
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
var contentUpdatedAt;
|
|
108
|
-
if (typeof data.contentUpdatedAt === 'number' && fg('platform_synced_block_dogfooding')) {
|
|
109
|
-
try {
|
|
110
|
-
contentUpdatedAt = new Date(data.contentUpdatedAt).toISOString();
|
|
111
|
-
} catch (e) {
|
|
112
|
-
contentUpdatedAt = undefined;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
107
|
return {
|
|
116
108
|
blockInstanceId: data.blockInstanceId,
|
|
117
109
|
content: JSON.parse(data.content),
|
|
118
|
-
contentUpdatedAt: contentUpdatedAt,
|
|
110
|
+
contentUpdatedAt: convertContentUpdatedAt(data.contentUpdatedAt),
|
|
119
111
|
createdAt: createdAt,
|
|
120
112
|
createdBy: data.createdBy,
|
|
121
113
|
product: data.product,
|
|
@@ -155,7 +147,9 @@ export var fetchReferences = /*#__PURE__*/function () {
|
|
|
155
147
|
if (!resourceId) {
|
|
156
148
|
// could not extract resourceId from blockAri, return InvalidContent error
|
|
157
149
|
return {
|
|
158
|
-
error:
|
|
150
|
+
error: {
|
|
151
|
+
type: SyncBlockError.InvalidContent
|
|
152
|
+
},
|
|
159
153
|
resourceId: blockContentResponse.blockAri
|
|
160
154
|
};
|
|
161
155
|
}
|
|
@@ -163,17 +157,21 @@ export var fetchReferences = /*#__PURE__*/function () {
|
|
|
163
157
|
data: convertToSyncBlockData(blockContentResponse, resourceId),
|
|
164
158
|
resourceId: resourceId
|
|
165
159
|
};
|
|
166
|
-
} catch (
|
|
160
|
+
} catch (_unused2) {
|
|
167
161
|
// JSON parsing error, return InvalidContent error
|
|
168
162
|
return {
|
|
169
|
-
error:
|
|
163
|
+
error: {
|
|
164
|
+
type: SyncBlockError.InvalidContent
|
|
165
|
+
},
|
|
170
166
|
resourceId: blockContentResponse.blockAri
|
|
171
167
|
};
|
|
172
168
|
}
|
|
173
169
|
});
|
|
174
170
|
errorInstances = (errors || []).map(function (errorBlock) {
|
|
175
171
|
return {
|
|
176
|
-
error:
|
|
172
|
+
error: {
|
|
173
|
+
type: SyncBlockError.Errored
|
|
174
|
+
},
|
|
177
175
|
resourceId: errorBlock.blockAri
|
|
178
176
|
};
|
|
179
177
|
});
|
|
@@ -206,7 +204,7 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
206
204
|
key: "fetchData",
|
|
207
205
|
value: function () {
|
|
208
206
|
var _fetchData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceId) {
|
|
209
|
-
var blockAri, blockContentResponse, value, syncedBlockData
|
|
207
|
+
var blockAri, blockContentResponse, value, syncedBlockData;
|
|
210
208
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
211
209
|
while (1) switch (_context2.prev = _context2.next) {
|
|
212
210
|
case 0:
|
|
@@ -228,53 +226,54 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
228
226
|
break;
|
|
229
227
|
}
|
|
230
228
|
return _context2.abrupt("return", {
|
|
231
|
-
error:
|
|
229
|
+
error: {
|
|
230
|
+
type: SyncBlockError.NotFound,
|
|
231
|
+
reason: blockContentResponse.deletionReason
|
|
232
|
+
},
|
|
232
233
|
resourceId: resourceId
|
|
233
234
|
});
|
|
234
235
|
case 8:
|
|
235
236
|
// Parse the synced block content from the response's content
|
|
236
237
|
syncedBlockData = JSON.parse(value);
|
|
237
|
-
if (typeof blockContentResponse.contentUpdatedAt === 'number' && fg('platform_synced_block_dogfooding')) {
|
|
238
|
-
try {
|
|
239
|
-
contentUpdatedAt = new Date(blockContentResponse.contentUpdatedAt).toISOString();
|
|
240
|
-
} catch (e) {
|
|
241
|
-
contentUpdatedAt = undefined;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
238
|
return _context2.abrupt("return", {
|
|
245
239
|
data: {
|
|
246
240
|
content: syncedBlockData,
|
|
247
241
|
resourceId: blockAri,
|
|
248
242
|
blockInstanceId: blockContentResponse.blockInstanceId,
|
|
249
243
|
// this was the node's localId, but has become the resourceId.
|
|
250
|
-
contentUpdatedAt: contentUpdatedAt,
|
|
244
|
+
contentUpdatedAt: convertContentUpdatedAt(blockContentResponse.contentUpdatedAt),
|
|
251
245
|
sourceAri: blockContentResponse.sourceAri,
|
|
252
246
|
product: blockContentResponse.product,
|
|
253
|
-
status: blockContentResponse.status
|
|
247
|
+
status: blockContentResponse.status,
|
|
248
|
+
deletionReason: blockContentResponse.deletionReason
|
|
254
249
|
},
|
|
255
250
|
resourceId: resourceId
|
|
256
251
|
});
|
|
257
|
-
case
|
|
258
|
-
_context2.prev =
|
|
252
|
+
case 12:
|
|
253
|
+
_context2.prev = 12;
|
|
259
254
|
_context2.t0 = _context2["catch"](1);
|
|
260
255
|
if (!(_context2.t0 instanceof BlockError)) {
|
|
261
|
-
_context2.next =
|
|
256
|
+
_context2.next = 16;
|
|
262
257
|
break;
|
|
263
258
|
}
|
|
264
259
|
return _context2.abrupt("return", {
|
|
265
|
-
error:
|
|
260
|
+
error: {
|
|
261
|
+
type: mapBlockError(_context2.t0)
|
|
262
|
+
},
|
|
266
263
|
resourceId: resourceId
|
|
267
264
|
});
|
|
268
|
-
case
|
|
265
|
+
case 16:
|
|
269
266
|
return _context2.abrupt("return", {
|
|
270
|
-
error:
|
|
267
|
+
error: {
|
|
268
|
+
type: SyncBlockError.Errored
|
|
269
|
+
},
|
|
271
270
|
resourceId: resourceId
|
|
272
271
|
});
|
|
273
|
-
case
|
|
272
|
+
case 17:
|
|
274
273
|
case "end":
|
|
275
274
|
return _context2.stop();
|
|
276
275
|
}
|
|
277
|
-
}, _callee2, this, [[1,
|
|
276
|
+
}, _callee2, this, [[1, 12]]);
|
|
278
277
|
}));
|
|
279
278
|
function fetchData(_x2) {
|
|
280
279
|
return _fetchData.apply(this, arguments);
|
|
@@ -367,7 +366,7 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
367
366
|
value: (function () {
|
|
368
367
|
var _batchFetchData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(blockNodeIdentifiers) {
|
|
369
368
|
var _this2 = this;
|
|
370
|
-
var blockIdentifiers, validResourceIds, processedResourceIds, response, results, _iterator, _step, blockContentResponse, resourceId, value, syncedBlockData,
|
|
369
|
+
var blockIdentifiers, validResourceIds, processedResourceIds, response, results, _iterator, _step, blockContentResponse, resourceId, value, syncedBlockData, _iterator2, _step2, errorResponse, _resourceId, _iterator3, _step3, blockNodeIdentifier;
|
|
371
370
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
372
371
|
while (1) switch (_context4.prev = _context4.next) {
|
|
373
372
|
case 0:
|
|
@@ -390,7 +389,9 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
390
389
|
}
|
|
391
390
|
return _context4.abrupt("return", blockNodeIdentifiers.map(function (blockNodeIdentifier) {
|
|
392
391
|
return {
|
|
393
|
-
error:
|
|
392
|
+
error: {
|
|
393
|
+
type: SyncBlockError.Errored
|
|
394
|
+
},
|
|
394
395
|
resourceId: blockNodeIdentifier.resourceId
|
|
395
396
|
};
|
|
396
397
|
}));
|
|
@@ -432,36 +433,34 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
432
433
|
break;
|
|
433
434
|
}
|
|
434
435
|
results.push({
|
|
435
|
-
error:
|
|
436
|
+
error: {
|
|
437
|
+
type: SyncBlockError.NotFound,
|
|
438
|
+
reason: blockContentResponse.deletionReason
|
|
439
|
+
},
|
|
436
440
|
resourceId: resourceId
|
|
437
441
|
});
|
|
438
442
|
return _context4.abrupt("continue", 25);
|
|
439
443
|
case 24:
|
|
440
444
|
try {
|
|
441
445
|
syncedBlockData = JSON.parse(value);
|
|
442
|
-
contentUpdatedAt = void 0;
|
|
443
|
-
if (typeof blockContentResponse.contentUpdatedAt === 'number' && fg('platform_synced_block_dogfooding')) {
|
|
444
|
-
try {
|
|
445
|
-
contentUpdatedAt = new Date(blockContentResponse.contentUpdatedAt).toISOString();
|
|
446
|
-
} catch (e) {
|
|
447
|
-
contentUpdatedAt = undefined;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
446
|
results.push({
|
|
451
447
|
data: {
|
|
452
448
|
content: syncedBlockData,
|
|
453
449
|
resourceId: blockContentResponse.blockAri,
|
|
454
|
-
contentUpdatedAt: contentUpdatedAt,
|
|
450
|
+
contentUpdatedAt: convertContentUpdatedAt(blockContentResponse.contentUpdatedAt),
|
|
455
451
|
blockInstanceId: blockContentResponse.blockInstanceId,
|
|
456
452
|
sourceAri: blockContentResponse.sourceAri,
|
|
457
453
|
product: blockContentResponse.product,
|
|
458
|
-
status: blockContentResponse.status
|
|
454
|
+
status: blockContentResponse.status,
|
|
455
|
+
deletionReason: blockContentResponse.deletionReason
|
|
459
456
|
},
|
|
460
457
|
resourceId: resourceId
|
|
461
458
|
});
|
|
462
|
-
} catch (
|
|
459
|
+
} catch (_unused3) {
|
|
463
460
|
results.push({
|
|
464
|
-
error:
|
|
461
|
+
error: {
|
|
462
|
+
type: SyncBlockError.Errored
|
|
463
|
+
},
|
|
465
464
|
resourceId: resourceId
|
|
466
465
|
});
|
|
467
466
|
}
|
|
@@ -503,7 +502,9 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
503
502
|
case 44:
|
|
504
503
|
processedResourceIds.add(_resourceId);
|
|
505
504
|
results.push({
|
|
506
|
-
error:
|
|
505
|
+
error: {
|
|
506
|
+
type: mapErrorResponseCode(errorResponse.code)
|
|
507
|
+
},
|
|
507
508
|
resourceId: _resourceId
|
|
508
509
|
});
|
|
509
510
|
case 46:
|
|
@@ -528,7 +529,9 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
528
529
|
blockNodeIdentifier = _step3.value;
|
|
529
530
|
if (!processedResourceIds.has(blockNodeIdentifier.resourceId)) {
|
|
530
531
|
results.push({
|
|
531
|
-
error:
|
|
532
|
+
error: {
|
|
533
|
+
type: SyncBlockError.NotFound
|
|
534
|
+
},
|
|
532
535
|
resourceId: blockNodeIdentifier.resourceId
|
|
533
536
|
});
|
|
534
537
|
}
|
|
@@ -544,7 +547,9 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
544
547
|
_context4.t2 = _context4["catch"](5);
|
|
545
548
|
return _context4.abrupt("return", blockNodeIdentifiers.map(function (blockNodeIdentifier) {
|
|
546
549
|
return {
|
|
547
|
-
error:
|
|
550
|
+
error: {
|
|
551
|
+
type: _context4.t2 instanceof BlockError ? mapBlockError(_context4.t2) : SyncBlockError.Errored
|
|
552
|
+
},
|
|
548
553
|
resourceId: blockNodeIdentifier.resourceId
|
|
549
554
|
};
|
|
550
555
|
}));
|
|
@@ -584,6 +589,7 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
584
589
|
sourceAri: parsedData.sourceAri,
|
|
585
590
|
product: parsedData.product,
|
|
586
591
|
createdAt: parsedData.createdAt,
|
|
592
|
+
contentUpdatedAt: parsedData.contentUpdatedAt,
|
|
587
593
|
createdBy: parsedData.createdBy,
|
|
588
594
|
status: parsedData.status
|
|
589
595
|
},
|
|
@@ -743,7 +749,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
743
749
|
}, {
|
|
744
750
|
key: "deleteData",
|
|
745
751
|
value: function () {
|
|
746
|
-
var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(resourceId) {
|
|
752
|
+
var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(resourceId, deleteReason) {
|
|
747
753
|
var blockAri;
|
|
748
754
|
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
749
755
|
while (1) switch (_context7.prev = _context7.next) {
|
|
@@ -767,7 +773,8 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
767
773
|
_context7.prev = 3;
|
|
768
774
|
_context7.next = 6;
|
|
769
775
|
return deleteSyncedBlock({
|
|
770
|
-
blockAri: blockAri
|
|
776
|
+
blockAri: blockAri,
|
|
777
|
+
deleteReason: deleteReason
|
|
771
778
|
});
|
|
772
779
|
case 6:
|
|
773
780
|
return _context7.abrupt("return", {
|
|
@@ -808,7 +815,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
808
815
|
}
|
|
809
816
|
}, _callee7, this, [[3, 9]]);
|
|
810
817
|
}));
|
|
811
|
-
function deleteData(_x7) {
|
|
818
|
+
function deleteData(_x7, _x8) {
|
|
812
819
|
return _deleteData.apply(this, arguments);
|
|
813
820
|
}
|
|
814
821
|
return deleteData;
|
|
@@ -881,7 +888,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
881
888
|
}
|
|
882
889
|
}, _callee8, this, [[2, 8]]);
|
|
883
890
|
}));
|
|
884
|
-
function updateReferenceData(
|
|
891
|
+
function updateReferenceData(_x9, _x0) {
|
|
885
892
|
return _updateReferenceData.apply(this, arguments);
|
|
886
893
|
}
|
|
887
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;
|
|
@@ -493,7 +493,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
493
493
|
value: (function () {
|
|
494
494
|
var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockNodes) {
|
|
495
495
|
var _this5 = this;
|
|
496
|
-
var nodesToFetch, _this$fetchExperience, data,
|
|
496
|
+
var nodesToFetch, _this$fetchExperience, data, hasUnexpectedError, hasExpectedError, _this$fetchExperience2, _this$fetchExperience3, _this$fetchExperience4;
|
|
497
497
|
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
|
|
498
498
|
while (1) switch (_context3.prev = _context3.next) {
|
|
499
499
|
case 0:
|
|
@@ -506,11 +506,12 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
506
506
|
// Don't fetch for not_found error since the source is already deleted
|
|
507
507
|
nodesToFetch = [];
|
|
508
508
|
syncBlockNodes.forEach(function (node) {
|
|
509
|
+
var _existingSyncBlock$er;
|
|
509
510
|
if (_this5.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
|
|
510
511
|
return;
|
|
511
512
|
}
|
|
512
513
|
var existingSyncBlock = _this5.getFromCache(node.attrs.resourceId);
|
|
513
|
-
if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 :
|
|
514
|
+
if ((existingSyncBlock === null || existingSyncBlock === void 0 || (_existingSyncBlock$er = existingSyncBlock.error) === null || _existingSyncBlock$er === void 0 ? void 0 : _existingSyncBlock$er.type) === SyncBlockError.NotFound) {
|
|
514
515
|
return;
|
|
515
516
|
}
|
|
516
517
|
nodesToFetch.push(node);
|
|
@@ -541,23 +542,21 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
541
542
|
});
|
|
542
543
|
case 12:
|
|
543
544
|
data = _context3.sent;
|
|
544
|
-
resolvedData = [];
|
|
545
545
|
hasUnexpectedError = false;
|
|
546
546
|
hasExpectedError = false;
|
|
547
547
|
data.forEach(function (syncBlockInstance) {
|
|
548
548
|
if (!syncBlockInstance.resourceId) {
|
|
549
|
-
var _this5$fireAnalyticsE;
|
|
550
|
-
(_this5$fireAnalyticsE = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE === void 0 || _this5$fireAnalyticsE.call(_this5, fetchErrorPayload(syncBlockInstance.error || 'Returned sync block instance does not have resource id'));
|
|
549
|
+
var _this5$fireAnalyticsE, _syncBlockInstance$er;
|
|
550
|
+
(_this5$fireAnalyticsE = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE === void 0 || _this5$fireAnalyticsE.call(_this5, fetchErrorPayload(((_syncBlockInstance$er = syncBlockInstance.error) === null || _syncBlockInstance$er === void 0 ? void 0 : _syncBlockInstance$er.type) || 'Returned sync block instance does not have resource id'));
|
|
551
551
|
return;
|
|
552
552
|
}
|
|
553
553
|
var existingSyncBlock = _this5.getFromCache(syncBlockInstance.resourceId);
|
|
554
554
|
var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
|
|
555
555
|
_this5.updateCache(resolvedSyncBlockInstance);
|
|
556
|
-
resolvedData.push(resolvedSyncBlockInstance);
|
|
557
556
|
if (syncBlockInstance.error) {
|
|
558
557
|
var _this5$fireAnalyticsE2;
|
|
559
|
-
(_this5$fireAnalyticsE2 = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE2 === void 0 || _this5$fireAnalyticsE2.call(_this5, fetchErrorPayload(syncBlockInstance.error, syncBlockInstance.resourceId));
|
|
560
|
-
if (syncBlockInstance.error === SyncBlockError.NotFound || syncBlockInstance.error === SyncBlockError.Forbidden) {
|
|
558
|
+
(_this5$fireAnalyticsE2 = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE2 === void 0 || _this5$fireAnalyticsE2.call(_this5, fetchErrorPayload(syncBlockInstance.error.type, syncBlockInstance.resourceId));
|
|
559
|
+
if (syncBlockInstance.error.type === SyncBlockError.NotFound || syncBlockInstance.error.type === SyncBlockError.Forbidden) {
|
|
561
560
|
hasExpectedError = true;
|
|
562
561
|
} else if (syncBlockInstance.error) {
|
|
563
562
|
hasUnexpectedError = true;
|
|
@@ -582,7 +581,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
582
581
|
(_this$fetchExperience4 = this.fetchExperience) === null || _this$fetchExperience4 === void 0 || _this$fetchExperience4.success();
|
|
583
582
|
}
|
|
584
583
|
}
|
|
585
|
-
case
|
|
584
|
+
case 17:
|
|
586
585
|
case "end":
|
|
587
586
|
return _context3.stop();
|
|
588
587
|
}
|