Constructor
new SAFEApp(appInfo, networkStateCallBackopt, optionsopt)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
appInfo |
AppInfo | |||
networkStateCallBack |
function |
<optional> |
null |
optional callback function to receive network state updates |
options |
InitOptions |
<optional> |
initilalisation options |
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const networkStateCallback = (state) => {
console.log('Network state change event: ', state);
};
const initialisationOptions = {
log : true,
registerScheme : false
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(
appInfo,
networkStateCallBack,
initialisationOptions
);
} catch (err) {
throw err;
}
};
Members
appInfo
Returns the AppInfo used to initialise current app.
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const appInfo = app.appInfo;
} catch(err) {
throw err;
}
};
auth
Get an AuthInterface instance
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const auth = app.auth;
} catch (err) {
throw err;
}
};
cipherOpt
Get a CipherOptInterface interface
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const cipherOpt = app.cipherOpt;
} catch (err) {
throw err;
}
};
connection
Returns pointer to current connection object held in memory.
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const connection = app.connection;
} catch(err) {
throw err;
}
};
crypto
Get a CryptoInterface interface
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const crypto = app.crypto;
} catch (err) {
throw err;
}
};
immutableData
Get an ImmutableDataInterface
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const immutableData = app.immutableData;
} catch (err) {
throw err;
}
};
mutableData
Get a MutableDataInterface
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const mutableData = app.mutableData;
} catch (err) {
throw err;
}
};
networkState
Textual representation of the current network connection state.
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const networkState = app.networkState;
} catch(err) {
throw err;
}
};
web
Get a WebInterface interface
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const web = app.web;
} catch (err) {
throw err;
}
};
Methods
appIsMock() → {Boolean}
Returns true if the underlyging library was compiled against mock routing.
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const isMock = await app.appIsMock();
} catch(err) {
throw err;
}
};
clearObjectCache() → {Promise}
Resets the object cache kept by the underlying library.
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
await app.clearObjectCache();
} catch(err) {
throw err;
}
};
fetch(url) → {Promise.<NetworkResource>}
Experimental function to lookup a given safe://
-URL in accordance with the
public name resolution and find the requested network resource.
Parameters:
Name | Type | Description |
---|---|---|
url |
String |
the url you want to fetch |
Throws:
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
// If you have an XOR-URL with a type tag, and therefore represents MutableData,
// use this operation to fetch an interface to the underlying data structure.
try {
const app = await safe.initialiseApp(appInfo);
const unRegisteredUri = await app.auth.genConnUri();
await app.auth.loginFromUri(unRegisteredUri);
const data = await app.fetch(
'safe://hyfktcerbwpctjz6ws8468hncw1ddpzrz65z3mapzx9wr413r7gj3w6yt5y:15001'
);
} catch(err) {
throw err;
}
};
getAccountInfo() → {Promise.<AccountInfo>}
Returns account information, specifically, number of mutations done and available.
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const getAccountInfo = await app.getAccountInfo();
} catch(err) {
throw err;
}
};
getOwnContainerName() → {Promise.<String>}
Returns the name of the app's own container.
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const rootContainerName = await app.getOwnContainerName();
} catch(err) {
throw err;
}
};
isNetStateConnected() → {Boolean}
Returns true if current network connection state is CONNECTED.
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const isNetStateConnected = app.isNetStateConnected();
} catch(err) {
throw err;
}
};
isNetStateDisconnected() → {Boolean}
Returns true if current network connection state is DISCONNECTED.
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const isNetStateDisconnected = app.isNetStateDisconnected();
} catch(err) {
throw err;
}
};
isNetStateInit() → {Boolean}
Returns true if current network connection state is INIT. This is state means the library has been initialised but there is no connection made with the network yet.
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const isNetStateInit = app.isNetStateInit();
} catch(err) {
throw err;
}
};
logPath(logFilenameopt) → {Promise.<String>}
Generate the log path for the provided filename. If the filename provided is null, it then returns the path of where the safe_core log file is located.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
logFilename |
String |
<optional> |
optional log filename to generate the path |
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
const logPath = await app.logPath();
} catch(err) {
throw err;
}
};
reconnect() → {Promise}
Reconnect to the network. Must be invoked when the client decides to connect back after the connection was lost.
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
try {
const app = await safe.initialiseApp(appInfo);
await app.reconnect();
} catch(err) {
throw err;
}
};
webFetch(url, optionsopt) → {Promise.<{body: Buffer, headers: Object}>}
Function to lookup a given safe://
-URL in accordance with the
public name resolution and find the requested network resource.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
url |
String |
the url you want to fetch |
||
options |
WebFetchOptions |
<optional> |
null |
additional options |
Throws:
Example
const safe = require( '@maidsafe/safe-node-app' );
const appInfo = {
id : 'net.maidsafe.example',
name : 'Example SAFE App',
vendor : 'MaidSafe.net Ltd'
};
const asyncFn = async () => {
const app = await safe.initialiseApp(appInfo);
const unRegisteredUri = await app.auth.genConnUri();
await app.auth.loginFromUri(unRegisteredUri);
const webFetchOptions = {
range: {
start:safe.CONSTANTS.NFS_FILE_START,
end: safe.CONSTANTS.NFS_FILE_END
}
};
try {
const data = await app.webFetch(
'safe://home.safenetwork',
webFetchOptions
);
// Alternatively, fetch an ImmutableData XOR-URL such as:
// safe://hygkdkftyhkmzma5cjwgcghws9hyorcucqyqna1uaje68hyquah7nd9kh3rjy
} catch(err) {
throw err;
}
};