@nandansravesh/sendgrid-core 0.0.0
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.ts +37 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/package.json +25 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/schema.d.ts
|
|
4
|
+
declare const telegramMessageInputSchema: z.ZodObject<{
|
|
5
|
+
chatId: z.ZodString;
|
|
6
|
+
message: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
declare const telegramMessageOptionSchema: z.ZodObject<{
|
|
9
|
+
chatId: z.ZodString;
|
|
10
|
+
message: z.ZodString;
|
|
11
|
+
botToken: z.ZodString;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
declare const telegramSendMessageSchema: z.ZodObject<{
|
|
14
|
+
chat_id: z.ZodString;
|
|
15
|
+
text: z.ZodString;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
declare const telegramResponseSchema: z.ZodObject<{
|
|
18
|
+
ok: z.ZodBoolean;
|
|
19
|
+
result: z.ZodOptional<z.ZodObject<{
|
|
20
|
+
message_id: z.ZodNumber;
|
|
21
|
+
}, z.core.$strip>>;
|
|
22
|
+
description: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
declare const telegramMessageOutputSchema: z.ZodObject<{
|
|
25
|
+
ok: z.ZodLiteral<true>;
|
|
26
|
+
chatId: z.ZodString;
|
|
27
|
+
messageId: z.ZodString;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
type TelegramMessageInput = z.infer<typeof telegramMessageInputSchema>;
|
|
30
|
+
type TelegramMessageOption = z.infer<typeof telegramMessageOptionSchema>;
|
|
31
|
+
type TelegramMessageOutput = z.infer<typeof telegramMessageOutputSchema>;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/operations.d.ts
|
|
34
|
+
declare function sendTelegramMessage(options: TelegramMessageOption): Promise<TelegramMessageOutput>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { TelegramMessageInput, TelegramMessageOption, TelegramMessageOutput, sendTelegramMessage, telegramMessageInputSchema, telegramMessageOptionSchema, telegramMessageOutputSchema, telegramResponseSchema, telegramSendMessageSchema };
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/schema.ts
|
|
3
|
+
const telegramMessageInputSchema = z.object({
|
|
4
|
+
chatId: z.string().min(1, "Chat Id is required"),
|
|
5
|
+
message: z.string().min(1, "Message is required")
|
|
6
|
+
});
|
|
7
|
+
const telegramMessageOptionSchema = telegramMessageInputSchema.extend({ botToken: z.string().min(1, "Bot Token is required") });
|
|
8
|
+
const telegramSendMessageSchema = z.object({
|
|
9
|
+
chat_id: z.string(),
|
|
10
|
+
text: z.string().min(1)
|
|
11
|
+
});
|
|
12
|
+
const telegramResponseSchema = z.object({
|
|
13
|
+
ok: z.boolean(),
|
|
14
|
+
result: z.object({ message_id: z.number() }).optional(),
|
|
15
|
+
description: z.string().optional()
|
|
16
|
+
});
|
|
17
|
+
const telegramMessageOutputSchema = z.object({
|
|
18
|
+
ok: z.literal(true),
|
|
19
|
+
chatId: z.string(),
|
|
20
|
+
messageId: z.string()
|
|
21
|
+
});
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/operations.ts
|
|
24
|
+
async function sendTelegramMessage(options) {
|
|
25
|
+
const parsedInput = telegramMessageOptionSchema.parse(options);
|
|
26
|
+
const requestBody = telegramSendMessageSchema.parse({
|
|
27
|
+
chat_id: parsedInput.chatId,
|
|
28
|
+
text: parsedInput.message
|
|
29
|
+
});
|
|
30
|
+
const response = await fetch(`https://api.telegram.org/bot${parsedInput.botToken}/sendMessage`, {
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: { "Content-Type": "application/json" },
|
|
33
|
+
body: JSON.stringify(requestBody)
|
|
34
|
+
});
|
|
35
|
+
const data = telegramResponseSchema.parse(await response.json());
|
|
36
|
+
if (!response.ok || !data.ok || !data.result) throw new Error(data.description ?? "Telegram API error");
|
|
37
|
+
return telegramMessageOutputSchema.parse({
|
|
38
|
+
ok: true,
|
|
39
|
+
chatId: parsedInput.chatId,
|
|
40
|
+
messageId: data.result.message_id.toString()
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { sendTelegramMessage, telegramMessageInputSchema, telegramMessageOptionSchema, telegramMessageOutputSchema, telegramResponseSchema, telegramSendMessageSchema };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/schema.ts","../src/operations.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const telegramMessageInputSchema = z.object({\n chatId: z.string().min(1, \"Chat Id is required\"),\n message: z.string().min(1, \"Message is required\"),\n});\n\nexport const telegramMessageOptionSchema = telegramMessageInputSchema.extend({\n botToken: z.string().min(1, \"Bot Token is required\"),\n});\n\nexport const telegramSendMessageSchema = z.object({\n chat_id: z.string(),\n text: z.string().min(1),\n});\n\nexport const telegramResponseSchema = z.object({\n ok: z.boolean(),\n result: z\n .object({\n message_id: z.number(),\n })\n .optional(),\n description: z.string().optional(),\n});\n\nexport const telegramMessageOutputSchema = z.object({\n ok: z.literal(true),\n chatId: z.string(),\n messageId: z.string(),\n});\n\nexport type TelegramMessageInput = z.infer<typeof telegramMessageInputSchema>;\nexport type TelegramMessageOption = z.infer<typeof telegramMessageOptionSchema>;\nexport type TelegramMessageOutput = z.infer<typeof telegramMessageOutputSchema>;\n","import {\n TelegramMessageOption,\n telegramMessageOptionSchema,\n TelegramMessageOutput,\n telegramMessageOutputSchema,\n telegramResponseSchema,\n telegramSendMessageSchema,\n} from \"./schema\";\n\nexport async function sendTelegramMessage(\n options: TelegramMessageOption,\n): Promise<TelegramMessageOutput> {\n const parsedInput = telegramMessageOptionSchema.parse(options);\n\n const requestBody = telegramSendMessageSchema.parse({\n chat_id: parsedInput.chatId,\n text: parsedInput.message,\n });\n\n const response = await fetch(\n `https://api.telegram.org/bot${parsedInput.botToken}/sendMessage`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(requestBody),\n },\n );\n\n const data = telegramResponseSchema.parse(await response.json());\n\n if (!response.ok || !data.ok || !data.result) {\n throw new Error(data.description ?? \"Telegram API error\");\n }\n\n return telegramMessageOutputSchema.parse({\n ok: true,\n chatId: parsedInput.chatId,\n messageId: data.result.message_id.toString(),\n });\n}\n"],"mappings":";;AAEA,MAAa,6BAA6B,EAAE,OAAO;CACjD,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,qBAAqB;CAC/C,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,qBAAqB;AAClD,CAAC;AAED,MAAa,8BAA8B,2BAA2B,OAAO,EAC3E,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,uBAAuB,EACrD,CAAC;AAED,MAAa,4BAA4B,EAAE,OAAO;CAChD,SAAS,EAAE,OAAO;CAClB,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AACxB,CAAC;AAED,MAAa,yBAAyB,EAAE,OAAO;CAC7C,IAAI,EAAE,QAAQ;CACd,QAAQ,EACL,OAAO,EACN,YAAY,EAAE,OAAO,EACvB,CAAC,CAAC,CACD,SAAS;CACZ,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;AACnC,CAAC;AAED,MAAa,8BAA8B,EAAE,OAAO;CAClD,IAAI,EAAE,QAAQ,IAAI;CAClB,QAAQ,EAAE,OAAO;CACjB,WAAW,EAAE,OAAO;AACtB,CAAC;;;ACrBD,eAAsB,oBACpB,SACgC;CAChC,MAAM,cAAc,4BAA4B,MAAM,OAAO;CAE7D,MAAM,cAAc,0BAA0B,MAAM;EAClD,SAAS,YAAY;EACrB,MAAM,YAAY;CACpB,CAAC;CAED,MAAM,WAAW,MAAM,MACrB,+BAA+B,YAAY,SAAS,eACpD;EACE,QAAQ;EACR,SAAS,EACP,gBAAgB,mBAClB;EACA,MAAM,KAAK,UAAU,WAAW;CAClC,CACF;CAEA,MAAM,OAAO,uBAAuB,MAAM,MAAM,SAAS,KAAK,CAAC;CAE/D,IAAI,CAAC,SAAS,MAAM,CAAC,KAAK,MAAM,CAAC,KAAK,QACpC,MAAM,IAAI,MAAM,KAAK,eAAe,oBAAoB;CAG1D,OAAO,4BAA4B,MAAM;EACvC,IAAI;EACJ,QAAQ,YAAY;EACpB,WAAW,KAAK,OAAO,WAAW,SAAS;CAC7C,CAAC;AACH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nandansravesh/sendgrid-core",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"files": [
|
|
5
|
+
"dist"
|
|
6
|
+
],
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "Sravesh Nandan"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./src/index.ts"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsdown",
|
|
19
|
+
"pack:dry": " bun run build && npm pack --dry-run",
|
|
20
|
+
"prePublishOnly": "bun run build"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"zod": "^4.4.3"
|
|
24
|
+
}
|
|
25
|
+
}
|