@oasis-path/gamma-sdk 1.0.10 → 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.d.ts CHANGED
@@ -58,4 +58,22 @@ export declare class GammaFilesClient {
58
58
  downloadFolder(folderId: string, token: string): Promise<ArrayBuffer>;
59
59
  viewFile(fileId: string, token: string, compressionValue?: number): Promise<ViewFileResult>;
60
60
  listFolderFiles(folderId: string): Promise<ListFolderFilesResponse>;
61
+ deleteFile(fileId: string): Promise<{
62
+ success: true;
63
+ message: string;
64
+ }>;
65
+ getFileMetadata(fileId: string): Promise<{
66
+ success: true;
67
+ file: FileMetadata;
68
+ }>;
69
+ generatePresignedUrl(options: {
70
+ fileId: string;
71
+ expiresIn?: number;
72
+ maxUsageCount?: number;
73
+ }): Promise<{
74
+ success: true;
75
+ token: string;
76
+ url: string;
77
+ expiresAt: string;
78
+ }>;
61
79
  }
package/dist/index.js CHANGED
@@ -5,7 +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("./methods/listFolderFiles");
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");
9
12
  // Client
10
13
  class GammaFilesClient {
11
14
  constructor(config) {
@@ -30,5 +33,23 @@ class GammaFilesClient {
30
33
  }
31
34
  return (0, listFolderFiles_1.listFolderFiles)(folderId, this.apiKey, this.baseUrl);
32
35
  }
36
+ async deleteFile(fileId) {
37
+ if (!this.apiKey) {
38
+ throw new Error('API key is required for deleteFile method. Please provide apiKey in the constructor config.');
39
+ }
40
+ return (0, deleteFile_1.deleteFile)(fileId, this.apiKey, this.baseUrl);
41
+ }
42
+ async getFileMetadata(fileId) {
43
+ if (!this.apiKey) {
44
+ throw new Error('API key is required for getFileMetadata method. Please provide apiKey in the constructor config.');
45
+ }
46
+ return (0, getFileMetadata_1.getFileMetadata)(fileId, this.apiKey, this.baseUrl);
47
+ }
48
+ async generatePresignedUrl(options) {
49
+ if (!this.apiKey) {
50
+ throw new Error('API key is required for generatePresignedUrl method. Please provide apiKey in the constructor config.');
51
+ }
52
+ return (0, generatePresignedUrl_1.generatePresignedUrl)(options, this.apiKey, this.baseUrl);
53
+ }
33
54
  }
34
55
  exports.GammaFilesClient = GammaFilesClient;
@@ -1,2 +1,5 @@
1
- import { DeleteFileResponse } from '../types';
2
- export declare function deleteFile(fileId: string, request: <T>(method: string, path: string, options?: any) => Promise<T>): Promise<DeleteFileResponse>;
1
+ export interface DeleteFileResponse {
2
+ success: true;
3
+ message: string;
4
+ }
5
+ export declare function deleteFile(fileId: string, apiKey: string, baseUrl: string): Promise<DeleteFileResponse>;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deleteFile = deleteFile;
4
- async function deleteFile(fileId, request) {
5
- const url = `/api/files/${fileId}`;
6
- return request('DELETE', url);
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
+ });
7
11
  }
@@ -1,2 +1,12 @@
1
- import { PresignedUrlOptions, PresignedUrlResponse } from '../types';
2
- export declare function generatePresignedUrl(options: PresignedUrlOptions, request: <T>(method: string, path: string, options?: any) => Promise<T>): Promise<PresignedUrlResponse>;
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>;
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generatePresignedUrl = generatePresignedUrl;
4
- async function generatePresignedUrl(options, request) {
5
- const url = '/api/files/presigned-url';
6
- const payload = {
7
- ...options,
8
- maxUsageCount: options.maxUsageCount ?? 1
9
- };
10
- return request('POST', url, {
11
- body: JSON.stringify(payload),
12
- headers: {
13
- 'Content-Type': 'application/json',
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,
14
11
  },
15
12
  });
16
13
  }
@@ -1,2 +1,16 @@
1
- import { FileMetadataResponse } from '../types';
2
- export declare function getFileMetadata(fileId: string, request: <T>(method: string, path: string, options?: any) => Promise<T>): Promise<FileMetadataResponse>;
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>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFileMetadata = getFileMetadata;
4
- async function getFileMetadata(fileId, request) {
5
- const url = `/api/files/${fileId}/metadata`;
6
- return request('GET', url);
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
7
  }
@@ -0,0 +1,5 @@
1
+ export interface DeleteFileResponse {
2
+ success: true;
3
+ message: string;
4
+ }
5
+ export declare function deleteFile(fileId: string, apiKey: string, baseUrl: string): Promise<DeleteFileResponse>;
@@ -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,5 @@
1
+ export declare function makeRequest<T>(method: string, path: string, baseUrl: string, apiKey: string, options?: {
2
+ body?: any;
3
+ headers?: Record<string, string>;
4
+ query?: Record<string, string>;
5
+ }): Promise<T>;
@@ -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.10",
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": { "access": "public" },
8
- "scripts": {
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
+ }