@canva/n8n-nodes-canva 0.1.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 +217 -0
- package/dist/credentials/CanvaOAuth2Api.credentials.d.ts +9 -0
- package/dist/credentials/CanvaOAuth2Api.credentials.js +55 -0
- package/dist/credentials/CanvaOAuth2Api.credentials.js.map +1 -0
- package/dist/nodes/Canva/Canva.node.d.ts +5 -0
- package/dist/nodes/Canva/Canva.node.js +717 -0
- package/dist/nodes/Canva/Canva.node.js.map +1 -0
- package/dist/nodes/Canva/Canva.node.json +19 -0
- package/dist/nodes/Canva/GenericFunctions.d.ts +2 -0
- package/dist/nodes/Canva/GenericFunctions.js +12 -0
- package/dist/nodes/Canva/GenericFunctions.js.map +1 -0
- package/dist/nodes/Canva/icons/canva.dark.svg +1 -0
- package/dist/nodes/Canva/icons/canva.svg +1 -0
- package/dist/nodes/Canva/resources/asset/delete.d.ts +2 -0
- package/dist/nodes/Canva/resources/asset/delete.js +16 -0
- package/dist/nodes/Canva/resources/asset/delete.js.map +1 -0
- package/dist/nodes/Canva/resources/asset/get.d.ts +2 -0
- package/dist/nodes/Canva/resources/asset/get.js +16 -0
- package/dist/nodes/Canva/resources/asset/get.js.map +1 -0
- package/dist/nodes/Canva/resources/asset/index.d.ts +3 -0
- package/dist/nodes/Canva/resources/asset/index.js +53 -0
- package/dist/nodes/Canva/resources/asset/index.js.map +1 -0
- package/dist/nodes/Canva/resources/asset/update.d.ts +2 -0
- package/dist/nodes/Canva/resources/asset/update.js +42 -0
- package/dist/nodes/Canva/resources/asset/update.js.map +1 -0
- package/dist/nodes/Canva/resources/asset/upload.d.ts +2 -0
- package/dist/nodes/Canva/resources/asset/upload.js +44 -0
- package/dist/nodes/Canva/resources/asset/upload.js.map +1 -0
- package/dist/nodes/Canva/resources/asset/uploadPreviewNotice.d.ts +2 -0
- package/dist/nodes/Canva/resources/asset/uploadPreviewNotice.js +13 -0
- package/dist/nodes/Canva/resources/asset/uploadPreviewNotice.js.map +1 -0
- package/dist/nodes/Canva/resources/autofill/create.d.ts +2 -0
- package/dist/nodes/Canva/resources/autofill/create.js +53 -0
- package/dist/nodes/Canva/resources/autofill/create.js.map +1 -0
- package/dist/nodes/Canva/resources/autofill/index.d.ts +3 -0
- package/dist/nodes/Canva/resources/autofill/index.js +29 -0
- package/dist/nodes/Canva/resources/autofill/index.js.map +1 -0
- package/dist/nodes/Canva/resources/autofill/premiumNotice.d.ts +2 -0
- package/dist/nodes/Canva/resources/autofill/premiumNotice.js +13 -0
- package/dist/nodes/Canva/resources/autofill/premiumNotice.js.map +1 -0
- package/dist/nodes/Canva/resources/brandTemplate/get.d.ts +2 -0
- package/dist/nodes/Canva/resources/brandTemplate/get.js +16 -0
- package/dist/nodes/Canva/resources/brandTemplate/get.js.map +1 -0
- package/dist/nodes/Canva/resources/brandTemplate/getAll.d.ts +2 -0
- package/dist/nodes/Canva/resources/brandTemplate/getAll.js +69 -0
- package/dist/nodes/Canva/resources/brandTemplate/getAll.js.map +1 -0
- package/dist/nodes/Canva/resources/brandTemplate/getDataset.d.ts +2 -0
- package/dist/nodes/Canva/resources/brandTemplate/getDataset.js +16 -0
- package/dist/nodes/Canva/resources/brandTemplate/getDataset.js.map +1 -0
- package/dist/nodes/Canva/resources/brandTemplate/index.d.ts +3 -0
- package/dist/nodes/Canva/resources/brandTemplate/index.js +55 -0
- package/dist/nodes/Canva/resources/brandTemplate/index.js.map +1 -0
- package/dist/nodes/Canva/resources/brandTemplate/premiumNotice.d.ts +2 -0
- package/dist/nodes/Canva/resources/brandTemplate/premiumNotice.js +13 -0
- package/dist/nodes/Canva/resources/brandTemplate/premiumNotice.js.map +1 -0
- package/dist/nodes/Canva/resources/brandTemplate/publish.d.ts +2 -0
- package/dist/nodes/Canva/resources/brandTemplate/publish.js +16 -0
- package/dist/nodes/Canva/resources/brandTemplate/publish.js.map +1 -0
- package/dist/nodes/Canva/resources/brandTemplate/publishPreviewNotice.d.ts +2 -0
- package/dist/nodes/Canva/resources/brandTemplate/publishPreviewNotice.js +13 -0
- package/dist/nodes/Canva/resources/brandTemplate/publishPreviewNotice.js.map +1 -0
- package/dist/nodes/Canva/resources/comment/createReply.d.ts +2 -0
- package/dist/nodes/Canva/resources/comment/createReply.js +37 -0
- package/dist/nodes/Canva/resources/comment/createReply.js.map +1 -0
- package/dist/nodes/Canva/resources/comment/createThread.d.ts +2 -0
- package/dist/nodes/Canva/resources/comment/createThread.js +45 -0
- package/dist/nodes/Canva/resources/comment/createThread.js.map +1 -0
- package/dist/nodes/Canva/resources/comment/getReply.d.ts +2 -0
- package/dist/nodes/Canva/resources/comment/getReply.js +36 -0
- package/dist/nodes/Canva/resources/comment/getReply.js.map +1 -0
- package/dist/nodes/Canva/resources/comment/getThread.d.ts +2 -0
- package/dist/nodes/Canva/resources/comment/getThread.js +26 -0
- package/dist/nodes/Canva/resources/comment/getThread.js.map +1 -0
- package/dist/nodes/Canva/resources/comment/index.d.ts +3 -0
- package/dist/nodes/Canva/resources/comment/index.js +61 -0
- package/dist/nodes/Canva/resources/comment/index.js.map +1 -0
- package/dist/nodes/Canva/resources/comment/listReplies.d.ts +2 -0
- package/dist/nodes/Canva/resources/comment/listReplies.js +45 -0
- package/dist/nodes/Canva/resources/comment/listReplies.js.map +1 -0
- package/dist/nodes/Canva/resources/comment/previewNotice.d.ts +2 -0
- package/dist/nodes/Canva/resources/comment/previewNotice.js +13 -0
- package/dist/nodes/Canva/resources/comment/previewNotice.js.map +1 -0
- package/dist/nodes/Canva/resources/design/create.d.ts +2 -0
- package/dist/nodes/Canva/resources/design/create.js +78 -0
- package/dist/nodes/Canva/resources/design/create.js.map +1 -0
- package/dist/nodes/Canva/resources/design/get.d.ts +2 -0
- package/dist/nodes/Canva/resources/design/get.js +16 -0
- package/dist/nodes/Canva/resources/design/get.js.map +1 -0
- package/dist/nodes/Canva/resources/design/getAll.d.ts +2 -0
- package/dist/nodes/Canva/resources/design/getAll.js +69 -0
- package/dist/nodes/Canva/resources/design/getAll.js.map +1 -0
- package/dist/nodes/Canva/resources/design/getDataset.d.ts +2 -0
- package/dist/nodes/Canva/resources/design/getDataset.js +16 -0
- package/dist/nodes/Canva/resources/design/getDataset.js.map +1 -0
- package/dist/nodes/Canva/resources/design/getDatasetPreviewNotice.d.ts +2 -0
- package/dist/nodes/Canva/resources/design/getDatasetPreviewNotice.js +13 -0
- package/dist/nodes/Canva/resources/design/getDatasetPreviewNotice.js.map +1 -0
- package/dist/nodes/Canva/resources/design/getExportFormats.d.ts +2 -0
- package/dist/nodes/Canva/resources/design/getExportFormats.js +16 -0
- package/dist/nodes/Canva/resources/design/getExportFormats.js.map +1 -0
- package/dist/nodes/Canva/resources/design/getPages.d.ts +2 -0
- package/dist/nodes/Canva/resources/design/getPages.js +34 -0
- package/dist/nodes/Canva/resources/design/getPages.js.map +1 -0
- package/dist/nodes/Canva/resources/design/getPagesPreviewNotice.d.ts +2 -0
- package/dist/nodes/Canva/resources/design/getPagesPreviewNotice.js +13 -0
- package/dist/nodes/Canva/resources/design/getPagesPreviewNotice.js.map +1 -0
- package/dist/nodes/Canva/resources/design/index.d.ts +3 -0
- package/dist/nodes/Canva/resources/design/index.js +71 -0
- package/dist/nodes/Canva/resources/design/index.js.map +1 -0
- package/dist/nodes/Canva/resources/designImport/createImport.d.ts +2 -0
- package/dist/nodes/Canva/resources/designImport/createImport.js +44 -0
- package/dist/nodes/Canva/resources/designImport/createImport.js.map +1 -0
- package/dist/nodes/Canva/resources/designImport/index.d.ts +3 -0
- package/dist/nodes/Canva/resources/designImport/index.js +27 -0
- package/dist/nodes/Canva/resources/designImport/index.js.map +1 -0
- package/dist/nodes/Canva/resources/export/export.d.ts +2 -0
- package/dist/nodes/Canva/resources/export/export.js +92 -0
- package/dist/nodes/Canva/resources/export/export.js.map +1 -0
- package/dist/nodes/Canva/resources/export/index.d.ts +3 -0
- package/dist/nodes/Canva/resources/export/index.js +27 -0
- package/dist/nodes/Canva/resources/export/index.js.map +1 -0
- package/dist/nodes/Canva/resources/folder/create.d.ts +2 -0
- package/dist/nodes/Canva/resources/folder/create.js +26 -0
- package/dist/nodes/Canva/resources/folder/create.js.map +1 -0
- package/dist/nodes/Canva/resources/folder/delete.d.ts +2 -0
- package/dist/nodes/Canva/resources/folder/delete.js +16 -0
- package/dist/nodes/Canva/resources/folder/delete.js.map +1 -0
- package/dist/nodes/Canva/resources/folder/get.d.ts +2 -0
- package/dist/nodes/Canva/resources/folder/get.js +16 -0
- package/dist/nodes/Canva/resources/folder/get.js.map +1 -0
- package/dist/nodes/Canva/resources/folder/index.d.ts +3 -0
- package/dist/nodes/Canva/resources/folder/index.js +67 -0
- package/dist/nodes/Canva/resources/folder/index.js.map +1 -0
- package/dist/nodes/Canva/resources/folder/listItems.d.ts +2 -0
- package/dist/nodes/Canva/resources/folder/listItems.js +73 -0
- package/dist/nodes/Canva/resources/folder/listItems.js.map +1 -0
- package/dist/nodes/Canva/resources/folder/moveItem.d.ts +2 -0
- package/dist/nodes/Canva/resources/folder/moveItem.js +26 -0
- package/dist/nodes/Canva/resources/folder/moveItem.js.map +1 -0
- package/dist/nodes/Canva/resources/folder/update.d.ts +2 -0
- package/dist/nodes/Canva/resources/folder/update.js +26 -0
- package/dist/nodes/Canva/resources/folder/update.js.map +1 -0
- package/dist/nodes/Canva/resources/merge/create.d.ts +2 -0
- package/dist/nodes/Canva/resources/merge/create.js +90 -0
- package/dist/nodes/Canva/resources/merge/create.js.map +1 -0
- package/dist/nodes/Canva/resources/merge/index.d.ts +3 -0
- package/dist/nodes/Canva/resources/merge/index.js +29 -0
- package/dist/nodes/Canva/resources/merge/index.js.map +1 -0
- package/dist/nodes/Canva/resources/merge/previewNotice.d.ts +2 -0
- package/dist/nodes/Canva/resources/merge/previewNotice.js +13 -0
- package/dist/nodes/Canva/resources/merge/previewNotice.js.map +1 -0
- package/dist/nodes/Canva/resources/resize/create.d.ts +2 -0
- package/dist/nodes/Canva/resources/resize/create.js +86 -0
- package/dist/nodes/Canva/resources/resize/create.js.map +1 -0
- package/dist/nodes/Canva/resources/resize/index.d.ts +3 -0
- package/dist/nodes/Canva/resources/resize/index.js +29 -0
- package/dist/nodes/Canva/resources/resize/index.js.map +1 -0
- package/dist/nodes/Canva/resources/resize/premiumNotice.d.ts +2 -0
- package/dist/nodes/Canva/resources/resize/premiumNotice.js +13 -0
- package/dist/nodes/Canva/resources/resize/premiumNotice.js.map +1 -0
- package/dist/nodes/Canva/resources/user/index.d.ts +3 -0
- package/dist/nodes/Canva/resources/user/index.js +35 -0
- package/dist/nodes/Canva/resources/user/index.js.map +1 -0
- package/dist/package.json +61 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Canva = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const autofill_1 = require("./resources/autofill");
|
|
6
|
+
const brandTemplate_1 = require("./resources/brandTemplate");
|
|
7
|
+
const comment_1 = require("./resources/comment");
|
|
8
|
+
const design_1 = require("./resources/design");
|
|
9
|
+
const designImport_1 = require("./resources/designImport");
|
|
10
|
+
const export_1 = require("./resources/export");
|
|
11
|
+
const folder_1 = require("./resources/folder");
|
|
12
|
+
const merge_1 = require("./resources/merge");
|
|
13
|
+
const resize_1 = require("./resources/resize");
|
|
14
|
+
const asset_1 = require("./resources/asset");
|
|
15
|
+
const user_1 = require("./resources/user");
|
|
16
|
+
const GenericFunctions_1 = require("./GenericFunctions");
|
|
17
|
+
class Canva {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.description = {
|
|
20
|
+
displayName: 'Canva',
|
|
21
|
+
name: 'canva',
|
|
22
|
+
icon: { light: 'file:icons/canva.svg', dark: 'file:icons/canva.dark.svg' },
|
|
23
|
+
group: ['transform'],
|
|
24
|
+
version: 1,
|
|
25
|
+
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
26
|
+
description: 'Interact with the Canva API',
|
|
27
|
+
defaults: { name: 'Canva' },
|
|
28
|
+
usableAsTool: true,
|
|
29
|
+
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
30
|
+
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
31
|
+
credentials: [{ name: 'canvaOAuth2Api', required: true }],
|
|
32
|
+
properties: [
|
|
33
|
+
{
|
|
34
|
+
displayName: 'Resource',
|
|
35
|
+
name: 'resource',
|
|
36
|
+
type: 'options',
|
|
37
|
+
noDataExpression: true,
|
|
38
|
+
options: [
|
|
39
|
+
{ name: 'Asset', value: 'asset' },
|
|
40
|
+
{ name: 'Autofill', value: 'autofill' },
|
|
41
|
+
{ name: 'Brand Template', value: 'brandTemplate' },
|
|
42
|
+
{ name: 'Comment (Preview API)', value: 'comment' },
|
|
43
|
+
{ name: 'Design', value: 'design' },
|
|
44
|
+
{ name: 'Design Import', value: 'designImport' },
|
|
45
|
+
{ name: 'Export', value: 'export' },
|
|
46
|
+
{ name: 'Folder', value: 'folder' },
|
|
47
|
+
{ name: 'Merge (Preview API)', value: 'merge' },
|
|
48
|
+
{ name: 'Resize', value: 'resize' },
|
|
49
|
+
{ name: 'User', value: 'user' },
|
|
50
|
+
],
|
|
51
|
+
default: 'design',
|
|
52
|
+
},
|
|
53
|
+
...autofill_1.autofillDescription,
|
|
54
|
+
...brandTemplate_1.brandTemplateDescription,
|
|
55
|
+
...comment_1.commentDescription,
|
|
56
|
+
...design_1.designDescription,
|
|
57
|
+
...designImport_1.designImportDescription,
|
|
58
|
+
...export_1.exportDescription,
|
|
59
|
+
...folder_1.folderDescription,
|
|
60
|
+
...merge_1.mergeDescription,
|
|
61
|
+
...resize_1.resizeDescription,
|
|
62
|
+
...asset_1.assetDescription,
|
|
63
|
+
...user_1.userDescription,
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async execute() {
|
|
68
|
+
var _a, _b, _c, _d;
|
|
69
|
+
const items = this.getInputData();
|
|
70
|
+
const returnData = [];
|
|
71
|
+
for (let i = 0; i < items.length; i++) {
|
|
72
|
+
try {
|
|
73
|
+
const resource = this.getNodeParameter('resource', i);
|
|
74
|
+
const operation = this.getNodeParameter('operation', i);
|
|
75
|
+
let responseData;
|
|
76
|
+
if (resource === 'asset') {
|
|
77
|
+
if (operation === 'delete') {
|
|
78
|
+
const assetId = this.getNodeParameter('assetId', i);
|
|
79
|
+
await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
80
|
+
method: 'DELETE',
|
|
81
|
+
url: `/assets/${encodeURIComponent(assetId)}`,
|
|
82
|
+
json: true,
|
|
83
|
+
});
|
|
84
|
+
responseData = { success: true };
|
|
85
|
+
}
|
|
86
|
+
else if (operation === 'get') {
|
|
87
|
+
const assetId = this.getNodeParameter('assetId', i);
|
|
88
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
89
|
+
method: 'GET',
|
|
90
|
+
url: `/assets/${encodeURIComponent(assetId)}`,
|
|
91
|
+
json: true,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else if (operation === 'update') {
|
|
95
|
+
const assetId = this.getNodeParameter('assetId', i);
|
|
96
|
+
const updateFields = this.getNodeParameter('updateFields', i);
|
|
97
|
+
const body = {};
|
|
98
|
+
if (updateFields.name)
|
|
99
|
+
body.name = updateFields.name;
|
|
100
|
+
if (updateFields.tags) {
|
|
101
|
+
body.tags = updateFields.tags
|
|
102
|
+
.split(',')
|
|
103
|
+
.map((t) => t.trim())
|
|
104
|
+
.filter(Boolean);
|
|
105
|
+
}
|
|
106
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
107
|
+
method: 'PATCH',
|
|
108
|
+
url: `/assets/${encodeURIComponent(assetId)}`,
|
|
109
|
+
body,
|
|
110
|
+
json: true,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else if (operation === 'upload') {
|
|
114
|
+
const name = this.getNodeParameter('name', i);
|
|
115
|
+
const url = this.getNodeParameter('url', i);
|
|
116
|
+
const pollInterval = this.getNodeParameter('pollInterval', i);
|
|
117
|
+
const maxWait = this.getNodeParameter('maxWait', i) * 1000;
|
|
118
|
+
const createResp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
119
|
+
method: 'POST',
|
|
120
|
+
url: `/url-asset-uploads`,
|
|
121
|
+
body: { name, url },
|
|
122
|
+
json: true,
|
|
123
|
+
}));
|
|
124
|
+
const uploadJobId = createResp.job.id;
|
|
125
|
+
const deadline = Date.now() + maxWait;
|
|
126
|
+
let jobResp = createResp;
|
|
127
|
+
while (jobResp.job.status === 'in_progress') {
|
|
128
|
+
if (Date.now() >= deadline) {
|
|
129
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Asset upload job ${uploadJobId} timed out after ${maxWait / 1000}s`, { itemIndex: i });
|
|
130
|
+
}
|
|
131
|
+
await (0, n8n_workflow_1.sleep)(pollInterval);
|
|
132
|
+
jobResp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
133
|
+
method: 'GET',
|
|
134
|
+
url: `/url-asset-uploads/${uploadJobId}`,
|
|
135
|
+
json: true,
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
if (jobResp.job.status === 'failed') {
|
|
139
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Asset upload job ${uploadJobId} failed`, { itemIndex: i });
|
|
140
|
+
}
|
|
141
|
+
responseData = jobResp;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else if (resource === 'autofill') {
|
|
145
|
+
if (operation === 'create') {
|
|
146
|
+
const brandTemplateId = this.getNodeParameter('brandTemplateId', i);
|
|
147
|
+
const dataRaw = this.getNodeParameter('data', i);
|
|
148
|
+
const title = this.getNodeParameter('title', i);
|
|
149
|
+
const pollInterval = this.getNodeParameter('pollInterval', i);
|
|
150
|
+
const maxWait = this.getNodeParameter('maxWait', i) * 1000;
|
|
151
|
+
let data;
|
|
152
|
+
try {
|
|
153
|
+
data = typeof dataRaw === 'string' ? JSON.parse(dataRaw) : dataRaw;
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'The "Data" field is not valid JSON', {
|
|
157
|
+
itemIndex: i,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
const body = { brand_template_id: brandTemplateId, data };
|
|
161
|
+
if (title)
|
|
162
|
+
body.title = title;
|
|
163
|
+
const createResp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
164
|
+
method: 'POST',
|
|
165
|
+
url: `/autofills`,
|
|
166
|
+
body,
|
|
167
|
+
json: true,
|
|
168
|
+
}));
|
|
169
|
+
const autofillJobId = createResp.job.id;
|
|
170
|
+
const deadline = Date.now() + maxWait;
|
|
171
|
+
let jobResp = createResp;
|
|
172
|
+
while (jobResp.job.status === 'in_progress') {
|
|
173
|
+
if (Date.now() >= deadline) {
|
|
174
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Autofill job ${autofillJobId} timed out after ${maxWait / 1000}s`, { itemIndex: i });
|
|
175
|
+
}
|
|
176
|
+
await (0, n8n_workflow_1.sleep)(pollInterval);
|
|
177
|
+
jobResp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
178
|
+
method: 'GET',
|
|
179
|
+
url: `/autofills/${autofillJobId}`,
|
|
180
|
+
json: true,
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
if (jobResp.job.status === 'failed') {
|
|
184
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Autofill job ${autofillJobId} failed`, {
|
|
185
|
+
itemIndex: i,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
responseData = jobResp;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else if (resource === 'brandTemplate') {
|
|
192
|
+
if (operation === 'get') {
|
|
193
|
+
const brandTemplateId = this.getNodeParameter('brandTemplateId', i);
|
|
194
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
195
|
+
method: 'GET',
|
|
196
|
+
url: `/brand-templates/${encodeURIComponent(brandTemplateId)}`,
|
|
197
|
+
json: true,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
else if (operation === 'getDataset') {
|
|
201
|
+
const brandTemplateId = this.getNodeParameter('brandTemplateId', i);
|
|
202
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
203
|
+
method: 'GET',
|
|
204
|
+
url: `/brand-templates/${encodeURIComponent(brandTemplateId)}/dataset`,
|
|
205
|
+
json: true,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
else if (operation === 'getAll') {
|
|
209
|
+
const returnAll = this.getNodeParameter('returnAll', i);
|
|
210
|
+
const limit = returnAll ? 100 : this.getNodeParameter('limit', i);
|
|
211
|
+
const filters = this.getNodeParameter('filters', i);
|
|
212
|
+
const qs = { limit };
|
|
213
|
+
if (filters.query)
|
|
214
|
+
qs.query = filters.query;
|
|
215
|
+
if (filters.ownership)
|
|
216
|
+
qs.ownership = filters.ownership;
|
|
217
|
+
if (filters.sort_by)
|
|
218
|
+
qs.sort_by = filters.sort_by;
|
|
219
|
+
const allItems = [];
|
|
220
|
+
let continuation;
|
|
221
|
+
do {
|
|
222
|
+
if (continuation)
|
|
223
|
+
qs.continuation = continuation;
|
|
224
|
+
const resp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
225
|
+
method: 'GET',
|
|
226
|
+
url: `/brand-templates`,
|
|
227
|
+
qs,
|
|
228
|
+
json: true,
|
|
229
|
+
}));
|
|
230
|
+
allItems.push(...((_a = resp.items) !== null && _a !== void 0 ? _a : []));
|
|
231
|
+
continuation = resp.continuation;
|
|
232
|
+
} while (continuation && (returnAll || allItems.length < limit));
|
|
233
|
+
responseData = returnAll ? allItems : allItems.slice(0, limit);
|
|
234
|
+
}
|
|
235
|
+
else if (operation === 'publish') {
|
|
236
|
+
const designId = this.getNodeParameter('designId', i);
|
|
237
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
238
|
+
method: 'POST',
|
|
239
|
+
url: `/brand-templates`,
|
|
240
|
+
body: { design_id: designId },
|
|
241
|
+
json: true,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
else if (resource === 'comment') {
|
|
246
|
+
if (operation === 'createThread') {
|
|
247
|
+
const designId = this.getNodeParameter('designId', i);
|
|
248
|
+
const message = this.getNodeParameter('message', i);
|
|
249
|
+
const additionalFields = this.getNodeParameter('additionalFields', i);
|
|
250
|
+
const body = { message_plaintext: message };
|
|
251
|
+
if (additionalFields.assignee_id)
|
|
252
|
+
body.assignee_id = additionalFields.assignee_id;
|
|
253
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
254
|
+
method: 'POST',
|
|
255
|
+
url: `/designs/${encodeURIComponent(designId)}/comments`,
|
|
256
|
+
body,
|
|
257
|
+
json: true,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
else if (operation === 'createReply') {
|
|
261
|
+
const designId = this.getNodeParameter('designId', i);
|
|
262
|
+
const threadId = this.getNodeParameter('threadId', i);
|
|
263
|
+
const message = this.getNodeParameter('message', i);
|
|
264
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
265
|
+
method: 'POST',
|
|
266
|
+
url: `/designs/${encodeURIComponent(designId)}/comments/${encodeURIComponent(threadId)}/replies`,
|
|
267
|
+
body: { message_plaintext: message },
|
|
268
|
+
json: true,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
else if (operation === 'getThread') {
|
|
272
|
+
const designId = this.getNodeParameter('designId', i);
|
|
273
|
+
const threadId = this.getNodeParameter('threadId', i);
|
|
274
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
275
|
+
method: 'GET',
|
|
276
|
+
url: `/designs/${encodeURIComponent(designId)}/comments/${encodeURIComponent(threadId)}`,
|
|
277
|
+
json: true,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
else if (operation === 'getReply') {
|
|
281
|
+
const designId = this.getNodeParameter('designId', i);
|
|
282
|
+
const threadId = this.getNodeParameter('threadId', i);
|
|
283
|
+
const replyId = this.getNodeParameter('replyId', i);
|
|
284
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
285
|
+
method: 'GET',
|
|
286
|
+
url: `/designs/${encodeURIComponent(designId)}/comments/${encodeURIComponent(threadId)}/replies/${encodeURIComponent(replyId)}`,
|
|
287
|
+
json: true,
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
else if (operation === 'listReplies') {
|
|
291
|
+
const designId = this.getNodeParameter('designId', i);
|
|
292
|
+
const threadId = this.getNodeParameter('threadId', i);
|
|
293
|
+
const returnAll = this.getNodeParameter('returnAll', i);
|
|
294
|
+
const limit = returnAll ? 100 : this.getNodeParameter('limit', i);
|
|
295
|
+
const qs = { limit };
|
|
296
|
+
const allItems = [];
|
|
297
|
+
let continuation;
|
|
298
|
+
do {
|
|
299
|
+
if (continuation)
|
|
300
|
+
qs.continuation = continuation;
|
|
301
|
+
const resp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
302
|
+
method: 'GET',
|
|
303
|
+
url: `/designs/${encodeURIComponent(designId)}/comments/${encodeURIComponent(threadId)}/replies`,
|
|
304
|
+
qs,
|
|
305
|
+
json: true,
|
|
306
|
+
}));
|
|
307
|
+
allItems.push(...((_b = resp.items) !== null && _b !== void 0 ? _b : []));
|
|
308
|
+
continuation = resp.continuation;
|
|
309
|
+
} while (continuation && (returnAll || allItems.length < limit));
|
|
310
|
+
responseData = returnAll ? allItems : allItems.slice(0, limit);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
else if (resource === 'design') {
|
|
314
|
+
if (operation === 'create') {
|
|
315
|
+
const designType = this.getNodeParameter('designType', i);
|
|
316
|
+
const title = this.getNodeParameter('title', i);
|
|
317
|
+
const assetId = this.getNodeParameter('assetId', i);
|
|
318
|
+
let design_type;
|
|
319
|
+
if (designType === 'preset') {
|
|
320
|
+
const presetName = this.getNodeParameter('presetName', i);
|
|
321
|
+
design_type = { type: 'preset', name: presetName };
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
const width = this.getNodeParameter('width', i);
|
|
325
|
+
const height = this.getNodeParameter('height', i);
|
|
326
|
+
design_type = { type: 'custom', width, height };
|
|
327
|
+
}
|
|
328
|
+
const body = { type: 'type_and_asset', design_type };
|
|
329
|
+
if (title)
|
|
330
|
+
body.title = title;
|
|
331
|
+
if (assetId)
|
|
332
|
+
body.asset_id = assetId;
|
|
333
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
334
|
+
method: 'POST',
|
|
335
|
+
url: `/designs`,
|
|
336
|
+
body,
|
|
337
|
+
json: true,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
else if (operation === 'get') {
|
|
341
|
+
const designId = this.getNodeParameter('designId', i);
|
|
342
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
343
|
+
method: 'GET',
|
|
344
|
+
url: `/designs/${encodeURIComponent(designId)}`,
|
|
345
|
+
json: true,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
else if (operation === 'getDataset') {
|
|
349
|
+
const designId = this.getNodeParameter('designId', i);
|
|
350
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
351
|
+
method: 'GET',
|
|
352
|
+
url: `/designs/${encodeURIComponent(designId)}/dataset`,
|
|
353
|
+
json: true,
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
else if (operation === 'getPages') {
|
|
357
|
+
const designId = this.getNodeParameter('designId', i);
|
|
358
|
+
const offset = this.getNodeParameter('offset', i);
|
|
359
|
+
const limit = this.getNodeParameter('limit', i);
|
|
360
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
361
|
+
method: 'GET',
|
|
362
|
+
url: `/designs/${encodeURIComponent(designId)}/pages`,
|
|
363
|
+
qs: { offset, limit },
|
|
364
|
+
json: true,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
else if (operation === 'getExportFormats') {
|
|
368
|
+
const designId = this.getNodeParameter('designId', i);
|
|
369
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
370
|
+
method: 'GET',
|
|
371
|
+
url: `/designs/${encodeURIComponent(designId)}/export-formats`,
|
|
372
|
+
json: true,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
else if (operation === 'getAll') {
|
|
376
|
+
const returnAll = this.getNodeParameter('returnAll', i);
|
|
377
|
+
const limit = returnAll ? 100 : this.getNodeParameter('limit', i);
|
|
378
|
+
const filters = this.getNodeParameter('filters', i);
|
|
379
|
+
const qs = { limit };
|
|
380
|
+
if (filters.query)
|
|
381
|
+
qs.query = filters.query;
|
|
382
|
+
if (filters.ownership)
|
|
383
|
+
qs.ownership = filters.ownership;
|
|
384
|
+
if (filters.sort_by)
|
|
385
|
+
qs.sort_by = filters.sort_by;
|
|
386
|
+
const allItems = [];
|
|
387
|
+
let continuation;
|
|
388
|
+
do {
|
|
389
|
+
if (continuation)
|
|
390
|
+
qs.continuation = continuation;
|
|
391
|
+
const resp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
392
|
+
method: 'GET',
|
|
393
|
+
url: `/designs`,
|
|
394
|
+
qs,
|
|
395
|
+
json: true,
|
|
396
|
+
}));
|
|
397
|
+
allItems.push(...((_c = resp.items) !== null && _c !== void 0 ? _c : []));
|
|
398
|
+
continuation = resp.continuation;
|
|
399
|
+
} while (continuation && (returnAll || allItems.length < limit));
|
|
400
|
+
responseData = returnAll ? allItems : allItems.slice(0, limit);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
else if (resource === 'designImport') {
|
|
404
|
+
if (operation === 'createImport') {
|
|
405
|
+
const url = this.getNodeParameter('url', i);
|
|
406
|
+
const title = this.getNodeParameter('title', i);
|
|
407
|
+
const pollInterval = this.getNodeParameter('pollInterval', i);
|
|
408
|
+
const maxWait = this.getNodeParameter('maxWait', i) * 1000;
|
|
409
|
+
const createResp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
410
|
+
method: 'POST',
|
|
411
|
+
url: `/url-imports`,
|
|
412
|
+
body: { url, title },
|
|
413
|
+
json: true,
|
|
414
|
+
}));
|
|
415
|
+
const importJobId = createResp.job.id;
|
|
416
|
+
const deadline = Date.now() + maxWait;
|
|
417
|
+
let jobResp = createResp;
|
|
418
|
+
while (jobResp.job.status === 'in_progress') {
|
|
419
|
+
if (Date.now() >= deadline) {
|
|
420
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Design import job ${importJobId} timed out after ${maxWait / 1000}s`, { itemIndex: i });
|
|
421
|
+
}
|
|
422
|
+
await (0, n8n_workflow_1.sleep)(pollInterval);
|
|
423
|
+
jobResp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
424
|
+
method: 'GET',
|
|
425
|
+
url: `/url-imports/${importJobId}`,
|
|
426
|
+
json: true,
|
|
427
|
+
}));
|
|
428
|
+
}
|
|
429
|
+
if (jobResp.job.status === 'failed') {
|
|
430
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Design import job ${importJobId} failed`, { itemIndex: i });
|
|
431
|
+
}
|
|
432
|
+
responseData = jobResp;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
else if (resource === 'export') {
|
|
436
|
+
if (operation === 'export') {
|
|
437
|
+
const designId = this.getNodeParameter('designId', i);
|
|
438
|
+
const format = this.getNodeParameter('format', i);
|
|
439
|
+
const pagesRaw = this.getNodeParameter('pages', i);
|
|
440
|
+
const pollInterval = this.getNodeParameter('pollInterval', i);
|
|
441
|
+
const maxWait = this.getNodeParameter('maxWait', i) * 1000;
|
|
442
|
+
const exportFormat = { type: format };
|
|
443
|
+
if (format === 'jpg') {
|
|
444
|
+
exportFormat.quality = this.getNodeParameter('jpgQuality', i);
|
|
445
|
+
}
|
|
446
|
+
else if (format === 'mp4') {
|
|
447
|
+
exportFormat.quality = this.getNodeParameter('mp4Quality', i);
|
|
448
|
+
}
|
|
449
|
+
if (pagesRaw.trim()) {
|
|
450
|
+
exportFormat.pages = pagesRaw
|
|
451
|
+
.split(',')
|
|
452
|
+
.map((p) => parseInt(p.trim(), 10))
|
|
453
|
+
.filter((n) => !isNaN(n));
|
|
454
|
+
}
|
|
455
|
+
const createResp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
456
|
+
method: 'POST',
|
|
457
|
+
url: `/exports`,
|
|
458
|
+
body: { design_id: designId, format: exportFormat },
|
|
459
|
+
json: true,
|
|
460
|
+
}));
|
|
461
|
+
const exportId = createResp.job.id;
|
|
462
|
+
const deadline = Date.now() + maxWait;
|
|
463
|
+
let jobResp = createResp;
|
|
464
|
+
while (jobResp.job.status === 'in_progress') {
|
|
465
|
+
if (Date.now() >= deadline) {
|
|
466
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Export job ${exportId} timed out after ${maxWait / 1000}s`, { itemIndex: i });
|
|
467
|
+
}
|
|
468
|
+
await (0, n8n_workflow_1.sleep)(pollInterval);
|
|
469
|
+
jobResp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
470
|
+
method: 'GET',
|
|
471
|
+
url: `/exports/${exportId}`,
|
|
472
|
+
json: true,
|
|
473
|
+
}));
|
|
474
|
+
}
|
|
475
|
+
if (jobResp.job.status === 'failed') {
|
|
476
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Export job ${exportId} failed`, {
|
|
477
|
+
itemIndex: i,
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
responseData = jobResp;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
else if (resource === 'folder') {
|
|
484
|
+
if (operation === 'create') {
|
|
485
|
+
const name = this.getNodeParameter('name', i);
|
|
486
|
+
const parentFolderId = this.getNodeParameter('parentFolderId', i);
|
|
487
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
488
|
+
method: 'POST',
|
|
489
|
+
url: `/folders`,
|
|
490
|
+
body: { name, parent_folder_id: parentFolderId },
|
|
491
|
+
json: true,
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
else if (operation === 'delete') {
|
|
495
|
+
const folderId = this.getNodeParameter('folderId', i);
|
|
496
|
+
await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
497
|
+
method: 'DELETE',
|
|
498
|
+
url: `/folders/${encodeURIComponent(folderId)}`,
|
|
499
|
+
json: true,
|
|
500
|
+
});
|
|
501
|
+
responseData = { success: true };
|
|
502
|
+
}
|
|
503
|
+
else if (operation === 'get') {
|
|
504
|
+
const folderId = this.getNodeParameter('folderId', i);
|
|
505
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
506
|
+
method: 'GET',
|
|
507
|
+
url: `/folders/${encodeURIComponent(folderId)}`,
|
|
508
|
+
json: true,
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
else if (operation === 'listItems') {
|
|
512
|
+
const folderId = this.getNodeParameter('folderId', i);
|
|
513
|
+
const returnAll = this.getNodeParameter('returnAll', i);
|
|
514
|
+
const limit = returnAll ? 100 : this.getNodeParameter('limit', i);
|
|
515
|
+
const filters = this.getNodeParameter('filters', i);
|
|
516
|
+
const qs = { limit };
|
|
517
|
+
if (filters.sort_by)
|
|
518
|
+
qs.sort_by = filters.sort_by;
|
|
519
|
+
if (Array.isArray(filters.item_types) && filters.item_types.length > 0) {
|
|
520
|
+
qs.item_types = filters.item_types.join(',');
|
|
521
|
+
}
|
|
522
|
+
const allItems = [];
|
|
523
|
+
let continuation;
|
|
524
|
+
do {
|
|
525
|
+
if (continuation)
|
|
526
|
+
qs.continuation = continuation;
|
|
527
|
+
const resp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
528
|
+
method: 'GET',
|
|
529
|
+
url: `/folders/${encodeURIComponent(folderId)}/items`,
|
|
530
|
+
qs,
|
|
531
|
+
json: true,
|
|
532
|
+
}));
|
|
533
|
+
allItems.push(...((_d = resp.items) !== null && _d !== void 0 ? _d : []));
|
|
534
|
+
continuation = resp.continuation;
|
|
535
|
+
} while (continuation && (returnAll || allItems.length < limit));
|
|
536
|
+
responseData = returnAll ? allItems : allItems.slice(0, limit);
|
|
537
|
+
}
|
|
538
|
+
else if (operation === 'moveItem') {
|
|
539
|
+
const itemId = this.getNodeParameter('itemId', i);
|
|
540
|
+
const toFolderId = this.getNodeParameter('toFolderId', i);
|
|
541
|
+
await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
542
|
+
method: 'POST',
|
|
543
|
+
url: `/folders/move`,
|
|
544
|
+
body: {
|
|
545
|
+
item_id: itemId,
|
|
546
|
+
to_folder_id: toFolderId,
|
|
547
|
+
},
|
|
548
|
+
json: true,
|
|
549
|
+
});
|
|
550
|
+
responseData = { success: true };
|
|
551
|
+
}
|
|
552
|
+
else if (operation === 'update') {
|
|
553
|
+
const folderId = this.getNodeParameter('folderId', i);
|
|
554
|
+
const name = this.getNodeParameter('name', i);
|
|
555
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
556
|
+
method: 'PATCH',
|
|
557
|
+
url: `/folders/${encodeURIComponent(folderId)}`,
|
|
558
|
+
body: { name },
|
|
559
|
+
json: true,
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
else if (resource === 'merge') {
|
|
564
|
+
if (operation === 'create') {
|
|
565
|
+
const mergeType = this.getNodeParameter('mergeType', i);
|
|
566
|
+
const operationsRaw = this.getNodeParameter('operations', i);
|
|
567
|
+
const pollInterval = this.getNodeParameter('pollInterval', i);
|
|
568
|
+
const maxWait = this.getNodeParameter('maxWait', i) * 1000;
|
|
569
|
+
let operations;
|
|
570
|
+
try {
|
|
571
|
+
operations =
|
|
572
|
+
typeof operationsRaw === 'string'
|
|
573
|
+
? JSON.parse(operationsRaw)
|
|
574
|
+
: operationsRaw;
|
|
575
|
+
}
|
|
576
|
+
catch {
|
|
577
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'The "Operations" field is not valid JSON', { itemIndex: i });
|
|
578
|
+
}
|
|
579
|
+
const body = { type: mergeType, operations };
|
|
580
|
+
if (mergeType === 'create_new_design') {
|
|
581
|
+
const title = this.getNodeParameter('title', i);
|
|
582
|
+
body.title = title;
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
const designId = this.getNodeParameter('designId', i);
|
|
586
|
+
const optionalTitle = this.getNodeParameter('optionalTitle', i);
|
|
587
|
+
body.design_id = designId;
|
|
588
|
+
if (optionalTitle)
|
|
589
|
+
body.title = optionalTitle;
|
|
590
|
+
}
|
|
591
|
+
const createResp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
592
|
+
method: 'POST',
|
|
593
|
+
url: `/merges`,
|
|
594
|
+
body,
|
|
595
|
+
json: true,
|
|
596
|
+
}));
|
|
597
|
+
const mergeJobId = createResp.job.id;
|
|
598
|
+
const deadline = Date.now() + maxWait;
|
|
599
|
+
let jobResp = createResp;
|
|
600
|
+
while (jobResp.job.status === 'in_progress') {
|
|
601
|
+
if (Date.now() >= deadline) {
|
|
602
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Merge job ${mergeJobId} timed out after ${maxWait / 1000}s`, { itemIndex: i });
|
|
603
|
+
}
|
|
604
|
+
await (0, n8n_workflow_1.sleep)(pollInterval);
|
|
605
|
+
jobResp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
606
|
+
method: 'GET',
|
|
607
|
+
url: `/merges/${mergeJobId}`,
|
|
608
|
+
json: true,
|
|
609
|
+
}));
|
|
610
|
+
}
|
|
611
|
+
if (jobResp.job.status === 'failed') {
|
|
612
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Merge job ${mergeJobId} failed`, {
|
|
613
|
+
itemIndex: i,
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
responseData = jobResp;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
else if (resource === 'resize') {
|
|
620
|
+
if (operation === 'create') {
|
|
621
|
+
const designId = this.getNodeParameter('designId', i);
|
|
622
|
+
const designType = this.getNodeParameter('designType', i);
|
|
623
|
+
const pollInterval = this.getNodeParameter('pollInterval', i);
|
|
624
|
+
const maxWait = this.getNodeParameter('maxWait', i) * 1000;
|
|
625
|
+
let design_type;
|
|
626
|
+
if (designType === 'preset') {
|
|
627
|
+
const presetName = this.getNodeParameter('presetName', i);
|
|
628
|
+
design_type = { type: 'preset', name: presetName };
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
const width = this.getNodeParameter('width', i);
|
|
632
|
+
const height = this.getNodeParameter('height', i);
|
|
633
|
+
design_type = { type: 'custom', width, height };
|
|
634
|
+
}
|
|
635
|
+
const createResp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
636
|
+
method: 'POST',
|
|
637
|
+
url: `/resizes`,
|
|
638
|
+
body: { design_id: designId, design_type },
|
|
639
|
+
json: true,
|
|
640
|
+
}));
|
|
641
|
+
const resizeJobId = createResp.job.id;
|
|
642
|
+
const deadline = Date.now() + maxWait;
|
|
643
|
+
let jobResp = createResp;
|
|
644
|
+
while (jobResp.job.status === 'in_progress') {
|
|
645
|
+
if (Date.now() >= deadline) {
|
|
646
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Resize job ${resizeJobId} timed out after ${maxWait / 1000}s`, { itemIndex: i });
|
|
647
|
+
}
|
|
648
|
+
await (0, n8n_workflow_1.sleep)(pollInterval);
|
|
649
|
+
jobResp = (await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
650
|
+
method: 'GET',
|
|
651
|
+
url: `/resizes/${resizeJobId}`,
|
|
652
|
+
json: true,
|
|
653
|
+
}));
|
|
654
|
+
}
|
|
655
|
+
if (jobResp.job.status === 'failed') {
|
|
656
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Resize job ${resizeJobId} failed`, {
|
|
657
|
+
itemIndex: i,
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
responseData = jobResp;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
else if (resource === 'user') {
|
|
664
|
+
if (operation === 'getCapabilities') {
|
|
665
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
666
|
+
method: 'GET',
|
|
667
|
+
url: `/users/me/capabilities`,
|
|
668
|
+
json: true,
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
else if (operation === 'getMe') {
|
|
672
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
673
|
+
method: 'GET',
|
|
674
|
+
url: `/users/me`,
|
|
675
|
+
json: true,
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
else if (operation === 'getProfile') {
|
|
679
|
+
responseData = await (0, GenericFunctions_1.canvaApiRequest)(this, {
|
|
680
|
+
method: 'GET',
|
|
681
|
+
url: `/users/me/profile`,
|
|
682
|
+
json: true,
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
if (responseData === undefined) {
|
|
687
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation "${operation}" for resource "${resource}"`, { itemIndex: i });
|
|
688
|
+
}
|
|
689
|
+
if (Array.isArray(responseData)) {
|
|
690
|
+
returnData.push(...this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } }));
|
|
691
|
+
}
|
|
692
|
+
else {
|
|
693
|
+
returnData.push({
|
|
694
|
+
json: responseData,
|
|
695
|
+
pairedItem: { item: i },
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
catch (error) {
|
|
700
|
+
if (this.continueOnFail()) {
|
|
701
|
+
returnData.push({
|
|
702
|
+
json: { error: error.message },
|
|
703
|
+
pairedItem: { item: i },
|
|
704
|
+
});
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
if (error instanceof n8n_workflow_1.NodeOperationError) {
|
|
708
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
|
|
709
|
+
}
|
|
710
|
+
throw new n8n_workflow_1.NodeApiError(this.getNode(), error, { itemIndex: i });
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
return [returnData];
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
exports.Canva = Canva;
|
|
717
|
+
//# sourceMappingURL=Canva.node.js.map
|