@@ -32,10 +32,18 @@ interface VersionedLink {
32
32
type : "Link"
33
33
linkType : "Entry" | "Asset"
34
34
id : string
35
- version ? : number
35
+ version : number
36
36
}
37
37
}
38
38
39
+ // Define a Collection type to match SDK expectations
40
+ interface Collection < T > {
41
+ sys : {
42
+ type : "Array"
43
+ }
44
+ items : T [ ]
45
+ }
46
+
39
47
type BulkUnpublishParams = BulkPublishParams
40
48
41
49
type BulkValidateParams = {
@@ -52,7 +60,7 @@ export const bulkActionHandlers = {
52
60
const contentfulClient = await getContentfulClient ( )
53
61
54
62
// Get the current version of each entity
55
- const entityVersions : VersionedLink [ ] = await Promise . all (
63
+ const entityVersions = await Promise . all (
56
64
args . entities . map ( async ( entity ) => {
57
65
try {
58
66
// Get the current version of the entity
@@ -71,38 +79,34 @@ export const bulkActionHandlers = {
71
79
return {
72
80
sys : {
73
81
type : "Link" ,
74
- linkType : entity . sys . type ,
82
+ linkType : entity . sys . type as "Entry" | "Asset" ,
75
83
id : entity . sys . id ,
76
84
version : currentEntity . sys . version
77
85
}
78
86
} ;
79
87
} catch ( error ) {
80
88
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
+ throw new Error ( `Failed to get version for entity ${ entity . sys . id } . All entities must have a version.` ) ;
89
90
}
90
91
} )
91
92
) ;
92
93
94
+ // Create the collection object with the correct structure
95
+ const entitiesCollection : Collection < VersionedLink > = {
96
+ sys : {
97
+ type : "Array"
98
+ } ,
99
+ items : entityVersions
100
+ } ;
101
+
93
102
// Create the bulk action
94
103
const bulkAction = await contentfulClient . bulkAction . publish (
95
104
{
96
105
spaceId,
97
106
environmentId,
98
107
} ,
99
108
{
100
- entities : {
101
- sys : {
102
- type : "Array" ,
103
- } ,
104
- items : entityVersions ,
105
- } ,
109
+ entities : entitiesCollection ,
106
110
} ,
107
111
)
108
112
@@ -143,7 +147,7 @@ export const bulkActionHandlers = {
143
147
const contentfulClient = await getContentfulClient ( )
144
148
145
149
// Get the current version of each entity
146
- const entityVersions : VersionedLink [ ] = await Promise . all (
150
+ const entityVersions = await Promise . all (
147
151
args . entities . map ( async ( entity ) => {
148
152
try {
149
153
// Get the current version of the entity
@@ -162,38 +166,34 @@ export const bulkActionHandlers = {
162
166
return {
163
167
sys : {
164
168
type : "Link" ,
165
- linkType : entity . sys . type ,
169
+ linkType : entity . sys . type as "Entry" | "Asset" ,
166
170
id : entity . sys . id ,
167
171
version : currentEntity . sys . version
168
172
}
169
173
} ;
170
174
} catch ( error ) {
171
175
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
- } ;
176
+ throw new Error ( `Failed to get version for entity ${ entity . sys . id } . All entities must have a version.` ) ;
180
177
}
181
178
} )
182
179
) ;
183
180
181
+ // Create the collection object with the correct structure
182
+ const entitiesCollection : Collection < VersionedLink > = {
183
+ sys : {
184
+ type : "Array"
185
+ } ,
186
+ items : entityVersions
187
+ } ;
188
+
184
189
// Create the bulk action
185
190
const bulkAction = await contentfulClient . bulkAction . unpublish (
186
191
{
187
192
spaceId,
188
193
environmentId,
189
194
} ,
190
195
{
191
- entities : {
192
- sys : {
193
- type : "Array" ,
194
- } ,
195
- items : entityVersions ,
196
- } ,
196
+ entities : entitiesCollection ,
197
197
} ,
198
198
)
199
199
@@ -234,7 +234,7 @@ export const bulkActionHandlers = {
234
234
const contentfulClient = await getContentfulClient ( )
235
235
236
236
// Get the current version of each entry
237
- const entityVersions : VersionedLink [ ] = await Promise . all (
237
+ const entityVersions = await Promise . all (
238
238
args . entryIds . map ( async ( id ) => {
239
239
try {
240
240
// Get the current version of the entry
@@ -254,31 +254,27 @@ export const bulkActionHandlers = {
254
254
} ;
255
255
} catch ( error ) {
256
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
- } ;
257
+ throw new Error ( `Failed to get version for entry ${ id } . All entries must have a version.` ) ;
265
258
}
266
259
} )
267
260
) ;
268
261
262
+ // Create the collection object with the correct structure
263
+ const entitiesCollection : Collection < VersionedLink > = {
264
+ sys : {
265
+ type : "Array"
266
+ } ,
267
+ items : entityVersions
268
+ } ;
269
+
269
270
// Create the bulk action
270
271
const bulkAction = await contentfulClient . bulkAction . validate (
271
272
{
272
273
spaceId,
273
274
environmentId,
274
275
} ,
275
276
{
276
- entities : {
277
- sys : {
278
- type : "Array" ,
279
- } ,
280
- items : entityVersions ,
281
- } ,
277
+ entities : entitiesCollection ,
282
278
} ,
283
279
)
284
280
0 commit comments