unshared-clientjs-sdk 1.0.12 → 1.0.14

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/dist/client.d.ts CHANGED
@@ -18,6 +18,7 @@ export interface UnsharedLabsClientConfig {
18
18
  *
19
19
  * This client provides methods to:
20
20
  * - Process user events for fraud detection and analysis
21
+ * - Check if a user is flagged as an account sharer
21
22
  * - Trigger email verification
22
23
  * - Verify email verification codes
23
24
  *
@@ -93,6 +94,7 @@ export default class UnsharedLabsClient {
93
94
  * @param {string} sessionHash - Hash of the user's session
94
95
  * @param {string} userAgent - User agent string from the browser/client
95
96
  * @param {string} emailAddress - Email address of the user
97
+ * @param {string | null} [subscriptionStatus] - Optional subscription status string, (e.g. 'paid', 'free', 'trial', 'discounted')
96
98
  * @param {Map<string, any> | null} [eventDetails] - Optional map of additional event details to include
97
99
  *
98
100
  * @returns {Promise<any>} Response object containing:
@@ -111,6 +113,7 @@ export default class UnsharedLabsClient {
111
113
  * 'session789',
112
114
  * 'Mozilla/5.0...',
113
115
  * 'user@example.com',
116
+ * 'paid',
114
117
  * new Map([['source', 'web']])
115
118
  * );
116
119
  *
@@ -121,7 +124,38 @@ export default class UnsharedLabsClient {
121
124
  * }
122
125
  * ```
123
126
  */
124
- processUserEvent(eventType: string, userId: string, ipAddress: string, deviceId: string, sessionHash: string, userAgent: string, emailAddress: string, eventDetails?: Map<string, any> | null): Promise<any>;
127
+ processUserEvent(eventType: string, userId: string, ipAddress: string, deviceId: string, sessionHash: string, userAgent: string, emailAddress: string, subscriptionStatus?: string | null, eventDetails?: Map<string, any> | null): Promise<any>;
128
+ /**
129
+ * Checks if a user is flagged as an account sharer based on their email address and device ID.
130
+ *
131
+ * This method encrypts the email address and device ID before sending them to the API.
132
+ * The response indicates whether the user has been flagged for suspicious activity.
133
+ *
134
+ * @param {string} emailAddress - Email address of the user to check
135
+ * @param {string} deviceId - Unique identifier for the device
136
+ *
137
+ * @returns {Promise<any>} Response object containing:
138
+ * - success: Boolean indicating if the API call was successful
139
+ * - status: String indicating the status ("success" or "error")
140
+ * - is_user_flagged: Boolean indicating if the user was flagged as an account sharer
141
+ * - status_details: String with error details (only present on error)
142
+ * - error: Error message (only present on failure)
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * const response = await client.checkUser(
147
+ * 'user@example.com',
148
+ * 'device456'
149
+ * );
150
+ *
151
+ * if (!response.success) {
152
+ * console.error('Error:', response.error || response.status_details);
153
+ * } else if (response.is_user_flagged) {
154
+ * console.log('User is flagged for suspicious activity');
155
+ * }
156
+ * ```
157
+ */
158
+ checkUser(emailAddress: string, deviceId: string): Promise<any>;
125
159
  /**
126
160
  * Triggers an email verification to be sent to the user.
127
161
  *
package/dist/client.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const util_1=require("./util");class UnsharedLabsClient{constructor(t){this._apiBaseUrl="https://api.unsharedlabs.com",this._emailServiceUrl="https://emailservice.unsharedlabs.com",this._apiKey=t.apiKey,this._clientId=atob(t.clientId).trim(),t.baseUrl&&(this._apiBaseUrl=t.baseUrl),t.emailServiceUrl&&(this._emailServiceUrl=t.emailServiceUrl)}_getBasicAuthHeader(){const t=`${this._clientId}:${this._apiKey}`;return`Basic ${Buffer.from(t).toString("base64")}`}async submitEvent(t,e,i,r,a,s,n,o){try{const c=(0,util_1.encryptData)(e,this._apiKey),h=(0,util_1.encryptData)(i,this._apiKey),l=(0,util_1.encryptData)(r,this._apiKey),d=(0,util_1.encryptData)(a,this._apiKey),_=(0,util_1.encryptData)(s,this._apiKey),p={user_id:c,event_type:t,ip_address:h,device_id:l,session_hash:d,user_agent:_,client_timestamp:n,event_details:(0,util_1.encryptData)(o?JSON.stringify([...o.entries()]):null,this._apiKey)},y=await fetch(`${this._apiBaseUrl}/api/v1/submitEvent`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify(p)});if(!y.ok){const t=await y.json().catch(()=>({error:y.statusText}));throw new Error(`API returned error: ${JSON.stringify(t)}`)}const u=await y.json();return{status:y.status,statusText:y.statusText,data:u}}catch(t){throw new Error(`Failed to call UnsharedLabs API: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}async processUserEvent(t,e,i,r,a,s,n,o){try{const c=(0,util_1.encryptData)(e,this._apiKey),h=(0,util_1.encryptData)(i,this._apiKey),l=(0,util_1.encryptData)(r,this._apiKey),d=(0,util_1.encryptData)(a,this._apiKey),_=(0,util_1.encryptData)(s,this._apiKey),p=(0,util_1.encryptData)(n,this._apiKey),y={user_id:c,event_type:t,ip_address:h,device_id:l,session_hash:d,user_agent:_,email_address:p,event_details:(0,util_1.encryptData)(o?JSON.stringify([...o.entries()]):null,this._apiKey)},u=await fetch(`${this._apiBaseUrl}/api/v1/processUserEvent`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify(y)});return await u.json()}catch(t){return{success:!1,error:`Failed to process user event: ${t instanceof Error?t.message:JSON.stringify(t)}`}}}async triggerEmailVerification(t,e){try{if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t))throw new Error("Invalid email address provided");const i=await fetch(`${this._emailServiceUrl}/api/send-email`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify({email_address:t,device_id:e})});if(!i.ok){const t=await i.json().catch(()=>({error:i.statusText}));throw new Error(`Email service returned error: ${JSON.stringify(t)}`)}return await i.json()}catch(t){throw new Error(`Failed to trigger email verification: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}async verify(t,e,i){try{const r=await fetch(`${this._emailServiceUrl}/api/verify`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify({email_address:t,device_id:e,code:i})});if(!r.ok){const t=await r.json().catch(()=>({error:r.statusText}));throw new Error(`Verification service returned error: ${JSON.stringify(t)}`)}return await r.json()}catch(t){throw new Error(`Failed to verify code: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}}exports.default=UnsharedLabsClient;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const util_1=require("./util");class UnsharedLabsClient{constructor(t){this._apiBaseUrl="https://api.unsharedlabs.com",this._emailServiceUrl="https://emailservice.unsharedlabs.com",this._apiKey=t.apiKey,this._clientId=atob(t.clientId).trim(),t.baseUrl&&(this._apiBaseUrl=t.baseUrl),t.emailServiceUrl&&(this._emailServiceUrl=t.emailServiceUrl)}_getBasicAuthHeader(){const t=`${this._clientId}:${this._apiKey}`;return`Basic ${Buffer.from(t).toString("base64")}`}async submitEvent(t,e,i,a,r,s,n,c){try{const o=(0,util_1.encryptData)(e,this._apiKey),h=(0,util_1.encryptData)(i,this._apiKey),_=(0,util_1.encryptData)(a,this._apiKey),l=(0,util_1.encryptData)(r,this._apiKey),p=(0,util_1.encryptData)(s,this._apiKey),y={user_id:o,event_type:t,ip_address:h,device_id:_,session_hash:l,user_agent:p,client_timestamp:n,event_details:(0,util_1.encryptData)(c?JSON.stringify([...c.entries()]):null,this._apiKey)},u=await fetch(`${this._apiBaseUrl}/api/v1/submitEvent`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify(y)});if(!u.ok){const t=await u.json().catch(()=>({error:u.statusText}));throw new Error(`API returned error: ${JSON.stringify(t)}`)}const d=await u.json();return{status:u.status,statusText:u.statusText,data:d}}catch(t){throw new Error(`Failed to call UnsharedLabs API: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}async processUserEvent(t,e,i,a,r,s,n,c,o){try{const h=(0,util_1.encryptData)(e,this._apiKey),_=(0,util_1.encryptData)(i,this._apiKey),l=(0,util_1.encryptData)(a,this._apiKey),p=(0,util_1.encryptData)(r,this._apiKey),y=(0,util_1.encryptData)(s,this._apiKey),u=(0,util_1.encryptData)(n,this._apiKey),d={user_id:h,event_type:t,ip_address:_,device_id:l,session_hash:p,user_agent:y,email_address:u,event_details:(0,util_1.encryptData)(o?JSON.stringify([...o.entries()]):null,this._apiKey)};null!=c&&"string"==typeof c&&(d.subscription_status=c.trim());const f=await fetch(`${this._apiBaseUrl}/api/v1/processUserEvent`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify(d)});return await f.json()}catch(t){return{success:!1,error:`Failed to process user event: ${t instanceof Error?t.message:JSON.stringify(t)}`}}}async checkUser(t,e){try{const i=(0,util_1.encryptData)(t,this._apiKey),a=(0,util_1.encryptData)(e,this._apiKey),r=new URLSearchParams({email_address:i||"",device_id:a||""}),s=await fetch(`${this._apiBaseUrl}/api/v1/checkUser?${r.toString()}`,{method:"GET",headers:{Authorization:this._getBasicAuthHeader()}});return await s.json()}catch(t){return{success:!1,error:`Failed to check user: ${t instanceof Error?t.message:JSON.stringify(t)}`}}}async triggerEmailVerification(t,e){try{if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t))throw new Error("Invalid email address provided");const i=(0,util_1.encryptData)(t,this._apiKey),a=(0,util_1.encryptData)(e,this._apiKey),r=await fetch(`${this._emailServiceUrl}/api/trigger-email-verification`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify({email_address:i,device_id:a})});if(!r.ok){const t=await r.json().catch(()=>({error:r.statusText}));throw new Error(`Email service returned error: ${JSON.stringify(t)}`)}return await r.json()}catch(t){throw new Error(`Failed to trigger email verification: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}async verify(t,e,i){try{const a=(0,util_1.encryptData)(t,this._apiKey),r=(0,util_1.encryptData)(e,this._apiKey),s=(0,util_1.encryptData)(i,this._apiKey),n=await fetch(`${this._emailServiceUrl}/api/verify`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify({email_address:a,device_id:r,code:s})});if(!n.ok){const t=await n.json().catch(()=>({error:n.statusText}));throw new Error(`Verification service returned error: ${JSON.stringify(t)}`)}return await n.json()}catch(t){throw new Error(`Failed to verify code: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}}exports.default=UnsharedLabsClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unshared-clientjs-sdk",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "",
5
5
  "main": "dist/client.js",
6
6
  "types": "dist/client.d.ts",