@rechat/sdk 0.1.2 → 0.1.4

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 ADDED
@@ -0,0 +1,50 @@
1
+
2
+ Rechat SDK library allows you to integrate your website or application with Rechat.
3
+
4
+ [[include:Installation.md]]
5
+
6
+ #### Basic Example
7
+
8
+ ```html
9
+ <!DOCTYPE html>
10
+ <html lang="en">
11
+ <head>
12
+ <meta charset="UTF-8">
13
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
14
+ <script src="https://unpkg.com/@rechat/sdk@latest/dist/rechat.min.js"></script>
15
+ </head>
16
+ <body>
17
+
18
+ <button id="capture-1">Lead Capture</button>
19
+
20
+ <script>
21
+ const sdk = new Rechat.Sdk()
22
+
23
+ const channel = {
24
+ channel_id: '2c55e69d-adbe-42d9-97a5-bedb43783b80'
25
+ }
26
+
27
+ const input = {
28
+ first_name: 'John',
29
+ last_name: 'Doe',
30
+ email: 'john@rechat.com',
31
+ phone: '+18189191212',
32
+ }
33
+
34
+ document.getElementById('capture-1').addEventListener('click', () => {
35
+ sdk.Leads.capture(channel, input)
36
+ .then(() => {
37
+ console.log('Done')
38
+ })
39
+ .catch((e) => {
40
+ console.log('Error:', e)
41
+ })
42
+ })
43
+ </script>
44
+ </body>
45
+ </html>
46
+ ```
47
+
48
+ #### More Examples
49
+ [Lead Capture](examples/lead-capture.html)
50
+ [Lead Form](examples/lead-form.html)
@@ -0,0 +1 @@
1
+ var Rechat=function(t){"use strict";var n=function(){return n=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},n.apply(this,arguments)};function e(t,n,e,r){return new(e||(e=Promise))((function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function u(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(a,u)}c((r=r.apply(t,n||[])).next())}))}function r(t,n){var e,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(c){return function(u){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(e=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=n.call(t,a)}catch(t){u=[6,t],r=0}finally{e=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}"function"==typeof SuppressedError&&SuppressedError;var o=function(){function t(t){this._settings=t}return t.prototype.capture=function(t,o){return e(this,void 0,void 0,(function(){return r(this,(function(e){return[2,new Promise((function(e,r){fetch("https://api.rechat.com/leads/channels/".concat(t.channel_id,"/webhook"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n(n({},o),{lead:t}))}).then((function(){return e()})).catch(r)}))]}))}))},t.prototype.form=function(t,e,r){var o=this;t.addEventListener("submit",(function(i){var a;i.preventDefault();var u=Object.values(t).reduce((function(t,e){var r;return e.name?n(n({},t),((r={})[e.name]=e.value,r)):t}),{});!1!==(null===(a=r.validate)||void 0===a?void 0:a.call(r,u))&&o.capture(e,u).then(r.onSuccess).catch(r.onError)}))},t}(),i=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=i,t}({});
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@rechat/sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "clean:sdk": "rimraf umd",
8
8
  "clean:docs": "rimraf api",
9
- "build:docs": "npm run clean:docs && typedoc",
10
- "build:sdk": "npm run clean:sdk && rollup --config --bundleConfigAsCjs"
9
+ "build:docs": "npm run clean:docs && typedoc --readme README.md && npm run docs:examples",
10
+ "build:sdk": "npm run clean:sdk && rollup --config --bundleConfigAsCjs",
11
+ "docs:examples": "cp -r ./public/examples ./api"
11
12
  },
12
13
  "keywords": [],
13
14
  "author": "Rechat INC.",