unshared-clientjs-sdk 1.0.5 → 1.0.6

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