@sage-protocol/sdk 0.1.24 → 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/README.md +1 -1
- package/dist/browser/index.mjs +2 -1
- package/dist/index.cjs +622 -106
- package/dist/index.mjs +622 -106
- package/dist/node/index.cjs +622 -106
- package/dist/node/index.mjs +622 -106
- package/package.json +2 -1
package/dist/node/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.
|
|
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
|
-
|
|
3121
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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);
|
|
@@ -9795,6 +9808,335 @@ var require_contributions = __commonJS({
|
|
|
9795
9808
|
}
|
|
9796
9809
|
});
|
|
9797
9810
|
|
|
9811
|
+
// src/browser/reputation.js
|
|
9812
|
+
var require_reputation = __commonJS({
|
|
9813
|
+
"src/browser/reputation.js"(exports2, module2) {
|
|
9814
|
+
var { getAddress } = require_utils();
|
|
9815
|
+
var subgraph = require_subgraph2();
|
|
9816
|
+
function safeGetAddress(value) {
|
|
9817
|
+
try {
|
|
9818
|
+
return getAddress(value);
|
|
9819
|
+
} catch {
|
|
9820
|
+
return null;
|
|
9821
|
+
}
|
|
9822
|
+
}
|
|
9823
|
+
function clampInt(value, { min = 1, max = 100, fallback = 100 } = {}) {
|
|
9824
|
+
const n = Number(value);
|
|
9825
|
+
if (!Number.isFinite(n)) return fallback;
|
|
9826
|
+
return Math.min(max, Math.max(min, Math.trunc(n)));
|
|
9827
|
+
}
|
|
9828
|
+
function toBigIntString(value, fallback = "0") {
|
|
9829
|
+
try {
|
|
9830
|
+
if (typeof value === "bigint") return value.toString();
|
|
9831
|
+
if (typeof value === "number") return String(Math.trunc(value));
|
|
9832
|
+
const str = String(value).trim();
|
|
9833
|
+
if (!str) return fallback;
|
|
9834
|
+
if (!/^-?\d+$/.test(str)) return fallback;
|
|
9835
|
+
return str;
|
|
9836
|
+
} catch {
|
|
9837
|
+
return fallback;
|
|
9838
|
+
}
|
|
9839
|
+
}
|
|
9840
|
+
function mapSafe(list, mapper) {
|
|
9841
|
+
const out = [];
|
|
9842
|
+
for (const item of list || []) {
|
|
9843
|
+
try {
|
|
9844
|
+
const v = mapper(item);
|
|
9845
|
+
if (v != null) out.push(v);
|
|
9846
|
+
} catch {
|
|
9847
|
+
}
|
|
9848
|
+
}
|
|
9849
|
+
return out;
|
|
9850
|
+
}
|
|
9851
|
+
async function getBadgesByRecipient({ url, recipient, first = 50 }) {
|
|
9852
|
+
if (!url) throw new Error("subgraph url required");
|
|
9853
|
+
if (!recipient) throw new Error("recipient required");
|
|
9854
|
+
const addr = safeGetAddress(recipient);
|
|
9855
|
+
if (!addr) throw new Error("invalid recipient address");
|
|
9856
|
+
const doc = `
|
|
9857
|
+
query($recipient: Bytes!, $first: Int!) {
|
|
9858
|
+
soulboundBadges(
|
|
9859
|
+
where: { recipient: $recipient }
|
|
9860
|
+
first: $first
|
|
9861
|
+
orderBy: blockTimestamp
|
|
9862
|
+
orderDirection: desc
|
|
9863
|
+
) {
|
|
9864
|
+
id
|
|
9865
|
+
contract
|
|
9866
|
+
badgeId
|
|
9867
|
+
recipient
|
|
9868
|
+
evidenceURI
|
|
9869
|
+
blockNumber
|
|
9870
|
+
blockTimestamp
|
|
9871
|
+
transactionHash
|
|
9872
|
+
}
|
|
9873
|
+
}
|
|
9874
|
+
`;
|
|
9875
|
+
const data = await subgraph.query(url, doc, {
|
|
9876
|
+
recipient: addr.toLowerCase(),
|
|
9877
|
+
first: clampInt(first, { min: 1, max: 100, fallback: 50 })
|
|
9878
|
+
});
|
|
9879
|
+
return mapSafe(data?.soulboundBadges, (row) => {
|
|
9880
|
+
const contract = safeGetAddress(row.contract);
|
|
9881
|
+
const recipientAddr = safeGetAddress(row.recipient);
|
|
9882
|
+
if (!contract || !recipientAddr) return null;
|
|
9883
|
+
return {
|
|
9884
|
+
id: String(row.id),
|
|
9885
|
+
contract,
|
|
9886
|
+
badgeId: toBigIntString(row.badgeId, "0"),
|
|
9887
|
+
recipient: recipientAddr,
|
|
9888
|
+
evidenceURI: row.evidenceURI || null,
|
|
9889
|
+
blockNumber: Number(row.blockNumber || 0),
|
|
9890
|
+
blockTimestamp: Number(row.blockTimestamp || 0),
|
|
9891
|
+
transactionHash: row.transactionHash || null
|
|
9892
|
+
};
|
|
9893
|
+
});
|
|
9894
|
+
}
|
|
9895
|
+
async function listContributions({ url, contributor, subdao, first = 50, orderBy = "updatedAt", orderDirection = "desc" }) {
|
|
9896
|
+
if (!url) throw new Error("subgraph url required");
|
|
9897
|
+
const filters = [];
|
|
9898
|
+
if (contributor) {
|
|
9899
|
+
const addr = safeGetAddress(contributor);
|
|
9900
|
+
if (!addr) throw new Error("invalid contributor address");
|
|
9901
|
+
filters.push(`contributor: "${addr.toLowerCase()}"`);
|
|
9902
|
+
}
|
|
9903
|
+
if (subdao) {
|
|
9904
|
+
const addr = safeGetAddress(subdao);
|
|
9905
|
+
if (!addr) throw new Error("invalid subdao address");
|
|
9906
|
+
filters.push(`dao: "${addr.toLowerCase()}"`);
|
|
9907
|
+
}
|
|
9908
|
+
const where = filters.length ? `where: { ${filters.join(", ")} }` : "";
|
|
9909
|
+
const safeOrderBy = ["updatedAt", "createdAt"].includes(orderBy) ? orderBy : "updatedAt";
|
|
9910
|
+
const safeOrderDirection = orderDirection === "asc" ? "asc" : "desc";
|
|
9911
|
+
const doc = `
|
|
9912
|
+
query($first: Int!) {
|
|
9913
|
+
promptContributions(
|
|
9914
|
+
${where}
|
|
9915
|
+
first: $first
|
|
9916
|
+
orderBy: ${safeOrderBy}
|
|
9917
|
+
orderDirection: ${safeOrderDirection}
|
|
9918
|
+
) {
|
|
9919
|
+
id
|
|
9920
|
+
dao
|
|
9921
|
+
promptKey
|
|
9922
|
+
contributor
|
|
9923
|
+
cid
|
|
9924
|
+
proposalId
|
|
9925
|
+
forVotes
|
|
9926
|
+
againstVotes
|
|
9927
|
+
abstainVotes
|
|
9928
|
+
uniqueVoters
|
|
9929
|
+
quorum
|
|
9930
|
+
fromBounty
|
|
9931
|
+
bountyId
|
|
9932
|
+
badgeId
|
|
9933
|
+
badgeEvidenceURI
|
|
9934
|
+
createdAt
|
|
9935
|
+
updatedAt
|
|
9936
|
+
transactionHash
|
|
9937
|
+
}
|
|
9938
|
+
}
|
|
9939
|
+
`;
|
|
9940
|
+
const data = await subgraph.query(url, doc, {
|
|
9941
|
+
first: clampInt(first, { min: 1, max: 100, fallback: 50 })
|
|
9942
|
+
});
|
|
9943
|
+
return mapSafe(data?.promptContributions, (row) => {
|
|
9944
|
+
const dao = safeGetAddress(row.dao);
|
|
9945
|
+
const contributorAddr = safeGetAddress(row.contributor);
|
|
9946
|
+
if (!dao) return null;
|
|
9947
|
+
return {
|
|
9948
|
+
id: String(row.id),
|
|
9949
|
+
dao,
|
|
9950
|
+
promptKey: String(row.promptKey),
|
|
9951
|
+
contributor: contributorAddr || "0x0000000000000000000000000000000000000000",
|
|
9952
|
+
cid: String(row.cid),
|
|
9953
|
+
timestamp: Number(row.updatedAt || 0),
|
|
9954
|
+
createdAt: Number(row.createdAt || 0),
|
|
9955
|
+
updatedAt: Number(row.updatedAt || 0),
|
|
9956
|
+
transactionHash: row.transactionHash || null,
|
|
9957
|
+
proposalId: row.proposalId != null ? toBigIntString(row.proposalId) : null,
|
|
9958
|
+
forVotes: row.forVotes != null ? toBigIntString(row.forVotes) : null,
|
|
9959
|
+
againstVotes: row.againstVotes != null ? toBigIntString(row.againstVotes) : null,
|
|
9960
|
+
abstainVotes: row.abstainVotes != null ? toBigIntString(row.abstainVotes) : null,
|
|
9961
|
+
uniqueVoters: row.uniqueVoters != null ? Number(row.uniqueVoters) : null,
|
|
9962
|
+
quorum: row.quorum != null ? toBigIntString(row.quorum) : null,
|
|
9963
|
+
fromBounty: Boolean(row.fromBounty),
|
|
9964
|
+
bountyId: row.bountyId != null ? toBigIntString(row.bountyId) : null,
|
|
9965
|
+
badgeId: row.badgeId != null ? toBigIntString(row.badgeId) : null,
|
|
9966
|
+
badgeEvidenceURI: row.badgeEvidenceURI || null
|
|
9967
|
+
};
|
|
9968
|
+
});
|
|
9969
|
+
}
|
|
9970
|
+
function computeAggregates(contributions) {
|
|
9971
|
+
if (!contributions || contributions.length === 0) {
|
|
9972
|
+
return {
|
|
9973
|
+
totalContributions: 0,
|
|
9974
|
+
uniqueContributors: 0,
|
|
9975
|
+
bountyOriginated: 0,
|
|
9976
|
+
governanceOriginated: 0,
|
|
9977
|
+
totalForVotes: "0",
|
|
9978
|
+
totalAgainstVotes: "0",
|
|
9979
|
+
averageVoterCount: 0,
|
|
9980
|
+
badgeCount: 0
|
|
9981
|
+
};
|
|
9982
|
+
}
|
|
9983
|
+
const contributorSet = /* @__PURE__ */ new Set();
|
|
9984
|
+
let bountyOriginated = 0;
|
|
9985
|
+
let governanceOriginated = 0;
|
|
9986
|
+
let totalForVotes = 0n;
|
|
9987
|
+
let totalAgainstVotes = 0n;
|
|
9988
|
+
let voterCountSum = 0;
|
|
9989
|
+
let voterCountN = 0;
|
|
9990
|
+
let badgeCount = 0;
|
|
9991
|
+
for (const c of contributions) {
|
|
9992
|
+
if (c.contributor) contributorSet.add(c.contributor.toLowerCase());
|
|
9993
|
+
if (c.fromBounty) {
|
|
9994
|
+
bountyOriginated++;
|
|
9995
|
+
} else {
|
|
9996
|
+
governanceOriginated++;
|
|
9997
|
+
}
|
|
9998
|
+
if (c.forVotes != null) {
|
|
9999
|
+
try {
|
|
10000
|
+
totalForVotes += BigInt(c.forVotes);
|
|
10001
|
+
} catch {
|
|
10002
|
+
}
|
|
10003
|
+
}
|
|
10004
|
+
if (c.againstVotes != null) {
|
|
10005
|
+
try {
|
|
10006
|
+
totalAgainstVotes += BigInt(c.againstVotes);
|
|
10007
|
+
} catch {
|
|
10008
|
+
}
|
|
10009
|
+
}
|
|
10010
|
+
if (c.uniqueVoters != null) {
|
|
10011
|
+
voterCountSum += c.uniqueVoters;
|
|
10012
|
+
voterCountN++;
|
|
10013
|
+
}
|
|
10014
|
+
if (c.badgeId != null) badgeCount++;
|
|
10015
|
+
}
|
|
10016
|
+
return {
|
|
10017
|
+
totalContributions: contributions.length,
|
|
10018
|
+
uniqueContributors: contributorSet.size,
|
|
10019
|
+
bountyOriginated,
|
|
10020
|
+
governanceOriginated,
|
|
10021
|
+
totalForVotes: totalForVotes.toString(),
|
|
10022
|
+
totalAgainstVotes: totalAgainstVotes.toString(),
|
|
10023
|
+
averageVoterCount: voterCountN > 0 ? Math.round(voterCountSum / voterCountN) : 0,
|
|
10024
|
+
badgeCount
|
|
10025
|
+
};
|
|
10026
|
+
}
|
|
10027
|
+
async function getByAddress({
|
|
10028
|
+
url,
|
|
10029
|
+
address,
|
|
10030
|
+
subdao,
|
|
10031
|
+
includeBadges = true,
|
|
10032
|
+
includeContributions = true,
|
|
10033
|
+
first = 100
|
|
10034
|
+
} = {}) {
|
|
10035
|
+
if (!url) throw new Error("subgraph url required");
|
|
10036
|
+
if (!address) throw new Error("address required");
|
|
10037
|
+
const addr = safeGetAddress(address);
|
|
10038
|
+
if (!addr) throw new Error("invalid address");
|
|
10039
|
+
const subdaoAddr = subdao ? safeGetAddress(subdao) : null;
|
|
10040
|
+
if (subdao && !subdaoAddr) throw new Error("invalid subdao address");
|
|
10041
|
+
const limit = clampInt(first, { min: 1, max: 200, fallback: 100 });
|
|
10042
|
+
let badges = void 0;
|
|
10043
|
+
if (includeBadges) {
|
|
10044
|
+
badges = await getBadgesByRecipient({ url, recipient: addr, first: limit });
|
|
10045
|
+
}
|
|
10046
|
+
let contributionAggregates = void 0;
|
|
10047
|
+
let lastContributionAt = null;
|
|
10048
|
+
if (includeContributions) {
|
|
10049
|
+
const rows = await listContributions({
|
|
10050
|
+
url,
|
|
10051
|
+
contributor: addr,
|
|
10052
|
+
subdao: subdaoAddr || void 0,
|
|
10053
|
+
first: limit,
|
|
10054
|
+
orderBy: "updatedAt",
|
|
10055
|
+
orderDirection: "desc"
|
|
10056
|
+
});
|
|
10057
|
+
if (rows && rows.length) {
|
|
10058
|
+
const updatedAt = rows[0]?.updatedAt ?? rows[0]?.timestamp ?? null;
|
|
10059
|
+
lastContributionAt = updatedAt != null ? Number(updatedAt) : null;
|
|
10060
|
+
if (!Number.isFinite(lastContributionAt)) lastContributionAt = null;
|
|
10061
|
+
}
|
|
10062
|
+
contributionAggregates = computeAggregates(rows || []);
|
|
10063
|
+
}
|
|
10064
|
+
const signals = {
|
|
10065
|
+
badgeCount: includeBadges ? badges ? badges.length : 0 : null,
|
|
10066
|
+
totalContributions: includeContributions ? contributionAggregates ? contributionAggregates.totalContributions : 0 : null,
|
|
10067
|
+
governanceOriginated: includeContributions ? contributionAggregates ? contributionAggregates.governanceOriginated : 0 : null,
|
|
10068
|
+
bountyOriginated: includeContributions ? contributionAggregates ? contributionAggregates.bountyOriginated : 0 : null,
|
|
10069
|
+
lastContributionAt: includeContributions ? lastContributionAt : null
|
|
10070
|
+
};
|
|
10071
|
+
const out = {
|
|
10072
|
+
address: addr,
|
|
10073
|
+
subdao: subdaoAddr || null,
|
|
10074
|
+
signals
|
|
10075
|
+
};
|
|
10076
|
+
if (includeBadges) out.badges = badges;
|
|
10077
|
+
if (includeContributions) {
|
|
10078
|
+
out.contributionAggregates = contributionAggregates;
|
|
10079
|
+
out.lastContributionAt = lastContributionAt;
|
|
10080
|
+
}
|
|
10081
|
+
return out;
|
|
10082
|
+
}
|
|
10083
|
+
function normalizeGateInt(value, name) {
|
|
10084
|
+
if (value === void 0 || value === null) return null;
|
|
10085
|
+
const n = Number(value);
|
|
10086
|
+
if (!Number.isFinite(n) || n < 0) {
|
|
10087
|
+
throw new Error(`invalid gate: ${name}`);
|
|
10088
|
+
}
|
|
10089
|
+
return Math.trunc(n);
|
|
10090
|
+
}
|
|
10091
|
+
function normalizeRequiredBadgeIds(value) {
|
|
10092
|
+
const list = Array.isArray(value) ? value : value != null ? [value] : [];
|
|
10093
|
+
const out = [];
|
|
10094
|
+
for (const item of list) {
|
|
10095
|
+
const id2 = toBigIntString(item, "");
|
|
10096
|
+
if (id2) out.push(id2);
|
|
10097
|
+
}
|
|
10098
|
+
return out;
|
|
10099
|
+
}
|
|
10100
|
+
function evaluate(result, gates = {}) {
|
|
10101
|
+
const reasons = [];
|
|
10102
|
+
const minBadges = normalizeGateInt(gates.minBadges, "minBadges");
|
|
10103
|
+
const minContributions = normalizeGateInt(gates.minContributions, "minContributions");
|
|
10104
|
+
const requiredBadges = normalizeRequiredBadgeIds(gates.requireBadges ?? gates.requireBadge);
|
|
10105
|
+
const badgeCount = Number(result?.signals?.badgeCount ?? (result?.badges?.length ?? 0));
|
|
10106
|
+
const totalContributions = Number(result?.signals?.totalContributions ?? (result?.contributionAggregates?.totalContributions ?? 0));
|
|
10107
|
+
if (minBadges != null) {
|
|
10108
|
+
if (!Number.isFinite(badgeCount)) {
|
|
10109
|
+
reasons.push("badges_unavailable");
|
|
10110
|
+
} else if (badgeCount < minBadges) {
|
|
10111
|
+
reasons.push(`minBadges:${badgeCount}<${minBadges}`);
|
|
10112
|
+
}
|
|
10113
|
+
}
|
|
10114
|
+
if (minContributions != null) {
|
|
10115
|
+
if (!Number.isFinite(totalContributions)) {
|
|
10116
|
+
reasons.push("contributions_unavailable");
|
|
10117
|
+
} else if (totalContributions < minContributions) {
|
|
10118
|
+
reasons.push(`minContributions:${totalContributions}<${minContributions}`);
|
|
10119
|
+
}
|
|
10120
|
+
}
|
|
10121
|
+
if (requiredBadges.length) {
|
|
10122
|
+
const have = new Set((result?.badges || []).map((b) => toBigIntString(b?.badgeId, "")).filter(Boolean));
|
|
10123
|
+
for (const req2 of requiredBadges) {
|
|
10124
|
+
if (!have.has(req2)) reasons.push(`missingBadge:${req2}`);
|
|
10125
|
+
}
|
|
10126
|
+
}
|
|
10127
|
+
return { ok: reasons.length === 0, reasons };
|
|
10128
|
+
}
|
|
10129
|
+
module2.exports = {
|
|
10130
|
+
getByAddress,
|
|
10131
|
+
evaluate,
|
|
10132
|
+
// Expose lower-level functions for advanced usage
|
|
10133
|
+
getBadgesByRecipient,
|
|
10134
|
+
listContributions,
|
|
10135
|
+
computeAggregates
|
|
10136
|
+
};
|
|
10137
|
+
}
|
|
10138
|
+
});
|
|
10139
|
+
|
|
9798
10140
|
// src/votingMultiplier/index.js
|
|
9799
10141
|
var require_votingMultiplier = __commonJS({
|
|
9800
10142
|
"src/votingMultiplier/index.js"(exports2, module2) {
|
|
@@ -13225,32 +13567,156 @@ var require_git_storage_client = __commonJS({
|
|
|
13225
13567
|
this._authCacheExpiry = 0;
|
|
13226
13568
|
}
|
|
13227
13569
|
// =========================================================================
|
|
13228
|
-
//
|
|
13570
|
+
// Path Building Helpers
|
|
13571
|
+
// =========================================================================
|
|
13572
|
+
/**
|
|
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
|
|
13229
13608
|
// =========================================================================
|
|
13230
13609
|
/**
|
|
13231
|
-
* Create a new library
|
|
13610
|
+
* Create a new DAO library (requires governance authority)
|
|
13232
13611
|
* @param {string} subdao - SubDAO address
|
|
13233
13612
|
* @param {string} name - Library name
|
|
13234
13613
|
* @param {Object} [options] - Creation options
|
|
13614
|
+
* @param {string} [options.libraryId] - Custom library ID (auto-generated from name if not provided)
|
|
13235
13615
|
* @param {string} [options.description] - Library description
|
|
13236
13616
|
* @param {'public'|'private'} [options.visibility='public'] - Library visibility
|
|
13237
13617
|
* @returns {Promise<LibraryMetadata>}
|
|
13238
13618
|
*/
|
|
13239
|
-
async
|
|
13240
|
-
return this._post(
|
|
13241
|
-
subdao,
|
|
13619
|
+
async createDAOLibrary(subdao, name, options = {}) {
|
|
13620
|
+
return this._post(`/git/dao/${encodeURIComponent(subdao)}/libraries`, {
|
|
13242
13621
|
name,
|
|
13622
|
+
libraryId: options.libraryId,
|
|
13243
13623
|
description: options.description,
|
|
13244
13624
|
visibility: options.visibility || "public"
|
|
13245
13625
|
}, { auth: true });
|
|
13246
13626
|
}
|
|
13247
13627
|
/**
|
|
13248
|
-
*
|
|
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
|
|
13249
13715
|
* @param {string} subdao - SubDAO address
|
|
13250
13716
|
* @returns {Promise<LibraryMetadata>}
|
|
13251
13717
|
*/
|
|
13252
13718
|
async getLibrary(subdao) {
|
|
13253
|
-
return this.
|
|
13719
|
+
return this.getDAOLibrary(subdao, "default");
|
|
13254
13720
|
}
|
|
13255
13721
|
/**
|
|
13256
13722
|
* List all libraries
|
|
@@ -13267,207 +13733,251 @@ var require_git_storage_client = __commonJS({
|
|
|
13267
13733
|
return this._get(`/git/libraries${queryString ? "?" + queryString : ""}`);
|
|
13268
13734
|
}
|
|
13269
13735
|
/**
|
|
13270
|
-
* Delete a library (
|
|
13736
|
+
* Delete a library (legacy - use deleteDAOLibrary or deletePersonalLibrary)
|
|
13737
|
+
* @deprecated Use deleteDAOLibrary() or deletePersonalLibrary() instead
|
|
13271
13738
|
* @param {string} subdao - SubDAO address
|
|
13272
13739
|
* @returns {Promise<{ok: boolean}>}
|
|
13273
13740
|
*/
|
|
13274
13741
|
async deleteLibrary(subdao) {
|
|
13275
|
-
return this.
|
|
13742
|
+
return this.deleteDAOLibrary(subdao, "default");
|
|
13276
13743
|
}
|
|
13277
13744
|
// =========================================================================
|
|
13278
13745
|
// Git Object Operations
|
|
13279
13746
|
// =========================================================================
|
|
13280
13747
|
/**
|
|
13281
13748
|
* Store git objects (batch)
|
|
13282
|
-
* @param {string}
|
|
13749
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13283
13750
|
* @param {GitObject[]} objects - Objects to store
|
|
13751
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13284
13752
|
* @returns {Promise<{stored: number}>}
|
|
13285
13753
|
*/
|
|
13286
|
-
async putObjects(
|
|
13287
|
-
|
|
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 });
|
|
13288
13757
|
}
|
|
13289
13758
|
/**
|
|
13290
13759
|
* Get a single git object
|
|
13291
|
-
* @param {string}
|
|
13760
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13292
13761
|
* @param {string} oid - Object ID
|
|
13762
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13293
13763
|
* @returns {Promise<GitObject>}
|
|
13294
13764
|
*/
|
|
13295
|
-
async getObject(
|
|
13296
|
-
|
|
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);
|
|
13297
13768
|
}
|
|
13298
13769
|
/**
|
|
13299
13770
|
* Get multiple git objects
|
|
13300
|
-
* @param {string}
|
|
13771
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13301
13772
|
* @param {string[]} oids - Object IDs
|
|
13773
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13302
13774
|
* @returns {Promise<{objects: GitObject[]}>}
|
|
13303
13775
|
*/
|
|
13304
|
-
async getObjects(
|
|
13305
|
-
|
|
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);
|
|
13306
13779
|
}
|
|
13307
13780
|
// =========================================================================
|
|
13308
13781
|
// Reference Operations
|
|
13309
13782
|
// =========================================================================
|
|
13310
13783
|
/**
|
|
13311
13784
|
* List all refs
|
|
13312
|
-
* @param {string}
|
|
13785
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13786
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13313
13787
|
* @returns {Promise<{refs: GitRef[]}>}
|
|
13314
13788
|
*/
|
|
13315
|
-
async listRefs(
|
|
13316
|
-
|
|
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);
|
|
13317
13792
|
}
|
|
13318
13793
|
/**
|
|
13319
13794
|
* Get a specific ref
|
|
13320
|
-
* @param {string}
|
|
13795
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13321
13796
|
* @param {string} refName - Reference name (e.g., 'refs/heads/main')
|
|
13797
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13322
13798
|
* @returns {Promise<GitRef>}
|
|
13323
13799
|
*/
|
|
13324
|
-
async getRef(
|
|
13325
|
-
|
|
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);
|
|
13326
13803
|
}
|
|
13327
13804
|
/**
|
|
13328
13805
|
* Update a ref
|
|
13329
|
-
* @param {string}
|
|
13806
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13330
13807
|
* @param {string} refName - Reference name
|
|
13331
13808
|
* @param {string} oid - New object ID
|
|
13332
13809
|
* @param {Object} [options] - Update options
|
|
13333
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)
|
|
13334
13812
|
* @returns {Promise<{ok: boolean}>}
|
|
13335
13813
|
*/
|
|
13336
|
-
async updateRef(
|
|
13337
|
-
|
|
13338
|
-
|
|
13339
|
-
|
|
13340
|
-
{ auth: true }
|
|
13341
|
-
);
|
|
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 });
|
|
13342
13818
|
}
|
|
13343
13819
|
// =========================================================================
|
|
13344
13820
|
// Sync Operations
|
|
13345
13821
|
// =========================================================================
|
|
13346
13822
|
/**
|
|
13347
13823
|
* Push changes to library
|
|
13348
|
-
* @param {string}
|
|
13824
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13349
13825
|
* @param {Object} payload - Push payload
|
|
13350
13826
|
* @param {GitObject[]} payload.objects - Objects to push
|
|
13351
13827
|
* @param {Record<string, string>} payload.refs - Ref updates (name -> oid)
|
|
13352
13828
|
* @param {string} payload.message - Commit message
|
|
13829
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13353
13830
|
* @returns {Promise<PushResult>}
|
|
13354
13831
|
*/
|
|
13355
|
-
async push(
|
|
13356
|
-
|
|
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 });
|
|
13357
13835
|
}
|
|
13358
13836
|
/**
|
|
13359
13837
|
* Clone a library (get all objects and refs)
|
|
13360
|
-
* @param {string}
|
|
13838
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13839
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13361
13840
|
* @returns {Promise<{objects: GitObject[], refs: Record<string, string>, metadata: LibraryMetadata}>}
|
|
13362
13841
|
*/
|
|
13363
|
-
async clone(
|
|
13364
|
-
|
|
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);
|
|
13365
13845
|
}
|
|
13366
13846
|
/**
|
|
13367
13847
|
* Fetch changes since a commit
|
|
13368
|
-
* @param {string}
|
|
13848
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13369
13849
|
* @param {string} [since] - Commit OID to fetch since
|
|
13850
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13370
13851
|
* @returns {Promise<{objects: GitObject[], refs: Record<string, string>}>}
|
|
13371
13852
|
*/
|
|
13372
|
-
async fetch(
|
|
13853
|
+
async fetch(target, since, libraryId = "default") {
|
|
13373
13854
|
const params = since ? `?since=${since}` : "";
|
|
13374
|
-
|
|
13855
|
+
const path2 = typeof target === "string" ? this._buildLibraryPath("dao", target, libraryId, `fetch${params}`) : this._buildPath(target, `fetch${params}`);
|
|
13856
|
+
return this._get(path2);
|
|
13375
13857
|
}
|
|
13376
13858
|
// =========================================================================
|
|
13377
13859
|
// File Access
|
|
13378
13860
|
// =========================================================================
|
|
13379
13861
|
/**
|
|
13380
13862
|
* Get commit history
|
|
13381
|
-
* @param {string}
|
|
13863
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13382
13864
|
* @param {Object} [options] - History options
|
|
13383
13865
|
* @param {string} [options.ref='refs/heads/main'] - Reference to get history from
|
|
13384
13866
|
* @param {number} [options.limit=50] - Max commits to return
|
|
13867
|
+
* @param {string} [options.libraryId='default'] - Library ID (only used if target is string)
|
|
13385
13868
|
* @returns {Promise<{commits: GitCommit[]}>}
|
|
13386
13869
|
*/
|
|
13387
|
-
async getHistory(
|
|
13870
|
+
async getHistory(target, options = {}) {
|
|
13388
13871
|
const params = new URLSearchParams();
|
|
13389
13872
|
if (options.ref) params.set("ref", options.ref);
|
|
13390
13873
|
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
13391
|
-
|
|
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);
|
|
13392
13877
|
}
|
|
13393
13878
|
/**
|
|
13394
13879
|
* Get directory listing
|
|
13395
|
-
* @param {string}
|
|
13880
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13396
13881
|
* @param {string} ref - Reference (e.g., 'main')
|
|
13397
|
-
* @param {string}
|
|
13882
|
+
* @param {string} filePath - Directory path
|
|
13883
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13398
13884
|
* @returns {Promise<{entries: Array}>}
|
|
13399
13885
|
*/
|
|
13400
|
-
async getTree(
|
|
13401
|
-
|
|
13402
|
-
|
|
13403
|
-
);
|
|
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);
|
|
13404
13890
|
}
|
|
13405
13891
|
/**
|
|
13406
13892
|
* Get file contents
|
|
13407
|
-
* @param {string}
|
|
13893
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13408
13894
|
* @param {string} ref - Reference (e.g., 'main')
|
|
13409
|
-
* @param {string}
|
|
13895
|
+
* @param {string} filePath - File path
|
|
13896
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13410
13897
|
* @returns {Promise<{content: string}>}
|
|
13411
13898
|
*/
|
|
13412
|
-
async getBlob(
|
|
13413
|
-
|
|
13414
|
-
|
|
13415
|
-
);
|
|
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);
|
|
13416
13903
|
}
|
|
13417
13904
|
/**
|
|
13418
13905
|
* Get file contents as string (convenience method)
|
|
13419
|
-
* @param {string}
|
|
13906
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13420
13907
|
* @param {string} ref - Reference (e.g., 'main')
|
|
13421
|
-
* @param {string}
|
|
13908
|
+
* @param {string} filePath - File path
|
|
13909
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13422
13910
|
* @returns {Promise<string>}
|
|
13423
13911
|
*/
|
|
13424
|
-
async getFile(
|
|
13425
|
-
const result = await this.getBlob(
|
|
13912
|
+
async getFile(target, ref, filePath, libraryId = "default") {
|
|
13913
|
+
const result = await this.getBlob(target, ref, filePath, libraryId);
|
|
13426
13914
|
return result.content;
|
|
13427
13915
|
}
|
|
13428
13916
|
// =========================================================================
|
|
13429
13917
|
// Fork Operations
|
|
13430
13918
|
// =========================================================================
|
|
13431
13919
|
/**
|
|
13432
|
-
* Fork a library to a new SubDAO
|
|
13920
|
+
* Fork a DAO library to a new SubDAO
|
|
13433
13921
|
* @param {string} sourceSubdao - Source SubDAO address to fork from
|
|
13922
|
+
* @param {string} sourceLibraryId - Source library ID
|
|
13434
13923
|
* @param {string} targetSubdao - Target SubDAO address for the fork
|
|
13435
13924
|
* @param {Object} [options] - Fork options
|
|
13925
|
+
* @param {string} [options.targetLibraryId] - Library ID for the fork
|
|
13436
13926
|
* @param {string} [options.targetName] - Name for the forked library
|
|
13437
13927
|
* @param {string} [options.targetDescription] - Description for the forked library
|
|
13438
13928
|
* @returns {Promise<{ok: boolean, forkedLibrary: string, sourceLibrary: string, commitsCopied: number}>}
|
|
13439
13929
|
*/
|
|
13440
|
-
async
|
|
13441
|
-
|
|
13930
|
+
async forkDAOLibrary(sourceSubdao, sourceLibraryId, targetSubdao, options = {}) {
|
|
13931
|
+
const path2 = this._buildLibraryPath("dao", sourceSubdao, sourceLibraryId, "fork");
|
|
13932
|
+
return this._post(path2, {
|
|
13442
13933
|
targetSubdao,
|
|
13934
|
+
targetLibraryId: options.targetLibraryId,
|
|
13443
13935
|
targetName: options.targetName,
|
|
13444
13936
|
targetDescription: options.targetDescription
|
|
13445
13937
|
}, { auth: true });
|
|
13446
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
|
+
}
|
|
13447
13952
|
/**
|
|
13448
13953
|
* List forks of a library
|
|
13449
|
-
* @param {string}
|
|
13954
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13955
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13450
13956
|
* @returns {Promise<{forks: Array, count: number}>}
|
|
13451
13957
|
*/
|
|
13452
|
-
async getForks(
|
|
13453
|
-
|
|
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);
|
|
13454
13961
|
}
|
|
13455
13962
|
/**
|
|
13456
13963
|
* Get upstream fork info (for forked libraries)
|
|
13457
|
-
* @param {string}
|
|
13964
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13965
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13458
13966
|
* @returns {Promise<{upstreamSubdao: string, upstreamCommit: string, forkedAt: number}>}
|
|
13459
13967
|
*/
|
|
13460
|
-
async getUpstream(
|
|
13461
|
-
|
|
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);
|
|
13462
13971
|
}
|
|
13463
13972
|
/**
|
|
13464
13973
|
* Check if a library is a fork
|
|
13465
|
-
* @param {string}
|
|
13974
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13975
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13466
13976
|
* @returns {Promise<boolean>}
|
|
13467
13977
|
*/
|
|
13468
|
-
async isFork(
|
|
13978
|
+
async isFork(target, libraryId = "default") {
|
|
13469
13979
|
try {
|
|
13470
|
-
await this.getUpstream(
|
|
13980
|
+
await this.getUpstream(target, libraryId);
|
|
13471
13981
|
return true;
|
|
13472
13982
|
} catch (e) {
|
|
13473
13983
|
if (e.message && e.message.includes("404")) {
|
|
@@ -13481,59 +13991,62 @@ var require_git_storage_client = __commonJS({
|
|
|
13481
13991
|
// =========================================================================
|
|
13482
13992
|
/**
|
|
13483
13993
|
* List collaborators
|
|
13484
|
-
* @param {string}
|
|
13994
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13995
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13485
13996
|
* @returns {Promise<{collaborators: Collaborator[]}>}
|
|
13486
13997
|
*/
|
|
13487
|
-
async listCollaborators(
|
|
13488
|
-
|
|
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);
|
|
13489
14001
|
}
|
|
13490
14002
|
/**
|
|
13491
14003
|
* Add a collaborator
|
|
13492
|
-
* @param {string}
|
|
14004
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13493
14005
|
* @param {string} address - Collaborator wallet address
|
|
13494
14006
|
* @param {'read'|'write'|'admin'} permission - Permission level
|
|
14007
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13495
14008
|
* @returns {Promise<{ok: boolean}>}
|
|
13496
14009
|
*/
|
|
13497
|
-
async addCollaborator(
|
|
13498
|
-
|
|
13499
|
-
|
|
13500
|
-
permission
|
|
13501
|
-
}, { 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 });
|
|
13502
14013
|
}
|
|
13503
14014
|
/**
|
|
13504
14015
|
* Remove a collaborator
|
|
13505
|
-
* @param {string}
|
|
14016
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13506
14017
|
* @param {string} address - Collaborator wallet address
|
|
14018
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13507
14019
|
* @returns {Promise<{ok: boolean}>}
|
|
13508
14020
|
*/
|
|
13509
|
-
async removeCollaborator(
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
|
|
13513
|
-
);
|
|
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 });
|
|
13514
14025
|
}
|
|
13515
14026
|
/**
|
|
13516
14027
|
* Check permissions for an address
|
|
13517
|
-
* @param {string}
|
|
14028
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13518
14029
|
* @param {string} address - Wallet address to check
|
|
14030
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13519
14031
|
* @returns {Promise<{canRead: boolean, canWrite: boolean, isAdmin: boolean, permission?: string}>}
|
|
13520
14032
|
*/
|
|
13521
|
-
async getPermissions(
|
|
13522
|
-
|
|
13523
|
-
|
|
13524
|
-
);
|
|
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);
|
|
13525
14037
|
}
|
|
13526
14038
|
// =========================================================================
|
|
13527
14039
|
// High-Level Convenience Methods
|
|
13528
14040
|
// =========================================================================
|
|
13529
14041
|
/**
|
|
13530
14042
|
* Push a manifest file (convenience method)
|
|
13531
|
-
* @param {string}
|
|
14043
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13532
14044
|
* @param {Object} manifest - Manifest object to push
|
|
13533
14045
|
* @param {string} message - Commit message
|
|
14046
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13534
14047
|
* @returns {Promise<PushResult>}
|
|
13535
14048
|
*/
|
|
13536
|
-
async pushManifest(
|
|
14049
|
+
async pushManifest(target, manifest, message, libraryId = "default") {
|
|
13537
14050
|
const content = JSON.stringify(manifest, null, 2);
|
|
13538
14051
|
const oid = await this._computeOid(content);
|
|
13539
14052
|
const objects = [{
|
|
@@ -13552,7 +14065,7 @@ var require_git_storage_client = __commonJS({
|
|
|
13552
14065
|
});
|
|
13553
14066
|
let parentOid = null;
|
|
13554
14067
|
try {
|
|
13555
|
-
const currentRef = await this.getRef(
|
|
14068
|
+
const currentRef = await this.getRef(target, "refs/heads/main", libraryId);
|
|
13556
14069
|
parentOid = currentRef.oid;
|
|
13557
14070
|
} catch (e) {
|
|
13558
14071
|
}
|
|
@@ -13571,20 +14084,21 @@ var require_git_storage_client = __commonJS({
|
|
|
13571
14084
|
size: commitContent.length,
|
|
13572
14085
|
data: this._toBase64(commitContent)
|
|
13573
14086
|
});
|
|
13574
|
-
return this.push(
|
|
14087
|
+
return this.push(target, {
|
|
13575
14088
|
objects,
|
|
13576
14089
|
refs: { "refs/heads/main": commitOid },
|
|
13577
14090
|
message
|
|
13578
|
-
});
|
|
14091
|
+
}, libraryId);
|
|
13579
14092
|
}
|
|
13580
14093
|
/**
|
|
13581
14094
|
* Get manifest from library (convenience method)
|
|
13582
|
-
* @param {string}
|
|
14095
|
+
* @param {string|LibraryContext} target - SubDAO address (legacy) or LibraryContext
|
|
13583
14096
|
* @param {string} [ref='main'] - Reference to get manifest from
|
|
14097
|
+
* @param {string} [libraryId='default'] - Library ID (only used if target is string)
|
|
13584
14098
|
* @returns {Promise<Object>}
|
|
13585
14099
|
*/
|
|
13586
|
-
async getManifest(
|
|
13587
|
-
const content = await this.getFile(
|
|
14100
|
+
async getManifest(target, ref = "main", libraryId = "default") {
|
|
14101
|
+
const content = await this.getFile(target, ref, "manifest.json", libraryId);
|
|
13588
14102
|
return JSON.parse(content);
|
|
13589
14103
|
}
|
|
13590
14104
|
// =========================================================================
|
|
@@ -14049,6 +14563,7 @@ var require_src = __commonJS({
|
|
|
14049
14563
|
var boost = require_boost();
|
|
14050
14564
|
var bounty = require_bounty();
|
|
14051
14565
|
var contributions = require_contributions();
|
|
14566
|
+
var reputation = require_reputation();
|
|
14052
14567
|
var votingMultiplier = require_votingMultiplier();
|
|
14053
14568
|
var auction = require_auction();
|
|
14054
14569
|
var wallet = require_wallet();
|
|
@@ -14102,6 +14617,7 @@ var require_src = __commonJS({
|
|
|
14102
14617
|
utils: { ...utils, privateTx, safe, time },
|
|
14103
14618
|
bounty,
|
|
14104
14619
|
contributions,
|
|
14620
|
+
reputation,
|
|
14105
14621
|
votingMultiplier,
|
|
14106
14622
|
auction,
|
|
14107
14623
|
wallet: Object.assign(wallet, {
|