-
Notifications
You must be signed in to change notification settings - Fork 5.5k
13377 components encharge #19148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
luancazarine
wants to merge
4
commits into
master
Choose a base branch
from
13377-components-encharge
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
13377 components encharge #19148
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1e09207
Enhance Encharge component with new actions and sources
luancazarine 2aa0c23
pnpm update
luancazarine e8cc937
Refactor Encharge component actions for improved error handling and o…
luancazarine c1c302a
Remove phone field from add-or-update-person action for cleaner data …
luancazarine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
components/encharge/actions/add-or-update-person/add-or-update-person.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
| import app from "../../encharge.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "encharge-add-or-update-person", | ||
| name: "Add or Update Person", | ||
| description: "Add or update a person in Encharge. [See the documentation](https://app-encharge-resources.s3.amazonaws.com/redoc.html#/people/createupdatepeople)", | ||
| version: "0.0.1", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: false, | ||
| }, | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| userId: { | ||
| propDefinition: [ | ||
| app, | ||
| "userId", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| firstName: { | ||
| type: "string", | ||
| label: "First Name", | ||
| description: "The first name of the person.", | ||
| optional: true, | ||
| }, | ||
| lastName: { | ||
| type: "string", | ||
| label: "Last Name", | ||
| description: "The last name of the person.", | ||
| optional: true, | ||
| }, | ||
| email: { | ||
| type: "string", | ||
| label: "Email", | ||
| description: "The email of the person.", | ||
| optional: true, | ||
| }, | ||
| additionalFields: { | ||
| type: "object", | ||
| label: "Additional Fields", | ||
| description: "Additional fields to include in the request body.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const parsedAdditionalFields = parseObject(this.additionalFields) || {}; | ||
| const data = [ | ||
| { | ||
| firstName: this.firstName, | ||
| lastName: this.lastName, | ||
| email: this.email, | ||
| phone: this.phone, | ||
luancazarine marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| id: this.userId, | ||
| ...parsedAdditionalFields, | ||
| }, | ||
| ]; | ||
|
|
||
| const response = await this.app.addOrUpdatePerson({ | ||
| $, | ||
| data, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully ${this.userId | ||
| ? "updated" | ||
| : "added"} person${this.email | ||
| ? ` with email ${this.email}` | ||
| : ""}`); | ||
| return response; | ||
| }, | ||
| }; | ||
62 changes: 62 additions & 0 deletions
62
components/encharge/actions/archive-person/archive-person.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import app from "../../encharge.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "encharge-archive-person", | ||
| name: "Archive Person", | ||
| description: "Archive a person in Encharge. [See the documentation](https://app-encharge-resources.s3.amazonaws.com/redoc.html#/people/archivepeople)", | ||
| version: "0.0.1", | ||
| annotations: { | ||
| destructiveHint: true, | ||
| openWorldHint: true, | ||
| readOnlyHint: false, | ||
| }, | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| userId: { | ||
| propDefinition: [ | ||
| app, | ||
| "userId", | ||
| ], | ||
| description: "The user ID of the person to archive.", | ||
| optional: true, | ||
| }, | ||
| email: { | ||
| type: "string", | ||
| label: "Email", | ||
| description: "The email of the person to archive.", | ||
| optional: true, | ||
| }, | ||
| force: { | ||
| type: "boolean", | ||
| label: "Force", | ||
| description: "If set to `true`, will delete the person's data. This is useful for GDPR-compliant removal of user data.", | ||
| default: false, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| if (!this.userId && !this.email) { | ||
| throw new Error("You must provide either a user ID or an email."); | ||
| } | ||
| if (this.userId && this.email) { | ||
| throw new Error("You must provide either a user ID or an email, not both."); | ||
| } | ||
|
|
||
| const response = await this.app.archivePerson({ | ||
| $, | ||
| params: { | ||
| people: [ | ||
| { | ||
| id: this.userId, | ||
| email: this.email, | ||
| }, | ||
| ], | ||
| force: this.force, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully archived person with ${this.userId | ||
| ? `ID ${this.userId}` | ||
| : `email ${this.email}`}`); | ||
| return response; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
| import app from "../../encharge.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "encharge-remove-tags", | ||
| name: "Remove Tags", | ||
| description: "Remove tag(s) from existing user. [See the documentation](https://app-encharge-resources.s3.amazonaws.com/#/tags/removetag)", | ||
| version: "0.0.1", | ||
| annotations: { | ||
| destructiveHint: true, | ||
| openWorldHint: true, | ||
| readOnlyHint: false, | ||
| }, | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| userId: { | ||
| propDefinition: [ | ||
| app, | ||
| "userId", | ||
| ], | ||
| description: "UserID of the person.", | ||
| }, | ||
| tags: { | ||
| propDefinition: [ | ||
| app, | ||
| "tags", | ||
| ({ userId }) => ({ | ||
| userId, | ||
| }), | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const tags = parseObject(this.tags); | ||
| const tagsArray = Array.isArray(tags) | ||
| ? tags | ||
| : [ | ||
| tags, | ||
| ]; | ||
| const response = await this.app.removeTag({ | ||
| $, | ||
| data: { | ||
| tag: tagsArray.join(","), | ||
| id: this.userId, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully removed ${tagsArray.length} tag${tagsArray.length > 1 | ||
| ? "s" | ||
| : ""} from person with ID ${this.userId}`); | ||
| return response; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const LIMIT = 100; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| export const parseObject = (obj) => { | ||
| if (!obj) return undefined; | ||
|
|
||
| if (Array.isArray(obj)) { | ||
| return obj.map((item) => { | ||
| if (typeof item === "string") { | ||
| try { | ||
| return JSON.parse(item); | ||
| } catch (e) { | ||
| return item; | ||
| } | ||
| } | ||
| return item; | ||
| }); | ||
| } | ||
| if (typeof obj === "string") { | ||
| try { | ||
| return JSON.parse(obj); | ||
| } catch (e) { | ||
| return obj; | ||
| } | ||
| } | ||
| return obj; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,119 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
| import { LIMIT } from "./common/constants.mjs"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "encharge", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| userId: { | ||
| type: "string", | ||
| label: "User ID", | ||
| description: "The user ID of the person to update.", | ||
| async options({ page }) { | ||
| const { people } = await this.listPeople({ | ||
| params: { | ||
| limit: LIMIT, | ||
| offset: LIMIT * page, | ||
| }, | ||
| }); | ||
|
|
||
| return people.map(({ | ||
| id: value, name, email, | ||
| }) => ({ | ||
| label: `${name}${email | ||
| ? ` (${email})` | ||
| : ""}`, | ||
| value, | ||
| })); | ||
| }, | ||
| }, | ||
| tags: { | ||
| type: "string[]", | ||
| label: "Tags", | ||
| description: "Tags to remove from the person.", | ||
| async options({ userId }) { | ||
| const { | ||
| users: [ | ||
| { tags }, | ||
| ], | ||
| } = await this.getPerson({ | ||
| params: { | ||
| people: [ | ||
| { | ||
| id: userId, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
| return tags | ||
| ? tags.split(",") | ||
| : []; | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _apiUrl() { | ||
| return "https://api.encharge.io/v1"; | ||
| }, | ||
| _getHeaders() { | ||
| return { | ||
| "Authorization": `Bearer ${this.$auth.oauth_access_token}`, | ||
| }; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: `${this._apiUrl()}/${path}`, | ||
| headers: this._getHeaders(), | ||
| ...opts, | ||
| }); | ||
| }, | ||
| getPerson(args = {}) { | ||
| return this._makeRequest({ | ||
| path: "people", | ||
| ...args, | ||
| }); | ||
| }, | ||
| listPeople(args = {}) { | ||
| return this._makeRequest({ | ||
| path: "people/all", | ||
| ...args, | ||
| }); | ||
| }, | ||
| addOrUpdatePerson(args = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "people", | ||
| ...args, | ||
| }); | ||
| }, | ||
| archivePerson(args = {}) { | ||
| return this._makeRequest({ | ||
| method: "DELETE", | ||
| path: "people", | ||
| ...args, | ||
| }); | ||
| }, | ||
| removeTag(args = {}) { | ||
| return this._makeRequest({ | ||
| method: "DELETE", | ||
| path: "tags", | ||
| ...args, | ||
| }); | ||
| }, | ||
| createHook(args = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "event-subscriptions", | ||
| ...args, | ||
| }); | ||
| }, | ||
| deleteHook(hookId) { | ||
| return this._makeRequest({ | ||
| method: "DELETE", | ||
| path: `event-subscriptions/${hookId}`, | ||
| }); | ||
| }, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/encharge", | ||
| "version": "0.0.2", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Encharge Components", | ||
| "main": "encharge.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.1" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import encharge from "../../encharge.app.mjs"; | ||
|
|
||
| export default { | ||
| props: { | ||
| encharge, | ||
| db: "$.service.db", | ||
| http: "$.interface.http", | ||
| }, | ||
| methods: { | ||
| _setWebhookId(id) { | ||
| this.db.set("webhookId", id); | ||
| }, | ||
| _getWebhookId() { | ||
| return this.db.get("webhookId"); | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async activate() { | ||
| const { subscription } = await this.encharge.createHook({ | ||
| data: { | ||
| url: this.http.endpoint, | ||
| eventType: this.getEvent(), | ||
| }, | ||
| }); | ||
| this._setWebhookId(subscription.id); | ||
| }, | ||
| async deactivate() { | ||
| const webhookId = this._getWebhookId(); | ||
| await this.encharge.deleteHook(webhookId); | ||
| }, | ||
| }, | ||
| async run({ body }) { | ||
| this.$emit(body, this.generateMeta(body)); | ||
| }, | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.