Skip to content

Commit e8cfb62

Browse files
committed
Merge branch 'master' into feature/content-branching
2 parents 3c970be + a652fd7 commit e8cfb62

File tree

12 files changed

+3198
-2249
lines changed

12 files changed

+3198
-2249
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ docdash-template/
2020
.env
2121
.babelrc
2222
.babel-preset.js
23-
.eslintrc.js
23+
.eslintrc.js
24+
.talismanrc

.talismanrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fileignoreconfig:
2+
- filename: jsdocs/stack_environment_index.js.html
3+
checksum: 1eac06c1c56f00422a548245f1c92fe505174fb349d85584d81508028117f53c
4+
- filename: dist/node/contentstack-management.js
5+
checksum: 0cc6ad62a7f0cef0882d7416e9ec966b34e56ef906592e11aa9a5dc4a6e443b9
6+
- filename: package-lock.json
7+
checksum: 99fcfcea623a71f7b8b8537e19ff32f2e20bc17a21dfe861ce5697c5e928bae7
8+
- filename: dist/nativescript/contentstack-management.js
9+
checksum: fbf96bf31cc89c74e3e239b8c330dd9be336af20973a0ec56dd11c463447ddf1
10+
- filename: dist/react-native/contentstack-management.js
11+
checksum: 4eeba7bb1f57f6031334d4394ce2a40890fdc8e96101f8c01441fca2e2708baa
12+
- filename: dist/web/contentstack-management.js
13+
checksum: 394411bc4d75c6ec6fc001cd2aea9747b91a065daa5b770dff0c1e58ef095465

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
# Changelog
2+
3+
## [v1.2.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.2.4) (2021-07-19)
4+
- Bug Fix
5+
- Form data upload timeout on retrying rate limit error issue resolved
6+
7+
## [v1.2.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.2.3) (2021-06-21)
8+
- Bug Fix
9+
- Request Timeout retry support added
10+
## [v1.2.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.2.2) (2021-05-26)
11+
- Bug Fix
12+
- Organization Specific get all Stack: Get Stack for specific organization from org_uid
13+
- Resolved: Entry Publish and Update not work after find function
14+
- Resolved: Workflow update issue on fetchAll function
15+
- Document Update
16+
- `update` Entry example code update
17+
218
## [v1.2.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.2.1) (2021-03-19)
319
- Bug Fix
420
- User get details: Include organization functions for `is_owner` of the organization

lib/core/concurrency-queue.js

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ export function ConcurrencyQueue ({ axios, config }) {
6969
}
7070
}
7171

72-
// Request interseptor to queue the request
72+
// Request interceptor to queue the request
7373
const requestHandler = request => {
74+
if (typeof request.data === 'function') {
75+
request.formdata = request.data
76+
request.data = transformFormData(request)
77+
}
7478
request.retryCount = request.retryCount || 0
7579
if (request.headers.authorization && request.headers.authorization !== undefined) {
7680
delete request.headers.authtoken
@@ -91,6 +95,9 @@ export function ConcurrencyQueue ({ axios, config }) {
9195
}
9296

9397
return new Promise(resolve => {
98+
request.onComplete = () => {
99+
this.running.pop({ request, resolve })
100+
}
94101
this.push({ request, resolve })
95102
})
96103
}
@@ -117,7 +124,7 @@ export function ConcurrencyQueue ({ axios, config }) {
117124

118125
// Response interceptor used for
119126
const responseHandler = (response) => {
120-
this.running.shift()
127+
response.config.onComplete()
121128
shift()
122129
return response
123130
}
@@ -130,15 +137,16 @@ export function ConcurrencyQueue ({ axios, config }) {
130137
}
131138

132139
// Error handling
133-
let wait = this.config.retryDelay
134-
const response = error.response
140+
const wait = this.config.retryDelay
141+
var response = error.response
135142
if (!response) {
136143
if (error.code === 'ECONNABORTED') {
137144
error.response = {
138145
...error.response,
139146
status: 408,
140147
statusText: `timeout of ${this.config.timeout}ms exceeded`
141148
}
149+
response = error.response
142150
} else {
143151
return Promise.reject(responseHandler(error))
144152
}
@@ -150,38 +158,43 @@ export function ConcurrencyQueue ({ axios, config }) {
150158
return Promise.reject(responseHandler(error))
151159
}
152160
this.running.shift()
153-
wait = 1000
154-
// Cooldown the running requests
161+
// Cool down the running requests
155162
delay(wait)
156163
error.config.retryCount = networkError
157164

158165
return axios(updateRequestConfig(error, retryErrorType, wait))
159-
} else if (this.config.retryCondition && this.config.retryCondition(error)) {
160-
retryErrorType = `Error with status: ${response.status}`
166+
}
167+
if (this.config.retryCondition && this.config.retryCondition(error)) {
168+
retryErrorType = error.response ? `Error with status: ${response.status}` : `Error Code:${error.code}`
161169
networkError++
162-
if (networkError > this.config.retryLimit) {
163-
return Promise.reject(responseHandler(error))
164-
}
165-
if (this.config.retryDelayOptions) {
166-
if (this.config.retryDelayOptions.customBackoff) {
167-
wait = this.config.retryDelayOptions.customBackoff(networkError, error)
168-
if (wait && wait <= 0) {
169-
return Promise.reject(responseHandler(error))
170-
}
171-
} else if (this.config.retryDelayOptions.base) {
172-
wait = this.config.retryDelayOptions.base * networkError
170+
return this.retry(error, retryErrorType, networkError, wait)
171+
}
172+
return Promise.reject(responseHandler(error))
173+
}
174+
175+
this.retry = (error, retryErrorType, retryCount, waittime) => {
176+
let delaytime = waittime
177+
if (retryCount > this.config.retryLimit) {
178+
return Promise.reject(responseHandler(error))
179+
}
180+
if (this.config.retryDelayOptions) {
181+
if (this.config.retryDelayOptions.customBackoff) {
182+
delaytime = this.config.retryDelayOptions.customBackoff(retryCount, error)
183+
if (delaytime && delaytime <= 0) {
184+
return Promise.reject(responseHandler(error))
173185
}
174-
} else {
175-
wait = this.config.retryDelay
186+
} else if (this.config.retryDelayOptions.base) {
187+
delaytime = this.config.retryDelayOptions.base * retryCount
176188
}
177-
error.config.retryCount = networkError
178-
return new Promise(function (resolve) {
179-
return setTimeout(function () {
180-
return resolve(axios(updateRequestConfig(error, retryErrorType, wait)))
181-
}, wait)
182-
})
189+
} else {
190+
delaytime = this.config.retryDelay
183191
}
184-
return Promise.reject(responseHandler(error))
192+
error.config.retryCount = retryCount
193+
return new Promise(function (resolve) {
194+
return setTimeout(function () {
195+
return resolve(axios(updateRequestConfig(error, retryErrorType, delaytime)))
196+
}, delaytime)
197+
})
185198
}
186199

187200
this.interceptors = {
@@ -204,12 +217,25 @@ export function ConcurrencyQueue ({ axios, config }) {
204217
}
205218
}
206219

220+
requestConfig.data = transformFormData(requestConfig)
207221
requestConfig.transformRequest = [function (data) {
208222
return data
209223
}]
210224
return requestConfig
211225
}
212226

227+
const transformFormData = (request) => {
228+
if (request.formdata) {
229+
const formdata = request.formdata()
230+
request.headers = {
231+
...request.headers,
232+
...formdata.getHeaders()
233+
}
234+
return formdata
235+
}
236+
return request.data
237+
}
238+
213239
// Adds interseptors in axios to queue request
214240
this.interceptors.request = axios.interceptors.request.use(requestHandler)
215241
this.interceptors.response = axios.interceptors.response.use(responseHandler, responseErrorHandler)

lib/entity.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export const upload = async ({ http, urlPath, stackHeaders, formData, params, me
5757
const headers = {
5858
headers: {
5959
...params,
60-
...formData.getHeaders(),
6160
...cloneDeep(stackHeaders)
6261
}
6362
} || {}

lib/stack/asset/index.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -233,28 +233,25 @@ export function AssetCollection (http, data) {
233233
return assetCollection
234234
}
235235

236-
function createFormData (data) {
237-
const formData = new FormData()
238-
if (typeof data['parent_uid'] === 'string') {
239-
formData.append('asset[parent_uid]', data['parent_uid'])
240-
}
241-
242-
if (typeof data.description === 'string') {
243-
formData.append('asset[description]', data.description)
244-
}
245-
246-
if (data.tags instanceof Array) {
247-
formData.append('asset[tags]', data.tags.join(','))
248-
} else if (typeof data.tags === 'string') {
249-
formData.append('asset[tags]', data.tags)
250-
}
251-
252-
if (typeof data.title === 'string') {
253-
formData.append('asset[title]', data.title)
236+
export function createFormData (data) {
237+
return () => {
238+
const formData = new FormData()
239+
if (typeof data['parent_uid'] === 'string') {
240+
formData.append('asset[parent_uid]', data['parent_uid'])
241+
}
242+
if (typeof data.description === 'string') {
243+
formData.append('asset[description]', data.description)
244+
}
245+
if (data.tags instanceof Array) {
246+
formData.append('asset[tags]', data.tags.join(','))
247+
} else if (typeof data.tags === 'string') {
248+
formData.append('asset[tags]', data.tags)
249+
}
250+
if (typeof data.title === 'string') {
251+
formData.append('asset[title]', data.title)
252+
}
253+
const uploadStream = createReadStream(data.upload)
254+
formData.append('asset[upload]', uploadStream)
255+
return formData
254256
}
255-
256-
const uploadStream = createReadStream(data.upload)
257-
formData.append('asset[upload]', uploadStream)
258-
259-
return formData
260257
}

lib/stack/contentType/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,11 @@ export function ContentTypeCollection (http, data) {
198198
return contentTypeCollection
199199
}
200200

201-
function createFormData (data) {
202-
const formData = new FormData()
203-
const uploadStream = createReadStream(data.content_type)
204-
formData.append('content_type', uploadStream)
205-
return formData
201+
export function createFormData (data) {
202+
return () => {
203+
const formData = new FormData()
204+
const uploadStream = createReadStream(data.content_type)
205+
formData.append('content_type', uploadStream)
206+
return formData
207+
}
206208
}

lib/stack/extension/index.js

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -155,34 +155,35 @@ export function ExtensionCollection (http, data) {
155155
return extensionCollection
156156
}
157157

158-
function createExtensionFormData (data) {
159-
const formData = new FormData()
158+
export function createExtensionFormData (data) {
159+
return () => {
160+
const formData = new FormData()
160161

161-
if (typeof data.title === 'string') {
162-
formData.append('extension[title]', data.title)
163-
}
164-
if (typeof data.scope === 'object') {
165-
formData.append('extension[scope]', `${data.scope}`)
166-
}
167-
if (typeof data['data_type'] === 'string') {
168-
formData.append('extension[data_type]', data['data_type'])
169-
}
170-
if (typeof data.type === 'string') {
171-
formData.append('extension[type]', data.type)
172-
}
173-
if (data.tags instanceof Array) {
174-
formData.append('extension[tags]', data.tags.join(','))
175-
} else if (typeof data.tags === 'string') {
176-
formData.append('extension[tags]', data.tags)
177-
}
178-
if (typeof data.multiple === 'boolean') {
179-
formData.append('extension[multiple]', `${data.multiple}`)
180-
}
181-
if (typeof data.enable === 'boolean') {
182-
formData.append('extension[enable]', `${data.enable}`)
162+
if (typeof data.title === 'string') {
163+
formData.append('extension[title]', data.title)
164+
}
165+
if (typeof data.scope === 'object') {
166+
formData.append('extension[scope]', `${data.scope}`)
167+
}
168+
if (typeof data['data_type'] === 'string') {
169+
formData.append('extension[data_type]', data['data_type'])
170+
}
171+
if (typeof data.type === 'string') {
172+
formData.append('extension[type]', data.type)
173+
}
174+
if (data.tags instanceof Array) {
175+
formData.append('extension[tags]', data.tags.join(','))
176+
} else if (typeof data.tags === 'string') {
177+
formData.append('extension[tags]', data.tags)
178+
}
179+
if (typeof data.multiple === 'boolean') {
180+
formData.append('extension[multiple]', `${data.multiple}`)
181+
}
182+
if (typeof data.enable === 'boolean') {
183+
formData.append('extension[enable]', `${data.enable}`)
184+
}
185+
const uploadStream = createReadStream(data.upload)
186+
formData.append('extension[upload]', uploadStream)
187+
return formData
183188
}
184-
185-
const uploadStream = createReadStream(data.upload)
186-
formData.append('extension[upload]', uploadStream)
187-
return formData
188189
}

lib/stack/globalField/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,11 @@ export function GlobalFieldCollection (http, data) {
148148
return globalFieldCollection
149149
}
150150

151-
function createFormData (data) {
152-
const formData = new FormData()
153-
const uploadStream = createReadStream(data.global_field)
154-
formData.append('global_field', uploadStream)
155-
return formData
151+
export function createFormData (data) {
152+
return () => {
153+
const formData = new FormData()
154+
const uploadStream = createReadStream(data.global_field)
155+
formData.append('global_field', uploadStream)
156+
return formData
157+
}
156158
}

lib/stack/webhook/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,11 @@ export function WebhookCollection (http, data) {
231231
return webhookCollection
232232
}
233233

234-
function createFormData (data) {
235-
const formData = new FormData()
236-
const uploadStream = createReadStream(data.webhook)
237-
formData.append('webhook', uploadStream)
238-
return formData
234+
export function createFormData (data) {
235+
return () => {
236+
const formData = new FormData()
237+
const uploadStream = createReadStream(data.webhook)
238+
formData.append('webhook', uploadStream)
239+
return formData
240+
}
239241
}

0 commit comments

Comments
 (0)