@kya-os/provider-registry 0.1.0
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/README.md +592 -0
- package/dist/default-providers.d.ts +30 -0
- package/dist/default-providers.d.ts.map +1 -0
- package/dist/default-providers.js +162 -0
- package/dist/default-providers.js.map +1 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +173 -0
- package/dist/index.js.map +1 -0
- package/dist/registry.d.ts +291 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +339 -0
- package/dist/registry.js.map +1 -0
- package/dist/schemas.d.ts +780 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +104 -0
- package/dist/schemas.js.map +1 -0
- package/dist/types.d.ts +214 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +35 -0
- package/dist/types.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default Provider Definitions
|
|
3
|
+
*
|
|
4
|
+
* Pre-populated list of common authentication providers.
|
|
5
|
+
* This list is intentionally concise - additional providers should be
|
|
6
|
+
* registered via config or runtime registration.
|
|
7
|
+
*
|
|
8
|
+
* NOTE: Custom/customer-specific providers (e.g., HardwareWorld) should NOT be
|
|
9
|
+
* in this list. They should be registered dynamically via:
|
|
10
|
+
* - loadFromConfig() with custom configuration
|
|
11
|
+
* - registerProvider() at runtime
|
|
12
|
+
* - MCP_PROVIDER_REGISTRY environment variable
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Default set of common providers
|
|
16
|
+
*
|
|
17
|
+
* These providers are automatically registered when creating a new ProviderRegistry
|
|
18
|
+
* without explicit initial providers.
|
|
19
|
+
*
|
|
20
|
+
* Includes:
|
|
21
|
+
* - Well-known OAuth providers (GitHub, Google, Microsoft, etc.)
|
|
22
|
+
* - Generic credential provider placeholder
|
|
23
|
+
*
|
|
24
|
+
* Does NOT include:
|
|
25
|
+
* - Customer-specific providers (should be loaded via config)
|
|
26
|
+
* - Custom OAuth providers (should be registered at runtime)
|
|
27
|
+
*/
|
|
28
|
+
export const defaultProviders = [
|
|
29
|
+
// OAuth Providers
|
|
30
|
+
{
|
|
31
|
+
id: 'github',
|
|
32
|
+
displayName: 'GitHub',
|
|
33
|
+
authType: 'oauth2',
|
|
34
|
+
oauthProviderId: 'github',
|
|
35
|
+
defaultScopes: ['read:user'],
|
|
36
|
+
ui: {
|
|
37
|
+
icon: 'github',
|
|
38
|
+
description: 'Sign in with GitHub',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'google',
|
|
43
|
+
displayName: 'Google',
|
|
44
|
+
authType: 'oauth2',
|
|
45
|
+
oauthProviderId: 'google',
|
|
46
|
+
defaultScopes: ['openid', 'profile', 'email'],
|
|
47
|
+
ui: {
|
|
48
|
+
icon: 'google',
|
|
49
|
+
description: 'Sign in with Google',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: 'microsoft',
|
|
54
|
+
displayName: 'Microsoft',
|
|
55
|
+
authType: 'oauth2',
|
|
56
|
+
oauthProviderId: 'microsoft',
|
|
57
|
+
defaultScopes: ['openid', 'profile', 'email'],
|
|
58
|
+
ui: {
|
|
59
|
+
icon: 'microsoft',
|
|
60
|
+
description: 'Sign in with Microsoft',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 'discord',
|
|
65
|
+
displayName: 'Discord',
|
|
66
|
+
authType: 'oauth2',
|
|
67
|
+
oauthProviderId: 'discord',
|
|
68
|
+
defaultScopes: ['identify', 'email'],
|
|
69
|
+
ui: {
|
|
70
|
+
icon: 'discord',
|
|
71
|
+
description: 'Sign in with Discord',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: 'slack',
|
|
76
|
+
displayName: 'Slack',
|
|
77
|
+
authType: 'oauth2',
|
|
78
|
+
oauthProviderId: 'slack',
|
|
79
|
+
defaultScopes: ['identity.basic', 'identity.email'],
|
|
80
|
+
ui: {
|
|
81
|
+
icon: 'slack',
|
|
82
|
+
description: 'Sign in with Slack',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: 'apple',
|
|
87
|
+
displayName: 'Apple',
|
|
88
|
+
authType: 'oauth2',
|
|
89
|
+
oauthProviderId: 'apple',
|
|
90
|
+
defaultScopes: ['name', 'email'],
|
|
91
|
+
ui: {
|
|
92
|
+
icon: 'apple',
|
|
93
|
+
description: 'Sign in with Apple',
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: 'linkedin',
|
|
98
|
+
displayName: 'LinkedIn',
|
|
99
|
+
authType: 'oauth2',
|
|
100
|
+
oauthProviderId: 'linkedin',
|
|
101
|
+
defaultScopes: ['r_liteprofile', 'r_emailaddress'],
|
|
102
|
+
ui: {
|
|
103
|
+
icon: 'linkedin',
|
|
104
|
+
description: 'Sign in with LinkedIn',
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: 'twitter',
|
|
109
|
+
displayName: 'Twitter',
|
|
110
|
+
authType: 'oauth2',
|
|
111
|
+
oauthProviderId: 'twitter',
|
|
112
|
+
defaultScopes: ['tweet.read', 'users.read'],
|
|
113
|
+
ui: {
|
|
114
|
+
icon: 'twitter',
|
|
115
|
+
description: 'Sign in with Twitter',
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: 'facebook',
|
|
120
|
+
displayName: 'Facebook',
|
|
121
|
+
authType: 'oauth2',
|
|
122
|
+
oauthProviderId: 'facebook',
|
|
123
|
+
defaultScopes: ['email', 'public_profile'],
|
|
124
|
+
ui: {
|
|
125
|
+
icon: 'facebook',
|
|
126
|
+
description: 'Sign in with Facebook',
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
id: 'okta',
|
|
131
|
+
displayName: 'Okta',
|
|
132
|
+
authType: 'oauth2',
|
|
133
|
+
oauthProviderId: 'okta',
|
|
134
|
+
defaultScopes: ['openid', 'profile', 'email'],
|
|
135
|
+
ui: {
|
|
136
|
+
icon: 'okta',
|
|
137
|
+
description: 'Sign in with Okta',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
id: 'auth0',
|
|
142
|
+
displayName: 'Auth0',
|
|
143
|
+
authType: 'oauth2',
|
|
144
|
+
oauthProviderId: 'auth0',
|
|
145
|
+
defaultScopes: ['openid', 'profile', 'email'],
|
|
146
|
+
ui: {
|
|
147
|
+
icon: 'auth0',
|
|
148
|
+
description: 'Sign in with Auth0',
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
// Generic Credential Provider (placeholder for custom credential auth)
|
|
152
|
+
// Customers should register their own credential providers via config
|
|
153
|
+
{
|
|
154
|
+
id: 'credentials',
|
|
155
|
+
displayName: 'Credentials (generic)',
|
|
156
|
+
authType: 'password',
|
|
157
|
+
ui: {
|
|
158
|
+
description: 'Sign in with email and password',
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
];
|
|
162
|
+
//# sourceMappingURL=default-providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-providers.js","sourceRoot":"","sources":["../src/default-providers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAyB;IACpD,kBAAkB;IAClB;QACE,EAAE,EAAE,QAAQ;QACZ,WAAW,EAAE,QAAQ;QACrB,QAAQ,EAAE,QAAQ;QAClB,eAAe,EAAE,QAAQ;QACzB,aAAa,EAAE,CAAC,WAAW,CAAC;QAC5B,EAAE,EAAE;YACF,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,qBAAqB;SACnC;KACF;IACD;QACE,EAAE,EA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AW,EAAE,iCAAiC;SAC/C;KACF;CACF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Registry Package
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for provider definitions and provider-type mapping.
|
|
5
|
+
* Used by agents, consent UI, and runtime code to determine authentication
|
|
6
|
+
* provider types and metadata.
|
|
7
|
+
*
|
|
8
|
+
* ## Usage Patterns
|
|
9
|
+
*
|
|
10
|
+
* ### Basic Usage (Default Registry)
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { defaultProviderRegistry } from '@kya-os/provider-registry';
|
|
14
|
+
*
|
|
15
|
+
* if (defaultProviderRegistry.isOAuthProvider('github')) {
|
|
16
|
+
* // Handle OAuth flow
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* ### Custom Provider Registration
|
|
21
|
+
*
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { defaultProviderRegistry } from '@kya-os/provider-registry';
|
|
24
|
+
*
|
|
25
|
+
* // Register a custom credential provider
|
|
26
|
+
* defaultProviderRegistry.registerProvider({
|
|
27
|
+
* id: 'my-company-auth',
|
|
28
|
+
* displayName: 'My Company Login',
|
|
29
|
+
* authType: 'password',
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* ### Dependency Injection (Testing)
|
|
34
|
+
*
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { createDefaultProviderRegistry } from '@kya-os/provider-registry';
|
|
37
|
+
*
|
|
38
|
+
* const testRegistry = createDefaultProviderRegistry();
|
|
39
|
+
* // Use testRegistry in tests without affecting global state
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* ### Production Sealing
|
|
43
|
+
*
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { defaultProviderRegistry } from '@kya-os/provider-registry';
|
|
46
|
+
*
|
|
47
|
+
* // Load config, then seal to prevent modifications
|
|
48
|
+
* defaultProviderRegistry.loadFromConfig(customConfig);
|
|
49
|
+
* defaultProviderRegistry.seal();
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @module @kya-os/provider-registry
|
|
53
|
+
*/
|
|
54
|
+
export * from './types';
|
|
55
|
+
export * from './schemas';
|
|
56
|
+
export { ProviderRegistry, IProviderRegistry, RegistryLogger } from './registry';
|
|
57
|
+
export { defaultProviders } from './default-providers';
|
|
58
|
+
export { AUTH_MODES, PROVIDER_AUTH_TYPES } from './types';
|
|
59
|
+
export { OAuthProviderConfigSchema, CredentialProviderConfigSchema, ProviderDefinitionSchema, ProviderConfigSchema, } from './schemas';
|
|
60
|
+
import { ProviderRegistry, RegistryLogger } from './registry';
|
|
61
|
+
/**
|
|
62
|
+
* Create a new ProviderRegistry pre-populated with default providers
|
|
63
|
+
*
|
|
64
|
+
* Use this for dependency injection or when you need an isolated registry
|
|
65
|
+
* that won't affect the global singleton.
|
|
66
|
+
*
|
|
67
|
+
* @param logger - Optional custom logger for warnings
|
|
68
|
+
* @returns A new ProviderRegistry instance with default providers
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* // For testing with isolated state
|
|
73
|
+
* const testRegistry = createDefaultProviderRegistry();
|
|
74
|
+
*
|
|
75
|
+
* // For production with custom logger
|
|
76
|
+
* const registry = createDefaultProviderRegistry(myMetricsLogger);
|
|
77
|
+
* registry.loadFromConfig(customConfig);
|
|
78
|
+
* registry.seal();
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function createDefaultProviderRegistry(logger?: RegistryLogger): ProviderRegistry;
|
|
82
|
+
/**
|
|
83
|
+
* Reset the default provider registry singleton (FOR TESTING ONLY)
|
|
84
|
+
*
|
|
85
|
+
* This resets the lazy singleton to null, so the next access will
|
|
86
|
+
* create a fresh registry. Use this in test beforeEach/afterEach
|
|
87
|
+
* to ensure test isolation.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* import { resetDefaultProviderRegistryForTests } from '@kya-os/provider-registry';
|
|
92
|
+
*
|
|
93
|
+
* beforeEach(() => {
|
|
94
|
+
* resetDefaultProviderRegistryForTests();
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @internal This is for testing only. Do not use in production code.
|
|
99
|
+
*/
|
|
100
|
+
export declare function resetDefaultProviderRegistryForTests(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Default provider registry singleton
|
|
103
|
+
*
|
|
104
|
+
* Pre-populated with common providers (GitHub, Google, Microsoft, etc.).
|
|
105
|
+
* Use this for most cases, or use `createDefaultProviderRegistry()` for
|
|
106
|
+
* dependency injection.
|
|
107
|
+
*
|
|
108
|
+
* ## Lifecycle Notes
|
|
109
|
+
*
|
|
110
|
+
* The registry is lazily initialized on first property access, avoiding
|
|
111
|
+
* module-load side effects that can cause issues with bundlers and testing.
|
|
112
|
+
*
|
|
113
|
+
* For production workers:
|
|
114
|
+
* 1. Load custom provider config early in initialization
|
|
115
|
+
* 2. Call `seal()` to prevent accidental runtime modifications
|
|
116
|
+
*
|
|
117
|
+
* ## Configuration Loading
|
|
118
|
+
*
|
|
119
|
+
* Custom providers can be loaded from environment variables:
|
|
120
|
+
*
|
|
121
|
+
* ```typescript
|
|
122
|
+
* if (process.env.MCP_PROVIDER_REGISTRY) {
|
|
123
|
+
* defaultProviderRegistry.loadFromConfig(
|
|
124
|
+
* JSON.parse(process.env.MCP_PROVIDER_REGISTRY)
|
|
125
|
+
* );
|
|
126
|
+
* }
|
|
127
|
+
* defaultProviderRegistry.seal(); // Prevent further modifications
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export declare const defaultProviderRegistry: ProviderRegistry;
|
|
131
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE1D,OAAO,EACL,yBAAyB,EACzB,8BAA8B,EAC9B,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG9D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,CAAC,EAAE,cAAc,GACtB,gBAAgB,CAElB;AAyBD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oCAAoC,IAAI,IAAI,CAE3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,uBAAuB,EAAE,gBAiBrC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Registry Package
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for provider definitions and provider-type mapping.
|
|
5
|
+
* Used by agents, consent UI, and runtime code to determine authentication
|
|
6
|
+
* provider types and metadata.
|
|
7
|
+
*
|
|
8
|
+
* ## Usage Patterns
|
|
9
|
+
*
|
|
10
|
+
* ### Basic Usage (Default Registry)
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { defaultProviderRegistry } from '@kya-os/provider-registry';
|
|
14
|
+
*
|
|
15
|
+
* if (defaultProviderRegistry.isOAuthProvider('github')) {
|
|
16
|
+
* // Handle OAuth flow
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* ### Custom Provider Registration
|
|
21
|
+
*
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { defaultProviderRegistry } from '@kya-os/provider-registry';
|
|
24
|
+
*
|
|
25
|
+
* // Register a custom credential provider
|
|
26
|
+
* defaultProviderRegistry.registerProvider({
|
|
27
|
+
* id: 'my-company-auth',
|
|
28
|
+
* displayName: 'My Company Login',
|
|
29
|
+
* authType: 'password',
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* ### Dependency Injection (Testing)
|
|
34
|
+
*
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { createDefaultProviderRegistry } from '@kya-os/provider-registry';
|
|
37
|
+
*
|
|
38
|
+
* const testRegistry = createDefaultProviderRegistry();
|
|
39
|
+
* // Use testRegistry in tests without affecting global state
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* ### Production Sealing
|
|
43
|
+
*
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { defaultProviderRegistry } from '@kya-os/provider-registry';
|
|
46
|
+
*
|
|
47
|
+
* // Load config, then seal to prevent modifications
|
|
48
|
+
* defaultProviderRegistry.loadFromConfig(customConfig);
|
|
49
|
+
* defaultProviderRegistry.seal();
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @module @kya-os/provider-registry
|
|
53
|
+
*/
|
|
54
|
+
export * from './types';
|
|
55
|
+
export * from './schemas';
|
|
56
|
+
export { ProviderRegistry } from './registry';
|
|
57
|
+
export { defaultProviders } from './default-providers';
|
|
58
|
+
// Re-export canonical vocab from types (which imports from contracts)
|
|
59
|
+
export { AUTH_MODES, PROVIDER_AUTH_TYPES } from './types';
|
|
60
|
+
// Also export schemas for config validation
|
|
61
|
+
export { OAuthProviderConfigSchema, CredentialProviderConfigSchema, ProviderDefinitionSchema, ProviderConfigSchema, } from './schemas';
|
|
62
|
+
import { ProviderRegistry } from './registry';
|
|
63
|
+
import { defaultProviders } from './default-providers';
|
|
64
|
+
/**
|
|
65
|
+
* Create a new ProviderRegistry pre-populated with default providers
|
|
66
|
+
*
|
|
67
|
+
* Use this for dependency injection or when you need an isolated registry
|
|
68
|
+
* that won't affect the global singleton.
|
|
69
|
+
*
|
|
70
|
+
* @param logger - Optional custom logger for warnings
|
|
71
|
+
* @returns A new ProviderRegistry instance with default providers
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // For testing with isolated state
|
|
76
|
+
* const testRegistry = createDefaultProviderRegistry();
|
|
77
|
+
*
|
|
78
|
+
* // For production with custom logger
|
|
79
|
+
* const registry = createDefaultProviderRegistry(myMetricsLogger);
|
|
80
|
+
* registry.loadFromConfig(customConfig);
|
|
81
|
+
* registry.seal();
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export function createDefaultProviderRegistry(logger) {
|
|
85
|
+
return new ProviderRegistry(defaultProviders, logger);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Lazy singleton holder
|
|
89
|
+
*
|
|
90
|
+
* Uses lazy initialization to avoid side effects during module load.
|
|
91
|
+
* The registry is created on first access, not at import time.
|
|
92
|
+
*/
|
|
93
|
+
let _defaultProviderRegistry = null;
|
|
94
|
+
/**
|
|
95
|
+
* Get the default provider registry singleton
|
|
96
|
+
*
|
|
97
|
+
* This is lazily initialized on first access. Subsequent calls
|
|
98
|
+
* return the same instance.
|
|
99
|
+
*
|
|
100
|
+
* @returns The default ProviderRegistry singleton
|
|
101
|
+
*/
|
|
102
|
+
function getDefaultProviderRegistry() {
|
|
103
|
+
if (!_defaultProviderRegistry) {
|
|
104
|
+
_defaultProviderRegistry = new ProviderRegistry(defaultProviders);
|
|
105
|
+
}
|
|
106
|
+
return _defaultProviderRegistry;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Reset the default provider registry singleton (FOR TESTING ONLY)
|
|
110
|
+
*
|
|
111
|
+
* This resets the lazy singleton to null, so the next access will
|
|
112
|
+
* create a fresh registry. Use this in test beforeEach/afterEach
|
|
113
|
+
* to ensure test isolation.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* import { resetDefaultProviderRegistryForTests } from '@kya-os/provider-registry';
|
|
118
|
+
*
|
|
119
|
+
* beforeEach(() => {
|
|
120
|
+
* resetDefaultProviderRegistryForTests();
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @internal This is for testing only. Do not use in production code.
|
|
125
|
+
*/
|
|
126
|
+
export function resetDefaultProviderRegistryForTests() {
|
|
127
|
+
_defaultProviderRegistry = null;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Default provider registry singleton
|
|
131
|
+
*
|
|
132
|
+
* Pre-populated with common providers (GitHub, Google, Microsoft, etc.).
|
|
133
|
+
* Use this for most cases, or use `createDefaultProviderRegistry()` for
|
|
134
|
+
* dependency injection.
|
|
135
|
+
*
|
|
136
|
+
* ## Lifecycle Notes
|
|
137
|
+
*
|
|
138
|
+
* The registry is lazily initialized on first property access, avoiding
|
|
139
|
+
* module-load side effects that can cause issues with bundlers and testing.
|
|
140
|
+
*
|
|
141
|
+
* For production workers:
|
|
142
|
+
* 1. Load custom provider config early in initialization
|
|
143
|
+
* 2. Call `seal()` to prevent accidental runtime modifications
|
|
144
|
+
*
|
|
145
|
+
* ## Configuration Loading
|
|
146
|
+
*
|
|
147
|
+
* Custom providers can be loaded from environment variables:
|
|
148
|
+
*
|
|
149
|
+
* ```typescript
|
|
150
|
+
* if (process.env.MCP_PROVIDER_REGISTRY) {
|
|
151
|
+
* defaultProviderRegistry.loadFromConfig(
|
|
152
|
+
* JSON.parse(process.env.MCP_PROVIDER_REGISTRY)
|
|
153
|
+
* );
|
|
154
|
+
* }
|
|
155
|
+
* defaultProviderRegistry.seal(); // Prevent further modifications
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export const defaultProviderRegistry = new Proxy({}, {
|
|
159
|
+
get(_target, prop) {
|
|
160
|
+
const registry = getDefaultProviderRegistry();
|
|
161
|
+
const value = registry[prop];
|
|
162
|
+
if (typeof value === 'function') {
|
|
163
|
+
return value.bind(registry);
|
|
164
|
+
}
|
|
165
|
+
return value;
|
|
166
|
+
},
|
|
167
|
+
set(_target, prop, value) {
|
|
168
|
+
const registry = getDefaultProviderRegistry();
|
|
169
|
+
registry[prop] = value;
|
|
170
|
+
return true;
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAqC,MAAM,YAAY,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,sEAAsE;AACtE,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC1D,4CAA4C;AAC5C,OAAO,EACL,yBAAyB,EACzB,8BAA8B,EAC9B,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,gBAAgB,EAAkB,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,6BAA6B,CAC3C,MAAuB;IAEvB,OAAO,IAAI,gBAAgB,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC;AAED;;;;;GAKG;AACH,IAAI,wBAAwB,GAA4B,IAAI,CAAC;AA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