@skyservice-developers/vue-dev-kit 2.5.7 → 2.6.2
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 +21 -1
- package/dist/{api-AhLH5w3p.js → api-C6FKIf2t.js} +154 -123
- package/dist/api-DAgEQpwF.cjs +1 -0
- package/dist/sdk/api.d.ts +27 -1
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sdk/types.d.ts +7 -0
- package/dist/sdk.cjs +1 -1
- package/dist/sdk.js +1 -1
- package/dist/style.css +1 -1
- package/dist/vue-dev-kit.cjs +23 -23
- package/dist/vue-dev-kit.js +4270 -4281
- package/package.json +1 -1
- package/dist/api-lQ6dAmaI.cjs +0 -1
package/README.md
CHANGED
|
@@ -101,6 +101,10 @@ const tradepoints = await api.getTradepoints()
|
|
|
101
101
|
const categories = await api.getCategoryTree(tradepointId)
|
|
102
102
|
const products = await api.getProducts({ tradepointId })
|
|
103
103
|
|
|
104
|
+
// Права доступу
|
|
105
|
+
const canInventory = await api.getPerms('204') // → boolean
|
|
106
|
+
const allPerms = await api.getPerms() // → PermsMap { '204': true, ... }
|
|
107
|
+
|
|
104
108
|
// Активація/деактивація міні-додатку
|
|
105
109
|
await api.setAppActive({ isActive: true, title: 'Glovo', settings: { foo: 'bar' } })
|
|
106
110
|
await api.setAppActive({ isActive: false, title: 'Glovo' })
|
|
@@ -111,6 +115,22 @@ await api.setAppActive({ isActive: false, title: 'Glovo' })
|
|
|
111
115
|
> `deploymentId` + `appName` задані в конфізі — додатково шле `sendActiveApp`
|
|
112
116
|
> postMessage в parent (Dashboard) з відповіддю сервера та новим станом.
|
|
113
117
|
|
|
118
|
+
#### Права доступу — `getPerms`
|
|
119
|
+
|
|
120
|
+
Повертає права поточного користувача. Джерело за пріоритетом:
|
|
121
|
+
|
|
122
|
+
1. **Стор Dashboard** через iframe bridge (`store.perms`) — миттєво, без токена, працює всередині iframe;
|
|
123
|
+
2. **HTTP fallback** `section=adminPanel&action=getStart` → `data.settings.perms` — поза iframe (standalone-сторінка, Node) або поки стор ще порожній.
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
await api.getPerms('9006') // → boolean — чи надано право 9006
|
|
127
|
+
await api.getPerms() // → PermsMap: { '9006': true, '100': false, ... }
|
|
128
|
+
api.clearPermsCache() // скинути кеш (наступний getPerms перезапросить джерело)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
> Результат кешується на інстансі — повторні виклики не роблять зайвих запитів/postMessage.
|
|
132
|
+
> Значення нормалізуються в `boolean` (бек може віддавати `0/1`); відсутній код → `false`.
|
|
133
|
+
|
|
114
134
|
### Webview detection
|
|
115
135
|
|
|
116
136
|
```ts
|
|
@@ -841,7 +861,7 @@ src/
|
|
|
841
861
|
│ ├── bridge.ts # iframe postMessage API
|
|
842
862
|
│ ├── api.ts # SkyserviceAPI HTTP клієнт
|
|
843
863
|
│ ├── webview.ts # детекція webview/iframe
|
|
844
|
-
│ ├── types.ts # DTO типи (Tradepoint, Category, Product, AppIntegration)
|
|
864
|
+
│ ├── types.ts # DTO типи (Tradepoint, Category, Product, AppIntegration, PermsMap)
|
|
845
865
|
│ └── index.ts
|
|
846
866
|
└── styles/
|
|
847
867
|
```
|
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
let
|
|
1
|
+
import b from "ua-parser-js";
|
|
2
|
+
const h = "DASHBOARD", k = 5e3;
|
|
3
|
+
let P = 0, u = null;
|
|
4
4
|
function A() {
|
|
5
|
-
return `sdk_${Date.now()}_${++
|
|
5
|
+
return `sdk_${Date.now()}_${++P}`;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function C() {
|
|
8
8
|
return "APP_" + Math.random().toString(36).slice(2, 10);
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function R(t) {
|
|
11
11
|
u = t;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
return u || (u =
|
|
13
|
+
function m() {
|
|
14
|
+
return u || (u = C()), u;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function o(t) {
|
|
17
17
|
window.parent.postMessage(
|
|
18
18
|
{
|
|
19
19
|
...t,
|
|
20
|
-
sender:
|
|
21
|
-
target: t.target ||
|
|
20
|
+
sender: m(),
|
|
21
|
+
target: t.target || h
|
|
22
22
|
},
|
|
23
23
|
"*"
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
|
-
function w(t, e, r =
|
|
27
|
-
return
|
|
28
|
-
const
|
|
26
|
+
function w(t, e, r = k) {
|
|
27
|
+
return y() ? new Promise((n) => {
|
|
28
|
+
const a = A(), i = m(), s = setTimeout(() => {
|
|
29
29
|
window.removeEventListener("message", d), n(null);
|
|
30
30
|
}, r);
|
|
31
|
-
function d(
|
|
32
|
-
const c =
|
|
33
|
-
(c == null ? void 0 : c.type) === "DATA_RESPONSE" && (c == null ? void 0 : c.requestId) ===
|
|
31
|
+
function d(S) {
|
|
32
|
+
const c = S.data;
|
|
33
|
+
(c == null ? void 0 : c.type) === "DATA_RESPONSE" && (c == null ? void 0 : c.requestId) === a && (!c.target || c.target === i) && (clearTimeout(s), window.removeEventListener("message", d), n(c.data ?? null));
|
|
34
34
|
}
|
|
35
|
-
window.addEventListener("message", d),
|
|
35
|
+
window.addEventListener("message", d), o({ type: "DATA_REQUEST", requestId: a, source: t, key: e });
|
|
36
36
|
}) : Promise.resolve(null);
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
38
|
+
function U(t) {
|
|
39
|
+
o({ type: "navigate", path: t });
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
|
|
41
|
+
function E() {
|
|
42
|
+
o({ type: "exit" });
|
|
43
43
|
}
|
|
44
|
-
const
|
|
45
|
-
function
|
|
44
|
+
const $ = E;
|
|
45
|
+
function p(t) {
|
|
46
46
|
return w("store", t);
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function g(t) {
|
|
49
49
|
return w("localStorage", t);
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function O(t) {
|
|
52
52
|
return w("window", t);
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
return
|
|
54
|
+
function j() {
|
|
55
|
+
return p("company");
|
|
56
56
|
}
|
|
57
57
|
function W() {
|
|
58
|
-
return
|
|
58
|
+
return p("user");
|
|
59
59
|
}
|
|
60
60
|
function x() {
|
|
61
|
-
return
|
|
61
|
+
return g("token");
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
return
|
|
63
|
+
function B() {
|
|
64
|
+
return g("lang");
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
return
|
|
66
|
+
function M() {
|
|
67
|
+
return p("productCategories");
|
|
68
68
|
}
|
|
69
69
|
function q(t, e) {
|
|
70
|
-
|
|
70
|
+
o({ type: "setLocalStorage", key: t, value: e });
|
|
71
71
|
}
|
|
72
|
-
function
|
|
73
|
-
|
|
72
|
+
function z(t) {
|
|
73
|
+
o({ type: "setRocketMode", value: t });
|
|
74
74
|
}
|
|
75
75
|
function G(t, e) {
|
|
76
|
-
|
|
76
|
+
o({ type: "trackVisit", name: t, path: e });
|
|
77
77
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
78
|
+
function F(t) {
|
|
79
|
+
o({ type: "openExternalLink", url: t });
|
|
80
80
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
function H(t) {
|
|
85
|
-
s({ type: "notification", text: t });
|
|
81
|
+
function H() {
|
|
82
|
+
o({ type: "openCrispChat" });
|
|
86
83
|
}
|
|
87
84
|
function Q(t) {
|
|
88
|
-
|
|
85
|
+
o({ type: "notification", text: t });
|
|
89
86
|
}
|
|
90
87
|
function V(t) {
|
|
91
|
-
|
|
88
|
+
o({ type: "notification", text: t, variant: "error" });
|
|
89
|
+
}
|
|
90
|
+
function J(t) {
|
|
91
|
+
o({ type: "notification", text: t, variant: "warn" });
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function y() {
|
|
94
94
|
try {
|
|
95
95
|
return window.self !== window.top;
|
|
96
96
|
} catch {
|
|
97
97
|
return !0;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
const
|
|
101
|
-
function
|
|
100
|
+
const K = y;
|
|
101
|
+
function Y(t) {
|
|
102
102
|
function e(r) {
|
|
103
103
|
var n;
|
|
104
|
-
((n = r.data) == null ? void 0 : n.sender) ===
|
|
104
|
+
((n = r.data) == null ? void 0 : n.sender) === h && t(r.data);
|
|
105
105
|
}
|
|
106
106
|
return window.addEventListener("message", e), () => window.removeEventListener("message", e);
|
|
107
107
|
}
|
|
108
|
-
function
|
|
108
|
+
function f() {
|
|
109
109
|
if (typeof window > "u") return "browser";
|
|
110
110
|
if (window.webkit != null && window.webkit.messageHandlers !== void 0)
|
|
111
111
|
try {
|
|
112
|
-
if (
|
|
112
|
+
if (b(navigator.userAgent).browser.name === "WebKit") return "ios_webview";
|
|
113
113
|
} catch (t) {
|
|
114
114
|
console.error(t);
|
|
115
115
|
}
|
|
116
116
|
return typeof Android < "u" ? "android_webview" : typeof window.cefQuery < "u" ? "cef_webview" : "browser";
|
|
117
117
|
}
|
|
118
|
-
function Y() {
|
|
119
|
-
return p() === "ios_webview";
|
|
120
|
-
}
|
|
121
118
|
function X() {
|
|
122
|
-
return
|
|
119
|
+
return f() === "ios_webview";
|
|
123
120
|
}
|
|
124
121
|
function Z() {
|
|
125
|
-
return
|
|
122
|
+
return f() === "android_webview";
|
|
126
123
|
}
|
|
127
124
|
function ee() {
|
|
128
|
-
return
|
|
125
|
+
return f() === "cef_webview";
|
|
129
126
|
}
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
function te() {
|
|
128
|
+
return f() !== "browser";
|
|
129
|
+
}
|
|
130
|
+
const L = "https://api.cabinet.developer.skyservice.online/index.php";
|
|
131
|
+
class v {
|
|
132
132
|
constructor(e) {
|
|
133
|
-
this.token = e.token, this.companyId = e.companyId, this.appId = e.appId, this.developerId = e.developerId, this.deploymentId = e.deploymentId, this.appName = e.appName;
|
|
133
|
+
this.permsCache = null, this.token = e.token, this.companyId = e.companyId, this.appId = e.appId, this.developerId = e.developerId, this.deploymentId = e.deploymentId, this.appName = e.appName;
|
|
134
134
|
const r = e.domain.replace("dashboard", "api");
|
|
135
135
|
this.baseUrl = r.startsWith("http") ? r : `https://${r}`;
|
|
136
136
|
}
|
|
137
137
|
/** Factory — create a new SkyserviceAPI instance. */
|
|
138
138
|
static create(e) {
|
|
139
|
-
return new
|
|
139
|
+
return new v(e);
|
|
140
140
|
}
|
|
141
141
|
// --- Low-level ---
|
|
142
142
|
async get(e) {
|
|
@@ -147,26 +147,26 @@ class m {
|
|
|
147
147
|
}), n = await fetch(`${this.baseUrl}/?${r}`);
|
|
148
148
|
if (!n.ok)
|
|
149
149
|
throw new Error(`Skyservice API error: ${n.status}`);
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
152
|
-
throw new Error(`Skyservice API returned status: ${
|
|
153
|
-
return
|
|
150
|
+
const a = await n.json();
|
|
151
|
+
if (a.status !== "done")
|
|
152
|
+
throw new Error(`Skyservice API returned status: ${a.status}`);
|
|
153
|
+
return a.data;
|
|
154
154
|
}
|
|
155
155
|
async post(e, r, n) {
|
|
156
|
-
const
|
|
156
|
+
const a = new URLSearchParams({
|
|
157
157
|
token: this.token,
|
|
158
158
|
...r
|
|
159
|
-
}),
|
|
159
|
+
}), i = await fetch(`${e}?${a}`, {
|
|
160
160
|
method: "POST",
|
|
161
161
|
headers: { "Content-Type": "application/json" },
|
|
162
162
|
body: JSON.stringify(n)
|
|
163
163
|
});
|
|
164
|
-
if (!
|
|
165
|
-
throw new Error(`Skyservice API error: ${
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
168
|
-
throw new Error(`Skyservice API returned status: ${
|
|
169
|
-
return
|
|
164
|
+
if (!i.ok)
|
|
165
|
+
throw new Error(`Skyservice API error: ${i.status}`);
|
|
166
|
+
const s = await i.json();
|
|
167
|
+
if (s.status !== "done")
|
|
168
|
+
throw new Error(`Skyservice API returned status: ${s.status}`);
|
|
169
|
+
return s.data;
|
|
170
170
|
}
|
|
171
171
|
// --- Tradepoints ---
|
|
172
172
|
/**
|
|
@@ -195,7 +195,7 @@ class m {
|
|
|
195
195
|
action: "getCategories",
|
|
196
196
|
...e ? { tradepointId: String(e) } : {}
|
|
197
197
|
});
|
|
198
|
-
return
|
|
198
|
+
return I(r, e);
|
|
199
199
|
}
|
|
200
200
|
// --- Products ---
|
|
201
201
|
/**
|
|
@@ -215,7 +215,7 @@ class m {
|
|
|
215
215
|
of: "nomenclatureId",
|
|
216
216
|
...e != null && e.tradepointId ? { tradepointId: String(e.tradepointId) } : {}
|
|
217
217
|
});
|
|
218
|
-
return
|
|
218
|
+
return D(r.items, e == null ? void 0 : e.includeInactive);
|
|
219
219
|
}
|
|
220
220
|
// --- Integrations ---
|
|
221
221
|
/**
|
|
@@ -235,49 +235,80 @@ class m {
|
|
|
235
235
|
title: r,
|
|
236
236
|
settings: n
|
|
237
237
|
}) {
|
|
238
|
-
const
|
|
238
|
+
const a = e ? "activateApp" : "deactivateApp", i = {
|
|
239
239
|
company_id: this.companyId,
|
|
240
240
|
app_id: this.appId,
|
|
241
241
|
...this.developerId !== void 0 && { developer_id: this.developerId },
|
|
242
242
|
...e && n !== void 0 && { settings: n }
|
|
243
|
-
},
|
|
244
|
-
|
|
245
|
-
{ section: "integrations", action:
|
|
246
|
-
|
|
243
|
+
}, s = await this.post(
|
|
244
|
+
L,
|
|
245
|
+
{ section: "integrations", action: a },
|
|
246
|
+
i
|
|
247
247
|
);
|
|
248
248
|
return this.deploymentId && this.appName && typeof window < "u" && window.self !== window.top && window.parent.postMessage(
|
|
249
249
|
{
|
|
250
250
|
type: "sendActiveApp",
|
|
251
|
-
id:
|
|
251
|
+
id: s.id,
|
|
252
252
|
is_active: e,
|
|
253
253
|
deploymentId: this.deploymentId,
|
|
254
254
|
appName: this.appName,
|
|
255
255
|
title: r
|
|
256
256
|
},
|
|
257
257
|
"*"
|
|
258
|
-
),
|
|
258
|
+
), s;
|
|
259
|
+
}
|
|
260
|
+
async getPerms(e) {
|
|
261
|
+
const r = await this.loadPerms();
|
|
262
|
+
return e === void 0 ? r : !!r[String(e)];
|
|
259
263
|
}
|
|
264
|
+
/** Drop the cached permissions so the next {@link getPerms} call refetches. */
|
|
265
|
+
clearPermsCache() {
|
|
266
|
+
this.permsCache = null;
|
|
267
|
+
}
|
|
268
|
+
async loadPerms() {
|
|
269
|
+
var r;
|
|
270
|
+
if (this.permsCache) return this.permsCache;
|
|
271
|
+
if (typeof window < "u")
|
|
272
|
+
try {
|
|
273
|
+
const n = await p("perms");
|
|
274
|
+
if (n && Object.keys(n).length > 0)
|
|
275
|
+
return this.permsCache = l(n), this.permsCache;
|
|
276
|
+
} catch {
|
|
277
|
+
}
|
|
278
|
+
const e = await this.get({
|
|
279
|
+
section: "adminPanel",
|
|
280
|
+
action: "getStart"
|
|
281
|
+
});
|
|
282
|
+
return this.permsCache = l((r = e == null ? void 0 : e.settings) == null ? void 0 : r.perms), this.permsCache;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function l(t) {
|
|
286
|
+
const e = {};
|
|
287
|
+
if (!t || typeof t != "object") return e;
|
|
288
|
+
for (const [r, n] of Object.entries(t))
|
|
289
|
+
e[r] = !!n;
|
|
290
|
+
return e;
|
|
260
291
|
}
|
|
261
|
-
function
|
|
262
|
-
var n,
|
|
292
|
+
function I(t, e) {
|
|
293
|
+
var n, a;
|
|
263
294
|
const r = [];
|
|
264
|
-
for (const
|
|
265
|
-
if (e != null && !((n =
|
|
295
|
+
for (const i of t) {
|
|
296
|
+
if (e != null && !((n = i.tradepointShow) == null ? void 0 : n[String(e)]))
|
|
266
297
|
continue;
|
|
267
|
-
const
|
|
268
|
-
id:
|
|
269
|
-
pid:
|
|
270
|
-
name:
|
|
271
|
-
active:
|
|
272
|
-
background:
|
|
273
|
-
show:
|
|
298
|
+
const s = {
|
|
299
|
+
id: i.id,
|
|
300
|
+
pid: i.pid,
|
|
301
|
+
name: i.name,
|
|
302
|
+
active: i.active,
|
|
303
|
+
background: i.background,
|
|
304
|
+
show: i.show
|
|
274
305
|
};
|
|
275
|
-
|
|
306
|
+
i.img && (s.img = i.img), (a = i.children) != null && a.length && (s.children = I(i.children, e)), r.push(s);
|
|
276
307
|
}
|
|
277
308
|
return r;
|
|
278
309
|
}
|
|
279
310
|
const _ = /* @__PURE__ */ new Set(["product", "techcard"]), T = "/img/no.png";
|
|
280
|
-
function
|
|
311
|
+
function D(t, e) {
|
|
281
312
|
const r = [];
|
|
282
313
|
for (const n of t)
|
|
283
314
|
_.has(n.type) && (!e && !n.active || r.push({
|
|
@@ -294,34 +325,34 @@ function C(t, e) {
|
|
|
294
325
|
return r;
|
|
295
326
|
}
|
|
296
327
|
export {
|
|
297
|
-
|
|
328
|
+
R as A,
|
|
298
329
|
G as B,
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
330
|
+
f as C,
|
|
331
|
+
v as S,
|
|
332
|
+
j as a,
|
|
333
|
+
B as b,
|
|
334
|
+
g as c,
|
|
335
|
+
M as d,
|
|
336
|
+
E as e,
|
|
337
|
+
m as f,
|
|
338
|
+
$ as g,
|
|
339
|
+
p as h,
|
|
309
340
|
x as i,
|
|
310
341
|
W as j,
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
342
|
+
O as k,
|
|
343
|
+
Z as l,
|
|
344
|
+
ee as m,
|
|
345
|
+
K as n,
|
|
346
|
+
y as o,
|
|
347
|
+
X as p,
|
|
348
|
+
te as q,
|
|
349
|
+
U as r,
|
|
350
|
+
Q as s,
|
|
351
|
+
V as t,
|
|
352
|
+
J as u,
|
|
353
|
+
Y as v,
|
|
354
|
+
H as w,
|
|
355
|
+
F as x,
|
|
325
356
|
q as y,
|
|
326
|
-
|
|
357
|
+
z
|
|
327
358
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const k=require("ua-parser-js"),v="DASHBOARD",C=5e3;let P=0,f=null;function A(){return`sdk_${Date.now()}_${++P}`}function E(){return"APP_"+Math.random().toString(36).slice(2,10)}function L(t){f=t}function w(){return f||(f=E()),f}function s(t){window.parent.postMessage({...t,sender:w(),target:t.target||v},"*")}function g(t,e,r=C){return h()?new Promise(n=>{const o=A(),i=w(),a=setTimeout(()=>{window.removeEventListener("message",p),n(null)},r);function p(b){const c=b.data;(c==null?void 0:c.type)==="DATA_RESPONSE"&&(c==null?void 0:c.requestId)===o&&(!c.target||c.target===i)&&(clearTimeout(a),window.removeEventListener("message",p),n(c.data??null))}window.addEventListener("message",p),s({type:"DATA_REQUEST",requestId:o,source:t,key:e})}):Promise.resolve(null)}function T(t){s({type:"navigate",path:t})}function I(){s({type:"exit"})}const _=I;function d(t){return g("store",t)}function l(t){return g("localStorage",t)}function D(t){return g("window",t)}function W(){return d("company")}function R(){return d("user")}function U(){return l("token")}function N(){return l("lang")}function $(){return d("productCategories")}function O(t,e){s({type:"setLocalStorage",key:t,value:e})}function M(t){s({type:"setRocketMode",value:t})}function j(t,e){s({type:"trackVisit",name:t,path:e})}function x(t){s({type:"openExternalLink",url:t})}function B(){s({type:"openCrispChat"})}function q(t){s({type:"notification",text:t})}function G(t){s({type:"notification",text:t,variant:"error"})}function V(t){s({type:"notification",text:t,variant:"warn"})}function h(){try{return window.self!==window.top}catch{return!0}}const z=h;function F(t){function e(r){var n;((n=r.data)==null?void 0:n.sender)===v&&t(r.data)}return window.addEventListener("message",e),()=>window.removeEventListener("message",e)}function u(){if(typeof window>"u")return"browser";if(window.webkit!=null&&window.webkit.messageHandlers!==void 0)try{if(k(navigator.userAgent).browser.name==="WebKit")return"ios_webview"}catch(t){console.error(t)}return typeof Android<"u"?"android_webview":typeof window.cefQuery<"u"?"cef_webview":"browser"}function H(){return u()==="ios_webview"}function Q(){return u()==="android_webview"}function J(){return u()==="cef_webview"}function K(){return u()!=="browser"}const Y="https://api.cabinet.developer.skyservice.online/index.php";class m{constructor(e){this.permsCache=null,this.token=e.token,this.companyId=e.companyId,this.appId=e.appId,this.developerId=e.developerId,this.deploymentId=e.deploymentId,this.appName=e.appName;const r=e.domain.replace("dashboard","api");this.baseUrl=r.startsWith("http")?r:`https://${r}`}static create(e){return new m(e)}async get(e){const r=new URLSearchParams({token:this.token,companyId:this.companyId,...e}),n=await fetch(`${this.baseUrl}/?${r}`);if(!n.ok)throw new Error(`Skyservice API error: ${n.status}`);const o=await n.json();if(o.status!=="done")throw new Error(`Skyservice API returned status: ${o.status}`);return o.data}async post(e,r,n){const o=new URLSearchParams({token:this.token,...r}),i=await fetch(`${e}?${o}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!i.ok)throw new Error(`Skyservice API error: ${i.status}`);const a=await i.json();if(a.status!=="done")throw new Error(`Skyservice API returned status: ${a.status}`);return a.data}async getTradepoints(e){const r=await this.get({section:"tradepoints",action:"getTradepoints"});return e!=null&&e.includeDeleted?r.items:r.items.filter(n=>!n.deleted&&!n.frozen)}async getCategoryTree(e){const r=await this.get({section:"productCategory",action:"getCategories",...e?{tradepointId:String(e)}:{}});return S(r,e)}async getProducts(e){const r=await this.get({section:"products",action:"getProducts",pagelimit:"9999",ot:"desc",of:"nomenclatureId",...e!=null&&e.tradepointId?{tradepointId:String(e.tradepointId)}:{}});return ee(r.items,e==null?void 0:e.includeInactive)}async setAppActive({isActive:e,title:r,settings:n}){const o=e?"activateApp":"deactivateApp",i={company_id:this.companyId,app_id:this.appId,...this.developerId!==void 0&&{developer_id:this.developerId},...e&&n!==void 0&&{settings:n}},a=await this.post(Y,{section:"integrations",action:o},i);return this.deploymentId&&this.appName&&typeof window<"u"&&window.self!==window.top&&window.parent.postMessage({type:"sendActiveApp",id:a.id,is_active:e,deploymentId:this.deploymentId,appName:this.appName,title:r},"*"),a}async getPerms(e){const r=await this.loadPerms();return e===void 0?r:!!r[String(e)]}clearPermsCache(){this.permsCache=null}async loadPerms(){var r;if(this.permsCache)return this.permsCache;if(typeof window<"u")try{const n=await d("perms");if(n&&Object.keys(n).length>0)return this.permsCache=y(n),this.permsCache}catch{}const e=await this.get({section:"adminPanel",action:"getStart"});return this.permsCache=y((r=e==null?void 0:e.settings)==null?void 0:r.perms),this.permsCache}}function y(t){const e={};if(!t||typeof t!="object")return e;for(const[r,n]of Object.entries(t))e[r]=!!n;return e}function S(t,e){var n,o;const r=[];for(const i of t){if(e!=null&&!((n=i.tradepointShow)==null?void 0:n[String(e)]))continue;const a={id:i.id,pid:i.pid,name:i.name,active:i.active,background:i.background,show:i.show};i.img&&(a.img=i.img),(o=i.children)!=null&&o.length&&(a.children=S(i.children,e)),r.push(a)}return r}const X=new Set(["product","techcard"]),Z="/img/no.png";function ee(t,e){const r=[];for(const n of t)X.has(n.type)&&(!e&&!n.active||r.push({id:n.id,name:n.nomenclatureName,price:n.price,categoryId:n.categoryId,categoryName:n.categoryTitle||"",active:n.active,type:n.type,unit:n.unit,logo:n.logo&&n.logo!==Z?n.logo:""}));return r}exports.SkyserviceAPI=m;exports.exit=I;exports.getBack=_;exports.getCompany=W;exports.getLang=N;exports.getLocalStorageData=l;exports.getProductCategories=$;exports.getSenderId=w;exports.getStoreData=d;exports.getToken=U;exports.getUser=R;exports.getWindowData=D;exports.isAndroidWebview=Q;exports.isCefWebview=J;exports.isInIframe=z;exports.isInsideIframe=h;exports.isIosWebview=H;exports.isWebview=K;exports.navigate=T;exports.notify=q;exports.notifyError=G;exports.notifyWarn=V;exports.onMessage=F;exports.openCrispChat=B;exports.openExternalLink=x;exports.setLocalStorage=O;exports.setRocketMode=M;exports.setSenderId=L;exports.trackVisit=j;exports.webviewCheck=u;
|
package/dist/sdk/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Tradepoint, Category, Product, AppIntegration } from './types';
|
|
1
|
+
import { Tradepoint, Category, Product, AppIntegration, PermsMap } from './types';
|
|
2
2
|
|
|
3
3
|
export interface SkyserviceAPIConfig {
|
|
4
4
|
token: string;
|
|
@@ -33,6 +33,7 @@ export declare class SkyserviceAPI {
|
|
|
33
33
|
private developerId;
|
|
34
34
|
private deploymentId;
|
|
35
35
|
private appName;
|
|
36
|
+
private permsCache;
|
|
36
37
|
private constructor();
|
|
37
38
|
/** Factory — create a new SkyserviceAPI instance. */
|
|
38
39
|
static create(config: SkyserviceAPIConfig): SkyserviceAPI;
|
|
@@ -83,4 +84,29 @@ export declare class SkyserviceAPI {
|
|
|
83
84
|
title?: string;
|
|
84
85
|
settings?: Record<string, unknown>;
|
|
85
86
|
}): Promise<AppIntegration>;
|
|
87
|
+
/**
|
|
88
|
+
* Get access permissions for the current user.
|
|
89
|
+
*
|
|
90
|
+
* Source priority:
|
|
91
|
+
* 1. Dashboard's Vuex store via iframe bridge (`getStoreData('perms')`) —
|
|
92
|
+
* instant, no token needed, includes Dashboard's computed perms. Used when
|
|
93
|
+
* running inside the Dashboard iframe.
|
|
94
|
+
* 2. HTTP fallback `section=adminPanel&action=getStart` → `data.settings.perms`
|
|
95
|
+
* — used outside the iframe (standalone page, Node) or while the store is
|
|
96
|
+
* still empty.
|
|
97
|
+
*
|
|
98
|
+
* The resolved map is cached on the instance — repeated calls don't re-request.
|
|
99
|
+
* Call {@link clearPermsCache} to force a refetch.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* await api.getPerms('9006') // → boolean — is permission 9006 granted?
|
|
104
|
+
* await api.getPerms() // → { '9006': true, '100': false, ... }
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
getPerms(): Promise<PermsMap>;
|
|
108
|
+
getPerms(code: string | number): Promise<boolean>;
|
|
109
|
+
/** Drop the cached permissions so the next {@link getPerms} call refetches. */
|
|
110
|
+
clearPermsCache(): void;
|
|
111
|
+
private loadPerms;
|
|
86
112
|
}
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { webviewCheck, isIosWebview, isAndroidWebview, isCefWebview, isWebview,
|
|
|
3
3
|
export type { WebviewType } from './webview';
|
|
4
4
|
export { SkyserviceAPI } from './api';
|
|
5
5
|
export type { SkyserviceAPIConfig } from './api';
|
|
6
|
-
export type { Tradepoint, TradepointWorkDay, Category, RawCategory, Product, RawProduct, AppIntegration, } from './types';
|
|
6
|
+
export type { Tradepoint, TradepointWorkDay, Category, RawCategory, Product, RawProduct, AppIntegration, PermsMap, } from './types';
|
package/dist/sdk/types.d.ts
CHANGED
|
@@ -12,6 +12,13 @@ export interface AppIntegration {
|
|
|
12
12
|
created_at: string;
|
|
13
13
|
updated_at: string;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Access permissions map — access-code → granted.
|
|
17
|
+
*
|
|
18
|
+
* Mirrors Dashboard's `store.perms` (e.g. `{ '9006': true, '100': false }`).
|
|
19
|
+
* A missing code means "not granted". Returned by `SkyserviceAPI.getPerms()`.
|
|
20
|
+
*/
|
|
21
|
+
export type PermsMap = Record<string, boolean>;
|
|
15
22
|
export interface Tradepoint {
|
|
16
23
|
tradepointId: number;
|
|
17
24
|
tradepointName: string;
|
package/dist/sdk.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./api-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./api-DAgEQpwF.cjs");exports.SkyserviceAPI=e.SkyserviceAPI;exports.exit=e.exit;exports.getBack=e.getBack;exports.getCompany=e.getCompany;exports.getLang=e.getLang;exports.getLocalStorageData=e.getLocalStorageData;exports.getProductCategories=e.getProductCategories;exports.getSenderId=e.getSenderId;exports.getStoreData=e.getStoreData;exports.getToken=e.getToken;exports.getUser=e.getUser;exports.getWindowData=e.getWindowData;exports.isAndroidWebview=e.isAndroidWebview;exports.isCefWebview=e.isCefWebview;exports.isInIframe=e.isInIframe;exports.isInsideIframe=e.isInsideIframe;exports.isIosWebview=e.isIosWebview;exports.isWebview=e.isWebview;exports.navigate=e.navigate;exports.notify=e.notify;exports.notifyError=e.notifyError;exports.notifyWarn=e.notifyWarn;exports.onMessage=e.onMessage;exports.openCrispChat=e.openCrispChat;exports.openExternalLink=e.openExternalLink;exports.setLocalStorage=e.setLocalStorage;exports.setRocketMode=e.setRocketMode;exports.setSenderId=e.setSenderId;exports.trackVisit=e.trackVisit;exports.webviewCheck=e.webviewCheck;
|
package/dist/sdk.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as s, e as t, g as i, a as o, b as r, c as n, d as g, f as d, h as c, i as f, j as k, k as v, l as w, m as I, n as C, o as S, p as b, q as p, r as y, s as W, t as m, u as l, v as x, w as L, x as h, y as A, z as D, A as u, B, C as E } from "./api-
|
|
1
|
+
import { S as s, e as t, g as i, a as o, b as r, c as n, d as g, f as d, h as c, i as f, j as k, k as v, l as w, m as I, n as C, o as S, p as b, q as p, r as y, s as W, t as m, u as l, v as x, w as L, x as h, y as A, z as D, A as u, B, C as E } from "./api-C6FKIf2t.js";
|
|
2
2
|
export {
|
|
3
3
|
s as SkyserviceAPI,
|
|
4
4
|
t as exit,
|