-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: function to get app config from data and hidden data
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict' | ||
|
||
// log on files | ||
const logger = require('console-files') | ||
|
||
module.exports = ({ appSdk, storeId, auth }, getHiddenData) => { | ||
// 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 | ||
let config = data.data || {} | ||
if (getHiddenData && typeof data.hidden_data === 'object' && data.hidden_data !== null) { | ||
Object.assign(data, data.hidden_data) | ||
} | ||
return config | ||
}) | ||
|
||
.catch(err => { | ||
// cannot GET current application | ||
// debug error | ||
logger.error(err) | ||
}) | ||
} |