@poof-bg/js 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/LICENSE +21 -0
- package/README.md +189 -0
- package/dist/index.cjs +304 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +222 -0
- package/dist/index.d.ts +222 -0
- package/dist/index.js +295 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Poof SDK Types
|
|
3
|
+
*/
|
|
4
|
+
/** Configuration options for the Poof client */
|
|
5
|
+
interface PoofOptions {
|
|
6
|
+
/** Your Poof API key */
|
|
7
|
+
apiKey: string;
|
|
8
|
+
/** Base URL for the API (default: https://api.poof.bg/v1) */
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/** Request timeout in milliseconds (default: 60000) */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Output image format */
|
|
14
|
+
type ImageFormat = 'png' | 'jpg' | 'webp';
|
|
15
|
+
/** Output color channels */
|
|
16
|
+
type Channels = 'rgba' | 'rgb';
|
|
17
|
+
/** Output image size preset */
|
|
18
|
+
type ImageSize = 'full' | 'preview' | 'small' | 'medium' | 'large';
|
|
19
|
+
/** Options for background removal */
|
|
20
|
+
interface RemoveBackgroundOptions {
|
|
21
|
+
/** Output format (default: png) */
|
|
22
|
+
format?: ImageFormat;
|
|
23
|
+
/** Color channels - rgba for transparency, rgb for opaque (default: rgba) */
|
|
24
|
+
channels?: Channels;
|
|
25
|
+
/** Background color (hex, rgb, or color name). Only applies when channels is 'rgb' */
|
|
26
|
+
bgColor?: string;
|
|
27
|
+
/** Output size preset (default: full) */
|
|
28
|
+
size?: ImageSize;
|
|
29
|
+
/** Crop to subject bounds (default: false) */
|
|
30
|
+
crop?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** Metadata returned with processed images */
|
|
33
|
+
interface ProcessingMetadata {
|
|
34
|
+
/** Unique request identifier */
|
|
35
|
+
requestId: string;
|
|
36
|
+
/** Processing time in milliseconds */
|
|
37
|
+
processingTimeMs: number;
|
|
38
|
+
/** Output image width in pixels */
|
|
39
|
+
width: number;
|
|
40
|
+
/** Output image height in pixels */
|
|
41
|
+
height: number;
|
|
42
|
+
/** Content type of the result */
|
|
43
|
+
contentType: string;
|
|
44
|
+
}
|
|
45
|
+
/** Result of background removal including image data and metadata */
|
|
46
|
+
interface RemoveBackgroundResult {
|
|
47
|
+
/** The processed image data */
|
|
48
|
+
data: ArrayBuffer;
|
|
49
|
+
/** Processing metadata */
|
|
50
|
+
metadata: ProcessingMetadata;
|
|
51
|
+
}
|
|
52
|
+
/** Account information */
|
|
53
|
+
interface AccountInfo {
|
|
54
|
+
/** Your organization ID */
|
|
55
|
+
organizationId: string;
|
|
56
|
+
/** Current plan name */
|
|
57
|
+
plan: string;
|
|
58
|
+
/** Total credits available in billing cycle */
|
|
59
|
+
maxCredits: number;
|
|
60
|
+
/** Credits used in current billing cycle */
|
|
61
|
+
usedCredits: number;
|
|
62
|
+
/** Credit threshold for auto-recharge (if enabled) */
|
|
63
|
+
autoRechargeThreshold: number | null;
|
|
64
|
+
}
|
|
65
|
+
/** Error codes returned by the API */
|
|
66
|
+
type ErrorCode = 'authentication_error' | 'permission_denied' | 'payment_required' | 'rate_limit_exceeded' | 'validation_error' | 'missing_image' | 'image_too_large' | 'upstream_error' | 'internal_server_error';
|
|
67
|
+
/** API error response structure */
|
|
68
|
+
interface ApiErrorResponse {
|
|
69
|
+
code: ErrorCode;
|
|
70
|
+
message: string;
|
|
71
|
+
details?: string;
|
|
72
|
+
request_id: string;
|
|
73
|
+
}
|
|
74
|
+
/** Valid input types for image processing */
|
|
75
|
+
type ImageInput = File | Blob | ArrayBuffer | Buffer | Uint8Array | string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Poof API client for background removal
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import { Poof } from '@poof-bg/js';
|
|
83
|
+
*
|
|
84
|
+
* const poof = new Poof({ apiKey: 'your-api-key' });
|
|
85
|
+
* const result = await poof.removeBackground(imageFile);
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
declare class Poof {
|
|
89
|
+
private readonly apiKey;
|
|
90
|
+
private readonly baseUrl;
|
|
91
|
+
private readonly timeout;
|
|
92
|
+
constructor(options: PoofOptions);
|
|
93
|
+
/**
|
|
94
|
+
* Remove background from an image
|
|
95
|
+
*
|
|
96
|
+
* @param input - Image input: File, Blob, Buffer, ArrayBuffer, Uint8Array, or file path (Node.js)
|
|
97
|
+
* @param options - Processing options
|
|
98
|
+
* @returns Processed image data and metadata
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* // Basic usage
|
|
103
|
+
* const result = await poof.removeBackground(file);
|
|
104
|
+
* const imageBlob = new Blob([result.data], { type: result.metadata.contentType });
|
|
105
|
+
*
|
|
106
|
+
* // With options
|
|
107
|
+
* const result = await poof.removeBackground(file, {
|
|
108
|
+
* format: 'webp',
|
|
109
|
+
* crop: true,
|
|
110
|
+
* size: 'medium'
|
|
111
|
+
* });
|
|
112
|
+
*
|
|
113
|
+
* // Node.js: from file path
|
|
114
|
+
* const result = await poof.removeBackground('/path/to/image.png');
|
|
115
|
+
*
|
|
116
|
+
* // Node.js: save to file
|
|
117
|
+
* const fs = require('fs');
|
|
118
|
+
* fs.writeFileSync('output.png', Buffer.from(result.data));
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
removeBackground(input: ImageInput, options?: RemoveBackgroundOptions): Promise<RemoveBackgroundResult>;
|
|
122
|
+
/**
|
|
123
|
+
* Get account information
|
|
124
|
+
*
|
|
125
|
+
* @returns Account info including plan and credit usage
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const account = await poof.me();
|
|
130
|
+
* console.log(`Plan: ${account.plan}`);
|
|
131
|
+
* console.log(`Credits: ${account.usedCredits}/${account.maxCredits}`);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
me(): Promise<AccountInfo>;
|
|
135
|
+
/** Make a fetch request with auth and timeout */
|
|
136
|
+
private fetch;
|
|
137
|
+
/** Handle error response */
|
|
138
|
+
private handleError;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Base error class for all Poof SDK errors
|
|
143
|
+
*/
|
|
144
|
+
declare class PoofError extends Error {
|
|
145
|
+
/** Machine-readable error code */
|
|
146
|
+
readonly code: string;
|
|
147
|
+
/** HTTP status code */
|
|
148
|
+
readonly status?: number;
|
|
149
|
+
/** Unique request ID for support */
|
|
150
|
+
readonly requestId?: string;
|
|
151
|
+
/** Additional details */
|
|
152
|
+
readonly details?: string;
|
|
153
|
+
constructor(message: string, code: string, options?: {
|
|
154
|
+
status?: number;
|
|
155
|
+
requestId?: string;
|
|
156
|
+
details?: string;
|
|
157
|
+
});
|
|
158
|
+
/** Create error from API response */
|
|
159
|
+
static fromResponse(response: ApiErrorResponse, status: number): PoofError;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Thrown when the API key is invalid or missing
|
|
163
|
+
*/
|
|
164
|
+
declare class AuthenticationError extends PoofError {
|
|
165
|
+
constructor(message: string, code: string, options?: {
|
|
166
|
+
status?: number;
|
|
167
|
+
requestId?: string;
|
|
168
|
+
details?: string;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Thrown when the account doesn't have permission
|
|
173
|
+
*/
|
|
174
|
+
declare class PermissionError extends PoofError {
|
|
175
|
+
constructor(message: string, code: string, options?: {
|
|
176
|
+
status?: number;
|
|
177
|
+
requestId?: string;
|
|
178
|
+
details?: string;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Thrown when the account has insufficient credits
|
|
183
|
+
*/
|
|
184
|
+
declare class PaymentRequiredError extends PoofError {
|
|
185
|
+
constructor(message: string, code: string, options?: {
|
|
186
|
+
status?: number;
|
|
187
|
+
requestId?: string;
|
|
188
|
+
details?: string;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Thrown when rate limit is exceeded
|
|
193
|
+
*/
|
|
194
|
+
declare class RateLimitError extends PoofError {
|
|
195
|
+
constructor(message: string, code: string, options?: {
|
|
196
|
+
status?: number;
|
|
197
|
+
requestId?: string;
|
|
198
|
+
details?: string;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Thrown when request parameters are invalid
|
|
203
|
+
*/
|
|
204
|
+
declare class ValidationError extends PoofError {
|
|
205
|
+
constructor(message: string, code: string, options?: {
|
|
206
|
+
status?: number;
|
|
207
|
+
requestId?: string;
|
|
208
|
+
details?: string;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Thrown when a server error occurs
|
|
213
|
+
*/
|
|
214
|
+
declare class ServerError extends PoofError {
|
|
215
|
+
constructor(message: string, code: string, options?: {
|
|
216
|
+
status?: number;
|
|
217
|
+
requestId?: string;
|
|
218
|
+
details?: string;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export { type AccountInfo, type ApiErrorResponse, AuthenticationError, type Channels, type ErrorCode, type ImageFormat, type ImageInput, type ImageSize, PaymentRequiredError, PermissionError, Poof, PoofError, type PoofOptions, type ProcessingMetadata, RateLimitError, type RemoveBackgroundOptions, type RemoveBackgroundResult, ServerError, ValidationError };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Poof SDK Types
|
|
3
|
+
*/
|
|
4
|
+
/** Configuration options for the Poof client */
|
|
5
|
+
interface PoofOptions {
|
|
6
|
+
/** Your Poof API key */
|
|
7
|
+
apiKey: string;
|
|
8
|
+
/** Base URL for the API (default: https://api.poof.bg/v1) */
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/** Request timeout in milliseconds (default: 60000) */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Output image format */
|
|
14
|
+
type ImageFormat = 'png' | 'jpg' | 'webp';
|
|
15
|
+
/** Output color channels */
|
|
16
|
+
type Channels = 'rgba' | 'rgb';
|
|
17
|
+
/** Output image size preset */
|
|
18
|
+
type ImageSize = 'full' | 'preview' | 'small' | 'medium' | 'large';
|
|
19
|
+
/** Options for background removal */
|
|
20
|
+
interface RemoveBackgroundOptions {
|
|
21
|
+
/** Output format (default: png) */
|
|
22
|
+
format?: ImageFormat;
|
|
23
|
+
/** Color channels - rgba for transparency, rgb for opaque (default: rgba) */
|
|
24
|
+
channels?: Channels;
|
|
25
|
+
/** Background color (hex, rgb, or color name). Only applies when channels is 'rgb' */
|
|
26
|
+
bgColor?: string;
|
|
27
|
+
/** Output size preset (default: full) */
|
|
28
|
+
size?: ImageSize;
|
|
29
|
+
/** Crop to subject bounds (default: false) */
|
|
30
|
+
crop?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** Metadata returned with processed images */
|
|
33
|
+
interface ProcessingMetadata {
|
|
34
|
+
/** Unique request identifier */
|
|
35
|
+
requestId: string;
|
|
36
|
+
/** Processing time in milliseconds */
|
|
37
|
+
processingTimeMs: number;
|
|
38
|
+
/** Output image width in pixels */
|
|
39
|
+
width: number;
|
|
40
|
+
/** Output image height in pixels */
|
|
41
|
+
height: number;
|
|
42
|
+
/** Content type of the result */
|
|
43
|
+
contentType: string;
|
|
44
|
+
}
|
|
45
|
+
/** Result of background removal including image data and metadata */
|
|
46
|
+
interface RemoveBackgroundResult {
|
|
47
|
+
/** The processed image data */
|
|
48
|
+
data: ArrayBuffer;
|
|
49
|
+
/** Processing metadata */
|
|
50
|
+
metadata: ProcessingMetadata;
|
|
51
|
+
}
|
|
52
|
+
/** Account information */
|
|
53
|
+
interface AccountInfo {
|
|
54
|
+
/** Your organization ID */
|
|
55
|
+
organizationId: string;
|
|
56
|
+
/** Current plan name */
|
|
57
|
+
plan: string;
|
|
58
|
+
/** Total credits available in billing cycle */
|
|
59
|
+
maxCredits: number;
|
|
60
|
+
/** Credits used in current billing cycle */
|
|
61
|
+
usedCredits: number;
|
|
62
|
+
/** Credit threshold for auto-recharge (if enabled) */
|
|
63
|
+
autoRechargeThreshold: number | null;
|
|
64
|
+
}
|
|
65
|
+
/** Error codes returned by the API */
|
|
66
|
+
type ErrorCode = 'authentication_error' | 'permission_denied' | 'payment_required' | 'rate_limit_exceeded' | 'validation_error' | 'missing_image' | 'image_too_large' | 'upstream_error' | 'internal_server_error';
|
|
67
|
+
/** API error response structure */
|
|
68
|
+
interface ApiErrorResponse {
|
|
69
|
+
code: ErrorCode;
|
|
70
|
+
message: string;
|
|
71
|
+
details?: string;
|
|
72
|
+
request_id: string;
|
|
73
|
+
}
|
|
74
|
+
/** Valid input types for image processing */
|
|
75
|
+
type ImageInput = File | Blob | ArrayBuffer | Buffer | Uint8Array | string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Poof API client for background removal
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import { Poof } from '@poof-bg/js';
|
|
83
|
+
*
|
|
84
|
+
* const poof = new Poof({ apiKey: 'your-api-key' });
|
|
85
|
+
* const result = await poof.removeBackground(imageFile);
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
declare class Poof {
|
|
89
|
+
private readonly apiKey;
|
|
90
|
+
private readonly baseUrl;
|
|
91
|
+
private readonly timeout;
|
|
92
|
+
constructor(options: PoofOptions);
|
|
93
|
+
/**
|
|
94
|
+
* Remove background from an image
|
|
95
|
+
*
|
|
96
|
+
* @param input - Image input: File, Blob, Buffer, ArrayBuffer, Uint8Array, or file path (Node.js)
|
|
97
|
+
* @param options - Processing options
|
|
98
|
+
* @returns Processed image data and metadata
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* // Basic usage
|
|
103
|
+
* const result = await poof.removeBackground(file);
|
|
104
|
+
* const imageBlob = new Blob([result.data], { type: result.metadata.contentType });
|
|
105
|
+
*
|
|
106
|
+
* // With options
|
|
107
|
+
* const result = await poof.removeBackground(file, {
|
|
108
|
+
* format: 'webp',
|
|
109
|
+
* crop: true,
|
|
110
|
+
* size: 'medium'
|
|
111
|
+
* });
|
|
112
|
+
*
|
|
113
|
+
* // Node.js: from file path
|
|
114
|
+
* const result = await poof.removeBackground('/path/to/image.png');
|
|
115
|
+
*
|
|
116
|
+
* // Node.js: save to file
|
|
117
|
+
* const fs = require('fs');
|
|
118
|
+
* fs.writeFileSync('output.png', Buffer.from(result.data));
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
removeBackground(input: ImageInput, options?: RemoveBackgroundOptions): Promise<RemoveBackgroundResult>;
|
|
122
|
+
/**
|
|
123
|
+
* Get account information
|
|
124
|
+
*
|
|
125
|
+
* @returns Account info including plan and credit usage
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const account = await poof.me();
|
|
130
|
+
* console.log(`Plan: ${account.plan}`);
|
|
131
|
+
* console.log(`Credits: ${account.usedCredits}/${account.maxCredits}`);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
me(): Promise<AccountInfo>;
|
|
135
|
+
/** Make a fetch request with auth and timeout */
|
|
136
|
+
private fetch;
|
|
137
|
+
/** Handle error response */
|
|
138
|
+
private handleError;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Base error class for all Poof SDK errors
|
|
143
|
+
*/
|
|
144
|
+
declare class PoofError extends Error {
|
|
145
|
+
/** Machine-readable error code */
|
|
146
|
+
readonly code: string;
|
|
147
|
+
/** HTTP status code */
|
|
148
|
+
readonly status?: number;
|
|
149
|
+
/** Unique request ID for support */
|
|
150
|
+
readonly requestId?: string;
|
|
151
|
+
/** Additional details */
|
|
152
|
+
readonly details?: string;
|
|
153
|
+
constructor(message: string, code: string, options?: {
|
|
154
|
+
status?: number;
|
|
155
|
+
requestId?: string;
|
|
156
|
+
details?: string;
|
|
157
|
+
});
|
|
158
|
+
/** Create error from API response */
|
|
159
|
+
static fromResponse(response: ApiErrorResponse, status: number): PoofError;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Thrown when the API key is invalid or missing
|
|
163
|
+
*/
|
|
164
|
+
declare class AuthenticationError extends PoofError {
|
|
165
|
+
constructor(message: string, code: string, options?: {
|
|
166
|
+
status?: number;
|
|
167
|
+
requestId?: string;
|
|
168
|
+
details?: string;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Thrown when the account doesn't have permission
|
|
173
|
+
*/
|
|
174
|
+
declare class PermissionError extends PoofError {
|
|
175
|
+
constructor(message: string, code: string, options?: {
|
|
176
|
+
status?: number;
|
|
177
|
+
requestId?: string;
|
|
178
|
+
details?: string;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Thrown when the account has insufficient credits
|
|
183
|
+
*/
|
|
184
|
+
declare class PaymentRequiredError extends PoofError {
|
|
185
|
+
constructor(message: string, code: string, options?: {
|
|
186
|
+
status?: number;
|
|
187
|
+
requestId?: string;
|
|
188
|
+
details?: string;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Thrown when rate limit is exceeded
|
|
193
|
+
*/
|
|
194
|
+
declare class RateLimitError extends PoofError {
|
|
195
|
+
constructor(message: string, code: string, options?: {
|
|
196
|
+
status?: number;
|
|
197
|
+
requestId?: string;
|
|
198
|
+
details?: string;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Thrown when request parameters are invalid
|
|
203
|
+
*/
|
|
204
|
+
declare class ValidationError extends PoofError {
|
|
205
|
+
constructor(message: string, code: string, options?: {
|
|
206
|
+
status?: number;
|
|
207
|
+
requestId?: string;
|
|
208
|
+
details?: string;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Thrown when a server error occurs
|
|
213
|
+
*/
|
|
214
|
+
declare class ServerError extends PoofError {
|
|
215
|
+
constructor(message: string, code: string, options?: {
|
|
216
|
+
status?: number;
|
|
217
|
+
requestId?: string;
|
|
218
|
+
details?: string;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export { type AccountInfo, type ApiErrorResponse, AuthenticationError, type Channels, type ErrorCode, type ImageFormat, type ImageInput, type ImageSize, PaymentRequiredError, PermissionError, Poof, PoofError, type PoofOptions, type ProcessingMetadata, RateLimitError, type RemoveBackgroundOptions, type RemoveBackgroundResult, ServerError, ValidationError };
|