![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
mage-sdk-node
Advanced tools
This is a MAGE client written in pure ES6, it should be compatible with Node 5.x and should also run in the browser if built through a tool like Babel.
npm i mage-sdk-node --save
At least NodeJS 6.x
const Mage = require('mage-sdk-node')
const config = require('./my-mage-config')
const client = new Mage(config)
// mage commands are now promises so they can be chained
client.user.register()
.then(() => {
// do game/app logic
})
.catch(error => {
console.error(error);
process.exit(1);
});
If async/await is available, the code above can be rewritten as follow:
const Mage = require('mage-sdk-node')
const config = require('./my-mage-config')
try {
// create the mage client
const client = new Mage(config)
// register a guest user and join a game
await client.user.register();
const game = await client.game.join();
doSomething(game);
} catch (error) {
console.error(error);
}
You will need to extract your client configuration from your mage project, to do
so create a javascript file at the root of your project (ie. config.js
) with
the following content:
const mage = require('./lib');
console.log(JSON.stringify(mage.getClientConfig('api'), null, 4));
Then run it with node, a JSON object should get output in your console, this is
your node config and can be used to instanciate the Mage
class.
It could for example be saved in a file called config/production.js
in your
client project using this format:
module.exports = {
/* json configuration */
}
That way you can easily require it in your project.
When the mage client finish initializing, you should be able to run client.{module}.{command} for each user command set on the server, those calls will return a promise.
constructor(config: MageClientConfig)
The Mage client config can be extracted from your server by running the command described above.
get archivist
The archivist instance.
get commands
Returns the Command Center.
get session
Returns the current session.
set session
Sets the current session, must be a Session object.
get stream
Returns the message stream.
close() -> void
Closes all connections to the server.
{module}.{command}(any ...params) -> Promise(any)
Wrappers for CommandCenter.send
.
get cache
Returns the underlying cache (defaults to Memory).
exists(string topic, Object index[, Object options]) -> Promise(boolean)
Checks if the given value exists.
get(string topic, Object index[, Object options]) -> Promise(any)
Retrieve a value from the server, unless cached locally.
list(string topic, Object partialIndex[, Object options]) -> Promise(any[])
List objects on the server using a partial index.
mget(Object|Object[] queries[, Object options]) -> Promise(Object|any[])
Run multiple gets on the server in one go.
event {topic}(string operation, Object index[, any value])
Whenether set
, applyDiff
or del
operations are run, emit an event for the topic.
set cookies
Set a cookie jar for use with the command center.
registerHook(string name, Function hook)
Register a hook with the command center, when hooks are called they should return an object that will then be set as a header to the current call.
unregisterHook(string name)
Remove a hook.
send(string cmdName, any[] params) -> Promise(any)
Call the command center, returns a promise and queue the command, the promise only resolves once the queue goes through.
MIT
FAQs
Mage client for Node.js
The npm package mage-sdk-node receives a total of 1 weekly downloads. As such, mage-sdk-node popularity was classified as not popular.
We found that mage-sdk-node demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.