@atlaskit/editor-synced-block-provider 3.4.1 → 3.5.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 +7 -0
- package/dist/cjs/providers/block-service/blockServiceAPI.js +40 -6
- package/dist/es2019/providers/block-service/blockServiceAPI.js +39 -5
- package/dist/esm/providers/block-service/blockServiceAPI.js +39 -5
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +19 -0
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +19 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 3.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`25da5a5d67a2a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/25da5a5d67a2a) -
|
|
8
|
+
EDITOR-2257 implement resourceId conversion and enable SSR
|
|
9
|
+
|
|
3
10
|
## 3.4.1
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.useMemoizedBlockServiceFetchOnlyAPIProvider = exports.useMemoizedBlockServiceAPIProviders = exports.fetchReferences = exports.createBlockServiceFetchOnlyAPIProvider = exports.createBlockServiceAPIProviders = void 0;
|
|
7
|
+
exports.useMemoizedBlockServiceFetchOnlyAPIProvider = exports.useMemoizedBlockServiceAPIProviders = exports.fetchReferences = exports.createBlockServiceFetchOnlyAPIProvider = exports.createBlockServiceAPIProviders = exports.convertToSyncBlockData = exports.blockAriToResourceId = void 0;
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
10
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
@@ -39,6 +39,32 @@ var mapBlockError = function mapBlockError(error) {
|
|
|
39
39
|
return _types.SyncBlockError.Errored;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Extracts the ResourceId from a block ARI by returning the full path after synced-block/.
|
|
44
|
+
*
|
|
45
|
+
* Document ARI format from Block Service API:
|
|
46
|
+
* "ari:cloud:blocks:{uuid}:synced-block/{product}/{parentId}/{resourceId}"
|
|
47
|
+
*
|
|
48
|
+
* ResourceId format (extracted from ARI):
|
|
49
|
+
* "{product}/{parentId}/{resourceId}" (the full path after synced-block/)
|
|
50
|
+
*
|
|
51
|
+
* Example in context:
|
|
52
|
+
* Input: "ari:cloud:blocks:{uuid}:synced-block/confluence-page/{pageId}/{resourceId}"
|
|
53
|
+
* Output: "confluence-page/{pageId}/{resourceId}"
|
|
54
|
+
*
|
|
55
|
+
* @param blockAri - The block ARI string from Block Service API
|
|
56
|
+
* @returns The ResourceId (full path after synced-block/)
|
|
57
|
+
*/
|
|
58
|
+
var blockAriToResourceId = exports.blockAriToResourceId = function blockAriToResourceId(blockAri) {
|
|
59
|
+
// Validate ARI format and extract resourceId using regex
|
|
60
|
+
// Format: ari:cloud:blocks:{uuid}:synced-block/{product}/{parentId}/{resourceId}
|
|
61
|
+
// The regex captures the full path after synced-block/
|
|
62
|
+
// e.g. ari:cloud:blocks:DUMMY-a5a01d21-1cc3-4f29-9565-f2bb8cd969f5:synced-block/confluence-page/455232061495/e8cf64e3-1b6e-489b-ad86-8465b0905bb4
|
|
63
|
+
// should return confluence-page/455232061495/e8cf64e3-1b6e-489b-ad86-8465b0905bb4
|
|
64
|
+
var match = blockAri.match(/^ari:cloud:blocks:.*:synced-block\/(.+)$/);
|
|
65
|
+
return (match === null || match === void 0 ? void 0 : match[1]) || null;
|
|
66
|
+
};
|
|
67
|
+
|
|
42
68
|
// convert BlockContentResponse to SyncBlockData
|
|
43
69
|
// throws exception if JSON parsing fails
|
|
44
70
|
// what's missing from BlockContentResponse to SyncBlockData:
|
|
@@ -46,9 +72,9 @@ var mapBlockError = function mapBlockError(error) {
|
|
|
46
72
|
// - sourceURL
|
|
47
73
|
// - sourceTitle
|
|
48
74
|
// - isSynced
|
|
49
|
-
var convertToSyncBlockData = function convertToSyncBlockData(data) {
|
|
75
|
+
var convertToSyncBlockData = exports.convertToSyncBlockData = function convertToSyncBlockData(data, resourceId) {
|
|
50
76
|
var createdAt;
|
|
51
|
-
if (data.createdAt) {
|
|
77
|
+
if (data.createdAt !== undefined && data.createdAt !== null) {
|
|
52
78
|
try {
|
|
53
79
|
// BE returns microseconds, convert to milliseconds
|
|
54
80
|
// BE should fix this in the future
|
|
@@ -65,7 +91,7 @@ var convertToSyncBlockData = function convertToSyncBlockData(data) {
|
|
|
65
91
|
createdAt: createdAt,
|
|
66
92
|
createdBy: data.createdBy,
|
|
67
93
|
product: data.product,
|
|
68
|
-
resourceId:
|
|
94
|
+
resourceId: resourceId,
|
|
69
95
|
sourceAri: data.sourceAri
|
|
70
96
|
};
|
|
71
97
|
};
|
|
@@ -96,9 +122,17 @@ var fetchReferences = exports.fetchReferences = /*#__PURE__*/function () {
|
|
|
96
122
|
_ref2 = response || {}, blocks = _ref2.blocks, errors = _ref2.errors;
|
|
97
123
|
blocksInstances = (blocks || []).map(function (blockContentResponse) {
|
|
98
124
|
try {
|
|
125
|
+
var resourceId = blockAriToResourceId(blockContentResponse.blockAri);
|
|
126
|
+
if (!resourceId) {
|
|
127
|
+
// could not extract resourceId from blockAri, return InvalidContent error
|
|
128
|
+
return {
|
|
129
|
+
error: _types.SyncBlockError.InvalidContent,
|
|
130
|
+
resourceId: blockContentResponse.blockAri
|
|
131
|
+
};
|
|
132
|
+
}
|
|
99
133
|
return {
|
|
100
|
-
data: convertToSyncBlockData(blockContentResponse),
|
|
101
|
-
resourceId:
|
|
134
|
+
data: convertToSyncBlockData(blockContentResponse, resourceId),
|
|
135
|
+
resourceId: resourceId
|
|
102
136
|
};
|
|
103
137
|
} catch (_unused) {
|
|
104
138
|
// JSON parsing error, return InvalidContent error
|
|
@@ -25,6 +25,32 @@ const mapBlockError = error => {
|
|
|
25
25
|
return SyncBlockError.Errored;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Extracts the ResourceId from a block ARI by returning the full path after synced-block/.
|
|
30
|
+
*
|
|
31
|
+
* Document ARI format from Block Service API:
|
|
32
|
+
* "ari:cloud:blocks:{uuid}:synced-block/{product}/{parentId}/{resourceId}"
|
|
33
|
+
*
|
|
34
|
+
* ResourceId format (extracted from ARI):
|
|
35
|
+
* "{product}/{parentId}/{resourceId}" (the full path after synced-block/)
|
|
36
|
+
*
|
|
37
|
+
* Example in context:
|
|
38
|
+
* Input: "ari:cloud:blocks:{uuid}:synced-block/confluence-page/{pageId}/{resourceId}"
|
|
39
|
+
* Output: "confluence-page/{pageId}/{resourceId}"
|
|
40
|
+
*
|
|
41
|
+
* @param blockAri - The block ARI string from Block Service API
|
|
42
|
+
* @returns The ResourceId (full path after synced-block/)
|
|
43
|
+
*/
|
|
44
|
+
export const blockAriToResourceId = blockAri => {
|
|
45
|
+
// Validate ARI format and extract resourceId using regex
|
|
46
|
+
// Format: ari:cloud:blocks:{uuid}:synced-block/{product}/{parentId}/{resourceId}
|
|
47
|
+
// The regex captures the full path after synced-block/
|
|
48
|
+
// e.g. ari:cloud:blocks:DUMMY-a5a01d21-1cc3-4f29-9565-f2bb8cd969f5:synced-block/confluence-page/455232061495/e8cf64e3-1b6e-489b-ad86-8465b0905bb4
|
|
49
|
+
// should return confluence-page/455232061495/e8cf64e3-1b6e-489b-ad86-8465b0905bb4
|
|
50
|
+
const match = blockAri.match(/^ari:cloud:blocks:.*:synced-block\/(.+)$/);
|
|
51
|
+
return (match === null || match === void 0 ? void 0 : match[1]) || null;
|
|
52
|
+
};
|
|
53
|
+
|
|
28
54
|
// convert BlockContentResponse to SyncBlockData
|
|
29
55
|
// throws exception if JSON parsing fails
|
|
30
56
|
// what's missing from BlockContentResponse to SyncBlockData:
|
|
@@ -32,9 +58,9 @@ const mapBlockError = error => {
|
|
|
32
58
|
// - sourceURL
|
|
33
59
|
// - sourceTitle
|
|
34
60
|
// - isSynced
|
|
35
|
-
const convertToSyncBlockData = data => {
|
|
61
|
+
export const convertToSyncBlockData = (data, resourceId) => {
|
|
36
62
|
let createdAt;
|
|
37
|
-
if (data.createdAt) {
|
|
63
|
+
if (data.createdAt !== undefined && data.createdAt !== null) {
|
|
38
64
|
try {
|
|
39
65
|
// BE returns microseconds, convert to milliseconds
|
|
40
66
|
// BE should fix this in the future
|
|
@@ -51,7 +77,7 @@ const convertToSyncBlockData = data => {
|
|
|
51
77
|
createdAt,
|
|
52
78
|
createdBy: data.createdBy,
|
|
53
79
|
product: data.product,
|
|
54
|
-
resourceId
|
|
80
|
+
resourceId,
|
|
55
81
|
sourceAri: data.sourceAri
|
|
56
82
|
};
|
|
57
83
|
};
|
|
@@ -71,9 +97,17 @@ export const fetchReferences = async documentAri => {
|
|
|
71
97
|
} = response || {};
|
|
72
98
|
const blocksInstances = (blocks || []).map(blockContentResponse => {
|
|
73
99
|
try {
|
|
100
|
+
const resourceId = blockAriToResourceId(blockContentResponse.blockAri);
|
|
101
|
+
if (!resourceId) {
|
|
102
|
+
// could not extract resourceId from blockAri, return InvalidContent error
|
|
103
|
+
return {
|
|
104
|
+
error: SyncBlockError.InvalidContent,
|
|
105
|
+
resourceId: blockContentResponse.blockAri
|
|
106
|
+
};
|
|
107
|
+
}
|
|
74
108
|
return {
|
|
75
|
-
data: convertToSyncBlockData(blockContentResponse),
|
|
76
|
-
resourceId
|
|
109
|
+
data: convertToSyncBlockData(blockContentResponse, resourceId),
|
|
110
|
+
resourceId
|
|
77
111
|
};
|
|
78
112
|
} catch {
|
|
79
113
|
// JSON parsing error, return InvalidContent error
|
|
@@ -33,6 +33,32 @@ var mapBlockError = function mapBlockError(error) {
|
|
|
33
33
|
return SyncBlockError.Errored;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Extracts the ResourceId from a block ARI by returning the full path after synced-block/.
|
|
38
|
+
*
|
|
39
|
+
* Document ARI format from Block Service API:
|
|
40
|
+
* "ari:cloud:blocks:{uuid}:synced-block/{product}/{parentId}/{resourceId}"
|
|
41
|
+
*
|
|
42
|
+
* ResourceId format (extracted from ARI):
|
|
43
|
+
* "{product}/{parentId}/{resourceId}" (the full path after synced-block/)
|
|
44
|
+
*
|
|
45
|
+
* Example in context:
|
|
46
|
+
* Input: "ari:cloud:blocks:{uuid}:synced-block/confluence-page/{pageId}/{resourceId}"
|
|
47
|
+
* Output: "confluence-page/{pageId}/{resourceId}"
|
|
48
|
+
*
|
|
49
|
+
* @param blockAri - The block ARI string from Block Service API
|
|
50
|
+
* @returns The ResourceId (full path after synced-block/)
|
|
51
|
+
*/
|
|
52
|
+
export var blockAriToResourceId = function blockAriToResourceId(blockAri) {
|
|
53
|
+
// Validate ARI format and extract resourceId using regex
|
|
54
|
+
// Format: ari:cloud:blocks:{uuid}:synced-block/{product}/{parentId}/{resourceId}
|
|
55
|
+
// The regex captures the full path after synced-block/
|
|
56
|
+
// e.g. ari:cloud:blocks:DUMMY-a5a01d21-1cc3-4f29-9565-f2bb8cd969f5:synced-block/confluence-page/455232061495/e8cf64e3-1b6e-489b-ad86-8465b0905bb4
|
|
57
|
+
// should return confluence-page/455232061495/e8cf64e3-1b6e-489b-ad86-8465b0905bb4
|
|
58
|
+
var match = blockAri.match(/^ari:cloud:blocks:.*:synced-block\/(.+)$/);
|
|
59
|
+
return (match === null || match === void 0 ? void 0 : match[1]) || null;
|
|
60
|
+
};
|
|
61
|
+
|
|
36
62
|
// convert BlockContentResponse to SyncBlockData
|
|
37
63
|
// throws exception if JSON parsing fails
|
|
38
64
|
// what's missing from BlockContentResponse to SyncBlockData:
|
|
@@ -40,9 +66,9 @@ var mapBlockError = function mapBlockError(error) {
|
|
|
40
66
|
// - sourceURL
|
|
41
67
|
// - sourceTitle
|
|
42
68
|
// - isSynced
|
|
43
|
-
var convertToSyncBlockData = function convertToSyncBlockData(data) {
|
|
69
|
+
export var convertToSyncBlockData = function convertToSyncBlockData(data, resourceId) {
|
|
44
70
|
var createdAt;
|
|
45
|
-
if (data.createdAt) {
|
|
71
|
+
if (data.createdAt !== undefined && data.createdAt !== null) {
|
|
46
72
|
try {
|
|
47
73
|
// BE returns microseconds, convert to milliseconds
|
|
48
74
|
// BE should fix this in the future
|
|
@@ -59,7 +85,7 @@ var convertToSyncBlockData = function convertToSyncBlockData(data) {
|
|
|
59
85
|
createdAt: createdAt,
|
|
60
86
|
createdBy: data.createdBy,
|
|
61
87
|
product: data.product,
|
|
62
|
-
resourceId:
|
|
88
|
+
resourceId: resourceId,
|
|
63
89
|
sourceAri: data.sourceAri
|
|
64
90
|
};
|
|
65
91
|
};
|
|
@@ -90,9 +116,17 @@ export var fetchReferences = /*#__PURE__*/function () {
|
|
|
90
116
|
_ref2 = response || {}, blocks = _ref2.blocks, errors = _ref2.errors;
|
|
91
117
|
blocksInstances = (blocks || []).map(function (blockContentResponse) {
|
|
92
118
|
try {
|
|
119
|
+
var resourceId = blockAriToResourceId(blockContentResponse.blockAri);
|
|
120
|
+
if (!resourceId) {
|
|
121
|
+
// could not extract resourceId from blockAri, return InvalidContent error
|
|
122
|
+
return {
|
|
123
|
+
error: SyncBlockError.InvalidContent,
|
|
124
|
+
resourceId: blockContentResponse.blockAri
|
|
125
|
+
};
|
|
126
|
+
}
|
|
93
127
|
return {
|
|
94
|
-
data: convertToSyncBlockData(blockContentResponse),
|
|
95
|
-
resourceId:
|
|
128
|
+
data: convertToSyncBlockData(blockContentResponse, resourceId),
|
|
129
|
+
resourceId: resourceId
|
|
96
130
|
};
|
|
97
131
|
} catch (_unused) {
|
|
98
132
|
// JSON parsing error, return InvalidContent error
|
|
@@ -1,5 +1,24 @@
|
|
|
1
|
+
import { type BlockContentResponse } from '../../clients/block-service/blockService';
|
|
1
2
|
import { SyncBlockError, type ResourceId, type SyncBlockAttrs, type SyncBlockData, type SyncBlockProduct } from '../../common/types';
|
|
2
3
|
import type { ADFFetchProvider, ADFWriteProvider, DeleteSyncBlockResult, SyncBlockInstance, UpdateReferenceSyncBlockResult, WriteSyncBlockResult } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the ResourceId from a block ARI by returning the full path after synced-block/.
|
|
6
|
+
*
|
|
7
|
+
* Document ARI format from Block Service API:
|
|
8
|
+
* "ari:cloud:blocks:{uuid}:synced-block/{product}/{parentId}/{resourceId}"
|
|
9
|
+
*
|
|
10
|
+
* ResourceId format (extracted from ARI):
|
|
11
|
+
* "{product}/{parentId}/{resourceId}" (the full path after synced-block/)
|
|
12
|
+
*
|
|
13
|
+
* Example in context:
|
|
14
|
+
* Input: "ari:cloud:blocks:{uuid}:synced-block/confluence-page/{pageId}/{resourceId}"
|
|
15
|
+
* Output: "confluence-page/{pageId}/{resourceId}"
|
|
16
|
+
*
|
|
17
|
+
* @param blockAri - The block ARI string from Block Service API
|
|
18
|
+
* @returns The ResourceId (full path after synced-block/)
|
|
19
|
+
*/
|
|
20
|
+
export declare const blockAriToResourceId: (blockAri: string) => ResourceId | null;
|
|
21
|
+
export declare const convertToSyncBlockData: (data: BlockContentResponse, resourceId: ResourceId) => SyncBlockData;
|
|
3
22
|
export declare const fetchReferences: (documentAri: string) => Promise<SyncBlockInstance[] | SyncBlockError>;
|
|
4
23
|
interface BlockServiceADFFetchProviderProps {
|
|
5
24
|
cloudId: string;
|
|
@@ -1,5 +1,24 @@
|
|
|
1
|
+
import { type BlockContentResponse } from '../../clients/block-service/blockService';
|
|
1
2
|
import { SyncBlockError, type ResourceId, type SyncBlockAttrs, type SyncBlockData, type SyncBlockProduct } from '../../common/types';
|
|
2
3
|
import type { ADFFetchProvider, ADFWriteProvider, DeleteSyncBlockResult, SyncBlockInstance, UpdateReferenceSyncBlockResult, WriteSyncBlockResult } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the ResourceId from a block ARI by returning the full path after synced-block/.
|
|
6
|
+
*
|
|
7
|
+
* Document ARI format from Block Service API:
|
|
8
|
+
* "ari:cloud:blocks:{uuid}:synced-block/{product}/{parentId}/{resourceId}"
|
|
9
|
+
*
|
|
10
|
+
* ResourceId format (extracted from ARI):
|
|
11
|
+
* "{product}/{parentId}/{resourceId}" (the full path after synced-block/)
|
|
12
|
+
*
|
|
13
|
+
* Example in context:
|
|
14
|
+
* Input: "ari:cloud:blocks:{uuid}:synced-block/confluence-page/{pageId}/{resourceId}"
|
|
15
|
+
* Output: "confluence-page/{pageId}/{resourceId}"
|
|
16
|
+
*
|
|
17
|
+
* @param blockAri - The block ARI string from Block Service API
|
|
18
|
+
* @returns The ResourceId (full path after synced-block/)
|
|
19
|
+
*/
|
|
20
|
+
export declare const blockAriToResourceId: (blockAri: string) => ResourceId | null;
|
|
21
|
+
export declare const convertToSyncBlockData: (data: BlockContentResponse, resourceId: ResourceId) => SyncBlockData;
|
|
3
22
|
export declare const fetchReferences: (documentAri: string) => Promise<SyncBlockInstance[] | SyncBlockError>;
|
|
4
23
|
interface BlockServiceADFFetchProviderProps {
|
|
5
24
|
cloudId: string;
|
package/package.json
CHANGED