Skip to content

Latest commit

 

History

History
111 lines (85 loc) · 3.93 KB

client-spec.md

File metadata and controls

111 lines (85 loc) · 3.93 KB

Client Spec

  1. Call getViewData(name, data) for every view provided.
  • 1.1 Use the return value as the data field's value for the Jobs Object.
  1. Call prepareRequest(currentJobs, originalJobs) as a reducer.
  • 2.1 The return value becomes the new Jobs Object.
  1. Call shouldSendRequest(jobs) and pass in the Jobs object.
  • 3.1 If false.
    • 3.1.1 Create a Response Object.
    • 3.1.2 The html attribute is the fallback client-rendered output.
    • 3.1.3 The error attribute should be null.
  1. Call willSendRequest(jobs).
  • 4.1 Submit the HTTP Request as a POST.
  1. If any error occurs up until this point create a Response Object.
  • 5.1 The error attribute should equal the Error that was thrown.
  • 5.2 The html attribute is the fallback client-rendered output.
  • 5.3 Call onError(error, jobs).
  1. When a response is received from the server:
  • 6.1 Iterate over the response, if the error field is not null then call onError(error, job) per job.
  • 6.2 Ensure that every job has an html field and that it is a string. If there is no HTML then use the fallback client-rendered output.
  1. Call onSuccess(response, jobs).
  2. Call afterResponse(currentResponse, originalResponse) as a reducer.
  3. If an error is encountered then call onError(error, jobs) and assert that the fallback HTML is provided.

Client URL and Request Information

Constructing the URL

HOST is whatever you're running Hypernova on localhost usually works if you're testing locally.

PORT is whatever is specified when you setup Hypernova. You can see an example here in the README and there's also this working example.

The URL is /batch and that's just because that's what it was named. It's the only route that is defined for express.

So the full URL would be something like http://localhost:3030/batch

Posting a batch of jobs

The POST to /batch should look something like:

{
  "NameOfComponent": {
    "name": "NameOfComponent",
    "data": {
      "theseAreProps": true,
      "someOtherProps": ["one", "two", "three"]
    },
  }
}

If getComponent returns something for "NameOfComponent" then you should be good to go.

Plugin Lifecycle API

function getViewData(viewName: string, data: any): any {}

Allows you to alter the data that a "view" will receive.

type Job = { name: string, data: any };
type Jobs = { [string]: Job };
function prepareRequest(currentJobs: Jobs, originalJobs: Jobs): Jobs {}

A reducer type function that is called when preparing the request that will be sent to Hypernova. This function receives the current running jobs Object and the original jobs Object.

function shouldSendRequest(jobs: Jobs): boolean {}

An every type function. If one returns false then the request is canceled.

function willSendRequest(jobs: Jobs): void {}

An event type function that is called prior to a request being sent.

type Job = { name: string, data: any };
type Response = {
  [string]: {
    error: ?Error,
    html: string,
    job: Job,
  },
};
function afterResponse(currentResponse: any, originalResponse: Response): any {}

A reducer type function which receives the current response and the original response from the Hypernova service.

type Job = { name: string, data: any };
type Jobs = { [string]: Job };
function onSuccess(response: any, jobs: Jobs): void {}

An event type function that is called whenever a request was successful.

type Job = { name: string, data: any };
type Jobs = { [string]: Job };
function onError(err: Error, jobs: Jobs): void {}

An event type function that is called whenever any error is encountered.