↓ Skip to main content
A mixed-media picture of a worn wooden table. On it stands a small house built from teal wooden blocks, with a roof of two triangles. Beside the house lie three orange blocks in a row.

The User Interface: Carbon Without @maximo

A companion app brings its own user interface. Ours is built with Carbon, the design system that IBM publishes as open source. The page of the skeleton uses three Carbon packages, and no package from the scope @maximo.

MAS 9.2 series companion app user interface

This page is about the browser side of our skeleton. We built it and ran it on a workstation and on our test system, on the MAS 9.2 series.

The page
#

The same page at two widths, side by side. On the left a wide page with the header “MAS Companion App” and three grey tiles: “Signed in to Maximo Application Suite” with the user DEVUSER, “Your rights in Maximo Manage” with a small JSON text, and across the full width “Approved work orders, read as you” with two demo work orders. On the right the page at the width of a phone, with the same three tiles one under the other.
The page of the skeleton at 1280 and at 390 points, with demo data

The page has a header and three tiles on a grid. At the width of a phone the grid puts the tiles one under the other. The page had no horizontal overflow at either width.

It uses ten components of @carbon/react: Header, HeaderName, HeaderGlobalBar, HeaderGlobalAction, Content, Grid, Column, Tile, InlineLoading and CodeSnippet. One icon comes from @carbon/icons-react, and the styles from @carbon/styles.

The packages, and the line we keep
#

    "@carbon/icons-react": "^11.53.0",
    "@carbon/react": "^1.71.0",
    "@carbon/styles": "^1.71.0"

These are the three Carbon packages of the skeleton. They are build packages: the browser gets what the build makes of them. At run time the server has eight packages of its own, none of them from the scope @maximo.

No package from the scope @maximo is a dependency. We checked the package file and the lock file. That scope holds IBM’s own packages. We keep our page on the public side of that line.

The header of our page is Carbon’s Header, with the name of the app and a logout button. We did not rebuild the header of the suite.

What the build weighs
#

The page is bundled with Vite. On our workstation the build took about one second.

FileSizeWith gzip
the style sheet828 kB84 kB
the JavaScript242 kB77 kB
index.html0.5 kB–

One build of the skeleton as it is, with three tiles.

The style sheet is the largest part. The skeleton imports the complete styles of Carbon, with one line: import "@carbon/styles/css/styles.css";.

Relative addresses, for the base path
#

Under path routing the app lives under a path of the suite’s host. The page has to work there and at a host root. Two things take care of it.

The build writes relative addresses. This is the Vite setting file, with base set to ./:

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

// Builds the Carbon React SPA into web/dist, which the Express server serves.
// Dev proxy sends /api and the OIDC routes to the local server on :3001.
export default defineConfig({
  root: __dirname,
  // Relative URLs, so the same build runs at a host root and under a base path.
  base: "./",
  plugins: [react()],
  build: { outDir: "dist", emptyOutDir: true },
  server: {
    port: 5173,
    proxy: {
      "/api": "http://localhost:3001",
      "/login": "http://localhost:3001",
      "/auth": "http://localhost:3001",
      "/logmeout": "http://localhost:3001",
    },
  },
});

And the page calls its API with relative addresses: api/whoami, with no slash in front. The server redirects the base path without a slash at its end to the one with a slash, so that relative addresses start at the right place. We asked for it: the answer was 301.

How settings reach the page
#

The page needs a few facts that only the server knows, such as the base path. The server writes them into index.html when it sends the page. This is the source of index.html:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>MAS Companion App</title>
    <!--MAS_RUNTIME_CONFIG--><!-- server replaces this exact marker with the runtime config script -->
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="./src/main.tsx"></script>
  </body>
</html>

And this is the part of the server that sends it:

// --- the page: gated, with runtime configuration and a nonce injected into index.html ---
root.get("*", checkAuthentication, checkUserAccess, (_req, res) => {
  const indexHtml = path.join(WEB_DIR, "index.html");
  const nonce = crypto.randomBytes(16).toString("base64");
  fs.readFile(indexHtml, "utf8", (err, html) => {
    if (err) return res.status(500).send("Internal Server Error");
    // Replace a marker of our own. A match on </head> also hits a </head> inside an HTML
    // comment, and the page then stays blank.
    const runtime = `<script nonce="${nonce}">window.MAS_APP_CONFIG={routingMode:'${config.routingMode}',masDomain:'${config.domain}',namespace:'${config.namespace}',basePath:'${config.basePath}'};</script>`;
    res.setHeader(
      "Content-Security-Policy",
      `default-src 'self'; script-src 'self' 'nonce-${nonce}'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'`,
    );
    res.send(html.replace("<!--MAS_RUNTIME_CONFIG-->", runtime));
  });
});

The server replaces one marker with a small script. The script carries a nonce, and the same nonce is in the Content-Security-Policy of the answer. A script without that nonce does not run: our test tool tried to inject one on the running app, and the browser refused it.

The trap with the closing head tag
#

The marker is there for a reason. The obvious way is to put the script in front of </head>. That works until some comment in the page mentions </head>.

We tested it on the built page. We added one comment that mentions the closing head tag, and ran both replacements:

Replacement onWhere the script landed
the first </head>inside the comment
the markerin the head, as intended

A script inside a comment never runs, and the settings in it never reach the page.

What we take from it
#

  • Build the page from Carbon’s public packages. Ours has three of them and none from the scope @maximo.
  • Write relative addresses. Our build ran under a base path with them.
  • Inject settings at a marker of your own. A replacement on the closing head tag put our script into a comment that mentions that tag.
  • Give the injected script a nonce. The policy of our page refused a script without it.

What to read next#

From Skeleton to a Running App runs this page on a workstation and on the cluster. OSLC From a Companion App is where the third tile gets its data. There Are Three Ways to Build for Maximo Application Suite compares a page of your own with the components of the framework.