unshared-clientjs-sdk 1.0.7 → 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 CHANGED
@@ -196,31 +196,22 @@ export default class UnsharedLabsClient {
196
196
  /**
197
197
  * Triggers an email verification to be sent to the user.
198
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.
199
+ * This method sends a verification email to the specified email address.
202
200
  *
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.
201
+ * @param {string} emailAddress - Email address to send the verification to
207
202
  *
208
203
  * @returns {Promise<any>} Response object from the email service containing verification details
209
204
  *
210
205
  * @throws {Error} Throws an error if:
211
- * - Neither userId nor emailAddress is a valid email address
206
+ * - The emailAddress is not a valid email address
212
207
  * - The email service request fails or returns a non-OK status
213
208
  *
214
209
  * @example
215
210
  * ```typescript
216
- * // Using userId as email
217
211
  * await client.triggerEmailVerification('user@example.com');
218
- *
219
- * // Using separate emailAddress
220
- * await client.triggerEmailVerification('user@example.com', 'user@example.com');
221
212
  * ```
222
213
  */
223
- triggerEmailVerification(userId: string, emailAddress?: string): Promise<any>;
214
+ triggerEmailVerification(emailAddress: string): Promise<any>;
224
215
  /**
225
216
  * Verifies an email verification code for a user.
226
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),d=(0,util_1.encryptData)(a,this._apiKey),y=(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: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(p)});if(!u.ok){const t=await u.json().catch(()=>({error:u.statusText}));throw new Error(`API returned error: ${JSON.stringify(t)}`)}const _=await u.json();return{status:u.status,statusText:u.statusText,data:_}}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),y=(0,util_1.encryptData)(s,this._apiKey),p=(0,util_1.encryptData)(n,this._apiKey),u={user_id:c,event_type:t,ip_address:h,device_id:l,session_hash:d,user_agent:y,email_address:p,event_details:(0,util_1.encryptData)(o?JSON.stringify([...o.entries()]):null,this._apiKey)},_=await fetch(`${this._apiBaseUrl}/api/v1/processUserEvent`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify(u)});if(!_.ok){const t=await _.json().catch(()=>({error:_.statusText}));throw new Error(`API returned error: ${JSON.stringify(t)}`)}return await _.json()}catch(t){throw new Error(`Failed to process user event: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}async triggerEmailVerification(t,e){try{const i=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;let r;if(i.test(t))r=t;else{if(!e||!i.test(e))throw new Error("Invalid email address: userId must be an email address or emailAddress must be provided");r=e}const a=await fetch(`${this._emailServiceUrl}/api/send-email`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify({to:r})});if(!a.ok){const t=await a.json().catch(()=>({error:a.statusText}));throw new Error(`Email service returned error: ${JSON.stringify(t)}`)}return await a.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),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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unshared-clientjs-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "",
5
5
  "main": "dist/client.js",
6
6
  "types": "dist/client.d.ts",