@spritz-finance/api-client 0.0.7 → 0.0.9

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
@@ -20,16 +20,64 @@ A Typescript library for interacting with the Spritz Finance API
20
20
 
21
21
  ## Usage
22
22
 
23
+ Your integration key is provided by Spritz and must always be provided.
24
+ The api key is specific to each user,
25
+ and is returned once the user is created. Leave the api key blank if you haven't created the user yet.
26
+
23
27
  ```typescript
24
28
  import { SpritzApiClient, Environment } from '@spritz-finance/api-client'
25
29
 
26
30
  const client = SpritzApiClient.initialize({
27
- environment: Environment.Staging,
28
- apiKey: 'YOUR_USER_API_KEY_HERE',
29
- integrationKey: 'YOUR_INTEGRATION_KEY_HERE',
31
+ environment: Environment.Staging,
32
+ apiKey: 'YOUR_USER_API_KEY_HERE',
33
+ integrationKey: 'YOUR_INTEGRATION_KEY_HERE',
30
34
  })
31
35
  ```
32
36
 
37
+ ## User Creation
38
+
39
+ You start the process by transmitting the user's email address.
40
+
41
+ ```typescript
42
+ // Fetch all bank accounts for the user
43
+ const user = await client.user.createUser({
44
+ email: "bilbo@shiremail.net"
45
+ })
46
+
47
+ // user = {
48
+ // email: "bilbo@shiremail.net"
49
+ // userId: "62d17d3b377dab6c1342136e",
50
+ // apiKey: "ak_ZTBGDcjfdTg3NmYtZDJlZC00ZjYyLThlMDMtZmYwNDJiZDRlMWZm"
51
+ // }
52
+
53
+
54
+ ```
55
+
56
+ Once the user is created, set the api client to use the user's api key:
57
+
58
+ ```typescript
59
+ client.setApiKey(user.apiKey)
60
+ ```
61
+
62
+ Now you're ready to issue requests on behalf of the user.
63
+
64
+ ## Basic User Data
65
+
66
+ Use this to fetch the user's basic data
67
+
68
+ ```typescript
69
+ const userData = await client.user.getCurrentUser()
70
+ ```
71
+
72
+ ## User Verification
73
+
74
+ Use this to get a URL for the user to pass verification, and track the user's verification status.
75
+ You will need to direct the user's browser to go to the provided URL.
76
+
77
+ ```typescript
78
+ const verificationData = await client.user.getUserVerification()
79
+ ```
80
+
33
81
  ## Basic payment flow
34
82
 
35
83
  ```typescript
@@ -41,15 +89,15 @@ const account = bankAccounts[0]
41
89
 
42
90
  // Create a payment request for the selected bank account
43
91
  const paymentRequest = await client.paymentRequest.create({
44
- amount: 100,
45
- accountId: account.id,
46
- network: PaymentNetwork.Ethereum,
47
- });
92
+ amount: 100,
93
+ accountId: account.id,
94
+ network: PaymentNetwork.Ethereum,
95
+ })
48
96
 
49
97
  // Retrieve the transaction data required to issue a blockchain transaction
50
98
  const transactionData = await client.paymentRequest.getWeb3PaymentParams({
51
- paymentRequest,
52
- paymentTokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC on mainnet
99
+ paymentRequest,
100
+ paymentTokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC on mainnet
53
101
  })
54
102
 
55
103
  /**
@@ -58,7 +106,7 @@ const transactionData = await client.paymentRequest.getWeb3PaymentParams({
58
106
  **/
59
107
 
60
108
  // Retrieve the payment issued for the payment request to check the payment status and confirmation
61
- const payment = await client.payment.getForPaymentRequest(paymentRequest.id);
109
+ const payment = await client.payment.getForPaymentRequest(paymentRequest.id)
62
110
  ```
63
111
 
64
112
  ## Bank Accounts
@@ -100,7 +148,7 @@ const bankAccounts = [{
100
148
  },
101
149
  ownedByUser: true,
102
150
  createdAt: "2023-05-03T11:25:02.401Z",
103
- }];
151
+ }]
104
152
  ```
105
153
 
106
154
  ### Add US bank account
@@ -111,13 +159,13 @@ At present, you can only add US bank accounts to a user's account. To add a US b
111
159
  // Input arguments for creating a US bank account
112
160
 
113
161
  export interface USBankAccountInput {
114
- accountNumber: string
115
- email: string
116
- holder: string
117
- name: string
118
- ownedByUser?: boolean | null
119
- routingNumber: string
120
- subType: BankAccountSubType
162
+ accountNumber: string
163
+ email: string
164
+ holder: string
165
+ name: string
166
+ ownedByUser?: boolean | null
167
+ routingNumber: string
168
+ subType: BankAccountSubType
121
169
  }
122
170
  ```
123
171
 
@@ -125,13 +173,13 @@ export interface USBankAccountInput {
125
173
  import { BankAccountType, BankAccountSubType } from '@spritz-finance/api-client'
126
174
 
127
175
  const bankAccounts = await client.bankAccounts.create(BankAccountType.USBankAccount, {
128
- accountNumber: '123456789',
129
- routingNumber: '987654321',
130
- email: 'bilbo@shiremail.net',
131
- holder: 'Bilbo Baggins',
132
- name: 'Precious Savings',
133
- ownedByUser: true,
134
- subType: BankAccountSubType.Savings,
176
+ accountNumber: '123456789',
177
+ routingNumber: '987654321',
178
+ email: 'bilbo@shiremail.net',
179
+ holder: 'Bilbo Baggins',
180
+ name: 'Precious Savings',
181
+ ownedByUser: true,
182
+ subType: BankAccountSubType.Savings,
135
183
  })
136
184
  ```
137
185
 
@@ -247,15 +295,15 @@ const payment = await client.payment.getForPaymentRequest(paymentRequest.id);
247
295
 
248
296
  // Example response
249
297
 
250
- {
251
- id: '6368e3a3ec516e9572bbd23b',
252
- userId: '63d12d3B577fab6c6382136e',
253
- status: 'PENDING',
254
- accountId: '6322445f10d3f4d19c4d72fe',
255
- amount: 100,
256
- feeAmount: null,
257
- createdAt: '2022-11-07T10:53:23.998Z'
258
- }
298
+ {
299
+ id: '6368e3a3ec516e9572bbd23b',
300
+ userId: '63d12d3B577fab6c6382136e',
301
+ status: 'PENDING',
302
+ accountId: '6322445f10d3f4d19c4d72fe',
303
+ amount: 100,
304
+ feeAmount: null,
305
+ createdAt: '2022-11-07T10:53:23.998Z'
306
+ }
259
307
 
260
308
  ```
261
309
 
@@ -573,6 +573,7 @@ interface QueryParams<V = any> {
573
573
  }
574
574
  declare class GraphClient {
575
575
  client: AxiosInstance;
576
+ baseClient: AxiosInstance;
576
577
  constructor(environment: Environment, apiKey: string, integrationKey?: string);
577
578
  query<Q = any, V = any>({ query, variables }: QueryParams<V>): Promise<Q>;
578
579
  }
@@ -647,9 +648,15 @@ declare class PaymentRequestService {
647
648
  }): Promise<Web3PaymentParams>;
648
649
  }
649
650
 
651
+ interface CreateUserResponse {
652
+ userId: string;
653
+ email: string;
654
+ apiKey: string;
655
+ }
650
656
  declare class UserService {
651
657
  private client;
652
658
  constructor(client: GraphClient);
659
+ createUser(email: string): Promise<CreateUserResponse>;
653
660
  getCurrentUser(): Promise<CurrentUser_me>;
654
661
  getUserVerification(): Promise<UserVerification_verification>;
655
662
  }
@@ -660,13 +667,18 @@ type ClientParams = {
660
667
  integrationKey?: string;
661
668
  };
662
669
  declare class SpritzApiClient {
670
+ private apiKey;
671
+ private integrationKey;
672
+ private environment;
663
673
  private client;
664
674
  user: UserService;
665
675
  bankAccount: BankAccountService;
666
676
  paymentRequest: PaymentRequestService;
667
677
  payment: PaymentService;
678
+ constructor(apiKey: string, integrationKey: string, environment: Environment);
668
679
  static initialize({ environment, apiKey, integrationKey }: ClientParams): SpritzApiClient;
669
680
  private init;
681
+ setApiKey(_apiKey: string): this;
670
682
  }
671
683
 
672
684
  export { AccountPayments, AccountPaymentsVariables, AccountPayments_paymentsForAccount, AccountProvider, BankAccountFragment, BankAccountFragment_bankAccountDetails, BankAccountFragment_bankAccountDetails_CanadianBankAccountDetails, BankAccountFragment_bankAccountDetails_USBankAccountDetails, BankAccountFragment_institution, BankAccountSubType, BankAccountType, CreateDirectPaymentInput, CreatePaymentRequestInput, CurrentUser, CurrentUser_me, DirectPaymentStatus, Environment, GetSpritzPayParams, GetSpritzPayParamsVariables, GetSpritzPayParams_spritzPayParams, ModuleStatus, PayableAccountFragment, PayableAccountFragment_BankAccount, PayableAccountFragment_BankAccount_bankAccountDetails, PayableAccountFragment_BankAccount_bankAccountDetails_CanadianBankAccountDetails, PayableAccountFragment_BankAccount_bankAccountDetails_USBankAccountDetails, PayableAccountFragment_BankAccount_institution, PayableAccountFragment_Bill, PayableAccountFragment_Bill_institution, PayableAccountType, PaymentFragment, PaymentNetwork, PaymentRequestFragment, PaymentRequestPayment, PaymentRequestPaymentVariables, PaymentRequestPayment_paymentForPaymentRequest, PaymentStatus, SpritzApiClient, TokenBalanceFragment, TransactionPrice, TransactionPriceVariables, USBankAccountInput, UserBankAccounts, UserBankAccounts_userBankAccounts, UserBankAccounts_userBankAccounts_bankAccountDetails, UserBankAccounts_userBankAccounts_bankAccountDetails_CanadianBankAccountDetails, UserBankAccounts_userBankAccounts_bankAccountDetails_USBankAccountDetails, UserBankAccounts_userBankAccounts_institution, UserFragment, UserPayableAccounts, UserPayableAccounts_payableAccounts, UserPayableAccounts_payableAccounts_BankAccount, UserPayableAccounts_payableAccounts_BankAccount_bankAccountDetails, UserPayableAccounts_payableAccounts_BankAccount_bankAccountDetails_CanadianBankAccountDetails, UserPayableAccounts_payableAccounts_BankAccount_bankAccountDetails_USBankAccountDetails, UserPayableAccounts_payableAccounts_BankAccount_institution, UserPayableAccounts_payableAccounts_Bill, UserPayableAccounts_payableAccounts_Bill_institution, UserVerification, UserVerification_verification, UserVerification_verification_identity, UserVerification_verification_identity_user, WalletTokenBalances, WalletTokenBalancesVariables, WalletTokenBalances_tokenBalances };