@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 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 before each query,
446
- * `SET LOCAL` is used to inject the current request ID and call index
447
- * into the PostgreSQL session. The `audit_trigger_function` reads these
448
- * via `current_setting()` and stamps audit rows atomically at INSERT
449
- * time inside the trigger — no separate UPDATE required.
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 rawSql = sql;
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
- await rawSql(`SET LOCAL app.replay_request_id = '${requestId.replace(/'/g, "''")}'`);
1199
- await rawSql(`SET LOCAL app.replay_call_index = '${callIndex}'`);
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: failed to SET LOCAL audit context:", err);
1205
+ console.warn("netlify-recorder: audited transaction failed, falling back:", err);
1202
1206
  }
1203
1207
  }
1204
1208
  return await sql(strings, ...values);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replayio-app-building/netlify-recorder",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "Capture and replay Netlify function executions as Replay recordings",
5
5
  "type": "module",
6
6
  "exports": {