Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/rollup-2.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nellyk authored Jul 21, 2020
2 parents 92d6430 + 9c14e31 commit 02cd71f
Show file tree
Hide file tree
Showing 10 changed files with 3,225 additions and 1,081 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [5.2.2](https://github.com/americanexpress/one-app/compare/v5.2.1...v5.2.2) (2020-07-15)

### Dependency Updates

* **deps-dev/webdriverio** 6.1.20 to 6.1.24
* **deps/@americanexpress/one-app-ducks** 4.0.1 to 4.1.1
* **deps/@americanexpress/one-app-bundler** 6.6.0 to 6.7.0
* **deps-dev/jest** 26.0.1 to 26.1.0
* **deps/@americanexpress/fetch-enhancers** 1.0.0 to 1.0.1

<a name="5.2.1"></a>
## [5.2.1](https://github.com/americanexpress/one-app/compare/v5.2.0...v5.2.1) (2020-07-01)

Expand Down
16 changes: 9 additions & 7 deletions docs/api/modules/App-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,13 @@ The `eventLoopDelayThreshold` directive accepts a number representing the thresh
if (!global.BROWSER) {
Module.appConfig = {
validateStateConfig: {
server: {
[settingName]: {
[settingName]: {
server: {
validate(settingValue) {
// Throw an error or return undefined
},
},
},
client: {
[settingName]: {
client: {
validate(settingValue) {
// Throw an error or return undefined
},
Expand All @@ -468,9 +466,13 @@ if (!global.BROWSER) {
}
```

The `validateStateConfig` allows a Child Module to validate settings passed from `provideStateConfig`. Each `settingName` object accepts a `validate(settingValue)` method. The `validate` function may throw an `Error` or return `undefined` depending on validity of the value supplied to the Module on load.
The `validateStateConfig` allows a Child Module to validate settings passed from
`provideStateConfig`. Each `settingName` object accepts a `validate(settingValue)`
method per `server` and `client` key. The `validate` function may throw an `Error`
or return `undefined` depending on validity of the value supplied to the Module on load.

If an `Error` is thrown, the Server will fail to startup or if already running will prevent [Holocron](https://github.com/americanexpress/holocron) from loading the Module dynamically.
If an `Error` is thrown, the Server will fail to startup or if already running will prevent
[Holocron](https://github.com/americanexpress/holocron) from loading the Module dynamically.

**📘 More Information**
* [`provideStateConfig`](#providestateconfig)
Expand Down
7 changes: 0 additions & 7 deletions docs/api/server/Development-Tools.md

This file was deleted.

63 changes: 34 additions & 29 deletions docs/api/server/Environment-Variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,55 @@ One App can be configured via Environment Variables:
* [`IP_ADDRESS`](#ip_address)
* Running in Production
* [`HOLOCRON_MODULE_MAP_URL`](#holocron_module_map_url) ⚠️
* [`NODE_ENV`](#node_env)
* [`NODE_ENV`](#node_env) ⚠️
* [`ONE_CLIENT_LOCALE_FILENAME`](#one_client_locale_filename)
* [`ONE_CLIENT_REPORTING_URL`](#one_client_reporting_url) ⚠️
* [`ONE_CLIENT_CSP_REPORTING_URL`](#one_client_csp_reporting_url) ⚠️
* [`ONE_CLIENT_ROOT_MODULE_NAME`](#one_client_root_module_name) ⚠️
* [`ONE_CLIENT_CDN_URL`](#one_client_cdn_url) ⚠️
* [`ONE_CONFIG_ENV`](#one_config_env)
* [`ONE_CONFIG_ENV`](#one_config_env) ⚠️
* Running in Development
* [`NODE_ENV`](#node_env)
* [`NODE_ENV`](#node_env) ⚠️
* [`ONE_CLIENT_ROOT_MODULE_NAME`](#one_client_root_module_name) ⚠️
* [`ONE_CONFIG_ENV`](#one_config_env)
* [`ONE_CONFIG_ENV`](#one_config_env) ⚠️
* Server Settings
* [`HOLOCRON_SERVER_MAX_MODULES_RETRY`](#holocron_server_max_modules_retry)
* [`HOLOCRON_SERVER_MAX_SIM_MODULES_FETCH`](#holocron_server_max_sim_modules_fetch)
* [`ONE_ENABLE_POST_TO_MODULE_ROUTES`](#one_enable_post_to_module_routes)
* [`ONE_MAP_POLLING_MAX`](#one_map_polling_max)
* [`ONE_MAP_POLLING_MIN`](#one_map_polling_min)
* [`ONE_REFERRER_POLICY_OVERRIDE`](#one_referrer_policy_override)
* [`ONE_SERVICE_WORKER`](#one_service_worker)

**Alphabetical Contents**
* [`HOLOCRON_MODULE_MAP_URL`](#holocron_module_map_url)
* [`HOLOCRON_SERVER_MAX_MODULES_RETRY`](#holocron_server_max_modules_retry)
* [`HOLOCRON_SERVER_MAX_SIM_MODULES_FETCH`](#holocron_server_max_sim_modules_fetch)
* [`HTTPS_PORT`](#https_port)
* [`HTTPS_PRIVATE_KEY_PASS_FILE_PATH`](#https_private_key_pass_file_path)
* [`HTTPS_PRIVATE_KEY_PATH`](#https_private_key_path)
* [`HTTPS_PUBLIC_CERT_CHAIN_PATH`](#https_public_cert_chain_path)
* [`HTTPS_TRUSTED_CA_PATH`](#https_trusted_ca_path)
* [`HTTP_METRICS_PORT`](#http_metrics_port)
* [`HTTP_ONE_APP_DEV_CDN_PORT`](#http_one_app_dev_cdn_port)
* [`HTTP_ONE_APP_DEV_PROXY_SERVER_PORT`](#http_one_app_dev_proxy_server_port)
* [`HTTP_PORT`](#http_port)
* [`IP_ADDRESS`](#ip_address)
* [`NODE_ENV`](#node_env)
* [`ONE_CLIENT_CDN_URL`](#one_client_cdn_url)
* [`ONE_CLIENT_LOCALE_FILENAME`](#one_client_locale_filename)
* [`ONE_CLIENT_REPORTING_URL`](#one_client_reporting_url)
* [`ONE_CLIENT_ROOT_MODULE_NAME`](#one_client_root_module_name)
* [`ONE_CONFIG_ENV`](#one_config_env)
* [`ONE_ENABLE_POST_TO_MODULE_ROUTES`](#one_enable_post_to_module_routes)
* [`ONE_MAP_POLLING_MAX`](#one_map_polling_max)
* [`ONE_MAP_POLLING_MIN`](#one_map_polling_min)
* [`ONE_REFERRER_POLICY_OVERRIDE`](#one_referrer_policy_override)
* [`ONE_SERVICE_WORKER`](#one_service_worker)
<details>
<summary>Alphabetical Contents</summary>

* [`HOLOCRON_MODULE_MAP_URL`](#holocron_module_map_url) ⚠️
* [`HOLOCRON_SERVER_MAX_MODULES_RETRY`](#holocron_server_max_modules_retry)
* [`HOLOCRON_SERVER_MAX_SIM_MODULES_FETCH`](#holocron_server_max_sim_modules_fetch)
* [`HTTPS_PORT`](#https_port)
* [`HTTPS_PRIVATE_KEY_PASS_FILE_PATH`](#https_private_key_pass_file_path)
* [`HTTPS_PRIVATE_KEY_PATH`](#https_private_key_path)
* [`HTTPS_PUBLIC_CERT_CHAIN_PATH`](#https_public_cert_chain_path)
* [`HTTPS_TRUSTED_CA_PATH`](#https_trusted_ca_path)
* [`HTTP_METRICS_PORT`](#http_metrics_port)
* [`HTTP_ONE_APP_DEV_CDN_PORT`](#http_one_app_dev_cdn_port)
* [`HTTP_ONE_APP_DEV_PROXY_SERVER_PORT`](#http_one_app_dev_proxy_server_port)
* [`HTTP_PORT`](#http_port)
* [`IP_ADDRESS`](#ip_address)
* [`NODE_ENV`](#node_env) ⚠️
* [`ONE_CLIENT_CDN_URL`](#one_client_cdn_url)
* [`ONE_CLIENT_CSP_REPORTING_URL`](#one_client_csp_reporting_url) ⚠️
* [`ONE_CLIENT_LOCALE_FILENAME`](#one_client_locale_filename)
* [`ONE_CLIENT_REPORTING_URL`](#one_client_reporting_url) ⚠️
* [`ONE_CLIENT_ROOT_MODULE_NAME`](#one_client_root_module_name) ⚠️
* [`ONE_CONFIG_ENV`](#one_config_env) ⚠️
* [`ONE_ENABLE_POST_TO_MODULE_ROUTES`](#one_enable_post_to_module_routes)
* [`ONE_MAP_POLLING_MAX`](#one_map_polling_max)
* [`ONE_MAP_POLLING_MIN`](#one_map_polling_min)
* [`ONE_REFERRER_POLICY_OVERRIDE`](#one_referrer_policy_override)
* [`ONE_SERVICE_WORKER`](#one_service_worker)
</details>

> ⚠️ = Required
Expand Down
133 changes: 111 additions & 22 deletions docs/recipes/Mocking-Api-Calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,124 @@

# Mocking your API calls for Local Development

<!-- TODO: expand on this section -->

The `set-middleware` command links your module's custom dev middleware file to One App:
1. Call the API following [making an API Call guide](../../recipes/Making-An-API-Call.md). The API call would be similar to this:

```bash
$ npm run set-middleware ../[module-name]/dev.middleware.js
```
```javascript
const loadModuleData = async ({ store, fetchClient }) => {
store.dispatch(someApiLoadingAction());
const someApiResponse = await fetchClient(store.getState().getIn(['config', 'someApiUrl']));
const data = await someApiResponse.json();
store.dispatch(someApiCompleteAction(data));
};
```

This allows you to use your [Parrot](https://github.com/americanexpress/parrot) mocks when developing your module with One App.
`someApiUrl` is set within the `appConfig` of the module. Check out the [One App configurations guide to learn more](../modules/App-Configuration.md#provideStateConfig).

The `set-dev-endpoints` command links your module's dev endpoints file to One App.
2. Configure the Parrot scenarios. When modules are generated using [One App module generator](https://github.com/americanexpress/one-app-cli/tree/master/packages/generator-one-app-module) a mock folder is created, this contains sample scenarios.

A `dev.endpoints.js` file contains all the information One App needs to configure [one-app-dev-proxy](https://github.com/americanexpress/one-app-dev-proxy)
(our reverse proxy and mocking server that runs during development) and can be used to set remote endpoints
for your Module to use during local development.
> 🐦 [Parrot](https://github.com/americanexpress/parrot) is a set of tools that allow you to create HTTP mocks
> and organize them into scenarios in order to develop your app against different sets of data.

```bash
$ npm run set-dev-endpoints ../[module-name]/dev.endpoints.js
```
```
module
├── README.md
├── mock
| └── scenarios.js
|
├── package.json
└── src
└── index.js
```

A `dev.endpoints.js` file looks like:
Update `mock/scenarios.js` to accommodate all the scenarios that you'd like to mock using Parrot. Refer to [Parrot scenarios](https://github.com/americanexpress/parrot/blob/master/SCENARIOS.md) to learn how you can setup different scenarios.
3. Set up the `dev-middleware.js` and `dev.endpoints.js`.
### `dev-middleware.js`
`dev-middleware.js` allows you to setup a custom middleware configuration. This file is created by default when [One App module generator](https://github.com/americanexpress/one-app-cli/tree/master/packages/generator-one-app-module) is used. Ensure that [`parrot-middleware`](https://github.com/americanexpress/parrot/tree/master/packages/parrot-middleware) is installed.
**Running within One App**
Use the `set-middleware` command to link your module's custom dev middleware file to One App. Navigate to your local One App directory and run the following command:

```bash
npm run set-middleware [path-to-your-module]/dev.middleware.js
```

**Using One App runner**

When using [one-app-runner](https://github.com/americanexpress/one-app-cli/tree/master/packages/one-app-runner), this can be configured within the `package.json` under `"one-amex" -> "runner" -> "parrotMiddleware "`:

```json
"one-amex": {
"runner": {
"parrotMiddleware": "[path-to-your-module]/dev.middleware.js"
}
}
```

`dev-middleware.js` contains the following parrot configuration.

```javascript
const parrot = require('parrot-middleware');
const scenarios = require('./mock/scenarios');
module.exports = (app) => app.use(parrot(scenarios));
```

### `set-dev-endpoints.js`

A `dev.endpoints.js` file contains all the information One App needs to configure [one-app-dev-proxy](https://github.com/americanexpress/one-app-dev-proxy)
(our reverse proxy and mocking server that runs during development) and can be used to set remote endpoints
for your Module to use during local development. Create this file within the root folder of your module.

**Running within One App**

Use the `set-dev-endpoints` command to link your module's dev endpoints file to One App. Navigate to your local One App directory and run the following command:
```bash
npm run set-dev-endpoints [path-to-your-module]/dev.endpoints.js
```
**Using One App runner**
When using [one-app-runner](https://github.com/americanexpress/one-app-cli/tree/master/packages/one-app-runner), this can be setup within the `package.json` as follows:
```json
"one-amex": {
"runner": {
"devEndpoints": "[path-to-your-module]/dev.endpoints.js"
},
}
```
A `dev.endpoints.js` file contains the following:
```js
module.exports = () => ({
someApiUrl: {
devProxyPath: 'api',
destination: 'https://example.com',
},
});
```
4. If using One App you will need to use the `--use-middleware` flag when starting one-app.
```bash
npm start -- --root-module-name=<module-name> --use-middleware
# e.g. npm start -- --root-module-name=my-first-module --use-middleware
```
5. Install the [Parrot Chrome extension](https://chrome.google.com/webstore/detail/parrot-devtools/jckchajdleibnohnphddbiglgpjpbffn) to switch between different scenarios, you can also view the scenarios by visiting [http://localhost:3002/parrot/scenarios](http://localhost:3002/parrot/scenarios)
**📘 More Information**
* [parrot-middleware](https://github.com/americanexpress/one-app-cli/tree/master/packages/one-app-runner#parrot-middleware-optional)
* [dev-endpoints](https://github.com/americanexpress/one-app-cli/tree/master/packages/one-app-runner#dev-endpoints-optional)
* [Loading Data](../api/modules/Loading-Data.md)
```js
module.exports = () => ({
apiUrl: {
devProxyPath: 'api',
destination: 'https://example.com',
},
});
```
[☝️ Return To Top](#mocking-your-api-calls-for-local-development)
4 changes: 2 additions & 2 deletions docs/recipes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

* [Adding Styles](./Adding-Styles.md) 🔨
* [Making an API call](./Making-An-Api-Call.md) 📌
* [Mocking your API calls for Local Development](./Mocking-Api-Calls.md) 🔨
* [Mocking your API calls for Local Development](./Mocking-Api-Calls.md)
* [Routing and Navigation](./Routing-And-Navigation.md)
* [Code Splitting using Holocron](./Code-Splitting-Using-Holocron.md)
* [Internationalizing your Module](./Internationalizing-Your-Module.md) 📌
* [Internationalizing your Module](./Internationalizing-Your-Module.md)
* [Enabling Server Side Rendering](./Enabling-Serverside-Rendering.md) 📌
* [Partial Rendering](./Partial-Rendering.md) 🔨
* [Running An Existing One App Instance Locally](./Running-Existing-App-Locally.md) 🔨
Expand Down
2 changes: 1 addition & 1 deletion one-app-statics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@americanexpress/one-app-statics",
"version": "5.2.1",
"version": "5.2.2",
"description": "One App Static Assets",
"main": "index.js",
"scripts": {
Expand Down
Loading

0 comments on commit 02cd71f

Please sign in to comment.