nx-factory-cli 2.1.3 → 2.1.5

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 (93) hide show
  1. package/dist/commands/add-app.d.ts +10 -0
  2. package/dist/commands/add-app.d.ts.map +1 -0
  3. package/dist/commands/add-app.js +392 -0
  4. package/dist/commands/add-app.js.map +1 -0
  5. package/dist/commands/add-auth.d.ts +8 -0
  6. package/dist/commands/add-auth.d.ts.map +1 -0
  7. package/dist/commands/add-auth.js +182 -0
  8. package/dist/commands/add-auth.js.map +1 -0
  9. package/dist/commands/add-component.d.ts +2 -0
  10. package/dist/commands/add-component.d.ts.map +1 -0
  11. package/dist/commands/add-component.js +116 -0
  12. package/dist/commands/add-component.js.map +1 -0
  13. package/dist/commands/add-lib.d.ts +9 -0
  14. package/dist/commands/add-lib.d.ts.map +1 -0
  15. package/dist/commands/add-lib.js +190 -0
  16. package/dist/commands/add-lib.js.map +1 -0
  17. package/dist/commands/add-storybook.d.ts +6 -0
  18. package/dist/commands/add-storybook.d.ts.map +1 -0
  19. package/dist/commands/add-storybook.js +181 -0
  20. package/dist/commands/add-storybook.js.map +1 -0
  21. package/dist/commands/doctor.d.ts +2 -0
  22. package/dist/commands/doctor.d.ts.map +1 -0
  23. package/dist/commands/doctor.js +235 -0
  24. package/dist/commands/doctor.js.map +1 -0
  25. package/dist/commands/init.d.ts +9 -0
  26. package/dist/commands/init.d.ts.map +1 -0
  27. package/dist/commands/init.js +527 -0
  28. package/dist/commands/init.js.map +1 -0
  29. package/dist/commands/list.d.ts +2 -0
  30. package/dist/commands/list.d.ts.map +1 -0
  31. package/dist/commands/list.js +130 -0
  32. package/dist/commands/list.js.map +1 -0
  33. package/dist/commands/publish.d.ts +8 -0
  34. package/dist/commands/publish.d.ts.map +1 -0
  35. package/dist/commands/publish.js +179 -0
  36. package/dist/commands/publish.js.map +1 -0
  37. package/dist/commands/remove-component.d.ts +5 -0
  38. package/dist/commands/remove-component.d.ts.map +1 -0
  39. package/dist/commands/remove-component.js +172 -0
  40. package/dist/commands/remove-component.js.map +1 -0
  41. package/dist/commands/update.d.ts +5 -0
  42. package/dist/commands/update.d.ts.map +1 -0
  43. package/dist/commands/update.js +126 -0
  44. package/dist/commands/update.js.map +1 -0
  45. package/dist/config.d.ts +14 -0
  46. package/dist/config.d.ts.map +1 -0
  47. package/dist/config.js +35 -0
  48. package/dist/config.js.map +1 -0
  49. package/dist/exec.d.ts +25 -0
  50. package/dist/exec.d.ts.map +1 -0
  51. package/dist/exec.js +80 -0
  52. package/dist/exec.js.map +1 -0
  53. package/dist/files.d.ts +7 -0
  54. package/dist/files.d.ts.map +1 -0
  55. package/dist/files.js +23 -0
  56. package/dist/files.js.map +1 -0
  57. package/dist/index.d.ts +3 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +93 -42127
  60. package/dist/index.js.map +1 -0
  61. package/dist/resolve-root.d.ts +22 -0
  62. package/dist/resolve-root.d.ts.map +1 -0
  63. package/dist/resolve-root.js +65 -0
  64. package/dist/resolve-root.js.map +1 -0
  65. package/dist/setups/auth/base.d.ts +11 -0
  66. package/dist/setups/auth/base.d.ts.map +1 -0
  67. package/dist/setups/auth/base.js +91 -0
  68. package/dist/setups/auth/base.js.map +1 -0
  69. package/dist/setups/auth/index.d.ts +6 -0
  70. package/dist/setups/auth/index.d.ts.map +1 -0
  71. package/dist/setups/auth/index.js +5 -0
  72. package/dist/setups/auth/index.js.map +1 -0
  73. package/dist/setups/auth/systems/better-auth.d.ts +3 -0
  74. package/dist/setups/auth/systems/better-auth.d.ts.map +1 -0
  75. package/dist/setups/auth/systems/better-auth.js +357 -0
  76. package/dist/setups/auth/systems/better-auth.js.map +1 -0
  77. package/dist/setups/auth/systems/clerk.d.ts +3 -0
  78. package/dist/setups/auth/systems/clerk.d.ts.map +1 -0
  79. package/dist/setups/auth/systems/clerk.js +259 -0
  80. package/dist/setups/auth/systems/clerk.js.map +1 -0
  81. package/dist/setups/auth/systems/workos.d.ts +3 -0
  82. package/dist/setups/auth/systems/workos.d.ts.map +1 -0
  83. package/dist/setups/auth/systems/workos.js +273 -0
  84. package/dist/setups/auth/systems/workos.js.map +1 -0
  85. package/dist/setups/auth/types.d.ts +39 -0
  86. package/dist/setups/auth/types.d.ts.map +1 -0
  87. package/dist/setups/auth/types.js +2 -0
  88. package/dist/setups/auth/types.js.map +1 -0
  89. package/dist/ui.d.ts +44 -0
  90. package/dist/ui.d.ts.map +1 -0
  91. package/dist/ui.js +149 -0
  92. package/dist/ui.js.map +1 -0
  93. package/package.json +3 -3
@@ -0,0 +1,259 @@
1
+ import path from "path";
2
+ import { writeFile, ensureDir } from "../../../files.js";
3
+ export const clerkScaffolder = {
4
+ label: "Clerk",
5
+ // Clerk v6 — all packages unified under @clerk/nextjs / @clerk/react etc.
6
+ dependencies: {
7
+ "@clerk/nextjs": "latest",
8
+ "@clerk/clerk-react": "latest",
9
+ "@clerk/remix": "latest",
10
+ "@clerk/clerk-expo": "latest",
11
+ },
12
+ devDependencies: {
13
+ "@types/react": "^19.0.0",
14
+ },
15
+ peerDependencies: {
16
+ react: "^18 || ^19",
17
+ "react-dom": "^18 || ^19",
18
+ },
19
+ async scaffold(pkgDir, _opts) {
20
+ await ensureDir(path.join(pkgDir, "src"));
21
+ // ── src/index.ts ──────────────────────────────────────────────────────────
22
+ await writeFile(path.join(pkgDir, "src/index.ts"), `/**
23
+ * @workspace/auth — Clerk latest setup.
24
+ *
25
+ * Prefer sub-path imports for tree-shaking:
26
+ * import { auth, currentUser } from "@workspace/auth/server"
27
+ * import { useAuth, UserButton } from "@workspace/auth/client"
28
+ * import { authMiddleware } from "@workspace/auth/middleware"
29
+ */
30
+ export * from "./server.js";
31
+ export * from "./client.js";
32
+ `);
33
+ // ── src/server.ts ─────────────────────────────────────────────────────────
34
+ // Clerk v6: auth() is async, currentUser() is async, clerkClient is a factory
35
+ await writeFile(path.join(pkgDir, "src/server.ts"), `/**
36
+ * Clerk v6 — server-side helpers.
37
+ * Import in Next.js Server Components, Route Handlers, or Middleware.
38
+ *
39
+ * @example Next.js App Router
40
+ * import { auth, currentUser } from "@workspace/auth/server";
41
+ *
42
+ * export default async function Page() {
43
+ * const { userId } = await auth();
44
+ * const user = await currentUser();
45
+ * }
46
+ *
47
+ * @example Route Handler / Remix loader
48
+ * import { getAuth } from "@workspace/auth/server";
49
+ * const { userId } = getAuth(req); // Express / Remix: sync helper
50
+ */
51
+
52
+ // auth() — returns Promise<{ userId, sessionId, sessionClaims, ... }>
53
+ export { auth } from "@clerk/nextjs/server";
54
+
55
+ // currentUser() — returns full User object or null
56
+ export { currentUser } from "@clerk/nextjs/server";
57
+
58
+ // clerkClient() — factory function (Clerk v6 changed from singleton to factory)
59
+ export { clerkClient } from "@clerk/nextjs/server";
60
+
61
+ // getAuth() — for Express/Remix/Node environments (sync, takes Request)
62
+ export { getAuth } from "@clerk/nextjs/server";
63
+
64
+ // Type helpers
65
+ export type {
66
+ User,
67
+ Organization,
68
+ Session,
69
+ } from "@clerk/nextjs/server";
70
+ `);
71
+ // ── src/client.ts ─────────────────────────────────────────────────────────
72
+ await writeFile(path.join(pkgDir, "src/client.ts"), `/**
73
+ * Clerk v6 — client-side hooks and pre-built components.
74
+ * Use in React Client Components, Vite SPAs, or Expo apps.
75
+ *
76
+ * @example
77
+ * import { useAuth, useUser, UserButton } from "@workspace/auth/client";
78
+ *
79
+ * function Header() {
80
+ * const { isSignedIn } = useAuth();
81
+ * return isSignedIn ? <UserButton /> : <SignInButton />;
82
+ * }
83
+ */
84
+ "use client";
85
+
86
+ // Hooks
87
+ export {
88
+ useAuth,
89
+ useUser,
90
+ useClerk,
91
+ useSession,
92
+ useOrganization,
93
+ useOrganizationList,
94
+ useSignIn,
95
+ useSignUp,
96
+ } from "@clerk/nextjs";
97
+
98
+ // Pre-built UI components
99
+ export {
100
+ ClerkProvider,
101
+ SignIn,
102
+ SignUp,
103
+ SignInButton,
104
+ SignUpButton,
105
+ SignOutButton,
106
+ UserButton,
107
+ UserProfile,
108
+ OrganizationProfile,
109
+ OrganizationSwitcher,
110
+ CreateOrganization,
111
+ } from "@clerk/nextjs";
112
+
113
+ // Render helpers
114
+ export { SignedIn, SignedOut, Protect } from "@clerk/nextjs";
115
+ `);
116
+ // ── src/middleware.ts ─────────────────────────────────────────────────────
117
+ // Clerk v6: clerkMiddleware replaces authMiddleware (deprecated in v5, removed in v6)
118
+ await writeFile(path.join(pkgDir, "src/middleware.ts"), `/**
119
+ * Clerk v6 middleware for Next.js.
120
+ *
121
+ * Clerk v6 uses clerkMiddleware() — authMiddleware() was removed.
122
+ *
123
+ * Quick start — copy into apps/<your-app>/middleware.ts:
124
+ *
125
+ * export { authMiddleware as default, middlewareConfig as config }
126
+ * from "@workspace/auth/middleware";
127
+ *
128
+ * Custom public routes:
129
+ *
130
+ * import { buildMiddleware } from "@workspace/auth/middleware";
131
+ * export default buildMiddleware(["/", "/about(.*)", "/marketing(.*)"]);
132
+ * export { middlewareConfig as config } from "@workspace/auth/middleware";
133
+ */
134
+ import {
135
+ clerkMiddleware,
136
+ createRouteMatcher,
137
+ type ClerkMiddlewareOptions,
138
+ } from "@clerk/nextjs/server";
139
+
140
+ export const middlewareConfig = {
141
+ matcher: [
142
+ // Skip Next.js internals and all static files
143
+ "/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)",
144
+ // Always run for API routes
145
+ "/(api|trpc)(.*)",
146
+ ],
147
+ };
148
+
149
+ const defaultPublicPaths = [
150
+ "/",
151
+ "/sign-in(.*)",
152
+ "/sign-up(.*)",
153
+ "/api/webhooks(.*)",
154
+ ];
155
+
156
+ /** Default middleware — protects all routes except the ones above */
157
+ export const authMiddleware = clerkMiddleware(
158
+ async (auth, request) => {
159
+ const isPublic = createRouteMatcher(defaultPublicPaths);
160
+ if (!isPublic(request)) await auth.protect();
161
+ },
162
+ );
163
+
164
+ /**
165
+ * Build a middleware with custom public paths.
166
+ *
167
+ * @param publicPaths - Array of path patterns (supports wildcards with (.*))
168
+ * @param options - Extra Clerk middleware options (e.g. debug: true)
169
+ *
170
+ * @example
171
+ * export default buildMiddleware(["/", "/marketing(.*)", "/blog(.*)"]);
172
+ */
173
+ export function buildMiddleware(
174
+ publicPaths: string[],
175
+ options?: ClerkMiddlewareOptions,
176
+ ) {
177
+ const isPublic = createRouteMatcher(publicPaths);
178
+ return clerkMiddleware(async (auth, request) => {
179
+ if (!isPublic(request)) await auth.protect();
180
+ }, options);
181
+ }
182
+ `);
183
+ // ── .env.example ─────────────────────────────────────────────────────────
184
+ await writeFile(path.join(pkgDir, ".env.example"), `# ─── Clerk v6 ────────────────────────────────────────────────────────────────
185
+ # Get these from: https://dashboard.clerk.com → your app → API Keys
186
+ NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_REPLACE_ME
187
+ CLERK_SECRET_KEY=sk_test_REPLACE_ME
188
+
189
+ # Redirect URLs (optional — Clerk uses these if set)
190
+ NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
191
+ NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
192
+ NEXT_PUBLIC_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL=/dashboard
193
+ NEXT_PUBLIC_CLERK_SIGN_UP_FALLBACK_REDIRECT_URL=/dashboard
194
+ `);
195
+ // ── README.md ─────────────────────────────────────────────────────────────
196
+ await writeFile(path.join(pkgDir, "README.md"), `# @workspace/auth — Clerk v6
197
+
198
+ Shared authentication package powered by [Clerk](https://clerk.com) v6.
199
+
200
+ > **Clerk v6 notes:** \`authMiddleware\` was removed — use \`clerkMiddleware\` (exported here as \`authMiddleware\` for compatibility). \`clerkClient\` is now a factory function, not a singleton.
201
+
202
+ ## Setup
203
+
204
+ ### 1. Copy env vars to your app
205
+ \`\`\`bash
206
+ cp packages/auth/.env.example apps/<your-app>/.env.local
207
+ # Fill in keys from https://dashboard.clerk.com
208
+ \`\`\`
209
+
210
+ ### 2. Add the dependency
211
+ \`\`\`json
212
+ { "dependencies": { "@workspace/auth": "workspace:*" } }
213
+ \`\`\`
214
+
215
+ ### 3. Wrap your root layout
216
+ \`\`\`tsx
217
+ // apps/<your-app>/src/app/layout.tsx
218
+ import { ClerkProvider } from "@workspace/auth/client";
219
+
220
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
221
+ return (
222
+ <ClerkProvider>
223
+ <html><body>{children}</body></html>
224
+ </ClerkProvider>
225
+ );
226
+ }
227
+ \`\`\`
228
+
229
+ ### 4. Add the middleware
230
+ \`\`\`ts
231
+ // apps/<your-app>/middleware.ts
232
+ export { authMiddleware as default, middlewareConfig as config }
233
+ from "@workspace/auth/middleware";
234
+ \`\`\`
235
+
236
+ ### 5. Use in your pages
237
+ \`\`\`tsx
238
+ // Server component
239
+ import { auth, currentUser } from "@workspace/auth/server";
240
+ const { userId } = await auth();
241
+ const user = await currentUser();
242
+
243
+ // Client component
244
+ "use client";
245
+ import { useAuth, UserButton, SignedIn, SignedOut } from "@workspace/auth/client";
246
+ const { isSignedIn } = useAuth();
247
+ \`\`\`
248
+
249
+ ## API
250
+
251
+ | Sub-path | Key exports |
252
+ |---|---|
253
+ | \`@workspace/auth/server\` | \`auth()\`, \`currentUser()\`, \`clerkClient()\`, \`getAuth()\` |
254
+ | \`@workspace/auth/client\` | \`useAuth\`, \`useUser\`, \`ClerkProvider\`, \`UserButton\`, \`SignedIn\`, \`SignedOut\` |
255
+ | \`@workspace/auth/middleware\` | \`authMiddleware\`, \`buildMiddleware()\`, \`middlewareConfig\` |
256
+ `);
257
+ },
258
+ };
259
+ //# sourceMappingURL=clerk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clerk.js","sourceRoot":"","sources":["../../../../src/setups/auth/systems/clerk.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGzD,MAAM,CAAC,MAAM,eAAe,GAA0B;IACpD,KAAK,EAAE,OAAO;IAEd,0EAA0E;IAC1E,YAAY,EAAE;QACZ,eAAe,EAAO,QAAQ;QAC9B,oBAAoB,EAAE,QAAQ;QAC9B,cAAc,EAAQ,QAAQ;QAC9B,mBAAmB,EAAG,QAAQ;KAC/B;IAED,eAAe,EAAE;QACf,cAAc,EAAE,SAAS;KAC1B;IAED,gBAAgB,EAAE;QAChB,KAAK,EAAQ,YAAY;QACzB,WAAW,EAAE,YAAY;KAC1B;IAED,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,KAAyB;QACtD,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAE1C,6EAA6E;QAC7E,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,EACjC;;;;;;;;;;CAUL,CACI,CAAC;QAEF,6EAA6E;QAC7E,8EAA8E;QAC9E,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,EAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCL,CACI,CAAC;QAEF,6EAA6E;QAC7E,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,EAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CL,CACI,CAAC;QAEF,6EAA6E;QAC7E,sFAAsF;QACtF,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgEL,CACI,CAAC;QAEF,4EAA4E;QAC5E,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,EACjC;;;;;;;;;;CAUL,CACI,CAAC;QAEF,6EAA6E;QAC7E,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,EAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4DL,CACI,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { AuthPackageScaffolder } from "../types.js";
2
+ export declare const workosScaffolder: AuthPackageScaffolder;
3
+ //# sourceMappingURL=workos.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workos.d.ts","sourceRoot":"","sources":["../../../../src/setups/auth/systems/workos.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAsB,MAAM,aAAa,CAAC;AAE7E,eAAO,MAAM,gBAAgB,EAAE,qBAyS9B,CAAC"}
@@ -0,0 +1,273 @@
1
+ import path from "path";
2
+ import { writeFile, ensureDir } from "../../../files.js";
3
+ export const workosScaffolder = {
4
+ label: "WorkOS AuthKit",
5
+ dependencies: {
6
+ "@workos-inc/authkit-nextjs": "latest",
7
+ "@workos-inc/node": "latest",
8
+ },
9
+ devDependencies: {
10
+ "@types/react": "^19.0.0",
11
+ },
12
+ peerDependencies: {
13
+ react: "^18 || ^19",
14
+ "react-dom": "^18 || ^19",
15
+ },
16
+ async scaffold(pkgDir, _opts) {
17
+ await ensureDir(path.join(pkgDir, "src"));
18
+ // ── src/index.ts ──────────────────────────────────────────────────────────
19
+ await writeFile(path.join(pkgDir, "src/index.ts"), `/**
20
+ * @workspace/auth — WorkOS AuthKit latest setup.
21
+ *
22
+ * Prefer sub-path imports:
23
+ * import { getUser, withAuth } from "@workspace/auth/server"
24
+ * import { useAuth } from "@workspace/auth/client"
25
+ * import { authMiddleware } from "@workspace/auth/middleware"
26
+ */
27
+ export * from "./server.js";
28
+ export * from "./client.js";
29
+ `);
30
+ // ── src/server.ts ─────────────────────────────────────────────────────────
31
+ // AuthKit v1+: getUser() replaces getSession(), withAuth() HOC
32
+ await writeFile(path.join(pkgDir, "src/server.ts"), `/**
33
+ * WorkOS AuthKit v1+ — server-side helpers.
34
+ *
35
+ * AuthKit v1 changes from v0:
36
+ * - getSession() → getUser() (returns { user, sessionId, accessToken })
37
+ * - withAuth() — HOC now passes { user } prop (no session wrapper)
38
+ * - handleAuth() — still the catch-all callback handler
39
+ *
40
+ * @example Server Component (manual check)
41
+ * import { getUser } from "@workspace/auth/server";
42
+ * const { user } = await getUser();
43
+ * if (!user) redirect("/sign-in");
44
+ *
45
+ * @example Server Component (HOC — auto-redirects)
46
+ * import { withAuth } from "@workspace/auth/server";
47
+ * export default withAuth(async function Page({ user }) {
48
+ * return <h1>Hello {user.firstName}</h1>;
49
+ * });
50
+ *
51
+ * @example Sign-in redirect
52
+ * import { getSignInUrl } from "@workspace/auth/server";
53
+ * redirect(await getSignInUrl());
54
+ */
55
+
56
+ export {
57
+ getUser, // Replaces getSession() in AuthKit v1
58
+ withAuth, // HOC — passes { user } to your component
59
+ getSignInUrl, // Returns the WorkOS hosted sign-in URL
60
+ getSignUpUrl, // Returns the WorkOS hosted sign-up URL
61
+ signOut, // Server-side sign out (clears session cookie)
62
+ refreshSession, // Extend the session lifetime
63
+ handleAuth, // Catch-all callback route handler (GET)
64
+ verifyAccessToken, // Verify a JWT access token
65
+ encryptSession, // For custom session storage scenarios
66
+ terminateSession, // Force-terminate a specific session
67
+ } from "@workos-inc/authkit-nextjs";
68
+
69
+ export type {
70
+ User,
71
+ AuthKitSession,
72
+ } from "@workos-inc/authkit-nextjs";
73
+
74
+ /**
75
+ * Low-level WorkOS Node SDK.
76
+ * Use for organization management, directory sync, audit logs, etc.
77
+ *
78
+ * import { workos } from "@workspace/auth/server";
79
+ * const orgs = await workos.organizations.listOrganizations();
80
+ */
81
+ import WorkOS from "@workos-inc/node";
82
+
83
+ if (!process.env.WORKOS_API_KEY) {
84
+ throw new Error("Missing WORKOS_API_KEY — set it in your app's .env.local");
85
+ }
86
+
87
+ export const workos = new WorkOS(process.env.WORKOS_API_KEY);
88
+ export const workosClientId = process.env.WORKOS_CLIENT_ID!;
89
+ `);
90
+ // ── src/client.ts ─────────────────────────────────────────────────────────
91
+ // AuthKit v1: useAuth() hook from the /components sub-path
92
+ await writeFile(path.join(pkgDir, "src/client.ts"), `/**
93
+ * WorkOS AuthKit v1+ — client-side hooks.
94
+ *
95
+ * The AuthKitProvider is required at the root of apps that use useAuth().
96
+ *
97
+ * @example Root layout
98
+ * import { AuthKitProvider } from "@workspace/auth/client";
99
+ * export default function Layout({ children }) {
100
+ * return <AuthKitProvider>{children}</AuthKitProvider>;
101
+ * }
102
+ *
103
+ * @example Any client component
104
+ * "use client";
105
+ * import { useAuth } from "@workspace/auth/client";
106
+ * const { user, loading, getAccessToken } = useAuth();
107
+ */
108
+ "use client";
109
+
110
+ export {
111
+ useAuth, // { user, loading, getAccessToken, getRawAccessToken }
112
+ AuthKitProvider, // Required root context provider
113
+ } from "@workos-inc/authkit-nextjs/components";
114
+ `);
115
+ // ── src/middleware.ts ─────────────────────────────────────────────────────
116
+ // AuthKit v1: authkitMiddleware with middlewareAuth option
117
+ await writeFile(path.join(pkgDir, "src/middleware.ts"), `/**
118
+ * WorkOS AuthKit v1+ — Next.js middleware.
119
+ *
120
+ * Quick start — copy into apps/<your-app>/middleware.ts:
121
+ *
122
+ * export { authMiddleware as default, middlewareConfig as config }
123
+ * from "@workspace/auth/middleware";
124
+ *
125
+ * Custom public paths:
126
+ *
127
+ * import { buildMiddleware } from "@workspace/auth/middleware";
128
+ * export default buildMiddleware({ unauthenticatedPaths: ["/", "/about"] });
129
+ * export { middlewareConfig as config } from "@workspace/auth/middleware";
130
+ */
131
+ import { authkitMiddleware } from "@workos-inc/authkit-nextjs";
132
+ import type { AuthkitMiddlewareOptions } from "@workos-inc/authkit-nextjs";
133
+
134
+ export const middlewareConfig = {
135
+ matcher: [
136
+ "/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)",
137
+ "/(api|trpc)(.*)",
138
+ ],
139
+ };
140
+
141
+ const defaultUnauthenticatedPaths = [
142
+ "/",
143
+ "/sign-in",
144
+ "/sign-up",
145
+ "/api/webhooks(.*)",
146
+ ];
147
+
148
+ /** Default middleware — requires auth on all paths except the ones above */
149
+ export const authMiddleware = authkitMiddleware({
150
+ middlewareAuth: {
151
+ enabled: true,
152
+ unauthenticatedPaths: defaultUnauthenticatedPaths,
153
+ },
154
+ });
155
+
156
+ /**
157
+ * Build a middleware with configurable unauthenticated paths.
158
+ *
159
+ * @param unauthenticatedPaths - Paths that do NOT require authentication
160
+ * @param options - Additional AuthKit middleware options
161
+ */
162
+ export function buildMiddleware({
163
+ unauthenticatedPaths = defaultUnauthenticatedPaths,
164
+ ...options
165
+ }: {
166
+ unauthenticatedPaths?: string[];
167
+ } & Omit<AuthkitMiddlewareOptions, "middlewareAuth"> = {}) {
168
+ return authkitMiddleware({
169
+ ...options,
170
+ middlewareAuth: {
171
+ enabled: true,
172
+ unauthenticatedPaths,
173
+ },
174
+ });
175
+ }
176
+ `);
177
+ // ── .env.example ─────────────────────────────────────────────────────────
178
+ await writeFile(path.join(pkgDir, ".env.example"), `# ─── WorkOS AuthKit v1+ ──────────────────────────────────────────────────────
179
+ # Get these from: https://dashboard.workos.com → your app → API Keys
180
+ WORKOS_API_KEY=sk_REPLACE_ME
181
+ WORKOS_CLIENT_ID=client_REPLACE_ME
182
+
183
+ # Must match the redirect URI configured in your WorkOS dashboard
184
+ WORKOS_REDIRECT_URI=http://localhost:3000/callback
185
+
186
+ # Cookie encryption secret — generate with: openssl rand -base64 32
187
+ # Must be at least 32 characters
188
+ WORKOS_COOKIE_PASSWORD=REPLACE_WITH_RANDOM_32_CHAR_STRING
189
+
190
+ # The public URL of your app
191
+ NEXT_PUBLIC_APP_URL=http://localhost:3000
192
+ `);
193
+ // ── README.md ─────────────────────────────────────────────────────────────
194
+ await writeFile(path.join(pkgDir, "README.md"), `# @workspace/auth — WorkOS AuthKit v1+
195
+
196
+ Shared authentication powered by [WorkOS AuthKit](https://workos.com/docs/user-management) — enterprise SSO, SCIM, MFA, magic auth, and a hosted sign-in UI.
197
+
198
+ > **AuthKit v1 notes:** \`getSession()\` was renamed to \`getUser()\`. The HOC \`withAuth()\` now passes \`{ user }\` directly (no session wrapper). \`AuthKitProvider\` is now required for \`useAuth()\`.
199
+
200
+ ## Setup
201
+
202
+ ### 1. Copy env vars to your app
203
+ \`\`\`bash
204
+ cp packages/auth/.env.example apps/<your-app>/.env.local
205
+ \`\`\`
206
+
207
+ Fill in from your [WorkOS Dashboard](https://dashboard.workos.com):
208
+ - \`WORKOS_API_KEY\`
209
+ - \`WORKOS_CLIENT_ID\`
210
+ - \`WORKOS_COOKIE_PASSWORD\` (run: \`openssl rand -base64 32\`)
211
+ - Add \`WORKOS_REDIRECT_URI\` in the WorkOS dashboard → Redirects
212
+
213
+ ### 2. Add the dependency
214
+ \`\`\`json
215
+ { "dependencies": { "@workspace/auth": "workspace:*" } }
216
+ \`\`\`
217
+
218
+ ### 3. Add the callback route
219
+ \`\`\`ts
220
+ // apps/<your-app>/src/app/callback/route.ts
221
+ export { handleAuth as GET } from "@workspace/auth/server";
222
+ \`\`\`
223
+
224
+ ### 4. Add the middleware
225
+ \`\`\`ts
226
+ // apps/<your-app>/middleware.ts
227
+ export { authMiddleware as default, middlewareConfig as config }
228
+ from "@workspace/auth/middleware";
229
+ \`\`\`
230
+
231
+ ### 5. Wrap your layout with AuthKitProvider
232
+ \`\`\`tsx
233
+ // apps/<your-app>/src/app/layout.tsx
234
+ import { AuthKitProvider } from "@workspace/auth/client";
235
+ export default function Layout({ children }) {
236
+ return <AuthKitProvider>{children}</AuthKitProvider>;
237
+ }
238
+ \`\`\`
239
+
240
+ ### 6. Use in your pages
241
+ \`\`\`tsx
242
+ // Server component — HOC (auto-redirects if not signed in)
243
+ import { withAuth } from "@workspace/auth/server";
244
+ export default withAuth(async function Page({ user }) {
245
+ return <h1>Hello, {user.firstName}</h1>;
246
+ });
247
+
248
+ // Server component — manual
249
+ import { getUser } from "@workspace/auth/server";
250
+ const { user } = await getUser();
251
+
252
+ // Client component
253
+ "use client";
254
+ import { useAuth } from "@workspace/auth/client";
255
+ const { user, loading } = useAuth();
256
+
257
+ // Sign-in redirect page
258
+ import { getSignInUrl } from "@workspace/auth/server";
259
+ import { redirect } from "next/navigation";
260
+ export default async function SignIn() { redirect(await getSignInUrl()); }
261
+ \`\`\`
262
+
263
+ ## API
264
+
265
+ | Sub-path | Key exports |
266
+ |---|---|
267
+ | \`@workspace/auth/server\` | \`getUser()\`, \`withAuth()\`, \`getSignInUrl()\`, \`handleAuth\`, \`workos\`, \`signOut()\` |
268
+ | \`@workspace/auth/client\` | \`useAuth\`, \`AuthKitProvider\` |
269
+ | \`@workspace/auth/middleware\` | \`authMiddleware\`, \`buildMiddleware()\`, \`middlewareConfig\` |
270
+ `);
271
+ },
272
+ };
273
+ //# sourceMappingURL=workos.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workos.js","sourceRoot":"","sources":["../../../../src/setups/auth/systems/workos.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGzD,MAAM,CAAC,MAAM,gBAAgB,GAA0B;IACrD,KAAK,EAAE,gBAAgB;IAEvB,YAAY,EAAE;QACZ,4BAA4B,EAAE,QAAQ;QACtC,kBAAkB,EAAY,QAAQ;KACvC;IAED,eAAe,EAAE;QACf,cAAc,EAAE,SAAS;KAC1B;IAED,gBAAgB,EAAE;QAChB,KAAK,EAAQ,YAAY;QACzB,WAAW,EAAE,YAAY;KAC1B;IAED,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,KAAyB;QACtD,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAE1C,6EAA6E;QAC7E,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,EACjC;;;;;;;;;;CAUL,CACI,CAAC;QAEF,6EAA6E;QAC7E,+DAA+D;QAC/D,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,EAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyDL,CACI,CAAC;QAEF,6EAA6E;QAC7E,2DAA2D;QAC3D,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,EAClC;;;;;;;;;;;;;;;;;;;;;;CAsBL,CACI,CAAC;QAEF,6EAA6E;QAC7E,2DAA2D;QAC3D,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2DL,CACI,CAAC;QAEF,4EAA4E;QAC5E,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,EACjC;;;;;;;;;;;;;;CAcL,CACI,CAAC;QAEF,6EAA6E;QAC7E,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,EAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4EL,CACI,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,39 @@
1
+ export type AuthProvider = "clerk" | "better-auth" | "workos";
2
+ export interface AuthPackageOptions {
3
+ /** The chosen provider */
4
+ provider: AuthProvider;
5
+ /** Absolute path to the monorepo root (where packages/ lives) */
6
+ workspaceRoot: string;
7
+ /** The workspace name (from nx-factory.config.json) */
8
+ workspaceName: string;
9
+ /** The package manager in use */
10
+ pm: string;
11
+ /** If true, print what would happen but write nothing */
12
+ dryRun?: boolean;
13
+ }
14
+ /**
15
+ * Everything a provider scaffolder must implement.
16
+ *
17
+ * The CLI calls scaffold() once — it creates the entire packages/auth
18
+ * directory for that provider, including:
19
+ * - package.json
20
+ * - tsconfig.json
21
+ * - tsup.config.ts
22
+ * - src/index.ts (the public barrel)
23
+ * - src/<provider>-specific files
24
+ * - .env.example
25
+ * - README.md
26
+ */
27
+ export interface AuthPackageScaffolder {
28
+ /** Pretty label used in step output */
29
+ label: string;
30
+ /** npm deps that go into the auth package's package.json dependencies */
31
+ dependencies: Record<string, string>;
32
+ /** npm devDeps for the auth package */
33
+ devDependencies: Record<string, string>;
34
+ /** peerDeps (e.g. react) */
35
+ peerDependencies: Record<string, string>;
36
+ /** Write every file into pkgDir */
37
+ scaffold(pkgDir: string, opts: AuthPackageOptions): Promise<void>;
38
+ }
39
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/setups/auth/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,aAAa,GAAG,QAAQ,CAAC;AAE9D,MAAM,WAAW,kBAAkB;IACjC,0BAA0B;IAC1B,QAAQ,EAAK,YAAY,CAAC;IAC1B,iEAAiE;IACjE,aAAa,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,aAAa,EAAE,MAAM,CAAC;IACtB,iCAAiC;IACjC,EAAE,EAAW,MAAM,CAAC;IACpB,yDAAyD;IACzD,MAAM,CAAC,EAAM,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,qBAAqB;IACpC,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,uCAAuC;IACvC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,4BAA4B;IAC5B,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,mCAAmC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/setups/auth/types.ts"],"names":[],"mappings":""}
package/dist/ui.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ export declare const c: {
2
+ purple: import("chalk").ChalkInstance;
3
+ purpleDim: import("chalk").ChalkInstance;
4
+ purpleBold: import("chalk").ChalkInstance;
5
+ green: import("chalk").ChalkInstance;
6
+ greenBold: import("chalk").ChalkInstance;
7
+ yellow: import("chalk").ChalkInstance;
8
+ red: import("chalk").ChalkInstance;
9
+ cyan: import("chalk").ChalkInstance;
10
+ white: import("chalk").ChalkInstance;
11
+ whiteBold: import("chalk").ChalkInstance;
12
+ dim: import("chalk").ChalkInstance;
13
+ dimItalic: import("chalk").ChalkInstance;
14
+ muted: import("chalk").ChalkInstance;
15
+ };
16
+ export declare function printBanner(): void;
17
+ export declare function printSection(label: string): void;
18
+ export type StepRunner = (label: string, fn: () => Promise<void>) => Promise<void>;
19
+ export declare function createStepRunner(total: number, dryRun?: boolean): StepRunner;
20
+ export declare function q(label: string, hint?: string): string;
21
+ export declare function detected(value: string): string;
22
+ export interface SuccessOptions {
23
+ title: string;
24
+ commands: Array<{
25
+ cmd: string;
26
+ comment?: string;
27
+ }>;
28
+ tips?: Array<{
29
+ label: string;
30
+ cmd: string;
31
+ }>;
32
+ }
33
+ export declare function printSuccess(opts: SuccessOptions): void;
34
+ export interface ErrorOptions {
35
+ title: string;
36
+ detail?: string;
37
+ recovery: Array<{
38
+ label: string;
39
+ cmd: string;
40
+ }>;
41
+ }
42
+ export declare function printError(opts: ErrorOptions): void;
43
+ export declare function printWarn(message: string, hint?: string): void;
44
+ //# sourceMappingURL=ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,CAAC;;;;;;;;;;;;;;CAcb,CAAC;AAGF,wBAAgB,WAAW,IAAI,IAAI,CAkBlC;AASD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAKhD;AAOD,MAAM,MAAM,UAAU,GAAG,CACvB,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KACpB,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,UAAU,CAuB1E;AAKD,wBAAgB,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAGtD;AAID,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C;AAGD,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAK,MAAM,CAAC;IACjB,QAAQ,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,IAAI,CAAC,EAAK,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjD;AAYD,wBAAgB,YAAY,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CA8BvD;AAGD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAK,MAAM,CAAC;IACjB,MAAM,CAAC,EAAG,MAAM,CAAC;IACjB,QAAQ,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAsBnD;AAID,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAG9D"}