unshared-clientjs-sdk 1.0.10 → 1.0.12
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 -3
- package/dist/client.js +1 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -128,7 +128,7 @@ export default class UnsharedLabsClient {
|
|
|
128
128
|
* This method sends a verification email to the specified email address.
|
|
129
129
|
*
|
|
130
130
|
* @param {string} emailAddress - Email address to send the verification to
|
|
131
|
-
*
|
|
131
|
+
* @param {string} deviceId - device id for whom the code is being verified.
|
|
132
132
|
* @returns {Promise<any>} Response object from the email service containing verification details
|
|
133
133
|
*
|
|
134
134
|
* @throws {Error} Throws an error if:
|
|
@@ -140,7 +140,7 @@ export default class UnsharedLabsClient {
|
|
|
140
140
|
* await client.triggerEmailVerification('user@example.com');
|
|
141
141
|
* ```
|
|
142
142
|
*/
|
|
143
|
-
triggerEmailVerification(emailAddress: string): Promise<any>;
|
|
143
|
+
triggerEmailVerification(emailAddress: string, deviceId: string): Promise<any>;
|
|
144
144
|
/**
|
|
145
145
|
* Verifies an email verification code for a user.
|
|
146
146
|
*
|
|
@@ -148,6 +148,7 @@ export default class UnsharedLabsClient {
|
|
|
148
148
|
* The code is typically obtained from the user after they receive the verification email.
|
|
149
149
|
*
|
|
150
150
|
* @param {string} emailAddress - Email address for whom the code is being verified.
|
|
151
|
+
* @param {string} deviceId - device id for whom the code is being verified.
|
|
151
152
|
* @param {string} code - Verification code that was sent to the user's email
|
|
152
153
|
*
|
|
153
154
|
* @returns {Promise<any>} Response object from the verification service containing:
|
|
@@ -168,5 +169,5 @@ export default class UnsharedLabsClient {
|
|
|
168
169
|
* }
|
|
169
170
|
* ```
|
|
170
171
|
*/
|
|
171
|
-
verify(emailAddress: string, code: string): Promise<any>;
|
|
172
|
+
verify(emailAddress: string, deviceId: string, code: string): Promise<any>;
|
|
172
173
|
}
|
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).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),
|
|
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),d=(0,util_1.encryptData)(a,this._apiKey),_=(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:_,client_timestamp:n,event_details:(0,util_1.encryptData)(o?JSON.stringify([...o.entries()]):null,this._apiKey)},y=await fetch(`${this._apiBaseUrl}/api/v1/submitEvent`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify(p)});if(!y.ok){const t=await y.json().catch(()=>({error:y.statusText}));throw new Error(`API returned error: ${JSON.stringify(t)}`)}const u=await y.json();return{status:y.status,statusText:y.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),d=(0,util_1.encryptData)(a,this._apiKey),_=(0,util_1.encryptData)(s,this._apiKey),p=(0,util_1.encryptData)(n,this._apiKey),y={user_id:c,event_type:t,ip_address:h,device_id:l,session_hash:d,user_agent:_,email_address:p,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(y)});return await u.json()}catch(t){return{success:!1,error:`Failed to process user event: ${t instanceof Error?t.message:JSON.stringify(t)}`}}}async triggerEmailVerification(t,e){try{if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t))throw new Error("Invalid email address provided");const i=await fetch(`${this._emailServiceUrl}/api/send-email`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify({email_address:t,device_id:e})});if(!i.ok){const t=await i.json().catch(()=>({error:i.statusText}));throw new Error(`Email service returned error: ${JSON.stringify(t)}`)}return await i.json()}catch(t){throw new Error(`Failed to trigger email verification: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}async verify(t,e,i){try{const r=await fetch(`${this._emailServiceUrl}/api/verify`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:this._getBasicAuthHeader()},body:JSON.stringify({email_address:t,device_id:e,code:i})});if(!r.ok){const t=await r.json().catch(()=>({error:r.statusText}));throw new Error(`Verification service returned error: ${JSON.stringify(t)}`)}return await r.json()}catch(t){throw new Error(`Failed to verify code: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}}exports.default=UnsharedLabsClient;
|