UNPKG

@react-native-ohos/realm

Version:

Realm by MongoDB is an offline-first mobile database: an alternative to SQLite and key-value stores

176 lines 7.19 kB
import type { DefaultObject } from "../schema"; import { ApiKeyAuth } from "./ApiKeyAuth"; import type { ProviderType } from "./Credentials"; import { type Credentials } from "./Credentials"; import { type DefaultFunctionsFactory } from "./FunctionsFactory"; import type { DefaultUserProfileData } from "./UserProfile"; import { type MongoDBService } from "./MongoDBCollection"; import { PushClient } from "./PushClient"; export type UserChangeCallback = () => void; /** * The state of a user. */ export declare enum UserState { /** * Authenticated and available to communicate with services. * @deprecated Will be removed in v13. Please use {@link UserState.LoggedIn} */ Active = "active", /** Authenticated and available to communicate with services. */ LoggedIn = "LoggedIn", /** Logged out, but ready to be logged in. */ LoggedOut = "LoggedOut", /** Removed from the app entirely. */ Removed = "Removed" } /** * A user's identity with a particular authentication provider. */ export interface UserIdentity { /** * The ID of the identity. */ id: string; /** * The type of the provider associated with the identity. */ providerType: ProviderType; } export type AnyUser = User<any, any, any>; /** * Representation of an authenticated user of an {@link App}. */ export declare class User<UserFunctionsFactoryType extends DefaultFunctionsFactory = DefaultFunctionsFactory, UserCustomDataType extends DefaultObject = DefaultObject, UserProfileDataType extends DefaultUserProfileData = DefaultUserProfileData> { /** * The automatically-generated internal ID of the user. * @returns The user ID as a string. */ get id(): string; /** * The provider type used when authenticating the user. If multiple identities exist, * the provider type for the first identity found is return. * @returns The provider type as an enumerated string. * @deprecated Use {@link User.identities} instead. */ get providerType(): ProviderType; /** * The ID of the device. * @returns The device ID as a string or `null`. */ get deviceId(): string | null; /** * The state of the user. * @returns The state as an enumerated string. */ get state(): UserState; /** * The logged in state of the user. * @returns `true` if the user is logged in, `false` otherwise. */ get isLoggedIn(): boolean; /** * The identities of the user at any of the app's authentication providers. * @returns An array of {@link UserIdentity} objects. */ get identities(): UserIdentity[]; /** * The access token used when requesting a new access token. * @returns The access token as a string or `null`. */ get accessToken(): string | null; /** * The refresh token used when requesting a new access token. * @returns The refresh token as a string or `null`. */ get refreshToken(): string | null; /** * You can store arbitrary data about your application users in a MongoDB collection and configure * Atlas App Services to automatically expose each user’s data in a field of their user object. * For example, you might store a user’s preferred language, date of birth, or their local timezone. * * If this value has not been configured, it will be empty. * @returns The custom data as an object. */ get customData(): UserCustomDataType; /** * A profile containing additional information about the user. * @returns The user profile data as an object. */ get profile(): UserProfileDataType; /** * Use this to call functions defined by the Atlas App Services application, as this user. * @returns A {@link User.UserFunctionsFactoryType} that can be used to call the app's functions. */ get functions(): UserFunctionsFactoryType; /** * Perform operations related to the API-key auth provider. * @returns An {@link ApiKeyAuth} object that can be used to manage API keys. */ get apiKeys(): ApiKeyAuth; /** * Log out the user. * @returns A promise that resolves once the user has been logged out of the app. */ logOut(): Promise<void>; /** * Link the user with an identity represented by another set of credentials. * @param credentials - The credentials to use when linking. * @returns A promise that resolves once the user has been linked with the credentials. */ linkCredentials(credentials: Credentials): Promise<void>; /** * Call a remote Atlas App Services Function by its name. * @note Consider using `functions[name]()` instead of calling this method. * @param name - Name of the App Services Function. * @param args - Arguments passed to the Function. * @returns A promise that resolves to the value returned by the Function. * @example * // These are all equivalent: * await user.callFunction("doThing", a1, a2, a3); * await user.functions.doThing(a1, a2, a3); * await user.functions["doThing"](a1, a2, a3); * @example * // The methods returned from the functions object are bound, which is why it's okay to store the function in a variable before calling it: * const doThing = user.functions.doThing; * await doThing(a1); * await doThing(a2); */ callFunction(name: string, ...args: unknown[]): Promise<unknown>; /** * Refresh the access token and derive custom data from it. * @returns A promise that resolves to the refreshed custom data. */ refreshCustomData(): Promise<UserCustomDataType>; /** * Use the Push service to enable sending push messages to this user via Firebase Cloud Messaging (FCM). * @deprecated https://www.mongodb.com/docs/atlas/app-services/reference/push-notifications/ * @returns A {@link PushClient} with methods to register and deregister the device on the user. */ push(serviceName: string): PushClient; /** * @param serviceName - The name of the MongoDB service to connect to. * @returns A client enabling access to a MongoDB service. * @example * let blueWidgets = user.mongoClient("myService") * .db("myDb") * .collection<Widget>("widgets") * .find({ color: "blue" }); */ mongoClient(serviceName: string): MongoDBService; /** * Adds a listener that will be fired on various user related events. * This includes auth token refresh, refresh token refresh, refresh custom user data, and logout. * @param callback - The callback to be fired when the event occurs. */ addListener(callback: UserChangeCallback): void; /** * Removes an event listener previously added via {@link User.addListener}. * @param callback - The callback to be removed. */ removeListener(callback: UserChangeCallback): void; /** * Removes all event listeners previously added via {@link User.addListener}. */ removeAllListeners(): void; } //# sourceMappingURL=User.d.ts.map