@aghamdi/shared-types 0.2.0 → 0.2.1
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 +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -7,4 +7,22 @@ declare class MiaServerResponse {
|
|
|
7
7
|
static sendError: (error: any) => MiaServerResponse;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface Notification {
|
|
11
|
+
title?: string;
|
|
12
|
+
body: string;
|
|
13
|
+
badge?: number;
|
|
14
|
+
topic?: string;
|
|
15
|
+
payload?: any;
|
|
16
|
+
}
|
|
17
|
+
interface UserNotification extends Notification {
|
|
18
|
+
userId: string;
|
|
19
|
+
}
|
|
20
|
+
interface DeviceNotification extends Notification {
|
|
21
|
+
deviceId: string;
|
|
22
|
+
}
|
|
23
|
+
declare class MiaNotifications {
|
|
24
|
+
static sendtoDevice(deviceId: string, body: string): Promise<void>;
|
|
25
|
+
static sendtoUserDevices(userId: string, body: string): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { type DeviceNotification, MiaNotifications, MiaServerResponse, type UserNotification };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,22 @@ declare class MiaServerResponse {
|
|
|
7
7
|
static sendError: (error: any) => MiaServerResponse;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface Notification {
|
|
11
|
+
title?: string;
|
|
12
|
+
body: string;
|
|
13
|
+
badge?: number;
|
|
14
|
+
topic?: string;
|
|
15
|
+
payload?: any;
|
|
16
|
+
}
|
|
17
|
+
interface UserNotification extends Notification {
|
|
18
|
+
userId: string;
|
|
19
|
+
}
|
|
20
|
+
interface DeviceNotification extends Notification {
|
|
21
|
+
deviceId: string;
|
|
22
|
+
}
|
|
23
|
+
declare class MiaNotifications {
|
|
24
|
+
static sendtoDevice(deviceId: string, body: string): Promise<void>;
|
|
25
|
+
static sendtoUserDevices(userId: string, body: string): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { type DeviceNotification, MiaNotifications, MiaServerResponse, type UserNotification };
|
package/dist/index.js
CHANGED
|
@@ -16,10 +16,31 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
19
39
|
|
|
20
40
|
// src/index.ts
|
|
21
41
|
var src_exports = {};
|
|
22
42
|
__export(src_exports, {
|
|
43
|
+
MiaNotifications: () => MiaNotifications,
|
|
23
44
|
MiaServerResponse: () => MiaServerResponse
|
|
24
45
|
});
|
|
25
46
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -51,8 +72,38 @@ MiaServerResponse.sendError = (error) => {
|
|
|
51
72
|
};
|
|
52
73
|
return response;
|
|
53
74
|
};
|
|
75
|
+
|
|
76
|
+
// src/notifications.ts
|
|
77
|
+
var import_nats = require("nats");
|
|
78
|
+
var MiaNotifications = class {
|
|
79
|
+
static sendtoDevice(deviceId, body) {
|
|
80
|
+
return __async(this, null, function* () {
|
|
81
|
+
if (!process.env.NATS_HOST) {
|
|
82
|
+
throw new Error("NATS_HOST ENV is not defined");
|
|
83
|
+
}
|
|
84
|
+
const nc = yield (0, import_nats.connect)({ servers: process.env.NATS_HOST });
|
|
85
|
+
const jc = (0, import_nats.JSONCodec)();
|
|
86
|
+
const message = { deviceId, body };
|
|
87
|
+
nc.publish("mia.notifications.test", jc.encode({ message }));
|
|
88
|
+
yield nc.drain();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
static sendtoUserDevices(userId, body) {
|
|
92
|
+
return __async(this, null, function* () {
|
|
93
|
+
if (!process.env.NATS_HOST) {
|
|
94
|
+
throw new Error("NATS_HOST ENV is not defined");
|
|
95
|
+
}
|
|
96
|
+
const nc = yield (0, import_nats.connect)({ servers: process.env.NATS_HOST });
|
|
97
|
+
const jc = (0, import_nats.JSONCodec)();
|
|
98
|
+
const message = { userId, body };
|
|
99
|
+
nc.publish("mia.notifications.test", jc.encode({ message }));
|
|
100
|
+
yield nc.drain();
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
54
104
|
// Annotate the CommonJS export names for ESM import in node:
|
|
55
105
|
0 && (module.exports = {
|
|
106
|
+
MiaNotifications,
|
|
56
107
|
MiaServerResponse
|
|
57
108
|
});
|
|
58
109
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/mia-server-response.ts"],"sourcesContent":["export * from './mia-server-response'","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: 200,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (error: any) => {\n const response: MiaServerResponse = {\n status: 400,\n message: \"Failed\",\n data: error\n };\n return response;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/mia-server-response.ts","../src/notifications.ts"],"sourcesContent":["export * from './mia-server-response'\nexport * from './notifications'","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: 200,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (error: any) => {\n const response: MiaServerResponse = {\n status: 400,\n message: \"Failed\",\n data: error\n };\n return response;\n }\n}\n","import { connect, JSONCodec } from \"nats\";\n\ninterface Notification {\n title?: string,\n body: string,\n badge?: number,\n topic?: string,\n payload?: any\n}\nexport interface UserNotification extends Notification {\n userId: string\n}\nexport interface DeviceNotification extends Notification {\n deviceId: string\n}\n\nexport class MiaNotifications {\n static async sendtoDevice(deviceId: string, body: string) {\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 const message: DeviceNotification = { deviceId, body };\n nc.publish(\"mia.notifications.test\", jc.encode({ message }));\n await nc.drain();\n }\n static async sendtoUserDevices(userId: string, body: string) {\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 const message: UserNotification = { userId, body };\n nc.publish(\"mia.notifications.test\", jc.encode({ message }));\n await nc.drain();\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,oBAAN,MAAwB;AA6B/B;AA7Ba,kBAKJ,OAAO,CAAC,QAAgB,SAAiB,SAAc;AAC5D,QAAM,WAA8B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|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
1
22
|
// src/mia-server-response.ts
|
|
2
23
|
var MiaServerResponse = class {
|
|
3
24
|
};
|
|
@@ -25,7 +46,37 @@ MiaServerResponse.sendError = (error) => {
|
|
|
25
46
|
};
|
|
26
47
|
return response;
|
|
27
48
|
};
|
|
49
|
+
|
|
50
|
+
// src/notifications.ts
|
|
51
|
+
import { connect, JSONCodec } from "nats";
|
|
52
|
+
var MiaNotifications = class {
|
|
53
|
+
static sendtoDevice(deviceId, body) {
|
|
54
|
+
return __async(this, null, function* () {
|
|
55
|
+
if (!process.env.NATS_HOST) {
|
|
56
|
+
throw new Error("NATS_HOST ENV is not defined");
|
|
57
|
+
}
|
|
58
|
+
const nc = yield connect({ servers: process.env.NATS_HOST });
|
|
59
|
+
const jc = JSONCodec();
|
|
60
|
+
const message = { deviceId, body };
|
|
61
|
+
nc.publish("mia.notifications.test", jc.encode({ message }));
|
|
62
|
+
yield nc.drain();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
static sendtoUserDevices(userId, body) {
|
|
66
|
+
return __async(this, null, function* () {
|
|
67
|
+
if (!process.env.NATS_HOST) {
|
|
68
|
+
throw new Error("NATS_HOST ENV is not defined");
|
|
69
|
+
}
|
|
70
|
+
const nc = yield connect({ servers: process.env.NATS_HOST });
|
|
71
|
+
const jc = JSONCodec();
|
|
72
|
+
const message = { userId, body };
|
|
73
|
+
nc.publish("mia.notifications.test", jc.encode({ message }));
|
|
74
|
+
yield nc.drain();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
};
|
|
28
78
|
export {
|
|
79
|
+
MiaNotifications,
|
|
29
80
|
MiaServerResponse
|
|
30
81
|
};
|
|
31
82
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mia-server-response.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: 200,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (error: any) => {\n const response: MiaServerResponse = {\n status: 400,\n message: \"Failed\",\n data: error\n };\n return response;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/mia-server-response.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: 200,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (error: any) => {\n const response: MiaServerResponse = {\n status: 400,\n message: \"Failed\",\n data: error\n };\n return response;\n }\n}\n","import { connect, JSONCodec } from \"nats\";\n\ninterface Notification {\n title?: string,\n body: string,\n badge?: number,\n topic?: string,\n payload?: any\n}\nexport interface UserNotification extends Notification {\n userId: string\n}\nexport interface DeviceNotification extends Notification {\n deviceId: string\n}\n\nexport class MiaNotifications {\n static async sendtoDevice(deviceId: string, body: string) {\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 const message: DeviceNotification = { deviceId, body };\n nc.publish(\"mia.notifications.test\", jc.encode({ message }));\n await nc.drain();\n }\n static async sendtoUserDevices(userId: string, body: string) {\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 const message: UserNotification = { userId, body };\n nc.publish(\"mia.notifications.test\", jc.encode({ message }));\n await nc.drain();\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,SAAc;AAC/B,QAAM,WAA8B;AAAA,IAClC,QAAQ;AAAA,IACR,SAAS;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AApBW,kBAqBJ,YAAY,CAAC,UAAe;AACjC,QAAM,WAA8B;AAAA,IAClC,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,MAAM;AAAA,EACR;AACA,SAAO;AACT;;;AC5BF,SAAS,SAAS,iBAAiB;AAgB5B,IAAM,mBAAN,MAAuB;AAAA,EAC5B,OAAa,aAAa,UAAkB,MAAc;AAAA;AACxD,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,UAA8B,EAAE,UAAU,KAAK;AACrD,SAAG,QAAQ,0BAA0B,GAAG,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC3D,YAAM,GAAG,MAAM;AAAA,IACjB;AAAA;AAAA,EACA,OAAa,kBAAkB,QAAg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