npm

Need private packages and team management tools?Check out npm Orgs. »

webcenterjs

1.0.13 • Public • Published

WebCenterJS

A Framework independent javascript library that makes working with Oracle WebCenter (11g & 12c) REST API a breeze.It cannot get any simpler than this

Library encapsulates all the logic necessary for

Works with framework of your choice. KnockoutJS, Angular, React, React Native, NodeJS, jQuery just to name a few.

Features

  • Built with TypeScript.
  • Distributed as NPM & Bower packages.
  • CommonJS & Bundled distributions.
  • Full Intellisense in Visual Code, WebStorm , Sublime Text etc.
  • Type Definitions.
  • Automatically handles utoken & Link Model parsing.
  • Promise based.

Installation

NPM

CommonJS distribution that integrates well with Modern frameworks like Angular, React, Aurelia, VueJS, etc.

> npm install webcenterjs --save

Bower

Bundled distribution that integrates well with jQuery, KnockoutJS or plain old javascript.

> bower install webcenterjs --save

Usage

TypeScript / ES6

Install webcenterjs NPM module as shown above and use the following snippet.

// import module
import WebCenter from "webcenterjs";
import {WallMessageItem} from "webcenterjs"; // Required only for TypeScript, for type definitions.
 
/**
* Assuming Oracle WebCeter Installation is available at 
* http(s)://wc-host-name:8888/. The following context roots will be available
* OOTB
* WebCenter : http(s)://wc-host-name:8888/webcenter
* Content : http(s)://wc-host-name:16200/cs
* REST API : http(s)://wc-host-name:8888/rest
*/
 
/**
* Set REST Base URL. 
* Automatically defaults to [window.location.protocol, "//", window.location.host, "/rest"].join("") when running on browser. 
* Defaults to "/rest" when running on NodeJS, React Native.
* It is recommended to set the REST Base URL
*/
WebCenter.Config.setRestBaseUrl("http(s)://wc-host-name:8888/rest");
 
/**OPTIONAL : Optionally set WC & CS Base URLs as shown below
* The WC & CS URLs will come into play only for Basic Authentication and not for SSO or OIT.
*/
WebCenter.Config.setWcBaseUrl("http(s)://wc-host-name:8888/webcenter");
WebCenter.Config.setCsBaseUrl("http(s)://wc-host-name:16200/cs");
 
/**OPTIONAL : Optionally set Usename & Password
* 1. When username & password are provided, Basic Authentication is used.
* 2. WebCenter.Auth.setOIT("<OIT_TOKEN>") can be used to work with OIT token. 
* 3. When neither is provided, SSO is assumed.
*/
WebCenter.Auth.setUserName(username);
WebCenter.Auth.setPassword(password);
 
 
WebCenter.Wall.postMessage("Awesome Message from WebcenterJS !!!!").then((messageItem: WallMessageItem) => {
    console.log("------ Congrats on your Post ---------", messageItem.id);
}, (error: any) => {
    console.error(error);
});

In the above example, when postMessage is done, the following happens

  1. GET request to http(s)://wc-host-name:8888/rest/resourceIndex with Basic Auth.
  2. Extract uToken.
  3. Parse Link Model.
  4. postMessage using the uToken

Explicit login can be performed using the following snippet, if needed

WebCenter.Auth.login().then((resourceIndex: ResourceIndex) => {
    console.log(resourceIndex);
    // ... Do something elese
    // for ex.
    
    /**
    WebCenter.Wall.postMessage("Awesome Message from WebcenterJS !!!!").then((messageItem: WallMessageItem) => {
        console.log("------ Congrats on your Post ---------", messageItem.id);
    }, (error: any) => {
        console.error(error);
    });
    */
 
},(error:Error) => {
    console.error(error);
});

ES5 (Plain Old JavaScript in Browser)

<script src="bower_components/webcenterjs/dist/webcenter.min.js"></script>

With the above script a global object WebCenter is registered on the window.

/**
* Assuming Oracle WebCeter Installation is available at 
* http(s)://wc-host-name:8888/. The following context roots will be available
* OOTB
* WebCenter : http(s)://wc-host-name:8888/webcenter
* Content : http(s)://wc-host-name:16200/cs
* REST API : http(s)://wc-host-name:8888/rest
*/
 
/**
* Set REST Base URL. 
* Automatically defaults to [window.location.protocol, "//", window.location.host, "/rest"].join("") when running on browser. 
* Defaults to "/rest" when running on NodeJS, React Native.
* It is recommended to set the REST Base URL
*/
WebCenter.Config.setRestBaseUrl("http(s)://wc-host-name:8888/rest");
 
/**OPTIONAL : Optionally set WC & CS Base URLs as shown below
* The WC & CS URLs will come into play only for Basic Authentication and not for SSO or OIT.
*/
WebCenter.Config.setWcBaseUrl("http(s)://wc-host-name:8888/webcenter");
WebCenter.Config.setCsBaseUrl("http(s)://wc-host-name:16200/cs");
 
/**OPTIONAL : Optionally set Usename & Password
* 1. When username & password are provided, Basic Authentication is used.
* 2. WebCenter.Auth.setOIT("<OIT_TOKEN>") can be used to work with OIT token. 
* 3. When neither is provided, SSO is assumed.
*/
WebCenter.Auth.setUserName(username);
WebCenter.Auth.setPassword(password);
 
WebCenter.Wall.postMessage("Awesome Message from WebcenterJS !!!!").then(function(messageItem){
    console.log("------ Congrats on your Post ---------", messageItem.id);
}, function(error){
    console.error(error);
});

Explicit login can be performed using the following snippet, if needed

WebCenter.Auth.login().then(function(resourceIndex){
    console.log(resourceIndex);
    // ... Do something elese
    // for ex.
    
    /**
    WebCenter.Wall.postMessage("Awesome Message from WebcenterJS !!!!").then(function(messageItem){
        console.log("------ Congrats on your Post ---------", messageItem.id);
    }, function(error) => {
        console.error(error);
    });
    */
 
},function(error){
    console.error(error);
});

Prerequisites

Make sure Oracle WebCenter Portal is configured as per instructions at Configuring REST APIs

Link Model (HATEOAS)

Oracle WebCenter REST API responses confirm to HATEOAS Standard.

WebCenterJS automatically parses the link model and enriches the response as shown below Chrome Console

In the above screenshot, note that the response wcResIdx is enriched and contains several methods that can be called direclty (getInvitations in this case).

install

npm i webcenterjs

Downloadsweekly downloads

15

version

1.0.13

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability