@atlaskit/editor-synced-block-provider 3.1.0 → 3.2.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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 3.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`b7db97837674e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b7db97837674e) -
8
+ Use GraphQL endpoint for fetching references on a document instead of Rest API
9
+
3
10
  ## 3.1.0
4
11
 
5
12
  ### Minor Changes
@@ -20,11 +20,10 @@ var isBlockContentResponse = exports.isBlockContentResponse = function isBlockCo
20
20
  var content = response.content;
21
21
  return typeof content === 'string';
22
22
  };
23
-
24
23
  /**
25
24
  * Retrieves all synced blocks referenced in a document.
26
25
  *
27
- * Calls the Block Service API endpoint: `/v1/block/document/reference/{documentAri}`
26
+ * Calls the Block Service GraphQL API: `blockService_getDocumentReferenceBlocks`
28
27
  *
29
28
  * @param documentAri - The ARI of the document to fetch synced blocks for
30
29
  * @returns A promise containing arrays of successfully fetched blocks and any errors encountered
@@ -61,32 +60,51 @@ var isBlockContentResponse = exports.isBlockContentResponse = function isBlockCo
61
60
  * ]
62
61
  * }
63
62
  * ```
64
- * Check https://block-service.dev.atl-paas.net/ for latest API documentation.
65
63
  */
66
64
  var getReferenceSyncedBlocks = exports.getReferenceSyncedBlocks = /*#__PURE__*/function () {
67
65
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(documentAri) {
68
- var response;
66
+ var bodyData, response, result;
69
67
  return _regenerator.default.wrap(function _callee$(_context) {
70
68
  while (1) switch (_context.prev = _context.next) {
71
69
  case 0:
72
- _context.next = 2;
73
- return (0, _retry.fetchWithRetry)("".concat(BLOCK_SERVICE_API_URL, "/block/document/reference/").concat(encodeURIComponent(documentAri)), {
74
- method: 'GET',
75
- headers: COMMON_HEADERS
70
+ bodyData = {
71
+ query: buildGetDocumentReferenceBlocksQuery(documentAri),
72
+ operationName: GET_DOCUMENT_REFERENCE_BLOCKS_OPERATION_NAME
73
+ };
74
+ _context.next = 3;
75
+ return (0, _retry.fetchWithRetry)(GRAPHQL_ENDPOINT, {
76
+ method: 'POST',
77
+ headers: COMMON_HEADERS,
78
+ body: JSON.stringify(bodyData)
76
79
  });
77
- case 2:
80
+ case 3:
78
81
  response = _context.sent;
79
82
  if (response.ok) {
80
- _context.next = 5;
83
+ _context.next = 6;
81
84
  break;
82
85
  }
83
86
  throw new BlockError(response.status);
84
- case 5:
85
- _context.next = 7;
87
+ case 6:
88
+ _context.next = 8;
86
89
  return response.json();
87
- case 7:
88
- return _context.abrupt("return", _context.sent);
89
90
  case 8:
91
+ result = _context.sent;
92
+ if (!(result.errors && result.errors.length > 0)) {
93
+ _context.next = 11;
94
+ break;
95
+ }
96
+ throw new Error(result.errors.map(function (e) {
97
+ return e.message;
98
+ }).join(', '));
99
+ case 11:
100
+ if (result.data) {
101
+ _context.next = 13;
102
+ break;
103
+ }
104
+ throw new Error('No data returned from GraphQL query');
105
+ case 13:
106
+ return _context.abrupt("return", result.data.blockService_getDocumentReferenceBlocks);
107
+ case 14:
90
108
  case "end":
91
109
  return _context.stop();
92
110
  }
@@ -101,6 +119,11 @@ var COMMON_HEADERS = {
101
119
  Accept: 'application/json'
102
120
  };
103
121
  var BLOCK_SERVICE_API_URL = '/gateway/api/blocks/v1';
122
+ var GRAPHQL_ENDPOINT = '/gateway/api/graphql';
123
+ var GET_DOCUMENT_REFERENCE_BLOCKS_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_GET_DOCUMENT_REFERENCE_BLOCKS';
124
+ var buildGetDocumentReferenceBlocksQuery = function buildGetDocumentReferenceBlocksQuery(documentAri) {
125
+ return "query ".concat(GET_DOCUMENT_REFERENCE_BLOCKS_OPERATION_NAME, " {\n\tblockService_getDocumentReferenceBlocks(documentAri: \"").concat(documentAri, "\") {\n\t\tblocks {\n\t\t\tblockAri\n\t\t\tblockInstanceId\n\t\t\tcontent\n\t\t\tcreatedAt\n\t\t\tcreatedBy\n\t\t\tproduct\n\t\t\tsourceAri\n\t\t\tstatus\n\t\t\tversion\n\t\t}\n\t\terrors {\n\t\t\tblockAri\n\t\t\tcode\n\t\t\treason\n\t\t}\n\t}\n}");
126
+ };
104
127
  var BlockError = exports.BlockError = /*#__PURE__*/function (_Error) {
105
128
  function BlockError(status) {
106
129
  var _this;
@@ -3,11 +3,10 @@ export const isBlockContentResponse = response => {
3
3
  const content = response.content;
4
4
  return typeof content === 'string';
5
5
  };
6
-
7
6
  /**
8
7
  * Retrieves all synced blocks referenced in a document.
9
8
  *
10
- * Calls the Block Service API endpoint: `/v1/block/document/reference/{documentAri}`
9
+ * Calls the Block Service GraphQL API: `blockService_getDocumentReferenceBlocks`
11
10
  *
12
11
  * @param documentAri - The ARI of the document to fetch synced blocks for
13
12
  * @returns A promise containing arrays of successfully fetched blocks and any errors encountered
@@ -44,23 +43,56 @@ export const isBlockContentResponse = response => {
44
43
  * ]
45
44
  * }
46
45
  * ```
47
- * Check https://block-service.dev.atl-paas.net/ for latest API documentation.
48
46
  */
49
47
  export const getReferenceSyncedBlocks = async documentAri => {
50
- const response = await fetchWithRetry(`${BLOCK_SERVICE_API_URL}/block/document/reference/${encodeURIComponent(documentAri)}`, {
51
- method: 'GET',
52
- headers: COMMON_HEADERS
48
+ const bodyData = {
49
+ query: buildGetDocumentReferenceBlocksQuery(documentAri),
50
+ operationName: GET_DOCUMENT_REFERENCE_BLOCKS_OPERATION_NAME
51
+ };
52
+ const response = await fetchWithRetry(GRAPHQL_ENDPOINT, {
53
+ method: 'POST',
54
+ headers: COMMON_HEADERS,
55
+ body: JSON.stringify(bodyData)
53
56
  });
54
57
  if (!response.ok) {
55
58
  throw new BlockError(response.status);
56
59
  }
57
- return await response.json();
60
+ const result = await response.json();
61
+ if (result.errors && result.errors.length > 0) {
62
+ throw new Error(result.errors.map(e => e.message).join(', '));
63
+ }
64
+ if (!result.data) {
65
+ throw new Error('No data returned from GraphQL query');
66
+ }
67
+ return result.data.blockService_getDocumentReferenceBlocks;
58
68
  };
59
69
  const COMMON_HEADERS = {
60
70
  'Content-Type': 'application/json',
61
71
  Accept: 'application/json'
62
72
  };
63
73
  const BLOCK_SERVICE_API_URL = '/gateway/api/blocks/v1';
74
+ const GRAPHQL_ENDPOINT = '/gateway/api/graphql';
75
+ const GET_DOCUMENT_REFERENCE_BLOCKS_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_GET_DOCUMENT_REFERENCE_BLOCKS';
76
+ const buildGetDocumentReferenceBlocksQuery = documentAri => `query ${GET_DOCUMENT_REFERENCE_BLOCKS_OPERATION_NAME} {
77
+ blockService_getDocumentReferenceBlocks(documentAri: "${documentAri}") {
78
+ blocks {
79
+ blockAri
80
+ blockInstanceId
81
+ content
82
+ createdAt
83
+ createdBy
84
+ product
85
+ sourceAri
86
+ status
87
+ version
88
+ }
89
+ errors {
90
+ blockAri
91
+ code
92
+ reason
93
+ }
94
+ }
95
+ }`;
64
96
  export class BlockError extends Error {
65
97
  constructor(status) {
66
98
  super(`Block error`);
@@ -13,11 +13,10 @@ export var isBlockContentResponse = function isBlockContentResponse(response) {
13
13
  var content = response.content;
14
14
  return typeof content === 'string';
15
15
  };
16
-
17
16
  /**
18
17
  * Retrieves all synced blocks referenced in a document.
19
18
  *
20
- * Calls the Block Service API endpoint: `/v1/block/document/reference/{documentAri}`
19
+ * Calls the Block Service GraphQL API: `blockService_getDocumentReferenceBlocks`
21
20
  *
22
21
  * @param documentAri - The ARI of the document to fetch synced blocks for
23
22
  * @returns A promise containing arrays of successfully fetched blocks and any errors encountered
@@ -54,32 +53,51 @@ export var isBlockContentResponse = function isBlockContentResponse(response) {
54
53
  * ]
55
54
  * }
56
55
  * ```
57
- * Check https://block-service.dev.atl-paas.net/ for latest API documentation.
58
56
  */
59
57
  export var getReferenceSyncedBlocks = /*#__PURE__*/function () {
60
58
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(documentAri) {
61
- var response;
59
+ var bodyData, response, result;
62
60
  return _regeneratorRuntime.wrap(function _callee$(_context) {
63
61
  while (1) switch (_context.prev = _context.next) {
64
62
  case 0:
65
- _context.next = 2;
66
- return fetchWithRetry("".concat(BLOCK_SERVICE_API_URL, "/block/document/reference/").concat(encodeURIComponent(documentAri)), {
67
- method: 'GET',
68
- headers: COMMON_HEADERS
63
+ bodyData = {
64
+ query: buildGetDocumentReferenceBlocksQuery(documentAri),
65
+ operationName: GET_DOCUMENT_REFERENCE_BLOCKS_OPERATION_NAME
66
+ };
67
+ _context.next = 3;
68
+ return fetchWithRetry(GRAPHQL_ENDPOINT, {
69
+ method: 'POST',
70
+ headers: COMMON_HEADERS,
71
+ body: JSON.stringify(bodyData)
69
72
  });
70
- case 2:
73
+ case 3:
71
74
  response = _context.sent;
72
75
  if (response.ok) {
73
- _context.next = 5;
76
+ _context.next = 6;
74
77
  break;
75
78
  }
76
79
  throw new BlockError(response.status);
77
- case 5:
78
- _context.next = 7;
80
+ case 6:
81
+ _context.next = 8;
79
82
  return response.json();
80
- case 7:
81
- return _context.abrupt("return", _context.sent);
82
83
  case 8:
84
+ result = _context.sent;
85
+ if (!(result.errors && result.errors.length > 0)) {
86
+ _context.next = 11;
87
+ break;
88
+ }
89
+ throw new Error(result.errors.map(function (e) {
90
+ return e.message;
91
+ }).join(', '));
92
+ case 11:
93
+ if (result.data) {
94
+ _context.next = 13;
95
+ break;
96
+ }
97
+ throw new Error('No data returned from GraphQL query');
98
+ case 13:
99
+ return _context.abrupt("return", result.data.blockService_getDocumentReferenceBlocks);
100
+ case 14:
83
101
  case "end":
84
102
  return _context.stop();
85
103
  }
@@ -94,6 +112,11 @@ var COMMON_HEADERS = {
94
112
  Accept: 'application/json'
95
113
  };
96
114
  var BLOCK_SERVICE_API_URL = '/gateway/api/blocks/v1';
115
+ var GRAPHQL_ENDPOINT = '/gateway/api/graphql';
116
+ var GET_DOCUMENT_REFERENCE_BLOCKS_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_GET_DOCUMENT_REFERENCE_BLOCKS';
117
+ var buildGetDocumentReferenceBlocksQuery = function buildGetDocumentReferenceBlocksQuery(documentAri) {
118
+ return "query ".concat(GET_DOCUMENT_REFERENCE_BLOCKS_OPERATION_NAME, " {\n\tblockService_getDocumentReferenceBlocks(documentAri: \"").concat(documentAri, "\") {\n\t\tblocks {\n\t\t\tblockAri\n\t\t\tblockInstanceId\n\t\t\tcontent\n\t\t\tcreatedAt\n\t\t\tcreatedBy\n\t\t\tproduct\n\t\t\tsourceAri\n\t\t\tstatus\n\t\t\tversion\n\t\t}\n\t\terrors {\n\t\t\tblockAri\n\t\t\tcode\n\t\t\treason\n\t\t}\n\t}\n}");
119
+ };
97
120
  export var BlockError = /*#__PURE__*/function (_Error) {
98
121
  function BlockError(status) {
99
122
  var _this;
@@ -23,7 +23,7 @@ export declare const isBlockContentResponse: (response: BlockContentResponse | B
23
23
  /**
24
24
  * Retrieves all synced blocks referenced in a document.
25
25
  *
26
- * Calls the Block Service API endpoint: `/v1/block/document/reference/{documentAri}`
26
+ * Calls the Block Service GraphQL API: `blockService_getDocumentReferenceBlocks`
27
27
  *
28
28
  * @param documentAri - The ARI of the document to fetch synced blocks for
29
29
  * @returns A promise containing arrays of successfully fetched blocks and any errors encountered
@@ -60,7 +60,6 @@ export declare const isBlockContentResponse: (response: BlockContentResponse | B
60
60
  * ]
61
61
  * }
62
62
  * ```
63
- * Check https://block-service.dev.atl-paas.net/ for latest API documentation.
64
63
  */
65
64
  export declare const getReferenceSyncedBlocks: (documentAri: string) => Promise<ReferenceSyncedBlockResponse>;
66
65
  export type GetSyncedBlockContentRequest = {
@@ -23,7 +23,7 @@ export declare const isBlockContentResponse: (response: BlockContentResponse | B
23
23
  /**
24
24
  * Retrieves all synced blocks referenced in a document.
25
25
  *
26
- * Calls the Block Service API endpoint: `/v1/block/document/reference/{documentAri}`
26
+ * Calls the Block Service GraphQL API: `blockService_getDocumentReferenceBlocks`
27
27
  *
28
28
  * @param documentAri - The ARI of the document to fetch synced blocks for
29
29
  * @returns A promise containing arrays of successfully fetched blocks and any errors encountered
@@ -60,7 +60,6 @@ export declare const isBlockContentResponse: (response: BlockContentResponse | B
60
60
  * ]
61
61
  * }
62
62
  * ```
63
- * Check https://block-service.dev.atl-paas.net/ for latest API documentation.
64
63
  */
65
64
  export declare const getReferenceSyncedBlocks: (documentAri: string) => Promise<ReferenceSyncedBlockResponse>;
66
65
  export type GetSyncedBlockContentRequest = {
package/package.json CHANGED
@@ -76,7 +76,7 @@
76
76
  }
77
77
  },
78
78
  "name": "@atlaskit/editor-synced-block-provider",
79
- "version": "3.1.0",
79
+ "version": "3.2.0",
80
80
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
81
81
  "author": "Atlassian Pty Ltd",
82
82
  "license": "Apache-2.0",