-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: dev
Are you sure you want to change the base?
Changes from all commits
eb60c9a
3df13ef
093c9a3
298b108
59dfb3d
005ea13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
}; | ||
} | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,75 @@ | ||||||
'use strict'; | ||||||
const Promise = require('bluebird'); | ||||||
|
||||||
/** | ||||||
* Process employees to find newly deleted. | ||||||
* @param {Array} currentEmployees | ||||||
* @param {Array} deletedEmployees | ||||||
* @param {Object} employeeId | ||||||
*/ | ||||||
|
||||||
|
||||||
Comment on lines
+10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use native |
||||||
|
||||||
await context.saveState({ | ||||||
known: current | ||||||
}); | ||||||
} catch (error) { | ||||||
// TODO: Add logging here | ||||||
throw error; | ||||||
} | ||||||
|
||||||
|
||||||
} | ||||||
} | ||||||
|
||||||
module.exports = new DeletedEmployee('maesn.hibob.employees.DeletedEmployee'); | ||||||
|
Large diffs are not rendered by default.
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'); |
Large diffs are not rendered by default.
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'); |
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file can be removed completely:
|
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" | ||
} | ||
} |
Large diffs are not rendered by default.
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 | ||
|
||
}; | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove
bluebird
dependency.