@n8n/ai-utilities 0.16.0 → 0.16.1
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/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/typecheck.tsbuildinfo +1 -1
- package/dist/cjs/utils/follow-redirects.d.ts +5 -0
- package/dist/cjs/utils/follow-redirects.js +51 -0
- package/dist/cjs/utils/follow-redirects.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +4 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/typecheck.tsbuildinfo +1 -1
- package/dist/esm/utils/follow-redirects.d.ts +5 -0
- package/dist/esm/utils/follow-redirects.js +41 -0
- package/dist/esm/utils/follow-redirects.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export interface FollowRedirectsOptions {
|
|
2
|
+
onBeforeHop?: (url: string) => void | Promise<void>;
|
|
3
|
+
maxRedirects?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function fetchFollowingRedirects(fetcher: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>, url: string | URL, init?: RequestInit, options?: FollowRedirectsOptions): Promise<Response>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchFollowingRedirects = fetchFollowingRedirects;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const DEFAULT_MAX_REDIRECTS = 20;
|
|
6
|
+
async function fetchFollowingRedirects(fetcher, url, init, options) {
|
|
7
|
+
const maxRedirects = options?.maxRedirects ?? DEFAULT_MAX_REDIRECTS;
|
|
8
|
+
let currentInput = url;
|
|
9
|
+
let currentInit = { ...init };
|
|
10
|
+
let hops = 0;
|
|
11
|
+
while (true) {
|
|
12
|
+
const currentUrlString = currentInput instanceof URL ? currentInput.href : currentInput;
|
|
13
|
+
if (options?.onBeforeHop) {
|
|
14
|
+
await options.onBeforeHop(currentUrlString);
|
|
15
|
+
}
|
|
16
|
+
const response = await fetcher(currentInput, {
|
|
17
|
+
...currentInit,
|
|
18
|
+
redirect: 'manual',
|
|
19
|
+
});
|
|
20
|
+
if (response.status < 300 || response.status >= 400) {
|
|
21
|
+
return response;
|
|
22
|
+
}
|
|
23
|
+
const location = response.headers.get('location');
|
|
24
|
+
if (!location) {
|
|
25
|
+
return response;
|
|
26
|
+
}
|
|
27
|
+
hops += 1;
|
|
28
|
+
if (hops > maxRedirects) {
|
|
29
|
+
throw new n8n_workflow_1.ApplicationError(`Too many redirects (max ${maxRedirects})`);
|
|
30
|
+
}
|
|
31
|
+
await response.body?.cancel().catch(() => { });
|
|
32
|
+
currentInput = new URL(location, currentUrlString);
|
|
33
|
+
const method = (currentInit.method ?? 'GET').toUpperCase();
|
|
34
|
+
const isUnsafe = method !== 'GET' && method !== 'HEAD';
|
|
35
|
+
if (response.status === 303 ||
|
|
36
|
+
((response.status === 301 || response.status === 302) && isUnsafe)) {
|
|
37
|
+
currentInit = { ...currentInit, method: 'GET', body: undefined };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=follow-redirects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"follow-redirects.js","sourceRoot":"","sources":["../../../src/utils/follow-redirects.ts"],"names":[],"mappings":";;AAcA,0DAiDC;AA/DD,+CAAgD;AAEhD,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAY1B,KAAK,UAAU,uBAAuB,CAC5C,OAA4E,EAC5E,GAAiB,EACjB,IAAkB,EAClB,OAAgC;IAEhC,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,qBAAqB,CAAC;IACpE,IAAI,YAAY,GAAiB,GAAG,CAAC;IACrC,IAAI,WAAW,GAAgB,EAAE,GAAG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AAG;YACvB,CAAC,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,CAAC,IAAI,QAAQ,CAAC,EACjE,CAAC;YACF,WAAW,GAAG,EAAE,GAAG,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAClE,CAAC;IACF,CAAC;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n8n/ai-utilities",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Utilities for building AI nodes in n8n",
|
|
5
5
|
"types": "dist/esm/index.d.ts",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@types/mime-types": "3.0.1",
|
|
37
37
|
"tsx": "^4.19.3",
|
|
38
38
|
"axios": "1.16.0",
|
|
39
|
-
"n8n-workflow": "2.22.
|
|
39
|
+
"n8n-workflow": "2.22.1"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"zod": "3.25.67",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"https-proxy-agent": "7.0.6",
|
|
53
53
|
"proxy-from-env": "^1.1.0",
|
|
54
54
|
"undici": "^6.21.0",
|
|
55
|
-
"@n8n/config": "
|
|
56
|
-
"@n8n/
|
|
55
|
+
"@n8n/typescript-config": "1.4.0",
|
|
56
|
+
"@n8n/config": "2.21.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"n8n-workflow": "*"
|