@vunexa/lixa 0.0.1-alpha.6 → 0.0.1-alpha.9
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/lixa.d.ts +17 -11
- package/dist/lixa.d.ts.map +1 -1
- package/dist/lixa.js +15 -19
- package/dist/lixa.js.map +1 -1
- package/index.d.ts +18 -11
- package/package.json +1 -1
package/dist/lixa.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type LixaConfig, type Session } from "./types";
|
|
2
2
|
import { IProvider } from "./providers";
|
|
3
|
+
/**
|
|
4
|
+
* Type representing the keys of configured providers
|
|
5
|
+
*/
|
|
6
|
+
type ConfiguredProviderKey<T extends LixaConfig> = keyof T['providers'];
|
|
3
7
|
/**
|
|
4
8
|
* A flexible, provider-agnostic OAuth 2.0 and OpenID Connect (OIDC) client library.
|
|
5
9
|
*
|
|
@@ -22,7 +26,7 @@ import { IProvider } from "./providers";
|
|
|
22
26
|
*
|
|
23
27
|
* @public
|
|
24
28
|
*/
|
|
25
|
-
declare class Lixa {
|
|
29
|
+
declare class Lixa<TConfig extends LixaConfig = LixaConfig> {
|
|
26
30
|
private static CONFIGURED_PROVIDERS;
|
|
27
31
|
private static LOCAL_STATE_CACHE;
|
|
28
32
|
private config;
|
|
@@ -32,21 +36,23 @@ declare class Lixa {
|
|
|
32
36
|
*
|
|
33
37
|
* @param config - The configuration object containing provider settings and optional session strategy
|
|
34
38
|
*/
|
|
35
|
-
constructor(config:
|
|
39
|
+
constructor(config: TConfig);
|
|
36
40
|
/**
|
|
37
|
-
* Checks if a provider is registered and
|
|
41
|
+
* Checks if a provider is both registered and configured for this instance.
|
|
42
|
+
* This is a type guard that narrows the provider type for use with getAuthUrl.
|
|
38
43
|
*
|
|
39
44
|
* @param provider - The provider name to check (case-insensitive)
|
|
40
|
-
* @returns True if the provider is registered, false otherwise
|
|
45
|
+
* @returns True if the provider is registered and configured, false otherwise
|
|
41
46
|
*
|
|
42
47
|
* @example
|
|
43
48
|
* ```typescript
|
|
44
|
-
* if (
|
|
45
|
-
*
|
|
49
|
+
* if (lixa.isProviderConfigured(provider)) {
|
|
50
|
+
* // TypeScript now knows provider is a valid ConfiguredProviderKey
|
|
51
|
+
* const authUrl = lixa.getAuthUrl(provider, state);
|
|
46
52
|
* }
|
|
47
53
|
* ```
|
|
48
54
|
*/
|
|
49
|
-
|
|
55
|
+
isProviderConfigured<T extends string>(provider: T): provider is T & ConfiguredProviderKey<TConfig>;
|
|
50
56
|
/**
|
|
51
57
|
* Registers custom OAuth providers for use with Lixa.
|
|
52
58
|
*
|
|
@@ -88,7 +94,7 @@ declare class Lixa {
|
|
|
88
94
|
/**
|
|
89
95
|
* Generates the authorization URL for the specified provider.
|
|
90
96
|
*
|
|
91
|
-
* @param provider - The provider name (
|
|
97
|
+
* @param provider - The provider name (must be a configured provider key)
|
|
92
98
|
* @param state - The state parameter for CSRF protection
|
|
93
99
|
* @returns The complete authorization URL to redirect users to
|
|
94
100
|
*
|
|
@@ -101,11 +107,11 @@ declare class Lixa {
|
|
|
101
107
|
* res.redirect(authUrl);
|
|
102
108
|
* ```
|
|
103
109
|
*/
|
|
104
|
-
getAuthUrl(provider: string, state: string): string;
|
|
110
|
+
getAuthUrl(provider: ConfiguredProviderKey<TConfig> | string, state: string): string;
|
|
105
111
|
/**
|
|
106
112
|
* Handles the OAuth callback and creates a user session.
|
|
107
113
|
*
|
|
108
|
-
* @param provider - The provider name
|
|
114
|
+
* @param provider - The provider name (must be a configured provider key)
|
|
109
115
|
* @param code - The authorization code from the provider
|
|
110
116
|
* @param state - The state parameter for validation
|
|
111
117
|
* @returns A Promise that resolves to a Session object
|
|
@@ -122,7 +128,7 @@ declare class Lixa {
|
|
|
122
128
|
* ```
|
|
123
129
|
*/
|
|
124
130
|
handleCallback({ provider, code, state, }: {
|
|
125
|
-
provider: string;
|
|
131
|
+
provider: ConfiguredProviderKey<TConfig> | string;
|
|
126
132
|
code: string;
|
|
127
133
|
state?: string;
|
|
128
134
|
}): Promise<Session>;
|
package/dist/lixa.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lixa.d.ts","sourceRoot":"","sources":["../src/lixa.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAuB,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"lixa.d.ts","sourceRoot":"","sources":["../src/lixa.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAuB,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAKxC;;GAEG;AACH,KAAK,qBAAqB,CAAC,CAAC,SAAS,UAAU,IAAI,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,cAAM,IAAI,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU;IAChD,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAAqC;IACxE,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAyB;IACzD,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,QAAQ,CAAW;IAE3B;;;;OAIG;gBACS,MAAM,EAAE,OAAO;IAK3B;;;;;;;;;;;;;;OAcG;IACI,oBAAoB,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,QAAQ,IAAI,CAAC,GAAG,qBAAqB,CAAC,OAAO,CAAC;IAM1G;;;;;;;;;;;;;;;OAeG;WACW,gBAAgB,CAAC,WAAW,EAAE;QAC1C,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;KAC1B,GAAG,IAAI;IAQR;;;;;;;OAOG;WACW,mBAAmB,IAAI,MAAM;IAI3C;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAInC,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAUjC;;;;;;;;;;;;;;;OAeG;IACI,UAAU,CAAC,QAAQ,EAAE,qBAAqB,CAAC,OAAO,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAsC3F;;;;;;;;;;;;;;;;;;OAkBG;IACU,cAAc,CAAC,EAC1B,QAAQ,EACR,IAAI,EACJ,KAAK,GACN,EAAE;QACD,QAAQ,EAAE,qBAAqB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;QAClD,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,OAAO,CAAC;YAmDN,oBAAoB;IAsClC,OAAO,CAAC,kBAAkB;CAG3B;AAED,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/dist/lixa.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { randomBytes } from "crypto";
|
|
2
|
-
import { GithubProvider, GoogleProvider } from "./providers";
|
|
3
|
-
import { GITHUB, GOOGLE } from "./utils/constants";
|
|
4
2
|
import { LocalStateCache } from "./dao/state-cache";
|
|
5
3
|
import crypto from "crypto";
|
|
6
4
|
/**
|
|
@@ -38,28 +36,26 @@ class Lixa {
|
|
|
38
36
|
constructor(config) {
|
|
39
37
|
this.config = config;
|
|
40
38
|
this.stateDao = config.stateDao || Lixa.LOCAL_STATE_CACHE;
|
|
41
|
-
if (!Lixa.CONFIGURED_PROVIDERS.has(GITHUB)) {
|
|
42
|
-
Lixa.CONFIGURED_PROVIDERS.set(GITHUB, new GithubProvider());
|
|
43
|
-
}
|
|
44
|
-
if (!Lixa.CONFIGURED_PROVIDERS.has(GOOGLE)) {
|
|
45
|
-
Lixa.CONFIGURED_PROVIDERS.set(GOOGLE, new GoogleProvider());
|
|
46
|
-
}
|
|
47
39
|
}
|
|
48
40
|
/**
|
|
49
|
-
* Checks if a provider is registered and
|
|
41
|
+
* Checks if a provider is both registered and configured for this instance.
|
|
42
|
+
* This is a type guard that narrows the provider type for use with getAuthUrl.
|
|
50
43
|
*
|
|
51
44
|
* @param provider - The provider name to check (case-insensitive)
|
|
52
|
-
* @returns True if the provider is registered, false otherwise
|
|
45
|
+
* @returns True if the provider is registered and configured, false otherwise
|
|
53
46
|
*
|
|
54
47
|
* @example
|
|
55
48
|
* ```typescript
|
|
56
|
-
* if (
|
|
57
|
-
*
|
|
49
|
+
* if (lixa.isProviderConfigured(provider)) {
|
|
50
|
+
* // TypeScript now knows provider is a valid ConfiguredProviderKey
|
|
51
|
+
* const authUrl = lixa.getAuthUrl(provider, state);
|
|
58
52
|
* }
|
|
59
53
|
* ```
|
|
60
54
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
isProviderConfigured(provider) {
|
|
56
|
+
const providerType = provider.toLowerCase();
|
|
57
|
+
return Lixa.CONFIGURED_PROVIDERS.has(providerType) &&
|
|
58
|
+
this.config.providers.hasOwnProperty(providerType);
|
|
63
59
|
}
|
|
64
60
|
/**
|
|
65
61
|
* Registers custom OAuth providers for use with Lixa.
|
|
@@ -117,7 +113,7 @@ class Lixa {
|
|
|
117
113
|
/**
|
|
118
114
|
* Generates the authorization URL for the specified provider.
|
|
119
115
|
*
|
|
120
|
-
* @param provider - The provider name (
|
|
116
|
+
* @param provider - The provider name (must be a configured provider key)
|
|
121
117
|
* @param state - The state parameter for CSRF protection
|
|
122
118
|
* @returns The complete authorization URL to redirect users to
|
|
123
119
|
*
|
|
@@ -131,7 +127,7 @@ class Lixa {
|
|
|
131
127
|
* ```
|
|
132
128
|
*/
|
|
133
129
|
getAuthUrl(provider, state) {
|
|
134
|
-
const providerType = provider.toLowerCase();
|
|
130
|
+
const providerType = String(provider).toLowerCase();
|
|
135
131
|
const providerConfig = this.findProviderByType(providerType);
|
|
136
132
|
const providerImpl = Lixa.CONFIGURED_PROVIDERS.get(providerType);
|
|
137
133
|
if (!providerConfig || !providerImpl) {
|
|
@@ -162,7 +158,7 @@ class Lixa {
|
|
|
162
158
|
/**
|
|
163
159
|
* Handles the OAuth callback and creates a user session.
|
|
164
160
|
*
|
|
165
|
-
* @param provider - The provider name
|
|
161
|
+
* @param provider - The provider name (must be a configured provider key)
|
|
166
162
|
* @param code - The authorization code from the provider
|
|
167
163
|
* @param state - The state parameter for validation
|
|
168
164
|
* @returns A Promise that resolves to a Session object
|
|
@@ -194,11 +190,11 @@ class Lixa {
|
|
|
194
190
|
await this.stateDao.deleteState(state);
|
|
195
191
|
//Get code verifier from cached state
|
|
196
192
|
const codeVerifier = cachedState.codeVerifier;
|
|
197
|
-
const providerType = provider.toLowerCase();
|
|
193
|
+
const providerType = String(provider).toLowerCase();
|
|
198
194
|
const providerConfig = this.findProviderByType(providerType);
|
|
199
195
|
const providerImpl = Lixa.CONFIGURED_PROVIDERS.get(providerType);
|
|
200
196
|
if (!providerConfig || !providerImpl) {
|
|
201
|
-
throw new Error(`Provider ${provider} not configured`);
|
|
197
|
+
throw new Error(`Provider ${String(provider)} not configured`);
|
|
202
198
|
}
|
|
203
199
|
// Exchange code for tokens and fetch user info here.
|
|
204
200
|
const tokens = await this.exchangeCodeForToken(code, providerConfig, providerImpl, codeVerifier);
|
package/dist/lixa.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lixa.js","sourceRoot":"","sources":["../src/lixa.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"lixa.js","sourceRoot":"","sources":["../src/lixa.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAGrC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAO5B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,IAAI;IACA,MAAM,CAAC,oBAAoB,GAA2B,IAAI,GAAG,EAAE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AQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CACnE,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IAEO,kBAAkB,CAAC,YAAoB;QAC7C,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IAC7C,CAAC;;AAGH,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/index.d.ts
CHANGED
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Type representing the keys of configured providers
|
|
12
|
+
*/
|
|
13
|
+
declare type ConfiguredProviderKey<T extends LixaConfig> = keyof T['providers'];
|
|
14
|
+
|
|
10
15
|
/**
|
|
11
16
|
* Interface for OAuth provider implementations.
|
|
12
17
|
*
|
|
@@ -46,7 +51,7 @@ export declare interface IProvider {
|
|
|
46
51
|
*
|
|
47
52
|
* @public
|
|
48
53
|
*/
|
|
49
|
-
export declare class Lixa {
|
|
54
|
+
export declare class Lixa<TConfig extends LixaConfig = LixaConfig> {
|
|
50
55
|
private static CONFIGURED_PROVIDERS;
|
|
51
56
|
private static LOCAL_STATE_CACHE;
|
|
52
57
|
private config;
|
|
@@ -56,21 +61,23 @@ export declare class Lixa {
|
|
|
56
61
|
*
|
|
57
62
|
* @param config - The configuration object containing provider settings and optional session strategy
|
|
58
63
|
*/
|
|
59
|
-
constructor(config:
|
|
64
|
+
constructor(config: TConfig);
|
|
60
65
|
/**
|
|
61
|
-
* Checks if a provider is registered and
|
|
66
|
+
* Checks if a provider is both registered and configured for this instance.
|
|
67
|
+
* This is a type guard that narrows the provider type for use with getAuthUrl.
|
|
62
68
|
*
|
|
63
69
|
* @param provider - The provider name to check (case-insensitive)
|
|
64
|
-
* @returns True if the provider is registered, false otherwise
|
|
70
|
+
* @returns True if the provider is registered and configured, false otherwise
|
|
65
71
|
*
|
|
66
72
|
* @example
|
|
67
73
|
* ```typescript
|
|
68
|
-
* if (
|
|
69
|
-
*
|
|
74
|
+
* if (lixa.isProviderConfigured(provider)) {
|
|
75
|
+
* // TypeScript now knows provider is a valid ConfiguredProviderKey
|
|
76
|
+
* const authUrl = lixa.getAuthUrl(provider, state);
|
|
70
77
|
* }
|
|
71
78
|
* ```
|
|
72
79
|
*/
|
|
73
|
-
|
|
80
|
+
isProviderConfigured<T extends string>(provider: T): provider is T & ConfiguredProviderKey<TConfig>;
|
|
74
81
|
/**
|
|
75
82
|
* Registers custom OAuth providers for use with Lixa.
|
|
76
83
|
*
|
|
@@ -112,7 +119,7 @@ export declare class Lixa {
|
|
|
112
119
|
/**
|
|
113
120
|
* Generates the authorization URL for the specified provider.
|
|
114
121
|
*
|
|
115
|
-
* @param provider - The provider name (
|
|
122
|
+
* @param provider - The provider name (must be a configured provider key)
|
|
116
123
|
* @param state - The state parameter for CSRF protection
|
|
117
124
|
* @returns The complete authorization URL to redirect users to
|
|
118
125
|
*
|
|
@@ -125,11 +132,11 @@ export declare class Lixa {
|
|
|
125
132
|
* res.redirect(authUrl);
|
|
126
133
|
* ```
|
|
127
134
|
*/
|
|
128
|
-
getAuthUrl(provider: string, state: string): string;
|
|
135
|
+
getAuthUrl(provider: ConfiguredProviderKey<TConfig> | string, state: string): string;
|
|
129
136
|
/**
|
|
130
137
|
* Handles the OAuth callback and creates a user session.
|
|
131
138
|
*
|
|
132
|
-
* @param provider - The provider name
|
|
139
|
+
* @param provider - The provider name (must be a configured provider key)
|
|
133
140
|
* @param code - The authorization code from the provider
|
|
134
141
|
* @param state - The state parameter for validation
|
|
135
142
|
* @returns A Promise that resolves to a Session object
|
|
@@ -146,7 +153,7 @@ export declare class Lixa {
|
|
|
146
153
|
* ```
|
|
147
154
|
*/
|
|
148
155
|
handleCallback({ provider, code, state, }: {
|
|
149
|
-
provider: string;
|
|
156
|
+
provider: ConfiguredProviderKey<TConfig> | string;
|
|
150
157
|
code: string;
|
|
151
158
|
state?: string;
|
|
152
159
|
}): Promise<Session>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vunexa/lixa",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.9",
|
|
4
4
|
"description": "Lixa is a flexible, provider-agnostic OAuth and OpenID Connect (OIDC) client library that simplifies multi-provider authentication flows. It supports seamless integration with providers like Google and GitHub, offers extensible session management, and enables dynamic provider resolution based on callback URLs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"oauth",
|