Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
ISSUE: ADPM-34
  • Loading branch information
goran-stamenkovski-logeecom committed Oct 10, 2023
1 parent 57600a3 commit 56d68b5
Show file tree
Hide file tree
Showing 116 changed files with 1,041 additions and 1,043 deletions.
2 changes: 1 addition & 1 deletion extension/extension-trigger/index.azureFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const azureExtensionTrigger = async function (context, req) {
try {
const paymentResult = await paymentHandler.handlePayment(
paymentObj,
authToken
authToken,
)

if (paymentResult.actions)
Expand Down
2 changes: 1 addition & 1 deletion extension/index.googleFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const extensionTrigger = async (request, response) => {
const authToken = getAuthorizationRequestHeader(request)
const paymentResult = await paymentHandler.handlePayment(
paymentObj,
authToken
authToken,
)
if (paymentResult.actions) {
return response.status(200).send({
Expand Down
2 changes: 1 addition & 1 deletion extension/index.lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let handler = async (event) => {
const authToken = getAuthorizationRequestHeader(event)
const paymentResult = await paymentHandler.handlePayment(
paymentObj,
authToken
authToken,
)
return {
responseType: paymentResult.actions
Expand Down
4 changes: 2 additions & 2 deletions extension/src/api/payment/payment.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function processRequest(request, response) {
// API extensions always calls this endpoint with POST, so if we got GET, we don't process further
// https://docs.commercetools.com/api/projects/api-extensions#input
logger.debug(
`Received non-POST request: ${request.method}. The request will not be processed...`
`Received non-POST request: ${request.method}. The request will not be processed...`,
)
return httpUtils.sendResponse({
response,
Expand All @@ -33,7 +33,7 @@ async function processRequest(request, response) {
logger.debug('Received payment object', JSON.stringify(paymentObject))
const paymentResult = await paymentHandler.handlePayment(
paymentObject,
authToken
authToken,
)
const result = {
response,
Expand Down
2 changes: 1 addition & 1 deletion extension/src/config/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function loadFromAdyenIntegrationEnvVar() {
return JSON.parse(process.env.ADYEN_INTEGRATION_CONFIG)
} catch (e) {
throw new Error(
'Adyen integration configuration is not provided in the JSON format'
'Adyen integration configuration is not provided in the JSON format',
)
}
}
Expand Down
22 changes: 11 additions & 11 deletions extension/src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function getModuleConfig() {
return {
removeSensitiveData: _getValueOfBooleanFlag(
config.removeSensitiveData,
true
true,
),
port: config.port,
logLevel: config.logLevel,
Expand All @@ -19,11 +19,11 @@ function getModuleConfig() {
: undefined,
addCommercetoolsLineItems: _getValueOfBooleanFlag(
config.addCommercetoolsLineItems,
false
false,
),
generateIdempotencyKey: _getValueOfBooleanFlag(
config.generateIdempotencyKey,
false
false,
),
}
}
Expand Down Expand Up @@ -67,7 +67,7 @@ function getCtpConfig(ctpProjectKey) {
const ctpConfig = config.commercetools[ctpProjectKey]
if (!ctpConfig)
throw new Error(
`Configuration is not provided. Please update the configuration. ctpProjectKey: [${ctpProjectKey}]`
`Configuration is not provided. Please update the configuration. ctpProjectKey: [${ctpProjectKey}]`,
)
const result = {
clientId: ctpConfig.clientId,
Expand All @@ -93,8 +93,8 @@ function getAdyenConfig(adyenMerchantAccount) {
if (!adyenConfig)
throw new Error(
`Configuration for adyenMerchantAccount is not provided. Please update the configuration: ${JSON.stringify(
adyenMerchantAccount
)}`
adyenMerchantAccount,
)}`,
)
return {
apiKey: adyenConfig.apiKey,
Expand Down Expand Up @@ -132,26 +132,26 @@ function loadAndValidateConfig() {
const numberOfAdyenConfigs = Object.keys(config.adyen).length
if (numberOfCtpConfigs === 0)
throw new Error(
'Please add at least one commercetools project to the config'
'Please add at least one commercetools project to the config',
)
if (numberOfAdyenConfigs === 0)
throw new Error(
'Please add at least one Adyen merchant account to the config'
'Please add at least one Adyen merchant account to the config',
)

for (const [ctpProjectKey, ctpConfig] of Object.entries(
config.commercetools
config.commercetools,
)) {
if (!ctpConfig.clientId || !ctpConfig.clientSecret)
throw new Error(
`[${ctpProjectKey}]: CTP project credentials are missing. ` +
'Please verify that all projects have projectKey, clientId and clientSecret'
'Please verify that all projects have projectKey, clientId and clientSecret',
)
const errorMessage = _validateAuthenticationConfig(ctpConfig)
if (errorMessage) {
throw new Error(
`Authentication is not properly configured. Please update the configuration. error : [${errorMessage}]
ctpProjectKey: [${ctpProjectKey}]`
ctpProjectKey: [${ctpProjectKey}]`,
)
}
}
Expand Down
20 changes: 10 additions & 10 deletions extension/src/config/init/ensure-api-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ async function ensureApiExtensions(
ctpClient,
ctpProjectKey,
ctpAdyenIntegrationBaseUrl,
ctpAuthHeaderValue
ctpAuthHeaderValue,
) {
const apiExtensionTemplate = await utils.readAndParseJsonFile(
'resources/api-extension.json'
'resources/api-extension.json',
)
try {
const logger = mainLogger.child({
Expand All @@ -20,25 +20,25 @@ async function ensureApiExtensions(
const extensionDraft = JSON.parse(
_.template(JSON.stringify(apiExtensionTemplate))({
ctpAdyenIntegrationBaseUrl,
})
}),
)
if (ctpAuthHeaderValue) {
extensionDraft.destination.authentication = JSON.parse(
`{` +
` "type": "AuthorizationHeader",` +
` "headerValue": "${ctpAuthHeaderValue}"` +
` }`
` }`,
)
}
const existingExtension = await fetchExtensionByKey(
ctpClient,
apiExtensionTemplate.key
apiExtensionTemplate.key,
)
if (existingExtension === null) {
await ctpClient.create(ctpClient.builder.extensions, extensionDraft)
logger.info(
'Successfully created an API extension for payment resource type ' +
`(key=${apiExtensionTemplate.key})`
`(key=${apiExtensionTemplate.key})`,
)
} else {
const actions = buildUpdateActions(existingExtension, extensionDraft)
Expand All @@ -47,18 +47,18 @@ async function ensureApiExtensions(
ctpClient.builder.extensions,
existingExtension.id,
existingExtension.version,
actions
actions,
)
logger.info(
'Successfully updated the API extension for payment resource type ' +
`(key=${apiExtensionTemplate.key})`
`(key=${apiExtensionTemplate.key})`,
)
}
}
} catch (err) {
throw Error(
`Failed to sync API extension (key=${apiExtensionTemplate.key}). ` +
`Error: ${JSON.stringify(serializeError(err))}`
`Error: ${JSON.stringify(serializeError(err))}`,
)
}
}
Expand All @@ -84,7 +84,7 @@ async function fetchExtensionByKey(ctpClient, key) {
try {
const { body } = await ctpClient.fetchByKey(
ctpClient.builder.extensions,
key
key,
)
return body
} catch (err) {
Expand Down
16 changes: 8 additions & 8 deletions extension/src/config/init/ensure-custom-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ const mainLogger = utils.getLogger()

async function ensurePaymentCustomType(ctpClient, ctpProjectKey) {
const paymentCustomType = await utils.readAndParseJsonFile(
'resources/web-components-payment-type.json'
'resources/web-components-payment-type.json',
)
return syncCustomType(
ctpClient,
createChildLogger(ctpProjectKey),
paymentCustomType
paymentCustomType,
)
}

async function ensureInterfaceInteractionCustomType(ctpClient, ctpProjectKey) {
const interfaceInteractionType = await utils.readAndParseJsonFile(
'resources/payment-interface-interaction-type.json'
'resources/payment-interface-interaction-type.json',
)
return syncCustomType(
ctpClient,
createChildLogger(ctpProjectKey),
interfaceInteractionType
interfaceInteractionType,
)
}

async function ensureTransactionCustomType(ctpClient, ctpProjectKey) {
const interfaceInteractionType = await utils.readAndParseJsonFile(
'resources/payment-transaction-type.json'
'resources/payment-transaction-type.json',
)
return syncCustomType(
ctpClient,
createChildLogger(ctpProjectKey),
interfaceInteractionType
interfaceInteractionType,
)
}

Expand All @@ -59,15 +59,15 @@ async function syncCustomType(ctpClient, logger, typeDraft) {
ctpClient.builder.types,
existingType.id,
existingType.version,
updateActions
updateActions,
)
logger.info(`Successfully updated the type (key=${typeDraft.key})`)
}
}
} catch (err) {
throw Error(
`Failed to sync payment type (key=${typeDraft.key}). ` +
`Error: ${JSON.stringify(serializeError(err))}`
`Error: ${JSON.stringify(serializeError(err))}`,
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions extension/src/config/init/ensure-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ function ensureResources(
ctpClient,
ctpProjectKey,
apiExtensionBaseUrl,
authHeaderValue
authHeaderValue,
) {
return Promise.all([
ensureCustomTypes(ctpClient, ctpProjectKey),
ensureApiExtensions(
ctpClient,
ctpProjectKey,
apiExtensionBaseUrl,
authHeaderValue
authHeaderValue,
),
])
}
Expand Down
10 changes: 5 additions & 5 deletions extension/src/ctp.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ async function setUpClient(config) {
return ctpClient.execute(
this.buildRequestOptions(
uri.byId(id).withVersion(version).build(),
'DELETE'
)
'DELETE',
),
)
},

create(uri, body) {
return ctpClient.execute(
this.buildRequestOptions(uri.build(), 'POST', body)
this.buildRequestOptions(uri.build(), 'POST', body),
)
},

Expand All @@ -114,7 +114,7 @@ async function setUpClient(config) {
actions,
}
return ctpClient.execute(
this.buildRequestOptions(uri.byId(id).build(), 'POST', body)
this.buildRequestOptions(uri.byId(id).build(), 'POST', body),
)
},

Expand All @@ -134,7 +134,7 @@ async function setUpClient(config) {
return this.process(
this.buildRequestOptions(uri.build()),
(data) => Promise.resolve(callback(data.body.results)),
opts
opts,
)
},

Expand Down
6 changes: 3 additions & 3 deletions extension/src/paymentHandler/amount-updates.handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import c from '../config/constants.js'

async function execute(paymentObject) {
const amountUpdatesRequestObj = JSON.parse(
paymentObject.custom.fields.amountUpdatesRequest
paymentObject.custom.fields.amountUpdatesRequest,
)
const adyenMerchantAccount = paymentObject.custom.fields.adyenMerchantAccount
const commercetoolsProjectKey =
paymentObject.custom.fields.commercetoolsProjectKey
const { request, response } = await updateAmount(
adyenMerchantAccount,
commercetoolsProjectKey,
amountUpdatesRequestObj
amountUpdatesRequestObj,
)
return {
actions: [
Expand All @@ -26,7 +26,7 @@ async function execute(paymentObject) {
}),
createSetCustomFieldAction(
c.CTP_CUSTOM_FIELD_AMOUNT_UPDATES_RESPONSE,
response
response,
),
],
}
Expand Down
4 changes: 2 additions & 2 deletions extension/src/paymentHandler/cancel-payment.handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function execute(paymentObject) {
const { request, response } = await cancelPayment(
adyenMerchantAccount,
commercetoolsProjectKey,
cancelRequestObj
cancelRequestObj,
)

const addInterfaceInteractionAction = createAddInterfaceInteractionAction({
Expand All @@ -38,7 +38,7 @@ async function execute(paymentObject) {
const actions = [addInterfaceInteractionAction]
if (!response.errorCode && response.pspReference)
actions.push(
..._createTransactionActions(paymentObject, response.pspReference)
..._createTransactionActions(paymentObject, response.pspReference),
)

return { actions }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import c from '../config/constants.js'

async function execute(paymentObject) {
const disableStoredPaymentRequestObj = JSON.parse(
paymentObject.custom.fields.disableStoredPaymentRequest
paymentObject.custom.fields.disableStoredPaymentRequest,
)
const adyenMerchantAccount = paymentObject.custom.fields.adyenMerchantAccount
const { request, response } = await disableStoredPayment(
adyenMerchantAccount,
disableStoredPaymentRequestObj
disableStoredPaymentRequestObj,
)

return {
Expand All @@ -24,7 +24,7 @@ async function execute(paymentObject) {
}),
createSetCustomFieldAction(
c.CTP_DISABLE_STORED_PAYMENT_RESPONSE,
response
response,
),
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { getCarbonOffsetCosts } from '../service/web-component-service.js'

async function execute(paymentObject) {
const getCarbonOffsetCostsRequestObj = JSON.parse(
paymentObject.custom.fields.getCarbonOffsetCostsRequest
paymentObject.custom.fields.getCarbonOffsetCostsRequest,
)
const adyenMerchantAccount = paymentObject.custom.fields.adyenMerchantAccount
const { request, response } = await getCarbonOffsetCosts(
adyenMerchantAccount,
getCarbonOffsetCostsRequestObj
getCarbonOffsetCostsRequestObj,
)
return {
actions: [
Expand Down
Loading

0 comments on commit 56d68b5

Please sign in to comment.