@sudobility/ratelimit_client 0.0.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/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useRateLimits.d.ts +15 -0
- package/dist/hooks/useRateLimits.d.ts.map +1 -0
- package/dist/hooks/useRateLimits.js +88 -0
- package/dist/hooks/useRateLimits.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/network/RateLimitClient.d.ts +20 -0
- package/dist/network/RateLimitClient.d.ts.map +1 -0
- package/dist/network/RateLimitClient.js +26 -0
- package/dist/network/RateLimitClient.js.map +1 -0
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.d.ts.map +1 -0
- package/dist/network/index.js +2 -0
- package/dist/network/index.js.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/ratelimit-helpers.d.ts +7 -0
- package/dist/utils/ratelimit-helpers.d.ts.map +1 -0
- package/dist/utils/ratelimit-helpers.js +33 -0
- package/dist/utils/ratelimit-helpers.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA4B,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NetworkClient, Optional, RateLimitHistoryData, RateLimitPeriodType, RateLimitsConfigData } from '@sudobility/types';
|
|
2
|
+
import type { FirebaseIdToken } from '../types';
|
|
3
|
+
export interface UseRateLimitsReturn {
|
|
4
|
+
config: Optional<RateLimitsConfigData>;
|
|
5
|
+
history: Optional<RateLimitHistoryData>;
|
|
6
|
+
isLoadingConfig: boolean;
|
|
7
|
+
isLoadingHistory: boolean;
|
|
8
|
+
error: Optional<string>;
|
|
9
|
+
refreshConfig: (token: FirebaseIdToken) => Promise<void>;
|
|
10
|
+
refreshHistory: (periodType: RateLimitPeriodType | 'hour' | 'day' | 'month', token: FirebaseIdToken) => Promise<void>;
|
|
11
|
+
clearError: () => void;
|
|
12
|
+
reset: () => void;
|
|
13
|
+
}
|
|
14
|
+
export declare const useRateLimits: (networkClient: NetworkClient, baseUrl: string) => UseRateLimitsReturn;
|
|
15
|
+
//# sourceMappingURL=useRateLimits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRateLimits.d.ts","sourceRoot":"","sources":["../../src/hooks/useRateLimits.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,QAAQ,EACR,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAMhD,MAAM,WAAW,mBAAmB;IAElC,MAAM,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAAC;IAEvC,OAAO,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAAC;IAExC,eAAe,EAAE,OAAO,CAAC;IAEzB,gBAAgB,EAAE,OAAO,CAAC;IAE1B,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAGxB,aAAa,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAGzD,cAAc,EAAE,CACd,UAAU,EAAE,mBAAmB,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,EAC1D,KAAK,EAAE,eAAe,KACnB,OAAO,CAAC,IAAI,CAAC,CAAC;IAGnB,UAAU,EAAE,MAAM,IAAI,CAAC;IAGvB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAMD,eAAO,MAAM,aAAa,GACxB,eAAe,aAAa,EAC5B,SAAS,MAAM,KACd,mBAqHF,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import { RateLimitClient } from '../network/RateLimitClient';
|
|
3
|
+
export const useRateLimits = (networkClient, baseUrl) => {
|
|
4
|
+
const client = useMemo(() => new RateLimitClient({ baseUrl, networkClient }), [baseUrl, networkClient]);
|
|
5
|
+
const [config, setConfig] = useState(null);
|
|
6
|
+
const [history, setHistory] = useState(null);
|
|
7
|
+
const [isLoadingConfig, setIsLoadingConfig] = useState(false);
|
|
8
|
+
const [isLoadingHistory, setIsLoadingHistory] = useState(false);
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
const refreshConfig = useCallback(async (token) => {
|
|
11
|
+
setIsLoadingConfig(true);
|
|
12
|
+
setError(null);
|
|
13
|
+
try {
|
|
14
|
+
const response = await client.getRateLimitsConfig(token);
|
|
15
|
+
if (response.success && response.data) {
|
|
16
|
+
setConfig(response.data);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
setError(response.error || 'Failed to fetch rate limits config');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
const errorMessage = err instanceof Error
|
|
24
|
+
? err.message
|
|
25
|
+
: 'Failed to fetch rate limits config';
|
|
26
|
+
setError(errorMessage);
|
|
27
|
+
console.error('[useRateLimits] refreshConfig error:', errorMessage, err);
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
setIsLoadingConfig(false);
|
|
31
|
+
}
|
|
32
|
+
}, [client]);
|
|
33
|
+
const refreshHistory = useCallback(async (periodType, token) => {
|
|
34
|
+
setIsLoadingHistory(true);
|
|
35
|
+
setError(null);
|
|
36
|
+
try {
|
|
37
|
+
const response = await client.getRateLimitHistory(periodType, token);
|
|
38
|
+
if (response.success && response.data) {
|
|
39
|
+
setHistory(response.data);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
setError(response.error || 'Failed to fetch rate limit history');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
const errorMessage = err instanceof Error
|
|
47
|
+
? err.message
|
|
48
|
+
: 'Failed to fetch rate limit history';
|
|
49
|
+
setError(errorMessage);
|
|
50
|
+
console.error('[useRateLimits] refreshHistory error:', errorMessage, err);
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
setIsLoadingHistory(false);
|
|
54
|
+
}
|
|
55
|
+
}, [client]);
|
|
56
|
+
const clearError = useCallback(() => {
|
|
57
|
+
setError(null);
|
|
58
|
+
}, []);
|
|
59
|
+
const reset = useCallback(() => {
|
|
60
|
+
setConfig(null);
|
|
61
|
+
setHistory(null);
|
|
62
|
+
setError(null);
|
|
63
|
+
setIsLoadingConfig(false);
|
|
64
|
+
setIsLoadingHistory(false);
|
|
65
|
+
}, []);
|
|
66
|
+
return useMemo(() => ({
|
|
67
|
+
config,
|
|
68
|
+
history,
|
|
69
|
+
isLoadingConfig,
|
|
70
|
+
isLoadingHistory,
|
|
71
|
+
error,
|
|
72
|
+
refreshConfig,
|
|
73
|
+
refreshHistory,
|
|
74
|
+
clearError,
|
|
75
|
+
reset,
|
|
76
|
+
}), [
|
|
77
|
+
config,
|
|
78
|
+
history,
|
|
79
|
+
isLoadingConfig,
|
|
80
|
+
isLoadingHistory,
|
|
81
|
+
error,
|
|
82
|
+
refreshConfig,
|
|
83
|
+
refreshHistory,
|
|
84
|
+
clearError,
|
|
85
|
+
reset,
|
|
86
|
+
]);
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=useRateLimits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRateLimits.js","sourceRoot":"","sources":["../../src/hooks/useRateLimits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AASvD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAqC7D,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,aAA4B,EAC5B,OAAe,EACM,EAAE;IACvB,MAAM,MAAM,GAAG,OAAO,CACpB,GAAG,EAAE,CAAC,IAAI,eAAe,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,EACrD,CAAC,OAAO,EAAE,aAAa,CAAC,CACzB,CAAC;IAEF,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAiC,IAAI,CAAC,CAAC;IAC3E,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAiC,IAAI,CAAC,CAAC;IAC7E,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9D,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAmB,IAAI,CAAC,CAAC;IAK3D,MAAM,aAAa,GAAG,WAAW,CAC/B,KAAK,EAAE,KAAsB,EAAiB,EAAE;QAC9C,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACzB,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEf,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;YAC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/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,cAAc,WAAW,CAAC;AAG1B,cAAc,SAAS,CAAC;AAGxB,cAAc,SAAS,CAAC;AAIxB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { NetworkClient, RateLimitHistoryData, RateLimitPeriodType, RateLimitsConfigData } from '@sudobility/types';
|
|
2
|
+
import type { FirebaseIdToken } from '../types';
|
|
3
|
+
interface BaseResponse<T> {
|
|
4
|
+
success: boolean;
|
|
5
|
+
data?: T;
|
|
6
|
+
error?: string;
|
|
7
|
+
timestamp?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class RateLimitClient {
|
|
10
|
+
private readonly baseUrl;
|
|
11
|
+
private readonly networkClient;
|
|
12
|
+
constructor(config: {
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
networkClient: NetworkClient;
|
|
15
|
+
});
|
|
16
|
+
getRateLimitsConfig(token: FirebaseIdToken): Promise<BaseResponse<RateLimitsConfigData>>;
|
|
17
|
+
getRateLimitHistory(periodType: RateLimitPeriodType | 'hour' | 'day' | 'month', token: FirebaseIdToken): Promise<BaseResponse<RateLimitHistoryData>>;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=RateLimitClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RateLimitClient.d.ts","sourceRoot":"","sources":["../../src/network/RateLimitClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAMhD,UAAU,YAAY,CAAC,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAMD,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;gBAElC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,aAAa,CAAA;KAAE;IAa/D,mBAAmB,CACvB,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;IA2BxC,mBAAmB,CACvB,UAAU,EAAE,mBAAmB,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,EAC1D,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;CAmB/C"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { buildUrl, createAuthHeaders, handleApiError } from '../utils';
|
|
2
|
+
export class RateLimitClient {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
this.baseUrl = config.baseUrl;
|
|
5
|
+
this.networkClient = config.networkClient;
|
|
6
|
+
}
|
|
7
|
+
async getRateLimitsConfig(token) {
|
|
8
|
+
const headers = createAuthHeaders(token);
|
|
9
|
+
const response = await this.networkClient.get(buildUrl(this.baseUrl, '/ratelimits'), {
|
|
10
|
+
headers,
|
|
11
|
+
});
|
|
12
|
+
if (!response.ok || !response.data) {
|
|
13
|
+
throw handleApiError(response, 'get rate limits config');
|
|
14
|
+
}
|
|
15
|
+
return response.data;
|
|
16
|
+
}
|
|
17
|
+
async getRateLimitHistory(periodType, token) {
|
|
18
|
+
const headers = createAuthHeaders(token);
|
|
19
|
+
const response = await this.networkClient.get(buildUrl(this.baseUrl, `/ratelimits/history/${encodeURIComponent(periodType)}`), { headers });
|
|
20
|
+
if (!response.ok || !response.data) {
|
|
21
|
+
throw handleApiError(response, 'get rate limit history');
|
|
22
|
+
}
|
|
23
|
+
return response.data;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=RateLimitClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RateLimitClient.js","sourceRoot":"","sources":["../../src/network/RateLimitClient.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAgBvE,MAAM,OAAO,eAAe;IAI1B,YAAY,MAAyD;QACnE,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;IAC5C,CAAC;IAUD,KAAK,CAAC,mBAAmB,CACvB,KAAsB;QAEtB,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAEzC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAE3C,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,EAAE;YACvC,OAAO;SACR,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,MAAM,cAAc,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAaD,KAAK,CAAC,mBAAmB,CACvB,UAA0D,EAC1D,KAAsB;QAEtB,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAEzC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAG3C,QAAQ,CACN,IAAI,CAAC,OAAO,EACZ,uBAAuB,kBAAkB,CAAC,UAAU,CAAC,EAAE,CACxD,EACD,EAAE,OAAO,EAAE,CACZ,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,MAAM,cAAc,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/network/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/network/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type FirebaseIdToken = string;
|
|
2
|
+
export declare const QUERY_KEYS: {
|
|
3
|
+
readonly rateLimitsConfig: () => readonly ["ratelimit", "config"];
|
|
4
|
+
readonly rateLimitsHistory: (periodType: string) => readonly ["ratelimit", "history", string];
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAKrC,eAAO,MAAM,UAAU;;6CAEW,MAAM;CAE9B,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,gBAAgB,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE,QAAQ,CAAU;IACxD,iBAAiB,EAAE,CAAC,UAAkB,EAAE,EAAE,CACxC,CAAC,WAAW,EAAE,SAAS,EAAE,UAAU,CAAU;CACvC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,cAAc,EACd,gBAAgB,GACjB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,cAAc,EACd,gBAAgB,GACjB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FirebaseIdToken } from '../types';
|
|
2
|
+
export declare function createAuthHeaders(token: FirebaseIdToken): Record<string, string>;
|
|
3
|
+
export declare function createHeaders(): Record<string, string>;
|
|
4
|
+
export declare function buildUrl(baseUrl: string, path: string): string;
|
|
5
|
+
export declare function handleApiError(response: unknown, operation: string): Error;
|
|
6
|
+
export declare function buildQueryString(params: object): string;
|
|
7
|
+
//# sourceMappingURL=ratelimit-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ratelimit-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/ratelimit-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAKhD,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,eAAe,GACrB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMxB;AAKD,wBAAgB,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAKtD;AAKD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI9D;AAKD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK,CAK1E;AAKD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAWvD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function createAuthHeaders(token) {
|
|
2
|
+
return {
|
|
3
|
+
'Content-Type': 'application/json',
|
|
4
|
+
Accept: 'application/json',
|
|
5
|
+
Authorization: `Bearer ${token}`,
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export function createHeaders() {
|
|
9
|
+
return {
|
|
10
|
+
'Content-Type': 'application/json',
|
|
11
|
+
Accept: 'application/json',
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function buildUrl(baseUrl, path) {
|
|
15
|
+
const cleanBase = baseUrl.replace(/\/$/, '');
|
|
16
|
+
return `${cleanBase}${path}`;
|
|
17
|
+
}
|
|
18
|
+
export function handleApiError(response, operation) {
|
|
19
|
+
const resp = response;
|
|
20
|
+
const errorMessage = resp?.data?.error || resp?.data?.message || 'Unknown error';
|
|
21
|
+
return new Error(`Failed to ${operation}: ${errorMessage}`);
|
|
22
|
+
}
|
|
23
|
+
export function buildQueryString(params) {
|
|
24
|
+
const queryParams = new URLSearchParams();
|
|
25
|
+
for (const [key, value] of Object.entries(params)) {
|
|
26
|
+
if (value !== undefined && value !== null) {
|
|
27
|
+
queryParams.append(key, String(value));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const queryString = queryParams.toString();
|
|
31
|
+
return queryString ? `?${queryString}` : '';
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=ratelimit-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ratelimit-helpers.js","sourceRoot":"","sources":["../../src/utils/ratelimit-helpers.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,iBAAiB,CAC/B,KAAsB;IAEtB,OAAO;QACL,cAAc,EAAE,kBAAkB;QAClC,MAAM,EA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
|
2
|
+
"name": "@sudobility/ratelimit_client",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "React client library for Rate Limit API with TanStack Query hooks",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "restricted"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/**/*"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "bunx tsc -p tsconfig.build.json",
|
|
16
|
+
"build:watch": "bunx tsc --watch",
|
|
17
|
+
"clean": "rm -rf dist",
|
|
18
|
+
"prepublishOnly": "bun run clean && bun run build",
|
|
19
|
+
"test": "bunx vitest",
|
|
20
|
+
"test:run": "bunx vitest run",
|
|
21
|
+
"lint": "bunx eslint src --ext .ts,.tsx",
|
|
22
|
+
"lint:fix": "bunx eslint src --ext .ts,.tsx --fix",
|
|
23
|
+
"format": "bunx prettier --write src/**/*.ts",
|
|
24
|
+
"format:check": "bunx prettier --check src/**/*.ts",
|
|
25
|
+
"typecheck": "bunx tsc --noEmit"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"ratelimit",
|
|
29
|
+
"api-client",
|
|
30
|
+
"react",
|
|
31
|
+
"tanstack-query",
|
|
32
|
+
"typescript"
|
|
33
|
+
],
|
|
34
|
+
"author": "John Huang",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@sudobility/types": "^1.9.37",
|
|
38
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
39
|
+
"react": ">=18.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@eslint/js": "^9.39.2",
|
|
43
|
+
"@sudobility/di": "^1.5.8",
|
|
44
|
+
"@sudobility/types": "^1.9.37",
|
|
45
|
+
"@tanstack/react-query": "^5.90.5",
|
|
46
|
+
"@testing-library/dom": "^10.4.1",
|
|
47
|
+
"@testing-library/react": "^16.3.1",
|
|
48
|
+
"@types/node": "^24.9.1",
|
|
49
|
+
"@types/react": "^19.2.2",
|
|
50
|
+
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
51
|
+
"@typescript-eslint/parser": "^8.46.2",
|
|
52
|
+
"eslint": "^9.38.0",
|
|
53
|
+
"eslint-config-prettier": "^10.1.8",
|
|
54
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
55
|
+
"jsdom": "^27.3.0",
|
|
56
|
+
"prettier": "^3.6.2",
|
|
57
|
+
"react": "^19.2.1",
|
|
58
|
+
"react-dom": "^19.2.1",
|
|
59
|
+
"typescript": "^5.9.3",
|
|
60
|
+
"vitest": "^4.0.4"
|
|
61
|
+
}
|
|
62
|
+
}
|