@atlaskit/editor-synced-block-provider 3.2.0 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -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 +22 -23
- package/dist/cjs/providers/block-service/blockServiceAPI.js +89 -26
- package/dist/cjs/providers/syncBlockProvider.js +82 -39
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +5 -8
- package/dist/cjs/store-manager/syncBlockStoreManager.js +12 -2
- 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 +4 -5
- package/dist/es2019/providers/block-service/blockServiceAPI.js +92 -27
- package/dist/es2019/providers/syncBlockProvider.js +71 -25
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +5 -8
- package/dist/es2019/store-manager/syncBlockStoreManager.js +12 -1
- 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 +4 -5
- package/dist/esm/providers/block-service/blockServiceAPI.js +88 -25
- package/dist/esm/providers/syncBlockProvider.js +81 -38
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +4 -8
- package/dist/esm/store-manager/syncBlockStoreManager.js +11 -1
- 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 +7 -8
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +39 -6
- package/dist/types/providers/syncBlockProvider.d.ts +15 -13
- package/dist/types/providers/types.d.ts +9 -6
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +4 -0
- 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 +7 -8
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +39 -6
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +15 -13
- package/dist/types-ts4.5/providers/types.d.ts +9 -6
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +4 -0
- 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
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
import { fetchWithRetry } from '../../utils/retry';
|
|
2
|
-
import { getConfluencePageAri } from './ari';
|
|
3
|
-
import { isBlogPageType } from './utils';
|
|
4
|
-
const COMMON_HEADERS = {
|
|
5
|
-
'Content-Type': 'application/json',
|
|
6
|
-
Accept: 'application/json'
|
|
7
|
-
};
|
|
8
|
-
const AGG_HEADERS = {
|
|
9
|
-
'X-ExperimentalApi': 'confluence-agg-beta'
|
|
10
|
-
};
|
|
11
|
-
const GRAPHQL_ENDPOINT = '/gateway/api/graphql';
|
|
12
|
-
const GET_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_GET';
|
|
13
|
-
const CREATE_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_CREATE';
|
|
14
|
-
const UPDATE_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_UPDATE';
|
|
15
|
-
const DELETE_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_DELETE';
|
|
16
|
-
/**
|
|
17
|
-
* Query to get the page property by key
|
|
18
|
-
* @param documentARI
|
|
19
|
-
* @param key
|
|
20
|
-
* @returns
|
|
21
|
-
*/
|
|
22
|
-
const GET_PAGE_QUERY = `query ${GET_OPERATION_NAME} ($id: ID!, $keys: [String]!) {
|
|
23
|
-
confluence {
|
|
24
|
-
page (id: $id) {
|
|
25
|
-
properties(keys: $keys) {
|
|
26
|
-
key,
|
|
27
|
-
value
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}`;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Query to get the blog page property by key
|
|
35
|
-
* @param documentARI
|
|
36
|
-
* @param key
|
|
37
|
-
* @returns
|
|
38
|
-
*/
|
|
39
|
-
const GET_BLOG_QUERY = `query ${GET_OPERATION_NAME} ($id: ID!, $keys: [String]!) {
|
|
40
|
-
confluence {
|
|
41
|
-
blogPost (id: $id) {
|
|
42
|
-
properties(keys: $keys) {
|
|
43
|
-
key,
|
|
44
|
-
value
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}`;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Query to create a page property with key and value
|
|
52
|
-
* @param documentARI
|
|
53
|
-
* @param key
|
|
54
|
-
* @param value
|
|
55
|
-
* @returns
|
|
56
|
-
*/
|
|
57
|
-
const CREATE_PAGE_QUERY = `mutation ${CREATE_OPERATION_NAME} ($input: ConfluenceCreatePagePropertyInput!){
|
|
58
|
-
confluence {
|
|
59
|
-
createPageProperty(input: $input) {
|
|
60
|
-
pageProperty {
|
|
61
|
-
key,
|
|
62
|
-
value
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}`;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Query to create a blog page property with key and value
|
|
70
|
-
* @param documentARI
|
|
71
|
-
* @param key
|
|
72
|
-
* @param value
|
|
73
|
-
* @returns
|
|
74
|
-
*/
|
|
75
|
-
const CREATE_BLOG_QUERY = `mutation ${CREATE_OPERATION_NAME} ($input: ConfluenceCreateBlogPostPropertyInput!){
|
|
76
|
-
confluence {
|
|
77
|
-
createBlogPostProperty(input: $input) {
|
|
78
|
-
blogPostProperty {
|
|
79
|
-
key,
|
|
80
|
-
value
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}`;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Query to update a page property with key and value without bumping the version
|
|
88
|
-
* @param documentARI
|
|
89
|
-
* @param key
|
|
90
|
-
* @param value
|
|
91
|
-
* @returns
|
|
92
|
-
*/
|
|
93
|
-
const UPDATE_PAGE_QUERY = `mutation ${UPDATE_OPERATION_NAME} ($input: ConfluenceUpdateValuePagePropertyInput!) {
|
|
94
|
-
confluence {
|
|
95
|
-
updateValuePageProperty(input: $input) {
|
|
96
|
-
pageProperty {
|
|
97
|
-
key,
|
|
98
|
-
value
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}`;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Query to update a blog page property with key and value without bumping the version
|
|
106
|
-
* @param documentARI
|
|
107
|
-
* @param key
|
|
108
|
-
* @param value
|
|
109
|
-
* @returns
|
|
110
|
-
*/
|
|
111
|
-
const UPDATE_BLOG_QUERY = `mutation ${UPDATE_OPERATION_NAME} ($input: ConfluenceUpdateValueBlogPostPropertyInput!) {
|
|
112
|
-
confluence {
|
|
113
|
-
updateValueBlogPostProperty(input: $input) {
|
|
114
|
-
blogPostProperty {
|
|
115
|
-
key,
|
|
116
|
-
value
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}`;
|
|
121
|
-
const DELETE_PAGE_QUERY = `mutation ${DELETE_OPERATION_NAME} ($input: ConfluenceDeletePagePropertyInput!) {
|
|
122
|
-
confluence {
|
|
123
|
-
deletePageProperty(input: $input) {
|
|
124
|
-
success, errors {
|
|
125
|
-
message
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}`;
|
|
130
|
-
const DELETE_BLOG_QUERY = `mutation ${DELETE_OPERATION_NAME} ($input: ConfluenceDeleteBlogPostPropertyInput!) {
|
|
131
|
-
confluence {
|
|
132
|
-
deleteBlogPostProperty(input: $input) {
|
|
133
|
-
success, errors {
|
|
134
|
-
message
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}`;
|
|
139
|
-
export const getContentProperty = async ({
|
|
140
|
-
pageId,
|
|
141
|
-
key,
|
|
142
|
-
cloudId,
|
|
143
|
-
pageType
|
|
144
|
-
}) => {
|
|
145
|
-
const documentARI = getConfluencePageAri(pageId, cloudId, pageType);
|
|
146
|
-
const isBlog = isBlogPageType(pageType);
|
|
147
|
-
const bodyData = {
|
|
148
|
-
query: isBlog ? GET_BLOG_QUERY : GET_PAGE_QUERY,
|
|
149
|
-
operationName: GET_OPERATION_NAME,
|
|
150
|
-
variables: {
|
|
151
|
-
id: documentARI,
|
|
152
|
-
keys: [key]
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
|
|
156
|
-
method: 'POST',
|
|
157
|
-
headers: {
|
|
158
|
-
...COMMON_HEADERS,
|
|
159
|
-
...AGG_HEADERS
|
|
160
|
-
},
|
|
161
|
-
body: JSON.stringify(bodyData)
|
|
162
|
-
});
|
|
163
|
-
if (!response.ok) {
|
|
164
|
-
throw new Error(`Failed to get content property: ${response.statusText}`);
|
|
165
|
-
}
|
|
166
|
-
return await response.json();
|
|
167
|
-
};
|
|
168
|
-
export const updateContentProperty = async ({
|
|
169
|
-
pageId,
|
|
170
|
-
key,
|
|
171
|
-
value,
|
|
172
|
-
cloudId,
|
|
173
|
-
pageType
|
|
174
|
-
}) => {
|
|
175
|
-
const documentARI = getConfluencePageAri(pageId, cloudId, pageType);
|
|
176
|
-
const isBlog = isBlogPageType(pageType);
|
|
177
|
-
const useSameVersion = {
|
|
178
|
-
useSameVersion: true
|
|
179
|
-
};
|
|
180
|
-
let input = {
|
|
181
|
-
...(isBlog ? {
|
|
182
|
-
blogPostId: documentARI
|
|
183
|
-
} : {
|
|
184
|
-
pageId: documentARI
|
|
185
|
-
}),
|
|
186
|
-
key,
|
|
187
|
-
value: JSON.stringify(value)
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
// Blog content properties don't support the useSameVersion flag at the moment
|
|
191
|
-
if (!isBlog) {
|
|
192
|
-
input = {
|
|
193
|
-
...input,
|
|
194
|
-
...useSameVersion
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
const bodyData = {
|
|
198
|
-
query: isBlog ? UPDATE_BLOG_QUERY : UPDATE_PAGE_QUERY,
|
|
199
|
-
operationName: UPDATE_OPERATION_NAME,
|
|
200
|
-
variables: {
|
|
201
|
-
input
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
const response = await fetch(GRAPHQL_ENDPOINT, {
|
|
205
|
-
method: 'POST',
|
|
206
|
-
headers: {
|
|
207
|
-
...COMMON_HEADERS,
|
|
208
|
-
...AGG_HEADERS
|
|
209
|
-
},
|
|
210
|
-
body: JSON.stringify(bodyData)
|
|
211
|
-
});
|
|
212
|
-
if (!response.ok) {
|
|
213
|
-
throw new Error(`Failed to update content property: ${response.statusText}`);
|
|
214
|
-
}
|
|
215
|
-
return await response.json();
|
|
216
|
-
};
|
|
217
|
-
export const createContentProperty = async ({
|
|
218
|
-
pageId,
|
|
219
|
-
key,
|
|
220
|
-
value,
|
|
221
|
-
cloudId,
|
|
222
|
-
pageType
|
|
223
|
-
}) => {
|
|
224
|
-
const documentARI = getConfluencePageAri(pageId, cloudId, pageType);
|
|
225
|
-
const isBlog = isBlogPageType(pageType);
|
|
226
|
-
const bodyData = {
|
|
227
|
-
query: isBlog ? CREATE_BLOG_QUERY : CREATE_PAGE_QUERY,
|
|
228
|
-
operationName: CREATE_OPERATION_NAME,
|
|
229
|
-
variables: {
|
|
230
|
-
input: {
|
|
231
|
-
...(isBlog ? {
|
|
232
|
-
blogPostId: documentARI
|
|
233
|
-
} : {
|
|
234
|
-
pageId: documentARI
|
|
235
|
-
}),
|
|
236
|
-
key,
|
|
237
|
-
value: JSON.stringify(value)
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
|
|
242
|
-
method: 'POST',
|
|
243
|
-
headers: {
|
|
244
|
-
...COMMON_HEADERS,
|
|
245
|
-
...AGG_HEADERS
|
|
246
|
-
},
|
|
247
|
-
body: JSON.stringify(bodyData)
|
|
248
|
-
});
|
|
249
|
-
if (!response.ok) {
|
|
250
|
-
throw new Error(`Failed to create content property: ${response.statusText}`);
|
|
251
|
-
}
|
|
252
|
-
return await response.json();
|
|
253
|
-
};
|
|
254
|
-
export const deleteContentProperty = async ({
|
|
255
|
-
pageId,
|
|
256
|
-
cloudId,
|
|
257
|
-
pageType,
|
|
258
|
-
key
|
|
259
|
-
}) => {
|
|
260
|
-
const documentARI = getConfluencePageAri(pageId, cloudId, pageType);
|
|
261
|
-
const isBlog = isBlogPageType(pageType);
|
|
262
|
-
const bodyData = {
|
|
263
|
-
query: isBlog ? DELETE_BLOG_QUERY : DELETE_PAGE_QUERY,
|
|
264
|
-
operationName: DELETE_OPERATION_NAME,
|
|
265
|
-
variables: {
|
|
266
|
-
input: {
|
|
267
|
-
...(isBlog ? {
|
|
268
|
-
blogPostId: documentARI
|
|
269
|
-
} : {
|
|
270
|
-
pageId: documentARI
|
|
271
|
-
}),
|
|
272
|
-
key
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
|
|
277
|
-
method: 'POST',
|
|
278
|
-
headers: {
|
|
279
|
-
...COMMON_HEADERS,
|
|
280
|
-
...AGG_HEADERS
|
|
281
|
-
},
|
|
282
|
-
body: JSON.stringify(bodyData)
|
|
283
|
-
});
|
|
284
|
-
if (!response.ok) {
|
|
285
|
-
throw new Error(`Failed to delete content property: ${response.statusText}`);
|
|
286
|
-
}
|
|
287
|
-
return await response.json();
|
|
288
|
-
};
|
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import { useMemo } from 'react';
|
|
3
|
-
import { getConfluencePageAri, getLocalIdFromContentPropertyResourceId, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId } from '../../clients/confluence/ari';
|
|
4
|
-
import { getContentProperty, createContentProperty, updateContentProperty, deleteContentProperty } from '../../clients/confluence/contentProperty';
|
|
5
|
-
import { isBlogPageType } from '../../clients/confluence/utils';
|
|
6
|
-
import { SyncBlockError } from '../../common/types';
|
|
7
|
-
import { stringifyError } from '../../utils/errorHandling';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Configuration for Content API providers
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const getContentPropertyKey = (contentPropertyKey, localId) => {
|
|
14
|
-
return contentPropertyKey + '-' + localId;
|
|
15
|
-
};
|
|
16
|
-
const parseSyncedBlockContentPropertyValue = value => {
|
|
17
|
-
try {
|
|
18
|
-
if (value !== '') {
|
|
19
|
-
const parsedValue = JSON.parse(value);
|
|
20
|
-
if (typeof parsedValue.content === 'object') {
|
|
21
|
-
return parsedValue;
|
|
22
|
-
}
|
|
23
|
-
throw new Error('Cannot parse synced block data: required properties missing in value');
|
|
24
|
-
} else {
|
|
25
|
-
throw new Error('Cannot parse synced block data: value is empty');
|
|
26
|
-
}
|
|
27
|
-
} catch (error) {
|
|
28
|
-
throw new Error(`Failed to parse synced block data: ${error}`);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const getResponseError = contentProperty => {
|
|
32
|
-
var _content$properties;
|
|
33
|
-
const content = 'blogPost' in contentProperty.data.confluence ? contentProperty.data.confluence.blogPost : contentProperty.data.confluence.page;
|
|
34
|
-
if (!content) {
|
|
35
|
-
return SyncBlockError.Forbidden;
|
|
36
|
-
}
|
|
37
|
-
if (!((_content$properties = content.properties) !== null && _content$properties !== void 0 && _content$properties[0])) {
|
|
38
|
-
return SyncBlockError.NotFound;
|
|
39
|
-
}
|
|
40
|
-
return SyncBlockError.Errored;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* ADFFetchProvider implementation that fetches synced block data from Confluence Content API
|
|
45
|
-
*/
|
|
46
|
-
class ConfluenceADFFetchProvider {
|
|
47
|
-
constructor(config) {
|
|
48
|
-
this.config = config;
|
|
49
|
-
}
|
|
50
|
-
async fetchData(resourceId) {
|
|
51
|
-
const {
|
|
52
|
-
id: pageId,
|
|
53
|
-
type: pageType
|
|
54
|
-
} = getPageIdAndTypeFromConfluencePageAri(resourceId);
|
|
55
|
-
const localId = getLocalIdFromContentPropertyResourceId(resourceId);
|
|
56
|
-
try {
|
|
57
|
-
const key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
58
|
-
const options = {
|
|
59
|
-
pageId,
|
|
60
|
-
key,
|
|
61
|
-
cloudId: this.config.cloudId,
|
|
62
|
-
pageType
|
|
63
|
-
};
|
|
64
|
-
let error;
|
|
65
|
-
let value;
|
|
66
|
-
if (isBlogPageType(pageType)) {
|
|
67
|
-
var _contentProperty$data, _contentProperty$data2, _contentProperty$data3;
|
|
68
|
-
const contentProperty = await getContentProperty(options);
|
|
69
|
-
value = (_contentProperty$data = contentProperty.data.confluence.blogPost) === null || _contentProperty$data === void 0 ? void 0 : (_contentProperty$data2 = _contentProperty$data.properties) === null || _contentProperty$data2 === void 0 ? void 0 : (_contentProperty$data3 = _contentProperty$data2[0]) === null || _contentProperty$data3 === void 0 ? void 0 : _contentProperty$data3.value;
|
|
70
|
-
error = getResponseError(contentProperty);
|
|
71
|
-
} else {
|
|
72
|
-
var _contentProperty$data4, _contentProperty$data5, _contentProperty$data6;
|
|
73
|
-
const contentProperty = await getContentProperty(options);
|
|
74
|
-
value = (_contentProperty$data4 = contentProperty.data.confluence.page) === null || _contentProperty$data4 === void 0 ? void 0 : (_contentProperty$data5 = _contentProperty$data4.properties) === null || _contentProperty$data5 === void 0 ? void 0 : (_contentProperty$data6 = _contentProperty$data5[0]) === null || _contentProperty$data6 === void 0 ? void 0 : _contentProperty$data6.value;
|
|
75
|
-
error = getResponseError(contentProperty);
|
|
76
|
-
}
|
|
77
|
-
if (!value) {
|
|
78
|
-
return {
|
|
79
|
-
error,
|
|
80
|
-
resourceId
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Parse the synced block content from the property value
|
|
85
|
-
const syncedBlockData = parseSyncedBlockContentPropertyValue(value);
|
|
86
|
-
return {
|
|
87
|
-
data: {
|
|
88
|
-
content: syncedBlockData.content,
|
|
89
|
-
// If the block instance ID is not set, use the local ID from the fetch data request
|
|
90
|
-
// This is a fallback for the case where the block instance ID is not set in the synced block data (old data)
|
|
91
|
-
blockInstanceId: syncedBlockData.blockInstanceId || localId,
|
|
92
|
-
// If the resource ID is not set, use the resource ID from the fetch data request
|
|
93
|
-
// This is a fallback for the case where the resource ID is not set in the synced block data (old data)
|
|
94
|
-
resourceId: syncedBlockData.resourceId || resourceId,
|
|
95
|
-
// If the product is not set, use the default product 'confluence-page'
|
|
96
|
-
// This is a fallback for the case where the product is not set in the synced block data (old data)
|
|
97
|
-
product: syncedBlockData.product || 'confluence-page',
|
|
98
|
-
// If the source Ari is not set, use the resource ID as the source Ari
|
|
99
|
-
// This is a fallback for the case where the source Ari is not set in the synced block data (old data)
|
|
100
|
-
sourceAri: syncedBlockData.sourceAri || resourceId
|
|
101
|
-
},
|
|
102
|
-
resourceId
|
|
103
|
-
};
|
|
104
|
-
} catch {
|
|
105
|
-
return {
|
|
106
|
-
error: SyncBlockError.Errored,
|
|
107
|
-
resourceId
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* ADFWriteProvider implementation that writes synced block data to Confluence Content API
|
|
115
|
-
*/
|
|
116
|
-
class ConfluenceADFWriteProvider {
|
|
117
|
-
constructor(config) {
|
|
118
|
-
_defineProperty(this, "product", 'confluence-page');
|
|
119
|
-
_defineProperty(this, "createNewContentProperty", async (pageId, key, value, pageType) => {
|
|
120
|
-
const options = {
|
|
121
|
-
pageId,
|
|
122
|
-
key,
|
|
123
|
-
value,
|
|
124
|
-
cloudId: this.config.cloudId,
|
|
125
|
-
pageType
|
|
126
|
-
};
|
|
127
|
-
if (isBlogPageType(pageType)) {
|
|
128
|
-
var _contentProperty$data7;
|
|
129
|
-
const contentProperty = await createContentProperty(options);
|
|
130
|
-
if (((_contentProperty$data7 = contentProperty.data.confluence.createBlogPostProperty.blogPostProperty) === null || _contentProperty$data7 === void 0 ? void 0 : _contentProperty$data7.key) === key) {
|
|
131
|
-
return key;
|
|
132
|
-
} else {
|
|
133
|
-
return Promise.reject('Failed to create blog post content property');
|
|
134
|
-
}
|
|
135
|
-
} else {
|
|
136
|
-
var _contentProperty$data8;
|
|
137
|
-
const contentProperty = await createContentProperty(options);
|
|
138
|
-
if (((_contentProperty$data8 = contentProperty.data.confluence.createPageProperty.pageProperty) === null || _contentProperty$data8 === void 0 ? void 0 : _contentProperty$data8.key) === key) {
|
|
139
|
-
return key;
|
|
140
|
-
} else {
|
|
141
|
-
return Promise.reject('Failed to create page content property');
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
this.config = config;
|
|
146
|
-
}
|
|
147
|
-
async writeData(syncBlockData) {
|
|
148
|
-
let match;
|
|
149
|
-
const {
|
|
150
|
-
resourceId
|
|
151
|
-
} = syncBlockData;
|
|
152
|
-
try {
|
|
153
|
-
match = getPageIdAndTypeFromConfluencePageAri(resourceId);
|
|
154
|
-
} catch (error) {
|
|
155
|
-
return {
|
|
156
|
-
error: stringifyError(error)
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
const {
|
|
160
|
-
id: pageId,
|
|
161
|
-
type: pageType
|
|
162
|
-
} = match;
|
|
163
|
-
try {
|
|
164
|
-
// Update existing content property
|
|
165
|
-
const localId = getLocalIdFromContentPropertyResourceId(resourceId);
|
|
166
|
-
const key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
167
|
-
const sourceAri = getConfluencePageAri(pageId, this.config.cloudId, pageType);
|
|
168
|
-
const syncBlockDataWithSourceDocumentAri = {
|
|
169
|
-
...syncBlockData,
|
|
170
|
-
product: 'confluence-page',
|
|
171
|
-
sourceAri
|
|
172
|
-
};
|
|
173
|
-
const options = {
|
|
174
|
-
pageId,
|
|
175
|
-
key,
|
|
176
|
-
value: syncBlockDataWithSourceDocumentAri,
|
|
177
|
-
cloudId: this.config.cloudId,
|
|
178
|
-
pageType
|
|
179
|
-
};
|
|
180
|
-
const updatePayload = await updateContentProperty(options);
|
|
181
|
-
const updateResult = isBlogPageType(pageType) ? updatePayload.data.confluence.updateValueBlogPostProperty.blogPostProperty : updatePayload.data.confluence.updateValuePageProperty.pageProperty;
|
|
182
|
-
if ((updateResult === null || updateResult === void 0 ? void 0 : updateResult.key) === key) {
|
|
183
|
-
return {
|
|
184
|
-
resourceId
|
|
185
|
-
};
|
|
186
|
-
} else {
|
|
187
|
-
return {
|
|
188
|
-
error: `Failed to update ${pageType} content property`
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
} catch {
|
|
192
|
-
return {
|
|
193
|
-
error: `Failed to write ${pageType}`
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
async createData(syncBlockData) {
|
|
198
|
-
let match;
|
|
199
|
-
const {
|
|
200
|
-
resourceId
|
|
201
|
-
} = syncBlockData;
|
|
202
|
-
try {
|
|
203
|
-
match = getPageIdAndTypeFromConfluencePageAri(resourceId);
|
|
204
|
-
} catch (error) {
|
|
205
|
-
return {
|
|
206
|
-
error: stringifyError(error)
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
const {
|
|
210
|
-
id: pageId,
|
|
211
|
-
type: pageType
|
|
212
|
-
} = match;
|
|
213
|
-
try {
|
|
214
|
-
const localId = getLocalIdFromContentPropertyResourceId(resourceId);
|
|
215
|
-
const key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
216
|
-
const sourceAri = getConfluencePageAri(pageId, this.config.cloudId, pageType);
|
|
217
|
-
const syncBlockDataWithSourceDocumentAri = {
|
|
218
|
-
...syncBlockData,
|
|
219
|
-
product: 'confluence-page',
|
|
220
|
-
sourceAri
|
|
221
|
-
};
|
|
222
|
-
await this.createNewContentProperty(pageId, key, syncBlockDataWithSourceDocumentAri, pageType);
|
|
223
|
-
return {
|
|
224
|
-
resourceId
|
|
225
|
-
};
|
|
226
|
-
} catch (error) {
|
|
227
|
-
return Promise.resolve({
|
|
228
|
-
error: stringifyError(error)
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
async deleteData(resourceId) {
|
|
233
|
-
let deletePayload, deleteResult, match;
|
|
234
|
-
try {
|
|
235
|
-
match = getPageIdAndTypeFromConfluencePageAri(resourceId);
|
|
236
|
-
} catch (error) {
|
|
237
|
-
return {
|
|
238
|
-
resourceId,
|
|
239
|
-
success: false,
|
|
240
|
-
error: stringifyError(error)
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
const {
|
|
244
|
-
id: pageId,
|
|
245
|
-
type: pageType
|
|
246
|
-
} = match;
|
|
247
|
-
try {
|
|
248
|
-
const localId = getLocalIdFromContentPropertyResourceId(resourceId);
|
|
249
|
-
const key = getContentPropertyKey(this.config.contentPropertyKey, localId);
|
|
250
|
-
const options = {
|
|
251
|
-
pageId,
|
|
252
|
-
key,
|
|
253
|
-
cloudId: this.config.cloudId,
|
|
254
|
-
pageType
|
|
255
|
-
};
|
|
256
|
-
deletePayload = await deleteContentProperty(options);
|
|
257
|
-
deleteResult = isBlogPageType(pageType) ? deletePayload.data.confluence.deleteBlogPostProperty : deletePayload.data.confluence.deletePageProperty;
|
|
258
|
-
} catch (error) {
|
|
259
|
-
var _stringifyError;
|
|
260
|
-
return {
|
|
261
|
-
resourceId,
|
|
262
|
-
success: false,
|
|
263
|
-
error: (_stringifyError = stringifyError(error)) !== null && _stringifyError !== void 0 ? _stringifyError : `Fail to delete ${pageType} content property`
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
return {
|
|
267
|
-
resourceId,
|
|
268
|
-
success: deleteResult.success,
|
|
269
|
-
error: deleteResult.errors.join()
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
generateResourceId(sourceId, localId) {
|
|
273
|
-
return resourceIdFromConfluencePageSourceIdAndLocalId(sourceId, localId);
|
|
274
|
-
}
|
|
275
|
-
generateResourceIdForReference(sourceId) {
|
|
276
|
-
return sourceId;
|
|
277
|
-
}
|
|
278
|
-
updateReferenceData(_blocks, _noContent) {
|
|
279
|
-
return Promise.resolve({
|
|
280
|
-
success: true
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Factory function to create both providers with shared configuration
|
|
287
|
-
*/
|
|
288
|
-
const createContentAPIProviders = config => {
|
|
289
|
-
const fetchProvider = new ConfluenceADFFetchProvider(config);
|
|
290
|
-
const writeProvider = new ConfluenceADFWriteProvider(config);
|
|
291
|
-
return {
|
|
292
|
-
fetchProvider,
|
|
293
|
-
writeProvider
|
|
294
|
-
};
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Convenience function to create providers with default content property key
|
|
299
|
-
*/
|
|
300
|
-
export const createContentAPIProvidersWithDefaultKey = cloudId => {
|
|
301
|
-
return createContentAPIProviders({
|
|
302
|
-
cloudId,
|
|
303
|
-
contentPropertyKey: 'editor-synced-block'
|
|
304
|
-
});
|
|
305
|
-
};
|
|
306
|
-
export const useMemoizedContentAPIProviders = cloudId => {
|
|
307
|
-
return useMemo(() => {
|
|
308
|
-
return createContentAPIProvidersWithDefaultKey(cloudId);
|
|
309
|
-
}, [cloudId]);
|
|
310
|
-
};
|