diff --git a/components/stripe/actions/search-customers/search-customers.mjs b/components/stripe/actions/search-customers/search-customers.mjs new file mode 100644 index 0000000000000..51ef3523c0c46 --- /dev/null +++ b/components/stripe/actions/search-customers/search-customers.mjs @@ -0,0 +1,109 @@ +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.,`user@example.com`)", + 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) { + // Escape quotes in the email value to prevent query syntax errors + const escapedEmail = this.email.replace(/"/g, "\\\""); + queryParts.push(`email="${escapedEmail}"`); + } + + if (this.emailDomain) { + // Escape quotes in the domain value to prevent query syntax errors + const escapedDomain = this.emailDomain.replace(/"/g, "\\\""); + queryParts.push(`email~"${escapedDomain}"`); + } + + 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; + }, +}; diff --git a/components/stripe/package.json b/components/stripe/package.json index 214df681ddb88..a55a71fd40ce0 100644 --- a/components/stripe/package.json +++ b/components/stripe/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/stripe", - "version": "0.6.3", + "version": "0.6.4", "description": "Pipedream Stripe Components", "main": "stripe.app.mjs", "keywords": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 444614bbe09b6..9187b8eb95cc6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23123,6 +23123,7 @@ packages: formidable@2.1.2: resolution: {integrity: sha512-CM3GuJ57US06mlpQ47YcunuUZ9jpm8Vx+P2CGt2j7HpgkKZO/DJYQ0Bobim8G6PFQmK5lOqOOdUXboU+h73A4g==} + deprecated: 'ACTION REQUIRED: SWITCH TO v3 - v1 and v2 are VULNERABLE! v1 is DEPRECATED FOR OVER 2 YEARS! Use formidable@latest or try formidable-mini for fresh projects' fp-ts@2.16.9: resolution: {integrity: sha512-+I2+FnVB+tVaxcYyQkHUq7ZdKScaBlX53A41mxQtpIccsfyv8PzdzP7fzp2AY832T4aoK6UZ5WRX/ebGd8uZuQ==} @@ -25881,6 +25882,7 @@ packages: node-domexception@1.0.0: resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==} engines: {node: '>=10.5.0'} + deprecated: Use your platform's native DOMException instead node-fetch-h2@2.3.0: resolution: {integrity: sha512-ofRW94Ab0T4AOh5Fk8t0h8OBWrmjb0SSB20xh1H8YnPV9EJ+f5AMoYSUQ2zgJ4Iq2HAK0I2l5/Nequ8YzFS3Hg==}