krawlet-js 1.0.1 → 1.1.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.cjs +87 -0
- package/dist/index.d.cts +55 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.js +86 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
AddressesResource: () => AddressesResource,
|
|
24
|
+
ApiKeyResource: () => ApiKeyResource,
|
|
24
25
|
ErrorCode: () => ErrorCode,
|
|
25
26
|
HealthResource: () => HealthResource,
|
|
26
27
|
ItemsResource: () => ItemsResource,
|
|
@@ -549,6 +550,90 @@ var ReportsResource = class {
|
|
|
549
550
|
}
|
|
550
551
|
};
|
|
551
552
|
|
|
553
|
+
// src/resources/apikey.ts
|
|
554
|
+
var ApiKeyResource = class {
|
|
555
|
+
constructor(client) {
|
|
556
|
+
this.client = client;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Get information about the authenticated API key
|
|
560
|
+
*
|
|
561
|
+
* @param options - Optional parameters
|
|
562
|
+
* @param options.usage - Include detailed usage statistics (default: true)
|
|
563
|
+
* @returns API key information with optional usage statistics
|
|
564
|
+
* @throws {KrawletError} If not authenticated (401)
|
|
565
|
+
*
|
|
566
|
+
* @example
|
|
567
|
+
* ```typescript
|
|
568
|
+
* // Get full info with usage stats
|
|
569
|
+
* const info = await client.apiKey.getInfo();
|
|
570
|
+
*
|
|
571
|
+
* // Get basic info without usage stats
|
|
572
|
+
* const basicInfo = await client.apiKey.getInfo({ usage: false });
|
|
573
|
+
* ```
|
|
574
|
+
*/
|
|
575
|
+
async getInfo(options) {
|
|
576
|
+
const params = {};
|
|
577
|
+
if (options?.usage !== void 0) {
|
|
578
|
+
params.usage = String(options.usage);
|
|
579
|
+
}
|
|
580
|
+
const response = await this.client.request("/v1/apikey", {
|
|
581
|
+
params: Object.keys(params).length > 0 ? params : void 0
|
|
582
|
+
});
|
|
583
|
+
return response.data;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Get detailed usage statistics for the authenticated API key
|
|
587
|
+
*
|
|
588
|
+
* @returns Detailed usage statistics including request counts and top endpoints
|
|
589
|
+
* @throws {KrawletError} If not authenticated (401)
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```typescript
|
|
593
|
+
* const usage = await client.apiKey.getUsage();
|
|
594
|
+
* console.log(`Total requests: ${usage.totalRequests}`);
|
|
595
|
+
* console.log(`Last 24h: ${usage.last24h}`);
|
|
596
|
+
* console.log(`Blocked: ${usage.blockedRequests}`);
|
|
597
|
+
* console.log('Top endpoints:', usage.topEndpoints);
|
|
598
|
+
* ```
|
|
599
|
+
*/
|
|
600
|
+
async getUsage() {
|
|
601
|
+
const response = await this.client.request("/v1/apikey/usage");
|
|
602
|
+
return response.data;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Get recent request logs for the authenticated API key
|
|
606
|
+
*
|
|
607
|
+
* @param options - Optional parameters
|
|
608
|
+
* @param options.limit - Maximum number of logs to return (1-100, default: 50)
|
|
609
|
+
* @returns Request logs with count
|
|
610
|
+
* @throws {KrawletError} If not authenticated (401)
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* ```typescript
|
|
614
|
+
* // Get default number of logs (50)
|
|
615
|
+
* const logs = await client.apiKey.getLogs();
|
|
616
|
+
*
|
|
617
|
+
* // Get last 10 requests
|
|
618
|
+
* const recentLogs = await client.apiKey.getLogs({ limit: 10 });
|
|
619
|
+
*
|
|
620
|
+
* for (const log of recentLogs.logs) {
|
|
621
|
+
* console.log(`${log.method} ${log.path} - ${log.responseStatus} (${log.responseTimeMs}ms)`);
|
|
622
|
+
* }
|
|
623
|
+
* ```
|
|
624
|
+
*/
|
|
625
|
+
async getLogs(options) {
|
|
626
|
+
const params = {};
|
|
627
|
+
if (options?.limit !== void 0) {
|
|
628
|
+
params.limit = String(options.limit);
|
|
629
|
+
}
|
|
630
|
+
const response = await this.client.request("/v1/apikey/logs", {
|
|
631
|
+
params: Object.keys(params).length > 0 ? params : void 0
|
|
632
|
+
});
|
|
633
|
+
return response.data;
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
|
|
552
637
|
// src/client.ts
|
|
553
638
|
var KrawletClient = class {
|
|
554
639
|
/**
|
|
@@ -573,6 +658,7 @@ var KrawletClient = class {
|
|
|
573
658
|
this.addresses = new AddressesResource(this.httpClient);
|
|
574
659
|
this.storage = new StorageResource(this.httpClient);
|
|
575
660
|
this.reports = new ReportsResource(this.httpClient);
|
|
661
|
+
this.apiKey = new ApiKeyResource(this.httpClient);
|
|
576
662
|
}
|
|
577
663
|
/**
|
|
578
664
|
* Get the last known rate limit information
|
|
@@ -603,6 +689,7 @@ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
|
603
689
|
// Annotate the CommonJS export names for ESM import in node:
|
|
604
690
|
0 && (module.exports = {
|
|
605
691
|
AddressesResource,
|
|
692
|
+
ApiKeyResource,
|
|
606
693
|
ErrorCode,
|
|
607
694
|
HealthResource,
|
|
608
695
|
ItemsResource,
|
package/dist/index.d.cts
CHANGED
|
@@ -148,6 +148,45 @@ interface ShopSyncData {
|
|
|
148
148
|
}>;
|
|
149
149
|
}>;
|
|
150
150
|
}
|
|
151
|
+
type ApiKeyTier = 'free' | 'premium';
|
|
152
|
+
interface ApiKeyUsage {
|
|
153
|
+
totalRequests: number;
|
|
154
|
+
last24h: number;
|
|
155
|
+
last7d: number;
|
|
156
|
+
last30d: number;
|
|
157
|
+
blockedRequests: number;
|
|
158
|
+
avgResponseTimeMs: number | null;
|
|
159
|
+
topEndpoints: Array<{
|
|
160
|
+
path: string;
|
|
161
|
+
count: number;
|
|
162
|
+
}>;
|
|
163
|
+
}
|
|
164
|
+
interface ApiKeyInfo {
|
|
165
|
+
id: string;
|
|
166
|
+
name: string;
|
|
167
|
+
email: string | null;
|
|
168
|
+
tier: ApiKeyTier;
|
|
169
|
+
rateLimit: number;
|
|
170
|
+
isActive: boolean;
|
|
171
|
+
requestCount: number;
|
|
172
|
+
lastUsedAt: string | null;
|
|
173
|
+
createdAt: string;
|
|
174
|
+
usage?: ApiKeyUsage;
|
|
175
|
+
}
|
|
176
|
+
interface RequestLog {
|
|
177
|
+
requestId: string;
|
|
178
|
+
timestamp: string;
|
|
179
|
+
method: string;
|
|
180
|
+
path: string;
|
|
181
|
+
responseStatus: number | null;
|
|
182
|
+
responseTimeMs: number | null;
|
|
183
|
+
wasBlocked: boolean;
|
|
184
|
+
blockReason: string | null;
|
|
185
|
+
}
|
|
186
|
+
interface RequestLogsResponse {
|
|
187
|
+
count: number;
|
|
188
|
+
logs: RequestLog[];
|
|
189
|
+
}
|
|
151
190
|
interface RateLimit {
|
|
152
191
|
limit: number;
|
|
153
192
|
remaining: number;
|
|
@@ -325,6 +364,20 @@ declare class ReportsResource {
|
|
|
325
364
|
get(id: string): Promise<unknown>;
|
|
326
365
|
}
|
|
327
366
|
|
|
367
|
+
interface GetApiKeyInfoOptions {
|
|
368
|
+
usage?: boolean;
|
|
369
|
+
}
|
|
370
|
+
interface GetApiKeyLogsOptions {
|
|
371
|
+
limit?: number;
|
|
372
|
+
}
|
|
373
|
+
declare class ApiKeyResource {
|
|
374
|
+
private client;
|
|
375
|
+
constructor(client: HttpClient);
|
|
376
|
+
getInfo(options?: GetApiKeyInfoOptions): Promise<ApiKeyInfo>;
|
|
377
|
+
getUsage(): Promise<ApiKeyUsage>;
|
|
378
|
+
getLogs(options?: GetApiKeyLogsOptions): Promise<RequestLogsResponse>;
|
|
379
|
+
}
|
|
380
|
+
|
|
328
381
|
interface KrawletClientConfig {
|
|
329
382
|
baseUrl?: string;
|
|
330
383
|
apiKey?: string;
|
|
@@ -343,6 +396,7 @@ declare class KrawletClient {
|
|
|
343
396
|
readonly addresses: AddressesResource;
|
|
344
397
|
readonly storage: StorageResource;
|
|
345
398
|
readonly reports: ReportsResource;
|
|
399
|
+
readonly apiKey: ApiKeyResource;
|
|
346
400
|
constructor(config?: KrawletClientConfig);
|
|
347
401
|
getRateLimit(): RateLimit | undefined;
|
|
348
402
|
}
|
|
@@ -359,4 +413,4 @@ declare class KrawletError extends Error {
|
|
|
359
413
|
isRateLimitError(): boolean;
|
|
360
414
|
}
|
|
361
415
|
|
|
362
|
-
export { AddressesResource, type ApiResponse, type ApiResponseMeta, type ChangeLogOptions, type ChangeLogResult, type DetailedHealthResponse, ErrorCode, type ErrorResponse, HealthResource, type HealthResponse, type Item, type ItemChangeLog, type ItemChangeType, ItemsResource, type KnownAddress, type KnownAddressType, KrawletClient, type KrawletClientConfig, KrawletError, type Player, type PlayerNotifications, PlayersResource, type Price, type PriceChangeLog, type RateLimit, type ReportRecords, ReportsResource, type Shop, type ShopChangeLog, type ShopSyncData, ShopsResource, type StorageData, StorageResource };
|
|
416
|
+
export { AddressesResource, type ApiKeyInfo, ApiKeyResource, type ApiKeyTier, type ApiKeyUsage, type ApiResponse, type ApiResponseMeta, type ChangeLogOptions, type ChangeLogResult, type DetailedHealthResponse, ErrorCode, type ErrorResponse, HealthResource, type HealthResponse, type Item, type ItemChangeLog, type ItemChangeType, ItemsResource, type KnownAddress, type KnownAddressType, KrawletClient, type KrawletClientConfig, KrawletError, type Player, type PlayerNotifications, PlayersResource, type Price, type PriceChangeLog, type RateLimit, type ReportRecords, ReportsResource, type RequestLog, type RequestLogsResponse, type Shop, type ShopChangeLog, type ShopSyncData, ShopsResource, type StorageData, StorageResource };
|
package/dist/index.d.ts
CHANGED
|
@@ -148,6 +148,45 @@ interface ShopSyncData {
|
|
|
148
148
|
}>;
|
|
149
149
|
}>;
|
|
150
150
|
}
|
|
151
|
+
type ApiKeyTier = 'free' | 'premium';
|
|
152
|
+
interface ApiKeyUsage {
|
|
153
|
+
totalRequests: number;
|
|
154
|
+
last24h: number;
|
|
155
|
+
last7d: number;
|
|
156
|
+
last30d: number;
|
|
157
|
+
blockedRequests: number;
|
|
158
|
+
avgResponseTimeMs: number | null;
|
|
159
|
+
topEndpoints: Array<{
|
|
160
|
+
path: string;
|
|
161
|
+
count: number;
|
|
162
|
+
}>;
|
|
163
|
+
}
|
|
164
|
+
interface ApiKeyInfo {
|
|
165
|
+
id: string;
|
|
166
|
+
name: string;
|
|
167
|
+
email: string | null;
|
|
168
|
+
tier: ApiKeyTier;
|
|
169
|
+
rateLimit: number;
|
|
170
|
+
isActive: boolean;
|
|
171
|
+
requestCount: number;
|
|
172
|
+
lastUsedAt: string | null;
|
|
173
|
+
createdAt: string;
|
|
174
|
+
usage?: ApiKeyUsage;
|
|
175
|
+
}
|
|
176
|
+
interface RequestLog {
|
|
177
|
+
requestId: string;
|
|
178
|
+
timestamp: string;
|
|
179
|
+
method: string;
|
|
180
|
+
path: string;
|
|
181
|
+
responseStatus: number | null;
|
|
182
|
+
responseTimeMs: number | null;
|
|
183
|
+
wasBlocked: boolean;
|
|
184
|
+
blockReason: string | null;
|
|
185
|
+
}
|
|
186
|
+
interface RequestLogsResponse {
|
|
187
|
+
count: number;
|
|
188
|
+
logs: RequestLog[];
|
|
189
|
+
}
|
|
151
190
|
interface RateLimit {
|
|
152
191
|
limit: number;
|
|
153
192
|
remaining: number;
|
|
@@ -325,6 +364,20 @@ declare class ReportsResource {
|
|
|
325
364
|
get(id: string): Promise<unknown>;
|
|
326
365
|
}
|
|
327
366
|
|
|
367
|
+
interface GetApiKeyInfoOptions {
|
|
368
|
+
usage?: boolean;
|
|
369
|
+
}
|
|
370
|
+
interface GetApiKeyLogsOptions {
|
|
371
|
+
limit?: number;
|
|
372
|
+
}
|
|
373
|
+
declare class ApiKeyResource {
|
|
374
|
+
private client;
|
|
375
|
+
constructor(client: HttpClient);
|
|
376
|
+
getInfo(options?: GetApiKeyInfoOptions): Promise<ApiKeyInfo>;
|
|
377
|
+
getUsage(): Promise<ApiKeyUsage>;
|
|
378
|
+
getLogs(options?: GetApiKeyLogsOptions): Promise<RequestLogsResponse>;
|
|
379
|
+
}
|
|
380
|
+
|
|
328
381
|
interface KrawletClientConfig {
|
|
329
382
|
baseUrl?: string;
|
|
330
383
|
apiKey?: string;
|
|
@@ -343,6 +396,7 @@ declare class KrawletClient {
|
|
|
343
396
|
readonly addresses: AddressesResource;
|
|
344
397
|
readonly storage: StorageResource;
|
|
345
398
|
readonly reports: ReportsResource;
|
|
399
|
+
readonly apiKey: ApiKeyResource;
|
|
346
400
|
constructor(config?: KrawletClientConfig);
|
|
347
401
|
getRateLimit(): RateLimit | undefined;
|
|
348
402
|
}
|
|
@@ -359,4 +413,4 @@ declare class KrawletError extends Error {
|
|
|
359
413
|
isRateLimitError(): boolean;
|
|
360
414
|
}
|
|
361
415
|
|
|
362
|
-
export { AddressesResource, type ApiResponse, type ApiResponseMeta, type ChangeLogOptions, type ChangeLogResult, type DetailedHealthResponse, ErrorCode, type ErrorResponse, HealthResource, type HealthResponse, type Item, type ItemChangeLog, type ItemChangeType, ItemsResource, type KnownAddress, type KnownAddressType, KrawletClient, type KrawletClientConfig, KrawletError, type Player, type PlayerNotifications, PlayersResource, type Price, type PriceChangeLog, type RateLimit, type ReportRecords, ReportsResource, type Shop, type ShopChangeLog, type ShopSyncData, ShopsResource, type StorageData, StorageResource };
|
|
416
|
+
export { AddressesResource, type ApiKeyInfo, ApiKeyResource, type ApiKeyTier, type ApiKeyUsage, type ApiResponse, type ApiResponseMeta, type ChangeLogOptions, type ChangeLogResult, type DetailedHealthResponse, ErrorCode, type ErrorResponse, HealthResource, type HealthResponse, type Item, type ItemChangeLog, type ItemChangeType, ItemsResource, type KnownAddress, type KnownAddressType, KrawletClient, type KrawletClientConfig, KrawletError, type Player, type PlayerNotifications, PlayersResource, type Price, type PriceChangeLog, type RateLimit, type ReportRecords, ReportsResource, type RequestLog, type RequestLogsResponse, type Shop, type ShopChangeLog, type ShopSyncData, ShopsResource, type StorageData, StorageResource };
|
package/dist/index.js
CHANGED
|
@@ -514,6 +514,90 @@ var ReportsResource = class {
|
|
|
514
514
|
}
|
|
515
515
|
};
|
|
516
516
|
|
|
517
|
+
// src/resources/apikey.ts
|
|
518
|
+
var ApiKeyResource = class {
|
|
519
|
+
constructor(client) {
|
|
520
|
+
this.client = client;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Get information about the authenticated API key
|
|
524
|
+
*
|
|
525
|
+
* @param options - Optional parameters
|
|
526
|
+
* @param options.usage - Include detailed usage statistics (default: true)
|
|
527
|
+
* @returns API key information with optional usage statistics
|
|
528
|
+
* @throws {KrawletError} If not authenticated (401)
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```typescript
|
|
532
|
+
* // Get full info with usage stats
|
|
533
|
+
* const info = await client.apiKey.getInfo();
|
|
534
|
+
*
|
|
535
|
+
* // Get basic info without usage stats
|
|
536
|
+
* const basicInfo = await client.apiKey.getInfo({ usage: false });
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
async getInfo(options) {
|
|
540
|
+
const params = {};
|
|
541
|
+
if (options?.usage !== void 0) {
|
|
542
|
+
params.usage = String(options.usage);
|
|
543
|
+
}
|
|
544
|
+
const response = await this.client.request("/v1/apikey", {
|
|
545
|
+
params: Object.keys(params).length > 0 ? params : void 0
|
|
546
|
+
});
|
|
547
|
+
return response.data;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Get detailed usage statistics for the authenticated API key
|
|
551
|
+
*
|
|
552
|
+
* @returns Detailed usage statistics including request counts and top endpoints
|
|
553
|
+
* @throws {KrawletError} If not authenticated (401)
|
|
554
|
+
*
|
|
555
|
+
* @example
|
|
556
|
+
* ```typescript
|
|
557
|
+
* const usage = await client.apiKey.getUsage();
|
|
558
|
+
* console.log(`Total requests: ${usage.totalRequests}`);
|
|
559
|
+
* console.log(`Last 24h: ${usage.last24h}`);
|
|
560
|
+
* console.log(`Blocked: ${usage.blockedRequests}`);
|
|
561
|
+
* console.log('Top endpoints:', usage.topEndpoints);
|
|
562
|
+
* ```
|
|
563
|
+
*/
|
|
564
|
+
async getUsage() {
|
|
565
|
+
const response = await this.client.request("/v1/apikey/usage");
|
|
566
|
+
return response.data;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Get recent request logs for the authenticated API key
|
|
570
|
+
*
|
|
571
|
+
* @param options - Optional parameters
|
|
572
|
+
* @param options.limit - Maximum number of logs to return (1-100, default: 50)
|
|
573
|
+
* @returns Request logs with count
|
|
574
|
+
* @throws {KrawletError} If not authenticated (401)
|
|
575
|
+
*
|
|
576
|
+
* @example
|
|
577
|
+
* ```typescript
|
|
578
|
+
* // Get default number of logs (50)
|
|
579
|
+
* const logs = await client.apiKey.getLogs();
|
|
580
|
+
*
|
|
581
|
+
* // Get last 10 requests
|
|
582
|
+
* const recentLogs = await client.apiKey.getLogs({ limit: 10 });
|
|
583
|
+
*
|
|
584
|
+
* for (const log of recentLogs.logs) {
|
|
585
|
+
* console.log(`${log.method} ${log.path} - ${log.responseStatus} (${log.responseTimeMs}ms)`);
|
|
586
|
+
* }
|
|
587
|
+
* ```
|
|
588
|
+
*/
|
|
589
|
+
async getLogs(options) {
|
|
590
|
+
const params = {};
|
|
591
|
+
if (options?.limit !== void 0) {
|
|
592
|
+
params.limit = String(options.limit);
|
|
593
|
+
}
|
|
594
|
+
const response = await this.client.request("/v1/apikey/logs", {
|
|
595
|
+
params: Object.keys(params).length > 0 ? params : void 0
|
|
596
|
+
});
|
|
597
|
+
return response.data;
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
|
|
517
601
|
// src/client.ts
|
|
518
602
|
var KrawletClient = class {
|
|
519
603
|
/**
|
|
@@ -538,6 +622,7 @@ var KrawletClient = class {
|
|
|
538
622
|
this.addresses = new AddressesResource(this.httpClient);
|
|
539
623
|
this.storage = new StorageResource(this.httpClient);
|
|
540
624
|
this.reports = new ReportsResource(this.httpClient);
|
|
625
|
+
this.apiKey = new ApiKeyResource(this.httpClient);
|
|
541
626
|
}
|
|
542
627
|
/**
|
|
543
628
|
* Get the last known rate limit information
|
|
@@ -567,6 +652,7 @@ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
|
567
652
|
})(ErrorCode || {});
|
|
568
653
|
export {
|
|
569
654
|
AddressesResource,
|
|
655
|
+
ApiKeyResource,
|
|
570
656
|
ErrorCode,
|
|
571
657
|
HealthResource,
|
|
572
658
|
ItemsResource,
|