/occ-graphql

GraphQL implementation for Oracle Commerce Cloud

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

occ-graphql

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

version 1.1.0

CORS

Add white listed Card Provider endpoints via OCC API to allow CORS support

{
    "properties": {
        "allowedOriginMethods": {
            "https://{your origin}": "POST",
            "https://{your origin}": "POST"
         }
    }
}

Routes

Sample Routes

Secure endpoints

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

Configuration config.json

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 ./*",

Installation

Install all dependencies required by module

$ npm i

Tests

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

Deployment Steps

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

* The deploy will not complete unless both the tests and linter pass.

Local dev server

$ 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

Validate SSE is runnning

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"}

Generate an Auth token for postman

$ npm run token

Requesting SSE fom client side

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) {});




Disclaimer of Warranty.

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.