@actual-app/sync-server 26.7.0-nightly.20260607 → 26.7.0-nightly.20260609
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/build/app.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as run } from "./chunks/migrations-BM3OCiKK.js";
|
|
2
2
|
//#region app.ts
|
|
3
3
|
run().then(() => {
|
|
4
|
-
import("./chunks/app-
|
|
4
|
+
import("./chunks/app-C92I5MBg.js").then((app) => app.run());
|
|
5
5
|
}).catch((err) => {
|
|
6
6
|
console.log("Error starting app:", err);
|
|
7
7
|
process.exit(1);
|
|
@@ -630,6 +630,18 @@ var secretsService = {
|
|
|
630
630
|
}
|
|
631
631
|
};
|
|
632
632
|
//#endregion
|
|
633
|
+
//#region src/util/mutex.ts
|
|
634
|
+
var createMutex = () => {
|
|
635
|
+
let mutex = Promise.resolve();
|
|
636
|
+
return (operation) => new Promise((resolve, reject) => {
|
|
637
|
+
mutex = mutex.finally(() => {
|
|
638
|
+
try {
|
|
639
|
+
return operation().then(resolve, reject);
|
|
640
|
+
} catch {}
|
|
641
|
+
});
|
|
642
|
+
});
|
|
643
|
+
};
|
|
644
|
+
//#endregion
|
|
633
645
|
//#region src/app-akahu/app-akahu.ts
|
|
634
646
|
var app$9 = express();
|
|
635
647
|
app$9.use(express.json());
|
|
@@ -685,7 +697,7 @@ app$9.post("/transactions", handleError(async (req, res) => {
|
|
|
685
697
|
}
|
|
686
698
|
try {
|
|
687
699
|
const akahu = new AkahuClient({ appToken });
|
|
688
|
-
const account = await akahu
|
|
700
|
+
const account = await getRefreshedAccount(akahu, userToken, accountId);
|
|
689
701
|
if (!account) return res.send({
|
|
690
702
|
status: "error",
|
|
691
703
|
data: { error: "Account not found" }
|
|
@@ -764,6 +776,25 @@ app$9.post("/transactions", handleError(async (req, res) => {
|
|
|
764
776
|
});
|
|
765
777
|
}
|
|
766
778
|
}));
|
|
779
|
+
var runRefresh = createMutex();
|
|
780
|
+
function getRefreshedAccount(akahu, userToken, accountId) {
|
|
781
|
+
return runRefresh(async () => {
|
|
782
|
+
let account = await akahu.accounts.get(userToken, accountId);
|
|
783
|
+
if (!account) return null;
|
|
784
|
+
else if (!shouldRefreshAccount(account.refreshed?.transactions)) return account;
|
|
785
|
+
await akahu.accounts.refreshAll(userToken);
|
|
786
|
+
for (let i = 0; i < 5; i++) {
|
|
787
|
+
await new Promise((resolve) => setTimeout(resolve, 3e3));
|
|
788
|
+
account = await akahu.accounts.get(userToken, accountId);
|
|
789
|
+
if (!account) return null;
|
|
790
|
+
else if (!shouldRefreshAccount(account.refreshed?.transactions)) {
|
|
791
|
+
await new Promise((resolve) => setTimeout(resolve, 3e3));
|
|
792
|
+
break;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
return account;
|
|
796
|
+
});
|
|
797
|
+
}
|
|
767
798
|
function isEnriched(trans) {
|
|
768
799
|
return "merchant" in trans || "meta" in trans || "category" in trans;
|
|
769
800
|
}
|
|
@@ -805,6 +836,12 @@ function processTransaction(trans, account) {
|
|
|
805
836
|
transactionId: trans._id
|
|
806
837
|
};
|
|
807
838
|
}
|
|
839
|
+
var AKAHU_TRANSACTION_REFRESH_INTERVAL_MS = 3600 * 1e3;
|
|
840
|
+
function shouldRefreshAccount(refreshedAt) {
|
|
841
|
+
if (!refreshedAt) return false;
|
|
842
|
+
const refreshedAtTime = Date.parse(refreshedAt);
|
|
843
|
+
return Number.isFinite(refreshedAtTime) && Date.now() - refreshedAtTime > AKAHU_TRANSACTION_REFRESH_INTERVAL_MS;
|
|
844
|
+
}
|
|
808
845
|
//#endregion
|
|
809
846
|
//#region src/util/ssrf.ts
|
|
810
847
|
var dnsLookup = promisify(dns.lookup);
|
|
@@ -5253,4 +5290,4 @@ async function run() {
|
|
|
5253
5290
|
//#endregion
|
|
5254
5291
|
export { run };
|
|
5255
5292
|
|
|
5256
|
-
//# sourceMappingURL=app-
|
|
5293
|
+
//# sourceMappingURL=app-C92I5MBg.js.map
|