@fiber-pay/runtime 0.1.0-rc.6 → 0.1.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/dist/index.js +65 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -218,16 +218,20 @@ var AlertManager = class {
|
|
|
218
218
|
};
|
|
219
219
|
|
|
220
220
|
// src/alerts/backends/file-jsonl.ts
|
|
221
|
-
import {
|
|
221
|
+
import { appendFile, mkdir } from "fs/promises";
|
|
222
222
|
import { dirname, join } from "path";
|
|
223
223
|
var JsonlFileAlertBackend = class {
|
|
224
224
|
path;
|
|
225
|
+
initialized = false;
|
|
225
226
|
constructor(path) {
|
|
226
227
|
this.path = path;
|
|
227
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
228
228
|
}
|
|
229
229
|
async send(alert) {
|
|
230
|
-
|
|
230
|
+
if (!this.initialized) {
|
|
231
|
+
await mkdir(dirname(this.path), { recursive: true });
|
|
232
|
+
this.initialized = true;
|
|
233
|
+
}
|
|
234
|
+
await appendFile(this.path, `${JSON.stringify(alert)}
|
|
231
235
|
`, "utf-8");
|
|
232
236
|
}
|
|
233
237
|
};
|
|
@@ -247,8 +251,8 @@ var DailyJsonlFileAlertBackend = class {
|
|
|
247
251
|
}
|
|
248
252
|
async send(alert) {
|
|
249
253
|
const dateDir = join(this.baseLogsDir, todayDateString());
|
|
250
|
-
|
|
251
|
-
|
|
254
|
+
await mkdir(dateDir, { recursive: true });
|
|
255
|
+
await appendFile(join(dateDir, this.filename), `${JSON.stringify(alert)}
|
|
252
256
|
`, "utf-8");
|
|
253
257
|
}
|
|
254
258
|
};
|
|
@@ -2168,12 +2172,60 @@ var HealthMonitor = class extends BaseMonitor {
|
|
|
2168
2172
|
|
|
2169
2173
|
// src/monitors/tracker-utils.ts
|
|
2170
2174
|
function isNotFoundError(error) {
|
|
2171
|
-
const
|
|
2172
|
-
return /not found|does not exist|no such/i.test(
|
|
2175
|
+
const haystack = collectErrorText(error);
|
|
2176
|
+
return /not found|does not exist|no such/i.test(haystack);
|
|
2173
2177
|
}
|
|
2174
2178
|
function isExpectedTrackerError(error) {
|
|
2175
|
-
const
|
|
2176
|
-
return /temporarily unavailable|connection refused|timed out|timeout/i.test(
|
|
2179
|
+
const haystack = collectErrorText(error);
|
|
2180
|
+
return /temporarily unavailable|connection refused|timed out|timeout/i.test(haystack);
|
|
2181
|
+
}
|
|
2182
|
+
function collectErrorText(error) {
|
|
2183
|
+
if (error === null || error === void 0) {
|
|
2184
|
+
return "";
|
|
2185
|
+
}
|
|
2186
|
+
const parts = [];
|
|
2187
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2188
|
+
const walk = (value, depth) => {
|
|
2189
|
+
if (value === null || value === void 0) {
|
|
2190
|
+
return;
|
|
2191
|
+
}
|
|
2192
|
+
if (depth > 4) {
|
|
2193
|
+
return;
|
|
2194
|
+
}
|
|
2195
|
+
if (typeof value === "string") {
|
|
2196
|
+
parts.push(value);
|
|
2197
|
+
return;
|
|
2198
|
+
}
|
|
2199
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
2200
|
+
parts.push(String(value));
|
|
2201
|
+
return;
|
|
2202
|
+
}
|
|
2203
|
+
if (typeof value !== "object") {
|
|
2204
|
+
return;
|
|
2205
|
+
}
|
|
2206
|
+
if (seen.has(value)) {
|
|
2207
|
+
return;
|
|
2208
|
+
}
|
|
2209
|
+
seen.add(value);
|
|
2210
|
+
if (value instanceof Error) {
|
|
2211
|
+
parts.push(value.message);
|
|
2212
|
+
const valueWithData = value;
|
|
2213
|
+
walk(valueWithData.data, depth + 1);
|
|
2214
|
+
walk(valueWithData.cause, depth + 1);
|
|
2215
|
+
return;
|
|
2216
|
+
}
|
|
2217
|
+
if (Array.isArray(value)) {
|
|
2218
|
+
for (const item of value) {
|
|
2219
|
+
walk(item, depth + 1);
|
|
2220
|
+
}
|
|
2221
|
+
return;
|
|
2222
|
+
}
|
|
2223
|
+
for (const nested of Object.values(value)) {
|
|
2224
|
+
walk(nested, depth + 1);
|
|
2225
|
+
}
|
|
2226
|
+
};
|
|
2227
|
+
walk(error, 0);
|
|
2228
|
+
return parts.join(" ");
|
|
2177
2229
|
}
|
|
2178
2230
|
|
|
2179
2231
|
// src/monitors/invoice-tracker.ts
|
|
@@ -2893,7 +2945,7 @@ function normalizeHost(host) {
|
|
|
2893
2945
|
}
|
|
2894
2946
|
|
|
2895
2947
|
// src/storage/memory-store.ts
|
|
2896
|
-
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
2948
|
+
import { mkdir as mkdir2, readFile, writeFile } from "fs/promises";
|
|
2897
2949
|
import { dirname as dirname2 } from "path";
|
|
2898
2950
|
function nowMs() {
|
|
2899
2951
|
return Date.now();
|
|
@@ -2937,7 +2989,7 @@ var MemoryStore = class {
|
|
|
2937
2989
|
trackedPayments: toRecord2(this.trackedPayments),
|
|
2938
2990
|
alerts: this.alerts
|
|
2939
2991
|
};
|
|
2940
|
-
await
|
|
2992
|
+
await mkdir2(dirname2(this.config.stateFilePath), { recursive: true });
|
|
2941
2993
|
await writeFile(this.config.stateFilePath, JSON.stringify(state, null, 2), "utf-8");
|
|
2942
2994
|
}
|
|
2943
2995
|
startAutoFlush() {
|
|
@@ -3082,7 +3134,7 @@ function isTerminalPaymentStatus2(status) {
|
|
|
3082
3134
|
|
|
3083
3135
|
// src/storage/sqlite-store.ts
|
|
3084
3136
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
3085
|
-
import { mkdirSync
|
|
3137
|
+
import { mkdirSync } from "fs";
|
|
3086
3138
|
import { dirname as dirname3 } from "path";
|
|
3087
3139
|
import Database from "better-sqlite3";
|
|
3088
3140
|
var MIGRATIONS = [
|
|
@@ -3126,7 +3178,7 @@ var MIGRATIONS = [
|
|
|
3126
3178
|
var SqliteJobStore = class {
|
|
3127
3179
|
db;
|
|
3128
3180
|
constructor(dbPath) {
|
|
3129
|
-
|
|
3181
|
+
mkdirSync(dirname3(dbPath), { recursive: true });
|
|
3130
3182
|
this.db = new Database(dbPath);
|
|
3131
3183
|
this.db.pragma("journal_mode = WAL");
|
|
3132
3184
|
this.db.pragma("foreign_keys = ON");
|