@seedprotocol/arweave 0.7.9-next.1189.g5e63267 → 0.7.9-next.1306.g4ff6582

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,43 +1,44 @@
1
- import "graphql-request";
1
+ import { GraphQLClient as e } from "graphql-request";
2
+ import t from "debug";
2
3
  //#region src/constants.ts
3
- var e = "ar.seedprotocol.io", t = "", n = "", r = "127.0.0.1", i = 1984, a = `https://${e}/graphql`, o = [
4
+ var n = "ar.seedprotocol.io", r = "", i = "", a = "127.0.0.1", o = 1984, s = `https://${n}/graphql`, c = [
4
5
  "ar.seedprotocol.io",
5
6
  "arweave.net",
6
7
  "arweave.dev",
7
8
  "g8way.io",
8
9
  "permagate.io",
9
10
  "zigza.xyz"
10
- ], s = ["ARWEAVE_READ_GATEWAYS", "NEXT_PUBLIC_ARWEAVE_READ_GATEWAYS"], ee = [
11
+ ], ee = ["ARWEAVE_READ_GATEWAYS", "NEXT_PUBLIC_ARWEAVE_READ_GATEWAYS"], te = [
11
12
  "NEXT_PUBLIC_ARWEAVE_HOST",
12
13
  "ARWEAVE_HOST",
13
14
  "VITE_ARWEAVE_HOST"
14
15
  ];
15
- function te(e) {
16
+ function ne(e) {
16
17
  let t = e.trim();
17
18
  return t.startsWith("http://") ? t.slice(7).replace(/\/$/, "") : t.startsWith("https://") ? t.slice(8).replace(/\/$/, "") : t.replace(/\/$/, "");
18
19
  }
19
- function c() {
20
- if (typeof process < "u" && process.env) for (let e of ee) {
20
+ function l() {
21
+ if (typeof process < "u" && process.env) for (let e of te) {
21
22
  let t = process.env[e]?.trim();
22
- if (t) return te(t);
23
+ if (t) return ne(t);
23
24
  }
24
25
  }
25
- function ne(t, n) {
26
- let r = t.trim().toLowerCase().replace(/\/$/, ""), i = e.toLowerCase();
27
- return r === i ? [...n] : n.filter((e) => e.toLowerCase() !== i);
26
+ function re(e, t) {
27
+ let r = e.trim().toLowerCase().replace(/\/$/, ""), i = n.toLowerCase();
28
+ return r === i ? [...t] : t.filter((e) => e.toLowerCase() !== i);
28
29
  }
29
- function l(e) {
30
- return d(e, ne(e, u()));
30
+ function u(e) {
31
+ return ae(e, re(e, ie()));
31
32
  }
32
- function u() {
33
- if (typeof process > "u" || !process.env) return [...o];
34
- for (let e of s) {
33
+ function ie() {
34
+ if (typeof process > "u" || !process.env) return [...c];
35
+ for (let e of ee) {
35
36
  let t = process.env[e]?.trim();
36
37
  if (t) return t.split(",").map((e) => e.trim()).filter(Boolean);
37
38
  }
38
- return [...o];
39
+ return [...c];
39
40
  }
40
- function d(e, t) {
41
+ function ae(e, t) {
41
42
  let n = /* @__PURE__ */ new Set(), r = [], i = (e) => e.trim().toLowerCase().replace(/\/$/, ""), a = (e) => {
42
43
  let t = e.trim().replace(/\/$/, "");
43
44
  if (!t) return;
@@ -48,11 +49,11 @@ function d(e, t) {
48
49
  for (let e of t) a(e);
49
50
  return r;
50
51
  }
51
- function re(e) {
52
+ function oe(e) {
52
53
  let t = e.trim().toLowerCase();
53
54
  if (!t) return !1;
54
55
  if (t.endsWith("arweave.net") || t.endsWith("ar-io.net")) return !0;
55
- for (let e of o) {
56
+ for (let e of c) {
56
57
  let n = e.toLowerCase();
57
58
  if (t === n || t.endsWith(`.${n}`)) return !0;
58
59
  }
@@ -60,46 +61,46 @@ function re(e) {
60
61
  }
61
62
  //#endregion
62
63
  //#region src/content/arweaveContent.ts
63
- var f;
64
- function ie(e) {
65
- f = e;
64
+ var d;
65
+ function se(e) {
66
+ d = e;
66
67
  }
67
- function ae() {
68
- return f !== void 0;
68
+ function ce() {
69
+ return d !== void 0;
69
70
  }
70
- async function p(e, t) {
71
- return f ? f(e, t) : e;
71
+ async function f(e, t) {
72
+ return d ? d(e, t) : e;
72
73
  }
73
- function oe(e) {
74
+ function p(e) {
74
75
  return (e.headers?.get("content-type"))?.split(";")[0]?.trim().toLowerCase() || void 0;
75
76
  }
76
77
  async function m(e, t) {
77
- return p({
78
+ return f({
78
79
  bytes: new Uint8Array(await e.arrayBuffer()),
79
- contentType: oe(e)
80
+ contentType: p(e)
80
81
  }, t);
81
82
  }
82
83
  //#endregion
83
84
  //#region src/moduleOwner.ts
84
85
  var h = Symbol.for("@seedprotocol/arweave:clientOwner"), g = Object.freeze({ package: "@seedprotocol/arweave" });
85
- function se() {
86
+ function le() {
86
87
  globalThis[h] = g;
87
88
  }
88
- var ce = class extends Error {
89
+ var _ = class extends Error {
89
90
  constructor() {
90
91
  super("Two copies of @seedprotocol/arweave are loaded, and the Arweave client was registered on the other copy (e.g. by SeedClient). Reads through this copy would use a different client and gateway. Make sure every @seedprotocol/* package is the same version and installed once (`npm ls @seedprotocol/arweave`). With Vite, keep @seedprotocol/* packages out of optimizeDeps.exclude so they are pre-bundled together, and dedupe them (seedVitePlugin does) when they are linked into the app."), this.name = "DuplicateArweaveModuleError";
91
92
  }
92
93
  };
93
- function le() {
94
+ function ue() {
94
95
  let e = globalThis[h];
95
- if (e !== void 0 && e !== g) throw new ce();
96
+ if (e !== void 0 && e !== g) throw new _();
96
97
  }
97
- function ue() {
98
+ function de() {
98
99
  delete globalThis[h];
99
100
  }
100
101
  //#endregion
101
102
  //#region src/ArweaveClient/BaseArweaveClient.ts
102
- function _(e) {
103
+ function v(e) {
103
104
  let t = e.trim();
104
105
  return t.startsWith("http://") ? {
105
106
  protocol: "http",
@@ -112,11 +113,11 @@ function _(e) {
112
113
  host: t.replace(/\/$/, "")
113
114
  };
114
115
  }
115
- var v = e, y = "https", b = !1, x = !1, S = class e {
116
+ var y = n, b = "https", x = !1, S = !1, C = class e {
116
117
  static _impl = null;
117
118
  static configure(t) {
118
119
  if (!t) throw Error("Cannot configure ArweaveClient with undefined or null. Ensure the platform-specific ArweaveClient is properly created.");
119
- e._impl = t, se();
120
+ e._impl = t, le();
120
121
  }
121
122
  static isConfigured() {
122
123
  return e._impl != null;
@@ -126,10 +127,10 @@ var v = e, y = "https", b = !1, x = !1, S = class e {
126
127
  return e._impl;
127
128
  }
128
129
  static resolveGateway() {
129
- let e = c();
130
- return e && !b && !x ? _(e) : {
131
- protocol: y,
132
- host: v
130
+ let e = l();
131
+ return e && !x && !S ? v(e) : {
132
+ protocol: b,
133
+ host: y
133
134
  };
134
135
  }
135
136
  static getHost() {
@@ -168,22 +169,22 @@ var v = e, y = "https", b = !1, x = !1, S = class e {
168
169
  return `${e}://${t}`;
169
170
  }
170
171
  static setHost(e) {
171
- let t = _(e);
172
- v = t.host, y = t.protocol, b = !0, x = !1;
172
+ let t = v(e);
173
+ y = t.host, b = t.protocol, x = !0, S = !1;
173
174
  }
174
175
  static isReadGatewayLocked() {
175
- return b;
176
+ return x;
176
177
  }
177
178
  static resetReadGatewaySelectionStateForTests() {
178
- x = !1;
179
+ S = !1;
179
180
  }
180
181
  static setPreferredReadGateway(e) {
181
- let t = _(e);
182
- v = t.host, y = t.protocol, b = !1;
182
+ let t = v(e);
183
+ y = t.host, b = t.protocol, x = !1;
183
184
  }
184
185
  static applyProbedReadGateway(e) {
185
- let t = _(e);
186
- v = t.host, y = t.protocol, b = !1, x = !0;
186
+ let t = v(e);
187
+ y = t.host, b = t.protocol, x = !1, S = !0;
187
188
  }
188
189
  static getEndpoint() {
189
190
  return `${this.getBaseUrl()}/graphql`;
@@ -202,8 +203,8 @@ var v = e, y = "https", b = !1, x = !1, S = class e {
202
203
  }
203
204
  static async getTransactionData(t, n) {
204
205
  let r = await e.requireImpl().getTransactionData(t, n);
205
- if (n?.decode === !1 || !ae()) return r;
206
- let i = typeof r == "string", { bytes: a } = await p({ bytes: i ? new TextEncoder().encode(r) : r }, { transactionId: t });
206
+ if (n?.decode === !1 || !ce()) return r;
207
+ let i = typeof r == "string", { bytes: a } = await f({ bytes: i ? new TextEncoder().encode(r) : r }, { transactionId: t });
207
208
  return i ? new TextDecoder().decode(a) : a;
208
209
  }
209
210
  static getTransactionTags(t) {
@@ -215,7 +216,7 @@ var v = e, y = "https", b = !1, x = !1, S = class e {
215
216
  static downloadFiles(t) {
216
217
  return e.requireImpl().downloadFiles(t);
217
218
  }
218
- }, de = {
219
+ }, fe = {
219
220
  "\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n": {
220
221
  kind: "Document",
221
222
  definitions: [{
@@ -569,85 +570,85 @@ var v = e, y = "https", b = !1, x = !1, S = class e {
569
570
  }]
570
571
  }
571
572
  };
572
- function fe(e) {
573
- return de[e] ?? {};
573
+ function pe(e) {
574
+ return fe[e] ?? {};
574
575
  }
575
576
  //#endregion
576
577
  //#region src/ArweaveClient/queries.ts
577
- var pe = fe("\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n"), me = fe("\n query GetArweaveTransactions(\n $owners: [String!]\n $first: Int\n $after: String\n ) {\n transactions(owners: $owners, first: $first, after: $after) {\n edges {\n cursor\n node {\n id\n anchor\n signature\n block {\n id\n height\n }\n data {\n size\n type\n }\n tags {\n name\n value\n }\n }\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n"), C = 1, w = 6e4, T = C, E = w, D = /* @__PURE__ */ new Map();
578
- function O(e) {
578
+ var me = pe("\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n"), he = pe("\n query GetArweaveTransactions(\n $owners: [String!]\n $first: Int\n $after: String\n ) {\n transactions(owners: $owners, first: $first, after: $after) {\n edges {\n cursor\n node {\n id\n anchor\n signature\n block {\n id\n height\n }\n data {\n size\n type\n }\n tags {\n name\n value\n }\n }\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n"), ge = 1, _e = 6e4, w = ge, T = _e, E = /* @__PURE__ */ new Map();
579
+ function D(e) {
579
580
  let t = e.trim();
580
581
  return t ? (t.startsWith("http://") ? t = t.slice(7) : t.startsWith("https://") && (t = t.slice(8)), t.replace(/\/$/, "").toLowerCase()) : "";
581
582
  }
582
- function he(e) {
583
- let t = D.get(e);
583
+ function O(e) {
584
+ let t = E.get(e);
584
585
  return t || (t = {
585
586
  failures: 0,
586
587
  openedAt: null,
587
588
  halfOpenProbeInFlight: !1
588
- }, D.set(e, t)), t;
589
+ }, E.set(e, t)), t;
589
590
  }
590
591
  function k(e, t) {
591
- return e.openedAt == null ? "closed" : t - e.openedAt >= E ? "half-open" : "open";
592
+ return e.openedAt == null ? "closed" : t - e.openedAt >= T ? "half-open" : "open";
592
593
  }
593
- function ge(e) {
594
- e.failureThreshold != null && e.failureThreshold >= 1 && (T = e.failureThreshold), e.openDurationMs != null && e.openDurationMs >= 0 && (E = e.openDurationMs);
594
+ function ve(e) {
595
+ e.failureThreshold != null && e.failureThreshold >= 1 && (w = e.failureThreshold), e.openDurationMs != null && e.openDurationMs >= 0 && (T = e.openDurationMs);
595
596
  }
596
597
  function A() {
597
- D.clear(), T = C, E = w;
598
+ E.clear(), w = ge, T = _e;
598
599
  }
599
600
  function j(e, t = Date.now()) {
600
- let n = O(e);
601
+ let n = D(e);
601
602
  if (!n) return !1;
602
- let r = D.get(n);
603
+ let r = E.get(n);
603
604
  if (!r) return !1;
604
605
  let i = k(r, t);
605
606
  return !!(i === "open" || i === "half-open" && r.halfOpenProbeInFlight);
606
607
  }
607
- function _e(e, t = Date.now()) {
608
- let n = O(e);
608
+ function ye(e, t = Date.now()) {
609
+ let n = D(e);
609
610
  if (!n) return "closed";
610
- let r = D.get(n);
611
+ let r = E.get(n);
611
612
  return r ? k(r, t) : "closed";
612
613
  }
613
614
  function M(e, t = Date.now()) {
614
- let n = O(e);
615
+ let n = D(e);
615
616
  if (!n) return;
616
- let r = he(n);
617
+ let r = O(n);
617
618
  k(r, t) === "half-open" && (r.halfOpenProbeInFlight = !0);
618
619
  }
619
620
  function N(e) {
620
- let t = O(e);
621
- t && D.set(t, {
621
+ let t = D(e);
622
+ t && E.set(t, {
622
623
  failures: 0,
623
624
  openedAt: null,
624
625
  halfOpenProbeInFlight: !1
625
626
  });
626
627
  }
627
628
  function P(e, t = Date.now()) {
628
- let n = O(e);
629
+ let n = D(e);
629
630
  if (!n) return;
630
- let r = he(n);
631
- r.failures += 1, r.halfOpenProbeInFlight = !1, r.failures >= T && (r.openedAt = t);
631
+ let r = O(n);
632
+ r.failures += 1, r.halfOpenProbeInFlight = !1, r.failures >= w && (r.openedAt = t);
632
633
  }
633
- function ve(e = Date.now()) {
634
+ function be(e = Date.now()) {
634
635
  let t = [];
635
- for (let n of D.keys()) j(n, e) && t.push(n);
636
+ for (let n of E.keys()) j(n, e) && t.push(n);
636
637
  return t;
637
638
  }
638
639
  //#endregion
639
640
  //#region src/ArweaveClient/selectReadGateway.ts
640
- var F = 18e4, ye = 6e4, be = 5e3, I = null, L = null, R = null;
641
+ var F = 18e4, xe = 6e4, Se = 5e3, I = null, L = null, R = null;
641
642
  function z() {
642
643
  I = null, L = null;
643
644
  }
644
- function xe() {
645
- z(), R = null, A(), S.resetReadGatewaySelectionStateForTests(), S.isReadGatewayLocked() || S.setPreferredReadGateway(e);
645
+ function Ce() {
646
+ z(), R = null, A(), C.resetReadGatewaySelectionStateForTests(), C.isReadGatewayLocked() || C.setPreferredReadGateway(n);
646
647
  }
647
- function Se() {
648
- return S.isReadGatewayLocked() ? !0 : I && Date.now() < I.expiresAt ? I.healthy : R != null;
648
+ function we() {
649
+ return C.isReadGatewayLocked() ? !0 : I && Date.now() < I.expiresAt ? I.healthy : R != null;
649
650
  }
650
- function Ce() {
651
+ function Te() {
651
652
  return R;
652
653
  }
653
654
  async function B(e, t) {
@@ -660,7 +661,7 @@ async function B(e, t) {
660
661
  if (j(r)) return !1;
661
662
  M(r);
662
663
  let i, a = new AbortController(), o = t ?? a.signal;
663
- t || (i = setTimeout(() => a.abort(), be));
664
+ t || (i = setTimeout(() => a.abort(), Se));
664
665
  try {
665
666
  let e = await fetch(n, {
666
667
  method: "GET",
@@ -689,31 +690,31 @@ async function V(e, t = "https", n) {
689
690
  }
690
691
  return null;
691
692
  }
692
- function we() {
693
- return l(S.getHost());
693
+ function Ee() {
694
+ return u(C.getHost());
694
695
  }
695
- async function H(e) {
696
- if (S.isReadGatewayLocked()) return S.getHost();
696
+ async function De(e) {
697
+ if (C.isReadGatewayLocked()) return C.getHost();
697
698
  if (I && Date.now() < I.expiresAt) return I.host;
698
699
  if (L) return L;
699
700
  L = (async () => {
700
- let t = await V(we(), S.getProtocol(), e);
701
- if (S.isReadGatewayLocked()) I = {
702
- host: S.getHost(),
701
+ let t = await V(Ee(), C.getProtocol(), e);
702
+ if (C.isReadGatewayLocked()) I = {
703
+ host: C.getHost(),
703
704
  healthy: !0,
704
705
  expiresAt: Date.now() + F
705
706
  };
706
- else if (t) S.applyProbedReadGateway(t), R = t, I = {
707
+ else if (t) C.applyProbedReadGateway(t), R = t, I = {
707
708
  host: t,
708
709
  healthy: !0,
709
710
  expiresAt: Date.now() + F
710
711
  };
711
712
  else {
712
- let e = R ?? S.getHost();
713
- R && S.getHost() !== R && S.applyProbedReadGateway(R), I = {
713
+ let e = R ?? C.getHost();
714
+ R && C.getHost() !== R && C.applyProbedReadGateway(R), I = {
714
715
  host: e,
715
716
  healthy: !1,
716
- expiresAt: Date.now() + ye
717
+ expiresAt: Date.now() + xe
717
718
  };
718
719
  }
719
720
  return I.host;
@@ -726,11 +727,11 @@ async function H(e) {
726
727
  }
727
728
  //#endregion
728
729
  //#region src/gateway/resolveSeedGatewayEndpoints.ts
729
- var U = 18e4, W = null, G = /* @__PURE__ */ new Map();
730
- function K() {
731
- W = null, G.clear();
730
+ var Oe = 18e4, H = null, U = /* @__PURE__ */ new Map();
731
+ function ke() {
732
+ H = null, U.clear();
732
733
  }
733
- function Te(e) {
734
+ function Ae(e) {
734
735
  let t = (e ?? "ar.seedprotocol.io").trim();
735
736
  return t.startsWith("http://") ? {
736
737
  protocol: "http",
@@ -743,11 +744,11 @@ function Te(e) {
743
744
  host: t.replace(/\/$/, "")
744
745
  };
745
746
  }
746
- function Ee(e) {
747
- let { host: t, protocol: n } = Te(e.arweaveDomain);
747
+ function je(e) {
748
+ let { host: t, protocol: n } = Ae(e.arweaveDomain);
748
749
  return `${n}://${t}`;
749
750
  }
750
- function De(e) {
751
+ function Me(e) {
751
752
  let t = e.hyper?.localSidecarHost?.trim() || "127.0.0.1", n = e.hyper?.localSidecarPort ?? 1984;
752
753
  return {
753
754
  host: n === 80 || n === 443 ? t : `${t}:${n}`,
@@ -755,7 +756,7 @@ function De(e) {
755
756
  baseUrl: `http://${t}:${n}`
756
757
  };
757
758
  }
758
- function Oe() {
759
+ function Ne() {
759
760
  try {
760
761
  let e = globalThis.window?.location?.origin;
761
762
  return typeof e == "string" && e.length > 0 ? e.replace(/\/$/, "") : void 0;
@@ -763,37 +764,37 @@ function Oe() {
763
764
  return;
764
765
  }
765
766
  }
766
- function q(e, t) {
767
+ function W(e, t) {
767
768
  let n = e.trim();
768
769
  if (!n) throw Error("proxyBaseUrl is empty");
769
770
  if (n.startsWith("http://") || n.startsWith("https://")) return n.replace(/\/$/, "");
770
771
  if (n.startsWith("/")) {
771
- let r = (t?.origin?.trim() || Oe() || "").replace(/\/$/, "");
772
+ let r = (t?.origin?.trim() || Ne() || "").replace(/\/$/, "");
772
773
  if (!r) throw Error(`Relative proxyBaseUrl "${e}" requires a browser origin or resolve options.origin`);
773
774
  return `${r}${n.replace(/\/$/, "")}`;
774
775
  }
775
776
  return `https://${n.replace(/\/$/, "")}`;
776
777
  }
777
- async function J(e, t, n) {
778
+ async function G(e, t, n) {
778
779
  let r = Date.now();
779
780
  if (t === "sidecar") {
780
- if (W && r < W.expiresAt) return W.healthy;
781
+ if (H && r < H.expiresAt) return H.healthy;
781
782
  let t = await B(e, n);
782
- return W = {
783
+ return H = {
783
784
  healthy: t,
784
- expiresAt: r + U
785
+ expiresAt: r + Oe
785
786
  }, t;
786
787
  }
787
- let i = G.get(t);
788
+ let i = U.get(t);
788
789
  if (i && r < i.expiresAt) return i.healthy;
789
790
  let a = await B(e, n);
790
- return G.set(t, {
791
+ return U.set(t, {
791
792
  healthy: a,
792
- expiresAt: r + U
793
+ expiresAt: r + Oe
793
794
  }), a;
794
795
  }
795
- function ke(e) {
796
- let { host: t, protocol: n } = Te(e.arweaveDomain), r = `${n}://${t}`, i = e.uploadApiBaseUrl?.trim() || r;
796
+ function Pe(e) {
797
+ let { host: t, protocol: n } = Ae(e.arweaveDomain), r = `${n}://${t}`, i = e.uploadApiBaseUrl?.trim() || r;
797
798
  return {
798
799
  mode: e.transport ?? "http-gateway",
799
800
  arweaveHost: t,
@@ -806,8 +807,8 @@ function ke(e) {
806
807
  publicArweaveBaseUrl: r
807
808
  };
808
809
  }
809
- function Ae(e) {
810
- let t = De(e), n = e.hyper?.gatewayHyperKey?.trim();
810
+ function Fe(e) {
811
+ let t = Me(e), n = e.hyper?.gatewayHyperKey?.trim();
811
812
  return {
812
813
  mode: "hyper",
813
814
  arweaveHost: t.host,
@@ -817,10 +818,10 @@ function Ae(e) {
817
818
  uploadApiBaseUrl: t.baseUrl,
818
819
  activePath: "hyper-sidecar",
819
820
  gatewayHyperKey: n || void 0,
820
- publicArweaveBaseUrl: Ee(e)
821
+ publicArweaveBaseUrl: je(e)
821
822
  };
822
823
  }
823
- function je(e, t) {
824
+ function Ie(e, t) {
824
825
  let n = new URL(t), r = n.protocol === "http:" ? "http" : "https", i = n.pathname.replace(/\/$/, ""), a = i ? `${n.host}${i}` : n.host, o = `${r}://${a}`;
825
826
  return {
826
827
  mode: e.transport ?? "http-gateway",
@@ -832,56 +833,56 @@ function je(e, t) {
832
833
  activePath: "http-proxy",
833
834
  gatewayHyperKey: e.hyper?.gatewayHyperKey?.trim() || void 0,
834
835
  proxyBaseUrl: t,
835
- publicArweaveBaseUrl: Ee(e)
836
+ publicArweaveBaseUrl: je(e)
836
837
  };
837
838
  }
838
- async function Me(e, t) {
839
+ async function Le(e, t) {
839
840
  let n = e.proxyBaseUrl?.trim();
840
841
  if (!n) return null;
841
- let r = q(n, { origin: t?.origin });
842
- return e.hyper?.probeSidecar !== !1 && !await J(r, `proxy:${r}`, t?.signal) ? null : je(e, r);
842
+ let r = W(n, { origin: t?.origin });
843
+ return e.hyper?.probeSidecar !== !1 && !await G(r, `proxy:${r}`, t?.signal) ? null : Ie(e, r);
843
844
  }
844
- async function Ne(e, t) {
845
- t?.forceSidecarProbe && K();
845
+ async function Re(e, t) {
846
+ t?.forceSidecarProbe && ke();
846
847
  let n = e.transport ?? "http-gateway", r = e.hyper?.probeSidecar !== !1;
847
848
  if (n === "http-gateway") {
848
849
  if (e.proxyBaseUrl?.trim()) {
849
- let i = q(e.proxyBaseUrl, { origin: t?.origin });
850
- if (r && !await J(i, `proxy:${i}`, t?.signal)) throw Error(`Gateway HTTP proxy not reachable at ${i}. Ensure your Node route runs createGatewayProxy (or equivalent) and mounts at proxyBaseUrl.`);
851
- return je({
850
+ let i = W(e.proxyBaseUrl, { origin: t?.origin });
851
+ if (r && !await G(i, `proxy:${i}`, t?.signal)) throw Error(`Gateway HTTP proxy not reachable at ${i}. Ensure your Node route runs createGatewayProxy (or equivalent) and mounts at proxyBaseUrl.`);
852
+ return Ie({
852
853
  ...e,
853
854
  transport: n
854
855
  }, i);
855
856
  }
856
- return ke({
857
+ return Pe({
857
858
  ...e,
858
859
  transport: n
859
860
  });
860
861
  }
861
862
  if (n === "hyper") {
862
- let i = await Me({
863
+ let i = await Le({
863
864
  ...e,
864
865
  transport: n
865
866
  }, t);
866
867
  if (i) return i;
867
- let a = Ae({
868
+ let a = Fe({
868
869
  ...e,
869
870
  transport: n
870
871
  });
871
- if (r && !await J(a.arweaveBaseUrl, "sidecar", t?.signal)) throw Error(`Gateway Hyper sidecar not reachable at ${a.arweaveBaseUrl}. Run: seed-gateway connect <operator-z32-key> — or configure gateway.proxyBaseUrl for an app-server proxy.`);
872
+ if (r && !await G(a.arweaveBaseUrl, "sidecar", t?.signal)) throw Error(`Gateway Hyper sidecar not reachable at ${a.arweaveBaseUrl}. Run: seed-gateway connect <operator-z32-key> — or configure gateway.proxyBaseUrl for an app-server proxy.`);
872
873
  return a;
873
874
  }
874
- let i = await Me({
875
+ let i = await Le({
875
876
  ...e,
876
877
  transport: n
877
878
  }, t);
878
879
  if (i) return i;
879
- let a = De(e);
880
- return r && await J(a.baseUrl, "sidecar", t?.signal) ? Ae({
880
+ let a = Me(e);
881
+ return r && await G(a.baseUrl, "sidecar", t?.signal) ? Fe({
881
882
  ...e,
882
883
  transport: "hyper"
883
884
  }) : {
884
- ...ke({
885
+ ...Pe({
885
886
  ...e,
886
887
  transport: "http-gateway"
887
888
  }),
@@ -889,67 +890,67 @@ async function Ne(e, t) {
889
890
  activePath: "hybrid-fallback-http"
890
891
  };
891
892
  }
892
- function Pe(e, t) {
893
- return e.activePath === "hyper-sidecar" || e.activePath === "http-proxy" ? [e.arweaveHost] : l(e.arweaveHost);
893
+ function ze(e, t) {
894
+ return e.activePath === "hyper-sidecar" || e.activePath === "http-proxy" ? [e.arweaveHost] : u(e.arweaveHost);
894
895
  }
895
896
  //#endregion
896
897
  //#region src/gateway/gatewayState.ts
897
- var Fe = null;
898
- function Y() {
899
- return Fe;
898
+ var Be = null;
899
+ function K() {
900
+ return Be;
900
901
  }
901
- function Ie(e) {
902
- Fe = e;
902
+ function Ve(e) {
903
+ Be = e;
903
904
  }
904
- var Le = [];
905
- function X() {
906
- return Le;
905
+ var He = [];
906
+ function q() {
907
+ return He;
907
908
  }
908
- function Re(e) {
909
+ function Ue(e) {
909
910
  let t = [], n = /* @__PURE__ */ new Set();
910
911
  for (let r of e) {
911
912
  let e = r?.trim();
912
913
  if (!e) continue;
913
914
  let i;
914
915
  try {
915
- let t = new URL(/^https?:\/\//i.test(e) ? e : q(e));
916
+ let t = new URL(/^https?:\/\//i.test(e) ? e : W(e));
916
917
  i = `${t.origin}${t.pathname.replace(/\/+$/, "")}`;
917
918
  } catch {
918
919
  continue;
919
920
  }
920
921
  n.has(i) || (n.add(i), t.push(i));
921
922
  }
922
- Le = t;
923
+ He = t;
923
924
  }
924
925
  //#endregion
925
926
  //#region src/gateway/readBaseUrls.ts
926
- var ze = 1e4;
927
- function Z(e, t, n) {
927
+ var We = 1e4;
928
+ function J(e, t, n) {
928
929
  let r = n.trim().replace(/\/$/, "");
929
930
  r && !t.has(r) && (t.add(r), e.push(r));
930
931
  }
931
- function Q(e) {
932
- let t = Y(), n = S.getProtocol(), r = t ? Pe(t) : e?.fallbackHosts?.length ? [...e.fallbackHosts] : l(S.getHost()), i = [], a = /* @__PURE__ */ new Set();
932
+ function Y(e) {
933
+ let t = K(), n = C.getProtocol(), r = t ? ze(t) : e?.fallbackHosts?.length ? [...e.fallbackHosts] : u(C.getHost()), i = [], a = /* @__PURE__ */ new Set();
933
934
  for (let e of r) {
934
935
  let t = e.trim();
935
- t && Z(i, a, /^https?:\/\//i.test(t) ? t : `${n}://${t}`);
936
+ t && J(i, a, /^https?:\/\//i.test(t) ? t : `${n}://${t}`);
936
937
  }
937
938
  return i;
938
939
  }
939
- function Be(e) {
940
+ function Ge(e) {
940
941
  let t = [], n = /* @__PURE__ */ new Set();
941
- for (let e of X()) Z(t, n, e);
942
- for (let r of Q(e)) Z(t, n, r);
942
+ for (let e of q()) J(t, n, e);
943
+ for (let r of Y(e)) J(t, n, r);
943
944
  return t;
944
945
  }
945
- async function Ve() {
946
+ async function Ke() {
946
947
  try {
947
- let e = Y();
948
+ let e = K();
948
949
  if (e && (e.activePath === "hyper-sidecar" || e.activePath === "http-proxy")) return;
949
- await H();
950
+ await De();
950
951
  } catch {}
951
952
  }
952
- async function $(e, t, n) {
953
+ async function X(e, t, n) {
953
954
  let r = new AbortController(), i = setTimeout(() => r.abort(), n?.timeoutMs ?? 1e4);
954
955
  try {
955
956
  let n = await fetch(`${e.replace(/\/$/, "")}/raw/${encodeURIComponent(t)}`, {
@@ -964,24 +965,24 @@ async function $(e, t, n) {
964
965
  clearTimeout(i);
965
966
  }
966
967
  }
967
- async function He(e, t) {
968
+ async function qe(e, t) {
968
969
  let n = /* @__PURE__ */ new Set(), r = async (r) => {
969
970
  for (let i of r) {
970
971
  if (n.has(i)) continue;
971
972
  n.add(i);
972
- let r = await $(i, e, t);
973
+ let r = await X(i, e, t);
973
974
  if (r) try {
974
975
  let { bytes: t } = await m(r, { transactionId: e }), n = new TextDecoder().decode(t);
975
976
  if (n.length > 0) return n;
976
977
  } catch {}
977
978
  }
978
979
  };
979
- return await r(X()) || (await Ve(), r(Q(t)));
980
+ return await r(q()) || (await Ke(), r(Y(t)));
980
981
  }
981
982
  //#endregion
982
983
  //#region src/gateway/transactionStatus.ts
983
- var Ue = 1e4, We = 2e4, Ge = (e) => e >= 500 || e === 429;
984
- async function Ke(e, t, n) {
984
+ var Je = 1e4, Ye = 2e4, Xe = (e) => e >= 500 || e === 429;
985
+ async function Ze(e, t, n) {
985
986
  let r = new AbortController(), i = setTimeout(() => r.abort(), n);
986
987
  try {
987
988
  let n = await fetch(`${e.replace(/\/$/, "")}/${encodeURIComponent(t)}`, {
@@ -989,7 +990,7 @@ async function Ke(e, t, n) {
989
990
  credentials: "omit",
990
991
  signal: r.signal
991
992
  });
992
- return await n.body?.cancel().catch(() => {}), Ge(n.status) ? {
993
+ return await n.body?.cancel().catch(() => {}), Xe(n.status) ? {
993
994
  kind: "retry",
994
995
  status: n.status
995
996
  } : {
@@ -1005,12 +1006,12 @@ async function Ke(e, t, n) {
1005
1006
  clearTimeout(i);
1006
1007
  }
1007
1008
  }
1008
- async function qe(e, t = {}) {
1009
- let n = t.timeoutMs ?? 1e4, r = Date.now() + (t.totalTimeoutMs ?? 2e4), i = t.baseUrls ?? Be(), a = i.filter((e) => !j(e)), o = a.length > 0 ? a : i, s = 500;
1009
+ async function Qe(e, t = {}) {
1010
+ let n = t.timeoutMs ?? 1e4, r = Date.now() + (t.totalTimeoutMs ?? 2e4), i = t.baseUrls ?? Ge(), a = i.filter((e) => !j(e)), o = a.length > 0 ? a : i, s = 500;
1010
1011
  for (let t of o) {
1011
1012
  let i = r - Date.now();
1012
1013
  if (i <= 0) break;
1013
- let a = await Ke(t, e, Math.min(n, i));
1014
+ let a = await Ze(t, e, Math.min(n, i));
1014
1015
  if (a.kind === "answer") return N(t), {
1015
1016
  status: a.status >= 200 && a.status < 300 ? 200 : a.status,
1016
1017
  confirmed: null
@@ -1023,6 +1024,92 @@ async function qe(e, t = {}) {
1023
1024
  };
1024
1025
  }
1025
1026
  //#endregion
1026
- export { l as $, O as A, oe as B, xe as C, _e as D, ge as E, pe as F, ee as G, m as H, S as I, e as J, o as K, ce as L, N as M, A as N, j as O, me as P, n as Q, le as R, B as S, M as T, ie as U, ae as V, p as W, i as X, r as Y, t as Z, Ne as _, Ve as a, z as b, Be as c, Y as d, u as et, Re as f, q as g, K as h, ze as i, P as j, ve as k, Q as l, Pe as m, We as n, d as nt, $ as o, Ie as p, a as q, qe as r, c as rt, He as s, Ue as t, re as tt, X as u, H as v, V as w, Se as x, Ce as y, ue as z };
1027
+ //#region src/default/ArweaveClient.ts
1028
+ var Z = t("seedArweave:ArweaveClient"), Q = null, $e = null, $ = async () => {
1029
+ let e = `${C.getProtocol()}://${C.getHost()}`;
1030
+ if (Q && $e === e) return Q;
1031
+ let t = await import("arweave"), n = t.default ?? t;
1032
+ return typeof n.init != "function" && typeof n.default?.init == "function" && (n = n.default), $e = e, Q = n.init(C.getArweaveJsApiConfig()), Q;
1033
+ }, et = class {
1034
+ getArweaveClient() {
1035
+ return new e(C.getEndpoint());
1036
+ }
1037
+ async getTransactionStatus(e) {
1038
+ return Qe(e);
1039
+ }
1040
+ async getTransactionData(e, t) {
1041
+ let n = t?.decode === !1 ? [] : q();
1042
+ for (let r of n) {
1043
+ let n = await X(r, e);
1044
+ if (n) try {
1045
+ return t?.string ? await n.text() : new Uint8Array(await n.arrayBuffer());
1046
+ } catch (e) {
1047
+ Z("Error reading preferred gateway response:", e);
1048
+ }
1049
+ }
1050
+ if (C.getGatewayPath()) {
1051
+ let n = await fetch(C.getRawUrl(e));
1052
+ if (!n.ok) throw Error(`Failed to fetch transaction data: HTTP ${n.status}`);
1053
+ return t?.string ? n.text() : new Uint8Array(await n.arrayBuffer());
1054
+ }
1055
+ let r = await $();
1056
+ try {
1057
+ let n = await r.transactions.getData(e, {
1058
+ decode: t?.decode ?? !0,
1059
+ string: t?.string ?? !1
1060
+ });
1061
+ return t?.string && typeof n == "string" || n instanceof Uint8Array ? n : typeof n == "string" ? new TextEncoder().encode(n) : n;
1062
+ } catch (e) {
1063
+ throw Z("Error fetching transaction data:", e), e;
1064
+ }
1065
+ }
1066
+ async getTransactionTags(e) {
1067
+ let t = this.getArweaveClient();
1068
+ try {
1069
+ let n = await t.request(me, { transactionId: e });
1070
+ return n.tags?.tags ? n.tags.tags.map((e) => ({
1071
+ name: e.name,
1072
+ value: e.value
1073
+ })) : [];
1074
+ } catch (e) {
1075
+ return Z("Error fetching transaction tags:", e), [];
1076
+ }
1077
+ }
1078
+ async createTransaction(e, t) {
1079
+ let n = await (await $()).createTransaction({ data: e });
1080
+ if (t?.tags) for (let e of t.tags) n.addTag(e.name, e.value);
1081
+ return n;
1082
+ }
1083
+ async downloadFiles(e) {
1084
+ let { transactionIds: t, excludedTransactions: n } = e, r = [], i = C.getBaseUrl();
1085
+ for (let e of t) if (!n?.has(e)) try {
1086
+ let t = `${i}/raw/${e}`, n = await fetch(t);
1087
+ if (!n.ok) {
1088
+ r.push({
1089
+ transactionId: e,
1090
+ success: !1,
1091
+ error: `HTTP ${n.status}: ${n.statusText}`
1092
+ });
1093
+ continue;
1094
+ }
1095
+ let a = new Uint8Array(await n.arrayBuffer()), o = n.headers.get("content-type") || void 0;
1096
+ r.push({
1097
+ transactionId: e,
1098
+ success: !0,
1099
+ contentType: o,
1100
+ data: a
1101
+ });
1102
+ } catch (t) {
1103
+ Z(`Error downloading transaction ${e}:`, t), r.push({
1104
+ transactionId: e,
1105
+ success: !1,
1106
+ error: t instanceof Error ? t.message : String(t)
1107
+ });
1108
+ }
1109
+ return r;
1110
+ }
1111
+ };
1112
+ //#endregion
1113
+ export { i as $, be as A, de as B, B as C, ve as D, M as E, he as F, f as G, ce as H, me as I, s as J, te as K, C as L, P as M, N, ye as O, A as P, r as Q, _ as R, we as S, V as T, m as U, p as V, se as W, a as X, n as Y, o as Z, W as _, We as a, Te as b, qe as c, q as d, u as et, K as f, ke as g, ze as h, Qe as i, l as it, D as j, j as k, Ge as l, Ve as m, Je as n, oe as nt, Ke as o, Ue as p, c as q, Ye as r, ae as rt, X as s, et as t, ie as tt, Y as u, Re as v, Ce as w, z as x, De as y, ue as z };
1027
1114
 
1028
- //# sourceMappingURL=transactionStatus-zdutyXNX.js.map
1115
+ //# sourceMappingURL=ArweaveClient-EKSAAcSl.js.map