@atlaskit/editor-synced-block-provider 3.14.1 → 3.14.3
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 +22 -0
- package/dist/cjs/clients/block-service/blockService.js +21 -16
- package/dist/cjs/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/cjs/providers/block-service/blockServiceAPI.js +75 -36
- package/dist/cjs/providers/syncBlockProvider.js +10 -6
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +65 -26
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +68 -28
- package/dist/cjs/store-manager/syncBlockStoreManager.js +54 -23
- package/dist/cjs/utils/experienceTracking.js +18 -1
- package/dist/cjs/utils/resolveSyncBlockInstance.js +2 -1
- package/dist/es2019/clients/block-service/blockService.js +10 -3
- package/dist/es2019/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/es2019/providers/block-service/blockServiceAPI.js +62 -23
- package/dist/es2019/providers/syncBlockProvider.js +8 -4
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +71 -36
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +55 -17
- package/dist/es2019/store-manager/syncBlockStoreManager.js +37 -3
- package/dist/es2019/utils/experienceTracking.js +17 -0
- package/dist/es2019/utils/resolveSyncBlockInstance.js +2 -1
- package/dist/esm/clients/block-service/blockService.js +21 -16
- package/dist/esm/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/esm/providers/block-service/blockServiceAPI.js +75 -36
- package/dist/esm/providers/syncBlockProvider.js +10 -6
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +65 -26
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +70 -30
- package/dist/esm/store-manager/syncBlockStoreManager.js +54 -23
- package/dist/esm/utils/experienceTracking.js +17 -0
- package/dist/esm/utils/resolveSyncBlockInstance.js +2 -1
- package/dist/types/clients/block-service/blockService.d.ts +7 -4
- 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 +6 -3
- package/dist/types/providers/syncBlockProvider.d.ts +2 -2
- package/dist/types/providers/types.d.ts +8 -4
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +9 -0
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +5 -3
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +2 -0
- package/dist/types/utils/experienceTracking.d.ts +8 -0
- package/dist/types-ts4.5/clients/block-service/blockService.d.ts +7 -4
- 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 +6 -3
- 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/referenceSyncBlockStoreManager.d.ts +9 -0
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +5 -3
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +2 -0
- package/dist/types-ts4.5/utils/experienceTracking.d.ts +8 -0
- package/package.json +2 -2
|
@@ -12,9 +12,11 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
12
12
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
13
|
var _react = require("react");
|
|
14
14
|
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
15
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
15
16
|
var _ari = require("../clients/block-service/ari");
|
|
16
17
|
var _types = require("../common/types");
|
|
17
18
|
var _errorHandling = require("../utils/errorHandling");
|
|
19
|
+
var _experienceTracking = require("../utils/experienceTracking");
|
|
18
20
|
var _referenceSyncBlockStoreManager = require("./referenceSyncBlockStoreManager");
|
|
19
21
|
var _sourceSyncBlockStoreManager = require("./sourceSyncBlockStoreManager");
|
|
20
22
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -38,7 +40,7 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
38
40
|
value: function () {
|
|
39
41
|
var _fetchReferencesSourceInfo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resourceId, blockInstanceId, isSourceSyncBlock) {
|
|
40
42
|
var _this = this;
|
|
41
|
-
var _response$references, response, sourceInfoPromises, sourceInfos, sourceSyncBlockData, _this$fireAnalyticsEv;
|
|
43
|
+
var _this$fetchReferences, _response$references, _this$fetchReferences5, response, _this$fetchReferences2, _this$fetchReferences3, _this$fetchReferences4, sourceInfoPromises, sourceInfos, sourceSyncBlockData, _this$fireAnalyticsEv;
|
|
42
44
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
43
45
|
while (1) switch (_context2.prev = _context2.next) {
|
|
44
46
|
case 0:
|
|
@@ -49,51 +51,69 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
49
51
|
}
|
|
50
52
|
throw new Error('Data provider not set');
|
|
51
53
|
case 3:
|
|
52
|
-
|
|
54
|
+
(_this$fetchReferences = this.fetchReferencesExperience) === null || _this$fetchReferences === void 0 || _this$fetchReferences.start();
|
|
55
|
+
_context2.next = 6;
|
|
53
56
|
return this.dataProvider.fetchReferences(resourceId, isSourceSyncBlock);
|
|
54
|
-
case
|
|
57
|
+
case 6:
|
|
55
58
|
response = _context2.sent;
|
|
56
59
|
if (!response.error) {
|
|
57
|
-
_context2.next =
|
|
60
|
+
_context2.next = 10;
|
|
58
61
|
break;
|
|
59
62
|
}
|
|
63
|
+
(_this$fetchReferences2 = this.fetchReferencesExperience) === null || _this$fetchReferences2 === void 0 || _this$fetchReferences2.failure({
|
|
64
|
+
reason: response.error
|
|
65
|
+
});
|
|
60
66
|
return _context2.abrupt("return", {
|
|
61
67
|
error: response.error
|
|
62
68
|
});
|
|
63
|
-
case
|
|
69
|
+
case 10:
|
|
64
70
|
if (!(!response.references || ((_response$references = response.references) === null || _response$references === void 0 ? void 0 : _response$references.length) === 0)) {
|
|
65
|
-
_context2.next =
|
|
71
|
+
_context2.next = 13;
|
|
66
72
|
break;
|
|
67
73
|
}
|
|
74
|
+
// No reference found
|
|
75
|
+
if (isSourceSyncBlock) {
|
|
76
|
+
(_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 || _this$fetchReferences3.success();
|
|
77
|
+
} else {
|
|
78
|
+
(_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 || _this$fetchReferences4.failure({
|
|
79
|
+
reason: 'No references found for reference synced block'
|
|
80
|
+
});
|
|
81
|
+
}
|
|
68
82
|
return _context2.abrupt("return", isSourceSyncBlock ? {
|
|
69
83
|
references: []
|
|
70
84
|
} : {
|
|
71
85
|
error: _types.SyncBlockError.Errored
|
|
72
86
|
});
|
|
73
|
-
case
|
|
87
|
+
case 13:
|
|
88
|
+
(_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.success();
|
|
74
89
|
sourceInfoPromises = response.references.map( /*#__PURE__*/function () {
|
|
75
90
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(reference) {
|
|
76
|
-
var _this$dataProvider;
|
|
77
|
-
var sourceInfo;
|
|
91
|
+
var _this$fetchSourceInfo, _this$dataProvider, _this$fetchSourceInfo3;
|
|
92
|
+
var sourceInfo, _this$fetchSourceInfo2;
|
|
78
93
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
79
94
|
while (1) switch (_context.prev = _context.next) {
|
|
80
95
|
case 0:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
(_this$fetchSourceInfo = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.start();
|
|
97
|
+
_context.next = 3;
|
|
98
|
+
return (_this$dataProvider = _this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(reference.blockInstanceId || '', reference.documentAri, (0, _ari.getProductFromSourceAri)(reference.documentAri), _this.fireAnalyticsEvent, reference.hasAccess, 'view');
|
|
99
|
+
case 3:
|
|
84
100
|
sourceInfo = _context.sent;
|
|
85
101
|
if (sourceInfo) {
|
|
86
|
-
_context.next =
|
|
102
|
+
_context.next = 7;
|
|
87
103
|
break;
|
|
88
104
|
}
|
|
105
|
+
(_this$fetchSourceInfo2 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.failure({
|
|
106
|
+
reason: "no source info returned for ari: ".concat(reference.documentAri)
|
|
107
|
+
});
|
|
89
108
|
return _context.abrupt("return", undefined);
|
|
90
|
-
case
|
|
109
|
+
case 7:
|
|
110
|
+
(_this$fetchSourceInfo3 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 || _this$fetchSourceInfo3.success();
|
|
91
111
|
return _context.abrupt("return", _objectSpread(_objectSpread({}, sourceInfo), {}, {
|
|
92
112
|
onSameDocument: reference.onSameDocument,
|
|
93
113
|
hasAccess: reference.hasAccess,
|
|
94
114
|
productType: sourceInfo.productType
|
|
95
115
|
}));
|
|
96
|
-
case
|
|
116
|
+
case 9:
|
|
97
117
|
case "end":
|
|
98
118
|
return _context.stop();
|
|
99
119
|
}
|
|
@@ -103,13 +123,13 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
103
123
|
return _ref.apply(this, arguments);
|
|
104
124
|
};
|
|
105
125
|
}());
|
|
106
|
-
_context2.next =
|
|
126
|
+
_context2.next = 17;
|
|
107
127
|
return Promise.all(sourceInfoPromises);
|
|
108
|
-
case
|
|
128
|
+
case 17:
|
|
109
129
|
sourceInfos = _context2.sent;
|
|
110
|
-
_context2.next =
|
|
130
|
+
_context2.next = 20;
|
|
111
131
|
return isSourceSyncBlock ? this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId) : this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
|
|
112
|
-
case
|
|
132
|
+
case 20:
|
|
113
133
|
sourceSyncBlockData = _context2.sent;
|
|
114
134
|
if (sourceSyncBlockData) {
|
|
115
135
|
sourceInfos.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
|
|
@@ -122,8 +142,8 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
122
142
|
return _context2.abrupt("return", {
|
|
123
143
|
references: sourceInfos
|
|
124
144
|
});
|
|
125
|
-
case
|
|
126
|
-
_context2.prev =
|
|
145
|
+
case 25:
|
|
146
|
+
_context2.prev = 25;
|
|
127
147
|
_context2.t0 = _context2["catch"](0);
|
|
128
148
|
(0, _monitoring.logException)(_context2.t0, {
|
|
129
149
|
location: 'editor-synced-block-provider/syncBlockStoreManager'
|
|
@@ -132,11 +152,11 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
132
152
|
return _context2.abrupt("return", {
|
|
133
153
|
error: _types.SyncBlockError.Errored
|
|
134
154
|
});
|
|
135
|
-
case
|
|
155
|
+
case 30:
|
|
136
156
|
case "end":
|
|
137
157
|
return _context2.stop();
|
|
138
158
|
}
|
|
139
|
-
}, _callee2, this, [[0,
|
|
159
|
+
}, _callee2, this, [[0, 25]]);
|
|
140
160
|
}));
|
|
141
161
|
function fetchReferencesSourceInfo(_x, _x2, _x3) {
|
|
142
162
|
return _fetchReferencesSourceInfo.apply(this, arguments);
|
|
@@ -149,6 +169,10 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
149
169
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
150
170
|
this.referenceSyncBlockStoreManager.setFireAnalyticsEvent(fireAnalyticsEvent);
|
|
151
171
|
this.sourceSyncBlockStoreManager.setFireAnalyticsEvent(fireAnalyticsEvent);
|
|
172
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
|
|
173
|
+
this.fetchReferencesExperience = (0, _experienceTracking.getFetchReferencesExperience)(fireAnalyticsEvent);
|
|
174
|
+
this.fetchSourceInfoExperience = (0, _experienceTracking.getFetchSourceInfoExperience)(fireAnalyticsEvent);
|
|
175
|
+
}
|
|
152
176
|
}
|
|
153
177
|
}, {
|
|
154
178
|
key: "referenceManager",
|
|
@@ -163,8 +187,15 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
163
187
|
}, {
|
|
164
188
|
key: "destroy",
|
|
165
189
|
value: function destroy() {
|
|
190
|
+
var _this$fetchReferences6, _this$fetchSourceInfo4;
|
|
166
191
|
this.referenceSyncBlockStoreManager.destroy();
|
|
167
192
|
this.sourceSyncBlockStoreManager.destroy();
|
|
193
|
+
(_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.abort({
|
|
194
|
+
reason: 'editorDestroyed'
|
|
195
|
+
});
|
|
196
|
+
(_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 || _this$fetchSourceInfo4.abort({
|
|
197
|
+
reason: 'editorDestroyed'
|
|
198
|
+
});
|
|
168
199
|
}
|
|
169
200
|
}]);
|
|
170
201
|
}();
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getSaveSourceExperience = exports.getSaveReferenceExperience = exports.getFetchSourceInfoExperience = exports.getFetchExperience = exports.getDeleteSourceExperience = exports.getCreateSourceExperience = exports.createExperienceDispatcher = void 0;
|
|
6
|
+
exports.getSaveSourceExperience = exports.getSaveReferenceExperience = exports.getFetchSourceInfoExperience = exports.getFetchReferencesExperience = exports.getFetchExperience = exports.getDeleteSourceExperience = exports.getCreateSourceExperience = exports.createExperienceDispatcher = void 0;
|
|
7
7
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
8
|
var _experiences = require("@atlaskit/editor-common/experiences");
|
|
9
9
|
var TIMEOUT_DURATION = 30000;
|
|
@@ -116,4 +116,21 @@ var getCreateSourceExperience = exports.getCreateSourceExperience = function get
|
|
|
116
116
|
durationMs: TIMEOUT_DURATION
|
|
117
117
|
})]
|
|
118
118
|
});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* This experience tracks when a source sync block is created and registered to the BE.
|
|
123
|
+
*
|
|
124
|
+
* Start: When the fetchSourceInfo function is called.
|
|
125
|
+
* Success: When the fetching the data is successful within the timeout duration of start.
|
|
126
|
+
* Failure: When the timeout duration passes without the data being successfully fetched, or the fetch fails
|
|
127
|
+
*/
|
|
128
|
+
var getFetchReferencesExperience = exports.getFetchReferencesExperience = function getFetchReferencesExperience(fireAnalyticsEvent) {
|
|
129
|
+
return new _experiences.Experience(_experiences.EXPERIENCE_ID.ASYNC_OPERATION, {
|
|
130
|
+
action: _analytics.ACTION.SYNCED_BLOCK_FETCH_REFERENCES,
|
|
131
|
+
dispatchAnalyticsEvent: createExperienceDispatcher(fireAnalyticsEvent),
|
|
132
|
+
checks: [new _experiences.ExperienceCheckTimeout({
|
|
133
|
+
durationMs: TIMEOUT_DURATION
|
|
134
|
+
})]
|
|
135
|
+
});
|
|
119
136
|
};
|
|
@@ -26,8 +26,9 @@ var resolveSyncBlockInstance = exports.resolveSyncBlockInstance = function resol
|
|
|
26
26
|
if (!oldResult.data) {
|
|
27
27
|
return newResult;
|
|
28
28
|
} else if (!newResult.data) {
|
|
29
|
+
var _newResult$error, _newResult$error2;
|
|
29
30
|
// return the old result if there was an error, e.g. network error, but not if not found or forbidden
|
|
30
|
-
if (newResult.error === _types.SyncBlockError.NotFound || newResult.error === _types.SyncBlockError.Forbidden) {
|
|
31
|
+
if (((_newResult$error = newResult.error) === null || _newResult$error === void 0 ? void 0 : _newResult$error.type) === _types.SyncBlockError.NotFound || ((_newResult$error2 = newResult.error) === null || _newResult$error2 === void 0 ? void 0 : _newResult$error2.type) === _types.SyncBlockError.Forbidden) {
|
|
31
32
|
return newResult;
|
|
32
33
|
} else {
|
|
33
34
|
return oldResult;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
1
2
|
import { fetchWithRetry } from '../../utils/retry';
|
|
2
3
|
export const isBlockContentResponse = response => {
|
|
3
4
|
const content = response.content;
|
|
@@ -144,9 +145,11 @@ export const batchRetrieveSyncedBlocks = async ({
|
|
|
144
145
|
return await response.json();
|
|
145
146
|
};
|
|
146
147
|
export const deleteSyncedBlock = async ({
|
|
147
|
-
blockAri
|
|
148
|
+
blockAri,
|
|
149
|
+
deleteReason
|
|
148
150
|
}) => {
|
|
149
|
-
const
|
|
151
|
+
const url = deleteReason && fg('platform_synced_block_dogfooding') ? `${BLOCK_SERVICE_API_URL}/block/${encodeURIComponent(blockAri)}?deletionReason=${encodeURIComponent(deleteReason)}` : `${BLOCK_SERVICE_API_URL}/block/${encodeURIComponent(blockAri)}`;
|
|
152
|
+
const response = await fetchWithRetry(url, {
|
|
150
153
|
method: 'DELETE',
|
|
151
154
|
headers: COMMON_HEADERS
|
|
152
155
|
});
|
|
@@ -180,7 +183,8 @@ export const createSyncedBlock = async ({
|
|
|
180
183
|
sourceAri,
|
|
181
184
|
product,
|
|
182
185
|
content,
|
|
183
|
-
stepVersion
|
|
186
|
+
stepVersion,
|
|
187
|
+
status
|
|
184
188
|
}) => {
|
|
185
189
|
const requestBody = {
|
|
186
190
|
blockAri,
|
|
@@ -192,6 +196,9 @@ export const createSyncedBlock = async ({
|
|
|
192
196
|
if (stepVersion !== undefined) {
|
|
193
197
|
requestBody.stepVersion = stepVersion;
|
|
194
198
|
}
|
|
199
|
+
if (status !== undefined && fg('platform_synced_block_dogfooding')) {
|
|
200
|
+
requestBody.status = status;
|
|
201
|
+
}
|
|
195
202
|
const response = await fetchWithRetry(`${BLOCK_SERVICE_API_URL}/block`, {
|
|
196
203
|
method: 'POST',
|
|
197
204
|
headers: COMMON_HEADERS,
|
|
@@ -59,7 +59,9 @@ export const useFetchSyncBlockData = (manager, resourceId, localId, fireAnalytic
|
|
|
59
59
|
setFetchState({
|
|
60
60
|
syncBlockInstance: {
|
|
61
61
|
resourceId: resourceId || '',
|
|
62
|
-
error:
|
|
62
|
+
error: {
|
|
63
|
+
type: SyncBlockError.Errored
|
|
64
|
+
}
|
|
63
65
|
},
|
|
64
66
|
isLoading: false
|
|
65
67
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
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
5
|
import { batchRetrieveSyncedBlocks, BlockError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getReferenceSyncedBlocksByBlockAri, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock } from '../../clients/block-service/blockService';
|
|
5
6
|
import { subscribeToBlockUpdates as subscribeToBlockUpdatesWS } from '../../clients/block-service/blockSubscription';
|
|
@@ -125,7 +126,9 @@ export const fetchReferences = async documentAri => {
|
|
|
125
126
|
if (!resourceId) {
|
|
126
127
|
// could not extract resourceId from blockAri, return InvalidContent error
|
|
127
128
|
return {
|
|
128
|
-
error:
|
|
129
|
+
error: {
|
|
130
|
+
type: SyncBlockError.InvalidContent
|
|
131
|
+
},
|
|
129
132
|
resourceId: blockContentResponse.blockAri
|
|
130
133
|
};
|
|
131
134
|
}
|
|
@@ -136,13 +139,17 @@ export const fetchReferences = async documentAri => {
|
|
|
136
139
|
} catch {
|
|
137
140
|
// JSON parsing error, return InvalidContent error
|
|
138
141
|
return {
|
|
139
|
-
error:
|
|
142
|
+
error: {
|
|
143
|
+
type: SyncBlockError.InvalidContent
|
|
144
|
+
},
|
|
140
145
|
resourceId: blockContentResponse.blockAri
|
|
141
146
|
};
|
|
142
147
|
}
|
|
143
148
|
});
|
|
144
149
|
const errorInstances = (errors || []).map(errorBlock => ({
|
|
145
|
-
error:
|
|
150
|
+
error: {
|
|
151
|
+
type: SyncBlockError.Errored
|
|
152
|
+
},
|
|
146
153
|
resourceId: errorBlock.blockAri
|
|
147
154
|
}));
|
|
148
155
|
return [...blocksInstances, ...errorInstances];
|
|
@@ -174,7 +181,10 @@ class BlockServiceADFFetchProvider {
|
|
|
174
181
|
const value = blockContentResponse.content;
|
|
175
182
|
if (!value) {
|
|
176
183
|
return {
|
|
177
|
-
error:
|
|
184
|
+
error: {
|
|
185
|
+
type: SyncBlockError.NotFound,
|
|
186
|
+
reason: blockContentResponse.deletionReason
|
|
187
|
+
},
|
|
178
188
|
resourceId
|
|
179
189
|
};
|
|
180
190
|
}
|
|
@@ -190,19 +200,24 @@ class BlockServiceADFFetchProvider {
|
|
|
190
200
|
contentUpdatedAt: convertContentUpdatedAt(blockContentResponse.contentUpdatedAt),
|
|
191
201
|
sourceAri: blockContentResponse.sourceAri,
|
|
192
202
|
product: blockContentResponse.product,
|
|
193
|
-
status: blockContentResponse.status
|
|
203
|
+
status: blockContentResponse.status,
|
|
204
|
+
deletionReason: blockContentResponse.deletionReason
|
|
194
205
|
},
|
|
195
206
|
resourceId
|
|
196
207
|
};
|
|
197
208
|
} catch (error) {
|
|
198
209
|
if (error instanceof BlockError) {
|
|
199
210
|
return {
|
|
200
|
-
error:
|
|
211
|
+
error: {
|
|
212
|
+
type: mapBlockError(error)
|
|
213
|
+
},
|
|
201
214
|
resourceId
|
|
202
215
|
};
|
|
203
216
|
}
|
|
204
217
|
return {
|
|
205
|
-
error:
|
|
218
|
+
error: {
|
|
219
|
+
type: SyncBlockError.Errored
|
|
220
|
+
},
|
|
206
221
|
resourceId
|
|
207
222
|
};
|
|
208
223
|
}
|
|
@@ -279,7 +294,9 @@ class BlockServiceADFFetchProvider {
|
|
|
279
294
|
const processedResourceIds = new Set();
|
|
280
295
|
if (!this.parentAri) {
|
|
281
296
|
return blockNodeIdentifiers.map(blockNodeIdentifier => ({
|
|
282
|
-
error:
|
|
297
|
+
error: {
|
|
298
|
+
type: SyncBlockError.Errored
|
|
299
|
+
},
|
|
283
300
|
resourceId: blockNodeIdentifier.resourceId
|
|
284
301
|
}));
|
|
285
302
|
}
|
|
@@ -302,7 +319,10 @@ class BlockServiceADFFetchProvider {
|
|
|
302
319
|
const value = blockContentResponse.content;
|
|
303
320
|
if (!value) {
|
|
304
321
|
results.push({
|
|
305
|
-
error:
|
|
322
|
+
error: {
|
|
323
|
+
type: SyncBlockError.NotFound,
|
|
324
|
+
reason: blockContentResponse.deletionReason
|
|
325
|
+
},
|
|
306
326
|
resourceId
|
|
307
327
|
});
|
|
308
328
|
continue;
|
|
@@ -317,13 +337,16 @@ class BlockServiceADFFetchProvider {
|
|
|
317
337
|
blockInstanceId: blockContentResponse.blockInstanceId,
|
|
318
338
|
sourceAri: blockContentResponse.sourceAri,
|
|
319
339
|
product: blockContentResponse.product,
|
|
320
|
-
status: blockContentResponse.status
|
|
340
|
+
status: blockContentResponse.status,
|
|
341
|
+
deletionReason: blockContentResponse.deletionReason
|
|
321
342
|
},
|
|
322
343
|
resourceId
|
|
323
344
|
});
|
|
324
345
|
} catch {
|
|
325
346
|
results.push({
|
|
326
|
-
error:
|
|
347
|
+
error: {
|
|
348
|
+
type: SyncBlockError.Errored
|
|
349
|
+
},
|
|
327
350
|
resourceId
|
|
328
351
|
});
|
|
329
352
|
}
|
|
@@ -340,7 +363,9 @@ class BlockServiceADFFetchProvider {
|
|
|
340
363
|
}
|
|
341
364
|
processedResourceIds.add(resourceId);
|
|
342
365
|
results.push({
|
|
343
|
-
error:
|
|
366
|
+
error: {
|
|
367
|
+
type: mapErrorResponseCode(errorResponse.code)
|
|
368
|
+
},
|
|
344
369
|
resourceId
|
|
345
370
|
});
|
|
346
371
|
}
|
|
@@ -350,7 +375,9 @@ class BlockServiceADFFetchProvider {
|
|
|
350
375
|
for (const blockNodeIdentifier of blockNodeIdentifiers) {
|
|
351
376
|
if (!processedResourceIds.has(blockNodeIdentifier.resourceId)) {
|
|
352
377
|
results.push({
|
|
353
|
-
error:
|
|
378
|
+
error: {
|
|
379
|
+
type: SyncBlockError.NotFound
|
|
380
|
+
},
|
|
354
381
|
resourceId: blockNodeIdentifier.resourceId
|
|
355
382
|
});
|
|
356
383
|
}
|
|
@@ -359,7 +386,9 @@ class BlockServiceADFFetchProvider {
|
|
|
359
386
|
} catch (error) {
|
|
360
387
|
// If batch request fails, return error for all resourceIds
|
|
361
388
|
return blockNodeIdentifiers.map(blockNodeIdentifier => ({
|
|
362
|
-
error:
|
|
389
|
+
error: {
|
|
390
|
+
type: error instanceof BlockError ? mapBlockError(error) : SyncBlockError.Errored
|
|
391
|
+
},
|
|
363
392
|
resourceId: blockNodeIdentifier.resourceId
|
|
364
393
|
}));
|
|
365
394
|
}
|
|
@@ -406,13 +435,15 @@ class BlockServiceADFWriteProvider {
|
|
|
406
435
|
parentAri,
|
|
407
436
|
parentId,
|
|
408
437
|
product,
|
|
409
|
-
getVersion
|
|
438
|
+
getVersion,
|
|
439
|
+
isParentUnpublished
|
|
410
440
|
}) {
|
|
411
441
|
this.cloudId = cloudId;
|
|
412
442
|
this.parentAri = parentAri;
|
|
413
443
|
this.parentId = parentId;
|
|
414
444
|
this.product = product;
|
|
415
445
|
this.getVersion = getVersion;
|
|
446
|
+
this.isParentUnpublished = isParentUnpublished;
|
|
416
447
|
}
|
|
417
448
|
|
|
418
449
|
// it will first try to update and if it can't (404) then it will try to create
|
|
@@ -456,6 +487,7 @@ class BlockServiceADFWriteProvider {
|
|
|
456
487
|
}
|
|
457
488
|
}
|
|
458
489
|
async createData(data) {
|
|
490
|
+
var _this$isParentUnpubli;
|
|
459
491
|
if (!this.parentAri || !this.parentId) {
|
|
460
492
|
return {
|
|
461
493
|
error: SyncBlockError.Errored
|
|
@@ -471,6 +503,7 @@ class BlockServiceADFWriteProvider {
|
|
|
471
503
|
resourceId
|
|
472
504
|
});
|
|
473
505
|
const stepVersion = this.getVersion ? this.getVersion() : undefined;
|
|
506
|
+
const status = fg('platform_synced_block_dogfooding') ? (_this$isParentUnpubli = this.isParentUnpublished) !== null && _this$isParentUnpubli !== void 0 && _this$isParentUnpubli.call(this) ? 'unpublished' : data.status || 'active' : undefined;
|
|
474
507
|
try {
|
|
475
508
|
await createSyncedBlock({
|
|
476
509
|
blockAri,
|
|
@@ -478,7 +511,8 @@ class BlockServiceADFWriteProvider {
|
|
|
478
511
|
sourceAri: this.parentAri,
|
|
479
512
|
product: this.product,
|
|
480
513
|
content: JSON.stringify(data.content),
|
|
481
|
-
stepVersion
|
|
514
|
+
stepVersion,
|
|
515
|
+
status
|
|
482
516
|
});
|
|
483
517
|
return {
|
|
484
518
|
resourceId
|
|
@@ -498,7 +532,7 @@ class BlockServiceADFWriteProvider {
|
|
|
498
532
|
}
|
|
499
533
|
|
|
500
534
|
// soft deletes the source synced block
|
|
501
|
-
async deleteData(resourceId) {
|
|
535
|
+
async deleteData(resourceId, deleteReason) {
|
|
502
536
|
if (!this.parentId) {
|
|
503
537
|
return {
|
|
504
538
|
resourceId,
|
|
@@ -514,7 +548,8 @@ class BlockServiceADFWriteProvider {
|
|
|
514
548
|
});
|
|
515
549
|
try {
|
|
516
550
|
await deleteSyncedBlock({
|
|
517
|
-
blockAri
|
|
551
|
+
blockAri,
|
|
552
|
+
deleteReason
|
|
518
553
|
});
|
|
519
554
|
return {
|
|
520
555
|
resourceId,
|
|
@@ -593,7 +628,8 @@ const createBlockServiceAPIProviders = ({
|
|
|
593
628
|
parentAri,
|
|
594
629
|
parentId,
|
|
595
630
|
product,
|
|
596
|
-
getVersion
|
|
631
|
+
getVersion,
|
|
632
|
+
isParentUnpublished
|
|
597
633
|
}) => {
|
|
598
634
|
return {
|
|
599
635
|
fetchProvider: new BlockServiceADFFetchProvider({
|
|
@@ -605,7 +641,8 @@ const createBlockServiceAPIProviders = ({
|
|
|
605
641
|
parentAri,
|
|
606
642
|
parentId,
|
|
607
643
|
product,
|
|
608
|
-
getVersion
|
|
644
|
+
getVersion,
|
|
645
|
+
isParentUnpublished
|
|
609
646
|
})
|
|
610
647
|
};
|
|
611
648
|
};
|
|
@@ -614,7 +651,8 @@ export const useMemoizedBlockServiceAPIProviders = ({
|
|
|
614
651
|
parentAri,
|
|
615
652
|
parentId,
|
|
616
653
|
product,
|
|
617
|
-
getVersion
|
|
654
|
+
getVersion,
|
|
655
|
+
isParentUnpublished
|
|
618
656
|
}) => {
|
|
619
657
|
return useMemo(() => {
|
|
620
658
|
return createBlockServiceAPIProviders({
|
|
@@ -622,9 +660,10 @@ export const useMemoizedBlockServiceAPIProviders = ({
|
|
|
622
660
|
parentAri,
|
|
623
661
|
parentId,
|
|
624
662
|
product,
|
|
625
|
-
getVersion
|
|
663
|
+
getVersion,
|
|
664
|
+
isParentUnpublished
|
|
626
665
|
});
|
|
627
|
-
}, [cloudId, parentAri, parentId, product, getVersion]);
|
|
666
|
+
}, [cloudId, parentAri, parentId, product, getVersion, isParentUnpublished]);
|
|
628
667
|
};
|
|
629
668
|
const createBlockServiceFetchOnlyAPIProvider = ({
|
|
630
669
|
cloudId,
|
|
@@ -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') {
|