Skip to content

Commit

Permalink
Add log for new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
1v4n4 committed Jun 14, 2024
1 parent c30ef46 commit b8f7048
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
37 changes: 22 additions & 15 deletions dist/crm/gpdedatahub/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,40 @@ dotenv_1.default.config();
const url = process.env.CRM_URL;
const username = process.env.CRM_USERNAME;
const password = process.env.CRM_PASSWORD;
const testUrl = process.env.CRM_TEST_URL;
const testUsername = process.env.CRM_TEST_USERNAME;
const testPassword = process.env.CRM_TEST_PASSWORD;
if (!url || !username || !password) {
console.error("no credentials");
process.exit();
console.error("No credentials");
process.exit(1);
}
const authToken = `${username}:${password}`;
const tokenEncoded = Buffer.from(authToken).toString('base64');
const headers = {
"Authorization": `Basic ${tokenEncoded}`,
"Content-type": "application/json"
const getEncodedToken = (username, password) => {
return username && password ? Buffer.from(`${username}:${password}`).toString('base64') : null;
};
const tokenEncoded = getEncodedToken(username, password);
// If there is no test environment, use production credentials
const testTokenEncoded = getEncodedToken(testUsername, testPassword) || tokenEncoded;
const postAction = (action) => __awaiter(void 0, void 0, void 0, function* () {
const isTest = action.action.testing || false;
const requestUrl = isTest ? (testUrl || url) : url;
const headers = {
"Authorization": `Basic ${isTest ? testTokenEncoded : tokenEncoded}`,
"Content-type": "application/json"
};
const body = JSON.stringify(action);
try {
const response = yield fetch(url, {
const response = yield fetch(requestUrl, {
method: "POST",
headers: {
"Authorization": `Basic ${tokenEncoded}`,
"Content-type": "application/json"
},
headers: headers,
body: body
});
//we only get status = 200 if everything is fine;
// We only get status = 200 if everything is fine;
console.log(action.actionId, requestUrl);
return response.status;
}
catch (error) {
console.error('post error: ', error);
throw (error);
console.error('Post error:', error);
throw error;
}
});
exports.postAction = postAction;
1 change: 1 addition & 0 deletions src/crm/gpdedatahub/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const postAction = async (action: GPAction): Promise<number> => {
});

// We only get status = 200 if everything is fine;
console.log(action.actionId, requestUrl)
return response.status;
} catch (error: any) {
console.error('Post error:', error);
Expand Down

0 comments on commit b8f7048

Please sign in to comment.