@zoralabs/cli 1.3.0 → 1.4.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.
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/messaging/native-binding.ts
4
+ var REQUIRED_GLIBC = "2.38";
5
+ var errorChainText = (err) => {
6
+ const parts = [];
7
+ const seen = /* @__PURE__ */ new Set();
8
+ let cur = err;
9
+ while (cur && !seen.has(cur)) {
10
+ seen.add(cur);
11
+ if (cur instanceof Error) {
12
+ parts.push(cur.message);
13
+ const code = cur.code;
14
+ if (code) parts.push(code);
15
+ cur = cur.cause;
16
+ } else {
17
+ parts.push(String(cur));
18
+ break;
19
+ }
20
+ }
21
+ return parts.join("\n");
22
+ };
23
+ var isNativeBindingError = (err) => {
24
+ const text = errorChainText(err);
25
+ return /ERR_DLOPEN_FAILED/.test(text) || /\bdlopen\b/i.test(text) || /GLIBC_[\d.]+'? not found/i.test(text) || /cannot open shared object/i.test(text) || /cannot find native binding/i.test(text) || /@xmtp\/node-bindings/i.test(text);
26
+ };
27
+ var detectGlibc = () => {
28
+ try {
29
+ const raw = process.report?.getReport?.();
30
+ const report = typeof raw === "string" ? JSON.parse(raw) : raw;
31
+ return report?.header?.glibcVersionRuntime || void 0;
32
+ } catch {
33
+ return void 0;
34
+ }
35
+ };
36
+ var nativeBindingErrorHelp = () => {
37
+ const glibc = detectGlibc();
38
+ const where = glibc ? ` (glibc ${glibc})` : "";
39
+ return [
40
+ `The XMTP messaging library's native module couldn't load on this system${where}.`,
41
+ "",
42
+ "DMs need a platform-native binary. Any of these fixes it:",
43
+ " \u2022 run on an Alpine / musl image \u2014 e.g. node:20-alpine (works on any Node version)",
44
+ " \u2022 use Node 22+ and reinstall the CLI \u2014 `npm install -g @zoralabs/cli`",
45
+ ` \u2022 or use a glibc >= ${REQUIRED_GLIBC} image \u2014 Ubuntu 24.04+ or Debian 13`
46
+ ].join("\n");
47
+ };
48
+
49
+ export {
50
+ REQUIRED_GLIBC,
51
+ isNativeBindingError,
52
+ detectGlibc,
53
+ nativeBindingErrorHelp
54
+ };
@@ -1,33 +1,44 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ REQUIRED_GLIBC,
4
+ detectGlibc
5
+ } from "./chunk-WF24B44I.js";
2
6
 
3
7
  // src/messaging/client.ts
4
8
  import { homedir, platform } from "os";
5
9
  import { join } from "path";
6
10
  import { mkdirSync } from "fs";
7
- import {
8
- Client,
9
- ConsentState,
10
- IdentifierKind,
11
- LogLevel,
12
- isText
13
- } from "@xmtp/node-sdk";
14
11
  import { ReactionCodec } from "@xmtp/content-type-reaction";
15
12
  import { ReadReceiptCodec } from "@xmtp/content-type-read-receipt";
16
13
  import { getAddress } from "viem";
17
- var CONSENT_TO_SDK = {
18
- allowed: ConsentState.Allowed,
19
- unknown: ConsentState.Unknown,
20
- denied: ConsentState.Denied
14
+
15
+ // src/messaging/load-xmtp-sdk.ts
16
+ var parseVer = (v) => {
17
+ const [major = 0, minor = 0] = v.split(".").map((n) => parseInt(n, 10) || 0);
18
+ return [major, minor];
21
19
  };
22
- var consentFromSdk = (state) => {
23
- if (state === ConsentState.Allowed) return "allowed";
24
- if (state === ConsentState.Denied) return "denied";
25
- return "unknown";
20
+ var glibcOlderThan = (a, b) => {
21
+ const [aMaj, aMin] = parseVer(a);
22
+ const [bMaj, bMin] = parseVer(b);
23
+ return aMaj !== bMaj ? aMaj < bMaj : aMin < bMin;
24
+ };
25
+ var shouldUseLowGlibcSdk = () => {
26
+ if (process.platform !== "linux") return false;
27
+ const glibc = detectGlibc();
28
+ if (!glibc) return false;
29
+ return glibcOlderThan(glibc, REQUIRED_GLIBC);
30
+ };
31
+ var loadXmtpSdk = async () => {
32
+ if (shouldUseLowGlibcSdk()) {
33
+ try {
34
+ return await import("@xmtp/node-sdk-lowglibc");
35
+ } catch {
36
+ }
37
+ }
38
+ return import("@xmtp/node-sdk");
26
39
  };
27
- var toIdentifier = (address) => ({
28
- identifier: address.toLowerCase(),
29
- identifierKind: IdentifierKind.Ethereum
30
- });
40
+
41
+ // src/messaging/client.ts
31
42
  var formatContentType = (ct) => `${ct.authorityId}/${ct.typeId}:${ct.versionMajor}.${ct.versionMinor}`;
32
43
  var asAddress = (value) => {
33
44
  if (!value) return null;
@@ -46,19 +57,34 @@ var defaultDbPath = (env, inboxId) => {
46
57
  mkdirSync(dir, { recursive: true });
47
58
  return join(dir, `xmtp-${env}-${inboxId}.db3`);
48
59
  };
49
- var buildXmtpSigner = (spec) => {
50
- const getIdentifier = () => toIdentifier(spec.address);
51
- if (spec.type === "EOA") {
52
- return { type: "EOA", getIdentifier, signMessage: spec.signMessage };
53
- }
54
- return {
55
- type: "SCW",
56
- getIdentifier,
57
- getChainId: () => BigInt(spec.chainId),
58
- signMessage: spec.signMessage
59
- };
60
- };
61
60
  var createMessagingClient = async (spec, options = {}) => {
61
+ const { Client, ConsentState, IdentifierKind, LogLevel, isText } = await loadXmtpSdk();
62
+ const consentToSdk = {
63
+ allowed: ConsentState.Allowed,
64
+ unknown: ConsentState.Unknown,
65
+ denied: ConsentState.Denied
66
+ };
67
+ const consentFromSdk = (state) => {
68
+ if (state === ConsentState.Allowed) return "allowed";
69
+ if (state === ConsentState.Denied) return "denied";
70
+ return "unknown";
71
+ };
72
+ const toIdentifier = (address2) => ({
73
+ identifier: address2.toLowerCase(),
74
+ identifierKind: IdentifierKind.Ethereum
75
+ });
76
+ const buildXmtpSigner = (s) => {
77
+ const getIdentifier = () => toIdentifier(s.address);
78
+ if (s.type === "EOA") {
79
+ return { type: "EOA", getIdentifier, signMessage: s.signMessage };
80
+ }
81
+ return {
82
+ type: "SCW",
83
+ getIdentifier,
84
+ getChainId: () => BigInt(s.chainId),
85
+ signMessage: s.signMessage
86
+ };
87
+ };
62
88
  const env = options.env ?? "production";
63
89
  const signer = buildXmtpSigner(spec);
64
90
  const clientOptions = {
@@ -96,15 +122,16 @@ var createMessagingClient = async (spec, options = {}) => {
96
122
  sentAtMs: Number(message.sentAtNs / 1000000n)
97
123
  });
98
124
  const findDm = (peerAddress) => client.conversations.fetchDmByIdentifier(toIdentifier(peerAddress));
125
+ let streamAbort;
99
126
  return {
100
127
  address,
101
128
  async sync(consent) {
102
- const states = consent?.map((c) => CONSENT_TO_SDK[c]);
129
+ const states = consent?.map((c) => consentToSdk[c]);
103
130
  await client.conversations.syncAll(states);
104
131
  await client.conversations.sync();
105
132
  },
106
133
  async listDms(consent) {
107
- const states = consent?.map((c) => CONSENT_TO_SDK[c]);
134
+ const states = consent?.map((c) => consentToSdk[c]);
108
135
  const dms = client.conversations.listDms({ consentStates: states });
109
136
  return Promise.all(
110
137
  dms.map(async (dm) => {
@@ -154,13 +181,39 @@ var createMessagingClient = async (spec, options = {}) => {
154
181
  if (!dm) {
155
182
  throw new Error(`No conversation found with ${peerAddress}`);
156
183
  }
157
- await dm.updateConsentState(CONSENT_TO_SDK[consent]);
184
+ await dm.updateConsentState(consentToSdk[consent]);
185
+ },
186
+ streamAllMessages() {
187
+ const ctrl = new AbortController();
188
+ streamAbort = ctrl;
189
+ const outerClient = client;
190
+ async function* generate() {
191
+ await outerClient.conversations.sync();
192
+ const stream = await outerClient.conversations.streamAllMessages();
193
+ for await (const message of stream) {
194
+ if (ctrl.signal.aborted) break;
195
+ let convo = outerClient.conversations.listDms().find((dm) => dm.id === message.conversationId);
196
+ if (!convo) {
197
+ await outerClient.conversations.sync();
198
+ convo = outerClient.conversations.listDms().find((dm) => dm.id === message.conversationId);
199
+ if (!convo) continue;
200
+ }
201
+ const addrByInbox = await addressMapForDm(convo);
202
+ const dmMessage = toMessage(message, addrByInbox);
203
+ const peerAddr = addrByInbox.get(convo.peerInboxId) ?? null;
204
+ yield { ...dmMessage, peerAddress: peerAddr };
205
+ }
206
+ }
207
+ return generate();
158
208
  },
159
209
  async close() {
210
+ if (streamAbort) {
211
+ streamAbort.abort();
212
+ streamAbort = void 0;
213
+ }
160
214
  }
161
215
  };
162
216
  };
163
217
  export {
164
- buildXmtpSigner,
165
218
  createMessagingClient
166
219
  };