@fileverse/api 0.0.9 → 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 +2 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cloudflare.js +261 -4
- package/dist/cloudflare.js.map +1 -1
- package/dist/commands/index.js +25 -1
- package/dist/commands/index.js.map +1 -1
- package/dist/index.js +75 -1
- package/dist/index.js.map +1 -1
- package/dist/worker.js +75 -1
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1136,6 +1136,29 @@ var init_events_model = __esm({
|
|
|
1136
1136
|
`;
|
|
1137
1137
|
await QueryBuilder.execute(sql, [Date.now(), _id]);
|
|
1138
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
|
+
}
|
|
1139
1162
|
static async markProcessed(_id) {
|
|
1140
1163
|
const sql = `
|
|
1141
1164
|
UPDATE ${this.TABLE}
|
|
@@ -2893,6 +2916,56 @@ var init_file_manager = __esm({
|
|
|
2893
2916
|
metadata
|
|
2894
2917
|
};
|
|
2895
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
|
+
}
|
|
2896
2969
|
async updateFile(file2) {
|
|
2897
2970
|
logger.debug(`Updating file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
|
|
2898
2971
|
const { encryptedSecretKey, nonce, secretKey } = await generateLinkKeyMaterial({
|
|
@@ -2996,6 +3069,7 @@ var init_publish = __esm({
|
|
|
2996
3069
|
init_smart_agent();
|
|
2997
3070
|
init_file_manager();
|
|
2998
3071
|
init_config();
|
|
3072
|
+
init_pimlico_utils();
|
|
2999
3073
|
createFileManager = async (portalSeed, portalAddress, ucanSecret, privateAccountKey) => {
|
|
3000
3074
|
const keyPair = ucans2.EdKeypair.fromSecretKey(fromUint8Array3(ucanSecret), {
|
|
3001
3075
|
exportable: true
|
|
@@ -3601,7 +3675,7 @@ CREATE TABLE IF NOT EXISTS events (
|
|
|
3601
3675
|
type TEXT NOT NULL CHECK (type IN ('create', 'update', 'delete')),
|
|
3602
3676
|
timestamp BIGINT NOT NULL,
|
|
3603
3677
|
fileId TEXT NOT NULL,
|
|
3604
|
-
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')),
|
|
3605
3679
|
retryCount INTEGER NOT NULL DEFAULT 0,
|
|
3606
3680
|
lastError TEXT,
|
|
3607
3681
|
lockedAt BIGINT,
|