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