@sage-protocol/sdk 0.1.8 → 0.1.9

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.
@@ -14,7 +14,7 @@ var require_package = __commonJS({
14
14
  "package.json"(exports, module) {
15
15
  module.exports = {
16
16
  name: "@sage-protocol/sdk",
17
- version: "0.1.7",
17
+ version: "0.1.8",
18
18
  description: "Backend-agnostic SDK for interacting with the Sage Protocol (governance, SubDAOs, tokens).",
19
19
  main: "dist/index.cjs",
20
20
  module: "dist/index.mjs",
@@ -377,15 +377,31 @@ var require_utils = __commonJS({
377
377
  // src/browser/subgraph.js
378
378
  var require_subgraph = __commonJS({
379
379
  "src/browser/subgraph.js"(exports, module) {
380
- var axios = __require("axios");
381
380
  var { getAddress } = require_utils();
382
381
  async function query(url, document, variables) {
383
382
  if (!url) throw new Error("subgraph url required");
384
- const resp = await axios.post(url, { query: document, variables }, { timeout: 1e4 });
385
- if (resp.data && resp.data.errors) {
386
- throw new Error(resp.data.errors.map((e) => e.message).join("; "));
383
+ const controller = new AbortController();
384
+ const timeoutId = setTimeout(() => controller.abort(), 1e4);
385
+ try {
386
+ const resp = await fetch(url, {
387
+ method: "POST",
388
+ headers: { "Content-Type": "application/json" },
389
+ body: JSON.stringify({ query: document, variables }),
390
+ signal: controller.signal
391
+ });
392
+ clearTimeout(timeoutId);
393
+ if (!resp.ok) {
394
+ throw new Error(`HTTP ${resp.status}: ${resp.statusText}`);
395
+ }
396
+ const data = await resp.json();
397
+ if (data && data.errors) {
398
+ throw new Error(data.errors.map((e) => e.message).join("; "));
399
+ }
400
+ return data.data;
401
+ } catch (error) {
402
+ clearTimeout(timeoutId);
403
+ throw error;
387
404
  }
388
- return resp.data.data;
389
405
  }
390
406
  async function listProposals({ url, governor, first = 20, skip = 0 }) {
391
407
  const data = await query(url, `
@@ -723,9 +739,69 @@ var require_subgraph = __commonJS({
723
739
  // src/browser/ipfs.js
724
740
  var require_ipfs = __commonJS({
725
741
  "src/browser/ipfs.js"(exports, module) {
726
- var axiosDefault = __require("axios");
727
- var FormData = __require("form-data");
728
742
  var { keccak256Sync } = require_utils();
743
+ var browserHttp = {
744
+ async post(url, data, options = {}) {
745
+ const controller = new AbortController();
746
+ const timeout = options.timeout || 15e3;
747
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
748
+ try {
749
+ const response = await fetch(url, {
750
+ method: "POST",
751
+ headers: { "Content-Type": "application/json", ...options.headers },
752
+ body: JSON.stringify(data),
753
+ signal: controller.signal
754
+ });
755
+ clearTimeout(timeoutId);
756
+ if (!response.ok) {
757
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
758
+ }
759
+ return { data: await response.json() };
760
+ } catch (error) {
761
+ clearTimeout(timeoutId);
762
+ throw error;
763
+ }
764
+ },
765
+ async get(url, options = {}) {
766
+ const controller = new AbortController();
767
+ const timeout = options.timeout || 15e3;
768
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
769
+ try {
770
+ const params = options.params || {};
771
+ const queryString = Object.keys(params).length ? "?" + new URLSearchParams(params).toString() : "";
772
+ const response = await fetch(url + queryString, {
773
+ method: "GET",
774
+ headers: options.headers || {},
775
+ signal: controller.signal
776
+ });
777
+ clearTimeout(timeoutId);
778
+ if (!response.ok) {
779
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
780
+ }
781
+ return { data: await response.json() };
782
+ } catch (error) {
783
+ clearTimeout(timeoutId);
784
+ throw error;
785
+ }
786
+ },
787
+ async head(url, options = {}) {
788
+ const controller = new AbortController();
789
+ const timeout = options.timeout || 15e3;
790
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
791
+ try {
792
+ const response = await fetch(url, {
793
+ method: "HEAD",
794
+ headers: options.headers || {},
795
+ signal: controller.signal
796
+ });
797
+ clearTimeout(timeoutId);
798
+ return { status: response.status, ok: response.ok };
799
+ } catch (error) {
800
+ clearTimeout(timeoutId);
801
+ throw error;
802
+ }
803
+ }
804
+ };
729
805
  var DEFAULT_GATEWAY = "https://ipfs.dev.sageprotocol.io/ipfs";
730
806
  function toLowerSafe(value, fallback = "") {
731
807
  if (value == null) return fallback;
@@ -794,8 +870,8 @@ var require_ipfs = __commonJS({
794
870
  }
795
871
  function createClient(options = {}) {
796
872
  const env = options.env || process?.env || {};
797
- const axiosInstance = options.axiosInstance || options.axios || axiosDefault;
798
- const formDataFactory = options.formDataFactory || (() => new FormData());
873
+ const axiosInstance = options.axiosInstance || options.axios || browserHttp;
874
+ const formDataFactory = options.formDataFactory || null;
799
875
  const generateCid = options.generateCid || generateDeterministicCid;
800
876
  const config = {
801
877
  provider: toLowerSafe(options.provider ?? env.SAGE_IPFS_PROVIDER ?? "auto"),
@@ -1276,7 +1352,7 @@ var require_ipfs = __commonJS({
1276
1352
  }
1277
1353
  async function ensureWorkerAccess(options = {}) {
1278
1354
  const env = options.env || process?.env || {};
1279
- const axiosInstance = options.axiosInstance || axiosDefault;
1355
+ const axiosInstance = options.axiosInstance || browserHttp;
1280
1356
  const signer = options.signer;
1281
1357
  if (!signer) throw new Error("worker_signer_required");
1282
1358
  const baseUrl = removeTrailingSlash(options.workerBaseUrl || env.SAGE_IPFS_WORKER_URL || "");
package/dist/index.cjs CHANGED
@@ -14,7 +14,7 @@ var require_package = __commonJS({
14
14
  "package.json"(exports2, module2) {
15
15
  module2.exports = {
16
16
  name: "@sage-protocol/sdk",
17
- version: "0.1.7",
17
+ version: "0.1.8",
18
18
  description: "Backend-agnostic SDK for interacting with the Sage Protocol (governance, SubDAOs, tokens).",
19
19
  main: "dist/index.cjs",
20
20
  module: "dist/index.mjs",
package/dist/index.mjs CHANGED
@@ -20,7 +20,7 @@ var require_package = __commonJS({
20
20
  "package.json"(exports2, module2) {
21
21
  module2.exports = {
22
22
  name: "@sage-protocol/sdk",
23
- version: "0.1.7",
23
+ version: "0.1.8",
24
24
  description: "Backend-agnostic SDK for interacting with the Sage Protocol (governance, SubDAOs, tokens).",
25
25
  main: "dist/index.cjs",
26
26
  module: "dist/index.mjs",
@@ -14,7 +14,7 @@ var require_package = __commonJS({
14
14
  "package.json"(exports2, module2) {
15
15
  module2.exports = {
16
16
  name: "@sage-protocol/sdk",
17
- version: "0.1.7",
17
+ version: "0.1.8",
18
18
  description: "Backend-agnostic SDK for interacting with the Sage Protocol (governance, SubDAOs, tokens).",
19
19
  main: "dist/index.cjs",
20
20
  module: "dist/index.mjs",
@@ -20,7 +20,7 @@ var require_package = __commonJS({
20
20
  "package.json"(exports2, module2) {
21
21
  module2.exports = {
22
22
  name: "@sage-protocol/sdk",
23
- version: "0.1.7",
23
+ version: "0.1.8",
24
24
  description: "Backend-agnostic SDK for interacting with the Sage Protocol (governance, SubDAOs, tokens).",
25
25
  main: "dist/index.cjs",
26
26
  module: "dist/index.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sage-protocol/sdk",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Backend-agnostic SDK for interacting with the Sage Protocol (governance, SubDAOs, tokens).",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",