diff --git a/src/components/priority-logics/PriorityLogicUtils.res b/src/components/priority-logics/PriorityLogicUtils.res deleted file mode 100644 index e516b8d6c..000000000 --- a/src/components/priority-logics/PriorityLogicUtils.res +++ /dev/null @@ -1,7 +0,0 @@ -type gateway = { - gateway_name: string, - distribution: int, - disableFallback: bool, -} - -type formState = CreateConfig | EditConfig | ViewConfig diff --git a/src/screens/HyperSwitch/Routing/AdvancedRouting/RoutingPreviewer.res b/src/screens/HyperSwitch/Routing/AdvancedRouting/RoutingPreviewer.res index 578ca6eb4..95f691b4a 100644 --- a/src/screens/HyperSwitch/Routing/AdvancedRouting/RoutingPreviewer.res +++ b/src/screens/HyperSwitch/Routing/AdvancedRouting/RoutingPreviewer.res @@ -1,5 +1,4 @@ open RoutingTypes -open RoutingUtils module SimplePreview = { @react.component @@ -26,6 +25,7 @@ module SimplePreview = { } } + module GatewayView = { @react.component let make = (~gateways, ~connectorList=?) => { @@ -56,126 +56,3 @@ module GatewayView = { } } -module RulePreviewer = { - @react.component - let make = (~ruleInfo: ruleInfoType, ~isFrom3ds=false) => { - open LogicUtils -
-
-
- {ruleInfo.rules - ->Array.mapWithIndex((rule, index) => { - let headingText = `Rule ${string_of_int(index + 1)}` - let marginStyle = index === ruleInfo.rules->Array.length - 1 ? "mt-2" : "my-2" - let threeDsType = - rule.routingOutput->Belt.Option.getWithDefault(defaultThreeDsObjectValue) -
-
- {headingText->React.string} -
-
-
- {rule.conditions - ->RoutingUtils.filterEmptyValues - ->Array.mapWithIndex((condition, index) => { - let logical = logicalOperatorTypeToStringMapper(condition.logicalOperator) - let operator = operatorTypeToStringMapper(condition.operator) - let field = condition.field->String.length > 0 ? condition.field : "" - - let value = switch condition.value { - | StringArray(arr) => arr->Array.joinWith(", ") - | String(str) => str - | Int(int) => int->Belt.Int.toString - } - let metadataKey = switch condition.metadata { - | Some(json) => json->getDictFromJsonObject->getOptionString("key") - | _ => None - } - -
- - - - - {switch metadataKey { - | Some(key) => - | None => React.null - }} - - -
- }) - ->React.array} -
- Array.length > 0}> - - - -
- {threeDsType.override_3ds->LogicUtils.capitalizeString->React.string} -
-
- - - -
-
- }) - ->React.array} -
- -
-
- ()} - /> -
- {React.string("Default Processors")} - {React.string(" *")} -
-
-
- {ruleInfo.default_gateways - ->Array.mapWithIndex((gateway, index) => { -
-
- {React.string(string_of_int(index + 1))} -
-
{gateway->React.string}
- Array.length - 1}> - ()} - /> - -
- }) - ->React.array} -
-
-
-
-
- } -} diff --git a/src/screens/HyperSwitch/Routing/HistoryEntity.res b/src/screens/HyperSwitch/Routing/HistoryEntity.res index e90fb16d2..47ecffdd9 100644 --- a/src/screens/HyperSwitch/Routing/HistoryEntity.res +++ b/src/screens/HyperSwitch/Routing/HistoryEntity.res @@ -2,7 +2,17 @@ open LogicUtils open RoutingUtils open RoutingTypes -let allColumns = [Name, Type, ProfileId, ProfileName, Description, Created, LastUpdated, Status] +let allColumns: array = [ + Name, + Type, + ProfileId, + ProfileName, + Description, + Created, + LastUpdated, + Status, +] + let itemToObjMapper = dict => { { id: getString(dict, "id", ""), @@ -14,9 +24,17 @@ let itemToObjMapper = dict => { created_at: getString(dict, "created_at", ""), } } -let defaultColumns = [Name, ProfileId, ProfileName, Type, Description, Status] -let getHeading = colType => { +let defaultColumns: array = [ + Name, + ProfileId, + ProfileName, + Type, + Description, + Status, +] + +let getHeading: historyColType => Table.header = colType => { switch colType { | Name => Table.makeHeaderInfo(~key="name", ~title="Name of Control", ~showSort=true, ()) | Type => Table.makeHeaderInfo(~key="kind", ~title="Type of Control", ~showSort=true, ()) @@ -32,7 +50,7 @@ let getHeading = colType => { } } let getTableCell = activeRoutingIds => { - let getCell = (historyData, colType): Table.cell => { + let getCell = (historyData, colType: historyColType): Table.cell => { switch colType { | Name => Text(historyData.name) | Type => diff --git a/src/screens/HyperSwitch/Routing/PriorityRouting.res b/src/screens/HyperSwitch/Routing/PriorityRouting.res index 20592a4a4..7533a3f18 100644 --- a/src/screens/HyperSwitch/Routing/PriorityRouting.res +++ b/src/screens/HyperSwitch/Routing/PriorityRouting.res @@ -1,7 +1,6 @@ open RoutingUtils open APIUtils open RoutingTypes -open PriorityLogicUtils open RoutingPreviewer module SimpleRoutingView = { @react.component diff --git a/src/screens/HyperSwitch/Routing/RoutingTypes.res b/src/screens/HyperSwitch/Routing/RoutingTypes.res index bd0b6c90d..4b0a522fa 100644 --- a/src/screens/HyperSwitch/Routing/RoutingTypes.res +++ b/src/screens/HyperSwitch/Routing/RoutingTypes.res @@ -1,7 +1,21 @@ type routingType = SINGLE | PRIORITY | VOLUME_SPLIT | ADVANCED | COST | DEFAULTFALLBACK | NO_ROUTING -type modalValue = {conType: string, conText: React.element} -type routingValueType = {heading: string, subHeading: string} -type modalObj = (routingType, string) => modalValue +type formState = CreateConfig | EditConfig | ViewConfig +type status = ACTIVE | APPROVED | PENDING | REJECTED +type pageState = Preview | Create | Edit +type variantType = Number | Enum_variant | Metadata_value | String_value | UnknownVariant(string) +type logicalOperator = AND | OR | UnknownLogicalOperator(string) +type val = StringArray(array) | String(string) | Int(int) + +type historyColType = + | Name + | Type + | ProfileId + | ProfileName + | Description + | Created + | LastUpdated + | Status + type colType = | Name | Description @@ -10,8 +24,6 @@ type colType = | DateCreated | LastUpdated -type status = ACTIVE | APPROVED | PENDING | REJECTED -type configType = RuleBased | CodeBased type operator = | IS | IS_NOT @@ -22,75 +34,30 @@ type operator = | NOT_CONTAINS | NOT_EQUAL_TO | UnknownOperator(string) -type variantType = Number | Enum_variant | Metadata_value | String_value | UnknownVariant(string) -type logicalOperator = AND | OR | UnknownLogicalOperator(string) -type val = StringArray(array) | String(string) | Int(int) -type logic = { - id: string, - name: string, - description: string, - isActiveLogic: bool, - status: status, - configType: configType, - version: string, - priorityLogic: string, - priorityLogicRules: string, - dateCreated: string, - lastUpdated: string, -} -type response = { - useCode: bool, - gatewayPriority: string, - gatewayPriorityLogic: string, - logics: array, -} + +type modalValue = {conType: string, conText: React.element} +type routingValueType = {heading: string, subHeading: string} +type modalObj = (routingType, string) => modalValue + type wasmModule = { getAllKeys: unit => array, getKeyType: string => string, getAllConnectors: unit => array, getVariantValues: string => array, } + type gateway = { distribution: int, disableFallback: bool, gateway_name: string, } + type volumeDistribution = { connector: string, split: int, } -type pageState = Preview | Create | Edit -type condition = { - field: string, - metadata?: Js.Json.t, - operator: operator, - value: val, - logicalOperator: logicalOperator, -} -type routingOutputType = {override_3ds: string} -type rule = { - gateways: array, - conditions: array, - routingOutput?: routingOutputType, -} -type ruleInfoType = { - rules: array, - default_gateways: array, -} - -type gateWAY = {gateways: array} -type volumeDistributionType = {volumeBasedDistribution: gateWAY} -type ruleDict = {json: volumeDistributionType} -type historyColType = - | Name - | Type - | ProfileId - | ProfileName - | Description - | Created - | LastUpdated - | Status +type routingOutputType = {override_3ds: string} type historyData = { id: string, @@ -103,9 +70,3 @@ type historyData = { } type value = {"type": Js.Json.t, "value": Js.Json.t} -type payloadCondition = { - lhs: string, - comparison: string, - value: value, - metadata: Js.Json.t, -} diff --git a/src/screens/HyperSwitch/Routing/RoutingUtils.res b/src/screens/HyperSwitch/Routing/RoutingUtils.res index 0a4f4067a..a1528303a 100644 --- a/src/screens/HyperSwitch/Routing/RoutingUtils.res +++ b/src/screens/HyperSwitch/Routing/RoutingUtils.res @@ -1,9 +1,7 @@ open RoutingTypes open LogicUtils external toWasm: Js.Dict.t => wasmModule = "%identity" -let getObjects = (_: Js.Json.t) => { - [] -} + let defaultThreeDsObjectValue: routingOutputType = { override_3ds: "three_ds", } @@ -19,38 +17,6 @@ let getCurrentUTCTime = () => { `${currYear}-${currMonth}-${currDay}` } -let operatorMapper = value => { - switch value { - | "CONTAINS" => CONTAINS - | "NOT_CONTAINS" => NOT_CONTAINS - | "IS" => IS - | "IS_NOT" => IS_NOT - | "GREATER THAN" => GREATER_THAN - | "LESS THAN" => LESS_THAN - | "EQUAL TO" => EQUAL_TO - | "NOT EQUAL_TO" => NOT_EQUAL_TO - | _ => UnknownOperator("") - } -} - -let variantTypeMapper = variantType => { - switch variantType { - | "number" => Number - | "enum_variant" => Enum_variant - | "metadata_value" => Metadata_value - | "str_value" => String_value - | _ => UnknownVariant("") - } -} - -let logicalOperatorMapper = logical => { - switch logical { - | "AND" => AND - | "OR" => OR - | _ => UnknownLogicalOperator("") - } -} - let routingTypeMapper = routingType => { switch routingType { | "single" => SINGLE @@ -75,75 +41,6 @@ let routingTypeName = routingType => { } } -let logicalOperatorTypeToStringMapper = logicalOperator => { - switch logicalOperator { - | AND => "AND" - | OR => "OR" - | UnknownLogicalOperator(str) => str - } -} -let operatorTypeToStringMapper = operator => { - switch operator { - | IS => "IS" - | CONTAINS => "CONTAINS" - | IS_NOT => "IS_NOT" - | NOT_CONTAINS => "NOT_CONTAINS" - | GREATER_THAN => "GREATER THAN" - | LESS_THAN => "LESS THAN" - | EQUAL_TO => "EQUAL TO" - | NOT_EQUAL_TO => "NOT EQUAL_TO" - | UnknownOperator(str) => str - } -} - -let itemGateWayObjMapper = ( - dict, - _connectorList: option>, -) => { - let connectorId = dict->getDictfromDict("connector")->getString("merchant_connector_id", "") - [ - ("distribution", dict->getFloat("split", 0.00)->Js.Json.number), - ("disableFallback", dict->getBool("disableFallback", false)->Js.Json.boolean), - ("gateway_name", connectorId->Js.Json.string), - ]->Dict.fromArray -} - -let itemBodyGateWayObjMapper = ( - dict, - connectorList: option>, -) => { - let merchantConnectorId = - dict->getDictfromDict("connector")->getString("merchant_connector_id", "") - let name = - connectorList - ->Belt.Option.getWithDefault([Dict.make()->ConnectorTableUtils.getProcessorPayloadType]) - ->ConnectorTableUtils.getConnectorNameViaId(merchantConnectorId) - let newDict = - [ - ("connector", name.connector_name->Js.Json.string), - ("merchant_connector_id", merchantConnectorId->Js.Json.string), - ] - ->Dict.fromArray - ->Js.Json.object_ - [("split", dict->getFloat("split", 0.00)->Js.Json.number), ("connector", newDict)]->Dict.fromArray -} - -let connectorPayload = (routingType, arr) => { - switch routingType->routingTypeMapper { - | VOLUME_SPLIT => { - let connectorData = arr->Array.reduce([], (acc, routingObj) => { - let routingDict = routingObj->getDictFromJsonObject - acc->Array.push(getString(routingDict, "connector", "")) - acc - }) - connectorData - } - - | PRIORITY => arr->Js.Json.array->getStrArryFromJson - | _ => [] - } -} - let getRoutingPayload = (data, routingType, name, description, profileId) => { let connectorsOrder = [("data", data->Js.Json.array), ("type", routingType->Js.Json.string)]->Dict.fromArray @@ -156,210 +53,6 @@ let getRoutingPayload = (data, routingType, name, description, profileId) => { ]->Dict.fromArray } -let getWasmKeyType = (wasm, value) => { - try { - switch wasm { - | Some(res) => res.getKeyType(value) - | None => "" - } - } catch { - | _ => "" - } -} - -let getWasmVariantValues = (wasm, value) => { - try { - switch wasm { - | Some(res) => res.getVariantValues(value) - | None => [] - } - } catch { - | _ => [] - } -} - -let getWasmGateway = wasm => { - try { - switch wasm { - | Some(res) => res.getAllConnectors() - | None => [] - } - } catch { - | _ => [] - } -} - -let advanceRoutingConditionMapper = (dict, wasm) => { - let variantType = wasm->getWasmKeyType(dict->getString("field", "")) - let obj = { - lhs: dict->getString("field", ""), - comparison: switch dict->getString("operator", "")->operatorMapper { - | IS => "equal" - | IS_NOT => "not_equal" - | CONTAINS => "equal" - | NOT_CONTAINS => "not_equal" - | EQUAL_TO => "equal" - | GREATER_THAN => "greater_than" - | LESS_THAN => "less_than" - | NOT_EQUAL_TO => "not_equal" - | UnknownOperator(str) => str - }, - value: { - "type": switch variantType->variantTypeMapper { - | Number => "number" - | Enum_variant => - switch dict->getString("operator", "")->operatorMapper { - | IS => "enum_variant" - | CONTAINS => "enum_variant_array" - | IS_NOT => "enum_variant" - | NOT_CONTAINS => "enum_variant_array" - | _ => "" - } - | Metadata_value => "metadata_variant" - | String_value => "str_value" - | _ => "" - }->Js.Json.string, - "value": switch variantType->variantTypeMapper { - | Number => (dict->getString("value", "")->float_of_string *. 100.00)->Js.Json.number - | Enum_variant => - switch dict->getString("operator", "")->operatorMapper { - | IS => dict->getString("value", "")->Js.Json.string - | CONTAINS => dict->getArrayFromDict("value", [])->Js.Json.array - | IS_NOT => dict->getString("value", "")->Js.Json.string - | NOT_CONTAINS => dict->getArrayFromDict("value", [])->Js.Json.array - - | _ => ""->Js.Json.string - } - | Metadata_value => { - let key = - dict->getDictfromDict("metadata")->getString("key", "")->String.trim->Js.Json.string - let value = dict->getString("value", "")->String.trim->Js.Json.string - Dict.fromArray([("key", key), ("value", value)])->Js.Json.object_ - } - | String_value => dict->getString("value", "")->Js.Json.string - | _ => ""->Js.Json.string - }, - }, - metadata: Dict.make()->Js.Json.object_, - } - let value = [("value", obj.value["value"]), ("type", obj.value["type"])]->Dict.fromArray - let dict = - [ - ("lhs", obj.lhs->Js.Json.string), - ("comparison", obj.comparison->Js.Json.string), - ("value", value->Js.Json.object_), - ("metadata", obj.metadata), - ]->Dict.fromArray - - dict->Js.Json.object_ -} - -let getVolumeSplit = ( - dict_arr, - objMapper, - connectorList: option>, -) => { - dict_arr->Array.reduce([], (acc, routingObj) => { - let value = [routingObj->getDictFromJsonObject->objMapper(connectorList)->Js.Json.object_] - acc->Array.concat(value)->Array.map(value => value) - }) -} - -let checkIfValuePresesent = valueRes => { - // to check if the value is present only then add to the statement - let conditionMatched = switch Js.Json.classify(valueRes) { - | JSONArray(arr) => arr->Array.length > 0 - | JSONString(str) => str->String.length > 0 - | JSONNumber(num) => num > Belt.Int.toFloat(0) - | _ => false - } - conditionMatched -} - -let generateStatement = (arr, wasm) => { - let conditionDict = Dict.make() - let statementDict = Dict.make() - arr->Array.forEachWithIndex((item, index) => { - let valueRes = - item->getDictFromJsonObject->Dict.get("value")->Belt.Option.getWithDefault([]->Js.Json.array) - - if valueRes->checkIfValuePresesent { - let value = item->getDictFromJsonObject->advanceRoutingConditionMapper(wasm) - let logical = item->getDictFromJsonObject->getString("logical.operator", "") - - switch logical->logicalOperatorMapper { - | OR => { - let copyDict = Js.Dict.map((. val) => val, conditionDict) - Dict.set(statementDict, Belt.Int.toString(index), copyDict) - conditionDict->Dict.set("condition", []->Js.Json.array) - let val = - conditionDict->Dict.get("condition")->Belt.Option.getWithDefault([]->Js.Json.array) - let arr = switch Js.Json.classify(val) { - | JSONArray(arr) => { - arr->Array.push(value) - arr - } - | _ => [] - } - conditionDict->Dict.set("condition", arr->Js.Json.array) - } - - | _ => - let val = - conditionDict->Dict.get("condition")->Belt.Option.getWithDefault([]->Js.Json.array) - let arr = switch Js.Json.classify(val) { - | JSONArray(arr) => { - arr->Array.push(value) - arr - } - - | _ => [] - } - conditionDict->Dict.set("condition", arr->Js.Json.array) - } - } - }) - - let copyDict = Js.Dict.map((. val) => val, conditionDict) - Dict.set(statementDict, Belt.Int.toString(arr->Array.length), copyDict) - statementDict - ->Dict.keysToArray - ->Array.map(val => { - switch statementDict->Dict.get(val) { - | Some(dt) => dt->Js.Json.object_ - | _ => Dict.make()->Js.Json.object_ - } - }) -} - -let getDefaultSelection = dict => { - [ - ("data", dict->getArrayFromDict("default_gateways", [])->Js.Json.array), - ("type", "priority"->Js.Json.string), - ]->Dict.fromArray -} -let generateRuleObject = (index, connectorSelection, statement) => { - let ruleObj = Dict.fromArray([ - ("name", `rule_${string_of_int(index + 1)}`->Js.Json.string), - ("statements", statement->Js.Json.array), - ("connectorSelection", connectorSelection->Js.Json.object_), - ]) - ruleObj -} -let constuctAlgorithm = (dict, rules, metadata) => { - let body = - [ - ("defaultSelection", getDefaultSelection(dict)->Js.Json.object_), - ("rules", rules->Js.Json.array), - ("metadata", metadata->Js.Json.object_), - ]->Dict.fromArray - - let algorithm = - [("type", "advanced"->Js.Json.string), ("data", body->Js.Json.object_)]->Dict.fromArray - - algorithm -} - let getModalObj = (routingType, text) => { switch routingType { | ADVANCED => { @@ -453,21 +146,6 @@ let valueTypeMapper = dict => { value } -let conditionTypeMapper = (conditionArr: array) => { - let conditionArray = [] - conditionArr->Array.forEach(value => { - let val = value->getDictFromJsonObject - let tempval = { - field: val->getString("field", ""), - metadata: val->getDictfromDict("metadata")->Js.Json.object_, - operator: val->getString("operator", "")->operatorMapper, - value: val->valueTypeMapper, - logicalOperator: val->getString("logical.operator", "")->logicalOperatorMapper, - } - conditionArray->Array.push(tempval) - }) - conditionArray -} let threeDsTypeMapper = dict => { let getRoutingOutputval = dict->getString("override_3ds", "three_ds") let val = { @@ -490,78 +168,8 @@ let constructNameDescription = routingType => { ]) } -let manipulateInitialValueJson = initialValueJson => { - let manipulatedJson = ADVANCED->constructNameDescription - manipulatedJson->Dict.set("code", initialValueJson->getString("code", "")->Js.Json.string) - manipulatedJson->Dict.set("json", initialValueJson->getObj("json", Dict.make())->Js.Json.object_) - manipulatedJson -} let currentTabNameRecoilAtom = Recoil.atom(. "currentTabName", "ActiveTab") -module SaveAndActivateButton = { - @react.component - let make = ( - ~onSubmit: (Js.Json.t, 'a) => promise>, - ~handleActivateConfiguration, - ) => { - let formState: ReactFinalForm.formState = ReactFinalForm.useFormState( - ReactFinalForm.useFormSubscription(["values"])->Js.Nullable.return, - ) - - let handleSaveAndActivate = async _ev => { - try { - let onSubmitResponse = await onSubmit(formState.values, false) - let currentActivatedFromJson = - onSubmitResponse->Js.Nullable.toOption->Belt.Option.getWithDefault(Js.Json.null) - let currentActivatedId = - currentActivatedFromJson->LogicUtils.getDictFromJsonObject->LogicUtils.getString("id", "") - let _ = await handleActivateConfiguration(Some(currentActivatedId)) - } catch { - | Js.Exn.Error(e) => - let _err = - Js.Exn.message(e)->Belt.Option.getWithDefault( - "Failed to save and activate configuration!", - ) - } - } -