n8n-nodes-cribops 0.1.20 → 0.1.24
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.
|
@@ -25,13 +25,6 @@ class CribopsApi {
|
|
|
25
25
|
required: true,
|
|
26
26
|
description: 'Base URL of the Cribops API',
|
|
27
27
|
},
|
|
28
|
-
{
|
|
29
|
-
displayName: 'Organization ID',
|
|
30
|
-
name: 'organizationId',
|
|
31
|
-
type: 'string',
|
|
32
|
-
default: '',
|
|
33
|
-
description: 'Organization ID (optional - if not provided, will use the default organization for the API token)',
|
|
34
|
-
},
|
|
35
28
|
];
|
|
36
29
|
authenticate = {
|
|
37
30
|
type: 'generic',
|
|
@@ -109,9 +109,8 @@ class CribopsTrigger {
|
|
|
109
109
|
apiToken: credentials.apiToken,
|
|
110
110
|
});
|
|
111
111
|
try {
|
|
112
|
-
//
|
|
113
|
-
const
|
|
114
|
-
const webhooks = await cribopsHttp.getWebhooks(organizationId);
|
|
112
|
+
// Organization is automatically determined from API key
|
|
113
|
+
const webhooks = await cribopsHttp.getWebhooks();
|
|
115
114
|
// Filter for N8N type webhooks that are active and not linked
|
|
116
115
|
const availableWebhooks = webhooks.filter((webhook) => webhook.type === 'N8N' &&
|
|
117
116
|
webhook.status === 'active' &&
|
|
@@ -123,7 +122,27 @@ class CribopsTrigger {
|
|
|
123
122
|
}));
|
|
124
123
|
}
|
|
125
124
|
catch (error) {
|
|
126
|
-
|
|
125
|
+
let errorMessage = 'Failed to load webhooks';
|
|
126
|
+
if (error instanceof Error) {
|
|
127
|
+
errorMessage += `: ${error.message}`;
|
|
128
|
+
// Check for common issues
|
|
129
|
+
if (error.message.includes('HTTP 401') || error.message.includes('Unauthorized')) {
|
|
130
|
+
errorMessage = 'Authentication failed. Please check your API token in the credentials.';
|
|
131
|
+
}
|
|
132
|
+
else if (error.message.includes('HTTP 404')) {
|
|
133
|
+
errorMessage = 'Webhook endpoint not found. Please check the API base URL in credentials.';
|
|
134
|
+
}
|
|
135
|
+
else if (error.message.includes('HTTP 403')) {
|
|
136
|
+
errorMessage = 'Access forbidden. Your API token may not have permission to access webhooks.';
|
|
137
|
+
}
|
|
138
|
+
else if (error.message.includes('Failed to fetch') || error.message.includes('network')) {
|
|
139
|
+
errorMessage = 'Network error. Please check the API base URL and ensure the Cribops API is accessible.';
|
|
140
|
+
}
|
|
141
|
+
else if (error.message.includes('HTTP 400')) {
|
|
142
|
+
errorMessage = 'Bad request. Please check that the API endpoint is correct and your API token has the necessary permissions.';
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
127
146
|
}
|
|
128
147
|
},
|
|
129
148
|
},
|
package/dist/package.json
CHANGED
|
@@ -69,7 +69,7 @@ export declare class CribopsHttp {
|
|
|
69
69
|
status: string;
|
|
70
70
|
updated_count: number;
|
|
71
71
|
}>;
|
|
72
|
-
getWebhooks(
|
|
72
|
+
getWebhooks(): Promise<CribopsWebhookEntity[]>;
|
|
73
73
|
linkWebhook(webhookId: string, linkData: {
|
|
74
74
|
workflow_id: string;
|
|
75
75
|
webhook_url: string;
|
|
@@ -11,10 +11,10 @@ class CribopsHttp {
|
|
|
11
11
|
}
|
|
12
12
|
async makeRequest(method, endpoint, data, options) {
|
|
13
13
|
let url = `${this.config.baseUrl}${endpoint}`;
|
|
14
|
-
// Handle query parameters
|
|
15
|
-
if (method === 'GET' && data
|
|
14
|
+
// Handle query parameters for GET requests
|
|
15
|
+
if (method === 'GET' && data && Object.keys(data).length > 0) {
|
|
16
16
|
const params = new URLSearchParams();
|
|
17
|
-
Object.entries(data
|
|
17
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
18
18
|
if (value !== undefined && value !== null) {
|
|
19
19
|
params.append(key, String(value));
|
|
20
20
|
}
|
|
@@ -23,7 +23,8 @@ class CribopsHttp {
|
|
|
23
23
|
if (queryString) {
|
|
24
24
|
url += `?${queryString}`;
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
// Clear data for GET requests as params are in URL
|
|
27
|
+
data = undefined;
|
|
27
28
|
}
|
|
28
29
|
const requestHeaders = {
|
|
29
30
|
'Authorization': `Bearer ${this.config.apiToken}`,
|
|
@@ -42,8 +43,17 @@ class CribopsHttp {
|
|
|
42
43
|
body: (method !== 'GET' && data) ? JSON.stringify(data) : undefined,
|
|
43
44
|
});
|
|
44
45
|
if (!response.ok) {
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
let errorText = await response.text();
|
|
47
|
+
let errorDetail = '';
|
|
48
|
+
// Try to parse error response as JSON
|
|
49
|
+
try {
|
|
50
|
+
const errorJson = JSON.parse(errorText);
|
|
51
|
+
errorDetail = errorJson.message || errorJson.error || errorText;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
errorDetail = errorText;
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`HTTP ${response.status}: ${errorDetail}`);
|
|
47
57
|
}
|
|
48
58
|
const result = await response.json();
|
|
49
59
|
return result;
|
|
@@ -87,8 +97,17 @@ class CribopsHttp {
|
|
|
87
97
|
},
|
|
88
98
|
});
|
|
89
99
|
if (!response.ok) {
|
|
90
|
-
|
|
91
|
-
|
|
100
|
+
let errorText = await response.text();
|
|
101
|
+
let errorDetail = '';
|
|
102
|
+
// Try to parse error response as JSON
|
|
103
|
+
try {
|
|
104
|
+
const errorJson = JSON.parse(errorText);
|
|
105
|
+
errorDetail = errorJson.message || errorJson.error || errorText;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
errorDetail = errorText;
|
|
109
|
+
}
|
|
110
|
+
throw new Error(`HTTP ${response.status}: ${errorDetail}`);
|
|
92
111
|
}
|
|
93
112
|
const arrayBuffer = await response.arrayBuffer();
|
|
94
113
|
return Buffer.from(arrayBuffer);
|
|
@@ -159,11 +178,25 @@ class CribopsHttp {
|
|
|
159
178
|
}
|
|
160
179
|
}
|
|
161
180
|
// Webhook-specific methods
|
|
162
|
-
async getWebhooks(
|
|
181
|
+
async getWebhooks() {
|
|
163
182
|
try {
|
|
164
|
-
|
|
165
|
-
const response = await this.makeRequest('GET', '/api/v1/webhooks'
|
|
166
|
-
|
|
183
|
+
// Organization is automatically determined from API key
|
|
184
|
+
const response = await this.makeRequest('GET', '/api/v1/webhooks');
|
|
185
|
+
// Handle different response structures
|
|
186
|
+
// The API might return webhooks directly as array or wrapped in data property
|
|
187
|
+
if (Array.isArray(response)) {
|
|
188
|
+
return response;
|
|
189
|
+
}
|
|
190
|
+
else if (response.data && Array.isArray(response.data)) {
|
|
191
|
+
return response.data;
|
|
192
|
+
}
|
|
193
|
+
else if (response.webhooks && Array.isArray(response.webhooks)) {
|
|
194
|
+
return response.webhooks;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
// If we can't find webhooks, return empty array
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
167
200
|
}
|
|
168
201
|
catch (error) {
|
|
169
202
|
throw new Error(`Failed to fetch webhooks: ${error}`);
|