ezlogs-nextjs 0.4.4 → 0.4.6

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 (65) hide show
  1. package/README.md +51 -11
  2. package/dist/actors/index.d.cts +1 -1
  3. package/dist/actors/index.d.ts +1 -1
  4. package/dist/{chunk-Z2TM3LGG.js → chunk-2NFJOT6Q.js} +1 -1
  5. package/dist/{chunk-R6IWVTX3.cjs → chunk-65HRY3PW.cjs} +31 -21
  6. package/dist/{chunk-YXZZNZG6.cjs → chunk-B3WST6ES.cjs} +9 -9
  7. package/dist/{chunk-MMLQXSSD.cjs → chunk-B5ZUQULZ.cjs} +18 -11
  8. package/dist/{chunk-NX4EL7BY.cjs → chunk-DM2EAOSF.cjs} +4 -4
  9. package/dist/chunk-DRE2VXFX.js +19 -0
  10. package/dist/chunk-H3FC5HMW.cjs +16 -0
  11. package/dist/{chunk-GI6BM4MR.js → chunk-IBSNHBUC.js} +18 -12
  12. package/dist/chunk-JWJKFZBW.js +52 -0
  13. package/dist/{chunk-MHBS5FEP.js → chunk-M3VBQ5KT.js} +27 -4
  14. package/dist/chunk-NFZ5OKF3.cjs +22 -0
  15. package/dist/{chunk-GMHOUAKD.cjs → chunk-O7SFYXJC.cjs} +37 -13
  16. package/dist/{chunk-U22T7QYY.js → chunk-PK2Z2ABL.js} +13 -3
  17. package/dist/{chunk-YMIGZYFH.js → chunk-RD47JECJ.js} +1 -1
  18. package/dist/chunk-RMKGMIV2.js +13 -0
  19. package/dist/{chunk-NINIAL7M.js → chunk-U3IJV5EJ.js} +1 -1
  20. package/dist/chunk-VJR4VB4B.cjs +56 -0
  21. package/dist/{chunk-PS4U2GFJ.cjs → chunk-YO6E763S.cjs} +5 -5
  22. package/dist/{configuration-CJ5yKVlP.d.cts → configuration-b9pImwFB.d.cts} +2 -2
  23. package/dist/{configuration-CJ5yKVlP.d.ts → configuration-b9pImwFB.d.ts} +2 -2
  24. package/dist/db/drizzle.cjs +3 -3
  25. package/dist/db/drizzle.js +2 -2
  26. package/dist/db/postgres-js.cjs +4 -4
  27. package/dist/db/postgres-js.js +2 -2
  28. package/dist/db/prisma.cjs +12 -12
  29. package/dist/db/prisma.js +2 -2
  30. package/dist/db/supabase.cjs +42 -17
  31. package/dist/db/supabase.d.cts +11 -5
  32. package/dist/db/supabase.d.ts +11 -5
  33. package/dist/db/supabase.js +33 -9
  34. package/dist/index.cjs +288 -142
  35. package/dist/index.d.cts +2 -2
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.js +198 -52
  38. package/dist/jobs/bullmq.cjs +44 -16
  39. package/dist/jobs/bullmq.d.cts +7 -1
  40. package/dist/jobs/bullmq.d.ts +7 -1
  41. package/dist/jobs/bullmq.js +33 -6
  42. package/dist/jobs/inngest.cjs +36 -17
  43. package/dist/jobs/inngest.d.cts +7 -1
  44. package/dist/jobs/inngest.d.ts +7 -1
  45. package/dist/jobs/inngest.js +23 -5
  46. package/dist/jobs/supabase-queues.cjs +9 -9
  47. package/dist/jobs/supabase-queues.js +4 -4
  48. package/dist/jobs/trigger.cjs +7 -7
  49. package/dist/jobs/trigger.js +4 -4
  50. package/dist/jobs/upstash-workflow.cjs +139 -23
  51. package/dist/jobs/upstash-workflow.d.cts +20 -2
  52. package/dist/jobs/upstash-workflow.d.ts +20 -2
  53. package/dist/jobs/upstash-workflow.js +129 -14
  54. package/dist/nextjs-plugin/index.cjs +46 -29
  55. package/dist/nextjs-plugin/index.js +46 -29
  56. package/dist/nextjs-plugin/loader.cjs +70 -60
  57. package/dist/nextjs-plugin/loader.d.cts +18 -1
  58. package/dist/nextjs-plugin/loader.d.ts +18 -1
  59. package/dist/nextjs-plugin/loader.js +70 -61
  60. package/dist/triggers/index.cjs +22 -16
  61. package/dist/triggers/index.d.cts +0 -10
  62. package/dist/triggers/index.d.ts +0 -10
  63. package/dist/triggers/index.js +11 -5
  64. package/package.json +1 -1
  65. package/sql/postgres/00_install.sql +20 -3
@@ -1,5 +1,6 @@
1
- import { emitDbEvent, resolveDisplayName } from '../chunk-NINIAL7M.js';
2
- import { currentActorSource, configuration } from '../chunk-GI6BM4MR.js';
1
+ import { instrumentFrom, instrumentFactory } from '../chunk-JWJKFZBW.js';
2
+ import { emitDbEvent, resolveDisplayName } from '../chunk-U3IJV5EJ.js';
3
+ import { currentActorSource, configuration } from '../chunk-IBSNHBUC.js';
3
4
  import { logger } from '../chunk-FCFVIRQF.js';
4
5
  import '../chunk-SIAA4J6H.js';
5
6
 
@@ -64,7 +65,8 @@ function registerActorSource(client) {
64
65
  try {
65
66
  const slot = currentActorSource();
66
67
  if (slot) {
67
- slot.client = client;
68
+ slot.clients ??= [];
69
+ if (!slot.clients.includes(client)) slot.clients.push(client);
68
70
  slot.tried = false;
69
71
  return;
70
72
  }
@@ -75,18 +77,36 @@ function registerActorSource(client) {
75
77
  }
76
78
  async function tryExtractSupabaseActor() {
77
79
  const slot = currentActorSource();
78
- const client = slot ? slot.client : globalThis[GLOBAL_CLIENT_KEY];
79
- if (!client || typeof client.auth?.getUser !== "function") return null;
80
+ const clients = slot ? slot.clients ?? [] : [globalThis[GLOBAL_CLIENT_KEY]];
81
+ for (const client of clients) {
82
+ const actor = await userOf(client);
83
+ if (actor) return actor;
84
+ }
85
+ return null;
86
+ }
87
+ async function userOf(client) {
88
+ const auth = client?.auth;
89
+ if (!auth) return null;
80
90
  try {
81
- const { data } = await client.auth.getUser();
91
+ if (typeof auth.getClaims === "function") {
92
+ const claims = await auth.getClaims().then((r) => r?.data?.claims, () => null);
93
+ if (claims && typeof claims.sub === "string" && claims.sub) {
94
+ return withLabel(claims.sub, claims.user_metadata?.full_name, claims.user_metadata?.name, claims.email);
95
+ }
96
+ }
97
+ if (typeof auth.getUser !== "function") return null;
98
+ const { data } = await auth.getUser();
82
99
  const user = data?.user;
83
100
  if (!user || typeof user.id !== "string" || !user.id) return null;
84
- const label = user.user_metadata?.full_name ?? user.user_metadata?.name ?? user.email ?? void 0;
85
- return label ? { id: user.id, label } : { id: user.id };
101
+ return withLabel(user.id, user.user_metadata?.full_name, user.user_metadata?.name, user.email);
86
102
  } catch {
87
103
  return null;
88
104
  }
89
105
  }
106
+ function withLabel(id, ...candidates) {
107
+ const label = candidates.find((c) => typeof c === "string" && c.length > 0);
108
+ return label ? { id, label } : { id };
109
+ }
90
110
  function wrapBuilder(builder, table, preread) {
91
111
  if (typeof builder.insert === "function") {
92
112
  builder.insert = wrapMutation(
@@ -359,5 +379,9 @@ function describeError(error) {
359
379
  if (error instanceof Error) return `${error.name}: ${error.message}`;
360
380
  return String(error);
361
381
  }
382
+ var __ezlogsInstrument = instrumentFrom({
383
+ "@supabase/supabase-js#createClient": (original) => instrumentFactory(original, wrapSupabase),
384
+ "@supabase/ssr#createServerClient": (original) => instrumentFactory(original, wrapSupabase)
385
+ });
362
386
 
363
- export { tryExtractSupabaseActor, wrapSupabase };
387
+ export { __ezlogsInstrument, tryExtractSupabaseActor, wrapSupabase };