@spritz-finance/api-client 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -63,6 +63,11 @@ A Typescript library for interacting with the Spritz Finance API
63
63
  - [Payments](#payments)
64
64
  - [Retrieve the payment for a payment request](#retrieve-the-payment-for-a-payment-request)
65
65
  - [Retrieve all payments for an account](#retrieve-all-payments-for-an-account)
66
+ - [Webhooks](#webhooks)
67
+ - [Supported webhook events](#supported-webhook-events)
68
+ - [Account Events](#account-events)
69
+ - [Payment Events](#payment-events)
70
+ - [Setting up webhooks](#setting-up-webhooks)
66
71
 
67
72
  ## Interacting with the Spritz API
68
73
 
@@ -630,3 +635,50 @@ const payments = await client.payment.listForAccount(account.id)
630
635
  },
631
636
  ]
632
637
  ```
638
+
639
+ ## Webhooks
640
+
641
+ Instead of making a request to get information, webhooks send information to your specified endpoint as soon as an event occurs. Spritz's integration offers a variety of webhook events that can be crucial for maintaining data integrity and responsiveness in applications. Let's dive into how you can best utilize these.
642
+
643
+ ### Supported webhook events
644
+
645
+ Spritz currently supports the following webhook events:
646
+
647
+ #### Account Events
648
+
649
+ - `account.created`: Triggered when a new account is created.
650
+ - `account.updated`: Triggered when details of an account are updated.
651
+ - `account.deleted`: Triggered when an account is deleted.
652
+
653
+ #### Payment Events
654
+
655
+ - `payment.created`: Triggered when a new payment is initiated.
656
+ - `payment.updated`: Triggered when details of a payment are updated.
657
+ - `payment.completed`: Triggered when a payment is successfully completed.
658
+ - `payment.refunded`: Triggered when a payment is refunded.
659
+
660
+ These events allow you to respond to changes in the account and payments for a user.
661
+
662
+ ### Setting up webhooks
663
+
664
+ To set up a webhook with Spritz, you'll need to provide:
665
+
666
+ 1. **URL**: The endpoint URL where Spritz will send the webhook data.
667
+ 2. **Events**: The specific events you want to listen for.
668
+
669
+ ```typescript
670
+ const webhook = await client.webhook.create({
671
+ url: 'https://my.webhook.url/spritz',
672
+ events: ['account.created', 'account.updated', 'account.deleted'],
673
+ })
674
+ ```
675
+
676
+ Upon receiving a webhook, your server will get a payload with the following structure:
677
+
678
+ ```json
679
+ {
680
+ "userId": "user-id-here",
681
+ "id": "resource-id-here",
682
+ "eventName": "name-of-the-event-here"
683
+ }
684
+ ```
@@ -1184,6 +1184,26 @@ declare class VirtualCardService {
1184
1184
  create<T extends VirtualCardType>(type: T, input: CreateInputMapping[T]): Promise<NonNullable<CreateMutationMapping[T]["query"][keyof CreateMutationMapping[T]["query"]]> | null>;
1185
1185
  }
1186
1186
 
1187
+ declare const EVENTS: readonly ["account.created", "account.updated", "account.deleted", "payment.created", "payment.updated", "payment.completed", "payment.refunded"];
1188
+ type WebhookEvent = (typeof EVENTS)[number];
1189
+ type IntegratorWebhook = {
1190
+ id: string;
1191
+ integratorId: string;
1192
+ failureCount: number;
1193
+ events: string[];
1194
+ url: string;
1195
+ createdAt: string;
1196
+ };
1197
+ type CreateWebhookArgs = {
1198
+ url: string;
1199
+ events: WebhookEvent[];
1200
+ };
1201
+ declare class WebhookService {
1202
+ private client;
1203
+ constructor(client: GraphClient);
1204
+ create(args: CreateWebhookArgs): Promise<IntegratorWebhook>;
1205
+ }
1206
+
1187
1207
  type ClientParams = {
1188
1208
  environment: Environment;
1189
1209
  apiKey?: string;
@@ -1201,6 +1221,7 @@ declare class SpritzApiClient {
1201
1221
  virtualCard: VirtualCardService;
1202
1222
  bill: BillService;
1203
1223
  institution: InstitutionService;
1224
+ webhook: WebhookService;
1204
1225
  constructor(apiKey: string, integrationKey: string, environment: Environment);
1205
1226
  static initialize({ environment, apiKey, integrationKey }: ClientParams): SpritzApiClient;
1206
1227
  private init;