@spritz-finance/api-client 0.1.6 → 0.2.0
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 +52 -0
- package/dist/spritz-api-client.d.ts +107 -23
- package/dist/spritz-api-client.js +52 -46
- package/dist/spritz-api-client.mjs +52 -46
- package/package.json +5 -5
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
|
+
```
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
2
1
|
import { DocumentNode } from 'graphql';
|
|
3
2
|
|
|
4
3
|
declare enum Environment {
|
|
@@ -978,15 +977,61 @@ interface RenameBankAccount_renamePayableAccount_BankAccount {
|
|
|
978
977
|
institution: RenameBankAccount_renamePayableAccount_BankAccount_institution | null;
|
|
979
978
|
}
|
|
980
979
|
|
|
980
|
+
type Headers = Record<string, string | null | undefined>;
|
|
981
|
+
|
|
981
982
|
interface QueryParams<V = any> {
|
|
982
983
|
query: DocumentNode;
|
|
983
|
-
variables?: V;
|
|
984
|
+
variables?: V | undefined;
|
|
984
985
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
986
|
+
type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
987
|
+
declare class SpritzClient {
|
|
988
|
+
private baseGraphURL;
|
|
989
|
+
private baseRestURL;
|
|
990
|
+
private timeout;
|
|
991
|
+
private apiKey;
|
|
992
|
+
private integrationKey;
|
|
993
|
+
constructor({ environment, timeout, // 5 minutes
|
|
994
|
+
apiKey, integrationKey, }: {
|
|
995
|
+
environment: Environment;
|
|
996
|
+
timeout?: number | undefined;
|
|
997
|
+
integrationKey: string | undefined;
|
|
998
|
+
apiKey: string | undefined;
|
|
999
|
+
});
|
|
989
1000
|
query<Q = any, V = any>({ query, variables }: QueryParams<V>): Promise<Q>;
|
|
1001
|
+
request<Response, Request extends Record<string, any> = Record<string, any>>({ method, path, body, }: {
|
|
1002
|
+
method: HTTPMethod;
|
|
1003
|
+
path: string;
|
|
1004
|
+
body?: Request | undefined;
|
|
1005
|
+
}): Promise<Response>;
|
|
1006
|
+
sendQuery<V = any>({ query: documentNodeQuery, variables: inputVariables, }: QueryParams<V>): Promise<{
|
|
1007
|
+
response: Response;
|
|
1008
|
+
controller: AbortController;
|
|
1009
|
+
headers: {
|
|
1010
|
+
traceId: string | null;
|
|
1011
|
+
requestId: string | null;
|
|
1012
|
+
};
|
|
1013
|
+
}>;
|
|
1014
|
+
sendRequest({ method, path, body, }: {
|
|
1015
|
+
method: HTTPMethod;
|
|
1016
|
+
path: string;
|
|
1017
|
+
body: Record<string, any> | undefined;
|
|
1018
|
+
}): Promise<{
|
|
1019
|
+
response: Response;
|
|
1020
|
+
controller: AbortController;
|
|
1021
|
+
headers: {
|
|
1022
|
+
traceId: string | null;
|
|
1023
|
+
requestId: string | null;
|
|
1024
|
+
};
|
|
1025
|
+
}>;
|
|
1026
|
+
private sendHTTPRequest;
|
|
1027
|
+
private getResponseHeaders;
|
|
1028
|
+
private fetchWithTimeout;
|
|
1029
|
+
private buildGraphRequest;
|
|
1030
|
+
private buildRestRequest;
|
|
1031
|
+
private defaultHeaders;
|
|
1032
|
+
private calculateContentLength;
|
|
1033
|
+
protected authHeaders(): Headers;
|
|
1034
|
+
private makeStatusError;
|
|
990
1035
|
}
|
|
991
1036
|
|
|
992
1037
|
type CreateInputMapping$1 = {
|
|
@@ -1001,7 +1046,7 @@ type CreateMutationMapping$1 = {
|
|
|
1001
1046
|
};
|
|
1002
1047
|
declare class BankAccountService {
|
|
1003
1048
|
private client;
|
|
1004
|
-
constructor(client:
|
|
1049
|
+
constructor(client: SpritzClient);
|
|
1005
1050
|
list(): Promise<UserBankAccounts_bankAccounts[]>;
|
|
1006
1051
|
rename(accountId: string, name: string): Promise<RenameBankAccount_renamePayableAccount_BankAccount>;
|
|
1007
1052
|
delete(accountId: string): Promise<DeletePayableAccount_deletePayableAccount_BankAccount>;
|
|
@@ -1050,7 +1095,7 @@ interface CreateUSBill_addUSBill {
|
|
|
1050
1095
|
|
|
1051
1096
|
declare class BillService {
|
|
1052
1097
|
private client;
|
|
1053
|
-
constructor(client:
|
|
1098
|
+
constructor(client: SpritzClient);
|
|
1054
1099
|
list(): Promise<UserBills_bills[]>;
|
|
1055
1100
|
rename(accountId: string, name: string): Promise<RenameBankAccount_renamePayableAccount_Bill>;
|
|
1056
1101
|
delete(accountId: string): Promise<DeletePayableAccount_deletePayableAccount_Bill>;
|
|
@@ -1059,14 +1104,14 @@ declare class BillService {
|
|
|
1059
1104
|
|
|
1060
1105
|
declare class InstitutionService {
|
|
1061
1106
|
private client;
|
|
1062
|
-
constructor(client:
|
|
1107
|
+
constructor(client: SpritzClient);
|
|
1063
1108
|
popularUSBillInstitutions(type?: BillType): Promise<PopularBillInstitutions_popularUSBillInstitutions[]>;
|
|
1064
1109
|
searchUSBillInstitutions(searchTerm: string, type?: BillType): Promise<SearchUSBillInstitutions_searchUSBillInstitutions[]>;
|
|
1065
1110
|
}
|
|
1066
1111
|
|
|
1067
1112
|
declare class PaymentService {
|
|
1068
1113
|
private client;
|
|
1069
|
-
constructor(client:
|
|
1114
|
+
constructor(client: SpritzClient);
|
|
1070
1115
|
listForAccount(accountId: string): Promise<AccountPayments_paymentsForAccount[]>;
|
|
1071
1116
|
getForPaymentRequest(paymentRequestId: string): Promise<PaymentRequestPayment_paymentForPaymentRequest | null>;
|
|
1072
1117
|
}
|
|
@@ -1103,16 +1148,15 @@ interface CreatePaymentRequestInput {
|
|
|
1103
1148
|
}
|
|
1104
1149
|
|
|
1105
1150
|
type PaymentRequest = CreatePaymentRequest_createDirectPayment;
|
|
1106
|
-
type Web3PaymentParams = GetSpritzPayParams_spritzPayParams;
|
|
1107
1151
|
declare class PaymentRequestService {
|
|
1108
1152
|
private client;
|
|
1109
|
-
constructor(client:
|
|
1153
|
+
constructor(client: SpritzClient);
|
|
1110
1154
|
create(input: CreatePaymentRequestInput): Promise<CreatePaymentRequest_createDirectPayment>;
|
|
1111
1155
|
transactionPrice(paymentAmount: number): Promise<number>;
|
|
1112
1156
|
getWeb3PaymentParams(input: {
|
|
1113
1157
|
paymentRequest: PaymentRequest;
|
|
1114
1158
|
paymentTokenAddress: string;
|
|
1115
|
-
}): Promise<
|
|
1159
|
+
}): Promise<GetSpritzPayParams_spritzPayParams>;
|
|
1116
1160
|
}
|
|
1117
1161
|
|
|
1118
1162
|
interface CreateUserResponse {
|
|
@@ -1120,14 +1164,14 @@ interface CreateUserResponse {
|
|
|
1120
1164
|
email: string;
|
|
1121
1165
|
apiKey: string;
|
|
1122
1166
|
}
|
|
1123
|
-
interface
|
|
1167
|
+
interface CreateUserParams {
|
|
1124
1168
|
email: string;
|
|
1125
1169
|
}
|
|
1126
1170
|
declare class UserService {
|
|
1127
1171
|
private client;
|
|
1128
|
-
constructor(client:
|
|
1129
|
-
createUser(args:
|
|
1130
|
-
create(args:
|
|
1172
|
+
constructor(client: SpritzClient);
|
|
1173
|
+
createUser(args: CreateUserParams): Promise<CreateUserResponse>;
|
|
1174
|
+
create(args: CreateUserParams): Promise<CreateUserResponse>;
|
|
1131
1175
|
getCurrentUser(): Promise<CurrentUser_me>;
|
|
1132
1176
|
getUserVerification(): Promise<UserVerification_verification | null>;
|
|
1133
1177
|
}
|
|
@@ -1179,20 +1223,59 @@ type CreateMutationMapping = {
|
|
|
1179
1223
|
};
|
|
1180
1224
|
declare class VirtualCardService {
|
|
1181
1225
|
private client;
|
|
1182
|
-
constructor(client:
|
|
1226
|
+
constructor(client: SpritzClient);
|
|
1183
1227
|
fetch(): Promise<UserVirtualDebitCard_virtualDebitCard | null>;
|
|
1184
1228
|
create<T extends VirtualCardType>(type: T, input: CreateInputMapping[T]): Promise<NonNullable<CreateMutationMapping[T]["query"][keyof CreateMutationMapping[T]["query"]]> | null>;
|
|
1185
1229
|
}
|
|
1186
1230
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1231
|
+
declare const EVENTS: readonly ["account.created", "account.updated", "account.deleted", "payment.created", "payment.updated", "payment.completed", "payment.refunded"];
|
|
1232
|
+
type WebhookEvent = (typeof EVENTS)[number];
|
|
1233
|
+
type IntegratorWebhook = {
|
|
1234
|
+
id: string;
|
|
1235
|
+
integratorId: string;
|
|
1236
|
+
failureCount: number;
|
|
1237
|
+
events: string[];
|
|
1238
|
+
url: string;
|
|
1239
|
+
createdAt: string;
|
|
1240
|
+
};
|
|
1241
|
+
type CreateWebhookParams = {
|
|
1242
|
+
url: string;
|
|
1243
|
+
events: WebhookEvent[];
|
|
1244
|
+
};
|
|
1245
|
+
declare class WebhookService {
|
|
1246
|
+
private client;
|
|
1247
|
+
constructor(client: SpritzClient);
|
|
1248
|
+
create(args: CreateWebhookParams): Promise<IntegratorWebhook>;
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
type ClientOptions = {
|
|
1252
|
+
/**
|
|
1253
|
+
* Defaults to Environment.Staging.
|
|
1254
|
+
*/
|
|
1255
|
+
environment?: Environment;
|
|
1189
1256
|
apiKey?: string;
|
|
1190
1257
|
integrationKey?: string;
|
|
1258
|
+
/**
|
|
1259
|
+
* The client will wait up to a specified duration (in milliseconds)
|
|
1260
|
+
* for a response from the server before considering a single request as timed out.
|
|
1261
|
+
*
|
|
1262
|
+
* Please be aware that requests are automatically retried by default.
|
|
1263
|
+
* This means that in some situations, the actual wait time could exceed the set timeout
|
|
1264
|
+
* before the process is either completed or terminated.
|
|
1265
|
+
*/
|
|
1266
|
+
timeout?: number;
|
|
1267
|
+
/**
|
|
1268
|
+
* For security reasons, using this library on the client-side is not recommended
|
|
1269
|
+
* because it could potentially reveal your confidential Integrator Key.
|
|
1270
|
+
* Please enable this option to 'true' only if you're fully aware of the risks and
|
|
1271
|
+
* have implemented the necessary protective measures.
|
|
1272
|
+
*/
|
|
1273
|
+
dangerouslyAllowBrowser?: boolean;
|
|
1191
1274
|
};
|
|
1192
1275
|
declare class SpritzApiClient {
|
|
1276
|
+
private environment;
|
|
1193
1277
|
private apiKey;
|
|
1194
1278
|
private integrationKey;
|
|
1195
|
-
private environment;
|
|
1196
1279
|
private client;
|
|
1197
1280
|
user: UserService;
|
|
1198
1281
|
bankAccount: BankAccountService;
|
|
@@ -1201,8 +1284,9 @@ declare class SpritzApiClient {
|
|
|
1201
1284
|
virtualCard: VirtualCardService;
|
|
1202
1285
|
bill: BillService;
|
|
1203
1286
|
institution: InstitutionService;
|
|
1204
|
-
|
|
1205
|
-
|
|
1287
|
+
webhook: WebhookService;
|
|
1288
|
+
constructor(environment: Environment, apiKey?: string, integrationKey?: string, dangerouslyAllowBrowser?: boolean);
|
|
1289
|
+
static initialize({ environment, apiKey, integrationKey, dangerouslyAllowBrowser, }: ClientOptions): SpritzApiClient;
|
|
1206
1290
|
private init;
|
|
1207
1291
|
setApiKey(_apiKey: string): this;
|
|
1208
1292
|
}
|