-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #595 from aziontech/dev
DEPLOY 2024.01.22
- Loading branch information
Showing
63 changed files
with
2,919 additions
and
183 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
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
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,11 @@ | ||
import { AxiosHttpClientAdapter, parseHttpResponse } from '../axios/AxiosHttpClientAdapter' | ||
import { makeAuthMethodBaseUrl } from './make-auth-method-base-url' | ||
|
||
export const verifyLoginMethodService = async (email) => { | ||
const emailEncoded = encodeURIComponent(email) | ||
let httpResponse = await AxiosHttpClientAdapter.request({ | ||
url: `${makeAuthMethodBaseUrl()}/login_method?email=${emailEncoded}`, | ||
method: 'GET' | ||
}) | ||
return parseHttpResponse(httpResponse) | ||
} |
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,3 @@ | ||
export const makeAuthMethodBaseUrl = () => { | ||
return 'auth' | ||
} |
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
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
103 changes: 103 additions & 0 deletions
103
src/services/edge-application-rules-engine-services/create-rules-engine-service.js
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,103 @@ | ||
import { AxiosHttpClientAdapter } from '@/services/axios/AxiosHttpClientAdapter' | ||
import { makeEdgeApplicationBaseUrl } from '../edge-application-services/make-edge-application-base-url' | ||
import * as Errors from '@/services/axios/errors' | ||
|
||
export const createRulesEngineService = async (payload) => { | ||
const { edgeApplicationId, phase } = payload | ||
let httpResponse = await AxiosHttpClientAdapter.request({ | ||
url: `${makeEdgeApplicationBaseUrl()}/${edgeApplicationId}/rules_engine/${phase}/rules`, | ||
method: 'POST', | ||
body: adapt(payload) | ||
}) | ||
|
||
return parseHttpResponse(httpResponse, edgeApplicationId) | ||
} | ||
|
||
const adapt = (payload) => { | ||
return { | ||
name: payload.name, | ||
phase: payload.phase, | ||
criteria: payload.criteria, | ||
behaviors: payload.behaviors, | ||
is_active: payload.isActive, | ||
description: payload.description | ||
} | ||
} | ||
|
||
const errorMessagesMap = { | ||
duplicated_behaviors: `The behavior '{value}' is duplicated.`, | ||
blank_parameter: `The '{value}' field is empty.`, | ||
incompatible_behaviors: `The behavior '{value}' is incompatible with the others.`, | ||
invalid_behaviors: `The behavior '{value}' is invalid.`, | ||
invalid_behaviors_target: `The behavior '{value}' has a invalid target.` | ||
} | ||
|
||
/** | ||
* Extracts the first error message from an error object. | ||
* @param {Object} errorObject - The error object to extract the message from. | ||
* @returns {string} The first error message found. | ||
*/ | ||
function getFirstErrorMessage(errorObject) { | ||
for (let key in errorObject) { | ||
const errorValue = errorObject[key] | ||
if (typeof errorValue === 'string') { | ||
return errorValue | ||
} | ||
if (Array.isArray(errorValue)) { | ||
return processArrayError(key, errorValue) | ||
} | ||
if (typeof errorValue === 'object') { | ||
return getFirstErrorMessage(errorValue) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Processes an array error to extract the error message. | ||
* @param {string} key - The key of the error in the error object. | ||
* @param {Array} errorArray - The array containing the error details. | ||
* @returns {string} The processed error message. | ||
*/ | ||
function processArrayError(key, errorArray) { | ||
const errorMessageTemplate = errorMessagesMap[key] | ||
if (errorMessageTemplate) { | ||
let value = errorArray[0] | ||
if (key === 'incompatible_behaviors') { | ||
// Extract the behavior name from the string | ||
value = value.match(/\(u'(.*?)',/)[1].replace(/_/g, ' ') | ||
} else { | ||
value = value.replace(/_/g, ' ') | ||
} | ||
return errorMessageTemplate.replace('{value}', value) | ||
} | ||
return `${key}: ${errorArray[0]}` | ||
} | ||
|
||
/** | ||
* @param {Object} httpResponse - The HTTP response object. | ||
* @param {Object} httpResponse.body - The response body. | ||
* @param {String} httpResponse.statusCode - The HTTP status code. | ||
* @returns {string} The result message based on the status code. | ||
* @throws {Error} If there is an error with the response. | ||
*/ | ||
const parseHttpResponse = (httpResponse) => { | ||
switch (httpResponse.statusCode) { | ||
case 201: | ||
return { | ||
feedback: 'Your Rules Engine has been created.' | ||
} | ||
case 400: | ||
const apiError = getFirstErrorMessage(httpResponse) | ||
throw new Error(apiError).message | ||
case 401: | ||
throw new Errors.InvalidApiTokenError().message | ||
case 403: | ||
throw new Errors.PermissionError().message | ||
case 404: | ||
throw new Errors.NotFoundError().message | ||
case 500: | ||
throw new Errors.InternalServerError().message | ||
default: | ||
throw new Errors.UnexpectedError().message | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { listRulesEngineService } from './list-rules-engine-service' | ||
import { deleteRulesEngineService } from './delete-rules-engine-service' | ||
import { editRulesEngineService } from './edit-rules-engine-service' | ||
import { createRulesEngineService } from './create-rules-engine-service' | ||
import { loadRulesEngineService } from './load-rules-engine-service' | ||
import { reorderRulesEngine } from './reorder-rules-engine-service' | ||
|
||
export { | ||
listRulesEngineService, | ||
createRulesEngineService, | ||
editRulesEngineService, | ||
loadRulesEngineService, | ||
deleteRulesEngineService, | ||
reorderRulesEngine | ||
} |
44 changes: 44 additions & 0 deletions
44
src/services/edge-application-rules-engine-services/load-rules-engine-service.js
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,44 @@ | ||
import { AxiosHttpClientAdapter, parseHttpResponse } from '@/services/axios/AxiosHttpClientAdapter' | ||
import { makeEdgeApplicationBaseUrl } from '../edge-application-services/make-edge-application-base-url' | ||
|
||
export const loadRulesEngineService = async ({ edgeApplicationId, id, phase }) => { | ||
const rulesPhase = generateRulePhase(phase) | ||
|
||
let httpResponse = await AxiosHttpClientAdapter.request({ | ||
url: `${makeEdgeApplicationBaseUrl()}/${edgeApplicationId}/rules_engine/${rulesPhase}/rules/${id}`, | ||
method: 'GET' | ||
}) | ||
httpResponse = adapt(httpResponse) | ||
|
||
return parseHttpResponse(httpResponse) | ||
} | ||
|
||
/** | ||
* | ||
* @param {Object} phase | ||
* @param {string | undefined} phase.content | ||
* @returns {string} | ||
*/ | ||
const generateRulePhase = (phase) => { | ||
const DEFAULT_RULE_PHASE = 'Default' | ||
return phase.content === DEFAULT_RULE_PHASE ? 'request' : phase.content?.toLowerCase() | ||
} | ||
|
||
const adapt = (httpResponse) => { | ||
const ruleEngine = httpResponse.body.results | ||
const parsedBody = { | ||
id: ruleEngine.id, | ||
name: ruleEngine.name, | ||
phase: ruleEngine.phase, | ||
criteria: ruleEngine.criteria, | ||
behaviors: ruleEngine.behaviors, | ||
isActive: ruleEngine.is_active, | ||
order: ruleEngine.order, | ||
description: ruleEngine.description | ||
} | ||
|
||
return { | ||
body: parsedBody, | ||
statusCode: httpResponse.statusCode | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
src/services/edge-application-services/make-edge-application-base-url.js
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,4 +1,3 @@ | ||
export const makeEdgeApplicationBaseUrl = () => { | ||
const version = 'v3' | ||
return `${version}/edge_applications` | ||
return `v3/edge_applications` | ||
} |
Oops, something went wrong.