@equinor/fusion-framework-module-msal 4.0.8 → 4.1.0

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 (46) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +203 -48
  3. package/dist/esm/__tests__/versioning/resolve-version.test.js +207 -0
  4. package/dist/esm/__tests__/versioning/resolve-version.test.js.map +1 -0
  5. package/dist/esm/static.js +1 -1
  6. package/dist/esm/v2/provider.js +1 -1
  7. package/dist/esm/v2/provider.js.map +1 -1
  8. package/dist/esm/version.js +1 -1
  9. package/dist/esm/versioning/VersionError.js +78 -0
  10. package/dist/esm/versioning/VersionError.js.map +1 -0
  11. package/dist/esm/versioning/create-version-message.js +54 -0
  12. package/dist/esm/versioning/create-version-message.js.map +1 -0
  13. package/dist/esm/versioning/index.js +25 -0
  14. package/dist/esm/versioning/index.js.map +1 -0
  15. package/dist/esm/versioning/resolve-version.js +90 -0
  16. package/dist/esm/versioning/resolve-version.js.map +1 -0
  17. package/dist/esm/versioning/static.js +10 -0
  18. package/dist/esm/versioning/static.js.map +1 -0
  19. package/dist/esm/versioning/types.js +2 -0
  20. package/dist/esm/versioning/types.js.map +1 -0
  21. package/dist/tsconfig.tsbuildinfo +1 -1
  22. package/dist/types/__tests__/versioning/resolve-version.test.d.ts +1 -0
  23. package/dist/types/static.d.ts +1 -1
  24. package/dist/types/version.d.ts +1 -1
  25. package/dist/types/versioning/VersionError.d.ts +73 -0
  26. package/dist/types/versioning/create-version-message.d.ts +34 -0
  27. package/dist/types/versioning/index.d.ts +23 -0
  28. package/dist/types/versioning/resolve-version.d.ts +43 -0
  29. package/dist/types/versioning/static.d.ts +8 -0
  30. package/dist/types/versioning/types.d.ts +54 -0
  31. package/package.json +5 -4
  32. package/src/__tests__/versioning/resolve-version.test.ts +255 -0
  33. package/src/v2/provider.ts +1 -1
  34. package/src/version.ts +1 -1
  35. package/src/versioning/VersionError.ts +103 -0
  36. package/src/versioning/create-version-message.ts +63 -0
  37. package/src/versioning/index.ts +29 -0
  38. package/src/versioning/resolve-version.ts +125 -0
  39. package/src/versioning/static.ts +8 -0
  40. package/src/versioning/types.ts +60 -0
  41. package/tsconfig.json +1 -1
  42. package/vitest.config.ts +11 -0
  43. package/dist/esm/resolve-version.js +0 -27
  44. package/dist/esm/resolve-version.js.map +0 -1
  45. package/dist/types/resolve-version.d.ts +0 -10
  46. package/src/resolve-version.ts +0 -43
@@ -1,5 +1,5 @@
1
1
  export declare const ModuleName: "msal";
2
2
  export declare enum MsalModuleVersion {
3
3
  V2 = "v2",
4
- Latest = "4.0.8"
4
+ Latest = "4.1.0"
5
5
  }
@@ -1 +1 @@
1
- export declare const version = "4.0.8";
1
+ export declare const version = "4.1.0";
@@ -0,0 +1,73 @@
1
+ import { VersionMessageType } from './static';
2
+ import type { SemVer } from 'semver';
3
+ /**
4
+ * Creates a VersionError instance with a formatted message.
5
+ *
6
+ * This is a helper function that creates a VersionError with a human-readable
7
+ * message based on the error type and version information.
8
+ *
9
+ * @param type - The type of version error
10
+ * @param requestedVersion - The version that was requested
11
+ * @param latestVersion - The latest available version
12
+ * @param options - Additional error options including the error type
13
+ * @returns A new VersionError instance with formatted message
14
+ */
15
+ declare const createVersionError: (type: VersionMessageType, requestedVersion: string | SemVer, latestVersion: string | SemVer, options?: ErrorOptions & {
16
+ type?: VersionMessageType;
17
+ }) => VersionError;
18
+ /**
19
+ * Error class for version-related issues in the MSAL module.
20
+ *
21
+ * This error is thrown when there are version compatibility problems,
22
+ * such as requesting an incompatible major version or providing an invalid version string.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * try {
27
+ * resolveVersion('3.0.0'); // Assuming latest is 2.x
28
+ * } catch (error) {
29
+ * if (error instanceof VersionError) {
30
+ * console.error('Version error:', error.message);
31
+ * console.error('Requested:', error.requestedVersion);
32
+ * console.error('Latest:', error.latestVersion);
33
+ * console.error('Type:', error.type);
34
+ * }
35
+ * }
36
+ * ```
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // Create a version error manually
41
+ * const error = VersionError.create(
42
+ * VersionError.Type.MajorIncompatibility,
43
+ * '3.0.0',
44
+ * '2.1.0'
45
+ * );
46
+ * ```
47
+ */
48
+ export declare class VersionError extends Error {
49
+ /** The version that was requested by the user */
50
+ readonly requestedVersion: string;
51
+ /** The latest available version in the system */
52
+ readonly latestVersion: string;
53
+ /** The specific type of version error that occurred */
54
+ readonly type?: VersionMessageType;
55
+ /** The error name for instanceof checks */
56
+ static Name: string;
57
+ /** Reference to the VersionMessageType enum for convenience */
58
+ static Type: typeof VersionMessageType;
59
+ /** Factory method for creating VersionError instances with formatted messages */
60
+ static create: typeof createVersionError;
61
+ /**
62
+ * Creates a new VersionError instance.
63
+ *
64
+ * @param message - The error message describing the version issue
65
+ * @param requestedVersion - The version that was requested (will be stored as string)
66
+ * @param latestVersion - The latest available version (will be stored as string)
67
+ * @param options - Additional error options including the error type
68
+ */
69
+ constructor(message: string, requestedVersion: string | SemVer, latestVersion: string | SemVer, options?: ErrorOptions & {
70
+ type?: VersionMessageType;
71
+ });
72
+ }
73
+ export {};
@@ -0,0 +1,34 @@
1
+ import type { SemVer } from 'semver';
2
+ import { VersionMessageType } from './static';
3
+ /**
4
+ * Creates a human-readable version message based on the version message type.
5
+ *
6
+ * This function generates descriptive error messages for different version compatibility
7
+ * scenarios, helping developers understand version-related issues.
8
+ *
9
+ * @param type - The type of version message to create
10
+ * @param requestedVersion - The version that was requested by the user
11
+ * @param latestVersion - The latest available version in the system
12
+ * @returns A formatted, human-readable version message string
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const message = createVersionMessage(
17
+ * VersionMessageType.MajorIncompatibility,
18
+ * '3.0.0',
19
+ * '2.1.0'
20
+ * );
21
+ * // Returns: "Requested major version 3.0.0 is greater than the latest major version 2.1.0"
22
+ * ```
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const message = createVersionMessage(
27
+ * VersionMessageType.MinorMismatch,
28
+ * '2.1.0',
29
+ * '2.2.0'
30
+ * );
31
+ * // Returns: "Minor version mismatch, requested 2.1.0, latest 2.2.0"
32
+ * ```
33
+ */
34
+ export declare const createVersionMessage: (type: VersionMessageType, requestedVersion: string | SemVer, latestVersion: string | SemVer) => string;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @fileoverview Versioning module for MSAL module compatibility checking.
3
+ *
4
+ * This module provides comprehensive version resolution and validation functionality
5
+ * for the MSAL module, ensuring compatibility between different MSAL library versions.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { resolveVersion, VersionError } from '@equinor/fusion-framework-module-msal/versioning';
10
+ *
11
+ * try {
12
+ * const result = resolveVersion('2.1.0');
13
+ * console.log('Version is compatible:', result.satisfiesLatest);
14
+ * } catch (error) {
15
+ * if (error instanceof VersionError) {
16
+ * console.error('Version error:', error.message);
17
+ * }
18
+ * }
19
+ * ```
20
+ */
21
+ export { resolveVersion } from './resolve-version';
22
+ export { VersionError } from './VersionError';
23
+ export type { ResolvedVersion } from './types';
@@ -0,0 +1,43 @@
1
+ import { type SemVer } from 'semver';
2
+ import type { ResolvedVersion } from './types';
3
+ /**
4
+ * Resolves and validates a version string against the latest available MSAL version.
5
+ *
6
+ * This function performs comprehensive version checking including:
7
+ * - Parsing and validating the requested version
8
+ * - Checking major version compatibility (throws on incompatibility)
9
+ * - Warning on minor version mismatches (logs warning but continues)
10
+ * - Ignoring patch version differences for maximum compatibility
11
+ *
12
+ * @param version - The version string or SemVer object to resolve. If not provided, defaults to latest.
13
+ * @returns A ResolvedVersion object containing parsed versions and compatibility information
14
+ *
15
+ * @throws {VersionError} When the requested version is invalid or incompatible
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * // Resolve a specific version
20
+ * const result = resolveVersion('2.1.0');
21
+ * console.log(result.satisfiesLatest); // true if major version matches
22
+ *
23
+ * // Resolve with SemVer object
24
+ * const result2 = resolveVersion(new SemVer('2.0.0'));
25
+ *
26
+ * // Default to latest version
27
+ * const result3 = resolveVersion();
28
+ * ```
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * // Error handling
33
+ * try {
34
+ * const result = resolveVersion('3.0.0'); // Assuming latest is 2.x
35
+ * } catch (error) {
36
+ * if (error instanceof VersionError) {
37
+ * console.error('Version error:', error.message);
38
+ * }
39
+ * }
40
+ * ```
41
+ */
42
+ export declare function resolveVersion(version?: string | SemVer): ResolvedVersion;
43
+ export default resolveVersion;
@@ -0,0 +1,8 @@
1
+ export declare enum VersionMessageType {
2
+ MajorIncompatibility = "major-incompatibility",
3
+ MinorMismatch = "minor-mismatch",
4
+ PatchDifference = "patch-difference",
5
+ InvalidVersion = "invalid-version",
6
+ InvalidLatestVersion = "invalid-latest-version",
7
+ IncompatibleVersion = "incompatible-version"
8
+ }
@@ -0,0 +1,54 @@
1
+ import type { SemVer } from 'semver';
2
+ import type { MsalModuleVersion } from '../static';
3
+ /**
4
+ * Result of version resolution containing parsed versions and compatibility information.
5
+ *
6
+ * This type represents the outcome of resolving a version string against the latest
7
+ * available MSAL version, providing detailed compatibility information for consumers.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const result: ResolvedVersion = {
12
+ * wantedVersion: new SemVer('2.1.0'),
13
+ * latestVersion: new SemVer('2.2.0'),
14
+ * isLatest: false,
15
+ * satisfiesLatest: true,
16
+ * enumVersion: MsalModuleVersion.V2
17
+ * };
18
+ * ```
19
+ */
20
+ export type ResolvedVersion = {
21
+ /**
22
+ * The version that was requested and successfully parsed.
23
+ * This is the SemVer object representing the user's requested version.
24
+ */
25
+ wantedVersion: SemVer;
26
+ /**
27
+ * The latest available version in the system.
28
+ * This represents the most recent MSAL version that the module supports.
29
+ */
30
+ latestVersion: SemVer;
31
+ /**
32
+ * Whether the wanted version is exactly the latest version.
33
+ * True when wantedVersion.compare(latestVersion) === 0
34
+ */
35
+ isLatest: boolean;
36
+ /**
37
+ * Whether the wanted version satisfies the latest major version.
38
+ * True when major versions match, regardless of minor/patch differences.
39
+ * This is the primary compatibility check for MSAL versions.
40
+ */
41
+ satisfiesLatest: boolean;
42
+ /**
43
+ * The corresponding enum version for the wanted version.
44
+ * Maps the major version number to the appropriate MsalModuleVersion enum value.
45
+ * Used for module configuration and feature detection.
46
+ */
47
+ enumVersion: MsalModuleVersion;
48
+ /**
49
+ * Optional array of warning messages for version mismatches.
50
+ * Present when there are minor version differences but major versions match.
51
+ * Consumers can check this field to log warnings or handle version differences.
52
+ */
53
+ warnings?: string[];
54
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-module-msal",
3
- "version": "4.0.8",
4
- "description": "",
3
+ "version": "4.1.0",
4
+ "description": "Microsoft Authentication Library (MSAL) integration module for Fusion Framework",
5
5
  "main": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
7
7
  "exports": {
@@ -40,12 +40,13 @@
40
40
  "@types/semver": "^7.5.0",
41
41
  "semver": "^7.5.4",
42
42
  "zod": "^3.25.76",
43
- "@equinor/fusion-framework-module": "^5.0.0"
43
+ "@equinor/fusion-framework-module": "^5.0.1"
44
44
  },
45
45
  "devDependencies": {
46
46
  "typescript": "^5.8.2"
47
47
  },
48
48
  "scripts": {
49
- "build": "tsc -b"
49
+ "build": "tsc -b",
50
+ "test": "vitest run"
50
51
  }
51
52
  }
@@ -0,0 +1,255 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { SemVer } from 'semver';
3
+ import { resolveVersion } from '../../versioning/resolve-version';
4
+ import { VersionError } from '../../versioning/VersionError';
5
+
6
+ // Mock the static module to avoid test failures when package version changes
7
+ // This ensures tests remain stable regardless of package.json version bumps
8
+ vi.mock('../../static', () => ({
9
+ MsalModuleVersion: {
10
+ V2: 'v2',
11
+ Latest: '4.0.9', // Fixed version for consistent testing
12
+ },
13
+ }));
14
+
15
+ // Import the mocked version
16
+ import { MsalModuleVersion } from '../../static';
17
+
18
+ describe('resolveVersion', () => {
19
+ describe('mock verification', () => {
20
+ it('should use mocked version for consistent testing', () => {
21
+ // Verify that our mock is working and we're using the fixed version
22
+ expect(MsalModuleVersion.Latest).toBe('4.0.9');
23
+ expect(MsalModuleVersion.V2).toBe('v2');
24
+ });
25
+ });
26
+
27
+ describe('successful version resolution', () => {
28
+ it('should resolve a valid version string', () => {
29
+ const result = resolveVersion('2.1.0');
30
+
31
+ expect(result).toMatchObject({
32
+ wantedVersion: expect.any(SemVer),
33
+ latestVersion: expect.any(SemVer),
34
+ isLatest: false,
35
+ satisfiesLatest: false, // 2.x is not compatible with 4.x
36
+ enumVersion: MsalModuleVersion.V2,
37
+ });
38
+
39
+ expect(result.wantedVersion.version).toBe('2.1.0');
40
+ expect(result.latestVersion.version).toBe('4.0.9');
41
+ });
42
+
43
+ it('should resolve with SemVer object', () => {
44
+ const semver = new SemVer('2.0.0');
45
+ const result = resolveVersion(semver);
46
+
47
+ expect(result.wantedVersion).toBe(semver);
48
+ expect(result.satisfiesLatest).toBe(false); // 2.x is not compatible with 4.x
49
+ });
50
+
51
+ it('should resolve latest version when no version provided', () => {
52
+ const result = resolveVersion();
53
+
54
+ expect(result.wantedVersion.version).toBe('4.0.9');
55
+ expect(result.latestVersion.version).toBe('4.0.9');
56
+ expect(result.isLatest).toBe(true);
57
+ expect(result.satisfiesLatest).toBe(true);
58
+ });
59
+
60
+ it('should resolve latest version when empty string provided', () => {
61
+ const result = resolveVersion('');
62
+
63
+ expect(result.wantedVersion.version).toBe('4.0.9');
64
+ expect(result.isLatest).toBe(true);
65
+ });
66
+
67
+ it('should handle patch version differences without warnings', () => {
68
+ const result = resolveVersion('4.0.8');
69
+
70
+ expect(result.satisfiesLatest).toBe(true);
71
+ expect(result.isLatest).toBe(false);
72
+ expect(result.warnings).toBeUndefined();
73
+ });
74
+
75
+ it('should handle minor version differences with warnings', () => {
76
+ const result = resolveVersion('4.1.0');
77
+
78
+ expect(result.satisfiesLatest).toBe(true);
79
+ expect(result.isLatest).toBe(false);
80
+ expect(result.warnings).toBeDefined();
81
+ expect(result.warnings).toHaveLength(1);
82
+ expect(result.warnings?.[0]).toContain('Minor version mismatch');
83
+ });
84
+
85
+ it('should find correct enum version for major version', () => {
86
+ const result = resolveVersion('2.5.0');
87
+
88
+ expect(result.enumVersion).toBe(MsalModuleVersion.V2);
89
+ expect(result.satisfiesLatest).toBe(false); // 2.x is not compatible with 4.x
90
+ });
91
+
92
+ it('should throw error when no matching major version exists in enum', () => {
93
+ // Version 3.0.0 should throw because there's no enum for major version 3
94
+ expect(() => resolveVersion('3.0.0')).toThrow(VersionError);
95
+ });
96
+ });
97
+
98
+ describe('error handling', () => {
99
+ it('should throw VersionError for invalid version string', () => {
100
+ expect(() => resolveVersion('invalid-version')).toThrow(VersionError);
101
+ });
102
+
103
+ it('should not throw for malformed version (coerce handles it)', () => {
104
+ // semver.coerce('2.') returns '2.0.0', so it doesn't throw
105
+ expect(() => resolveVersion('2.')).not.toThrow();
106
+ });
107
+
108
+ it('should throw VersionError for non-semver string', () => {
109
+ expect(() => resolveVersion('not-a-version')).toThrow(VersionError);
110
+ });
111
+
112
+ it('should throw VersionError for major version incompatibility', () => {
113
+ expect(() => resolveVersion('5.0.0')).toThrow(VersionError);
114
+ });
115
+
116
+ it('should throw VersionError for very high major version', () => {
117
+ expect(() => resolveVersion('999.0.0')).toThrow(VersionError);
118
+ });
119
+
120
+ it('should include correct error type for major incompatibility', () => {
121
+ try {
122
+ resolveVersion('5.0.0');
123
+ expect.fail('Should have thrown VersionError');
124
+ } catch (error) {
125
+ expect(error).toBeInstanceOf(VersionError);
126
+ const versionError = error as VersionError;
127
+ expect(versionError.type).toBe('major-incompatibility');
128
+ expect(versionError.requestedVersion).toBe('5.0.0');
129
+ expect(versionError.latestVersion).toBe('4.0.9');
130
+ }
131
+ });
132
+
133
+ it('should include correct error type for invalid version', () => {
134
+ try {
135
+ resolveVersion('invalid');
136
+ expect.fail('Should have thrown VersionError');
137
+ } catch (error) {
138
+ expect(error).toBeInstanceOf(VersionError);
139
+ expect((error as VersionError).type).toBe('invalid-version');
140
+ }
141
+ });
142
+ });
143
+
144
+ describe('version comparison logic', () => {
145
+ it('should correctly identify latest version', () => {
146
+ const result = resolveVersion('4.0.9');
147
+ expect(result.isLatest).toBe(true);
148
+ });
149
+
150
+ it('should correctly identify non-latest version', () => {
151
+ const result = resolveVersion('4.0.8');
152
+ expect(result.isLatest).toBe(false);
153
+ });
154
+
155
+ it('should correctly identify satisfying version', () => {
156
+ const result = resolveVersion('4.1.0');
157
+ expect(result.satisfiesLatest).toBe(true);
158
+ });
159
+
160
+ it('should correctly identify non-satisfying version', () => {
161
+ expect(() => resolveVersion('5.0.0')).toThrow();
162
+ });
163
+
164
+ it('should throw error for major versions without enum values', () => {
165
+ // Version 3.0.0 should throw because there's no enum for major version 3
166
+ expect(() => resolveVersion('3.0.0')).toThrow(VersionError);
167
+ });
168
+ });
169
+
170
+ describe('warning behavior', () => {
171
+ it('should warn on minor version mismatch', () => {
172
+ const result = resolveVersion('4.1.0');
173
+
174
+ expect(result.warnings).toBeDefined();
175
+ expect(result.warnings).toHaveLength(1);
176
+ expect(result.warnings?.[0]).toContain('Minor version mismatch');
177
+ });
178
+
179
+ it('should not warn on patch version differences', () => {
180
+ const result = resolveVersion('4.0.8');
181
+
182
+ expect(result.warnings).toBeUndefined();
183
+ });
184
+
185
+ it('should not warn on exact version match', () => {
186
+ const result = resolveVersion('4.0.9');
187
+
188
+ expect(result.warnings).toBeUndefined();
189
+ });
190
+
191
+ it('should warn with correct version information', () => {
192
+ const result = resolveVersion('4.2.0');
193
+
194
+ expect(result.warnings).toBeDefined();
195
+ expect(result.warnings).toHaveLength(1);
196
+ expect(result.warnings?.[0]).toContain('4.2.0');
197
+ expect(result.warnings?.[0]).toContain('4.0.9');
198
+ });
199
+ });
200
+
201
+ describe('edge cases', () => {
202
+ it('should handle version with pre-release identifiers (coerce strips them)', () => {
203
+ const result = resolveVersion('4.0.9-beta.1');
204
+
205
+ expect(result.satisfiesLatest).toBe(true);
206
+ expect(result.wantedVersion.version).toBe('4.0.9'); // coerce strips pre-release
207
+ });
208
+
209
+ it('should handle version with build metadata (coerce strips them)', () => {
210
+ const result = resolveVersion('4.0.9+build.123');
211
+
212
+ expect(result.satisfiesLatest).toBe(true);
213
+ expect(result.wantedVersion.version).toBe('4.0.9'); // coerce strips build metadata
214
+ });
215
+
216
+ it('should handle very long version strings (coerce strips them)', () => {
217
+ const longVersion = '4.0.9-beta.1.alpha.2+build.123.456';
218
+ const result = resolveVersion(longVersion);
219
+
220
+ expect(result.satisfiesLatest).toBe(true);
221
+ expect(result.wantedVersion.version).toBe('4.0.9'); // coerce strips pre-release and build
222
+ });
223
+
224
+ it('should throw error for zero versions without enum values', () => {
225
+ // Version 0.0.0 should throw because there's no enum for major version 0
226
+ expect(() => resolveVersion('0.0.0')).toThrow(VersionError);
227
+ });
228
+ });
229
+
230
+ describe('return value structure', () => {
231
+ it('should return object with all required properties', () => {
232
+ const result = resolveVersion('2.1.0');
233
+
234
+ expect(result).toHaveProperty('wantedVersion');
235
+ expect(result).toHaveProperty('latestVersion');
236
+ expect(result).toHaveProperty('isLatest');
237
+ expect(result).toHaveProperty('satisfiesLatest');
238
+ expect(result).toHaveProperty('enumVersion');
239
+
240
+ expect(typeof result.isLatest).toBe('boolean');
241
+ expect(typeof result.satisfiesLatest).toBe('boolean');
242
+ expect(result.wantedVersion).toBeInstanceOf(SemVer);
243
+ expect(result.latestVersion).toBeInstanceOf(SemVer);
244
+ expect(typeof result.enumVersion).toBe('string');
245
+ });
246
+
247
+ it('should have consistent latest version across calls', () => {
248
+ const result1 = resolveVersion('2.0.0');
249
+ const result2 = resolveVersion('4.0.0');
250
+
251
+ expect(result1.latestVersion.version).toBe(result2.latestVersion.version);
252
+ expect(result1.latestVersion.version).toBe('4.0.9');
253
+ });
254
+ });
255
+ });
@@ -5,7 +5,7 @@ import { MsalModuleVersion } from '../static';
5
5
  import type { AuthClientConfig } from './configurator';
6
6
  import type { AccountInfo, AuthenticationResult } from './types';
7
7
  import type { IProxyProvider } from '../types';
8
- import resolveVersion from '../resolve-version';
8
+ import { resolveVersion } from '../versioning/resolve-version';
9
9
  import { SemanticVersion } from '@equinor/fusion-framework-module';
10
10
 
11
11
  export interface IAuthProvider {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '4.0.8';
2
+ export const version = '4.1.0';
@@ -0,0 +1,103 @@
1
+ import { VersionMessageType } from './static';
2
+ import { createVersionMessage } from './create-version-message';
3
+ import type { SemVer } from 'semver';
4
+
5
+ /**
6
+ * Creates a VersionError instance with a formatted message.
7
+ *
8
+ * This is a helper function that creates a VersionError with a human-readable
9
+ * message based on the error type and version information.
10
+ *
11
+ * @param type - The type of version error
12
+ * @param requestedVersion - The version that was requested
13
+ * @param latestVersion - The latest available version
14
+ * @param options - Additional error options including the error type
15
+ * @returns A new VersionError instance with formatted message
16
+ */
17
+ const createVersionError = (
18
+ type: VersionMessageType,
19
+ requestedVersion: string | SemVer,
20
+ latestVersion: string | SemVer,
21
+ options?: ErrorOptions & { type?: VersionMessageType },
22
+ ): VersionError => {
23
+ return new VersionError(
24
+ createVersionMessage(type, requestedVersion, latestVersion),
25
+ requestedVersion,
26
+ latestVersion,
27
+ { ...options, type },
28
+ );
29
+ };
30
+
31
+ /**
32
+ * Error class for version-related issues in the MSAL module.
33
+ *
34
+ * This error is thrown when there are version compatibility problems,
35
+ * such as requesting an incompatible major version or providing an invalid version string.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * try {
40
+ * resolveVersion('3.0.0'); // Assuming latest is 2.x
41
+ * } catch (error) {
42
+ * if (error instanceof VersionError) {
43
+ * console.error('Version error:', error.message);
44
+ * console.error('Requested:', error.requestedVersion);
45
+ * console.error('Latest:', error.latestVersion);
46
+ * console.error('Type:', error.type);
47
+ * }
48
+ * }
49
+ * ```
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * // Create a version error manually
54
+ * const error = VersionError.create(
55
+ * VersionError.Type.MajorIncompatibility,
56
+ * '3.0.0',
57
+ * '2.1.0'
58
+ * );
59
+ * ```
60
+ */
61
+ export class VersionError extends Error {
62
+ /** The version that was requested by the user */
63
+ public readonly requestedVersion: string;
64
+
65
+ /** The latest available version in the system */
66
+ public readonly latestVersion: string;
67
+
68
+ /** The specific type of version error that occurred */
69
+ public readonly type?: VersionMessageType;
70
+
71
+ /** The error name for instanceof checks */
72
+ static Name = 'VersionError';
73
+
74
+ /** Reference to the VersionMessageType enum for convenience */
75
+ static Type = VersionMessageType;
76
+
77
+ /** Factory method for creating VersionError instances with formatted messages */
78
+ static create: typeof createVersionError = createVersionError;
79
+
80
+ /**
81
+ * Creates a new VersionError instance.
82
+ *
83
+ * @param message - The error message describing the version issue
84
+ * @param requestedVersion - The version that was requested (will be stored as string)
85
+ * @param latestVersion - The latest available version (will be stored as string)
86
+ * @param options - Additional error options including the error type
87
+ */
88
+ constructor(
89
+ message: string,
90
+ requestedVersion: string | SemVer,
91
+ latestVersion: string | SemVer,
92
+ options?: ErrorOptions & { type?: VersionMessageType },
93
+ ) {
94
+ super(message, options);
95
+ this.name = VersionError.Name;
96
+
97
+ // Store versions as strings
98
+ this.requestedVersion = String(requestedVersion);
99
+ this.latestVersion = String(latestVersion);
100
+
101
+ this.type = options?.type;
102
+ }
103
+ }