create-authhero 0.30.0 → 0.31.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.
- package/dist/create-authhero.js +69 -69
- package/package.json +1 -1
package/dist/create-authhero.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Command as
|
|
2
|
+
import { Command as R } from "commander";
|
|
3
3
|
import u from "inquirer";
|
|
4
|
-
import
|
|
4
|
+
import a from "fs";
|
|
5
5
|
import l from "path";
|
|
6
|
-
import { spawn as
|
|
7
|
-
const
|
|
6
|
+
import { spawn as I } from "child_process";
|
|
7
|
+
const T = new R(), p = {
|
|
8
8
|
local: {
|
|
9
9
|
name: "Local (SQLite)",
|
|
10
10
|
description: "Local development setup with SQLite database - great for getting started",
|
|
@@ -134,13 +134,13 @@ const I = new U(), p = {
|
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
function E(o, e) {
|
|
137
|
-
|
|
138
|
-
const t = l.join(o, n),
|
|
139
|
-
|
|
137
|
+
a.readdirSync(o).forEach((n) => {
|
|
138
|
+
const t = l.join(o, n), s = l.join(e, n);
|
|
139
|
+
a.lstatSync(t).isDirectory() ? (a.mkdirSync(s, { recursive: !0 }), E(t, s)) : a.copyFileSync(t, s);
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
|
-
function
|
|
143
|
-
const n = o ? "control_plane" : "main", t = o ? "Control Plane" : "Main",
|
|
142
|
+
function U(o, e = !1, r = "authhero-local") {
|
|
143
|
+
const n = o ? "control_plane" : "main", t = o ? "Control Plane" : "Main", s = [
|
|
144
144
|
"https://manage.authhero.net/auth-callback",
|
|
145
145
|
"https://local.authhero.net/auth-callback",
|
|
146
146
|
"http://localhost:5173/auth-callback",
|
|
@@ -148,7 +148,7 @@ function j(o, e = !1, r = "authhero-local") {
|
|
|
148
148
|
], c = e ? [
|
|
149
149
|
`https://localhost.emobix.co.uk:8443/test/a/${r}/callback`,
|
|
150
150
|
`https://localhost:8443/test/a/${r}/callback`
|
|
151
|
-
] : [], g = [...
|
|
151
|
+
] : [], g = [...s, ...c], w = [
|
|
152
152
|
"https://manage.authhero.net",
|
|
153
153
|
"https://local.authhero.net",
|
|
154
154
|
"http://localhost:5173",
|
|
@@ -210,7 +210,7 @@ function j(o, e = !1, r = "authhero-local") {
|
|
|
210
210
|
// This is required for OIDCC-5.4 (VerifyScopesReturnedInUserInfoClaims) test
|
|
211
211
|
try {
|
|
212
212
|
await adapters.users.create("${n}", {
|
|
213
|
-
user_id:
|
|
213
|
+
user_id: \`\${USERNAME_PASSWORD_PROVIDER}|conformance-user\`,
|
|
214
214
|
email: "conformance@example.com",
|
|
215
215
|
email_verified: true,
|
|
216
216
|
name: "Conformance Test User",
|
|
@@ -227,7 +227,7 @@ function j(o, e = !1, r = "authhero-local") {
|
|
|
227
227
|
zoneinfo: "Europe/London",
|
|
228
228
|
locale: "en-US",
|
|
229
229
|
connection: "Username-Password-Authentication",
|
|
230
|
-
provider:
|
|
230
|
+
provider: USERNAME_PASSWORD_PROVIDER,
|
|
231
231
|
is_social: false,
|
|
232
232
|
});
|
|
233
233
|
console.log("✅ Created conformance test user (conformance@example.com)");
|
|
@@ -245,7 +245,7 @@ function j(o, e = !1, r = "authhero-local") {
|
|
|
245
245
|
const bcrypt = await import("bcryptjs");
|
|
246
246
|
const hashedPassword = await bcrypt.hash("ConformanceTest123!", 10);
|
|
247
247
|
await adapters.passwords.create("${n}", {
|
|
248
|
-
user_id:
|
|
248
|
+
user_id: \`\${USERNAME_PASSWORD_PROVIDER}|conformance-user\`,
|
|
249
249
|
password: hashedPassword,
|
|
250
250
|
});
|
|
251
251
|
console.log("✅ Created password for conformance test user");
|
|
@@ -289,7 +289,7 @@ ${b}
|
|
|
289
289
|
main().catch(console.error);
|
|
290
290
|
`;
|
|
291
291
|
}
|
|
292
|
-
function
|
|
292
|
+
function O(o) {
|
|
293
293
|
return o ? `import { Context } from "hono";
|
|
294
294
|
import { swaggerUI } from "@hono/swagger-ui";
|
|
295
295
|
import { AuthHeroConfig, DataAdapters } from "authhero";
|
|
@@ -393,7 +393,7 @@ export default function createApp(config: AuthHeroConfig) {
|
|
|
393
393
|
}
|
|
394
394
|
`;
|
|
395
395
|
}
|
|
396
|
-
function
|
|
396
|
+
function j(o) {
|
|
397
397
|
return `import { D1Dialect } from "kysely-d1";
|
|
398
398
|
import { Kysely } from "kysely";
|
|
399
399
|
import createAdapters from "@authhero/kysely-adapter";
|
|
@@ -453,7 +453,7 @@ export default {
|
|
|
453
453
|
};
|
|
454
454
|
`;
|
|
455
455
|
}
|
|
456
|
-
function
|
|
456
|
+
function L(o) {
|
|
457
457
|
return o ? `import { Context } from "hono";
|
|
458
458
|
import { swaggerUI } from "@hono/swagger-ui";
|
|
459
459
|
import { AuthHeroConfig, DataAdapters } from "authhero";
|
|
@@ -681,20 +681,20 @@ main().catch(console.error);
|
|
|
681
681
|
}
|
|
682
682
|
function H(o, e) {
|
|
683
683
|
const r = l.join(o, "src");
|
|
684
|
-
|
|
684
|
+
a.writeFileSync(
|
|
685
685
|
l.join(r, "app.ts"),
|
|
686
686
|
$(e)
|
|
687
|
-
),
|
|
687
|
+
), a.writeFileSync(
|
|
688
688
|
l.join(r, "seed.ts"),
|
|
689
689
|
M(e)
|
|
690
690
|
);
|
|
691
691
|
}
|
|
692
|
-
function
|
|
692
|
+
function D(o) {
|
|
693
693
|
console.log("\\n" + "─".repeat(50)), console.log("🔐 AuthHero deployed to AWS!"), console.log("📚 Check SST output for your API URL"), console.log("🌐 Portal available at https://local.authhero.net"), console.log(o ? "🏢 Multi-tenant mode enabled with control_plane tenant" : "🏠 Single-tenant mode with 'main' tenant"), console.log("─".repeat(50) + "\\n");
|
|
694
694
|
}
|
|
695
695
|
function F(o) {
|
|
696
696
|
const e = l.join(o, ".github", "workflows");
|
|
697
|
-
|
|
697
|
+
a.mkdirSync(e, { recursive: !0 });
|
|
698
698
|
const r = `name: Unit tests
|
|
699
699
|
|
|
700
700
|
on: push
|
|
@@ -781,7 +781,7 @@ jobs:
|
|
|
781
781
|
apiToken: \${{ secrets.PROD_CLOUDFLARE_API_TOKEN }}
|
|
782
782
|
command: deploy --env production
|
|
783
783
|
`;
|
|
784
|
-
|
|
784
|
+
a.writeFileSync(l.join(e, "unit-tests.yml"), r), a.writeFileSync(l.join(e, "deploy-dev.yml"), n), a.writeFileSync(l.join(e, "release.yml"), t), console.log("\\n📦 GitHub CI workflows created!");
|
|
785
785
|
}
|
|
786
786
|
function W(o) {
|
|
787
787
|
const e = {
|
|
@@ -792,11 +792,11 @@ function W(o) {
|
|
|
792
792
|
"@semantic-release/github"
|
|
793
793
|
]
|
|
794
794
|
};
|
|
795
|
-
|
|
795
|
+
a.writeFileSync(
|
|
796
796
|
l.join(o, ".releaserc.json"),
|
|
797
797
|
JSON.stringify(e, null, 2)
|
|
798
798
|
);
|
|
799
|
-
const r = l.join(o, "package.json"), n = JSON.parse(
|
|
799
|
+
const r = l.join(o, "package.json"), n = JSON.parse(a.readFileSync(r, "utf-8"));
|
|
800
800
|
n.devDependencies = {
|
|
801
801
|
...n.devDependencies,
|
|
802
802
|
"semantic-release": "^24.0.0"
|
|
@@ -804,54 +804,54 @@ function W(o) {
|
|
|
804
804
|
...n.scripts,
|
|
805
805
|
test: 'echo "No tests yet"',
|
|
806
806
|
"type-check": "tsc --noEmit"
|
|
807
|
-
},
|
|
807
|
+
}, a.writeFileSync(r, JSON.stringify(n, null, 2));
|
|
808
808
|
}
|
|
809
|
-
function
|
|
809
|
+
function A(o, e) {
|
|
810
810
|
return new Promise((r, n) => {
|
|
811
|
-
const t =
|
|
811
|
+
const t = I(o, [], {
|
|
812
812
|
cwd: e,
|
|
813
813
|
shell: !0,
|
|
814
814
|
stdio: "inherit"
|
|
815
815
|
});
|
|
816
|
-
t.on("close", (
|
|
817
|
-
|
|
816
|
+
t.on("close", (s) => {
|
|
817
|
+
s === 0 ? r() : n(new Error(`Command failed with exit code ${s}`));
|
|
818
818
|
}), t.on("error", n);
|
|
819
819
|
});
|
|
820
820
|
}
|
|
821
|
-
function
|
|
821
|
+
function _(o, e, r) {
|
|
822
822
|
return new Promise((n, t) => {
|
|
823
|
-
const
|
|
823
|
+
const s = I(o, [], {
|
|
824
824
|
cwd: e,
|
|
825
825
|
shell: !0,
|
|
826
826
|
stdio: "inherit",
|
|
827
827
|
env: { ...process.env, ...r }
|
|
828
828
|
});
|
|
829
|
-
|
|
829
|
+
s.on("close", (c) => {
|
|
830
830
|
c === 0 ? n() : t(new Error(`Command failed with exit code ${c}`));
|
|
831
|
-
}),
|
|
831
|
+
}), s.on("error", t);
|
|
832
832
|
});
|
|
833
833
|
}
|
|
834
834
|
function q(o, e) {
|
|
835
835
|
const r = l.join(o, "src");
|
|
836
|
-
|
|
836
|
+
a.writeFileSync(
|
|
837
837
|
l.join(r, "app.ts"),
|
|
838
|
-
|
|
839
|
-
),
|
|
838
|
+
L(e)
|
|
839
|
+
), a.writeFileSync(
|
|
840
840
|
l.join(r, "seed.ts"),
|
|
841
|
-
|
|
841
|
+
j(e)
|
|
842
842
|
);
|
|
843
843
|
}
|
|
844
|
-
function
|
|
844
|
+
function x(o) {
|
|
845
845
|
console.log(`
|
|
846
846
|
` + "─".repeat(50)), console.log("🔐 AuthHero server running at https://localhost:3000"), console.log("📚 API documentation available at https://localhost:3000/docs"), console.log("🌐 Portal available at https://local.authhero.net"), console.log(o ? "🏢 Multi-tenant mode enabled with control_plane tenant" : "🏠 Single-tenant mode with 'main' tenant"), console.log("─".repeat(50) + `
|
|
847
847
|
`);
|
|
848
848
|
}
|
|
849
|
-
function
|
|
849
|
+
function N(o) {
|
|
850
850
|
console.log(`
|
|
851
851
|
` + "─".repeat(50)), console.log("✅ Self-signed certificates generated with openssl"), console.log("⚠️ You may need to trust the certificate in your browser"), console.log("🔐 AuthHero server running at https://localhost:3000"), console.log("📚 API documentation available at https://localhost:3000/docs"), console.log("🌐 Portal available at https://local.authhero.net"), console.log(o ? "🏢 Multi-tenant mode enabled with control_plane tenant" : "🏠 Single-tenant mode with 'main' tenant"), console.log("─".repeat(50) + `
|
|
852
852
|
`);
|
|
853
853
|
}
|
|
854
|
-
|
|
854
|
+
T.version("1.0.0").description("Create a new AuthHero project").argument("[project-name]", "name of the project").option("-t, --template <type>", "template type: local or cloudflare").option("-e, --email <email>", "admin email address").option("-p, --password <password>", "admin password (min 8 characters)").option(
|
|
855
855
|
"--package-manager <pm>",
|
|
856
856
|
"package manager to use: npm, yarn, pnpm, or bun"
|
|
857
857
|
).option("--multi-tenant", "enable multi-tenant mode").option("--skip-install", "skip installing dependencies").option("--skip-migrate", "skip running database migrations").option("--skip-seed", "skip seeding the database").option("--skip-start", "skip starting the development server").option("--github-ci", "include GitHub CI workflows with semantic versioning").option("--conformance", "add OpenID conformance suite test clients").option(
|
|
@@ -873,9 +873,9 @@ I.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
873
873
|
}
|
|
874
874
|
])).projectName);
|
|
875
875
|
const t = l.join(process.cwd(), n);
|
|
876
|
-
|
|
877
|
-
let
|
|
878
|
-
e.template ? (["local", "cloudflare", "aws-sst"].includes(e.template) || (console.error(`❌ Invalid template: ${e.template}`), console.error("Valid options: local, cloudflare, aws-sst"), process.exit(1)),
|
|
876
|
+
a.existsSync(t) && (console.error(`❌ Project "${n}" already exists.`), process.exit(1));
|
|
877
|
+
let s;
|
|
878
|
+
e.template ? (["local", "cloudflare", "aws-sst"].includes(e.template) || (console.error(`❌ Invalid template: ${e.template}`), console.error("Valid options: local, cloudflare, aws-sst"), process.exit(1)), s = e.template, console.log(`Using template: ${p[s].name}`)) : s = (await u.prompt([
|
|
879
879
|
{
|
|
880
880
|
type: "list",
|
|
881
881
|
name: "setupType",
|
|
@@ -918,8 +918,8 @@ I.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
918
918
|
);
|
|
919
919
|
const C = e.workspace || !1;
|
|
920
920
|
C && console.log("Workspace mode: enabled (using workspace:* dependencies)");
|
|
921
|
-
const y = p[
|
|
922
|
-
|
|
921
|
+
const y = p[s];
|
|
922
|
+
a.mkdirSync(t, { recursive: !0 }), a.writeFileSync(
|
|
923
923
|
l.join(t, "package.json"),
|
|
924
924
|
JSON.stringify(y.packageJson(n, c, g, C), null, 2)
|
|
925
925
|
);
|
|
@@ -927,33 +927,33 @@ I.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
927
927
|
import.meta.url.replace("file://", "").replace("/create-authhero.js", ""),
|
|
928
928
|
b
|
|
929
929
|
);
|
|
930
|
-
if (
|
|
930
|
+
if (a.existsSync(k) ? E(k, t) : (console.error(`❌ Template directory not found: ${k}`), process.exit(1)), s === "cloudflare" && q(t, c), s === "cloudflare") {
|
|
931
931
|
const i = l.join(t, "wrangler.toml"), d = l.join(t, "wrangler.local.toml");
|
|
932
|
-
|
|
932
|
+
a.existsSync(i) && a.copyFileSync(i, d);
|
|
933
933
|
const m = l.join(t, ".dev.vars.example"), f = l.join(t, ".dev.vars");
|
|
934
|
-
|
|
934
|
+
a.existsSync(m) && a.copyFileSync(m, f), console.log(
|
|
935
935
|
"📁 Created wrangler.local.toml and .dev.vars for local development"
|
|
936
936
|
);
|
|
937
937
|
}
|
|
938
|
-
let
|
|
939
|
-
if (
|
|
938
|
+
let S = !1;
|
|
939
|
+
if (s === "cloudflare" && (e.githubCi !== void 0 ? (S = e.githubCi, S && console.log("Including GitHub CI workflows with semantic versioning")) : r || (S = (await u.prompt([
|
|
940
940
|
{
|
|
941
941
|
type: "confirm",
|
|
942
942
|
name: "includeGithubCi",
|
|
943
943
|
message: "Would you like to include GitHub CI with semantic versioning?",
|
|
944
944
|
default: !1
|
|
945
945
|
}
|
|
946
|
-
])).includeGithubCi),
|
|
947
|
-
const i =
|
|
946
|
+
])).includeGithubCi), S && (F(t), W(t))), s === "local") {
|
|
947
|
+
const i = U(
|
|
948
948
|
c,
|
|
949
949
|
g,
|
|
950
950
|
w
|
|
951
951
|
);
|
|
952
|
-
|
|
953
|
-
const d =
|
|
954
|
-
|
|
952
|
+
a.writeFileSync(l.join(t, "src/seed.ts"), i);
|
|
953
|
+
const d = O(c);
|
|
954
|
+
a.writeFileSync(l.join(t, "src/app.ts"), d);
|
|
955
955
|
}
|
|
956
|
-
if (
|
|
956
|
+
if (s === "aws-sst" && H(t, c), g) {
|
|
957
957
|
const i = {
|
|
958
958
|
alias: w,
|
|
959
959
|
description: "AuthHero Conformance Test",
|
|
@@ -972,7 +972,7 @@ I.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
972
972
|
resourceUrl: "http://host.docker.internal:3000/userinfo"
|
|
973
973
|
}
|
|
974
974
|
};
|
|
975
|
-
|
|
975
|
+
a.writeFileSync(
|
|
976
976
|
l.join(t, "conformance-config.json"),
|
|
977
977
|
JSON.stringify(i, null, 2)
|
|
978
978
|
), console.log(
|
|
@@ -1015,11 +1015,11 @@ I.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
1015
1015
|
`);
|
|
1016
1016
|
try {
|
|
1017
1017
|
const d = i === "pnpm" ? "pnpm install --ignore-workspace" : `${i} install`;
|
|
1018
|
-
if (await
|
|
1018
|
+
if (await A(d, t), s === "local" && (console.log(`
|
|
1019
1019
|
🔧 Building native modules...
|
|
1020
|
-
`), await
|
|
1020
|
+
`), await A("npm rebuild better-sqlite3", t)), console.log(`
|
|
1021
1021
|
✅ Dependencies installed successfully!
|
|
1022
|
-
`),
|
|
1022
|
+
`), s === "local" || s === "cloudflare") {
|
|
1023
1023
|
let f;
|
|
1024
1024
|
if (e.skipMigrate && e.skipSeed ? f = !1 : r ? f = !e.skipMigrate || !e.skipSeed : f = (await u.prompt([
|
|
1025
1025
|
{
|
|
@@ -1049,16 +1049,16 @@ I.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
1049
1049
|
}
|
|
1050
1050
|
]), e.skipMigrate || (console.log(`
|
|
1051
1051
|
🔄 Running migrations...
|
|
1052
|
-
`), await
|
|
1052
|
+
`), await A(`${i} run migrate`, t)), e.skipSeed || (console.log(`
|
|
1053
1053
|
🌱 Seeding database...
|
|
1054
|
-
`),
|
|
1054
|
+
`), s === "local" ? await _(
|
|
1055
1055
|
`${i} run seed`,
|
|
1056
1056
|
t,
|
|
1057
1057
|
{
|
|
1058
1058
|
ADMIN_USERNAME: h.username,
|
|
1059
1059
|
ADMIN_PASSWORD: h.password
|
|
1060
1060
|
}
|
|
1061
|
-
) : await
|
|
1061
|
+
) : await _(
|
|
1062
1062
|
`${i} run seed:local`,
|
|
1063
1063
|
t,
|
|
1064
1064
|
{
|
|
@@ -1076,22 +1076,22 @@ I.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
1076
1076
|
message: "Would you like to start the development server?",
|
|
1077
1077
|
default: !0
|
|
1078
1078
|
}
|
|
1079
|
-
])).shouldStart, m && (
|
|
1080
|
-
`), await
|
|
1079
|
+
])).shouldStart, m && (s === "cloudflare" ? x(c) : s === "aws-sst" ? D(c) : N(c), console.log(`🚀 Starting development server...
|
|
1080
|
+
`), await A(`${i} run dev`, t)), r && !m && (console.log(`
|
|
1081
1081
|
✅ Setup complete!`), console.log(`
|
|
1082
|
-
To start the development server:`), console.log(` cd ${n}`), console.log(" npm run dev"),
|
|
1082
|
+
To start the development server:`), console.log(` cd ${n}`), console.log(" npm run dev"), s === "cloudflare" ? x(c) : s === "aws-sst" ? D(c) : N(c));
|
|
1083
1083
|
} catch (d) {
|
|
1084
1084
|
console.error(`
|
|
1085
1085
|
❌ An error occurred:`, d), process.exit(1);
|
|
1086
1086
|
}
|
|
1087
1087
|
}
|
|
1088
|
-
v || (console.log("Next steps:"), console.log(` cd ${n}`),
|
|
1088
|
+
v || (console.log("Next steps:"), console.log(` cd ${n}`), s === "local" ? (console.log(" npm install"), console.log(" npm run migrate"), console.log(
|
|
1089
1089
|
" npm run seed # defaults to admin/admin"
|
|
1090
|
-
), console.log(" npm run dev")) :
|
|
1090
|
+
), console.log(" npm run dev")) : s === "cloudflare" ? (console.log(" npm install"), console.log(
|
|
1091
1091
|
" npm run migrate # or npm run db:migrate:remote for production"
|
|
1092
1092
|
), console.log(
|
|
1093
1093
|
" npm run seed # defaults to admin/admin"
|
|
1094
|
-
), console.log(" npm run dev # or npm run dev:remote for production")) :
|
|
1094
|
+
), console.log(" npm run dev # or npm run dev:remote for production")) : s === "aws-sst" && (console.log(" npm install"), console.log(" npm run dev # Deploys to AWS in development mode"), console.log(" # After deploy, get TABLE_NAME from output, then:"), console.log(
|
|
1095
1095
|
" TABLE_NAME=<your-table> npm run seed # defaults to admin/admin"
|
|
1096
1096
|
)), console.log(`
|
|
1097
1097
|
Server will be available at: https://localhost:3000`), console.log("Portal available at: https://local.authhero.net"), g && (console.log(`
|
|
@@ -1105,4 +1105,4 @@ Server will be available at: https://localhost:3000`), console.log("Portal avail
|
|
|
1105
1105
|
For more information, visit: https://authhero.net/docs
|
|
1106
1106
|
`));
|
|
1107
1107
|
});
|
|
1108
|
-
|
|
1108
|
+
T.parse(process.argv);
|