@bitakit/better-auth 0.2.5 → 0.3.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.
- package/AGENTS.md +66 -2
- package/README.md +2 -0
- package/dist/access.d.ts +70 -0
- package/dist/access.js +97 -0
- package/dist/client.d.ts +15 -12
- package/dist/client.js +9 -4
- package/dist/domain-policy.d.ts +34 -0
- package/dist/domain-policy.js +76 -0
- package/dist/guard.d.ts +171 -0
- package/dist/guard.js +286 -0
- package/dist/organization-session.js +19 -0
- package/dist/organizations.d.ts +45 -2
- package/dist/organizations.js +99 -6
- package/dist/security-policy.d.ts +15 -0
- package/dist/security-policy.js +36 -0
- package/dist/server.d.ts +756 -0
- package/dist/server.js +46 -0
- package/package.json +18 -9
package/dist/server.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { organization } from 'better-auth/plugins/organization';
|
|
2
|
+
import { betterAuthAccess } from './access.js';
|
|
3
|
+
import { membershipGuard } from './guard.js';
|
|
4
|
+
export { membershipGuard, membershipGuardErrors } from './guard.js';
|
|
5
|
+
export { anyDomain, invitationPolicyAllows, invitationPolicyView, normalizeDomain, parseInvitationPolicy, storedInvitationPolicy, InvitationPolicyError, } from './domain-policy.js';
|
|
6
|
+
export { defaultSecurityPolicy, parseSecurityPolicy, securityPolicyMet, storedSecurityPolicy, SecurityPolicyError, } from './security-policy.js';
|
|
7
|
+
/** Organization options BitaKit derives from `accessConfiguration`; the app must not set them. */
|
|
8
|
+
const derived = ['ac', 'roles', 'creatorRole', 'dynamicAccessControl'];
|
|
9
|
+
/**
|
|
10
|
+
* Better Auth's server `organization` plugin for a BitaKit app: the roles and permissions from the
|
|
11
|
+
* generated `accessConfiguration`, and the membership guard (role ceiling, invitation re-validation,
|
|
12
|
+
* invitation domain policy, the stored security policy) installed in the same plugin, so it cannot be left out. Every other
|
|
13
|
+
* organization option (invitation e-mail, hooks, teams, limits) is the app's, unchanged.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* betterAuth({ plugins: [createOrganizationPlugin(accessConfiguration, { sendInvitationEmail })] });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function createOrganizationPlugin(configuration, options = {}) {
|
|
20
|
+
const conflicting = derived.filter((key) => key in options);
|
|
21
|
+
if (conflicting.length)
|
|
22
|
+
throw new Error(`createOrganizationPlugin: ${conflicting.join(', ')} come from the app's roles and permissions (src/roles.ts, permissions.ts); remove them from the organization options.`);
|
|
23
|
+
const access = betterAuthAccess(configuration);
|
|
24
|
+
const base = organization({ ...options, ...access.organization });
|
|
25
|
+
const guard = membershipGuard(access, {
|
|
26
|
+
requireEmailVerificationOnInvitation: options.requireEmailVerificationOnInvitation,
|
|
27
|
+
});
|
|
28
|
+
// One plugin: Better Auth's organization plugin with the guard's field, hooks and endpoints.
|
|
29
|
+
const plugin = base;
|
|
30
|
+
const schema = (plugin.schema ?? {});
|
|
31
|
+
return {
|
|
32
|
+
...plugin,
|
|
33
|
+
schema: {
|
|
34
|
+
...schema,
|
|
35
|
+
organization: {
|
|
36
|
+
...schema.organization,
|
|
37
|
+
fields: { ...schema.organization?.fields, ...guard.schema.organization.fields },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
hooks: {
|
|
41
|
+
...plugin.hooks,
|
|
42
|
+
before: [...(plugin.hooks?.before ?? []), ...guard.hooks.before],
|
|
43
|
+
},
|
|
44
|
+
endpoints: { ...base.endpoints, ...guard.endpoints },
|
|
45
|
+
};
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitakit/better-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bitakit": {
|
|
6
6
|
"plugin": "./plugin",
|
|
@@ -22,6 +22,14 @@
|
|
|
22
22
|
"types": "./dist/plugin.d.ts",
|
|
23
23
|
"default": "./dist/plugin.js"
|
|
24
24
|
},
|
|
25
|
+
"./access": {
|
|
26
|
+
"types": "./dist/access.d.ts",
|
|
27
|
+
"default": "./dist/access.js"
|
|
28
|
+
},
|
|
29
|
+
"./server": {
|
|
30
|
+
"types": "./dist/server.d.ts",
|
|
31
|
+
"default": "./dist/server.js"
|
|
32
|
+
},
|
|
25
33
|
"./organizations": {
|
|
26
34
|
"types": "./dist/organizations.d.ts",
|
|
27
35
|
"default": "./dist/organizations.js"
|
|
@@ -41,20 +49,21 @@
|
|
|
41
49
|
"test": "npm run build && node --test tests/*.test.mjs"
|
|
42
50
|
},
|
|
43
51
|
"dependencies": {
|
|
44
|
-
"@
|
|
45
|
-
"@
|
|
52
|
+
"@better-auth/api-key": "^1.7.5",
|
|
53
|
+
"@bitakit/core": "^0.3.0"
|
|
46
54
|
},
|
|
47
55
|
"peerDependencies": {
|
|
56
|
+
"@bitakit/email": "^0.3.0",
|
|
57
|
+
"@bitakit/organizations": "^0.3.1",
|
|
48
58
|
"better-auth": "^1.7.5",
|
|
49
|
-
"react": "^19.0.0"
|
|
50
|
-
"@bitakit/organizations": "^0.2.2",
|
|
51
|
-
"@bitakit/email": "^0.2.2"
|
|
59
|
+
"react": "^19.0.0"
|
|
52
60
|
},
|
|
53
61
|
"devDependencies": {
|
|
54
|
-
"
|
|
62
|
+
"@bitakit/email": "^0.3.0",
|
|
63
|
+
"@bitakit/organizations": "^0.3.1",
|
|
64
|
+
"@types/node": "^24.19.2",
|
|
55
65
|
"@types/react": "^19",
|
|
56
|
-
"
|
|
57
|
-
"@bitakit/email": "^0.2.2"
|
|
66
|
+
"typescript": "^5"
|
|
58
67
|
},
|
|
59
68
|
"peerDependenciesMeta": {
|
|
60
69
|
"better-auth": {
|