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