@canveletedotcom/sdk 2.0.0 → 2.0.2
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/dist/client.js +2 -1
- package/dist/resources/render.d.ts +3 -1
- package/dist/resources/render.js +18 -5
- package/package.json +4 -1
package/dist/client.js
CHANGED
|
@@ -16,7 +16,8 @@ export class CanveleteClient {
|
|
|
16
16
|
*/
|
|
17
17
|
constructor(options = {}) {
|
|
18
18
|
this.apiKey = options.apiKey || '';
|
|
19
|
-
|
|
19
|
+
// Default to backend API for direct rendering
|
|
20
|
+
this.baseUrl = (options.baseUrl || 'https://api.canvelete.com').replace(/\/$/, '');
|
|
20
21
|
this.timeout = options.timeout || 30000;
|
|
21
22
|
// Initialize resource handlers
|
|
22
23
|
this.designs = new DesignsResource(this);
|
|
@@ -7,6 +7,7 @@ export interface RenderOptions {
|
|
|
7
7
|
designId?: string;
|
|
8
8
|
templateId?: string;
|
|
9
9
|
dynamicData?: Record<string, any>;
|
|
10
|
+
dynamicElements?: Record<string, any>;
|
|
10
11
|
format?: 'png' | 'jpg' | 'jpeg' | 'pdf' | 'svg';
|
|
11
12
|
width?: number;
|
|
12
13
|
height?: number;
|
|
@@ -47,6 +48,7 @@ export declare class RenderResource {
|
|
|
47
48
|
constructor(client: CanveleteClient);
|
|
48
49
|
/**
|
|
49
50
|
* Create a synchronous render (waits for completion)
|
|
51
|
+
* Uses the backend API directly at /api/v1/render
|
|
50
52
|
*/
|
|
51
53
|
create(options: RenderOptions): Promise<ArrayBuffer>;
|
|
52
54
|
/**
|
|
@@ -80,7 +82,7 @@ export declare class RenderResource {
|
|
|
80
82
|
pollInterval?: number;
|
|
81
83
|
}): Promise<RenderRecord[]>;
|
|
82
84
|
/**
|
|
83
|
-
* List render history
|
|
85
|
+
* List render history
|
|
84
86
|
*/
|
|
85
87
|
list(options?: ListRenderOptions): Promise<PaginatedResponse<RenderRecord>>;
|
|
86
88
|
/**
|
package/dist/resources/render.js
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Render resource for creating and managing render jobs
|
|
3
3
|
*/
|
|
4
|
-
import { writeFileSync } from 'fs';
|
|
5
4
|
import { ValidationError } from '../errors';
|
|
5
|
+
// Helper to check if we're in a Node.js environment
|
|
6
|
+
const isNode = typeof process !== 'undefined' && process.versions?.node;
|
|
7
|
+
// Dynamic import for fs (only available in Node.js)
|
|
8
|
+
const writeFile = async (path, data) => {
|
|
9
|
+
if (!isNode) {
|
|
10
|
+
throw new Error('File writing is only available in Node.js environments');
|
|
11
|
+
}
|
|
12
|
+
const { writeFileSync } = await import('fs');
|
|
13
|
+
writeFileSync(path, data);
|
|
14
|
+
};
|
|
6
15
|
export class RenderResource {
|
|
7
16
|
constructor(client) {
|
|
8
17
|
this.client = client;
|
|
9
18
|
}
|
|
10
19
|
/**
|
|
11
20
|
* Create a synchronous render (waits for completion)
|
|
21
|
+
* Uses the backend API directly at /api/v1/render
|
|
12
22
|
*/
|
|
13
23
|
async create(options) {
|
|
14
24
|
if (!options.designId && !options.templateId) {
|
|
@@ -22,18 +32,21 @@ export class RenderResource {
|
|
|
22
32
|
data.designId = options.designId;
|
|
23
33
|
if (options.templateId)
|
|
24
34
|
data.templateId = options.templateId;
|
|
35
|
+
// Support both dynamicData and dynamicElements for flexibility
|
|
25
36
|
if (options.dynamicData)
|
|
26
37
|
data.dynamicData = options.dynamicData;
|
|
38
|
+
if (options.dynamicElements)
|
|
39
|
+
data.dynamicElements = options.dynamicElements;
|
|
27
40
|
if (options.width)
|
|
28
41
|
data.width = options.width;
|
|
29
42
|
if (options.height)
|
|
30
43
|
data.height = options.height;
|
|
31
|
-
const imageData = await this.client.request('POST', '/api/
|
|
44
|
+
const imageData = await this.client.request('POST', '/api/v1/render', {
|
|
32
45
|
json: data,
|
|
33
46
|
binary: true,
|
|
34
47
|
});
|
|
35
48
|
if (options.outputFile) {
|
|
36
|
-
|
|
49
|
+
await writeFile(options.outputFile, Buffer.from(imageData));
|
|
37
50
|
}
|
|
38
51
|
return imageData;
|
|
39
52
|
}
|
|
@@ -140,14 +153,14 @@ export class RenderResource {
|
|
|
140
153
|
throw new Error(`Batch render timed out after ${timeout}ms`);
|
|
141
154
|
}
|
|
142
155
|
/**
|
|
143
|
-
* List render history
|
|
156
|
+
* List render history
|
|
144
157
|
*/
|
|
145
158
|
async list(options = {}) {
|
|
146
159
|
const params = {
|
|
147
160
|
page: String(options.page || 1),
|
|
148
161
|
limit: String(options.limit || 20),
|
|
149
162
|
};
|
|
150
|
-
return await this.client.request('GET', '/api/
|
|
163
|
+
return await this.client.request('GET', '/api/v1/render/history', { params });
|
|
151
164
|
}
|
|
152
165
|
/**
|
|
153
166
|
* Iterate through all render records with automatic pagination
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canveletedotcom/sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Official TypeScript SDK for the Canvelete API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -53,5 +53,8 @@
|
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|
|
55
55
|
"node": ">=18.0.0"
|
|
56
|
+
},
|
|
57
|
+
"browser": {
|
|
58
|
+
"fs": false
|
|
56
59
|
}
|
|
57
60
|
}
|