Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions components/stripe/actions/search-customers/search-customers.mjs
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;
},
};
2 changes: 1 addition & 1 deletion components/stripe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/stripe",
"version": "0.6.3",
"version": "0.6.4",
"description": "Pipedream Stripe Components",
"main": "stripe.app.mjs",
"keywords": [
Expand Down
Loading