@psctickets/common 1.0.36 → 1.0.39

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,10 @@
1
+ import { Subjects } from "./Subjects";
2
+ export interface OrderCompletedEvent extends Event {
3
+ subject: Subjects.OrderCompleted;
4
+ data: {
5
+ id: string;
6
+ version: number;
7
+ userId: string;
8
+ ticketId: string;
9
+ };
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { Subjects } from "./Subjects";
2
+ export interface PaymentSuccessEvent extends Event {
3
+ subject: Subjects.PaymentSuccess;
4
+ data: {
5
+ orderId: string;
6
+ rzpPaymentId: string;
7
+ rzpOrderId: string;
8
+ };
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -4,5 +4,7 @@ export declare enum Subjects {
4
4
  OrderCreated = "order:created",
5
5
  OrderCancelled = "order:cancelled",
6
6
  OrderExpired = "order:expired",
7
- ExpirationCompleted = "expiration:completed"
7
+ ExpirationCompleted = "expiration:completed",
8
+ PaymentSuccess = "payment:success",
9
+ OrderCompleted = "order:completed"
8
10
  }
@@ -9,4 +9,6 @@ var Subjects;
9
9
  Subjects["OrderCancelled"] = "order:cancelled";
10
10
  Subjects["OrderExpired"] = "order:expired";
11
11
  Subjects["ExpirationCompleted"] = "expiration:completed";
12
+ Subjects["PaymentSuccess"] = "payment:success";
13
+ Subjects["OrderCompleted"] = "order:completed";
12
14
  })(Subjects || (exports.Subjects = Subjects = {}));
@@ -7,3 +7,5 @@ export * from "./TicketUpdatedEvent";
7
7
  export * from "./OrderCreatedEvent";
8
8
  export * from "./OrderCancelledEvent";
9
9
  export * from "./ExpirationCompletedEvent";
10
+ export * from "./PaymentSuccessEvent";
11
+ export * from "./OrderCompletedEvent";
@@ -23,3 +23,5 @@ __exportStar(require("./TicketUpdatedEvent"), exports);
23
23
  __exportStar(require("./OrderCreatedEvent"), exports);
24
24
  __exportStar(require("./OrderCancelledEvent"), exports);
25
25
  __exportStar(require("./ExpirationCompletedEvent"), exports);
26
+ __exportStar(require("./PaymentSuccessEvent"), exports);
27
+ __exportStar(require("./OrderCompletedEvent"), exports);
@@ -18,10 +18,37 @@ const verifyTokenMiddleware = (req, _res, next) => __awaiter(void 0, void 0, voi
18
18
  var _a;
19
19
  let user;
20
20
  try {
21
- const signInToken = (_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt;
22
- user = jsonwebtoken_1.default.verify(signInToken, process.env.JWT_KEY);
21
+ // Check if this is an internal service-to-service call
22
+ const internalApiKey = req.headers["x-internal-api-key"];
23
+ if (internalApiKey) {
24
+ // Verify internal API key
25
+ const expectedApiKey = process.env.INTERNAL_API_KEY;
26
+ if (!expectedApiKey || internalApiKey !== expectedApiKey) {
27
+ throw new UnAuthorizedRequest_1.UnauthorizedRequest("Invalid internal API key");
28
+ }
29
+ // Get JWT token from header (Authorization header or x-jwt-token)
30
+ const authHeader = req.headers.authorization;
31
+ const signInToken = (authHeader && authHeader.startsWith("Bearer ")
32
+ ? authHeader.substring(7)
33
+ : authHeader) || req.headers["x-jwt-token"];
34
+ if (!signInToken) {
35
+ throw new UnAuthorizedRequest_1.UnauthorizedRequest("JWT token not provided in header");
36
+ }
37
+ user = jsonwebtoken_1.default.verify(signInToken, process.env.JWT_KEY);
38
+ }
39
+ else {
40
+ // Normal cookie-based authentication
41
+ const signInToken = (_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt;
42
+ if (!signInToken) {
43
+ throw new UnAuthorizedRequest_1.UnauthorizedRequest("JWT token not found in session");
44
+ }
45
+ user = jsonwebtoken_1.default.verify(signInToken, process.env.JWT_KEY);
46
+ }
23
47
  }
24
48
  catch (error) {
49
+ if (error instanceof UnAuthorizedRequest_1.UnauthorizedRequest) {
50
+ throw error;
51
+ }
25
52
  throw new UnAuthorizedRequest_1.UnauthorizedRequest("Invalid token");
26
53
  }
27
54
  req.currentUser = user;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psctickets/common",
3
- "version": "1.0.36",
3
+ "version": "1.0.39",
4
4
  "description": "common package for tickets learning project",
5
5
  "main": "./build/index.js",
6
6
  "files": [