@dvmkit/sdk 0.0.0 → 0.1.0-rc.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.
Files changed (41) hide show
  1. package/NOTICE +2 -0
  2. package/README.md +38 -2
  3. package/dist/chunk-27V2ILSR.js +291 -0
  4. package/dist/chunk-5GFED3GJ.js +955 -0
  5. package/dist/chunk-6JZIX5WW.js +1155 -0
  6. package/dist/chunk-7IH5SG2A.js +1038 -0
  7. package/dist/chunk-AT6V3SY7.js +102 -0
  8. package/dist/chunk-DCNT4PJS.js +733 -0
  9. package/dist/chunk-DMNLFNTW.js +135 -0
  10. package/dist/chunk-FROTD5XQ.js +70 -0
  11. package/dist/chunk-H25M54MI.js +149 -0
  12. package/dist/chunk-KQAJVVZT.js +712 -0
  13. package/dist/chunk-KXWROQGK.js +74 -0
  14. package/dist/chunk-L4OYF4DQ.js +67 -0
  15. package/dist/chunk-NTK5DJ6R.js +1256 -0
  16. package/dist/chunk-RPXHKMYE.js +3808 -0
  17. package/dist/chunk-S3XAHZQY.js +63 -0
  18. package/dist/chunk-YG7G4DPZ.js +25 -0
  19. package/dist/credit-ledger-EDMEZSA2.js +28 -0
  20. package/dist/index.d.ts +144 -0
  21. package/dist/index.js +303 -0
  22. package/dist/job-store-C5n6bhap.d.ts +5090 -0
  23. package/dist/memory-credit-ledger-7TTZDSRS.js +9 -0
  24. package/dist/mpp-secret-state-WNAQQ6K4.js +127 -0
  25. package/dist/mpp-setup-MOBWGTWJ.js +30 -0
  26. package/dist/postgres-consumed-credential-store-VHBT4KEA.js +72 -0
  27. package/dist/postgres-job-store-J5F4GUWU.js +7 -0
  28. package/dist/postgres-kv-store-JFBDP5IP.js +7 -0
  29. package/dist/postgres-replay-store-UJXRT6VO.js +7 -0
  30. package/dist/pricing-4CEB34RM.js +48 -0
  31. package/dist/processed-payment-store-HAA4SFNK.js +11 -0
  32. package/dist/revenue-reporter-M35KP6V7.js +435 -0
  33. package/dist/server/index.d.ts +4108 -0
  34. package/dist/server/index.js +22538 -0
  35. package/dist/ssrf-BdHsrrIb.d.ts +325 -0
  36. package/dist/tempo-charge-store-6GJEMNUU.js +130 -0
  37. package/dist/tempo-session-store-FTEEGZXA.js +467 -0
  38. package/dist/testing/index.d.ts +135 -0
  39. package/dist/testing/index.js +151 -0
  40. package/dist/x402-35VLYFKZ.js +1272 -0
  41. package/package.json +89 -6
@@ -0,0 +1,74 @@
1
+ // src/lib/url-redact.ts
2
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3
+ var LONG_HEX_RE = /^[0-9a-f]{16,}$/i;
4
+ var NUMERIC_RE = /^\d{4,}$/;
5
+ var BASE58_RE = /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{32,}$/;
6
+ var OPAQUE_TOKEN_MIN_LENGTH = 32;
7
+ var OPAQUE_TOKEN_MIN_UNIQUE_CHARS = 8;
8
+ var URL_IN_TEXT_RE = /https?:\/\/[^\s"'`<>]+/gi;
9
+ function redactPath(pathname) {
10
+ const segments = pathname.split("/");
11
+ const redacted = segments.map((seg) => {
12
+ if (!seg) return seg;
13
+ if (UUID_RE.test(seg)) return ":uuid";
14
+ if (LONG_HEX_RE.test(seg)) return ":hex";
15
+ if (NUMERIC_RE.test(seg)) return ":n";
16
+ if (BASE58_RE.test(seg)) return ":b58";
17
+ if (isOpaqueToken(seg)) return ":token";
18
+ return seg;
19
+ });
20
+ return redacted.join("/");
21
+ }
22
+ function redactUrl(url) {
23
+ let parsed;
24
+ try {
25
+ parsed = new URL(url);
26
+ } catch {
27
+ return url;
28
+ }
29
+ return `${parsed.origin}${redactPath(parsed.pathname)}`;
30
+ }
31
+ function redactUrlsInText(text) {
32
+ return text.replace(URL_IN_TEXT_RE, (match) => {
33
+ const trailing = /[.,;:!?)\]}]+$/.exec(match)?.[0] ?? "";
34
+ const url = trailing.length > 0 ? match.slice(0, -trailing.length) : match;
35
+ return `${redactUrl(url)}${trailing}`;
36
+ });
37
+ }
38
+ function isOpaqueToken(segment) {
39
+ if (segment.length < OPAQUE_TOKEN_MIN_LENGTH) return false;
40
+ const distinct = /* @__PURE__ */ new Set();
41
+ for (let index = 0; index < segment.length; index++) {
42
+ distinct.add(segment.charCodeAt(index));
43
+ if (distinct.size >= OPAQUE_TOKEN_MIN_UNIQUE_CHARS) return true;
44
+ }
45
+ return false;
46
+ }
47
+
48
+ // src/lib/caller-loggers.ts
49
+ var callerLoggers = buildNoopLoggers();
50
+ function initCallerLoggers(nextLoggers) {
51
+ callerLoggers = nextLoggers;
52
+ }
53
+ function buildNoopLoggers() {
54
+ const noopLogger = {
55
+ // eslint-disable-next-line @typescript-eslint/no-empty-function -- standalone caller has no exporter
56
+ info() {
57
+ },
58
+ async span(_name, _attrs, fn) {
59
+ return fn();
60
+ }
61
+ };
62
+ return {
63
+ cashu: noopLogger,
64
+ lightning: noopLogger,
65
+ x402: noopLogger
66
+ };
67
+ }
68
+
69
+ export {
70
+ redactUrl,
71
+ redactUrlsInText,
72
+ callerLoggers,
73
+ initCallerLoggers
74
+ };
@@ -0,0 +1,67 @@
1
+ import {
2
+ withSdkInitLock
3
+ } from "./chunk-S3XAHZQY.js";
4
+
5
+ // src/sdk/server/postgres-replay-store.ts
6
+ var DEFAULT_TABLE_NAME = "signed_request_replays";
7
+ var DEFAULT_WINDOW_SECONDS = 10 * 60;
8
+ var DEFAULT_GC_SAMPLE_RATE = 0.01;
9
+ var VALID_IDENTIFIER = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
10
+ var PostgresReplayStore = class {
11
+ pool;
12
+ tableName;
13
+ windowSeconds;
14
+ gcSampleRate;
15
+ constructor(pool, opts) {
16
+ const tableName = opts?.tableName ?? DEFAULT_TABLE_NAME;
17
+ if (!VALID_IDENTIFIER.test(tableName)) {
18
+ throw new Error(
19
+ `PostgresReplayStore: tableName must match ${VALID_IDENTIFIER.source}, got "${tableName}"`
20
+ );
21
+ }
22
+ this.pool = pool;
23
+ this.tableName = tableName;
24
+ this.windowSeconds = opts?.windowSeconds ?? DEFAULT_WINDOW_SECONDS;
25
+ this.gcSampleRate = opts?.gcSampleRate ?? DEFAULT_GC_SAMPLE_RATE;
26
+ }
27
+ /** Run the CREATE TABLE migration. Idempotent — safe to call repeatedly. */
28
+ async init() {
29
+ await withSdkInitLock(this.pool, () => this.createTables());
30
+ }
31
+ /** The boot DDL itself — always runs under {@link withSdkInitLock} (internal-review). */
32
+ async createTables() {
33
+ await this.pool.query(`
34
+ CREATE TABLE IF NOT EXISTS ${this.tableName} (
35
+ pubkey TEXT NOT NULL,
36
+ timestamp BIGINT NOT NULL,
37
+ nonce TEXT NOT NULL,
38
+ recorded_at BIGINT NOT NULL,
39
+ PRIMARY KEY (pubkey, timestamp, nonce)
40
+ );
41
+ CREATE INDEX IF NOT EXISTS ${this.tableName}_recorded_at_idx
42
+ ON ${this.tableName} (recorded_at);
43
+ `);
44
+ }
45
+ async checkAndRecord(pubkey, timestamp, nonce, now) {
46
+ const { rowCount } = await this.pool.query(
47
+ `INSERT INTO ${this.tableName} (pubkey, timestamp, nonce, recorded_at)
48
+ VALUES ($1, $2, $3, $4)
49
+ ON CONFLICT DO NOTHING`,
50
+ [pubkey, timestamp, nonce, now]
51
+ );
52
+ if (this.gcSampleRate > 0 && Math.random() < this.gcSampleRate) {
53
+ this.gcSweep(now);
54
+ }
55
+ return rowCount === 0;
56
+ }
57
+ gcSweep(now) {
58
+ const cutoff = now - this.windowSeconds;
59
+ this.pool.query(`DELETE FROM ${this.tableName} WHERE recorded_at < $1`, [cutoff]).catch((err) => {
60
+ console.error("PostgresReplayStore GC sweep failed:", err);
61
+ });
62
+ }
63
+ };
64
+
65
+ export {
66
+ PostgresReplayStore
67
+ };