generated from ecomplus/application-starter
-
Notifications
You must be signed in to change notification settings - Fork 4
/
get-app-data.js
40 lines (34 loc) · 1.16 KB
/
get-app-data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// handle Store API errors
const errorHandling = require('./error-handling')
module.exports = ({ appSdk, storeId, auth }, getHiddenData = true) => {
// read configured options from app data
// https://developers.e-com.plus/docs/api/#/store/applications/applications
let apiRequest
if (getHiddenData) {
// send authenticated request to get full application document from Store API
const subresource = null
const method = 'GET'
const data = {}
apiRequest = appSdk.apiApp(storeId, subresource, method, data, auth)
} else {
// send non-authenticated request to get only the public app body
apiRequest = appSdk.appPublicBody(storeId, auth)
}
// returns Store API request promise
return apiRequest
.then(({ response }) => {
const { data } = response
// setup returned config object
const config = data.data || {}
if (getHiddenData && typeof data.hidden_data === 'object' && data.hidden_data !== null) {
Object.assign(config, data.hidden_data)
}
return config
})
.catch(err => {
// cannot GET current application
// debug error
errorHandling(err)
throw err
})
}