@oasis-path/gamma-sdk 1.0.11 → 1.0.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.
- package/dist/index.js +4 -4
- package/dist/trpc/deleteFile.d.ts +5 -0
- package/dist/trpc/deleteFile.js +11 -0
- package/dist/trpc/generatePresignedUrl.d.ts +12 -0
- package/dist/trpc/generatePresignedUrl.js +13 -0
- package/dist/trpc/getFileMetadata.d.ts +16 -0
- package/dist/trpc/getFileMetadata.js +7 -0
- package/dist/trpc/listFolderFiles.d.ts +16 -0
- package/dist/trpc/listFolderFiles.js +7 -0
- package/dist/trpc/request.d.ts +5 -0
- package/dist/trpc/request.js +46 -0
- package/package.json +10 -9
package/dist/index.js
CHANGED
|
@@ -5,10 +5,10 @@ const uploadPresigned_1 = require("./methods/uploadPresigned");
|
|
|
5
5
|
const downloadPresigned_1 = require("./methods/downloadPresigned");
|
|
6
6
|
const downloadFolder_1 = require("./methods/downloadFolder");
|
|
7
7
|
const viewFile_1 = require("./methods/viewFile");
|
|
8
|
-
const listFolderFiles_1 = require("./
|
|
9
|
-
const deleteFile_1 = require("./
|
|
10
|
-
const getFileMetadata_1 = require("./
|
|
11
|
-
const generatePresignedUrl_1 = require("./
|
|
8
|
+
const listFolderFiles_1 = require("./trpc/listFolderFiles");
|
|
9
|
+
const deleteFile_1 = require("./trpc/deleteFile");
|
|
10
|
+
const getFileMetadata_1 = require("./trpc/getFileMetadata");
|
|
11
|
+
const generatePresignedUrl_1 = require("./trpc/generatePresignedUrl");
|
|
12
12
|
// Client
|
|
13
13
|
class GammaFilesClient {
|
|
14
14
|
constructor(config) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteFile = deleteFile;
|
|
4
|
+
const request_1 = require("./request");
|
|
5
|
+
async function deleteFile(fileId, apiKey, baseUrl) {
|
|
6
|
+
return (0, request_1.makeRequest)('POST', `/trpc/deleteFile`, baseUrl, apiKey, {
|
|
7
|
+
body: {
|
|
8
|
+
fileId,
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface GeneratePresignedUrlOptions {
|
|
2
|
+
fileId: string;
|
|
3
|
+
expiresIn?: number;
|
|
4
|
+
maxUsageCount?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface GeneratePresignedUrlResponse {
|
|
7
|
+
success: true;
|
|
8
|
+
token: string;
|
|
9
|
+
url: string;
|
|
10
|
+
expiresAt: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function generatePresignedUrl(options: GeneratePresignedUrlOptions, apiKey: string, baseUrl: string): Promise<GeneratePresignedUrlResponse>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generatePresignedUrl = generatePresignedUrl;
|
|
4
|
+
const request_1 = require("./request");
|
|
5
|
+
async function generatePresignedUrl(options, apiKey, baseUrl) {
|
|
6
|
+
return (0, request_1.makeRequest)('POST', `/trpc/generatePresignedUrl`, baseUrl, apiKey, {
|
|
7
|
+
body: {
|
|
8
|
+
fileId: options.fileId,
|
|
9
|
+
expiresIn: options.expiresIn,
|
|
10
|
+
maxUsageCount: options.maxUsageCount,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface FileMetadata {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
originalName: string;
|
|
5
|
+
mimeType: string;
|
|
6
|
+
size: number;
|
|
7
|
+
folderId: string;
|
|
8
|
+
uploadedBy: string;
|
|
9
|
+
createdAt: string;
|
|
10
|
+
updatedAt: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface GetFileMetadataResponse {
|
|
13
|
+
success: true;
|
|
14
|
+
file: FileMetadata;
|
|
15
|
+
}
|
|
16
|
+
export declare function getFileMetadata(fileId: string, apiKey: string, baseUrl: string): Promise<GetFileMetadataResponse>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFileMetadata = getFileMetadata;
|
|
4
|
+
const request_1 = require("./request");
|
|
5
|
+
async function getFileMetadata(fileId, apiKey, baseUrl) {
|
|
6
|
+
return (0, request_1.makeRequest)('GET', `/trpc/getFileMetadata?input=${encodeURIComponent(JSON.stringify({ fileId }))}`, baseUrl, apiKey);
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface FileMetadata {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
originalName: string;
|
|
5
|
+
mimeType: string;
|
|
6
|
+
size: number;
|
|
7
|
+
folderId: string;
|
|
8
|
+
uploadedBy: string;
|
|
9
|
+
createdAt: string;
|
|
10
|
+
updatedAt: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface ListFolderFilesResponse {
|
|
13
|
+
success: true;
|
|
14
|
+
files: FileMetadata[];
|
|
15
|
+
}
|
|
16
|
+
export declare function listFolderFiles(folderId: string, apiKey: string, baseUrl: string): Promise<ListFolderFilesResponse>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listFolderFiles = listFolderFiles;
|
|
4
|
+
const request_1 = require("./request");
|
|
5
|
+
async function listFolderFiles(folderId, apiKey, baseUrl) {
|
|
6
|
+
return (0, request_1.makeRequest)('GET', `/trpc/listFolderFiles?input=${encodeURIComponent(JSON.stringify({ folderId }))}`, baseUrl, apiKey);
|
|
7
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeRequest = makeRequest;
|
|
4
|
+
async function makeRequest(method, path, baseUrl, apiKey, options) {
|
|
5
|
+
const url = new URL(path, baseUrl);
|
|
6
|
+
if (options?.query) {
|
|
7
|
+
Object.entries(options.query).forEach(([key, value]) => {
|
|
8
|
+
if (value !== undefined && value !== null) {
|
|
9
|
+
url.searchParams.append(key, value);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
const headers = {
|
|
14
|
+
'X-API-Key': apiKey,
|
|
15
|
+
...options?.headers,
|
|
16
|
+
};
|
|
17
|
+
if (options?.body && typeof options.body === 'object' && !(options.body instanceof FormData)) {
|
|
18
|
+
headers['Content-Type'] = 'application/json';
|
|
19
|
+
}
|
|
20
|
+
const fetchOptions = {
|
|
21
|
+
method,
|
|
22
|
+
headers,
|
|
23
|
+
};
|
|
24
|
+
if (options?.body) {
|
|
25
|
+
fetchOptions.body = options.body instanceof FormData || typeof options.body === 'string'
|
|
26
|
+
? options.body
|
|
27
|
+
: JSON.stringify(options.body);
|
|
28
|
+
}
|
|
29
|
+
const response = await fetch(url.toString(), fetchOptions);
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
const errorText = await response.text();
|
|
32
|
+
let errorData;
|
|
33
|
+
try {
|
|
34
|
+
errorData = JSON.parse(errorText);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
errorData = { error: errorText };
|
|
38
|
+
}
|
|
39
|
+
throw new Error(errorData.error || errorData.message || `Request failed with status ${response.status}`);
|
|
40
|
+
}
|
|
41
|
+
const contentType = response.headers.get('content-type');
|
|
42
|
+
if (contentType?.includes('application/json')) {
|
|
43
|
+
return await response.json();
|
|
44
|
+
}
|
|
45
|
+
return response;
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oasis-path/gamma-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "TypeScript SDK for Gamma Files API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
|
|
9
|
-
"build": "tsc",
|
|
10
|
-
"watch": "tsc --watch",
|
|
11
|
-
"prepublishOnly": "pnpm run build",
|
|
12
|
-
"publish2": "pnpm run build && git add . && git commit -m 'chore: publish new version' && git push && pnpm publish --no-git-checks"
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
13
9
|
},
|
|
14
10
|
"keywords": [
|
|
15
11
|
"gamma",
|
|
@@ -30,5 +26,10 @@
|
|
|
30
26
|
},
|
|
31
27
|
"files": [
|
|
32
28
|
"dist"
|
|
33
|
-
]
|
|
34
|
-
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"watch": "tsc --watch",
|
|
33
|
+
"publish2": "pnpm run build && git add . && git commit -m 'chore: publish new version' && git push && pnpm publish --no-git-checks"
|
|
34
|
+
}
|
|
35
|
+
}
|