better-auth 0.2.3-beta.7 → 0.2.3
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/dist/access.js +125 -1
- package/dist/adapters.js +1156 -14
- package/dist/api.js +2458 -4
- package/dist/cli.js +1010 -3
- package/dist/client/plugins.js +527 -2
- package/dist/client.js +382 -1
- package/dist/index.js +3670 -5
- package/dist/next-js.js +34 -1
- package/dist/node.js +8 -1
- package/dist/plugins.js +5529 -4
- package/dist/react.js +393 -1
- package/dist/social.js +586 -2
- package/dist/solid-start.js +13 -1
- package/dist/solid.js +389 -1
- package/dist/svelte-kit.js +34 -1
- package/dist/svelte.js +380 -1
- package/dist/utils.js +453 -2
- package/dist/vue.js +389 -1
- package/package.json +5 -3
package/dist/access.js
CHANGED
|
@@ -1 +1,125 @@
|
|
|
1
|
-
|
|
1
|
+
// src/plugins/organization/access/src/access.ts
|
|
2
|
+
var ParsingError = class extends Error {
|
|
3
|
+
path;
|
|
4
|
+
constructor(message, path) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.path = path;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
var AccessControl = class {
|
|
10
|
+
constructor(s) {
|
|
11
|
+
this.s = s;
|
|
12
|
+
this.statements = s;
|
|
13
|
+
}
|
|
14
|
+
statements;
|
|
15
|
+
newRole(statements) {
|
|
16
|
+
return new Role(statements);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var Role = class _Role {
|
|
20
|
+
statements;
|
|
21
|
+
constructor(statements) {
|
|
22
|
+
this.statements = statements;
|
|
23
|
+
}
|
|
24
|
+
authorize(request, connector) {
|
|
25
|
+
for (const [requestedResource, requestedActions] of Object.entries(
|
|
26
|
+
request
|
|
27
|
+
)) {
|
|
28
|
+
const allowedActions = this.statements[requestedResource];
|
|
29
|
+
if (!allowedActions) {
|
|
30
|
+
return {
|
|
31
|
+
success: false,
|
|
32
|
+
error: `You are not allowed to access resource: ${requestedResource}`
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const success = connector === "OR" ? requestedActions.some(
|
|
36
|
+
(requestedAction) => allowedActions.includes(requestedAction)
|
|
37
|
+
) : requestedActions.every(
|
|
38
|
+
(requestedAction) => allowedActions.includes(requestedAction)
|
|
39
|
+
);
|
|
40
|
+
if (success) {
|
|
41
|
+
return { success };
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
success: false,
|
|
45
|
+
error: `unauthorized to access resource "${requestedResource}"`
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
error: "Not authorized"
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
static fromString(s) {
|
|
54
|
+
const statements = JSON.parse(s);
|
|
55
|
+
if (typeof statements !== "object") {
|
|
56
|
+
throw new ParsingError("statements is not an object", ".");
|
|
57
|
+
}
|
|
58
|
+
for (const [resource, actions] of Object.entries(statements)) {
|
|
59
|
+
if (typeof resource !== "string") {
|
|
60
|
+
throw new ParsingError("invalid resource identifier", resource);
|
|
61
|
+
}
|
|
62
|
+
if (!Array.isArray(actions)) {
|
|
63
|
+
throw new ParsingError("actions is not an array", resource);
|
|
64
|
+
}
|
|
65
|
+
for (let i = 0; i < actions.length; i++) {
|
|
66
|
+
if (typeof actions[i] !== "string") {
|
|
67
|
+
throw new ParsingError("action is not a string", `${resource}[${i}]`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return new _Role(statements);
|
|
72
|
+
}
|
|
73
|
+
toString() {
|
|
74
|
+
return JSON.stringify(this.statements);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/plugins/organization/access/statement.ts
|
|
79
|
+
var createAccessControl = (statements) => {
|
|
80
|
+
return new AccessControl(statements);
|
|
81
|
+
};
|
|
82
|
+
var defaultStatements = {
|
|
83
|
+
organization: ["update", "delete"],
|
|
84
|
+
member: ["create", "update", "delete"],
|
|
85
|
+
invitation: ["create", "cancel"]
|
|
86
|
+
};
|
|
87
|
+
var defaultAc = createAccessControl(defaultStatements);
|
|
88
|
+
var adminAc = defaultAc.newRole({
|
|
89
|
+
organization: ["update"],
|
|
90
|
+
invitation: ["create", "cancel"],
|
|
91
|
+
member: ["create", "update", "delete"]
|
|
92
|
+
});
|
|
93
|
+
var ownerAc = defaultAc.newRole({
|
|
94
|
+
organization: ["update", "delete"],
|
|
95
|
+
member: ["create", "update", "delete"],
|
|
96
|
+
invitation: ["create", "cancel"]
|
|
97
|
+
});
|
|
98
|
+
var memberAc = defaultAc.newRole({
|
|
99
|
+
organization: [],
|
|
100
|
+
member: [],
|
|
101
|
+
invitation: []
|
|
102
|
+
});
|
|
103
|
+
var defaultRoles = {
|
|
104
|
+
admin: adminAc,
|
|
105
|
+
owner: ownerAc,
|
|
106
|
+
member: memberAc
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/plugins/organization/access/utils.ts
|
|
110
|
+
var permissionFromString = (permission) => {
|
|
111
|
+
return Role.fromString(permission ?? "");
|
|
112
|
+
};
|
|
113
|
+
export {
|
|
114
|
+
AccessControl,
|
|
115
|
+
ParsingError,
|
|
116
|
+
Role,
|
|
117
|
+
adminAc,
|
|
118
|
+
createAccessControl,
|
|
119
|
+
defaultAc,
|
|
120
|
+
defaultRoles,
|
|
121
|
+
defaultStatements,
|
|
122
|
+
memberAc,
|
|
123
|
+
ownerAc,
|
|
124
|
+
permissionFromString
|
|
125
|
+
};
|