@shhhum/simplex-chat 0.0.0-placeholder → 7.1.0-beta.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +130 -0
  3. package/dist/api.d.ts +439 -0
  4. package/dist/api.js +911 -0
  5. package/dist/api.js.map +1 -0
  6. package/dist/bot.d.ts +34 -0
  7. package/dist/bot.js +194 -0
  8. package/dist/bot.js.map +1 -0
  9. package/dist/cli.d.ts +4 -0
  10. package/dist/cli.js +46 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/core.d.ts +138 -0
  13. package/dist/core.js +144 -0
  14. package/dist/core.js.map +1 -0
  15. package/dist/index.d.ts +19 -0
  16. package/dist/index.js +23 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/libs.d.ts +12 -0
  19. package/dist/libs.js +210 -0
  20. package/dist/libs.js.map +1 -0
  21. package/dist/release.d.ts +5 -0
  22. package/dist/release.js +20 -0
  23. package/dist/release.js.map +1 -0
  24. package/dist/simplex.d.ts +12 -0
  25. package/dist/simplex.js +22 -0
  26. package/dist/util.d.ts +15 -0
  27. package/dist/util.js +91 -0
  28. package/dist/util.js.map +1 -0
  29. package/docs/Namespace.api.md +33 -0
  30. package/docs/Namespace.bot.md +24 -0
  31. package/docs/Namespace.core.md +50 -0
  32. package/docs/Namespace.util.md +25 -0
  33. package/docs/README.md +12 -0
  34. package/docs/api.Class.ChatApi.md +1851 -0
  35. package/docs/api.Class.ChatCommandError.md +205 -0
  36. package/docs/api.Enumeration.ConnReqType.md +27 -0
  37. package/docs/api.Interface.BotAddressSettings.md +60 -0
  38. package/docs/api.TypeAlias.DbConfig.md +62 -0
  39. package/docs/api.TypeAlias.EventSubscriberFunc.md +31 -0
  40. package/docs/api.TypeAlias.EventSubscribers.md +11 -0
  41. package/docs/api.Variable.defaultBotAddressSettings.md +11 -0
  42. package/docs/bot.Function.run.md +21 -0
  43. package/docs/bot.Function.subscribeChatItems.md +27 -0
  44. package/docs/bot.Interface.BotConfig.md +87 -0
  45. package/docs/bot.Interface.BotOptions.md +81 -0
  46. package/docs/bot.TypeAlias.BotDbOpts.md +21 -0
  47. package/docs/core.Class.ChatAPIError.md +205 -0
  48. package/docs/core.Class.ChatInitError.md +205 -0
  49. package/docs/core.DBMigrationError.Interface.ErrorMigration.md +41 -0
  50. package/docs/core.DBMigrationError.Interface.ErrorNotADatabase.md +33 -0
  51. package/docs/core.DBMigrationError.Interface.ErrorSQL.md +41 -0
  52. package/docs/core.DBMigrationError.Interface.InvalidConfirmation.md +25 -0
  53. package/docs/core.DBMigrationError.Interface.InvalidQueueSize.md +25 -0
  54. package/docs/core.DBMigrationError.TypeAlias.Tag.md +11 -0
  55. package/docs/core.Enumeration.MigrationConfirmation.md +43 -0
  56. package/docs/core.Function.chatCloseStore.md +23 -0
  57. package/docs/core.Function.chatDecryptFile.md +31 -0
  58. package/docs/core.Function.chatEncryptFile.md +31 -0
  59. package/docs/core.Function.chatMigrateInit.md +37 -0
  60. package/docs/core.Function.chatReadFile.md +27 -0
  61. package/docs/core.Function.chatRecvMsgWait.md +27 -0
  62. package/docs/core.Function.chatSendCmd.md +27 -0
  63. package/docs/core.Function.chatWriteFile.md +31 -0
  64. package/docs/core.Function.loadLibrary.md +24 -0
  65. package/docs/core.Interface.APIResult.md +31 -0
  66. package/docs/core.Interface.CryptoArgs.md +27 -0
  67. package/docs/core.Interface.UpMigration.md +25 -0
  68. package/docs/core.MTRError.Interface.MTREDifferent.md +33 -0
  69. package/docs/core.MTRError.Interface.MTRENoDown.md +33 -0
  70. package/docs/core.MTRError.TypeAlias.Tag.md +11 -0
  71. package/docs/core.MigrationError.Interface.MEDowngrade.md +33 -0
  72. package/docs/core.MigrationError.Interface.MEUpgrade.md +33 -0
  73. package/docs/core.MigrationError.Interface.MigrationError.md +33 -0
  74. package/docs/core.MigrationError.TypeAlias.Tag.md +11 -0
  75. package/docs/core.Namespace.DBMigrationError.md +19 -0
  76. package/docs/core.Namespace.MTRError.md +16 -0
  77. package/docs/core.Namespace.MigrationError.md +17 -0
  78. package/docs/core.TypeAlias.Backend.md +11 -0
  79. package/docs/core.TypeAlias.DBMigrationError.md +11 -0
  80. package/docs/core.TypeAlias.MTRError.md +11 -0
  81. package/docs/core.TypeAlias.MigrationError.md +11 -0
  82. package/docs/util.Function.botAddressSettings.md +21 -0
  83. package/docs/util.Function.chatInfoName.md +21 -0
  84. package/docs/util.Function.chatInfoRef.md +21 -0
  85. package/docs/util.Function.ciBotCommand.md +21 -0
  86. package/docs/util.Function.ciContentText.md +21 -0
  87. package/docs/util.Function.contactAddressStr.md +21 -0
  88. package/docs/util.Function.fromLocalProfile.md +21 -0
  89. package/docs/util.Function.reactionText.md +21 -0
  90. package/docs/util.Function.senderName.md +25 -0
  91. package/docs/util.Interface.BotCommand.md +25 -0
  92. package/examples/squaring-bot-readme.js +17 -0
  93. package/examples/squaring-bot.ts +42 -0
  94. package/package.json +52 -6
  95. package/src/api.ts +997 -0
  96. package/src/bot.ts +221 -0
  97. package/src/cli.ts +42 -0
  98. package/src/core.ts +240 -0
  99. package/src/index.ts +22 -0
  100. package/src/libs.ts +202 -0
  101. package/src/release.ts +19 -0
  102. package/src/simplex.d.ts +12 -0
  103. package/src/simplex.js +22 -0
  104. package/src/util.ts +92 -0
  105. package/tsconfig.json +23 -0
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A simple declarative API to run a chat-bot with a single function call.
3
+ * It automates creating and updating of the bot profile, address and bot commands shown in the app UI.
4
+ */
5
+ export * as bot from "./bot";
6
+ /**
7
+ * An API to send chat commands and receive chat events to/from chat core.
8
+ * You need to use it in bot event handlers, and for any other use cases.
9
+ */
10
+ export * as api from "./api";
11
+ /**
12
+ * A low level API to the core library - the same that is used in desktop clients.
13
+ * You are unlikely to ever need to use this module directly.
14
+ */
15
+ export * as core from "./core";
16
+ /**
17
+ * Useful functions for chat events and types.
18
+ */
19
+ export * as util from "./util";
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.util = exports.core = exports.api = exports.bot = void 0;
4
+ /**
5
+ * A simple declarative API to run a chat-bot with a single function call.
6
+ * It automates creating and updating of the bot profile, address and bot commands shown in the app UI.
7
+ */
8
+ exports.bot = require("./bot");
9
+ /**
10
+ * An API to send chat commands and receive chat events to/from chat core.
11
+ * You need to use it in bot event handlers, and for any other use cases.
12
+ */
13
+ exports.api = require("./api");
14
+ /**
15
+ * A low level API to the core library - the same that is used in desktop clients.
16
+ * You are unlikely to ever need to use this module directly.
17
+ */
18
+ exports.core = require("./core");
19
+ /**
20
+ * Useful functions for chat events and types.
21
+ */
22
+ exports.util = require("./util");
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,+BAA4B;AAE5B;;;GAGG;AACH,+BAA4B;AAE5B;;;GAGG;AACH,iCAA8B;AAE9B;;GAEG;AACH,iCAA8B"}
package/dist/libs.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { Backend } from "./core";
2
+ export declare const MAX_REDIRECTS = 5;
3
+ export declare function platformTag(platform: string, arch: string): string;
4
+ export declare function cacheRoot(platform: string, env: NodeJS.ProcessEnv, home?: string): string;
5
+ export declare function libsAsset(backend: Backend, tag: string): string;
6
+ export declare function addonAsset(tag: string): string;
7
+ export declare function releaseUrl(release: string, asset: string): string;
8
+ export declare function libPath(dir: string): string;
9
+ export declare function resolveLibsDir(backend: Backend, env?: NodeJS.ProcessEnv, platform?: string, arch?: string): Promise<string>;
10
+ export declare function resolveAddonPath(env?: NodeJS.ProcessEnv, platform?: string, arch?: string): Promise<string>;
11
+ export declare function installLibs(url: string, sha256: string, target: string, lib: string, timeoutMs?: number): Promise<void>;
12
+ export declare function installAddon(url: string, sha256: string, target: string, timeoutMs?: number): Promise<void>;
package/dist/libs.js ADDED
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_REDIRECTS = void 0;
4
+ exports.platformTag = platformTag;
5
+ exports.cacheRoot = cacheRoot;
6
+ exports.libsAsset = libsAsset;
7
+ exports.addonAsset = addonAsset;
8
+ exports.releaseUrl = releaseUrl;
9
+ exports.libPath = libPath;
10
+ exports.resolveLibsDir = resolveLibsDir;
11
+ exports.resolveAddonPath = resolveAddonPath;
12
+ exports.installLibs = installLibs;
13
+ exports.installAddon = installAddon;
14
+ const crypto = require("crypto");
15
+ const fs = require("fs");
16
+ const http = require("http");
17
+ const https = require("https");
18
+ const os = require("os");
19
+ const path = require("path");
20
+ const promises_1 = require("stream/promises");
21
+ const extract = require("extract-zip");
22
+ const release_1 = require("./release");
23
+ const GITHUB_REPO = "simplex-chat/simplex-chat-libs";
24
+ const REQUEST_TIMEOUT_MS = 60000;
25
+ exports.MAX_REDIRECTS = 5;
26
+ const PLATFORMS = {
27
+ linux: { name: "linux", lib: "libsimplex.so" },
28
+ darwin: { name: "macos", lib: "libsimplex.dylib" },
29
+ win32: { name: "windows", lib: "libsimplex.dll" },
30
+ };
31
+ const ARCHS = { x64: "x86_64", arm64: "aarch64" };
32
+ const SUPPORTED = ["linux-x86_64", "linux-aarch64", "macos-x86_64", "macos-aarch64", "windows-x86_64"];
33
+ function unsupported(platform, arch) {
34
+ return new Error(`Unsupported platform: ${platform}/${arch}; supported: ${SUPPORTED.join(", ")}`);
35
+ }
36
+ function platformTag(platform, arch) {
37
+ var _a;
38
+ const tag = `${(_a = PLATFORMS[platform]) === null || _a === void 0 ? void 0 : _a.name}-${ARCHS[arch]}`;
39
+ if (!SUPPORTED.includes(tag))
40
+ throw unsupported(platform, arch);
41
+ return tag;
42
+ }
43
+ function libName(platform = process.platform, arch = process.arch) {
44
+ var _a;
45
+ const lib = (_a = PLATFORMS[platform]) === null || _a === void 0 ? void 0 : _a.lib;
46
+ if (!lib)
47
+ throw unsupported(platform, arch);
48
+ return lib;
49
+ }
50
+ function cacheRoot(platform, env, home = os.homedir()) {
51
+ if (platform === "darwin")
52
+ return path.join(home, "Library", "Caches", "simplex-chat");
53
+ if (platform === "win32") {
54
+ if (!env.LOCALAPPDATA)
55
+ throw new Error("LOCALAPPDATA is not set");
56
+ return path.join(env.LOCALAPPDATA, "simplex-chat");
57
+ }
58
+ return path.join(env.XDG_CACHE_HOME || path.join(home, ".cache"), "simplex-chat");
59
+ }
60
+ function libsAsset(backend, tag) {
61
+ const suffix = backend === "postgres" ? "-postgres" : "";
62
+ return `simplex-chat-libs-${tag}${suffix}.zip`;
63
+ }
64
+ function addonAsset(tag) {
65
+ return `simplex-chat-nodejs-${tag}.node`;
66
+ }
67
+ function releaseUrl(release, asset) {
68
+ return `https://github.com/${GITHUB_REPO}/releases/download/${release}/${asset}`;
69
+ }
70
+ function pinnedSha256(asset) {
71
+ const sha256 = release_1.SHA256[asset];
72
+ if (!sha256)
73
+ throw new Error(`no SHA-256 is pinned for ${asset}`);
74
+ return sha256;
75
+ }
76
+ function libPath(dir) {
77
+ return path.join(dir, libName());
78
+ }
79
+ async function resolveLibsDir(backend, env = process.env, platform = process.platform, arch = process.arch) {
80
+ const lib = libName(platform, arch);
81
+ if (env.SIMPLEX_LIBS_DIR) {
82
+ const dir = path.resolve(env.SIMPLEX_LIBS_DIR);
83
+ if (!fs.existsSync(path.join(dir, lib)))
84
+ throw new Error(`SIMPLEX_LIBS_DIR has no ${lib}: ${dir}`);
85
+ return dir;
86
+ }
87
+ const tag = platformTag(platform, arch);
88
+ if (backend === "postgres" && tag !== "linux-x86_64") {
89
+ throw new Error(`postgres backend is only supported on linux-x86_64; current platform is ${tag}`);
90
+ }
91
+ const target = path.resolve(cacheRoot(platform, env), release_1.LIBS_RELEASE, backend);
92
+ if (!fs.existsSync(path.join(target, lib))) {
93
+ const asset = libsAsset(backend, tag);
94
+ await installLibs(releaseUrl(release_1.LIBS_RELEASE, asset), pinnedSha256(asset), target, lib);
95
+ }
96
+ return target;
97
+ }
98
+ async function resolveAddonPath(env = process.env, platform = process.platform, arch = process.arch) {
99
+ if (env.SIMPLEX_ADDON_PATH) {
100
+ const file = path.resolve(env.SIMPLEX_ADDON_PATH);
101
+ if (!fs.existsSync(file))
102
+ throw new Error(`SIMPLEX_ADDON_PATH does not exist: ${file}`);
103
+ return file;
104
+ }
105
+ if (!release_1.ADDON_RELEASE)
106
+ throw new Error("no prebuilt Node.js add-on is pinned in this version; set SIMPLEX_ADDON_PATH");
107
+ const asset = addonAsset(platformTag(platform, arch));
108
+ const target = path.resolve(cacheRoot(platform, env), release_1.ADDON_RELEASE, asset);
109
+ if (!fs.existsSync(target))
110
+ await installAddon(releaseUrl(release_1.ADDON_RELEASE, asset), pinnedSha256(asset), target);
111
+ return target;
112
+ }
113
+ function installLibs(url, sha256, target, lib, timeoutMs = REQUEST_TIMEOUT_MS) {
114
+ return inTempDir(target, async (tmp) => {
115
+ console.error(`Downloading libsimplex from ${url} ...`);
116
+ const zipPath = path.join(tmp, "libs.zip");
117
+ await download(url, zipPath, timeoutMs);
118
+ await verifySha256(zipPath, sha256, url);
119
+ await extract(zipPath, { dir: tmp });
120
+ const extracted = path.join(tmp, "libs");
121
+ if (!fs.existsSync(path.join(extracted, lib)))
122
+ throw new Error(`libs/${lib} missing from ${url}`);
123
+ await renameInto(extracted, target, path.join(target, lib));
124
+ });
125
+ }
126
+ function installAddon(url, sha256, target, timeoutMs = REQUEST_TIMEOUT_MS) {
127
+ return inTempDir(target, async (tmp) => {
128
+ console.error(`Downloading the Node.js add-on from ${url} ...`);
129
+ const file = path.join(tmp, path.basename(target));
130
+ await download(url, file, timeoutMs);
131
+ await verifySha256(file, sha256, url);
132
+ await renameInto(file, target, target);
133
+ });
134
+ }
135
+ async function verifySha256(file, expected, url) {
136
+ const hash = crypto.createHash("sha256");
137
+ for await (const chunk of fs.createReadStream(file))
138
+ hash.update(chunk);
139
+ const actual = hash.digest("hex");
140
+ if (actual !== expected)
141
+ throw new Error(`SHA-256 of ${url} is ${actual}, expected ${expected}`);
142
+ }
143
+ // The temp dir is next to the target, so the final rename stays on one filesystem.
144
+ async function inTempDir(target, install) {
145
+ const parent = path.dirname(target);
146
+ await fs.promises.mkdir(parent, { recursive: true });
147
+ const tmp = await fs.promises.mkdtemp(path.join(parent, ".download-"));
148
+ try {
149
+ await install(tmp);
150
+ }
151
+ finally {
152
+ await fs.promises.rm(tmp, { recursive: true, force: true });
153
+ }
154
+ }
155
+ async function renameInto(from, target, installed) {
156
+ try {
157
+ await fs.promises.rename(from, target);
158
+ }
159
+ catch (e) {
160
+ // Another process installed the same version first; its files are identical.
161
+ // Windows reports renaming onto an existing directory or a loaded file as EPERM.
162
+ const code = e.code;
163
+ const lost = (code === "EEXIST" || code === "ENOTEMPTY" || code === "EPERM") && fs.existsSync(target);
164
+ if (!lost)
165
+ throw e;
166
+ if (!fs.existsSync(installed)) {
167
+ throw new Error(`another process partially populated ${target} but ${path.basename(installed)} is missing; remove it manually and retry`);
168
+ }
169
+ }
170
+ }
171
+ function download(url, dest, timeoutMs, redirects = 0) {
172
+ return new Promise((resolve, reject) => {
173
+ const get = url.startsWith("https:") ? https.get : http.get;
174
+ // Once a response arrives, request errors are ignored: a download settles via pipeline, which
175
+ // waits for the file to close, so tmp cleanup cannot fail with EBUSY on Windows.
176
+ let res;
177
+ const req = get(url, { headers: { "User-Agent": "simplex-chat-nodejs" }, timeout: timeoutMs }, response => {
178
+ var _a;
179
+ res = response;
180
+ const status = (_a = response.statusCode) !== null && _a !== void 0 ? _a : 0;
181
+ const location = response.headers.location;
182
+ if (status >= 300 && status < 400 && location) {
183
+ response.resume();
184
+ if (redirects >= exports.MAX_REDIRECTS)
185
+ return reject(new Error(`too many redirects downloading ${url}`));
186
+ let next;
187
+ try {
188
+ next = new URL(location, url);
189
+ }
190
+ catch (e) {
191
+ return reject(e);
192
+ }
193
+ if (next.protocol !== new URL(url).protocol)
194
+ return reject(new Error(`redirect from ${url} to ${next} changes protocol`));
195
+ download(next.toString(), dest, timeoutMs, redirects + 1).then(resolve, reject);
196
+ return;
197
+ }
198
+ if (status !== 200) {
199
+ response.resume();
200
+ return reject(new Error(`HTTP ${status} downloading ${url}`));
201
+ }
202
+ (0, promises_1.pipeline)(response, fs.createWriteStream(dest)).then(resolve, reject);
203
+ });
204
+ const abort = (err) => (res ? res.destroy(err) : req.destroy(err));
205
+ req.on("timeout", () => abort(new Error(`timeout downloading ${url}`)));
206
+ req.on("error", e => { if (!res)
207
+ reject(e); });
208
+ });
209
+ }
210
+ //# sourceMappingURL=libs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libs.js","sourceRoot":"","sources":["../src/libs.ts"],"names":[],"mappings":";;;AA0BA,kCAIC;AAQD,8BAOC;AAED,8BAGC;AAED,gCAEC;AAED,gCAEC;AAQD,0BAEC;AAED,wCAsBC;AAED,4CAeC;AAED,kCAWC;AAED,oCAQC;AApID,iCAAgC;AAChC,yBAAwB;AACxB,6BAA4B;AAC5B,+BAA8B;AAC9B,yBAAwB;AACxB,6BAA4B;AAC5B,8CAAwC;AACxC,uCAAuC;AAEvC,uCAA6D;AAE7D,MAAM,WAAW,GAAG,gCAAgC,CAAA;AACpD,MAAM,kBAAkB,GAAG,KAAM,CAAA;AACpB,QAAA,aAAa,GAAG,CAAC,CAAA;AAC9B,MAAM,SAAS,GAAkE;IAC/E,KAAK,EAAE,EAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,eAAe,EAAC;IAC5C,MAAM,EAAE,EAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,kBAAkB,EAAC;IAChD,KAAK,EAAE,EAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,gBAAgB,EAAC;CAChD,CAAA;AACD,MAAM,KAAK,GAAyC,EAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAC,CAAA;AACrF,MAAM,SAAS,GAAG,CAAC,cAAc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AAI,KAAK,CAAC,iBAAiB,GAAG,OAAO,IAAI,mBAAmB,CAAC,CAAC,CAAA;gBACzH,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;gBAC/E,OAAM;YACR,CAAC;YACD,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;gBACnB,QAAQ,CAAC,MAAM,EAAE,CAAA;gBACjB,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,QAAQ,MAAM,gBAAgB,GAAG,EAAE,CAAC,CAAC,CAAA;YAC/D,CAAC;YACD,IAAA,mBAAQ,EAAC,QAAQ,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QACtE,CAAC,CAAC,CAAA;QACF,MAAM,KAAK,GAAG,CAAC,GAAU,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;QACzE,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;QACvE,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG;YAAE,MAAM,CAAC,CAAC,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const LIBS_RELEASE = "core-7.1.0.11";
2
+ export declare const ADDON_RELEASE: string | undefined;
3
+ export declare const SHA256: {
4
+ readonly [asset: string]: string;
5
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ // Written by scripts/ci/packages_release.py from the simplex-chat-libs releases.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.SHA256 = exports.ADDON_RELEASE = exports.LIBS_RELEASE = void 0;
5
+ exports.LIBS_RELEASE = "core-7.1.0.11";
6
+ exports.ADDON_RELEASE = "nodejs-addon-308c0960c707";
7
+ exports.SHA256 = {
8
+ "simplex-chat-libs-linux-aarch64.zip": "d66aa1b30b9fa20225dad8ef75a9c605961e1c0adde2ba0283e2fcac4e15d260",
9
+ "simplex-chat-libs-linux-x86_64-postgres.zip": "925b3166f969b12082ff8ee659e5f2a9933fe40120deb80c9aa3002a5ba6c803",
10
+ "simplex-chat-libs-linux-x86_64.zip": "dabad0824e8813ea4a084fbf37e1ba4cf6dcea9cd8ccadc521fec200f246208a",
11
+ "simplex-chat-libs-macos-aarch64.zip": "aa74608b149fff7508a47eaac4284dcc6d189c6ed8b7c18428df9158bc176a61",
12
+ "simplex-chat-libs-macos-x86_64.zip": "a0e21457e1077be7f71b46c1c27452945b2cee2b6c50efb0004412ce5b7042ec",
13
+ "simplex-chat-libs-windows-x86_64.zip": "c01dad574daa101a1cbfd31ddbf2b3d0d986a4a42f97d789d2f878b2050b2b4b",
14
+ "simplex-chat-nodejs-linux-aarch64.node": "3636a82c56c48229e0326fa03d6ceb5c16dd3afbcc1e86337783dc53a7328d67",
15
+ "simplex-chat-nodejs-linux-x86_64.node": "55f3479b03fdb57591179ed730da744f1aa362e7529df55221b60028415746e9",
16
+ "simplex-chat-nodejs-macos-aarch64.node": "17da0ed991bcc60f3a0329ba4ce8af902a02cb3dfd7ab7b84718449cc857c857",
17
+ "simplex-chat-nodejs-macos-x86_64.node": "6218210db6caf520ecb7b5066babfce1e51ad2082f7ba6043aa26510418c1aea",
18
+ "simplex-chat-nodejs-windows-x86_64.node": "03aaee6f19b216c660f492e064a02a2820c41cd4b58b2a7b7561ac97b982f90d",
19
+ };
20
+ //# sourceMappingURL=release.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release.js","sourceRoot":"","sources":["../src/release.ts"],"names":[],"mappings":";AAAA,iFAAiF;;;AAEpE,QAAA,YAAY,GAAG,eAAe,CAAA;AAE9B,QAAA,aAAa,GAAuB,2BAA2B,CAAA;AAE/D,QAAA,MAAM,GAAuC;IACxD,qCAAqC,EAAE,kEAAkE;IACzG,6CAA6C,EAAE,kEAAkE;IACjH,oCAAoC,EAAE,kEAAkE;IACxG,qCAAqC,EAAE,kEAAkE;IACzG,oCAAoC,EAAE,kEAAkE;IACxG,sCAAsC,EAAE,kEAAkE;IAC1G,wCAAwC,EAAE,kEAAkE;IAC5G,uCAAuC,EAAE,kEAAkE;IAC3G,wCAAwC,EAAE,kEAAkE;IAC5G,uCAAuC,EAAE,kEAAkE;IAC3G,yCAAyC,EAAE,kEAAkE;CAC9G,CAAA"}
@@ -0,0 +1,12 @@
1
+ // These functions are defined in CPP add-on ../cpp/simplex.cc
2
+
3
+ export function load(addonPath: string, libPath: string): void
4
+ export function chat_migrate_init(dbPath: string, dbKey: string, confirm: string): Promise<[bigint, string]>
5
+ export function chat_migrate_init_queue(dbPath: string, dbKey: string, confirm: string, queueSize: number): Promise<[bigint, string]>
6
+ export function chat_close_store(ctrl: bigint): Promise<string>
7
+ export function chat_send_cmd(ctrl: bigint, cmd: string): Promise<string>
8
+ export function chat_recv_msg_wait(ctrl: bigint, wait: number): Promise<string>
9
+ export function chat_write_file(ctrl: bigint, path: string, buffer: ArrayBuffer | Uint8Array): Promise<string>
10
+ export function chat_read_file(path: string, key: string, nonce: string): Promise<Buffer>
11
+ export function chat_encrypt_file(ctrl: bigint, fromPath: string, toPath: string): Promise<string>
12
+ export function chat_decrypt_file(fromPath: string, key: string, nonce: string, toPath: string): Promise<string>
@@ -0,0 +1,22 @@
1
+ // The add-on is downloaded from the libsimplex release, so it is loaded at runtime by core.loadLibrary.
2
+ const NOT_LOADED = "libsimplex is not loaded, call core.loadLibrary(backend) first"
3
+ const BINDINGS = ["chat_migrate_init", "chat_migrate_init_queue", "chat_close_store", "chat_send_cmd", "chat_recv_msg_wait",
4
+ "chat_write_file", "chat_read_file", "chat_encrypt_file", "chat_decrypt_file"]
5
+
6
+ let addon
7
+
8
+ exports.load = (addonPath, libPath) => {
9
+ if (!addon) {
10
+ const addonModule = {exports: {}}
11
+ process.dlopen(addonModule, addonPath)
12
+ addon = addonModule.exports
13
+ }
14
+ addon.load(libPath)
15
+ }
16
+
17
+ for (const name of BINDINGS) {
18
+ exports[name] = (...args) => {
19
+ if (!addon) throw new Error(NOT_LOADED)
20
+ return addon[name](...args)
21
+ }
22
+ }
package/dist/util.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { T } from "@simplex-chat/types";
2
+ import { BotAddressSettings } from "./api";
3
+ export declare function chatInfoRef(cInfo: T.ChatInfo): T.ChatRef | undefined;
4
+ export declare function chatInfoName(cInfo: T.ChatInfo): string;
5
+ export declare function senderName(cInfo: T.ChatInfo, chatDir: T.CIDirection): string;
6
+ export declare function contactAddressStr(link: T.CreatedConnLink): string;
7
+ export declare function botAddressSettings({ addressSettings }: T.UserContactLink): BotAddressSettings;
8
+ export declare function fromLocalProfile({ displayName, fullName, shortDescr, image, contactLink, preferences, peerType, contactDomain }: T.LocalProfile): T.Profile;
9
+ export declare function ciContentText({ content }: T.ChatItem): string | undefined;
10
+ export interface BotCommand {
11
+ keyword: string;
12
+ params: string;
13
+ }
14
+ export declare function ciBotCommand(chatItem: T.ChatItem): BotCommand | undefined;
15
+ export declare function reactionText(reaction: T.ACIReaction): string;
package/dist/util.js ADDED
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chatInfoRef = chatInfoRef;
4
+ exports.chatInfoName = chatInfoName;
5
+ exports.senderName = senderName;
6
+ exports.contactAddressStr = contactAddressStr;
7
+ exports.botAddressSettings = botAddressSettings;
8
+ exports.fromLocalProfile = fromLocalProfile;
9
+ exports.ciContentText = ciContentText;
10
+ exports.ciBotCommand = ciBotCommand;
11
+ exports.reactionText = reactionText;
12
+ const types_1 = require("@simplex-chat/types");
13
+ function chatInfoRef(cInfo) {
14
+ var _a, _b;
15
+ switch (cInfo.type) {
16
+ case types_1.T.ChatType.Direct: return { chatType: types_1.T.ChatType.Direct, chatId: cInfo.contact.contactId };
17
+ case types_1.T.ChatType.Group: {
18
+ const chatScope = ((_a = cInfo.groupChatScope) === null || _a === void 0 ? void 0 : _a.type) == "memberSupport"
19
+ ? { type: "memberSupport", groupMemberId_: (_b = cInfo.groupChatScope.groupMember_) === null || _b === void 0 ? void 0 : _b.groupMemberId }
20
+ : undefined;
21
+ return { chatType: types_1.T.ChatType.Group, chatId: cInfo.groupInfo.groupId, chatScope };
22
+ }
23
+ default: return undefined;
24
+ }
25
+ }
26
+ function chatInfoName(cInfo) {
27
+ switch (cInfo.type) {
28
+ case "direct": return `@${cInfo.contact.profile.displayName}`;
29
+ case "group": {
30
+ const scope = cInfo.groupChatScope;
31
+ const scopeName = (scope === null || scope === void 0 ? void 0 : scope.type) === "memberSupport"
32
+ ? `(support${scope.groupMember_ ? ` ${scope.groupMember_.memberProfile.displayName}` : ""})`
33
+ : "";
34
+ return `#${cInfo.groupInfo.groupProfile.displayName}${scopeName}`;
35
+ }
36
+ case "local": return "private notes";
37
+ case "contactRequest": return `request from @${cInfo.contactRequest.profile.displayName}`;
38
+ case "contactConnection": {
39
+ const alias = cInfo.contactConnection.localAlias;
40
+ return `pending connection${alias ? ` (@${alias})` : ""}`;
41
+ }
42
+ }
43
+ }
44
+ function senderName(cInfo, chatDir) {
45
+ const sender = chatDir.type === "groupRcv"
46
+ ? ` @${chatDir.groupMember.memberProfile.displayName}`
47
+ : "";
48
+ return chatInfoName(cInfo) + sender;
49
+ }
50
+ function contactAddressStr(link) {
51
+ return link.connShortLink || link.connFullLink;
52
+ }
53
+ function botAddressSettings({ addressSettings }) {
54
+ return {
55
+ autoAccept: addressSettings.autoAccept ? true : false,
56
+ welcomeMessage: addressSettings.autoReply,
57
+ businessAddress: addressSettings.businessAddress
58
+ };
59
+ }
60
+ function fromLocalProfile({ displayName, fullName, shortDescr, image, contactLink, preferences, peerType, contactDomain }) {
61
+ const profile = { displayName, fullName, shortDescr, image, contactLink, preferences, peerType, contactDomain: contactDomain && { domain: contactDomain.domain } };
62
+ for (const key in profile) {
63
+ if (typeof profile[key] === "undefined")
64
+ delete profile[key];
65
+ }
66
+ return profile;
67
+ }
68
+ function ciContentText({ content }) {
69
+ switch (content.type) {
70
+ case "sndMsgContent": return content.msgContent.text;
71
+ case "rcvMsgContent": return content.msgContent.text;
72
+ default: return undefined;
73
+ }
74
+ }
75
+ // returns command (without /) and trimmed parameters
76
+ function ciBotCommand(chatItem) {
77
+ var _a;
78
+ const msg = (_a = ciContentText(chatItem)) === null || _a === void 0 ? void 0 : _a.trim();
79
+ if (msg) {
80
+ const r = msg.match(/^\/([^\s]+)([\s\S]*)/);
81
+ if (r && r.length >= 3) {
82
+ return { keyword: r[1], params: r[2].trim() };
83
+ }
84
+ }
85
+ return undefined;
86
+ }
87
+ function reactionText(reaction) {
88
+ const r = reaction.chatReaction;
89
+ return r.reaction.type === "emoji" ? r.reaction.emoji : r.reaction.tag;
90
+ }
91
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;AAGA,kCAYC;AAED,oCAiBC;AAED,gCAKC;AAED,8CAEC;AAED,gDAMC;AAED,4CAMC;AAED,sCAMC;AAQD,oCASC;AAED,oCAGC;AA3FD,+CAAqC;AAGrC,SAAgB,WAAW,CAAC,KAAiB;;IAC3C,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,SAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAC,QAAQ,EAAE,SAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,CAA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0,0 +1,33 @@
1
+ [**simplex-chat**](README.md)
2
+
3
+ ***
4
+
5
+ [simplex-chat](README.md) / api
6
+
7
+ # api
8
+
9
+ An API to send chat commands and receive chat events to/from chat core.
10
+ You need to use it in bot event handlers, and for any other use cases.
11
+
12
+ ## Enumerations
13
+
14
+ - [ConnReqType](api.Enumeration.ConnReqType.md)
15
+
16
+ ## Classes
17
+
18
+ - [ChatApi](api.Class.ChatApi.md)
19
+ - [ChatCommandError](api.Class.ChatCommandError.md)
20
+
21
+ ## Interfaces
22
+
23
+ - [BotAddressSettings](api.Interface.BotAddressSettings.md)
24
+
25
+ ## Type Aliases
26
+
27
+ - [DbConfig](api.TypeAlias.DbConfig.md)
28
+ - [EventSubscriberFunc](api.TypeAlias.EventSubscriberFunc.md)
29
+ - [EventSubscribers](api.TypeAlias.EventSubscribers.md)
30
+
31
+ ## Variables
32
+
33
+ - [defaultBotAddressSettings](api.Variable.defaultBotAddressSettings.md)
@@ -0,0 +1,24 @@
1
+ [**simplex-chat**](README.md)
2
+
3
+ ***
4
+
5
+ [simplex-chat](README.md) / bot
6
+
7
+ # bot
8
+
9
+ A simple declarative API to run a chat-bot with a single function call.
10
+ It automates creating and updating of the bot profile, address and bot commands shown in the app UI.
11
+
12
+ ## Interfaces
13
+
14
+ - [BotConfig](bot.Interface.BotConfig.md)
15
+ - [BotOptions](bot.Interface.BotOptions.md)
16
+
17
+ ## Type Aliases
18
+
19
+ - [BotDbOpts](bot.TypeAlias.BotDbOpts.md)
20
+
21
+ ## Functions
22
+
23
+ - [run](bot.Function.run.md)
24
+ - [subscribeChatItems](bot.Function.subscribeChatItems.md)
@@ -0,0 +1,50 @@
1
+ [**simplex-chat**](README.md)
2
+
3
+ ***
4
+
5
+ [simplex-chat](README.md) / core
6
+
7
+ # core
8
+
9
+ A low level API to the core library - the same that is used in desktop clients.
10
+ You are unlikely to ever need to use this module directly.
11
+
12
+ ## Namespaces
13
+
14
+ - [DBMigrationError](core.Namespace.DBMigrationError.md)
15
+ - [MigrationError](core.Namespace.MigrationError.md)
16
+ - [MTRError](core.Namespace.MTRError.md)
17
+
18
+ ## Enumerations
19
+
20
+ - [MigrationConfirmation](core.Enumeration.MigrationConfirmation.md)
21
+
22
+ ## Classes
23
+
24
+ - [ChatAPIError](core.Class.ChatAPIError.md)
25
+ - [ChatInitError](core.Class.ChatInitError.md)
26
+
27
+ ## Interfaces
28
+
29
+ - [APIResult](core.Interface.APIResult.md)
30
+ - [CryptoArgs](core.Interface.CryptoArgs.md)
31
+ - [UpMigration](core.Interface.UpMigration.md)
32
+
33
+ ## Type Aliases
34
+
35
+ - [Backend](core.TypeAlias.Backend.md)
36
+ - [DBMigrationError](core.TypeAlias.DBMigrationError.md)
37
+ - [MigrationError](core.TypeAlias.MigrationError.md)
38
+ - [MTRError](core.TypeAlias.MTRError.md)
39
+
40
+ ## Functions
41
+
42
+ - [chatCloseStore](core.Function.chatCloseStore.md)
43
+ - [chatDecryptFile](core.Function.chatDecryptFile.md)
44
+ - [chatEncryptFile](core.Function.chatEncryptFile.md)
45
+ - [chatMigrateInit](core.Function.chatMigrateInit.md)
46
+ - [chatReadFile](core.Function.chatReadFile.md)
47
+ - [chatRecvMsgWait](core.Function.chatRecvMsgWait.md)
48
+ - [chatSendCmd](core.Function.chatSendCmd.md)
49
+ - [chatWriteFile](core.Function.chatWriteFile.md)
50
+ - [loadLibrary](core.Function.loadLibrary.md)
@@ -0,0 +1,25 @@
1
+ [**simplex-chat**](README.md)
2
+
3
+ ***
4
+
5
+ [simplex-chat](README.md) / util
6
+
7
+ # util
8
+
9
+ Useful functions for chat events and types.
10
+
11
+ ## Interfaces
12
+
13
+ - [BotCommand](util.Interface.BotCommand.md)
14
+
15
+ ## Functions
16
+
17
+ - [botAddressSettings](util.Function.botAddressSettings.md)
18
+ - [chatInfoName](util.Function.chatInfoName.md)
19
+ - [chatInfoRef](util.Function.chatInfoRef.md)
20
+ - [ciBotCommand](util.Function.ciBotCommand.md)
21
+ - [ciContentText](util.Function.ciContentText.md)
22
+ - [contactAddressStr](util.Function.contactAddressStr.md)
23
+ - [fromLocalProfile](util.Function.fromLocalProfile.md)
24
+ - [reactionText](util.Function.reactionText.md)
25
+ - [senderName](util.Function.senderName.md)
package/docs/README.md ADDED
@@ -0,0 +1,12 @@
1
+ **simplex-chat**
2
+
3
+ ***
4
+
5
+ # simplex-chat
6
+
7
+ ## Namespaces
8
+
9
+ - [api](Namespace.api.md)
10
+ - [bot](Namespace.bot.md)
11
+ - [core](Namespace.core.md)
12
+ - [util](Namespace.util.md)