JavaScript Adapter

With the JavaScript Adapter, you can integrate plain JavaScript services to applications in Quantum Fabric.

You can upload custom JavaScript files to Quantum Fabric. Using JavaScript adapters, you can easily create server-side code and make it available as operations. The JavaScript file must contain functions that a user wants to be made available as operations, along with other supporting functions. You can also add preprocessor and postprocessor to the operations defined. For more details on the structure for JavaScript function definitions, refer to the Limitations section.

For more details about the sample JavaScript code, refer to JavaScript Sample Code for Preprocessor and Postprocessor.

Based on the JDK version supported by Quantum Fabric Installer, the JavaScript adapter uses the following JavaScript engines:

  • If the Java version is 1.7 or 1.8, then the adapter uses Nashorn JavaScript engine
  • If the Java version is below 1.7 , then the adapter uses Rhino JavaScript engine

Configure JavaScript Endpoint Adapter

To configure JavaScript service in the Integration Service Definition tab, follow these steps:

  1. In the Name field, provide a unique name for your service.
  2. From the Service Type list, select JavaScript.
  3. Provide the following details in the JavaScript service definition:
  4. Field Description
    Specify JavaScript libraries From the Specify the Javascript libraries section, select a .JS file, or click Upload to select the .JS file from your local machine. The console adds your JS file to the console. The system displays the added JS file's name under the Specify the Javascript libraries section.

    The system allows you to upload more than one JS file at Specify the Javascript libraries.

    Once uploaded, JavaScript files are available across Quantum Fabric console. They cannot be deleted, only unlinked. You can unlink uploaded .JS files by clicking the Unlink icon.


  5. NOTE: All the fields in the Advanced tab are optional.

  6. In the Description field, provide a suitable description for the service.

  7. Click Save to save your service definition.

Create Operations for JavaScript

The Operation List tab appears when you click Add Operation in the Service Definition page.

NOTE: Click Operations List tab > Configure Operation. The Configured Operations list appears.

  1. Click SAVE & ADD OPERATION in your service definition page to save your service definition and display the NewOperation tab for adding operations.
                        OR
    Click Add Operation to add a new operation or from the tree in the left pane, click Add > Add New Operation.
    1. Under Operations List tab, in the JS Library drop-down list, select the required .JS file. For example, Sample.js. This will populate the Function drop-down list.
    2. From the Function drop-down list, select the required functions. Each function equates to an operation.
    3. Click ADD OPERATION to create operations with the selected functions.
      The new operations are created and listed under the Configured Operations.

      Operation names are auto-generated in the format : <Name-of-the-JS-file>_<function-name>. For example, sample_addTwoNumbers

  2. To edit an operation, either click on the operation name or click Edit from the Settings.
  3. In the Operation Modal tab, provide the following details to configure an operation:|

    Field Description
    Name It is prepopulated with the operation name. You can change the name if required.
    Operation Security Level

    It specifies how a client must authenticate to invoke this operation.

    Description Provide a suitable description of your operation.
  4. NOTE: All options in the Advanced section are optional.

Configure Request Operation for JavaScript

Integration services accept only form-url-encoded inputs for all the input parameters provided in the service input parameters (request input).

You can perform the following actions in Request Input tab:

  1. Click Add Parameter to add an entry (if the entries for input and the output tabs does not exist).
  2. To make duplicate entries, select the check box for the entry, click Copy and Paste.
  3. To delete an entry, select the check box for an entry and click Delete .
  4. To configure the request input tab, provide the following details:
  5. Field Description
    Name It Contains a Unique Identifier. Change the name if required.
    Test Value Enter a value. A test value is used for testing the service.
    Default Value Enter the value, if required. The default value will be used if the test value is empty.
    Value

    Select one of the following options. It is set to Request by default.

    • Request indicates that the value must be retrieved from the HTTP request received from the mobile device.
    • Session indicates that the value must be retrieved from the HTTP session stored on Quantum Fabric.
    • Identity:Selecting this option allows you to send values from identity session as request inputs. Use <Identity Provider><”Profile”/”Security”><Name of the Parameter> notation to send identity session values.
      • <Identity Provider> - Name of the identity provider from which the value must be extracted.

      • <Parameter> is the key whose value must be passed along with the service request.

      NOTE: For more information on Externalizing Identity Services, refer to Replace the Identity Service references in a Fabric app.

    Data Type
    Encode

    Select the check box to enable encoding of an input parameter. For example, the name New York Times would be encoded as New%20York%20Times when the encoding is set to True. The encoding must also adhere to the HTML URL encoding standards.

    Description Provide a suitable description.
  6. To validate the operation details, click Save and Test. For more details, refer to Test a Service Operation.

Configure Response Operation for JavaScript

  1. Click the Response Output tab, and enter the values for required fields such as name, scope, data type, collection ID, record ID, format and format value.

    NOTE: If you define parameters inside a record as the session, the session scope will not get reflected for the parameters.

    In JavaScript service, the response (output) from a back end is not parsed based on the response values. The complete response from the back end is sent to the client device.

    NOTE: By default, the opStatus and httpStatusCode values for JavaScript services are added as 0 and 200.

  2. To validate the operation details, click Save and Test. For more details, refer to Test a Service Operation.

  3. Click SAVE OPERATION to save the operation. The system updates the operation definition.

    If you click Cancel, the Operation Modal tab closes without saving any information.

    NOTE: To add more operations for your JavaScript service, repeat Step 3 through Step 4.

    NOTE: You can view the service in the Data Panel feature of Quantum Visualizer. By using the Data Panel, you can link back-end data services to your application UI elements seamlessly with low-code to no code. For more information on Data Panel, click here.

Limitations for JavaScript Engine - JavaScript Adapter

  • The JavaScript Engine does not support some common JavaScript libraries and global JavaScript functions such as jQuery, setTimeout, setInterval or XMLHttpRequest. However, it provides an alternate mechanism to perform the same operation. You can invoke the required functionality using Java for such cases. For example, consider the XMLHttpRequest API. Since Nashorn does not support this API, you will need to use Java to perform the required operations. You can use URLConnection java class or HttpClient API to achieve the same goal.

  • The JavaScript Engine only supports ECMAScript-262 Edition 5.1. It does not support any features of Edition 6 or any nonstandard features provided by other JavaScript implementations.
  • The JavaScript Engine does not include a browser plug-in API.
  • The JavaScript Engine does not include support for DOM/CSS or any related libraries (such as jQuery, Prototype, or Dojo)
  • The JavaScript Engine does not include direct debugging support.
  • The JavaScript Engine does not support event loop or a task queue.

Limitations for Supported Function Formats - JavaScript Adapter

  • Supported formats of the JavaScript function definition as follows:
     function abc() { … }