samandesk 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/data.d.ts CHANGED
@@ -16,6 +16,8 @@ export declare function setToken(newToken: string): void;
16
16
  export declare function getToken(): string | undefined;
17
17
  /** ⁧تگ iframe را حذف می‌کند ⁩ */
18
18
  export declare function clearFrame(): void;
19
+ /** ⁧مقدار src تگ iframe‌ را براساس ورودی تنظیم می‌کند */
20
+ export declare function setFrameSrc(src: string): void;
19
21
  /** ⁧تگ iframe را بر می‌گرداند ⁩ */
20
22
  export declare function getFrame(): HTMLIFrameElement;
21
23
  export {};
@@ -1,63 +1,66 @@
1
- let a;
2
- const i = document.createElement("iframe"), d = {
1
+ let d;
2
+ const i = document.createElement("iframe"), l = {
3
3
  count: 0,
4
4
  promises: {}
5
5
  };
6
6
  function m() {
7
- return d;
7
+ return l;
8
8
  }
9
- function l(o) {
10
- a = o;
9
+ function p(t) {
10
+ d = t;
11
11
  }
12
- function p() {
13
- return a;
12
+ function f() {
13
+ return d;
14
14
  }
15
15
  function u() {
16
16
  i.src = "";
17
17
  }
18
- function r() {
18
+ function c(t) {
19
+ i.src = t;
20
+ }
21
+ function a() {
19
22
  return i;
20
23
  }
21
- const f = new Event("ready");
22
- function h() {
23
- return f;
24
+ const h = new Event("ready");
25
+ function y() {
26
+ return h;
24
27
  }
25
- function c(o) {
28
+ function x(t) {
26
29
  window.addEventListener("message", (e) => {
27
30
  if (!e.data.from || e.data.from !== "SamanDesk")
28
31
  return;
32
+ let o = !1;
29
33
  console.log(`message from (${e.origin})`, e);
30
34
  try {
31
- o[e.data.action](e.data);
35
+ t[e.data.action](e.data.data), o = !0;
32
36
  } catch {
33
37
  console.error("error while run event action");
34
38
  }
35
- const n = e.data, t = n.id, s = m();
36
- t in s.promises ? (s.promises[t](n), delete s.promises[t]) : console.error("Message from outside of frame is invalid");
39
+ const n = e.data, s = n.id, r = m();
40
+ s in r.promises ? (r.promises[s](n), delete r.promises[s]) : o || console.error("Message from outside of frame is invalid");
37
41
  });
38
42
  }
39
- class y {
43
+ class g {
40
44
  async init() {
41
- c(this);
45
+ x(this);
42
46
  }
43
47
  /** توکن را از میزبان دریافت کرده و آن را ذخیره می‌کند. سپس به میزبان اعلام می‌کند که آماده‌ی ادامه‌ی کار است */
44
48
  setToken(e) {
45
- l(e.token), window.dispatchEvent(h()), u();
49
+ p(e.token), u(), window.dispatchEvent(y());
46
50
  }
47
51
  }
48
- class g {
52
+ class k {
49
53
  /**
50
54
  * ⁧این تابع در ابتدا مقدار verifiedToken را دریافت کرده و سپس مقدار token‌ را دریافت و سپس آن را ذخیره می‌کند
51
55
  */
52
56
  async init(e) {
53
- const n = new y();
54
- n.init(), c(n);
55
- const t = r();
56
- t.src = `https://samandesk.com/setup-interoperation/${e}`, t.width = "0", document.body.appendChild(t);
57
+ new g().init();
58
+ const n = a();
59
+ c(`https://samandesk.com/setup-interoperation/${e}`), n.width = "0", document.body.appendChild(n);
57
60
  }
58
61
  /** استایل مربوط به آیفریم را تنظیم می‌کند */
59
62
  setStyle() {
60
- const e = r();
63
+ const e = a();
61
64
  e.style.position = "fixed", e.style.bottom = "12px", e.style.left = "12px", e.style.boxShadow = "0px 0px 100px 0px rgba(0,0,0,0.48)", e.style.maxWidth = "500px", e.style.width = "100%", e.style.maxHeight = "640px", e.style.height = "100%", e.style.zIndex = "1000", e.style.borderRadius = "24px", e.width = "500px", e.height = "640px";
62
65
  }
63
66
  /**
@@ -67,10 +70,10 @@ class g {
67
70
  * اگر لینک را در ورودی ارسال نکند، خودکار به صفحه‌ی انتخاب دپارتمان می‌رویم و ادامه‌ی کار توسط سامان دسک صورت می‌گیرد
68
71
  */
69
72
  open(e) {
70
- const n = r(), t = e || `https://samandesk.com/department_selection?token=${p()}`;
71
- n.src = t, this.setStyle(), document.body.appendChild(n);
73
+ const o = a(), n = e || `https://samandesk.com/department_selection?token=${f()}`;
74
+ c(n), this.setStyle(), document.body.appendChild(o);
72
75
  }
73
76
  }
74
77
  export {
75
- g as SamanDesk
78
+ k as SamanDesk
76
79
  };
@@ -1 +1 @@
1
- (function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o.SamanDesk={}))})(this,function(o){"use strict";let s;const d=document.createElement("iframe"),m={count:0,promises:{}};function p(){return m}function l(i){s=i}function f(){return s}function u(){d.src=""}function r(){return d}const y=new Event("ready");function h(){return y}function c(i){window.addEventListener("message",e=>{if(!e.data.from||e.data.from!=="SamanDesk")return;console.log(`message from (${e.origin})`,e);try{i[e.data.action](e.data)}catch{console.error("error while run event action")}const n=e.data,t=n.id,a=p();t in a.promises?(a.promises[t](n),delete a.promises[t]):console.error("Message from outside of frame is invalid")})}class x{async init(){c(this)}setToken(e){l(e.token),window.dispatchEvent(h()),u()}}class g{async init(e){const n=new x;n.init(),c(n);const t=r();t.src=`https://samandesk.com/setup-interoperation/${e}`,t.width="0",document.body.appendChild(t)}setStyle(){const e=r();e.style.position="fixed",e.style.bottom="12px",e.style.left="12px",e.style.boxShadow="0px 0px 100px 0px rgba(0,0,0,0.48)",e.style.maxWidth="500px",e.style.width="100%",e.style.maxHeight="640px",e.style.height="100%",e.style.zIndex="1000",e.style.borderRadius="24px",e.width="500px",e.height="640px"}open(e){const n=r(),t=e||`https://samandesk.com/department_selection?token=${f()}`;n.src=t,this.setStyle(),document.body.appendChild(n)}}o.SamanDesk=g,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
1
+ (function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o.SamanDesk={}))})(this,function(o){"use strict";let s;const r=document.createElement("iframe"),m={count:0,promises:{}};function p(){return m}function f(t){s=t}function u(){return s}function y(){r.src=""}function l(t){r.src=t}function a(){return r}const h=new Event("ready");function x(){return h}function g(t){window.addEventListener("message",e=>{if(!e.data.from||e.data.from!=="SamanDesk")return;let i=!1;console.log(`message from (${e.origin})`,e);try{t[e.data.action](e.data.data),i=!0}catch{console.error("error while run event action")}const n=e.data,d=n.id,c=p();d in c.promises?(c.promises[d](n),delete c.promises[d]):i||console.error("Message from outside of frame is invalid")})}class k{async init(){g(this)}setToken(e){f(e.token),y(),window.dispatchEvent(x())}}class w{async init(e){new k().init();const n=a();l(`https://samandesk.com/setup-interoperation/${e}`),n.width="0",document.body.appendChild(n)}setStyle(){const e=a();e.style.position="fixed",e.style.bottom="12px",e.style.left="12px",e.style.boxShadow="0px 0px 100px 0px rgba(0,0,0,0.48)",e.style.maxWidth="500px",e.style.width="100%",e.style.maxHeight="640px",e.style.height="100%",e.style.zIndex="1000",e.style.borderRadius="24px",e.width="500px",e.height="640px"}open(e){const i=a(),n=e||`https://samandesk.com/department_selection?token=${u()}`;l(n),this.setStyle(),document.body.appendChild(i)}}o.SamanDesk=w,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samandesk",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "files": [