@headless-lms/adapter-auth 0.3.1 → 0.4.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.
@@ -1,4 +1,3 @@
1
- import { AccessScope } from "@headless-lms/core/organizations";
2
1
  import { AccessTokenAuthorization } from "better-auth/oauth2";
3
2
  import { AccessGrant } from "@headless-lms/core/types";
4
3
  //#region src/access-grant.d.ts
@@ -8,8 +7,7 @@ declare function grantFromClaims(claims: Record<string, unknown>): AccessGrant |
8
7
  declare function needsOrgChoice(activeOrgId: string | null, memberOrgIds: () => Promise<readonly string[]>): Promise<boolean>;
9
8
  declare function consentOrgId(activeOrgId: string | null, memberOrgIds: () => Promise<readonly string[]>): Promise<string | null>;
10
9
  declare function orgIdFromMetadata(metadata: unknown): string | null;
11
- declare function scopesToPermissions(scopes: string[]): Record<string, string[]>;
12
- declare function permissionsToScopes(permissions: unknown): AccessScope[];
10
+ declare function roleFromMetadata(metadata: unknown): string | null;
13
11
  //#endregion
14
- export { accessTokenAuthorization, consentOrgId, grantFromClaims, isCompactJws, needsOrgChoice, orgIdFromMetadata, permissionsToScopes, scopesToPermissions };
12
+ export { accessTokenAuthorization, consentOrgId, grantFromClaims, isCompactJws, needsOrgChoice, orgIdFromMetadata, roleFromMetadata };
15
13
  //# sourceMappingURL=access-grant.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { ORG_CLAIM } from "@headless-lms/core/identity";
2
- import { ACCESS_SCOPES, isAccessScope } from "@headless-lms/core/organizations";
2
+ import { isPermission } from "@headless-lms/core/organizations";
3
3
  import { parseAccessTokenAuthorization } from "better-auth/oauth2";
4
4
  //#region src/access-grant.ts
5
5
  function accessTokenAuthorization(header) {
@@ -21,7 +21,7 @@ function grantFromClaims(claims) {
21
21
  userId,
22
22
  clientId,
23
23
  orgId,
24
- scopes: typeof claims.scope === "string" ? claims.scope.split(" ").filter(isAccessScope) : []
24
+ limit: { scopes: typeof claims.scope === "string" ? claims.scope.split(" ").filter(isPermission) : [] }
25
25
  };
26
26
  }
27
27
  async function needsOrgChoice(activeOrgId, memberOrgIds) {
@@ -31,32 +31,23 @@ async function needsOrgChoice(activeOrgId, memberOrgIds) {
31
31
  async function consentOrgId(activeOrgId, memberOrgIds) {
32
32
  return activeOrgId !== null && !await needsOrgChoice(activeOrgId, memberOrgIds) ? activeOrgId : null;
33
33
  }
34
- function orgIdFromMetadata(metadata) {
34
+ function metadataField(metadata, field) {
35
35
  let value = metadata;
36
36
  if (typeof value === "string") try {
37
37
  value = JSON.parse(value);
38
38
  } catch {
39
39
  return null;
40
40
  }
41
- const orgId = value?.organizationId;
42
- return typeof orgId === "string" ? orgId : null;
43
- }
44
- function scopesToPermissions(scopes) {
45
- const permissions = {};
46
- for (const scope of new Set(scopes.filter(isAccessScope))) {
47
- const separator = scope.indexOf(":");
48
- const resource = scope.slice(0, separator);
49
- permissions[resource] = [...permissions[resource] ?? [], scope.slice(separator + 1)];
50
- }
51
- return permissions;
41
+ const found = value?.[field];
42
+ return typeof found === "string" && found.length > 0 ? found : null;
43
+ }
44
+ function orgIdFromMetadata(metadata) {
45
+ return metadataField(metadata, "organizationId");
52
46
  }
53
- function permissionsToScopes(permissions) {
54
- if (permissions === null || typeof permissions !== "object") return [];
55
- const granted = /* @__PURE__ */ new Set();
56
- for (const [resource, actions] of Object.entries(permissions)) if (Array.isArray(actions)) for (const action of actions) granted.add(`${resource}:${String(action)}`);
57
- return ACCESS_SCOPES.filter((scope) => granted.has(scope));
47
+ function roleFromMetadata(metadata) {
48
+ return metadataField(metadata, "role");
58
49
  }
59
50
  //#endregion
60
- export { accessTokenAuthorization, consentOrgId, grantFromClaims, isCompactJws, needsOrgChoice, orgIdFromMetadata, permissionsToScopes, scopesToPermissions };
51
+ export { accessTokenAuthorization, consentOrgId, grantFromClaims, isCompactJws, needsOrgChoice, orgIdFromMetadata, roleFromMetadata };
61
52
 
62
53
  //# sourceMappingURL=access-grant.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"access-grant.js","names":[],"sources":["../src/access-grant.ts"],"sourcesContent":["import type { AccessGrant } from \"@headless-lms/core/types\";\nimport { ORG_CLAIM } from \"@headless-lms/core/identity\";\nimport { ACCESS_SCOPES, type AccessScope, isAccessScope } from \"@headless-lms/core/organizations\";\nimport { type AccessTokenAuthorization, parseAccessTokenAuthorization } from \"better-auth/oauth2\";\n\nexport function accessTokenAuthorization(\n header: string | string[] | undefined,\n): AccessTokenAuthorization | null {\n if (typeof header !== \"string\") {\n return null;\n }\n const authorization = parseAccessTokenAuthorization(header);\n if (!authorization?.token || authorization.scheme === \"Unknown\") {\n return null;\n }\n return authorization;\n}\n\nexport function isCompactJws(token: string): boolean {\n const parts = token.split(\".\");\n return parts.length === 3 && parts.every((part) => part.length > 0);\n}\n\nexport function grantFromClaims(claims: Record<string, unknown>): AccessGrant | null {\n const userId = claims.sub;\n const clientId = claims.client_id ?? claims.azp;\n const orgId = claims[ORG_CLAIM];\n if (typeof userId !== \"string\" || typeof clientId !== \"string\" || typeof orgId !== \"string\") {\n return null;\n }\n const scopes =\n typeof claims.scope === \"string\" ? claims.scope.split(\" \").filter(isAccessScope) : [];\n return { userId, clientId, orgId, scopes };\n}\n\nexport async function needsOrgChoice(\n activeOrgId: string | null,\n memberOrgIds: () => Promise<readonly string[]>,\n): Promise<boolean> {\n if (activeOrgId === null) {\n return true;\n }\n return !(await memberOrgIds()).includes(activeOrgId);\n}\n\nexport async function consentOrgId(\n activeOrgId: string | null,\n memberOrgIds: () => Promise<readonly string[]>,\n): Promise<string | null> {\n return activeOrgId !== null && !(await needsOrgChoice(activeOrgId, memberOrgIds))\n ? activeOrgId\n : null;\n}\n\nexport function orgIdFromMetadata(metadata: unknown): string | null {\n let value = metadata;\n if (typeof value === \"string\") {\n try {\n value = JSON.parse(value);\n } catch {\n return null;\n }\n }\n const orgId = (value as { organizationId?: unknown } | null)?.organizationId;\n return typeof orgId === \"string\" ? orgId : null;\n}\n\nexport function scopesToPermissions(scopes: string[]): Record<string, string[]> {\n const permissions: Record<string, string[]> = {};\n for (const scope of new Set(scopes.filter(isAccessScope))) {\n const separator = scope.indexOf(\":\");\n const resource = scope.slice(0, separator);\n permissions[resource] = [...(permissions[resource] ?? []), scope.slice(separator + 1)];\n }\n return permissions;\n}\n\nexport function permissionsToScopes(permissions: unknown): AccessScope[] {\n if (permissions === null || typeof permissions !== \"object\") {\n return [];\n }\n const granted = new Set<string>();\n for (const [resource, actions] of Object.entries(permissions)) {\n if (Array.isArray(actions)) {\n for (const action of actions) {\n granted.add(`${resource}:${String(action)}`);\n }\n }\n }\n return ACCESS_SCOPES.filter((scope) => granted.has(scope));\n}\n"],"mappings":";;;;AAKA,SAAgB,yBACd,QACiC;CACjC,IAAI,OAAO,WAAW,UACpB,OAAO;CAET,MAAM,gBAAgB,8BAA8B,MAAM;CAC1D,IAAI,CAAC,eAAe,SAAS,cAAc,WAAW,WACpD,OAAO;CAET,OAAO;AACT;AAEA,SAAgB,aAAa,OAAwB;CACnD,MAAM,QAAQ,MAAM,MAAM,GAAG;CAC7B,OAAO,MAAM,WAAW,KAAK,MAAM,OAAO,SAAS,KAAK,SAAS,CAAC;AACpE;AAEA,SAAgB,gBAAgB,QAAqD;CACnF,MAAM,SAAS,OAAO;CACtB,MAAM,WAAW,OAAO,aAAa,OAAO;CAC5C,MAAM,QAAQ,OAAO;CACrB,IAAI,OAAO,WAAW,YAAY,OAAO,aAAa,YAAY,OAAO,UAAU,UACjF,OAAO;CAIT,OAAO;EAAE;EAAQ;EAAU;EAAO,QADhC,OAAO,OAAO,UAAU,WAAW,OAAO,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,aAAa,IAAI,CAAC;CAC7C;AAC3C;AAEA,eAAsB,eACpB,aACA,cACkB;CAClB,IAAI,gBAAgB,MAClB,OAAO;CAET,OAAO,EAAE,MAAM,aAAa,EAAA,CAAG,SAAS,WAAW;AACrD;AAEA,eAAsB,aACpB,aACA,cACwB;CACxB,OAAO,gBAAgB,QAAQ,CAAE,MAAM,eAAe,aAAa,YAAY,IAC3E,cACA;AACN;AAEA,SAAgB,kBAAkB,UAAkC;CAClE,IAAI,QAAQ;CACZ,IAAI,OAAO,UAAU,UACnB,IAAI;EACF,QAAQ,KAAK,MAAM,KAAK;CAC1B,QAAQ;EACN,OAAO;CACT;CAEF,MAAM,QAAS,OAA+C;CAC9D,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAgB,oBAAoB,QAA4C;CAC9E,MAAM,cAAwC,CAAC;CAC/C,KAAK,MAAM,SAAS,IAAI,IAAI,OAAO,OAAO,aAAa,CAAC,GAAG;EACzD,MAAM,YAAY,MAAM,QAAQ,GAAG;EACnC,MAAM,WAAW,MAAM,MAAM,GAAG,SAAS;EACzC,YAAY,YAAY,CAAC,GAAI,YAAY,aAAa,CAAC,GAAI,MAAM,MAAM,YAAY,CAAC,CAAC;CACvF;CACA,OAAO;AACT;AAEA,SAAgB,oBAAoB,aAAqC;CACvE,IAAI,gBAAgB,QAAQ,OAAO,gBAAgB,UACjD,OAAO,CAAC;CAEV,MAAM,0BAAU,IAAI,IAAY;CAChC,KAAK,MAAM,CAAC,UAAU,YAAY,OAAO,QAAQ,WAAW,GAC1D,IAAI,MAAM,QAAQ,OAAO,GACvB,KAAK,MAAM,UAAU,SACnB,QAAQ,IAAI,GAAG,SAAS,GAAG,OAAO,MAAM,GAAG;CAIjD,OAAO,cAAc,QAAQ,UAAU,QAAQ,IAAI,KAAK,CAAC;AAC3D"}
1
+ {"version":3,"file":"access-grant.js","names":[],"sources":["../src/access-grant.ts"],"sourcesContent":["import type { AccessGrant } from \"@headless-lms/core/types\";\nimport { ORG_CLAIM } from \"@headless-lms/core/identity\";\nimport { isPermission } from \"@headless-lms/core/organizations\";\nimport { type AccessTokenAuthorization, parseAccessTokenAuthorization } from \"better-auth/oauth2\";\n\nexport function accessTokenAuthorization(\n header: string | string[] | undefined,\n): AccessTokenAuthorization | null {\n if (typeof header !== \"string\") {\n return null;\n }\n const authorization = parseAccessTokenAuthorization(header);\n if (!authorization?.token || authorization.scheme === \"Unknown\") {\n return null;\n }\n return authorization;\n}\n\nexport function isCompactJws(token: string): boolean {\n const parts = token.split(\".\");\n return parts.length === 3 && parts.every((part) => part.length > 0);\n}\n\nexport function grantFromClaims(claims: Record<string, unknown>): AccessGrant | null {\n const userId = claims.sub;\n const clientId = claims.client_id ?? claims.azp;\n const orgId = claims[ORG_CLAIM];\n if (typeof userId !== \"string\" || typeof clientId !== \"string\" || typeof orgId !== \"string\") {\n return null;\n }\n const scopes =\n typeof claims.scope === \"string\" ? claims.scope.split(\" \").filter(isPermission) : [];\n return { userId, clientId, orgId, limit: { scopes } };\n}\n\nexport async function needsOrgChoice(\n activeOrgId: string | null,\n memberOrgIds: () => Promise<readonly string[]>,\n): Promise<boolean> {\n if (activeOrgId === null) {\n return true;\n }\n return !(await memberOrgIds()).includes(activeOrgId);\n}\n\nexport async function consentOrgId(\n activeOrgId: string | null,\n memberOrgIds: () => Promise<readonly string[]>,\n): Promise<string | null> {\n return activeOrgId !== null && !(await needsOrgChoice(activeOrgId, memberOrgIds))\n ? activeOrgId\n : null;\n}\n\nfunction metadataField(metadata: unknown, field: string): string | null {\n let value = metadata;\n if (typeof value === \"string\") {\n try {\n value = JSON.parse(value);\n } catch {\n return null;\n }\n }\n const found = (value as Record<string, unknown> | null)?.[field];\n return typeof found === \"string\" && found.length > 0 ? found : null;\n}\n\nexport function orgIdFromMetadata(metadata: unknown): string | null {\n return metadataField(metadata, \"organizationId\");\n}\n\nexport function roleFromMetadata(metadata: unknown): string | null {\n return metadataField(metadata, \"role\");\n}\n"],"mappings":";;;;AAKA,SAAgB,yBACd,QACiC;CACjC,IAAI,OAAO,WAAW,UACpB,OAAO;CAET,MAAM,gBAAgB,8BAA8B,MAAM;CAC1D,IAAI,CAAC,eAAe,SAAS,cAAc,WAAW,WACpD,OAAO;CAET,OAAO;AACT;AAEA,SAAgB,aAAa,OAAwB;CACnD,MAAM,QAAQ,MAAM,MAAM,GAAG;CAC7B,OAAO,MAAM,WAAW,KAAK,MAAM,OAAO,SAAS,KAAK,SAAS,CAAC;AACpE;AAEA,SAAgB,gBAAgB,QAAqD;CACnF,MAAM,SAAS,OAAO;CACtB,MAAM,WAAW,OAAO,aAAa,OAAO;CAC5C,MAAM,QAAQ,OAAO;CACrB,IAAI,OAAO,WAAW,YAAY,OAAO,aAAa,YAAY,OAAO,UAAU,UACjF,OAAO;CAIT,OAAO;EAAE;EAAQ;EAAU;EAAO,OAAO,EAAE,QADzC,OAAO,OAAO,UAAU,WAAW,OAAO,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,YAAY,IAAI,CAAC,EACnC;CAAE;AACtD;AAEA,eAAsB,eACpB,aACA,cACkB;CAClB,IAAI,gBAAgB,MAClB,OAAO;CAET,OAAO,EAAE,MAAM,aAAa,EAAA,CAAG,SAAS,WAAW;AACrD;AAEA,eAAsB,aACpB,aACA,cACwB;CACxB,OAAO,gBAAgB,QAAQ,CAAE,MAAM,eAAe,aAAa,YAAY,IAC3E,cACA;AACN;AAEA,SAAS,cAAc,UAAmB,OAA8B;CACtE,IAAI,QAAQ;CACZ,IAAI,OAAO,UAAU,UACnB,IAAI;EACF,QAAQ,KAAK,MAAM,KAAK;CAC1B,QAAQ;EACN,OAAO;CACT;CAEF,MAAM,QAAS,QAA2C;CAC1D,OAAO,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ;AACjE;AAEA,SAAgB,kBAAkB,UAAkC;CAClE,OAAO,cAAc,UAAU,gBAAgB;AACjD;AAEA,SAAgB,iBAAiB,UAAkC;CACjE,OAAO,cAAc,UAAU,MAAM;AACvC"}
package/dist/access.d.ts CHANGED
@@ -1,8 +1,5 @@
1
1
  //#region src/access.d.ts
2
2
  declare const statement: {
3
- readonly course: readonly ["create", "read", "update", "delete"];
4
- readonly progress: readonly ["view"];
5
- readonly community: readonly ["moderate"];
6
3
  readonly organization: readonly ["update", "delete"];
7
4
  readonly member: readonly ["create", "update", "delete"];
8
5
  readonly invitation: readonly ["create", "cancel"];
@@ -11,18 +8,12 @@ declare const statement: {
11
8
  };
12
9
  declare const ac: {
13
10
  newRole<const TRoleStatements extends import("better-auth/plugins/access").Statements>(statements: import("better-auth/plugins/access").RoleInput<{
14
- readonly course: readonly ["create", "read", "update", "delete"];
15
- readonly progress: readonly ["view"];
16
- readonly community: readonly ["moderate"];
17
11
  readonly organization: readonly ["update", "delete"];
18
12
  readonly member: readonly ["create", "update", "delete"];
19
13
  readonly invitation: readonly ["create", "cancel"];
20
14
  readonly team: readonly ["create", "update", "delete"];
21
15
  readonly ac: readonly ["create", "read", "update", "delete"];
22
16
  }, TRoleStatements>): import("better-auth/plugins/access").Role<import("better-auth/plugins/access").ExactRoleStatements<TRoleStatements>, {
23
- readonly course: readonly ["create", "read", "update", "delete"];
24
- readonly progress: readonly ["view"];
25
- readonly community: readonly ["moderate"];
26
17
  readonly organization: readonly ["update", "delete"];
27
18
  readonly member: readonly ["create", "update", "delete"];
28
19
  readonly invitation: readonly ["create", "cancel"];
@@ -30,9 +21,6 @@ declare const ac: {
30
21
  readonly ac: readonly ["create", "read", "update", "delete"];
31
22
  }>;
32
23
  statements: {
33
- readonly course: readonly ["create", "read", "update", "delete"];
34
- readonly progress: readonly ["view"];
35
- readonly community: readonly ["moderate"];
36
24
  readonly organization: readonly ["update", "delete"];
37
25
  readonly member: readonly ["create", "update", "delete"];
38
26
  readonly invitation: readonly ["create", "cancel"];
@@ -40,78 +28,29 @@ declare const ac: {
40
28
  readonly ac: readonly ["create", "read", "update", "delete"];
41
29
  };
42
30
  };
31
+ declare const OWNER_MEMBERSHIP = "owner";
32
+ declare const PARTICIPANT_MEMBERSHIP = "participant";
43
33
  declare const roles: {
44
- owner: import("better-auth/plugins/access").Role<import("better-auth/plugins/access").ExactRoleStatements<{
45
- readonly course: ["create", "read", "update", "delete"];
46
- readonly progress: ["view"];
47
- readonly community: ["moderate"];
48
- readonly organization: readonly ["update", "delete"];
49
- readonly member: readonly ["create", "update", "delete"];
50
- readonly invitation: readonly ["create", "cancel"];
51
- readonly team: readonly ["create", "update", "delete"];
52
- readonly ac: readonly ["create", "read", "update", "delete"];
53
- }>, {
54
- readonly course: readonly ["create", "read", "update", "delete"];
55
- readonly progress: readonly ["view"];
56
- readonly community: readonly ["moderate"];
57
- readonly organization: readonly ["update", "delete"];
58
- readonly member: readonly ["create", "update", "delete"];
59
- readonly invitation: readonly ["create", "cancel"];
60
- readonly team: readonly ["create", "update", "delete"];
61
- readonly ac: readonly ["create", "read", "update", "delete"];
62
- }>;
63
- admin: import("better-auth/plugins/access").Role<import("better-auth/plugins/access").ExactRoleStatements<{
64
- readonly course: ["create", "read", "update", "delete"];
65
- readonly progress: ["view"];
66
- readonly community: ["moderate"];
67
- readonly organization: readonly ["update"];
68
- readonly invitation: readonly ["create", "cancel"];
69
- readonly member: readonly ["create", "update", "delete"];
70
- readonly team: readonly ["create", "update", "delete"];
71
- readonly ac: readonly ["create", "read", "update", "delete"];
72
- }>, {
73
- readonly course: readonly ["create", "read", "update", "delete"];
74
- readonly progress: readonly ["view"];
75
- readonly community: readonly ["moderate"];
76
- readonly organization: readonly ["update", "delete"];
77
- readonly member: readonly ["create", "update", "delete"];
78
- readonly invitation: readonly ["create", "cancel"];
79
- readonly team: readonly ["create", "update", "delete"];
80
- readonly ac: readonly ["create", "read", "update", "delete"];
81
- }>;
82
- instructor: import("better-auth/plugins/access").Role<import("better-auth/plugins/access").ExactRoleStatements<{
83
- readonly course: ["read", "update"];
84
- readonly progress: ["view"];
85
- readonly community: ["moderate"];
86
- }>, {
87
- readonly course: readonly ["create", "read", "update", "delete"];
88
- readonly progress: readonly ["view"];
89
- readonly community: readonly ["moderate"];
90
- readonly organization: readonly ["update", "delete"];
91
- readonly member: readonly ["create", "update", "delete"];
92
- readonly invitation: readonly ["create", "cancel"];
93
- readonly team: readonly ["create", "update", "delete"];
94
- readonly ac: readonly ["create", "read", "update", "delete"];
95
- }>;
96
- moderator: import("better-auth/plugins/access").Role<import("better-auth/plugins/access").ExactRoleStatements<{
97
- readonly course: ["read"];
98
- readonly community: ["moderate"];
99
- }>, {
100
- readonly course: readonly ["create", "read", "update", "delete"];
101
- readonly progress: readonly ["view"];
102
- readonly community: readonly ["moderate"];
34
+ owner: import("better-auth/plugins/access").Role<import("better-auth/plugins/access").ExactRoleStatements<import("better-auth/plugins/access").ExactRoleStatements<{
35
+ readonly organization: ["update", "delete"];
36
+ readonly member: ["create", "update", "delete"];
37
+ readonly invitation: ["create", "cancel"];
38
+ readonly team: ["create", "update", "delete"];
39
+ readonly ac: ["create", "read", "update", "delete"];
40
+ }>>, {
103
41
  readonly organization: readonly ["update", "delete"];
104
42
  readonly member: readonly ["create", "update", "delete"];
105
43
  readonly invitation: readonly ["create", "cancel"];
106
44
  readonly team: readonly ["create", "update", "delete"];
107
45
  readonly ac: readonly ["create", "read", "update", "delete"];
108
46
  }>;
109
- student: import("better-auth/plugins/access").Role<import("better-auth/plugins/access").ExactRoleStatements<{
110
- readonly course: ["read"];
111
- }>, {
112
- readonly course: readonly ["create", "read", "update", "delete"];
113
- readonly progress: readonly ["view"];
114
- readonly community: readonly ["moderate"];
47
+ participant: import("better-auth/plugins/access").Role<import("better-auth/plugins/access").ExactRoleStatements<import("better-auth/plugins/access").ExactRoleStatements<{
48
+ readonly organization: [];
49
+ readonly member: [];
50
+ readonly invitation: [];
51
+ readonly team: [];
52
+ readonly ac: ["read"];
53
+ }>>, {
115
54
  readonly organization: readonly ["update", "delete"];
116
55
  readonly member: readonly ["create", "update", "delete"];
117
56
  readonly invitation: readonly ["create", "cancel"];
@@ -120,5 +59,5 @@ declare const roles: {
120
59
  }>;
121
60
  };
122
61
  //#endregion
123
- export { ac, roles, statement };
62
+ export { OWNER_MEMBERSHIP, PARTICIPANT_MEMBERSHIP, ac, roles, statement };
124
63
  //# sourceMappingURL=access.d.ts.map
package/dist/access.js CHANGED
@@ -1,53 +1,15 @@
1
1
  import { createAccessControl } from "better-auth/plugins/access";
2
- import { adminAc, defaultStatements, ownerAc } from "better-auth/plugins/organization/access";
2
+ import { defaultStatements, memberAc, ownerAc } from "better-auth/plugins/organization/access";
3
3
  //#region src/access.ts
4
- const statement = {
5
- ...defaultStatements,
6
- course: [
7
- "create",
8
- "read",
9
- "update",
10
- "delete"
11
- ],
12
- progress: ["view"],
13
- community: ["moderate"]
14
- };
4
+ const statement = { ...defaultStatements };
15
5
  const ac = createAccessControl(statement);
6
+ const OWNER_MEMBERSHIP = "owner";
7
+ const PARTICIPANT_MEMBERSHIP = "participant";
16
8
  const roles = {
17
- owner: ac.newRole({
18
- ...ownerAc.statements,
19
- course: [
20
- "create",
21
- "read",
22
- "update",
23
- "delete"
24
- ],
25
- progress: ["view"],
26
- community: ["moderate"]
27
- }),
28
- admin: ac.newRole({
29
- ...adminAc.statements,
30
- course: [
31
- "create",
32
- "read",
33
- "update",
34
- "delete"
35
- ],
36
- progress: ["view"],
37
- community: ["moderate"]
38
- }),
39
- instructor: ac.newRole({
40
- course: ["read", "update"],
41
- progress: ["view"],
42
- community: ["moderate"]
43
- }),
44
- moderator: ac.newRole({
45
- course: ["read"],
46
- community: ["moderate"]
47
- }),
48
- student: ac.newRole({ course: ["read"] })
9
+ [OWNER_MEMBERSHIP]: ac.newRole(ownerAc.statements),
10
+ [PARTICIPANT_MEMBERSHIP]: ac.newRole(memberAc.statements)
49
11
  };
50
12
  //#endregion
51
- export { ac, roles, statement };
13
+ export { OWNER_MEMBERSHIP, PARTICIPANT_MEMBERSHIP, ac, roles, statement };
52
14
 
53
15
  //# sourceMappingURL=access.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"access.js","names":[],"sources":["../src/access.ts"],"sourcesContent":["// Better Auth org-plugin access control. Better Auth is the system of record for\n// roles; these roles mirror the domain Role union (core/organizations/roles).\nimport { createAccessControl } from \"better-auth/plugins/access\";\nimport { defaultStatements, ownerAc, adminAc } from \"better-auth/plugins/organization/access\";\n\nexport const statement = {\n ...defaultStatements,\n course: [\"create\", \"read\", \"update\", \"delete\"],\n progress: [\"view\"],\n community: [\"moderate\"],\n} as const;\n\nconst ac = createAccessControl(statement);\n\nexport const roles = {\n owner: ac.newRole({\n ...ownerAc.statements,\n course: [\"create\", \"read\", \"update\", \"delete\"],\n progress: [\"view\"],\n community: [\"moderate\"],\n }),\n admin: ac.newRole({\n ...adminAc.statements,\n course: [\"create\", \"read\", \"update\", \"delete\"],\n progress: [\"view\"],\n community: [\"moderate\"],\n }),\n instructor: ac.newRole({\n course: [\"read\", \"update\"],\n progress: [\"view\"],\n community: [\"moderate\"],\n }),\n moderator: ac.newRole({\n course: [\"read\"],\n community: [\"moderate\"],\n }),\n student: ac.newRole({\n course: [\"read\"],\n }),\n};\n\nexport { ac };\n"],"mappings":";;;AAKA,MAAa,YAAY;CACvB,GAAG;CACH,QAAQ;EAAC;EAAU;EAAQ;EAAU;CAAQ;CAC7C,UAAU,CAAC,MAAM;CACjB,WAAW,CAAC,UAAU;AACxB;AAEA,MAAM,KAAK,oBAAoB,SAAS;AAExC,MAAa,QAAQ;CACnB,OAAO,GAAG,QAAQ;EAChB,GAAG,QAAQ;EACX,QAAQ;GAAC;GAAU;GAAQ;GAAU;EAAQ;EAC7C,UAAU,CAAC,MAAM;EACjB,WAAW,CAAC,UAAU;CACxB,CAAC;CACD,OAAO,GAAG,QAAQ;EAChB,GAAG,QAAQ;EACX,QAAQ;GAAC;GAAU;GAAQ;GAAU;EAAQ;EAC7C,UAAU,CAAC,MAAM;EACjB,WAAW,CAAC,UAAU;CACxB,CAAC;CACD,YAAY,GAAG,QAAQ;EACrB,QAAQ,CAAC,QAAQ,QAAQ;EACzB,UAAU,CAAC,MAAM;EACjB,WAAW,CAAC,UAAU;CACxB,CAAC;CACD,WAAW,GAAG,QAAQ;EACpB,QAAQ,CAAC,MAAM;EACf,WAAW,CAAC,UAAU;CACxB,CAAC;CACD,SAAS,GAAG,QAAQ,EAClB,QAAQ,CAAC,MAAM,EACjB,CAAC;AACH"}
1
+ {"version":3,"file":"access.js","names":[],"sources":["../src/access.ts"],"sourcesContent":["import { createAccessControl } from \"better-auth/plugins/access\";\nimport { defaultStatements, ownerAc, memberAc } from \"better-auth/plugins/organization/access\";\n\nexport const statement = { ...defaultStatements } as const;\n\nconst ac = createAccessControl(statement);\n\nexport const OWNER_MEMBERSHIP = \"owner\";\nexport const PARTICIPANT_MEMBERSHIP = \"participant\";\n\nexport const roles = {\n [OWNER_MEMBERSHIP]: ac.newRole(ownerAc.statements),\n [PARTICIPANT_MEMBERSHIP]: ac.newRole(memberAc.statements),\n};\n\nexport { ac };\n"],"mappings":";;;AAGA,MAAa,YAAY,EAAE,GAAG,kBAAkB;AAEhD,MAAM,KAAK,oBAAoB,SAAS;AAExC,MAAa,mBAAmB;AAChC,MAAa,yBAAyB;AAEtC,MAAa,QAAQ;EAClB,mBAAmB,GAAG,QAAQ,QAAQ,UAAU;EAChD,yBAAyB,GAAG,QAAQ,SAAS,UAAU;AAC1D"}