@memberjunction/ng-workspace-initializer 5.43.0 → 5.44.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ng-workspace-initializer",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.44.0",
|
|
4
4
|
"description": "MemberJunction: Workspace Initialization Service and Components",
|
|
5
5
|
"main": "./dist/public-api.js",
|
|
6
6
|
"typings": "./dist/public-api.d.ts",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
"@angular/router": "21.1.3"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@memberjunction/core": "5.
|
|
34
|
-
"@memberjunction/global": "5.
|
|
35
|
-
"@memberjunction/graphql-dataprovider": "5.
|
|
36
|
-
"@memberjunction/ng-auth-services": "5.
|
|
37
|
-
"@memberjunction/ng-explorer-core": "5.
|
|
38
|
-
"@memberjunction/ng-shared": "5.
|
|
39
|
-
"@memberjunction/ng-shared-generic": "5.
|
|
33
|
+
"@memberjunction/core": "5.44.0",
|
|
34
|
+
"@memberjunction/global": "5.44.0",
|
|
35
|
+
"@memberjunction/graphql-dataprovider": "5.44.0",
|
|
36
|
+
"@memberjunction/ng-auth-services": "5.44.0",
|
|
37
|
+
"@memberjunction/ng-explorer-core": "5.44.0",
|
|
38
|
+
"@memberjunction/ng-shared": "5.44.0",
|
|
39
|
+
"@memberjunction/ng-shared-generic": "5.44.0",
|
|
40
40
|
"rxjs": "^7.8.2",
|
|
41
41
|
"tslib": "^2.8.1"
|
|
42
42
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-initializer.test.d.ts","sourceRoot":"","sources":["../../../src/lib/__tests__/workspace-initializer.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for workspace-initializer package:
|
|
3
|
-
* - WorkspaceInitError types
|
|
4
|
-
* - WorkspaceInitializerService.classifyError
|
|
5
|
-
*/
|
|
6
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
7
|
-
// Mock Angular
|
|
8
|
-
vi.mock('@angular/core', () => ({
|
|
9
|
-
Injectable: () => (target) => target,
|
|
10
|
-
}));
|
|
11
|
-
vi.mock('@memberjunction/core', () => ({
|
|
12
|
-
LogError: vi.fn(),
|
|
13
|
-
LogStatus: vi.fn(),
|
|
14
|
-
Metadata: class {
|
|
15
|
-
CurrentUser = { ID: 'user-1' };
|
|
16
|
-
},
|
|
17
|
-
}));
|
|
18
|
-
vi.mock('@memberjunction/graphql-dataprovider', () => ({
|
|
19
|
-
setupGraphQLClient: vi.fn(),
|
|
20
|
-
GraphQLProviderConfigData: class {
|
|
21
|
-
constructor(...args) { }
|
|
22
|
-
},
|
|
23
|
-
}));
|
|
24
|
-
vi.mock('@memberjunction/ng-auth-services', () => ({
|
|
25
|
-
MJAuthBase: class {
|
|
26
|
-
classifyError = vi.fn(() => ({ type: 'UNKNOWN_ERROR', message: 'unknown' }));
|
|
27
|
-
refreshToken = vi.fn();
|
|
28
|
-
login = vi.fn(() => ({ subscribe: vi.fn() }));
|
|
29
|
-
},
|
|
30
|
-
StandardUserInfo: class {
|
|
31
|
-
},
|
|
32
|
-
AuthErrorType: {
|
|
33
|
-
TOKEN_EXPIRED: 'TOKEN_EXPIRED',
|
|
34
|
-
NO_ACTIVE_SESSION: 'NO_ACTIVE_SESSION',
|
|
35
|
-
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
36
|
-
},
|
|
37
|
-
}));
|
|
38
|
-
vi.mock('@memberjunction/ng-shared', () => ({
|
|
39
|
-
SharedService: {
|
|
40
|
-
RefreshData: vi.fn(),
|
|
41
|
-
},
|
|
42
|
-
}));
|
|
43
|
-
vi.mock('@memberjunction/ng-explorer-core', () => ({
|
|
44
|
-
StartupValidationService: class {
|
|
45
|
-
validateSystemSetup = vi.fn();
|
|
46
|
-
addNoRolesValidationIssue = vi.fn();
|
|
47
|
-
},
|
|
48
|
-
}));
|
|
49
|
-
vi.mock('rxjs', async () => {
|
|
50
|
-
const actual = await vi.importActual('rxjs');
|
|
51
|
-
return actual;
|
|
52
|
-
});
|
|
53
|
-
// ======================= Workspace types =======================
|
|
54
|
-
describe('WorkspaceEnvironment / WorkspaceInitResult types', () => {
|
|
55
|
-
it('should define type interfaces correctly', async () => {
|
|
56
|
-
const types = await import('../models/workspace-types');
|
|
57
|
-
// These are interfaces, we can just verify the module exports
|
|
58
|
-
expect(types).toBeDefined();
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
// ======================= WorkspaceInitializerService.classifyError =======================
|
|
62
|
-
describe('WorkspaceInitializerService.classifyError', () => {
|
|
63
|
-
let service;
|
|
64
|
-
beforeEach(async () => {
|
|
65
|
-
vi.clearAllMocks();
|
|
66
|
-
const mod = await import('../services/workspace-initializer.service');
|
|
67
|
-
const { MJAuthBase } = await import('@memberjunction/ng-auth-services');
|
|
68
|
-
const { StartupValidationService } = await import('@memberjunction/ng-explorer-core');
|
|
69
|
-
service = new mod.WorkspaceInitializerService({}, {}, {});
|
|
70
|
-
});
|
|
71
|
-
it('should classify no-roles GraphQL error', () => {
|
|
72
|
-
const err = {
|
|
73
|
-
response: {
|
|
74
|
-
errors: [{ message: 'User does not have read permissions on User Roles' }]
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
const result = service.classifyError(err);
|
|
78
|
-
expect(result.type).toBe('no_roles');
|
|
79
|
-
expect(result.shouldRetry).toBe(false);
|
|
80
|
-
});
|
|
81
|
-
it('should classify ResourceTypes error as no_roles', () => {
|
|
82
|
-
const err = new Error("Cannot read properties of undefined (reading 'ResourceTypes')");
|
|
83
|
-
const result = service.classifyError(err);
|
|
84
|
-
expect(result.type).toBe('no_roles');
|
|
85
|
-
});
|
|
86
|
-
it('should classify access denied error', () => {
|
|
87
|
-
const err = new Error("You don't have access to this application");
|
|
88
|
-
const result = service.classifyError(err);
|
|
89
|
-
expect(result.type).toBe('no_access');
|
|
90
|
-
expect(result.shouldRetry).toBe(false);
|
|
91
|
-
});
|
|
92
|
-
it('should classify network errors', () => {
|
|
93
|
-
const err = new Error('Failed to fetch data from network');
|
|
94
|
-
const result = service.classifyError(err);
|
|
95
|
-
expect(result.type).toBe('network');
|
|
96
|
-
expect(result.shouldRetry).toBe(true);
|
|
97
|
-
});
|
|
98
|
-
it('should classify unknown errors as unknown', () => {
|
|
99
|
-
const err = new Error('Something unexpected happened');
|
|
100
|
-
const result = service.classifyError(err);
|
|
101
|
-
expect(result.type).toBe('unknown');
|
|
102
|
-
expect(result.shouldRetry).toBe(false);
|
|
103
|
-
});
|
|
104
|
-
it('should handle errors without message property gracefully', () => {
|
|
105
|
-
// classifyError accesses err.message directly, so pass an object without message
|
|
106
|
-
const result = service.classifyError({ someOtherProp: true });
|
|
107
|
-
expect(result.type).toBe('unknown');
|
|
108
|
-
});
|
|
109
|
-
it('should handle errors without message', () => {
|
|
110
|
-
const result = service.classifyError({});
|
|
111
|
-
expect(result.type).toBe('unknown');
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
// ======================= handleAuthRetry =======================
|
|
115
|
-
describe('WorkspaceInitializerService.handleAuthRetry', () => {
|
|
116
|
-
let service;
|
|
117
|
-
beforeEach(async () => {
|
|
118
|
-
vi.clearAllMocks();
|
|
119
|
-
// Clear localStorage mock
|
|
120
|
-
const localStorageMock = {};
|
|
121
|
-
global.localStorage = {
|
|
122
|
-
getItem: vi.fn((key) => localStorageMock[key] ?? null),
|
|
123
|
-
setItem: vi.fn((key, value) => { localStorageMock[key] = value; }),
|
|
124
|
-
removeItem: vi.fn((key) => { delete localStorageMock[key]; }),
|
|
125
|
-
};
|
|
126
|
-
const mod = await import('../services/workspace-initializer.service');
|
|
127
|
-
const { MJAuthBase } = await import('@memberjunction/ng-auth-services');
|
|
128
|
-
const { StartupValidationService } = await import('@memberjunction/ng-explorer-core');
|
|
129
|
-
service = new mod.WorkspaceInitializerService({}, {}, {});
|
|
130
|
-
});
|
|
131
|
-
it('should return false for non-retryable errors', async () => {
|
|
132
|
-
const result = await service.handleAuthRetry({ type: 'no_roles', message: 'No roles', userMessage: 'No roles', shouldRetry: false }, '/dashboard');
|
|
133
|
-
expect(result).toBe(false);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
//# sourceMappingURL=workspace-initializer.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-initializer.test.js","sourceRoot":"","sources":["../../../src/lib/__tests__/workspace-initializer.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE9D,eAAe;AACf,EAAE,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;IAC9B,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,MAAgB,EAAE,EAAE,CAAC,MAAM;CAC/C,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,sBAAsB,EAAE,GAAG,EAAE,CAAC,CAAC;IACrC,QAAQ,EAAE,EAAE,CAAC,EAAE,EAAE;IACjB,SAAS,EAAE,EAAE,CAAC,EAAE,EAAE;IAClB,QAAQ,EAAE;QACR,WAAW,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;KAChC;CACF,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,sCAAsC,EAAE,GAAG,EAAE,CAAC,CAAC;IACrD,kBAAkB,EAAE,EAAE,CAAC,EAAE,EAAE;IAC3B,yBAAyB,EAAE;QACzB,YAAY,GAAG,IAAe,IAAG,CAAC;KACnC;CACF,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,kCAAkC,EAAE,GAAG,E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G,MAAM,MAAM,CAAC,kCAAkC,CAAC,CAAC;QACtF,OAAO,GAAG,IAAI,GAAG,CAAC,2BAA2B,CAC3C,EAAW,EACX,EAAW,EACX,EAAW,CACZ,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;QAC5D,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,eAAe,CAC1C,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,EACtF,YAAY,CACb,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Tests for workspace-initializer package:\n * - WorkspaceInitError types\n * - WorkspaceInitializerService.classifyError\n */\nimport { describe, it, expect, vi, beforeEach } from 'vitest';\n\n// Mock Angular\nvi.mock('@angular/core', () => ({\n Injectable: () => (target: Function) => target,\n}));\n\nvi.mock('@memberjunction/core', () => ({\n LogError: vi.fn(),\n LogStatus: vi.fn(),\n Metadata: class {\n CurrentUser = { ID: 'user-1' };\n },\n}));\n\nvi.mock('@memberjunction/graphql-dataprovider', () => ({\n setupGraphQLClient: vi.fn(),\n GraphQLProviderConfigData: class {\n constructor(...args: unknown[]) {}\n },\n}));\n\nvi.mock('@memberjunction/ng-auth-services', () => ({\n MJAuthBase: class {\n classifyError = vi.fn(() => ({ type: 'UNKNOWN_ERROR', message: 'unknown' }));\n refreshToken = vi.fn();\n login = vi.fn(() => ({ subscribe: vi.fn() }));\n },\n StandardUserInfo: class {},\n AuthErrorType: {\n TOKEN_EXPIRED: 'TOKEN_EXPIRED',\n NO_ACTIVE_SESSION: 'NO_ACTIVE_SESSION',\n UNKNOWN_ERROR: 'UNKNOWN_ERROR',\n },\n}));\n\nvi.mock('@memberjunction/ng-shared', () => ({\n SharedService: {\n RefreshData: vi.fn(),\n },\n}));\n\nvi.mock('@memberjunction/ng-explorer-core', () => ({\n StartupValidationService: class {\n validateSystemSetup = vi.fn();\n addNoRolesValidationIssue = vi.fn();\n },\n}));\n\nvi.mock('rxjs', async () => {\n const actual = await vi.importActual<typeof import('rxjs')>('rxjs');\n return actual;\n});\n\n// ======================= Workspace types =======================\ndescribe('WorkspaceEnvironment / WorkspaceInitResult types', () => {\n it('should define type interfaces correctly', async () => {\n const types = await import('../models/workspace-types');\n // These are interfaces, we can just verify the module exports\n expect(types).toBeDefined();\n });\n});\n\n// ======================= WorkspaceInitializerService.classifyError =======================\ndescribe('WorkspaceInitializerService.classifyError', () => {\n let service: InstanceType<typeof import('../services/workspace-initializer.service').WorkspaceInitializerService>;\n\n beforeEach(async () => {\n vi.clearAllMocks();\n const mod = await import('../services/workspace-initializer.service');\n const { MJAuthBase } = await import('@memberjunction/ng-auth-services');\n const { StartupValidationService } = await import('@memberjunction/ng-explorer-core');\n service = new mod.WorkspaceInitializerService(\n {} as never,\n {} as never,\n {} as never\n );\n });\n\n it('should classify no-roles GraphQL error', () => {\n const err = {\n response: {\n errors: [{ message: 'User does not have read permissions on User Roles' }]\n }\n };\n const result = service.classifyError(err);\n expect(result.type).toBe('no_roles');\n expect(result.shouldRetry).toBe(false);\n });\n\n it('should classify ResourceTypes error as no_roles', () => {\n const err = new Error(\"Cannot read properties of undefined (reading 'ResourceTypes')\");\n const result = service.classifyError(err);\n expect(result.type).toBe('no_roles');\n });\n\n it('should classify access denied error', () => {\n const err = new Error(\"You don't have access to this application\");\n const result = service.classifyError(err);\n expect(result.type).toBe('no_access');\n expect(result.shouldRetry).toBe(false);\n });\n\n it('should classify network errors', () => {\n const err = new Error('Failed to fetch data from network');\n const result = service.classifyError(err);\n expect(result.type).toBe('network');\n expect(result.shouldRetry).toBe(true);\n });\n\n it('should classify unknown errors as unknown', () => {\n const err = new Error('Something unexpected happened');\n const result = service.classifyError(err);\n expect(result.type).toBe('unknown');\n expect(result.shouldRetry).toBe(false);\n });\n\n it('should handle errors without message property gracefully', () => {\n // classifyError accesses err.message directly, so pass an object without message\n const result = service.classifyError({ someOtherProp: true });\n expect(result.type).toBe('unknown');\n });\n\n it('should handle errors without message', () => {\n const result = service.classifyError({});\n expect(result.type).toBe('unknown');\n });\n});\n\n// ======================= handleAuthRetry =======================\ndescribe('WorkspaceInitializerService.handleAuthRetry', () => {\n let service: InstanceType<typeof import('../services/workspace-initializer.service').WorkspaceInitializerService>;\n\n beforeEach(async () => {\n vi.clearAllMocks();\n // Clear localStorage mock\n const localStorageMock: Record<string, string> = {};\n (global as Record<string, unknown>).localStorage = {\n getItem: vi.fn((key: string) => localStorageMock[key] ?? null),\n setItem: vi.fn((key: string, value: string) => { localStorageMock[key] = value; }),\n removeItem: vi.fn((key: string) => { delete localStorageMock[key]; }),\n };\n\n const mod = await import('../services/workspace-initializer.service');\n const { MJAuthBase } = await import('@memberjunction/ng-auth-services');\n const { StartupValidationService } = await import('@memberjunction/ng-explorer-core');\n service = new mod.WorkspaceInitializerService(\n {} as never,\n {} as never,\n {} as never\n );\n });\n\n it('should return false for non-retryable errors', async () => {\n const result = await service.handleAuthRetry(\n { type: 'no_roles', message: 'No roles', userMessage: 'No roles', shouldRetry: false },\n '/dashboard'\n );\n expect(result).toBe(false);\n });\n});\n"]}
|