n8n-nodes-elearning-magic 0.1.18 → 0.1.19

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.
@@ -18,12 +18,7 @@ const handleBinaryData = async (context, prepareOutput) => {
18
18
  try {
19
19
  await (0, promises_2.pipeline)(req, (0, fs_1.createWriteStream)(binaryFile.path));
20
20
  const returnItem = {
21
- json: {
22
- headers: req.headers,
23
- params: req.params,
24
- query: req.query,
25
- body: {},
26
- },
21
+ json: (0, utils_1.buildWebhookOutput)(req, {}),
27
22
  };
28
23
  const stats = await (0, promises_1.stat)(binaryFile.path);
29
24
  if (stats.size) {
@@ -119,12 +114,7 @@ class ElearningMagicTrigger extends n8n_workflow_1.Node {
119
114
  }
120
115
  if (!result) {
121
116
  const response = {
122
- json: {
123
- headers: req.headers,
124
- params: req.params,
125
- query: req.query,
126
- body: req.body,
127
- },
117
+ json: (0, utils_1.buildWebhookOutput)(req, req.body),
128
118
  binary: undefined,
129
119
  };
130
120
  result = { workflowData: prepareOutput(response) };
@@ -1,4 +1,5 @@
1
1
  import type { IWebhookFunctions, INodeExecutionData, IDataObject } from 'n8n-workflow';
2
+ export declare const buildWebhookOutput: (req: any, body: IDataObject | string | null | undefined) => IDataObject;
2
3
  export type WebhookParameters = {
3
4
  httpMethod: string | string[];
4
5
  responseMode: string;
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.checkResponseModeConfiguration = exports.isIpWhitelisted = exports.setupOutputConnection = exports.configuredOutputs = exports.getResponseData = exports.getResponseCode = void 0;
36
+ exports.checkResponseModeConfiguration = exports.isIpWhitelisted = exports.setupOutputConnection = exports.configuredOutputs = exports.getResponseData = exports.getResponseCode = exports.buildWebhookOutput = void 0;
37
37
  exports.validateWebhookAuthentication = validateWebhookAuthentication;
38
38
  exports.handleFormData = handleFormData;
39
39
  const promises_1 = require("fs/promises");
@@ -42,6 +42,37 @@ const n8n_workflow_1 = require("n8n-workflow");
42
42
  const a = __importStar(require("node:assert"));
43
43
  const node_net_1 = require("node:net");
44
44
  const error_1 = require("./error");
45
+ const shouldKeepHeader = (key) => {
46
+ const lower = key.toLowerCase();
47
+ return lower === 'content-type' || lower.startsWith('x-em-');
48
+ };
49
+ const buildWebhookOutput = (req, body) => {
50
+ var _a, _b, _c;
51
+ const json = {
52
+ body: body !== null && body !== void 0 ? body : {},
53
+ };
54
+ const headers = (_a = req === null || req === void 0 ? void 0 : req.headers) !== null && _a !== void 0 ? _a : {};
55
+ const cleanedHeaders = {};
56
+ Object.entries(headers).forEach(([key, value]) => {
57
+ if (!shouldKeepHeader(key)) {
58
+ return;
59
+ }
60
+ cleanedHeaders[key.toLowerCase()] = value;
61
+ });
62
+ if (Object.keys(cleanedHeaders).length) {
63
+ json.headers = cleanedHeaders;
64
+ }
65
+ const params = (_b = req === null || req === void 0 ? void 0 : req.params) !== null && _b !== void 0 ? _b : {};
66
+ if (params && Object.keys(params).length) {
67
+ json.params = params;
68
+ }
69
+ const query = (_c = req === null || req === void 0 ? void 0 : req.query) !== null && _c !== void 0 ? _c : {};
70
+ if (query && Object.keys(query).length) {
71
+ json.query = query;
72
+ }
73
+ return json;
74
+ };
75
+ exports.buildWebhookOutput = buildWebhookOutput;
45
76
  const computeSignature = (secret, rawBody) => (0, crypto_1.createHmac)('sha256', secret).update(rawBody).digest('hex');
46
77
  const safeCompare = (a, b) => {
47
78
  if (!a || !b || a.length !== b.length) {
@@ -190,12 +221,7 @@ async function handleFormData(context, prepareOutput) {
190
221
  const options = context.getNodeParameter('options', {});
191
222
  const { data, files } = req.body;
192
223
  const returnItem = {
193
- json: {
194
- headers: req.headers,
195
- params: req.params,
196
- query: req.query,
197
- body: data,
198
- },
224
+ json: (0, exports.buildWebhookOutput)(req, data),
199
225
  };
200
226
  if (files && Object.keys(files).length) {
201
227
  returnItem.binary = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-elearning-magic",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "n8n community node for receiving signed payloads from the eLearning Magic SCORM wrapper",
5
5
  "keywords": [
6
6
  "n8n-community-node",