@lobb-js/lobb-ext-auth 0.1.67 → 0.2.2

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.
Files changed (86) hide show
  1. package/.vscode/settings.json +5 -0
  2. package/CHANGELOG.md +90 -31
  3. package/README.md +1 -1
  4. package/extensions/auth/collections/activityFeed.ts +53 -0
  5. package/extensions/auth/collections/collections.ts +43 -0
  6. package/extensions/auth/collections/sessions.ts +34 -0
  7. package/extensions/auth/collections/users.ts +44 -0
  8. package/extensions/auth/config/extensionConfigSchema.ts +47 -0
  9. package/extensions/auth/config/permissionsAction/create.ts +20 -0
  10. package/extensions/auth/config/permissionsAction/delete.ts +3 -0
  11. package/extensions/auth/config/permissionsAction/read.ts +10 -0
  12. package/extensions/auth/config/permissionsAction/update.ts +20 -0
  13. package/extensions/auth/database/init.ts +51 -0
  14. package/extensions/auth/database/migrations.ts +3 -0
  15. package/extensions/auth/database/utils.ts +36 -0
  16. package/extensions/auth/index.ts +19 -0
  17. package/extensions/auth/meta/meta.ts +11 -0
  18. package/extensions/auth/openapi.ts +469 -0
  19. package/extensions/auth/studio/tests/login.spec.ts +34 -0
  20. package/extensions/auth/studio/tests/package.json +1 -0
  21. package/extensions/auth/studio/tests/playwright.config.cjs +27 -0
  22. package/extensions/auth/tests/collections/extend_users_collection.test.ts +61 -0
  23. package/extensions/auth/tests/configs/auth.ts +73 -0
  24. package/extensions/auth/tests/configs/auth_no_roles.ts +65 -0
  25. package/extensions/auth/tests/configs/auth_public_full_access.ts +69 -0
  26. package/extensions/auth/tests/configs/auth_with_different_admin_creds.ts +81 -0
  27. package/extensions/auth/tests/configs/auth_with_extend_users.ts +81 -0
  28. package/extensions/auth/tests/configs/auth_with_refresh_token.ts +86 -0
  29. package/extensions/auth/tests/configs/auth_with_short_access_token_only.ts +95 -0
  30. package/extensions/auth/tests/configs/auth_with_short_time_refresh_token.ts +86 -0
  31. package/extensions/auth/tests/configs/social_blog.ts +156 -0
  32. package/extensions/auth/tests/controllers/change_password.test.ts +113 -0
  33. package/extensions/auth/tests/controllers/dashboardAccessRoles.test.ts +29 -0
  34. package/extensions/auth/tests/controllers/login.test.ts +101 -0
  35. package/extensions/auth/tests/controllers/logout.test.ts +89 -0
  36. package/extensions/auth/tests/controllers/me.test.ts +272 -0
  37. package/extensions/auth/tests/controllers/register.test.ts +45 -0
  38. package/extensions/auth/tests/database/db.test.ts +64 -0
  39. package/extensions/auth/tests/database/differentAdminCreds.test.ts +51 -0
  40. package/extensions/auth/tests/middlewares/adminAuthGuard.test.ts +157 -0
  41. package/extensions/auth/tests/middlewares/publicAllowBasic.test.ts +137 -0
  42. package/extensions/auth/tests/middlewares/publicPreventBasic.test.ts +108 -0
  43. package/extensions/auth/tests/socialBlog.test.ts +253 -0
  44. package/extensions/auth/tests/utils/addArticles.ts +22 -0
  45. package/extensions/auth/tests/utils/addSocialBlogArticles.ts +52 -0
  46. package/extensions/auth/tests/utils/data/articles.ts +65 -0
  47. package/extensions/auth/tests/utils/data/socialBlogArticles.ts +56 -0
  48. package/extensions/auth/utils.ts +17 -0
  49. package/extensions/auth/workflows/baseWorkflow.ts +159 -0
  50. package/extensions/auth/workflows/hashHandlerWorkflows.ts +29 -0
  51. package/extensions/auth/workflows/index.ts +29 -0
  52. package/extensions/auth/workflows/meAliasWorkflows.ts +48 -0
  53. package/extensions/auth/workflows/policiesWorkflows.ts +240 -0
  54. package/extensions/auth/workflows/utils.ts +306 -0
  55. package/lobb.ts +108 -0
  56. package/package.json +33 -6
  57. package/public/public/vite.svg +1 -0
  58. package/scripts/postpublish.sh +12 -0
  59. package/scripts/prepublish.sh +17 -0
  60. package/studio/app.html +12 -0
  61. package/studio/routes/+layout.svelte +7 -0
  62. package/studio/routes/+layout.ts +1 -0
  63. package/studio/routes/[...path]/+page.svelte +6 -0
  64. package/svelte.config.js +23 -7
  65. package/todo.md +37 -0
  66. package/tsconfig.app.json +3 -3
  67. package/tsconfig.json +9 -10
  68. package/vite.config.ts +4 -8
  69. package/.env +0 -1
  70. package/components.json +0 -16
  71. package/index.html +0 -13
  72. package/src/app.css +0 -124
  73. package/src/main.ts +0 -14
  74. /package/{src → extensions/auth/studio}/auth.ts +0 -0
  75. /package/{src → extensions/auth/studio}/index.ts +0 -0
  76. /package/{src → extensions/auth/studio}/lib/components/pages/loginPage/index.svelte +0 -0
  77. /package/{src → extensions/auth/studio}/lib/components/pages/settings/index.svelte +0 -0
  78. /package/{src → extensions/auth/studio}/lib/components/pages/settings/pages/activityFeed.svelte +0 -0
  79. /package/{src → extensions/auth/studio}/lib/components/pages/settings/pages/rolesAndPermissions.svelte +0 -0
  80. /package/{src → extensions/auth/studio}/lib/components/pages/settings/pages/users.svelte +0 -0
  81. /package/{src → extensions/auth/studio}/lib/components/pages/userSettings/components/account.svelte +0 -0
  82. /package/{src → extensions/auth/studio}/lib/components/pages/userSettings/components/profile.svelte +0 -0
  83. /package/{src → extensions/auth/studio}/lib/components/pages/userSettings/index.svelte +0 -0
  84. /package/{src → extensions/auth/studio}/lib/index.ts +0 -0
  85. /package/{src → extensions/auth/studio}/lib/utils.ts +0 -0
  86. /package/{src → extensions/auth/studio}/onStartup.ts +0 -0
@@ -0,0 +1,5 @@
1
+ {
2
+ "deno.disablePaths": [
3
+ "studio"
4
+ ]
5
+ }
package/CHANGELOG.md CHANGED
@@ -2,58 +2,110 @@
2
2
  All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
3
3
 
4
4
  - - -
5
- ## auth-ext-studio@0.1.67 - 2026-03-13
5
+ ## auth-ext@0.2.2 - 2026-03-28
6
6
  #### Bug Fixes
7
- - chaning $lib to relative path - (c6d9e8f) - malik ben
7
+ - update readme to trigger publish - (cf1e896) - malik ben
8
+ - update READMEs to trigger republish of all packages - (2bd145d) - malik ben
8
9
  #### Miscellaneous Chores
9
- - (**version**) 0.22.0 - (6510e32) - Cocogitto Bot
10
- - (**version**) 0.21.0 - (c973aa9) - Cocogitto Bot
10
+ - (**version**) 0.26.2 - (1907933) - Cocogitto Bot
11
11
 
12
12
  - - -
13
13
 
14
- ## auth-ext-studio@0.1.66 - 2026-03-01
14
+ ## auth-ext@0.2.1 - 2026-03-28
15
15
  #### Bug Fixes
16
+ - adding readme to all packages - (3a9264a) - malik ben
17
+ #### Miscellaneous Chores
18
+ - add publishConfig and fix ext packages for npm publishing - (49747e9) - malik ben
19
+
20
+ - - -
21
+
22
+ ## auth-ext@0.2.0 - 2026-03-28
23
+ #### Features
24
+ - (**auth-ext**) convert studio from Svelte SPA to SvelteKit - (6f24661) - malik ben
25
+ - (**auth-ext**) add Playwright e2e tests for studio login page - (5679c3e) - malik ben
26
+ - (**auth-ext**) auto-discover studio extensions via import.meta.glob - (478c4be) - malik ben
27
+ - (**auth-ext**) enable parallel bun test execution with port/db isolation - (721ee14) - malik ben
28
+ - (**auth-ext**) migrate packages/auth-ext from Deno to Bun - (2ce1866) - malik ben
29
+ - replace hasDashboardExtension with virtual:lobb-studio-extensions module - (437cb2e) - malik ben
30
+ #### Bug Fixes
31
+ - (**auth-ext**) move onStartup.ts to extensions/auth/studio - (af08d43) - malik ben
16
32
  - (**studio**) prevent @lobb-js/studio version shadowing in extensions - (cd674b9) - malik ben
33
+ - add /studio subpath exports to ext packages, update studio pages to use them - (c0b9a82) - malik ben
34
+ - untrack .svelte-kit from mindhar, fix process leak and $lib imports, update ai sdk versions - (017f784) - malik ben
35
+ - chaning $lib to relative path - (c6d9e8f) - malik ben
17
36
  #### Miscellaneous Chores
37
+ - (**auth-ext**) remove dashboard extension.json reference from auth extension - (27df519) - malik ben
38
+ - (**auth-ext**) move backend tests to extensions/auth/tests and rename scripts - (6ba4a4e) - malik ben
39
+ - (**auth-ext**) split studio into host and extension-specific directories - (6f68493) - malik ben
40
+ - (**auth-ext**) move extension logic from projectExtension to extensions/auth - (e172b74) - malik ben
41
+ - (**auth-ext**) flatten studio into project root and simplify workspace globs - (7a9a873) - malik ben
42
+ - (**auth-ext**) rename studio directory to __studio - (abdaa72) - malik ben
43
+ - (**auth-ext**) clear create_users_collections migration - (cbe5d2a) - malik ben
44
+ - (**version**) 0.25.2 - (a62acb9) - Cocogitto Bot
45
+ - (**version**) 0.25.1 - (afe7e69) - Cocogitto Bot
46
+ - (**version**) 0.25.0 - (77a383c) - Cocogitto Bot
47
+ - (**version**) 0.24.0 - (a8cb605) - Cocogitto Bot
48
+ - (**version**) 0.23.0 - (60f357e) - Cocogitto Bot
49
+ - (**version**) 0.22.0 - (6510e32) - Cocogitto Bot
50
+ - (**version**) 0.21.0 - (c973aa9) - Cocogitto Bot
51
+ - (**version**) 0.20.0 - (06cc303) - Cocogitto Bot
52
+ - (**version**) 0.19.0 - (6bbc900) - Cocogitto Bot
53
+ - (**version**) 0.18.0 - (efc553f) - Cocogitto Bot
54
+ - (**version**) 0.17.0 - (4174f0c) - Cocogitto Bot
55
+ - (**version**) 0.16.0 - (9508655) - Cocogitto Bot
18
56
  - (**version**) 0.15.0 - (0c2c345) - Cocogitto Bot
19
- - fixing the /studio base issue - (de6686f) - Malik Najjar
57
+ - (**version**) 0.14.11 - (ad92b61) - Cocogitto Bot
58
+ - add dev:studio/build:studio scripts, fix Dockerfiles, remove --build flag - (1595975) - malik ben
59
+ - add prepublish/postpublish scripts to extension packages for standalone compatibility - (4d6108f) - malik ben
60
+ - centralize studio app.css in @lobb-js/studio package, remove local copies - (05192dc) - malik ben
61
+ - rename @lobb/ scope to @lobb-js/ across all packages and apps - (cce4ce0) - malik ben
62
+ - add start/build scripts and gitignore build dir across all projects - (58f539d) - malik ben
63
+ - update CLAUDE.md to enforce no-commit-without-explicit-instruction rule - (6d63a42) - malik ben
64
+ - replace workspace:* with exact versions in all package.json files - (74fbdb7) - malik ben
65
+ - rename __studio to studio and remove unused studio dirs - (77fb932) - malik ben
20
66
 
21
67
  - - -
22
68
 
23
- ## auth-ext-studio@0.1.65 - 2026-02-22
69
+ ## auth-ext@0.1.67 - 2026-02-25
24
70
  #### Bug Fixes
25
- - adding a studio prefix for the studio app - (6607b5a) - malik ben
71
+ - publishing extension again - (e07ac36) - Malik Najjar
26
72
  #### Miscellaneous Chores
27
- - (**version**) 0.14.2 - (6ecdc1d) - Cocogitto Bot
73
+ - (**version**) 0.14.8 - (0e6c1cb) - Cocogitto Bot
28
74
 
29
75
  - - -
30
76
 
31
- ## auth-ext-studio@0.1.64 - 2026-02-21
77
+ ## auth-ext@0.1.66 - 2026-02-22
32
78
  #### Bug Fixes
33
- - using default export instead of named export for extensions - (37dd485) - malik ben
34
- #### Miscellaneous Chores
35
- - (**version**) 0.14.0 - (7d2eb87) - Cocogitto Bot
36
- - (**version**) 0.12.1 - (c548105) - Cocogitto Bot
79
+ - coggito publishing packages order fix - (573c75e) - malik ben
37
80
 
38
81
  - - -
39
82
 
40
- ## auth-ext-studio@0.1.63 - 2026-02-17
83
+ ## auth-ext@0.1.65 - 2026-02-22
41
84
  #### Bug Fixes
42
- - fixing the standalone issue - (1a70a51) - Malik Najjar
43
- #### Miscellaneous Chores
44
- - (**version**) 0.10.9 - (19ac765) - Cocogitto Bot
85
+ - adjusted the names of the events - (6543d8c) - malik ben
45
86
 
46
87
  - - -
47
88
 
48
- ## auth-ext-studio@0.1.60 - 2026-02-17
89
+ ## auth-ext@0.1.64 - 2026-02-22
49
90
  #### Bug Fixes
50
- - removing a comment - (68c182d) - Malik Najjar
91
+ - made the collectionService become an property in the main lobb object - (146e4cb) - malik ben
92
+
93
+ - - -
94
+
95
+ ## auth-ext@0.1.63 - 2026-02-21
96
+ #### Bug Fixes
97
+ - using default export instead of named export for extensions - (37dd485) - malik ben
51
98
  #### Miscellaneous Chores
52
- - adding a comment - (c5c8fbf) - Malik Najjar
99
+ - (**version**) 0.13.2 - (39b0145) - Cocogitto Bot
100
+ - (**version**) 0.12.3 - (cd06fc0) - Cocogitto Bot
101
+ - (**version**) 0.12.2 - (35b2ff3) - Cocogitto Bot
102
+ - (**version**) 0.12.1 - (c548105) - Cocogitto Bot
103
+ - (**version**) 0.11.1 - (659ebd3) - Cocogitto Bot
104
+ - (**version**) 0.11.0 - (3f4f47e) - Cocogitto Bot
53
105
 
54
106
  - - -
55
107
 
56
- ## auth-ext-studio@0.1.59 - 2026-02-17
108
+ ## auth-ext@0.1.62 - 2026-02-17
57
109
  #### Bug Fixes
58
110
  - removing a comment - (15c57c0) - Malik Najjar
59
111
  #### Miscellaneous Chores
@@ -61,7 +113,7 @@ All notable changes to this project will be documented in this file. See [conven
61
113
 
62
114
  - - -
63
115
 
64
- ## auth-ext-studio@0.1.1 - 2026-02-17
116
+ ## auth-ext@0.1.61 - 2026-02-17
65
117
  #### Bug Fixes
66
118
  - removeing stupid comment - (ca41782) - Malik Najjar
67
119
  #### Miscellaneous Chores
@@ -70,20 +122,27 @@ All notable changes to this project will be documented in this file. See [conven
70
122
 
71
123
  - - -
72
124
 
73
- ## auth-ext-studio@0.1.0 - 2026-02-15
74
- #### Features
75
- - add authentication and user settings pages with responsive design - (aba51e4) - Malik Najjar
125
+ ## auth-ext@0.1.60 - 2026-02-17
126
+ #### Bug Fixes
127
+ - update the auth extension - (5318dda) - Malik Najjar
128
+ #### Miscellaneous Chores
129
+ - (**version**) 0.8.0 - (fdee7ca) - Cocogitto Bot
130
+
131
+ - - -
132
+
133
+ ## auth-ext@0.1.59 - 2026-02-15
134
+ #### Bug Fixes
135
+ - fix deno publish issue - (e8dcc4f) - malik ben
136
+ - issue fix - (63d66d3) - malik ben
76
137
  #### Miscellaneous Chores
77
138
  - (**version**) 0.5.5 - (d4dedeb) - Cocogitto Bot
78
139
  - (**version**) 0.5.4 - (1ca3970) - Cocogitto Bot
79
140
  - (**version**) 0.5.3 - (dcdb9cb) - Cocogitto Bot
80
141
  - (**version**) 0.5.2 - (aa66e29) - Cocogitto Bot
81
142
  - (**version**) 0.5.1 - (41b7c35) - Cocogitto Bot
82
- - (**version**) 0.4.2 - (4395d99) - Cocogitto Bot
83
- - (**version**) 0.4.1 - (5e9f152) - Cocogitto Bot
84
- - (**version**) 0.4.0 - (aafd2d6) - Cocogitto Bot
85
- #### Style
86
- - Update background color from bg-soft to bg-muted/30 across various components - (ad2240a) - Malik Najjar
143
+ - (**version**) 0.5.0 - (af63147) - Cocogitto Bot
144
+ - (**version**) 0.4.4 - (eaed3b4) - Cocogitto Bot
145
+ - (**version**) 0.4.3 - (ea9ec49) - Cocogitto Bot
87
146
 
88
147
  - - -
89
148
 
package/README.md CHANGED
@@ -1 +1 @@
1
- # instagram_api_integration
1
+ # @lobb-js/lobb-ext-auth
@@ -0,0 +1,53 @@
1
+ import type { CollectionConfig } from "@lobb-js/core";
2
+
3
+ export const activityFeedCollection: CollectionConfig = {
4
+ indexes: {},
5
+ fields: {
6
+ id: {
7
+ type: "integer",
8
+ },
9
+ user_id: {
10
+ type: "integer",
11
+ references: {
12
+ collection: "auth_users",
13
+ field: "id",
14
+ },
15
+ validators: {
16
+ required: true,
17
+ },
18
+ },
19
+ action: {
20
+ type: "string",
21
+ length: 255,
22
+ validators: {
23
+ required: true,
24
+ enum: [
25
+ "create",
26
+ "read",
27
+ "update",
28
+ "delete",
29
+ ],
30
+ },
31
+ },
32
+ collection: {
33
+ type: "string",
34
+ length: 255,
35
+ validators: {
36
+ required: true,
37
+ },
38
+ },
39
+ item_id: {
40
+ type: "string",
41
+ length: 255,
42
+ validators: {
43
+ required: true,
44
+ },
45
+ },
46
+ created_at: {
47
+ type: "datetime",
48
+ pre_processors: {
49
+ default: "{{ now }}",
50
+ },
51
+ },
52
+ },
53
+ };
@@ -0,0 +1,43 @@
1
+ import type { CollectionConfig, Lobb } from "@lobb-js/core";
2
+ import { usersCollection } from "./users.ts";
3
+ import { sessionsCollection } from "./sessions.ts";
4
+ import type { ExtensionConfig } from "../config/extensionConfigSchema.ts";
5
+ import { activityFeedCollection } from "./activityFeed.ts";
6
+
7
+ export function collections(
8
+ lobb: Lobb,
9
+ extensionConfig: ExtensionConfig,
10
+ ): Record<string, CollectionConfig> {
11
+ const collectionsSchemas: Record<string, CollectionConfig> = {};
12
+ collectionsSchemas["auth_users"] = usersCollection;
13
+ collectionsSchemas["auth_sessions"] = sessionsCollection;
14
+
15
+ // adding the additional fields and indexes if the extend_users property exists
16
+ if (extensionConfig.extend_users) {
17
+ collectionsSchemas["auth_users"].indexes = {
18
+ ...collectionsSchemas["auth_users"].indexes,
19
+ ...extensionConfig.extend_users.indexes,
20
+ };
21
+ collectionsSchemas["auth_users"].fields = {
22
+ ...collectionsSchemas["auth_users"].fields,
23
+ ...extensionConfig.extend_users.fields,
24
+ };
25
+ }
26
+
27
+ const authConfig = extensionConfig;
28
+
29
+ if (!authConfig.roles) {
30
+ authConfig.roles = {};
31
+ }
32
+
33
+ collectionsSchemas["auth_roles"] = lobb.utils.lockCollectionToObject(
34
+ {
35
+ collectionName: "auth_roles",
36
+ object: authConfig.roles,
37
+ },
38
+ );
39
+
40
+ collectionsSchemas["auth_activity_feed"] = activityFeedCollection;
41
+
42
+ return collectionsSchemas;
43
+ }
@@ -0,0 +1,34 @@
1
+ import type { CollectionConfig } from "@lobb-js/core";
2
+
3
+ export const sessionsCollection: CollectionConfig = {
4
+ indexes: {},
5
+ fields: {
6
+ id: {
7
+ type: "integer",
8
+ },
9
+ user_id: {
10
+ type: "integer",
11
+ references: {
12
+ collection: "auth_users",
13
+ field: "id",
14
+ },
15
+ validators: {
16
+ required: true,
17
+ },
18
+ },
19
+ token: {
20
+ type: "string",
21
+ length: 255,
22
+ validators: {
23
+ maxLength: 255,
24
+ required: true,
25
+ },
26
+ },
27
+ expires_at: {
28
+ type: "datetime",
29
+ validators: {
30
+ required: true,
31
+ },
32
+ },
33
+ },
34
+ };
@@ -0,0 +1,44 @@
1
+ import type { CollectionConfig } from "@lobb-js/core";
2
+
3
+ export const usersCollection: CollectionConfig = {
4
+ indexes: {
5
+ auth_users_email_index: {
6
+ unique: true,
7
+ fields: {
8
+ email: {
9
+ order: "asc",
10
+ },
11
+ },
12
+ },
13
+ },
14
+ fields: {
15
+ id: {
16
+ type: "integer",
17
+ },
18
+ email: {
19
+ type: "string",
20
+ length: 255,
21
+ validators: {
22
+ validator: {
23
+ name: "isEmail",
24
+ },
25
+ maxLength: 255,
26
+ required: true,
27
+ },
28
+ },
29
+ password: {
30
+ type: "string",
31
+ length: 255,
32
+ validators: {
33
+ required: true,
34
+ },
35
+ },
36
+ role: {
37
+ type: "string",
38
+ length: 255,
39
+ validators: {
40
+ required: true,
41
+ },
42
+ },
43
+ },
44
+ };
@@ -0,0 +1,47 @@
1
+ import type { CollectionConfig } from "@lobb-js/core";
2
+ import type { CreatePermissionAction } from "./permissionsAction/create.ts";
3
+ import type { ReadPermissionAction } from "./permissionsAction/read.ts";
4
+ import type { UpdatePermissionAction } from "./permissionsAction/update.ts";
5
+ import type { DeletePermissionAction } from "./permissionsAction/delete.ts";
6
+
7
+ export interface User {
8
+ id: number;
9
+ email: string;
10
+ password: string;
11
+ role: string;
12
+ }
13
+
14
+ export interface PermissionAction {}
15
+
16
+ export type CollectionPermissionsActions = {
17
+ create?: true | CreatePermissionAction;
18
+ read?: true | ReadPermissionAction;
19
+ update?: true | UpdatePermissionAction;
20
+ delete?: true | DeletePermissionAction;
21
+ };
22
+
23
+ export type CollectionPermissionActionsKeys =
24
+ keyof CollectionPermissionsActions;
25
+ export type CollectionPermissionsConfig =
26
+ | true
27
+ | CollectionPermissionsActions;
28
+ export type PermissionsConfig =
29
+ | true
30
+ | Record<string, CollectionPermissionsConfig | undefined>;
31
+
32
+ export type RolesConfig = {
33
+ permissions: PermissionsConfig;
34
+ };
35
+
36
+ export type ExtensionConfig = {
37
+ admin: {
38
+ password: string;
39
+ email: string;
40
+ };
41
+ dashboard_access_roles?: string[];
42
+ roles: Record<string, RolesConfig | undefined>;
43
+ extend_users?: {
44
+ indexes?: CollectionConfig["indexes"];
45
+ fields?: Omit<CollectionConfig["fields"], "id">;
46
+ };
47
+ };
@@ -0,0 +1,20 @@
1
+ import type { PermissionAction, User } from "../extensionConfigSchema.ts";
2
+
3
+ interface FieldTrasnsformerFnParams {
4
+ value: unknown;
5
+ payload: Record<string, unknown>;
6
+ user?: User;
7
+ }
8
+ type FieldTrasnsformerFn = (params: FieldTrasnsformerFnParams) => unknown;
9
+
10
+ interface CreateGuardProps {
11
+ payload: Record<string, unknown>;
12
+ user?: User;
13
+ }
14
+ type CreateGuardFn = (props: CreateGuardProps) => true | void;
15
+
16
+ export interface CreatePermissionAction extends PermissionAction {
17
+ payloadGuard?: CreateGuardFn;
18
+ fields?: Record<string, true>;
19
+ mutate?: Record<string, FieldTrasnsformerFn>;
20
+ }
@@ -0,0 +1,3 @@
1
+ import type { PermissionAction } from "../extensionConfigSchema.ts";
2
+
3
+ export interface DeletePermissionAction extends PermissionAction {}
@@ -0,0 +1,10 @@
1
+ import type { Filter } from "@lobb-js/core";
2
+ import type { PermissionAction, User } from "../extensionConfigSchema.ts";
3
+
4
+ export interface ReadPermissionAction extends PermissionAction {
5
+ /**
6
+ * Filter that gets passed to the db select query condition
7
+ */
8
+ filter?: Filter<{ user?: User }>;
9
+ fields?: Record<string, true>;
10
+ }
@@ -0,0 +1,20 @@
1
+ import type { PermissionAction, User } from "../extensionConfigSchema.ts";
2
+
3
+ interface FieldTrasnsformerFnParams {
4
+ value: unknown;
5
+ payload: Record<string, unknown>;
6
+ user?: User;
7
+ }
8
+ type FieldTrasnsformerFn = (params: FieldTrasnsformerFnParams) => unknown;
9
+
10
+ interface UpdateGuardProps {
11
+ payload: Record<string, unknown>;
12
+ user?: User;
13
+ }
14
+ type UpdateGuardFn = (props: UpdateGuardProps) => true | void;
15
+
16
+ export interface UpdatePermissionAction extends PermissionAction {
17
+ payloadGuard?: UpdateGuardFn;
18
+ fields?: Record<string, true>;
19
+ mutate?: Record<string, FieldTrasnsformerFn>;
20
+ }
@@ -0,0 +1,51 @@
1
+ import type { Lobb } from "@lobb-js/core";
2
+ import { verify } from "argon2";
3
+ import type { ExtensionConfig } from "../config/extensionConfigSchema.ts";
4
+ import { checkCollectionsInPermissions } from "./utils.ts";
5
+
6
+ export async function init(lobb: Lobb, extensionConfig: ExtensionConfig) {
7
+ checkCollectionsInPermissions(lobb, extensionConfig);
8
+ await syncincAdminUserInDB(lobb, extensionConfig);
9
+ }
10
+
11
+ async function syncincAdminUserInDB(lobb: Lobb, extensionConfig: ExtensionConfig) {
12
+ // syncinc the admin user in users collection
13
+ const config = extensionConfig;
14
+ const adminUserData = config.admin;
15
+ const entries = (await lobb.collectionService.findAll({
16
+ collectionName: "auth_users",
17
+ params: {
18
+ filter: {
19
+ role: "admin",
20
+ },
21
+ sort: "id",
22
+ },
23
+ })).data;
24
+ const adminUser = entries[0];
25
+ if (!adminUser) {
26
+ await lobb.collectionService.createOne({
27
+ collectionName: "auth_users",
28
+ data: {
29
+ email: adminUserData.email,
30
+ password: adminUserData.password,
31
+ role: "admin",
32
+ },
33
+ });
34
+ } else {
35
+ const passwordIdentical = await verify(
36
+ adminUser.password,
37
+ adminUserData.password,
38
+ );
39
+
40
+ if (adminUser.email !== adminUserData.email || !passwordIdentical) {
41
+ await lobb.collectionService.updateOne({
42
+ collectionName: "auth_users",
43
+ id: adminUser.id,
44
+ data: {
45
+ email: adminUserData.email,
46
+ password: adminUserData.password,
47
+ },
48
+ });
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,3 @@
1
+ import type { Migrations } from "@lobb-js/core";
2
+
3
+ export const migrations: Migrations = {};
@@ -0,0 +1,36 @@
1
+ import type { Lobb } from "@lobb-js/core";
2
+ import { LobbError } from "@lobb-js/core";
3
+ import type { ExtensionConfig } from "../config/extensionConfigSchema.ts";
4
+
5
+ export function checkCollectionsInPermissions(
6
+ lobb: Lobb,
7
+ extensionConfig: ExtensionConfig,
8
+ ) {
9
+ const authExtensionConfig = extensionConfig;
10
+ for (const roleName in authExtensionConfig.roles) {
11
+ const role = authExtensionConfig.roles[roleName];
12
+
13
+ if (typeof role === "undefined") {
14
+ throw new LobbError({
15
+ code: "INTERNAL_SERVER_ERROR",
16
+ message: `The (${roleName}) role in the auth permissions doesnt exist`,
17
+ });
18
+ }
19
+
20
+ const permissions = role.permissions;
21
+ const collectionNames = Object.keys(permissions);
22
+ for (let index = 0; index < collectionNames.length; index++) {
23
+ const collectionName = collectionNames[index];
24
+ const collectionExists = lobb.configManager.collectionExists(
25
+ collectionName,
26
+ );
27
+ if (!collectionExists) {
28
+ throw new LobbError({
29
+ code: "INTERNAL_SERVER_ERROR",
30
+ message:
31
+ `The (${collectionName}) collection in the auth permissions doesnt exist`,
32
+ });
33
+ }
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,19 @@
1
+ import type { Extension } from "@lobb-js/core";
2
+ import type { ExtensionConfig } from "./config/extensionConfigSchema.ts";
3
+
4
+ import { init } from "./database/init.ts";
5
+ import { collections } from "./collections/collections.ts";
6
+ import { meta } from "./meta/meta.ts";
7
+ import { migrations } from "./database/migrations.ts";
8
+ import { getWorkflows } from "./workflows/index.ts";
9
+
10
+ export default function auth(extensionConfig: ExtensionConfig): Extension {
11
+ return {
12
+ name: "auth",
13
+ init: (lobb) => init(lobb, extensionConfig),
14
+ collections: (lobb) => collections(lobb, extensionConfig),
15
+ migrations: migrations,
16
+ meta: (lobb) => meta(lobb, extensionConfig),
17
+ workflows: getWorkflows(extensionConfig),
18
+ };
19
+ }
@@ -0,0 +1,11 @@
1
+ import type { Lobb } from "@lobb-js/core";
2
+ import type { ExtensionConfig } from "../config/extensionConfigSchema.ts";
3
+
4
+ export async function meta(lobb: Lobb, extensionConfig: ExtensionConfig) {
5
+ const config = extensionConfig;
6
+ const meta: any = {};
7
+
8
+ meta["dashboard_access_roles"] = config.dashboard_access_roles ?? ["admin"];
9
+
10
+ return meta;
11
+ }