Skip to content

Commit 0129ef7

Browse files
authored
[Components] plaid - new components (#16586)
1 parent a03e487 commit 0129ef7

File tree

19 files changed

+1036
-28
lines changed

19 files changed

+1036
-28
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import app from "../../plaid.app.mjs";
2+
3+
export default {
4+
key: "plaid-create-access-token",
5+
name: "Create Access Token",
6+
description: "Exchange a Link `public_token` for an API `access_token`. [See the documentation](https://plaid.com/docs/api/items/#itempublic_tokenexchange).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
publicToken: {
12+
propDefinition: [
13+
app,
14+
"publicToken",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const {
20+
app,
21+
publicToken,
22+
} = this;
23+
24+
const response = await app.exchangePublicToken({
25+
public_token: publicToken,
26+
});
27+
28+
$.export("$summary", "Successfully created access token for public token");
29+
30+
return response;
31+
},
32+
};
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import app from "../../plaid.app.mjs";
2+
import institutions from "../../common/sandbox-institutions.mjs";
3+
4+
export default {
5+
key: "plaid-create-sandbox-public-token",
6+
name: "Create Sandbox Public Token",
7+
description: "Creates a valid `public_token` for an arbitrary institution ID, initial products, and test credentials. [See the documentation](https://plaid.com/docs/api/sandbox/#sandboxpublic_tokencreate).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
institutionId: {
13+
type: "string",
14+
label: "Institution ID",
15+
description: "The ID of the institution the Item will be associated with",
16+
options: Object.values(institutions),
17+
},
18+
initialProducts: {
19+
type: "string[]",
20+
label: "Initial Products",
21+
description: "The products to initially pull for the Item. May be any products that the specified institution supports.",
22+
options: [
23+
"assets",
24+
"auth",
25+
"balance",
26+
"employment",
27+
"identity",
28+
"income_verification",
29+
"identity_verification",
30+
"investments",
31+
"liabilities",
32+
"payment_initiation",
33+
"standing_orders",
34+
"statements",
35+
"transactions",
36+
"transfer",
37+
],
38+
},
39+
webhookUrl: {
40+
type: "string",
41+
label: "Webhook URL",
42+
description: "The URL to which Plaid should send webhook notifications. You must configure at least one webhook to enable webhooks.",
43+
optional: true,
44+
},
45+
userToken: {
46+
type: "string",
47+
label: "User Token",
48+
description: "The user token associated with the User data is being requested for.",
49+
optional: true,
50+
},
51+
},
52+
async run({ $ }) {
53+
const {
54+
app,
55+
institutionId,
56+
initialProducts,
57+
webhookUrl,
58+
userToken,
59+
} = this;
60+
61+
const response = await app.createSandboxPublicToken({
62+
institution_id: institutionId,
63+
initial_products: initialProducts,
64+
user_token: userToken,
65+
...(
66+
webhookUrl
67+
? {
68+
options: {
69+
webhook: webhookUrl,
70+
},
71+
}
72+
: {}
73+
),
74+
});
75+
76+
$.export("$summary", `Successfully created sandbox public token for institution ${institutionId}`);
77+
78+
return response;
79+
},
80+
};
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import app from "../../plaid.app.mjs";
2+
3+
export default {
4+
key: "plaid-create-user",
5+
name: "Create User",
6+
description: "Creates a user ID and token to be used with Plaid Check, Income, or Multi-Item Link flow. [See the documentation](https://plaid.com/docs/api/users/#usercreate).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
clientUserId: {
12+
type: "string",
13+
label: "Client User ID",
14+
description: "A unique ID representing the end user. Maximum of 128 characters. Typically this will be a user ID number from your application. Personally identifiable information, such as an email address or phone number, should not be used in the client_user_id.",
15+
optional: false,
16+
},
17+
includeConsumerReportUserIdentity: {
18+
type: "boolean",
19+
label: "Include Consumer Report User Identity",
20+
description: "Whether to include the consumer report user identity. This is required for all Plaid Check customers.",
21+
optional: true,
22+
reloadProps: true,
23+
},
24+
},
25+
additionalProps() {
26+
if (!this.includeConsumerReportUserIdentity) {
27+
return {};
28+
}
29+
30+
return {
31+
firstName: {
32+
type: "string",
33+
label: "First Name",
34+
description: "The user's first name",
35+
},
36+
lastName: {
37+
type: "string",
38+
label: "Last Name",
39+
description: "The user's last name",
40+
},
41+
phoneNumbers: {
42+
type: "string[]",
43+
label: "Phone Numbers",
44+
description: "The user's phone number, in E.164 format: +{countrycode}{number}. For example: `+14157452130`. Phone numbers provided in other formats will be parsed on a best-effort basis. Phone number input is validated against valid number ranges; number strings that do not match a real-world phone numbering scheme may cause the request to fail, even in the Sandbox test environment.",
45+
},
46+
emails: {
47+
type: "string[]",
48+
label: "Emails",
49+
description: "The user's emails",
50+
},
51+
ssnLast4: {
52+
type: "string",
53+
label: "SSN Last 4",
54+
description: "The last 4 digits of the user's social security number.",
55+
optional: true,
56+
},
57+
dateOfBirth: {
58+
type: "string",
59+
label: "Date of Birth",
60+
description: "To be provided in the format `yyyy-mm-dd`. This field is required for all Plaid Check customers.",
61+
},
62+
primaryAddressCity: {
63+
type: "string",
64+
label: "City",
65+
description: "The full city name for the primary address",
66+
},
67+
primaryAddressRegion: {
68+
type: "string",
69+
label: "Region/State",
70+
description: "The region or state. Example: `NC`",
71+
},
72+
primaryAddressStreet: {
73+
type: "string",
74+
label: "Street",
75+
description: "The full street address. Example: `564 Main Street, APT 15`",
76+
},
77+
primaryAddressPostalCode: {
78+
type: "string",
79+
label: "Postal Code",
80+
description: "The postal code",
81+
},
82+
primaryAddressCountry: {
83+
type: "string",
84+
label: "Country",
85+
description: "The ISO 3166-1 alpha-2 country code",
86+
},
87+
};
88+
},
89+
async run({ $ }) {
90+
const {
91+
app,
92+
clientUserId,
93+
includeConsumerReportUserIdentity,
94+
firstName,
95+
lastName,
96+
phoneNumbers,
97+
emails,
98+
ssnLast4,
99+
dateOfBirth,
100+
primaryAddressCity,
101+
primaryAddressRegion,
102+
primaryAddressStreet,
103+
primaryAddressPostalCode,
104+
primaryAddressCountry,
105+
} = this;
106+
107+
const response = await app.createUser({
108+
client_user_id: clientUserId,
109+
...(includeConsumerReportUserIdentity
110+
? {
111+
consumer_report_user_identity: {
112+
first_name: firstName,
113+
last_name: lastName,
114+
phone_numbers: phoneNumbers,
115+
emails: emails,
116+
date_of_birth: dateOfBirth,
117+
ssn_last_4: ssnLast4,
118+
primary_address: {
119+
city: primaryAddressCity,
120+
region: primaryAddressRegion,
121+
street: primaryAddressStreet,
122+
postal_code: primaryAddressPostalCode,
123+
country: primaryAddressCountry,
124+
},
125+
},
126+
}
127+
: {}
128+
),
129+
});
130+
131+
$.export("$summary", `Successfully created user with ID \`${response.user_id}\`.`);
132+
133+
return response;
134+
},
135+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import app from "../../plaid.app.mjs";
2+
3+
export default {
4+
key: "plaid-get-real-time-balance",
5+
name: "Get Real-Time Balance",
6+
description: "Get the real-time balance for each of an Item's accounts. [See the documentation](https://plaid.com/docs/api/products/balance/#accountsbalanceget).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
accessToken: {
12+
propDefinition: [
13+
app,
14+
"accessToken",
15+
],
16+
},
17+
accountIds: {
18+
type: "string[]",
19+
label: "Account IDs",
20+
description: "The specific account IDs to filter by. If not provided, all accounts will be returned.",
21+
propDefinition: [
22+
app,
23+
"accountId",
24+
({ accessToken }) => ({
25+
accessToken,
26+
}),
27+
],
28+
},
29+
},
30+
async run({ $ }) {
31+
const {
32+
app,
33+
accessToken,
34+
accountIds,
35+
} = this;
36+
37+
const response = await app.getAccountsBalance({
38+
access_token: accessToken,
39+
options: {
40+
account_ids: accountIds,
41+
},
42+
});
43+
44+
$.export("$summary", "Successfully fetched account balances");
45+
return response;
46+
},
47+
};
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import app from "../../plaid.app.mjs";
2+
3+
export default {
4+
key: "plaid-get-transactions",
5+
name: "Get Transactions",
6+
description: "Retrieves user-authorized transaction data for a specified date range. [See the documentation](https://plaid.com/docs/api/products/transactions/#transactionsget)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
accessToken: {
12+
propDefinition: [
13+
app,
14+
"accessToken",
15+
],
16+
},
17+
startDate: {
18+
propDefinition: [
19+
app,
20+
"startDate",
21+
],
22+
},
23+
endDate: {
24+
propDefinition: [
25+
app,
26+
"endDate",
27+
],
28+
},
29+
accountIds: {
30+
type: "string[]",
31+
label: "Account IDs",
32+
description: "A list of `account_ids` to retrieve for the Item. Note: An error will be returned if a provided `account_id` is not associated with the Item.",
33+
propDefinition: [
34+
app,
35+
"accountId",
36+
({ accessToken }) => ({
37+
accessToken,
38+
}),
39+
],
40+
},
41+
includeOriginalDescription: {
42+
type: "boolean",
43+
label: "Include Original Description",
44+
description: "Include the raw unparsed transaction description from the financial institution.",
45+
default: false,
46+
optional: true,
47+
},
48+
daysRequested: {
49+
type: "integer",
50+
label: "Days Requested",
51+
description: "Number of days of transaction history to request from the financial institution. Only applies when Transactions product hasn't been initialized. Min: 1, Max: 730, Default: 90.",
52+
min: 1,
53+
max: 730,
54+
optional: true,
55+
},
56+
},
57+
async run({ $ }) {
58+
const {
59+
app,
60+
accessToken,
61+
startDate,
62+
endDate,
63+
accountIds,
64+
includeOriginalDescription,
65+
daysRequested,
66+
} = this;
67+
68+
const options = {};
69+
70+
if (accountIds?.length) {
71+
options.account_ids = accountIds;
72+
}
73+
74+
if (includeOriginalDescription !== undefined) {
75+
options.include_original_description = includeOriginalDescription;
76+
}
77+
78+
if (daysRequested) {
79+
options.days_requested = daysRequested;
80+
}
81+
82+
const transactions = await app.paginate({
83+
resourcesFn: app.getTransactions,
84+
resourcesFnArgs: {
85+
access_token: accessToken,
86+
start_date: startDate,
87+
end_date: endDate,
88+
...(Object.keys(options).length > 0 && {
89+
options,
90+
}),
91+
},
92+
resourceName: "transactions",
93+
});
94+
95+
const transactionCount = transactions?.length || 0;
96+
$.export("$summary", `Successfully retrieved ${transactionCount} transactions from ${startDate} to ${endDate}`);
97+
98+
return transactions;
99+
},
100+
};

0 commit comments

Comments
 (0)