simplex-chat 6.5.0-beta.4.1 → 6.5.0-beta.4.3

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 (69) hide show
  1. package/README.md +1 -1
  2. package/binding.gyp +19 -4
  3. package/cpp/simplex.cc +426 -0
  4. package/cpp/simplex.h +46 -0
  5. package/dist/index.d.ts +17 -2
  6. package/dist/index.js +18 -3
  7. package/dist/index.js.map +1 -1
  8. package/docs/Namespace.api.md +32 -0
  9. package/docs/Namespace.bot.md +20 -0
  10. package/docs/Namespace.core.md +48 -0
  11. package/docs/Namespace.util.md +25 -0
  12. package/docs/README.md +12 -0
  13. package/docs/api.Class.ChatApi.md +1602 -0
  14. package/docs/api.Class.ChatCommandError.md +205 -0
  15. package/docs/api.Enumeration.ConnReqType.md +27 -0
  16. package/docs/api.Interface.BotAddressSettings.md +60 -0
  17. package/docs/api.TypeAlias.EventSubscriberFunc.md +27 -0
  18. package/docs/api.TypeAlias.EventSubscribers.md +11 -0
  19. package/docs/api.Variable.defaultBotAddressSettings.md +11 -0
  20. package/docs/bot.Function.run.md +21 -0
  21. package/docs/bot.Interface.BotConfig.md +75 -0
  22. package/docs/bot.Interface.BotDbOpts.md +33 -0
  23. package/docs/bot.Interface.BotOptions.md +81 -0
  24. package/docs/core.Class.ChatAPIError.md +205 -0
  25. package/docs/core.Class.ChatInitError.md +205 -0
  26. package/docs/core.DBMigrationError.Interface.ErrorMigration.md +41 -0
  27. package/docs/core.DBMigrationError.Interface.ErrorNotADatabase.md +33 -0
  28. package/docs/core.DBMigrationError.Interface.ErrorSQL.md +41 -0
  29. package/docs/core.DBMigrationError.Interface.InvalidConfirmation.md +25 -0
  30. package/docs/core.DBMigrationError.TypeAlias.Tag.md +11 -0
  31. package/docs/core.Enumeration.MigrationConfirmation.md +43 -0
  32. package/docs/core.Function.chatCloseStore.md +23 -0
  33. package/docs/core.Function.chatDecryptFile.md +31 -0
  34. package/docs/core.Function.chatEncryptFile.md +31 -0
  35. package/docs/core.Function.chatMigrateInit.md +31 -0
  36. package/docs/core.Function.chatReadFile.md +27 -0
  37. package/docs/core.Function.chatRecvMsgWait.md +27 -0
  38. package/docs/core.Function.chatSendCmd.md +27 -0
  39. package/docs/core.Function.chatWriteFile.md +31 -0
  40. package/docs/core.Interface.APIResult.md +31 -0
  41. package/docs/core.Interface.CryptoArgs.md +27 -0
  42. package/docs/core.Interface.UpMigration.md +25 -0
  43. package/docs/core.MTRError.Interface.MTREDifferent.md +33 -0
  44. package/docs/core.MTRError.Interface.MTRENoDown.md +33 -0
  45. package/docs/core.MTRError.TypeAlias.Tag.md +11 -0
  46. package/docs/core.MigrationError.Interface.MEDowngrade.md +33 -0
  47. package/docs/core.MigrationError.Interface.MEUpgrade.md +33 -0
  48. package/docs/core.MigrationError.Interface.MigrationError.md +33 -0
  49. package/docs/core.MigrationError.TypeAlias.Tag.md +11 -0
  50. package/docs/core.Namespace.DBMigrationError.md +18 -0
  51. package/docs/core.Namespace.MTRError.md +16 -0
  52. package/docs/core.Namespace.MigrationError.md +17 -0
  53. package/docs/core.TypeAlias.DBMigrationError.md +11 -0
  54. package/docs/core.TypeAlias.MTRError.md +11 -0
  55. package/docs/core.TypeAlias.MigrationError.md +11 -0
  56. package/docs/util.Function.botAddressSettings.md +21 -0
  57. package/docs/util.Function.chatInfoName.md +21 -0
  58. package/docs/util.Function.chatInfoRef.md +21 -0
  59. package/docs/util.Function.ciBotCommand.md +21 -0
  60. package/docs/util.Function.ciContentText.md +21 -0
  61. package/docs/util.Function.contactAddressStr.md +21 -0
  62. package/docs/util.Function.fromLocalProfile.md +21 -0
  63. package/docs/util.Function.reactionText.md +21 -0
  64. package/docs/util.Function.senderName.md +25 -0
  65. package/docs/util.Interface.BotCommand.md +25 -0
  66. package/examples/squaring-bot-readme.js +17 -0
  67. package/examples/squaring-bot.ts +42 -0
  68. package/package.json +7 -3
  69. package/tsconfig.json +23 -0
package/README.md CHANGED
@@ -14,7 +14,7 @@ Please share your use cases and implementations.
14
14
  ## Quick start: a simple bot
15
15
 
16
16
  ```
17
- npm i simplex-chat@6.5.0-beta.4
17
+ npm i simplex-chat@6.5.0-beta.4.3
18
18
  ```
19
19
 
20
20
  Simple bot that replies with squares of numbers you send to it:
package/binding.gyp CHANGED
@@ -9,15 +9,15 @@
9
9
  "dependencies": [
10
10
  "<!(node -p \"require('node-addon-api').gyp\")"
11
11
  ],
12
- "libraries": [
13
- "-L<(module_root_dir)/libs",
14
- "-lsimplex"
15
- ],
16
12
  "cflags!": [ "-fno-exceptions" ],
17
13
  "cflags_cc!": [ "-fno-exceptions" ],
18
14
  "defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
19
15
  "conditions": [
20
16
  ["OS=='mac'", {
17
+ "libraries": [
18
+ "-L<(module_root_dir)/libs",
19
+ "-lsimplex"
20
+ ],
21
21
  "xcode_settings": {
22
22
  "OTHER_LDFLAGS": [
23
23
  "-Wl,-rpath,@loader_path/../../libs"
@@ -25,9 +25,24 @@
25
25
  }
26
26
  }],
27
27
  ["OS=='linux'", {
28
+ "libraries": [
29
+ "-L<(module_root_dir)/libs",
30
+ "-lsimplex"
31
+ ],
28
32
  "ldflags": [
29
33
  "-Wl,-rpath,'$$ORIGIN'/../../libs"
30
34
  ]
35
+ }],
36
+ ["OS=='win'", {
37
+ "libraries": [
38
+ "<(module_root_dir)/libs/libsimplex.lib"
39
+ ],
40
+ "copies": [{
41
+ "destination": "<(PRODUCT_DIR)",
42
+ "files": [
43
+ "<(module_root_dir)/libs/*"
44
+ ]
45
+ }]
31
46
  }]
32
47
  ]
33
48
  }
package/cpp/simplex.cc ADDED
@@ -0,0 +1,426 @@
1
+ #include <napi.h>
2
+ #include <sstream>
3
+ #include <string>
4
+ #include <functional>
5
+ #include <cstdlib>
6
+ #include "simplex.h"
7
+
8
+ namespace simplex {
9
+
10
+ using namespace Napi;
11
+
12
+ void haskell_init() {
13
+ #ifdef _WIN32
14
+ // non-moving GC is broken on windows with GHC 9.4-9.6.3
15
+ int argc = 5;
16
+ const char *argv[] = {
17
+ "simplex",
18
+ "+RTS", // requires `hs_init_with_rtsopts`
19
+ "-A64m", // chunk size for new allocations
20
+ "-H64m", // initial heap size
21
+ "--install-signal-handlers=no",
22
+ nullptr};
23
+ #else
24
+ int argc = 6;
25
+ const char *argv[] = {
26
+ "simplex",
27
+ "+RTS", // requires `hs_init_with_rtsopts`
28
+ "-A64m", // chunk size for new allocations
29
+ "-H64m", // initial heap size
30
+ "-xn", // non-moving GC
31
+ "--install-signal-handlers=no",
32
+ nullptr};
33
+ #endif
34
+ char **pargv = const_cast<char **>(argv);
35
+ hs_init_with_rtsopts(&argc, &pargv);
36
+ }
37
+
38
+ class ResultAsyncWorker : public AsyncWorker {
39
+ public:
40
+ using ExecuteFn = std::function<void(ResultAsyncWorker*)>;
41
+ using ResultProcessor = std::function<void(ResultAsyncWorker*, Napi::Env)>;
42
+
43
+ ResultAsyncWorker(Function& callback, ExecuteFn execute_fn, ResultProcessor result_processor = nullptr)
44
+ : AsyncWorker(callback), execute_fn_(std::move(execute_fn)), result_processor_(std::move(result_processor)) {}
45
+
46
+ void Execute() override {
47
+ execute_fn_(this);
48
+ }
49
+
50
+ void OnOK() override {
51
+ HandleScope scope(Env());
52
+ if (result_processor_) {
53
+ result_processor_(this, Env());
54
+ } else {
55
+ Callback().Call({Env().Null(), String::New(Env(), result_)});
56
+ }
57
+ }
58
+
59
+ void OnError(const Error& e) override {
60
+ HandleScope scope(Env());
61
+ Callback().Call({e.Value(), Env().Undefined()});
62
+ }
63
+
64
+ void SetResult(std::string result) {
65
+ result_ = std::move(result);
66
+ }
67
+
68
+ void SetWorkerError(const std::string& msg) {
69
+ SetError(msg);
70
+ }
71
+
72
+ const std::string& GetStringResult() const {
73
+ return result_;
74
+ }
75
+
76
+ void SetCtrl(uintptr_t ctrl) {
77
+ ctrl_ = ctrl;
78
+ }
79
+
80
+ uintptr_t GetCtrl() const {
81
+ return ctrl_;
82
+ }
83
+
84
+ protected:
85
+ std::string result_;
86
+ uintptr_t ctrl_ = 0;
87
+
88
+ private:
89
+ ExecuteFn execute_fn_;
90
+ ResultProcessor result_processor_;
91
+ };
92
+
93
+ class BinaryAsyncWorker : public AsyncWorker {
94
+ public:
95
+ using ExecuteFn = std::function<void(BinaryAsyncWorker*)>;
96
+
97
+ BinaryAsyncWorker(Function& callback, ExecuteFn execute_fn)
98
+ : AsyncWorker(callback), execute_fn_(std::move(execute_fn)) {}
99
+
100
+ void Execute() override {
101
+ execute_fn_(this);
102
+ }
103
+
104
+ void OnOK() override {
105
+ HandleScope scope(Env());
106
+ if (original_buf == nullptr || binary_len == 0) {
107
+ Callback().Call({Env().Null(), Env().Undefined()});
108
+ return;
109
+ }
110
+ char* data_ptr = original_buf + 5;
111
+ auto finalizer = [](Napi::Env env, char* finalize_data, char* orig) {
112
+ free(orig);
113
+ };
114
+ Napi::Buffer<char> buffer = Napi::Buffer<char>::New(Env(), data_ptr, binary_len, finalizer, original_buf);
115
+ Callback().Call({Env().Null(), buffer});
116
+ }
117
+
118
+ void OnError(const Error& e) override {
119
+ HandleScope scope(Env());
120
+ Callback().Call({e.Value(), Env().Undefined()});
121
+ }
122
+
123
+ void SetWorkerError(const std::string& msg) {
124
+ SetError(msg);
125
+ }
126
+
127
+ char* original_buf = nullptr;
128
+ size_t binary_len = 0;
129
+
130
+ private:
131
+ ExecuteFn execute_fn_;
132
+ };
133
+
134
+ // Helper for converting chat_ctrl pointer to BigInt
135
+ Napi::BigInt ToChatCtrlBigInt(Napi::Env env, uintptr_t ctrl) {
136
+ return Napi::BigInt::New(env, static_cast<uint64_t>(ctrl));
137
+ }
138
+
139
+ // Helper for converting BigInt to chat_ctrl pointer
140
+ chat_ctrl FromChatCtrlBigInt(const Napi::Value& value) {
141
+ Napi::Env env = value.Env();
142
+ if (!value.IsBigInt()) {
143
+ Napi::TypeError::New(env, "Expected BigInt for ctrl").ThrowAsJavaScriptException();
144
+ return nullptr;
145
+ }
146
+ Napi::BigInt big = value.As<Napi::BigInt>();
147
+ bool lossless;
148
+ uint64_t val = big.Uint64Value(&lossless);
149
+ if (!lossless) {
150
+ Napi::TypeError::New(env, "BigInt too large for ctrl").ThrowAsJavaScriptException();
151
+ return nullptr;
152
+ }
153
+ return reinterpret_cast<chat_ctrl>(val);
154
+ }
155
+
156
+ // Helper for handling common C result patterns (no empty check)
157
+ void HandleCResult(ResultAsyncWorker* worker, char* c_res, const std::string& func_name) {
158
+ if (c_res == nullptr) {
159
+ worker->SetWorkerError(func_name + " failed");
160
+ return;
161
+ }
162
+ std::string res = c_res;
163
+ free(c_res);
164
+ worker->SetResult(res);
165
+ }
166
+
167
+ Napi::Promise CreatePromiseAndCallback(Env env, Function& cb_out) {
168
+ Promise::Deferred deferred = Promise::Deferred::New(env);
169
+ cb_out = Function::New(env, [deferred](const CallbackInfo& args) {
170
+ if (!args[0].IsNull() && !args[0].IsUndefined()) {
171
+ deferred.Reject(args[0]);
172
+ } else {
173
+ deferred.Resolve(args[1]);
174
+ }
175
+ });
176
+ return deferred.Promise();
177
+ }
178
+
179
+ // Common result processors
180
+ ResultAsyncWorker::ResultProcessor MigrateResultProcessor() {
181
+ return [](ResultAsyncWorker* worker, Napi::Env env) {
182
+ Napi::Array arr = Napi::Array::New(env, 2);
183
+ arr.Set(0u, ToChatCtrlBigInt(env, worker->GetCtrl()));
184
+ arr.Set(1u, Napi::String::New(env, worker->GetStringResult()));
185
+ worker->Callback().Call({env.Null(), arr});
186
+ };
187
+ }
188
+
189
+ // Refactored functions using common patterns
190
+
191
+ Value ChatMigrateInit(const CallbackInfo& args) {
192
+ Env env = args.Env();
193
+ if (args.Length() < 3 || !args[0].IsString() || !args[1].IsString() || !args[2].IsString()) {
194
+ TypeError::New(env, "Expected three string arguments").ThrowAsJavaScriptException();
195
+ return env.Undefined();
196
+ }
197
+
198
+ std::string path = args[0].As<String>().Utf8Value();
199
+ std::string key = args[1].As<String>().Utf8Value();
200
+ std::string confirm = args[2].As<String>().Utf8Value();
201
+
202
+ Function cb;
203
+ Promise promise = CreatePromiseAndCallback(env, cb);
204
+
205
+ auto execute_fn = [path, key, confirm](ResultAsyncWorker* worker) {
206
+ chat_ctrl ctrl = nullptr;
207
+ char* c_res = chat_migrate_init(path.c_str(), key.c_str(), confirm.c_str(), &ctrl);
208
+ worker->SetCtrl(reinterpret_cast<uintptr_t>(ctrl));
209
+ HandleCResult(worker, c_res, "chat_migrate_init");
210
+ };
211
+
212
+ ResultAsyncWorker* worker = new ResultAsyncWorker(cb, std::move(execute_fn), MigrateResultProcessor());
213
+ worker->Queue();
214
+
215
+ return promise;
216
+ }
217
+
218
+ Value ChatCloseStore(const CallbackInfo& args) {
219
+ Env env = args.Env();
220
+ if (args.Length() < 1 || !args[0].IsBigInt()) {
221
+ TypeError::New(env, "Expected bigint (ctrl)").ThrowAsJavaScriptException();
222
+ return env.Undefined();
223
+ }
224
+
225
+ chat_ctrl ctrl = FromChatCtrlBigInt(args[0]);
226
+
227
+ Function cb;
228
+ Promise promise = CreatePromiseAndCallback(env, cb);
229
+
230
+ auto execute_fn = [ctrl](ResultAsyncWorker* worker) {
231
+ char* c_res = chat_close_store(ctrl);
232
+ HandleCResult(worker, c_res, "chat_close_store");
233
+ };
234
+
235
+ ResultAsyncWorker* worker = new ResultAsyncWorker(cb, std::move(execute_fn));
236
+ worker->Queue();
237
+
238
+ return promise;
239
+ }
240
+
241
+ Value ChatSendCmd(const CallbackInfo& args) {
242
+ Env env = args.Env();
243
+ if (args.Length() < 2 || !args[0].IsBigInt() || !args[1].IsString()) {
244
+ TypeError::New(env, "Expected bigint (ctrl) and string (cmd)").ThrowAsJavaScriptException();
245
+ return env.Undefined();
246
+ }
247
+
248
+ chat_ctrl ctrl = FromChatCtrlBigInt(args[0]);
249
+ std::string cmd = args[1].As<String>().Utf8Value();
250
+
251
+ Function cb;
252
+ Promise promise = CreatePromiseAndCallback(env, cb);
253
+
254
+ auto execute_fn = [ctrl, cmd](ResultAsyncWorker* worker) {
255
+ char* c_res = chat_send_cmd(ctrl, cmd.c_str());
256
+ HandleCResult(worker, c_res, "chat_send_cmd");
257
+ };
258
+
259
+ ResultAsyncWorker* worker = new ResultAsyncWorker(cb, std::move(execute_fn));
260
+ worker->Queue();
261
+
262
+ return promise;
263
+ }
264
+
265
+ Value ChatRecvMsgWait(const CallbackInfo& args) {
266
+ Env env = args.Env();
267
+ if (args.Length() < 2 || !args[0].IsBigInt() || !args[1].IsNumber()) {
268
+ TypeError::New(env, "Expected bigint (ctrl), number (wait)").ThrowAsJavaScriptException();
269
+ return env.Undefined();
270
+ }
271
+
272
+ chat_ctrl ctrl = FromChatCtrlBigInt(args[0]);
273
+ int wait = static_cast<int>(args[1].As<Number>().Int32Value());
274
+
275
+ Function cb;
276
+ Promise promise = CreatePromiseAndCallback(env, cb);
277
+
278
+ auto execute_fn = [ctrl, wait](ResultAsyncWorker* worker) {
279
+ char* c_res = chat_recv_msg_wait(ctrl, wait);
280
+ HandleCResult(worker, c_res, "chat_recv_msg_wait");
281
+ };
282
+
283
+ ResultAsyncWorker* worker = new ResultAsyncWorker(cb, std::move(execute_fn));
284
+ worker->Queue();
285
+
286
+ return promise;
287
+ }
288
+
289
+ Value ChatWriteFile(const CallbackInfo& args) {
290
+ Env env = args.Env();
291
+ if (args.Length() < 3 || !args[0].IsBigInt() || !args[1].IsString() || !args[2].IsArrayBuffer()) {
292
+ TypeError::New(env, "Expected bigint (ctrl), string (path), ArrayBuffer").ThrowAsJavaScriptException();
293
+ return env.Undefined();
294
+ }
295
+
296
+ chat_ctrl ctrl = FromChatCtrlBigInt(args[0]);
297
+ std::string path = args[1].As<String>().Utf8Value();
298
+ ArrayBuffer ab = args[2].As<ArrayBuffer>();
299
+ char* data = static_cast<char*>(ab.Data());
300
+ size_t len = ab.ByteLength();
301
+
302
+ Function cb;
303
+ Promise promise = CreatePromiseAndCallback(env, cb);
304
+
305
+ auto execute_fn = [ctrl, path, ab, data, len](ResultAsyncWorker* worker) {
306
+ (void)ab; // to keep ArrayBuffer alive
307
+ char* c_res = chat_write_file(ctrl, path.c_str(), data, static_cast<int>(len));
308
+ HandleCResult(worker, c_res, "chat_write_file");
309
+ };
310
+
311
+ ResultAsyncWorker* worker = new ResultAsyncWorker(cb, std::move(execute_fn));
312
+ worker->Queue();
313
+
314
+ return promise;
315
+ }
316
+
317
+ Value ChatReadFile(const CallbackInfo& args) {
318
+ Env env = args.Env();
319
+ if (args.Length() < 3 || !args[0].IsString() || !args[1].IsString() || !args[2].IsString()) {
320
+ TypeError::New(env, "Expected three strings (path, key, nonce)").ThrowAsJavaScriptException();
321
+ return env.Undefined();
322
+ }
323
+
324
+ std::string path = args[0].As<String>().Utf8Value();
325
+ std::string key = args[1].As<String>().Utf8Value();
326
+ std::string nonce = args[2].As<String>().Utf8Value();
327
+
328
+ Function cb;
329
+ Promise promise = CreatePromiseAndCallback(env, cb);
330
+
331
+ auto execute_fn = [path, key, nonce](BinaryAsyncWorker* worker) {
332
+ char* buf = chat_read_file(path.c_str(), key.c_str(), nonce.c_str());
333
+ if (buf == nullptr) {
334
+ worker->SetWorkerError("chat_read_file failed");
335
+ return;
336
+ }
337
+ char status = buf[0];
338
+ if (status == 1) {
339
+ std::string err = buf + 1;
340
+ free(buf);
341
+ worker->SetWorkerError(err);
342
+ return;
343
+ } else if (status == 0) {
344
+ uint32_t len = *(uint32_t*)(buf + 1);
345
+ worker->original_buf = buf;
346
+ worker->binary_len = len;
347
+ } else {
348
+ free(buf);
349
+ worker->SetWorkerError("Unexpected status from chat_read_file");
350
+ return;
351
+ }
352
+ };
353
+
354
+ BinaryAsyncWorker* worker = new BinaryAsyncWorker(cb, std::move(execute_fn));
355
+ worker->Queue();
356
+
357
+ return promise;
358
+ }
359
+
360
+ Value ChatEncryptFile(const CallbackInfo& args) {
361
+ Env env = args.Env();
362
+ if (args.Length() < 3 || !args[0].IsBigInt() || !args[1].IsString() || !args[2].IsString()) {
363
+ TypeError::New(env, "Expected bigint (ctrl), two strings (fromPath, toPath)").ThrowAsJavaScriptException();
364
+ return env.Undefined();
365
+ }
366
+
367
+ chat_ctrl ctrl = FromChatCtrlBigInt(args[0]);
368
+ std::string fromPath = args[1].As<String>().Utf8Value();
369
+ std::string toPath = args[2].As<String>().Utf8Value();
370
+
371
+ Function cb;
372
+ Promise promise = CreatePromiseAndCallback(env, cb);
373
+
374
+ auto execute_fn = [ctrl, fromPath, toPath](ResultAsyncWorker* worker) {
375
+ char* c_res = chat_encrypt_file(ctrl, fromPath.c_str(), toPath.c_str());
376
+ HandleCResult(worker, c_res, "chat_encrypt_file");
377
+ };
378
+
379
+ ResultAsyncWorker* worker = new ResultAsyncWorker(cb, std::move(execute_fn));
380
+ worker->Queue();
381
+
382
+ return promise;
383
+ }
384
+
385
+ Value ChatDecryptFile(const CallbackInfo& args) {
386
+ Env env = args.Env();
387
+ if (args.Length() < 4 || !args[0].IsString() || !args[1].IsString() || !args[2].IsString() || !args[3].IsString()) {
388
+ TypeError::New(env, "Expected four strings (fromPath, key, nonce, toPath)").ThrowAsJavaScriptException();
389
+ return env.Undefined();
390
+ }
391
+
392
+ std::string fromPath = args[0].As<String>().Utf8Value();
393
+ std::string key = args[1].As<String>().Utf8Value();
394
+ std::string nonce = args[2].As<String>().Utf8Value();
395
+ std::string toPath = args[3].As<String>().Utf8Value();
396
+
397
+ Function cb;
398
+ Promise promise = CreatePromiseAndCallback(env, cb);
399
+
400
+ auto execute_fn = [fromPath, key, nonce, toPath](ResultAsyncWorker* worker) {
401
+ char* c_res = chat_decrypt_file(fromPath.c_str(), key.c_str(), nonce.c_str(), toPath.c_str());
402
+ HandleCResult(worker, c_res, "chat_decrypt_file");
403
+ };
404
+
405
+ ResultAsyncWorker* worker = new ResultAsyncWorker(cb, std::move(execute_fn));
406
+ worker->Queue();
407
+
408
+ return promise;
409
+ }
410
+
411
+ Object Init(Env env, Object exports) {
412
+ haskell_init();
413
+ exports.Set("chat_migrate_init", Function::New(env, ChatMigrateInit));
414
+ exports.Set("chat_close_store", Function::New(env, ChatCloseStore));
415
+ exports.Set("chat_send_cmd", Function::New(env, ChatSendCmd));
416
+ exports.Set("chat_recv_msg_wait", Function::New(env, ChatRecvMsgWait));
417
+ exports.Set("chat_write_file", Function::New(env, ChatWriteFile));
418
+ exports.Set("chat_read_file", Function::New(env, ChatReadFile));
419
+ exports.Set("chat_encrypt_file", Function::New(env, ChatEncryptFile));
420
+ exports.Set("chat_decrypt_file", Function::New(env, ChatDecryptFile));
421
+ return exports;
422
+ }
423
+
424
+ NODE_API_MODULE(simplex, Init)
425
+
426
+ }
package/cpp/simplex.h ADDED
@@ -0,0 +1,46 @@
1
+ //
2
+ // simplex.h
3
+ // SimpleX
4
+ //
5
+ // Created by Evgeny on 30/05/2022.
6
+ // Copyright © 2022 SimpleX Chat. All rights reserved.
7
+ //
8
+
9
+ #ifndef SimpleX_h
10
+ #define SimpleX_h
11
+
12
+ extern "C" void hs_init(int argc, char **argv[]);
13
+ extern "C" void hs_init_with_rtsopts(int * argc, char **argv[]);
14
+
15
+ typedef long* chat_ctrl;
16
+
17
+ // the last parameter is used to return the pointer to chat controller
18
+ extern "C" char *chat_migrate_init(const char *path, const char *key, const char *confirm, chat_ctrl *ctrl);
19
+ extern "C" char *chat_close_store(chat_ctrl ctrl);
20
+ extern "C" char *chat_reopen_store(chat_ctrl ctrl);
21
+ extern "C" char *chat_send_cmd(chat_ctrl ctrl, const char *cmd);
22
+ extern "C" char *chat_recv_msg_wait(chat_ctrl ctrl, const int wait);
23
+ extern "C" char *chat_parse_markdown(const char *str);
24
+ extern "C" char *chat_parse_server(const char *str);
25
+ extern "C" char *chat_password_hash(const char *pwd, const char *salt);
26
+ extern "C" char *chat_valid_name(const char *name);
27
+ extern "C" int chat_json_length(const char *str);
28
+ extern "C" char *chat_encrypt_media(chat_ctrl ctrl, const char *key, const char *frame, const int len);
29
+ extern "C" char *chat_decrypt_media(const char *key, const char *frame, const int len);
30
+
31
+ // chat_write_file returns null-terminated string with JSON of WriteFileResult
32
+ extern "C" char *chat_write_file(chat_ctrl ctrl, const char *path, const char *data, const int len);
33
+
34
+ // chat_read_file returns a buffer with:
35
+ // result status (1 byte), then if
36
+ // status == 0 (success): buffer length (uint32, 4 bytes), buffer of specified length.
37
+ // status == 1 (error): null-terminated error message string.
38
+ extern "C" char *chat_read_file(const char *path, const char *key, const char *nonce);
39
+
40
+ // chat_encrypt_file returns null-terminated string with JSON of WriteFileResult
41
+ extern "C" char *chat_encrypt_file(chat_ctrl ctrl, const char *fromPath, const char *toPath);
42
+
43
+ // chat_decrypt_file returns null-terminated string with the error message
44
+ extern "C" char *chat_decrypt_file(const char *fromPath, const char *key, const char *nonce, const char *toPath);
45
+
46
+ #endif /* simplex_h */
package/dist/index.d.ts CHANGED
@@ -1,4 +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
+ */
1
15
  export * as core from "./core";
16
+ /**
17
+ * Useful functions for chat events and types.
18
+ */
2
19
  export * as util from "./util";
3
- export * as api from "./api";
4
- export * as bot from "./bot";
package/dist/index.js CHANGED
@@ -1,8 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bot = exports.api = exports.util = exports.core = void 0;
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
+ */
4
18
  exports.core = require("./core");
19
+ /**
20
+ * Useful functions for chat events and types.
21
+ */
5
22
  exports.util = require("./util");
6
- exports.api = require("./api");
7
- exports.bot = require("./bot");
8
23
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAC9B,iCAA8B;AAC9B,+BAA4B;AAC5B,+BAA4B"}
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"}
@@ -0,0 +1,32 @@
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
+ - [EventSubscriberFunc](api.TypeAlias.EventSubscriberFunc.md)
28
+ - [EventSubscribers](api.TypeAlias.EventSubscribers.md)
29
+
30
+ ## Variables
31
+
32
+ - [defaultBotAddressSettings](api.Variable.defaultBotAddressSettings.md)
@@ -0,0 +1,20 @@
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
+ - [BotDbOpts](bot.Interface.BotDbOpts.md)
16
+ - [BotOptions](bot.Interface.BotOptions.md)
17
+
18
+ ## Functions
19
+
20
+ - [run](bot.Function.run.md)
@@ -0,0 +1,48 @@
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
+ - [DBMigrationError](core.TypeAlias.DBMigrationError.md)
36
+ - [MigrationError](core.TypeAlias.MigrationError.md)
37
+ - [MTRError](core.TypeAlias.MTRError.md)
38
+
39
+ ## Functions
40
+
41
+ - [chatCloseStore](core.Function.chatCloseStore.md)
42
+ - [chatDecryptFile](core.Function.chatDecryptFile.md)
43
+ - [chatEncryptFile](core.Function.chatEncryptFile.md)
44
+ - [chatMigrateInit](core.Function.chatMigrateInit.md)
45
+ - [chatReadFile](core.Function.chatReadFile.md)
46
+ - [chatRecvMsgWait](core.Function.chatRecvMsgWait.md)
47
+ - [chatSendCmd](core.Function.chatSendCmd.md)
48
+ - [chatWriteFile](core.Function.chatWriteFile.md)