@rpcbase/server 0.356.0-tsbundlerserver.0 → 0.356.0-tsbundlerserver.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/get_object_id.ts CHANGED
@@ -1,5 +1,6 @@
1
- const assert = require("assert")
2
- const crypto = require("crypto")
1
+ import assert from "assert";
2
+ import crypto from "crypto";
3
+ import mongoose from "./mongoose"
3
4
 
4
5
  import isHexadecimal from "validator/lib/isHexadecimal"
5
6
 
@@ -16,12 +17,12 @@ assert(isHexadecimal(RB_TENANT_ID), "expected RB_TENANT_ID to be a hexadecimal")
16
17
  assert(RB_TENANT_ID.length === 8, "RB_TENANT_ID must be exactly 4 bytes (8 hex chars)")
17
18
 
18
19
  // generates a 12 bytes mongodb object id using the org id prefix or custom customer id
19
- export const get_object_id = (): string => {
20
+ export const get_object_id = (): mongoose.Types.ObjectId => {
20
21
  const ts_bytes = Math.floor(Date.now() / 1000).toString(16)
21
22
  expect(ts_bytes.length).toBe(8)
22
23
 
23
24
  const random_bytes = crypto.randomBytes(4).toString("hex")
24
25
 
25
26
  const obj_id = `${ts_bytes}${RB_TENANT_ID}${random_bytes}`
26
- return obj_id
27
+ return new mongoose.Types.ObjectId(obj_id)
27
28
  }
@@ -1,13 +1,13 @@
1
- import mongoose, { Schema } from "mongoose"
1
+ import mongoose, { Schema } from "./"
2
2
 
3
- import get_object_id from "../get_object_id"
3
+ import {get_object_id} from "../get_object_id"
4
4
 
5
5
  export const object_id_plugin = (schema: Schema) => {
6
6
  if (!schema.path("_id")) {
7
7
  schema.add({
8
8
  _id: {
9
9
  type: mongoose.Types.ObjectId,
10
- default: () => new mongoose.Types.ObjectId(get_object_id()),
10
+ default: () => get_object_id(),
11
11
  },
12
12
  })
13
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.356.0-tsbundlerserver.0",
3
+ "version": "0.356.0-tsbundlerserver.2",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "scripts": {
@@ -10,7 +10,6 @@ const get_random_str = require("@rpcbase/std/crypto/get_random_str")
10
10
 
11
11
  const mailer = require("../../mailer")
12
12
  const mongoose = require("../../mongoose")
13
- const get_object_id = require("../../get_object_id")
14
13
  const ResetPasswordToken = require("../models/ResetPasswordToken")
15
14
 
16
15
  const log = debug("rb:auth:reset_password")
@@ -39,7 +38,6 @@ const reset_password = async({email}, ctx) => {
39
38
  const token_hash = await hash_password(token)
40
39
 
41
40
  const reset_token = new ResetPasswordToken({
42
- _id: get_object_id(),
43
41
  user_id: user._id,
44
42
  token_hash,
45
43
  })
@@ -1,13 +1,10 @@
1
1
  /* @flow */
2
2
  const {hash_password} = require("@rpcbase/std/crypto/hash")
3
3
 
4
- const get_object_id = require("../../get_object_id")
5
4
  const mongoose = require("../../mongoose")
6
5
 
7
6
  const UserStoredValues = require("../models/UserStoredValues")
8
7
 
9
-
10
-
11
8
  const MIN_PASSWORD_LENGTH = 12
12
9
 
13
10
  const sign_up = async(payload, ctx, session) => {
@@ -40,7 +37,6 @@ const sign_up = async(payload, ctx, session) => {
40
37
  const hash = await hash_password(password)
41
38
 
42
39
  const user = new User({
43
- _id: get_object_id(),
44
40
  email,
45
41
  password_hash: hash
46
42
  })
@@ -50,7 +46,6 @@ const sign_up = async(payload, ctx, session) => {
50
46
  const user_id = user._id.toString()
51
47
 
52
48
  const values_store = new UserStoredValues({
53
- _id: get_object_id(),
54
49
  _owners: [user_id]
55
50
  })
56
51