React-native-app-auth: Typescript definitions

Created on 19 Feb 2018  路  4Comments  路  Source: FormidableLabs/react-native-app-auth

I have created Typescript definitions, and wanted to check if you wanted to include this in the package or if I should simply add them to DefinitelyTyped.

declare module "react-native-app-auth" {
  interface IAppAuthProperties {
    scopes: string[];
    issuer: string;
    clientId: string;
    redirectUrl: string;
    aditionalParameters?: object;
  }

  function authorize(
    properties: IAppAuthProperties
  ): Promise<{
    accessToken: string;
    accessTokenExpirationDate: string;
    additionalParameters: object;
    idToken: string;
    refreshToken: string;
    tokenType: string;
  }>;

  function refresh(
    properties: IAppAuthProperties,
    { refreshToken: string }
  ): Promise<AuthorizeResult>;

  function revoke(
    properties: IAppAuthProperties,
    { tokenToRevoke: string, sendClientId: boolean }
  ): Promise<void>;
}

Most helpful comment

I think due to the small size of the module and the low likelihood of extra exports, we shouldn't resort to declaring a module, but just create a d.ts with exports in parallel to the index file.

But in general this is looking fine, although I'd create another interface for the authorize result.

I'm also personally not a fan of starting all interfaces with I* as in IAppAuthProperties, and Properties could just be Input or Opts, without losing clarity.

/cc @kadikraman

All 4 comments

I think due to the small size of the module and the low likelihood of extra exports, we shouldn't resort to declaring a module, but just create a d.ts with exports in parallel to the index file.

But in general this is looking fine, although I'd create another interface for the authorize result.

I'm also personally not a fan of starting all interfaces with I* as in IAppAuthProperties, and Properties could just be Input or Opts, without losing clarity.

/cc @kadikraman

Totally forgot I wanted to share mine as well ... Anyways, there are a few differences so we might join these 2 together. Here's what I have:

declare module 'react-native-app-auth' {
    export interface AuthConfig {
        issuer: string;
        clientId: string;
        redirectUrl: string;
        scopes: string[];
        additionalParameters?: { [name: string]: any };
    }

    export interface AuthorizeResult {
        accessToken: string;
        accessTokenExpirationDate: string;
        additionalParameters?: { [name: string]: any };
        idToken: string;
        refreshToken: string;
        tokenType: string;
    }

    export interface RevokeConfig {
        tokenToRevoke: string;
        sendClientId?: boolean;
    }

    export interface RefreshConfig {
        refreshToken: string;
    }

    export function authorize(config: AuthConfig): Promise<AuthorizeResult>;
    export function revoke(config: AuthConfig, revokeConfig: RevokeConfig): Promise<AuthorizeResult>;
    export function refresh(config: AuthConfig, refreshConfig: RefreshConfig): Promise<AuthorizeResult>;
}

Almost the same, just notice few small things.

  1. sendClientId in Revoke config should be optional as only Identity Server expects this.
  2. additionalParameters should be optional and it's slightly better practice to define it as { [name: string]: any } rather than object.

Just my 2 cents.

@PeterKottas nice! Was wondering about the additionalParameters. Have made a couple of changes (there's a pull request). Cheers.

Released as v2.1.0 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kadikraman picture kadikraman  路  3Comments

djleonskennedy picture djleonskennedy  路  3Comments

sattaman picture sattaman  路  3Comments

Electrofenster picture Electrofenster  路  4Comments

baltuonis picture baltuonis  路  6Comments