Skip to content

Commit aaca8d4

Browse files
authored
Add App Builder Sample Extension (#2)
1 parent a3f492d commit aaca8d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1981
-9
lines changed

.github/CONTRIBUTING.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Contributing to Magento 2 code
2+
3+
Contributions to the Magento 2 codebase are done using the fork & pull model.
4+
This contribution model has contributors maintaining their own copy of the forked codebase (which can easily be synced with the main copy). The forked repository is then used to submit a request to the base repository to “pull” a set of changes. For more information on pull requests please refer to [GitHub Help](https://help.github.com/articles/about-pull-requests/).
5+
6+
Contributions can take the form of new components or features, changes to existing features, tests, documentation (such as developer guides, user guides, examples, or specifications), bug fixes or optimizations.
7+
8+
The Magento 2 development team will review all issues and contributions submitted by the community of developers in the first in, first out order. During the review we might require clarifications from the contributor. If there is no response from the contributor within two weeks, the pull request will be closed.
9+
10+
11+
## Contribution requirements
12+
13+
1. Contributions must adhere to the [Magento coding standards](https://devdocs.magento.com/guides/v2.2/coding-standards/bk-coding-standards.html).
14+
2. Pull requests (PRs) must be accompanied by a meaningful description of their purpose. Comprehensive descriptions increase the chances of a pull request being merged quickly and without additional clarification requests.
15+
3. Commits must be accompanied by meaningful commit messages. Please see the [Magento Pull Request Template](https://github.com/magento/magento2/blob/2.2-develop/.github/PULL_REQUEST_TEMPLATE.md) for more information.
16+
4. PRs which include bug fixes must be accompanied with a step-by-step description of how to reproduce the bug.
17+
3. PRs which include new logic or new features must be submitted along with:
18+
* Unit/integration test coverage.
19+
* Proposed [documentation](https://devdocs.magento.com) updates. Documentation contributions can be submitted via the [devdocs GitHub](https://github.com/magento/devdocs).
20+
4. For larger features or changes, please [open an issue](https://github.com/magento/magento2/issues) to discuss the proposed changes prior to development. This may prevent duplicate or unnecessary effort and allow other contributors to provide input.
21+
5. All automated tests must pass (all builds on [Travis CI](https://travis-ci.org/magento/magento2) must be green).
22+
23+
## Contribution process
24+
25+
If you are a new GitHub user, we recommend that you create your own [free github account](https://github.com/signup/free). This will allow you to collaborate with the Magento 2 development team, fork the Magento 2 project and send pull requests.
26+
27+
1. Search current [listed issues](https://github.com/magento/magento2/issues) (open or closed) for similar proposals of intended contribution before starting work on a new contribution.
28+
2. Review and sign the [Contributor License Agreement (CLA)](https://opensource.adobe.com/cla.html) if this is your first time contributing. You only need to sign the CLA once.
29+
3. Create and test your work.
30+
4. Fork the Magento 2 repository according to the [Fork A Repository instructions](https://devdocs.magento.com/guides/v2.2/contributor-guide/contributing.html#fork) and when you are ready to send us a pull request – follow the [Create A Pull Request instructions](https://devdocs.magento.com/guides/v2.2/contributor-guide/contributing.html#pull_request).
31+
5. Once your contribution is received the Magento 2 development team will review the contribution and collaborate with you as needed.
32+
33+
## Code of Conduct
34+
35+
Please note that this project is released with a Contributor Code of Conduct. We expect you to agree to its terms when participating in this project.
36+
The full text is available in the repository [Wiki](https://github.com/magento/magento2/wiki/Magento-Code-of-Conduct).

.github/ISSUE_TEMPLATE.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!--- STOP! Before you open an issue please search this repository's issues to see if it has already been reported. This helps reduce duplicate issues from being created. -->
2+
<!--- SECURITY DISCLOSURE: If this is a security disclosure please follow the guidelines in CONTRIBUTING.md. This helps keep folks from accidentally releasing vulnerabilities before the maintainers get a chance to fix the issue. -->
3+
4+
### Expected Behaviour
5+
6+
### Actual Behaviour
7+
8+
### Reproduce Scenario (including but not limited to)
9+
10+
#### Steps to Reproduce
11+
12+
#### Platform and Version
13+
14+
#### Sample Code that illustrates the problem
15+
16+
#### Logs taken while reproducing problem

.github/PULL_REQUEST_TEMPLATE.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!--- Provide a general summary of your changes in the Title above -->
2+
3+
## Description
4+
5+
<!--- Describe your changes in detail -->
6+
7+
## Related Issue
8+
9+
<!--- This project only accepts pull requests related to open issues -->
10+
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
11+
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
12+
<!--- Please link to the issue here: -->
13+
14+
## Motivation and Context
15+
16+
<!--- Why is this change required? What problem does it solve? -->
17+
18+
## How Has This Been Tested?
19+
20+
<!--- Please describe in detail how you tested your changes. -->
21+
<!--- Include details of your testing environment, and the tests you ran to -->
22+
<!--- see how your change affects other areas of the code, etc. -->
23+
24+
## Screenshots (if appropriate):
25+
26+
## Types of changes
27+
28+
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
29+
30+
- [ ] Bug fix (non-breaking change which fixes an issue)
31+
- [ ] New feature (non-breaking change which adds functionality)
32+
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
33+
34+
## Checklist:
35+
36+
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
37+
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
38+
39+
- [ ] I have signed the [Adobe Open Source CLA](https://opensource.adobe.com/cla.html).
40+
- [ ] My code follows the code style of this project.
41+
- [ ] My change requires a change to the documentation.
42+
- [ ] I have updated the documentation accordingly.
43+
- [ ] I have read the **CONTRIBUTING** document.
44+
- [ ] I have added tests to cover my changes.
45+
- [ ] All new and existing tests passed.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

CODE_OF_CONDUCT

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language.
12+
* Being respectful of differing viewpoints and experiences.
13+
* Gracefully accepting constructive criticism.
14+
* Focusing on what is best for the community.
15+
* Showing empathy towards other community members.
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances.
20+
* Trolling, insulting/derogatory comments, and personal or political attacks.
21+
* Public or private harassment.
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission.
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting.
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version].
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

COPYRIGHT

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Copyright 2024 Adobe. All rights reserved.
2+
3+
Adobe holds the copyright for all the files found in this repository.
4+
5+
See the LICENSE file for licensing information.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2024 Adobe
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
# Adobe Commerce - Extensibility Code Samples
2+
23
This project is a collection of code samples that demonstrate common extensibility use cases for Adobe Commerce.
34

4-
### What this project is
5+
## What this project is
6+
57
This project is intended as a reference for developers to learn how to extend and integrate Adobe Commerce. The code is meant to showcase concepts and may not necessarily implement real-world scenarios.
68

7-
### What this project isn't
9+
## What this project isn't
10+
811
The code in the project is not meant to be construed as production-ready code and should not be used as-is in production use cases. It may not have been tested for security, performance, or other best practices.
912

10-
### How to use this project
13+
## Prerequisites
14+
15+
- Access to Adobe Developer Console.
16+
- Full access or trial access to App Builder.
17+
- Project and workspaces has been created and correctly configured.
18+
- AIO CLI installed to run commands.
19+
20+
## How to use this project
21+
1122
The code and comments are expected to be self-explanatory and developers can use them to learn the concepts. When deploying code from this project, ensure it is only used in development environments
1223

13-
### Contributing to this project
14-
* Contribute new samples: runtime actions, mesh configs, dropins, etc…
15-
* Samples should be heavily commented describing WHAT the code does and WHY.
16-
* Report or fix any bugs or inefficiencies.
17-
* Participate in code reviews.
24+
## Contributing to this project
25+
26+
Contributions are welcomed!
27+
28+
- Contribute new samples: runtime actions, mesh configs, dropins, etc…
29+
- Samples should be heavily commented describing WHAT the code does and WHY.
30+
- Report or fix any bugs or inefficiencies.
31+
- Participate in code reviews.
32+
33+
## Licensing
34+
35+
This project is licensed under the Apache V2 License. See [LICENSE](LICENSE) for more information.

sample-extension/.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# package directories
2+
node_modules
3+
4+
# build
5+
build
6+
dist
7+
.manifest-dist.yml
8+
9+
# Config
10+
config.json
11+
.env*
12+
!.env.dist
13+
.aio
14+
15+
# Adobe I/O console config
16+
console.json
17+
18+
.idea
19+
package-lock.json
20+
.aws.tmp.creds.json
21+
.parcel-cache
22+
.DS_Store
23+
.vscode
24+

sample-extension/README.md

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Sample Extension
2+
3+
The sample extension is an App Builder application that helps you start with Out-of-Process extensibility for Adobe Commerce.
4+
5+
## Prerequisites
6+
7+
- Have the Adobe AIO CLI installed.
8+
- Have an App Builder project created in your IMS organization.
9+
10+
## Setup
11+
12+
- Run `npm install`.
13+
- Run `aio console where` to check if the right project and workspace are selected. If not, you can run `aio console project select` and `aio console workspace select`.
14+
- Run `aio app use` to create and populate `.env` and `.aio` files. Make sure you defined your OAuth credentials in the project first and added the I/O Management API to the workspace.
15+
- Run `aio app build`.
16+
17+
## Local Dev
18+
19+
- `aio app run` to start your local Dev server.
20+
- App will run on `localhost:9080` by default.
21+
22+
By default, the UI will be served locally but actions will be deployed and served from Adobe I/O Runtime. To start a
23+
local serverless stack and also run your actions locally use the `aio app run --local` option.
24+
25+
## Test & Coverage
26+
27+
- Run `aio app test` to run unit tests for ui and actions.
28+
- Run `aio app test --e2e` to run e2e tests.
29+
30+
## Deploy & Cleanup
31+
32+
- `aio app deploy` to build and deploy all actions on Runtime and static files to CDN
33+
- `aio app undeploy` to undeploy the app
34+
35+
## Config
36+
37+
### `.env` and `.aio`
38+
39+
The `.env` and `.aio` files should not be committed to source control.
40+
41+
### `app.config.yaml`
42+
43+
- Main configuration file that defines an application's implementation.
44+
- More information on this file, application configuration, and extension configuration
45+
can be found [here](https://developer.adobe.com/app-builder/docs/guides/appbuilder-configuration/#appconfigyaml)
46+
47+
#### Action Dependencies
48+
49+
- You have two options to resolve your actions' dependencies:
50+
51+
1. **Packaged action file**: Add your action's dependencies to the root
52+
`package.json` and install them using `npm install`. Then set the `function`
53+
field in `app.config.yaml` to point to the **entry file** of your action
54+
folder. We will use `webpack` to package your code and dependencies into a
55+
single minified js file. The action will then be deployed as a single file.
56+
Use this method if you want to reduce the size of your actions.
57+
58+
2. **Zipped action folder**: In the folder containing the action code add a
59+
`package.json` with the action's dependencies. Then set the `function`
60+
field in `app.config.yaml` to point to the **folder** of that action. We will
61+
install the required dependencies within that directory and zip the folder
62+
before deploying it as a zipped action. Use this method if you want to keep
63+
your action's dependencies separated.
64+
65+
## Debugging in VS Code
66+
67+
While running your local server (`aio app run`), both UI and actions can be debugged, to do so open the vscode debugger
68+
and select the debugging configuration called `WebAndActions`.
69+
Alternatively, there are also debug configs for only UI and each separate action.
70+
71+
## Typescript support for UI
72+
73+
To use typescript use `.tsx` extension for react components and add a `tsconfig.json`
74+
and make sure you have the below config added
75+
```
76+
{
77+
"compilerOptions": {
78+
"jsx": "react"
79+
}
80+
}
81+
```
82+
83+
## Test Admin UI SDK registrations in your Commerce instance
84+
85+
### Local development
86+
87+
For your local development you can refer to the following [documentation](https://developer.adobe.com/commerce/extensibility/admin-ui-sdk/configuration/).
88+
89+
### Cloud instance
90+
91+
For your cloud instance testing, you'll have to publish your application by following this [documentation](https://developer.adobe.com/commerce/extensibility/admin-ui-sdk/publish/).
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2024 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
const { Core } = require('@adobe/aio-sdk')
13+
const { errorResponse, checkMissingRequestInputs} = require('../utils')
14+
const { getCommerceOauthClient } = require('../oauth1a')
15+
16+
async function main(params) {
17+
const logger = Core.Logger('main', { level: params.LOG_LEVEL || 'info' })
18+
19+
try {
20+
const requiredParams = ['operation', 'COMMERCE_BASE_URL']
21+
const requiredHeaders = ['Authorization']
22+
const errorMessage = checkMissingRequestInputs(params, requiredParams, requiredHeaders)
23+
if (errorMessage) {
24+
// return and log client errors
25+
return errorResponse(400, errorMessage, logger)
26+
}
27+
28+
const { operation } = params
29+
30+
const oauth = getCommerceOauthClient(
31+
{
32+
url: params.COMMERCE_BASE_URL,
33+
consumerKey: params.COMMERCE_CONSUMER_KEY,
34+
consumerSecret: params.COMMERCE_CONSUMER_SECRET,
35+
accessToken: params.COMMERCE_ACCESS_TOKEN,
36+
accessTokenSecret: params.COMMERCE_ACCESS_TOKEN_SECRET
37+
},
38+
logger
39+
)
40+
41+
const content = await oauth.get(operation)
42+
43+
return {
44+
statusCode: 200,
45+
body: content
46+
}
47+
} catch (error) {
48+
// log any server errors
49+
logger.error(error)
50+
// return with 500
51+
return errorResponse(500, error, logger)
52+
}
53+
}
54+
55+
exports.main = main

0 commit comments

Comments
 (0)