Skip to main content

Single Page Requester

The Single Page Requester is a tool that allows you to request metrics from a project without having to crawl the entire site.

How to use the Single Page Requester

oreo-api-sdk package include a Single Page Requester client that can be used to request metrics from a url.

install the package
npm install @deepcrawl/oreo-api-sdk

For authentication you will need to create a user key and set it as environment variables.

OREO_API_SDK_USER_KEY_ID=<user_key_id>
OREO_API_SDK_USER_KEY_SECRET=<user_key_secret>
request metrics from a url
import { SinglePageRequesterClient } from "@deepcrawl/oreo-api-sdk";

jest.setTimeout(60000);

const seoProjectId = 123456;
const a11yProjectId = 123457;
const siteSpeedProjectId = 123458;

let client: SinglePageRequesterClient;

beforeAll(async () => {
client = await SinglePageRequesterClient.create();
});

describe("request{ProjectType}Project", () => {
it("returns SEO metrics", async () => {
const url = "https://www.lumar.io/";
const { metrics } = await client.requestSEOProject({
projectId: seoProjectId,
url,
});
expect(metrics?.url).toBe(url);
expect(metrics?.pageTitle).toBe("Lumar | The #1 Technical SEO Platform");
});

it("returns Accessibility metrics", async () => {
const url = "https://www.lumar.io/";
const { metrics, accessibilityIssues } = await client.requestAccessibilityProject({
projectId: a11yProjectId,
url,
});
expect(metrics?.url).toBe(url);
expect(accessibilityIssues?.length).toBe(64);
});

it("returns Site Speed metrics", async () => {
const url = "https://www.lumar.io/";
const { metrics, siteSpeedAudits, siteSpeedAuditItems } = await client.requestSiteSpeedProject({
projectId: siteSpeedProjectId,
url,
});
expect(metrics?.url).toBe(url);
expect(siteSpeedAudits?.length).toBe(64);
expect(siteSpeedAuditItems?.length).toBe(256);
expect(metrics?.firstContentfulPaint).toBe(0.01);
expect(metrics?.firstMeaningfulPaint).toBe(0.01);
});
});

Custom Metrics

If the project has custom metrics configured, those metrics will be returned in the response.

If you would like for type safety, you can pass the type of the custom metrics to the request method.

const { customMetrics, containerExecutionFailures } = await client.requestProject<ICustomMetrics>(projectId, url);

Running in CI/CD

name: Run tests

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Install dependencies
run: yarn install

- name: Run tests
run: |
export OREO_API_SDK_USER_KEY_ID=${{secrets.userKeyId}}
export OREO_API_SDK_USER_KEY_SECRET=${{secrets.userKeySecret}}
yarn test