diff --git a/types/auth0/auth0-tests.ts b/types/auth0/auth0-tests.ts index 24a4aad87d..b84e92e223 100644 --- a/types/auth0/auth0-tests.ts +++ b/types/auth0/auth0-tests.ts @@ -28,6 +28,42 @@ management // Handle the error. }); +// Using a callback. +management.getUser({id: 'user_id'},(err: Error, user: auth0.User) => { + if (err) { + // Handle error. + } + console.log(user); +}); + +// Using a Promise. +management + .getUser({id: 'user_id'}) + .then((user) => { + console.log(user); + }) + .catch((err) => { + // Handle the error. + }); + +// Using a callback. +management.deleteUser({id: 'user_id'},(err: Error) => { + if (err) { + // Handle error. + } + console.log('deleted'); +}); + +// Using a Promise. +management + .deleteUser({id: 'user_id'}) + .then(() => { + console.log('deleted'); + }) + .catch((err) => { + // Handle the error. + }); + management .createUser({ connection: 'My-Connection', diff --git a/types/auth0/index.d.ts b/types/auth0/index.d.ts index 0e810f8ae5..3025b8d380 100644 --- a/types/auth0/index.d.ts +++ b/types/auth0/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for auth0 2.4 +// Type definitions for auth0 3.0 // Project: https://github.com/auth0/node-auth0 -// Definitions by: Wilson Hobbs , Seth Westphal +// Definitions by: Wilson Hobbs , Seth Westphal , Amiram Korach // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -15,16 +15,29 @@ export interface UserMetadata { } export interface AppMetadata { } export interface UserData { - connection: string; email?: string; username?: string; + email_verified?: boolean; + verify_email?: boolean; password?: string; phone_number?: string; + phone_verified?: boolean, user_metadata?: UserMetadata; - email_verified?: boolean; app_metadata?: AppMetadata; } +export interface CreateUserData extends UserData { + connection: string; +} + +export interface UpdateUserData extends UserData { + connection?: string; + blocked?: boolean; + verify_phone_number?: boolean, + verify_password?: boolean, + client_id?: string +} + export interface GetUsersData { per_page?: number; page?: number; @@ -68,10 +81,6 @@ export interface Identity { isSocial: boolean; } -export interface UpdateUserParameters { - id: string; -} - export interface AuthenticationClientOptions { clientId?: string; domain: string; @@ -135,17 +144,47 @@ export interface ClientParams { client_id: string; } +export type DeleteDeleteMultifactorParamsProvider = 'duo' | 'google-authenticator'; + export interface DeleteMultifactorParams { id: string; - provider: string; + provider: DeleteDeleteMultifactorParamsProvider; } -export interface LinkAccountsParams { +export type UnlinkAccountsParamsProvider = 'ad' | 'adfs' | 'amazon' | 'dropbox' | 'bitbucket' | 'aol' | 'auth0-adldap' | + 'auth0-oidc' | 'auth0' | 'baidu' | 'bitly' | 'box' | 'custom' | 'dwolla' | 'email' | 'evernote-sandbox' | 'evernote' | + 'exact' | 'facebook' | 'fitbit' | 'flickr' | 'github' | 'google-apps' | 'google-oauth2' | 'guardian' | 'instagram' | + 'ip' | 'linkedin' | 'miicard' | 'oauth1' | 'oauth2' | 'office365' | 'paypal' | 'paypal-sandbox' | 'pingfederate' | + 'planningcenter' | 'renren' | 'salesforce-community' | 'salesforce-sandbox' | 'salesforce' | 'samlp' | 'sharepoint' | + 'shopify' | 'sms' | 'soundcloud' | 'thecity-sandbox' | 'thecity' | 'thirtysevensignals' | 'twitter' | 'untappd' | + 'vkontakte' | 'waad' | 'weibo' | 'windowslive' | 'wordpress' | 'yahoo' | 'yammer' | 'yandex'; + +export interface UnlinkAccountsParams { id: string; - provider: string; + provider: UnlinkAccountsParamsProvider; user_id: string; } +export interface UnlinkAccountsResponseProfile { + email?: string; + email_verified?: boolean; + name?: string; + username?: string; + given_name?: string; + phone_number?: string; + phone_verified?: boolean; + family_name?: string; +} + +export interface UnlinkAccountsResponse { + connection: string; + user_id: string; + provider: string; + isSocial?: boolean; + access_token?: string; + profileData?: UnlinkAccountsResponseProfile +} + export interface LinkAccountsData { user_id: string; connection_id: string; @@ -308,32 +347,33 @@ export class ManagementClient { getUsers(params?: GetUsersData): Promise; getUsers(params?: GetUsersData, cb?: (err: Error, users: User[]) => void): void; - getUser(params?: ObjectWithId): Promise; - getUser(params?: ObjectWithId, cb?: (err: Error, users: User[]) => void): void; + getUser(params: ObjectWithId): Promise; + getUser(params: ObjectWithId, cb?: (err: Error, user: User) => void): void; - createUser(data: UserData): Promise; - createUser(data: UserData, cb: (err: Error, data: User) => void): void; + createUser(data: CreateUserData): Promise; + createUser(data: CreateUserData, cb: (err: Error, data: User) => void): void; - updateUser(params: UpdateUserParameters, data: User): Promise; - updateUser(params: UpdateUserParameters, data: User, cb: (err: Error, data: User) => void): void; + updateUser(params: ObjectWithId, data: UpdateUserData): Promise; + updateUser(params: ObjectWithId, data: UpdateUserData, cb: (err: Error, data: User) => void): void; - updateUserMetadata(params: UpdateUserParameters, data: UserMetadata): Promise; - updateUserMetadata(params: UpdateUserParameters, data: UserMetadata, cb: (err: Error, data: User) => void): void; + updateUserMetadata(params: ObjectWithId, data: UserMetadata): Promise; + updateUserMetadata(params: ObjectWithId, data: UserMetadata, cb: (err: Error, data: User) => void): void; + // Should be removed from auth0 also. Doesn't exist in api. deleteAllUsers(): Promise; deleteAllUsers(cb: (err: Error, data: any) => void): void; - deleteUser(params?: ObjectWithId): Promise; - deleteUser(params?: ObjectWithId, cb?: (err: Error, users: User[]) => void): void; + deleteUser(params: ObjectWithId): Promise; + deleteUser(params: ObjectWithId, cb?: (err: Error) => void): void; - updateAppMetadata(params: UpdateUserParameters, data: AppMetadata): Promise; - updateAppMetadata(params: UpdateUserParameters, data: AppMetadata, cb: (err: Error, data: User) => void): void; + updateAppMetadata(params: ObjectWithId, data: AppMetadata): Promise; + updateAppMetadata(params: ObjectWithId, data: AppMetadata, cb: (err: Error, data: User) => void): void; - deleteUserMultifactor(params: DeleteMultifactorParams): Promise; - deleteUserMultifactor(params: DeleteMultifactorParams, cb: (err: Error, data: any) => void): void; + deleteUserMultifactor(params: DeleteMultifactorParams): Promise; + deleteUserMultifactor(params: DeleteMultifactorParams, cb: (err: Error) => void): void; - unlinkUsers(params: LinkAccountsParams): Promise; - unlinkUsers(params: LinkAccountsParams, cb: (err: Error, data: any) => void): void; + unlinkUsers(params: UnlinkAccountsParams): Promise; + unlinkUsers(params: UnlinkAccountsParams, cb: (err: Error, data: UnlinkAccountsResponse) => void): void; linkUsers(params: ObjectWithId, data: LinkAccountsData): Promise; linkUsers(params: ObjectWithId, data: LinkAccountsData, cb: (err: Error, data: any) => void): void;