@burdenoff/be-sdk 2026.1107.4 → 2026.1108.1
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/auth/index.d.ts +2 -2
- package/dist/auth/index.js +2 -2
- package/dist/{chunk-5EVD6HOD.js → chunk-2T3N5SNW.js} +333 -385
- package/dist/chunk-2T3N5SNW.js.map +1 -0
- package/dist/{chunk-YZIWBUIN.js → chunk-4XIBXZ6J.js} +3 -3
- package/dist/{chunk-YZIWBUIN.js.map → chunk-4XIBXZ6J.js.map} +1 -1
- package/dist/{chunk-Y4N7N2G4.js → chunk-A6DE32ZS.js} +3 -3
- package/dist/{chunk-Y4N7N2G4.js.map → chunk-A6DE32ZS.js.map} +1 -1
- package/dist/{chunk-DIOS6L7M.js → chunk-FHVBMQDW.js} +3 -3
- package/dist/{chunk-DIOS6L7M.js.map → chunk-FHVBMQDW.js.map} +1 -1
- package/dist/{chunk-5SIL5AG2.js → chunk-I3KOWRT3.js} +3 -3
- package/dist/chunk-I3KOWRT3.js.map +1 -0
- package/dist/{chunk-DXTBH7IW.js → chunk-ID3WR4JS.js} +3 -3
- package/dist/{chunk-DXTBH7IW.js.map → chunk-ID3WR4JS.js.map} +1 -1
- package/dist/{chunk-5CS3ZITV.js → chunk-KH4TRQCO.js} +3 -3
- package/dist/{chunk-5CS3ZITV.js.map → chunk-KH4TRQCO.js.map} +1 -1
- package/dist/{chunk-LQYHWC7F.js → chunk-O2JMZHNH.js} +3 -3
- package/dist/{chunk-LQYHWC7F.js.map → chunk-O2JMZHNH.js.map} +1 -1
- package/dist/{chunk-BD3SMWUU.js → chunk-QVPIACWD.js} +198 -402
- package/dist/chunk-QVPIACWD.js.map +1 -0
- package/dist/database/index.js +2 -2
- package/dist/event-queue/index.d.ts +3 -3
- package/dist/graph/index.d.ts +3 -3
- package/dist/graph/index.js +2 -2
- package/dist/{graphql-CEblo7lw.d.ts → graphql-CMHMQjvd.d.ts} +1 -1
- package/dist/{index-XzbbMKe4.d.ts → index-B8KrxO4j.d.ts} +2 -2
- package/dist/{index-BioY0Ewz.d.ts → index-CmpG-zak.d.ts} +1 -1
- package/dist/{index-DHQKCVDQ.d.ts → index-DCaVm66D.d.ts} +2 -2
- package/dist/{index-7pTpoN3Q.d.ts → index-DE2w7E0d.d.ts} +6 -1
- package/dist/{index-BV8hveh_.d.ts → index-DnjJ9CwI.d.ts} +40 -17
- package/dist/{index-BHe7zIVb.d.ts → index-DwMJZ8PP.d.ts} +2 -2
- package/dist/{index-KZ4OzW6D.d.ts → index-pxYge_6k.d.ts} +1 -1
- package/dist/index.d.ts +14 -13
- package/dist/index.js +31 -28
- package/dist/index.js.map +1 -1
- package/dist/instrumentation/index.d.ts +3 -3
- package/dist/logger/index.d.ts +2 -2
- package/dist/notifications/index.d.ts +3 -3
- package/dist/notifications/index.js +2 -2
- package/dist/prisma/index.js +2 -2
- package/dist/rbac/index.d.ts +2 -2
- package/dist/rbac/index.js +2 -2
- package/dist/resource-caps/index.d.ts +2 -2
- package/dist/telemetry/index.d.ts +4 -4
- package/dist/tracker/index.d.ts +4 -4
- package/dist/tracker/index.js +5 -5
- package/dist/usage/index.d.ts +49 -15
- package/dist/usage/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-5EVD6HOD.js.map +0 -1
- package/dist/chunk-5SIL5AG2.js.map +0 -1
- package/dist/chunk-BD3SMWUU.js.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { UsageModule } from './chunk-QVPIACWD.js';
|
|
2
|
+
import { NotificationsModule, NotificationType2 } from './chunk-KH4TRQCO.js';
|
|
3
|
+
import { RBACModule } from './chunk-A6DE32ZS.js';
|
|
1
4
|
import { markExplicitActivity, runInExplicitActivityScope, createExplicitActivityScope, trackOperation } from './chunk-JVMAQOA3.js';
|
|
2
|
-
import {
|
|
3
|
-
import { NotificationsModule, NotificationType2 } from './chunk-5CS3ZITV.js';
|
|
4
|
-
import { RBACModule } from './chunk-Y4N7N2G4.js';
|
|
5
|
-
import { ValidationError, PermissionDeniedError, QuotaExceededError } from './chunk-5SIL5AG2.js';
|
|
5
|
+
import { SDKError, ValidationError, PermissionDeniedError, QuotaExceededError } from './chunk-I3KOWRT3.js';
|
|
6
6
|
import { logger } from './chunk-RU266375.js';
|
|
7
7
|
import { __name } from './chunk-XE4OXN2W.js';
|
|
8
|
+
import { randomUUID } from 'crypto';
|
|
8
9
|
|
|
9
|
-
// src/activity/index.ts
|
|
10
10
|
var ActivityType = /* @__PURE__ */ (function(ActivityType2) {
|
|
11
11
|
ActivityType2["CREATE"] = "create";
|
|
12
12
|
ActivityType2["READ"] = "read";
|
|
@@ -39,6 +39,194 @@ var ActivitySeverity = /* @__PURE__ */ (function(ActivitySeverity2) {
|
|
|
39
39
|
ActivitySeverity2["CRITICAL"] = "critical";
|
|
40
40
|
return ActivitySeverity2;
|
|
41
41
|
})({});
|
|
42
|
+
var ActivityOperationUnsupportedError = class _ActivityOperationUnsupportedError extends SDKError {
|
|
43
|
+
static {
|
|
44
|
+
__name(this, "ActivityOperationUnsupportedError");
|
|
45
|
+
}
|
|
46
|
+
constructor(operation, guidance) {
|
|
47
|
+
super(`ActivityModule.${operation} is not supported by the workspace activity owner: ${guidance}`, "ACTIVITY_OPERATION_UNSUPPORTED", {
|
|
48
|
+
operation
|
|
49
|
+
});
|
|
50
|
+
this.name = "ActivityOperationUnsupportedError";
|
|
51
|
+
Object.setPrototypeOf(this, _ActivityOperationUnsupportedError.prototype);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var ACTIVITY_LOG_SELECTION = `
|
|
55
|
+
id
|
|
56
|
+
userId
|
|
57
|
+
action
|
|
58
|
+
description
|
|
59
|
+
details
|
|
60
|
+
timestamp
|
|
61
|
+
productId
|
|
62
|
+
workspaceId
|
|
63
|
+
resourceType
|
|
64
|
+
resourceId
|
|
65
|
+
targetUserId
|
|
66
|
+
ipAddress
|
|
67
|
+
userAgent
|
|
68
|
+
actorType
|
|
69
|
+
onBehalfOf
|
|
70
|
+
context {
|
|
71
|
+
projectId
|
|
72
|
+
custom
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
var RECORD_ACTIVITY_MUTATION = `
|
|
76
|
+
mutation RecordActivity($input: RecordActivityInput!) {
|
|
77
|
+
recordActivity(input: $input) {
|
|
78
|
+
${ACTIVITY_LOG_SELECTION}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
var WORKSPACE_ACTIVITY_SLICE_QUERY = `
|
|
83
|
+
query GetWorkspaceActivitySlice($filter: ActivityLogFilter!) {
|
|
84
|
+
getWorkspaceActivitySlice(filter: $filter) {
|
|
85
|
+
${ACTIVITY_LOG_SELECTION}
|
|
86
|
+
}
|
|
87
|
+
activityCount(filter: $filter)
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
var SDK_DETAIL_KEYS = [
|
|
91
|
+
"activityType",
|
|
92
|
+
"status",
|
|
93
|
+
"severity",
|
|
94
|
+
"duration",
|
|
95
|
+
"organizationId",
|
|
96
|
+
"projectId",
|
|
97
|
+
"requestIpAddress",
|
|
98
|
+
"requestUserAgent",
|
|
99
|
+
"errorMessage",
|
|
100
|
+
"ipAddress",
|
|
101
|
+
"userAgent"
|
|
102
|
+
];
|
|
103
|
+
function readRecord(value) {
|
|
104
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
105
|
+
}
|
|
106
|
+
__name(readRecord, "readRecord");
|
|
107
|
+
function readString(value) {
|
|
108
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
109
|
+
}
|
|
110
|
+
__name(readString, "readString");
|
|
111
|
+
function readEnum(values, value, fallback) {
|
|
112
|
+
const allowed = Object.values(values);
|
|
113
|
+
return typeof value === "string" && allowed.includes(value) ? value : fallback;
|
|
114
|
+
}
|
|
115
|
+
__name(readEnum, "readEnum");
|
|
116
|
+
function compact(input) {
|
|
117
|
+
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
|
|
118
|
+
}
|
|
119
|
+
__name(compact, "compact");
|
|
120
|
+
function buildRecordActivityInput(options, context = {}) {
|
|
121
|
+
const severity = options.severity ?? "low";
|
|
122
|
+
const metadata = compact({
|
|
123
|
+
...options.metadata,
|
|
124
|
+
activityType: options.activityType,
|
|
125
|
+
status: options.status,
|
|
126
|
+
severity,
|
|
127
|
+
duration: options.duration,
|
|
128
|
+
// The owner stores errorMessage in a column it does not expose on ActivityLog; keeping a
|
|
129
|
+
// copy in details is what lets a read return it.
|
|
130
|
+
errorMessage: options.errorMessage,
|
|
131
|
+
organizationId: options.organizationId,
|
|
132
|
+
projectId: options.projectId,
|
|
133
|
+
requestIpAddress: options.ipAddress,
|
|
134
|
+
requestUserAgent: options.userAgent
|
|
135
|
+
});
|
|
136
|
+
const activityContext = compact({
|
|
137
|
+
workspaceId: options.workspaceId,
|
|
138
|
+
userId: options.userId,
|
|
139
|
+
projectId: options.projectId,
|
|
140
|
+
custom: options.organizationId ? {
|
|
141
|
+
organizationId: options.organizationId
|
|
142
|
+
} : void 0
|
|
143
|
+
});
|
|
144
|
+
return compact({
|
|
145
|
+
action: options.action,
|
|
146
|
+
description: options.description,
|
|
147
|
+
resourceType: options.resourceType,
|
|
148
|
+
resourceId: options.resourceId,
|
|
149
|
+
workspaceId: options.workspaceId,
|
|
150
|
+
productId: options.productId ?? context.productId,
|
|
151
|
+
targetUserId: options.targetUserId,
|
|
152
|
+
teamId: options.teamId,
|
|
153
|
+
success: options.status !== "failure",
|
|
154
|
+
errorMessage: options.errorMessage,
|
|
155
|
+
actorType: options.actorType,
|
|
156
|
+
onBehalfOf: options.onBehalfOf,
|
|
157
|
+
context: activityContext,
|
|
158
|
+
metadata,
|
|
159
|
+
dedupeKey: options.dedupeKey ?? `sdk-activity:${randomUUID()}`
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
__name(buildRecordActivityInput, "buildRecordActivityInput");
|
|
163
|
+
function toActivity(record) {
|
|
164
|
+
const details = readRecord(record.details) ?? {};
|
|
165
|
+
const custom = readRecord(record.context?.custom);
|
|
166
|
+
const metadata = {};
|
|
167
|
+
for (const [key, value] of Object.entries(details)) {
|
|
168
|
+
if (!SDK_DETAIL_KEYS.includes(key)) metadata[key] = value;
|
|
169
|
+
}
|
|
170
|
+
const duration = details["duration"];
|
|
171
|
+
return {
|
|
172
|
+
id: record.id,
|
|
173
|
+
userId: record.userId,
|
|
174
|
+
activityType: readEnum(ActivityType, details["activityType"], "custom"),
|
|
175
|
+
resourceType: record.resourceType ?? "",
|
|
176
|
+
resourceId: record.resourceId ?? void 0,
|
|
177
|
+
action: record.action,
|
|
178
|
+
status: readEnum(ActivityStatus, details["status"], "success"),
|
|
179
|
+
workspaceId: record.workspaceId ?? void 0,
|
|
180
|
+
organizationId: readString(details["organizationId"]) ?? readString(custom?.["organizationId"]),
|
|
181
|
+
projectId: record.context?.projectId ?? readString(details["projectId"]),
|
|
182
|
+
productId: record.productId ?? void 0,
|
|
183
|
+
description: record.description ?? void 0,
|
|
184
|
+
targetUserId: record.targetUserId ?? void 0,
|
|
185
|
+
actorType: record.actorType ?? void 0,
|
|
186
|
+
onBehalfOf: record.onBehalfOf ?? void 0,
|
|
187
|
+
ipAddress: readString(details["requestIpAddress"]) ?? record.ipAddress ?? void 0,
|
|
188
|
+
userAgent: readString(details["requestUserAgent"]) ?? record.userAgent ?? void 0,
|
|
189
|
+
metadata,
|
|
190
|
+
severity: readEnum(ActivitySeverity, details["severity"], "low"),
|
|
191
|
+
errorMessage: readString(details["errorMessage"]),
|
|
192
|
+
duration: typeof duration === "number" && Number.isFinite(duration) ? duration : void 0,
|
|
193
|
+
createdAt: record.timestamp
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
__name(toActivity, "toActivity");
|
|
197
|
+
function buildActivityLogFilter(options) {
|
|
198
|
+
if (!options.workspaceId) {
|
|
199
|
+
throw new ValidationError("workspaceId is required to read activities");
|
|
200
|
+
}
|
|
201
|
+
const unsupported = [
|
|
202
|
+
"organizationId",
|
|
203
|
+
"projectId",
|
|
204
|
+
"activityType",
|
|
205
|
+
"status",
|
|
206
|
+
"severity",
|
|
207
|
+
"search"
|
|
208
|
+
].filter((key) => options[key] !== void 0);
|
|
209
|
+
if (options.sortBy !== void 0 && options.sortBy !== "createdAt") unsupported.push("sortBy");
|
|
210
|
+
if (options.sortOrder !== void 0 && options.sortOrder !== "desc") unsupported.push("sortOrder");
|
|
211
|
+
if (unsupported.length > 0) {
|
|
212
|
+
throw new ValidationError(`Activity filters not supported by the workspace activity owner: ${unsupported.join(", ")}`, {
|
|
213
|
+
unsupported
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return compact({
|
|
217
|
+
workspaceId: options.workspaceId,
|
|
218
|
+
userId: options.userId,
|
|
219
|
+
action: options.action,
|
|
220
|
+
resourceType: options.resourceType,
|
|
221
|
+
resourceId: options.resourceId,
|
|
222
|
+
targetUserId: options.targetUserId,
|
|
223
|
+
startDate: options.startDate,
|
|
224
|
+
endDate: options.endDate,
|
|
225
|
+
limit: options.limit ?? 50,
|
|
226
|
+
offset: options.offset ?? 0
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
__name(buildActivityLogFilter, "buildActivityLogFilter");
|
|
42
230
|
var ActivityModule = class {
|
|
43
231
|
static {
|
|
44
232
|
__name(this, "ActivityModule");
|
|
@@ -51,6 +239,10 @@ var ActivityModule = class {
|
|
|
51
239
|
}
|
|
52
240
|
/**
|
|
53
241
|
* Log activity
|
|
242
|
+
*
|
|
243
|
+
* The write is relayed as a platform service acting for `userId`, the same identity
|
|
244
|
+
* transport `trackOperation` uses, so the owner records the end user as the actor and
|
|
245
|
+
* honours `actorType`/`onBehalfOf` from the input.
|
|
54
246
|
*/
|
|
55
247
|
async log(options) {
|
|
56
248
|
if (!options.userId) {
|
|
@@ -74,92 +266,21 @@ var ActivityModule = class {
|
|
|
74
266
|
action: options.action,
|
|
75
267
|
resourceType: options.resourceType
|
|
76
268
|
});
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
resourceType
|
|
84
|
-
resourceId
|
|
85
|
-
action
|
|
86
|
-
status
|
|
87
|
-
workspaceId
|
|
88
|
-
organizationId
|
|
89
|
-
projectId
|
|
90
|
-
ipAddress
|
|
91
|
-
userAgent
|
|
92
|
-
metadata
|
|
93
|
-
severity
|
|
94
|
-
errorMessage
|
|
95
|
-
duration
|
|
96
|
-
createdAt
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
`;
|
|
100
|
-
const legacyLogActivityMutation = `
|
|
101
|
-
mutation LogActivity($input: LogActivityInput!) {
|
|
102
|
-
logActivity(input: $input) {
|
|
103
|
-
id
|
|
104
|
-
userId
|
|
105
|
-
activityType
|
|
106
|
-
resourceType
|
|
107
|
-
resourceId
|
|
108
|
-
action
|
|
109
|
-
status
|
|
110
|
-
workspaceId
|
|
111
|
-
organizationId
|
|
112
|
-
projectId
|
|
113
|
-
ipAddress
|
|
114
|
-
userAgent
|
|
115
|
-
metadata
|
|
116
|
-
severity
|
|
117
|
-
errorMessage
|
|
118
|
-
duration
|
|
119
|
-
createdAt
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
`;
|
|
123
|
-
const variables = {
|
|
124
|
-
input: {
|
|
125
|
-
userId: options.userId,
|
|
126
|
-
activityType: options.activityType,
|
|
127
|
-
resourceType: options.resourceType,
|
|
128
|
-
resourceId: options.resourceId,
|
|
129
|
-
action: options.action,
|
|
130
|
-
status: options.status,
|
|
131
|
-
workspaceId: options.workspaceId,
|
|
132
|
-
organizationId: options.organizationId,
|
|
133
|
-
projectId: options.projectId,
|
|
134
|
-
ipAddress: options.ipAddress,
|
|
135
|
-
userAgent: options.userAgent,
|
|
136
|
-
metadata: options.metadata,
|
|
137
|
-
severity: options.severity || "low",
|
|
138
|
-
errorMessage: options.errorMessage,
|
|
139
|
-
duration: options.duration
|
|
140
|
-
}
|
|
269
|
+
const input = buildRecordActivityInput(options, this.context);
|
|
270
|
+
const requestContext = {
|
|
271
|
+
...this.context,
|
|
272
|
+
actorId: options.userId,
|
|
273
|
+
actorType: "service",
|
|
274
|
+
workspaceId: options.workspaceId ?? this.context.workspaceId
|
|
141
275
|
};
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const isRecordActivityUnavailable = message.includes('Cannot query field "recordActivity"') || message.includes('Unknown type "RecordActivityInput"');
|
|
151
|
-
if (!isRecordActivityUnavailable) {
|
|
152
|
-
throw error;
|
|
153
|
-
}
|
|
154
|
-
logger.warn("[Activity] Falling back to legacy logActivity mutation", {
|
|
155
|
-
reason: message
|
|
156
|
-
});
|
|
157
|
-
const legacyResponse = await this.client.query(legacyLogActivityMutation, variables, this.context);
|
|
158
|
-
logger.info("[Activity] Activity logged (legacy)", {
|
|
159
|
-
activityId: legacyResponse.logActivity.id
|
|
160
|
-
});
|
|
161
|
-
return legacyResponse.logActivity;
|
|
162
|
-
}
|
|
276
|
+
const response = await this.client.query(RECORD_ACTIVITY_MUTATION, {
|
|
277
|
+
input
|
|
278
|
+
}, requestContext);
|
|
279
|
+
const activity = toActivity(response.recordActivity);
|
|
280
|
+
logger.info("[Activity] Activity logged", {
|
|
281
|
+
activityId: activity.id
|
|
282
|
+
});
|
|
283
|
+
return activity;
|
|
163
284
|
}
|
|
164
285
|
/**
|
|
165
286
|
* Log activity with automatic status detection
|
|
@@ -195,207 +316,53 @@ var ActivityModule = class {
|
|
|
195
316
|
});
|
|
196
317
|
}
|
|
197
318
|
/**
|
|
198
|
-
* Get activities
|
|
319
|
+
* Get one workspace's activities, newest first.
|
|
320
|
+
*
|
|
321
|
+
* Reads the owner's workspace-scoped slice (`getWorkspaceActivitySlice`) together with the
|
|
322
|
+
* matching `activityCount`, so `total` counts every row the filter matches, not just the page.
|
|
199
323
|
*/
|
|
200
324
|
async getActivities(options) {
|
|
201
325
|
logger.debug("[Activity] Getting activities", options);
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
$startDate: DateTime
|
|
214
|
-
$endDate: DateTime
|
|
215
|
-
$search: String
|
|
216
|
-
$limit: Int
|
|
217
|
-
$offset: Int
|
|
218
|
-
$sortBy: String
|
|
219
|
-
$sortOrder: String
|
|
220
|
-
) {
|
|
221
|
-
getActivities(
|
|
222
|
-
userId: $userId
|
|
223
|
-
workspaceId: $workspaceId
|
|
224
|
-
organizationId: $organizationId
|
|
225
|
-
projectId: $projectId
|
|
226
|
-
activityType: $activityType
|
|
227
|
-
resourceType: $resourceType
|
|
228
|
-
resourceId: $resourceId
|
|
229
|
-
status: $status
|
|
230
|
-
severity: $severity
|
|
231
|
-
startDate: $startDate
|
|
232
|
-
endDate: $endDate
|
|
233
|
-
search: $search
|
|
234
|
-
limit: $limit
|
|
235
|
-
offset: $offset
|
|
236
|
-
sortBy: $sortBy
|
|
237
|
-
sortOrder: $sortOrder
|
|
238
|
-
) {
|
|
239
|
-
activities {
|
|
240
|
-
id
|
|
241
|
-
userId
|
|
242
|
-
activityType
|
|
243
|
-
resourceType
|
|
244
|
-
resourceId
|
|
245
|
-
action
|
|
246
|
-
status
|
|
247
|
-
workspaceId
|
|
248
|
-
organizationId
|
|
249
|
-
projectId
|
|
250
|
-
ipAddress
|
|
251
|
-
userAgent
|
|
252
|
-
metadata
|
|
253
|
-
severity
|
|
254
|
-
errorMessage
|
|
255
|
-
duration
|
|
256
|
-
createdAt
|
|
257
|
-
}
|
|
258
|
-
total
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
`;
|
|
262
|
-
const variables = {
|
|
263
|
-
userId: options.userId,
|
|
264
|
-
workspaceId: options.workspaceId,
|
|
265
|
-
organizationId: options.organizationId,
|
|
266
|
-
projectId: options.projectId,
|
|
267
|
-
activityType: options.activityType,
|
|
268
|
-
resourceType: options.resourceType,
|
|
269
|
-
resourceId: options.resourceId,
|
|
270
|
-
status: options.status,
|
|
271
|
-
severity: options.severity,
|
|
272
|
-
startDate: options.startDate,
|
|
273
|
-
endDate: options.endDate,
|
|
274
|
-
search: options.search,
|
|
275
|
-
limit: options.limit || 50,
|
|
276
|
-
offset: options.offset || 0,
|
|
277
|
-
sortBy: options.sortBy || "createdAt",
|
|
278
|
-
sortOrder: options.sortOrder || "desc"
|
|
326
|
+
const filter = buildActivityLogFilter(options);
|
|
327
|
+
const requestContext = {
|
|
328
|
+
...this.context,
|
|
329
|
+
workspaceId: options.workspaceId
|
|
330
|
+
};
|
|
331
|
+
const response = await this.client.query(WORKSPACE_ACTIVITY_SLICE_QUERY, {
|
|
332
|
+
filter
|
|
333
|
+
}, requestContext);
|
|
334
|
+
return {
|
|
335
|
+
activities: response.getWorkspaceActivitySlice.map(toActivity),
|
|
336
|
+
total: response.activityCount
|
|
279
337
|
};
|
|
280
|
-
const response = await this.client.query(query, variables, this.context);
|
|
281
|
-
return response.getActivities;
|
|
282
338
|
}
|
|
283
339
|
/**
|
|
284
|
-
*
|
|
340
|
+
* @deprecated The workspace activity owner has no read-by-id operation. Use
|
|
341
|
+
* {@link getActivities} with `resourceId`/`action` filters instead.
|
|
285
342
|
*/
|
|
286
|
-
async getActivity(
|
|
287
|
-
|
|
288
|
-
activityId
|
|
289
|
-
});
|
|
290
|
-
const query = `
|
|
291
|
-
query GetActivity($activityId: ID!) {
|
|
292
|
-
getActivity(activityId: $activityId) {
|
|
293
|
-
id
|
|
294
|
-
userId
|
|
295
|
-
activityType
|
|
296
|
-
resourceType
|
|
297
|
-
resourceId
|
|
298
|
-
action
|
|
299
|
-
status
|
|
300
|
-
workspaceId
|
|
301
|
-
organizationId
|
|
302
|
-
projectId
|
|
303
|
-
ipAddress
|
|
304
|
-
userAgent
|
|
305
|
-
metadata
|
|
306
|
-
severity
|
|
307
|
-
errorMessage
|
|
308
|
-
duration
|
|
309
|
-
createdAt
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
`;
|
|
313
|
-
const response = await this.client.query(query, {
|
|
314
|
-
activityId
|
|
315
|
-
}, this.context);
|
|
316
|
-
return response.getActivity;
|
|
343
|
+
async getActivity(_activityId) {
|
|
344
|
+
throw new ActivityOperationUnsupportedError("getActivity", "use getActivities with a workspace filter");
|
|
317
345
|
}
|
|
318
346
|
/**
|
|
319
|
-
*
|
|
347
|
+
* @deprecated The workspace activity owner has no statistics operation. Use
|
|
348
|
+
* {@link getActivities} (its `total` is the owner's `activityCount`) per filter instead.
|
|
320
349
|
*/
|
|
321
|
-
async getStats(
|
|
322
|
-
|
|
323
|
-
const query = `
|
|
324
|
-
query GetActivityStats(
|
|
325
|
-
$userId: ID
|
|
326
|
-
$workspaceId: ID
|
|
327
|
-
$organizationId: ID
|
|
328
|
-
$projectId: ID
|
|
329
|
-
$activityType: ActivityType
|
|
330
|
-
$resourceType: String
|
|
331
|
-
$startDate: DateTime
|
|
332
|
-
$endDate: DateTime
|
|
333
|
-
) {
|
|
334
|
-
getActivityStats(
|
|
335
|
-
userId: $userId
|
|
336
|
-
workspaceId: $workspaceId
|
|
337
|
-
organizationId: $organizationId
|
|
338
|
-
projectId: $projectId
|
|
339
|
-
activityType: $activityType
|
|
340
|
-
resourceType: $resourceType
|
|
341
|
-
startDate: $startDate
|
|
342
|
-
endDate: $endDate
|
|
343
|
-
) {
|
|
344
|
-
totalActivities
|
|
345
|
-
successCount
|
|
346
|
-
failureCount
|
|
347
|
-
pendingCount
|
|
348
|
-
warningCount
|
|
349
|
-
averageDuration
|
|
350
|
-
activitiesByType
|
|
351
|
-
activitiesBySeverity
|
|
352
|
-
topUsers {
|
|
353
|
-
userId
|
|
354
|
-
count
|
|
355
|
-
}
|
|
356
|
-
topResources {
|
|
357
|
-
resourceType
|
|
358
|
-
count
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
`;
|
|
363
|
-
const variables = {
|
|
364
|
-
userId: options.userId,
|
|
365
|
-
workspaceId: options.workspaceId,
|
|
366
|
-
organizationId: options.organizationId,
|
|
367
|
-
projectId: options.projectId,
|
|
368
|
-
activityType: options.activityType,
|
|
369
|
-
resourceType: options.resourceType,
|
|
370
|
-
startDate: options.startDate,
|
|
371
|
-
endDate: options.endDate
|
|
372
|
-
};
|
|
373
|
-
const response = await this.client.query(query, variables, this.context);
|
|
374
|
-
return response.getActivityStats;
|
|
350
|
+
async getStats(_options) {
|
|
351
|
+
throw new ActivityOperationUnsupportedError("getStats", "use getActivities and its total per filter");
|
|
375
352
|
}
|
|
376
353
|
/**
|
|
377
|
-
*
|
|
354
|
+
* @deprecated Retention is enforced by the activity owner's retention policy and legal holds;
|
|
355
|
+
* there is no client-driven cleanup operation.
|
|
378
356
|
*/
|
|
379
|
-
async cleanup(
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
`;
|
|
391
|
-
const response = await this.client.query(mutation, {
|
|
392
|
-
olderThanDays,
|
|
393
|
-
workspaceId
|
|
394
|
-
}, this.context);
|
|
395
|
-
logger.info("[Activity] Cleanup completed", {
|
|
396
|
-
deletedCount: response.cleanupActivities.deletedCount
|
|
397
|
-
});
|
|
398
|
-
return response.cleanupActivities.deletedCount;
|
|
357
|
+
async cleanup(_olderThanDays, _workspaceId) {
|
|
358
|
+
throw new ActivityOperationUnsupportedError("cleanup", "retention is enforced by the activity owner");
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* @deprecated The workspace activity owner exports through `exportActivityLogsSiem`
|
|
362
|
+
* (CEF/LEEF/JSON lines); there is no CSV export operation.
|
|
363
|
+
*/
|
|
364
|
+
async exportToCSV(_options) {
|
|
365
|
+
throw new ActivityOperationUnsupportedError("exportToCSV", "use the owner exportActivityLogsSiem query");
|
|
399
366
|
}
|
|
400
367
|
/**
|
|
401
368
|
* Infer activity type from action string
|
|
@@ -446,40 +413,6 @@ var ActivityModule = class {
|
|
|
446
413
|
}
|
|
447
414
|
return "custom";
|
|
448
415
|
}
|
|
449
|
-
/**
|
|
450
|
-
* Export activities to CSV
|
|
451
|
-
*/
|
|
452
|
-
async exportToCSV(options) {
|
|
453
|
-
logger.debug("[Activity] Exporting activities to CSV");
|
|
454
|
-
const query = `
|
|
455
|
-
query ExportActivities(
|
|
456
|
-
$userId: ID
|
|
457
|
-
$workspaceId: ID
|
|
458
|
-
$organizationId: ID
|
|
459
|
-
$startDate: DateTime
|
|
460
|
-
$endDate: DateTime
|
|
461
|
-
) {
|
|
462
|
-
exportActivities(
|
|
463
|
-
userId: $userId
|
|
464
|
-
workspaceId: $workspaceId
|
|
465
|
-
organizationId: $organizationId
|
|
466
|
-
startDate: $startDate
|
|
467
|
-
endDate: $endDate
|
|
468
|
-
) {
|
|
469
|
-
csvData
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
`;
|
|
473
|
-
const response = await this.client.query(query, {
|
|
474
|
-
userId: options.userId,
|
|
475
|
-
workspaceId: options.workspaceId,
|
|
476
|
-
organizationId: options.organizationId,
|
|
477
|
-
startDate: options.startDate,
|
|
478
|
-
endDate: options.endDate
|
|
479
|
-
}, this.context);
|
|
480
|
-
logger.info("[Activity] Activities exported to CSV");
|
|
481
|
-
return response.exportActivities.csvData;
|
|
482
|
-
}
|
|
483
416
|
};
|
|
484
417
|
|
|
485
418
|
// src/tracker/agent-activity.ts
|
|
@@ -576,16 +509,18 @@ var TrackerModule = class {
|
|
|
576
509
|
} else {
|
|
577
510
|
result.permissionGranted = true;
|
|
578
511
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
await this.
|
|
584
|
-
|
|
512
|
+
const usage = this.resolveUsage(options);
|
|
513
|
+
if (usage) {
|
|
514
|
+
let quotaAssignmentId;
|
|
515
|
+
if (usage.checkQuota) {
|
|
516
|
+
quotaAssignmentId = await this.checkQuota(options, usage, result);
|
|
517
|
+
if (result.quotaAvailable === false) {
|
|
518
|
+
result.duration = Date.now() - startTime;
|
|
519
|
+
await this.logFailedActivity(options, result, startTime);
|
|
520
|
+
return result;
|
|
521
|
+
}
|
|
585
522
|
}
|
|
586
|
-
|
|
587
|
-
if (options.usage?.enabled !== false && options.usage?.metricType) {
|
|
588
|
-
await this.trackUsage(options, result);
|
|
523
|
+
await this.trackUsage(options, usage, quotaAssignmentId, result);
|
|
589
524
|
}
|
|
590
525
|
if (options.activity?.enabled !== false) {
|
|
591
526
|
await this.logSuccessActivity(options, result, startTime);
|
|
@@ -662,23 +597,18 @@ var TrackerModule = class {
|
|
|
662
597
|
return result;
|
|
663
598
|
}
|
|
664
599
|
/**
|
|
665
|
-
* Simplified track method for common operations
|
|
600
|
+
* Simplified track method for common operations.
|
|
601
|
+
* The trailing metric type is accepted for source compatibility and is not metered.
|
|
666
602
|
*/
|
|
667
|
-
async trackSimple(userId, action, resourceType, resourceId,
|
|
603
|
+
async trackSimple(userId, action, resourceType, resourceId, _metricType) {
|
|
668
604
|
const result = await this.track({
|
|
669
605
|
userId,
|
|
670
606
|
action,
|
|
671
607
|
resourceType,
|
|
672
608
|
resourceId,
|
|
673
609
|
workspaceId: this.context.workspaceId,
|
|
674
|
-
usage:
|
|
675
|
-
enabled:
|
|
676
|
-
metricType,
|
|
677
|
-
amount: 1,
|
|
678
|
-
checkQuota: true
|
|
679
|
-
} : {
|
|
680
|
-
enabled: false,
|
|
681
|
-
metricType: "api_calls"
|
|
610
|
+
usage: {
|
|
611
|
+
enabled: false
|
|
682
612
|
}
|
|
683
613
|
});
|
|
684
614
|
return result.success;
|
|
@@ -719,70 +649,88 @@ var TrackerModule = class {
|
|
|
719
649
|
}
|
|
720
650
|
}
|
|
721
651
|
/**
|
|
722
|
-
*
|
|
652
|
+
* Resolve the usage step for an operation, or null when nothing is metered: usage is
|
|
653
|
+
* disabled, or no workspace quota is named (a legacy `metricType` alone has no owner
|
|
654
|
+
* quota to charge).
|
|
723
655
|
*/
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
if (
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
656
|
+
resolveUsage(options) {
|
|
657
|
+
const usage = options.usage;
|
|
658
|
+
if (!usage || usage.enabled === false) {
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
const quotaName = usage.quotaName?.trim();
|
|
662
|
+
if (!quotaName) {
|
|
663
|
+
if (usage.metricType) {
|
|
664
|
+
logger.debug("[Tracker] Usage step skipped: no quotaName for legacy metricType", {
|
|
665
|
+
action: options.action,
|
|
666
|
+
metricType: usage.metricType
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
return null;
|
|
670
|
+
}
|
|
671
|
+
const amount = usage.amount ?? 1;
|
|
672
|
+
if (typeof amount !== "number" || !Number.isFinite(amount) || amount === 0) {
|
|
673
|
+
throw new ValidationError("Usage amount must be a finite, non-zero number");
|
|
674
|
+
}
|
|
675
|
+
const workspaceId = options.workspaceId ?? this.context.workspaceId;
|
|
676
|
+
if (!workspaceId) {
|
|
677
|
+
throw new ValidationError("Workspace ID is required to track workspace quota usage");
|
|
678
|
+
}
|
|
679
|
+
return {
|
|
680
|
+
quotaName,
|
|
681
|
+
amount,
|
|
682
|
+
workspaceId,
|
|
683
|
+
// Only consumption is gated; a release (negative amount) must always go through.
|
|
684
|
+
checkQuota: usage.checkQuota !== false && amount > 0
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Check workspace quota capacity. Returns the assignment to charge when one exists.
|
|
689
|
+
*/
|
|
690
|
+
async checkQuota(options, usage, result) {
|
|
691
|
+
const quotaCheck = await this.usage.checkWorkspaceQuota({
|
|
692
|
+
quotaName: usage.quotaName,
|
|
693
|
+
amount: usage.amount,
|
|
694
|
+
workspaceId: usage.workspaceId,
|
|
695
|
+
userId: options.userId
|
|
744
696
|
});
|
|
745
697
|
result.quotaAvailable = quotaCheck.allowed;
|
|
746
|
-
result.quotaRemaining = quotaCheck.
|
|
698
|
+
result.quotaRemaining = quotaCheck.limitLeft ?? void 0;
|
|
747
699
|
if (!quotaCheck.allowed) {
|
|
700
|
+
const notProvisioned = quotaCheck.assignmentId === null;
|
|
748
701
|
result.error = {
|
|
749
702
|
type: "quota",
|
|
750
|
-
message:
|
|
703
|
+
message: notProvisioned ? `Quota ${usage.quotaName} is not included in this workspace's plan` : "Quota exceeded",
|
|
751
704
|
details: {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
705
|
+
quotaName: usage.quotaName,
|
|
706
|
+
requestedAmount: usage.amount,
|
|
707
|
+
limitLeft: quotaCheck.limitLeft,
|
|
708
|
+
notProvisioned
|
|
755
709
|
}
|
|
756
710
|
};
|
|
757
711
|
}
|
|
712
|
+
return quotaCheck.assignmentId ?? void 0;
|
|
758
713
|
}
|
|
759
714
|
/**
|
|
760
|
-
*
|
|
715
|
+
* Record workspace quota usage with the owner.
|
|
761
716
|
*/
|
|
762
|
-
async trackUsage(options, result) {
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
amount: options.usage.amount || 1,
|
|
780
|
-
resourceId: options.resourceId,
|
|
781
|
-
workspaceId: options.workspaceId,
|
|
782
|
-
organizationId: options.organizationId
|
|
783
|
-
};
|
|
784
|
-
const usageRecord = await this.usage.track(trackOptions);
|
|
785
|
-
result.usageRecordId = usageRecord.id;
|
|
717
|
+
async trackUsage(options, usage, quotaAssignmentId, result) {
|
|
718
|
+
result.usageTracked = await this.usage.trackUsage({
|
|
719
|
+
quotaName: usage.quotaName,
|
|
720
|
+
productId: options.usage?.productId,
|
|
721
|
+
amount: usage.amount,
|
|
722
|
+
description: options.usage?.description?.trim() || `${options.action} ${options.resourceType}`,
|
|
723
|
+
workspaceId: usage.workspaceId,
|
|
724
|
+
userId: options.userId,
|
|
725
|
+
quotaAssignmentId,
|
|
726
|
+
metadata: {
|
|
727
|
+
action: options.action,
|
|
728
|
+
resourceType: options.resourceType,
|
|
729
|
+
...options.resourceId ? {
|
|
730
|
+
resourceId: options.resourceId
|
|
731
|
+
} : {}
|
|
732
|
+
}
|
|
733
|
+
});
|
|
786
734
|
}
|
|
787
735
|
/**
|
|
788
736
|
* Log successful activity
|
|
@@ -923,6 +871,6 @@ var TrackerModule = class {
|
|
|
923
871
|
}
|
|
924
872
|
};
|
|
925
873
|
|
|
926
|
-
export { AGENT_ACTIVITY_ACTIONS, AGENT_ACTIVITY_RESOURCE_TYPE, ActivityModule, TrackerModule, trackAgentActivity };
|
|
927
|
-
//# sourceMappingURL=chunk-
|
|
928
|
-
//# sourceMappingURL=chunk-
|
|
874
|
+
export { AGENT_ACTIVITY_ACTIONS, AGENT_ACTIVITY_RESOURCE_TYPE, ActivityModule, ActivityOperationUnsupportedError, TrackerModule, trackAgentActivity };
|
|
875
|
+
//# sourceMappingURL=chunk-2T3N5SNW.js.map
|
|
876
|
+
//# sourceMappingURL=chunk-2T3N5SNW.js.map
|