@atlaskit/editor-synced-block-provider 3.2.0 → 3.2.1
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 +7 -0
- package/dist/cjs/clients/block-service/ari.js +13 -16
- package/dist/cjs/clients/confluence/ari.js +7 -40
- package/dist/cjs/clients/confluence/sourceInfo.js +3 -1
- package/dist/cjs/clients/jira/ari.js +5 -2
- package/dist/cjs/index.js +2 -27
- package/dist/cjs/providers/block-service/blockServiceAPI.js +71 -28
- package/dist/cjs/providers/syncBlockProvider.js +57 -38
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +5 -8
- package/dist/es2019/clients/block-service/ari.js +15 -16
- package/dist/es2019/clients/confluence/ari.js +11 -37
- package/dist/es2019/clients/confluence/sourceInfo.js +3 -1
- package/dist/es2019/clients/jira/ari.js +9 -2
- package/dist/es2019/index.js +2 -3
- package/dist/es2019/providers/block-service/blockServiceAPI.js +75 -28
- package/dist/es2019/providers/syncBlockProvider.js +45 -25
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +5 -8
- package/dist/esm/clients/block-service/ari.js +13 -16
- package/dist/esm/clients/confluence/ari.js +6 -39
- package/dist/esm/clients/confluence/sourceInfo.js +3 -1
- package/dist/esm/clients/jira/ari.js +5 -2
- package/dist/esm/index.js +2 -3
- package/dist/esm/providers/block-service/blockServiceAPI.js +70 -27
- package/dist/esm/providers/syncBlockProvider.js +57 -38
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +4 -8
- package/dist/types/clients/block-service/ari.d.ts +14 -4
- package/dist/types/clients/confluence/ari.d.ts +8 -21
- package/dist/types/clients/jira/ari.d.ts +7 -2
- package/dist/types/index.d.ts +5 -6
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +31 -6
- package/dist/types/providers/syncBlockProvider.d.ts +14 -13
- package/dist/types/providers/types.d.ts +9 -6
- package/dist/types-ts4.5/clients/block-service/ari.d.ts +14 -4
- package/dist/types-ts4.5/clients/confluence/ari.d.ts +8 -21
- package/dist/types-ts4.5/clients/jira/ari.d.ts +7 -2
- package/dist/types-ts4.5/index.d.ts +5 -6
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +31 -6
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +14 -13
- package/dist/types-ts4.5/providers/types.d.ts +9 -6
- package/package.json +1 -1
- package/dist/cjs/clients/confluence/contentProperty.js +0 -284
- package/dist/cjs/providers/confluence/confluenceContentAPI.js +0 -446
- package/dist/es2019/clients/confluence/contentProperty.js +0 -288
- package/dist/es2019/providers/confluence/confluenceContentAPI.js +0 -310
- package/dist/esm/clients/confluence/contentProperty.js +0 -277
- package/dist/esm/providers/confluence/confluenceContentAPI.js +0 -440
- package/dist/types/clients/confluence/contentProperty.d.ts +0 -139
- package/dist/types/providers/confluence/confluenceContentAPI.d.ts +0 -44
- package/dist/types-ts4.5/clients/confluence/contentProperty.d.ts +0 -139
- package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +0 -44
|
@@ -2,32 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Generates the block ARI from the source page ARI and the source block's resource ID.
|
|
5
|
-
* @param
|
|
5
|
+
* @param cloudId - the cloudId of the block. E.G the cloudId of the confluence page, or the cloudId of the Jira instance
|
|
6
|
+
* @param parentId - the parentId of the block. E.G the pageId for a confluence page, or the issueId for a Jira work item
|
|
6
7
|
* @param resourceId - the resource ID of the block node. A randomly generated UUID
|
|
8
|
+
* @param product - the product of the block. E.G 'confluence-page', 'jira-work-item'
|
|
7
9
|
* @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
|
|
8
10
|
*/
|
|
9
|
-
export const generateBlockAri = (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return `ari:cloud:blocks:${cloudId}:synced-block/${product}/${pageId}/${resourceId}`;
|
|
11
|
+
export const generateBlockAri = ({
|
|
12
|
+
cloudId,
|
|
13
|
+
parentId,
|
|
14
|
+
product,
|
|
15
|
+
resourceId
|
|
16
|
+
}) => {
|
|
17
|
+
return `ari:cloud:blocks:${cloudId}:synced-block/${product}/${parentId}/${resourceId}`;
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Generates the block ARI from the reference synced block ARI and the resource ID
|
|
21
|
-
* @param
|
|
22
|
+
* @param cloudId - the cloudId of the block. E.G the cloudId of the confluence page, or the cloudId of the Jira instance
|
|
22
23
|
* @param resourceId - the resource ID of the reference synced block. E.G confluence-page/pageId/sourceResourceId
|
|
23
24
|
* @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
|
|
24
25
|
*/
|
|
25
|
-
export const generateBlockAriFromReference = (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
const cloudId = match[1];
|
|
26
|
+
export const generateBlockAriFromReference = ({
|
|
27
|
+
cloudId,
|
|
28
|
+
resourceId
|
|
29
|
+
}) => {
|
|
31
30
|
return `ari:cloud:blocks:${cloudId}:synced-block/${resourceId}`;
|
|
32
31
|
};
|
|
33
32
|
|
|
@@ -11,14 +11,22 @@
|
|
|
11
11
|
* @param pageType - the type of the page
|
|
12
12
|
* @returns the Confluence page ARI
|
|
13
13
|
*/
|
|
14
|
-
export const getConfluencePageAri = (
|
|
14
|
+
export const getConfluencePageAri = ({
|
|
15
|
+
pageId,
|
|
16
|
+
cloudId,
|
|
17
|
+
pageType
|
|
18
|
+
}) => {
|
|
19
|
+
return `ari:cloud:confluence:${cloudId}:${pageType}/${pageId}`;
|
|
20
|
+
};
|
|
15
21
|
|
|
16
22
|
/**
|
|
17
23
|
* Extracts the page ID and type from the Confluence page ARI
|
|
18
24
|
* @param ari - the Confluence page ARI
|
|
19
25
|
* @returns the page ID and type
|
|
20
26
|
*/
|
|
21
|
-
export const getPageIdAndTypeFromConfluencePageAri =
|
|
27
|
+
export const getPageIdAndTypeFromConfluencePageAri = ({
|
|
28
|
+
ari
|
|
29
|
+
}) => {
|
|
22
30
|
const match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/(\d+)/);
|
|
23
31
|
if (match !== null && match !== void 0 && match[2]) {
|
|
24
32
|
return {
|
|
@@ -27,38 +35,4 @@ export const getPageIdAndTypeFromConfluencePageAri = ari => {
|
|
|
27
35
|
};
|
|
28
36
|
}
|
|
29
37
|
throw new Error(`Invalid page ARI: ${ari}`);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Extracts the local ID from the Confluence page content property resource ID
|
|
34
|
-
* @param resourceId - the Confluence page content property resource ID
|
|
35
|
-
* @returns the local ID
|
|
36
|
-
*/
|
|
37
|
-
export const getLocalIdFromContentPropertyResourceId = resourceId => {
|
|
38
|
-
const match = resourceId.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+\/([a-zA-Z0-9-]+)/);
|
|
39
|
-
if (match !== null && match !== void 0 && match[2]) {
|
|
40
|
-
return match[2];
|
|
41
|
-
}
|
|
42
|
-
throw new Error(`Invalid resourceId: ${resourceId}`);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Extracts the Confluence page ARI from the Confluence content property resource ID
|
|
47
|
-
* @param resourceId - the Confluence content property resource ID
|
|
48
|
-
* @returns the Confluence page ARI
|
|
49
|
-
*/
|
|
50
|
-
export const getPageAriFromContentPropertyResourceId = resourceId => {
|
|
51
|
-
const match = resourceId.match(/(ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+)\/([a-zA-Z0-9-]+)$/);
|
|
52
|
-
if (match !== null && match !== void 0 && match[1]) {
|
|
53
|
-
return match[1];
|
|
54
|
-
}
|
|
55
|
-
throw new Error(`Invalid resourceId: ${resourceId}`);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Generates the Confluence page content property resource ID from the source ID and local ID
|
|
60
|
-
* @param sourceId - the source ID
|
|
61
|
-
* @param localId - the local ID
|
|
62
|
-
* @returns the Confluence page content property resource ID
|
|
63
|
-
*/
|
|
64
|
-
export const resourceIdFromConfluencePageSourceIdAndLocalId = (sourceId, localId) => `${sourceId}/${localId}`;
|
|
38
|
+
};
|
|
@@ -60,7 +60,9 @@ export const fetchConfluencePageInfo = async (pageAri, localId, fireAnalyticsEve
|
|
|
60
60
|
var _response$data, _response$data$conten, _response$data$conten2, _contentData$space;
|
|
61
61
|
const {
|
|
62
62
|
type: pageType
|
|
63
|
-
} = getPageIdAndTypeFromConfluencePageAri(
|
|
63
|
+
} = getPageIdAndTypeFromConfluencePageAri({
|
|
64
|
+
ari: pageAri
|
|
65
|
+
});
|
|
64
66
|
const response = await getConfluenceSourceInfo(pageAri);
|
|
65
67
|
const contentData = (_response$data = response.data) === null || _response$data === void 0 ? void 0 : (_response$data$conten = _response$data.content) === null || _response$data$conten === void 0 ? void 0 : (_response$data$conten2 = _response$data$conten.nodes) === null || _response$data$conten2 === void 0 ? void 0 : _response$data$conten2[0];
|
|
66
68
|
const title = contentData === null || contentData === void 0 ? void 0 : contentData.title;
|
|
@@ -6,14 +6,21 @@
|
|
|
6
6
|
* @param cloudId - the cloud ID
|
|
7
7
|
* @returns the Jira work item ARI
|
|
8
8
|
*/
|
|
9
|
-
export const getJiraWorkItemAri = (
|
|
9
|
+
export const getJiraWorkItemAri = ({
|
|
10
|
+
cloudId,
|
|
11
|
+
workItemId
|
|
12
|
+
}) => {
|
|
13
|
+
return `ari:cloud:jira:${cloudId}:issue/${workItemId}`;
|
|
14
|
+
};
|
|
10
15
|
|
|
11
16
|
/**
|
|
12
17
|
* Extracts the Jira work item ID from the Jira work item ARI
|
|
13
18
|
* @param ari - the Jira work item ARI
|
|
14
19
|
* @returns the Jira work item ID
|
|
15
20
|
*/
|
|
16
|
-
export const getJiraWorkItemIdFromAri =
|
|
21
|
+
export const getJiraWorkItemIdFromAri = ({
|
|
22
|
+
ari
|
|
23
|
+
}) => {
|
|
17
24
|
const match = ari.match(/ari:cloud:jira:([^:]+):issue\/(\d+)/);
|
|
18
25
|
if (match !== null && match !== void 0 && match[2]) {
|
|
19
26
|
return match[2];
|
package/dist/es2019/index.js
CHANGED
|
@@ -10,12 +10,11 @@ export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
|
10
10
|
|
|
11
11
|
// clients
|
|
12
12
|
export { generateBlockAri, generateBlockAriFromReference, getLocalIdFromBlockResourceId } from './clients/block-service/ari';
|
|
13
|
-
export { getConfluencePageAri,
|
|
13
|
+
export { getConfluencePageAri, getPageIdAndTypeFromConfluencePageAri } from './clients/confluence/ari';
|
|
14
14
|
export { getJiraWorkItemAri, getJiraWorkItemIdFromAri } from './clients/jira/ari';
|
|
15
15
|
|
|
16
16
|
// providers
|
|
17
|
-
export { useMemoizedBlockServiceAPIProviders } from './providers/block-service/blockServiceAPI';
|
|
18
|
-
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluence/confluenceContentAPI';
|
|
17
|
+
export { useMemoizedBlockServiceAPIProviders, useMemoizedBlockServiceFetchOnlyAPIProvider } from './providers/block-service/blockServiceAPI';
|
|
19
18
|
export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
|
|
20
19
|
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
|
|
21
20
|
|
|
@@ -77,19 +77,23 @@ export const fetchReferences = async documentAri => {
|
|
|
77
77
|
}));
|
|
78
78
|
return [...blocksInstances, ...errorInstances];
|
|
79
79
|
};
|
|
80
|
-
|
|
81
80
|
/**
|
|
82
81
|
* ADFFetchProvider implementation that fetches synced block data from Block Service API
|
|
83
82
|
*/
|
|
84
83
|
class BlockServiceADFFetchProvider {
|
|
85
|
-
constructor(
|
|
86
|
-
|
|
84
|
+
constructor({
|
|
85
|
+
cloudId
|
|
86
|
+
}) {
|
|
87
|
+
this.cloudId = cloudId;
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
// resourceId of the reference synced block.
|
|
90
91
|
// the ARI must be constructed to call the block service API
|
|
91
92
|
async fetchData(resourceId) {
|
|
92
|
-
const blockAri = generateBlockAriFromReference(
|
|
93
|
+
const blockAri = generateBlockAriFromReference({
|
|
94
|
+
cloudId: this.cloudId,
|
|
95
|
+
resourceId
|
|
96
|
+
});
|
|
93
97
|
try {
|
|
94
98
|
const blockContentResponse = await getSyncedBlockContent({
|
|
95
99
|
blockAri
|
|
@@ -129,15 +133,21 @@ class BlockServiceADFFetchProvider {
|
|
|
129
133
|
}
|
|
130
134
|
}
|
|
131
135
|
}
|
|
132
|
-
|
|
133
136
|
/**
|
|
134
137
|
* ADFWriteProvider implementation that writes synced block data to Block Service API
|
|
135
138
|
*/
|
|
136
139
|
class BlockServiceADFWriteProvider {
|
|
137
|
-
constructor(
|
|
138
|
-
|
|
140
|
+
constructor({
|
|
141
|
+
cloudId,
|
|
142
|
+
parentAri,
|
|
143
|
+
parentId,
|
|
144
|
+
product,
|
|
145
|
+
getVersion
|
|
146
|
+
}) {
|
|
147
|
+
this.cloudId = cloudId;
|
|
148
|
+
this.parentAri = parentAri;
|
|
149
|
+
this.parentId = parentId;
|
|
139
150
|
this.product = product;
|
|
140
|
-
this.sourceDocumentId = sourceDocumentId;
|
|
141
151
|
this.getVersion = getVersion;
|
|
142
152
|
}
|
|
143
153
|
|
|
@@ -146,7 +156,12 @@ class BlockServiceADFWriteProvider {
|
|
|
146
156
|
const {
|
|
147
157
|
resourceId
|
|
148
158
|
} = data;
|
|
149
|
-
const blockAri = generateBlockAri(
|
|
159
|
+
const blockAri = generateBlockAri({
|
|
160
|
+
cloudId: this.cloudId,
|
|
161
|
+
parentId: this.parentId,
|
|
162
|
+
product: this.product,
|
|
163
|
+
resourceId
|
|
164
|
+
});
|
|
150
165
|
const stepVersion = this.getVersion ? this.getVersion() : undefined;
|
|
151
166
|
try {
|
|
152
167
|
// Try update existing block's content
|
|
@@ -175,13 +190,18 @@ class BlockServiceADFWriteProvider {
|
|
|
175
190
|
const {
|
|
176
191
|
resourceId
|
|
177
192
|
} = data;
|
|
178
|
-
const blockAri = generateBlockAri(
|
|
193
|
+
const blockAri = generateBlockAri({
|
|
194
|
+
cloudId: this.cloudId,
|
|
195
|
+
parentId: this.parentId,
|
|
196
|
+
product: this.product,
|
|
197
|
+
resourceId
|
|
198
|
+
});
|
|
179
199
|
const stepVersion = this.getVersion ? this.getVersion() : undefined;
|
|
180
200
|
try {
|
|
181
201
|
await createSyncedBlock({
|
|
182
202
|
blockAri,
|
|
183
203
|
blockInstanceId: data.blockInstanceId,
|
|
184
|
-
sourceAri: this.
|
|
204
|
+
sourceAri: this.parentAri,
|
|
185
205
|
product: this.product,
|
|
186
206
|
content: JSON.stringify(data.content),
|
|
187
207
|
stepVersion
|
|
@@ -205,7 +225,12 @@ class BlockServiceADFWriteProvider {
|
|
|
205
225
|
|
|
206
226
|
// soft deletes the source synced block
|
|
207
227
|
async deleteData(resourceId) {
|
|
208
|
-
const blockAri = generateBlockAri(
|
|
228
|
+
const blockAri = generateBlockAri({
|
|
229
|
+
cloudId: this.cloudId,
|
|
230
|
+
parentId: this.parentId,
|
|
231
|
+
product: this.product,
|
|
232
|
+
resourceId
|
|
233
|
+
});
|
|
209
234
|
try {
|
|
210
235
|
await deleteSyncedBlock({
|
|
211
236
|
blockAri
|
|
@@ -241,7 +266,7 @@ class BlockServiceADFWriteProvider {
|
|
|
241
266
|
|
|
242
267
|
// the sourceId is the resourceId of the source synced block.
|
|
243
268
|
generateResourceIdForReference(sourceId) {
|
|
244
|
-
return `${this.product}/${this.
|
|
269
|
+
return `${this.product}/${this.parentId}/${sourceId}`;
|
|
245
270
|
}
|
|
246
271
|
generateResourceId() {
|
|
247
272
|
return crypto.randomUUID();
|
|
@@ -249,9 +274,12 @@ class BlockServiceADFWriteProvider {
|
|
|
249
274
|
async updateReferenceData(blocks, noContent) {
|
|
250
275
|
try {
|
|
251
276
|
await updateReferenceSyncedBlockOnDocument({
|
|
252
|
-
documentAri: this.
|
|
277
|
+
documentAri: this.parentAri,
|
|
253
278
|
blocks: blocks.map(block => ({
|
|
254
|
-
blockAri: generateBlockAriFromReference(
|
|
279
|
+
blockAri: generateBlockAriFromReference({
|
|
280
|
+
cloudId: this.cloudId,
|
|
281
|
+
resourceId: block.resourceId
|
|
282
|
+
}),
|
|
255
283
|
blockInstanceId: block.localId
|
|
256
284
|
})),
|
|
257
285
|
noContent
|
|
@@ -273,18 +301,37 @@ class BlockServiceADFWriteProvider {
|
|
|
273
301
|
}
|
|
274
302
|
}
|
|
275
303
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
304
|
+
export const useMemoizedBlockServiceAPIProviders = ({
|
|
305
|
+
cloudId,
|
|
306
|
+
parentAri,
|
|
307
|
+
parentId,
|
|
308
|
+
product,
|
|
309
|
+
getVersion
|
|
310
|
+
}) => {
|
|
311
|
+
return useMemo(() => {
|
|
312
|
+
return {
|
|
313
|
+
fetchProvider: new BlockServiceADFFetchProvider({
|
|
314
|
+
cloudId
|
|
315
|
+
}),
|
|
316
|
+
writeProvider: new BlockServiceADFWriteProvider({
|
|
317
|
+
cloudId,
|
|
318
|
+
parentAri,
|
|
319
|
+
parentId,
|
|
320
|
+
product,
|
|
321
|
+
getVersion
|
|
322
|
+
})
|
|
323
|
+
};
|
|
324
|
+
}, [cloudId, parentAri, parentId, product, getVersion]);
|
|
287
325
|
};
|
|
288
|
-
export const
|
|
289
|
-
|
|
326
|
+
export const useMemoizedBlockServiceFetchOnlyAPIProvider = ({
|
|
327
|
+
cloudId
|
|
328
|
+
}) => {
|
|
329
|
+
return useMemo(() => {
|
|
330
|
+
return {
|
|
331
|
+
fetchProvider: new BlockServiceADFFetchProvider({
|
|
332
|
+
cloudId
|
|
333
|
+
}),
|
|
334
|
+
writeProvider: undefined
|
|
335
|
+
};
|
|
336
|
+
}, [cloudId]);
|
|
290
337
|
};
|
|
@@ -3,32 +3,25 @@ import { useMemo } from 'react';
|
|
|
3
3
|
import { getPageIdAndTypeFromConfluencePageAri } from '../clients/confluence/ari';
|
|
4
4
|
import { fetchConfluencePageInfo } from '../clients/confluence/sourceInfo';
|
|
5
5
|
import { SyncBlockError } from '../common/types';
|
|
6
|
-
import { SyncBlockDataProvider } from '
|
|
6
|
+
import { SyncBlockDataProvider } from './types';
|
|
7
7
|
export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
8
|
-
// the source document ARI; that the source sync block is on.
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Constructor for the SyncBlockProvider
|
|
12
10
|
*
|
|
13
11
|
* @param fetchProvider
|
|
14
12
|
* @param writeProvider
|
|
15
|
-
* @param sourceId
|
|
16
13
|
* @param nestedRendererDataProviders
|
|
17
14
|
*/
|
|
18
|
-
constructor(fetchProvider, writeProvider
|
|
15
|
+
constructor(fetchProvider, writeProvider) {
|
|
19
16
|
super();
|
|
20
17
|
_defineProperty(this, "name", 'syncBlockProvider');
|
|
21
18
|
this.fetchProvider = fetchProvider;
|
|
22
19
|
this.writeProvider = writeProvider;
|
|
23
|
-
this.sourceId = sourceId;
|
|
24
20
|
this.providerOptions = {};
|
|
25
21
|
}
|
|
26
22
|
setProviderOptions(providerOptions) {
|
|
27
23
|
this.providerOptions = providerOptions;
|
|
28
24
|
}
|
|
29
|
-
getProduct() {
|
|
30
|
-
return this.writeProvider.product;
|
|
31
|
-
}
|
|
32
25
|
|
|
33
26
|
/**
|
|
34
27
|
* Check if the node is supported by the provider
|
|
@@ -88,11 +81,18 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
88
81
|
* resourceId: resource id of the node if write successfully , error: reason for when write failed
|
|
89
82
|
*/
|
|
90
83
|
async writeNodesData(nodes, data) {
|
|
84
|
+
if (!this.writeProvider) {
|
|
85
|
+
return Promise.reject(new Error('Write provider not set'));
|
|
86
|
+
}
|
|
91
87
|
const results = await Promise.allSettled(nodes.map((_node, index) => {
|
|
88
|
+
var _this$writeProvider;
|
|
89
|
+
if (!this.writeProvider) {
|
|
90
|
+
return Promise.reject('Write provider not set');
|
|
91
|
+
}
|
|
92
92
|
if (!data[index].content) {
|
|
93
93
|
return Promise.reject('No Synced Block content to write');
|
|
94
94
|
}
|
|
95
|
-
return this.writeProvider.writeData(data[index]);
|
|
95
|
+
return (_this$writeProvider = this.writeProvider) === null || _this$writeProvider === void 0 ? void 0 : _this$writeProvider.writeData(data[index]);
|
|
96
96
|
}));
|
|
97
97
|
return results.map(result => {
|
|
98
98
|
if (result.status === 'fulfilled') {
|
|
@@ -105,6 +105,9 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
createNodeData(data) {
|
|
108
|
+
if (!this.writeProvider) {
|
|
109
|
+
return Promise.reject(new Error('Write provider not set'));
|
|
110
|
+
}
|
|
108
111
|
return this.writeProvider.createData(data).then(result => result, error => ({
|
|
109
112
|
error
|
|
110
113
|
}));
|
|
@@ -118,7 +121,15 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
118
121
|
* @returns Array of {resourceId?: string, error?: string}.
|
|
119
122
|
*/
|
|
120
123
|
async deleteNodesData(resourceIds) {
|
|
121
|
-
|
|
124
|
+
if (!this.writeProvider) {
|
|
125
|
+
return Promise.reject(new Error('Write provider not set'));
|
|
126
|
+
}
|
|
127
|
+
const results = await Promise.allSettled(resourceIds.map(resourceId => {
|
|
128
|
+
if (!this.writeProvider) {
|
|
129
|
+
return Promise.reject('Write provider not set');
|
|
130
|
+
}
|
|
131
|
+
return this.writeProvider.deleteData(resourceId);
|
|
132
|
+
}));
|
|
122
133
|
return results.map((result, index) => {
|
|
123
134
|
if (result.status === 'fulfilled') {
|
|
124
135
|
return result.value;
|
|
@@ -132,15 +143,6 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
132
143
|
});
|
|
133
144
|
}
|
|
134
145
|
|
|
135
|
-
/**
|
|
136
|
-
* Get the source id
|
|
137
|
-
*
|
|
138
|
-
* @returns The source id
|
|
139
|
-
*/
|
|
140
|
-
getSourceId() {
|
|
141
|
-
return this.sourceId;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
146
|
/**
|
|
145
147
|
* Fetch the source info from the source id
|
|
146
148
|
*
|
|
@@ -163,10 +165,18 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
163
165
|
return Promise.reject(new Error(`${sourceProduct} source product not supported`));
|
|
164
166
|
}
|
|
165
167
|
}
|
|
166
|
-
generateResourceId(
|
|
167
|
-
|
|
168
|
+
generateResourceId() {
|
|
169
|
+
const localId = crypto.randomUUID();
|
|
170
|
+
const resourceId = crypto.randomUUID();
|
|
171
|
+
return {
|
|
172
|
+
localId,
|
|
173
|
+
resourceId
|
|
174
|
+
};
|
|
168
175
|
}
|
|
169
176
|
generateResourceIdForReference(sourceId) {
|
|
177
|
+
if (!this.writeProvider) {
|
|
178
|
+
throw new Error('Write provider not set');
|
|
179
|
+
}
|
|
170
180
|
return this.writeProvider.generateResourceIdForReference(sourceId);
|
|
171
181
|
}
|
|
172
182
|
|
|
@@ -194,7 +204,9 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
194
204
|
switch (sourceProduct) {
|
|
195
205
|
case 'confluence-page':
|
|
196
206
|
return {
|
|
197
|
-
contentId: getPageIdAndTypeFromConfluencePageAri(
|
|
207
|
+
contentId: getPageIdAndTypeFromConfluencePageAri({
|
|
208
|
+
ari: sourceAri
|
|
209
|
+
}).id,
|
|
198
210
|
contentProduct: sourceProduct
|
|
199
211
|
};
|
|
200
212
|
case 'jira-work-item':
|
|
@@ -204,11 +216,19 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
204
216
|
}
|
|
205
217
|
}
|
|
206
218
|
updateReferenceData(blocks, noContent) {
|
|
219
|
+
if (!this.writeProvider) {
|
|
220
|
+
throw new Error('Write provider not set');
|
|
221
|
+
}
|
|
207
222
|
return this.writeProvider.updateReferenceData(blocks, noContent);
|
|
208
223
|
}
|
|
209
224
|
}
|
|
210
|
-
export const useMemoizedSyncedBlockProvider = (
|
|
211
|
-
|
|
225
|
+
export const useMemoizedSyncedBlockProvider = ({
|
|
226
|
+
fetchProvider,
|
|
227
|
+
writeProvider,
|
|
228
|
+
providerOptions,
|
|
229
|
+
getSSRData
|
|
230
|
+
}) => {
|
|
231
|
+
const syncBlockProvider = useMemo(() => new SyncBlockProvider(fetchProvider, writeProvider), [fetchProvider, writeProvider]);
|
|
212
232
|
syncBlockProvider.setProviderOptions(providerOptions);
|
|
213
233
|
const ssrData = getSSRData ? getSSRData() : undefined;
|
|
214
234
|
if (ssrData) {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
// eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
|
|
3
|
-
import uuid from 'uuid';
|
|
4
2
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
5
3
|
import { SyncBlockError } from '../common/types';
|
|
6
4
|
import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload } from '../utils/errorHandling';
|
|
@@ -168,14 +166,13 @@ export class SourceSyncBlockStoreManager {
|
|
|
168
166
|
* @returns attributes for a new bodiedSyncBlock node
|
|
169
167
|
*/
|
|
170
168
|
generateBodiedSyncBlockAttrs() {
|
|
171
|
-
|
|
172
|
-
// eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
|
|
173
|
-
const localId = uuid();
|
|
174
|
-
const sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
|
|
175
|
-
if (!this.dataProvider || !sourceId) {
|
|
169
|
+
if (!this.dataProvider) {
|
|
176
170
|
throw new Error('Data provider not set or source id not set');
|
|
177
171
|
}
|
|
178
|
-
const
|
|
172
|
+
const {
|
|
173
|
+
resourceId,
|
|
174
|
+
localId
|
|
175
|
+
} = this.dataProvider.generateResourceId();
|
|
179
176
|
return {
|
|
180
177
|
resourceId,
|
|
181
178
|
localId
|
|
@@ -2,32 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Generates the block ARI from the source page ARI and the source block's resource ID.
|
|
5
|
-
* @param
|
|
5
|
+
* @param cloudId - the cloudId of the block. E.G the cloudId of the confluence page, or the cloudId of the Jira instance
|
|
6
|
+
* @param parentId - the parentId of the block. E.G the pageId for a confluence page, or the issueId for a Jira work item
|
|
6
7
|
* @param resourceId - the resource ID of the block node. A randomly generated UUID
|
|
8
|
+
* @param product - the product of the block. E.G 'confluence-page', 'jira-work-item'
|
|
7
9
|
* @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
|
|
8
10
|
*/
|
|
9
|
-
export var generateBlockAri = function generateBlockAri(
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var pageId = match[3];
|
|
16
|
-
return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(product, "/").concat(pageId, "/").concat(resourceId);
|
|
11
|
+
export var generateBlockAri = function generateBlockAri(_ref) {
|
|
12
|
+
var cloudId = _ref.cloudId,
|
|
13
|
+
parentId = _ref.parentId,
|
|
14
|
+
product = _ref.product,
|
|
15
|
+
resourceId = _ref.resourceId;
|
|
16
|
+
return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(product, "/").concat(parentId, "/").concat(resourceId);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Generates the block ARI from the reference synced block ARI and the resource ID
|
|
21
|
-
* @param
|
|
21
|
+
* @param cloudId - the cloudId of the block. E.G the cloudId of the confluence page, or the cloudId of the Jira instance
|
|
22
22
|
* @param resourceId - the resource ID of the reference synced block. E.G confluence-page/pageId/sourceResourceId
|
|
23
23
|
* @returns the block ARI. E.G ari:cloud:blocks:<cloudId>:synced-block/<product>/<pageId>/<resourceId>
|
|
24
24
|
*/
|
|
25
|
-
export var generateBlockAriFromReference = function generateBlockAriFromReference(
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
throw new Error("Invalid source ARI: ".concat(sourceAri));
|
|
29
|
-
}
|
|
30
|
-
var cloudId = match[1];
|
|
25
|
+
export var generateBlockAriFromReference = function generateBlockAriFromReference(_ref2) {
|
|
26
|
+
var cloudId = _ref2.cloudId,
|
|
27
|
+
resourceId = _ref2.resourceId;
|
|
31
28
|
return "ari:cloud:blocks:".concat(cloudId, ":synced-block/").concat(resourceId);
|
|
32
29
|
};
|
|
33
30
|
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
* @param pageType - the type of the page
|
|
12
12
|
* @returns the Confluence page ARI
|
|
13
13
|
*/
|
|
14
|
-
export var getConfluencePageAri = function getConfluencePageAri(
|
|
15
|
-
var
|
|
14
|
+
export var getConfluencePageAri = function getConfluencePageAri(_ref) {
|
|
15
|
+
var pageId = _ref.pageId,
|
|
16
|
+
cloudId = _ref.cloudId,
|
|
17
|
+
pageType = _ref.pageType;
|
|
16
18
|
return "ari:cloud:confluence:".concat(cloudId, ":").concat(pageType, "/").concat(pageId);
|
|
17
19
|
};
|
|
18
20
|
|
|
@@ -21,7 +23,8 @@ export var getConfluencePageAri = function getConfluencePageAri(pageId, cloudId)
|
|
|
21
23
|
* @param ari - the Confluence page ARI
|
|
22
24
|
* @returns the page ID and type
|
|
23
25
|
*/
|
|
24
|
-
export var getPageIdAndTypeFromConfluencePageAri = function getPageIdAndTypeFromConfluencePageAri(
|
|
26
|
+
export var getPageIdAndTypeFromConfluencePageAri = function getPageIdAndTypeFromConfluencePageAri(_ref2) {
|
|
27
|
+
var ari = _ref2.ari;
|
|
25
28
|
var match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/(\d+)/);
|
|
26
29
|
if (match !== null && match !== void 0 && match[2]) {
|
|
27
30
|
return {
|
|
@@ -30,40 +33,4 @@ export var getPageIdAndTypeFromConfluencePageAri = function getPageIdAndTypeFrom
|
|
|
30
33
|
};
|
|
31
34
|
}
|
|
32
35
|
throw new Error("Invalid page ARI: ".concat(ari));
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Extracts the local ID from the Confluence page content property resource ID
|
|
37
|
-
* @param resourceId - the Confluence page content property resource ID
|
|
38
|
-
* @returns the local ID
|
|
39
|
-
*/
|
|
40
|
-
export var getLocalIdFromContentPropertyResourceId = function getLocalIdFromContentPropertyResourceId(resourceId) {
|
|
41
|
-
var match = resourceId.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+\/([a-zA-Z0-9-]+)/);
|
|
42
|
-
if (match !== null && match !== void 0 && match[2]) {
|
|
43
|
-
return match[2];
|
|
44
|
-
}
|
|
45
|
-
throw new Error("Invalid resourceId: ".concat(resourceId));
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Extracts the Confluence page ARI from the Confluence content property resource ID
|
|
50
|
-
* @param resourceId - the Confluence content property resource ID
|
|
51
|
-
* @returns the Confluence page ARI
|
|
52
|
-
*/
|
|
53
|
-
export var getPageAriFromContentPropertyResourceId = function getPageAriFromContentPropertyResourceId(resourceId) {
|
|
54
|
-
var match = resourceId.match(/(ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+)\/([a-zA-Z0-9-]+)$/);
|
|
55
|
-
if (match !== null && match !== void 0 && match[1]) {
|
|
56
|
-
return match[1];
|
|
57
|
-
}
|
|
58
|
-
throw new Error("Invalid resourceId: ".concat(resourceId));
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Generates the Confluence page content property resource ID from the source ID and local ID
|
|
63
|
-
* @param sourceId - the source ID
|
|
64
|
-
* @param localId - the local ID
|
|
65
|
-
* @returns the Confluence page content property resource ID
|
|
66
|
-
*/
|
|
67
|
-
export var resourceIdFromConfluencePageSourceIdAndLocalId = function resourceIdFromConfluencePageSourceIdAndLocalId(sourceId, localId) {
|
|
68
|
-
return "".concat(sourceId, "/").concat(localId);
|
|
69
36
|
};
|
|
@@ -73,7 +73,9 @@ export var fetchConfluencePageInfo = /*#__PURE__*/function () {
|
|
|
73
73
|
while (1) switch (_context2.prev = _context2.next) {
|
|
74
74
|
case 0:
|
|
75
75
|
_context2.prev = 0;
|
|
76
|
-
_getPageIdAndTypeFrom = getPageIdAndTypeFromConfluencePageAri(
|
|
76
|
+
_getPageIdAndTypeFrom = getPageIdAndTypeFromConfluencePageAri({
|
|
77
|
+
ari: pageAri
|
|
78
|
+
}), pageType = _getPageIdAndTypeFrom.type;
|
|
77
79
|
_context2.next = 4;
|
|
78
80
|
return getConfluenceSourceInfo(pageAri);
|
|
79
81
|
case 4:
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
* @param cloudId - the cloud ID
|
|
7
7
|
* @returns the Jira work item ARI
|
|
8
8
|
*/
|
|
9
|
-
export var getJiraWorkItemAri = function getJiraWorkItemAri(
|
|
9
|
+
export var getJiraWorkItemAri = function getJiraWorkItemAri(_ref) {
|
|
10
|
+
var cloudId = _ref.cloudId,
|
|
11
|
+
workItemId = _ref.workItemId;
|
|
10
12
|
return "ari:cloud:jira:".concat(cloudId, ":issue/").concat(workItemId);
|
|
11
13
|
};
|
|
12
14
|
|
|
@@ -15,7 +17,8 @@ export var getJiraWorkItemAri = function getJiraWorkItemAri(workItemId, cloudId)
|
|
|
15
17
|
* @param ari - the Jira work item ARI
|
|
16
18
|
* @returns the Jira work item ID
|
|
17
19
|
*/
|
|
18
|
-
export var getJiraWorkItemIdFromAri = function getJiraWorkItemIdFromAri(
|
|
20
|
+
export var getJiraWorkItemIdFromAri = function getJiraWorkItemIdFromAri(_ref2) {
|
|
21
|
+
var ari = _ref2.ari;
|
|
19
22
|
var match = ari.match(/ari:cloud:jira:([^:]+):issue\/(\d+)/);
|
|
20
23
|
if (match !== null && match !== void 0 && match[2]) {
|
|
21
24
|
return match[2];
|