@bluedot-innovation/javascript-sdk
Advanced tools
Comparing version 1.2.0 to 1.3.0
import { AxiosResponse } from 'axios'; | ||
import { InitializeOptions } from '../types/bluedot'; | ||
declare const _default: { | ||
@@ -7,3 +8,3 @@ /** | ||
*/ | ||
get: (projectId: string) => Promise<AxiosResponse>; | ||
get: (projectId: string, options?: InitializeOptions) => Promise<AxiosResponse>; | ||
}; | ||
@@ -10,0 +11,0 @@ /** |
@@ -77,3 +77,4 @@ 'use strict'; | ||
InterruptedByResetError: 'InterruptedByResetError', | ||
LocationAPINotAvailableError: 'LocationAPINotAvailableError' | ||
LocationAPINotAvailableError: 'LocationAPINotAvailableError', | ||
RetryAttemptFailedError: 'RetryAttemptFailedError' | ||
}; | ||
@@ -128,2 +129,13 @@ var errorFactory = { | ||
throw this.createError(BluedotErrorTypes.LocationAPINotAvailableError, description !== null && description !== void 0 ? description : defaultErrorMessage, error); | ||
}, | ||
createRetryAttemptFailedError: function createRetryAttemptFailedError(retryCount, error) { | ||
var errorMessage = "Retry attempt " + retryCount + " failed"; | ||
var errorObj = this.createError(BluedotErrorTypes.RetryAttemptFailedError, errorMessage, error); | ||
var retryAttemptFailedErrorObject = tslib.__assign(tslib.__assign({}, errorObj), { | ||
name: BluedotErrorTypes.RetryAttemptFailedError, | ||
retryCount: retryCount | ||
}); | ||
return retryAttemptFailedErrorObject; | ||
} | ||
@@ -160,3 +172,4 @@ }; | ||
locationEnabled: false, | ||
userPersistenceEnabled: false | ||
userPersistenceEnabled: false, | ||
userToken: null | ||
}; | ||
@@ -341,3 +354,54 @@ var stateId = 1; | ||
}; | ||
var isValidUserToken = function isValidUserToken(input) { | ||
if (isString(input)) { | ||
var userTokenRegex = new RegExp(/^[0-9A-Fa-z]{7}$/i); | ||
return userTokenRegex.test(input); | ||
} | ||
return false; | ||
}; | ||
var validateUserToken = function validateUserToken(input) { | ||
if (!isValidUserToken(input)) { | ||
errorFactory.throwValidationError('userToken must be a 7-alphanumeric-character string'); | ||
} | ||
}; | ||
var validateWaveOptions = function validateWaveOptions(input) { | ||
if (input !== null && input !== undefined) { | ||
if (typeof input !== 'object') { | ||
errorFactory.throwValidationError('WaveOptions is not an object'); | ||
} | ||
var allowedFields_1 = ['retryCallback']; | ||
var invalidFields_1 = []; | ||
Object.keys(input).forEach(function (key) { | ||
if (!allowedFields_1.includes(key)) { | ||
invalidFields_1.push(key); | ||
} | ||
}); | ||
if (invalidFields_1.length > 0) { | ||
errorFactory.throwValidationError("Invalid options parameters [" + invalidFields_1 + "]"); | ||
} | ||
} | ||
}; | ||
var validateInitializeOptions = function validateInitializeOptions(input) { | ||
if (input !== null && input !== undefined) { | ||
if (typeof input !== 'object') { | ||
errorFactory.throwValidationError('InitializeOptions is not an object'); | ||
} | ||
var allowedFields_2 = ['retryCallback']; | ||
var invalidFields_2 = []; | ||
Object.keys(input).forEach(function (key) { | ||
if (!allowedFields_2.includes(key)) { | ||
invalidFields_2.push(key); | ||
} | ||
}); | ||
if (invalidFields_2.length > 0) { | ||
errorFactory.throwValidationError("Invalid options parameters [" + invalidFields_2 + "]"); | ||
} | ||
} | ||
}; | ||
var privateStore = /*#__PURE__*/createPrivateStore(); | ||
@@ -490,5 +554,2 @@ | ||
err.config.retryCount = 0; | ||
return [2 | ||
/*return*/ | ||
, axios(err.config)]; | ||
} | ||
@@ -501,2 +562,6 @@ | ||
if ((isNetworkError || is500Errors) && err.config.retryCallback) { | ||
err.config.retryCallback(errorFactory.createRetryAttemptFailedError(err.config.retryCount, err)); | ||
} | ||
if (!((isNetworkError || is500Errors) && err.config.retryCount < err.config.retries)) return [3 | ||
@@ -610,3 +675,3 @@ /*break*/ | ||
*/ | ||
get: function get$1(projectId) { | ||
get: function get$1(projectId, options) { | ||
return tslib.__awaiter(void 0, void 0, void 0, function () { | ||
@@ -622,3 +687,4 @@ var err_1, responseError; | ||
, get("" + currentState.globalConfigUrl + projectId + ".json", { | ||
retries: currentState.remoteConfig.oneShot.maxAttempts | ||
retries: currentState.remoteConfig.oneShot.maxAttempts, | ||
retryCallback: options === null || options === void 0 ? void 0 : options.retryCallback | ||
})]; | ||
@@ -704,3 +770,3 @@ | ||
var initializeService = { | ||
initialize: function initialize(projectId) { | ||
initialize: function initialize(projectId, options) { | ||
return tslib.__awaiter(void 0, void 0, void 0, function () { | ||
@@ -716,5 +782,6 @@ var stateId, response, storedInstallRef, err_1; | ||
currentState.initializeStatus = initializeStatusEnum.IN_PROGRESS; | ||
validateInitializeOptions(options); | ||
return [4 | ||
/*yield*/ | ||
, globalConfig.get(projectId)]; | ||
, globalConfig.get(projectId, options)]; | ||
@@ -870,3 +937,4 @@ case 1: | ||
}, | ||
retries: currentState.remoteConfig.oneShot.maxAttempts | ||
retries: currentState.remoteConfig.oneShot.maxAttempts, | ||
retryCallback: triggerOneshotOptions.retryCallback | ||
}; | ||
@@ -879,2 +947,6 @@ body = tslib.__assign({}, triggerOneshotOptions.notification); | ||
if (currentState === null || currentState === void 0 ? void 0 : currentState.userToken) { | ||
body.userToken = currentState.userToken; | ||
} | ||
if (triggerOneshotOptions.location && triggerOneshotOptions.location.longitude && triggerOneshotOptions.location.latitude) { | ||
@@ -927,3 +999,3 @@ body.location = composeWaveLocation(triggerOneshotOptions.location); | ||
function () { | ||
function OneShotInstance(notification, notificationType) { | ||
function OneShotInstance(notification, notificationType, options) { | ||
this.attemptCount = 0; | ||
@@ -934,2 +1006,3 @@ this.bestEffort = null; | ||
this.notificationType = notificationType; | ||
this.options = options; | ||
} | ||
@@ -958,2 +1031,4 @@ | ||
OneShotInstance.prototype.sendEvent = function () { | ||
var _a; | ||
return tslib.__awaiter(this, void 0, void 0, function () { | ||
@@ -964,3 +1039,3 @@ var attemptId; | ||
return tslib.__generator(this, function (_a) { | ||
return tslib.__generator(this, function (_b) { | ||
attemptId = ++this.attemptCount; | ||
@@ -983,3 +1058,4 @@ | ||
notificationType: this.notificationType, | ||
location: this.bestEffort | ||
location: this.bestEffort, | ||
retryCallback: (_a = this.options) === null || _a === void 0 ? void 0 : _a.retryCallback | ||
})]; | ||
@@ -996,3 +1072,5 @@ } | ||
return tslib.__awaiter(_this, void 0, void 0, function () { | ||
return tslib.__generator(this, function (_a) { | ||
var _a; | ||
return tslib.__generator(this, function (_b) { | ||
logger.info("State event emitted " + event); | ||
@@ -1006,3 +1084,4 @@ | ||
notificationType: this.notificationType, | ||
location: this.bestEffort | ||
location: this.bestEffort, | ||
retryCallback: (_a = this.options) === null || _a === void 0 ? void 0 : _a.retryCallback | ||
}).then(resolve)["catch"](reject); | ||
@@ -1158,7 +1237,7 @@ } else if (currentState.initializeStatus === initializeStatusEnum.FAILED) { | ||
OneShotService.prototype.triggerOneShot = function (notification, notificationType) { | ||
OneShotService.prototype.triggerOneShot = function (notification, notificationType, options) { | ||
return tslib.__awaiter(this, void 0, void 0, function () { | ||
var instance; | ||
return tslib.__generator(this, function (_a) { | ||
instance = new OneShotInstance(notification, notificationType); | ||
instance = new OneShotInstance(notification, notificationType, options); | ||
return [2 | ||
@@ -1178,3 +1257,3 @@ /*return*/ | ||
var wave = { | ||
send: function send(destinationId, customEventMetaData) { | ||
send: function send(destinationId, customEventMetaData, options) { | ||
return tslib.__awaiter(void 0, void 0, void 0, function () { | ||
@@ -1188,2 +1267,3 @@ var waveNotification, helloModel, err_1, errorObject, regExp; | ||
validateIsString(destinationId, 'destinationId'); | ||
validateWaveOptions(options); | ||
waveNotification = { | ||
@@ -1203,3 +1283,3 @@ destinationId: destinationId, | ||
/*yield*/ | ||
, OneShotService$1.triggerOneShot(waveNotification, WAVE_TYPE)]; | ||
, OneShotService$1.triggerOneShot(waveNotification, WAVE_TYPE, options)]; | ||
@@ -1291,2 +1371,12 @@ case 1: | ||
var credentials = { | ||
setUserToken: function setUserToken(userToken) { | ||
validateUserToken(userToken); | ||
currentState.userToken = userToken; | ||
}, | ||
clearUserToken: function clearUserToken() { | ||
delete currentState.userToken; | ||
} | ||
}; | ||
/** | ||
@@ -1301,3 +1391,4 @@ * This interface is the high-level entry point for integration with the Bluedot Javascript SDK.<br /> | ||
config: config, | ||
initialize: function initialize(projectId) { | ||
credentials: credentials, | ||
initialize: function initialize(projectId, options) { | ||
return tslib.__awaiter(void 0, void 0, void 0, function () { | ||
@@ -1309,3 +1400,3 @@ return tslib.__generator(this, function (_a) { | ||
/*return*/ | ||
, initializeService.initialize(projectId)]; | ||
, initializeService.initialize(projectId, options)]; | ||
}); | ||
@@ -1312,0 +1403,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
"use strict";var t,e=require("tslib"),r=require("events"),o=require("uuid"),n=(t=require("axios"))&&"object"==typeof t&&"default"in t?t.default:t,i=function(){var t=new WeakMap;return function(e){return t.has(e)||t.set(e,{}),t.get(e)}},a=!1;function s(t,e,r){a&&(e&&r?t(e,r):t(e||r||new Error("Error logger called. See stack trace for details")))}var c=function(t,e){return s(console.error,t,e)},u=function(t,e){return s(console.warn,t,e)},l=function(t,e){return s(console.log,t,e)},d={ValidationError:"ValidationError",NetworkRetriesExceededError:"NetworkRetriesExceededError",UnexpectedServerError:"UnexpectedServerError",InvalidInputTypeError:"InvalidInputTypeError",RequiredValueMissingError:"RequiredValueMissingError",SdkNotInitializedError:"SdkNotInitializedError",ProjectIdNotFoundError:"ProjectIdNotFoundError",NotFoundError:"NotFoundError",InterruptedByResetError:"InterruptedByResetError",LocationAPINotAvailableError:"LocationAPINotAvailableError"},f={createError:function(t,e,r){var o=new Error(e);o.name=t;var n=o;return n.errorObject=r,u(e,n),n},throwInvalidInputTypeError:function(t,e){throw this.createError(d.InvalidInputTypeError,null!=t?t:"Invalid input type error",e)},throwNetworkRetriesExceededError:function(t,e){throw this.createError(d.NetworkRetriesExceededError,t?"Failed to communicate via network after "+t+" attempts":"Failed to communicate via network",e)},throwProjectIdNotFoundError:function(t,e){throw this.createError(d.ProjectIdNotFoundError,t?"Project with ID: "+t+" not found":"Project ID not found",e)},throwRequiredValueMissingError:function(t,e){throw this.createError(d.RequiredValueMissingError,t?"Cannot trigger event. Missing required value: "+t:"Cannot trigger event. Missing required value",e)},throwSdkNotInitializedError:function(t,e){throw this.createError(d.SdkNotInitializedError,null!=t?t:"SDK is not initialized with a valid projectId",e)},throwUnexpectedServerError:function(t,e){throw this.createError(d.UnexpectedServerError,null!=t?t:"An unexpected server error occurred. Check the attached errorObject for more details",e)},throwValidationError:function(t,e){throw this.createError(d.ValidationError,null!=t?t:"Invalid input was detected",e)},throwNotFoundError:function(t,e){throw this.createError(d.NotFoundError,null!=t?t:"Not found",e)},throwInterruptedByResetError:function(t,e){throw this.createError(d.InterruptedByResetError,null!=t?t:"Interrupted by reset",e)},throwLocationAPINotAvailableError:function(t,e){throw this.createError(d.LocationAPINotAvailableError,null!=t?t:"Location API is not available",e)}},h=new r.EventEmitter,g={remoteConfig:e.__assign({},{oneShot:{minAccuracy:50,targetAccuracy:20,maxAttempts:15,timeout:5e3}}),globalConfigUrl:"https://globalconfig.bluedot.io/",globalConfig:null,isInitialized:!1,initializeStatus:"notStarted",projectId:null,reset:m,addListener:w,removeListener:E,id:0,locationEnabled:!1,userPersistenceEnabled:!1},v=1,p=new Proxy(e.__assign({},g),{get:function(t,e){return t[e]},set:function(t,e,r){return t[e]=r,h.emit("stateUpdated",e),!0}});function m(){return Object.assign(p,g),p.reset=m,p.addListener=w,p.removeListener=E,p.id=v++,h.emit("stateReset"),h.removeAllListeners(),p}function w(t){return l("Adding state listener"),h.on("stateUpdated",t)}function E(t){h.removeListener("stateUpdated",t)}m();var b=function(t){return"string"==typeof t},y=function(t){return"number"==typeof t&&t>0},_=function(t,e){b(t)||f.throwInvalidInputTypeError(e+" must be a string")},I=function(t,e){_(t,"fieldName"),_(e,"fieldValue"),function(t){var e=["customername","orderid","eventtype","mobilenumber"],r=t.replace(/\s+/g,"");return t.toLowerCase().startsWith("hs_")?e.includes(r.slice(3).toLowerCase()):e.includes(r.toLowerCase())}(t)&&f.throwValidationError(t+" is a reserved keyword for Hello Screens. Use the helloModel method instead to set this value")},S=function(t,e){(function(t){return"boolean"==typeof t})(t)||f.throwInvalidInputTypeError(e+" must be a boolean")},C=i();function N(t){return _(t,"orderId"),C(this).orderId=t,this}function R(t){var e=function(t){var e;"string"==typeof t?e=t:"number"==typeof t&&(e=t.toString()),e||f.throwInvalidInputTypeError("mobileNumber must be a string");var r,o,n=e.replace(/ /g,"").replace(/-/g,"");return r=n,o=new RegExp(/^\+?[0-9]+$/),"string"==typeof r&&o.test(r)||f.throwValidationError("Invalid mobileNumber found. mobileNumber can only contain numerals or a leading + character"),n}(t);return C(this).mobileNumber=e,this}function L(t){return function(t){return!!b(t)&&["arrival","onTheWay"].includes(t)}(t)||f.throwValidationError("Invalid eventType found. eventType can only be 'arrival' or 'onTheWay'"),C(this).eventType=t,this}function A(t){return _(t,"customerName"),C(this).customerName=t,this}function U(t,e){I(t,e),function(t){t.toLowerCase().startsWith("hs_")&&f.throwValidationError("The hs_ prefix is reserved for fields that are displayed in Hello Screens. Use the setDisplayedCustomDataField method to set these values")}(t);var r=C(this).customFields;return void 0===r&&(r={},C(this).customFields=r),r[t]=e,this}function j(t,e){I(t,e);var r=C(this).displayedCustomFields;void 0===r&&(r={},C(this).displayedCustomFields=r);var o=r;return t.toLowerCase().startsWith("hs_")?o["hs_"+t.slice(3)]=e:o["hs_"+t]=e,this}function T(){var t=C(this),r=t.eventType,o=t.mobileNumber,n=t.customerName,i=t.orderId,a=t.customFields,s=t.displayedCustomFields;i||f.throwRequiredValueMissingError("orderId");var c=s,u=e.__assign(e.__assign({},a),c);return r&&(u.hs_eventType=r),i&&(u.hs_orderId=i),n&&(u.hs_customerName=n),o&&(u["hs_Mobile Number"]=o),u}n.interceptors.response.use(void 0,(function(t){return e.__awaiter(void 0,void 0,void 0,(function(){var r,o;return e.__generator(this,(function(e){switch(e.label){case 0:if(!t.config.retries)throw t;if(o=t.response&&t.response.status>499&&t.response.status<600,((r="ENOTFOUND"===t.code||"Network Error"===t.message)||o)&&!t.config.isRetryRequest)return t.config.isRetryRequest=!0,t.config.retryCount=0,[2,n(t.config)];if(void 0===t.config.retryCount)throw t;return(r||o)&&t.config.retryCount<t.config.retries?(l("Retry count: "+t.config.retryCount),[4,(i=Math.floor(100*Math.pow(t.config.retryCount,2))+Math.floor(100*Math.random()),new Promise((function(t){return setTimeout(t,i)})))]):[3,2];case 1:return e.sent(),t.config.retryCount+=1,[2,n(t.config)];case 2:throw t}var i}))}))}));var P=function(t,r,o){return e.__awaiter(void 0,void 0,void 0,(function(){var i;return e.__generator(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,n.post(t,r,o)];case 1:return[2,e.sent()];case 2:if((i=e.sent()).config.retryCount&&i.config.retryCount>=i.config.retries)throw f.throwNetworkRetriesExceededError(i.config.retryCount,i);if(i.response&&400===i.response.status)throw f.throwValidationError("Bad request",i);throw f.throwUnexpectedServerError(void 0,i);case 3:return[2]}}))}))},x=function(t){return e.__awaiter(void 0,void 0,void 0,(function(){var r,o;return e.__generator(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,(a=""+p.globalConfigUrl+t+".json",s={retries:p.remoteConfig.oneShot.maxAttempts},e.__awaiter(void 0,void 0,void 0,(function(){var t;return e.__generator(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,n.get(a,s)];case 1:return[2,e.sent()];case 2:if((t=e.sent()).config.retryCount&&t.config.retryCount>=t.config.retries)throw f.throwNetworkRetriesExceededError(t.config.retryCount,t);throw f.throwUnexpectedServerError(void 0,t);case 3:return[2]}}))})))];case 1:return[2,i.sent()];case 2:if((r=i.sent()).name&&"UnexpectedServerError"===r.name&&(o=r.errorObject).response&&(404===o.response.status||403===o.response.status))throw f.throwProjectIdNotFoundError(void 0,r);throw r;case 3:return[2]}var a,s}))}))},F=function(){return!!global.localStorage},z=function(t,e){if(F()){var r=global.localStorage.getItem("installRefs"),o={};r&&(o=JSON.parse(r)),o[t]=e,global.localStorage.setItem("installRefs",JSON.stringify(o)),l("Storing installRef: "+e+" for projectId: "+t)}else u("localStorage object not found")},k=function(t){return e.__awaiter(void 0,void 0,void 0,(function(){var r,n,i,a;return e.__generator(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),r=p.id,p.projectId=t,p.initializeStatus="inProgress",[4,x(t)];case 1:if(n=e.sent(),r!==p.id)throw f.throwInterruptedByResetError();return p.isInitialized=!0,p.initializeStatus="completed",F()&&((i=function(t){if(!F())return u("localStorage object not found"),null;var e=global.localStorage.getItem("installRefs");return e?JSON.parse(e)[t]:null}(t))?(p.installRef=i,l("Using stored installRef: "+i)):(p.installRef=o.v4(),p.userPersistenceEnabled&&z(t,p.installRef))),p.globalConfig=n.data,[3,3];case 2:throw a=e.sent(),p.initializeStatus="failed",c("An error occurred during initialization",a),a;case 3:return[2]}}))}))},O=new(function(){function t(){var t=this;this.emitter=new r.EventEmitter,this.emitter.on("locationError",(function(t){c("Failed to get positon",t)})),this.emitter.on("removeListener",(function(e){"locationUpdate"===e&&0===t.emitter.listenerCount("locationUpdate")&&null!=t.handlerId&&(l("Remove locationUpdate"),navigator.geolocation.clearWatch(t.handlerId))}))}return t.prototype.getUpdatedPosition=function(t){var e=this;"locationUpdate"===t&&(this.handlerId=navigator.geolocation.watchPosition((function(t){l("Emitting",t),e.emitter.emit("locationUpdate",t)}),(function(t){e.emitter.emit("locationError",t),e.emitter.emit("locationUpdate")}),{enableHighAccuracy:!0,maximumAge:5e3}))},t.prototype.addListener=function(t){l("Adding locationUpdate listener."),this.emitter.on("locationUpdate",t),this.getUpdatedPosition("locationUpdate")},t.prototype.removeListener=function(t){this.emitter.removeListener("locationUpdate",t)},t}()),D=function(t){return e.__awaiter(void 0,void 0,void 0,(function(){var r,o,n,i;return e.__generator(this,(function(a){switch(a.label){case 0:return r=function(){if(p.globalConfig){var t=p.globalConfig.eventsApiUrl;if(t)return t;throw new Error("Project does not have Events Api Url")}throw f.throwSdkNotInitializedError()}(),o={headers:{"x-bluedot-api-key":p.projectId},retries:p.remoteConfig.oneShot.maxAttempts},n=e.__assign({},t.notification),p&&p.installRef&&(n.installRef=p.installRef),t.location&&t.location.longitude&&t.location.latitude&&(n.location=(c={longitude:(s=t.location).longitude,latitude:s.latitude,horizontalAccuracy:s.accuracy},s.speed&&(c.speed=s.speed),s.heading&&(c.bearing=s.heading),c)),[4,P(r+"wave",n,o)];case 1:return i=a.sent(),l("Event sent"),[2,i]}var s,c}))}))},V=function(t){return e.__awaiter(void 0,void 0,void 0,(function(){return e.__generator(this,(function(e){return t.notificationType&&"wave"===t.notificationType?[2,D(t)]:[2]}))}))},M=function(){function t(t,r){this.attemptCount=0,this.bestEffort=null,this.isClosed=!1,this.notification=e.__assign({},t),this.notificationType=r}return t.prototype.trigger=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){return"failed"!==p.initializeStatus&&"notStarted"!==p.initializeStatus||f.throwSdkNotInitializedError(),p.locationEnabled?[2,this.trackAndSendLocation()]:[2,this.sendEvent()]}))}))},t.prototype.sendEvent=function(){return e.__awaiter(this,void 0,void 0,(function(){var t=this;return e.__generator(this,(function(r){return++this.attemptCount>1?(l("Previous event is in progress. Ignoring retrigger"),[2,null]):p.globalConfig?(l("Target region identified"),l("Sending event"),[2,V({notification:this.notification,notificationType:this.notificationType,location:this.bestEffort})]):[2,new Promise((function(r,o){l("Target region identification in progress. Listening..."),p.addListener((function n(i){return e.__awaiter(t,void 0,void 0,(function(){return e.__generator(this,(function(t){return l("State event emitted "+i),p.globalConfig?(l("Target region found. Sending event"),p.removeListener(n),V({notification:this.notification,notificationType:this.notificationType,location:this.bestEffort}).then(r).catch(o)):"failed"===p.initializeStatus?(p.removeListener(n),o(f.createError(d.SdkNotInitializedError,"SDK failed to initialize"))):l("No target region found."),[2]}))}))}))}))]}))}))},t.prototype.attemptSendEvent=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.sendEvent()];case 1:return t.sent(),this.closeLocationPolling(),[2]}}))}))},t.prototype.closeLocationPolling=function(){!this.isClosed&&this.listener&&O.removeListener(this.listener),this.isClosed=!0},t.prototype.trackAndSendLocation=function(){return e.__awaiter(this,void 0,void 0,(function(){var t=this;return e.__generator(this,(function(r){return[2,new Promise((function(r){l("OneShotService: Adding location listener"),t.listener=function(o){return e.__awaiter(t,void 0,void 0,(function(){var t,n=this;return e.__generator(this,(function(e){return l("OneShotService: Received position",o),o&&o.coords&&o.coords.accuracy?null==this.bestEffort||this.bestEffort.accuracy&&this.bestEffort.accuracy<o.coords.accuracy?(o.coords.accuracy<p.remoteConfig.oneShot.minAccuracy&&(this.bestEffort=o.coords),p.isInitialized&&o.coords.accuracy<p.remoteConfig.oneShot.minAccuracy?r(this.attemptSendEvent()):(t=function(e){"isInitialized"===e&&(o.coords.accuracy&&o.coords.accuracy<p.remoteConfig.oneShot.minAccuracy&&r(n.attemptSendEvent()),p.removeListener(t))},p.addListener(t))):l("Lower accuracy than best effort, ignored."):r(this.attemptSendEvent()),[2]}))}))},O.addListener(t.listener),setTimeout((function(){return e.__awaiter(t,void 0,void 0,(function(){var t;return e.__generator(this,(function(e){switch(e.label){case 0:return this.isClosed?[3,2]:(l("Send event on location timeout"),this.closeLocationPolling(),t=r,[4,this.sendEvent()]);case 1:t.apply(void 0,[e.sent()]),e.label=2;case 2:return[2]}}))}))}),p.remoteConfig.oneShot.timeout)}))]}))}))},t}(),q=new(function(){function t(){}return t.prototype.triggerOneShot=function(t,r){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){return[2,new M(t,r).trigger()]}))}))},t}());exports.bluedot={wave:{send:function(t,r){return e.__awaiter(void 0,void 0,void 0,(function(){var o,n,i,a;return e.__generator(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),_(t,"destinationId"),(o={destinationId:t,eventTime:new Date(Date.now()).toISOString()}).customEventMetaData=r&&Object.prototype.hasOwnProperty.call(r,"convertToDataObject")?r.convertToDataObject():r,[4,q.triggerOneShot(o,"wave")];case 1:return e.sent(),[3,3];case 2:if(n=e.sent(),!Object.values(d).includes(n.name))throw f.throwUnexpectedServerError(void 0,n);if(n.errorObject&&(i=n.errorObject).response&&404===i.response.status&&(a=new RegExp(/destinationId/i),i.response&&i.response.data&&i.response.data.errorCauses&&i.response.data.errorCauses.length&&i.response.data.errorCauses[0].message.match(a)))throw f.throwNotFoundError("Zone with destinationId: "+t+" not found",n);throw n;case 3:return[2]}}))}))}},config:{setConfigurationDomain:function(t){t?(function(t){if(b(t))try{var e=new URL(t);return Boolean(e)}catch(t){c(t)}return!1}(t)||f.throwValidationError("BDGlobalConfigUrl must be a valid URL"),p.globalConfigUrl=t):p.globalConfigUrl="https://globalconfig.bluedot.io/"},setUserPersistenceEnabled:function(t){S(t,"enabled"),F()?(p.userPersistenceEnabled=t,t?p.projectId&&p.installRef&&z(p.projectId,p.installRef):(F()?global.localStorage.removeItem("installRefs"):u("localStorage object not found"),delete p.installRef)):u("User persistence is not available in this environment")},setDebugModeEnabled:function(t){S(t,"enabled"),function(t){a=t}(t)},setLocationMinimumAccuracy:function(t){y(t)||f.throwValidationError("Location accuracy must be a positive number"),p.remoteConfig.oneShot.minAccuracy=t},setLocationTimeout:function(t){(function(t){return Number.isInteger(t)&&y(t)})(t)||f.throwValidationError("Location timeout must be a positive integer number"),p.remoteConfig.oneShot.timeout=t}},initialize:function(t){return e.__awaiter(void 0,void 0,void 0,(function(){return e.__generator(this,(function(e){return function(t){return!!b(t)&&new RegExp(/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i).test(t)}(t)||f.throwValidationError("projectId must be a valid uuid"),"notStarted"!==p.initializeStatus&&f.throwValidationError("Bluedot SDK is already initialized with projectId: "+p.projectId+". You need to call reset before initializing again"),[2,k(t)]}))}))},reset:function(){p.reset()},setLocationEnabled:function(t){S(t,"locationEnabled"),p.locationEnabled=t,!0===t&&("undefined"==typeof navigator&&f.throwLocationAPINotAvailableError(),navigator.geolocation.getCurrentPosition((function(t){return l("Current location",t)})))}},exports.createHelloModel=function(){return{setCustomerName:A,setCustomDataField:U,setEventType:L,setMobileNumber:R,setOrderId:N,convertToDataObject:T,setDisplayedCustomDataField:j}}; | ||
"use strict";var t,e=require("tslib"),r=require("events"),o=require("uuid"),n=(t=require("axios"))&&"object"==typeof t&&"default"in t?t.default:t,i=function(){var t=new WeakMap;return function(e){return t.has(e)||t.set(e,{}),t.get(e)}},a=!1;function s(t,e,r){a&&(e&&r?t(e,r):t(e||r||new Error("Error logger called. See stack trace for details")))}var c=function(t,e){return s(console.error,t,e)},u=function(t,e){return s(console.warn,t,e)},l=function(t,e){return s(console.log,t,e)},d={ValidationError:"ValidationError",NetworkRetriesExceededError:"NetworkRetriesExceededError",UnexpectedServerError:"UnexpectedServerError",InvalidInputTypeError:"InvalidInputTypeError",RequiredValueMissingError:"RequiredValueMissingError",SdkNotInitializedError:"SdkNotInitializedError",ProjectIdNotFoundError:"ProjectIdNotFoundError",NotFoundError:"NotFoundError",InterruptedByResetError:"InterruptedByResetError",LocationAPINotAvailableError:"LocationAPINotAvailableError",RetryAttemptFailedError:"RetryAttemptFailedError"},f={createError:function(t,e,r){var o=new Error(e);o.name=t;var n=o;return n.errorObject=r,u(e,n),n},throwInvalidInputTypeError:function(t,e){throw this.createError(d.InvalidInputTypeError,null!=t?t:"Invalid input type error",e)},throwNetworkRetriesExceededError:function(t,e){throw this.createError(d.NetworkRetriesExceededError,t?"Failed to communicate via network after "+t+" attempts":"Failed to communicate via network",e)},throwProjectIdNotFoundError:function(t,e){throw this.createError(d.ProjectIdNotFoundError,t?"Project with ID: "+t+" not found":"Project ID not found",e)},throwRequiredValueMissingError:function(t,e){throw this.createError(d.RequiredValueMissingError,t?"Cannot trigger event. Missing required value: "+t:"Cannot trigger event. Missing required value",e)},throwSdkNotInitializedError:function(t,e){throw this.createError(d.SdkNotInitializedError,null!=t?t:"SDK is not initialized with a valid projectId",e)},throwUnexpectedServerError:function(t,e){throw this.createError(d.UnexpectedServerError,null!=t?t:"An unexpected server error occurred. Check the attached errorObject for more details",e)},throwValidationError:function(t,e){throw this.createError(d.ValidationError,null!=t?t:"Invalid input was detected",e)},throwNotFoundError:function(t,e){throw this.createError(d.NotFoundError,null!=t?t:"Not found",e)},throwInterruptedByResetError:function(t,e){throw this.createError(d.InterruptedByResetError,null!=t?t:"Interrupted by reset",e)},throwLocationAPINotAvailableError:function(t,e){throw this.createError(d.LocationAPINotAvailableError,null!=t?t:"Location API is not available",e)},createRetryAttemptFailedError:function(t,r){var o=this.createError(d.RetryAttemptFailedError,"Retry attempt "+t+" failed",r);return e.__assign(e.__assign({},o),{name:d.RetryAttemptFailedError,retryCount:t})}},h=new r.EventEmitter,v={remoteConfig:e.__assign({},{oneShot:{minAccuracy:50,targetAccuracy:20,maxAttempts:15,timeout:5e3}}),globalConfigUrl:"https://globalconfig.bluedot.io/",globalConfig:null,isInitialized:!1,initializeStatus:"notStarted",projectId:null,reset:m,addListener:E,removeListener:w,id:0,locationEnabled:!1,userPersistenceEnabled:!1,userToken:null},g=1,p=new Proxy(e.__assign({},v),{get:function(t,e){return t[e]},set:function(t,e,r){return t[e]=r,h.emit("stateUpdated",e),!0}});function m(){return Object.assign(p,v),p.reset=m,p.addListener=E,p.removeListener=w,p.id=g++,h.emit("stateReset"),h.removeAllListeners(),p}function E(t){return l("Adding state listener"),h.on("stateUpdated",t)}function w(t){h.removeListener("stateUpdated",t)}m();var b=function(t){return"string"==typeof t},y=function(t){return"number"==typeof t&&t>0},_=function(t,e){b(t)||f.throwInvalidInputTypeError(e+" must be a string")},I=function(t,e){_(t,"fieldName"),_(e,"fieldValue"),function(t){var e=["customername","orderid","eventtype","mobilenumber"],r=t.replace(/\s+/g,"");return t.toLowerCase().startsWith("hs_")?e.includes(r.slice(3).toLowerCase()):e.includes(r.toLowerCase())}(t)&&f.throwValidationError(t+" is a reserved keyword for Hello Screens. Use the helloModel method instead to set this value")},C=function(t,e){(function(t){return"boolean"==typeof t})(t)||f.throwInvalidInputTypeError(e+" must be a boolean")},S=i();function R(t){return _(t,"orderId"),S(this).orderId=t,this}function N(t){var e=function(t){var e;"string"==typeof t?e=t:"number"==typeof t&&(e=t.toString()),e||f.throwInvalidInputTypeError("mobileNumber must be a string");var r,o,n=e.replace(/ /g,"").replace(/-/g,"");return r=n,o=new RegExp(/^\+?[0-9]+$/),"string"==typeof r&&o.test(r)||f.throwValidationError("Invalid mobileNumber found. mobileNumber can only contain numerals or a leading + character"),n}(t);return S(this).mobileNumber=e,this}function A(t){return function(t){return!!b(t)&&["arrival","onTheWay"].includes(t)}(t)||f.throwValidationError("Invalid eventType found. eventType can only be 'arrival' or 'onTheWay'"),S(this).eventType=t,this}function k(t){return _(t,"customerName"),S(this).customerName=t,this}function T(t,e){I(t,e),function(t){t.toLowerCase().startsWith("hs_")&&f.throwValidationError("The hs_ prefix is reserved for fields that are displayed in Hello Screens. Use the setDisplayedCustomDataField method to set these values")}(t);var r=S(this).customFields;return void 0===r&&(r={},S(this).customFields=r),r[t]=e,this}function L(t,e){I(t,e);var r=S(this).displayedCustomFields;void 0===r&&(r={},S(this).displayedCustomFields=r);var o=r;return t.toLowerCase().startsWith("hs_")?o["hs_"+t.slice(3)]=e:o["hs_"+t]=e,this}function j(){var t=S(this),r=t.eventType,o=t.mobileNumber,n=t.customerName,i=t.orderId,a=t.customFields,s=t.displayedCustomFields;i||f.throwRequiredValueMissingError("orderId");var c=s,u=e.__assign(e.__assign({},a),c);return r&&(u.hs_eventType=r),i&&(u.hs_orderId=i),n&&(u.hs_customerName=n),o&&(u["hs_Mobile Number"]=o),u}n.interceptors.response.use(void 0,(function(t){return e.__awaiter(void 0,void 0,void 0,(function(){var r,o;return e.__generator(this,(function(e){switch(e.label){case 0:if(!t.config.retries)throw t;if(o=t.response&&t.response.status>499&&t.response.status<600,!(r="ENOTFOUND"===t.code||"Network Error"===t.message)&&!o||t.config.isRetryRequest||(t.config.isRetryRequest=!0,t.config.retryCount=0),void 0===t.config.retryCount)throw t;return(r||o)&&t.config.retryCallback&&t.config.retryCallback(f.createRetryAttemptFailedError(t.config.retryCount,t)),(r||o)&&t.config.retryCount<t.config.retries?(l("Retry count: "+t.config.retryCount),[4,(i=Math.floor(100*Math.pow(t.config.retryCount,2))+Math.floor(100*Math.random()),new Promise((function(t){return setTimeout(t,i)})))]):[3,2];case 1:return e.sent(),t.config.retryCount+=1,[2,n(t.config)];case 2:throw t}var i}))}))}));var U=function(t,r,o){return e.__awaiter(void 0,void 0,void 0,(function(){var i;return e.__generator(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,n.post(t,r,o)];case 1:return[2,e.sent()];case 2:if((i=e.sent()).config.retryCount&&i.config.retryCount>=i.config.retries)throw f.throwNetworkRetriesExceededError(i.config.retryCount,i);if(i.response&&400===i.response.status)throw f.throwValidationError("Bad request",i);throw f.throwUnexpectedServerError(void 0,i);case 3:return[2]}}))}))},F=function(t,r){return e.__awaiter(void 0,void 0,void 0,(function(){var o;return e.__generator(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,n.get(t,r)];case 1:return[2,e.sent()];case 2:if((o=e.sent()).config.retryCount&&o.config.retryCount>=o.config.retries)throw f.throwNetworkRetriesExceededError(o.config.retryCount,o);throw f.throwUnexpectedServerError(void 0,o);case 3:return[2]}}))}))},P=function(t,r){return e.__awaiter(void 0,void 0,void 0,(function(){var o,n;return e.__generator(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,F(""+p.globalConfigUrl+t+".json",{retries:p.remoteConfig.oneShot.maxAttempts,retryCallback:null==r?void 0:r.retryCallback})];case 1:return[2,e.sent()];case 2:if((o=e.sent()).name&&"UnexpectedServerError"===o.name&&(n=o.errorObject).response&&(404===n.response.status||403===n.response.status))throw f.throwProjectIdNotFoundError(void 0,o);throw o;case 3:return[2]}}))}))},x=function(){return!!global.localStorage},z=function(t,e){if(x()){var r=global.localStorage.getItem("installRefs"),o={};r&&(o=JSON.parse(r)),o[t]=e,global.localStorage.setItem("installRefs",JSON.stringify(o)),l("Storing installRef: "+e+" for projectId: "+t)}else u("localStorage object not found")},O=function(t,r){return e.__awaiter(void 0,void 0,void 0,(function(){var n,i,a,s;return e.__generator(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),n=p.id,p.projectId=t,p.initializeStatus="inProgress",function(t){if(null!=t){"object"!=typeof t&&f.throwValidationError("InitializeOptions is not an object");var e=["retryCallback"],r=[];Object.keys(t).forEach((function(t){e.includes(t)||r.push(t)})),r.length>0&&f.throwValidationError("Invalid options parameters ["+r+"]")}}(r),[4,P(t,r)];case 1:if(i=e.sent(),n!==p.id)throw f.throwInterruptedByResetError();return p.isInitialized=!0,p.initializeStatus="completed",x()&&((a=function(t){if(!x())return u("localStorage object not found"),null;var e=global.localStorage.getItem("installRefs");return e?JSON.parse(e)[t]:null}(t))?(p.installRef=a,l("Using stored installRef: "+a)):(p.installRef=o.v4(),p.userPersistenceEnabled&&z(t,p.installRef))),p.globalConfig=i.data,[3,3];case 2:throw s=e.sent(),p.initializeStatus="failed",c("An error occurred during initialization",s),s;case 3:return[2]}}))}))},V=new(function(){function t(){var t=this;this.emitter=new r.EventEmitter,this.emitter.on("locationError",(function(t){c("Failed to get positon",t)})),this.emitter.on("removeListener",(function(e){"locationUpdate"===e&&0===t.emitter.listenerCount("locationUpdate")&&null!=t.handlerId&&(l("Remove locationUpdate"),navigator.geolocation.clearWatch(t.handlerId))}))}return t.prototype.getUpdatedPosition=function(t){var e=this;"locationUpdate"===t&&(this.handlerId=navigator.geolocation.watchPosition((function(t){l("Emitting",t),e.emitter.emit("locationUpdate",t)}),(function(t){e.emitter.emit("locationError",t),e.emitter.emit("locationUpdate")}),{enableHighAccuracy:!0,maximumAge:5e3}))},t.prototype.addListener=function(t){l("Adding locationUpdate listener."),this.emitter.on("locationUpdate",t),this.getUpdatedPosition("locationUpdate")},t.prototype.removeListener=function(t){this.emitter.removeListener("locationUpdate",t)},t}()),D=function(t){return e.__awaiter(void 0,void 0,void 0,(function(){var r,o,n,i;return e.__generator(this,(function(a){switch(a.label){case 0:return r=function(){if(p.globalConfig){var t=p.globalConfig.eventsApiUrl;if(t)return t;throw new Error("Project does not have Events Api Url")}throw f.throwSdkNotInitializedError()}(),o={headers:{"x-bluedot-api-key":p.projectId},retries:p.remoteConfig.oneShot.maxAttempts,retryCallback:t.retryCallback},n=e.__assign({},t.notification),p&&p.installRef&&(n.installRef=p.installRef),(null==p?void 0:p.userToken)&&(n.userToken=p.userToken),t.location&&t.location.longitude&&t.location.latitude&&(n.location=(c={longitude:(s=t.location).longitude,latitude:s.latitude,horizontalAccuracy:s.accuracy},s.speed&&(c.speed=s.speed),s.heading&&(c.bearing=s.heading),c)),[4,U(r+"wave",n,o)];case 1:return i=a.sent(),l("Event sent"),[2,i]}var s,c}))}))},M=function(t){return e.__awaiter(void 0,void 0,void 0,(function(){return e.__generator(this,(function(e){return t.notificationType&&"wave"===t.notificationType?[2,D(t)]:[2]}))}))},q=function(){function t(t,r,o){this.attemptCount=0,this.bestEffort=null,this.isClosed=!1,this.notification=e.__assign({},t),this.notificationType=r,this.options=o}return t.prototype.trigger=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){return"failed"!==p.initializeStatus&&"notStarted"!==p.initializeStatus||f.throwSdkNotInitializedError(),p.locationEnabled?[2,this.trackAndSendLocation()]:[2,this.sendEvent()]}))}))},t.prototype.sendEvent=function(){var t;return e.__awaiter(this,void 0,void 0,(function(){var r=this;return e.__generator(this,(function(o){return++this.attemptCount>1?(l("Previous event is in progress. Ignoring retrigger"),[2,null]):p.globalConfig?(l("Target region identified"),l("Sending event"),[2,M({notification:this.notification,notificationType:this.notificationType,location:this.bestEffort,retryCallback:null===(t=this.options)||void 0===t?void 0:t.retryCallback})]):[2,new Promise((function(t,o){l("Target region identification in progress. Listening..."),p.addListener((function n(i){return e.__awaiter(r,void 0,void 0,(function(){var r;return e.__generator(this,(function(e){return l("State event emitted "+i),p.globalConfig?(l("Target region found. Sending event"),p.removeListener(n),M({notification:this.notification,notificationType:this.notificationType,location:this.bestEffort,retryCallback:null===(r=this.options)||void 0===r?void 0:r.retryCallback}).then(t).catch(o)):"failed"===p.initializeStatus?(p.removeListener(n),o(f.createError(d.SdkNotInitializedError,"SDK failed to initialize"))):l("No target region found."),[2]}))}))}))}))]}))}))},t.prototype.attemptSendEvent=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.sendEvent()];case 1:return t.sent(),this.closeLocationPolling(),[2]}}))}))},t.prototype.closeLocationPolling=function(){!this.isClosed&&this.listener&&V.removeListener(this.listener),this.isClosed=!0},t.prototype.trackAndSendLocation=function(){return e.__awaiter(this,void 0,void 0,(function(){var t=this;return e.__generator(this,(function(r){return[2,new Promise((function(r){l("OneShotService: Adding location listener"),t.listener=function(o){return e.__awaiter(t,void 0,void 0,(function(){var t,n=this;return e.__generator(this,(function(e){return l("OneShotService: Received position",o),o&&o.coords&&o.coords.accuracy?null==this.bestEffort||this.bestEffort.accuracy&&this.bestEffort.accuracy<o.coords.accuracy?(o.coords.accuracy<p.remoteConfig.oneShot.minAccuracy&&(this.bestEffort=o.coords),p.isInitialized&&o.coords.accuracy<p.remoteConfig.oneShot.minAccuracy?r(this.attemptSendEvent()):(t=function(e){"isInitialized"===e&&(o.coords.accuracy&&o.coords.accuracy<p.remoteConfig.oneShot.minAccuracy&&r(n.attemptSendEvent()),p.removeListener(t))},p.addListener(t))):l("Lower accuracy than best effort, ignored."):r(this.attemptSendEvent()),[2]}))}))},V.addListener(t.listener),setTimeout((function(){return e.__awaiter(t,void 0,void 0,(function(){var t;return e.__generator(this,(function(e){switch(e.label){case 0:return this.isClosed?[3,2]:(l("Send event on location timeout"),this.closeLocationPolling(),t=r,[4,this.sendEvent()]);case 1:t.apply(void 0,[e.sent()]),e.label=2;case 2:return[2]}}))}))}),p.remoteConfig.oneShot.timeout)}))]}))}))},t}(),B=new(function(){function t(){}return t.prototype.triggerOneShot=function(t,r,o){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){return[2,new q(t,r,o).trigger()]}))}))},t}());exports.bluedot={wave:{send:function(t,r,o){return e.__awaiter(void 0,void 0,void 0,(function(){var n,i,a,s;return e.__generator(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),_(t,"destinationId"),function(t){if(null!=t){"object"!=typeof t&&f.throwValidationError("WaveOptions is not an object");var e=["retryCallback"],r=[];Object.keys(t).forEach((function(t){e.includes(t)||r.push(t)})),r.length>0&&f.throwValidationError("Invalid options parameters ["+r+"]")}}(o),(n={destinationId:t,eventTime:new Date(Date.now()).toISOString()}).customEventMetaData=r&&Object.prototype.hasOwnProperty.call(r,"convertToDataObject")?r.convertToDataObject():r,[4,B.triggerOneShot(n,"wave",o)];case 1:return e.sent(),[3,3];case 2:if(i=e.sent(),!Object.values(d).includes(i.name))throw f.throwUnexpectedServerError(void 0,i);if(i.errorObject&&(a=i.errorObject).response&&404===a.response.status&&(s=new RegExp(/destinationId/i),a.response&&a.response.data&&a.response.data.errorCauses&&a.response.data.errorCauses.length&&a.response.data.errorCauses[0].message.match(s)))throw f.throwNotFoundError("Zone with destinationId: "+t+" not found",i);throw i;case 3:return[2]}}))}))}},config:{setConfigurationDomain:function(t){t?(function(t){if(b(t))try{var e=new URL(t);return Boolean(e)}catch(t){c(t)}return!1}(t)||f.throwValidationError("BDGlobalConfigUrl must be a valid URL"),p.globalConfigUrl=t):p.globalConfigUrl="https://globalconfig.bluedot.io/"},setUserPersistenceEnabled:function(t){C(t,"enabled"),x()?(p.userPersistenceEnabled=t,t?p.projectId&&p.installRef&&z(p.projectId,p.installRef):(x()?global.localStorage.removeItem("installRefs"):u("localStorage object not found"),delete p.installRef)):u("User persistence is not available in this environment")},setDebugModeEnabled:function(t){C(t,"enabled"),function(t){a=t}(t)},setLocationMinimumAccuracy:function(t){y(t)||f.throwValidationError("Location accuracy must be a positive number"),p.remoteConfig.oneShot.minAccuracy=t},setLocationTimeout:function(t){(function(t){return Number.isInteger(t)&&y(t)})(t)||f.throwValidationError("Location timeout must be a positive integer number"),p.remoteConfig.oneShot.timeout=t}},credentials:{setUserToken:function(t){(function(t){return!!b(t)&&new RegExp(/^[0-9A-Fa-z]{7}$/i).test(t)})(t)||f.throwValidationError("userToken must be a 7-alphanumeric-character string"),p.userToken=t},clearUserToken:function(){delete p.userToken}},initialize:function(t,r){return e.__awaiter(void 0,void 0,void 0,(function(){return e.__generator(this,(function(e){return function(t){return!!b(t)&&new RegExp(/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i).test(t)}(t)||f.throwValidationError("projectId must be a valid uuid"),"notStarted"!==p.initializeStatus&&f.throwValidationError("Bluedot SDK is already initialized with projectId: "+p.projectId+". You need to call reset before initializing again"),[2,O(t,r)]}))}))},reset:function(){p.reset()},setLocationEnabled:function(t){C(t,"locationEnabled"),p.locationEnabled=t,!0===t&&("undefined"==typeof navigator&&f.throwLocationAPINotAvailableError(),navigator.geolocation.getCurrentPosition((function(t){return l("Current location",t)})))}},exports.createHelloModel=function(){return{setCustomerName:k,setCustomDataField:T,setEventType:A,setMobileNumber:N,setOrderId:R,convertToDataObject:j,setDisplayedCustomDataField:L}}; | ||
//# sourceMappingURL=javascript-sdk.cjs.production.min.js.map |
@@ -73,3 +73,4 @@ import { __assign, __awaiter, __generator } from 'tslib'; | ||
InterruptedByResetError: 'InterruptedByResetError', | ||
LocationAPINotAvailableError: 'LocationAPINotAvailableError' | ||
LocationAPINotAvailableError: 'LocationAPINotAvailableError', | ||
RetryAttemptFailedError: 'RetryAttemptFailedError' | ||
}; | ||
@@ -124,2 +125,13 @@ var errorFactory = { | ||
throw this.createError(BluedotErrorTypes.LocationAPINotAvailableError, description !== null && description !== void 0 ? description : defaultErrorMessage, error); | ||
}, | ||
createRetryAttemptFailedError: function createRetryAttemptFailedError(retryCount, error) { | ||
var errorMessage = "Retry attempt " + retryCount + " failed"; | ||
var errorObj = this.createError(BluedotErrorTypes.RetryAttemptFailedError, errorMessage, error); | ||
var retryAttemptFailedErrorObject = __assign(__assign({}, errorObj), { | ||
name: BluedotErrorTypes.RetryAttemptFailedError, | ||
retryCount: retryCount | ||
}); | ||
return retryAttemptFailedErrorObject; | ||
} | ||
@@ -156,3 +168,4 @@ }; | ||
locationEnabled: false, | ||
userPersistenceEnabled: false | ||
userPersistenceEnabled: false, | ||
userToken: null | ||
}; | ||
@@ -337,3 +350,54 @@ var stateId = 1; | ||
}; | ||
var isValidUserToken = function isValidUserToken(input) { | ||
if (isString(input)) { | ||
var userTokenRegex = new RegExp(/^[0-9A-Fa-z]{7}$/i); | ||
return userTokenRegex.test(input); | ||
} | ||
return false; | ||
}; | ||
var validateUserToken = function validateUserToken(input) { | ||
if (!isValidUserToken(input)) { | ||
errorFactory.throwValidationError('userToken must be a 7-alphanumeric-character string'); | ||
} | ||
}; | ||
var validateWaveOptions = function validateWaveOptions(input) { | ||
if (input !== null && input !== undefined) { | ||
if (typeof input !== 'object') { | ||
errorFactory.throwValidationError('WaveOptions is not an object'); | ||
} | ||
var allowedFields_1 = ['retryCallback']; | ||
var invalidFields_1 = []; | ||
Object.keys(input).forEach(function (key) { | ||
if (!allowedFields_1.includes(key)) { | ||
invalidFields_1.push(key); | ||
} | ||
}); | ||
if (invalidFields_1.length > 0) { | ||
errorFactory.throwValidationError("Invalid options parameters [" + invalidFields_1 + "]"); | ||
} | ||
} | ||
}; | ||
var validateInitializeOptions = function validateInitializeOptions(input) { | ||
if (input !== null && input !== undefined) { | ||
if (typeof input !== 'object') { | ||
errorFactory.throwValidationError('InitializeOptions is not an object'); | ||
} | ||
var allowedFields_2 = ['retryCallback']; | ||
var invalidFields_2 = []; | ||
Object.keys(input).forEach(function (key) { | ||
if (!allowedFields_2.includes(key)) { | ||
invalidFields_2.push(key); | ||
} | ||
}); | ||
if (invalidFields_2.length > 0) { | ||
errorFactory.throwValidationError("Invalid options parameters [" + invalidFields_2 + "]"); | ||
} | ||
} | ||
}; | ||
var privateStore = /*#__PURE__*/createPrivateStore(); | ||
@@ -486,5 +550,2 @@ | ||
err.config.retryCount = 0; | ||
return [2 | ||
/*return*/ | ||
, axios(err.config)]; | ||
} | ||
@@ -497,2 +558,6 @@ | ||
if ((isNetworkError || is500Errors) && err.config.retryCallback) { | ||
err.config.retryCallback(errorFactory.createRetryAttemptFailedError(err.config.retryCount, err)); | ||
} | ||
if (!((isNetworkError || is500Errors) && err.config.retryCount < err.config.retries)) return [3 | ||
@@ -606,3 +671,3 @@ /*break*/ | ||
*/ | ||
get: function get$1(projectId) { | ||
get: function get$1(projectId, options) { | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -618,3 +683,4 @@ var err_1, responseError; | ||
, get("" + currentState.globalConfigUrl + projectId + ".json", { | ||
retries: currentState.remoteConfig.oneShot.maxAttempts | ||
retries: currentState.remoteConfig.oneShot.maxAttempts, | ||
retryCallback: options === null || options === void 0 ? void 0 : options.retryCallback | ||
})]; | ||
@@ -700,3 +766,3 @@ | ||
var initializeService = { | ||
initialize: function initialize(projectId) { | ||
initialize: function initialize(projectId, options) { | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -712,5 +778,6 @@ var stateId, response, storedInstallRef, err_1; | ||
currentState.initializeStatus = initializeStatusEnum.IN_PROGRESS; | ||
validateInitializeOptions(options); | ||
return [4 | ||
/*yield*/ | ||
, globalConfig.get(projectId)]; | ||
, globalConfig.get(projectId, options)]; | ||
@@ -866,3 +933,4 @@ case 1: | ||
}, | ||
retries: currentState.remoteConfig.oneShot.maxAttempts | ||
retries: currentState.remoteConfig.oneShot.maxAttempts, | ||
retryCallback: triggerOneshotOptions.retryCallback | ||
}; | ||
@@ -875,2 +943,6 @@ body = __assign({}, triggerOneshotOptions.notification); | ||
if (currentState === null || currentState === void 0 ? void 0 : currentState.userToken) { | ||
body.userToken = currentState.userToken; | ||
} | ||
if (triggerOneshotOptions.location && triggerOneshotOptions.location.longitude && triggerOneshotOptions.location.latitude) { | ||
@@ -923,3 +995,3 @@ body.location = composeWaveLocation(triggerOneshotOptions.location); | ||
function () { | ||
function OneShotInstance(notification, notificationType) { | ||
function OneShotInstance(notification, notificationType, options) { | ||
this.attemptCount = 0; | ||
@@ -930,2 +1002,3 @@ this.bestEffort = null; | ||
this.notificationType = notificationType; | ||
this.options = options; | ||
} | ||
@@ -954,2 +1027,4 @@ | ||
OneShotInstance.prototype.sendEvent = function () { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -960,3 +1035,3 @@ var attemptId; | ||
return __generator(this, function (_a) { | ||
return __generator(this, function (_b) { | ||
attemptId = ++this.attemptCount; | ||
@@ -979,3 +1054,4 @@ | ||
notificationType: this.notificationType, | ||
location: this.bestEffort | ||
location: this.bestEffort, | ||
retryCallback: (_a = this.options) === null || _a === void 0 ? void 0 : _a.retryCallback | ||
})]; | ||
@@ -992,3 +1068,5 @@ } | ||
return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
var _a; | ||
return __generator(this, function (_b) { | ||
logger.info("State event emitted " + event); | ||
@@ -1002,3 +1080,4 @@ | ||
notificationType: this.notificationType, | ||
location: this.bestEffort | ||
location: this.bestEffort, | ||
retryCallback: (_a = this.options) === null || _a === void 0 ? void 0 : _a.retryCallback | ||
}).then(resolve)["catch"](reject); | ||
@@ -1154,7 +1233,7 @@ } else if (currentState.initializeStatus === initializeStatusEnum.FAILED) { | ||
OneShotService.prototype.triggerOneShot = function (notification, notificationType) { | ||
OneShotService.prototype.triggerOneShot = function (notification, notificationType, options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var instance; | ||
return __generator(this, function (_a) { | ||
instance = new OneShotInstance(notification, notificationType); | ||
instance = new OneShotInstance(notification, notificationType, options); | ||
return [2 | ||
@@ -1174,3 +1253,3 @@ /*return*/ | ||
var wave = { | ||
send: function send(destinationId, customEventMetaData) { | ||
send: function send(destinationId, customEventMetaData, options) { | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -1184,2 +1263,3 @@ var waveNotification, helloModel, err_1, errorObject, regExp; | ||
validateIsString(destinationId, 'destinationId'); | ||
validateWaveOptions(options); | ||
waveNotification = { | ||
@@ -1199,3 +1279,3 @@ destinationId: destinationId, | ||
/*yield*/ | ||
, OneShotService$1.triggerOneShot(waveNotification, WAVE_TYPE)]; | ||
, OneShotService$1.triggerOneShot(waveNotification, WAVE_TYPE, options)]; | ||
@@ -1287,2 +1367,12 @@ case 1: | ||
var credentials = { | ||
setUserToken: function setUserToken(userToken) { | ||
validateUserToken(userToken); | ||
currentState.userToken = userToken; | ||
}, | ||
clearUserToken: function clearUserToken() { | ||
delete currentState.userToken; | ||
} | ||
}; | ||
/** | ||
@@ -1297,3 +1387,4 @@ * This interface is the high-level entry point for integration with the Bluedot Javascript SDK.<br /> | ||
config: config, | ||
initialize: function initialize(projectId) { | ||
credentials: credentials, | ||
initialize: function initialize(projectId, options) { | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -1305,3 +1396,3 @@ return __generator(this, function (_a) { | ||
/*return*/ | ||
, initializeService.initialize(projectId)]; | ||
, initializeService.initialize(projectId, options)]; | ||
}); | ||
@@ -1308,0 +1399,0 @@ }); |
import { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
import { RetryCallback } from '../types/bluedot'; | ||
export interface AxiosWithRetryOptions extends AxiosRequestConfig { | ||
@@ -6,2 +7,3 @@ retries?: number; | ||
retryCount?: number; | ||
retryCallback?: RetryCallback; | ||
} | ||
@@ -8,0 +10,0 @@ export interface AxiosErrorWithRetryOptions extends AxiosError { |
@@ -0,5 +1,6 @@ | ||
import { InitializeOptions } from '../types/bluedot'; | ||
declare const _default: { | ||
initialize: (projectId: string) => Promise<void>; | ||
initialize: (projectId: string, options?: InitializeOptions) => Promise<void>; | ||
reset: () => void; | ||
}; | ||
export default _default; |
@@ -1,6 +0,6 @@ | ||
import { NotificationType, WaveNotification } from '../types/bluedot'; | ||
import { NotificationType, WaveNotification, OneShotOptions } from '../types/bluedot'; | ||
declare class OneShotService { | ||
triggerOneShot(notification: WaveNotification, notificationType: NotificationType): Promise<unknown>; | ||
triggerOneShot(notification: WaveNotification, notificationType: NotificationType, options?: OneShotOptions): Promise<unknown>; | ||
} | ||
declare const _default: OneShotService; | ||
export default _default; |
@@ -27,4 +27,5 @@ /// <reference types="node" /> | ||
userPersistenceEnabled: boolean; | ||
userToken?: string | null; | ||
} | ||
declare const currentState: SdkState; | ||
export default currentState; |
export declare type HelloEventType = 'arrival' | 'onTheWay' | undefined; | ||
export declare type NotificationType = 'wave'; | ||
/** | ||
* Thrown when an input is invalid | ||
*/ | ||
declare type ValidationError = 'ValidationError'; | ||
/** | ||
* Thrown when a network operation fails after being retried. This is likely due to network unavailability. | ||
*/ | ||
declare type NetworkRetriesExceededError = 'NetworkRetriesExceededError'; | ||
/** | ||
* Thrown when an unexpected error occurs on Bluedot servers, for example cloud services being unavailable | ||
*/ | ||
declare type UnexpectedServerError = 'UnexpectedServerError'; | ||
/** | ||
* Thrown when an input argument provided is of the wrong type | ||
*/ | ||
declare type InvalidInputTypeError = 'InvalidInputTypeError'; | ||
/** | ||
* Thrown when a required value is not provided so the operation cannot be completed | ||
*/ | ||
declare type RequiredValueMissingError = 'RequiredValueMissingError'; | ||
/** | ||
* Thrown when the SDK has not been initialized via the initialize call, or there was an error during initialization | ||
*/ | ||
declare type SdkNotInitializedError = 'SdkNotInitializedError'; | ||
/** | ||
* Thrown when the provided projectId cannot be found, likely due to incorrect ID or deleted project | ||
*/ | ||
declare type ProjectIdNotFoundError = 'ProjectIdNotFoundError'; | ||
/** | ||
* Thrown when Bluedot server returns Not found errors | ||
*/ | ||
declare type NotFoundError = 'NotFoundError'; | ||
/** | ||
* Thrown when processes are interrupted by reset | ||
*/ | ||
declare type InterruptedByResetError = 'InterruptedByResetError'; | ||
/** | ||
* Thrown when location api is not available in the current environment | ||
*/ | ||
declare type LocationAPINotAvailableError = 'LocationAPINotAvailableError'; | ||
/** | ||
* Thrown when failed to complete an action | ||
*/ | ||
declare type RetryAttemptFailedError = 'RetryAttemptFailedError'; | ||
/** | ||
* The generic error type that encompasses all custom errors | ||
*/ | ||
export declare type BluedotErrorType = ValidationError | NetworkRetriesExceededError | UnexpectedServerError | InvalidInputTypeError | RequiredValueMissingError | SdkNotInitializedError | ProjectIdNotFoundError | NotFoundError | InterruptedByResetError | LocationAPINotAvailableError | RetryAttemptFailedError; | ||
export interface BluedotErrorTypeEnum { | ||
ValidationError: ValidationError; | ||
NetworkRetriesExceededError: NetworkRetriesExceededError; | ||
UnexpectedServerError: UnexpectedServerError; | ||
InvalidInputTypeError: InvalidInputTypeError; | ||
RequiredValueMissingError: RequiredValueMissingError; | ||
SdkNotInitializedError: SdkNotInitializedError; | ||
ProjectIdNotFoundError: ProjectIdNotFoundError; | ||
NotFoundError: NotFoundError; | ||
InterruptedByResetError: InterruptedByResetError; | ||
LocationAPINotAvailableError: LocationAPINotAvailableError; | ||
RetryAttemptFailedError: RetryAttemptFailedError; | ||
} | ||
export interface BluedotErrorObject extends Error { | ||
name: BluedotErrorType; | ||
errorObject?: Error; | ||
} | ||
export interface RetryAttemptFailedErrorObject extends BluedotErrorObject { | ||
name: RetryAttemptFailedError; | ||
retryCount: number; | ||
} | ||
export interface ErrorFactory { | ||
createError(errorType: BluedotErrorType, description: string, error?: Error): BluedotErrorObject; | ||
throwNetworkRetriesExceededError(retriesAttempted?: number, error?: Error): BluedotErrorObject; | ||
throwValidationError(description?: string, error?: Error): BluedotErrorObject; | ||
throwUnexpectedServerError(description?: string, error?: Error): BluedotErrorObject; | ||
throwInvalidInputTypeError(description?: string, error?: Error): BluedotErrorObject; | ||
throwSdkNotInitializedError(description?: string, error?: Error): BluedotErrorObject; | ||
throwRequiredValueMissingError(missingFieldName?: string, error?: Error): BluedotErrorObject; | ||
throwProjectIdNotFoundError(invalidId?: string, error?: Error): BluedotErrorObject; | ||
throwNotFoundError(description?: string, error?: Error): BluedotErrorObject; | ||
throwInterruptedByResetError(description?: string, error?: Error): BluedotErrorObject; | ||
throwLocationAPINotAvailableError(description?: string, error?: Error): BluedotErrorObject; | ||
createRetryAttemptFailedError(retryCount: number, error?: Error): RetryAttemptFailedErrorObject; | ||
} | ||
export interface DataTemplate { | ||
@@ -118,2 +201,15 @@ convertToDataObject: () => Partial<Record<string, string>>; | ||
/** | ||
* A retry callback can be used to receive any warnings caused by a failure to complete an action | ||
* while the retry behavior of the function is still in progress. For each retry an new call will | ||
* be made to RetryCallback returning the retry count and the error which caused the retry | ||
*/ | ||
export declare type RetryCallback = (error: RetryAttemptFailedErrorObject) => void; | ||
/** | ||
* An options object containing extra configurable properties for sending Wave events | ||
* Currently only contains the ability to set a callback to listen for retry failure warnings | ||
*/ | ||
export interface WaveOptions { | ||
retryCallback: RetryCallback; | ||
} | ||
/** | ||
* A Wave request payload.<br /> | ||
@@ -148,2 +244,3 @@ * Request samples: | ||
installRef?: string; | ||
userToken?: string; | ||
customEventMetaData?: CustomEventMetaData | HelloDataTemplate; | ||
@@ -153,2 +250,9 @@ location?: Location; | ||
} | ||
/** | ||
* An options object containing extra configurable properties for one shot service | ||
* Currently only contains the ability to set a callback to listen for retry failure warnings | ||
*/ | ||
export interface OneShotOptions { | ||
retryCallback: RetryCallback; | ||
} | ||
export interface TriggerOneshotOptions { | ||
@@ -158,76 +262,4 @@ notification: WaveNotification; | ||
location?: Location | null; | ||
retryCallback?: RetryCallback | undefined; | ||
} | ||
/** | ||
* Thrown when an input is invalid | ||
*/ | ||
declare type ValidationError = 'ValidationError'; | ||
/** | ||
* Thrown when a network operation fails after being retried. This is likely due to network unavailability. | ||
*/ | ||
declare type NetworkRetriesExceededError = 'NetworkRetriesExceededError'; | ||
/** | ||
* Thrown when an unexpected error occurs on Bluedot servers, for example cloud services being unavailable | ||
*/ | ||
declare type UnexpectedServerError = 'UnexpectedServerError'; | ||
/** | ||
* Thrown when an input argument provided is of the wrong type | ||
*/ | ||
declare type InvalidInputTypeError = 'InvalidInputTypeError'; | ||
/** | ||
* Thrown when a required value is not provided so the operation cannot be completed | ||
*/ | ||
declare type RequiredValueMissingError = 'RequiredValueMissingError'; | ||
/** | ||
* Thrown when the SDK has not been initialized via the initialize call, or there was an error during initialization | ||
*/ | ||
declare type SdkNotInitializedError = 'SdkNotInitializedError'; | ||
/** | ||
* Thrown when the provided projectId cannot be found, likely due to incorrect ID or deleted project | ||
*/ | ||
declare type ProjectIdNotFoundError = 'ProjectIdNotFoundError'; | ||
/** | ||
* Thrown when Bluedot server returns Not found errors | ||
*/ | ||
declare type NotFoundError = 'NotFoundError'; | ||
/** | ||
* Thrown when processes are interrupted by reset | ||
*/ | ||
declare type InterruptedByResetError = 'InterruptedByResetError'; | ||
/** | ||
* Thrown when location api is not available in the current environment | ||
*/ | ||
declare type LocationAPINotAvailableError = 'LocationAPINotAvailableError'; | ||
/** | ||
* The generic error type that encompasses all custom errors | ||
*/ | ||
export declare type BluedotErrorType = ValidationError | NetworkRetriesExceededError | UnexpectedServerError | InvalidInputTypeError | RequiredValueMissingError | SdkNotInitializedError | ProjectIdNotFoundError | NotFoundError | InterruptedByResetError | LocationAPINotAvailableError; | ||
export interface BluedotErrorTypeEnum { | ||
ValidationError: ValidationError; | ||
NetworkRetriesExceededError: NetworkRetriesExceededError; | ||
UnexpectedServerError: UnexpectedServerError; | ||
InvalidInputTypeError: InvalidInputTypeError; | ||
RequiredValueMissingError: RequiredValueMissingError; | ||
SdkNotInitializedError: SdkNotInitializedError; | ||
ProjectIdNotFoundError: ProjectIdNotFoundError; | ||
NotFoundError: NotFoundError; | ||
InterruptedByResetError: InterruptedByResetError; | ||
LocationAPINotAvailableError: LocationAPINotAvailableError; | ||
} | ||
export interface BluedotErrorObject extends Error { | ||
name: BluedotErrorType; | ||
errorObject?: Error; | ||
} | ||
export interface ErrorFactory { | ||
createError(errorType: BluedotErrorType, description: string, error?: Error): BluedotErrorObject; | ||
throwNetworkRetriesExceededError(retriesAttempted?: number, error?: Error): BluedotErrorObject; | ||
throwValidationError(description?: string, error?: Error): BluedotErrorObject; | ||
throwUnexpectedServerError(description?: string, error?: Error): BluedotErrorObject; | ||
throwInvalidInputTypeError(description?: string, error?: Error): BluedotErrorObject; | ||
throwSdkNotInitializedError(description?: string, error?: Error): BluedotErrorObject; | ||
throwRequiredValueMissingError(missingFieldName?: string, error?: Error): BluedotErrorObject; | ||
throwProjectIdNotFoundError(invalidId?: string, error?: Error): BluedotErrorObject; | ||
throwNotFoundError(description?: string, error?: Error): BluedotErrorObject; | ||
throwInterruptedByResetError(description?: string, error?: Error): BluedotErrorObject; | ||
throwLocationAPINotAvailableError(description?: string, error?: Error): BluedotErrorObject; | ||
} | ||
export interface GlobalConfig { | ||
@@ -303,2 +335,3 @@ apiKey?: string; | ||
* @param customEventMetaData - any custom data fields or a HelloModel object | ||
* @param options - an optional options object containing extra configurable properties | ||
* | ||
@@ -308,5 +341,29 @@ * @throws InvalidInputTypeError If destinationId is not a string | ||
*/ | ||
send: (destinationId: string, customEventMetaData?: CustomEventMetaData | HelloModel) => Promise<void>; | ||
send: (destinationId: string, customEventMetaData?: CustomEventMetaData | HelloModel, options?: WaveOptions) => Promise<void>; | ||
} | ||
/** | ||
* Manage the userToken that is passed along with all events. This is used to validate subsequent events relating to registered orders. | ||
*/ | ||
export interface Credentials { | ||
/** | ||
* Set the userToken for Bluedot SDK if you intend to use Now Ready Screens | ||
* @param userToken - The unique userToken returned by Register order endpoint. | ||
* Learn more about Order Registration [here](https://events-docs.bluedot.io/#operation/registerOrder) | ||
* | ||
* @throws ValidationError Throws validation error for userToken is not a 7-alphanumeric-character string | ||
*/ | ||
setUserToken: (userToken: string) => void; | ||
/** | ||
* Clean up the userToken of Bluedot SDK | ||
*/ | ||
clearUserToken: () => void; | ||
} | ||
/** | ||
* An options object containing extra configurable properties for initializing the SDK | ||
* Currently only contains the ability to set a callback to listen for retry failure warnings | ||
*/ | ||
export interface InitializeOptions { | ||
retryCallback: RetryCallback; | ||
} | ||
/** | ||
* This interface is the high-level entry point for integration with the Bluedot Javascript SDK.<br /> | ||
@@ -327,9 +384,14 @@ * To use the SDK, it is necessary to initialize with your projectId.<br /> | ||
/** | ||
* Manage the userToken that is passed along with all events. This is used to validate subsequent events relating to registered orders. | ||
*/ | ||
credentials: Credentials; | ||
/** | ||
* Initialize Bluedot service with a given projectId. | ||
* The given projectId will be searched against the GlobalConfig and return corresponding configurations. | ||
* @param projectId - The Project ID of a project can be found in the Projects section of Canvas. | ||
* @param options - an optional options object containing extra configurable properties | ||
* | ||
* @throws ValidationError If the projectId is not a valid UUID. | ||
*/ | ||
initialize: (projectId: string) => Promise<void>; | ||
initialize: (projectId: string, options?: InitializeOptions) => Promise<void>; | ||
/** | ||
@@ -336,0 +398,0 @@ * Halt all SDK activities and reset all states to as it was before initialization. |
@@ -22,1 +22,5 @@ export declare const isString: (input: unknown) => boolean; | ||
export declare const validateDuplicateInitialization: () => void; | ||
export declare const isValidUserToken: (input: unknown) => boolean; | ||
export declare const validateUserToken: (input: unknown) => void; | ||
export declare const validateWaveOptions: (input: unknown) => void; | ||
export declare const validateInitializeOptions: (input: unknown) => void; |
{ | ||
"name": "@bluedot-innovation/javascript-sdk", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
298431
29
3017