sentri 1.0.0 → 1.0.2
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/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +59 -0
- package/dist/cli.js.map +1 -0
- package/package.json +14 -3
- package/templates/schema.prisma +56 -0
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync, copyFileSync, mkdirSync } from 'fs';
|
|
3
|
+
import { join, dirname } from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const COMMANDS = ['init'];
|
|
7
|
+
function help() {
|
|
8
|
+
console.log(`
|
|
9
|
+
sentri — auth/authorization library for Express
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
npx sentri <command>
|
|
13
|
+
|
|
14
|
+
Commands:
|
|
15
|
+
init Copy the Prisma schema template to prisma/schema.prisma
|
|
16
|
+
`);
|
|
17
|
+
}
|
|
18
|
+
function init() {
|
|
19
|
+
const src = join(__dirname, '..', 'templates', 'schema.prisma');
|
|
20
|
+
const dest = join(process.cwd(), 'prisma', 'schema.prisma');
|
|
21
|
+
if (!existsSync(src)) {
|
|
22
|
+
console.error('Error: template file not found. Try reinstalling sentri.');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
if (existsSync(dest)) {
|
|
26
|
+
console.error(`Error: prisma/schema.prisma already exists. Remove it first if you want to reset.`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
30
|
+
copyFileSync(src, dest);
|
|
31
|
+
console.log(`Created prisma/schema.prisma`);
|
|
32
|
+
console.log(`
|
|
33
|
+
Next steps:
|
|
34
|
+
1. Edit prisma/schema.prisma
|
|
35
|
+
— change @map("email") on the identifier field to match your column name
|
|
36
|
+
|
|
37
|
+
2. Set DATABASE_URL in your .env file
|
|
38
|
+
|
|
39
|
+
3. Run: npx prisma migrate dev
|
|
40
|
+
Run: npx prisma generate
|
|
41
|
+
`);
|
|
42
|
+
}
|
|
43
|
+
const [, , command, ...args] = process.argv;
|
|
44
|
+
if (!command || command === '--help' || command === '-h') {
|
|
45
|
+
help();
|
|
46
|
+
process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
if (!COMMANDS.includes(command)) {
|
|
49
|
+
console.error(`Unknown command: ${command}`);
|
|
50
|
+
help();
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
54
|
+
help();
|
|
55
|
+
process.exit(0);
|
|
56
|
+
}
|
|
57
|
+
if (command === 'init')
|
|
58
|
+
init();
|
|
59
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D,MAAM,QAAQ,GAAG,CAAC,MAAM,CAAU,CAAC;AAGnC,SAAS,IAAI;IACX,OAAO,CAAC,GAAG,CAAC;;;;;;;;CAQb,CAAC,CAAC;AACH,CAAC;AAED,SAAS,IAAI;IACX,MAA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ClB,CAAC;AAED,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IACnD,IAAI,EAAE,CAAC;IACP,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,OAAO,KAAK,MAAM;IAAE,IAAI,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sentri",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Personal auth/authorization library for Express + Postgres",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,13 +11,24 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"sentri": "./dist/cli.js"
|
|
16
|
+
},
|
|
14
17
|
"files": [
|
|
15
|
-
"dist"
|
|
18
|
+
"dist",
|
|
19
|
+
"templates"
|
|
16
20
|
],
|
|
17
21
|
"scripts": {
|
|
18
22
|
"build": "tsc"
|
|
19
23
|
},
|
|
20
|
-
"keywords": [
|
|
24
|
+
"keywords": [
|
|
25
|
+
"auth",
|
|
26
|
+
"authentication",
|
|
27
|
+
"authorization",
|
|
28
|
+
"express",
|
|
29
|
+
"jwt",
|
|
30
|
+
"bcrypt"
|
|
31
|
+
],
|
|
21
32
|
"author": "rizzzdev",
|
|
22
33
|
"license": "ISC",
|
|
23
34
|
"devDependencies": {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// sentri — Prisma schema template (Prisma v7+)
|
|
2
|
+
// Run `npx sentri init` to copy this file to your project.
|
|
3
|
+
//
|
|
4
|
+
// Field mapping: library uses `identifier` internally, but your DB column
|
|
5
|
+
// can be named anything — adjust the @map(...) values below to match
|
|
6
|
+
// your existing schema, or leave them as-is for a fresh project.
|
|
7
|
+
//
|
|
8
|
+
// Database and generator config lives in prisma.config.ts (Prisma v7+).
|
|
9
|
+
|
|
10
|
+
model User {
|
|
11
|
+
id String @id @default(cuid()) @map("id")
|
|
12
|
+
// Change @map("email") to match your column name:
|
|
13
|
+
// @map("email") — login via email
|
|
14
|
+
// @map("username") — login via username
|
|
15
|
+
// @map("phone") — login via phone number
|
|
16
|
+
identifier String @unique @map("email")
|
|
17
|
+
passwordHash String @map("password_hash")
|
|
18
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
19
|
+
updatedAt DateTime @updatedAt @map("updated_at")
|
|
20
|
+
|
|
21
|
+
userRoles UserRole[]
|
|
22
|
+
sessions Session[]
|
|
23
|
+
|
|
24
|
+
@@map("users")
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
model Role {
|
|
28
|
+
id String @id @default(cuid()) @map("id")
|
|
29
|
+
name String @unique @map("name")
|
|
30
|
+
|
|
31
|
+
userRoles UserRole[]
|
|
32
|
+
|
|
33
|
+
@@map("roles")
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
model UserRole {
|
|
37
|
+
userId String @map("user_id")
|
|
38
|
+
roleId String @map("role_id")
|
|
39
|
+
|
|
40
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
41
|
+
role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
|
|
42
|
+
|
|
43
|
+
@@id([userId, roleId])
|
|
44
|
+
@@map("user_roles")
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
model Session {
|
|
48
|
+
id String @id @default(cuid()) @map("id")
|
|
49
|
+
userId String @map("user_id")
|
|
50
|
+
expiresAt DateTime @map("expires_at")
|
|
51
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
52
|
+
|
|
53
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
54
|
+
|
|
55
|
+
@@map("sessions")
|
|
56
|
+
}
|