easywork-common-lib 1.0.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/.gitattributes +2 -0
- package/eslint.config.js +45 -0
- package/package.json +29 -0
- package/src/common/@types/typings/globals.d.ts +13 -0
- package/src/common/database/base.entity.ts +30 -0
- package/src/common/database/index.ts +1 -0
- package/src/entities/group.entity.ts +10 -0
- package/src/entities/index.ts +7 -0
- package/src/entities/otp-log.entity.ts +20 -0
- package/src/entities/permission.entity.ts +20 -0
- package/src/entities/profile.entity.ts +24 -0
- package/src/entities/protocol.entity.ts +24 -0
- package/src/entities/refresh-token.entity.ts +24 -0
- package/src/entities/role.entity.ts +13 -0
- package/src/entities/user.entity.ts +54 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +29 -0
package/.gitattributes
ADDED
package/eslint.config.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const rubiin = require("@antfu/eslint-config").default;
|
|
2
|
+
|
|
3
|
+
module.exports = rubiin({
|
|
4
|
+
stylistic: {
|
|
5
|
+
semi: true,
|
|
6
|
+
quotes: "double",
|
|
7
|
+
}, // enable stylistic rules
|
|
8
|
+
yaml: true, // enable yaml rules,
|
|
9
|
+
jsonc: true, // enable jsonc rules
|
|
10
|
+
markdown: false, // enable markdown rules
|
|
11
|
+
gitignore: true, // enable gitignore rules,
|
|
12
|
+
typescript: {
|
|
13
|
+
tsconfigPath: "tsconfig.json",
|
|
14
|
+
},
|
|
15
|
+
overrides: {
|
|
16
|
+
test: {
|
|
17
|
+
"ts/unbound-method": "off",
|
|
18
|
+
},
|
|
19
|
+
typescript: {
|
|
20
|
+
"ts/no-misused-promises": [
|
|
21
|
+
"error",
|
|
22
|
+
{
|
|
23
|
+
checksVoidReturn: false,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
"ts/no-floating-promises": [
|
|
27
|
+
"error",
|
|
28
|
+
{
|
|
29
|
+
ignoreIIFE: true,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
"unicorn/prefer-top-level-await": "off",
|
|
33
|
+
"unicorn/prevent-abbreviations": [
|
|
34
|
+
"error",
|
|
35
|
+
{
|
|
36
|
+
ignore: ["\\.e2e*", "\\.spec*", "\\.decorator*", "\\*idx*"],
|
|
37
|
+
allowList: {
|
|
38
|
+
ProcessEnv: true,
|
|
39
|
+
UUIDParam: true,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "easywork-common-lib",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Paquete de librerías compartidas para EasyWork",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"nestjs",
|
|
12
|
+
"typeorm",
|
|
13
|
+
"shared",
|
|
14
|
+
"entities"
|
|
15
|
+
],
|
|
16
|
+
"author": "Rosmer Campos",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@nestjs/common": "^10.3.8",
|
|
20
|
+
"@nestjs/typeorm": "^10.0.2",
|
|
21
|
+
"@rubiin/tsconfig": "^1.1.2",
|
|
22
|
+
"class-transformer": "^0.5.1",
|
|
23
|
+
"class-validator": "^0.14.1",
|
|
24
|
+
"typeorm": "^0.2.45"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "^5.4.2"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NextFunction, Request, Response } from "express";
|
|
2
|
+
|
|
3
|
+
/* The `export {};` statement is used to indicate that the file is a module and exports nothing. It is
|
|
4
|
+
often used in TypeScript files that only contain type declarations or interfaces, without any actual
|
|
5
|
+
code or exports. This statement ensures that the file is treated as a module and not as a script. */
|
|
6
|
+
export {};
|
|
7
|
+
|
|
8
|
+
declare global {
|
|
9
|
+
// Using this allows is to quickly switch between express and fastify and others
|
|
10
|
+
export type NestifyRequest = Request;
|
|
11
|
+
export type NestifyResponse = Response;
|
|
12
|
+
export type NestifyNextFunction = NextFunction;
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Column,
|
|
3
|
+
CreateDateColumn,
|
|
4
|
+
DeleteDateColumn,
|
|
5
|
+
Entity,
|
|
6
|
+
BaseEntity as EntityBase,
|
|
7
|
+
PrimaryGeneratedColumn,
|
|
8
|
+
UpdateDateColumn,
|
|
9
|
+
} from "typeorm";
|
|
10
|
+
|
|
11
|
+
@Entity()
|
|
12
|
+
export abstract class BaseEntity extends EntityBase {
|
|
13
|
+
@PrimaryGeneratedColumn("uuid")
|
|
14
|
+
id?: string;
|
|
15
|
+
|
|
16
|
+
@Column({ default: true })
|
|
17
|
+
isActive?: boolean;
|
|
18
|
+
|
|
19
|
+
@Column({ default: false })
|
|
20
|
+
isDeleted?: boolean;
|
|
21
|
+
|
|
22
|
+
@CreateDateColumn()
|
|
23
|
+
createdAt?: Date;
|
|
24
|
+
|
|
25
|
+
@UpdateDateColumn()
|
|
26
|
+
updatedAt?: Date;
|
|
27
|
+
|
|
28
|
+
@DeleteDateColumn()
|
|
29
|
+
deletedAt?: Date;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./base.entity";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
|
|
2
|
+
import { BaseEntity } from "@common/database";
|
|
3
|
+
import { User } from "./user.entity";
|
|
4
|
+
|
|
5
|
+
@Entity()
|
|
6
|
+
@Index(["otpCode"], { unique: true })
|
|
7
|
+
export class OtpLog extends BaseEntity {
|
|
8
|
+
@Column({ type: "timestamp" })
|
|
9
|
+
expiresIn!: Date;
|
|
10
|
+
|
|
11
|
+
@Column({ length: 20, nullable: true })
|
|
12
|
+
otpCode?: string;
|
|
13
|
+
|
|
14
|
+
@ManyToOne(() => User, { eager: false, nullable: false })
|
|
15
|
+
@JoinColumn()
|
|
16
|
+
user!: User;
|
|
17
|
+
|
|
18
|
+
@Column({ default: false })
|
|
19
|
+
isUsed?: boolean;
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseEntity } from "@common/database";
|
|
2
|
+
import { Column, Entity, Index, JoinTable, ManyToMany } from "typeorm";
|
|
3
|
+
import { Role } from "./role.entity";
|
|
4
|
+
|
|
5
|
+
@Entity()
|
|
6
|
+
@Index(["resource", "action"], { unique: true })
|
|
7
|
+
export class Permission extends BaseEntity {
|
|
8
|
+
@Column()
|
|
9
|
+
resource: string;
|
|
10
|
+
|
|
11
|
+
@Column()
|
|
12
|
+
action: string;
|
|
13
|
+
|
|
14
|
+
@ManyToMany(() => Role, {
|
|
15
|
+
onDelete: "CASCADE",
|
|
16
|
+
onUpdate: "CASCADE",
|
|
17
|
+
})
|
|
18
|
+
@JoinTable()
|
|
19
|
+
roles?: Role[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseEntity } from "@common/database";
|
|
2
|
+
import { Column, Entity, OneToOne } from "typeorm";
|
|
3
|
+
import { User } from "./user.entity";
|
|
4
|
+
|
|
5
|
+
@Entity("user_profile")
|
|
6
|
+
export class Profile extends BaseEntity {
|
|
7
|
+
@Column()
|
|
8
|
+
firstName: string;
|
|
9
|
+
|
|
10
|
+
@Column()
|
|
11
|
+
lastName: string;
|
|
12
|
+
|
|
13
|
+
@Column({ unique: true })
|
|
14
|
+
idcard: string;
|
|
15
|
+
|
|
16
|
+
@Column({ nullable: true })
|
|
17
|
+
birthday: Date;
|
|
18
|
+
|
|
19
|
+
@OneToOne(() => User, user => user.profile, {
|
|
20
|
+
onDelete: "CASCADE",
|
|
21
|
+
onUpdate: "CASCADE",
|
|
22
|
+
})
|
|
23
|
+
user: User;
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Column, Entity } from "typeorm";
|
|
2
|
+
import { BaseEntity } from "@common/database";
|
|
3
|
+
|
|
4
|
+
// Usa este modelo para almacenar el protocolo
|
|
5
|
+
|
|
6
|
+
@Entity()
|
|
7
|
+
export class Protocol extends BaseEntity {
|
|
8
|
+
@Column()
|
|
9
|
+
loginAttemptInterval!: number;
|
|
10
|
+
|
|
11
|
+
@Column()
|
|
12
|
+
loginIntervalUnit!: string;
|
|
13
|
+
|
|
14
|
+
@Column()
|
|
15
|
+
loginMaxRetry!: number;
|
|
16
|
+
|
|
17
|
+
@Column()
|
|
18
|
+
otpExpiryInMinutes!: number;
|
|
19
|
+
|
|
20
|
+
constructor(partial?: Partial<Protocol>) {
|
|
21
|
+
super();
|
|
22
|
+
Object.assign(this, partial);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Column, Entity, ManyToOne } from "typeorm";
|
|
2
|
+
import { BaseEntity } from "@common/database";
|
|
3
|
+
import { User } from "./user.entity";
|
|
4
|
+
|
|
5
|
+
@Entity()
|
|
6
|
+
export class RefreshToken extends BaseEntity {
|
|
7
|
+
@Column()
|
|
8
|
+
expiresIn!: Date;
|
|
9
|
+
|
|
10
|
+
@ManyToOne(() => User, {
|
|
11
|
+
eager: false,
|
|
12
|
+
onDelete: "CASCADE",
|
|
13
|
+
onUpdate: "CASCADE",
|
|
14
|
+
})
|
|
15
|
+
user!: User;
|
|
16
|
+
|
|
17
|
+
@Column({ default: false })
|
|
18
|
+
isRevoked?: boolean;
|
|
19
|
+
|
|
20
|
+
constructor(partial?: Partial<RefreshToken>) {
|
|
21
|
+
super();
|
|
22
|
+
Object.assign(this, partial);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseEntity } from "@common/database";
|
|
2
|
+
import { MinLength } from "class-validator";
|
|
3
|
+
import { Column, Entity } from "typeorm";
|
|
4
|
+
|
|
5
|
+
@Entity()
|
|
6
|
+
export class Role extends BaseEntity {
|
|
7
|
+
@MinLength(3)
|
|
8
|
+
@Column({ unique: true })
|
|
9
|
+
name: string;
|
|
10
|
+
|
|
11
|
+
@Column({ default: false })
|
|
12
|
+
isDefault: boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BaseEntity } from "@common/database";
|
|
2
|
+
import { Column, Entity, JoinColumn, JoinTable, ManyToMany, OneToOne } from "typeorm";
|
|
3
|
+
import { Exclude } from "class-transformer";
|
|
4
|
+
import { Profile } from "./profile.entity";
|
|
5
|
+
import { Role } from "./role.entity";
|
|
6
|
+
|
|
7
|
+
@Entity()
|
|
8
|
+
export class User extends BaseEntity {
|
|
9
|
+
@Column({ unique: true })
|
|
10
|
+
username!: string;
|
|
11
|
+
|
|
12
|
+
@Column({ unique: true })
|
|
13
|
+
email!: string;
|
|
14
|
+
|
|
15
|
+
@Column({ type: "text" })
|
|
16
|
+
bio!: string;
|
|
17
|
+
|
|
18
|
+
@Column({ type: "text" })
|
|
19
|
+
avatar!: string;
|
|
20
|
+
|
|
21
|
+
@Exclude()
|
|
22
|
+
@Column({ type: "text" })
|
|
23
|
+
hash!: string;
|
|
24
|
+
|
|
25
|
+
@Exclude()
|
|
26
|
+
@Column({ nullable: true })
|
|
27
|
+
twoFactorSecret?: string;
|
|
28
|
+
|
|
29
|
+
@Column({ default: false })
|
|
30
|
+
isTwoFactorEnabled?: boolean;
|
|
31
|
+
|
|
32
|
+
@Column({ unique: true })
|
|
33
|
+
phone?: string;
|
|
34
|
+
|
|
35
|
+
@Column({ default: false })
|
|
36
|
+
isVerified?: boolean;
|
|
37
|
+
|
|
38
|
+
@Column({ type: "timestamp", nullable: true })
|
|
39
|
+
lastLogin?: Date;
|
|
40
|
+
|
|
41
|
+
@OneToOne(() => Profile, {
|
|
42
|
+
onDelete: "CASCADE",
|
|
43
|
+
onUpdate: "CASCADE",
|
|
44
|
+
})
|
|
45
|
+
@JoinColumn()
|
|
46
|
+
profile: Profile;
|
|
47
|
+
|
|
48
|
+
@ManyToMany(() => Role, {
|
|
49
|
+
onDelete: "CASCADE",
|
|
50
|
+
onUpdate: "CASCADE",
|
|
51
|
+
})
|
|
52
|
+
@JoinTable()
|
|
53
|
+
roles?: Role[];
|
|
54
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@rubiin/tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"removeComments": true,
|
|
7
|
+
"emitDecoratorMetadata": true,
|
|
8
|
+
"experimentalDecorators": true,
|
|
9
|
+
"allowSyntheticDefaultImports": true,
|
|
10
|
+
"target": "ES2021",
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"outDir": "./dist",
|
|
13
|
+
"baseUrl": "./src",
|
|
14
|
+
"incremental": true,
|
|
15
|
+
"strict": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"strictNullChecks": false,
|
|
18
|
+
"noImplicitAny": false,
|
|
19
|
+
"strictBindCallApply": false,
|
|
20
|
+
"forceConsistentCasingInFileNames": true,
|
|
21
|
+
"paths": {
|
|
22
|
+
"@common/*": ["./common/*"],
|
|
23
|
+
"@entities": ["./entities"]
|
|
24
|
+
},
|
|
25
|
+
"noFallthroughCasesInSwitch": false
|
|
26
|
+
},
|
|
27
|
+
"include": ["test/**/*", "src/**/*", "eslint.config.js"],
|
|
28
|
+
"typeRoots": ["./src/common/@types/typings"]
|
|
29
|
+
}
|