@sage-protocol/sdk 0.1.25 → 0.2.0

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