n8n-nodes-n8ndesigner-salla-n8nai 0.3.161 → 0.3.162
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/package.json +5 -10
- package/dist/nodes/Customers/DeleteCustomer.node.d.ts +0 -8
- package/dist/nodes/Customers/DeleteCustomer.node.js +0 -304
- package/dist/nodes/Orders/UpdateOrderStatus.node.d.ts +0 -8
- package/dist/nodes/Orders/UpdateOrderStatus.node.js +0 -359
- package/dist/nodes/Triggers/CustomerCreatedTrigger.node.d.ts +0 -8
- package/dist/nodes/Triggers/CustomerCreatedTrigger.node.js +0 -150
- package/dist/nodes/Triggers/OrderStatusUpdatedTrigger.node.d.ts +0 -8
- package/dist/nodes/Triggers/OrderStatusUpdatedTrigger.node.js +0 -150
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-n8ndesigner-salla-n8nai",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.162",
|
|
4
4
|
"description": "Salla nodes for n8n (Actions + Triggers)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -29,15 +29,10 @@
|
|
|
29
29
|
"n8n-workflow": "^1.116.0"
|
|
30
30
|
},
|
|
31
31
|
"n8n": {
|
|
32
|
-
"nodes": [
|
|
33
|
-
"dist/nodes/Actions/SallaActions.node.js",
|
|
34
|
-
"dist/nodes/
|
|
35
|
-
|
|
36
|
-
"dist/nodes/Triggers/OrderStatusUpdatedTrigger.node.js",
|
|
37
|
-
"dist/nodes/Triggers/CustomerCreatedTrigger.node.js",
|
|
38
|
-
"dist/nodes/Triggers/SallaTriggers.node.js",
|
|
39
|
-
"dist/nodes/Triggers/SallaTrigger.node.js"
|
|
40
|
-
],
|
|
32
|
+
"nodes": [
|
|
33
|
+
"dist/nodes/Actions/SallaActions.node.js",
|
|
34
|
+
"dist/nodes/Triggers/SallaTrigger.node.js"
|
|
35
|
+
],
|
|
41
36
|
"credentials": [
|
|
42
37
|
"dist/credentials/SallaActionsApi.credentials.js"
|
|
43
38
|
]
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { INodeType, INodeTypeDescription, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
|
2
|
-
|
|
3
|
-
declare class DeleteCustomer implements INodeType {
|
|
4
|
-
description: INodeTypeDescription;
|
|
5
|
-
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export { DeleteCustomer };
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// nodes/Customers/DeleteCustomer.node.ts
|
|
21
|
-
var DeleteCustomer_node_exports = {};
|
|
22
|
-
__export(DeleteCustomer_node_exports, {
|
|
23
|
-
DeleteCustomer: () => DeleteCustomer
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(DeleteCustomer_node_exports);
|
|
26
|
-
var import_n8n_workflow2 = require("n8n-workflow");
|
|
27
|
-
|
|
28
|
-
// shared/constants.ts
|
|
29
|
-
var SALLA_CREDENTIAL_NAME = "sallaActionsApi";
|
|
30
|
-
var DEFAULT_BASE_URL = "https://app.n8ndesigner.com";
|
|
31
|
-
var SALLA_BRAND_COLOR = "#00C58E";
|
|
32
|
-
|
|
33
|
-
// shared/httpClient.ts
|
|
34
|
-
var import_n8n_workflow = require("n8n-workflow");
|
|
35
|
-
var DEFAULT_TIMEOUT = 12e3;
|
|
36
|
-
var RETRY_DELAYS = [1e3, 3e3];
|
|
37
|
-
var RETRY_ERROR_CODES = /* @__PURE__ */ new Set(["ETIMEDOUT", "ECONNRESET"]);
|
|
38
|
-
function trimTrailingSlash(input) {
|
|
39
|
-
const value = input && input.trim() !== "" ? input : DEFAULT_BASE_URL;
|
|
40
|
-
return value.replace(/\/+$/, "");
|
|
41
|
-
}
|
|
42
|
-
function ensureLeadingSlash(path) {
|
|
43
|
-
if (!path.startsWith("/")) {
|
|
44
|
-
return "/" + path;
|
|
45
|
-
}
|
|
46
|
-
return path;
|
|
47
|
-
}
|
|
48
|
-
function buildActionsUrl(baseUrl, path) {
|
|
49
|
-
const normalizedBase = trimTrailingSlash(baseUrl);
|
|
50
|
-
return normalizedBase + "/api/actions" + ensureLeadingSlash(path);
|
|
51
|
-
}
|
|
52
|
-
function buildProxyUrl(baseUrl) {
|
|
53
|
-
const normalizedBase = trimTrailingSlash(baseUrl);
|
|
54
|
-
return normalizedBase + "/api/merchant/salla";
|
|
55
|
-
}
|
|
56
|
-
function normalizeResponse(rawBody, statusCode) {
|
|
57
|
-
const raw = rawBody ?? null;
|
|
58
|
-
if (rawBody === void 0 || rawBody === null || rawBody === "") {
|
|
59
|
-
return {
|
|
60
|
-
ok: statusCode >= 200 && statusCode < 300,
|
|
61
|
-
status: statusCode,
|
|
62
|
-
data: null,
|
|
63
|
-
error: statusCode >= 400 ? "Request failed with status " + statusCode : null,
|
|
64
|
-
raw
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
if (typeof rawBody !== "object") {
|
|
68
|
-
return {
|
|
69
|
-
ok: statusCode >= 200 && statusCode < 300,
|
|
70
|
-
status: statusCode,
|
|
71
|
-
data: rawBody,
|
|
72
|
-
error: statusCode >= 400 ? String(rawBody) : null,
|
|
73
|
-
raw
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
const body = rawBody;
|
|
77
|
-
const successFlag = typeof body.success === "boolean" ? body.success : void 0;
|
|
78
|
-
const okFlag = typeof body.ok === "boolean" ? body.ok : void 0;
|
|
79
|
-
const status = typeof body.status === "number" ? body.status : statusCode;
|
|
80
|
-
const ok = okFlag ?? successFlag ?? (status >= 200 && status < 300);
|
|
81
|
-
let data = null;
|
|
82
|
-
if (Object.prototype.hasOwnProperty.call(body, "data")) {
|
|
83
|
-
data = body.data ?? null;
|
|
84
|
-
}
|
|
85
|
-
const errors = body.errors;
|
|
86
|
-
if (errors) {
|
|
87
|
-
if (data && typeof data === "object") {
|
|
88
|
-
data = {
|
|
89
|
-
...data,
|
|
90
|
-
errors
|
|
91
|
-
};
|
|
92
|
-
} else {
|
|
93
|
-
data = { errors };
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
let error = null;
|
|
97
|
-
if (typeof body.error === "string") {
|
|
98
|
-
error = body.error;
|
|
99
|
-
} else if (!ok) {
|
|
100
|
-
if (typeof body.message === "string" && body.message.trim() !== "") {
|
|
101
|
-
error = body.message;
|
|
102
|
-
} else if (body.error && typeof body.error === "object") {
|
|
103
|
-
error = JSON.stringify(body.error);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (!ok && !error) {
|
|
107
|
-
error = "Request failed with status " + status;
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
ok,
|
|
111
|
-
status,
|
|
112
|
-
data: data ?? null,
|
|
113
|
-
error,
|
|
114
|
-
raw
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
function shouldRetryStatus(status) {
|
|
118
|
-
return status === 429 || status >= 500;
|
|
119
|
-
}
|
|
120
|
-
function shouldRetryError(error) {
|
|
121
|
-
if (!error || typeof error !== "object") {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
const err = error;
|
|
125
|
-
const status = err.statusCode ?? err.response?.statusCode;
|
|
126
|
-
if (typeof status === "number" && shouldRetryStatus(status)) {
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
const code = err.code ?? err.cause?.code;
|
|
130
|
-
return code ? RETRY_ERROR_CODES.has(code) : false;
|
|
131
|
-
}
|
|
132
|
-
async function executeWithRetry(caller, requestOptions) {
|
|
133
|
-
let lastError;
|
|
134
|
-
for (let attempt = 0; attempt <= RETRY_DELAYS.length; attempt++) {
|
|
135
|
-
try {
|
|
136
|
-
const response = await caller(requestOptions);
|
|
137
|
-
const normalized = normalizeResponse(response.body, response.statusCode);
|
|
138
|
-
if (shouldRetryStatus(normalized.status) && attempt < RETRY_DELAYS.length) {
|
|
139
|
-
await (0, import_n8n_workflow.sleep)(RETRY_DELAYS[attempt]);
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
return normalized;
|
|
143
|
-
} catch (error) {
|
|
144
|
-
lastError = error;
|
|
145
|
-
if (attempt < RETRY_DELAYS.length && shouldRetryError(error)) {
|
|
146
|
-
await (0, import_n8n_workflow.sleep)(RETRY_DELAYS[attempt]);
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (lastError && typeof lastError === "object") {
|
|
153
|
-
const err = lastError;
|
|
154
|
-
const status = err.statusCode ?? err.response?.statusCode ?? 0;
|
|
155
|
-
const body = err.response?.body;
|
|
156
|
-
const fallback = normalizeResponse(body, status || 0);
|
|
157
|
-
if (fallback.error && err.message && !fallback.error.includes(err.message)) {
|
|
158
|
-
fallback.error = fallback.error + ". " + err.message;
|
|
159
|
-
} else if (!fallback.error) {
|
|
160
|
-
fallback.error = err.message ?? "Request failed";
|
|
161
|
-
}
|
|
162
|
-
return fallback;
|
|
163
|
-
}
|
|
164
|
-
return {
|
|
165
|
-
ok: false,
|
|
166
|
-
status: 0,
|
|
167
|
-
data: null,
|
|
168
|
-
error: lastError instanceof Error ? lastError.message : "Request failed",
|
|
169
|
-
raw: null
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
function buildCaller(context, credentialType) {
|
|
173
|
-
return async (options) => {
|
|
174
|
-
const response = await context.helpers.requestWithAuthentication.call(
|
|
175
|
-
context,
|
|
176
|
-
credentialType,
|
|
177
|
-
options
|
|
178
|
-
);
|
|
179
|
-
return {
|
|
180
|
-
statusCode: response.statusCode,
|
|
181
|
-
body: response.body,
|
|
182
|
-
headers: response.headers
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function createSallaActionsClient(context, credentials, credentialType = SALLA_CREDENTIAL_NAME) {
|
|
187
|
-
const caller = buildCaller(context, credentialType);
|
|
188
|
-
async function request(options) {
|
|
189
|
-
const requestOptions = {
|
|
190
|
-
method: options.method,
|
|
191
|
-
url: buildActionsUrl(credentials.baseUrl, options.path),
|
|
192
|
-
qs: options.qs,
|
|
193
|
-
body: options.body,
|
|
194
|
-
headers: options.headers,
|
|
195
|
-
json: true,
|
|
196
|
-
timeout: DEFAULT_TIMEOUT
|
|
197
|
-
};
|
|
198
|
-
const advanced = requestOptions;
|
|
199
|
-
advanced["returnFullResponse"] = true;
|
|
200
|
-
advanced["resolveWithFullResponse"] = true;
|
|
201
|
-
advanced["ignoreHttpStatusErrors"] = true;
|
|
202
|
-
return executeWithRetry(caller, requestOptions);
|
|
203
|
-
}
|
|
204
|
-
async function proxy(options) {
|
|
205
|
-
const requestOptions = {
|
|
206
|
-
method: "POST",
|
|
207
|
-
url: buildProxyUrl(credentials.baseUrl),
|
|
208
|
-
body: {
|
|
209
|
-
salla_merchant_id: credentials.salla_merchant_id,
|
|
210
|
-
method: options.method,
|
|
211
|
-
path: options.path,
|
|
212
|
-
payload: options.payload ?? null
|
|
213
|
-
},
|
|
214
|
-
json: true,
|
|
215
|
-
timeout: DEFAULT_TIMEOUT
|
|
216
|
-
};
|
|
217
|
-
const advanced = requestOptions;
|
|
218
|
-
advanced["returnFullResponse"] = true;
|
|
219
|
-
advanced["resolveWithFullResponse"] = true;
|
|
220
|
-
advanced["ignoreHttpStatusErrors"] = true;
|
|
221
|
-
return executeWithRetry(caller, requestOptions);
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
request,
|
|
225
|
-
proxy
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// nodes/Customers/DeleteCustomer.node.ts
|
|
230
|
-
var DeleteCustomer = class {
|
|
231
|
-
constructor() {
|
|
232
|
-
this.description = {
|
|
233
|
-
displayName: "Delete Customer (Deprecated)",
|
|
234
|
-
name: "sallaDeleteCustomer",
|
|
235
|
-
group: ["transform"],
|
|
236
|
-
version: 1,
|
|
237
|
-
icon: "file:assets/salla-logo.svg",
|
|
238
|
-
description: "Deprecated – use Salla Actions node instead.",
|
|
239
|
-
defaults: {
|
|
240
|
-
name: "Delete Customer (Deprecated)",
|
|
241
|
-
color: SALLA_BRAND_COLOR
|
|
242
|
-
},
|
|
243
|
-
inputs: ["main"],
|
|
244
|
-
outputs: ["main"],
|
|
245
|
-
credentials: [
|
|
246
|
-
{
|
|
247
|
-
name: SALLA_CREDENTIAL_NAME,
|
|
248
|
-
required: true
|
|
249
|
-
}
|
|
250
|
-
],
|
|
251
|
-
properties: [
|
|
252
|
-
{
|
|
253
|
-
displayName: "Customer ID",
|
|
254
|
-
name: "customerId",
|
|
255
|
-
type: "string",
|
|
256
|
-
required: true,
|
|
257
|
-
default: "",
|
|
258
|
-
description: "Numeric or string identifier of the customer to delete."
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
displayName: "Warning",
|
|
262
|
-
name: "deleteWarning",
|
|
263
|
-
type: "notice",
|
|
264
|
-
default: "This action permanently deletes the customer from Salla."
|
|
265
|
-
}
|
|
266
|
-
]
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
async execute() {
|
|
270
|
-
const items = this.getInputData();
|
|
271
|
-
const returnItems = [];
|
|
272
|
-
const credentials = await this.getCredentials(
|
|
273
|
-
SALLA_CREDENTIAL_NAME
|
|
274
|
-
);
|
|
275
|
-
const client = createSallaActionsClient(this, credentials);
|
|
276
|
-
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
|
277
|
-
const customerId = this.getNodeParameter("customerId", itemIndex);
|
|
278
|
-
const body = null;
|
|
279
|
-
const response = await client.request({
|
|
280
|
-
method: "DELETE",
|
|
281
|
-
path: "/customers/" + encodeURIComponent(String(customerId))});
|
|
282
|
-
if (!response.ok) {
|
|
283
|
-
throw new import_n8n_workflow2.NodeOperationError(this.getNode(), response.error ?? "Salla Actions request failed", {
|
|
284
|
-
itemIndex,
|
|
285
|
-
description: response.raw ? JSON.stringify(response.raw, null, 2) : void 0
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
returnItems.push({
|
|
289
|
-
json: {
|
|
290
|
-
ok: response.ok,
|
|
291
|
-
status: response.status,
|
|
292
|
-
data: response.data ?? null,
|
|
293
|
-
raw: response.raw ?? null
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
return [returnItems];
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
301
|
-
0 && (module.exports = {
|
|
302
|
-
DeleteCustomer
|
|
303
|
-
});
|
|
304
|
-
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { INodeType, INodeTypeDescription, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
|
2
|
-
|
|
3
|
-
declare class UpdateOrderStatus implements INodeType {
|
|
4
|
-
description: INodeTypeDescription;
|
|
5
|
-
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export { UpdateOrderStatus };
|
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// nodes/Orders/UpdateOrderStatus.node.ts
|
|
21
|
-
var UpdateOrderStatus_node_exports = {};
|
|
22
|
-
__export(UpdateOrderStatus_node_exports, {
|
|
23
|
-
UpdateOrderStatus: () => UpdateOrderStatus
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(UpdateOrderStatus_node_exports);
|
|
26
|
-
var import_n8n_workflow2 = require("n8n-workflow");
|
|
27
|
-
|
|
28
|
-
// shared/constants.ts
|
|
29
|
-
var SALLA_CREDENTIAL_NAME = "sallaActionsApi";
|
|
30
|
-
var DEFAULT_BASE_URL = "https://app.n8ndesigner.com";
|
|
31
|
-
var SALLA_BRAND_COLOR = "#00C58E";
|
|
32
|
-
|
|
33
|
-
// shared/httpClient.ts
|
|
34
|
-
var import_n8n_workflow = require("n8n-workflow");
|
|
35
|
-
var DEFAULT_TIMEOUT = 12e3;
|
|
36
|
-
var RETRY_DELAYS = [1e3, 3e3];
|
|
37
|
-
var RETRY_ERROR_CODES = /* @__PURE__ */ new Set(["ETIMEDOUT", "ECONNRESET"]);
|
|
38
|
-
function trimTrailingSlash(input) {
|
|
39
|
-
const value = input && input.trim() !== "" ? input : DEFAULT_BASE_URL;
|
|
40
|
-
return value.replace(/\/+$/, "");
|
|
41
|
-
}
|
|
42
|
-
function ensureLeadingSlash(path) {
|
|
43
|
-
if (!path.startsWith("/")) {
|
|
44
|
-
return "/" + path;
|
|
45
|
-
}
|
|
46
|
-
return path;
|
|
47
|
-
}
|
|
48
|
-
function buildActionsUrl(baseUrl, path) {
|
|
49
|
-
const normalizedBase = trimTrailingSlash(baseUrl);
|
|
50
|
-
return normalizedBase + "/api/actions" + ensureLeadingSlash(path);
|
|
51
|
-
}
|
|
52
|
-
function buildProxyUrl(baseUrl) {
|
|
53
|
-
const normalizedBase = trimTrailingSlash(baseUrl);
|
|
54
|
-
return normalizedBase + "/api/merchant/salla";
|
|
55
|
-
}
|
|
56
|
-
function normalizeResponse(rawBody, statusCode) {
|
|
57
|
-
const raw = rawBody ?? null;
|
|
58
|
-
if (rawBody === void 0 || rawBody === null || rawBody === "") {
|
|
59
|
-
return {
|
|
60
|
-
ok: statusCode >= 200 && statusCode < 300,
|
|
61
|
-
status: statusCode,
|
|
62
|
-
data: null,
|
|
63
|
-
error: statusCode >= 400 ? "Request failed with status " + statusCode : null,
|
|
64
|
-
raw
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
if (typeof rawBody !== "object") {
|
|
68
|
-
return {
|
|
69
|
-
ok: statusCode >= 200 && statusCode < 300,
|
|
70
|
-
status: statusCode,
|
|
71
|
-
data: rawBody,
|
|
72
|
-
error: statusCode >= 400 ? String(rawBody) : null,
|
|
73
|
-
raw
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
const body = rawBody;
|
|
77
|
-
const successFlag = typeof body.success === "boolean" ? body.success : void 0;
|
|
78
|
-
const okFlag = typeof body.ok === "boolean" ? body.ok : void 0;
|
|
79
|
-
const status = typeof body.status === "number" ? body.status : statusCode;
|
|
80
|
-
const ok = okFlag ?? successFlag ?? (status >= 200 && status < 300);
|
|
81
|
-
let data = null;
|
|
82
|
-
if (Object.prototype.hasOwnProperty.call(body, "data")) {
|
|
83
|
-
data = body.data ?? null;
|
|
84
|
-
}
|
|
85
|
-
const errors = body.errors;
|
|
86
|
-
if (errors) {
|
|
87
|
-
if (data && typeof data === "object") {
|
|
88
|
-
data = {
|
|
89
|
-
...data,
|
|
90
|
-
errors
|
|
91
|
-
};
|
|
92
|
-
} else {
|
|
93
|
-
data = { errors };
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
let error = null;
|
|
97
|
-
if (typeof body.error === "string") {
|
|
98
|
-
error = body.error;
|
|
99
|
-
} else if (!ok) {
|
|
100
|
-
if (typeof body.message === "string" && body.message.trim() !== "") {
|
|
101
|
-
error = body.message;
|
|
102
|
-
} else if (body.error && typeof body.error === "object") {
|
|
103
|
-
error = JSON.stringify(body.error);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (!ok && !error) {
|
|
107
|
-
error = "Request failed with status " + status;
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
ok,
|
|
111
|
-
status,
|
|
112
|
-
data: data ?? null,
|
|
113
|
-
error,
|
|
114
|
-
raw
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
function shouldRetryStatus(status) {
|
|
118
|
-
return status === 429 || status >= 500;
|
|
119
|
-
}
|
|
120
|
-
function shouldRetryError(error) {
|
|
121
|
-
if (!error || typeof error !== "object") {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
const err = error;
|
|
125
|
-
const status = err.statusCode ?? err.response?.statusCode;
|
|
126
|
-
if (typeof status === "number" && shouldRetryStatus(status)) {
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
const code = err.code ?? err.cause?.code;
|
|
130
|
-
return code ? RETRY_ERROR_CODES.has(code) : false;
|
|
131
|
-
}
|
|
132
|
-
async function executeWithRetry(caller, requestOptions) {
|
|
133
|
-
let lastError;
|
|
134
|
-
for (let attempt = 0; attempt <= RETRY_DELAYS.length; attempt++) {
|
|
135
|
-
try {
|
|
136
|
-
const response = await caller(requestOptions);
|
|
137
|
-
const normalized = normalizeResponse(response.body, response.statusCode);
|
|
138
|
-
if (shouldRetryStatus(normalized.status) && attempt < RETRY_DELAYS.length) {
|
|
139
|
-
await (0, import_n8n_workflow.sleep)(RETRY_DELAYS[attempt]);
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
return normalized;
|
|
143
|
-
} catch (error) {
|
|
144
|
-
lastError = error;
|
|
145
|
-
if (attempt < RETRY_DELAYS.length && shouldRetryError(error)) {
|
|
146
|
-
await (0, import_n8n_workflow.sleep)(RETRY_DELAYS[attempt]);
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (lastError && typeof lastError === "object") {
|
|
153
|
-
const err = lastError;
|
|
154
|
-
const status = err.statusCode ?? err.response?.statusCode ?? 0;
|
|
155
|
-
const body = err.response?.body;
|
|
156
|
-
const fallback = normalizeResponse(body, status || 0);
|
|
157
|
-
if (fallback.error && err.message && !fallback.error.includes(err.message)) {
|
|
158
|
-
fallback.error = fallback.error + ". " + err.message;
|
|
159
|
-
} else if (!fallback.error) {
|
|
160
|
-
fallback.error = err.message ?? "Request failed";
|
|
161
|
-
}
|
|
162
|
-
return fallback;
|
|
163
|
-
}
|
|
164
|
-
return {
|
|
165
|
-
ok: false,
|
|
166
|
-
status: 0,
|
|
167
|
-
data: null,
|
|
168
|
-
error: lastError instanceof Error ? lastError.message : "Request failed",
|
|
169
|
-
raw: null
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
function buildCaller(context, credentialType) {
|
|
173
|
-
return async (options) => {
|
|
174
|
-
const response = await context.helpers.requestWithAuthentication.call(
|
|
175
|
-
context,
|
|
176
|
-
credentialType,
|
|
177
|
-
options
|
|
178
|
-
);
|
|
179
|
-
return {
|
|
180
|
-
statusCode: response.statusCode,
|
|
181
|
-
body: response.body,
|
|
182
|
-
headers: response.headers
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function createSallaActionsClient(context, credentials, credentialType = SALLA_CREDENTIAL_NAME) {
|
|
187
|
-
const caller = buildCaller(context, credentialType);
|
|
188
|
-
async function request(options) {
|
|
189
|
-
const requestOptions = {
|
|
190
|
-
method: options.method,
|
|
191
|
-
url: buildActionsUrl(credentials.baseUrl, options.path),
|
|
192
|
-
qs: options.qs,
|
|
193
|
-
body: options.body,
|
|
194
|
-
headers: options.headers,
|
|
195
|
-
json: true,
|
|
196
|
-
timeout: DEFAULT_TIMEOUT
|
|
197
|
-
};
|
|
198
|
-
const advanced = requestOptions;
|
|
199
|
-
advanced["returnFullResponse"] = true;
|
|
200
|
-
advanced["resolveWithFullResponse"] = true;
|
|
201
|
-
advanced["ignoreHttpStatusErrors"] = true;
|
|
202
|
-
return executeWithRetry(caller, requestOptions);
|
|
203
|
-
}
|
|
204
|
-
async function proxy(options) {
|
|
205
|
-
const requestOptions = {
|
|
206
|
-
method: "POST",
|
|
207
|
-
url: buildProxyUrl(credentials.baseUrl),
|
|
208
|
-
body: {
|
|
209
|
-
salla_merchant_id: credentials.salla_merchant_id,
|
|
210
|
-
method: options.method,
|
|
211
|
-
path: options.path,
|
|
212
|
-
payload: options.payload ?? null
|
|
213
|
-
},
|
|
214
|
-
json: true,
|
|
215
|
-
timeout: DEFAULT_TIMEOUT
|
|
216
|
-
};
|
|
217
|
-
const advanced = requestOptions;
|
|
218
|
-
advanced["returnFullResponse"] = true;
|
|
219
|
-
advanced["resolveWithFullResponse"] = true;
|
|
220
|
-
advanced["ignoreHttpStatusErrors"] = true;
|
|
221
|
-
return executeWithRetry(caller, requestOptions);
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
request,
|
|
225
|
-
proxy
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// nodes/Orders/UpdateOrderStatus.node.ts
|
|
230
|
-
var UpdateOrderStatus = class {
|
|
231
|
-
constructor() {
|
|
232
|
-
this.description = {
|
|
233
|
-
displayName: "Update Order Status (Deprecated)",
|
|
234
|
-
name: "sallaUpdateOrderStatus",
|
|
235
|
-
group: ["transform"],
|
|
236
|
-
version: 1,
|
|
237
|
-
icon: "file:assets/salla-logo.svg",
|
|
238
|
-
description: "Deprecated – use Salla Actions node instead.",
|
|
239
|
-
defaults: {
|
|
240
|
-
name: "Update Order Status (Deprecated)",
|
|
241
|
-
color: SALLA_BRAND_COLOR
|
|
242
|
-
},
|
|
243
|
-
inputs: ["main"],
|
|
244
|
-
outputs: ["main"],
|
|
245
|
-
credentials: [
|
|
246
|
-
{
|
|
247
|
-
name: SALLA_CREDENTIAL_NAME,
|
|
248
|
-
required: true
|
|
249
|
-
}
|
|
250
|
-
],
|
|
251
|
-
properties: [
|
|
252
|
-
{
|
|
253
|
-
displayName: "Order ID",
|
|
254
|
-
name: "orderId",
|
|
255
|
-
type: "string",
|
|
256
|
-
required: true,
|
|
257
|
-
default: "",
|
|
258
|
-
description: "Numeric or string identifier of the order to update."
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
displayName: "Status Slug",
|
|
262
|
-
name: "slug",
|
|
263
|
-
type: "string",
|
|
264
|
-
default: "",
|
|
265
|
-
required: false,
|
|
266
|
-
placeholder: "under_review",
|
|
267
|
-
description: "Workflow status slug (e.g. under_review, processing, in_progress). Provide either slug or status ID. If both are set, both will be sent."
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
displayName: "Status ID",
|
|
271
|
-
name: "status_id",
|
|
272
|
-
type: "number",
|
|
273
|
-
default: 0,
|
|
274
|
-
required: false,
|
|
275
|
-
typeOptions: {
|
|
276
|
-
minValue: 0
|
|
277
|
-
},
|
|
278
|
-
description: "Numeric workflow status ID. Provide either slug or status ID. If both are set, both will be sent."
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
displayName: "Note",
|
|
282
|
-
name: "note",
|
|
283
|
-
type: "string",
|
|
284
|
-
typeOptions: {
|
|
285
|
-
maxLength: 500
|
|
286
|
-
},
|
|
287
|
-
default: "",
|
|
288
|
-
description: "Optional note that will be persisted with the status change (max 500 characters)."
|
|
289
|
-
},
|
|
290
|
-
{
|
|
291
|
-
displayName: "Status Hint",
|
|
292
|
-
name: "statusHint",
|
|
293
|
-
type: "notice",
|
|
294
|
-
default: "Provide either slug or status_id. If both are set, both will be sent."
|
|
295
|
-
}
|
|
296
|
-
]
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
async execute() {
|
|
300
|
-
const items = this.getInputData();
|
|
301
|
-
const returnItems = [];
|
|
302
|
-
const credentials = await this.getCredentials(
|
|
303
|
-
SALLA_CREDENTIAL_NAME
|
|
304
|
-
);
|
|
305
|
-
const client = createSallaActionsClient(this, credentials);
|
|
306
|
-
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
|
307
|
-
const orderId = this.getNodeParameter("orderId", itemIndex);
|
|
308
|
-
const slug = this.getNodeParameter("slug", itemIndex);
|
|
309
|
-
const statusIdRaw = this.getNodeParameter("status_id", itemIndex);
|
|
310
|
-
const note = this.getNodeParameter("note", itemIndex);
|
|
311
|
-
if ((!slug || slug.trim() === "") && (!statusIdRaw || Number.isNaN(statusIdRaw))) {
|
|
312
|
-
throw new import_n8n_workflow2.NodeOperationError(this.getNode(), "Provide either a status slug or status ID.", {
|
|
313
|
-
itemIndex
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
if (note && note.length > 500) {
|
|
317
|
-
throw new import_n8n_workflow2.NodeOperationError(this.getNode(), "Note must be 500 characters or fewer.", {
|
|
318
|
-
itemIndex
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
const body = {};
|
|
322
|
-
if (slug && slug.trim() !== "") {
|
|
323
|
-
body.slug = slug.trim();
|
|
324
|
-
}
|
|
325
|
-
if (statusIdRaw && !Number.isNaN(statusIdRaw)) {
|
|
326
|
-
body.status_id = Number(statusIdRaw);
|
|
327
|
-
}
|
|
328
|
-
if (note && note.trim() !== "") {
|
|
329
|
-
body.note = note.trim();
|
|
330
|
-
}
|
|
331
|
-
const response = await client.request({
|
|
332
|
-
method: "POST",
|
|
333
|
-
path: "/orders/" + encodeURIComponent(String(orderId)) + "/status",
|
|
334
|
-
body
|
|
335
|
-
});
|
|
336
|
-
if (!response.ok) {
|
|
337
|
-
throw new import_n8n_workflow2.NodeOperationError(this.getNode(), response.error ?? "Salla Actions request failed", {
|
|
338
|
-
itemIndex,
|
|
339
|
-
description: response.raw ? JSON.stringify(response.raw, null, 2) : void 0
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
returnItems.push({
|
|
343
|
-
json: {
|
|
344
|
-
ok: response.ok,
|
|
345
|
-
status: response.status,
|
|
346
|
-
data: response.data ?? null,
|
|
347
|
-
raw: response.raw ?? null
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
return [returnItems];
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
355
|
-
0 && (module.exports = {
|
|
356
|
-
UpdateOrderStatus
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { INodeType, INodeTypeDescription, IWebhookFunctions, IWebhookResponseData } from 'n8n-workflow';
|
|
2
|
-
|
|
3
|
-
declare class CustomerCreatedTrigger implements INodeType {
|
|
4
|
-
description: INodeTypeDescription;
|
|
5
|
-
webhook(this: IWebhookFunctions): Promise<IWebhookResponseData>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export { CustomerCreatedTrigger };
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// nodes/Triggers/CustomerCreatedTrigger.node.ts
|
|
21
|
-
var CustomerCreatedTrigger_node_exports = {};
|
|
22
|
-
__export(CustomerCreatedTrigger_node_exports, {
|
|
23
|
-
CustomerCreatedTrigger: () => CustomerCreatedTrigger
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(CustomerCreatedTrigger_node_exports);
|
|
26
|
-
|
|
27
|
-
// shared/constants.ts
|
|
28
|
-
var SALLA_BRAND_COLOR = "#00C58E";
|
|
29
|
-
|
|
30
|
-
// shared/eventStore.ts
|
|
31
|
-
var TTL_MS = 10 * 60 * 1e3;
|
|
32
|
-
var cache = /* @__PURE__ */ new Map();
|
|
33
|
-
function prune() {
|
|
34
|
-
const now = Date.now();
|
|
35
|
-
for (const [id, expiresAt] of cache.entries()) {
|
|
36
|
-
if (expiresAt <= now) {
|
|
37
|
-
cache.delete(id);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function isDuplicateEvent(eventId) {
|
|
42
|
-
if (!eventId) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
prune();
|
|
46
|
-
const now = Date.now();
|
|
47
|
-
const expiresAt = cache.get(eventId);
|
|
48
|
-
if (expiresAt && expiresAt > now) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
cache.set(eventId, now + TTL_MS);
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// nodes/Triggers/CustomerCreatedTrigger.node.ts
|
|
56
|
-
var HEADER_KEYS = [
|
|
57
|
-
{ key: "x-salla-event", canonical: "X-Salla-Event" },
|
|
58
|
-
{ key: "x-salla-event-id", canonical: "X-Salla-Event-Id" },
|
|
59
|
-
{ key: "x-salla-merchant-id", canonical: "X-Salla-Merchant-Id" },
|
|
60
|
-
{ key: "x-forwarded-by", canonical: "X-Forwarded-By" }
|
|
61
|
-
];
|
|
62
|
-
function extractHeaders(raw) {
|
|
63
|
-
const collected = {};
|
|
64
|
-
for (const entry of HEADER_KEYS) {
|
|
65
|
-
const value = raw[entry.key] ?? raw[entry.canonical] ?? raw[entry.key.toLowerCase()];
|
|
66
|
-
if (value !== void 0) {
|
|
67
|
-
collected[entry.canonical] = Array.isArray(value) ? value.join(",") : value;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return collected;
|
|
71
|
-
}
|
|
72
|
-
function preparePayload(body, headers) {
|
|
73
|
-
const payload = body && typeof body === "object" ? { ...body } : { rawBody: body ?? null };
|
|
74
|
-
payload.__sallaHeaders = headers;
|
|
75
|
-
return payload;
|
|
76
|
-
}
|
|
77
|
-
var CustomerCreatedTrigger = class {
|
|
78
|
-
constructor() {
|
|
79
|
-
this.description = {
|
|
80
|
-
displayName: "Customer Created (Salla) [Deprecated]",
|
|
81
|
-
name: "sallaCustomerCreatedTrigger",
|
|
82
|
-
group: ["trigger"],
|
|
83
|
-
version: 1,
|
|
84
|
-
icon: "file:assets/salla-logo.svg",
|
|
85
|
-
description: "Deprecated. Use the “Salla Triggers” node with Trigger On = customer.created.",
|
|
86
|
-
defaults: {
|
|
87
|
-
name: "Customer Created (Salla)",
|
|
88
|
-
color: SALLA_BRAND_COLOR
|
|
89
|
-
},
|
|
90
|
-
inputs: [],
|
|
91
|
-
outputs: ["main"],
|
|
92
|
-
credentials: [],
|
|
93
|
-
webhooks: [
|
|
94
|
-
{
|
|
95
|
-
name: "default",
|
|
96
|
-
httpMethod: "POST",
|
|
97
|
-
responseMode: "onReceived",
|
|
98
|
-
path: "salla/customer-created"
|
|
99
|
-
}
|
|
100
|
-
],
|
|
101
|
-
properties: [
|
|
102
|
-
{
|
|
103
|
-
displayName: "Webhook Secret",
|
|
104
|
-
name: "secret",
|
|
105
|
-
type: "string",
|
|
106
|
-
default: "",
|
|
107
|
-
description: "Optional shared secret reserved for future signature validation."
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
async webhook() {
|
|
113
|
-
const request = this.getRequestObject();
|
|
114
|
-
const rawHeaders = request.headers ?? {};
|
|
115
|
-
const headers = extractHeaders(rawHeaders);
|
|
116
|
-
const eventName = String(headers["X-Salla-Event"] ?? "").toLowerCase();
|
|
117
|
-
if (eventName !== "customer.created") {
|
|
118
|
-
return {
|
|
119
|
-
webhookResponse: {
|
|
120
|
-
message: "Ignored event"
|
|
121
|
-
},
|
|
122
|
-
workflowData: []
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
const eventIdRaw = headers["X-Salla-Event-Id"];
|
|
126
|
-
const eventId = Array.isArray(eventIdRaw) ? eventIdRaw[0] : eventIdRaw;
|
|
127
|
-
if (eventId && isDuplicateEvent(eventId)) {
|
|
128
|
-
return {
|
|
129
|
-
webhookResponse: {
|
|
130
|
-
message: "Duplicate event ignored"
|
|
131
|
-
},
|
|
132
|
-
workflowData: []
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
const payload = preparePayload(request.body, headers);
|
|
136
|
-
const item = {
|
|
137
|
-
json: payload
|
|
138
|
-
};
|
|
139
|
-
return {
|
|
140
|
-
webhookResponse: {
|
|
141
|
-
message: "Event received"
|
|
142
|
-
},
|
|
143
|
-
workflowData: [[item]]
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
-
0 && (module.exports = {
|
|
149
|
-
CustomerCreatedTrigger
|
|
150
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { INodeType, INodeTypeDescription, IWebhookFunctions, IWebhookResponseData } from 'n8n-workflow';
|
|
2
|
-
|
|
3
|
-
declare class OrderStatusUpdatedTrigger implements INodeType {
|
|
4
|
-
description: INodeTypeDescription;
|
|
5
|
-
webhook(this: IWebhookFunctions): Promise<IWebhookResponseData>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export { OrderStatusUpdatedTrigger };
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// nodes/Triggers/OrderStatusUpdatedTrigger.node.ts
|
|
21
|
-
var OrderStatusUpdatedTrigger_node_exports = {};
|
|
22
|
-
__export(OrderStatusUpdatedTrigger_node_exports, {
|
|
23
|
-
OrderStatusUpdatedTrigger: () => OrderStatusUpdatedTrigger
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(OrderStatusUpdatedTrigger_node_exports);
|
|
26
|
-
|
|
27
|
-
// shared/constants.ts
|
|
28
|
-
var SALLA_BRAND_COLOR = "#00C58E";
|
|
29
|
-
|
|
30
|
-
// shared/eventStore.ts
|
|
31
|
-
var TTL_MS = 10 * 60 * 1e3;
|
|
32
|
-
var cache = /* @__PURE__ */ new Map();
|
|
33
|
-
function prune() {
|
|
34
|
-
const now = Date.now();
|
|
35
|
-
for (const [id, expiresAt] of cache.entries()) {
|
|
36
|
-
if (expiresAt <= now) {
|
|
37
|
-
cache.delete(id);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function isDuplicateEvent(eventId) {
|
|
42
|
-
if (!eventId) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
prune();
|
|
46
|
-
const now = Date.now();
|
|
47
|
-
const expiresAt = cache.get(eventId);
|
|
48
|
-
if (expiresAt && expiresAt > now) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
cache.set(eventId, now + TTL_MS);
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// nodes/Triggers/OrderStatusUpdatedTrigger.node.ts
|
|
56
|
-
var HEADER_KEYS = [
|
|
57
|
-
{ key: "x-salla-event", canonical: "X-Salla-Event" },
|
|
58
|
-
{ key: "x-salla-event-id", canonical: "X-Salla-Event-Id" },
|
|
59
|
-
{ key: "x-salla-merchant-id", canonical: "X-Salla-Merchant-Id" },
|
|
60
|
-
{ key: "x-forwarded-by", canonical: "X-Forwarded-By" }
|
|
61
|
-
];
|
|
62
|
-
function extractHeaders(raw) {
|
|
63
|
-
const collected = {};
|
|
64
|
-
for (const entry of HEADER_KEYS) {
|
|
65
|
-
const value = raw[entry.key] ?? raw[entry.canonical] ?? raw[entry.key.toLowerCase()];
|
|
66
|
-
if (value !== void 0) {
|
|
67
|
-
collected[entry.canonical] = Array.isArray(value) ? value.join(",") : value;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return collected;
|
|
71
|
-
}
|
|
72
|
-
function preparePayload(body, headers) {
|
|
73
|
-
const payload = body && typeof body === "object" ? { ...body } : { rawBody: body ?? null };
|
|
74
|
-
payload.__sallaHeaders = headers;
|
|
75
|
-
return payload;
|
|
76
|
-
}
|
|
77
|
-
var OrderStatusUpdatedTrigger = class {
|
|
78
|
-
constructor() {
|
|
79
|
-
this.description = {
|
|
80
|
-
displayName: "Order Status Updated (Salla) [Deprecated]",
|
|
81
|
-
name: "sallaOrderStatusUpdatedTrigger",
|
|
82
|
-
group: ["trigger"],
|
|
83
|
-
version: 1,
|
|
84
|
-
icon: "file:assets/salla-logo.svg",
|
|
85
|
-
description: "Deprecated. Use the “Salla Triggers” node with Trigger On = order.status.updated.",
|
|
86
|
-
defaults: {
|
|
87
|
-
name: "Order Status Updated (Salla)",
|
|
88
|
-
color: SALLA_BRAND_COLOR
|
|
89
|
-
},
|
|
90
|
-
inputs: [],
|
|
91
|
-
outputs: ["main"],
|
|
92
|
-
credentials: [],
|
|
93
|
-
webhooks: [
|
|
94
|
-
{
|
|
95
|
-
name: "default",
|
|
96
|
-
httpMethod: "POST",
|
|
97
|
-
responseMode: "onReceived",
|
|
98
|
-
path: "salla/order-status-updated"
|
|
99
|
-
}
|
|
100
|
-
],
|
|
101
|
-
properties: [
|
|
102
|
-
{
|
|
103
|
-
displayName: "Webhook Secret",
|
|
104
|
-
name: "secret",
|
|
105
|
-
type: "string",
|
|
106
|
-
default: "",
|
|
107
|
-
description: "Optional shared secret reserved for future signature validation."
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
async webhook() {
|
|
113
|
-
const request = this.getRequestObject();
|
|
114
|
-
const rawHeaders = request.headers ?? {};
|
|
115
|
-
const headers = extractHeaders(rawHeaders);
|
|
116
|
-
const eventName = String(headers["X-Salla-Event"] ?? "").toLowerCase();
|
|
117
|
-
if (eventName !== "order.status.updated") {
|
|
118
|
-
return {
|
|
119
|
-
webhookResponse: {
|
|
120
|
-
message: "Ignored event"
|
|
121
|
-
},
|
|
122
|
-
workflowData: []
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
const eventIdRaw = headers["X-Salla-Event-Id"];
|
|
126
|
-
const eventId = Array.isArray(eventIdRaw) ? eventIdRaw[0] : eventIdRaw;
|
|
127
|
-
if (eventId && isDuplicateEvent(eventId)) {
|
|
128
|
-
return {
|
|
129
|
-
webhookResponse: {
|
|
130
|
-
message: "Duplicate event ignored"
|
|
131
|
-
},
|
|
132
|
-
workflowData: []
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
const payload = preparePayload(request.body, headers);
|
|
136
|
-
const item = {
|
|
137
|
-
json: payload
|
|
138
|
-
};
|
|
139
|
-
return {
|
|
140
|
-
webhookResponse: {
|
|
141
|
-
message: "Event received"
|
|
142
|
-
},
|
|
143
|
-
workflowData: [[item]]
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
-
0 && (module.exports = {
|
|
149
|
-
OrderStatusUpdatedTrigger
|
|
150
|
-
});
|