@flashbacktech/flashbackclient 0.1.9 → 0.1.11
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/types/bridge.d.ts +9 -0
- package/dist/api/types/stats.d.ts +1 -1
- package/dist/gcs/oauth2.d.ts +8 -12
- package/dist/gcs/oauth2.js +49 -48
- package/package.json +1 -1
|
@@ -41,4 +41,13 @@ export interface RegisterResponse {
|
|
|
41
41
|
errorCode?: string;
|
|
42
42
|
errorMessage?: string;
|
|
43
43
|
}
|
|
44
|
+
export interface NodeInfo {
|
|
45
|
+
ip: string;
|
|
46
|
+
region: string;
|
|
47
|
+
version: string;
|
|
48
|
+
status: string;
|
|
49
|
+
latencyMs?: number;
|
|
50
|
+
lastUpdated: string;
|
|
51
|
+
url: string;
|
|
52
|
+
}
|
|
44
53
|
export {};
|
package/dist/gcs/oauth2.d.ts
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
1
1
|
import { OAuth2Client } from 'google-auth-library';
|
|
2
|
-
import { ServiceCredentials } from './storage';
|
|
3
|
-
import { GaxiosResponse } from 'gaxios';
|
|
4
2
|
export declare class MockupAuthClient extends OAuth2Client {
|
|
5
3
|
getRequestHeaders(): Promise<{
|
|
6
4
|
Authorization: string;
|
|
7
5
|
}>;
|
|
8
6
|
}
|
|
9
7
|
export declare class FlashbackAuthClient extends OAuth2Client {
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private _credentials;
|
|
8
|
+
private customTokenUri;
|
|
9
|
+
private serviceCredentials;
|
|
13
10
|
private scopes;
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
private _credentials;
|
|
12
|
+
constructor(customTokenUri: string, serviceCredentials: {
|
|
16
13
|
client_email: string;
|
|
17
14
|
private_key: string;
|
|
18
|
-
}
|
|
15
|
+
}, scopes: string[]);
|
|
19
16
|
getAccessToken(): Promise<{
|
|
20
17
|
token: string | null;
|
|
21
|
-
res:
|
|
18
|
+
res: any;
|
|
22
19
|
}>;
|
|
23
20
|
getRequestHeaders(): Promise<Record<string, string>>;
|
|
24
|
-
private ensureValidToken;
|
|
25
|
-
private fetchToken;
|
|
26
|
-
request<T = any>(opts: any): Promise<GaxiosResponse<T>>;
|
|
27
21
|
getRequestMetadata(url?: string): Promise<Record<string, string>>;
|
|
28
22
|
authorizeRequest(reqOpts: any): Promise<any>;
|
|
23
|
+
private ensureValidToken;
|
|
24
|
+
private fetchToken;
|
|
29
25
|
}
|
package/dist/gcs/oauth2.js
CHANGED
|
@@ -15,19 +15,12 @@ class MockupAuthClient extends google_auth_library_1.OAuth2Client {
|
|
|
15
15
|
}
|
|
16
16
|
exports.MockupAuthClient = MockupAuthClient;
|
|
17
17
|
class FlashbackAuthClient extends google_auth_library_1.OAuth2Client {
|
|
18
|
-
constructor(
|
|
18
|
+
constructor(customTokenUri, serviceCredentials, scopes) {
|
|
19
19
|
super();
|
|
20
|
-
this.authUrl = authUrl;
|
|
21
20
|
this._credentials = null;
|
|
22
|
-
this.
|
|
21
|
+
this.customTokenUri = customTokenUri;
|
|
22
|
+
this.serviceCredentials = serviceCredentials;
|
|
23
23
|
this.scopes = scopes;
|
|
24
|
-
console.log('FlashbackAuthClient created with URL:', authUrl);
|
|
25
|
-
}
|
|
26
|
-
async getCredentials() {
|
|
27
|
-
return {
|
|
28
|
-
client_email: this.creds.client_email,
|
|
29
|
-
private_key: this.creds.private_key,
|
|
30
|
-
};
|
|
31
24
|
}
|
|
32
25
|
async getAccessToken() {
|
|
33
26
|
await this.ensureValidToken();
|
|
@@ -42,44 +35,6 @@ class FlashbackAuthClient extends google_auth_library_1.OAuth2Client {
|
|
|
42
35
|
Authorization: `Bearer ${this._credentials?.access_token}`,
|
|
43
36
|
};
|
|
44
37
|
}
|
|
45
|
-
async ensureValidToken() {
|
|
46
|
-
const now = Date.now();
|
|
47
|
-
if (!this._credentials?.access_token ||
|
|
48
|
-
!this._credentials?.expiry_date ||
|
|
49
|
-
now >= this._credentials.expiry_date) {
|
|
50
|
-
await this.fetchToken();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
async fetchToken() {
|
|
54
|
-
const response = await axios_1.default.post(this.authUrl, {
|
|
55
|
-
client_email: this.creds.client_email,
|
|
56
|
-
private_key: this.creds.private_key,
|
|
57
|
-
scopes: this.scopes,
|
|
58
|
-
});
|
|
59
|
-
const { access_token, expires_in } = response.data;
|
|
60
|
-
this._credentials = {
|
|
61
|
-
access_token,
|
|
62
|
-
expiry_date: Date.now() + expires_in * 1000 - 10000,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
async request(opts) {
|
|
66
|
-
await this.ensureValidToken();
|
|
67
|
-
const headers = {
|
|
68
|
-
...(opts.headers || {}),
|
|
69
|
-
Authorization: `Bearer ${this._credentials?.access_token}`,
|
|
70
|
-
};
|
|
71
|
-
const response = await axios_1.default.request({
|
|
72
|
-
...opts,
|
|
73
|
-
headers,
|
|
74
|
-
});
|
|
75
|
-
return {
|
|
76
|
-
config: opts,
|
|
77
|
-
data: response.data,
|
|
78
|
-
headers: response.headers,
|
|
79
|
-
status: response.status,
|
|
80
|
-
statusText: response.statusText,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
38
|
async getRequestMetadata(url) {
|
|
84
39
|
await this.ensureValidToken();
|
|
85
40
|
return {
|
|
@@ -96,5 +51,51 @@ class FlashbackAuthClient extends google_auth_library_1.OAuth2Client {
|
|
|
96
51
|
},
|
|
97
52
|
};
|
|
98
53
|
}
|
|
54
|
+
async ensureValidToken() {
|
|
55
|
+
const now = Date.now();
|
|
56
|
+
if (!this._credentials?.access_token ||
|
|
57
|
+
!this._credentials?.expiry_date ||
|
|
58
|
+
now >= this._credentials.expiry_date) {
|
|
59
|
+
await this.fetchToken();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async fetchToken() {
|
|
63
|
+
// Create JWT assertion like the Python SDK
|
|
64
|
+
const now = Math.floor(Date.now() / 1000);
|
|
65
|
+
const header = {
|
|
66
|
+
alg: 'RS256',
|
|
67
|
+
typ: 'JWT',
|
|
68
|
+
};
|
|
69
|
+
const payload = {
|
|
70
|
+
iss: this.serviceCredentials.client_email,
|
|
71
|
+
sub: this.serviceCredentials.client_email,
|
|
72
|
+
aud: 'https://oauth2.googleapis.com/token',
|
|
73
|
+
exp: now + 3600,
|
|
74
|
+
iat: now,
|
|
75
|
+
scope: this.scopes.join(' '),
|
|
76
|
+
};
|
|
77
|
+
const encodedHeader = Buffer.from(JSON.stringify(header)).toString('base64url');
|
|
78
|
+
const encodedPayload = Buffer.from(JSON.stringify(payload)).toString('base64url');
|
|
79
|
+
const signatureInput = `${encodedHeader}.${encodedPayload}`;
|
|
80
|
+
const crypto = require('crypto');
|
|
81
|
+
const sign = crypto.createSign('RSA-SHA256');
|
|
82
|
+
sign.update(signatureInput);
|
|
83
|
+
const signature = sign.sign(this.serviceCredentials.private_key, 'base64url');
|
|
84
|
+
const assertion = `${signatureInput}.${signature}`;
|
|
85
|
+
// Request token from custom endpoint
|
|
86
|
+
const formData = new URLSearchParams();
|
|
87
|
+
formData.append('grant_type', 'urn:ietf:params:oauth:grant-type:jwt-bearer');
|
|
88
|
+
formData.append('assertion', assertion);
|
|
89
|
+
const response = await axios_1.default.post(this.customTokenUri, formData, {
|
|
90
|
+
headers: {
|
|
91
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
this._credentials = {
|
|
95
|
+
access_token: response.data.access_token,
|
|
96
|
+
expiry_date: (now + response.data.expires_in) * 1000, // Convert to milliseconds
|
|
97
|
+
token_type: response.data.token_type || 'Bearer',
|
|
98
|
+
};
|
|
99
|
+
}
|
|
99
100
|
}
|
|
100
101
|
exports.FlashbackAuthClient = FlashbackAuthClient;
|