The abstraction layer between the public api and integration-hub that accounts for data mapping and traffic shuffling
npm install public-api-proxynpm start script will run the compiled code directly, while invoking nodemon app.js will use the babel require hook for simplicity as you don't have to worry about making sure the build step is being ran.hapi-router will load routes dynamically. Routes should be separated by the action being performed on the resource.create.js file in the taxes/routes directory.All handler code should typically remain in the handler function of the route object. If extensive logic is needed and would otherwise make the route object hard to read/change, move the handler function into a controller.js file.
Schemas, unless trivial, should live in a schemas folder to keep route definitions as minimal and clean as possible.
You should also take note that any route withe the api tag will return a wrapped response on a successful transaction consisting of the url that was called and the response in a data property. Errors will be sent to the user without being wrapped.
1) Specify the following fields (at a minimum) in the route definition:
``js`
{
method: {String|Array
path: String,
config: {
description: ''
tags: ['api', ...], // Tags should also include the primary resource (e.g. hub-taxes, mkt-units, etc)
// Note: the primary resource tag must also be added to the ui plugin (see step 2)
validate: {
/*
* Any validation for the route, query, or payload parameter/properties
*/
}
response: {
schema: Joi.object().description('')
}
},
handler: // Any function that takes the req[uest] and the reply
}
2) Add the unique primary resource route tag to the defaultTags section of the desired api hapi-swaggered-ui plugin config:
* For Integration Hub API routes, add to: server/plugins/hapiSwaggeredUiHubApi.jsserver/plugins/hapiSwaggeredUiMktApi.js
* For Inventory Marketplace API routes, add to:
`js`
{
register: require('@leisurelink/hapi-swaggered-ui'),
options: {
...
defaultTags: [
'hub-pmcs',
'hub-promotions',
//Add new primary resource route tags here to include in documentation
]
...
}
}
collections in plugins/index.js and then run npm run build. Use this step if the plugin requires no extra configuration
2. Add a new file that has the same name as the plugin (with camel casing), add any necessary options or configuration, and then follow step 1 using the file you just createdIndex files
With trying to keep confusion at a minimum, index.js files only responsibility should be to gather all other files in the directory and export them back out. Think of index files as a manifest for the directory.
If a directory contains only one file and only ever contains one file, remove the directory and just name the js file the same as the directory.
This helps avoid the scenario when developing of having 10 different index.js files open at once and cycling through all of them to find the one you want
A convenience function has been implemented in mod.js that takes a directory, usually __dirname, requires all the .js or .json files in that directory (excluding index.js, and returns an object keyed by the file name. Index files should be as simple as
`js
import load from 'mod.js'export default load(__dirname);
`Tests
Unit Tests should be separated by the same structure as the file they're testing, so if testing taxes routes, the test directory would be tests/supply/v2/pmcs/taxes/{filename}.tests.js
The server object is a global defined in tests/server.tests.js` to avoid the problem of walking the directory structure and requiring the server in every test file.