@memberjunction/server 5.24.0 → 5.26.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/dist/agents/skip-sdk.d.ts +12 -0
- package/dist/agents/skip-sdk.d.ts.map +1 -1
- package/dist/agents/skip-sdk.js +70 -1
- package/dist/agents/skip-sdk.js.map +1 -1
- package/dist/config.d.ts +70 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +21 -0
- package/dist/config.js.map +1 -1
- package/dist/generated/generated.d.ts +498 -0
- package/dist/generated/generated.d.ts.map +1 -1
- package/dist/generated/generated.js +2755 -0
- package/dist/generated/generated.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -2
- package/dist/index.js.map +1 -1
- package/dist/resolvers/ArtifactFileResolver.d.ts +15 -0
- package/dist/resolvers/ArtifactFileResolver.d.ts.map +1 -0
- package/dist/resolvers/ArtifactFileResolver.js +74 -0
- package/dist/resolvers/ArtifactFileResolver.js.map +1 -0
- package/dist/resolvers/AutotagPipelineResolver.d.ts +13 -0
- package/dist/resolvers/AutotagPipelineResolver.d.ts.map +1 -1
- package/dist/resolvers/AutotagPipelineResolver.js +103 -3
- package/dist/resolvers/AutotagPipelineResolver.js.map +1 -1
- package/dist/resolvers/CacheStatsResolver.d.ts +31 -0
- package/dist/resolvers/CacheStatsResolver.d.ts.map +1 -0
- package/dist/resolvers/CacheStatsResolver.js +181 -0
- package/dist/resolvers/CacheStatsResolver.js.map +1 -0
- package/dist/resolvers/FileResolver.d.ts.map +1 -1
- package/dist/resolvers/FileResolver.js +12 -32
- package/dist/resolvers/FileResolver.js.map +1 -1
- package/dist/resolvers/GeoResolver.d.ts +58 -0
- package/dist/resolvers/GeoResolver.d.ts.map +1 -0
- package/dist/resolvers/GeoResolver.js +302 -0
- package/dist/resolvers/GeoResolver.js.map +1 -0
- package/dist/resolvers/RunAIAgentResolver.d.ts +13 -1
- package/dist/resolvers/RunAIAgentResolver.d.ts.map +1 -1
- package/dist/resolvers/RunAIAgentResolver.js +115 -20
- package/dist/resolvers/RunAIAgentResolver.js.map +1 -1
- package/dist/resolvers/SearchKnowledgeResolver.d.ts +21 -80
- package/dist/resolvers/SearchKnowledgeResolver.d.ts.map +1 -1
- package/dist/resolvers/SearchKnowledgeResolver.js +129 -604
- package/dist/resolvers/SearchKnowledgeResolver.js.map +1 -1
- package/dist/resolvers/SearchKnowledgeSystemUserResolver.d.ts +19 -0
- package/dist/resolvers/SearchKnowledgeSystemUserResolver.d.ts.map +1 -0
- package/dist/resolvers/SearchKnowledgeSystemUserResolver.js +149 -0
- package/dist/resolvers/SearchKnowledgeSystemUserResolver.js.map +1 -0
- package/package.json +66 -63
- package/src/__tests__/search-knowledge-tags.test.ts +177 -337
- package/src/__tests__/skip-sdk-organic-keys.test.ts +274 -0
- package/src/agents/skip-sdk.ts +83 -2
- package/src/config.ts +24 -0
- package/src/generated/generated.ts +1902 -1
- package/src/index.ts +18 -2
- package/src/resolvers/ArtifactFileResolver.ts +71 -0
- package/src/resolvers/AutotagPipelineResolver.ts +118 -4
- package/src/resolvers/CacheStatsResolver.ts +142 -0
- package/src/resolvers/FileResolver.ts +12 -41
- package/src/resolvers/GeoResolver.ts +258 -0
- package/src/resolvers/RunAIAgentResolver.ts +137 -23
- package/src/resolvers/SearchKnowledgeResolver.ts +114 -715
- package/src/resolvers/SearchKnowledgeSystemUserResolver.ts +138 -0
package/src/index.ts
CHANGED
|
@@ -108,6 +108,7 @@ export * from './generic/DeleteOptionsInput.js';
|
|
|
108
108
|
export * from './agents/skip-agent.js';
|
|
109
109
|
export * from './agents/skip-sdk.js';
|
|
110
110
|
|
|
111
|
+
export * from './resolvers/GeoResolver.js';
|
|
111
112
|
export * from './resolvers/ColorResolver.js';
|
|
112
113
|
export * from './resolvers/ComponentRegistryResolver.js';
|
|
113
114
|
export * from './resolvers/DatasetResolver.js';
|
|
@@ -127,9 +128,11 @@ export * from './resolvers/TelemetryResolver.js';
|
|
|
127
128
|
export * from './resolvers/APIKeyResolver.js';
|
|
128
129
|
export * from './resolvers/MCPResolver.js';
|
|
129
130
|
export * from './resolvers/ActionResolver.js';
|
|
131
|
+
export * from './resolvers/CacheStatsResolver.js';
|
|
130
132
|
export * from './resolvers/EntityCommunicationsResolver.js';
|
|
131
133
|
export * from './resolvers/EntityResolver.js';
|
|
132
134
|
export * from './resolvers/ISAEntityResolver.js';
|
|
135
|
+
export * from './resolvers/ArtifactFileResolver.js';
|
|
133
136
|
export * from './resolvers/FileCategoryResolver.js';
|
|
134
137
|
export * from './resolvers/FileResolver.js';
|
|
135
138
|
export * from './resolvers/InfoResolver.js';
|
|
@@ -449,8 +452,21 @@ export const serve = async (resolverPaths: Array<string>, app: Application = cre
|
|
|
449
452
|
}
|
|
450
453
|
// Ensure LocalCacheManager is initialized (no-op if already done during engine loading)
|
|
451
454
|
if (!LocalCacheManager.Instance.IsInitialized) {
|
|
452
|
-
|
|
453
|
-
|
|
455
|
+
// Build cache config from mj.config.cjs cacheSettings
|
|
456
|
+
const cs = configInfo.cacheSettings;
|
|
457
|
+
const cacheConfig = {
|
|
458
|
+
maxSizeBytes: (cs.maxMemoryMB ?? 150) * 1024 * 1024,
|
|
459
|
+
maxPercentOfCachePerEntity: cs.maxPercentOfCachePerEntity ?? 50,
|
|
460
|
+
defaultTTLMs: (cs.defaultTTLSeconds ?? 0) * 1000,
|
|
461
|
+
evictionSweepIntervalMs: (cs.evictionSweepIntervalSeconds ?? 300) * 1000,
|
|
462
|
+
verboseLogging: cs.verboseLogging ?? false,
|
|
463
|
+
};
|
|
464
|
+
await LocalCacheManager.Instance.Initialize(Metadata.Provider.LocalStorageProvider, cacheConfig);
|
|
465
|
+
console.log('LocalCacheManager initialized with cache config:', JSON.stringify({
|
|
466
|
+
maxMemoryMB: cs.maxMemoryMB ?? 150,
|
|
467
|
+
maxPercentOfCachePerEntity: cs.maxPercentOfCachePerEntity ?? 50,
|
|
468
|
+
evictionSweepIntervalSeconds: cs.evictionSweepIntervalSeconds ?? 300,
|
|
469
|
+
}));
|
|
454
470
|
}
|
|
455
471
|
|
|
456
472
|
// Initialize APIKeyEngine singleton — reads apiKeyGeneration from mj.config.cjs automatically
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Resolver, Query, Arg, Ctx } from 'type-graphql';
|
|
2
|
+
import { Metadata, IMetadataProvider } from '@memberjunction/core';
|
|
3
|
+
import { MJArtifactVersionEntity, MJFileEntity } from '@memberjunction/core-entities';
|
|
4
|
+
import { FileStorageEngine } from '@memberjunction/storage';
|
|
5
|
+
import { ResolverBase } from '../generic/ResolverBase.js';
|
|
6
|
+
import { AppContext } from '../types.js';
|
|
7
|
+
import { GetReadWriteProvider } from '../util.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* GraphQL resolver that produces a short-lived download URL for an artifact version
|
|
11
|
+
* stored as a binary file (ContentMode = 'File').
|
|
12
|
+
*
|
|
13
|
+
* Separating this from the generated FileResolver keeps the artifact-specific
|
|
14
|
+
* logic in one place and avoids mixing concerns in the large FileResolver class.
|
|
15
|
+
*/
|
|
16
|
+
@Resolver()
|
|
17
|
+
export class ArtifactFileResolver extends ResolverBase {
|
|
18
|
+
|
|
19
|
+
@Query(() => String, { description: 'Returns a pre-authenticated download URL for an artifact version whose ContentMode is "File".' })
|
|
20
|
+
async ArtifactFileDownloadUrl(
|
|
21
|
+
@Arg('artifactVersionId', () => String) artifactVersionId: string,
|
|
22
|
+
@Ctx() context: AppContext,
|
|
23
|
+
): Promise<string> {
|
|
24
|
+
const user = this.GetUserFromPayload(context.userPayload);
|
|
25
|
+
if (!user) {
|
|
26
|
+
throw new Error('Unauthorized');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const p = GetReadWriteProvider(context.providers);
|
|
30
|
+
|
|
31
|
+
// Load the artifact version
|
|
32
|
+
const artifactVersion = await p.GetEntityObject<MJArtifactVersionEntity>('MJ: Artifact Versions', user);
|
|
33
|
+
const loaded = await artifactVersion.Load(artifactVersionId);
|
|
34
|
+
if (!loaded) {
|
|
35
|
+
throw new Error(`Artifact version ${artifactVersionId} not found`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (artifactVersion.ContentMode !== 'File') {
|
|
39
|
+
throw new Error(`Artifact version ${artifactVersionId} is not a file artifact (ContentMode=${artifactVersion.ContentMode})`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!artifactVersion.FileID) {
|
|
43
|
+
throw new Error(`Artifact version ${artifactVersionId} has no associated file`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return this.buildDownloadUrl(artifactVersion.FileID, user, p);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Load the File + its storage account/provider and generate a signed URL. */
|
|
50
|
+
private async buildDownloadUrl(
|
|
51
|
+
fileId: string,
|
|
52
|
+
user: ReturnType<ResolverBase['GetUserFromPayload']>,
|
|
53
|
+
provider: IMetadataProvider,
|
|
54
|
+
): Promise<string> {
|
|
55
|
+
const fileEntity = await provider.GetEntityObject<MJFileEntity>('MJ: Files', user);
|
|
56
|
+
const fileLoaded = await fileEntity.Load(fileId);
|
|
57
|
+
if (!fileLoaded) {
|
|
58
|
+
throw new Error(`File record ${fileId} not found`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Find the storage account for this file's provider using cached metadata
|
|
62
|
+
await FileStorageEngine.Instance.Config(false, user!);
|
|
63
|
+
const matchingAccounts = FileStorageEngine.Instance.GetAccountsByProviderID(fileEntity.ProviderID);
|
|
64
|
+
if (matchingAccounts.length === 0) {
|
|
65
|
+
throw new Error(`No FileStorageAccount found for ProviderID ${fileEntity.ProviderID}. Cannot generate download URL.`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const driver = await FileStorageEngine.Instance.GetDriver(matchingAccounts[0].ID, user!);
|
|
69
|
+
return driver.CreatePreAuthDownloadUrl(fileEntity.ProviderKey ?? fileEntity.Name);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Resolver, Mutation, Ctx, Arg, ObjectType, Field } from 'type-graphql';
|
|
2
2
|
import { AppContext } from '../types.js';
|
|
3
|
-
import { LogError, LogStatus, Metadata } from '@memberjunction/core';
|
|
3
|
+
import { LogError, LogStatus, Metadata, RunView, UserInfo } from '@memberjunction/core';
|
|
4
4
|
import { MJContentProcessRunEntity } from '@memberjunction/core-entities';
|
|
5
5
|
import { ResolverBase } from '../generic/ResolverBase.js';
|
|
6
6
|
import { ActionEngineServer } from '@memberjunction/actions';
|
|
@@ -67,11 +67,13 @@ export class AutotagPipelineResolver extends ResolverBase {
|
|
|
67
67
|
*/
|
|
68
68
|
private async runPipelineInBackground(
|
|
69
69
|
pipelineRunID: string,
|
|
70
|
-
currentUser:
|
|
70
|
+
currentUser: UserInfo,
|
|
71
71
|
contentSourceIDs?: string[],
|
|
72
72
|
forceReprocess?: boolean
|
|
73
73
|
): Promise<void> {
|
|
74
74
|
const startTime = Date.now();
|
|
75
|
+
const processRun = await this.createProcessRun(pipelineRunID, currentUser, contentSourceIDs);
|
|
76
|
+
|
|
75
77
|
try {
|
|
76
78
|
this.publishProgress(pipelineRunID, 'autotag', 0, 0, startTime, 'Initializing pipeline...');
|
|
77
79
|
|
|
@@ -83,22 +85,26 @@ export class AutotagPipelineResolver extends ResolverBase {
|
|
|
83
85
|
if (!action) {
|
|
84
86
|
LogError(`RunAutotagPipeline: Action 'Autotag and Vectorize Content' not found`);
|
|
85
87
|
this.publishProgress(pipelineRunID, 'error', 0, 0, startTime, 'Autotag action not found');
|
|
88
|
+
await this.completeProcessRun(processRun, 'Failed', 'Autotag action not found', currentUser);
|
|
86
89
|
return;
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
// Stage: autotagging — provide a progress callback that publishes per-item updates
|
|
93
|
+
// and keeps the process run record in sync
|
|
90
94
|
this.publishProgress(pipelineRunID, 'autotag', 0, 0, startTime, 'Running autotaggers...');
|
|
91
95
|
|
|
92
96
|
const progressCallback = (processed: number, total: number, currentItem?: string) => {
|
|
93
97
|
const pct = total > 0 ? Math.round((processed / total) * 80) : 0; // 0-80% for tagging
|
|
94
98
|
this.publishProgress(pipelineRunID, 'autotag', total, pct, startTime, currentItem || `${processed}/${total} items`);
|
|
99
|
+
this.updateProcessRunProgress(processRun, processed, total);
|
|
95
100
|
};
|
|
96
101
|
|
|
97
|
-
// Build action params
|
|
102
|
+
// Build action params — include the process run ID so the action can create detail records
|
|
98
103
|
const actionParams: Array<{ Name: string; Value: unknown; Type: 'Input' | 'Output' | 'Both' }> = [
|
|
99
104
|
{ Name: 'Autotag', Value: 1, Type: 'Input' },
|
|
100
105
|
{ Name: 'Vectorize', Value: 1, Type: 'Input' },
|
|
101
|
-
{ Name: '__progressCallback', Value: progressCallback, Type: 'Input' }
|
|
106
|
+
{ Name: '__progressCallback', Value: progressCallback, Type: 'Input' },
|
|
107
|
+
{ Name: 'ContentProcessRunID', Value: pipelineRunID, Type: 'Input' }
|
|
102
108
|
];
|
|
103
109
|
if (contentSourceIDs && contentSourceIDs.length > 0) {
|
|
104
110
|
actionParams.push({ Name: 'ContentSourceIDs', Value: contentSourceIDs, Type: 'Input' });
|
|
@@ -120,14 +126,122 @@ export class AutotagPipelineResolver extends ResolverBase {
|
|
|
120
126
|
if (result.Success) {
|
|
121
127
|
LogStatus(`RunAutotagPipeline: pipeline ${pipelineRunID} completed successfully`);
|
|
122
128
|
this.publishProgress(pipelineRunID, 'complete', 100, 100, startTime);
|
|
129
|
+
await this.completeProcessRun(processRun, 'Completed', undefined, currentUser);
|
|
123
130
|
} else {
|
|
124
131
|
LogError(`RunAutotagPipeline: pipeline ${pipelineRunID} failed: ${result.Message}`);
|
|
125
132
|
this.publishProgress(pipelineRunID, 'error', 0, 0, startTime, String(result.Message));
|
|
133
|
+
await this.completeProcessRun(processRun, 'Failed', String(result.Message), currentUser);
|
|
126
134
|
}
|
|
127
135
|
} catch (error) {
|
|
128
136
|
const msg = error instanceof Error ? error.message : String(error);
|
|
129
137
|
LogError(`RunAutotagPipeline pipeline ${pipelineRunID} failed: ${msg}`);
|
|
130
138
|
this.publishProgress(pipelineRunID, 'error', 0, 0, startTime, msg);
|
|
139
|
+
await this.completeProcessRun(processRun, 'Failed', msg, currentUser);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Create a ContentProcessRun record to track this pipeline execution.
|
|
145
|
+
* Returns the entity so it can be updated during and after the run.
|
|
146
|
+
*/
|
|
147
|
+
private async createProcessRun(
|
|
148
|
+
pipelineRunID: string,
|
|
149
|
+
currentUser: UserInfo,
|
|
150
|
+
contentSourceIDs?: string[]
|
|
151
|
+
): Promise<MJContentProcessRunEntity | null> {
|
|
152
|
+
try {
|
|
153
|
+
// Resolve the source ID — use the specified source or the first available
|
|
154
|
+
let sourceID: string | undefined;
|
|
155
|
+
if (contentSourceIDs && contentSourceIDs.length > 0) {
|
|
156
|
+
sourceID = contentSourceIDs[0];
|
|
157
|
+
} else {
|
|
158
|
+
// Load content sources to get any available source ID (SourceID is NOT NULL)
|
|
159
|
+
const rv = new RunView();
|
|
160
|
+
const result = await rv.RunView<{ ID: string }>({
|
|
161
|
+
EntityName: 'MJ: Content Sources',
|
|
162
|
+
Fields: ['ID'],
|
|
163
|
+
ResultType: 'simple',
|
|
164
|
+
MaxRows: 1
|
|
165
|
+
}, currentUser);
|
|
166
|
+
if (result.Success && result.Results.length > 0) {
|
|
167
|
+
sourceID = result.Results[0].ID;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (!sourceID) {
|
|
172
|
+
LogError('RunAutotagPipeline: no content sources available, cannot create process run');
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const md = new Metadata();
|
|
177
|
+
const run = await md.GetEntityObject<MJContentProcessRunEntity>('MJ: Content Process Runs', currentUser);
|
|
178
|
+
run.NewRecord();
|
|
179
|
+
run.ID = pipelineRunID;
|
|
180
|
+
run.SourceID = sourceID;
|
|
181
|
+
run.StartTime = new Date();
|
|
182
|
+
run.Status = 'Running';
|
|
183
|
+
run.StartedByUserID = currentUser.ID;
|
|
184
|
+
run.ProcessedItems = 0;
|
|
185
|
+
run.TotalItemCount = 0;
|
|
186
|
+
run.LastProcessedOffset = 0;
|
|
187
|
+
run.ErrorCount = 0;
|
|
188
|
+
run.BatchSize = 20;
|
|
189
|
+
run.CancellationRequested = false;
|
|
190
|
+
const saved = await run.Save();
|
|
191
|
+
if (!saved) {
|
|
192
|
+
LogError(`RunAutotagPipeline: failed to create ContentProcessRun: ${run.LatestResult?.CompleteMessage}`);
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
LogStatus(`RunAutotagPipeline: created ContentProcessRun ${pipelineRunID}`);
|
|
196
|
+
return run;
|
|
197
|
+
} catch (error) {
|
|
198
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
199
|
+
LogError(`RunAutotagPipeline: error creating ContentProcessRun: ${msg}`);
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Update the process run record with current progress (fire-and-forget, non-blocking).
|
|
206
|
+
*/
|
|
207
|
+
private updateProcessRunProgress(
|
|
208
|
+
processRun: MJContentProcessRunEntity | null,
|
|
209
|
+
processedItems: number,
|
|
210
|
+
totalItems: number
|
|
211
|
+
): void {
|
|
212
|
+
if (!processRun) return;
|
|
213
|
+
processRun.ProcessedItems = processedItems;
|
|
214
|
+
processRun.TotalItemCount = totalItems;
|
|
215
|
+
processRun.LastProcessedOffset = processedItems;
|
|
216
|
+
// Fire-and-forget save — don't await to avoid slowing down the pipeline
|
|
217
|
+
processRun.Save().catch(e => {
|
|
218
|
+
LogError(`RunAutotagPipeline: error updating process run progress: ${e instanceof Error ? e.message : String(e)}`);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Mark the process run as completed, failed, or cancelled.
|
|
224
|
+
*/
|
|
225
|
+
private async completeProcessRun(
|
|
226
|
+
processRun: MJContentProcessRunEntity | null,
|
|
227
|
+
status: string,
|
|
228
|
+
errorMessage: string | undefined,
|
|
229
|
+
currentUser: import('@memberjunction/core').UserInfo
|
|
230
|
+
): Promise<void> {
|
|
231
|
+
if (!processRun) return;
|
|
232
|
+
try {
|
|
233
|
+
processRun.Status = status;
|
|
234
|
+
processRun.EndTime = new Date();
|
|
235
|
+
if (errorMessage) {
|
|
236
|
+
processRun.ErrorMessage = errorMessage;
|
|
237
|
+
processRun.ErrorCount = (processRun.ErrorCount ?? 0) + 1;
|
|
238
|
+
}
|
|
239
|
+
const saved = await processRun.Save();
|
|
240
|
+
if (!saved) {
|
|
241
|
+
LogError(`RunAutotagPipeline: failed to complete ContentProcessRun: ${processRun.LatestResult?.CompleteMessage}`);
|
|
242
|
+
}
|
|
243
|
+
} catch (error) {
|
|
244
|
+
LogError(`RunAutotagPipeline: error completing ContentProcessRun: ${error instanceof Error ? error.message : String(error)}`);
|
|
131
245
|
}
|
|
132
246
|
}
|
|
133
247
|
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Field, Float, Int, ObjectType, Query, Resolver } from 'type-graphql';
|
|
2
|
+
import { LocalCacheManager, CacheStats, CacheEntryType } from '@memberjunction/core';
|
|
3
|
+
import { RequireSystemUser } from '../directives/index.js';
|
|
4
|
+
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// GraphQL Object Types
|
|
7
|
+
// ============================================================================
|
|
8
|
+
|
|
9
|
+
@ObjectType()
|
|
10
|
+
class CacheStatsByTypeGQL {
|
|
11
|
+
@Field(() => String)
|
|
12
|
+
Type: CacheEntryType;
|
|
13
|
+
|
|
14
|
+
@Field(() => Int)
|
|
15
|
+
Count: number;
|
|
16
|
+
|
|
17
|
+
@Field(() => Int)
|
|
18
|
+
SizeBytes: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@ObjectType()
|
|
22
|
+
class CacheStatsGQL {
|
|
23
|
+
@Field(() => Int)
|
|
24
|
+
TotalEntries: number;
|
|
25
|
+
|
|
26
|
+
@Field(() => Int)
|
|
27
|
+
TotalSizeBytes: number;
|
|
28
|
+
|
|
29
|
+
@Field(() => [CacheStatsByTypeGQL])
|
|
30
|
+
ByType: CacheStatsByTypeGQL[];
|
|
31
|
+
|
|
32
|
+
@Field(() => Float)
|
|
33
|
+
OldestEntry: number;
|
|
34
|
+
|
|
35
|
+
@Field(() => Float)
|
|
36
|
+
NewestEntry: number;
|
|
37
|
+
|
|
38
|
+
@Field(() => Int)
|
|
39
|
+
Hits: number;
|
|
40
|
+
|
|
41
|
+
@Field(() => Int)
|
|
42
|
+
Misses: number;
|
|
43
|
+
|
|
44
|
+
@Field(() => Float)
|
|
45
|
+
HitRate: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@ObjectType()
|
|
49
|
+
class CacheEntityBreakdownGQL {
|
|
50
|
+
@Field(() => String)
|
|
51
|
+
EntityName: string;
|
|
52
|
+
|
|
53
|
+
@Field(() => Int)
|
|
54
|
+
EntryCount: number;
|
|
55
|
+
|
|
56
|
+
@Field(() => Int)
|
|
57
|
+
TotalSizeBytes: number;
|
|
58
|
+
|
|
59
|
+
@Field(() => Int)
|
|
60
|
+
TotalAccessCount: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@ObjectType()
|
|
64
|
+
class CacheStatsDetailGQL extends CacheStatsGQL {
|
|
65
|
+
@Field(() => [CacheEntityBreakdownGQL])
|
|
66
|
+
EntityBreakdown: CacheEntityBreakdownGQL[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ============================================================================
|
|
70
|
+
// Helpers (pure core)
|
|
71
|
+
// ============================================================================
|
|
72
|
+
|
|
73
|
+
function toGQL(stats: CacheStats): CacheStatsGQL {
|
|
74
|
+
const gql = new CacheStatsGQL();
|
|
75
|
+
gql.TotalEntries = stats.totalEntries;
|
|
76
|
+
gql.TotalSizeBytes = stats.totalSizeBytes;
|
|
77
|
+
gql.ByType = (['dataset', 'runview', 'runquery'] as const).map(t => {
|
|
78
|
+
const bt = stats.byType[t];
|
|
79
|
+
const entry = new CacheStatsByTypeGQL();
|
|
80
|
+
entry.Type = t;
|
|
81
|
+
entry.Count = bt.count;
|
|
82
|
+
entry.SizeBytes = bt.sizeBytes;
|
|
83
|
+
return entry;
|
|
84
|
+
});
|
|
85
|
+
gql.OldestEntry = stats.oldestEntry;
|
|
86
|
+
gql.NewestEntry = stats.newestEntry;
|
|
87
|
+
gql.Hits = stats.hits;
|
|
88
|
+
gql.Misses = stats.misses;
|
|
89
|
+
gql.HitRate = (stats.hits + stats.misses) > 0
|
|
90
|
+
? (stats.hits / (stats.hits + stats.misses)) * 100
|
|
91
|
+
: 0;
|
|
92
|
+
return gql;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function buildEntityBreakdown(): CacheEntityBreakdownGQL[] {
|
|
96
|
+
const entries = LocalCacheManager.Instance.GetAllEntries();
|
|
97
|
+
const entityMap = new Map<string, { count: number; sizeBytes: number; accessCount: number }>();
|
|
98
|
+
|
|
99
|
+
for (const entry of entries) {
|
|
100
|
+
if (entry.type !== 'runview' || !entry.name) continue;
|
|
101
|
+
const existing = entityMap.get(entry.name) ?? { count: 0, sizeBytes: 0, accessCount: 0 };
|
|
102
|
+
existing.count++;
|
|
103
|
+
existing.sizeBytes += entry.sizeBytes;
|
|
104
|
+
existing.accessCount += entry.accessCount;
|
|
105
|
+
entityMap.set(entry.name, existing);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return [...entityMap.entries()]
|
|
109
|
+
.map(([name, data]) => {
|
|
110
|
+
const gql = new CacheEntityBreakdownGQL();
|
|
111
|
+
gql.EntityName = name;
|
|
112
|
+
gql.EntryCount = data.count;
|
|
113
|
+
gql.TotalSizeBytes = data.sizeBytes;
|
|
114
|
+
gql.TotalAccessCount = data.accessCount;
|
|
115
|
+
return gql;
|
|
116
|
+
})
|
|
117
|
+
.sort((a, b) => b.EntryCount - a.EntryCount);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ============================================================================
|
|
121
|
+
// Resolver
|
|
122
|
+
// ============================================================================
|
|
123
|
+
|
|
124
|
+
@Resolver()
|
|
125
|
+
export class CacheStatsResolver {
|
|
126
|
+
@RequireSystemUser()
|
|
127
|
+
@Query(() => CacheStatsGQL)
|
|
128
|
+
CacheStats(): CacheStatsGQL {
|
|
129
|
+
const stats = LocalCacheManager.Instance.GetStats();
|
|
130
|
+
return toGQL(stats);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@RequireSystemUser()
|
|
134
|
+
@Query(() => CacheStatsDetailGQL)
|
|
135
|
+
CacheStatsDetail(): CacheStatsDetailGQL {
|
|
136
|
+
const stats = LocalCacheManager.Instance.GetStats();
|
|
137
|
+
const result = new CacheStatsDetailGQL();
|
|
138
|
+
Object.assign(result, toGQL(stats));
|
|
139
|
+
result.EntityBreakdown = buildEntityBreakdown();
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityPermissionType, Metadata, FieldValueCollection, EntitySaveOptions
|
|
1
|
+
import { EntityPermissionType, Metadata, FieldValueCollection, EntitySaveOptions } from '@memberjunction/core';
|
|
2
2
|
import { NormalizeUUID } from '@memberjunction/global';
|
|
3
3
|
import { MJFileEntity, MJFileStorageProviderEntity, MJFileStorageAccountEntity } from '@memberjunction/core-entities';
|
|
4
4
|
import {
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
FileSearchResult,
|
|
33
33
|
UserContextOptions,
|
|
34
34
|
ExtendedUserContextOptions,
|
|
35
|
-
|
|
35
|
+
FileStorageEngine,
|
|
36
36
|
} from '@memberjunction/storage';
|
|
37
37
|
import { CreateMJFileInput, MJFileResolver as FileResolverBase, MJFile_, UpdateMJFileInput } from '../generated/generated.js';
|
|
38
38
|
import { FieldMapper } from '@memberjunction/graphql-dataprovider';
|
|
@@ -648,12 +648,9 @@ export class FileResolver extends FileResolverBase {
|
|
|
648
648
|
const fileEntity = await md.GetEntityObject<MJFileEntity>('MJ: Files', user);
|
|
649
649
|
fileEntity.CheckPermissions(EntityPermissionType.Create, true);
|
|
650
650
|
|
|
651
|
-
// Initialize driver
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
providerEntity,
|
|
655
|
-
contextUser: user,
|
|
656
|
-
});
|
|
651
|
+
// Initialize driver via FileStorageEngine (handles credential decryption + token refresh)
|
|
652
|
+
await FileStorageEngine.Instance.Config(false, user);
|
|
653
|
+
const driver = await FileStorageEngine.Instance.GetDriver(accountEntity.ID, user);
|
|
657
654
|
|
|
658
655
|
const success = await driver.CreateDirectory(input.Path);
|
|
659
656
|
return success;
|
|
@@ -726,23 +723,12 @@ export class FileResolver extends FileResolverBase {
|
|
|
726
723
|
const fileEntity = await md.GetEntityObject<MJFileEntity>('MJ: Files', user);
|
|
727
724
|
fileEntity.CheckPermissions(EntityPermissionType.Read, true);
|
|
728
725
|
|
|
729
|
-
//
|
|
730
|
-
|
|
731
|
-
const
|
|
732
|
-
const
|
|
733
|
-
|
|
734
|
-
EntityName: 'MJ: File Storage Accounts',
|
|
735
|
-
ExtraFilter: `ID IN (${quotedIDs})`,
|
|
736
|
-
ResultType: 'entity_object',
|
|
737
|
-
},
|
|
738
|
-
user,
|
|
739
|
-
);
|
|
726
|
+
// Use cached accounts from the engine — no RunView needed
|
|
727
|
+
await FileStorageEngine.Instance.Config(false, user);
|
|
728
|
+
const normalizedIDs = new Set(input.AccountIDs.map((id: string) => NormalizeUUID(id)));
|
|
729
|
+
const accountEntities = FileStorageEngine.Instance.Accounts
|
|
730
|
+
.filter(a => normalizedIDs.has(NormalizeUUID(a.ID)));
|
|
740
731
|
|
|
741
|
-
if (!accountResult.Success) {
|
|
742
|
-
throw new Error(`Failed to load storage accounts: ${accountResult.ErrorMessage}`);
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
const accountEntities = accountResult.Results;
|
|
746
732
|
if (accountEntities.length === 0) {
|
|
747
733
|
throw new Error('No valid storage accounts found for the provided IDs');
|
|
748
734
|
}
|
|
@@ -754,24 +740,9 @@ export class FileResolver extends FileResolverBase {
|
|
|
754
740
|
console.warn(`[FileResolver] Accounts not found: ${missingIDs.join(', ')}`);
|
|
755
741
|
}
|
|
756
742
|
|
|
757
|
-
// Load providers
|
|
758
|
-
const providerIDs = [...new Set(accountEntities.map((a) => a.ProviderID))];
|
|
759
|
-
const quotedProviderIDs = providerIDs.map((id) => `'${id}'`).join(', ');
|
|
760
|
-
const providerResult = await rv.RunView<MJFileStorageProviderEntity>(
|
|
761
|
-
{
|
|
762
|
-
EntityName: 'MJ: File Storage Providers',
|
|
763
|
-
ExtraFilter: `ID IN (${quotedProviderIDs})`,
|
|
764
|
-
ResultType: 'entity_object',
|
|
765
|
-
},
|
|
766
|
-
user,
|
|
767
|
-
);
|
|
768
|
-
|
|
769
|
-
if (!providerResult.Success) {
|
|
770
|
-
throw new Error(`Failed to load storage providers: ${providerResult.ErrorMessage}`);
|
|
771
|
-
}
|
|
772
|
-
|
|
743
|
+
// Load providers from cached metadata
|
|
773
744
|
const providerMap = new Map<string, MJFileStorageProviderEntity>();
|
|
774
|
-
for (const provider of
|
|
745
|
+
for (const provider of FileStorageEngine.Instance.Providers) {
|
|
775
746
|
providerMap.set(provider.ID, provider);
|
|
776
747
|
}
|
|
777
748
|
|