@vc-shell/framework 1.1.98-rc.5 → 1.1.99-alpha.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 (96) hide show
  1. package/core/api/platform.ts +9883 -9883
  2. package/core/composables/useNotifications/index.ts +32 -1
  3. package/core/composables/useSettings/index.ts +8 -3
  4. package/core/composables/useUser/index.ts +74 -171
  5. package/core/composables/useUserManagement/index.ts +67 -25
  6. package/core/interceptors/index.ts +19 -56
  7. package/core/plugins/signalR/index.ts +27 -1
  8. package/core/providers/README.md +176 -0
  9. package/core/providers/auth-provider-manager.ts +74 -0
  10. package/core/providers/auth-provider-utils.ts +26 -0
  11. package/core/providers/example-custom-auth-provider.ts +162 -0
  12. package/core/providers/index.ts +3 -0
  13. package/core/providers/platform-auth-provider.ts +207 -0
  14. package/core/types/auth-provider.ts +40 -0
  15. package/core/types/index.ts +2 -0
  16. package/dist/core/api/platform.d.ts +1 -1
  17. package/dist/core/api/platform.d.ts.map +1 -1
  18. package/dist/core/composables/useNotifications/index.d.ts.map +1 -1
  19. package/dist/core/composables/useSettings/index.d.ts.map +1 -1
  20. package/dist/core/composables/useUser/index.d.ts +18 -9
  21. package/dist/core/composables/useUser/index.d.ts.map +1 -1
  22. package/dist/core/composables/useUserManagement/index.d.ts +7 -7
  23. package/dist/core/composables/useUserManagement/index.d.ts.map +1 -1
  24. package/dist/core/interceptors/index.d.ts +2 -1
  25. package/dist/core/interceptors/index.d.ts.map +1 -1
  26. package/dist/core/plugins/signalR/index.d.ts +2 -0
  27. package/dist/core/plugins/signalR/index.d.ts.map +1 -1
  28. package/dist/core/providers/auth-provider-manager.d.ts +34 -0
  29. package/dist/core/providers/auth-provider-manager.d.ts.map +1 -0
  30. package/dist/core/providers/auth-provider-utils.d.ts +17 -0
  31. package/dist/core/providers/auth-provider-utils.d.ts.map +1 -0
  32. package/dist/core/providers/example-custom-auth-provider.d.ts +45 -0
  33. package/dist/core/providers/example-custom-auth-provider.d.ts.map +1 -0
  34. package/dist/core/providers/index.d.ts +3 -0
  35. package/dist/core/providers/index.d.ts.map +1 -0
  36. package/dist/core/providers/platform-auth-provider.d.ts +34 -0
  37. package/dist/core/providers/platform-auth-provider.d.ts.map +1 -0
  38. package/dist/core/types/auth-provider.d.ts +27 -0
  39. package/dist/core/types/auth-provider.d.ts.map +1 -0
  40. package/dist/core/types/index.d.ts +1 -1
  41. package/dist/core/types/index.d.ts.map +1 -1
  42. package/dist/framework.js +6348 -6198
  43. package/dist/index.css +1 -1
  44. package/dist/index.d.ts +8 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/injection-keys.d.ts +2 -1
  47. package/dist/injection-keys.d.ts.map +1 -1
  48. package/dist/shared/components/app-switcher/composables/useAppSwitcher/index.d.ts.map +1 -1
  49. package/dist/shared/components/sign-in/useExternalProvider.d.ts +1 -1
  50. package/dist/shared/components/sign-in/useExternalProvider.d.ts.map +1 -1
  51. package/dist/shared/modules/dynamic/helpers/nodeBuilder.d.ts.map +1 -1
  52. package/dist/tsconfig.tsbuildinfo +1 -1
  53. package/dist/ui/components/organisms/vc-app/vc-app.vue.d.ts.map +1 -1
  54. package/dist/vendor-tiptap-core-ClsTgaMv.js +3699 -0
  55. package/dist/{vendor-tiptap-extension-blockquote-BVmAuV7o.js → vendor-tiptap-extension-blockquote-r1MBx4hD.js} +1 -1
  56. package/dist/{vendor-tiptap-extension-bold-BOh8AIRZ.js → vendor-tiptap-extension-bold-BjLI4i8b.js} +1 -1
  57. package/dist/{vendor-tiptap-extension-code-R4pc2wFE.js → vendor-tiptap-extension-code-D5-kDnMW.js} +1 -1
  58. package/dist/{vendor-tiptap-extension-code-block-DibKlZFG.js → vendor-tiptap-extension-code-block-RjEb0zPA.js} +1 -1
  59. package/dist/{vendor-tiptap-extension-document-BwORJR1k.js → vendor-tiptap-extension-document--PLOxIdq.js} +1 -1
  60. package/dist/{vendor-tiptap-extension-hard-break-DH36OfVk.js → vendor-tiptap-extension-hard-break-9cxC2YOS.js} +13 -9
  61. package/dist/{vendor-tiptap-extension-heading-oMLORiPI.js → vendor-tiptap-extension-heading-2w0TutHn.js} +1 -1
  62. package/dist/{vendor-tiptap-extension-horizontal-rule-BMHSoB_Y.js → vendor-tiptap-extension-horizontal-rule-CFowa_lc.js} +1 -1
  63. package/dist/vendor-tiptap-extension-image-aWn-na6j.js +127 -0
  64. package/dist/{vendor-tiptap-extension-italic-BzqrUuB0.js → vendor-tiptap-extension-italic-Bn-6saY0.js} +1 -1
  65. package/dist/{vendor-tiptap-extension-link-hMFZ0hfl.js → vendor-tiptap-extension-link-BmcG1_k-.js} +1 -1
  66. package/dist/{vendor-tiptap-extension-list-Bj5AK6Pq.js → vendor-tiptap-extension-list-BrNBJ45n.js} +1 -1
  67. package/dist/{vendor-tiptap-extension-paragraph-Bs1wl42E.js → vendor-tiptap-extension-paragraph-DAiYhwUB.js} +1 -1
  68. package/dist/vendor-tiptap-extension-placeholder-9tURDKy-.js +1 -0
  69. package/dist/{vendor-tiptap-extension-strike-C4YpGyzc.js → vendor-tiptap-extension-strike-DqbXPfos.js} +1 -1
  70. package/dist/vendor-tiptap-extension-table-DQwPaR7v.js +374 -0
  71. package/dist/vendor-tiptap-extension-table-cell-C0tEP_0i.js +1 -0
  72. package/dist/vendor-tiptap-extension-table-header-C0tEP_0i.js +1 -0
  73. package/dist/vendor-tiptap-extension-table-row-C0tEP_0i.js +1 -0
  74. package/dist/{vendor-tiptap-extension-text-C4dQW13r.js → vendor-tiptap-extension-text-BFnfj70b.js} +1 -1
  75. package/dist/{vendor-tiptap-extension-text-style-a_NYjXT6.js → vendor-tiptap-extension-text-style-Darua3qr.js} +1 -1
  76. package/dist/{vendor-tiptap-extension-underline-DthCaPX3.js → vendor-tiptap-extension-underline-QyVnBqQZ.js} +1 -1
  77. package/dist/{vendor-tiptap-extensions-C8rF1qdq.js → vendor-tiptap-extensions-CU-D7bfm.js} +1 -1
  78. package/dist/{vendor-tiptap-markdown-DRc3qhBU.js → vendor-tiptap-markdown-BwATYN5A.js} +1 -1
  79. package/dist/{vendor-tiptap-starter-kit-BfUUblkP.js → vendor-tiptap-starter-kit-5luf7zzS.js} +17 -17
  80. package/dist/{vendor-tiptap-vue-3-DYxT2sf6.js → vendor-tiptap-vue-3-CFBErZGb.js} +1 -1
  81. package/dist/{vendor-vueuse-components-B0zqjNRW.js → vendor-vueuse-components-sgKpNzof.js} +1 -1
  82. package/dist/{vendor-vueuse-core-CYgwn-B2.js → vendor-vueuse-core-D0cN7FqY.js} +10 -10
  83. package/dist/{vendor-vueuse-shared-B_uDJJ6V.js → vendor-vueuse-shared-Pt0UEStA.js} +19 -19
  84. package/package.json +7 -5
  85. package/shared/components/app-switcher/components/vc-app-switcher/vc-app-switcher.vue +2 -2
  86. package/shared/components/app-switcher/composables/useAppSwitcher/index.ts +15 -1
  87. package/shared/components/sign-in/useExternalProvider.ts +11 -1
  88. package/shared/modules/dynamic/helpers/nodeBuilder.ts +11 -3
  89. package/ui/components/organisms/vc-app/vc-app.vue +20 -2
  90. package/dist/vendor-tiptap-core-8RGSOCZs.js +0 -3442
  91. package/dist/vendor-tiptap-extension-image-DF1ZJ94q.js +0 -80
  92. package/dist/vendor-tiptap-extension-placeholder-CupUGaI_.js +0 -1
  93. package/dist/vendor-tiptap-extension-table-D8RFr_6X.js +0 -368
  94. package/dist/vendor-tiptap-extension-table-cell-k9uLwyL6.js +0 -1
  95. package/dist/vendor-tiptap-extension-table-header-k9uLwyL6.js +0 -1
  96. package/dist/vendor-tiptap-extension-table-row-k9uLwyL6.js +0 -1
@@ -0,0 +1,176 @@
1
+ # Authentication Providers
2
+
3
+ This directory contains authentication provider implementations for the vc-shell framework.
4
+
5
+ ## Overview
6
+
7
+ The vc-shell framework uses a pluggable authentication system that allows you to implement custom authentication logic while maintaining compatibility with all framework pages (Login, ResetPassword, ChangePassword, Invite).
8
+
9
+ ## Available Providers
10
+
11
+ ### PlatformAuthProvider (Default)
12
+
13
+ The default authentication provider that uses VirtoCommerce Platform API for authentication.
14
+
15
+ ```typescript
16
+ import { PlatformAuthProvider } from "@vc-shell/framework";
17
+
18
+ const authProvider = new PlatformAuthProvider();
19
+ ```
20
+
21
+ This provider is used automatically if no custom provider is specified.
22
+
23
+ ## Creating a Custom Provider
24
+
25
+ To create a custom authentication provider, implement the `IAuthProvider` interface:
26
+
27
+ ```typescript
28
+ import { IAuthProvider, UserDetail, SignInResult } from "@vc-shell/framework";
29
+ import { computed, ref } from "vue";
30
+
31
+ export class CustomAuthProvider implements IAuthProvider {
32
+ private _user = ref<UserDetail | undefined>();
33
+ private _loading = ref(false);
34
+
35
+ get user() {
36
+ return computed(() => this._user.value);
37
+ }
38
+
39
+ get loading() {
40
+ return computed(() => this._loading.value);
41
+ }
42
+
43
+ get isAuthenticated() {
44
+ return computed(() => this._user.value?.userName != null);
45
+ }
46
+
47
+ get isAdministrator() {
48
+ return computed(() => this._user.value?.isAdministrator);
49
+ }
50
+
51
+ async loadUser(): Promise<UserDetail> {
52
+ // Your custom logic to load user
53
+ // Example: from localStorage, file, custom API, etc.
54
+ }
55
+
56
+ async signIn(username: string, password: string): Promise<SignInResult> {
57
+ // Your custom sign-in logic
58
+ }
59
+
60
+ async signOut(): Promise<void> {
61
+ // Your custom sign-out logic
62
+ }
63
+
64
+ // Implement other required methods...
65
+ }
66
+ ```
67
+
68
+ See `example-custom-auth-provider.ts` for a complete implementation example.
69
+
70
+ ## Required Methods
71
+
72
+ All authentication providers must implement the following methods:
73
+
74
+ ### Core Methods
75
+ - `loadUser()` - Load current authenticated user
76
+ - `signIn(username, password)` - Authenticate user with credentials
77
+ - `signOut()` - Sign out current user
78
+
79
+ ### Password Management Methods
80
+ - `validateToken(userId, token)` - Validate password reset token
81
+ - `validatePassword(password)` - Validate password strength
82
+ - `resetPasswordByToken(userId, password, token)` - Reset password using token
83
+ - `requestPasswordReset(loginOrEmail)` - Request password reset email
84
+ - `changeUserPassword(oldPassword, newPassword)` - Change current user password
85
+
86
+ ### Additional Methods
87
+ - `getLoginType()` - Get available login types (e.g., local, external)
88
+
89
+ ### Properties
90
+ - `user` - Current user details (ComputedRef)
91
+ - `loading` - Loading state (ComputedRef)
92
+ - `isAuthenticated` - Authentication status (ComputedRef)
93
+ - `isAdministrator` - Administrator status (ComputedRef)
94
+
95
+ ## Using a Custom Provider
96
+
97
+ To use a custom authentication provider in your application:
98
+
99
+ ```typescript
100
+ import VirtoShellFramework from "@vc-shell/framework";
101
+ import { CustomAuthProvider } from "./auth/custom-provider";
102
+
103
+ const app = createApp(App);
104
+ const customAuthProvider = new CustomAuthProvider();
105
+
106
+ app.use(VirtoShellFramework, {
107
+ router,
108
+ authProvider: customAuthProvider, // Pass your custom provider
109
+ i18n: {
110
+ locale: "en",
111
+ fallbackLocale: "en",
112
+ },
113
+ });
114
+ ```
115
+
116
+ ## Type Safety
117
+
118
+ All providers use the same types from the platform API:
119
+ - `UserDetail` - User information
120
+ - `SignInResult` - Sign-in result
121
+ - `SecurityResult` - Security operation result
122
+ - `IdentityResult` - Identity validation result
123
+ - `LoginType` - Login type enumeration
124
+
125
+ This ensures compatibility across all authentication pages and interceptors.
126
+
127
+ ## Integration with Framework
128
+
129
+ The authentication provider integrates with:
130
+
131
+ 1. **Login Pages** - All auth pages (Login, ResetPassword, ChangePassword, Invite) automatically use the provided auth provider
132
+ 2. **HTTP Interceptors** - Automatically handles 401 errors and redirects to login
133
+ 3. **Route Guards** - Checks authentication status before route navigation
134
+ 4. **Composables** - Available via `useUser()` and `useUserManagement()` composables
135
+
136
+ ## Example Use Cases
137
+
138
+ ### File-based Authentication
139
+ ```typescript
140
+ class FileAuthProvider implements IAuthProvider {
141
+ async signIn(username: string, password: string) {
142
+ const credentials = await fetch("/auth-data.json");
143
+ const users = await credentials.json();
144
+ // Validate against file data
145
+ }
146
+ }
147
+ ```
148
+
149
+ ### Custom API Authentication
150
+ ```typescript
151
+ class CustomApiAuthProvider implements IAuthProvider {
152
+ async signIn(username: string, password: string) {
153
+ const response = await fetch("https://my-custom-api.com/auth", {
154
+ method: "POST",
155
+ body: JSON.stringify({ username, password }),
156
+ });
157
+ // Handle custom API response
158
+ }
159
+ }
160
+ ```
161
+
162
+ ### OAuth/OIDC Provider
163
+ ```typescript
164
+ class OAuthAuthProvider implements IAuthProvider {
165
+ async signIn(username: string, password: string) {
166
+ // Redirect to OAuth provider
167
+ window.location.href = "https://oauth-provider.com/authorize";
168
+ }
169
+ }
170
+ ```
171
+
172
+ ## Backward Compatibility
173
+
174
+ If no custom provider is specified, the framework automatically uses `PlatformAuthProvider`, ensuring full backward compatibility with existing applications.
175
+
176
+
@@ -0,0 +1,74 @@
1
+ import { IAuthProvider } from "../types/auth-provider";
2
+ import { PlatformAuthProvider } from "./platform-auth-provider";
3
+
4
+ /**
5
+ * Global auth provider manager
6
+ * Provides access to auth provider before Vue app context is available
7
+ * This is necessary for early initialization scenarios where composables
8
+ * are called before app.use(VirtoShellFramework)
9
+ */
10
+ class AuthProviderManager {
11
+ private provider: IAuthProvider | null = null;
12
+ private defaultProvider: IAuthProvider | null = null;
13
+ private configureWasCalled = false;
14
+
15
+ /**
16
+ * Set the global auth provider
17
+ * Should be called via VirtoShellFramework.configure() before any composables
18
+ * If custom provider is provided, it will replace the default
19
+ */
20
+ setProvider(provider: IAuthProvider): void {
21
+ console.log("[AuthProviderManager] Setting auth provider:", provider.constructor.name);
22
+ this.configureWasCalled = true;
23
+ this.provider = provider;
24
+ }
25
+
26
+ /**
27
+ * Get the global auth provider
28
+ * Lazy-initializes default PlatformAuthProvider if no custom provider was set
29
+ */
30
+ getProvider(): IAuthProvider {
31
+ // If custom provider was set, use it
32
+ if (this.provider) {
33
+ return this.provider;
34
+ }
35
+
36
+ // Lazy-initialize default platform provider only when needed (backward compatibility)
37
+ if (!this.defaultProvider) {
38
+ console.log("[AuthProviderManager] Lazy-initializing default PlatformAuthProvider");
39
+
40
+ // Show deprecation warning only if configure() was never called
41
+ if (!this.configureWasCalled) {
42
+ console.warn(
43
+ "[AuthProviderManager] DEPRECATION WARNING: " +
44
+ "Automatic PlatformAuthProvider creation will be removed in a future version. " +
45
+ "Please use VirtoShellFramework.configure({ authProvider }) explicitly before calling useUser()."
46
+ );
47
+ }
48
+
49
+ this.defaultProvider = new PlatformAuthProvider();
50
+ }
51
+
52
+ return this.defaultProvider;
53
+ }
54
+
55
+ /**
56
+ * Check if provider is available
57
+ */
58
+ hasProvider(): boolean {
59
+ return this.provider !== null || this.defaultProvider !== null;
60
+ }
61
+
62
+ /**
63
+ * Reset manager (for testing)
64
+ */
65
+ reset(): void {
66
+ this.provider = null;
67
+ this.defaultProvider = null;
68
+ this.configureWasCalled = false;
69
+ }
70
+ }
71
+
72
+ // Global singleton instance
73
+ export const authProviderManager = new AuthProviderManager();
74
+
@@ -0,0 +1,26 @@
1
+ import { IAuthProvider } from "../types/auth-provider";
2
+ import { PlatformAuthProvider } from "./platform-auth-provider";
3
+
4
+ /**
5
+ * Check if the provider is a platform provider
6
+ * Centralized logic for determining platform-specific features availability
7
+ */
8
+ export function isPlatformProvider(provider: IAuthProvider | null | undefined): boolean {
9
+ return provider instanceof PlatformAuthProvider;
10
+ }
11
+
12
+ /**
13
+ * Check if platform-specific features should be enabled
14
+ * This is the main function to use throughout the framework
15
+ */
16
+ export function shouldEnablePlatformFeatures(provider: IAuthProvider | null | undefined): boolean {
17
+ return isPlatformProvider(provider);
18
+ }
19
+
20
+ /**
21
+ * Get a safe provider instance with fallback
22
+ * Handles null/undefined cases gracefully
23
+ */
24
+ export function getSafeProvider(provider: IAuthProvider | null | undefined): IAuthProvider | null {
25
+ return provider || null;
26
+ }
@@ -0,0 +1,162 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /**
3
+ * Example Custom Authentication Provider
4
+ *
5
+ * This is an example implementation showing how to create a custom authentication provider.
6
+ * You can use this as a template to implement your own authentication logic.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { CustomAuthProvider } from './auth/custom-provider';
11
+ *
12
+ * const customAuthProvider = new CustomAuthProvider();
13
+ *
14
+ * app.use(VirtoShellFramework, {
15
+ * router,
16
+ * authProvider: customAuthProvider,
17
+ * i18n: { ... }
18
+ * });
19
+ * ```
20
+ */
21
+
22
+ import { computed, Ref, ref, ComputedRef } from "vue";
23
+ import {
24
+ UserDetail,
25
+ SecurityResult,
26
+ IdentityResult,
27
+ LoginType,
28
+ SignInResult,
29
+ IIdentityResult,
30
+ } from "../api/platform";
31
+ import { RequestPasswordResult } from "../types";
32
+ import { IAuthProvider } from "../types/auth-provider";
33
+
34
+ export class CustomAuthProvider implements IAuthProvider {
35
+
36
+ private _user: Ref<UserDetail | undefined> = ref();
37
+ private _loading: Ref<boolean> = ref(false);
38
+
39
+ get user(): ComputedRef<UserDetail | undefined> {
40
+ return computed(() => this._user.value);
41
+ }
42
+
43
+ get loading(): ComputedRef<boolean> {
44
+ return computed(() => this._loading.value);
45
+ }
46
+
47
+ get isAuthenticated(): ComputedRef<boolean> {
48
+ return computed(() => this._user.value?.userName != null);
49
+ }
50
+
51
+ get isAdministrator(): ComputedRef<boolean | undefined> {
52
+ return computed(() => this._user.value?.isAdministrator);
53
+ }
54
+
55
+ async loadUser(): Promise<UserDetail> {
56
+ // Implement your custom user loading logic
57
+ // Example: Load from localStorage, custom API, etc.
58
+ console.debug("[CustomAuthProvider] Loading user...");
59
+
60
+ this._loading.value = true;
61
+
62
+ try {
63
+ // Example: Load from localStorage
64
+ const storedUser = localStorage.getItem("customUser");
65
+ if (storedUser) {
66
+ this._user.value = JSON.parse(storedUser) as UserDetail;
67
+ }
68
+ } catch (e) {
69
+ console.error("Failed to load user:", e);
70
+ } finally {
71
+ this._loading.value = false;
72
+ }
73
+
74
+ return { ...this._user.value } as UserDetail;
75
+ }
76
+
77
+ async signIn(
78
+ username: string,
79
+ password: string,
80
+ ): Promise<SignInResult | { succeeded: boolean; error?: any; status?: number }> {
81
+ console.debug("[CustomAuthProvider] Signing in...");
82
+
83
+ this._loading.value = true;
84
+
85
+ try {
86
+ // Implement your custom sign-in logic
87
+ // Example: Validate against local file, custom API, etc.
88
+
89
+ // Example implementation:
90
+ if (username === "demo" && password === "demo") {
91
+ this._user.value = {
92
+ userName: username,
93
+ isAdministrator: true,
94
+ // ... other user properties
95
+ } as UserDetail;
96
+
97
+ // Store user in localStorage
98
+ localStorage.setItem("customUser", JSON.stringify(this._user.value));
99
+
100
+ return { succeeded: true } as SignInResult;
101
+ }
102
+
103
+ return { succeeded: false, error: "Invalid credentials" };
104
+ } catch (e: any) {
105
+ console.error("Sign in failed:", e);
106
+ return { succeeded: false, error: e.message };
107
+ } finally {
108
+ this._loading.value = false;
109
+ }
110
+ }
111
+
112
+ async signOut(): Promise<void> {
113
+ console.debug("[CustomAuthProvider] Signing out...");
114
+
115
+ this._user.value = undefined;
116
+ localStorage.removeItem("customUser");
117
+ }
118
+
119
+ async validateToken(userId: string, token: string): Promise<boolean> {
120
+ // Implement your custom token validation logic
121
+ console.debug("[CustomAuthProvider] Validating token...");
122
+ return false;
123
+ }
124
+
125
+ async validatePassword(password: string): Promise<IIdentityResult> {
126
+ // Implement your custom password validation logic
127
+ console.debug("[CustomAuthProvider] Validating password...");
128
+ return { succeeded: true } as IIdentityResult;
129
+ }
130
+
131
+ async resetPasswordByToken(
132
+ userId: string,
133
+ password: string,
134
+ token: string,
135
+ ): Promise<SecurityResult> {
136
+ // Implement your custom password reset logic
137
+ console.debug("[CustomAuthProvider] Resetting password...");
138
+ return { succeeded: true } as SecurityResult;
139
+ }
140
+
141
+ async requestPasswordReset(loginOrEmail: string): Promise<RequestPasswordResult> {
142
+ // Implement your custom password reset request logic
143
+ console.debug("[CustomAuthProvider] Requesting password reset...");
144
+ return { succeeded: true };
145
+ }
146
+
147
+ async changeUserPassword(
148
+ oldPassword: string,
149
+ newPassword: string,
150
+ ): Promise<SecurityResult | undefined> {
151
+ // Implement your custom password change logic
152
+ console.debug("[CustomAuthProvider] Changing password...");
153
+ return { succeeded: true } as SecurityResult;
154
+ }
155
+
156
+ async getLoginType(): Promise<LoginType[]> {
157
+ // Return supported login types for your custom provider
158
+ console.debug("[CustomAuthProvider] Getting login types...");
159
+ return [];
160
+ }
161
+ }
162
+
@@ -0,0 +1,3 @@
1
+ export { PlatformAuthProvider } from "./platform-auth-provider";
2
+ export { authProviderManager } from "./auth-provider-manager";
3
+
@@ -0,0 +1,207 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { computed, Ref, ref, ComputedRef } from "vue";
3
+ import {
4
+ UserDetail,
5
+ SecurityClient,
6
+ ResetPasswordConfirmRequest,
7
+ SecurityResult,
8
+ ValidatePasswordResetTokenRequest,
9
+ IdentityResult,
10
+ ChangePasswordRequest,
11
+ LoginType,
12
+ LoginRequest,
13
+ SignInResult,
14
+ IIdentityResult,
15
+ ISecurityResult,
16
+ } from "../api/platform";
17
+ import { RequestPasswordResult } from "../types";
18
+ import { useExternalProvider } from "../../shared/components/sign-in/useExternalProvider";
19
+ import { IAuthProvider } from "../types/auth-provider";
20
+
21
+ const DEMO_USER = {
22
+ id: "demo_user_id",
23
+ userName: "DEMO_USER",
24
+ isAdministrator: true,
25
+ } as UserDetail;
26
+
27
+ /**
28
+ * Platform-based authentication provider
29
+ * Implements authentication using VirtoCommerce Platform API
30
+ */
31
+ export class PlatformAuthProvider implements IAuthProvider {
32
+ private _user: Ref<UserDetail | undefined> = ref();
33
+ private _loading: Ref<boolean> = ref(false);
34
+ private securityClient: SecurityClient;
35
+ private externalSignInStorage: ReturnType<typeof useExternalProvider>["storage"];
36
+ private externalSignOut: ReturnType<typeof useExternalProvider>["signOut"];
37
+
38
+ constructor() {
39
+ console.log("🔐 [PlatformAuthProvider] Constructor called - using PLATFORM authentication");
40
+ this.securityClient = new SecurityClient();
41
+ const { storage, signOut } = useExternalProvider();
42
+ this.externalSignInStorage = storage;
43
+ this.externalSignOut = signOut;
44
+ }
45
+
46
+ get user(): ComputedRef<UserDetail | undefined> {
47
+ return computed(() => this._user.value);
48
+ }
49
+
50
+ get loading(): ComputedRef<boolean> {
51
+ return computed(() => this._loading.value);
52
+ }
53
+
54
+ get isAuthenticated(): ComputedRef<boolean> {
55
+ return computed(() => this._user.value?.userName != null);
56
+ }
57
+
58
+ get isAdministrator(): ComputedRef<boolean | undefined> {
59
+ return computed(() => this._user.value?.isAdministrator);
60
+ }
61
+
62
+ async validateToken(userId: string, token: string): Promise<boolean> {
63
+ let result = false;
64
+ try {
65
+ this._loading.value = true;
66
+ result = await this.securityClient.validatePasswordResetToken(userId, {
67
+ token,
68
+ } as ValidatePasswordResetTokenRequest);
69
+ } catch (e) {
70
+ //TODO: log error
71
+ } finally {
72
+ this._loading.value = false;
73
+ }
74
+ return result;
75
+ }
76
+
77
+ async validatePassword(password: string): Promise<IIdentityResult> {
78
+ return this.securityClient.validatePassword(password) as Promise<IIdentityResult>;
79
+ }
80
+
81
+ async resetPasswordByToken(userId: string, password: string, token: string): Promise<ISecurityResult> {
82
+ return this.securityClient.resetPasswordByToken(userId, {
83
+ newPassword: password,
84
+ token,
85
+ } as ResetPasswordConfirmRequest);
86
+ }
87
+
88
+ async signIn(
89
+ username: string,
90
+ password: string,
91
+ ): Promise<SignInResult | { succeeded: boolean; error?: any; status?: number }> {
92
+ console.debug(`[@vc-shell/framework#PlatformAuthProvider:signIn] - Entry point`);
93
+
94
+ // Handle demo mode for platform provider
95
+ if (window.__DEMO_MODE__) {
96
+ console.warn("[PlatformAuthProvider] Running in DEMO mode - authentication is mocked");
97
+ this._user.value = DEMO_USER as UserDetail;
98
+ return { succeeded: true } as SignInResult;
99
+ }
100
+
101
+ try {
102
+ this._loading.value = true;
103
+ const result = await this.securityClient.login(new LoginRequest({ userName: username, password }));
104
+ return await this.securityClient
105
+ .getCurrentUser()
106
+ .then((res) => {
107
+ if (res) {
108
+ this._user.value = res;
109
+ return result;
110
+ }
111
+ throw { succeeded: false };
112
+ })
113
+ .catch((e) => {
114
+ throw e;
115
+ });
116
+ } catch (e: any) {
117
+ //TODO: log error
118
+ console.log(e);
119
+ return { succeeded: false, error: e.message, status: e.status };
120
+ } finally {
121
+ this._loading.value = false;
122
+ }
123
+ }
124
+
125
+ async signOut(): Promise<void> {
126
+ console.debug(`[@vc-shell/framework#PlatformAuthProvider:signOut] - Entry point`);
127
+
128
+ this._user.value = undefined;
129
+
130
+ if (this.externalSignInStorage.value?.providerType) {
131
+ await this.externalSignOut(this.externalSignInStorage.value.providerType);
132
+ } else {
133
+ this.securityClient.logout();
134
+ }
135
+ }
136
+
137
+ async loadUser(): Promise<UserDetail> {
138
+ console.debug(`[@vc-shell/framework#PlatformAuthProvider:loadUser] - Entry point`);
139
+
140
+ // Handle demo mode for platform provider
141
+ if (window.__DEMO_MODE__) {
142
+ console.warn(
143
+ "[PlatformAuthProvider] Running in DEMO mode. All API calls are disabled. Please add APP_PLATFORM_URL to your application's .env file to enable API calls.",
144
+ );
145
+ this._user.value = DEMO_USER as UserDetail;
146
+ return { ...this._user.value } as UserDetail;
147
+ }
148
+
149
+ try {
150
+ this._loading.value = true;
151
+ this._user.value = await this.securityClient.getCurrentUser();
152
+ console.log("[PlatformAuthProvider]: an user details has been loaded", this._user.value);
153
+ } catch (e: any) {
154
+ console.error(e);
155
+ } finally {
156
+ this._loading.value = false;
157
+ }
158
+
159
+ return { ...this._user.value } as UserDetail;
160
+ }
161
+
162
+ async requestPasswordReset(loginOrEmail: string): Promise<RequestPasswordResult> {
163
+ try {
164
+ this._loading.value = true;
165
+ await this.securityClient.requestPasswordReset(loginOrEmail);
166
+ return { succeeded: true };
167
+ } catch (e) {
168
+ //TODO: log error
169
+ return { succeeded: false, error: e as string };
170
+ } finally {
171
+ this._loading.value = false;
172
+ }
173
+ }
174
+
175
+ async changeUserPassword(oldPassword: string, newPassword: string): Promise<SecurityResult | undefined> {
176
+ let result;
177
+
178
+ try {
179
+ this._loading.value = true;
180
+ const command = new ChangePasswordRequest({
181
+ oldPassword,
182
+ newPassword,
183
+ });
184
+
185
+ result = await this.securityClient.changeCurrentUserPassword(command);
186
+ } catch (e: any) {
187
+ return { succeeded: false, errors: [e.message] } as SecurityResult;
188
+ } finally {
189
+ this._loading.value = false;
190
+ }
191
+
192
+ return result;
193
+ }
194
+
195
+ async getLoginType(): Promise<LoginType[]> {
196
+ let result: LoginType[] | null = null;
197
+ try {
198
+ result = await this.securityClient.getLoginTypes();
199
+ } catch (e) {
200
+ console.error(e);
201
+ throw e;
202
+ }
203
+
204
+ return result;
205
+ }
206
+ }
207
+
@@ -0,0 +1,40 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { ComputedRef } from "vue";
3
+ import {
4
+ SignInResult,
5
+ IUserDetail,
6
+ ISecurityResult,
7
+ ILoginType,
8
+ IIdentityResult,
9
+ } from "../api/platform";
10
+ import { RequestPasswordResult } from "./index";
11
+
12
+ /**
13
+ * Interface for authentication provider
14
+ * Allows custom authentication implementations while maintaining compatibility with all framework pages
15
+ */
16
+ export interface IAuthProvider {
17
+ // Core properties
18
+ user: ComputedRef<IUserDetail | undefined>;
19
+ loading: ComputedRef<boolean>;
20
+ isAuthenticated: ComputedRef<boolean>;
21
+ isAdministrator: ComputedRef<boolean | undefined>;
22
+
23
+ // Core methods
24
+ loadUser(): Promise<IUserDetail>;
25
+ signIn(
26
+ username: string,
27
+ password: string,
28
+ ): Promise<SignInResult | { succeeded: boolean; error?: any; status?: number }>;
29
+ signOut(): Promise<void>;
30
+
31
+ // Password management methods
32
+ validateToken(userId: string, token: string): Promise<boolean>;
33
+ validatePassword(password: string): Promise<IIdentityResult>;
34
+ resetPasswordByToken(userId: string, password: string, token: string): Promise<ISecurityResult>;
35
+ requestPasswordReset(loginOrEmail: string): Promise<RequestPasswordResult>;
36
+ changeUserPassword(oldPassword: string, newPassword: string): Promise<ISecurityResult | undefined>;
37
+
38
+ // Additional methods
39
+ getLoginType(): Promise<ILoginType[]>;
40
+ }
@@ -233,3 +233,5 @@ export interface MenuItemConfig {
233
233
  inGroupPriority?: number;
234
234
  permissions?: string | string[];
235
235
  }
236
+
237
+ export * from "./auth-provider";