diff --git a/components/kenjo/actions/create-attendance-entry/create-attendance-entry.mjs b/components/kenjo/actions/create-attendance-entry/create-attendance-entry.mjs new file mode 100644 index 0000000000000..3d646afcfa717 --- /dev/null +++ b/components/kenjo/actions/create-attendance-entry/create-attendance-entry.mjs @@ -0,0 +1,77 @@ +import kenjo from "../../kenjo.app.mjs"; +import { ConfigurationError } from "@pipedream/platform"; + +export default { + key: "kenjo-create-attendance-entry", + name: "Create Attendance Entry", + description: "Creates a new attendance entry for an employee in Kenjo. [See the documentation](https://kenjo.readme.io/reference/post_attendances)", + version: "0.0.1", + type: "action", + props: { + kenjo, + employeeId: { + propDefinition: [ + kenjo, + "employeeId", + ], + }, + date: { + type: "string", + label: "Date", + description: "The date of the entry. Format: `YYYY-MM-DD`", + }, + startTime: { + type: "string", + label: "Start Time", + description: "The start time of the entry. Format: `hh:mm:ss`", + }, + endTime: { + type: "string", + label: "End Time", + description: "The end time of the entry. Format: `hh:mm:ss`", + optional: true, + }, + breakStartTime: { + type: "string", + label: "Break Start Time", + description: "The start time of the break. Format: `hh:mm:ss`", + optional: true, + }, + breakEndTime: { + type: "string", + label: "Break End Time", + description: "The end time of the break. Format: `hh:mm:ss`", + optional: true, + }, + comment: { + type: "string", + label: "Comment", + description: "Comment to describe the attendance record", + optional: true, + }, + }, + async run({ $ }) { + if (this.breakEndTime && !this.breakStartTime) { + throw new ConfigurationError("Break Start Time is required if including a break"); + } + + const response = await this.kenjo.createAttendanceEntry({ + $, + data: { + userId: this.employeeId, + date: this.date, + startTime: this.startTime, + endTime: this.endTime, + breaks: this.breakStartTime && [ + { + start: this.breakStartTime, + end: this.breakEndTime, + }, + ], + comment: this.comment, + }, + }); + $.export("$summary", `Successfully created attendance entry with ID: ${response._id}`); + return response; + }, +}; diff --git a/components/kenjo/actions/create-employee/create-employee.mjs b/components/kenjo/actions/create-employee/create-employee.mjs new file mode 100644 index 0000000000000..316a46fe919b4 --- /dev/null +++ b/components/kenjo/actions/create-employee/create-employee.mjs @@ -0,0 +1,178 @@ +import kenjo from "../../kenjo.app.mjs"; + +export default { + key: "kenjo-create-employee", + name: "Create Employee", + description: "Creates a new employee in Kenjo. [See the documentation](https://kenjo.readme.io/reference/post_employees)", + version: "0.0.1", + type: "action", + props: { + kenjo, + email: { + type: "string", + label: "Email", + description: "The email address of the employee", + }, + firstName: { + type: "string", + label: "First Name", + description: "The first name of the employee", + }, + lastName: { + type: "string", + label: "Last Name", + description: "The last name of the employee", + }, + companyId: { + propDefinition: [ + kenjo, + "companyId", + ], + }, + weeklyHours: { + type: "integer", + label: "Weekly Hours", + description: "The number of weekly hours that an employee works", + }, + officeId: { + propDefinition: [ + kenjo, + "officeId", + (c) => ({ + companyId: c.companyId, + }), + ], + }, + departmentId: { + propDefinition: [ + kenjo, + "departmentId", + ], + }, + language: { + type: "string", + label: "Language", + description: "The employee's language", + options: [ + "en", + "es", + "de", + ], + optional: true, + }, + birthdate: { + type: "string", + label: "Birthdate", + description: "The birthdate of the employee. Format `YYYY-MM-DDThh:mm:ss.000Z`", + optional: true, + }, + jobTitle: { + type: "string", + label: "Job Title", + description: "The job title of the employee", + optional: true, + }, + workPhone: { + type: "string", + label: "Work Phone", + description: "The work phone number of the employee", + optional: true, + }, + personalPhone: { + type: "string", + label: "Personal Phone", + description: "The personal phone number of the employee", + optional: true, + }, + workDays: { + type: "string[]", + label: "Work Days", + description: "The days of the week that the employee works", + options: [ + "monday", + "tuesday", + "wednesday", + "thursday", + "friday", + "saturday", + "sunday", + ], + optional: true, + }, + trackAttendance: { + type: "boolean", + label: "Track Attendance", + description: "Set to `true` to activate attendance tracking for the employee", + optional: true, + }, + street: { + type: "string", + label: "Street", + description: "The street address of the employee", + optional: true, + }, + postalCode: { + type: "string", + label: "Postal Code", + description: "The postal code of the employee", + optional: true, + }, + city: { + type: "string", + label: "City", + description: "The city of the employee", + optional: true, + }, + country: { + type: "string", + label: "Country", + description: "The country code in ISO 3166-1 alpha-2. Example: `ES`", + optional: true, + }, + }, + async run({ $ }) { + const workSchedule = { + trackAttendance: this.trackAttendance, + }; + if (this.workDays?.length) { + for (const day of this.workDays) { + workSchedule[`${day}WorkingDay`] = true; + } + } + + const response = await this.kenjo.createEmployee({ + $, + data: { + account: { + email: this.email, + language: this.language, + }, + personal: { + firstName: this.firstName, + lastName: this.lastName, + birthdate: this.birthdate, + }, + work: { + companyId: this.companyId, + officeId: this.officeId, + departmentId: this.departmentId, + weeklyHours: this.weeklyHours, + jobTitle: this.jobTitle, + workPhone: this.workPhone, + }, + workSchedule, + address: (this.street || this.postalCode || this.city || this.country) && { + street: this.street, + postalCode: this.postalCode, + city: this.city, + country: this.country, + }, + home: this.personalPhone && { + personalPhone: this.personalPhone, + }, + }, + }); + $.export("$summary", `Created employee with ID: ${response.account._id}`); + return response; + }, +}; diff --git a/components/kenjo/actions/create-leave-request/create-leave-request.mjs b/components/kenjo/actions/create-leave-request/create-leave-request.mjs new file mode 100644 index 0000000000000..e6e6bdb7ac43a --- /dev/null +++ b/components/kenjo/actions/create-leave-request/create-leave-request.mjs @@ -0,0 +1,76 @@ +import kenjo from "../../kenjo.app.mjs"; + +export default { + key: "kenjo-create-leave-request", + name: "Create Leave Request", + description: "Creates a new leave request in Kenjo. [See the documentation](https://kenjo.readme.io/reference/post_time-off-requests).", + version: "0.0.1", + type: "action", + props: { + kenjo, + employeeId: { + propDefinition: [ + kenjo, + "employeeId", + ], + }, + timeOffTypeId: { + propDefinition: [ + kenjo, + "timeOffTypeId", + ], + }, + from: { + type: "string", + label: "From", + description: "The starting date of the time-off request in format `YYYY-MM-DD`", + }, + to: { + type: "string", + label: "To", + description: "The ending date of the time-off request in format `YYYY-MM-DD`", + }, + partOfDayFrom: { + type: "string", + label: "Part of Day From", + description: "The duration of the from date. 'StartOfDay' means that the from date is the entire day. 'HalfOfDay' means that the request starts to apply in the middle of the from day. If not specified, the default value will be 'StartOfDay'.", + options: [ + "StartOfDay", + "HalfOfDay", + ], + optional: true, + }, + partOfDayTo: { + type: "string", + label: "Part of Day To", + description: "The duration of the to date. 'EndOfDay' means that the to date is the entire day. 'HalfOfDay' means the request starts to apply in the middle of the to day. If not specified, the default value will be 'EndOfDay'.", + options: [ + "HalfOfDay", + "EndOfDay", + ], + optional: true, + }, + description: { + type: "string", + label: "Description", + description: "The description of the time-off request", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.kenjo.createLeaveRequest({ + $, + data: { + _userId: this.employeeId, + _timeOffTypeId: this.timeOffTypeId, + from: this.from, + to: this.to, + partOfDayFrom: this.partOfDayFrom, + partOfDayTo: this.partOfDayTo, + description: this.description, + }, + }); + $.export("$summary", `Successfully created leave request with ID: ${response._id}`); + return response; + }, +}; diff --git a/components/kenjo/kenjo.app.mjs b/components/kenjo/kenjo.app.mjs index 5fb9fe1d5e69b..ba9af1996d928 100644 --- a/components/kenjo/kenjo.app.mjs +++ b/components/kenjo/kenjo.app.mjs @@ -1,11 +1,154 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "kenjo", - propDefinitions: {}, + propDefinitions: { + employeeId: { + type: "string", + label: "Employee ID", + description: "The identifier of an employee", + async options() { + const { data } = await this.listEmployees(); + return data?.filter(({ isActive }) => isActive)?.map(({ + _id: value, email: label, + }) => ({ + value, + label, + })); + }, + }, + companyId: { + type: "string", + label: "Company ID", + description: "The identifier of a company", + async options() { + const companies = await this.listCompanies(); + return companies?.map(({ + _id: value, name: label, + }) => ({ + value, + label, + })) || []; + }, + }, + timeOffTypeId: { + type: "string", + label: "Time Off Type ID", + description: "The identifier of a time off request type", + async options() { + const { data } = await this.listTimeOffTypes(); + return data?.map(({ + _id: value, name: label, + }) => ({ + value, + label, + })) || []; + }, + }, + officeId: { + type: "string", + label: "Office ID", + description: "The identifier of an office", + optional: true, + async options({ companyId }) { + const offices = await this.listOffices({ + params: { + companyId, + }, + }); + return offices?.map(({ + _id: value, name: label, + }) => ({ + value, + label, + })) || []; + }, + }, + departmentId: { + type: "string", + label: "Department ID", + description: "The identifier of a department", + optional: true, + async options() { + const departments = await this.listDepartments(); + return departments?.map(({ + _id: value, name: label, + }) => ({ + value, + label, + })) || []; + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return this.$auth.api_url; + }, + _makeRequest({ + $ = this, + path, + ...otherOpts + }) { + return axios($, { + ...otherOpts, + url: `${this._baseUrl()}${path}`, + headers: { + Authorization: `${this.$auth.oauth_access_token}`, + Accept: "application/json", + }, + }); + }, + listCompanies(opts = {}) { + return this._makeRequest({ + path: "/companies", + ...opts, + }); + }, + listOffices(opts = {}) { + return this._makeRequest({ + path: "/offices", + ...opts, + }); + }, + listDepartments(opts = {}) { + return this._makeRequest({ + path: "/departments", + ...opts, + }); + }, + listEmployees(opts = {}) { + return this._makeRequest({ + path: "/employees", + ...opts, + }); + }, + listTimeOffTypes(opts = {}) { + return this._makeRequest({ + path: "/time-off/types", + ...opts, + }); + }, + createEmployee(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/employees", + ...opts, + }); + }, + createLeaveRequest(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/time-off/requests", + ...opts, + }); + }, + createAttendanceEntry(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/attendances", + ...opts, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/kenjo/package.json b/components/kenjo/package.json index 03d6237a93e34..fe2b6b1d667c5 100644 --- a/components/kenjo/package.json +++ b/components/kenjo/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/kenjo", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Kenjo Components", "main": "kenjo.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/components/kenjo/sources/common/base.mjs b/components/kenjo/sources/common/base.mjs new file mode 100644 index 0000000000000..2adcc01a56863 --- /dev/null +++ b/components/kenjo/sources/common/base.mjs @@ -0,0 +1,40 @@ +import kenjo from "../../kenjo.app.mjs"; +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; + +export default { + props: { + kenjo, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + }, + methods: { + getResourceKey() { + return; + }, + getResourceFn() { + throw new Error("getResourceFn is not implemented"); + }, + generateMeta() { + throw new Error("generateMeta is not implemented"); + }, + }, + async run() { + const resourceFn = this.getResourceFn(); + const resourceKey = this.getResourceKey(); + + const results = await resourceFn(); + const items = resourceKey + ? results[resourceKey] + : results; + + for (const item of items) { + const meta = this.generateMeta(item); + this.$emit(item, meta); + } + }, +}; diff --git a/components/kenjo/sources/new-company-created/new-company-created.mjs b/components/kenjo/sources/new-company-created/new-company-created.mjs new file mode 100644 index 0000000000000..af14be69af8d4 --- /dev/null +++ b/components/kenjo/sources/new-company-created/new-company-created.mjs @@ -0,0 +1,24 @@ +import common from "../common/base.mjs"; + +export default { + ...common, + key: "kenjo-new-company-created", + name: "New Company Created", + description: "Emit new event when a new company is created in Kenjo. [See the documentation](https://kenjo.readme.io/reference/get_companies)", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getResourceFn() { + return this.kenjo.listCompanies; + }, + generateMeta(company) { + return { + id: company._id, + summary: `New Company: ${company.name}`, + ts: Date.now(), + }; + }, + }, +}; diff --git a/components/kenjo/sources/new-employee-created/new-employee-created.mjs b/components/kenjo/sources/new-employee-created/new-employee-created.mjs new file mode 100644 index 0000000000000..230c2b932a9dd --- /dev/null +++ b/components/kenjo/sources/new-employee-created/new-employee-created.mjs @@ -0,0 +1,27 @@ +import common from "../common/base.mjs"; + +export default { + ...common, + key: "kenjo-new-employee-created", + name: "New Employee Created", + description: "Emit new event when a new employee is added in Kenjo. [See the documentation](https://kenjo.readme.io/reference/get_employees)", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getResourceFn() { + return this.kenjo.listEmployees; + }, + getResourceKey() { + return "data"; + }, + generateMeta(employee) { + return { + id: employee._id, + summary: `New Employee: ${employee.email}`, + ts: Date.now(), + }; + }, + }, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f397324c0497a..826a6edb637e9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1334,8 +1334,7 @@ importers: components/braze: {} - components/breathe: - specifiers: {} + components/breathe: {} components/brevo: dependencies: @@ -5429,7 +5428,11 @@ importers: components/keen_io: {} - components/kenjo: {} + components/kenjo: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/key_app_demo_1: {}