@atlaskit/editor-synced-block-provider 0.6.1 → 0.7.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.
@@ -4,8 +4,9 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
4
  import _createClass from "@babel/runtime/helpers/createClass";
5
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
6
  import { useMemo } from 'react';
7
- import { getLocalIdFromAri, getPageIdFromAri, resourceIdFromSourceAndLocalId } from '../utils/ari';
7
+ import { getLocalIdFromAri, getPageIdAndTypeFromAri, resourceIdFromSourceAndLocalId } from '../utils/ari';
8
8
  import { getContentProperty, createContentProperty, updateContentProperty } from '../utils/contentProperty';
9
+ import { isBlogPageType } from '../utils/utils';
9
10
 
10
11
  /**
11
12
  * Configuration for Content API providers
@@ -16,17 +17,19 @@ var getContentPropertyKey = function getContentPropertyKey(contentPropertyKey, l
16
17
  };
17
18
  var parseSyncedBlockContentPropertyValue = function parseSyncedBlockContentPropertyValue(value) {
18
19
  try {
19
- if (typeof value === 'string') {
20
- return JSON.parse(value);
20
+ if (value !== '') {
21
+ var parsedValue = JSON.parse(value);
22
+ if (parsedValue.content) {
23
+ return parsedValue;
24
+ }
21
25
  }
22
- return value;
23
26
  } catch (error) {
24
27
  // eslint-disable-next-line no-console
25
28
  console.error('Failed to parse synced block content:', error);
26
- return {
27
- content: undefined
28
- };
29
29
  }
30
+ return {
31
+ content: undefined
32
+ };
30
33
  };
31
34
 
32
35
  /**
@@ -41,30 +44,43 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
41
44
  key: "fetchData",
42
45
  value: function () {
43
46
  var _fetchData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resourceId) {
44
- var _contentProperty$data;
45
- var pageId, localId, key, options, contentProperty, value, syncedBlockData;
47
+ var _getPageIdAndTypeFrom, pageId, pageType, localId, key, options, value, _contentProperty$data, contentProperty, _contentProperty$data2, _contentProperty, syncedBlockData;
46
48
  return _regeneratorRuntime.wrap(function _callee$(_context) {
47
49
  while (1) switch (_context.prev = _context.next) {
48
50
  case 0:
49
- pageId = getPageIdFromAri(resourceId);
51
+ _getPageIdAndTypeFrom = getPageIdAndTypeFromAri(resourceId), pageId = _getPageIdAndTypeFrom.id, pageType = _getPageIdAndTypeFrom.type;
50
52
  localId = getLocalIdFromAri(resourceId);
51
53
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
52
54
  options = {
53
55
  pageId: pageId,
54
56
  key: key,
55
- cloudId: this.config.cloudId
57
+ cloudId: this.config.cloudId,
58
+ pageType: pageType
56
59
  };
57
- _context.next = 6;
60
+ if (!isBlogPageType(pageType)) {
61
+ _context.next = 11;
62
+ break;
63
+ }
64
+ _context.next = 7;
58
65
  return getContentProperty(options);
59
- case 6:
66
+ case 7:
60
67
  contentProperty = _context.sent;
61
- value = (_contentProperty$data = contentProperty.data.confluence.page.properties) === null || _contentProperty$data === void 0 || (_contentProperty$data = _contentProperty$data[0]) === null || _contentProperty$data === void 0 ? void 0 : _contentProperty$data.value;
68
+ value = (_contentProperty$data = contentProperty.data.confluence.blogPost.properties) === null || _contentProperty$data === void 0 || (_contentProperty$data = _contentProperty$data[0]) === null || _contentProperty$data === void 0 ? void 0 : _contentProperty$data.value;
69
+ _context.next = 15;
70
+ break;
71
+ case 11:
72
+ _context.next = 13;
73
+ return getContentProperty(options);
74
+ case 13:
75
+ _contentProperty = _context.sent;
76
+ value = (_contentProperty$data2 = _contentProperty.data.confluence.page.properties) === null || _contentProperty$data2 === void 0 || (_contentProperty$data2 = _contentProperty$data2[0]) === null || _contentProperty$data2 === void 0 ? void 0 : _contentProperty$data2.value;
77
+ case 15:
62
78
  if (value) {
63
- _context.next = 10;
79
+ _context.next = 17;
64
80
  break;
65
81
  }
66
82
  throw new Error('Content property value does not exist');
67
- case 10:
83
+ case 17:
68
84
  // Parse the synced block content from the property value
69
85
  syncedBlockData = parseSyncedBlockContentPropertyValue(value);
70
86
  return _context.abrupt("return", {
@@ -72,7 +88,7 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
72
88
  resourceId: resourceId,
73
89
  localId: localId
74
90
  });
75
- case 12:
91
+ case 19:
76
92
  case "end":
77
93
  return _context.stop();
78
94
  }
@@ -93,35 +109,55 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
93
109
  var _this = this;
94
110
  _classCallCheck(this, ConfluenceADFWriteProvider);
95
111
  _defineProperty(this, "createNewContentProperty", /*#__PURE__*/function () {
96
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(pageId, key, value) {
97
- var _contentProperty$data2;
98
- var contentProperty;
112
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(pageId, key, value, pageType) {
113
+ var options, _contentProperty$data3, contentProperty, _contentProperty2$dat, _contentProperty2;
99
114
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
100
115
  while (1) switch (_context2.prev = _context2.next) {
101
116
  case 0:
102
- _context2.next = 2;
103
- return createContentProperty({
117
+ options = {
104
118
  pageId: pageId,
105
119
  key: key,
106
120
  value: value,
107
- cloudId: _this.config.cloudId
108
- });
109
- case 2:
121
+ cloudId: _this.config.cloudId,
122
+ pageType: pageType
123
+ };
124
+ if (!isBlogPageType(pageType)) {
125
+ _context2.next = 12;
126
+ break;
127
+ }
128
+ _context2.next = 4;
129
+ return createContentProperty(options);
130
+ case 4:
110
131
  contentProperty = _context2.sent;
111
- if (!(((_contentProperty$data2 = contentProperty.data.confluence.createPageProperty.pageProperty) === null || _contentProperty$data2 === void 0 ? void 0 : _contentProperty$data2.key) === key)) {
112
- _context2.next = 7;
132
+ if (!(((_contentProperty$data3 = contentProperty.data.confluence.createBlogPostProperty.blogPostProperty) === null || _contentProperty$data3 === void 0 ? void 0 : _contentProperty$data3.key) === key)) {
133
+ _context2.next = 9;
113
134
  break;
114
135
  }
115
136
  return _context2.abrupt("return", key);
116
- case 7:
117
- throw new Error('Failed to create content property');
118
- case 8:
137
+ case 9:
138
+ throw new Error('Failed to create blog post content property');
139
+ case 10:
140
+ _context2.next = 20;
141
+ break;
142
+ case 12:
143
+ _context2.next = 14;
144
+ return createContentProperty(options);
145
+ case 14:
146
+ _contentProperty2 = _context2.sent;
147
+ if (!(((_contentProperty2$dat = _contentProperty2.data.confluence.createPageProperty.pageProperty) === null || _contentProperty2$dat === void 0 ? void 0 : _contentProperty2$dat.key) === key)) {
148
+ _context2.next = 19;
149
+ break;
150
+ }
151
+ return _context2.abrupt("return", key);
152
+ case 19:
153
+ throw new Error('Failed to create page content property');
154
+ case 20:
119
155
  case "end":
120
156
  return _context2.stop();
121
157
  }
122
158
  }, _callee2);
123
159
  }));
124
- return function (_x2, _x3, _x4) {
160
+ return function (_x2, _x3, _x4, _x5) {
125
161
  return _ref.apply(this, arguments);
126
162
  };
127
163
  }());
@@ -131,11 +167,11 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
131
167
  key: "writeData",
132
168
  value: function () {
133
169
  var _writeData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(data) {
134
- var pageId, syncedBlockValue, _contentProperty$data3, localId, key, contentProperty, _key;
170
+ var _getPageIdAndTypeFrom2, pageId, pageType, syncedBlockValue, localId, key, options, _contentProperty$data4, contentProperty, _contentProperty3$dat, _contentProperty3, _key;
135
171
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
136
172
  while (1) switch (_context3.prev = _context3.next) {
137
173
  case 0:
138
- pageId = getPageIdFromAri(data.resourceId);
174
+ _getPageIdAndTypeFrom2 = getPageIdAndTypeFromAri(data.resourceId), pageId = _getPageIdAndTypeFrom2.id, pageType = _getPageIdAndTypeFrom2.type;
139
175
  if (!(data.sourceDocumentAri && data.resourceId !== resourceIdFromSourceAndLocalId(data.sourceDocumentAri, data.localId))) {
140
176
  _context3.next = 3;
141
177
  break;
@@ -146,48 +182,75 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
146
182
  content: data.content
147
183
  });
148
184
  if (!data.resourceId) {
149
- _context3.next = 21;
185
+ _context3.next = 37;
150
186
  break;
151
187
  }
152
188
  // Update existing content property
153
189
  localId = getLocalIdFromAri(data.resourceId);
154
190
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
155
- _context3.next = 9;
156
- return updateContentProperty({
191
+ options = {
157
192
  pageId: pageId,
158
193
  key: key,
159
194
  value: syncedBlockValue,
160
- cloudId: this.config.cloudId
161
- });
162
- case 9:
195
+ cloudId: this.config.cloudId,
196
+ pageType: pageType
197
+ };
198
+ if (!isBlogPageType(pageType)) {
199
+ _context3.next = 23;
200
+ break;
201
+ }
202
+ _context3.next = 11;
203
+ return updateContentProperty(options);
204
+ case 11:
163
205
  contentProperty = _context3.sent;
164
- if (!(((_contentProperty$data3 = contentProperty.data.confluence.updateValuePageProperty.pageProperty) === null || _contentProperty$data3 === void 0 ? void 0 : _contentProperty$data3.key) === key)) {
165
- _context3.next = 14;
206
+ if (!(((_contentProperty$data4 = contentProperty.data.confluence.updateValueBlogPostProperty.blogPostProperty) === null || _contentProperty$data4 === void 0 ? void 0 : _contentProperty$data4.key) === key)) {
207
+ _context3.next = 16;
166
208
  break;
167
209
  }
168
210
  return _context3.abrupt("return", key);
169
- case 14:
170
- if (!(contentProperty.data.confluence.updateValuePageProperty.pageProperty === null)) {
171
- _context3.next = 18;
211
+ case 16:
212
+ if (!(contentProperty.data.confluence.updateValueBlogPostProperty.blogPostProperty === null)) {
213
+ _context3.next = 20;
172
214
  break;
173
215
  }
174
- return _context3.abrupt("return", this.createNewContentProperty(pageId, key, syncedBlockValue));
175
- case 18:
216
+ return _context3.abrupt("return", this.createNewContentProperty(pageId, key, syncedBlockValue, pageType));
217
+ case 20:
218
+ throw new Error('Failed to update blog post content property');
219
+ case 21:
220
+ _context3.next = 35;
221
+ break;
222
+ case 23:
223
+ _context3.next = 25;
224
+ return updateContentProperty(options);
225
+ case 25:
226
+ _contentProperty3 = _context3.sent;
227
+ if (!(((_contentProperty3$dat = _contentProperty3.data.confluence.updateValuePageProperty.pageProperty) === null || _contentProperty3$dat === void 0 ? void 0 : _contentProperty3$dat.key) === key)) {
228
+ _context3.next = 30;
229
+ break;
230
+ }
231
+ return _context3.abrupt("return", key);
232
+ case 30:
233
+ if (!(_contentProperty3.data.confluence.updateValuePageProperty.pageProperty === null)) {
234
+ _context3.next = 34;
235
+ break;
236
+ }
237
+ return _context3.abrupt("return", this.createNewContentProperty(pageId, key, syncedBlockValue, pageType));
238
+ case 34:
176
239
  throw new Error('Failed to update content property');
177
- case 19:
178
- _context3.next = 23;
240
+ case 35:
241
+ _context3.next = 39;
179
242
  break;
180
- case 21:
243
+ case 37:
181
244
  // Create new content property
182
245
  _key = getContentPropertyKey(this.config.contentPropertyKey, data.localId);
183
- return _context3.abrupt("return", this.createNewContentProperty(pageId, _key, syncedBlockValue));
184
- case 23:
246
+ return _context3.abrupt("return", this.createNewContentProperty(pageId, _key, syncedBlockValue, pageType));
247
+ case 39:
185
248
  case "end":
186
249
  return _context3.stop();
187
250
  }
188
251
  }, _callee3, this);
189
252
  }));
190
- function writeData(_x5) {
253
+ function writeData(_x6) {
191
254
  return _writeData.apply(this, arguments);
192
255
  }
193
256
  return writeData;
@@ -1,31 +1,28 @@
1
+ /* eslint-disable require-unicode-regexp */
2
+
1
3
  export var getConfluencePageAri = function getConfluencePageAri(pageId, cloudId) {
2
- return "ari:cloud:confluence:".concat(cloudId, ":page/").concat(pageId);
4
+ var pageType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'page';
5
+ return "ari:cloud:confluence:".concat(cloudId, ":").concat(pageType, "/").concat(pageId);
3
6
  };
4
- export var getPageIdFromAri = function getPageIdFromAri(ari) {
5
- // eslint-disable-next-line require-unicode-regexp
6
- var match = ari.match(/ari:cloud:confluence:[^:]+:page\/(\d+)/);
7
- if (match !== null && match !== void 0 && match[1]) {
8
- return match[1];
7
+ export var getPageIdAndTypeFromAri = function getPageIdAndTypeFromAri(ari) {
8
+ var match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/(\d+)/);
9
+ if (match !== null && match !== void 0 && match[2]) {
10
+ return {
11
+ type: match[1],
12
+ id: match[2]
13
+ };
9
14
  }
10
15
  throw new Error("Invalid page ARI: ".concat(ari));
11
16
  };
12
-
13
- /**
14
- *
15
- * @param ari ari:cloud:confluence:<cloudId>:page/<pageId>/<localId>
16
- * @returns
17
- */
18
17
  export var getLocalIdFromAri = function getLocalIdFromAri(ari) {
19
- // eslint-disable-next-line require-unicode-regexp
20
- var match = ari.match(/ari:cloud:confluence:[^:]+:page\/\d+\/([a-zA-Z0-9-]+)/);
21
- if (match !== null && match !== void 0 && match[1]) {
22
- return match[1];
18
+ var match = ari.match(/ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+\/([a-zA-Z0-9-]+)/);
19
+ if (match !== null && match !== void 0 && match[2]) {
20
+ return match[2];
23
21
  }
24
22
  throw new Error("Invalid page ARI: ".concat(ari));
25
23
  };
26
24
  export var getPageARIFromResourceId = function getPageARIFromResourceId(resourceId) {
27
- // eslint-disable-next-line require-unicode-regexp
28
- var match = resourceId.match(/(ari:cloud:confluence:[^:]+:page\/\d+)\/([a-zA-Z0-9-]+)$/);
25
+ var match = resourceId.match(/(ari:cloud:confluence:[^:]+:(page|blogpost)\/\d+)\/([a-zA-Z0-9-]+)$/);
29
26
  if (match !== null && match !== void 0 && match[1]) {
30
27
  return match[1];
31
28
  }
@@ -34,8 +31,15 @@ export var getPageARIFromResourceId = function getPageARIFromResourceId(resource
34
31
  export var getContentPropertyAri = function getContentPropertyAri(contentPropertyId, cloudId) {
35
32
  return "ari:cloud:confluence:".concat(cloudId, ":content/").concat(contentPropertyId);
36
33
  };
34
+
35
+ /**
36
+ * DEPRECATED - Will be removed in the future
37
+ * @private
38
+ * @deprecated
39
+ * @param ari
40
+ * @returns
41
+ */
37
42
  export var getContentPropertyIdFromAri = function getContentPropertyIdFromAri(ari) {
38
- // eslint-disable-next-line require-unicode-regexp
39
43
  var match = ari.match(/ari:cloud:confluence:[^:]+:content\/([^/]+)/);
40
44
  if (match) {
41
45
  return match[1];
@@ -4,6 +4,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  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; }
5
5
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
6
  import { getConfluencePageAri } from './ari';
7
+ import { isBlogPageType } from './utils';
7
8
  var COMMON_HEADERS = {
8
9
  'Content-Type': 'application/json',
9
10
  Accept: 'application/json'
@@ -21,7 +22,15 @@ var UPDATE_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_UPDATE';
21
22
  * @param key
22
23
  * @returns
23
24
  */
24
- var GET_QUERY = "query ".concat(GET_OPERATION_NAME, " ($id: ID!, $keys: [String]!) {\n\t\t\t\t\tconfluence {\n\t\t\t\t\t\tpage (id: $id) {\n\t\t\t\t\t\t\tproperties(keys: $keys) {\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}");
25
+ var GET_PAGE_QUERY = "query ".concat(GET_OPERATION_NAME, " ($id: ID!, $keys: [String]!) {\n\t\t\t\t\tconfluence {\n\t\t\t\t\t\tpage (id: $id) {\n\t\t\t\t\t\t\tproperties(keys: $keys) {\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}");
26
+
27
+ /**
28
+ * Query to get the blog page property by key
29
+ * @param documentARI
30
+ * @param key
31
+ * @returns
32
+ */
33
+ var GET_BLOG_QUERY = "query ".concat(GET_OPERATION_NAME, " ($id: ID!, $keys: [String]!) {\n\tconfluence {\n\t\tblogPost (id: $id) {\n\t\t\tproperties(keys: $keys) {\n\t\t\t\tkey,\n\t\t\t\tvalue\n\t\t\t}\n\t\t}\n\t}\n}");
25
34
 
26
35
  /**
27
36
  * Query to create a page property with key and value
@@ -30,7 +39,16 @@ var GET_QUERY = "query ".concat(GET_OPERATION_NAME, " ($id: ID!, $keys: [String]
30
39
  * @param value
31
40
  * @returns
32
41
  */
33
- var CREATE_QUERY = "mutation ".concat(CREATE_OPERATION_NAME, " ($input: ConfluenceCreatePagePropertyInput!){\n\t\t\t\t\t\tconfluence {\n\t\t\t\t\t\t\tcreatePageProperty(input: $input) {\n\t\t\t\t\t\t\t\tpageProperty {\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}");
42
+ var CREATE_PAGE_QUERY = "mutation ".concat(CREATE_OPERATION_NAME, " ($input: ConfluenceCreatePagePropertyInput!){\n\t\t\t\t\t\tconfluence {\n\t\t\t\t\t\t\tcreatePageProperty(input: $input) {\n\t\t\t\t\t\t\t\tpageProperty {\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}");
43
+
44
+ /**
45
+ * Query to create a blog page property with key and value
46
+ * @param documentARI
47
+ * @param key
48
+ * @param value
49
+ * @returns
50
+ */
51
+ var CREATE_BLOG_QUERY = "mutation ".concat(CREATE_OPERATION_NAME, " ($input: ConfluenceCreateBlogPostPropertyInput!){\n\tconfluence {\n\t\tcreateBlogPostProperty(input: $input) {\n\t\t\tblogPostProperty {\n\t\t\t\tkey,\n\t\t\t\tvalue\n\t\t\t}\n\t\t}\n\t}\n}");
34
52
 
35
53
  /**
36
54
  * Query to update a page property with key and value without bumping the version
@@ -39,42 +57,51 @@ var CREATE_QUERY = "mutation ".concat(CREATE_OPERATION_NAME, " ($input: Confluen
39
57
  * @param value
40
58
  * @returns
41
59
  */
42
- var UPDATE_QUERY = "mutation ".concat(UPDATE_OPERATION_NAME, " ($input: ConfluenceUpdateValuePagePropertyInput!) {\n\t\t\t\t\t\tconfluence {\n\t\t\t\t\t\t\tupdateValuePageProperty(input: $input) {\n\t\t\t\t\t\t\t\tpageProperty {\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}");
60
+ var UPDATE_PAGE_QUERY = "mutation ".concat(UPDATE_OPERATION_NAME, " ($input: ConfluenceUpdateValuePagePropertyInput!) {\n\t\t\t\t\t\tconfluence {\n\t\t\t\t\t\t\tupdateValuePageProperty(input: $input) {\n\t\t\t\t\t\t\t\tpageProperty {\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}");
61
+
62
+ /**
63
+ * Query to update a blog page property with key and value without bumping the version
64
+ * @param documentARI
65
+ * @param key
66
+ * @param value
67
+ * @returns
68
+ */
69
+ var UPDATE_BLOG_QUERY = "mutation ".concat(UPDATE_OPERATION_NAME, " ($input: ConfluenceUpdateValueBlogPostPropertyInput!) {\n\tconfluence {\n\t\tupdateValueBlogPostProperty(input: $input) {\n\t\t\tblogPostProperty {\n\t\t\t\tkey,\n\t\t\t\tvalue\n\t\t\t}\n\t\t}\n\t}\n}");
43
70
  export var getContentProperty = /*#__PURE__*/function () {
44
71
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
45
- var pageId, key, cloudId, documentARI, bodyData, response, contentProperty;
72
+ var pageId, key, cloudId, pageType, documentARI, isBlog, bodyData, response;
46
73
  return _regeneratorRuntime.wrap(function _callee$(_context) {
47
74
  while (1) switch (_context.prev = _context.next) {
48
75
  case 0:
49
- pageId = _ref.pageId, key = _ref.key, cloudId = _ref.cloudId;
50
- documentARI = getConfluencePageAri(pageId, cloudId);
76
+ pageId = _ref.pageId, key = _ref.key, cloudId = _ref.cloudId, pageType = _ref.pageType;
77
+ documentARI = getConfluencePageAri(pageId, cloudId, pageType);
78
+ isBlog = isBlogPageType(pageType);
51
79
  bodyData = {
52
- query: GET_QUERY,
80
+ query: isBlog ? GET_BLOG_QUERY : GET_PAGE_QUERY,
53
81
  operationName: GET_OPERATION_NAME,
54
82
  variables: {
55
83
  id: documentARI,
56
84
  keys: [key]
57
85
  }
58
86
  };
59
- _context.next = 5;
87
+ _context.next = 6;
60
88
  return fetch(GRAPHQL_ENDPOINT, {
61
89
  method: 'POST',
62
90
  headers: _objectSpread(_objectSpread({}, COMMON_HEADERS), AGG_HEADERS),
63
91
  body: JSON.stringify(bodyData)
64
92
  });
65
- case 5:
93
+ case 6:
66
94
  response = _context.sent;
67
95
  if (response.ok) {
68
- _context.next = 8;
96
+ _context.next = 9;
69
97
  break;
70
98
  }
71
99
  throw new Error("Failed to get content property: ".concat(response.statusText));
72
- case 8:
73
- _context.next = 10;
100
+ case 9:
101
+ _context.next = 11;
74
102
  return response.json();
75
- case 10:
76
- contentProperty = _context.sent;
77
- return _context.abrupt("return", contentProperty);
103
+ case 11:
104
+ return _context.abrupt("return", _context.sent);
78
105
  case 12:
79
106
  case "end":
80
107
  return _context.stop();
@@ -87,44 +114,53 @@ export var getContentProperty = /*#__PURE__*/function () {
87
114
  }();
88
115
  export var updateContentProperty = /*#__PURE__*/function () {
89
116
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
90
- var pageId, key, value, cloudId, documentARI, bodyData, response, contentProperty;
117
+ var pageId, key, value, cloudId, pageType, documentARI, isBlog, useSameVersion, input, bodyData, response;
91
118
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
92
119
  while (1) switch (_context2.prev = _context2.next) {
93
120
  case 0:
94
- pageId = _ref3.pageId, key = _ref3.key, value = _ref3.value, cloudId = _ref3.cloudId;
95
- documentARI = getConfluencePageAri(pageId, cloudId);
121
+ pageId = _ref3.pageId, key = _ref3.key, value = _ref3.value, cloudId = _ref3.cloudId, pageType = _ref3.pageType;
122
+ documentARI = getConfluencePageAri(pageId, cloudId, pageType);
123
+ isBlog = isBlogPageType(pageType);
124
+ useSameVersion = {
125
+ useSameVersion: true
126
+ };
127
+ input = _objectSpread(_objectSpread({}, isBlog ? {
128
+ blogPostId: documentARI
129
+ } : {
130
+ pageId: documentARI
131
+ }), {}, {
132
+ key: key,
133
+ value: value
134
+ }); // Blog content properties don't support the useSameVersion flag at the moment
135
+ if (!isBlog) {
136
+ input = _objectSpread(_objectSpread({}, input), useSameVersion);
137
+ }
96
138
  bodyData = {
97
- query: UPDATE_QUERY,
139
+ query: isBlog ? UPDATE_BLOG_QUERY : UPDATE_PAGE_QUERY,
98
140
  operationName: UPDATE_OPERATION_NAME,
99
141
  variables: {
100
- input: {
101
- pageId: documentARI,
102
- key: key,
103
- value: value,
104
- useSameVersion: true
105
- }
142
+ input: input
106
143
  }
107
144
  };
108
- _context2.next = 5;
145
+ _context2.next = 9;
109
146
  return fetch(GRAPHQL_ENDPOINT, {
110
147
  method: 'POST',
111
148
  headers: _objectSpread(_objectSpread({}, COMMON_HEADERS), AGG_HEADERS),
112
149
  body: JSON.stringify(bodyData)
113
150
  });
114
- case 5:
151
+ case 9:
115
152
  response = _context2.sent;
116
153
  if (response.ok) {
117
- _context2.next = 8;
154
+ _context2.next = 12;
118
155
  break;
119
156
  }
120
157
  throw new Error("Failed to update content property: ".concat(response.statusText));
121
- case 8:
122
- _context2.next = 10;
123
- return response.json();
124
- case 10:
125
- contentProperty = _context2.sent;
126
- return _context2.abrupt("return", contentProperty);
127
158
  case 12:
159
+ _context2.next = 14;
160
+ return response.json();
161
+ case 14:
162
+ return _context2.abrupt("return", _context2.sent);
163
+ case 15:
128
164
  case "end":
129
165
  return _context2.stop();
130
166
  }
@@ -136,43 +172,46 @@ export var updateContentProperty = /*#__PURE__*/function () {
136
172
  }();
137
173
  export var createContentProperty = /*#__PURE__*/function () {
138
174
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
139
- var pageId, key, value, cloudId, documentARI, escapedValue, bodyData, response, contentProperty;
175
+ var pageId, key, value, cloudId, pageType, documentARI, isBlog, escapedValue, bodyData, response;
140
176
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
141
177
  while (1) switch (_context3.prev = _context3.next) {
142
178
  case 0:
143
- pageId = _ref5.pageId, key = _ref5.key, value = _ref5.value, cloudId = _ref5.cloudId;
144
- documentARI = getConfluencePageAri(pageId, cloudId); // eslint-disable-next-line require-unicode-regexp
179
+ pageId = _ref5.pageId, key = _ref5.key, value = _ref5.value, cloudId = _ref5.cloudId, pageType = _ref5.pageType;
180
+ documentARI = getConfluencePageAri(pageId, cloudId, pageType);
181
+ isBlog = isBlogPageType(pageType); // eslint-disable-next-line require-unicode-regexp
145
182
  escapedValue = value.replace(/"/g, '\\"');
146
183
  bodyData = {
147
- query: CREATE_QUERY,
184
+ query: isBlog ? CREATE_BLOG_QUERY : CREATE_PAGE_QUERY,
148
185
  operationName: CREATE_OPERATION_NAME,
149
186
  variables: {
150
- input: {
151
- pageId: documentARI,
187
+ input: _objectSpread(_objectSpread({}, isBlog ? {
188
+ blogPostId: documentARI
189
+ } : {
190
+ pageId: documentARI
191
+ }), {}, {
152
192
  key: key,
153
193
  value: escapedValue
154
- }
194
+ })
155
195
  }
156
196
  };
157
- _context3.next = 6;
197
+ _context3.next = 7;
158
198
  return fetch(GRAPHQL_ENDPOINT, {
159
199
  method: 'POST',
160
200
  headers: _objectSpread(_objectSpread({}, COMMON_HEADERS), AGG_HEADERS),
161
201
  body: JSON.stringify(bodyData)
162
202
  });
163
- case 6:
203
+ case 7:
164
204
  response = _context3.sent;
165
205
  if (response.ok) {
166
- _context3.next = 9;
206
+ _context3.next = 10;
167
207
  break;
168
208
  }
169
209
  throw new Error("Failed to create content property: ".concat(response.statusText));
170
- case 9:
171
- _context3.next = 11;
210
+ case 10:
211
+ _context3.next = 12;
172
212
  return response.json();
173
- case 11:
174
- contentProperty = _context3.sent;
175
- return _context3.abrupt("return", contentProperty);
213
+ case 12:
214
+ return _context3.abrupt("return", _context3.sent);
176
215
  case 13:
177
216
  case "end":
178
217
  return _context3.stop();
@@ -13,4 +13,7 @@ export var convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNo
13
13
  },
14
14
  content: includeContent ? node.content.content.map(toJSON) : undefined
15
15
  };
16
+ };
17
+ export var isBlogPageType = function isBlogPageType(pageType) {
18
+ return pageType === 'blogpost';
16
19
  };
@@ -1,12 +1,18 @@
1
- export declare const getConfluencePageAri: (pageId: string, cloudId: string) => string;
2
- export declare const getPageIdFromAri: (ari: string) => string;
3
- /**
4
- *
5
- * @param ari ari:cloud:confluence:<cloudId>:page/<pageId>/<localId>
6
- * @returns
7
- */
1
+ export type PAGE_TYPE = 'page' | 'blogpost';
2
+ export declare const getConfluencePageAri: (pageId: string, cloudId: string, pageType?: PAGE_TYPE) => string;
3
+ export declare const getPageIdAndTypeFromAri: (ari: string) => {
4
+ id: string;
5
+ type: PAGE_TYPE;
6
+ };
8
7
  export declare const getLocalIdFromAri: (ari: string) => string;
9
8
  export declare const getPageARIFromResourceId: (resourceId: string) => string;
10
9
  export declare const getContentPropertyAri: (contentPropertyId: string, cloudId: string) => string;
10
+ /**
11
+ * DEPRECATED - Will be removed in the future
12
+ * @private
13
+ * @deprecated
14
+ * @param ari
15
+ * @returns
16
+ */
11
17
  export declare const getContentPropertyIdFromAri: (ari: string) => string;
12
18
  export declare const resourceIdFromSourceAndLocalId: (sourceId: string, localId: string) => string;