@ai-wendao/ant 0.5.4 → 0.5.5
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/client.js +140 -9
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -220,6 +220,16 @@ window.__ModuleLoader__.load({
|
|
|
220
220
|
}
|
|
221
221
|
return false
|
|
222
222
|
}
|
|
223
|
+
function safeInstallDiagnostic(value) {
|
|
224
|
+
const text = typeof value === 'string' ? value
|
|
225
|
+
: [value?.name, value?.code, value?.message].filter((part) => part != null).join(' ')
|
|
226
|
+
return String(text || '')
|
|
227
|
+
.replace(/\b(Bearer|Basic)\s+[^\s,;]+/giu, '$1 [REDACTED]')
|
|
228
|
+
.replace(/([?&](?:access[_-]?token|refresh[_-]?token|token|api[_-]?key|secret|password|signature|authorization)=)[^&#\s]*/giu, '$1[REDACTED]')
|
|
229
|
+
.replace(/(["']?(?:access[_-]?token|refresh[_-]?token|token|api[_-]?key|client[_-]?secret|secret|password|authorization)["']?\s*[:=]\s*["']?)[^,"';\s}]+/giu, '$1[REDACTED]')
|
|
230
|
+
.replace(/(https?:\/\/)[^/\s?#@]+:[^@\s/]+@/giu, '$1[REDACTED]@')
|
|
231
|
+
.slice(0, 180)
|
|
232
|
+
}
|
|
223
233
|
const inject = ['slots', 'layout', 'pluginNavigation', 'remote', 'remote.credentials', 'remote.settings', 'remote.pluginManager']
|
|
224
234
|
|
|
225
235
|
async function readLocalJsonResponse(response) {
|
|
@@ -1844,6 +1854,9 @@ window.__ModuleLoader__.load({
|
|
|
1844
1854
|
}
|
|
1845
1855
|
const local = bundles.find((bundle) => bundle.name === plugin.package_name && bundle.installed)
|
|
1846
1856
|
const localAhead = local?.version && newerVersion(local.version, plugin.version)
|
|
1857
|
+
const updatingInstalled = Boolean(local?.version && local.version !== plugin.version)
|
|
1858
|
+
const replacingInstalled = Boolean(local?.version && (updatingInstalled
|
|
1859
|
+
|| artifactUrl && local.source !== artifactUrl))
|
|
1847
1860
|
const action = localAhead ? '回退到团队版本' : local ? local.version === plugin.version ? '重新安装' : '更新' : '安装'
|
|
1848
1861
|
const sourceNotice = artifactUrl
|
|
1849
1862
|
? 'DSH 将安装 ANT 固定的顶层制品。'
|
|
@@ -1862,23 +1875,128 @@ window.__ModuleLoader__.load({
|
|
|
1862
1875
|
throw new Error('插件审核信息已变化,请刷新目录后重试。')
|
|
1863
1876
|
}
|
|
1864
1877
|
const requestId = crypto.randomUUID()
|
|
1878
|
+
const requestReference = requestId.slice(0, 8).toUpperCase()
|
|
1879
|
+
const previousSourceIsRegistry = Boolean(local && (!local.source
|
|
1880
|
+
|| local.source === plugin.package_name || local.source.startsWith(`${plugin.package_name}@`)))
|
|
1881
|
+
const previousInstallSpec = local
|
|
1882
|
+
? previousSourceIsRegistry ? `${plugin.package_name}@${local.version}` : local.source || ''
|
|
1883
|
+
: ''
|
|
1884
|
+
const expectedPreviousSource = previousSourceIsRegistry ? previousInstallSpec : local?.source
|
|
1885
|
+
const previousRegistry = previousSourceIsRegistry ? 'https://registry.npmjs.org/' : null
|
|
1886
|
+
const currentBundle = async () => {
|
|
1887
|
+
try {
|
|
1888
|
+
const listed = await manager.listBundles()
|
|
1889
|
+
if (listed.ok && Array.isArray(listed.value)) {
|
|
1890
|
+
return listed.value.find((bundle) => bundle.name === plugin.package_name && bundle.installed) || null
|
|
1891
|
+
}
|
|
1892
|
+
} catch {}
|
|
1893
|
+
return undefined
|
|
1894
|
+
}
|
|
1895
|
+
const isPreviousVersion = (bundle) => bundle?.version === local?.version
|
|
1896
|
+
&& (!expectedPreviousSource || bundle.source === expectedPreviousSource)
|
|
1897
|
+
const restorePreviousVersion = async () => {
|
|
1898
|
+
let installed = await currentBundle()
|
|
1899
|
+
if (installed === undefined) return 'unknown'
|
|
1900
|
+
if (isPreviousVersion(installed)) {
|
|
1901
|
+
if (installed.enabled === (local.enabled !== false)) return 'restored'
|
|
1902
|
+
if (typeof manager.setBundleEnabled !== 'function') return 'unknown'
|
|
1903
|
+
try {
|
|
1904
|
+
await manager.setBundleEnabled(plugin.package_name, local.enabled !== false)
|
|
1905
|
+
} catch {}
|
|
1906
|
+
installed = await currentBundle()
|
|
1907
|
+
return isPreviousVersion(installed) && installed.enabled === (local.enabled !== false)
|
|
1908
|
+
? 'restored' : 'unknown'
|
|
1909
|
+
}
|
|
1910
|
+
if (installed?.installed) {
|
|
1911
|
+
return installed.version === plugin.version
|
|
1912
|
+
&& (!artifactUrl || installed.source === artifactUrl) ? 'target' : 'unknown'
|
|
1913
|
+
}
|
|
1914
|
+
if (installed !== null || !previousInstallSpec) return 'unknown'
|
|
1915
|
+
if (previousSourceIsRegistry && !previousRegistry) return 'unknown'
|
|
1916
|
+
const restoreRequestId = crypto.randomUUID()
|
|
1917
|
+
try {
|
|
1918
|
+
const restoreOptions = {
|
|
1919
|
+
enabled: local.enabled !== false, requestId: restoreRequestId,
|
|
1920
|
+
saveExact: true,
|
|
1921
|
+
}
|
|
1922
|
+
if (previousSourceIsRegistry && previousRegistry) restoreOptions.registry = previousRegistry
|
|
1923
|
+
await manager.installBundle(previousInstallSpec, restoreOptions)
|
|
1924
|
+
if (typeof manager.waitForInstall === 'function') {
|
|
1925
|
+
await manager.waitForInstall(restoreRequestId)
|
|
1926
|
+
}
|
|
1927
|
+
} catch {}
|
|
1928
|
+
installed = await currentBundle()
|
|
1929
|
+
return isPreviousVersion(installed) && installed.enabled === (local.enabled !== false)
|
|
1930
|
+
? 'restored' : 'unknown'
|
|
1931
|
+
}
|
|
1865
1932
|
let result
|
|
1933
|
+
let installFailure = null
|
|
1934
|
+
let updateRestore = null
|
|
1935
|
+
let removedForUpdate = false
|
|
1866
1936
|
const options = artifactUrl
|
|
1867
|
-
? { enabled: true, requestId }
|
|
1868
|
-
: { enabled: true, requestId, registry: 'https://registry.npmjs.org/' }
|
|
1869
|
-
|
|
1870
|
-
|
|
1937
|
+
? { enabled: local ? local.enabled !== false : true, requestId }
|
|
1938
|
+
: { enabled: local ? local.enabled !== false : true, requestId, registry: 'https://registry.npmjs.org/' }
|
|
1939
|
+
if (replacingInstalled && !localAhead && !artifactUrl && local.updatable !== false
|
|
1940
|
+
&& typeof manager.updateBundle === 'function') {
|
|
1941
|
+
try {
|
|
1942
|
+
const update = await manager.updateBundle(plugin.package_name, plugin.version, {
|
|
1943
|
+
requestId, registry: 'https://registry.npmjs.org/',
|
|
1944
|
+
})
|
|
1945
|
+
result = { ok: true, value: update?.result }
|
|
1946
|
+
updateRestore = update?.restore || null
|
|
1947
|
+
} catch (error) { installFailure = error; result = null }
|
|
1948
|
+
} else {
|
|
1949
|
+
if (replacingInstalled && typeof manager.removeBundle !== 'function') {
|
|
1950
|
+
setMessage('当前 DSH 不支持通过 ANT 安全替换已安装插件。请在 DSH 插件管理查看状态,或联系管理员。')
|
|
1951
|
+
return
|
|
1952
|
+
}
|
|
1953
|
+
if (replacingInstalled) {
|
|
1954
|
+
let removed = null
|
|
1955
|
+
let removeFailure = null
|
|
1956
|
+
try { removed = await manager.removeBundle(plugin.package_name) }
|
|
1957
|
+
catch (error) { removeFailure = error }
|
|
1958
|
+
if (!removed?.ok || !['applied', 'restart-required'].includes(removed.value?.application)) {
|
|
1959
|
+
const diagnostic = safeInstallDiagnostic(removed?.value?.error || removed?.error || removeFailure)
|
|
1960
|
+
const recovery = await restorePreviousVersion()
|
|
1961
|
+
if (recovery !== 'restored') setUncertainId(plugin.id)
|
|
1962
|
+
const recoveryNotice = recovery === 'restored'
|
|
1963
|
+
? `旧版本号和原启用状态已恢复。${previousSourceIsRegistry ? '恢复按团队目录使用 npm 官方源;若此前来自私有源,请联系管理员核对。' : ''}`
|
|
1964
|
+
: recovery === 'target' ? `本机列表显示审核版本 ${plugin.version} 已安装,请核对后再操作。`
|
|
1965
|
+
: '无法确认旧版本及启用状态,请先在 DSH 插件管理核对。'
|
|
1966
|
+
setMessage(`无法开始更新 ${plugin.title}:DSH 未能确认旧版本移除完成。${diagnostic
|
|
1967
|
+
? `DSH 诊断:${diagnostic}。` : ''}${recoveryNotice}`)
|
|
1968
|
+
return
|
|
1969
|
+
}
|
|
1970
|
+
removedForUpdate = true
|
|
1971
|
+
}
|
|
1972
|
+
try { result = await manager.installBundle(installSpec, options) }
|
|
1973
|
+
catch (error) { installFailure = error; result = null }
|
|
1974
|
+
}
|
|
1871
1975
|
if (!result?.ok) {
|
|
1976
|
+
if (!installFailure && result?.error) installFailure = result.error
|
|
1872
1977
|
let recovered = null
|
|
1978
|
+
let waitFailure = null
|
|
1873
1979
|
if (typeof manager.waitForInstall === 'function') {
|
|
1874
1980
|
try {
|
|
1875
1981
|
const pending = await manager.waitForInstall(requestId)
|
|
1876
1982
|
if (pending.ok && pending.value) recovered = { ok: true, value: pending.value }
|
|
1877
|
-
|
|
1983
|
+
else if (pending?.error) waitFailure = pending.error
|
|
1984
|
+
} catch (error) { waitFailure = error }
|
|
1878
1985
|
}
|
|
1879
1986
|
if (!recovered) {
|
|
1880
1987
|
setUncertainId(plugin.id)
|
|
1881
|
-
|
|
1988
|
+
let restoreNotice = ''
|
|
1989
|
+
if (removedForUpdate) {
|
|
1990
|
+
const restoreState = await restorePreviousVersion()
|
|
1991
|
+
restoreNotice = restoreState === 'restored'
|
|
1992
|
+
? ` DSH 已恢复旧版本号 ${local.version}。${previousSourceIsRegistry ? '恢复按团队目录使用 npm 官方源;若此前来自私有源,请核对来源。' : ''}`
|
|
1993
|
+
: restoreState === 'target' ? ` 本机列表显示审核版本 ${plugin.version} 已安装,但操作结果未确认。`
|
|
1994
|
+
: ' DSH 未能确认旧版本恢复,请先在插件列表核对。'
|
|
1995
|
+
}
|
|
1996
|
+
const details = [installFailure && `installBundle:${safeInstallDiagnostic(installFailure)}`,
|
|
1997
|
+
waitFailure && `waitForInstall:${safeInstallDiagnostic(waitFailure)}`].filter(Boolean)
|
|
1998
|
+
setMessage(`暂时无法确认 ${plugin.title} 的安装结果(请求编号 ${requestReference})。${details.length
|
|
1999
|
+
? `本机诊断:${details.join(';')}。` : ''}${restoreNotice}请先在 DSH 插件列表核对,勿重复点击安装。`)
|
|
1882
2000
|
return
|
|
1883
2001
|
}
|
|
1884
2002
|
result = recovered
|
|
@@ -1894,9 +2012,22 @@ window.__ModuleLoader__.load({
|
|
|
1894
2012
|
setMessage(`DSH 无法确定 ${plugin.title} 本次安装的唯一结果,未确认完成。请先在 DSH 插件列表核对;若已经正常使用同版则无需重复安装,仍需核对来源时请联系管理员。`)
|
|
1895
2013
|
return
|
|
1896
2014
|
}
|
|
1897
|
-
const diagnostic =
|
|
1898
|
-
|
|
1899
|
-
|
|
2015
|
+
const diagnostic = safeInstallDiagnostic({ name: outcome.error?.name,
|
|
2016
|
+
code: outcome.error?.code,
|
|
2017
|
+
message: outcome.error?.diagnostic || outcome.error?.message || outcome.packageResult?.output })
|
|
2018
|
+
let restoreNotice = ''
|
|
2019
|
+
if (updateRestore) {
|
|
2020
|
+
restoreNotice = ['applied', 'restart-required'].includes(updateRestore.application)
|
|
2021
|
+
? ` DSH 已恢复旧版本 ${local.version}。` : ' DSH 未能确认旧版本已恢复,请先在插件列表核对。'
|
|
2022
|
+
} else if (removedForUpdate) {
|
|
2023
|
+
const restoreState = await restorePreviousVersion()
|
|
2024
|
+
restoreNotice = restoreState === 'restored'
|
|
2025
|
+
? ` DSH 已恢复旧版本号 ${local.version}。${previousSourceIsRegistry ? '恢复按团队目录使用 npm 官方源;若此前来自私有源,请核对来源。' : ''}`
|
|
2026
|
+
: restoreState === 'target' ? ` 本机列表显示审核版本 ${plugin.version} 已安装,但结果未确认。`
|
|
2027
|
+
: ' DSH 未能确认旧版本恢复,请先在插件列表核对。'
|
|
2028
|
+
}
|
|
2029
|
+
setMessage(`${plugin.title} 安装未完成(请求编号 ${requestReference})。${diagnostic
|
|
2030
|
+
? `DSH 诊断:${diagnostic}。` : 'DSH 没有返回失败诊断。'}${restoreNotice}请在 DSH 插件管理查看状态或联系管理员。`)
|
|
1900
2031
|
return
|
|
1901
2032
|
}
|
|
1902
2033
|
if (outcome.bundle !== plugin.package_name
|