@microservice_udemy/common 1.0.20 → 1.0.22

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,4 @@
1
+ export interface UserPayload {
2
+ id: string;
3
+ email: string;
4
+ }
@@ -0,0 +1,9 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class BadRequestError extends CustomError {
3
+ message: string;
4
+ statusCode: number;
5
+ constructor(message: string);
6
+ serializeErrors(): {
7
+ message: string;
8
+ }[];
9
+ }
@@ -0,0 +1,8 @@
1
+ export declare abstract class CustomError extends Error {
2
+ abstract statusCode: number;
3
+ constructor(message: string);
4
+ abstract serializeErrors(): {
5
+ message: string;
6
+ field?: string;
7
+ }[];
8
+ }
@@ -0,0 +1,9 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class DatabaseConnectionError extends CustomError {
3
+ statusCode: number;
4
+ reason: string;
5
+ constructor();
6
+ serializeErrors(): {
7
+ message: string;
8
+ }[];
9
+ }
@@ -0,0 +1,9 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class NotAuthorizedError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ field?: string;
8
+ }[];
9
+ }
@@ -0,0 +1,8 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class NotFoundError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ }[];
8
+ }
@@ -0,0 +1,11 @@
1
+ import { ValidationError } from "express-validator";
2
+ import { CustomError } from "./custom-error";
3
+ export declare class RequestValidationError extends CustomError {
4
+ errors: ValidationError[];
5
+ statusCode: number;
6
+ constructor(errors: ValidationError[]);
7
+ serializeErrors(): {
8
+ message: any;
9
+ field: string | undefined;
10
+ }[];
11
+ }
@@ -0,0 +1,5 @@
1
+ import { Subjects } from "./subjects/subjects";
2
+ export interface Event {
3
+ subject: Subjects;
4
+ data: any;
5
+ }
@@ -0,0 +1,7 @@
1
+ import { Subjects } from "../subjects/subjects";
2
+ export interface ExpirationCompleteEvent {
3
+ subject: Subjects.ExpirationComplete;
4
+ data: {
5
+ orderId: string;
6
+ };
7
+ }
@@ -0,0 +1,18 @@
1
+ import { Message, Stan } from "node-nats-streaming";
2
+ import { Subjects } from "./subjects/subjects";
3
+ interface events {
4
+ subject: Subjects;
5
+ data: any;
6
+ }
7
+ export declare abstract class Listener<T extends events> {
8
+ abstract subject: T["subject"];
9
+ abstract queueGroupName: string;
10
+ abstract onMessage(data: T["data"], msg: Message): void;
11
+ protected client: Stan;
12
+ protected ackWait: number;
13
+ constructor(client: Stan);
14
+ subscriptionOptions(): import("node-nats-streaming").SubscriptionOptions;
15
+ listen(): void;
16
+ parseMessage(msg: Message): any;
17
+ }
18
+ export {};
@@ -0,0 +1,11 @@
1
+ import { Subjects } from "../subjects/subjects";
2
+ export interface OrderCancelledEvent {
3
+ subject: Subjects.OrderCancelled;
4
+ data: {
5
+ id: string;
6
+ version: number;
7
+ ticket: {
8
+ id: string;
9
+ };
10
+ };
11
+ }
@@ -0,0 +1,16 @@
1
+ import { Subjects } from "../subjects/subjects";
2
+ import { OrderStatus } from "../types/order-status";
3
+ export interface OrderCreatedEvent {
4
+ subject: Subjects.OrderCreated;
5
+ data: {
6
+ id: string;
7
+ version: number;
8
+ status: OrderStatus;
9
+ userId: string;
10
+ expiresAt: string;
11
+ ticket: {
12
+ id: string;
13
+ price: number;
14
+ };
15
+ };
16
+ }
@@ -0,0 +1,9 @@
1
+ import { Subjects } from "../subjects/subjects";
2
+ export interface PaymentCreatedEvent {
3
+ subject: Subjects.PaymentCreated;
4
+ data: {
5
+ id: string;
6
+ orderId: string;
7
+ stripeId: string;
8
+ };
9
+ }
@@ -0,0 +1,13 @@
1
+ import { Stan } from "node-nats-streaming";
2
+ import { Subjects } from "./subjects/subjects";
3
+ interface Event {
4
+ subject: Subjects;
5
+ data: any;
6
+ }
7
+ export declare abstract class Publisher<T extends Event> {
8
+ abstract subject: T["subject"];
9
+ protected client: Stan;
10
+ constructor(client: Stan);
11
+ publish(data: T["data"]): Promise<void>;
12
+ }
13
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare enum Subjects {
2
+ TicketCreated = "ticket:created",
3
+ TicketUpdated = "ticket:updated",
4
+ OrderCreated = "order:created",
5
+ OrderCancelled = "order:cancelled",
6
+ ExpirationComplete = "expiration:complete",
7
+ PaymentCreated = "payment:created"
8
+ }
@@ -0,0 +1,12 @@
1
+ import { Subjects } from "../subjects/subjects";
2
+ export interface TicketCreatedEvent {
3
+ subject: Subjects.TicketCreated;
4
+ data: {
5
+ id: string;
6
+ version: number;
7
+ title: string;
8
+ price: number;
9
+ userId: string;
10
+ orderId?: string;
11
+ };
12
+ }
@@ -0,0 +1,12 @@
1
+ import { Subjects } from "../subjects/subjects";
2
+ export interface TicketUpdatedEvent {
3
+ subject: Subjects.TicketUpdated;
4
+ data: {
5
+ id: string;
6
+ version: number;
7
+ title: string;
8
+ price: number;
9
+ userId: string;
10
+ orderId?: string;
11
+ };
12
+ }
@@ -0,0 +1,6 @@
1
+ export declare enum OrderStatus {
2
+ Created = "created",
3
+ Cancelled = "cancelled",
4
+ AwaitingPayment = "awaiting:payment",
5
+ Complete = "complete"
6
+ }
@@ -0,0 +1,20 @@
1
+ export * from "./errors/bad-request-error";
2
+ export * from "./errors/custom-error";
3
+ export * from "./errors/database-connection-error";
4
+ export * from "./errors/not-authorized-error";
5
+ export * from "./errors/not-found-error";
6
+ export * from "./errors/request-validation-error";
7
+ export * from "./middlewares/current-user";
8
+ export * from "./middlewares/error-handler";
9
+ export * from "./middlewares/require-auth";
10
+ export * from "./middlewares/validate-request";
11
+ export * from "./events/listener";
12
+ export * from "./events/publisher";
13
+ export * from "./events/subjects/subjects";
14
+ export * from "./events/ticket-events/ticket-created-event";
15
+ export * from "./events/ticket-events/ticket-updated-event";
16
+ export * from "./events/order-events/order-created-event";
17
+ export * from "./events/order-events/order-cancelled-event";
18
+ export * from "./events/payment-events/payment-created-event";
19
+ export * from "./events/expiration-events/expiration-complete-event";
20
+ export * from "./events/types/order-status";
@@ -0,0 +1,2 @@
1
+ import { Request, Response, NextFunction } from "express";
2
+ export declare const currentUser: (req: Request, _res: Response, next: NextFunction) => void;
@@ -0,0 +1,2 @@
1
+ import { Request, Response, NextFunction } from "express";
2
+ export declare const errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
@@ -0,0 +1,2 @@
1
+ import { Request, Response, NextFunction } from "express";
2
+ export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
@@ -0,0 +1,2 @@
1
+ import { Request, Response, NextFunction } from "express";
2
+ export declare const validateRequest: (req: Request, res: Response, next: NextFunction) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microservice_udemy/common",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",