Skip to content

Commit aaceb56

Browse files
authored
New base headers x-accept-version and relationships update for Create Application Form (#471)
* feat: new base headers x-accept-version and relationships update for Create Application Form * feat: test to verify that providing version header changes the response
1 parent ebe319f commit aaceb56

File tree

5 files changed

+70
-14
lines changed

5 files changed

+70
-14
lines changed

resources/baseResource.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ export class BaseResource {
2222
this.headers = {
2323
"Authorization": `Bearer ${token}`,
2424
"Content-Type": "application/vnd.api+json",
25-
"X-UNIT-SDK": `unit-node-sdk@v${version}`
25+
"X-UNIT-SDK": `unit-node-sdk@v${version}`,
2626
}
27+
28+
if(config?.apiVersion) this.headers["X-Accept-Version"] = config?.apiVersion
2729

2830
this.axios = config?.axios ?? axiosStatic
2931
}

tests/applicationForms.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11

22

3-
import { ApplicationFormPrefill, Unit } from "../unit"
3+
import { ApiVersion, ApplicationFormPrefill, CreateApplicationForm, Unit } from "../unit"
44

55
import dotenv from "dotenv"
66
dotenv.config()
77
const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test")
8+
const unitWithVersion = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test", {apiVersion: ApiVersion.V2024_06})
89

910

1011
describe("ApplicationForms", () => {
@@ -25,6 +26,26 @@ describe("ApplicationForms", () => {
2526
})
2627
})
2728

29+
test("Create Application Form", async () => {
30+
const req: CreateApplicationForm = {
31+
type: "applicationForm",
32+
attributes: {},
33+
relationships: {}
34+
}
35+
const res = await unit.applicationForms.create(req)
36+
expect(res.data.type === "applicationForm")
37+
})
38+
39+
test("Create White-Label Application Form", async () => {
40+
const req: CreateApplicationForm = {
41+
type: "applicationForm",
42+
attributes: {},
43+
relationships: {}
44+
}
45+
const res = await unitWithVersion.applicationForms.create(req)
46+
expect(res.data.type === "applicationFormV2")
47+
})
48+
2849
test("Test ApplicationFormPrefill Interface", () => {
2950
const applicationFormPrefill: ApplicationFormPrefill = {
3051
"applicationType": "Business",

tests/applications.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11

22

33
import { createAddress, createFullName, createPhone } from "../helpers"
4-
import { Agent, BusinessApplication, CancelApplicationRequest, CreateBusinessApplicationRequest, CreateIndividualApplicationRequest, CreateSoleProprietorApplicationRequest, CreateTrustApplicationRequest, IndividualApplication, PatchApplicationRequest, PatchBusinessApplicationAttributes, PatchBusinessApplicationBeneficialOwner, RelationshipsArrayData, TrustApplication, Unit, VerifyDocumentRequest } from "../unit"
4+
import { Agent, BusinessApplication, CancelApplicationRequest, CreateBusinessApplicationRequest, CreateIndividualApplicationRequest, CreateSoleProprietorApplicationRequest, CreateTrustApplicationRequest, IndividualApplication, PatchApplicationRequest, PatchBusinessApplicationAttributes, PatchBusinessApplicationBeneficialOwner, RelationshipsArrayData, TrustApplication, Unit } from "../unit"
55
import {
66
createIndividualApplication,
77
createBusinessApplication,
88
createTrustApplication,
9-
createIndividualApplicationWithRequiredDocument,
10-
createVerifyDocumentRequest,
11-
createIndividualApplicationWithSelfieVerification
9+
createIndividualApplicationWithRequiredDocument
1210
} from "./testHelpers"
1311
import dotenv from "dotenv"
1412
import * as fs from "fs"

types/applicationForm.ts

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export type ApplicationFormStage =
1515
"SoleProprietorshipPhoneVerification" |
1616
"SoleProprietorshipApplicationCreated"
1717

18-
export interface CreateApplicationFormRequest {
19-
"type": "applicationForm"
20-
"attributes": {
18+
export interface CreateApplicationForm {
19+
type: "applicationForm"
20+
attributes: {
2121
/**
2222
* See [Tags](https://developers.unit.co/#tags). Tags that will be copied to the customer that this application creates(see [Tag Inheritance](https://developers.unit.co/#tag-inheritance)).
2323
*/
@@ -37,19 +37,45 @@ export interface CreateApplicationFormRequest {
3737
}
3838
relationships?: {
3939
/**
40-
* See [Create an Application Form from an existing Application](https://developers.unit.co/application-forms/#create-an-application-form-from-an-existing-application)
40+
* Optional. The ID of the white-label theme to be used for this application form. See [White-Labeling and Customization](https://www.unit.co/docs/white-label-uis/white-label-application-form/#white-labeling-and-customization).
41+
*/
42+
whiteLabelTheme?: {
43+
data: {
44+
type: "whiteLabelTheme"
45+
id: string
46+
}
47+
}
48+
/**
49+
* Optional. The ID of the lending program to be used for this application form. See [Create Application Form with Credit Application](https://www.unit.co/docs/white-label-uis/white-label-application-form/#create-application-form-with-credit-application) for more information.
4150
*/
42-
application?: {
51+
lendingProgram?: {
4352
data: {
44-
type: "application"
53+
type: "lendingProgram"
4554
id: string
4655
}
4756
}
4857
}
4958
}
5059

51-
export interface CreateApplicationFormResponse {
52-
"type": "applicationForm"
60+
export interface CreateApplicationFormFromAnExistingApplication {
61+
type: "applicationForm"
62+
attributes: Record<string, never>
63+
relationships?: {
64+
/**
65+
* See [Create an Application Form from an existing Application](https://developers.unit.co/application-forms/#create-an-application-form-from-an-existing-application)
66+
*/
67+
application?: {
68+
data: {
69+
type: "application"
70+
id: string
71+
}
72+
}}
73+
}
74+
75+
export type CreateApplicationFormRequest = CreateApplicationForm | CreateApplicationFormFromAnExistingApplication
76+
77+
export type CreateApplicationFormResponseDefault = {
78+
type: "applicationForm"
5379
"id": string
5480
"attributes": {
5581
/**
@@ -84,6 +110,10 @@ export interface CreateApplicationFormResponse {
84110
}
85111
}
86112

113+
export type CreateApplicationFormResponseV2 = { type: "applicationFormV2"; }
114+
115+
export type CreateApplicationFormResponse = CreateApplicationFormResponseDefault | CreateApplicationFormResponseV2
116+
87117
export interface ApplicationFormPrefill {
88118
/**
89119
* Optional. One of "Individual", "Business" or "SoleProprietorship".

types/common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,15 @@ export interface BaseCreateRequestAttributes {
484484
idempotencyKey?: string
485485
}
486486

487+
export enum ApiVersion {
488+
V2024_06 = "V2024_06"
489+
}
490+
487491
export interface UnitConfig {
488492
axios?: AxiosInstance
489493
sdkUserAgent?: boolean
490494
securePath?: string
495+
apiVersion?: ApiVersion | string
491496
}
492497

493498
export class UnitError extends Error {

0 commit comments

Comments
 (0)