Amazon-cognito-identity-js: Typescript typings

Created on 20 Aug 2016  路  7Comments  路  Source: amazon-archives/amazon-cognito-identity-js

Typescript is being adopted heavily now and almost all Angular2 projects are using Typescript.
I have an Angular2 project using Typescript and the aws-sdk-js. Th aws-sdk-js team is providing Typescript typings which are working out great although they aren't in master yet:
https://github.com/aws/aws-sdk-js/tree/support/typescript/typings

When will this add on library for working with cognito user pools add Typescript typings? I believe the above branch for aws-sdk-js automatically has the typings files created when changes are made.

Is this library going to be rolled into the aws-sdk-js eventually?

Thanks!

enhancement

Most helpful comment

This is my temporary typings definitions just for reference

declare module "amazon-cognito-identity-js" {

  import { ClientConfig } from "aws-sdk";

  export interface AuthenticationDetailsData {
    Username: string;
    Password: string;
  }

  export class AuthenticationDetails {
    constructor(data: AuthenticationDetailsData);

    public getUsername(): string;
    public getPassword(): string;
    public getValidationData(): any[];
  }

  export interface CognitoUserData {
    Username: string;
    Pool: CognitoUserPool;
  }

  export class CognitoUser {
    constructor(data: CognitoUserData);

    public getSignInUserSession(): CognitoUserSession;
    public getUsername(): string;

    public getAuthenticationFlowType(): string;
    public setAuthenticationFlowType(authenticationFlowType: string): string;

    public getSession(callback: Function): void;
    public authenticateUser(params: any, callbacks: any): void;
    public confirmRegistration(code: string, somethingWhichIsTrue: boolean, callback: (err: any, result: any) => void): void;
    public resendConfirmationCode(callback: Function): void;
  }

  export interface CognitoUserAttributeData {
    Name: string;
    Value: string;
  }

  export class CognitoUserAttribute {
    constructor(data: CognitoUserAttributeData);

    public getValue(): string;
    public setValue(value: string): CognitoUserAttribute;
    public getName(): string;
    public setName(name: string): CognitoUserAttribute;
    public toString(): string;
    public toJSON(): Object;
  }

  export interface CognitoUserPoolData {
    UserPoolId: string;
    ClientId: string;
    Paranoia?: number;
  }

  export class CognitoUserPool {
    constructor(data: CognitoUserPoolData);

    public getUserPoolId(): string;
    public getClientId(): string;
    public getParanoia(): number

    public setParanoia(paranoia: number): void;

    public signUp(username: string, password: string, userAttributes: any[], validationData: any[], callback: (err: any, result: any) => void): void;

    public getCurrentUser(): CognitoUser;
  }

  export interface CognitoUserSessionData {
    IdToken: string;
    AccessToken: string;
    RefreshToken?: string;
  }

  export class CognitoUserSession {
    constructor(data: CognitoUserSessionData);

    public getIdToken(): CognitoIdToken;
    public getRefreshToken(): CognitoRefreshToken;
    public getAccessToken(): CognitoAccessToken;
    public isValid(): boolean;
  }

  export class CognitoIdentityServiceProvider {
    public config: ClientConfig;
  }

  export class CognitoAccessToken {
    constructor(accessToken: string);

    getJwtToken(): string;
    getExpiration(): number;
  }

  export class CognitoIdToken {
    constructor(idToken: string);

    getJwtToken(): string;
    getExpiration(): number;
  }

  export class CognitoRefreshToken {
    constructor(refreshToken: string);

    getJwtToken(): string;
    getExpiration(): number;
  }
}

All 7 comments

Main issue would be getting the team to keep it up to date, if they don't want to do that, probably best to leave it to DefinitelyTyped.

The main problem with DefinitelyTyped is the definitions even for typings of aws-sdk-js is that they aren't useable because they are so outdated. See:
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/7458

For aws-sdk-js I'm using typings from:
https://github.com/ingenieux/aws-sdk-typescript

This is my temporary typings definitions just for reference

declare module "amazon-cognito-identity-js" {

  import { ClientConfig } from "aws-sdk";

  export interface AuthenticationDetailsData {
    Username: string;
    Password: string;
  }

  export class AuthenticationDetails {
    constructor(data: AuthenticationDetailsData);

    public getUsername(): string;
    public getPassword(): string;
    public getValidationData(): any[];
  }

  export interface CognitoUserData {
    Username: string;
    Pool: CognitoUserPool;
  }

  export class CognitoUser {
    constructor(data: CognitoUserData);

    public getSignInUserSession(): CognitoUserSession;
    public getUsername(): string;

    public getAuthenticationFlowType(): string;
    public setAuthenticationFlowType(authenticationFlowType: string): string;

    public getSession(callback: Function): void;
    public authenticateUser(params: any, callbacks: any): void;
    public confirmRegistration(code: string, somethingWhichIsTrue: boolean, callback: (err: any, result: any) => void): void;
    public resendConfirmationCode(callback: Function): void;
  }

  export interface CognitoUserAttributeData {
    Name: string;
    Value: string;
  }

  export class CognitoUserAttribute {
    constructor(data: CognitoUserAttributeData);

    public getValue(): string;
    public setValue(value: string): CognitoUserAttribute;
    public getName(): string;
    public setName(name: string): CognitoUserAttribute;
    public toString(): string;
    public toJSON(): Object;
  }

  export interface CognitoUserPoolData {
    UserPoolId: string;
    ClientId: string;
    Paranoia?: number;
  }

  export class CognitoUserPool {
    constructor(data: CognitoUserPoolData);

    public getUserPoolId(): string;
    public getClientId(): string;
    public getParanoia(): number

    public setParanoia(paranoia: number): void;

    public signUp(username: string, password: string, userAttributes: any[], validationData: any[], callback: (err: any, result: any) => void): void;

    public getCurrentUser(): CognitoUser;
  }

  export interface CognitoUserSessionData {
    IdToken: string;
    AccessToken: string;
    RefreshToken?: string;
  }

  export class CognitoUserSession {
    constructor(data: CognitoUserSessionData);

    public getIdToken(): CognitoIdToken;
    public getRefreshToken(): CognitoRefreshToken;
    public getAccessToken(): CognitoAccessToken;
    public isValid(): boolean;
  }

  export class CognitoIdentityServiceProvider {
    public config: ClientConfig;
  }

  export class CognitoAccessToken {
    constructor(accessToken: string);

    getJwtToken(): string;
    getExpiration(): number;
  }

  export class CognitoIdToken {
    constructor(idToken: string);

    getJwtToken(): string;
    getExpiration(): number;
  }

  export class CognitoRefreshToken {
    constructor(refreshToken: string);

    getJwtToken(): string;
    getExpiration(): number;
  }
}

Thanks! Closing the issue since we merged the above. Thanks everyone!

There doesn't seem to be a ClientConfig exported by the aws-sdk anymore. I think that for the Cognito identity service provider this has been replaced by CognitoIdentityServiceProvider.Types.ClientConfiguration which is just ServiceConfigurationOptions & ClientApiVersions

Thanks for doing this,

its actually easier if you dev in TypeScript first as you get the types export for free. You can then auto publish it to defTyped.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sarah-pixvana picture sarah-pixvana  路  4Comments

guyb1 picture guyb1  路  4Comments

kaihendry picture kaihendry  路  4Comments

tranan89 picture tranan89  路  5Comments

sarah-pixvana picture sarah-pixvana  路  5Comments