skyservice-sdk 0.2.0 → 0.3.0
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/skyservice-sdk.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`DASHBOARD`,t=5e3,n=0;function r(){return`sdk_${Date.now()}_${++n}`}function i(e){window.parent.postMessage(e,`*`)}function a(n,a,o=t){return new Promise((t,s)=>{let c=r(),l=setTimeout(()=>{window.removeEventListener(`message`,u),s(Error(`[skyservice-sdk] Request timed out: ${n}.${a}`))},o);function u(e){let{type:n,requestId:r,data:i}=e.data||{};n!==`DATA_RESPONSE`||r!==c||(clearTimeout(l),window.removeEventListener(`message`,u),t(i))}window.addEventListener(`message`,u),i({type:`DATA_REQUEST`,requestId:c,source:n,key:a,target:e})})}function o(t){i({type:`navigate`,path:t,target:e})}function s(){i({type:`exit`,target:e})}var c=s;function l(e){return a(`store`,e)}function u(e){return a(`localStorage`,e)}function d(e){return a(`window`,e)}function f(){return l(`company`)}function p(){return l(`user`)}function m(){return u(`token`)}function h(){return u(`lang`)}function g(){return l(`productCategories`)}function _(t,n){i({type:`setLocalStorage`,key:t,value:n,target:e})}function v(t){i({type:`setRocketMode`,value:t,target:e})}function y(t,n){i({type:`trackVisit`,name:t,path:n,target:e})}function b(t){i({type:`openExternalLink`,url:t,target:e})}function x(){i({type:`openCrispChat`,target:e})}function S(t){i({type:`notification`,text:t,target:e})}function C(t){i({type:`notification`,text:t,variant:`error`,target:e})}function w(t){i({type:`notification`,text:t,variant:`warn`,target:e})}function T(){return window.self!==window.top}function E(t){function n(n){n.data?.sender===e&&t(n.data)}return window.addEventListener(`message`,n),()=>window.removeEventListener(`message`,n)}var D=class{constructor(e){this.token=e.token,this.companyId=e.companyId;let t=e.domain.replace(`dashboard`,`api`);this.baseUrl=t.startsWith(`http`)?t:`https://${t}`}async request(e){let t=new URLSearchParams({token:this.token,...this.companyId?{companyId:this.companyId}:{},...e}),n=await fetch(`${this.baseUrl}/?${t}`);if(!n.ok)throw Error(`Skyservice API error: ${n.status}`);let r=await n.json();if(r.status!==`done`)throw Error(`Skyservice API returned status: ${r.status}`);return r.data}async getTradepoints(e){let t=await this.request({section:`tradepoints`,action:`getTradepoints`});return e?.includeDeleted?t.items:t.items.filter(e=>!e.deleted&&!e.frozen)}async getCategoryTree(e){return O(await this.request({section:`productCategory`,action:`getCategories`,...e?{tradepointId:String(e)}:{}}),e)}};function O(e,t){let n=[];for(let r of e){if(t!=null&&!r.tradepointShow?.[String(t)])continue;let e={id:r.id,pid:r.pid,name:r.name,active:r.active,background:r.background,show:r.show};r.img&&(e.img=r.img),r.children?.length&&(e.children=O(r.children,t)),n.push(e)}return n}exports.SkyserviceAPI=D,exports.exit=s,exports.getBack=c,exports.getCompany=f,exports.getLang=h,exports.getLocalStorageData=u,exports.getProductCategories=g,exports.getStoreData=l,exports.getToken=m,exports.getUser=p,exports.getWindowData=d,exports.isInsideIframe=T,exports.navigate=o,exports.notify=S,exports.notifyError=C,exports.notifyWarn=w,exports.onMessage=E,exports.openCrispChat=x,exports.openExternalLink=b,exports.setLocalStorage=_,exports.setRocketMode=v,exports.trackVisit=y;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`DASHBOARD`,t=5e3,n=0;function r(){return`sdk_${Date.now()}_${++n}`}function i(e){window.parent.postMessage(e,`*`)}function a(n,a,o=t){return new Promise((t,s)=>{let c=r(),l=setTimeout(()=>{window.removeEventListener(`message`,u),s(Error(`[skyservice-sdk] Request timed out: ${n}.${a}`))},o);function u(e){let{type:n,requestId:r,data:i}=e.data||{};n!==`DATA_RESPONSE`||r!==c||(clearTimeout(l),window.removeEventListener(`message`,u),t(i))}window.addEventListener(`message`,u),i({type:`DATA_REQUEST`,requestId:c,source:n,key:a,target:e})})}function o(t){i({type:`navigate`,path:t,target:e})}function s(){i({type:`exit`,target:e})}var c=s;function l(e){return a(`store`,e)}function u(e){return a(`localStorage`,e)}function d(e){return a(`window`,e)}function f(){return l(`company`)}function p(){return l(`user`)}function m(){return u(`token`)}function h(){return u(`lang`)}function g(){return l(`productCategories`)}function _(t,n){i({type:`setLocalStorage`,key:t,value:n,target:e})}function v(t){i({type:`setRocketMode`,value:t,target:e})}function y(t,n){i({type:`trackVisit`,name:t,path:n,target:e})}function b(t){i({type:`openExternalLink`,url:t,target:e})}function x(){i({type:`openCrispChat`,target:e})}function S(t){i({type:`notification`,text:t,target:e})}function C(t){i({type:`notification`,text:t,variant:`error`,target:e})}function w(t){i({type:`notification`,text:t,variant:`warn`,target:e})}function T(){return window.self!==window.top}function E(t){function n(n){n.data?.sender===e&&t(n.data)}return window.addEventListener(`message`,n),()=>window.removeEventListener(`message`,n)}var D=class{constructor(e){this.token=e.token,this.companyId=e.companyId;let t=e.domain.replace(`dashboard`,`api`);this.baseUrl=t.startsWith(`http`)?t:`https://${t}`}async request(e){let t=new URLSearchParams({token:this.token,...this.companyId?{companyId:this.companyId}:{},...e}),n=await fetch(`${this.baseUrl}/?${t}`);if(!n.ok)throw Error(`Skyservice API error: ${n.status}`);let r=await n.json();if(r.status!==`done`)throw Error(`Skyservice API returned status: ${r.status}`);return r.data}async getTradepoints(e){let t=await this.request({section:`tradepoints`,action:`getTradepoints`});return e?.includeDeleted?t.items:t.items.filter(e=>!e.deleted&&!e.frozen)}async getCategoryTree(e){return O(await this.request({section:`productCategory`,action:`getCategories`,...e?{tradepointId:String(e)}:{}}),e)}async getProducts(e){return j((await this.request({section:`products`,action:`getProducts`,pagelimit:`9999`,ot:`desc`,of:`nomenclatureId`,...e?.tradepointId?{tradepointId:String(e.tradepointId)}:{}})).items,e?.includeInactive)}};function O(e,t){let n=[];for(let r of e){if(t!=null&&!r.tradepointShow?.[String(t)])continue;let e={id:r.id,pid:r.pid,name:r.name,active:r.active,background:r.background,show:r.show};r.img&&(e.img=r.img),r.children?.length&&(e.children=O(r.children,t)),n.push(e)}return n}var k=new Set([`product`,`techcard`]),A=`/img/no.png`;function j(e,t){let n=[];for(let r of e)k.has(r.type)&&(!t&&!r.active||n.push({id:r.id,name:r.nomenclatureName,price:r.price,categoryId:r.categoryId,categoryName:r.categoryTitle||``,active:r.active,type:r.type,unit:r.unit,logo:r.logo&&r.logo!==A?r.logo:``}));return n}exports.SkyserviceAPI=D,exports.exit=s,exports.getBack=c,exports.getCompany=f,exports.getLang=h,exports.getLocalStorageData=u,exports.getProductCategories=g,exports.getStoreData=l,exports.getToken=m,exports.getUser=p,exports.getWindowData=d,exports.isInsideIframe=T,exports.navigate=o,exports.notify=S,exports.notifyError=C,exports.notifyWarn=w,exports.onMessage=E,exports.openCrispChat=x,exports.openExternalLink=b,exports.setLocalStorage=_,exports.setRocketMode=v,exports.trackVisit=y;
|
package/dist/skyservice-sdk.d.ts
CHANGED
|
@@ -58,6 +58,18 @@ export declare function openCrispChat(): void;
|
|
|
58
58
|
/** Open an external link (handles webview bridges) */
|
|
59
59
|
export declare function openExternalLink(url: string): void;
|
|
60
60
|
|
|
61
|
+
export declare interface Product {
|
|
62
|
+
id: number;
|
|
63
|
+
name: string;
|
|
64
|
+
price: number;
|
|
65
|
+
categoryId: number | null;
|
|
66
|
+
categoryName: string;
|
|
67
|
+
active: 0 | 1;
|
|
68
|
+
type: 'product' | 'techcard';
|
|
69
|
+
unit: string;
|
|
70
|
+
logo: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
61
73
|
/**
|
|
62
74
|
* Raw category from Skyservice API — includes per-tradepoint visibility.
|
|
63
75
|
* Stripped down to `Category` by SkyserviceAPI methods.
|
|
@@ -68,6 +80,30 @@ export declare interface RawCategory extends Category {
|
|
|
68
80
|
children?: RawCategory[];
|
|
69
81
|
}
|
|
70
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Raw product from Skyservice API — includes POS-specific fields.
|
|
85
|
+
* Stripped down to `Product` by SkyserviceAPI methods.
|
|
86
|
+
*/
|
|
87
|
+
export declare interface RawProduct {
|
|
88
|
+
id: number;
|
|
89
|
+
nomenclatureName: string;
|
|
90
|
+
nomenclatureCode: string;
|
|
91
|
+
nomenclatureId: number;
|
|
92
|
+
price: number;
|
|
93
|
+
categoryId: number | null;
|
|
94
|
+
categoryTitle: string;
|
|
95
|
+
active: 0 | 1;
|
|
96
|
+
defaultActive: 0 | 1;
|
|
97
|
+
type: string;
|
|
98
|
+
unit: string;
|
|
99
|
+
weight: number;
|
|
100
|
+
logo: string;
|
|
101
|
+
background: string;
|
|
102
|
+
workshopId: number;
|
|
103
|
+
activeProductAppearance: 0 | 1;
|
|
104
|
+
[key: string]: unknown;
|
|
105
|
+
}
|
|
106
|
+
|
|
71
107
|
/** Set a key in Dashboard's localStorage */
|
|
72
108
|
export declare function setLocalStorage(key: string, value: unknown): void;
|
|
73
109
|
|
|
@@ -108,6 +144,18 @@ export declare class SkyserviceAPI {
|
|
|
108
144
|
* If `tradepointId` is provided, filters to categories visible for that tradepoint.
|
|
109
145
|
*/
|
|
110
146
|
getCategoryTree(tradepointId?: number): Promise<Category[]>;
|
|
147
|
+
/**
|
|
148
|
+
* Get products, cleaned from POS-specific fields.
|
|
149
|
+
*
|
|
150
|
+
* Filters out ingredients by default — returns only sellable items
|
|
151
|
+
* (type `product` or `techcard`).
|
|
152
|
+
*
|
|
153
|
+
* If `tradepointId` is provided, scopes to that tradepoint.
|
|
154
|
+
*/
|
|
155
|
+
getProducts(options?: {
|
|
156
|
+
tradepointId?: number;
|
|
157
|
+
includeInactive?: boolean;
|
|
158
|
+
}): Promise<Product[]>;
|
|
111
159
|
}
|
|
112
160
|
|
|
113
161
|
export declare interface SkyserviceAPIConfig {
|
package/dist/skyservice-sdk.js
CHANGED
|
@@ -163,6 +163,16 @@ var D = class {
|
|
|
163
163
|
...e ? { tradepointId: String(e) } : {}
|
|
164
164
|
}), e);
|
|
165
165
|
}
|
|
166
|
+
async getProducts(e) {
|
|
167
|
+
return j((await this.request({
|
|
168
|
+
section: "products",
|
|
169
|
+
action: "getProducts",
|
|
170
|
+
pagelimit: "9999",
|
|
171
|
+
ot: "desc",
|
|
172
|
+
of: "nomenclatureId",
|
|
173
|
+
...e?.tradepointId ? { tradepointId: String(e.tradepointId) } : {}
|
|
174
|
+
})).items, e?.includeInactive);
|
|
175
|
+
}
|
|
166
176
|
};
|
|
167
177
|
function O(e, t) {
|
|
168
178
|
let n = [];
|
|
@@ -180,5 +190,21 @@ function O(e, t) {
|
|
|
180
190
|
}
|
|
181
191
|
return n;
|
|
182
192
|
}
|
|
193
|
+
var k = new Set(["product", "techcard"]), A = "/img/no.png";
|
|
194
|
+
function j(e, t) {
|
|
195
|
+
let n = [];
|
|
196
|
+
for (let r of e) k.has(r.type) && (!t && !r.active || n.push({
|
|
197
|
+
id: r.id,
|
|
198
|
+
name: r.nomenclatureName,
|
|
199
|
+
price: r.price,
|
|
200
|
+
categoryId: r.categoryId,
|
|
201
|
+
categoryName: r.categoryTitle || "",
|
|
202
|
+
active: r.active,
|
|
203
|
+
type: r.type,
|
|
204
|
+
unit: r.unit,
|
|
205
|
+
logo: r.logo && r.logo !== A ? r.logo : ""
|
|
206
|
+
}));
|
|
207
|
+
return n;
|
|
208
|
+
}
|
|
183
209
|
//#endregion
|
|
184
210
|
export { D as SkyserviceAPI, s as exit, c as getBack, f as getCompany, h as getLang, u as getLocalStorageData, g as getProductCategories, l as getStoreData, m as getToken, p as getUser, d as getWindowData, T as isInsideIframe, o as navigate, S as notify, C as notifyError, w as notifyWarn, E as onMessage, x as openCrispChat, b as openExternalLink, _ as setLocalStorage, v as setRocketMode, y as trackVisit };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.SkyserviceSDK={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=`DASHBOARD`,n=5e3,r=0;function i(){return`sdk_${Date.now()}_${++r}`}function a(e){window.parent.postMessage(e,`*`)}function o(e,r,o=n){return new Promise((n,s)=>{let c=i(),l=setTimeout(()=>{window.removeEventListener(`message`,u),s(Error(`[skyservice-sdk] Request timed out: ${e}.${r}`))},o);function u(e){let{type:t,requestId:r,data:i}=e.data||{};t!==`DATA_RESPONSE`||r!==c||(clearTimeout(l),window.removeEventListener(`message`,u),n(i))}window.addEventListener(`message`,u),a({type:`DATA_REQUEST`,requestId:c,source:e,key:r,target:t})})}function s(e){a({type:`navigate`,path:e,target:t})}function c(){a({type:`exit`,target:t})}var l=c;function u(e){return o(`store`,e)}function d(e){return o(`localStorage`,e)}function f(e){return o(`window`,e)}function p(){return u(`company`)}function m(){return u(`user`)}function h(){return d(`token`)}function g(){return d(`lang`)}function _(){return u(`productCategories`)}function v(e,n){a({type:`setLocalStorage`,key:e,value:n,target:t})}function y(e){a({type:`setRocketMode`,value:e,target:t})}function b(e,n){a({type:`trackVisit`,name:e,path:n,target:t})}function x(e){a({type:`openExternalLink`,url:e,target:t})}function S(){a({type:`openCrispChat`,target:t})}function C(e){a({type:`notification`,text:e,target:t})}function w(e){a({type:`notification`,text:e,variant:`error`,target:t})}function T(e){a({type:`notification`,text:e,variant:`warn`,target:t})}function E(){return window.self!==window.top}function D(e){function n(n){n.data?.sender===t&&e(n.data)}return window.addEventListener(`message`,n),()=>window.removeEventListener(`message`,n)}var O=class{constructor(e){this.token=e.token,this.companyId=e.companyId;let t=e.domain.replace(`dashboard`,`api`);this.baseUrl=t.startsWith(`http`)?t:`https://${t}`}async request(e){let t=new URLSearchParams({token:this.token,...this.companyId?{companyId:this.companyId}:{},...e}),n=await fetch(`${this.baseUrl}/?${t}`);if(!n.ok)throw Error(`Skyservice API error: ${n.status}`);let r=await n.json();if(r.status!==`done`)throw Error(`Skyservice API returned status: ${r.status}`);return r.data}async getTradepoints(e){let t=await this.request({section:`tradepoints`,action:`getTradepoints`});return e?.includeDeleted?t.items:t.items.filter(e=>!e.deleted&&!e.frozen)}async getCategoryTree(e){return k(await this.request({section:`productCategory`,action:`getCategories`,...e?{tradepointId:String(e)}:{}}),e)}};function k(e,t){let n=[];for(let r of e){if(t!=null&&!r.tradepointShow?.[String(t)])continue;let e={id:r.id,pid:r.pid,name:r.name,active:r.active,background:r.background,show:r.show};r.img&&(e.img=r.img),r.children?.length&&(e.children=k(r.children,t)),n.push(e)}return n}e.SkyserviceAPI=O,e.exit=c,e.getBack=l,e.getCompany=p,e.getLang=g,e.getLocalStorageData=d,e.getProductCategories=_,e.getStoreData=u,e.getToken=h,e.getUser=m,e.getWindowData=f,e.isInsideIframe=E,e.navigate=s,e.notify=C,e.notifyError=w,e.notifyWarn=T,e.onMessage=D,e.openCrispChat=S,e.openExternalLink=x,e.setLocalStorage=v,e.setRocketMode=y,e.trackVisit=b});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.SkyserviceSDK={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=`DASHBOARD`,n=5e3,r=0;function i(){return`sdk_${Date.now()}_${++r}`}function a(e){window.parent.postMessage(e,`*`)}function o(e,r,o=n){return new Promise((n,s)=>{let c=i(),l=setTimeout(()=>{window.removeEventListener(`message`,u),s(Error(`[skyservice-sdk] Request timed out: ${e}.${r}`))},o);function u(e){let{type:t,requestId:r,data:i}=e.data||{};t!==`DATA_RESPONSE`||r!==c||(clearTimeout(l),window.removeEventListener(`message`,u),n(i))}window.addEventListener(`message`,u),a({type:`DATA_REQUEST`,requestId:c,source:e,key:r,target:t})})}function s(e){a({type:`navigate`,path:e,target:t})}function c(){a({type:`exit`,target:t})}var l=c;function u(e){return o(`store`,e)}function d(e){return o(`localStorage`,e)}function f(e){return o(`window`,e)}function p(){return u(`company`)}function m(){return u(`user`)}function h(){return d(`token`)}function g(){return d(`lang`)}function _(){return u(`productCategories`)}function v(e,n){a({type:`setLocalStorage`,key:e,value:n,target:t})}function y(e){a({type:`setRocketMode`,value:e,target:t})}function b(e,n){a({type:`trackVisit`,name:e,path:n,target:t})}function x(e){a({type:`openExternalLink`,url:e,target:t})}function S(){a({type:`openCrispChat`,target:t})}function C(e){a({type:`notification`,text:e,target:t})}function w(e){a({type:`notification`,text:e,variant:`error`,target:t})}function T(e){a({type:`notification`,text:e,variant:`warn`,target:t})}function E(){return window.self!==window.top}function D(e){function n(n){n.data?.sender===t&&e(n.data)}return window.addEventListener(`message`,n),()=>window.removeEventListener(`message`,n)}var O=class{constructor(e){this.token=e.token,this.companyId=e.companyId;let t=e.domain.replace(`dashboard`,`api`);this.baseUrl=t.startsWith(`http`)?t:`https://${t}`}async request(e){let t=new URLSearchParams({token:this.token,...this.companyId?{companyId:this.companyId}:{},...e}),n=await fetch(`${this.baseUrl}/?${t}`);if(!n.ok)throw Error(`Skyservice API error: ${n.status}`);let r=await n.json();if(r.status!==`done`)throw Error(`Skyservice API returned status: ${r.status}`);return r.data}async getTradepoints(e){let t=await this.request({section:`tradepoints`,action:`getTradepoints`});return e?.includeDeleted?t.items:t.items.filter(e=>!e.deleted&&!e.frozen)}async getCategoryTree(e){return k(await this.request({section:`productCategory`,action:`getCategories`,...e?{tradepointId:String(e)}:{}}),e)}async getProducts(e){return M((await this.request({section:`products`,action:`getProducts`,pagelimit:`9999`,ot:`desc`,of:`nomenclatureId`,...e?.tradepointId?{tradepointId:String(e.tradepointId)}:{}})).items,e?.includeInactive)}};function k(e,t){let n=[];for(let r of e){if(t!=null&&!r.tradepointShow?.[String(t)])continue;let e={id:r.id,pid:r.pid,name:r.name,active:r.active,background:r.background,show:r.show};r.img&&(e.img=r.img),r.children?.length&&(e.children=k(r.children,t)),n.push(e)}return n}var A=new Set([`product`,`techcard`]),j=`/img/no.png`;function M(e,t){let n=[];for(let r of e)A.has(r.type)&&(!t&&!r.active||n.push({id:r.id,name:r.nomenclatureName,price:r.price,categoryId:r.categoryId,categoryName:r.categoryTitle||``,active:r.active,type:r.type,unit:r.unit,logo:r.logo&&r.logo!==j?r.logo:``}));return n}e.SkyserviceAPI=O,e.exit=c,e.getBack=l,e.getCompany=p,e.getLang=g,e.getLocalStorageData=d,e.getProductCategories=_,e.getStoreData=u,e.getToken=h,e.getUser=m,e.getWindowData=f,e.isInsideIframe=E,e.navigate=s,e.notify=C,e.notifyError=w,e.notifyWarn=T,e.onMessage=D,e.openCrispChat=S,e.openExternalLink=x,e.setLocalStorage=v,e.setRocketMode=y,e.trackVisit=b});
|