@atlaskit/editor-synced-block-provider 2.12.3 → 2.13.0
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 +8 -0
- package/dist/cjs/clients/block-service/ari.js +26 -9
- package/dist/cjs/index.js +12 -6
- package/dist/cjs/providers/block-service/blockServiceAPI.js +68 -49
- package/dist/cjs/providers/confluence/confluenceContentAPI.js +6 -0
- package/dist/cjs/providers/syncBlockProvider.js +18 -8
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +8 -0
- package/dist/es2019/clients/block-service/ari.js +25 -8
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/providers/block-service/blockServiceAPI.js +32 -13
- package/dist/es2019/providers/confluence/confluenceContentAPI.js +4 -0
- package/dist/es2019/providers/syncBlockProvider.js +6 -0
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +6 -0
- package/dist/esm/clients/block-service/ari.js +25 -8
- package/dist/esm/index.js +1 -1
- package/dist/esm/providers/block-service/blockServiceAPI.js +68 -50
- package/dist/esm/providers/confluence/confluenceContentAPI.js +6 -0
- package/dist/esm/providers/syncBlockProvider.js +18 -8
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +8 -0
- package/dist/types/clients/block-service/ari.d.ts +13 -5
- package/dist/types/common/types.d.ts +3 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +6 -3
- package/dist/types/providers/confluence/confluenceContentAPI.d.ts +3 -1
- package/dist/types/providers/syncBlockProvider.d.ts +2 -0
- package/dist/types/providers/types.d.ts +7 -0
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +1 -0
- package/dist/types-ts4.5/clients/block-service/ari.d.ts +13 -5
- package/dist/types-ts4.5/common/types.d.ts +3 -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/confluence/confluenceContentAPI.d.ts +3 -1
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +2 -0
- package/dist/types-ts4.5/providers/types.d.ts +7 -0
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 2.13.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`676d28a61e356`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/676d28a61e356) -
|
|
8
|
+
Add runtime blockAri generation for endpoint calls, update resourceId generation for create
|
|
9
|
+
reference from toolbar
|
|
10
|
+
|
|
3
11
|
## 2.12.3
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -3,21 +3,38 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getLocalIdFromBlockResourceId = exports.
|
|
6
|
+
exports.getLocalIdFromBlockResourceId = exports.generateBlockAriFromReference = exports.generateBlockAri = void 0;
|
|
7
7
|
/* eslint-disable require-unicode-regexp */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Generates the block ARI from the source page ARI and the source block's resource ID.
|
|
11
|
+
* @param sourceAri - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
|
|
12
|
+
* @param resourceId - the resource ID of the block node. A randomly generated UUID
|
|
13
|
+
* @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
|
|
14
|
+
*/
|
|
15
|
+
var generateBlockAri = exports.generateBlockAri = function generateBlockAri(sourceAri, resourceId, product) {
|
|
16
|
+
var match = sourceAri.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/(\d+)/);
|
|
17
|
+
if (!(match !== null && match !== void 0 && match[1])) {
|
|
18
|
+
throw new Error("Invalid source ARI: ".concat(sourceAri));
|
|
19
|
+
}
|
|
20
|
+
var cloudId = match[1];
|
|
21
|
+
var pageId = match[3];
|
|
22
|
+
return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(product, "/").concat(pageId, "/").concat(resourceId);
|
|
23
|
+
};
|
|
24
|
+
|
|
8
25
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @returns the block ARI. E.G ari:cloud:blocks
|
|
26
|
+
*
|
|
27
|
+
* @param sourceAri - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
|
|
28
|
+
* @param resourceId - the resource ID of the reference synced block. E.G confluence-page/pageId/sourceResourceId
|
|
29
|
+
* @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
|
|
13
30
|
*/
|
|
14
|
-
var
|
|
15
|
-
var match =
|
|
31
|
+
var generateBlockAriFromReference = exports.generateBlockAriFromReference = function generateBlockAriFromReference(sourceAri, resourceId) {
|
|
32
|
+
var match = sourceAri.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/(\d+)/);
|
|
16
33
|
if (!(match !== null && match !== void 0 && match[1])) {
|
|
17
|
-
throw new Error("Invalid source ARI: ".concat(
|
|
34
|
+
throw new Error("Invalid source ARI: ".concat(sourceAri));
|
|
18
35
|
}
|
|
19
36
|
var cloudId = match[1];
|
|
20
|
-
return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(
|
|
37
|
+
return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(resourceId);
|
|
21
38
|
};
|
|
22
39
|
|
|
23
40
|
/**
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,12 +27,6 @@ Object.defineProperty(exports, "SyncedBlockProvider", {
|
|
|
27
27
|
return _syncBlockProvider.SyncBlockProvider;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
Object.defineProperty(exports, "blockResourceIdFromSourceAndLocalId", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function get() {
|
|
33
|
-
return _ari.blockResourceIdFromSourceAndLocalId;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
30
|
Object.defineProperty(exports, "convertPMNodesToSyncBlockNodes", {
|
|
37
31
|
enumerable: true,
|
|
38
32
|
get: function get() {
|
|
@@ -75,6 +69,18 @@ Object.defineProperty(exports, "fetchReferences", {
|
|
|
75
69
|
return _blockServiceAPI.fetchReferences;
|
|
76
70
|
}
|
|
77
71
|
});
|
|
72
|
+
Object.defineProperty(exports, "generateBlockAri", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function get() {
|
|
75
|
+
return _ari.generateBlockAri;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "generateBlockAriFromReference", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function get() {
|
|
81
|
+
return _ari.generateBlockAriFromReference;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
78
84
|
Object.defineProperty(exports, "getConfluencePageAri", {
|
|
79
85
|
enumerable: true,
|
|
80
86
|
get: function get() {
|
|
@@ -15,6 +15,8 @@ var _ari = require("../../clients/block-service/ari");
|
|
|
15
15
|
var _blockService = require("../../clients/block-service/blockService");
|
|
16
16
|
var _types = require("../../common/types");
|
|
17
17
|
var _errorHandling = require("../../utils/errorHandling");
|
|
18
|
+
/* eslint-disable require-unicode-regexp */
|
|
19
|
+
|
|
18
20
|
var mapBlockError = function mapBlockError(error) {
|
|
19
21
|
switch (error.status) {
|
|
20
22
|
case 400:
|
|
@@ -115,24 +117,26 @@ var fetchReferences = exports.fetchReferences = /*#__PURE__*/function () {
|
|
|
115
117
|
* ADFFetchProvider implementation that fetches synced block data from Block Service API
|
|
116
118
|
*/
|
|
117
119
|
var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
118
|
-
function BlockServiceADFFetchProvider() {
|
|
120
|
+
function BlockServiceADFFetchProvider(sourceAri) {
|
|
119
121
|
(0, _classCallCheck2.default)(this, BlockServiceADFFetchProvider);
|
|
122
|
+
this.sourceAri = sourceAri;
|
|
120
123
|
}
|
|
124
|
+
|
|
125
|
+
// resourceId of the reference synced block.
|
|
126
|
+
// the ARI must be constructed to call the block service API
|
|
121
127
|
return (0, _createClass2.default)(BlockServiceADFFetchProvider, [{
|
|
122
128
|
key: "fetchData",
|
|
123
|
-
value:
|
|
124
|
-
// in the content API provider, this was the concatenation of the source document's ARI and the local ID. E.G ari:cloud:confluence:site-123:page/pageId/uuid-456
|
|
125
|
-
function () {
|
|
129
|
+
value: function () {
|
|
126
130
|
var _fetchData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resourceId) {
|
|
127
|
-
var
|
|
131
|
+
var blockAri, blockContentResponse, value, syncedBlockData;
|
|
128
132
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
129
133
|
while (1) switch (_context2.prev = _context2.next) {
|
|
130
134
|
case 0:
|
|
131
|
-
|
|
135
|
+
blockAri = (0, _ari.generateBlockAriFromReference)(this.sourceAri, resourceId);
|
|
132
136
|
_context2.prev = 1;
|
|
133
137
|
_context2.next = 4;
|
|
134
138
|
return (0, _blockService.getSyncedBlockContent)({
|
|
135
|
-
blockAri:
|
|
139
|
+
blockAri: blockAri
|
|
136
140
|
});
|
|
137
141
|
case 4:
|
|
138
142
|
blockContentResponse = _context2.sent;
|
|
@@ -151,8 +155,9 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
151
155
|
return _context2.abrupt("return", {
|
|
152
156
|
data: {
|
|
153
157
|
content: syncedBlockData,
|
|
154
|
-
resourceId:
|
|
155
|
-
blockInstanceId:
|
|
158
|
+
resourceId: blockAri,
|
|
159
|
+
blockInstanceId: blockContentResponse.blockInstanceId,
|
|
160
|
+
// this was the node's localId, but has become the resourceId.
|
|
156
161
|
sourceAri: blockContentResponse.sourceAri,
|
|
157
162
|
product: blockContentResponse.product
|
|
158
163
|
},
|
|
@@ -178,7 +183,7 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
178
183
|
case "end":
|
|
179
184
|
return _context2.stop();
|
|
180
185
|
}
|
|
181
|
-
}, _callee2,
|
|
186
|
+
}, _callee2, this, [[1, 12]]);
|
|
182
187
|
}));
|
|
183
188
|
function fetchData(_x2) {
|
|
184
189
|
return _fetchData.apply(this, arguments);
|
|
@@ -202,42 +207,43 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
202
207
|
key: "writeData",
|
|
203
208
|
value: function () {
|
|
204
209
|
var _writeData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(data) {
|
|
205
|
-
var resourceId;
|
|
210
|
+
var resourceId, blockAri;
|
|
206
211
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
207
212
|
while (1) switch (_context3.prev = _context3.next) {
|
|
208
213
|
case 0:
|
|
209
214
|
resourceId = data.resourceId;
|
|
210
|
-
|
|
211
|
-
_context3.
|
|
215
|
+
blockAri = (0, _ari.generateBlockAri)(this.sourceAri, resourceId, this.product);
|
|
216
|
+
_context3.prev = 2;
|
|
217
|
+
_context3.next = 5;
|
|
212
218
|
return (0, _blockService.updateSyncedBlock)({
|
|
213
|
-
blockAri:
|
|
219
|
+
blockAri: blockAri,
|
|
214
220
|
content: JSON.stringify(data.content)
|
|
215
221
|
});
|
|
216
|
-
case
|
|
222
|
+
case 5:
|
|
217
223
|
return _context3.abrupt("return", {
|
|
218
224
|
resourceId: resourceId
|
|
219
225
|
});
|
|
220
|
-
case
|
|
221
|
-
_context3.prev =
|
|
222
|
-
_context3.t0 = _context3["catch"](
|
|
226
|
+
case 8:
|
|
227
|
+
_context3.prev = 8;
|
|
228
|
+
_context3.t0 = _context3["catch"](2);
|
|
223
229
|
if (!(_context3.t0 instanceof _blockService.BlockError)) {
|
|
224
|
-
_context3.next =
|
|
230
|
+
_context3.next = 12;
|
|
225
231
|
break;
|
|
226
232
|
}
|
|
227
233
|
return _context3.abrupt("return", {
|
|
228
234
|
error: mapBlockError(_context3.t0),
|
|
229
235
|
resourceId: resourceId
|
|
230
236
|
});
|
|
231
|
-
case
|
|
237
|
+
case 12:
|
|
232
238
|
return _context3.abrupt("return", {
|
|
233
239
|
error: (0, _errorHandling.stringifyError)(_context3.t0),
|
|
234
240
|
resourceId: resourceId
|
|
235
241
|
});
|
|
236
|
-
case
|
|
242
|
+
case 13:
|
|
237
243
|
case "end":
|
|
238
244
|
return _context3.stop();
|
|
239
245
|
}
|
|
240
|
-
}, _callee3,
|
|
246
|
+
}, _callee3, this, [[2, 8]]);
|
|
241
247
|
}));
|
|
242
248
|
function writeData(_x3) {
|
|
243
249
|
return _writeData.apply(this, arguments);
|
|
@@ -248,45 +254,46 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
248
254
|
key: "createData",
|
|
249
255
|
value: function () {
|
|
250
256
|
var _createData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(data) {
|
|
251
|
-
var resourceId;
|
|
257
|
+
var resourceId, blockAri;
|
|
252
258
|
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
253
259
|
while (1) switch (_context4.prev = _context4.next) {
|
|
254
260
|
case 0:
|
|
255
261
|
resourceId = data.resourceId;
|
|
256
|
-
|
|
257
|
-
_context4.
|
|
262
|
+
blockAri = (0, _ari.generateBlockAri)(this.sourceAri, resourceId, this.product);
|
|
263
|
+
_context4.prev = 2;
|
|
264
|
+
_context4.next = 5;
|
|
258
265
|
return (0, _blockService.createSyncedBlock)({
|
|
259
|
-
blockAri:
|
|
266
|
+
blockAri: blockAri,
|
|
260
267
|
blockInstanceId: data.blockInstanceId,
|
|
261
268
|
sourceAri: this.sourceAri,
|
|
262
269
|
product: this.product,
|
|
263
270
|
content: JSON.stringify(data.content)
|
|
264
271
|
});
|
|
265
|
-
case
|
|
272
|
+
case 5:
|
|
266
273
|
return _context4.abrupt("return", {
|
|
267
274
|
resourceId: resourceId
|
|
268
275
|
});
|
|
269
|
-
case
|
|
270
|
-
_context4.prev =
|
|
271
|
-
_context4.t0 = _context4["catch"](
|
|
276
|
+
case 8:
|
|
277
|
+
_context4.prev = 8;
|
|
278
|
+
_context4.t0 = _context4["catch"](2);
|
|
272
279
|
if (!(_context4.t0 instanceof _blockService.BlockError)) {
|
|
273
|
-
_context4.next =
|
|
280
|
+
_context4.next = 12;
|
|
274
281
|
break;
|
|
275
282
|
}
|
|
276
283
|
return _context4.abrupt("return", {
|
|
277
284
|
error: mapBlockError(_context4.t0),
|
|
278
285
|
resourceId: resourceId
|
|
279
286
|
});
|
|
280
|
-
case
|
|
287
|
+
case 12:
|
|
281
288
|
return _context4.abrupt("return", {
|
|
282
289
|
error: (0, _errorHandling.stringifyError)(_context4.t0),
|
|
283
290
|
resourceId: resourceId
|
|
284
291
|
});
|
|
285
|
-
case
|
|
292
|
+
case 13:
|
|
286
293
|
case "end":
|
|
287
294
|
return _context4.stop();
|
|
288
295
|
}
|
|
289
|
-
}, _callee4, this, [[
|
|
296
|
+
}, _callee4, this, [[2, 8]]);
|
|
290
297
|
}));
|
|
291
298
|
function createData(_x4) {
|
|
292
299
|
return _createData.apply(this, arguments);
|
|
@@ -297,25 +304,27 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
297
304
|
key: "deleteData",
|
|
298
305
|
value: function () {
|
|
299
306
|
var _deleteData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(resourceId) {
|
|
307
|
+
var blockAri;
|
|
300
308
|
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
301
309
|
while (1) switch (_context5.prev = _context5.next) {
|
|
302
310
|
case 0:
|
|
303
|
-
|
|
304
|
-
_context5.
|
|
311
|
+
blockAri = (0, _ari.generateBlockAri)(this.sourceAri, resourceId, this.product);
|
|
312
|
+
_context5.prev = 1;
|
|
313
|
+
_context5.next = 4;
|
|
305
314
|
return (0, _blockService.deleteSyncedBlock)({
|
|
306
|
-
blockAri:
|
|
315
|
+
blockAri: blockAri
|
|
307
316
|
});
|
|
308
|
-
case
|
|
317
|
+
case 4:
|
|
309
318
|
return _context5.abrupt("return", {
|
|
310
319
|
resourceId: resourceId,
|
|
311
320
|
success: true,
|
|
312
321
|
error: undefined
|
|
313
322
|
});
|
|
314
|
-
case
|
|
315
|
-
_context5.prev =
|
|
316
|
-
_context5.t0 = _context5["catch"](
|
|
323
|
+
case 7:
|
|
324
|
+
_context5.prev = 7;
|
|
325
|
+
_context5.t0 = _context5["catch"](1);
|
|
317
326
|
if (!(_context5.t0 instanceof _blockService.BlockError)) {
|
|
318
|
-
_context5.next =
|
|
327
|
+
_context5.next = 11;
|
|
319
328
|
break;
|
|
320
329
|
}
|
|
321
330
|
return _context5.abrupt("return", {
|
|
@@ -323,27 +332,37 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
323
332
|
success: false,
|
|
324
333
|
error: mapBlockError(_context5.t0)
|
|
325
334
|
});
|
|
326
|
-
case
|
|
335
|
+
case 11:
|
|
327
336
|
return _context5.abrupt("return", {
|
|
328
337
|
resourceId: resourceId,
|
|
329
338
|
success: false,
|
|
330
339
|
error: (0, _errorHandling.stringifyError)(_context5.t0)
|
|
331
340
|
});
|
|
332
|
-
case
|
|
341
|
+
case 12:
|
|
333
342
|
case "end":
|
|
334
343
|
return _context5.stop();
|
|
335
344
|
}
|
|
336
|
-
}, _callee5,
|
|
345
|
+
}, _callee5, this, [[1, 7]]);
|
|
337
346
|
}));
|
|
338
347
|
function deleteData(_x5) {
|
|
339
348
|
return _deleteData.apply(this, arguments);
|
|
340
349
|
}
|
|
341
350
|
return deleteData;
|
|
342
|
-
}()
|
|
351
|
+
}() // the sourceId is the resourceId of the source synced block.
|
|
352
|
+
}, {
|
|
353
|
+
key: "generateResourceIdForReference",
|
|
354
|
+
value: function generateResourceIdForReference(sourceId) {
|
|
355
|
+
var match = this.sourceAri.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/(\d+)/);
|
|
356
|
+
if (!(match !== null && match !== void 0 && match[1])) {
|
|
357
|
+
throw new Error("Invalid source ARI: ".concat(this.sourceAri));
|
|
358
|
+
}
|
|
359
|
+
var pageId = match[3];
|
|
360
|
+
return "".concat(this.product, "/").concat(pageId, "/").concat(sourceId);
|
|
361
|
+
}
|
|
343
362
|
}, {
|
|
344
363
|
key: "generateResourceId",
|
|
345
|
-
value: function generateResourceId(
|
|
346
|
-
return
|
|
364
|
+
value: function generateResourceId() {
|
|
365
|
+
return crypto.randomUUID();
|
|
347
366
|
}
|
|
348
367
|
}]);
|
|
349
368
|
}();
|
|
@@ -351,7 +370,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
351
370
|
* Factory function to create both providers with shared configuration
|
|
352
371
|
*/
|
|
353
372
|
var createBlockServiceAPIProviders = function createBlockServiceAPIProviders(sourceAri, product) {
|
|
354
|
-
var fetchProvider = new BlockServiceADFFetchProvider();
|
|
373
|
+
var fetchProvider = new BlockServiceADFFetchProvider(sourceAri);
|
|
355
374
|
var writeProvider = new BlockServiceADFWriteProvider(sourceAri, product);
|
|
356
375
|
return {
|
|
357
376
|
fetchProvider: fetchProvider,
|
|
@@ -155,6 +155,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
155
155
|
function ConfluenceADFWriteProvider(config) {
|
|
156
156
|
var _this = this;
|
|
157
157
|
(0, _classCallCheck2.default)(this, ConfluenceADFWriteProvider);
|
|
158
|
+
(0, _defineProperty2.default)(this, "product", 'confluence-page');
|
|
158
159
|
(0, _defineProperty2.default)(this, "createNewContentProperty", /*#__PURE__*/function () {
|
|
159
160
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(pageId, key, value, pageType) {
|
|
160
161
|
var options, _contentProperty$data3, contentProperty, _contentProperty2$dat, _contentProperty2;
|
|
@@ -403,6 +404,11 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
403
404
|
value: function generateResourceId(sourceId, localId) {
|
|
404
405
|
return (0, _ari.resourceIdFromConfluencePageSourceIdAndLocalId)(sourceId, localId);
|
|
405
406
|
}
|
|
407
|
+
}, {
|
|
408
|
+
key: "generateResourceIdForReference",
|
|
409
|
+
value: function generateResourceIdForReference(sourceId) {
|
|
410
|
+
return sourceId;
|
|
411
|
+
}
|
|
406
412
|
}]);
|
|
407
413
|
}();
|
|
408
414
|
/**
|
|
@@ -43,16 +43,21 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
43
43
|
_this.providerOptions = providerOptions;
|
|
44
44
|
return _this;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Check if the node is supported by the provider
|
|
49
|
-
*
|
|
50
|
-
* @param node
|
|
51
|
-
*
|
|
52
|
-
* @returns True if the node is supported, false otherwise
|
|
53
|
-
*/
|
|
54
46
|
(0, _inherits2.default)(SyncBlockProvider, _SyncBlockDataProvide);
|
|
55
47
|
return (0, _createClass2.default)(SyncBlockProvider, [{
|
|
48
|
+
key: "getProduct",
|
|
49
|
+
value: function getProduct() {
|
|
50
|
+
return this.writeProvider.product;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Check if the node is supported by the provider
|
|
55
|
+
*
|
|
56
|
+
* @param node
|
|
57
|
+
*
|
|
58
|
+
* @returns True if the node is supported, false otherwise
|
|
59
|
+
*/
|
|
60
|
+
}, {
|
|
56
61
|
key: "isNodeSupported",
|
|
57
62
|
value: function isNodeSupported(node) {
|
|
58
63
|
return node.type === 'syncBlock' || node.type === 'bodiedSyncBlock';
|
|
@@ -248,6 +253,11 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
248
253
|
value: function generateResourceId(sourceId, localId) {
|
|
249
254
|
return this.writeProvider.generateResourceId(sourceId, localId);
|
|
250
255
|
}
|
|
256
|
+
}, {
|
|
257
|
+
key: "generateResourceIdForReference",
|
|
258
|
+
value: function generateResourceIdForReference(sourceId) {
|
|
259
|
+
return this.writeProvider.generateResourceIdForReference(sourceId);
|
|
260
|
+
}
|
|
251
261
|
|
|
252
262
|
/**
|
|
253
263
|
* Get the synced block renderer provider options
|
|
@@ -40,6 +40,14 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
40
40
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
41
41
|
}
|
|
42
42
|
return (0, _createClass2.default)(ReferenceSyncBlockStoreManager, [{
|
|
43
|
+
key: "generateResourceIdForReference",
|
|
44
|
+
value: function generateResourceIdForReference(sourceId) {
|
|
45
|
+
if (!this.dataProvider) {
|
|
46
|
+
throw new Error('Data provider not set');
|
|
47
|
+
}
|
|
48
|
+
return this.dataProvider.generateResourceIdForReference(sourceId);
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
43
51
|
key: "updateFireAnalyticsEvent",
|
|
44
52
|
value: function updateFireAnalyticsEvent(fireAnalyticsEvent) {
|
|
45
53
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
@@ -1,17 +1,34 @@
|
|
|
1
1
|
/* eslint-disable require-unicode-regexp */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generates the block ARI from the source page ARI and the source block's resource ID.
|
|
5
|
+
* @param sourceAri - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
|
|
6
|
+
* @param resourceId - the resource ID of the block node. A randomly generated UUID
|
|
7
|
+
* @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
|
|
8
|
+
*/
|
|
9
|
+
export const generateBlockAri = (sourceAri, resourceId, product) => {
|
|
10
|
+
const match = sourceAri.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/(\d+)/);
|
|
11
|
+
if (!(match !== null && match !== void 0 && match[1])) {
|
|
12
|
+
throw new Error(`Invalid source ARI: ${sourceAri}`);
|
|
13
|
+
}
|
|
14
|
+
const cloudId = match[1];
|
|
15
|
+
const pageId = match[3];
|
|
16
|
+
return `ari:cloud:blocks:${cloudId}:synced-block/${product}/${pageId}/${resourceId}`;
|
|
17
|
+
};
|
|
18
|
+
|
|
2
19
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param
|
|
5
|
-
* @param
|
|
6
|
-
* @returns the block ARI. E.G ari:cloud:blocks
|
|
20
|
+
*
|
|
21
|
+
* @param sourceAri - the ARI of the document. E.G ari:cloud:confluence:cloudId:page/pageId
|
|
22
|
+
* @param resourceId - the resource ID of the reference synced block. E.G confluence-page/pageId/sourceResourceId
|
|
23
|
+
* @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
|
|
7
24
|
*/
|
|
8
|
-
export const
|
|
9
|
-
const match =
|
|
25
|
+
export const generateBlockAriFromReference = (sourceAri, resourceId) => {
|
|
26
|
+
const match = sourceAri.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/(\d+)/);
|
|
10
27
|
if (!(match !== null && match !== void 0 && match[1])) {
|
|
11
|
-
throw new Error(`Invalid source ARI: ${
|
|
28
|
+
throw new Error(`Invalid source ARI: ${sourceAri}`);
|
|
12
29
|
}
|
|
13
30
|
const cloudId = match[1];
|
|
14
|
-
return `ari:cloud:blocks:${cloudId}:synced-block/${
|
|
31
|
+
return `ari:cloud:blocks:${cloudId}:synced-block/${resourceId}`;
|
|
15
32
|
};
|
|
16
33
|
|
|
17
34
|
/**
|
package/dist/es2019/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
|
|
|
9
9
|
export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
10
10
|
|
|
11
11
|
// clients
|
|
12
|
-
export {
|
|
12
|
+
export { generateBlockAri, generateBlockAriFromReference, getLocalIdFromBlockResourceId } from './clients/block-service/ari';
|
|
13
13
|
export { getConfluencePageAri, getLocalIdFromConfluencePageAri, getPageARIFromContentPropertyResourceId, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId } from './clients/confluence/ari';
|
|
14
14
|
|
|
15
15
|
// providers
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/* eslint-disable require-unicode-regexp */
|
|
1
2
|
import { useMemo } from 'react';
|
|
2
|
-
import {
|
|
3
|
+
import { generateBlockAri, generateBlockAriFromReference } from '../../clients/block-service/ari';
|
|
3
4
|
import { BlockError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getSyncedBlockContent, updateSyncedBlock } from '../../clients/block-service/blockService';
|
|
4
5
|
import { SyncBlockError } from '../../common/types';
|
|
5
6
|
import { stringifyError } from '../../utils/errorHandling';
|
|
@@ -81,13 +82,17 @@ export const fetchReferences = async documentAri => {
|
|
|
81
82
|
* ADFFetchProvider implementation that fetches synced block data from Block Service API
|
|
82
83
|
*/
|
|
83
84
|
class BlockServiceADFFetchProvider {
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
constructor(sourceAri) {
|
|
86
|
+
this.sourceAri = sourceAri;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// resourceId of the reference synced block.
|
|
90
|
+
// the ARI must be constructed to call the block service API
|
|
86
91
|
async fetchData(resourceId) {
|
|
87
|
-
const
|
|
92
|
+
const blockAri = generateBlockAriFromReference(this.sourceAri, resourceId);
|
|
88
93
|
try {
|
|
89
94
|
const blockContentResponse = await getSyncedBlockContent({
|
|
90
|
-
blockAri
|
|
95
|
+
blockAri
|
|
91
96
|
});
|
|
92
97
|
const value = blockContentResponse.content;
|
|
93
98
|
if (!value) {
|
|
@@ -102,8 +107,9 @@ class BlockServiceADFFetchProvider {
|
|
|
102
107
|
return {
|
|
103
108
|
data: {
|
|
104
109
|
content: syncedBlockData,
|
|
105
|
-
resourceId,
|
|
106
|
-
blockInstanceId:
|
|
110
|
+
resourceId: blockAri,
|
|
111
|
+
blockInstanceId: blockContentResponse.blockInstanceId,
|
|
112
|
+
// this was the node's localId, but has become the resourceId.
|
|
107
113
|
sourceAri: blockContentResponse.sourceAri,
|
|
108
114
|
product: blockContentResponse.product
|
|
109
115
|
},
|
|
@@ -138,10 +144,11 @@ class BlockServiceADFWriteProvider {
|
|
|
138
144
|
const {
|
|
139
145
|
resourceId
|
|
140
146
|
} = data;
|
|
147
|
+
const blockAri = generateBlockAri(this.sourceAri, resourceId, this.product);
|
|
141
148
|
try {
|
|
142
149
|
// Try update existing block's content
|
|
143
150
|
await updateSyncedBlock({
|
|
144
|
-
blockAri
|
|
151
|
+
blockAri,
|
|
145
152
|
content: JSON.stringify(data.content)
|
|
146
153
|
});
|
|
147
154
|
return {
|
|
@@ -164,9 +171,10 @@ class BlockServiceADFWriteProvider {
|
|
|
164
171
|
const {
|
|
165
172
|
resourceId
|
|
166
173
|
} = data;
|
|
174
|
+
const blockAri = generateBlockAri(this.sourceAri, resourceId, this.product);
|
|
167
175
|
try {
|
|
168
176
|
await createSyncedBlock({
|
|
169
|
-
blockAri
|
|
177
|
+
blockAri,
|
|
170
178
|
blockInstanceId: data.blockInstanceId,
|
|
171
179
|
sourceAri: this.sourceAri,
|
|
172
180
|
product: this.product,
|
|
@@ -191,9 +199,10 @@ class BlockServiceADFWriteProvider {
|
|
|
191
199
|
|
|
192
200
|
// soft deletes the source synced block
|
|
193
201
|
async deleteData(resourceId) {
|
|
202
|
+
const blockAri = generateBlockAri(this.sourceAri, resourceId, this.product);
|
|
194
203
|
try {
|
|
195
204
|
await deleteSyncedBlock({
|
|
196
|
-
blockAri
|
|
205
|
+
blockAri
|
|
197
206
|
});
|
|
198
207
|
return {
|
|
199
208
|
resourceId,
|
|
@@ -215,8 +224,18 @@ class BlockServiceADFWriteProvider {
|
|
|
215
224
|
};
|
|
216
225
|
}
|
|
217
226
|
}
|
|
218
|
-
|
|
219
|
-
|
|
227
|
+
|
|
228
|
+
// the sourceId is the resourceId of the source synced block.
|
|
229
|
+
generateResourceIdForReference(sourceId) {
|
|
230
|
+
const match = this.sourceAri.match(/ari:cloud:confluence:([^:]+):(page|blogpost)\/(\d+)/);
|
|
231
|
+
if (!(match !== null && match !== void 0 && match[1])) {
|
|
232
|
+
throw new Error(`Invalid source ARI: ${this.sourceAri}`);
|
|
233
|
+
}
|
|
234
|
+
const pageId = match[3];
|
|
235
|
+
return `${this.product}/${pageId}/${sourceId}`;
|
|
236
|
+
}
|
|
237
|
+
generateResourceId() {
|
|
238
|
+
return crypto.randomUUID();
|
|
220
239
|
}
|
|
221
240
|
}
|
|
222
241
|
|
|
@@ -224,7 +243,7 @@ class BlockServiceADFWriteProvider {
|
|
|
224
243
|
* Factory function to create both providers with shared configuration
|
|
225
244
|
*/
|
|
226
245
|
const createBlockServiceAPIProviders = (sourceAri, product) => {
|
|
227
|
-
const fetchProvider = new BlockServiceADFFetchProvider();
|
|
246
|
+
const fetchProvider = new BlockServiceADFFetchProvider(sourceAri);
|
|
228
247
|
const writeProvider = new BlockServiceADFWriteProvider(sourceAri, product);
|
|
229
248
|
return {
|
|
230
249
|
fetchProvider,
|
|
@@ -115,6 +115,7 @@ class ConfluenceADFFetchProvider {
|
|
|
115
115
|
*/
|
|
116
116
|
class ConfluenceADFWriteProvider {
|
|
117
117
|
constructor(config) {
|
|
118
|
+
_defineProperty(this, "product", 'confluence-page');
|
|
118
119
|
_defineProperty(this, "createNewContentProperty", async (pageId, key, value, pageType) => {
|
|
119
120
|
const options = {
|
|
120
121
|
pageId,
|
|
@@ -271,6 +272,9 @@ class ConfluenceADFWriteProvider {
|
|
|
271
272
|
generateResourceId(sourceId, localId) {
|
|
272
273
|
return resourceIdFromConfluencePageSourceIdAndLocalId(sourceId, localId);
|
|
273
274
|
}
|
|
275
|
+
generateResourceIdForReference(sourceId) {
|
|
276
|
+
return sourceId;
|
|
277
|
+
}
|
|
274
278
|
}
|
|
275
279
|
|
|
276
280
|
/**
|
|
@@ -23,6 +23,9 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
23
23
|
this.sourceId = sourceId;
|
|
24
24
|
this.providerOptions = providerOptions;
|
|
25
25
|
}
|
|
26
|
+
getProduct() {
|
|
27
|
+
return this.writeProvider.product;
|
|
28
|
+
}
|
|
26
29
|
|
|
27
30
|
/**
|
|
28
31
|
* Check if the node is supported by the provider
|
|
@@ -160,6 +163,9 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
160
163
|
generateResourceId(sourceId, localId) {
|
|
161
164
|
return this.writeProvider.generateResourceId(sourceId, localId);
|
|
162
165
|
}
|
|
166
|
+
generateResourceIdForReference(sourceId) {
|
|
167
|
+
return this.writeProvider.generateResourceIdForReference(sourceId);
|
|
168
|
+
}
|
|
163
169
|
|
|
164
170
|
/**
|
|
165
171
|
* Get the synced block renderer provider options
|
|
@@ -22,6 +22,12 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
22
22
|
this.providerFactories = new Map();
|
|
23
23
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
24
24
|
}
|
|
25
|
+
generateResourceIdForReference(sourceId) {
|
|
26
|
+
if (!this.dataProvider) {
|
|
27
|
+
throw new Error('Data provider not set');
|
|
28
|
+
}
|
|
29
|
+
return this.dataProvider.generateResourceIdForReference(sourceId);
|
|
30
|
+
}
|
|
25
31
|
updateFireAnalyticsEvent(fireAnalyticsEvent) {
|
|
26
32
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
27
33
|
}
|