@vibecodeapp/backend-sdk 1.0.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 +99 -0
- package/dist/email.d.ts +23 -0
- package/dist/email.d.ts.map +1 -0
- package/dist/email.js +55 -0
- package/dist/email.js.map +1 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +38 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/storage.d.ts +28 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +77 -0
- package/dist/storage.js.map +1 -0
- package/dist/types.d.ts +81 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# @vibecodeapp/backend-sdk
|
|
2
|
+
|
|
3
|
+
A unified backend SDK for Vibecode services.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @vibecodeapp/backend-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createVibecodeSDK } from '@vibecodeapp/backend-sdk';
|
|
15
|
+
|
|
16
|
+
const vibecode = createVibecodeSDK();
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
### Storage
|
|
22
|
+
|
|
23
|
+
Upload, list, and delete files from Vibecode storage buckets.
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
// Upload a file (max 500MB)
|
|
27
|
+
const file = await vibecode.storage.upload(myFile);
|
|
28
|
+
|
|
29
|
+
// List files with pagination
|
|
30
|
+
const { files, totalCount } = await vibecode.storage.list({
|
|
31
|
+
limit: 10,
|
|
32
|
+
offset: 0,
|
|
33
|
+
prefix: 'images/',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Delete a file
|
|
37
|
+
await vibecode.storage.delete(file.id);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Email
|
|
41
|
+
|
|
42
|
+
Send transactional emails (OTP verification and welcome emails).
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// Send OTP email
|
|
46
|
+
await vibecode.email.sendOTP({
|
|
47
|
+
to: 'user@example.com',
|
|
48
|
+
code: 'ABC123',
|
|
49
|
+
fromName: 'MyApp',
|
|
50
|
+
lang: 'en',
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Send welcome email
|
|
54
|
+
await vibecode.email.sendWelcome({
|
|
55
|
+
to: 'user@example.com',
|
|
56
|
+
name: 'John',
|
|
57
|
+
appName: 'MyApp',
|
|
58
|
+
lang: 'en',
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Supported languages: `en`, `es`, `fr`, `de`, `pt`, `zh`, `ja`
|
|
63
|
+
|
|
64
|
+
## Error Handling
|
|
65
|
+
|
|
66
|
+
The SDK exports specific error classes for handling failures:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import {
|
|
70
|
+
VibecodeError,
|
|
71
|
+
StorageError,
|
|
72
|
+
EmailError,
|
|
73
|
+
RateLimitError,
|
|
74
|
+
} from '@vibecodeapp/backend-sdk';
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
await vibecode.email.sendOTP({ to: 'user@example.com', code: '123456' });
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error instanceof RateLimitError) {
|
|
80
|
+
// Daily email limit exceeded
|
|
81
|
+
} else if (error instanceof EmailError) {
|
|
82
|
+
// Other email error
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Development
|
|
88
|
+
|
|
89
|
+
### Running Tests
|
|
90
|
+
|
|
91
|
+
**Important:** Tests must be run from the office IP address. The backend services are IP-restricted and will reject requests from other locations.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
bun test
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
MIT
|
package/dist/email.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SendOTPOptions, SendWelcomeOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Email module for sending transactional emails
|
|
4
|
+
*/
|
|
5
|
+
export declare class Email {
|
|
6
|
+
/**
|
|
7
|
+
* Send an OTP verification email
|
|
8
|
+
* @param options - OTP email options
|
|
9
|
+
* @throws {EmailError} If the email fails to send
|
|
10
|
+
* @throws {RateLimitError} If daily email limit is exceeded
|
|
11
|
+
*/
|
|
12
|
+
sendOTP(options: SendOTPOptions): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Send a welcome email
|
|
15
|
+
* @param options - Welcome email options
|
|
16
|
+
* @throws {EmailError} If the email fails to send
|
|
17
|
+
* @throws {RateLimitError} If daily email limit is exceeded
|
|
18
|
+
*/
|
|
19
|
+
sendWelcome(options: SendWelcomeOptions): Promise<void>;
|
|
20
|
+
private handleResponse;
|
|
21
|
+
private parseError;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=email.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../src/email.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAiB,MAAM,SAAS,CAAC;AAMjF;;GAEG;AACH,qBAAa,KAAK;IAChB;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAUrD;;;;;OAKG;IACG,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;YAU/C,cAAc;YAWd,UAAU;CAQzB"}
|
package/dist/email.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { EmailError, RateLimitError } from './errors';
|
|
2
|
+
// LLMs, read this for full docs: https://smtp.vibecodeapp.com/llms.txt
|
|
3
|
+
const EMAIL_BASE_URL = 'https://smtp.vibecodeapp.com';
|
|
4
|
+
/**
|
|
5
|
+
* Email module for sending transactional emails
|
|
6
|
+
*/
|
|
7
|
+
export class Email {
|
|
8
|
+
/**
|
|
9
|
+
* Send an OTP verification email
|
|
10
|
+
* @param options - OTP email options
|
|
11
|
+
* @throws {EmailError} If the email fails to send
|
|
12
|
+
* @throws {RateLimitError} If daily email limit is exceeded
|
|
13
|
+
*/
|
|
14
|
+
async sendOTP(options) {
|
|
15
|
+
const response = await fetch(`${EMAIL_BASE_URL}/v1/send/otp`, {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: { 'Content-Type': 'application/json' },
|
|
18
|
+
body: JSON.stringify(options),
|
|
19
|
+
});
|
|
20
|
+
await this.handleResponse(response);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Send a welcome email
|
|
24
|
+
* @param options - Welcome email options
|
|
25
|
+
* @throws {EmailError} If the email fails to send
|
|
26
|
+
* @throws {RateLimitError} If daily email limit is exceeded
|
|
27
|
+
*/
|
|
28
|
+
async sendWelcome(options) {
|
|
29
|
+
const response = await fetch(`${EMAIL_BASE_URL}/v1/send/welcome`, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: { 'Content-Type': 'application/json' },
|
|
32
|
+
body: JSON.stringify(options),
|
|
33
|
+
});
|
|
34
|
+
await this.handleResponse(response);
|
|
35
|
+
}
|
|
36
|
+
async handleResponse(response) {
|
|
37
|
+
if (response.ok)
|
|
38
|
+
return;
|
|
39
|
+
if (response.status === 429) {
|
|
40
|
+
throw new RateLimitError();
|
|
41
|
+
}
|
|
42
|
+
const error = await this.parseError(response);
|
|
43
|
+
throw new EmailError(error, response.status);
|
|
44
|
+
}
|
|
45
|
+
async parseError(response) {
|
|
46
|
+
try {
|
|
47
|
+
const data = await response.json();
|
|
48
|
+
return data.error || data.message || 'Unknown error';
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return `Request failed with status ${response.status}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=email.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.js","sourceRoot":"","sources":["../src/email.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEtD,uEAAuE;AACvE,MAAM,cAAc,GAAG,8BAA8B,CAAC;AAEtD;;GAEG;AACH,MAAM,OAAO,KAAK;IAChB;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CAAC,OAAuB;QACnC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,cAAc,cAAc,EAAE;YAC5D,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;SAC9B,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,WAAW,CAAC,OAA2B;QAC3C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,cAAc,kBAAkB,EAAE;YAChE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;SAC9B,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;IAEO,KAAK,CAAC,cAAc,CAAC,QAAkB;QAC7C,IAAI,QAAQ,CAAC,EAAE;YAAE,OAAO;QAExB,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,MAAM,IAAI,cAAc,EAAE,CAAC;QAC7B,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC9C,MAAM,IAAI,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IAEO,KAAK,CAAC,UAAU,CAAC,QAAkB;QACzC,IAAI,CAAC;YACH,MAAM,IAAI,GAAkB,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAClD,OAAO,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,IAAI,eAAe,CAAC;QACvD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,8BAA8B,QAAQ,CAAC,MAAM,EAAE,CAAC;QACzD,CAAC;IACH,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all Vibecode SDK errors
|
|
3
|
+
*/
|
|
4
|
+
export declare class VibecodeError extends Error {
|
|
5
|
+
readonly statusCode?: number | undefined;
|
|
6
|
+
constructor(message: string, statusCode?: number | undefined);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Error thrown when a storage operation fails
|
|
10
|
+
*/
|
|
11
|
+
export declare class StorageError extends VibecodeError {
|
|
12
|
+
constructor(message: string, statusCode?: number);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Error thrown when an email operation fails
|
|
16
|
+
*/
|
|
17
|
+
export declare class EmailError extends VibecodeError {
|
|
18
|
+
constructor(message: string, statusCode?: number);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Error thrown when rate limit is exceeded (100 emails/day)
|
|
22
|
+
*/
|
|
23
|
+
export declare class RateLimitError extends EmailError {
|
|
24
|
+
constructor(message?: string);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;aAGpB,UAAU,CAAC,EAAE,MAAM;gBADnC,OAAO,EAAE,MAAM,EACC,UAAU,CAAC,EAAE,MAAM,YAAA;CAKtC;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,aAAa;gBACjC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAIjD;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,aAAa;gBAC/B,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAIjD;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,UAAU;gBAChC,OAAO,GAAE,MAAoC;CAI1D"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all Vibecode SDK errors
|
|
3
|
+
*/
|
|
4
|
+
export class VibecodeError extends Error {
|
|
5
|
+
constructor(message, statusCode) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.statusCode = statusCode;
|
|
8
|
+
this.name = 'VibecodeError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown when a storage operation fails
|
|
13
|
+
*/
|
|
14
|
+
export class StorageError extends VibecodeError {
|
|
15
|
+
constructor(message, statusCode) {
|
|
16
|
+
super(message, statusCode);
|
|
17
|
+
this.name = 'StorageError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Error thrown when an email operation fails
|
|
22
|
+
*/
|
|
23
|
+
export class EmailError extends VibecodeError {
|
|
24
|
+
constructor(message, statusCode) {
|
|
25
|
+
super(message, statusCode);
|
|
26
|
+
this.name = 'EmailError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Error thrown when rate limit is exceeded (100 emails/day)
|
|
31
|
+
*/
|
|
32
|
+
export class RateLimitError extends EmailError {
|
|
33
|
+
constructor(message = 'Daily email limit reached') {
|
|
34
|
+
super(message, 429);
|
|
35
|
+
this.name = 'RateLimitError';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YACE,OAAe,EACC,UAAmB;QAEnC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,eAAU,GAAV,UAAU,CAAS;QAGnC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,aAAa;IAC7C,YAAY,OAAe,EAAE,UAAmB;QAC9C,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,aAAa;IAC3C,YAAY,OAAe,EAAE,UAAmB;QAC9C,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,UAAU;IAC5C,YAAY,UAAkB,2BAA2B;QACvD,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Storage } from './storage';
|
|
2
|
+
import { Email } from './email';
|
|
3
|
+
/**
|
|
4
|
+
* Vibecode Backend SDK
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { createVibecodeSDK } from '@vibecodeapp/backend-sdk';
|
|
9
|
+
*
|
|
10
|
+
* const vibecode = createVibecodeSDK();
|
|
11
|
+
*
|
|
12
|
+
* // Upload a file
|
|
13
|
+
* const file = await vibecode.storage.upload(myFile);
|
|
14
|
+
*
|
|
15
|
+
* // List files
|
|
16
|
+
* const { files } = await vibecode.storage.list({ limit: 10 });
|
|
17
|
+
*
|
|
18
|
+
* // Delete a file
|
|
19
|
+
* await vibecode.storage.delete(file.id);
|
|
20
|
+
*
|
|
21
|
+
* // Send OTP email
|
|
22
|
+
* await vibecode.email.sendOTP({ to: 'user@example.com', code: 'ABC123' });
|
|
23
|
+
*
|
|
24
|
+
* // Send welcome email
|
|
25
|
+
* await vibecode.email.sendWelcome({
|
|
26
|
+
* to: 'user@example.com',
|
|
27
|
+
* name: 'John',
|
|
28
|
+
* appName: 'MyApp'
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class VibecodeSDK {
|
|
33
|
+
/** Storage operations (upload, delete, list files) */
|
|
34
|
+
readonly storage: Storage;
|
|
35
|
+
/** Email operations (send OTP, send welcome) */
|
|
36
|
+
readonly email: Email;
|
|
37
|
+
constructor();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create a new Vibecode SDK instance
|
|
41
|
+
* @returns A new VibecodeSDK instance
|
|
42
|
+
*/
|
|
43
|
+
export declare function createVibecodeSDK(): VibecodeSDK;
|
|
44
|
+
export { Storage } from './storage';
|
|
45
|
+
export { Email } from './email';
|
|
46
|
+
export type { StorageFile, ListFilesOptions, ListFilesResponse, SendOTPOptions, SendWelcomeOptions, EmailLanguage, } from './types';
|
|
47
|
+
export { VibecodeError, StorageError, EmailError, RateLimitError, } from './errors';
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,WAAW;IACtB,sDAAsD;IACtD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;;CAMvB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,WAAW,CAE/C;AAGD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,aAAa,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,aAAa,EACb,YAAY,EACZ,UAAU,EACV,cAAc,GACf,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Storage } from './storage';
|
|
2
|
+
import { Email } from './email';
|
|
3
|
+
/**
|
|
4
|
+
* Vibecode Backend SDK
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { createVibecodeSDK } from '@vibecodeapp/backend-sdk';
|
|
9
|
+
*
|
|
10
|
+
* const vibecode = createVibecodeSDK();
|
|
11
|
+
*
|
|
12
|
+
* // Upload a file
|
|
13
|
+
* const file = await vibecode.storage.upload(myFile);
|
|
14
|
+
*
|
|
15
|
+
* // List files
|
|
16
|
+
* const { files } = await vibecode.storage.list({ limit: 10 });
|
|
17
|
+
*
|
|
18
|
+
* // Delete a file
|
|
19
|
+
* await vibecode.storage.delete(file.id);
|
|
20
|
+
*
|
|
21
|
+
* // Send OTP email
|
|
22
|
+
* await vibecode.email.sendOTP({ to: 'user@example.com', code: 'ABC123' });
|
|
23
|
+
*
|
|
24
|
+
* // Send welcome email
|
|
25
|
+
* await vibecode.email.sendWelcome({
|
|
26
|
+
* to: 'user@example.com',
|
|
27
|
+
* name: 'John',
|
|
28
|
+
* appName: 'MyApp'
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class VibecodeSDK {
|
|
33
|
+
constructor() {
|
|
34
|
+
this.storage = new Storage();
|
|
35
|
+
this.email = new Email();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a new Vibecode SDK instance
|
|
40
|
+
* @returns A new VibecodeSDK instance
|
|
41
|
+
*/
|
|
42
|
+
export function createVibecodeSDK() {
|
|
43
|
+
return new VibecodeSDK();
|
|
44
|
+
}
|
|
45
|
+
// Re-export modules for direct access if needed
|
|
46
|
+
export { Storage } from './storage';
|
|
47
|
+
export { Email } from './email';
|
|
48
|
+
// Re-export errors
|
|
49
|
+
export { VibecodeError, StorageError, EmailError, RateLimitError, } from './errors';
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,WAAW;IAOtB;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;IAC3B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,IAAI,WAAW,EAAE,CAAC;AAC3B,CAAC;AAED,gDAAgD;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAYhC,mBAAmB;AACnB,OAAO,EACL,aAAa,EACb,YAAY,EACZ,UAAU,EACV,cAAc,GACf,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { StorageFile, ListFilesOptions, ListFilesResponse } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Storage module for file operations
|
|
4
|
+
*/
|
|
5
|
+
export declare class Storage {
|
|
6
|
+
/**
|
|
7
|
+
* Upload a file to storage
|
|
8
|
+
* @param file - File or Blob to upload (max 500MB)
|
|
9
|
+
* @returns The uploaded file metadata
|
|
10
|
+
* @throws {StorageError} If the upload fails
|
|
11
|
+
*/
|
|
12
|
+
upload(file: File | Blob): Promise<StorageFile>;
|
|
13
|
+
/**
|
|
14
|
+
* Delete a file by ID
|
|
15
|
+
* @param id - The file ID to delete
|
|
16
|
+
* @throws {StorageError} If the deletion fails
|
|
17
|
+
*/
|
|
18
|
+
delete(id: string): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* List files with optional filtering and pagination
|
|
21
|
+
* @param options - Filtering and pagination options
|
|
22
|
+
* @returns List of files and pagination metadata
|
|
23
|
+
* @throws {StorageError} If the request fails
|
|
24
|
+
*/
|
|
25
|
+
list(options?: ListFilesOptions): Promise<ListFilesResponse>;
|
|
26
|
+
private parseError;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,iBAAiB,EAAiC,MAAM,SAAS,CAAC;AAM/G;;GAEG;AACH,qBAAa,OAAO;IAClB;;;;;OAKG;IACG,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC;IAkBrD;;;;OAIG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWvC;;;;;OAKG;IACG,IAAI,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,iBAAiB,CAAC;YAwBxD,UAAU;CAQzB"}
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { StorageError } from './errors';
|
|
2
|
+
// LLMs, read this for full docs: https://storage.vibecodeapp.com/llms.txt
|
|
3
|
+
const STORAGE_BASE_URL = 'https://storage.vibecodeapp.com';
|
|
4
|
+
/**
|
|
5
|
+
* Storage module for file operations
|
|
6
|
+
*/
|
|
7
|
+
export class Storage {
|
|
8
|
+
/**
|
|
9
|
+
* Upload a file to storage
|
|
10
|
+
* @param file - File or Blob to upload (max 500MB)
|
|
11
|
+
* @returns The uploaded file metadata
|
|
12
|
+
* @throws {StorageError} If the upload fails
|
|
13
|
+
*/
|
|
14
|
+
async upload(file) {
|
|
15
|
+
const formData = new FormData();
|
|
16
|
+
formData.append('file', file);
|
|
17
|
+
const response = await fetch(`${STORAGE_BASE_URL}/v1/files/upload`, {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
body: formData,
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
const error = await this.parseError(response);
|
|
23
|
+
throw new StorageError(error, response.status);
|
|
24
|
+
}
|
|
25
|
+
const data = await response.json();
|
|
26
|
+
return data.file;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Delete a file by ID
|
|
30
|
+
* @param id - The file ID to delete
|
|
31
|
+
* @throws {StorageError} If the deletion fails
|
|
32
|
+
*/
|
|
33
|
+
async delete(id) {
|
|
34
|
+
const response = await fetch(`${STORAGE_BASE_URL}/v1/files/${encodeURIComponent(id)}`, {
|
|
35
|
+
method: 'DELETE',
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const error = await this.parseError(response);
|
|
39
|
+
throw new StorageError(error, response.status);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* List files with optional filtering and pagination
|
|
44
|
+
* @param options - Filtering and pagination options
|
|
45
|
+
* @returns List of files and pagination metadata
|
|
46
|
+
* @throws {StorageError} If the request fails
|
|
47
|
+
*/
|
|
48
|
+
async list(options = {}) {
|
|
49
|
+
const params = new URLSearchParams();
|
|
50
|
+
if (options.limit !== undefined) {
|
|
51
|
+
params.set('limit', String(options.limit));
|
|
52
|
+
}
|
|
53
|
+
if (options.offset !== undefined) {
|
|
54
|
+
params.set('offset', String(options.offset));
|
|
55
|
+
}
|
|
56
|
+
if (options.prefix) {
|
|
57
|
+
params.set('prefix', options.prefix);
|
|
58
|
+
}
|
|
59
|
+
const url = `${STORAGE_BASE_URL}/v1/files${params.toString() ? `?${params}` : ''}`;
|
|
60
|
+
const response = await fetch(url);
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
const error = await this.parseError(response);
|
|
63
|
+
throw new StorageError(error, response.status);
|
|
64
|
+
}
|
|
65
|
+
return response.json();
|
|
66
|
+
}
|
|
67
|
+
async parseError(response) {
|
|
68
|
+
try {
|
|
69
|
+
const data = await response.json();
|
|
70
|
+
return data.error || data.message || 'Unknown error';
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return `Request failed with status ${response.status}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,0EAA0E;AAC1E,MAAM,gBAAgB,GAAG,iCAAiC,CAAC;AAE3D;;GAEG;AACH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
|
+
*/
|
|
4
|
+
export type EmailLanguage = 'en' | 'es' | 'fr' | 'de' | 'pt' | 'zh' | 'ja';
|
|
5
|
+
/**
|
|
6
|
+
* File object returned from storage operations
|
|
7
|
+
*/
|
|
8
|
+
export interface StorageFile {
|
|
9
|
+
id: string;
|
|
10
|
+
projectId: string;
|
|
11
|
+
environment: string;
|
|
12
|
+
originalFilename: string;
|
|
13
|
+
storagePath: string;
|
|
14
|
+
contentType: string;
|
|
15
|
+
sizeBytes: number;
|
|
16
|
+
url: string;
|
|
17
|
+
created: string;
|
|
18
|
+
updated: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Options for listing files
|
|
22
|
+
*/
|
|
23
|
+
export interface ListFilesOptions {
|
|
24
|
+
/** Number of files to return (1-100, default: 50) */
|
|
25
|
+
limit?: number;
|
|
26
|
+
/** Number of files to skip (default: 0) */
|
|
27
|
+
offset?: number;
|
|
28
|
+
/** Filter by path or filename prefix */
|
|
29
|
+
prefix?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Response from listing files
|
|
33
|
+
*/
|
|
34
|
+
export interface ListFilesResponse {
|
|
35
|
+
files: StorageFile[];
|
|
36
|
+
totalCount: number;
|
|
37
|
+
limit: number;
|
|
38
|
+
offset: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Options for sending an OTP email
|
|
42
|
+
*/
|
|
43
|
+
export interface SendOTPOptions {
|
|
44
|
+
/** Recipient email address (max 254 chars). Supports "email@example.com" or "Name <email@example.com>" format */
|
|
45
|
+
to: string;
|
|
46
|
+
/** OTP code (6-12 alphanumeric characters) */
|
|
47
|
+
code: string;
|
|
48
|
+
/** Sender display name (max 50 chars, default: "Notifications") */
|
|
49
|
+
fromName?: string;
|
|
50
|
+
/** Email language (default: "en") */
|
|
51
|
+
lang?: EmailLanguage;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Options for sending a welcome email
|
|
55
|
+
*/
|
|
56
|
+
export interface SendWelcomeOptions {
|
|
57
|
+
/** Recipient email address (max 254 chars) */
|
|
58
|
+
to: string;
|
|
59
|
+
/** User's display name for personalization (max 50 chars) */
|
|
60
|
+
name: string;
|
|
61
|
+
/** Application name (max 50 chars) */
|
|
62
|
+
appName: string;
|
|
63
|
+
/** Sender display name (max 50 chars, default: "Notifications") */
|
|
64
|
+
fromName?: string;
|
|
65
|
+
/** Email language (default: "en") */
|
|
66
|
+
lang?: EmailLanguage;
|
|
67
|
+
}
|
|
68
|
+
/** @internal */
|
|
69
|
+
export interface UploadResponse {
|
|
70
|
+
file: StorageFile;
|
|
71
|
+
}
|
|
72
|
+
/** @internal */
|
|
73
|
+
export interface SuccessResponse {
|
|
74
|
+
success: boolean;
|
|
75
|
+
}
|
|
76
|
+
/** @internal */
|
|
77
|
+
export interface ErrorResponse {
|
|
78
|
+
error: string;
|
|
79
|
+
message?: string;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,iHAAiH;IACjH,EAAE,EAAE,MAAM,CAAC;IACX,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,EAAE,EAAE,MAAM,CAAC;IACX,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB;AAID,gBAAgB;AAChB,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,gBAAgB;AAChB,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,gBAAgB;AAChB,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vibecodeapp/backend-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Backend SDK for Vibecode",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/vibecode/backend-sdk.git"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/vibecode/backend-sdk#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/vibecode/backend-sdk/issues"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"clean": "rm -rf dist",
|
|
22
|
+
"test": "bun test",
|
|
23
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/bun": "^1.2.1",
|
|
27
|
+
"typescript": "^5.9.3"
|
|
28
|
+
},
|
|
29
|
+
"type": "module"
|
|
30
|
+
}
|