tuturuuu 0.1.4 → 0.1.6
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 -0
- package/package.json +35 -18
- package/src/errors.ts +197 -0
- package/src/index.ts +90 -0
- package/src/storage.ts +1050 -0
- package/src/types.ts +93 -0
- package/dist/errors.d.ts +0 -90
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -174
- package/dist/errors.js.map +0 -1
- package/dist/index.d.ts +0 -29
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -56
- package/dist/index.js.map +0 -1
- package/dist/storage.d.ts +0 -372
- package/dist/storage.d.ts.map +0 -1
- package/dist/storage.js +0 -806
- package/dist/storage.js.map +0 -1
- package/dist/types.d.ts +0 -6
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -22
- package/dist/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ const doc = await client.documents.create({
|
|
|
42
42
|
- ✅ **Direct Uploads** - Generate signed URLs for client-side uploads without proxying
|
|
43
43
|
- ✅ **Document Management** - Create, read, update, delete workspace documents
|
|
44
44
|
- ✅ **Signed URLs** - Generate temporary shareable links for files
|
|
45
|
+
- ✅ **Image Resizing** - Request Supabase-powered image transforms on share/download
|
|
45
46
|
- ✅ **Storage Analytics** - Track usage, file counts, and limits
|
|
46
47
|
- ✅ **Type-Safe** - Full TypeScript support with type inference
|
|
47
48
|
- ✅ **Error Handling** - Comprehensive error classes for all scenarios
|
|
@@ -96,6 +97,19 @@ const result = await client.storage.upload(file, {
|
|
|
96
97
|
const blob = await client.storage.download('documents/report.pdf');
|
|
97
98
|
```
|
|
98
99
|
|
|
100
|
+
Resize an image during download:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
const blob = await client.storage.download('images/photo.png', {
|
|
104
|
+
transform: {
|
|
105
|
+
width: 320,
|
|
106
|
+
height: 180,
|
|
107
|
+
resize: 'cover',
|
|
108
|
+
quality: 80
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
99
113
|
#### Delete Files
|
|
100
114
|
|
|
101
115
|
```typescript
|
|
@@ -145,6 +159,20 @@ const { data } = await client.storage.share('documents/report.pdf', {
|
|
|
145
159
|
console.log(data.signedUrl);
|
|
146
160
|
```
|
|
147
161
|
|
|
162
|
+
Resize an image before sharing it:
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
const { data } = await client.storage.share('images/photo.png', {
|
|
166
|
+
expiresIn: 3600,
|
|
167
|
+
transform: {
|
|
168
|
+
width: 320,
|
|
169
|
+
height: 180,
|
|
170
|
+
resize: 'contain',
|
|
171
|
+
quality: 85
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
148
176
|
#### Get Analytics
|
|
149
177
|
|
|
150
178
|
```typescript
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tuturuuu",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Official TypeScript/JavaScript SDK for the Tuturuuu platform",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Tuturuuu",
|
|
@@ -15,30 +15,46 @@
|
|
|
15
15
|
},
|
|
16
16
|
"keywords": ["tuturuuu", "sdk", "api"],
|
|
17
17
|
"main": "./dist/index.js",
|
|
18
|
-
"types": "./
|
|
18
|
+
"types": "./src/index.ts",
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
|
-
"types": "./
|
|
21
|
+
"types": "./src/index.ts",
|
|
22
|
+
"bun": "./src/index.ts",
|
|
22
23
|
"import": "./dist/index.js",
|
|
23
|
-
"require": "./dist/index.js"
|
|
24
|
+
"require": "./dist/index.js",
|
|
25
|
+
"default": "./dist/index.js"
|
|
24
26
|
},
|
|
25
27
|
"./storage": {
|
|
26
|
-
"types": "./
|
|
28
|
+
"types": "./src/storage.ts",
|
|
29
|
+
"bun": "./src/storage.ts",
|
|
27
30
|
"import": "./dist/storage.js",
|
|
28
|
-
"require": "./dist/storage.js"
|
|
31
|
+
"require": "./dist/storage.js",
|
|
32
|
+
"default": "./dist/storage.js"
|
|
29
33
|
},
|
|
30
34
|
"./types": {
|
|
31
|
-
"types": "./
|
|
35
|
+
"types": "./src/types.ts",
|
|
36
|
+
"bun": "./src/types.ts",
|
|
32
37
|
"import": "./dist/types.js",
|
|
33
|
-
"require": "./dist/types.js"
|
|
38
|
+
"require": "./dist/types.js",
|
|
39
|
+
"default": "./dist/types.js"
|
|
34
40
|
},
|
|
35
41
|
"./errors": {
|
|
36
|
-
"types": "./
|
|
42
|
+
"types": "./src/errors.ts",
|
|
43
|
+
"bun": "./src/errors.ts",
|
|
37
44
|
"import": "./dist/errors.js",
|
|
38
|
-
"require": "./dist/errors.js"
|
|
45
|
+
"require": "./dist/errors.js",
|
|
46
|
+
"default": "./dist/errors.js"
|
|
39
47
|
}
|
|
40
48
|
},
|
|
41
|
-
"files": [
|
|
49
|
+
"files": [
|
|
50
|
+
"dist",
|
|
51
|
+
"src/index.ts",
|
|
52
|
+
"src/storage.ts",
|
|
53
|
+
"src/types.ts",
|
|
54
|
+
"src/errors.ts",
|
|
55
|
+
"README.md",
|
|
56
|
+
"LICENSE"
|
|
57
|
+
],
|
|
42
58
|
"publishConfig": {
|
|
43
59
|
"access": "public"
|
|
44
60
|
},
|
|
@@ -47,22 +63,23 @@
|
|
|
47
63
|
"dev": "tsc --project tsconfig.build.json --watch --incremental",
|
|
48
64
|
"type-check": "tsgo --project tsconfig.build.json",
|
|
49
65
|
"clean": "rm -rf dist .turbo",
|
|
50
|
-
"
|
|
66
|
+
"prepack": "bun run clean && bun run build",
|
|
67
|
+
"prepublishOnly": "bun run test",
|
|
51
68
|
"test": "vitest run",
|
|
52
69
|
"test:watch": "vitest"
|
|
53
70
|
},
|
|
54
71
|
"dependencies": {
|
|
55
72
|
"@tuturuuu/types": "0.2.3",
|
|
56
|
-
"zod": "^4.
|
|
73
|
+
"zod": "^4.3.6"
|
|
57
74
|
},
|
|
58
75
|
"devDependencies": {
|
|
59
|
-
"@tuturuuu/typescript-config": "
|
|
60
|
-
"@types/node": "^
|
|
61
|
-
"typescript": "^
|
|
62
|
-
"vitest": "^4.
|
|
76
|
+
"@tuturuuu/typescript-config": "workspace:*",
|
|
77
|
+
"@types/node": "^25.5.0",
|
|
78
|
+
"typescript": "^6.0.2",
|
|
79
|
+
"vitest": "^4.1.2"
|
|
63
80
|
},
|
|
64
81
|
"engines": {
|
|
65
82
|
"node": ">=18.0.0"
|
|
66
83
|
},
|
|
67
|
-
"packageManager": "bun@1.3.
|
|
84
|
+
"packageManager": "bun@1.3.11"
|
|
68
85
|
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes for the Tuturuuu SDK
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ApiErrorResponse } from './types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base error class for all SDK errors
|
|
9
|
+
*/
|
|
10
|
+
export class TuturuuuError extends Error {
|
|
11
|
+
public readonly code?: string;
|
|
12
|
+
public readonly statusCode?: number;
|
|
13
|
+
|
|
14
|
+
constructor(message: string, code?: string, statusCode?: number) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'TuturuuuError';
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.statusCode = statusCode;
|
|
19
|
+
|
|
20
|
+
// Maintains proper stack trace for where our error was thrown
|
|
21
|
+
if (Error.captureStackTrace) {
|
|
22
|
+
Error.captureStackTrace(this, this.constructor);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Authentication error (401)
|
|
29
|
+
*/
|
|
30
|
+
export class AuthenticationError extends TuturuuuError {
|
|
31
|
+
constructor(message: string, code?: string) {
|
|
32
|
+
super(message, code, 401);
|
|
33
|
+
this.name = 'AuthenticationError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Authorization error (403)
|
|
39
|
+
*/
|
|
40
|
+
export class AuthorizationError extends TuturuuuError {
|
|
41
|
+
constructor(message: string, code?: string) {
|
|
42
|
+
super(message, code, 403);
|
|
43
|
+
this.name = 'AuthorizationError';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Not found error (404)
|
|
49
|
+
*/
|
|
50
|
+
export class NotFoundError extends TuturuuuError {
|
|
51
|
+
constructor(message: string, code?: string) {
|
|
52
|
+
super(message, code, 404);
|
|
53
|
+
this.name = 'NotFoundError';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Bad request error (400)
|
|
59
|
+
*/
|
|
60
|
+
export class BadRequestError extends TuturuuuError {
|
|
61
|
+
constructor(message: string, code?: string) {
|
|
62
|
+
super(message, code, 400);
|
|
63
|
+
this.name = 'BadRequestError';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Conflict error (409)
|
|
69
|
+
*/
|
|
70
|
+
export class ConflictError extends TuturuuuError {
|
|
71
|
+
constructor(message: string, code?: string) {
|
|
72
|
+
super(message, code, 409);
|
|
73
|
+
this.name = 'ConflictError';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Rate limit error (429)
|
|
79
|
+
*/
|
|
80
|
+
export class RateLimitError extends TuturuuuError {
|
|
81
|
+
/** Number of seconds to wait before retrying (from Retry-After header) */
|
|
82
|
+
public readonly retryAfter?: number;
|
|
83
|
+
/** Unix timestamp when the rate limit resets (from X-RateLimit-Reset header) */
|
|
84
|
+
public readonly resetTime?: number;
|
|
85
|
+
|
|
86
|
+
constructor(
|
|
87
|
+
message: string,
|
|
88
|
+
options?: {
|
|
89
|
+
code?: string;
|
|
90
|
+
retryAfter?: number;
|
|
91
|
+
resetTime?: number;
|
|
92
|
+
}
|
|
93
|
+
) {
|
|
94
|
+
super(message, options?.code, 429);
|
|
95
|
+
this.name = 'RateLimitError';
|
|
96
|
+
this.retryAfter = options?.retryAfter;
|
|
97
|
+
this.resetTime = options?.resetTime;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Internal server error (500)
|
|
103
|
+
*/
|
|
104
|
+
export class InternalServerError extends TuturuuuError {
|
|
105
|
+
constructor(message: string, code?: string) {
|
|
106
|
+
super(message, code, 500);
|
|
107
|
+
this.name = 'InternalServerError';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Network error
|
|
113
|
+
*/
|
|
114
|
+
export class NetworkError extends TuturuuuError {
|
|
115
|
+
constructor(message: string) {
|
|
116
|
+
super(message, 'NETWORK_ERROR');
|
|
117
|
+
this.name = 'NetworkError';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Validation error
|
|
123
|
+
*/
|
|
124
|
+
export class ValidationError extends TuturuuuError {
|
|
125
|
+
constructor(message: string) {
|
|
126
|
+
super(message, 'VALIDATION_ERROR', 400);
|
|
127
|
+
this.name = 'ValidationError';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Options for creating a rate limit error from response headers
|
|
133
|
+
*/
|
|
134
|
+
export interface RateLimitHeaders {
|
|
135
|
+
retryAfter?: string | null;
|
|
136
|
+
resetTime?: string | null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Helper function to create appropriate error from API response
|
|
141
|
+
*/
|
|
142
|
+
export function createErrorFromResponse(
|
|
143
|
+
response: ApiErrorResponse,
|
|
144
|
+
statusCode: number,
|
|
145
|
+
rateLimitHeaders?: RateLimitHeaders
|
|
146
|
+
): TuturuuuError {
|
|
147
|
+
const { message, code } = response;
|
|
148
|
+
|
|
149
|
+
switch (statusCode) {
|
|
150
|
+
case 400:
|
|
151
|
+
return new BadRequestError(message, code);
|
|
152
|
+
case 401:
|
|
153
|
+
return new AuthenticationError(message, code);
|
|
154
|
+
case 403:
|
|
155
|
+
return new AuthorizationError(message, code);
|
|
156
|
+
case 404:
|
|
157
|
+
return new NotFoundError(message, code);
|
|
158
|
+
case 409:
|
|
159
|
+
return new ConflictError(message, code);
|
|
160
|
+
case 429:
|
|
161
|
+
return new RateLimitError(message, {
|
|
162
|
+
code,
|
|
163
|
+
retryAfter: parseIntSafe(rateLimitHeaders?.retryAfter),
|
|
164
|
+
resetTime: parseIntSafe(rateLimitHeaders?.resetTime),
|
|
165
|
+
});
|
|
166
|
+
case 500:
|
|
167
|
+
case 502:
|
|
168
|
+
case 503:
|
|
169
|
+
case 504:
|
|
170
|
+
return new InternalServerError(message, code);
|
|
171
|
+
default:
|
|
172
|
+
return new TuturuuuError(message, code, statusCode);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Safely parse a string to integer, returning undefined for invalid values
|
|
178
|
+
*/
|
|
179
|
+
function parseIntSafe(value: string | null | undefined): number | undefined {
|
|
180
|
+
if (!value) return undefined;
|
|
181
|
+
const parsed = parseInt(value, 10);
|
|
182
|
+
return Number.isNaN(parsed) || parsed < 0 ? undefined : parsed;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Type guard to check if an object is an ApiErrorResponse
|
|
187
|
+
*/
|
|
188
|
+
export function isApiErrorResponse(obj: unknown): obj is ApiErrorResponse {
|
|
189
|
+
return (
|
|
190
|
+
typeof obj === 'object' &&
|
|
191
|
+
obj !== null &&
|
|
192
|
+
'error' in obj &&
|
|
193
|
+
'message' in obj &&
|
|
194
|
+
typeof (obj as any).error === 'string' &&
|
|
195
|
+
typeof (obj as any).message === 'string'
|
|
196
|
+
);
|
|
197
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tuturuuu SDK
|
|
3
|
+
*
|
|
4
|
+
* Official TypeScript/JavaScript SDK for interacting with the Tuturuuu platform.
|
|
5
|
+
* Provides access to storage (files/folders) and documents via API keys.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Errors
|
|
11
|
+
export {
|
|
12
|
+
AuthenticationError,
|
|
13
|
+
AuthorizationError,
|
|
14
|
+
BadRequestError,
|
|
15
|
+
ConflictError,
|
|
16
|
+
createErrorFromResponse,
|
|
17
|
+
InternalServerError,
|
|
18
|
+
isApiErrorResponse,
|
|
19
|
+
NetworkError,
|
|
20
|
+
NotFoundError,
|
|
21
|
+
RateLimitError,
|
|
22
|
+
TuturuuuError,
|
|
23
|
+
ValidationError,
|
|
24
|
+
} from './errors';
|
|
25
|
+
export type { RetryConfig, TuturuuuClientConfig } from './storage';
|
|
26
|
+
// Main client
|
|
27
|
+
/**
|
|
28
|
+
* Default Tuturuuu client instance with auto-configured credentials
|
|
29
|
+
*
|
|
30
|
+
* Automatically loads from environment variables:
|
|
31
|
+
* - TUTURUUU_API_KEY (required)
|
|
32
|
+
* - TUTURUUU_BASE_URL (optional, defaults to https://tuturuuu.com/api/v1)
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { tuturuuu } from 'tuturuuu';
|
|
37
|
+
*
|
|
38
|
+
* const analytics = await tuturuuu.storage.getAnalytics();
|
|
39
|
+
* const files = await tuturuuu.storage.list({ path: 'documents' });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export {
|
|
43
|
+
DocumentsClient,
|
|
44
|
+
StorageClient,
|
|
45
|
+
TuturuuuClient,
|
|
46
|
+
tuturuuu,
|
|
47
|
+
} from './storage';
|
|
48
|
+
// Types
|
|
49
|
+
export type {
|
|
50
|
+
AnalyticsResponse,
|
|
51
|
+
ApiErrorResponse,
|
|
52
|
+
BatchShareResponse,
|
|
53
|
+
CreateDocumentData,
|
|
54
|
+
CreateFolderResponse,
|
|
55
|
+
CreateSignedUploadUrlOptions,
|
|
56
|
+
DeleteDocumentResponse,
|
|
57
|
+
DeleteResponse,
|
|
58
|
+
Document,
|
|
59
|
+
DocumentResponse,
|
|
60
|
+
DownloadOptions,
|
|
61
|
+
GetDocumentResponse,
|
|
62
|
+
ImageResizeMode,
|
|
63
|
+
ImageTransformOptions,
|
|
64
|
+
ListDocumentsOptions,
|
|
65
|
+
ListDocumentsResponse,
|
|
66
|
+
ListStorageOptions,
|
|
67
|
+
ListStorageResponse,
|
|
68
|
+
Pagination,
|
|
69
|
+
ShareOptions,
|
|
70
|
+
ShareResponse,
|
|
71
|
+
SignedUploadUrlResponse,
|
|
72
|
+
SignedUrlData,
|
|
73
|
+
StorageAnalytics,
|
|
74
|
+
StorageObject,
|
|
75
|
+
UpdateDocumentData,
|
|
76
|
+
UploadOptions,
|
|
77
|
+
UploadResponse,
|
|
78
|
+
} from './types';
|
|
79
|
+
// Zod schemas (for external validation if needed)
|
|
80
|
+
export {
|
|
81
|
+
createDocumentDataSchema,
|
|
82
|
+
createSignedUploadUrlOptionsSchema,
|
|
83
|
+
downloadOptionsSchema,
|
|
84
|
+
imageTransformOptionsSchema,
|
|
85
|
+
listDocumentsOptionsSchema,
|
|
86
|
+
listStorageOptionsSchema,
|
|
87
|
+
shareOptionsSchema,
|
|
88
|
+
updateDocumentDataSchema,
|
|
89
|
+
uploadOptionsSchema,
|
|
90
|
+
} from './types';
|