@one-commerce/sdk-core 1.18.0-alpha.0 → 1.19.2-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 +80 -48
- 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 +80 -47
- 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/backoffice/context.js +104 -0
- package/lib/cjs/backoffice/context.js.map +1 -0
- package/lib/cjs/{backofficeServices.js → backoffice/services.js} +3 -52
- package/lib/cjs/backoffice/services.js.map +1 -0
- package/lib/cjs/index.js +34 -17
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/{shopServices.js → shop/services.js} +2 -2
- package/lib/cjs/shop/services.js.map +1 -0
- package/lib/esm/backoffice/context.js +38 -0
- package/lib/esm/backoffice/context.js.map +1 -0
- package/lib/esm/{backofficeServices.js → backoffice/services.js} +2 -28
- package/lib/esm/backoffice/services.js.map +1 -0
- package/lib/esm/index.js +13 -3
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/{shopServices.js → shop/services.js} +2 -2
- package/lib/esm/shop/services.js.map +1 -0
- package/lib/types/backoffice/context.d.ts +16 -0
- package/lib/types/backoffice/context.d.ts.map +1 -0
- package/lib/types/{backofficeServices.d.ts → backoffice/services.d.ts} +2 -11
- package/lib/types/backoffice/services.d.ts.map +1 -0
- package/lib/types/index.d.ts +11 -5
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/{shopServices.d.ts → shop/services.d.ts} +2 -2
- package/lib/types/{shopServices.d.ts.map → shop/services.d.ts.map} +1 -1
- package/package.json +3 -3
- package/lib/cjs/backofficeServices.js.map +0 -1
- package/lib/cjs/shopServices.js.map +0 -1
- package/lib/esm/backofficeServices.js.map +0 -1
- package/lib/esm/shopServices.js.map +0 -1
- package/lib/types/backofficeServices.d.ts.map +0 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.AddToCartContext = void 0;
|
|
9
|
+
|
|
10
|
+
var _utils = require("../utils");
|
|
11
|
+
|
|
12
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
13
|
+
|
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
15
|
+
|
|
16
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
17
|
+
|
|
18
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
19
|
+
|
|
20
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
21
|
+
|
|
22
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
23
|
+
|
|
24
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
25
|
+
|
|
26
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
27
|
+
|
|
28
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
29
|
+
|
|
30
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
var ContextCallClass = /*#__PURE__*/function (_BaseCallClass) {
|
|
35
|
+
_inherits(ContextCallClass, _BaseCallClass);
|
|
36
|
+
|
|
37
|
+
var _super = _createSuper(ContextCallClass);
|
|
38
|
+
|
|
39
|
+
function ContextCallClass() {
|
|
40
|
+
var _this;
|
|
41
|
+
|
|
42
|
+
_classCallCheck(this, ContextCallClass);
|
|
43
|
+
|
|
44
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
45
|
+
args[_key] = arguments[_key];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
49
|
+
|
|
50
|
+
_defineProperty(_assertThisInitialized(_this), "serviceName", 'context');
|
|
51
|
+
|
|
52
|
+
return _this;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return _createClass(ContextCallClass);
|
|
56
|
+
}(_utils.BaseCallClass);
|
|
57
|
+
|
|
58
|
+
var AddToCartContext = /*#__PURE__*/function (_ContextCallClass) {
|
|
59
|
+
_inherits(AddToCartContext, _ContextCallClass);
|
|
60
|
+
|
|
61
|
+
var _super2 = _createSuper(AddToCartContext);
|
|
62
|
+
|
|
63
|
+
function AddToCartContext() {
|
|
64
|
+
var _this2;
|
|
65
|
+
|
|
66
|
+
_classCallCheck(this, AddToCartContext);
|
|
67
|
+
|
|
68
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
69
|
+
args[_key2] = arguments[_key2];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
_this2 = _super2.call.apply(_super2, [this].concat(args));
|
|
73
|
+
|
|
74
|
+
_defineProperty(_assertThisInitialized(_this2), "productId", void 0);
|
|
75
|
+
|
|
76
|
+
_defineProperty(_assertThisInitialized(_this2), "cartId", void 0);
|
|
77
|
+
|
|
78
|
+
_defineProperty(_assertThisInitialized(_this2), "warehouses", void 0);
|
|
79
|
+
|
|
80
|
+
return _this2;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
_createClass(AddToCartContext, [{
|
|
84
|
+
key: "closePlugin",
|
|
85
|
+
value: function closePlugin() {
|
|
86
|
+
return this.call('closePlugin');
|
|
87
|
+
}
|
|
88
|
+
}, {
|
|
89
|
+
key: "closePluginAndAddToCart",
|
|
90
|
+
value: function closePluginAndAddToCart() {
|
|
91
|
+
return this.call('closePluginAndAddToCart');
|
|
92
|
+
}
|
|
93
|
+
}, {
|
|
94
|
+
key: "closePluginAndRefreshCart",
|
|
95
|
+
value: function closePluginAndRefreshCart() {
|
|
96
|
+
return this.call('closePluginAndRefreshCart');
|
|
97
|
+
}
|
|
98
|
+
}]);
|
|
99
|
+
|
|
100
|
+
return AddToCartContext;
|
|
101
|
+
}(ContextCallClass);
|
|
102
|
+
|
|
103
|
+
exports.AddToCartContext = AddToCartContext;
|
|
104
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/backoffice/context.ts"],"names":["ContextCallClass","BaseCallClass","AddToCartContext","call"],"mappings":";;;;;;;;;AACA;;;;;;;;;;;;;;;;;;;;;;;;IAEMA,gB;;;;;;;;;;;;;;;;kEACU,S;;;;;;EADeC,oB;;IAIlBC,gB;;;;;;;;;;;;;;;;;;;;;;;;;;;WAIX,uBAA6B;AAC3B,aAAO,KAAKC,IAAL,CAAU,aAAV,CAAP;AACD;;;WACD,mCAAyC;AACvC,aAAO,KAAKA,IAAL,CAAU,yBAAV,CAAP;AACD;;;WACD,qCAA2C;AACzC,aAAO,KAAKA,IAAL,CAAU,2BAAV,CAAP;AACD;;;;EAZmCH,gB","sourcesContent":["import {Backoffice} from \"@one-commerce/sdk-shared\";\nimport {BaseCallClass} from \"../utils\";\n\nclass ContextCallClass extends BaseCallClass {\n serviceName = 'context'\n}\n\nexport class AddToCartContext extends ContextCallClass implements Backoffice.Context.AddToCart {\n productId: string;\n cartId: string;\n warehouses: Array<any>;\n closePlugin(): Promise<void> {\n return this.call('closePlugin')\n }\n closePluginAndAddToCart(): Promise<void> {\n return this.call('closePluginAndAddToCart')\n }\n closePluginAndRefreshCart(): Promise<void> {\n return this.call('closePluginAndRefreshCart')\n }\n}\n\nexport type AvailableContext = AddToCartContext\n"],"file":"context.js"}
|
|
@@ -5,9 +5,9 @@ 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.BackofficeOrderpath = exports.BackofficeLayout = exports.BackofficeCustomer = exports.BackofficeCatalog = exports.BackofficeAuthorization =
|
|
8
|
+
exports.BackofficeUser = exports.BackofficeTenant = exports.BackofficePlugin = exports.BackofficeOrderpath = exports.BackofficeLayout = exports.BackofficeCustomer = exports.BackofficeCatalog = exports.BackofficeAuthorization = void 0;
|
|
9
9
|
|
|
10
|
-
var _utils = require("
|
|
10
|
+
var _utils = require("../utils");
|
|
11
11
|
|
|
12
12
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
13
|
|
|
@@ -283,53 +283,4 @@ var BackofficePlugin = /*#__PURE__*/function (_BaseCallClass8) {
|
|
|
283
283
|
}(_utils.BaseCallClass);
|
|
284
284
|
|
|
285
285
|
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
|
-
//# sourceMappingURL=backofficeServices.js.map
|
|
286
|
+
//# sourceMappingURL=services.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/backoffice/services.ts"],"names":["BackofficeCatalog","call","id","BaseCallClass","BackofficeUser","BackofficeTenant","BackofficeOrderpath","BackofficeLayout","BackofficeAuthorization","BackofficeCustomer","BackofficePlugin"],"mappings":";;;;;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;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,mB;;;;;;;;;;;;;;;;mEACG,W;;;;;;EADyBH,oB;;;;IAI5BI,gB;;;;;;;;;;;;;;;;mEACG,Q;;;;;;;;EADsBJ,oB;;;;IAKzBK,uB;;;;;;;;;;;;;;;;mEACG,e;;;;;;;WAEd,wBAAgC;AAC9B,aAAO,KAAKP,IAAL,CAAU,cAAV,CAAP;AACD;;;;EAL0CE,oB;;;;IAQhCM,kB;;;;;;;;;;;;;;;;mEACG,U;;;;;;;;;;EADwBN,oB;;;;IAM3BO,gB;;;;;;;;;;;;;;;;mEACG,Q;;;;;;;;;;;;EADsBP,oB","sourcesContent":["import {Backoffice} from \"@one-commerce/sdk-shared\";\n\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 BackofficeOrderpath extends BaseCallClass implements Backoffice.Orderpath {\n serviceName = 'orderpath'\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"],"file":"services.js"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -5,17 +5,25 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
+
Object.defineProperty(exports, "AddToCartContext", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _context.AddToCartContext;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
8
14
|
exports.ShopSdk = exports.SdkEvents = exports.BackofficeSdk = void 0;
|
|
9
15
|
|
|
10
16
|
var _sdkShared = require("@one-commerce/sdk-shared");
|
|
11
17
|
|
|
12
18
|
var _iframeChannel = _interopRequireDefault(require("iframe-channel"));
|
|
13
19
|
|
|
14
|
-
var
|
|
20
|
+
var _context = require("./backoffice/context");
|
|
21
|
+
|
|
22
|
+
var _services = require("./backoffice/services");
|
|
15
23
|
|
|
16
24
|
var _events = _interopRequireDefault(require("./events"));
|
|
17
25
|
|
|
18
|
-
var
|
|
26
|
+
var _services2 = require("./shop/services");
|
|
19
27
|
|
|
20
28
|
var _utils = require("./utils");
|
|
21
29
|
|
|
@@ -94,6 +102,8 @@ var Sdk = /*#__PURE__*/function (_Events) {
|
|
|
94
102
|
|
|
95
103
|
_defineProperty(_assertThisInitialized(_this), "instances", void 0);
|
|
96
104
|
|
|
105
|
+
_defineProperty(_assertThisInitialized(_this), "contextClass", void 0);
|
|
106
|
+
|
|
97
107
|
_this.initializeServiceGetters();
|
|
98
108
|
|
|
99
109
|
_this.origin = options.origin;
|
|
@@ -157,6 +167,11 @@ var Sdk = /*#__PURE__*/function (_Events) {
|
|
|
157
167
|
}
|
|
158
168
|
|
|
159
169
|
_createClass(Sdk, [{
|
|
170
|
+
key: "initializeContextClass",
|
|
171
|
+
value: function initializeContextClass() {
|
|
172
|
+
return new this.contextClass(this.callFunction.bind(this));
|
|
173
|
+
}
|
|
174
|
+
}, {
|
|
160
175
|
key: "initializeServiceGetters",
|
|
161
176
|
value: function initializeServiceGetters() {
|
|
162
177
|
var _this2 = this;
|
|
@@ -216,6 +231,8 @@ var Sdk = /*#__PURE__*/function (_Events) {
|
|
|
216
231
|
if (typeof options.autoheight !== 'undefined') {
|
|
217
232
|
this.autoheight = options.autoheight;
|
|
218
233
|
}
|
|
234
|
+
|
|
235
|
+
this.contextClass = options.context;
|
|
219
236
|
}
|
|
220
237
|
}
|
|
221
238
|
}, {
|
|
@@ -308,15 +325,15 @@ var BackofficeSdk = /*#__PURE__*/function (_Sdk) {
|
|
|
308
325
|
hash: '',
|
|
309
326
|
query: {}
|
|
310
327
|
},
|
|
311
|
-
orderpath: new
|
|
312
|
-
catalog: new
|
|
313
|
-
user: new
|
|
314
|
-
tenant: new
|
|
315
|
-
layout: new
|
|
316
|
-
authorization: new
|
|
317
|
-
customer: new
|
|
318
|
-
plugin: new
|
|
319
|
-
|
|
328
|
+
orderpath: new _services.BackofficeOrderpath(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
329
|
+
catalog: new _services.BackofficeCatalog(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
330
|
+
user: new _services.BackofficeUser(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
331
|
+
tenant: new _services.BackofficeTenant(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
332
|
+
layout: new _services.BackofficeLayout(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
333
|
+
authorization: new _services.BackofficeAuthorization(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
334
|
+
customer: new _services.BackofficeCustomer(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
335
|
+
plugin: new _services.BackofficePlugin(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
336
|
+
context: _this5.initializeContextClass()
|
|
320
337
|
});
|
|
321
338
|
|
|
322
339
|
return _this5;
|
|
@@ -348,12 +365,12 @@ var ShopSdk = /*#__PURE__*/function (_Sdk2) {
|
|
|
348
365
|
hash: '',
|
|
349
366
|
query: {}
|
|
350
367
|
},
|
|
351
|
-
authorization: new
|
|
352
|
-
cart: new
|
|
353
|
-
catalog: new
|
|
354
|
-
account: new
|
|
355
|
-
utils: new
|
|
356
|
-
config: new
|
|
368
|
+
authorization: new _services2.ShopAuthorization(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
369
|
+
cart: new _services2.ShopCart(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
370
|
+
catalog: new _services2.ShopCatalog(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
371
|
+
account: new _services2.ShopAccount(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
372
|
+
utils: new _services2.ShopUtils(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
373
|
+
config: new _services2.ShopConfig(_this6.callFunction.bind(_assertThisInitialized(_this6)))
|
|
357
374
|
});
|
|
358
375
|
|
|
359
376
|
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;;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,EAAqC,UAACC,OAAD,EAAkB;AACrDb,MAAAA,GAAG,CAACc,GAAJ,CAAQ,uBAAR;AACAC,MAAAA,MAAM,CAACC,OAAP,CAAe,MAAKC,SAApB,EAAgCC,OAAhC,CAAwC,gBAA6E;AAAA;AAAA,YAA3EC,GAA2E;AAAA,YAAtEC,KAAsE;;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CAAd,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","contextClass","callFunction","bind","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","context","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","catalog","BackofficeCatalog","user","BackofficeUser","tenant","BackofficeTenant","layout","BackofficeLayout","authorization","BackofficeAuthorization","customer","BackofficeCustomer","plugin","BackofficePlugin","initializeContextClass","ShopSdk","ShopAuthorization","cart","ShopCart","ShopCatalog","account","ShopAccount","utils","ShopUtils","ShopConfig"],"mappings":";;;;;;;;;;;;;;;AAAA;;AAMA;;AAEA;;AAGA;;AAUA;;AACA;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIKA,iB;;WAAAA,iB;AAAAA,EAAAA,iB;AAAAA,EAAAA,iB;GAAAA,iB,KAAAA,iB;;IAIOC,S;;;WAAAA,S;AAAAA,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,EAAE,IAAIC,4BAAJ,CAAuB,OAAKlE,YAAL,CAAkBC,IAAlB,gCAAvB,CAXA;AAYVkE,MAAAA,MAAM,EAAE,IAAIC,0BAAJ,CAAqB,OAAKpE,YAAL,CAAkBC,IAAlB,gCAArB,CAZE;AAaV8B,MAAAA,OAAO,EAAE,OAAKsC,sBAAL;AAbC,K;;;;;;EADqBzG,G;;;;IAkBtB0G,O;;;;;;;;;;;;;;;;iEACC;AACVpB,MAAAA,KAAK,EAAE;AACLC,QAAAA,IAAI,EAAE,EADD;AAELC,QAAAA,KAAK,EAAE;AAFF,OADG;AAKVW,MAAAA,aAAa,EAAE,IAAIQ,4BAAJ,CAAsB,OAAKvE,YAAL,CAAkBC,IAAlB,gCAAtB,CALL;AAMVuE,MAAAA,IAAI,EAAE,IAAIC,mBAAJ,CAAa,OAAKzE,YAAL,CAAkBC,IAAlB,gCAAb,CANI;AAOVsD,MAAAA,OAAO,EAAE,IAAImB,sBAAJ,CAAgB,OAAK1E,YAAL,CAAkBC,IAAlB,gCAAhB,CAPC;AAQV0E,MAAAA,OAAO,EAAE,IAAIC,sBAAJ,CAAgB,OAAK5E,YAAL,CAAkBC,IAAlB,gCAAhB,CARC;AASV4E,MAAAA,KAAK,EAAE,IAAIC,oBAAJ,CAAc,OAAK9E,YAAL,CAAkBC,IAAlB,gCAAd,CATG;AAUVmB,MAAAA,MAAM,EAAE,IAAI2D,qBAAJ,CAAe,OAAK/E,YAAL,CAAkBC,IAAlB,gCAAf;AAVE,K;;;;;;EADerC,G","sourcesContent":["import {\n Backoffice,\n Message,\n Route,\n Shop\n} from \"@one-commerce/sdk-shared\";\nimport Channel from \"iframe-channel\"\n\nimport {\n AddToCartContext,\n} from \"./backoffice/context\";\nimport {\n BackofficeAuthorization,\n BackofficeCatalog,\n BackofficeCustomer,\n BackofficeLayout,\n BackofficeOrderpath,\n BackofficePlugin,\n BackofficeTenant,\n BackofficeUser,\n} from \"./backoffice/services\";\nimport Events from \"./events\";\nimport {\n ShopAccount, ShopAuthorization,\n ShopCart,\n ShopCatalog, ShopConfig, ShopUtils,\n} from \"./shop/services\";\nimport { BaseCallClass, generateCallId } from \"./utils\";\n\nexport type AvailableContext = AddToCartContext\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 context?: Class<AvailableContext>;\n}\n\ninterface NamedNavigationPayload {\n name: string\n params: any\n}\n\ninterface PathNavigationPayload {\n path: string\n params: any\n}\n\nexport type Class<T = any> = new (...args: any[]) => T;\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 contextClass?: Class<AvailableContext>;\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 public initializeContextClass(): AvailableContext {\n return new this.contextClass(this.callFunction.bind(this))\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 this.contextClass = options.context\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 context: AvailableContext\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 context: this.initializeContextClass()\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\nexport {\n AddToCartContext\n}\n"],"file":"index.js"}
|
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.ShopUtils = exports.ShopConfig = exports.ShopCatalog = exports.ShopCart = exports.ShopAuthorization = exports.ShopAccount = void 0;
|
|
9
9
|
|
|
10
|
-
var _utils = require("
|
|
10
|
+
var _utils = require("../utils");
|
|
11
11
|
|
|
12
12
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
13
|
|
|
@@ -297,4 +297,4 @@ var ShopConfig = /*#__PURE__*/function (_BaseCallClass6) {
|
|
|
297
297
|
}(_utils.BaseCallClass);
|
|
298
298
|
|
|
299
299
|
exports.ShopConfig = ShopConfig;
|
|
300
|
-
//# sourceMappingURL=
|
|
300
|
+
//# sourceMappingURL=services.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/shop/services.ts"],"names":["ShopCatalog","productId","call","categoryId","BaseCallClass","ShopAccount","name","ShopCart","amount","where","cartId","ShopAuthorization","ShopUtils","routes","getCategoryPath","getManufacturerSearchUrl","getProductUrl","isExternalUrl","id","manufacturer","product","url","ShopConfig"],"mappings":";;;;;;;;;AACA;;;;;;;;;;;;;;;;;;;;;;;;IAGaA,W;;;;;;;;;;;;;;;;kEACG,S;;;;;;;;;;;WAId,sBAAaC,SAAb,EAA8C;AAC5C,aAAO,KAAKC,IAAL,CAAU,cAAV,EAA0BD,SAA1B,CAAP;AACD;;;WAED,yBAAgBE,UAAhB,EAAkD;AAChD,aAAO,KAAKD,IAAL,CAAU,iBAAV,EAA6BC,UAA7B,CAAP;AACD;;;;EAX8BC,oB;;;;IAgBpBC,W;;;;;;;;;;;;;;;;mEACG,S;;;;;;;;;;;;;;;WAoDd,oBAAWC,IAAX,EAA2C;AACzC,aAAO,KAAKJ,IAAL,CAAU,YAAV,EAAwBI,IAAxB,CAAP;AACD;;;WAWD,kBAAe,CACb;AACD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;;;;;;;;;;;;;;;;;;;EADgBlB,oB","sourcesContent":["import {Shop} from \"@one-commerce/sdk-shared\";\nimport {BaseCallClass} from \"../utils\";\n\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 id: string;\n name: string;\n externalId?: string;\n tin?: string;\n phone?: string;\n segmentId?: string;\n segments: {\n additionalSegments?: Array<{\n id: string;\n name: string;\n externalId?: string;\n parentSegmentId?: string;\n }>;\n mainSegment: {\n id: string;\n name: string;\n externalId?: string;\n parentSegmentId?: string;\n };\n };\n warehouseId?: string;\n termPayment?: {\n id: string;\n label?: string;\n paymentDaysPeriod?: number;\n };\n isTaxPayer?: boolean;\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 ShopAuthorization extends BaseCallClass implements Shop.Authorization {\n serviceName = 'authorization'\n\n getAuthToken(): Promise<string> {\n return this.call('getAuthToken')\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":"services.js"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
import { BaseCallClass } from "../utils";
|
|
4
|
+
|
|
5
|
+
class ContextCallClass extends BaseCallClass {
|
|
6
|
+
constructor(...args) {
|
|
7
|
+
super(...args);
|
|
8
|
+
|
|
9
|
+
_defineProperty(this, "serviceName", 'context');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class AddToCartContext extends ContextCallClass {
|
|
15
|
+
constructor(...args) {
|
|
16
|
+
super(...args);
|
|
17
|
+
|
|
18
|
+
_defineProperty(this, "productId", void 0);
|
|
19
|
+
|
|
20
|
+
_defineProperty(this, "cartId", void 0);
|
|
21
|
+
|
|
22
|
+
_defineProperty(this, "warehouses", void 0);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
closePlugin() {
|
|
26
|
+
return this.call('closePlugin');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
closePluginAndAddToCart() {
|
|
30
|
+
return this.call('closePluginAndAddToCart');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
closePluginAndRefreshCart() {
|
|
34
|
+
return this.call('closePluginAndRefreshCart');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/backoffice/context.ts"],"names":["BaseCallClass","ContextCallClass","AddToCartContext","closePlugin","call","closePluginAndAddToCart","closePluginAndRefreshCart"],"mappings":";;AACA,SAAQA,aAAR,QAA4B,UAA5B;;AAEA,MAAMC,gBAAN,SAA+BD,aAA/B,CAA6C;AAAA;AAAA;;AAAA,yCAC7B,SAD6B;AAAA;;AAAA;;AAI7C,OAAO,MAAME,gBAAN,SAA+BD,gBAA/B,CAAwF;AAAA;AAAA;;AAAA;;AAAA;;AAAA;AAAA;;AAI7FE,EAAAA,WAAW,GAAkB;AAC3B,WAAO,KAAKC,IAAL,CAAU,aAAV,CAAP;AACD;;AACDC,EAAAA,uBAAuB,GAAkB;AACvC,WAAO,KAAKD,IAAL,CAAU,yBAAV,CAAP;AACD;;AACDE,EAAAA,yBAAyB,GAAkB;AACzC,WAAO,KAAKF,IAAL,CAAU,2BAAV,CAAP;AACD;;AAZ4F","sourcesContent":["import {Backoffice} from \"@one-commerce/sdk-shared\";\nimport {BaseCallClass} from \"../utils\";\n\nclass ContextCallClass extends BaseCallClass {\n serviceName = 'context'\n}\n\nexport class AddToCartContext extends ContextCallClass implements Backoffice.Context.AddToCart {\n productId: string;\n cartId: string;\n warehouses: Array<any>;\n closePlugin(): Promise<void> {\n return this.call('closePlugin')\n }\n closePluginAndAddToCart(): Promise<void> {\n return this.call('closePluginAndAddToCart')\n }\n closePluginAndRefreshCart(): Promise<void> {\n return this.call('closePluginAndRefreshCart')\n }\n}\n\nexport type AvailableContext = AddToCartContext\n"],"file":"context.js"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
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
2
|
|
|
3
|
-
import { BaseCallClass } from "
|
|
3
|
+
import { BaseCallClass } from "../utils";
|
|
4
4
|
export class BackofficeCatalog extends BaseCallClass {
|
|
5
5
|
constructor(...args) {
|
|
6
6
|
super(...args);
|
|
@@ -103,30 +103,4 @@ export class BackofficePlugin extends BaseCallClass {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
}
|
|
106
|
-
|
|
107
|
-
constructor(...args) {
|
|
108
|
-
super(...args);
|
|
109
|
-
|
|
110
|
-
_defineProperty(this, "serviceName", 'addToCartContext');
|
|
111
|
-
|
|
112
|
-
_defineProperty(this, "productId", void 0);
|
|
113
|
-
|
|
114
|
-
_defineProperty(this, "cartId", void 0);
|
|
115
|
-
|
|
116
|
-
_defineProperty(this, "warehouses", void 0);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
closePlugin() {
|
|
120
|
-
this.call('closePlugin');
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
closePluginAndAddToCart() {
|
|
124
|
-
this.call('closePluginAndAddToCart');
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
closePluginAndRefreshCart() {
|
|
128
|
-
this.call('closePluginAndRefreshCart');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
//# sourceMappingURL=backofficeServices.js.map
|
|
106
|
+
//# sourceMappingURL=services.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/backoffice/services.ts"],"names":["BaseCallClass","BackofficeCatalog","fetchCategories","call","fetchProduct","id","BackofficeUser","BackofficeTenant","BackofficeOrderpath","BackofficeLayout","BackofficeAuthorization","getAuthToken","BackofficeCustomer","BackofficePlugin"],"mappings":";;AAEA,SAAQA,aAAR,QAA4B,UAA5B;AAEA,OAAO,MAAMC,iBAAN,SAAgCD,aAAhC,CAA4E;AAAA;AAAA;;AAAA,yCACnE,SADmE;AAAA;;AAGjFE,EAAAA,eAAe,GAA4B;AACzC,WAAO,KAAKC,IAAL,CAAU,iBAAV,CAAP;AACD;;AACMC,EAAAA,YAAY,CAACC,EAAD,EAA+B;AAChD,WAAO,KAAKF,IAAL,CAAU,cAAV,EAA0BE,EAA1B,CAAP;AACD;;AARgF;AAWnF,OAAO,MAAMC,cAAN,SAA6BN,aAA7B,CAAsE;AAAA;AAAA;;AAAA,yCAC7D,MAD6D;;AAAA;;AAAA;;AAAA;;AAAA;AAAA;;AAAA;AAQ7E,OAAO,MAAMO,gBAAN,SAA+BP,aAA/B,CAA0E;AAAA;AAAA;;AAAA,yCACjE,QADiE;;AAAA;;AAAA;;AAAA;AAAA;;AAAA;AAOjF,OAAO,MAAMQ,mBAAN,SAAkCR,aAAlC,CAAgF;AAAA;AAAA;;AAAA,yCACvE,WADuE;AAAA;;AAAA;AAIvF,OAAO,MAAMS,gBAAN,SAA+BT,aAA/B,CAA0E;AAAA;AAAA;;AAAA,yCACjE,QADiE;;AAAA;AAAA;;AAAA;AAKjF,OAAO,MAAMU,uBAAN,SAAsCV,aAAtC,CAAwF;AAAA;AAAA;;AAAA,yCAC/E,eAD+E;AAAA;;AAG7FW,EAAAA,YAAY,GAAoB;AAC9B,WAAO,KAAKR,IAAL,CAAU,cAAV,CAAP;AACD;;AAL4F;AAQ/F,OAAO,MAAMS,kBAAN,SAAiCZ,aAAjC,CAA8E;AAAA;AAAA;;AAAA,yCACrE,UADqE;;AAAA;;AAAA;AAAA;;AAAA;AAMrF,OAAO,MAAMa,gBAAN,SAA+Bb,aAA/B,CAA0E;AAAA;AAAA;;AAAA,yCACjE,QADiE;;AAAA;;AAAA;;AAAA;AAAA;;AAAA","sourcesContent":["import {Backoffice} from \"@one-commerce/sdk-shared\";\n\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 BackofficeOrderpath extends BaseCallClass implements Backoffice.Orderpath {\n serviceName = 'orderpath'\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"],"file":"services.js"}
|
package/lib/esm/index.js
CHANGED
|
@@ -2,9 +2,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
2
2
|
|
|
3
3
|
import { Message } from "@one-commerce/sdk-shared";
|
|
4
4
|
import Channel from "iframe-channel";
|
|
5
|
-
import {
|
|
5
|
+
import { AddToCartContext } from "./backoffice/context";
|
|
6
|
+
import { BackofficeAuthorization, BackofficeCatalog, BackofficeCustomer, BackofficeLayout, BackofficeOrderpath, BackofficePlugin, BackofficeTenant, BackofficeUser } from "./backoffice/services";
|
|
6
7
|
import Events from "./events";
|
|
7
|
-
import { ShopAccount, ShopAuthorization, ShopCart, ShopCatalog, ShopConfig, ShopUtils } from "./
|
|
8
|
+
import { ShopAccount, ShopAuthorization, ShopCart, ShopCatalog, ShopConfig, ShopUtils } from "./shop/services";
|
|
8
9
|
import { BaseCallClass, generateCallId } from "./utils";
|
|
9
10
|
var SdkInternalEvents;
|
|
10
11
|
|
|
@@ -29,6 +30,10 @@ class Sdk extends Events {
|
|
|
29
30
|
console.warn('[SDK Core] ', ...data);
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
initializeContextClass() {
|
|
34
|
+
return new this.contextClass(this.callFunction.bind(this));
|
|
35
|
+
}
|
|
36
|
+
|
|
32
37
|
initializeServiceGetters() {
|
|
33
38
|
if (this.instances) {
|
|
34
39
|
Object.keys(this.instances).forEach(serviceName => {
|
|
@@ -56,6 +61,8 @@ class Sdk extends Events {
|
|
|
56
61
|
|
|
57
62
|
_defineProperty(this, "instances", void 0);
|
|
58
63
|
|
|
64
|
+
_defineProperty(this, "contextClass", void 0);
|
|
65
|
+
|
|
59
66
|
this.initializeServiceGetters();
|
|
60
67
|
this.origin = options.origin;
|
|
61
68
|
this.channel = new Channel({
|
|
@@ -141,6 +148,8 @@ class Sdk extends Events {
|
|
|
141
148
|
if (typeof options.autoheight !== 'undefined') {
|
|
142
149
|
this.autoheight = options.autoheight;
|
|
143
150
|
}
|
|
151
|
+
|
|
152
|
+
this.contextClass = options.context;
|
|
144
153
|
}
|
|
145
154
|
}
|
|
146
155
|
|
|
@@ -196,7 +205,7 @@ export class BackofficeSdk extends Sdk {
|
|
|
196
205
|
authorization: new BackofficeAuthorization(this.callFunction.bind(this)),
|
|
197
206
|
customer: new BackofficeCustomer(this.callFunction.bind(this)),
|
|
198
207
|
plugin: new BackofficePlugin(this.callFunction.bind(this)),
|
|
199
|
-
|
|
208
|
+
context: this.initializeContextClass()
|
|
200
209
|
});
|
|
201
210
|
}
|
|
202
211
|
|
|
@@ -220,4 +229,5 @@ export class ShopSdk extends Sdk {
|
|
|
220
229
|
}
|
|
221
230
|
|
|
222
231
|
}
|
|
232
|
+
export { AddToCartContext };
|
|
223
233
|
//# sourceMappingURL=index.js.map
|