diff --git a/components/educateme/actions/create-course/create-course.mjs b/components/educateme/actions/create-course/create-course.mjs new file mode 100644 index 0000000000000..ad9499a14c76d --- /dev/null +++ b/components/educateme/actions/create-course/create-course.mjs @@ -0,0 +1,68 @@ +import educateme from "../../educateme.app.mjs"; + +export default { + key: "educateme-create-course", + name: "Create Course", + description: "Create a new course. [See the documentation](https://edme.notion.site/API-integration-v0-2-ef33641eb7f24fa9a6efb969c1f2928f)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + props: { + educateme, + title: { + type: "string", + label: "Title", + description: "The title of the course", + }, + type: { + type: "string", + label: "Course Type", + description: "The type of the course", + options: [ + "COHORT_BASED", + "SELF_PACED", + ], + }, + previewUrl: { + type: "string", + label: "Preview URL", + description: "The URL of the course preview", + optional: true, + }, + withProgramSyncing: { + type: "boolean", + label: "With Program Syncing", + description: "Whether to sync the course with the program", + optional: true, + }, + duplicatedCourseId: { + propDefinition: [ + educateme, + "courseId", + ], + label: "Duplicated Course ID", + description: "Optional. In case you need to copy a structure from another course", + optional: true, + }, + }, + async run({ $ }) { + const { result } = await this.educateme.createCourse({ + $, + data: { + title: this.title, + type: this.type, + previewUrl: this.previewUrl, + withProgramSyncing: this.withProgramSyncing, + duplicatedCourseId: this.duplicatedCourseId, + }, + }); + if (result?.id) { + $.export("$summary", `Successfully created course with ID: ${result.id}`); + } + return result; + }, +}; diff --git a/components/educateme/actions/find-courses/find-courses.mjs b/components/educateme/actions/find-courses/find-courses.mjs new file mode 100644 index 0000000000000..7a361952a9722 --- /dev/null +++ b/components/educateme/actions/find-courses/find-courses.mjs @@ -0,0 +1,49 @@ +import educateme from "../../educateme.app.mjs"; + +export default { + key: "educateme-find-courses", + name: "Find Courses", + description: "Find courses by optional filters. [See the documentation](https://edme.notion.site/API-integration-v0-2-ef33641eb7f24fa9a6efb969c1f2928f)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + educateme, + learnerEmail: { + type: "string", + label: "Learner Email", + description: "Filter courses by assigned learner email", + optional: true, + }, + isFinished: { + type: "boolean", + label: "Is Finished", + description: "If the course is finished", + optional: true, + }, + isSuspended: { + type: "boolean", + label: "Is Suspended", + description: "If the course is suspended", + optional: true, + }, + }, + async run({ $ }) { + const courses = await this.educateme.listCourses({ + $, + params: { + learnerEmail: this.learnerEmail, + isFinished: this.isFinished, + isSuspended: this.isSuspended, + }, + }); + $.export("$summary", `Successfully found ${courses.length} course${courses.length === 1 + ? "" + : "s"}`); + return courses; + }, +}; diff --git a/components/educateme/actions/get-course-activities/get-course-activities.mjs b/components/educateme/actions/get-course-activities/get-course-activities.mjs new file mode 100644 index 0000000000000..a6e3981acd4df --- /dev/null +++ b/components/educateme/actions/get-course-activities/get-course-activities.mjs @@ -0,0 +1,31 @@ +import educateme from "../../educateme.app.mjs"; + +export default { + key: "educateme-get-course-activities", + name: "Get Course Activities", + description: "Get the activities for a course. [See the documentation](https://edme.notion.site/API-integration-v0-2-ef33641eb7f24fa9a6efb969c1f2928f)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + educateme, + courseId: { + propDefinition: [ + educateme, + "courseId", + ], + }, + }, + async run({ $ }) { + const { result } = await this.educateme.listCourseActivities({ + $, + courseId: this.courseId, + }); + $.export("$summary", "Successfully retrieved course activities"); + return result; + }, +}; diff --git a/components/educateme/educateme.app.mjs b/components/educateme/educateme.app.mjs index 01fb72abfeade..2b74868ce5ff1 100644 --- a/components/educateme/educateme.app.mjs +++ b/components/educateme/educateme.app.mjs @@ -1,11 +1,57 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "educateme", - propDefinitions: {}, + propDefinitions: { + courseId: { + type: "string", + label: "Course ID", + description: "The ID of a course", + async options() { + const courses = await this.listCourses(); + return courses.map((course) => ({ + label: course.title, + value: course.id, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return this.$auth.api_url; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + ...opts, + url: `${this._baseUrl()}${path}`, + headers: { + "api-key": `${this.$auth.api_key}`, + }, + }); + }, + listCourses(opts = {}) { + return this._makeRequest({ + path: "/courses", + ...opts, + }); + }, + listCourseActivities({ + courseId, ...opts + }) { + return this._makeRequest({ + path: `/courses/${courseId}/lessons`, + ...opts, + }); + }, + createCourse(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/courses", + ...opts, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/educateme/package.json b/components/educateme/package.json index 0730e5153d9ce..203d197cae2d1 100644 --- a/components/educateme/package.json +++ b/components/educateme/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/educateme", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream EducateMe Components", "main": "educateme.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.1" } } diff --git a/components/educateme/sources/common/base.mjs b/components/educateme/sources/common/base.mjs new file mode 100644 index 0000000000000..337f199b8300c --- /dev/null +++ b/components/educateme/sources/common/base.mjs @@ -0,0 +1,31 @@ +import educateme from "../../educateme.app.mjs"; +import { + DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError, +} from "@pipedream/platform"; + +export default { + props: { + educateme, + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + }, + methods: { + async getResources() { + throw new ConfigurationError("getResources method must be implemented"); + }, + generateMeta() { + throw new ConfigurationError("generateMeta method must be implemented"); + }, + }, + async run() { + const resources = await this.getResources(); + for (const resource of resources || []) { + const meta = this.generateMeta(resource); + this.$emit(resource, meta); + } + }, +}; diff --git a/components/educateme/sources/new-course-activity/new-course-activity.mjs b/components/educateme/sources/new-course-activity/new-course-activity.mjs new file mode 100644 index 0000000000000..988bdbe3f975d --- /dev/null +++ b/components/educateme/sources/new-course-activity/new-course-activity.mjs @@ -0,0 +1,36 @@ +import common from "../common/base.mjs"; + +export default { + ...common, + key: "educateme-new-course-activity", + name: "New Course Activity", + description: "Emit new event when a new activity is created in a course. [See the documentation](https://edme.notion.site/API-integration-v0-2-ef33641eb7f24fa9a6efb969c1f2928f)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + ...common.props, + courseId: { + propDefinition: [ + common.props.educateme, + "courseId", + ], + }, + }, + methods: { + ...common.methods, + async getResources() { + const { result } = await this.educateme.listCourseActivities({ + courseId: this.courseId, + }); + return result; + }, + generateMeta(activity) { + return { + id: activity.id, + summary: `New activity: ${activity.title}`, + ts: Date.now(), + }; + }, + }, +}; diff --git a/components/educateme/sources/new-course-created/new-course-created.mjs b/components/educateme/sources/new-course-created/new-course-created.mjs new file mode 100644 index 0000000000000..8362c3c329142 --- /dev/null +++ b/components/educateme/sources/new-course-created/new-course-created.mjs @@ -0,0 +1,24 @@ +import common from "../common/base.mjs"; + +export default { + ...common, + key: "educateme-new-course-created", + name: "New Course Created", + description: "Emit new event when a new course is created. [See the documentation](https://edme.notion.site/API-integration-v0-2-ef33641eb7f24fa9a6efb969c1f2928f)", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getResources() { + return this.educateme.listCourses(); + }, + generateMeta(course) { + return { + id: course.id, + summary: `New course: ${course.title}`, + ts: Date.now(), + }; + }, + }, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e3bbf0b93d14a..58029fbb5ae33 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4631,7 +4631,11 @@ importers: specifier: 4.0.4 version: 4.0.4 - components/educateme: {} + components/educateme: + dependencies: + '@pipedream/platform': + specifier: ^3.1.1 + version: 3.1.1 components/edusign: {} @@ -31703,17 +31707,17 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net supports-color@10.2.2: resolution: {integrity: sha512-SS+jx45GF1QjgEXQx4NJZV9ImqmO2NPz5FNsIHrsDjh2YsHnawpan7SNQ1o8NuhrbHZy9AZhIoCUiCeaW/C80g==}