Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

personio, hibob (new) Connector contribution program [Maesn] #167

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/appmixer/hibob/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module.exports = {

type: 'pwd',

definition: {

accountNameFromProfileInfo: 'serviceUserId',
auth: {
serviceUserId: {
type: 'text',
name: 'Servivce User Id',
tooltip: 'Servivce User Id'
},
serviceUserToken: {
type: 'password',
name: 'Token',
tooltip: 'The service user token from your HiBob account'
}
},

validate: async context => {

const { serviceUserId, serviceUserToken } = context;
const token = Buffer.from(serviceUserId + ':' + serviceUserToken).toString('base64');

const auth = 'Basic ' + token;
const url = 'https://api.hibob.com/v1/company/named-lists';

try {
await context.httpRequest({
method: 'GET',
url: url,
headers: {
'Authorization': auth
}
});

} catch (error) {
throw new Error('Invalid id/token combination.');
}

return {
token: token
};
}
}
};
75 changes: 75 additions & 0 deletions src/appmixer/hibob/employees/DeletedEmployee/DeletedEmployee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict';
const Promise = require('bluebird');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove bluebird dependency.


/**
* Process employees to find newly deleted.
* @param {Array} currentEmployees
* @param {Array} deletedEmployees
* @param {Object} employeeId
*/


Comment on lines +10 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove empty lines.

function processEmployees(currentEmployees, deletedEmployees, employeeId) {
if (!currentEmployees.includes(employeeId)) {
deletedEmployees.push(employeeId);
}
}

/**
* Component which triggers whenever an employee is deleted.
*/
class DeletedEmployee {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for defining a class and later exporting it? Can it be simplified instead like this?

Suggested change
class DeletedEmployee {
module.exports = {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this is simply that it was required for our logging framework, which I removed from the components as it would not be relevant to you


async receive(context) {
try {
const auth = 'Basic ' + context.auth.token;
let hibobEndpoint = 'https://api.hibob.com/v1/people/search';

const { data } = await context.httpRequest({
url: hibobEndpoint,
method: 'POST',
headers: {
Authorization: auth
},
data: {
'humanReadable': 'APPEND',
'showInactive': true,
'fields': [
'/root/firstName',
'/root/surname',
'/root/id',
'/root/email',
'/internal/status',
'/work/manager'
]
},
json: true
});

let known = Array.isArray(context.state.known) ? new Set(context.state.known) : new Set();
let current = (data.employees || []).map(employee => employee.id);
let diff = [];

if (known.size > 0) {
known.forEach(processEmployees.bind(null, current, diff));
}

await Promise.map(diff, employee => {
// TODO: Add logging here
return context.sendJson({ employee }, 'out');
});
Comment on lines +57 to +60
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use native await Promise.all and not bluebird's Promise.map.


await context.saveState({
known: current
});
} catch (error) {
// TODO: Add logging here
throw error;
}


}
}

module.exports = new DeletedEmployee('maesn.hibob.employees.DeletedEmployee');

25 changes: 25 additions & 0 deletions src/appmixer/hibob/employees/DeletedEmployee/component.json

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions src/appmixer/hibob/employees/NewEmployee/NewEmployee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict';
const Promise = require('bluebird');


/**
* Process employees to find newly added.
* @param {Set} knownEmployees
* @param {Array} currentEmployees
* @param {Array} newEmployees
* @param {Object} employee
*/
function processEmployees(knownEmployees, currentEmployees, newEmployees, employee) {
const employeeId = employee.id;

if (knownEmployees && !knownEmployees.has(employeeId)) {
newEmployees.push(employee);
}
currentEmployees.push(employeeId);
}

/**
* Component which triggers whenever new employee is added.
*/


class NewEmployee {

async receive(context) {
try {
const auth = 'Basic ' + context.auth.token;
let hibobEndpoint = 'https://api.hibob.com/v1/people/search';
const { data } = await context.httpRequest({
url: hibobEndpoint,
method: 'POST',
headers: {
Authorization: auth
},
data: {
'humanReadable': 'APPEND',
'showInactive': true,
'fields': [
'/root/firstName',
'/root/surname',
'/root/id',
'/root/email',
'/internal/status',
'/work/manager'
]
},
json: true
});
let known = Array.isArray(context.state.known) ? new Set(context.state.known) : new Set();
let current = [];
let diff = [];
if (data.employees) {
data.employees.forEach(processEmployees.bind(null, known, current, diff));
}
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
for (const employee of diff) {
await delay(1000);
await context.sendJson(employee, 'employee');
// TODO: Add logging here
}
await context.saveState({
known: current
});
} catch (error) {
// TODO: Add logging here
throw error;
}
}
}
module.exports = new NewEmployee('maesn.hibob.employees.NewEmployee');
27 changes: 27 additions & 0 deletions src/appmixer/hibob/employees/NewEmployee/component.json

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions src/appmixer/hibob/employees/UpdatedEmployee/UpdatedEmployee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
'use strict';
const Promise = require('bluebird');

/**
* Process employees to find newly updated.
* @param {Array} knownEmployees
* @param {Array} currentEmployees
* @param {Array} updatedEmployees
* @param {Object} employee
*/

function processEmployees(knownEmployees, currentEmployees, updatedEmployees, employee) {
let employeeId = employee.id;
let foundEmployee = knownEmployees.find(emp => emp.id === employeeId);

if (foundEmployee && !isEqual(foundEmployee, employee)) {
updatedEmployees.push(employee);
}
currentEmployees.push(employee);
}


function isEqual(obj1, obj2) {
return JSON.stringify(obj1) === JSON.stringify(obj2);
}

/**
* Component which triggers whenever new employee is updated.
*/

class UpdatedEmployee {

async receive(context) {
try {
const auth = 'Basic ' + context.auth.token;
const { storeId } = context.properties;
const key = 'HiBobEmployeeStorage' + context.flowId;

let hibobEndpoint = 'https://api.hibob.com/v1/people/search';

const { data } = await context.httpRequest({
url: hibobEndpoint,
method: 'POST',
headers: {
Authorization: auth
},
data: {
'humanReadable': 'APPEND',
'showInactive': true,
'fields': [
'/root/firstName',
'/root/surname',
'/root/id',
'/root/email',
'/internal/status',
'/work/manager'
]
},
json: true
});


let storage = await context.store.get(storeId, key);
let known = [];

if (storage && storage.value) {
known = storage.value;
};

let current = [];
let updated = [];

if (data.employees && known) {
data.employees.forEach(processEmployees.bind(null, known, current, updated));
}

await Promise.map(updated, employee => {
return context.sendJson(employee, 'employee');
});


await context.store.set(storeId, key, current);
} catch (error) {
// TODO: Add logging here
throw error;
}
}
}

module.exports = new UpdatedEmployee('maesn.hibob.employees.UpdatedEmployee');
55 changes: 55 additions & 0 deletions src/appmixer/hibob/employees/UpdatedEmployee/component.json

Large diffs are not rendered by default.

Binary file added src/appmixer/hibob/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/appmixer/hibob/package.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file can be removed completely:

  • axios -> context.httpRequest
  • bluebird -> node Promise
  • request-promise - not used

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "maesn.hibob",
"author": "Rovan Talani <[email protected]>",
"version": "1.0.1",
"dependencies": {
"axios": "^0.21.0",
"bluebird": "^3.7.1",
"request-promise": "^4.2.2"
}
}
10 changes: 10 additions & 0 deletions src/appmixer/hibob/service.json

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions src/appmixer/personio/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';
module.exports = {

type: 'pwd',

definition: {
accountNameFromProfileInfo: 'clientId',
auth: {
clientId: {
type: 'text',
name: 'Client Id',
tooltip: 'Client Id'
},
clientSecret: {
type: 'password',
name: 'Client Secret',
tooltip: 'Client Secret'
}
},

validate: async context => {

const { clientId, clientSecret } = context;
const authorizationUrl = 'https://api.personio.de/v1/auth';

const { data } = await context.httpRequest({
url: authorizationUrl,
method: 'POST',
headers: {
'accept': 'application/json',
'content-type': 'application/json'
},
data: {
client_id: clientId,
client_secret: clientSecret
},
json: true
});
if (data.error) {
throw new Error('Invalid username/password combination.');
}

const { token, expiresIn } = data.data;

return {
token: token,
expires: expiresIn,
clientId: clientId,
clientSecret: clientSecret

};
}
}
};
Loading
Loading