Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "method-node",
"version": "1.2.5",
"version": "1.2.6",
"description": "Node.js library for the Method API",
"main": "dist/index.ts",
"module": "dist/index.mjs",
Expand Down
14 changes: 14 additions & 0 deletions src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,20 @@ export default class Resource extends ExtensibleFunction {
return (await this.client.put(path, data)).data.data;
}

protected async _patchWithId<Response, Data>(
id: string,
data: Data,
requestConfig: IRequestConfig = {},
): Promise<Response> {
const _requestConfig = { headers: {} };
if (requestConfig.idempotency_key) {
_requestConfig.headers = {
'Idempotency-Key': requestConfig.idempotency_key,
};
}
return (await this.client.patch(`/${id}`, data, _requestConfig)).data.data;
}

protected async _delete<Response>(id: string): Promise<Response> {
return (await this.client.delete(`/${id}`)).data.data;
}
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Account/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ export const AccountProductStatuses = {
export type TAccountProductStatuses = keyof typeof AccountProductStatuses;

export interface IAccountProduct {
id: string;
name: string;
status: TAccountProductStatuses;
status_error: IResourceError | null;
latest_request_id: string | null;
latest_successful_request_id: string | null;
is_subscribable: boolean;
created_at: string;
updated_at: string;
Expand Down
4 changes: 3 additions & 1 deletion src/resources/Entity/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export interface IEntityConnect {
entity_id: string;
status: TResourceStatus;
accounts: string[] | null;
requested_products: TEntityProductType[];
requested_subscriptions: TEntitySubscriptionNames[];
error: IResourceError | null;
created_at: string;
updated_at: string;
Expand Down Expand Up @@ -259,11 +261,11 @@ export const EntityProductType = {
export type TEntityProductType = keyof typeof EntityProductType;

export interface IEntityProduct {
id: string;
name: string;
status: TEntityProductTypeStatuses;
status_error: IResourceError | null;
latest_request_id: string | null;
latest_successful_request_id: string | null;
is_subscribable: boolean;
created_at: string;
updated_at: string;
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Event/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Resource from '../../resource';
import Configuration, { IResponse } from '../../configuration';
import type { IEventListOpts, EventResourceTypes, IEventDiff } from './types';
import { TWebhookTypes } from '../Webhook';
import type { TWebhookTypes } from '../Webhook/types';

export interface IEvent {
id: string;
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Event/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IResourceListOpts } from '../../resource';
import { TWebhookTypes } from '../Webhook';
import type { TWebhookTypes } from '../Webhook/types';

export const EventResourceTypes = {
account: 'account',
Expand Down
4 changes: 2 additions & 2 deletions src/resources/Simulate/Events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Resource from '../../resource';
import Configuration, { IResponse } from '../../configuration';
import { TWebhookTypes } from '../Webhook';
import Configuration from '../../configuration';
import type { TWebhookTypes } from '../Webhook/types';

export interface ISimulateEventsOpts {
type: TWebhookTypes;
Expand Down
99 changes: 13 additions & 86 deletions src/resources/Webhook/index.ts
Original file line number Diff line number Diff line change
@@ -1,91 +1,6 @@
import Resource, { IRequestConfig } from '../../resource';
import Configuration, { IResponse } from '../../configuration';

export const WebhookTypes = {
payment_create: 'payment.create',
payment_update: 'payment.update',
account_create: 'account.create',
account_update: 'account.update',
entity_update: 'entity.update',
entity_create: 'entity.create',
account_verification_create: 'account_verification.create',
account_verification_update: 'account_verification.update',
payment_reversal_create: 'payment_reversal.create',
payment_reversal_update: 'payment_reversal.update',
connection_create: 'connection.create',
connection_update: 'connection.update',
transaction_create: 'transaction.create',
transaction_update: 'transaction.update',
report_create: 'report.create',
report_update: 'report.update',
product_create: 'product.create',
product_update: 'product.update',
subscription_create: 'subscription.create',
subscription_update: 'subscription.update',
credit_score_create: 'credit_score.create',
credit_score_update: 'credit_score.update',
payoff_create: 'payoff.create',
payoff_update: 'payoff.update',
entity_verification_session_create: 'entity_verification_session.create',
entity_verification_session_update: 'entity_verification_session.update',
connect_create: 'connect.create',
connect_update: 'connect.update',
balance_create: 'balance.create',
balance_update: 'balance.update',
identity_create: 'identity.create',
identity_update: 'identity.update',
account_verification_session_create: 'account_verification_session.create',
account_verification_session_update: 'account_verification_session.update',
card_brand_create: 'card_brand.create',
card_brand_update: 'card_brand.update',
sensitive_create: 'sensitive.create',
sensitive_update: 'sensitive.update',
update_create: 'update.create',
update_update: 'update.update',
attribute_create: 'attribute.create',
attribute_update: 'attribute.update',
account_opened: 'account.opened',
account_closed: 'account.closed',
credit_score_increased: 'credit_score.increased',
credit_score_decreased: 'credit_score.decreased',
attribute_credit_health_credit_card_usage_increased: 'attribute.credit_health_credit_card_usage.increased',
attribute_credit_health_credit_card_usage_decreased: 'attribute.credit_health_credit_card_usage.decreased',
attribute_credit_health_derogatory_marks_increased: 'attribute.credit_health_derogatory_marks.increased',
attribute_credit_health_derogatory_marks_decreased: 'attribute.credit_health_derogatory_marks.decreased',
attribute_credit_health_hard_inquiries_increased: 'attribute.credit_health_hard_inquiries.increased',
attribute_credit_health_hard_inquiries_decreased: 'attribute.credit_health_hard_inquiries.decreased',
attribute_credit_health_total_accounts_increased: 'attribute.credit_health_total_accounts.increased',
attribute_credit_health_total_accounts_decreased: 'attribute.credit_health_total_accounts.decreased',
attribute_credit_health_credit_age_increased: 'attribute.credit_health_credit_age.increased',
attribute_credit_health_credit_age_decreased: 'attribute.credit_health_credit_age.decreased',
attribute_credit_health_payment_history_increased: 'attribute.credit_health_payment_history.increased',
attribute_credit_health_payment_history_decreased: 'attribute.credit_health_payment_history.decreased',
attribute_credit_health_open_accounts_increased: 'attribute.credit_health_open_accounts.increased',
attribute_credit_health_open_accounts_decreased: 'attribute.credit_health_open_accounts.decreased',
} as const;

export type TWebhookTypes = typeof WebhookTypes[keyof typeof WebhookTypes];

export interface IWebhook {
id: string;
type: TWebhookTypes;
url: string;
metadata: {} | null;
created_at: string;
updated_at: string;
expand_event: boolean;
error: object | null;
status: string | null;
};

export interface IWebhookCreateOpts {
type: TWebhookTypes;
url: string;
auth_token?: string;
hmac_secret?: string;
metadata?: {};
expand_event?: boolean;
};
import type { IWebhook, IWebhookCreateOpts, IWebhookUpdateOpts } from './types';

export default class Webhook extends Resource {
constructor(config: Configuration) {
Expand Down Expand Up @@ -126,6 +41,18 @@ export default class Webhook extends Resource {
return super._create<IResponse<IWebhook>, IWebhookCreateOpts>(opts, requestConfig);
}

/**
* Updates the status of the webhook associated with the id.
*
* @param whk_id id of the webhook
* @param opts IWebhookUpdateOpts: https://docs.methodfi.com/api/core/webhooks/update
* @returns Returns the updated Webhook object.
*/

async update(whk_id: string, opts: IWebhookUpdateOpts) {
return super._patchWithId<IResponse<IWebhook>, IWebhookUpdateOpts>(whk_id, opts);
}

/**
* Deletes the webhook associated with the id.
*
Expand Down
100 changes: 100 additions & 0 deletions src/resources/Webhook/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
export const WebhookTypes = {
payment_create: 'payment.create',
payment_update: 'payment.update',
account_create: 'account.create',
account_update: 'account.update',
entity_update: 'entity.update',
entity_create: 'entity.create',
account_verification_create: 'account_verification.create',
account_verification_update: 'account_verification.update',
payment_reversal_create: 'payment_reversal.create',
payment_reversal_update: 'payment_reversal.update',
connection_create: 'connection.create',
connection_update: 'connection.update',
transaction_create: 'transaction.create',
transaction_update: 'transaction.update',
report_create: 'report.create',
report_update: 'report.update',
product_create: 'product.create',
product_update: 'product.update',
subscription_create: 'subscription.create',
subscription_update: 'subscription.update',
credit_score_create: 'credit_score.create',
credit_score_update: 'credit_score.update',
payoff_create: 'payoff.create',
payoff_update: 'payoff.update',
entity_verification_session_create: 'entity_verification_session.create',
entity_verification_session_update: 'entity_verification_session.update',
connect_create: 'connect.create',
connect_update: 'connect.update',
balance_create: 'balance.create',
balance_update: 'balance.update',
identity_create: 'identity.create',
identity_update: 'identity.update',
account_verification_session_create: 'account_verification_session.create',
account_verification_session_update: 'account_verification_session.update',
card_brand_create: 'card_brand.create',
card_brand_update: 'card_brand.update',
sensitive_create: 'sensitive.create',
sensitive_update: 'sensitive.update',
update_create: 'update.create',
update_update: 'update.update',
attribute_create: 'attribute.create',
attribute_update: 'attribute.update',
account_opened: 'account.opened',
account_closed: 'account.closed',
credit_score_increased: 'credit_score.increased',
credit_score_decreased: 'credit_score.decreased',
attribute_credit_health_credit_card_usage_increased: 'attribute.credit_health_credit_card_usage.increased',
attribute_credit_health_credit_card_usage_decreased: 'attribute.credit_health_credit_card_usage.decreased',
attribute_credit_health_derogatory_marks_increased: 'attribute.credit_health_derogatory_marks.increased',
attribute_credit_health_derogatory_marks_decreased: 'attribute.credit_health_derogatory_marks.decreased',
attribute_credit_health_hard_inquiries_increased: 'attribute.credit_health_hard_inquiries.increased',
attribute_credit_health_hard_inquiries_decreased: 'attribute.credit_health_hard_inquiries.decreased',
attribute_credit_health_total_accounts_increased: 'attribute.credit_health_total_accounts.increased',
attribute_credit_health_total_accounts_decreased: 'attribute.credit_health_total_accounts.decreased',
attribute_credit_health_credit_age_increased: 'attribute.credit_health_credit_age.increased',
attribute_credit_health_credit_age_decreased: 'attribute.credit_health_credit_age.decreased',
attribute_credit_health_payment_history_increased: 'attribute.credit_health_payment_history.increased',
attribute_credit_health_payment_history_decreased: 'attribute.credit_health_payment_history.decreased',
attribute_credit_health_open_accounts_increased: 'attribute.credit_health_open_accounts.increased',
attribute_credit_health_open_accounts_decreased: 'attribute.credit_health_open_accounts.decreased',
} as const;

export type TWebhookTypes = typeof WebhookTypes[keyof typeof WebhookTypes];

export const WebhookStatus = {
active: 'active',
disabled: 'disabled',
deleted: 'deleted',
requires_attention: 'requires_attention',
} as const;

export type TWebhookStatus = typeof WebhookStatus[keyof typeof WebhookStatus];

export type TUpdateWebhookStatus = 'active' | 'disabled';

export interface IWebhook {
id: string;
type: TWebhookTypes;
url: string;
metadata: {} | null;
created_at: string;
updated_at: string;
expand_event: boolean;
error: object | null;
status: string | null;
};

export interface IWebhookCreateOpts {
type: TWebhookTypes;
url: string;
auth_token?: string;
hmac_secret?: string;
metadata?: {};
expand_event?: boolean;
};

export interface IWebhookUpdateOpts {
status: TUpdateWebhookStatus;
};
Loading