create-authhero 0.47.2 → 0.48.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/aws-sst/src/index.ts +1 -1
- package/dist/aws-sst/sst.config.ts +1 -1
- package/dist/create-authhero.js +11 -13
- package/dist/local/src/index.ts +5 -8
- package/dist/local/src/migrate.ts +11 -10
- package/dist/proxy/README.md +34 -20
- package/package.json +6 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { handle } from "hono/aws-lambda";
|
|
2
2
|
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
3
3
|
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
4
|
-
import createAdapters from "@authhero/aws";
|
|
4
|
+
import createAdapters from "@authhero/aws-adapter";
|
|
5
5
|
import {
|
|
6
6
|
DataAdapters,
|
|
7
7
|
createEncryptedDataAdapter,
|
package/dist/create-authhero.js
CHANGED
|
@@ -30,7 +30,7 @@ var c = new e(), l = {
|
|
|
30
30
|
decrypt: "node --env-file=.env scripts/decrypt-field.mjs"
|
|
31
31
|
},
|
|
32
32
|
dependencies: {
|
|
33
|
-
"@authhero/
|
|
33
|
+
"@authhero/drizzle": a,
|
|
34
34
|
...i && { "@authhero/admin": a },
|
|
35
35
|
"@authhero/widget": a,
|
|
36
36
|
"@hono/swagger-ui": "^0.6.0",
|
|
@@ -38,8 +38,8 @@ var c = new e(), l = {
|
|
|
38
38
|
"@hono/node-server": "latest",
|
|
39
39
|
authhero: a,
|
|
40
40
|
"better-sqlite3": "latest",
|
|
41
|
+
"drizzle-orm": "^0.44.0",
|
|
41
42
|
hono: "^4.12.0",
|
|
42
|
-
kysely: "latest",
|
|
43
43
|
...t && { "@authhero/multi-tenancy": a },
|
|
44
44
|
...n && { bcryptjs: "latest" }
|
|
45
45
|
},
|
|
@@ -267,7 +267,7 @@ var c = new e(), l = {
|
|
|
267
267
|
decrypt: "node --env-file=.env scripts/decrypt-field.mjs"
|
|
268
268
|
},
|
|
269
269
|
dependencies: {
|
|
270
|
-
"@authhero/aws": a,
|
|
270
|
+
"@authhero/aws-adapter": a,
|
|
271
271
|
...i && { "@authhero/admin": a },
|
|
272
272
|
"@authhero/widget": a,
|
|
273
273
|
"@aws-sdk/client-dynamodb": "^3.0.0",
|
|
@@ -441,9 +441,10 @@ function d(e, t = !1, n = "authhero-local", r) {
|
|
|
441
441
|
}
|
|
442
442
|
}
|
|
443
443
|
` : "";
|
|
444
|
-
return `import
|
|
445
|
-
import
|
|
446
|
-
import createAdapters from "@authhero/
|
|
444
|
+
return `import Database from "better-sqlite3";
|
|
445
|
+
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
446
|
+
import createAdapters from "@authhero/drizzle";
|
|
447
|
+
import * as schema from "@authhero/drizzle/schema/sqlite";
|
|
447
448
|
import { seed, createEncryptedDataAdapter, loadEncryptionKey${t ? ", USERNAME_PASSWORD_PROVIDER" : ""} } from "authhero";
|
|
448
449
|
|
|
449
450
|
interface ExtraClient {
|
|
@@ -493,11 +494,8 @@ async function main() {
|
|
|
493
494
|
? JSON.parse(userProfileJson)
|
|
494
495
|
: {};
|
|
495
496
|
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
const db = new Kysely<any>({ dialect });
|
|
497
|
+
const sqlite = new Database("db.sqlite");
|
|
498
|
+
const db = drizzle(sqlite, { schema });
|
|
501
499
|
let adapters = createAdapters(db);
|
|
502
500
|
|
|
503
501
|
// Match the server: encrypt seeded secrets at rest when a key is configured.
|
|
@@ -544,7 +542,7 @@ async function main() {
|
|
|
544
542
|
console.log(\`✅ Updated profile of user "\${seedResult.username}"\`);
|
|
545
543
|
}
|
|
546
544
|
${f}
|
|
547
|
-
|
|
545
|
+
sqlite.close();
|
|
548
546
|
}
|
|
549
547
|
|
|
550
548
|
main().catch((err) => {
|
|
@@ -837,7 +835,7 @@ function h(e) {
|
|
|
837
835
|
function g(e) {
|
|
838
836
|
return `import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
839
837
|
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
840
|
-
import createAdapters from "@authhero/aws";
|
|
838
|
+
import createAdapters from "@authhero/aws-adapter";
|
|
841
839
|
import { seed, createEncryptedDataAdapter, loadEncryptionKey } from "authhero";
|
|
842
840
|
|
|
843
841
|
async function main() {
|
package/dist/local/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { serve } from "@hono/node-server";
|
|
2
|
-
import { SqliteDialect } from "kysely";
|
|
3
|
-
import { Kysely } from "kysely";
|
|
4
2
|
import Database from "better-sqlite3";
|
|
5
|
-
import
|
|
3
|
+
import { drizzle, BetterSQLite3Database } from "drizzle-orm/better-sqlite3";
|
|
4
|
+
import createAdapters from "@authhero/drizzle";
|
|
5
|
+
import * as schema from "@authhero/drizzle/schema/sqlite";
|
|
6
6
|
import { createEncryptedDataAdapter, loadEncryptionKey } from "authhero";
|
|
7
7
|
import createApp from "./app";
|
|
8
8
|
import fs from "fs";
|
|
@@ -85,12 +85,9 @@ function ensureCertificates() {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// Initialize SQLite database
|
|
88
|
-
let db:
|
|
88
|
+
let db: BetterSQLite3Database<typeof schema>;
|
|
89
89
|
try {
|
|
90
|
-
|
|
91
|
-
database: new Database("db.sqlite"),
|
|
92
|
-
});
|
|
93
|
-
db = new Kysely<any>({ dialect });
|
|
90
|
+
db = drizzle(new Database("db.sqlite"), { schema });
|
|
94
91
|
} catch (error) {
|
|
95
92
|
console.error("❌ Failed to initialize database:");
|
|
96
93
|
console.error(
|
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import { SqliteDialect, Kysely } from "kysely";
|
|
2
1
|
import Database from "better-sqlite3";
|
|
3
|
-
import {
|
|
2
|
+
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
3
|
+
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
});
|
|
5
|
+
// Migrations are pre-generated and shipped with the @authhero/drizzle package.
|
|
6
|
+
// The schema is managed by AuthHero — do not generate your own migrations.
|
|
7
|
+
const migrationsFolder = "node_modules/@authhero/drizzle/drizzle";
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
function migrateDb() {
|
|
10
|
+
const sqlite = new Database("db.sqlite");
|
|
11
|
+
const db = drizzle(sqlite);
|
|
11
12
|
|
|
12
13
|
console.log("Running migrations...");
|
|
13
14
|
|
|
14
15
|
try {
|
|
15
|
-
|
|
16
|
+
migrate(db, { migrationsFolder });
|
|
16
17
|
console.log("✅ All migrations completed successfully");
|
|
17
18
|
} catch (error) {
|
|
18
19
|
console.error("Migration failed:", error);
|
|
19
20
|
process.exit(1);
|
|
20
21
|
} finally {
|
|
21
|
-
|
|
22
|
+
sqlite.close();
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
migrateDb();
|
package/dist/proxy/README.md
CHANGED
|
@@ -29,34 +29,35 @@ export const proxyConfig: StaticProxyAdapterOptions = {
|
|
|
29
29
|
|
|
30
30
|
The proxy reads its routes through a `ProxyDataAdapter`. Three implementations are common:
|
|
31
31
|
|
|
32
|
-
| Adapter
|
|
33
|
-
|
|
|
34
|
-
| **Static** (default)
|
|
35
|
-
| **Database**
|
|
32
|
+
| Adapter | Best for | Notes |
|
|
33
|
+
| ------------------------- | -------------------------------------------------- | -------------------------------------------------------------------------- |
|
|
34
|
+
| **Static** (default) | Local dev, small fixed deployments | Routes baked into the worker bundle; re-deploy to change them. |
|
|
35
|
+
| **Database** | Same-process or co-located deployments | Reads directly from the proxy_routes table that authhero writes to. |
|
|
36
36
|
| **HTTP / management API** | Geographically distributed proxies, hosted Workers | Calls `/api/v2/proxy-routes` on your authhero server with a service token. |
|
|
37
37
|
|
|
38
38
|
The authhero server exposes the management API (`/api/v2/proxy-routes`) and creates the underlying table automatically once the standard adapter migrations have run — see the `local` template's [src/index.ts](../local/src/index.ts).
|
|
39
39
|
|
|
40
|
-
### Database-backed (
|
|
40
|
+
### Database-backed (Drizzle)
|
|
41
41
|
|
|
42
|
-
Add the adapter and
|
|
42
|
+
Add the adapter and drizzle-orm, then swap the data line:
|
|
43
43
|
|
|
44
44
|
```bash
|
|
45
|
-
npm install @authhero/
|
|
45
|
+
npm install @authhero/drizzle drizzle-orm
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
```ts
|
|
49
|
-
import {
|
|
49
|
+
import { drizzle } from "drizzle-orm/d1";
|
|
50
50
|
import { createProxyApp } from "@authhero/proxy";
|
|
51
|
-
import { createProxyDataAdapter } from "@authhero/
|
|
51
|
+
import { createProxyDataAdapter } from "@authhero/drizzle";
|
|
52
|
+
import * as schema from "@authhero/drizzle/schema/sqlite";
|
|
52
53
|
|
|
53
|
-
const db =
|
|
54
|
+
const db = drizzle(env.AUTH_DB, { schema });
|
|
54
55
|
const app = createProxyApp({
|
|
55
56
|
data: createProxyDataAdapter(db),
|
|
56
57
|
});
|
|
57
58
|
```
|
|
58
59
|
|
|
59
|
-
Cloudflare Workers
|
|
60
|
+
On Cloudflare Workers this reads from the same D1 database your authhero worker uses. For a local Node process, use `drizzle-orm/better-sqlite3` pointing at the same `db.sqlite` your authhero server uses. (If your routes live in MySQL/Postgres, `@authhero/kysely-adapter` exposes the same `createProxyDataAdapter` for Kysely dialects.)
|
|
60
61
|
|
|
61
62
|
### HTTP-backed (management API)
|
|
62
63
|
|
|
@@ -87,7 +88,7 @@ interface Env {
|
|
|
87
88
|
|
|
88
89
|
function createHttpProxyAdapter(env: Env): ProxyDataAdapter {
|
|
89
90
|
const headers = {
|
|
90
|
-
|
|
91
|
+
authorization: `Bearer ${env.AUTHHERO_SERVICE_TOKEN}`,
|
|
91
92
|
"tenant-id": env.AUTHHERO_TENANT_ID,
|
|
92
93
|
};
|
|
93
94
|
|
|
@@ -101,16 +102,29 @@ function createHttpProxyAdapter(env: Env): ProxyDataAdapter {
|
|
|
101
102
|
// The proxy data plane only needs resolveHost; the CRUD methods on
|
|
102
103
|
// proxyRoutes stay unused (writes always go through authhero directly).
|
|
103
104
|
proxyRoutes: {
|
|
104
|
-
list: () => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
list: () => {
|
|
106
|
+
throw new Error("read-only proxy adapter");
|
|
107
|
+
},
|
|
108
|
+
get: () => {
|
|
109
|
+
throw new Error("read-only proxy adapter");
|
|
110
|
+
},
|
|
111
|
+
create: () => {
|
|
112
|
+
throw new Error("read-only proxy adapter");
|
|
113
|
+
},
|
|
114
|
+
update: () => {
|
|
115
|
+
throw new Error("read-only proxy adapter");
|
|
116
|
+
},
|
|
117
|
+
remove: () => {
|
|
118
|
+
throw new Error("read-only proxy adapter");
|
|
119
|
+
},
|
|
109
120
|
},
|
|
110
121
|
async resolveHost(host): Promise<ResolvedHost | null> {
|
|
111
|
-
const domains = await api<{
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
const domains = await api<{
|
|
123
|
+
custom_domains: Array<{
|
|
124
|
+
custom_domain_id: string;
|
|
125
|
+
domain: string;
|
|
126
|
+
}>;
|
|
127
|
+
}>("/api/v2/custom-domains");
|
|
114
128
|
const match = domains.custom_domains.find((d) => d.domain === host);
|
|
115
129
|
if (!match) return null;
|
|
116
130
|
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/markusahlstrand/authhero"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.48.0",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "dist/create-authhero.js",
|
|
11
11
|
"bin": {
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"@types/node": "^20.19.41",
|
|
23
23
|
"tsx": "^4.22.3",
|
|
24
24
|
"typescript": "^5.5.2",
|
|
25
|
-
"vite": "^8.0.14"
|
|
25
|
+
"vite": "^8.0.14",
|
|
26
|
+
"vitest": "^4.1.7"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
29
|
"commander": "^12.1.0",
|
|
@@ -31,6 +32,8 @@
|
|
|
31
32
|
"scripts": {
|
|
32
33
|
"build": "tsc && vite build",
|
|
33
34
|
"dev": "pnpm build && rm -rf auth-server && node dist/create-authhero.js auth-server --workspace --skip-install --skip-start && pnpm -w install --force --filter auth-server... && pnpm --filter auth-server migrate && pnpm --filter auth-server dev",
|
|
34
|
-
"start": "pnpm build && node dist/create-authhero.js"
|
|
35
|
+
"start": "pnpm build && node dist/create-authhero.js",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"test:watch": "vitest"
|
|
35
38
|
}
|
|
36
39
|
}
|