@open-frames/types
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Open Frames Types

A shared set of types for all Open Frames implementations

Usage

import {
  OpenFramesUntrustedData,
  OpenFramesTrustedData,
  OpenFramesRequest,
  ValidationResponse,
  RequestValidator,
} from "@open-frames/types";

type RequestType = {
  clientProtocol: "test";
  untrustedData: OpenFramesUntrustedData & { foo: string };
  trustedData: OpenFramesTrustedData;
};

type ValidationResponseType = {
  foo: string;
};

class ExampleValidator
  implements RequestValidator<RequestType, ValidationResponseType, "test">
{
  readonly protocolIdentifier = "test";

  minProtocolVersion(): string {
    return `${this.protocolIdentifier}@VNext`;
  }

  isSupported(payload: OpenFramesRequest): payload is RequestType {
    return true;
  }

  async validate(
    payload: RequestType
  ): Promise<
    ValidationResponse<ValidationResponseType, typeof this.protocolIdentifier>
  > {
    return {
      isValid: true,
      clientProtocol: payload.clientProtocol,
      message: { foo: payload.untrustedData.foo },
    };
  }
}

Package Sidebar

Install

npm i @open-frames/types

Weekly Downloads

241

Version

0.1.1

License

MIT

Unpacked Size

6.51 kB

Total Files

7

Last publish

Collaborators

  • nick-xmtp