@financeable/aggregation 0.3.4 → 0.4.2

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.
Files changed (102) hide show
  1. package/FUNCTIONS.md +119 -6
  2. package/README.md +1585 -568
  3. package/docs/sdks/applications/README.md +16 -14
  4. package/docs/sdks/financeable/README.md +0 -84
  5. package/docs/sdks/oauthtoken/README.md +90 -0
  6. package/funcs/applicationsCreate.d.ts +1 -1
  7. package/funcs/applicationsCreate.d.ts.map +1 -1
  8. package/funcs/applicationsCreate.js +1 -1
  9. package/funcs/applicationsCreate.js.map +1 -1
  10. package/funcs/applicationsGet.d.ts +1 -1
  11. package/funcs/applicationsGet.d.ts.map +1 -1
  12. package/funcs/applicationsGet.js +1 -1
  13. package/funcs/applicationsGet.js.map +1 -1
  14. package/funcs/applicationsList.d.ts +1 -1
  15. package/funcs/applicationsList.d.ts.map +1 -1
  16. package/funcs/applicationsList.js +1 -1
  17. package/funcs/applicationsList.js.map +1 -1
  18. package/funcs/{getToken.d.ts → oauthTokenOauthToken.d.ts} +2 -2
  19. package/funcs/oauthTokenOauthToken.d.ts.map +1 -0
  20. package/funcs/{getToken.js → oauthTokenOauthToken.js} +3 -3
  21. package/funcs/oauthTokenOauthToken.js.map +1 -0
  22. package/jsr.json +1 -1
  23. package/lib/config.d.ts +7 -7
  24. package/lib/config.d.ts.map +1 -1
  25. package/lib/config.js +4 -4
  26. package/lib/files.js.map +1 -1
  27. package/lib/primitives.d.ts +3 -0
  28. package/lib/primitives.d.ts.map +1 -1
  29. package/lib/primitives.js +7 -0
  30. package/lib/primitives.js.map +1 -1
  31. package/lib/sdks.d.ts.map +1 -1
  32. package/lib/sdks.js +2 -8
  33. package/lib/sdks.js.map +1 -1
  34. package/models/components/assetattributes.d.ts +17 -94
  35. package/models/components/assetattributes.d.ts.map +1 -1
  36. package/models/components/assetattributes.js +27 -37
  37. package/models/components/assetattributes.js.map +1 -1
  38. package/models/components/commercialassettype.d.ts +44 -0
  39. package/models/components/commercialassettype.d.ts.map +1 -0
  40. package/models/components/commercialassettype.js +85 -0
  41. package/models/components/commercialassettype.js.map +1 -0
  42. package/models/components/consumerassettype.d.ts +32 -0
  43. package/models/components/consumerassettype.d.ts.map +1 -0
  44. package/models/components/consumerassettype.js +73 -0
  45. package/models/components/consumerassettype.js.map +1 -0
  46. package/models/components/customerattributes.d.ts +12 -2
  47. package/models/components/customerattributes.d.ts.map +1 -1
  48. package/models/components/customerattributes.js +4 -0
  49. package/models/components/customerattributes.js.map +1 -1
  50. package/models/components/index.d.ts +2 -0
  51. package/models/components/index.d.ts.map +1 -1
  52. package/models/components/index.js +2 -0
  53. package/models/components/index.js.map +1 -1
  54. package/models/errors/index.d.ts +1 -3
  55. package/models/errors/index.d.ts.map +1 -1
  56. package/models/errors/index.js +1 -3
  57. package/models/errors/index.js.map +1 -1
  58. package/models/errors/responsebody.d.ts +38 -0
  59. package/models/errors/responsebody.d.ts.map +1 -0
  60. package/models/errors/{getapplication.js → responsebody.js} +15 -15
  61. package/models/errors/responsebody.js.map +1 -0
  62. package/package.json +1 -1
  63. package/sdk/oauthtoken.d.ts +9 -0
  64. package/sdk/oauthtoken.d.ts.map +1 -0
  65. package/sdk/oauthtoken.js +19 -0
  66. package/sdk/oauthtoken.js.map +1 -0
  67. package/sdk/sdk.d.ts +4 -6
  68. package/sdk/sdk.d.ts.map +1 -1
  69. package/sdk/sdk.js +3 -7
  70. package/sdk/sdk.js.map +1 -1
  71. package/src/funcs/applicationsCreate.ts +4 -4
  72. package/src/funcs/applicationsGet.ts +4 -4
  73. package/src/funcs/applicationsList.ts +4 -4
  74. package/src/funcs/{getToken.ts → oauthTokenOauthToken.ts} +1 -1
  75. package/src/lib/config.ts +7 -7
  76. package/src/lib/files.ts +1 -1
  77. package/src/lib/primitives.ts +14 -0
  78. package/src/lib/sdks.ts +2 -7
  79. package/src/models/components/assetattributes.ts +58 -47
  80. package/src/models/components/commercialassettype.ts +61 -0
  81. package/src/models/components/consumerassettype.ts +43 -0
  82. package/src/models/components/customerattributes.ts +16 -2
  83. package/src/models/components/index.ts +2 -0
  84. package/src/models/errors/index.ts +1 -3
  85. package/src/models/errors/{getapplication.ts → responsebody.ts} +20 -20
  86. package/src/sdk/oauthtoken.ts +24 -0
  87. package/src/sdk/sdk.ts +5 -16
  88. package/funcs/getToken.d.ts.map +0 -1
  89. package/funcs/getToken.js.map +0 -1
  90. package/models/errors/createapplication.d.ts +0 -38
  91. package/models/errors/createapplication.d.ts.map +0 -1
  92. package/models/errors/createapplication.js +0 -81
  93. package/models/errors/createapplication.js.map +0 -1
  94. package/models/errors/getapplication.d.ts +0 -38
  95. package/models/errors/getapplication.d.ts.map +0 -1
  96. package/models/errors/getapplication.js.map +0 -1
  97. package/models/errors/getapplications.d.ts +0 -38
  98. package/models/errors/getapplications.d.ts.map +0 -1
  99. package/models/errors/getapplications.js +0 -81
  100. package/models/errors/getapplications.js.map +0 -1
  101. package/src/models/errors/createapplication.ts +0 -76
  102. package/src/models/errors/getapplications.ts +0 -76
package/README.md CHANGED
@@ -1,24 +1,23 @@
1
1
  # financeable-aggregation-api
2
2
 
3
-
4
3
  ## Summary
5
4
 
6
-
7
5
  ## Table of Contents
8
6
 
9
- * [financeable-aggregation-api](#financeable-aggregation-api)
10
- * [SDK Installation](#sdk-installation)
11
- * [Requirements](#requirements)
12
- * [SDK Example Usage](#sdk-example-usage)
13
- * [Available Resources and Operations](#available-resources-and-operations)
14
- * [Standalone functions](#standalone-functions)
15
- * [Retries](#retries)
16
- * [Error Handling](#error-handling)
17
- * [Server Selection](#server-selection)
18
- * [Custom HTTP Client](#custom-http-client)
19
- * [Debugging](#debugging)
7
+ - [financeable-aggregation-api](#financeable-aggregation-api)
8
+ - [SDK Installation](#sdk-installation)
9
+ - [Requirements](#requirements)
10
+ - [SDK Example Usage](#sdk-example-usage)
11
+ - [Available Resources and Operations](#available-resources-and-operations)
12
+ - [Standalone functions](#standalone-functions)
13
+ - [Retries](#retries)
14
+ - [Error Handling](#error-handling)
15
+ - [Server Selection](#server-selection)
16
+ - [Custom HTTP Client](#custom-http-client)
17
+ - [Debugging](#debugging)
20
18
 
21
19
  ## SDK Installation
20
+
22
21
  The SDK can be installed with either [npm](https://www.npmjs.com/), [pnpm](https://pnpm.io/), [bun](https://bun.sh/) or [yarn](https://classic.yarnpkg.com/en/) package managers.
23
22
 
24
23
  ### NPM
@@ -56,142 +55,160 @@ For supported JavaScript runtimes, please consult [RUNTIMES.md](RUNTIMES.md).
56
55
 
57
56
  ```typescript
58
57
  import { Financeable } from "@financeable/aggregation";
58
+ import { ConsumerAssetType } from "@financeable/aggregation/models/components"
59
59
 
60
- const financeable = new Financeable();
60
+ const financeable = new Financeable({
61
+ serverURL: "<Server_URL>
62
+ });
61
63
 
62
64
  async function run() {
63
- const result = await financeable.applications.create({
64
- data: {
65
- type: "applications",
66
- attributes: {
67
- purpose: "Purchase of a motor vehicle",
68
- applicationType: "consumer",
69
- },
70
- relationships: {
71
- loanDetails: {
72
- data: {
73
- type: "loan-details",
74
- attributes: {
75
- repayments: 12,
76
- repaymentFrequency: "monthly",
77
- repaymentStructure: "group-payments",
78
- loanAmount: "10280.95",
79
- purpose: "Purchase of a motor vehicle",
80
- term: 48,
81
- balloon: 5,
82
- deposit: "2500",
83
- originationFee: 200,
84
- rate: "0.15",
85
- rateAdjustment: "-0.01",
86
- },
65
+
66
+ const tokenRequest = await financeable.oauthToken.get({
67
+ grantType: 'client_credentials',
68
+ clientId: '<ClientId>',
69
+ clientSecret: '<ClientSecret>',
70
+ scope: 'application:read application:write',
71
+ });
72
+
73
+ const result = await financeable.applications.create(
74
+ {
75
+ data: {
76
+ type: 'applications',
77
+ attributes: {
78
+ purpose: 'Purchase of a motor vehicle',
79
+ applicationType: 'consumer',
87
80
  },
88
- },
89
- customers: {
90
- data: [
91
- {
92
- id: "<id>",
93
- type: "customers",
94
- attributes: {
95
- title: "Mr",
96
- firstName: "John",
97
- lastName: "Smith",
98
- dateOfBirth: "01-01-1990",
99
- idExpiryDate: "01-01-2025",
100
- idType: "licence",
101
- idNumber: "12345678",
81
+ relationships: {
82
+ loanDetails: {
83
+ data: {
84
+ type: 'loan-details',
85
+ attributes: {
86
+ repayments: 12,
87
+ repaymentFrequency: 'monthly',
88
+ repaymentStructure: 'group-payments',
89
+ loanAmount: '10280.95',
90
+ purpose: 'Purchase of a motor vehicle',
91
+ term: 48,
92
+ balloon: 5,
93
+ deposit: '2500',
94
+ originationFee: 200,
95
+ rate: '0.15',
96
+ rateAdjustment: '-0.01',
97
+ },
102
98
  },
103
- relationships: {
104
- addresses: {
105
- data: [
106
- {
107
- id: "<id>",
108
- type: "addresses",
109
- attributes: {
110
- addressType: "residential",
111
- fullAddress: "42 Wallaby Way, Sydney NSW 2000",
112
- city: "Sydney",
113
- postCode: "2000",
114
- streetAddress: "42 Wallaby Way",
115
- addressLine2: "",
116
- streetNumber: "42",
117
- streetType: "Way",
118
- street: "Wallaby",
119
- state: "NSW",
120
- country: "Australia",
121
- status: "current",
122
- monthsAt: 24,
123
- yearsAt: 2,
124
- },
125
- },
126
- {
127
- id: "<id>",
128
- type: "addresses",
129
- attributes: {
130
- addressType: "residential",
131
- fullAddress: "42 Wallaby Way, Sydney NSW 2000",
132
- city: "Sydney",
133
- postCode: "2000",
134
- streetAddress: "42 Wallaby Way",
135
- addressLine2: "",
136
- streetNumber: "42",
137
- streetType: "Way",
138
- street: "Wallaby",
139
- state: "NSW",
140
- country: "Australia",
141
- status: "current",
142
- monthsAt: 24,
143
- yearsAt: 2,
144
- },
99
+ },
100
+ customers: {
101
+ data: [
102
+ {
103
+ type: 'customers',
104
+ attributes: {
105
+ title: 'Mr',
106
+ firstName: 'John',
107
+ emailAddresses: ["john.smith@mrandmrssmith.com.au"],
108
+ phoneNumbers: ["0412345678"],
109
+ lastName: 'Smith',
110
+ dateOfBirth: '1990-01-28',
111
+ idExpiryDate: '2025-11-15',
112
+ idType: 'licence',
113
+ idNumber: '12345678',
114
+ },
115
+ relationships: {
116
+ addresses: {
117
+ data: [
118
+ {
119
+ type: 'addresses',
120
+ attributes: {
121
+ addressType: 'residential',
122
+ fullAddress: '42 Wallaby Way, Sydney NSW 2000',
123
+ city: 'Sydney',
124
+ postCode: '2000',
125
+ streetAddress: '42 Wallaby Way',
126
+ addressLine2: '',
127
+ streetNumber: '42',
128
+ streetType: 'Way',
129
+ street: 'Wallaby',
130
+ state: 'NSW',
131
+ country: 'Australia',
132
+ status: 'current',
133
+ monthsAt: 6,
134
+ yearsAt: 2,
135
+ },
136
+ },
137
+ {
138
+ type: 'addresses',
139
+ attributes: {
140
+ addressType: 'residential',
141
+ fullAddress: '28 Wallaby Way, Sydney NSW 2000',
142
+ city: 'Sydney',
143
+ postCode: '2000',
144
+ streetAddress: '28 Wallaby Way',
145
+ addressLine2: '',
146
+ streetNumber: '28',
147
+ streetType: 'Way',
148
+ street: 'Wallaby',
149
+ state: 'NSW',
150
+ country: 'Australia',
151
+ status: 'previous',
152
+ monthsAt: 0,
153
+ yearsAt: 2,
154
+ },
155
+ },
156
+ ],
145
157
  },
146
- ],
158
+ },
159
+ },
160
+ ],
161
+ },
162
+ asset: {
163
+ data: {
164
+ type: 'assets',
165
+ attributes: {
166
+ assetType: ConsumerAssetType.MotorVehicle,
167
+ ageOfAsset: 3,
168
+ ageOfAssetAtEnd: 8,
169
+ condition: 'USED',
170
+ purpose: 'VEHICLE',
171
+ assetValue: '35000.00',
172
+ make: 'Toyota',
173
+ assetModel: 'Camry',
174
+ registrationNumber: 'ABC123',
175
+ registrationState: 'VIC',
176
+ vin: '1HGCM82633A123456',
177
+ supplierName: 'Mr and Mrs Smith',
178
+ supplierABN: '12345678901',
179
+ supplierAddress: '123 Car Street, Melbourne VIC 3000',
180
+ supplierPhone: '0412345678',
181
+ supplierContactName: 'John Smith',
182
+ supplierEmail: 'john.smith@mrandmrssmith.com.au',
183
+ privateSale: false,
184
+ typeOfSale: 'DEALER',
185
+ description: '2020 Toyota Camry Hybrid SL, Silver, 45,000km',
186
+ netAssetValue: '32000.00',
187
+ isLuxury: false,
188
+ additionalFees: '995.00',
189
+ additionalTaxes: '0.00',
147
190
  },
148
191
  },
149
192
  },
150
- ],
193
+ },
151
194
  },
152
- asset: {
153
- data: {
154
- id: "<id>",
155
- type: "asset",
156
- attributes: {
157
- ageOfAsset: 3,
158
- ageOfAssetAtEnd: 8,
159
- condition: "USED",
160
- assetType: "MOTOR_VEHICLE_(<4.5_TONNES)",
161
- purpose: "VEHICLE",
162
- assetValue: "35000.00",
163
- make: "Toyota",
164
- assetModel: "Camry",
165
- registrationNumber: "ABC123",
166
- registrationState: "VIC",
167
- vin: "1HGCM82633A123456",
168
- supplierName: "Mr and Mrs Smith",
169
- supplierABN: "12345678901",
170
- supplierAddress: "123 Car Street, Melbourne VIC 3000",
171
- supplierPhone: "0412345678",
172
- supplierContactName: "John Smith",
173
- supplierEmail: "john.smith@mrandmrssmith.com.au",
174
- privateSale: false,
175
- typeOfSale: "DEALER",
176
- description: "2020 Toyota Camry Hybrid SL, Silver, 45,000km",
177
- netAssetValue: "32000.00",
178
- isLuxury: false,
179
- additionalFees: "995.00",
180
- additionalTaxes: "0.00",
181
- },
195
+ },
196
+ {
197
+ fetchOptions: {
198
+ headers: {
199
+ authorization: `Bearer ${tokenRequest.accessToken}`,
182
200
  },
183
201
  },
184
202
  },
185
- },
186
- });
203
+ );
187
204
 
188
205
  // Handle the result
189
206
  console.log(result);
190
207
  }
191
208
 
192
209
  run();
193
-
194
210
  ```
211
+
195
212
  ## Available Resources and Operations
196
213
 
197
214
  <details open>
@@ -199,11 +216,7 @@ run();
199
216
 
200
217
  ### [applications](docs/sdks/applications/README.md)
201
218
 
202
- * [create](docs/sdks/applications/README.md#create) - Create an application in the Financeable platform.
203
- * [list](docs/sdks/applications/README.md#list) - Retrieve a list of applications
204
- * [get](docs/sdks/applications/README.md#get) - Retrieve an application by its ID
205
-
206
-
219
+ - [create](docs/sdks/applications/README.md#create) - Create an application in the Financeable platform.
207
220
  </details>
208
221
 
209
222
  ## Standalone functions
@@ -221,171 +234,186 @@ To read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md).
221
234
  <summary>Available standalone functions</summary>
222
235
 
223
236
  - [`applicationsCreate`](docs/sdks/applications/README.md#create) - Create an application in the Financeable platform.
224
- - [`applicationsGet`](docs/sdks/applications/README.md#get) - Retrieve an application by its ID
225
- - [`applicationsList`](docs/sdks/applications/README.md#list) - Retrieve a list of applications
226
237
 
227
238
  </details>
228
239
 
229
240
  ## Retries
230
241
 
231
- Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
242
+ Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
232
243
 
233
244
  To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
245
+
234
246
  ```typescript
235
247
  import { Financeable } from "@financeable/aggregation";
236
248
 
237
- const financeable = new Financeable();
249
+ const financeable = new Financeable({
250
+ serverURL: '<ServerUrl>'
251
+ })
238
252
 
239
253
  async function run() {
240
- const result = await financeable.applications.create({
241
- data: {
242
- type: "applications",
243
- attributes: {
244
- purpose: "Purchase of a motor vehicle",
245
- applicationType: "consumer",
246
- },
247
- relationships: {
248
- loanDetails: {
249
- data: {
250
- type: "loan-details",
251
- attributes: {
252
- repayments: 12,
253
- repaymentFrequency: "monthly",
254
- repaymentStructure: "group-payments",
255
- loanAmount: "10280.95",
256
- purpose: "Purchase of a motor vehicle",
257
- term: 48,
258
- balloon: 5,
259
- deposit: "2500",
260
- originationFee: 200,
261
- rate: "0.15",
262
- rateAdjustment: "-0.01",
263
- },
254
+ const tokenRequest = await financeable.oauthToken.get({
255
+ grantType: 'client_credentials',
256
+ clientId: '<ClientId>',
257
+ clientSecret: '<ClientSecret>',
258
+ scope: 'application:read application:write',
259
+ });
260
+
261
+ const result = await financeable.applications.create(
262
+ {
263
+ data: {
264
+ type: 'applications',
265
+ attributes: {
266
+ purpose: 'Purchase of a motor vehicle',
267
+ applicationType: 'consumer',
264
268
  },
265
- },
266
- customers: {
267
- data: [
268
- {
269
- id: "<id>",
270
- type: "customers",
271
- attributes: {
272
- title: "Mr",
273
- firstName: "John",
274
- lastName: "Smith",
275
- dateOfBirth: "01-01-1990",
276
- idExpiryDate: "01-01-2025",
277
- idType: "licence",
278
- idNumber: "12345678",
269
+ relationships: {
270
+ loanDetails: {
271
+ data: {
272
+ type: 'loan-details',
273
+ attributes: {
274
+ repayments: 12,
275
+ repaymentFrequency: 'monthly',
276
+ repaymentStructure: 'group-payments',
277
+ loanAmount: '10280.95',
278
+ purpose: 'Purchase of a motor vehicle',
279
+ term: 48,
280
+ balloon: 5,
281
+ deposit: '2500',
282
+ originationFee: 200,
283
+ rate: '0.15',
284
+ rateAdjustment: '-0.01',
285
+ },
279
286
  },
280
- relationships: {
281
- addresses: {
282
- data: [
283
- {
284
- id: "<id>",
285
- type: "addresses",
286
- attributes: {
287
- addressType: "residential",
288
- fullAddress: "42 Wallaby Way, Sydney NSW 2000",
289
- city: "Sydney",
290
- postCode: "2000",
291
- streetAddress: "42 Wallaby Way",
292
- addressLine2: "",
293
- streetNumber: "42",
294
- streetType: "Way",
295
- street: "Wallaby",
296
- state: "NSW",
297
- country: "Australia",
298
- status: "current",
299
- monthsAt: 24,
300
- yearsAt: 2,
301
- },
302
- },
303
- {
304
- id: "<id>",
305
- type: "addresses",
306
- attributes: {
307
- addressType: "residential",
308
- fullAddress: "42 Wallaby Way, Sydney NSW 2000",
309
- city: "Sydney",
310
- postCode: "2000",
311
- streetAddress: "42 Wallaby Way",
312
- addressLine2: "",
313
- streetNumber: "42",
314
- streetType: "Way",
315
- street: "Wallaby",
316
- state: "NSW",
317
- country: "Australia",
318
- status: "current",
319
- monthsAt: 24,
320
- yearsAt: 2,
321
- },
287
+ },
288
+ customers: {
289
+ data: [
290
+ {
291
+ type: 'customers',
292
+ attributes: {
293
+ title: 'Mr',
294
+ firstName: 'John',
295
+ emailAddresses: ["john.smith@mrandmrssmith.com.au"],
296
+ phoneNumbers: ["0412345678"],
297
+ lastName: 'Smith',
298
+ dateOfBirth: '1990-01-28',
299
+ idExpiryDate: '2025-11-15',
300
+ idType: 'licence',
301
+ idNumber: '12345678',
302
+ },
303
+ relationships: {
304
+ addresses: {
305
+ data: [
306
+ {
307
+ type: 'addresses',
308
+ attributes: {
309
+ addressType: 'residential',
310
+ fullAddress: '42 Wallaby Way, Sydney NSW 2000',
311
+ city: 'Sydney',
312
+ postCode: '2000',
313
+ streetAddress: '42 Wallaby Way',
314
+ addressLine2: '',
315
+ streetNumber: '42',
316
+ streetType: 'Way',
317
+ street: 'Wallaby',
318
+ state: 'NSW',
319
+ country: 'Australia',
320
+ status: 'current',
321
+ monthsAt: 6,
322
+ yearsAt: 2,
323
+ },
324
+ },
325
+ {
326
+ type: 'addresses',
327
+ attributes: {
328
+ addressType: 'residential',
329
+ fullAddress: '28 Wallaby Way, Sydney NSW 2000',
330
+ city: 'Sydney',
331
+ postCode: '2000',
332
+ streetAddress: '28 Wallaby Way',
333
+ addressLine2: '',
334
+ streetNumber: '28',
335
+ streetType: 'Way',
336
+ street: 'Wallaby',
337
+ state: 'NSW',
338
+ country: 'Australia',
339
+ status: 'previous',
340
+ monthsAt: 0,
341
+ yearsAt: 2,
342
+ },
343
+ },
344
+ ],
322
345
  },
323
- ],
346
+ },
347
+ },
348
+ ],
349
+ },
350
+ asset: {
351
+ data: {
352
+ type: 'assets',
353
+ attributes: {
354
+ assetType: ConsumerAssetType.MotorVehicle,
355
+ ageOfAsset: 3,
356
+ ageOfAssetAtEnd: 8,
357
+ condition: 'USED',
358
+ purpose: 'VEHICLE',
359
+ assetValue: '35000.00',
360
+ make: 'Toyota',
361
+ assetModel: 'Camry',
362
+ registrationNumber: 'ABC123',
363
+ registrationState: 'VIC',
364
+ vin: '1HGCM82633A123456',
365
+ supplierName: 'Mr and Mrs Smith',
366
+ supplierABN: '12345678901',
367
+ supplierAddress: '123 Car Street, Melbourne VIC 3000',
368
+ supplierPhone: '0412345678',
369
+ supplierContactName: 'John Smith',
370
+ supplierEmail: 'john.smith@mrandmrssmith.com.au',
371
+ privateSale: false,
372
+ typeOfSale: 'DEALER',
373
+ description: '2020 Toyota Camry Hybrid SL, Silver, 45,000km',
374
+ netAssetValue: '32000.00',
375
+ isLuxury: false,
376
+ additionalFees: '995.00',
377
+ additionalTaxes: '0.00',
324
378
  },
325
379
  },
326
380
  },
327
- ],
381
+ },
328
382
  },
329
- asset: {
330
- data: {
331
- id: "<id>",
332
- type: "asset",
333
- attributes: {
334
- ageOfAsset: 3,
335
- ageOfAssetAtEnd: 8,
336
- condition: "USED",
337
- assetType: "MOTOR_VEHICLE_(<4.5_TONNES)",
338
- purpose: "VEHICLE",
339
- assetValue: "35000.00",
340
- make: "Toyota",
341
- assetModel: "Camry",
342
- registrationNumber: "ABC123",
343
- registrationState: "VIC",
344
- vin: "1HGCM82633A123456",
345
- supplierName: "Mr and Mrs Smith",
346
- supplierABN: "12345678901",
347
- supplierAddress: "123 Car Street, Melbourne VIC 3000",
348
- supplierPhone: "0412345678",
349
- supplierContactName: "John Smith",
350
- supplierEmail: "john.smith@mrandmrssmith.com.au",
351
- privateSale: false,
352
- typeOfSale: "DEALER",
353
- description: "2020 Toyota Camry Hybrid SL, Silver, 45,000km",
354
- netAssetValue: "32000.00",
355
- isLuxury: false,
356
- additionalFees: "995.00",
357
- additionalTaxes: "0.00",
358
- },
383
+ },
384
+ {
385
+ fetchOptions: {
386
+ headers: {
387
+ authorization: `Bearer ${tokenRequest.accessToken}`,
359
388
  },
360
389
  },
390
+ retries: {
391
+ strategy: "backoff",
392
+ backoff: {
393
+ initialInterval: 1,
394
+ maxInterval: 50,
395
+ exponent: 1.1,
396
+ maxElapsedTime: 100,
397
+ },
398
+ retryConnectionErrors: false,
399
+ }
361
400
  },
362
- },
363
- }, {
364
- retries: {
365
- strategy: "backoff",
366
- backoff: {
367
- initialInterval: 1,
368
- maxInterval: 50,
369
- exponent: 1.1,
370
- maxElapsedTime: 100,
371
- },
372
- retryConnectionErrors: false,
373
- },
374
- });
401
+ );
375
402
 
376
403
  // Handle the result
377
404
  console.log(result);
378
405
  }
379
406
 
380
407
  run();
381
-
382
408
  ```
383
409
 
384
410
  If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
411
+
385
412
  ```typescript
386
413
  import { Financeable } from "@financeable/aggregation";
387
414
 
388
415
  const financeable = new Financeable({
416
+ serverURL: "<ServerURL>",
389
417
  retryConfig: {
390
418
  strategy: "backoff",
391
419
  backoff: {
@@ -399,6 +427,673 @@ const financeable = new Financeable({
399
427
  });
400
428
 
401
429
  async function run() {
430
+ const tokenRequest = await financeable.oauthToken.get({
431
+ grantType: 'client_credentials',
432
+ clientId: '<ClientId>',
433
+ clientSecret: '<ClientSecret>',
434
+ scope: 'application:read application:write',
435
+ });
436
+
437
+ const result = await financeable.applications.create(
438
+ {
439
+ data: {
440
+ type: 'applications',
441
+ attributes: {
442
+ purpose: 'Purchase of a motor vehicle',
443
+ applicationType: 'consumer',
444
+ },
445
+ relationships: {
446
+ loanDetails: {
447
+ data: {
448
+ type: 'loan-details',
449
+ attributes: {
450
+ repayments: 12,
451
+ repaymentFrequency: 'monthly',
452
+ repaymentStructure: 'group-payments',
453
+ loanAmount: '10280.95',
454
+ purpose: 'Purchase of a motor vehicle',
455
+ term: 48,
456
+ balloon: 5,
457
+ deposit: '2500',
458
+ originationFee: 200,
459
+ rate: '0.15',
460
+ rateAdjustment: '-0.01',
461
+ },
462
+ },
463
+ },
464
+ customers: {
465
+ data: [
466
+ {
467
+ type: 'customers',
468
+ attributes: {
469
+ title: 'Mr',
470
+ firstName: 'John',
471
+ emailAddresses: ["john.smith@mrandmrssmith.com.au"],
472
+ phoneNumbers: ["0412345678"],
473
+ lastName: 'Smith',
474
+ dateOfBirth: '1990-01-28',
475
+ idExpiryDate: '2025-11-15',
476
+ idType: 'licence',
477
+ idNumber: '12345678',
478
+ },
479
+ relationships: {
480
+ addresses: {
481
+ data: [
482
+ {
483
+ type: 'addresses',
484
+ attributes: {
485
+ addressType: 'residential',
486
+ fullAddress: '42 Wallaby Way, Sydney NSW 2000',
487
+ city: 'Sydney',
488
+ postCode: '2000',
489
+ streetAddress: '42 Wallaby Way',
490
+ addressLine2: '',
491
+ streetNumber: '42',
492
+ streetType: 'Way',
493
+ street: 'Wallaby',
494
+ state: 'NSW',
495
+ country: 'Australia',
496
+ status: 'current',
497
+ monthsAt: 6,
498
+ yearsAt: 2,
499
+ },
500
+ },
501
+ {
502
+ type: 'addresses',
503
+ attributes: {
504
+ addressType: 'residential',
505
+ fullAddress: '28 Wallaby Way, Sydney NSW 2000',
506
+ city: 'Sydney',
507
+ postCode: '2000',
508
+ streetAddress: '28 Wallaby Way',
509
+ addressLine2: '',
510
+ streetNumber: '28',
511
+ streetType: 'Way',
512
+ street: 'Wallaby',
513
+ state: 'NSW',
514
+ country: 'Australia',
515
+ status: 'previous',
516
+ monthsAt: 0,
517
+ yearsAt: 2,
518
+ },
519
+ },
520
+ ],
521
+ },
522
+ },
523
+ },
524
+ ],
525
+ },
526
+ asset: {
527
+ data: {
528
+ type: 'assets',
529
+ attributes: {
530
+ assetType: ConsumerAssetType.MotorVehicle,
531
+ ageOfAsset: 3,
532
+ ageOfAssetAtEnd: 8,
533
+ condition: 'USED',
534
+ purpose: 'VEHICLE',
535
+ assetValue: '35000.00',
536
+ make: 'Toyota',
537
+ assetModel: 'Camry',
538
+ registrationNumber: 'ABC123',
539
+ registrationState: 'VIC',
540
+ vin: '1HGCM82633A123456',
541
+ supplierName: 'Mr and Mrs Smith',
542
+ supplierABN: '12345678901',
543
+ supplierAddress: '123 Car Street, Melbourne VIC 3000',
544
+ supplierPhone: '0412345678',
545
+ supplierContactName: 'John Smith',
546
+ supplierEmail: 'john.smith@mrandmrssmith.com.au',
547
+ privateSale: false,
548
+ typeOfSale: 'DEALER',
549
+ description: '2020 Toyota Camry Hybrid SL, Silver, 45,000km',
550
+ netAssetValue: '32000.00',
551
+ isLuxury: false,
552
+ additionalFees: '995.00',
553
+ additionalTaxes: '0.00',
554
+ },
555
+ },
556
+ },
557
+ },
558
+ },
559
+ },
560
+ {
561
+ fetchOptions: {
562
+ headers: {
563
+ authorization: `Bearer ${tokenRequest.accessToken}`,
564
+ },
565
+ }
566
+ },
567
+ );
568
+
569
+ // Handle the result
570
+ console.log(result);
571
+ }
572
+
573
+ run();
574
+ ```
575
+
576
+ ## Error Handling
577
+
578
+ Some methods specify known errors which can be thrown. All the known errors are enumerated in the `models/errors/errors.ts` module. The known errors for a method are documented under the _Errors_ tables in SDK docs. For example, the `create` method may throw the following errors:
579
+
580
+ | Error Type | Status Code | Content Type |
581
+ | ------------------------------------ | ----------- | ---------------- |
582
+ | errors.CreateApplicationResponseBody | 403 | application/json |
583
+ | errors.APIError | 4XX, 5XX | \*/\* |
584
+
585
+ If the method throws an error and it is not captured by the known errors, it will default to throwing a `APIError`.
586
+
587
+ ```typescript
588
+ import { Financeable } from "@financeable/aggregation";
589
+ import {
590
+ CreateApplicationResponseBody,
591
+ SDKValidationError,
592
+ } from "@financeable/aggregation/models/errors";
593
+ import { ConsumerAssetType } from "@financeable/aggregation/models/components"
594
+
595
+ const financeable = new Financeable({
596
+ serverURL: "<ServerURL>"
597
+ });
598
+
599
+ async function run() {
600
+ let result;
601
+ try {
602
+ const tokenRequest = await financeable.oauthToken.get({
603
+ grantType: 'client_credentials',
604
+ clientId: '<ClientId>',
605
+ clientSecret: '<ClientSecret>',
606
+ scope: 'application:read application:write',
607
+ });
608
+
609
+ result = await financeable.applications.create({
610
+ data: {
611
+ type: "applications",
612
+ attributes: {
613
+ purpose: "Purchase of a motor vehicle",
614
+ applicationType: "consumer",
615
+ },
616
+ relationships: {
617
+ loanDetails: {
618
+ data: {
619
+ type: "loan-details",
620
+ attributes: {
621
+ repayments: 12,
622
+ repaymentFrequency: "monthly",
623
+ repaymentStructure: "group-payments",
624
+ loanAmount: "10280.95",
625
+ purpose: "Purchase of a motor vehicle",
626
+ term: 48,
627
+ balloon: 5,
628
+ deposit: "2500",
629
+ originationFee: 200,
630
+ rate: "0.15",
631
+ rateAdjustment: "-0.01",
632
+ },
633
+ },
634
+ },
635
+ customers: {
636
+ data: [
637
+ {
638
+ type: "customers",
639
+ attributes: {
640
+ title: "Mr",
641
+ firstName: "John",
642
+ lastName: "Smith",
643
+ dateOfBirth: "1982-06-21",
644
+ idExpiryDate: "2030-03-15",
645
+ idType: "licence",
646
+ idNumber: "12345678",
647
+ },
648
+ relationships: {
649
+ addresses: {
650
+ data: [
651
+ {
652
+ type: "addresses",
653
+ attributes: {
654
+ addressType: "residential",
655
+ fullAddress: "42 Wallaby Way, Sydney NSW 2000",
656
+ city: "Sydney",
657
+ postCode: "2000",
658
+ streetAddress: "42 Wallaby Way",
659
+ addressLine2: "",
660
+ streetNumber: "42",
661
+ streetType: "Way",
662
+ street: "Wallaby",
663
+ state: "NSW",
664
+ country: "Australia",
665
+ status: "current",
666
+ monthsAt: 5,
667
+ yearsAt: 2,
668
+ },
669
+ },
670
+ {
671
+ type: "addresses",
672
+ attributes: {
673
+ addressType: "residential",
674
+ fullAddress: "28 Wallaby Way, Sydney NSW 2000",
675
+ city: "Sydney",
676
+ postCode: "2000",
677
+ streetAddress: "28 Wallaby Way",
678
+ addressLine2: "",
679
+ streetNumber: "28",
680
+ streetType: "Way",
681
+ street: "Wallaby",
682
+ state: "NSW",
683
+ country: "Australia",
684
+ status: "previous",
685
+ monthsAt: 0,
686
+ yearsAt: 5,
687
+ },
688
+ },
689
+ ],
690
+ },
691
+ },
692
+ },
693
+ ],
694
+ },
695
+ asset: {
696
+ data: {
697
+ type: "asset",
698
+ attributes: {
699
+ ageOfAsset: 3,
700
+ ageOfAssetAtEnd: 8,
701
+ condition: "USED",
702
+ assetType: ConsumerAssetType.MotorVehicle,
703
+ purpose: "VEHICLE",
704
+ assetValue: "35000.00",
705
+ make: "Toyota",
706
+ assetModel: "Camry",
707
+ registrationNumber: "ABC123",
708
+ registrationState: "VIC",
709
+ vin: "1HGCM82633A123456",
710
+ supplierName: "Mr and Mrs Smith",
711
+ supplierABN: "12345678901",
712
+ supplierAddress: "123 Car Street, Melbourne VIC 3000",
713
+ supplierPhone: "0412345678",
714
+ supplierContactName: "John Smith",
715
+ supplierEmail: "john.smith@mrandmrssmith.com.au",
716
+ privateSale: false,
717
+ typeOfSale: "DEALER",
718
+ description: "2020 Toyota Camry Hybrid SL, Silver, 45,000km",
719
+ netAssetValue: "32000.00",
720
+ isLuxury: false,
721
+ additionalFees: "995.00",
722
+ additionalTaxes: "0.00",
723
+ },
724
+ },
725
+ },
726
+ },
727
+ },
728
+ {
729
+ fetchOptions: {
730
+ headers: {
731
+ authorization: `Bearer ${tokenRequest.accessToken}`,
732
+ },
733
+ }
734
+ }
735
+ });
736
+
737
+ // Handle the result
738
+ console.log(result);
739
+ } catch (err) {
740
+ switch (true) {
741
+ // The server response does not match the expected SDK schema
742
+ case err instanceof SDKValidationError: {
743
+ // Pretty-print will provide a human-readable multi-line error message
744
+ console.error(err.pretty());
745
+ // Raw value may also be inspected
746
+ console.error(err.rawValue);
747
+ return;
748
+ }
749
+ case err instanceof CreateApplicationResponseBody: {
750
+ // Handle err.data$: CreateApplicationResponseBodyData
751
+ console.error(err);
752
+ return;
753
+ }
754
+ default: {
755
+ // Other errors such as network errors, see HTTPClientErrors for more details
756
+ throw err;
757
+ }
758
+ }
759
+ }
760
+ }
761
+
762
+ run();
763
+ ```
764
+
765
+ Validation errors can also occur when either method arguments or data returned from the server do not match the expected format. The `SDKValidationError` that is thrown as a result will capture the raw value that failed validation in an attribute called `rawValue`. Additionally, a `pretty()` method is available on this error that can be used to log a nicely formatted multi-line string since validation errors can list many issues and the plain error string may be difficult read when debugging.
766
+
767
+ In some rare cases, the SDK can fail to get a response from the server or even make the request due to unexpected circumstances such as network conditions. These types of errors are captured in the `models/errors/httpclienterrors.ts` module:
768
+
769
+ | HTTP Client Error | Description |
770
+ | --------------------- | ---------------------------------------------------- |
771
+ | RequestAbortedError | HTTP request was aborted by the client |
772
+ | RequestTimeoutError | HTTP request timed out due to an AbortSignal signal |
773
+ | ConnectionError | HTTP client was unable to make a request to a server |
774
+ | InvalidRequestError | Any input used to create a request is invalid |
775
+ | UnexpectedClientError | Unrecognised or unexpected error |
776
+
777
+ ## Server Selection
778
+
779
+ ### Override Server URL Per-Client
780
+
781
+ The default server can also be overridden globally by passing a URL to the `serverURL: string` optional parameter when initializing the SDK client instance. For example:
782
+
783
+ ```typescript
784
+ import { Financeable } from "@financeable/aggregation";
785
+
786
+ const financeable = new Financeable({
787
+ serverURL: "https://dev.server.api.financeable.com.au",
788
+ });
789
+
790
+ async function run() {
791
+ const tokenRequest = await financeable.oauthToken.get({
792
+ grantType: 'client_credentials',
793
+ clientId: '<ClientId>',
794
+ clientSecret: '<ClientSecret>',
795
+ scope: 'application:read application:write',
796
+ });
797
+
798
+ const result = await financeable.applications.create({
799
+ data: {
800
+ type: "applications",
801
+ attributes: {
802
+ purpose: "Purchase of a motor vehicle",
803
+ applicationType: "consumer",
804
+ },
805
+ relationships: {
806
+ loanDetails: {
807
+ data: {
808
+ type: "loan-details",
809
+ attributes: {
810
+ repayments: 12,
811
+ repaymentFrequency: "monthly",
812
+ repaymentStructure: "group-payments",
813
+ loanAmount: "10280.95",
814
+ purpose: "Purchase of a motor vehicle",
815
+ term: 48,
816
+ balloon: 5,
817
+ deposit: "2500",
818
+ originationFee: 200,
819
+ rate: "0.15",
820
+ rateAdjustment: "-0.01",
821
+ },
822
+ },
823
+ },
824
+ customers: {
825
+ data: [
826
+ {
827
+ type: "customers",
828
+ attributes: {
829
+ title: "Mr",
830
+ firstName: "John",
831
+ lastName: "Smith",
832
+ dateOfBirth: "1950-04-20",
833
+ idExpiryDate: "2029-06-13",
834
+ idType: "licence",
835
+ idNumber: "12345678",
836
+ },
837
+ relationships: {
838
+ addresses: {
839
+ data: [
840
+ {
841
+ type: "addresses",
842
+ attributes: {
843
+ addressType: "residential",
844
+ fullAddress: "42 Wallaby Way, Sydney NSW 2000",
845
+ city: "Sydney",
846
+ postCode: "2000",
847
+ streetAddress: "42 Wallaby Way",
848
+ addressLine2: "",
849
+ streetNumber: "42",
850
+ streetType: "Way",
851
+ street: "Wallaby",
852
+ state: "NSW",
853
+ country: "Australia",
854
+ status: "current",
855
+ monthsAt: 11,
856
+ yearsAt: 2,
857
+ },
858
+ },
859
+ {
860
+ type: "addresses",
861
+ attributes: {
862
+ addressType: "residential",
863
+ fullAddress: "42 Wallaby Way, Sydney NSW 2000",
864
+ city: "Sydney",
865
+ postCode: "2000",
866
+ streetAddress: "42 Wallaby Way",
867
+ addressLine2: "",
868
+ streetNumber: "42",
869
+ streetType: "Way",
870
+ street: "Wallaby",
871
+ state: "NSW",
872
+ country: "Australia",
873
+ status: "previous",
874
+ monthsAt: 2,
875
+ yearsAt: 2,
876
+ },
877
+ },
878
+ ],
879
+ },
880
+ },
881
+ },
882
+ ],
883
+ },
884
+ asset: {
885
+ data: {
886
+ type: "assets",
887
+ attributes: {
888
+ ageOfAsset: 3,
889
+ ageOfAssetAtEnd: 8,
890
+ condition: "USED",
891
+ assetType: ConsumerAssetType.MotorVehicle,
892
+ purpose: "VEHICLE",
893
+ assetValue: "35000.00",
894
+ make: "Toyota",
895
+ assetModel: "Camry",
896
+ registrationNumber: "ABC123",
897
+ registrationState: "VIC",
898
+ vin: "1HGCM82633A123456",
899
+ supplierName: "Mr and Mrs Smith",
900
+ supplierABN: "12345678901",
901
+ supplierAddress: "123 Car Street, Melbourne VIC 3000",
902
+ supplierPhone: "0412345678",
903
+ supplierContactName: "John Smith",
904
+ supplierEmail: "john.smith@mrandmrssmith.com.au",
905
+ privateSale: false,
906
+ typeOfSale: "DEALER",
907
+ description: "2020 Toyota Camry Hybrid SL, Silver, 45,000km",
908
+ netAssetValue: "32000.00",
909
+ isLuxury: false,
910
+ additionalFees: "995.00",
911
+ additionalTaxes: "0.00",
912
+ },
913
+ },
914
+ },
915
+ },
916
+ }},
917
+ {
918
+ fetchOptions: {
919
+ headers: {
920
+ authorization: `Bearer ${tokenRequest.accessToken}`,
921
+ },
922
+ }
923
+ },
924
+ );
925
+
926
+ // Handle the result
927
+ console.log(result);
928
+ }
929
+
930
+ run();
931
+ ```
932
+
933
+ ## Custom HTTP Client
934
+
935
+ The TypeScript SDK makes API calls using an `HTTPClient` that wraps the native
936
+ [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). This
937
+ client is a thin wrapper around `fetch` and provides the ability to attach hooks
938
+ around the request lifecycle that can be used to modify the request or handle
939
+ errors and response.
940
+
941
+ The `HTTPClient` constructor takes an optional `fetcher` argument that can be
942
+ used to integrate a third-party HTTP client or when writing tests to mock out
943
+ the HTTP client and feed in fixtures.
944
+
945
+ The following example shows how to use the `"beforeRequest"` hook to to add a
946
+ custom header and a timeout to requests and how to use the `"requestError"` hook
947
+ to log errors:
948
+
949
+ ```typescript
950
+ import { Financeable } from "@financeable/aggregation";
951
+ import { HTTPClient } from "@financeable/aggregation/lib/http";
952
+
953
+ const httpClient = new HTTPClient({
954
+ // fetcher takes a function that has the same signature as native `fetch`.
955
+ fetcher: (request) => {
956
+ return fetch(request);
957
+ },
958
+ });
959
+
960
+ httpClient.addHook("beforeRequest", (request) => {
961
+ const nextRequest = new Request(request, {
962
+ signal: request.signal || AbortSignal.timeout(5000),
963
+ });
964
+
965
+ nextRequest.headers.set("x-custom-header", "custom value");
966
+
967
+ return nextRequest;
968
+ });
969
+
970
+ httpClient.addHook("requestError", (error, request) => {
971
+ console.group("Request Error");
972
+ console.log("Reason:", `${error}`);
973
+ console.log("Endpoint:", `${request.method} ${request.url}`);
974
+ console.groupEnd();
975
+ });
976
+
977
+ const sdk = new Financeable({ httpClient });
978
+ ```
979
+
980
+ ## Debugging
981
+
982
+ You can setup your SDK to emit debug logs for SDK requests and responses.
983
+
984
+ You can pass a logger that matches `console`'s interface as an SDK option.
985
+
986
+ > [!WARNING]
987
+ > Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
988
+
989
+ ```typescript
990
+ import { Financeable } from "@financeable/aggregation";
991
+
992
+ const sdk = new Financeable({ debugLogger: console });
993
+ ```
994
+
995
+ You can also enable a default debug logger by setting an environment variable `FINANCEABLE_DEBUG` to true.
996
+
997
+ <!-- Start Summary [summary] -->
998
+
999
+ ## Summary
1000
+
1001
+ <!-- End Summary [summary] -->
1002
+
1003
+ <!-- Start Table of Contents [toc] -->
1004
+
1005
+ ## Table of Contents
1006
+
1007
+ <!-- $toc-max-depth=2 -->
1008
+
1009
+ - [financeable-aggregation-api](#financeable-aggregation-api)
1010
+ - [SDK Installation](#sdk-installation)
1011
+ - [Requirements](#requirements)
1012
+ - [SDK Example Usage](#sdk-example-usage)
1013
+ - [Available Resources and Operations](#available-resources-and-operations)
1014
+ - [Standalone functions](#standalone-functions)
1015
+ - [Retries](#retries)
1016
+ - [Error Handling](#error-handling)
1017
+ - [Server Selection](#server-selection)
1018
+ - [Custom HTTP Client](#custom-http-client)
1019
+ - [Debugging](#debugging)
1020
+ - [SDK Installation](#sdk-installation-1)
1021
+ - [Requirements](#requirements-1)
1022
+ - [SDK Example Usage](#sdk-example-usage-1)
1023
+ - [Authentication](#authentication)
1024
+ - [Available Resources and Operations](#available-resources-and-operations-1)
1025
+ - [Standalone functions](#standalone-functions-1)
1026
+ - [Retries](#retries-1)
1027
+ - [Error Handling](#error-handling-1)
1028
+ - [Server Selection](#server-selection-1)
1029
+ - [Custom HTTP Client](#custom-http-client-1)
1030
+ - [Debugging](#debugging-1)
1031
+
1032
+ <!-- End Table of Contents [toc] -->
1033
+
1034
+ <!-- Start SDK Installation [installation] -->
1035
+
1036
+ ## SDK Installation
1037
+
1038
+ The SDK can be installed with either [npm](https://www.npmjs.com/), [pnpm](https://pnpm.io/), [bun](https://bun.sh/) or [yarn](https://classic.yarnpkg.com/en/) package managers.
1039
+
1040
+ ### NPM
1041
+
1042
+ ```bash
1043
+ npm add @financeable/aggregation
1044
+ ```
1045
+
1046
+ ### PNPM
1047
+
1048
+ ```bash
1049
+ pnpm add @financeable/aggregation
1050
+ ```
1051
+
1052
+ ### Bun
1053
+
1054
+ ```bash
1055
+ bun add @financeable/aggregation
1056
+ ```
1057
+
1058
+ ### Yarn
1059
+
1060
+ ```bash
1061
+ yarn add @financeable/aggregation zod
1062
+
1063
+ # Note that Yarn does not install peer dependencies automatically. You will need
1064
+ # to install zod as shown above.
1065
+ ```
1066
+
1067
+ <!-- End SDK Installation [installation] -->
1068
+
1069
+ <!-- Start Requirements [requirements] -->
1070
+
1071
+ ## Requirements
1072
+
1073
+ For supported JavaScript runtimes, please consult [RUNTIMES.md](RUNTIMES.md).
1074
+
1075
+ <!-- End Requirements [requirements] -->
1076
+
1077
+ ## SDK Example Usage
1078
+
1079
+ ### Example
1080
+
1081
+ ```typescript
1082
+ import { Financeable } from "@financeable/aggregation";
1083
+ import { ConsumerAssetType } from "@financeable/aggregation/models/components"
1084
+
1085
+ const financeable = new Financeable({
1086
+ serverURL: '<ServerURL>',
1087
+ });
1088
+
1089
+ async function run() {
1090
+ const tokenRequest = await financeable.oauthToken.get({
1091
+ grantType: 'client_credentials',
1092
+ clientId: '<ClientId>',
1093
+ clientSecret: '<ClientSecret>',
1094
+ scope: 'application:read application:write',
1095
+ });
1096
+
402
1097
  const result = await financeable.applications.create({
403
1098
  data: {
404
1099
  type: "applications",
@@ -428,22 +1123,18 @@ async function run() {
428
1123
  customers: {
429
1124
  data: [
430
1125
  {
431
- id: "<id>",
432
1126
  type: "customers",
433
1127
  attributes: {
434
1128
  title: "Mr",
435
1129
  firstName: "John",
436
1130
  lastName: "Smith",
437
- dateOfBirth: "01-01-1990",
438
- idExpiryDate: "01-01-2025",
439
- idType: "licence",
440
- idNumber: "12345678",
1131
+ dateOfBirth: "1990-06-28",
1132
+ idExpiryDate: "<value>",
441
1133
  },
442
1134
  relationships: {
443
1135
  addresses: {
444
1136
  data: [
445
1137
  {
446
- id: "<id>",
447
1138
  type: "addresses",
448
1139
  attributes: {
449
1140
  addressType: "residential",
@@ -458,12 +1149,11 @@ async function run() {
458
1149
  state: "NSW",
459
1150
  country: "Australia",
460
1151
  status: "current",
461
- monthsAt: 24,
1152
+ monthsAt: 6,
462
1153
  yearsAt: 2,
463
1154
  },
464
1155
  },
465
1156
  {
466
- id: "<id>",
467
1157
  type: "addresses",
468
1158
  attributes: {
469
1159
  addressType: "residential",
@@ -477,9 +1167,9 @@ async function run() {
477
1167
  street: "Wallaby",
478
1168
  state: "NSW",
479
1169
  country: "Australia",
480
- status: "current",
481
- monthsAt: 24,
482
- yearsAt: 2,
1170
+ status: "previous",
1171
+ monthsAt: 0,
1172
+ yearsAt: 5,
483
1173
  },
484
1174
  },
485
1175
  ],
@@ -490,13 +1180,12 @@ async function run() {
490
1180
  },
491
1181
  asset: {
492
1182
  data: {
493
- id: "<id>",
494
- type: "asset",
1183
+ type: "assets",
495
1184
  attributes: {
496
1185
  ageOfAsset: 3,
497
1186
  ageOfAssetAtEnd: 8,
498
1187
  condition: "USED",
499
- assetType: "MOTOR_VEHICLE_(<4.5_TONNES)",
1188
+ assetType: ConsumerAssetType.MotorVehicle,
500
1189
  purpose: "VEHICLE",
501
1190
  assetValue: "35000.00",
502
1191
  make: "Toyota",
@@ -522,6 +1211,13 @@ async function run() {
522
1211
  },
523
1212
  },
524
1213
  },
1214
+ {
1215
+ fetchOptions: {
1216
+ headers: {
1217
+ authorization: `Bearer ${tokenRequest.accessToken}`,
1218
+ },
1219
+ },
1220
+ },
525
1221
  });
526
1222
 
527
1223
  // Handle the result
@@ -531,30 +1227,81 @@ async function run() {
531
1227
  run();
532
1228
 
533
1229
  ```
534
- ## Error Handling
535
1230
 
536
- Some methods specify known errors which can be thrown. All the known errors are enumerated in the `models/errors/errors.ts` module. The known errors for a method are documented under the *Errors* tables in SDK docs. For example, the `create` method may throw the following errors:
1231
+ <!-- No End SDK Example Usage [usage] -->
537
1232
 
538
- | Error Type | Status Code | Content Type |
539
- | ------------------------------------ | ----------- | ---------------- |
540
- | errors.CreateApplicationResponseBody | 403 | application/json |
541
- | errors.APIError | 4XX, 5XX | \*/\* |
1233
+ <!-- No End Authentication [security] -->
542
1234
 
543
- If the method throws an error and it is not captured by the known errors, it will default to throwing a `APIError`.
1235
+ <!-- Start Available Resources and Operations [operations] -->
1236
+
1237
+ ## Available Resources and Operations
1238
+
1239
+ <details open>
1240
+ <summary>Available methods</summary>
1241
+
1242
+ ### [applications](docs/sdks/applications/README.md)
1243
+
1244
+ - [create](docs/sdks/applications/README.md#create) - Create an application in the Financeable platform.
1245
+ - [list](docs/sdks/applications/README.md#list) - Retrieve a list of applications
1246
+ - [get](docs/sdks/applications/README.md#get) - Retrieve an application by its ID
1247
+
1248
+ ### [oauthToken](docs/sdks/oauthtoken/README.md)
1249
+
1250
+ - [get](docs/sdks/oauthtoken/README.md#get) - Obtain an OAuth client_credentials token
1251
+
1252
+ </details>
1253
+ <!-- End Available Resources and Operations [operations] -->
1254
+
1255
+ <!-- Start Standalone functions [standalone-funcs] -->
1256
+
1257
+ ## Standalone functions
1258
+
1259
+ All the methods listed above are available as standalone functions. These
1260
+ functions are ideal for use in applications running in the browser, serverless
1261
+ runtimes or other environments where application bundle size is a primary
1262
+ concern. When using a bundler to build your application, all unused
1263
+ functionality will be either excluded from the final bundle or tree-shaken away.
1264
+
1265
+ To read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md).
1266
+
1267
+ <details>
1268
+
1269
+ <summary>Available standalone functions</summary>
1270
+
1271
+ - [`applicationsCreate`](docs/sdks/applications/README.md#create) - Create an application in the Financeable platform.
1272
+ - [`applicationsGet`](docs/sdks/applications/README.md#get) - Retrieve an application by its ID
1273
+ - [`applicationsList`](docs/sdks/applications/README.md#list) - Retrieve a list of applications
1274
+ - [`oauthTokenGet`](docs/sdks/oauthtoken/README.md#get) - Obtain an OAuth client_credentials token
1275
+
1276
+ </details>
1277
+ <!-- End Standalone functions [standalone-funcs] -->
1278
+
1279
+ <!-- Start Retries [retries] -->
1280
+
1281
+ ## Retries
1282
+
1283
+ Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
1284
+
1285
+ To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
544
1286
 
545
1287
  ```typescript
546
1288
  import { Financeable } from "@financeable/aggregation";
547
- import {
548
- CreateApplicationResponseBody,
549
- SDKValidationError,
550
- } from "@financeable/aggregation/models/errors";
1289
+ import { CommercialAssetType } from "@financeable/aggregation/models/components";
551
1290
 
552
- const financeable = new Financeable();
1291
+ const financeable = new Financeable({
1292
+ clientCredentials: process.env["FINANCEABLE_CLIENT_CREDENTIALS"] ?? "",
1293
+ });
553
1294
 
554
1295
  async function run() {
555
- let result;
556
- try {
557
- result = await financeable.applications.create({
1296
+ const tokenRequest = await financeable.oauthToken.get({
1297
+ grantType: 'client_credentials',
1298
+ clientId: '<ClientId>',
1299
+ clientSecret: '<ClientSecret>',
1300
+ scope: 'application:read application:write',
1301
+ });
1302
+
1303
+ const result = await financeable.applications.create(
1304
+ {
558
1305
  data: {
559
1306
  type: "applications",
560
1307
  attributes: {
@@ -583,22 +1330,18 @@ async function run() {
583
1330
  customers: {
584
1331
  data: [
585
1332
  {
586
- id: "<id>",
587
1333
  type: "customers",
588
1334
  attributes: {
589
1335
  title: "Mr",
590
1336
  firstName: "John",
591
1337
  lastName: "Smith",
592
1338
  dateOfBirth: "01-01-1990",
593
- idExpiryDate: "01-01-2025",
594
- idType: "licence",
595
- idNumber: "12345678",
1339
+ idExpiryDate: "<value>",
596
1340
  },
597
1341
  relationships: {
598
1342
  addresses: {
599
1343
  data: [
600
1344
  {
601
- id: "<id>",
602
1345
  type: "addresses",
603
1346
  attributes: {
604
1347
  addressType: "residential",
@@ -618,7 +1361,6 @@ async function run() {
618
1361
  },
619
1362
  },
620
1363
  {
621
- id: "<id>",
622
1364
  type: "addresses",
623
1365
  attributes: {
624
1366
  addressType: "residential",
@@ -645,13 +1387,12 @@ async function run() {
645
1387
  },
646
1388
  asset: {
647
1389
  data: {
648
- id: "<id>",
649
- type: "asset",
1390
+ type: "assets",
650
1391
  attributes: {
651
1392
  ageOfAsset: 3,
652
1393
  ageOfAssetAtEnd: 8,
653
1394
  condition: "USED",
654
- assetType: "MOTOR_VEHICLE_(<4.5_TONNES)",
1395
+ assetType: CommercialAssetType.MotorVehicleLessThan45Tonnes,
655
1396
  purpose: "VEHICLE",
656
1397
  assetValue: "35000.00",
657
1398
  make: "Toyota",
@@ -661,202 +1402,41 @@ async function run() {
661
1402
  vin: "1HGCM82633A123456",
662
1403
  supplierName: "Mr and Mrs Smith",
663
1404
  supplierABN: "12345678901",
664
- supplierAddress: "123 Car Street, Melbourne VIC 3000",
665
- supplierPhone: "0412345678",
666
- supplierContactName: "John Smith",
667
- supplierEmail: "john.smith@mrandmrssmith.com.au",
668
- privateSale: false,
669
- typeOfSale: "DEALER",
670
- description: "2020 Toyota Camry Hybrid SL, Silver, 45,000km",
671
- netAssetValue: "32000.00",
672
- isLuxury: false,
673
- additionalFees: "995.00",
674
- additionalTaxes: "0.00",
675
- },
676
- },
677
- },
678
- },
679
- },
680
- });
681
-
682
- // Handle the result
683
- console.log(result);
684
- } catch (err) {
685
- switch (true) {
686
- // The server response does not match the expected SDK schema
687
- case (err instanceof SDKValidationError): {
688
- // Pretty-print will provide a human-readable multi-line error message
689
- console.error(err.pretty());
690
- // Raw value may also be inspected
691
- console.error(err.rawValue);
692
- return;
693
- }
694
- case (err instanceof CreateApplicationResponseBody): {
695
- // Handle err.data$: CreateApplicationResponseBodyData
696
- console.error(err);
697
- return;
698
- }
699
- default: {
700
- // Other errors such as network errors, see HTTPClientErrors for more details
701
- throw err;
702
- }
703
- }
704
- }
705
- }
706
-
707
- run();
708
-
709
- ```
710
-
711
- Validation errors can also occur when either method arguments or data returned from the server do not match the expected format. The `SDKValidationError` that is thrown as a result will capture the raw value that failed validation in an attribute called `rawValue`. Additionally, a `pretty()` method is available on this error that can be used to log a nicely formatted multi-line string since validation errors can list many issues and the plain error string may be difficult read when debugging.
712
-
713
- In some rare cases, the SDK can fail to get a response from the server or even make the request due to unexpected circumstances such as network conditions. These types of errors are captured in the `models/errors/httpclienterrors.ts` module:
714
-
715
- | HTTP Client Error | Description |
716
- | ---------------------------------------------------- | ---------------------------------------------------- |
717
- | RequestAbortedError | HTTP request was aborted by the client |
718
- | RequestTimeoutError | HTTP request timed out due to an AbortSignal signal |
719
- | ConnectionError | HTTP client was unable to make a request to a server |
720
- | InvalidRequestError | Any input used to create a request is invalid |
721
- | UnexpectedClientError | Unrecognised or unexpected error |
722
-
723
- ## Server Selection
724
-
725
- ### Override Server URL Per-Client
726
-
727
- The default server can also be overridden globally by passing a URL to the `serverURL: string` optional parameter when initializing the SDK client instance. For example:
728
- ```typescript
729
- import { Financeable } from "@financeable/aggregation";
730
-
731
- const financeable = new Financeable({
732
- serverURL: "https://api.financeable.com.au",
733
- });
734
-
735
- async function run() {
736
- const result = await financeable.applications.create({
737
- data: {
738
- type: "applications",
739
- attributes: {
740
- purpose: "Purchase of a motor vehicle",
741
- applicationType: "consumer",
742
- },
743
- relationships: {
744
- loanDetails: {
745
- data: {
746
- type: "loan-details",
747
- attributes: {
748
- repayments: 12,
749
- repaymentFrequency: "monthly",
750
- repaymentStructure: "group-payments",
751
- loanAmount: "10280.95",
752
- purpose: "Purchase of a motor vehicle",
753
- term: 48,
754
- balloon: 5,
755
- deposit: "2500",
756
- originationFee: 200,
757
- rate: "0.15",
758
- rateAdjustment: "-0.01",
759
- },
760
- },
761
- },
762
- customers: {
763
- data: [
764
- {
765
- id: "<id>",
766
- type: "customers",
767
- attributes: {
768
- title: "Mr",
769
- firstName: "John",
770
- lastName: "Smith",
771
- dateOfBirth: "01-01-1990",
772
- idExpiryDate: "01-01-2025",
773
- idType: "licence",
774
- idNumber: "12345678",
775
- },
776
- relationships: {
777
- addresses: {
778
- data: [
779
- {
780
- id: "<id>",
781
- type: "addresses",
782
- attributes: {
783
- addressType: "residential",
784
- fullAddress: "42 Wallaby Way, Sydney NSW 2000",
785
- city: "Sydney",
786
- postCode: "2000",
787
- streetAddress: "42 Wallaby Way",
788
- addressLine2: "",
789
- streetNumber: "42",
790
- streetType: "Way",
791
- street: "Wallaby",
792
- state: "NSW",
793
- country: "Australia",
794
- status: "current",
795
- monthsAt: 24,
796
- yearsAt: 2,
797
- },
798
- },
799
- {
800
- id: "<id>",
801
- type: "addresses",
802
- attributes: {
803
- addressType: "residential",
804
- fullAddress: "42 Wallaby Way, Sydney NSW 2000",
805
- city: "Sydney",
806
- postCode: "2000",
807
- streetAddress: "42 Wallaby Way",
808
- addressLine2: "",
809
- streetNumber: "42",
810
- streetType: "Way",
811
- street: "Wallaby",
812
- state: "NSW",
813
- country: "Australia",
814
- status: "current",
815
- monthsAt: 24,
816
- yearsAt: 2,
817
- },
818
- },
819
- ],
820
- },
821
- },
822
- },
823
- ],
824
- },
825
- asset: {
826
- data: {
827
- id: "<id>",
828
- type: "asset",
829
- attributes: {
830
- ageOfAsset: 3,
831
- ageOfAssetAtEnd: 8,
832
- condition: "USED",
833
- assetType: "MOTOR_VEHICLE_(<4.5_TONNES)",
834
- purpose: "VEHICLE",
835
- assetValue: "35000.00",
836
- make: "Toyota",
837
- assetModel: "Camry",
838
- registrationNumber: "ABC123",
839
- registrationState: "VIC",
840
- vin: "1HGCM82633A123456",
841
- supplierName: "Mr and Mrs Smith",
842
- supplierABN: "12345678901",
843
- supplierAddress: "123 Car Street, Melbourne VIC 3000",
844
- supplierPhone: "0412345678",
845
- supplierContactName: "John Smith",
846
- supplierEmail: "john.smith@mrandmrssmith.com.au",
847
- privateSale: false,
848
- typeOfSale: "DEALER",
849
- description: "2020 Toyota Camry Hybrid SL, Silver, 45,000km",
850
- netAssetValue: "32000.00",
851
- isLuxury: false,
852
- additionalFees: "995.00",
853
- additionalTaxes: "0.00",
1405
+ supplierAddress: "123 Car Street, Melbourne VIC 3000",
1406
+ supplierPhone: "0412345678",
1407
+ supplierContactName: "John Smith",
1408
+ supplierEmail: "john.smith@mrandmrssmith.com.au",
1409
+ privateSale: false,
1410
+ typeOfSale: "DEALER",
1411
+ description: "2020 Toyota Camry Hybrid SL, Silver, 45,000km",
1412
+ netAssetValue: "32000.00",
1413
+ isLuxury: false,
1414
+ additionalFees: "995.00",
1415
+ additionalTaxes: "0.00",
1416
+ },
854
1417
  },
855
1418
  },
856
1419
  },
857
1420
  },
858
1421
  },
859
- });
1422
+ {
1423
+ fetchOptions: {
1424
+ headers: {
1425
+ authorization: `Bearer ${tokenRequest.accessToken}`,
1426
+ },
1427
+ },
1428
+ retries: {
1429
+ strategy: "backoff",
1430
+ backoff: {
1431
+ initialInterval: 1,
1432
+ maxInterval: 50,
1433
+ exponent: 1.1,
1434
+ maxElapsedTime: 100,
1435
+ },
1436
+ retryConnectionErrors: false,
1437
+ }
1438
+ }
1439
+ );
860
1440
 
861
1441
  // Handle the result
862
1442
  console.log(result);
@@ -1011,17 +1591,130 @@ For supported JavaScript runtimes, please consult [RUNTIMES.md](RUNTIMES.md).
1011
1591
 
1012
1592
  ```typescript
1013
1593
  import { Financeable } from "@financeable/aggregation";
1594
+ import { CommercialAssetType } from "@financeable/aggregation/models/components";
1014
1595
 
1015
1596
  const financeable = new Financeable({
1016
1597
  clientCredentials: process.env["FINANCEABLE_CLIENT_CREDENTIALS"] ?? "",
1017
1598
  });
1018
1599
 
1019
1600
  async function run() {
1020
- const result = await financeable.getToken({
1021
- grantType: "client_credentials",
1022
- clientId: "<id>",
1023
- clientSecret: "<value>",
1024
- scope: "<value>",
1601
+ const result = await financeable.applications.create({
1602
+ data: {
1603
+ type: "applications",
1604
+ attributes: {
1605
+ purpose: "Purchase of a motor vehicle",
1606
+ applicationType: "consumer",
1607
+ },
1608
+ relationships: {
1609
+ loanDetails: {
1610
+ data: {
1611
+ type: "loan-details",
1612
+ attributes: {
1613
+ repayments: 12,
1614
+ repaymentFrequency: "monthly",
1615
+ repaymentStructure: "group-payments",
1616
+ loanAmount: "10280.95",
1617
+ purpose: "Purchase of a motor vehicle",
1618
+ term: 48,
1619
+ balloon: 5,
1620
+ deposit: "2500",
1621
+ originationFee: 200,
1622
+ rate: "0.15",
1623
+ rateAdjustment: "-0.01",
1624
+ },
1625
+ },
1626
+ },
1627
+ customers: {
1628
+ data: [
1629
+ {
1630
+ type: "customers",
1631
+ attributes: {
1632
+ title: "Mr",
1633
+ firstName: "John",
1634
+ lastName: "Smith",
1635
+ dateOfBirth: "01-01-1990",
1636
+ idExpiryDate: "<value>",
1637
+ },
1638
+ relationships: {
1639
+ addresses: {
1640
+ data: [
1641
+ {
1642
+ type: "addresses",
1643
+ attributes: {
1644
+ addressType: "residential",
1645
+ fullAddress: "42 Wallaby Way, Sydney NSW 2000",
1646
+ city: "Sydney",
1647
+ postCode: "2000",
1648
+ streetAddress: "42 Wallaby Way",
1649
+ addressLine2: "",
1650
+ streetNumber: "42",
1651
+ streetType: "Way",
1652
+ street: "Wallaby",
1653
+ state: "NSW",
1654
+ country: "Australia",
1655
+ status: "current",
1656
+ monthsAt: 24,
1657
+ yearsAt: 2,
1658
+ },
1659
+ },
1660
+ {
1661
+ type: "addresses",
1662
+ attributes: {
1663
+ addressType: "residential",
1664
+ fullAddress: "42 Wallaby Way, Sydney NSW 2000",
1665
+ city: "Sydney",
1666
+ postCode: "2000",
1667
+ streetAddress: "42 Wallaby Way",
1668
+ addressLine2: "",
1669
+ streetNumber: "42",
1670
+ streetType: "Way",
1671
+ street: "Wallaby",
1672
+ state: "NSW",
1673
+ country: "Australia",
1674
+ status: "current",
1675
+ monthsAt: 24,
1676
+ yearsAt: 2,
1677
+ },
1678
+ },
1679
+ ],
1680
+ },
1681
+ },
1682
+ },
1683
+ ],
1684
+ },
1685
+ asset: {
1686
+ data: {
1687
+ type: "assets",
1688
+ attributes: {
1689
+ ageOfAsset: 3,
1690
+ ageOfAssetAtEnd: 8,
1691
+ condition: "USED",
1692
+ assetType: CommercialAssetType.MotorVehicleLessThan45Tonnes,
1693
+ purpose: "VEHICLE",
1694
+ assetValue: "35000.00",
1695
+ make: "Toyota",
1696
+ assetModel: "Camry",
1697
+ registrationNumber: "ABC123",
1698
+ registrationState: "VIC",
1699
+ vin: "1HGCM82633A123456",
1700
+ supplierName: "Mr and Mrs Smith",
1701
+ supplierABN: "12345678901",
1702
+ supplierAddress: "123 Car Street, Melbourne VIC 3000",
1703
+ supplierPhone: "0412345678",
1704
+ supplierContactName: "John Smith",
1705
+ supplierEmail: "john.smith@mrandmrssmith.com.au",
1706
+ privateSale: false,
1707
+ typeOfSale: "DEALER",
1708
+ description: "2020 Toyota Camry Hybrid SL, Silver, 45,000km",
1709
+ netAssetValue: "32000.00",
1710
+ isLuxury: false,
1711
+ additionalFees: "995.00",
1712
+ additionalTaxes: "0.00",
1713
+ },
1714
+ },
1715
+ },
1716
+ },
1717
+ },
1025
1718
  });
1026
1719
 
1027
1720
  // Handle the result
@@ -1047,17 +1740,130 @@ This SDK supports the following security scheme globally:
1047
1740
  To authenticate with the API the `clientCredentials` parameter must be set when initializing the SDK client instance. For example:
1048
1741
  ```typescript
1049
1742
  import { Financeable } from "@financeable/aggregation";
1743
+ import { CommercialAssetType } from "@financeable/aggregation/models/components";
1050
1744
 
1051
1745
  const financeable = new Financeable({
1052
1746
  clientCredentials: process.env["FINANCEABLE_CLIENT_CREDENTIALS"] ?? "",
1053
1747
  });
1054
1748
 
1055
1749
  async function run() {
1056
- const result = await financeable.getToken({
1057
- grantType: "client_credentials",
1058
- clientId: "<id>",
1059
- clientSecret: "<value>",
1060
- scope: "<value>",
1750
+ const result = await financeable.applications.create({
1751
+ data: {
1752
+ type: "applications",
1753
+ attributes: {
1754
+ purpose: "Purchase of a motor vehicle",
1755
+ applicationType: "consumer",
1756
+ },
1757
+ relationships: {
1758
+ loanDetails: {
1759
+ data: {
1760
+ type: "loan-details",
1761
+ attributes: {
1762
+ repayments: 12,
1763
+ repaymentFrequency: "monthly",
1764
+ repaymentStructure: "group-payments",
1765
+ loanAmount: "10280.95",
1766
+ purpose: "Purchase of a motor vehicle",
1767
+ term: 48,
1768
+ balloon: 5,
1769
+ deposit: "2500",
1770
+ originationFee: 200,
1771
+ rate: "0.15",
1772
+ rateAdjustment: "-0.01",
1773
+ },
1774
+ },
1775
+ },
1776
+ customers: {
1777
+ data: [
1778
+ {
1779
+ type: "customers",
1780
+ attributes: {
1781
+ title: "Mr",
1782
+ firstName: "John",
1783
+ lastName: "Smith",
1784
+ dateOfBirth: "01-01-1990",
1785
+ idExpiryDate: "<value>",
1786
+ },
1787
+ relationships: {
1788
+ addresses: {
1789
+ data: [
1790
+ {
1791
+ type: "addresses",
1792
+ attributes: {
1793
+ addressType: "residential",
1794
+ fullAddress: "42 Wallaby Way, Sydney NSW 2000",
1795
+ city: "Sydney",
1796
+ postCode: "2000",
1797
+ streetAddress: "42 Wallaby Way",
1798
+ addressLine2: "",
1799
+ streetNumber: "42",
1800
+ streetType: "Way",
1801
+ street: "Wallaby",
1802
+ state: "NSW",
1803
+ country: "Australia",
1804
+ status: "current",
1805
+ monthsAt: 24,
1806
+ yearsAt: 2,
1807
+ },
1808
+ },
1809
+ {
1810
+ type: "addresses",
1811
+ attributes: {
1812
+ addressType: "residential",
1813
+ fullAddress: "42 Wallaby Way, Sydney NSW 2000",
1814
+ city: "Sydney",
1815
+ postCode: "2000",
1816
+ streetAddress: "42 Wallaby Way",
1817
+ addressLine2: "",
1818
+ streetNumber: "42",
1819
+ streetType: "Way",
1820
+ street: "Wallaby",
1821
+ state: "NSW",
1822
+ country: "Australia",
1823
+ status: "current",
1824
+ monthsAt: 24,
1825
+ yearsAt: 2,
1826
+ },
1827
+ },
1828
+ ],
1829
+ },
1830
+ },
1831
+ },
1832
+ ],
1833
+ },
1834
+ asset: {
1835
+ data: {
1836
+ type: "assets",
1837
+ attributes: {
1838
+ ageOfAsset: 3,
1839
+ ageOfAssetAtEnd: 8,
1840
+ condition: "USED",
1841
+ assetType: CommercialAssetType.MotorVehicleLessThan45Tonnes,
1842
+ purpose: "VEHICLE",
1843
+ assetValue: "35000.00",
1844
+ make: "Toyota",
1845
+ assetModel: "Camry",
1846
+ registrationNumber: "ABC123",
1847
+ registrationState: "VIC",
1848
+ vin: "1HGCM82633A123456",
1849
+ supplierName: "Mr and Mrs Smith",
1850
+ supplierABN: "12345678901",
1851
+ supplierAddress: "123 Car Street, Melbourne VIC 3000",
1852
+ supplierPhone: "0412345678",
1853
+ supplierContactName: "John Smith",
1854
+ supplierEmail: "john.smith@mrandmrssmith.com.au",
1855
+ privateSale: false,
1856
+ typeOfSale: "DEALER",
1857
+ description: "2020 Toyota Camry Hybrid SL, Silver, 45,000km",
1858
+ netAssetValue: "32000.00",
1859
+ isLuxury: false,
1860
+ additionalFees: "995.00",
1861
+ additionalTaxes: "0.00",
1862
+ },
1863
+ },
1864
+ },
1865
+ },
1866
+ },
1061
1867
  });
1062
1868
 
1063
1869
  // Handle the result
@@ -1081,9 +1887,10 @@ run();
1081
1887
  * [list](docs/sdks/applications/README.md#list) - Retrieve a list of applications
1082
1888
  * [get](docs/sdks/applications/README.md#get) - Retrieve an application by its ID
1083
1889
 
1084
- ### [Financeable SDK](docs/sdks/financeable/README.md)
1085
1890
 
1086
- * [getToken](docs/sdks/financeable/README.md#gettoken) - Obtain an OAuth client_credentials token
1891
+ ### [oauthToken](docs/sdks/oauthtoken/README.md)
1892
+
1893
+ * [oauthToken](docs/sdks/oauthtoken/README.md#oauthtoken) - Obtain an OAuth client_credentials token
1087
1894
 
1088
1895
  </details>
1089
1896
  <!-- End Available Resources and Operations [operations] -->
@@ -1106,7 +1913,7 @@ To read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md).
1106
1913
  - [`applicationsCreate`](docs/sdks/applications/README.md#create) - Create an application in the Financeable platform.
1107
1914
  - [`applicationsGet`](docs/sdks/applications/README.md#get) - Retrieve an application by its ID
1108
1915
  - [`applicationsList`](docs/sdks/applications/README.md#list) - Retrieve a list of applications
1109
- - [`getToken`](docs/sdks/financeable/README.md#gettoken) - Obtain an OAuth client_credentials token
1916
+ - [`oauthTokenOauthToken`](docs/sdks/oauthtoken/README.md#oauthtoken) - Obtain an OAuth client_credentials token
1110
1917
 
1111
1918
  </details>
1112
1919
  <!-- End Standalone functions [standalone-funcs] -->
@@ -1119,17 +1926,130 @@ Some of the endpoints in this SDK support retries. If you use the SDK without a
1119
1926
  To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
1120
1927
  ```typescript
1121
1928
  import { Financeable } from "@financeable/aggregation";
1929
+ import { CommercialAssetType } from "@financeable/aggregation/models/components";
1122
1930
 
1123
1931
  const financeable = new Financeable({
1124
1932
  clientCredentials: process.env["FINANCEABLE_CLIENT_CREDENTIALS"] ?? "",
1125
1933
  });
1126
1934
 
1127
1935
  async function run() {
1128
- const result = await financeable.getToken({
1129
- grantType: "client_credentials",
1130
- clientId: "<id>",
1131
- clientSecret: "<value>",
1132
- scope: "<value>",
1936
+ const result = await financeable.applications.create({
1937
+ data: {
1938
+ type: "applications",
1939
+ attributes: {
1940
+ purpose: "Purchase of a motor vehicle",
1941
+ applicationType: "consumer",
1942
+ },
1943
+ relationships: {
1944
+ loanDetails: {
1945
+ data: {
1946
+ type: "loan-details",
1947
+ attributes: {
1948
+ repayments: 12,
1949
+ repaymentFrequency: "monthly",
1950
+ repaymentStructure: "group-payments",
1951
+ loanAmount: "10280.95",
1952
+ purpose: "Purchase of a motor vehicle",
1953
+ term: 48,
1954
+ balloon: 5,
1955
+ deposit: "2500",
1956
+ originationFee: 200,
1957
+ rate: "0.15",
1958
+ rateAdjustment: "-0.01",
1959
+ },
1960
+ },
1961
+ },
1962
+ customers: {
1963
+ data: [
1964
+ {
1965
+ type: "customers",
1966
+ attributes: {
1967
+ title: "Mr",
1968
+ firstName: "John",
1969
+ lastName: "Smith",
1970
+ dateOfBirth: "01-01-1990",
1971
+ idExpiryDate: "<value>",
1972
+ },
1973
+ relationships: {
1974
+ addresses: {
1975
+ data: [
1976
+ {
1977
+ type: "addresses",
1978
+ attributes: {
1979
+ addressType: "residential",
1980
+ fullAddress: "42 Wallaby Way, Sydney NSW 2000",
1981
+ city: "Sydney",
1982
+ postCode: "2000",
1983
+ streetAddress: "42 Wallaby Way",
1984
+ addressLine2: "",
1985
+ streetNumber: "42",
1986
+ streetType: "Way",
1987
+ street: "Wallaby",
1988
+ state: "NSW",
1989
+ country: "Australia",
1990
+ status: "current",
1991
+ monthsAt: 24,
1992
+ yearsAt: 2,
1993
+ },
1994
+ },
1995
+ {
1996
+ type: "addresses",
1997
+ attributes: {
1998
+ addressType: "residential",
1999
+ fullAddress: "42 Wallaby Way, Sydney NSW 2000",
2000
+ city: "Sydney",
2001
+ postCode: "2000",
2002
+ streetAddress: "42 Wallaby Way",
2003
+ addressLine2: "",
2004
+ streetNumber: "42",
2005
+ streetType: "Way",
2006
+ street: "Wallaby",
2007
+ state: "NSW",
2008
+ country: "Australia",
2009
+ status: "current",
2010
+ monthsAt: 24,
2011
+ yearsAt: 2,
2012
+ },
2013
+ },
2014
+ ],
2015
+ },
2016
+ },
2017
+ },
2018
+ ],
2019
+ },
2020
+ asset: {
2021
+ data: {
2022
+ type: "assets",
2023
+ attributes: {
2024
+ ageOfAsset: 3,
2025
+ ageOfAssetAtEnd: 8,
2026
+ condition: "USED",
2027
+ assetType: CommercialAssetType.MotorVehicleLessThan45Tonnes,
2028
+ purpose: "VEHICLE",
2029
+ assetValue: "35000.00",
2030
+ make: "Toyota",
2031
+ assetModel: "Camry",
2032
+ registrationNumber: "ABC123",
2033
+ registrationState: "VIC",
2034
+ vin: "1HGCM82633A123456",
2035
+ supplierName: "Mr and Mrs Smith",
2036
+ supplierABN: "12345678901",
2037
+ supplierAddress: "123 Car Street, Melbourne VIC 3000",
2038
+ supplierPhone: "0412345678",
2039
+ supplierContactName: "John Smith",
2040
+ supplierEmail: "john.smith@mrandmrssmith.com.au",
2041
+ privateSale: false,
2042
+ typeOfSale: "DEALER",
2043
+ description: "2020 Toyota Camry Hybrid SL, Silver, 45,000km",
2044
+ netAssetValue: "32000.00",
2045
+ isLuxury: false,
2046
+ additionalFees: "995.00",
2047
+ additionalTaxes: "0.00",
2048
+ },
2049
+ },
2050
+ },
2051
+ },
2052
+ },
1133
2053
  }, {
1134
2054
  retries: {
1135
2055
  strategy: "backoff",
@@ -1152,8 +2072,10 @@ run();
1152
2072
  ```
1153
2073
 
1154
2074
  If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
2075
+
1155
2076
  ```typescript
1156
2077
  import { Financeable } from "@financeable/aggregation";
2078
+ import { CommercialAssetType } from "@financeable/aggregation/models/components";
1157
2079
 
1158
2080
  const financeable = new Financeable({
1159
2081
  retryConfig: {
@@ -1166,15 +2088,133 @@ const financeable = new Financeable({
1166
2088
  },
1167
2089
  retryConnectionErrors: false,
1168
2090
  },
1169
- clientCredentials: process.env["FINANCEABLE_CLIENT_CREDENTIALS"] ?? "",
1170
2091
  });
1171
2092
 
1172
2093
  async function run() {
1173
- const result = await financeable.getToken({
1174
- grantType: "client_credentials",
1175
- clientId: "<id>",
1176
- clientSecret: "<value>",
1177
- scope: "<value>",
2094
+ const tokenRequest = await financeable.oauthToken.get({
2095
+ grantType: 'client_credentials',
2096
+ clientId: '<ClientId>',
2097
+ clientSecret: '<ClientSecret>',
2098
+ scope: 'application:read application:write',
2099
+ });
2100
+
2101
+ const result = await financeable.applications.create({
2102
+ data: {
2103
+ type: "applications",
2104
+ attributes: {
2105
+ purpose: "Purchase of a motor vehicle",
2106
+ applicationType: "consumer",
2107
+ },
2108
+ relationships: {
2109
+ loanDetails: {
2110
+ data: {
2111
+ type: "loan-details",
2112
+ attributes: {
2113
+ repayments: 12,
2114
+ repaymentFrequency: "monthly",
2115
+ repaymentStructure: "group-payments",
2116
+ loanAmount: "10280.95",
2117
+ purpose: "Purchase of a motor vehicle",
2118
+ term: 48,
2119
+ balloon: 5,
2120
+ deposit: "2500",
2121
+ originationFee: 200,
2122
+ rate: "0.15",
2123
+ rateAdjustment: "-0.01",
2124
+ },
2125
+ },
2126
+ },
2127
+ customers: {
2128
+ data: [
2129
+ {
2130
+ type: "customers",
2131
+ attributes: {
2132
+ title: "Mr",
2133
+ firstName: "John",
2134
+ lastName: "Smith",
2135
+ dateOfBirth: "1963-05-24",
2136
+ idExpiryDate: "2028-04-20",
2137
+ },
2138
+ relationships: {
2139
+ addresses: {
2140
+ data: [
2141
+ {
2142
+ type: "addresses",
2143
+ attributes: {
2144
+ addressType: "residential",
2145
+ fullAddress: "42 Wallaby Way, Sydney NSW 2000",
2146
+ city: "Sydney",
2147
+ postCode: "2000",
2148
+ streetAddress: "42 Wallaby Way",
2149
+ addressLine2: "",
2150
+ streetNumber: "42",
2151
+ streetType: "Way",
2152
+ street: "Wallaby",
2153
+ state: "NSW",
2154
+ country: "Australia",
2155
+ status: "current",
2156
+ monthsAt: 11,
2157
+ yearsAt: 2,
2158
+ },
2159
+ },
2160
+ {
2161
+ type: "addresses",
2162
+ attributes: {
2163
+ addressType: "residential",
2164
+ fullAddress: "42 Wallaby Way, Sydney NSW 2000",
2165
+ city: "Sydney",
2166
+ postCode: "2000",
2167
+ streetAddress: "42 Wallaby Way",
2168
+ addressLine2: "",
2169
+ streetNumber: "42",
2170
+ streetType: "Way",
2171
+ street: "Wallaby",
2172
+ state: "NSW",
2173
+ country: "Australia",
2174
+ status: "previous",
2175
+ monthsAt: 4,
2176
+ yearsAt: 3,
2177
+ },
2178
+ },
2179
+ ],
2180
+ },
2181
+ },
2182
+ },
2183
+ ],
2184
+ },
2185
+ asset: {
2186
+ data: {
2187
+ type: "assets",
2188
+ attributes: {
2189
+ ageOfAsset: 3,
2190
+ ageOfAssetAtEnd: 8,
2191
+ condition: "USED",
2192
+ assetType: ConsumerAssetType.MotorVehicle,
2193
+ purpose: "VEHICLE",
2194
+ assetValue: "35000.00",
2195
+ make: "Toyota",
2196
+ assetModel: "Camry",
2197
+ registrationNumber: "ABC123",
2198
+ registrationState: "VIC",
2199
+ vin: "1HGCM82633A123456",
2200
+ supplierName: "Mr and Mrs Smith",
2201
+ supplierABN: "12345678901",
2202
+ supplierAddress: "123 Car Street, Melbourne VIC 3000",
2203
+ supplierPhone: "0412345678",
2204
+ supplierContactName: "John Smith",
2205
+ supplierEmail: "john.smith@mrandmrssmith.com.au",
2206
+ privateSale: false,
2207
+ typeOfSale: "DEALER",
2208
+ description: "2020 Toyota Camry Hybrid SL, Silver, 45,000km",
2209
+ netAssetValue: "32000.00",
2210
+ isLuxury: false,
2211
+ additionalFees: "995.00",
2212
+ additionalTaxes: "0.00",
2213
+ },
2214
+ },
2215
+ },
2216
+ },
2217
+ },
1178
2218
  });
1179
2219
 
1180
2220
  // Handle the result
@@ -1182,26 +2222,28 @@ async function run() {
1182
2222
  }
1183
2223
 
1184
2224
  run();
1185
-
1186
2225
  ```
2226
+
1187
2227
  <!-- End Retries [retries] -->
1188
2228
 
1189
2229
  <!-- Start Error Handling [errors] -->
2230
+
1190
2231
  ## Error Handling
1191
2232
 
1192
- Some methods specify known errors which can be thrown. All the known errors are enumerated in the `models/errors/errors.ts` module. The known errors for a method are documented under the *Errors* tables in SDK docs. For example, the `create` method may throw the following errors:
2233
+ Some methods specify known errors which can be thrown. All the known errors are enumerated in the `models/errors/errors.ts` module. The known errors for a method are documented under the _Errors_ tables in SDK docs. For example, the `create` method may throw the following errors:
1193
2234
 
1194
- | Error Type | Status Code | Content Type |
1195
- | ------------------------------------ | ----------- | ---------------- |
1196
- | errors.CreateApplicationResponseBody | 403 | application/json |
1197
- | errors.APIError | 4XX, 5XX | \*/\* |
2235
+ | Error Type | Status Code | Content Type |
2236
+ | ------------------- | ----------- | ---------------- |
2237
+ | errors.ResponseBody | 403 | application/json |
2238
+ | errors.APIError | 4XX, 5XX | \*/\* |
1198
2239
 
1199
2240
  If the method throws an error and it is not captured by the known errors, it will default to throwing a `APIError`.
1200
2241
 
1201
2242
  ```typescript
1202
2243
  import { Financeable } from "@financeable/aggregation";
2244
+ import { CommercialAssetType } from "@financeable/aggregation/models/components";
1203
2245
  import {
1204
- CreateApplicationResponseBody,
2246
+ ResponseBody,
1205
2247
  SDKValidationError,
1206
2248
  } from "@financeable/aggregation/models/errors";
1207
2249
 
@@ -1303,7 +2345,7 @@ async function run() {
1303
2345
  ageOfAsset: 3,
1304
2346
  ageOfAssetAtEnd: 8,
1305
2347
  condition: "USED",
1306
- assetType: "MOTOR_VEHICLE_(<4.5_TONNES)",
2348
+ assetType: CommercialAssetType.MotorVehicleLessThan45Tonnes,
1307
2349
  purpose: "VEHICLE",
1308
2350
  assetValue: "35000.00",
1309
2351
  make: "Toyota",
@@ -1336,15 +2378,15 @@ async function run() {
1336
2378
  } catch (err) {
1337
2379
  switch (true) {
1338
2380
  // The server response does not match the expected SDK schema
1339
- case (err instanceof SDKValidationError): {
2381
+ case err instanceof SDKValidationError: {
1340
2382
  // Pretty-print will provide a human-readable multi-line error message
1341
2383
  console.error(err.pretty());
1342
2384
  // Raw value may also be inspected
1343
2385
  console.error(err.rawValue);
1344
2386
  return;
1345
2387
  }
1346
- case (err instanceof CreateApplicationResponseBody): {
1347
- // Handle err.data$: CreateApplicationResponseBodyData
2388
+ case err instanceof ResponseBody: {
2389
+ // Handle err.data$: ResponseBodyData
1348
2390
  console.error(err);
1349
2391
  return;
1350
2392
  }
@@ -1357,54 +2399,26 @@ async function run() {
1357
2399
  }
1358
2400
 
1359
2401
  run();
1360
-
1361
2402
  ```
1362
2403
 
1363
2404
  Validation errors can also occur when either method arguments or data returned from the server do not match the expected format. The `SDKValidationError` that is thrown as a result will capture the raw value that failed validation in an attribute called `rawValue`. Additionally, a `pretty()` method is available on this error that can be used to log a nicely formatted multi-line string since validation errors can list many issues and the plain error string may be difficult read when debugging.
1364
2405
 
1365
2406
  In some rare cases, the SDK can fail to get a response from the server or even make the request due to unexpected circumstances such as network conditions. These types of errors are captured in the `models/errors/httpclienterrors.ts` module:
1366
2407
 
1367
- | HTTP Client Error | Description |
1368
- | ---------------------------------------------------- | ---------------------------------------------------- |
1369
- | RequestAbortedError | HTTP request was aborted by the client |
1370
- | RequestTimeoutError | HTTP request timed out due to an AbortSignal signal |
1371
- | ConnectionError | HTTP client was unable to make a request to a server |
1372
- | InvalidRequestError | Any input used to create a request is invalid |
1373
- | UnexpectedClientError | Unrecognised or unexpected error |
1374
- <!-- End Error Handling [errors] -->
1375
-
1376
- <!-- Start Server Selection [server] -->
1377
- ## Server Selection
1378
-
1379
- ### Override Server URL Per-Client
1380
-
1381
- The default server can be overridden globally by passing a URL to the `serverURL: string` optional parameter when initializing the SDK client instance. For example:
1382
- ```typescript
1383
- import { Financeable } from "@financeable/aggregation";
1384
-
1385
- const financeable = new Financeable({
1386
- serverURL: "https://api.financeable.com.au",
1387
- clientCredentials: process.env["FINANCEABLE_CLIENT_CREDENTIALS"] ?? "",
1388
- });
1389
-
1390
- async function run() {
1391
- const result = await financeable.getToken({
1392
- grantType: "client_credentials",
1393
- clientId: "<id>",
1394
- clientSecret: "<value>",
1395
- scope: "<value>",
1396
- });
1397
-
1398
- // Handle the result
1399
- console.log(result);
1400
- }
2408
+ | HTTP Client Error | Description |
2409
+ | --------------------- | ---------------------------------------------------- |
2410
+ | RequestAbortedError | HTTP request was aborted by the client |
2411
+ | RequestTimeoutError | HTTP request timed out due to an AbortSignal signal |
2412
+ | ConnectionError | HTTP client was unable to make a request to a server |
2413
+ | InvalidRequestError | Any input used to create a request is invalid |
2414
+ | UnexpectedClientError | Unrecognised or unexpected error |
1401
2415
 
1402
- run();
2416
+ <!-- End Error Handling [errors] -->
1403
2417
 
1404
- ```
1405
- <!-- End Server Selection [server] -->
2418
+ <!-- No End Server Selection [server] -->
1406
2419
 
1407
2420
  <!-- Start Custom HTTP Client [http-client] -->
2421
+
1408
2422
  ## Custom HTTP Client
1409
2423
 
1410
2424
  The TypeScript SDK makes API calls using an `HTTPClient` that wraps the native
@@ -1429,12 +2443,12 @@ const httpClient = new HTTPClient({
1429
2443
  // fetcher takes a function that has the same signature as native `fetch`.
1430
2444
  fetcher: (request) => {
1431
2445
  return fetch(request);
1432
- }
2446
+ },
1433
2447
  });
1434
2448
 
1435
2449
  httpClient.addHook("beforeRequest", (request) => {
1436
2450
  const nextRequest = new Request(request, {
1437
- signal: request.signal || AbortSignal.timeout(5000)
2451
+ signal: request.signal || AbortSignal.timeout(5000),
1438
2452
  });
1439
2453
 
1440
2454
  nextRequest.headers.set("x-custom-header", "custom value");
@@ -1451,9 +2465,11 @@ httpClient.addHook("requestError", (error, request) => {
1451
2465
 
1452
2466
  const sdk = new Financeable({ httpClient });
1453
2467
  ```
2468
+
1454
2469
  <!-- End Custom HTTP Client [http-client] -->
1455
2470
 
1456
2471
  <!-- Start Debugging [debug] -->
2472
+
1457
2473
  ## Debugging
1458
2474
 
1459
2475
  You can setup your SDK to emit debug logs for SDK requests and responses.
@@ -1470,6 +2486,7 @@ const sdk = new Financeable({ debugLogger: console });
1470
2486
  ```
1471
2487
 
1472
2488
  You can also enable a default debug logger by setting an environment variable `FINANCEABLE_DEBUG` to true.
2489
+
1473
2490
  <!-- End Debugging [debug] -->
1474
2491
 
1475
2492
  <!-- Placeholder for Future Speakeasy SDK Sections -->