simplex-chat 0.2.1 → 6.5.0-beta.10

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 (116) hide show
  1. package/README.md +108 -21
  2. package/binding.gyp +50 -0
  3. package/cpp/simplex.cc +426 -0
  4. package/cpp/simplex.h +46 -0
  5. package/dist/api.d.ts +423 -0
  6. package/dist/api.js +857 -0
  7. package/dist/api.js.map +1 -0
  8. package/dist/bot.d.ts +29 -0
  9. package/dist/bot.js +189 -0
  10. package/dist/bot.js.map +1 -0
  11. package/dist/core.d.ts +128 -0
  12. package/dist/core.js +121 -0
  13. package/dist/core.js.map +1 -0
  14. package/dist/index.d.ts +19 -2
  15. package/dist/index.js +20 -4
  16. package/dist/index.js.map +1 -1
  17. package/dist/simplex.d.ts +10 -0
  18. package/dist/simplex.js +1 -0
  19. package/dist/util.d.ts +15 -0
  20. package/dist/util.js +91 -0
  21. package/dist/util.js.map +1 -0
  22. package/docs/Namespace.api.md +33 -0
  23. package/docs/Namespace.bot.md +23 -0
  24. package/docs/Namespace.core.md +48 -0
  25. package/docs/Namespace.util.md +25 -0
  26. package/docs/README.md +12 -0
  27. package/docs/api.Class.ChatApi.md +1752 -0
  28. package/docs/api.Class.ChatCommandError.md +205 -0
  29. package/docs/api.Enumeration.ConnReqType.md +27 -0
  30. package/docs/api.Interface.BotAddressSettings.md +60 -0
  31. package/docs/api.TypeAlias.DbConfig.md +64 -0
  32. package/docs/api.TypeAlias.EventSubscriberFunc.md +27 -0
  33. package/docs/api.TypeAlias.EventSubscribers.md +11 -0
  34. package/docs/api.Variable.defaultBotAddressSettings.md +11 -0
  35. package/docs/bot.Function.run.md +21 -0
  36. package/docs/bot.Interface.BotConfig.md +75 -0
  37. package/docs/bot.Interface.BotOptions.md +81 -0
  38. package/docs/bot.TypeAlias.BotDbOpts.md +17 -0
  39. package/docs/core.Class.ChatAPIError.md +205 -0
  40. package/docs/core.Class.ChatInitError.md +205 -0
  41. package/docs/core.DBMigrationError.Interface.ErrorMigration.md +41 -0
  42. package/docs/core.DBMigrationError.Interface.ErrorNotADatabase.md +33 -0
  43. package/docs/core.DBMigrationError.Interface.ErrorSQL.md +41 -0
  44. package/docs/core.DBMigrationError.Interface.InvalidConfirmation.md +25 -0
  45. package/docs/core.DBMigrationError.TypeAlias.Tag.md +11 -0
  46. package/docs/core.Enumeration.MigrationConfirmation.md +43 -0
  47. package/docs/core.Function.chatCloseStore.md +23 -0
  48. package/docs/core.Function.chatDecryptFile.md +31 -0
  49. package/docs/core.Function.chatEncryptFile.md +31 -0
  50. package/docs/core.Function.chatMigrateInit.md +31 -0
  51. package/docs/core.Function.chatReadFile.md +27 -0
  52. package/docs/core.Function.chatRecvMsgWait.md +27 -0
  53. package/docs/core.Function.chatSendCmd.md +27 -0
  54. package/docs/core.Function.chatWriteFile.md +31 -0
  55. package/docs/core.Interface.APIResult.md +31 -0
  56. package/docs/core.Interface.CryptoArgs.md +27 -0
  57. package/docs/core.Interface.UpMigration.md +25 -0
  58. package/docs/core.MTRError.Interface.MTREDifferent.md +33 -0
  59. package/docs/core.MTRError.Interface.MTRENoDown.md +33 -0
  60. package/docs/core.MTRError.TypeAlias.Tag.md +11 -0
  61. package/docs/core.MigrationError.Interface.MEDowngrade.md +33 -0
  62. package/docs/core.MigrationError.Interface.MEUpgrade.md +33 -0
  63. package/docs/core.MigrationError.Interface.MigrationError.md +33 -0
  64. package/docs/core.MigrationError.TypeAlias.Tag.md +11 -0
  65. package/docs/core.Namespace.DBMigrationError.md +18 -0
  66. package/docs/core.Namespace.MTRError.md +16 -0
  67. package/docs/core.Namespace.MigrationError.md +17 -0
  68. package/docs/core.TypeAlias.DBMigrationError.md +11 -0
  69. package/docs/core.TypeAlias.MTRError.md +11 -0
  70. package/docs/core.TypeAlias.MigrationError.md +11 -0
  71. package/docs/util.Function.botAddressSettings.md +21 -0
  72. package/docs/util.Function.chatInfoName.md +21 -0
  73. package/docs/util.Function.chatInfoRef.md +21 -0
  74. package/docs/util.Function.ciBotCommand.md +21 -0
  75. package/docs/util.Function.ciContentText.md +21 -0
  76. package/docs/util.Function.contactAddressStr.md +21 -0
  77. package/docs/util.Function.fromLocalProfile.md +21 -0
  78. package/docs/util.Function.reactionText.md +21 -0
  79. package/docs/util.Function.senderName.md +25 -0
  80. package/docs/util.Interface.BotCommand.md +25 -0
  81. package/examples/squaring-bot-pg.js +21 -0
  82. package/examples/squaring-bot-readme.js +17 -0
  83. package/examples/squaring-bot.ts +42 -0
  84. package/package.json +34 -37
  85. package/src/api.ts +939 -0
  86. package/src/bot.ts +214 -0
  87. package/src/core.ts +210 -0
  88. package/src/download-libs.js +239 -0
  89. package/src/index.ts +22 -0
  90. package/src/simplex.d.ts +10 -0
  91. package/src/simplex.js +1 -0
  92. package/src/util.ts +92 -0
  93. package/tsconfig.json +23 -0
  94. package/dist/client.d.ts +0 -76
  95. package/dist/client.js +0 -329
  96. package/dist/client.js.map +0 -1
  97. package/dist/command.d.ts +0 -412
  98. package/dist/command.js +0 -186
  99. package/dist/command.js.map +0 -1
  100. package/dist/index-web.d.ts +0 -1
  101. package/dist/index-web.js +0 -6
  102. package/dist/index-web.js.map +0 -1
  103. package/dist/index.bundle.js +0 -11
  104. package/dist/queue.d.ts +0 -24
  105. package/dist/queue.js +0 -77
  106. package/dist/queue.js.map +0 -1
  107. package/dist/response.d.ts +0 -755
  108. package/dist/response.js +0 -21
  109. package/dist/response.js.map +0 -1
  110. package/dist/test.html +0 -7
  111. package/dist/transport.d.ts +0 -51
  112. package/dist/transport.js +0 -131
  113. package/dist/transport.js.map +0 -1
  114. package/dist/websocket.d.ts +0 -8
  115. package/dist/websocket.js +0 -4
  116. package/dist/websocket.js.map +0 -1
@@ -0,0 +1,21 @@
1
+ [**simplex-chat**](README.md)
2
+
3
+ ***
4
+
5
+ [simplex-chat](README.md) / [util](Namespace.util.md) / reactionText
6
+
7
+ # Function: reactionText()
8
+
9
+ > **reactionText**(`reaction`): `string`
10
+
11
+ Defined in: [src/util.ts:89](../src/util.ts#L89)
12
+
13
+ ## Parameters
14
+
15
+ ### reaction
16
+
17
+ `ACIReaction`
18
+
19
+ ## Returns
20
+
21
+ `string`
@@ -0,0 +1,25 @@
1
+ [**simplex-chat**](README.md)
2
+
3
+ ***
4
+
5
+ [simplex-chat](README.md) / [util](Namespace.util.md) / senderName
6
+
7
+ # Function: senderName()
8
+
9
+ > **senderName**(`cInfo`, `chatDir`): `string`
10
+
11
+ Defined in: [src/util.ts:37](../src/util.ts#L37)
12
+
13
+ ## Parameters
14
+
15
+ ### cInfo
16
+
17
+ `ChatInfo`
18
+
19
+ ### chatDir
20
+
21
+ `CIDirection`
22
+
23
+ ## Returns
24
+
25
+ `string`
@@ -0,0 +1,25 @@
1
+ [**simplex-chat**](README.md)
2
+
3
+ ***
4
+
5
+ [simplex-chat](README.md) / [util](Namespace.util.md) / BotCommand
6
+
7
+ # Interface: BotCommand
8
+
9
+ Defined in: [src/util.ts:72](../src/util.ts#L72)
10
+
11
+ ## Properties
12
+
13
+ ### keyword
14
+
15
+ > **keyword**: `string`
16
+
17
+ Defined in: [src/util.ts:73](../src/util.ts#L73)
18
+
19
+ ***
20
+
21
+ ### params
22
+
23
+ > **params**: `string`
24
+
25
+ Defined in: [src/util.ts:74](../src/util.ts#L74)
@@ -0,0 +1,21 @@
1
+ (async () => {
2
+ const {bot} = await import("../dist/index.js")
3
+ const [chat, user, address] = await bot.run({
4
+ profile: {displayName: "Test PG bot", fullName: ""},
5
+ dbOpts: {
6
+ dbFilePrefix: "bot",
7
+ dbKey: "postgresql:///postgres?host=/tmp/pgsocket&port=5433&user=builder"
8
+ },
9
+ options: {
10
+ addressSettings: {welcomeMessage: "Send a number, I will square it."},
11
+ },
12
+ onMessage: async (ci, content) => {
13
+ var num = Number(content.text)
14
+ var reply = !isNaN(num) ? num + " * " + num + " = " + (num * num) : "this is not a number"
15
+ await chat.apiSendTextReply(ci, reply)
16
+ }
17
+ })
18
+ console.log("Bot running!")
19
+ console.log("User:", user.localDisplayName)
20
+ if (address) console.log("Address:", address.connLinkContact.connFullLink)
21
+ })()
@@ -0,0 +1,17 @@
1
+ (async () => {
2
+ const {bot} = await import("../dist/index.js")
3
+ const [chat, _user, _address] = await bot.run({
4
+ profile: {displayName: "Squaring bot example", fullName: ""},
5
+ dbOpts: {type: "sqlite", filePrefix: "./squaring_bot"},
6
+ options: {
7
+ addressSettings: {welcomeMessage: "Send a number, I will square it."},
8
+ },
9
+ onMessage: async (ci, content) => {
10
+ const n = +content.text
11
+ const reply = typeof n === "number" && !isNaN(n)
12
+ ? `${n} * ${n} = ${n * n}`
13
+ : `this is not a number`
14
+ await chat.apiSendTextReply(ci, reply)
15
+ }
16
+ })
17
+ })()
@@ -0,0 +1,42 @@
1
+ import {T} from "@simplex-chat/types"
2
+ import {bot, util} from "../dist"
3
+
4
+ (async () => {
5
+ const welcomeMessage = "Hello! I am a simple squaring bot.\n\nIf you send me a number, I will calculate its square."
6
+ const [chat, _user, _address] = await bot.run({
7
+ profile: {displayName: "Squaring bot example", fullName: ""},
8
+ dbOpts: {type: "sqlite", filePrefix: "./squaring_bot"},
9
+ options: {
10
+ addressSettings: {autoAccept: true, welcomeMessage, businessAddress: false},
11
+ commands: [ // commands to show in client UI
12
+ {type: "command", keyword: "help", label: "Send welcome message"},
13
+ {type: "command", keyword: "info", label: "More information (not implemented)"}
14
+ ],
15
+ logContacts: true,
16
+ logNetwork: false
17
+ },
18
+ onMessage: async (ci, content) => {
19
+ const n = +content.text
20
+ const reply = typeof n === "number" && !isNaN(n)
21
+ ? `${n} * ${n} = ${n * n}`
22
+ : `this is not a number`
23
+ await chat.apiSendTextReply(ci, reply)
24
+ },
25
+ onCommands: { // command handlers can be different from commands to be shown in client UI
26
+ "help": async (ci: T.AChatItem, _cmd: util.BotCommand) => {
27
+ await chat.apiSendTextMessage(ci.chatInfo, welcomeMessage)
28
+ },
29
+ // fallback handler that will be called for all other commands
30
+ "": async (ci: T.AChatItem, _cmd: util.BotCommand) => {
31
+ await chat.apiSendTextReply(ci, "This command is not supported")
32
+ }
33
+ },
34
+ // If you use `onMessage` and subscribe to "newChatItems" event, exclude content messages from processing
35
+ // If you use `onCommands` and subscribe to "newChatItems" event, exclude commands from processing
36
+ events: {
37
+ "chatItemReaction": ({added, reaction}) => {
38
+ console.log(`${util.senderName(reaction.chatInfo, reaction.chatReaction.chatDir)} ${added ? "added" : "removed"} reaction ${util.reactionText(reaction)}`)
39
+ }
40
+ },
41
+ })
42
+ })()
package/package.json CHANGED
@@ -1,19 +1,42 @@
1
1
  {
2
2
  "name": "simplex-chat",
3
- "version": "0.2.1",
4
- "description": "SimpleX Chat client",
3
+ "version": "6.5.0-beta.10",
5
4
  "main": "dist/index.js",
6
5
  "types": "dist/index.d.ts",
7
6
  "files": [
8
- "dist"
7
+ "src",
8
+ "cpp",
9
+ "dist",
10
+ "binding.gyp",
11
+ "tsconfig.json",
12
+ "docs",
13
+ "examples"
9
14
  ],
10
15
  "scripts": {
11
- "test": "npm run prettier:check && npm run eslint && jest --coverage",
12
- "build": "npm run prettier:write && npm run eslint && tsc && ./copy && npm run bundle",
13
- "bundle": "rollup dist/index-web.js --file dist/index.bundle.js --format umd --name simplex",
14
- "eslint": "eslint --ext .ts ./src/**/*.ts",
15
- "prettier:write": "prettier --write './**/*.{json,yaml,js,ts}'",
16
- "prettier:check": "prettier --list-different './**/*.{json,yaml,js,ts}'"
16
+ "preinstall": "node src/download-libs.js",
17
+ "install": "node-gyp configure; node-gyp rebuild --release",
18
+ "install-tools": "npm install -g node-gyp",
19
+ "configure": "node-gyp configure; mkdir libs 2> /dev/null | true",
20
+ "build": "node-gyp rebuild && tsc && cp ./src/simplex.* ./dist",
21
+ "run": "node src/index.js",
22
+ "build-run": "node-gyp build && node src/index.js",
23
+ "test": "jest",
24
+ "docs": "typedoc"
25
+ },
26
+ "dependencies": {
27
+ "@simplex-chat/types": "^0.5.0",
28
+ "extract-zip": "^2.0.1",
29
+ "fast-deep-equal": "^3.1.3",
30
+ "node-addon-api": "^8.5.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/jest": "^30.0.0",
34
+ "@types/node": "^25.0.5",
35
+ "jest": "^30.2.0",
36
+ "ts-jest": "^29.4.6",
37
+ "typedoc": "^0.28.15",
38
+ "typedoc-plugin-markdown": "^4.9.0",
39
+ "typescript": "^5.9.3"
17
40
  },
18
41
  "repository": {
19
42
  "type": "git",
@@ -30,32 +53,6 @@
30
53
  "bugs": {
31
54
  "url": "https://github.com/simplex-chat/simplex-chat/issues"
32
55
  },
33
- "homepage": "https://github.com/simplex-chat/simplex-chat/packages/simplex-chat-client/typescript#readme",
34
- "dependencies": {
35
- "isomorphic-ws": "^4.0.1"
36
- },
37
- "devDependencies": {
38
- "@types/jest": "^27.5.1",
39
- "@types/node": "^18.11.18",
40
- "@typescript-eslint/eslint-plugin": "^5.23.0",
41
- "@typescript-eslint/parser": "^5.23.0",
42
- "eslint": "^8.15.0",
43
- "eslint-config-prettier": "^8.5.0",
44
- "husky": "^7.0.4",
45
- "jest": "^28.1.0",
46
- "lint-staged": "^12.3.8",
47
- "prettier": "^2.6.2",
48
- "rollup": "^2.72.1",
49
- "ts-jest": "^28.0.2",
50
- "ts-node": "^10.7.0",
51
- "typescript": "^4.9.3"
52
- },
53
- "husky": {
54
- "hooks": {
55
- "pre-commit": "lint-staged"
56
- }
57
- },
58
- "lint-staged": {
59
- "**/*": "prettier --write --ignore-unknown"
60
- }
56
+ "homepage": "https://github.com/simplex-chat/simplex-chat/tree/stable/packages/simplex-chat-nodejs#readme",
57
+ "description": "SimpleX Chat Node.js library for chat bots"
61
58
  }