* integrate json-rpc repo https://github.com/deltachat/deltachat-jsonrpc * get target dir from cargo * fix clippy * use node 16 in ci use `npm i` instead of `npm ci` try fix ci script and fix a doc comment * fix get_provider_info docs * refactor function name * fix formatting make test pass fix clippy * update .gitignore * change now returns event names as id directly, no conversion method or number ids anymore also longer timeout for requesting test accounts from mailadm * fix compile after rebase * add json api to cffi and expose it in dc node * add some files to npm ignore that don't need to be in the npm package * add jsonrpc crate to set_core_version * add jsonrpc feature flag * call a jsonrpc function in segfault example * break loop on empty response * fix closing segfault thanks again to link2xt for figguring this out * activate other tests again * remove selectAccount from highlevel client * put jsonrpc stuff in own module * disable jsonrpc by default * add @deltachat/jsonrpc-client to make sure its dependencies are installed, too whwn installing dc-node * commit types.ts that dc-node has everything it needs to provide @deltachat/jsonrpc-client without an extra ts compile step * improve naming * Changes for tokio compat, upgrade to yerpc 0.3 This also changes the webserver binary to use axum in place of tide. * Improvements to typescript package * Improve docs. * improve docs, fix example * Fix CFFI for JSON-RPC changes * use stable toolchain not 1.56.0 * fix ci * try to fix ci * remove emtpy file allow unused code for new_from_arc * expose anyhow errors feature name was wrong * use multi-threaded runtime in JSON-RPC webserver * improve test setup and code style * don't wait for IO on webserver start * Bump yerpc to 0.3.1 with fix for axum server * update todo document remove specific api stuff for now, we now have the an incremental aproach on moving not the all at-once effort I though it would be * remove debug logs * changelog entry about the jsonrpc * Fix method name casings and cleanups * Improve JSON-RPC CI, no need to build things multiple times * Naming consistency: Use DeltaChat not Deltachat * Improve documentation * fix docs * adress dig's comments - description in cargo.toml - impl From<EventType> for EventTypeName - rename `CommandApi::new_from_arc` -> `CommandApi::from_arc` - pre-allocate if we know the entry count already - remove unused enumerate - remove unused serde attribute comment - rename `FullChat::from_dc_chat_id` -> `FullChat::try_from_dc_chat_id` * make it more idiomatic: rename `ContactObject::from_dc_contact -> `ContactObject::try_from_dc_contact` * apply link2xt's suggestions: - unref jsonrpc_instance in same thread it was created in - increase `max_queue_size` from 1 to 1000 * reintroduce segfault test script * remove unneeded context thanks to link2xt for pointing that out * Update deltachat-ffi/deltachat.h Co-authored-by: bjoern <r10s@b44t.com> * Update deltachat-ffi/deltachat.h Co-authored-by: bjoern <r10s@b44t.com> * make sure to use dc_str_unref instead of free on cstrings returned/owned by rust * Increase online test timeouts for CI * fix the typos thanks to ralphtheninja for finding them * restore same configure behaviour as desktop: make configure restart io with the old configuration if it had one on error * found another segfault: this time in batch_set_config * remove print from test * make dcn_json_rpc_request return undefined instead of not returning this might have been the cause for the second segfault * add set_config_from_qr to jsonrpc * add `add_device_message` to jsonrpc * jsonrpc: add `get_fresh_msgs` and `get_fresh_msg_cnt` * jsonrpc: add dm_chat_contact to ChatListItemFetchResult * add webxdc methods to jsonrpc: - `webxdc_send_status_update` - `webxdc_get_status_updates` - `message_get_webxdc_info` * add `chat_get_media` to jsonrpc also add viewtype wrapper enum and use it in `MessageObject`, additionally to using it in `chat_get_media` * use camelCase in all js object properties * Add check_qr function to jsonrpc * Fixed clippy errors and formatting * Fixed formatting * fix changelog ordering after rebase * fix compile after merging in master branch Co-authored-by: Simon Laux <mobile.info@simonlaux.de> Co-authored-by: Simon Laux <Simon-Laux@users.noreply.github.com> Co-authored-by: bjoern <r10s@b44t.com> Co-authored-by: flipsimon <28535045+flipsimon@users.noreply.github.com>
deltachat-node
node.js bindings for
deltachat-core-rust
deltachat-node primarily aims to offer two things:
- A high level JavaScript api with syntactic sugar
- A low level c binding api around
deltachat-core-rust
This code used to live at deltachat-node
Table of Contents
Click to expand
Install
By default the installation will build try to use the bundled prebuilds in the
npm package. If this fails it falls back to compile ../deltachat-core-rust from
this repository, using scripts/rebuild-core.js.
To install from npm use:
npm install deltachat-node
Dependencies
- Nodejs >=
v16.0.0 - rustup (optional if you can't use the prebuilds)
On Windows, you may need to also install Perl to be able to compile deltachat-core.
Build from source
If you want to build from source, make sure that you have rustup installed.
You can either use npm install deltachat-node --build-from-source to force
building from source or clone this repository and follow this steps:
git clone https://github.com/deltachat/deltachat-core-rust.gitcd deltachat-core-rustnpm inpm run build
Our
package.jsonfile is located in the root directory of this repository, not inside this folder. (We need this in order to include the rust source code in the npm package.)
Use a git branch in deltachat-desktop
You can directly install a core branch, but make sure:
- that you have typescript in your project dependencies, as it is likely required
- you know that there are no prebuilds and so core is built during installation which is why it takes so long
npm install https://github.com/deltachat/deltachat-core-rust.git#branch
If you want prebuilds for a branch that has a core pr, you might find an npm tar.gz package for that branch at https://download.delta.chat/node/preview/. The github ci also posts a link to it in the checks for each pr.
Use build-from-source in deltachat-desktop
If you want to use the manually built node bindings in the desktop client (for example), you can follow these instructions:
First clone the
deltachat-desktop repository,
e.g. with git clone https://github.com/deltachat/deltachat-desktop.
Then you need to make sure that this directory is referenced correctly in
deltachat-desktop's package.json. You need to change
deltachat-desktop/package.json like this:
diff --git i/package.json w/package.json
index 45893894..5154512c 100644
--- i/package.json
+++ w/package.json
@@ -83,7 +83,7 @@
"application-config": "^1.0.1",
"classnames": "^2.3.1",
"debounce": "^1.2.0",
- "deltachat-node": "1.79.3",
+ "deltachat-node": "file:../deltachat-core-rust/",
"emoji-js-clean": "^4.0.0",
"emoji-mart": "^3.0.1",
"emoji-regex": "^9.2.2",
Then, in the deltachat-desktop repository, run:
npm inpm run build- And
npm run startto start the newly built client.
Workaround to build for x86_64 on Apple's M1
deltachat doesn't support universal (fat) binaries (that contain builds for both cpu architectures) yet, until it does you can use the following workaround to get x86_64 builds:
$ fnm install 17 --arch x64
$ fnm use 17
$ node -p process.arch
# result should be x64
$ rustup target add x86_64-apple-darwin
$ git apply patches/m1_build_use_x86_64.patch
$ CARGO_BUILD_TARGET=x86_64-apple-darwin npm run build
$ npm run test
(when using fnm instead of nvm, you can select the architecture) If your node and electron are already build for arm64 you can also try bulding for arm:
$ fnm install 16 --arch arm64
$ fnm use 16
$ node -p process.arch
# result should be arm64
$ npm_config_arch=arm64 npm run build
$ npm run test
Usage
const { Context } = require('deltachat-node')
const opts = {
addr: '[email]',
mail_pw: '[password]',
}
const contact = '[email]'
async function main() {
const dc = Context.open('./')
dc.on('ALL', console.log.bind(null, 'core |'))
try {
await dc.configure(opts)
} catch (err) {
console.error('Failed to configure because of: ', err)
dc.unref()
return
}
dc.startIO()
console.log('fully configured')
const contactId = dc.createContact('Test', contact)
const chatId = dc.createChatByContactId(contactId)
dc.sendMessage(chatId, 'Hi!')
console.log('sent message')
dc.once('DC_EVENT_SMTP_MESSAGE_SENT', async () => {
console.log('Message sent, shutting down...')
dc.stopIO()
console.log('stopped io')
dc.unref()
})
}
main()
this example can also be found in the examples folder examples/send_message.js
Generating Docs
We are curently migrating to automaticaly generated documentation. You can find the old documentation at old_docs.
to generate the documentation, run:
npx typedoc
The resulting documentation can be found in the docs/ folder.
An online version can be found under js.delta.chat.
Developing
Tests and Coverage
Running npm test ends with showing a code coverage report, which is produced by nyc.
The coverage report from nyc in the console is rather limited. To get a more detailed coverage report you can run npm run coverage-html-report. This will produce a html report from the nyc data and display it in a browser on your local machine.
To run the integration tests you need to set the DCC_NEW_TMP_EMAIL environment variables. E.g.:
$ export DCC_NEW_TMP_EMAIL=https://testrun.org/new_email?t=[token]
$ npm run test
Scripts
We have the following scripts for building, testing and coverage:
npm run coverageCreates a coverage report and passes it tocoveralls. Only done byTravis.npm run coverage-html-reportGenerates a html report from the coverage data and opens it in a browser on the local machine.npm run generate-constantsGeneratesconstants.jsandevents.jsbased on thedeltachat-core-rust/deltachat-ffi/deltachat.hheader file.npm installAfter dependencies are installed, runsnode-gyp-buildto see if the native code needs to be rebuilt.npm run buildRebuilds all code.npm run build:coreRebuilds code indeltachat-core-rust.npm run build:bindingsRebuilds the bindings and links withdeltachat-core-rust.ǹpm run cleanRemoves all built codenpm run prebuildifyBuilds prebuilt binary toprebuilds/$PLATFORM-$ARCH. Copiesdeltachat.dllfromdeltachat-core-rustfor windows.npm run download-prebuildsDownloads all prebuilt binaries from github beforenpm publish.npm testRunsstandardand then the tests intest/index.js.npm run test-integrationRuns the integration tests.npm run hallmarkRunshallmarkon all markdown files.
Releases
The following steps are needed to make a release:
- Wait until
pack-modulegithub action is completed - Run
npm publish https://download.delta.chat/node/deltachat-node-1.x.x.tar.gzto publish it to npm. You probably need write rights to npm.
License
Licensed under GPL-3.0-or-later, see LICENSE file for details.
Copyright © 2018
DeltaChatcontributors.This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
