@one-commerce/sdk-core 1.7.0 → 1.11.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 +943 -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 +954 -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 +289 -121
- 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 +150 -108
- 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 +6 -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 -74
- 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,128 +1,170 @@
|
|
|
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
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
constructor(options) {
|
|
38
|
-
super();
|
|
39
|
-
this.initializeServiceGetters();
|
|
40
|
-
this.origin = options.origin;
|
|
41
|
-
this.channel = new Channel({
|
|
42
|
-
targetOrigin: this.origin,
|
|
43
|
-
target: window.parent,
|
|
44
|
-
});
|
|
45
|
-
this.channel.subscribe(Message.INIT, (payload) => {
|
|
46
|
-
Sdk.log('Handling INIT message');
|
|
47
|
-
Object.entries(this.instances).forEach(([key, value]) => {
|
|
48
|
-
if (value instanceof BaseCallClass) {
|
|
49
|
-
value.update(payload);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
BaseCallClass.update(value, payload[key]);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
Sdk.log('Emitting INIT with payload ', this.instances);
|
|
56
|
-
this.emit(SdkInternalEvents.INIT, this.instances);
|
|
57
|
-
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
|
+
}
|
|
58
39
|
});
|
|
59
|
-
|
|
60
|
-
Sdk.log('Emitting UPDATE with payload ', payload);
|
|
61
|
-
this.emit(SdkInternalEvents.UPDATE, payload);
|
|
62
|
-
});
|
|
63
|
-
this.channel.connect().then(() => {
|
|
64
|
-
Sdk.log('Connected with ONe SDK');
|
|
65
|
-
});
|
|
66
|
-
this.setupOptions(options);
|
|
67
|
-
Sdk.log('Initialized.');
|
|
68
|
-
}
|
|
69
|
-
setupOptions(options) {
|
|
70
|
-
if (options) {
|
|
71
|
-
if (typeof options.debug !== 'undefined') {
|
|
72
|
-
Sdk.debug = options.debug;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
40
|
+
});
|
|
75
41
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
constructor(options) {
|
|
45
|
+
super();
|
|
46
|
+
|
|
47
|
+
_defineProperty(this, "channel", void 0);
|
|
48
|
+
|
|
49
|
+
_defineProperty(this, "origin", void 0);
|
|
50
|
+
|
|
51
|
+
_defineProperty(this, "isInitialized", false);
|
|
52
|
+
|
|
53
|
+
_defineProperty(this, "instances", void 0);
|
|
54
|
+
|
|
55
|
+
this.initializeServiceGetters();
|
|
56
|
+
this.origin = options.origin;
|
|
57
|
+
this.channel = new Channel({
|
|
58
|
+
targetOrigin: this.origin,
|
|
59
|
+
target: window.parent
|
|
60
|
+
});
|
|
61
|
+
this.channel.subscribe(Message.INIT, payload => {
|
|
62
|
+
Sdk.log('Handling INIT message');
|
|
63
|
+
Object.entries(this.instances).forEach(([key, value]) => {
|
|
64
|
+
if (value instanceof BaseCallClass) {
|
|
65
|
+
value.update(payload);
|
|
66
|
+
} else {
|
|
67
|
+
const attributesForKey = payload[key];
|
|
68
|
+
|
|
69
|
+
if (typeof attributesForKey !== 'undefined') {
|
|
70
|
+
BaseCallClass.update(value, payload[key]);
|
|
71
|
+
} else {
|
|
72
|
+
Sdk.warn(`Missing attributes for ${key} in `, payload);
|
|
73
|
+
}
|
|
95
74
|
}
|
|
96
|
-
|
|
97
|
-
|
|
75
|
+
});
|
|
76
|
+
Sdk.log('Emitting INIT with payload ', this.instances);
|
|
77
|
+
this.emit(SdkInternalEvents.INIT, this.instances);
|
|
78
|
+
this.isInitialized = true;
|
|
79
|
+
});
|
|
80
|
+
this.channel.subscribe(Message.UPDATE, payload => {
|
|
81
|
+
Sdk.log('Emitting UPDATE with payload ', payload);
|
|
82
|
+
this.emit(SdkInternalEvents.UPDATE, payload);
|
|
83
|
+
});
|
|
84
|
+
this.channel.connect().then(() => {
|
|
85
|
+
Sdk.log('Connected with ONe SDK');
|
|
86
|
+
});
|
|
87
|
+
this.setupOptions(options);
|
|
88
|
+
Sdk.log('Initialized.');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
setupOptions(options) {
|
|
92
|
+
if (options) {
|
|
93
|
+
if (typeof options.debug !== 'undefined') {
|
|
94
|
+
Sdk.debug = options.debug;
|
|
95
|
+
}
|
|
98
96
|
}
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
callFunction(service, fun, ...payload) {
|
|
100
|
+
const callId = generateCallId();
|
|
101
|
+
|
|
102
|
+
if (this.isInitialized) {
|
|
103
|
+
Sdk.log(`Call ID ${callId} for ${service}:${fun}`, payload);
|
|
104
|
+
this.channel.postMessage(Message.METHOD_CALL, {
|
|
105
|
+
callId,
|
|
106
|
+
service,
|
|
107
|
+
method: fun,
|
|
108
|
+
payload: payload
|
|
109
|
+
});
|
|
110
|
+
return new Promise(resolve => {
|
|
111
|
+
const onChannelMessage = response => {
|
|
112
|
+
if (response.callId === callId) {
|
|
113
|
+
this.channel.unsubscribe(Message.METHOD_RESULT, onChannelMessage);
|
|
114
|
+
return resolve(response.result);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
this.channel.subscribe(Message.METHOD_RESULT, onChannelMessage);
|
|
119
|
+
});
|
|
101
120
|
}
|
|
121
|
+
|
|
122
|
+
Sdk.log('SDK is not initialized!');
|
|
123
|
+
return Promise.resolve(null);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
navigate(event) {
|
|
127
|
+
this.channel.postMessage(Message.NAVIGATION_PUSH, event);
|
|
128
|
+
}
|
|
129
|
+
|
|
102
130
|
}
|
|
131
|
+
|
|
132
|
+
_defineProperty(Sdk, "debug", false);
|
|
133
|
+
|
|
103
134
|
export class BackofficeSdk extends Sdk {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
135
|
+
constructor(...args) {
|
|
136
|
+
super(...args);
|
|
137
|
+
|
|
138
|
+
_defineProperty(this, "instances", {
|
|
139
|
+
route: {
|
|
140
|
+
hash: '',
|
|
141
|
+
query: {}
|
|
142
|
+
},
|
|
143
|
+
orderpath: new BackofficeOrderpath(this.callFunction.bind(this)),
|
|
144
|
+
catalog: new BackofficeCatalog(this.callFunction.bind(this)),
|
|
145
|
+
user: new BackofficeUser(this.callFunction.bind(this)),
|
|
146
|
+
tenant: new BackofficeTenant(this.callFunction.bind(this)),
|
|
147
|
+
layout: new BackofficeLayout(this.callFunction.bind(this))
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
114
151
|
}
|
|
115
152
|
export class ShopSdk extends Sdk {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
153
|
+
constructor(...args) {
|
|
154
|
+
super(...args);
|
|
155
|
+
|
|
156
|
+
_defineProperty(this, "instances", {
|
|
157
|
+
route: {
|
|
158
|
+
hash: '',
|
|
159
|
+
query: {}
|
|
160
|
+
},
|
|
161
|
+
cart: new ShopCart(this.callFunction.bind(this)),
|
|
162
|
+
catalog: new ShopCatalog(this.callFunction.bind(this)),
|
|
163
|
+
account: new ShopAccount(this.callFunction.bind(this)),
|
|
164
|
+
utils: new ShopUtils(this.callFunction.bind(this)),
|
|
165
|
+
config: new ShopConfig(this.callFunction.bind(this))
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
127
169
|
}
|
|
128
|
-
//# sourceMappingURL=
|
|
170
|
+
//# 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","connect","then","setupOptions","callFunction","service","fun","callId","postMessage","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;AAK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AhB,CANC;AAOVO,MAAAA,OAAO,EAAE,IAAI1E,WAAJ,CAAgB,KAAK6C,YAAL,CAAkBsB,IAAlB,CAAuB,IAAvB,CAAhB,CAPC;AAQVQ,MAAAA,KAAK,EAAE,IAAIvE,SAAJ,CAAc,KAAKyC,YAAL,CAAkBsB,IAAlB,CAAuB,IAAvB,CAAd,CARG;AASVS,MAAAA,MAAM,EAAE,IAAIzE,UAAJ,CAAe,KAAK0C,YAAL,CAAkBsB,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 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 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.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 }\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,EAAAA,MAAM,GAAS,CACb;AACD;;AA1CoE;AA6CvE,OAAO,MAAMC,QAAN,SAAuBX,aAAvB,CAA0D;AAAA;AAAA;;AAAA,yCACjD,MADiD;;AAAA;;AAAA;;AAAA;AAAA;;AAM/DY,EAAAA,SAAS,CAACT,SAAD,EAAoBU,MAApB,EAAoCC,KAApC,EAAmDC,MAAnD,EAAmF;AAC1F,WAAO,KAAKX,IAAL,CAAU,WAAV,EAAuBD,SAAvB,EAAkCU,MAAlC,EAA0CC,KAA1C,EAAiDC,MAAjD,CAAP;AACD;;AAR8D;AAWjE,OAAO,MAAMC,SAAN,SAAwBhB,aAAxB,CAA4D;AASjEiB,EAAAA,WAAW,CAACb,IAAD,EAAoE;AAC7E,UAAMA,IAAN;;AAD6E,yCARjE,OAQiE;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAE7E,SAAKc,MAAL,GAAc;AACZC,MAAAA,eAAe,EAAE,KAAKA,eADV;AAEZC,MAAAA,wBAAwB,EAAE,KAAKA,wBAFnB;AAGZC,MAAAA,aAAa,EAAE,KAAKA,aAHR;AAIZC,MAAAA,aAAa,EAAE,KAAKA;AAJR,KAAd;AAMD;;AAEDH,EAAAA,eAAe,CAACI,EAAD,EAAsC;AACnD,WAAO,KAAKnB,IAAL,CAAU,iBAAV,EAA6BmB,EAA7B,CAAP;AACD;;AAEDH,EAAAA,wBAAwB,CAACI,YAAD,EAAwC;AAC9D,WAAO,KAAKpB,IAAL,CAAU,0BAAV,EAAsCoB,YAAtC,CAAP;AACD;;AAEDH,EAAAA,aAAa,CAACI,OAAD,EAAuC;AAClD,WAAO,KAAKrB,IAAL,CAAU,eAAV,EAA2BqB,OAA3B,CAAP;AACD;;AAEDH,EAAAA,aAAa,CAACI,GAAD,EAAgC;AAC3C,WAAO,KAAKtB,IAAL,CAAU,eAAV,EAA2BsB,GAA3B,CAAP;AACD;;AAjCgE;AAuDnE,OAAO,MAAMC,UAAN,SAAyB3B,aAAzB,CAA8D;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"}
|
|
@@ -12,6 +12,12 @@ export declare class BackofficeUser extends BaseCallClass implements Backoffice.
|
|
|
12
12
|
name?: string;
|
|
13
13
|
authorities: Array<string>;
|
|
14
14
|
}
|
|
15
|
+
export declare class BackofficeTenant extends BaseCallClass implements Backoffice.Tenant {
|
|
16
|
+
serviceName: string;
|
|
17
|
+
tenantKey?: string;
|
|
18
|
+
language?: string;
|
|
19
|
+
currency?: string;
|
|
20
|
+
}
|
|
15
21
|
export declare class BackofficeOrderpath extends BaseCallClass implements Backoffice.Orderpath {
|
|
16
22
|
serviceName: string;
|
|
17
23
|
}
|
|
@@ -19,3 +25,4 @@ export declare class BackofficeLayout extends BaseCallClass implements Backoffic
|
|
|
19
25
|
serviceName: string;
|
|
20
26
|
isAsideOpened: boolean;
|
|
21
27
|
}
|
|
28
|
+
//# sourceMappingURL=backofficeServices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backofficeServices.d.ts","sourceRoot":"","sources":["../../src/backofficeServices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAEtC,qBAAa,iBAAkB,SAAQ,aAAc,YAAW,UAAU,CAAC,OAAO;IAChF,WAAW,SAAY;IAEvB,eAAe,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAGnC,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAGlD;AAED,qBAAa,cAAe,SAAQ,aAAc,YAAW,UAAU,CAAC,IAAI;IAC1E,WAAW,SAAS;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,EAAG,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAAG,KAAK,CAAC,MAAM,CAAC,CAAC;CAC7B;AAED,qBAAa,gBAAiB,SAAQ,aAAc,YAAW,UAAU,CAAC,MAAM;IAC9E,WAAW,SAAW;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,mBAAoB,SAAQ,aAAc,YAAW,UAAU,CAAC,SAA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