samandesk 1.0.2 → 1.0.5
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 +21 -0
- package/dist/events.d.ts +9 -0
- package/dist/index.d.ts +15 -1
- package/dist/interoperation.d.ts +14 -0
- package/dist/saman-desk.js +73 -4
- package/dist/saman-desk.umd.cjs +1 -1
- package/package.json +7 -12
package/dist/data.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type PromiseMap = {
|
|
2
|
+
[key: number]: (data: any) => void;
|
|
3
|
+
};
|
|
4
|
+
/** آبجکت پرامیسهای منتظر اجرا */
|
|
5
|
+
export declare function getRun(): {
|
|
6
|
+
count: number;
|
|
7
|
+
promises: PromiseMap;
|
|
8
|
+
};
|
|
9
|
+
/** تنظیم تعداد پرامیسهای منتظر اجرا */
|
|
10
|
+
export declare function setRunCount(count: number): void;
|
|
11
|
+
/** تنظیم پرامیسهای منتظر اجرا */
|
|
12
|
+
export declare function setRunPromises(promises: PromiseMap): void;
|
|
13
|
+
/** تنظیم کردن توکن */
|
|
14
|
+
export declare function setToken(newToken: string): void;
|
|
15
|
+
/** توکن را بر میگرداند */
|
|
16
|
+
export declare function getToken(): string | undefined;
|
|
17
|
+
/** تگ iframe را حذف میکند */
|
|
18
|
+
export declare function clearFrame(): void;
|
|
19
|
+
/** تگ iframe را بر میگرداند */
|
|
20
|
+
export declare function getFrame(): HTMLIFrameElement;
|
|
21
|
+
export {};
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InterOperation } from './interoperation';
|
|
2
|
+
/**
|
|
3
|
+
* ایونت آمادهشدن توکن را بر میگرداند
|
|
4
|
+
*/
|
|
5
|
+
export declare function getReadyEvent(): Event;
|
|
6
|
+
/**
|
|
7
|
+
* eventهایی که از بیرون به داخل میایند را اعتبار سنجی و سپس کار خواسته شده را انجام میدهد
|
|
8
|
+
*/
|
|
9
|
+
export declare function handleEvents(interoperation: InterOperation): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare class SamanDesk {
|
|
2
|
+
/**
|
|
3
|
+
* این تابع در ابتدا مقدار verifiedToken را دریافت کرده و سپس مقدار token را دریافت و سپس آن را ذخیره میکند
|
|
4
|
+
*/
|
|
5
|
+
init(verifiedToken: string): Promise<void>;
|
|
6
|
+
/** استایل مربوط به آیفریم را تنظیم میکند */
|
|
7
|
+
private setStyle;
|
|
8
|
+
/**
|
|
9
|
+
* این تابع آیفریم را باز میکند.
|
|
10
|
+
* اگر لینک مستقیما از بیرون آمده باشد همان را باز میکند
|
|
11
|
+
* این اتفاق در شرایطی رخ میدهد که میزبان میخواهد از لینکی که در اختیارش قرار گرفته است مستقیما استفاده کند
|
|
12
|
+
* اگر لینک را در ورودی ارسال نکند، خودکار به صفحهی انتخاب دپارتمان میرویم و ادامهی کار توسط سامان دسک صورت میگیرد
|
|
13
|
+
*/
|
|
14
|
+
open(link?: string): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FunctionKeys } from 'utility-types';
|
|
2
|
+
/**
|
|
3
|
+
* این تابع برای فراخوانی متدهاییست که مقداری بر نمیگردانند
|
|
4
|
+
*/
|
|
5
|
+
export declare function post(action: keyof InterOperation, data?: object): void;
|
|
6
|
+
/**
|
|
7
|
+
* این تابع برای فراخوانی متدهاییست که مقدار بر میگردانند
|
|
8
|
+
*/
|
|
9
|
+
export declare function run<A extends FunctionKeys<InterOperation>>(action: A, data?: object): Promise<ReturnType<InterOperation[A]>>;
|
|
10
|
+
export declare class InterOperation {
|
|
11
|
+
init(): Promise<void>;
|
|
12
|
+
/** توکن را از میزبان دریافت کرده و آن را ذخیره میکند. سپس به میزبان اعلام میکند که آمادهی ادامهی کار است */
|
|
13
|
+
setToken(data: any): void;
|
|
14
|
+
}
|
package/dist/saman-desk.js
CHANGED
|
@@ -1,7 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
let a;
|
|
2
|
+
const i = document.createElement("iframe"), d = {
|
|
3
|
+
count: 0,
|
|
4
|
+
promises: {}
|
|
5
|
+
};
|
|
6
|
+
function m() {
|
|
7
|
+
return d;
|
|
8
|
+
}
|
|
9
|
+
function l(o) {
|
|
10
|
+
a = o;
|
|
11
|
+
}
|
|
12
|
+
function p() {
|
|
13
|
+
return a;
|
|
14
|
+
}
|
|
15
|
+
function u() {
|
|
16
|
+
i.src = "";
|
|
17
|
+
}
|
|
18
|
+
function r() {
|
|
19
|
+
return i;
|
|
20
|
+
}
|
|
21
|
+
const f = new Event("ready");
|
|
22
|
+
function h() {
|
|
23
|
+
return f;
|
|
24
|
+
}
|
|
25
|
+
function c(o) {
|
|
26
|
+
window.addEventListener("message", (e) => {
|
|
27
|
+
if (!e.data.from || e.data.from !== "SamanDesk")
|
|
28
|
+
return;
|
|
29
|
+
console.log(`message from (${e.origin})`, e);
|
|
30
|
+
try {
|
|
31
|
+
o[e.data.action](e.data);
|
|
32
|
+
} catch {
|
|
33
|
+
console.error("error while run event action");
|
|
34
|
+
}
|
|
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");
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
class y {
|
|
40
|
+
async init() {
|
|
41
|
+
c(this);
|
|
42
|
+
}
|
|
43
|
+
/** توکن را از میزبان دریافت کرده و آن را ذخیره میکند. سپس به میزبان اعلام میکند که آمادهی ادامهی کار است */
|
|
44
|
+
setToken(e) {
|
|
45
|
+
l(e.token), window.dispatchEvent(h()), u();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class g {
|
|
49
|
+
/**
|
|
50
|
+
* این تابع در ابتدا مقدار verifiedToken را دریافت کرده و سپس مقدار token را دریافت و سپس آن را ذخیره میکند
|
|
51
|
+
*/
|
|
52
|
+
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
|
+
}
|
|
58
|
+
/** استایل مربوط به آیفریم را تنظیم میکند */
|
|
59
|
+
setStyle() {
|
|
60
|
+
const e = r();
|
|
61
|
+
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
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* این تابع آیفریم را باز میکند.
|
|
65
|
+
* اگر لینک مستقیما از بیرون آمده باشد همان را باز میکند
|
|
66
|
+
* این اتفاق در شرایطی رخ میدهد که میزبان میخواهد از لینکی که در اختیارش قرار گرفته است مستقیما استفاده کند
|
|
67
|
+
* اگر لینک را در ورودی ارسال نکند، خودکار به صفحهی انتخاب دپارتمان میرویم و ادامهی کار توسط سامان دسک صورت میگیرد
|
|
68
|
+
*/
|
|
69
|
+
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);
|
|
72
|
+
}
|
|
4
73
|
}
|
|
5
74
|
export {
|
|
6
|
-
|
|
75
|
+
g as SamanDesk
|
|
7
76
|
};
|
package/dist/saman-desk.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
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"})});
|
package/package.json
CHANGED
|
@@ -1,30 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "samandesk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"files": [
|
|
6
7
|
"dist"
|
|
7
8
|
],
|
|
8
|
-
"main": "./dist/
|
|
9
|
-
"module": "./dist/
|
|
9
|
+
"main": "./dist/saman-desk.umd.cjs",
|
|
10
|
+
"module": "./dist/saman-desk.js",
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
13
|
-
"import": "./dist/
|
|
14
|
-
"require": "./dist/
|
|
14
|
+
"import": "./dist/saman-desk.js",
|
|
15
|
+
"require": "./dist/saman-desk.umd.cjs",
|
|
15
16
|
"types": "./dist/index.d.ts"
|
|
16
17
|
}
|
|
17
18
|
},
|
|
18
|
-
"keywords": [
|
|
19
|
-
"support"
|
|
20
|
-
],
|
|
21
|
-
"author": "TSIT",
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"dependencies": {},
|
|
24
19
|
"devDependencies": {
|
|
25
20
|
"typescript": "^5.2.2",
|
|
21
|
+
"utility-types": "^3.10.0",
|
|
26
22
|
"vite": "^4.4.9",
|
|
27
|
-
"vite-plugin": "^0.0.0",
|
|
28
23
|
"vite-plugin-dts": "^3.5.4"
|
|
29
24
|
}
|
|
30
25
|
}
|