next-action-plus 1.0.1 → 2.0.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.
Files changed (94) hide show
  1. package/README.md +862 -280
  2. package/dist/auth/authjs.d.ts +23 -0
  3. package/dist/auth/authjs.js +18 -0
  4. package/dist/auth/better-auth.d.ts +34 -0
  5. package/dist/auth/better-auth.js +17 -0
  6. package/dist/auth/clerk.d.ts +20 -0
  7. package/dist/auth/clerk.js +17 -0
  8. package/dist/auth/iron-session.d.ts +21 -0
  9. package/dist/auth/iron-session.js +18 -0
  10. package/dist/auth/kinde.d.ts +25 -0
  11. package/dist/auth/kinde.js +19 -0
  12. package/dist/auth/supabase.d.ts +29 -0
  13. package/dist/auth/supabase.js +17 -0
  14. package/dist/auth/workos.d.ts +25 -0
  15. package/dist/auth/workos.js +17 -0
  16. package/dist/authorize/casl.d.ts +14 -0
  17. package/dist/authorize/casl.js +10 -0
  18. package/dist/authorize/cerbos.d.ts +26 -0
  19. package/dist/authorize/cerbos.js +10 -0
  20. package/dist/authorize/openfga.d.ts +20 -0
  21. package/dist/authorize/openfga.js +10 -0
  22. package/dist/authorize/oso.d.ts +20 -0
  23. package/dist/authorize/oso.js +10 -0
  24. package/dist/authorize/permit.d.ts +14 -0
  25. package/dist/authorize/permit.js +10 -0
  26. package/dist/authorize.d.ts +11 -0
  27. package/dist/authorize.js +2 -0
  28. package/dist/chunk-2INYDUJR.js +16 -0
  29. package/dist/chunk-A55FM7D6.js +53 -0
  30. package/dist/chunk-GFGIJNSY.js +19 -0
  31. package/dist/chunk-IFAKJ72B.js +16 -0
  32. package/dist/codemod/bin.js +169 -0
  33. package/dist/concurrency/lock/memory.d.ts +5 -0
  34. package/dist/concurrency/lock/memory.js +1 -0
  35. package/dist/concurrency/lock/postgres.d.ts +9 -0
  36. package/dist/concurrency/lock/postgres.js +45 -0
  37. package/dist/concurrency/lock/redis.d.ts +9 -0
  38. package/dist/concurrency/lock/redis.js +30 -0
  39. package/dist/concurrency.d.ts +21 -0
  40. package/dist/concurrency.js +48 -0
  41. package/dist/conformance.d.ts +29 -0
  42. package/dist/conformance.js +139 -0
  43. package/dist/gate.d.ts +17 -0
  44. package/dist/gate.js +2 -0
  45. package/dist/i18n/next-intl.d.ts +12 -0
  46. package/dist/i18n/next-intl.js +11 -0
  47. package/dist/idempotency.d.ts +12 -0
  48. package/dist/idempotency.js +28 -0
  49. package/dist/index-BSA9a_EW.d.ts +22 -0
  50. package/dist/index-C3Ra6AYj.d.ts +37 -0
  51. package/dist/index-CZFS0TSh.d.ts +53 -0
  52. package/dist/index-CuAEDv-H.d.ts +64 -0
  53. package/dist/index-DJ2Ox9am.d.ts +31 -0
  54. package/dist/index-DV3R2g7H.d.ts +41 -0
  55. package/dist/index.d.ts +196 -192
  56. package/dist/index.js +189 -276
  57. package/dist/kv/memory.d.ts +5 -0
  58. package/dist/kv/memory.js +27 -0
  59. package/dist/kv/redis.d.ts +9 -0
  60. package/dist/kv/redis.js +23 -0
  61. package/dist/queue/bullmq.d.ts +18 -0
  62. package/dist/queue/bullmq.js +14 -0
  63. package/dist/queue/inngest.d.ts +18 -0
  64. package/dist/queue/inngest.js +14 -0
  65. package/dist/queue/qstash.d.ts +19 -0
  66. package/dist/queue/qstash.js +14 -0
  67. package/dist/queue/trigger.d.ts +16 -0
  68. package/dist/queue/trigger.js +11 -0
  69. package/dist/rate/limit/arcjet.d.ts +19 -0
  70. package/dist/rate/limit/arcjet.js +15 -0
  71. package/dist/rate/limit/unkey.d.ts +25 -0
  72. package/dist/rate/limit/unkey.js +14 -0
  73. package/dist/rate/limit/upstash.d.ts +18 -0
  74. package/dist/rate/limit/upstash.js +15 -0
  75. package/dist/rate/limit.d.ts +12 -0
  76. package/dist/rate/limit.js +17 -0
  77. package/dist/react.d.ts +40 -0
  78. package/dist/react.js +110 -0
  79. package/dist/security/origin.d.ts +11 -0
  80. package/dist/security/origin.js +21 -0
  81. package/dist/security/redact.d.ts +9 -0
  82. package/dist/security/redact.js +15 -0
  83. package/dist/security/secret.d.ts +6 -0
  84. package/dist/security/secret.js +13 -0
  85. package/dist/spec.d.ts +6 -0
  86. package/dist/spec.js +1 -0
  87. package/dist/telemetry/otel.d.ts +11 -0
  88. package/dist/telemetry/otel.js +25 -0
  89. package/dist/telemetry/pino.d.ts +12 -0
  90. package/dist/telemetry/pino.js +18 -0
  91. package/dist/telemetry/sentry.d.ts +16 -0
  92. package/dist/telemetry/sentry.js +11 -0
  93. package/package.json +325 -72
  94. package/dist/index.js.map +0 -1
@@ -0,0 +1,16 @@
1
+ import { d as TQueue } from '../index-CZFS0TSh.js';
2
+ import '../index-DV3R2g7H.js';
3
+ import '../index-CuAEDv-H.js';
4
+
5
+ declare const queueTrigger: (props: Readonly<{
6
+ tasks: {
7
+ trigger: (id: string, payload: unknown, options?: {
8
+ idempotencyKey?: string;
9
+ delay?: string;
10
+ }) => Promise<{
11
+ id: string;
12
+ }>;
13
+ };
14
+ }>) => TQueue;
15
+
16
+ export { queueTrigger };
@@ -0,0 +1,11 @@
1
+ // src/queue/trigger.ts
2
+ var queueTrigger = (props) => {
3
+ const { tasks } = props;
4
+ return {
5
+ name: "trigger",
6
+ version: 1,
7
+ enqueue: async (enqueueProps) => tasks.trigger(enqueueProps.name, enqueueProps.payload, { ...enqueueProps.dedupe && { idempotencyKey: enqueueProps.dedupe.id }, ...enqueueProps.delayMs !== void 0 && { delay: `${Math.ceil(enqueueProps.delayMs / 1e3)}s` } })
8
+ };
9
+ };
10
+
11
+ export { queueTrigger };
@@ -0,0 +1,19 @@
1
+ import { e as TRateLimiter } from '../../index-CZFS0TSh.js';
2
+ import '../../index-DV3R2g7H.js';
3
+ import '../../index-CuAEDv-H.js';
4
+
5
+ declare const rateLimitArcjet: (props: Readonly<{
6
+ aj: {
7
+ protect: (request: unknown, options?: {
8
+ requested?: number;
9
+ }) => Promise<{
10
+ isDenied: () => boolean;
11
+ reason?: {
12
+ resetTime?: Date;
13
+ };
14
+ }>;
15
+ };
16
+ request: () => Promise<unknown>;
17
+ }>) => TRateLimiter;
18
+
19
+ export { rateLimitArcjet };
@@ -0,0 +1,15 @@
1
+ // src/rate/limit/arcjet.ts
2
+ var rateLimitArcjet = (props) => {
3
+ const { aj, request } = props;
4
+ return {
5
+ name: "arcjet",
6
+ version: 1,
7
+ limit: async (limitProps) => {
8
+ const decision = await aj.protect(await request(), { requested: limitProps.cost });
9
+ const reset = decision.reason?.resetTime?.getTime();
10
+ return decision.isDenied() ? { success: false, retryAfterMs: reset === void 0 ? void 0 : Math.max(0, reset - Date.now()) } : { success: true };
11
+ }
12
+ };
13
+ };
14
+
15
+ export { rateLimitArcjet };
@@ -0,0 +1,25 @@
1
+ import { e as TRateLimiter } from '../../index-CZFS0TSh.js';
2
+ import '../../index-DV3R2g7H.js';
3
+ import '../../index-CuAEDv-H.js';
4
+
5
+ declare const rateLimitUnkey: (props: Readonly<{
6
+ unkey: {
7
+ ratelimit: {
8
+ limit: (props: {
9
+ namespace: string;
10
+ identifier: string;
11
+ limit: number;
12
+ duration: number;
13
+ cost?: number;
14
+ }) => Promise<{
15
+ success: boolean;
16
+ reset?: number;
17
+ }>;
18
+ };
19
+ };
20
+ namespace: string;
21
+ limit: number;
22
+ durationMs: number;
23
+ }>) => TRateLimiter;
24
+
25
+ export { rateLimitUnkey };
@@ -0,0 +1,14 @@
1
+ // src/rate/limit/unkey.ts
2
+ var rateLimitUnkey = (props) => {
3
+ const { unkey, namespace, limit, durationMs } = props;
4
+ return {
5
+ name: "unkey",
6
+ version: 1,
7
+ limit: async (limitProps) => {
8
+ const outcome = await unkey.ratelimit.limit({ namespace, identifier: limitProps.key, limit, duration: durationMs, cost: limitProps.cost });
9
+ return { success: outcome.success, retryAfterMs: outcome.success || outcome.reset === void 0 ? void 0 : Math.max(0, outcome.reset - Date.now()) };
10
+ }
11
+ };
12
+ };
13
+
14
+ export { rateLimitUnkey };
@@ -0,0 +1,18 @@
1
+ import { e as TRateLimiter } from '../../index-CZFS0TSh.js';
2
+ import '../../index-DV3R2g7H.js';
3
+ import '../../index-CuAEDv-H.js';
4
+
5
+ declare const rateLimitUpstash: (props: Readonly<{
6
+ ratelimit: {
7
+ limit: (identifier: string, options?: {
8
+ rate?: number;
9
+ }) => Promise<{
10
+ success: boolean;
11
+ reset: number;
12
+ pending?: Promise<unknown>;
13
+ }>;
14
+ };
15
+ wait?: (pending: Promise<unknown>) => void;
16
+ }>) => TRateLimiter;
17
+
18
+ export { rateLimitUpstash };
@@ -0,0 +1,15 @@
1
+ // src/rate/limit/upstash.ts
2
+ var rateLimitUpstash = (props) => {
3
+ const { ratelimit, wait } = props;
4
+ return {
5
+ name: "upstash",
6
+ version: 1,
7
+ limit: async (limitProps) => {
8
+ const outcome = await ratelimit.limit(limitProps.key, { rate: limitProps.cost });
9
+ if (outcome.pending) wait?.(outcome.pending);
10
+ return { success: outcome.success, retryAfterMs: outcome.success ? void 0 : Math.max(0, outcome.reset - Date.now()) };
11
+ }
12
+ };
13
+ };
14
+
15
+ export { rateLimitUpstash };
@@ -0,0 +1,12 @@
1
+ import { d as TPlugin } from '../index-DV3R2g7H.js';
2
+ import { e as TRateLimiter, b as TPluginRead, c as TPluginShape } from '../index-CZFS0TSh.js';
3
+ import '../index-CuAEDv-H.js';
4
+
5
+ declare const rateLimitCreate: <Ctx extends object = object>(props: Readonly<{
6
+ limiter: TRateLimiter;
7
+ key: TPluginRead<string, TPluginShape<Ctx>>;
8
+ cost?: number;
9
+ message?: string;
10
+ }>) => TPlugin<TPluginShape<Ctx>>;
11
+
12
+ export { rateLimitCreate };
@@ -0,0 +1,17 @@
1
+ import { errorCreate } from '../chunk-IFAKJ72B.js';
2
+
3
+ // src/rate/limit/create.ts
4
+ var rateLimitCreate = (props) => {
5
+ const { limiter, key, cost, message } = props;
6
+ return {
7
+ name: `rate-limit:${limiter.name}`,
8
+ version: 1,
9
+ run: async (call) => {
10
+ const outcome = await limiter.limit({ key: await key({ input: call.input, args: call.args, ctx: call.ctx, meta: call.meta }), cost: cost ?? 1 });
11
+ if (!outcome.success) throw errorCreate({ code: "RATE_LIMITED", message: message ?? "Too many requests, try again later", data: { retryAfterMs: outcome.retryAfterMs } });
12
+ return call.next();
13
+ }
14
+ };
15
+ };
16
+
17
+ export { rateLimitCreate };
@@ -0,0 +1,40 @@
1
+ type TReactStrategy = 'parallel' | 'queue' | 'drop' | 'latest' | 'keepLatest';
2
+ type TReactStatus = 'idle' | 'pending' | 'success' | 'error';
3
+ type TReactActionOptions<Params extends unknown[], Result, State> = {
4
+ action: (...params: Params) => Promise<Result>;
5
+ strategy?: TReactStrategy;
6
+ debounceMs?: number;
7
+ ok?: (props: Readonly<{
8
+ result: unknown;
9
+ }>) => boolean;
10
+ optimistic?: {
11
+ state: State;
12
+ update: (props: Readonly<{
13
+ state: State;
14
+ params: Params;
15
+ }>) => State;
16
+ };
17
+ onSuccess?: (props: Readonly<{
18
+ result: Result;
19
+ params: Params;
20
+ }>) => void;
21
+ onError?: (props: Readonly<{
22
+ error: unknown;
23
+ params: Params;
24
+ }>) => void;
25
+ onSettled?: (props: Readonly<{
26
+ params: Params;
27
+ }>) => void;
28
+ };
29
+ type TReactAction<Params extends unknown[], Result, State> = {
30
+ execute: (...params: Params) => Promise<Result | undefined>;
31
+ status: TReactStatus;
32
+ result: Result | undefined;
33
+ error: unknown;
34
+ optimistic: State;
35
+ reset: () => void;
36
+ };
37
+
38
+ declare const useAction: <Params extends unknown[], Result, State = undefined>(props: TReactActionOptions<Params, Result, State>) => TReactAction<Params, Result, State>;
39
+
40
+ export { useAction };
package/dist/react.js ADDED
@@ -0,0 +1,110 @@
1
+ "use client";
2
+
3
+ // src/react/use-action.ts
4
+ import { startTransition, useCallback, useOptimistic, useRef, useState } from "react";
5
+
6
+ // src/error/create.ts
7
+ var ERROR_BRAND = /* @__PURE__ */ Symbol.for("next-action-plus/error");
8
+ var ERROR_STATUS = { VALIDATION: 400, UNAUTHORIZED: 401, FORBIDDEN: 403, NOT_FOUND: 404, CONFLICT: 409, RATE_LIMITED: 429, DROPPED: 409, SUPERSEDED: 409, LOCK_TIMEOUT: 423, TIMEOUT: 504, ABORTED: 499, LIMIT: 413, STALE_ACTION: 410, INTERNAL: 500 };
9
+ var errorCreate = (props) => {
10
+ const { code, message, status, phase, issues, data, cause, expose, correlationId } = props;
11
+ const error = new Error(message ?? code, cause === void 0 ? void 0 : { cause });
12
+ error.name = "ActionError";
13
+ return Object.assign(error, { [ERROR_BRAND]: true, code, status: status ?? ERROR_STATUS[code] ?? 400, phase, issues: issues ?? [], data, correlationId, expose: expose ?? code !== "INTERNAL" });
14
+ };
15
+
16
+ // src/react/use-action.ts
17
+ var useAction = (props) => {
18
+ const [status, setStatus] = useState("idle");
19
+ const [result, setResult] = useState(void 0);
20
+ const [error, setError] = useState(void 0);
21
+ const [optimistic, optimisticAdd] = useOptimistic(props.optimistic?.state, (state, params) => props.optimistic ? props.optimistic.update({ state, params }) : state);
22
+ const latest = useRef({ props, counter: 0, running: 0, chain: Promise.resolve(), waiting: void 0, debounce: void 0 });
23
+ latest.current.props = props;
24
+ const call = useCallback(
25
+ (params) => new Promise((resolve, reject) => {
26
+ const self = latest.current;
27
+ const id = ++self.counter;
28
+ self.running++;
29
+ setStatus("pending");
30
+ startTransition(async () => {
31
+ if (self.props.optimistic) optimisticAdd(params);
32
+ try {
33
+ const value = await self.props.action(...params);
34
+ const isCurrent = self.props.strategy !== "latest" || id === self.counter;
35
+ if (!isCurrent) return resolve(void 0);
36
+ if (self.props.ok && !self.props.ok({ result: value })) {
37
+ setResult(value);
38
+ setError(value);
39
+ setStatus("error");
40
+ self.props.onError?.({ error: value, params });
41
+ } else {
42
+ setResult(value);
43
+ setError(void 0);
44
+ setStatus("success");
45
+ self.props.onSuccess?.({ result: value, params });
46
+ }
47
+ resolve(value);
48
+ } catch (thrown) {
49
+ const digest = thrown?.digest;
50
+ if (typeof digest === "string" && digest.startsWith("NEXT_")) return reject(thrown);
51
+ if (self.props.strategy === "latest" && id !== self.counter) return resolve(void 0);
52
+ const failure = thrown instanceof Error && /Failed to find Server Action|Server Action .* was not found/i.test(thrown.message) ? errorCreate({ code: "STALE_ACTION", message: "This page is out of date, reload to continue", cause: thrown }) : thrown;
53
+ setError(failure);
54
+ setStatus("error");
55
+ self.props.onError?.({ error: failure, params });
56
+ resolve(void 0);
57
+ } finally {
58
+ self.running--;
59
+ self.props.onSettled?.({ params });
60
+ }
61
+ });
62
+ }),
63
+ [optimisticAdd]
64
+ );
65
+ const execute = useCallback(
66
+ (...params) => {
67
+ const self = latest.current;
68
+ const { strategy, debounceMs } = self.props;
69
+ if (debounceMs) {
70
+ if (self.debounce) {
71
+ clearTimeout(self.debounce.timer);
72
+ self.debounce.resolve(void 0);
73
+ }
74
+ return new Promise((resolve) => {
75
+ self.debounce = { resolve, timer: setTimeout(() => (self.debounce = void 0, call(params).then(resolve)), debounceMs) };
76
+ });
77
+ }
78
+ if (strategy === "drop" && self.running > 0) return Promise.resolve(void 0);
79
+ if (strategy === "queue") {
80
+ const queued = self.chain.then(() => call(params));
81
+ self.chain = queued.catch(() => void 0);
82
+ return queued;
83
+ }
84
+ if (strategy === "keepLatest" && self.running > 0) {
85
+ self.waiting?.resolve(void 0);
86
+ return new Promise((resolve) => {
87
+ self.waiting = { params, resolve };
88
+ });
89
+ }
90
+ const running = call(params);
91
+ if (strategy === "keepLatest")
92
+ void running.finally(() => {
93
+ const next = self.waiting;
94
+ self.waiting = void 0;
95
+ if (next) void execute(...next.params).then(next.resolve);
96
+ });
97
+ return running;
98
+ },
99
+ [call]
100
+ );
101
+ const reset = useCallback(() => {
102
+ setStatus("idle");
103
+ setResult(void 0);
104
+ setError(void 0);
105
+ }, []);
106
+ return { execute, status, result, error, optimistic, reset };
107
+ };
108
+ export {
109
+ useAction
110
+ };
@@ -0,0 +1,11 @@
1
+ import { d as TPlugin } from '../index-DV3R2g7H.js';
2
+ import { c as TPluginShape } from '../index-CZFS0TSh.js';
3
+ import '../index-CuAEDv-H.js';
4
+
5
+ declare const securityOrigin: (props: Readonly<{
6
+ allowed: string[];
7
+ headers: () => Headers | Promise<Headers>;
8
+ fetchSite?: boolean;
9
+ }>) => TPlugin<TPluginShape<object>>;
10
+
11
+ export { securityOrigin };
@@ -0,0 +1,21 @@
1
+ import { errorCreate } from '../chunk-IFAKJ72B.js';
2
+
3
+ // src/security/origin.ts
4
+ var securityOrigin = (props) => {
5
+ const { allowed, headers, fetchSite } = props;
6
+ return {
7
+ name: "security-origin",
8
+ version: 1,
9
+ run: async (call) => {
10
+ const list = await headers();
11
+ const origin = list.get("origin");
12
+ const host = origin && URL.canParse(origin) ? new URL(origin).host : void 0;
13
+ const isAllowed = host !== void 0 && allowed.some((pattern) => pattern.startsWith("*.") ? host.endsWith(pattern.slice(1)) && host.length > pattern.length - 1 : host === pattern);
14
+ const site = list.get("sec-fetch-site");
15
+ if (!isAllowed || fetchSite !== false && site !== null && site !== "same-origin") throw errorCreate({ code: "FORBIDDEN", message: "Request origin is not allowed" });
16
+ return call.next();
17
+ }
18
+ };
19
+ };
20
+
21
+ export { securityOrigin };
@@ -0,0 +1,9 @@
1
+ declare const redactValue: (props: Readonly<{
2
+ value: unknown;
3
+ keys?: RegExp;
4
+ mask?: string;
5
+ depth?: number;
6
+ array?: number;
7
+ }>) => unknown;
8
+
9
+ export { redactValue };
@@ -0,0 +1,15 @@
1
+ // src/security/redact.ts
2
+ var redactValue = (props) => {
3
+ const { value, keys, mask, depth, array } = props;
4
+ const pattern = keys ?? /secret|password|passcode|token|key|seed|credential|cookie|authorization|session/i;
5
+ const walk = (item, level) => {
6
+ if (typeof item === "string") return item.replace(/[\r\n]+/g, " ");
7
+ if (typeof item !== "object" || item === null || item instanceof Date) return item;
8
+ if (level >= (depth ?? 5)) return "[depth]";
9
+ if (Array.isArray(item)) return item.slice(0, array ?? 50).map((child) => walk(child, level + 1));
10
+ return Object.fromEntries(Object.entries(item).map(([key, child]) => [key, pattern.test(key) ? mask ?? "\u2022\u2022\u2022\u2022" : walk(child, level + 1)]));
11
+ };
12
+ return walk(value, 0);
13
+ };
14
+
15
+ export { redactValue };
@@ -0,0 +1,6 @@
1
+ declare const secretEqual: (props: Readonly<{
2
+ a: string;
3
+ b: string;
4
+ }>) => Promise<boolean>;
5
+
6
+ export { secretEqual };
@@ -0,0 +1,13 @@
1
+ // src/security/secret.ts
2
+ var secretEqual = async (props) => {
3
+ const { a, b } = props;
4
+ const encoder = new TextEncoder();
5
+ const [left, right] = await Promise.all([crypto.subtle.digest("SHA-256", encoder.encode(a)), crypto.subtle.digest("SHA-256", encoder.encode(b))]);
6
+ const x = new Uint8Array(left);
7
+ const y = new Uint8Array(right);
8
+ let difference = 0;
9
+ for (let index = 0; index < x.length; index++) difference |= x[index] ^ y[index];
10
+ return difference === 0;
11
+ };
12
+
13
+ export { secretEqual };
package/dist/spec.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export { e as TError, f as TErrorCode, g as TErrorDefinition, h as TErrorFactories, i as TErrorIssue, j as TErrorMap, k as TErrorPhase, l as TErrorUnion, T as TSchema, a as TSchemaInput, b as TSchemaIssue, c as TSchemaOutput, d as TSchemaResult } from './index-CuAEDv-H.js';
2
+ export { T as TMiddleware, a as TMiddlewareProps, b as TMiddlewareResult, c as TMiddlewareShape, d as TPlugin } from './index-DV3R2g7H.js';
3
+ export { T as TResponse, a as TResponseApply, b as TResponseInfo, c as TResponseLambda } from './index-DJ2Ox9am.js';
4
+ export { T as TLock, a as TLockLease, b as TPostgresClient, c as TRedisClient } from './index-C3Ra6AYj.js';
5
+ export { T as TKv } from './index-BSA9a_EW.js';
6
+ export { T as TGateCheck, a as TPluginCall, b as TPluginRead, c as TPluginShape, d as TQueue, e as TRateLimiter, f as TTelemetrySpan } from './index-CZFS0TSh.js';
package/dist/spec.js ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,11 @@
1
+ import { d as TPlugin } from '../index-DV3R2g7H.js';
2
+ import { f as TTelemetrySpan, c as TPluginShape } from '../index-CZFS0TSh.js';
3
+ import '../index-CuAEDv-H.js';
4
+
5
+ declare const telemetryOtel: (props: Readonly<{
6
+ tracer: {
7
+ startActiveSpan: <F extends (span: TTelemetrySpan) => unknown>(name: string, fn: F) => ReturnType<F>;
8
+ };
9
+ }>) => TPlugin<TPluginShape<object>>;
10
+
11
+ export { telemetryOtel };
@@ -0,0 +1,25 @@
1
+ // src/telemetry/otel.ts
2
+ var telemetryOtel = (props) => {
3
+ const { tracer } = props;
4
+ return {
5
+ name: "telemetry:otel",
6
+ version: 1,
7
+ run: async (call) => tracer.startActiveSpan(`action ${String(call.meta.name ?? "anonymous")}`, async (span) => {
8
+ try {
9
+ const result = await call.next();
10
+ span.setAttribute("action.ok", result.ok);
11
+ if (!result.ok) {
12
+ span.setAttribute("action.error.code", result.error.code);
13
+ span.setAttribute("action.correlation_id", result.error.correlationId ?? "");
14
+ span.recordException(result.error);
15
+ span.setStatus({ code: 2, message: result.error.code });
16
+ }
17
+ return result;
18
+ } finally {
19
+ span.end();
20
+ }
21
+ })
22
+ };
23
+ };
24
+
25
+ export { telemetryOtel };
@@ -0,0 +1,12 @@
1
+ import { d as TPlugin } from '../index-DV3R2g7H.js';
2
+ import { c as TPluginShape } from '../index-CZFS0TSh.js';
3
+ import '../index-CuAEDv-H.js';
4
+
5
+ declare const telemetryPino: (props: Readonly<{
6
+ logger: {
7
+ info: (object: object, message: string) => void;
8
+ error: (object: object, message: string) => void;
9
+ };
10
+ }>) => TPlugin<TPluginShape<object>>;
11
+
12
+ export { telemetryPino };
@@ -0,0 +1,18 @@
1
+ // src/telemetry/pino.ts
2
+ var telemetryPino = (props) => {
3
+ const { logger } = props;
4
+ return {
5
+ name: "telemetry:pino",
6
+ version: 1,
7
+ run: async (call) => {
8
+ const startedAt = Date.now();
9
+ const result = await call.next();
10
+ const line = { action: call.meta.name ?? "anonymous", ok: result.ok, durationMs: Date.now() - startedAt };
11
+ if (result.ok) logger.info(line, "action ok");
12
+ else logger.error({ ...line, code: result.error.code, correlationId: result.error.correlationId }, "action failed");
13
+ return result;
14
+ }
15
+ };
16
+ };
17
+
18
+ export { telemetryPino };
@@ -0,0 +1,16 @@
1
+ import { d as TPlugin } from '../index-DV3R2g7H.js';
2
+ import { c as TPluginShape } from '../index-CZFS0TSh.js';
3
+ import '../index-CuAEDv-H.js';
4
+
5
+ declare const telemetrySentry: (props: Readonly<{
6
+ sentry: {
7
+ withServerActionInstrumentation: <T>(name: string, options: {
8
+ headers?: Headers;
9
+ recordResponse?: boolean;
10
+ }, callback: () => Promise<T>) => Promise<T>;
11
+ };
12
+ headers?: () => Headers | Promise<Headers>;
13
+ recordResponse?: boolean;
14
+ }>) => TPlugin<TPluginShape<object>>;
15
+
16
+ export { telemetrySentry };
@@ -0,0 +1,11 @@
1
+ // src/telemetry/sentry.ts
2
+ var telemetrySentry = (props) => {
3
+ const { sentry, headers, recordResponse } = props;
4
+ return {
5
+ name: "telemetry:sentry",
6
+ version: 1,
7
+ run: async (call) => sentry.withServerActionInstrumentation(String(call.meta.name ?? "action"), { headers: headers ? await headers() : void 0, recordResponse: recordResponse ?? false }, () => call.next())
8
+ };
9
+ };
10
+
11
+ export { telemetrySentry };