Skip to content

Commit

Permalink
Merge branch 'main' into access-control-added-in-codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja authored Jan 23, 2024
2 parents a3f533e + 84c283b commit cb3855f
Show file tree
Hide file tree
Showing 60 changed files with 157 additions and 123 deletions.
2 changes: 1 addition & 1 deletion src/components/HSwitchFeedBackModal.res
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let make = (
[
("Feedback", values->HSwitchUtils.getBodyForFeedBack(~modalType, ())->Js.Json.object_),
]->LogicUtils.getJsonFromArrayOfJson
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
let successMessage = switch modalType {
| FeedBackModal => "Thanks for feedback"
| RequestConnectorModal => "Request submitted succesfully"
Expand Down
2 changes: 1 addition & 1 deletion src/entryPoints/hyperswitch/HyperSwitchEntry.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module HyperSwitchEntryComponent = {
let url = `${HSwitchGlobalVars.hyperSwitchFEPrefix}/config/merchant-access`
let typedResponse =
(
await postDetails(url, Dict.make()->Js.Json.object_, Post)
await postDetails(url, Dict.make()->Js.Json.object_, Post, ())
)->FeatureFlagUtils.featureFlagType
setFeatureFlag(._ => typedResponse)
setScreenState(_ => PageLoaderWrapper.Success)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ module SelectPaymentMethods = {
let body = ConnectorUtils.constructConnectorRequestBody(obj, initialValues)
let connectorUrl = APIUtils.getURL(~entityName=CONNECTOR, ~methodType=Post, ~id=None, ())

let response = await updateAPIHook(connectorUrl, body, Post)
let response = await updateAPIHook(connectorUrl, body, Post, ())
setInitialValues(_ => response)
response->LogicUtils.getDictFromJsonObject->updateEnumForConnector->ignore
setConnectorConfigureState(_ => Summary)
Expand Down
57 changes: 19 additions & 38 deletions src/hooks/AuthHooks.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,23 @@ let getHeaders = (~uri, ~headers, ()) => {
let hyperSwitchToken = LocalStorage.getItem("login")->Js.Nullable.toOption
let isMixpanel = uri->String.includes("mixpanel")

if isMixpanel {
let headerObj = {
"Content-Type": "application/x-www-form-urlencoded",
"accept": "application/json",
}
Fetch.HeadersInit.make(headerObj)
let headerObj = if isMixpanel {
[
("Content-Type", "application/x-www-form-urlencoded"),
("accept", "application/json"),
]->Dict.fromArray
} else {
let headerObj = headers->Dict.get("api-key")->Option.getWithDefault("")->String.length > 0

if headerObj {
let headerObj = {
"Content-Type": "application/json",
"api-key": headers->Dict.get("api-key")->Option.getWithDefault(""),
let res = switch hyperSwitchToken {
| Some(token) => {
headers->Dict.set("authorization", `Bearer ${token}`)
headers
}
Fetch.HeadersInit.make(headerObj)
} else {
switch hyperSwitchToken {
| Some(token) =>
if token !== "" {
let headerObj = {
"Content-Type": "application/json",
"Authorization": `Bearer ${hyperSwitchToken->Option.getWithDefault("")}`,
"api-key": "hyperswitch",
}

Fetch.HeadersInit.make(headerObj)
} else {
let headerObj = {
"Content-Type": "application/json",
}
Fetch.HeadersInit.make(headerObj)
}

| None =>
let headerObj = {
"Content-Type": "application/json",
}
Fetch.HeadersInit.make(headerObj)
}
| None => headers
}
res
}
Fetch.HeadersInit.make(headerObj->dictToObj)
}

@val @scope(("window", "location"))
Expand All @@ -81,7 +57,8 @@ let useApiFetcher = () => {
(
uri,
~bodyStr: string="",
~headers=Dict.make(),
~bodyFormData=None,
~headers=[("Content-Type", "application/json")]->Dict.fromArray,
~bodyHeader as _=?,
~method_: Fetch.requestMethod,
~authToken as _=?,
Expand All @@ -98,7 +75,11 @@ let useApiFetcher = () => {

let body = switch method_ {
| Get => resolve(None)
| _ => resolve(Some(Fetch.BodyInit.make(bodyStr)))
| _ =>
switch bodyFormData {
| Some(formDataVal) => resolve(Some(Fetch.BodyInit.makeWithFormData(formDataVal)))
| None => resolve(Some(Fetch.BodyInit.make(bodyStr)))
}
}

body->then(body => {
Expand Down
19 changes: 17 additions & 2 deletions src/screens/HyperSwitch/APIUtils/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ let handleLogout = async (
~fetchApi as _: (
Js.String2.t,
~bodyStr: string=?,
~bodyFormData: option<Fetch.formData>=?,
~headers: Js.Dict.t<Js.String2.t>=?,
~bodyHeader: Js.Dict.t<Js.Json.t>=?,
~method_: Fetch.requestMethod,
Expand Down Expand Up @@ -387,9 +388,23 @@ let useUpdateMethod = (~showErrorToast=true, ()) => {
},
})

async (url, body, method) => {
async (
url,
body,
method,
~bodyFormData=?,
~headers=[("Content-Type", "application/json")]->Dict.fromArray,
(),
) => {
try {
let res = await fetchApi(url, ~method_=method, ~bodyStr=body->Js.Json.stringify, ())
let res = await fetchApi(
url,
~method_=method,
~bodyStr=body->Js.Json.stringify,
~bodyFormData,
~headers,
(),
)
await responseHandler(
~res,
~showErrorToast,
Expand Down
6 changes: 3 additions & 3 deletions src/screens/HyperSwitch/Analytics/Analytics.res
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ module TableWrapper = {
(),
)

fetchDetails(tableEntity.uri, weeklyTableReqBody, Post)
fetchDetails(tableEntity.uri, weeklyTableReqBody, Post, ())
->thenResolve(json => {
setTableData(_ => getUpdatedData(data, json, cols))
setTableDataLoading(_ => false)
Expand Down Expand Up @@ -285,7 +285,7 @@ module TableWrapper = {
(),
)

fetchDetails(tableEntity.uri, tableReqBody, Post)
fetchDetails(tableEntity.uri, tableReqBody, Post, ())
->thenResolve(json => {
switch weeklyTableMetricsCols {
| Some(cols) => getWeeklyData(json, cols)->ignore
Expand Down Expand Up @@ -612,7 +612,7 @@ let make = (
setFilterDataJson(_ => None)
if startTimeVal->isStringNonEmpty && endTimeVal->isStringNonEmpty {
try {
updateDetails(filterUri, filterBody->Js.Json.object_, Post)
updateDetails(filterUri, filterBody->Js.Json.object_, Post, ())
->thenResolve(json => setFilterDataJson(_ => json->Some))
->catch(_ => resolve())
->ignore
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/Analytics/DownloadReportModal.res
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let make = (~reportModal, ~setReportModal, ~entityName) => {
let downloadReport = async body => {
try {
let url = getURL(~entityName, ~methodType=Post, ())
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
setReportModal(_ => false)
showToast(~message="Email Sent", ~toastType=ToastSuccess, ())
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ module OverviewInfo = {
generateSampleDataUrl,
[("record", 50.0->Js.Json.number)]->Dict.fromArray->Js.Json.object_,
Post,
(),
)
showToast(~message="Sample data generated successfully.", ~toastType=ToastSuccess, ())
Window.Location.reload()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let make = () => {
let refundUrl = getURL(~entityName=REFUNDS, ~methodType=Post, ~id=Some("refund-post"), ())
let body = Dict.make()
body->Dict.set("limit", 100->Belt.Int.toFloat->Js.Json.number)
let refundDetails = await updateDetails(refundUrl, body->Js.Json.object_, Post)
let refundDetails = await updateDetails(refundUrl, body->Js.Json.object_, Post, ())
let data = refundDetails->getDictFromJsonObject->getArrayFromDict("data", [])

if data->Array.length < 1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ module HSiwtchPaymentConfirmLatency = {
}

let getOverallLatency = async () => {
updateDetails(url, singleStatBodyEntity->singleStatBodyMake("Payment"), Fetch.Post)
updateDetails(url, singleStatBodyEntity->singleStatBodyMake("Payment"), Fetch.Post, ())
->thenResolve(json => {
setOverallrLatency(_ => json->parseJson)
})
Expand All @@ -146,7 +146,7 @@ module HSiwtchPaymentConfirmLatency = {
}

let getConnectorLatency = () => {
updateDetails(url, singleStatBodyEntity->singleStatBodyMake("OutgoingEvent"), Fetch.Post)
updateDetails(url, singleStatBodyEntity->singleStatBodyMake("OutgoingEvent"), Fetch.Post, ())
->thenResolve(json => {
setConnectorLatency(_ => json->parseJson)
setIsLoading(_ => false)
Expand Down Expand Up @@ -275,7 +275,7 @@ module SystemMetricsAnalytics = {
setFilterDataJson(_ => None)
if startTimeVal->isStringNonEmpty && endTimeVal->isStringNonEmpty {
try {
updateDetails(filterUri, filterBody->Js.Json.object_, Post)
updateDetails(filterUri, filterBody->Js.Json.object_, Post, ())
->thenResolve(json => setFilterDataJson(_ => json->Some))
->catch(_ => resolve())
->ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ let make = (~setCurrentStep, ~setInitialValues, ~initialValues, ~isUpdateFlow, ~
~connector=Some(connector),
(),
)
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
setShowVerifyModal(_ => false)
onSubmitMain(values)->ignore
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let make = (
ConnectorUtils.connectorIgnoredField,
)
let connectorUrl = getURL(~entityName=CONNECTOR, ~methodType=Post, ~id=connectorID, ())
let response = await updateAPIHook(connectorUrl, body, Post)
let response = await updateAPIHook(connectorUrl, body, Post, ())
setInitialValues(_ => response)
setScreenState(_ => Success)
setCurrentStep(_ => ConnectorTypes.SummaryAndTest)
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/Connectors/ConnectorPreview.res
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ let make = (
isConnectorDisabled,
)
let url = getURL(~entityName=CONNECTOR, ~methodType=Post, ~id=Some(connectorID), ())
let _ = await updateDetails(url, disableConnectorPayload->Js.Json.object_, Post)
let _ = await updateDetails(url, disableConnectorPayload->Js.Json.object_, Post, ())
showToast(~message=`Successfully Saved the Changes`, ~toastType=ToastSuccess, ())
RescriptReactRouter.push("/connectors")
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module Simplified = {
try {
let (body, domainName) = values->constructVerifyApplePayReq(connectorID)
let verifyAppleUrl = getURL(~entityName=VERIFY_APPLE_PAY, ~methodType=Post, ())
let _ = await updateAPIHook(`${verifyAppleUrl}/${merchantId}`, body, Post)
let _ = await updateAPIHook(`${verifyAppleUrl}/${merchantId}`, body, Post, ())

let updatedValue = values->constructApplePayMetadata(metadataInputs, #simplified)
update(updatedValue)
Expand Down
4 changes: 2 additions & 2 deletions src/screens/HyperSwitch/Developer/APIKeys/KeyManagement.res
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module ApiEditModal = {
| _ => APIUtils.getURL(~entityName=API_KEYS, ~methodType=Post, ())
}

let json = await updateDetails(url, body->Js.Json.object_, Post)
let json = await updateDetails(url, body->Js.Json.object_, Post, ())
let keyDict = json->LogicUtils.getDictFromJsonObject

setApiKey(_ => keyDict->LogicUtils.getString("api_key", ""))
Expand Down Expand Up @@ -224,7 +224,7 @@ module TableActionsCell = {
~id=Some(keyId),
(),
)
(await deleteDetails(deleteUrl, body->Js.Json.object_, Delete))->ignore
(await deleteDetails(deleteUrl, body->Js.Json.object_, Delete, ()))->ignore
getAPIKeyDetails()->ignore
} catch {
| Js.Exn.Error(e) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let make = (~webhookOnly=false, ~showFormOnly=false, ~profileId="") => {
setScreenState(_ => PageLoaderWrapper.Loading)
let url = getURL(~entityName=BUSINESS_PROFILE, ~methodType=Post, ~id=Some(id), ())
let body = values->getBusinessProfilePayload->Js.Json.object_
let res = await updateDetails(url, body, Post)
let res = await updateDetails(url, body, Post, ())
let profileTypeInfo = res->businessProfileTypeMapper
setProfileInfo(_ => profileTypeInfo)
showToast(~message=`Details updated`, ~toastType=ToastState.ToastSuccess, ())
Expand Down
4 changes: 2 additions & 2 deletions src/screens/HyperSwitch/FraudAndRisk/FRMIntegrationFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ let make = (
->Js.Json.object_
let url = getURL(~entityName=MERCHANT_ACCOUNT, ~methodType=Post, ())
try {
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
} catch {
| _ => ()
}
Js.Nullable.null
}

let setFRMValues = async body => {
fetchApi(frmUrl, body, Fetch.Post)
fetchApi(frmUrl, body, Fetch.Post, ())
->thenResolve(res => {
setCurrentStep(prev => prev->getNextStep)
let _ = updateMerchantDetails()
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/FraudAndRisk/FRMSummary.res
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ let make = (~initialValues, ~currentStep, ~setCurrentStep) => {
let frmID = initialValues->getDictFromJsonObject->getString("merchant_connector_id", "")
let disableFRMPayload = initialValues->FRMTypes.getDisableConnectorPayload(isFRMDisabled)
let url = getURL(~entityName=FRAUD_RISK_MANAGEMENT, ~methodType=Post, ~id=Some(frmID), ())
let _ = await updateDetails(url, disableFRMPayload->Js.Json.object_, Post)
let _ = await updateDetails(url, disableFRMPayload->Js.Json.object_, Post, ())
showToast(~message=`Successfully Saved the Changes`, ~toastType=ToastSuccess, ())
RescriptReactRouter.push("/fraud-risk-management")
} catch {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/HSwitchRemoteFilter.res
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ module RemoteTableFilters = {
setFilterDataJson(_ => None)
if startTimeVal->isStringNonEmpty && endTimeVal->isStringNonEmpty {
try {
updateDetails(filterUrl, filterBody->Js.Json.object_, Post)
updateDetails(filterUrl, filterBody->Js.Json.object_, Post, ())
->thenResolve(json => setFilterDataJson(_ => json->Some))
->catch(_ => resolve())
->ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ let make = (~connectProcessorValue: connectProcessor) => {
firstProcessorRoutingPayload,
secondProcessorRoutingPayload,
)
let routingResponse = await updateDetails(routingUrl, body, Post)
let routingResponse = await updateDetails(routingUrl, body, Post, ())
let activatingId = routingResponse->getDictFromJsonObject->getString("id", "")
let activateRuleURL = getURL(
~entityName=ROUTING,
~methodType=Post,
~id=Some(activatingId),
(),
)
let _ = await updateDetails(activateRuleURL, Dict.make()->Js.Json.object_, Post)
let _ = await updateDetails(activateRuleURL, Dict.make()->Js.Json.object_, Post, ())
let _ = await updateEnumForRouting(activatingId)
setButtonState(_ => Normal)
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ let make = (
~json=connectorName->Window.getConnectorConfig,
~profileId=activeBusinessProfile.profile_id,
)
let res = await updateDetails(url, testConnectorBody, Post)
let res = await updateDetails(url, testConnectorBody, Post, ())
connectorArray->Array.push(connectorName)
setConnectorArray(_ => connectorArray)
setInitialValues(_ => res)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ module SelectPaymentMethods = {
let body = ConnectorUtils.constructConnectorRequestBody(obj, initialValues)
let connectorUrl = APIUtils.getURL(~entityName=CONNECTOR, ~methodType=Post, ~id=None, ())

let response = await updateAPIHook(connectorUrl, body, Post)
let response = await updateAPIHook(connectorUrl, body, Post, ())

setInitialValues(_ => response)
connectorArray->Array.push(connectorName)
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/Home/DelayedVerificationBanner.res
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let make = React.memo((~merchantId="", ~verificationDays) => {
let body = email->HyperSwitchAuthUtils.getEmailBody()
try {
let url = getURL(~entityName=USERS, ~userType=#VERIFY_EMAIL_REQUEST, ~methodType=Post, ())
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
showToast(~message=`Email Send Successfully!`, ~toastType=ToastSuccess, ())
} catch {
| _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let make = (~showModal, ~setShowModal, ~initialValues=Dict.make(), ~getProdVerif
let url = getURL(~entityName=USERS, ~userType=#USER_DATA, ~methodType=Post, ())
let bodyValues = values->getBody->Js.Json.object_
let body = [("ProdIntent", bodyValues)]->LogicUtils.getJsonFromArrayOfJson
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
showToast(
~toastType=ToastSuccess,
~message="Successfully sent for verification!",
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/Home/QuickStart/GoLive.res
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let make = (~goLive) => {
let url = getURL(~entityName=USERS, ~userType=#USER_DATA, ~methodType=Post, ())
let bodyValues = values->getBody->Js.Json.object_
let body = [("ProdIntent", bodyValues)]->LogicUtils.getJsonFromArrayOfJson
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())

getProdVerifyDetails()->ignore
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module RequestPage = {
->Js.Json.object_

let body = [("Feedback", requestedBody)]->LogicUtils.getJsonFromArrayOfJson
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
showToast(
~toastType=ToastSuccess,
~message="Request submitted successfully!",
Expand Down
Loading

0 comments on commit cb3855f

Please sign in to comment.