@fileverse/api 0.0.8 → 0.0.10
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/cli/index.js +8 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cloudflare.js +18119 -0
- package/dist/cloudflare.js.map +1 -0
- package/dist/commands/index.js +31 -2
- package/dist/commands/index.js.map +1 -1
- package/dist/index.js +81 -2
- package/dist/index.js.map +1 -1
- package/dist/worker.js +81 -2
- package/dist/worker.js.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -116,7 +116,12 @@ var init_config = __esm({
|
|
|
116
116
|
init_constants();
|
|
117
117
|
projectEnvPath = path2.join(process.cwd(), "config", ".env");
|
|
118
118
|
userEnvPath = path2.join(os.homedir(), ".fileverse", ".env");
|
|
119
|
-
|
|
119
|
+
if (typeof globalThis.process !== "undefined" && typeof globalThis.process.cwd === "function") {
|
|
120
|
+
try {
|
|
121
|
+
loadConfig(false);
|
|
122
|
+
} catch {
|
|
123
|
+
}
|
|
124
|
+
}
|
|
120
125
|
config = {
|
|
121
126
|
...STATIC_CONFIG,
|
|
122
127
|
get SERVICE_NAME() {
|
|
@@ -1131,6 +1136,29 @@ var init_events_model = __esm({
|
|
|
1131
1136
|
`;
|
|
1132
1137
|
await QueryBuilder.execute(sql, [Date.now(), _id]);
|
|
1133
1138
|
}
|
|
1139
|
+
static async markSubmitted(_id) {
|
|
1140
|
+
const sql = `
|
|
1141
|
+
UPDATE ${this.TABLE}
|
|
1142
|
+
SET status = 'submitted',
|
|
1143
|
+
lockedAt = NULL
|
|
1144
|
+
WHERE _id = ?
|
|
1145
|
+
`;
|
|
1146
|
+
await QueryBuilder.execute(sql, [_id]);
|
|
1147
|
+
}
|
|
1148
|
+
static async findNextSubmitted(lockedFileIds) {
|
|
1149
|
+
const exclusionClause = lockedFileIds.length > 0 ? `AND fileId NOT IN (${lockedFileIds.map(() => "?").join(", ")})` : "";
|
|
1150
|
+
const sql = `
|
|
1151
|
+
SELECT * FROM ${this.TABLE}
|
|
1152
|
+
WHERE status = 'submitted'
|
|
1153
|
+
AND userOpHash IS NOT NULL
|
|
1154
|
+
${exclusionClause}
|
|
1155
|
+
ORDER BY timestamp ASC
|
|
1156
|
+
LIMIT 1
|
|
1157
|
+
`;
|
|
1158
|
+
const params = [...lockedFileIds];
|
|
1159
|
+
const row = await QueryBuilder.selectOne(sql, params);
|
|
1160
|
+
return row ? this.parseEvent(row) : void 0;
|
|
1161
|
+
}
|
|
1134
1162
|
static async markProcessed(_id) {
|
|
1135
1163
|
const sql = `
|
|
1136
1164
|
UPDATE ${this.TABLE}
|
|
@@ -2888,6 +2916,56 @@ var init_file_manager = __esm({
|
|
|
2888
2916
|
metadata
|
|
2889
2917
|
};
|
|
2890
2918
|
}
|
|
2919
|
+
async submitUpdateFile(file2) {
|
|
2920
|
+
logger.debug(`Submitting update for file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
|
|
2921
|
+
const { encryptedSecretKey, nonce, secretKey } = await generateLinkKeyMaterial({
|
|
2922
|
+
ddocId: file2.ddocId,
|
|
2923
|
+
linkKey: file2.linkKey,
|
|
2924
|
+
linkKeyNonce: file2.linkKeyNonce
|
|
2925
|
+
});
|
|
2926
|
+
const yjsContent = markdownToYjs(file2.content);
|
|
2927
|
+
const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
|
|
2928
|
+
const commentKey = toUint8Array2(file2.commentKey);
|
|
2929
|
+
const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
|
|
2930
|
+
const linkLock = buildLinklock(secretKey, toUint8Array2(key), commentKey);
|
|
2931
|
+
const encryptedTitle = await encryptTitleWithFileKey({
|
|
2932
|
+
title: file2.title || "Untitled",
|
|
2933
|
+
key
|
|
2934
|
+
});
|
|
2935
|
+
const metadata = buildFileMetadata({
|
|
2936
|
+
encryptedTitle,
|
|
2937
|
+
encryptedFileSize: encryptedFile.size,
|
|
2938
|
+
appLock,
|
|
2939
|
+
ownerLock,
|
|
2940
|
+
ddocId: file2.ddocId,
|
|
2941
|
+
nonce: fromUint8Array2(nonce),
|
|
2942
|
+
owner: this.agentClient.getAgentAddress()
|
|
2943
|
+
});
|
|
2944
|
+
const authParams = await this.getAuthParams();
|
|
2945
|
+
const { metadataHash, contentHash, gateHash } = await uploadAllFilesToIPFS(
|
|
2946
|
+
{ metadata, encryptedFile, linkLock, ddocId: file2.ddocId },
|
|
2947
|
+
authParams
|
|
2948
|
+
);
|
|
2949
|
+
const callData = prepareCallData({
|
|
2950
|
+
metadataHash,
|
|
2951
|
+
contentHash,
|
|
2952
|
+
gateHash,
|
|
2953
|
+
appFileId: file2.ddocId,
|
|
2954
|
+
fileId: file2.onChainFileId
|
|
2955
|
+
});
|
|
2956
|
+
const userOpHash = await this.sendFileOperation(callData);
|
|
2957
|
+
logger.debug(`Submitted update user op for file ${file2.ddocId}`);
|
|
2958
|
+
return { userOpHash, metadata };
|
|
2959
|
+
}
|
|
2960
|
+
async submitDeleteFile(file2) {
|
|
2961
|
+
logger.debug(`Submitting delete for file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
|
|
2962
|
+
const callData = prepareDeleteFileCallData({
|
|
2963
|
+
onChainFileId: file2.onChainFileId
|
|
2964
|
+
});
|
|
2965
|
+
const userOpHash = await this.sendFileOperation(callData);
|
|
2966
|
+
logger.debug(`Submitted delete user op for file ${file2.ddocId}`);
|
|
2967
|
+
return { userOpHash };
|
|
2968
|
+
}
|
|
2891
2969
|
async updateFile(file2) {
|
|
2892
2970
|
logger.debug(`Updating file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
|
|
2893
2971
|
const { encryptedSecretKey, nonce, secretKey } = await generateLinkKeyMaterial({
|
|
@@ -2991,6 +3069,7 @@ var init_publish = __esm({
|
|
|
2991
3069
|
init_smart_agent();
|
|
2992
3070
|
init_file_manager();
|
|
2993
3071
|
init_config();
|
|
3072
|
+
init_pimlico_utils();
|
|
2994
3073
|
createFileManager = async (portalSeed, portalAddress, ucanSecret, privateAccountKey) => {
|
|
2995
3074
|
const keyPair = ucans2.EdKeypair.fromSecretKey(fromUint8Array3(ucanSecret), {
|
|
2996
3075
|
exportable: true
|
|
@@ -3596,7 +3675,7 @@ CREATE TABLE IF NOT EXISTS events (
|
|
|
3596
3675
|
type TEXT NOT NULL CHECK (type IN ('create', 'update', 'delete')),
|
|
3597
3676
|
timestamp BIGINT NOT NULL,
|
|
3598
3677
|
fileId TEXT NOT NULL,
|
|
3599
|
-
status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'processed', 'failed')),
|
|
3678
|
+
status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'submitted', 'processed', 'failed')),
|
|
3600
3679
|
retryCount INTEGER NOT NULL DEFAULT 0,
|
|
3601
3680
|
lastError TEXT,
|
|
3602
3681
|
lockedAt BIGINT,
|