insta-checker-sdk 1.0.1 → 1.0.3

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,90 @@
1
+ # API Reference
2
+
3
+ This is a detailed list of the methods and options available in the SDK.
4
+
5
+ ## Class: InstaChecker
6
+
7
+ ### Constructor
8
+
9
+ ```typescript
10
+ new InstaChecker(options?)
11
+ ```
12
+
13
+ Creates a new checker instance.
14
+
15
+ **Parameters:**
16
+
17
+ * `options` (Object): Optional configuration object.
18
+
19
+ | Property | Type | Default | Description |
20
+ | --- | --- | --- | --- |
21
+ | `timeout` | number | 5000 | Request timeout in ms. |
22
+ | `concurrency` | number | 5 | Number of parallel requests allowed. |
23
+ | `retries` | number | 2 | Number of times to retry a failed request. |
24
+ | `cacheTTL` | number | 300000 | Cache time to live in ms. |
25
+ | `enableCache` | boolean | true | Enable or disable the memory cache. |
26
+
27
+ ### Method: checkUsername
28
+
29
+ Checks if a single username is available.
30
+
31
+ ```typescript
32
+ checkUsername(username: string): Promise<CheckResult>
33
+ ```
34
+
35
+ **Parameters:**
36
+
37
+ * `username` (string): The Instagram username to check.
38
+
39
+ **Returns:**
40
+
41
+ A Promise that resolves to a `CheckResult` object:
42
+
43
+ ```typescript
44
+ {
45
+ available: boolean, // true if available, false if taken
46
+ cached: boolean // true if result came from memory cache
47
+ }
48
+ ```
49
+
50
+ **Throws:**
51
+
52
+ Throws an Error if the username is invalid or if the request fails after all retries.
53
+
54
+ ### Method: checkBatch
55
+
56
+ Checks multiple usernames in parallel.
57
+
58
+ ```typescript
59
+ checkBatch(usernames: string[], options?: BatchOptions): Promise<Record<string, boolean | null>>
60
+ ```
61
+
62
+ **Parameters:**
63
+
64
+ * `usernames` (string[]): An array of username strings.
65
+ * `options` (Object): Optional settings.
66
+ * `onProgress` (function): A callback function that fires every time a username finishes.
67
+
68
+ **Returns:**
69
+
70
+ A Promise that resolves to an object where keys are usernames and values are booleans (`true`, `false`) or `null` if an error occurred.
71
+
72
+ **Example:**
73
+
74
+ ```javascript
75
+ const results = await checker.checkBatch(['a', 'b', 'c'], {
76
+ onProgress: (info) => {
77
+ console.log(`${info.current}/${info.total} done`);
78
+ }
79
+ });
80
+ ```
81
+
82
+ ### Method: clearCache
83
+
84
+ Clears all items from the in-memory cache.
85
+
86
+ ```typescript
87
+ clearCache(): void
88
+ ```
89
+
90
+ Use this if you want to ensure all subsequent checks hit the live API.
@@ -0,0 +1,127 @@
1
+ # Usage Examples
2
+
3
+ Here are some common patterns for using this SDK in different types of applications.
4
+
5
+ ## Discord Bot (discord.js)
6
+
7
+ This example shows how to add a command to check a username.
8
+
9
+ ```javascript
10
+ const { Client, GatewayIntentBits } = require('discord.js');
11
+ const InstaChecker = require('insta-checker-sdk');
12
+
13
+ // Initialize the checker
14
+ const checker = new InstaChecker({ timeout: 5000 });
15
+
16
+ const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
17
+
18
+ client.on('messageCreate', async message => {
19
+ if (message.content.startsWith('!check')) {
20
+ // Get the username from the command
21
+ const args = message.content.split(' ');
22
+ const username = args[1];
23
+
24
+ if (!username) {
25
+ return message.reply('Please provide a username.');
26
+ }
27
+
28
+ // Reply immediately so the user knows we are working
29
+ const msg = await message.channel.send(`Checking \`${username}\`...`);
30
+
31
+ try {
32
+ const result = await checker.checkUsername(username);
33
+
34
+ let status = result.available ? 'Available' : 'Taken';
35
+ if (result.cached) status += ' (Cached)';
36
+
37
+ msg.edit(`Status: ${status}`);
38
+ } catch (error) {
39
+ msg.edit('Error checking username.');
40
+ }
41
+ }
42
+ });
43
+
44
+ client.login('YOUR_BOT_TOKEN');
45
+ ```
46
+
47
+ ## Express Web API
48
+
49
+ This example creates a simple HTTP endpoint to check usernames.
50
+
51
+ ```javascript
52
+ const express = require('express');
53
+ const InstaChecker = require('insta-checker-sdk');
54
+
55
+ const app = express();
56
+ const checker = new InstaChecker({ concurrency: 20 });
57
+
58
+ // Middleware to parse JSON
59
+ app.use(express.json());
60
+
61
+ app.get('/api/check/:username', async (req, res) => {
62
+ const { username } = req.params;
63
+
64
+ try {
65
+ const result = await checker.checkUsername(username);
66
+ res.json({
67
+ username: username,
68
+ available: result.available,
69
+ cached: result.cached
70
+ });
71
+ } catch (err) {
72
+ res.status(500).json({ error: err.message });
73
+ }
74
+ });
75
+
76
+ app.post('/api/check-batch', async (req, res) => {
77
+ const { usernames } = req.body;
78
+
79
+ if (!Array.isArray(usernames)) {
80
+ return res.status(400).json({ error: 'Expected an array of usernames' });
81
+ }
82
+
83
+ try {
84
+ const results = await checker.checkBatch(usernames);
85
+ res.json(results);
86
+ } catch (err) {
87
+ res.status(500).json({ error: err.message });
88
+ }
89
+ });
90
+
91
+ app.listen(3000, () => console.log('Server running on port 3000'));
92
+ ```
93
+
94
+ ## Bulk Checking with Progress
95
+
96
+ If you need to check 10,000 usernames, you might want to log progress to the console.
97
+
98
+ ```javascript
99
+ const InstaChecker = require('insta-checker-sdk');
100
+ const fs = require('fs');
101
+
102
+ const checker = new InstaChecker({ concurrency: 10 });
103
+
104
+ // Imagine you loaded this from a file
105
+ const hugeList = Array.from({ length: 1000 }, (_, i) => `user${i}`);
106
+
107
+ async function runBulk() {
108
+ console.log(`Starting bulk check for ${hugeList.length} users...`);
109
+
110
+ const startTime = Date.now();
111
+
112
+ const results = await checker.checkBatch(hugeList, {
113
+ onProgress: (info) => {
114
+ // Update console log in place
115
+ process.stdout.write(`\rProgress: ${info.current}/${info.total} (${Math.round(info.current/info.total*100)}%)`);
116
+ }
117
+ });
118
+
119
+ const duration = (Date.now() - startTime) / 1000;
120
+ console.log(`\nDone in ${duration} seconds.`);
121
+
122
+ // Save to file
123
+ fs.writeFileSync('results.json', JSON.stringify(results, null, 2));
124
+ }
125
+
126
+ runBulk();
127
+ ```
@@ -0,0 +1,77 @@
1
+
2
+ # Getting Started
3
+
4
+ This guide covers the basics of setting up and running the Insta Checker SDK in your project.
5
+
6
+ ## How it works
7
+
8
+ The library uses an external API to check availability. It sends a POST request and looks for the `available` status in the response.
9
+
10
+ To make this efficient for production, we do a few things:
11
+
12
+ 1. **Keep-Alive**: We open an HTTPS connection and keep it open to check many names without reconnecting.
13
+ 2. **Concurrency**: We don't fire off 1000 requests instantly. We queue them and process them in small batches (default is 5 at a time).
14
+ 3. **Memory Cache**: If you check "instagram" twice in 5 minutes, the second time comes from memory.
15
+
16
+ ## Installation
17
+
18
+ Make sure you are using Node.js version 14 or higher.
19
+
20
+ ```bash
21
+ npm install insta-checker-sdk
22
+ ```
23
+ ## Your first script
24
+
25
+ Create a file called `check.js` and paste this code:
26
+
27
+ ```javascript
28
+ const InstaChecker = require('insta-checker-sdk');
29
+
30
+ // Create a new instance
31
+ const checker = new InstaChecker({
32
+ timeout: 5000,
33
+ retries: 3
34
+ });
35
+
36
+ async function main() {
37
+ try {
38
+ console.log('Checking username...');
39
+ const result = await checker.checkUsername('microsoft');
40
+
41
+ if (result.available) {
42
+ console.log('Available!');
43
+ } else {
44
+ console.log('Taken.');
45
+ }
46
+ } catch (error) {
47
+ console.error('Something went wrong:', error.message);
48
+ }
49
+ }
50
+
51
+ main();
52
+ ```
53
+
54
+ Run it:
55
+
56
+ ```bash
57
+ node check.js
58
+ ```
59
+
60
+ ## TypeScript Support
61
+
62
+ If you use TypeScript, import the class and the types.
63
+
64
+ ```typescript
65
+ import InstaChecker, { CheckerOptions, CheckResult } from 'insta-checker-sdk';
66
+
67
+ const options: CheckerOptions = {
68
+ timeout: 4000
69
+ };
70
+
71
+ const checker = new InstaChecker(options);
72
+
73
+ const result: CheckResult = await checker.checkUsername('google');
74
+ ```
75
+
76
+ The types are built into the package, so you don't need to install anything extra.
77
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insta-checker-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A robust, production-ready Instagram username availability checker written in TypeScript.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -34,6 +34,7 @@
34
34
  },
35
35
  "files": [
36
36
  "dist/",
37
+ "docs/",
37
38
  "README.md",
38
39
  "LICENSE"
39
40
  ]