Skip to content

Commit 100bed3

Browse files
committed
FLS-1450: Add PreAwardApiClient and configuration
- Add PreAwardApiClient with TypeScript interfaces - Add preAwardApiUrl configuration with default value - Support for createOrUpdateForm, getAllForms, getFormDraft methods
1 parent 54256c8 commit 100bed3

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

designer/server/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface Config {
3131
authCookieName: string,
3232
sslKey: string,
3333
sslCert: string,
34+
preAwardApiUrl: string,
3435
}
3536

3637
// server-side storage expiration - defaults to 20 minutes
@@ -65,6 +66,7 @@ const schema = joi.object({
6566
authCookieName: joi.string().optional(),
6667
sslKey: joi.string().optional(),
6768
sslCert: joi.string().optional(),
69+
preAwardApiUrl: joi.string().default("https://api.communities.gov.localhost:4004"),
6870
});
6971

7072
// Build config
@@ -90,6 +92,7 @@ const config = {
9092
authCookieName: process.env.AUTH_COOKIE_NAME,
9193
sslKey: process.env.SSL_KEY,
9294
sslCert: process.env.SSL_CERT,
95+
preAwardApiUrl: process.env.PRE_AWARD_API_URL || "https://api.communities.gov.localhost:4004",
9396
};
9497

9598
// Validate config
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import config from "../config";
2+
import * as Wreck from "@hapi/wreck";
3+
4+
interface FormJson {
5+
startPage: string;
6+
pages: any[];
7+
sections: any[];
8+
name: string;
9+
version?: number;
10+
conditions?: any[];
11+
lists?: any[];
12+
metadata?: any;
13+
fees?: any[];
14+
outputs?: any[];
15+
skipSummary?: boolean;
16+
[key: string]: any;
17+
}
18+
19+
export interface FormData {
20+
name: string;
21+
form_json: FormJson;
22+
}
23+
24+
export interface FormResponse {
25+
id: string;
26+
name: string;
27+
created_at: string;
28+
updated_at: string;
29+
published_at: string | null;
30+
draft_json: FormJson;
31+
published_json: FormJson;
32+
is_published: boolean;
33+
}
34+
35+
export class PreAwardApiClient {
36+
private baseUrl: string;
37+
38+
constructor() {
39+
this.baseUrl = config.preAwardApiUrl;
40+
}
41+
42+
async createOrUpdateForm(formData: FormData): Promise<FormResponse>{
43+
const payload = formData;
44+
45+
try{
46+
const { payload: responseData } = await Wreck.post(
47+
`${this.baseUrl}/forms`,
48+
{
49+
payload: JSON.stringify(payload),
50+
headers: {
51+
'Content-Type': 'application/json'
52+
}
53+
}
54+
);
55+
const parsedData = JSON.parse((responseData as Buffer).toString());
56+
return parsedData as FormResponse;
57+
}
58+
catch (error) {
59+
throw error;
60+
}
61+
}
62+
63+
async getAllForms(): Promise<FormResponse[]> {
64+
try {
65+
const { payload: responseData } = await Wreck.get(
66+
`${this.baseUrl}/forms`,
67+
{
68+
headers: {
69+
'Content-Type': 'application/json'
70+
}
71+
}
72+
);
73+
74+
const parsedData = JSON.parse((responseData as Buffer).toString());
75+
return parsedData as FormResponse[];
76+
} catch (error) {
77+
throw error;
78+
}
79+
}
80+
81+
async getFormDraft(name: string): Promise<FormJson>{
82+
try{
83+
const { payload: responseData } = await Wreck.get(
84+
`${this.baseUrl}/forms/${name}/draft`,
85+
{
86+
headers: {
87+
'Content-Type': 'application/json'
88+
}
89+
}
90+
);
91+
const parsedData = JSON.parse((responseData as Buffer).toString());
92+
return parsedData as FormJson;
93+
}
94+
catch (error) {
95+
throw error;
96+
}
97+
}
98+
}
99+
100+
export const preAwardApiClient = new PreAwardApiClient();

0 commit comments

Comments
 (0)