@goodandready/dsh-subscriptions 0.4.0 → 0.4.2
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/lib/index.js +2 -3
- package/lib/refs.js +15 -33
- package/lib/vendors/index.js +32 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -3,12 +3,11 @@ import { PROVIDERS, oauthRef, isProvider, displayName, droppedCredentialRefs } f
|
|
|
3
3
|
import { createPkce } from './pkce.js'
|
|
4
4
|
import { parseCallbackInput, requestOrigin, webCallbackUri } from './oauth.js'
|
|
5
5
|
import { writeJson, writeHtml, readBody, isTrustedSettingsRequest, queryOf } from './http.js'
|
|
6
|
-
import { getVendor } from './vendors/index.js'
|
|
6
|
+
import { getVendor, registerCustomVendor, clearCustomVendors } from './vendors/index.js'
|
|
7
7
|
import { SubscriptionAdapter } from './adapter.js'
|
|
8
8
|
import { generateOnce, SIZES as IMAGE_SIZES } from './images.js'
|
|
9
9
|
import { parseBlob } from './blob.js'
|
|
10
10
|
import { createVendorFromProfile, validateProfile } from './vendor-factory.js'
|
|
11
|
-
import { registerCustomVendor } from './vendors/index.js'
|
|
12
11
|
import { registerCustomProviderIds, registerDisplayName } from './refs.js'
|
|
13
12
|
import { createSubscriptionsService } from './subscriptions.js'
|
|
14
13
|
import { encryptWithPassphrase, decryptWithPassphrase } from './crypto.js'
|
|
@@ -106,7 +105,7 @@ export function apply(ctx, config) {
|
|
|
106
105
|
try { ctx.log && ctx.log.warn && ctx.log.warn('[dsh-subscriptions] customVendors: ' + String(e && e.message || e)) } catch {}
|
|
107
106
|
return
|
|
108
107
|
}
|
|
109
|
-
|
|
108
|
+
clearCustomVendors()
|
|
110
109
|
for (const profile of profiles) {
|
|
111
110
|
try {
|
|
112
111
|
const vendor = createVendorFromProfile(profile)
|
package/lib/refs.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// Встроенные
|
|
2
|
-
// registerCustomProviderIds и попадают в тот же список.
|
|
1
|
+
// Встроенные провайдеры + динамические из Config.customVendors.
|
|
3
2
|
export const BUILTIN_PROVIDERS = Object.freeze([
|
|
4
3
|
'codex',
|
|
5
4
|
'claude',
|
|
@@ -7,49 +6,32 @@ export const BUILTIN_PROVIDERS = Object.freeze([
|
|
|
7
6
|
'antigravity',
|
|
8
7
|
])
|
|
9
8
|
|
|
10
|
-
const
|
|
9
|
+
const dynamicIds = new Set()
|
|
10
|
+
const displayExtra = {}
|
|
11
|
+
|
|
12
|
+
export let PROVIDERS = [...BUILTIN_PROVIDERS]
|
|
11
13
|
|
|
12
14
|
export function registerCustomProviderIds(ids) {
|
|
15
|
+
let changed = false
|
|
13
16
|
for (const id of ids || []) {
|
|
14
|
-
if (typeof id === 'string' && /^[a-z][a-z0-9_]*$/.test(id)
|
|
17
|
+
if (typeof id === 'string' && /^[a-z][a-z0-9_]*$/.test(id) && !dynamicIds.has(id)) {
|
|
18
|
+
dynamicIds.add(id)
|
|
19
|
+
changed = true
|
|
20
|
+
}
|
|
15
21
|
}
|
|
22
|
+
if (changed) PROVIDERS = listProviders()
|
|
16
23
|
}
|
|
17
24
|
|
|
18
25
|
export function listProviders() {
|
|
19
|
-
return [...BUILTIN_PROVIDERS, ...
|
|
26
|
+
return [...BUILTIN_PROVIDERS, ...dynamicIds]
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
// Обратно-совместимый доступ: массив читается на момент вызова.
|
|
23
|
-
export const PROVIDERS = new Proxy([], {
|
|
24
|
-
get(_t, prop) {
|
|
25
|
-
if (prop === 'length') return listProviders().length
|
|
26
|
-
if (prop === Symbol.iterator) return listProviders()[Symbol.iterator]
|
|
27
|
-
const i = Number(prop)
|
|
28
|
-
return Number.isInteger(i) ? listProviders()[i] : undefined
|
|
29
|
-
},
|
|
30
|
-
has() { return true },
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const DISPLAY_EXTRA = {}
|
|
34
|
-
|
|
35
29
|
export function registerDisplayName(id, name) {
|
|
36
|
-
if (id && name)
|
|
30
|
+
if (id && name) displayExtra[id] = name
|
|
37
31
|
}
|
|
38
32
|
|
|
39
|
-
const KNOWN_CACHE = new Map()
|
|
40
|
-
|
|
41
33
|
export function isProvider(value) {
|
|
42
|
-
|
|
43
|
-
let result
|
|
44
|
-
try {
|
|
45
|
-
const { isProvider: check } = require('./vendors/index.js')
|
|
46
|
-
result = Boolean(check(value))
|
|
47
|
-
} catch {
|
|
48
|
-
// require недоступен в этом контексте — используем списки
|
|
49
|
-
result = BUILTIN_PROVIDERS.includes(value) || dynamic.has(value)
|
|
50
|
-
}
|
|
51
|
-
KNOWN_CACHE.set(value, result)
|
|
52
|
-
return result
|
|
34
|
+
return BUILTIN_PROVIDERS.includes(value) || dynamicIds.has(value)
|
|
53
35
|
}
|
|
54
36
|
|
|
55
37
|
const DISPLAY = {
|
|
@@ -60,7 +42,7 @@ const DISPLAY = {
|
|
|
60
42
|
}
|
|
61
43
|
|
|
62
44
|
export function displayName(provider) {
|
|
63
|
-
return DISPLAY[provider] ||
|
|
45
|
+
return DISPLAY[provider] || displayExtra[provider] || provider
|
|
64
46
|
}
|
|
65
47
|
|
|
66
48
|
export function oauthRef(provider, index) {
|
package/lib/vendors/index.js
CHANGED
|
@@ -2,12 +2,39 @@ import * as codex from './codex.js'
|
|
|
2
2
|
import * as claude from './claude.js'
|
|
3
3
|
import * as grok from './grok.js'
|
|
4
4
|
import * as antigravity from './antigravity.js'
|
|
5
|
+
import { createVendorFromProfile } from '../vendor-factory.js'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const builtins = { codex, claude, grok, antigravity }
|
|
8
|
+
|
|
9
|
+
const customVendors = new Map()
|
|
10
|
+
|
|
11
|
+
export function registerCustomVendor(vendor) {
|
|
12
|
+
if (!vendor || !vendor.id) throw new Error('custom vendor needs id')
|
|
13
|
+
customVendors.set(vendor.id, vendor)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function clearCustomVendors() {
|
|
17
|
+
customVendors.clear()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const vendors = new Proxy({}, {
|
|
21
|
+
get(_t, prop) {
|
|
22
|
+
if (prop in builtins) return builtins[prop]
|
|
23
|
+
return customVendors.get(prop)
|
|
24
|
+
},
|
|
25
|
+
has(_t, prop) {
|
|
26
|
+
return prop in builtins || customVendors.has(prop)
|
|
27
|
+
},
|
|
28
|
+
ownKeys() {
|
|
29
|
+
return [...Reflect.ownKeys(builtins), ...customVendors.keys()]
|
|
30
|
+
},
|
|
31
|
+
getOwnPropertyDescriptor() {
|
|
32
|
+
return { enumerable: true, configurable: true }
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export function isProvider(value) {
|
|
37
|
+
return Boolean(vendors[value])
|
|
11
38
|
}
|
|
12
39
|
|
|
13
40
|
export function getVendor(provider) {
|
package/package.json
CHANGED