@flashbacktech/flashbackclient 0.0.71 → 0.0.73

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.
@@ -38,6 +38,7 @@ export interface UpdateUnitResponse extends CreateUnitResponse {
38
38
  export interface RepoUnitInfo {
39
39
  folder: string;
40
40
  master: boolean;
41
+ unitId?: string;
41
42
  unit?: StorageUnit;
42
43
  }
43
44
  export interface CreateRepoRequest {
@@ -0,0 +1,2 @@
1
+ import { MockupAuthClient } from "./oauth2";
2
+ export { MockupAuthClient };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockupAuthClient = void 0;
4
+ const oauth2_1 = require("./oauth2");
5
+ Object.defineProperty(exports, "MockupAuthClient", { enumerable: true, get: function () { return oauth2_1.MockupAuthClient; } });
@@ -0,0 +1,19 @@
1
+ import { OAuth2Client } from 'google-auth-library';
2
+ import { ServiceCredentials } from './storage';
3
+ export declare class MockupAuthClient extends OAuth2Client {
4
+ getRequestHeaders(): Promise<{
5
+ Authorization: string;
6
+ }>;
7
+ }
8
+ export declare class FlashbackAuthClient extends OAuth2Client {
9
+ private authUrl;
10
+ private scopes;
11
+ private token;
12
+ private tokenExpiry;
13
+ private clientEmail;
14
+ private privateKey;
15
+ constructor(authUrl: string, scopes: string[], credentials: ServiceCredentials);
16
+ private fetchToken;
17
+ private ensureValidToken;
18
+ getRequestHeaders(): Promise<Record<string, string>>;
19
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FlashbackAuthClient = exports.MockupAuthClient = void 0;
7
+ const google_auth_library_1 = require("google-auth-library");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ class MockupAuthClient extends google_auth_library_1.OAuth2Client {
10
+ async getRequestHeaders() {
11
+ return {
12
+ Authorization: 'Bearer test-token',
13
+ };
14
+ }
15
+ }
16
+ exports.MockupAuthClient = MockupAuthClient;
17
+ class FlashbackAuthClient extends google_auth_library_1.OAuth2Client {
18
+ constructor(authUrl, scopes, credentials) {
19
+ super();
20
+ this.authUrl = authUrl;
21
+ this.scopes = scopes;
22
+ this.token = null;
23
+ this.tokenExpiry = null;
24
+ this.clientEmail = credentials.client_email;
25
+ this.privateKey = credentials.private_key;
26
+ }
27
+ async fetchToken() {
28
+ const response = await axios_1.default.post(this.authUrl, {
29
+ client_email: this.clientEmail,
30
+ private_key: this.privateKey,
31
+ scopes: this.scopes,
32
+ });
33
+ const { access_token, expires_in } = response.data;
34
+ this.token = access_token;
35
+ this.tokenExpiry = Date.now() + (expires_in * 1000) - 10000;
36
+ }
37
+ async ensureValidToken() {
38
+ if (!this.token || !this.tokenExpiry || Date.now() >= this.tokenExpiry) {
39
+ await this.fetchToken();
40
+ }
41
+ }
42
+ async getRequestHeaders() {
43
+ await this.ensureValidToken();
44
+ return {
45
+ Authorization: `Bearer ${this.token}`,
46
+ };
47
+ }
48
+ }
49
+ exports.FlashbackAuthClient = FlashbackAuthClient;
@@ -0,0 +1,13 @@
1
+ import { Storage, StorageOptions } from '@google-cloud/storage';
2
+ export interface ServiceCredentials {
3
+ client_email: string;
4
+ private_key: string;
5
+ }
6
+ export interface FlashbackStorageOptions extends Omit<StorageOptions, 'authClient'> {
7
+ apiEndpoint?: string;
8
+ tokenScopes?: string[];
9
+ credentials: ServiceCredentials;
10
+ }
11
+ export declare class FlashbackGCSStorage extends Storage {
12
+ constructor(opts: FlashbackStorageOptions);
13
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlashbackGCSStorage = void 0;
4
+ const storage_1 = require("@google-cloud/storage");
5
+ const oauth2_1 = require("./oauth2");
6
+ class FlashbackGCSStorage extends storage_1.Storage {
7
+ constructor(opts) {
8
+ const { credentials, apiEndpoint = 'https://gcs.us-east-1.flashback.tech', tokenScopes = ['READ', 'WRITE'], ...rest } = opts;
9
+ //const authClient = new FlashbackAuthClient(apiEndpoint + '/token', tokenScopes, credentials!);
10
+ const authClient = new oauth2_1.MockupAuthClient();
11
+ super({
12
+ ...rest,
13
+ apiEndpoint,
14
+ authClient,
15
+ useAuthWithCustomEndpoint: true,
16
+ });
17
+ }
18
+ }
19
+ exports.FlashbackGCSStorage = FlashbackGCSStorage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flashbacktech/flashbackclient",
3
- "version": "0.0.71",
3
+ "version": "0.0.73",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -25,7 +25,9 @@
25
25
  "dependencies": {
26
26
  "@aws-sdk/client-sts": "^3.777.0",
27
27
  "@stellar/stellar-sdk": "^13.0.0",
28
- "formdata-node": "^6.0.3"
28
+ "formdata-node": "^6.0.3",
29
+ "@google-cloud/storage": "^7.15.0",
30
+ "google-auth-library": "^9.15.1"
29
31
  },
30
32
  "bin": {
31
33
  "": "./dist/.min.js"
@@ -40,6 +42,11 @@
40
42
  "types": "./dist/api/index.d.ts",
41
43
  "require": "./dist/api/index.js",
42
44
  "default": "./dist/api/index.js"
45
+ },
46
+ "./gcs": {
47
+ "types": "./dist/gcs/index.d.ts",
48
+ "require": "./dist/gcs/index.js",
49
+ "default": "./dist/gcs/index.js"
43
50
  }
44
51
  },
45
52
  "files": [
@@ -47,8 +54,8 @@
47
54
  ],
48
55
  "devDependencies": {
49
56
  "@aws-sdk/client-s3": "^3.777.0",
57
+ "@aws-sdk/s3-request-presigner": "^3.782.0",
50
58
  "@eslint/js": "^8.56.0",
51
- "@google-cloud/storage": "^7.15.0",
52
59
  "@types/jest": "^29.5.14",
53
60
  "@types/node": "^22.10.1",
54
61
  "@types/node-fetch": "^2.6.12",
@@ -71,6 +78,9 @@
71
78
  ],
72
79
  "api": [
73
80
  "./dist/api/index.d.ts"
81
+ ],
82
+ "gcs": [
83
+ "./dist/gcs/index.d.ts"
74
84
  ]
75
85
  }
76
86
  }