@atlaskit/editor-synced-block-provider 3.9.0 → 3.11.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,19 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 3.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`7b4cb91fc67a6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7b4cb91fc67a6) -
8
+ Do not immediately show error state on initial load of blocks
9
+
10
+ ## 3.10.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [`7638bd91b6c72`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7638bd91b6c72) -
15
+ The errors should render correctly when using batch-retrieve to fetch synced blocks
16
+
3
17
  ## 3.9.0
4
18
 
5
19
  ### Minor Changes
@@ -43,6 +43,26 @@ var mapBlockError = function mapBlockError(error) {
43
43
  }
44
44
  return _types.SyncBlockError.Errored;
45
45
  };
46
+ var mapErrorResponseCode = function mapErrorResponseCode(errorCode) {
47
+ switch (errorCode) {
48
+ case 'FORBIDDEN':
49
+ return _types.SyncBlockError.Forbidden;
50
+ case 'NOT_FOUND':
51
+ return _types.SyncBlockError.NotFound;
52
+ case 'INVALID_REQUEST':
53
+ return _types.SyncBlockError.InvalidRequest;
54
+ case 'CONFLICT':
55
+ return _types.SyncBlockError.Conflict;
56
+ case 'RATE_LIMITED':
57
+ return _types.SyncBlockError.RateLimited;
58
+ case 'SERVER_ERROR':
59
+ return _types.SyncBlockError.ServerError;
60
+ case 'INVALID_CONTENT':
61
+ return _types.SyncBlockError.InvalidContent;
62
+ default:
63
+ return _types.SyncBlockError.Errored;
64
+ }
65
+ };
46
66
 
47
67
  /**
48
68
  * Extracts the ResourceId from a block ARI by returning the full path after synced-block/.
@@ -460,7 +480,7 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
460
480
  case 44:
461
481
  processedResourceIds.add(_resourceId);
462
482
  results.push({
463
- error: _types.SyncBlockError.Errored,
483
+ error: mapErrorResponseCode(errorResponse.code),
464
484
  resourceId: _resourceId
465
485
  });
466
486
  case 46:
@@ -115,11 +115,21 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
115
115
  case 10:
116
116
  _context.prev = 10;
117
117
  _context.t0 = _context["catch"](4);
118
- return _context.abrupt("return", blockIdentifiers.map(function (blockIdentifier) {
119
- return {
120
- error: _types.SyncBlockError.Errored,
121
- resourceId: blockIdentifier.resourceId
122
- };
118
+ return _context.abrupt("return", Promise.allSettled(blockIdentifiers.map(function (blockIdentifier) {
119
+ return _this2.fetchProvider.fetchData(blockIdentifier.resourceId).then(function (data) {
120
+ return data;
121
+ }, function () {
122
+ return {
123
+ error: _types.SyncBlockError.Errored,
124
+ resourceId: blockIdentifier.resourceId
125
+ };
126
+ });
127
+ })).then(function (results) {
128
+ return results.filter(function (result) {
129
+ return result.status === 'fulfilled';
130
+ }).map(function (result) {
131
+ return result.value;
132
+ });
123
133
  }));
124
134
  case 13:
125
135
  _context.next = 16;
@@ -26,6 +26,26 @@ const mapBlockError = error => {
26
26
  }
27
27
  return SyncBlockError.Errored;
28
28
  };
29
+ const mapErrorResponseCode = errorCode => {
30
+ switch (errorCode) {
31
+ case 'FORBIDDEN':
32
+ return SyncBlockError.Forbidden;
33
+ case 'NOT_FOUND':
34
+ return SyncBlockError.NotFound;
35
+ case 'INVALID_REQUEST':
36
+ return SyncBlockError.InvalidRequest;
37
+ case 'CONFLICT':
38
+ return SyncBlockError.Conflict;
39
+ case 'RATE_LIMITED':
40
+ return SyncBlockError.RateLimited;
41
+ case 'SERVER_ERROR':
42
+ return SyncBlockError.ServerError;
43
+ case 'INVALID_CONTENT':
44
+ return SyncBlockError.InvalidContent;
45
+ default:
46
+ return SyncBlockError.Errored;
47
+ }
48
+ };
29
49
 
30
50
  /**
31
51
  * Extracts the ResourceId from a block ARI by returning the full path after synced-block/.
@@ -314,7 +334,7 @@ class BlockServiceADFFetchProvider {
314
334
  }
315
335
  processedResourceIds.add(resourceId);
316
336
  results.push({
317
- error: SyncBlockError.Errored,
337
+ error: mapErrorResponseCode(errorResponse.code),
318
338
  resourceId
319
339
  });
320
340
  }
@@ -66,11 +66,22 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
66
66
  try {
67
67
  return await this.fetchProvider.batchFetchData(blockIdentifiers);
68
68
  } catch {
69
- // If batch fetch fails, return error for all resourceIds
70
- return blockIdentifiers.map(blockIdentifier => ({
71
- error: SyncBlockError.Errored,
72
- resourceId: blockIdentifier.resourceId
73
- }));
69
+ // If batch fetch fails, fall back to individual fetch behavior
70
+ // This allows loading states to be shown before errors, matching non-batch behavior
71
+ return Promise.allSettled(blockIdentifiers.map(blockIdentifier => {
72
+ return this.fetchProvider.fetchData(blockIdentifier.resourceId).then(data => {
73
+ return data;
74
+ }, () => {
75
+ return {
76
+ error: SyncBlockError.Errored,
77
+ resourceId: blockIdentifier.resourceId
78
+ };
79
+ });
80
+ })).then(results => {
81
+ return results.filter(result => {
82
+ return result.status === 'fulfilled';
83
+ }).map(result => result.value);
84
+ });
74
85
  }
75
86
  } else {
76
87
  return Promise.allSettled(blockIdentifiers.map(blockIdentifier => {
@@ -37,6 +37,26 @@ var mapBlockError = function mapBlockError(error) {
37
37
  }
38
38
  return SyncBlockError.Errored;
39
39
  };
40
+ var mapErrorResponseCode = function mapErrorResponseCode(errorCode) {
41
+ switch (errorCode) {
42
+ case 'FORBIDDEN':
43
+ return SyncBlockError.Forbidden;
44
+ case 'NOT_FOUND':
45
+ return SyncBlockError.NotFound;
46
+ case 'INVALID_REQUEST':
47
+ return SyncBlockError.InvalidRequest;
48
+ case 'CONFLICT':
49
+ return SyncBlockError.Conflict;
50
+ case 'RATE_LIMITED':
51
+ return SyncBlockError.RateLimited;
52
+ case 'SERVER_ERROR':
53
+ return SyncBlockError.ServerError;
54
+ case 'INVALID_CONTENT':
55
+ return SyncBlockError.InvalidContent;
56
+ default:
57
+ return SyncBlockError.Errored;
58
+ }
59
+ };
40
60
 
41
61
  /**
42
62
  * Extracts the ResourceId from a block ARI by returning the full path after synced-block/.
@@ -454,7 +474,7 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
454
474
  case 44:
455
475
  processedResourceIds.add(_resourceId);
456
476
  results.push({
457
- error: SyncBlockError.Errored,
477
+ error: mapErrorResponseCode(errorResponse.code),
458
478
  resourceId: _resourceId
459
479
  });
460
480
  case 46:
@@ -108,11 +108,21 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
108
108
  case 10:
109
109
  _context.prev = 10;
110
110
  _context.t0 = _context["catch"](4);
111
- return _context.abrupt("return", blockIdentifiers.map(function (blockIdentifier) {
112
- return {
113
- error: SyncBlockError.Errored,
114
- resourceId: blockIdentifier.resourceId
115
- };
111
+ return _context.abrupt("return", Promise.allSettled(blockIdentifiers.map(function (blockIdentifier) {
112
+ return _this2.fetchProvider.fetchData(blockIdentifier.resourceId).then(function (data) {
113
+ return data;
114
+ }, function () {
115
+ return {
116
+ error: SyncBlockError.Errored,
117
+ resourceId: blockIdentifier.resourceId
118
+ };
119
+ });
120
+ })).then(function (results) {
121
+ return results.filter(function (result) {
122
+ return result.status === 'fulfilled';
123
+ }).map(function (result) {
124
+ return result.value;
125
+ });
116
126
  }));
117
127
  case 13:
118
128
  _context.next = 16;
@@ -1,11 +1,10 @@
1
- type ConfigData = {
1
+ export type ConfigData = {
2
2
  readonly clientId: string;
3
3
  readonly fileStoreUrl: string;
4
4
  };
5
- type TokenData = {
5
+ export type TokenData = {
6
6
  collectionId?: string;
7
7
  config: ConfigData;
8
8
  token: string;
9
9
  };
10
10
  export declare const fetchMediaToken: (contentId: string) => Promise<TokenData>;
11
- export {};
@@ -6,7 +6,7 @@ export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
6
6
  export { useHandleContentChanges } from './hooks/useHandleContentChanges';
7
7
  export { generateBlockAri, generateBlockAriFromReference, getLocalIdFromBlockResourceId, } from './clients/block-service/ari';
8
8
  export { getConfluencePageAri, getPageIdAndTypeFromConfluencePageAri, } from './clients/confluence/ari';
9
- export { fetchMediaToken } from './clients/confluence/fetchMediaToken';
9
+ export { fetchMediaToken, type TokenData, type ConfigData, } from './clients/confluence/fetchMediaToken';
10
10
  export { getJiraWorkItemAri, getJiraWorkItemIdFromAri } from './clients/jira/ari';
11
11
  export { useMemoizedBlockServiceAPIProviders, useMemoizedBlockServiceFetchOnlyAPIProvider, } from './providers/block-service/blockServiceAPI';
12
12
  export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
@@ -1,11 +1,10 @@
1
- type ConfigData = {
1
+ export type ConfigData = {
2
2
  readonly clientId: string;
3
3
  readonly fileStoreUrl: string;
4
4
  };
5
- type TokenData = {
5
+ export type TokenData = {
6
6
  collectionId?: string;
7
7
  config: ConfigData;
8
8
  token: string;
9
9
  };
10
10
  export declare const fetchMediaToken: (contentId: string) => Promise<TokenData>;
11
- export {};
@@ -6,7 +6,7 @@ export { useFetchSyncBlockTitle } from './hooks/useFetchSyncBlockTitle';
6
6
  export { useHandleContentChanges } from './hooks/useHandleContentChanges';
7
7
  export { generateBlockAri, generateBlockAriFromReference, getLocalIdFromBlockResourceId, } from './clients/block-service/ari';
8
8
  export { getConfluencePageAri, getPageIdAndTypeFromConfluencePageAri, } from './clients/confluence/ari';
9
- export { fetchMediaToken } from './clients/confluence/fetchMediaToken';
9
+ export { fetchMediaToken, type TokenData, type ConfigData, } from './clients/confluence/fetchMediaToken';
10
10
  export { getJiraWorkItemAri, getJiraWorkItemIdFromAri } from './clients/jira/ari';
11
11
  export { useMemoizedBlockServiceAPIProviders, useMemoizedBlockServiceFetchOnlyAPIProvider, } from './providers/block-service/blockServiceAPI';
12
12
  export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
package/package.json CHANGED
@@ -77,7 +77,7 @@
77
77
  }
78
78
  },
79
79
  "name": "@atlaskit/editor-synced-block-provider",
80
- "version": "3.9.0",
80
+ "version": "3.11.0",
81
81
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
82
82
  "author": "Atlassian Pty Ltd",
83
83
  "license": "Apache-2.0",