-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Adding stripe search customer action #16480
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 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0ac21e7
Adding stripe search customer action
dannyroosevelt 2bc7f73
Merge branch 'master' into danny/stripe-search-customers
dannyroosevelt e677e93
Escaping unsafe characters in email, adding pnpm-lock
dannyroosevelt e274911
Merge branch 'master' into danny/stripe-search-customers
dannyroosevelt 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
105 changes: 105 additions & 0 deletions
105
components/stripe/actions/search-customers/search-customers.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,105 @@ | ||
| import app from "../../stripe.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "stripe-search-customers", | ||
| name: "Search Customers", | ||
| type: "action", | ||
| version: "0.0.1", | ||
| description: "Search customers by various attributes like email domain, created date, etc. [See the docs](https://stripe.com/docs/api/customers/search) for more information", | ||
| props: { | ||
| app, | ||
| query: { | ||
| type: "string", | ||
| label: "Search Query", | ||
| description: "Search query using Stripe's [search query language](https://stripe.com/docs/search#search-query-language). Example: `email~\"example.com\" AND created>1609459200`", | ||
| optional: true, | ||
| }, | ||
| email: { | ||
| type: "string", | ||
| label: "Email", | ||
| description: "Search by customer email address (e.g.,`[email protected]`)", | ||
| optional: true, | ||
| }, | ||
| emailDomain: { | ||
| type: "string", | ||
| label: "Email Domain", | ||
| description: "Search by email **domain** (e.g., `example.com` to find all emails from that domain)", | ||
| optional: true, | ||
| }, | ||
| createdAfter: { | ||
| type: "string", | ||
| label: "Created After", | ||
| description: "Filter customers created after this date (format: `YYYY-MM-DD`)", | ||
| optional: true, | ||
| }, | ||
| createdBefore: { | ||
| type: "string", | ||
| label: "Created Before", | ||
| description: "Filter customers created before this date (format: `YYYY-MM-DD`)", | ||
| optional: true, | ||
| }, | ||
| limit: { | ||
| propDefinition: [ | ||
| app, | ||
| "limit", | ||
| ], | ||
| description: "Maximum number of customers to return", | ||
| default: 25, | ||
| }, | ||
| }, | ||
| methods: { | ||
| convertDateToTimestamp(dateStr) { | ||
| if (!dateStr) return null; | ||
| const date = new Date(`${dateStr}T00:00:00Z`); | ||
| return Math.floor(date.getTime() / 1000); | ||
| }, | ||
|
|
||
| buildSearchQuery() { | ||
| const queryParts = []; | ||
|
|
||
| if (this.query) { | ||
| return this.query; | ||
| } | ||
|
|
||
| if (this.email) { | ||
| queryParts.push(`email="${this.email}"`); | ||
| } | ||
|
|
||
| if (this.emailDomain) { | ||
| queryParts.push(`email~"${this.emailDomain}"`); | ||
| } | ||
|
|
||
| const afterTimestamp = this.convertDateToTimestamp(this.createdAfter); | ||
| if (afterTimestamp) { | ||
| queryParts.push(`created>${afterTimestamp}`); | ||
| } | ||
|
|
||
| const beforeTimestamp = this.convertDateToTimestamp(this.createdBefore); | ||
| if (beforeTimestamp) { | ||
| queryParts.push(`created<${beforeTimestamp}`); | ||
| } | ||
|
|
||
| return queryParts.join(" AND "); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const query = this.buildSearchQuery(); | ||
|
|
||
| if (!query) { | ||
| throw new Error("Please provide at least one search parameter"); | ||
| } | ||
|
|
||
| // Use a specific API version for search functionality | ||
| const results = await this.app.sdk("2023-10-16").customers.search({ | ||
| query, | ||
| limit: this.limit, | ||
| }); | ||
|
|
||
| const resultCount = results.data.length; | ||
| $.export("$summary", `Found ${resultCount} customer${resultCount === 1 | ||
| ? "" | ||
| : "s"}`); | ||
|
|
||
| return results.data; | ||
| }, | ||
| }; | ||
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
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.