@quatrain/storage-supabase 1.1.11 → 1.1.12
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.
|
@@ -3,16 +3,17 @@
|
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
import { AbstractStorageAdapter, FileType, FileResponseLinkType, StorageParameters, DownloadFileMetaType } from '@quatrain/storage';
|
|
5
5
|
import { Readable, Stream } from 'stream';
|
|
6
|
-
import {
|
|
6
|
+
import { StorageClient } from '@supabase/storage-js';
|
|
7
7
|
export declare class SupabaseStorageAdapter extends AbstractStorageAdapter {
|
|
8
|
-
protected _client:
|
|
8
|
+
protected _client: StorageClient;
|
|
9
9
|
constructor(params: StorageParameters);
|
|
10
|
-
getDriver():
|
|
10
|
+
getDriver(): StorageClient;
|
|
11
11
|
getMetaData(file: FileType): Promise<FileType>;
|
|
12
|
+
test(): Promise<boolean>;
|
|
12
13
|
streamToBuffer(stream: Stream): Promise<Buffer>;
|
|
13
|
-
create(file: FileType, stream: Readable): Promise<FileType>;
|
|
14
|
+
create(file: FileType, stream: Readable | string): Promise<FileType>;
|
|
14
15
|
copy(file: FileType, destFile: FileType): Promise<void>;
|
|
15
|
-
move(file: FileType, destFile: FileType): Promise<
|
|
16
|
+
move(file: FileType, destFile: FileType): Promise<FileType>;
|
|
16
17
|
getUrl(file: FileType, expiresIn?: number): Promise<{
|
|
17
18
|
url: string;
|
|
18
19
|
expiresIn: number;
|
|
@@ -8,18 +8,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.SupabaseStorageAdapter = void 0;
|
|
13
16
|
const storage_1 = require("@quatrain/storage");
|
|
14
17
|
const stream_1 = require("stream");
|
|
15
|
-
const
|
|
18
|
+
const storage_js_1 = require("@supabase/storage-js");
|
|
16
19
|
const os_1 = require("os");
|
|
17
20
|
const path_1 = require("path");
|
|
21
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
18
22
|
class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
19
23
|
constructor(params) {
|
|
20
24
|
super(params);
|
|
21
|
-
this._client =
|
|
22
|
-
|
|
25
|
+
this._client = new storage_js_1.StorageClient(params.config.endpoint, {
|
|
26
|
+
apikey: params.config.secret,
|
|
27
|
+
Authorization: `Bearer ${params.config.secret}`,
|
|
28
|
+
});
|
|
29
|
+
storage_1.Storage.log(`[SSA] Supabase Storage Adapter initialized`);
|
|
23
30
|
}
|
|
24
31
|
getDriver() {
|
|
25
32
|
return this._client;
|
|
@@ -27,6 +34,23 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
27
34
|
getMetaData(file) {
|
|
28
35
|
return new Promise(() => file);
|
|
29
36
|
}
|
|
37
|
+
test() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
try {
|
|
40
|
+
const { data, error } = yield this._client.listBuckets();
|
|
41
|
+
if (error !== null) {
|
|
42
|
+
storage_1.Storage.error(`Unable to get buckets list`);
|
|
43
|
+
throw new Error(`Unable to get buckets list: ${error.message}`);
|
|
44
|
+
}
|
|
45
|
+
// Storage.info(`S3 Buckets: ${JSON.stringify(data)}`)
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
storage_1.Storage.error(`Failed to connect to storage: ${err.message}`);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
30
54
|
streamToBuffer(stream) {
|
|
31
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
56
|
return new Promise((resolve, reject) => {
|
|
@@ -39,21 +63,28 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
39
63
|
}
|
|
40
64
|
create(file, stream) {
|
|
41
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
66
|
+
console.log(stream);
|
|
67
|
+
storage_1.Storage.info(`Uploading ${file.ref} to ${file.bucket}`);
|
|
68
|
+
if (typeof stream === 'string') {
|
|
69
|
+
const { data, error } = yield this._client
|
|
70
|
+
.from(file.bucket)
|
|
71
|
+
.upload(file.ref, new Blob([node_fs_1.default.readFileSync(stream)]), {
|
|
72
|
+
// cacheControl: '3600',
|
|
73
|
+
upsert: false,
|
|
74
|
+
contentType: file.contentType,
|
|
75
|
+
});
|
|
76
|
+
if (error !== null) {
|
|
77
|
+
storage_1.Storage.error(`Unable to upload ${file.ref} to ${file.bucket}`);
|
|
78
|
+
throw new Error(`Unable to upload ${file.ref} to ${file.bucket}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
49
81
|
return file;
|
|
50
82
|
});
|
|
51
83
|
}
|
|
52
84
|
copy(file, destFile) {
|
|
53
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
storage_1.Storage.log(`Copying file ${file.ref} to ${destFile.ref} in bucket ${file.bucket}`);
|
|
55
86
|
try {
|
|
56
|
-
const response = yield this._client
|
|
87
|
+
const response = yield this._client
|
|
57
88
|
.from(file.bucket)
|
|
58
89
|
.copy(file.ref, destFile.ref, {
|
|
59
90
|
destinationBucket: destFile.bucket,
|
|
@@ -67,21 +98,23 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
67
98
|
}
|
|
68
99
|
move(file, destFile) {
|
|
69
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
101
|
+
storage_1.Storage.info(`Moving file ${file.ref} to ${destFile.ref} in same bucket ${file.bucket}`);
|
|
102
|
+
const { data, error } = yield this._client
|
|
103
|
+
.from(file.bucket)
|
|
104
|
+
.move(file.ref, destFile.ref);
|
|
105
|
+
if (error !== null) {
|
|
106
|
+
storage_1.Storage.error(`Unable to move ${file.ref} to ${destFile.ref}: ${error.message}`);
|
|
107
|
+
throw new Error(`Unable to move ${file.ref} to ${destFile.ref}`);
|
|
77
108
|
}
|
|
109
|
+
return destFile;
|
|
78
110
|
});
|
|
79
111
|
}
|
|
80
112
|
getUrl(file, expiresIn = 3600) {
|
|
81
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
|
|
114
|
+
storage_1.Storage.info(`Getting signed url for file ${file.ref} in bucket ${file.bucket}`);
|
|
115
|
+
const { data, error } = yield this._client
|
|
83
116
|
.from(file.bucket)
|
|
84
|
-
.createSignedUrl(file.
|
|
117
|
+
.createSignedUrl(file.ref, expiresIn, { download: true });
|
|
85
118
|
if (error !== null) {
|
|
86
119
|
throw new Error(`Unable to get signed url: ${error}`);
|
|
87
120
|
}
|
|
@@ -90,13 +123,12 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
90
123
|
}
|
|
91
124
|
delete(file) {
|
|
92
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
.remove([file.ref]);
|
|
126
|
+
storage_1.Storage.info(`Deleting file ${file.ref} in bucket ${file.bucket}`);
|
|
127
|
+
const { error } = yield this._client.from(file.bucket).remove([file.ref]);
|
|
96
128
|
if (error !== null) {
|
|
97
129
|
throw new Error(`Unable to delete ${file.ref}`);
|
|
98
130
|
}
|
|
99
|
-
storage_1.Storage.
|
|
131
|
+
storage_1.Storage.info(`Object ${file.ref} successfully deleted`);
|
|
100
132
|
return true;
|
|
101
133
|
});
|
|
102
134
|
}
|
|
@@ -127,7 +159,7 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
127
159
|
}
|
|
128
160
|
download(file, meta) {
|
|
129
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
const { data, error } = yield this._client
|
|
162
|
+
const { data, error } = yield this._client
|
|
131
163
|
.from(file.bucket)
|
|
132
164
|
.download(meta.path);
|
|
133
165
|
if (error !== null) {
|
|
@@ -142,7 +174,7 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
142
174
|
}
|
|
143
175
|
getUploadUrl(file, _expiresIn = 3600) {
|
|
144
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
const { data, error } = yield this._client
|
|
177
|
+
const { data, error } = yield this._client
|
|
146
178
|
.from(file.bucket)
|
|
147
179
|
.createSignedUploadUrl(file.ref);
|
|
148
180
|
if (error !== null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/storage-supabase",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.12",
|
|
4
4
|
"description": "Storage adapter for Supabase Storage",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -22,16 +22,20 @@
|
|
|
22
22
|
"typescript": "^5.1.5"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@quatrain/core": "^1.1.
|
|
26
|
-
"@quatrain/storage": "^1.1.
|
|
25
|
+
"@quatrain/core": "^1.1.19",
|
|
26
|
+
"@quatrain/storage": "^1.1.16",
|
|
27
|
+
"@supabase/storage-js": "^2.7.2",
|
|
27
28
|
"@supabase/supabase-js": "^2.45.1"
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
|
30
|
-
"test": "
|
|
31
|
+
"test-ci": "jest --runInBand",
|
|
31
32
|
"build": "tsc",
|
|
32
33
|
"wbuild": "tsc --watch",
|
|
33
34
|
"bump-to": "yarn version",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
35
|
+
"hash": "node ../../bin/hashFolder.js",
|
|
36
|
+
"hash:persist": "yarn hash > .hash_latest.txt",
|
|
37
|
+
"hash:compare": "yarn hash > .hash_newest.txt && cmp -s .hash_latest.txt .hash_newest.txt",
|
|
38
|
+
"publish": "yarn hash:compare || yarn publish:process",
|
|
39
|
+
"publish:process": "yarn version patch && yarn build && yarn npm publish --access public && yarn hash:persist"
|
|
36
40
|
}
|
|
37
41
|
}
|