@vunexa/lixa 0.0.1-alpha.9 → 0.1.1

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.
Files changed (84) hide show
  1. package/README.md +173 -143
  2. package/README.template.md +360 -0
  3. package/dist/dao/session-cache.d.ts +11 -0
  4. package/dist/dao/session-cache.d.ts.map +1 -0
  5. package/dist/dao/state-cache.d.ts +8 -6
  6. package/dist/dao/state-cache.d.ts.map +1 -1
  7. package/dist/dao/types.d.ts +376 -3
  8. package/dist/dao/types.d.ts.map +1 -1
  9. package/dist/export-types/index.d.ts +1397 -0
  10. package/dist/export-types/tsdoc-metadata.json +11 -0
  11. package/dist/index.cjs +1035 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.cts +1361 -0
  14. package/dist/index.d.ts +11 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +992 -9
  17. package/dist/index.js.map +1 -1
  18. package/dist/lixa.d.ts +280 -15
  19. package/dist/lixa.d.ts.map +1 -1
  20. package/dist/models/session.d.ts +316 -0
  21. package/dist/models/session.d.ts.map +1 -0
  22. package/dist/providers/IProvider.d.ts +127 -4
  23. package/dist/providers/IProvider.d.ts.map +1 -1
  24. package/dist/providers/index.d.ts +0 -2
  25. package/dist/providers/index.d.ts.map +1 -1
  26. package/dist/types.d.ts +195 -24
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/utils/user-info.d.ts +82 -0
  29. package/dist/utils/user-info.d.ts.map +1 -0
  30. package/docs/api/index.md +32 -0
  31. package/docs/api/lixa.iprovider.authorizationendpoint.md +13 -0
  32. package/docs/api/lixa.iprovider.md +100 -0
  33. package/docs/api/lixa.iprovider.tokenendpoint.md +13 -0
  34. package/docs/api/lixa.iprovider.userinfoendpoint.md +13 -0
  35. package/docs/api/lixa.lixa._constructor_.md +50 -0
  36. package/docs/api/lixa.lixa.generaterandomstate.md +23 -0
  37. package/docs/api/lixa.lixa.getauthurl.md +85 -0
  38. package/docs/api/lixa.lixa.handlecallback.md +73 -0
  39. package/docs/api/lixa.lixa.isproviderregistered.md +65 -0
  40. package/docs/api/lixa.lixa.md +164 -0
  41. package/docs/api/lixa.lixa.registerprovider.md +69 -0
  42. package/docs/api/lixa.lixaconfig.md +96 -0
  43. package/docs/api/lixa.lixaconfig.providers.md +13 -0
  44. package/docs/api/lixa.lixaconfig.sessionstrategy.md +13 -0
  45. package/docs/api/lixa.lixaconfig.statedao.md +13 -0
  46. package/docs/api/lixa.md +108 -0
  47. package/docs/api/lixa.providerconfig.clientid.md +13 -0
  48. package/docs/api/lixa.providerconfig.clientsecret.md +13 -0
  49. package/docs/api/lixa.providerconfig.extraconfig.md +13 -0
  50. package/docs/api/lixa.providerconfig.md +134 -0
  51. package/docs/api/lixa.providerconfig.redirecturi.md +13 -0
  52. package/docs/api/lixa.providerconfig.scopes.md +13 -0
  53. package/docs/api/lixa.session.md +77 -0
  54. package/docs/api/lixa.session.raw.md +13 -0
  55. package/docs/api/lixa.session.token.md +13 -0
  56. package/docs/api/lixa.sessionstrategy.createsession.md +56 -0
  57. package/docs/api/lixa.sessionstrategy.md +40 -0
  58. package/docs/images/account-linking.svg +1 -0
  59. package/docs/images/architecture.svg +1 -0
  60. package/docs/images/resource-connection.svg +1 -0
  61. package/package.json +18 -10
  62. package/dist/dao/state-cache.js +0 -18
  63. package/dist/dao/state-cache.js.map +0 -1
  64. package/dist/dao/types.js +0 -2
  65. package/dist/dao/types.js.map +0 -1
  66. package/dist/lixa.js +0 -244
  67. package/dist/lixa.js.map +0 -1
  68. package/dist/providers/IProvider.js +0 -2
  69. package/dist/providers/IProvider.js.map +0 -1
  70. package/dist/providers/github.d.ts +0 -9
  71. package/dist/providers/github.d.ts.map +0 -1
  72. package/dist/providers/github.js +0 -8
  73. package/dist/providers/github.js.map +0 -1
  74. package/dist/providers/google.d.ts +0 -9
  75. package/dist/providers/google.d.ts.map +0 -1
  76. package/dist/providers/google.js +0 -8
  77. package/dist/providers/google.js.map +0 -1
  78. package/dist/providers/index.js +0 -3
  79. package/dist/providers/index.js.map +0 -1
  80. package/dist/types.js +0 -2
  81. package/dist/types.js.map +0 -1
  82. package/dist/utils/constants.js +0 -4
  83. package/dist/utils/constants.js.map +0 -1
  84. package/index.d.ts +0 -229
@@ -1,9 +0,0 @@
1
- import { IProvider } from "./IProvider";
2
- declare class GithubProvider implements IProvider {
3
- providerType: string;
4
- authorizationEndpoint: string;
5
- tokenEndpoint: string;
6
- userInfoEndpoint: string;
7
- }
8
- export { GithubProvider };
9
- //# sourceMappingURL=github.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../src/providers/github.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,cAAM,cAAe,YAAW,SAAS;IACvC,YAAY,SAAY;IACxB,qBAAqB,SAA8C;IACnE,aAAa,SAAiD;IAC9D,gBAAgB,SAAiC;CAClD;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,8 +0,0 @@
1
- class GithubProvider {
2
- providerType = "GITHUB";
3
- authorizationEndpoint = "https://github.com/login/oauth/authorize";
4
- tokenEndpoint = "https://github.com/login/oauth/access_token";
5
- userInfoEndpoint = "https://api.github.com/user";
6
- }
7
- export { GithubProvider };
8
- //# sourceMappingURL=github.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"github.js","sourceRoot":"","sources":["../../src/providers/github.ts"],"names":[],"mappings":"AAEA,MAAM,cAAc;IAClB,YAAY,GAAG,QAAQ,CAAC;IACxB,qBAAqB,GAAG,0CAA0C,CAAC;IACnE,aAAa,GAAG,6CAA6C,CAAC;IAC9D,gBAAgB,GAAG,6BAA6B,CAAC;CAClD;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,9 +0,0 @@
1
- import { IProvider } from "./IProvider";
2
- declare class GoogleProvider implements IProvider {
3
- providerType: string;
4
- authorizationEndpoint: string;
5
- tokenEndpoint: string;
6
- userInfoEndpoint: string;
7
- }
8
- export { GoogleProvider };
9
- //# sourceMappingURL=google.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,cAAM,cAAe,YAAW,SAAS;IACvC,YAAY,SAAY;IACxB,qBAAqB,SAAkD;IACvE,aAAa,SAAyC;IACtD,gBAAgB,SAAmD;CACpE;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,8 +0,0 @@
1
- class GoogleProvider {
2
- providerType = "GOOGLE";
3
- authorizationEndpoint = "https://accounts.google.com/o/oauth2/v2/auth";
4
- tokenEndpoint = "https://oauth2.googleapis.com/token";
5
- userInfoEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo";
6
- }
7
- export { GoogleProvider };
8
- //# sourceMappingURL=google.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAEA,MAAM,cAAc;IAClB,YAAY,GAAG,QAAQ,CAAC;IACxB,qBAAqB,GAAG,8CAA8C,CAAC;IACvE,aAAa,GAAG,qCAAqC,CAAC;IACtD,gBAAgB,GAAG,+CAA+C,CAAC;CACpE;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,3 +0,0 @@
1
- export { GithubProvider } from "./github";
2
- export { GoogleProvider } from "./google";
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,4 +0,0 @@
1
- const GOOGLE = "google";
2
- const GITHUB = "github";
3
- export { GOOGLE, GITHUB };
4
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,QAAQ,CAAC;AACxB,MAAM,MAAM,GAAG,QAAQ,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC"}
package/index.d.ts DELETED
@@ -1,229 +0,0 @@
1
- /**
2
- * A flexible, provider-agnostic OAuth 2.0 and OpenID Connect (OIDC) client library for backend applications.
3
- *
4
- * @remarks
5
- * This package simplifies multi-provider authentication flows (e.g., Google, GitHub), supports extensible session management, and enables custom provider registration.
6
- *
7
- * @packageDocumentation
8
- */
9
-
10
- /**
11
- * Type representing the keys of configured providers
12
- */
13
- declare type ConfiguredProviderKey<T extends LixaConfig> = keyof T['providers'];
14
-
15
- /**
16
- * Interface for OAuth provider implementations.
17
- *
18
- * @remarks
19
- * Implement this interface to add support for custom OAuth providers.
20
- *
21
- * @public
22
- */
23
- export declare interface IProvider {
24
- /** The OAuth authorization endpoint URL */
25
- authorizationEndpoint: string;
26
- /** The OAuth token exchange endpoint URL */
27
- tokenEndpoint: string;
28
- /** The user information endpoint URL */
29
- userInfoEndpoint: string;
30
- }
31
-
32
- /**
33
- * A flexible, provider-agnostic OAuth 2.0 and OpenID Connect (OIDC) client library.
34
- *
35
- * @remarks
36
- * Lixa simplifies multi-provider authentication flows and supports extensible session management.
37
- *
38
- * @example
39
- * ```typescript
40
- * const lixa = new Lixa({
41
- * providers: {
42
- * google: {
43
- * clientId: 'your-client-id',
44
- * clientSecret: 'your-client-secret',
45
- * redirectUri: 'https://yourapp.com/auth/google/callback',
46
- * scopes: ['openid', 'email', 'profile']
47
- * }
48
- * }
49
- * });
50
- * ```
51
- *
52
- * @public
53
- */
54
- export declare class Lixa<TConfig extends LixaConfig = LixaConfig> {
55
- private static CONFIGURED_PROVIDERS;
56
- private static LOCAL_STATE_CACHE;
57
- private config;
58
- private stateDao;
59
- /**
60
- * Creates a new Lixa instance with the provided configuration.
61
- *
62
- * @param config - The configuration object containing provider settings and optional session strategy
63
- */
64
- constructor(config: TConfig);
65
- /**
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.
68
- *
69
- * @param provider - The provider name to check (case-insensitive)
70
- * @returns True if the provider is registered and configured, false otherwise
71
- *
72
- * @example
73
- * ```typescript
74
- * if (lixa.isProviderConfigured(provider)) {
75
- * // TypeScript now knows provider is a valid ConfiguredProviderKey
76
- * const authUrl = lixa.getAuthUrl(provider, state);
77
- * }
78
- * ```
79
- */
80
- isProviderConfigured<T extends string>(provider: T): provider is T & ConfiguredProviderKey<TConfig>;
81
- /**
82
- * Registers custom OAuth providers for use with Lixa.
83
- *
84
- * @param providerMap - A map of provider names to IProvider implementations
85
- *
86
- * @example
87
- * ```typescript
88
- * class CustomProvider implements IProvider {
89
- * authorizationEndpoint = 'https://custom.com/oauth/authorize';
90
- * tokenEndpoint = 'https://custom.com/oauth/token';
91
- * userInfoEndpoint = 'https://custom.com/api/user';
92
- * }
93
- *
94
- * Lixa.registerProvider({ custom: new CustomProvider() });
95
- * ```
96
- */
97
- static registerProvider(providerMap: {
98
- [key: string]: IProvider;
99
- }): void;
100
- /**
101
- * Generates a cryptographically secure random state parameter for OAuth flows.
102
- *
103
- * @returns A 32-character hexadecimal string
104
- *
105
- * @remarks
106
- * The state parameter is used to prevent CSRF attacks in OAuth flows.
107
- */
108
- static generateRandomState(): string;
109
- /**
110
- * Generates a cryptographically secure code verifier for PKCE flows.
111
- *
112
- * @returns A 64-character hexadecimal string
113
- *
114
- * @remarks
115
- * The code verifier is used in PKCE (Proof Key for Code Exchange) to enhance security.
116
- */
117
- private static generateCodeVerifier;
118
- private static buildCodeChallenge;
119
- /**
120
- * Generates the authorization URL for the specified provider.
121
- *
122
- * @param provider - The provider name (must be a configured provider key)
123
- * @param state - The state parameter for CSRF protection
124
- * @returns The complete authorization URL to redirect users to
125
- *
126
- * @throws Error when the provider is not configured
127
- *
128
- * @example
129
- * ```typescript
130
- * const state = Lixa.generateRandomState();
131
- * const authUrl = lixa.getAuthUrl('google', state);
132
- * res.redirect(authUrl);
133
- * ```
134
- */
135
- getAuthUrl(provider: ConfiguredProviderKey<TConfig> | string, state: string): string;
136
- /**
137
- * Handles the OAuth callback and creates a user session.
138
- *
139
- * @param provider - The provider name (must be a configured provider key)
140
- * @param code - The authorization code from the provider
141
- * @param state - The state parameter for validation
142
- * @returns A Promise that resolves to a Session object
143
- *
144
- * @throws Error when code or state is missing/invalid, or provider is not configured
145
- *
146
- * @example
147
- * ```typescript
148
- * const session = await lixa.handleCallback({
149
- * provider: 'google',
150
- * code: req.query.code,
151
- * state: req.query.state
152
- * });
153
- * ```
154
- */
155
- handleCallback({ provider, code, state, }: {
156
- provider: ConfiguredProviderKey<TConfig> | string;
157
- code: string;
158
- state?: string;
159
- }): Promise<Session>;
160
- private exchangeCodeForToken;
161
- private findProviderByType;
162
- }
163
-
164
- /**
165
- * Main configuration object for Lixa.
166
- *
167
- * @public
168
- */
169
- export declare interface LixaConfig {
170
- /** Map of provider names to their configurations */
171
- providers: Record<string, ProviderConfig>;
172
- /** Optional custom session creation strategy */
173
- sessionStrategy?: SessionStrategy;
174
- /** Optional custom state storage implementation */
175
- stateDao?: StateDao;
176
- }
177
-
178
- /**
179
- * Configuration for an OAuth provider.
180
- *
181
- * @public
182
- */
183
- export declare interface ProviderConfig {
184
- /** The OAuth client ID provided by the provider */
185
- clientId: string;
186
- /** The OAuth client secret provided by the provider */
187
- clientSecret: string;
188
- /** The redirect URI registered with the provider */
189
- redirectUri: string;
190
- /** Array of OAuth scopes to request */
191
- scopes: string[];
192
- /** Additional provider-specific configuration parameters */
193
- extraConfig?: Record<string, any>;
194
- }
195
-
196
- /**
197
- * Represents a user session after successful OAuth authentication.
198
- *
199
- * @public
200
- */
201
- export declare interface Session {
202
- /** The session token (typically the access token) */
203
- token: string;
204
- /** Raw token data from the OAuth provider */
205
- raw: any;
206
- }
207
-
208
- /**
209
- * Strategy interface for custom session creation.
210
- *
211
- * @public
212
- */
213
- export declare interface SessionStrategy {
214
- /**
215
- * Creates a session from OAuth token data.
216
- *
217
- * @param userInfo - The token data received from the OAuth provider
218
- * @returns A Promise that resolves to a Session object
219
- */
220
- createSession(userInfo: any): Promise<Session>;
221
- }
222
-
223
- declare interface StateDao {
224
- saveState(state: string, data: any, expiresInSeconds: number): Promise<void>;
225
- getState(state: string): Promise<any | null>;
226
- deleteState(state: string): Promise<void>;
227
- }
228
-
229
- export { }