@aghamdi/shared-types 0.2.11 → 0.2.13
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 +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -3,8 +3,8 @@ 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: (
|
|
7
|
-
static sendError: (
|
|
6
|
+
static sendData: (data: any, status?: number) => MiaServerResponse;
|
|
7
|
+
static sendError: (error: any, status?: number) => MiaServerResponse;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
interface Notification {
|
|
@@ -23,11 +23,15 @@ interface DeviceNotification extends Notification {
|
|
|
23
23
|
interface TopicNotification extends Notification {
|
|
24
24
|
topic: string;
|
|
25
25
|
}
|
|
26
|
+
interface SmsNotification extends Notification {
|
|
27
|
+
mobile: string;
|
|
28
|
+
}
|
|
26
29
|
declare class MiaNotifications {
|
|
27
30
|
static sendtoDevice(message: DeviceNotification): Promise<void>;
|
|
28
31
|
static sendtoUserDevices(message: UserNotification): Promise<void>;
|
|
29
32
|
static sendtoTopic(message: TopicNotification): Promise<void>;
|
|
30
|
-
static
|
|
33
|
+
static sendtoSms(message: SmsNotification): Promise<void>;
|
|
34
|
+
static topicFormatter: (topic: string) => string;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
declare class MessagingBus {
|
|
@@ -35,4 +39,4 @@ declare class MessagingBus {
|
|
|
35
39
|
static publish(channel: string, message: any): Promise<void>;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
export { type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, type Notification, type TopicNotification, type UserNotification };
|
|
42
|
+
export { type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, type Notification, type SmsNotification, type TopicNotification, type UserNotification };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ 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: (
|
|
7
|
-
static sendError: (
|
|
6
|
+
static sendData: (data: any, status?: number) => MiaServerResponse;
|
|
7
|
+
static sendError: (error: any, status?: number) => MiaServerResponse;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
interface Notification {
|
|
@@ -23,11 +23,15 @@ interface DeviceNotification extends Notification {
|
|
|
23
23
|
interface TopicNotification extends Notification {
|
|
24
24
|
topic: string;
|
|
25
25
|
}
|
|
26
|
+
interface SmsNotification extends Notification {
|
|
27
|
+
mobile: string;
|
|
28
|
+
}
|
|
26
29
|
declare class MiaNotifications {
|
|
27
30
|
static sendtoDevice(message: DeviceNotification): Promise<void>;
|
|
28
31
|
static sendtoUserDevices(message: UserNotification): Promise<void>;
|
|
29
32
|
static sendtoTopic(message: TopicNotification): Promise<void>;
|
|
30
|
-
static
|
|
33
|
+
static sendtoSms(message: SmsNotification): Promise<void>;
|
|
34
|
+
static topicFormatter: (topic: string) => string;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
declare class MessagingBus {
|
|
@@ -35,4 +39,4 @@ declare class MessagingBus {
|
|
|
35
39
|
static publish(channel: string, message: any): Promise<void>;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
export { type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, type Notification, type TopicNotification, type UserNotification };
|
|
42
|
+
export { type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, type Notification, type SmsNotification, type TopicNotification, type UserNotification };
|
package/dist/index.js
CHANGED
|
@@ -61,7 +61,7 @@ MiaServerResponse.send = (status, message, data) => {
|
|
|
61
61
|
};
|
|
62
62
|
return response;
|
|
63
63
|
};
|
|
64
|
-
MiaServerResponse.sendData = (status = 200
|
|
64
|
+
MiaServerResponse.sendData = (data, status = 200) => {
|
|
65
65
|
const response = {
|
|
66
66
|
status,
|
|
67
67
|
message: "Success",
|
|
@@ -69,7 +69,7 @@ MiaServerResponse.sendData = (status = 200, data) => {
|
|
|
69
69
|
};
|
|
70
70
|
return response;
|
|
71
71
|
};
|
|
72
|
-
MiaServerResponse.sendError = (status = 400
|
|
72
|
+
MiaServerResponse.sendError = (error, status = 400) => {
|
|
73
73
|
const response = {
|
|
74
74
|
status,
|
|
75
75
|
message: "Failed",
|
|
@@ -141,8 +141,13 @@ var MiaNotifications = class {
|
|
|
141
141
|
yield MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || "general"}`, message);
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
+
static sendtoSms(message) {
|
|
145
|
+
return __async(this, null, function* () {
|
|
146
|
+
yield MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || "general"}`, message);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
144
149
|
};
|
|
145
|
-
MiaNotifications.
|
|
150
|
+
MiaNotifications.topicFormatter = (topic) => "/topics/" + topic.replace(/\//g, "~");
|
|
146
151
|
// Annotate the CommonJS export names for ESM import in node:
|
|
147
152
|
0 && (module.exports = {
|
|
148
153
|
MessagingBus,
|
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'\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
|
|
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 = (data: any, status: number = 200) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (error: any, status: number = 400) => {\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}\nexport interface SmsNotification extends Notification {\n mobile: 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 static async sendtoSms(message: SmsNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || \"general\"}`, message);\n }\n static topicFormatter = (topic: string) => \"/topics/\" + topic.replace(/\\//g, \"~\")\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,MAAW,SAAiB,QAAQ;AACrD,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AApBW,kBAqBJ,YAAY,CAAC,OAAY,SAAiB,QAAQ;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,iBAAi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aAAa,MAAM,QAAQ,OAAO,GAAG;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -34,7 +34,7 @@ MiaServerResponse.send = (status, message, data) => {
|
|
|
34
34
|
};
|
|
35
35
|
return response;
|
|
36
36
|
};
|
|
37
|
-
MiaServerResponse.sendData = (status = 200
|
|
37
|
+
MiaServerResponse.sendData = (data, status = 200) => {
|
|
38
38
|
const response = {
|
|
39
39
|
status,
|
|
40
40
|
message: "Success",
|
|
@@ -42,7 +42,7 @@ MiaServerResponse.sendData = (status = 200, data) => {
|
|
|
42
42
|
};
|
|
43
43
|
return response;
|
|
44
44
|
};
|
|
45
|
-
MiaServerResponse.sendError = (status = 400
|
|
45
|
+
MiaServerResponse.sendError = (error, status = 400) => {
|
|
46
46
|
const response = {
|
|
47
47
|
status,
|
|
48
48
|
message: "Failed",
|
|
@@ -114,8 +114,13 @@ var MiaNotifications = class {
|
|
|
114
114
|
yield MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || "general"}`, message);
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
|
+
static sendtoSms(message) {
|
|
118
|
+
return __async(this, null, function* () {
|
|
119
|
+
yield MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || "general"}`, message);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
117
122
|
};
|
|
118
|
-
MiaNotifications.
|
|
123
|
+
MiaNotifications.topicFormatter = (topic) => "/topics/" + topic.replace(/\//g, "~");
|
|
119
124
|
export {
|
|
120
125
|
MessagingBus,
|
|
121
126
|
MiaNotifications,
|
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 = (status: number = 200
|
|
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, status: number = 200) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (error: any, status: number = 400) => {\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}\nexport interface SmsNotification extends Notification {\n mobile: 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 static async sendtoSms(message: SmsNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.APP_HOSTNAME || \"general\"}`, message);\n }\n static topicFormatter = (topic: string) => \"/topics/\" + topic.replace(/\\//g, \"~\")\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,MAAW,SAAiB,QAAQ;AACrD,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AApBW,kBAqBJ,YAAY,CAAC,OAAY,SAAiB,QAAQ;AACvD,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA,SAAS;AAAA,IACT,MAAM;AAAA,EACR;AACA,SAAO;AACT;;;AC5BF,SAAS,SAAS,iBAAiB;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,MAAM,QAAQ,EAAE,SAAS,QAAQ,IAAI,UAAU,CAAC;AAC3D,YAAM,KAAK,UAAU;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,k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