Skip to content

Commit

Permalink
Added sample for Adobe Commerce Webhook (#8)
Browse files Browse the repository at this point in the history
* Added webhooks code sample app.

* Finished webhooks action process.

* Changed webhook folder name.

* devcontainer for running the solution

* adds github actions to run webhook

* stubs out a pr test for the sample extension

* renames workflows for easier identification

* adds a workflow readme

* adds content to the readme

* updates the path for the webhooks test action

* adds static testing for api mesh directory

* Finished webhooks sample unit tests and updated Readme.

* Added Adobe license header and EOF empty line.

* Removed unecessary web-src folder and updated readme file.

* Adding EOF empty lines and updating webhooks readme file.

* Removing unnecessary dependencies.

---------

Co-authored-by: Gabriel Ranghetti <gabriel.ranghetti@toyota.com>
Co-authored-by: Doug Hatcher <doug.hatcher@blueacornici.com>
  • Loading branch information
3 people authored Jun 7, 2024
1 parent 7155ad5 commit d241ce3
Show file tree
Hide file tree
Showing 23 changed files with 12,634 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Adobe Commerce Samples",

"image": "mcr.microsoft.com/devcontainers/base:jammy",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"version": "18",
"nvmVersion": "latest"
}
},

"postCreateCommand": "npm install -g @adobe/aio-cli && aio telemetry yes && aio plugins:install @adobe/aio-cli-plugin-api-mesh"


}
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
19 changes: 19 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Github Actions

This repository has several self-contained example projects that need to be regularly tested when modified. While some example projects have their own `.github` directory, this mono-repo needs a varient of these workflows to work in order to account for different directory structures and other changes. This directory houses these modified versions.

## Github Actions Setup

The following are the variables required for the github actions to execute correctly

| Variable | Description | Default Value |
|------------------------------|-----------------------------------------------------------------------------------------------|--------------------------------|
| AIO_RUNTIME_NAMESPACE_STAGE | The namespace for the AIO runtime environment in the staging stage, used for isolating resources and configurations. | `aio-runtime-namespace-stage` |
| CLIENTID_STAGE | The client identifier for the staging environment, used to authenticate API requests. | `client-id-stage` |
| CLIENTSECRET_STAGE | The client secret for the staging environment, used in conjunction with the client ID to authenticate API requests. | `client-secret-stage` |
| IMSORGID_STAGE | The IMS organization ID for the staging environment, used to identify the organization within the IMS system. | `ims-org-id-stage` |
| SCOPES_STAGE | The OAuth scopes for the staging environment, defining the permissions granted to the application. | `read:scope-stage write:scope-stage` |
| TECHNICALACCEMAIL_STAGE | The email address associated with the technical account for the staging environment, used for notifications and account recovery. | `tech-account-email-stage@example.com` |
| TECHNICALACCID_STAGE | The identifier for the technical account in the staging environment, used for managing the technical user and associated resources. | `tech-account-id-stage` |

Credentials like Technical Account Email can be found by adding an I/O Action Event to the App Builder workspace and then adding an `Oauth Server-to-server` credential, this will generate most of the credentials needed above. For anything else, within the workspace click `Download All` and copy the information from the json file.
43 changes: 43 additions & 0 deletions .github/workflows/api-mesh_mock-response_pr_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: API Mesh/Mock Response CI
on: [pull_request, push]
jobs:
deploy:
name: Lint
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 1
matrix:
node-version: ['20']
os: [ubuntu-latest]
steps:

- name: Checkout
uses: actions/checkout@v4

- name: Prepare Context (Linux/macOS)
if: runner.os != 'Windows'
run: mv -f api-mesh/mock-response/* .
- name: Prepare Context (Windows)
if: runner.os == 'Windows'
run: |
$source = "api-mesh\mock-response\*"
$destination = "."
$files = Get-ChildItem -Path $source
foreach ($file in $files) {
$destPath = Join-Path -Path $destination -ChildPath $file.Name
if (Test-Path -Path $destPath) {
Remove-Item -Path $destPath -Recurse -Force
}
}
Move-Item -Path $source -Destination $destination -Force
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: setup dependancies
run: npm install -g eslint jsonlint
- name: Lint JSON
run: jsonlint *.json
- name: Lint Js
run: eslint *.js
66 changes: 66 additions & 0 deletions .github/workflows/sample_extention_pr_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Sample Extension CI

on: [pull_request, push]
jobs:
test:
name: Test PR
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: ['20']
os: [macOS-latest, ubuntu-latest, windows-latest]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare Context (Linux/macOS)
if: runner.os != 'Windows'
run: mv -f sample-extension/* .
- name: Prepare Context (Windows)
if: runner.os == 'Windows'
run: |
$source = "sample-extension\*"
$destination = "."
$files = Get-ChildItem -Path $source
foreach ($file in $files) {
$destPath = Join-Path -Path $destination -ChildPath $file.Name
if (Test-Path -Path $destPath) {
Remove-Item -Path $destPath -Recurse -Force
}
}
Move-Item -Path $source -Destination $destination -Force
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: npm install
run: npm i
- name: Setup CLI
uses: adobe/aio-cli-setup-action@1.3.0
with:
os: ${{ matrix.os }}
version: 10.x.x
- name: Auth
uses: adobe/aio-apps-action@3.3.0
with:
os: ${{ matrix.os }}
command: oauth_sts
CLIENTID: ${{ secrets.CLIENTID_STAGE }}
CLIENTSECRET: ${{ secrets.CLIENTSECRET_STAGE }}
TECHNICALACCOUNTID: ${{ secrets.TECHNICALACCID_STAGE }}
TECHNICALACCOUNTEMAIL: ${{ secrets.TECHNICALACCEMAIL_STAGE }}
IMSORGID: ${{ secrets.IMSORGID_STAGE }}
SCOPES: ${{ secrets.SCOPES_STAGE }}
- name: Build
env:
AIO_RUNTIME_NAMESPACE: ${{ secrets.AIO_RUNTIME_NAMESPACE_STAGE }}
uses: adobe/aio-apps-action@3.3.0
with:
os: ${{ matrix.os }}
command: build
- name: Test
uses: adobe/aio-apps-action@3.3.0
with:
os: ${{ matrix.os }}
command: test
66 changes: 66 additions & 0 deletions .github/workflows/webhooks_pr_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Webhooks CI

on: [pull_request, push]
jobs:
test:
name: Test PR
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: ['20']
os: [macOS-latest, ubuntu-latest, windows-latest]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare Context (Linux/macOS)
if: runner.os != 'Windows'
run: mv -f webhooks/add-to-cart-stock-validation/* .
- name: Prepare Context (Windows)
if: runner.os == 'Windows'
run: |
$source = "webhooks\add-to-cart-stock-validation\*"
$destination = "."
$files = Get-ChildItem -Path $source
foreach ($file in $files) {
$destPath = Join-Path -Path $destination -ChildPath $file.Name
if (Test-Path -Path $destPath) {
Remove-Item -Path $destPath -Recurse -Force
}
}
Move-Item -Path $source -Destination $destination -Force
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: npm install
run: npm i
- name: Setup CLI
uses: adobe/aio-cli-setup-action@1.3.0
with:
os: ${{ matrix.os }}
version: 10.x.x
- name: Auth
uses: adobe/aio-apps-action@3.3.0
with:
os: ${{ matrix.os }}
command: oauth_sts
CLIENTID: ${{ secrets.CLIENTID_STAGE }}
CLIENTSECRET: ${{ secrets.CLIENTSECRET_STAGE }}
TECHNICALACCOUNTID: ${{ secrets.TECHNICALACCID_STAGE }}
TECHNICALACCOUNTEMAIL: ${{ secrets.TECHNICALACCEMAIL_STAGE }}
IMSORGID: ${{ secrets.IMSORGID_STAGE }}
SCOPES: ${{ secrets.SCOPES_STAGE }}
- name: Build
env:
AIO_RUNTIME_NAMESPACE: ${{ secrets.AIO_RUNTIME_NAMESPACE_STAGE }}
uses: adobe/aio-apps-action@3.3.0
with:
os: ${{ matrix.os }}
command: build
- name: Test
uses: adobe/aio-apps-action@3.3.0
with:
os: ${{ matrix.os }}
command: test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.vscode
62 changes: 62 additions & 0 deletions api-mesh/mock-response/.github/workflows/pr_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CI
# Controls when the workflow will run
# on:
# # Triggers the workflow on push or pull request events but only for the "main" branch
# # push:
# # branches: [ "main" ]
# # pull_request:
# # branches: [ "main" ]

# # Allows you to run this workflow manually from the Actions tab
# workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
deploy:
name: Lint
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 1
matrix:
node-version: ['20']
os: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Setup CLI
uses: adobe/aio-cli-setup-action@1.3.0
with:
os: ${{ matrix.os }}
version: 10.x.x
- name: api-mesh-plugin install
run: aio plugins:install @adobe/aio-cli-plugin-api-mesh
- name: Auth
uses: adobe/aio-apps-action@3.3.0
with:
os: ${{ matrix.os }}
command: oauth_sts
CLIENTID: ${{ secrets.CLIENTID_PROD }}
CLIENTSECRET: ${{ secrets.CLIENTSECRET_PROD }}
TECHNICALACCOUNTID: ${{ secrets.TECHNICALACCID_PROD }}
TECHNICALACCOUNTEMAIL: ${{ secrets.TECHNICALACCEMAIL_PROD }}
IMSORGID: ${{ secrets.IMSORGID_PROD }}
SCOPES: AdobeID, openid, read_organizations, additional_info.projectedProductContext, additional_info.roles, adobeio_api, read_client_secret, manage_client_secrets
- name: Select org
run: aio console:org:select ${{ secrets.ORGID_PROD }}
- name: Select project
run: aio console:project:select ${{ secrets.PROJECTID_PROD }}
- name: Select workspace
run: aio console:workspace:select ${{ secrets.WORKSPACEID_PROD }}
- name: 'Create env file'
run: |
touch .env
echo API_ENDPOINT="https://xxx.execute-api.us-west-2.amazonaws.com" >> .env
echo API_KEY=${{ secrets.API_KEY }} >> .env
cat .env
- name: api-mesh update
run: aio api-mesh:update -c meshConfig.json --env .env
63 changes: 63 additions & 0 deletions api-mesh/mock-response/.github/workflows/pr_prod_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
# push:
# branches: [ "main" ]
# pull_request:
# branches: [ "main" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
deploy:
name: Deploy to Prod
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 1
matrix:
node-version: ['20']
os: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Setup CLI
uses: adobe/aio-cli-setup-action@1.3.0
with:
os: ${{ matrix.os }}
version: 10.x.x
- name: api-mesh-plugin install
run: aio plugins:install @adobe/aio-cli-plugin-api-mesh
- name: Auth
uses: adobe/aio-apps-action@3.3.0
with:
os: ${{ matrix.os }}
command: oauth_sts
CLIENTID: ${{ secrets.CLIENTID_PROD }}
CLIENTSECRET: ${{ secrets.CLIENTSECRET_PROD }}
TECHNICALACCOUNTID: ${{ secrets.TECHNICALACCID_PROD }}
TECHNICALACCOUNTEMAIL: ${{ secrets.TECHNICALACCEMAIL_PROD }}
IMSORGID: ${{ secrets.IMSORGID_PROD }}
SCOPES: AdobeID, openid, read_organizations, additional_info.projectedProductContext, additional_info.roles, adobeio_api, read_client_secret, manage_client_secrets
- name: Select org
run: aio console:org:select ${{ secrets.ORGID_PROD }}
- name: Select project
run: aio console:project:select ${{ secrets.PROJECTID_PROD }}
- name: Select workspace
run: aio console:workspace:select ${{ secrets.WORKSPACEID_PROD }}
- name: 'Create env file'
run: |
touch .env
echo API_ENDPOINT="https://xxx.execute-api.us-west-2.amazonaws.com" >> .env
echo API_KEY=${{ secrets.API_KEY }} >> .env
cat .env
- name: api-mesh update
run: aio api-mesh:update -c meshConfig.json --env .env
1 change: 1 addition & 0 deletions api-mesh/mock-response/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
6 changes: 3 additions & 3 deletions webhooks/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Adobe Commerce Webhooks Applications

This section contains a collection of application examples that demonstrate the use of Webhooks in Adobe Commerce.
This section contains a collection of application examples that demonstrate the use of Webhooks in Adobe Commerce.
Each application serves as a practical example of how Webhooks can be utilized to enhance the functionality and efficiency of your Adobe Commerce store.

## Applications List

The applications covered in this section include:

-
- **add-to-cart-stock-validation**: Product add to cart stock validation.

Please refer to the README file of each individual application for more details.

Expand All @@ -17,4 +17,4 @@ To get started with these applications, simply navigate to the directory of the

## Note

Please note that this section is still a **work in progress**. Application examples will be available soon.
Please note that this section is still a **work in progress**. Application examples will be available soon.
5 changes: 5 additions & 0 deletions webhooks/add-to-cart-stock-validation/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": [
"@babel/plugin-transform-react-jsx"
]
}
10 changes: 10 additions & 0 deletions webhooks/add-to-cart-stock-validation/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"env": {
"es6": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:jest/recommended"],
"parserOptions": {
"ecmaVersion": "latest"
}
}
Loading

0 comments on commit d241ce3

Please sign in to comment.