GraphQL / Graphiql implementation for Oracle Commerce Cloud
This application makes it easy to create and deploy Express GraphQL Server Side Extensions in Oracle Commerce Cloud
Add white listed Card Provider endpoints via OCC API to allow CORS support
{
"properties": {
"allowedOriginMethods": {
"https://{your origin}": "POST",
"https://{your origin}": "POST"
}
}
}
For access to external resources from SSE, copy all X509 PEM Certificates(.pem | .crt) files to the following folder
/ssl
- you can use chrome or firefox to export these directly from the browser
1.Rename config.rename.json to config.json and update the configuration values
{
"occDeployServer": "{OCC ADMIN URL}"
}
2.Update the SSE_NAME and ROUTE_BASE properties in constants.js
SSE_NAME: '{NAME}',
...
ROUTE_BASE: '/v1/{NAME',
3.Update package json package:zip script // todo: make this dynamic
"package:zip": "bestzip {NAME}-sse.zip ./*",
Install all dependencies required by module
$ npm i
To run tests: Running tests allows you to test the static and live json schema without having to use postman. The test state will only ever run when the sse is executed locally. Files located in /tests
$ TOKEN={API_TOKEN} npm run test
1 . Packages and deploys to your OCC instance. Host and api key must be configured in config.js and constants.js
$ TOKEN={API_TOKEN} npm run deploy
$ TOKEN={API_TOKEN} npm run start-dev
Starts up a local server to test for remote access by other clients. Local Development Routes
GET http://localhost:11372/v1/h{SSE_NAME}/version
Open the SSE specific url in the browser {OCC Instance}/ccstorex/custom/v1/{SSE_NAME}/version
// Response:
{
"version": "starter version: 1",
"node_version": "v8.11.1"
}
Use occ-route-tester to test the endpoints in real-time in the occ preview-admin or storefront.
//example for occ-sse-tester
method: POST
path: starter/serviceexternal/getPlanet
JSON: {"planetId":"1"}
$ npm run token
Please add the following to the header requests:
// Insecure Endpoint
headers:{
'env': 'preview', //Boolean indicating mode ex: [ 'preview' | 'storefront' ]
'hc-page': widget.pageContext().page.name, // name of the page requesting resource ex: ['home']
'Content-Type': 'application/json' // Content Type of the payload
}
// Secure Endpoint
// ...same as above but add users authenticated occ token
'Authorization': 'Bearer ' + ccRestClient.tokenSecret
// Example request from JS using Jquery Ajax
$.ajax({
method: 'POST',
dataType: 'json',
url: '/ccstorex/custom/v1/{SSE_NAME}/{YOUR_ENDPOINT}',
withCredentials: true,
data: JSON.stringify({somePayload:'some payloadd'}),
headers: {
'Authorization': 'Bearer ' + ccRestClient.tokenSecret,
'env': 'preview'
'hc-page': widget.pageContext().page.name,
'Content-Type': 'application/json'
}
})
.done(function (res) {})
.fail(function (err) {});
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.