Skip to content
This repository was archived by the owner on Jan 7, 2020. It is now read-only.
Open
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
7 changes: 7 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# safe_app nodejs Change Log

##

### Added

- `app.registredScheme` returns the registered scheme for a given app (if one was registered.)
- `suppressWarnings` added to optionally prevent experimental warnings.

## [0.10.3] - 13-12-2018

### Fixed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Any/all of them may be deprecated, removed, or very likely change in the future.
Also regular users won't have this APIs enabled by default unless the flag is provided, so be aware of all these limitations.
For more information, updates, or to submit ideas and suggestions, please visit https://github.com/maidsafe/safe_app_nodejs
```
Should you need, you can suppress these warnings by using the `--quietSafeApp` flag on the safe_app process, or by passing `suppressWarnings` with the `InitOptions` on `initialiseApp`.

## Further Help

Expand Down
15 changes: 15 additions & 0 deletions src/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,24 @@ class AuthInterface {
name: appInfo.name,
icon: 'test',
exec: appInfo.customExecPath }, scheme);

this.registeredAppScheme = scheme;
}
}

/**
* Whether or not this is a registered/authenticated session.
*
* @returns {Boolean} true if this is an authenticated session
*/
get registeredAppScheme() {
return this._registeredScheme;
}

set registeredAppScheme(scheme) {
this._registeredScheme = scheme;
}

/**
* Whether or not this is a registered/authenticated session.
*
Expand Down
5 changes: 5 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,18 @@ class SAFEApp extends EventEmitter {
registerScheme: true,
configPath: null,
forceUseMock: false,
suppressWarnings: false,
enableExperimentalApis: false,
}, options);

if (typeof this.options.forceUseMock !== 'boolean') {
throw new Error('The \'forceUseMock\' option must be a boolean.');
}

if (typeof this.options.suppressWarnings !== 'boolean') {
throw new Error('The \'suppressWarnings\' option must be a boolean.');
}

if (typeof this.options.enableExperimentalApis !== 'boolean') {
throw new Error('The \'enableExperimentalApis\' option must be a boolean.');
}
Expand Down
7 changes: 6 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const useMockByDefault = isTestEnv ? true : hasMockArg;
* APIs and start exploring and testing them as well as provide feedback for enhancements.
*/
const isExperimentalApisEnabled = process.argv.includes('--enable-experimental-apis');
const shouldNotLogWarnings = process.argv.includes('--quietSafeApp');

// Helper function to check the experimental APIs flag and
// either throw an error or log a warning message
Expand All @@ -53,7 +54,11 @@ function checkExperimentalApisFlag(fn) {
errConst.EXPERIMENTAL_API_DISABLED.msg(featureName));
}

if (this._warningLoggedAlready) return;
if (this._warningLoggedAlready ||
shouldNotLogWarnings ||
this.options.suppressWarnings) {
return;
}

console.warn(`
** Experimental API WARNING **
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ const { pubConsts: CONSTANTS } = require('./consts.js');
* holds the additional intialisation options for the App.
* @param {Boolean=} registerScheme to register auth scheme with the OS. Defaults to true.
* @param {Array=} joinSchemes to additionally register custom protocol schemes
* @param {Boolean=} log to enable or disable back end logging. Defaults to true.
* @param {Boolean=} log to enable or disable back end logging from Rust. Defaults to true.
* @param {String=} libPath path to the folder where the native libs can
* be found. Defaults to current folder path.
* @param {String=} configPath set additional search path for the config files.
* E.g. `log.toml` and `crust.config` files will be also searched not only
* in the same folder where the native library is, but also in this
* additional search path.
* @param {Boolean=} suppressWarnings prevent the application from logging any javascript
* warnings to the console. Defaults to false.
* @param {Boolean=} forceUseMock to force the use of mock routing regardless
* the NODE_ENV environment variable value. Defaults to false.
* @param {Boolean=} enableExperimentalApis to enable the experimental APIs
Expand Down
1 change: 1 addition & 0 deletions test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe('Smoke test', () => {
const optionsObject = {
log: false,
registerScheme: false,
suppressWarnings: false,
joinSchemes: ['proto'],
configPath: '/home',
forceUseMock: false,
Expand Down
7 changes: 6 additions & 1 deletion test/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ describe('auth interface', () => {
it('should build some containers uri if missing containers object', async () => {
const app = await h.createTestApp();
return app.auth.genContainerAuthUri()
.then((resp) => should(resp.uri).startWith('safe-auth:'));
.then((resp) => should(resp.uri)
.startWith('safe-auth:'));
});
it('should register a protocol scheme on the auth object if registering protocols', async () => {
const app = await h.createTestApp({}, null, { registerScheme: true });
should(app.auth.registeredAppScheme).startWith('safe-');
});

it('throws error if invalid container permission requested', async () => {
Expand Down