Skip to content

Instantly share code, notes, and snippets.

@naydav
Created October 1, 2021 16:31
Show Gist options
  • Save naydav/97c4024dd879a6b9a186efa04cd00f18 to your computer and use it in GitHub Desktop.
Save naydav/97c4024dd879a6b9a186efa04cd00f18 to your computer and use it in GitHub Desktop.
i-am-here-action
/*
* <license header>
*/
/**
* This is a sample action showcasing how to access an external API
*
* Note:
* You might want to disable authentication and authorization checks against Adobe Identity Management System for a generic action. In that case:
* - Remove the require-adobe-auth annotation for this action in the manifest.yml of your application
* - Remove the Authorization header from the array passed in checkMissingRequestInputs
* - The two steps above imply that every client knowing the URL to this deployed action will be able to invoke it without any authentication and authorization checks against Adobe Identity Management System
* - Make sure to validate these changes against your security requirements before deploying the action
*/
const fetch = require('node-fetch')
const { Core } = require('@adobe/aio-sdk')
const { errorResponse, getBearerToken, stringParameters, checkMissingRequestInputs } = require('../utils')
// main function that will be executed by Adobe I/O Runtime
async function main (params) {
// create a Logger
const logger = Core.Logger('main', { level: params.LOG_LEVEL || 'debug' })
try {
// 'info' is the default level if not set
logger.info('Calling the main action')
// log parameters, only if params.LOG_LEVEL === 'debug'
logger.debug(stringParameters(params))
// check for missing request input parameters and headers
const requiredParams = ['orderNumber', 'parkingSpaceNumber', 'customerEmail']
const requiredHeaders = []
const errorMessage = checkMissingRequestInputs(params, requiredParams, requiredHeaders)
if (errorMessage) {
// return and log client errors
return errorResponse(400, errorMessage, logger)
}
const response = {
statusCode: 200,
body: JSON.stringify({
orderNumber: params.orderNumber,
parkingSpace: params.parkingSpaceNumber,
customerEmail: params.customerEmail
})
}
// log the response status code
logger.info(`${response.statusCode}: successful request`)
return response
} catch (error) {
// log any server errors
logger.error(error)
// return with 500
return errorResponse(500, 'server error', logger)
}
}
exports.main = main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment