@oasis-path/gamma-sdk 1.0.4 → 1.0.5
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 +28 -7
- package/dist/client.d.ts +2 -2
- package/dist/methods/generatePresignedUrl.js +5 -1
- package/dist/methods/request.d.ts +1 -0
- package/dist/methods/request.js +18 -1
- package/dist/methods/viewFileByToken.d.ts +2 -1
- package/dist/methods/viewFileByToken.js +2 -1
- package/dist/types.d.ts +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -136,14 +136,26 @@ console.log('Expires at:', result.expiresAt);
|
|
|
136
136
|
|
|
137
137
|
### View File by Token
|
|
138
138
|
|
|
139
|
-
Access a file using a presigned token (no API key required):
|
|
139
|
+
Access a file using a presigned token (no API key required). Returns the file data along with response headers including caching information:
|
|
140
140
|
|
|
141
141
|
```typescript
|
|
142
|
-
const
|
|
142
|
+
const result = await client.viewFileByToken('presigned-token-here');
|
|
143
143
|
|
|
144
|
-
//
|
|
145
|
-
const buffer = Buffer.from(
|
|
144
|
+
// Access file data
|
|
145
|
+
const buffer = Buffer.from(result.data);
|
|
146
146
|
fs.writeFileSync('./viewed-file.pdf', buffer);
|
|
147
|
+
|
|
148
|
+
// Access cache headers for optimization
|
|
149
|
+
console.log('Content Type:', result.headers.contentType);
|
|
150
|
+
console.log('File Size:', result.headers.contentLength);
|
|
151
|
+
console.log('ETag:', result.headers.etag); // For cache validation
|
|
152
|
+
console.log('Cache Control:', result.headers.cacheControl);
|
|
153
|
+
console.log('Cloudflare Cache Tag:', result.headers.cfCacheTag); // File ID for consistent caching
|
|
154
|
+
|
|
155
|
+
// In browser, use the headers to implement client-side caching
|
|
156
|
+
if (result.headers.etag) {
|
|
157
|
+
localStorage.setItem(`file-etag-${result.headers.cfCacheTag}`, result.headers.etag);
|
|
158
|
+
}
|
|
147
159
|
```
|
|
148
160
|
|
|
149
161
|
## API Reference
|
|
@@ -232,14 +244,22 @@ Generate a presigned URL for temporary file access.
|
|
|
232
244
|
|
|
233
245
|
**API Key Permissions Required:** `read`, `write`, or `admin`
|
|
234
246
|
|
|
235
|
-
##### `viewFileByToken(token: string): Promise<
|
|
247
|
+
##### `viewFileByToken(token: string): Promise<ViewFileByTokenResult>`
|
|
236
248
|
|
|
237
|
-
Access a file using a presigned token (no API key required).
|
|
249
|
+
Access a file using a presigned token (no API key required). Returns file data along with response headers including caching information.
|
|
238
250
|
|
|
239
251
|
**Parameters:**
|
|
240
252
|
- `token` - Presigned token from `generatePresignedUrl`
|
|
241
253
|
|
|
242
|
-
**Returns:**
|
|
254
|
+
**Returns:** Object containing:
|
|
255
|
+
- `data` - File data as ArrayBuffer
|
|
256
|
+
- `headers` - Response headers including:
|
|
257
|
+
- `contentType` - MIME type of the file
|
|
258
|
+
- `contentLength` - Size of the file in bytes
|
|
259
|
+
- `contentDisposition` - Content disposition header (inline)
|
|
260
|
+
- `etag` - Entity tag for cache validation (based on file ID)
|
|
261
|
+
- `cacheControl` - Cache control directives (1 year immutable)
|
|
262
|
+
- `cfCacheTag` - Cloudflare cache tag (file ID for consistent caching across tokens)
|
|
243
263
|
|
|
244
264
|
**API Key Permissions Required:** None (uses token authentication)
|
|
245
265
|
|
|
@@ -260,6 +280,7 @@ import {
|
|
|
260
280
|
PresignedUrlOptions,
|
|
261
281
|
PresignedUrlResponse,
|
|
262
282
|
DownloadFileResult,
|
|
283
|
+
ViewFileByTokenResult,
|
|
263
284
|
ApiErrorResponse
|
|
264
285
|
} from '@gamma/files-sdk';
|
|
265
286
|
```
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GammaFilesClientConfig, UploadFileOptions, UploadFileResponse, ListFilesResponse, FileMetadataResponse, DeleteFileResponse, PresignedUrlOptions, PresignedUrlResponse } from './types';
|
|
1
|
+
import { GammaFilesClientConfig, UploadFileOptions, UploadFileResponse, ListFilesResponse, FileMetadataResponse, DeleteFileResponse, PresignedUrlOptions, PresignedUrlResponse, ViewFileByTokenResult } from './types';
|
|
2
2
|
export declare class GammaFilesClient {
|
|
3
3
|
private baseUrl;
|
|
4
4
|
private apiKey;
|
|
@@ -9,6 +9,6 @@ export declare class GammaFilesClient {
|
|
|
9
9
|
deleteFile(fileId: string): Promise<DeleteFileResponse>;
|
|
10
10
|
getFileMetadata(fileId: string): Promise<FileMetadataResponse>;
|
|
11
11
|
generatePresignedUrl(options: PresignedUrlOptions): Promise<PresignedUrlResponse>;
|
|
12
|
-
viewFileByToken(token: string): Promise<
|
|
12
|
+
viewFileByToken(token: string): Promise<ViewFileByTokenResult>;
|
|
13
13
|
private request;
|
|
14
14
|
}
|
|
@@ -3,8 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generatePresignedUrl = generatePresignedUrl;
|
|
4
4
|
async function generatePresignedUrl(options, request) {
|
|
5
5
|
const url = '/api/files/presigned-url';
|
|
6
|
+
const payload = {
|
|
7
|
+
...options,
|
|
8
|
+
maxUsageCount: options.maxUsageCount ?? 1
|
|
9
|
+
};
|
|
6
10
|
return request('POST', url, {
|
|
7
|
-
body: JSON.stringify(
|
|
11
|
+
body: JSON.stringify(payload),
|
|
8
12
|
headers: {
|
|
9
13
|
'Content-Type': 'application/json',
|
|
10
14
|
},
|
package/dist/methods/request.js
CHANGED
|
@@ -78,7 +78,24 @@ async function makeRequest(method, path, baseUrl, apiKey, options = {}) {
|
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
80
|
if (options.binary) {
|
|
81
|
-
|
|
81
|
+
const arrayBuffer = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
82
|
+
if (options.includeHeaders) {
|
|
83
|
+
const result = {
|
|
84
|
+
data: arrayBuffer,
|
|
85
|
+
headers: {
|
|
86
|
+
contentType: res.headers['content-type'] || '',
|
|
87
|
+
contentLength: parseInt(res.headers['content-length'] || '0', 10),
|
|
88
|
+
contentDisposition: res.headers['content-disposition'] || '',
|
|
89
|
+
etag: res.headers['etag'],
|
|
90
|
+
cacheControl: res.headers['cache-control'],
|
|
91
|
+
cfCacheTag: res.headers['cf-cache-tag'],
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
resolve(result);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
resolve(arrayBuffer);
|
|
98
|
+
}
|
|
82
99
|
}
|
|
83
100
|
else {
|
|
84
101
|
const data = JSON.parse(responseText);
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { ViewFileByTokenResult } from '../types';
|
|
2
|
+
export declare function viewFileByToken(token: string, request: <T>(method: string, path: string, options?: any) => Promise<T>): Promise<ViewFileByTokenResult>;
|
package/dist/types.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface DeleteFileResponse {
|
|
|
37
37
|
export interface PresignedUrlOptions {
|
|
38
38
|
fileId: string;
|
|
39
39
|
expiresIn?: number;
|
|
40
|
+
maxUsageCount?: number;
|
|
40
41
|
}
|
|
41
42
|
export interface PresignedUrlResponse {
|
|
42
43
|
success: true;
|
|
@@ -48,6 +49,17 @@ export interface DownloadFileResult {
|
|
|
48
49
|
file: FileMetadata;
|
|
49
50
|
data: ArrayBuffer;
|
|
50
51
|
}
|
|
52
|
+
export interface ViewFileByTokenResult {
|
|
53
|
+
data: ArrayBuffer;
|
|
54
|
+
headers: {
|
|
55
|
+
contentType: string;
|
|
56
|
+
contentLength: number;
|
|
57
|
+
contentDisposition: string;
|
|
58
|
+
etag?: string;
|
|
59
|
+
cacheControl?: string;
|
|
60
|
+
cfCacheTag?: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
51
63
|
export interface ApiErrorResponse {
|
|
52
64
|
success: false;
|
|
53
65
|
error: string;
|