项目作者: johnfacey

项目描述 :
Salesforce Commerce Cloud NodeJS OCAPI Proxy Router
高级语言: JavaScript
项目地址: git://github.com/johnfacey/ocapi-proxy.git
创建时间: 2018-11-28T19:41:20Z
项目社区:https://github.com/johnfacey/ocapi-proxy

开源协议:Other

下载


Salesforce Commerce Cloud OCAPI Proxy

version version

NPM

This project will serve as a local Node.js based Proxy server that will forward requests to an Salesforce Commerce Cloud OCAPI instance.
This can be used for purposes such as testing 3rd party apps using OCAPI as well as integration for mobile/browser apps.
The configuration of site_id, client_id are configured at the proxy level rather than in the app directly.

Welcome:

Postman Example

Getting Started

Edit the config.json to match the server you are using.
If you are using a service such as https://ngrok.com you may need to add the url to your Business Manager allowed origins.

NOTE: This package only forwards OCAPI requests from one point to another. The main purpose is for routing data around CORS and is typically useful for Mobile Applications. x-dw-client-id as a header attribute must be used instead of client_id as a url parameter.

Updates

Updated UI Interface with Request and Response sections.
Removed Autolaunch of UI.
Cors changes to express have been added.
UI can be compltely disabled in config.json as well as Google Anaylrics by making the value “”
Errors will now return a json format if the SFCC instance can be reached.
This will resolve issues with Postman not getting back a json result and aid in debugging.

Prerequisites

  1. Required:
  2. Node.js
  3. Salesforce Commerce Cloud Sandbox - Configured for OCAPI
  4. Optional:
  5. Postman or another rest API tool.
  6. ngrok - If you need to get a public url to your localhost

Installing

  1. npm install ocapi-proxy

Running

From the command line:

  1. npm start or node ocapi-proxy.js

Example:

  1. npm start ocapi-proxy.js

Postman Example

You will need a config.json (one will be generated on first launch)
To edit the port, domain, etc.. modify the config.json file.
server: your Salesforce Commerce Cloud server (currently all calls are https)
site_id: SFCC Site ID
version: SFCC OCAPI Version
port_ui: Port for browser testing requests.
port: Port that proxy listens for requests.

Example:

  1. {
  2. "server": "yoursandbox.demandware.net",
  3. "site_id": "SiteGenesis",
  4. "version": "v23_2",
  5. "client_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  6. "port": 8080,
  7. "port_ui": 80,
  8. "UA": "UA-XXXX-XXXX", //Optional: Universal Analytics ID
  9. "rate_limit": "", //Optional: 15 minutes default
  10. "rate_max": "", //Optional: number of calls that can be made
  11. "windowMs": limit, // 15 minutes or config file entry
  12. "max": max, // Limit each IP to 100 requests per `window` (here, per 15 minutes)
  13. }

OCAPI Commands

You can send OCAPI commands to your local proxy.
Specify the host to make the call.
Send the endpoint as the callurl header attribute.
All other attributes can be sent similar to a direct OCAPI call.
This ensures that the Proxy communicates with OCAPI as middleware.

Example:

Postman Example

Deployment/Development

This is currently a work in progress. Please report any issues you find.
Latest: Fixes to logging added dates to log files.
Updated contact info for Github and Twitter.

OCAPI Output Modifications

Currently Authorization and ETag headers are returned into the body from the output proxy rather than in the header. These are not needed in 19.X+

Universal Analytics

The Proxy will communicate with Google Universal Analytics if a “UA” attribute is found in the config file. You may leave this attribute blank or remove it from the config. Currently all UA requests are send as a event tag with the url of the Commerce Cloud Instance.

Proxy Testing UI

Postman Example

NEW Proxy UI for testing from a web browser interface. Config attribute “port_ui” added to config.json

File Structure

  1. Within the download you'll find the following directories and files:
  2. |-- Root
  3. |-- .gitignore
  4. |-- .npmignore
  5. |-- build.js
  6. |-- config.json
  7. |-- ecosystem.config.js
  8. |-- libProxy.js
  9. |-- LICENSE.md
  10. |-- ocapi-proxy.js
  11. |-- package-lock.json
  12. |-- package.json
  13. |-- README.md
  14. |-- sample-config.json
  15. |-- SECURITY.md
  16. |-- .vscode
  17. | |-- launch.json
  18. |-- examples
  19. | |-- diagram-middleware.png
  20. | |-- OCAPI-Proxy-Tester.png
  21. | |-- OCAPI-Proxy.postman_collection.json
  22. | |-- pm2-example.png
  23. | |-- postman-example.png
  24. |-- html
  25. | |-- index.html
  26. |-- logs

Logging

The Proxy will generate logs where the current proxy has been executed in the logs directory.

Built With

Authors

  • John Facey II - Lead
    GitHub followers
    Twitter followers
    ko-fi

License

License: MIT

See the LICENSE.md file for details

Acknowledgments