11import cloneDeep from 'lodash/cloneDeep'
22import { publishUnpublish } from '../../entity'
33import { bindModuleHeaders } from '../../core/moduleHeaderSupport.js'
4+ import { getServiceVersion } from '../../core/serviceVersion.js'
45
56/**
67 * Bulk operations such as Publish, Unpublish, and Delete on multiple entries or assets.
@@ -101,7 +102,7 @@ export function BulkOperation (http, data = {}) {
101102 * .then((response) => { console.log(response) })
102103 */
103104 // eslint-disable-next-line camelcase
104- this . jobStatus = async ( { job_id, bulk_version = '' , api_version = '' } ) => {
105+ this . jobStatus = async ( { job_id, bulk_version = '' , api_version = getServiceVersion ( 'bulk_job_status' ) } ) => {
105106 // eslint-disable-next-line camelcase
106107 this . urlPath = `/bulk/jobs/${ job_id } `
107108 const headers = {
@@ -112,17 +113,13 @@ export function BulkOperation (http, data = {}) {
112113 // eslint-disable-next-line camelcase
113114 if ( bulk_version ) headers . headers . bulk_version = bulk_version
114115 // eslint-disable-next-line camelcase
115- if ( api_version ) headers . headers . api_version = api_version
116+ headers . headers . api_version = api_version
116117 try {
117118 const response = await http . get ( this . urlPath , headers )
118119 if ( response . data ) {
119- // eslint-disable-next-line camelcase
120- if ( api_version ) delete headers . headers . api_version
121120 return response . data
122121 }
123122 } catch ( error ) {
124- // eslint-disable-next-line camelcase
125- if ( api_version ) delete headers . headers . api_version
126123 console . error ( error )
127124 }
128125 }
@@ -145,7 +142,7 @@ export function BulkOperation (http, data = {}) {
145142 // eslint-disable-next-line camelcase
146143 this . getJobItems = async ( job_id , params = { } ) => {
147144 // eslint-disable-next-line camelcase
148- const { api_version = '3.2' , ...queryParams } = cloneDeep ( params )
145+ const { api_version = getServiceVersion ( 'bulk_job_items' ) , ...queryParams } = cloneDeep ( params )
149146 // eslint-disable-next-line camelcase
150147 this . urlPath = `/bulk/jobs/${ job_id } /items`
151148 const headers = {
@@ -154,18 +151,14 @@ export function BulkOperation (http, data = {}) {
154151 }
155152 }
156153 // eslint-disable-next-line camelcase
157- if ( api_version ) headers . headers . api_version = api_version
154+ headers . headers . api_version = api_version
158155 if ( Object . keys ( queryParams ) . length > 0 ) headers . params = queryParams
159156 try {
160157 const response = await http . get ( this . urlPath , headers )
161158 if ( response . data ) {
162- // eslint-disable-next-line camelcase
163- if ( api_version ) delete headers . headers . api_version
164159 return response . data
165160 }
166161 } catch ( error ) {
167- // eslint-disable-next-line camelcase
168- if ( api_version ) delete headers . headers . api_version
169162 console . error ( error )
170163 }
171164 }
@@ -231,7 +224,7 @@ export function BulkOperation (http, data = {}) {
231224 *
232225 */
233226 // eslint-disable-next-line camelcase
234- this . publish = async ( { details, skip_workflow_stage = false , approvals = false , is_nested = false , api_version = '' , publishAllLocalized = false } ) => {
227+ this . publish = async ( { details, skip_workflow_stage = false , approvals = false , is_nested = false , api_version = getServiceVersion ( 'bulk_publish' ) , publishAllLocalized = false } ) => {
235228 var httpBody = { }
236229 if ( details ) {
237230 httpBody = cloneDeep ( details )
@@ -264,7 +257,7 @@ export function BulkOperation (http, data = {}) {
264257 }
265258
266259 // eslint-disable-next-line camelcase
267- if ( api_version ) headers . headers . api_version = api_version
260+ headers . headers . api_version = api_version
268261
269262 return publishUnpublish ( http , '/bulk/publish' , httpBody , headers )
270263 }
@@ -329,7 +322,7 @@ export function BulkOperation (http, data = {}) {
329322 * .then((response) => { console.log(response.notice) })
330323 */
331324 // eslint-disable-next-line camelcase
332- this . unpublish = async ( { details, skip_workflow_stage = false , approvals = false , is_nested = false , api_version = '' , unpublishAllLocalized = false } ) => {
325+ this . unpublish = async ( { details, skip_workflow_stage = false , approvals = false , is_nested = false , api_version = getServiceVersion ( 'bulk_unpublish' ) , unpublishAllLocalized = false } ) => {
333326 var httpBody = { }
334327 if ( details ) {
335328 httpBody = cloneDeep ( details )
@@ -355,7 +348,7 @@ export function BulkOperation (http, data = {}) {
355348 headers . headers . approvals = approvals
356349 }
357350 // eslint-disable-next-line camelcase
358- if ( api_version ) headers . headers . api_version = api_version
351+ headers . headers . api_version = api_version
359352
360353 if ( unpublishAllLocalized ) {
361354 if ( ! headers . params ) {
0 commit comments