@wrcb/cb-common 1.0.58 → 1.0.59

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.
@@ -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,51 @@ 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
+ role: userRole_1.UserRole.User,
29
+ };
30
+ // Create the JWT
31
+ const token = jsonwebtoken_1.default.sign(payload, process.env.JWT_KEY);
32
+ // Build session object {jwt: MY_JWT}
33
+ const session = { jwt: token };
34
+ // Turn that session into JSON
35
+ const sessionJSON = JSON.stringify(session);
36
+ // Take JSON and encode it as base64
37
+ const base64 = Buffer.from(sessionJSON).toString('base64');
38
+ // return a string that the cookie with the encoded data
39
+ const cookieString = [`session=${base64}`];
40
+ return cookieString;
41
+ }
42
+ function signUpReturnCookieAdmin(id) {
43
+ // Build a JWT payload
44
+ const payload = {
45
+ id: id !== null && id !== void 0 ? id : new mongoose_1.default.Types.ObjectId().toHexString(),
46
+ email: 'test@test.com',
47
+ role: userRole_1.UserRole.Admin,
48
+ };
49
+ // Create the JWT
50
+ const token = jsonwebtoken_1.default.sign(payload, process.env.JWT_KEY);
51
+ // Build session object {jwt: MY_JWT}
52
+ const session = { jwt: token };
53
+ // Turn that session into JSON
54
+ const sessionJSON = JSON.stringify(session);
55
+ // Take JSON and encode it as base64
56
+ const base64 = Buffer.from(sessionJSON).toString('base64');
57
+ // return a string that the cookie wieht the encoded data
58
+ return [`session=${base64}`];
59
+ }
22
60
  function signUp(app) {
23
61
  return __awaiter(this, void 0, void 0, function* () {
24
62
  const response = yield (0, supertest_1.default)(app)
@@ -38,21 +76,3 @@ function signUp(app) {
38
76
  return { cookie, userData };
39
77
  });
40
78
  }
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.59",
4
4
  "description": "Common resources between services",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",