@atlasent/sdk 1.5.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.
@@ -0,0 +1,109 @@
1
+ import { Context, ErrorHandler, MiddlewareHandler } from 'hono';
2
+ import { A as AtlaSentDeniedError, a as AtlaSentError } from './protect-BKxcoR_2.cjs';
3
+ export { P as Permit, b as ProtectRequest } from './protect-BKxcoR_2.cjs';
4
+
5
+ /**
6
+ * Hono middleware for AtlaSent execution-time authorization.
7
+ *
8
+ * ```ts
9
+ * import { Hono } from "hono";
10
+ * import { atlaSentGuard, atlaSentErrorHandler } from "@atlasent/sdk/hono";
11
+ *
12
+ * const app = new Hono();
13
+ *
14
+ * // One-line drop-in protection for a sensitive route.
15
+ * app.post(
16
+ * "/deploy",
17
+ * atlaSentGuard({
18
+ * action: "deploy_to_production",
19
+ * agent: (c) => c.req.header("x-agent-id") ?? "anonymous",
20
+ * context: async (c) => ({ commit: (await c.req.json()).commit }),
21
+ * }),
22
+ * (c) => {
23
+ * // If we got here, AtlaSent allowed the action end-to-end.
24
+ * const permit = c.get("atlasent");
25
+ * return c.json({ ok: true, permitId: permit.permitId });
26
+ * },
27
+ * );
28
+ *
29
+ * // One place to map AtlaSent errors to HTTP responses.
30
+ * app.onError(atlaSentErrorHandler());
31
+ * ```
32
+ *
33
+ * The guard calls {@link protect} under the hood — same fail-closed
34
+ * semantics. On allow, it stashes the {@link Permit} on the Hono
35
+ * context (default key: `"atlasent"`) and calls `next()`. On anything
36
+ * else, it **throws**: {@link AtlaSentDeniedError} for policy denials
37
+ * and verification failures, {@link AtlaSentError} for transport /
38
+ * auth / server failures. Attach {@link atlaSentErrorHandler} via
39
+ * `app.onError(...)` to turn those into HTTP responses once, at the
40
+ * app level, rather than wrap every guarded route.
41
+ *
42
+ * `hono` is an optional peer dependency — this module is only pulled
43
+ * in when you import from the `@atlasent/sdk/hono` subpath.
44
+ */
45
+
46
+ /** Resolver: a literal string, or a function deriving one from the request. */
47
+ type Resolver<T extends string | Record<string, unknown>> = T | ((c: Context) => T | Promise<T>);
48
+ /** Options for {@link atlaSentGuard}. */
49
+ interface AtlaSentGuardOptions {
50
+ /**
51
+ * Action being authorized (e.g. `"deploy_to_production"`). A string
52
+ * fixes the action; a function lets you derive it per-request (e.g.
53
+ * from route params or the HTTP verb).
54
+ */
55
+ action: Resolver<string>;
56
+ /**
57
+ * Agent identifier. A string fixes the caller; a function lets you
58
+ * read it from an auth header, JWT claim, session, etc.
59
+ */
60
+ agent: Resolver<string>;
61
+ /**
62
+ * Build the policy context dict for the decision. Defaults to `{}`.
63
+ * Receives the Hono context so you can reach into headers, body,
64
+ * route params, or previously-set middleware values.
65
+ */
66
+ context?: (c: Context) => Record<string, unknown> | Promise<Record<string, unknown>>;
67
+ /**
68
+ * Key used to stash the resulting {@link Permit} on the Hono
69
+ * context via `c.set(...)`. Callers read it back with
70
+ * `c.get(options.key)`. Default: `"atlasent"`.
71
+ */
72
+ key?: string;
73
+ }
74
+ /**
75
+ * Hono middleware that calls {@link protect} before the wrapped
76
+ * handler runs. On allow, stores the {@link Permit} on the context;
77
+ * on deny or error, throws. Use {@link atlaSentErrorHandler} with
78
+ * `app.onError(...)` to turn those throws into HTTP responses.
79
+ */
80
+ declare function atlaSentGuard(options: AtlaSentGuardOptions): MiddlewareHandler;
81
+ /** Options for {@link atlaSentErrorHandler}. */
82
+ interface AtlaSentErrorHandlerOptions {
83
+ /** HTTP status returned on policy denial. Default: 403. */
84
+ denyStatus?: 401 | 403 | 409 | 422;
85
+ /** HTTP status returned on transport / auth / server failure. Default: 503. */
86
+ errorStatus?: 502 | 503 | 500;
87
+ /**
88
+ * Hook to customize the JSON body returned on denial. Receives the
89
+ * error; must return a JSON-serializable object. Defaults to a
90
+ * minimal `{ error, decision, evaluationId, reason?, requestId? }`.
91
+ */
92
+ renderDeny?: (err: AtlaSentDeniedError) => Record<string, unknown>;
93
+ /** Hook for transport/auth/server errors. Defaults to `{ error, code, requestId? }`. */
94
+ renderError?: (err: AtlaSentError) => Record<string, unknown>;
95
+ }
96
+ /**
97
+ * Hono error handler that converts AtlaSent exceptions into
98
+ * appropriate HTTP responses. Install once at the app level:
99
+ *
100
+ * ```ts
101
+ * app.onError(atlaSentErrorHandler());
102
+ * ```
103
+ *
104
+ * Non-AtlaSent errors re-throw so other `onError` chains (or Hono's
105
+ * default 500 handler) still see them.
106
+ */
107
+ declare function atlaSentErrorHandler(options?: AtlaSentErrorHandlerOptions): ErrorHandler;
108
+
109
+ export { AtlaSentDeniedError, AtlaSentError, type AtlaSentErrorHandlerOptions, type AtlaSentGuardOptions, atlaSentErrorHandler, atlaSentGuard };
package/dist/hono.d.ts ADDED
@@ -0,0 +1,109 @@
1
+ import { Context, ErrorHandler, MiddlewareHandler } from 'hono';
2
+ import { A as AtlaSentDeniedError, a as AtlaSentError } from './protect-BKxcoR_2.js';
3
+ export { P as Permit, b as ProtectRequest } from './protect-BKxcoR_2.js';
4
+
5
+ /**
6
+ * Hono middleware for AtlaSent execution-time authorization.
7
+ *
8
+ * ```ts
9
+ * import { Hono } from "hono";
10
+ * import { atlaSentGuard, atlaSentErrorHandler } from "@atlasent/sdk/hono";
11
+ *
12
+ * const app = new Hono();
13
+ *
14
+ * // One-line drop-in protection for a sensitive route.
15
+ * app.post(
16
+ * "/deploy",
17
+ * atlaSentGuard({
18
+ * action: "deploy_to_production",
19
+ * agent: (c) => c.req.header("x-agent-id") ?? "anonymous",
20
+ * context: async (c) => ({ commit: (await c.req.json()).commit }),
21
+ * }),
22
+ * (c) => {
23
+ * // If we got here, AtlaSent allowed the action end-to-end.
24
+ * const permit = c.get("atlasent");
25
+ * return c.json({ ok: true, permitId: permit.permitId });
26
+ * },
27
+ * );
28
+ *
29
+ * // One place to map AtlaSent errors to HTTP responses.
30
+ * app.onError(atlaSentErrorHandler());
31
+ * ```
32
+ *
33
+ * The guard calls {@link protect} under the hood — same fail-closed
34
+ * semantics. On allow, it stashes the {@link Permit} on the Hono
35
+ * context (default key: `"atlasent"`) and calls `next()`. On anything
36
+ * else, it **throws**: {@link AtlaSentDeniedError} for policy denials
37
+ * and verification failures, {@link AtlaSentError} for transport /
38
+ * auth / server failures. Attach {@link atlaSentErrorHandler} via
39
+ * `app.onError(...)` to turn those into HTTP responses once, at the
40
+ * app level, rather than wrap every guarded route.
41
+ *
42
+ * `hono` is an optional peer dependency — this module is only pulled
43
+ * in when you import from the `@atlasent/sdk/hono` subpath.
44
+ */
45
+
46
+ /** Resolver: a literal string, or a function deriving one from the request. */
47
+ type Resolver<T extends string | Record<string, unknown>> = T | ((c: Context) => T | Promise<T>);
48
+ /** Options for {@link atlaSentGuard}. */
49
+ interface AtlaSentGuardOptions {
50
+ /**
51
+ * Action being authorized (e.g. `"deploy_to_production"`). A string
52
+ * fixes the action; a function lets you derive it per-request (e.g.
53
+ * from route params or the HTTP verb).
54
+ */
55
+ action: Resolver<string>;
56
+ /**
57
+ * Agent identifier. A string fixes the caller; a function lets you
58
+ * read it from an auth header, JWT claim, session, etc.
59
+ */
60
+ agent: Resolver<string>;
61
+ /**
62
+ * Build the policy context dict for the decision. Defaults to `{}`.
63
+ * Receives the Hono context so you can reach into headers, body,
64
+ * route params, or previously-set middleware values.
65
+ */
66
+ context?: (c: Context) => Record<string, unknown> | Promise<Record<string, unknown>>;
67
+ /**
68
+ * Key used to stash the resulting {@link Permit} on the Hono
69
+ * context via `c.set(...)`. Callers read it back with
70
+ * `c.get(options.key)`. Default: `"atlasent"`.
71
+ */
72
+ key?: string;
73
+ }
74
+ /**
75
+ * Hono middleware that calls {@link protect} before the wrapped
76
+ * handler runs. On allow, stores the {@link Permit} on the context;
77
+ * on deny or error, throws. Use {@link atlaSentErrorHandler} with
78
+ * `app.onError(...)` to turn those throws into HTTP responses.
79
+ */
80
+ declare function atlaSentGuard(options: AtlaSentGuardOptions): MiddlewareHandler;
81
+ /** Options for {@link atlaSentErrorHandler}. */
82
+ interface AtlaSentErrorHandlerOptions {
83
+ /** HTTP status returned on policy denial. Default: 403. */
84
+ denyStatus?: 401 | 403 | 409 | 422;
85
+ /** HTTP status returned on transport / auth / server failure. Default: 503. */
86
+ errorStatus?: 502 | 503 | 500;
87
+ /**
88
+ * Hook to customize the JSON body returned on denial. Receives the
89
+ * error; must return a JSON-serializable object. Defaults to a
90
+ * minimal `{ error, decision, evaluationId, reason?, requestId? }`.
91
+ */
92
+ renderDeny?: (err: AtlaSentDeniedError) => Record<string, unknown>;
93
+ /** Hook for transport/auth/server errors. Defaults to `{ error, code, requestId? }`. */
94
+ renderError?: (err: AtlaSentError) => Record<string, unknown>;
95
+ }
96
+ /**
97
+ * Hono error handler that converts AtlaSent exceptions into
98
+ * appropriate HTTP responses. Install once at the app level:
99
+ *
100
+ * ```ts
101
+ * app.onError(atlaSentErrorHandler());
102
+ * ```
103
+ *
104
+ * Non-AtlaSent errors re-throw so other `onError` chains (or Hono's
105
+ * default 500 handler) still see them.
106
+ */
107
+ declare function atlaSentErrorHandler(options?: AtlaSentErrorHandlerOptions): ErrorHandler;
108
+
109
+ export { AtlaSentDeniedError, AtlaSentError, type AtlaSentErrorHandlerOptions, type AtlaSentGuardOptions, atlaSentErrorHandler, atlaSentGuard };