mirror of https://github.com/langgenius/dify.git
chore: update ky to 1.14.3 (#33201)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
125ece1d0c
commit
0ae73296d7
|
|
@ -25,7 +25,6 @@ updates:
|
||||||
interval: "weekly"
|
interval: "weekly"
|
||||||
open-pull-requests-limit: 2
|
open-pull-requests-limit: 2
|
||||||
ignore:
|
ignore:
|
||||||
- dependency-name: "ky"
|
|
||||||
- dependency-name: "tailwind-merge"
|
- dependency-name: "tailwind-merge"
|
||||||
update-types: ["version-update:semver-major"]
|
update-types: ["version-update:semver-major"]
|
||||||
- dependency-name: "tailwindcss"
|
- dependency-name: "tailwindcss"
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,18 @@ jobs:
|
||||||
docker/.env.example
|
docker/.env.example
|
||||||
docker/docker-compose-template.yaml
|
docker/docker-compose-template.yaml
|
||||||
docker/docker-compose.yaml
|
docker/docker-compose.yaml
|
||||||
|
- name: Check web inputs
|
||||||
|
id: web-changes
|
||||||
|
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
web/**
|
||||||
|
- name: Check api inputs
|
||||||
|
id: api-changes
|
||||||
|
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
api/**
|
||||||
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||||
with:
|
with:
|
||||||
python-version: "3.11"
|
python-version: "3.11"
|
||||||
|
|
@ -35,7 +47,8 @@ jobs:
|
||||||
cd docker
|
cd docker
|
||||||
./generate_docker_compose
|
./generate_docker_compose
|
||||||
|
|
||||||
- run: |
|
- if: steps.api-changes.outputs.any_changed == 'true'
|
||||||
|
run: |
|
||||||
cd api
|
cd api
|
||||||
uv sync --dev
|
uv sync --dev
|
||||||
# fmt first to avoid line too long
|
# fmt first to avoid line too long
|
||||||
|
|
@ -46,11 +59,13 @@ jobs:
|
||||||
uv run ruff format ..
|
uv run ruff format ..
|
||||||
|
|
||||||
- name: count migration progress
|
- name: count migration progress
|
||||||
|
if: steps.api-changes.outputs.any_changed == 'true'
|
||||||
run: |
|
run: |
|
||||||
cd api
|
cd api
|
||||||
./cnt_base.sh
|
./cnt_base.sh
|
||||||
|
|
||||||
- name: ast-grep
|
- name: ast-grep
|
||||||
|
if: steps.api-changes.outputs.any_changed == 'true'
|
||||||
run: |
|
run: |
|
||||||
# ast-grep exits 1 if no matches are found; allow idempotent runs.
|
# ast-grep exits 1 if no matches are found; allow idempotent runs.
|
||||||
uvx --from ast-grep-cli ast-grep --pattern 'db.session.query($WHATEVER).filter($HERE)' --rewrite 'db.session.query($WHATEVER).where($HERE)' -l py --update-all || true
|
uvx --from ast-grep-cli ast-grep --pattern 'db.session.query($WHATEVER).filter($HERE)' --rewrite 'db.session.query($WHATEVER).where($HERE)' -l py --update-all || true
|
||||||
|
|
@ -85,13 +100,15 @@ jobs:
|
||||||
uvx --python 3.13 mdformat . --exclude ".agents/skills/**"
|
uvx --python 3.13 mdformat . --exclude ".agents/skills/**"
|
||||||
|
|
||||||
- name: Setup web environment
|
- name: Setup web environment
|
||||||
|
if: steps.web-changes.outputs.any_changed == 'true'
|
||||||
uses: ./.github/actions/setup-web
|
uses: ./.github/actions/setup-web
|
||||||
with:
|
with:
|
||||||
node-version: "24"
|
node-version: "24"
|
||||||
|
|
||||||
- name: ESLint autofix
|
- name: ESLint autofix
|
||||||
|
if: steps.web-changes.outputs.any_changed == 'true'
|
||||||
run: |
|
run: |
|
||||||
cd web
|
cd web
|
||||||
pnpm eslint --concurrency=2 --prune-suppressions
|
pnpm eslint --concurrency=2 --prune-suppressions --quiet || true
|
||||||
|
|
||||||
- uses: autofix-ci/action@7a166d7532b277f34e16238930461bf77f9d7ed8 # v1.3.3
|
- uses: autofix-ci/action@7a166d7532b277f34e16238930461bf77f9d7ed8 # v1.3.3
|
||||||
|
|
|
||||||
|
|
@ -12961,9 +12961,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"service/fetch.ts": {
|
"service/fetch.ts": {
|
||||||
"e18e/prefer-spread-syntax": {
|
|
||||||
"count": 1
|
|
||||||
},
|
|
||||||
"e18e/prefer-static-regex": {
|
"e18e/prefer-static-regex": {
|
||||||
"count": 1
|
"count": 1
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@
|
||||||
"js-yaml": "4.1.1",
|
"js-yaml": "4.1.1",
|
||||||
"jsonschema": "1.5.0",
|
"jsonschema": "1.5.0",
|
||||||
"katex": "0.16.38",
|
"katex": "0.16.38",
|
||||||
"ky": "1.12.0",
|
"ky": "1.14.3",
|
||||||
"lamejs": "1.2.1",
|
"lamejs": "1.2.1",
|
||||||
"lexical": "0.41.0",
|
"lexical": "0.41.0",
|
||||||
"mermaid": "11.13.0",
|
"mermaid": "11.13.0",
|
||||||
|
|
|
||||||
|
|
@ -234,8 +234,8 @@ importers:
|
||||||
specifier: 0.16.38
|
specifier: 0.16.38
|
||||||
version: 0.16.38
|
version: 0.16.38
|
||||||
ky:
|
ky:
|
||||||
specifier: 1.12.0
|
specifier: 1.14.3
|
||||||
version: 1.12.0
|
version: 1.14.3
|
||||||
lamejs:
|
lamejs:
|
||||||
specifier: 1.2.1
|
specifier: 1.2.1
|
||||||
version: 1.2.1
|
version: 1.2.1
|
||||||
|
|
@ -5515,8 +5515,8 @@ packages:
|
||||||
kolorist@1.8.0:
|
kolorist@1.8.0:
|
||||||
resolution: {integrity: sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==}
|
resolution: {integrity: sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==}
|
||||||
|
|
||||||
ky@1.12.0:
|
ky@1.14.3:
|
||||||
resolution: {integrity: sha512-YRLmSUHCwOJRBMArtqMRLOmO7fewn3yOoui6aB8ERkRVXupa0UiaQaKbIXteMt4jUElhbdqTMsLFHs8APxxUoQ==}
|
resolution: {integrity: sha512-9zy9lkjac+TR1c2tG+mkNSVlyOpInnWdSMiue4F+kq8TwJSgv6o8jhLRg8Ho6SnZ9wOYUq/yozts9qQCfk7bIw==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
|
|
||||||
lamejs@1.2.1:
|
lamejs@1.2.1:
|
||||||
|
|
@ -13268,7 +13268,7 @@ snapshots:
|
||||||
|
|
||||||
kolorist@1.8.0: {}
|
kolorist@1.8.0: {}
|
||||||
|
|
||||||
ky@1.12.0: {}
|
ky@1.14.3: {}
|
||||||
|
|
||||||
lamejs@1.2.1:
|
lamejs@1.2.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
import { base } from './fetch'
|
||||||
|
|
||||||
|
vi.mock('@/app/components/base/toast', () => ({
|
||||||
|
default: {
|
||||||
|
notify: vi.fn(),
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
describe('base', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Error responses', () => {
|
||||||
|
it('should keep the response body readable when a 401 response is rejected', async () => {
|
||||||
|
// Arrange
|
||||||
|
const unauthorizedResponse = new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
code: 'unauthorized',
|
||||||
|
message: 'Unauthorized',
|
||||||
|
status: 401,
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
status: 401,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
vi.spyOn(globalThis, 'fetch').mockResolvedValue(unauthorizedResponse)
|
||||||
|
|
||||||
|
// Act
|
||||||
|
let caughtError: unknown
|
||||||
|
try {
|
||||||
|
await base('/login')
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
caughtError = error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(caughtError).toBeInstanceOf(Response)
|
||||||
|
await expect((caughtError as Response).json()).resolves.toEqual({
|
||||||
|
code: 'unauthorized',
|
||||||
|
message: 'Unauthorized',
|
||||||
|
status: 401,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import type { AfterResponseHook, BeforeErrorHook, BeforeRequestHook, Hooks } from 'ky'
|
import type { AfterResponseHook, BeforeRequestHook, Hooks } from 'ky'
|
||||||
import type { IOtherOptions } from './base'
|
import type { IOtherOptions } from './base'
|
||||||
import Cookies from 'js-cookie'
|
import Cookies from 'js-cookie'
|
||||||
import ky from 'ky'
|
import ky, { HTTPError } from 'ky'
|
||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
import { API_PREFIX, APP_VERSION, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, IS_MARKETPLACE, MARKETPLACE_API_PREFIX, PASSPORT_HEADER_NAME, PUBLIC_API_PREFIX, WEB_APP_SHARE_CODE_HEADER_NAME } from '@/config'
|
import { API_PREFIX, APP_VERSION, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, IS_MARKETPLACE, MARKETPLACE_API_PREFIX, PASSPORT_HEADER_NAME, PUBLIC_API_PREFIX, WEB_APP_SHARE_CODE_HEADER_NAME } from '@/config'
|
||||||
import { getWebAppAccessToken, getWebAppPassport } from './webapp-auth'
|
import { getWebAppAccessToken, getWebAppPassport } from './webapp-auth'
|
||||||
|
|
@ -40,37 +40,19 @@ export type ResponseError = {
|
||||||
|
|
||||||
const afterResponseErrorCode = (otherOptions: IOtherOptions): AfterResponseHook => {
|
const afterResponseErrorCode = (otherOptions: IOtherOptions): AfterResponseHook => {
|
||||||
return async (_request, _options, response) => {
|
return async (_request, _options, response) => {
|
||||||
const clonedResponse = response.clone()
|
if (!/^([23])\d{2}$/.test(String(response.status))) {
|
||||||
if (!/^([23])\d{2}$/.test(String(clonedResponse.status))) {
|
const errorData = await response.clone()
|
||||||
const bodyJson = clonedResponse.json() as Promise<ResponseError>
|
.json()
|
||||||
switch (clonedResponse.status) {
|
.then(data => data as ResponseError)
|
||||||
case 403:
|
.catch(() => null)
|
||||||
bodyJson.then((data: ResponseError) => {
|
const shouldNotifyError = response.status !== 401 && errorData && !otherOptions.silent
|
||||||
if (!otherOptions.silent)
|
|
||||||
Toast.notify({ type: 'error', message: data.message })
|
|
||||||
if (data.code === 'already_setup')
|
|
||||||
globalThis.location.href = `${globalThis.location.origin}/signin`
|
|
||||||
})
|
|
||||||
break
|
|
||||||
case 401:
|
|
||||||
return Promise.reject(response)
|
|
||||||
// fall through
|
|
||||||
default:
|
|
||||||
bodyJson.then((data: ResponseError) => {
|
|
||||||
if (!otherOptions.silent)
|
|
||||||
Toast.notify({ type: 'error', message: data.message })
|
|
||||||
})
|
|
||||||
return Promise.reject(response)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const beforeErrorToast = (otherOptions: IOtherOptions): BeforeErrorHook => {
|
if (shouldNotifyError)
|
||||||
return (error) => {
|
Toast.notify({ type: 'error', message: errorData.message })
|
||||||
if (!otherOptions.silent)
|
|
||||||
Toast.notify({ type: 'error', message: error.message })
|
if (response.status === 403 && errorData?.code === 'already_setup')
|
||||||
return error
|
globalThis.location.href = `${globalThis.location.origin}/signin`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,7 +119,7 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
credentials: 'include', // always send cookies、HTTP Basic authentication.
|
credentials: 'include', // always send cookies、HTTP Basic authentication.
|
||||||
redirect: 'follow',
|
redirect: 'follow',
|
||||||
}
|
} as const
|
||||||
: {
|
: {
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
credentials: 'include', // always send cookies、HTTP Basic authentication.
|
credentials: 'include', // always send cookies、HTTP Basic authentication.
|
||||||
|
|
@ -146,8 +128,8 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
|
||||||
}),
|
}),
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
redirect: 'follow',
|
redirect: 'follow',
|
||||||
}
|
} as const
|
||||||
const { params, body, headers: headersFromProps, ...init } = Object.assign({}, baseOptions, options)
|
const { params, body, headers: headersFromProps, ...init } = { ...baseOptions, ...options }
|
||||||
const headers = new Headers(headersFromProps || {})
|
const headers = new Headers(headersFromProps || {})
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|
@ -189,10 +171,6 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
|
||||||
const client = baseClient.extend({
|
const client = baseClient.extend({
|
||||||
hooks: {
|
hooks: {
|
||||||
...baseHooks,
|
...baseHooks,
|
||||||
beforeError: [
|
|
||||||
...baseHooks.beforeError || [],
|
|
||||||
beforeErrorToast(otherOptions),
|
|
||||||
],
|
|
||||||
beforeRequest: [
|
beforeRequest: [
|
||||||
...baseHooks.beforeRequest || [],
|
...baseHooks.beforeRequest || [],
|
||||||
isPublicAPI && beforeRequestPublicWithCode,
|
isPublicAPI && beforeRequestPublicWithCode,
|
||||||
|
|
@ -204,28 +182,36 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const res = await client(request || fetchPathname, {
|
let res: Response
|
||||||
...init,
|
try {
|
||||||
headers,
|
res = await client(request || fetchPathname, {
|
||||||
credentials: isMarketplaceAPI
|
...init,
|
||||||
? 'omit'
|
headers,
|
||||||
: (options.credentials || 'include'),
|
credentials: isMarketplaceAPI
|
||||||
retry: {
|
? 'omit'
|
||||||
methods: [],
|
: (options.credentials || 'include'),
|
||||||
},
|
retry: {
|
||||||
...(bodyStringify && !fetchCompat ? { json: body } : { body: body as BodyInit }),
|
methods: [],
|
||||||
searchParams: !fetchCompat ? params : undefined,
|
},
|
||||||
fetch(resource: RequestInfo | URL, options?: RequestInit) {
|
...(bodyStringify && !fetchCompat ? { json: body } : { body: body as BodyInit }),
|
||||||
if (resource instanceof Request && options) {
|
searchParams: !fetchCompat ? params : undefined,
|
||||||
const mergedHeaders = new Headers(options.headers || {})
|
fetch(resource: RequestInfo | URL, options?: RequestInit) {
|
||||||
resource.headers.forEach((value, key) => {
|
if (resource instanceof Request && options) {
|
||||||
mergedHeaders.append(key, value)
|
const mergedHeaders = new Headers(options.headers || {})
|
||||||
})
|
resource.headers.forEach((value, key) => {
|
||||||
options.headers = mergedHeaders
|
mergedHeaders.append(key, value)
|
||||||
}
|
})
|
||||||
return globalThis.fetch(resource, options)
|
options.headers = mergedHeaders
|
||||||
},
|
}
|
||||||
})
|
return globalThis.fetch(resource, options)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
if (error instanceof HTTPError)
|
||||||
|
throw error.response.clone()
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
if (needAllResponseContent || fetchCompat)
|
if (needAllResponseContent || fetchCompat)
|
||||||
return res as T
|
return res as T
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue