@memberjunction/ng-workspace-initializer 4.0.0 → 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 (2) hide show
  1. package/README.md +156 -0
  2. package/package.json +8 -8
package/README.md ADDED
@@ -0,0 +1,156 @@
1
+ # @memberjunction/ng-workspace-initializer
2
+
3
+ Reusable workspace initialization service for MemberJunction Angular applications. Handles GraphQL client setup, metadata loading, user validation, error classification, and authentication retry logic.
4
+
5
+ ## Overview
6
+
7
+ This package extracts the workspace initialization logic that was originally embedded in the MJExplorer `AppComponent` into a standalone, reusable service. Any MemberJunction Angular application can use `WorkspaceInitializerService` to bootstrap an authenticated workspace session with proper error handling and retry semantics.
8
+
9
+ ```mermaid
10
+ graph TD
11
+ WIS["WorkspaceInitializerService"] --> GQL["GraphQL Client Setup"]
12
+ WIS --> META["Metadata + User Validation"]
13
+ WIS --> CLASSIFY["Error Classification"]
14
+ WIS --> RETRY["Auth Retry Logic"]
15
+
16
+ GQL --> CONFIG["GraphQLProviderConfigData"]
17
+ META --> SHARED["SharedService.RefreshData()"]
18
+ CLASSIFY --> TYPES["no_roles | no_access |\ntoken_expired | network | unknown"]
19
+ RETRY --> AUTHBASE["MJAuthBase.login()"]
20
+
21
+ style WIS fill:#7c5295,stroke:#563a6b,color:#fff
22
+ style GQL fill:#2d6a9f,stroke:#1a4971,color:#fff
23
+ style META fill:#2d6a9f,stroke:#1a4971,color:#fff
24
+ style CLASSIFY fill:#2d8659,stroke:#1a5c3a,color:#fff
25
+ style RETRY fill:#2d8659,stroke:#1a5c3a,color:#fff
26
+ style CONFIG fill:#64748b,stroke:#475569,color:#fff
27
+ style SHARED fill:#64748b,stroke:#475569,color:#fff
28
+ style TYPES fill:#b8762f,stroke:#8a5722,color:#fff
29
+ style AUTHBASE fill:#64748b,stroke:#475569,color:#fff
30
+ ```
31
+
32
+ ## Features
33
+
34
+ - **GraphQL client setup**: Configures the GraphQL data provider with token refresh callbacks
35
+ - **Metadata loading**: Loads entity metadata and validates the current user
36
+ - **Startup validation**: Triggers system configuration checks after initialization
37
+ - **Error classification**: Categorizes errors into actionable types (`no_roles`, `no_access`, `token_expired`, `network`, `unknown`)
38
+ - **Auth retry**: One-time automatic retry for expired tokens with 24-hour backoff
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ npm install @memberjunction/ng-workspace-initializer
44
+ ```
45
+
46
+ ## Key Dependencies
47
+
48
+ | Dependency | Purpose |
49
+ |---|---|
50
+ | `@memberjunction/core` | `Metadata`, `LogError`, `LogStatus` |
51
+ | `@memberjunction/graphql-dataprovider` | `setupGraphQLClient`, `GraphQLProviderConfigData` |
52
+ | `@memberjunction/ng-auth-services` | `MJAuthBase` for token operations |
53
+ | `@memberjunction/ng-shared` | `SharedService` for data refresh |
54
+ | `@memberjunction/ng-explorer-core` | `StartupValidationService` |
55
+
56
+ ## Usage
57
+
58
+ ### Module Import
59
+
60
+ ```typescript
61
+ import { WorkspaceInitializerModule } from '@memberjunction/ng-workspace-initializer';
62
+
63
+ @NgModule({
64
+ imports: [WorkspaceInitializerModule]
65
+ })
66
+ export class AppModule {}
67
+ ```
68
+
69
+ ### Initialize a Workspace
70
+
71
+ ```typescript
72
+ import { WorkspaceInitializerService } from '@memberjunction/ng-workspace-initializer';
73
+
74
+ class MyAppComponent {
75
+ constructor(private workspaceInit: WorkspaceInitializerService) {}
76
+
77
+ async onLogin(token: string, userInfo: StandardUserInfo) {
78
+ const result = await this.workspaceInit.initializeWorkspace(token, userInfo, {
79
+ GRAPHQL_URI: 'http://localhost:4000',
80
+ GRAPHQL_WS_URI: 'ws://localhost:4000',
81
+ MJ_CORE_SCHEMA_NAME: '__mj'
82
+ });
83
+
84
+ if (result.success) {
85
+ // Workspace ready - navigate to app
86
+ } else if (result.error) {
87
+ // Handle typed error
88
+ console.error(result.error.type, result.error.userMessage);
89
+
90
+ // Optionally retry for retryable errors
91
+ const retried = await this.workspaceInit.handleAuthRetry(
92
+ result.error,
93
+ window.location.pathname
94
+ );
95
+ }
96
+ }
97
+ }
98
+ ```
99
+
100
+ ## API Reference
101
+
102
+ ### WorkspaceInitializerService
103
+
104
+ | Method | Returns | Description |
105
+ |---|---|---|
106
+ | `initializeWorkspace(token, userInfo, environment)` | `Promise<WorkspaceInitResult>` | Sets up GraphQL client, loads metadata, validates user |
107
+ | `classifyError(err)` | `WorkspaceInitError` | Categorizes an error into an actionable type |
108
+ | `handleAuthRetry(error, currentPath)` | `Promise<boolean>` | Attempts auth retry for retryable errors (24h backoff) |
109
+
110
+ ### Interfaces
111
+
112
+ ```typescript
113
+ interface WorkspaceEnvironment {
114
+ GRAPHQL_URI: string;
115
+ GRAPHQL_WS_URI: string;
116
+ MJ_CORE_SCHEMA_NAME: string;
117
+ }
118
+
119
+ interface WorkspaceInitResult {
120
+ success: boolean;
121
+ error?: WorkspaceInitError;
122
+ }
123
+
124
+ interface WorkspaceInitError {
125
+ type: 'no_roles' | 'no_access' | 'token_expired' | 'network' | 'unknown';
126
+ message: string;
127
+ userMessage: string;
128
+ shouldRetry: boolean;
129
+ }
130
+ ```
131
+
132
+ ## Exported API
133
+
134
+ | Export | Type | Description |
135
+ |---|---|---|
136
+ | `WorkspaceInitializerModule` | NgModule | Module providing the service |
137
+ | `WorkspaceInitializerService` | Service | Main initialization service |
138
+ | `WorkspaceEnvironment` | Interface | Environment configuration shape |
139
+ | `WorkspaceInitResult` | Interface | Initialization result |
140
+ | `WorkspaceInitError` | Interface | Typed error with classification |
141
+
142
+ ## Build
143
+
144
+ ```bash
145
+ cd packages/Angular/Explorer/workspace-initializer && npm run build
146
+ ```
147
+
148
+ ## Related Packages
149
+
150
+ - [`@memberjunction/ng-explorer-app`](../explorer-app) - Application shell that consumes this service
151
+ - [`@memberjunction/ng-explorer-core`](../explorer-core) - Shell and validation services
152
+ - [`@memberjunction/ng-auth-services`](../auth-services) - Authentication abstraction
153
+
154
+ ## License
155
+
156
+ ISC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/ng-workspace-initializer",
3
- "version": "4.0.0",
3
+ "version": "4.1.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": "4.0.0",
34
- "@memberjunction/global": "4.0.0",
35
- "@memberjunction/graphql-dataprovider": "4.0.0",
36
- "@memberjunction/ng-auth-services": "4.0.0",
37
- "@memberjunction/ng-explorer-core": "4.0.0",
38
- "@memberjunction/ng-shared": "4.0.0",
39
- "@memberjunction/ng-shared-generic": "4.0.0",
33
+ "@memberjunction/core": "4.1.0",
34
+ "@memberjunction/global": "4.1.0",
35
+ "@memberjunction/graphql-dataprovider": "4.1.0",
36
+ "@memberjunction/ng-auth-services": "4.1.0",
37
+ "@memberjunction/ng-explorer-core": "4.1.0",
38
+ "@memberjunction/ng-shared": "4.1.0",
39
+ "@memberjunction/ng-shared-generic": "4.1.0",
40
40
  "rxjs": "^7.8.2",
41
41
  "tslib": "^2.8.1"
42
42
  },