@ndbs-dk/afu-shared-services 2.5.34 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers/altinn-helper.d.ts +1 -26
- package/dist/helpers/altinn-helper.d.ts.map +1 -1
- package/dist/helpers/altinn-helper.js +27 -96
- package/dist/helpers/altinn-helper.js.map +1 -1
- package/dist/services/altinn-service.d.ts +14 -7
- package/dist/services/altinn-service.d.ts.map +1 -1
- package/dist/services/altinn-service.js +87 -44
- package/dist/services/altinn-service.js.map +1 -1
- package/dist/services/sf-service.d.ts +5 -1
- package/dist/services/sf-service.d.ts.map +1 -1
- package/dist/services/sf-service.js +54 -14
- package/dist/services/sf-service.js.map +1 -1
- package/dist/test/altinn-service.test.js +1 -1
- package/dist/test/altinn-service.test.js.map +1 -1
- package/dist/test/scripts/test-altinn-fetch.js +49 -24
- package/dist/test/scripts/test-altinn-fetch.js.map +1 -1
- package/dist/test/scripts/test-sf-fetch.d.ts +2 -0
- package/dist/test/scripts/test-sf-fetch.d.ts.map +1 -0
- package/dist/test/scripts/test-sf-fetch.js +35 -0
- package/dist/test/scripts/test-sf-fetch.js.map +1 -0
- package/dist/types/altinn.types.d.ts +77 -90
- package/dist/types/altinn.types.d.ts.map +1 -1
- package/dist/types/sf.types.d.ts +16 -0
- package/dist/types/sf.types.d.ts.map +1 -1
- package/dist/utils/altinn-util.d.ts +5 -29
- package/dist/utils/altinn-util.d.ts.map +1 -1
- package/dist/utils/altinn-util.js +49 -147
- package/dist/utils/altinn-util.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import https from "https";
|
|
2
1
|
import { type Destination } from "@sap-cloud-sdk/connectivity";
|
|
3
2
|
import type { AltinnDestinationConfig, SickLeaveInfoSummary } from "../types/altinn.types.js";
|
|
4
|
-
/**
|
|
5
|
-
* Creates an HTTPS agent for Altinn requests with the given certificates and passphrase.
|
|
6
|
-
* @param cert Certificate buffer
|
|
7
|
-
* @param key Key buffer
|
|
8
|
-
* @param ca CA buffer
|
|
9
|
-
* @param passphrase Optional passphrase for the key/cert
|
|
10
|
-
*/
|
|
11
|
-
export declare function createAltinnHttpsAgent(cert: Buffer, key: Buffer, ca: Buffer, passphrase?: string): https.Agent;
|
|
12
3
|
/**
|
|
13
4
|
* Validates required Altinn config and returns the config object.
|
|
14
5
|
* @param destination The Altinn destination object
|
|
@@ -19,19 +10,6 @@ export declare function createAltinnHttpsAgent(cert: Buffer, key: Buffer, ca: Bu
|
|
|
19
10
|
* // config has properties: authEndpoint, apiKey, username, password, organizationNumbers (optional)
|
|
20
11
|
*/
|
|
21
12
|
export declare function getValidAltinnConfig(destination: Destination): AltinnDestinationConfig;
|
|
22
|
-
/**
|
|
23
|
-
* Creates the request data for Altinn authentication.
|
|
24
|
-
* @param username Altinn username
|
|
25
|
-
* @param password Altinn password
|
|
26
|
-
* @returns The request data object
|
|
27
|
-
* @example
|
|
28
|
-
* const requestData = createAuthRequestData("myUsername", "myPassword");
|
|
29
|
-
* // requestData = { UserName: "myUsername", UserPassword: "myPassword" }
|
|
30
|
-
*/
|
|
31
|
-
export declare function createAuthRequestData(username: string, password: string): {
|
|
32
|
-
UserName: string;
|
|
33
|
-
UserPassword: string;
|
|
34
|
-
};
|
|
35
13
|
/**
|
|
36
14
|
* Fetches cases from Altinn API.
|
|
37
15
|
* @param destination Destination config
|
|
@@ -41,11 +19,8 @@ export declare function createAuthRequestData(username: string, password: string
|
|
|
41
19
|
* @param accessToken Valid Altinn access token (cookie)
|
|
42
20
|
* @param endpoint (optional) Altinn cases endpoint (default: '/api/cases')
|
|
43
21
|
*/
|
|
44
|
-
export declare function fetchAltinnCases({ destination,
|
|
22
|
+
export declare function fetchAltinnCases({ destination, accessToken, who, dateFrom, dateTo }: {
|
|
45
23
|
destination: Destination;
|
|
46
|
-
cert: Buffer;
|
|
47
|
-
key: Buffer;
|
|
48
|
-
ca: Buffer;
|
|
49
24
|
accessToken: string;
|
|
50
25
|
who: string;
|
|
51
26
|
dateFrom?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"altinn-helper.d.ts","sourceRoot":"","sources":["../../src/helpers/altinn-helper.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"altinn-helper.d.ts","sourceRoot":"","sources":["../../src/helpers/altinn-helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,uBAAuB,EAAqD,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAGjJ;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,uBAAuB,CAetF;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,EACnC,WAAW,EACX,WAAW,EACX,GAAG,EACH,QAAuB,EACvB,MAAqB,EACxB,EAAE;IACC,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAClB,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC,CA4BlC"}
|
|
@@ -3,31 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createAltinnHttpsAgent = createAltinnHttpsAgent;
|
|
7
6
|
exports.getValidAltinnConfig = getValidAltinnConfig;
|
|
8
|
-
exports.createAuthRequestData = createAuthRequestData;
|
|
9
7
|
exports.fetchAltinnCases = fetchAltinnCases;
|
|
10
8
|
const axios_1 = __importDefault(require("axios"));
|
|
11
|
-
const https_1 = __importDefault(require("https"));
|
|
12
|
-
const xml_util_1 = require("../utils/xml-util");
|
|
13
9
|
const altinn_util_1 = require("../utils/altinn-util");
|
|
14
|
-
/**
|
|
15
|
-
* Creates an HTTPS agent for Altinn requests with the given certificates and passphrase.
|
|
16
|
-
* @param cert Certificate buffer
|
|
17
|
-
* @param key Key buffer
|
|
18
|
-
* @param ca CA buffer
|
|
19
|
-
* @param passphrase Optional passphrase for the key/cert
|
|
20
|
-
*/
|
|
21
|
-
function createAltinnHttpsAgent(cert, key, ca, passphrase) {
|
|
22
|
-
return new https_1.default.Agent({
|
|
23
|
-
cert,
|
|
24
|
-
key,
|
|
25
|
-
ca,
|
|
26
|
-
passphrase,
|
|
27
|
-
rejectUnauthorized: false,
|
|
28
|
-
secureOptions: require('crypto').constants.SSL_OP_LEGACY_SERVER_CONNECT
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
10
|
/**
|
|
32
11
|
* Validates required Altinn config and returns the config object.
|
|
33
12
|
* @param destination The Altinn destination object
|
|
@@ -40,30 +19,18 @@ function createAltinnHttpsAgent(cert, key, ca, passphrase) {
|
|
|
40
19
|
function getValidAltinnConfig(destination) {
|
|
41
20
|
if (!destination)
|
|
42
21
|
throw new Error(`Destination not found`);
|
|
43
|
-
const config = destination
|
|
44
|
-
const required = [
|
|
22
|
+
const config = destination;
|
|
23
|
+
const required = [
|
|
24
|
+
"authUrl", "organizationNumbers", "privateKey", "cliendId", "kid", "scopeSykepenger",
|
|
25
|
+
"systemuserOrgIso6523", "externalRef", "organizationNumbers"
|
|
26
|
+
];
|
|
45
27
|
for (const key of required) {
|
|
46
|
-
if (!config[key]) {
|
|
28
|
+
if (!config.originalProperties?.destinationConfiguration[key]) {
|
|
47
29
|
throw new Error(`Missing config: ${key}`);
|
|
48
30
|
}
|
|
49
31
|
}
|
|
50
32
|
return config;
|
|
51
33
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Creates the request data for Altinn authentication.
|
|
54
|
-
* @param username Altinn username
|
|
55
|
-
* @param password Altinn password
|
|
56
|
-
* @returns The request data object
|
|
57
|
-
* @example
|
|
58
|
-
* const requestData = createAuthRequestData("myUsername", "myPassword");
|
|
59
|
-
* // requestData = { UserName: "myUsername", UserPassword: "myPassword" }
|
|
60
|
-
*/
|
|
61
|
-
function createAuthRequestData(username, password) {
|
|
62
|
-
return {
|
|
63
|
-
UserName: username,
|
|
64
|
-
UserPassword: password
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
34
|
/**
|
|
68
35
|
* Fetches cases from Altinn API.
|
|
69
36
|
* @param destination Destination config
|
|
@@ -73,65 +40,29 @@ function createAuthRequestData(username, password) {
|
|
|
73
40
|
* @param accessToken Valid Altinn access token (cookie)
|
|
74
41
|
* @param endpoint (optional) Altinn cases endpoint (default: '/api/cases')
|
|
75
42
|
*/
|
|
76
|
-
async function fetchAltinnCases({ destination,
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
43
|
+
async function fetchAltinnCases({ destination, accessToken, who, dateFrom = '1970-01-01', dateTo = '2300-01-01' }) {
|
|
44
|
+
const baseUrl = destination.url || '';
|
|
45
|
+
const url = `${baseUrl}/v1/sykmeldinger`;
|
|
46
|
+
const data = {
|
|
47
|
+
"orgnr": who,
|
|
48
|
+
"fom": dateFrom,
|
|
49
|
+
"tom": dateTo,
|
|
50
|
+
};
|
|
51
|
+
const response = await axios_1.default.post(url, data, {
|
|
82
52
|
headers: {
|
|
83
|
-
'
|
|
84
|
-
'
|
|
85
|
-
'
|
|
86
|
-
}
|
|
87
|
-
params: {
|
|
88
|
-
dateFrom,
|
|
89
|
-
dateTo
|
|
90
|
-
},
|
|
91
|
-
httpsAgent
|
|
53
|
+
'Content-Type': 'application/json',
|
|
54
|
+
'Accept': '*/*',
|
|
55
|
+
'Authorization': `Bearer ${accessToken}`
|
|
56
|
+
}
|
|
92
57
|
});
|
|
93
|
-
const
|
|
94
|
-
if (!Array.isArray(
|
|
58
|
+
const sickLeaves = response.data;
|
|
59
|
+
if (!Array.isArray(sickLeaves)) {
|
|
95
60
|
return [];
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
headers: {
|
|
103
|
-
'Cookie': accessToken,
|
|
104
|
-
'ApiKey': config.apiKey,
|
|
105
|
-
'Content-Type': 'Application/hal+json',
|
|
106
|
-
'Accept': 'application/hal+json'
|
|
107
|
-
},
|
|
108
|
-
httpsAgent
|
|
109
|
-
});
|
|
110
|
-
const attachments = attRes.data;
|
|
111
|
-
const xmlAttachmentUrl = (0, altinn_util_1.findXmlAttachmentUrl)(attachments);
|
|
112
|
-
if (xmlAttachmentUrl) {
|
|
113
|
-
try {
|
|
114
|
-
const xmlString = await (0, altinn_util_1.fetchXmlString)(xmlAttachmentUrl, accessToken, config.apiKey, httpsAgent);
|
|
115
|
-
if (xmlString) {
|
|
116
|
-
try {
|
|
117
|
-
const parsed = await (0, xml_util_1.parseXmlToJson)(xmlString);
|
|
118
|
-
return (0, altinn_util_1.mapSickLeaveInfoFromXmlJson)(parsed);
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
catch {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
}))).filter((info) => info !== null);
|
|
135
|
-
return sickLeaveInfos;
|
|
61
|
+
}
|
|
62
|
+
const infoSummary = [];
|
|
63
|
+
for (const leave of sickLeaves) {
|
|
64
|
+
infoSummary.push((0, altinn_util_1.mapSickleaveInformation)(leave));
|
|
65
|
+
}
|
|
66
|
+
return infoSummary;
|
|
136
67
|
}
|
|
137
68
|
//# sourceMappingURL=altinn-helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"altinn-helper.js","sourceRoot":"","sources":["../../src/helpers/altinn-helper.ts"],"names":[],"mappings":";;;;;AAcA,
|
|
1
|
+
{"version":3,"file":"altinn-helper.js","sourceRoot":"","sources":["../../src/helpers/altinn-helper.ts"],"names":[],"mappings":";;;;;AAcA,oDAeC;AAWD,4CAwCC;AAhFD,kDAA0B;AAG1B,sDAA+D;AAE/D;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAAC,WAAwB;IACzD,IAAI,CAAC,WAAW;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,WAAsC,CAAC;IACtD,MAAM,QAAQ,GAAG;QACb,SAAS,EAAE,qBAAqB,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,iBAAiB;QACpF,sBAAsB,EAAE,aAAa,EAAE,qBAAqB;KAC/D,CAAC;IAEF,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,wBAAwB,CAAC,GAAkC,CAAC,EAAE,CAAC;YAC3F,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC;QAC9C,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,gBAAgB,CAAC,EACnC,WAAW,EACX,WAAW,EACX,GAAG,EACH,QAAQ,GAAG,YAAY,EACvB,MAAM,GAAG,YAAY,EAOxB;IACG,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,IAAI,EAAE,CAAC;IACtC,MAAM,GAAG,GAAG,GAAG,OAAO,kBAAkB,CAAC;IACzC,MAAM,IAAI,GAAG;QACT,OAAO,EAAE,GAAG;QACZ,KAAK,EAAE,QAAQ;QACf,KAAK,EAAE,MAAM;KAChB,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE;QACzC,OAAO,EAAE;YACL,cAAc,EAAE,kBAAkB;YAClC,QAAQ,EAAE,KAAK;YACf,eAAe,EAAE,UAAU,WAAW,EAAE;SAC3C;KACJ,CAAC,CAAC;IACH,MAAM,UAAU,GAAiC,QAAQ,CAAC,IAAI,CAAC;IAE/D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,OAAO,EAAE,CAAC;IACd,CAAC;IAED,MAAM,WAAW,GAA2B,EAAE,CAAC;IAE/C,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;QAC7B,WAAW,CAAC,IAAI,CAAC,IAAA,qCAAuB,EAAC,KAAK,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,WAAW,CAAC;AACvB,CAAC"}
|
|
@@ -2,14 +2,18 @@ import { AxiosResponse } from "axios";
|
|
|
2
2
|
import { type Destination } from "@sap-cloud-sdk/connectivity";
|
|
3
3
|
import { SickLeaveInfoSummary } from "../types/altinn.types";
|
|
4
4
|
export declare class AltinnService {
|
|
5
|
-
private destination;
|
|
6
5
|
accessToken: string;
|
|
7
|
-
private
|
|
8
|
-
private
|
|
9
|
-
private
|
|
10
|
-
private
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
private destination;
|
|
7
|
+
private privateKey;
|
|
8
|
+
private cliendId;
|
|
9
|
+
private kid;
|
|
10
|
+
private scopeSykepenger;
|
|
11
|
+
private systemuserOrgIso6523;
|
|
12
|
+
private externalRef;
|
|
13
|
+
private organizationNumbers;
|
|
14
|
+
constructor(destination: Destination);
|
|
15
|
+
/**
|
|
16
|
+
* Authenticates the user and retrieves an access token from Altinn.
|
|
13
17
|
* @returns The access token string
|
|
14
18
|
* @throws Error if authentication fails
|
|
15
19
|
* @example authenticate() => "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
@@ -28,5 +32,8 @@ export declare class AltinnService {
|
|
|
28
32
|
* @returns A promise that resolves to the response from Altinn
|
|
29
33
|
*/
|
|
30
34
|
postAltinn(formData: string, who: string): Promise<AxiosResponse>;
|
|
35
|
+
private getJwt;
|
|
36
|
+
private getAccessToken;
|
|
37
|
+
private parseDestinationConfig;
|
|
31
38
|
}
|
|
32
39
|
//# sourceMappingURL=altinn-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"altinn-service.d.ts","sourceRoot":"","sources":["../../src/services/altinn-service.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG/D,OAAO,
|
|
1
|
+
{"version":3,"file":"altinn-service.d.ts","sourceRoot":"","sources":["../../src/services/altinn-service.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG/D,OAAO,EAA8C,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAIzG,qBAAa,aAAa;IACjB,WAAW,EAAE,MAAM,CAAM;IAChC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,UAAU,CAAc;IAChC,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,GAAG,CAAc;IACzB,OAAO,CAAC,eAAe,CAAc;IACrC,OAAO,CAAC,oBAAoB,CAAc;IAC1C,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,mBAAmB,CAAc;gBAE7B,WAAW,EAAE,WAAW;IAKpC;;;;;OAKG;IACG,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IA4BrC;;;;;OAKG;IACG,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAiCvF;;;;OAIG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAgDvE,OAAO,CAAC,MAAM;YAiCA,cAAc;IA2B5B,OAAO,CAAC,sBAAsB;CAe/B"}
|
|
@@ -8,20 +8,24 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
8
8
|
const cache_util_1 = require("../utils/cache-util");
|
|
9
9
|
const altinn_helper_1 = require("../helpers/altinn-helper");
|
|
10
10
|
const altinn_util_1 = require("../utils/altinn-util");
|
|
11
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
12
|
+
const qs_1 = __importDefault(require("qs"));
|
|
11
13
|
class AltinnService {
|
|
12
|
-
destination;
|
|
13
14
|
accessToken = "";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
destination;
|
|
16
|
+
privateKey = "";
|
|
17
|
+
cliendId = "";
|
|
18
|
+
kid = "";
|
|
19
|
+
scopeSykepenger = "";
|
|
20
|
+
systemuserOrgIso6523 = "";
|
|
21
|
+
externalRef = "";
|
|
22
|
+
organizationNumbers = "";
|
|
23
|
+
constructor(destination) {
|
|
19
24
|
this.destination = destination;
|
|
20
|
-
this.
|
|
21
|
-
this.key = key;
|
|
22
|
-
this.ca = ca;
|
|
25
|
+
this.parseDestinationConfig();
|
|
23
26
|
}
|
|
24
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Authenticates the user and retrieves an access token from Altinn.
|
|
25
29
|
* @returns The access token string
|
|
26
30
|
* @throws Error if authentication fails
|
|
27
31
|
* @example authenticate() => "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
@@ -32,31 +36,13 @@ class AltinnService {
|
|
|
32
36
|
const cached = (0, cache_util_1.getCachedToken)('altinn');
|
|
33
37
|
if (cached)
|
|
34
38
|
return cached;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const httpsAgent = (0, altinn_helper_1.createAltinnHttpsAgent)(this.cert, this.key, this.ca, passphrase);
|
|
41
|
-
// Prepare request
|
|
42
|
-
const url = this.destination?.url + config.authEndpoint;
|
|
43
|
-
const data = (0, altinn_helper_1.createAuthRequestData)(config.username, config.password);
|
|
44
|
-
// Execute HTTP request
|
|
45
|
-
const response = await axios_1.default.post(url, data, {
|
|
46
|
-
headers: {
|
|
47
|
-
'ApiKey': config.apiKey,
|
|
48
|
-
'Content-Type': 'application/json'
|
|
49
|
-
},
|
|
50
|
-
httpsAgent,
|
|
51
|
-
maxRedirects: 0
|
|
52
|
-
});
|
|
53
|
-
// Extract token from set-cookie header
|
|
54
|
-
const setCookie = response.headers?.['set-cookie']?.[0];
|
|
55
|
-
if (!setCookie)
|
|
56
|
-
throw new Error("No set-cookie header found in Altinn response");
|
|
57
|
-
const accessToken = setCookie.split(';')[0];
|
|
39
|
+
const jwt = this.getJwt();
|
|
40
|
+
if (!jwt) {
|
|
41
|
+
throw new Error("Unfortunately, it was not possible to create a JWT for authentication to maskinporten. Please, review the provided information.");
|
|
42
|
+
}
|
|
43
|
+
const accessToken = await this.getAccessToken(jwt);
|
|
58
44
|
if (!accessToken) {
|
|
59
|
-
throw new Error("
|
|
45
|
+
throw new Error("Unfortunately, it was not possible to fetch a Maskinporten token. Please, review the provided information.");
|
|
60
46
|
}
|
|
61
47
|
// Cache token for 10 minutes (per service)
|
|
62
48
|
(0, cache_util_1.setCachedToken)('altinn', accessToken, 10 * 60 * 1000);
|
|
@@ -77,8 +63,7 @@ class AltinnService {
|
|
|
77
63
|
*/
|
|
78
64
|
async syncSickLeaves(dateFrom, dateTo) {
|
|
79
65
|
await (0, cache_util_1.ensureServiceToken)(this, 'altinn');
|
|
80
|
-
const
|
|
81
|
-
const orgNumbers = (config.organizationNumbers || "")
|
|
66
|
+
const orgNumbers = (this.organizationNumbers || "")
|
|
82
67
|
.split(",")
|
|
83
68
|
.map((s) => s.trim())
|
|
84
69
|
.filter(Boolean);
|
|
@@ -88,21 +73,14 @@ class AltinnService {
|
|
|
88
73
|
if (new Date(dateFrom) > new Date(dateTo)) {
|
|
89
74
|
throw new Error("Invalid date range: dateFrom cannot be after dateTo");
|
|
90
75
|
}
|
|
91
|
-
dateFrom = dateFrom || '1970-01-01';
|
|
92
|
-
dateTo = dateTo || '2300-01-01';
|
|
93
76
|
const allCases = (await Promise.all(orgNumbers.map((orgNo) => (0, altinn_helper_1.fetchAltinnCases)({
|
|
94
77
|
destination: this.destination,
|
|
95
|
-
cert: this.cert,
|
|
96
|
-
key: this.key,
|
|
97
|
-
ca: this.ca,
|
|
98
78
|
accessToken: this.accessToken,
|
|
99
79
|
who: orgNo,
|
|
100
80
|
dateFrom,
|
|
101
81
|
dateTo,
|
|
102
82
|
})))).flat();
|
|
103
|
-
|
|
104
|
-
const filteredSickLeaveInfos = (0, altinn_util_1.filterSickNoteDuplicates)(sickLeaveInfos);
|
|
105
|
-
return filteredSickLeaveInfos;
|
|
83
|
+
return (0, altinn_util_1.filterSickNoteDuplicates)(allCases);
|
|
106
84
|
}
|
|
107
85
|
/**
|
|
108
86
|
* Posts immediate leader information to Altinn.
|
|
@@ -153,6 +131,71 @@ class AltinnService {
|
|
|
153
131
|
throw error;
|
|
154
132
|
}
|
|
155
133
|
}
|
|
134
|
+
getJwt() {
|
|
135
|
+
const authUrl = this.destination.originalProperties?.destinationConfiguration.authUrl;
|
|
136
|
+
const iat = Math.floor(Date.now() / 1000);
|
|
137
|
+
const exp = iat + 60;
|
|
138
|
+
const nbf = iat - 5;
|
|
139
|
+
const payload = {
|
|
140
|
+
iss: this.cliendId,
|
|
141
|
+
sub: this.cliendId,
|
|
142
|
+
aud: authUrl,
|
|
143
|
+
scope: this.scopeSykepenger,
|
|
144
|
+
iat,
|
|
145
|
+
exp,
|
|
146
|
+
nbf,
|
|
147
|
+
jti: crypto.randomUUID(),
|
|
148
|
+
authorization_details: [
|
|
149
|
+
{
|
|
150
|
+
type: "urn:altinn:systemuser",
|
|
151
|
+
systemuser_org: {
|
|
152
|
+
authority: "iso6523-actorid-upis",
|
|
153
|
+
ID: this.systemuserOrgIso6523
|
|
154
|
+
},
|
|
155
|
+
externalRef: this.externalRef
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
};
|
|
159
|
+
const token = jsonwebtoken_1.default.sign(payload, this.privateKey, {
|
|
160
|
+
algorithm: "RS256",
|
|
161
|
+
keyid: this.kid
|
|
162
|
+
});
|
|
163
|
+
return token || null;
|
|
164
|
+
}
|
|
165
|
+
async getAccessToken(jwt) {
|
|
166
|
+
const authUrl = this.destination.originalProperties?.destinationConfiguration.authUrl;
|
|
167
|
+
if (!authUrl) {
|
|
168
|
+
throw new Error("The token service URL is not provided in the destination.");
|
|
169
|
+
}
|
|
170
|
+
const url = authUrl + "token";
|
|
171
|
+
const data = qs_1.default.stringify({
|
|
172
|
+
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
173
|
+
assertion: jwt
|
|
174
|
+
});
|
|
175
|
+
const response = await axios_1.default.post(url, data, {
|
|
176
|
+
headers: {
|
|
177
|
+
'alg': 'RS256',
|
|
178
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
179
|
+
'kid': this.kid
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return response.data["access_token"];
|
|
183
|
+
}
|
|
184
|
+
parseDestinationConfig() {
|
|
185
|
+
try {
|
|
186
|
+
const config = (0, altinn_helper_1.getValidAltinnConfig)(this.destination);
|
|
187
|
+
this.privateKey = config.originalProperties?.destinationConfiguration.privateKey;
|
|
188
|
+
this.cliendId = config.originalProperties?.destinationConfiguration.cliendId;
|
|
189
|
+
this.kid = config.originalProperties?.destinationConfiguration.kid;
|
|
190
|
+
this.scopeSykepenger = config.originalProperties?.destinationConfiguration.scopeSykepenger;
|
|
191
|
+
this.systemuserOrgIso6523 = config.originalProperties?.destinationConfiguration.systemuserOrgIso6523;
|
|
192
|
+
this.externalRef = config.originalProperties?.destinationConfiguration.externalRef;
|
|
193
|
+
this.organizationNumbers = config.originalProperties?.destinationConfiguration.organizationNumbers;
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
156
199
|
}
|
|
157
200
|
exports.AltinnService = AltinnService;
|
|
158
201
|
//# sourceMappingURL=altinn-service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"altinn-service.js","sourceRoot":"","sources":["../../src/services/altinn-service.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AAC7C,oDAAyF;AAEzF,
|
|
1
|
+
{"version":3,"file":"altinn-service.js","sourceRoot":"","sources":["../../src/services/altinn-service.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AAC7C,oDAAyF;AAEzF,4DAAkF;AAClF,sDAAgE;AAEhE,gEAA+B;AAC/B,4CAAoB;AAEpB,MAAa,aAAa;IACjB,WAAW,GAAW,EAAE,CAAC;IACxB,WAAW,CAAc;IACzB,UAAU,GAAW,EAAE,CAAC;IACxB,QAAQ,GAAW,EAAE,CAAC;IACtB,GAAG,GAAW,EAAE,CAAC;IACjB,eAAe,GAAW,EAAE,CAAC;IAC7B,oBAAoB,GAAW,EAAE,CAAC;IAClC,WAAW,GAAW,EAAE,CAAC;IACzB,mBAAmB,GAAW,EAAE,CAAC;IAEzC,YAAY,WAAwB;QAClC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAChC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC;YACH,wCAAwC;YACxC,MAAM,MAAM,GAAG,IAAA,2BAAc,EAAC,QAAQ,CAAC,CAAC;YACxC,IAAI,MAAM;gBAAE,OAAO,MAAM,CAAC;YAE1B,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YAE1B,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,MAAM,IAAI,KAAK,CAAC,iIAAiI,CAAC,CAA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,UAAU,GAAG,MAAM,CAAC,kBAAkB,EAAE,wBAAwB,CAAC,UAAoB,CAAC;YAC3F,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,kBAAkB,EAAE,wBAAwB,CAAC,QAAkB,CAAC;YACvF,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,kBAAkB,EAAE,wBAAwB,CAAC,GAAa,CAAC;YAC7E,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,kBAAkB,EAAE,wBAAwB,CAAC,eAAyB,CAAC;YACrG,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,kBAAkB,EAAE,wBAAwB,CAAC,oBAA8B,CAAC;YAC/G,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,kBAAkB,EAAE,wBAAwB,CAAC,WAAqB,CAAC;YAC7F,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,kBAAkB,EAAE,wBAAwB,CAAC,mBAA6B,CAAC;QAC/G,CAAC;QACD,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAzND,sCAyNC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Destination } from "@sap-cloud-sdk/connectivity";
|
|
2
2
|
import { SickLeaveInfoSummary } from "../types/altinn.types";
|
|
3
|
-
import { SfAbsenceCase, SfManager, SfMeeting, SfPlan, SFUpsertResponse } from "../types";
|
|
3
|
+
import { InsertTimeOffRecord, SfAbsenceCase, SfManager, SfMeeting, SfPlan, SFUpsertResponse, UpdateTimeOffRecord } from "../types";
|
|
4
4
|
export declare class SuccessFactorsService {
|
|
5
5
|
private destination;
|
|
6
6
|
accessToken: string;
|
|
@@ -98,6 +98,8 @@ export declare class SuccessFactorsService {
|
|
|
98
98
|
startDate: string;
|
|
99
99
|
timeType: string;
|
|
100
100
|
userId: string;
|
|
101
|
+
cust_absence_percentage: string;
|
|
102
|
+
cust_absence_NAV_ID: string;
|
|
101
103
|
}> | null>;
|
|
102
104
|
/**
|
|
103
105
|
* Inserts a new absence follow-up case into SuccessFactors.
|
|
@@ -162,5 +164,7 @@ export declare class SuccessFactorsService {
|
|
|
162
164
|
* @returns The API response from SuccessFactors
|
|
163
165
|
*/
|
|
164
166
|
insertEmployeeTimeOffRecord(userId: string, startDate: string, endDate: string): Promise<SFUpsertResponse>;
|
|
167
|
+
insertTimeOffRecordCollision(record: InsertTimeOffRecord): Promise<SFUpsertResponse>;
|
|
168
|
+
updateTimeOffRecordCollision(record: UpdateTimeOffRecord): Promise<SFUpsertResponse>;
|
|
165
169
|
}
|
|
166
170
|
//# sourceMappingURL=sf-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sf-service.d.ts","sourceRoot":"","sources":["../../src/services/sf-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAA2C,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"sf-service.d.ts","sourceRoot":"","sources":["../../src/services/sf-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAA2C,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE5K,qBAAa,qBAAqB;IAC9B,OAAO,CAAC,WAAW,CAAc;IAC1B,WAAW,EAAE,MAAM,CAAM;gBAEpB,WAAW,EAAE,WAAW;IAIpC;;;;;OAKG;IACG,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAgDrC;;;;;;;OAOG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AAO,CAAC,gBAAgB,CAAC;IA+F9E;;;;;;OAMG;IACG,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAyBnG,4BAA4B,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAyBpF,4BAA4B,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAyBpG"}
|
|
@@ -260,6 +260,9 @@ class SuccessFactorsService {
|
|
|
260
260
|
};
|
|
261
261
|
const response = await this.getSuccessFactorContent("cust_absencefollowup", queryParams);
|
|
262
262
|
let caseData = null;
|
|
263
|
+
if (Array.isArray(response) && !response.length) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
263
266
|
if (typeof response === "object" && response !== null) {
|
|
264
267
|
caseData = response;
|
|
265
268
|
if (!caseData)
|
|
@@ -375,7 +378,7 @@ class SuccessFactorsService {
|
|
|
375
378
|
const queryParams = {
|
|
376
379
|
$format: "json",
|
|
377
380
|
$expand: "",
|
|
378
|
-
$select: "
|
|
381
|
+
$select: "endDate,externalCode,startDate,timeType,userId,approvalStatus,entityUUID,cust_absence_percentage,cust_absence_NAV_ID",
|
|
379
382
|
$filter: `(userId eq '${userId}' and approvalStatus eq 'APPROVED')`,
|
|
380
383
|
};
|
|
381
384
|
const response = await this.getSuccessFactorContent("EmployeeTime", queryParams);
|
|
@@ -397,11 +400,6 @@ class SuccessFactorsService {
|
|
|
397
400
|
const receivedAt = (0, sf_util_1.dateToEpoch)(typeof absence.mdfSystemEffectiveStartDate === "string" || absence.mdfSystemEffectiveStartDate == null
|
|
398
401
|
? absence.mdfSystemEffectiveStartDate || absence.sickLeaveReceivedAt
|
|
399
402
|
: absence.mdfSystemEffectiveStartDate.toISOString());
|
|
400
|
-
const practitionerName = [
|
|
401
|
-
absence.practitionerFirstName,
|
|
402
|
-
absence.practitionerMiddleName,
|
|
403
|
-
absence.practitionerLastName
|
|
404
|
-
].filter(Boolean).join(" ");
|
|
405
403
|
const data = {
|
|
406
404
|
__metadata: {
|
|
407
405
|
uri: `cust_absencefollowup(externalCode='${employeeId}',mdfSystemEffectiveStartDate=datetime'${absence.sickLeaveReceivedAt}')`,
|
|
@@ -410,7 +408,7 @@ class SuccessFactorsService {
|
|
|
410
408
|
cust_startDate: absenceFrom ? `/Date(${absenceFrom})/` : null,
|
|
411
409
|
cust_returnDate: absenceTo ? `/Date(${absenceTo})/` : null,
|
|
412
410
|
cust_sentDate: receivedAt ? `/Date(${receivedAt})/` : null,
|
|
413
|
-
cust_doctorName:
|
|
411
|
+
cust_doctorName: absence.practitionerFullName,
|
|
414
412
|
cust_doctorPhone: absence.practitionerPhoneNumber,
|
|
415
413
|
cust_infoEmployer: absence.considerationsByTheWorkPlace,
|
|
416
414
|
cust_absenceID: absence.sickLeaveId,
|
|
@@ -518,11 +516,6 @@ class SuccessFactorsService {
|
|
|
518
516
|
: mdfSystemEffectiveStartDate.toISOString();
|
|
519
517
|
const epochEndDate = (0, sf_util_1.dateToEpoch)(newCaseInfo.sickTo);
|
|
520
518
|
const epochStartDate = (0, sf_util_1.dateToEpoch)(newCaseInfo.sickFrom);
|
|
521
|
-
const practitionerName = [
|
|
522
|
-
newCaseInfo.practitionerFirstName,
|
|
523
|
-
newCaseInfo.practitionerMiddleName,
|
|
524
|
-
newCaseInfo.practitionerLastName
|
|
525
|
-
].filter(part => part && part !== "null" && part !== null && part !== undefined && part !== "").join("");
|
|
526
519
|
const data = {
|
|
527
520
|
__metadata: metadata.__metadata,
|
|
528
521
|
cust_startDate: epochStartDate ? `/Date(${epochStartDate})/` : null,
|
|
@@ -530,7 +523,7 @@ class SuccessFactorsService {
|
|
|
530
523
|
cust_absencePercentage: newCaseInfo.sickleaveRate,
|
|
531
524
|
cust_infoEmployer: newCaseInfo.considerationsByTheWorkPlace,
|
|
532
525
|
cust_absenceID: newCaseInfo.sickLeaveId,
|
|
533
|
-
cust_doctorName:
|
|
526
|
+
cust_doctorName: newCaseInfo.practitionerFullName,
|
|
534
527
|
cust_doctorPhone: newCaseInfo.practitionerPhoneNumber,
|
|
535
528
|
};
|
|
536
529
|
try {
|
|
@@ -679,7 +672,7 @@ class SuccessFactorsService {
|
|
|
679
672
|
userId: userId,
|
|
680
673
|
startDate: `/Date(${epochStartDate})/`,
|
|
681
674
|
endDate: `/Date(${epochEndDate})/`,
|
|
682
|
-
timeType: "SICKNESS_NAV"
|
|
675
|
+
timeType: "SICKNESS_NAV"
|
|
683
676
|
};
|
|
684
677
|
try {
|
|
685
678
|
const response = await this.postSuccessFactorContent(data);
|
|
@@ -690,6 +683,53 @@ class SuccessFactorsService {
|
|
|
690
683
|
throw error;
|
|
691
684
|
}
|
|
692
685
|
}
|
|
686
|
+
async insertTimeOffRecordCollision(record) {
|
|
687
|
+
const epochStartDate = (0, sf_util_1.dateToEpoch)(record.startDate);
|
|
688
|
+
const epochEndDate = (0, sf_util_1.dateToEpoch)(record.endDate);
|
|
689
|
+
const data = {
|
|
690
|
+
"__metadata": {
|
|
691
|
+
"uri": "EmployeeTime('')",
|
|
692
|
+
"type": "SFOData.EmployeeTime"
|
|
693
|
+
},
|
|
694
|
+
"cust_absence_NAV_ID": record.sickLeaveId,
|
|
695
|
+
"cust_absence_percentage": record.rate,
|
|
696
|
+
"userId": record.userId,
|
|
697
|
+
"startDate": `/Date(${epochStartDate})/`,
|
|
698
|
+
"endDate": `/Date(${epochEndDate})/`,
|
|
699
|
+
"timeType": "NO_2"
|
|
700
|
+
};
|
|
701
|
+
try {
|
|
702
|
+
return this.postSuccessFactorContent(data);
|
|
703
|
+
}
|
|
704
|
+
catch (error) {
|
|
705
|
+
console.error("Error inserting employee time off record collision:", error);
|
|
706
|
+
throw error;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
async updateTimeOffRecordCollision(record) {
|
|
710
|
+
const epochStartDate = (0, sf_util_1.dateToEpoch)(record.startDate);
|
|
711
|
+
const epochEndDate = (0, sf_util_1.dateToEpoch)(record.endDate);
|
|
712
|
+
const data = {
|
|
713
|
+
"__metadata": {
|
|
714
|
+
"uri": `EmployeeTime('${record.uuid}')`,
|
|
715
|
+
"type": "SFOData.EmployeeTime"
|
|
716
|
+
},
|
|
717
|
+
"externalCode": `${record.uuid}`,
|
|
718
|
+
"endDate": `/Date(${epochEndDate})/`,
|
|
719
|
+
"timeType": `${record.timeType}`,
|
|
720
|
+
"cust_absence_NAV_ID": `${record.sickLeaveId}`,
|
|
721
|
+
"cust_absence_percentage": `${record.rate}`,
|
|
722
|
+
"userId": record.userId ? `${record.userId}` : `${record.uuid}`,
|
|
723
|
+
"startDate": `/Date(${epochStartDate})/`
|
|
724
|
+
};
|
|
725
|
+
try {
|
|
726
|
+
return this.postSuccessFactorContent(data);
|
|
727
|
+
}
|
|
728
|
+
catch (error) {
|
|
729
|
+
console.error("Error updating employee time off record collision:", error);
|
|
730
|
+
throw error;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
693
733
|
}
|
|
694
734
|
exports.SuccessFactorsService = SuccessFactorsService;
|
|
695
735
|
//# sourceMappingURL=sf-service.js.map
|