Skip to content

Commit ac1afd7

Browse files
feat: add FIMS endpoints
1 parent 4369c11 commit ac1afd7

File tree

13 files changed

+874
-2
lines changed

13 files changed

+874
-2
lines changed

.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ROOT_REDIRECT_URL=https://io.italia.it
3232
FF_BONUS_ENABLED=1
3333
FF_CGN_ENABLED=1
3434
FF_IO_SIGN_ENABLED=1
35+
FF_IO_FIMS_ENABLED=1
3536
FF_IO_WALLET_ENABLED=1
3637
FF_IO_WALLET_TRIAL_ENABLED=1
3738

@@ -49,6 +50,13 @@ IO_SIGN_API_URL=http://host.docker.internal:7075
4950
IO_SIGN_API_BASE_PATH="/api/v1/sign"
5051
IO_SIGN_SERVICE_ID="aIoSignServiceId"
5152

53+
# ------------------------------------
54+
# IO_FIMS Env Variables
55+
# ------------------------------------
56+
IO_FIMS_API_KEY=put_your_api_key_here
57+
IO_FIMS_API_URL=http://host.docker.internal:7075
58+
IO_FIMS_API_BASE_PATH="/api/v1/fims"
59+
5260
# ------------------------------------
5361
# CGN Env Variables
5462
# ------------------------------------

api_io_fims.yaml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
openapi: 3.0.1
2+
info:
3+
version: 1.0.1
4+
title: IO FIMS - Backend API
5+
servers:
6+
- url: https://api-app.io.pagopa.it/api/v1/fims
7+
security:
8+
- Bearer: []
9+
10+
paths:
11+
/accesses:
12+
get:
13+
summary: Get access history
14+
description: Get the access history for the specified user
15+
operationId: getAccessHistory
16+
parameters:
17+
- in: query
18+
name: page
19+
schema:
20+
type: string
21+
description: The page identifier
22+
- in: header
23+
name: Accept-Language
24+
required: false
25+
schema:
26+
type: string
27+
responses:
28+
"200":
29+
description: An access history page
30+
content:
31+
application/json:
32+
schema:
33+
$ref: "#/components/schemas/AccessHistoryPage"
34+
"400":
35+
description: Validation error
36+
content:
37+
application/json:
38+
schema:
39+
$ref: "#/components/schemas/ProblemJson"
40+
"500":
41+
description: Internal server error
42+
content:
43+
application/json:
44+
schema:
45+
$ref: "#/components/schemas/ProblemJson"
46+
47+
/export-requests:
48+
post:
49+
summary: Request export
50+
description: Request the export of the access history for the specified user
51+
operationId: requestExport
52+
responses:
53+
"202":
54+
description: The export request has been accepted
55+
content:
56+
application/json:
57+
schema:
58+
$ref: "#/components/schemas/ExportRequest"
59+
"409":
60+
description: The export request has already been requested
61+
content:
62+
application/json:
63+
schema:
64+
$ref: "#/components/schemas/ProblemJson"
65+
"400":
66+
description: Validation error
67+
content:
68+
application/json:
69+
schema:
70+
$ref: "#/components/schemas/ProblemJson"
71+
"500":
72+
description: Internal server error
73+
content:
74+
application/json:
75+
schema:
76+
$ref: "#/components/schemas/ProblemJson"
77+
78+
components:
79+
securitySchemes:
80+
Bearer:
81+
type: apiKey
82+
name: Authorization
83+
in: header
84+
85+
schemas:
86+
Timestamp:
87+
$ref: "https://raw.githubusercontent.com/pagopa/io-functions-commons/v26.3.0/openapi/definitions.yaml#/Timestamp"
88+
89+
ProblemJson:
90+
$ref: "https://raw.githubusercontent.com/pagopa/io-functions-commons/v26.3.0/openapi/definitions.yaml#/ProblemJson"
91+
92+
Redirect:
93+
type: object
94+
properties:
95+
display_name:
96+
type: string
97+
uri:
98+
type: string
99+
format: uri
100+
required:
101+
- display_name
102+
- uri
103+
104+
Access:
105+
type: object
106+
properties:
107+
id:
108+
type: string
109+
format: ulid
110+
redirect:
111+
$ref: "#/components/schemas/Redirect"
112+
service_id:
113+
type: string
114+
format: ulid
115+
timestamp:
116+
$ref: "#/components/schemas/Timestamp"
117+
required:
118+
- id
119+
- redirect
120+
- service_id
121+
- timestamp
122+
123+
AccessHistoryPage:
124+
type: object
125+
properties:
126+
data:
127+
type: array
128+
items:
129+
$ref: "#/components/schemas/Access"
130+
next:
131+
type: string
132+
required:
133+
- data
134+
135+
ExportRequest:
136+
type: object
137+
properties:
138+
id:
139+
type: string
140+
format: ulid
141+
required:
142+
- id

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@
4343
"generate:proxy:bonus-models": "rimraf generated/bonus && gen-api-models --api-spec api_bonus.yaml --out-dir generated/bonus",
4444
"generate:proxy:cgn-models": "rimraf generated/cgn && gen-api-models --api-spec api_cgn.yaml --out-dir generated/cgn",
4545
"generate:proxy:io-sign-models": "rimraf generated/io-sign && gen-api-models --api-spec api_io_sign.yaml --out-dir generated/io-sign",
46+
"generate:proxy:io-fims-models": "rimraf generated/io-fims && gen-api-models --api-spec api_io_fims.yaml --out-dir generated/io-fims",
4647
"generate:proxy:cgn-operator-search-models": "rimraf generated/cgn-operator-search && gen-api-models --api-spec api_cgn_operator_search.yaml --out-dir generated/cgn-operator-search",
4748
"generate:api:io-bonus": "rimraf generated/io-bonus-api && gen-api-models --api-spec openapi/consumed/fn_bonus.yaml --no-strict --out-dir generated/io-bonus-api --request-types --response-decoders --client",
4849
"generate:api:io-sign": "rimraf generated/io-sign-api && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-sign/0a9124b7c782b2569dd82c094496e50a17b418f4/apps/io-func-sign-user/openapi.yaml --no-strict --out-dir generated/io-sign-api --request-types --response-decoders --client",
50+
"generate:api:io-fims": "rimraf generated/io-fims-api && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-fims/44c478f9b9ca024aa4db963873a85f8d9c37f5d3/apps/user-func/openapi.yaml --no-strict --out-dir generated/io-fims-api --request-types --response-decoders --client",
4951
"generate:api:io-cgn-operator-search": "rimraf generated/io-cgn-operator-search-api && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-cgn/refs/tags/search-func@3.3.0/apps/search-func/openapi/index.yaml --no-strict --out-dir generated/io-cgn-operator-search-api --request-types --response-decoders --client",
5052
"generate:api:pagopaproxy": "rimraf generated/pagopa-proxy && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-pagopa-proxy/v1.6.0/api-spec/api-for-io.yaml --no-strict --out-dir generated/pagopa-proxy --request-types --response-decoders --client",
5153
"generate:api:lollipop": "rimraf generated/lollipop-api && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-functions-lollipop/724c3ba79d272d4e2555dbc2a8e1657bec9f84ce/openapi/internal.yaml --no-strict --out-dir generated/lollipop-api --request-types --response-decoders --client",

src/__tests__/app.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const aMyPortalBasePath = "/myportal/api/v1";
6565
const aCgnAPIBasePath = "/api/v1/cgn";
6666
const aCgnOperatorSearchAPIBasePath = "/api/v1/cgn-operator-search";
6767
const aEuCovidCertAPIBasePath = "/api/v1/eucovidcert";
68+
const aIoFimsAPIBasePath = "/api/v1/fims";
6869
const aIoSignAPIBasePath = "/api/v1/sign";
6970
const aServicesAppBackendBasePath = "/api/v2";
7071
const aTrialSystemBasePath = "/trials/api/v1";
@@ -80,6 +81,7 @@ describe("Success app start", () => {
8081
CGNAPIBasePath: aCgnAPIBasePath,
8182
CGNOperatorSearchAPIBasePath: aCgnOperatorSearchAPIBasePath,
8283
EUCovidCertBasePath: aEuCovidCertAPIBasePath,
84+
IoFimsAPIBasePath: aIoFimsAPIBasePath,
8385
IoSignAPIBasePath: aIoSignAPIBasePath,
8486
IoWalletAPIBasePath: aIoWalletAPIBasePath,
8587
MyPortalBasePath: aMyPortalBasePath,
@@ -188,6 +190,7 @@ describe("Failure app start", () => {
188190
CGNAPIBasePath: aCgnAPIBasePath,
189191
CGNOperatorSearchAPIBasePath: aCgnOperatorSearchAPIBasePath,
190192
EUCovidCertBasePath: aEuCovidCertAPIBasePath,
193+
IoFimsAPIBasePath: aIoFimsAPIBasePath,
191194
IoSignAPIBasePath: aIoSignAPIBasePath,
192195
IoWalletAPIBasePath: aIoWalletAPIBasePath,
193196
MyPortalBasePath: aMyPortalBasePath,

src/app.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ import {
4141
FF_ENABLE_SESSION_ENDPOINTS,
4242
FF_EUCOVIDCERT_ENABLED,
4343
FF_IO_SIGN_ENABLED,
44+
FF_IO_FIMS_ENABLED,
4445
FF_IO_WALLET_ENABLED,
4546
FF_ROUTING_PUSH_NOTIF,
4647
FF_ROUTING_PUSH_NOTIF_BETA_TESTER_SHA_LIST,
4748
FF_ROUTING_PUSH_NOTIF_CANARY_SHA_USERS_REGEX,
4849
FF_TRIAL_SYSTEM_ENABLED,
4950
FIRST_LOLLIPOP_CONSUMER_CLIENT,
5051
IO_SIGN_API_CLIENT,
52+
IO_FIMS_API_CLIENT,
5153
IO_SIGN_SERVICE_ID,
5254
IO_WALLET_API_CLIENT,
5355
LOCKED_PROFILES_STORAGE_CONNECTION_STRING,
@@ -105,6 +107,7 @@ import CgnService from "./services/cgnService";
105107
import EUCovidCertService from "./services/eucovidcertService";
106108
import FunctionsAppService from "./services/functionAppService";
107109
import IoSignService from "./services/ioSignService";
110+
import IoFimsService from "./services/fimsService";
108111
import LollipopService from "./services/lollipopService";
109112
import NewMessagesService from "./services/newMessagesService";
110113
import NotificationService from "./services/notificationService";
@@ -140,6 +143,7 @@ import TrialService from "./services/trialService";
140143
import TrialController from "./controllers/trialController";
141144
import IoWalletController from "./controllers/ioWalletController";
142145
import IoWalletService from "./services/ioWalletService";
146+
import IoFimsController from "./controllers/fimsController";
143147

144148
const defaultModule = {
145149
// eslint-disable-next-line @typescript-eslint/no-use-before-define
@@ -159,6 +163,7 @@ export interface IAppFactoryParameters {
159163
readonly CGNAPIBasePath: string;
160164
readonly CGNOperatorSearchAPIBasePath: string;
161165
readonly IoSignAPIBasePath: string;
166+
readonly IoFimsAPIBasePath: string;
162167
readonly IoWalletAPIBasePath: string;
163168
readonly EUCovidCertBasePath: string;
164169
readonly ServicesAppBackendBasePath: string;
@@ -178,6 +183,7 @@ export async function newApp({
178183
MyPortalBasePath,
179184
CGNAPIBasePath,
180185
IoSignAPIBasePath,
186+
IoFimsAPIBasePath,
181187
IoWalletAPIBasePath,
182188
CGNOperatorSearchAPIBasePath,
183189
EUCovidCertBasePath,
@@ -326,6 +332,9 @@ export async function newApp({
326332
// Create the io sign
327333
const IO_SIGN_SERVICE = new IoSignService(IO_SIGN_API_CLIENT);
328334

335+
// Create the io fims service
336+
const IO_FIMS_SERVICE = new IoFimsService(IO_FIMS_API_CLIENT);
337+
329338
// Create the cgn operator search service
330339
const CGN_OPERATOR_SEARCH_SERVICE = new CgnOperatorSearchService(
331340
CGN_OPERATOR_SEARCH_API_CLIENT
@@ -512,6 +521,17 @@ export async function newApp({
512521
);
513522
}
514523

524+
if (FF_IO_FIMS_ENABLED) {
525+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
526+
registerIoFimsAPIRoutes(
527+
app,
528+
IoFimsAPIBasePath,
529+
IO_FIMS_SERVICE,
530+
PROFILE_SERVICE,
531+
authMiddlewares.bearerSession
532+
);
533+
}
534+
515535
if (FF_EUCOVIDCERT_ENABLED) {
516536
// eslint-disable-next-line @typescript-eslint/no-use-before-define
517537
registerEUCovidCertAPIRoutes(
@@ -1161,6 +1181,32 @@ function registerIoSignAPIRoutes(
11611181
);
11621182
}
11631183

1184+
function registerIoFimsAPIRoutes(
1185+
app: Express,
1186+
basePath: string,
1187+
ioFimsService: IoFimsService,
1188+
profileService: ProfileService,
1189+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1190+
bearerSessionTokenAuth: any
1191+
): void {
1192+
const ioFimsController: IoFimsController = new IoFimsController(
1193+
ioFimsService,
1194+
profileService
1195+
);
1196+
1197+
app.get(
1198+
`${basePath}/accesses`,
1199+
bearerSessionTokenAuth,
1200+
toExpressHandler(ioFimsController.getAccessHistory, ioFimsController)
1201+
);
1202+
1203+
app.post(
1204+
`${basePath}/export-requests`,
1205+
bearerSessionTokenAuth,
1206+
toExpressHandler(ioFimsController.requestExport, ioFimsController)
1207+
);
1208+
}
1209+
11641210
function registerCgnOperatorSearchAPIRoutes(
11651211
app: Express,
11661212
basePath: string,

src/clients/io-fims.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import nodeFetch from "node-fetch";
2+
import { Client, createClient } from "../../generated/io-fims-api/client";
3+
4+
export function IoFimsAPIClient(
5+
token: string,
6+
baseUrl: string,
7+
basePath: string,
8+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9+
fetchApi: typeof fetch = nodeFetch as any as typeof fetch
10+
): Client<"FunctionsKey"> {
11+
return createClient<"FunctionsKey">({
12+
basePath,
13+
baseUrl,
14+
fetchApi,
15+
withDefaults: (op) => (params) =>
16+
op({
17+
...params,
18+
FunctionsKey: token,
19+
}),
20+
});
21+
}
22+
23+
export type IoFimsAPIClient = typeof IoFimsAPIClient;

src/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { LollipopApiClient } from "./clients/lollipop";
4646
import { FirstLollipopConsumerClient } from "./clients/firstLollipopConsumer";
4747
import { TrialSystemAPIClient } from "./clients/trial-system.client";
4848
import { IoWalletAPIClient } from "./clients/io-wallet";
49+
import { IoFimsAPIClient } from "./clients/io-fims";
4950

5051
// Without this, the environment variables loaded by dotenv aren't available in
5152
// this file.
@@ -187,6 +188,16 @@ export const IO_SIGN_API_CLIENT = IoSignAPIClient(
187188
httpOrHttpsApiFetch
188189
);
189190

191+
export const IO_FIMS_API_KEY = getRequiredENVVar("IO_FIMS_API_KEY");
192+
export const IO_FIMS_API_URL = getRequiredENVVar("IO_FIMS_API_URL");
193+
export const IO_FIMS_API_BASE_PATH = getRequiredENVVar("IO_FIMS_API_BASE_PATH");
194+
export const IO_FIMS_API_CLIENT = IoFimsAPIClient(
195+
IO_FIMS_API_KEY,
196+
IO_FIMS_API_URL,
197+
IO_FIMS_API_BASE_PATH,
198+
httpOrHttpsApiFetch
199+
);
200+
190201
export const CGN_API_KEY = getRequiredENVVar("CGN_API_KEY");
191202
export const CGN_API_URL = getRequiredENVVar("CGN_API_URL");
192203
export const CGN_API_BASE_PATH = getRequiredENVVar("CGN_API_BASE_PATH");
@@ -422,6 +433,7 @@ export const DEFAULT_APPINSIGHTS_SAMPLING_PERCENTAGE = 5;
422433
export const FF_BONUS_ENABLED = process.env.FF_BONUS_ENABLED === "1";
423434
export const FF_CGN_ENABLED = process.env.FF_CGN_ENABLED === "1";
424435
export const FF_IO_SIGN_ENABLED = process.env.FF_IO_SIGN_ENABLED === "1";
436+
export const FF_IO_FIMS_ENABLED = process.env.FF_IO_FIMS_ENABLED === "1";
425437
export const FF_EUCOVIDCERT_ENABLED =
426438
process.env.FF_EUCOVIDCERT_ENABLED === "1";
427439

0 commit comments

Comments
 (0)