@lobb-js/lobb-ext-auth 0.10.4 → 0.11.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.
Files changed (56) hide show
  1. package/README.md +1 -0
  2. package/dist/auth.d.ts +2 -1
  3. package/dist/auth.js +23 -4
  4. package/dist/index.js +41 -2
  5. package/dist/lib/components/pages/settings/index.svelte +1 -1
  6. package/dist/lib/components/pages/settings/pages/activityFeed.svelte +1 -1
  7. package/dist/lib/components/pages/settings/pages/rolesAndPermissions.svelte +1 -1
  8. package/dist/lib/components/pages/settings/pages/users.svelte +1 -1
  9. package/dist/lib/components/pages/userSettings/index.svelte +45 -32
  10. package/dist/onStartup.js +17 -2
  11. package/extensions/auth/collections/collections.ts +2 -0
  12. package/extensions/auth/collections/shares.ts +60 -0
  13. package/extensions/auth/config/extensionConfigSchema.d.ts +41 -0
  14. package/extensions/auth/config/permissionsAction/create.d.ts +18 -0
  15. package/extensions/auth/config/permissionsAction/delete.d.ts +3 -0
  16. package/extensions/auth/config/permissionsAction/read.d.ts +11 -0
  17. package/extensions/auth/config/permissionsAction/update.d.ts +18 -0
  18. package/extensions/auth/index.ts +0 -2
  19. package/extensions/auth/permissions.d.ts +2 -0
  20. package/extensions/auth/permissions.ts +34 -0
  21. package/extensions/auth/studio/auth.ts +25 -5
  22. package/extensions/auth/studio/index.ts +44 -2
  23. package/extensions/auth/studio/lib/components/pages/settings/index.svelte +1 -1
  24. package/extensions/auth/studio/lib/components/pages/settings/pages/activityFeed.svelte +1 -1
  25. package/extensions/auth/studio/lib/components/pages/settings/pages/rolesAndPermissions.svelte +1 -1
  26. package/extensions/auth/studio/lib/components/pages/settings/pages/users.svelte +1 -1
  27. package/extensions/auth/studio/lib/components/pages/userSettings/index.svelte +45 -32
  28. package/extensions/auth/studio/onStartup.ts +14 -2
  29. package/extensions/auth/tests/collections/shares.test.ts +657 -0
  30. package/extensions/auth/tests/configs/auth.ts +17 -0
  31. package/extensions/auth/tests/controllers/me.test.ts +104 -0
  32. package/extensions/auth/tests/permissions.test.ts +127 -0
  33. package/extensions/auth/tests/workflows/shareIntersection.test.ts +158 -0
  34. package/extensions/auth/workflows/baseWorkflow.ts +48 -26
  35. package/extensions/auth/workflows/currentUserPermissionsWorkflow.ts +32 -0
  36. package/extensions/auth/workflows/index.ts +12 -0
  37. package/extensions/auth/workflows/meAliasWorkflows.ts +26 -0
  38. package/extensions/auth/workflows/policiesWorkflows.ts +64 -117
  39. package/extensions/auth/workflows/shareIntersection.ts +64 -0
  40. package/extensions/auth/workflows/sharesWorkflows.ts +135 -0
  41. package/extensions/auth/workflows/utils.ts +132 -224
  42. package/package.json +4 -6
  43. package/dist/lib/components/pages/userSettings/components/account.svelte +0 -106
  44. package/dist/lib/components/pages/userSettings/components/account.svelte.d.ts +0 -14
  45. package/dist/lib/components/pages/userSettings/components/profile.svelte +0 -87
  46. package/dist/lib/components/pages/userSettings/components/profile.svelte.d.ts +0 -14
  47. package/dist/tests/login.spec.d.ts +0 -1
  48. package/dist/tests/login.spec.js +0 -27
  49. package/dist/tests/package.json +0 -1
  50. package/dist/tests/playwright.config.cjs +0 -27
  51. package/dist/tests/playwright.config.d.cts +0 -2
  52. package/extensions/auth/studio/lib/components/pages/userSettings/components/account.svelte +0 -106
  53. package/extensions/auth/studio/lib/components/pages/userSettings/components/profile.svelte +0 -87
  54. package/extensions/auth/studio/tests/login.spec.ts +0 -34
  55. package/extensions/auth/studio/tests/package.json +0 -1
  56. package/extensions/auth/studio/tests/playwright.config.cjs +0 -27
@@ -1 +0,0 @@
1
- export {};
@@ -1,27 +0,0 @@
1
- import { test, expect } from "@playwright/test";
2
- const ADMIN_EMAIL = "admin@example.com";
3
- const ADMIN_PASSWORD = "admin";
4
- const LOGIN_URL = "/studio/extensions/auth/login_page";
5
- const STUDIO_URL = "/studio";
6
- test.describe("Login page", () => {
7
- test.beforeEach(async ({ page }) => {
8
- await page.goto(LOGIN_URL);
9
- });
10
- test("shows the login form", async ({ page }) => {
11
- await expect(page.getByText("Welcome back")).toBeVisible();
12
- await expect(page.getByPlaceholder("email@example.com")).toBeVisible();
13
- await expect(page.getByPlaceholder("••••••••")).toBeVisible();
14
- await expect(page.getByRole("button", { name: "Sign In" })).toBeVisible();
15
- });
16
- test("logs in with valid credentials and redirects to studio", async ({ page }) => {
17
- await page.getByPlaceholder("email@example.com").fill(ADMIN_EMAIL);
18
- await page.getByPlaceholder("••••••••").fill(ADMIN_PASSWORD);
19
- await page.getByRole("button", { name: "Sign In" }).click();
20
- await page.waitForURL(STUDIO_URL);
21
- expect(page.url()).toContain(STUDIO_URL);
22
- });
23
- test("shows error toast on empty form submission", async ({ page }) => {
24
- await page.getByRole("button", { name: "Sign In" }).click();
25
- await expect(page.getByText("Please complete all fields")).toBeVisible();
26
- });
27
- });
@@ -1 +0,0 @@
1
- {"type": "commonjs"}
@@ -1,27 +0,0 @@
1
- const { defineConfig, devices } = require("@playwright/test");
2
-
3
- module.exports = defineConfig({
4
- testDir: __dirname,
5
- testMatch: "**/*.spec.ts",
6
- fullyParallel: true,
7
- retries: 0,
8
- expect: { timeout: 15000 },
9
- use: {
10
- baseURL: "http://localhost:3000",
11
- trace: "on-first-retry",
12
- headless: true,
13
- },
14
- projects: [
15
- {
16
- name: "chromium",
17
- use: { ...devices["Desktop Chrome"] },
18
- },
19
- ],
20
- // Automatically start the dev server before running tests
21
- webServer: {
22
- command: "bun run dev",
23
- url: "http://localhost:3000/studio",
24
- reuseExistingServer: true,
25
- cwd: "../../../../", // packages/auth-ext root
26
- },
27
- });
@@ -1,2 +0,0 @@
1
- declare const _exports: import("@playwright/test").Config<import("@playwright/test").PlaywrightTestOptions & {}, import("@playwright/test").PlaywrightWorkerOptions & {}>;
2
- export = _exports;
@@ -1,106 +0,0 @@
1
- <script lang="ts">
2
- import type { ExtensionProps } from "@lobb-js/studio";
3
- import { onMount } from "svelte";
4
-
5
- const { utils }: ExtensionProps = $props();
6
-
7
- let user = $state({
8
- old_password: "",
9
- new_password: "",
10
- });
11
- const icons = utils.components.Icons;
12
-
13
- // @ts-ignore: Im sure the session object exist
14
- const currentUserId = utils.ctx.extensions.auth.session.user.id;
15
- let loaded = $state(false);
16
- onMount(async () => {
17
- const response = await utils.lobb.findOne("auth_users", currentUserId);
18
- const result = await response.json();
19
- user = result.data;
20
- loaded = true;
21
- });
22
-
23
- async function onUpdateCLick() {
24
- if (!user.new_password) {
25
- utils.toast.error("Make sure you fill the new password");
26
- return;
27
- } else if (!user.old_password) {
28
- utils.toast.error("Make sure you fill the old password");
29
- return;
30
- }
31
-
32
- const result = await utils.lobb.request({
33
- method: "POST",
34
- route: "/api/extensions/auth/change_password",
35
- payload: {
36
- old_password: user.old_password,
37
- new_password: user.new_password,
38
- },
39
- });
40
-
41
- if (result.status >= 400) {
42
- return;
43
- }
44
-
45
- utils.toast.success("Account updated successfully.");
46
- }
47
- </script>
48
-
49
- {#if loaded}
50
- <div class="flex max-w-[40rem] flex-1 flex-col gap-4 overflow-y-visible">
51
- <div>
52
- <div class="text-lg font-semibold">Account</div>
53
- <div class="text-sm text-muted-foreground">
54
- Update your account settings.
55
- </div>
56
- </div>
57
- <utils.components.Separator />
58
- <!-- TODO: add prefered language here too -->
59
- <div class="flex flex-col gap-2">
60
- <div class="text-sm">Change Password</div>
61
- <div class="flex gap-4">
62
- <utils.components.Input
63
- bind:value={user.old_password}
64
- placeholder="Old password"
65
- type="password"
66
- />
67
- <utils.components.Input
68
- bind:value={user.new_password}
69
- placeholder="New password"
70
- type="password"
71
- />
72
- </div>
73
- <div class="text-xs text-muted-foreground">
74
- This is where you can change your password.
75
- </div>
76
- </div>
77
- <utils.components.Button
78
- class="self-start"
79
- onclick={onUpdateCLick}
80
- Icon={icons.Pencil}
81
- >
82
- Update Account
83
- </utils.components.Button>
84
- </div>
85
- {:else}
86
- <div class="flex max-w-[40rem] flex-1 flex-col gap-8 overflow-y-visible">
87
- <div class="grid gap-2">
88
- <utils.components.Skeleton class="h-8 w-full max-w-60" />
89
- <utils.components.Skeleton class="h-4 w-full max-w-96" />
90
- </div>
91
- <utils.components.Separator />
92
- <div class="flex flex-col gap-2">
93
- <utils.components.Skeleton class="h-4 w-full max-w-36" />
94
- <utils.components.Skeleton class="h-8 w-full max-w-60" />
95
- <utils.components.Skeleton class="h-4 w-full max-w-96" />
96
- </div>
97
- <div class="flex flex-col gap-2">
98
- <utils.components.Skeleton class="h-4 w-full max-w-36" />
99
- <div class="flex gap-4">
100
- <utils.components.Skeleton class="h-8 w-full max-w-60" />
101
- <utils.components.Skeleton class="h-8 w-full max-w-60" />
102
- </div>
103
- <utils.components.Skeleton class="h-4 w-full max-w-96" />
104
- </div>
105
- </div>
106
- {/if}
@@ -1,87 +0,0 @@
1
- <script lang="ts">
2
- import type { ExtensionProps } from "@lobb-js/studio";
3
- import { onMount } from "svelte";
4
-
5
- const { utils }: ExtensionProps = $props();
6
-
7
- let user = $state({
8
- name: "",
9
- });
10
- const icons = utils.components.Icons;
11
-
12
- // @ts-ignore: Im sure the session object exist
13
- const currentUserId = utils.ctx.extensions.auth.session.user.id;
14
- let loaded = $state(false);
15
- onMount(async () => {
16
- const response = await utils.lobb.findOne("auth_users", currentUserId);
17
- const result = await response.json();
18
- user = result.data;
19
- loaded = true;
20
- });
21
-
22
- async function onUpdateCLick() {
23
- // TODO: add the logic of updating some of the current user's information
24
- const updateObject: any = {};
25
- updateObject["name"] = user.name;
26
- const response = await utils.lobb.updateOne(
27
- "auth_users",
28
- currentUserId,
29
- updateObject,
30
- );
31
- if (response.status >= 400) {
32
- const result = await response.json();
33
- utils.toast.error(result.message);
34
- return;
35
- }
36
- utils.toast.success("Profile updated successfully.");
37
- }
38
- </script>
39
-
40
- {#if loaded}
41
- <div class="flex max-w-[40rem] flex-1 flex-col gap-4 overflow-y-visible">
42
- <div>
43
- <div class="text-lg font-semibold">Profile</div>
44
- <div class="text-sm text-muted-foreground">
45
- Edit information that others will see.
46
- </div>
47
- </div>
48
- <utils.components.Separator />
49
- <!-- TODO: you should add name and other stuff like phone number and stuff like that -->
50
- <div class="flex flex-col gap-2">
51
- <div class="text-sm">Full Name</div>
52
- <utils.components.Input
53
- placeholder="Full Name"
54
- bind:value={user.name}
55
- />
56
- <div class="text-xs text-muted-foreground">
57
- This is your public display name. It can be your real name or a
58
- pseudonym.
59
- </div>
60
- </div>
61
- <utils.components.Button
62
- class="self-start"
63
- onclick={onUpdateCLick}
64
- Icon={icons.Pencil}
65
- >
66
- Update Profile
67
- </utils.components.Button>
68
- </div>
69
- {:else}
70
- <div class="flex max-w-[40rem] flex-1 flex-col gap-8 overflow-y-visible">
71
- <div class="grid gap-2">
72
- <utils.components.Skeleton class="h-8 w-full max-w-60" />
73
- <utils.components.Skeleton class="h-4 w-full max-w-96" />
74
- </div>
75
- <utils.components.Separator />
76
- <div class="flex flex-col gap-2">
77
- <utils.components.Skeleton class="h-4 w-full max-w-36" />
78
- <utils.components.Skeleton class="h-8 w-full max-w-60" />
79
- <utils.components.Skeleton class="h-4 w-full max-w-96" />
80
- </div>
81
- <div class="flex flex-col gap-2">
82
- <utils.components.Skeleton class="h-4 w-full max-w-36" />
83
- <utils.components.Skeleton class="h-8 w-full max-w-60" />
84
- <utils.components.Skeleton class="h-4 w-full max-w-96" />
85
- </div>
86
- </div>
87
- {/if}
@@ -1,34 +0,0 @@
1
- import { test, expect } from "@playwright/test";
2
-
3
- const ADMIN_EMAIL = "admin@example.com";
4
- const ADMIN_PASSWORD = "admin";
5
- const LOGIN_URL = "/studio/extensions/auth/login_page";
6
- const STUDIO_URL = "/studio";
7
-
8
- test.describe("Login page", () => {
9
- test.beforeEach(async ({ page }) => {
10
- await page.goto(LOGIN_URL);
11
- });
12
-
13
- test("shows the login form", async ({ page }) => {
14
- await expect(page.getByText("Welcome back")).toBeVisible();
15
- await expect(page.getByPlaceholder("email@example.com")).toBeVisible();
16
- await expect(page.getByPlaceholder("••••••••")).toBeVisible();
17
- await expect(page.getByRole("button", { name: "Sign In" })).toBeVisible();
18
- });
19
-
20
- test("logs in with valid credentials and redirects to studio", async ({ page }) => {
21
- await page.getByPlaceholder("email@example.com").fill(ADMIN_EMAIL);
22
- await page.getByPlaceholder("••••••••").fill(ADMIN_PASSWORD);
23
- await page.getByRole("button", { name: "Sign In" }).click();
24
-
25
- await page.waitForURL(STUDIO_URL);
26
- expect(page.url()).toContain(STUDIO_URL);
27
- });
28
-
29
- test("shows error toast on empty form submission", async ({ page }) => {
30
- await page.getByRole("button", { name: "Sign In" }).click();
31
-
32
- await expect(page.getByText("Please complete all fields")).toBeVisible();
33
- });
34
- });
@@ -1 +0,0 @@
1
- {"type": "commonjs"}
@@ -1,27 +0,0 @@
1
- const { defineConfig, devices } = require("@playwright/test");
2
-
3
- module.exports = defineConfig({
4
- testDir: __dirname,
5
- testMatch: "**/*.spec.ts",
6
- fullyParallel: true,
7
- retries: 0,
8
- expect: { timeout: 15000 },
9
- use: {
10
- baseURL: "http://localhost:3000",
11
- trace: "on-first-retry",
12
- headless: true,
13
- },
14
- projects: [
15
- {
16
- name: "chromium",
17
- use: { ...devices["Desktop Chrome"] },
18
- },
19
- ],
20
- // Automatically start the dev server before running tests
21
- webServer: {
22
- command: "bun run dev",
23
- url: "http://localhost:3000/studio",
24
- reuseExistingServer: true,
25
- cwd: "../../../../", // packages/auth-ext root
26
- },
27
- });