@flashbacktech/flashbackclient 0.0.97 → 0.0.99

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.
@@ -1,7 +1,7 @@
1
1
  import { CreateUnitRequest, CreateUnitResponse, CreateRepoRequest, CreateRepoResponse, StorageUnit, CreateRepoKeyRequest, CreateRepoKeyResponse, GetUnitsResponse, GetReposResponse, GetRepoKeysResponse, UpdateUnitRequest, UpdateUnitResponse, ActionResponse, UpdateRepoRequest, UpdateRepoResponse, UpdateRepoKeyRequest, UpdateRepoKeyResponse, ValidateUnitRequest, ValidateUnitResponse, ValidateRepoUnitsRequest, ValidateRepoUnitsResponse, StorageUnitStatusResponse, GetUnitNodeStatsResponse, GetUnitNodeStatsRequest } from './types/storage';
2
2
  import { IApiClient, ProviderType } from './interfaces';
3
3
  import { ActivateResponse, DeactivateResponse, LoginBody, LoginResponse, LogoutResponse, OAuth2ResponseDTO, RefreshTokenErrorResponse, RefreshTokenResponse, RegisterBody, RegisterResponse } from './types/auth';
4
- import { StatsQueryParams, StatsResponse, NodeStatsMinuteResponse, NodeStatsDailyResponse, NodeStatsQueryParams } from './types/stats';
4
+ import { StatsQueryParams, StatsResponse, NodeStatsMinuteResponse, NodeStatsDailyResponse, NodeStatsQueryParams, UnitStatsResponse, RepoStatsResponse } from './types/stats';
5
5
  interface ErrorResponse {
6
6
  message?: string;
7
7
  [key: string]: any;
@@ -63,7 +63,13 @@ export declare class ApiClient implements IApiClient {
63
63
  private validateDateRange;
64
64
  getDailyStats: (params: StatsQueryParams) => Promise<StatsResponse>;
65
65
  getMinuteStats: (params: StatsQueryParams) => Promise<StatsResponse>;
66
- getNodeStatsMinute: (params?: NodeStatsQueryParams) => Promise<NodeStatsMinuteResponse>;
67
- getNodeStatsDaily: (params?: NodeStatsQueryParams) => Promise<NodeStatsDailyResponse>;
66
+ getNodeStatsMinute: (params: NodeStatsQueryParams) => Promise<NodeStatsMinuteResponse>;
67
+ getNodeStatsDaily: (params: NodeStatsQueryParams) => Promise<NodeStatsDailyResponse>;
68
+ getRepoStats: (params?: {
69
+ repoId?: string[];
70
+ }) => Promise<RepoStatsResponse>;
71
+ getUnitStats: (params?: {
72
+ unitId?: string[];
73
+ }) => Promise<UnitStatsResponse>;
68
74
  }
69
75
  export {};
@@ -137,7 +137,9 @@ class ApiClient {
137
137
  return this.makeRequest('auth/github', 'POST', { code });
138
138
  };
139
139
  this.refreshGoogleToken = async (refreshToken) => {
140
- return this.makeRequest('auth/google/refresh', 'POST', { refresh_token: refreshToken });
140
+ return this.makeRequest('auth/google/refresh', 'POST', {
141
+ refresh_token: refreshToken,
142
+ });
141
143
  };
142
144
  this.exchangeGoogleCode = async (code) => {
143
145
  return this.makeRequest('auth/google/exchange', 'POST', { code });
@@ -250,27 +252,53 @@ class ApiClient {
250
252
  };
251
253
  this.getNodeStatsMinute = async (params) => {
252
254
  const queryParams = new URLSearchParams();
253
- if (params && params.unitId && params.unitId.length > 0) {
255
+ if (params.unitId.length > 0) {
254
256
  queryParams.append('unitId', params.unitId.join(','));
255
257
  }
256
- const response = await this.makeRequest(`stats/nodes/minute${queryParams.toString() ? `?${queryParams.toString()}` : ''}`, 'GET', null);
258
+ if (params.startDate) {
259
+ queryParams.append('startDate', params.startDate.toISOString());
260
+ }
261
+ if (params.endDate) {
262
+ queryParams.append('endDate', params.endDate.toISOString());
263
+ }
264
+ const response = await this.makeRequest(`stats/nodes/minute?${queryParams.toString() ? `?${queryParams.toString()}` : ''}`, 'GET', null);
257
265
  // Process the response to convert lastUpdated strings to Date objects
258
- const processedData = response.data.map(item => ({
266
+ const processedData = response.data.map((item) => ({
259
267
  ...item,
260
- lastUpdated: new Date(item.lastUpdated)
268
+ lastUpdated: new Date(item.lastUpdated),
261
269
  }));
262
270
  return {
263
271
  ...response,
264
- data: processedData
272
+ data: processedData,
265
273
  };
266
274
  };
267
275
  this.getNodeStatsDaily = async (params) => {
268
276
  const queryParams = new URLSearchParams();
269
- if (params && params.unitId && params.unitId.length > 0) {
277
+ if (params.unitId.length > 0) {
270
278
  queryParams.append('unitId', params.unitId.join(','));
271
279
  }
280
+ if (params.startDate) {
281
+ queryParams.append('startDate', params.startDate.toISOString());
282
+ }
283
+ if (params.endDate) {
284
+ queryParams.append('endDate', params.endDate.toISOString());
285
+ }
272
286
  return this.makeRequest(`stats/nodes/daily${queryParams.toString() ? `?${queryParams.toString()}` : ''}`, 'GET', null);
273
287
  };
288
+ this.getRepoStats = async (params) => {
289
+ const queryParams = new URLSearchParams();
290
+ if (params && params.repoId && params.repoId.length > 0) {
291
+ queryParams.append('repoId', params.repoId.join(','));
292
+ }
293
+ return this.makeRequest(`repo/stats${queryParams.toString() ? `?${queryParams.toString()}` : ''}`, 'GET', null);
294
+ };
295
+ this.getUnitStats = async (params) => {
296
+ const queryParams = new URLSearchParams();
297
+ if (params && params.unitId && params.unitId.length > 0) {
298
+ queryParams.append('unitId', params.unitId.join(','));
299
+ }
300
+ return this.makeRequest(`unit/stats${queryParams.toString() ? `?${queryParams.toString()}` : ''}`, 'GET', null);
301
+ };
274
302
  this.baseURL = baseURL;
275
303
  this.headers = {};
276
304
  this.debug = false;
@@ -1,6 +1,6 @@
1
- import { StorageUnit, CreateUnitRequest, CreateUnitResponse, CreateRepoRequest, CreateRepoResponse, CreateRepoKeyRequest, CreateRepoKeyResponse, GetUnitsResponse, GetReposResponse, GetRepoKeysResponse, UpdateUnitRequest, UpdateUnitResponse, ActionResponse, UpdateRepoResponse, UpdateRepoRequest, UpdateRepoKeyRequest, UpdateRepoKeyResponse, ValidateUnitRequest, ValidateUnitResponse, ValidateRepoUnitsRequest, ValidateRepoUnitsResponse, GetUnitNodeStatsRequest, GetUnitNodeStatsResponse } from "./types/storage";
2
- import { RegisterBody, LoginBody, RegisterResponse, LoginResponse, LogoutResponse, ActivateResponse, DeactivateResponse, RefreshTokenResponse, RefreshTokenErrorResponse } from "./types/auth";
3
- import { StatsQueryParams, StatsResponse, NodeStatsMinuteResponse, NodeStatsDailyResponse, NodeStatsQueryParams } from "./types/stats";
1
+ import { StorageUnit, CreateUnitRequest, CreateUnitResponse, CreateRepoRequest, CreateRepoResponse, CreateRepoKeyRequest, CreateRepoKeyResponse, GetUnitsResponse, GetReposResponse, GetRepoKeysResponse, UpdateUnitRequest, UpdateUnitResponse, ActionResponse, UpdateRepoResponse, UpdateRepoRequest, UpdateRepoKeyRequest, UpdateRepoKeyResponse, ValidateUnitRequest, ValidateUnitResponse, ValidateRepoUnitsRequest, ValidateRepoUnitsResponse, GetUnitNodeStatsRequest, GetUnitNodeStatsResponse } from './types/storage';
2
+ import { RegisterBody, LoginBody, RegisterResponse, LoginResponse, LogoutResponse, ActivateResponse, DeactivateResponse, RefreshTokenResponse, RefreshTokenErrorResponse } from './types/auth';
3
+ import { StatsQueryParams, StatsResponse, NodeStatsMinuteResponse, NodeStatsDailyResponse, NodeStatsQueryParams } from './types/stats';
4
4
  export declare enum ProviderType {
5
5
  GOOGLE = "GOOGLE",
6
6
  GITHUB = "GITHUB",
@@ -1,4 +1,4 @@
1
- import { ProviderType } from "../interfaces";
1
+ import { ProviderType } from '../interfaces';
2
2
  export interface AuthState {
3
3
  user: {
4
4
  email: string;
@@ -49,5 +49,26 @@ export interface NodeStatsDailyData {
49
49
  version: string;
50
50
  }
51
51
  export interface NodeStatsQueryParams {
52
- unitId?: string[];
52
+ unitId: string[];
53
+ startDate?: Date;
54
+ endDate?: Date;
55
+ }
56
+ export interface RepoStatsResponse {
57
+ success: boolean;
58
+ stats: {
59
+ repoId: string;
60
+ totalUploadBytes: string;
61
+ totalDownloadBytes: string;
62
+ totalSizeChange: string;
63
+ }[];
64
+ }
65
+ export interface UnitStatsResponse {
66
+ success: boolean;
67
+ stats: {
68
+ unitId: string;
69
+ totalCount: string;
70
+ totalUploadBytes: string;
71
+ totalDownloadBytes: string;
72
+ totalSizeChange: string;
73
+ }[];
53
74
  }
@@ -1,4 +1,4 @@
1
- import { NodeStatusInfo, NodeStatusType } from "./bridge";
1
+ import { NodeStatusInfo, NodeStatusType } from './bridge';
2
2
  export declare enum StorageType {
3
3
  S3 = "S3",
4
4
  GCS = "GCS",
@@ -1,3 +1,3 @@
1
- import { FlashbackAuthClient } from "./oauth2";
2
- import { FlashbackGCSStorage, FlashbackStorageOptions } from "./storage";
1
+ import { FlashbackAuthClient } from './oauth2';
2
+ import { FlashbackGCSStorage, FlashbackStorageOptions } from './storage';
3
3
  export { FlashbackAuthClient, FlashbackGCSStorage, FlashbackStorageOptions };
@@ -33,7 +33,7 @@ class FlashbackAuthClient extends google_auth_library_1.OAuth2Client {
33
33
  await this.ensureValidToken();
34
34
  return {
35
35
  token: this._credentials?.access_token || null,
36
- res: null
36
+ res: null,
37
37
  };
38
38
  }
39
39
  async getRequestHeaders() {
@@ -44,7 +44,9 @@ class FlashbackAuthClient extends google_auth_library_1.OAuth2Client {
44
44
  }
45
45
  async ensureValidToken() {
46
46
  const now = Date.now();
47
- if (!this._credentials?.access_token || !this._credentials?.expiry_date || now >= this._credentials.expiry_date) {
47
+ if (!this._credentials?.access_token ||
48
+ !this._credentials?.expiry_date ||
49
+ now >= this._credentials.expiry_date) {
48
50
  await this.fetchToken();
49
51
  }
50
52
  }
@@ -57,7 +59,7 @@ class FlashbackAuthClient extends google_auth_library_1.OAuth2Client {
57
59
  const { access_token, expires_in } = response.data;
58
60
  this._credentials = {
59
61
  access_token,
60
- expiry_date: Date.now() + (expires_in * 1000) - 10000,
62
+ expiry_date: Date.now() + expires_in * 1000 - 10000,
61
63
  };
62
64
  }
63
65
  async request(opts) {
@@ -96,9 +96,10 @@ class FlashbackGCSStorage extends storage_1.Storage {
96
96
  expires,
97
97
  expiresPeriodInSeconds,
98
98
  accessibleAt: accessibleAt.toISOString(),
99
- contentType
99
+ contentType,
100
100
  });
101
- if (expiresPeriodInSeconds > 604800) { // 7 days in seconds
101
+ if (expiresPeriodInSeconds > 604800) {
102
+ // 7 days in seconds
102
103
  throw new Error('Max allowed expiration is seven days (604800 seconds).');
103
104
  }
104
105
  const extensionHeaders = {};
@@ -108,12 +109,11 @@ class FlashbackGCSStorage extends storage_1.Storage {
108
109
  }
109
110
  // Sort headers once and use the same order for both signedHeaders and canonicalHeaders
110
111
  const sortedHeaderKeys = Object.keys(extensionHeaders)
111
- .map(header => header.toLowerCase())
112
+ .map((header) => header.toLowerCase())
112
113
  .sort();
113
114
  const signedHeaders = sortedHeaderKeys.join(';');
114
- const canonicalHeaders = sortedHeaderKeys
115
- .map(key => `${key}:${extensionHeaders[key.toLowerCase()]}`)
116
- .join('\n') + '\n';
115
+ const canonicalHeaders = sortedHeaderKeys.map((key) => `${key}:${extensionHeaders[key.toLowerCase()]}`).join('\n') +
116
+ '\n';
117
117
  const datestamp = accessibleAt.toISOString().split('T')[0];
118
118
  const credentialScope = `${datestamp}/auto/storage/goog4_request`;
119
119
  const credential = `${this.credentials.client_email}/${credentialScope}`;
@@ -162,7 +162,9 @@ class FlashbackGCSStorage extends storage_1.Storage {
162
162
  sign.update(stringToSign);
163
163
  const signature = sign.sign(this.credentials.private_key, 'hex');
164
164
  this.doLog('Generated Signature:', signature);
165
- return [`${this.apiEndpoint}/${cfg.file.bucket.name}/${cfg.file.name}?${canonicalQueryString}&X-Goog-Signature=${signature}`];
165
+ return [
166
+ `${this.apiEndpoint}/${cfg.file.bucket.name}/${cfg.file.name}?${canonicalQueryString}&X-Goog-Signature=${signature}`,
167
+ ];
166
168
  }
167
169
  }
168
170
  exports.FlashbackGCSStorage = FlashbackGCSStorage;
@@ -18,6 +18,6 @@ function generateBlockID(blockIDPrefix, blockIndex) {
18
18
  blockIDPrefix = blockIDPrefix.slice(0, maxAllowedBlockIDPrefixLength);
19
19
  }
20
20
  const res = blockIDPrefix +
21
- blockIndex.toString().padStart(maxSourceStringLength - blockIDPrefix.length, "0");
22
- return Buffer.from(res).toString("base64");
21
+ blockIndex.toString().padStart(maxSourceStringLength - blockIDPrefix.length, '0');
22
+ return Buffer.from(res).toString('base64');
23
23
  }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@flashbacktech/flashbackclient",
3
- "version": "0.0.97",
3
+ "version": "0.0.99",
4
+ "type": "module",
4
5
  "publishConfig": {
5
6
  "access": "public"
6
7
  },