@ajayjbtickets/common 1.0.27 → 1.0.32
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/dist/index.cjs +64 -2
- package/dist/index.d.cts +54 -2
- package/dist/index.d.ts +54 -2
- package/dist/index.js +61 -2
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -46,13 +46,16 @@ __export(index_exports, {
|
|
|
46
46
|
InternalError: () => InternalError,
|
|
47
47
|
InternalErrorResponse: () => InternalErrorResponse,
|
|
48
48
|
JwtService: () => JwtService,
|
|
49
|
+
Listener: () => Listener,
|
|
49
50
|
NoDataError: () => NoDataError,
|
|
50
51
|
NoEntryError: () => NoEntryError,
|
|
51
52
|
NoFoundResponse: () => NoFoundResponse,
|
|
52
53
|
NotFoundError: () => NotFoundError,
|
|
53
54
|
Password: () => Password,
|
|
55
|
+
Publisher: () => Publisher,
|
|
54
56
|
ResponseStatusCode: () => ResponseStatusCode,
|
|
55
57
|
StatusCode: () => StatusCode,
|
|
58
|
+
Subjects: () => Subjects,
|
|
56
59
|
SuccessResponse: () => SuccessResponse,
|
|
57
60
|
TokenExpiredError: () => TokenExpiredError,
|
|
58
61
|
ValidationSource: () => ValidationSource,
|
|
@@ -143,10 +146,14 @@ var ApiResponse = class {
|
|
|
143
146
|
}
|
|
144
147
|
};
|
|
145
148
|
var SuccessResponse = class extends ApiResponse {
|
|
146
|
-
|
|
149
|
+
data;
|
|
150
|
+
pagination;
|
|
151
|
+
constructor(responseStatusCode, message, data, pagination) {
|
|
147
152
|
super(responseStatusCode, message, "10000" /* SUCCESS */);
|
|
148
153
|
this.data = data;
|
|
149
|
-
|
|
154
|
+
if (pagination) {
|
|
155
|
+
this.pagination = pagination;
|
|
156
|
+
}
|
|
150
157
|
}
|
|
151
158
|
send(res) {
|
|
152
159
|
this.prepare(res, this, {});
|
|
@@ -504,6 +511,58 @@ var sanitizeObject = (value) => {
|
|
|
504
511
|
}
|
|
505
512
|
return newObject;
|
|
506
513
|
};
|
|
514
|
+
|
|
515
|
+
// src/events/baseListener.ts
|
|
516
|
+
var Listener = class {
|
|
517
|
+
ackWait = 5 * 1e3;
|
|
518
|
+
client;
|
|
519
|
+
constructor(client) {
|
|
520
|
+
this.client = client;
|
|
521
|
+
}
|
|
522
|
+
subscriptionOptions() {
|
|
523
|
+
return this.client.subscriptionOptions().setManualAckMode(true).setDeliverAllAvailable().setAckWait(this.ackWait).setDurableName(this.queueGroupName);
|
|
524
|
+
}
|
|
525
|
+
listen() {
|
|
526
|
+
const subscription = this.client.subscribe(
|
|
527
|
+
this.subject,
|
|
528
|
+
this.queueGroupName,
|
|
529
|
+
this.subscriptionOptions()
|
|
530
|
+
);
|
|
531
|
+
subscription.on("message", (msg) => {
|
|
532
|
+
const parsedData = this.parseData(msg);
|
|
533
|
+
this.onMessage(parsedData, msg);
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
parseData(msg) {
|
|
537
|
+
const data = msg.getData();
|
|
538
|
+
return typeof data === "string" ? JSON.parse(data) : JSON.parse(data.toString("utf-8"));
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
// src/events/basePublisher.ts
|
|
543
|
+
var Publisher = class {
|
|
544
|
+
client;
|
|
545
|
+
constructor(client) {
|
|
546
|
+
this.client = client;
|
|
547
|
+
}
|
|
548
|
+
async publish(data) {
|
|
549
|
+
return new Promise((resolve, reject) => {
|
|
550
|
+
this.client.publish(this.subject, JSON.stringify(data), (error, guid) => {
|
|
551
|
+
if (error) {
|
|
552
|
+
reject(error);
|
|
553
|
+
}
|
|
554
|
+
resolve(guid);
|
|
555
|
+
});
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
// src/events/subjects.ts
|
|
561
|
+
var Subjects = /* @__PURE__ */ ((Subjects2) => {
|
|
562
|
+
Subjects2["TicketCreated"] = "ticket:created";
|
|
563
|
+
Subjects2["TicketUpdated"] = "ticket:updated";
|
|
564
|
+
return Subjects2;
|
|
565
|
+
})(Subjects || {});
|
|
507
566
|
// Annotate the CommonJS export names for ESM import in node:
|
|
508
567
|
0 && (module.exports = {
|
|
509
568
|
AccessTokenError,
|
|
@@ -522,13 +581,16 @@ var sanitizeObject = (value) => {
|
|
|
522
581
|
InternalError,
|
|
523
582
|
InternalErrorResponse,
|
|
524
583
|
JwtService,
|
|
584
|
+
Listener,
|
|
525
585
|
NoDataError,
|
|
526
586
|
NoEntryError,
|
|
527
587
|
NoFoundResponse,
|
|
528
588
|
NotFoundError,
|
|
529
589
|
Password,
|
|
590
|
+
Publisher,
|
|
530
591
|
ResponseStatusCode,
|
|
531
592
|
StatusCode,
|
|
593
|
+
Subjects,
|
|
532
594
|
SuccessResponse,
|
|
533
595
|
TokenExpiredError,
|
|
534
596
|
ValidationSource,
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,8 @@ import { Response, Request, NextFunction } from 'express';
|
|
|
2
2
|
import winston from 'winston';
|
|
3
3
|
import { ZodSchema } from 'zod';
|
|
4
4
|
import jsonwebtoken, { SignOptions, VerifyOptions } from 'jsonwebtoken';
|
|
5
|
+
import * as node_nats_streaming from 'node-nats-streaming';
|
|
6
|
+
import { Message, Stan } from 'node-nats-streaming';
|
|
5
7
|
|
|
6
8
|
declare const ENVIRONMENTS: {
|
|
7
9
|
production: string;
|
|
@@ -98,6 +100,11 @@ declare enum ResponseStatusCode {
|
|
|
98
100
|
SERVICE_UNAVAILABLE = 503,
|
|
99
101
|
GATEWAY_TIMEOUT = 504
|
|
100
102
|
}
|
|
103
|
+
type Pagination = {
|
|
104
|
+
currentPage: number;
|
|
105
|
+
itemsPerPage: number;
|
|
106
|
+
totalItems: number;
|
|
107
|
+
};
|
|
101
108
|
declare abstract class ApiResponse {
|
|
102
109
|
message: string;
|
|
103
110
|
statusCode: string | undefined;
|
|
@@ -113,7 +120,8 @@ declare abstract class ApiResponse {
|
|
|
113
120
|
}
|
|
114
121
|
declare class SuccessResponse<T> extends ApiResponse {
|
|
115
122
|
data: T;
|
|
116
|
-
|
|
123
|
+
pagination: Pagination | undefined;
|
|
124
|
+
constructor(responseStatusCode: ResponseStatusCode.SUCCESS | ResponseStatusCode.CREATED | ResponseStatusCode.ACCEPTED | ResponseStatusCode.NO_CONTENT, message: string, data: T, pagination?: Pagination);
|
|
117
125
|
send(res: Response): void;
|
|
118
126
|
}
|
|
119
127
|
declare class AccessTokenErrorResponse extends ApiResponse {
|
|
@@ -178,4 +186,48 @@ declare const asyncHandler: (execution: AsyncFunction) => (req: Request, res: Re
|
|
|
178
186
|
|
|
179
187
|
declare const sanitizeObject: <T>(value: T) => T;
|
|
180
188
|
|
|
181
|
-
|
|
189
|
+
declare enum Subjects {
|
|
190
|
+
TicketCreated = "ticket:created",
|
|
191
|
+
TicketUpdated = "ticket:updated"
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
interface Event {
|
|
195
|
+
subject: Subjects;
|
|
196
|
+
data: any;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
declare abstract class Listener<T extends Event> {
|
|
200
|
+
abstract subject: T["subject"];
|
|
201
|
+
abstract queueGroupName: string;
|
|
202
|
+
abstract onMessage(data: T["data"], msg: Message): void;
|
|
203
|
+
protected ackWait: number;
|
|
204
|
+
private client;
|
|
205
|
+
constructor(client: Stan);
|
|
206
|
+
subscriptionOptions(): node_nats_streaming.SubscriptionOptions;
|
|
207
|
+
listen(): void;
|
|
208
|
+
parseData(msg: Message): T["data"];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
declare abstract class Publisher<T extends Event> {
|
|
212
|
+
abstract subject: T["subject"];
|
|
213
|
+
private client;
|
|
214
|
+
constructor(client: Stan);
|
|
215
|
+
publish(data: T["data"]): Promise<string>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
interface Ticket {
|
|
219
|
+
id: number;
|
|
220
|
+
name: string;
|
|
221
|
+
price: number;
|
|
222
|
+
userId: string;
|
|
223
|
+
}
|
|
224
|
+
interface TicketCreatedEvent {
|
|
225
|
+
subject: Subjects.TicketCreated;
|
|
226
|
+
data: Ticket;
|
|
227
|
+
}
|
|
228
|
+
interface TicketUpdatedEvent {
|
|
229
|
+
subject: Subjects.TicketUpdated;
|
|
230
|
+
data: Ticket;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export { AccessTokenError, AccessTokenErrorResponse, ApiError, ApiResponse, AuthFailureError, BadRequestError, BadRequestResponse, BadTokenError, BadTokenResponse, ENVIRONMENTS, type ErrorDetailType, ErrorType, ForbiddenError, ForbiddenResponse, InternalError, InternalErrorResponse, type JwtPayload, JwtService, Listener, NoDataError, NoEntryError, NoFoundResponse, NotFoundError, type Pagination, Password, Publisher, ResponseStatusCode, StatusCode, Subjects, SuccessResponse, type Ticket, type TicketCreatedEvent, type TicketUpdatedEvent, TokenExpiredError, ValidationSource, asyncHandler, logger, sanitizeObject, schemaValidator, verifyToken };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { Response, Request, NextFunction } from 'express';
|
|
|
2
2
|
import winston from 'winston';
|
|
3
3
|
import { ZodSchema } from 'zod';
|
|
4
4
|
import jsonwebtoken, { SignOptions, VerifyOptions } from 'jsonwebtoken';
|
|
5
|
+
import * as node_nats_streaming from 'node-nats-streaming';
|
|
6
|
+
import { Message, Stan } from 'node-nats-streaming';
|
|
5
7
|
|
|
6
8
|
declare const ENVIRONMENTS: {
|
|
7
9
|
production: string;
|
|
@@ -98,6 +100,11 @@ declare enum ResponseStatusCode {
|
|
|
98
100
|
SERVICE_UNAVAILABLE = 503,
|
|
99
101
|
GATEWAY_TIMEOUT = 504
|
|
100
102
|
}
|
|
103
|
+
type Pagination = {
|
|
104
|
+
currentPage: number;
|
|
105
|
+
itemsPerPage: number;
|
|
106
|
+
totalItems: number;
|
|
107
|
+
};
|
|
101
108
|
declare abstract class ApiResponse {
|
|
102
109
|
message: string;
|
|
103
110
|
statusCode: string | undefined;
|
|
@@ -113,7 +120,8 @@ declare abstract class ApiResponse {
|
|
|
113
120
|
}
|
|
114
121
|
declare class SuccessResponse<T> extends ApiResponse {
|
|
115
122
|
data: T;
|
|
116
|
-
|
|
123
|
+
pagination: Pagination | undefined;
|
|
124
|
+
constructor(responseStatusCode: ResponseStatusCode.SUCCESS | ResponseStatusCode.CREATED | ResponseStatusCode.ACCEPTED | ResponseStatusCode.NO_CONTENT, message: string, data: T, pagination?: Pagination);
|
|
117
125
|
send(res: Response): void;
|
|
118
126
|
}
|
|
119
127
|
declare class AccessTokenErrorResponse extends ApiResponse {
|
|
@@ -178,4 +186,48 @@ declare const asyncHandler: (execution: AsyncFunction) => (req: Request, res: Re
|
|
|
178
186
|
|
|
179
187
|
declare const sanitizeObject: <T>(value: T) => T;
|
|
180
188
|
|
|
181
|
-
|
|
189
|
+
declare enum Subjects {
|
|
190
|
+
TicketCreated = "ticket:created",
|
|
191
|
+
TicketUpdated = "ticket:updated"
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
interface Event {
|
|
195
|
+
subject: Subjects;
|
|
196
|
+
data: any;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
declare abstract class Listener<T extends Event> {
|
|
200
|
+
abstract subject: T["subject"];
|
|
201
|
+
abstract queueGroupName: string;
|
|
202
|
+
abstract onMessage(data: T["data"], msg: Message): void;
|
|
203
|
+
protected ackWait: number;
|
|
204
|
+
private client;
|
|
205
|
+
constructor(client: Stan);
|
|
206
|
+
subscriptionOptions(): node_nats_streaming.SubscriptionOptions;
|
|
207
|
+
listen(): void;
|
|
208
|
+
parseData(msg: Message): T["data"];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
declare abstract class Publisher<T extends Event> {
|
|
212
|
+
abstract subject: T["subject"];
|
|
213
|
+
private client;
|
|
214
|
+
constructor(client: Stan);
|
|
215
|
+
publish(data: T["data"]): Promise<string>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
interface Ticket {
|
|
219
|
+
id: number;
|
|
220
|
+
name: string;
|
|
221
|
+
price: number;
|
|
222
|
+
userId: string;
|
|
223
|
+
}
|
|
224
|
+
interface TicketCreatedEvent {
|
|
225
|
+
subject: Subjects.TicketCreated;
|
|
226
|
+
data: Ticket;
|
|
227
|
+
}
|
|
228
|
+
interface TicketUpdatedEvent {
|
|
229
|
+
subject: Subjects.TicketUpdated;
|
|
230
|
+
data: Ticket;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export { AccessTokenError, AccessTokenErrorResponse, ApiError, ApiResponse, AuthFailureError, BadRequestError, BadRequestResponse, BadTokenError, BadTokenResponse, ENVIRONMENTS, type ErrorDetailType, ErrorType, ForbiddenError, ForbiddenResponse, InternalError, InternalErrorResponse, type JwtPayload, JwtService, Listener, NoDataError, NoEntryError, NoFoundResponse, NotFoundError, type Pagination, Password, Publisher, ResponseStatusCode, StatusCode, Subjects, SuccessResponse, type Ticket, type TicketCreatedEvent, type TicketUpdatedEvent, TokenExpiredError, ValidationSource, asyncHandler, logger, sanitizeObject, schemaValidator, verifyToken };
|
package/dist/index.js
CHANGED
|
@@ -77,10 +77,14 @@ var ApiResponse = class {
|
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
var SuccessResponse = class extends ApiResponse {
|
|
80
|
-
|
|
80
|
+
data;
|
|
81
|
+
pagination;
|
|
82
|
+
constructor(responseStatusCode, message, data, pagination) {
|
|
81
83
|
super(responseStatusCode, message, "10000" /* SUCCESS */);
|
|
82
84
|
this.data = data;
|
|
83
|
-
|
|
85
|
+
if (pagination) {
|
|
86
|
+
this.pagination = pagination;
|
|
87
|
+
}
|
|
84
88
|
}
|
|
85
89
|
send(res) {
|
|
86
90
|
this.prepare(res, this, {});
|
|
@@ -438,6 +442,58 @@ var sanitizeObject = (value) => {
|
|
|
438
442
|
}
|
|
439
443
|
return newObject;
|
|
440
444
|
};
|
|
445
|
+
|
|
446
|
+
// src/events/baseListener.ts
|
|
447
|
+
var Listener = class {
|
|
448
|
+
ackWait = 5 * 1e3;
|
|
449
|
+
client;
|
|
450
|
+
constructor(client) {
|
|
451
|
+
this.client = client;
|
|
452
|
+
}
|
|
453
|
+
subscriptionOptions() {
|
|
454
|
+
return this.client.subscriptionOptions().setManualAckMode(true).setDeliverAllAvailable().setAckWait(this.ackWait).setDurableName(this.queueGroupName);
|
|
455
|
+
}
|
|
456
|
+
listen() {
|
|
457
|
+
const subscription = this.client.subscribe(
|
|
458
|
+
this.subject,
|
|
459
|
+
this.queueGroupName,
|
|
460
|
+
this.subscriptionOptions()
|
|
461
|
+
);
|
|
462
|
+
subscription.on("message", (msg) => {
|
|
463
|
+
const parsedData = this.parseData(msg);
|
|
464
|
+
this.onMessage(parsedData, msg);
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
parseData(msg) {
|
|
468
|
+
const data = msg.getData();
|
|
469
|
+
return typeof data === "string" ? JSON.parse(data) : JSON.parse(data.toString("utf-8"));
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
// src/events/basePublisher.ts
|
|
474
|
+
var Publisher = class {
|
|
475
|
+
client;
|
|
476
|
+
constructor(client) {
|
|
477
|
+
this.client = client;
|
|
478
|
+
}
|
|
479
|
+
async publish(data) {
|
|
480
|
+
return new Promise((resolve, reject) => {
|
|
481
|
+
this.client.publish(this.subject, JSON.stringify(data), (error, guid) => {
|
|
482
|
+
if (error) {
|
|
483
|
+
reject(error);
|
|
484
|
+
}
|
|
485
|
+
resolve(guid);
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
// src/events/subjects.ts
|
|
492
|
+
var Subjects = /* @__PURE__ */ ((Subjects2) => {
|
|
493
|
+
Subjects2["TicketCreated"] = "ticket:created";
|
|
494
|
+
Subjects2["TicketUpdated"] = "ticket:updated";
|
|
495
|
+
return Subjects2;
|
|
496
|
+
})(Subjects || {});
|
|
441
497
|
export {
|
|
442
498
|
AccessTokenError,
|
|
443
499
|
AccessTokenErrorResponse,
|
|
@@ -455,13 +511,16 @@ export {
|
|
|
455
511
|
InternalError,
|
|
456
512
|
InternalErrorResponse,
|
|
457
513
|
JwtService,
|
|
514
|
+
Listener,
|
|
458
515
|
NoDataError,
|
|
459
516
|
NoEntryError,
|
|
460
517
|
NoFoundResponse,
|
|
461
518
|
NotFoundError,
|
|
462
519
|
Password,
|
|
520
|
+
Publisher,
|
|
463
521
|
ResponseStatusCode,
|
|
464
522
|
StatusCode,
|
|
523
|
+
Subjects,
|
|
465
524
|
SuccessResponse,
|
|
466
525
|
TokenExpiredError,
|
|
467
526
|
ValidationSource,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ajayjbtickets/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.32",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
|
-
"dev": "tsx
|
|
26
|
-
"clean": "del
|
|
25
|
+
"dev": "tsx watch src/index.ts",
|
|
26
|
+
"clean": "del dist/*",
|
|
27
27
|
"build": "npm run clean && tsup",
|
|
28
28
|
"release": "git add . && git commit -m \"updates\" && npm version patch && npm run build && npm publish"
|
|
29
29
|
},
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"express": "^5.1.0",
|
|
38
38
|
"jsonwebtoken": "^9.0.2",
|
|
39
39
|
"lodash": "^4.17.21",
|
|
40
|
+
"node-nats-streaming": "^0.3.2",
|
|
40
41
|
"winston": "^3.17.0",
|
|
41
42
|
"winston-daily-rotate-file": "^5.0.0",
|
|
42
43
|
"zod": "^3.24.4"
|