unshared-clientjs-sdk 1.0.5 → 1.0.7

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 (2) hide show
  1. package/dist/client.d.ts +203 -1
  2. package/package.json +1 -1
package/dist/client.d.ts CHANGED
@@ -1,9 +1,31 @@
1
+ /**
2
+ * Configuration object for initializing the UnsharedLabsClient.
3
+ *
4
+ * @interface UnsharedLabsClientConfig
5
+ * @property {string} apiKey - Your API key for authenticating with UnsharedLabs services
6
+ * @property {string} clientId - Encrypted client ID for authentication
7
+ * @property {string} [baseUrl] - Optional custom base URL for the API service
8
+ * @property {string} [emailServiceUrl] - Optional custom URL for the email service
9
+ */
1
10
  export interface UnsharedLabsClientConfig {
2
11
  apiKey: string;
3
12
  clientId: string;
4
13
  baseUrl?: string;
5
14
  emailServiceUrl?: string;
6
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
+ */
7
29
  export interface ProcessUserEventData {
8
30
  id: string;
9
31
  event_type: string;
@@ -13,38 +35,218 @@ export interface ProcessUserEventData {
13
35
  device_id: string;
14
36
  session_hash: string;
15
37
  user_agent: string;
16
- client_timestamp: string;
17
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
+ */
18
47
  export interface ProcessUserEventEvent {
19
48
  data: ProcessUserEventData[];
20
49
  status: string;
21
50
  statusDetails: string;
22
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
+ */
23
60
  export interface ProcessUserEventAnalysis {
24
61
  status: string;
25
62
  isUserFlagged: boolean;
26
63
  statusDetails: string;
27
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
+ */
28
72
  export interface ProcessUserEventResponseData {
29
73
  event: ProcessUserEventEvent;
30
74
  analysis: ProcessUserEventAnalysis;
31
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
+ */
32
83
  export interface ProcessUserEventResponse {
33
84
  success: boolean;
34
85
  data: ProcessUserEventResponseData;
35
86
  }
87
+ /**
88
+ * Client for interacting with UnsharedLabs API services.
89
+ *
90
+ * This client provides methods to:
91
+ * - Process user events for fraud detection and analysis
92
+ * - Trigger email verification
93
+ * - Verify email verification codes
94
+ *
95
+ * All sensitive data (user IDs, IP addresses, etc.) is automatically encrypted
96
+ * before being sent to the API using the provided API key.
97
+ *
98
+ * @class UnsharedLabsClient
99
+ * @example
100
+ * ```typescript
101
+ * const client = new UnsharedLabsClient({
102
+ * apiKey: 'your-api-key',
103
+ * clientId: 'base64-encoded-client-id'
104
+ * });
105
+ * ```
106
+ */
36
107
  export default class UnsharedLabsClient {
37
108
  private _apiKey;
38
109
  private _clientId;
39
110
  private _apiBaseUrl;
40
111
  private _emailServiceUrl;
112
+ /**
113
+ * Creates a new instance of UnsharedLabsClient.
114
+ *
115
+ * @param {UnsharedLabsClientConfig} config - Configuration object containing API credentials and optional service URLs
116
+ * @constructor
117
+ */
41
118
  constructor(config: UnsharedLabsClientConfig);
42
119
  private _getBasicAuthHeader;
43
120
  /**
121
+ * Submits a user event to the UnsharedLabs API for processing.
122
+ *
44
123
  * @deprecated This method is deprecated and will be removed in a future version. Use `processUserEvent` instead.
124
+ *
125
+ * @param {string} eventType - Type of event being submitted (e.g., 'signup', 'login', 'purchase')
126
+ * @param {string} userId - Unique identifier for the user. Use email address if available.
127
+ * @param {string} ipAddress - IP address of the user
128
+ * @param {string} deviceId - Unique identifier for the device
129
+ * @param {string} sessionHash - Hash of the user's session
130
+ * @param {string} userAgent - User agent string from the browser/client
131
+ * @param {string} clientTimestamp - ISO 8601 timestamp when the event occurred on the client
132
+ * @param {Map<string, any> | null} [eventDetails] - Optional map of additional event details to include
133
+ *
134
+ * @returns {Promise<{status: number, statusText: string, data: any}>} Response object containing HTTP status, status text, and response data
135
+ *
136
+ * @throws {Error} Throws an error if the API request fails or returns a non-OK status
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * const result = await client.submitEvent(
141
+ * 'signup',
142
+ * 'user@example.com',
143
+ * '192.168.1.1',
144
+ * 'device456',
145
+ * 'session789',
146
+ * 'Mozilla/5.0...',
147
+ * '2024-01-01T00:00:00Z',
148
+ * new Map([['source', 'web']])
149
+ * );
150
+ * ```
45
151
  */
46
152
  submitEvent(eventType: string, userId: string, ipAddress: string, deviceId: string, sessionHash: string, userAgent: string, clientTimestamp: string, eventDetails?: Map<string, any> | null): Promise<any>;
153
+ /**
154
+ * Processes a user event through the UnsharedLabs API, including fraud detection and analysis.
155
+ *
156
+ * This method encrypts all sensitive user data (user ID, IP address, device ID, etc.) before
157
+ * sending it to the API. The response includes both event processing results and analysis
158
+ * results that indicate if the user has been flagged for suspicious activity.
159
+ *
160
+ * @param {string} eventType - Type of event being processed (e.g., 'signup', 'login', 'purchase')
161
+ * @param {string} userId - Unique identifier for the user. Use email address if available.
162
+ * @param {string} ipAddress - IP address of the user
163
+ * @param {string} deviceId - Unique identifier for the device
164
+ * @param {string} sessionHash - Hash of the user's session
165
+ * @param {string} userAgent - User agent string from the browser/client
166
+ * @param {string} emailAddress - Email address of the user
167
+ * @param {Map<string, any> | null} [eventDetails] - Optional map of additional event details to include
168
+ *
169
+ * @returns {Promise<ProcessUserEventResponse>} Response object containing:
170
+ * - 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
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * const response = await client.processUserEvent(
180
+ * 'signup',
181
+ * 'user@example.com',
182
+ * '192.168.1.1',
183
+ * 'device456',
184
+ * 'session789',
185
+ * 'Mozilla/5.0...',
186
+ * 'user@example.com',
187
+ * new Map([['source', 'web']])
188
+ * );
189
+ *
190
+ * if (response.data.analysis.isUserFlagged) {
191
+ * console.log('User flagged for suspicious activity');
192
+ * }
193
+ * ```
194
+ */
47
195
  processUserEvent(eventType: string, userId: string, ipAddress: string, deviceId: string, sessionHash: string, userAgent: string, emailAddress: string, eventDetails?: Map<string, any> | null): Promise<ProcessUserEventResponse>;
196
+ /**
197
+ * Triggers an email verification to be sent to the user.
198
+ *
199
+ * This method sends a verification email to the specified user. The email address can be
200
+ * provided either as the userId parameter (if userId is a valid email) or as the optional
201
+ * emailAddress parameter.
202
+ *
203
+ * @param {string} userId - User identifier (enter email if possible). If this is a valid email address, it will be used as the recipient.
204
+ *
205
+ * @param {string} [emailAddress] - Optional email address to send the verification to.
206
+ * Required if userId is not a valid email address.
207
+ *
208
+ * @returns {Promise<any>} Response object from the email service containing verification details
209
+ *
210
+ * @throws {Error} Throws an error if:
211
+ * - Neither userId nor emailAddress is a valid email address
212
+ * - The email service request fails or returns a non-OK status
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * // Using userId as email
217
+ * await client.triggerEmailVerification('user@example.com');
218
+ *
219
+ * // Using separate emailAddress
220
+ * await client.triggerEmailVerification('user@example.com', 'user@example.com');
221
+ * ```
222
+ */
48
223
  triggerEmailVerification(userId: string, emailAddress?: string): Promise<any>;
224
+ /**
225
+ * Verifies an email verification code for a user.
226
+ *
227
+ * This method validates a verification code that was sent to the user via email.
228
+ * The code is typically obtained from the user after they receive the verification email.
229
+ *
230
+ * @param {string} userId - User identifier/email address for whom the code is being verified.
231
+ * @param {string} code - Verification code that was sent to the user's email
232
+ *
233
+ * @returns {Promise<any>} Response object from the verification service containing:
234
+ * - Verification status (success/failure)
235
+ * - Additional verification details
236
+ *
237
+ * @throws {Error} Throws an error if:
238
+ * - The verification service request fails
239
+ * - The service returns a non-OK status (e.g., invalid code, expired code)
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * try {
244
+ * const result = await client.verify('user@example.com', '123456');
245
+ * console.log('Verification successful:', result);
246
+ * } catch (error) {
247
+ * console.error('Verification failed:', error.message);
248
+ * }
249
+ * ```
250
+ */
49
251
  verify(userId: string, code: string): Promise<any>;
50
252
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unshared-clientjs-sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "",
5
5
  "main": "dist/client.js",
6
6
  "types": "dist/client.d.ts",