@aghamdi/shared-types 0.2.7 → 0.2.10
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.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -3,15 +3,14 @@ declare class MiaServerResponse {
|
|
|
3
3
|
message?: string;
|
|
4
4
|
data: any;
|
|
5
5
|
static send: (status: number, message: string, data: any) => MiaServerResponse;
|
|
6
|
-
static sendData: (data: any) => MiaServerResponse;
|
|
7
|
-
static sendError: (error: any) => MiaServerResponse;
|
|
6
|
+
static sendData: (status: number | undefined, data: any) => MiaServerResponse;
|
|
7
|
+
static sendError: (status: number | undefined, error: any) => MiaServerResponse;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
interface Notification {
|
|
11
11
|
title?: string;
|
|
12
12
|
body: string;
|
|
13
13
|
badge?: number;
|
|
14
|
-
topic?: string;
|
|
15
14
|
payload?: any;
|
|
16
15
|
target?: string;
|
|
17
16
|
}
|
|
@@ -21,9 +20,13 @@ interface UserNotification extends Notification {
|
|
|
21
20
|
interface DeviceNotification extends Notification {
|
|
22
21
|
deviceId: string;
|
|
23
22
|
}
|
|
23
|
+
interface TopicNotification extends Notification {
|
|
24
|
+
topic: string;
|
|
25
|
+
}
|
|
24
26
|
declare class MiaNotifications {
|
|
25
27
|
static sendtoDevice(message: DeviceNotification): Promise<void>;
|
|
26
28
|
static sendtoUserDevices(message: UserNotification): Promise<void>;
|
|
29
|
+
static sendtoTopic(message: TopicNotification): Promise<void>;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
declare class MessagingBus {
|
|
@@ -31,4 +34,4 @@ declare class MessagingBus {
|
|
|
31
34
|
static publish(channel: string, message: any): Promise<void>;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
export { type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, type Notification, type UserNotification };
|
|
37
|
+
export { type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, type Notification, type TopicNotification, type UserNotification };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,15 +3,14 @@ declare class MiaServerResponse {
|
|
|
3
3
|
message?: string;
|
|
4
4
|
data: any;
|
|
5
5
|
static send: (status: number, message: string, data: any) => MiaServerResponse;
|
|
6
|
-
static sendData: (data: any) => MiaServerResponse;
|
|
7
|
-
static sendError: (error: any) => MiaServerResponse;
|
|
6
|
+
static sendData: (status: number | undefined, data: any) => MiaServerResponse;
|
|
7
|
+
static sendError: (status: number | undefined, error: any) => MiaServerResponse;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
interface Notification {
|
|
11
11
|
title?: string;
|
|
12
12
|
body: string;
|
|
13
13
|
badge?: number;
|
|
14
|
-
topic?: string;
|
|
15
14
|
payload?: any;
|
|
16
15
|
target?: string;
|
|
17
16
|
}
|
|
@@ -21,9 +20,13 @@ interface UserNotification extends Notification {
|
|
|
21
20
|
interface DeviceNotification extends Notification {
|
|
22
21
|
deviceId: string;
|
|
23
22
|
}
|
|
23
|
+
interface TopicNotification extends Notification {
|
|
24
|
+
topic: string;
|
|
25
|
+
}
|
|
24
26
|
declare class MiaNotifications {
|
|
25
27
|
static sendtoDevice(message: DeviceNotification): Promise<void>;
|
|
26
28
|
static sendtoUserDevices(message: UserNotification): Promise<void>;
|
|
29
|
+
static sendtoTopic(message: TopicNotification): Promise<void>;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
declare class MessagingBus {
|
|
@@ -31,4 +34,4 @@ declare class MessagingBus {
|
|
|
31
34
|
static publish(channel: string, message: any): Promise<void>;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
export { type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, type Notification, type UserNotification };
|
|
37
|
+
export { type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, type Notification, type TopicNotification, type UserNotification };
|
package/dist/index.js
CHANGED
|
@@ -61,17 +61,17 @@ MiaServerResponse.send = (status, message, data) => {
|
|
|
61
61
|
};
|
|
62
62
|
return response;
|
|
63
63
|
};
|
|
64
|
-
MiaServerResponse.sendData = (data) => {
|
|
64
|
+
MiaServerResponse.sendData = (status = 200, data) => {
|
|
65
65
|
const response = {
|
|
66
|
-
status
|
|
66
|
+
status,
|
|
67
67
|
message: "Success",
|
|
68
68
|
data
|
|
69
69
|
};
|
|
70
70
|
return response;
|
|
71
71
|
};
|
|
72
|
-
MiaServerResponse.sendError = (error) => {
|
|
72
|
+
MiaServerResponse.sendError = (status = 400, error) => {
|
|
73
73
|
const response = {
|
|
74
|
-
status
|
|
74
|
+
status,
|
|
75
75
|
message: "Failed",
|
|
76
76
|
data: error
|
|
77
77
|
};
|
|
@@ -136,6 +136,11 @@ var MiaNotifications = class {
|
|
|
136
136
|
yield MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || "general"}`, message);
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
|
+
static sendtoTopic(message) {
|
|
140
|
+
return __async(this, null, function* () {
|
|
141
|
+
yield MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || "general"}`, message);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
139
144
|
};
|
|
140
145
|
// Annotate the CommonJS export names for ESM import in node:
|
|
141
146
|
0 && (module.exports = {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/mia-server-response.ts","../src/messaging-bus.ts","../src/notifications.ts"],"sourcesContent":["export * from './mia-server-response'\nexport * from './notifications'\nexport * from './messaging-bus'","export class MiaServerResponse {\n status?: number;\n message?: string;\n data: any;\n\n static send = (status: number, message: string, data: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: message,\n data: data\n };\n return response;\n }\n static sendData = (data: any) => {\n const response: MiaServerResponse = {\n status:
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/mia-server-response.ts","../src/messaging-bus.ts","../src/notifications.ts"],"sourcesContent":["export * from './mia-server-response'\nexport * from './notifications'\nexport * from './messaging-bus'\n","export class MiaServerResponse {\n status?: number;\n message?: string;\n data: any;\n\n static send = (status: number, message: string, data: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: message,\n data: data\n };\n return response;\n }\n static sendData = (status: number = 200, data: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (status: number = 400, error: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Failed\",\n data: error\n };\n return response;\n }\n}\n","import { connect, JSONCodec } from \"nats\";\n\nexport class MessagingBus {\n static async subscribe(channel: string, queue: string, onMessage: Function) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const sc = JSONCodec();\n const subscription = nc.subscribe(channel, { queue: queue });\n\n (async (sub) => {\n\n console.log(`listening for ${sub.getSubject()} requests...`);\n\n for await (const m of sub) {\n const msg = sc.decode(m.data);\n onMessage(msg);\n }\n\n console.log(`subscription ${sub.getSubject()} drained.`);\n })(subscription);\n }\n\n static async publish(channel: string, message: any) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const jc = JSONCodec();\n nc.publish(channel, jc.encode(message));\n await nc.drain();\n }\n}\n","import { MessagingBus } from \"./messaging-bus\";\nexport interface Notification {\n title?: string,\n body: string,\n badge?: number,\n payload?: any,\n target?: string\n}\nexport interface UserNotification extends Notification {\n userId: string\n}\nexport interface DeviceNotification extends Notification {\n deviceId: string\n}\nexport interface TopicNotification extends Notification {\n topic: string,\n}\n\nexport class MiaNotifications {\n static async sendtoDevice(message: DeviceNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || \"general\"}`, message);\n }\n static async sendtoUserDevices(message: UserNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || \"general\"}`, message);\n }\n static async sendtoTopic(message: TopicNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || \"general\"}`, message);\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,oBAAN,MAAwB;AA6B/B;AA7Ba,kBAKJ,OAAO,CAAC,QAAgB,SAAiB,SAAc;AAC5D,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO;AACT;AAZW,kBAaJ,WAAW,CAAC,SAAiB,KAAK,SAAc;AACrD,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AApBW,kBAqBJ,YAAY,CAAC,SAAiB,KAAK,UAAe;AACvD,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA,SAAS;AAAA,IACT,MAAM;AAAA,EACR;AACA,SAAO;AACT;;;AC5BF,kBAAmC;AAE5B,IAAM,eAAN,MAAmB;AAAA,EACxB,OAAa,UAAU,SAAiB,OAAe,WAAqB;AAAA;AAC1E,UAAI,CAAC,QAAQ,IAAI,WAAW;AAC1B,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAChD;AACA,YAAM,KAAK,UAAM,qBAAQ,EAAE,SAAS,QAAQ,IAAI,UAAU,CAAC;AAC3D,YAAM,SAAK,uBAAU;AACrB,YAAM,eAAe,GAAG,UAAU,SAAS,EAAE,MAAa,CAAC;AAE3D,OAAC,CAAO,QAAQ;AAEd,gBAAQ,IAAI,iBAAiB,IAAI,WAAW,CAAC,cAAc;AAE3D;AAAA,qCAAsB,MAAtB,0EAA2B;AAAhB,kBAAM,IAAjB;AACE,kBAAM,MAAM,GAAG,OAAO,EAAE,IAAI;AAC5B,sBAAU,GAAG;AAAA,UACf;AAAA,iBAHA,MAfN;AAeM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,gBAAQ,IAAI,gBAAgB,IAAI,WAAW,CAAC,WAAW;AAAA,MACzD,IAAG,YAAY;AAAA,IACjB;AAAA;AAAA,EAEA,OAAa,QAAQ,SAAiB,SAAc;AAAA;AAClD,UAAI,CAAC,QAAQ,IAAI,WAAW;AAC1B,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAChD;AACA,YAAM,KAAK,UAAM,qBAAQ,EAAE,SAAS,QAAQ,IAAI,UAAU,CAAC;AAC3D,YAAM,SAAK,uBAAU;AACrB,SAAG,QAAQ,SAAS,GAAG,OAAO,OAAO,CAAC;AACtC,YAAM,GAAG,MAAM;AAAA,IACjB;AAAA;AACF;;;ACfO,IAAM,mBAAN,MAAuB;AAAA,EAC5B,OAAa,aAAa,SAA6B;AAAA;AACrD,YAAM,aAAa,QAAQ,qBAAqB,QAAQ,IAAI,gBAAgB,SAAS,IAAI,OAAO;AAAA,IAClG;AAAA;AAAA,EACA,OAAa,kBAAkB,SAA2B;AAAA;AACxD,YAAM,aAAa,QAAQ,qBAAqB,QAAQ,IAAI,gBAAgB,SAAS,IAAI,OAAO;AAAA,IAClG;AAAA;AAAA,EACA,OAAa,YAAY,SAA4B;AAAA;AACnD,YAAM,aAAa,QAAQ,qBAAqB,QAAQ,IAAI,gBAAgB,SAAS,IAAI,OAAO;AAAA,IAClG;AAAA;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -34,17 +34,17 @@ MiaServerResponse.send = (status, message, data) => {
|
|
|
34
34
|
};
|
|
35
35
|
return response;
|
|
36
36
|
};
|
|
37
|
-
MiaServerResponse.sendData = (data) => {
|
|
37
|
+
MiaServerResponse.sendData = (status = 200, data) => {
|
|
38
38
|
const response = {
|
|
39
|
-
status
|
|
39
|
+
status,
|
|
40
40
|
message: "Success",
|
|
41
41
|
data
|
|
42
42
|
};
|
|
43
43
|
return response;
|
|
44
44
|
};
|
|
45
|
-
MiaServerResponse.sendError = (error) => {
|
|
45
|
+
MiaServerResponse.sendError = (status = 400, error) => {
|
|
46
46
|
const response = {
|
|
47
|
-
status
|
|
47
|
+
status,
|
|
48
48
|
message: "Failed",
|
|
49
49
|
data: error
|
|
50
50
|
};
|
|
@@ -109,6 +109,11 @@ var MiaNotifications = class {
|
|
|
109
109
|
yield MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || "general"}`, message);
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
+
static sendtoTopic(message) {
|
|
113
|
+
return __async(this, null, function* () {
|
|
114
|
+
yield MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || "general"}`, message);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
112
117
|
};
|
|
113
118
|
export {
|
|
114
119
|
MessagingBus,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mia-server-response.ts","../src/messaging-bus.ts","../src/notifications.ts"],"sourcesContent":["export class MiaServerResponse {\n status?: number;\n message?: string;\n data: any;\n\n static send = (status: number, message: string, data: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: message,\n data: data\n };\n return response;\n }\n static sendData = (data: any) => {\n const response: MiaServerResponse = {\n status:
|
|
1
|
+
{"version":3,"sources":["../src/mia-server-response.ts","../src/messaging-bus.ts","../src/notifications.ts"],"sourcesContent":["export class MiaServerResponse {\n status?: number;\n message?: string;\n data: any;\n\n static send = (status: number, message: string, data: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: message,\n data: data\n };\n return response;\n }\n static sendData = (status: number = 200, data: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (status: number = 400, error: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Failed\",\n data: error\n };\n return response;\n }\n}\n","import { connect, JSONCodec } from \"nats\";\n\nexport class MessagingBus {\n static async subscribe(channel: string, queue: string, onMessage: Function) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const sc = JSONCodec();\n const subscription = nc.subscribe(channel, { queue: queue });\n\n (async (sub) => {\n\n console.log(`listening for ${sub.getSubject()} requests...`);\n\n for await (const m of sub) {\n const msg = sc.decode(m.data);\n onMessage(msg);\n }\n\n console.log(`subscription ${sub.getSubject()} drained.`);\n })(subscription);\n }\n\n static async publish(channel: string, message: any) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const jc = JSONCodec();\n nc.publish(channel, jc.encode(message));\n await nc.drain();\n }\n}\n","import { MessagingBus } from \"./messaging-bus\";\nexport interface Notification {\n title?: string,\n body: string,\n badge?: number,\n payload?: any,\n target?: string\n}\nexport interface UserNotification extends Notification {\n userId: string\n}\nexport interface DeviceNotification extends Notification {\n deviceId: string\n}\nexport interface TopicNotification extends Notification {\n topic: string,\n}\n\nexport class MiaNotifications {\n static async sendtoDevice(message: DeviceNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || \"general\"}`, message);\n }\n static async sendtoUserDevices(message: UserNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || \"general\"}`, message);\n }\n static async sendtoTopic(message: TopicNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || \"general\"}`, message);\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,IAAM,oBAAN,MAAwB;AA6B/B;AA7Ba,kBAKJ,OAAO,CAAC,QAAgB,SAAiB,SAAc;AAC5D,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO;AACT;AAZW,kBAaJ,WAAW,CAAC,SAAiB,KAAK,SAAc;AACr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