@flashbacktech/flashbackclient 0.0.74 → 0.0.75
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/gcs/storage.d.ts +3 -1
- package/dist/gcs/storage.js +31 -12
- package/package.json +1 -1
package/dist/gcs/storage.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface FlashbackStorageOptions extends Omit<StorageOptions, 'authClien
|
|
|
10
10
|
}
|
|
11
11
|
export interface SignedUrlOptions {
|
|
12
12
|
version: 'v4';
|
|
13
|
-
action: 'write' | 'read';
|
|
13
|
+
action: 'write' | 'read' | 'delete';
|
|
14
14
|
expires: number;
|
|
15
15
|
contentType: string;
|
|
16
16
|
file: File;
|
|
@@ -18,5 +18,7 @@ export interface SignedUrlOptions {
|
|
|
18
18
|
export declare class FlashbackGCSStorage extends Storage {
|
|
19
19
|
protected credentials: ServiceCredentials;
|
|
20
20
|
constructor(opts: FlashbackStorageOptions);
|
|
21
|
+
cleanup(): void;
|
|
22
|
+
bucket(name: string): import("@google-cloud/storage").Bucket;
|
|
21
23
|
getSignedUrl(cfg: SignedUrlOptions): Promise<[string]>;
|
|
22
24
|
}
|
package/dist/gcs/storage.js
CHANGED
|
@@ -7,21 +7,11 @@ exports.FlashbackGCSStorage = void 0;
|
|
|
7
7
|
const storage_1 = require("@google-cloud/storage");
|
|
8
8
|
const oauth2_1 = require("./oauth2");
|
|
9
9
|
const crypto_1 = __importDefault(require("crypto"));
|
|
10
|
+
const originalRequest = require('gaxios').instance.request;
|
|
10
11
|
class FlashbackGCSStorage extends storage_1.Storage {
|
|
11
12
|
constructor(opts) {
|
|
12
13
|
const { credentials, apiEndpoint = 'https://gcs.us-east-1.flashback.tech', tokenScopes = ['READ', 'WRITE'], ...rest } = opts;
|
|
13
14
|
const authClient = new oauth2_1.FlashbackAuthClient(apiEndpoint + '/token', tokenScopes, credentials);
|
|
14
|
-
// Intercept Gaxios instance creation
|
|
15
|
-
const originalRequest = require('gaxios').instance.request;
|
|
16
|
-
require('gaxios').instance.request = async function (opts) {
|
|
17
|
-
// Add auth headers to all requests
|
|
18
|
-
const headers = await authClient.getRequestHeaders();
|
|
19
|
-
opts.headers = {
|
|
20
|
-
...(opts.headers || {}),
|
|
21
|
-
...headers,
|
|
22
|
-
};
|
|
23
|
-
return originalRequest.call(this, opts);
|
|
24
|
-
};
|
|
25
15
|
super({
|
|
26
16
|
...rest,
|
|
27
17
|
apiEndpoint,
|
|
@@ -33,6 +23,23 @@ class FlashbackGCSStorage extends storage_1.Storage {
|
|
|
33
23
|
},
|
|
34
24
|
});
|
|
35
25
|
this.credentials = credentials;
|
|
26
|
+
// Intercept Gaxios instance creation
|
|
27
|
+
require('gaxios').instance.request = async function (opts) {
|
|
28
|
+
// Add auth headers to all requests
|
|
29
|
+
const headers = await authClient.getRequestHeaders();
|
|
30
|
+
opts.headers = {
|
|
31
|
+
...(opts.headers || {}),
|
|
32
|
+
...headers,
|
|
33
|
+
};
|
|
34
|
+
return originalRequest.call(this, opts);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
cleanup() {
|
|
38
|
+
require('gaxios').instance.request = originalRequest;
|
|
39
|
+
}
|
|
40
|
+
// Override the bucket method to ensure we pass the auth client
|
|
41
|
+
bucket(name) {
|
|
42
|
+
return super.bucket(name);
|
|
36
43
|
}
|
|
37
44
|
// Override the getSignedUrl method
|
|
38
45
|
async getSignedUrl(cfg) {
|
|
@@ -76,8 +83,20 @@ class FlashbackGCSStorage extends storage_1.Storage {
|
|
|
76
83
|
const canonicalQueryString = Object.entries(queryParams)
|
|
77
84
|
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
78
85
|
.join('&');
|
|
86
|
+
let method;
|
|
87
|
+
switch (action) {
|
|
88
|
+
case 'read':
|
|
89
|
+
method = 'GET';
|
|
90
|
+
break;
|
|
91
|
+
case 'delete':
|
|
92
|
+
method = 'DELETE';
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
method = 'PUT';
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
79
98
|
const canonicalRequest = [
|
|
80
|
-
|
|
99
|
+
method,
|
|
81
100
|
`/${cfg.file.bucket.name}/${cfg.file.name}`,
|
|
82
101
|
canonicalQueryString,
|
|
83
102
|
canonicalHeaders,
|