sentilyze 1.1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +214 -0
  3. package/index.js +204 -0
  4. package/package.json +38 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sentilyze.ai
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,214 @@
1
+ # Sentilyze SDK
2
+
3
+ Official Node.js SDK for [Sentilyze.ai](https://sentilyze.ai) - Transform customer feedback into actionable insights with AI-powered sentiment analysis.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/sentilyze.svg)](https://www.npmjs.com/package/sentilyze)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install sentilyze
12
+ ```
13
+
14
+ ## Quick Start
15
+
16
+ ```javascript
17
+ import SentilyzeClient from 'sentilyze';
18
+
19
+ const client = new SentilyzeClient({ apiKey: 'senti_your_api_key' });
20
+ const result = await client.analyze('This product is amazing!');
21
+
22
+ console.log(result.sentiment); // 'positive'
23
+ console.log(result.score); // 5.2
24
+ ```
25
+
26
+ **Response:**
27
+ ```javascript
28
+ {
29
+ sentiment: 'positive',
30
+ score: 5.2,
31
+ summary: 'Customer expresses high satisfaction with the product',
32
+ tags: ['product', 'satisfaction', 'quality'],
33
+ usage: {
34
+ requestsUsed: 1,
35
+ requestsLimit: 1000,
36
+ requestsRemaining: 999,
37
+ subscriptionPlan: 'Starter',
38
+ resetDate: '2025-12-31T23:59:59.999Z'
39
+ }
40
+ }
41
+ ```
42
+
43
+ ## Features
44
+
45
+ - ✅ **Sentiment Analysis** - Detect positive, negative, or neutral sentiment
46
+ - ✅ **Happiness Scoring** - Measure happiness levels from 1-6 scale
47
+ - ✅ **AI-Powered Summary** - Get concise summaries of feedback
48
+ - ✅ **Tag Extraction** - Automatic keyword and topic extraction
49
+ - ✅ **Batch Processing** - Analyze multiple texts efficiently
50
+ - ✅ **Usage Tracking** - Monitor your API usage in real-time
51
+ - ✅ **Error Handling** - Comprehensive error messages and retry logic
52
+
53
+ ## API Reference
54
+
55
+ ### Initialize Client
56
+
57
+ ```javascript
58
+ const client = new SentilyzeClient({
59
+ apiKey: 'senti_your_api_key', // Required: Your API key
60
+ baseUrl: 'https://api.sentilyze.ai', // Optional: Custom API URL
61
+ timeout: 30000 // Optional: Request timeout (ms)
62
+ });
63
+ ```
64
+
65
+ ### Analyze Text
66
+
67
+ Analyze a single text for sentiment and happiness:
68
+
69
+ ```javascript
70
+ // Simple string
71
+ const result = await client.analyze('Customer feedback text');
72
+
73
+ // With options
74
+ const result = await client.analyze('Customer feedback text', {
75
+ spamcheck: true, // Check for spam (Professional/Enterprise)
76
+ reply: true, // Generate auto-reply (Professional/Enterprise)
77
+ language: 'en' // Language code (Professional/Enterprise)
78
+ });
79
+
80
+ // With options object
81
+ const result = await client.analyze({
82
+ feedback: 'Customer feedback text',
83
+ spamcheck: true,
84
+ reply: true,
85
+ language: 'en'
86
+ });
87
+ ```
88
+
89
+ **Response Structure:**
90
+ ```javascript
91
+ {
92
+ sentiment: 'positive' | 'negative' | 'neutral',
93
+ score: number, // 1-6 scale (decimal)
94
+ summary: string, // AI-generated summary
95
+ tags: string[], // Extracted keywords
96
+ spam: boolean, // If spamcheck was requested
97
+ autoReply: string, // If reply was requested
98
+ }
99
+ ```
100
+
101
+ **Example:**
102
+ ```javascript
103
+ const result = await client.analyze('The product quality is excellent, but shipping was slow', {
104
+ language: 'en',
105
+ reply: true
106
+ });
107
+
108
+ console.log(result.sentiment); // 'positive'
109
+ console.log(result.autoReply); // 'Thank you for your feedback...'
110
+ console.log(result.score); // 4.5
111
+ console.log(result.summary); // 'Mixed feedback with product praise and shipping concerns'
112
+ console.log(result.tags); // ['product', 'quality', 'shipping', 'delivery']
113
+ ```
114
+
115
+
116
+ ### Get Usage Statistics
117
+
118
+ Check your current API usage:
119
+
120
+ ```javascript
121
+ const usage = await client.getUsage();
122
+ console.log(usage);
123
+ ```
124
+
125
+ **Response:**
126
+ ```javascript
127
+ {
128
+ data: {
129
+ requestsUsed: 150,
130
+ requestsLimit: 1000,
131
+ requestsRemaining: 850,
132
+ subscriptionPlan: 'Starter',
133
+ resetDate: '2025-12-31T23:59:59.999Z',
134
+ currentPeriod: {
135
+ month: 12,
136
+ year: 2025
137
+ }
138
+ }
139
+ }
140
+ ```
141
+
142
+ ## Error Handling
143
+
144
+ The SDK provides detailed error handling:
145
+
146
+ ```javascript
147
+ try {
148
+ const result = await client.analyze('Text to analyze');
149
+ } catch (error) {
150
+ if (error.status === 401) {
151
+ console.error('Invalid API key');
152
+ } else if (error.status === 429) {
153
+ console.error('Rate limit exceeded');
154
+ } else if (error.message.includes('timeout')) {
155
+ console.error('Request timed out');
156
+ } else if (error.message.includes('Network error')) {
157
+ console.error('Cannot reach API');
158
+ } else {
159
+ console.error('Analysis failed:', error.message);
160
+ }
161
+ }
162
+ ```
163
+
164
+ ## Common Use Cases
165
+
166
+ ### Customer Feedback Analysis
167
+ ```javascript
168
+ // Analyze customer review
169
+ const review = await client.analyze(
170
+ 'The product quality is excellent, but shipping was slow'
171
+ );
172
+
173
+ if (review.sentiment === 'positive') {
174
+ console.log(`Happy customer! Score: ${review.score}/6`);
175
+ console.log(`Summary: ${review.summary}`);
176
+ console.log(`Topics: ${review.tags.join(', ')}`);
177
+ }
178
+ ```
179
+
180
+ ## Subscription Plans
181
+
182
+ | Plan | Requests/Month | Price | Best For |
183
+ |------|----------------|-------|----------|
184
+ | Developer | 100 | Free | Testing & development |
185
+ | Starter | 1,000 | $29 | Small projects |
186
+ | Professional | 10,000 | $199 | Growing businesses |
187
+ | Enterprise | Unlimited | Custom | Large organizations |
188
+
189
+ Get your API key at [sentilyze.ai](https://sentilyze.ai)
190
+
191
+ ## Response Field Descriptions
192
+
193
+ - **sentiment**: Classification of the feedback (`positive`, `negative`, or `neutral`)
194
+ - **score**: Happiness/satisfaction score on a 1-6 scale (decimal values like 4.5 are supported)
195
+ - 1-2: Very unhappy
196
+ - 3-4: Neutral to slightly satisfied
197
+ - 5-6: Very happy
198
+ - **summary**: AI-generated concise summary of the feedback
199
+ - **tags**: Array of extracted keywords and topics from the text
200
+ - **usage**: Current API usage information for rate limiting and billing
201
+
202
+ ## Support
203
+
204
+ - 📧 Email: support@sentilyze.ai
205
+ - 🌐 Website: https://www.sentilyze.ai
206
+ - 📚 Dashboard: https://www.sentilyze.ai/dashboard
207
+
208
+ ## License
209
+
210
+ MIT © Sentilyze.ai
211
+
212
+ ---
213
+
214
+ Made with ❤️ by [Sentilyze.ai](https://sentilyze.ai)
package/index.js ADDED
@@ -0,0 +1,204 @@
1
+ /**
2
+ * Sentilyze SDK - Official Node.js client for Sentilyze.ai
3
+ * Analyze sentiment and happiness levels from customer feedback
4
+ * @version 1.1.0
5
+ */
6
+
7
+ class SentilyzeClient {
8
+ /**
9
+ * Create a Sentilyze client instance
10
+ * @param {Object} config - Configuration options
11
+ * @param {string} config.apiKey - Your Sentilyze API key
12
+ * @param {string} [config.baseUrl='https://api.sentilyze.ai'] - API base URL
13
+ * @param {number} [config.timeout=30000] - Request timeout in milliseconds
14
+ */
15
+ constructor(config) {
16
+ if (!config || !config.apiKey) {
17
+ throw new Error('API key is required. Get yours at https://sentilyze.ai');
18
+ }
19
+
20
+ this.apiKey = config.apiKey;
21
+ this.baseUrl = config.baseUrl || 'https://api.sentilyze.ai';
22
+ this.timeout = config.timeout || 30000;
23
+ }
24
+
25
+ /**
26
+ * Internal method to make API requests
27
+ * @private
28
+ */
29
+ async _request(endpoint, options = {}) {
30
+ const controller = new AbortController();
31
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
32
+
33
+ try {
34
+ const response = await fetch(`${this.baseUrl}${endpoint}`, {
35
+ ...options,
36
+ headers: {
37
+ 'Content-Type': 'application/json',
38
+ 'x-api-key': this.apiKey,
39
+ ...options.headers
40
+ },
41
+ signal: controller.signal
42
+ });
43
+
44
+ clearTimeout(timeoutId);
45
+
46
+ const data = await response.json().catch(() => null);
47
+
48
+ if (!response.ok) {
49
+ const errorMessage = data?.error?.message || data?.message || response.statusText;
50
+ const error = new Error(errorMessage);
51
+ error.status = response.status;
52
+ error.response = data;
53
+ throw error;
54
+ }
55
+
56
+ return data;
57
+ } catch (error) {
58
+ clearTimeout(timeoutId);
59
+
60
+ if (error.name === 'AbortError') {
61
+ throw new Error(`Request timeout after ${this.timeout}ms`);
62
+ }
63
+
64
+ if (error.message.includes('fetch') && !error.status) {
65
+ throw new Error('Network error: Unable to reach Sentilyze API');
66
+ }
67
+
68
+ throw error;
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Analyze sentiment and happiness from text
74
+ * @param {string|Object} input - Text to analyze or options object
75
+ * @param {Object} [options] - Configuration options (when input is a string)
76
+ * @param {string} [input.feedback] - Text to analyze (when using options object)
77
+ * @param {boolean} [input.spamcheck=false] - Check for spam (Professional/Enterprise only)
78
+ * @param {boolean} [input.reply=false] - Generate auto-reply (Professional/Enterprise only)
79
+ * @param {string} [input.language='en'] - Language code (e.g. 'en', 'es', 'fr') (Professional/Enterprise only)
80
+ * @returns {Promise<Object>} Analysis results with sentiment, score, summary, tags, and usage info
81
+ *
82
+ * @example
83
+ * const result = await client.analyze('This product is amazing!');
84
+ *
85
+ * // With options
86
+ * const result = await client.analyze('This product is amazing!', {
87
+ * spamcheck: true,
88
+ * reply: true,
89
+ * language: 'es'
90
+ * });
91
+ *
92
+ * // Or with single object
93
+ * const result = await client.analyze({
94
+ * feedback: 'This product is amazing!',
95
+ * spamcheck: true,
96
+ * reply: true,
97
+ * language: 'es'
98
+ * });
99
+ */
100
+ async analyze(input, options = {}) {
101
+ let feedback;
102
+ let finalOptions = {};
103
+
104
+ if (typeof input === 'string') {
105
+ feedback = input;
106
+ finalOptions = options;
107
+ } else if (typeof input === 'object' && input !== null) {
108
+ feedback = input.feedback;
109
+ finalOptions = { ...input, ...options };
110
+ }
111
+
112
+ if (!feedback || typeof feedback !== 'string') {
113
+ throw new Error('Text is required for analysis');
114
+ }
115
+
116
+ if (feedback.trim().length === 0) {
117
+ throw new Error('Text cannot be empty');
118
+ }
119
+
120
+ const body = {
121
+ feedback,
122
+ includeSpamCheck: finalOptions.spamcheck || finalOptions.includeSpamCheck || false,
123
+ includeAutoReply: finalOptions.reply || finalOptions.includeAutoReply || false,
124
+ language: finalOptions.language || 'en'
125
+ };
126
+
127
+ return await this._request('/api/analyze', {
128
+ method: 'POST',
129
+ body: JSON.stringify(body)
130
+ });
131
+ }
132
+
133
+ /**
134
+ * Batch analyze multiple texts (processes them in parallel)
135
+ * @param {string[]} texts - Array of texts to analyze
136
+ * @param {Object} [options] - Batch options
137
+ * @param {number} [options.concurrency=5] - Number of concurrent requests
138
+ * @returns {Promise<Object>} Object containing results array and statistics
139
+ *
140
+ * @example
141
+ * const result = await client.batchAnalyze([
142
+ * 'Great service!',
143
+ * 'Not satisfied with the product',
144
+ * 'Average experience'
145
+ * ]);
146
+ * console.log(result.successCount); // 3
147
+ * console.log(result.results[0].sentiment); // 'positive'
148
+ */
149
+ async batchAnalyze(texts, options = {}) {
150
+ if (!Array.isArray(texts) || texts.length === 0) {
151
+ throw new Error('An array of texts is required for batch analysis');
152
+ }
153
+
154
+ const concurrency = options.concurrency || 5;
155
+ const results = [];
156
+ const errors = [];
157
+
158
+ // Process in batches to respect concurrency
159
+ for (let i = 0; i < texts.length; i += concurrency) {
160
+ const batch = texts.slice(i, i + concurrency);
161
+ const batchResults = await Promise.allSettled(
162
+ batch.map((text, index) =>
163
+ this.analyze(text).catch(error => {
164
+ errors.push({ index: i + index, text, error: error.message });
165
+ return null;
166
+ })
167
+ )
168
+ );
169
+
170
+ results.push(...batchResults.map(r => r.status === 'fulfilled' ? r.value : null));
171
+ }
172
+
173
+ return {
174
+ results: results.filter(r => r !== null),
175
+ errors,
176
+ totalProcessed: texts.length,
177
+ successCount: results.filter(r => r !== null).length,
178
+ errorCount: errors.length
179
+ };
180
+ }
181
+
182
+ /**
183
+ * Get API usage statistics for your account
184
+ * @returns {Promise<Object>} Usage statistics for current period
185
+ *
186
+ * @example
187
+ * const usage = await client.getUsage();
188
+ * console.log(usage.data);
189
+ * // {
190
+ * // requestsUsed: 150,
191
+ * // requestsLimit: 1000,
192
+ * // requestsRemaining: 850,
193
+ * // subscriptionPlan: 'Starter',
194
+ * // resetDate: '2025-12-31T23:59:59.999Z'
195
+ * // }
196
+ */
197
+ async getUsage() {
198
+ return await this._request('/api/usage', {
199
+ method: 'GET'
200
+ });
201
+ }
202
+ }
203
+
204
+ module.exports = SentilyzeClient;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "sentilyze",
3
+ "version": "1.1.0",
4
+ "description": "Official Node.js SDK for Sentilyze.ai - Analyze sentiment and happiness levels from customer feedback with AI",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [
10
+ "sentilyze",
11
+ "sentiment",
12
+ "analysis",
13
+ "sentiment-analysis",
14
+ "happiness",
15
+ "ai",
16
+ "nlp",
17
+ "customer-feedback",
18
+ "gpt-4",
19
+ "text-analysis",
20
+ "analytics",
21
+ "insights",
22
+ "word-cloud",
23
+ "customer-satisfaction"
24
+ ],
25
+ "author": "Sentilyze.ai",
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/yourusername/sentilyze-sdk.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/yourusername/sentilyze-sdk/issues"
33
+ },
34
+ "homepage": "https://sentilyze.ai",
35
+ "engines": {
36
+ "node": ">=18.0.0"
37
+ }
38
+ }