Developer tools
The following sections describe development tools and processes available in the starter kit.
Parameters as environment variables
The actionparams object allows you to pass values from your environment variables to an action. Add the parameter to your .env file:
YOUR_PARAM=your_value
To pass the parameters to the action, add the parameter as an input under the corresponding action in the actions/{entity}/../../actions.config.yaml file:
Copied to your clipboard{action name}:function: {action name}/index.jsweb: 'no'runtime: nodejs:16inputs:LOG_LEVEL: debugYOUR_PARAM: $YOUR_PARAMannotations:require-adobe-auth: truefinal: true
This parameter is now accessible in the params object.
Copied to your clipboardasync function main(params) {params.YOUR_PARAM}
Logging
Application logs allow developers to debug an application in development as well as monitor it in production. By default, the starter kit uses the Adobe I/O SDK to store logs in Adobe I/O Runtime. You can find additional details in Managing Application Logs.
Alternatively, the application logs can be forwarded to a customer-owned log management solution. Use When to use Log Forwarding to inform your decision when choosing to store logs in Adobe I/O Runtime or forward them to a log management platform.
If you are using Adobe Commerce on Cloud Infrastructure, you have access to a New Relic instance. Forwarding Logs to New Relic page describes the process necessary to configure starter kit to forward logs to New Relic.
Hiding secrets in logs
stringParameters in the ./actions/utils.js file can help you prevent exposing secrets when logging the parameters received by a runtime action. It replaces the authorization header value with <hidden> and any parameters containing a term present in the hidden array with <hidden>.
By default, the following parameters are hidden:
Copied to your clipboardconst hidden = ['secret','token']
Adjust these values to hide any secrets you want to pass as params to your runtime actions.
Testing
The starter kit provides unit tests for most of the predefined runtime actions. These tests are located in the ./test/actions folder.
Additionally, unit tests for the onboarding script can be found in the .test/scripts folder.
For more details about unit testing, refer to Testing a Serverless Action.
Create or modify an event
The starter kit comes with predefined events for each entity. If you need to add a new event to an entity or modify an existing one, use the following steps.
Add the event to the
scripts/onboarding/config/events.jsonfile under the corresponding entity. For example, if the event is related to a customer and is coming from commerce, you should add it under thecustomerentity in thecommercesection. To modify an existing event, edit the event in the corresponding section of the./onboarding/config/events.jsonfile.Copied to your clipboard"customer": {"commerce": ["com.adobe.commerce.observer.customer_save_commit_after","com.adobe.commerce.observer.customer_delete_commit_after","com.adobe.commerce.observer.customer_group_save_commit_after","com.adobe.commerce.observer.customer_group_delete_commit_after","com.adobe.commerce.THE_NEW_CUSTOMER_EVENT"],...}Run the onboarding script:
Copied to your clipboardnpm run onboardIn the
action/{entity}/{flow}directory, add or modify the action that will handle this event, such asactions/customer/commerce/NEW_OPERATION/index.js.Add the newly created operation action to the
action/{entity}/{flow}/actions.config.yamlconfig file or edit the existing action flow.Copied to your clipboardNEW_OPERATION:function: NEW_OPERATION/index.jsweb: 'no'runtime: nodejs:16inputs:LOG_LEVEL: debugannotations:require-adobe-auth: truefinal: trueAdd a new
caseto the switch statement in the consumer of the entity flowaction/{entity}/{flow}or edit the existingcase:Copied to your clipboardcase 'com.adobe.commerce.observer.NEW_CUSTOMER_EVENT': {logger.info('Invoking NEW OPERATION')const res = await openwhiskClient.invokeAction('customer-commerce/NEW_OPERATION', params.data.value)response = res?.response?.result?.bodystatusCode = res?.response?.result?.statusCodebreak}Deploy the changes:
Copied to your clipboard`aio app deploy`
After completing this process, you can consume the new or updated event.
