@dvmkit/sdk 0.1.0-rc.5 → 0.1.0-rc.7

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.
@@ -1,54 +1,11 @@
1
+ import {
2
+ BTC_RATE_FILE,
3
+ ensureConfigSubdir
4
+ } from "./chunk-MKI6OVW4.js";
1
5
  import {
2
6
  formatFiat
3
7
  } from "./chunk-AT6V3SY7.js";
4
8
 
5
- // src/lib/errors.ts
6
- var DvmError = class extends Error {
7
- constructor(code, message, hint, data, display, proseSources) {
8
- super(message);
9
- this.code = code;
10
- this.hint = hint;
11
- this.data = data;
12
- this.display = display;
13
- this.proseSources = proseSources;
14
- this.name = "DvmError";
15
- }
16
- code;
17
- hint;
18
- data;
19
- display;
20
- proseSources;
21
- };
22
- function providerProseSources(...sources) {
23
- const provenance = {};
24
- for (const source of sources) {
25
- if (!source) continue;
26
- for (const field of ["message", "hint", "display"]) {
27
- if (typeof source[field] === "string") provenance[field] = "provider";
28
- }
29
- }
30
- return Object.keys(provenance).length > 0 ? provenance : void 0;
31
- }
32
- function isAbortError(err) {
33
- return err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError");
34
- }
35
- function transportErrorCode(err) {
36
- let current = err;
37
- const seen = /* @__PURE__ */ new Set();
38
- for (let depth = 0; depth < 5 && isErrorLike(current) && !seen.has(current); depth++) {
39
- seen.add(current);
40
- const code = current.code;
41
- if (typeof code === "string" && /^(?:E[A-Z0-9_]{1,63}|UND_ERR_[A-Z0-9_]{1,63})$/.test(code)) {
42
- return code;
43
- }
44
- current = current.cause;
45
- }
46
- return void 0;
47
- }
48
- function isErrorLike(value) {
49
- return (typeof value === "object" || typeof value === "function") && value !== null;
50
- }
51
-
52
9
  // src/lib/credit-implicit.ts
53
10
  var IMPLICIT_CREDIT_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
54
11
 
@@ -98,53 +55,6 @@ function isPositiveNumber(v) {
98
55
  // src/lib/currency.ts
99
56
  import { existsSync, readFileSync, writeFileSync } from "fs";
100
57
  import { dirname } from "path";
101
-
102
- // src/defaults.ts
103
- import { homedir } from "os";
104
- import { join } from "path";
105
- var CONFIG_DIR = process.env.DVM_CONFIG_DIR ?? join(homedir(), ".dvm");
106
- var CONFIG_FILE = join(CONFIG_DIR, "config.json");
107
- var CONFIG_BACKUP_FILE = join(CONFIG_DIR, "config.json.bak");
108
- var CONFIG_AUDIT_FILE = join(CONFIG_DIR, "config-audit.jsonl");
109
- var CONFIG_PINNED_FILE = join(CONFIG_DIR, "config.json.pinned");
110
- var JOBS_FILE = join(CONFIG_DIR, "jobs.json");
111
- var REQUEST_INTENTS_DIR = join(CONFIG_DIR, "request-intents");
112
- var FAVORITES_FILE = join(CONFIG_DIR, "favorites.json");
113
- var MESSAGES_DIR = join(CONFIG_DIR, "messages");
114
- var RECEIPTS_FILE = join(CONFIG_DIR, "receipts.jsonl");
115
- var CREDITS_FILE = join(CONFIG_DIR, "credits.json");
116
- var X402_CHANNELS_FILE = join(CONFIG_DIR, "x402-channels.json");
117
- var TEMPO_CHANNELS_FILE = join(CONFIG_DIR, "tempo-channels.json");
118
- var FEEDBACK_NUDGES_FILE = join(CONFIG_DIR, "feedback-nudges.json");
119
- var RECOVERY_MNEMONIC_FILE = join(CONFIG_DIR, "recovery.mnemonic");
120
- var WALLET_FILE = join(CONFIG_DIR, "wallet.json");
121
- var AGENT_MNEMONIC_FILE = join(CONFIG_DIR, "wallet.mnemonic");
122
- var IDENTITIES_FILE = join(CONFIG_DIR, "identities.json");
123
- var PAIRINGS_DIR = join(CONFIG_DIR, "pairings");
124
- var BUDGET_FILE = join(CONFIG_DIR, "budget.json");
125
- var BTC_RATE_FILE = join(CONFIG_DIR, "btc-rate.json");
126
- var ADMIN_DIR = join(CONFIG_DIR, "admin");
127
- var PROXY_STATE_FILE = join(ADMIN_DIR, "proxy.json");
128
- var BUILDER_CONFIG_DIR = process.env.DVMKIT_CONFIG_DIR ?? join(homedir(), ".dvmkit");
129
- var BUILDER_FILE = join(BUILDER_CONFIG_DIR, "builder.json");
130
- var BUILDER_MNEMONIC_FILE = join(BUILDER_CONFIG_DIR, "recovery.mnemonic");
131
- var BUILDER_KEY_FILE = join(BUILDER_CONFIG_DIR, "builder.key");
132
- var MELT_PENDING_LOG_FILE = join(BUILDER_CONFIG_DIR, "melt-pending.log");
133
- var DRAIN_PARK_LOG_FILE = join(BUILDER_CONFIG_DIR, "drain-park.log");
134
- var DRAIN_HOLD_STATE_FILE = join(BUILDER_CONFIG_DIR, "drain-hold.json");
135
- var MELT_SUCCESS_FILE = join(BUILDER_CONFIG_DIR, "melt-success.json");
136
-
137
- // src/lib/config-dir.ts
138
- import { chmodSync, mkdirSync, statSync } from "fs";
139
- var CONFIG_DIR_MODE = 448;
140
- function ensureConfigDir() {
141
- ensureConfigSubdir(CONFIG_DIR);
142
- }
143
- function ensureConfigSubdir(path) {
144
- mkdirSync(path, { recursive: true, mode: CONFIG_DIR_MODE });
145
- }
146
-
147
- // src/lib/currency.ts
148
58
  function msatsToUsd(msats, rate) {
149
59
  return msats / 1e11 * rate;
150
60
  }
@@ -306,54 +216,8 @@ async function fetchFromApi() {
306
216
  return rate;
307
217
  }
308
218
 
309
- // src/lib/payment-rails/rpc.ts
310
- function resolveRpcOverride(envValue, bundled) {
311
- const override = envValue?.trim() ?? "";
312
- return override.length > 0 ? { url: override, source: "override" } : { url: bundled, source: "bundled" };
313
- }
314
- function resolveRpcHttpTransportOptions(source, envValue) {
315
- if (source !== "override" || !envValue?.trim()) return void 0;
316
- let parsed;
317
- try {
318
- parsed = JSON.parse(envValue);
319
- } catch {
320
- throw new Error("RPC headers must be a JSON object of non-empty string values.");
321
- }
322
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
323
- throw new Error("RPC headers must be a JSON object of non-empty string values.");
324
- const headers = {};
325
- for (const [name, value] of Object.entries(parsed)) {
326
- if (!/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(name) || typeof value !== "string" || value.length === 0 || /[\r\n]/.test(value))
327
- throw new Error("RPC headers must be a JSON object of non-empty string values.");
328
- headers[name] = value;
329
- }
330
- if (Object.keys(headers).length === 0)
331
- throw new Error("RPC headers must be a JSON object of non-empty string values.");
332
- return { fetchOptions: { headers } };
333
- }
334
-
335
219
  export {
336
- DvmError,
337
- providerProseSources,
338
- isAbortError,
339
- transportErrorCode,
340
220
  IMPLICIT_CREDIT_TTL_MS,
341
- CONFIG_FILE,
342
- CONFIG_BACKUP_FILE,
343
- CONFIG_AUDIT_FILE,
344
- CONFIG_PINNED_FILE,
345
- RECEIPTS_FILE,
346
- CREDITS_FILE,
347
- X402_CHANNELS_FILE,
348
- TEMPO_CHANNELS_FILE,
349
- WALLET_FILE,
350
- AGENT_MNEMONIC_FILE,
351
- IDENTITIES_FILE,
352
- BUDGET_FILE,
353
- BUILDER_CONFIG_DIR,
354
- BUILDER_FILE,
355
- BUILDER_KEY_FILE,
356
- ensureConfigDir,
357
221
  COINGECKO_SIMPLE_PRICE_URL,
358
222
  fetchCoinGeckoSpot,
359
223
  fetchCoinGeckoBtcUsd,
@@ -374,7 +238,5 @@ export {
374
238
  fetchBtcUsdRate,
375
239
  getLastKnownBtcRate,
376
240
  formatStaleness,
377
- formatAmountBestEffort,
378
- resolveRpcOverride,
379
- resolveRpcHttpTransportOptions
241
+ formatAmountBestEffort
380
242
  };