ezlogs-nextjs 0.1.0 → 0.1.1

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.
Files changed (41) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +98 -688
  3. package/bin/install-triggers.cjs +1 -1
  4. package/dist/actors/index.d.cts +1 -1
  5. package/dist/actors/index.d.ts +1 -1
  6. package/dist/{configuration-D9x9Gvds.d.cts → configuration-aUYgA8-h.d.cts} +20 -3
  7. package/dist/{configuration-D9x9Gvds.d.ts → configuration-aUYgA8-h.d.ts} +20 -3
  8. package/dist/db/drizzle.cjs +17 -6
  9. package/dist/db/drizzle.js +17 -6
  10. package/dist/db/prisma.cjs +17 -6
  11. package/dist/db/prisma.js +17 -6
  12. package/dist/db/supabase.cjs +17 -6
  13. package/dist/db/supabase.js +17 -6
  14. package/dist/index.cjs +459 -222
  15. package/dist/index.d.cts +2 -2
  16. package/dist/index.d.ts +2 -2
  17. package/dist/index.js +459 -222
  18. package/dist/jobs/bullmq.cjs +6 -5
  19. package/dist/jobs/bullmq.d.cts +16 -8
  20. package/dist/jobs/bullmq.d.ts +16 -8
  21. package/dist/jobs/bullmq.js +6 -5
  22. package/dist/jobs/inngest.cjs +16 -6
  23. package/dist/jobs/inngest.js +16 -6
  24. package/dist/jobs/supabase-queues.cjs +16 -6
  25. package/dist/jobs/supabase-queues.js +16 -6
  26. package/dist/jobs/trigger.cjs +16 -6
  27. package/dist/jobs/trigger.js +16 -6
  28. package/dist/jobs/upstash-workflow.cjs +16 -6
  29. package/dist/jobs/upstash-workflow.js +16 -6
  30. package/dist/nextjs-plugin/index.cjs +18 -0
  31. package/dist/nextjs-plugin/index.js +18 -0
  32. package/dist/nextjs-plugin/loader.cjs +44 -34
  33. package/dist/nextjs-plugin/loader.d.cts +10 -0
  34. package/dist/nextjs-plugin/loader.d.ts +10 -0
  35. package/dist/nextjs-plugin/loader.js +44 -34
  36. package/dist/triggers/index.cjs +43 -8
  37. package/dist/triggers/index.d.cts +7 -0
  38. package/dist/triggers/index.d.ts +7 -0
  39. package/dist/triggers/index.js +43 -8
  40. package/package.json +3 -4
  41. package/sql/postgres/00_install.sql +1 -1
@@ -19,6 +19,18 @@ function withEzlogsConfig(nextConfig = {}) {
19
19
  const loaderPath = resolveLoaderPath();
20
20
  return {
21
21
  ...nextConfig,
22
+ // Mark the agent as a server-external package so Next.js's webpack
23
+ // doesn't try to bundle it through its own pipeline. The agent
24
+ // imports Node built-ins (`node:crypto`, `node:async_hooks`),
25
+ // and Next's bundler can strip the `node:` prefix on some compile
26
+ // paths (notably the Next-15 instrumentation.ts bundle) — turning
27
+ // `import "node:crypto"` into `import "crypto"`, which then fails
28
+ // to resolve. Treating the agent as a regular Node dependency
29
+ // mirrors what Node's resolver does natively at runtime and works
30
+ // across Next 14, 15, and the App Router / Pages Router splits.
31
+ serverExternalPackages: mergeServerExternalPackages(
32
+ nextConfig.serverExternalPackages
33
+ ),
22
34
  webpack(config, options) {
23
35
  const merged = userWebpack ? userWebpack(config, options) : config;
24
36
  if (!options.isServer) return merged;
@@ -27,6 +39,12 @@ function withEzlogsConfig(nextConfig = {}) {
27
39
  turbopack: mergeTurbopackConfig(nextConfig.turbopack, loaderPath)
28
40
  };
29
41
  }
42
+ function mergeServerExternalPackages(user) {
43
+ const ezlogsPkg = "ezlogs-nextjs";
44
+ if (!user) return [ezlogsPkg];
45
+ if (user.includes(ezlogsPkg)) return [...user];
46
+ return [...user, ezlogsPkg];
47
+ }
30
48
  function mergeTurbopackConfig(userTurbopack, loaderPath) {
31
49
  const ezlogsRules = {};
32
50
  for (const ext of ["ts", "tsx", "js", "jsx"]) {
@@ -16,6 +16,18 @@ function withEzlogsConfig(nextConfig = {}) {
16
16
  const loaderPath = resolveLoaderPath();
17
17
  return {
18
18
  ...nextConfig,
19
+ // Mark the agent as a server-external package so Next.js's webpack
20
+ // doesn't try to bundle it through its own pipeline. The agent
21
+ // imports Node built-ins (`node:crypto`, `node:async_hooks`),
22
+ // and Next's bundler can strip the `node:` prefix on some compile
23
+ // paths (notably the Next-15 instrumentation.ts bundle) — turning
24
+ // `import "node:crypto"` into `import "crypto"`, which then fails
25
+ // to resolve. Treating the agent as a regular Node dependency
26
+ // mirrors what Node's resolver does natively at runtime and works
27
+ // across Next 14, 15, and the App Router / Pages Router splits.
28
+ serverExternalPackages: mergeServerExternalPackages(
29
+ nextConfig.serverExternalPackages
30
+ ),
19
31
  webpack(config, options) {
20
32
  const merged = userWebpack ? userWebpack(config, options) : config;
21
33
  if (!options.isServer) return merged;
@@ -24,6 +36,12 @@ function withEzlogsConfig(nextConfig = {}) {
24
36
  turbopack: mergeTurbopackConfig(nextConfig.turbopack, loaderPath)
25
37
  };
26
38
  }
39
+ function mergeServerExternalPackages(user) {
40
+ const ezlogsPkg = "ezlogs-nextjs";
41
+ if (!user) return [ezlogsPkg];
42
+ if (user.includes(ezlogsPkg)) return [...user];
43
+ return [...user, ezlogsPkg];
44
+ }
27
45
  function mergeTurbopackConfig(userTurbopack, loaderPath) {
28
46
  const ezlogsRules = {};
29
47
  for (const ext of ["ts", "tsx", "js", "jsx"]) {
@@ -4,31 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var path = require('path');
6
6
 
7
- var __create = Object.create;
8
- var __defProp = Object.defineProperty;
9
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
11
- var __getProtoOf = Object.getPrototypeOf;
12
- var __hasOwnProp = Object.prototype.hasOwnProperty;
13
8
  var __commonJS = (cb, mod) => function __require() {
14
9
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
10
  };
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from))
19
- if (!__hasOwnProp.call(to, key) && key !== except)
20
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
- }
22
- return to;
23
- };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- __defProp(target, "default", { value: mod, enumerable: true }) ,
30
- mod
31
- ));
32
11
 
33
12
  // node_modules/sucrase/dist/parser/tokenizer/keywords.js
34
13
  var require_keywords = __commonJS({
@@ -15735,9 +15714,25 @@ var require_parser = __commonJS({
15735
15714
  exports.parse = parse;
15736
15715
  }
15737
15716
  });
15738
-
15739
- // src/nextjs-plugin/loader.ts
15740
- var import_parser = __toESM(require_parser());
15717
+ var cachedSucraseParse;
15718
+ function getSucraseParse() {
15719
+ if (cachedSucraseParse !== void 0) return cachedSucraseParse;
15720
+ try {
15721
+ const mod = require_parser();
15722
+ if (typeof mod.parse !== "function") {
15723
+ throw new Error("sucrase parser module has no `parse` export");
15724
+ }
15725
+ cachedSucraseParse = mod.parse;
15726
+ return cachedSucraseParse;
15727
+ } catch (e) {
15728
+ const message = e instanceof Error ? e.message : String(e);
15729
+ console.warn(
15730
+ `[ezlogs] sucrase parser unavailable; inline Server Actions won't be auto-captured. Wrap them manually with captureServerAction(). Reason: ${message}`
15731
+ );
15732
+ cachedSucraseParse = null;
15733
+ return null;
15734
+ }
15735
+ }
15741
15736
  var HTTP_METHOD_NAMES = [
15742
15737
  "GET",
15743
15738
  "HEAD",
@@ -15748,8 +15743,21 @@ var HTTP_METHOD_NAMES = [
15748
15743
  "OPTIONS"
15749
15744
  ];
15750
15745
  var ALREADY_WRAPPED_MARKER = "__ezlogs_orig_";
15751
- var REEXPORT_WRAP_MARKER = "ezlogs-nextjs auto-wrap re-export";
15746
+ var PACKAGE_NAME = "ezlogs-nextjs";
15747
+ var REEXPORT_WRAP_MARKER = `${PACKAGE_NAME} auto-wrap re-export`;
15752
15748
  function loader(source) {
15749
+ try {
15750
+ return loaderImpl.call(this, source);
15751
+ } catch (loaderError) {
15752
+ const path = this.resourcePath ?? "<unknown>";
15753
+ const message = loaderError instanceof Error ? `${loaderError.name}: ${loaderError.message}` : String(loaderError);
15754
+ console.warn(
15755
+ `[ezlogs] loader failed for ${path}; leaving source unchanged so the build succeeds. ${message}`
15756
+ );
15757
+ return source;
15758
+ }
15759
+ }
15760
+ function loaderImpl(source) {
15753
15761
  if (source.includes(ALREADY_WRAPPED_MARKER) || source.includes(REEXPORT_WRAP_MARKER)) {
15754
15762
  return source;
15755
15763
  }
@@ -15794,7 +15802,7 @@ function rewriteAppRoute(source, routeModulePath) {
15794
15802
  const wrapperBlock = [
15795
15803
  "",
15796
15804
  "// --- ezlogs-nextjs auto-wrap (build-time) ---",
15797
- `import { captureRoute as __ezlogs_capture } from "ezlogs-nextjs";`,
15805
+ `import { captureRoute as __ezlogs_capture } from "${PACKAGE_NAME}";`,
15798
15806
  `const __ezlogs_meta = ${meta};`,
15799
15807
  ...Array.from(detected).map(
15800
15808
  (method) => `export const ${method} = __ezlogs_capture(${ALREADY_WRAPPED_MARKER}${method}, __ezlogs_meta);`
@@ -15837,7 +15845,7 @@ function rewriteLocalAliasedRouteExports(source, routeModulePath) {
15837
15845
  const meta = JSON.stringify({ routeModulePath });
15838
15846
  const wrapperLines = [
15839
15847
  "// --- ezlogs-nextjs auto-wrap re-export (build-time) ---",
15840
- `import { captureRoute as __ezlogs_capture } from "ezlogs-nextjs";`,
15848
+ `import { captureRoute as __ezlogs_capture } from "${PACKAGE_NAME}";`,
15841
15849
  `const __ezlogs_meta = ${meta};`,
15842
15850
  ...entries.map(
15843
15851
  (e) => `export const ${e.exported} = __ezlogs_capture(${e.local}, __ezlogs_meta);`
@@ -15880,7 +15888,7 @@ ${wrapper}
15880
15888
  }
15881
15889
  if (!changed) return source;
15882
15890
  if (needsWrapImport) {
15883
- rewritten = `import { wrapSupabase as ${ALREADY_WRAPPED_MARKER}wrap } from "ezlogs-nextjs/supabase";
15891
+ rewritten = `import { wrapSupabase as ${ALREADY_WRAPPED_MARKER}wrap } from "${PACKAGE_NAME}/supabase";
15884
15892
  ${rewritten}`;
15885
15893
  }
15886
15894
  return rewritten;
@@ -15912,7 +15920,7 @@ function rewriteServerActionFile(source) {
15912
15920
  const wrapperBlock = [
15913
15921
  "",
15914
15922
  "// --- ezlogs-nextjs auto-wrap server action (build-time) ---",
15915
- `import { captureServerActionExport as __ezlogs_capture_sa } from "ezlogs-nextjs";`,
15923
+ `import { captureServerActionExport as __ezlogs_capture_sa } from "${PACKAGE_NAME}";`,
15916
15924
  ...detected.map(
15917
15925
  (name) => `export const ${name} = __ezlogs_capture_sa(${ALREADY_WRAPPED_MARKER}${name}, ${JSON.stringify(name)});`
15918
15926
  ),
@@ -15938,11 +15946,13 @@ var INLINE_HELPER_NAME = "__ezlogs_run_inline_server_action";
15938
15946
  function rewriteInlineServerActions(source, filename) {
15939
15947
  if (!source.includes("use server")) return source;
15940
15948
  if (source.includes(INLINE_HELPER_NAME)) return source;
15949
+ const sucraseParse = getSucraseParse();
15950
+ if (sucraseParse === null) return source;
15941
15951
  let parsed;
15942
15952
  try {
15943
15953
  const isJSX = /\.(jsx|tsx)$/i.test(filename);
15944
15954
  const isTS = /\.(ts|tsx)$/i.test(filename);
15945
- parsed = (0, import_parser.parse)(source, isJSX, isTS, false);
15955
+ parsed = sucraseParse(source, isJSX, isTS, false);
15946
15956
  } catch (e) {
15947
15957
  const message = e instanceof Error ? e.message : String(e);
15948
15958
  console.warn(
@@ -15990,7 +16000,7 @@ return await ${INLINE_HELPER_NAME}(${nameLiteral}, async () => {${patch.bodyText
15990
16000
  `;
15991
16001
  out = out.slice(0, patch.bodyContentStart) + replacement + out.slice(patch.bodyContentEnd);
15992
16002
  }
15993
- return `import { ${INLINE_HELPER_NAME} } from "ezlogs-nextjs";
16003
+ return `import { ${INLINE_HELPER_NAME} } from "${PACKAGE_NAME}";
15994
16004
  ${out}`;
15995
16005
  }
15996
16006
  function identifyFunctionShape(tokens, braceLIdx, source) {
@@ -16118,7 +16128,7 @@ function rewriteMiddleware(source) {
16118
16128
  const wrapperBlock = [
16119
16129
  "",
16120
16130
  "// --- ezlogs-nextjs auto-wrap middleware (build-time) ---",
16121
- `import { withMiddlewareCapture as __ezlogs_with_mw } from "ezlogs-nextjs";`,
16131
+ `import { withMiddlewareCapture as __ezlogs_with_mw } from "${PACKAGE_NAME}";`,
16122
16132
  `export const middleware = __ezlogs_with_mw(${ALREADY_WRAPPED_MARKER}middleware);`,
16123
16133
  "// --- end ezlogs-nextjs auto-wrap middleware ---",
16124
16134
  ""
@@ -16130,7 +16140,7 @@ function rewriteMiddleware(source) {
16130
16140
  const wrapperBlock = [
16131
16141
  "",
16132
16142
  "// --- ezlogs-nextjs auto-wrap middleware (build-time) ---",
16133
- `import { withMiddlewareCapture as __ezlogs_with_mw } from "ezlogs-nextjs";`,
16143
+ `import { withMiddlewareCapture as __ezlogs_with_mw } from "${PACKAGE_NAME}";`,
16134
16144
  `export default __ezlogs_with_mw(${ALREADY_WRAPPED_MARKER}default);`,
16135
16145
  "// --- end ezlogs-nextjs auto-wrap middleware ---",
16136
16146
  ""
@@ -16148,7 +16158,7 @@ function rewritePagesApi(source, routeModulePath) {
16148
16158
  const wrapperBlock = [
16149
16159
  "",
16150
16160
  "// --- ezlogs-nextjs auto-wrap (build-time) ---",
16151
- `import { capturePagesApi as __ezlogs_capture_pages } from "ezlogs-nextjs";`,
16161
+ `import { capturePagesApi as __ezlogs_capture_pages } from "${PACKAGE_NAME}";`,
16152
16162
  `const __ezlogs_meta = ${meta};`,
16153
16163
  `export default typeof ${ALREADY_WRAPPED_MARKER}default === "function"`,
16154
16164
  ` ? __ezlogs_capture_pages(${ALREADY_WRAPPED_MARKER}default, __ezlogs_meta)`,
@@ -16,6 +16,16 @@ interface PitchContext {
16
16
  * Loader entry point. Receives the user's source file as a string,
17
17
  * returns transformed source. Both Webpack and Turbopack call this
18
18
  * the same way (Turbopack uses loader-runner under the hood).
19
+ *
20
+ * Outer fail-open guard: this loader runs at the customer's `next
21
+ * build` time on every file Next.js routes through it. A throw in
22
+ * ANY of the rewrite helpers (regex catastrophe, malformed source,
23
+ * future sucrase incompatibility) would break the customer's build.
24
+ * EZLogs must never break the host. On any exception we log a warn
25
+ * with the file path + error, and return the source unchanged so
26
+ * the build continues — that one file just isn't auto-instrumented.
27
+ * The customer can still wrap manually via `captureRoute()` /
28
+ * `captureServerAction()`.
19
29
  */
20
30
  declare function loader(this: PitchContext, source: string): string;
21
31
  /**
@@ -16,6 +16,16 @@ interface PitchContext {
16
16
  * Loader entry point. Receives the user's source file as a string,
17
17
  * returns transformed source. Both Webpack and Turbopack call this
18
18
  * the same way (Turbopack uses loader-runner under the hood).
19
+ *
20
+ * Outer fail-open guard: this loader runs at the customer's `next
21
+ * build` time on every file Next.js routes through it. A throw in
22
+ * ANY of the rewrite helpers (regex catastrophe, malformed source,
23
+ * future sucrase incompatibility) would break the customer's build.
24
+ * EZLogs must never break the host. On any exception we log a warn
25
+ * with the file path + error, and return the source unchanged so
26
+ * the build continues — that one file just isn't auto-instrumented.
27
+ * The customer can still wrap manually via `captureRoute()` /
28
+ * `captureServerAction()`.
19
29
  */
20
30
  declare function loader(this: PitchContext, source: string): string;
21
31
  /**
@@ -1,30 +1,9 @@
1
1
  import { sep } from 'path';
2
2
 
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
4
  var __commonJS = (cb, mod) => function __require() {
10
5
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
6
  };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- __defProp(target, "default", { value: mod, enumerable: true }) ,
26
- mod
27
- ));
28
7
 
29
8
  // node_modules/sucrase/dist/parser/tokenizer/keywords.js
30
9
  var require_keywords = __commonJS({
@@ -15731,9 +15710,25 @@ var require_parser = __commonJS({
15731
15710
  exports.parse = parse;
15732
15711
  }
15733
15712
  });
15734
-
15735
- // src/nextjs-plugin/loader.ts
15736
- var import_parser = __toESM(require_parser());
15713
+ var cachedSucraseParse;
15714
+ function getSucraseParse() {
15715
+ if (cachedSucraseParse !== void 0) return cachedSucraseParse;
15716
+ try {
15717
+ const mod = require_parser();
15718
+ if (typeof mod.parse !== "function") {
15719
+ throw new Error("sucrase parser module has no `parse` export");
15720
+ }
15721
+ cachedSucraseParse = mod.parse;
15722
+ return cachedSucraseParse;
15723
+ } catch (e) {
15724
+ const message = e instanceof Error ? e.message : String(e);
15725
+ console.warn(
15726
+ `[ezlogs] sucrase parser unavailable; inline Server Actions won't be auto-captured. Wrap them manually with captureServerAction(). Reason: ${message}`
15727
+ );
15728
+ cachedSucraseParse = null;
15729
+ return null;
15730
+ }
15731
+ }
15737
15732
  var HTTP_METHOD_NAMES = [
15738
15733
  "GET",
15739
15734
  "HEAD",
@@ -15744,8 +15739,21 @@ var HTTP_METHOD_NAMES = [
15744
15739
  "OPTIONS"
15745
15740
  ];
15746
15741
  var ALREADY_WRAPPED_MARKER = "__ezlogs_orig_";
15747
- var REEXPORT_WRAP_MARKER = "ezlogs-nextjs auto-wrap re-export";
15742
+ var PACKAGE_NAME = "ezlogs-nextjs";
15743
+ var REEXPORT_WRAP_MARKER = `${PACKAGE_NAME} auto-wrap re-export`;
15748
15744
  function loader(source) {
15745
+ try {
15746
+ return loaderImpl.call(this, source);
15747
+ } catch (loaderError) {
15748
+ const path = this.resourcePath ?? "<unknown>";
15749
+ const message = loaderError instanceof Error ? `${loaderError.name}: ${loaderError.message}` : String(loaderError);
15750
+ console.warn(
15751
+ `[ezlogs] loader failed for ${path}; leaving source unchanged so the build succeeds. ${message}`
15752
+ );
15753
+ return source;
15754
+ }
15755
+ }
15756
+ function loaderImpl(source) {
15749
15757
  if (source.includes(ALREADY_WRAPPED_MARKER) || source.includes(REEXPORT_WRAP_MARKER)) {
15750
15758
  return source;
15751
15759
  }
@@ -15790,7 +15798,7 @@ function rewriteAppRoute(source, routeModulePath) {
15790
15798
  const wrapperBlock = [
15791
15799
  "",
15792
15800
  "// --- ezlogs-nextjs auto-wrap (build-time) ---",
15793
- `import { captureRoute as __ezlogs_capture } from "ezlogs-nextjs";`,
15801
+ `import { captureRoute as __ezlogs_capture } from "${PACKAGE_NAME}";`,
15794
15802
  `const __ezlogs_meta = ${meta};`,
15795
15803
  ...Array.from(detected).map(
15796
15804
  (method) => `export const ${method} = __ezlogs_capture(${ALREADY_WRAPPED_MARKER}${method}, __ezlogs_meta);`
@@ -15833,7 +15841,7 @@ function rewriteLocalAliasedRouteExports(source, routeModulePath) {
15833
15841
  const meta = JSON.stringify({ routeModulePath });
15834
15842
  const wrapperLines = [
15835
15843
  "// --- ezlogs-nextjs auto-wrap re-export (build-time) ---",
15836
- `import { captureRoute as __ezlogs_capture } from "ezlogs-nextjs";`,
15844
+ `import { captureRoute as __ezlogs_capture } from "${PACKAGE_NAME}";`,
15837
15845
  `const __ezlogs_meta = ${meta};`,
15838
15846
  ...entries.map(
15839
15847
  (e) => `export const ${e.exported} = __ezlogs_capture(${e.local}, __ezlogs_meta);`
@@ -15876,7 +15884,7 @@ ${wrapper}
15876
15884
  }
15877
15885
  if (!changed) return source;
15878
15886
  if (needsWrapImport) {
15879
- rewritten = `import { wrapSupabase as ${ALREADY_WRAPPED_MARKER}wrap } from "ezlogs-nextjs/supabase";
15887
+ rewritten = `import { wrapSupabase as ${ALREADY_WRAPPED_MARKER}wrap } from "${PACKAGE_NAME}/supabase";
15880
15888
  ${rewritten}`;
15881
15889
  }
15882
15890
  return rewritten;
@@ -15908,7 +15916,7 @@ function rewriteServerActionFile(source) {
15908
15916
  const wrapperBlock = [
15909
15917
  "",
15910
15918
  "// --- ezlogs-nextjs auto-wrap server action (build-time) ---",
15911
- `import { captureServerActionExport as __ezlogs_capture_sa } from "ezlogs-nextjs";`,
15919
+ `import { captureServerActionExport as __ezlogs_capture_sa } from "${PACKAGE_NAME}";`,
15912
15920
  ...detected.map(
15913
15921
  (name) => `export const ${name} = __ezlogs_capture_sa(${ALREADY_WRAPPED_MARKER}${name}, ${JSON.stringify(name)});`
15914
15922
  ),
@@ -15934,11 +15942,13 @@ var INLINE_HELPER_NAME = "__ezlogs_run_inline_server_action";
15934
15942
  function rewriteInlineServerActions(source, filename) {
15935
15943
  if (!source.includes("use server")) return source;
15936
15944
  if (source.includes(INLINE_HELPER_NAME)) return source;
15945
+ const sucraseParse = getSucraseParse();
15946
+ if (sucraseParse === null) return source;
15937
15947
  let parsed;
15938
15948
  try {
15939
15949
  const isJSX = /\.(jsx|tsx)$/i.test(filename);
15940
15950
  const isTS = /\.(ts|tsx)$/i.test(filename);
15941
- parsed = (0, import_parser.parse)(source, isJSX, isTS, false);
15951
+ parsed = sucraseParse(source, isJSX, isTS, false);
15942
15952
  } catch (e) {
15943
15953
  const message = e instanceof Error ? e.message : String(e);
15944
15954
  console.warn(
@@ -15986,7 +15996,7 @@ return await ${INLINE_HELPER_NAME}(${nameLiteral}, async () => {${patch.bodyText
15986
15996
  `;
15987
15997
  out = out.slice(0, patch.bodyContentStart) + replacement + out.slice(patch.bodyContentEnd);
15988
15998
  }
15989
- return `import { ${INLINE_HELPER_NAME} } from "ezlogs-nextjs";
15999
+ return `import { ${INLINE_HELPER_NAME} } from "${PACKAGE_NAME}";
15990
16000
  ${out}`;
15991
16001
  }
15992
16002
  function identifyFunctionShape(tokens, braceLIdx, source) {
@@ -16114,7 +16124,7 @@ function rewriteMiddleware(source) {
16114
16124
  const wrapperBlock = [
16115
16125
  "",
16116
16126
  "// --- ezlogs-nextjs auto-wrap middleware (build-time) ---",
16117
- `import { withMiddlewareCapture as __ezlogs_with_mw } from "ezlogs-nextjs";`,
16127
+ `import { withMiddlewareCapture as __ezlogs_with_mw } from "${PACKAGE_NAME}";`,
16118
16128
  `export const middleware = __ezlogs_with_mw(${ALREADY_WRAPPED_MARKER}middleware);`,
16119
16129
  "// --- end ezlogs-nextjs auto-wrap middleware ---",
16120
16130
  ""
@@ -16126,7 +16136,7 @@ function rewriteMiddleware(source) {
16126
16136
  const wrapperBlock = [
16127
16137
  "",
16128
16138
  "// --- ezlogs-nextjs auto-wrap middleware (build-time) ---",
16129
- `import { withMiddlewareCapture as __ezlogs_with_mw } from "ezlogs-nextjs";`,
16139
+ `import { withMiddlewareCapture as __ezlogs_with_mw } from "${PACKAGE_NAME}";`,
16130
16140
  `export default __ezlogs_with_mw(${ALREADY_WRAPPED_MARKER}default);`,
16131
16141
  "// --- end ezlogs-nextjs auto-wrap middleware ---",
16132
16142
  ""
@@ -16144,7 +16154,7 @@ function rewritePagesApi(source, routeModulePath) {
16144
16154
  const wrapperBlock = [
16145
16155
  "",
16146
16156
  "// --- ezlogs-nextjs auto-wrap (build-time) ---",
16147
- `import { capturePagesApi as __ezlogs_capture_pages } from "ezlogs-nextjs";`,
16157
+ `import { capturePagesApi as __ezlogs_capture_pages } from "${PACKAGE_NAME}";`,
16148
16158
  `const __ezlogs_meta = ${meta};`,
16149
16159
  `export default typeof ${ALREADY_WRAPPED_MARKER}default === "function"`,
16150
16160
  ` ? __ezlogs_capture_pages(${ALREADY_WRAPPED_MARKER}default, __ezlogs_meta)`,
@@ -3,7 +3,6 @@
3
3
  var promises = require('fs/promises');
4
4
  var path = require('path');
5
5
  var url = require('url');
6
- require('crypto');
7
6
 
8
7
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
9
8
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
@@ -94,9 +93,8 @@ var DEFAULT_EXCLUDED_TABLES = Object.freeze([
94
93
  ]);
95
94
  var DEFAULT_EXCLUDED_JOB_CLASSES = Object.freeze([]);
96
95
  var DEFAULT_EXCLUDED_GRAPHQL_OPERATIONS = Object.freeze(["IntrospectionQuery", "__*"]);
97
- var DEFAULT_SERVER_URL = "https://app.ezlogs.io";
98
96
  var Configuration = class {
99
- serverUrl = DEFAULT_SERVER_URL;
97
+ serverUrl = null;
100
98
  projectToken = null;
101
99
  captureHttp = true;
102
100
  captureDb = true;
@@ -108,6 +106,7 @@ var Configuration = class {
108
106
  logLevel = "warn";
109
107
  patchGlobalFetch = true;
110
108
  actorFromSupabase = true;
109
+ allowInsecureTransport = false;
111
110
  excludedPaths = [];
112
111
  excludedTables = [];
113
112
  excludedJobClasses = [];
@@ -135,7 +134,7 @@ var Configuration = class {
135
134
  */
136
135
  triggerTrackedTables = null;
137
136
  apply(options) {
138
- if (options.serverUrl !== void 0) this.serverUrl = options.serverUrl;
137
+ this.serverUrl = options.serverUrl;
139
138
  this.projectToken = options.projectToken;
140
139
  if (options.captureHttp !== void 0) this.captureHttp = options.captureHttp;
141
140
  if (options.captureDb !== void 0) this.captureDb = options.captureDb;
@@ -160,6 +159,9 @@ var Configuration = class {
160
159
  if (options.patchGlobalFetch !== void 0) {
161
160
  this.patchGlobalFetch = options.patchGlobalFetch;
162
161
  }
162
+ if (options.allowInsecureTransport !== void 0) {
163
+ this.allowInsecureTransport = options.allowInsecureTransport;
164
+ }
163
165
  if (options.actorFromSupabase !== void 0) {
164
166
  this.actorFromSupabase = options.actorFromSupabase;
165
167
  }
@@ -508,6 +510,8 @@ var storage = createScopedStorage(
508
510
  function getCurrentActor() {
509
511
  return storage.read();
510
512
  }
513
+
514
+ // src/correlation.ts
511
515
  var storage2 = createScopedStorage(
512
516
  /* @__PURE__ */ Symbol.for("ezlogs-nextjs:correlation-storage")
513
517
  );
@@ -795,7 +799,17 @@ var DB_SENSITIVE_PATTERNS = Object.freeze([
795
799
  "credit_card",
796
800
  "ssn",
797
801
  "social_security",
798
- "encrypted"
802
+ "encrypted",
803
+ "private_key",
804
+ "public_key",
805
+ "signing_key",
806
+ "pem",
807
+ "cipher",
808
+ "nonce",
809
+ "salt",
810
+ "digest",
811
+ "signature",
812
+ "hmac"
799
813
  ]);
800
814
  function emitDbEvent(input) {
801
815
  try {
@@ -967,13 +981,21 @@ function runWithAuditSnapshotScope(callback) {
967
981
  return storage3.run(0n, callback);
968
982
  }
969
983
 
984
+ // src/triggers/emit-dedup.ts
985
+ var storage4 = createScopedStorage(
986
+ /* @__PURE__ */ Symbol.for("ezlogs-nextjs:audit-emitted-ids-storage")
987
+ );
988
+ function currentEmittedAuditIds() {
989
+ return storage4.read();
990
+ }
991
+
970
992
  // src/triggers/reader.ts
971
993
  async function readAuditRows(exec, correlationId, snapshotMaxId = null) {
972
994
  try {
973
- const sql = snapshotMaxId === null ? `SELECT table_name, op, old_row, new_row, resource_id
995
+ const sql = snapshotMaxId === null ? `SELECT id, table_name, op, old_row, new_row, resource_id
974
996
  FROM ezlogs_audit_log
975
997
  WHERE correlation_id = $1
976
- ORDER BY id ASC` : `SELECT table_name, op, old_row, new_row, resource_id
998
+ ORDER BY id ASC` : `SELECT id, table_name, op, old_row, new_row, resource_id
977
999
  FROM ezlogs_audit_log
978
1000
  WHERE correlation_id = $1
979
1001
  OR (correlation_id IS NULL AND id > $2)
@@ -1044,7 +1066,19 @@ async function flushAuditLog(exec) {
1044
1066
  const snapshot = currentAuditSnapshot();
1045
1067
  const rows = await readAuditRows(exec, correlationId, snapshot);
1046
1068
  if (rows.length === 0) return;
1047
- emitAuditRows(rows);
1069
+ const emitted = currentEmittedAuditIds();
1070
+ if (emitted === null) {
1071
+ emitAuditRows(rows);
1072
+ return;
1073
+ }
1074
+ const fresh = [];
1075
+ for (const row of rows) {
1076
+ if (row.id === "" || emitted.has(row.id)) continue;
1077
+ emitted.add(row.id);
1078
+ fresh.push(row);
1079
+ }
1080
+ if (fresh.length === 0) return;
1081
+ emitAuditRows(fresh);
1048
1082
  }
1049
1083
  function emitOne(row) {
1050
1084
  const op = mapOp(row.op);
@@ -1140,6 +1174,7 @@ function extractRows(result) {
1140
1174
  function normalizeAuditRow(raw) {
1141
1175
  const r = raw ?? {};
1142
1176
  return {
1177
+ id: r.id == null ? "" : String(r.id),
1143
1178
  table_name: String(r.table_name ?? ""),
1144
1179
  op: r.op,
1145
1180
  old_row: r.old_row ?? null,
@@ -123,6 +123,13 @@ declare function withDatabaseContext<T>(client: PgLikeClient, callback: (client:
123
123
  * drivers return strings) — `coerceJsonb` below handles both.
124
124
  */
125
125
  interface AuditRow {
126
+ /**
127
+ * The audit log row's primary key, stringified. Used only for
128
+ * within-request emit dedup — never reaches the wire. We stringify
129
+ * here so drivers that return bigint, number, or string all live in
130
+ * one Set comparable type.
131
+ */
132
+ id: string;
126
133
  table_name: string;
127
134
  op: "INSERT" | "UPDATE" | "DELETE";
128
135
  old_row: Record<string, unknown> | string | null;
@@ -123,6 +123,13 @@ declare function withDatabaseContext<T>(client: PgLikeClient, callback: (client:
123
123
  * drivers return strings) — `coerceJsonb` below handles both.
124
124
  */
125
125
  interface AuditRow {
126
+ /**
127
+ * The audit log row's primary key, stringified. Used only for
128
+ * within-request emit dedup — never reaches the wire. We stringify
129
+ * here so drivers that return bigint, number, or string all live in
130
+ * one Set comparable type.
131
+ */
132
+ id: string;
126
133
  table_name: string;
127
134
  op: "INSERT" | "UPDATE" | "DELETE";
128
135
  old_row: Record<string, unknown> | string | null;