@replayio-app-building/netlify-recorder 0.13.0 → 0.15.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.d.ts +8 -5
- package/dist/index.js +9 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -442,11 +442,14 @@ declare function databaseAuditMonitorTable(sql: SqlFunction, tableName: string):
|
|
|
442
442
|
*/
|
|
443
443
|
declare function databaseAuditDumpLogTable(sql: SqlFunction): Promise<Record<string, unknown>[]>;
|
|
444
444
|
/**
|
|
445
|
-
* Wraps a Neon SQL tagged-template function so that
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
* via `current_setting()` and stamps audit rows atomically
|
|
449
|
-
*
|
|
445
|
+
* Wraps a Neon SQL tagged-template function so that each query runs
|
|
446
|
+
* inside a transaction that first calls `set_config()` to inject the
|
|
447
|
+
* current request ID and call index. The `audit_trigger_function`
|
|
448
|
+
* reads these via `current_setting()` and stamps audit rows atomically
|
|
449
|
+
* — no separate UPDATE required.
|
|
450
|
+
*
|
|
451
|
+
* Requires the Neon HTTP driver's `.transaction()` method so that
|
|
452
|
+
* `set_config` and the user's query share one transaction.
|
|
450
453
|
*
|
|
451
454
|
* @example
|
|
452
455
|
* ```ts
|
package/dist/index.js
CHANGED
|
@@ -1189,16 +1189,20 @@ async function databaseAuditDumpLogTable(sql) {
|
|
|
1189
1189
|
}
|
|
1190
1190
|
function createAuditedSql(sql) {
|
|
1191
1191
|
let callIndex = 0;
|
|
1192
|
-
const
|
|
1192
|
+
const sqlWithTx = sql;
|
|
1193
1193
|
const auditedSql = async (strings, ...values) => {
|
|
1194
1194
|
const requestId = getCurrentRequestId();
|
|
1195
1195
|
callIndex++;
|
|
1196
|
-
if (requestId) {
|
|
1196
|
+
if (requestId && typeof sqlWithTx.transaction === "function") {
|
|
1197
1197
|
try {
|
|
1198
|
-
|
|
1199
|
-
|
|
1198
|
+
const results = await sqlWithTx.transaction([
|
|
1199
|
+
sql`SELECT set_config('app.replay_request_id', ${requestId}, true)`,
|
|
1200
|
+
sql`SELECT set_config('app.replay_call_index', ${String(callIndex)}, true)`,
|
|
1201
|
+
sql(strings, ...values)
|
|
1202
|
+
]);
|
|
1203
|
+
return results[2];
|
|
1200
1204
|
} catch (err) {
|
|
1201
|
-
console.warn("netlify-recorder:
|
|
1205
|
+
console.warn("netlify-recorder: audited transaction failed, falling back:", err);
|
|
1202
1206
|
}
|
|
1203
1207
|
}
|
|
1204
1208
|
return await sql(strings, ...values);
|