Widget Development Kit

If you want to develop a widget in your environment, you must enable SevOne Data Insight's WDK module.

This module is a collection of docker images that contain the WDK documentation along with the private npm registry to install insight-wdk-cli on your local machine.

When you enable WDK, SevOne Data Insight exposes two new endpoints.

Endpoint Description
https://sdi.customer.com/registry The private npm registry.
https://sdi.customer.com/docs Documentation and HOWTOs on widget development.
Note: widget.son file
widget.json file file contains the widget metadata. It is placed in the root directory of your widget.
  • Required fields
    • name
    • version
    • title
    • runtime
  • Optional Fields
    • description
    • tags
    • exportTypes
    • exportMimeTypes
    • producedFacets
    • consumedFacets

For details on the required and optional fields, please refer to section widget.json.

Enable WDK Module

Enable WDK to expose a private registry and related documentation.

  1. Using a text editor of your choice, edit /opt/SevOne/chartconfs/di_custom.yaml file to set the following environment variable and then, save it.
    Important: If /opt/SevOne/chartconfs/di_custom.yaml file does not exist, please create one and add the following to it.
    wdk:
      enabled: true
  2. Apply the change made to /opt/SevOne/chartconfs/di_custom.yaml file.
    $ sevone-cli playbook up --tags apps

Configure your Development Environment

On your local machine, you must configure the following before installing insight-wdk-cli.

  1. Install Node.js if you have not done so already. The recommended version is v18.x.
  2. Configure npm to use the private registry for any packages under the @sevone namespace.
    $ npm config set @sevone:registry https://sdi.customer.com/registry
    
    $ npm config set strict-ssl false

Install insight-wdk-cli

On your local machine, you can use npm to install @sevone/insight-wdk-cli.

$ npm cache clean --force
 
$ npm install @sevone/insight-wdk-cli -g

Migrate to WDK v3.x

Several WDK APIs were deprecated with the release of SevOne Data Insight 3.0.x but were kept for backward compatibility.

As of insight-wdk@2.3.0, released with SevOne Data Insight 3.12.x, these APIs will be disabled by default.

In an upcoming version, they will be removed completely. To ensure your custom widgets continue to work, these APIs must be replaced with their updated equivalent.

For a detailed migration guide, please refer to /docs/insight-wdk/v3-migration endpoint on your SevOne Data Insight instance.

https://sdi.customer.com/docs/insight-wdk/v3-migration

Enable WDK v2.x Compatibility Mode

In case there are custom widgets relying on deprecated APIs, a compatibility mode can be enabled as a temporary workaround.

Warning: This mode is a temporary stopgap and should not be relied on as a long term solution.
It will be removed in an upcoming SevOne Data Insight version. To ensure custom widgets continue working, please make sure you update them as described in the migration guide in the WDK docs.
  1. Using a text editor of your choice, edit /opt/SevOne/chartconfs/di_custom.yaml file to set the following environment variable and then, save it.
    Important: If /opt/SevOne/chartconfs/di_custom.yaml file does not exist, please create one and add the following to it.
    ui:
      env:
        WDK2_COMPATIBILITY: true
  2. Apply the change made to /opt/SevOne/chartconfs/di_custom.yaml file.
    $ sevone-cli playbook up --tags apps

widget.json

widget.json contains the widget's metadata and is placed in the root directory of your widget.

Required Fields

Field 'name'

  • Type: string
  • Description: The name field is a unique identifier for the widget. Here are the rules.
    • name field must be unique
    • name field cannot start with a dot or an underscore
    • uppercase letters are not allowed
    • the name ends up being part of a URL, an argument on the command line, and a folder name. Name cannot contain any non-URL-safe characters.

Example: widget.json, field 'name'

{
  "name": "my-widget"
}

Field 'version'

  • Type: string
  • Description: This contains the widget's version and it must be parseable by node-semver. Changes to the widget come along with the changes to the version when published.

Example: widget.json, field 'version'

{
  "version": "3.5.0"
}

Field 'title'

  • Type: string
  • Description: the title is a user-friendly display name for the widget.

Example: widget.json, field 'title'

{
  "title": "My Widget"
}

Field 'runtime'

  • Type: string
  • Description: runtime represents which version of WDK is being used to develop against. This field is automatically generated and you will not need to modify this field.

Example: widget.json, field 'runtime'

{
  "runtime": "3.0.0"
}

Optional Fields

Field 'description'

  • Type: string
  • Description: The description field contains the description of the widget. It helps user to discover the widget.

Example: widget.json, field 'description'

{
  "description": "Historical temperature data for a city."
}

Field 'tags'

  • Type: Array<string>
  • Description: tags is a set of keywords to describe the widget. It is useful for widget discovery.

Example: widget.json, field 'tags'

{
  "tags": [ "weather", "location", "time series" ]
}

Type

{
  [mimeType: string]: Array<ExportTypeConfigType>
}

type ExportTypeConfigType = {
  value: string,
  label: string
};
  • Description: An object which maps from MIME type keys to an array of export types for each MIME type. This field was introduced in SevOne Data Insight 3.12 or insight-widget-runtime 1.3.0-beta.12. To support older versions, you do not need to also pass exportMimeTypes . However, please refer to the note about including a fallback in the widget's exportData function.

Example: widget.json, field 'exportTypes'

{
  "exportTypes": {
    "text/csv": [
      {
        "value": "AS_VISUALIZED",
        "label": "As Visualized"
      },
      {
        "value": "TIME_SERIES",
        "label": "Time Series"
      },
      {
        "value": "SUMMARY",
        "label": "Summary"
      }
    ],
    "application/json": [
      {
        "value": "AS_VISUALIZED",
        "label": "As Visualized"
      },
      {
        "value": "RAW_DATA",
        "label": "Raw Data"
      }
    ]
  }
}

For simpler use-cases where only one export type is needed for each MIME type, you may use field exportMimeTypes.


Field 'exportMimeTypes'

  • Type: Array<string>
  • Description: This is a set of MIME types representing the formats the widget can export data as.

Example: widget.json, field 'exportMimeTypes'

{
  "exportMimeTypes": [ "text/csv", "application/json" ]
}
Important: Field exportTypes takes precedence over field exportMimeTypes if both fields are passed. Field exportMimeTypes is still supported by itself for simpler use-cases where multiple export types per MIME type are not needed.

Field 'producedFacets'

  • Type: Array<FacetSchema>
  • Description: This is a set of facet schemas the widget may broadcast.

Example: widget.json, field 'producedFacets'

{
  "producedFacets": [
    {
      "$id": "my-location",
      "type": "object",
      "properties": {
        "city": {
          "type": "string"
        },
        "state": {
          "type": "string"
        }
      },
      "required": [ "city", "state" ]
    }
  ]
}

Field 'consumedFacets'

  • Type: Array<FacetSchema>
  • Description: This is a set of facet schemas the widget is capable of handling and processing internally into the configuration.

Example: widget.json, field 'consumedFacets'

{
  "consumedFacets": [
    {
      "$id": "my-location",
      "type": "object",
      "properties": {
        "city": {
          "type": "string"
        },
        "state": {
          "type": "string"
        }
      },
      "required": [ "city", "state" ]
    }
  ]
}

Important: Function exportData()

type ExportTypeConfigType = {
  value: string,
  label: string
};

(
  configuration: Config,
  data: Data,
  mimeType: string,
  exportTypeConfig?: ExportTypeConfigType
) => Blob | Promise null

A widget can be asked to export its data as any valid MIME type has registered in its widget.json file. This data must be represented as a Blob. If null is returned, no further action will be taken.

The exportTypeConfig argument includes further type information for widgets that can export multiple export types of the same mime type. This argument will only be available if the widget.json file uses https://staging.di.sevone.dev/docs/insight-wdk/api/widget-json#exporttypes rather than https://staging.di.sevone.dev/docs/insight-wdk/api/widget-json#exportmimetypes. This is available in insight-widget-runtime version 1.3.0-beta.12 or later, which is shipped with SevOne Data Insight 3.12 or later.

To support older versions of the runtime or SevOne Data Insight, this argument should always be considered optional, and the export function should include a default fallback in case mimeType is passed, but exportTypeConfig is not.

Important: Mime Types
Please refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_typesfor the MIME types (IANA media types) available.

Important: Facet Schemas
A facet schema is simply a valid JSON schema with a required $id field.

{
  "$id": "my-timespan",
  "type": "object",
  "properties": {
    "startTime": {
      "type": "number",
      "description": "Start time."
    },
    "endTime": {
      "type": "number",
      "description": "End time."
    },
    "timezone": {
      "type": "string"
    }
  },
  "required": [ "startTime", "endTime" ]
}