diff --git a/components/certifier/actions/create-group/create-group.mjs b/components/certifier/actions/create-group/create-group.mjs new file mode 100644 index 0000000000000..98d3d9991d8c5 --- /dev/null +++ b/components/certifier/actions/create-group/create-group.mjs @@ -0,0 +1,71 @@ +import certifier from "../../certifier.app.mjs"; + +export default { + name: "Create Group", + version: "0.0.1", + key: "certifier-create-group", + description: + "Create a group. [See the documentation](https://developers.certifier.io/reference/create-a-group)", + props: { + certifier, + name: { + propDefinition: [ + certifier, + "groupName", + ], + }, + certificateDesignId: { + propDefinition: [ + certifier, + "certificateDesignId", + ], + }, + badgeDesignId: { + propDefinition: [ + certifier, + "badgeDesignId", + ], + }, + learningEventUrl: { + propDefinition: [ + certifier, + "learningEventUrl", + ], + }, + // eslint-disable-next-line pipedream/props-label, pipedream/props-description + alert: { + type: "alert", + alertType: "warning", + content: + "At least one of `Certificate Design` and `Badge Design` fields is required.", + }, + }, + type: "action", + methods: {}, + async run({ $ }) { + const { + certifier, + name, + certificateDesignId, + badgeDesignId, + learningEventUrl, + } = this; + + const response = await certifier.createGroup({ + $, + data: { + name, + certificateDesignId, + badgeDesignId, + learningEventUrl, + }, + }); + + $.export( + "$summary", + `Successfully created group ${response.name}`, + ); + + return response; + }, +}; diff --git a/components/certifier/actions/issue-credential/issue-credential.mjs b/components/certifier/actions/issue-credential/issue-credential.mjs index 6a862cbe6dce4..4241c86d4433b 100644 --- a/components/certifier/actions/issue-credential/issue-credential.mjs +++ b/components/certifier/actions/issue-credential/issue-credential.mjs @@ -2,7 +2,7 @@ import certifier from "../../certifier.app.mjs"; export default { name: "Issue Credential", - version: "0.0.1", + version: "0.0.2", key: "certifier-issue-credential", description: "Create, issue and send a credential to a recipient. [See the documentation](https://developers.certifier.io/reference/create-issue-send-a-credential)", diff --git a/components/certifier/certifier.app.mjs b/components/certifier/certifier.app.mjs index c904d412dae85..2e3bc29e01b2b 100644 --- a/components/certifier/certifier.app.mjs +++ b/components/certifier/certifier.app.mjs @@ -36,6 +36,12 @@ export default { ...args, }); }, + searchDesigns(args = {}) { + return this.callApi({ + path: "/designs", + ...args, + }); + }, createCredential(args = {}) { return this.callApi({ method: "POST", @@ -57,6 +63,13 @@ export default { ...args, }); }, + createGroup(args = {}) { + return this.callApi({ + method: "POST", + path: "/groups", + ...args, + }); + }, }, propDefinitions: { groupId: { @@ -121,5 +134,82 @@ export default { "The date (in `YYYY-MM-DD` format) of your credential's expiration. If not provided, expiry date from the group settings will be used (by default this field is empty).", optional: true, }, + groupName: { + type: "string", + label: "Group Name", + description: + "The group's name that is used as [group.name] attribute later on.", + }, + certificateDesignId: { + type: "string", + label: "Certificate Design", + description: "The unique certificate design's name.", + optional: true, + async options({ prevContext } = {}) { + const response = await this.searchDesigns({ + params: { + cursor: prevContext.cursor, + }, + }); + const designs = response.data; + const cursor = response.pagination.next; + + return { + options: designs + .filter((design) => design.type === "certificate") + .map(({ + id, name, + }) => ({ + label: name, + value: id, + })), + context: { + cursor, + }, + }; + }, + }, + badgeDesignId: { + type: "string", + label: "Badge Design", + description: "The unique badge design's name.", + optional: true, + async options({ prevContext } = {}) { + const response = await this.searchDesigns({ + params: { + cursor: prevContext.cursor, + }, + }); + const designs = response.data; + const cursor = response.pagination.next; + + return { + options: designs + .filter((design) => design.type === "badge") + .map(({ + id, name, + }) => ({ + label: name, + value: id, + })), + context: { + cursor, + }, + }; + }, + }, + learningEventUrl: { + type: "string", + label: "Learning Event URL", + description: + "The learning event's URL that is shown in the digital wallet.", + optional: true, + }, + credentialId: { + type: "string", + label: "Credential ID", + description: + "The credential's unique ID.", + }, }, }; diff --git a/components/certifier/package.json b/components/certifier/package.json index a65b18de7a6d5..587da8d1ed5de 100644 --- a/components/certifier/package.json +++ b/components/certifier/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/certifier", - "version": "0.1.0", + "version": "0.2.0", "description": "Pipedream Certifier Components", "main": "certifier.app.mjs", "keywords": [