argus-discord-analytics 0.1.1 → 0.2.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/index.d.mts +13 -3
- package/dist/index.d.ts +13 -3
- package/dist/index.js +50 -7
- package/dist/index.mjs +48 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* argus.trackRevenue({ source: 'patreon', amount: 500, tier: 'Premium' });
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
+
declare const SDK_VERSION = "0.2.0";
|
|
24
25
|
interface ArgusConfig {
|
|
25
26
|
/** Your Argus API key (starts with arg_live_ or arg_test_) */
|
|
26
27
|
apiKey: string;
|
|
@@ -93,7 +94,7 @@ declare class Argus {
|
|
|
93
94
|
private startFlushTimer;
|
|
94
95
|
/**
|
|
95
96
|
* Track a Discord.js interaction automatically
|
|
96
|
-
* Extracts command name, server ID, and user ID from the interaction
|
|
97
|
+
* Extracts command name (including subcommands), server ID, and user ID from the interaction
|
|
97
98
|
*/
|
|
98
99
|
track(interaction: {
|
|
99
100
|
commandName?: string;
|
|
@@ -103,6 +104,7 @@ declare class Argus {
|
|
|
103
104
|
id: string;
|
|
104
105
|
};
|
|
105
106
|
type?: number;
|
|
107
|
+
options?: unknown;
|
|
106
108
|
}): void;
|
|
107
109
|
/**
|
|
108
110
|
* Track a custom event
|
|
@@ -114,16 +116,22 @@ declare class Argus {
|
|
|
114
116
|
}): void;
|
|
115
117
|
/**
|
|
116
118
|
* Track a command (convenience method)
|
|
119
|
+
* Accepts either a command name string or a Discord.js interaction object
|
|
117
120
|
*
|
|
118
121
|
* @example
|
|
119
122
|
* ```typescript
|
|
123
|
+
* // Option 1: Pass the interaction directly (recommended)
|
|
124
|
+
* // Automatically extracts subcommands: /show profile -> "show profile"
|
|
125
|
+
* argus.trackCommand(interaction);
|
|
126
|
+
*
|
|
127
|
+
* // Option 2: Pass command name as string
|
|
120
128
|
* argus.trackCommand('ban', {
|
|
121
129
|
* serverId: interaction.guildId,
|
|
122
130
|
* userId: interaction.user.id
|
|
123
131
|
* });
|
|
124
132
|
* ```
|
|
125
133
|
*/
|
|
126
|
-
trackCommand(
|
|
134
|
+
trackCommand(commandOrInteraction: string | Record<string, unknown>, options?: {
|
|
127
135
|
serverId?: string;
|
|
128
136
|
userId?: string;
|
|
129
137
|
metadata?: Record<string, unknown>;
|
|
@@ -240,6 +248,7 @@ declare class Argus {
|
|
|
240
248
|
startTimer(id: string): string;
|
|
241
249
|
/**
|
|
242
250
|
* End timing and track the command with latency
|
|
251
|
+
* Automatically extracts subcommands from the interaction
|
|
243
252
|
*/
|
|
244
253
|
endTimer(timerId: string, interaction: {
|
|
245
254
|
commandName?: string;
|
|
@@ -249,6 +258,7 @@ declare class Argus {
|
|
|
249
258
|
id: string;
|
|
250
259
|
};
|
|
251
260
|
type?: number;
|
|
261
|
+
options?: unknown;
|
|
252
262
|
}): void;
|
|
253
263
|
/**
|
|
254
264
|
* Track an event with latency measurement
|
|
@@ -264,4 +274,4 @@ declare class Argus {
|
|
|
264
274
|
shutdown(): Promise<void>;
|
|
265
275
|
}
|
|
266
276
|
|
|
267
|
-
export { Argus, type ArgusConfig, type HeartbeatConfig, type RevenueEvent, type ServerEvent, type TrackEvent, Argus as default };
|
|
277
|
+
export { Argus, type ArgusConfig, type HeartbeatConfig, type RevenueEvent, SDK_VERSION, type ServerEvent, type TrackEvent, Argus as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* argus.trackRevenue({ source: 'patreon', amount: 500, tier: 'Premium' });
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
+
declare const SDK_VERSION = "0.2.0";
|
|
24
25
|
interface ArgusConfig {
|
|
25
26
|
/** Your Argus API key (starts with arg_live_ or arg_test_) */
|
|
26
27
|
apiKey: string;
|
|
@@ -93,7 +94,7 @@ declare class Argus {
|
|
|
93
94
|
private startFlushTimer;
|
|
94
95
|
/**
|
|
95
96
|
* Track a Discord.js interaction automatically
|
|
96
|
-
* Extracts command name, server ID, and user ID from the interaction
|
|
97
|
+
* Extracts command name (including subcommands), server ID, and user ID from the interaction
|
|
97
98
|
*/
|
|
98
99
|
track(interaction: {
|
|
99
100
|
commandName?: string;
|
|
@@ -103,6 +104,7 @@ declare class Argus {
|
|
|
103
104
|
id: string;
|
|
104
105
|
};
|
|
105
106
|
type?: number;
|
|
107
|
+
options?: unknown;
|
|
106
108
|
}): void;
|
|
107
109
|
/**
|
|
108
110
|
* Track a custom event
|
|
@@ -114,16 +116,22 @@ declare class Argus {
|
|
|
114
116
|
}): void;
|
|
115
117
|
/**
|
|
116
118
|
* Track a command (convenience method)
|
|
119
|
+
* Accepts either a command name string or a Discord.js interaction object
|
|
117
120
|
*
|
|
118
121
|
* @example
|
|
119
122
|
* ```typescript
|
|
123
|
+
* // Option 1: Pass the interaction directly (recommended)
|
|
124
|
+
* // Automatically extracts subcommands: /show profile -> "show profile"
|
|
125
|
+
* argus.trackCommand(interaction);
|
|
126
|
+
*
|
|
127
|
+
* // Option 2: Pass command name as string
|
|
120
128
|
* argus.trackCommand('ban', {
|
|
121
129
|
* serverId: interaction.guildId,
|
|
122
130
|
* userId: interaction.user.id
|
|
123
131
|
* });
|
|
124
132
|
* ```
|
|
125
133
|
*/
|
|
126
|
-
trackCommand(
|
|
134
|
+
trackCommand(commandOrInteraction: string | Record<string, unknown>, options?: {
|
|
127
135
|
serverId?: string;
|
|
128
136
|
userId?: string;
|
|
129
137
|
metadata?: Record<string, unknown>;
|
|
@@ -240,6 +248,7 @@ declare class Argus {
|
|
|
240
248
|
startTimer(id: string): string;
|
|
241
249
|
/**
|
|
242
250
|
* End timing and track the command with latency
|
|
251
|
+
* Automatically extracts subcommands from the interaction
|
|
243
252
|
*/
|
|
244
253
|
endTimer(timerId: string, interaction: {
|
|
245
254
|
commandName?: string;
|
|
@@ -249,6 +258,7 @@ declare class Argus {
|
|
|
249
258
|
id: string;
|
|
250
259
|
};
|
|
251
260
|
type?: number;
|
|
261
|
+
options?: unknown;
|
|
252
262
|
}): void;
|
|
253
263
|
/**
|
|
254
264
|
* Track an event with latency measurement
|
|
@@ -264,4 +274,4 @@ declare class Argus {
|
|
|
264
274
|
shutdown(): Promise<void>;
|
|
265
275
|
}
|
|
266
276
|
|
|
267
|
-
export { Argus, type ArgusConfig, type HeartbeatConfig, type RevenueEvent, type ServerEvent, type TrackEvent, Argus as default };
|
|
277
|
+
export { Argus, type ArgusConfig, type HeartbeatConfig, type RevenueEvent, SDK_VERSION, type ServerEvent, type TrackEvent, Argus as default };
|
package/dist/index.js
CHANGED
|
@@ -21,9 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
Argus: () => Argus,
|
|
24
|
+
SDK_VERSION: () => SDK_VERSION,
|
|
24
25
|
default: () => index_default
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var SDK_VERSION = "0.2.0";
|
|
27
29
|
function hashString(str) {
|
|
28
30
|
let hash = 0;
|
|
29
31
|
for (let i = 0; i < str.length; i++) {
|
|
@@ -33,6 +35,25 @@ function hashString(str) {
|
|
|
33
35
|
}
|
|
34
36
|
return Math.abs(hash).toString(36);
|
|
35
37
|
}
|
|
38
|
+
function extractFullCommandName(interaction) {
|
|
39
|
+
let command = interaction.commandName || interaction.customId || "unknown";
|
|
40
|
+
const options = interaction.options;
|
|
41
|
+
if (options && typeof options.getSubcommandGroup === "function") {
|
|
42
|
+
try {
|
|
43
|
+
const group = options.getSubcommandGroup(false);
|
|
44
|
+
if (group) command += ` ${group}`;
|
|
45
|
+
} catch {
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (options && typeof options.getSubcommand === "function") {
|
|
49
|
+
try {
|
|
50
|
+
const sub = options.getSubcommand(false);
|
|
51
|
+
if (sub) command += ` ${sub}`;
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return command;
|
|
56
|
+
}
|
|
36
57
|
var Argus = class {
|
|
37
58
|
constructor(apiKeyOrConfig) {
|
|
38
59
|
this.queue = [];
|
|
@@ -73,10 +94,10 @@ var Argus = class {
|
|
|
73
94
|
}
|
|
74
95
|
/**
|
|
75
96
|
* Track a Discord.js interaction automatically
|
|
76
|
-
* Extracts command name, server ID, and user ID from the interaction
|
|
97
|
+
* Extracts command name (including subcommands), server ID, and user ID from the interaction
|
|
77
98
|
*/
|
|
78
99
|
track(interaction) {
|
|
79
|
-
const name = interaction
|
|
100
|
+
const name = extractFullCommandName(interaction);
|
|
80
101
|
const serverId = interaction.guildId || void 0;
|
|
81
102
|
const userId = interaction.user?.id;
|
|
82
103
|
this.trackEvent("command", name, {
|
|
@@ -111,17 +132,37 @@ var Argus = class {
|
|
|
111
132
|
}
|
|
112
133
|
/**
|
|
113
134
|
* Track a command (convenience method)
|
|
135
|
+
* Accepts either a command name string or a Discord.js interaction object
|
|
114
136
|
*
|
|
115
137
|
* @example
|
|
116
138
|
* ```typescript
|
|
139
|
+
* // Option 1: Pass the interaction directly (recommended)
|
|
140
|
+
* // Automatically extracts subcommands: /show profile -> "show profile"
|
|
141
|
+
* argus.trackCommand(interaction);
|
|
142
|
+
*
|
|
143
|
+
* // Option 2: Pass command name as string
|
|
117
144
|
* argus.trackCommand('ban', {
|
|
118
145
|
* serverId: interaction.guildId,
|
|
119
146
|
* userId: interaction.user.id
|
|
120
147
|
* });
|
|
121
148
|
* ```
|
|
122
149
|
*/
|
|
123
|
-
trackCommand(
|
|
124
|
-
|
|
150
|
+
trackCommand(commandOrInteraction, options) {
|
|
151
|
+
let commandName;
|
|
152
|
+
let extractedOptions = options;
|
|
153
|
+
if (typeof commandOrInteraction === "string") {
|
|
154
|
+
commandName = commandOrInteraction;
|
|
155
|
+
} else {
|
|
156
|
+
commandName = extractFullCommandName(commandOrInteraction);
|
|
157
|
+
if (!extractedOptions) {
|
|
158
|
+
const interaction = commandOrInteraction;
|
|
159
|
+
extractedOptions = {
|
|
160
|
+
serverId: interaction.guildId || void 0,
|
|
161
|
+
userId: interaction.user?.id
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
this.trackEvent("command", commandName, extractedOptions);
|
|
125
166
|
}
|
|
126
167
|
/**
|
|
127
168
|
* Track an error
|
|
@@ -233,7 +274,7 @@ var Argus = class {
|
|
|
233
274
|
"Content-Type": "application/json",
|
|
234
275
|
"Authorization": `Bearer ${this.apiKey}`
|
|
235
276
|
},
|
|
236
|
-
body: JSON.stringify({ events })
|
|
277
|
+
body: JSON.stringify({ events, sdkVersion: SDK_VERSION })
|
|
237
278
|
});
|
|
238
279
|
if (!response.ok) {
|
|
239
280
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
@@ -391,6 +432,7 @@ var Argus = class {
|
|
|
391
432
|
}
|
|
392
433
|
/**
|
|
393
434
|
* End timing and track the command with latency
|
|
435
|
+
* Automatically extracts subcommands from the interaction
|
|
394
436
|
*/
|
|
395
437
|
endTimer(timerId, interaction) {
|
|
396
438
|
const startTime = this.commandStartTimes.get(timerId);
|
|
@@ -401,7 +443,7 @@ var Argus = class {
|
|
|
401
443
|
}
|
|
402
444
|
const latencyMs = Date.now() - startTime;
|
|
403
445
|
this.commandStartTimes.delete(timerId);
|
|
404
|
-
const name = interaction
|
|
446
|
+
const name = extractFullCommandName(interaction);
|
|
405
447
|
const serverId = interaction.guildId || void 0;
|
|
406
448
|
const userId = interaction.user?.id;
|
|
407
449
|
this.trackEventWithLatency("command", name, latencyMs, {
|
|
@@ -454,5 +496,6 @@ var Argus = class {
|
|
|
454
496
|
var index_default = Argus;
|
|
455
497
|
// Annotate the CommonJS export names for ESM import in node:
|
|
456
498
|
0 && (module.exports = {
|
|
457
|
-
Argus
|
|
499
|
+
Argus,
|
|
500
|
+
SDK_VERSION
|
|
458
501
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
var SDK_VERSION = "0.2.0";
|
|
2
3
|
function hashString(str) {
|
|
3
4
|
let hash = 0;
|
|
4
5
|
for (let i = 0; i < str.length; i++) {
|
|
@@ -8,6 +9,25 @@ function hashString(str) {
|
|
|
8
9
|
}
|
|
9
10
|
return Math.abs(hash).toString(36);
|
|
10
11
|
}
|
|
12
|
+
function extractFullCommandName(interaction) {
|
|
13
|
+
let command = interaction.commandName || interaction.customId || "unknown";
|
|
14
|
+
const options = interaction.options;
|
|
15
|
+
if (options && typeof options.getSubcommandGroup === "function") {
|
|
16
|
+
try {
|
|
17
|
+
const group = options.getSubcommandGroup(false);
|
|
18
|
+
if (group) command += ` ${group}`;
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (options && typeof options.getSubcommand === "function") {
|
|
23
|
+
try {
|
|
24
|
+
const sub = options.getSubcommand(false);
|
|
25
|
+
if (sub) command += ` ${sub}`;
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return command;
|
|
30
|
+
}
|
|
11
31
|
var Argus = class {
|
|
12
32
|
constructor(apiKeyOrConfig) {
|
|
13
33
|
this.queue = [];
|
|
@@ -48,10 +68,10 @@ var Argus = class {
|
|
|
48
68
|
}
|
|
49
69
|
/**
|
|
50
70
|
* Track a Discord.js interaction automatically
|
|
51
|
-
* Extracts command name, server ID, and user ID from the interaction
|
|
71
|
+
* Extracts command name (including subcommands), server ID, and user ID from the interaction
|
|
52
72
|
*/
|
|
53
73
|
track(interaction) {
|
|
54
|
-
const name = interaction
|
|
74
|
+
const name = extractFullCommandName(interaction);
|
|
55
75
|
const serverId = interaction.guildId || void 0;
|
|
56
76
|
const userId = interaction.user?.id;
|
|
57
77
|
this.trackEvent("command", name, {
|
|
@@ -86,17 +106,37 @@ var Argus = class {
|
|
|
86
106
|
}
|
|
87
107
|
/**
|
|
88
108
|
* Track a command (convenience method)
|
|
109
|
+
* Accepts either a command name string or a Discord.js interaction object
|
|
89
110
|
*
|
|
90
111
|
* @example
|
|
91
112
|
* ```typescript
|
|
113
|
+
* // Option 1: Pass the interaction directly (recommended)
|
|
114
|
+
* // Automatically extracts subcommands: /show profile -> "show profile"
|
|
115
|
+
* argus.trackCommand(interaction);
|
|
116
|
+
*
|
|
117
|
+
* // Option 2: Pass command name as string
|
|
92
118
|
* argus.trackCommand('ban', {
|
|
93
119
|
* serverId: interaction.guildId,
|
|
94
120
|
* userId: interaction.user.id
|
|
95
121
|
* });
|
|
96
122
|
* ```
|
|
97
123
|
*/
|
|
98
|
-
trackCommand(
|
|
99
|
-
|
|
124
|
+
trackCommand(commandOrInteraction, options) {
|
|
125
|
+
let commandName;
|
|
126
|
+
let extractedOptions = options;
|
|
127
|
+
if (typeof commandOrInteraction === "string") {
|
|
128
|
+
commandName = commandOrInteraction;
|
|
129
|
+
} else {
|
|
130
|
+
commandName = extractFullCommandName(commandOrInteraction);
|
|
131
|
+
if (!extractedOptions) {
|
|
132
|
+
const interaction = commandOrInteraction;
|
|
133
|
+
extractedOptions = {
|
|
134
|
+
serverId: interaction.guildId || void 0,
|
|
135
|
+
userId: interaction.user?.id
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
this.trackEvent("command", commandName, extractedOptions);
|
|
100
140
|
}
|
|
101
141
|
/**
|
|
102
142
|
* Track an error
|
|
@@ -208,7 +248,7 @@ var Argus = class {
|
|
|
208
248
|
"Content-Type": "application/json",
|
|
209
249
|
"Authorization": `Bearer ${this.apiKey}`
|
|
210
250
|
},
|
|
211
|
-
body: JSON.stringify({ events })
|
|
251
|
+
body: JSON.stringify({ events, sdkVersion: SDK_VERSION })
|
|
212
252
|
});
|
|
213
253
|
if (!response.ok) {
|
|
214
254
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
@@ -366,6 +406,7 @@ var Argus = class {
|
|
|
366
406
|
}
|
|
367
407
|
/**
|
|
368
408
|
* End timing and track the command with latency
|
|
409
|
+
* Automatically extracts subcommands from the interaction
|
|
369
410
|
*/
|
|
370
411
|
endTimer(timerId, interaction) {
|
|
371
412
|
const startTime = this.commandStartTimes.get(timerId);
|
|
@@ -376,7 +417,7 @@ var Argus = class {
|
|
|
376
417
|
}
|
|
377
418
|
const latencyMs = Date.now() - startTime;
|
|
378
419
|
this.commandStartTimes.delete(timerId);
|
|
379
|
-
const name = interaction
|
|
420
|
+
const name = extractFullCommandName(interaction);
|
|
380
421
|
const serverId = interaction.guildId || void 0;
|
|
381
422
|
const userId = interaction.user?.id;
|
|
382
423
|
this.trackEventWithLatency("command", name, latencyMs, {
|
|
@@ -429,5 +470,6 @@ var Argus = class {
|
|
|
429
470
|
var index_default = Argus;
|
|
430
471
|
export {
|
|
431
472
|
Argus,
|
|
473
|
+
SDK_VERSION,
|
|
432
474
|
index_default as default
|
|
433
475
|
};
|
package/package.json
CHANGED