Skip to content

Commit f73e966

Browse files
author
Ali Tahir
committed
added ability to set configs using environment variables.
1 parent 8e5d653 commit f73e966

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/api-client.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,33 @@ const defaultConfig = {
2525
}
2626
};
2727

28+
function buildEnvConfig() {
29+
let env = process.env;
30+
let envConfig = {};
31+
if (env.hasOwnProperty('AGILITY_BASEURL')) {
32+
envConfig.baseUrl = env.AGILITY_BASEURL;
33+
}
34+
if (env.hasOwnProperty('AGILITY_GUID')) {
35+
envConfig.guid = env.AGILITY_GUID;
36+
}
37+
if (env.hasOwnProperty('AGILITY_APIKEY')) {
38+
envConfig.apiKey = env.AGILITY_APIKEY;
39+
}
40+
if (env.hasOwnProperty('AGILITY_ISPREVIEW')){
41+
envConfig.isPreview = env.AGILITY_ISPREVIEW;
42+
}
43+
44+
return envConfig;
45+
}
46+
2847
export default function createClient(userConfig) {
29-
48+
49+
let envConfig = buildEnvConfig();
3050

3151
//merge our config - user values will override our defaults
3252
let config = {
3353
...defaultConfig,
54+
...envConfig,
3455
...userConfig
3556
};
3657

test/getContentList.tests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ describe('getContentList:', function() {
300300
api.getContentList({
301301
referenceName: 'posts',
302302
languageCode: 'en-us',
303-
filters: [{property: 'properties.versionID', operator: api.types.FilterOperators.EQUAL_TO, value: '40'}, {property: 'properties.referenceName', operator: api.types.FilterOperators.LIKE, value: 'posts'}]
303+
filters: [{property: 'properties.versionID', operator: api.types.FilterOperators.GREATER_THAN, value: '40'}, {property: 'properties.referenceName', operator: api.types.FilterOperators.LIKE, value: 'posts'}],
304+
filtersLogicOperator: api.types.FilterLogicOperators.AND
304305
})
305306
.then(function(contentList) {
306307
assert.strictEqual(contentList.items[0].contentID, 16);

0 commit comments

Comments
 (0)