@l4yercak3/cli 1.2.16 → 1.2.19

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 (31) hide show
  1. package/.claude/settings.local.json +3 -1
  2. package/docs/CRM-PIPELINES-SEQUENCES-SPEC.md +429 -0
  3. package/docs/INTEGRATION_PATHS_ARCHITECTURE.md +1543 -0
  4. package/package.json +1 -1
  5. package/src/commands/login.js +26 -7
  6. package/src/commands/spread.js +251 -10
  7. package/src/detectors/database-detector.js +245 -0
  8. package/src/detectors/expo-detector.js +4 -4
  9. package/src/detectors/index.js +17 -4
  10. package/src/generators/api-only/client.js +683 -0
  11. package/src/generators/api-only/index.js +96 -0
  12. package/src/generators/api-only/types.js +618 -0
  13. package/src/generators/api-only/webhooks.js +377 -0
  14. package/src/generators/env-generator.js +23 -8
  15. package/src/generators/expo-auth-generator.js +1009 -0
  16. package/src/generators/index.js +88 -2
  17. package/src/generators/mcp-guide-generator.js +256 -0
  18. package/src/generators/quickstart/components/index.js +1699 -0
  19. package/src/generators/quickstart/components-mobile/index.js +1440 -0
  20. package/src/generators/quickstart/database/convex.js +1257 -0
  21. package/src/generators/quickstart/database/index.js +34 -0
  22. package/src/generators/quickstart/database/supabase.js +1132 -0
  23. package/src/generators/quickstart/hooks/index.js +1065 -0
  24. package/src/generators/quickstart/index.js +177 -0
  25. package/src/generators/quickstart/pages/index.js +1466 -0
  26. package/src/generators/quickstart/screens/index.js +1498 -0
  27. package/src/mcp/registry/domains/benefits.js +798 -0
  28. package/src/mcp/registry/index.js +2 -0
  29. package/tests/database-detector.test.js +221 -0
  30. package/tests/expo-detector.test.js +3 -4
  31. package/tests/generators-index.test.js +215 -3
@@ -0,0 +1,1009 @@
1
+ /**
2
+ * Expo Auth Session Generator
3
+ * Generates OAuth authentication for Expo/React Native projects using expo-auth-session
4
+ */
5
+
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const { ensureDir, writeFileWithBackup, checkFileOverwrite } = require('../utils/file-utils');
9
+
10
+ class ExpoAuthGenerator {
11
+ /**
12
+ * Generate expo-auth-session configuration
13
+ * @param {Object} options - Generation options
14
+ * @returns {Promise<Object>} - Generated file paths
15
+ */
16
+ async generate(options) {
17
+ const { projectPath, oauthProviders = [], isTypeScript } = options;
18
+
19
+ const results = {};
20
+
21
+ // Determine output directory
22
+ let outputDir;
23
+ if (fs.existsSync(path.join(projectPath, 'src'))) {
24
+ outputDir = path.join(projectPath, 'src', 'lib', 'l4yercak3', 'auth');
25
+ } else {
26
+ outputDir = path.join(projectPath, 'lib', 'l4yercak3', 'auth');
27
+ }
28
+
29
+ ensureDir(outputDir);
30
+
31
+ const ext = isTypeScript ? 'ts' : 'js';
32
+
33
+ // Generate auth provider context
34
+ results.authContext = await this.generateAuthContext(outputDir, ext, isTypeScript, oauthProviders);
35
+
36
+ // Generate OAuth hooks for each provider
37
+ if (oauthProviders.includes('google')) {
38
+ results.googleAuth = await this.generateGoogleAuth(outputDir, ext, isTypeScript);
39
+ }
40
+
41
+ if (oauthProviders.includes('github')) {
42
+ results.githubAuth = await this.generateGithubAuth(outputDir, ext, isTypeScript);
43
+ }
44
+
45
+ if (oauthProviders.includes('microsoft')) {
46
+ results.microsoftAuth = await this.generateMicrosoftAuth(outputDir, ext, isTypeScript);
47
+ }
48
+
49
+ // Generate index file
50
+ results.index = await this.generateIndex(outputDir, ext, isTypeScript, oauthProviders);
51
+
52
+ return results;
53
+ }
54
+
55
+ async generateAuthContext(outputDir, ext, isTypeScript, oauthProviders) {
56
+ const outputPath = path.join(outputDir, `AuthContext.${isTypeScript ? 'tsx' : 'jsx'}`);
57
+
58
+ const action = await checkFileOverwrite(outputPath);
59
+ if (action === 'skip') {
60
+ return null;
61
+ }
62
+
63
+ const content = isTypeScript
64
+ ? this.getAuthContextTS(oauthProviders)
65
+ : this.getAuthContextJS(oauthProviders);
66
+
67
+ return writeFileWithBackup(outputPath, content, action);
68
+ }
69
+
70
+ getAuthContextTS(_oauthProviders) {
71
+ return `/**
72
+ * Auth Context for Expo
73
+ * Provides authentication state and methods using expo-auth-session
74
+ * Auto-generated by @l4yercak3/cli
75
+ */
76
+
77
+ import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
78
+ import * as SecureStore from 'expo-secure-store';
79
+ import { getL4yercak3Client } from '../client';
80
+
81
+ interface User {
82
+ id: string;
83
+ email: string;
84
+ name?: string;
85
+ image?: string;
86
+ provider: string;
87
+ }
88
+
89
+ interface AuthContextType {
90
+ user: User | null;
91
+ isLoading: boolean;
92
+ isAuthenticated: boolean;
93
+ signIn: (token: string, user: User) => Promise<void>;
94
+ signOut: () => Promise<void>;
95
+ refreshToken: () => Promise<void>;
96
+ }
97
+
98
+ const AuthContext = createContext<AuthContextType | undefined>(undefined);
99
+
100
+ const TOKEN_KEY = 'l4yercak3_auth_token';
101
+ const USER_KEY = 'l4yercak3_user';
102
+
103
+ interface AuthProviderProps {
104
+ children: ReactNode;
105
+ }
106
+
107
+ export function AuthProvider({ children }: AuthProviderProps) {
108
+ const [user, setUser] = useState<User | null>(null);
109
+ const [isLoading, setIsLoading] = useState(true);
110
+
111
+ useEffect(() => {
112
+ loadStoredAuth();
113
+ }, []);
114
+
115
+ const loadStoredAuth = async () => {
116
+ try {
117
+ const [token, storedUser] = await Promise.all([
118
+ SecureStore.getItemAsync(TOKEN_KEY),
119
+ SecureStore.getItemAsync(USER_KEY),
120
+ ]);
121
+
122
+ if (token && storedUser) {
123
+ const parsedUser = JSON.parse(storedUser);
124
+ setUser(parsedUser);
125
+
126
+ // Configure client with token
127
+ const client = getL4yercak3Client();
128
+ client.setAuthToken(token);
129
+ }
130
+ } catch (error) {
131
+ console.error('Failed to load stored auth:', error);
132
+ } finally {
133
+ setIsLoading(false);
134
+ }
135
+ };
136
+
137
+ const signIn = async (token: string, userData: User) => {
138
+ try {
139
+ await Promise.all([
140
+ SecureStore.setItemAsync(TOKEN_KEY, token),
141
+ SecureStore.setItemAsync(USER_KEY, JSON.stringify(userData)),
142
+ ]);
143
+
144
+ // Configure client with token
145
+ const client = getL4yercak3Client();
146
+ client.setAuthToken(token);
147
+
148
+ setUser(userData);
149
+ } catch (error) {
150
+ console.error('Failed to sign in:', error);
151
+ throw error;
152
+ }
153
+ };
154
+
155
+ const signOut = async () => {
156
+ try {
157
+ await Promise.all([
158
+ SecureStore.deleteItemAsync(TOKEN_KEY),
159
+ SecureStore.deleteItemAsync(USER_KEY),
160
+ ]);
161
+
162
+ // Clear client token
163
+ const client = getL4yercak3Client();
164
+ client.setAuthToken(null);
165
+
166
+ setUser(null);
167
+ } catch (error) {
168
+ console.error('Failed to sign out:', error);
169
+ throw error;
170
+ }
171
+ };
172
+
173
+ const refreshToken = async () => {
174
+ try {
175
+ const client = getL4yercak3Client();
176
+ const newToken = await client.refreshAuthToken();
177
+
178
+ if (newToken) {
179
+ await SecureStore.setItemAsync(TOKEN_KEY, newToken);
180
+ client.setAuthToken(newToken);
181
+ }
182
+ } catch (error) {
183
+ console.error('Failed to refresh token:', error);
184
+ // If refresh fails, sign out
185
+ await signOut();
186
+ }
187
+ };
188
+
189
+ return (
190
+ <AuthContext.Provider
191
+ value={{
192
+ user,
193
+ isLoading,
194
+ isAuthenticated: !!user,
195
+ signIn,
196
+ signOut,
197
+ refreshToken,
198
+ }}
199
+ >
200
+ {children}
201
+ </AuthContext.Provider>
202
+ );
203
+ }
204
+
205
+ export function useAuth() {
206
+ const context = useContext(AuthContext);
207
+ if (context === undefined) {
208
+ throw new Error('useAuth must be used within an AuthProvider');
209
+ }
210
+ return context;
211
+ }
212
+ `;
213
+ }
214
+
215
+ getAuthContextJS(_oauthProviders) {
216
+ return `/**
217
+ * Auth Context for Expo
218
+ * Provides authentication state and methods using expo-auth-session
219
+ * Auto-generated by @l4yercak3/cli
220
+ */
221
+
222
+ import React, { createContext, useContext, useState, useEffect } from 'react';
223
+ import * as SecureStore from 'expo-secure-store';
224
+ import { getL4yercak3Client } from '../client';
225
+
226
+ const AuthContext = createContext(undefined);
227
+
228
+ const TOKEN_KEY = 'l4yercak3_auth_token';
229
+ const USER_KEY = 'l4yercak3_user';
230
+
231
+ export function AuthProvider({ children }) {
232
+ const [user, setUser] = useState(null);
233
+ const [isLoading, setIsLoading] = useState(true);
234
+
235
+ useEffect(() => {
236
+ loadStoredAuth();
237
+ }, []);
238
+
239
+ const loadStoredAuth = async () => {
240
+ try {
241
+ const [token, storedUser] = await Promise.all([
242
+ SecureStore.getItemAsync(TOKEN_KEY),
243
+ SecureStore.getItemAsync(USER_KEY),
244
+ ]);
245
+
246
+ if (token && storedUser) {
247
+ const parsedUser = JSON.parse(storedUser);
248
+ setUser(parsedUser);
249
+
250
+ // Configure client with token
251
+ const client = getL4yercak3Client();
252
+ client.setAuthToken(token);
253
+ }
254
+ } catch (error) {
255
+ console.error('Failed to load stored auth:', error);
256
+ } finally {
257
+ setIsLoading(false);
258
+ }
259
+ };
260
+
261
+ const signIn = async (token, userData) => {
262
+ try {
263
+ await Promise.all([
264
+ SecureStore.setItemAsync(TOKEN_KEY, token),
265
+ SecureStore.setItemAsync(USER_KEY, JSON.stringify(userData)),
266
+ ]);
267
+
268
+ // Configure client with token
269
+ const client = getL4yercak3Client();
270
+ client.setAuthToken(token);
271
+
272
+ setUser(userData);
273
+ } catch (error) {
274
+ console.error('Failed to sign in:', error);
275
+ throw error;
276
+ }
277
+ };
278
+
279
+ const signOut = async () => {
280
+ try {
281
+ await Promise.all([
282
+ SecureStore.deleteItemAsync(TOKEN_KEY),
283
+ SecureStore.deleteItemAsync(USER_KEY),
284
+ ]);
285
+
286
+ // Clear client token
287
+ const client = getL4yercak3Client();
288
+ client.setAuthToken(null);
289
+
290
+ setUser(null);
291
+ } catch (error) {
292
+ console.error('Failed to sign out:', error);
293
+ throw error;
294
+ }
295
+ };
296
+
297
+ const refreshToken = async () => {
298
+ try {
299
+ const client = getL4yercak3Client();
300
+ const newToken = await client.refreshAuthToken();
301
+
302
+ if (newToken) {
303
+ await SecureStore.setItemAsync(TOKEN_KEY, newToken);
304
+ client.setAuthToken(newToken);
305
+ }
306
+ } catch (error) {
307
+ console.error('Failed to refresh token:', error);
308
+ // If refresh fails, sign out
309
+ await signOut();
310
+ }
311
+ };
312
+
313
+ return (
314
+ <AuthContext.Provider
315
+ value={{
316
+ user,
317
+ isLoading,
318
+ isAuthenticated: !!user,
319
+ signIn,
320
+ signOut,
321
+ refreshToken,
322
+ }}
323
+ >
324
+ {children}
325
+ </AuthContext.Provider>
326
+ );
327
+ }
328
+
329
+ export function useAuth() {
330
+ const context = useContext(AuthContext);
331
+ if (context === undefined) {
332
+ throw new Error('useAuth must be used within an AuthProvider');
333
+ }
334
+ return context;
335
+ }
336
+ `;
337
+ }
338
+
339
+ async generateGoogleAuth(outputDir, ext, isTypeScript) {
340
+ const outputPath = path.join(outputDir, `useGoogleAuth.${ext}`);
341
+
342
+ const action = await checkFileOverwrite(outputPath);
343
+ if (action === 'skip') {
344
+ return null;
345
+ }
346
+
347
+ const content = isTypeScript
348
+ ? this.getGoogleAuthTS()
349
+ : this.getGoogleAuthJS();
350
+
351
+ return writeFileWithBackup(outputPath, content, action);
352
+ }
353
+
354
+ getGoogleAuthTS() {
355
+ return `/**
356
+ * Google OAuth Hook for Expo
357
+ * Uses expo-auth-session for Google authentication
358
+ * Auto-generated by @l4yercak3/cli
359
+ */
360
+
361
+ import { useState, useEffect } from 'react';
362
+ import * as Google from 'expo-auth-session/providers/google';
363
+ import * as WebBrowser from 'expo-web-browser';
364
+ import { useAuth } from './AuthContext';
365
+ import { getL4yercak3Client } from '../client';
366
+
367
+ WebBrowser.maybeCompleteAuthSession();
368
+
369
+ interface UseGoogleAuthOptions {
370
+ expoClientId?: string;
371
+ iosClientId?: string;
372
+ androidClientId?: string;
373
+ webClientId?: string;
374
+ }
375
+
376
+ export function useGoogleAuth(options: UseGoogleAuthOptions = {}) {
377
+ const { signIn } = useAuth();
378
+ const [isLoading, setIsLoading] = useState(false);
379
+ const [error, setError] = useState<Error | null>(null);
380
+
381
+ const [request, response, promptAsync] = Google.useAuthRequest({
382
+ expoClientId: options.expoClientId || process.env.EXPO_PUBLIC_GOOGLE_CLIENT_ID,
383
+ iosClientId: options.iosClientId || process.env.EXPO_PUBLIC_GOOGLE_IOS_CLIENT_ID,
384
+ androidClientId: options.androidClientId || process.env.EXPO_PUBLIC_GOOGLE_ANDROID_CLIENT_ID,
385
+ webClientId: options.webClientId || process.env.EXPO_PUBLIC_GOOGLE_WEB_CLIENT_ID,
386
+ scopes: ['openid', 'profile', 'email'],
387
+ });
388
+
389
+ useEffect(() => {
390
+ if (response?.type === 'success') {
391
+ handleGoogleSuccess(response.authentication?.accessToken);
392
+ } else if (response?.type === 'error') {
393
+ setError(new Error(response.error?.message || 'Google authentication failed'));
394
+ }
395
+ }, [response]);
396
+
397
+ const handleGoogleSuccess = async (accessToken: string | undefined) => {
398
+ if (!accessToken) {
399
+ setError(new Error('No access token received'));
400
+ return;
401
+ }
402
+
403
+ setIsLoading(true);
404
+ setError(null);
405
+
406
+ try {
407
+ // Fetch user info from Google
408
+ const userInfoResponse = await fetch(
409
+ 'https://www.googleapis.com/userinfo/v2/me',
410
+ { headers: { Authorization: \`Bearer \${accessToken}\` } }
411
+ );
412
+ const googleUser = await userInfoResponse.json();
413
+
414
+ // Exchange with L4YERCAK3 backend
415
+ const client = getL4yercak3Client();
416
+ const authResult = await client.authenticateWithProvider('google', {
417
+ accessToken,
418
+ email: googleUser.email,
419
+ name: googleUser.name,
420
+ image: googleUser.picture,
421
+ });
422
+
423
+ // Sign in with the result
424
+ await signIn(authResult.token, {
425
+ id: authResult.user.id,
426
+ email: googleUser.email,
427
+ name: googleUser.name,
428
+ image: googleUser.picture,
429
+ provider: 'google',
430
+ });
431
+ } catch (err) {
432
+ setError(err instanceof Error ? err : new Error('Authentication failed'));
433
+ } finally {
434
+ setIsLoading(false);
435
+ }
436
+ };
437
+
438
+ const signInWithGoogle = async () => {
439
+ setError(null);
440
+ try {
441
+ await promptAsync();
442
+ } catch (err) {
443
+ setError(err instanceof Error ? err : new Error('Failed to initiate Google sign in'));
444
+ }
445
+ };
446
+
447
+ return {
448
+ signInWithGoogle,
449
+ isLoading,
450
+ error,
451
+ isReady: !!request,
452
+ };
453
+ }
454
+ `;
455
+ }
456
+
457
+ getGoogleAuthJS() {
458
+ return `/**
459
+ * Google OAuth Hook for Expo
460
+ * Uses expo-auth-session for Google authentication
461
+ * Auto-generated by @l4yercak3/cli
462
+ */
463
+
464
+ import { useState, useEffect } from 'react';
465
+ import * as Google from 'expo-auth-session/providers/google';
466
+ import * as WebBrowser from 'expo-web-browser';
467
+ import { useAuth } from './AuthContext';
468
+ import { getL4yercak3Client } from '../client';
469
+
470
+ WebBrowser.maybeCompleteAuthSession();
471
+
472
+ export function useGoogleAuth(options = {}) {
473
+ const { signIn } = useAuth();
474
+ const [isLoading, setIsLoading] = useState(false);
475
+ const [error, setError] = useState(null);
476
+
477
+ const [request, response, promptAsync] = Google.useAuthRequest({
478
+ expoClientId: options.expoClientId || process.env.EXPO_PUBLIC_GOOGLE_CLIENT_ID,
479
+ iosClientId: options.iosClientId || process.env.EXPO_PUBLIC_GOOGLE_IOS_CLIENT_ID,
480
+ androidClientId: options.androidClientId || process.env.EXPO_PUBLIC_GOOGLE_ANDROID_CLIENT_ID,
481
+ webClientId: options.webClientId || process.env.EXPO_PUBLIC_GOOGLE_WEB_CLIENT_ID,
482
+ scopes: ['openid', 'profile', 'email'],
483
+ });
484
+
485
+ useEffect(() => {
486
+ if (response?.type === 'success') {
487
+ handleGoogleSuccess(response.authentication?.accessToken);
488
+ } else if (response?.type === 'error') {
489
+ setError(new Error(response.error?.message || 'Google authentication failed'));
490
+ }
491
+ }, [response]);
492
+
493
+ const handleGoogleSuccess = async (accessToken) => {
494
+ if (!accessToken) {
495
+ setError(new Error('No access token received'));
496
+ return;
497
+ }
498
+
499
+ setIsLoading(true);
500
+ setError(null);
501
+
502
+ try {
503
+ // Fetch user info from Google
504
+ const userInfoResponse = await fetch(
505
+ 'https://www.googleapis.com/userinfo/v2/me',
506
+ { headers: { Authorization: \`Bearer \${accessToken}\` } }
507
+ );
508
+ const googleUser = await userInfoResponse.json();
509
+
510
+ // Exchange with L4YERCAK3 backend
511
+ const client = getL4yercak3Client();
512
+ const authResult = await client.authenticateWithProvider('google', {
513
+ accessToken,
514
+ email: googleUser.email,
515
+ name: googleUser.name,
516
+ image: googleUser.picture,
517
+ });
518
+
519
+ // Sign in with the result
520
+ await signIn(authResult.token, {
521
+ id: authResult.user.id,
522
+ email: googleUser.email,
523
+ name: googleUser.name,
524
+ image: googleUser.picture,
525
+ provider: 'google',
526
+ });
527
+ } catch (err) {
528
+ setError(err instanceof Error ? err : new Error('Authentication failed'));
529
+ } finally {
530
+ setIsLoading(false);
531
+ }
532
+ };
533
+
534
+ const signInWithGoogle = async () => {
535
+ setError(null);
536
+ try {
537
+ await promptAsync();
538
+ } catch (err) {
539
+ setError(err instanceof Error ? err : new Error('Failed to initiate Google sign in'));
540
+ }
541
+ };
542
+
543
+ return {
544
+ signInWithGoogle,
545
+ isLoading,
546
+ error,
547
+ isReady: !!request,
548
+ };
549
+ }
550
+ `;
551
+ }
552
+
553
+ async generateGithubAuth(outputDir, ext, isTypeScript) {
554
+ const outputPath = path.join(outputDir, `useGithubAuth.${ext}`);
555
+
556
+ const action = await checkFileOverwrite(outputPath);
557
+ if (action === 'skip') {
558
+ return null;
559
+ }
560
+
561
+ const content = isTypeScript
562
+ ? this.getGithubAuthTS()
563
+ : this.getGithubAuthJS();
564
+
565
+ return writeFileWithBackup(outputPath, content, action);
566
+ }
567
+
568
+ getGithubAuthTS() {
569
+ return `/**
570
+ * GitHub OAuth Hook for Expo
571
+ * Uses expo-auth-session for GitHub authentication
572
+ * Auto-generated by @l4yercak3/cli
573
+ */
574
+
575
+ import { useState, useEffect } from 'react';
576
+ import * as AuthSession from 'expo-auth-session';
577
+ import * as WebBrowser from 'expo-web-browser';
578
+ import { useAuth } from './AuthContext';
579
+ import { getL4yercak3Client } from '../client';
580
+
581
+ WebBrowser.maybeCompleteAuthSession();
582
+
583
+ const discovery = {
584
+ authorizationEndpoint: 'https://github.com/login/oauth/authorize',
585
+ tokenEndpoint: 'https://github.com/login/oauth/access_token',
586
+ revocationEndpoint: \`https://github.com/settings/connections/applications/\${process.env.EXPO_PUBLIC_GITHUB_CLIENT_ID}\`,
587
+ };
588
+
589
+ interface UseGithubAuthOptions {
590
+ clientId?: string;
591
+ clientSecret?: string;
592
+ }
593
+
594
+ export function useGithubAuth(options: UseGithubAuthOptions = {}) {
595
+ const { signIn } = useAuth();
596
+ const [isLoading, setIsLoading] = useState(false);
597
+ const [error, setError] = useState<Error | null>(null);
598
+
599
+ const clientId = options.clientId || process.env.EXPO_PUBLIC_GITHUB_CLIENT_ID || '';
600
+
601
+ const redirectUri = AuthSession.makeRedirectUri({
602
+ scheme: 'l4yercak3',
603
+ path: 'oauth/github',
604
+ });
605
+
606
+ const [request, response, promptAsync] = AuthSession.useAuthRequest(
607
+ {
608
+ clientId,
609
+ scopes: ['read:user', 'user:email'],
610
+ redirectUri,
611
+ },
612
+ discovery
613
+ );
614
+
615
+ useEffect(() => {
616
+ if (response?.type === 'success') {
617
+ handleGithubSuccess(response.params.code);
618
+ } else if (response?.type === 'error') {
619
+ setError(new Error(response.error?.message || 'GitHub authentication failed'));
620
+ }
621
+ }, [response]);
622
+
623
+ const handleGithubSuccess = async (code: string) => {
624
+ setIsLoading(true);
625
+ setError(null);
626
+
627
+ try {
628
+ // Exchange code for token via L4YERCAK3 backend
629
+ const client = getL4yercak3Client();
630
+ const authResult = await client.authenticateWithProvider('github', {
631
+ code,
632
+ redirectUri,
633
+ });
634
+
635
+ // Sign in with the result
636
+ await signIn(authResult.token, {
637
+ id: authResult.user.id,
638
+ email: authResult.user.email,
639
+ name: authResult.user.name,
640
+ image: authResult.user.image,
641
+ provider: 'github',
642
+ });
643
+ } catch (err) {
644
+ setError(err instanceof Error ? err : new Error('Authentication failed'));
645
+ } finally {
646
+ setIsLoading(false);
647
+ }
648
+ };
649
+
650
+ const signInWithGithub = async () => {
651
+ setError(null);
652
+ try {
653
+ await promptAsync();
654
+ } catch (err) {
655
+ setError(err instanceof Error ? err : new Error('Failed to initiate GitHub sign in'));
656
+ }
657
+ };
658
+
659
+ return {
660
+ signInWithGithub,
661
+ isLoading,
662
+ error,
663
+ isReady: !!request,
664
+ };
665
+ }
666
+ `;
667
+ }
668
+
669
+ getGithubAuthJS() {
670
+ return `/**
671
+ * GitHub OAuth Hook for Expo
672
+ * Uses expo-auth-session for GitHub authentication
673
+ * Auto-generated by @l4yercak3/cli
674
+ */
675
+
676
+ import { useState, useEffect } from 'react';
677
+ import * as AuthSession from 'expo-auth-session';
678
+ import * as WebBrowser from 'expo-web-browser';
679
+ import { useAuth } from './AuthContext';
680
+ import { getL4yercak3Client } from '../client';
681
+
682
+ WebBrowser.maybeCompleteAuthSession();
683
+
684
+ const discovery = {
685
+ authorizationEndpoint: 'https://github.com/login/oauth/authorize',
686
+ tokenEndpoint: 'https://github.com/login/oauth/access_token',
687
+ revocationEndpoint: \`https://github.com/settings/connections/applications/\${process.env.EXPO_PUBLIC_GITHUB_CLIENT_ID}\`,
688
+ };
689
+
690
+ export function useGithubAuth(options = {}) {
691
+ const { signIn } = useAuth();
692
+ const [isLoading, setIsLoading] = useState(false);
693
+ const [error, setError] = useState(null);
694
+
695
+ const clientId = options.clientId || process.env.EXPO_PUBLIC_GITHUB_CLIENT_ID || '';
696
+
697
+ const redirectUri = AuthSession.makeRedirectUri({
698
+ scheme: 'l4yercak3',
699
+ path: 'oauth/github',
700
+ });
701
+
702
+ const [request, response, promptAsync] = AuthSession.useAuthRequest(
703
+ {
704
+ clientId,
705
+ scopes: ['read:user', 'user:email'],
706
+ redirectUri,
707
+ },
708
+ discovery
709
+ );
710
+
711
+ useEffect(() => {
712
+ if (response?.type === 'success') {
713
+ handleGithubSuccess(response.params.code);
714
+ } else if (response?.type === 'error') {
715
+ setError(new Error(response.error?.message || 'GitHub authentication failed'));
716
+ }
717
+ }, [response]);
718
+
719
+ const handleGithubSuccess = async (code) => {
720
+ setIsLoading(true);
721
+ setError(null);
722
+
723
+ try {
724
+ // Exchange code for token via L4YERCAK3 backend
725
+ const client = getL4yercak3Client();
726
+ const authResult = await client.authenticateWithProvider('github', {
727
+ code,
728
+ redirectUri,
729
+ });
730
+
731
+ // Sign in with the result
732
+ await signIn(authResult.token, {
733
+ id: authResult.user.id,
734
+ email: authResult.user.email,
735
+ name: authResult.user.name,
736
+ image: authResult.user.image,
737
+ provider: 'github',
738
+ });
739
+ } catch (err) {
740
+ setError(err instanceof Error ? err : new Error('Authentication failed'));
741
+ } finally {
742
+ setIsLoading(false);
743
+ }
744
+ };
745
+
746
+ const signInWithGithub = async () => {
747
+ setError(null);
748
+ try {
749
+ await promptAsync();
750
+ } catch (err) {
751
+ setError(err instanceof Error ? err : new Error('Failed to initiate GitHub sign in'));
752
+ }
753
+ };
754
+
755
+ return {
756
+ signInWithGithub,
757
+ isLoading,
758
+ error,
759
+ isReady: !!request,
760
+ };
761
+ }
762
+ `;
763
+ }
764
+
765
+ async generateMicrosoftAuth(outputDir, ext, isTypeScript) {
766
+ const outputPath = path.join(outputDir, `useMicrosoftAuth.${ext}`);
767
+
768
+ const action = await checkFileOverwrite(outputPath);
769
+ if (action === 'skip') {
770
+ return null;
771
+ }
772
+
773
+ const content = isTypeScript
774
+ ? this.getMicrosoftAuthTS()
775
+ : this.getMicrosoftAuthJS();
776
+
777
+ return writeFileWithBackup(outputPath, content, action);
778
+ }
779
+
780
+ getMicrosoftAuthTS() {
781
+ return `/**
782
+ * Microsoft OAuth Hook for Expo
783
+ * Uses expo-auth-session for Microsoft/Azure AD authentication
784
+ * Auto-generated by @l4yercak3/cli
785
+ */
786
+
787
+ import { useState, useEffect } from 'react';
788
+ import * as AuthSession from 'expo-auth-session';
789
+ import * as WebBrowser from 'expo-web-browser';
790
+ import { useAuth } from './AuthContext';
791
+ import { getL4yercak3Client } from '../client';
792
+
793
+ WebBrowser.maybeCompleteAuthSession();
794
+
795
+ interface UseMicrosoftAuthOptions {
796
+ clientId?: string;
797
+ tenantId?: string;
798
+ }
799
+
800
+ export function useMicrosoftAuth(options: UseMicrosoftAuthOptions = {}) {
801
+ const { signIn } = useAuth();
802
+ const [isLoading, setIsLoading] = useState(false);
803
+ const [error, setError] = useState<Error | null>(null);
804
+
805
+ const clientId = options.clientId || process.env.EXPO_PUBLIC_AZURE_CLIENT_ID || '';
806
+ const tenantId = options.tenantId || process.env.EXPO_PUBLIC_AZURE_TENANT_ID || 'common';
807
+
808
+ const discovery = AuthSession.useAutoDiscovery(
809
+ \`https://login.microsoftonline.com/\${tenantId}/v2.0\`
810
+ );
811
+
812
+ const redirectUri = AuthSession.makeRedirectUri({
813
+ scheme: 'l4yercak3',
814
+ path: 'oauth/microsoft',
815
+ });
816
+
817
+ const [request, response, promptAsync] = AuthSession.useAuthRequest(
818
+ {
819
+ clientId,
820
+ scopes: ['openid', 'profile', 'email', 'User.Read'],
821
+ redirectUri,
822
+ },
823
+ discovery
824
+ );
825
+
826
+ useEffect(() => {
827
+ if (response?.type === 'success') {
828
+ handleMicrosoftSuccess(response.params.code);
829
+ } else if (response?.type === 'error') {
830
+ setError(new Error(response.error?.message || 'Microsoft authentication failed'));
831
+ }
832
+ }, [response]);
833
+
834
+ const handleMicrosoftSuccess = async (code: string) => {
835
+ setIsLoading(true);
836
+ setError(null);
837
+
838
+ try {
839
+ // Exchange code for token via L4YERCAK3 backend
840
+ const client = getL4yercak3Client();
841
+ const authResult = await client.authenticateWithProvider('microsoft', {
842
+ code,
843
+ redirectUri,
844
+ tenantId,
845
+ });
846
+
847
+ // Sign in with the result
848
+ await signIn(authResult.token, {
849
+ id: authResult.user.id,
850
+ email: authResult.user.email,
851
+ name: authResult.user.name,
852
+ image: authResult.user.image,
853
+ provider: 'microsoft',
854
+ });
855
+ } catch (err) {
856
+ setError(err instanceof Error ? err : new Error('Authentication failed'));
857
+ } finally {
858
+ setIsLoading(false);
859
+ }
860
+ };
861
+
862
+ const signInWithMicrosoft = async () => {
863
+ setError(null);
864
+ try {
865
+ await promptAsync();
866
+ } catch (err) {
867
+ setError(err instanceof Error ? err : new Error('Failed to initiate Microsoft sign in'));
868
+ }
869
+ };
870
+
871
+ return {
872
+ signInWithMicrosoft,
873
+ isLoading,
874
+ error,
875
+ isReady: !!request,
876
+ };
877
+ }
878
+ `;
879
+ }
880
+
881
+ getMicrosoftAuthJS() {
882
+ return `/**
883
+ * Microsoft OAuth Hook for Expo
884
+ * Uses expo-auth-session for Microsoft/Azure AD authentication
885
+ * Auto-generated by @l4yercak3/cli
886
+ */
887
+
888
+ import { useState, useEffect } from 'react';
889
+ import * as AuthSession from 'expo-auth-session';
890
+ import * as WebBrowser from 'expo-web-browser';
891
+ import { useAuth } from './AuthContext';
892
+ import { getL4yercak3Client } from '../client';
893
+
894
+ WebBrowser.maybeCompleteAuthSession();
895
+
896
+ export function useMicrosoftAuth(options = {}) {
897
+ const { signIn } = useAuth();
898
+ const [isLoading, setIsLoading] = useState(false);
899
+ const [error, setError] = useState(null);
900
+
901
+ const clientId = options.clientId || process.env.EXPO_PUBLIC_AZURE_CLIENT_ID || '';
902
+ const tenantId = options.tenantId || process.env.EXPO_PUBLIC_AZURE_TENANT_ID || 'common';
903
+
904
+ const discovery = AuthSession.useAutoDiscovery(
905
+ \`https://login.microsoftonline.com/\${tenantId}/v2.0\`
906
+ );
907
+
908
+ const redirectUri = AuthSession.makeRedirectUri({
909
+ scheme: 'l4yercak3',
910
+ path: 'oauth/microsoft',
911
+ });
912
+
913
+ const [request, response, promptAsync] = AuthSession.useAuthRequest(
914
+ {
915
+ clientId,
916
+ scopes: ['openid', 'profile', 'email', 'User.Read'],
917
+ redirectUri,
918
+ },
919
+ discovery
920
+ );
921
+
922
+ useEffect(() => {
923
+ if (response?.type === 'success') {
924
+ handleMicrosoftSuccess(response.params.code);
925
+ } else if (response?.type === 'error') {
926
+ setError(new Error(response.error?.message || 'Microsoft authentication failed'));
927
+ }
928
+ }, [response]);
929
+
930
+ const handleMicrosoftSuccess = async (code) => {
931
+ setIsLoading(true);
932
+ setError(null);
933
+
934
+ try {
935
+ // Exchange code for token via L4YERCAK3 backend
936
+ const client = getL4yercak3Client();
937
+ const authResult = await client.authenticateWithProvider('microsoft', {
938
+ code,
939
+ redirectUri,
940
+ tenantId,
941
+ });
942
+
943
+ // Sign in with the result
944
+ await signIn(authResult.token, {
945
+ id: authResult.user.id,
946
+ email: authResult.user.email,
947
+ name: authResult.user.name,
948
+ image: authResult.user.image,
949
+ provider: 'microsoft',
950
+ });
951
+ } catch (err) {
952
+ setError(err instanceof Error ? err : new Error('Authentication failed'));
953
+ } finally {
954
+ setIsLoading(false);
955
+ }
956
+ };
957
+
958
+ const signInWithMicrosoft = async () => {
959
+ setError(null);
960
+ try {
961
+ await promptAsync();
962
+ } catch (err) {
963
+ setError(err instanceof Error ? err : new Error('Failed to initiate Microsoft sign in'));
964
+ }
965
+ };
966
+
967
+ return {
968
+ signInWithMicrosoft,
969
+ isLoading,
970
+ error,
971
+ isReady: !!request,
972
+ };
973
+ }
974
+ `;
975
+ }
976
+
977
+ async generateIndex(outputDir, ext, isTypeScript, oauthProviders) {
978
+ const outputPath = path.join(outputDir, `index.${ext}`);
979
+
980
+ const action = await checkFileOverwrite(outputPath);
981
+ if (action === 'skip') {
982
+ return null;
983
+ }
984
+
985
+ const exports = [`export { AuthProvider, useAuth } from './AuthContext';`];
986
+
987
+ if (oauthProviders.includes('google')) {
988
+ exports.push(`export { useGoogleAuth } from './useGoogleAuth';`);
989
+ }
990
+ if (oauthProviders.includes('github')) {
991
+ exports.push(`export { useGithubAuth } from './useGithubAuth';`);
992
+ }
993
+ if (oauthProviders.includes('microsoft')) {
994
+ exports.push(`export { useMicrosoftAuth } from './useMicrosoftAuth';`);
995
+ }
996
+
997
+ const content = `/**
998
+ * L4YERCAK3 Expo Authentication
999
+ * Auto-generated by @l4yercak3/cli
1000
+ */
1001
+
1002
+ ${exports.join('\n')}
1003
+ `;
1004
+
1005
+ return writeFileWithBackup(outputPath, content, action);
1006
+ }
1007
+ }
1008
+
1009
+ module.exports = new ExpoAuthGenerator();