Home Manual Reference Source
import PageProof from '@pageproof/sdk/src/core/PageProof.js'
public class | source

PageProof

Constructor Summary

Public Constructor
public

constructor(options: {})

Member Summary

Public Members
public

The Accounts API.

public

The repository of registered adapters.

public

The Comments API.

public

The Dashboard API.

public

The Files API.

public

The Proofs API.

public

The current session.

public

The Users API.

public

The Workflows API.

Method Summary

Public Methods
public

Returns the Admin API (experimental).

public

on(event: string, handler: function): void

Registers an event handler.

public

Sets the current session.

Public Constructors

public constructor(options: {}) source

Params:

NameTypeAttributeDescription
options {}
  • optional
  • default: {}

Public Members

public accounts: Accounts source

The Accounts API.

public adapters: AdapterRepository source

The repository of registered adapters.

The AdapterRepository helps provide the functionality of the SDK to the APIs (API).

public comments: Comments source

The Comments API.

public dashboard: Dashboard source

The Dashboard API.

public files: Files source

The Files API.

public proofs: Proofs source

The Proofs API.

public session: Session source

The current session.

The session object is used to make authorized requests to PageProof. If there is no session, it's not possible to send any requests to the API other than those which have been made explicitly public.

See:

public users: Users source

The Users API.

public workflows: Workflows source

The Workflows API.

Public Methods

public admin(): Promise<Admin> source

Returns the Admin API (experimental).

Please use this API with caution. This functionality is primarily used within the app, so these APIs are updated regularly. Please ensure you have registered a error.deprecated event to be notified when these APIs become incompatible with the version of the SDK you're running.

We also advise you to let us know when you incorporate this API into your app, as we will try our best to notify you of major breaking changes. Email us at hello@pageproof.com.

This feature is only for team/enterprise administrators. If you call this method while authenticated with a non-admin account, the promise will reject. Only the first call to this method is potentially async, as it verifies the account is actually an administrator.

Return:

Promise<Admin>

Example:

const client = new PageProof(...);
const admin = await client.admin();
const users = await admin.team.users.active(); // retrieve a list of all the active users in your team
console.log(users); // [User, User, User]

public on(event: string, handler: function): void source

Registers an event handler.

The SDK exposes some events/hooks, which you can use to make it easier for yourself to use it seamlessly. For example, we have an event ("error.unauthorized") which is emitted when an endpoint responds with a 401 (Unauthorized). If you return a Promise, it will automatically retry the request.

All event handlers are invoked at the same time. Returning a Promise in one, will not defer the others.

Here is a list of currently supported events.

  • error.unauthorized
  • error.deprecated
  • error.throttled
  • error.response

Params:

NameTypeAttributeDescription
event string

The event name (or pattern) to register a handler for

handler function

The event handler

Return:

void

Example:

Handle unexpected session expirations
const client = new PageProof({ <omitted> });
 
client.on('error.unauthorized', () => {
  // If the "error.unauthorized" event handler returns a promise, the SDK
  // will automatically retry the request if it notices the session has changed.
  return client.accounts.login('user@example.com', '<password>');
});
Be notified of deprecated APIs
const client = new PageProof({ <omitted> });
 
client.on('error.deprecated', (event) => {
  // Some custom code which notifies you (the developer) that it's probably time
  // to update the SDK. We will never deprecate APIs without an update to the
  // SDK with a replacement.
});

public setSession(session: Session | object | null): Session | null source

Sets the current session.

This method should be called when restoring a session. You can either pass an object (containing all the properties, or an instance of an existing Session object.

Params:

NameTypeAttributeDescription
session Session | object | null

The session object

Return:

Session | null