@@ -26,6 +26,16 @@ interface BulkActionResponse {
26
26
error ?: any
27
27
}
28
28
29
+ // Define the correct types for bulk action payloads
30
+ interface VersionedLink {
31
+ sys : {
32
+ type : "Link"
33
+ linkType : "Entry" | "Asset"
34
+ id : string
35
+ version ?: number
36
+ }
37
+ }
38
+
29
39
type BulkUnpublishParams = BulkPublishParams
30
40
31
41
type BulkValidateParams = {
@@ -41,6 +51,45 @@ export const bulkActionHandlers = {
41
51
42
52
const contentfulClient = await getContentfulClient ( )
43
53
54
+ // Get the current version of each entity
55
+ const entityVersions : VersionedLink [ ] = await Promise . all (
56
+ args . entities . map ( async ( entity ) => {
57
+ try {
58
+ // Get the current version of the entity
59
+ const currentEntity = entity . sys . type === "Entry"
60
+ ? await contentfulClient . entry . get ( {
61
+ spaceId,
62
+ environmentId,
63
+ entryId : entity . sys . id
64
+ } )
65
+ : await contentfulClient . asset . get ( {
66
+ spaceId,
67
+ environmentId,
68
+ assetId : entity . sys . id
69
+ } ) ;
70
+
71
+ return {
72
+ sys : {
73
+ type : "Link" ,
74
+ linkType : entity . sys . type ,
75
+ id : entity . sys . id ,
76
+ version : currentEntity . sys . version
77
+ }
78
+ } ;
79
+ } catch ( error ) {
80
+ console . error ( `Error fetching entity ${ entity . sys . id } : ${ error } ` ) ;
81
+ // Return without version if we can't get it
82
+ return {
83
+ sys : {
84
+ type : "Link" ,
85
+ linkType : entity . sys . type ,
86
+ id : entity . sys . id
87
+ }
88
+ } ;
89
+ }
90
+ } )
91
+ ) ;
92
+
44
93
// Create the bulk action
45
94
const bulkAction = await contentfulClient . bulkAction . publish (
46
95
{
@@ -52,13 +101,7 @@ export const bulkActionHandlers = {
52
101
sys : {
53
102
type : "Array" ,
54
103
} ,
55
- items : args . entities . map ( ( entity ) => ( {
56
- sys : {
57
- type : "Link" ,
58
- linkType : entity . sys . type ,
59
- id : entity . sys . id ,
60
- } ,
61
- } ) ) ,
104
+ items : entityVersions ,
62
105
} ,
63
106
} ,
64
107
)
@@ -99,6 +142,45 @@ export const bulkActionHandlers = {
99
142
100
143
const contentfulClient = await getContentfulClient ( )
101
144
145
+ // Get the current version of each entity
146
+ const entityVersions : VersionedLink [ ] = await Promise . all (
147
+ args . entities . map ( async ( entity ) => {
148
+ try {
149
+ // Get the current version of the entity
150
+ const currentEntity = entity . sys . type === "Entry"
151
+ ? await contentfulClient . entry . get ( {
152
+ spaceId,
153
+ environmentId,
154
+ entryId : entity . sys . id
155
+ } )
156
+ : await contentfulClient . asset . get ( {
157
+ spaceId,
158
+ environmentId,
159
+ assetId : entity . sys . id
160
+ } ) ;
161
+
162
+ return {
163
+ sys : {
164
+ type : "Link" ,
165
+ linkType : entity . sys . type ,
166
+ id : entity . sys . id ,
167
+ version : currentEntity . sys . version
168
+ }
169
+ } ;
170
+ } catch ( error ) {
171
+ console . error ( `Error fetching entity ${ entity . sys . id } : ${ error } ` ) ;
172
+ // Return without version if we can't get it
173
+ return {
174
+ sys : {
175
+ type : "Link" ,
176
+ linkType : entity . sys . type ,
177
+ id : entity . sys . id
178
+ }
179
+ } ;
180
+ }
181
+ } )
182
+ ) ;
183
+
102
184
// Create the bulk action
103
185
const bulkAction = await contentfulClient . bulkAction . unpublish (
104
186
{
@@ -110,13 +192,7 @@ export const bulkActionHandlers = {
110
192
sys : {
111
193
type : "Array" ,
112
194
} ,
113
- items : args . entities . map ( ( entity ) => ( {
114
- sys : {
115
- type : "Link" ,
116
- linkType : entity . sys . type ,
117
- id : entity . sys . id ,
118
- } ,
119
- } ) ) ,
195
+ items : entityVersions ,
120
196
} ,
121
197
} ,
122
198
)
@@ -157,6 +233,39 @@ export const bulkActionHandlers = {
157
233
158
234
const contentfulClient = await getContentfulClient ( )
159
235
236
+ // Get the current version of each entry
237
+ const entityVersions : VersionedLink [ ] = await Promise . all (
238
+ args . entryIds . map ( async ( id ) => {
239
+ try {
240
+ // Get the current version of the entry
241
+ const currentEntry = await contentfulClient . entry . get ( {
242
+ spaceId,
243
+ environmentId,
244
+ entryId : id
245
+ } ) ;
246
+
247
+ return {
248
+ sys : {
249
+ type : "Link" ,
250
+ linkType : "Entry" ,
251
+ id,
252
+ version : currentEntry . sys . version
253
+ }
254
+ } ;
255
+ } catch ( error ) {
256
+ console . error ( `Error fetching entry ${ id } : ${ error } ` ) ;
257
+ // Return without version if we can't get it
258
+ return {
259
+ sys : {
260
+ type : "Link" ,
261
+ linkType : "Entry" ,
262
+ id
263
+ }
264
+ } ;
265
+ }
266
+ } )
267
+ ) ;
268
+
160
269
// Create the bulk action
161
270
const bulkAction = await contentfulClient . bulkAction . validate (
162
271
{
@@ -168,13 +277,7 @@ export const bulkActionHandlers = {
168
277
sys : {
169
278
type : "Array" ,
170
279
} ,
171
- items : args . entryIds . map ( ( id ) => ( {
172
- sys : {
173
- type : "Link" ,
174
- linkType : "Entry" ,
175
- id,
176
- } ,
177
- } ) ) ,
280
+ items : entityVersions ,
178
281
} ,
179
282
} ,
180
283
)
0 commit comments