-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add Givebutter contact and transaction actions #21676
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1b422e6
Add Givebutter contact and transaction actions
Priyadharshan-Pdm 7028bdd
Rename constants.js to constants.mjs
Priyadharshan-Pdm d3fc10c
Update description and type filter for list-contacts
Priyadharshan-Pdm adacd15
Clean up Givebutter component descriptions and reset version
Priyadharshan-Pdm afeb23d
Add @pipedream/platform dependency to givebutter component
Priyadharshan-Pdm 2d42a00
Update package.json
Priyadharshan-Pdm d1242a7
Remove scope prop and fix parameter naming in Givebutter actions
Priyadharshan-Pdm 8f27189
Update contact email and phone schema for Givebutter API
Priyadharshan-Pdm 21da098
Improve Givebutter update contact logic
Priyadharshan-Pdm 31867c1
Prevent blank email and phone updates in Givebutter action
Priyadharshan-Pdm 3c1e470
Upgrade @pipedream/platform in givebutter component
Priyadharshan-Pdm dcfceb3
Refactor Givebutter components to use shared prop definitions
Priyadharshan-Pdm b751d0e
Update components/givebutter/actions/create-contact/create-contact.mjs
Priyadharshan-Pdm 3b6bfbb
Merge branch 'master' into issue-21668-givebutter
Priyadharshan-Pdm a4ed828
Refactor Givebutter constants and move common definitions
Priyadharshan-Pdm 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
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
components/givebutter/actions/create-contact/create-contact.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,83 @@ | ||
| // x-pd-ai: optimized | ||
| import givebutter from "../../givebutter.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "givebutter-create-contact", | ||
| name: "Create Contact", | ||
| description: "Create a new contact/donor in Givebutter, returning the created contact with its assigned `id`. For an individual contact, provide `firstName` and `lastName`; the `email` value is submitted as the API `primary_email` field. [See the documentation](https://docs.givebutter.com/api-reference/contacts/create-a-contact)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: false, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| givebutter, | ||
| firstName: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "firstName", | ||
| ], | ||
| description: "Contact's first name (max 255 chars). For an individual contact without email or phone, provide both first and last names. Maps to the API `first_name` field.", | ||
| }, | ||
| lastName: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "lastName", | ||
| ], | ||
| description: "Contact's last name (max 255 chars). Maps to the API `last_name` field.", | ||
| }, | ||
| email: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "email", | ||
| ], | ||
| description: "Contact's primary email address. Submitted to Givebutter as the `primary_email` field. Example: `jane@example.com`.", | ||
| }, | ||
| phone: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "phone", | ||
| ], | ||
| description: "Contact's primary phone number. Maps to the API `primary_phone` field. Example: `+15555550100`.", | ||
| }, | ||
| type: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "contactType", | ||
| ], | ||
| description: "Type of contact to create. For `company`, provide **Company Name** instead of first/last name.", | ||
| }, | ||
| companyName: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "companyName", | ||
| ], | ||
| description: "Company name (max 255 chars). Required when **Type** is `company`. Maps to the API `company_name` field.", | ||
| }, | ||
| tags: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "tags", | ||
| ], | ||
| description: "Optional list of tag strings to attach to the contact (max 64 tags). Example: `[\"vip\", \"newsletter\"]`.", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const contact = await this.givebutter.createContact({ | ||
| $, | ||
| data: { | ||
| first_name: this.firstName, | ||
| last_name: this.lastName, | ||
| primary_email: this.email, | ||
| primary_phone: this.phone, | ||
| type: this.type, | ||
| company_name: this.companyName, | ||
| tags: this.tags, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Created contact ${contact?.id} - ${contact?.first_name ?? ""} ${contact?.last_name ?? ""}`.trim()); | ||
| return contact; | ||
| }, | ||
| }; | ||
31 changes: 31 additions & 0 deletions
31
components/givebutter/actions/get-transaction/get-transaction.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,31 @@ | ||
| // x-pd-ai: optimized | ||
| import givebutter from "../../givebutter.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "givebutter-get-transaction", | ||
| name: "Get Transaction", | ||
| description: "Retrieve a single transaction from Givebutter by its transaction ID. Returns the transaction object (includes `id`, `amount`, `fee`, `captured`, `refunded`, and `line_items`). [See the documentation](https://docs.givebutter.com/api-reference/transactions/get-a-transaction)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: true, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| givebutter, | ||
| transactionId: { | ||
| type: "string", | ||
| label: "Transaction ID", | ||
| description: "The transaction ID (the Givebutter transaction `tid`, a string, e.g. `AbCd1234`). Obtain it from a transaction event or from your Givebutter dashboard; there is no list-transactions action in this set.", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const transaction = await this.givebutter.getTransaction({ | ||
| $, | ||
| transactionId: this.transactionId, | ||
| }); | ||
| $.export("$summary", `Retrieved transaction ${transaction?.id ?? this.transactionId}`); | ||
| return transaction; | ||
| }, | ||
| }; |
45 changes: 45 additions & 0 deletions
45
components/givebutter/actions/list-campaigns/list-campaigns.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,45 @@ | ||
| // x-pd-ai: optimized | ||
| import givebutter from "../../givebutter.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "givebutter-list-campaigns", | ||
| name: "List Campaigns", | ||
| description: "List campaigns from the authenticated Givebutter account. Returns a paginated array of campaign objects (each includes at minimum `id`, `code`, and `title`). Use this to discover campaign IDs before referencing a campaign in other tools. [See the documentation](https://docs.givebutter.com/api-reference/campaigns/list-all-campaigns)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: true, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| givebutter, | ||
| page: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "page", | ||
| ], | ||
| }, | ||
| limit: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "limit", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.givebutter.listCampaigns({ | ||
| $, | ||
| params: { | ||
| page: this.page, | ||
| per_page: this.limit, | ||
| }, | ||
| }); | ||
| const campaigns = response?.data ?? response; | ||
| const count = Array.isArray(campaigns) | ||
| ? campaigns.length | ||
| : "unknown number of"; | ||
| $.export("$summary", `Retrieved ${count} campaign(s)`); | ||
| return response; | ||
| }, | ||
| }; |
77 changes: 77 additions & 0 deletions
77
components/givebutter/actions/list-contacts/list-contacts.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,77 @@ | ||
| // x-pd-ai: optimized | ||
| import givebutter from "../../givebutter.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "givebutter-list-contacts", | ||
| name: "List Contacts", | ||
| description: "List contacts/donors from the authenticated Givebutter account. Returns a paginated array of contact objects (each includes at minimum `id`, `primary_email`, `first_name`, and `last_name`). Note that the API returns only `individual` contacts unless **Type** is set to `company`. Use this to discover contact IDs before calling **Update Contact**. [See the documentation](https://docs.givebutter.com/api-reference/contacts/list-all-contacts)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: true, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| givebutter, | ||
| type: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "contactType", | ||
| ], | ||
| description: "Contact type to list. The Givebutter API defaults to `individual`, so company contacts are omitted unless this is explicitly set to `company`.", | ||
| }, | ||
| email: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "email", | ||
| ], | ||
| description: "Optional exact email to filter contacts by (maps to the API `email` query param). Example: `jane@example.com`.", | ||
| }, | ||
| sortBy: { | ||
| type: "string", | ||
| label: "Sort By", | ||
| description: "Optional field to sort by.", | ||
| options: [ | ||
| "name_or_company", | ||
| "primary_email", | ||
| "point_of_contact", | ||
| "created_at", | ||
| "total_contributions", | ||
| "recurring_contributions", | ||
| "last_donation_amount", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| page: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "page", | ||
| ], | ||
| }, | ||
| limit: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "limit", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.givebutter.listContacts({ | ||
| $, | ||
| params: { | ||
| type: this.type, | ||
| email: this.email, | ||
| sortBy: this.sortBy, | ||
| page: this.page, | ||
| per_page: this.limit, | ||
| }, | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
| const contacts = response?.data ?? response; | ||
| const count = Array.isArray(contacts) | ||
| ? contacts.length | ||
| : "unknown number of"; | ||
| $.export("$summary", `Retrieved ${count} contact(s)`); | ||
| return response; | ||
| }, | ||
| }; | ||
137 changes: 137 additions & 0 deletions
137
components/givebutter/actions/update-contact/update-contact.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,137 @@ | ||
| // x-pd-ai: optimized | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import givebutter from "../../givebutter.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "givebutter-update-contact", | ||
| name: "Update Contact", | ||
| description: "Update an existing Givebutter contact, returning the updated contact object. Set only the fields you want to change. Use **List Contacts** first to find the contact ID. Note that Givebutter validates this as a full update — individual contacts require `first_name` and `last_name`, and company contacts require `company_name`, even when those values are not changing — so this action reads the contact first and re-sends its existing name and company values automatically. [See the documentation](https://docs.givebutter.com/api-reference/contacts/update-a-contact)", | ||
|
Priyadharshan-Pdm marked this conversation as resolved.
|
||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: false, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| givebutter, | ||
| contactId: { | ||
| type: "string", | ||
| label: "Contact ID", | ||
| description: "The ID of the contact to update (an integer identifier, e.g. `12345`). Run **List Contacts** to find valid contact IDs.", | ||
| }, | ||
| firstName: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "firstName", | ||
| ], | ||
| }, | ||
| lastName: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "lastName", | ||
| ], | ||
| }, | ||
| email: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "email", | ||
| ], | ||
| description: "Email address to set on the contact, submitted in the API `emails` array. Example: `jane.updated@example.com`. Becomes the contact's primary email unless `Email Is Primary` is set to `false`.", | ||
| }, | ||
| emailIsPrimary: { | ||
| type: "boolean", | ||
| label: "Email Is Primary", | ||
| description: "Whether `Email` becomes the contact's primary email address (the API `is_primary` flag). Defaults to `true`; set to `false` to add it as a secondary address, leaving the existing primary in place. Ignored when `Email` is not set.", | ||
| default: true, | ||
| optional: true, | ||
| }, | ||
| phone: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "phone", | ||
| ], | ||
| description: "Phone number to set on the contact, submitted in the API `phones` array. Example: `+15555550100`. Becomes the contact's primary phone unless `Phone Is Primary` is set to `false`.", | ||
| }, | ||
| phoneIsPrimary: { | ||
| type: "boolean", | ||
| label: "Phone Is Primary", | ||
| description: "Whether `Phone` becomes the contact's primary phone number (the API `is_primary` flag). Defaults to `true`; set to `false` to add it as a secondary number, leaving the existing primary in place. Ignored when `Phone` is not set.", | ||
| default: true, | ||
| optional: true, | ||
| }, | ||
| companyName: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "companyName", | ||
| ], | ||
| }, | ||
| note: { | ||
| type: "string", | ||
| label: "Note", | ||
| description: "Optional note to set on the contact.", | ||
| optional: true, | ||
| }, | ||
| tags: { | ||
| propDefinition: [ | ||
| givebutter, | ||
| "tags", | ||
| ], | ||
| description: "Optional list of tag strings to set on the contact (max 64 tags), replacing the contact's existing tags. Example: `[\"vip\", \"newsletter\"]`.", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| if (this.email?.trim() === "" || this.phone?.trim() === "") { | ||
| throw new ConfigurationError("Email and Phone cannot be blank. Omit the prop entirely to leave the contact's existing value unchanged."); | ||
| } | ||
|
|
||
| const updates = [ | ||
| this.firstName, | ||
| this.lastName, | ||
| this.email, | ||
| this.phone, | ||
| this.companyName, | ||
| this.note, | ||
| this.tags, | ||
| ]; | ||
| if (updates.every((value) => value === undefined || value === null)) { | ||
|
Priyadharshan-Pdm marked this conversation as resolved.
|
||
| throw new ConfigurationError("Set at least one field to update."); | ||
| } | ||
|
|
||
| const existing = await this.givebutter.getContact({ | ||
| $, | ||
| contactId: this.contactId, | ||
| }); | ||
| const current = existing?.data ?? existing; | ||
|
|
||
| const contact = await this.givebutter.updateContact({ | ||
| $, | ||
| contactId: this.contactId, | ||
| data: { | ||
| first_name: this.firstName ?? current?.first_name, | ||
| last_name: this.lastName ?? current?.last_name, | ||
| company_name: this.companyName ?? current?.company_name, | ||
| ...(this.email && { | ||
| emails: [ | ||
| { | ||
| value: this.email, | ||
| is_primary: this.emailIsPrimary ?? true, | ||
| }, | ||
| ], | ||
| }), | ||
| ...(this.phone && { | ||
| phones: [ | ||
| { | ||
| value: this.phone, | ||
| is_primary: this.phoneIsPrimary ?? true, | ||
| }, | ||
| ], | ||
| }), | ||
| note: this.note, | ||
| tags: this.tags, | ||
| }, | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
| $.export("$summary", `Updated contact ${contact?.id ?? this.contactId}`); | ||
| return contact; | ||
| }, | ||
| }; | ||
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,2 @@ | ||
| export const DEFAULT_PER_PAGE = 20; | ||
| export const MAX_PER_PAGE = 100; |
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.