@eid-easy/eideasy-browser-client 1.9.1 → 2.1.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/CHANGELOG.md +148 -117
- package/dist/eideasy-browser-client.js +1 -1
- package/docs/.vuepress/components/AppError.vue +1 -1
- package/docs/.vuepress/components/AppIdentification.vue +9 -3
- package/docs/.vuepress/components/AppSigning.vue +167 -0
- package/docs/.vuepress/components/IdentAtHandy.vue +102 -0
- package/docs/.vuepress/components/IdentEParakstsMobile.vue +16 -19
- package/docs/.vuepress/components/IdentFinnishTrustNetwork.vue +14 -26
- package/docs/.vuepress/components/IdentMojeId.vue +7 -22
- package/docs/.vuepress/components/SignEParakstsMobile.vue +103 -0
- package/docs/.vuepress/components/SignEvrotrust.vue +113 -0
- package/docs/.vuepress/components/SignFtn.vue +103 -0
- package/docs/.vuepress/components/SignIdCard.vue +70 -0
- package/docs/.vuepress/components/SignMobileId.vue +100 -0
- package/docs/.vuepress/components/SignOtp.vue +93 -0
- package/docs/.vuepress/components/SignSmartId.vue +89 -0
- package/docs/.vuepress/components/eidEasyDemoClient.js +15 -3
- package/docs/demos/README.md +5 -0
- package/package.json +4 -4
- package/src/apiClient/createApiEndpoints.js +22 -0
- package/src/config.js +139 -51
- package/src/coreSettingsSchema.js +69 -0
- package/src/createApiPoller.js +54 -0
- package/src/createClientCore.js +10 -8
- package/src/createModuleCreator.js +17 -11
- package/src/createMonitoringService.js +33 -0
- package/src/createSettings.js +26 -0
- package/src/createStep.js +11 -3
- package/src/i18n/de.json +1 -1
- package/src/i18n/en.json +1 -1
- package/src/i18n/et.json +1 -1
- package/src/i18n/lt.json +1 -1
- package/src/i18n/lv.json +1 -1
- package/src/i18n/ru.json +1 -1
- package/src/identificationModules/createAtHandy.js +37 -0
- package/src/identificationModules/createEParakstsMobile.js +19 -23
- package/src/identificationModules/createFinnishTrustNetwork.js +22 -24
- package/src/identificationModules/createFrejaEid.js +11 -1
- package/src/identificationModules/createIdCard.js +7 -1
- package/src/identificationModules/createMobileId.js +15 -1
- package/src/identificationModules/createMojeId.js +19 -23
- package/src/identificationModules/createSmartId.js +11 -1
- package/src/identificationModules/createZealId.js +11 -1
- package/src/identificationModules/identificationModules.js +2 -0
- package/src/main.js +44 -1
- package/src/signatureModules/createEParakstsMobileSignature.js +70 -0
- package/src/signatureModules/createEvrotrustSignature.js +144 -0
- package/src/signatureModules/createFtnSignature.js +70 -0
- package/src/signatureModules/createIdCardSignature.js +208 -0
- package/src/signatureModules/createMobileIdSignature.js +129 -0
- package/src/signatureModules/createOtpSignature.js +68 -0
- package/src/signatureModules/createSmartIdSignature.js +124 -0
- package/src/signatureModules/signatureModules.js +17 -0
- package/src/{cloneDeep.test.js → tests/cloneDeep.test.js} +1 -1
- package/src/tests/config.test.js +25 -0
- package/src/{createRequestError.test.js → tests/createRequestError.test.js} +1 -1
- package/src/{main.test.js → tests/main.test.js} +1 -1
- package/src/{poll.test.js → tests/poll.test.js} +1 -1
- package/src/{windowOpen.test.js → tests/windowOpen.test.js} +1 -1
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import createStep from '../createStep';
|
|
2
|
+
import createModuleCreator from '../createModuleCreator';
|
|
3
|
+
import { getMethodByHandlingModule, methodTypes, moduleNames } from '../config';
|
|
4
|
+
|
|
5
|
+
const MODULE_NAME = moduleNames.idCardSignature;
|
|
6
|
+
|
|
7
|
+
const settingsSchema = {
|
|
8
|
+
iframeHolder: {
|
|
9
|
+
type: 'object',
|
|
10
|
+
},
|
|
11
|
+
docId: {
|
|
12
|
+
type: 'string',
|
|
13
|
+
required: true,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const createMessenger = function createMessenger({ iframe }) {
|
|
18
|
+
const url = new URL(iframe.src);
|
|
19
|
+
return {
|
|
20
|
+
post(message) {
|
|
21
|
+
iframe.contentWindow.postMessage(message, url.origin);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const getIframeUrl = function getIframeUrl({ countryCode, clientId, apiEndpoints }) {
|
|
27
|
+
const method = getMethodByHandlingModule(methodTypes.SIGNATURE, MODULE_NAME, countryCode);
|
|
28
|
+
return apiEndpoints.inCurrentMode.idCardIframe({
|
|
29
|
+
clientId,
|
|
30
|
+
actionType: method.actionType,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const createIframe = function createIframe({
|
|
35
|
+
iframeHolder, iframeUrl, i18n,
|
|
36
|
+
}) {
|
|
37
|
+
const iframe = document.createElement('iframe');
|
|
38
|
+
iframe.setAttribute('src', iframeUrl);
|
|
39
|
+
iframe.setAttribute('referrerpolicy', 'origin');
|
|
40
|
+
iframe.style.width = '0';
|
|
41
|
+
iframe.style.height = '0';
|
|
42
|
+
iframe.style.position = 'absolute';
|
|
43
|
+
iframe.style.border = '0';
|
|
44
|
+
// eslint-disable-next-line no-param-reassign
|
|
45
|
+
iframeHolder.innerHTML = '';
|
|
46
|
+
const promise = new Promise((resolve, reject) => {
|
|
47
|
+
window.addEventListener('message', (e) => {
|
|
48
|
+
const { operation, error, status } = e.data;
|
|
49
|
+
if (error) {
|
|
50
|
+
reject(e.data);
|
|
51
|
+
} else if (operation === 'ready' || operation === 'welcome') {
|
|
52
|
+
if (status === 'OK') {
|
|
53
|
+
resolve(iframe);
|
|
54
|
+
} else {
|
|
55
|
+
reject(e.data);
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
reject(e.data);
|
|
59
|
+
}
|
|
60
|
+
}, { once: true });
|
|
61
|
+
// eslint-disable-next-line prefer-promise-reject-errors
|
|
62
|
+
window.setTimeout(() => reject({ message: i18n.t('createIframeTimeout') }), 30 * 1000);
|
|
63
|
+
});
|
|
64
|
+
iframeHolder.appendChild(iframe);
|
|
65
|
+
return promise;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const getCertificate = function getCertificate({ messenger }) {
|
|
69
|
+
const promise = new Promise((resolve, reject) => {
|
|
70
|
+
window.addEventListener('message', (e) => {
|
|
71
|
+
const { result, cert } = e.data;
|
|
72
|
+
if (result === 'ok' && cert) {
|
|
73
|
+
resolve(e.data);
|
|
74
|
+
} else {
|
|
75
|
+
let error = {};
|
|
76
|
+
if (e.data && e.data.result === 'user_cancel') {
|
|
77
|
+
error.isCancel = true;
|
|
78
|
+
} else {
|
|
79
|
+
error = e.data;
|
|
80
|
+
}
|
|
81
|
+
reject(error);
|
|
82
|
+
}
|
|
83
|
+
}, { once: true });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
messenger.post({
|
|
87
|
+
operation: 'getCertificate',
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return promise;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const startSigning = function startSigning({
|
|
94
|
+
certificate, clientId, docId, cancelToken, apiEndpoints, apiClient,
|
|
95
|
+
}) {
|
|
96
|
+
const url = apiEndpoints.inCurrentMode.startSigning();
|
|
97
|
+
return apiClient.post({
|
|
98
|
+
url,
|
|
99
|
+
withCredentials: false,
|
|
100
|
+
data: {
|
|
101
|
+
client_id: clientId,
|
|
102
|
+
doc_id: docId,
|
|
103
|
+
sign_type: 'id-card',
|
|
104
|
+
certificate,
|
|
105
|
+
},
|
|
106
|
+
cancelToken,
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const getSignature = function createSignature({ messenger, hexDigest }) {
|
|
111
|
+
const promise = new Promise((resolve, reject) => {
|
|
112
|
+
window.addEventListener('message', (e) => {
|
|
113
|
+
const { result, signature } = e.data;
|
|
114
|
+
if (result === 'ok' && signature) {
|
|
115
|
+
resolve(e.data);
|
|
116
|
+
} else {
|
|
117
|
+
let error = {};
|
|
118
|
+
if (e.data && e.data.result === 'user_cancel') {
|
|
119
|
+
error.isCancel = true;
|
|
120
|
+
} else {
|
|
121
|
+
error = e.data;
|
|
122
|
+
}
|
|
123
|
+
reject(error);
|
|
124
|
+
}
|
|
125
|
+
}, { once: true });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
messenger.post({
|
|
129
|
+
operation: 'getSignature',
|
|
130
|
+
hexDigest,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
return promise;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const completeSigning = function completeSigning({
|
|
137
|
+
signature, clientId, docId, cancelToken, apiEndpoints, apiClient,
|
|
138
|
+
}) {
|
|
139
|
+
const url = apiEndpoints.inCurrentMode.completeSignatureIdCard();
|
|
140
|
+
return apiClient.post({
|
|
141
|
+
url,
|
|
142
|
+
withCredentials: false,
|
|
143
|
+
data: {
|
|
144
|
+
client_id: clientId,
|
|
145
|
+
doc_id: docId,
|
|
146
|
+
signature_value: signature,
|
|
147
|
+
},
|
|
148
|
+
cancelToken,
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const executable = async function executable(config) {
|
|
153
|
+
const iframeUrl = await createStep(getIframeUrl, { shouldFormatResult: false })({
|
|
154
|
+
countryCode: config.countryCode,
|
|
155
|
+
clientId: config.clientId,
|
|
156
|
+
apiEndpoints: config.apiEndpoints,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const iframe = await createStep(createIframe, { shouldFormatResult: false })({
|
|
160
|
+
iframeUrl,
|
|
161
|
+
iframeHolder: config.iframeHolder,
|
|
162
|
+
i18n: config.i18n,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const messenger = await createStep(createMessenger, { shouldFormatResult: false })({
|
|
166
|
+
iframe,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const certificateResult = await createStep(getCertificate, {
|
|
170
|
+
shouldFormatResult: false,
|
|
171
|
+
})({
|
|
172
|
+
messenger,
|
|
173
|
+
}).catch((error) => {
|
|
174
|
+
if (!error.result) {
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
if (error.result === 'no_certificates') {
|
|
178
|
+
error.userMessage = config.i18n.t('no_certificates'); // eslint-disable-line no-param-reassign
|
|
179
|
+
}
|
|
180
|
+
throw error;
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const startSigningResult = await createStep(startSigning)({
|
|
184
|
+
certificate: certificateResult.cert,
|
|
185
|
+
clientId: config.clientId,
|
|
186
|
+
docId: config.docId,
|
|
187
|
+
cancelToken: config.cancelToken,
|
|
188
|
+
apiEndpoints: config.apiEndpoints,
|
|
189
|
+
apiClient: config.apiClient,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const getSignatureResult = await createStep(getSignature, { shouldFormatResult: false })({
|
|
193
|
+
messenger,
|
|
194
|
+
hexDigest: startSigningResult.data.hexDigest,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
return createStep(completeSigning)({
|
|
198
|
+
signature: getSignatureResult.signature,
|
|
199
|
+
clientId: config.clientId,
|
|
200
|
+
docId: config.docId,
|
|
201
|
+
cancelToken: config.cancelToken,
|
|
202
|
+
apiEndpoints: config.apiEndpoints,
|
|
203
|
+
apiClient: config.apiClient,
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const createIdCardSignature = createModuleCreator(MODULE_NAME, executable, settingsSchema);
|
|
208
|
+
export default createIdCardSignature;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import createStep from '../createStep';
|
|
2
|
+
import createModuleCreator from '../createModuleCreator';
|
|
3
|
+
import { getMethodByHandlingModule, methodTypes, moduleNames } from '../config';
|
|
4
|
+
import createApiPoller from '../createApiPoller';
|
|
5
|
+
|
|
6
|
+
const MODULE_NAME = moduleNames.mobileIdSignature;
|
|
7
|
+
const settingsSchema = {
|
|
8
|
+
countryCode: {
|
|
9
|
+
type: 'string',
|
|
10
|
+
required: true,
|
|
11
|
+
},
|
|
12
|
+
idcode: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
required: true,
|
|
15
|
+
},
|
|
16
|
+
phone: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
docId: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const startSigning = function startSigning({
|
|
27
|
+
phone, idcode, clientId, docId, cancelToken, apiEndpoints, apiClient, countryCode, language,
|
|
28
|
+
}) {
|
|
29
|
+
const url = apiEndpoints.inCurrentMode.startSigning();
|
|
30
|
+
return apiClient.post({
|
|
31
|
+
url,
|
|
32
|
+
withCredentials: false,
|
|
33
|
+
data: {
|
|
34
|
+
doc_id: docId,
|
|
35
|
+
client_id: clientId,
|
|
36
|
+
sign_type: 'mobile-id',
|
|
37
|
+
phone,
|
|
38
|
+
idcode,
|
|
39
|
+
country: countryCode,
|
|
40
|
+
lang: language,
|
|
41
|
+
},
|
|
42
|
+
cancelToken,
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const finishSigning = function finishSigning({
|
|
47
|
+
data, apiClient, apiEndpoints, language, cancelToken, docId, clientId,
|
|
48
|
+
}) {
|
|
49
|
+
return apiClient.post({
|
|
50
|
+
url: apiEndpoints.inCurrentMode.completeSignatureMobileId(),
|
|
51
|
+
withCredentials: false,
|
|
52
|
+
data: {
|
|
53
|
+
token: data.token,
|
|
54
|
+
doc_id: docId,
|
|
55
|
+
timeout: 2,
|
|
56
|
+
lang: language,
|
|
57
|
+
client_id: clientId,
|
|
58
|
+
},
|
|
59
|
+
cancelToken,
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const pollFinishSigning = function pollFinishSigning({
|
|
64
|
+
data, apiClient, apiEndpoints, language, cancelToken, docId, clientId,
|
|
65
|
+
}) {
|
|
66
|
+
const poller = createApiPoller({
|
|
67
|
+
pollInterval: 2000,
|
|
68
|
+
// Mobile ID users have 120 seconds to enter their pin,
|
|
69
|
+
// so it doesn't make sense to poll longer than that
|
|
70
|
+
maxPollDuration: 120 * 1000,
|
|
71
|
+
fn: finishSigning,
|
|
72
|
+
fnArgs: [{
|
|
73
|
+
data,
|
|
74
|
+
apiClient,
|
|
75
|
+
apiEndpoints,
|
|
76
|
+
language,
|
|
77
|
+
cancelToken,
|
|
78
|
+
docId,
|
|
79
|
+
clientId,
|
|
80
|
+
}],
|
|
81
|
+
});
|
|
82
|
+
return poller.start();
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const executable = async function executable({
|
|
86
|
+
clientId,
|
|
87
|
+
docId,
|
|
88
|
+
cancelToken,
|
|
89
|
+
apiEndpoints,
|
|
90
|
+
apiClient,
|
|
91
|
+
monitoringService,
|
|
92
|
+
language,
|
|
93
|
+
idcode,
|
|
94
|
+
phone,
|
|
95
|
+
countryCode,
|
|
96
|
+
started,
|
|
97
|
+
}) {
|
|
98
|
+
const method = getMethodByHandlingModule(methodTypes.SIGNATURE, MODULE_NAME, countryCode);
|
|
99
|
+
monitoringService.dispatch({
|
|
100
|
+
message: `${method.actionType}: signing started`,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const startSigningResult = await createStep(startSigning)({
|
|
104
|
+
clientId,
|
|
105
|
+
docId,
|
|
106
|
+
cancelToken,
|
|
107
|
+
apiEndpoints,
|
|
108
|
+
apiClient,
|
|
109
|
+
language,
|
|
110
|
+
idcode,
|
|
111
|
+
phone,
|
|
112
|
+
countryCode,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
started(startSigningResult);
|
|
116
|
+
|
|
117
|
+
return createStep(pollFinishSigning)({
|
|
118
|
+
data: startSigningResult.data,
|
|
119
|
+
apiClient,
|
|
120
|
+
apiEndpoints,
|
|
121
|
+
language,
|
|
122
|
+
cancelToken,
|
|
123
|
+
docId,
|
|
124
|
+
clientId,
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const createMobileIdSignature = createModuleCreator(MODULE_NAME, executable, settingsSchema);
|
|
129
|
+
export default createMobileIdSignature;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import createStep from '../createStep';
|
|
2
|
+
import createModuleCreator from '../createModuleCreator';
|
|
3
|
+
import { getMethodByHandlingModule, methodTypes, moduleNames } from '../config';
|
|
4
|
+
|
|
5
|
+
const MODULE_NAME = moduleNames.otpSignature;
|
|
6
|
+
const settingsSchema = {
|
|
7
|
+
docId: {
|
|
8
|
+
type: 'string',
|
|
9
|
+
required: true,
|
|
10
|
+
},
|
|
11
|
+
emailToken: {
|
|
12
|
+
type: 'string',
|
|
13
|
+
},
|
|
14
|
+
smsToken: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const finishSigning = function finishSigning({
|
|
20
|
+
apiClient, apiEndpoints, language, cancelToken, docId, clientId, emailToken, smsToken,
|
|
21
|
+
}) {
|
|
22
|
+
return apiClient.post({
|
|
23
|
+
url: apiEndpoints.inCurrentMode.completeOtp(),
|
|
24
|
+
withCredentials: false,
|
|
25
|
+
data: {
|
|
26
|
+
doc_id: docId,
|
|
27
|
+
timeout: 2,
|
|
28
|
+
lang: language,
|
|
29
|
+
client_id: clientId,
|
|
30
|
+
email_token: emailToken,
|
|
31
|
+
sms_token: smsToken,
|
|
32
|
+
},
|
|
33
|
+
cancelToken,
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const executable = async function executable({
|
|
38
|
+
clientId,
|
|
39
|
+
docId,
|
|
40
|
+
cancelToken,
|
|
41
|
+
apiEndpoints,
|
|
42
|
+
apiClient,
|
|
43
|
+
monitoringService,
|
|
44
|
+
language,
|
|
45
|
+
countryCode,
|
|
46
|
+
emailToken,
|
|
47
|
+
smsToken,
|
|
48
|
+
}) {
|
|
49
|
+
const method = getMethodByHandlingModule(methodTypes.SIGNATURE, MODULE_NAME, countryCode);
|
|
50
|
+
console.log(method);
|
|
51
|
+
monitoringService.dispatch({
|
|
52
|
+
message: `${method.actionType}: signing started`,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return createStep(finishSigning)({
|
|
56
|
+
apiClient,
|
|
57
|
+
apiEndpoints,
|
|
58
|
+
language,
|
|
59
|
+
cancelToken,
|
|
60
|
+
docId,
|
|
61
|
+
clientId,
|
|
62
|
+
emailToken,
|
|
63
|
+
smsToken,
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const createOtpSignature = createModuleCreator(MODULE_NAME, executable, settingsSchema);
|
|
68
|
+
export default createOtpSignature;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import createStep from '../createStep';
|
|
2
|
+
import createModuleCreator from '../createModuleCreator';
|
|
3
|
+
import { getMethodByHandlingModule, methodTypes, moduleNames } from '../config';
|
|
4
|
+
import createApiPoller from '../createApiPoller';
|
|
5
|
+
|
|
6
|
+
const MODULE_NAME = moduleNames.smartIdSignature;
|
|
7
|
+
const settingsSchema = {
|
|
8
|
+
countryCode: {
|
|
9
|
+
type: 'string',
|
|
10
|
+
required: true,
|
|
11
|
+
},
|
|
12
|
+
idcode: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
required: true,
|
|
15
|
+
},
|
|
16
|
+
docId: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const startSigning = function startSigning({
|
|
23
|
+
contractId, idcode, clientId, docId, cancelToken, apiEndpoints, apiClient, countryCode, language,
|
|
24
|
+
}) {
|
|
25
|
+
const url = apiEndpoints.inCurrentMode.startSigning();
|
|
26
|
+
return apiClient.post({
|
|
27
|
+
url,
|
|
28
|
+
withCredentials: false,
|
|
29
|
+
data: {
|
|
30
|
+
doc_id: docId,
|
|
31
|
+
contract_id: contractId,
|
|
32
|
+
client_id: clientId,
|
|
33
|
+
sign_type: 'smart-id',
|
|
34
|
+
idcode,
|
|
35
|
+
country: countryCode,
|
|
36
|
+
lang: language,
|
|
37
|
+
},
|
|
38
|
+
cancelToken,
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const finishSigning = function finishSigning({
|
|
43
|
+
data, apiClient, apiEndpoints, language, cancelToken, docId, clientId,
|
|
44
|
+
}) {
|
|
45
|
+
return apiClient.post({
|
|
46
|
+
url: apiEndpoints.inCurrentMode.completeSignatureSmartId(),
|
|
47
|
+
withCredentials: false,
|
|
48
|
+
data: {
|
|
49
|
+
token: data.token,
|
|
50
|
+
doc_id: docId,
|
|
51
|
+
lang: language,
|
|
52
|
+
client_id: clientId,
|
|
53
|
+
},
|
|
54
|
+
cancelToken,
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const pollFinishSigning = function pollFinishSigning({
|
|
59
|
+
data, apiClient, apiEndpoints, language, cancelToken, docId, clientId,
|
|
60
|
+
}) {
|
|
61
|
+
const poller = createApiPoller({
|
|
62
|
+
pollInterval: 2000,
|
|
63
|
+
// Smart ID users have ~120 seconds to enter their pin,
|
|
64
|
+
// so it doesn't make sense to poll longer than that
|
|
65
|
+
maxPollDuration: 120 * 1000,
|
|
66
|
+
fn: finishSigning,
|
|
67
|
+
fnArgs: [{
|
|
68
|
+
data,
|
|
69
|
+
apiClient,
|
|
70
|
+
apiEndpoints,
|
|
71
|
+
language,
|
|
72
|
+
cancelToken,
|
|
73
|
+
docId,
|
|
74
|
+
clientId,
|
|
75
|
+
}],
|
|
76
|
+
});
|
|
77
|
+
return poller.start();
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const executable = async function executable({
|
|
81
|
+
clientId,
|
|
82
|
+
docId,
|
|
83
|
+
contractId,
|
|
84
|
+
cancelToken,
|
|
85
|
+
apiEndpoints,
|
|
86
|
+
apiClient,
|
|
87
|
+
monitoringService,
|
|
88
|
+
language,
|
|
89
|
+
idcode,
|
|
90
|
+
countryCode,
|
|
91
|
+
started,
|
|
92
|
+
}) {
|
|
93
|
+
const method = getMethodByHandlingModule(methodTypes.SIGNATURE, MODULE_NAME, countryCode);
|
|
94
|
+
monitoringService.dispatch({
|
|
95
|
+
message: `${method.actionType}: signing started`,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const startSigningResult = await createStep(startSigning)({
|
|
99
|
+
clientId,
|
|
100
|
+
docId,
|
|
101
|
+
cancelToken,
|
|
102
|
+
apiEndpoints,
|
|
103
|
+
apiClient,
|
|
104
|
+
language,
|
|
105
|
+
idcode,
|
|
106
|
+
countryCode,
|
|
107
|
+
contractId,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
started(startSigningResult);
|
|
111
|
+
|
|
112
|
+
return createStep(pollFinishSigning)({
|
|
113
|
+
data: startSigningResult.data,
|
|
114
|
+
apiClient,
|
|
115
|
+
apiEndpoints,
|
|
116
|
+
language,
|
|
117
|
+
cancelToken,
|
|
118
|
+
docId,
|
|
119
|
+
clientId,
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const createSmartIdSignature = createModuleCreator(MODULE_NAME, executable, settingsSchema);
|
|
124
|
+
export default createSmartIdSignature;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import createIdCardSignature from './createIdCardSignature';
|
|
2
|
+
import createMobileIdSignature from './createMobileIdSignature';
|
|
3
|
+
import createSmartIdSignature from './createSmartIdSignature';
|
|
4
|
+
import createEvrotrustSignature from './createEvrotrustSignature';
|
|
5
|
+
import createOtpSignature from './createOtpSignature';
|
|
6
|
+
import createEParakstsMobileSignature from './createEParakstsMobileSignature';
|
|
7
|
+
import createFtnSignature from './createFtnSignature';
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
createIdCardSignature,
|
|
11
|
+
createMobileIdSignature,
|
|
12
|
+
createSmartIdSignature,
|
|
13
|
+
createEvrotrustSignature,
|
|
14
|
+
createOtpSignature,
|
|
15
|
+
createEParakstsMobileSignature,
|
|
16
|
+
createFtnSignature,
|
|
17
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getMethodByHandlingModule, methodTypes, moduleNames, methodActionTypes,
|
|
3
|
+
} from '../config';
|
|
4
|
+
|
|
5
|
+
describe('config', () => {
|
|
6
|
+
test('getMethodByHandlingModule returns correct module in case country is not provided', () => {
|
|
7
|
+
const method = getMethodByHandlingModule(methodTypes.IDENTIFICATION, moduleNames.idCard);
|
|
8
|
+
expect(method.handlingModule).toBe(moduleNames.idCard);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('getMethodByHandlingModule returns correct module in case country is provided', () => {
|
|
12
|
+
const method = getMethodByHandlingModule(methodTypes.IDENTIFICATION, moduleNames.idCard, 'FI');
|
|
13
|
+
expect(method.actionType).toBe(methodActionTypes.FI_ID_LOGIN);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('getMethodByHandlingModule returns correct module in case country is provided and method has multiple countries', () => {
|
|
17
|
+
const method = getMethodByHandlingModule(methodTypes.IDENTIFICATION, moduleNames.frejaEid, 'NO');
|
|
18
|
+
expect(method.actionType).toBe(methodActionTypes.FREJA_EID_LOGIN);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('getMethodByHandlingModule returns correct module in case country is not provided and method has multiple countries', () => {
|
|
22
|
+
const method = getMethodByHandlingModule(methodTypes.IDENTIFICATION, moduleNames.frejaEid);
|
|
23
|
+
expect(method.actionType).toBe(methodActionTypes.FREJA_EID_LOGIN);
|
|
24
|
+
});
|
|
25
|
+
});
|