@rechat/sdk 0.2.12 → 0.3.1

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/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
 
2
2
  Rechat SDK library allows you to integrate your website or application with Rechat.
3
3
 
4
- [[include:Installation.md]]
5
-
6
4
  #### Basic Example
7
5
 
8
6
  ```html
@@ -46,5 +44,6 @@ Rechat SDK library allows you to integrate your website or application with Rech
46
44
  ```
47
45
 
48
46
  #### More Examples
49
- [Lead Capture](examples/lead-capture.html)
50
- [Lead Form](examples/lead-form.html)
47
+ [Lead Capture](./public/examples/lead-capture.html)
48
+ [Lead Tracker](./public/examples/lead-tracker.html)
49
+ [Lead Form](./public/examples/lead-form.html)
@@ -1 +1 @@
1
- var Rechat=function(t){"use strict";var e=function(){return e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},e.apply(this,arguments)};function n(t,e,n,r){return new(n||(n=Promise))((function(o,a){function i(t){try{u(r.next(t))}catch(t){a(t)}}function c(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,c)}u((r=r.apply(t,e||[])).next())}))}function r(t,e){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(c){return function(u){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=e.call(t,i)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,u])}}}"function"==typeof SuppressedError&&SuppressedError;var o=function(){function t(t){this._settings=t}return t.prototype.getLeadMetaDataFromUrl=function(){var t=new URLSearchParams(window.location.search);return["user_id","brand_id","ad_campaign_id","email_campaign_id","email_campaign_email_id"].reduce((function(n,r){var o,a;return e(e({},n),((o={})[r]=null!==(a=t.get("rechat_".concat(r)))&&void 0!==a?a:"",o))}),{})},t.prototype.capture=function(t,o){return n(this,void 0,void 0,(function(){var n=this;return r(this,(function(r){return[2,new Promise((function(r,a){fetch("".concat(n.ApiUrl,"/leads"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({lead:o,metadata:e(e({},n.getLeadMetaDataFromUrl()),t)})}).then((function(t){return t.ok?r():a(t)})).catch(a)}))]}))}))},t.prototype.form=function(t,n,r){var o=this;t.addEventListener("submit",(function(a){var i;a.preventDefault();var c=Object.values(t).reduce((function(t,n){var r;return n.name?e(e({},t),((r={})[n.name]=n.value,r)):t}),{});!1!==(null===(i=r.validate)||void 0===i?void 0:i.call(r,c))&&o.capture(n,c).then(r.onSuccess).catch(r.onError)}))},Object.defineProperty(t.prototype,"ApiUrl",{get:function(){return"https://".concat(this._settings.sandbox?"boer.":"","api.rechat.com")},enumerable:!1,configurable:!0}),t}(),a=function(){function t(t){void 0===t&&(t={}),this._settings=t,this._leads=new o(t)}return Object.defineProperty(t.prototype,"Leads",{get:function(){return this._leads},enumerable:!1,configurable:!0}),t}();return t.Sdk=a,t}({});
1
+ var Rechat=function(e){"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)};function n(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},r.apply(this,arguments)};function i(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function c(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))}function o(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=c(0),a.throw=c(1),a.return=c(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(c){return function(u){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&c[0]?r.return:c[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,c[1])).done)return i;switch(r=0,i&&(c=[2&c[0],i.value]),c[0]){case 0:case 1:i=c;break;case 4:return o.label++,{value:c[1],done:!1};case 5:o.label++,r=c[1],c=[0];continue;case 7:c=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==c[0]&&2!==c[0])){o=0;continue}if(3===c[0]&&(!i||c[1]>i[0]&&c[1]<i[3])){o.label=c[1];break}if(6===c[0]&&o.label<i[1]){o.label=i[1],i=c;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(c);break}i[2]&&o.ops.pop(),o.trys.pop();continue}c=t.call(e,o)}catch(e){c=[6,e],r=0}finally{n=i=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,u])}}}function a(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}"function"==typeof SuppressedError&&SuppressedError;var c,u={};var s=a(function(){if(c)return u;c=1,Object.defineProperty(u,"__esModule",{value:!0}),u.parse=function(e,t){const n=new o,r=e.length;if(r<2)return n;const i=t?.decode||l;let c=0;do{const t=e.indexOf("=",c);if(-1===t)break;const o=e.indexOf(";",c),u=-1===o?r:o;if(t>u){c=e.lastIndexOf(";",t-1)+1;continue}const l=a(e,c,t),p=s(e,t,l),f=e.slice(l,p);if(void 0===n[f]){let r=a(e,t+1,u),o=s(e,u,r);const c=i(e.slice(r,o));n[f]=c}c=u+1}while(c<r);return n},u.serialize=function(o,a,c){const u=c?.encode||encodeURIComponent;if(!e.test(o))throw new TypeError(`argument name is invalid: ${o}`);const s=u(a);if(!t.test(s))throw new TypeError(`argument val is invalid: ${a}`);let l=o+"="+s;if(!c)return l;if(void 0!==c.maxAge){if(!Number.isInteger(c.maxAge))throw new TypeError(`option maxAge is invalid: ${c.maxAge}`);l+="; Max-Age="+c.maxAge}if(c.domain){if(!n.test(c.domain))throw new TypeError(`option domain is invalid: ${c.domain}`);l+="; Domain="+c.domain}if(c.path){if(!r.test(c.path))throw new TypeError(`option path is invalid: ${c.path}`);l+="; Path="+c.path}if(c.expires){if(!function(e){return"[object Date]"===i.call(e)}(c.expires)||!Number.isFinite(c.expires.valueOf()))throw new TypeError(`option expires is invalid: ${c.expires}`);l+="; Expires="+c.expires.toUTCString()}c.httpOnly&&(l+="; HttpOnly");c.secure&&(l+="; Secure");c.partitioned&&(l+="; Partitioned");if(c.priority){switch("string"==typeof c.priority?c.priority.toLowerCase():void 0){case"low":l+="; Priority=Low";break;case"medium":l+="; Priority=Medium";break;case"high":l+="; Priority=High";break;default:throw new TypeError(`option priority is invalid: ${c.priority}`)}}if(c.sameSite){switch("string"==typeof c.sameSite?c.sameSite.toLowerCase():c.sameSite){case!0:case"strict":l+="; SameSite=Strict";break;case"lax":l+="; SameSite=Lax";break;case"none":l+="; SameSite=None";break;default:throw new TypeError(`option sameSite is invalid: ${c.sameSite}`)}}return l};const e=/^[\u0021-\u003A\u003C\u003E-\u007E]+$/,t=/^[\u0021-\u003A\u003C-\u007E]*$/,n=/^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i,r=/^[\u0020-\u003A\u003D-\u007E]*$/,i=Object.prototype.toString,o=(()=>{const e=function(){};return e.prototype=Object.create(null),e})();function a(e,t,n){do{const n=e.charCodeAt(t);if(32!==n&&9!==n)return t}while(++t<n);return n}function s(e,t,n){for(;t>n;){const n=e.charCodeAt(--t);if(32!==n&&9!==n)return t+1}return n}function l(e){if(-1===e.indexOf("%"))return e;try{return decodeURIComponent(e)}catch(t){return e}}return u}()),l=function(){function e(e){this.settings=e}return Object.defineProperty(e.prototype,"ApiUrl",{get:function(){var e;return null!==(e=this.settings.api_url)&&void 0!==e?e:"https://".concat(this.settings.sandbox?"boer.":"","api.rechat.com")},enumerable:!1,configurable:!0}),e}(),p=function(e){function t(t){return e.call(this,t)||this}return n(t,e),t.prototype.identify=function(e){var t,n;document.cookie=s.serialize(this.CookieName,e,null===(n=null===(t=this.TrackerSettings)||void 0===t?void 0:t.cookie)||void 0===n?void 0:n.options)},t.prototype.capture=function(e){var t=this;return new Promise((function(n,r){var i=t.leadTrackingId;if(i)if(e.listing_id||e.mlsid){var o={action:"ContactViewedListing",object_class:"listing"};e.mlsid?o.object_sa={mls_number:e.mlsid}:e.listing_id&&(o.object=e.listing_id),fetch("".concat(t.ApiUrl,"/leads/").concat(i,"/timeline"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(o)}).then((function(e){return e.ok?n():r(e)})).catch(r)}else r("Neither listing_id nor mlsid is provided in the data");else r("No tracking id is found")}))},t.prototype.stop=function(){document.cookie="".concat(this.CookieName,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;")},Object.defineProperty(t.prototype,"CookieName",{get:function(){var e,t,n;return null!==(n=null===(t=null===(e=this.TrackerSettings)||void 0===e?void 0:e.cookie)||void 0===t?void 0:t.name)&&void 0!==n?n:"rechat-sdk-tracker"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"TrackerSettings",{get:function(){return this.settings.tracker},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leadTrackingId",{get:function(){var e;return null!==(e=s.parse(document.cookie)[this.CookieName])&&void 0!==e?e:null},enumerable:!1,configurable:!0}),t}(l),f=function(e){function t(t){var n=e.call(this,t)||this;return n._tracker=new p(t),n}return n(t,e),Object.defineProperty(t.prototype,"Tracker",{get:function(){return this._tracker},enumerable:!1,configurable:!0}),t.prototype.getLeadMetaDataFromUrl=function(){var e=new URLSearchParams(window.location.search);return["user_id","brand_id","ad_campaign_id","email_campaign_id","email_campaign_email_id"].reduce((function(t,n){var i,o;return r(r({},t),((i={})[n]=null!==(o=e.get("rechat_".concat(n)))&&void 0!==o?o:"",i))}),{})},t.prototype.capture=function(e,t){return i(this,void 0,void 0,(function(){var n=this;return o(this,(function(i){return[2,new Promise((function(i,o){fetch("".concat(n.ApiUrl,"/leads"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({lead:t,metadata:r(r({},n.getLeadMetaDataFromUrl()),e)})}).then((function(e){e.ok?e.json().then((function(e){var t=e.data;!1!==n.settings.tracker&&n._tracker.identify(t.id),i(t)})):o(e)})).catch(o)}))]}))}))},t.prototype.form=function(e,t,n){var i=this;e.addEventListener("submit",(function(o){var a;o.preventDefault();var c=Object.values(e).reduce((function(e,t){var n;return t.name?r(r({},e),((n={})[t.name]=t.value,n)):e}),{});!1!==(null===(a=n.validate)||void 0===a?void 0:a.call(n,c))&&i.capture(t,c).then(n.onSuccess).catch(n.onError)}))},t}(l),d=function(){function e(e){void 0===e&&(e={}),this._settings=e,this._leads=new f(e)}return Object.defineProperty(e.prototype,"Leads",{get:function(){return this._leads},enumerable:!1,configurable:!0}),e}();return e.Sdk=d,e}({});
@@ -1,9 +1,11 @@
1
- import type { IFormEvents, ILeadMetaData, ILeadInput, ISdkSettings } from './types';
2
- export declare class LeadCapture {
3
- private _settings;
1
+ import { LeadTracker } from './LeadTracker';
2
+ import { SdkBase } from './SdkBase';
3
+ import type { IFormEvents, ILeadMetaData, ILeadInput, ISdkSettings, ILeadCaptureResponse } from './types';
4
+ export declare class LeadCapture extends SdkBase {
5
+ private _tracker;
4
6
  constructor(settings: ISdkSettings);
7
+ get Tracker(): LeadTracker;
5
8
  getLeadMetaDataFromUrl(): Partial<ILeadMetaData>;
6
- capture(metadata: ILeadMetaData, lead: ILeadInput): Promise<void>;
9
+ capture(metadata: ILeadMetaData, lead: ILeadInput): Promise<ILeadCaptureResponse>;
7
10
  form(element: HTMLFormElement, channel: ILeadMetaData, events: IFormEvents): void;
8
- private get ApiUrl();
9
11
  }
@@ -0,0 +1,12 @@
1
+ import { SdkBase } from './SdkBase';
2
+ import { ISdkSettings } from './types';
3
+ import { ITrackPayload } from './types/lead-tracker';
4
+ export declare class LeadTracker extends SdkBase {
5
+ constructor(settings: ISdkSettings);
6
+ identify(id: string): void;
7
+ capture(data: ITrackPayload): Promise<void>;
8
+ stop(): void;
9
+ private get CookieName();
10
+ private get TrackerSettings();
11
+ private get leadTrackingId();
12
+ }
@@ -0,0 +1,6 @@
1
+ import { ISdkSettings } from './types';
2
+ export declare abstract class SdkBase {
3
+ protected settings: ISdkSettings;
4
+ constructor(settings: ISdkSettings);
5
+ protected get ApiUrl(): string;
6
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './types';
2
2
  export { LeadCapture } from './LeadCapture';
3
+ export { LeadTracker } from './LeadTracker';
3
4
  export { Sdk } from '.';
package/esm/index.all.js CHANGED
@@ -1 +1 @@
1
- var t=function(){return t=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},t.apply(this,arguments)};function e(t,e,n,r){return new(n||(n=Promise))((function(o,a){function i(t){try{u(r.next(t))}catch(t){a(t)}}function c(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,c)}u((r=r.apply(t,e||[])).next())}))}function n(t,e){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(c){return function(u){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=e.call(t,i)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,u])}}}"function"==typeof SuppressedError&&SuppressedError;var r=function(){function r(t){this._settings=t}return r.prototype.getLeadMetaDataFromUrl=function(){var e=new URLSearchParams(window.location.search);return["user_id","brand_id","ad_campaign_id","email_campaign_id","email_campaign_email_id"].reduce((function(n,r){var o,a;return t(t({},n),((o={})[r]=null!==(a=e.get("rechat_".concat(r)))&&void 0!==a?a:"",o))}),{})},r.prototype.capture=function(r,o){return e(this,void 0,void 0,(function(){var e=this;return n(this,(function(n){return[2,new Promise((function(n,a){fetch("".concat(e.ApiUrl,"/leads"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({lead:o,metadata:t(t({},e.getLeadMetaDataFromUrl()),r)})}).then((function(t){return t.ok?n():a(t)})).catch(a)}))]}))}))},r.prototype.form=function(e,n,r){var o=this;e.addEventListener("submit",(function(a){var i;a.preventDefault();var c=Object.values(e).reduce((function(e,n){var r;return n.name?t(t({},e),((r={})[n.name]=n.value,r)):e}),{});!1!==(null===(i=r.validate)||void 0===i?void 0:i.call(r,c))&&o.capture(n,c).then(r.onSuccess).catch(r.onError)}))},Object.defineProperty(r.prototype,"ApiUrl",{get:function(){return"https://".concat(this._settings.sandbox?"boer.":"","api.rechat.com")},enumerable:!1,configurable:!0}),r}(),o=function(){function t(t){void 0===t&&(t={}),this._settings=t,this._leads=new r(t)}return Object.defineProperty(t.prototype,"Leads",{get:function(){return this._leads},enumerable:!1,configurable:!0}),t}();export{r as LeadCapture,o as Sdk};
1
+ var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};function t(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},n.apply(this,arguments)};function r(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function c(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))}function i(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=c(0),a.throw=c(1),a.return=c(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(c){return function(u){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&c[0]?r.return:c[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,c[1])).done)return i;switch(r=0,i&&(c=[2&c[0],i.value]),c[0]){case 0:case 1:i=c;break;case 4:return o.label++,{value:c[1],done:!1};case 5:o.label++,r=c[1],c=[0];continue;case 7:c=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==c[0]&&2!==c[0])){o=0;continue}if(3===c[0]&&(!i||c[1]>i[0]&&c[1]<i[3])){o.label=c[1];break}if(6===c[0]&&o.label<i[1]){o.label=i[1],i=c;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(c);break}i[2]&&o.ops.pop(),o.trys.pop();continue}c=t.call(e,o)}catch(e){c=[6,e],r=0}finally{n=i=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,u])}}}function o(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}"function"==typeof SuppressedError&&SuppressedError;var a,c={};var u=o(function(){if(a)return c;a=1,Object.defineProperty(c,"__esModule",{value:!0}),c.parse=function(e,t){const n=new o,r=e.length;if(r<2)return n;const i=t?.decode||l;let a=0;do{const t=e.indexOf("=",a);if(-1===t)break;const o=e.indexOf(";",a),c=-1===o?r:o;if(t>c){a=e.lastIndexOf(";",t-1)+1;continue}const l=u(e,a,t),p=s(e,t,l),f=e.slice(l,p);if(void 0===n[f]){let r=u(e,t+1,c),o=s(e,c,r);const a=i(e.slice(r,o));n[f]=a}a=c+1}while(a<r);return n},c.serialize=function(o,a,c){const u=c?.encode||encodeURIComponent;if(!e.test(o))throw new TypeError(`argument name is invalid: ${o}`);const s=u(a);if(!t.test(s))throw new TypeError(`argument val is invalid: ${a}`);let l=o+"="+s;if(!c)return l;if(void 0!==c.maxAge){if(!Number.isInteger(c.maxAge))throw new TypeError(`option maxAge is invalid: ${c.maxAge}`);l+="; Max-Age="+c.maxAge}if(c.domain){if(!n.test(c.domain))throw new TypeError(`option domain is invalid: ${c.domain}`);l+="; Domain="+c.domain}if(c.path){if(!r.test(c.path))throw new TypeError(`option path is invalid: ${c.path}`);l+="; Path="+c.path}if(c.expires){if(!function(e){return"[object Date]"===i.call(e)}(c.expires)||!Number.isFinite(c.expires.valueOf()))throw new TypeError(`option expires is invalid: ${c.expires}`);l+="; Expires="+c.expires.toUTCString()}c.httpOnly&&(l+="; HttpOnly");c.secure&&(l+="; Secure");c.partitioned&&(l+="; Partitioned");if(c.priority){switch("string"==typeof c.priority?c.priority.toLowerCase():void 0){case"low":l+="; Priority=Low";break;case"medium":l+="; Priority=Medium";break;case"high":l+="; Priority=High";break;default:throw new TypeError(`option priority is invalid: ${c.priority}`)}}if(c.sameSite){switch("string"==typeof c.sameSite?c.sameSite.toLowerCase():c.sameSite){case!0:case"strict":l+="; SameSite=Strict";break;case"lax":l+="; SameSite=Lax";break;case"none":l+="; SameSite=None";break;default:throw new TypeError(`option sameSite is invalid: ${c.sameSite}`)}}return l};const e=/^[\u0021-\u003A\u003C\u003E-\u007E]+$/,t=/^[\u0021-\u003A\u003C-\u007E]*$/,n=/^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i,r=/^[\u0020-\u003A\u003D-\u007E]*$/,i=Object.prototype.toString,o=(()=>{const e=function(){};return e.prototype=Object.create(null),e})();function u(e,t,n){do{const n=e.charCodeAt(t);if(32!==n&&9!==n)return t}while(++t<n);return n}function s(e,t,n){for(;t>n;){const n=e.charCodeAt(--t);if(32!==n&&9!==n)return t+1}return n}function l(e){if(-1===e.indexOf("%"))return e;try{return decodeURIComponent(e)}catch(t){return e}}return c}()),s=function(){function e(e){this.settings=e}return Object.defineProperty(e.prototype,"ApiUrl",{get:function(){var e;return null!==(e=this.settings.api_url)&&void 0!==e?e:"https://".concat(this.settings.sandbox?"boer.":"","api.rechat.com")},enumerable:!1,configurable:!0}),e}(),l=function(e){function n(t){return e.call(this,t)||this}return t(n,e),n.prototype.identify=function(e){var t,n;document.cookie=u.serialize(this.CookieName,e,null===(n=null===(t=this.TrackerSettings)||void 0===t?void 0:t.cookie)||void 0===n?void 0:n.options)},n.prototype.capture=function(e){var t=this;return new Promise((function(n,r){var i=t.leadTrackingId;if(i)if(e.listing_id||e.mlsid){var o={action:"ContactViewedListing",object_class:"listing"};e.mlsid?o.object_sa={mls_number:e.mlsid}:e.listing_id&&(o.object=e.listing_id),fetch("".concat(t.ApiUrl,"/leads/").concat(i,"/timeline"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(o)}).then((function(e){return e.ok?n():r(e)})).catch(r)}else r("Neither listing_id nor mlsid is provided in the data");else r("No tracking id is found")}))},n.prototype.stop=function(){document.cookie="".concat(this.CookieName,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;")},Object.defineProperty(n.prototype,"CookieName",{get:function(){var e,t,n;return null!==(n=null===(t=null===(e=this.TrackerSettings)||void 0===e?void 0:e.cookie)||void 0===t?void 0:t.name)&&void 0!==n?n:"rechat-sdk-tracker"},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"TrackerSettings",{get:function(){return this.settings.tracker},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"leadTrackingId",{get:function(){var e;return null!==(e=u.parse(document.cookie)[this.CookieName])&&void 0!==e?e:null},enumerable:!1,configurable:!0}),n}(s),p=function(e){function o(t){var n=e.call(this,t)||this;return n._tracker=new l(t),n}return t(o,e),Object.defineProperty(o.prototype,"Tracker",{get:function(){return this._tracker},enumerable:!1,configurable:!0}),o.prototype.getLeadMetaDataFromUrl=function(){var e=new URLSearchParams(window.location.search);return["user_id","brand_id","ad_campaign_id","email_campaign_id","email_campaign_email_id"].reduce((function(t,r){var i,o;return n(n({},t),((i={})[r]=null!==(o=e.get("rechat_".concat(r)))&&void 0!==o?o:"",i))}),{})},o.prototype.capture=function(e,t){return r(this,void 0,void 0,(function(){var r=this;return i(this,(function(i){return[2,new Promise((function(i,o){fetch("".concat(r.ApiUrl,"/leads"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({lead:t,metadata:n(n({},r.getLeadMetaDataFromUrl()),e)})}).then((function(e){e.ok?e.json().then((function(e){var t=e.data;!1!==r.settings.tracker&&r._tracker.identify(t.id),i(t)})):o(e)})).catch(o)}))]}))}))},o.prototype.form=function(e,t,r){var i=this;e.addEventListener("submit",(function(o){var a;o.preventDefault();var c=Object.values(e).reduce((function(e,t){var r;return t.name?n(n({},e),((r={})[t.name]=t.value,r)):e}),{});!1!==(null===(a=r.validate)||void 0===a?void 0:a.call(r,c))&&i.capture(t,c).then(r.onSuccess).catch(r.onError)}))},o}(s),f=function(){function e(e){void 0===e&&(e={}),this._settings=e,this._leads=new p(e)}return Object.defineProperty(e.prototype,"Leads",{get:function(){return this._leads},enumerable:!1,configurable:!0}),e}();export{p as LeadCapture,l as LeadTracker,f as Sdk};
@@ -1,5 +1,8 @@
1
+ import { ILeadTrackerOptions } from './lead-tracker';
1
2
  export * from './lead-capture';
2
3
  export * from './lead-form';
3
4
  export interface ISdkSettings {
4
5
  sandbox?: boolean;
6
+ api_url?: string;
7
+ tracker?: ILeadTrackerOptions | false;
5
8
  }
@@ -18,6 +18,14 @@ export interface ILeadInput {
18
18
  address?: string;
19
19
  referer_url?: string;
20
20
  mlsid?: string;
21
+ listing_id?: string;
21
22
  agent_mlsid?: string;
22
23
  source_type: string;
23
24
  }
25
+ export interface ILeadCaptureResponse {
26
+ id: string;
27
+ contact: string;
28
+ created_at: number;
29
+ lead_channel: string;
30
+ source_type: string;
31
+ }
@@ -0,0 +1,15 @@
1
+ import { SerializeOptions } from 'cookie';
2
+ export interface ILeadTrackerOptions {
3
+ cookie?: Partial<{
4
+ name: string;
5
+ options: SerializeOptions;
6
+ }>;
7
+ }
8
+ export type ITrackPayload = {
9
+ mlsid?: string;
10
+ listing_id?: string;
11
+ } & ({
12
+ mlsid: string;
13
+ } | {
14
+ listing_id: string;
15
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rechat/sdk",
3
- "version": "0.2.12",
3
+ "version": "0.3.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -19,22 +19,27 @@
19
19
  "access": "public"
20
20
  },
21
21
  "devDependencies": {
22
+ "@eslint/eslintrc": "^3.3.1",
23
+ "@eslint/js": "^9.24.0",
22
24
  "@jsdevtools/npm-publish": "^3.1.1",
25
+ "@rollup/plugin-commonjs": "^28.0.3",
26
+ "@rollup/plugin-node-resolve": "^16.0.1",
23
27
  "@rollup/plugin-terser": "^0.4.4",
24
- "@rollup/plugin-typescript": "^11.1.6",
25
- "@typescript-eslint/eslint-plugin": "^7.8.0",
26
- "@typescript-eslint/parser": "^7.8.0",
27
- "eslint": "^8.53.0",
28
- "eslint-config-prettier": "^9.1.0",
29
- "eslint-plugin-prettier": "^5.1.3",
30
- "eslint-plugin-tsdoc": "^0.2.17",
31
- "prettier": "^3.2.5",
32
- "rimraf": "^5.0.5",
33
- "rollup": "^4.17.2",
34
- "tslib": "^2.6.2",
35
- "typedoc": "^0.25.13",
36
- "typedoc-material-theme": "^1.0.2",
37
- "typescript": "^5.4.5"
28
+ "@rollup/plugin-typescript": "^12.1.2",
29
+ "@typescript-eslint/eslint-plugin": "^8.30.1",
30
+ "@typescript-eslint/parser": "^8.30.1",
31
+ "eslint": "^9.24.0",
32
+ "eslint-config-prettier": "^10.1.2",
33
+ "eslint-plugin-prettier": "^5.2.6",
34
+ "eslint-plugin-tsdoc": "^0.4.0",
35
+ "globals": "^16.0.0",
36
+ "prettier": "^3.5.3",
37
+ "rimraf": "^6.0.1",
38
+ "rollup": "^4.40.0",
39
+ "tslib": "^2.8.1",
40
+ "typedoc": "^0.28.2",
41
+ "typedoc-material-theme": "^1.4.0",
42
+ "typescript": "^5.8.3"
38
43
  },
39
44
  "type": "module",
40
45
  "typings": "esm/index.all.d.ts",
@@ -46,5 +51,8 @@
46
51
  "esm",
47
52
  "LICENSE",
48
53
  "README"
49
- ]
54
+ ],
55
+ "dependencies": {
56
+ "cookie": "^1.0.2"
57
+ }
50
58
  }