@lark-apaas/dataloom 0.1.1-alpha.0
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/README.md +3 -0
- package/lib/DataloomClient.d.ts +31 -0
- package/lib/DataloomClient.d.ts.map +1 -0
- package/lib/DataloomClient.js +39 -0
- package/lib/RateLimiter.d.ts +15 -0
- package/lib/RateLimiter.d.ts.map +1 -0
- package/lib/RateLimiter.js +31 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +3 -0
- package/lib/service/index.d.ts +9 -0
- package/lib/service/index.d.ts.map +1 -0
- package/lib/service/index.js +11 -0
- package/lib/service/services/DataloomServiceBase.d.ts +17 -0
- package/lib/service/services/DataloomServiceBase.d.ts.map +1 -0
- package/lib/service/services/DataloomServiceBase.js +126 -0
- package/lib/service/services/session-service/index.d.ts +45 -0
- package/lib/service/services/session-service/index.d.ts.map +1 -0
- package/lib/service/services/session-service/index.js +111 -0
- package/lib/service/services/session-service/types.d.ts +34 -0
- package/lib/service/services/session-service/types.d.ts.map +1 -0
- package/lib/service/services/session-service/types.js +0 -0
- package/lib/service/services/types.d.ts +12 -0
- package/lib/service/services/types.d.ts.map +1 -0
- package/lib/service/services/types.js +14 -0
- package/lib/service/services/user-service/index.d.ts +9 -0
- package/lib/service/services/user-service/index.d.ts.map +1 -0
- package/lib/service/services/user-service/index.js +60 -0
- package/lib/service/services/user-service/types.d.ts +51 -0
- package/lib/service/services/user-service/types.d.ts.map +1 -0
- package/lib/service/services/user-service/types.js +0 -0
- package/lib/service/utils/helpers.d.ts +8 -0
- package/lib/service/utils/helpers.d.ts.map +1 -0
- package/lib/service/utils/helpers.js +18 -0
- package/lib/service/utils/logger.d.ts +15 -0
- package/lib/service/utils/logger.d.ts.map +1 -0
- package/lib/service/utils/logger.js +18 -0
- package/lib/service/utils/trace-id.d.ts +45 -0
- package/lib/service/utils/trace-id.d.ts.map +1 -0
- package/lib/service/utils/trace-id.js +20 -0
- package/lib/service/utils/types.d.ts +49 -0
- package/lib/service/utils/types.d.ts.map +1 -0
- package/lib/service/utils/types.js +7 -0
- package/lib/storage/StorageClient.d.ts +22 -0
- package/lib/storage/StorageClient.d.ts.map +1 -0
- package/lib/storage/StorageClient.js +11 -0
- package/lib/storage/index.d.ts +4 -0
- package/lib/storage/index.d.ts.map +1 -0
- package/lib/storage/index.js +4 -0
- package/lib/storage/libs/constants.d.ts +4 -0
- package/lib/storage/libs/constants.d.ts.map +1 -0
- package/lib/storage/libs/constants.js +5 -0
- package/lib/storage/libs/errors.d.ts +24 -0
- package/lib/storage/libs/errors.d.ts.map +1 -0
- package/lib/storage/libs/errors.js +39 -0
- package/lib/storage/libs/fetch.d.ts +24 -0
- package/lib/storage/libs/fetch.d.ts.map +1 -0
- package/lib/storage/libs/fetch.js +139 -0
- package/lib/storage/libs/helpers.d.ts +18 -0
- package/lib/storage/libs/helpers.d.ts.map +1 -0
- package/lib/storage/libs/helpers.js +57 -0
- package/lib/storage/libs/index.d.ts +5 -0
- package/lib/storage/libs/index.d.ts.map +1 -0
- package/lib/storage/libs/index.js +4 -0
- package/lib/storage/libs/types.d.ts +205 -0
- package/lib/storage/libs/types.d.ts.map +1 -0
- package/lib/storage/libs/types.js +0 -0
- package/lib/storage/libs/version.d.ts +2 -0
- package/lib/storage/libs/version.d.ts.map +1 -0
- package/lib/storage/libs/version.js +2 -0
- package/lib/storage/packages/StorageBucketApi.d.ts +121 -0
- package/lib/storage/packages/StorageBucketApi.d.ts.map +1 -0
- package/lib/storage/packages/StorageBucketApi.js +135 -0
- package/lib/storage/packages/StorageFileApi.d.ts +190 -0
- package/lib/storage/packages/StorageFileApi.d.ts.map +1 -0
- package/lib/storage/packages/StorageFileApi.js +378 -0
- package/lib/storage/utils/logger.d.ts +15 -0
- package/lib/storage/utils/logger.d.ts.map +1 -0
- package/lib/storage/utils/logger.js +18 -0
- package/lib/storage/utils/trace-id.d.ts +45 -0
- package/lib/storage/utils/trace-id.d.ts.map +1 -0
- package/lib/storage/utils/trace-id.js +20 -0
- package/lib/utils/constants.d.ts +7 -0
- package/lib/utils/constants.d.ts.map +1 -0
- package/lib/utils/constants.js +33 -0
- package/lib/utils/fetch.d.ts +6 -0
- package/lib/utils/fetch.d.ts.map +1 -0
- package/lib/utils/fetch.js +22 -0
- package/lib/utils/helpers.d.ts +5 -0
- package/lib/utils/helpers.d.ts.map +1 -0
- package/lib/utils/helpers.js +17 -0
- package/lib/utils/types.d.ts +34 -0
- package/lib/utils/types.d.ts.map +1 -0
- package/lib/utils/types.js +0 -0
- package/lib/utils/version.d.ts +2 -0
- package/lib/utils/version.d.ts.map +1 -0
- package/lib/utils/version.js +2 -0
- package/package.json +34 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const THIRTY_DAYS_IN_SECONDS = 2592000;
|
|
2
|
+
const resolveFetch = (customFetch)=>{
|
|
3
|
+
let _fetch;
|
|
4
|
+
_fetch = customFetch ? customFetch : fetch;
|
|
5
|
+
return (...args)=>_fetch(...args);
|
|
6
|
+
};
|
|
7
|
+
const resolveResponse = async ()=>Response;
|
|
8
|
+
const recursiveToCamel = (item)=>{
|
|
9
|
+
if (Array.isArray(item)) return item.map((el)=>recursiveToCamel(el));
|
|
10
|
+
if ('function' == typeof item || item !== Object(item)) return item;
|
|
11
|
+
const result = {};
|
|
12
|
+
Object.entries(item).forEach(([key, value])=>{
|
|
13
|
+
const newKey = key.replace(/([-_][a-z])/gi, (c)=>c.toUpperCase().replace(/[-_]/g, ''));
|
|
14
|
+
result[newKey] = recursiveToCamel(value);
|
|
15
|
+
});
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
const isPlainObject = (value)=>{
|
|
19
|
+
if ('object' != typeof value || null === value) return false;
|
|
20
|
+
const prototype = Object.getPrototypeOf(value);
|
|
21
|
+
return (null === prototype || prototype === Object.prototype || null === Object.getPrototypeOf(prototype)) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
22
|
+
};
|
|
23
|
+
const getUpdateFileSize = (file)=>{
|
|
24
|
+
if ('undefined' != typeof File && file instanceof File) return file.size.toString();
|
|
25
|
+
if (file instanceof Blob) return file.size.toString();
|
|
26
|
+
if (file instanceof URLSearchParams) return file.size.toString();
|
|
27
|
+
if ('string' == typeof file) return file.length.toString();
|
|
28
|
+
if (ArrayBuffer.isView(file)) return file.byteLength.toString();
|
|
29
|
+
if (file instanceof ArrayBuffer) return file.byteLength.toString();
|
|
30
|
+
return '0';
|
|
31
|
+
};
|
|
32
|
+
const toValidExpiresIn = (expiresIn)=>{
|
|
33
|
+
if (expiresIn < 1) return 1;
|
|
34
|
+
if (expiresIn > THIRTY_DAYS_IN_SECONDS) return THIRTY_DAYS_IN_SECONDS;
|
|
35
|
+
return expiresIn;
|
|
36
|
+
};
|
|
37
|
+
const transformFilePayload = (file)=>({
|
|
38
|
+
...file,
|
|
39
|
+
buckets: {
|
|
40
|
+
allowed_mime_types: file?.buckets?.allowed_mime_types ?? [],
|
|
41
|
+
created_at: file?.buckets?.created_at ?? '',
|
|
42
|
+
file_size_limit: file?.buckets?.file_size_limit ?? 0,
|
|
43
|
+
id: file?.buckets?.id ?? '',
|
|
44
|
+
name: file?.buckets?.name ?? '',
|
|
45
|
+
public: file?.buckets?.public ?? false,
|
|
46
|
+
updated_at: file?.buckets?.updated_at ?? '',
|
|
47
|
+
updated_by: file?.buckets?.updated_by ?? '',
|
|
48
|
+
owner: file?.buckets?.created_by ?? ''
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const sanitizeFileName = (fileName)=>{
|
|
52
|
+
const illegalChars = /[\x00-\x1F\x7F:"\\/*?<>|,;]/g;
|
|
53
|
+
return encodeURIComponent(fileName.replace(illegalChars, '')) || 'download_file';
|
|
54
|
+
};
|
|
55
|
+
const VOLC_ENGINE_URL_REGEX = /^https:\/\/[\w-]+\.tos-cn-beijing\.volces\.com\/.+/;
|
|
56
|
+
const checkIsVolcEngineUrl = (url)=>VOLC_ENGINE_URL_REGEX.test(url);
|
|
57
|
+
export { checkIsVolcEngineUrl, getUpdateFileSize, isPlainObject, recursiveToCamel, resolveFetch, resolveResponse, sanitizeFileName, toValidExpiresIn, transformFilePayload };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/libs/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
export interface DataloomServiceError {
|
|
2
|
+
code: number;
|
|
3
|
+
details: string;
|
|
4
|
+
hint: string | null;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
export type OnRequestErrorType = DataloomServiceError & {
|
|
8
|
+
status: number;
|
|
9
|
+
statusText: string;
|
|
10
|
+
};
|
|
11
|
+
export type BucketType = 'STANDARD' | 'ANALYTICS';
|
|
12
|
+
export interface Bucket {
|
|
13
|
+
id: string;
|
|
14
|
+
type?: BucketType;
|
|
15
|
+
name: string;
|
|
16
|
+
owner: string;
|
|
17
|
+
file_size_limit?: number;
|
|
18
|
+
allowed_mime_types?: string[];
|
|
19
|
+
created_at: string;
|
|
20
|
+
updated_at: string;
|
|
21
|
+
public: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface TosMetaData {
|
|
24
|
+
cacheControl: string;
|
|
25
|
+
contentLength: number;
|
|
26
|
+
eTag: string;
|
|
27
|
+
lastModified: string;
|
|
28
|
+
mimeType: string;
|
|
29
|
+
}
|
|
30
|
+
export interface UploadFileData {
|
|
31
|
+
id: string;
|
|
32
|
+
file_path: string;
|
|
33
|
+
bucket_id: string;
|
|
34
|
+
download_url: string;
|
|
35
|
+
}
|
|
36
|
+
export interface FileObject {
|
|
37
|
+
name: string;
|
|
38
|
+
bucket_id: string;
|
|
39
|
+
owner: string;
|
|
40
|
+
id: string;
|
|
41
|
+
updated_at: string;
|
|
42
|
+
created_at: string;
|
|
43
|
+
created_by: string;
|
|
44
|
+
updated_by: string;
|
|
45
|
+
last_accessed_at?: string;
|
|
46
|
+
metadata: Record<string, any>;
|
|
47
|
+
buckets: Bucket;
|
|
48
|
+
}
|
|
49
|
+
export interface FileObjectV2 {
|
|
50
|
+
id: string;
|
|
51
|
+
version: string;
|
|
52
|
+
name: string;
|
|
53
|
+
bucket_id: string;
|
|
54
|
+
updated_at: string;
|
|
55
|
+
created_at: string;
|
|
56
|
+
last_accessed_at: string;
|
|
57
|
+
size?: number;
|
|
58
|
+
cache_control?: string;
|
|
59
|
+
content_type?: string;
|
|
60
|
+
etag?: string;
|
|
61
|
+
last_modified?: string;
|
|
62
|
+
metadata?: Record<string, any>;
|
|
63
|
+
}
|
|
64
|
+
export interface SortBy {
|
|
65
|
+
column?: string;
|
|
66
|
+
order?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface FileOptions {
|
|
69
|
+
/**
|
|
70
|
+
* The number of seconds the asset is cached in the browser and in the Supabase CDN. This is set in the `Cache-Control: max-age=<seconds>` header. Defaults to 3600 seconds.
|
|
71
|
+
*/
|
|
72
|
+
cacheControl?: string | number;
|
|
73
|
+
/**
|
|
74
|
+
* the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
|
|
75
|
+
*/
|
|
76
|
+
contentType?: string;
|
|
77
|
+
/**
|
|
78
|
+
* When upsert is set to true, the file is overwritten if it exists. When set to false, an error is thrown if the object already exists. Defaults to false.
|
|
79
|
+
*/
|
|
80
|
+
upsert?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The duplex option is a string parameter that enables or disables duplex streaming, allowing for both reading and writing data in the same stream. It can be passed as an option to the fetch() method.
|
|
83
|
+
*/
|
|
84
|
+
duplex?: string;
|
|
85
|
+
/**
|
|
86
|
+
* The metadata option is an object that allows you to store additional information about the file. This information can be used to filter and search for files. The metadata object can contain any key-value pairs you want to store.
|
|
87
|
+
*/
|
|
88
|
+
metadata?: Record<string, any>;
|
|
89
|
+
/**
|
|
90
|
+
* Optionally add extra headers
|
|
91
|
+
*/
|
|
92
|
+
headers?: Record<string, string>;
|
|
93
|
+
}
|
|
94
|
+
export interface FileOptionsV2 {
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
*/
|
|
98
|
+
filePath?: string;
|
|
99
|
+
/**
|
|
100
|
+
* The number of seconds the asset is cached in the browser and in the Supabase CDN. This is set in the `Cache-Control: max-age=<seconds>` header.
|
|
101
|
+
*/
|
|
102
|
+
cacheControl?: string | number;
|
|
103
|
+
/**
|
|
104
|
+
* the `Content-Type` header value.
|
|
105
|
+
*/
|
|
106
|
+
contentType?: string;
|
|
107
|
+
/**
|
|
108
|
+
* When upsert is set to true, the file is overwritten if it exists. When set to false, an error is thrown if the object already exists. Defaults to false.
|
|
109
|
+
*/
|
|
110
|
+
upsert?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* The `Content-Disposition` resposne header value when downloading the file.
|
|
113
|
+
*/
|
|
114
|
+
contentDisposition?: string;
|
|
115
|
+
}
|
|
116
|
+
export interface PreUploadBody {
|
|
117
|
+
bucket_id: string;
|
|
118
|
+
file_size: string;
|
|
119
|
+
upsert?: boolean;
|
|
120
|
+
file_path?: string;
|
|
121
|
+
content_disposition?: string;
|
|
122
|
+
content_type?: string;
|
|
123
|
+
file_name?: string;
|
|
124
|
+
}
|
|
125
|
+
export interface DestinationOptions {
|
|
126
|
+
destinationBucket?: string;
|
|
127
|
+
}
|
|
128
|
+
export interface SearchOptions {
|
|
129
|
+
/**
|
|
130
|
+
* The number of files you want to be returned.
|
|
131
|
+
* @default 100
|
|
132
|
+
*/
|
|
133
|
+
limit?: number;
|
|
134
|
+
/**
|
|
135
|
+
* The starting position.
|
|
136
|
+
*/
|
|
137
|
+
offset?: number;
|
|
138
|
+
/**
|
|
139
|
+
* The column to sort by. Can be any column inside a FileObject.
|
|
140
|
+
*/
|
|
141
|
+
sortBy?: SortBy;
|
|
142
|
+
/**
|
|
143
|
+
* The search string to filter files by.
|
|
144
|
+
*/
|
|
145
|
+
search?: string;
|
|
146
|
+
}
|
|
147
|
+
export interface SearchV2Options {
|
|
148
|
+
limit?: number;
|
|
149
|
+
prefix?: string;
|
|
150
|
+
cursor?: string;
|
|
151
|
+
with_delimiter?: boolean;
|
|
152
|
+
}
|
|
153
|
+
export interface SearchV2Result {
|
|
154
|
+
hasNext: boolean;
|
|
155
|
+
folders: {
|
|
156
|
+
name: string;
|
|
157
|
+
}[];
|
|
158
|
+
objects: FileObject[];
|
|
159
|
+
}
|
|
160
|
+
export interface FetchParameters {
|
|
161
|
+
/**
|
|
162
|
+
* Pass in an AbortController's signal to cancel the request.
|
|
163
|
+
*/
|
|
164
|
+
signal?: AbortSignal;
|
|
165
|
+
}
|
|
166
|
+
export interface TransformOptions {
|
|
167
|
+
/**
|
|
168
|
+
* The width of the image in pixels.
|
|
169
|
+
*/
|
|
170
|
+
width?: number;
|
|
171
|
+
/**
|
|
172
|
+
* The height of the image in pixels.
|
|
173
|
+
*/
|
|
174
|
+
height?: number;
|
|
175
|
+
/**
|
|
176
|
+
* The resize mode can be cover, contain or fill. Defaults to cover.
|
|
177
|
+
* Cover resizes the image to maintain it's aspect ratio while filling the entire width and height.
|
|
178
|
+
* Contain resizes the image to maintain it's aspect ratio while fitting the entire image within the width and height.
|
|
179
|
+
* Fill resizes the image to fill the entire width and height. If the object's aspect ratio does not match the width and height, the image will be stretched to fit.
|
|
180
|
+
*/
|
|
181
|
+
resize?: 'cover' | 'contain' | 'fill';
|
|
182
|
+
/**
|
|
183
|
+
* Set the quality of the returned image.
|
|
184
|
+
* A number from 20 to 100, with 100 being the highest quality.
|
|
185
|
+
* Defaults to 80
|
|
186
|
+
*/
|
|
187
|
+
quality?: number;
|
|
188
|
+
/**
|
|
189
|
+
* Specify the format of the image requested.
|
|
190
|
+
*
|
|
191
|
+
* When using 'origin' we force the format to be the same as the original image.
|
|
192
|
+
* When this option is not passed in, images are optimized to modern image formats like Webp.
|
|
193
|
+
*/
|
|
194
|
+
format?: 'origin';
|
|
195
|
+
}
|
|
196
|
+
export interface Metadata {
|
|
197
|
+
name: string;
|
|
198
|
+
}
|
|
199
|
+
type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` : S;
|
|
200
|
+
export type Camelize<T> = {
|
|
201
|
+
[K in keyof T as CamelCase<Extract<K, string>>]: T[K];
|
|
202
|
+
};
|
|
203
|
+
export type FileBody = ArrayBuffer | ArrayBufferView | Blob | File | FormData | ReadableStream<Uint8Array> | URLSearchParams | string;
|
|
204
|
+
export {};
|
|
205
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/storage/libs/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,kBAAkB,GAAG,oBAAoB,GAAG;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;AAElD,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CA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MAAM,CAAC,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,QAAQ,GAChB,WAAW,GACX,eAAe,GACf,IAAI,GACJ,IAAI,GACJ,QAAQ,GACR,cAAc,CAAC,UAAU,CAAC,GAC1B,eAAe,GACf,MAAM,CAAC"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/storage/libs/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { type StorageError } from '../libs/errors';
|
|
2
|
+
import { type Fetch } from '../libs/fetch';
|
|
3
|
+
import type { Bucket, BucketType, OnRequestErrorType } from '../libs/types';
|
|
4
|
+
import type { StorageClientOptions } from '../StorageClient';
|
|
5
|
+
export default class StorageBucketApi {
|
|
6
|
+
protected url: string;
|
|
7
|
+
protected headers: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
10
|
+
protected appId?: string;
|
|
11
|
+
protected fetch: Fetch;
|
|
12
|
+
protected loggerEnabled?: boolean;
|
|
13
|
+
protected onRequestError?: (error: OnRequestErrorType) => void;
|
|
14
|
+
constructor(url: string, headers?: {
|
|
15
|
+
[key: string]: string;
|
|
16
|
+
}, fetch?: Fetch, opts?: StorageClientOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves the details of all Storage buckets within an existing project.
|
|
19
|
+
*/
|
|
20
|
+
listBuckets(): Promise<{
|
|
21
|
+
data: Bucket[];
|
|
22
|
+
error: null;
|
|
23
|
+
} | {
|
|
24
|
+
data: null;
|
|
25
|
+
error: StorageError;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves the details of an existing Storage bucket.
|
|
29
|
+
*
|
|
30
|
+
* @param id The unique identifier of the bucket you would like to retrieve.
|
|
31
|
+
*/
|
|
32
|
+
getBucket(id: string): Promise<{
|
|
33
|
+
data: Bucket;
|
|
34
|
+
error: null;
|
|
35
|
+
} | {
|
|
36
|
+
data: null;
|
|
37
|
+
error: StorageError;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new Storage bucket
|
|
41
|
+
*
|
|
42
|
+
* @param id A unique identifier for the bucket you are creating.
|
|
43
|
+
* @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations. By default, buckets are private.
|
|
44
|
+
* @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
|
|
45
|
+
* The global file size limit takes precedence over this value.
|
|
46
|
+
* The default value is null, which doesn't set a per bucket file size limit.
|
|
47
|
+
* @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
|
|
48
|
+
* The default value is null, which allows files with all mime types to be uploaded.
|
|
49
|
+
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
|
|
50
|
+
* @returns newly created bucket id
|
|
51
|
+
* @param options.type (private-beta) specifies the bucket type. see `BucketType` for more details.
|
|
52
|
+
* - default bucket type is `STANDARD`
|
|
53
|
+
*/
|
|
54
|
+
createBucket(id: string, options?: {
|
|
55
|
+
public: boolean;
|
|
56
|
+
fileSizeLimit?: number | string | null;
|
|
57
|
+
allowedMimeTypes?: string[] | null;
|
|
58
|
+
type?: BucketType;
|
|
59
|
+
}): Promise<{
|
|
60
|
+
data: Pick<Bucket, 'name'>;
|
|
61
|
+
error: null;
|
|
62
|
+
} | {
|
|
63
|
+
data: null;
|
|
64
|
+
error: StorageError;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* Updates a Storage bucket
|
|
68
|
+
*
|
|
69
|
+
* @param id A unique identifier for the bucket you are updating.
|
|
70
|
+
* @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations.
|
|
71
|
+
* @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
|
|
72
|
+
* The global file size limit takes precedence over this value.
|
|
73
|
+
* The default value is null, which doesn't set a per bucket file size limit.
|
|
74
|
+
* @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
|
|
75
|
+
* The default value is null, which allows files with all mime types to be uploaded.
|
|
76
|
+
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
|
|
77
|
+
*/
|
|
78
|
+
updateBucket(id: string, options: {
|
|
79
|
+
public: boolean;
|
|
80
|
+
fileSizeLimit?: number | string | null;
|
|
81
|
+
allowedMimeTypes?: string[] | null;
|
|
82
|
+
}): Promise<{
|
|
83
|
+
data: {
|
|
84
|
+
message: string;
|
|
85
|
+
};
|
|
86
|
+
error: null;
|
|
87
|
+
} | {
|
|
88
|
+
data: null;
|
|
89
|
+
error: StorageError;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* Removes all objects inside a single bucket.
|
|
93
|
+
*
|
|
94
|
+
* @param id The unique identifier of the bucket you would like to empty.
|
|
95
|
+
*/
|
|
96
|
+
emptyBucket(id: string): Promise<{
|
|
97
|
+
data: {
|
|
98
|
+
message: string;
|
|
99
|
+
};
|
|
100
|
+
error: null;
|
|
101
|
+
} | {
|
|
102
|
+
data: null;
|
|
103
|
+
error: StorageError;
|
|
104
|
+
}>;
|
|
105
|
+
/**
|
|
106
|
+
* Deletes an existing bucket. A bucket can't be deleted with existing objects inside it.
|
|
107
|
+
* You must first `empty()` the bucket.
|
|
108
|
+
*
|
|
109
|
+
* @param id The unique identifier of the bucket you would like to delete.
|
|
110
|
+
*/
|
|
111
|
+
deleteBucket(id: string): Promise<{
|
|
112
|
+
data: {
|
|
113
|
+
message: string;
|
|
114
|
+
};
|
|
115
|
+
error: null;
|
|
116
|
+
} | {
|
|
117
|
+
data: null;
|
|
118
|
+
error: StorageError;
|
|
119
|
+
}>;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=StorageBucketApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageBucketApi.d.ts","sourceRoot":"","sources":["../../../src/storage/packages/StorageBucketApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,KAAK,KAAK,EAA0B,MAAM,eAAe,CAAC;AAEnE,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC7C,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;IACvB,SAAS,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IAClC,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;gBAG7D,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAO,EACvC,KAAK,CAAC,EAAE,KAAK,EACb,IAAI,CAAC,EAAE,oBAAoB;IAa7B;;OAEG;IACG,WAAW,IAAI,OAAO,CACxB;QACE,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,KAAK,EAAE,IAAI,CAAC;KACb,GACD;QACE,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,EAAE,YAAY,CAAC;KACrB,CACJ;IAeD;;;;OAIG;IACG,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAChC;QACE,IAAI,EAAE,MAAM,CAAC;QAC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ACG,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CACnC;QACE,IAAI,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;QAC1B,KAAK,EAAE,IAAI,CAAC;KACb,GACD;QACE,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,EAAE,YAAY,CAAC;KACrB,CACJ;CAiBF"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { DEFAULT_HEADERS } from "../libs/constants.js";
|
|
2
|
+
import { isStorageError } from "../libs/errors.js";
|
|
3
|
+
import { get, post, put, remove } from "../libs/fetch.js";
|
|
4
|
+
import { resolveFetch } from "../libs/helpers.js";
|
|
5
|
+
class StorageBucketApi {
|
|
6
|
+
constructor(url, headers = {}, fetch, opts){
|
|
7
|
+
this.url = url;
|
|
8
|
+
this.headers = {
|
|
9
|
+
...DEFAULT_HEADERS,
|
|
10
|
+
...headers
|
|
11
|
+
};
|
|
12
|
+
this.fetch = resolveFetch(fetch);
|
|
13
|
+
this.onRequestError = opts?.onRequestError;
|
|
14
|
+
this.appId = opts?.appId;
|
|
15
|
+
if (opts?.enableLogger) this.loggerEnabled = true;
|
|
16
|
+
}
|
|
17
|
+
async listBuckets() {
|
|
18
|
+
try {
|
|
19
|
+
const data = await get(this.fetch, `${this.url}/bucket`, {
|
|
20
|
+
headers: this.headers
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
data,
|
|
24
|
+
error: null
|
|
25
|
+
};
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (isStorageError(error)) return {
|
|
28
|
+
data: null,
|
|
29
|
+
error
|
|
30
|
+
};
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async getBucket(id) {
|
|
35
|
+
try {
|
|
36
|
+
const data = await get(this.fetch, `${this.url}/bucket/${id}`, {
|
|
37
|
+
headers: this.headers
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
data,
|
|
41
|
+
error: null
|
|
42
|
+
};
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (isStorageError(error)) return {
|
|
45
|
+
data: null,
|
|
46
|
+
error
|
|
47
|
+
};
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async createBucket(id, options = {
|
|
52
|
+
public: false
|
|
53
|
+
}) {
|
|
54
|
+
try {
|
|
55
|
+
const data = await post(this.fetch, `${this.url}/bucket`, {
|
|
56
|
+
id,
|
|
57
|
+
name: id,
|
|
58
|
+
type: options.type,
|
|
59
|
+
public: options.public,
|
|
60
|
+
file_size_limit: options.fileSizeLimit,
|
|
61
|
+
allowed_mime_types: options.allowedMimeTypes
|
|
62
|
+
}, {
|
|
63
|
+
headers: this.headers
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
data,
|
|
67
|
+
error: null
|
|
68
|
+
};
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (isStorageError(error)) return {
|
|
71
|
+
data: null,
|
|
72
|
+
error
|
|
73
|
+
};
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async updateBucket(id, options) {
|
|
78
|
+
try {
|
|
79
|
+
const data = await put(this.fetch, `${this.url}/bucket/${id}`, {
|
|
80
|
+
id,
|
|
81
|
+
name: id,
|
|
82
|
+
public: options.public,
|
|
83
|
+
file_size_limit: options.fileSizeLimit,
|
|
84
|
+
allowed_mime_types: options.allowedMimeTypes
|
|
85
|
+
}, {
|
|
86
|
+
headers: this.headers
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
data,
|
|
90
|
+
error: null
|
|
91
|
+
};
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (isStorageError(error)) return {
|
|
94
|
+
data: null,
|
|
95
|
+
error
|
|
96
|
+
};
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async emptyBucket(id) {
|
|
101
|
+
try {
|
|
102
|
+
const data = await post(this.fetch, `${this.url}/bucket/${id}/empty`, {}, {
|
|
103
|
+
headers: this.headers
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
data,
|
|
107
|
+
error: null
|
|
108
|
+
};
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (isStorageError(error)) return {
|
|
111
|
+
data: null,
|
|
112
|
+
error
|
|
113
|
+
};
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async deleteBucket(id) {
|
|
118
|
+
try {
|
|
119
|
+
const data = await remove(this.fetch, `${this.url}/bucket/${id}`, {}, {
|
|
120
|
+
headers: this.headers
|
|
121
|
+
});
|
|
122
|
+
return {
|
|
123
|
+
data,
|
|
124
|
+
error: null
|
|
125
|
+
};
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (isStorageError(error)) return {
|
|
128
|
+
data: null,
|
|
129
|
+
error
|
|
130
|
+
};
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export { StorageBucketApi as default };
|