zelapi 0.0.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.
@@ -0,0 +1,83 @@
1
+ [![ZelApi](./media/image.jpg)](https://zelapioffciall.koyeb.app)
2
+
3
+ <p align="center">
4
+ <a href="https://www.npmjs.com/package/zelapi">
5
+ <img src="https://img.shields.io/npm/v/zelapi.svg?style=flat&logo=npm" alt="NPM Version">
6
+ </a>
7
+ <a href="https://www.npmjs.com/package/zelapi">
8
+ <img src="https://img.shields.io/npm/dt/zelapi.svg?style=flat&logo=npm" alt="NPM Downloads">
9
+ </a>
10
+ <img src="https://img.shields.io/badge/Node.js-339933?style=flat&logo=nodedotjs&logoColor=white" alt="Node.js">
11
+ <img src="https://img.shields.io/badge/TypeScript-3178C6?style=flat&logo=typescript&logoColor=white" alt="TypeScript">
12
+ </p>
13
+
14
+ # ZelApi Code of Conduct
15
+
16
+ ## Our Pledge
17
+
18
+ We as maintainers and contributors of **ZelApi** pledge to make participation in our community a **safe, welcoming, and harassment-free experience** for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual orientation.
19
+
20
+ We are committed to fostering a community that is **open, inclusive, respectful, and professional**.
21
+
22
+ ---
23
+
24
+ ## Our Standards
25
+
26
+ ### ✅ Positive behavior includes:
27
+ - Showing empathy and kindness to others
28
+ - Respecting different opinions and experiences
29
+ - Giving and accepting constructive feedback
30
+ - Taking responsibility for mistakes and learning from them
31
+ - Prioritizing the health and growth of the community
32
+
33
+ ### ❌ Unacceptable behavior includes:
34
+ - Harassment, discrimination, or hate speech
35
+ - Sexualized language, imagery, or advances
36
+ - Trolling, insulting, or derogatory comments
37
+ - Publishing private information without consent
38
+ - Any conduct that is inappropriate in a professional setting
39
+
40
+ ---
41
+
42
+ ## Enforcement Responsibilities
43
+
44
+ Project maintainers are responsible for **clarifying and enforcing** these standards. They may remove, edit, or reject contributions that violate this Code of Conduct and will communicate moderation decisions when appropriate.
45
+
46
+ ---
47
+
48
+ ## Scope
49
+
50
+ This Code of Conduct applies to:
51
+ - All project spaces (GitHub, npm, issues, discussions)
52
+ - Public spaces when an individual is representing ZelApi
53
+
54
+ ---
55
+
56
+ ## Enforcement
57
+
58
+ If you experience or witness unacceptable behavior, please report it to:
59
+
60
+ 📧 **Contact:** hazelnutoffc@gmail.com
61
+ or via **GitHub Issues / Discussions**
62
+
63
+ All reports will be reviewed **promptly, fairly, and confidentially**.
64
+
65
+ ---
66
+
67
+ ## Enforcement Guidelines
68
+
69
+ ### 1. Correction
70
+ **Impact:** Minor unprofessional behavior
71
+ **Action:** Private warning with explanation
72
+
73
+ ### 2. Warning
74
+ **Impact:** Repeated or notable violation
75
+ **Action:** Formal warning and temporary restrictions
76
+
77
+ ### 3. Temporary Ban
78
+ **Impact:** Serious or sustained violations
79
+ **Action:** Temporary ban from community interaction
80
+
81
+ ### 4. Permanent Ban
82
+ **Impact:** Ongoing harassment or severe misconduct
83
+ **Action:** Permanent removal from the community
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ZelApioffciall
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,181 @@
1
+ [![ZelApi](./media/image.jpg)](https://zelapioffciall.koyeb.app)
2
+ <p align="center">
3
+ <a href="https://www.npmjs.com/package/zelapi"><img src="https://img.shields.io/npm/v/zelapi.svg?style=flat&logo=npm" alt="NPM Version"></a>
4
+ <a href="https://www.npmjs.com/package/zelapi"><img src="https://img.shields.io/npm/dt/zelapi.svg?style=flat&logo=npm" alt="NPM Downloads"></a>
5
+ <img src="https://img.shields.io/badge/Node.js-339933?style=flat&logo=nodedotjs&logoColor=white" alt="Node.js">
6
+ <img src="https://img.shields.io/badge/TypeScript-3178C6?style=flat&logo=typescript&logoColor=white" alt="TypeScript">
7
+ </p>
8
+
9
+ **ZelApi** is a powerful and versatile JavaScript/TypeScript library that simplifies HTTP requests to the ZelApi service. It's designed to be easy to use, with support for universal parameters, different response types, and a secure way to handle your API key.
10
+
11
+ ## Features
12
+
13
+ - **Universal Parameters**: Pass parameters as an object or a single string.
14
+ - **Multiple Response Types**: Handle JSON, text, and buffer (for images, videos, etc.) responses with ease.
15
+ - **Secure API Key Handling**: Your API key is sent securely in the request headers.
16
+ - **TypeScript Support**: Written in TypeScript for a better developer experience.
17
+ - **Easy to Use**: A simple and intuitive API that gets the job done.
18
+
19
+ ## Installation
20
+
21
+ You can install `zelapi` using npm or yarn:
22
+
23
+ ```bash
24
+ # Using npm
25
+ npm install zelapi
26
+
27
+ # Using yarn
28
+ yarn add zelapi
29
+ ```
30
+
31
+ ## How to Use
32
+
33
+ ### Basic Usage
34
+
35
+ Here's a simple example of how to use `ZelApi` to make a request:
36
+
37
+ ```javascript
38
+ import { ZelApi } from "zelapi";
39
+
40
+ // Initialize the client without an API key
41
+ const zel = new ZelApi();
42
+
43
+ async function getCat() {
44
+ try {
45
+ const res = await zel.json("/random/cat");
46
+ console.log(res);
47
+ } catch (error) {
48
+ console.error("Error fetching cat:", error);
49
+ }
50
+ }
51
+
52
+ getCat();
53
+ ```
54
+
55
+ ### Using an API Key
56
+
57
+ If you have an API key, you can pass it to the `ZelApi` constructor:
58
+
59
+ ```javascript
60
+ import { ZelApi } from "zelapi";
61
+
62
+ // Initialize the client with your API key
63
+ const zel = new ZelApi({
64
+ apiKey: "YOUR_API_KEY",
65
+ });
66
+
67
+ async function getDog() {
68
+ try {
69
+ const res = await zel.json("/random/dog");
70
+ console.log(res);
71
+ } catch (error) {
72
+ console.error("Error fetching dog:", error);
73
+ }
74
+ }
75
+
76
+ getDog();
77
+ ```
78
+
79
+ ### Universal Parameters
80
+
81
+ You can pass parameters as an object or a single string.
82
+
83
+ #### Object Parameters
84
+
85
+ ```javascript
86
+ import { ZelApi } from "zelapi";
87
+
88
+ const zel = new ZelApi();
89
+
90
+ async function search() {
91
+ try {
92
+ const res = await zel.json("/search", {
93
+ q: "nature",
94
+ type: "image",
95
+ });
96
+ console.log(res);
97
+ } catch (error) {
98
+ console.error("Error searching:", error);
99
+ }
100
+ }
101
+
102
+ search();
103
+ ```
104
+
105
+ #### String Parameter
106
+
107
+ If you pass a string as the second argument, it will be treated as the `text` parameter.
108
+
109
+ ```javascript
110
+ import { ZelApi } from "zelapi";
111
+
112
+ const zel = new ZelApi();
113
+
114
+ async function convert() {
115
+ try {
116
+ const res = await zel.json("/convert/to-emoji", "Hello World");
117
+ console.log(res);
118
+ } catch (error) {
119
+ console.error("Error converting:", error);
120
+ }
121
+ }
122
+
123
+ convert();
124
+ ```
125
+
126
+ ### Handling Different Response Types
127
+
128
+ `ZelApi` can handle different response types, such as JSON, text, and buffers.
129
+
130
+ #### JSON Response
131
+
132
+ The `json()` method returns a JSON object.
133
+
134
+ ```javascript
135
+ const res = await zel.json("/random/cat");
136
+ console.log(res);
137
+ ```
138
+
139
+ #### Text Response
140
+
141
+ The `text()` method returns a string.
142
+
143
+ ```javascript
144
+ const res = await zel.text("/random/quote");
145
+ console.log(res);
146
+ ```
147
+
148
+ #### Buffer Response
149
+
150
+ The `buffer()` method returns a `Buffer`, which is useful for handling images, videos, and other binary files.
151
+
152
+ ```javascript
153
+ import { ZelApi } from "zelapi";
154
+ import fs from "fs";
155
+
156
+ const zel = new ZelApi();
157
+
158
+ async function getCatImage() {
159
+ try {
160
+ const buffer = await zel.buffer("/random/cat-image");
161
+ fs.writeFileSync("cat.jpg", buffer);
162
+ console.log("Cat image saved!");
163
+ } catch (error) {
164
+ console.error("Error fetching cat image:", error);
165
+ }
166
+ }
167
+
168
+ getCatImage();
169
+ ```
170
+
171
+ ## Contributing
172
+
173
+ Contributions are welcome! Please read our [Contributing Guidelines](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md) before submitting a pull request.
174
+
175
+ ## Security
176
+
177
+ If you discover a security vulnerability, please report it to us by following the instructions in our [Security Policy](SECURITY.md).
178
+
179
+ ## License
180
+
181
+ This project is licensed under the [MIT License](LICENSE).
package/SECURITY.md ADDED
@@ -0,0 +1,43 @@
1
+ [![ZelApi](./media/image.jpg)](https://zelapioffciall.koyeb.app)
2
+
3
+ <p align="center">
4
+ <a href="https://www.npmjs.com/package/zelapi"><img src="https://img.shields.io/npm/v/zelapi.svg?style=flat&logo=npm" alt="NPM Version"></a>
5
+ <a href="https://www.npmjs.com/package/zelapi"><img src="https://img.shields.io/npm/dt/zelapi.svg?style=flat&logo=npm" alt="NPM Downloads"></a>
6
+ <img src="https://img.shields.io/badge/Node.js-339933?style=flat&logo=nodedotjs&logoColor=white" alt="Node.js">
7
+ <img src="https://img.shields.io/badge/TypeScript-3178C6?style=flat&logo=typescript&logoColor=white" alt="TypeScript">
8
+ </p>
9
+
10
+ # Security Policy
11
+
12
+ The security of our users and services is a top priority for the ZelApi team. We welcome contributions from the community to help us maintain a high standard of security.
13
+
14
+ ## Reporting a Vulnerability
15
+
16
+ If you discover a security vulnerability, please report it to us as soon as possible. We encourage responsible disclosure and will work with you to address the issue promptly.
17
+
18
+ **Please do not report security vulnerabilities through public GitHub issues.**
19
+
20
+ Instead, please send an email to `hazelnutoffc@gmail.com` with the subject line "Security Vulnerability Report".
21
+
22
+ In your report, please include the following information:
23
+
24
+ * A detailed description of the vulnerability, including how to reproduce it.
25
+ * The version of the package you are using.
26
+ * Any relevant logs, screenshots, or other supporting materials.
27
+
28
+ ## Our Commitment
29
+
30
+ * We will acknowledge receipt of your vulnerability report within 48 hours.
31
+ * We will provide you with an estimated timeline for addressing the vulnerability.
32
+ * We will keep you informed of our progress and notify you when the vulnerability has been patched.
33
+ * We will credit you for your discovery, unless you prefer to remain anonymous.
34
+
35
+ ## Scope
36
+
37
+ This security policy applies to the `zelapi` npm package and the associated API services.
38
+
39
+ ## Safe Harbor
40
+
41
+ We will not take legal action against you for discovering and reporting security vulnerabilities in accordance with this policy. We consider activities conducted consistent with this policy to constitute "authorized" conduct under the Computer Fraud and Abuse Act.
42
+
43
+ We appreciate your efforts to help us keep our community safe.
@@ -0,0 +1,7 @@
1
+ export type UniversalParams = string | Record<string, any>;
2
+ /**
3
+ * Handles and sanitizes API request parameters.
4
+ * @param params - The parameters to sanitize.
5
+ * @returns The sanitized parameters.
6
+ */
7
+ export declare function handleParams(params?: UniversalParams): Record<string, any>;
@@ -0,0 +1,32 @@
1
+ import { ZodError, z } from "zod";
2
+ const ParamSchema = z
3
+ .object({
4
+ apikey: z.string().optional(),
5
+ prompt: z.string().optional(),
6
+ text: z.string().optional(),
7
+ })
8
+ .catchall(z.any());
9
+ /**
10
+ * Handles and sanitizes API request parameters.
11
+ * @param params - The parameters to sanitize.
12
+ * @returns The sanitized parameters.
13
+ */
14
+ export function handleParams(params) {
15
+ if (typeof params === "string") {
16
+ return { text: params };
17
+ }
18
+ if (typeof params === "object" && params !== null) {
19
+ try {
20
+ const validatedParams = ParamSchema.parse(params);
21
+ return validatedParams;
22
+ }
23
+ catch (error) {
24
+ if (error instanceof ZodError) {
25
+ console.error("Parameter validation failed:", error.issues);
26
+ throw new Error("Invalid parameters provided.");
27
+ }
28
+ throw error;
29
+ }
30
+ }
31
+ return {};
32
+ }
@@ -0,0 +1,36 @@
1
+ import { ResponseType, ZelApiOptions } from "../types";
2
+ import { UniversalParams } from "./handler";
3
+ export declare class ZelApi {
4
+ private baseUrl;
5
+ private headers;
6
+ constructor(options?: ZelApiOptions);
7
+ /**
8
+ * Makes a request to the API.
9
+ * @param path - The API endpoint path.
10
+ * @param params - The request parameters. Can be an object or a single string.
11
+ * @param responseType - The expected response type.
12
+ * @returns A promise that resolves with the API response.
13
+ */
14
+ request<T = any>(path: string, params?: UniversalParams, responseType?: ResponseType): Promise<string | Buffer<ArrayBufferLike> | T>;
15
+ /**
16
+ * Makes a request and expects a JSON response.
17
+ * @param path - The API endpoint path.
18
+ * @param params - The request parameters.
19
+ * @returns A promise that resolves with the JSON response.
20
+ */
21
+ json<T = any>(path: string, params?: UniversalParams): Promise<string | Buffer<ArrayBufferLike> | T>;
22
+ /**
23
+ * Makes a request and expects a text response.
24
+ * @param path - The API endpoint path.
25
+ * @param params - The request parameters.
26
+ * @returns A promise that resolves with the text response.
27
+ */
28
+ text(path: string, params?: UniversalParams): Promise<string | Buffer<ArrayBufferLike>>;
29
+ /**
30
+ * Makes a request and expects a buffer response (for images, videos, etc.).
31
+ * @param path - The API endpoint path.
32
+ * @param params - The request parameters.
33
+ * @returns A promise that resolves with the buffer response.
34
+ */
35
+ buffer(path: string, params?: UniversalParams): Promise<string | Buffer<ArrayBufferLike>>;
36
+ }
@@ -0,0 +1,56 @@
1
+ import { apiRequest } from "../utils/zelclient";
2
+ import { handleParams } from "./handler";
3
+ export class ZelApi {
4
+ constructor(options = {}) {
5
+ this.baseUrl = options.baseUrl || "https://zelapioffciall.koyeb.app";
6
+ this.headers = {
7
+ "User-Agent": "ZelApi-Client/1.0",
8
+ ...options.headers,
9
+ };
10
+ if (options.apiKey) {
11
+ this.headers["Authorization"] = `Bearer ${options.apiKey}`;
12
+ }
13
+ }
14
+ /**
15
+ * Makes a request to the API.
16
+ * @param path - The API endpoint path.
17
+ * @param params - The request parameters. Can be an object or a single string.
18
+ * @param responseType - The expected response type.
19
+ * @returns A promise that resolves with the API response.
20
+ */
21
+ request(path, params, responseType = "json") {
22
+ const sanitizedParams = handleParams(params);
23
+ return apiRequest(this.baseUrl, path, {
24
+ params: sanitizedParams,
25
+ responseType,
26
+ headers: this.headers,
27
+ });
28
+ }
29
+ /**
30
+ * Makes a request and expects a JSON response.
31
+ * @param path - The API endpoint path.
32
+ * @param params - The request parameters.
33
+ * @returns A promise that resolves with the JSON response.
34
+ */
35
+ json(path, params) {
36
+ return this.request(path, params, "json");
37
+ }
38
+ /**
39
+ * Makes a request and expects a text response.
40
+ * @param path - The API endpoint path.
41
+ * @param params - The request parameters.
42
+ * @returns A promise that resolves with the text response.
43
+ */
44
+ text(path, params) {
45
+ return this.request(path, params, "text");
46
+ }
47
+ /**
48
+ * Makes a request and expects a buffer response (for images, videos, etc.).
49
+ * @param path - The API endpoint path.
50
+ * @param params - The request parameters.
51
+ * @returns A promise that resolves with the buffer response.
52
+ */
53
+ buffer(path, params) {
54
+ return this.request(path, params, "buffer");
55
+ }
56
+ }
@@ -0,0 +1,6 @@
1
+ export type ResponseType = "json" | "text" | "buffer";
2
+ export interface ZelApiOptions {
3
+ baseUrl?: string;
4
+ headers?: Record<string, string>;
5
+ apiKey?: string;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export type ResponseType = "json" | "text" | "buffer";
2
+ export interface RequestOptions {
3
+ params?: Record<string, any>;
4
+ responseType?: ResponseType;
5
+ headers?: Record<string, string>;
6
+ }
7
+ export declare function apiRequest<T = any>(baseUrl: string, path: string, options?: RequestOptions): Promise<T | string | Buffer>;
@@ -0,0 +1,27 @@
1
+ export async function apiRequest(baseUrl, path, options = {}) {
2
+ const url = new URL(baseUrl + path);
3
+ if (options.params) {
4
+ for (const [key, value] of Object.entries(options.params)) {
5
+ if (value !== undefined && value !== null) {
6
+ url.searchParams.append(key, String(value));
7
+ }
8
+ }
9
+ }
10
+ const res = await fetch(url.toString(), {
11
+ method: "GET",
12
+ headers: options.headers
13
+ });
14
+ if (!res.ok) {
15
+ const text = await res.text().catch(() => "");
16
+ throw new Error(`ZelApiError ${res.status}: ${text || res.statusText}`);
17
+ }
18
+ const type = options.responseType || "json";
19
+ if (type === "json")
20
+ return (await res.json());
21
+ if (type === "text")
22
+ return await res.text();
23
+ if (type === "buffer") {
24
+ return Buffer.from(await res.arrayBuffer());
25
+ }
26
+ return await res.text();
27
+ }
@@ -0,0 +1,13 @@
1
+ import { ZelApi } from "../dist/index.js"
2
+
3
+ const zel = new ZelApi()
4
+
5
+ const ai = await zel.json("/ai/mimo", {
6
+ text: "apa itu black hole"
7
+ })
8
+ console.log(ai)
9
+
10
+ const video = await zel.buffer("/download/tiktok", {
11
+ url: "https://tiktok.com/xxxx"
12
+ })
13
+ console.log(video.length)
Binary file
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "zelapi",
3
+ "version": "0.0.1",
4
+ "description": "Universal JavaScript & TypeScript client for ZelApi — simple, secure, and flexible HTTP requests with support for JSON, text, and media responses.",
5
+ "keywords": [
6
+ "zelapi",
7
+ "zel-api",
8
+ "zelapiofficial",
9
+ "siputzx",
10
+ "rest-api",
11
+ "api-client",
12
+ "http-client",
13
+ "fetch-client",
14
+ "universal-api",
15
+ "typescript",
16
+ "javascript",
17
+ "nodejs",
18
+ "node-fetch",
19
+ "backend",
20
+ "wrapper",
21
+ "sdk",
22
+ "ai-api",
23
+ "media-api",
24
+ "download-api",
25
+ "tiktok-downloader",
26
+ "youtube-downloader",
27
+ "image-api",
28
+ "video-api"
29
+ ],
30
+ "homepage": "https://github.com/hazelnuttty/zelapi-client#readme",
31
+ "bugs": {
32
+ "url": "https://github.com/hazelnuttty/zelapi-client/issues"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://hazelnuttty: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@github.com/hazelnuttty/zelapi-client.git"
37
+ },
38
+ "license": "MIT",
39
+ "author": "Hazel",
40
+ "type": "module",
41
+ "main": "dist/index.js",
42
+ "types": "dist/index.d.ts",
43
+ "directories": {
44
+ "example": "examples"
45
+ },
46
+ "scripts": {
47
+ "build": "tsc -p tsconfig.esm.json",
48
+ "prepublishOnly": "npm run build"
49
+ },
50
+ "devDependencies": {
51
+ "typescript": "^5.9.3"
52
+ }
53
+ }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { ZelApi } from "./lib/zelapi"
2
+ export * from "./types"
@@ -0,0 +1,40 @@
1
+ import { ZodError, z } from "zod";
2
+
3
+ const ParamSchema = z
4
+ .object({
5
+ apikey: z.string().optional(),
6
+ prompt: z.string().optional(),
7
+ text: z.string().optional(),
8
+ })
9
+ .catchall(z.any());
10
+
11
+ export type UniversalParams = string | Record<string, any>;
12
+
13
+ /**
14
+ * Handles and sanitizes API request parameters.
15
+ * @param params - The parameters to sanitize.
16
+ * @returns The sanitized parameters.
17
+ */
18
+ export function handleParams(params?: UniversalParams): Record<string, any> {
19
+ if (typeof params === "string") {
20
+ return { text: params };
21
+ }
22
+
23
+ if (typeof params === "object" && params !== null) {
24
+ try {
25
+ const validatedParams = ParamSchema.parse(params);
26
+ return validatedParams;
27
+ } catch (error) {
28
+ if (error instanceof ZodError) {
29
+ console.error(
30
+ "Parameter validation failed:",
31
+ error.issues
32
+ );
33
+ throw new Error("Invalid parameters provided.");
34
+ }
35
+ throw error;
36
+ }
37
+ }
38
+
39
+ return {};
40
+ }
@@ -0,0 +1,70 @@
1
+
2
+ import { apiRequest } from "../utils/zelclient";
3
+ import { ResponseType, ZelApiOptions } from "../types";
4
+ import { UniversalParams, handleParams } from "./handler";
5
+
6
+ export class ZelApi {
7
+ private baseUrl: string;
8
+ private headers: Record<string, string>;
9
+
10
+ constructor(options: ZelApiOptions = {}) {
11
+ this.baseUrl = options.baseUrl || "https://zelapioffciall.koyeb.app";
12
+ this.headers = {
13
+ "User-Agent": "ZelApi-Client/1.0",
14
+ ...options.headers,
15
+ };
16
+ if (options.apiKey) {
17
+ this.headers["Authorization"] = `Bearer ${options.apiKey}`;
18
+ }
19
+ }
20
+
21
+ /**
22
+ * Makes a request to the API.
23
+ * @param path - The API endpoint path.
24
+ * @param params - The request parameters. Can be an object or a single string.
25
+ * @param responseType - The expected response type.
26
+ * @returns A promise that resolves with the API response.
27
+ */
28
+ request<T = any>(
29
+ path: string,
30
+ params?: UniversalParams,
31
+ responseType: ResponseType = "json"
32
+ ) {
33
+ const sanitizedParams = handleParams(params);
34
+ return apiRequest<T>(this.baseUrl, path, {
35
+ params: sanitizedParams,
36
+ responseType,
37
+ headers: this.headers,
38
+ });
39
+ }
40
+
41
+ /**
42
+ * Makes a request and expects a JSON response.
43
+ * @param path - The API endpoint path.
44
+ * @param params - The request parameters.
45
+ * @returns A promise that resolves with the JSON response.
46
+ */
47
+ json<T = any>(path: string, params?: UniversalParams) {
48
+ return this.request<T>(path, params, "json");
49
+ }
50
+
51
+ /**
52
+ * Makes a request and expects a text response.
53
+ * @param path - The API endpoint path.
54
+ * @param params - The request parameters.
55
+ * @returns A promise that resolves with the text response.
56
+ */
57
+ text(path: string, params?: UniversalParams) {
58
+ return this.request<string>(path, params, "text");
59
+ }
60
+
61
+ /**
62
+ * Makes a request and expects a buffer response (for images, videos, etc.).
63
+ * @param path - The API endpoint path.
64
+ * @param params - The request parameters.
65
+ * @returns A promise that resolves with the buffer response.
66
+ */
67
+ buffer(path: string, params?: UniversalParams) {
68
+ return this.request<Buffer>(path, params, "buffer");
69
+ }
70
+ }
@@ -0,0 +1,7 @@
1
+ export type ResponseType = "json" | "text" | "buffer"
2
+
3
+ export interface ZelApiOptions {
4
+ baseUrl?: string
5
+ headers?: Record<string, string>
6
+ apiKey?: string
7
+ }
@@ -0,0 +1,45 @@
1
+ export type ResponseType = "json" | "text" | "buffer"
2
+
3
+ export interface RequestOptions {
4
+ params?: Record<string, any>
5
+ responseType?: ResponseType
6
+ headers?: Record<string, string>
7
+ }
8
+
9
+ export async function apiRequest<T = any>(
10
+ baseUrl: string,
11
+ path: string,
12
+ options: RequestOptions = {}
13
+ ): Promise<T | string | Buffer> {
14
+ const url = new URL(baseUrl + path)
15
+
16
+ if (options.params) {
17
+ for (const [key, value] of Object.entries(options.params)) {
18
+ if (value !== undefined && value !== null) {
19
+ url.searchParams.append(key, String(value))
20
+ }
21
+ }
22
+ }
23
+
24
+ const res = await fetch(url.toString(), {
25
+ method: "GET",
26
+ headers: options.headers
27
+ })
28
+
29
+ if (!res.ok) {
30
+ const text = await res.text().catch(() => "")
31
+ throw new Error(
32
+ `ZelApiError ${res.status}: ${text || res.statusText}`
33
+ )
34
+ }
35
+
36
+ const type = options.responseType || "json"
37
+
38
+ if (type === "json") return (await res.json()) as T
39
+ if (type === "text") return await res.text()
40
+ if (type === "buffer") {
41
+ return Buffer.from(await res.arrayBuffer())
42
+ }
43
+
44
+ return await res.text()
45
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "strict": true,
5
+ "skipLibCheck": true,
6
+ "forceConsistentCasingInFileNames": true
7
+ }
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "module": "CommonJS",
5
+ "moduleResolution": "Node",
6
+ "outDir": "dist/cjs"
7
+ },
8
+ "include": ["src"]
9
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "module": "ESNext",
5
+ "moduleResolution": "Node",
6
+ "outDir": "dist",
7
+ "declaration": true
8
+ },
9
+ "include": ["src"]
10
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "emitDeclarationOnly": true,
5
+ "declaration": true,
6
+ "outDir": "dist/types"
7
+ },
8
+ "include": ["src"]
9
+ }