@wrcb/cb-common 1.0.58 → 1.0.60

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.
@@ -2,6 +2,7 @@ import { Request, Response, NextFunction } from 'express';
2
2
  export interface UserPayload {
3
3
  id: string;
4
4
  email: string;
5
+ cpf: string;
5
6
  role?: string;
6
7
  }
7
8
  declare global {
@@ -1,6 +1,7 @@
1
1
  import { Express } from 'express';
2
+ export declare function signUpReturnCookie(id?: string): string[];
3
+ export declare function signUpReturnCookieAdmin(id?: string): string[];
2
4
  export declare function signUp(app: Express): Promise<{
3
5
  cookie: string[] | undefined;
4
6
  userData: any;
5
7
  }>;
6
- export declare function signUpAdmin(id?: string): string[];
@@ -12,13 +12,53 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.signUpReturnCookie = signUpReturnCookie;
16
+ exports.signUpReturnCookieAdmin = signUpReturnCookieAdmin;
15
17
  exports.signUp = signUp;
16
- exports.signUpAdmin = signUpAdmin;
17
18
  const supertest_1 = __importDefault(require("supertest"));
18
19
  const mongoose_1 = __importDefault(require("mongoose"));
19
20
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
20
21
  const country_1 = require("../events/types/country");
21
22
  const userRole_1 = require("../events/types/userRole");
23
+ function signUpReturnCookie(id) {
24
+ // Build a JWT payload
25
+ const payload = {
26
+ id: id !== null && id !== void 0 ? id : new mongoose_1.default.Types.ObjectId().toHexString(),
27
+ email: 'test@test.com',
28
+ cpf: '05854744600',
29
+ role: userRole_1.UserRole.User,
30
+ };
31
+ // Create the JWT
32
+ const token = jsonwebtoken_1.default.sign(payload, process.env.JWT_KEY);
33
+ // Build session object {jwt: MY_JWT}
34
+ const session = { jwt: token };
35
+ // Turn that session into JSON
36
+ const sessionJSON = JSON.stringify(session);
37
+ // Take JSON and encode it as base64
38
+ const base64 = Buffer.from(sessionJSON).toString('base64');
39
+ // return a string that the cookie with the encoded data
40
+ const cookieString = [`session=${base64}`];
41
+ return cookieString;
42
+ }
43
+ function signUpReturnCookieAdmin(id) {
44
+ // Build a JWT payload
45
+ const payload = {
46
+ id: id !== null && id !== void 0 ? id : new mongoose_1.default.Types.ObjectId().toHexString(),
47
+ email: 'test@test.com',
48
+ cpf: '05854744600',
49
+ role: userRole_1.UserRole.Admin,
50
+ };
51
+ // Create the JWT
52
+ const token = jsonwebtoken_1.default.sign(payload, process.env.JWT_KEY);
53
+ // Build session object {jwt: MY_JWT}
54
+ const session = { jwt: token };
55
+ // Turn that session into JSON
56
+ const sessionJSON = JSON.stringify(session);
57
+ // Take JSON and encode it as base64
58
+ const base64 = Buffer.from(sessionJSON).toString('base64');
59
+ // return a string that the cookie wieht the encoded data
60
+ return [`session=${base64}`];
61
+ }
22
62
  function signUp(app) {
23
63
  return __awaiter(this, void 0, void 0, function* () {
24
64
  const response = yield (0, supertest_1.default)(app)
@@ -38,21 +78,3 @@ function signUp(app) {
38
78
  return { cookie, userData };
39
79
  });
40
80
  }
41
- function signUpAdmin(id) {
42
- // Build a JWT payload
43
- const payload = {
44
- id: id !== null && id !== void 0 ? id : new mongoose_1.default.Types.ObjectId().toHexString(),
45
- email: 'test@test.com',
46
- role: userRole_1.UserRole.Admin,
47
- };
48
- // Create the JWT
49
- const token = jsonwebtoken_1.default.sign(payload, process.env.JWT_KEY);
50
- // Build session object {jwt: MY_JWT}
51
- const session = { jwt: token };
52
- // Turn that session into JSON
53
- const sessionJSON = JSON.stringify(session);
54
- // Take JSON and encode it as base64
55
- const base64 = Buffer.from(sessionJSON).toString('base64');
56
- // return a string that the cookie wieht the encoded data
57
- return [`session=${base64}`];
58
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrcb/cb-common",
3
- "version": "1.0.58",
3
+ "version": "1.0.60",
4
4
  "description": "Common resources between services",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",