@vunexa/lixa 0.0.1-alpha.10

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 (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +240 -0
  3. package/dist/dao/state-cache.d.ts +10 -0
  4. package/dist/dao/state-cache.d.ts.map +1 -0
  5. package/dist/dao/state-cache.js +18 -0
  6. package/dist/dao/state-cache.js.map +1 -0
  7. package/dist/dao/types.d.ts +6 -0
  8. package/dist/dao/types.d.ts.map +1 -0
  9. package/dist/dao/types.js +2 -0
  10. package/dist/dao/types.js.map +1 -0
  11. package/dist/index.d.ts +12 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +10 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/lixa.d.ts +160 -0
  16. package/dist/lixa.d.ts.map +1 -0
  17. package/dist/lixa.js +283 -0
  18. package/dist/lixa.js.map +1 -0
  19. package/dist/providers/IProvider.d.ts +18 -0
  20. package/dist/providers/IProvider.d.ts.map +1 -0
  21. package/dist/providers/IProvider.js +2 -0
  22. package/dist/providers/IProvider.js.map +1 -0
  23. package/dist/providers/github.d.ts +9 -0
  24. package/dist/providers/github.d.ts.map +1 -0
  25. package/dist/providers/github.js +8 -0
  26. package/dist/providers/github.js.map +1 -0
  27. package/dist/providers/google.d.ts +9 -0
  28. package/dist/providers/google.d.ts.map +1 -0
  29. package/dist/providers/google.js +8 -0
  30. package/dist/providers/google.js.map +1 -0
  31. package/dist/providers/index.d.ts +4 -0
  32. package/dist/providers/index.d.ts.map +1 -0
  33. package/dist/providers/index.js +3 -0
  34. package/dist/providers/index.js.map +1 -0
  35. package/dist/types.d.ts +67 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +2 -0
  38. package/dist/types.js.map +1 -0
  39. package/dist/utils/constants.d.ts +4 -0
  40. package/dist/utils/constants.d.ts.map +1 -0
  41. package/dist/utils/constants.js +4 -0
  42. package/dist/utils/constants.js.map +1 -0
  43. package/index.d.ts +261 -0
  44. package/package.json +63 -0
package/dist/lixa.js ADDED
@@ -0,0 +1,283 @@
1
+ import { randomBytes } from "crypto";
2
+ import { LocalStateCache } from "./dao/state-cache";
3
+ import crypto from "crypto";
4
+ /**
5
+ * A flexible, provider-agnostic OAuth 2.0 and OpenID Connect (OIDC) client library.
6
+ *
7
+ * @remarks
8
+ * Lixa simplifies multi-provider authentication flows and supports extensible session management.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { Lixa } from '@vunexa/lixa';
13
+ * import { GoogleProvider } from '@vunexa/lixa/providers';
14
+ *
15
+ * // Register providers before using them
16
+ * Lixa.registerProvider({ google: new GoogleProvider() });
17
+ *
18
+ * const config = Lixa.createConfig({
19
+ * providers: {
20
+ * google: {
21
+ * clientId: 'your-client-id',
22
+ * clientSecret: 'your-client-secret',
23
+ * redirectUri: 'https://yourapp.com/auth/google/callback',
24
+ * scopes: ['openid', 'email', 'profile']
25
+ * }
26
+ * }
27
+ * });
28
+ *
29
+ * const lixa = new Lixa(config);
30
+ * ```
31
+ *
32
+ * @public
33
+ */
34
+ class Lixa {
35
+ static CONFIGURED_PROVIDERS = new Map();
36
+ static LOCAL_STATE_CACHE = new LocalStateCache();
37
+ config;
38
+ stateDao;
39
+ /**
40
+ * Creates a new Lixa instance with the provided configuration.
41
+ *
42
+ * @param config - The configuration object containing provider settings and optional session strategy
43
+ */
44
+ constructor(config) {
45
+ // Validate that all providers in config are registered
46
+ const configuredProviders = Object.keys(config.providers);
47
+ const registeredProviders = Lixa.getRegisteredProviders();
48
+ for (const provider of configuredProviders) {
49
+ if (!registeredProviders.includes(provider.toLowerCase())) {
50
+ throw new Error(`Provider '${provider}' is not registered. Please register it first using Lixa.registerProvider()`);
51
+ }
52
+ }
53
+ this.config = config;
54
+ this.stateDao = config.stateDao || Lixa.LOCAL_STATE_CACHE;
55
+ }
56
+ /**
57
+ * Checks if a provider is both registered and configured for this instance.
58
+ * This is a type guard that narrows the provider type for use with getAuthUrl.
59
+ *
60
+ * @param provider - The provider name to check (case-insensitive)
61
+ * @returns True if the provider is registered and configured, false otherwise
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * if (lixa.isProviderConfigured(provider)) {
66
+ * // TypeScript now knows provider is a valid ConfiguredProviderKey
67
+ * const authUrl = lixa.getAuthUrl(provider, state);
68
+ * }
69
+ * ```
70
+ */
71
+ isProviderConfigured(provider) {
72
+ const providerType = provider.toLowerCase();
73
+ return Lixa.CONFIGURED_PROVIDERS.has(providerType) &&
74
+ this.config.providers.hasOwnProperty(providerType);
75
+ }
76
+ /**
77
+ * Registers custom OAuth providers for use with Lixa.
78
+ *
79
+ * @param providerMap - A map of provider names to IProvider implementations
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * class CustomProvider implements IProvider {
84
+ * authorizationEndpoint = 'https://custom.com/oauth/authorize';
85
+ * tokenEndpoint = 'https://custom.com/oauth/token';
86
+ * userInfoEndpoint = 'https://custom.com/api/user';
87
+ * }
88
+ *
89
+ * Lixa.registerProvider({ custom: new CustomProvider() });
90
+ * ```
91
+ */
92
+ static registerProvider(providerMap) {
93
+ Object.entries(providerMap).forEach(([key, providerImpl]) => {
94
+ Lixa.CONFIGURED_PROVIDERS.set(key.toLowerCase(), providerImpl);
95
+ });
96
+ }
97
+ /**
98
+ * Gets the list of registered provider names.
99
+ *
100
+ * @returns Array of registered provider names
101
+ */
102
+ static getRegisteredProviders() {
103
+ return Array.from(Lixa.CONFIGURED_PROVIDERS.keys());
104
+ }
105
+ /**
106
+ * Creates a type-safe configuration that only allows registered providers.
107
+ *
108
+ * @param config - Configuration object with providers that must be registered
109
+ * @returns The same configuration object, but with type safety for registered providers
110
+ */
111
+ static createConfig(config) {
112
+ // Validate that all providers in config are registered
113
+ const configuredProviders = Object.keys(config.providers);
114
+ const registeredProviders = Lixa.getRegisteredProviders();
115
+ for (const provider of configuredProviders) {
116
+ if (!registeredProviders.includes(provider.toLowerCase())) {
117
+ throw new Error(`Provider '${provider}' is not registered. Please register it first using Lixa.registerProvider()`);
118
+ }
119
+ }
120
+ return config;
121
+ }
122
+ /**
123
+ * Generates a cryptographically secure random state parameter for OAuth flows.
124
+ *
125
+ * @returns A 32-character hexadecimal string
126
+ *
127
+ * @remarks
128
+ * The state parameter is used to prevent CSRF attacks in OAuth flows.
129
+ */
130
+ static generateRandomState() {
131
+ return randomBytes(16).toString("hex");
132
+ }
133
+ /**
134
+ * Generates a cryptographically secure code verifier for PKCE flows.
135
+ *
136
+ * @returns A 64-character hexadecimal string
137
+ *
138
+ * @remarks
139
+ * The code verifier is used in PKCE (Proof Key for Code Exchange) to enhance security.
140
+ */
141
+ static generateCodeVerifier() {
142
+ return randomBytes(32).toString("hex");
143
+ }
144
+ static buildCodeChallenge(codeVerifier) {
145
+ const hash = crypto
146
+ .createHash("sha256")
147
+ .update(codeVerifier)
148
+ .digest("base64");
149
+ // Convert to base64url
150
+ return hash.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
151
+ }
152
+ /**
153
+ * Generates the authorization URL for the specified provider.
154
+ *
155
+ * @param provider - The provider name (must be a configured provider key)
156
+ * @param state - The state parameter for CSRF protection
157
+ * @returns The complete authorization URL to redirect users to
158
+ *
159
+ * @throws Error when the provider is not configured
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * const state = Lixa.generateRandomState();
164
+ * const authUrl = lixa.getAuthUrl('google', state);
165
+ * res.redirect(authUrl);
166
+ * ```
167
+ */
168
+ getAuthUrl(provider, state) {
169
+ const providerType = String(provider).toLowerCase();
170
+ const providerConfig = this.findProviderByType(providerType);
171
+ const providerImpl = Lixa.CONFIGURED_PROVIDERS.get(providerType);
172
+ if (!providerConfig || !providerImpl) {
173
+ throw new Error(`Provider ${providerType} not configured`);
174
+ }
175
+ const codeVerifier = Lixa.generateCodeVerifier();
176
+ const codeChallenge = Lixa.buildCodeChallenge(codeVerifier);
177
+ // Cache the state paramaeter with TTL of 5 minutes (300 seconds)
178
+ // We dont care about value. we are onl interested in key existence
179
+ this.stateDao.saveState(state, {
180
+ createdAt: Date.now(),
181
+ provider: providerType,
182
+ codeVerifier,
183
+ }, 300 // 5 minutes in seconds
184
+ );
185
+ const params = new URLSearchParams({
186
+ client_id: providerConfig.clientId,
187
+ redirect_uri: providerConfig.redirectUri,
188
+ scope: providerConfig.scopes.join(" "),
189
+ state,
190
+ response_type: "code",
191
+ code_challenge: codeChallenge,
192
+ code_challenge_method: "S256",
193
+ ...providerConfig.extraConfig,
194
+ });
195
+ return `${providerImpl.authorizationEndpoint}?${params.toString()}`;
196
+ }
197
+ /**
198
+ * Handles the OAuth callback and creates a user session.
199
+ *
200
+ * @param provider - The provider name (must be a configured provider key)
201
+ * @param code - The authorization code from the provider
202
+ * @param state - The state parameter for validation
203
+ * @returns A Promise that resolves to a Session object
204
+ *
205
+ * @throws Error when code or state is missing/invalid, or provider is not configured
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * const session = await lixa.handleCallback({
210
+ * provider: 'google',
211
+ * code: req.query.code,
212
+ * state: req.query.state
213
+ * });
214
+ * ```
215
+ */
216
+ async handleCallback({ provider, code, state, }) {
217
+ if (!code || code.trim() === "") {
218
+ throw new Error("Invalid or missing code in callback");
219
+ }
220
+ if (!state || state.trim() === "") {
221
+ throw new Error("Invalid or missing state in callback");
222
+ }
223
+ //Validate state here
224
+ const cachedState = await this.stateDao.getState(state);
225
+ if (!cachedState) {
226
+ throw new Error("Invalid or expired state");
227
+ }
228
+ // State is valid, remove it from cache to prevent reuse
229
+ await this.stateDao.deleteState(state);
230
+ //Get code verifier from cached state
231
+ const codeVerifier = cachedState.codeVerifier;
232
+ const providerType = String(provider).toLowerCase();
233
+ const providerConfig = this.findProviderByType(providerType);
234
+ const providerImpl = Lixa.CONFIGURED_PROVIDERS.get(providerType);
235
+ if (!providerConfig || !providerImpl) {
236
+ throw new Error(`Provider ${String(provider)} not configured`);
237
+ }
238
+ // Exchange code for tokens and fetch user info here.
239
+ const tokens = await this.exchangeCodeForToken(code, providerConfig, providerImpl, codeVerifier);
240
+ // For simplicity, we'll just return the tokens as the session.
241
+ // In a real implementation, you'd fetch user info and create a session.
242
+ const session = {
243
+ token: tokens.access_token,
244
+ raw: tokens, // Replace with actual user info
245
+ };
246
+ // If a session strategy is provided, use it to create a session.
247
+ if (this.config.sessionStrategy) {
248
+ return this.config.sessionStrategy.createSession(session.raw);
249
+ }
250
+ return session;
251
+ }
252
+ async exchangeCodeForToken(code, providerConfig, providerImpl, codeVerifier) {
253
+ // Build the request body
254
+ const body = {
255
+ client_id: providerConfig.clientId,
256
+ client_secret: providerConfig.clientSecret,
257
+ code,
258
+ redirect_uri: providerConfig.redirectUri,
259
+ grant_type: "authorization_code",
260
+ };
261
+ if (codeVerifier) {
262
+ body.code_verifier = codeVerifier;
263
+ }
264
+ const params = new URLSearchParams(body);
265
+ const response = await fetch(providerImpl.tokenEndpoint, {
266
+ method: "POST",
267
+ headers: {
268
+ "Content-Type": "application/x-www-form-urlencoded",
269
+ Accept: "application/json",
270
+ },
271
+ body: params.toString(),
272
+ });
273
+ if (!response.ok) {
274
+ throw new Error(`Token exchange failed: ${response.status} ${response.statusText}`);
275
+ }
276
+ return response.json();
277
+ }
278
+ findProviderByType(providerType) {
279
+ return this.config.providers[providerType];
280
+ }
281
+ }
282
+ export { Lixa };
283
+ //# sourceMappingURL=lixa.js.map
@@ -0,0 +1 @@
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;AAY5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,IAAI;IACA,MAAM,CAAC,oBAAoB,GAA2B,IAAI,GAAG,EAAE,CAAC;IAChE,MAAM,CAAC,iBAAiB,GAAG,IAAI,eAAe,EA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+ /**
2
+ * Interface for OAuth provider implementations.
3
+ *
4
+ * @remarks
5
+ * Implement this interface to add support for custom OAuth providers.
6
+ *
7
+ * @public
8
+ */
9
+ interface IProvider {
10
+ /** The OAuth authorization endpoint URL */
11
+ authorizationEndpoint: string;
12
+ /** The OAuth token exchange endpoint URL */
13
+ tokenEndpoint: string;
14
+ /** The user information endpoint URL */
15
+ userInfoEndpoint: string;
16
+ }
17
+ export { IProvider };
18
+ //# sourceMappingURL=IProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IProvider.d.ts","sourceRoot":"","sources":["../../src/providers/IProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,UAAU,SAAS;IACjB,2CAA2C;IAC3C,qBAAqB,EAAE,MAAM,CAAC;IAC9B,4CAA4C;IAC5C,aAAa,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../src/providers/IProvider.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,8 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,9 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,8 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,4 @@
1
+ export { IProvider } from "./IProvider";
2
+ export { GithubProvider } from "./github";
3
+ export { GoogleProvider } from "./google";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { GithubProvider } from "./github";
2
+ export { GoogleProvider } from "./google";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,67 @@
1
+ import { StateDao } from "./dao/types";
2
+ /**
3
+ * Configuration for an OAuth provider.
4
+ *
5
+ * @public
6
+ */
7
+ export interface ProviderConfig {
8
+ /** The OAuth client ID provided by the provider */
9
+ clientId: string;
10
+ /** The OAuth client secret provided by the provider */
11
+ clientSecret: string;
12
+ /** The redirect URI registered with the provider */
13
+ redirectUri: string;
14
+ /** Array of OAuth scopes to request */
15
+ scopes: string[];
16
+ /** Additional provider-specific configuration parameters */
17
+ extraConfig?: Record<string, any>;
18
+ }
19
+ /**
20
+ * Main configuration object for Lixa.
21
+ * Only allows providers that have been registered through registerProvider.
22
+ *
23
+ * @public
24
+ */
25
+ export interface LixaConfig<TRegisteredProviders extends string = string> {
26
+ /** Map of registered provider names to their configurations */
27
+ providers: Record<TRegisteredProviders, ProviderConfig>;
28
+ /** Optional custom session creation strategy */
29
+ sessionStrategy?: SessionStrategy;
30
+ /** Optional custom state storage implementation */
31
+ stateDao?: StateDao;
32
+ }
33
+ /**
34
+ * Strategy interface for custom session creation.
35
+ *
36
+ * @public
37
+ */
38
+ export interface SessionStrategy {
39
+ /**
40
+ * Creates a session from OAuth token data.
41
+ *
42
+ * @param userInfo - The token data received from the OAuth provider
43
+ * @returns A Promise that resolves to a Session object
44
+ */
45
+ createSession(userInfo: any): Promise<Session>;
46
+ }
47
+ /**
48
+ * Represents a user session after successful OAuth authentication.
49
+ *
50
+ * @public
51
+ */
52
+ export interface Session {
53
+ /** The session token (typically the access token) */
54
+ token: string;
55
+ /** Raw token data from the OAuth provider */
56
+ raw: any;
57
+ }
58
+ /**
59
+ * Helper type to create a configuration with only registered providers.
60
+ * Use this with Lixa.createConfig() for type safety.
61
+ *
62
+ * @public
63
+ */
64
+ export type SafeLixaConfig<TProviders extends Record<string, ProviderConfig>> = LixaConfig<keyof TProviders & string> & {
65
+ providers: TProviders;
66
+ };
67
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACnC;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU,CAAC,oBAAoB,SAAS,MAAM,GAAG,MAAM;IACtE,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC,oBAAoB,EAAE,cAAc,CAAC,CAAC;IACxD,gDAAgD;IAChD,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,mDAAmD;IACnD,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,aAAa,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAChD;AAED;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACtB,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,GAAG,EAAE,GAAG,CAAC;CACV;AAED;;;;;GAKG;AACH,MAAM,MAAM,cAAc,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,IAAI,UAAU,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG;IACtH,SAAS,EAAE,UAAU,CAAC;CACvB,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ declare const GOOGLE = "google";
2
+ declare const GITHUB = "github";
3
+ export { GOOGLE, GITHUB };
4
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,MAAM,WAAW,CAAC;AACxB,QAAA,MAAM,MAAM,WAAW,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ const GOOGLE = "google";
2
+ const GITHUB = "github";
3
+ export { GOOGLE, GITHUB };
4
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
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"}