unshared-clientjs-sdk 1.0.9 → 1.0.10

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
@@ -13,77 +13,6 @@ export interface UnsharedLabsClientConfig {
13
13
  baseUrl?: string;
14
14
  emailServiceUrl?: string;
15
15
  }
16
- /**
17
- * Data structure representing a processed user event.
18
- *
19
- * @interface ProcessUserEventData
20
- * @property {string} id - Unique identifier for the event
21
- * @property {string} event_type - Type of event that was processed
22
- * @property {string} user_id - Encrypted user identifier
23
- * @property {string} email_address - Encrypted email address
24
- * @property {string} ip_address - Encrypted IP address
25
- * @property {string} device_id - Encrypted device identifier
26
- * @property {string} session_hash - Encrypted session hash
27
- * @property {string} user_agent - Encrypted user agent string
28
- */
29
- export interface ProcessUserEventData {
30
- id: string;
31
- event_type: string;
32
- user_id: string;
33
- email_address: string;
34
- ip_address: string;
35
- device_id: string;
36
- session_hash: string;
37
- user_agent: string;
38
- }
39
- /**
40
- * Event processing result containing event data and status information.
41
- *
42
- * @interface ProcessUserEventEvent
43
- * @property {ProcessUserEventData[]} data - Array of processed event data
44
- * @property {string} status - Status of the event processing (e.g., 'success', 'error')
45
- * @property {string} statusDetails - Detailed status message
46
- */
47
- export interface ProcessUserEventEvent {
48
- data: ProcessUserEventData[];
49
- status: string;
50
- statusDetails: string;
51
- }
52
- /**
53
- * Analysis result from processing a user event, including flagging information.
54
- *
55
- * @interface ProcessUserEventAnalysis
56
- * @property {string} status - Status of the analysis (e.g., 'success', 'error')
57
- * @property {boolean} isUserFlagged - Whether the user has been flagged based on the analysis
58
- * @property {string} statusDetails - Detailed status message from the analysis
59
- */
60
- export interface ProcessUserEventAnalysis {
61
- status: string;
62
- isUserFlagged: boolean;
63
- statusDetails: string;
64
- }
65
- /**
66
- * Complete response data containing both event and analysis results.
67
- *
68
- * @interface ProcessUserEventResponseData
69
- * @property {ProcessUserEventEvent} event - Event processing result
70
- * @property {ProcessUserEventAnalysis} analysis - Analysis result
71
- */
72
- export interface ProcessUserEventResponseData {
73
- event: ProcessUserEventEvent;
74
- analysis: ProcessUserEventAnalysis;
75
- }
76
- /**
77
- * Complete response from the processUserEvent API call.
78
- *
79
- * @interface ProcessUserEventResponse
80
- * @property {boolean} success - Whether the API call was successful
81
- * @property {ProcessUserEventResponseData} data - Response data containing event and analysis results
82
- */
83
- export interface ProcessUserEventResponse {
84
- success: boolean;
85
- data: ProcessUserEventResponseData;
86
- }
87
16
  /**
88
17
  * Client for interacting with UnsharedLabs API services.
89
18
  *
@@ -166,13 +95,11 @@ export default class UnsharedLabsClient {
166
95
  * @param {string} emailAddress - Email address of the user
167
96
  * @param {Map<string, any> | null} [eventDetails] - Optional map of additional event details to include
168
97
  *
169
- * @returns {Promise<ProcessUserEventResponse>} Response object containing:
98
+ * @returns {Promise<any>} Response object containing:
170
99
  * - success: Boolean indicating if the API call was successful
171
- * - data: Object containing:
172
- * - event: Event processing result with status and event data
173
- * - analysis: Analysis result with flagging information (isUserFlagged)
174
- *
175
- * @throws {Error} Throws an error if the API request fails or returns a non-OK status
100
+ * - event: Event processing result with status and event data (on success)
101
+ * - analysis: Analysis result with flagging information (on success)
102
+ * - error: Error message (on failure)
176
103
  *
177
104
  * @example
178
105
  * ```typescript
@@ -187,12 +114,14 @@ export default class UnsharedLabsClient {
187
114
  * new Map([['source', 'web']])
188
115
  * );
189
116
  *
190
- * if (response.data.analysis.isUserFlagged) {
117
+ * if (!response.success) {
118
+ * console.error('Error:', response.error);
119
+ * } else if (response.analysis?.is_user_flagged) {
191
120
  * console.log('User flagged for suspicious activity');
192
121
  * }
193
122
  * ```
194
123
  */
195
- processUserEvent(eventType: string, userId: string, ipAddress: string, deviceId: string, sessionHash: string, userAgent: string, emailAddress: string, eventDetails?: Map<string, any> | null): Promise<ProcessUserEventResponse>;
124
+ processUserEvent(eventType: string, userId: string, ipAddress: string, deviceId: string, sessionHash: string, userAgent: string, emailAddress: string, eventDetails?: Map<string, any> | null): Promise<any>;
196
125
  /**
197
126
  * Triggers an email verification to be sent to the user.
198
127
  *
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),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),y=(0,util_1.encryptData)(a,this._apiKey),p=(0,util_1.encryptData)(s,this._apiKey),_={user_id:c,event_type:t,ip_address:h,device_id:l,session_hash:y,user_agent:p,client_timestamp:n,event_details:(0,util_1.encryptData)(o?JSON.stringify([...o.entries()]):null,this._apiKey)},d=await fetch(`${this._apiBaseUrl}/api/v1/submitEvent`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify(_)});if(!d.ok){const t=await d.json().catch(()=>({error:d.statusText}));throw new Error(`API returned error: ${JSON.stringify(t)}`)}const u=await d.json();return{status:d.status,statusText:d.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),y=(0,util_1.encryptData)(a,this._apiKey),p=(0,util_1.encryptData)(s,this._apiKey),_=(0,util_1.encryptData)(n,this._apiKey),d={user_id:c,event_type:t,ip_address:h,device_id:l,session_hash:y,user_agent:p,email_address:_,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(d)});if(!u.ok){const t=await u.json().catch(()=>({error:u.statusText}));throw new Error(`API returned error: ${JSON.stringify(t)}`)}return await u.json()}catch(t){throw new Error(`Failed to process user event: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}async triggerEmailVerification(t){try{if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t))throw new Error("Invalid email address provided");const e=await fetch(`${this._emailServiceUrl}/api/send-email`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify({to:t})});if(!e.ok){const t=await e.json().catch(()=>({error:e.statusText}));throw new Error(`Email service returned error: ${JSON.stringify(t)}`)}return await e.json()}catch(t){throw new Error(`Failed to trigger email verification: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}async verify(t,e){try{const i=await fetch(`${this._emailServiceUrl}/api/verify`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify({user_id:t,code:e})});if(!i.ok){const t=await i.json().catch(()=>({error:i.statusText}));throw new Error(`Verification service returned error: ${JSON.stringify(t)}`)}return await i.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,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),p=(0,util_1.encryptData)(a,this._apiKey),y=(0,util_1.encryptData)(s,this._apiKey),_={user_id:c,event_type:t,ip_address:h,device_id:l,session_hash:p,user_agent:y,client_timestamp:n,event_details:(0,util_1.encryptData)(o?JSON.stringify([...o.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(_)});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,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),p=(0,util_1.encryptData)(a,this._apiKey),y=(0,util_1.encryptData)(s,this._apiKey),_=(0,util_1.encryptData)(n,this._apiKey),u={user_id:c,event_type:t,ip_address:h,device_id:l,session_hash:p,user_agent:y,email_address:_,event_details:(0,util_1.encryptData)(o?JSON.stringify([...o.entries()]):null,this._apiKey)},d=await fetch(`${this._apiBaseUrl}/api/v1/processUserEvent`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify(u)});return await d.json()}catch(t){return{success:!1,error:`Failed to process user event: ${t instanceof Error?t.message:JSON.stringify(t)}`}}}async triggerEmailVerification(t){try{if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t))throw new Error("Invalid email address provided");const e=await fetch(`${this._emailServiceUrl}/api/send-email`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify({to:t})});if(!e.ok){const t=await e.json().catch(()=>({error:e.statusText}));throw new Error(`Email service returned error: ${JSON.stringify(t)}`)}return await e.json()}catch(t){throw new Error(`Failed to trigger email verification: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}async verify(t,e){try{const i=await fetch(`${this._emailServiceUrl}/api/verify`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify({user_id:t,code:e})});if(!i.ok){const t=await i.json().catch(()=>({error:i.statusText}));throw new Error(`Verification service returned error: ${JSON.stringify(t)}`)}return await i.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.9",
3
+ "version": "1.0.10",
4
4
  "description": "",
5
5
  "main": "dist/client.js",
6
6
  "types": "dist/client.d.ts",