@one-commerce/sdk-core 1.18.0-alpha.0 → 1.18.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 +155 -181
- package/lib/bundles/bundle.esm.js.map +1 -1
- package/lib/bundles/bundle.esm.min.js +1 -1
- package/lib/bundles/bundle.esm.min.js.map +1 -1
- package/lib/bundles/bundle.umd.js +155 -181
- package/lib/bundles/bundle.umd.js.map +1 -1
- package/lib/bundles/bundle.umd.min.js +1 -1
- package/lib/bundles/bundle.umd.min.js.map +1 -1
- package/lib/cjs/backofficeServices.js +40 -115
- package/lib/cjs/backofficeServices.js.map +1 -1
- package/lib/cjs/index.js +8 -5
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/shopServices.js +113 -70
- package/lib/cjs/shopServices.js.map +1 -1
- package/lib/esm/backofficeServices.js +0 -34
- package/lib/esm/backofficeServices.js.map +1 -1
- package/lib/esm/index.js +11 -7
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/shopServices.js +20 -0
- package/lib/esm/shopServices.js.map +1 -1
- package/lib/types/backofficeServices.d.ts +0 -12
- package/lib/types/backofficeServices.d.ts.map +1 -1
- package/lib/types/index.d.ts +4 -6
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shopServices.d.ts +6 -0
- package/lib/types/shopServices.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -5,7 +5,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.BackofficeUser = exports.BackofficeTenant = exports.BackofficePlugin = exports.
|
|
8
|
+
exports.BackofficeUser = exports.BackofficeTenant = exports.BackofficePlugin = exports.BackofficeLayout = exports.BackofficeCustomer = exports.BackofficeCatalog = exports.BackofficeAuthorization = void 0;
|
|
9
9
|
|
|
10
10
|
var _utils = require("./utils");
|
|
11
11
|
|
|
@@ -135,15 +135,15 @@ var BackofficeTenant = /*#__PURE__*/function (_BaseCallClass3) {
|
|
|
135
135
|
|
|
136
136
|
exports.BackofficeTenant = BackofficeTenant;
|
|
137
137
|
|
|
138
|
-
var
|
|
139
|
-
_inherits(
|
|
138
|
+
var BackofficeLayout = /*#__PURE__*/function (_BaseCallClass4) {
|
|
139
|
+
_inherits(BackofficeLayout, _BaseCallClass4);
|
|
140
140
|
|
|
141
|
-
var _super4 = _createSuper(
|
|
141
|
+
var _super4 = _createSuper(BackofficeLayout);
|
|
142
142
|
|
|
143
|
-
function
|
|
143
|
+
function BackofficeLayout() {
|
|
144
144
|
var _this4;
|
|
145
145
|
|
|
146
|
-
_classCallCheck(this,
|
|
146
|
+
_classCallCheck(this, BackofficeLayout);
|
|
147
147
|
|
|
148
148
|
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
149
149
|
args[_key4] = arguments[_key4];
|
|
@@ -151,25 +151,27 @@ var BackofficeOrderpath = /*#__PURE__*/function (_BaseCallClass4) {
|
|
|
151
151
|
|
|
152
152
|
_this4 = _super4.call.apply(_super4, [this].concat(args));
|
|
153
153
|
|
|
154
|
-
_defineProperty(_assertThisInitialized(_this4), "serviceName", '
|
|
154
|
+
_defineProperty(_assertThisInitialized(_this4), "serviceName", 'layout');
|
|
155
|
+
|
|
156
|
+
_defineProperty(_assertThisInitialized(_this4), "isAsideOpened", void 0);
|
|
155
157
|
|
|
156
158
|
return _this4;
|
|
157
159
|
}
|
|
158
160
|
|
|
159
|
-
return _createClass(
|
|
161
|
+
return _createClass(BackofficeLayout);
|
|
160
162
|
}(_utils.BaseCallClass);
|
|
161
163
|
|
|
162
|
-
exports.
|
|
164
|
+
exports.BackofficeLayout = BackofficeLayout;
|
|
163
165
|
|
|
164
|
-
var
|
|
165
|
-
_inherits(
|
|
166
|
+
var BackofficeAuthorization = /*#__PURE__*/function (_BaseCallClass5) {
|
|
167
|
+
_inherits(BackofficeAuthorization, _BaseCallClass5);
|
|
166
168
|
|
|
167
|
-
var _super5 = _createSuper(
|
|
169
|
+
var _super5 = _createSuper(BackofficeAuthorization);
|
|
168
170
|
|
|
169
|
-
function
|
|
171
|
+
function BackofficeAuthorization() {
|
|
170
172
|
var _this5;
|
|
171
173
|
|
|
172
|
-
_classCallCheck(this,
|
|
174
|
+
_classCallCheck(this, BackofficeAuthorization);
|
|
173
175
|
|
|
174
176
|
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
175
177
|
args[_key5] = arguments[_key5];
|
|
@@ -177,39 +179,11 @@ var BackofficeLayout = /*#__PURE__*/function (_BaseCallClass5) {
|
|
|
177
179
|
|
|
178
180
|
_this5 = _super5.call.apply(_super5, [this].concat(args));
|
|
179
181
|
|
|
180
|
-
_defineProperty(_assertThisInitialized(_this5), "serviceName", '
|
|
181
|
-
|
|
182
|
-
_defineProperty(_assertThisInitialized(_this5), "isAsideOpened", void 0);
|
|
182
|
+
_defineProperty(_assertThisInitialized(_this5), "serviceName", 'authorization');
|
|
183
183
|
|
|
184
184
|
return _this5;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
return _createClass(BackofficeLayout);
|
|
188
|
-
}(_utils.BaseCallClass);
|
|
189
|
-
|
|
190
|
-
exports.BackofficeLayout = BackofficeLayout;
|
|
191
|
-
|
|
192
|
-
var BackofficeAuthorization = /*#__PURE__*/function (_BaseCallClass6) {
|
|
193
|
-
_inherits(BackofficeAuthorization, _BaseCallClass6);
|
|
194
|
-
|
|
195
|
-
var _super6 = _createSuper(BackofficeAuthorization);
|
|
196
|
-
|
|
197
|
-
function BackofficeAuthorization() {
|
|
198
|
-
var _this6;
|
|
199
|
-
|
|
200
|
-
_classCallCheck(this, BackofficeAuthorization);
|
|
201
|
-
|
|
202
|
-
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
203
|
-
args[_key6] = arguments[_key6];
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
_this6 = _super6.call.apply(_super6, [this].concat(args));
|
|
207
|
-
|
|
208
|
-
_defineProperty(_assertThisInitialized(_this6), "serviceName", 'authorization');
|
|
209
|
-
|
|
210
|
-
return _this6;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
187
|
_createClass(BackofficeAuthorization, [{
|
|
214
188
|
key: "getAuthToken",
|
|
215
189
|
value: function getAuthToken() {
|
|
@@ -222,29 +196,29 @@ var BackofficeAuthorization = /*#__PURE__*/function (_BaseCallClass6) {
|
|
|
222
196
|
|
|
223
197
|
exports.BackofficeAuthorization = BackofficeAuthorization;
|
|
224
198
|
|
|
225
|
-
var BackofficeCustomer = /*#__PURE__*/function (
|
|
226
|
-
_inherits(BackofficeCustomer,
|
|
199
|
+
var BackofficeCustomer = /*#__PURE__*/function (_BaseCallClass6) {
|
|
200
|
+
_inherits(BackofficeCustomer, _BaseCallClass6);
|
|
227
201
|
|
|
228
|
-
var
|
|
202
|
+
var _super6 = _createSuper(BackofficeCustomer);
|
|
229
203
|
|
|
230
204
|
function BackofficeCustomer() {
|
|
231
|
-
var
|
|
205
|
+
var _this6;
|
|
232
206
|
|
|
233
207
|
_classCallCheck(this, BackofficeCustomer);
|
|
234
208
|
|
|
235
|
-
for (var
|
|
236
|
-
args[
|
|
209
|
+
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
210
|
+
args[_key6] = arguments[_key6];
|
|
237
211
|
}
|
|
238
212
|
|
|
239
|
-
|
|
213
|
+
_this6 = _super6.call.apply(_super6, [this].concat(args));
|
|
240
214
|
|
|
241
|
-
_defineProperty(_assertThisInitialized(
|
|
215
|
+
_defineProperty(_assertThisInitialized(_this6), "serviceName", 'customer');
|
|
242
216
|
|
|
243
|
-
_defineProperty(_assertThisInitialized(
|
|
217
|
+
_defineProperty(_assertThisInitialized(_this6), "id", void 0);
|
|
244
218
|
|
|
245
|
-
_defineProperty(_assertThisInitialized(
|
|
219
|
+
_defineProperty(_assertThisInitialized(_this6), "name", void 0);
|
|
246
220
|
|
|
247
|
-
return
|
|
221
|
+
return _this6;
|
|
248
222
|
}
|
|
249
223
|
|
|
250
224
|
return _createClass(BackofficeCustomer);
|
|
@@ -252,84 +226,35 @@ var BackofficeCustomer = /*#__PURE__*/function (_BaseCallClass7) {
|
|
|
252
226
|
|
|
253
227
|
exports.BackofficeCustomer = BackofficeCustomer;
|
|
254
228
|
|
|
255
|
-
var BackofficePlugin = /*#__PURE__*/function (
|
|
256
|
-
_inherits(BackofficePlugin,
|
|
229
|
+
var BackofficePlugin = /*#__PURE__*/function (_BaseCallClass7) {
|
|
230
|
+
_inherits(BackofficePlugin, _BaseCallClass7);
|
|
257
231
|
|
|
258
|
-
var
|
|
232
|
+
var _super7 = _createSuper(BackofficePlugin);
|
|
259
233
|
|
|
260
234
|
function BackofficePlugin() {
|
|
261
|
-
var
|
|
235
|
+
var _this7;
|
|
262
236
|
|
|
263
237
|
_classCallCheck(this, BackofficePlugin);
|
|
264
238
|
|
|
265
|
-
for (var
|
|
266
|
-
args[
|
|
239
|
+
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
240
|
+
args[_key7] = arguments[_key7];
|
|
267
241
|
}
|
|
268
242
|
|
|
269
|
-
|
|
243
|
+
_this7 = _super7.call.apply(_super7, [this].concat(args));
|
|
270
244
|
|
|
271
|
-
_defineProperty(_assertThisInitialized(
|
|
245
|
+
_defineProperty(_assertThisInitialized(_this7), "serviceName", 'plugin');
|
|
272
246
|
|
|
273
|
-
_defineProperty(_assertThisInitialized(
|
|
247
|
+
_defineProperty(_assertThisInitialized(_this7), "id", void 0);
|
|
274
248
|
|
|
275
|
-
_defineProperty(_assertThisInitialized(
|
|
249
|
+
_defineProperty(_assertThisInitialized(_this7), "srcUrl", void 0);
|
|
276
250
|
|
|
277
|
-
_defineProperty(_assertThisInitialized(
|
|
251
|
+
_defineProperty(_assertThisInitialized(_this7), "name", void 0);
|
|
278
252
|
|
|
279
|
-
return
|
|
253
|
+
return _this7;
|
|
280
254
|
}
|
|
281
255
|
|
|
282
256
|
return _createClass(BackofficePlugin);
|
|
283
257
|
}(_utils.BaseCallClass);
|
|
284
258
|
|
|
285
259
|
exports.BackofficePlugin = BackofficePlugin;
|
|
286
|
-
|
|
287
|
-
var BackofficeAddToCartContext = /*#__PURE__*/function (_BaseCallClass9) {
|
|
288
|
-
_inherits(BackofficeAddToCartContext, _BaseCallClass9);
|
|
289
|
-
|
|
290
|
-
var _super9 = _createSuper(BackofficeAddToCartContext);
|
|
291
|
-
|
|
292
|
-
function BackofficeAddToCartContext() {
|
|
293
|
-
var _this9;
|
|
294
|
-
|
|
295
|
-
_classCallCheck(this, BackofficeAddToCartContext);
|
|
296
|
-
|
|
297
|
-
for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
|
|
298
|
-
args[_key9] = arguments[_key9];
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
_this9 = _super9.call.apply(_super9, [this].concat(args));
|
|
302
|
-
|
|
303
|
-
_defineProperty(_assertThisInitialized(_this9), "serviceName", 'addToCartContext');
|
|
304
|
-
|
|
305
|
-
_defineProperty(_assertThisInitialized(_this9), "productId", void 0);
|
|
306
|
-
|
|
307
|
-
_defineProperty(_assertThisInitialized(_this9), "cartId", void 0);
|
|
308
|
-
|
|
309
|
-
_defineProperty(_assertThisInitialized(_this9), "warehouses", void 0);
|
|
310
|
-
|
|
311
|
-
return _this9;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
_createClass(BackofficeAddToCartContext, [{
|
|
315
|
-
key: "closePlugin",
|
|
316
|
-
value: function closePlugin() {
|
|
317
|
-
this.call('closePlugin');
|
|
318
|
-
}
|
|
319
|
-
}, {
|
|
320
|
-
key: "closePluginAndAddToCart",
|
|
321
|
-
value: function closePluginAndAddToCart() {
|
|
322
|
-
this.call('closePluginAndAddToCart');
|
|
323
|
-
}
|
|
324
|
-
}, {
|
|
325
|
-
key: "closePluginAndRefreshCart",
|
|
326
|
-
value: function closePluginAndRefreshCart() {
|
|
327
|
-
this.call('closePluginAndRefreshCart');
|
|
328
|
-
}
|
|
329
|
-
}]);
|
|
330
|
-
|
|
331
|
-
return BackofficeAddToCartContext;
|
|
332
|
-
}(_utils.BaseCallClass);
|
|
333
|
-
|
|
334
|
-
exports.BackofficeAddToCartContext = BackofficeAddToCartContext;
|
|
335
260
|
//# sourceMappingURL=backofficeServices.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/backofficeServices.ts"],"names":["BackofficeCatalog","call","id","BaseCallClass","BackofficeUser","BackofficeTenant","
|
|
1
|
+
{"version":3,"sources":["../../src/backofficeServices.ts"],"names":["BackofficeCatalog","call","id","BaseCallClass","BackofficeUser","BackofficeTenant","BackofficeLayout","BackofficeAuthorization","BackofficeCustomer","BackofficePlugin"],"mappings":";;;;;;;;;AACA;;;;;;;;;;;;;;;;;;;;;;;;IAEaA,iB;;;;;;;;;;;;;;;;kEACG,S;;;;;;;WAEd,2BAA2C;AACzC,aAAO,KAAKC,IAAL,CAAU,iBAAV,CAAP;AACD;;;WACD,sBAAoBC,EAApB,EAAkD;AAChD,aAAO,KAAKD,IAAL,CAAU,cAAV,EAA0BC,EAA1B,CAAP;AACD;;;;EARoCC,oB;;;;IAW1BC,c;;;;;;;;;;;;;;;;mEACG,M;;;;;;;;;;;;;;EADoBD,oB;;;;IAQvBE,gB;;;;;;;;;;;;;;;;mEACG,Q;;;;;;;;;;;;EADsBF,oB;;;;IAOzBG,gB;;;;;;;;;;;;;;;;mEACG,Q;;;;;;;;EADsBH,oB;;;;IAKzBI,uB;;;;;;;;;;;;;;;;mEACG,e;;;;;;;WAEd,wBAAgC;AAC9B,aAAO,KAAKN,IAAL,CAAU,cAAV,CAAP;AACD;;;;EAL0CE,oB;;;;IAQhCK,kB;;;;;;;;;;;;;;;;mEACG,U;;;;;;;;;;EADwBL,oB;;;;IAM3BM,gB;;;;;;;;;;;;;;;;mEACG,Q;;;;;;;;;;;;EADsBN,oB","sourcesContent":["import { Backoffice } from \"@one-commerce/sdk-shared\";\nimport { BaseCallClass } from \"./utils\";\n\nexport class BackofficeCatalog extends BaseCallClass implements Backoffice.Catalog {\n serviceName = 'catalog'\n\n fetchCategories(): Promise<Array<unknown>> {\n return this.call('fetchCategories')\n }\n public fetchProduct(id: string): Promise<unknown> {\n return this.call('fetchProduct', id)\n }\n}\n\nexport class BackofficeUser extends BaseCallClass implements Backoffice.User {\n serviceName = 'user'\n email?: string;\n id!: string;\n name?: string;\n authorities!: Array<string>;\n}\n\nexport class BackofficeTenant extends BaseCallClass implements Backoffice.Tenant {\n serviceName = 'tenant'\n tenantKey?: string;\n language?: string;\n currency?: string;\n}\n\nexport class BackofficeLayout extends BaseCallClass implements Backoffice.Layout {\n serviceName = 'layout'\n isAsideOpened!: boolean;\n}\n\nexport class BackofficeAuthorization extends BaseCallClass implements Backoffice.Authorization {\n serviceName = 'authorization'\n\n getAuthToken(): Promise<string> {\n return this.call('getAuthToken')\n }\n}\n\nexport class BackofficeCustomer extends BaseCallClass implements Backoffice.Customer {\n serviceName = 'customer'\n id?: string;\n name?: string;\n}\n\nexport class BackofficePlugin extends BaseCallClass implements Backoffice.Plugin {\n serviceName = 'plugin'\n id: string;\n srcUrl?: string;\n name?: string;\n}\n\n"],"file":"backofficeServices.js"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -237,11 +237,15 @@ var Sdk = /*#__PURE__*/function (_Events) {
|
|
|
237
237
|
method: fun,
|
|
238
238
|
payload: payload
|
|
239
239
|
});
|
|
240
|
-
return new Promise(function (resolve) {
|
|
240
|
+
return new Promise(function (resolve, reject) {
|
|
241
241
|
var onChannelMessage = function onChannelMessage(response) {
|
|
242
242
|
if (response.callId === callId) {
|
|
243
243
|
_this4.channel.unsubscribe(_sdkShared.Message.METHOD_RESULT, onChannelMessage);
|
|
244
244
|
|
|
245
|
+
if (response.isException) {
|
|
246
|
+
return reject(response.result);
|
|
247
|
+
}
|
|
248
|
+
|
|
245
249
|
return resolve(response.result);
|
|
246
250
|
}
|
|
247
251
|
};
|
|
@@ -308,15 +312,13 @@ var BackofficeSdk = /*#__PURE__*/function (_Sdk) {
|
|
|
308
312
|
hash: '',
|
|
309
313
|
query: {}
|
|
310
314
|
},
|
|
311
|
-
orderpath: new _backofficeServices.BackofficeOrderpath(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
312
315
|
catalog: new _backofficeServices.BackofficeCatalog(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
313
316
|
user: new _backofficeServices.BackofficeUser(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
314
317
|
tenant: new _backofficeServices.BackofficeTenant(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
315
318
|
layout: new _backofficeServices.BackofficeLayout(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
316
319
|
authorization: new _backofficeServices.BackofficeAuthorization(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
317
320
|
customer: new _backofficeServices.BackofficeCustomer(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
318
|
-
plugin: new _backofficeServices.BackofficePlugin(_this5.callFunction.bind(_assertThisInitialized(_this5)))
|
|
319
|
-
addToCartContext: new _backofficeServices.BackofficeAddToCartContext(_this5.callFunction.bind(_assertThisInitialized(_this5)))
|
|
321
|
+
plugin: new _backofficeServices.BackofficePlugin(_this5.callFunction.bind(_assertThisInitialized(_this5)))
|
|
320
322
|
});
|
|
321
323
|
|
|
322
324
|
return _this5;
|
|
@@ -353,7 +355,8 @@ var ShopSdk = /*#__PURE__*/function (_Sdk2) {
|
|
|
353
355
|
catalog: new _shopServices.ShopCatalog(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
354
356
|
account: new _shopServices.ShopAccount(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
355
357
|
utils: new _shopServices.ShopUtils(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
356
|
-
config: new _shopServices.ShopConfig(_this6.callFunction.bind(_assertThisInitialized(_this6)))
|
|
358
|
+
config: new _shopServices.ShopConfig(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
359
|
+
wishlist: new _shopServices.ShopWishlist(_this6.callFunction.bind(_assertThisInitialized(_this6)))
|
|
357
360
|
});
|
|
358
361
|
|
|
359
362
|
return _this6;
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":["SdkInternalEvents","SdkEvents","Sdk","options","initializeServiceGetters","origin","channel","Channel","targetOrigin","target","window","parent","subscribe","Message","INIT","payload","log","Object","entries","instances","forEach","key","value","BaseCallClass","update","attributesForKey","warn","emit","isInitialized","UPDATE","FRAME_HEIGHT_REQUEST","autoheight","sendFrameHeight","connect","then","initializeHeightObserver","setupOptions","keys","serviceName","defineProperty","get","body","document","html","documentElement","height","Math","max","scrollHeight","offsetHeight","clientHeight","postMessage","FRAME_HEIGHT_CHANGE","onMutationObserved","querySelector","config","attributes","attributeOldValue","characterData","characterDataOldValue","childList","subtree","heightMutationObserver","MutationObserver","observe","debug","service","fun","callId","METHOD_CALL","method","Promise","resolve","onChannelMessage","response","unsubscribe","METHOD_RESULT","result","event","NAVIGATION_PUSH","data","console","Events","BackofficeSdk","route","hash","query","orderpath","BackofficeOrderpath","callFunction","bind","catalog","BackofficeCatalog","user","BackofficeUser","tenant","BackofficeTenant","layout","BackofficeLayout","authorization","BackofficeAuthorization","customer","BackofficeCustomer","plugin","BackofficePlugin","addToCartContext","BackofficeAddToCartContext","ShopSdk","ShopAuthorization","cart","ShopCart","ShopCatalog","account","ShopAccount","utils","ShopUtils","ShopConfig"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA;;AAWA;;AACA;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEKA,iB;;WA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MAAAA,MAAM,EAAE,IAAIC,oCAAJ,CAAqB,OAAKf,YAAL,CAAkBC,IAAlB,gCAArB,CAZE;AAaVe,MAAAA,gBAAgB,EAAE,IAAIC,8CAAJ,CAA+B,OAAKjB,YAAL,CAAkBC,IAAlB,gCAA/B;AAbR,K;;;;;;EADqBxF,G;;;;IAkBtByG,O;;;;;;;;;;;;;;;;iEACC;AACVvB,MAAAA,KAAK,EAAE;AACLC,QAAAA,IAAI,EAAE,EADD;AAELC,QAAAA,KAAK,EAAE;AAFF,OADG;AAKVa,MAAAA,aAAa,EAAE,IAAIS,+BAAJ,CAAsB,OAAKnB,YAAL,CAAkBC,IAAlB,gCAAtB,CALL;AAMVmB,MAAAA,IAAI,EAAE,IAAIC,sBAAJ,CAAa,OAAKrB,YAAL,CAAkBC,IAAlB,gCAAb,CANI;AAOVC,MAAAA,OAAO,EAAE,IAAIoB,yBAAJ,CAAgB,OAAKtB,YAAL,CAAkBC,IAAlB,gCAAhB,CAPC;AAQVsB,MAAAA,OAAO,EAAE,IAAIC,yBAAJ,CAAgB,OAAKxB,YAAL,CAAkBC,IAAlB,gCAAhB,CARC;AASVwB,MAAAA,KAAK,EAAE,IAAIC,uBAAJ,CAAc,OAAK1B,YAAL,CAAkBC,IAAlB,gCAAd,CATG;AAUVnC,MAAAA,MAAM,EAAE,IAAI6D,wBAAJ,CAAe,OAAK3B,YAAL,CAAkBC,IAAlB,gCAAf;AAVE,K;;;;;;EADexF,G","sourcesContent":["import {Backoffice, Message, Route, Shop} from \"@one-commerce/sdk-shared\";\nimport Channel from \"iframe-channel\"\n\nimport {\n BackofficeAuthorization,\n BackofficeCatalog,\n BackofficeCustomer,\n BackofficeLayout,\n BackofficeOrderpath,\n BackofficePlugin,\n BackofficeTenant,\n BackofficeUser,\n BackofficeAddToCartContext\n} from \"./backofficeServices\";\nimport Events from \"./events\";\nimport {\n ShopAccount, ShopAuthorization,\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 private heightMutationObserver = null\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 this.sendFrameHeight()\n }\n })\n this.channel.connect().then(() => {\n Sdk.log('Connected with ONe SDK')\n if(this.autoheight) {\n this.initializeHeightObserver()\n }\n })\n this.setupOptions(options)\n Sdk.log('Initialized.')\n }\n\n private sendFrameHeight() {\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 private initializeHeightObserver() {\n if (\"MutationObserver\" in window) {\n const onMutationObserved = () => {\n this.sendFrameHeight()\n }\n const target = document.querySelector('body'),\n config = {\n attributes: true,\n attributeOldValue: false,\n characterData: true,\n characterDataOldValue: false,\n childList: true,\n subtree: true\n }\n\n this.heightMutationObserver = new MutationObserver(onMutationObserved)\n\n Sdk.log('Create body MutationObserver')\n this.heightMutationObserver.observe(target, config)\n } else {\n Sdk.warn('MutationObserver not available. Auto-height functionality disabled.')\n }\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 authorization: BackofficeAuthorization,\n customer: BackofficeCustomer,\n plugin: BackofficePlugin,\n addToCartContext: BackofficeAddToCartContext\n}\n\nexport interface ShopInstances extends Shop.Api {\n authorization: ShopAuthorization,\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 authorization: new BackofficeAuthorization(this.callFunction.bind(this)),\n customer: new BackofficeCustomer(this.callFunction.bind(this)),\n plugin: new BackofficePlugin(this.callFunction.bind(this)),\n addToCartContext: new BackofficeAddToCartContext(this.callFunction.bind(this)),\n }\n}\n\nexport class ShopSdk extends Sdk<ShopInstances> {\n instances = {\n route: {\n hash: '',\n query: {},\n },\n authorization: new ShopAuthorization(this.callFunction.bind(this)),\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"}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":["SdkInternalEvents","SdkEvents","Sdk","options","initializeServiceGetters","origin","channel","Channel","targetOrigin","target","window","parent","subscribe","Message","INIT","payload","log","Object","entries","instances","forEach","key","value","BaseCallClass","update","attributesForKey","warn","emit","isInitialized","UPDATE","FRAME_HEIGHT_REQUEST","autoheight","sendFrameHeight","connect","then","initializeHeightObserver","setupOptions","keys","serviceName","defineProperty","get","body","document","html","documentElement","height","Math","max","scrollHeight","offsetHeight","clientHeight","postMessage","FRAME_HEIGHT_CHANGE","onMutationObserved","querySelector","config","attributes","attributeOldValue","characterData","characterDataOldValue","childList","subtree","heightMutationObserver","MutationObserver","observe","debug","service","fun","callId","METHOD_CALL","method","Promise","resolve","reject","onChannelMessage","response","unsubscribe","METHOD_RESULT","isException","result","event","NAVIGATION_PUSH","data","console","Events","BackofficeSdk","route","hash","query","catalog","BackofficeCatalog","callFunction","bind","user","BackofficeUser","tenant","BackofficeTenant","layout","BackofficeLayout","authorization","BackofficeAuthorization","customer","BackofficeCustomer","plugin","BackofficePlugin","ShopSdk","ShopAuthorization","cart","ShopCart","ShopCatalog","account","ShopAccount","utils","ShopUtils","ShopConfig","wishlist","ShopWishlist"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA;;AASA;;AACA;;AASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEKA,iB;;WAAAA,iB;AAAAA,EAAAA,iB;AAAAA,EAAAA,iB;GAAAA,iB,KAAAA,iB;;IAIOC,S;;;WAAAA,S;AAAAA,EAAAA,S;AAAAA,EAAAA,S;GAAAA,S,yBAAAA,S;;IAoBGC,G;;;;;AA6Bb,eAAYC,OAAZ,EAAiC;AAAA;;AAAA;;AAC/B;;AAD+B;;AAAA,iEA1BZ,IA0BY;;AAAA,6EAzBA,IAyBA;;AAAA;;AAAA,oEAvBjB,KAuBiB;;AAAA;;AAE/B,UAAKC,wBAAL;;AACA,UAAKC,MAAL,GAAcF,OAAO,CAACE,MAAtB;AACA,UAAKC,OAAL,GAAe,IAAIC,yBAAJ,CAAY;AACzBC,MAAAA,YAAY,EAAE,MAAKH,MADM;AAEzBI,MAAAA,MAAM,EAAEC,MAAM,CAACC;AAFU,KAAZ,CAAf;;AAIA,UAAKL,OAAL,CAAaM,SAAb,CAAuBC,mBAAQC,IAA/B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AgB,OAAKpB,YAAL,CAAkBC,IAAlB,gCAAhB,CARC;AASVoB,MAAAA,KAAK,EAAE,IAAIC,uBAAJ,CAAc,OAAKtB,YAAL,CAAkBC,IAAlB,gCAAd,CATG;AAUVrC,MAAAA,MAAM,EAAE,IAAI2D,wBAAJ,CAAe,OAAKvB,YAAL,CAAkBC,IAAlB,gCAAf,CAVE;AAWVuB,MAAAA,QAAQ,EAAE,IAAIC,0BAAJ,CAAiB,OAAKzB,YAAL,CAAkBC,IAAlB,gCAAjB;AAXA,K;;;;;;EADe1F,G","sourcesContent":["import {Backoffice, Message, Route, Shop} from \"@one-commerce/sdk-shared\";\nimport Channel from \"iframe-channel\"\n\nimport {\n BackofficeAuthorization,\n BackofficeCatalog,\n BackofficeCustomer,\n BackofficeLayout,\n BackofficePlugin,\n BackofficeTenant,\n BackofficeUser\n} from \"./backofficeServices\";\nimport Events from \"./events\";\nimport {\n ShopAccount,\n ShopAuthorization,\n ShopCart,\n ShopCatalog,\n ShopConfig,\n ShopUtils,\n ShopWishlist,\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 private heightMutationObserver = null\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 this.sendFrameHeight()\n }\n })\n this.channel.connect().then(() => {\n Sdk.log('Connected with ONe SDK')\n if(this.autoheight) {\n this.initializeHeightObserver()\n }\n })\n this.setupOptions(options)\n Sdk.log('Initialized.')\n }\n\n private sendFrameHeight() {\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 private initializeHeightObserver() {\n if (\"MutationObserver\" in window) {\n const onMutationObserved = () => {\n this.sendFrameHeight()\n }\n const target = document.querySelector('body'),\n config = {\n attributes: true,\n attributeOldValue: false,\n characterData: true,\n characterDataOldValue: false,\n childList: true,\n subtree: true\n }\n\n this.heightMutationObserver = new MutationObserver(onMutationObserved)\n\n Sdk.log('Create body MutationObserver')\n this.heightMutationObserver.observe(target, config)\n } else {\n Sdk.warn('MutationObserver not available. Auto-height functionality disabled.')\n }\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, reject) => {\n const onChannelMessage = (response: any) => {\n if (response.callId === callId) {\n this.channel.unsubscribe(Message.METHOD_RESULT, onChannelMessage)\n if (response.isException) {\n return reject(response.result);\n }\n\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 catalog: BackofficeCatalog,\n user: BackofficeUser,\n tenant: BackofficeTenant,\n layout: BackofficeLayout,\n authorization: BackofficeAuthorization,\n customer: BackofficeCustomer,\n plugin: BackofficePlugin\n}\n\nexport interface ShopInstances extends Shop.Api {\n authorization: ShopAuthorization,\n route: Route,\n cart: ShopCart,\n catalog: ShopCatalog,\n account: ShopAccount,\n utils: ShopUtils\n config: ShopConfig,\n wishlist: ShopWishlist,\n}\n\nexport class BackofficeSdk extends Sdk<BackofficeInstances> {\n instances = {\n route: {\n hash: '',\n query: {},\n },\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 authorization: new BackofficeAuthorization(this.callFunction.bind(this)),\n customer: new BackofficeCustomer(this.callFunction.bind(this)),\n plugin: new BackofficePlugin(this.callFunction.bind(this)),\n }\n}\n\nexport class ShopSdk extends Sdk<ShopInstances> {\n instances = {\n route: {\n hash: '',\n query: {},\n },\n authorization: new ShopAuthorization(this.callFunction.bind(this)),\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 wishlist: new ShopWishlist(this.callFunction.bind(this)),\n }\n}\n"],"file":"index.js"}
|