-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathnavigate.js
More file actions
31 lines (27 loc) · 1.12 KB
/
navigate.js
File metadata and controls
31 lines (27 loc) · 1.12 KB
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
import { getSupportingCodeToInject } from '../captcha-services/captcha.service';
import { ErrorResponse, SuccessResponse } from '../types';
import { buildUrl } from './build-url';
/**
* This builds the proper URL given the URL template and userData.
* Also, if the action requires a captcha handler, it will inject the necessary code.
*
* @param {import('../types.js').PirAction} action
* @param {Record<string, any>} userData
* @return {import('../types.js').ActionResponse}
*/
export function navigate(action, userData) {
const { id: actionID, actionType } = action;
const urlResult = buildUrl(action, userData);
if (urlResult instanceof ErrorResponse) {
return urlResult;
}
const codeToInjectResponse = getSupportingCodeToInject(action);
if (codeToInjectResponse instanceof ErrorResponse) {
return codeToInjectResponse;
}
const response = {
.../** @type {Record<string, unknown>} */ (urlResult.success.response),
.../** @type {Record<string, unknown>} */ (codeToInjectResponse.success.response),
};
return new SuccessResponse({ actionID, actionType, response });
}