From 82acf192d608f3d8c8452ae6ad2d48c304e05911 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Thu, 26 Dec 2024 16:05:33 -0500 Subject: [PATCH 1/3] kenjo init --- .../create-employee/create-employee.mjs | 47 +++ .../generate-payslip/generate-payslip.mjs | 46 +++ .../update-leave-request.mjs | 46 +++ components/kenjo/kenjo.app.mjs | 339 +++++++++++++++++- components/kenjo/package.json | 2 +- .../new-employee-instant.mjs | 127 +++++++ .../new-performance-review-instant.mjs | 86 +++++ .../updated-leave-request-instant.mjs | 116 ++++++ 8 files changed, 803 insertions(+), 6 deletions(-) create mode 100644 components/kenjo/actions/create-employee/create-employee.mjs create mode 100644 components/kenjo/actions/generate-payslip/generate-payslip.mjs create mode 100644 components/kenjo/actions/update-leave-request/update-leave-request.mjs create mode 100644 components/kenjo/sources/new-employee-instant/new-employee-instant.mjs create mode 100644 components/kenjo/sources/new-performance-review-instant/new-performance-review-instant.mjs create mode 100644 components/kenjo/sources/updated-leave-request-instant/updated-leave-request-instant.mjs 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..3997f8c3c3a4d --- /dev/null +++ b/components/kenjo/actions/create-employee/create-employee.mjs @@ -0,0 +1,47 @@ +import kenjo from "../../kenjo.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "kenjo-create-employee", + name: "Create Employee", + description: "Creates a new employee in Kenjo. [See the documentation]()", + version: "0.0.{{ts}}", + type: "action", + props: { + kenjo, + createEmployeeName: { + propDefinition: [ + kenjo, + "createEmployeeName", + ], + }, + createEmployeeEmail: { + propDefinition: [ + kenjo, + "createEmployeeEmail", + ], + }, + createEmployeeDepartment: { + propDefinition: [ + kenjo, + "createEmployeeDepartment", + ], + }, + createEmployeeRole: { + propDefinition: [ + kenjo, + "createEmployeeRole", + ], + }, + }, + async run({ $ }) { + const response = await this.kenjo.createEmployee({ + name: this.createEmployeeName, + email: this.createEmployeeEmail, + department_id: this.createEmployeeDepartment, + role_id: this.createEmployeeRole, + }); + $.export("$summary", `Created employee ${response.name}`); + return response; + }, +}; diff --git a/components/kenjo/actions/generate-payslip/generate-payslip.mjs b/components/kenjo/actions/generate-payslip/generate-payslip.mjs new file mode 100644 index 0000000000000..e5e48f0a4ec7b --- /dev/null +++ b/components/kenjo/actions/generate-payslip/generate-payslip.mjs @@ -0,0 +1,46 @@ +import kenjo from "../../kenjo.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "kenjo-generate-payslip", + name: "Generate Payslip", + description: "Generates a payslip for a specific employee. [See the documentation]()", + version: "0.0.{{ts}}", + type: "action", + props: { + kenjo, + generatePayslipEmployeeId: { + propDefinition: [ + kenjo, + "generatePayslipEmployeeId", + ], + }, + generatePayPeriodStart: { + propDefinition: [ + kenjo, + "generatePayPeriodStart", + ], + }, + generatePayPeriodEnd: { + propDefinition: [ + kenjo, + "generatePayPeriodEnd", + ], + }, + generateCustomNotes: { + propDefinition: [ + kenjo, + "generateCustomNotes", + ], + optional: true, + }, + }, + async run({ $ }) { + const response = await this.kenjo.generatePayslip(); + $.export( + "$summary", + `Generated payslip for employee ${this.generatePayslipEmployeeId} for period ${this.generatePayPeriodStart} to ${this.generatePayPeriodEnd}`, + ); + return response; + }, +}; diff --git a/components/kenjo/actions/update-leave-request/update-leave-request.mjs b/components/kenjo/actions/update-leave-request/update-leave-request.mjs new file mode 100644 index 0000000000000..927a8d9194db9 --- /dev/null +++ b/components/kenjo/actions/update-leave-request/update-leave-request.mjs @@ -0,0 +1,46 @@ +import kenjo from "../../kenjo.app.mjs"; + +export default { + key: "kenjo-update-leave-request", + name: "Update Leave Request", + description: "Updates an existing leave request in Kenjo. [See the documentation]().", + version: "0.0.{{ts}}", + type: "action", + props: { + kenjo, + updateLeaveRequestId: { + propDefinition: [ + kenjo, + "updateLeaveRequestId", + ], + }, + updateLeaveStatus: { + propDefinition: [ + kenjo, + "updateLeaveStatus", + ], + }, + updateLeaveStartDate: { + propDefinition: [ + kenjo, + "updateLeaveStartDate", + ], + }, + updateLeaveEndDate: { + propDefinition: [ + kenjo, + "updateLeaveEndDate", + ], + }, + }, + async run({ $ }) { + const response = await this.kenjo.updateLeaveRequest({ + leaveRequestId: this.updateLeaveRequestId, + status: this.updateLeaveStatus, + startDate: this.updateLeaveStartDate, + endDate: this.updateLeaveEndDate, + }); + $.export("$summary", `Updated leave request with ID ${this.updateLeaveRequestId}`); + return response; + }, +}; diff --git a/components/kenjo/kenjo.app.mjs b/components/kenjo/kenjo.app.mjs index 5fb9fe1d5e69b..da3a0f4e0ff50 100644 --- a/components/kenjo/kenjo.app.mjs +++ b/components/kenjo/kenjo.app.mjs @@ -1,11 +1,340 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "kenjo", - propDefinitions: {}, + version: "0.0.{{ts}}", + propDefinitions: { + // Props for emitting new employee added + emitNewEmployee: { + type: "$.interface.timer", + label: "Emit New Employee Event", + description: "Emit an event when a new employee is added", + }, + filterDepartment: { + type: "string", + label: "Filter by Department", + description: "Filter events by department", + optional: true, + async options() { + const departments = await this.paginate(this.getDepartments); + return departments.map((dept) => ({ + label: dept.name, + value: dept.id, + })); + }, + }, + filterRole: { + type: "string", + label: "Filter by Role", + description: "Filter events by role", + optional: true, + async options() { + const roles = await this.paginate(this.getRoles); + return roles.map((role) => ({ + label: role.name, + value: role.id, + })); + }, + }, + // Props for emitting updated leave request + emitUpdatedLeaveRequest: { + type: "$.interface.timer", + label: "Emit Updated Leave Request Event", + description: "Emit an event when a leave request is updated", + }, + filterEmployeeId: { + type: "string", + label: "Filter by Employee ID", + description: "Filter events by employee ID", + optional: true, + async options() { + const employees = await this.paginate(this.listEmployees); + return employees.map((emp) => ({ + label: emp.name, + value: emp.id, + })); + }, + }, + filterStatus: { + type: "string", + label: "Filter by Status", + description: "Filter events by status", + optional: true, + async options() { + const statuses = await this.paginate(this.getLeaveStatuses); + return statuses.map((status) => ({ + label: status.name, + value: status.id, + })); + }, + }, + // Props for emitting new performance review + emitNewPerformanceReview: { + type: "$.interface.timer", + label: "Emit New Performance Review Event", + description: "Emit an event when a new performance review is created", + }, + filterReviewType: { + type: "string", + label: "Filter by Review Type", + description: "Filter events by review type", + optional: true, + async options() { + const reviewTypes = await this.paginate(this.getReviewTypes); + return reviewTypes.map((type) => ({ + label: type.name, + value: type.id, + })); + }, + }, + filterReviewEmployee: { + type: "string", + label: "Filter by Employee for Review", + description: "Filter performance reviews by employee", + optional: true, + async options() { + const employees = await this.paginate(this.listEmployees); + return employees.map((emp) => ({ + label: emp.name, + value: emp.id, + })); + }, + }, + // Props for creating a new employee + createEmployeeName: { + type: "string", + label: "Name", + description: "The full name of the employee", + }, + createEmployeeEmail: { + type: "string", + label: "Email", + description: "The email address of the employee", + }, + createEmployeeDepartment: { + type: "string", + label: "Department", + description: "The department of the employee", + async options() { + const departments = await this.paginate(this.getDepartments); + return departments.map((dept) => ({ + label: dept.name, + value: dept.id, + })); + }, + }, + createEmployeeRole: { + type: "string", + label: "Role", + description: "The role of the employee", + async options() { + const roles = await this.paginate(this.getRoles); + return roles.map((role) => ({ + label: role.name, + value: role.id, + })); + }, + }, + // Props for updating an existing leave request + updateLeaveRequestId: { + type: "string", + label: "Leave Request ID", + description: "The ID of the leave request to update", + }, + updateLeaveStatus: { + type: "string", + label: "Leave Status", + description: "The new status of the leave request", + async options() { + const statuses = await this.paginate(this.getLeaveStatuses); + return statuses.map((status) => ({ + label: status.name, + value: status.id, + })); + }, + }, + updateLeaveStartDate: { + type: "string", + label: "Leave Start Date", + description: "The new start date of the leave request (YYYY-MM-DD)", + }, + updateLeaveEndDate: { + type: "string", + label: "Leave End Date", + description: "The new end date of the leave request (YYYY-MM-DD)", + }, + // Props for generating a payslip + generatePayslipEmployeeId: { + type: "string", + label: "Employee ID", + description: "The ID of the employee", + async options() { + const employees = await this.paginate(this.listEmployees); + return employees.map((emp) => ({ + label: emp.name, + value: emp.id, + })); + }, + }, + generatePayPeriodStart: { + type: "string", + label: "Pay Period Start Date", + description: "The start date of the pay period (YYYY-MM-DD)", + }, + generatePayPeriodEnd: { + type: "string", + label: "Pay Period End Date", + description: "The end date of the pay period (YYYY-MM-DD)", + }, + generateCustomNotes: { + type: "string", + label: "Custom Notes", + description: "Optional custom notes to include in the payslip", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.kenjo.io/v1"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + method = "GET", + path = "/", + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + method, + url: this._baseUrl() + path, + headers: { + ...headers, + "Authorization": `Bearer ${this.$auth.api_key}`, + "Content-Type": "application/json", + }, + }); + }, + async paginate(fn, opts = {}, results = []) { + const response = await fn(opts); + if (Array.isArray(response)) { + results.push(...response); + return results; + } + if (response.items && response.items.length > 0) { + results.push(...response.items); + if (response.nextPage) { + return this.paginate(fn, { + ...opts, + page: response.nextPage, + }, results); + } + } + return results; + }, + // Methods for emitting new employee added + async getDepartments(opts = {}) { + return this._makeRequest({ + path: "/departments", + ...opts, + }); + }, + async getRoles(opts = {}) { + return this._makeRequest({ + path: "/roles", + ...opts, + }); + }, + // Methods for emitting updated leave request + async getLeaveStatuses(opts = {}) { + return this._makeRequest({ + path: "/time-off-statuses", + ...opts, + }); + }, + // Methods for emitting new performance review + async getReviewTypes(opts = {}) { + return this._makeRequest({ + path: "/performance-review-types", + ...opts, + }); + }, + async listEmployees(opts = {}) { + return this._makeRequest({ + path: "/employees", + ...opts, + }); + }, + // Action: Create a new employee + async createEmployee({ + name, email, department, role, ...opts + }) { + return this._makeRequest({ + method: "POST", + path: "/employees", + data: { + name: this.createEmployeeName, + email: this.createEmployeeEmail, + department_id: this.createEmployeeDepartment, + role_id: this.createEmployeeRole, + }, + ...opts, + }); + }, + // Action: Update an existing leave request + async updateLeaveRequest({ + leaveRequestId, status, startDate, endDate, ...opts + }) { + return this._makeRequest({ + method: "PUT", + path: `/time-off-requests/${this.updateLeaveRequestId}`, + data: { + status: this.updateLeaveStatus, + start_date: this.updateLeaveStartDate, + end_date: this.updateLeaveEndDate, + }, + ...opts, + }); + }, + // Action: Generate a payslip + async generatePayslip({ + employeeId, payPeriodStart, payPeriodEnd, customNotes, ...opts + }) { + const data = { + employee_id: this.generatePayslipEmployeeId, + pay_period_start: this.generatePayPeriodStart, + pay_period_end: this.generatePayPeriodEnd, + }; + if (this.generateCustomNotes) { + data.custom_notes = this.generateCustomNotes; + } + return this._makeRequest({ + method: "POST", + path: "/payslips", + data, + ...opts, + }); + }, + // Methods for emitting events + async emitEmployeeAddedEvent() { + const newEmployees = await this.listEmployees(); + // Logic to detect new employees + // This is a placeholder; actual implementation may vary + return newEmployees; + }, + async emitLeaveRequestUpdatedEvent() { + const updatedLeaveRequests = await this._makeRequest({ + path: "/leave-requests/updated", + }); + return updatedLeaveRequests; + }, + async emitPerformanceReviewCreatedEvent() { + const newPerformanceReviews = await this._makeRequest({ + path: "/performance-reviews/new", + }); + return newPerformanceReviews; }, }, -}; \ No newline at end of file +}; diff --git a/components/kenjo/package.json b/components/kenjo/package.json index 03d6237a93e34..f87f8e64c80e8 100644 --- a/components/kenjo/package.json +++ b/components/kenjo/package.json @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/components/kenjo/sources/new-employee-instant/new-employee-instant.mjs b/components/kenjo/sources/new-employee-instant/new-employee-instant.mjs new file mode 100644 index 0000000000000..6d4255fb9be09 --- /dev/null +++ b/components/kenjo/sources/new-employee-instant/new-employee-instant.mjs @@ -0,0 +1,127 @@ +import kenjo from "../../kenjo.app.mjs"; +import { axios } from "@pipedream/platform"; +import crypto from "crypto"; + +export default { + key: "kenjo-new-employee-instant", + name: "New Employee Added", + description: "Emit a new event when a new employee is added in Kenjo. Useful for syncing employee data with other systems. [See the documentation]()", + version: "0.0.{{ts}}", + type: "source", + dedupe: "unique", + props: { + kenjo: { + type: "app", + app: "kenjo", + }, + filterDepartment: { + propDefinition: [ + kenjo, + "filterDepartment", + ], + }, + filterRole: { + propDefinition: [ + kenjo, + "filterRole", + ], + }, + db: "$.service.db", + http: { + type: "$.interface.http", + customResponse: true, + }, + }, + hooks: { + async activate() { + const callbackUrl = this.http.endpoint; + const secret = crypto.randomBytes(32).toString("hex"); + const response = await this.kenjo._makeRequest({ + method: "POST", + path: "/webhooks", + data: { + event: "employee.created", + callback_url: callbackUrl, + signature_secret: secret, + }, + }); + await this.db.set("webhookId", response.id); + await this.db.set("webhookSecret", secret); + }, + async deactivate() { + const webhookId = await this.db.get("webhookId"); + if (webhookId) { + await this.kenjo._makeRequest({ + method: "DELETE", + path: `/webhooks/${webhookId}`, + }); + await this.db.set("webhookId", null); + await this.db.set("webhookSecret", null); + } + }, + async deploy() { + const filters = {}; + if (this.filterDepartment) { + filters.department_id = this.filterDepartment; + } + if (this.filterRole) { + filters.role_id = this.filterRole; + } + const employees = await this.kenjo.paginate(this.kenjo.listEmployees, { + params: filters, + paginate: true, + max: 50, + }); + for (const employee of employees) { + this.$emit(employee, { + id: employee.id.toString(), + summary: `New employee added: ${employee.name}`, + ts: Date.parse(employee.created_at) || Date.now(), + }); + } + }, + }, + async run(event) { + const signature = event.headers["x-kenjo-signature"]; + const body = JSON.stringify(event.body); + const secret = await this.db.get("webhookSecret"); + const computedSignature = crypto.createHmac("sha256", secret).update(body) + .digest("hex"); + if (signature !== computedSignature) { + this.http.respond({ + status: 401, + body: "Unauthorized", + }); + return; + } + + const employee = event.body; + + if (this.filterDepartment && employee.department_id !== this.filterDepartment) { + this.http.respond({ + status: 200, + body: "OK", + }); + return; + } + + if (this.filterRole && employee.role_id !== this.filterRole) { + this.http.respond({ + status: 200, + body: "OK", + }); + return; + } + + this.$emit(employee, { + id: employee.id.toString(), + summary: `New employee added: ${employee.name}`, + ts: Date.parse(employee.created_at) || Date.now(), + }); + + this.http.respond({ + status: 200, + body: "OK", + }); + }, +}; diff --git a/components/kenjo/sources/new-performance-review-instant/new-performance-review-instant.mjs b/components/kenjo/sources/new-performance-review-instant/new-performance-review-instant.mjs new file mode 100644 index 0000000000000..d0d9d33f5f8d6 --- /dev/null +++ b/components/kenjo/sources/new-performance-review-instant/new-performance-review-instant.mjs @@ -0,0 +1,86 @@ +import kenjo from "../../kenjo.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "kenjo-new-performance-review-instant", + name: "New Performance Review Created", + description: "Emit a new event when a performance review is created. [See the documentation]()]", + version: "0.0.{{ts}}", + type: "source", + dedupe: "unique", + props: { + kenjo: { + type: "app", + app: "kenjo", + }, + emitNewPerformanceReview: { + propDefinition: [ + "kenjo", + "emitNewPerformanceReview", + ], + }, + filterReviewType: { + propDefinition: [ + "kenjo", + "filterReviewType", + ], + }, + filterReviewEmployee: { + propDefinition: [ + "kenjo", + "filterReviewEmployee", + ], + }, + db: "$.service.db", + }, + methods: { + _getLastReviewId() { + return this.db.get("lastReviewId") || null; + }, + _setLastReviewId(id) { + return this.db.set("lastReviewId", id); + }, + _generateId(review) { + return `${review.employeeId}-${new Date(review.createdAt).getTime()}`; + }, + }, + hooks: { + async deploy() { + const reviews = await this.kenjo.emitNewPerformanceReview(); + reviews.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt)); + for (const review of reviews) { + const id = review.id || this._generateId(review); + const summary = `New performance review created for ${review.employeeName}`; + const ts = Date.parse(review.createdAt) || Date.now(); + this.$emit(review, { + id, + summary, + ts, + }); + if (!this._getLastReviewId() || review.id > this._getLastReviewId()) { + this._setLastReviewId(review.id); + } + } + }, + }, + async run() { + const lastId = this._getLastReviewId(); + const reviews = await this.kenjo.emitNewPerformanceReview(); + reviews.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt)); + for (const review of reviews) { + if (!lastId || review.id > lastId) { + const id = review.id || this._generateId(review); + const summary = `New performance review created for ${review.employeeName}`; + const ts = Date.parse(review.createdAt) || Date.now(); + this.$emit(review, { + id, + summary, + ts, + }); + if (!lastId || review.id > lastId) { + this._setLastReviewId(review.id); + } + } + } + }, +}; diff --git a/components/kenjo/sources/updated-leave-request-instant/updated-leave-request-instant.mjs b/components/kenjo/sources/updated-leave-request-instant/updated-leave-request-instant.mjs new file mode 100644 index 0000000000000..6b31f4c5fab20 --- /dev/null +++ b/components/kenjo/sources/updated-leave-request-instant/updated-leave-request-instant.mjs @@ -0,0 +1,116 @@ +import kenjo from "../../kenjo.app.mjs"; +import crypto from "crypto"; +import { axios } from "@pipedream/platform"; + +export default { + key: "kenjo-updated-leave-request-instant", + name: "Updated Leave Request (Instant)", + description: "Emit a new event when an existing leave request is updated (e.g., approved, rejected, or modified). [See the documentation]().", + version: "0.0.{{ts}}", + type: "source", + dedupe: "unique", + props: { + kenjo, + db: "$.service.db", + http: { + type: "$.interface.http", + customResponse: true, + }, + filterEmployeeId: { + propDefinition: [ + "kenjo", + "filterEmployeeId", + ], + optional: true, + }, + filterStatus: { + propDefinition: [ + "kenjo", + "filterStatus", + ], + optional: true, + }, + }, + hooks: { + async deploy() { + const updatedLeaveRequests = await this.kenjo.emitLeaveRequestUpdatedEvent(); + const last50 = updatedLeaveRequests.slice(-50).reverse(); + for (const leaveRequest of last50) { + if ( + (this.filterEmployeeId && leaveRequest.employee_id !== this.filterEmployeeId) || + (this.filterStatus && leaveRequest.status_id !== this.filterStatus) + ) { + continue; + } + this.$emit(leaveRequest, { + id: leaveRequest.id || `${leaveRequest.updated_at}`, + summary: `Leave request ${leaveRequest.id} updated`, + ts: Date.parse(leaveRequest.updated_at) || Date.now(), + }); + } + }, + async activate() { + const response = await this.kenjo._makeRequest({ + method: "POST", + path: "/webhooks", + data: { + event: "leave_request_updated", + callback_url: this.http.endpoint, + }, + }); + const webhookId = response.id; + this.db.set("webhookId", webhookId); + }, + async deactivate() { + const webhookId = await this.db.get("webhookId"); + if (webhookId) { + await this.kenjo._makeRequest({ + method: "DELETE", + path: `/webhooks/${webhookId}`, + }); + this.db.delete("webhookId"); + } + }, + }, + async run(event) { + const signature = event.headers["x-kenjo-signature"]; + const secret = this.kenjo.$auth.api_key; + const rawBody = event.rawBody; + const computedSignature = crypto.createHmac("sha256", secret).update(rawBody) + .digest("hex"); + if (computedSignature !== signature) { + this.http.respond({ + status: 401, + body: "Unauthorized", + }); + return; + } + const data = event.body; + if (this.filterEmployeeId && data.employee_id !== this.filterEmployeeId) { + this.http.respond({ + status: 200, + body: "OK", + }); + return; + } + if (this.filterStatus && data.status_id !== this.filterStatus) { + this.http.respond({ + status: 200, + body: "OK", + }); + return; + } + const id = data.id || `${Date.now()}`; + const summary = `Leave request ${data.id} updated`; + const ts = Date.parse(data.updated_at) || Date.now(); + this.$emit(data, { + id, + summary, + ts, + }); + this.http.respond({ + status: 200, + body: "OK", + }); + }, +}; From 4ca63c2c7c9eee2213433e933ebefd7023d4f6c6 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 27 Dec 2024 13:27:22 -0500 Subject: [PATCH 2/3] new components --- .../create-attendance-entry.mjs | 77 ++++ .../create-employee/create-employee.mjs | 167 ++++++++- .../create-leave-request.mjs | 76 ++++ .../generate-payslip/generate-payslip.mjs | 46 --- .../update-leave-request.mjs | 46 --- components/kenjo/kenjo.app.mjs | 344 ++++-------------- components/kenjo/package.json | 5 +- components/kenjo/sources/common/base.mjs | 40 ++ .../new-company-created.mjs | 24 ++ .../new-employee-created.mjs | 27 ++ .../new-employee-instant.mjs | 127 ------- .../new-performance-review-instant.mjs | 86 ----- .../updated-leave-request-instant.mjs | 116 ------ 13 files changed, 476 insertions(+), 705 deletions(-) create mode 100644 components/kenjo/actions/create-attendance-entry/create-attendance-entry.mjs create mode 100644 components/kenjo/actions/create-leave-request/create-leave-request.mjs delete mode 100644 components/kenjo/actions/generate-payslip/generate-payslip.mjs delete mode 100644 components/kenjo/actions/update-leave-request/update-leave-request.mjs create mode 100644 components/kenjo/sources/common/base.mjs create mode 100644 components/kenjo/sources/new-company-created/new-company-created.mjs create mode 100644 components/kenjo/sources/new-employee-created/new-employee-created.mjs delete mode 100644 components/kenjo/sources/new-employee-instant/new-employee-instant.mjs delete mode 100644 components/kenjo/sources/new-performance-review-instant/new-performance-review-instant.mjs delete mode 100644 components/kenjo/sources/updated-leave-request-instant/updated-leave-request-instant.mjs 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 index 3997f8c3c3a4d..316a46fe919b4 100644 --- a/components/kenjo/actions/create-employee/create-employee.mjs +++ b/components/kenjo/actions/create-employee/create-employee.mjs @@ -1,47 +1,178 @@ import kenjo from "../../kenjo.app.mjs"; -import { axios } from "@pipedream/platform"; export default { key: "kenjo-create-employee", name: "Create Employee", - description: "Creates a new employee in Kenjo. [See the documentation]()", - version: "0.0.{{ts}}", + 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, - createEmployeeName: { + 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, - "createEmployeeName", + "companyId", ], }, - createEmployeeEmail: { + weeklyHours: { + type: "integer", + label: "Weekly Hours", + description: "The number of weekly hours that an employee works", + }, + officeId: { propDefinition: [ kenjo, - "createEmployeeEmail", + "officeId", + (c) => ({ + companyId: c.companyId, + }), ], }, - createEmployeeDepartment: { + departmentId: { propDefinition: [ kenjo, - "createEmployeeDepartment", + "departmentId", ], }, - createEmployeeRole: { - propDefinition: [ - kenjo, - "createEmployeeRole", + 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({ - name: this.createEmployeeName, - email: this.createEmployeeEmail, - department_id: this.createEmployeeDepartment, - role_id: this.createEmployeeRole, + $, + 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 ${response.name}`); + $.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/actions/generate-payslip/generate-payslip.mjs b/components/kenjo/actions/generate-payslip/generate-payslip.mjs deleted file mode 100644 index e5e48f0a4ec7b..0000000000000 --- a/components/kenjo/actions/generate-payslip/generate-payslip.mjs +++ /dev/null @@ -1,46 +0,0 @@ -import kenjo from "../../kenjo.app.mjs"; -import { axios } from "@pipedream/platform"; - -export default { - key: "kenjo-generate-payslip", - name: "Generate Payslip", - description: "Generates a payslip for a specific employee. [See the documentation]()", - version: "0.0.{{ts}}", - type: "action", - props: { - kenjo, - generatePayslipEmployeeId: { - propDefinition: [ - kenjo, - "generatePayslipEmployeeId", - ], - }, - generatePayPeriodStart: { - propDefinition: [ - kenjo, - "generatePayPeriodStart", - ], - }, - generatePayPeriodEnd: { - propDefinition: [ - kenjo, - "generatePayPeriodEnd", - ], - }, - generateCustomNotes: { - propDefinition: [ - kenjo, - "generateCustomNotes", - ], - optional: true, - }, - }, - async run({ $ }) { - const response = await this.kenjo.generatePayslip(); - $.export( - "$summary", - `Generated payslip for employee ${this.generatePayslipEmployeeId} for period ${this.generatePayPeriodStart} to ${this.generatePayPeriodEnd}`, - ); - return response; - }, -}; diff --git a/components/kenjo/actions/update-leave-request/update-leave-request.mjs b/components/kenjo/actions/update-leave-request/update-leave-request.mjs deleted file mode 100644 index 927a8d9194db9..0000000000000 --- a/components/kenjo/actions/update-leave-request/update-leave-request.mjs +++ /dev/null @@ -1,46 +0,0 @@ -import kenjo from "../../kenjo.app.mjs"; - -export default { - key: "kenjo-update-leave-request", - name: "Update Leave Request", - description: "Updates an existing leave request in Kenjo. [See the documentation]().", - version: "0.0.{{ts}}", - type: "action", - props: { - kenjo, - updateLeaveRequestId: { - propDefinition: [ - kenjo, - "updateLeaveRequestId", - ], - }, - updateLeaveStatus: { - propDefinition: [ - kenjo, - "updateLeaveStatus", - ], - }, - updateLeaveStartDate: { - propDefinition: [ - kenjo, - "updateLeaveStartDate", - ], - }, - updateLeaveEndDate: { - propDefinition: [ - kenjo, - "updateLeaveEndDate", - ], - }, - }, - async run({ $ }) { - const response = await this.kenjo.updateLeaveRequest({ - leaveRequestId: this.updateLeaveRequestId, - status: this.updateLeaveStatus, - startDate: this.updateLeaveStartDate, - endDate: this.updateLeaveEndDate, - }); - $.export("$summary", `Updated leave request with ID ${this.updateLeaveRequestId}`); - return response; - }, -}; diff --git a/components/kenjo/kenjo.app.mjs b/components/kenjo/kenjo.app.mjs index da3a0f4e0ff50..ba9af1996d928 100644 --- a/components/kenjo/kenjo.app.mjs +++ b/components/kenjo/kenjo.app.mjs @@ -3,338 +3,152 @@ import { axios } from "@pipedream/platform"; export default { type: "app", app: "kenjo", - version: "0.0.{{ts}}", propDefinitions: { - // Props for emitting new employee added - emitNewEmployee: { - type: "$.interface.timer", - label: "Emit New Employee Event", - description: "Emit an event when a new employee is added", - }, - filterDepartment: { + employeeId: { type: "string", - label: "Filter by Department", - description: "Filter events by department", - optional: true, + label: "Employee ID", + description: "The identifier of an employee", async options() { - const departments = await this.paginate(this.getDepartments); - return departments.map((dept) => ({ - label: dept.name, - value: dept.id, + const { data } = await this.listEmployees(); + return data?.filter(({ isActive }) => isActive)?.map(({ + _id: value, email: label, + }) => ({ + value, + label, })); }, }, - filterRole: { + companyId: { type: "string", - label: "Filter by Role", - description: "Filter events by role", - optional: true, + label: "Company ID", + description: "The identifier of a company", async options() { - const roles = await this.paginate(this.getRoles); - return roles.map((role) => ({ - label: role.name, - value: role.id, - })); + const companies = await this.listCompanies(); + return companies?.map(({ + _id: value, name: label, + }) => ({ + value, + label, + })) || []; }, }, - // Props for emitting updated leave request - emitUpdatedLeaveRequest: { - type: "$.interface.timer", - label: "Emit Updated Leave Request Event", - description: "Emit an event when a leave request is updated", - }, - filterEmployeeId: { + timeOffTypeId: { type: "string", - label: "Filter by Employee ID", - description: "Filter events by employee ID", - optional: true, + label: "Time Off Type ID", + description: "The identifier of a time off request type", async options() { - const employees = await this.paginate(this.listEmployees); - return employees.map((emp) => ({ - label: emp.name, - value: emp.id, - })); + const { data } = await this.listTimeOffTypes(); + return data?.map(({ + _id: value, name: label, + }) => ({ + value, + label, + })) || []; }, }, - filterStatus: { + officeId: { type: "string", - label: "Filter by Status", - description: "Filter events by status", + label: "Office ID", + description: "The identifier of an office", optional: true, - async options() { - const statuses = await this.paginate(this.getLeaveStatuses); - return statuses.map((status) => ({ - label: status.name, - value: status.id, - })); + async options({ companyId }) { + const offices = await this.listOffices({ + params: { + companyId, + }, + }); + return offices?.map(({ + _id: value, name: label, + }) => ({ + value, + label, + })) || []; }, }, - // Props for emitting new performance review - emitNewPerformanceReview: { - type: "$.interface.timer", - label: "Emit New Performance Review Event", - description: "Emit an event when a new performance review is created", - }, - filterReviewType: { + departmentId: { type: "string", - label: "Filter by Review Type", - description: "Filter events by review type", + label: "Department ID", + description: "The identifier of a department", optional: true, async options() { - const reviewTypes = await this.paginate(this.getReviewTypes); - return reviewTypes.map((type) => ({ - label: type.name, - value: type.id, - })); + const departments = await this.listDepartments(); + return departments?.map(({ + _id: value, name: label, + }) => ({ + value, + label, + })) || []; }, }, - filterReviewEmployee: { - type: "string", - label: "Filter by Employee for Review", - description: "Filter performance reviews by employee", - optional: true, - async options() { - const employees = await this.paginate(this.listEmployees); - return employees.map((emp) => ({ - label: emp.name, - value: emp.id, - })); - }, - }, - // Props for creating a new employee - createEmployeeName: { - type: "string", - label: "Name", - description: "The full name of the employee", - }, - createEmployeeEmail: { - type: "string", - label: "Email", - description: "The email address of the employee", - }, - createEmployeeDepartment: { - type: "string", - label: "Department", - description: "The department of the employee", - async options() { - const departments = await this.paginate(this.getDepartments); - return departments.map((dept) => ({ - label: dept.name, - value: dept.id, - })); - }, - }, - createEmployeeRole: { - type: "string", - label: "Role", - description: "The role of the employee", - async options() { - const roles = await this.paginate(this.getRoles); - return roles.map((role) => ({ - label: role.name, - value: role.id, - })); - }, - }, - // Props for updating an existing leave request - updateLeaveRequestId: { - type: "string", - label: "Leave Request ID", - description: "The ID of the leave request to update", - }, - updateLeaveStatus: { - type: "string", - label: "Leave Status", - description: "The new status of the leave request", - async options() { - const statuses = await this.paginate(this.getLeaveStatuses); - return statuses.map((status) => ({ - label: status.name, - value: status.id, - })); - }, - }, - updateLeaveStartDate: { - type: "string", - label: "Leave Start Date", - description: "The new start date of the leave request (YYYY-MM-DD)", - }, - updateLeaveEndDate: { - type: "string", - label: "Leave End Date", - description: "The new end date of the leave request (YYYY-MM-DD)", - }, - // Props for generating a payslip - generatePayslipEmployeeId: { - type: "string", - label: "Employee ID", - description: "The ID of the employee", - async options() { - const employees = await this.paginate(this.listEmployees); - return employees.map((emp) => ({ - label: emp.name, - value: emp.id, - })); - }, - }, - generatePayPeriodStart: { - type: "string", - label: "Pay Period Start Date", - description: "The start date of the pay period (YYYY-MM-DD)", - }, - generatePayPeriodEnd: { - type: "string", - label: "Pay Period End Date", - description: "The end date of the pay period (YYYY-MM-DD)", - }, - generateCustomNotes: { - type: "string", - label: "Custom Notes", - description: "Optional custom notes to include in the payslip", - optional: true, - }, }, methods: { _baseUrl() { - return "https://api.kenjo.io/v1"; + return this.$auth.api_url; }, - async _makeRequest(opts = {}) { - const { - $ = this, - method = "GET", - path = "/", - headers, - ...otherOpts - } = opts; + _makeRequest({ + $ = this, + path, + ...otherOpts + }) { return axios($, { ...otherOpts, - method, - url: this._baseUrl() + path, + url: `${this._baseUrl()}${path}`, headers: { - ...headers, - "Authorization": `Bearer ${this.$auth.api_key}`, - "Content-Type": "application/json", + Authorization: `${this.$auth.oauth_access_token}`, + Accept: "application/json", }, }); }, - async paginate(fn, opts = {}, results = []) { - const response = await fn(opts); - if (Array.isArray(response)) { - results.push(...response); - return results; - } - if (response.items && response.items.length > 0) { - results.push(...response.items); - if (response.nextPage) { - return this.paginate(fn, { - ...opts, - page: response.nextPage, - }, results); - } - } - return results; - }, - // Methods for emitting new employee added - async getDepartments(opts = {}) { + listCompanies(opts = {}) { return this._makeRequest({ - path: "/departments", + path: "/companies", ...opts, }); }, - async getRoles(opts = {}) { + listOffices(opts = {}) { return this._makeRequest({ - path: "/roles", + path: "/offices", ...opts, }); }, - // Methods for emitting updated leave request - async getLeaveStatuses(opts = {}) { + listDepartments(opts = {}) { return this._makeRequest({ - path: "/time-off-statuses", + path: "/departments", ...opts, }); }, - // Methods for emitting new performance review - async getReviewTypes(opts = {}) { + listEmployees(opts = {}) { return this._makeRequest({ - path: "/performance-review-types", + path: "/employees", ...opts, }); }, - async listEmployees(opts = {}) { + listTimeOffTypes(opts = {}) { return this._makeRequest({ - path: "/employees", + path: "/time-off/types", ...opts, }); }, - // Action: Create a new employee - async createEmployee({ - name, email, department, role, ...opts - }) { + createEmployee(opts = {}) { return this._makeRequest({ method: "POST", path: "/employees", - data: { - name: this.createEmployeeName, - email: this.createEmployeeEmail, - department_id: this.createEmployeeDepartment, - role_id: this.createEmployeeRole, - }, ...opts, }); }, - // Action: Update an existing leave request - async updateLeaveRequest({ - leaveRequestId, status, startDate, endDate, ...opts - }) { + createLeaveRequest(opts = {}) { return this._makeRequest({ - method: "PUT", - path: `/time-off-requests/${this.updateLeaveRequestId}`, - data: { - status: this.updateLeaveStatus, - start_date: this.updateLeaveStartDate, - end_date: this.updateLeaveEndDate, - }, + method: "POST", + path: "/time-off/requests", ...opts, }); }, - // Action: Generate a payslip - async generatePayslip({ - employeeId, payPeriodStart, payPeriodEnd, customNotes, ...opts - }) { - const data = { - employee_id: this.generatePayslipEmployeeId, - pay_period_start: this.generatePayPeriodStart, - pay_period_end: this.generatePayPeriodEnd, - }; - if (this.generateCustomNotes) { - data.custom_notes = this.generateCustomNotes; - } + createAttendanceEntry(opts = {}) { return this._makeRequest({ method: "POST", - path: "/payslips", - data, + path: "/attendances", ...opts, }); }, - // Methods for emitting events - async emitEmployeeAddedEvent() { - const newEmployees = await this.listEmployees(); - // Logic to detect new employees - // This is a placeholder; actual implementation may vary - return newEmployees; - }, - async emitLeaveRequestUpdatedEvent() { - const updatedLeaveRequests = await this._makeRequest({ - path: "/leave-requests/updated", - }); - return updatedLeaveRequests; - }, - async emitPerformanceReviewCreatedEvent() { - const newPerformanceReviews = await this._makeRequest({ - path: "/performance-reviews/new", - }); - return newPerformanceReviews; - }, }, }; diff --git a/components/kenjo/package.json b/components/kenjo/package.json index f87f8e64c80e8..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" } } 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/components/kenjo/sources/new-employee-instant/new-employee-instant.mjs b/components/kenjo/sources/new-employee-instant/new-employee-instant.mjs deleted file mode 100644 index 6d4255fb9be09..0000000000000 --- a/components/kenjo/sources/new-employee-instant/new-employee-instant.mjs +++ /dev/null @@ -1,127 +0,0 @@ -import kenjo from "../../kenjo.app.mjs"; -import { axios } from "@pipedream/platform"; -import crypto from "crypto"; - -export default { - key: "kenjo-new-employee-instant", - name: "New Employee Added", - description: "Emit a new event when a new employee is added in Kenjo. Useful for syncing employee data with other systems. [See the documentation]()", - version: "0.0.{{ts}}", - type: "source", - dedupe: "unique", - props: { - kenjo: { - type: "app", - app: "kenjo", - }, - filterDepartment: { - propDefinition: [ - kenjo, - "filterDepartment", - ], - }, - filterRole: { - propDefinition: [ - kenjo, - "filterRole", - ], - }, - db: "$.service.db", - http: { - type: "$.interface.http", - customResponse: true, - }, - }, - hooks: { - async activate() { - const callbackUrl = this.http.endpoint; - const secret = crypto.randomBytes(32).toString("hex"); - const response = await this.kenjo._makeRequest({ - method: "POST", - path: "/webhooks", - data: { - event: "employee.created", - callback_url: callbackUrl, - signature_secret: secret, - }, - }); - await this.db.set("webhookId", response.id); - await this.db.set("webhookSecret", secret); - }, - async deactivate() { - const webhookId = await this.db.get("webhookId"); - if (webhookId) { - await this.kenjo._makeRequest({ - method: "DELETE", - path: `/webhooks/${webhookId}`, - }); - await this.db.set("webhookId", null); - await this.db.set("webhookSecret", null); - } - }, - async deploy() { - const filters = {}; - if (this.filterDepartment) { - filters.department_id = this.filterDepartment; - } - if (this.filterRole) { - filters.role_id = this.filterRole; - } - const employees = await this.kenjo.paginate(this.kenjo.listEmployees, { - params: filters, - paginate: true, - max: 50, - }); - for (const employee of employees) { - this.$emit(employee, { - id: employee.id.toString(), - summary: `New employee added: ${employee.name}`, - ts: Date.parse(employee.created_at) || Date.now(), - }); - } - }, - }, - async run(event) { - const signature = event.headers["x-kenjo-signature"]; - const body = JSON.stringify(event.body); - const secret = await this.db.get("webhookSecret"); - const computedSignature = crypto.createHmac("sha256", secret).update(body) - .digest("hex"); - if (signature !== computedSignature) { - this.http.respond({ - status: 401, - body: "Unauthorized", - }); - return; - } - - const employee = event.body; - - if (this.filterDepartment && employee.department_id !== this.filterDepartment) { - this.http.respond({ - status: 200, - body: "OK", - }); - return; - } - - if (this.filterRole && employee.role_id !== this.filterRole) { - this.http.respond({ - status: 200, - body: "OK", - }); - return; - } - - this.$emit(employee, { - id: employee.id.toString(), - summary: `New employee added: ${employee.name}`, - ts: Date.parse(employee.created_at) || Date.now(), - }); - - this.http.respond({ - status: 200, - body: "OK", - }); - }, -}; diff --git a/components/kenjo/sources/new-performance-review-instant/new-performance-review-instant.mjs b/components/kenjo/sources/new-performance-review-instant/new-performance-review-instant.mjs deleted file mode 100644 index d0d9d33f5f8d6..0000000000000 --- a/components/kenjo/sources/new-performance-review-instant/new-performance-review-instant.mjs +++ /dev/null @@ -1,86 +0,0 @@ -import kenjo from "../../kenjo.app.mjs"; -import { axios } from "@pipedream/platform"; - -export default { - key: "kenjo-new-performance-review-instant", - name: "New Performance Review Created", - description: "Emit a new event when a performance review is created. [See the documentation]()]", - version: "0.0.{{ts}}", - type: "source", - dedupe: "unique", - props: { - kenjo: { - type: "app", - app: "kenjo", - }, - emitNewPerformanceReview: { - propDefinition: [ - "kenjo", - "emitNewPerformanceReview", - ], - }, - filterReviewType: { - propDefinition: [ - "kenjo", - "filterReviewType", - ], - }, - filterReviewEmployee: { - propDefinition: [ - "kenjo", - "filterReviewEmployee", - ], - }, - db: "$.service.db", - }, - methods: { - _getLastReviewId() { - return this.db.get("lastReviewId") || null; - }, - _setLastReviewId(id) { - return this.db.set("lastReviewId", id); - }, - _generateId(review) { - return `${review.employeeId}-${new Date(review.createdAt).getTime()}`; - }, - }, - hooks: { - async deploy() { - const reviews = await this.kenjo.emitNewPerformanceReview(); - reviews.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt)); - for (const review of reviews) { - const id = review.id || this._generateId(review); - const summary = `New performance review created for ${review.employeeName}`; - const ts = Date.parse(review.createdAt) || Date.now(); - this.$emit(review, { - id, - summary, - ts, - }); - if (!this._getLastReviewId() || review.id > this._getLastReviewId()) { - this._setLastReviewId(review.id); - } - } - }, - }, - async run() { - const lastId = this._getLastReviewId(); - const reviews = await this.kenjo.emitNewPerformanceReview(); - reviews.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt)); - for (const review of reviews) { - if (!lastId || review.id > lastId) { - const id = review.id || this._generateId(review); - const summary = `New performance review created for ${review.employeeName}`; - const ts = Date.parse(review.createdAt) || Date.now(); - this.$emit(review, { - id, - summary, - ts, - }); - if (!lastId || review.id > lastId) { - this._setLastReviewId(review.id); - } - } - } - }, -}; diff --git a/components/kenjo/sources/updated-leave-request-instant/updated-leave-request-instant.mjs b/components/kenjo/sources/updated-leave-request-instant/updated-leave-request-instant.mjs deleted file mode 100644 index 6b31f4c5fab20..0000000000000 --- a/components/kenjo/sources/updated-leave-request-instant/updated-leave-request-instant.mjs +++ /dev/null @@ -1,116 +0,0 @@ -import kenjo from "../../kenjo.app.mjs"; -import crypto from "crypto"; -import { axios } from "@pipedream/platform"; - -export default { - key: "kenjo-updated-leave-request-instant", - name: "Updated Leave Request (Instant)", - description: "Emit a new event when an existing leave request is updated (e.g., approved, rejected, or modified). [See the documentation]().", - version: "0.0.{{ts}}", - type: "source", - dedupe: "unique", - props: { - kenjo, - db: "$.service.db", - http: { - type: "$.interface.http", - customResponse: true, - }, - filterEmployeeId: { - propDefinition: [ - "kenjo", - "filterEmployeeId", - ], - optional: true, - }, - filterStatus: { - propDefinition: [ - "kenjo", - "filterStatus", - ], - optional: true, - }, - }, - hooks: { - async deploy() { - const updatedLeaveRequests = await this.kenjo.emitLeaveRequestUpdatedEvent(); - const last50 = updatedLeaveRequests.slice(-50).reverse(); - for (const leaveRequest of last50) { - if ( - (this.filterEmployeeId && leaveRequest.employee_id !== this.filterEmployeeId) || - (this.filterStatus && leaveRequest.status_id !== this.filterStatus) - ) { - continue; - } - this.$emit(leaveRequest, { - id: leaveRequest.id || `${leaveRequest.updated_at}`, - summary: `Leave request ${leaveRequest.id} updated`, - ts: Date.parse(leaveRequest.updated_at) || Date.now(), - }); - } - }, - async activate() { - const response = await this.kenjo._makeRequest({ - method: "POST", - path: "/webhooks", - data: { - event: "leave_request_updated", - callback_url: this.http.endpoint, - }, - }); - const webhookId = response.id; - this.db.set("webhookId", webhookId); - }, - async deactivate() { - const webhookId = await this.db.get("webhookId"); - if (webhookId) { - await this.kenjo._makeRequest({ - method: "DELETE", - path: `/webhooks/${webhookId}`, - }); - this.db.delete("webhookId"); - } - }, - }, - async run(event) { - const signature = event.headers["x-kenjo-signature"]; - const secret = this.kenjo.$auth.api_key; - const rawBody = event.rawBody; - const computedSignature = crypto.createHmac("sha256", secret).update(rawBody) - .digest("hex"); - if (computedSignature !== signature) { - this.http.respond({ - status: 401, - body: "Unauthorized", - }); - return; - } - const data = event.body; - if (this.filterEmployeeId && data.employee_id !== this.filterEmployeeId) { - this.http.respond({ - status: 200, - body: "OK", - }); - return; - } - if (this.filterStatus && data.status_id !== this.filterStatus) { - this.http.respond({ - status: 200, - body: "OK", - }); - return; - } - const id = data.id || `${Date.now()}`; - const summary = `Leave request ${data.id} updated`; - const ts = Date.parse(data.updated_at) || Date.now(); - this.$emit(data, { - id, - summary, - ts, - }); - this.http.respond({ - status: 200, - body: "OK", - }); - }, -}; From 8165af19800032715da4f079e0ba4f490103bd9e Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 27 Dec 2024 13:31:00 -0500 Subject: [PATCH 3/3] pnpm-lock.yaml --- pnpm-lock.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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: {}