@noctaly/sdk 1.0.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/LICENSE +21 -0
- package/README.md +401 -0
- package/dist/index.cjs +370 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +784 -0
- package/dist/index.d.ts +784 -0
- package/dist/index.js +361 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal config object threaded through every resource. Not part of the public API.
|
|
3
|
+
*/
|
|
4
|
+
interface ClientConfig {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
baseURL: string;
|
|
7
|
+
/**
|
|
8
|
+
* Maximum number of automatic retries before throwing. @default 3
|
|
9
|
+
*/
|
|
10
|
+
maxRetries: number;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to automatically retry on `rate_limited` (429) responses. @default true
|
|
13
|
+
*/
|
|
14
|
+
retry: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Request timeout in milliseconds. `0` disables the timeout. @default 30_000
|
|
17
|
+
*/
|
|
18
|
+
timeout: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* An item defined in a guild's economy shop.
|
|
23
|
+
*/
|
|
24
|
+
interface Item {
|
|
25
|
+
/**
|
|
26
|
+
* Buy price in the shop.
|
|
27
|
+
*/
|
|
28
|
+
buyPrice: number;
|
|
29
|
+
/**
|
|
30
|
+
* Cooldown between uses, in seconds (`0` = no cooldown).
|
|
31
|
+
*/
|
|
32
|
+
cooldown: number;
|
|
33
|
+
/**
|
|
34
|
+
* Optional description.
|
|
35
|
+
*/
|
|
36
|
+
description: string | null;
|
|
37
|
+
/**
|
|
38
|
+
* Full durability per item (`0` = no durability), or `null`.
|
|
39
|
+
*/
|
|
40
|
+
durability: number | null;
|
|
41
|
+
/**
|
|
42
|
+
* Emoji string, or `null`.
|
|
43
|
+
*/
|
|
44
|
+
emoji: string | null;
|
|
45
|
+
/**
|
|
46
|
+
* `"UNICODE"`, `"CUSTOM"`, or `null`.
|
|
47
|
+
*/
|
|
48
|
+
emojiType: "CUSTOM" | "UNICODE" | null;
|
|
49
|
+
/**
|
|
50
|
+
* Item flags (e.g. `["KEEP_AFTER_USE"]`).
|
|
51
|
+
*/
|
|
52
|
+
flags: string[];
|
|
53
|
+
/**
|
|
54
|
+
* URL to a custom icon, or `null`.
|
|
55
|
+
*/
|
|
56
|
+
iconURL: string | null;
|
|
57
|
+
/**
|
|
58
|
+
* UUID of the item.
|
|
59
|
+
*/
|
|
60
|
+
id: string;
|
|
61
|
+
/**
|
|
62
|
+
* Display name.
|
|
63
|
+
*/
|
|
64
|
+
name: string;
|
|
65
|
+
/**
|
|
66
|
+
* Current quantity in the shop, or `null` for unlimited.
|
|
67
|
+
*/
|
|
68
|
+
quantity: number | null;
|
|
69
|
+
/**
|
|
70
|
+
* Per-member quantity limit, or `null` for unlimited.
|
|
71
|
+
*/
|
|
72
|
+
quantityLimit: number | null;
|
|
73
|
+
/**
|
|
74
|
+
* Sell price.
|
|
75
|
+
*/
|
|
76
|
+
sellPrice: number;
|
|
77
|
+
/**
|
|
78
|
+
* Item type (e.g. `"CUSTOM"`).
|
|
79
|
+
*/
|
|
80
|
+
type: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A chest defined in a guild's economy shop.
|
|
84
|
+
*/
|
|
85
|
+
interface Chest {
|
|
86
|
+
/**
|
|
87
|
+
* Buy price.
|
|
88
|
+
*/
|
|
89
|
+
buyPrice: number;
|
|
90
|
+
/**
|
|
91
|
+
* Chest flags (e.g. `["ANIMATED"]`).
|
|
92
|
+
*/
|
|
93
|
+
flags: string[];
|
|
94
|
+
/**
|
|
95
|
+
* URL to a custom icon, or `null`.
|
|
96
|
+
*/
|
|
97
|
+
iconURL: string | null;
|
|
98
|
+
/**
|
|
99
|
+
* UUID of the chest.
|
|
100
|
+
*/
|
|
101
|
+
id: string;
|
|
102
|
+
/**
|
|
103
|
+
* Number of items drawn when opened.
|
|
104
|
+
*/
|
|
105
|
+
itemDrawCount: number;
|
|
106
|
+
/**
|
|
107
|
+
* Display name.
|
|
108
|
+
*/
|
|
109
|
+
name: string;
|
|
110
|
+
/**
|
|
111
|
+
* Primary hex colour (without `#`).
|
|
112
|
+
*/
|
|
113
|
+
primaryColor: string;
|
|
114
|
+
/**
|
|
115
|
+
* Current quantity in the shop, or `null` for unlimited.
|
|
116
|
+
*/
|
|
117
|
+
quantity: number | null;
|
|
118
|
+
/**
|
|
119
|
+
* Per-member quantity limit, or `null` for unlimited.
|
|
120
|
+
*/
|
|
121
|
+
quantityLimit: number | null;
|
|
122
|
+
/**
|
|
123
|
+
* Secondary hex colour (without `#`).
|
|
124
|
+
*/
|
|
125
|
+
secondaryColor: string;
|
|
126
|
+
/**
|
|
127
|
+
* Sell price.
|
|
128
|
+
*/
|
|
129
|
+
sellPrice: number;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* An item entry in a member's inventory.
|
|
133
|
+
*/
|
|
134
|
+
interface UserItem {
|
|
135
|
+
/**
|
|
136
|
+
* Buy price.
|
|
137
|
+
*/
|
|
138
|
+
buyPrice: number;
|
|
139
|
+
/**
|
|
140
|
+
* Optional description.
|
|
141
|
+
*/
|
|
142
|
+
description: string | null;
|
|
143
|
+
/**
|
|
144
|
+
* Current durability of the active stack, or `null`.
|
|
145
|
+
*/
|
|
146
|
+
durability: number | null;
|
|
147
|
+
/**
|
|
148
|
+
* Emoji string, or `null`.
|
|
149
|
+
*/
|
|
150
|
+
emoji: string | null;
|
|
151
|
+
/**
|
|
152
|
+
* `"UNICODE"`, `"CUSTOM"`, or `null`.
|
|
153
|
+
*/
|
|
154
|
+
emojiType: "CUSTOM" | "UNICODE" | null;
|
|
155
|
+
/**
|
|
156
|
+
* Item flags.
|
|
157
|
+
*/
|
|
158
|
+
flags: string[];
|
|
159
|
+
/**
|
|
160
|
+
* URL to a custom icon, or `null`.
|
|
161
|
+
*/
|
|
162
|
+
iconURL: string | null;
|
|
163
|
+
/**
|
|
164
|
+
* UUID of the item.
|
|
165
|
+
*/
|
|
166
|
+
id: string;
|
|
167
|
+
/**
|
|
168
|
+
* Full durability per item (`0` = no durability).
|
|
169
|
+
*/
|
|
170
|
+
maxDurability: number;
|
|
171
|
+
/**
|
|
172
|
+
* Display name.
|
|
173
|
+
*/
|
|
174
|
+
name: string;
|
|
175
|
+
/**
|
|
176
|
+
* How many the member owns, or `null`.
|
|
177
|
+
*/
|
|
178
|
+
quantity: number | null;
|
|
179
|
+
/**
|
|
180
|
+
* Sell price.
|
|
181
|
+
*/
|
|
182
|
+
sellPrice: number;
|
|
183
|
+
/**
|
|
184
|
+
* Item type.
|
|
185
|
+
*/
|
|
186
|
+
type: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* A chest entry in a member's inventory.
|
|
190
|
+
*/
|
|
191
|
+
interface UserChest {
|
|
192
|
+
/**
|
|
193
|
+
* Buy price.
|
|
194
|
+
*/
|
|
195
|
+
buyPrice: number;
|
|
196
|
+
/**
|
|
197
|
+
* Chest flags.
|
|
198
|
+
*/
|
|
199
|
+
flags: string[];
|
|
200
|
+
/**
|
|
201
|
+
* URL to a custom icon, or `null`.
|
|
202
|
+
*/
|
|
203
|
+
iconURL: string | null;
|
|
204
|
+
/**
|
|
205
|
+
* UUID of the chest.
|
|
206
|
+
*/
|
|
207
|
+
id: string;
|
|
208
|
+
/**
|
|
209
|
+
* Display name.
|
|
210
|
+
*/
|
|
211
|
+
name: string;
|
|
212
|
+
/**
|
|
213
|
+
* Primary hex colour (without `#`).
|
|
214
|
+
*/
|
|
215
|
+
primaryColor: string;
|
|
216
|
+
/**
|
|
217
|
+
* How many the member owns.
|
|
218
|
+
*/
|
|
219
|
+
quantity: number;
|
|
220
|
+
/**
|
|
221
|
+
* Secondary hex colour (without `#`).
|
|
222
|
+
*/
|
|
223
|
+
secondaryColor: string;
|
|
224
|
+
/**
|
|
225
|
+
* Sell price.
|
|
226
|
+
*/
|
|
227
|
+
sellPrice: number;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* A member's daily-streak info.
|
|
231
|
+
*/
|
|
232
|
+
interface DailyStreak {
|
|
233
|
+
/**
|
|
234
|
+
* ISO 8601 timestamp of the last claim.
|
|
235
|
+
*/
|
|
236
|
+
lastClaim: string;
|
|
237
|
+
/**
|
|
238
|
+
* Current consecutive streak count.
|
|
239
|
+
*/
|
|
240
|
+
streak: number;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Query parameters for {@link UserResource.getEcoProfile}.
|
|
244
|
+
*/
|
|
245
|
+
interface EcoProfileOptions {
|
|
246
|
+
/**
|
|
247
|
+
* Include the member's chest inventory.
|
|
248
|
+
*/
|
|
249
|
+
chests?: boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Include the member's daily streak.
|
|
252
|
+
*/
|
|
253
|
+
dailyStreak?: boolean;
|
|
254
|
+
/**
|
|
255
|
+
* Include the member's item inventory.
|
|
256
|
+
*/
|
|
257
|
+
items?: boolean;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Conditional response type for {@link UserResource.getEcoProfile}.
|
|
261
|
+
* Optional relations are only present when their query param is `true`.
|
|
262
|
+
*/
|
|
263
|
+
type EcoProfileResult<O extends EcoProfileOptions> = (O extends {
|
|
264
|
+
chests: true;
|
|
265
|
+
} ? {
|
|
266
|
+
chests: UserChest[];
|
|
267
|
+
} : Record<never, never>) & (O extends {
|
|
268
|
+
dailyStreak: true;
|
|
269
|
+
} ? {
|
|
270
|
+
dailyStreak: DailyStreak | null;
|
|
271
|
+
} : Record<never, never>) & (O extends {
|
|
272
|
+
items: true;
|
|
273
|
+
} ? {
|
|
274
|
+
items: UserItem[];
|
|
275
|
+
} : Record<never, never>) & {
|
|
276
|
+
money: number;
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* Full levelling profile for a guild member.
|
|
280
|
+
*/
|
|
281
|
+
interface LevelProfile {
|
|
282
|
+
/**
|
|
283
|
+
* Current level.
|
|
284
|
+
*/
|
|
285
|
+
level: number;
|
|
286
|
+
/**
|
|
287
|
+
* Total messages sent.
|
|
288
|
+
*/
|
|
289
|
+
messages: number;
|
|
290
|
+
/**
|
|
291
|
+
* Remaining XP needed to reach the next level.
|
|
292
|
+
*/
|
|
293
|
+
neededXp: number;
|
|
294
|
+
/**
|
|
295
|
+
* Total reactions added.
|
|
296
|
+
*/
|
|
297
|
+
reactions: number;
|
|
298
|
+
/**
|
|
299
|
+
* Total XP across all levels.
|
|
300
|
+
*/
|
|
301
|
+
totalXp: number;
|
|
302
|
+
/**
|
|
303
|
+
* Total minutes spent in voice channels.
|
|
304
|
+
*/
|
|
305
|
+
voiceMinutes: number;
|
|
306
|
+
/**
|
|
307
|
+
* XP accumulated in the current level.
|
|
308
|
+
*/
|
|
309
|
+
xp: number;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Result returned after triggering an item's actions.
|
|
313
|
+
*/
|
|
314
|
+
interface UseItemResult {
|
|
315
|
+
/**
|
|
316
|
+
* Map of chest UUID → quantity added.
|
|
317
|
+
*/
|
|
318
|
+
addedChests: Record<string, number>;
|
|
319
|
+
/**
|
|
320
|
+
* Map of item UUID → quantity added.
|
|
321
|
+
*/
|
|
322
|
+
addedItems: Record<string, number>;
|
|
323
|
+
/**
|
|
324
|
+
* Role IDs added to the member.
|
|
325
|
+
*/
|
|
326
|
+
addedRoles: string[];
|
|
327
|
+
/**
|
|
328
|
+
* Map of chest UUID → quantity removed.
|
|
329
|
+
*/
|
|
330
|
+
chestsRemoved: Record<string, number>;
|
|
331
|
+
/**
|
|
332
|
+
* Map of item UUID → quantity removed.
|
|
333
|
+
*/
|
|
334
|
+
itemsRemoved: Record<string, number>;
|
|
335
|
+
/**
|
|
336
|
+
* Total money awarded (negative if removed).
|
|
337
|
+
*/
|
|
338
|
+
money: number;
|
|
339
|
+
/**
|
|
340
|
+
* Role IDs removed from the member.
|
|
341
|
+
*/
|
|
342
|
+
removedRoles: string[];
|
|
343
|
+
/**
|
|
344
|
+
* Map of role ID → Unix timestamp when the temporary role expires.
|
|
345
|
+
*/
|
|
346
|
+
rolesDuration: Record<string, number>;
|
|
347
|
+
/**
|
|
348
|
+
* Total XP awarded (negative if removed).
|
|
349
|
+
*/
|
|
350
|
+
xp: number;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Rate-limit information parsed from response headers.
|
|
354
|
+
*/
|
|
355
|
+
interface RateLimitInfo {
|
|
356
|
+
/**
|
|
357
|
+
* Maximum requests allowed in the window.
|
|
358
|
+
*/
|
|
359
|
+
limit: number;
|
|
360
|
+
/**
|
|
361
|
+
* Requests remaining in the current window.
|
|
362
|
+
*/
|
|
363
|
+
remaining: number;
|
|
364
|
+
/**
|
|
365
|
+
* Unix timestamp (seconds) when the window resets.
|
|
366
|
+
*/
|
|
367
|
+
reset: number;
|
|
368
|
+
/**
|
|
369
|
+
* Seconds until the window resets.
|
|
370
|
+
*/
|
|
371
|
+
resetAfter: number;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
interface NoctalyResponse<T> {
|
|
375
|
+
/**
|
|
376
|
+
* The parsed response data.
|
|
377
|
+
*/
|
|
378
|
+
data: T;
|
|
379
|
+
/**
|
|
380
|
+
* Rate-limit info from the response headers.
|
|
381
|
+
* Present on all successful responses that include rate-limit headers.
|
|
382
|
+
*/
|
|
383
|
+
rateLimit?: RateLimitInfo;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Manages guild-level chest operations.
|
|
388
|
+
*/
|
|
389
|
+
declare class GuildChestsResource {
|
|
390
|
+
#private;
|
|
391
|
+
constructor(guildID: string, config: ClientConfig);
|
|
392
|
+
/**
|
|
393
|
+
* Returns all chests configured in the guild's economy.
|
|
394
|
+
*
|
|
395
|
+
* `GET /guilds/{guildID}/chests`
|
|
396
|
+
*/
|
|
397
|
+
list(): Promise<NoctalyResponse<{
|
|
398
|
+
chests: Chest[];
|
|
399
|
+
}>>;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Manages guild-level item operations.
|
|
404
|
+
*/
|
|
405
|
+
declare class GuildItemsResource {
|
|
406
|
+
#private;
|
|
407
|
+
constructor(guildID: string, config: ClientConfig);
|
|
408
|
+
/**
|
|
409
|
+
* Returns all items configured in the guild's economy.
|
|
410
|
+
*
|
|
411
|
+
* `GET /guilds/{guildID}/items`
|
|
412
|
+
*/
|
|
413
|
+
list(): Promise<NoctalyResponse<{
|
|
414
|
+
items: Item[];
|
|
415
|
+
}>>;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
interface AddChestsBody {
|
|
419
|
+
/**
|
|
420
|
+
* UUID of the chest to add.
|
|
421
|
+
*/
|
|
422
|
+
chestID: string;
|
|
423
|
+
/**
|
|
424
|
+
* Quantity to add. Min: `1`. Max: `1,000,000`.
|
|
425
|
+
*/
|
|
426
|
+
quantity: number;
|
|
427
|
+
}
|
|
428
|
+
interface RemoveChestsBody {
|
|
429
|
+
/**
|
|
430
|
+
* UUID of the chest to remove.
|
|
431
|
+
*/
|
|
432
|
+
chestID: string;
|
|
433
|
+
/**
|
|
434
|
+
* Quantity to remove. Min: `1`. Max: `1,000,000`.
|
|
435
|
+
*/
|
|
436
|
+
quantity: number;
|
|
437
|
+
}
|
|
438
|
+
interface SetChestQuantityBody {
|
|
439
|
+
/**
|
|
440
|
+
* UUID of the chest.
|
|
441
|
+
*/
|
|
442
|
+
chestID: string;
|
|
443
|
+
/**
|
|
444
|
+
* Target quantity. Min: `0` (removes the chest entirely). Max: `1,000,000`.
|
|
445
|
+
*/
|
|
446
|
+
quantity: number;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Manages chest operations for a specific guild member.
|
|
450
|
+
*/
|
|
451
|
+
declare class UserChestsResource {
|
|
452
|
+
#private;
|
|
453
|
+
constructor(guildID: string, userID: string, config: ClientConfig);
|
|
454
|
+
/**
|
|
455
|
+
* Adds a quantity of a chest to the member's inventory.
|
|
456
|
+
*
|
|
457
|
+
* `POST /guilds/{guildID}/users/{userID}/chests`
|
|
458
|
+
*/
|
|
459
|
+
add(body: AddChestsBody): Promise<NoctalyResponse<{
|
|
460
|
+
quantity: number;
|
|
461
|
+
}>>;
|
|
462
|
+
/**
|
|
463
|
+
* Removes a quantity of a chest from the member's inventory. If the
|
|
464
|
+
* resulting quantity reaches `0` or below the chest is removed entirely.
|
|
465
|
+
*
|
|
466
|
+
* `DELETE /guilds/{guildID}/users/{userID}/chests`
|
|
467
|
+
*/
|
|
468
|
+
remove(body: RemoveChestsBody): Promise<NoctalyResponse<{
|
|
469
|
+
quantity: number;
|
|
470
|
+
}>>;
|
|
471
|
+
/**
|
|
472
|
+
* Sets the exact quantity of a chest in the member's inventory.
|
|
473
|
+
* Passing `0` removes the chest entirely.
|
|
474
|
+
*
|
|
475
|
+
* `PUT /guilds/{guildID}/users/{userID}/chests`
|
|
476
|
+
*/
|
|
477
|
+
set(body: SetChestQuantityBody): Promise<NoctalyResponse<{
|
|
478
|
+
quantity: number;
|
|
479
|
+
}>>;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
interface AddItemsBody {
|
|
483
|
+
/**
|
|
484
|
+
* UUID of the item to add.
|
|
485
|
+
*/
|
|
486
|
+
itemID: string;
|
|
487
|
+
/**
|
|
488
|
+
* Quantity to add. Min: `1`. Max: `1,000,000`.
|
|
489
|
+
*/
|
|
490
|
+
quantity: number;
|
|
491
|
+
}
|
|
492
|
+
interface RemoveItemsBody {
|
|
493
|
+
/**
|
|
494
|
+
* UUID of the item to remove.
|
|
495
|
+
*/
|
|
496
|
+
itemID: string;
|
|
497
|
+
/**
|
|
498
|
+
* Quantity to remove. Min: `1`. Max: `1,000,000`.
|
|
499
|
+
*/
|
|
500
|
+
quantity: number;
|
|
501
|
+
}
|
|
502
|
+
interface SetItemQuantityBody {
|
|
503
|
+
/**
|
|
504
|
+
* UUID of the item.
|
|
505
|
+
*/
|
|
506
|
+
itemID: string;
|
|
507
|
+
/**
|
|
508
|
+
* Target quantity. Min: `0` (removes the item entirely). Max: `1,000,000`.
|
|
509
|
+
*/
|
|
510
|
+
quantity: number;
|
|
511
|
+
}
|
|
512
|
+
interface UseItemBody {
|
|
513
|
+
/**
|
|
514
|
+
* Number of uses. Min: `1`. Max: `1,000,000`. Defaults to `1`.
|
|
515
|
+
*/
|
|
516
|
+
quantity?: number;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Manages item operations for a specific guild member.
|
|
520
|
+
*/
|
|
521
|
+
declare class UserItemsResource {
|
|
522
|
+
#private;
|
|
523
|
+
constructor(guildID: string, userID: string, config: ClientConfig);
|
|
524
|
+
/**
|
|
525
|
+
* Adds a quantity of an item to the member's inventory.
|
|
526
|
+
*
|
|
527
|
+
* `POST /guilds/{guildID}/users/{userID}/items`
|
|
528
|
+
*/
|
|
529
|
+
add(body: AddItemsBody): Promise<NoctalyResponse<{
|
|
530
|
+
quantity: number;
|
|
531
|
+
}>>;
|
|
532
|
+
/**
|
|
533
|
+
* Removes a quantity of an item from the member's inventory. If the
|
|
534
|
+
* resulting quantity reaches `0` or below the item is removed entirely.
|
|
535
|
+
*
|
|
536
|
+
* `DELETE /guilds/{guildID}/users/{userID}/items`
|
|
537
|
+
*/
|
|
538
|
+
remove(body: RemoveItemsBody): Promise<NoctalyResponse<{
|
|
539
|
+
quantity: number;
|
|
540
|
+
}>>;
|
|
541
|
+
/**
|
|
542
|
+
* Sets the exact quantity of an item in the member's inventory.
|
|
543
|
+
* Passing `0` removes the item entirely.
|
|
544
|
+
*
|
|
545
|
+
* `PUT /guilds/{guildID}/users/{userID}/items`
|
|
546
|
+
*/
|
|
547
|
+
set(body: SetItemQuantityBody): Promise<NoctalyResponse<{
|
|
548
|
+
quantity: number;
|
|
549
|
+
}>>;
|
|
550
|
+
/**
|
|
551
|
+
* Triggers the item's configured actions (give/remove money, XP, roles,
|
|
552
|
+
* other items…). Only works for items of type `CUSTOM` with at least one
|
|
553
|
+
* action. The item is consumed unless it has the `KEEP_AFTER_USE` flag.
|
|
554
|
+
*
|
|
555
|
+
* `POST /guilds/{guildID}/users/{userID}/items/{itemID}/use`
|
|
556
|
+
*/
|
|
557
|
+
use(itemID: string, body?: UseItemBody): Promise<NoctalyResponse<UseItemResult>>;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
interface UpdateXPBody {
|
|
561
|
+
/**
|
|
562
|
+
* When `true`, the server multiplier and the member's booster roles
|
|
563
|
+
* affect the amount of XP.
|
|
564
|
+
*
|
|
565
|
+
* @default false
|
|
566
|
+
*/
|
|
567
|
+
multiply?: boolean;
|
|
568
|
+
/**
|
|
569
|
+
* XP to give (positive) or remove (negative).
|
|
570
|
+
* Min: `-100,000,000`. Max: `100,000,000`.
|
|
571
|
+
*/
|
|
572
|
+
xp: number;
|
|
573
|
+
}
|
|
574
|
+
interface UpdateLevelBody {
|
|
575
|
+
/**
|
|
576
|
+
* Levels to give (positive) or remove (negative).
|
|
577
|
+
* Min: `-1,000`. Max: `1,000`.
|
|
578
|
+
*/
|
|
579
|
+
level: number;
|
|
580
|
+
}
|
|
581
|
+
interface UpdateMoneyBody {
|
|
582
|
+
/**
|
|
583
|
+
* Money to give (positive) or remove (negative).
|
|
584
|
+
* Min: `-1,000,000,000`. Max: `1,000,000,000`.
|
|
585
|
+
*/
|
|
586
|
+
money: number;
|
|
587
|
+
/**
|
|
588
|
+
* When `true`, the server multiplier and the member's booster roles
|
|
589
|
+
* affect the amount of money.
|
|
590
|
+
*
|
|
591
|
+
* @default false
|
|
592
|
+
*/
|
|
593
|
+
multiply?: boolean;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Operations scoped to a single guild member.
|
|
597
|
+
*/
|
|
598
|
+
declare class UserResource {
|
|
599
|
+
#private;
|
|
600
|
+
/**
|
|
601
|
+
* Item inventory operations for this member.
|
|
602
|
+
*/
|
|
603
|
+
readonly items: UserItemsResource;
|
|
604
|
+
/**
|
|
605
|
+
* Chest inventory operations for this member.
|
|
606
|
+
*/
|
|
607
|
+
readonly chests: UserChestsResource;
|
|
608
|
+
constructor(guildID: string, userID: string, config: ClientConfig);
|
|
609
|
+
/**
|
|
610
|
+
* Returns the member's economy profile.
|
|
611
|
+
* Pass options to include optional relations (items, chests, daily streak).
|
|
612
|
+
*
|
|
613
|
+
* `GET /guilds/{guildID}/users/{userID}/eco-profile`
|
|
614
|
+
*/
|
|
615
|
+
getEcoProfile(): Promise<NoctalyResponse<EcoProfileResult<Record<never, never>>>>;
|
|
616
|
+
getEcoProfile<O extends EcoProfileOptions>(options: O): Promise<NoctalyResponse<EcoProfileResult<O>>>;
|
|
617
|
+
/**
|
|
618
|
+
* Returns the member's full levelling profile.
|
|
619
|
+
*
|
|
620
|
+
* `GET /guilds/{guildID}/users/{userID}/level-profile`
|
|
621
|
+
*/
|
|
622
|
+
getLevelProfile(): Promise<NoctalyResponse<LevelProfile>>;
|
|
623
|
+
/**
|
|
624
|
+
* Adds or removes XP from the member.
|
|
625
|
+
*
|
|
626
|
+
* `POST /guilds/{guildID}/users/{userID}/xp`
|
|
627
|
+
*/
|
|
628
|
+
updateXP(body: UpdateXPBody): Promise<NoctalyResponse<{
|
|
629
|
+
xp: number;
|
|
630
|
+
}>>;
|
|
631
|
+
/**
|
|
632
|
+
* Adds or removes levels from the member.
|
|
633
|
+
*
|
|
634
|
+
* `POST /guilds/{guildID}/users/{userID}/level`
|
|
635
|
+
*/
|
|
636
|
+
updateLevel(body: UpdateLevelBody): Promise<NoctalyResponse<{
|
|
637
|
+
level: number;
|
|
638
|
+
}>>;
|
|
639
|
+
/**
|
|
640
|
+
* Adds or removes money from the member.
|
|
641
|
+
*
|
|
642
|
+
* `POST /guilds/{guildID}/users/{userID}/money`
|
|
643
|
+
*/
|
|
644
|
+
updateMoney(body: UpdateMoneyBody): Promise<NoctalyResponse<{
|
|
645
|
+
money: number;
|
|
646
|
+
}>>;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Operations scoped to a single guild.
|
|
651
|
+
*/
|
|
652
|
+
declare class GuildResource {
|
|
653
|
+
#private;
|
|
654
|
+
/**
|
|
655
|
+
* Guild-wide item catalogue operations.
|
|
656
|
+
*/
|
|
657
|
+
readonly items: GuildItemsResource;
|
|
658
|
+
/**
|
|
659
|
+
* Guild-wide chest catalogue operations.
|
|
660
|
+
*/
|
|
661
|
+
readonly chests: GuildChestsResource;
|
|
662
|
+
constructor(guildID: string, config: ClientConfig);
|
|
663
|
+
/**
|
|
664
|
+
* Returns a {@link UserResource} scoped to the given guild member.
|
|
665
|
+
*
|
|
666
|
+
* @param userID - Discord user ID of the member.
|
|
667
|
+
*/
|
|
668
|
+
users(userID: string): UserResource;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
interface NoctalyClientOptions {
|
|
672
|
+
/**
|
|
673
|
+
* Your Noctaly API key.
|
|
674
|
+
*/
|
|
675
|
+
apiKey: string;
|
|
676
|
+
/**
|
|
677
|
+
* Override the base URL. Useful for self-hosted or staging environments.
|
|
678
|
+
*
|
|
679
|
+
* @default "https://noctaly.com/api/v1"
|
|
680
|
+
*/
|
|
681
|
+
baseURL?: string;
|
|
682
|
+
/**
|
|
683
|
+
* Maximum number of automatic retries before the error is thrown.
|
|
684
|
+
*
|
|
685
|
+
* @default 3
|
|
686
|
+
*/
|
|
687
|
+
maxRetries?: number;
|
|
688
|
+
/**
|
|
689
|
+
* Automatically retry requests that receive a `rate_limited` (429) response,
|
|
690
|
+
* waiting `retryAfter` seconds between attempts.
|
|
691
|
+
*
|
|
692
|
+
* @default true
|
|
693
|
+
*/
|
|
694
|
+
retry?: boolean;
|
|
695
|
+
/**
|
|
696
|
+
* Request timeout in milliseconds. Set to `0` to disable.
|
|
697
|
+
*
|
|
698
|
+
* @default 30_000
|
|
699
|
+
*/
|
|
700
|
+
timeout?: number;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Entry point for the Noctaly SDK.
|
|
704
|
+
*
|
|
705
|
+
* @example
|
|
706
|
+
* ```ts
|
|
707
|
+
* import { NoctalyClient } from "@noctaly/sdk";
|
|
708
|
+
*
|
|
709
|
+
* const noctaly = new NoctalyClient({ apiKey: "your-api-key" });
|
|
710
|
+
*
|
|
711
|
+
* const { data } = await noctaly.guilds("GUILD_ID").users("USER_ID").getLevelProfile();
|
|
712
|
+
* console.log(`Level ${data.level} — ${data.xp} XP`);
|
|
713
|
+
* ```
|
|
714
|
+
*/
|
|
715
|
+
declare class NoctalyClient {
|
|
716
|
+
#private;
|
|
717
|
+
constructor({ apiKey, baseURL, timeout, retry, maxRetries, }: NoctalyClientOptions);
|
|
718
|
+
/**
|
|
719
|
+
* Returns a {@link GuildResource} scoped to the given guild.
|
|
720
|
+
*
|
|
721
|
+
* @param guildID - Discord guild (server) ID.
|
|
722
|
+
*/
|
|
723
|
+
guilds(guildID: string): GuildResource;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* All possible error codes returned by the Noctaly API.
|
|
728
|
+
*/
|
|
729
|
+
type ApiErrorCode = "module_disabled" | "not_found" | "rate_limited" | "unauthenticated" | "unauthorized" | "unexpected_error" | "validation_error";
|
|
730
|
+
/**
|
|
731
|
+
* A single Zod validation issue surfaced by the API.
|
|
732
|
+
*/
|
|
733
|
+
interface ValidationIssue {
|
|
734
|
+
/**
|
|
735
|
+
* Zod error code.
|
|
736
|
+
*/
|
|
737
|
+
code: string;
|
|
738
|
+
/**
|
|
739
|
+
* Human-readable error message.
|
|
740
|
+
*/
|
|
741
|
+
message: string;
|
|
742
|
+
/**
|
|
743
|
+
* Path to the field that failed validation.
|
|
744
|
+
*/
|
|
745
|
+
path: (number | string)[];
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Thrown by all SDK methods on a non-2xx API response.
|
|
749
|
+
*/
|
|
750
|
+
declare class NoctalyError extends Error {
|
|
751
|
+
/**
|
|
752
|
+
* Machine-readable error code.
|
|
753
|
+
*/
|
|
754
|
+
readonly code: ApiErrorCode;
|
|
755
|
+
/**
|
|
756
|
+
* HTTP status code.
|
|
757
|
+
*/
|
|
758
|
+
readonly status: number;
|
|
759
|
+
/**
|
|
760
|
+
* Seconds to wait before retrying. Only present when `code` is
|
|
761
|
+
* `"rate_limited"`.
|
|
762
|
+
*/
|
|
763
|
+
readonly retryAfter?: number;
|
|
764
|
+
/**
|
|
765
|
+
* `true` when the rate limit that was exceeded is the global one.
|
|
766
|
+
* Only present when `code` is `"rate_limited"`.
|
|
767
|
+
*/
|
|
768
|
+
readonly global?: boolean;
|
|
769
|
+
/**
|
|
770
|
+
* Zod validation issues. Only present when `code` is
|
|
771
|
+
* `"validation_error"`.
|
|
772
|
+
*/
|
|
773
|
+
readonly details?: ValidationIssue[];
|
|
774
|
+
constructor(opts: {
|
|
775
|
+
code: ApiErrorCode;
|
|
776
|
+
details?: ValidationIssue[];
|
|
777
|
+
global?: boolean;
|
|
778
|
+
message: string;
|
|
779
|
+
retryAfter?: number;
|
|
780
|
+
status: number;
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
export { type AddChestsBody, type AddItemsBody, type ApiErrorCode, type Chest, type DailyStreak, type EcoProfileOptions, type EcoProfileResult, GuildChestsResource, GuildItemsResource, GuildResource, type Item, type LevelProfile, NoctalyClient, type NoctalyClientOptions, NoctalyError, type NoctalyResponse, type RateLimitInfo, type RemoveChestsBody, type RemoveItemsBody, type SetChestQuantityBody, type SetItemQuantityBody, type UpdateLevelBody, type UpdateMoneyBody, type UpdateXPBody, type UseItemBody, type UseItemResult, type UserChest, UserChestsResource, type UserItem, UserItemsResource, UserResource, type ValidationIssue };
|