@zoralabs/cli 1.4.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];
19
+ };
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);
21
30
  };
22
- var consentFromSdk = (state) => {
23
- if (state === ConsentState.Allowed) return "allowed";
24
- if (state === ConsentState.Denied) return "denied";
25
- return "unknown";
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 = {
@@ -100,12 +126,12 @@ var createMessagingClient = async (spec, options = {}) => {
100
126
  return {
101
127
  address,
102
128
  async sync(consent) {
103
- const states = consent?.map((c) => CONSENT_TO_SDK[c]);
129
+ const states = consent?.map((c) => consentToSdk[c]);
104
130
  await client.conversations.syncAll(states);
105
131
  await client.conversations.sync();
106
132
  },
107
133
  async listDms(consent) {
108
- const states = consent?.map((c) => CONSENT_TO_SDK[c]);
134
+ const states = consent?.map((c) => consentToSdk[c]);
109
135
  const dms = client.conversations.listDms({ consentStates: states });
110
136
  return Promise.all(
111
137
  dms.map(async (dm) => {
@@ -155,7 +181,7 @@ var createMessagingClient = async (spec, options = {}) => {
155
181
  if (!dm) {
156
182
  throw new Error(`No conversation found with ${peerAddress}`);
157
183
  }
158
- await dm.updateConsentState(CONSENT_TO_SDK[consent]);
184
+ await dm.updateConsentState(consentToSdk[consent]);
159
185
  },
160
186
  streamAllMessages() {
161
187
  const ctrl = new AbortController();
@@ -189,6 +215,5 @@ var createMessagingClient = async (spec, options = {}) => {
189
215
  };
190
216
  };
191
217
  export {
192
- buildXmtpSigner,
193
218
  createMessagingClient
194
219
  };