emx-shoppable-sdk-js
v1.0.12
Published
JavaScript SDK for Shoppable and Face Recognition APIs
Maintainers
Readme
emx-shoppable-sdk-js
A JavaScript SDK for interacting with:
✅ Player Description API ✅ Shoppable Item API ✅ Face Recognition API
This SDK provides simple AWS-style function calls using callbacks, with built-in error codes, logging, and support for custom error messages.
✅ Installation
npm install emx-shoppable-sdk-js
✅ Usage
How to import and use in code
const { EmxbeSDK } = require('emx-shoppable-sdk-js');
// Get Player Description EmxbeSDK.getPlayerDescription('dale steyn', (err, data) => { if (err) console.error('Error:', err); else console.log('Player Data:', data); });
// Get Shoppable Item EmxbeSDK.getShoppableItem('virat kohli', (err, data) => { if (err) console.error('Error:', err); else console.log('Shoppable Item:', data); });
// Face Recognition EmxbeSDK.recognizeFace('', (err, data) => { if (err) console.error('Error:', err); else console.log('Face Recognition Result:', data); });
✅ Test After Install
mkdir sdk-test cd sdk-test npm init -y npm install emx-shoppable-sdk-js
Create test.js:
const { EmxbeSDK } = require('emx-shoppable-sdk-js');
EmxbeSDK.getPlayerDescription('dale steyn', (err, data) => { console.log(err || data); });
Run:
node test.js
Error Codes Reference
| Code | Category | Short Code | Description | |-------|--------------------|------------------------------------|--------------------------------------------------------------------| | 1001 | Generic | ERR_API | API Error – Issue with API response | | 1002 | Generic | ERR_NETWORK | Network Error – No response received from server | | 1003 | Generic | ERR_UNKNOWN | Unexpected Error – Something went wrong | | 2001 | Player API | ERR_PLAYER_NAME_REQUIRED | Player name is required – Parameter "name" cannot be empty | | 2002 | Player API | ERR_PLAYER_NOT_FOUND | Player not found on Wikipedia | | 2003 | Player API | ERR_PLAYER_RATE_LIMIT | Rate limit exceeded on Wikipedia API | | 2004 | Player API | ERR_PLAYER_SERVICE_UNAVAILABLE | Wikipedia API unavailable | | 2005 | Player API | ERR_PLAYER_BAD_GATEWAY | Wikipedia API URL unreachable or invalid | | 3001 | Shoppable API | ERR_ITEM_NAME_REQUIRED | Search string is required | | 3002 | Shoppable API | ERR_SERP_API_KEY_MISSING | Missing SERP API key in environment | | 3003 | Shoppable API | ERR_SHOPPING_NOT_FOUND | No shopping results found | | 3004 | Shoppable API | ERR_SHOPPING_RATE_LIMIT | Rate limit exceeded on SERP API | | 3005 | Shoppable API | ERR_SHOPPING_SERVICE_UNAVAILABLE | SERP API service unavailable | | 3006 | Shoppable API | ERR_SHOPPING_BAD_GATEWAY | SERP API URL unreachable or invalid | | 1001* | Face Recognition | ERR_FACE_NO_IMAGE | No image provided | | 2001* | Face Recognition | ERR_FACE_DETECTION_FAILED | Face detection failed | | 2002* | Face Recognition | ERR_FACE_IMAGE_INCOMPATIBLE | Incompatible image format | | 2003* | Face Recognition | ERR_FACE_NO_FACE_DETECTED | No face detected | | 2004* | Face Recognition | ERR_FACE_NO_ENCODINGS | No face encodings found | | 3001* | Face Recognition | ERR_FACE_NO_MATCHING_PLAYER | No matching player found | | 404 | Face Recognition | ERR_FACE_PROFILE_NOT_FOUND | Cricbuzz profile link not found | | 500 | Face Recognition | ERR_FACE_PROFILE_SECTION_MISSING | Player profile section not found on Cricbuzz | | 5001 | Face Recognition | ERR_FACE_VIDEO_FETCH_FAILED | Failed to fetch videos | | 9001 | Face Recognition | ERR_FACE_LIBRARY_ERROR | face_recognition library error | | 9002 | Face Recognition | ERR_FACE_INTERNAL_SERVER_ERROR | Internal server error |
✅ Setting Custom Error Messages
You can customize error codes and messages dynamically using setErrorCode():
const { setErrorCode, getErrorCodes } = require('emx-shoppable-sdk-js/utils/errorCodes');
// Customize Player API error
setErrorCode('ERR_PLAYER_NOT_FOUND', 9999, 'Custom message: Player data missing');
// Customize Shoppable API error
setErrorCode('ERR_SHOPPING_NOT_FOUND', null, 'Custom message: No items found');
// Customize Face Recognition error
setErrorCode('ERR_FACE_NO_IMAGE', 8888, 'Custom message: Please provide an image');
// Verify updates
console.log(getErrorCodes());✅ After this, when the SDK encounters these errors, it will return your custom message and code.
**NOTE**: Based on the error returned by the API , Search that particular errors "Short Code" from the above error list and then pass it in the setErrorCode() Function to Customize the Error Codes to your preference.
**Example**: Suppose while using the SDK, Error returned by FaceRecognize API is :
{
"error": "Internal server error: list index out of range",
"error_code": 9002
}
Find this particular ERROR CODE and MESSAGE in the Error Codes Reference and get its SHORT CODE and then use that along with a customized Error Message and Error Code of your Preference, Like Below.
setErrorCode("ERR_FACE_INTERNAL_SERVER_ERROR", 6699, "Custom message: Please dont waste my time...");
Then this particular Customized Message will be rendered.
The Same Applies to the other TWO API's.✅ Example Error Object Returned by SDK:
{
"code": 9999,
"message": "Custom message: Player data missing",
"details": { "error": "Invalid player name" }
}
{
"code": null,
"message": "Custom message: No items found",
"details": { "error": "Custom message: No items found" }
}
{
"code": 8888,
"message": "Custom message: Please provide an image",
"details": { "error": "Custom message: No image provided" }
}✅ React Integration Example
Here’s how you can integrate the SDK in a React component and display custom error messages in the UI:
import React, { useRef, useState, useEffect } from "react";
import "./VideoPlayer.css";
import { EmxbeSDK } from "emx-shoppable-sdk-js";
import { setErrorCode, getErrorCodes } from "emx-shoppable-sdk-js/utils/errorCodes";
const VideoPlayer = () => {
const videoRef = useRef(null);
const [errorMessage, setErrorMessage] = useState("");
// -------------------------------------------------
// CUSTOM ERROR CODES
// -------------------------------------------------
useEffect(() => {
// Face recognition errors
setErrorCode("ERR_FACE_INTERNAL_SERVER_ERROR", 9966, "Custom message: Please provide suna");
setErrorCode("ERR_FACE_NO_MATCHING_PLAYER", 7777, "Custom message: No matching player found in database");
// Shoppable errors
setErrorCode("ERR_SHOPPING_NOT_FOUND", 3553, "Custom message: No items found");
console.log("Updated Error Codes:", getErrorCodes());
if (videoRef.current) {
videoRef.current.crossOrigin = "anonymous";
}
}, []);
// -------------------------------------------------
// FRAME CAPTURE (NEEDED FOR FACE RECOGNITION)
// -------------------------------------------------
const captureFrame = () => {
const video = videoRef.current;
if (!video) return null;
const canvas = document.createElement("canvas");
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
const ctx = canvas.getContext("2d");
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
return canvas.toDataURL("image/jpeg");
};
// -------------------------------------------------
// ONLY SDK CALLS — FACE RECOG + STATS + VIDEOS
// -------------------------------------------------
const handleInfoClick = () => {
setErrorMessage("");
const image = captureFrame();
if (!image) return;
// 1️⃣ FACE RECOGNITION
EmxbeSDK.recognizeFace("", (err, data) => {
if (err) {
setErrorMessage(`Face Recognition Error: ${err.message} (Code: ${err.code})`);
return;
}
// 2️⃣ PLAYER DESCRIPTION
EmxbeSDK.getPlayerDescription("//", (err, playerData) => {
if (err) {
setErrorMessage(`Player Description Error: ${err.message} (Code: ${err.code})`);
}
});
// 3️⃣ SHOPPABLE ITEMS
EmxbeSDK.getShoppableItem("mohanlal", (err, shopData) => {
if (err) {
setErrorMessage(`Shoppable Item Error: ${err.message} (Code: ${err.code})`);
}
});
});
};
return (
<div className="video-player-container">
{/* VIDEO PLAYER */}
<video ref={videoRef} className="video-player" controls>
<source src="source.mp4" type="video/mp4" />
Your browser does not support the video tag.
</video>
{/* INFO BUTTON */}
<div className="info-icon" onClick={handleInfoClick}>i</div>
{/* ERROR MESSAGE */}
{errorMessage && (
<div className="error-message">
<p>{errorMessage}</p>
</div>
)}
</div>
);
};
export default VideoPlayer;✅ This example:
- Captures a video frame
- Calls Face Recognition, Player Description, and Shoppable APIs
- Displays custom error messages in the UI
✅ What Each Successful SDK Call Output Looks Like
- Face Recognition:
{
"recognized_player": "tim_paine",
"stats": {
"error": "Player profile section not found on Cricbuzz."
},
"videos": [
{
"channelTitle": "Star Sports",
"thumbnail": "https://i.ytimg.com/vi/pfO64Is2fVA/hqdefault.jpg",
"title": "2021 Sydney Test: Tim Paine & R. Ashwin's epic banter caught on the stump mic! | #AUSvINDonStar",
"videoId": "pfO64Is2fVA"
},
{
"channelTitle": "TwoLeftHands",
"thumbnail": "https://i.ytimg.com/vi/FyOHZKEDhPg/hqdefault.jpg",
"title": "The LUCKIEST AND UNLUCKIEST test CRICKET CAREER!? 😯",
"videoId": "FyOHZKEDhPg"
}
]
}- Get Player Description:
{
"name": "Tim Paine",
"description": "Timothy David Paine is an Australian former cricketer and a former captain...",
"image": {
"thumbnail": "https://upload.wikimedia.org/wikipedia/commons/...",
"original": "https://upload.wikimedia.org/wikipedia/commons/..."
}
}- Get Shoppable Item:
{
"code": 200,
"shopping_details": [
{
"price": "₹2,500",
"title": "The Empuraan Eagle Ring",
"source": "Vitra Jewellery",
"delivery": "Free delivery",
"position": 1,
"thumbnail": "https://encrypted-tbn3.gstatic.com/...",
"product_id": "10134496805831390726",
"product_link": "https://www.google.com/search?ibp=oshop&q=mohanlal..."
}
]
}✅ Author & Company
Author: Akshay Saji
Company: L&T Technology Services
✅ This README includes: - Installation steps - Usage examples - Error codes table - Author & company info - Publish & test instructions
