Edit in GitHubLog an issue

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.js
web: 'no'
runtime: nodejs:16
inputs:
LOG_LEVEL: debug
YOUR_PARAM: $YOUR_PARAM
annotations:
require-adobe-auth: true
final: true

This parameter is now accessible in the params object.

Copied to your clipboard
async 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 clipboard
const 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.

  1. Add the event to the scripts/onboarding/config/events.json file under the corresponding entity. For example, if the event is related to a customer and is coming from commerce, you should add it under the customer entity in the commerce section. To modify an existing event, edit the event in the corresponding section of the ./onboarding/config/events.json file.

    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"
    ],
    ...
    }
  2. Run the onboarding script:

    Copied to your clipboard
    npm run onboard
  3. In the action/{entity}/{flow} directory, add or modify the action that will handle this event, such as actions/customer/commerce/NEW_OPERATION/index.js.

  4. Add the newly created operation action to the action/{entity}/{flow}/actions.config.yaml config file or edit the existing action flow.

    Copied to your clipboard
    NEW_OPERATION:
    function: NEW_OPERATION/index.js
    web: 'no'
    runtime: nodejs:16
    inputs:
    LOG_LEVEL: debug
    annotations:
    require-adobe-auth: true
    final: true
  5. Add a new case to the switch statement in the consumer of the entity flow action/{entity}/{flow} or edit the existing case:

    Copied to your clipboard
    case '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?.body
    statusCode = res?.response?.result?.statusCode
    break
    }
  6. Deploy the changes:

    Copied to your clipboard
    `aio app deploy`

After completing this process, you can consume the new or updated event.

  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.