diff --git a/src/resource.ts b/src/resource.ts index 5a5a447..6dff085 100644 --- a/src/resource.ts +++ b/src/resource.ts @@ -206,17 +206,19 @@ export default class Resource extends ExtensibleFunction { return (await this.client.get('', { params })).data.data; } - protected async _create( + protected async _create( data: Data, + params?: Params, requestConfig: IRequestConfig = {}, ): Promise { - const _requestConfig = { headers: {} }; - if (requestConfig.idempotency_key) { - _requestConfig.headers = { - 'Idempotency-Key': requestConfig.idempotency_key, - }; - } - return (await this.client.post('', data, _requestConfig)).data.data; + const config = { + headers: requestConfig.idempotency_key + ? { 'Idempotency-Key': requestConfig.idempotency_key } + : {}, + params, + }; + + return (await this.client.post('', data, config)).data.data; } protected async _createWithSubPath( diff --git a/src/resources/Account/types.ts b/src/resources/Account/types.ts index a4e26fe..6e2e8da 100644 --- a/src/resources/Account/types.ts +++ b/src/resources/Account/types.ts @@ -299,11 +299,13 @@ export interface IAccountBalance { }; export interface IAccountCardBrandInfo { - art_id: string; + id: string; + art_id?: string; url: string; name: string; }; + export interface IAccountCardBrand { id: string; account_id: string; @@ -311,7 +313,7 @@ export interface IAccountCardBrand { issuer: string | null; last4: string | null; brands: IAccountCardBrandInfo[]; - status: 'completed' | 'failed'; + status: 'in_progress' | 'completed' | 'failed'; shared: boolean; source: 'method' | 'network' | null; error: IResourceError | null; diff --git a/src/resources/Entity/Connect.ts b/src/resources/Entity/Connect.ts index 35a3a4e..d64fc09 100644 --- a/src/resources/Entity/Connect.ts +++ b/src/resources/Entity/Connect.ts @@ -2,6 +2,50 @@ import Resource, { IResourceListOpts } from '../../resource'; import Configuration, { IResponse } from '../../configuration'; import type { IEntityConnect } from './types'; +// Expandable fields +export const AccountExpandableFields = { + sensitive: 'sensitive', + balance: 'balance', + card_brand: 'card_brand', + attribute: 'attribute', + payoff: 'payoff', + transaction: 'transaction', + update: 'update', + payment_instrument: 'payment_instrument', + latest_verification_session: 'latest_verification_session', +} as const; + +type AccountExpandableField = typeof AccountExpandableFields[keyof typeof AccountExpandableFields]; + +export interface IExpandableOpts { + expand?: AccountExpandableField[]; +} + +export interface IConnectListOpts extends IResourceListOpts, IExpandableOpts {} + +export const AccountProductsEligibleForAutomaticExecution = [ + 'account_attribute', + 'balance', + 'card_brand', + 'update', + 'payoff', +] as const; + +export const AccountSubscriptionsEligibleForAutomaticExecution = [ + 'card_brand', + 'update', + 'update.snapshot', + 'transaction', +] as const; + +export type AccountProduct = typeof AccountProductsEligibleForAutomaticExecution[number]; +export type AccountSubscription = typeof AccountSubscriptionsEligibleForAutomaticExecution[number]; + +export interface IConnectCreateOpts { + products?: AccountProduct[]; + subscriptions?: AccountSubscription[]; +} + export default class EntityConnect extends Resource { constructor(config: Configuration) { super(config.addPath('connect')); @@ -14,8 +58,8 @@ export default class EntityConnect extends Resource { * @returns Returns a Connect object. */ - async retrieve(cxn_id: string) { - return super._getWithId>(cxn_id); + async retrieve(cxn_id: string, opts: IExpandableOpts = {}) { + return super._getWithSubPathAndParams>(cxn_id, opts); } /** @@ -24,7 +68,7 @@ export default class EntityConnect extends Resource { * @returns Returns a list of Connect objects. */ - async list(opts?: IResourceListOpts) { + async list(opts?: IConnectListOpts) { return super._list>(opts); } @@ -34,7 +78,8 @@ export default class EntityConnect extends Resource { * @returns Returns a Connect object. */ - async create() { - return super._create, {}>({}); + async create(opts: IConnectCreateOpts = {}, params: IExpandableOpts = {}) { + return super._create, IConnectCreateOpts, IExpandableOpts>(opts, params); } + }; diff --git a/test/resources/Account.tests.ts b/test/resources/Account.tests.ts index 4f3b656..e13bbb5 100644 --- a/test/resources/Account.tests.ts +++ b/test/resources/Account.tests.ts @@ -1,4 +1,4 @@ -import { should } from 'chai'; +import { should, expect } from 'chai'; import { describe } from 'mocha'; import { client } from '../config'; import { awaitResults } from '../utils'; @@ -299,7 +299,7 @@ describe('Accounts - core methods tests', () => { id: card_create_response.id, account_id: test_credit_card_account.id, network: 'visa', - status: 'completed', + status: 'in_progress', issuer: card_create_response.issuer, last4: '1580', brands: card_create_response.brands, @@ -311,6 +311,7 @@ describe('Accounts - core methods tests', () => { }; card_create_response.should.be.eql(expect_results); + await new Promise(r => setTimeout(r, 5000)); }); it('should successfully retrieve a card for an account.', async () => { @@ -319,22 +320,24 @@ describe('Accounts - core methods tests', () => { .cardBrands .retrieve(card_create_response.id); - const expect_results: IAccountCardBrand = { - id: card_create_response.id, - account_id: test_credit_card_account.id, - network: 'visa', - status: 'completed', - issuer: card_retrieve_response.issuer, - last4: '1580', - brands: card_create_response.brands, - shared: false, - source: card_retrieve_response.source, - error: null, - created_at: card_retrieve_response.created_at, - updated_at: card_retrieve_response.updated_at - }; - - card_retrieve_response.should.be.eql(expect_results); + expect(card_retrieve_response.id).to.equal(card_create_response.id); + expect(card_retrieve_response.account_id).to.equal(test_credit_card_account.id); + expect(card_retrieve_response.network).to.equal('visa'); + expect(card_retrieve_response.status).to.equal('completed'); + expect(card_retrieve_response.issuer).to.equal(card_create_response.issuer); + expect(card_retrieve_response.last4).to.equal('1580'); + expect(card_retrieve_response.shared).to.equal(false); + expect(card_retrieve_response.source).to.equal('network'); + expect(card_retrieve_response.error).to.be.null; + expect(card_retrieve_response.created_at).to.be.a('string'); + expect(card_retrieve_response.updated_at).to.be.a('string'); + + const brand = card_retrieve_response.brands?.[0]; + expect(brand).to.exist; + expect(brand.id).to.equal('brand_UBwVzXjpP4PJ6'); + expect(brand.name).to.equal('Chase Sapphire Reserve'); + expect(brand.url).to.equal('https://static.methodfi.com/card_brands/1b7ccaba6535cb837f802d968add4700.png'); + expect(brand.art_id).to.be.a('string').and.match(/^art_/); }); it('should successfully list card brands for an account.', async () => { @@ -346,8 +349,26 @@ describe('Accounts - core methods tests', () => { }; const card_brands = await awaitResults(listCardBrands); - - card_brands[0].should.be.eql(card_create_response); + const result = card_brands[0]; + + expect(result.id).to.equal(card_create_response.id); + expect(result.account_id).to.equal(test_credit_card_account.id); + expect(result.network).to.equal('visa'); + expect(result.status).to.equal('completed'); + expect(result.issuer).to.equal(card_create_response.issuer); + expect(result.last4).to.equal('1580'); + expect(result.shared).to.equal(false); + expect(result.source).to.equal('network'); + expect(result.error).to.be.null; + expect(result.created_at).to.be.a('string'); + expect(result.updated_at).to.be.a('string'); + + const brand = result.brands?.[0]; + expect(brand).to.exist; + expect(brand.id).to.equal('brand_UBwVzXjpP4PJ6'); + expect(brand.name).to.equal('Chase Sapphire Reserve'); + expect(brand.url).to.equal('https://static.methodfi.com/card_brands/1b7ccaba6535cb837f802d968add4700.png'); + expect(brand.art_id).to.be.a('string').and.match(/^art_/); }); }); diff --git a/test/resources/Report.tests.ts b/test/resources/Report.tests.ts index cda4257..1091f75 100644 --- a/test/resources/Report.tests.ts +++ b/test/resources/Report.tests.ts @@ -23,7 +23,7 @@ describe('Reports - core methods tests', () => { type: 'payments.created.current', url: `https://dev.methodfi.com/reports/${reports_create_response.id}/download`, status: 'completed', - metadata: null, + metadata: reports_create_response.metadata, created_at: reports_create_response.created_at, updated_at: reports_create_response.updated_at, }; @@ -41,7 +41,7 @@ describe('Reports - core methods tests', () => { type: 'payments.created.current', url: `https://dev.methodfi.com/reports/${reports_create_response.id}/download`, status: 'completed', - metadata: null, + metadata: reports_create_response.metadata, created_at: reports_retrieve_response.created_at, updated_at: reports_retrieve_response.updated_at, };