Skip to content
This repository was archived by the owner on Jun 7, 2026. It is now read-only.
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
182 changes: 182 additions & 0 deletions .github/workflows/publish-privitty-deltachat-rpc-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# Build deltachat-rpc-server from branch deskstop-core (Privitty/core) and publish to npm as @privitty/deltachat-rpc-server

name: Publish @privitty/deltachat-rpc-server

concurrency:
group: publish-privitty-rpc-${{ github.ref }}
cancel-in-progress: true

on:
push:
branches: [desktop-core]
workflow_dispatch:
inputs:
branch:
description: "Branch to build from"
required: false
default: "desktop-core"

permissions: {}

jobs:
build_linux:
name: Linux
strategy:
fail-fast: false
matrix:
arch: [aarch64, armv7l, armv6l, i686, x86_64]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

Check failure on line 30 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
ref: ${{ github.event.inputs.branch || github.ref }}
show-progress: false
persist-credentials: false
- uses: DeterminateSystems/nix-installer-action@main

Check failure on line 35 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
- name: Build deltachat-rpc-server binaries
run: nix build .#deltachat-rpc-server-${{ matrix.arch }}-linux
- name: Upload binary
uses: actions/upload-artifact@v4

Check failure on line 39 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
name: deltachat-rpc-server-${{ matrix.arch }}-linux
path: result/bin/deltachat-rpc-server
if-no-files-found: error

build_windows:
name: Windows
strategy:
fail-fast: false
matrix:
arch: [win32, win64]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

Check failure on line 53 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
ref: ${{ github.event.inputs.branch || github.ref }}
show-progress: false
persist-credentials: false
- uses: DeterminateSystems/nix-installer-action@main

Check failure on line 58 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
- name: Build deltachat-rpc-server binaries
run: nix build .#deltachat-rpc-server-${{ matrix.arch }}
- name: Upload binary
uses: actions/upload-artifact@v4

Check failure on line 62 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
name: deltachat-rpc-server-${{ matrix.arch }}
path: result/bin/deltachat-rpc-server.exe
if-no-files-found: error

build_macos:
name: macOS
strategy:
fail-fast: false
matrix:
arch: [x86_64, aarch64]
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

Check failure on line 76 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
ref: ${{ github.event.inputs.branch || github.ref }}
show-progress: false
persist-credentials: false
- name: Setup rust target
run: rustup target add ${{ matrix.arch }}-apple-darwin
- name: Build
run: cargo build --release --package deltachat-rpc-server --target ${{ matrix.arch }}-apple-darwin --features vendored
- name: Upload binary
uses: actions/upload-artifact@v4

Check failure on line 86 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
name: deltachat-rpc-server-${{ matrix.arch }}-macos
path: target/${{ matrix.arch }}-apple-darwin/release/deltachat-rpc-server
if-no-files-found: error

publish_npm:
name: Pack and publish @privitty/deltachat-rpc-server
needs: [build_linux, build_windows, build_macos]
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4

Check failure on line 100 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
ref: ${{ github.event.inputs.branch || github.ref }}
show-progress: false
persist-credentials: false
- uses: actions/setup-python@v5

Check failure on line 105 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
python-version: "3.11"

- name: Download Linux binaries
uses: actions/download-artifact@v4

Check failure on line 110 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
name: deltachat-rpc-server-aarch64-linux
path: deltachat-rpc-server-aarch64-linux.d
- name: Download Linux armv7l
uses: actions/download-artifact@v4

Check failure on line 115 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
name: deltachat-rpc-server-armv7l-linux
path: deltachat-rpc-server-armv7l-linux.d
- name: Download Linux armv6l
uses: actions/download-artifact@v4

Check failure on line 120 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
name: deltachat-rpc-server-armv6l-linux
path: deltachat-rpc-server-armv6l-linux.d
- name: Download Linux i686
uses: actions/download-artifact@v4

Check failure on line 125 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
name: deltachat-rpc-server-i686-linux
path: deltachat-rpc-server-i686-linux.d
- name: Download Linux x86_64
uses: actions/download-artifact@v4

Check failure on line 130 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
name: deltachat-rpc-server-x86_64-linux
path: deltachat-rpc-server-x86_64-linux.d
- name: Download Win32
uses: actions/download-artifact@v4

Check failure on line 135 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
name: deltachat-rpc-server-win32
path: deltachat-rpc-server-win32.d
- name: Download Win64
uses: actions/download-artifact@v4

Check failure on line 140 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
name: deltachat-rpc-server-win64
path: deltachat-rpc-server-win64.d
- name: Download macOS x86_64
uses: actions/download-artifact@v4

Check failure on line 145 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
name: deltachat-rpc-server-x86_64-macos
path: deltachat-rpc-server-x86_64-macos.d
- name: Download macOS aarch64
uses: actions/download-artifact@v4

Check failure on line 150 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
name: deltachat-rpc-server-aarch64-macos
path: deltachat-rpc-server-aarch64-macos.d

- name: Make npm packages for @privitty/deltachat-rpc-server
run: |
cd deltachat-rpc-server/npm-package-privitty
python scripts/pack_binary_for_platform.py aarch64-unknown-linux-musl ../../deltachat-rpc-server-aarch64-linux.d/deltachat-rpc-server
python scripts/pack_binary_for_platform.py armv7-unknown-linux-musleabihf ../../deltachat-rpc-server-armv7l-linux.d/deltachat-rpc-server
python scripts/pack_binary_for_platform.py arm-unknown-linux-musleabihf ../../deltachat-rpc-server-armv6l-linux.d/deltachat-rpc-server
python scripts/pack_binary_for_platform.py i686-unknown-linux-musl ../../deltachat-rpc-server-i686-linux.d/deltachat-rpc-server
python scripts/pack_binary_for_platform.py x86_64-unknown-linux-musl ../../deltachat-rpc-server-x86_64-linux.d/deltachat-rpc-server
python scripts/pack_binary_for_platform.py i686-pc-windows-gnu ../../deltachat-rpc-server-win32.d/deltachat-rpc-server.exe
python scripts/pack_binary_for_platform.py x86_64-pc-windows-gnu ../../deltachat-rpc-server-win64.d/deltachat-rpc-server.exe
python scripts/pack_binary_for_platform.py x86_64-apple-darwin ../../deltachat-rpc-server-x86_64-macos.d/deltachat-rpc-server
python scripts/pack_binary_for_platform.py aarch64-apple-darwin ../../deltachat-rpc-server-aarch64-macos.d/deltachat-rpc-server
ls -la platform_package
for platform in ./platform_package/*; do npm pack "$platform"; done
npm pack
ls -la *.tgz

- uses: actions/setup-node@v4

Check failure on line 172 in .github/workflows/publish-privitty-deltachat-rpc-server.yml

View check run for this annotation

GitHub Advanced Security / zizmor

unpinned action reference
with:
node-version: 20
registry-url: "https://registry.npmjs.org"

- name: Publish @privitty/deltachat-rpc-server to npm
working-directory: deltachat-rpc-server/npm-package-privitty
run: |
for f in *.tgz; do npm publish --provenance "$f" --access public; done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 3 additions & 0 deletions deltachat-rpc-server/npm-package-privitty/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
platform_package/*
scripts/
*.tgz
19 changes: 19 additions & 0 deletions deltachat-rpc-server/npm-package-privitty/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @privitty/deltachat-rpc-server

deltachat-rpc-server (stdio JSON-RPC server) from [Privitty/core](https://github.com/Privitty/core), built from the **dekstop-core** branch and published under **@privitty** on npm.

Same API as `@deltachat/stdio-rpc-server`. Use this when you want the server from the dekstop-core branch.

```bash
npm i @privitty/deltachat-rpc-server @deltachat/jsonrpc-client
```

```js
import { startDeltaChat } from "@privitty/deltachat-rpc-server";

const dc = await startDeltaChat("deltachat-data");
console.log(await dc.rpc.getSystemInfo());
dc.close();
```

Binary is resolved in this order: `DELTA_CHAT_RPC_SERVER` env, PATH (if `takeVersionFromPATH: true`), or platform prebuilds. Node >= 16.
28 changes: 28 additions & 0 deletions deltachat-rpc-server/npm-package-privitty/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { StdioDeltaChat } from "@deltachat/jsonrpc-client";

export interface SearchOptions {
takeVersionFromPATH: boolean;
disableEnvPath: boolean;
}

export function getRPCServerPath(
options?: Partial<SearchOptions>
): Promise<string>;

export type DeltaChatOverJsonRpcServer = StdioDeltaChat & {
readonly pathToServerBinary: string;
};

export interface StartOptions {
muteStdErr: boolean;
}

export function startDeltaChat(
directory: string,
options?: Partial<SearchOptions & StartOptions>
): Promise<DeltaChatOverJsonRpcServer>;

export namespace FnTypes {
export type getRPCServerPath = typeof getRPCServerPath;
export type startDeltaChat = typeof startDeltaChat;
}
100 changes: 100 additions & 0 deletions deltachat-rpc-server/npm-package-privitty/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//@ts-check
import { spawn } from "node:child_process";
import { stat } from "node:fs/promises";
import os from "node:os";
import process from "node:process";
import { ENV_VAR_NAME, PATH_EXECUTABLE_NAME } from "./src/const.js";
import {
ENV_VAR_LOCATION_NOT_FOUND,
FAILED_TO_START_SERVER_EXECUTABLE,
NPM_NOT_FOUND_SUPPORTED_PLATFORM_ERROR,
NPM_NOT_FOUND_UNSUPPORTED_PLATFORM_ERROR,
} from "./src/errors.js";

import { createRequire } from "node:module";

function findRPCServerInNodeModules() {
const arch = os.arch();
const operating_system = process.platform;
const require = createRequire(import.meta.url);
const packageName = require("./package.json").name;
const package_name = `${packageName}-${operating_system}-${arch}`;
try {
const { resolve } = createRequire(import.meta.url);
return resolve(package_name);
} catch (error) {
console.debug("findRpcServerInNodeModules", error);
if (
Object.keys(require("./package.json").optionalDependencies || {}).includes(
package_name
)
) {
throw new Error(NPM_NOT_FOUND_SUPPORTED_PLATFORM_ERROR(package_name));
} else {
throw new Error(NPM_NOT_FOUND_UNSUPPORTED_PLATFORM_ERROR());
}
}
}

/** @type {import("./index").FnTypes.getRPCServerPath} */
export async function getRPCServerPath(options = {}) {
const { takeVersionFromPATH, disableEnvPath } = {
takeVersionFromPATH: false,
disableEnvPath: false,
...options,
};
if (process.env[ENV_VAR_NAME] && !disableEnvPath) {
try {
if (!(await stat(process.env[ENV_VAR_NAME])).isFile()) {
throw new Error(
`expected ${ENV_VAR_NAME} to point to the deltachat-rpc-server executable`
);
}
} catch (error) {
throw new Error(ENV_VAR_LOCATION_NOT_FOUND());
}
return process.env[ENV_VAR_NAME];
}
if (takeVersionFromPATH) {
return PATH_EXECUTABLE_NAME;
}
return findRPCServerInNodeModules();
}

import { StdioDeltaChat } from "@deltachat/jsonrpc-client";

/** @type {import("./index").FnTypes.startDeltaChat} */
export async function startDeltaChat(directory, options = {}) {
const pathToServerBinary = await getRPCServerPath(options);
const server = spawn(pathToServerBinary, {
env: {
RUST_LOG: process.env.RUST_LOG,
DC_ACCOUNTS_PATH: directory,
},
stdio: ["pipe", "pipe", options.muteStdErr ? "ignore" : "inherit"],
});

server.on("error", (err) => {
throw new Error(FAILED_TO_START_SERVER_EXECUTABLE(pathToServerBinary, err));
});
let shouldClose = false;

server.on("exit", () => {
if (shouldClose) return;
throw new Error("Server quit");
});

/** @type {import('./index').DeltaChatOverJsonRpcServer} */
//@ts-expect-error
const dc = new StdioDeltaChat(server.stdin, server.stdout, true);

dc.close = () => {
shouldClose = true;
if (!server.kill()) console.log("server termination failed");
};

//@ts-expect-error
dc.pathToServerBinary = pathToServerBinary;

return dc;
}
20 changes: 20 additions & 0 deletions deltachat-rpc-server/npm-package-privitty/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@privitty/deltachat-rpc-server",
"version": "1.160.0",
"license": "MPL-2.0",
"main": "index.js",
"types": "index.d.ts",
"type": "module",
"optionalDependencies": {},
"peerDependencies": {
"@deltachat/jsonrpc-client": "*"
},
"repository": {
"type": "git",
"url": "https://github.com/Privitty/core.git",
"directory": "deltachat-rpc-server"
},
"scripts": {
"prepack": "node scripts/update_optional_dependencies_and_version.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import subprocess
import sys
from os import path, makedirs, chdir, chmod
from shutil import copy

# run from npm-package-privitty/
chdir(path.join(path.dirname(path.abspath(__file__)), "../"))

if len(sys.argv) < 3:
print("Usage: pack_binary_for_platform.py <cargo-target> <binary_path>")
sys.exit(1)

target = sys.argv[1].strip()
binary_path = sys.argv[2].strip()

out = subprocess.run(["rustc", "--print", "target-list"], capture_output=True, check=True)
if target not in out.stdout.decode("utf-8"):
print("Unknown target:", target)
sys.exit(1)

makedirs("platform_package", exist_ok=True)
platform_path = "platform_package/" + target
makedirs(platform_path, exist_ok=True)

binary_name = path.basename(binary_path)
dest = platform_path + "/" + binary_name
copy(binary_path, dest)
chmod(dest, 0o555)

from src.make_package import write_package_json
write_package_json(platform_path, target, binary_name)
Loading
Loading