@memberjunction/server 2.50.0 → 2.52.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/README.md +133 -0
- package/dist/config.d.ts +264 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +24 -1
- package/dist/config.js.map +1 -1
- package/dist/generated/generated.d.ts +66 -0
- package/dist/generated/generated.d.ts.map +1 -1
- package/dist/generated/generated.js +849 -517
- package/dist/generated/generated.js.map +1 -1
- package/dist/generic/ResolverBase.d.ts +1 -1
- package/dist/generic/ResolverBase.d.ts.map +1 -1
- package/dist/generic/ResolverBase.js +13 -11
- package/dist/generic/ResolverBase.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/orm.d.ts.map +1 -1
- package/dist/orm.js +6 -0
- package/dist/orm.js.map +1 -1
- package/dist/resolvers/ActionResolver.d.ts +3 -3
- package/dist/resolvers/ActionResolver.d.ts.map +1 -1
- package/dist/resolvers/ActionResolver.js +13 -10
- package/dist/resolvers/ActionResolver.js.map +1 -1
- package/dist/resolvers/FileResolver.js +1 -1
- package/dist/resolvers/FileResolver.js.map +1 -1
- package/dist/resolvers/RunAIAgentResolver.d.ts +49 -8
- package/dist/resolvers/RunAIAgentResolver.d.ts.map +1 -1
- package/dist/resolvers/RunAIAgentResolver.js +389 -106
- package/dist/resolvers/RunAIAgentResolver.js.map +1 -1
- package/dist/resolvers/RunAIPromptResolver.d.ts +1 -1
- package/dist/resolvers/RunAIPromptResolver.d.ts.map +1 -1
- package/dist/resolvers/RunAIPromptResolver.js +53 -3
- package/dist/resolvers/RunAIPromptResolver.js.map +1 -1
- package/dist/resolvers/SqlLoggingConfigResolver.d.ts +61 -0
- package/dist/resolvers/SqlLoggingConfigResolver.d.ts.map +1 -0
- package/dist/resolvers/SqlLoggingConfigResolver.js +477 -0
- package/dist/resolvers/SqlLoggingConfigResolver.js.map +1 -0
- package/dist/resolvers/UserFavoriteResolver.d.ts +3 -3
- package/dist/resolvers/UserFavoriteResolver.d.ts.map +1 -1
- package/dist/resolvers/UserFavoriteResolver.js +6 -6
- package/dist/resolvers/UserFavoriteResolver.js.map +1 -1
- package/dist/resolvers/UserResolver.d.ts +3 -3
- package/dist/resolvers/UserResolver.d.ts.map +1 -1
- package/dist/resolvers/UserResolver.js +6 -6
- package/dist/resolvers/UserResolver.js.map +1 -1
- package/dist/resolvers/UserViewResolver.d.ts +4 -4
- package/dist/resolvers/UserViewResolver.d.ts.map +1 -1
- package/dist/resolvers/UserViewResolver.js +6 -6
- package/dist/resolvers/UserViewResolver.js.map +1 -1
- package/package.json +25 -25
- package/src/config.ts +28 -0
- package/src/generated/generated.ts +718 -518
- package/src/generic/ResolverBase.ts +17 -10
- package/src/index.ts +2 -1
- package/src/orm.ts +6 -0
- package/src/resolvers/ActionResolver.ts +21 -26
- package/src/resolvers/FileResolver.ts +1 -1
- package/src/resolvers/RunAIAgentResolver.ts +398 -100
- package/src/resolvers/RunAIPromptResolver.ts +52 -2
- package/src/resolvers/SqlLoggingConfigResolver.ts +691 -0
- package/src/resolvers/UserFavoriteResolver.ts +6 -6
- package/src/resolvers/UserResolver.ts +6 -6
- package/src/resolvers/UserViewResolver.ts +6 -6
|
@@ -10,7 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
|
-
import { Resolver, Mutation, Arg, Ctx, ObjectType, Field } from 'type-graphql';
|
|
13
|
+
import { Resolver, Mutation, Arg, Ctx, ObjectType, Field, Int } from 'type-graphql';
|
|
14
14
|
import { LogError, LogStatus, Metadata } from '@memberjunction/core';
|
|
15
15
|
import { AIPromptRunner, AIPromptParams } from '@memberjunction/ai-prompts';
|
|
16
16
|
import { ResolverBase } from '../generic/ResolverBase.js';
|
|
@@ -66,7 +66,7 @@ AIPromptRunResult = __decorate([
|
|
|
66
66
|
], AIPromptRunResult);
|
|
67
67
|
export { AIPromptRunResult };
|
|
68
68
|
let RunAIPromptResolver = class RunAIPromptResolver extends ResolverBase {
|
|
69
|
-
async RunAIPrompt(promptId, { userPayload }, data, modelId, vendorId, configurationId, skipValidation, templateData) {
|
|
69
|
+
async RunAIPrompt(promptId, { userPayload }, data, modelId, vendorId, configurationId, skipValidation, templateData, responseFormat, temperature, topP, topK, minP, frequencyPenalty, presencePenalty, seed, stopSequences, includeLogProbs, topLogProbs, messages) {
|
|
70
70
|
const startTime = Date.now();
|
|
71
71
|
try {
|
|
72
72
|
LogStatus(`=== RUNNING AI PROMPT FOR ID: ${promptId} ===`);
|
|
@@ -131,6 +131,44 @@ let RunAIPromptResolver = class RunAIPromptResolver extends ResolverBase {
|
|
|
131
131
|
promptParams.configurationId = configurationId;
|
|
132
132
|
promptParams.contextUser = currentUser;
|
|
133
133
|
promptParams.skipValidation = skipValidation || false;
|
|
134
|
+
if (messages) {
|
|
135
|
+
try {
|
|
136
|
+
promptParams.conversationMessages = JSON.parse(messages);
|
|
137
|
+
}
|
|
138
|
+
catch (parseError) {
|
|
139
|
+
promptParams.conversationMessages = [{
|
|
140
|
+
role: 'user',
|
|
141
|
+
content: messages
|
|
142
|
+
}];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (responseFormat) {
|
|
146
|
+
promptEntity.ResponseFormat = responseFormat;
|
|
147
|
+
}
|
|
148
|
+
const additionalParams = {};
|
|
149
|
+
if (temperature != null)
|
|
150
|
+
additionalParams.temperature = temperature;
|
|
151
|
+
if (topP != null)
|
|
152
|
+
additionalParams.topP = topP;
|
|
153
|
+
if (topK != null)
|
|
154
|
+
additionalParams.topK = topK;
|
|
155
|
+
if (minP != null)
|
|
156
|
+
additionalParams.minP = minP;
|
|
157
|
+
if (frequencyPenalty != null)
|
|
158
|
+
additionalParams.frequencyPenalty = frequencyPenalty;
|
|
159
|
+
if (presencePenalty != null)
|
|
160
|
+
additionalParams.presencePenalty = presencePenalty;
|
|
161
|
+
if (seed != null)
|
|
162
|
+
additionalParams.seed = seed;
|
|
163
|
+
if (stopSequences != null)
|
|
164
|
+
additionalParams.stopSequences = stopSequences;
|
|
165
|
+
if (includeLogProbs != null)
|
|
166
|
+
additionalParams.includeLogProbs = includeLogProbs;
|
|
167
|
+
if (topLogProbs != null)
|
|
168
|
+
additionalParams.topLogProbs = topLogProbs;
|
|
169
|
+
if (Object.keys(additionalParams).length > 0) {
|
|
170
|
+
promptParams.additionalParameters = additionalParams;
|
|
171
|
+
}
|
|
134
172
|
const result = await promptRunner.ExecutePrompt(promptParams);
|
|
135
173
|
const executionTime = Date.now() - startTime;
|
|
136
174
|
if (result.success) {
|
|
@@ -177,8 +215,20 @@ __decorate([
|
|
|
177
215
|
__param(5, Arg('configurationId', { nullable: true })),
|
|
178
216
|
__param(6, Arg('skipValidation', { nullable: true })),
|
|
179
217
|
__param(7, Arg('templateData', { nullable: true })),
|
|
218
|
+
__param(8, Arg('responseFormat', { nullable: true })),
|
|
219
|
+
__param(9, Arg('temperature', { nullable: true })),
|
|
220
|
+
__param(10, Arg('topP', { nullable: true })),
|
|
221
|
+
__param(11, Arg('topK', () => Int, { nullable: true })),
|
|
222
|
+
__param(12, Arg('minP', { nullable: true })),
|
|
223
|
+
__param(13, Arg('frequencyPenalty', { nullable: true })),
|
|
224
|
+
__param(14, Arg('presencePenalty', { nullable: true })),
|
|
225
|
+
__param(15, Arg('seed', () => Int, { nullable: true })),
|
|
226
|
+
__param(16, Arg('stopSequences', () => [String], { nullable: true })),
|
|
227
|
+
__param(17, Arg('includeLogProbs', { nullable: true })),
|
|
228
|
+
__param(18, Arg('topLogProbs', () => Int, { nullable: true })),
|
|
229
|
+
__param(19, Arg('messages', { nullable: true })),
|
|
180
230
|
__metadata("design:type", Function),
|
|
181
|
-
__metadata("design:paramtypes", [String, Object, String, String, String, String, Boolean, String]),
|
|
231
|
+
__metadata("design:paramtypes", [String, Object, String, String, String, String, Boolean, String, String, Number, Number, Number, Number, Number, Number, Number, Array, Boolean, Number, String]),
|
|
182
232
|
__metadata("design:returntype", Promise)
|
|
183
233
|
], RunAIPromptResolver.prototype, "RunAIPrompt", null);
|
|
184
234
|
RunAIPromptResolver = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RunAIPromptResolver.js","sourceRoot":"","sources":["../../src/resolvers/RunAIPromptResolver.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"RunAIPromptResolver.js","sourceRoot":"","sources":["../../src/resolvers/RunAIPromptResolver.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEpF,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAGnD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAE1B,OAAO,CAAU;IAGjB,MAAM,CAAU;IAGhB,YAAY,CAAU;IAGtB,KAAK,CAAU;IAGf,eAAe,CAAU;IAGzB,UAAU,CAAU;IAGpB,WAAW,CAAU;IAGrB,SAAS,CAAU;IAGnB,gBAAgB,CAAU;CAC7B,CAAA;AAzBG;IADC,KAAK,EAAE;;kDACS;AAGjB;IADC,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;iDACV;AAGhB;IADC,KAAK,CAAC,E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AAA,GAAG,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IACjD,YAAA,GAAG,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;;;;sDA6JvC;AAnLQ,mBAAmB;IAD/B,QAAQ,EAAE;GACE,mBAAmB,CAoL/B"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { AppContext } from '../types.js';
|
|
2
|
+
import { ResolverBase } from '../generic/ResolverBase.js';
|
|
3
|
+
export declare class SqlLoggingOptions {
|
|
4
|
+
formatAsMigration?: boolean;
|
|
5
|
+
description?: string;
|
|
6
|
+
statementTypes?: 'queries' | 'mutations' | 'both';
|
|
7
|
+
batchSeparator?: string;
|
|
8
|
+
prettyPrint?: boolean;
|
|
9
|
+
logRecordChangeMetadata?: boolean;
|
|
10
|
+
retainEmptyLogFiles?: boolean;
|
|
11
|
+
filterByUserId?: string;
|
|
12
|
+
sessionName?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class SqlLoggingSession {
|
|
15
|
+
id: string;
|
|
16
|
+
filePath: string;
|
|
17
|
+
startTime: Date;
|
|
18
|
+
statementCount: number;
|
|
19
|
+
options: SqlLoggingOptions;
|
|
20
|
+
sessionName?: string;
|
|
21
|
+
filterByUserId?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare class SqlLoggingOptionsInput {
|
|
24
|
+
formatAsMigration?: boolean;
|
|
25
|
+
description?: string;
|
|
26
|
+
statementTypes?: 'queries' | 'mutations' | 'both';
|
|
27
|
+
batchSeparator?: string;
|
|
28
|
+
prettyPrint?: boolean;
|
|
29
|
+
logRecordChangeMetadata?: boolean;
|
|
30
|
+
retainEmptyLogFiles?: boolean;
|
|
31
|
+
filterByUserId?: string;
|
|
32
|
+
sessionName?: string;
|
|
33
|
+
}
|
|
34
|
+
export declare class StartSqlLoggingInput {
|
|
35
|
+
fileName?: string;
|
|
36
|
+
options?: SqlLoggingOptionsInput;
|
|
37
|
+
filterToCurrentUser?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare class SqlLoggingConfig {
|
|
40
|
+
enabled: boolean;
|
|
41
|
+
defaultOptions: SqlLoggingOptions;
|
|
42
|
+
allowedLogDirectory: string;
|
|
43
|
+
maxActiveSessions: number;
|
|
44
|
+
autoCleanupEmptyFiles: boolean;
|
|
45
|
+
sessionTimeout: number;
|
|
46
|
+
activeSessionCount: number;
|
|
47
|
+
}
|
|
48
|
+
export declare class SqlLoggingConfigResolver extends ResolverBase {
|
|
49
|
+
private static readonly LOG_FILE_PREFIX;
|
|
50
|
+
private checkOwnerAccess;
|
|
51
|
+
sqlLoggingConfig(context: AppContext): Promise<SqlLoggingConfig>;
|
|
52
|
+
activeSqlLoggingSessions(context: AppContext): Promise<SqlLoggingSession[]>;
|
|
53
|
+
startSqlLogging(input: StartSqlLoggingInput, context: AppContext): Promise<SqlLoggingSession>;
|
|
54
|
+
stopSqlLogging(sessionId: string, context: AppContext): Promise<boolean>;
|
|
55
|
+
stopAllSqlLogging(context: AppContext): Promise<boolean>;
|
|
56
|
+
updateSqlLoggingDefaults(options: SqlLoggingOptionsInput, context: AppContext): Promise<SqlLoggingOptions>;
|
|
57
|
+
readSqlLogFile(sessionId: string, maxLines: number | null, context: AppContext): Promise<string>;
|
|
58
|
+
debugCurrentUserEmail(context: AppContext): Promise<string>;
|
|
59
|
+
private ensureDirectoryExists;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=SqlLoggingConfigResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqlLoggingConfigResolver.d.ts","sourceRoot":"","sources":["../../src/resolvers/SqlLoggingConfigResolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAQzC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAM1D,qBACa,iBAAiB;IAG5B,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AiB,CAAC;IAIlC,mBAAmB,EAAE,MAAM,CAAC;IAI5B,iBAAiB,EAAE,MAAM,CAAC;IAI1B,qBAAqB,EAAE,OAAO,CAAC;IAI/B,cAAc,EAAE,MAAM,CAAC;IAIvB,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AA8BD,qBACa,wBAAyB,SAAQ,YAAY;IAExD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAc;YAgBvC,gBAAgB;IA6DxB,gBAAgB,CAAQ,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAwDvE,wBAAwB,CAAQ,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAsDlF,eAAe,CACuB,KAAK,EAAE,oBAAoB,EAC9D,OAAO,EAAE,UAAU,GACzB,OAAO,CAAC,iBAAiB,CAAC;IAsFvB,cAAc,CACc,SAAS,EAAE,MAAM,EAC1C,OAAO,EAAE,UAAU,GACzB,OAAO,CAAC,OAAO,CAAC;IAqCb,iBAAiB,CAAQ,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAmC/D,wBAAwB,CACkB,OAAO,EAAE,sBAAsB,EACtE,OAAO,EAAE,UAAU,GACzB,OAAO,CAAC,iBAAiB,CAAC;IAwCvB,cAAc,CACc,SAAS,EAAE,MAAM,EACD,QAAQ,EAAE,MAAM,GAAG,IAAI,EAChE,OAAO,EAAE,UAAU,GACzB,OAAO,CAAC,MAAM,CAAC;IA+DZ,qBAAqB,CAAQ,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;YAqB1D,qBAAqB;CAOpC"}
|
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
var SqlLoggingConfigResolver_1;
|
|
14
|
+
import { Arg, Ctx, Field, InputType, Mutation, ObjectType, Query, Int, Resolver } from 'type-graphql';
|
|
15
|
+
import { Metadata } from '@memberjunction/core';
|
|
16
|
+
import { UserCache } from '@memberjunction/sqlserver-dataprovider';
|
|
17
|
+
import * as path from 'path';
|
|
18
|
+
import * as fs from 'fs/promises';
|
|
19
|
+
import { loadConfig } from '../config.js';
|
|
20
|
+
import { ResolverBase } from '../generic/ResolverBase.js';
|
|
21
|
+
let SqlLoggingOptions = class SqlLoggingOptions {
|
|
22
|
+
formatAsMigration;
|
|
23
|
+
description;
|
|
24
|
+
statementTypes;
|
|
25
|
+
batchSeparator;
|
|
26
|
+
prettyPrint;
|
|
27
|
+
logRecordChangeMetadata;
|
|
28
|
+
retainEmptyLogFiles;
|
|
29
|
+
filterByUserId;
|
|
30
|
+
sessionName;
|
|
31
|
+
};
|
|
32
|
+
__decorate([
|
|
33
|
+
Field(() => Boolean, { nullable: true }),
|
|
34
|
+
__metadata("design:type", Boolean)
|
|
35
|
+
], SqlLoggingOptions.prototype, "formatAsMigration", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
Field(() => String, { nullable: true }),
|
|
38
|
+
__metadata("design:type", String)
|
|
39
|
+
], SqlLoggingOptions.prototype, "description", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
Field(() => String, { nullable: true }),
|
|
42
|
+
__metadata("design:type", String)
|
|
43
|
+
], SqlLoggingOptions.prototype, "statementTypes", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
Field(() => String, { nullable: true }),
|
|
46
|
+
__metadata("design:type", String)
|
|
47
|
+
], SqlLoggingOptions.prototype, "batchSeparator", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
Field(() => Boolean, { nullable: true }),
|
|
50
|
+
__metadata("design:type", Boolean)
|
|
51
|
+
], SqlLoggingOptions.prototype, "prettyPrint", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
Field(() => Boolean, { nullable: true }),
|
|
54
|
+
__metadata("design:type", Boolean)
|
|
55
|
+
], SqlLoggingOptions.prototype, "logRecordChangeMetadata", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
Field(() => Boolean, { nullable: true }),
|
|
58
|
+
__metadata("design:type", Boolean)
|
|
59
|
+
], SqlLoggingOptions.prototype, "retainEmptyLogFiles", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
Field(() => String, { nullable: true }),
|
|
62
|
+
__metadata("design:type", String)
|
|
63
|
+
], SqlLoggingOptions.prototype, "filterByUserId", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
Field(() => String, { nullable: true }),
|
|
66
|
+
__metadata("design:type", String)
|
|
67
|
+
], SqlLoggingOptions.prototype, "sessionName", void 0);
|
|
68
|
+
SqlLoggingOptions = __decorate([
|
|
69
|
+
ObjectType()
|
|
70
|
+
], SqlLoggingOptions);
|
|
71
|
+
export { SqlLoggingOptions };
|
|
72
|
+
let SqlLoggingSession = class SqlLoggingSession {
|
|
73
|
+
id;
|
|
74
|
+
filePath;
|
|
75
|
+
startTime;
|
|
76
|
+
statementCount;
|
|
77
|
+
options;
|
|
78
|
+
sessionName;
|
|
79
|
+
filterByUserId;
|
|
80
|
+
};
|
|
81
|
+
__decorate([
|
|
82
|
+
Field(() => String),
|
|
83
|
+
__metadata("design:type", String)
|
|
84
|
+
], SqlLoggingSession.prototype, "id", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
Field(() => String),
|
|
87
|
+
__metadata("design:type", String)
|
|
88
|
+
], SqlLoggingSession.prototype, "filePath", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
Field(() => Date),
|
|
91
|
+
__metadata("design:type", Date)
|
|
92
|
+
], SqlLoggingSession.prototype, "startTime", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
Field(() => Int),
|
|
95
|
+
__metadata("design:type", Number)
|
|
96
|
+
], SqlLoggingSession.prototype, "statementCount", void 0);
|
|
97
|
+
__decorate([
|
|
98
|
+
Field(() => SqlLoggingOptions),
|
|
99
|
+
__metadata("design:type", SqlLoggingOptions)
|
|
100
|
+
], SqlLoggingSession.prototype, "options", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
Field(() => String, { nullable: true }),
|
|
103
|
+
__metadata("design:type", String)
|
|
104
|
+
], SqlLoggingSession.prototype, "sessionName", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
Field(() => String, { nullable: true }),
|
|
107
|
+
__metadata("design:type", String)
|
|
108
|
+
], SqlLoggingSession.prototype, "filterByUserId", void 0);
|
|
109
|
+
SqlLoggingSession = __decorate([
|
|
110
|
+
ObjectType()
|
|
111
|
+
], SqlLoggingSession);
|
|
112
|
+
export { SqlLoggingSession };
|
|
113
|
+
let SqlLoggingOptionsInput = class SqlLoggingOptionsInput {
|
|
114
|
+
formatAsMigration;
|
|
115
|
+
description;
|
|
116
|
+
statementTypes;
|
|
117
|
+
batchSeparator;
|
|
118
|
+
prettyPrint;
|
|
119
|
+
logRecordChangeMetadata;
|
|
120
|
+
retainEmptyLogFiles;
|
|
121
|
+
filterByUserId;
|
|
122
|
+
sessionName;
|
|
123
|
+
};
|
|
124
|
+
__decorate([
|
|
125
|
+
Field(() => Boolean, { nullable: true }),
|
|
126
|
+
__metadata("design:type", Boolean)
|
|
127
|
+
], SqlLoggingOptionsInput.prototype, "formatAsMigration", void 0);
|
|
128
|
+
__decorate([
|
|
129
|
+
Field(() => String, { nullable: true }),
|
|
130
|
+
__metadata("design:type", String)
|
|
131
|
+
], SqlLoggingOptionsInput.prototype, "description", void 0);
|
|
132
|
+
__decorate([
|
|
133
|
+
Field(() => String, { nullable: true }),
|
|
134
|
+
__metadata("design:type", String)
|
|
135
|
+
], SqlLoggingOptionsInput.prototype, "statementTypes", void 0);
|
|
136
|
+
__decorate([
|
|
137
|
+
Field(() => String, { nullable: true }),
|
|
138
|
+
__metadata("design:type", String)
|
|
139
|
+
], SqlLoggingOptionsInput.prototype, "batchSeparator", void 0);
|
|
140
|
+
__decorate([
|
|
141
|
+
Field(() => Boolean, { nullable: true }),
|
|
142
|
+
__metadata("design:type", Boolean)
|
|
143
|
+
], SqlLoggingOptionsInput.prototype, "prettyPrint", void 0);
|
|
144
|
+
__decorate([
|
|
145
|
+
Field(() => Boolean, { nullable: true }),
|
|
146
|
+
__metadata("design:type", Boolean)
|
|
147
|
+
], SqlLoggingOptionsInput.prototype, "logRecordChangeMetadata", void 0);
|
|
148
|
+
__decorate([
|
|
149
|
+
Field(() => Boolean, { nullable: true }),
|
|
150
|
+
__metadata("design:type", Boolean)
|
|
151
|
+
], SqlLoggingOptionsInput.prototype, "retainEmptyLogFiles", void 0);
|
|
152
|
+
__decorate([
|
|
153
|
+
Field(() => String, { nullable: true }),
|
|
154
|
+
__metadata("design:type", String)
|
|
155
|
+
], SqlLoggingOptionsInput.prototype, "filterByUserId", void 0);
|
|
156
|
+
__decorate([
|
|
157
|
+
Field(() => String, { nullable: true }),
|
|
158
|
+
__metadata("design:type", String)
|
|
159
|
+
], SqlLoggingOptionsInput.prototype, "sessionName", void 0);
|
|
160
|
+
SqlLoggingOptionsInput = __decorate([
|
|
161
|
+
InputType()
|
|
162
|
+
], SqlLoggingOptionsInput);
|
|
163
|
+
export { SqlLoggingOptionsInput };
|
|
164
|
+
let StartSqlLoggingInput = class StartSqlLoggingInput {
|
|
165
|
+
fileName;
|
|
166
|
+
options;
|
|
167
|
+
filterToCurrentUser;
|
|
168
|
+
};
|
|
169
|
+
__decorate([
|
|
170
|
+
Field(() => String, { nullable: true }),
|
|
171
|
+
__metadata("design:type", String)
|
|
172
|
+
], StartSqlLoggingInput.prototype, "fileName", void 0);
|
|
173
|
+
__decorate([
|
|
174
|
+
Field(() => SqlLoggingOptionsInput, { nullable: true }),
|
|
175
|
+
__metadata("design:type", SqlLoggingOptionsInput)
|
|
176
|
+
], StartSqlLoggingInput.prototype, "options", void 0);
|
|
177
|
+
__decorate([
|
|
178
|
+
Field(() => Boolean, { nullable: true }),
|
|
179
|
+
__metadata("design:type", Boolean)
|
|
180
|
+
], StartSqlLoggingInput.prototype, "filterToCurrentUser", void 0);
|
|
181
|
+
StartSqlLoggingInput = __decorate([
|
|
182
|
+
InputType()
|
|
183
|
+
], StartSqlLoggingInput);
|
|
184
|
+
export { StartSqlLoggingInput };
|
|
185
|
+
let SqlLoggingConfig = class SqlLoggingConfig {
|
|
186
|
+
enabled;
|
|
187
|
+
defaultOptions;
|
|
188
|
+
allowedLogDirectory;
|
|
189
|
+
maxActiveSessions;
|
|
190
|
+
autoCleanupEmptyFiles;
|
|
191
|
+
sessionTimeout;
|
|
192
|
+
activeSessionCount;
|
|
193
|
+
};
|
|
194
|
+
__decorate([
|
|
195
|
+
Field(() => Boolean),
|
|
196
|
+
__metadata("design:type", Boolean)
|
|
197
|
+
], SqlLoggingConfig.prototype, "enabled", void 0);
|
|
198
|
+
__decorate([
|
|
199
|
+
Field(() => SqlLoggingOptions),
|
|
200
|
+
__metadata("design:type", SqlLoggingOptions)
|
|
201
|
+
], SqlLoggingConfig.prototype, "defaultOptions", void 0);
|
|
202
|
+
__decorate([
|
|
203
|
+
Field(() => String),
|
|
204
|
+
__metadata("design:type", String)
|
|
205
|
+
], SqlLoggingConfig.prototype, "allowedLogDirectory", void 0);
|
|
206
|
+
__decorate([
|
|
207
|
+
Field(() => Int),
|
|
208
|
+
__metadata("design:type", Number)
|
|
209
|
+
], SqlLoggingConfig.prototype, "maxActiveSessions", void 0);
|
|
210
|
+
__decorate([
|
|
211
|
+
Field(() => Boolean),
|
|
212
|
+
__metadata("design:type", Boolean)
|
|
213
|
+
], SqlLoggingConfig.prototype, "autoCleanupEmptyFiles", void 0);
|
|
214
|
+
__decorate([
|
|
215
|
+
Field(() => Int),
|
|
216
|
+
__metadata("design:type", Number)
|
|
217
|
+
], SqlLoggingConfig.prototype, "sessionTimeout", void 0);
|
|
218
|
+
__decorate([
|
|
219
|
+
Field(() => Int),
|
|
220
|
+
__metadata("design:type", Number)
|
|
221
|
+
], SqlLoggingConfig.prototype, "activeSessionCount", void 0);
|
|
222
|
+
SqlLoggingConfig = __decorate([
|
|
223
|
+
ObjectType()
|
|
224
|
+
], SqlLoggingConfig);
|
|
225
|
+
export { SqlLoggingConfig };
|
|
226
|
+
let SqlLoggingConfigResolver = class SqlLoggingConfigResolver extends ResolverBase {
|
|
227
|
+
static { SqlLoggingConfigResolver_1 = this; }
|
|
228
|
+
static LOG_FILE_PREFIX = 'sql-log-';
|
|
229
|
+
async checkOwnerAccess(context) {
|
|
230
|
+
const userEmail = context.userPayload?.email;
|
|
231
|
+
if (!userEmail) {
|
|
232
|
+
throw new Error('User not authenticated');
|
|
233
|
+
}
|
|
234
|
+
const users = UserCache.Instance.Users;
|
|
235
|
+
const user = users.find(u => u.Email.toLowerCase() === userEmail.toLowerCase());
|
|
236
|
+
if (!user) {
|
|
237
|
+
throw new Error('User not found');
|
|
238
|
+
}
|
|
239
|
+
console.log('SQL Logging access check:', {
|
|
240
|
+
email: user.Email,
|
|
241
|
+
type: user.Type,
|
|
242
|
+
typeLength: user.Type?.length,
|
|
243
|
+
typeTrimmed: user.Type?.trim(),
|
|
244
|
+
isOwner: user.Type?.trim().toLowerCase() === 'owner'
|
|
245
|
+
});
|
|
246
|
+
if (user.Type?.trim().toLowerCase() !== 'owner') {
|
|
247
|
+
throw new Error('Access denied. This feature requires Owner privileges.');
|
|
248
|
+
}
|
|
249
|
+
return user;
|
|
250
|
+
}
|
|
251
|
+
async sqlLoggingConfig(context) {
|
|
252
|
+
await this.checkOwnerAccess(context);
|
|
253
|
+
const config = await loadConfig();
|
|
254
|
+
const provider = Metadata.Provider;
|
|
255
|
+
const activeSessions = provider.GetActiveSqlLoggingSessions();
|
|
256
|
+
return {
|
|
257
|
+
enabled: config.sqlLogging?.enabled ?? false,
|
|
258
|
+
defaultOptions: config.sqlLogging?.defaultOptions ?? {
|
|
259
|
+
formatAsMigration: false,
|
|
260
|
+
statementTypes: 'both',
|
|
261
|
+
batchSeparator: 'GO',
|
|
262
|
+
prettyPrint: true,
|
|
263
|
+
logRecordChangeMetadata: false,
|
|
264
|
+
retainEmptyLogFiles: false
|
|
265
|
+
},
|
|
266
|
+
allowedLogDirectory: config.sqlLogging?.allowedLogDirectory ?? './logs/sql',
|
|
267
|
+
maxActiveSessions: config.sqlLogging?.maxActiveSessions ?? 5,
|
|
268
|
+
autoCleanupEmptyFiles: config.sqlLogging?.autoCleanupEmptyFiles ?? true,
|
|
269
|
+
sessionTimeout: config.sqlLogging?.sessionTimeout ?? 3600000,
|
|
270
|
+
activeSessionCount: activeSessions.length
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
async activeSqlLoggingSessions(context) {
|
|
274
|
+
await this.checkOwnerAccess(context);
|
|
275
|
+
const provider = Metadata.Provider;
|
|
276
|
+
const sessions = provider.GetActiveSqlLoggingSessions();
|
|
277
|
+
return sessions.map(session => ({
|
|
278
|
+
id: session.id,
|
|
279
|
+
filePath: session.filePath,
|
|
280
|
+
startTime: session.startTime,
|
|
281
|
+
statementCount: session.statementCount,
|
|
282
|
+
options: session.options,
|
|
283
|
+
sessionName: session.options.sessionName,
|
|
284
|
+
filterByUserId: session.options.filterByUserId
|
|
285
|
+
}));
|
|
286
|
+
}
|
|
287
|
+
async startSqlLogging(input, context) {
|
|
288
|
+
await this.checkOwnerAccess(context);
|
|
289
|
+
const config = await loadConfig();
|
|
290
|
+
if (!config.sqlLogging?.enabled) {
|
|
291
|
+
throw new Error('SQL logging is not enabled in the server configuration');
|
|
292
|
+
}
|
|
293
|
+
const provider = Metadata.Provider;
|
|
294
|
+
const activeSessions = provider.GetActiveSqlLoggingSessions();
|
|
295
|
+
if (activeSessions.length >= (config.sqlLogging.maxActiveSessions ?? 5)) {
|
|
296
|
+
throw new Error(`Maximum number of active SQL logging sessions (${config.sqlLogging.maxActiveSessions}) reached`);
|
|
297
|
+
}
|
|
298
|
+
const allowedDir = path.resolve(config.sqlLogging.allowedLogDirectory ?? './logs/sql');
|
|
299
|
+
await this.ensureDirectoryExists(allowedDir);
|
|
300
|
+
const fileName = input.fileName || `${SqlLoggingConfigResolver_1.LOG_FILE_PREFIX}${new Date().toISOString().replace(/[:.]/g, '-')}.sql`;
|
|
301
|
+
const filePath = path.join(allowedDir, fileName);
|
|
302
|
+
const resolvedPath = path.resolve(filePath);
|
|
303
|
+
if (!resolvedPath.startsWith(allowedDir)) {
|
|
304
|
+
throw new Error('Invalid file path - must be within allowed log directory');
|
|
305
|
+
}
|
|
306
|
+
const defaultOptions = config.sqlLogging.defaultOptions || {};
|
|
307
|
+
const userInfo = input.filterToCurrentUser ? this.GetUserFromPayload(context.userPayload) : undefined;
|
|
308
|
+
const sessionOptions = {
|
|
309
|
+
...defaultOptions,
|
|
310
|
+
...input.options,
|
|
311
|
+
sessionName: input.options?.sessionName || `Session started by ${context.userPayload.email}`,
|
|
312
|
+
filterByUserId: input.filterToCurrentUser ? userInfo?.ID : input.options?.filterByUserId
|
|
313
|
+
};
|
|
314
|
+
const session = await provider.CreateSqlLogger(filePath, sessionOptions);
|
|
315
|
+
if (config.sqlLogging.sessionTimeout > 0) {
|
|
316
|
+
setTimeout(async () => {
|
|
317
|
+
try {
|
|
318
|
+
await session.dispose();
|
|
319
|
+
}
|
|
320
|
+
catch (e) {
|
|
321
|
+
}
|
|
322
|
+
}, config.sqlLogging.sessionTimeout);
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
id: session.id,
|
|
326
|
+
filePath: session.filePath,
|
|
327
|
+
startTime: session.startTime,
|
|
328
|
+
statementCount: session.statementCount,
|
|
329
|
+
options: session.options,
|
|
330
|
+
sessionName: session.options.sessionName,
|
|
331
|
+
filterByUserId: session.options.filterByUserId
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
async stopSqlLogging(sessionId, context) {
|
|
335
|
+
await this.checkOwnerAccess(context);
|
|
336
|
+
const provider = Metadata.Provider;
|
|
337
|
+
const sessionMap = provider._sqlLoggingSessions;
|
|
338
|
+
const session = sessionMap.get(sessionId);
|
|
339
|
+
if (!session) {
|
|
340
|
+
throw new Error(`SQL logging session ${sessionId} not found`);
|
|
341
|
+
}
|
|
342
|
+
await session.dispose();
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
async stopAllSqlLogging(context) {
|
|
346
|
+
await this.checkOwnerAccess(context);
|
|
347
|
+
const provider = Metadata.Provider;
|
|
348
|
+
await provider.DisposeAllSqlLoggingSessions();
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
async updateSqlLoggingDefaults(options, context) {
|
|
352
|
+
await this.checkOwnerAccess(context);
|
|
353
|
+
const config = await loadConfig();
|
|
354
|
+
if (!config.sqlLogging) {
|
|
355
|
+
throw new Error('SQL logging configuration not found');
|
|
356
|
+
}
|
|
357
|
+
config.sqlLogging.defaultOptions = {
|
|
358
|
+
...config.sqlLogging.defaultOptions,
|
|
359
|
+
...options
|
|
360
|
+
};
|
|
361
|
+
return config.sqlLogging.defaultOptions;
|
|
362
|
+
}
|
|
363
|
+
async readSqlLogFile(sessionId, maxLines, context) {
|
|
364
|
+
await this.checkOwnerAccess(context);
|
|
365
|
+
const config = await loadConfig();
|
|
366
|
+
if (!config.sqlLogging?.enabled) {
|
|
367
|
+
throw new Error('SQL logging is not enabled in the server configuration');
|
|
368
|
+
}
|
|
369
|
+
const provider = Metadata.Provider;
|
|
370
|
+
const sessions = provider.GetActiveSqlLoggingSessions();
|
|
371
|
+
const session = sessions.find(s => s.id === sessionId);
|
|
372
|
+
if (!session) {
|
|
373
|
+
throw new Error(`SQL logging session ${sessionId} not found`);
|
|
374
|
+
}
|
|
375
|
+
const allowedDir = path.resolve(config.sqlLogging.allowedLogDirectory ?? './logs/sql');
|
|
376
|
+
const resolvedPath = path.resolve(session.filePath);
|
|
377
|
+
if (!resolvedPath.startsWith(allowedDir)) {
|
|
378
|
+
throw new Error('Access denied - file path outside allowed directory');
|
|
379
|
+
}
|
|
380
|
+
try {
|
|
381
|
+
await fs.access(session.filePath);
|
|
382
|
+
const content = await fs.readFile(session.filePath, 'utf-8');
|
|
383
|
+
if (maxLines && maxLines > 0) {
|
|
384
|
+
const lines = content.split('\n');
|
|
385
|
+
if (lines.length > maxLines) {
|
|
386
|
+
return lines.slice(-maxLines).join('\n');
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return content;
|
|
390
|
+
}
|
|
391
|
+
catch (error) {
|
|
392
|
+
if (error.code === 'ENOENT') {
|
|
393
|
+
return '-- Log file not yet created or is empty --';
|
|
394
|
+
}
|
|
395
|
+
throw new Error(`Failed to read log file: ${error.message}`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
async debugCurrentUserEmail(context) {
|
|
399
|
+
await this.checkOwnerAccess(context);
|
|
400
|
+
const contextUserEmail = context.userPayload?.email || 'NOT_SET';
|
|
401
|
+
return `Context User Email: "${contextUserEmail}" | Note: Provider no longer stores user email - uses contextUser parameter for SQL logging`;
|
|
402
|
+
}
|
|
403
|
+
async ensureDirectoryExists(dir) {
|
|
404
|
+
try {
|
|
405
|
+
await fs.access(dir);
|
|
406
|
+
}
|
|
407
|
+
catch {
|
|
408
|
+
await fs.mkdir(dir, { recursive: true });
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
__decorate([
|
|
413
|
+
Query(() => SqlLoggingConfig),
|
|
414
|
+
__param(0, Ctx()),
|
|
415
|
+
__metadata("design:type", Function),
|
|
416
|
+
__metadata("design:paramtypes", [Object]),
|
|
417
|
+
__metadata("design:returntype", Promise)
|
|
418
|
+
], SqlLoggingConfigResolver.prototype, "sqlLoggingConfig", null);
|
|
419
|
+
__decorate([
|
|
420
|
+
Query(() => [SqlLoggingSession]),
|
|
421
|
+
__param(0, Ctx()),
|
|
422
|
+
__metadata("design:type", Function),
|
|
423
|
+
__metadata("design:paramtypes", [Object]),
|
|
424
|
+
__metadata("design:returntype", Promise)
|
|
425
|
+
], SqlLoggingConfigResolver.prototype, "activeSqlLoggingSessions", null);
|
|
426
|
+
__decorate([
|
|
427
|
+
Mutation(() => SqlLoggingSession),
|
|
428
|
+
__param(0, Arg('input', () => StartSqlLoggingInput)),
|
|
429
|
+
__param(1, Ctx()),
|
|
430
|
+
__metadata("design:type", Function),
|
|
431
|
+
__metadata("design:paramtypes", [StartSqlLoggingInput, Object]),
|
|
432
|
+
__metadata("design:returntype", Promise)
|
|
433
|
+
], SqlLoggingConfigResolver.prototype, "startSqlLogging", null);
|
|
434
|
+
__decorate([
|
|
435
|
+
Mutation(() => Boolean),
|
|
436
|
+
__param(0, Arg('sessionId', () => String)),
|
|
437
|
+
__param(1, Ctx()),
|
|
438
|
+
__metadata("design:type", Function),
|
|
439
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
440
|
+
__metadata("design:returntype", Promise)
|
|
441
|
+
], SqlLoggingConfigResolver.prototype, "stopSqlLogging", null);
|
|
442
|
+
__decorate([
|
|
443
|
+
Mutation(() => Boolean),
|
|
444
|
+
__param(0, Ctx()),
|
|
445
|
+
__metadata("design:type", Function),
|
|
446
|
+
__metadata("design:paramtypes", [Object]),
|
|
447
|
+
__metadata("design:returntype", Promise)
|
|
448
|
+
], SqlLoggingConfigResolver.prototype, "stopAllSqlLogging", null);
|
|
449
|
+
__decorate([
|
|
450
|
+
Mutation(() => SqlLoggingOptions),
|
|
451
|
+
__param(0, Arg('options', () => SqlLoggingOptionsInput)),
|
|
452
|
+
__param(1, Ctx()),
|
|
453
|
+
__metadata("design:type", Function),
|
|
454
|
+
__metadata("design:paramtypes", [SqlLoggingOptionsInput, Object]),
|
|
455
|
+
__metadata("design:returntype", Promise)
|
|
456
|
+
], SqlLoggingConfigResolver.prototype, "updateSqlLoggingDefaults", null);
|
|
457
|
+
__decorate([
|
|
458
|
+
Query(() => String),
|
|
459
|
+
__param(0, Arg('sessionId', () => String)),
|
|
460
|
+
__param(1, Arg('maxLines', () => Int, { nullable: true })),
|
|
461
|
+
__param(2, Ctx()),
|
|
462
|
+
__metadata("design:type", Function),
|
|
463
|
+
__metadata("design:paramtypes", [String, Number, Object]),
|
|
464
|
+
__metadata("design:returntype", Promise)
|
|
465
|
+
], SqlLoggingConfigResolver.prototype, "readSqlLogFile", null);
|
|
466
|
+
__decorate([
|
|
467
|
+
Query(() => String),
|
|
468
|
+
__param(0, Ctx()),
|
|
469
|
+
__metadata("design:type", Function),
|
|
470
|
+
__metadata("design:paramtypes", [Object]),
|
|
471
|
+
__metadata("design:returntype", Promise)
|
|
472
|
+
], SqlLoggingConfigResolver.prototype, "debugCurrentUserEmail", null);
|
|
473
|
+
SqlLoggingConfigResolver = SqlLoggingConfigResolver_1 = __decorate([
|
|
474
|
+
Resolver()
|
|
475
|
+
], SqlLoggingConfigResolver);
|
|
476
|
+
export { SqlLoggingConfigResolver };
|
|
477
|
+
//# sourceMappingURL=SqlLoggingConfigResolver.js.map
|