n8n-nodes-fasttext-language-detector 0.1.6 → 0.1.7

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.
@@ -36,6 +36,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.FastTextLanguageDetector = void 0;
37
37
  const n8n_workflow_1 = require("n8n-workflow");
38
38
  const fs = __importStar(require("fs"));
39
+ // Полифилл для fetch API, если не доступен глобально
40
+ if (typeof globalThis.fetch === 'undefined') {
41
+ try {
42
+ // Пробуем использовать node-fetch, если установлен
43
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
44
+ const nodeFetch = require('node-fetch');
45
+ globalThis.fetch = nodeFetch;
46
+ globalThis.Headers = nodeFetch.Headers;
47
+ globalThis.Request = nodeFetch.Request;
48
+ globalThis.Response = nodeFetch.Response;
49
+ }
50
+ catch (error) {
51
+ // Если node-fetch не установлен, выбросим ошибку при использовании
52
+ console.warn('fetch API not available. Install node-fetch or use Node.js 18+');
53
+ }
54
+ }
39
55
  class FastTextLanguageDetector {
40
56
  constructor() {
41
57
  this.description = {
@@ -195,11 +211,11 @@ class FastTextLanguageDetector {
195
211
  }
196
212
  // Динамически загружаем fasttext.js только когда он нужен
197
213
  // Это предотвращает загрузку WASM при старте n8n
198
- // ВАЖНО: используем прямой путь к lib/index.js, чтобы избежать автоматической загрузки WASM
214
+ // ВАЖНО: используем прямой путь к lib/index.js для корректной загрузки
199
215
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-var-requires
200
216
  const fastTextModule = await new Promise((resolve, reject) => {
201
217
  try {
202
- // Используем прямой путь к index.js, минуя автоматическую загрузку WASM
218
+ // Используем прямой путь к index.js для загрузки модуля
203
219
  // eslint-disable-next-line @typescript-eslint/no-var-requires
204
220
  const FastText = require('fasttext.js/lib/index');
205
221
  resolve(FastText);
@@ -225,11 +241,11 @@ class FastTextLanguageDetector {
225
241
  throw new n8n_workflow_1.ApplicationError(`Failed to load fastText module: FastText class not found. Available exports: ${availableExports}`, { level: 'error' });
226
242
  }
227
243
  // Создаем экземпляр FastText с путем к модели
228
- // ВАЖНО: явно отключаем WASM, используем бинарный режим
244
+ // ВАЖНО: включаем WASM для работы с fasttext.js
229
245
  const fastTextInstance = new FastTextClass({
230
246
  loadModel: modelPath,
231
247
  predict: {
232
- wasm: false, // КРИТИЧНО: отключаем WASM, используем бинарный файл
248
+ wasm: true, // Включаем WASM
233
249
  mostlikely: topK,
234
250
  verbosity: 0,
235
251
  normalize: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-fasttext-language-detector",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "n8n node for language detection using fastText",
5
5
  "author": {
6
6
  "name": "Your Name",
@@ -38,8 +38,9 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "^20.10.0",
41
- "@typescript-eslint/parser": "^6.13.0",
41
+ "@types/node-fetch": "^2.6.13",
42
42
  "@typescript-eslint/eslint-plugin": "^6.13.0",
43
+ "@typescript-eslint/parser": "^6.13.0",
43
44
  "eslint": "^8.57.1",
44
45
  "eslint-plugin-n8n-nodes-base": "^1.11.0",
45
46
  "gulp": "^4.0.2",
@@ -49,7 +50,8 @@
49
50
  "typescript": "^5.3.0"
50
51
  },
51
52
  "dependencies": {
52
- "fasttext.js": "^1.1.4"
53
+ "fasttext.js": "^1.1.4",
54
+ "node-fetch": "^2.7.0"
53
55
  },
54
56
  "peerDependencies": {
55
57
  "n8n-workflow": "*"