@atlaskit/editor-synced-block-provider 3.14.2 → 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 +11 -0
- package/dist/cjs/clients/block-service/blockService.js +12 -9
- package/dist/cjs/providers/block-service/blockServiceAPI.js +28 -18
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +61 -23
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +27 -5
- package/dist/cjs/store-manager/syncBlockStoreManager.js +53 -22
- package/dist/cjs/utils/experienceTracking.js +18 -1
- package/dist/es2019/clients/block-service/blockService.js +5 -1
- package/dist/es2019/providers/block-service/blockServiceAPI.js +17 -7
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +68 -34
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +27 -6
- package/dist/es2019/store-manager/syncBlockStoreManager.js +36 -2
- package/dist/es2019/utils/experienceTracking.js +17 -0
- package/dist/esm/clients/block-service/blockService.js +12 -9
- package/dist/esm/providers/block-service/blockServiceAPI.js +28 -18
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +61 -23
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +28 -6
- package/dist/esm/store-manager/syncBlockStoreManager.js +53 -22
- package/dist/esm/utils/experienceTracking.js +17 -0
- package/dist/types/clients/block-service/blockService.d.ts +3 -2
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +5 -2
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +9 -0
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +1 -0
- 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 +3 -2
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +5 -2
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +9 -0
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +1 -0
- 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
|
-
|
|
96
|
+
(_this$fetchSourceInfo = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.start();
|
|
97
|
+
_context.next = 3;
|
|
82
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');
|
|
83
|
-
case
|
|
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
|
};
|
|
@@ -183,7 +183,8 @@ export const createSyncedBlock = async ({
|
|
|
183
183
|
sourceAri,
|
|
184
184
|
product,
|
|
185
185
|
content,
|
|
186
|
-
stepVersion
|
|
186
|
+
stepVersion,
|
|
187
|
+
status
|
|
187
188
|
}) => {
|
|
188
189
|
const requestBody = {
|
|
189
190
|
blockAri,
|
|
@@ -195,6 +196,9 @@ export const createSyncedBlock = async ({
|
|
|
195
196
|
if (stepVersion !== undefined) {
|
|
196
197
|
requestBody.stepVersion = stepVersion;
|
|
197
198
|
}
|
|
199
|
+
if (status !== undefined && fg('platform_synced_block_dogfooding')) {
|
|
200
|
+
requestBody.status = status;
|
|
201
|
+
}
|
|
198
202
|
const response = await fetchWithRetry(`${BLOCK_SERVICE_API_URL}/block`, {
|
|
199
203
|
method: 'POST',
|
|
200
204
|
headers: COMMON_HEADERS,
|
|
@@ -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';
|
|
@@ -434,13 +435,15 @@ class BlockServiceADFWriteProvider {
|
|
|
434
435
|
parentAri,
|
|
435
436
|
parentId,
|
|
436
437
|
product,
|
|
437
|
-
getVersion
|
|
438
|
+
getVersion,
|
|
439
|
+
isParentUnpublished
|
|
438
440
|
}) {
|
|
439
441
|
this.cloudId = cloudId;
|
|
440
442
|
this.parentAri = parentAri;
|
|
441
443
|
this.parentId = parentId;
|
|
442
444
|
this.product = product;
|
|
443
445
|
this.getVersion = getVersion;
|
|
446
|
+
this.isParentUnpublished = isParentUnpublished;
|
|
444
447
|
}
|
|
445
448
|
|
|
446
449
|
// it will first try to update and if it can't (404) then it will try to create
|
|
@@ -484,6 +487,7 @@ class BlockServiceADFWriteProvider {
|
|
|
484
487
|
}
|
|
485
488
|
}
|
|
486
489
|
async createData(data) {
|
|
490
|
+
var _this$isParentUnpubli;
|
|
487
491
|
if (!this.parentAri || !this.parentId) {
|
|
488
492
|
return {
|
|
489
493
|
error: SyncBlockError.Errored
|
|
@@ -499,6 +503,7 @@ class BlockServiceADFWriteProvider {
|
|
|
499
503
|
resourceId
|
|
500
504
|
});
|
|
501
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;
|
|
502
507
|
try {
|
|
503
508
|
await createSyncedBlock({
|
|
504
509
|
blockAri,
|
|
@@ -506,7 +511,8 @@ class BlockServiceADFWriteProvider {
|
|
|
506
511
|
sourceAri: this.parentAri,
|
|
507
512
|
product: this.product,
|
|
508
513
|
content: JSON.stringify(data.content),
|
|
509
|
-
stepVersion
|
|
514
|
+
stepVersion,
|
|
515
|
+
status
|
|
510
516
|
});
|
|
511
517
|
return {
|
|
512
518
|
resourceId
|
|
@@ -622,7 +628,8 @@ const createBlockServiceAPIProviders = ({
|
|
|
622
628
|
parentAri,
|
|
623
629
|
parentId,
|
|
624
630
|
product,
|
|
625
|
-
getVersion
|
|
631
|
+
getVersion,
|
|
632
|
+
isParentUnpublished
|
|
626
633
|
}) => {
|
|
627
634
|
return {
|
|
628
635
|
fetchProvider: new BlockServiceADFFetchProvider({
|
|
@@ -634,7 +641,8 @@ const createBlockServiceAPIProviders = ({
|
|
|
634
641
|
parentAri,
|
|
635
642
|
parentId,
|
|
636
643
|
product,
|
|
637
|
-
getVersion
|
|
644
|
+
getVersion,
|
|
645
|
+
isParentUnpublished
|
|
638
646
|
})
|
|
639
647
|
};
|
|
640
648
|
};
|
|
@@ -643,7 +651,8 @@ export const useMemoizedBlockServiceAPIProviders = ({
|
|
|
643
651
|
parentAri,
|
|
644
652
|
parentId,
|
|
645
653
|
product,
|
|
646
|
-
getVersion
|
|
654
|
+
getVersion,
|
|
655
|
+
isParentUnpublished
|
|
647
656
|
}) => {
|
|
648
657
|
return useMemo(() => {
|
|
649
658
|
return createBlockServiceAPIProviders({
|
|
@@ -651,9 +660,10 @@ export const useMemoizedBlockServiceAPIProviders = ({
|
|
|
651
660
|
parentAri,
|
|
652
661
|
parentId,
|
|
653
662
|
product,
|
|
654
|
-
getVersion
|
|
663
|
+
getVersion,
|
|
664
|
+
isParentUnpublished
|
|
655
665
|
});
|
|
656
|
-
}, [cloudId, parentAri, parentId, product, getVersion]);
|
|
666
|
+
}, [cloudId, parentAri, parentId, product, getVersion, isParentUnpublished]);
|
|
657
667
|
};
|
|
658
668
|
const createBlockServiceFetchOnlyAPIProvider = ({
|
|
659
669
|
cloudId,
|
|
@@ -17,6 +17,10 @@ import { createSyncBlockNode } from '../utils/utils';
|
|
|
17
17
|
export class ReferenceSyncBlockStoreManager {
|
|
18
18
|
// Listeners for subscription changes (used by React components to know when to update)
|
|
19
19
|
|
|
20
|
+
// Track newly added sync blocks (resourceIds that were just subscribed to without cached data)
|
|
21
|
+
|
|
22
|
+
// Callback to notify when an unpublished sync block is detected
|
|
23
|
+
|
|
20
24
|
constructor(dataProvider) {
|
|
21
25
|
// Keeps track of addition and deletion of reference synced blocks on the document
|
|
22
26
|
// This starts as true to always flush the cache when document is saved for the first time
|
|
@@ -36,6 +40,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
36
40
|
this.pendingCacheDeletions = new Map();
|
|
37
41
|
this.graphqlSubscriptions = new Map();
|
|
38
42
|
this.subscriptionChangeListeners = new Set();
|
|
43
|
+
this.newlyAddedSyncBlocks = new Set();
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
/**
|
|
@@ -124,6 +129,18 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
124
129
|
this.fetchSourceInfoExperience = getFetchSourceInfoExperience(fireAnalyticsEvent);
|
|
125
130
|
this.saveExperience = getSaveReferenceExperience(fireAnalyticsEvent);
|
|
126
131
|
}
|
|
132
|
+
setOnUnpublishedSyncBlockDetected(callback) {
|
|
133
|
+
this.onUnpublishedSyncBlockDetected = callback;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Mark a sync block as newly added to the document.
|
|
138
|
+
* This should be called when a sync block node is added via a transaction.
|
|
139
|
+
* @param resourceId - The resource ID of the newly added sync block
|
|
140
|
+
*/
|
|
141
|
+
markAsNewlyAdded(resourceId) {
|
|
142
|
+
this.newlyAddedSyncBlocks.add(resourceId);
|
|
143
|
+
}
|
|
127
144
|
generateResourceIdForReference(sourceId) {
|
|
128
145
|
if (!this.dataProvider) {
|
|
129
146
|
throw new Error('Data provider not set');
|
|
@@ -208,13 +225,18 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
208
225
|
*/
|
|
209
226
|
handleGraphQLSubscriptionUpdate(syncBlockInstance) {
|
|
210
227
|
if (!syncBlockInstance.resourceId) {
|
|
211
|
-
|
|
228
|
+
throw new Error('Sync block instance provided to graphql subscription update missing resource id');
|
|
212
229
|
}
|
|
213
230
|
const existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
|
|
214
231
|
const resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
|
|
215
232
|
this.updateCache(resolvedSyncBlockInstance);
|
|
216
233
|
if (!syncBlockInstance.error) {
|
|
234
|
+
var _this$fireAnalyticsEv4, _syncBlockInstance$da, _syncBlockInstance$da2;
|
|
235
|
+
(_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 ? void 0 : _this$fireAnalyticsEv4.call(this, fetchSuccessPayload(syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.resourceId, syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.blockInstanceId, syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.product));
|
|
217
236
|
this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
237
|
+
} else {
|
|
238
|
+
var _this$fireAnalyticsEv5, _syncBlockInstance$er;
|
|
239
|
+
(_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 ? void 0 : _this$fireAnalyticsEv5.call(this, fetchErrorPayload((_syncBlockInstance$er = syncBlockInstance.error) === null || _syncBlockInstance$er === void 0 ? void 0 : _syncBlockInstance$er.type, syncBlockInstance.resourceId));
|
|
218
240
|
}
|
|
219
241
|
}
|
|
220
242
|
|
|
@@ -290,8 +312,8 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
290
312
|
}
|
|
291
313
|
}
|
|
292
314
|
if (!sourceAri || !product || !blockInstanceId) {
|
|
293
|
-
var _this$
|
|
294
|
-
(_this$
|
|
315
|
+
var _this$fireAnalyticsEv6;
|
|
316
|
+
(_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing', resourceId));
|
|
295
317
|
return Promise.resolve(undefined);
|
|
296
318
|
}
|
|
297
319
|
if (fg('platform_synced_block_dogfooding')) {
|
|
@@ -301,11 +323,11 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
301
323
|
const sourceInfoPromise = this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, this.fireAnalyticsEvent).then(sourceInfo => {
|
|
302
324
|
if (!sourceInfo) {
|
|
303
325
|
if (fg('platform_synced_block_dogfooding')) {
|
|
304
|
-
var _this$fetchSourceInfo2, _this$
|
|
326
|
+
var _this$fetchSourceInfo2, _this$fireAnalyticsEv7;
|
|
305
327
|
(_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 ? void 0 : _this$fetchSourceInfo2.failure({
|
|
306
328
|
reason: 'No source info returned'
|
|
307
329
|
});
|
|
308
|
-
(_this$
|
|
330
|
+
(_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 ? void 0 : _this$fireAnalyticsEv7.call(this, getSourceInfoErrorPayload('No source info returned', resourceId));
|
|
309
331
|
}
|
|
310
332
|
return undefined;
|
|
311
333
|
}
|
|
@@ -318,23 +340,23 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
318
340
|
var _this$fetchSourceInfo3;
|
|
319
341
|
(_this$fetchSourceInfo3 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 ? void 0 : _this$fetchSourceInfo3.success();
|
|
320
342
|
} else {
|
|
321
|
-
var _this$fetchSourceInfo4, _this$
|
|
343
|
+
var _this$fetchSourceInfo4, _this$fireAnalyticsEv8;
|
|
322
344
|
(_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 ? void 0 : _this$fetchSourceInfo4.failure({
|
|
323
345
|
reason: 'Missing title or url'
|
|
324
346
|
});
|
|
325
|
-
(_this$
|
|
347
|
+
(_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 ? void 0 : _this$fireAnalyticsEv8.call(this, getSourceInfoErrorPayload('Missing title or url', resourceId));
|
|
326
348
|
}
|
|
327
349
|
return sourceInfo;
|
|
328
350
|
}
|
|
329
351
|
}).catch(error => {
|
|
330
|
-
var _this$
|
|
352
|
+
var _this$fireAnalyticsEv9;
|
|
331
353
|
if (fg('platform_synced_block_dogfooding')) {
|
|
332
354
|
var _this$fetchSourceInfo5;
|
|
333
355
|
(_this$fetchSourceInfo5 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo5 === void 0 ? void 0 : _this$fetchSourceInfo5.failure({
|
|
334
356
|
reason: error.message
|
|
335
357
|
});
|
|
336
358
|
}
|
|
337
|
-
(_this$
|
|
359
|
+
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, getSourceInfoErrorPayload(error.message, resourceId));
|
|
338
360
|
return undefined;
|
|
339
361
|
}).finally(() => {
|
|
340
362
|
if (fg('platform_synced_block_dogfooding')) {
|
|
@@ -350,11 +372,11 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
350
372
|
this.syncBlockSourceInfoRequestsOld.set(resourceId, true);
|
|
351
373
|
}
|
|
352
374
|
} catch (error) {
|
|
353
|
-
var _this$
|
|
375
|
+
var _this$fireAnalyticsEv0;
|
|
354
376
|
logException(error, {
|
|
355
377
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
356
378
|
});
|
|
357
|
-
(_this$
|
|
379
|
+
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, getSourceInfoErrorPayload(error.message, resourceId));
|
|
358
380
|
}
|
|
359
381
|
return Promise.resolve(undefined);
|
|
360
382
|
}
|
|
@@ -403,17 +425,29 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
403
425
|
let hasUnexpectedError = false;
|
|
404
426
|
let hasExpectedError = false;
|
|
405
427
|
data.forEach(syncBlockInstance => {
|
|
428
|
+
var _resolvedSyncBlockIns;
|
|
406
429
|
if (!syncBlockInstance.resourceId) {
|
|
407
|
-
var _this$
|
|
408
|
-
(_this$
|
|
430
|
+
var _this$fireAnalyticsEv1, _syncBlockInstance$er2;
|
|
431
|
+
(_this$fireAnalyticsEv1 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv1 === void 0 ? void 0 : _this$fireAnalyticsEv1.call(this, fetchErrorPayload(((_syncBlockInstance$er2 = syncBlockInstance.error) === null || _syncBlockInstance$er2 === void 0 ? void 0 : _syncBlockInstance$er2.type) || 'Returned sync block instance does not have resource id'));
|
|
409
432
|
return;
|
|
410
433
|
}
|
|
411
434
|
const existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
|
|
412
435
|
const resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
|
|
413
436
|
this.updateCache(resolvedSyncBlockInstance);
|
|
437
|
+
|
|
438
|
+
// Check if this is a newly added unpublished sync block and notify
|
|
439
|
+
// Only trigger for sync blocks that were just added (not refreshed or loaded on page init)
|
|
440
|
+
if (!syncBlockInstance.error && ((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) === null || _resolvedSyncBlockIns === void 0 ? void 0 : _resolvedSyncBlockIns.status) === 'unpublished' && this.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId) && this.onUnpublishedSyncBlockDetected && fg('platform_synced_block_dogfooding')) {
|
|
441
|
+
// Remove from newly added set after checking to prevent duplicate flags
|
|
442
|
+
this.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
|
|
443
|
+
this.onUnpublishedSyncBlockDetected(resolvedSyncBlockInstance.resourceId);
|
|
444
|
+
} else if (this.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId)) {
|
|
445
|
+
// Remove from newly added set even if not unpublished (to clean up)
|
|
446
|
+
this.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
|
|
447
|
+
}
|
|
414
448
|
if (syncBlockInstance.error) {
|
|
415
|
-
var _this$
|
|
416
|
-
(_this$
|
|
449
|
+
var _this$fireAnalyticsEv10;
|
|
450
|
+
(_this$fireAnalyticsEv10 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv10 === void 0 ? void 0 : _this$fireAnalyticsEv10.call(this, fetchErrorPayload(syncBlockInstance.error.type, syncBlockInstance.resourceId));
|
|
417
451
|
if (syncBlockInstance.error.type === SyncBlockError.NotFound || syncBlockInstance.error.type === SyncBlockError.Forbidden) {
|
|
418
452
|
hasExpectedError = true;
|
|
419
453
|
} else if (syncBlockInstance.error) {
|
|
@@ -421,8 +455,8 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
421
455
|
}
|
|
422
456
|
return;
|
|
423
457
|
} else if (fg('platform_synced_block_dogfooding')) {
|
|
424
|
-
var _this$
|
|
425
|
-
(_this$
|
|
458
|
+
var _this$fireAnalyticsEv11, _syncBlockInstance$da3, _syncBlockInstance$da4;
|
|
459
|
+
(_this$fireAnalyticsEv11 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv11 === void 0 ? void 0 : _this$fireAnalyticsEv11.call(this, fetchSuccessPayload(syncBlockInstance.resourceId, (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.blockInstanceId, (_syncBlockInstance$da4 = syncBlockInstance.data) === null || _syncBlockInstance$da4 === void 0 ? void 0 : _syncBlockInstance$da4.product));
|
|
426
460
|
}
|
|
427
461
|
this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
428
462
|
});
|
|
@@ -522,11 +556,11 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
522
556
|
callback(cachedData);
|
|
523
557
|
} else {
|
|
524
558
|
this.fetchSyncBlocksData([syncBlockNode]).catch(error => {
|
|
525
|
-
var _this$
|
|
559
|
+
var _this$fireAnalyticsEv12;
|
|
526
560
|
logException(error, {
|
|
527
561
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
528
562
|
});
|
|
529
|
-
(_this$
|
|
563
|
+
(_this$fireAnalyticsEv12 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv12 === void 0 ? void 0 : _this$fireAnalyticsEv12.call(this, fetchErrorPayload(error.message, resourceId));
|
|
530
564
|
});
|
|
531
565
|
}
|
|
532
566
|
|
|
@@ -619,11 +653,11 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
619
653
|
}
|
|
620
654
|
return this.subscribeToSyncBlock(resourceId, localId, callback);
|
|
621
655
|
} catch (error) {
|
|
622
|
-
var _this$
|
|
656
|
+
var _this$fireAnalyticsEv13;
|
|
623
657
|
logException(error, {
|
|
624
658
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
625
659
|
});
|
|
626
|
-
(_this$
|
|
660
|
+
(_this$fireAnalyticsEv13 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv13 === void 0 ? void 0 : _this$fireAnalyticsEv13.call(this, fetchErrorPayload(error.message));
|
|
627
661
|
return () => {};
|
|
628
662
|
}
|
|
629
663
|
}
|
|
@@ -643,12 +677,12 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
643
677
|
}
|
|
644
678
|
getProviderFactory(resourceId) {
|
|
645
679
|
if (!this.dataProvider) {
|
|
646
|
-
var _this$
|
|
680
|
+
var _this$fireAnalyticsEv14;
|
|
647
681
|
const error = new Error('Data provider not set');
|
|
648
682
|
logException(error, {
|
|
649
683
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
650
684
|
});
|
|
651
|
-
(_this$
|
|
685
|
+
(_this$fireAnalyticsEv14 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv14 === void 0 ? void 0 : _this$fireAnalyticsEv14.call(this, fetchErrorPayload(error.message));
|
|
652
686
|
return undefined;
|
|
653
687
|
}
|
|
654
688
|
const {
|
|
@@ -678,11 +712,11 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
678
712
|
try {
|
|
679
713
|
this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
|
|
680
714
|
} catch (error) {
|
|
681
|
-
var _this$
|
|
715
|
+
var _this$fireAnalyticsEv15;
|
|
682
716
|
logException(error, {
|
|
683
717
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
684
718
|
});
|
|
685
|
-
(_this$
|
|
719
|
+
(_this$fireAnalyticsEv15 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv15 === void 0 ? void 0 : _this$fireAnalyticsEv15.call(this, fetchErrorPayload(error.message, resourceId));
|
|
686
720
|
}
|
|
687
721
|
}
|
|
688
722
|
return providerFactory;
|
|
@@ -741,8 +775,8 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
741
775
|
return;
|
|
742
776
|
}
|
|
743
777
|
if (!syncBlock.data.sourceAri || !syncBlock.data.product) {
|
|
744
|
-
var _this$
|
|
745
|
-
(_this$
|
|
778
|
+
var _this$fireAnalyticsEv16;
|
|
779
|
+
(_this$fireAnalyticsEv16 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv16 === void 0 ? void 0 : _this$fireAnalyticsEv16.call(this, fetchErrorPayload('Sync block source ari or product not found'));
|
|
746
780
|
return;
|
|
747
781
|
}
|
|
748
782
|
const parentInfo = this.dataProvider.retrieveSyncBlockParentInfo((_syncBlock$data2 = syncBlock.data) === null || _syncBlock$data2 === void 0 ? void 0 : _syncBlock$data2.sourceAri, (_syncBlock$data3 = syncBlock.data) === null || _syncBlock$data3 === void 0 ? void 0 : _syncBlock$data3.product);
|
|
@@ -831,7 +865,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
831
865
|
}
|
|
832
866
|
const updateResult = await this.dataProvider.updateReferenceData(blocks);
|
|
833
867
|
if (!updateResult.success) {
|
|
834
|
-
var _this$
|
|
868
|
+
var _this$fireAnalyticsEv17;
|
|
835
869
|
success = false;
|
|
836
870
|
if (fg('platform_synced_block_dogfooding')) {
|
|
837
871
|
var _this$saveExperience2;
|
|
@@ -839,10 +873,10 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
839
873
|
reason: updateResult.error || 'Failed to update reference synced blocks on the document'
|
|
840
874
|
});
|
|
841
875
|
}
|
|
842
|
-
(_this$
|
|
876
|
+
(_this$fireAnalyticsEv17 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv17 === void 0 ? void 0 : _this$fireAnalyticsEv17.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
|
|
843
877
|
}
|
|
844
878
|
} catch (error) {
|
|
845
|
-
var _this$
|
|
879
|
+
var _this$fireAnalyticsEv18;
|
|
846
880
|
success = false;
|
|
847
881
|
logException(error, {
|
|
848
882
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
@@ -853,7 +887,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
853
887
|
reason: error.message
|
|
854
888
|
});
|
|
855
889
|
}
|
|
856
|
-
(_this$
|
|
890
|
+
(_this$fireAnalyticsEv18 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv18 === void 0 ? void 0 : _this$fireAnalyticsEv18.call(this, updateReferenceErrorPayload(error.message));
|
|
857
891
|
} finally {
|
|
858
892
|
if (!success) {
|
|
859
893
|
// set isCacheDirty back to true for cases where it failed to update the reference synced blocks on the BE
|
|
@@ -885,13 +919,13 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
885
919
|
});
|
|
886
920
|
this.providerFactories.clear();
|
|
887
921
|
(_this$saveExperience5 = this.saveExperience) === null || _this$saveExperience5 === void 0 ? void 0 : _this$saveExperience5.abort({
|
|
888
|
-
reason: '
|
|
922
|
+
reason: 'editorDestroyed'
|
|
889
923
|
});
|
|
890
924
|
(_this$fetchExperience5 = this.fetchExperience) === null || _this$fetchExperience5 === void 0 ? void 0 : _this$fetchExperience5.abort({
|
|
891
|
-
reason: '
|
|
925
|
+
reason: 'editorDestroyed'
|
|
892
926
|
});
|
|
893
927
|
(_this$fetchSourceInfo6 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo6 === void 0 ? void 0 : _this$fetchSourceInfo6.abort({
|
|
894
|
-
reason: '
|
|
928
|
+
reason: 'editorDestroyed'
|
|
895
929
|
});
|
|
896
930
|
this.fireAnalyticsEvent = undefined;
|
|
897
931
|
}
|