-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: [IOCOM-1561] FIMS history saga (#5920)
## Short description This pr adds the implementation and barebones testing UI for the FIMS history flow ## List of changes proposed in this pull request - required Saga and actions - typedef to use with the client generator for FIMS' history calls - updated io-services-metadata definitions in order to include the newly added feature flag - listItem in privacyHomeScreen to show the FIMS history, hidden by the new feature flag - required selectors - new FIMS client - rename of FIMS features to not use uppercase characters - various navigators entries where required ## How to test running `io-dev-server`, while checked out in the `feature/fims` branch, go into profile>privacy and click the `FIMS_HISTORY` listItem, you should be greeted by a list of dates, which are the FIMS access dates. complete UI and export request to come in future PRs --------- Co-authored-by: Andrea <andrea.piai@pagopa.it>
- Loading branch information
Showing
20 changed files
with
419 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: IO (FIMS) | ||
version: 1.0.0 | ||
|
||
security: | ||
- Bearer: [] | ||
|
||
paths: | ||
/api/v1/fims/consents: | ||
get: | ||
operationId: getConsents | ||
parameters: | ||
- $ref: "#/components/parameters/continuationToken" | ||
responses: | ||
200: | ||
description: "OK" | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/ConsentsResponseDTO" | ||
401: | ||
description: Bearer token null or expired. | ||
502: | ||
description: Bad gateway. | ||
504: | ||
description: Gateway timeout. | ||
500: | ||
description: Service unavailable. | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/ProblemJson" | ||
|
||
/api/v1/fims/exports: | ||
post: | ||
operationId: exports | ||
requestBody: | ||
$ref: "#/components/requestBodies/Export" | ||
responses: | ||
202: | ||
description: Accepted | ||
409: | ||
description: Conflict | ||
401: | ||
description: Bearer token null or expired. | ||
502: | ||
description: Bad gateway. | ||
504: | ||
description: Gateway timeout. | ||
500: | ||
description: Service unavailable. | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/ProblemJson" | ||
|
||
|
||
components: | ||
securitySchemes: | ||
Bearer: | ||
type: http | ||
scheme: bearer | ||
bearerFormat: JWT | ||
|
||
parameters: | ||
continuationToken: | ||
name: continuationToken | ||
in: query | ||
required: false | ||
schema: | ||
type: string | ||
|
||
requestBodies: | ||
Export: | ||
description: Require an export | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
type: | ||
type: string | ||
enum: ["consent"] | ||
required: | ||
- type | ||
|
||
schemas: | ||
ConsentsResponseDTO: | ||
type: object | ||
properties: | ||
items: | ||
type: array | ||
items: | ||
$ref: "#/components/schemas/Consent" | ||
continuationToken: | ||
type: string | ||
required: | ||
- items | ||
- continuationToken | ||
|
||
ProblemJson: | ||
$ref: "https://raw.githubusercontent.com/pagopa/io-functions-commons/v26.3.0/openapi/definitions.yaml#/ProblemJson" | ||
|
||
Consent: | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
format: ulid | ||
service_id: | ||
type: string | ||
format: ulid | ||
redirect: | ||
type: object | ||
properties: | ||
uri: | ||
type: string | ||
format: uri | ||
display_name: | ||
type: string | ||
timestamp: | ||
$ref: "https://raw.githubusercontent.com/pagopa/io-functions-commons/v26.3.0/openapi/definitions.yaml#/Timestamp" | ||
required: | ||
- id | ||
- service_id | ||
- timestamp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { createStackNavigator } from "@react-navigation/stack"; | ||
import * as React from "react"; | ||
import { FimsHistoryScreen } from "../../history/screens/HistoryScreen"; | ||
import { | ||
FimsFlowHandlerScreen, | ||
FimsFlowHandlerScreenRouteParams | ||
} from "../../singleSignOn/screens/FimsFlowHandlerScreen"; | ||
|
||
export const FIMS_ROUTES = { | ||
MAIN: "FIMS_MAIN", | ||
CONSENTS: "FIMS_SSO_CONSENTS", | ||
HISTORY: "FIMS_HISTORY" | ||
} as const; | ||
|
||
export type FimsParamsList = { | ||
[FIMS_ROUTES.MAIN]: undefined; | ||
[FIMS_ROUTES.CONSENTS]: FimsFlowHandlerScreenRouteParams; | ||
[FIMS_ROUTES.HISTORY]: undefined; | ||
}; | ||
|
||
const Stack = createStackNavigator<FimsParamsList>(); | ||
|
||
export const FimsNavigator = () => ( | ||
<Stack.Navigator | ||
initialRouteName={FIMS_ROUTES.MAIN} | ||
// Make sure to disable gestures in order to prevent | ||
// the user from going back by swiping and thus not | ||
// calling the custom cancel logic | ||
screenOptions={{ gestureEnabled: false, headerShown: true }} | ||
> | ||
<Stack.Screen | ||
name={FIMS_ROUTES.CONSENTS} | ||
component={FimsFlowHandlerScreen} | ||
/> | ||
<Stack.Screen name={FIMS_ROUTES.HISTORY} component={FimsHistoryScreen} /> | ||
</Stack.Navigator> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
import { SagaIterator } from "redux-saga"; | ||
import { fork } from "typed-redux-saga/macro"; | ||
import { fork, select } from "typed-redux-saga/macro"; | ||
import { apiUrlPrefix } from "../../../../config"; | ||
import { sessionTokenSelector } from "../../../../store/reducers/authentication"; | ||
import { createFimsClient } from "../../history/api/client"; | ||
import { watchFimsHistorySaga } from "../../history/saga"; | ||
import { watchFimsSSOSaga } from "../../singleSignOn/saga"; | ||
|
||
const FIMS_DEV_ENV_TOKEN = ""; | ||
|
||
export function* watchFimsSaga(): SagaIterator { | ||
const fimsClient = createFimsClient(apiUrlPrefix); | ||
|
||
const sessionToken = yield* select(sessionTokenSelector); | ||
yield* fork(watchFimsSSOSaga); | ||
yield* fork( | ||
watchFimsHistorySaga, | ||
fimsClient, | ||
sessionToken ?? FIMS_DEV_ENV_TOKEN | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { FimsHistoryActions } from "../../history/store/actions"; | ||
import { FimsSSOActions } from "../../singleSignOn/store/actions"; | ||
|
||
export type FimsActions = FimsSSOActions; | ||
export type FimsActions = FimsSSOActions | FimsHistoryActions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createClient } from "../../../../../definitions/fims/client"; | ||
import { defaultRetryingFetch } from "../../../../utils/fetch"; | ||
|
||
export const createFimsClient = (baseUrl: string) => | ||
createClient({ | ||
baseUrl, | ||
fetchApi: defaultRetryingFetch() | ||
}); | ||
|
||
export type FimsHistoryClient = ReturnType<typeof createFimsClient>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as E from "fp-ts/lib/Either"; | ||
import { pipe } from "fp-ts/lib/function"; | ||
import { call, put } from "typed-redux-saga/macro"; | ||
import { ActionType } from "typesafe-actions"; | ||
import { SagaCallReturnType } from "../../../../types/utils"; | ||
import { withRefreshApiCall } from "../../../fastLogin/saga/utils"; | ||
import { FimsHistoryClient } from "../api/client"; | ||
import { fimsHistoryGet } from "../store/actions"; | ||
|
||
export function* handleGetFimsHistorySaga( | ||
getFimsHistory: FimsHistoryClient["getConsents"], | ||
bearerToken: string, | ||
action: ActionType<typeof fimsHistoryGet.request> | ||
) { | ||
const getHistoryRequest = getFimsHistory({ | ||
Bearer: bearerToken, | ||
continuationToken: action.payload.continuationToken | ||
}); | ||
|
||
try { | ||
const getHistoryResult = (yield* call( | ||
withRefreshApiCall, | ||
getHistoryRequest, | ||
action | ||
)) as SagaCallReturnType<typeof getFimsHistory>; | ||
|
||
const resultAction = yield* call( | ||
extractFimsHistoryResponseAction, | ||
getHistoryResult | ||
); | ||
yield* put(resultAction); | ||
} catch (e) { | ||
yield* put(fimsHistoryGet.failure((e as Error).toString())); | ||
} | ||
} | ||
|
||
const extractFimsHistoryResponseAction = ( | ||
historyResult: SagaCallReturnType<FimsHistoryClient["getConsents"]> | ||
) => | ||
pipe( | ||
historyResult, | ||
E.fold( | ||
error => fimsHistoryGet.failure(error.toString()), | ||
response => | ||
response.status === 200 | ||
? fimsHistoryGet.success(response.value) | ||
: fimsHistoryGet.failure("GENERIC_NON_200") | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { takeLatest } from "typed-redux-saga/macro"; | ||
import { FimsHistoryClient } from "../api/client"; | ||
import { fimsHistoryGet } from "../store/actions"; | ||
import { handleGetFimsHistorySaga } from "./handleGetFimsHistorySaga"; | ||
|
||
export function* watchFimsHistorySaga( | ||
client: FimsHistoryClient, | ||
bearerToken: string | ||
) { | ||
yield* takeLatest( | ||
fimsHistoryGet.request, | ||
handleGetFimsHistorySaga, | ||
client.getConsents, | ||
bearerToken | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { VSpacer } from "@pagopa/io-app-design-system"; | ||
import * as pot from "@pagopa/ts-commons/lib/pot"; | ||
import * as React from "react"; | ||
import { SafeAreaView, Text, View } from "react-native"; | ||
import LoadingScreenContent from "../../../../components/screens/LoadingScreenContent"; | ||
import { useHeaderSecondLevel } from "../../../../hooks/useHeaderSecondLevel"; | ||
import { useIODispatch, useIOSelector } from "../../../../store/hooks"; | ||
import { fimsHistoryGet } from "../store/actions"; | ||
import { fimsHistoryPotSelector } from "../store/selectors"; | ||
|
||
export const FimsHistoryScreen = () => { | ||
const dispatch = useIODispatch(); | ||
const historyPot = useIOSelector(fimsHistoryPotSelector); | ||
|
||
React.useEffect(() => { | ||
dispatch(fimsHistoryGet.request({})); | ||
}, [dispatch]); | ||
|
||
useHeaderSecondLevel({ | ||
title: "History" | ||
}); | ||
if (pot.isLoading(historyPot)) { | ||
return <LoadingScreenContent contentTitle="" />; | ||
} | ||
const history = pot.toUndefined(historyPot)?.items ?? []; | ||
|
||
return ( | ||
<SafeAreaView style={{ flex: 1 }}> | ||
{history.map((item, index) => ( | ||
<View key={index}> | ||
<Text>{item.timestamp.toDateString()}</Text> | ||
<VSpacer size={8} /> | ||
</View> | ||
))} | ||
</SafeAreaView> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ActionType, createAsyncAction } from "typesafe-actions"; | ||
import { ConsentsResponseDTO } from "../../../../../../definitions/fims/ConsentsResponseDTO"; | ||
|
||
export type FimsHistoryGetPayloadType = { | ||
continuationToken?: string; | ||
}; | ||
|
||
export const fimsHistoryGet = createAsyncAction( | ||
"FIMS_GET_HISTORY_REQUEST", | ||
"FIMS_GET_HISTORY_SUCCESS", | ||
"FIMS_GET_HISTORY_FAILURE" | ||
)<FimsHistoryGetPayloadType, ConsentsResponseDTO, string>(); | ||
|
||
export type FimsHistoryActions = ActionType<typeof fimsHistoryGet>; |
Oops, something went wrong.