@riocrypto/common 1.0.373 → 1.0.376

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.
@@ -0,0 +1,16 @@
1
+ import mongoose from "mongoose";
2
+ interface AdminAuthAttrs {
3
+ email: string;
4
+ password: string;
5
+ previousPasswords?: string[];
6
+ }
7
+ interface AdminAuthDoc extends mongoose.Document {
8
+ email: string;
9
+ password: string;
10
+ previousPasswords?: string[];
11
+ }
12
+ interface AdminAuthModel extends mongoose.Model<AdminAuthDoc> {
13
+ build(attrs: AdminAuthAttrs): AdminAuthDoc;
14
+ }
15
+ declare const AdminAuth: AdminAuthModel;
16
+ export { AdminAuth, AdminAuthDoc };
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AdminAuth = void 0;
16
+ const mongoose_1 = __importDefault(require("mongoose"));
17
+ const password_1 = require("../services/password");
18
+ const AdminSchema = new mongoose_1.default.Schema({
19
+ email: {
20
+ type: String,
21
+ required: true,
22
+ },
23
+ password: {
24
+ type: String,
25
+ required: true,
26
+ },
27
+ previousPasswords: [
28
+ {
29
+ type: String,
30
+ required: false,
31
+ },
32
+ ],
33
+ }, {
34
+ toJSON: {
35
+ transform(doc, ret) {
36
+ ret.id = ret._id.valueOf();
37
+ delete ret._id;
38
+ delete ret.__v;
39
+ delete ret.password;
40
+ },
41
+ },
42
+ });
43
+ AdminSchema.pre("save", function (done) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ if (this.isModified("password")) {
46
+ const hashed = yield password_1.Password.toHash(this.get("password"));
47
+ this.set("password", hashed);
48
+ }
49
+ done();
50
+ });
51
+ });
52
+ AdminSchema.statics.build = (attrs) => {
53
+ return new AdminAuth(attrs);
54
+ };
55
+ const AdminAuth = mongoose_1.default.model("Admin", AdminSchema);
56
+ exports.AdminAuth = AdminAuth;
@@ -0,0 +1,24 @@
1
+ import mongoose from "mongoose";
2
+ import { APIKey } from "../types/api-key";
3
+ import { SecurityQuestion } from "../types/security-question";
4
+ interface AuthAttrs {
5
+ phoneNumber: string;
6
+ password?: string;
7
+ securityQuestion?: SecurityQuestion;
8
+ securityAnswer?: string;
9
+ previousPasswords?: string[];
10
+ apiKeys?: APIKey[];
11
+ }
12
+ interface AuthDoc extends mongoose.Document {
13
+ phoneNumber: string;
14
+ password?: string;
15
+ securityQuestion?: SecurityQuestion;
16
+ securityAnswer?: string;
17
+ previousPasswords?: string[];
18
+ apiKeys?: APIKey[];
19
+ }
20
+ interface AuthModel extends mongoose.Model<AuthDoc> {
21
+ build(attrs: AuthAttrs): AuthDoc;
22
+ }
23
+ declare const Auth: AuthModel;
24
+ export { Auth, AuthDoc };
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Auth = void 0;
16
+ const mongoose_1 = __importDefault(require("mongoose"));
17
+ const password_1 = require("../services/password");
18
+ const AuthSchema = new mongoose_1.default.Schema({
19
+ phoneNumber: {
20
+ type: String,
21
+ required: true,
22
+ },
23
+ password: {
24
+ type: String,
25
+ },
26
+ securityQuestion: {
27
+ type: String,
28
+ },
29
+ securityAnswer: {
30
+ type: String,
31
+ },
32
+ previousPasswords: [
33
+ {
34
+ type: String,
35
+ },
36
+ ],
37
+ apiKeys: [
38
+ {
39
+ value: {
40
+ type: String,
41
+ required: true,
42
+ },
43
+ label: {
44
+ type: String,
45
+ },
46
+ id: {
47
+ type: String,
48
+ required: true,
49
+ },
50
+ },
51
+ ],
52
+ }, {
53
+ toJSON: {
54
+ transform(doc, ret) {
55
+ ret.id = ret._id.valueOf();
56
+ delete ret._id;
57
+ delete ret.__v;
58
+ delete ret.password;
59
+ delete ret.securityAnswer;
60
+ delete ret.previousPasswords;
61
+ for (let apiKey of ret.apiKeys) {
62
+ delete apiKey.value;
63
+ }
64
+ },
65
+ },
66
+ });
67
+ AuthSchema.pre("save", function (done) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ if (this.isModified("password")) {
70
+ const hashed = yield password_1.Password.toHash(this.get("password"));
71
+ this.set("password", hashed);
72
+ }
73
+ done();
74
+ });
75
+ });
76
+ AuthSchema.statics.build = (attrs) => {
77
+ return new Auth(attrs);
78
+ };
79
+ const Auth = mongoose_1.default.model("Auth", AuthSchema);
80
+ exports.Auth = Auth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common",
3
- "version": "1.0.373",
3
+ "version": "1.0.376",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",