@sage-protocol/sdk 0.1.25 → 0.2.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.
@@ -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.25",
23
+ version: "0.2.1",
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",
@@ -73,6 +73,7 @@ var require_package = __commonJS({
73
73
  build: "tsup --config tsup.config.ts",
74
74
  clean: "rm -rf dist",
75
75
  test: 'yarn build && node --test "tests/**/*.test.js"',
76
+ prepublishOnly: "npm run build",
76
77
  release: "yarn build && npm publish --workspace @sage-protocol/sdk"
77
78
  },
78
79
  dependencies: {
@@ -80,7 +81,6 @@ var require_package = __commonJS({
80
81
  "@whetstone-research/doppler-sdk": "^0.0.1-alpha.40",
81
82
  ai: "^3.2.3",
82
83
  axios: "^1.11.0",
83
- "content-hash": "^2.5.2",
84
84
  ethers: "^6.15.0",
85
85
  viem: "^2.33.2"
86
86
  },
@@ -3117,8 +3117,9 @@ var require_ipfs = __commonJS({
3117
3117
  async function uploadJson(payload, name = "metadata", options2 = {}) {
3118
3118
  const data = {
3119
3119
  name,
3120
- timestamp: Date.now(),
3121
- ...payload
3120
+ description: options2.description || `JSON: ${name}`,
3121
+ content: typeof payload === "string" ? payload : JSON.stringify(payload, null, 2),
3122
+ timestamp: Date.now()
3122
3123
  };
3123
3124
  const metadata = {
3124
3125
  name,
@@ -3129,6 +3130,7 @@ var require_ipfs = __commonJS({
3129
3130
  provider: options2.provider,
3130
3131
  warm: options2.warm,
3131
3132
  gateways: options2.gateways,
3133
+ pin: options2.pin,
3132
3134
  filename: `${name}.json`,
3133
3135
  metadata
3134
3136
  });
@@ -3655,7 +3657,13 @@ var require_validation = __commonJS({
3655
3657
  return { schema: null, schemaPath: null };
3656
3658
  }
3657
3659
  function detectVersion(manifest) {
3658
- return "3.0.0";
3660
+ const version = manifest?.version;
3661
+ if (typeof version === "string") {
3662
+ const trimmed = version.trim();
3663
+ if (trimmed === "3.0.0") return "3.0.0";
3664
+ return "2.0.0";
3665
+ }
3666
+ return "2.0.0";
3659
3667
  }
3660
3668
  function lintManifest(manifest, { enforceVersion = true, manifestPath = null } = {}) {
3661
3669
  if (!manifest || typeof manifest !== "object") {
@@ -5983,13 +5991,16 @@ var require_operations = __commonJS({
5983
5991
  proposalId,
5984
5992
  refresh = false,
5985
5993
  cache = null,
5986
- fromBlock = 0,
5994
+ fromBlock = null,
5995
+ // null means auto-detect from current block
5987
5996
  helperAddress = null,
5988
5997
  subgraphUrl = null,
5989
5998
  hints = {},
5990
5999
  chunkSizeBlocks = 1e4,
5991
6000
  lookBackBlocks = 2e3,
5992
- lookAheadBlocks = 2e3
6001
+ lookAheadBlocks = 2e3,
6002
+ maxBlockRange = 5e4
6003
+ // Default to 50k blocks to avoid RPC limits
5993
6004
  }) {
5994
6005
  if (!provider) throw new SageSDKError(CODES.INVALID_ARGS, "provider required");
5995
6006
  const govAddr = normaliseGovernor(governor);
@@ -6051,7 +6062,8 @@ var require_operations = __commonJS({
6051
6062
  metadata = null;
6052
6063
  }
6053
6064
  if (!metadata) {
6054
- let lower = fromBlock || 0;
6065
+ const currentBlock = await provider.getBlockNumber();
6066
+ let lower = fromBlock !== null ? fromBlock : Math.max(0, currentBlock - maxBlockRange);
6055
6067
  try {
6056
6068
  const govAbi = new Interface(ABI.Governor);
6057
6069
  const govC = new Contract(govAddr, govAbi, provider);
@@ -13554,32 +13566,156 @@ var require_git_storage_client = __commonJS({
13554
13566
  this._authCacheExpiry = 0;
13555
13567
  }
13556
13568
  // =========================================================================
13557
- // Library Management
13569
+ // Path Building Helpers
13558
13570
  // =========================================================================
13559
13571
  /**
13560
- * Create a new library
13572
+ * Build a library path based on tier
13573
+ * @private
13574
+ * @param {'dao'|'personal'|'cache'} tier - Library tier
13575
+ * @param {string} [subdao] - SubDAO address (required for DAO tier)
13576
+ * @param {string} libraryId - Library identifier
13577
+ * @param {string} [subpath] - Additional path segment
13578
+ * @returns {string}
13579
+ */
13580
+ _buildLibraryPath(tier, subdao, libraryId, subpath = "") {
13581
+ const encodedLibraryId = encodeURIComponent(libraryId);
13582
+ const suffix = subpath ? `/${subpath}` : "";
13583
+ switch (tier) {
13584
+ case "dao":
13585
+ if (!subdao) throw new Error("subdao required for DAO tier");
13586
+ return `/git/dao/${encodeURIComponent(subdao)}/${encodedLibraryId}${suffix}`;
13587
+ case "personal":
13588
+ return `/git/personal/${encodedLibraryId}${suffix}`;
13589
+ case "cache":
13590
+ return `/git/cache${suffix}`;
13591
+ default:
13592
+ throw new Error(`Unknown tier: ${tier}`);
13593
+ }
13594
+ }
13595
+ /**
13596
+ * Build path from context object
13597
+ * @private
13598
+ * @param {LibraryContext} ctx - Library context
13599
+ * @param {string} [subpath] - Additional path segment
13600
+ * @returns {string}
13601
+ */
13602
+ _buildPath(ctx, subpath = "") {
13603
+ return this._buildLibraryPath(ctx.tier, ctx.subdao, ctx.libraryId, subpath);
13604
+ }
13605
+ // =========================================================================
13606
+ // Library Management - DAO Libraries
13607
+ // =========================================================================
13608
+ /**
13609
+ * Create a new DAO library (requires governance authority)
13561
13610
  * @param {string} subdao - SubDAO address
13562
13611
  * @param {string} name - Library name
13563
13612
  * @param {Object} [options] - Creation options
13613
+ * @param {string} [options.libraryId] - Custom library ID (auto-generated from name if not provided)
13564
13614
  * @param {string} [options.description] - Library description
13565
13615
  * @param {'public'|'private'} [options.visibility='public'] - Library visibility
13566
13616
  * @returns {Promise<LibraryMetadata>}
13567
13617
  */
13568
- async createLibrary(subdao, name, options = {}) {
13569
- return this._post("/git/libraries", {
13570
- subdao,
13618
+ async createDAOLibrary(subdao, name, options = {}) {
13619
+ return this._post(`/git/dao/${encodeURIComponent(subdao)}/libraries`, {
13571
13620
  name,
13621
+ libraryId: options.libraryId,
13572
13622
  description: options.description,
13573
13623
  visibility: options.visibility || "public"
13574
13624
  }, { auth: true });
13575
13625
  }
13576
13626
  /**
13577
- * Get library metadata
13627
+ * List libraries for a SubDAO
13628
+ * @param {string} subdao - SubDAO address
13629
+ * @returns {Promise<{libraries: LibraryMetadata[], subdao: string}>}
13630
+ */
13631
+ async listDAOLibraries(subdao) {
13632
+ return this._get(`/git/dao/${encodeURIComponent(subdao)}/libraries`);
13633
+ }
13634
+ /**
13635
+ * Get DAO library metadata
13636
+ * @param {string} subdao - SubDAO address
13637
+ * @param {string} libraryId - Library identifier
13638
+ * @returns {Promise<LibraryMetadata>}
13639
+ */
13640
+ async getDAOLibrary(subdao, libraryId) {
13641
+ return this._get(this._buildLibraryPath("dao", subdao, libraryId));
13642
+ }
13643
+ /**
13644
+ * Delete a DAO library (requires admin or governance authority)
13645
+ * @param {string} subdao - SubDAO address
13646
+ * @param {string} libraryId - Library identifier
13647
+ * @returns {Promise<{deleted: boolean, libraryId: string}>}
13648
+ */
13649
+ async deleteDAOLibrary(subdao, libraryId) {
13650
+ return this._delete(this._buildLibraryPath("dao", subdao, libraryId), { auth: true });
13651
+ }
13652
+ // =========================================================================
13653
+ // Library Management - Personal Libraries
13654
+ // =========================================================================
13655
+ /**
13656
+ * Create a new personal library
13657
+ * @param {string} name - Library name
13658
+ * @param {Object} [options] - Creation options
13659
+ * @param {string} [options.libraryId] - Custom library ID (auto-generated from name if not provided)
13660
+ * @param {string} [options.description] - Library description
13661
+ * @param {'public'|'private'} [options.visibility='private'] - Library visibility
13662
+ * @returns {Promise<LibraryMetadata>}
13663
+ */
13664
+ async createPersonalLibrary(name, options = {}) {
13665
+ return this._post("/git/personal/libraries", {
13666
+ name,
13667
+ libraryId: options.libraryId,
13668
+ description: options.description,
13669
+ visibility: options.visibility || "private"
13670
+ }, { auth: true });
13671
+ }
13672
+ /**
13673
+ * List personal libraries for authenticated user
13674
+ * @returns {Promise<{libraries: LibraryMetadata[], owner: string}>}
13675
+ */
13676
+ async listPersonalLibraries() {
13677
+ return this._get("/git/personal/libraries", { auth: true });
13678
+ }
13679
+ /**
13680
+ * Get personal library metadata
13681
+ * @param {string} libraryId - Library identifier
13682
+ * @returns {Promise<LibraryMetadata>}
13683
+ */
13684
+ async getPersonalLibrary(libraryId) {
13685
+ return this._get(this._buildLibraryPath("personal", null, libraryId), { auth: true });
13686
+ }
13687
+ /**
13688
+ * Delete a personal library
13689
+ * @param {string} libraryId - Library identifier
13690
+ * @returns {Promise<{deleted: boolean, libraryId: string}>}
13691
+ */
13692
+ async deletePersonalLibrary(libraryId) {
13693
+ return this._delete(this._buildLibraryPath("personal", null, libraryId), { auth: true });
13694
+ }
13695
+ // =========================================================================
13696
+ // Library Management - Legacy/Generic (Backwards Compatibility)
13697
+ // =========================================================================
13698
+ /**
13699
+ * Create a new library (legacy - use createDAOLibrary or createPersonalLibrary)
13700
+ * @deprecated Use createDAOLibrary() or createPersonalLibrary() instead
13701
+ * @param {string} subdao - SubDAO address
13702
+ * @param {string} name - Library name
13703
+ * @param {Object} [options] - Creation options
13704
+ * @param {string} [options.description] - Library description
13705
+ * @param {'public'|'private'} [options.visibility='public'] - Library visibility
13706
+ * @returns {Promise<LibraryMetadata>}
13707
+ */
13708
+ async createLibrary(subdao, name, options = {}) {
13709
+ return this.createDAOLibrary(subdao, name, { ...options, libraryId: "default" });
13710
+ }
13711
+ /**
13712
+ * Get library metadata (legacy - use getDAOLibrary or getPersonalLibrary)
13713
+ * @deprecated Use getDAOLibrary() or getPersonalLibrary() instead
13578
13714
  * @param {string} subdao - SubDAO address
13579
13715
  * @returns {Promise<LibraryMetadata>}
13580
13716
  */
13581
13717
  async getLibrary(subdao) {
13582
- return this._get(`/git/libraries/${encodeURIComponent(subdao)}`);
13718
+ return this.getDAOLibrary(subdao, "default");
13583
13719
  }
13584
13720
  /**
13585
13721
  * List all libraries
@@ -13596,207 +13732,251 @@ var require_git_storage_client = __commonJS({
13596
13732
  return this._get(`/git/libraries${queryString ? "?" + queryString : ""}`);
13597
13733
  }
13598
13734
  /**
13599
- * Delete a library (admin only)
13735
+ * Delete a library (legacy - use deleteDAOLibrary or deletePersonalLibrary)
13736
+ * @deprecated Use deleteDAOLibrary() or deletePersonalLibrary() instead
13600
13737
  * @param {string} subdao - SubDAO address
13601
13738
  * @returns {Promise<{ok: boolean}>}
13602
13739
  */
13603
13740
  async deleteLibrary(subdao) {
13604
- return this._delete(`/git/libraries/${encodeURIComponent(subdao)}`, { auth: true });
13741
+ return this.deleteDAOLibrary(subdao, "default");
13605
13742
  }
13606
13743
  // =========================================================================
13607
13744
  // Git Object Operations
13608
13745
  // =========================================================================
13609
13746
  /**
13610
13747
  * Store git objects (batch)
13611
- * @param {string} subdao - SubDAO address
13748
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13612
13749
  * @param {GitObject[]} objects - Objects to store
13750
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13613
13751
  * @returns {Promise<{stored: number}>}
13614
13752
  */
13615
- async putObjects(subdao, objects) {
13616
- return this._post(`/git/${encodeURIComponent(subdao)}/objects`, { objects }, { auth: true });
13753
+ async putObjects(target, objects, libraryId = "default") {
13754
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, "objects") : this._buildPath(target, "objects");
13755
+ return this._post(path2, { objects }, { auth: true });
13617
13756
  }
13618
13757
  /**
13619
13758
  * Get a single git object
13620
- * @param {string} subdao - SubDAO address
13759
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13621
13760
  * @param {string} oid - Object ID
13761
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13622
13762
  * @returns {Promise<GitObject>}
13623
13763
  */
13624
- async getObject(subdao, oid) {
13625
- return this._get(`/git/${encodeURIComponent(subdao)}/objects/${oid}`);
13764
+ async getObject(target, oid, libraryId = "default") {
13765
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, `objects/${oid}`) : this._buildPath(target, `objects/${oid}`);
13766
+ return this._get(path2);
13626
13767
  }
13627
13768
  /**
13628
13769
  * Get multiple git objects
13629
- * @param {string} subdao - SubDAO address
13770
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13630
13771
  * @param {string[]} oids - Object IDs
13772
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13631
13773
  * @returns {Promise<{objects: GitObject[]}>}
13632
13774
  */
13633
- async getObjects(subdao, oids) {
13634
- return this._get(`/git/${encodeURIComponent(subdao)}/objects?oids=${oids.join(",")}`);
13775
+ async getObjects(target, oids, libraryId = "default") {
13776
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, `objects?oids=${oids.join(",")}`) : this._buildPath(target, `objects?oids=${oids.join(",")}`);
13777
+ return this._get(path2);
13635
13778
  }
13636
13779
  // =========================================================================
13637
13780
  // Reference Operations
13638
13781
  // =========================================================================
13639
13782
  /**
13640
13783
  * List all refs
13641
- * @param {string} subdao - SubDAO address
13784
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13785
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13642
13786
  * @returns {Promise<{refs: GitRef[]}>}
13643
13787
  */
13644
- async listRefs(subdao) {
13645
- return this._get(`/git/${encodeURIComponent(subdao)}/refs`);
13788
+ async listRefs(target, libraryId = "default") {
13789
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, "refs") : this._buildPath(target, "refs");
13790
+ return this._get(path2);
13646
13791
  }
13647
13792
  /**
13648
13793
  * Get a specific ref
13649
- * @param {string} subdao - SubDAO address
13794
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13650
13795
  * @param {string} refName - Reference name (e.g., 'refs/heads/main')
13796
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13651
13797
  * @returns {Promise<GitRef>}
13652
13798
  */
13653
- async getRef(subdao, refName) {
13654
- return this._get(`/git/${encodeURIComponent(subdao)}/refs/${encodeURIComponent(refName)}`);
13799
+ async getRef(target, refName, libraryId = "default") {
13800
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, `refs/${encodeURIComponent(refName)}`) : this._buildPath(target, `refs/${encodeURIComponent(refName)}`);
13801
+ return this._get(path2);
13655
13802
  }
13656
13803
  /**
13657
13804
  * Update a ref
13658
- * @param {string} subdao - SubDAO address
13805
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13659
13806
  * @param {string} refName - Reference name
13660
13807
  * @param {string} oid - New object ID
13661
13808
  * @param {Object} [options] - Update options
13662
13809
  * @param {string} [options.oldOid] - Expected current OID (for optimistic concurrency)
13810
+ * @param {string} [options.libraryId='default'] - Library ID (only used if target is string)
13663
13811
  * @returns {Promise<{ok: boolean}>}
13664
13812
  */
13665
- async updateRef(subdao, refName, oid, options = {}) {
13666
- return this._post(
13667
- `/git/${encodeURIComponent(subdao)}/refs/${encodeURIComponent(refName)}`,
13668
- { oid, oldOid: options.oldOid },
13669
- { auth: true }
13670
- );
13813
+ async updateRef(target, refName, oid, options = {}) {
13814
+ const libraryId = options.libraryId || "default";
13815
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, `refs/${encodeURIComponent(refName)}`) : this._buildPath(target, `refs/${encodeURIComponent(refName)}`);
13816
+ return this._post(path2, { oid, oldOid: options.oldOid }, { auth: true });
13671
13817
  }
13672
13818
  // =========================================================================
13673
13819
  // Sync Operations
13674
13820
  // =========================================================================
13675
13821
  /**
13676
13822
  * Push changes to library
13677
- * @param {string} subdao - SubDAO address
13823
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13678
13824
  * @param {Object} payload - Push payload
13679
13825
  * @param {GitObject[]} payload.objects - Objects to push
13680
13826
  * @param {Record<string, string>} payload.refs - Ref updates (name -> oid)
13681
13827
  * @param {string} payload.message - Commit message
13828
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13682
13829
  * @returns {Promise<PushResult>}
13683
13830
  */
13684
- async push(subdao, payload) {
13685
- return this._post(`/git/${encodeURIComponent(subdao)}/push`, payload, { auth: true });
13831
+ async push(target, payload, libraryId = "default") {
13832
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, "push") : this._buildPath(target, "push");
13833
+ return this._post(path2, payload, { auth: true });
13686
13834
  }
13687
13835
  /**
13688
13836
  * Clone a library (get all objects and refs)
13689
- * @param {string} subdao - SubDAO address
13837
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13838
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13690
13839
  * @returns {Promise<{objects: GitObject[], refs: Record<string, string>, metadata: LibraryMetadata}>}
13691
13840
  */
13692
- async clone(subdao) {
13693
- return this._get(`/git/${encodeURIComponent(subdao)}/clone`);
13841
+ async clone(target, libraryId = "default") {
13842
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, "clone") : this._buildPath(target, "clone");
13843
+ return this._get(path2);
13694
13844
  }
13695
13845
  /**
13696
13846
  * Fetch changes since a commit
13697
- * @param {string} subdao - SubDAO address
13847
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13698
13848
  * @param {string} [since] - Commit OID to fetch since
13849
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13699
13850
  * @returns {Promise<{objects: GitObject[], refs: Record<string, string>}>}
13700
13851
  */
13701
- async fetch(subdao, since) {
13852
+ async fetch(target, since, libraryId = "default") {
13702
13853
  const params = since ? `?since=${since}` : "";
13703
- return this._get(`/git/${encodeURIComponent(subdao)}/fetch${params}`);
13854
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, `fetch${params}`) : this._buildPath(target, `fetch${params}`);
13855
+ return this._get(path2);
13704
13856
  }
13705
13857
  // =========================================================================
13706
13858
  // File Access
13707
13859
  // =========================================================================
13708
13860
  /**
13709
13861
  * Get commit history
13710
- * @param {string} subdao - SubDAO address
13862
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13711
13863
  * @param {Object} [options] - History options
13712
13864
  * @param {string} [options.ref='refs/heads/main'] - Reference to get history from
13713
13865
  * @param {number} [options.limit=50] - Max commits to return
13866
+ * @param {string} [options.libraryId='default'] - Library ID (only used if target is string)
13714
13867
  * @returns {Promise<{commits: GitCommit[]}>}
13715
13868
  */
13716
- async getHistory(subdao, options = {}) {
13869
+ async getHistory(target, options = {}) {
13717
13870
  const params = new URLSearchParams();
13718
13871
  if (options.ref) params.set("ref", options.ref);
13719
13872
  if (options.limit !== void 0) params.set("limit", String(options.limit));
13720
- return this._get(`/git/${encodeURIComponent(subdao)}/log?${params}`);
13873
+ const libraryId = options.libraryId || "default";
13874
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, `log?${params}`) : this._buildPath(target, `log?${params}`);
13875
+ return this._get(path2);
13721
13876
  }
13722
13877
  /**
13723
13878
  * Get directory listing
13724
- * @param {string} subdao - SubDAO address
13879
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13725
13880
  * @param {string} ref - Reference (e.g., 'main')
13726
- * @param {string} path - Directory path
13881
+ * @param {string} filePath - Directory path
13882
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13727
13883
  * @returns {Promise<{entries: Array}>}
13728
13884
  */
13729
- async getTree(subdao, ref, path2) {
13730
- return this._get(
13731
- `/git/${encodeURIComponent(subdao)}/tree/${encodeURIComponent(ref)}/${encodeURIComponent(path2)}`
13732
- );
13885
+ async getTree(target, ref, filePath, libraryId = "default") {
13886
+ const subpath = `tree/${encodeURIComponent(ref)}/${encodeURIComponent(filePath)}`;
13887
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, subpath) : this._buildPath(target, subpath);
13888
+ return this._get(path2);
13733
13889
  }
13734
13890
  /**
13735
13891
  * Get file contents
13736
- * @param {string} subdao - SubDAO address
13892
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13737
13893
  * @param {string} ref - Reference (e.g., 'main')
13738
- * @param {string} path - File path
13894
+ * @param {string} filePath - File path
13895
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13739
13896
  * @returns {Promise<{content: string}>}
13740
13897
  */
13741
- async getBlob(subdao, ref, path2) {
13742
- return this._get(
13743
- `/git/${encodeURIComponent(subdao)}/blob/${encodeURIComponent(ref)}/${encodeURIComponent(path2)}`
13744
- );
13898
+ async getBlob(target, ref, filePath, libraryId = "default") {
13899
+ const subpath = `blob/${encodeURIComponent(ref)}/${encodeURIComponent(filePath)}`;
13900
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, subpath) : this._buildPath(target, subpath);
13901
+ return this._get(path2);
13745
13902
  }
13746
13903
  /**
13747
13904
  * Get file contents as string (convenience method)
13748
- * @param {string} subdao - SubDAO address
13905
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13749
13906
  * @param {string} ref - Reference (e.g., 'main')
13750
- * @param {string} path - File path
13907
+ * @param {string} filePath - File path
13908
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13751
13909
  * @returns {Promise<string>}
13752
13910
  */
13753
- async getFile(subdao, ref, path2) {
13754
- const result = await this.getBlob(subdao, ref, path2);
13911
+ async getFile(target, ref, filePath, libraryId = "default") {
13912
+ const result = await this.getBlob(target, ref, filePath, libraryId);
13755
13913
  return result.content;
13756
13914
  }
13757
13915
  // =========================================================================
13758
13916
  // Fork Operations
13759
13917
  // =========================================================================
13760
13918
  /**
13761
- * Fork a library to a new SubDAO
13919
+ * Fork a DAO library to a new SubDAO
13762
13920
  * @param {string} sourceSubdao - Source SubDAO address to fork from
13921
+ * @param {string} sourceLibraryId - Source library ID
13763
13922
  * @param {string} targetSubdao - Target SubDAO address for the fork
13764
13923
  * @param {Object} [options] - Fork options
13924
+ * @param {string} [options.targetLibraryId] - Library ID for the fork
13765
13925
  * @param {string} [options.targetName] - Name for the forked library
13766
13926
  * @param {string} [options.targetDescription] - Description for the forked library
13767
13927
  * @returns {Promise<{ok: boolean, forkedLibrary: string, sourceLibrary: string, commitsCopied: number}>}
13768
13928
  */
13769
- async fork(sourceSubdao, targetSubdao, options = {}) {
13770
- return this._post(`/git/libraries/${encodeURIComponent(sourceSubdao)}/fork`, {
13929
+ async forkDAOLibrary(sourceSubdao, sourceLibraryId, targetSubdao, options = {}) {
13930
+ const path2 = this._buildLibraryPath("dao", sourceSubdao, sourceLibraryId, "fork");
13931
+ return this._post(path2, {
13771
13932
  targetSubdao,
13933
+ targetLibraryId: options.targetLibraryId,
13772
13934
  targetName: options.targetName,
13773
13935
  targetDescription: options.targetDescription
13774
13936
  }, { auth: true });
13775
13937
  }
13938
+ /**
13939
+ * Fork a library (legacy - uses 'default' libraryId)
13940
+ * @deprecated Use forkDAOLibrary() instead
13941
+ * @param {string} sourceSubdao - Source SubDAO address to fork from
13942
+ * @param {string} targetSubdao - Target SubDAO address for the fork
13943
+ * @param {Object} [options] - Fork options
13944
+ * @param {string} [options.targetName] - Name for the forked library
13945
+ * @param {string} [options.targetDescription] - Description for the forked library
13946
+ * @returns {Promise<{ok: boolean, forkedLibrary: string, sourceLibrary: string, commitsCopied: number}>}
13947
+ */
13948
+ async fork(sourceSubdao, targetSubdao, options = {}) {
13949
+ return this.forkDAOLibrary(sourceSubdao, "default", targetSubdao, options);
13950
+ }
13776
13951
  /**
13777
13952
  * List forks of a library
13778
- * @param {string} subdao - SubDAO address
13953
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13954
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13779
13955
  * @returns {Promise<{forks: Array, count: number}>}
13780
13956
  */
13781
- async getForks(subdao) {
13782
- return this._get(`/git/libraries/${encodeURIComponent(subdao)}/forks`);
13957
+ async getForks(target, libraryId = "default") {
13958
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, "forks") : this._buildPath(target, "forks");
13959
+ return this._get(path2);
13783
13960
  }
13784
13961
  /**
13785
13962
  * Get upstream fork info (for forked libraries)
13786
- * @param {string} subdao - SubDAO address
13963
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13964
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13787
13965
  * @returns {Promise<{upstreamSubdao: string, upstreamCommit: string, forkedAt: number}>}
13788
13966
  */
13789
- async getUpstream(subdao) {
13790
- return this._get(`/git/${encodeURIComponent(subdao)}/upstream`);
13967
+ async getUpstream(target, libraryId = "default") {
13968
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, "upstream") : this._buildPath(target, "upstream");
13969
+ return this._get(path2);
13791
13970
  }
13792
13971
  /**
13793
13972
  * Check if a library is a fork
13794
- * @param {string} subdao - SubDAO address
13973
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13974
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13795
13975
  * @returns {Promise<boolean>}
13796
13976
  */
13797
- async isFork(subdao) {
13977
+ async isFork(target, libraryId = "default") {
13798
13978
  try {
13799
- await this.getUpstream(subdao);
13979
+ await this.getUpstream(target, libraryId);
13800
13980
  return true;
13801
13981
  } catch (e) {
13802
13982
  if (e.message && e.message.includes("404")) {
@@ -13810,59 +13990,62 @@ var require_git_storage_client = __commonJS({
13810
13990
  // =========================================================================
13811
13991
  /**
13812
13992
  * List collaborators
13813
- * @param {string} subdao - SubDAO address
13993
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13994
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13814
13995
  * @returns {Promise<{collaborators: Collaborator[]}>}
13815
13996
  */
13816
- async listCollaborators(subdao) {
13817
- return this._get(`/git/${encodeURIComponent(subdao)}/collaborators`);
13997
+ async listCollaborators(target, libraryId = "default") {
13998
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, "collaborators") : this._buildPath(target, "collaborators");
13999
+ return this._get(path2);
13818
14000
  }
13819
14001
  /**
13820
14002
  * Add a collaborator
13821
- * @param {string} subdao - SubDAO address
14003
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13822
14004
  * @param {string} address - Collaborator wallet address
13823
14005
  * @param {'read'|'write'|'admin'} permission - Permission level
14006
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13824
14007
  * @returns {Promise<{ok: boolean}>}
13825
14008
  */
13826
- async addCollaborator(subdao, address, permission) {
13827
- return this._post(`/git/${encodeURIComponent(subdao)}/collaborators`, {
13828
- address,
13829
- permission
13830
- }, { auth: true });
14009
+ async addCollaborator(target, address, permission, libraryId = "default") {
14010
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, "collaborators") : this._buildPath(target, "collaborators");
14011
+ return this._post(path2, { address, permission }, { auth: true });
13831
14012
  }
13832
14013
  /**
13833
14014
  * Remove a collaborator
13834
- * @param {string} subdao - SubDAO address
14015
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13835
14016
  * @param {string} address - Collaborator wallet address
14017
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13836
14018
  * @returns {Promise<{ok: boolean}>}
13837
14019
  */
13838
- async removeCollaborator(subdao, address) {
13839
- return this._delete(
13840
- `/git/${encodeURIComponent(subdao)}/collaborators/${encodeURIComponent(address)}`,
13841
- { auth: true }
13842
- );
14020
+ async removeCollaborator(target, address, libraryId = "default") {
14021
+ const subpath = `collaborators/${encodeURIComponent(address)}`;
14022
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, subpath) : this._buildPath(target, subpath);
14023
+ return this._delete(path2, { auth: true });
13843
14024
  }
13844
14025
  /**
13845
14026
  * Check permissions for an address
13846
- * @param {string} subdao - SubDAO address
14027
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13847
14028
  * @param {string} address - Wallet address to check
14029
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13848
14030
  * @returns {Promise<{canRead: boolean, canWrite: boolean, isAdmin: boolean, permission?: string}>}
13849
14031
  */
13850
- async getPermissions(subdao, address) {
13851
- return this._get(
13852
- `/git/${encodeURIComponent(subdao)}/collaborators/${encodeURIComponent(address)}/permissions`
13853
- );
14032
+ async getPermissions(target, address, libraryId = "default") {
14033
+ const subpath = `collaborators/${encodeURIComponent(address)}/permissions`;
14034
+ const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, subpath) : this._buildPath(target, subpath);
14035
+ return this._get(path2);
13854
14036
  }
13855
14037
  // =========================================================================
13856
14038
  // High-Level Convenience Methods
13857
14039
  // =========================================================================
13858
14040
  /**
13859
14041
  * Push a manifest file (convenience method)
13860
- * @param {string} subdao - SubDAO address
14042
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13861
14043
  * @param {Object} manifest - Manifest object to push
13862
14044
  * @param {string} message - Commit message
14045
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13863
14046
  * @returns {Promise<PushResult>}
13864
14047
  */
13865
- async pushManifest(subdao, manifest, message) {
14048
+ async pushManifest(target, manifest, message, libraryId = "default") {
13866
14049
  const content = JSON.stringify(manifest, null, 2);
13867
14050
  const oid = await this._computeOid(content);
13868
14051
  const objects = [{
@@ -13881,7 +14064,7 @@ var require_git_storage_client = __commonJS({
13881
14064
  });
13882
14065
  let parentOid = null;
13883
14066
  try {
13884
- const currentRef = await this.getRef(subdao, "refs/heads/main");
14067
+ const currentRef = await this.getRef(target, "refs/heads/main", libraryId);
13885
14068
  parentOid = currentRef.oid;
13886
14069
  } catch (e) {
13887
14070
  }
@@ -13900,20 +14083,21 @@ var require_git_storage_client = __commonJS({
13900
14083
  size: commitContent.length,
13901
14084
  data: this._toBase64(commitContent)
13902
14085
  });
13903
- return this.push(subdao, {
14086
+ return this.push(target, {
13904
14087
  objects,
13905
14088
  refs: { "refs/heads/main": commitOid },
13906
14089
  message
13907
- });
14090
+ }, libraryId);
13908
14091
  }
13909
14092
  /**
13910
14093
  * Get manifest from library (convenience method)
13911
- * @param {string} subdao - SubDAO address
14094
+ * @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
13912
14095
  * @param {string} [ref='main'] - Reference to get manifest from
14096
+ * @param {string} [libraryId='default'] - Library ID (only used if target is string)
13913
14097
  * @returns {Promise<Object>}
13914
14098
  */
13915
- async getManifest(subdao, ref = "main") {
13916
- const content = await this.getFile(subdao, ref, "manifest.json");
14099
+ async getManifest(target, ref = "main", libraryId = "default") {
14100
+ const content = await this.getFile(target, ref, "manifest.json", libraryId);
13917
14101
  return JSON.parse(content);
13918
14102
  }
13919
14103
  // =========================================================================