-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ts
61 lines (47 loc) · 1.59 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Context } from "@azure/functions";
import * as t from "io-ts";
import { UTCISODateFromString } from "@pagopa/ts-commons/lib/dates";
import {
IPString,
NonEmptyString,
PatternString
} from "@pagopa/ts-commons/lib/strings";
import { initTelemetryClient } from "../utils/appinsights";
import { getConfigOrThrow } from "../utils/config";
import { encryptAndStore } from "./handler";
const config = getConfigOrThrow();
/**
* Payload of the message retrieved from the queue
* (one for each SPID request or response).
*/
export const SpidMsgItem = t.intersection([
t.interface({
// Timestamp of Request/Response creation
createdAt: UTCISODateFromString,
// Date of the SPID request / response in YYYY-MM-DD format
createdAtDay: PatternString("^[0-9]{4}-[0-9]{2}-[0-9]{2}$"),
// IP of the client that made a SPID login action
ip: IPString,
// login type value
loginType: NonEmptyString,
// XML payload of the SPID Request
requestPayload: t.string,
// XML payload of the SPID Response
responsePayload: t.string,
// SPID request ID
spidRequestId: t.string
}),
t.partial({
// SPID user fiscal code
fiscalCode: t.string
})
]);
export type SpidMsgItem = t.TypeOf<typeof SpidMsgItem>;
// Initialize application insights
initTelemetryClient();
/**
* Store SPID request / responses, read from a queue, into a blob storage.
*/
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const index = (context: Context, spidMsgItem: SpidMsgItem) =>
encryptAndStore(context, spidMsgItem, config.SPID_LOGS_PUBLIC_KEY);