Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
x.x.x Release notes (yyyy-MM-dd)
=============================================================
NOTE: Support for syncing with realm.cloud.io and/or Realm Object Server has been replaced with support for syncing with MongoDB Realm Cloud.

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.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`.

### Enhancements
* None.

### Fixed
* None.

### Compatibility
* MongoDB Realm Cloud.
* APIs are backwards compatible with all previous releases of Realm JavaScript in the 10.x.y series.
* File format: generates Realms with format v11 (reads and upgrades file format v5 or later).

### Internal
* None.

10.0.0-beta.8 Release notes (2020-7-07)
=============================================================
NOTE: Support for syncing with realm.cloud.io and/or Realm Object Server has been replaced with support for syncing with MongoDB Realm Cloud.
Expand Down
16 changes: 8 additions & 8 deletions docs/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,54 +408,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 Down Expand Up @@ -528,7 +528,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
1 change: 1 addition & 0 deletions lib/browser/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Object.defineProperties(User.prototype, {
isLoggedIn: { get: getterForProperty('isLoggedIn') },
state: { get: getterForProperty('state') },
customData: { get: getterForProperty('customData') },
apiKeys: { get: getterForProperty('apiKeys') },
});

export function createUser(realmId, info) {
Expand Down
4 changes: 2 additions & 2 deletions lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ module.exports = function(realmConstructor, context) {
let emailPasswordProviderMethods = require("./email_password_provider_client_methods");
Object.defineProperties(realmConstructor.Auth.EmailPasswordProvider.prototype, getOwnPropertyDescriptors(emailPasswordProviderMethods.instance));

let userAPIKeyProviderMethods = require("./user_apikey_provider_client");
Object.defineProperties(realmConstructor.Auth.UserAPIKeyProvider.prototype, getOwnPropertyDescriptors(userAPIKeyProviderMethods.instance));
let apiKeyAuthMethods = require("./user_apikey_provider_client");
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 @@ -95,17 +95,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
24 changes: 12 additions & 12 deletions lib/user_apikey_provider_client.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
4 changes: 2 additions & 2 deletions src/RealmJS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
42BD57AB24640A94008679D5 /* js_user.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = js_user.hpp; sourceTree = "<group>"; };
42BD57AC24640A94008679D5 /* js_network_transport.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = js_network_transport.hpp; sourceTree = "<group>"; };
42BD57AD24640A95008679D5 /* js_sync_util.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = js_sync_util.hpp; sourceTree = "<group>"; };
42BD57AE24640A95008679D5 /* js_user_apikey_provider.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = js_user_apikey_provider.hpp; sourceTree = "<group>"; };
42BD57AE24640A95008679D5 /* js_api_key_auth.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = js_api_key_auth.hpp; sourceTree = "<group>"; };
42BD57AF24640AA8008679D5 /* keypath_helpers.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = keypath_helpers.hpp; path = src/keypath_helpers.hpp; sourceTree = "<group>"; };
42BD57B024640AE4008679D5 /* generic_network_transport.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = generic_network_transport.hpp; path = src/sync/generic_network_transport.hpp; sourceTree = "<group>"; };
42BD57B124640AE4008679D5 /* app_credentials.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = app_credentials.hpp; path = src/sync/app_credentials.hpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -360,7 +360,7 @@
42BD57A824640A94008679D5 /* js_app.hpp */,
42BD57AC24640A94008679D5 /* js_network_transport.hpp */,
42BD57AD24640A95008679D5 /* js_sync_util.hpp */,
42BD57AE24640A95008679D5 /* js_user_apikey_provider.hpp */,
42BD57AE24640A95008679D5 /* js_api_key_auth.hpp */,
42BD57AB24640A94008679D5 /* js_user.hpp */,
42BD57AA24640A94008679D5 /* js_email_password_provider.hpp */,
F62A35131C18E6E2004A917D /* iOS */,
Expand Down
60 changes: 30 additions & 30 deletions src/js_user_apikey_provider.hpp → src/js_api_key_auth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ using SharedUser = std::shared_ptr<realm::SyncUser>;
using SharedApp = std::shared_ptr<realm::app::App>;

template<typename T>
class UserAPIKeyProviderClient : public app::App::UserAPIKeyProviderClient {
class ApiKeyAuth : public app::App::UserAPIKeyProviderClient {
public:
UserAPIKeyProviderClient(app::App::UserAPIKeyProviderClient client, SharedUser user) : app::App::UserAPIKeyProviderClient(client), m_user(std::move(user)) {}
UserAPIKeyProviderClient(UserAPIKeyProviderClient &&) = default;
ApiKeyAuth(app::App::UserAPIKeyProviderClient client, SharedUser user) : app::App::UserAPIKeyProviderClient(client), m_user(std::move(user)) {}
ApiKeyAuth(ApiKeyAuth &&) = default;

UserAPIKeyProviderClient& operator=(UserAPIKeyProviderClient &&) = default;
UserAPIKeyProviderClient& operator=(UserAPIKeyProviderClient const&) = default;
ApiKeyAuth& operator=(ApiKeyAuth &&) = default;
ApiKeyAuth& operator=(ApiKeyAuth const&) = default;

SharedUser m_user;
};

template<typename T>
class UserAPIKeyProviderClientClass : public ClassDefinition<T, UserAPIKeyProviderClient<T>> {
class ApiKeyAuthClass : public ClassDefinition<T, ApiKeyAuth<T>> {
using GlobalContextType = typename T::GlobalContext;
using ContextType = typename T::Context;
using FunctionType = typename T::Function;
Expand All @@ -55,7 +55,7 @@ class UserAPIKeyProviderClientClass : public ClassDefinition<T, UserAPIKeyProvid
using Arguments = js::Arguments<T>;

public:
std::string const name = "UserAPIKeyProviderClient";
std::string const name = "ApiKeyAuth";

static FunctionType create_constructor(ContextType);
static ObjectType create_instance(ContextType, SharedApp, SharedUser);
Expand All @@ -65,30 +65,30 @@ class UserAPIKeyProviderClientClass : public ClassDefinition<T, UserAPIKeyProvid

static void create_api_key(ContextType, ObjectType, Arguments&, ReturnValue&);
static void fetch_api_key(ContextType, ObjectType, Arguments&, ReturnValue&);
static void fetch_api_keys(ContextType, ObjectType, Arguments&, ReturnValue&);
static void fetch_all_api_keys(ContextType, ObjectType, Arguments&, ReturnValue&);
static void delete_api_key(ContextType, ObjectType, Arguments&, ReturnValue&);
static void enable_api_key(ContextType, ObjectType, Arguments&, ReturnValue&);
static void disable_api_key(ContextType, ObjectType, Arguments&, ReturnValue&);

MethodMap<T> const methods = {
{"_createAPIKey", wrap<create_api_key>},
{"_fetchAPIKey", wrap<fetch_api_key>},
{"_fetchAPIKeys", wrap<fetch_api_keys>},
{"_deleteAPIKey", wrap<delete_api_key>},
{"_enableAPIKey", wrap<enable_api_key>},
{"_disableAPIKey", wrap<disable_api_key>},
{"_create", wrap<create_api_key>},
{"_fetch", wrap<fetch_api_key>},
{"_fetchAll", wrap<fetch_all_api_keys>},
{"_delete", wrap<delete_api_key>},
{"_enable", wrap<enable_api_key>},
{"_disable", wrap<disable_api_key>},
};
};

template<typename T>
inline typename T::Function UserAPIKeyProviderClientClass<T>::create_constructor(ContextType ctx) {
FunctionType constructor = ObjectWrap<T, UserAPIKeyProviderClientClass<T>>::create_constructor(ctx);
inline typename T::Function ApiKeyAuthClass<T>::create_constructor(ContextType ctx) {
FunctionType constructor = ObjectWrap<T, ApiKeyAuthClass<T>>::create_constructor(ctx);
return constructor;
}

template<typename T>
typename T::Object UserAPIKeyProviderClientClass<T>::create_instance(ContextType ctx, SharedApp app, SharedUser user) {
return create_object<T, UserAPIKeyProviderClientClass<T>>(ctx, new UserAPIKeyProviderClient<T>(app->provider_client<realm::app::App::UserAPIKeyProviderClient>(), user));
typename T::Object ApiKeyAuthClass<T>::create_instance(ContextType ctx, SharedApp app, SharedUser user) {
return create_object<T, ApiKeyAuthClass<T>>(ctx, new ApiKeyAuth<T>(app->provider_client<realm::app::App::UserAPIKeyProviderClient>(), user));
}

template<typename T>
Expand All @@ -107,10 +107,10 @@ typename T::Object make_api_key(typename T::Context ctx, util::Optional<app::App
}

template<typename T>
void UserAPIKeyProviderClientClass<T>::create_api_key(ContextType ctx, ObjectType this_object, Arguments& args, ReturnValue& return_value) {
void ApiKeyAuthClass<T>::create_api_key(ContextType ctx, ObjectType this_object, Arguments& args, ReturnValue& return_value) {
args.validate_count(2);

auto& client = *get_internal<T, UserAPIKeyProviderClientClass<T>>(ctx, this_object);
auto& client = *get_internal<T, ApiKeyAuthClass<T>>(ctx, this_object);

auto name = Value::validated_to_string(ctx, args[0], "name");
auto callback = Value::validated_to_function(ctx, args[1], "callback");
Expand Down Expand Up @@ -144,10 +144,10 @@ void UserAPIKeyProviderClientClass<T>::create_api_key(ContextType ctx, ObjectTyp
}

template<typename T>
void UserAPIKeyProviderClientClass<T>::fetch_api_key(ContextType ctx, ObjectType this_object, Arguments& args, ReturnValue& return_value) {
void ApiKeyAuthClass<T>::fetch_api_key(ContextType ctx, ObjectType this_object, Arguments& args, ReturnValue& return_value) {
args.validate_count(2);

auto& client = *get_internal<T, UserAPIKeyProviderClientClass<T>>(ctx, this_object);
auto& client = *get_internal<T, ApiKeyAuthClass<T>>(ctx, this_object);

auto id = Value::validated_to_object_id(ctx, args[0], "id");
auto callback = Value::validated_to_function(ctx, args[1], "callback");
Expand Down Expand Up @@ -181,10 +181,10 @@ void UserAPIKeyProviderClientClass<T>::fetch_api_key(ContextType ctx, ObjectType
}

template<typename T>
void UserAPIKeyProviderClientClass<T>::fetch_api_keys(ContextType ctx, ObjectType this_object, Arguments& args, ReturnValue& return_value) {
void ApiKeyAuthClass<T>::fetch_all_api_keys(ContextType ctx, ObjectType this_object, Arguments& args, ReturnValue& return_value) {
args.validate_count(1);

auto& client = *get_internal<T, UserAPIKeyProviderClientClass<T>>(ctx, this_object);
auto& client = *get_internal<T, ApiKeyAuthClass<T>>(ctx, this_object);
auto callback = Value::validated_to_function(ctx, args[0], "callback");

Protected<typename T::GlobalContext> protected_ctx(Context<T>::get_global_context(ctx));
Expand Down Expand Up @@ -255,10 +255,10 @@ app::App::UserAPIKey to_api_key(typename T::Context ctx, typename T::Object api_
}

template<typename T>
void UserAPIKeyProviderClientClass<T>::delete_api_key(ContextType ctx, ObjectType this_object, Arguments& args, ReturnValue& return_value) {
void ApiKeyAuthClass<T>::delete_api_key(ContextType ctx, ObjectType this_object, Arguments& args, ReturnValue& return_value) {
args.validate_count(2);

auto& client = *get_internal<T, UserAPIKeyProviderClientClass<T>>(ctx, this_object);
auto& client = *get_internal<T, ApiKeyAuthClass<T>>(ctx, this_object);

auto api_key_id = Value::validated_to_object_id(ctx, args[0], "API key id");
auto callback = Value::validated_to_function(ctx, args[1], "callback");
Expand All @@ -267,10 +267,10 @@ void UserAPIKeyProviderClientClass<T>::delete_api_key(ContextType ctx, ObjectTyp
}

template<typename T>
void UserAPIKeyProviderClientClass<T>::enable_api_key(ContextType ctx, ObjectType this_object, Arguments& args, ReturnValue& return_value) {
void ApiKeyAuthClass<T>::enable_api_key(ContextType ctx, ObjectType this_object, Arguments& args, ReturnValue& return_value) {
args.validate_count(2);

auto& client = *get_internal<T, UserAPIKeyProviderClientClass<T>>(ctx, this_object);
auto& client = *get_internal<T, ApiKeyAuthClass<T>>(ctx, this_object);

auto api_key_id = Value::validated_to_object_id(ctx, args[0], "API key id");
auto callback = Value::validated_to_function(ctx, args[1], "callback");
Expand All @@ -279,10 +279,10 @@ void UserAPIKeyProviderClientClass<T>::enable_api_key(ContextType ctx, ObjectTyp
}

template<typename T>
void UserAPIKeyProviderClientClass<T>::disable_api_key(ContextType ctx, ObjectType this_object, Arguments& args, ReturnValue& return_value) {
void ApiKeyAuthClass<T>::disable_api_key(ContextType ctx, ObjectType this_object, Arguments& args, ReturnValue& return_value) {
args.validate_count(2);

auto& client = *get_internal<T, UserAPIKeyProviderClientClass<T>>(ctx, this_object);
auto& client = *get_internal<T, ApiKeyAuthClass<T>>(ctx, this_object);

auto api_key_id = Value::validated_to_object_id(ctx, args[0], "API key id");
auto callback = Value::validated_to_function(ctx, args[1], "callback");
Expand Down
6 changes: 3 additions & 3 deletions src/js_realm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "js_auth.hpp"
#include "js_app_credentials.hpp"
#include "js_email_password_provider.hpp"
#include "js_user_apikey_provider.hpp"
#include "js_api_key_auth.hpp"
#include "sync/async_open_task.hpp"
#include "sync/sync_config.hpp"
#include "sync/sync_manager.hpp"
Expand Down Expand Up @@ -470,8 +470,8 @@ inline typename T::Function RealmClass<T>::create_constructor(ContextType ctx) {
FunctionType email_password_provider_client_constructor = EmailPasswordProviderClientClass<T>::create_constructor(ctx);
Object::set_property(ctx, auth_constructor, "EmailPasswordProvider", email_password_provider_client_constructor, attributes);

FunctionType user_apikey_provider_client_constructor = UserAPIKeyProviderClientClass<T>::create_constructor(ctx);
Object::set_property(ctx, auth_constructor, "UserAPIKeyProvider", user_apikey_provider_client_constructor, attributes);
FunctionType user_apikey_provider_client_constructor = ApiKeyAuthClass<T>::create_constructor(ctx);
Object::set_property(ctx, auth_constructor, "ApiKeyAuth", user_apikey_provider_client_constructor, attributes);
#endif

if (getenv("REALM_DISABLE_SYNC_TO_DISK")) {
Expand Down
Loading