Restructuring the folders (#1)
Co-authored-by: mifi <badmf@mifi.dev> Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
55
.drone.yml
55
.drone.yml
@@ -7,9 +7,15 @@ workspace:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: yarn install
|
- name: yarn install
|
||||||
image: node:latest
|
image: node:20-bullseye-slim
|
||||||
|
environment:
|
||||||
|
YARN_VERSION: 3.5.0
|
||||||
commands:
|
commands:
|
||||||
|
- yarn set version stable
|
||||||
- yarn install
|
- yarn install
|
||||||
|
volumes:
|
||||||
|
- name: yarnrc
|
||||||
|
path: /drone/auth/.yarnrc.yml
|
||||||
- name: Code Style Checks
|
- name: Code Style Checks
|
||||||
image: node:latest
|
image: node:latest
|
||||||
commands:
|
commands:
|
||||||
@@ -37,6 +43,30 @@ steps:
|
|||||||
status:
|
status:
|
||||||
- success
|
- success
|
||||||
- failure
|
- failure
|
||||||
|
- name: Build
|
||||||
|
image: node:latest
|
||||||
|
commands:
|
||||||
|
- yarn build:production
|
||||||
|
- name: Send Build Status Notifications
|
||||||
|
image: plugins/webhook
|
||||||
|
settings:
|
||||||
|
urls: https://lab.mifi.dev/hooks/9p65zpagctgkmndo8nwwm4199r
|
||||||
|
content_type: application/json
|
||||||
|
template: |
|
||||||
|
{
|
||||||
|
"icon_url":"https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/apple/198/freezing-face_1f976.png",
|
||||||
|
"text": "[{{ repo.name }} - Build # {{ build.number }}] Build package {{ build.status }} {{#success build.status}}:tada:{{else}}:poop:{{/success}}",
|
||||||
|
"username":"DroneBot"
|
||||||
|
}
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- success
|
||||||
|
- failure
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: yarnrc
|
||||||
|
host:
|
||||||
|
path: /volume1/docker/.yarnrc.yml
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
@@ -54,14 +84,26 @@ workspace:
|
|||||||
path: /drone/auth
|
path: /drone/auth
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Publish NPM
|
- name: Build
|
||||||
image: node:20-alpine
|
image: node:20-bullseye-slim
|
||||||
failure: ignore
|
environment:
|
||||||
|
YARN_VERSION: 3.5.0
|
||||||
commands:
|
commands:
|
||||||
- yarn publish -t ${DRONE_TAG}
|
- yarn set version stable
|
||||||
|
- yarn install
|
||||||
|
- yarn build:production
|
||||||
|
volumes:
|
||||||
|
- name: yarnrc
|
||||||
|
path: /drone/auth/.yarnrc.yml
|
||||||
|
- name: Publish NPM
|
||||||
|
image: node:20-bullseye-slim
|
||||||
|
commands:
|
||||||
|
- yarn npm publish
|
||||||
volumes:
|
volumes:
|
||||||
- name: npmrc
|
- name: npmrc
|
||||||
path: /drone/auth/.npmrc
|
path: /drone/auth/.npmrc
|
||||||
|
- name: yarnrc
|
||||||
|
path: /drone/auth/.yarnrc.yml
|
||||||
- name: Report NPM Publish Status
|
- name: Report NPM Publish Status
|
||||||
image: plugins/webhook
|
image: plugins/webhook
|
||||||
settings:
|
settings:
|
||||||
@@ -82,6 +124,9 @@ volumes:
|
|||||||
- name: npmrc
|
- name: npmrc
|
||||||
host:
|
host:
|
||||||
path: /volume1/docker/beethoven/labs-auth/.npmrc
|
path: /volume1/docker/beethoven/labs-auth/.npmrc
|
||||||
|
- name: yarnrc
|
||||||
|
host:
|
||||||
|
path: /volume1/docker/.yarnrc.yml
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- Test Pipeline
|
- Test Pipeline
|
||||||
|
|||||||
19
.eslintrc.js
Normal file
19
.eslintrc.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/* eslint-env node */
|
||||||
|
module.exports = {
|
||||||
|
extends: [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended',
|
||||||
|
'plugin:import/errors',
|
||||||
|
'plugin:prettier/recommended',
|
||||||
|
'prettier',
|
||||||
|
],
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
plugins: ['@typescript-eslint'],
|
||||||
|
settings: {
|
||||||
|
'import/parsers': {
|
||||||
|
'@typescript-eslint/parser': ['.ts', '.tsx'],
|
||||||
|
},
|
||||||
|
'import/resolver': 'typescript',
|
||||||
|
},
|
||||||
|
root: true,
|
||||||
|
};
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -130,3 +130,6 @@ dist
|
|||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
|
# Project
|
||||||
|
lib/
|
||||||
|
|
||||||
|
|||||||
10
.npmignore
Normal file
10
.npmignore
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
.build.yarnrc.yml
|
||||||
|
.drone.yml
|
||||||
|
.eslintrc*
|
||||||
|
.prettierrc*
|
||||||
|
.yarnrc.yml
|
||||||
|
babel.config.*
|
||||||
|
jest.config.*
|
||||||
|
src
|
||||||
|
tsconfig*.json
|
||||||
|
tslint.json
|
||||||
7
.prettierrc.js
Normal file
7
.prettierrc.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
module.exports = {
|
||||||
|
parser: 'typescript',
|
||||||
|
printWidth: 120,
|
||||||
|
trailingComma: 'all',
|
||||||
|
tabWidth: 4,
|
||||||
|
singleQuote: true,
|
||||||
|
};
|
||||||
873
.yarn/releases/yarn-3.5.1.cjs
vendored
Executable file
873
.yarn/releases/yarn-3.5.1.cjs
vendored
Executable file
File diff suppressed because one or more lines are too long
@@ -1 +1,3 @@
|
|||||||
nodeLinker: node-modules
|
nodeLinker: node-modules
|
||||||
|
|
||||||
|
yarnPath: .yarn/releases/yarn-3.5.1.cjs
|
||||||
|
|||||||
16
package.json
16
package.json
@@ -1,16 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "@mifi/auth-db",
|
"name": "@mifi/auth-db",
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"author": "mifi (Mike Fitzpatrick)",
|
"author": "mifi (Mike Fitzpatrick)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"build:production": "tsc -p .",
|
"build:production": "tsc -p ./tsconfig.production.json",
|
||||||
"format": "prettier:fix && lint:fix",
|
"format": "prettier:fix && lint:fix",
|
||||||
"lint": "eslint --ext .ts,.tsx lib/",
|
"lint": "eslint --ext .ts,.tsx src/",
|
||||||
"lint:fix": "eslint --fix --ext .ts,.tsx lib/",
|
"lint:fix": "eslint --fix --ext .ts,.tsx src/",
|
||||||
"prettier": "prettier --check 'lib/**/*.ts'",
|
"prettier": "prettier --check 'src/**/*.ts'",
|
||||||
"prettier:fix": "prettier --write 'lib/**/*.ts'",
|
"prettier:fix": "prettier --write 'src/**/*.ts'",
|
||||||
"test": "jest --passWithNoTests"
|
"test": "jest --passWithNoTests"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
"prettier-eslint": "^15.0.1",
|
"prettier-eslint": "^15.0.1",
|
||||||
"prettier-eslint-cli": "^7.1.0",
|
"prettier-eslint-cli": "^7.1.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -47,5 +48,6 @@
|
|||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.mifi.dev/mifi/auth-db.git"
|
"url": "https://git.mifi.dev/mifi/auth-db.git"
|
||||||
}
|
},
|
||||||
|
"packageManager": "yarn@3.5.1"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ export const resetPasswordPost = async (token: string, password: string) => {
|
|||||||
|
|
||||||
if (parentId) {
|
if (parentId) {
|
||||||
let parent: AuthDocument;
|
let parent: AuthDocument;
|
||||||
let strategy: StrategyDocument | null = await Strategy.findOne({ parent: parentId, method: STRATEGIES.LOCAL });
|
let strategy: StrategyDocument | null = await Strategy.findOne({
|
||||||
|
parent: parentId,
|
||||||
|
method: STRATEGIES.LOCAL,
|
||||||
|
});
|
||||||
|
|
||||||
if (strategy) {
|
if (strategy) {
|
||||||
parent = await strategy.getAuthRecord();
|
parent = await strategy.getAuthRecord();
|
||||||
@@ -18,19 +18,27 @@ export const create = async ({ record, username, password }: AuthProps & { passw
|
|||||||
throw new DatabaseError('failed to create user', { err });
|
throw new DatabaseError('failed to create user', { err });
|
||||||
});
|
});
|
||||||
if (doc) {
|
if (doc) {
|
||||||
const strategy = await Strategy.create({ method: STRATEGIES.LOCAL, key: password, parent: doc._id }).catch(
|
const strategy = await Strategy.create({
|
||||||
(err) => {
|
method: STRATEGIES.LOCAL,
|
||||||
throw new DatabaseError('failed to create strategy', { err });
|
key: password,
|
||||||
},
|
parent: doc._id,
|
||||||
);
|
}).catch((err) => {
|
||||||
|
throw new DatabaseError('failed to create strategy', { err });
|
||||||
|
});
|
||||||
if (strategy) {
|
if (strategy) {
|
||||||
doc.strategies.push(strategy._id);
|
doc.strategies.push(strategy._id);
|
||||||
await doc.save();
|
await doc.save();
|
||||||
Log.add(doc._id, Action.CREATE);
|
Log.add(doc._id, Action.CREATE);
|
||||||
return { doc, token: REQUIRE_VERIFICATION && (await Token.getToken(TokenType.VERIFICATION, doc._id)) };
|
return {
|
||||||
|
doc,
|
||||||
|
token: REQUIRE_VERIFICATION && (await Token.getToken(TokenType.VERIFICATION, doc._id)),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
await doc.deleteOne((err) => {
|
await doc.deleteOne((err) => {
|
||||||
throw new DatabaseError('failed to remove invalid auth record', { err, doc });
|
throw new DatabaseError('failed to remove invalid auth record', {
|
||||||
|
err,
|
||||||
|
doc,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -5,7 +5,12 @@ import { Status } from '../constants/auth';
|
|||||||
import { Action } from '../constants/action';
|
import { Action } from '../constants/action';
|
||||||
|
|
||||||
export const deleteById = async (id: StringSchemaDefinition) => {
|
export const deleteById = async (id: StringSchemaDefinition) => {
|
||||||
if (await Auth.findByIdAndUpdate(id, { status: Status.DELETED, strategies: [] }).catch()) {
|
if (
|
||||||
|
await Auth.findByIdAndUpdate(id, {
|
||||||
|
status: Status.DELETED,
|
||||||
|
strategies: [],
|
||||||
|
}).catch()
|
||||||
|
) {
|
||||||
await Strategy.deleteMany({ parent: id });
|
await Strategy.deleteMany({ parent: id });
|
||||||
await Token.deleteMany({ auth: id });
|
await Token.deleteMany({ auth: id });
|
||||||
Log.add(id, Action.DELETE);
|
Log.add(id, Action.DELETE);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { FilterQuery } from 'mongoose';
|
import { FilterQuery } from 'mongoose';
|
||||||
|
|
||||||
import { Auth } from '..';
|
import { Auth } from '../model/auth';
|
||||||
import { Status } from '../constants/auth';
|
import { Status } from '../constants/auth';
|
||||||
import { AuthDocument } from '../schema/auth';
|
import { AuthDocument } from '../schema/auth';
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Types } from 'mongoose';
|
import { Types } from 'mongoose';
|
||||||
|
|
||||||
import { Auth } from '..';
|
import { Auth } from '../model/auth';
|
||||||
|
|
||||||
export const readOneById = async (id: Types.ObjectId) => Auth.findById(id);
|
export const readOneById = async (id: Types.ObjectId) => Auth.findById(id);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Types } from 'mongoose';
|
import { Types } from 'mongoose';
|
||||||
|
|
||||||
import { Auth } from '..';
|
import { Auth } from '../model/auth';
|
||||||
|
|
||||||
export const readOneByRecord = async (record: Types.ObjectId) => Auth.findOne({ record });
|
export const readOneByRecord = async (record: Types.ObjectId) => Auth.findOne({ record });
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
import { Auth } from '..';
|
import { Auth } from '../model/auth';
|
||||||
|
|
||||||
export const readOneByUsername = async (username: string) => Auth.findOne({ username });
|
export const readOneByUsername = async (username: string) => Auth.findOne({ username });
|
||||||
@@ -37,7 +37,12 @@ export const AuthSchema = new Schema<AuthDocument, AuthModel>(
|
|||||||
{
|
{
|
||||||
is2FA: { type: Boolean, default: false },
|
is2FA: { type: Boolean, default: false },
|
||||||
record: { type: Types.ObjectId, unique: true },
|
record: { type: Types.ObjectId, unique: true },
|
||||||
status: { type: Number, enum: Status, default: Status.UNVERIFIED, index: true },
|
status: {
|
||||||
|
type: Number,
|
||||||
|
enum: Status,
|
||||||
|
default: Status.UNVERIFIED,
|
||||||
|
index: true,
|
||||||
|
},
|
||||||
strategies: [{ type: Types.ObjectId, ref: COLL_STRATEGY, default: [] }],
|
strategies: [{ type: Types.ObjectId, ref: COLL_STRATEGY, default: [] }],
|
||||||
username: { type: String, required: true, unique: true },
|
username: { type: String, required: true, unique: true },
|
||||||
},
|
},
|
||||||
@@ -30,7 +30,9 @@ export const TokenSchema = new Schema<Token, TokenModel>(
|
|||||||
|
|
||||||
TokenSchema.statics = {
|
TokenSchema.statics = {
|
||||||
async cleanupExpiredTokens() {
|
async cleanupExpiredTokens() {
|
||||||
const { acknowledged, deletedCount } = await this.deleteMany({ expires: { $lte: Date.now() } });
|
const { acknowledged, deletedCount } = await this.deleteMany({
|
||||||
|
expires: { $lte: Date.now() },
|
||||||
|
});
|
||||||
return { success: acknowledged, deletedCount };
|
return { success: acknowledged, deletedCount };
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -40,7 +42,11 @@ TokenSchema.statics = {
|
|||||||
await existing.deleteOne();
|
await existing.deleteOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
const doc = await this.create({ type, auth, expires: expires || getDefaultExpiresFor(type) });
|
const doc = await this.create({
|
||||||
|
type,
|
||||||
|
auth,
|
||||||
|
expires: expires || getDefaultExpiresFor(type),
|
||||||
|
});
|
||||||
return sign({
|
return sign({
|
||||||
sub: `${doc._id}`,
|
sub: `${doc._id}`,
|
||||||
exp: doc.expires,
|
exp: doc.expires,
|
||||||
@@ -2,11 +2,16 @@
|
|||||||
"extends": "@tsconfig/node16/tsconfig.json",
|
"extends": "@tsconfig/node16/tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"declaration": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"outDir": "./dist/",
|
"outDir": "lib/",
|
||||||
"rootDirs": ["lib"],
|
"rootDirs": ["./", "src/"],
|
||||||
"sourceMap": true
|
"strict": true,
|
||||||
}
|
"esModuleInterop": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"removeComments": false
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
}
|
}
|
||||||
|
|||||||
17
tsconfig.production.json
Normal file
17
tsconfig.production.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"extends": "@tsconfig/node16/tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"declaration": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"outDir": "lib/",
|
||||||
|
"rootDirs": ["./", "src/"],
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"sourceMap": false,
|
||||||
|
"removeComments": true
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user