unshared-clientjs-sdk 1.0.6 → 1.0.8
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 +4 -15
- package/dist/client.js +1 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -25,7 +25,6 @@ export interface UnsharedLabsClientConfig {
|
|
|
25
25
|
* @property {string} device_id - Encrypted device identifier
|
|
26
26
|
* @property {string} session_hash - Encrypted session hash
|
|
27
27
|
* @property {string} user_agent - Encrypted user agent string
|
|
28
|
-
* @property {string} client_timestamp - Timestamp when the event was created on the client
|
|
29
28
|
*/
|
|
30
29
|
export interface ProcessUserEventData {
|
|
31
30
|
id: string;
|
|
@@ -36,7 +35,6 @@ export interface ProcessUserEventData {
|
|
|
36
35
|
device_id: string;
|
|
37
36
|
session_hash: string;
|
|
38
37
|
user_agent: string;
|
|
39
|
-
client_timestamp: string;
|
|
40
38
|
}
|
|
41
39
|
/**
|
|
42
40
|
* Event processing result containing event data and status information.
|
|
@@ -198,31 +196,22 @@ export default class UnsharedLabsClient {
|
|
|
198
196
|
/**
|
|
199
197
|
* Triggers an email verification to be sent to the user.
|
|
200
198
|
*
|
|
201
|
-
* This method sends a verification email to the specified
|
|
202
|
-
* provided either as the userId parameter (if userId is a valid email) or as the optional
|
|
203
|
-
* emailAddress parameter.
|
|
199
|
+
* This method sends a verification email to the specified email address.
|
|
204
200
|
*
|
|
205
|
-
* @param {string}
|
|
206
|
-
*
|
|
207
|
-
* @param {string} [emailAddress] - Optional email address to send the verification to.
|
|
208
|
-
* Required if userId is not a valid email address.
|
|
201
|
+
* @param {string} emailAddress - Email address to send the verification to
|
|
209
202
|
*
|
|
210
203
|
* @returns {Promise<any>} Response object from the email service containing verification details
|
|
211
204
|
*
|
|
212
205
|
* @throws {Error} Throws an error if:
|
|
213
|
-
* -
|
|
206
|
+
* - The emailAddress is not a valid email address
|
|
214
207
|
* - The email service request fails or returns a non-OK status
|
|
215
208
|
*
|
|
216
209
|
* @example
|
|
217
210
|
* ```typescript
|
|
218
|
-
* // Using userId as email
|
|
219
211
|
* await client.triggerEmailVerification('user@example.com');
|
|
220
|
-
*
|
|
221
|
-
* // Using separate emailAddress
|
|
222
|
-
* await client.triggerEmailVerification('user@example.com', 'user@example.com');
|
|
223
212
|
* ```
|
|
224
213
|
*/
|
|
225
|
-
triggerEmailVerification(
|
|
214
|
+
triggerEmailVerification(emailAddress: string): Promise<any>;
|
|
226
215
|
/**
|
|
227
216
|
* Verifies an email verification code for a user.
|
|
228
217
|
*
|
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),
|
|
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;
|