@mrb-dev/sendkit 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.
@@ -0,0 +1 @@
1
+ export { };
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { z } from "zod";
4
+ import { homedir } from "node:os";
5
+ import { dirname, join } from "node:path";
6
+ import { sendTelegramMessage } from "@mrb-dev/sendkit-core";
7
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
8
+ //#region src/index.ts
9
+ const program = new Command();
10
+ const configPath = join(homedir(), ".config", "sendkit", "config.json");
11
+ const cliConfigSchema = z.object({ telegramBotToken: z.string().min(1).optional() });
12
+ function writeTelegramBotToken(token) {
13
+ mkdirSync(dirname(configPath), { recursive: true });
14
+ writeFileSync(configPath, `${JSON.stringify({ telegramBotToken: token }, null, 2)}\n`, { mode: 384 });
15
+ }
16
+ function getTelegramBotToken() {
17
+ if (!existsSync(configPath)) throw new Error(`Config file not found at ${configPath}. Please set the TELEGRAM_BOT_TOKEN environment variable by running 'sendkit init --telegram-bot-token <botToken>'.`);
18
+ const token = cliConfigSchema.parse(JSON.parse(readFileSync(configPath, "utf-8"))).telegramBotToken;
19
+ if (!token) throw new Error(`Telegram bot token not found in config file at ${configPath}. Please set the TELEGRAM_BOT_TOKEN environment variable or create the config file.`);
20
+ return token;
21
+ }
22
+ program.name("sendkit").description("SendKit CLI backed by sendkit-core");
23
+ program.command("init").description("Configure SendKit CLI local settings").requiredOption("--telegram-bot-token <botToken>", "Telegram bot token").action(async (options) => {
24
+ writeTelegramBotToken(options.telegramBotToken);
25
+ console.log(`Telegram bot token saved to ${configPath}`);
26
+ });
27
+ program.command("telegram").description("Send a Telegram message").argument("<chatId>", "Telegram chat ID").argument("<message>", "Message text to send").action(async (chatId, message) => {
28
+ const result = await sendTelegramMessage({
29
+ botToken: getTelegramBotToken(),
30
+ chatId,
31
+ message
32
+ });
33
+ console.log(JSON.stringify(result, null, 2));
34
+ });
35
+ await program.parseAsync(process.argv).catch((err) => {
36
+ console.error(err instanceof Error ? err.message : String(err));
37
+ process.exitCode = 1;
38
+ });
39
+ //#endregion
40
+ export {};
41
+
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Command } from \"commander\";\nimport { z } from \"zod\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { sendTelegramMessage } from \"@mrb-dev/sendkit-core\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\n\nconst program = new Command();\nconst configPath = join(homedir(), \".config\", \"sendkit\", \"config.json\");\nconst cliConfigSchema = z.object({\n telegramBotToken: z.string().min(1).optional(),\n});\n\nfunction writeTelegramBotToken(token: string) {\n mkdirSync(dirname(configPath), { recursive: true });\n writeFileSync(configPath, `${JSON.stringify({ telegramBotToken: token }, null, 2)}\\n`, {\n mode: 0o600,\n });\n}\n\nfunction getTelegramBotToken() {\n if (!existsSync(configPath)) {\n throw new Error(\n `Config file not found at ${configPath}. Please set the TELEGRAM_BOT_TOKEN environment variable by running 'sendkit init --telegram-bot-token <botToken>'.`,\n );\n }\n\n const config = cliConfigSchema.parse(JSON.parse(readFileSync(configPath, \"utf-8\")));\n const token = config.telegramBotToken;\n\n if (!token) {\n throw new Error(\n `Telegram bot token not found in config file at ${configPath}. Please set the TELEGRAM_BOT_TOKEN environment variable or create the config file.`,\n );\n }\n\n return token;\n}\n\nprogram.name(\"sendkit\").description(\"SendKit CLI backed by sendkit-core\");\n\nprogram\n .command(\"init\")\n .description(\"Configure SendKit CLI local settings\")\n .requiredOption(\"--telegram-bot-token <botToken>\", \"Telegram bot token\")\n .action(async (options: { telegramBotToken: string }) => {\n writeTelegramBotToken(options.telegramBotToken);\n console.log(`Telegram bot token saved to ${configPath}`);\n });\n\nprogram\n .command(\"telegram\")\n .description(\"Send a Telegram message\")\n .argument(\"<chatId>\", \"Telegram chat ID\")\n .argument(\"<message>\", \"Message text to send\")\n .action(async (chatId: string, message: string) => {\n const result = await sendTelegramMessage({\n botToken: getTelegramBotToken(),\n chatId: chatId,\n message: message,\n });\n\n console.log(JSON.stringify(result, null, 2));\n });\n\nawait program.parseAsync(process.argv).catch((err: unknown) => {\n console.error(err instanceof Error ? err.message : String(err));\n process.exitCode = 1;\n});\n"],"mappings":";;;;;;;;AAQA,MAAM,UAAU,IAAI,QAAQ;AAC5B,MAAM,aAAa,KAAK,QAAQ,GAAG,WAAW,WAAW,aAAa;AACtE,MAAM,kBAAkB,EAAE,OAAO,EAC/B,kBAAkB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAC/C,CAAC;AAED,SAAS,sBAAsB,OAAe;CAC5C,UAAU,QAAQ,UAAU,GAAG,EAAE,WAAW,KAAK,CAAC;CAClD,cAAc,YAAY,GAAG,KAAK,UAAU,EAAE,kBAAkB,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK,EACrF,MAAM,IACR,CAAC;AACH;AAEA,SAAS,sBAAsB;CAC7B,IAAI,CAAC,WAAW,UAAU,GACxB,MAAM,IAAI,MACR,4BAA4B,WAAW,oHACzC;CAIF,MAAM,QADS,gBAAgB,MAAM,KAAK,MAAM,aAAa,YAAY,OAAO,CAAC,CAC9D,CAAC,CAAC;CAErB,IAAI,CAAC,OACH,MAAM,IAAI,MACR,kDAAkD,WAAW,oFAC/D;CAGF,OAAO;AACT;AAEA,QAAQ,KAAK,SAAS,CAAC,CAAC,YAAY,oCAAoC;AAExE,QACG,QAAQ,MAAM,CAAC,CACf,YAAY,sCAAsC,CAAC,CACnD,eAAe,mCAAmC,oBAAoB,CAAC,CACvE,OAAO,OAAO,YAA0C;CACvD,sBAAsB,QAAQ,gBAAgB;CAC9C,QAAQ,IAAI,+BAA+B,YAAY;AACzD,CAAC;AAEH,QACG,QAAQ,UAAU,CAAC,CACnB,YAAY,yBAAyB,CAAC,CACtC,SAAS,YAAY,kBAAkB,CAAC,CACxC,SAAS,aAAa,sBAAsB,CAAC,CAC7C,OAAO,OAAO,QAAgB,YAAoB;CACjD,MAAM,SAAS,MAAM,oBAAoB;EACvC,UAAU,oBAAoB;EACtB;EACC;CACX,CAAC;CAED,QAAQ,IAAI,KAAK,UAAU,QAAQ,MAAM,CAAC,CAAC;AAC7C,CAAC;AAEH,MAAM,QAAQ,WAAW,QAAQ,IAAI,CAAC,CAAC,OAAO,QAAiB;CAC7D,QAAQ,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;CAC9D,QAAQ,WAAW;AACrB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@mrb-dev/sendkit",
3
+ "version": "0.0.0",
4
+ "bin": {
5
+ "sendkit": "./dist/index.js"
6
+ },
7
+ "type": "module",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "main": "dist/index.js",
12
+ "module": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "dependencies": {
24
+ "commander": "^15.0.0",
25
+ "@mrb-dev/sendkit-core": "0.0.0",
26
+ "zod": "^4.4.3"
27
+ },
28
+ "scripts": {
29
+ "build": "tsdown",
30
+ "pack:dry": "bun run build && bun pm pack --dry-run",
31
+ "prepublishOnly": "bun run build"
32
+ }
33
+ }