@sharpapi/sharpapi-node-product-review-sentiment 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.
package/README.md ADDED
@@ -0,0 +1,283 @@
1
+ ![SharpAPI GitHub cover](https://sharpapi.com/sharpapi-github-php-bg.jpg "SharpAPI Node.js Client")
2
+
3
+ # Product Review Sentiment Analyzer API for Node.js
4
+
5
+ ## ⭐ Analyze product review sentiment with AI — powered by SharpAPI.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@sharpapi/sharpapi-node-product-review-sentiment.svg)](https://www.npmjs.com/package/@sharpapi/sharpapi-node-product-review-sentiment)
8
+ [![License](https://img.shields.io/npm/l/@sharpapi/sharpapi-node-product-review-sentiment.svg)](https://github.com/sharpapi/sharpapi-node-client/blob/master/LICENSE.md)
9
+
10
+ **SharpAPI Product Review Sentiment Analyzer** uses advanced AI to determine if product reviews are positive, negative, or neutral with confidence scores. Perfect for e-commerce platforms, review management, and customer feedback analysis.
11
+
12
+ ---
13
+
14
+ ## 📋 Table of Contents
15
+
16
+ 1. [Requirements](#requirements)
17
+ 2. [Installation](#installation)
18
+ 3. [Usage](#usage)
19
+ 4. [API Documentation](#api-documentation)
20
+ 5. [Examples](#examples)
21
+ 6. [License](#license)
22
+
23
+ ---
24
+
25
+ ## Requirements
26
+
27
+ - Node.js >= 16.x
28
+ - npm or yarn
29
+
30
+ ---
31
+
32
+ ## Installation
33
+
34
+ ### Step 1. Install the package via npm:
35
+
36
+ ```bash
37
+ npm install @sharpapi/sharpapi-node-product-review-sentiment
38
+ ```
39
+
40
+ ### Step 2. Get your API key
41
+
42
+ Visit [SharpAPI.com](https://sharpapi.com/) to get your API key.
43
+
44
+ ---
45
+
46
+ ## Usage
47
+
48
+ ```javascript
49
+ const { SharpApiProductReviewSentimentService } = require('@sharpapi/sharpapi-node-product-review-sentiment');
50
+
51
+ const apiKey = process.env.SHARP_API_KEY; // Store your API key in environment variables
52
+ const service = new SharpApiProductReviewSentimentService(apiKey);
53
+
54
+ const review = `
55
+ This product exceeded my expectations! The quality is outstanding and delivery was fast.
56
+ I highly recommend it to anyone looking for a reliable solution.
57
+ `;
58
+
59
+ async function analyzeReview() {
60
+ try {
61
+ // Submit sentiment analysis job
62
+ const statusUrl = await service.analyzeSentiment(review);
63
+ console.log('Job submitted. Status URL:', statusUrl);
64
+
65
+ // Fetch results (polls automatically until complete)
66
+ const result = await service.fetchResults(statusUrl);
67
+ const sentiment = result.getResultJson();
68
+
69
+ console.log('Sentiment:', sentiment.opinion);
70
+ console.log('Confidence:', sentiment.score + '%');
71
+ } catch (error) {
72
+ console.error('Error:', error.message);
73
+ }
74
+ }
75
+
76
+ analyzeReview();
77
+ ```
78
+
79
+ ---
80
+
81
+ ## API Documentation
82
+
83
+ ### Methods
84
+
85
+ #### `analyzeSentiment(reviewText: string): Promise<string>`
86
+
87
+ Analyzes the sentiment of a product review.
88
+
89
+ **Parameters:**
90
+ - `reviewText` (string, required): The review text to analyze
91
+
92
+ **Returns:**
93
+ - Promise<string>: Status URL for polling the job result
94
+
95
+ **Example:**
96
+ ```javascript
97
+ const statusUrl = await service.analyzeSentiment(customerReview);
98
+ const result = await service.fetchResults(statusUrl);
99
+ ```
100
+
101
+ ### Response Format
102
+
103
+ The API returns sentiment classification with confidence score:
104
+
105
+ ```json
106
+ {
107
+ "opinion": "POSITIVE",
108
+ "score": 95,
109
+ "key_phrases": [
110
+ "exceeded expectations",
111
+ "outstanding quality",
112
+ "highly recommend"
113
+ ]
114
+ }
115
+ ```
116
+
117
+ **Sentiment Values:**
118
+ - `POSITIVE`: Review expresses satisfaction or praise
119
+ - `NEGATIVE`: Review expresses dissatisfaction or criticism
120
+ - `NEUTRAL`: Review is balanced or factual without strong opinion
121
+
122
+ ---
123
+
124
+ ## Examples
125
+
126
+ ### Basic Sentiment Analysis
127
+
128
+ ```javascript
129
+ const { SharpApiProductReviewSentimentService } = require('@sharpapi/sharpapi-node-product-review-sentiment');
130
+
131
+ const service = new SharpApiProductReviewSentimentService(process.env.SHARP_API_KEY);
132
+
133
+ const review = 'The product broke after 2 days. Very disappointed with the quality.';
134
+
135
+ service.analyzeSentiment(review)
136
+ .then(statusUrl => service.fetchResults(statusUrl))
137
+ .then(result => {
138
+ const sentiment = result.getResultJson();
139
+
140
+ const emoji = sentiment.opinion === 'POSITIVE' ? '😊' :
141
+ sentiment.opinion === 'NEGATIVE' ? '😞' : '😐';
142
+
143
+ console.log(`${emoji} Sentiment: ${sentiment.opinion} (${sentiment.score}% confidence)`);
144
+ })
145
+ .catch(error => console.error('Analysis failed:', error));
146
+ ```
147
+
148
+ ### Batch Review Analysis
149
+
150
+ ```javascript
151
+ const service = new SharpApiProductReviewSentimentService(process.env.SHARP_API_KEY);
152
+
153
+ const reviews = [
154
+ { id: 1, text: 'Amazing product! Love it.' },
155
+ { id: 2, text: 'Not worth the money, poor quality.' },
156
+ { id: 3, text: 'Good product, fast shipping.' },
157
+ { id: 4, text: 'Terrible experience, would not buy again.' }
158
+ ];
159
+
160
+ const analyzed = await Promise.all(
161
+ reviews.map(async (review) => {
162
+ const statusUrl = await service.analyzeSentiment(review.text);
163
+ const result = await service.fetchResults(statusUrl);
164
+ const sentiment = result.getResultJson();
165
+
166
+ return {
167
+ id: review.id,
168
+ text: review.text,
169
+ sentiment: sentiment.opinion,
170
+ score: sentiment.score
171
+ };
172
+ })
173
+ );
174
+
175
+ const positive = analyzed.filter(r => r.sentiment === 'POSITIVE').length;
176
+ const negative = analyzed.filter(r => r.sentiment === 'NEGATIVE').length;
177
+
178
+ console.log(`Positive reviews: ${positive}/${analyzed.length}`);
179
+ console.log(`Negative reviews: ${negative}/${analyzed.length}`);
180
+ ```
181
+
182
+ ### Product Rating Dashboard
183
+
184
+ ```javascript
185
+ const service = new SharpApiProductReviewSentimentService(process.env.SHARP_API_KEY);
186
+
187
+ async function analyzeProductReviews(productId, reviews) {
188
+ const sentiments = await Promise.all(
189
+ reviews.map(async (review) => {
190
+ const statusUrl = await service.analyzeSentiment(review.text);
191
+ const result = await service.fetchResults(statusUrl);
192
+ return result.getResultJson();
193
+ })
194
+ );
195
+
196
+ const positiveCount = sentiments.filter(s => s.opinion === 'POSITIVE').length;
197
+ const negativeCount = sentiments.filter(s => s.opinion === 'NEGATIVE').length;
198
+ const neutralCount = sentiments.filter(s => s.opinion === 'NEUTRAL').length;
199
+
200
+ const avgScore = sentiments.reduce((sum, s) => sum + s.score, 0) / sentiments.length;
201
+
202
+ return {
203
+ productId,
204
+ totalReviews: reviews.length,
205
+ positive: positiveCount,
206
+ negative: negativeCount,
207
+ neutral: neutralCount,
208
+ averageConfidence: Math.round(avgScore),
209
+ overallSentiment: positiveCount > negativeCount ? 'POSITIVE' : 'NEGATIVE'
210
+ };
211
+ }
212
+
213
+ const productReviews = [
214
+ { text: 'Great quality, very satisfied!' },
215
+ { text: 'Perfect for my needs.' },
216
+ { text: 'Not as described, disappointed.' }
217
+ ];
218
+
219
+ const dashboard = await analyzeProductReviews('PROD-123', productReviews);
220
+ console.log('Product Sentiment Dashboard:', dashboard);
221
+ ```
222
+
223
+ ---
224
+
225
+ ## Use Cases
226
+
227
+ - **E-commerce Platforms**: Analyze customer reviews automatically
228
+ - **Review Moderation**: Flag negative reviews for quick response
229
+ - **Product Insights**: Understand customer satisfaction trends
230
+ - **Quality Control**: Identify products with declining sentiment
231
+ - **Marketing**: Highlight positive reviews in campaigns
232
+ - **Customer Support**: Prioritize responses to negative feedback
233
+ - **Competitive Analysis**: Compare sentiment across products
234
+
235
+ ---
236
+
237
+ ## Sentiment Detection
238
+
239
+ The analyzer evaluates multiple factors:
240
+
241
+ - **Language Patterns**: Positive vs negative word choices
242
+ - **Emotional Indicators**: Expressions of satisfaction or frustration
243
+ - **Rating Consistency**: Alignment with explicit ratings
244
+ - **Key Phrases**: Important phrases indicating sentiment
245
+ - **Context Understanding**: Industry-specific terminology
246
+ - **Sarcasm Detection**: Identifies ironic or sarcastic reviews
247
+
248
+ ---
249
+
250
+ ## API Endpoint
251
+
252
+ **POST** `/ecommerce/review_sentiment`
253
+
254
+ For detailed API specifications, refer to:
255
+ - [Postman Documentation](https://documenter.getpostman.com/view/31106842/2sBXVeGsa8)
256
+ - [Product Page](https://sharpapi.com/en/catalog/ai/e-commerce/product-review-sentiment-checker)
257
+
258
+ ---
259
+
260
+ ## Related Packages
261
+
262
+ - [@sharpapi/sharpapi-node-travel-review-sentiment](https://www.npmjs.com/package/@sharpapi/sharpapi-node-travel-review-sentiment) - Travel review sentiment
263
+ - [@sharpapi/sharpapi-node-detect-spam](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-spam) - Spam detection
264
+ - [@sharpapi/sharpapi-node-product-categories](https://www.npmjs.com/package/@sharpapi/sharpapi-node-product-categories) - Product categorization
265
+ - [@sharpapi/sharpapi-node-client](https://www.npmjs.com/package/@sharpapi/sharpapi-node-client) - Full SharpAPI SDK
266
+
267
+ ---
268
+
269
+ ## License
270
+
271
+ This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.
272
+
273
+ ---
274
+
275
+ ## Support
276
+
277
+ - **Documentation**: [SharpAPI.com Documentation](https://sharpapi.com/documentation)
278
+ - **Issues**: [GitHub Issues](https://github.com/sharpapi/sharpapi-node-client/issues)
279
+ - **Email**: contact@sharpapi.com
280
+
281
+ ---
282
+
283
+ **Powered by [SharpAPI](https://sharpapi.com/) - AI-Powered API Workflow Automation**
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@sharpapi/sharpapi-node-product-review-sentiment",
3
+ "version": "1.0.0",
4
+ "description": "SharpAPI.com Node.js SDK for analyzing product review sentiment",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "jest"
8
+ },
9
+ "keywords": [
10
+ "sharpapi",
11
+ "ai-powered",
12
+ "ai capabilities",
13
+ "api",
14
+ "ai api",
15
+ "api integration",
16
+ "artificial intelligence",
17
+ "natural language processing",
18
+ "restful api",
19
+ "nodejs",
20
+ "software development",
21
+ "e-commerce",
22
+ "product reviews",
23
+ "sentiment analysis"
24
+ ],
25
+ "author": "Dawid Makowski <contact@sharpapi.com>",
26
+ "license": "MIT",
27
+ "dependencies": {
28
+ "@sharpapi/sharpapi-node-core": "file:../sharpapi-node-core"
29
+ },
30
+ "devDependencies": {
31
+ "jest": "^29.7.0"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/sharpapi/sharpapi-node-product-review-sentiment.git"
39
+ }
40
+ }
@@ -0,0 +1,21 @@
1
+ const { SharpApiCoreService, SharpApiJobTypeEnum } = require('@sharpapi/sharpapi-node-core');
2
+
3
+ /**
4
+ * Service for analyzing product review sentiment using SharpAPI.com
5
+ */
6
+ class SharpApiProductReviewSentimentService extends SharpApiCoreService {
7
+ /**
8
+ * Parses the customer's product review and provides its sentiment (POSITIVE/NEGATIVE/NEUTRAL)
9
+ * with a score between 0-100%. Great for sentiment report processing for any online store.
10
+ *
11
+ * @param {string} review
12
+ * @returns {Promise<string>} - The status URL.
13
+ */
14
+ async productReviewSentiment(review) {
15
+ const data = { content: review };
16
+ const response = await this.makeRequest('POST', SharpApiJobTypeEnum.ECOMMERCE_REVIEW_SENTIMENT.url, data);
17
+ return this.parseStatusUrl(response);
18
+ }
19
+ }
20
+
21
+ module.exports = { SharpApiProductReviewSentimentService };
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ // sharpapi-node-product-review-sentiment/src/index.js
2
+ const { SharpApiProductReviewSentimentService } = require('./SharpApiProductReviewSentimentService');
3
+
4
+ module.exports = {
5
+ SharpApiProductReviewSentimentService,
6
+ };