Skip to content

Autogenerated Authlete API client for Typescript based on the OpenAPI document.

License

Notifications You must be signed in to change notification settings

authlete/openapi-for-typescript

Repository files navigation

This generator creates TypeScript/JavaScript client that utilizes RxJS. The generated Node module can be used in the following environments:

Environment

  • Node.js
  • Webpack
  • Browserify

Language level

  • ES5 - you must have a Promises/A+ library installed
  • ES6

Module system

  • CommonJS
  • ES6 module system

It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via package.json. (Reference)

Building

To build and compile the typescript sources to javascript use:

npm install
npm run build

Publishing

First build the package then run npm publish

Consuming

navigate to the folder of your consuming project and run one of the following commands.

published:

npm install @authlete/[email protected] --save

unPublished (not recommended):

npm install PATH_TO_GENERATED_PACKAGE --save

How to apply middleware

First, add a singleton class that extends the generated Configuration class.

export class AuthInterceptor extends Configuration {
  private static config: AuthInterceptor;

  private constructor() {
    const middleware: Middleware[] = [
      {
        pre(request: RequestArgs): RequestArgs {
          const token = getAuthToken();

          return {
            ...request,
            headers: {
              ...request.headers,
              Authorization: `Bearer ${token}`,
            },
          };
        },
      },
    ];

    super({ middleware });
  }

  public static get Instance() {
    return AuthInterceptor.config || (AuthInterceptor.config = new this());
  }
}

Next, pass it to the generated api controller.

const api = new StoreApi(AuthInterceptor.Instance);

Releases

No releases published

Packages

No packages published