@one-commerce/sdk-core 1.7.1 → 1.12.0-alpha.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/lib/bundles/bundle.esm.js +962 -0
- package/lib/bundles/bundle.esm.js.map +1 -0
- package/lib/bundles/bundle.esm.min.js +2 -0
- package/lib/bundles/bundle.esm.min.js.map +1 -0
- package/lib/bundles/bundle.umd.js +973 -0
- package/lib/bundles/bundle.umd.js.map +1 -0
- package/lib/bundles/bundle.umd.min.js +2 -0
- package/lib/bundles/bundle.umd.min.js.map +1 -0
- package/lib/cjs/backofficeServices.js +180 -28
- package/lib/cjs/backofficeServices.js.map +1 -0
- package/lib/cjs/events.js +56 -22
- package/lib/cjs/events.js.map +1 -0
- package/lib/cjs/index.js +306 -130
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/shopServices.js +248 -54
- package/lib/cjs/shopServices.js.map +1 -0
- package/lib/cjs/utils.js +63 -28
- package/lib/cjs/utils.js.map +1 -0
- package/lib/esm/backofficeServices.js +59 -16
- package/lib/esm/backofficeServices.js.map +1 -0
- package/lib/esm/events.js +30 -22
- package/lib/esm/events.js.map +1 -0
- package/lib/esm/index.js +165 -117
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/shopServices.js +125 -67
- package/lib/esm/shopServices.js.map +1 -0
- package/lib/esm/utils.js +34 -25
- package/lib/esm/utils.js.map +1 -0
- package/lib/{cjs → types}/backofficeServices.d.ts +7 -0
- package/lib/types/backofficeServices.d.ts.map +1 -0
- package/lib/{cjs → types}/events.d.ts +1 -0
- package/lib/types/events.d.ts.map +1 -0
- package/lib/types/iframe-channel.d.ts +19 -0
- package/lib/{esm → types}/index.d.ts +7 -2
- package/lib/types/index.d.ts.map +1 -0
- package/lib/{esm → types}/shopServices.d.ts +1 -0
- package/lib/types/shopServices.d.ts.map +1 -0
- package/lib/{esm → types}/utils.d.ts +1 -0
- package/lib/types/utils.d.ts.map +1 -0
- package/package.json +42 -16
- package/lib/cjs/index.d.ts +0 -75
- package/lib/cjs/shopServices.d.ts +0 -98
- package/lib/cjs/utils.d.ts +0 -8
- package/lib/esm/backofficeServices.d.ts +0 -21
- package/lib/esm/events.d.ts +0 -7
- package/lib/tsconfig.module.tsbuildinfo +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
package/lib/esm/index.js
CHANGED
|
@@ -1,137 +1,185 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
1
3
|
import { Message } from "@one-commerce/sdk-shared";
|
|
2
4
|
import Channel from "iframe-channel";
|
|
3
|
-
import { BackofficeCatalog, BackofficeLayout, BackofficeOrderpath, BackofficeUser } from "./backofficeServices";
|
|
5
|
+
import { BackofficeCatalog, BackofficeLayout, BackofficeOrderpath, BackofficeTenant, BackofficeUser } from "./backofficeServices";
|
|
4
6
|
import Events from "./events";
|
|
5
|
-
import { ShopAccount, ShopCart, ShopCatalog, ShopConfig, ShopUtils
|
|
7
|
+
import { ShopAccount, ShopCart, ShopCatalog, ShopConfig, ShopUtils } from "./shopServices";
|
|
6
8
|
import { BaseCallClass, generateCallId } from "./utils";
|
|
7
9
|
var SdkInternalEvents;
|
|
10
|
+
|
|
8
11
|
(function (SdkInternalEvents) {
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
SdkInternalEvents["INIT"] = "INIT";
|
|
13
|
+
SdkInternalEvents["UPDATE"] = "UPDATE";
|
|
11
14
|
})(SdkInternalEvents || (SdkInternalEvents = {}));
|
|
12
|
-
|
|
15
|
+
|
|
16
|
+
export let SdkEvents;
|
|
17
|
+
|
|
13
18
|
(function (SdkEvents) {
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
SdkEvents["INIT"] = "INIT";
|
|
20
|
+
SdkEvents["UPDATE"] = "UPDATE";
|
|
16
21
|
})(SdkEvents || (SdkEvents = {}));
|
|
22
|
+
|
|
17
23
|
class Sdk extends Events {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
get: () => {
|
|
34
|
-
return this.isInitialized ? this.instances[serviceName] : null;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
constructor(options) {
|
|
41
|
-
super();
|
|
42
|
-
this.initializeServiceGetters();
|
|
43
|
-
this.origin = options.origin;
|
|
44
|
-
this.channel = new Channel({
|
|
45
|
-
targetOrigin: this.origin,
|
|
46
|
-
target: window.parent,
|
|
47
|
-
});
|
|
48
|
-
this.channel.subscribe(Message.INIT, (payload) => {
|
|
49
|
-
Sdk.log('Handling INIT message');
|
|
50
|
-
Object.entries(this.instances).forEach(([key, value]) => {
|
|
51
|
-
if (value instanceof BaseCallClass) {
|
|
52
|
-
value.update(payload);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
const attributesForKey = payload[key];
|
|
56
|
-
if (typeof attributesForKey !== 'undefined') {
|
|
57
|
-
BaseCallClass.update(value, payload[key]);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
Sdk.warn(`Missing attributes for ${key} in `, payload);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
Sdk.log('Emitting INIT with payload ', this.instances);
|
|
65
|
-
this.emit(SdkInternalEvents.INIT, this.instances);
|
|
66
|
-
this.isInitialized = true;
|
|
24
|
+
static log(...data) {
|
|
25
|
+
Sdk.debug && console.log('[SDK Core] ', ...data);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static warn(...data) {
|
|
29
|
+
console.warn('[SDK Core] ', ...data);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
initializeServiceGetters() {
|
|
33
|
+
if (this.instances) {
|
|
34
|
+
Object.keys(this.instances).forEach(serviceName => {
|
|
35
|
+
Object.defineProperty(this, serviceName, {
|
|
36
|
+
get: () => {
|
|
37
|
+
return this.isInitialized ? this.instances[serviceName] : null;
|
|
38
|
+
}
|
|
67
39
|
});
|
|
68
|
-
|
|
69
|
-
Sdk.log('Emitting UPDATE with payload ', payload);
|
|
70
|
-
this.emit(SdkInternalEvents.UPDATE, payload);
|
|
71
|
-
});
|
|
72
|
-
this.channel.connect().then(() => {
|
|
73
|
-
Sdk.log('Connected with ONe SDK');
|
|
74
|
-
});
|
|
75
|
-
this.setupOptions(options);
|
|
76
|
-
Sdk.log('Initialized.');
|
|
77
|
-
}
|
|
78
|
-
setupOptions(options) {
|
|
79
|
-
if (options) {
|
|
80
|
-
if (typeof options.debug !== 'undefined') {
|
|
81
|
-
Sdk.debug = options.debug;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
40
|
+
});
|
|
84
41
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
constructor(options) {
|
|
45
|
+
super();
|
|
46
|
+
|
|
47
|
+
_defineProperty(this, "channel", void 0);
|
|
48
|
+
|
|
49
|
+
_defineProperty(this, "autoheight", true);
|
|
50
|
+
|
|
51
|
+
_defineProperty(this, "origin", void 0);
|
|
52
|
+
|
|
53
|
+
_defineProperty(this, "isInitialized", false);
|
|
54
|
+
|
|
55
|
+
_defineProperty(this, "instances", void 0);
|
|
56
|
+
|
|
57
|
+
this.initializeServiceGetters();
|
|
58
|
+
this.origin = options.origin;
|
|
59
|
+
this.channel = new Channel({
|
|
60
|
+
targetOrigin: this.origin,
|
|
61
|
+
target: window.parent
|
|
62
|
+
});
|
|
63
|
+
this.channel.subscribe(Message.INIT, payload => {
|
|
64
|
+
Sdk.log('Handling INIT message');
|
|
65
|
+
Object.entries(this.instances).forEach(([key, value]) => {
|
|
66
|
+
if (value instanceof BaseCallClass) {
|
|
67
|
+
value.update(payload);
|
|
68
|
+
} else {
|
|
69
|
+
const attributesForKey = payload[key];
|
|
70
|
+
|
|
71
|
+
if (typeof attributesForKey !== 'undefined') {
|
|
72
|
+
BaseCallClass.update(value, payload[key]);
|
|
73
|
+
} else {
|
|
74
|
+
Sdk.warn(`Missing attributes for ${key} in `, payload);
|
|
75
|
+
}
|
|
104
76
|
}
|
|
105
|
-
|
|
106
|
-
|
|
77
|
+
});
|
|
78
|
+
Sdk.log('Emitting INIT with payload ', this.instances);
|
|
79
|
+
this.emit(SdkInternalEvents.INIT, this.instances);
|
|
80
|
+
this.isInitialized = true;
|
|
81
|
+
});
|
|
82
|
+
this.channel.subscribe(Message.UPDATE, payload => {
|
|
83
|
+
Sdk.log('Emitting UPDATE with payload ', payload);
|
|
84
|
+
this.emit(SdkInternalEvents.UPDATE, payload);
|
|
85
|
+
});
|
|
86
|
+
this.channel.subscribe(Message.FRAME_HEIGHT_REQUEST, payload => {
|
|
87
|
+
if (this.autoheight) {
|
|
88
|
+
Sdk.log('Request for iframe height');
|
|
89
|
+
const body = document.body,
|
|
90
|
+
html = document.documentElement;
|
|
91
|
+
const height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
|
|
92
|
+
this.channel.postMessage(Message.FRAME_HEIGHT_CHANGE, height);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
this.channel.connect().then(() => {
|
|
96
|
+
Sdk.log('Connected with ONe SDK');
|
|
97
|
+
});
|
|
98
|
+
this.setupOptions(options);
|
|
99
|
+
Sdk.log('Initialized.');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
setupOptions(options) {
|
|
103
|
+
if (options) {
|
|
104
|
+
if (typeof options.debug !== 'undefined') {
|
|
105
|
+
Sdk.debug = options.debug;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (typeof options.autoheight !== 'undefined') {
|
|
109
|
+
this.autoheight = options.autoheight;
|
|
110
|
+
}
|
|
107
111
|
}
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
callFunction(service, fun, ...payload) {
|
|
115
|
+
const callId = generateCallId();
|
|
116
|
+
|
|
117
|
+
if (this.isInitialized) {
|
|
118
|
+
Sdk.log(`Call ID ${callId} for ${service}:${fun}`, payload);
|
|
119
|
+
this.channel.postMessage(Message.METHOD_CALL, {
|
|
120
|
+
callId,
|
|
121
|
+
service,
|
|
122
|
+
method: fun,
|
|
123
|
+
payload: payload
|
|
124
|
+
});
|
|
125
|
+
return new Promise(resolve => {
|
|
126
|
+
const onChannelMessage = response => {
|
|
127
|
+
if (response.callId === callId) {
|
|
128
|
+
this.channel.unsubscribe(Message.METHOD_RESULT, onChannelMessage);
|
|
129
|
+
return resolve(response.result);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
this.channel.subscribe(Message.METHOD_RESULT, onChannelMessage);
|
|
134
|
+
});
|
|
110
135
|
}
|
|
136
|
+
|
|
137
|
+
Sdk.log('SDK is not initialized!');
|
|
138
|
+
return Promise.resolve(null);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
navigate(event) {
|
|
142
|
+
this.channel.postMessage(Message.NAVIGATION_PUSH, event);
|
|
143
|
+
}
|
|
144
|
+
|
|
111
145
|
}
|
|
146
|
+
|
|
147
|
+
_defineProperty(Sdk, "debug", false);
|
|
148
|
+
|
|
112
149
|
export class BackofficeSdk extends Sdk {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
150
|
+
constructor(...args) {
|
|
151
|
+
super(...args);
|
|
152
|
+
|
|
153
|
+
_defineProperty(this, "instances", {
|
|
154
|
+
route: {
|
|
155
|
+
hash: '',
|
|
156
|
+
query: {}
|
|
157
|
+
},
|
|
158
|
+
orderpath: new BackofficeOrderpath(this.callFunction.bind(this)),
|
|
159
|
+
catalog: new BackofficeCatalog(this.callFunction.bind(this)),
|
|
160
|
+
user: new BackofficeUser(this.callFunction.bind(this)),
|
|
161
|
+
tenant: new BackofficeTenant(this.callFunction.bind(this)),
|
|
162
|
+
layout: new BackofficeLayout(this.callFunction.bind(this))
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
123
166
|
}
|
|
124
167
|
export class ShopSdk extends Sdk {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
168
|
+
constructor(...args) {
|
|
169
|
+
super(...args);
|
|
170
|
+
|
|
171
|
+
_defineProperty(this, "instances", {
|
|
172
|
+
route: {
|
|
173
|
+
hash: '',
|
|
174
|
+
query: {}
|
|
175
|
+
},
|
|
176
|
+
cart: new ShopCart(this.callFunction.bind(this)),
|
|
177
|
+
catalog: new ShopCatalog(this.callFunction.bind(this)),
|
|
178
|
+
account: new ShopAccount(this.callFunction.bind(this)),
|
|
179
|
+
utils: new ShopUtils(this.callFunction.bind(this)),
|
|
180
|
+
config: new ShopConfig(this.callFunction.bind(this))
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
136
184
|
}
|
|
137
|
-
//# sourceMappingURL=
|
|
185
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":["Message","Channel","BackofficeCatalog","BackofficeLayout","BackofficeOrderpath","BackofficeTenant","BackofficeUser","Events","ShopAccount","ShopCart","ShopCatalog","ShopConfig","ShopUtils","BaseCallClass","generateCallId","SdkInternalEvents","SdkEvents","Sdk","log","data","debug","console","warn","initializeServiceGetters","instances","Object","keys","forEach","serviceName","defineProperty","get","isInitialized","constructor","options","origin","channel","targetOrigin","target","window","parent","subscribe","INIT","payload","entries","key","value","update","attributesForKey","emit","UPDATE","FRAME_HEIGHT_REQUEST","autoheight","body","document","html","documentElement","height","Math","max","scrollHeight","offsetHeight","clientHeight","postMessage","FRAME_HEIGHT_CHANGE","connect","then","setupOptions","callFunction","service","fun","callId","METHOD_CALL","method","Promise","resolve","onChannelMessage","response","unsubscribe","METHOD_RESULT","result","navigate","event","NAVIGATION_PUSH","BackofficeSdk","route","hash","query","orderpath","bind","catalog","user","tenant","layout","ShopSdk","cart","account","utils","config"],"mappings":";;AAAA,SAAoBA,OAApB,QAA+C,0BAA/C;AACA,OAAOC,OAAP,MAAoB,gBAApB;AAEA,SACEC,iBADF,EAEEC,gBAFF,EAGEC,mBAHF,EAIEC,gBAJF,EAKEC,cALF,QAMO,sBANP;AAOA,OAAOC,MAAP,MAAmB,UAAnB;AACA,SACEC,WADF,EAEEC,QAFF,EAGEC,WAHF,EAGeC,UAHf,EAG2BC,SAH3B,QAIO,gBAJP;AAKA,SAASC,aAAT,EAAwBC,cAAxB,QAA8C,SAA9C;IAEKC,iB;;WAAAA,iB;AAAAA,EAAAA,iB;AAAAA,EAAAA,iB;GAAAA,iB,KAAAA,iB;;AAIL,WAAYC,SAAZ;;WAAYA,S;AAAAA,EAAAA,S;AAAAA,EAAAA,S;GAAAA,S,KAAAA,S;;AAoBZ,MAAeC,GAAf,SAA8BV,MAA9B,CAAqC;AAQjB,SAAHW,GAAG,CAAC,GAAGC,IAAJ,EAAiB;AACjCF,IAAAA,GAAG,CAACG,KAAJ,IAAaC,OAAO,CAACH,GAAR,CAAY,aAAZ,EAA2B,GAAGC,IAA9B,CAAb;AACD;;AAEkB,SAAJG,IAAI,CAAC,GAAGH,I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ELC,QAAAA,KAAK,EAAE;AAFF,OADG;AAKVQ,MAAAA,IAAI,EAAE,IAAIrF,QAAJ,CAAa,KAAK0D,YAAL,CAAkBqB,IAAlB,CAAuB,IAAvB,CAAb,CALI;AAMVC,MAAAA,OAAO,EAAE,IAAI/E,WAAJ,CAAgB,KAAKyD,YAAL,CAAkBqB,IAAlB,CAAuB,IAAvB,CAAhB,CANC;AAOVO,MAAAA,OAAO,EAAE,IAAIvF,WAAJ,CAAgB,KAAK2D,YAAL,CAAkBqB,IAAlB,CAAuB,IAAvB,CAAhB,CAPC;AAQVQ,MAAAA,KAAK,EAAE,IAAIpF,SAAJ,CAAc,KAAKuD,YAAL,CAAkBqB,IAAlB,CAAuB,IAAvB,CAAd,CARG;AASVS,MAAAA,MAAM,EAAE,IAAItF,UAAJ,CAAe,KAAKwD,YAAL,CAAkBqB,IAAlB,CAAuB,IAAvB,CAAf;AATE,KADkC;AAAA;;AAAA","sourcesContent":["import {Backoffice, Message, Route, Shop} from \"@one-commerce/sdk-shared\";\nimport Channel from \"iframe-channel\"\n\nimport {\n BackofficeCatalog,\n BackofficeLayout,\n BackofficeOrderpath,\n BackofficeTenant,\n BackofficeUser\n} from \"./backofficeServices\";\nimport Events from \"./events\";\nimport {\n ShopAccount,\n ShopCart,\n ShopCatalog, ShopConfig, ShopUtils,\n} from \"./shopServices\";\nimport { BaseCallClass, generateCallId } from \"./utils\";\n\nenum SdkInternalEvents {\n INIT='INIT',\n UPDATE='UPDATE'\n}\nexport enum SdkEvents {\n INIT='INIT',\n UPDATE='UPDATE',\n}\nexport interface SdkOptions {\n debug?: boolean\n autoheight?: boolean\n origin: string\n}\n\ninterface NamedNavigationPayload {\n name: string\n params: any\n}\n\ninterface PathNavigationPayload {\n path: string\n params: any\n}\n\nabstract class Sdk<T> extends Events {\n private channel!: Channel;\n private static debug = false\n private autoheight = true\n origin: string;\n isInitialized = false\n instances!: T;\n\n private static log(...data: any[]) {\n Sdk.debug && console.log('[SDK Core] ', ...data)\n }\n\n private static warn(...data: any[]) {\n console.warn('[SDK Core] ', ...data)\n }\n\n private initializeServiceGetters(): void {\n if (this.instances) {\n Object.keys(this.instances).forEach((serviceName: string) => {\n Object.defineProperty(this, serviceName, {\n get: () => {\n return this.isInitialized ? this.instances![serviceName as keyof T] : null\n }\n })\n })\n }\n }\n\n constructor(options: SdkOptions) {\n super()\n this.initializeServiceGetters()\n this.origin = options.origin\n this.channel = new Channel({\n targetOrigin: this.origin,\n target: window.parent,\n })\n this.channel.subscribe(Message.INIT, (payload: any) => {\n Sdk.log('Handling INIT message')\n Object.entries(this.instances!).forEach(([key, value]: [key: string, value: BaseCallClass | Record<string, any>]) => {\n if (value instanceof BaseCallClass) {\n value.update(payload)\n } else {\n const attributesForKey = payload[key]\n if (typeof attributesForKey !== 'undefined') {\n BaseCallClass.update(value as Record<string, any>, payload[key])\n } else {\n Sdk.warn(`Missing attributes for ${key} in `, payload)\n }\n }\n })\n Sdk.log('Emitting INIT with payload ', this.instances)\n this.emit(SdkInternalEvents.INIT, this.instances)\n this.isInitialized = true\n })\n this.channel.subscribe(Message.UPDATE, (payload: any) => {\n Sdk.log('Emitting UPDATE with payload ', payload)\n this.emit(SdkInternalEvents.UPDATE, payload)\n })\n this.channel.subscribe(Message.FRAME_HEIGHT_REQUEST, (payload: any) => {\n if (this.autoheight) {\n Sdk.log('Request for iframe height')\n const body = document.body, html = document.documentElement;\n const height = Math.max(body.scrollHeight, body.offsetHeight,\n html.clientHeight, html.scrollHeight, html.offsetHeight);\n this.channel.postMessage(Message.FRAME_HEIGHT_CHANGE, height)\n }\n })\n this.channel.connect().then(() => {\n Sdk.log('Connected with ONe SDK')\n })\n this.setupOptions(options)\n Sdk.log('Initialized.')\n }\n\n private setupOptions(options?: SdkOptions) {\n if (options) {\n if (typeof options.debug !== 'undefined') {\n Sdk.debug = options.debug\n }\n if (typeof options.autoheight !== 'undefined') {\n this.autoheight = options.autoheight\n }\n }\n }\n protected callFunction(service: string, fun: string, ...payload: any) {\n const callId: string = generateCallId()\n if (this.isInitialized) {\n Sdk.log(`Call ID ${callId} for ${service}:${fun}`, payload)\n this.channel.postMessage(Message.METHOD_CALL, {\n callId,\n service,\n method: fun,\n payload: payload,\n })\n return new Promise((resolve) => {\n const onChannelMessage = (response: any) => {\n if (response.callId === callId) {\n this.channel.unsubscribe(Message.METHOD_RESULT, onChannelMessage)\n return resolve(response.result)\n }\n }\n this.channel.subscribe(Message.METHOD_RESULT, onChannelMessage)\n })\n }\n Sdk.log('SDK is not initialized!')\n return Promise.resolve(null)\n }\n\n public navigate(event: NamedNavigationPayload | PathNavigationPayload) {\n this.channel.postMessage(Message.NAVIGATION_PUSH, event)\n }\n\n}\n\nexport interface BackofficeInstances extends Backoffice.Api {\n route: Route,\n orderpath: BackofficeOrderpath,\n catalog: BackofficeCatalog,\n user: BackofficeUser,\n tenant: BackofficeTenant,\n layout: BackofficeLayout\n}\n\nexport interface ShopInstances extends Shop.Api {\n route: Route,\n cart: ShopCart,\n catalog: ShopCatalog,\n account: ShopAccount,\n utils: ShopUtils\n config: ShopConfig\n}\n\nexport class BackofficeSdk extends Sdk<BackofficeInstances> {\n instances = {\n route: {\n hash: '',\n query: {},\n },\n orderpath: new BackofficeOrderpath(this.callFunction.bind(this)),\n catalog: new BackofficeCatalog(this.callFunction.bind(this)),\n user: new BackofficeUser(this.callFunction.bind(this)),\n tenant: new BackofficeTenant(this.callFunction.bind(this)),\n layout: new BackofficeLayout(this.callFunction.bind(this))\n }\n}\n\nexport class ShopSdk extends Sdk<ShopInstances> {\n instances = {\n route: {\n hash: '',\n query: {},\n },\n cart: new ShopCart(this.callFunction.bind(this)),\n catalog: new ShopCatalog(this.callFunction.bind(this)),\n account: new ShopAccount(this.callFunction.bind(this)),\n utils: new ShopUtils(this.callFunction.bind(this)),\n config: new ShopConfig(this.callFunction.bind(this))\n }\n}\n"],"file":"index.js"}
|
package/lib/esm/shopServices.js
CHANGED
|
@@ -1,78 +1,136 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
1
3
|
import { BaseCallClass } from "./utils";
|
|
2
4
|
export class ShopCatalog extends BaseCallClass {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
constructor(...args) {
|
|
6
|
+
super(...args);
|
|
7
|
+
|
|
8
|
+
_defineProperty(this, "serviceName", 'catalog');
|
|
9
|
+
|
|
10
|
+
_defineProperty(this, "categories", void 0);
|
|
11
|
+
|
|
12
|
+
_defineProperty(this, "selectedCategoryId", void 0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
fetchProduct(productId) {
|
|
16
|
+
return this.call('fetchProduct', productId);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getCategoryById(categoryId) {
|
|
20
|
+
return this.call('getCategoryById', categoryId);
|
|
21
|
+
}
|
|
22
|
+
|
|
12
23
|
}
|
|
13
24
|
export class ShopAccount extends BaseCallClass {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
constructor(...args) {
|
|
26
|
+
super(...args);
|
|
27
|
+
|
|
28
|
+
_defineProperty(this, "serviceName", 'account');
|
|
29
|
+
|
|
30
|
+
_defineProperty(this, "client", void 0);
|
|
31
|
+
|
|
32
|
+
_defineProperty(this, "isAuthenticated", void 0);
|
|
33
|
+
|
|
34
|
+
_defineProperty(this, "user", void 0);
|
|
35
|
+
|
|
36
|
+
_defineProperty(this, "manager", void 0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
hasSegment(name) {
|
|
40
|
+
return this.call('hasSegment', name);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
logout() {// NotImplementedYet
|
|
44
|
+
}
|
|
45
|
+
|
|
25
46
|
}
|
|
26
47
|
export class ShopCart extends BaseCallClass {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
48
|
+
constructor(...args) {
|
|
49
|
+
super(...args);
|
|
50
|
+
|
|
51
|
+
_defineProperty(this, "serviceName", 'cart');
|
|
52
|
+
|
|
53
|
+
_defineProperty(this, "carts", void 0);
|
|
54
|
+
|
|
55
|
+
_defineProperty(this, "currentCart", void 0);
|
|
56
|
+
|
|
57
|
+
_defineProperty(this, "totalCartPrice", void 0);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
addToCart(productId, amount, where, cartId) {
|
|
61
|
+
return this.call('addToCart', productId, amount, where, cartId);
|
|
62
|
+
}
|
|
63
|
+
|
|
34
64
|
}
|
|
35
65
|
export class ShopUtils extends BaseCallClass {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
constructor(call) {
|
|
67
|
+
super(call);
|
|
68
|
+
|
|
69
|
+
_defineProperty(this, "serviceName", 'utils');
|
|
70
|
+
|
|
71
|
+
_defineProperty(this, "currency", void 0);
|
|
72
|
+
|
|
73
|
+
_defineProperty(this, "isAnonymousAndPurchaseDisabled", void 0);
|
|
74
|
+
|
|
75
|
+
_defineProperty(this, "isB2B", void 0);
|
|
76
|
+
|
|
77
|
+
_defineProperty(this, "isB2BAndPlatformIsNotOpened", void 0);
|
|
78
|
+
|
|
79
|
+
_defineProperty(this, "isIndexPage", void 0);
|
|
80
|
+
|
|
81
|
+
_defineProperty(this, "isPurchaseEnabledOrAuthenticated", void 0);
|
|
82
|
+
|
|
83
|
+
_defineProperty(this, "routes", void 0);
|
|
84
|
+
|
|
85
|
+
this.routes = {
|
|
86
|
+
getCategoryPath: this.getCategoryPath,
|
|
87
|
+
getManufacturerSearchUrl: this.getManufacturerSearchUrl,
|
|
88
|
+
getProductUrl: this.getProductUrl,
|
|
89
|
+
isExternalUrl: this.isExternalUrl
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getCategoryPath(id) {
|
|
94
|
+
return this.call('getCategoryPath', id);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getManufacturerSearchUrl(manufacturer) {
|
|
98
|
+
return this.call('getManufacturerSearchUrl', manufacturer);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getProductUrl(product) {
|
|
102
|
+
return this.call('getProductUrl', product);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
isExternalUrl(url) {
|
|
106
|
+
return this.call('isExternalUrl', url);
|
|
107
|
+
}
|
|
108
|
+
|
|
65
109
|
}
|
|
66
110
|
export class ShopConfig extends BaseCallClass {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
111
|
+
constructor(...args) {
|
|
112
|
+
super(...args);
|
|
113
|
+
|
|
114
|
+
_defineProperty(this, "serviceName", 'config');
|
|
115
|
+
|
|
116
|
+
_defineProperty(this, "accessMode", void 0);
|
|
117
|
+
|
|
118
|
+
_defineProperty(this, "isB2CRegistrationEnabled", void 0);
|
|
119
|
+
|
|
120
|
+
_defineProperty(this, "isCatalogOpened", void 0);
|
|
121
|
+
|
|
122
|
+
_defineProperty(this, "isGrossSelected", void 0);
|
|
123
|
+
|
|
124
|
+
_defineProperty(this, "isPlatformClosed", void 0);
|
|
125
|
+
|
|
126
|
+
_defineProperty(this, "isPlatformOpened", void 0);
|
|
127
|
+
|
|
128
|
+
_defineProperty(this, "isPurchaseEnabled", void 0);
|
|
129
|
+
|
|
130
|
+
_defineProperty(this, "isRegistrationEnabled", void 0);
|
|
131
|
+
|
|
132
|
+
_defineProperty(this, "currency", void 0);
|
|
133
|
+
}
|
|
134
|
+
|
|
77
135
|
}
|
|
78
|
-
//# sourceMappingURL=
|
|
136
|
+
//# sourceMappingURL=shopServices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shopServices.ts"],"names":["BaseCallClass","ShopCatalog","fetchProduct","productId","call","getCategoryById","categoryId","ShopAccount","hasSegment","name","logout","ShopCart","addToCart","amount","where","cartId","ShopUtils","constructor","routes","getCategoryPath","getManufacturerSearchUrl","getProductUrl","isExternalUrl","id","manufacturer","product","url","ShopConfig"],"mappings":";;AAEA,SAAQA,aAAR,QAA4B,SAA5B;AAEA,OAAO,MAAMC,WAAN,SAA0BD,aAA1B,CAAgE;AAAA;AAAA;;AAAA,yCACvD,SADuD;;AAAA;;AAAA;AAAA;;AAKrEE,EAAAA,YAAY,CAACC,SAAD,EAAkC;AAC5C,WAAO,KAAKC,IAAL,CAAU,cAAV,EAA0BD,SAA1B,CAAP;AACD;;AAEDE,EAAAA,eAAe,CAACC,UAAD,EAAmC;AAChD,WAAO,KAAKF,IAAL,CAAU,iBAAV,EAA6BE,UAA7B,CAAP;AACD;;AAXoE;AAgBvE,OAAO,MAAMC,WAAN,SAA0BP,aAA1B,CAAgE;AAAA;AAAA;;AAAA,yCACvD,SADuD;;AAAA;;AAAA;;AAAA;;AAAA;AAAA;;AA2BrEQ,EAAAA,UAAU,CAACC,IAAD,EAAiC;AACzC,WAAO,KAAKL,IAAL,CAAU,YAAV,EAAwBK,IAAxB,CAAP;AACD;;AAWDC,EAA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8D;AAAA;AAAA;;AAAA,yCACrD,QADqD;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;AAAA;;AAAA","sourcesContent":["import {Shop} from \"@one-commerce/sdk-shared\";\n\nimport {BaseCallClass} from \"./utils\";\n\nexport class ShopCatalog extends BaseCallClass implements Shop.Catalog {\n serviceName = 'catalog'\n categories!: Array<any>;\n selectedCategoryId!: string | null;\n\n fetchProduct(productId: string): Promise<any> {\n return this.call('fetchProduct', productId)\n }\n\n getCategoryById(categoryId: string): Promise<any> {\n return this.call('getCategoryById', categoryId)\n }\n\n\n}\n\nexport class ShopAccount extends BaseCallClass implements Shop.Account {\n serviceName = 'account'\n client!: {\n name: string;\n billingAddress?: {\n city: string;\n country: string;\n id: string;\n isDefault: boolean;\n name: string;\n phone: string;\n street: string;\n type: string;\n zipCode: string\n }\n };\n isAuthenticated!: boolean;\n user!: {\n email?: string;\n name?: string;\n phone?: string;\n /**\n * @deprecated Use non-nested function instead\n */\n hasSegment(name: string): Promise<boolean>\n };\n\n hasSegment(name: string): Promise<boolean> {\n return this.call('hasSegment', name)\n }\n\n manager!: {\n additionalEmail?: string;\n email: string; id: string;\n landlinePhone?: string;\n mobilePhone?: string;\n name: string;\n photo?: string\n };\n\n logout(): void {\n // NotImplementedYet\n }\n}\n\nexport class ShopCart extends BaseCallClass implements Shop.Cart {\n serviceName = 'cart'\n carts!: Array<any>;\n currentCart!: any;\n totalCartPrice!: number;\n\n addToCart(productId: string, amount: number, where: string, cartId?: string): Promise<void> {\n return this.call('addToCart', productId, amount, where, cartId)\n }\n}\n\nexport class ShopUtils extends BaseCallClass implements Shop.Utils {\n serviceName = 'utils'\n currency!: any;\n isAnonymousAndPurchaseDisabled!: boolean;\n isB2B!: boolean;\n isB2BAndPlatformIsNotOpened!: boolean;\n isIndexPage!: boolean;\n isPurchaseEnabledOrAuthenticated!: boolean;\n\n constructor(call: (service: string, fun: string, ...arg: any) => Promise<any>) {\n super(call)\n this.routes = {\n getCategoryPath: this.getCategoryPath,\n getManufacturerSearchUrl: this.getManufacturerSearchUrl,\n getProductUrl: this.getProductUrl,\n isExternalUrl: this.isExternalUrl\n }\n }\n\n getCategoryPath(id?: string): Promise<string | null> {\n return this.call('getCategoryPath', id)\n }\n\n getManufacturerSearchUrl(manufacturer: string): Promise<string> {\n return this.call('getManufacturerSearchUrl', manufacturer)\n }\n\n getProductUrl(product: any): Promise<string | null> {\n return this.call('getProductUrl', product)\n }\n\n isExternalUrl(url: string): Promise<boolean> {\n return this.call('isExternalUrl', url)\n }\n\n routes: {\n /**\n * @deprecated Use non-nested function instead\n */\n getCategoryPath(id?: string): (Promise<string | null> | string | null);\n /**\n * @deprecated Use non-nested function instead\n */\n getManufacturerSearchUrl(manufacturer: string): (Promise<string> | string);\n /**\n * @deprecated Use non-nested function instead\n */\n getProductUrl(product: any): (Promise<string | null> | string | null);\n /**\n * @deprecated Use non-nested function instead\n */\n isExternalUrl(url: string): (Promise<boolean> | boolean)\n };\n}\n\nexport class ShopConfig extends BaseCallClass implements Shop.Config {\n serviceName = 'config'\n accessMode!: string;\n isB2CRegistrationEnabled!: boolean;\n isCatalogOpened!: boolean;\n isGrossSelected!: boolean;\n isPlatformClosed!: boolean;\n isPlatformOpened!: boolean;\n isPurchaseEnabled!: boolean;\n isRegistrationEnabled!: boolean;\n currency: any;\n}\n"],"file":"shopServices.js"}
|
package/lib/esm/utils.js
CHANGED
|
@@ -1,30 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
const dec2hex = dec => {
|
|
4
|
+
return dec.toString(16).padStart(2, "0");
|
|
5
|
+
}; // generateId :: Integer -> String
|
|
6
|
+
|
|
7
|
+
|
|
5
8
|
export function generateCallId() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
const arr = new Uint8Array((10 || 40) / 2);
|
|
10
|
+
window.crypto.getRandomValues(arr);
|
|
11
|
+
return Array.from(arr, dec2hex).join('');
|
|
9
12
|
}
|
|
10
13
|
export class BaseCallClass {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
constructor(call) {
|
|
15
|
+
_defineProperty(this, "serviceName", '');
|
|
16
|
+
|
|
17
|
+
_defineProperty(this, "call", void 0);
|
|
18
|
+
|
|
19
|
+
this.call = (fun, ...arg) => {
|
|
20
|
+
return call(this.serviceName, fun, ...arg);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static update(target, payload) {
|
|
25
|
+
Object.keys(payload).forEach(key => {
|
|
26
|
+
target[key] = payload[key];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
update(payload) {
|
|
31
|
+
const attributes = payload[this.serviceName];
|
|
32
|
+
|
|
33
|
+
if (attributes) {
|
|
34
|
+
BaseCallClass.update(this, attributes);
|
|
28
35
|
}
|
|
36
|
+
}
|
|
37
|
+
|
|
29
38
|
}
|
|
30
|
-
//# sourceMappingURL=
|
|
39
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"names":["dec2hex","dec","toString","padStart","generateCallId","arr","Uint8Array","window","crypto","getRandomValues","Array","from","join","BaseCallClass","constructor","call","fun","arg","serviceName","update","target","payload","Object","keys","forEach","key","attributes"],"mappings":";;AAAA,MAAMA,OAAO,GAAKC,GAAD,IAAyB;AACxC,SAAOA,GAAG,CAACC,QAAJ,CAAa,EAAb,EAAiBC,QAAjB,CAA0B,CAA1B,EAA6B,GAA7B,CAAP;AACD,CAFD,C,CAIA;;;AACA,OAAO,SAASC,cAAT,GAA2B;AAChC,QAAMC,GAAG,GAAG,IAAIC,UAAJ,CAAe,CAAC,MAAM,EAAP,IAAa,CAA5B,CAAZ;AACAC,EAAAA,MAAM,CAACC,MAAP,CAAcC,eAAd,CAA8BJ,GAA9B;AACA,SAAOK,KAAK,CAACC,IAAN,CAAWN,GAAX,EAAgBL,OAAhB,EAAyBY,IAAzB,CAA8B,EAA9B,CAAP;AACD;AAED,OAAO,MAAMC,aAAN,CAAoB;AAGzBC,EAAAA,WAAW,CAACC,IAAD,EAAoE;AAAA,yCAFjE,EAEiE;;AAAA;;AAC7E,SAAKA,IAAL,GAAY,CAACC,GAAD,EAAc,GAAGC,GAAjB,KAA8B;AACxC,aAAOF,IAAI,CAAC,KAAKG,WAAN,EAAmBF,GAAnB,EAAwB,GAAGC,GAA3B,CAAX;AACD,KAFD;AAGD;;AACY,SAANE,MAAM,CAACC,MAAD,EAA8BC,OAA9B,EAA4D;AACvEC,IAAAA,MAAM,CAACC,IAAP,CAAYF,OAAZ,EAAqBG,OAArB,CAA8BC,GAAD,IAAiB;AAC5CL,MAAAA,MAAM,CAACK,GAAD,CAAN,GAAcJ,OAAO,CAACI,GAAD,CAArB;AACD,KAFD;AAGD;;AACDN,EAAAA,MAAM,CAACE,OAAD,EAAe;AACnB,UAAMK,UAAe,GAAGL,OAAO,CAAC,KAAKH,WAAN,CAA/B;;AACA,QAAIQ,UAAJ,EAAgB;AACdb,MAAAA,aAAa,CAACM,MAAd,CAAqB,IAArB,EAA2BO,UAA3B;AACD;AACF;;AAlBwB","sourcesContent":["const dec2hex = (dec: number): string => {\n return dec.toString(16).padStart(2, \"0\")\n}\n\n// generateId :: Integer -> String\nexport function generateCallId () {\n const arr = new Uint8Array((10 || 40) / 2)\n window.crypto.getRandomValues(arr)\n return Array.from(arr, dec2hex).join('')\n}\n\nexport class BaseCallClass {\n serviceName = ''\n call: (fun: string, ...arg: any[]) => Promise<any>;\n constructor(call: (service: string, fun: string, ...arg: any) => Promise<any>) {\n this.call = (fun: string, ...arg: any) => {\n return call(this.serviceName, fun, ...arg)\n }\n }\n static update(target: Record<string, any>, payload: Record<string, any>) {\n Object.keys(payload).forEach((key: string) => {\n target[key] = payload[key]\n })\n }\n update(payload: any) {\n const attributes: any = payload[this.serviceName]\n if (attributes) {\n BaseCallClass.update(this, attributes)\n }\n }\n}\n"],"file":"utils.js"}
|