workos 0.0.24 → 0.1.0

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 (305) hide show
  1. package/.claude-plugin/plugin.json +13 -0
  2. package/LICENSE +47 -0
  3. package/README.md +154 -1
  4. package/dist/bin.d.ts +2 -0
  5. package/dist/bin.js +163 -0
  6. package/dist/bin.js.map +1 -0
  7. package/dist/cli.config.d.ts +52 -0
  8. package/dist/cli.config.js +70 -0
  9. package/dist/cli.config.js.map +1 -0
  10. package/dist/package.json +87 -0
  11. package/dist/src/commands/install-skill.d.ts +20 -0
  12. package/dist/src/commands/install-skill.js +130 -0
  13. package/dist/src/commands/install-skill.js.map +1 -0
  14. package/dist/src/commands/install.d.ts +22 -0
  15. package/dist/src/commands/install.js +57 -0
  16. package/dist/src/commands/install.js.map +1 -0
  17. package/dist/src/commands/login.d.ts +1 -0
  18. package/dist/src/commands/login.js +141 -0
  19. package/dist/src/commands/login.js.map +1 -0
  20. package/dist/src/commands/logout.d.ts +1 -0
  21. package/dist/src/commands/logout.js +17 -0
  22. package/dist/src/commands/logout.js.map +1 -0
  23. package/dist/src/dashboard/components/AnimatedLogo.d.ts +8 -0
  24. package/dist/src/dashboard/components/AnimatedLogo.js +16 -0
  25. package/dist/src/dashboard/components/AnimatedLogo.js.map +1 -0
  26. package/dist/src/dashboard/components/CompletionView.d.ts +13 -0
  27. package/dist/src/dashboard/components/CompletionView.js +21 -0
  28. package/dist/src/dashboard/components/CompletionView.js.map +1 -0
  29. package/dist/src/dashboard/components/ConfirmPrompt.d.ts +9 -0
  30. package/dist/src/dashboard/components/ConfirmPrompt.js +25 -0
  31. package/dist/src/dashboard/components/ConfirmPrompt.js.map +1 -0
  32. package/dist/src/dashboard/components/CredentialsForm.d.ts +10 -0
  33. package/dist/src/dashboard/components/CredentialsForm.js +47 -0
  34. package/dist/src/dashboard/components/CredentialsForm.js.map +1 -0
  35. package/dist/src/dashboard/components/Dashboard.d.ts +3 -0
  36. package/dist/src/dashboard/components/Dashboard.js +100 -0
  37. package/dist/src/dashboard/components/Dashboard.js.map +1 -0
  38. package/dist/src/dashboard/components/DashboardLayout.d.ts +24 -0
  39. package/dist/src/dashboard/components/DashboardLayout.js +25 -0
  40. package/dist/src/dashboard/components/DashboardLayout.js.map +1 -0
  41. package/dist/src/dashboard/components/DiffPanel.d.ts +9 -0
  42. package/dist/src/dashboard/components/DiffPanel.js +136 -0
  43. package/dist/src/dashboard/components/DiffPanel.js.map +1 -0
  44. package/dist/src/dashboard/components/InlinePrompt.d.ts +8 -0
  45. package/dist/src/dashboard/components/InlinePrompt.js +19 -0
  46. package/dist/src/dashboard/components/InlinePrompt.js.map +1 -0
  47. package/dist/src/dashboard/components/OutputPanel.d.ts +10 -0
  48. package/dist/src/dashboard/components/OutputPanel.js +100 -0
  49. package/dist/src/dashboard/components/OutputPanel.js.map +1 -0
  50. package/dist/src/dashboard/components/Panel.d.ts +12 -0
  51. package/dist/src/dashboard/components/Panel.js +6 -0
  52. package/dist/src/dashboard/components/Panel.js.map +1 -0
  53. package/dist/src/dashboard/components/TextInput.d.ts +13 -0
  54. package/dist/src/dashboard/components/TextInput.js +57 -0
  55. package/dist/src/dashboard/components/TextInput.js.map +1 -0
  56. package/dist/src/dashboard/components/WelcomeArt.d.ts +2 -0
  57. package/dist/src/dashboard/components/WelcomeArt.js +9 -0
  58. package/dist/src/dashboard/components/WelcomeArt.js.map +1 -0
  59. package/dist/src/dashboard/hooks/useAnimation.d.ts +7 -0
  60. package/dist/src/dashboard/hooks/useAnimation.js +24 -0
  61. package/dist/src/dashboard/hooks/useAnimation.js.map +1 -0
  62. package/dist/src/dashboard/hooks/useKeyboard.d.ts +8 -0
  63. package/dist/src/dashboard/hooks/useKeyboard.js +18 -0
  64. package/dist/src/dashboard/hooks/useKeyboard.js.map +1 -0
  65. package/dist/src/dashboard/hooks/useTerminalSize.d.ts +8 -0
  66. package/dist/src/dashboard/hooks/useTerminalSize.js +23 -0
  67. package/dist/src/dashboard/hooks/useTerminalSize.js.map +1 -0
  68. package/dist/src/dashboard/index.d.ts +6 -0
  69. package/dist/src/dashboard/index.js +36 -0
  70. package/dist/src/dashboard/index.js.map +1 -0
  71. package/dist/src/dashboard/lib/diff-utils.d.ts +21 -0
  72. package/dist/src/dashboard/lib/diff-utils.js +271 -0
  73. package/dist/src/dashboard/lib/diff-utils.js.map +1 -0
  74. package/dist/src/dashboard/lib/logo-frames.d.ts +20 -0
  75. package/dist/src/dashboard/lib/logo-frames.js +109 -0
  76. package/dist/src/dashboard/lib/logo-frames.js.map +1 -0
  77. package/dist/src/dashboard/lib/welcome-art.d.ts +1 -0
  78. package/dist/src/dashboard/lib/welcome-art.js +5 -0
  79. package/dist/src/dashboard/lib/welcome-art.js.map +1 -0
  80. package/dist/src/dashboard/types.d.ts +5 -0
  81. package/dist/src/dashboard/types.js +2 -0
  82. package/dist/src/dashboard/types.js.map +1 -0
  83. package/dist/src/lib/__tests__/test-utils.d.ts +40 -0
  84. package/dist/src/lib/__tests__/test-utils.js +108 -0
  85. package/dist/src/lib/__tests__/test-utils.js.map +1 -0
  86. package/dist/src/lib/adapters/cli-adapter.d.ts +56 -0
  87. package/dist/src/lib/adapters/cli-adapter.js +318 -0
  88. package/dist/src/lib/adapters/cli-adapter.js.map +1 -0
  89. package/dist/src/lib/adapters/dashboard-adapter.d.ts +30 -0
  90. package/dist/src/lib/adapters/dashboard-adapter.js +97 -0
  91. package/dist/src/lib/adapters/dashboard-adapter.js.map +1 -0
  92. package/dist/src/lib/adapters/index.d.ts +3 -0
  93. package/dist/src/lib/adapters/index.js +3 -0
  94. package/dist/src/lib/adapters/index.js.map +1 -0
  95. package/dist/src/lib/adapters/types.d.ts +41 -0
  96. package/dist/src/lib/adapters/types.js +2 -0
  97. package/dist/src/lib/adapters/types.js.map +1 -0
  98. package/dist/src/lib/agent-interface.d.ts +75 -0
  99. package/dist/src/lib/agent-interface.js +563 -0
  100. package/dist/src/lib/agent-interface.js.map +1 -0
  101. package/dist/src/lib/agent-runner.d.ts +9 -0
  102. package/dist/src/lib/agent-runner.js +213 -0
  103. package/dist/src/lib/agent-runner.js.map +1 -0
  104. package/dist/src/lib/api.d.ts +25 -0
  105. package/dist/src/lib/api.js +120 -0
  106. package/dist/src/lib/api.js.map +1 -0
  107. package/dist/src/lib/config.d.ts +60 -0
  108. package/dist/src/lib/config.js +88 -0
  109. package/dist/src/lib/config.js.map +1 -0
  110. package/dist/src/lib/constants.d.ts +32 -0
  111. package/dist/src/lib/constants.js +53 -0
  112. package/dist/src/lib/constants.js.map +1 -0
  113. package/dist/src/lib/credentials.d.ts +19 -0
  114. package/dist/src/lib/credentials.js +55 -0
  115. package/dist/src/lib/credentials.js.map +1 -0
  116. package/dist/src/lib/env-writer.d.ts +14 -0
  117. package/dist/src/lib/env-writer.js +39 -0
  118. package/dist/src/lib/env-writer.js.map +1 -0
  119. package/dist/src/lib/events.d.ts +114 -0
  120. package/dist/src/lib/events.js +19 -0
  121. package/dist/src/lib/events.js.map +1 -0
  122. package/dist/src/lib/framework-config.d.ts +108 -0
  123. package/dist/src/lib/framework-config.js +11 -0
  124. package/dist/src/lib/framework-config.js.map +1 -0
  125. package/dist/src/lib/helper-functions.d.ts +1 -0
  126. package/dist/src/lib/helper-functions.js +2 -0
  127. package/dist/src/lib/helper-functions.js.map +1 -0
  128. package/dist/src/lib/port-detection.d.ts +7 -0
  129. package/dist/src/lib/port-detection.js +112 -0
  130. package/dist/src/lib/port-detection.js.map +1 -0
  131. package/dist/src/lib/progress-tracker.d.ts +22 -0
  132. package/dist/src/lib/progress-tracker.js +47 -0
  133. package/dist/src/lib/progress-tracker.js.map +1 -0
  134. package/dist/src/lib/run-with-core.d.ts +2 -0
  135. package/dist/src/lib/run-with-core.js +266 -0
  136. package/dist/src/lib/run-with-core.js.map +1 -0
  137. package/dist/src/lib/safe-tools.d.ts +2 -0
  138. package/dist/src/lib/safe-tools.js +212 -0
  139. package/dist/src/lib/safe-tools.js.map +1 -0
  140. package/dist/src/lib/settings.d.ts +59 -0
  141. package/dist/src/lib/settings.js +36 -0
  142. package/dist/src/lib/settings.js.map +1 -0
  143. package/dist/src/lib/token-refresh.d.ts +12 -0
  144. package/dist/src/lib/token-refresh.js +26 -0
  145. package/dist/src/lib/token-refresh.js.map +1 -0
  146. package/dist/src/lib/validation/build-validator.d.ts +9 -0
  147. package/dist/src/lib/validation/build-validator.js +118 -0
  148. package/dist/src/lib/validation/build-validator.js.map +1 -0
  149. package/dist/src/lib/validation/index.d.ts +3 -0
  150. package/dist/src/lib/validation/index.js +3 -0
  151. package/dist/src/lib/validation/index.js.map +1 -0
  152. package/dist/src/lib/validation/types.d.ts +41 -0
  153. package/dist/src/lib/validation/types.js +2 -0
  154. package/dist/src/lib/validation/types.js.map +1 -0
  155. package/dist/src/lib/validation/validator.d.ts +6 -0
  156. package/dist/src/lib/validation/validator.js +647 -0
  157. package/dist/src/lib/validation/validator.js.map +1 -0
  158. package/dist/src/lib/wizard-core.d.ts +200 -0
  159. package/dist/src/lib/wizard-core.js +392 -0
  160. package/dist/src/lib/wizard-core.js.map +1 -0
  161. package/dist/src/lib/wizard-core.types.d.ts +73 -0
  162. package/dist/src/lib/wizard-core.types.js +2 -0
  163. package/dist/src/lib/wizard-core.types.js.map +1 -0
  164. package/dist/src/lib/workos-management.d.ts +32 -0
  165. package/dist/src/lib/workos-management.js +142 -0
  166. package/dist/src/lib/workos-management.js.map +1 -0
  167. package/dist/src/nextjs/nextjs-wizard-agent.d.ts +6 -0
  168. package/dist/src/nextjs/nextjs-wizard-agent.js +97 -0
  169. package/dist/src/nextjs/nextjs-wizard-agent.js.map +1 -0
  170. package/dist/src/nextjs/utils.d.ts +8 -0
  171. package/dist/src/nextjs/utils.js +53 -0
  172. package/dist/src/nextjs/utils.js.map +1 -0
  173. package/dist/src/react/react-wizard-agent.d.ts +2 -0
  174. package/dist/src/react/react-wizard-agent.js +47 -0
  175. package/dist/src/react/react-wizard-agent.js.map +1 -0
  176. package/dist/src/react-router/react-router-wizard-agent.d.ts +6 -0
  177. package/dist/src/react-router/react-router-wizard-agent.js +103 -0
  178. package/dist/src/react-router/react-router-wizard-agent.js.map +1 -0
  179. package/dist/src/react-router/utils.d.ts +19 -0
  180. package/dist/src/react-router/utils.js +210 -0
  181. package/dist/src/react-router/utils.js.map +1 -0
  182. package/dist/src/run.d.ts +24 -0
  183. package/dist/src/run.js +48 -0
  184. package/dist/src/run.js.map +1 -0
  185. package/dist/src/steps/add-or-update-environment-variables.d.ts +10 -0
  186. package/dist/src/steps/add-or-update-environment-variables.js +155 -0
  187. package/dist/src/steps/add-or-update-environment-variables.js.map +1 -0
  188. package/dist/src/steps/index.d.ts +3 -0
  189. package/dist/src/steps/index.js +4 -0
  190. package/dist/src/steps/index.js.map +1 -0
  191. package/dist/src/steps/run-prettier.d.ts +5 -0
  192. package/dist/src/steps/run-prettier.js +54 -0
  193. package/dist/src/steps/run-prettier.js.map +1 -0
  194. package/dist/src/steps/upload-environment-variables/EnvironmentProvider.d.ts +8 -0
  195. package/dist/src/steps/upload-environment-variables/EnvironmentProvider.js +7 -0
  196. package/dist/src/steps/upload-environment-variables/EnvironmentProvider.js.map +1 -0
  197. package/dist/src/steps/upload-environment-variables/index.d.ts +6 -0
  198. package/dist/src/steps/upload-environment-variables/index.js +57 -0
  199. package/dist/src/steps/upload-environment-variables/index.js.map +1 -0
  200. package/dist/src/steps/upload-environment-variables/providers/vercel.d.ts +14 -0
  201. package/dist/src/steps/upload-environment-variables/providers/vercel.js +104 -0
  202. package/dist/src/steps/upload-environment-variables/providers/vercel.js.map +1 -0
  203. package/dist/src/tanstack-start/tanstack-start-wizard-agent.d.ts +2 -0
  204. package/dist/src/tanstack-start/tanstack-start-wizard-agent.js +49 -0
  205. package/dist/src/tanstack-start/tanstack-start-wizard-agent.js.map +1 -0
  206. package/dist/src/telemetry.d.ts +2 -0
  207. package/dist/src/telemetry.js +29 -0
  208. package/dist/src/telemetry.js.map +1 -0
  209. package/dist/src/utils/analytics.d.ts +24 -0
  210. package/dist/src/utils/analytics.js +139 -0
  211. package/dist/src/utils/analytics.js.map +1 -0
  212. package/dist/src/utils/bash.d.ts +2 -0
  213. package/dist/src/utils/bash.js +17 -0
  214. package/dist/src/utils/bash.js.map +1 -0
  215. package/dist/src/utils/clack-utils.d.ts +93 -0
  216. package/dist/src/utils/clack-utils.js +397 -0
  217. package/dist/src/utils/clack-utils.js.map +1 -0
  218. package/dist/src/utils/clack.d.ts +5 -0
  219. package/dist/src/utils/clack.js +34 -0
  220. package/dist/src/utils/clack.js.map +1 -0
  221. package/dist/src/utils/cli-symbols.d.ts +32 -0
  222. package/dist/src/utils/cli-symbols.js +46 -0
  223. package/dist/src/utils/cli-symbols.js.map +1 -0
  224. package/dist/src/utils/debug.d.ts +7 -0
  225. package/dist/src/utils/debug.js +88 -0
  226. package/dist/src/utils/debug.js.map +1 -0
  227. package/dist/src/utils/env-parser.d.ts +5 -0
  228. package/dist/src/utils/env-parser.js +18 -0
  229. package/dist/src/utils/env-parser.js.map +1 -0
  230. package/dist/src/utils/environment.d.ts +4 -0
  231. package/dist/src/utils/environment.js +69 -0
  232. package/dist/src/utils/environment.js.map +1 -0
  233. package/dist/src/utils/errors.d.ts +3 -0
  234. package/dist/src/utils/errors.js +7 -0
  235. package/dist/src/utils/errors.js.map +1 -0
  236. package/dist/src/utils/logging.d.ts +9 -0
  237. package/dist/src/utils/logging.js +36 -0
  238. package/dist/src/utils/logging.js.map +1 -0
  239. package/dist/src/utils/package-json.d.ts +25 -0
  240. package/dist/src/utils/package-json.js +21 -0
  241. package/dist/src/utils/package-json.js.map +1 -0
  242. package/dist/src/utils/package-manager.d.ts +21 -0
  243. package/dist/src/utils/package-manager.js +167 -0
  244. package/dist/src/utils/package-manager.js.map +1 -0
  245. package/dist/src/utils/redact.d.ts +5 -0
  246. package/dist/src/utils/redact.js +29 -0
  247. package/dist/src/utils/redact.js.map +1 -0
  248. package/dist/src/utils/semver.d.ts +10 -0
  249. package/dist/src/utils/semver.js +43 -0
  250. package/dist/src/utils/semver.js.map +1 -0
  251. package/dist/src/utils/string.d.ts +1 -0
  252. package/dist/src/utils/string.js +6 -0
  253. package/dist/src/utils/string.js.map +1 -0
  254. package/dist/src/utils/telemetry-client.d.ts +15 -0
  255. package/dist/src/utils/telemetry-client.js +57 -0
  256. package/dist/src/utils/telemetry-client.js.map +1 -0
  257. package/dist/src/utils/telemetry-types.d.ts +51 -0
  258. package/dist/src/utils/telemetry-types.js +6 -0
  259. package/dist/src/utils/telemetry-types.js.map +1 -0
  260. package/dist/src/utils/types.d.ts +80 -0
  261. package/dist/src/utils/types.js +2 -0
  262. package/dist/src/utils/types.js.map +1 -0
  263. package/dist/src/utils/urls.d.ts +7 -0
  264. package/dist/src/utils/urls.js +8 -0
  265. package/dist/src/utils/urls.js.map +1 -0
  266. package/dist/src/utils/vendor/is-unicorn-supported.d.ts +1 -0
  267. package/dist/src/utils/vendor/is-unicorn-supported.js +21 -0
  268. package/dist/src/utils/vendor/is-unicorn-supported.js.map +1 -0
  269. package/dist/src/vanilla-js/vanilla-js-wizard-agent.d.ts +2 -0
  270. package/dist/src/vanilla-js/vanilla-js-wizard-agent.js +47 -0
  271. package/dist/src/vanilla-js/vanilla-js-wizard-agent.js.map +1 -0
  272. package/package.json +76 -84
  273. package/skills/workos-authkit-base/SKILL.md +113 -0
  274. package/skills/workos-authkit-nextjs/SKILL.md +115 -0
  275. package/skills/workos-authkit-react/SKILL.md +91 -0
  276. package/skills/workos-authkit-react-router/SKILL.md +106 -0
  277. package/skills/workos-authkit-tanstack-start/SKILL.md +104 -0
  278. package/skills/workos-authkit-vanilla-js/SKILL.md +81 -0
  279. package/build/apps/index.js +0 -50
  280. package/build/apps/slack.js +0 -151
  281. package/build/cli.js +0 -42
  282. package/build/config.js +0 -34
  283. package/build/dev.js +0 -5
  284. package/build/enable-api-access.png +0 -0
  285. package/build/groups.js +0 -480
  286. package/build/index.js +0 -3
  287. package/build/info.js +0 -69
  288. package/build/login.js +0 -161
  289. package/build/main.js +0 -214
  290. package/build/users.js +0 -402
  291. package/build/util.js +0 -157
  292. package/coverage/clover.xml +0 -66
  293. package/coverage/coverage-final.json +0 -4
  294. package/coverage/lcov-report/base.css +0 -212
  295. package/coverage/lcov-report/cli.ts.html +0 -329
  296. package/coverage/lcov-report/config.ts.html +0 -152
  297. package/coverage/lcov-report/index.html +0 -119
  298. package/coverage/lcov-report/prettify.css +0 -1
  299. package/coverage/lcov-report/prettify.js +0 -1
  300. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  301. package/coverage/lcov-report/sorter.js +0 -158
  302. package/coverage/lcov-report/util.ts.html +0 -350
  303. package/coverage/lcov.info +0 -121
  304. package/package-lock.json +0 -7617
  305. package/tests/util.test.ts +0 -35
@@ -0,0 +1,647 @@
1
+ import { readFile } from 'fs/promises';
2
+ import { existsSync } from 'fs';
3
+ import { join } from 'path';
4
+ import fg from 'fast-glob';
5
+ import { runBuildValidation } from './build-validator.js';
6
+ export async function validateInstallation(framework, projectDir, options = {}) {
7
+ const startTime = Date.now();
8
+ const issues = [];
9
+ // Load rules for framework (with optional variant)
10
+ const rules = await loadRules(framework, options.variant);
11
+ if (!rules) {
12
+ return {
13
+ passed: true,
14
+ framework,
15
+ issues: [],
16
+ durationMs: Date.now() - startTime,
17
+ };
18
+ }
19
+ // Run validations
20
+ await validatePackages(rules, projectDir, issues);
21
+ await validateEnvVars(rules, projectDir, issues);
22
+ await validateFiles(rules, projectDir, issues);
23
+ // Run framework-specific cross-validations
24
+ await validateFrameworkSpecific(framework, projectDir, issues);
25
+ // Run build validation if enabled
26
+ if (options.runBuild !== false) {
27
+ const buildResult = await runBuildValidation(projectDir);
28
+ issues.push(...buildResult.issues);
29
+ }
30
+ return {
31
+ passed: issues.filter((i) => i.severity === 'error').length === 0,
32
+ framework,
33
+ issues,
34
+ durationMs: Date.now() - startTime,
35
+ };
36
+ }
37
+ async function loadRules(framework, variant) {
38
+ const rulesPath = new URL(`./rules/${framework}.json`, import.meta.url);
39
+ try {
40
+ const content = await readFile(rulesPath, 'utf-8');
41
+ const rules = JSON.parse(content);
42
+ // Merge variant rules if specified
43
+ if (variant && rules.variants?.[variant]) {
44
+ const variantRules = rules.variants[variant];
45
+ return {
46
+ ...rules,
47
+ files: [...rules.files, ...(variantRules.files || [])],
48
+ packages: [...rules.packages, ...(variantRules.packages || [])],
49
+ envVars: [...rules.envVars, ...(variantRules.envVars || [])],
50
+ };
51
+ }
52
+ return rules;
53
+ }
54
+ catch {
55
+ return null; // No rules for this framework yet
56
+ }
57
+ }
58
+ async function validatePackages(rules, projectDir, issues) {
59
+ const pkgPath = join(projectDir, 'package.json');
60
+ if (!existsSync(pkgPath))
61
+ return;
62
+ let pkg;
63
+ try {
64
+ pkg = JSON.parse(await readFile(pkgPath, 'utf-8'));
65
+ }
66
+ catch {
67
+ // Malformed package.json - skip package validation
68
+ return;
69
+ }
70
+ const deps = (pkg.dependencies || {});
71
+ const devDeps = (pkg.devDependencies || {});
72
+ const allDeps = { ...devDeps, ...deps };
73
+ for (const rule of rules.packages) {
74
+ const location = rule.location || 'any';
75
+ const searchIn = location === 'any' ? allDeps : location === 'dependencies' ? deps : devDeps;
76
+ if (!searchIn[rule.name]) {
77
+ issues.push({
78
+ type: 'package',
79
+ severity: 'error',
80
+ message: `Missing package: ${rule.name}`,
81
+ hint: `Run: npm install ${rule.name}`,
82
+ });
83
+ }
84
+ }
85
+ }
86
+ async function validateEnvVars(rules, projectDir, issues) {
87
+ const envPath = join(projectDir, '.env.local');
88
+ let envContent = '';
89
+ try {
90
+ envContent = await readFile(envPath, 'utf-8');
91
+ }
92
+ catch {
93
+ if (rules.envVars.length > 0) {
94
+ issues.push({
95
+ type: 'env',
96
+ severity: 'error',
97
+ message: 'Missing .env.local file',
98
+ hint: 'Create .env.local with required environment variables',
99
+ });
100
+ }
101
+ return;
102
+ }
103
+ for (const rule of rules.envVars) {
104
+ // Check primary name and any alternates
105
+ const varsToCheck = [rule.name, ...(rule.alternates || [])];
106
+ const found = varsToCheck.some((varName) => {
107
+ const pattern = new RegExp(`^${varName}=.+`, 'm');
108
+ return pattern.test(envContent);
109
+ });
110
+ if (!found) {
111
+ const hint = rule.alternates
112
+ ? `Add ${rule.name} (or one of: ${rule.alternates.join(', ')}) to .env.local`
113
+ : `Add ${rule.name}=your_value to .env.local`;
114
+ issues.push({
115
+ type: 'env',
116
+ severity: rule.required === false ? 'warning' : 'error',
117
+ message: `Missing environment variable: ${rule.name}`,
118
+ hint,
119
+ });
120
+ }
121
+ }
122
+ }
123
+ async function validateFiles(rules, projectDir, issues) {
124
+ for (const rule of rules.files) {
125
+ let matches;
126
+ try {
127
+ matches = await fg(rule.path, { cwd: projectDir });
128
+ }
129
+ catch {
130
+ // Invalid glob pattern - skip
131
+ continue;
132
+ }
133
+ if (matches.length === 0) {
134
+ issues.push({
135
+ type: 'file',
136
+ severity: 'error',
137
+ message: `Missing file: ${rule.path}`,
138
+ hint: `Create ${rule.path}`,
139
+ });
140
+ continue;
141
+ }
142
+ // Check content patterns
143
+ if (rule.mustContain || rule.mustContainAny) {
144
+ const filePath = join(projectDir, matches[0]);
145
+ let content;
146
+ try {
147
+ content = await readFile(filePath, 'utf-8');
148
+ }
149
+ catch {
150
+ // File read error - skip content checks
151
+ continue;
152
+ }
153
+ // All must be present
154
+ if (rule.mustContain) {
155
+ for (const pattern of rule.mustContain) {
156
+ if (!content.includes(pattern)) {
157
+ issues.push({
158
+ type: 'pattern',
159
+ severity: 'warning',
160
+ message: `File ${matches[0]} missing expected pattern: "${pattern}"`,
161
+ hint: `Ensure ${matches[0]} contains: ${pattern}`,
162
+ });
163
+ }
164
+ }
165
+ }
166
+ // At least one must be present
167
+ if (rule.mustContainAny) {
168
+ const hasAny = rule.mustContainAny.some((p) => content.includes(p));
169
+ if (!hasAny) {
170
+ issues.push({
171
+ type: 'pattern',
172
+ severity: 'warning',
173
+ message: `File ${matches[0]} missing one of: ${rule.mustContainAny.join(', ')}`,
174
+ hint: `Ensure ${matches[0]} contains one of these patterns`,
175
+ });
176
+ }
177
+ }
178
+ }
179
+ }
180
+ }
181
+ /**
182
+ * Framework-specific cross-validations that require reading multiple sources.
183
+ */
184
+ async function validateFrameworkSpecific(framework, projectDir, issues) {
185
+ // Universal cross-validations
186
+ await validateCredentialFormats(projectDir, issues);
187
+ await validateDuplicateEnvVars(projectDir, issues);
188
+ // Framework-specific validations
189
+ switch (framework) {
190
+ case 'nextjs':
191
+ await validateNextjsRedirectUri(projectDir, issues);
192
+ await validateNextjsMiddlewarePlacement(projectDir, issues);
193
+ await validateCookiePasswordLength(projectDir, issues, 'WORKOS_COOKIE_PASSWORD');
194
+ break;
195
+ case 'react':
196
+ await validateReactProviderWrapping(projectDir, issues);
197
+ break;
198
+ case 'react-router':
199
+ await validateReactRouterRedirectUri(projectDir, issues);
200
+ await validateCookiePasswordLength(projectDir, issues, 'WORKOS_COOKIE_PASSWORD');
201
+ break;
202
+ case 'tanstack-start':
203
+ await validateTanstackStartRedirectUri(projectDir, issues);
204
+ await validateCookiePasswordLength(projectDir, issues, 'WORKOS_COOKIE_PASSWORD');
205
+ break;
206
+ }
207
+ }
208
+ /**
209
+ * Validates that the Next.js redirect URI matches an existing callback route.
210
+ *
211
+ * Common failure: .env.local has /auth/callback but route is at /api/auth/callback
212
+ */
213
+ async function validateNextjsRedirectUri(projectDir, issues) {
214
+ const envPath = join(projectDir, '.env.local');
215
+ let envContent;
216
+ try {
217
+ envContent = await readFile(envPath, 'utf-8');
218
+ }
219
+ catch {
220
+ return; // No .env.local - other validators handle this
221
+ }
222
+ // Extract redirect URI value
223
+ const match = envContent.match(/^NEXT_PUBLIC_WORKOS_REDIRECT_URI=(.+)$/m);
224
+ if (!match) {
225
+ return; // Missing env var - other validators handle this
226
+ }
227
+ const redirectUri = match[1].trim();
228
+ let callbackPath;
229
+ try {
230
+ const url = new URL(redirectUri);
231
+ callbackPath = url.pathname;
232
+ }
233
+ catch {
234
+ issues.push({
235
+ type: 'env',
236
+ severity: 'error',
237
+ message: `Invalid redirect URI: ${redirectUri}`,
238
+ hint: 'NEXT_PUBLIC_WORKOS_REDIRECT_URI must be a valid URL',
239
+ });
240
+ return;
241
+ }
242
+ // Remove leading slash for path matching
243
+ const routePath = callbackPath.replace(/^\//, '');
244
+ // Check if route file exists at expected location (Next.js App Router)
245
+ const routePatterns = [
246
+ `app/${routePath}/route.ts`,
247
+ `app/${routePath}/route.tsx`,
248
+ `app/${routePath}/route.js`,
249
+ `app/${routePath}/route.jsx`,
250
+ `src/app/${routePath}/route.ts`,
251
+ `src/app/${routePath}/route.tsx`,
252
+ `src/app/${routePath}/route.js`,
253
+ `src/app/${routePath}/route.jsx`,
254
+ ];
255
+ const routeExists = routePatterns.some((pattern) => existsSync(join(projectDir, pattern)));
256
+ if (!routeExists) {
257
+ // Check what routes DO exist to give a better hint
258
+ const existingRoutes = await fg(['app/**/callback/**/route.{ts,tsx,js,jsx}', 'src/app/**/callback/**/route.{ts,tsx,js,jsx}'], {
259
+ cwd: projectDir,
260
+ });
261
+ let hint = `Create a route handler at app/${routePath}/route.ts`;
262
+ if (existingRoutes.length > 0) {
263
+ // Found a route at a different path - likely the mismatch
264
+ const actualPath = '/' + existingRoutes[0].replace(/^(src\/)?app\//, '').replace(/\/route\.(ts|tsx|js|jsx)$/, '');
265
+ hint =
266
+ `Found callback route at ${existingRoutes[0]} but redirect URI points to ${callbackPath}. Either:\n` +
267
+ ` 1. Change NEXT_PUBLIC_WORKOS_REDIRECT_URI to http://localhost:3000${actualPath}\n` +
268
+ ` 2. Move the route to app/${routePath}/route.ts`;
269
+ }
270
+ issues.push({
271
+ type: 'file',
272
+ severity: 'error',
273
+ message: `Redirect URI path "${callbackPath}" has no matching route file`,
274
+ hint,
275
+ });
276
+ }
277
+ }
278
+ /**
279
+ * Validates that the React Router redirect URI matches an existing callback route.
280
+ *
281
+ * React Router v7 framework mode uses file-based routing:
282
+ * - /auth/callback → app/routes/auth.callback.tsx (dot notation)
283
+ * - /auth/callback → app/routes/auth/callback.tsx (nested folders)
284
+ */
285
+ async function validateReactRouterRedirectUri(projectDir, issues) {
286
+ const envPath = join(projectDir, '.env.local');
287
+ let envContent;
288
+ try {
289
+ envContent = await readFile(envPath, 'utf-8');
290
+ }
291
+ catch {
292
+ return;
293
+ }
294
+ const match = envContent.match(/^WORKOS_REDIRECT_URI=(.+)$/m);
295
+ if (!match) {
296
+ return;
297
+ }
298
+ const redirectUri = match[1].trim();
299
+ let callbackPath;
300
+ try {
301
+ const url = new URL(redirectUri);
302
+ callbackPath = url.pathname;
303
+ }
304
+ catch {
305
+ issues.push({
306
+ type: 'env',
307
+ severity: 'error',
308
+ message: `Invalid redirect URI: ${redirectUri}`,
309
+ hint: 'WORKOS_REDIRECT_URI must be a valid URL',
310
+ });
311
+ return;
312
+ }
313
+ const routePath = callbackPath.replace(/^\//, '');
314
+ // React Router uses dot notation: /auth/callback → auth.callback
315
+ const dotPath = routePath.replace(/\//g, '.');
316
+ // Check possible route file locations
317
+ const routePatterns = [
318
+ // Dot notation (e.g., app/routes/auth.callback.tsx)
319
+ `app/routes/${dotPath}.tsx`,
320
+ `app/routes/${dotPath}.ts`,
321
+ `app/routes/${dotPath}.jsx`,
322
+ `app/routes/${dotPath}.js`,
323
+ // Nested folders (e.g., app/routes/auth/callback.tsx)
324
+ `app/routes/${routePath}.tsx`,
325
+ `app/routes/${routePath}.ts`,
326
+ `app/routes/${routePath}.jsx`,
327
+ `app/routes/${routePath}.js`,
328
+ // Index file in folder (e.g., app/routes/auth/callback/index.tsx)
329
+ `app/routes/${routePath}/index.tsx`,
330
+ `app/routes/${routePath}/index.ts`,
331
+ `app/routes/${routePath}/index.jsx`,
332
+ `app/routes/${routePath}/index.js`,
333
+ // Route file in folder (e.g., app/routes/auth/callback/route.tsx)
334
+ `app/routes/${routePath}/route.tsx`,
335
+ `app/routes/${routePath}/route.ts`,
336
+ `app/routes/${routePath}/route.jsx`,
337
+ `app/routes/${routePath}/route.js`,
338
+ ];
339
+ const routeExists = routePatterns.some((pattern) => existsSync(join(projectDir, pattern)));
340
+ if (!routeExists) {
341
+ const existingRoutes = await fg(['app/routes/**/*callback*.{ts,tsx,js,jsx}'], {
342
+ cwd: projectDir,
343
+ });
344
+ let hint = `Create a route at app/routes/${dotPath}.tsx`;
345
+ if (existingRoutes.length > 0) {
346
+ const actualFile = existingRoutes[0];
347
+ // Convert file path back to URL path
348
+ const actualPath = '/' +
349
+ actualFile
350
+ .replace(/^app\/routes\//, '')
351
+ .replace(/\.(tsx?|jsx?)$/, '')
352
+ .replace(/\/(index|route)$/, '')
353
+ .replace(/\./g, '/');
354
+ hint =
355
+ `Found callback route at ${actualFile} but redirect URI points to ${callbackPath}. Either:\n` +
356
+ ` 1. Change WORKOS_REDIRECT_URI to http://localhost:3000${actualPath}\n` +
357
+ ` 2. Move the route to app/routes/${dotPath}.tsx`;
358
+ }
359
+ issues.push({
360
+ type: 'file',
361
+ severity: 'error',
362
+ message: `Redirect URI path "${callbackPath}" has no matching route file`,
363
+ hint,
364
+ });
365
+ }
366
+ }
367
+ /**
368
+ * Validates that the TanStack Start redirect URI matches an existing callback route.
369
+ *
370
+ * TanStack Start uses file-based routing:
371
+ * - /auth/callback → app/routes/auth/callback.tsx
372
+ */
373
+ async function validateTanstackStartRedirectUri(projectDir, issues) {
374
+ const envPath = join(projectDir, '.env.local');
375
+ let envContent;
376
+ try {
377
+ envContent = await readFile(envPath, 'utf-8');
378
+ }
379
+ catch {
380
+ return;
381
+ }
382
+ const match = envContent.match(/^WORKOS_REDIRECT_URI=(.+)$/m);
383
+ if (!match) {
384
+ return;
385
+ }
386
+ const redirectUri = match[1].trim();
387
+ let callbackPath;
388
+ try {
389
+ const url = new URL(redirectUri);
390
+ callbackPath = url.pathname;
391
+ }
392
+ catch {
393
+ issues.push({
394
+ type: 'env',
395
+ severity: 'error',
396
+ message: `Invalid redirect URI: ${redirectUri}`,
397
+ hint: 'WORKOS_REDIRECT_URI must be a valid URL',
398
+ });
399
+ return;
400
+ }
401
+ const routePath = callbackPath.replace(/^\//, '');
402
+ // TanStack Start route patterns
403
+ const routePatterns = [
404
+ `app/routes/${routePath}.tsx`,
405
+ `app/routes/${routePath}.ts`,
406
+ `app/routes/${routePath}.jsx`,
407
+ `app/routes/${routePath}.js`,
408
+ `app/routes/${routePath}/index.tsx`,
409
+ `app/routes/${routePath}/index.ts`,
410
+ `app/routes/${routePath}/index.jsx`,
411
+ `app/routes/${routePath}/index.js`,
412
+ ];
413
+ const routeExists = routePatterns.some((pattern) => existsSync(join(projectDir, pattern)));
414
+ if (!routeExists) {
415
+ const existingRoutes = await fg(['app/routes/**/*callback*.{ts,tsx,js,jsx}'], {
416
+ cwd: projectDir,
417
+ });
418
+ let hint = `Create a route at app/routes/${routePath}.tsx`;
419
+ if (existingRoutes.length > 0) {
420
+ const actualFile = existingRoutes[0];
421
+ const actualPath = '/' +
422
+ actualFile
423
+ .replace(/^app\/routes\//, '')
424
+ .replace(/\.(tsx?|jsx?)$/, '')
425
+ .replace(/\/index$/, '');
426
+ hint =
427
+ `Found callback route at ${actualFile} but redirect URI points to ${callbackPath}. Either:\n` +
428
+ ` 1. Change WORKOS_REDIRECT_URI to http://localhost:3000${actualPath}\n` +
429
+ ` 2. Move the route to app/routes/${routePath}.tsx`;
430
+ }
431
+ issues.push({
432
+ type: 'file',
433
+ severity: 'error',
434
+ message: `Redirect URI path "${callbackPath}" has no matching route file`,
435
+ hint,
436
+ });
437
+ }
438
+ }
439
+ /**
440
+ * Validates cookie password is at least 32 characters.
441
+ * WorkOS requires this for secure session encryption.
442
+ */
443
+ async function validateCookiePasswordLength(projectDir, issues, envVarName) {
444
+ const envPath = join(projectDir, '.env.local');
445
+ let envContent;
446
+ try {
447
+ envContent = await readFile(envPath, 'utf-8');
448
+ }
449
+ catch {
450
+ return; // No .env.local - other validators handle this
451
+ }
452
+ const match = envContent.match(new RegExp(`^${envVarName}=(.*)$`, 'm'));
453
+ if (!match) {
454
+ return; // Missing env var - other validators handle this
455
+ }
456
+ const password = match[1].trim();
457
+ if (password.length < 32) {
458
+ issues.push({
459
+ type: 'env',
460
+ severity: 'error',
461
+ message: `${envVarName} must be at least 32 characters (currently ${password.length})`,
462
+ hint: `Generate a secure password: openssl rand -base64 32`,
463
+ });
464
+ }
465
+ }
466
+ /**
467
+ * Validates credential formats:
468
+ * - API key should start with sk_
469
+ * - Client ID should start with client_
470
+ */
471
+ async function validateCredentialFormats(projectDir, issues) {
472
+ const envPath = join(projectDir, '.env.local');
473
+ let envContent;
474
+ try {
475
+ envContent = await readFile(envPath, 'utf-8');
476
+ }
477
+ catch {
478
+ return;
479
+ }
480
+ // Check API key format (any common variation)
481
+ const apiKeyPatterns = [/^WORKOS_API_KEY=(.*)$/m, /^NEXT_PUBLIC_WORKOS_API_KEY=(.*)$/m];
482
+ for (const pattern of apiKeyPatterns) {
483
+ const match = envContent.match(pattern);
484
+ if (match) {
485
+ const value = match[1].trim();
486
+ if (value && !value.startsWith('sk_')) {
487
+ issues.push({
488
+ type: 'env',
489
+ severity: 'error',
490
+ message: `Invalid API key format: "${value.substring(0, 10)}..."`,
491
+ hint: 'WorkOS API keys start with "sk_". Check your WorkOS Dashboard for the correct key.',
492
+ });
493
+ }
494
+ }
495
+ }
496
+ // Check Client ID format
497
+ const clientIdPatterns = [/^WORKOS_CLIENT_ID=(.*)$/m, /^NEXT_PUBLIC_WORKOS_CLIENT_ID=(.*)$/m];
498
+ for (const pattern of clientIdPatterns) {
499
+ const match = envContent.match(pattern);
500
+ if (match) {
501
+ const value = match[1].trim();
502
+ if (value && !value.startsWith('client_')) {
503
+ issues.push({
504
+ type: 'env',
505
+ severity: 'error',
506
+ message: `Invalid Client ID format: "${value.substring(0, 15)}..."`,
507
+ hint: 'WorkOS Client IDs start with "client_". Check your WorkOS Dashboard for the correct ID.',
508
+ });
509
+ }
510
+ }
511
+ }
512
+ }
513
+ /**
514
+ * Validates Next.js middleware.ts is at the correct location.
515
+ * Must be at project root or src/ folder, not nested deeper.
516
+ */
517
+ async function validateNextjsMiddlewarePlacement(projectDir, issues) {
518
+ // Valid locations
519
+ const validPaths = ['middleware.ts', 'middleware.js', 'src/middleware.ts', 'src/middleware.js'];
520
+ const hasValidMiddleware = validPaths.some((p) => existsSync(join(projectDir, p)));
521
+ if (hasValidMiddleware) {
522
+ return; // Correctly placed
523
+ }
524
+ // Check for misplaced middleware
525
+ const misplacedMiddleware = await fg(['**/middleware.{ts,js}'], {
526
+ cwd: projectDir,
527
+ ignore: ['node_modules/**'],
528
+ });
529
+ if (misplacedMiddleware.length > 0) {
530
+ issues.push({
531
+ type: 'file',
532
+ severity: 'error',
533
+ message: `middleware.ts found at wrong location: ${misplacedMiddleware[0]}`,
534
+ hint: 'Next.js middleware must be at project root (middleware.ts) or src/middleware.ts, not nested in app/ or other folders.',
535
+ });
536
+ }
537
+ }
538
+ /**
539
+ * Validates React SPA has AuthKitProvider wrapping the app.
540
+ */
541
+ async function validateReactProviderWrapping(projectDir, issues) {
542
+ // Common entry points for React apps
543
+ const entryPatterns = [
544
+ 'src/main.tsx',
545
+ 'src/main.jsx',
546
+ 'src/index.tsx',
547
+ 'src/index.jsx',
548
+ 'src/App.tsx',
549
+ 'src/App.jsx',
550
+ 'app/layout.tsx',
551
+ 'app/layout.jsx',
552
+ ];
553
+ let foundProvider = false;
554
+ for (const pattern of entryPatterns) {
555
+ const filePath = join(projectDir, pattern);
556
+ if (!existsSync(filePath))
557
+ continue;
558
+ try {
559
+ const content = await readFile(filePath, 'utf-8');
560
+ if (content.includes('AuthKitProvider')) {
561
+ foundProvider = true;
562
+ break;
563
+ }
564
+ }
565
+ catch {
566
+ continue;
567
+ }
568
+ }
569
+ if (!foundProvider) {
570
+ // Check if package is installed (if not, other validators handle it)
571
+ const pkgPath = join(projectDir, 'package.json');
572
+ if (existsSync(pkgPath)) {
573
+ try {
574
+ const pkg = JSON.parse(await readFile(pkgPath, 'utf-8'));
575
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
576
+ if (deps['@workos-inc/authkit-react']) {
577
+ issues.push({
578
+ type: 'pattern',
579
+ severity: 'warning',
580
+ message: 'AuthKitProvider not found in common entry points',
581
+ hint: 'Wrap your app with <AuthKitProvider> in main.tsx or App.tsx. See: https://workos.com/docs/user-management/react/authkit',
582
+ });
583
+ }
584
+ }
585
+ catch {
586
+ // Malformed package.json - skip
587
+ }
588
+ }
589
+ }
590
+ }
591
+ /**
592
+ * Detects duplicate env vars between .env and .env.local with different values.
593
+ * This can cause confusing behavior where wrong values are used.
594
+ */
595
+ async function validateDuplicateEnvVars(projectDir, issues) {
596
+ const envPath = join(projectDir, '.env');
597
+ const envLocalPath = join(projectDir, '.env.local');
598
+ let envContent;
599
+ let envLocalContent;
600
+ try {
601
+ envContent = await readFile(envPath, 'utf-8');
602
+ }
603
+ catch {
604
+ return; // No .env file - no conflict possible
605
+ }
606
+ try {
607
+ envLocalContent = await readFile(envLocalPath, 'utf-8');
608
+ }
609
+ catch {
610
+ return; // No .env.local - no conflict possible
611
+ }
612
+ // Parse env files into key-value maps
613
+ const parseEnv = (content) => {
614
+ const map = new Map();
615
+ for (const line of content.split('\n')) {
616
+ const match = line.match(/^([A-Z_][A-Z0-9_]*)=(.*)$/);
617
+ if (match) {
618
+ map.set(match[1], match[2].trim());
619
+ }
620
+ }
621
+ return map;
622
+ };
623
+ const envVars = parseEnv(envContent);
624
+ const envLocalVars = parseEnv(envLocalContent);
625
+ // Check for WorkOS-related vars that differ
626
+ const workosVars = [
627
+ 'WORKOS_API_KEY',
628
+ 'WORKOS_CLIENT_ID',
629
+ 'WORKOS_REDIRECT_URI',
630
+ 'WORKOS_COOKIE_PASSWORD',
631
+ 'NEXT_PUBLIC_WORKOS_CLIENT_ID',
632
+ 'NEXT_PUBLIC_WORKOS_REDIRECT_URI',
633
+ ];
634
+ for (const varName of workosVars) {
635
+ const envValue = envVars.get(varName);
636
+ const localValue = envLocalVars.get(varName);
637
+ if (envValue && localValue && envValue !== localValue) {
638
+ issues.push({
639
+ type: 'env',
640
+ severity: 'warning',
641
+ message: `${varName} has different values in .env and .env.local`,
642
+ hint: `.env.local takes precedence. Remove from .env to avoid confusion, or ensure they match.`,
643
+ });
644
+ }
645
+ }
646
+ }
647
+ //# sourceMappingURL=validator.js.map