@burdenoff/be-sdk 2026.1017.10 → 2026.1021.2
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 +25 -0
- package/dist/chunk-GRGTUP44.js +394 -0
- package/dist/chunk-GRGTUP44.js.map +1 -0
- package/dist/{chunk-NCC5UN3L.js → chunk-HDUS6UBO.js} +6 -366
- package/dist/chunk-HDUS6UBO.js.map +1 -0
- package/dist/chunk-WVOW3CJR.js +545 -0
- package/dist/chunk-WVOW3CJR.js.map +1 -0
- package/dist/explicit-activity-scope-CCoxVwAr.d.ts +3 -0
- package/dist/{index-BSlifT21.d.ts → index-D0hKZ9e2.d.ts} +1 -0
- package/dist/index-qwG_TaUg.d.ts +155 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/server/index.d.ts +15 -3
- package/dist/server/index.js +224 -1
- package/dist/server/index.js.map +1 -1
- package/dist/tracker/index.d.ts +2 -1
- package/dist/tracker/index.js +3 -2
- package/dist/validation/index.d.ts +2 -1
- package/dist/validation/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-AHEXIONU.js +0 -165
- package/dist/chunk-AHEXIONU.js.map +0 -1
- package/dist/chunk-NCC5UN3L.js.map +0 -1
- package/dist/index-B2jIInhp.d.ts +0 -76
package/dist/server/index.d.ts
CHANGED
|
@@ -3,10 +3,11 @@ export { A as ActorProvenance, C as ConsentContext, E as ElysiaApp, c as IContex
|
|
|
3
3
|
import * as jose from 'jose';
|
|
4
4
|
import { VerifyOptions } from 'jsonwebtoken';
|
|
5
5
|
import { I as I18n } from '../i18n-DrdPTann.js';
|
|
6
|
-
import { GraphQLError } from 'graphql';
|
|
6
|
+
import { DocumentNode, GraphQLError } from 'graphql';
|
|
7
|
+
import { Plugin } from 'graphql-yoga';
|
|
8
|
+
export { s as suppressMutationAudit } from '../explicit-activity-scope-CCoxVwAr.js';
|
|
7
9
|
export { I as I18nContext, L as LocaleCode } from '../types-C8TbSdEj.js';
|
|
8
10
|
export { P as PrismaClientBase } from '../client-CCXpAZ2r.js';
|
|
9
|
-
import 'graphql-yoga';
|
|
10
11
|
import '../workspace-extension-DiNiTLa3.js';
|
|
11
12
|
import '@prisma/adapter-pg';
|
|
12
13
|
import 'pg';
|
|
@@ -139,6 +140,17 @@ declare function createWorkspaceGuardPlugin(config?: WorkspaceGuardConfig): {
|
|
|
139
140
|
}): undefined;
|
|
140
141
|
};
|
|
141
142
|
|
|
143
|
+
declare const MUTATION_AUDIT_ACTIVITY_TYPE = "graphql.mutation";
|
|
144
|
+
declare const MUTATION_AUDIT_RESOURCE_TYPE = "graphql_mutation";
|
|
145
|
+
interface MutationAuditPluginOptions {
|
|
146
|
+
serviceName: string;
|
|
147
|
+
excludeFields?: Iterable<string>;
|
|
148
|
+
dedupeExplicitActivity?: boolean;
|
|
149
|
+
}
|
|
150
|
+
declare function sanitizeAuditValue(value: unknown, depth?: number): unknown;
|
|
151
|
+
declare function getMutationFieldNames(document: DocumentNode, operationName?: string | null): string[];
|
|
152
|
+
declare function createMutationAuditPlugin(options: MutationAuditPluginOptions | string): Plugin;
|
|
153
|
+
|
|
142
154
|
interface UserFacingErrorOptions {
|
|
143
155
|
code: string;
|
|
144
156
|
userMessage: string;
|
|
@@ -182,4 +194,4 @@ declare function createHumanReadableErrorPlugin(options?: ErrorNormalizationOpti
|
|
|
182
194
|
declare function formatHttpError(error: unknown, options?: ErrorNormalizationOptions): HttpErrorResult;
|
|
183
195
|
declare function createHttpErrorResponse(error: unknown, options?: ErrorNormalizationOptions): Response;
|
|
184
196
|
|
|
185
|
-
export { type AuthConfig, type ContextBuilderOptions, type ErrorNormalizationOptions, type FetchWorkspaceSecretFn, GraphQLContext, type HttpErrorPayload, type HttpErrorResult, IActor, ITenant, JWTPayload, type NormalizedErrorState, ServerDefinition, ServerInstance, type UserFacingErrorOptions, UserFacingGraphQLError, type WorkspaceGuardConfig, WorkspaceSecret, YogaPlugin, authCheck, buildContext, configureAuth, configureContext, configureDefaultAuth, configureServerAuth, createHttpErrorResponse, createHumanReadableErrorPlugin, createServer, createWorkspaceGuardPlugin, decodeJWT, fetchWorkspaceSecret, formatHttpError, generateSymmetricSecret, getContextOptions, normalizeError, normalizeExecutionResultErrors, normalizeGraphQLResponse, normalizeGraphQLResponsePayload, orgCheck, requireWorkspace, tenantCheck, toUserFacingGraphQLError, verifyJWT, workspaceCheck };
|
|
197
|
+
export { type AuthConfig, type ContextBuilderOptions, type ErrorNormalizationOptions, type FetchWorkspaceSecretFn, GraphQLContext, type HttpErrorPayload, type HttpErrorResult, IActor, ITenant, JWTPayload, MUTATION_AUDIT_ACTIVITY_TYPE, MUTATION_AUDIT_RESOURCE_TYPE, type MutationAuditPluginOptions, type NormalizedErrorState, ServerDefinition, ServerInstance, type UserFacingErrorOptions, UserFacingGraphQLError, type WorkspaceGuardConfig, WorkspaceSecret, YogaPlugin, authCheck, buildContext, configureAuth, configureContext, configureDefaultAuth, configureServerAuth, createHttpErrorResponse, createHumanReadableErrorPlugin, createMutationAuditPlugin, createServer, createWorkspaceGuardPlugin, decodeJWT, fetchWorkspaceSecret, formatHttpError, generateSymmetricSecret, getContextOptions, getMutationFieldNames, normalizeError, normalizeExecutionResultErrors, normalizeGraphQLResponse, normalizeGraphQLResponsePayload, orgCheck, requireWorkspace, sanitizeAuditValue, tenantCheck, toUserFacingGraphQLError, verifyJWT, workspaceCheck };
|
package/dist/server/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createHumanReadableErrorPlugin, formatHttpError, normalizeGraphQLResponse, createHttpErrorResponse } from '../chunk-6GL4SLU7.js';
|
|
2
2
|
export { UserFacingGraphQLError, createHttpErrorResponse, createHumanReadableErrorPlugin, createWorkspaceGuardPlugin, formatHttpError, normalizeError, normalizeExecutionResultErrors, normalizeGraphQLResponse, normalizeGraphQLResponsePayload, toUserFacingGraphQLError } from '../chunk-6GL4SLU7.js';
|
|
3
3
|
import { getWorkspaceQuotaRegistry } from '../chunk-WTEHAVBX.js';
|
|
4
|
+
import { trackOperation, createExplicitActivityScope, runInExplicitActivityScope } from '../chunk-GRGTUP44.js';
|
|
5
|
+
export { suppressMutationAudit } from '../chunk-GRGTUP44.js';
|
|
4
6
|
import { setWorkspaceContext, withWorkspaceContext } from '../chunk-3Z2VRCT6.js';
|
|
5
7
|
import { I18n } from '../chunk-EBDHIL7V.js';
|
|
6
8
|
import { getMetricsRegistry } from '../chunk-AWPNRV3L.js';
|
|
@@ -8,6 +10,7 @@ import { ContextManager } from '../chunk-RZOFS2BQ.js';
|
|
|
8
10
|
import { logger } from '../chunk-RU266375.js';
|
|
9
11
|
import { __name } from '../chunk-XE4OXN2W.js';
|
|
10
12
|
import crypto from 'crypto';
|
|
13
|
+
import { Kind, OperationTypeNode } from 'graphql';
|
|
11
14
|
|
|
12
15
|
// src/server/auth.ts
|
|
13
16
|
var getDbFn = null;
|
|
@@ -1272,7 +1275,227 @@ function configureServerAuth(fetchWorkspaceSecret2) {
|
|
|
1272
1275
|
});
|
|
1273
1276
|
}
|
|
1274
1277
|
__name(configureServerAuth, "configureServerAuth");
|
|
1278
|
+
var MUTATION_AUDIT_ACTIVITY_TYPE = "graphql.mutation";
|
|
1279
|
+
var MUTATION_AUDIT_RESOURCE_TYPE = "graphql_mutation";
|
|
1280
|
+
var SENSITIVE_KEY_MARKERS = [
|
|
1281
|
+
"password",
|
|
1282
|
+
"passcode",
|
|
1283
|
+
"pass",
|
|
1284
|
+
"token",
|
|
1285
|
+
"secret",
|
|
1286
|
+
"apikey",
|
|
1287
|
+
"accesskey",
|
|
1288
|
+
"authorization",
|
|
1289
|
+
"cookie",
|
|
1290
|
+
"credential",
|
|
1291
|
+
"clientsecret",
|
|
1292
|
+
"privatekey"
|
|
1293
|
+
];
|
|
1294
|
+
var MAX_DEPTH = 2;
|
|
1295
|
+
var MAX_ARRAY_ITEMS = 5;
|
|
1296
|
+
var MAX_OBJECT_KEYS = 20;
|
|
1297
|
+
var MAX_STRING_LENGTH = 200;
|
|
1298
|
+
function isRecord(value) {
|
|
1299
|
+
return typeof value === "object" && value !== null;
|
|
1300
|
+
}
|
|
1301
|
+
__name(isRecord, "isRecord");
|
|
1302
|
+
function isSensitiveKey(key) {
|
|
1303
|
+
const normalizedKey = key.toLowerCase().replaceAll(/[-_]/g, "");
|
|
1304
|
+
return SENSITIVE_KEY_MARKERS.some((marker) => normalizedKey.includes(marker));
|
|
1305
|
+
}
|
|
1306
|
+
__name(isSensitiveKey, "isSensitiveKey");
|
|
1307
|
+
function truncate(value) {
|
|
1308
|
+
return value.length > MAX_STRING_LENGTH ? `${value.slice(0, MAX_STRING_LENGTH)}...` : value;
|
|
1309
|
+
}
|
|
1310
|
+
__name(truncate, "truncate");
|
|
1311
|
+
function sanitizeAuditValue(value, depth = 0) {
|
|
1312
|
+
if (value == null || typeof value === "boolean" || typeof value === "number") {
|
|
1313
|
+
return value;
|
|
1314
|
+
}
|
|
1315
|
+
if (typeof value === "string") {
|
|
1316
|
+
return truncate(value);
|
|
1317
|
+
}
|
|
1318
|
+
if (depth >= MAX_DEPTH) {
|
|
1319
|
+
return "[Truncated]";
|
|
1320
|
+
}
|
|
1321
|
+
if (Array.isArray(value)) {
|
|
1322
|
+
return value.slice(0, MAX_ARRAY_ITEMS).map((entry) => sanitizeAuditValue(entry, depth + 1));
|
|
1323
|
+
}
|
|
1324
|
+
if (!isRecord(value)) {
|
|
1325
|
+
return `[${typeof value}]`;
|
|
1326
|
+
}
|
|
1327
|
+
const sanitized = {};
|
|
1328
|
+
let count = 0;
|
|
1329
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
1330
|
+
if (count >= MAX_OBJECT_KEYS) {
|
|
1331
|
+
sanitized["__truncated__"] = true;
|
|
1332
|
+
break;
|
|
1333
|
+
}
|
|
1334
|
+
sanitized[key] = isSensitiveKey(key) ? "[REDACTED]" : sanitizeAuditValue(entry, depth + 1);
|
|
1335
|
+
count += 1;
|
|
1336
|
+
}
|
|
1337
|
+
return sanitized;
|
|
1338
|
+
}
|
|
1339
|
+
__name(sanitizeAuditValue, "sanitizeAuditValue");
|
|
1340
|
+
function findMutation(document, operationName) {
|
|
1341
|
+
const operations = document.definitions.filter((definition) => definition.kind === Kind.OPERATION_DEFINITION);
|
|
1342
|
+
let operation;
|
|
1343
|
+
if (operationName) {
|
|
1344
|
+
operation = operations.find((definition) => definition.name?.value === operationName);
|
|
1345
|
+
} else if (operations.length === 1) {
|
|
1346
|
+
operation = operations[0];
|
|
1347
|
+
}
|
|
1348
|
+
return operation?.operation === OperationTypeNode.MUTATION ? operation : void 0;
|
|
1349
|
+
}
|
|
1350
|
+
__name(findMutation, "findMutation");
|
|
1351
|
+
function collectTopLevelFields(selectionSet, fragments, fields, visitedFragments) {
|
|
1352
|
+
for (const selection of selectionSet.selections) {
|
|
1353
|
+
if (selection.kind === Kind.FIELD) {
|
|
1354
|
+
const name = selection.name.value;
|
|
1355
|
+
if (!name.startsWith("__") && !fields.includes(name)) fields.push(name);
|
|
1356
|
+
} else if (selection.kind === Kind.INLINE_FRAGMENT) {
|
|
1357
|
+
collectTopLevelFields(selection.selectionSet, fragments, fields, visitedFragments);
|
|
1358
|
+
} else {
|
|
1359
|
+
const fragmentName = selection.name.value;
|
|
1360
|
+
const fragment = fragments.get(fragmentName);
|
|
1361
|
+
if (fragment && !visitedFragments.has(fragmentName)) {
|
|
1362
|
+
visitedFragments.add(fragmentName);
|
|
1363
|
+
collectTopLevelFields(fragment.selectionSet, fragments, fields, visitedFragments);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
__name(collectTopLevelFields, "collectTopLevelFields");
|
|
1369
|
+
function getMutationFieldNames(document, operationName) {
|
|
1370
|
+
const operation = findMutation(document, operationName);
|
|
1371
|
+
if (!operation) return [];
|
|
1372
|
+
const fragments = /* @__PURE__ */ new Map();
|
|
1373
|
+
for (const definition of document.definitions) {
|
|
1374
|
+
if (definition.kind === Kind.FRAGMENT_DEFINITION) fragments.set(definition.name.value, definition);
|
|
1375
|
+
}
|
|
1376
|
+
const fields = [];
|
|
1377
|
+
collectTopLevelFields(operation.selectionSet, fragments, fields, /* @__PURE__ */ new Set());
|
|
1378
|
+
return fields;
|
|
1379
|
+
}
|
|
1380
|
+
__name(getMutationFieldNames, "getMutationFieldNames");
|
|
1381
|
+
function idOf(value) {
|
|
1382
|
+
if (!isRecord(value)) return void 0;
|
|
1383
|
+
const id2 = value["id"];
|
|
1384
|
+
return typeof id2 === "string" && id2.length > 0 ? id2 : void 0;
|
|
1385
|
+
}
|
|
1386
|
+
__name(idOf, "idOf");
|
|
1387
|
+
function stringOf(value) {
|
|
1388
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
1389
|
+
}
|
|
1390
|
+
__name(stringOf, "stringOf");
|
|
1391
|
+
function findWorkspaceId(value, depth = 0) {
|
|
1392
|
+
if (depth > MAX_DEPTH || !isRecord(value)) return void 0;
|
|
1393
|
+
const direct = stringOf(value["workspaceId"]);
|
|
1394
|
+
if (direct) return direct;
|
|
1395
|
+
for (const entry of Object.values(value)) {
|
|
1396
|
+
const nested = findWorkspaceId(entry, depth + 1);
|
|
1397
|
+
if (nested) return nested;
|
|
1398
|
+
}
|
|
1399
|
+
return void 0;
|
|
1400
|
+
}
|
|
1401
|
+
__name(findWorkspaceId, "findWorkspaceId");
|
|
1402
|
+
function isExecutionResult(value) {
|
|
1403
|
+
return isRecord(value) && ("data" in value || "errors" in value);
|
|
1404
|
+
}
|
|
1405
|
+
__name(isExecutionResult, "isExecutionResult");
|
|
1406
|
+
function recordMutationAudit(input) {
|
|
1407
|
+
const context = isRecord(input.contextValue) ? input.contextValue : {};
|
|
1408
|
+
const actor = isRecord(context["actor"]) ? context["actor"] : void 0;
|
|
1409
|
+
const actorId = idOf(actor) ?? stringOf(context["actorId"]) ?? "anonymous";
|
|
1410
|
+
const actorType = stringOf(actor?.["type"]) ?? stringOf(context["actorType"]) ?? "unknown";
|
|
1411
|
+
const workspaceId = idOf(context["workspace"]) ?? stringOf(context["workspaceId"]) ?? findWorkspaceId(input.variableValues);
|
|
1412
|
+
const tenantId = idOf(context["tenant"]) ?? stringOf(context["tenantId"]);
|
|
1413
|
+
const executionResult = isExecutionResult(input.result) ? input.result : void 0;
|
|
1414
|
+
const errors = executionResult?.errors ?? [];
|
|
1415
|
+
const success = errors.length === 0;
|
|
1416
|
+
const errorMessage = success ? void 0 : truncate(errors.map((error) => error.message).join("; "));
|
|
1417
|
+
const joinedFields = input.fieldNames.join(",");
|
|
1418
|
+
void trackOperation({
|
|
1419
|
+
operationName: joinedFields,
|
|
1420
|
+
userId: actorId,
|
|
1421
|
+
workspaceId,
|
|
1422
|
+
success,
|
|
1423
|
+
errorMessage,
|
|
1424
|
+
activityOptions: {
|
|
1425
|
+
enabled: true,
|
|
1426
|
+
activityType: MUTATION_AUDIT_ACTIVITY_TYPE,
|
|
1427
|
+
description: `GraphQL mutation executed: ${input.fieldNames.join(", ")}`,
|
|
1428
|
+
workspaceId,
|
|
1429
|
+
resourceType: MUTATION_AUDIT_RESOURCE_TYPE,
|
|
1430
|
+
resourceId: joinedFields,
|
|
1431
|
+
metadata: {
|
|
1432
|
+
serviceName: input.serviceName,
|
|
1433
|
+
source: "mutation-audit-backstop",
|
|
1434
|
+
actorType,
|
|
1435
|
+
fieldNames: input.fieldNames,
|
|
1436
|
+
tenantId,
|
|
1437
|
+
tracking: sanitizeAuditValue(context["tracking"]),
|
|
1438
|
+
variablePreview: sanitizeAuditValue(input.variableValues),
|
|
1439
|
+
resultPreview: sanitizeAuditValue(executionResult ? {
|
|
1440
|
+
data: executionResult.data,
|
|
1441
|
+
errors: errors.map((error) => ({
|
|
1442
|
+
message: error.message,
|
|
1443
|
+
path: error.path?.join(".")
|
|
1444
|
+
}))
|
|
1445
|
+
} : void 0)
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
}).catch((error) => {
|
|
1449
|
+
logger.warn("[MutationAuditPlugin] Failed to record mutation audit", {
|
|
1450
|
+
serviceName: input.serviceName,
|
|
1451
|
+
fieldNames: input.fieldNames,
|
|
1452
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1453
|
+
});
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
__name(recordMutationAudit, "recordMutationAudit");
|
|
1457
|
+
function shouldWrite(scope, dedupe) {
|
|
1458
|
+
if (scope.suppressed) return false;
|
|
1459
|
+
return !(dedupe && scope.explicitCount > 0);
|
|
1460
|
+
}
|
|
1461
|
+
__name(shouldWrite, "shouldWrite");
|
|
1462
|
+
function createMutationAuditPlugin(options) {
|
|
1463
|
+
const resolved = typeof options === "string" ? {
|
|
1464
|
+
serviceName: options
|
|
1465
|
+
} : options;
|
|
1466
|
+
const excluded = new Set(resolved.excludeFields ?? []);
|
|
1467
|
+
const dedupe = resolved.dedupeExplicitActivity !== false;
|
|
1468
|
+
return {
|
|
1469
|
+
onExecute({ args, executeFn, setExecuteFn }) {
|
|
1470
|
+
const fieldNames = getMutationFieldNames(args.document, args.operationName).filter((name) => !excluded.has(name));
|
|
1471
|
+
if (fieldNames.length === 0) return;
|
|
1472
|
+
setExecuteFn(async (executeArgs) => {
|
|
1473
|
+
const scope = createExplicitActivityScope();
|
|
1474
|
+
const result = await runInExplicitActivityScope(scope, () => executeFn(executeArgs));
|
|
1475
|
+
try {
|
|
1476
|
+
if (shouldWrite(scope, dedupe)) {
|
|
1477
|
+
recordMutationAudit({
|
|
1478
|
+
serviceName: resolved.serviceName,
|
|
1479
|
+
fieldNames,
|
|
1480
|
+
contextValue: executeArgs.contextValue,
|
|
1481
|
+
variableValues: executeArgs.variableValues,
|
|
1482
|
+
result
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
} catch (error) {
|
|
1486
|
+
logger.warn("[MutationAuditPlugin] Failed to prepare mutation audit", {
|
|
1487
|
+
serviceName: resolved.serviceName,
|
|
1488
|
+
fieldNames,
|
|
1489
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
return result;
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
__name(createMutationAuditPlugin, "createMutationAuditPlugin");
|
|
1275
1498
|
|
|
1276
|
-
export { authCheck, buildContext, configureAuth, configureContext, configureDefaultAuth, configureServerAuth, createServer, decodeJWT, fetchWorkspaceSecret, generateSymmetricSecret, getContextOptions, orgCheck, requireWorkspace, tenantCheck, verifyJWT, workspaceCheck };
|
|
1499
|
+
export { MUTATION_AUDIT_ACTIVITY_TYPE, MUTATION_AUDIT_RESOURCE_TYPE, authCheck, buildContext, configureAuth, configureContext, configureDefaultAuth, configureServerAuth, createMutationAuditPlugin, createServer, decodeJWT, fetchWorkspaceSecret, generateSymmetricSecret, getContextOptions, getMutationFieldNames, orgCheck, requireWorkspace, sanitizeAuditValue, tenantCheck, verifyJWT, workspaceCheck };
|
|
1277
1500
|
//# sourceMappingURL=index.js.map
|
|
1278
1501
|
//# sourceMappingURL=index.js.map
|