Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

realm-web

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

realm-web - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

20

CHANGELOG.md

@@ -5,2 +5,16 @@ ?.?.? Release notes (2020-??-??)

### Enhancements
* Added more credentials enabling logins via additional authentication providers: Custom Functions, Custom JWT, Google, Facebook & Apple ID. ([#3019](https://github.com/realm/realm-js/pull/3019))
* Custom data can now be retrieved from an active User. ([#3019](https://github.com/realm/realm-js/pull/3019))
### Fixed
* Fixed an error "Cannot use 'in' operator to search for 'node' in undefined", which could occur when bundling the package without Node.js stubs available. ([#3001](https://github.com/realm/realm-js/pull/3001))
* Fixed refreshing of access tokens upon 401 responses from the server. ([#3020](https://github.com/realm/realm-js/pull/3020))
### Internal
* None
0.5.0 Release notes (2020-06-29)
=============================================================
### Enhancements
* Users are now persisted across refreshes and browser tabs (using the browser's local-storage). ([#2990](https://github.com/realm/realm-js/pull/2990))

@@ -16,3 +30,3 @@ * App location metadata is now requested before making any requests towards the app server. This removes the need for users to manually resolve the baseUrl. ([#3000](https://github.com/realm/realm-js/pull/3000))

0.4.0 Release notes (2020-6-11)
0.4.0 Release notes (2020-06-11)
=============================================================

@@ -29,3 +43,3 @@

0.3.0 Release notes (2020-6-11)
0.3.0 Release notes (2020-06-11)
=============================================================

@@ -42,5 +56,5 @@

0.2.0 Release notes (2020-6-4)
0.2.0 Release notes (2020-06-04)
=============================================================
This was the first external release of the Realm Web package.

250

dist/bundle.d.ts
/// <reference path="../types/realm/bson.d.ts" />
/// <reference path="../types/realm/app.d.ts" />
declare type StorageChangeListner = () => void;
/**
* Implementors of this provide a simple key-value store
*/
interface Storage {
/**
* Get the value of a particular key in the storage.
*/
get(key: string): string | null;
/**
* Set the value of a particular key in the storage.
*/
set(key: string, value: string): void;
/**
* Remove the entry for a particular key from the storage.
*/
remove(key: string): void;
/**
* Create a new store prefixed with a part of the key.
*/
prefix(keyPart: string): Storage;
/**
* Clears all values stored in the storage.
*
* @param prefix Clear only values starting with this prefix.
*/
clear(prefix?: string): void;
/**
* Add a callback function which will be called when the store updates.
*
* @param listener The listener callback to add.
*/
addListener(listener: StorageChangeListner): void;
/**
* Remove a callback function which was previously added.
*
* @param listener The listener callback to remove.
*/
removeListener(listener: StorageChangeListner): void;
}
/**
* A `Storage` which will prefix a key part to every operation.
*/
declare class PrefixedStorage implements Storage {
/**
* The string separating two parts
*/
private static PART_SEPARATOR;
/**
* The underlying storage to use for operations.
*/
private storage;
/**
* The part of the key to prefix when performing operations.
*/
private keyPart;
/**
* Construct a `Storage` which will prefix a key part to every operation.
*
* @param storage The underlying storage to use for operations.
* @param keyPart The part of the key to prefix when performing operations.
*/
constructor(storage: Storage, keyPart: string);
/** @inheritdoc */
get(key: string): string | null;
/** @inheritdoc */
set(key: string, value: string): void;
/** @inheritdoc */
remove(key: string): void;
/** @inheritdoc */
prefix(keyPart: string): Storage;
/** @inheritdoc */
clear(prefix?: string): void;
/** @inheritdoc */
addListener(listener: StorageChangeListner): void;
/** @inheritdoc */
removeListener(listener: StorageChangeListner): void;
}
/**
* Create a `Storage` instance, default to the current environment
*
* @returns A LocalStorage instance if the window global is an object, MemoryStorage otherwise.
* Both will prefix keys with "realm-web".
*/
declare function createDefaultStorage(): Storage;
declare type Method = "GET" | "POST" | "DELETE" | "PUT";

@@ -98,3 +186,3 @@ declare type Headers = {

get customData(): CustomDataType;
get apiKeys(): Realm.Auth.ApiKeyProvider;
get apiKeys(): Realm.Auth.ApiKeyAuth;
/**

@@ -108,2 +196,3 @@ * @returns Profile containing detailed information about the user.

linkCredentials(credentials: Realm.Credentials): Promise<void>;
refreshAccessToken(): Promise<void>;
refreshCustomData(): Promise<CustomDataType>;

@@ -115,3 +204,3 @@ callFunction(name: string, ...args: any[]): Promise<any>;

hydrate(): void;
private refreshAccessToken;
private decodeAccessToken;
}

@@ -220,3 +309,3 @@

/** @inheritdoc */
fetch<RequestBody extends any, ResponseBody extends any>(request: BaseRequest<RequestBody>): Promise<ResponseBody>;
fetch<RequestBody extends any = any, ResponseBody extends any = any>(request: BaseRequest<RequestBody>): Promise<ResponseBody>;
/** @inheritdoc */

@@ -229,3 +318,3 @@ prefix(pathPrefix: string): Transport;

*/
private determineBaseUrl;
determineBaseUrl(ignoreLocation: boolean): Promise<string>;
}

@@ -236,2 +325,8 @@

declare type EmailPasswordPayload = Realm.Credentials.EmailPasswordPayload;
declare type OAuth2RedirectPayload = Realm.Credentials.OAuth2RedirectPayload;
declare type GooglePayload = Realm.Credentials.GooglePayload;
declare type FacebookPayload = Realm.Credentials.FacebookPayload;
declare type FunctionPayload = Realm.Credentials.FunctionPayload;
declare type JWTPayload = Realm.Credentials.JWTPayload;
declare type ApplePayload = Realm.Credentials.ApplePayload;
/**

@@ -242,3 +337,3 @@ * Instances of this class can be passed to the `app.logIn` method to authenticate an end-user.

/**
* Creates credentials that logs in using the [Anonymous Provider](https://docs.mongodb.com/stitch/authentication/anonymous/).
* Creates credentials that logs in using the [Anonymous Provider](https://docs.mongodb.com/realm/authentication/anonymous/).
*

@@ -249,3 +344,3 @@ * @returns The credentials instance, which can be passed to `app.logIn`.

/**
* Creates credentials that logs in using the [API Key Provider](https://docs.mongodb.com/stitch/authentication/api-key/).
* Creates credentials that logs in using the [API Key Provider](https://docs.mongodb.com/realm/authentication/api-key/).
*

@@ -257,3 +352,3 @@ * @param key The secret content of the API key.

/**
* Creates credentials that logs in using the [Email/Password Provider](https://docs.mongodb.com/stitch/authentication/userpass/).
* Creates credentials that logs in using the [Email/Password Provider](https://docs.mongodb.com/realm/authentication/email-password/).
* Note: This was formerly known as the "Username/Password" provider.

@@ -267,2 +362,37 @@ *

/**
* Creates credentials that logs in using the [Custom Function Provider](https://docs.mongodb.com/realm/authentication/custom-function/).
*
* @param payload The custom payload as expected by the server.
* @returns The credentials instance, which can be passed to `app.logIn`.
*/
static function<PayloadType extends FunctionPayload = FunctionPayload>(payload: PayloadType): Credentials<PayloadType>;
/**
* Creates credentials that logs in using the [Custom JWT Provider](https://docs.mongodb.com/realm/authentication/custom-jwt/).
*
* @param token The JSON Web Token (JWT).
* @returns The credentials instance, which can be passed to `app.logIn`.
*/
static jwt(token: string): Credentials<Realm.Credentials.ApiKeyPayload>;
/**
* Creates credentials that logs in using the [Google Provider](https://docs.mongodb.com/realm/authentication/google/).
*
* @param redirectUrlOrAuthCode The URL that users should be redirected to or the auth code returned from Google.
* @returns The credentials instance, which can be passed to `app.logIn`.
*/
static google<PayloadType extends object = OAuth2RedirectPayload | GooglePayload>(redirectUrlOrAuthCode: string): Credentials<PayloadType>;
/**
* Creates credentials that logs in using the [Facebook Provider](https://docs.mongodb.com/realm/authentication/facebook/).
*
* @param redirectUrlOrAccessToken The URL that users should be redirected to or the auth code returned from Facebook.
* @returns The credentials instance, which can be passed to `app.logIn`.
*/
static facebook<PayloadType extends object = OAuth2RedirectPayload | FacebookPayload>(redirectUrlOrAccessToken: string): Credentials<PayloadType>;
/**
* Creates credentials that logs in using the [Apple ID Provider](https://docs.mongodb.com/realm/authentication/apple/).
*
* @param redirectUrlOrIdToken The URL that users should be redirected to or the id_token returned from Apple.
* @returns The credentials instance, which can be passed to `app.logIn`.
*/
static apple<PayloadType extends object = OAuth2RedirectPayload | ApplePayload>(redirectUrlOrIdToken: string): Credentials<PayloadType>;
/**
* The name of the authentication provider used when authenticating.

@@ -283,76 +413,37 @@ * Note: This is the same as the type for all current authentication providers in the service and mainly required for forwards-compatibility.

constructor(name: string, type: "local-userpass", payload: EmailPasswordPayload);
constructor(name: string, type: "custom-function", payload: FunctionPayload);
constructor(name: string, type: "custom-token", payload: JWTPayload);
constructor(name: string, type: "oauth2-google", payload: OAuth2RedirectPayload | GooglePayload);
constructor(name: string, type: "oauth2-facebook", payload: OAuth2RedirectPayload | FacebookPayload);
constructor(name: string, type: "oauth2-apple", payload: OAuth2RedirectPayload | ApplePayload);
}
/**
* Implementors of this provide a simple key-value store
*/
interface Storage {
/** @inheritdoc */
declare class EmailPasswordAuth implements Realm.Auth.EmailPasswordAuth {
/**
* Get the value of a particular key in the storage.
* The underlying transport.
*/
get(key: string): string | null;
private readonly transport;
/**
* Set the value of a particular key in the storage.
*/
set(key: string, value: string): void;
/**
* Remove the entry for a particular key from the storage.
*/
remove(key: string): void;
/**
* Create a new store prefixed with a part of the key.
*/
prefix(keyPart: string): Storage;
/**
* Clears all values stored in the storage.
* Construct an interface to the email / password authentication provider.
*
* @param prefix Clear only values starting with this prefix.
* @param transport The underlying transport used to request the services.
* @param providerName Optional custom name of the authentication provider.
*/
clear(prefix?: string): void;
}
/**
* A `Storage` which will prefix a key part to every operation.
*/
declare class PrefixedStorage implements Storage {
/**
* The string separating two parts
*/
private static PART_SEPARATOR;
/**
* The underlying storage to use for operations.
*/
private storage;
/**
* The part of the key to prefix when performing operations.
*/
private keyPart;
/**
* Construct a `Storage` which will prefix a key part to every operation.
*
* @param storage The underlying storage to use for operations.
* @param keyPart The part of the key to prefix when performing operations.
*/
constructor(storage: Storage, keyPart: string);
constructor(transport: Transport, providerName?: string);
/** @inheritdoc */
get(key: string): string | null;
registerUser(email: string, password: string): Promise<void>;
/** @inheritdoc */
set(key: string, value: string): void;
confirmUser(token: string, tokenId: string): Promise<void>;
/** @inheritdoc */
remove(key: string): void;
resendConfirmationEmail(email: string): Promise<void>;
/** @inheritdoc */
prefix(keyPart: string): Storage;
resetPassword(token: string, tokenId: string, password: string): Promise<void>;
/** @inheritdoc */
clear(prefix?: string): void;
sendResetPasswordEmail(email: string): Promise<void>;
/** @inheritdoc */
callResetPasswordFunction(email: string, password: string, args: any[]): Promise<void>;
}
/**
* Create a `Storage` instance, default to the current environment
*
* @returns A LocalStorage instance if the window global is an object, MemoryStorage otherwise.
* Both will prefix keys with "realm-web".
*/
declare function createDefaultStorage(): Storage;
/**
* Storage specific to the app.

@@ -418,4 +509,2 @@ */

/** @inheritdoc */
readonly auth: Realm.AuthProviders;
/** @inheritdoc */
readonly id: string;

@@ -438,2 +527,4 @@ /**

readonly appTransport: Transport;
/** @inheritdoc */
readonly emailPasswordAuth: EmailPasswordAuth;
/**

@@ -453,2 +544,6 @@ * Storage available for the app

/**
* An helper used to open new and close current windows.
*/
private oauth2;
/**
* Construct a Realm App, either from the Realm App id visible from the MongoDB Realm UI or a configuration.

@@ -471,3 +566,3 @@ *

*/
logIn(credentials: Realm.Credentials, fetchProfile?: boolean): Promise<User<FunctionsFactoryType, CustomDataType>>;
logIn(credentials: Realm.Credentials<any>, fetchProfile?: boolean): Promise<User<FunctionsFactoryType, CustomDataType>>;
/**

@@ -498,2 +593,10 @@ * @inheritdoc

/**
* Perform the actual login, based on the credentials.
* Either it decodes the credentials and instantiates a user directly or it calls User.logIn to perform a fetch.
*
* @param credentials Credentials to use when logging in
* @param fetchProfile Should the users profile be fetched? (default: true)
*/
private performLogIn;
/**
* Restores the state of the app (active and logged-out users) from the storage

@@ -511,3 +614,10 @@ */

declare function app(id: string): Realm.App<Realm.DefaultFunctionsFactory, any> | App<Realm.DefaultFunctionsFactory, any>;
/**
* Handle an OAuth 2.0 redirect
*
* @param location An optional location to use (defaults to the windows current location)
* @param storage Optional storage used to save any results from the location.
*/
declare function handleAuthRedirect(location?: Location, storage?: Storage): void;
export { App, Credentials, User, UserState, app, createDefaultStorage };
export { App, Credentials, User, UserState, app, createDefaultStorage, handleAuthRedirect };
{
"name": "realm-web",
"version": "0.5.0",
"version": "0.6.0",
"description": "Authenticate and communicate with the MongoDB Realm platform, from your web-browser",

@@ -60,3 +60,3 @@ "main": "dist/bundle.cjs.js",

"node-fetch": "^2.6.0",
"realm-network-transport": "^0.3.0",
"realm-network-transport": "^0.5.0",
"rollup": "^2.6.1",

@@ -63,0 +63,0 @@ "rollup-plugin-dts": "^1.4.0",

@@ -16,13 +16,8 @@ # Realm Web

- Most importantly, the Realm Web project *will not* include a Realm Sync client in any foreseeable future.
- A limited selection of types of [credentials for authentication providers](https://docs.mongodb.com/stitch/authentication/providers/) are implemented at the moment:
- Anonymous.
- API key.
- Email & password.
- A limited selection of [services](https://docs.mongodb.com/stitch/services/) are implemented at the moment:
- MongoDB (watching a collection is not yet implemented).
- HTTP (send requests using the MongoDB service as a proxy).
- HTTP: Send requests using the MongoDB service as a proxy.
Some parts of the legacy Stitch SDK is still missing, most notably:
- The ability to link a user to another identity.
- The types for the `Realm.Credentials` namespace is not fully implemented.
- No device information is sent to the service when authenticating a user.

@@ -29,0 +24,0 @@

@@ -27,5 +27,11 @@ ////////////////////////////////////////////////////////////////////////////

namespace Credentials {
/**
* Payload sent when authenticating using the [Email/Password Provider](https://docs.mongodb.com/stitch/authentication/userpass/).
* Payload sent when authenticating using the [Anonymous Provider](https://docs.mongodb.com/realm/authentication/anonymous/).
*/
type AnonymousPayload = {};
/**
* Payload sent when authenticating using the [Email/Password Provider](https://docs.mongodb.com/realm/authentication/email-password/).
*/
type EmailPasswordPayload = {

@@ -45,3 +51,3 @@ /**

/**
* Payload sent when authenticating using the [API Key Provider](https://docs.mongodb.com/stitch/authentication/api-key/).
* Payload sent when authenticating using the [API Key Provider](https://docs.mongodb.com/realm/authentication/api-key/).
*/

@@ -56,5 +62,56 @@ type ApiKeyPayload = {

/**
* Payload sent when authenticating using the [Anonymous Provider](https://docs.mongodb.com/stitch/authentication/anonymous/).
* Payload sent when authenticating using the [Custom Function Provider](https://docs.mongodb.com/realm/authentication/custom-function/).
*/
type AnonymousPayload = {};
type FunctionPayload = {
[key: string]: string,
};
/**
* Payload sent when authenticating using the [Custom JWT Provider](https://docs.mongodb.com/realm/authentication/custom-jwt/).
*/
type JWTPayload = {
token: string;
};
/**
* Payload sent when authenticating using an OAuth 2.0 provider:
* - [Google Provider](https://docs.mongodb.com/realm/authentication/google/).
* - [Facebook Provider](https://docs.mongodb.com/realm/authentication/facebook/).
*/
type OAuth2RedirectPayload = {
/**
* The auth code returned from Google.
*/
redirectUrl: string;
};
/**
* Payload sent when authenticating using the [Google Provider](https://docs.mongodb.com/realm/authentication/google/).
*/
type GooglePayload = {
/**
* The auth code returned from Google.
*/
authCode: string;
};
/**
* Payload sent when authenticating using the [Google Provider](https://docs.mongodb.com/realm/authentication/google/).
*/
type FacebookPayload = {
/**
* The auth code returned from Google.
*/
accessToken: string;
};
/**
* Payload sent when authenticating using the [Apple ID Provider](https://docs.mongodb.com/realm/authentication/apple/).
*/
type ApplePayload = {
/**
* The ID token from Apple.
*/
id_token: string;
};
}

@@ -109,2 +166,10 @@

/**
* Creates credentials that logs in using the [Google Provider](https://docs.mongodb.com/realm/authentication/google/).
*
* @param authCode The auth code returned from Google.
* @returns The credentials instance, which can be passed to `app.logIn`.
*/
static google(authCode: string): Credentials<Credentials.GooglePayload>;
// TODO: Add providerCapabilities?

@@ -145,5 +210,5 @@ }

/**
* Perform operations on an app's authentication providers.
* Perform operations related to the email/password auth provider.
*/
auth: Realm.AuthProviders;
emailPasswordAuth: Realm.Auth.EmailPasswordAuth;

@@ -244,5 +309,5 @@ /**

/**
* This object allows API keys associated with the user to be retrieved, created, enabled and disabled.
* Perform operations related to the API-key auth provider.
*/
readonly apiKeys: Realm.Auth.ApiKeyProvider;
readonly apiKeys: Realm.Auth.ApiKeyAuth;

@@ -249,0 +314,0 @@ /**

@@ -25,5 +25,5 @@ ////////////////////////////////////////////////////////////////////////////

/** Authentication provider where users identify using email and password. */
emailPassword: Realm.Auth.EmailPasswordProvider;
emailPassword: Realm.Auth.EmailPasswordAuth;
/** Authentication provider where users identify using an API-key. */
apiKey: Realm.Auth.ApiKeyProvider;
apiKey: Realm.Auth.ApiKeyAuth;
}

@@ -35,3 +35,3 @@

*/
class EmailPasswordProvider {
class EmailPasswordAuth {
/**

@@ -122,3 +122,3 @@ * Register a new user.

*/
class ApiKeyProvider {
class ApiKeyAuth {
/**

@@ -125,0 +125,0 @@ * Creates an API key that can be used to authenticate as the current user.

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc