Skip to content

Commit

Permalink
Merge Realm JS and Realm Web types (#2950)
Browse files Browse the repository at this point in the history
* Updating package locks from release

* Merging types and adjusting configs

* Fixed linting issues

* Merged the auth provider types

* Updated types related to auth providers

* Fixing the functions factory types

* Fixed integration tests based on updated types

* Made options optional when using the HTTP service

* Delete the commented App class declaration

* Merge types and update code accordingly

* Package-lock got updated

* Fixed logging out a logged out user

* Commented out the App#logOut method

* Adding removeUser to the tests

* Update types/app.d.ts

Co-authored-by: Kenneth Geisshirt <kenneth.geisshirt@mongodb.com>

* Removed "| void"

* resendConfirmation → resendConfirmationEmail

* Removed logOut method from the `App`

* Fixed App constructor type

* Using unshift instead of splice where applicable

* Adopted API to the latest proposal

* Fixed the realm-network-transport types

* Updating integration tests

* ApiKeyAuth renames (#3047)

* Renamed UserAPIKeyProvider to ApiKeyAuth

* Renaming instance methods

* Moved from user.auth.apiKeys to user.apiKeys

* Renamed js_user_apikey_provider.hpp to js_api_key_auth.hpp

* Updated the jsdocs

* Adding apiKeys to the browser proxy

* Adding a note in the changelog

* EmailPasswordAuth renames (#3048)

    * Renamed to js_email_password_auth.hpp, email-password-auth-methods.js and api-key-auth-methods.js
    * Adding a note in the changelog
    * Updated docs
    * Renamed to EmailPasswordAuth

* Moved push service to a seperate interface

* Implemented a throwing push for a user

* Incorporated feedback

* v10 refactoring (#2996)

* registerEmail -> registerUser

* Realm.User.identity -> Realm.User.id. Realm.User.token -> Realm.User.accessToken. Add Realm.User.refreshToken.

* Turn Realm.App.{currentUser, allUsers} to an instance property

* Add Realm.Auth.EmailPassword.callResetPasswordFunction

* Wrongly merged

* Removed UserProfile from index.d.ts and updated pictureUrl

Co-authored-by: Kenneth Geisshirt <kenneth.geisshirt@mongodb.com>
  • Loading branch information
kraenhansen and kneth authored Jul 10, 2020
1 parent 70b24fa commit fb9f1d1
Show file tree
Hide file tree
Showing 49 changed files with 669 additions and 606 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ NOTE: Support for syncing with realm.cloud.io and/or Realm Object Server has bee

NOTE: This version bumps the Realm file format to version 11. It is not possible to downgrade to earlier versions. Older files will automatically be upgraded to the new file format. Files created by Realm JavaScript prior to v1.0.0, might not be upgradeable. Only [Realm Studio 10.0.0](https://github.com/realm/realm-studio/releases/tag/v10.0.0-beta.1) or later will be able to open the new file format.

### Breaking changes
* `Realm.Auth.EmailPassword.registerEmail()` has been renamed to `Realm.Auth.EmailPassword.registerUser()`.
* `Realm.User.identity` has been renamed to `Realm.User.id`.
* `Realm.User.token` has been renamed to `Realm.User.accessToken`.
* Change instance methods `Realm.App.currentUser()` and `Realm.App.allUsers()` to instance properties `Realm.App.currentUser` and `Realm.App.allUsers`.
* `Realm.Auth.UserAPIKeyProvider` has been replaced by `Realm.Auth.ApiKeyProvider`.
* `user.auth.apiKeys` has been replaced by `user.apiKeys`.
* The instance methods on the ApiKeyAuth instance (`user.apiKeys`) have gotten their APIKey(s) suffix removed: Ex. `apiKeys.createAPIKey` has been replaced by `apiKeys.create`.
* `Realm.Auth.EmailPasswordProvider` has been replaced by `Realm.Auth.EmailPasswordAuth`.
* `app.auth.emailPassword` has been replaced by `user.emailPasswordAuth`.

### Enhancements
* None.
* Added RemoteMongoClient functionality to `Realm.User`

### Fixed
* Failed to parse arguments correctly, causing the error `callback must be of type 'function', got (undefined)` when calling `Realm.App.emailPassword.sendResetPasswordEmail()` and `Realm.App.emailPassword.resendConfirmationEmail()`. ([#3037](https://github.com/realm/realm-js/issues/3037), since v10.0.0-beta.1)
Expand Down
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"src/js_app_credentials.hpp",
"src/js_user.hpp",
"src/js_network_transport.hpp",
"src/js_email_password_provider.hpp",
"src/js_email_password_auth.hpp",
"src/node/sync_logger.cpp",
"src/node/sync_logger.hpp",
]
Expand Down
66 changes: 42 additions & 24 deletions docs/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@
*
* @returns {Realm.User} The current user, `null` is no current user.
*/
currentUser() { }
get currentUser() { }

/**
* Returns a dictionary of alll users. Users' identity is used as key.
*
* @returns {Array}
*/
allUsers() { }
get allUsers() { }

/**
* Switches the current user.
Expand All @@ -133,18 +133,18 @@
removeUser(user) { }

/**
* Auth providers. Currently only `emailPassword` provider is support
* Client for the email/password authentication provider.
*
* @example
* {
* let app = new Realm.App(config);
* let provider = app.auth.emailPassword;
* // Creating a new user, by registering via email & password
* const app = new Realm.App(config);
* await app.emailPasswordAuth.registerUser('john@example.com', 'some-secure-password');
* }
*
* @see Realm.Auth
* @see Realm.Auth.EmailPassword
* @type {Realm.Auth.EmailPasswordAuth}
*/
get auth() { }
get emailPasswordAuth() { }
}


Expand Down Expand Up @@ -351,8 +351,8 @@ class Credentials {

/**
* A namespace for auth providers
* @see Realm.Auth.EmailPassword
* @see Realm.Auth.UserAPIKey
* @see Realm.Auth.EmailPasswordAuth
* @see Realm.Auth.ApiKeyAuth
* @memberof Realm
*/
class Auth {
Expand All @@ -363,20 +363,20 @@ class Auth {
* Class for managing email/password for users
* @memberof Realm.Auth
*/
class EmailPassword {
class EmailPasswordAuth {

/**
* Registers a new email identity with the username/password provider,
* Registers a new email identity with the email/password provider,
* and sends a confirmation email to the provided address.
*
* @param {string} email - The email address of the user to register.
* @param {string} password - The password that the user created for the new username/password identity.
* @returns {Promise<void>}
*/
registerEmail(email, password) { }
registerUser(email, password) { }

/**
* Confirms an email identity with the username/password provider.
* Confirms an email identity with the email/password provider.
*
* @param {string} token - The confirmation token that was emailed to the user.
* @param {string} id - The confirmation token id that was emailed to the user.
Expand Down Expand Up @@ -408,6 +408,17 @@ class EmailPassword {
* @returns {Promise<void>}
*/
resetPassword(password, token, id) { }

/**
* Resets the password of an email identity using the
* password reset function set up in the application.
*
* @param {string} email - The email address of the user.
* @param {string} password - The desired new password.
* @param {Array<BSON>} args - A bson array of arguments.
* @return {Promose<void>}
*/
callResetPasswordFunction(email, password, args) { }
}

/**
Expand All @@ -416,54 +427,54 @@ class EmailPassword {
* client should only be used by an authenticated user.
* @memberof Realm.Auth
*/
class APIKeys {
class ApiKeyAuth {

/**
* Creates a user API key that can be used to authenticate as the current user.
*
* @param {string} name - The name of the API key to be created.
* @returns {Promise<void>}
*/
createAPIKey(name) { }
create(name) { }

/**
* Fetches a user API key associated with the current user.
*
* @param {string} id - The id of the API key to fetch.
* @returns {Promise<Object>}
*/
fetchAPIKey(id) { }
fetch(id) { }

/**
* Fetches the user API keys associated with the current user.
*
* @returns {Promise<Array>}
*/
allAPIKeys() { }
fetchAll() { }

/**
* Deletes a user API key associated with the current user.
*
* @param {string} id - The id of the API key to delete.
* @returns {Promise<void>}
*/
deleteAPIKey(id) { }
delete(id) { }

/**
* Enables a user API key associated with the current user.
*
* @param {string} id - The id of the API key to enable.
* @returns {Promise<void>}
*/
enableAPIKey(id) { }
enable(id) { }

/**
* Disables a user API key associated with the current user.
*
* @param {string} id - The id of the API key to disable.
* @returns {Promise<void>}
*/
disableAPIKey(id) { }
disable(id) { }
}


Expand All @@ -477,14 +488,21 @@ class User {
* The identity is a guaranteed to be unique among all users on MongoDB Realm Cloud .
* @type {string}
*/
get identity() { }
get id() { }

/**
* Gets this user's access token. This is the user's credential for accessing the MongoDB
* Realm Cloud and should be treated as sensitive data.
* @type {string}
*/
get accessToken() { }

/**
* Gets this user's refresh token. This is the user's credential for accessing the MongoDB
* Realm Cloud and should be treated as sensitive data.
* @type {string}
*/
get token() { }
get refreshToken() { }

/**
* Gets this user's associated custom data. This is application-specific data provided by the server.
Expand Down Expand Up @@ -537,7 +555,7 @@ class User {

/**
* Returns a provider to interact with API keys.
* @return {Realm.Auth.APIKeys} - the provider
* @return {Realm.Auth.ApiKeyAuth} - the provider
*/
apiKeys() { }

Expand Down
24 changes: 12 additions & 12 deletions lib/user_apikey_provider_client.js → lib/api-key-auth-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@
const {promisify} = require("./utils.js");

const instanceMethods = {
createAPIKey(name) {
return promisify(cb => this._createAPIKey(name, cb));
create(name) {
return promisify(cb => this._create(name, cb));
},

fetchAPIKey(id) {
return promisify(cb => this._fetchAPIKey(id, cb));
fetch(id) {
return promisify(cb => this._fetch(id, cb));
},

fetchAPIKeys() {
return promisify(cb => this._fetchAPIKeys(cb));
fetchAll() {
return promisify(cb => this._fetchAll(cb));
},

deleteAPIKey(apiKeyId) {
return promisify(cb => this._deleteAPIKey(apiKeyId, cb));
delete(apiKeyId) {
return promisify(cb => this._delete(apiKeyId, cb));
},

enableAPIKey(apiKeyId) {
return promisify(cb => this._enableAPIKey(apiKeyId, cb));
enable(apiKeyId) {
return promisify(cb => this._enable(apiKeyId, cb));
},

disableAPIKey(apiKeyId) {
return promisify(cb => this._disableAPIKey(apiKeyId, cb));
disable(apiKeyId) {
return promisify(cb => this._disable(apiKeyId, cb));
},
};

Expand Down
11 changes: 0 additions & 11 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@ const instanceMethods = {
removeUser() {
return promisify(cb => this._removeUser(cb));
},

get auth() {
const app = this;
return new Proxy({}, {
get(target, name) {
if (name === "emailPassword") {
return app._authEmailPassword;
}
}
});
}
};

const staticMethods = {
Expand Down
6 changes: 4 additions & 2 deletions lib/browser/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ createMethods(User.prototype, objectTypes.USER, [
]);

Object.defineProperties(User.prototype, {
identity: { get: getterForProperty('identity') },
token: { get: getterForProperty('token') },
id: { get: getterForProperty('id') },
accessToken: { get: getterForProperty('accessToken') },
refreshToken: { get: getterForProperty('refreshToken') },
profile: { get: getterForProperty('profile') },
isLoggedIn: { get: getterForProperty('isLoggedIn') },
state: { get: getterForProperty('state') },
customData: { get: getterForProperty('customData') },
apiKeys: { get: getterForProperty('apiKeys') },
});

export function createUser(realmId, info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
//
////////////////////////////////////////////////////////////////////////////

'use strict';

const {promisify} = require("./utils.js");

const instanceMethods = {
registerEmail(email, password) {
return promisify(cb => this._registerEmail(email, password, cb));
registerUser(email, password) {
return promisify(cb => this._registerUser(email, password, cb));
},

confirmUser(token, token_id) {
Expand All @@ -38,8 +37,12 @@ const instanceMethods = {
},

resetPassword(password, token, token_id) {
return promisify(cb => this._sendResetPasswordEmail(password, token_id, token_id, cb));
}
return promisify(cb => this._resetPassword(password, token, token_id));
},

callResetPasswordFunction(email, password, bsonArgs) {
return promisify(cb => this._callResetPasswordFunction(email, password, bsonArgs));
},
};

const staticMethods = {
Expand Down
8 changes: 4 additions & 4 deletions lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ module.exports = function(realmConstructor, context) {
let credentialMethods = require("./credentials");
Object.defineProperties(realmConstructor.Credentials, getOwnPropertyDescriptors(credentialMethods.static))

let emailPasswordProviderMethods = require("./email_password_provider_client_methods");
Object.defineProperties(realmConstructor.Auth.EmailPasswordProvider.prototype, getOwnPropertyDescriptors(emailPasswordProviderMethods.instance));
let emailPasswordAuthMethods = require("./email-password-auth-methods");
Object.defineProperties(realmConstructor.Auth.EmailPasswordAuth.prototype, getOwnPropertyDescriptors(emailPasswordAuthMethods.instance));

let userAPIKeyProviderMethods = require("./user_apikey_provider_client");
Object.defineProperties(realmConstructor.Auth.UserAPIKeyProvider.prototype, getOwnPropertyDescriptors(userAPIKeyProviderMethods.instance));
let apiKeyAuthMethods = require("./api-key-auth-methods");
Object.defineProperties(realmConstructor.Auth.ApiKeyAuth.prototype, getOwnPropertyDescriptors(apiKeyAuthMethods.instance));


realmConstructor.Sync.AuthError = require("./errors").AuthError;
Expand Down
11 changes: 0 additions & 11 deletions lib/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,6 @@ const instanceMethods = {
get functions() {
return this._functionsOnService(undefined);
},

get auth() {
const user = this;
return new Proxy({}, {
get(target, name) {
if (name === "apiKeys") {
return user._authApiKeys;
}
}
});
}
}

const staticMethods = {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/realm-network-transport/.eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist/
/types/
1 change: 1 addition & 0 deletions packages/realm-network-transport/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export {
Method,
SuccessCallback,
ErrorCallback,
ResponseHandler,
} from "./NetworkTransport";
Loading

0 comments on commit fb9f1d1

Please sign in to comment.