@checodo/better-auth-audit-log 0.0.0-stage → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @checodo/better-auth-audit-log
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5f427b0: First release: an audit log of sign-ins, failed sign-ins, account changes, and admin actions. Users see their own history, admins everyone's.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Clas Heinemeyer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,50 @@
1
- # Temporary Holding Version
1
+ # @checodo/better-auth-audit-log
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An audit log for [better-auth](https://better-auth.com): sign-ins, failed sign-ins, account changes, admin and organization actions, with retention and an optional hash chain.
4
+
5
+ A community plugin, not made by the better-auth team. It looks and works
6
+ like better-auth's own plugins: a server plugin, a typed client plugin,
7
+ error codes, and database tables.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @checodo/better-auth-audit-log
13
+ ```
14
+
15
+ Requires `better-auth` and `@better-auth/core` 1.7.20 or a later 1.x
16
+ release (peer dependencies). ESM only.
17
+
18
+ ## Usage
19
+
20
+ ```ts
21
+ // auth.ts
22
+ import { betterAuth } from "better-auth";
23
+ import { auditLog } from "@checodo/better-auth-audit-log";
24
+
25
+ export const auth = betterAuth({
26
+ plugins: [
27
+ // last, after the other plugins
28
+ auditLog({ retention: { days: 180 } }),
29
+ ],
30
+ });
31
+ ```
32
+
33
+ ```ts
34
+ // auth-client.ts
35
+ import { createAuthClient } from "better-auth/client";
36
+ import { auditLogClient } from "@checodo/better-auth-audit-log/client";
37
+
38
+ export const authClient = createAuthClient({ plugins: [auditLogClient()] });
39
+ ```
40
+
41
+ Create the plugin's tables with the better-auth CLI:
42
+
43
+ ```bash
44
+ npx auth@latest migrate
45
+ ```
46
+
47
+ ## Documentation
48
+
49
+ Every option, endpoint, error code, and table:
50
+ [docs](https://github.com/checodo/better-auth-plugins/blob/main/apps/docs/content/docs/audit-log.mdx).
@@ -0,0 +1,33 @@
1
+ import { i as AUDIT_LOG_ERROR_CODES, t as AuditLogPlugin } from "./index-e6JB3Yiu.js";
2
+ /**
3
+ * Client companion to `auditLog()`. Adds `authClient.auditLog.listEvents`,
4
+ * typed from the server plugin: the signed-in user's own events, or any
5
+ * user's for admins.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { createAuthClient } from "better-auth/client";
10
+ * import { auditLogClient } from "@checodo/better-auth-audit-log/client";
11
+ *
12
+ * export const authClient = createAuthClient({
13
+ * plugins: [auditLogClient()],
14
+ * });
15
+ *
16
+ * const { data } = await authClient.auditLog.listEvents({ query: { type: "sign-in" } });
17
+ * ```
18
+ */
19
+ export declare const auditLogClient: () => {
20
+ id: "audit-log";
21
+ $InferServerPlugin: AuditLogPlugin;
22
+ pathMethods: {
23
+ "/audit-log/list-events": "GET";
24
+ };
25
+ $ERROR_CODES: {
26
+ YOU_ARE_NOT_ALLOWED_TO_LIST_OTHER_USERS_EVENTS: import("better-auth").RawError<"YOU_ARE_NOT_ALLOWED_TO_LIST_OTHER_USERS_EVENTS">;
27
+ METADATA_TOO_LARGE: import("better-auth").RawError<"METADATA_TOO_LARGE">;
28
+ RETENTION_NOT_CONFIGURED: import("better-auth").RawError<"RETENTION_NOT_CONFIGURED">;
29
+ HASH_CHAIN_NOT_ENABLED: import("better-auth").RawError<"HASH_CHAIN_NOT_ENABLED">;
30
+ };
31
+ };
32
+ export { AUDIT_LOG_ERROR_CODES };
33
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;;;;;;;;;;;;;;qBAqBa;;EAGiB,oBAAA"}
package/dist/client.js ADDED
@@ -0,0 +1,30 @@
1
+ import { t as AUDIT_LOG_ERROR_CODES } from "./error-codes-B9Frh9bu.js";
2
+ // src/client.ts
3
+ /**
4
+ * Client companion to `auditLog()`. Adds `authClient.auditLog.listEvents`,
5
+ * typed from the server plugin: the signed-in user's own events, or any
6
+ * user's for admins.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { createAuthClient } from "better-auth/client";
11
+ * import { auditLogClient } from "@checodo/better-auth-audit-log/client";
12
+ *
13
+ * export const authClient = createAuthClient({
14
+ * plugins: [auditLogClient()],
15
+ * });
16
+ *
17
+ * const { data } = await authClient.auditLog.listEvents({ query: { type: "sign-in" } });
18
+ * ```
19
+ */
20
+ const auditLogClient = () => {
21
+ return {
22
+ id: "audit-log",
23
+ $InferServerPlugin: {},
24
+ pathMethods: { "/audit-log/list-events": "GET" },
25
+ $ERROR_CODES: AUDIT_LOG_ERROR_CODES
26
+ };
27
+ };
28
+ export { AUDIT_LOG_ERROR_CODES, auditLogClient };
29
+
30
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"better-auth/client\";\nimport { AUDIT_LOG_ERROR_CODES } from \"./error-codes\";\nimport type { AuditLogPlugin } from \"./index\";\n\n/**\n * Client companion to `auditLog()`. Adds `authClient.auditLog.listEvents`,\n * typed from the server plugin: the signed-in user's own events, or any\n * user's for admins.\n *\n * @example\n * ```ts\n * import { createAuthClient } from \"better-auth/client\";\n * import { auditLogClient } from \"@checodo/better-auth-audit-log/client\";\n *\n * export const authClient = createAuthClient({\n * plugins: [auditLogClient()],\n * });\n *\n * const { data } = await authClient.auditLog.listEvents({ query: { type: \"sign-in\" } });\n * ```\n */\nexport const auditLogClient = () => {\n return {\n id: \"audit-log\",\n $InferServerPlugin: {} as AuditLogPlugin,\n pathMethods: {\n \"/audit-log/list-events\": \"GET\",\n },\n $ERROR_CODES: AUDIT_LOG_ERROR_CODES,\n } satisfies BetterAuthClientPlugin;\n};\n\nexport { AUDIT_LOG_ERROR_CODES } from \"./error-codes\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqBA,MAAa,uBAAuB;CAClC,OAAO;EACL,IAAI;EACJ,oBAAoB,CAAC;EACrB,aAAa,EACX,0BAA0B,MAC5B;EACA,cAAc;CAChB;AACF"}
@@ -0,0 +1,11 @@
1
+ import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
2
+ // src/error-codes.ts
3
+ const AUDIT_LOG_ERROR_CODES = defineErrorCodes({
4
+ YOU_ARE_NOT_ALLOWED_TO_LIST_OTHER_USERS_EVENTS: "You are not allowed to list the audit events of other users",
5
+ METADATA_TOO_LARGE: "The metadata is too large",
6
+ RETENTION_NOT_CONFIGURED: "Pass `days`, or configure the plugin's `retention` option",
7
+ HASH_CHAIN_NOT_ENABLED: "The plugin's `hashChain` option is off"
8
+ });
9
+ export { AUDIT_LOG_ERROR_CODES as t };
10
+
11
+ //# sourceMappingURL=error-codes-B9Frh9bu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-codes-B9Frh9bu.js","names":[],"sources":["../src/error-codes.ts"],"sourcesContent":["import { defineErrorCodes } from \"@better-auth/core/utils/error-codes\";\n\nexport const AUDIT_LOG_ERROR_CODES = defineErrorCodes({\n YOU_ARE_NOT_ALLOWED_TO_LIST_OTHER_USERS_EVENTS:\n \"You are not allowed to list the audit events of other users\",\n METADATA_TOO_LARGE: \"The metadata is too large\",\n RETENTION_NOT_CONFIGURED: \"Pass `days`, or configure the plugin's `retention` option\",\n HASH_CHAIN_NOT_ENABLED: \"The plugin's `hashChain` option is off\",\n});\n\nexport type AuditLogErrorCode = keyof typeof AUDIT_LOG_ERROR_CODES;\n"],"mappings":";;AAEA,MAAa,wBAAwB,iBAAiB;CACpD,gDACE;CACF,oBAAoB;CACpB,0BAA0B;CAC1B,wBAAwB;AAC1B,CAAC"}