@flashbacktech/flashbackclient 0.2.54 → 0.2.56
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/api/client.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ import { AiLlmStatsResponse, CreateAiLlmRequest, CreateAiLlmResponse, DeleteAiLl
|
|
|
21
21
|
import { CreatePolicyRequest, GetPoliciesQuery, GetPolicyViolationsQuery, GetPolicyViolationsResponse, GetPolicyAlertsQuery, GetPolicyAlertsResponse, PolicyDTO, UpdatePolicyRequest, PolicyValidationRequest, PolicyValidationResponse, PolicyRecommendationRequest, PolicyRecommendationResponse } from './types/ai/policy';
|
|
22
22
|
import { CreateConversationRequest, CreateConversationResponse, SendPromptRequest, SendPromptResponse, GetConversationsRequest, GetConversationsResponse, GetConversationMessagesResponse, GetConversationMessagesRequest, DeleteConversationRequest, DeleteConversationResponse } from './types/ai/conversation';
|
|
23
23
|
import { GetLinksRequest, GetLinksResponse, CreateLinkRequest, CreateLinkResponse, UpdateLinkRequest, UpdateLinkResponse, DeleteLinkResponse, GetLinkByTokenResponse } from './types/platform/links';
|
|
24
|
-
import { GetCreditsBalanceResponse, GetCreditsTransactionsRequest, GetCreditsTransactionsResponse, GetCreditsConsumptionRequest, GetCreditsConsumptionResponse, BuyCreditsPackRequest, BuyCreditsPackResponse, GetCreditsPacksResponse, GetCreditsRatesResponse } from './types/platform/credits';
|
|
24
|
+
import { GetCreditsBalanceResponse, GetCreditsTransactionsRequest, GetCreditsTransactionsResponse, GetCreditsConsumptionRequest, GetCreditsConsumptionResponse, BuyCreditsPackRequest, BuyCreditsPackResponse, GetCreditsPacksResponse, GetCreditsRatesResponse, GetCreditsMonthlyStatsRequest, GetCreditsMonthlyStatsResponse } from './types/platform/credits';
|
|
25
25
|
interface ErrorResponse {
|
|
26
26
|
message?: string;
|
|
27
27
|
[key: string]: any;
|
|
@@ -282,5 +282,7 @@ export declare class ApiClient implements IApiClient {
|
|
|
282
282
|
buyCreditsPack: (body: BuyCreditsPackRequest) => Promise<BuyCreditsPackResponse>;
|
|
283
283
|
getCreditsPacks: () => Promise<GetCreditsPacksResponse>;
|
|
284
284
|
getCreditsRates: () => Promise<GetCreditsRatesResponse>;
|
|
285
|
+
/** Get aggregated monthly credit stats for histogram (consumption, purchases, grants, balance) */
|
|
286
|
+
getCreditsMonthlyStats: (query?: GetCreditsMonthlyStatsRequest) => Promise<GetCreditsMonthlyStatsResponse>;
|
|
285
287
|
}
|
|
286
288
|
export {};
|
package/dist/api/client.js
CHANGED
|
@@ -79,18 +79,39 @@ class ApiClient {
|
|
|
79
79
|
};
|
|
80
80
|
this.makeRequest = async (path, method, data) => {
|
|
81
81
|
const isFormData = data instanceof FormData;
|
|
82
|
+
const isGetOrHead = method === 'GET' || method === 'HEAD';
|
|
83
|
+
// GET/HEAD cannot have a body: serialize plain objects as query string
|
|
84
|
+
let requestPath = path.startsWith('/') ? path.substring(1) : path;
|
|
85
|
+
let body = null;
|
|
86
|
+
if (data != null) {
|
|
87
|
+
if (isGetOrHead && !isFormData && typeof data === 'object' && data.constructor === Object) {
|
|
88
|
+
const params = new URLSearchParams();
|
|
89
|
+
for (const [k, v] of Object.entries(data)) {
|
|
90
|
+
if (v !== undefined && v !== null) {
|
|
91
|
+
params.set(k, String(v));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const qs = params.toString();
|
|
95
|
+
if (qs) {
|
|
96
|
+
requestPath += (requestPath.includes('?') ? '&' : '?') + qs;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (!isGetOrHead) {
|
|
100
|
+
body = isFormData ? data : JSON.stringify(data);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
82
103
|
const options = {
|
|
83
104
|
method,
|
|
84
105
|
headers: this.headers,
|
|
85
|
-
body
|
|
106
|
+
body,
|
|
86
107
|
};
|
|
87
|
-
if (
|
|
108
|
+
if (body && !isFormData) {
|
|
88
109
|
options.headers = {
|
|
89
110
|
...options.headers,
|
|
90
111
|
'Content-Type': 'application/json',
|
|
91
112
|
};
|
|
92
113
|
}
|
|
93
|
-
const cleanPath =
|
|
114
|
+
const cleanPath = requestPath;
|
|
94
115
|
if (this.debug) {
|
|
95
116
|
console.log(`DEBUG: ${method} ${cleanPath} ${JSON.stringify(data)}`);
|
|
96
117
|
console.log(`DEBUG: ${JSON.stringify(this.headers)}`);
|
|
@@ -831,7 +852,10 @@ class ApiClient {
|
|
|
831
852
|
return this.makeRequest('credits/balance', 'GET', null);
|
|
832
853
|
};
|
|
833
854
|
this.getCreditsTransactions = async (query) => {
|
|
834
|
-
|
|
855
|
+
console.log('[ApiClient] getCreditsTransactions called', query);
|
|
856
|
+
const result = await this.makeRequest('credits/transactions', 'GET', query);
|
|
857
|
+
console.log('[ApiClient] getCreditsTransactions result', result);
|
|
858
|
+
return result;
|
|
835
859
|
};
|
|
836
860
|
/** Consumption = transactions with direction 'out' (backend uses same endpoint) */
|
|
837
861
|
this.getCreditsConsumption = async (query) => {
|
|
@@ -846,6 +870,13 @@ class ApiClient {
|
|
|
846
870
|
this.getCreditsRates = async () => {
|
|
847
871
|
return this.makeRequest('credits/rates', 'GET', null);
|
|
848
872
|
};
|
|
873
|
+
/** Get aggregated monthly credit stats for histogram (consumption, purchases, grants, balance) */
|
|
874
|
+
this.getCreditsMonthlyStats = async (query) => {
|
|
875
|
+
console.log('[ApiClient] getCreditsMonthlyStats called', query);
|
|
876
|
+
const result = await this.makeRequest('credits/stats/monthly', 'GET', query ?? null);
|
|
877
|
+
console.log('[ApiClient] getCreditsMonthlyStats result', result);
|
|
878
|
+
return result;
|
|
879
|
+
};
|
|
849
880
|
this.baseURL = baseURL;
|
|
850
881
|
this.headers = {};
|
|
851
882
|
this.debug = false;
|
|
@@ -96,3 +96,31 @@ export interface GetCreditsRatesResponse {
|
|
|
96
96
|
error_code?: string;
|
|
97
97
|
message?: string;
|
|
98
98
|
}
|
|
99
|
+
export interface MonthlyCreditsStatsItem {
|
|
100
|
+
/** ISO date string for first day of month, e.g. "2025-01-01T00:00:00.000Z" */
|
|
101
|
+
month: string;
|
|
102
|
+
/** Credits consumed (as positive number for display, from negative transactions) */
|
|
103
|
+
consumption: number;
|
|
104
|
+
/** Credits from pack purchases */
|
|
105
|
+
purchases: number;
|
|
106
|
+
/** Credits from subscription grants */
|
|
107
|
+
grants: number;
|
|
108
|
+
/** Net change: grants + purchases - consumption */
|
|
109
|
+
balance: number;
|
|
110
|
+
}
|
|
111
|
+
export interface GetCreditsMonthlyStatsRequest {
|
|
112
|
+
/** Number of months to return (default 12, max 24) */
|
|
113
|
+
months?: number;
|
|
114
|
+
}
|
|
115
|
+
export interface GetCreditsMonthlyStatsResponse {
|
|
116
|
+
success: boolean;
|
|
117
|
+
data?: MonthlyCreditsStatsItem[];
|
|
118
|
+
totals?: {
|
|
119
|
+
consumption: number;
|
|
120
|
+
purchases: number;
|
|
121
|
+
grants: number;
|
|
122
|
+
balance: number;
|
|
123
|
+
};
|
|
124
|
+
error_code?: string;
|
|
125
|
+
message?: string;
|
|
126
|
+
}
|