Skip to content

Commit 954c21a

Browse files
Merge pull request #477 from unit-finance/create-app-form
Application Form V2
2 parents e308117 + bea3a16 commit 954c21a

File tree

3 files changed

+119
-53
lines changed

3 files changed

+119
-53
lines changed

resources/applicationForm.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { BaseResource } from "./baseResource"
2-
import { BaseListParams, Include, Sort, Tags, UnitConfig, UnitResponse } from "../types/common"
3-
import { CreateApplicationFormRequest, CreateApplicationFormResponse, ApplicationForm } from "../types/applicationForm"
2+
import { BaseListParams, Include, Sort, Tags, UnitConfig, UnitResponse } from "../types"
3+
import { CreateApplicationFormRequest, ApplicationForm } from "../types"
44
import { Application } from "../types"
55

66
export class ApplicationForms extends BaseResource {
77
constructor(token: string, basePath: string, config?: UnitConfig) {
88
super(token, basePath + "/application-forms", config)
99
}
1010

11-
public async create(request: CreateApplicationFormRequest): Promise<UnitResponse<CreateApplicationFormResponse>> {
12-
return this.httpPost<UnitResponse<CreateApplicationFormResponse>>("", { data: request })
11+
public async create(request: CreateApplicationFormRequest): Promise<UnitResponse<ApplicationForm>> {
12+
return this.httpPost<UnitResponse<ApplicationForm>>("", { data: request })
1313
}
1414

1515
public async get(applicationFormId: string): Promise<UnitResponse<ApplicationForm> & Include<Application>> {

tests/applicationForms.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

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

55
import dotenv from "dotenv"
66
dotenv.config()
@@ -37,9 +37,11 @@ describe("ApplicationForms", () => {
3737
})
3838

3939
test("Create White-Label Application Form", async () => {
40-
const req: CreateApplicationForm = {
40+
const req: CreateApplicationFormV2 = {
4141
type: "applicationForm",
42-
attributes: {},
42+
attributes: {
43+
idempotencyKey: Math.random().toString(36).substring(7),
44+
},
4345
relationships: {}
4446
}
4547
const res = await unitWithVersion.applicationForms.create(req)

types/applicationForm.ts

Lines changed: 110 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
import { AnnualIncome, AnnualRevenue, BeneficialOwner, BusinessVertical, CashFlow, NumberOfEmployees, Occupation, SourceOfIncome } from "./application"
2-
import { Address, BusinessContact, EntityType, FullName, Officer, Phone, Relationship } from "./common"
1+
import {
2+
AnnualIncome,
3+
AnnualRevenue,
4+
BeneficialOwner,
5+
BusinessVertical,
6+
CashFlow,
7+
NumberOfEmployees,
8+
Occupation,
9+
SourceOfIncome
10+
} from "./application"
11+
import {Address, BusinessContact, EntityType, FullName, Officer, Phone, Relationship, Tags} from "./common"
312

413
export type ApplicationFormStage =
514
"ChooseBusinessOrIndividual" |
@@ -31,10 +40,54 @@ export interface CreateApplicationForm {
3140
*/
3241
allowedApplicationTypes?: Array<"Individual" | "SoleProprietorship" | "Business">
3342
/**
34-
* Optional. Override disclosure and redirect URLs that were defined in the application form settings.
43+
* Optional. Override disclosure and redirect URLs that were defined in the application form settings.
3544
*/
3645
settingsOverride?: ApplicationFormSettingsOverride
3746
}
47+
relationships?: {
48+
/**
49+
* See [Create an Application Form from an existing Application](https://developers.unit.co/application-forms/#create-an-application-form-from-an-existing-application)
50+
*/
51+
application?: {
52+
data: {
53+
type: "application"
54+
id: string
55+
}
56+
}
57+
}
58+
}
59+
60+
export interface CreateApplicationFormV2 {
61+
type: "applicationForm"
62+
attributes: {
63+
/**
64+
* 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)).
65+
*/
66+
tags?: object
67+
/**
68+
* Optional. Add data that is already known about the end-customer to be auto populated on the form.
69+
*/
70+
applicantDetails?: ApplicationFormPrefill
71+
/**
72+
* Optional. Array of Individual, Business or SoleProprietorship. Restrict the available application type for this specific application.
73+
*/
74+
allowedApplicationTypes?: Array<"Individual" | "SoleProprietorship" | "Business">
75+
/**
76+
* Optional. Override disclosure and redirect URLs that were defined in the application form settings.
77+
*/
78+
settingsOverride?: ApplicationFormSettingsOverride
79+
80+
/**
81+
* See [Idempotency](https://docs.unit.co/#intro-idempotency). Required for ApplicationFormV2
82+
*/
83+
idempotencyKey: string
84+
85+
/**
86+
* Optional. JWT subject for embedding via JWT token
87+
*/
88+
89+
jwtSubject?: string
90+
}
3891
relationships?: {
3992
/**
4093
* 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).
@@ -45,7 +98,7 @@ export interface CreateApplicationForm {
4598
id: string
4699
}
47100
}
48-
/**
101+
/**
49102
* 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.
50103
*/
51104
lendingProgram?: {
@@ -54,65 +107,73 @@ export interface CreateApplicationForm {
54107
id: string
55108
}
56109
}
57-
}
58-
}
59110

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
111+
/**
112+
* See [Create an Application Form from an existing Application](https://developers.unit.co/application-forms/#create-an-application-form-from-an-existing-application)
113+
*/
114+
application?: {
115+
data: {
116+
type: "application"
117+
id: string
118+
}
71119
}
72-
}}
120+
}
73121
}
74122

75-
export type CreateApplicationFormRequest = CreateApplicationForm | CreateApplicationFormFromAnExistingApplication
123+
export type CreateApplicationFormRequest = CreateApplicationForm | CreateApplicationFormV2
76124

77-
export type CreateApplicationFormResponseDefault = {
78-
type: "applicationForm"
79-
"id": string
80-
"attributes": {
81-
/**
82-
* 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)).
83-
*/
84-
tags?: object
125+
export type ApplicationFormV2 = {
126+
type: "applicationFormV2"
127+
id: string
128+
attributes: {
85129

86130
/**
87-
* The URL of the application form for the end-customer to access
131+
* Date only. The date the resource was created.
132+
* RFC3339 format. For more information: https://en.wikipedia.org/wiki/ISO_8601#RFCs
88133
*/
89-
url: string
134+
135+
createdAt: string
90136

91137
/**
92-
* Optional. Add data that is already known about the end-customer to be auto populated on the form.
138+
* Date only. The date the resource was updated.
139+
* RFC3339 format. For more information: https://en.wikipedia.org/wiki/ISO_8601#RFCs
93140
*/
94-
applicantDetails?: ApplicationFormPrefill
95141

96-
/***
97-
* Optional. restrict the available application type for this specific application.
98-
*/
99-
allowedApplicationTypes?: ("Individual" | "Business" | "SoleProprietorship")[]
142+
updatedAt: string
100143

101144
/**
102-
* Optional. Language of application form. Either en or es. If not specified, will default to en.
145+
* 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)).
103146
*/
104-
lang?: "en" | "es"
147+
tags: Tags
105148

106149
/**
107-
* Optional. Override disclosure URLs that were defined in the application form settings.
150+
* Token for embedding application form via token
108151
*/
109-
settingsOverride?: ApplicationFormSettingsOverride
152+
153+
applicationFormToken: {
154+
token: string
155+
expiration: string
156+
}
157+
158+
159+
applicationFormSettings: ApplicationFormSettingsOverride
160+
110161
}
111-
}
162+
links: {
112163

113-
export type CreateApplicationFormResponseV2 = { type: "applicationFormV2"; }
164+
related: {
165+
166+
type: "text/html"
167+
168+
/**
169+
* The URL of the application form for the end-customer to access
170+
*/
171+
172+
href: string
173+
}
174+
}
175+
}
114176

115-
export type CreateApplicationFormResponse = CreateApplicationFormResponseDefault | CreateApplicationFormResponseV2
116177

117178
export interface ApplicationFormPrefill {
118179
/**
@@ -268,7 +329,7 @@ export interface ApplicationFormPrefill {
268329
stockSymbol?: string
269330

270331
/**
271-
* Optional. Indicates if any of the officer / BeneficialOwner of the business have a non US nationality.
332+
* Optional. Indicates if any of the officer / BeneficialOwner of the business have a non US nationality.
272333
*/
273334
hasNonUsEntities?: boolean
274335
}
@@ -320,7 +381,8 @@ export interface ApplicationFormSettingsOverride {
320381
additionalDisclosures: Record<string, string>[]
321382
}
322383

323-
export interface ApplicationForm {
384+
385+
export interface ApplicationFormV1 {
324386
/**
325387
* Identifier of the applicationForm resource.
326388
*/
@@ -361,10 +423,12 @@ export interface ApplicationForm {
361423
/**
362424
* Describes relationships between the applicattom form resource and the application.
363425
*/
364-
relationships: {
426+
relationships?: {
365427
/**
366428
* The application.
367429
*/
368-
application: Relationship
430+
application?: Relationship
369431
}
370432
}
433+
434+
export type ApplicationForm = ApplicationFormV2 | ApplicationFormV1

0 commit comments

Comments
 (0)