@awiki/im-core-node 0.1.0
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.
- package/COMMERCIAL-LICENSING.md +222 -0
- package/LICENSE +661 -0
- package/NOTICE.md +3 -0
- package/README.md +57 -0
- package/SOURCE.md +9 -0
- package/checksums.json +117 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +4 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +46 -0
- package/dist/loader.js.map +1 -0
- package/dist/native.d.ts +25 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +2 -0
- package/dist/native.js.map +1 -0
- package/dist/targets.d.ts +6 -0
- package/dist/targets.d.ts.map +1 -0
- package/dist/targets.js +23 -0
- package/dist/targets.js.map +1 -0
- package/dist/types.d.ts +184 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/package.json +46 -0
- package/provenance.json +27 -0
- package/sbom.cdx.json +4359 -0
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @awiki/im-core-node
|
|
2
|
+
|
|
3
|
+
`@awiki/im-core-node` 是 `awiki-im-core` 的 Node.js Promise facade。包只暴露 AWiki IM
|
|
4
|
+
领域 DTO,不包含 DSH、Cordis、SQLite、redb、ANP wire 或 Rust internal 类型。
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { openImCoreNodeClient } from '@awiki/im-core-node'
|
|
8
|
+
|
|
9
|
+
const client = await openImCoreNodeClient({
|
|
10
|
+
stateRoot: '/absolute/private/path/awiki/im-core',
|
|
11
|
+
serviceBaseUrl: 'https://awiki.info',
|
|
12
|
+
didDomain: 'awiki.info',
|
|
13
|
+
userServiceEndpoint: 'https://awiki.info',
|
|
14
|
+
messageServiceEndpoint: 'https://awiki.info',
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const identity = await client.getDefaultIdentity()
|
|
19
|
+
const conversations = identity ? await client.listConversations() : undefined
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
await client.close()
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 生命周期与线程
|
|
27
|
+
|
|
28
|
+
- 一个 client 对应一个环境级 `ImCore` 和一个 default identity-bound `ImClient`,不会为
|
|
29
|
+
每次请求重开 SQLite 或身份目录。
|
|
30
|
+
- 所有 I/O 都是 Promise;Rust async 任务不会阻塞 Node event loop。
|
|
31
|
+
- `close()` 开始后拒绝新任务,取消可安全取消的任务,等待已接受任务释放状态,再释放
|
|
32
|
+
state-root 文件锁;重复调用是幂等的。
|
|
33
|
+
- JS GC 只作为异常退出兜底,Host teardown 必须显式等待 `close()`。
|
|
34
|
+
|
|
35
|
+
## state root
|
|
36
|
+
|
|
37
|
+
`stateRoot` 必须是绝对路径。同一路径在同一时间只能由一个实例/进程打开。Unix 上目录收紧为
|
|
38
|
+
`0700`、文件收紧为 `0600`。包不读取旧 TypeScript SDK 的 `identity.json`,也不提供 legacy
|
|
39
|
+
import。
|
|
40
|
+
|
|
41
|
+
## DTO 与错误
|
|
42
|
+
|
|
43
|
+
- ID/cursor 都是不透明字符串;字节数和 `registeredAtMs` 使用十进制字符串。
|
|
44
|
+
- 时间字段除 `registeredAtMs` 外均为 RFC 3339;附件 bytes 使用 `Uint8Array`/Buffer,绝不经
|
|
45
|
+
JSON 或 base64。
|
|
46
|
+
- 抛出的 `ImCoreNodeError` 只包含 `{ code, safeMessage, retryable }`。底层服务正文、token、
|
|
47
|
+
OTP、路径、私钥和附件内容不会进入 JS 错误。
|
|
48
|
+
|
|
49
|
+
平台包、provenance 与许可证发行链由原生制品 workflow 维护。第一版已批准按
|
|
50
|
+
AGPL-3.0-only 分发,对应源码、SBOM、checksum 与构建来源随每个包提供。
|
|
51
|
+
|
|
52
|
+
## 原生制品
|
|
53
|
+
|
|
54
|
+
Tier 1 平台使用独立 optional package;wrapper 会显式区分 glibc 与 musl,不做运行期下载,也
|
|
55
|
+
不回退 TypeScript SDK。第一版五平台矩阵、AGPL test channel、SBOM、checksum、provenance 和
|
|
56
|
+
无源码安装验证见 `docs/node-sdk/awiki-im-core-node-artifacts.md`。仓库不包含自动 npm publish
|
|
57
|
+
job;正式 registry 发布仍是独立 release 动作。
|
package/SOURCE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Corresponding Source
|
|
2
|
+
|
|
3
|
+
Package: @awiki/im-core-node@0.1.0
|
|
4
|
+
Target: platform-independent-wrapper
|
|
5
|
+
Repository: https://github.com/AgentConnect/awiki-cli-rs2
|
|
6
|
+
Commit: 28d9b9e4dcdab2daeb1112ba624528695acedd97
|
|
7
|
+
ANP commit: d3cc6a9571cec9b7d53dfbc5ef5612e56d1d5ea9
|
|
8
|
+
|
|
9
|
+
Build instructions: docs/node-sdk/awiki-im-core-node-artifacts.md
|
package/checksums.json
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"files": [
|
|
4
|
+
{
|
|
5
|
+
"path": "COMMERCIAL-LICENSING.md",
|
|
6
|
+
"sha256": "c52c6b16a68e3801154a5b628ec594bd521e0559f60acda7f187952fea87a30d"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"path": "dist/index.d.ts",
|
|
10
|
+
"sha256": "4782dfe81c1be9eb1fed0da66fcc08744468b49715526d1953dc1b7f7a4db5d3"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"path": "dist/index.d.ts.map",
|
|
14
|
+
"sha256": "13fbb0d7994b8ed4acb49ea1b39ad931b677ad7dc5dab9cd6ea75629c68e98de"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "dist/index.js",
|
|
18
|
+
"sha256": "6c1f79dea917b2cdd61835ca202a2ca9412ba9ebe5bea75523ee4334e7964555"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"path": "dist/index.js.map",
|
|
22
|
+
"sha256": "2d578f3fd94ae95ab725c884661d7d1b7e4f9dced49ba9bca4bbf5817b3fef18"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"path": "dist/loader.d.ts",
|
|
26
|
+
"sha256": "d08bcd5df31129b3b8b555f1f6e2c1d6b19a1ceb85ae0feb6a189525fd4a1771"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"path": "dist/loader.d.ts.map",
|
|
30
|
+
"sha256": "57412d819ce3271f72fd46c5f8a56578ebb9346cb657771a3e50ab2a9ea8492f"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"path": "dist/loader.js",
|
|
34
|
+
"sha256": "c5682fc606540c651e65f66a3b01ada7a4389df9c529050bb5658d2e3c0340a7"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"path": "dist/loader.js.map",
|
|
38
|
+
"sha256": "c8c312aebfb572cdce77d4297466b1f8ac868c29d19f6c0caef3bc6e0bb0c47e"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"path": "dist/native.d.ts",
|
|
42
|
+
"sha256": "1763b94ba439cb4bff2d51fec2f3929b46ad9a76c7f44b6a7063610fa84cdbb9"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"path": "dist/native.d.ts.map",
|
|
46
|
+
"sha256": "43ca72fd6c8c1c6a954c2c4b344dfba41395ca494c305d3954faa8081e9076c3"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"path": "dist/native.js",
|
|
50
|
+
"sha256": "c7f589984eb75369f0ccf54c3d777c508f712ad75fc15df941bb9c7b48d15111"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"path": "dist/native.js.map",
|
|
54
|
+
"sha256": "bf35d1499437f527ed3a1d38c08fc81b25dfd78eef9aaf02cbb047774d7b5c8e"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"path": "dist/targets.d.ts",
|
|
58
|
+
"sha256": "2c81ea1db905322b21dca2f814e58b25ea315cce04067b65e7266dd18f87ca0c"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"path": "dist/targets.d.ts.map",
|
|
62
|
+
"sha256": "91819931dbb4f2517af53aa0a22ba6d114a3d58627b0764928645d0997150766"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"path": "dist/targets.js",
|
|
66
|
+
"sha256": "cee382eeb0d0955dfccaf26754441f75d61f02a1e1ac895edac583c84ca89630"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"path": "dist/targets.js.map",
|
|
70
|
+
"sha256": "1cb9d72f11338b261937886ae024e95ab40df82541505c9a939ee8d8825c779a"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"path": "dist/types.d.ts",
|
|
74
|
+
"sha256": "8f2faab38531f34075f7ab3c60670baa6f5febcd8a62f29567d40630bac5b4c6"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"path": "dist/types.d.ts.map",
|
|
78
|
+
"sha256": "e549027e1fa54d5d609c5dc4ce1f7fc0422427f71c5ed348a7c6c3980e4e0bbe"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"path": "dist/types.js",
|
|
82
|
+
"sha256": "5de98f8dc7c93b143abce75e6ffd672502bf46658727291273a16acd66ea3305"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"path": "dist/types.js.map",
|
|
86
|
+
"sha256": "3862f651b11d9b227df5617a247c00768a85d6e2d179b08d19ea08884d9b4201"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"path": "LICENSE",
|
|
90
|
+
"sha256": "0d96a4ff68ad6d4b6f1f30f713b18d5184912ba8dd389f86aa7710db079abcb0"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"path": "NOTICE.md",
|
|
94
|
+
"sha256": "1538a6d3d7e1c8e440d91aaa4051b3334937106dfd8b1678d49fa92f92babe8f"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"path": "package.json",
|
|
98
|
+
"sha256": "53d3a10896c4e97a4d91135c3717eb10d934a2e92c0ba4f63a02c5479d35fc3a"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"path": "provenance.json",
|
|
102
|
+
"sha256": "026b1825c6f32c9845a1a411eaf6f8c4bb920678f4b8ec192dee64ec7c45ac5b"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"path": "README.md",
|
|
106
|
+
"sha256": "3c4be29e8d16c1eb2469dd67e3c9d67d282729abfc8806292656228c303f5c19"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"path": "sbom.cdx.json",
|
|
110
|
+
"sha256": "38b1a75c85bd81978ae73204705316269470f076f74c9b8e3ae78a3f55b1e4e3"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"path": "SOURCE.md",
|
|
114
|
+
"sha256": "771e0e512cef57d57aefed2d7a2939c5aaebab1b8209eed50a64a5f42f6c42a5"
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ImCoreNodeClient, type ImCoreNodeOpenOptions } from './types.js';
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Open one Rust IM Core for the supplied absolute state root.
|
|
5
|
+
*
|
|
6
|
+
* All I/O methods are Promise-based. Call `close()` during host teardown; GC is
|
|
7
|
+
* only a last-resort cancellation path. A second process or instance opening
|
|
8
|
+
* the same state root fails with `state_in_use`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function openImCoreNodeClient(options: ImCoreNodeOpenOptions): Promise<ImCoreNodeClient>;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAgB3B,MAAM,YAAY,CAAA;AAEnB,cAAc,YAAY,CAAA;AA6F1B;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAIpG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { loadNativeBinding } from './loader.js';
|
|
2
|
+
import { ImCoreNodeError, } from './types.js';
|
|
3
|
+
export * from './types.js';
|
|
4
|
+
function nativeSafeError(error) {
|
|
5
|
+
if (!(error instanceof Error))
|
|
6
|
+
return undefined;
|
|
7
|
+
try {
|
|
8
|
+
const value = JSON.parse(error.message);
|
|
9
|
+
if (typeof value === 'object' && value !== null
|
|
10
|
+
&& 'code' in value && typeof value.code === 'string'
|
|
11
|
+
&& 'safeMessage' in value && typeof value.safeMessage === 'string'
|
|
12
|
+
&& 'retryable' in value && typeof value.retryable === 'boolean')
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
catch { }
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
async function call(operation) {
|
|
19
|
+
try {
|
|
20
|
+
return await operation();
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
const safe = nativeSafeError(error);
|
|
24
|
+
if (safe)
|
|
25
|
+
throw new ImCoreNodeError(safe.code, safe.safeMessage, safe.retryable);
|
|
26
|
+
if (error instanceof ImCoreNodeError)
|
|
27
|
+
throw error;
|
|
28
|
+
throw new ImCoreNodeError('internal', 'The IM operation failed internally.', false);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class RustImCoreNodeClient {
|
|
32
|
+
native;
|
|
33
|
+
constructor(native) {
|
|
34
|
+
this.native = native;
|
|
35
|
+
}
|
|
36
|
+
getDefaultIdentity() {
|
|
37
|
+
return call(() => this.native.getDefaultIdentity());
|
|
38
|
+
}
|
|
39
|
+
requestRegistrationOtp(input) {
|
|
40
|
+
return call(() => this.native.requestRegistrationOtp(input));
|
|
41
|
+
}
|
|
42
|
+
completeRegistration(input) {
|
|
43
|
+
return call(() => this.native.completeRegistration(input));
|
|
44
|
+
}
|
|
45
|
+
updateDisplayName(displayName) {
|
|
46
|
+
return call(() => this.native.updateDisplayName(displayName));
|
|
47
|
+
}
|
|
48
|
+
resolvePeer(peer) {
|
|
49
|
+
return call(() => this.native.resolvePeer(peer));
|
|
50
|
+
}
|
|
51
|
+
syncNow(input) {
|
|
52
|
+
return call(() => this.native.syncNow(input));
|
|
53
|
+
}
|
|
54
|
+
listConversations(input) {
|
|
55
|
+
return call(() => this.native.listConversations(input));
|
|
56
|
+
}
|
|
57
|
+
getHistory(input) {
|
|
58
|
+
return call(() => this.native.getHistory(input));
|
|
59
|
+
}
|
|
60
|
+
markConversationRead(conversationId) {
|
|
61
|
+
return call(() => this.native.markConversationRead(conversationId));
|
|
62
|
+
}
|
|
63
|
+
sendText(input) {
|
|
64
|
+
return call(() => this.native.sendText(input));
|
|
65
|
+
}
|
|
66
|
+
sendAttachment(input) {
|
|
67
|
+
const bytes = Buffer.from(input.bytes.buffer, input.bytes.byteOffset, input.bytes.byteLength);
|
|
68
|
+
return call(() => this.native.sendAttachment({ ...input, bytes }));
|
|
69
|
+
}
|
|
70
|
+
async downloadAttachment(input) {
|
|
71
|
+
const value = await call(() => this.native.downloadAttachment(input));
|
|
72
|
+
return { attachment: value.attachment, bytes: value.bytes };
|
|
73
|
+
}
|
|
74
|
+
close() {
|
|
75
|
+
return call(() => this.native.close());
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Open one Rust IM Core for the supplied absolute state root.
|
|
80
|
+
*
|
|
81
|
+
* All I/O methods are Promise-based. Call `close()` during host teardown; GC is
|
|
82
|
+
* only a last-resort cancellation path. A second process or instance opening
|
|
83
|
+
* the same state root fails with `state_in_use`.
|
|
84
|
+
*/
|
|
85
|
+
export async function openImCoreNodeClient(options) {
|
|
86
|
+
const binding = loadNativeBinding();
|
|
87
|
+
const native = await call(() => binding.openNativeClient(options));
|
|
88
|
+
return new RustImCoreNodeClient(native);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EACL,eAAe,GAoBhB,MAAM,YAAY,CAAA;AAEnB,cAAc,YAAY,CAAA;AAQ1B,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IAC/C,IAAI,CAAC;QACH,MAAM,KAAK,GAAY,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAChD,IACE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;eACxC,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;eACjD,aAAa,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,WAAW,KAAK,QAAQ;eAC/D,WAAW,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,SAAS,KAAK,SAAS;YAC/D,OAAO,KAAwB,CAAA;IACnC,CAAC;IACD,MAAM,CAAC,CAAA,CAAC;IACR,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,KAAK,UAAU,IAAI,CAAI,SAA2B;IAChD,IAAI,CAAC;QACH,OAAO,MAAM,SAAS,EAAE,CAAA;IAC1B,CAAC;IACD,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,IAAI,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;QACnC,IAAI,IAAI;YAAE,MAAM,IAAI,eAAe,CAAC,IA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MG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAA8B;IACvE,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAA;IACnC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAA;IAClE,OAAO,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAA;AACzC,CAAC"}
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAsBhD,2GAA2G;AAC3G,wBAAgB,iBAAiB,IAAI,aAAa,CAwBjD"}
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { currentNativeTarget, nativePlatformPackages } from './targets.js';
|
|
6
|
+
import { ImCoreNodeError } from './types.js';
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const packageRoot = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
9
|
+
function target() {
|
|
10
|
+
const key = currentNativeTarget();
|
|
11
|
+
const packageName = nativePlatformPackages[key];
|
|
12
|
+
if (!packageName) {
|
|
13
|
+
throw new ImCoreNodeError('unsupported_platform', `Unsupported native platform: ${key}.`, false);
|
|
14
|
+
}
|
|
15
|
+
return { key, packageName };
|
|
16
|
+
}
|
|
17
|
+
function isModuleMissing(error) {
|
|
18
|
+
return error instanceof Error
|
|
19
|
+
&& 'code' in error
|
|
20
|
+
&& error.code === 'MODULE_NOT_FOUND';
|
|
21
|
+
}
|
|
22
|
+
/** Load only a bundled or installed platform addon; runtime downloads and path overrides are forbidden. */
|
|
23
|
+
export function loadNativeBinding() {
|
|
24
|
+
const { key, packageName } = target();
|
|
25
|
+
let binding;
|
|
26
|
+
try {
|
|
27
|
+
binding = require(packageName);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (!isModuleMissing(error))
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
if (!binding) {
|
|
34
|
+
const local = join(packageRoot, 'native', `awiki-im-core-node.${key}.node`);
|
|
35
|
+
if (existsSync(local))
|
|
36
|
+
binding = require(local);
|
|
37
|
+
}
|
|
38
|
+
if (!binding) {
|
|
39
|
+
throw new ImCoreNodeError('native_addon_missing', `The native addon for ${key} is not installed.`, false);
|
|
40
|
+
}
|
|
41
|
+
if (binding.nativeApiVersion() !== 1) {
|
|
42
|
+
throw new ImCoreNodeError('native_api_mismatch', 'The native addon API version is incompatible.', false);
|
|
43
|
+
}
|
|
44
|
+
return binding;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE5C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9C,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,E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,IAAI,eAAe,CAAC,qBAAqB,EAAE,+CAA+C,EAAE,KAAK,CAAC,CAAA;IAC1G,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DownloadAttachmentInput, HistoryInput, ImCoreNodeOpenOptions, MarkReadResult, NodeConversation, NodeDownload, NodeIdentity, NodeMessage, NodePeer, OtpChallenge, Page, PageInput, RegistrationInput, RegistrationWithOtp, SendAttachmentInput, SendTextInput, SyncOptions, SyncResult } from './types.js';
|
|
2
|
+
export interface NativeImCoreNodeClient {
|
|
3
|
+
getDefaultIdentity(): Promise<NodeIdentity | null>;
|
|
4
|
+
requestRegistrationOtp(input: RegistrationInput): Promise<OtpChallenge>;
|
|
5
|
+
completeRegistration(input: RegistrationWithOtp): Promise<NodeIdentity>;
|
|
6
|
+
updateDisplayName(displayName: string): Promise<NodeIdentity>;
|
|
7
|
+
resolvePeer(peer: string): Promise<NodePeer>;
|
|
8
|
+
syncNow(input?: SyncOptions): Promise<SyncResult>;
|
|
9
|
+
listConversations(input?: PageInput): Promise<Page<NodeConversation>>;
|
|
10
|
+
getHistory(input: HistoryInput): Promise<Page<NodeMessage>>;
|
|
11
|
+
markConversationRead(conversationId: string): Promise<MarkReadResult>;
|
|
12
|
+
sendText(input: SendTextInput): Promise<NodeMessage>;
|
|
13
|
+
sendAttachment(input: Omit<SendAttachmentInput, 'bytes'> & {
|
|
14
|
+
readonly bytes: Buffer;
|
|
15
|
+
}): Promise<NodeMessage>;
|
|
16
|
+
downloadAttachment(input: DownloadAttachmentInput): Promise<Omit<NodeDownload, 'bytes'> & {
|
|
17
|
+
readonly bytes: Buffer;
|
|
18
|
+
}>;
|
|
19
|
+
close(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export interface NativeBinding {
|
|
22
|
+
readonly nativeApiVersion: () => number;
|
|
23
|
+
readonly openNativeClient: (options: ImCoreNodeOpenOptions) => Promise<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AAC,CAAA;IACpD,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,GAAG;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;IAC5G,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,GAAG;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACrH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,MAAM,CAAA;IACvC,QAAQ,CAAC,gBAAgB,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,OAAO,CAAC,sBAAsB,CAAC,CAAA;CAC/F"}
|
package/dist/native.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Approved first-release Tier 1 native packages. */
|
|
2
|
+
export declare const nativePlatformPackages: Readonly<Record<string, string>>;
|
|
3
|
+
/** Resolve the native target without treating a musl host as glibc. */
|
|
4
|
+
export declare function resolveNativeTarget(platform: NodeJS.Platform, arch: string, glibcVersionRuntime?: string): string;
|
|
5
|
+
export declare function currentNativeTarget(): string;
|
|
6
|
+
//# sourceMappingURL=targets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"targets.d.ts","sourceRoot":"","sources":["../src/targets.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMnE,CAAA;AAED,uEAAuE;AACvE,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,IAAI,EAAE,MAAM,EACZ,mBAAmB,CAAC,EAAE,MAAM,GAC3B,MAAM,CAKR;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CAU5C"}
|
package/dist/targets.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Approved first-release Tier 1 native packages. */
|
|
2
|
+
export const nativePlatformPackages = {
|
|
3
|
+
'linux-x64-gnu': '@awiki/im-core-node-linux-x64-gnu',
|
|
4
|
+
'linux-arm64-gnu': '@awiki/im-core-node-linux-arm64-gnu',
|
|
5
|
+
'darwin-x64': '@awiki/im-core-node-darwin-x64',
|
|
6
|
+
'darwin-arm64': '@awiki/im-core-node-darwin-arm64',
|
|
7
|
+
'win32-x64': '@awiki/im-core-node-win32-x64-msvc',
|
|
8
|
+
};
|
|
9
|
+
/** Resolve the native target without treating a musl host as glibc. */
|
|
10
|
+
export function resolveNativeTarget(platform, arch, glibcVersionRuntime) {
|
|
11
|
+
if (platform === 'linux') {
|
|
12
|
+
return `linux-${arch}-${glibcVersionRuntime ? 'gnu' : 'musl'}`;
|
|
13
|
+
}
|
|
14
|
+
return `${platform}-${arch}`;
|
|
15
|
+
}
|
|
16
|
+
export function currentNativeTarget() {
|
|
17
|
+
const report = process.platform === 'linux'
|
|
18
|
+
? process.report.getReport()
|
|
19
|
+
: undefined;
|
|
20
|
+
const glibcVersionRuntime = report?.header?.glibcVersionRuntime;
|
|
21
|
+
return resolveNativeTarget(process.platform, process.arch, typeof glibcVersionRuntime === 'string' ? glibcVersionRuntime : undefined);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=targets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"targets.js","sourceRoot":"","sources":["../src/targets.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,MAAM,CAAC,MAAM,sBAAsB,GAAqC;IACtE,eAAe,EAAE,mCAAmC;IACpD,iBAAiB,EAAE,qCAAqC;IACxD,YAAY,EAAE,gCAAgC;IAC9C,cAAc,EAAE,kCAAkC;IAClD,WAAW,EAAE,oCAAoC;CAClD,CAAA;AAED,uEAAuE;AACvE,MAAM,UAAU,mBAAmB,CACjC,QAAyB,EACzB,IAAY,EACZ,mBAA4B;IAE5B,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QACzB,OAAO,SAAS,IAAI,IAAI,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAA;IAChE,CAAC;IACD,OAAO,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAA;AAC9B,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO;QACzC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAsE;QAChG,CAAC,CAAC,SAAS,CAAA;IACb,MAAM,mBAAmB,GAAG,MAAM,EAAE,MAAM,EAAE,mBAAmB,CAAA;IAC/D,OAAO,mBAAmB,CACxB,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,IAAI,EACZ,OAAO,mBAAmB,KAAK,QAAQ,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,SAAS,CAC1E,CAAA;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/** State and service configuration owned by the Node host. */
|
|
2
|
+
export interface ImCoreNodeOpenOptions {
|
|
3
|
+
/** Absolute, process-exclusive root for identities, SQLite, cache, and metadata. */
|
|
4
|
+
readonly stateRoot: string;
|
|
5
|
+
readonly serviceBaseUrl: string;
|
|
6
|
+
readonly didDomain: string;
|
|
7
|
+
readonly userServiceEndpoint?: string;
|
|
8
|
+
readonly messageServiceEndpoint?: string;
|
|
9
|
+
readonly anpServiceEndpoint?: string;
|
|
10
|
+
readonly anpServiceDid?: string;
|
|
11
|
+
/** Default timeout for one operation, from 1 to 600000 milliseconds. */
|
|
12
|
+
readonly operationTimeoutMs?: number;
|
|
13
|
+
/** Timeout for bounded synchronization before list reads. */
|
|
14
|
+
readonly syncTimeoutMs?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Public identity projection. No token, private key, or local path is exposed. */
|
|
17
|
+
export interface NodeIdentity {
|
|
18
|
+
readonly identityId: string;
|
|
19
|
+
readonly did: string;
|
|
20
|
+
readonly handle?: string;
|
|
21
|
+
readonly displayName?: string;
|
|
22
|
+
/** Stable Unix milliseconds represented as a decimal string. */
|
|
23
|
+
readonly registeredAtMs: string;
|
|
24
|
+
}
|
|
25
|
+
/** First stage of phone registration. */
|
|
26
|
+
export interface RegistrationInput {
|
|
27
|
+
readonly handle: string;
|
|
28
|
+
readonly phone: string;
|
|
29
|
+
}
|
|
30
|
+
/** Second stage of phone registration. */
|
|
31
|
+
export interface RegistrationWithOtp extends RegistrationInput {
|
|
32
|
+
readonly otp: string;
|
|
33
|
+
}
|
|
34
|
+
/** Server-issued retry boundary for a registration OTP. */
|
|
35
|
+
export interface OtpChallenge {
|
|
36
|
+
readonly retryAfterSeconds: number;
|
|
37
|
+
/** RFC 3339 UTC timestamp. */
|
|
38
|
+
readonly retryAt: string;
|
|
39
|
+
}
|
|
40
|
+
/** Verified directory result with the canonical Direct conversation ID. */
|
|
41
|
+
export interface NodePeer {
|
|
42
|
+
readonly did: string;
|
|
43
|
+
readonly handle?: string;
|
|
44
|
+
readonly displayName?: string;
|
|
45
|
+
readonly conversationId: string;
|
|
46
|
+
}
|
|
47
|
+
/** Opaque cursor page input. */
|
|
48
|
+
export interface PageInput {
|
|
49
|
+
readonly cursor?: string;
|
|
50
|
+
readonly limit?: number;
|
|
51
|
+
}
|
|
52
|
+
/** Opaque cursor page. */
|
|
53
|
+
export interface Page<T> {
|
|
54
|
+
readonly items: readonly T[];
|
|
55
|
+
readonly nextCursor?: string;
|
|
56
|
+
readonly hasMore: boolean;
|
|
57
|
+
}
|
|
58
|
+
/** Explicit reliable-sync input. */
|
|
59
|
+
export interface SyncOptions {
|
|
60
|
+
readonly reason?: string;
|
|
61
|
+
readonly limit?: number;
|
|
62
|
+
readonly timeoutMs?: number;
|
|
63
|
+
}
|
|
64
|
+
export type SyncStatus = 'idle' | 'changed' | 'recovery_required' | 'retryable_failure' | 'auth_revoked';
|
|
65
|
+
/** Product-safe reliable-sync result. */
|
|
66
|
+
export interface SyncResult {
|
|
67
|
+
readonly status: SyncStatus;
|
|
68
|
+
readonly eventsApplied: number;
|
|
69
|
+
readonly pagesFetched: number;
|
|
70
|
+
readonly messagesHydrated: number;
|
|
71
|
+
readonly duplicatesSkipped: number;
|
|
72
|
+
readonly changedConversationIds: readonly string[];
|
|
73
|
+
readonly warnings: readonly string[];
|
|
74
|
+
}
|
|
75
|
+
/** One canonical Direct or Group conversation. */
|
|
76
|
+
export interface NodeConversation {
|
|
77
|
+
readonly id: string;
|
|
78
|
+
readonly kind: 'direct' | 'group';
|
|
79
|
+
readonly peerDid?: string;
|
|
80
|
+
readonly peerHandle?: string;
|
|
81
|
+
readonly groupDid?: string;
|
|
82
|
+
readonly title?: string;
|
|
83
|
+
readonly participants: readonly string[];
|
|
84
|
+
readonly unreadCount: number;
|
|
85
|
+
readonly messageCount: number;
|
|
86
|
+
/** RFC 3339 timestamp. */
|
|
87
|
+
readonly lastMessageAt?: string;
|
|
88
|
+
readonly lastMessage?: NodeMessage;
|
|
89
|
+
}
|
|
90
|
+
/** Single attachment metadata. Byte counts are decimal strings. */
|
|
91
|
+
export interface NodeAttachment {
|
|
92
|
+
readonly id: string;
|
|
93
|
+
readonly fileName: string;
|
|
94
|
+
readonly mimeType: string;
|
|
95
|
+
readonly sizeBytes: string;
|
|
96
|
+
readonly digestB64u: string;
|
|
97
|
+
readonly sha256Hex?: string;
|
|
98
|
+
}
|
|
99
|
+
export interface NodeMessageContent {
|
|
100
|
+
readonly kind: 'text' | 'attachment' | 'payload' | 'unsupported';
|
|
101
|
+
readonly text?: string;
|
|
102
|
+
readonly attachment?: NodeAttachment;
|
|
103
|
+
readonly caption?: string;
|
|
104
|
+
readonly payloadJson?: string;
|
|
105
|
+
readonly unsupportedContentType?: string;
|
|
106
|
+
}
|
|
107
|
+
/** Canonically routed message projection. */
|
|
108
|
+
export interface NodeMessage {
|
|
109
|
+
readonly id: string;
|
|
110
|
+
readonly conversationId: string;
|
|
111
|
+
readonly conversationKind: 'direct' | 'group';
|
|
112
|
+
readonly senderDid: string;
|
|
113
|
+
readonly senderHandle?: string;
|
|
114
|
+
readonly senderDisplayName?: string;
|
|
115
|
+
/** RFC 3339 timestamp. */
|
|
116
|
+
readonly sentAt?: string;
|
|
117
|
+
readonly outgoing: boolean;
|
|
118
|
+
readonly content: NodeMessageContent;
|
|
119
|
+
}
|
|
120
|
+
export interface HistoryInput extends PageInput {
|
|
121
|
+
readonly conversationId: string;
|
|
122
|
+
}
|
|
123
|
+
export interface MarkReadResult {
|
|
124
|
+
readonly updatedCount: number;
|
|
125
|
+
readonly remoteAcknowledged: boolean;
|
|
126
|
+
readonly partial: boolean;
|
|
127
|
+
readonly fallbackUsed: boolean;
|
|
128
|
+
readonly pendingRemoteAck: boolean;
|
|
129
|
+
readonly warnings: readonly string[];
|
|
130
|
+
}
|
|
131
|
+
export interface SendTextInput {
|
|
132
|
+
readonly conversationId: string;
|
|
133
|
+
readonly text: string;
|
|
134
|
+
readonly markdown?: boolean;
|
|
135
|
+
readonly clientMessageId?: string;
|
|
136
|
+
readonly idempotencyKey?: string;
|
|
137
|
+
}
|
|
138
|
+
/** Single attachment send. `bytes` crosses N-API as Uint8Array, never JSON/base64. */
|
|
139
|
+
export interface SendAttachmentInput {
|
|
140
|
+
readonly conversationId: string;
|
|
141
|
+
readonly fileName: string;
|
|
142
|
+
readonly mimeType: string;
|
|
143
|
+
readonly bytes: Uint8Array;
|
|
144
|
+
readonly caption?: string;
|
|
145
|
+
readonly clientMessageId?: string;
|
|
146
|
+
readonly idempotencyKey?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface DownloadAttachmentInput {
|
|
149
|
+
readonly conversationId: string;
|
|
150
|
+
readonly messageId: string;
|
|
151
|
+
readonly attachmentId?: string;
|
|
152
|
+
readonly timeoutMs?: number;
|
|
153
|
+
}
|
|
154
|
+
/** Verified in-memory download. */
|
|
155
|
+
export interface NodeDownload {
|
|
156
|
+
readonly attachment: NodeAttachment;
|
|
157
|
+
readonly bytes: Uint8Array;
|
|
158
|
+
}
|
|
159
|
+
/** Stable, redacted error taxonomy from the Rust bridge. */
|
|
160
|
+
export declare class ImCoreNodeError extends Error {
|
|
161
|
+
readonly code: string;
|
|
162
|
+
readonly safeMessage: string;
|
|
163
|
+
readonly retryable: boolean;
|
|
164
|
+
readonly name = "ImCoreNodeError";
|
|
165
|
+
constructor(code: string, safeMessage: string, retryable: boolean);
|
|
166
|
+
}
|
|
167
|
+
/** Environment-scoped Promise API backed by one Rust ImCore/ImClient pair. */
|
|
168
|
+
export interface ImCoreNodeClient {
|
|
169
|
+
getDefaultIdentity(): Promise<NodeIdentity | null>;
|
|
170
|
+
requestRegistrationOtp(input: RegistrationInput): Promise<OtpChallenge>;
|
|
171
|
+
completeRegistration(input: RegistrationWithOtp): Promise<NodeIdentity>;
|
|
172
|
+
updateDisplayName(displayName: string): Promise<NodeIdentity>;
|
|
173
|
+
resolvePeer(peer: string): Promise<NodePeer>;
|
|
174
|
+
syncNow(input?: SyncOptions): Promise<SyncResult>;
|
|
175
|
+
listConversations(input?: PageInput): Promise<Page<NodeConversation>>;
|
|
176
|
+
getHistory(input: HistoryInput): Promise<Page<NodeMessage>>;
|
|
177
|
+
markConversationRead(conversationId: string): Promise<MarkReadResult>;
|
|
178
|
+
sendText(input: SendTextInput): Promise<NodeMessage>;
|
|
179
|
+
sendAttachment(input: SendAttachmentInput): Promise<NodeMessage>;
|
|
180
|
+
downloadAttachment(input: DownloadAttachmentInput): Promise<NodeDownload>;
|
|
181
|
+
/** Rejects new work, cancels cancel-safe I/O, drains in-flight work, and releases the state lock. */
|
|
182
|
+
close(): Promise<void>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iB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IACvE,oBAAoB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IACvE,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IAC7D,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC5C,OAAO,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IACjD,iBAAiB,CAAC,KAAK,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAA;IACrE,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAA;IAC3D,oBAAoB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IACrE,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;IACpD,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;IAChE,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IACzE,qGAAqG;IACrG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Stable, redacted error taxonomy from the Rust bridge. */
|
|
2
|
+
export class ImCoreNodeError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
safeMessage;
|
|
5
|
+
retryable;
|
|
6
|
+
name = 'ImCoreNodeError';
|
|
7
|
+
constructor(code, safeMessage, retryable) {
|
|
8
|
+
super(safeMessage);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.safeMessage = safeMessage;
|
|
11
|
+
this.retryable = retryable;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=types.js.map
|