forked from windingtree/glider-aggregator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
205 lines (190 loc) · 7.96 KB
/
config.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* config.js - Provides configuration
*
* Variables are retrieved by order of priority:
* - From an environment specific variable: STAGING_.., if any
* - From the environment variable, if any
* - From a default value configured in this file
*
* Environment is determined from:
* - The GLIDER_ENV variable, if any
* - The Github's branch, if the deployment is made using the Vercel/Github integration
* - Defaults to 'staging', including local
*/
const path = require('path');
const profiles = require('@windingtree/config-profiles');
let buildEnv;
try {
buildEnv = require('./env.json');
} catch (err) {
console.warn('cannot load env.json file', err);
}
const activeProfile = process.env.ACTIVE_PROFILE || 'staging';
console.log('Active profile:', activeProfile);
profiles.init({
baseFolder: path.join(process.cwd(), 'api/profiles'),
dbUrl: profiles.getEnvironmentEntry(activeProfile, 'MONGO_URL'),
encryptionDetails: profiles.getEnvironmentEntry(activeProfile, 'PROFILE_SECRET'),
},
);
let features = {};
try {
features = require('./features.json');
} catch (err) {
console.warn('cannot load features.json file', err);
}
// Define the current environment
const determineEnviroment = () => {
// If defined, use the Glider environment variable
if (process.env.GLIDER_ENV) {
return process.env.GLIDER_ENV;
}
// If env.json file present, use it
if (buildEnv) {
return buildEnv.environment;
}
// Otherwise use the Github branch provided by Vercel
switch (process.env.VERCEL_GITHUB_COMMIT_REF || process.env.NOW_GITHUB_COMMIT_REF) {
case 'master':
return 'production';
case 'develop':
default:
return 'staging';
}
};
const environment = determineEnviroment();
console.log('ENV:', environment);
// Get an an environment variable
const getConfigKey = (key, defaultValue) => {
return profiles.getEnvOrProfileEntry(key, defaultValue);
};
module.exports.getConfigKey = getConfigKey;
const getConfigKeyAsArray = (key, defaultValue) => {
let result = getConfigKey(key);
if (result) {
let arr = result.split(',');
arr = arr.map(key => key.trim());
return arr;
}
return defaultValue;
};
module.exports.getConfigKeyAsArray = getConfigKeyAsArray;
const airFranceConfig = {
apiKey: getConfigKey('AF_API_KEY'),
commission: getConfigKey('AF_COMISSION') || '0',
AirlineID: getConfigKey('AF_PARTICIPANT_RECIPENT_AIRLINE_ID') || 'AF',
Party: {
Sender: {
TravelAgencySender: {
Name: getConfigKey('AF_SENDER_NAME') || 'Test',
PseudoCity: getConfigKey('AF_SENDER_PSEUDOCITY') || 'PARMM211L',
'IATA_Number': getConfigKey('AF_SENDER_IATA_NUMBER') || '12345675',
AgencyID: getConfigKey('AF_SENDER_AGENCY_ID') || 'id',
AgentUser: {
AgentUserID: getConfigKey('AF_SENDER_AGENT_USER_ID') || '1234',
},
},
},
Participants: {
Participant: {
EnabledSystemParticipant: {
SequenceNumber: getConfigKey('AF_PARTICIPANT_ENABLED_SYSTEM_PARTICIPANT_SEQUENCE_NUMBER') || '12',
Name: getConfigKey('AF_PARTICIPANT_ENABLED_SYSTEM_PARTICIPANT_NAME') || 'MASHERY',
SystemID: getConfigKey('AF_PARTICIPANT_ENABLED_SYSTEM_PARTICIPANT_SYSTEM_ID') || 'MAS',
},
Recipient: {
'ORA_Recipient': {
AirlineID: getConfigKey('AF_PARTICIPANT_RECIPENT_AIRLINE_ID') || 'AF',
Name: getConfigKey('AF_PARTICIPANT_RECIPENT_NAME') || 'AIRFRANCE',
},
},
},
},
},
};
const airCanadaConfig = {
apiKey: getConfigKey('AC_API_KEY'),
commission: getConfigKey('AC_COMISSION') || '0',
baseUrl: getConfigKey('AC_BASEURL') || (environment === 'production' ? 'https://ndcexchange.mconnect.aero/messaging/v2/ndc-exchange/' : 'https://ndchub.mconnect.aero/messaging/v2/ndc-exchange/'),
baseUrlPci: getConfigKey('AC_BASEURL_PCI') || (environment === 'production' ? 'https://pci.ndcexchange.mconnect.aero/messaging/v2/ndc-exchange/' : 'https://pci.ndchub.mconnect.aero/messaging/v2/ndc-exchange/'),
AirlineID: getConfigKey('AC_PARTICIPANT_RECIPENT_AIRLINE_ID') || 'AC',
PointOfSale: {
Location: {
CountryCode: {
'@value': getConfigKey('AC_POS_COUNTRY_CODE') || 'CA',
},
},
TouchPoint: {
Device: {
Code: getConfigKey('AC_POS_DEVICE_CODE') || '0.AAA.X',
TableName: {},
},
},
},
Document: {
'@id': getConfigKey('AC_DOCUMENT_ID') || 'OneWay',
Name: getConfigKey('AC_DOCUMENT_NAME') || 'NDC-Exchange',
ReferenceVersion: getConfigKey('AC_DOCUMENT_REFERENCE_VERSION') || 'UAT-OTA-2010B',
},
Party: {
Participants: {
Participant: {
EnabledSystemParticipant: {
'@SequenceNumber': getConfigKey('AC_PARTICIPANT_ENABLED_SYSTEM_PARTICIPANT_SEQUENCE_NUMBER') || '1',
Name: getConfigKey('AC_USERNAME') || getConfigKey('AC_PARTICIPANT_ENABLED_SYSTEM_PARTICIPANT_NAME'),
Category: getConfigKey('AC_PARTICIPANT_ENABLED_SYSTEM_PARTICIPANT_CATEGORY') || 'DC',
SystemID: {
'@Owner': getConfigKey('AC_PARTICIPANT_ENABLED_SYSTEM_PARTICIPANT_SYSTEM_ID_OWNER') || 'ADS',
'@value': getConfigKey('AC_PASSWORD') || getConfigKey('AC_PARTICIPANT_ENABLED_SYSTEM_PARTICIPANT_SYSTEM_ID'),
},
},
},
},
},
};
const amadeusGdsConfig = { //TEST
clientId: getConfigKey('AMADEUS_ENT_CLIENT_ID'),
clientSecret: getConfigKey('AMADEUS_ENT_CLIENT_SECRET'),
hostname: getConfigKey('AMADEUS_ENT_ENVIRONMENT') || 'test',
};
const amadeusSelfServiceConfig = { //TEST
clientId: getConfigKey('AMADEUS_SS_CLIENT_ID'),
clientSecret: getConfigKey('AMADEUS_SS_CLIENT_SECRET'),
hostname: getConfigKey('AMADEUS_SS_ENVIRONMENT') || 'test',
};
const erevmax = {
availabilityUrl: getConfigKey('EREVMAX_AVAILABILITY_URL') || 'https://ota-simulator.now.sh/api?ota=OTA_HotelAvailRS.xml',
reservationUrl: getConfigKey('EREVMAX_RESERVATION_URL') || 'https://ota-simulator.now.sh/api?ota=OTA_HotelResNotifRS_commit.xml',
cancellationUrl: getConfigKey('EREVMAX_CANCELLATION_URL') || 'https://ota-simulator.now.sh/api?ota=OTA_HotelResNotifRS_cancel.xml',
};
module.exports.debugInfo = () => {
return {
environment: environment,
erevmax: erevmax,
env: process.env,
buildEnv: buildEnv,
features: features,
};
};
module.exports.airFranceConfig = airFranceConfig;
module.exports.airCanadaConfig = airCanadaConfig;
module.exports.amadeusGdsConfig = amadeusGdsConfig;
module.exports.AMADEUS_CLIENT_TYPE = getConfigKey('AMADEUS_CLIENT_TYPE') || 'selfservice';
module.exports.amadeusSelfServiceConfig = amadeusSelfServiceConfig;
module.exports.erevmax = erevmax;
module.exports.redisUrl = getConfigKey('REDIS_URL') || 'redis://localhost:6379';
module.exports.mongoUrl = getConfigKey('MONGO_URL') || 'mongodb://localhost/glider';
module.exports.BUSINESS_RULES_MONGO_URL = getConfigKey('BUSINESS_RULES_MONGO_URL') || 'mongodb://localhost/glider';
module.exports.elasticUrl = getConfigKey('ELASTIC_URL') || 'http://localhost:9200';
module.exports.INFURA_URI = `${getConfigKey('INFURA_ENDPOINT')}/${getConfigKey('INFURA_PROJECT_ID')}`;
module.exports.GLIDER_DID = `did:orgid:${getConfigKey('GLIDER_ORGID') || '0x71cd1781a3082f33d2521ac8290c9d4b3b3b116e4e8548a4914b71a1f7201da0'}`;
module.exports.GLIDER_ADMIN_DID = `did:orgid:${getConfigKey('GLIDER_ORGID') || '0x71cd1781a3082f33d2521ac8290c9d4b3b3b116e4e8548a4914b71a1f7201da0'}#${getConfigKey('GLIDER_ADMIN_KEY') || ''}`;
module.exports.SIMARD_URL = getConfigKey('SIMARD_URL') || `https://${environment}.api.simard.io/api/v1`;
module.exports.SIMARD_JWT = getConfigKey('SIMARD_JWT') || getConfigKey('JWT');
module.exports.LIF_MIN_DEPOSIT = getConfigKey('LIF_MIN_DEPOSIT') || '0';
module.exports.expirationTime = 30 * 60; // 30 min in seconds
module.exports.expirationLong = 60 * 60 * 24 * 365 * 7; // 7 years in seconds
module.exports.ETHEREUM_NETWORK = getConfigKey('ETHEREUM_NETWORK') || 'ropsten';
module.exports.environment = environment;
module.exports.DEVELOPMENT_MODE = getConfigKey('DEVELOPMENT_MODE',false);
module.exports.branch = process.env.VERCEL_GITHUB_COMMIT_REF;