@html-css-to-image/client 0.4.0 → 0.6.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 +17 -0
- package/dist/HtmlCssToImageClient.d.ts +4 -1
- package/dist/HtmlCssToImageClient.js +26 -0
- package/dist/IHtmlCssToImageClient.d.ts +3 -1
- package/dist/index.d.ts +1 -1
- package/dist/types/request.d.ts +4 -0
- package/dist/types/request.js +4 -0
- package/dist/types/response.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,6 +67,23 @@ if (result.success) {
|
|
|
67
67
|
}
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
### Delete Images
|
|
71
|
+
|
|
72
|
+
Delete one or more existing images from HCTI and clear them from the CDN using their image IDs.
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const result = await client.deleteImage('your_image_id');
|
|
76
|
+
|
|
77
|
+
if (!result.success) {
|
|
78
|
+
console.error('Error:', result.error);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const batchResult = await client.deleteImageBatch([
|
|
82
|
+
'first_image_id',
|
|
83
|
+
'second_image_id'
|
|
84
|
+
]);
|
|
85
|
+
```
|
|
86
|
+
|
|
70
87
|
## Creating Image URLs
|
|
71
88
|
|
|
72
89
|
For use cases where you want to generate a URL on the server and use it safely on the client (without exposing your API key), you can generate a signed URL.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IHtmlCssToImageClient } from "./IHtmlCssToImageClient.js";
|
|
2
2
|
import { CreateTemplatedImageRequest } from "./types/request.js";
|
|
3
3
|
import type { CreateHtmlCssImageRequest, CreateUrlImageRequest } from "./types/request.js";
|
|
4
|
-
import type { CreateImageBatchResponse, CreateImageResponse } from "./types/response.js";
|
|
4
|
+
import type { CreateImageBatchResponse, CreateImageResponse, DeleteImageResponse } from "./types/response.js";
|
|
5
5
|
export type FetchFunction = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
6
6
|
export declare class HtmlCssToImageClient implements IHtmlCssToImageClient {
|
|
7
7
|
private readonly apiId;
|
|
@@ -12,11 +12,14 @@ export declare class HtmlCssToImageClient implements IHtmlCssToImageClient {
|
|
|
12
12
|
constructor(apiId: string, apiKey: string, customFetch?: FetchFunction);
|
|
13
13
|
static fromEnv(): HtmlCssToImageClient;
|
|
14
14
|
createImage(request: CreateHtmlCssImageRequest | CreateUrlImageRequest | CreateTemplatedImageRequest): Promise<CreateImageResponse>;
|
|
15
|
+
deleteImage(imageId: string): Promise<DeleteImageResponse>;
|
|
16
|
+
deleteImageBatch(imageIds: readonly string[]): Promise<DeleteImageResponse>;
|
|
15
17
|
private mapToInternal;
|
|
16
18
|
createImageBatch<T extends CreateHtmlCssImageRequest | CreateUrlImageRequest>(variations: T[], default_options?: T): Promise<CreateImageBatchResponse>;
|
|
17
19
|
generateTemplatedImageUrl<T extends Record<string, any>>(templateIdOrRequest: string | CreateTemplatedImageRequest<T>, templateValues?: T, templateVersion?: number): string;
|
|
18
20
|
generateCreateAndRenderUrl(request: CreateUrlImageRequest): string;
|
|
19
21
|
private responseToType;
|
|
22
|
+
private responseToDeleteImageResponse;
|
|
20
23
|
private mapHtmlCssToInternalRequest;
|
|
21
24
|
private mapUrlToInternalRequest;
|
|
22
25
|
private mapPDFOptionsToInternal;
|
|
@@ -38,6 +38,26 @@ export class HtmlCssToImageClient {
|
|
|
38
38
|
});
|
|
39
39
|
return await this.responseToType(response);
|
|
40
40
|
}
|
|
41
|
+
async deleteImage(imageId) {
|
|
42
|
+
const response = await this.fetch(`${this.baseUrl}/v1/image/${encodeURIComponent(imageId)}`, {
|
|
43
|
+
method: 'DELETE',
|
|
44
|
+
headers: {
|
|
45
|
+
'Authorization': this.authHeader,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
return await this.responseToDeleteImageResponse(response);
|
|
49
|
+
}
|
|
50
|
+
async deleteImageBatch(imageIds) {
|
|
51
|
+
const response = await this.fetch(`${this.baseUrl}/v1/image/batch`, {
|
|
52
|
+
method: 'DELETE',
|
|
53
|
+
headers: {
|
|
54
|
+
'Authorization': this.authHeader,
|
|
55
|
+
'Content-Type': 'application/json',
|
|
56
|
+
},
|
|
57
|
+
body: JSON.stringify({ ids: imageIds }),
|
|
58
|
+
});
|
|
59
|
+
return await this.responseToDeleteImageResponse(response);
|
|
60
|
+
}
|
|
41
61
|
mapToInternal(request, in_batch) {
|
|
42
62
|
switch (request.__type) {
|
|
43
63
|
case 'html_css':
|
|
@@ -141,6 +161,12 @@ export class HtmlCssToImageClient {
|
|
|
141
161
|
return { success: false, ...response_json };
|
|
142
162
|
}
|
|
143
163
|
}
|
|
164
|
+
async responseToDeleteImageResponse(response) {
|
|
165
|
+
if (response.ok) {
|
|
166
|
+
return { success: true };
|
|
167
|
+
}
|
|
168
|
+
return await this.responseToType(response);
|
|
169
|
+
}
|
|
144
170
|
mapHtmlCssToInternalRequest(request, in_batch) {
|
|
145
171
|
const { pdf_options, google_fonts, __type, ...shared_request } = request;
|
|
146
172
|
let new_request;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { CreateHtmlCssImageRequest, CreateTemplatedImageRequest, CreateUrlImageRequest } from "./types/request.js";
|
|
2
|
-
import type { CreateImageBatchResponse, CreateImageResponse } from "./types/response.js";
|
|
2
|
+
import type { CreateImageBatchResponse, CreateImageResponse, DeleteImageResponse } from "./types/response.js";
|
|
3
3
|
export interface IHtmlCssToImageClient {
|
|
4
4
|
createImage(request: CreateHtmlCssImageRequest | CreateUrlImageRequest | CreateTemplatedImageRequest): Promise<CreateImageResponse>;
|
|
5
5
|
createImageBatch<T extends CreateHtmlCssImageRequest | CreateUrlImageRequest>(variations: T[], default_options?: T): Promise<CreateImageBatchResponse>;
|
|
6
|
+
deleteImage(imageId: string): Promise<DeleteImageResponse>;
|
|
7
|
+
deleteImageBatch(imageIds: readonly string[]): Promise<DeleteImageResponse>;
|
|
6
8
|
generateCreateAndRenderUrl(request: CreateUrlImageRequest): string;
|
|
7
9
|
generateTemplatedImageUrl<T extends Record<string, any>>(template_id: string, template_values: T, template_version?: number): string;
|
|
8
10
|
generateTemplatedImageUrl(request: CreateTemplatedImageRequest): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { BaseCreateImageRequest, CreateHtmlCssImageRequest, CreateTemplatedImageRequest, CreateUrlImageRequest, PDFOptions } from './types/request.js';
|
|
2
2
|
export type { ColorSchemeType, MediaType, PdfMargins, PdfValueInput, PdfValueWithUnits, PdfUnit } from './types/request.js';
|
|
3
|
-
export type { CreateImageBatchResponse, CreateImageBatchSuccessResponse, CreateImageErrorResponse, CreateImageResponse, CreateImageSuccessResponse, ValidationError } from './types/response.js';
|
|
3
|
+
export type { CreateImageBatchResponse, CreateImageBatchSuccessResponse, CreateImageErrorResponse, CreateImageResponse, CreateImageSuccessResponse, DeleteImageResponse, DeleteImageSuccessResponse, ValidationError } from './types/response.js';
|
|
4
4
|
export { HtmlCssToImageClient } from './HtmlCssToImageClient.js';
|
|
5
5
|
export type { FetchFunction } from './HtmlCssToImageClient.js';
|
|
6
6
|
export type { IHtmlCssToImageClient } from './IHtmlCssToImageClient.js';
|
package/dist/types/request.d.ts
CHANGED
|
@@ -110,6 +110,10 @@ export declare abstract class BaseCreateImageRequest {
|
|
|
110
110
|
* Select an organization proxy for rendering.
|
|
111
111
|
*/
|
|
112
112
|
proxy_id?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Save rendered images to one of the organization's configured storage destinations.
|
|
115
|
+
*/
|
|
116
|
+
storage_destination_id?: string;
|
|
113
117
|
/**
|
|
114
118
|
* Set the maximum width in jumbo mode. jumbo_max_height must also be defined.
|
|
115
119
|
*/
|
package/dist/types/request.js
CHANGED
|
@@ -91,6 +91,10 @@ export class BaseCreateImageRequest {
|
|
|
91
91
|
* Select an organization proxy for rendering.
|
|
92
92
|
*/
|
|
93
93
|
proxy_id;
|
|
94
|
+
/**
|
|
95
|
+
* Save rendered images to one of the organization's configured storage destinations.
|
|
96
|
+
*/
|
|
97
|
+
storage_destination_id;
|
|
94
98
|
/**
|
|
95
99
|
* Set the maximum width in jumbo mode. jumbo_max_height must also be defined.
|
|
96
100
|
*/
|
package/dist/types/response.d.ts
CHANGED
|
@@ -17,5 +17,9 @@ export interface CreateImageBatchSuccessResponse {
|
|
|
17
17
|
success: true;
|
|
18
18
|
images: CreateImageSuccessResponse[];
|
|
19
19
|
}
|
|
20
|
+
export interface DeleteImageSuccessResponse {
|
|
21
|
+
success: true;
|
|
22
|
+
}
|
|
20
23
|
export type CreateImageBatchResponse = CreateImageBatchSuccessResponse | CreateImageErrorResponse;
|
|
21
24
|
export type CreateImageResponse = CreateImageSuccessResponse | CreateImageErrorResponse;
|
|
25
|
+
export type DeleteImageResponse = DeleteImageSuccessResponse | CreateImageErrorResponse;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@html-css-to-image/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Lightweight TypeScript client for the HTML/CSS to Image API. Generate images from HTML/CSS, URLs, or templates in your TypeScript or JavaScript projects.",
|
|
6
6
|
"main": "dist/index.js",
|