Skip to content

kapture

Capture Kano Snapshots as a Service

Overview

Capture App Snapshots as a Service

kapture is a lightweight service that let you take screenshots.

kapture relies on Puppeteer and Express

Installation

Install with your preferred package manager:

bash
pnpm add @kalisio/service-kapture
bash
npm install @kalisio/service-kapture
bash
yarn add @kalisio/service-kapture

API

capture (POST)

Request a capture with the following query parameters.

The body of the request must conform a JSON object with the following properties:

PropertyDescriptionDefaults`
layersspecifies the layers to display[]
timespecifies the time to display-
bboxspecifies the bounding box of the zone to display-
pathspecifies the frontend URL path to the activity/#/home/map for Kano
sizespecifies the capture size{ "width": 1024, "height": 768 }
delayspecified the waiting delay before capturing the screenshot (in milliseconds)1000
networkIdleTimeoutspecified the maximum time to wait for network idle capturing the screenshot (in milliseconds)90000
typeDeclares the input data type-
contentRaw content for generic imports-
parametersAdditional query parameters to be sent to the target activity-
layoutoverrides application layout configuration, will do nothing if emptypanes: { left: { opener: false, visible: false }, ... }, fab: { visible: false }

The layers property must conform the following JSON schema:

json
"layers": {
  "type" : "array",
  "items": {
    "type": "string"
  }
}

The items must conform the kano formalism, i.e. Layers.MY_LAYER. In addition and for backward compatibility, you can specify the layer name using kebab case: layers-my-layer, with or without the layers- prefix.

The path property must conform the following JSON schema:

json
"path": {
  "type": "string",
  "default": ""
}

The size property must conform the following JSON schema:

json
"size": {
  "type": "object",
  "properties": {
    "width": {
      "type": "integer",
      "default": 1024
    },
    "height": {
      "type": "integer",
      "default": 768
    }
}

The delay property must conform the following JSON schema:

json
"delay": {
  "type": "number",
  "default": "2000"
}

When type and content are provided, they allow rendering the data as an overlay.

  • type property declares the input data format (e.g. kml, geojson, etc.)
  • content contains the raw data as a string

Example:

json
{
  "type": "kml",
  "content": "<kml>...</kml>"
}

In addition the body can conform a GeoJSON object. The described features will be rendered as an overlay.

Here is a complete example:

json
{
  "layers": ["Layers.IMAGERY"],
  "type": "FeatureCollection",
  "features": [
    { 
      "type": "Feature", 
      "geometry": { 
        "type": "Point", 
        "coordinates": [3, 42.5]
      },
      "properties": { "fill-color": "#AAAAAA" } 
    },
    { 
      "type": "Feature", 
      "geometry": { 
        "type": "LineString", 
        "coordinates": [ [3, 42], [4, 43], [5,42], [6, 43]] 
      },
      "properties": { "fill-color": "#AAAAAA" } 
    },
    { 
      "type": "Feature", 
      "geometry": { 
        "type": "Polygon", 
        "coordinates": [ [ [0, 42], [1, 42], [1, 43], [0, 43], [0, 42] ] ] 
      }, 
      "properties": { "fill-color": "#AAAAAA" } 
    }
  ]
}

And the response looks like:

response

healthcheck (GET)

Check for the health of the service. It answers { "isRunning": true } as soon as the server accepts connections — it reports neither a name nor a version, unlike the other services of the ekosystem.

API reference

The full request/response schema — every body property, the response codes and the error payloads — is documented on the API reference page. That spec declares no server, so pick your own instance URL in the server selector before sending a request from that page.

Configuring

Here are the environment variables you can use to customize the service:

VariableDescriptionDefaults
APP_NAMEThe app name-
APP_URLThe app url-
APP_JWTThe app token to get connected*
BODY_LIMITThe size limit of the request body100kb
PORTThe port to be used when exposing the service3000
DELAYThe waiting delay before capturing the screen (in milliseconds)2000
PAGE_SETUP_DELAYThe waiting delay after navigation, letting the activity set itself up (in milliseconds)2000
UPLOAD_FILE_DELAYThe waiting delay after uploading the imported data (in milliseconds)2000
NETWORK_IDLE_TIMEOUTMaximum time to wait for the network idle (in milliseconds)100000
DEBUGThe namespaces to enable debug output. Set it to kapture:* to enable full debug output.

Building

Manual build

You can build the image with the following command:

bash
docker build -t <your-image-name> .

Automatic build using Travis CI

This project is configured to use Travis to build and push the image on the Kalisio's Docker Hub. The built image is tagged using the version property in the package.json file.

To enable Travis to do the job, you must define the following variable in the corresponding Travis project:

VariableDescription
DOCKER_USERyour username
DOCKER_PASSWORDyour password

Deploying

This image is designed to be deployed using the Kargo project.

Check out the compose file to have an overview on how the container is deployed.

Testing

To test the service you need to set the following environment variables:

VariableDescriptionDefaults
KAPTURE_URLThe Kapture url.http://localhost:3000
KAPTURE_JWTThe Kapture bearen token to pass a gateway if needed. It is set using Auhtorization header.-

To run the tests, use the subcommand test:

bash
yarn test