Skip to content
Draft
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
44b743a
docs: add goals/instructions for auth package
Vicentesan Feb 20, 2025
5fd1707
Merge branch 'main' into feat/auth-package
Vicentesan Feb 20, 2025
4e949ec
Merge branch 'main' into feat/auth-package
Vicentesan Feb 21, 2025
5a5fa6b
feat: add base domain file
Vicentesan Feb 21, 2025
b993399
setup initial project for vini
nicolasmelo1 Feb 21, 2025
e0926bf
feat: add auth package with password adapter example
Vicentesan Feb 26, 2025
6d4b2f6
fix typings
nicolasmelo1 Feb 26, 2025
f6f3b34
fix typings
nicolasmelo1 Feb 27, 2025
e0f4a93
fix linting
Vicentesan Mar 4, 2025
46ccd1d
fix: test example
brenoliradev Feb 21, 2025
f181ff7
chore(deps): bump drizzle-kit from 0.30.4 to 0.30.5 (#447)
dependabot[bot] Feb 26, 2025
b34a3b1
fix: serverless handler
brenoliradev Feb 24, 2025
90a7059
fix: serverless handler
brenoliradev Feb 24, 2025
6b9fe06
fix: include customServerInstance
brenoliradev Feb 24, 2025
12724af
feat: implement method 'new' to ExpressServer
brenoliradev Feb 27, 2025
45d12dc
changeset
brenoliradev Feb 27, 2025
d08dd15
feat: constructor method
brenoliradev Feb 27, 2025
79aa81e
docs: add goals/instructions for auth package
Vicentesan Feb 20, 2025
091867d
setup initial project for vini
nicolasmelo1 Feb 21, 2025
0e11b58
feat: add auth package with password adapter example
Vicentesan Feb 26, 2025
51f8b31
fix merge errors
Vicentesan Mar 6, 2025
de247e5
chore: update export/import sort
Vicentesan Mar 9, 2025
0f4ab1b
feat: add login route in example
Vicentesan Mar 10, 2025
dfc5b07
feat: add jwt adapter
Vicentesan Mar 10, 2025
b54b8c1
chore: update jwt-adapter docs
Vicentesan Mar 10, 2025
6d90b91
feat: add jwt adapter to with-auth example
Vicentesan Mar 11, 2025
d4fe3ff
chore: remove old JWT package
Vicentesan Mar 12, 2025
577e9ea
feat: add jwt adapter using Jose as inspiration
Vicentesan Mar 18, 2025
4f35c7c
chore: update readme
Vicentesan Mar 18, 2025
6e0743c
chore: update linting
Vicentesan Mar 18, 2025
b430c40
resolve merge conflicts
nicolasmelo1 Mar 23, 2025
6101cdc
feat: add salt rounds config to password adapter
Vicentesan Mar 23, 2025
4383799
feat: jwt adapter using classes
Vicentesan Mar 28, 2025
f3d1b28
update examples/with-auth/src/core/auth.ts
Vicentesan Mar 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/dull-hoops-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@palmares/express-adapter': patch
'@palmares/server': patch
---

"new" method for creating express servers
5 changes: 5 additions & 0 deletions .changeset/slow-hairs-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@palmares/server': patch
---

getAllRouters passing options at incorrect position
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const config = tseslint.config({
...prettier,
...javascript,
...typescript,
...imports
...imports,
'ts/no-namespace': 'off'
}
});

Expand Down
7 changes: 7 additions & 0 deletions examples/server-express-only/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ export default defineSettings({
}),
handler500: async (response: Response) => {
return response;
<<<<<<< HEAD
},
})
},
},
=======
Comment on lines +59 to +64
Copy link

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unresolved merge conflict markers detected. Please resolve the conflict and remove all merge conflict markers.

Suggested change
<<<<<<< HEAD
},
})
},
},
=======

Copilot uses AI. Check for mistakes.
}
})
}
}
>>>>>>> f4a426b7f4c1ccc67afc7f0089a41b91012112c7
],
// We have just created this custom domain, and it defines our routes.
RequestsDomain,
Expand Down
19 changes: 19 additions & 0 deletions examples/with-auth/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: with-auth

services:
db:
container_name: with-auth_db
image: bitnami/postgresql:latest
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: POSTGRES_DB
POSTGRESQL_REPLICATION_USE_PASSFILE: "no"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./priv/init-db.sh:/docker-entrypoint-initdb.d/init-db.sh
ports:
- 5432:5432

volumes:
postgres_data:
11 changes: 11 additions & 0 deletions examples/with-auth/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'drizzle-kit';
import { env } from './src/env';

export default defineConfig({
schema: 'drizzle/schemas',
out: 'drizzle/migrations',
dialect: 'postgresql',
dbCredentials: {
url: env.DATABASE_URL
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE "users" (
"id" uuid PRIMARY KEY NOT NULL,
"first_name" varchar(255) NOT NULL,
"last_name" varchar(255) NOT NULL,
"email" text,
"password" text NOT NULL,
CONSTRAINT "users_id_unique" UNIQUE("id"),
CONSTRAINT "users_email_unique" UNIQUE("email")
);
77 changes: 77 additions & 0 deletions examples/with-auth/drizzle/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"id": "0c57587a-46ae-47d0-ab01-fb42b01f4a6c",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.users": {
"name": "users",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true
},
"first_name": {
"name": "first_name",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"last_name": {
"name": "last_name",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": false
},
"password": {
"name": "password",
"type": "text",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"users_id_unique": {
"name": "users_id_unique",
"nullsNotDistinct": false,
"columns": [
"id"
]
},
"users_email_unique": {
"name": "users_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
13 changes: 13 additions & 0 deletions examples/with-auth/drizzle/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1741633229271,
"tag": "0000_initial_db_structure",
"breakpoints": true
}
]
}
12 changes: 12 additions & 0 deletions examples/with-auth/drizzle/schemas
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** Automatically generated by @palmares/drizzle-engine on 2025-03-10T18:54:40.648Z */

import * as d from '@palmares/drizzle-engine/pg-core';

export const users = d.pgTable('users', {
id: d.uuid('id').primaryKey().notNull().unique(),
firstName: d.varchar('first_name', { length: 255 }).notNull(),
lastName: d.varchar('last_name', { length: 255 }).notNull(),
email: d.text('email').unique(),
password: d.text('password').notNull()
});

10 changes: 10 additions & 0 deletions examples/with-auth/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import config from '../../eslint.config.js';

/** @type {import('eslint').Linter.RulesRecord} */
const configs = [{
...config[0],
name: '@palmares/auth',
files: ['src/**/*.ts',],
}];

export default configs;
5 changes: 5 additions & 0 deletions examples/with-auth/manage.drizzle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Commands } from '@palmares/core';

import settings from './src/settings';

Commands.handleCommands(settings, process.argv.slice(2));
4 changes: 4 additions & 0 deletions examples/with-auth/manage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Commands } from '@palmares/core';
import settings from './src/settings';

Commands.handleCommands(settings, process.argv.slice(2));
47 changes: 47 additions & 0 deletions examples/with-auth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@examples/with-auth",
"version": "0.0.0",
"description": "Tests the auth package",
"keywords": [
"palmares",
"with",
"auth"
],
"homepage": "https://github.com/palmaresHQ/palmares#readme",
"bugs": {
"url": "https://github.com/palmaresHQ/palmares/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/palmaresHQ/palmares.git"
},
"license": "MIT",
"author": "Vicente Sanchez",
"type": "module",
"main": "manage.ts",
"scripts": {
"dev": "tsx watch --env-file=.env manage.ts runserver",
"db:generate": "drizzle-kit generate --name",
"db:migrate": "tsx --env-file=.env manage.drizzle.ts drizzleMigrate",
"db:load": "tsx --env-file=.env manage.drizzle.ts load-models",
"db:studio": "drizzle-kit studio"
},
"dependencies": {
"@palmares/auth": "workspace:*",
"@palmares/console-logging": "workspace:*",
"@palmares/core": "workspace:*",
"@palmares/databases": "workspace:*",
"@palmares/drizzle-engine": "workspace:*",
"@palmares/express-adapter": "workspace:*",
"@palmares/logging": "workspace:*",
"@palmares/node-std": "workspace:*",
"@palmares/password-auth": "workspace:*",
"@palmares/schemas": "workspace:*",
"@palmares/server": "workspace:*",
"@palmares/zod-schema": "workspace:*",
"@palmares/jwt-adapter": "workspace:*"
},
"devDependencies": {
"drizzle-kit": "^0.30.5"
}
}
10 changes: 10 additions & 0 deletions examples/with-auth/priv/init-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

# Run the standard entrypoint setup from Postgres
export PGPASSWORD="$POSTGRES_PASSWORD"

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE DATABASE with_auth_dev;
CREATE DATABASE with_auth_test;
EOSQL
3 changes: 3 additions & 0 deletions examples/with-auth/src/core/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { getAuth } from 'packages/auth/dist/src';

export const auth = getAuth();
51 changes: 51 additions & 0 deletions examples/with-auth/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { domain } from '@palmares/core';
import { databaseDomainModifier } from '@palmares/databases';
import { migrate } from '@palmares/drizzle-engine/node-postgres/migrator';
import * as p from '@palmares/schemas';
import { Response, path, serverDomainModifier } from '@palmares/server';
import { ZodSchemaAdapter } from '@palmares/zod-schema';

import { auth } from './auth';
import { db } from '../db';
import { getUserByEmail } from '../db/repositories/users';
import { users } from '../db/schemas';

p.setDefaultAdapter(new ZodSchemaAdapter());

export default domain('core', import.meta.dirname, {
modifiers: [serverDomainModifier, databaseDomainModifier],

commands: {
drizzleMigrate: {
description: 'Migrate the database using drizzle',
keywordArgs: undefined,
positionalArgs: undefined,
handler: () => {
migrate(db, { migrationsFolder: './drizzle/migrations' });
}
}
},

getRoutes: () =>
path('/login/password').post(async ({ body }) => {
const { email, password } = body;

const user = await getUserByEmail(email);

if (!user[0]) return Response.json({ message: 'User not found', status: 404 });

const isPasswordValid = await auth.password.validate(password, user[0].password);

if (!isPasswordValid) return Response.json({ message: 'Invalid password', status: 401 });

const token = await new auth.jwt.SignJwt({ sub: user[0].id }).sign(process.env.JWT_SECRET!);

return Response.json({ token });
}),

getModels: () => ({
users
}),

getMigrations: () => []
});
16 changes: 16 additions & 0 deletions examples/with-auth/src/db/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import DrizzleDatabaseAdapter from '@palmares/drizzle-engine';
import { drizzle as drizzleBetterPostgres } from '@palmares/drizzle-engine/node-postgres';

import * as databaseSchema from './schemas';
import { env } from '../env';

export const db = drizzleBetterPostgres(env.DATABASE_URL, {
schema: databaseSchema,
logger: env.APP_ENV !== 'prod'
});

export const databaseEngine = DrizzleDatabaseAdapter.new({
output: './drizzle',
type: 'postgres',
drizzle: db
});
23 changes: 23 additions & 0 deletions examples/with-auth/src/db/repositories/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { users } from '../schemas/users';

import type { InferModel } from '@palmares/databases';

export async function createUser(data: InferModel<typeof users, 'create'>) {
return await users.default.set((qs) => qs.data(data));
}

export async function getUserByEmail(email: string) {
return await users.default.get((qs) => qs.where({ email }));
}

export async function getUserById(id: string) {
return await users.default.get((qs) => qs.where({ id }));
}

export async function updateUser(id: string, data: InferModel<typeof users, 'update'>) {
return await users.default.set((qs) => qs.where({ id }).data(data));
}

export async function deleteUser(id: string) {
return await users.default.remove((qs) => qs.where({ id }));
}
1 change: 1 addition & 0 deletions examples/with-auth/src/db/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './users';
11 changes: 11 additions & 0 deletions examples/with-auth/src/db/schemas/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Manager, define, fields } from '@palmares/databases';

export const users = define('users', {
fields: {
id: fields.uuid().primaryKey().unique(),
firstName: fields.char({ maxLen: 255 }),
lastName: fields.char({ maxLen: 255 }),
email: fields.text().unique(),
password: fields.text()
}
});
14 changes: 14 additions & 0 deletions examples/with-auth/src/env/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { z } from '@palmares/zod-schema';

/**
* here im not using directly @palmares/schemas cuz it requeries
* use of async functions and drizzle does not support top-level await
* */

const envSchema = z.object({
APP_ENV: z.enum(['dev', 'prod', 'test']).default('dev'),
DATABASE_URL: z.string(),
JWT_SECRET: z.string()
});

export const env = envSchema.parse(process.env);
Loading