@one-commerce/sdk-core 1.22.0 → 1.22.1-UNITYONE-11259.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.
Files changed (39) hide show
  1. package/lib/bundles/bundle.esm.js +26 -90
  2. package/lib/bundles/bundle.esm.js.map +1 -1
  3. package/lib/bundles/bundle.esm.min.js +1 -1
  4. package/lib/bundles/bundle.esm.min.js.map +1 -1
  5. package/lib/bundles/bundle.umd.js +25 -90
  6. package/lib/bundles/bundle.umd.js.map +1 -1
  7. package/lib/bundles/bundle.umd.min.js +1 -1
  8. package/lib/bundles/bundle.umd.min.js.map +1 -1
  9. package/lib/cjs/backoffice/context.js +33 -57
  10. package/lib/cjs/backoffice/context.js.map +1 -1
  11. package/lib/cjs/events.js +14 -0
  12. package/lib/cjs/events.js.map +1 -1
  13. package/lib/cjs/index.js +11 -18
  14. package/lib/cjs/index.js.map +1 -1
  15. package/lib/cjs/shop/context.js +88 -0
  16. package/lib/cjs/shop/context.js.map +1 -0
  17. package/lib/cjs/utils.js +43 -1
  18. package/lib/cjs/utils.js.map +1 -1
  19. package/lib/esm/backoffice/context.js +1 -11
  20. package/lib/esm/backoffice/context.js.map +1 -1
  21. package/lib/esm/events.js +13 -0
  22. package/lib/esm/events.js.map +1 -1
  23. package/lib/esm/index.js +10 -11
  24. package/lib/esm/index.js.map +1 -1
  25. package/lib/esm/shop/context.js +36 -0
  26. package/lib/esm/shop/context.js.map +1 -0
  27. package/lib/esm/utils.js +8 -0
  28. package/lib/esm/utils.js.map +1 -1
  29. package/lib/types/backoffice/context.d.ts +2 -6
  30. package/lib/types/backoffice/context.d.ts.map +1 -1
  31. package/lib/types/events.d.ts +1 -0
  32. package/lib/types/events.d.ts.map +1 -1
  33. package/lib/types/index.d.ts +15 -13
  34. package/lib/types/index.d.ts.map +1 -1
  35. package/lib/types/shop/context.d.ts +16 -0
  36. package/lib/types/shop/context.d.ts.map +1 -0
  37. package/lib/types/utils.d.ts +3 -0
  38. package/lib/types/utils.d.ts.map +1 -1
  39. package/package.json +3 -3
@@ -9,12 +9,12 @@ exports.EditProductLinesOnCartContext = exports.AddToCartContext = void 0;
9
9
 
10
10
  var _utils = require("../utils");
11
11
 
12
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
+
12
14
  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
15
 
14
16
  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
17
 
16
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
-
18
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
19
 
20
20
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
@@ -31,63 +31,39 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
31
31
 
32
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
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
34
  var AddToCartContext = /*#__PURE__*/function (_ContextCallClass) {
59
35
  _inherits(AddToCartContext, _ContextCallClass);
60
36
 
61
- var _super2 = _createSuper(AddToCartContext);
37
+ var _super = _createSuper(AddToCartContext);
62
38
 
63
39
  function AddToCartContext() {
64
- var _this2;
40
+ var _this;
65
41
 
66
42
  _classCallCheck(this, AddToCartContext);
67
43
 
68
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
69
- args[_key2] = arguments[_key2];
44
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
45
+ args[_key] = arguments[_key];
70
46
  }
71
47
 
72
- _this2 = _super2.call.apply(_super2, [this].concat(args));
48
+ _this = _super.call.apply(_super, [this].concat(args));
73
49
 
74
- _defineProperty(_assertThisInitialized(_this2), "productId", void 0);
50
+ _defineProperty(_assertThisInitialized(_this), "productId", void 0);
75
51
 
76
- _defineProperty(_assertThisInitialized(_this2), "cartId", void 0);
52
+ _defineProperty(_assertThisInitialized(_this), "cartId", void 0);
77
53
 
78
- _defineProperty(_assertThisInitialized(_this2), "offerId", void 0);
54
+ _defineProperty(_assertThisInitialized(_this), "offerId", void 0);
79
55
 
80
- _defineProperty(_assertThisInitialized(_this2), "warehouses", void 0);
56
+ _defineProperty(_assertThisInitialized(_this), "warehouses", void 0);
81
57
 
82
- _defineProperty(_assertThisInitialized(_this2), "warehouseId", void 0);
58
+ _defineProperty(_assertThisInitialized(_this), "warehouseId", void 0);
83
59
 
84
- _defineProperty(_assertThisInitialized(_this2), "meta", void 0);
60
+ _defineProperty(_assertThisInitialized(_this), "meta", void 0);
85
61
 
86
- _defineProperty(_assertThisInitialized(_this2), "pluginProductLines", void 0);
62
+ _defineProperty(_assertThisInitialized(_this), "pluginProductLines", void 0);
87
63
 
88
- _defineProperty(_assertThisInitialized(_this2), "productLines", void 0);
64
+ _defineProperty(_assertThisInitialized(_this), "productLines", void 0);
89
65
 
90
- return _this2;
66
+ return _this;
91
67
  }
92
68
 
93
69
  _createClass(AddToCartContext, [{
@@ -108,45 +84,45 @@ var AddToCartContext = /*#__PURE__*/function (_ContextCallClass) {
108
84
  }]);
109
85
 
110
86
  return AddToCartContext;
111
- }(ContextCallClass);
87
+ }(_utils.ContextCallClass);
112
88
 
113
89
  exports.AddToCartContext = AddToCartContext;
114
90
 
115
91
  var EditProductLinesOnCartContext = /*#__PURE__*/function (_ContextCallClass2) {
116
92
  _inherits(EditProductLinesOnCartContext, _ContextCallClass2);
117
93
 
118
- var _super3 = _createSuper(EditProductLinesOnCartContext);
94
+ var _super2 = _createSuper(EditProductLinesOnCartContext);
119
95
 
120
96
  function EditProductLinesOnCartContext() {
121
- var _this3;
97
+ var _this2;
122
98
 
123
99
  _classCallCheck(this, EditProductLinesOnCartContext);
124
100
 
125
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
126
- args[_key3] = arguments[_key3];
101
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
102
+ args[_key2] = arguments[_key2];
127
103
  }
128
104
 
129
- _this3 = _super3.call.apply(_super3, [this].concat(args));
105
+ _this2 = _super2.call.apply(_super2, [this].concat(args));
130
106
 
131
- _defineProperty(_assertThisInitialized(_this3), "productId", void 0);
107
+ _defineProperty(_assertThisInitialized(_this2), "productId", void 0);
132
108
 
133
- _defineProperty(_assertThisInitialized(_this3), "cartId", void 0);
109
+ _defineProperty(_assertThisInitialized(_this2), "cartId", void 0);
134
110
 
135
- _defineProperty(_assertThisInitialized(_this3), "offerId", void 0);
111
+ _defineProperty(_assertThisInitialized(_this2), "offerId", void 0);
136
112
 
137
- _defineProperty(_assertThisInitialized(_this3), "warehouses", void 0);
113
+ _defineProperty(_assertThisInitialized(_this2), "warehouses", void 0);
138
114
 
139
- _defineProperty(_assertThisInitialized(_this3), "warehouseId", void 0);
115
+ _defineProperty(_assertThisInitialized(_this2), "warehouseId", void 0);
140
116
 
141
- _defineProperty(_assertThisInitialized(_this3), "meta", void 0);
117
+ _defineProperty(_assertThisInitialized(_this2), "meta", void 0);
142
118
 
143
- _defineProperty(_assertThisInitialized(_this3), "productLineId", void 0);
119
+ _defineProperty(_assertThisInitialized(_this2), "productLineId", void 0);
144
120
 
145
- _defineProperty(_assertThisInitialized(_this3), "productLines", void 0);
121
+ _defineProperty(_assertThisInitialized(_this2), "productLines", void 0);
146
122
 
147
- _defineProperty(_assertThisInitialized(_this3), "pluginProductLines", void 0);
123
+ _defineProperty(_assertThisInitialized(_this2), "pluginProductLines", void 0);
148
124
 
149
- return _this3;
125
+ return _this2;
150
126
  }
151
127
 
152
128
  _createClass(EditProductLinesOnCartContext, [{
@@ -162,7 +138,7 @@ var EditProductLinesOnCartContext = /*#__PURE__*/function (_ContextCallClass2) {
162
138
  }]);
163
139
 
164
140
  return EditProductLinesOnCartContext;
165
- }(ContextCallClass);
141
+ }(_utils.ContextCallClass);
166
142
 
167
143
  exports.EditProductLinesOnCartContext = EditProductLinesOnCartContext;
168
144
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/backoffice/context.ts"],"names":["ContextCallClass","BaseCallClass","AddToCartContext","call","EditProductLinesOnCartContext"],"mappings":";;;;;;;;;AACA;;;;;;;;;;;;;;;;;;;;;;;;IAEMA,gB;;;;;;;;;;;;;;;;kEACU,S;;;;;;EADeC,oB;;IAIlBC,gB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WASX,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;;;;EAjBmCH,gB;;;;IAoBzBI,6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAUX,uBAA6B;AAC3B,aAAO,KAAKD,IAAL,CAAU,aAAV,CAAP;AACD;;;WACD,qCAA2C;AACzC,aAAO,KAAKA,IAAL,CAAU,2BAAV,CAAP;AACD;;;;EAfgDH,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 | null;\n offerId: string | null;\n warehouses: Array<any>;\n warehouseId: string;\n meta: unknown;\n pluginProductLines: Array<any>;\n productLines: 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 class EditProductLinesOnCartContext extends ContextCallClass implements Backoffice.Context.EditProductLinesOnCart {\n productId: string;\n cartId: string | null;\n offerId: string | null;\n warehouses: Array<any>;\n warehouseId: string;\n meta: unknown;\n productLineId: string;\n productLines: Array<any>;\n pluginProductLines: Array<any>;\n closePlugin(): Promise<void> {\n return this.call('closePlugin')\n }\n closePluginAndRefreshCart(): Promise<void> {\n return this.call('closePluginAndRefreshCart')\n }\n}\n\nexport type AvailableContext = AddToCartContext | EditProductLinesOnCartContext\n"],"file":"context.js"}
1
+ {"version":3,"sources":["../../../src/backoffice/context.ts"],"names":["AddToCartContext","call","ContextCallClass","EditProductLinesOnCartContext"],"mappings":";;;;;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;IAEaA,gB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WASX,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;;;;EAjBmCC,uB;;;;IAoBzBC,6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAUX,uBAA6B;AAC3B,aAAO,KAAKF,IAAL,CAAU,aAAV,CAAP;AACD;;;WACD,qCAA2C;AACzC,aAAO,KAAKA,IAAL,CAAU,2BAAV,CAAP;AACD;;;;EAfgDC,uB","sourcesContent":["import {Backoffice} from \"@one-commerce/sdk-shared\";\n\nimport {ContextCallClass} from \"../utils\";\n\nexport class AddToCartContext extends ContextCallClass implements Backoffice.Context.AddToCart {\n productId: string;\n cartId: string | null;\n offerId: string | null;\n warehouses: Array<any>;\n warehouseId: string;\n meta: unknown;\n pluginProductLines: Array<any>;\n productLines: 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 class EditProductLinesOnCartContext extends ContextCallClass implements Backoffice.Context.EditProductLinesOnCart {\n productId: string;\n cartId: string | null;\n offerId: string | null;\n warehouses: Array<any>;\n warehouseId: string;\n meta: unknown;\n productLineId: string;\n productLines: Array<any>;\n pluginProductLines: Array<any>;\n closePlugin(): Promise<void> {\n return this.call('closePlugin')\n }\n closePluginAndRefreshCart(): Promise<void> {\n return this.call('closePluginAndRefreshCart')\n }\n}\n\nexport type BackofficeAvailableContext = AddToCartContext | EditProductLinesOnCartContext\n"],"file":"context.js"}
package/lib/cjs/events.js CHANGED
@@ -33,6 +33,20 @@ var Events = /*#__PURE__*/function () {
33
33
 
34
34
  this._callbacks[key].push(callback);
35
35
  }
36
+ }, {
37
+ key: "off",
38
+ value: function off(key, callback) {
39
+ // if the key exists
40
+ if (this._callbacks[key] !== undefined) {
41
+ // iterate through the callbacks for the event key
42
+ for (var i = 0; i < this._callbacks[key].length; i++) {
43
+ // if the callback matches, remove it
44
+ if (this._callbacks[key][i] === callback) {
45
+ this._callbacks[key].splice(i, 1);
46
+ }
47
+ }
48
+ }
49
+ }
36
50
  }, {
37
51
  key: "emit",
38
52
  value: function emit(key) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/events.ts"],"names":["Events","_callbacks","key","callback","undefined","push","params","i","length"],"mappings":";;;;;;;;;;;;;;;IAAMA,M;AAEJ,oBAAe;AAAA;;AAAA;;AACb,SAAKC,UAAL,GAAkB,EAAlB;AACD;;;;WAED,YAAMC,GAAN,EAAmBC,QAAnB,EAA+C;AAC7C;AACA,UAAI,KAAKF,UAAL,CAAgBC,GAAhB,MAAyBE,SAA7B,EAAwC;AAAE,aAAKH,UAAL,CAAgBC,GAAhB,IAAuB,EAAvB;AAA2B,OAFxB,CAG7C;;;AACA,WAAKD,UAAL,CAAgBC,GAAhB,EAAqBG,IAArB,CAA0BF,QAA1B;AACD;;;WAED,cAAKD,GAAL,EAAyC;AACvC;AACA,UAAI,KAAKD,UAAL,CAAgBC,GAAhB,MAAyBE,SAA7B,EAAwC;AAAA,0CAFrBE,MAEqB;AAFrBA,UAAAA,MAEqB;AAAA;;AACtC;AACA,aAAK,IAAIC,CAAC,GAAC,CAAX,EAAcA,CAAC,GAAC,KAAKN,UAAL,CAAgBC,GAAhB,EAAqBM,MAArC,EAA6CD,CAAC,EAA9C,EAAkD;AAAA;;AAChD;AACA,uCAAKN,UAAL,CAAgBC,GAAhB,GAAqBK,CAArB,8BAA2BD,MAA3B;AACD;AACF;AACF;;;;;;eAGYN,M","sourcesContent":["class Events {\n _callbacks: Record<string, any>\n constructor () {\n this._callbacks = {}\n }\n\n on<T>(key: string, callback: (arg: T) => void) {\n // create an empty array for the event key\n if (this._callbacks[key] === undefined) { this._callbacks[key] = [] }\n // save the callback in the array for the event key\n this._callbacks[key].push(callback)\n }\n\n emit(key: string, ...params: Array<any>) {\n // if the key exists\n if (this._callbacks[key] !== undefined) {\n // iterate through the callbacks for the event key\n for (let i=0; i<this._callbacks[key].length; i++) {\n // trigger the callbacks with all provided params\n this._callbacks[key][i](...params)\n }\n }\n }\n}\n\nexport default Events\n"],"file":"events.js"}
1
+ {"version":3,"sources":["../../src/events.ts"],"names":["Events","_callbacks","key","callback","undefined","push","i","length","splice","params"],"mappings":";;;;;;;;;;;;;;;IAAMA,M;AAEJ,oBAAe;AAAA;;AAAA;;AACb,SAAKC,UAAL,GAAkB,EAAlB;AACD;;;;WAED,YAAMC,GAAN,EAAmBC,QAAnB,EAA+C;AAC7C;AACA,UAAI,KAAKF,UAAL,CAAgBC,GAAhB,MAAyBE,SAA7B,EAAwC;AAAE,aAAKH,UAAL,CAAgBC,GAAhB,IAAuB,EAAvB;AAA2B,OAFxB,CAG7C;;;AACA,WAAKD,UAAL,CAAgBC,GAAhB,EAAqBG,IAArB,CAA0BF,QAA1B;AACD;;;WAED,aAAOD,GAAP,EAAoBC,QAApB,EAAgD;AAC9C;AACA,UAAI,KAAKF,UAAL,CAAgBC,GAAhB,MAAyBE,SAA7B,EAAwC;AACtC;AACA,aAAK,IAAIE,CAAC,GAAC,CAAX,EAAcA,CAAC,GAAC,KAAKL,UAAL,CAAgBC,GAAhB,EAAqBK,MAArC,EAA6CD,CAAC,EAA9C,EAAkD;AAChD;AACA,cAAI,KAAKL,UAAL,CAAgBC,GAAhB,EAAqBI,CAArB,MAA4BH,QAAhC,EAA0C;AACxC,iBAAKF,UAAL,CAAgBC,GAAhB,EAAqBM,MAArB,CAA4BF,CAA5B,EAA+B,CAA/B;AACD;AACF;AACF;AACF;;;WAED,cAAKJ,GAAL,EAAyC;AACvC;AACA,UAAI,KAAKD,UAAL,CAAgBC,GAAhB,MAAyBE,SAA7B,EAAwC;AAAA,0CAFrBK,MAEqB;AAFrBA,UAAAA,MAEqB;AAAA;;AACtC;AACA,aAAK,IAAIH,CAAC,GAAC,CAAX,EAAcA,CAAC,GAAC,KAAKL,UAAL,CAAgBC,GAAhB,EAAqBK,MAArC,EAA6CD,CAAC,EAA9C,EAAkD;AAAA;;AAChD;AACA,uCAAKL,UAAL,CAAgBC,GAAhB,GAAqBI,CAArB,8BAA2BG,MAA3B;AACD;AACF;AACF;;;;;;eAGYT,M","sourcesContent":["class Events {\n _callbacks: Record<string, any>\n constructor () {\n this._callbacks = {}\n }\n\n on<T>(key: string, callback: (arg: T) => void) {\n // create an empty array for the event key\n if (this._callbacks[key] === undefined) { this._callbacks[key] = [] }\n // save the callback in the array for the event key\n this._callbacks[key].push(callback)\n }\n\n off<T>(key: string, callback: (arg: T) => void) {\n // if the key exists\n if (this._callbacks[key] !== undefined) {\n // iterate through the callbacks for the event key\n for (let i=0; i<this._callbacks[key].length; i++) {\n // if the callback matches, remove it\n if (this._callbacks[key][i] === callback) {\n this._callbacks[key].splice(i, 1)\n }\n }\n }\n }\n\n emit(key: string, ...params: Array<any>) {\n // if the key exists\n if (this._callbacks[key] !== undefined) {\n // iterate through the callbacks for the event key\n for (let i=0; i<this._callbacks[key].length; i++) {\n // trigger the callbacks with all provided params\n this._callbacks[key][i](...params)\n }\n }\n }\n}\n\nexport default Events\n"],"file":"events.js"}
package/lib/cjs/index.js CHANGED
@@ -5,20 +5,12 @@ 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
- });
14
8
  exports.ShopSdk = exports.SdkEvents = exports.BackofficeSdk = void 0;
15
9
 
16
10
  var _sdkShared = require("@one-commerce/sdk-shared");
17
11
 
18
12
  var _iframeChannel = _interopRequireDefault(require("iframe-channel"));
19
13
 
20
- var _context = require("./backoffice/context");
21
-
22
14
  var _services = require("./backoffice/services");
23
15
 
24
16
  var _events = _interopRequireDefault(require("./events"));
@@ -166,15 +158,6 @@ var Sdk = /*#__PURE__*/function (_Events) {
166
158
  }
167
159
 
168
160
  _createClass(Sdk, [{
169
- key: "initializeContextClass",
170
- value: function initializeContextClass() {
171
- if (this.contextClass) {
172
- return new this.contextClass(this.callFunction.bind(this));
173
- }
174
-
175
- return {};
176
- }
177
- }, {
178
161
  key: "initializeServiceGetters",
179
162
  value: function initializeServiceGetters() {
180
163
  var _this2 = this;
@@ -189,6 +172,15 @@ var Sdk = /*#__PURE__*/function (_Events) {
189
172
  });
190
173
  }
191
174
  }
175
+ }, {
176
+ key: "initializeContextClass",
177
+ value: function initializeContextClass() {
178
+ if (this.contextClass) {
179
+ return new this.contextClass(this.callFunction.bind(this));
180
+ }
181
+
182
+ return {};
183
+ }
192
184
  }, {
193
185
  key: "sendFrameHeight",
194
186
  value: function sendFrameHeight() {
@@ -378,7 +370,8 @@ var ShopSdk = /*#__PURE__*/function (_Sdk2) {
378
370
  account: new _services2.ShopAccount(_this6.callFunction.bind(_assertThisInitialized(_this6))),
379
371
  utils: new _services2.ShopUtils(_this6.callFunction.bind(_assertThisInitialized(_this6))),
380
372
  config: new _services2.ShopConfig(_this6.callFunction.bind(_assertThisInitialized(_this6))),
381
- wishlist: new _services2.ShopWishlist(_this6.callFunction.bind(_assertThisInitialized(_this6)))
373
+ wishlist: new _services2.ShopWishlist(_this6.callFunction.bind(_assertThisInitialized(_this6))),
374
+ context: _this6.initializeContextClass()
382
375
  });
383
376
 
384
377
  return _this6;
@@ -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","isInitialized","emit","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","reject","onChannelMessage","response","unsubscribe","METHOD_RESULT","isException","result","event","NAVIGATION_PUSH","data","console","Events","BackofficeSdk","route","hash","query","catalog","BackofficeCatalog","user","BackofficeUser","tenant","BackofficeTenant","layout","BackofficeLayout","authorization","BackofficeAuthorization","customer","BackofficeCustomer","plugin","BackofficePlugin","orderpath","BackofficeOrderpath","initializeContextClass","ShopSdk","ShopAuthorization","cart","ShopCart","ShopCatalog","account","ShopAccount","utils","ShopUtils","ShopConfig","wishlist","ShopWishlist"],"mappings":";;;;;;;;;;;;;;;AAAA;;AAMA;;AAEA;;AAGA;;AAUA;;AACA;;AASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIKA,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;;IAuBGC,G;;;;;AAqCb,eAAYC,OAAZ,EAAiC;AAAA;;AAAA;;AAC/B;;AAD+B;;AAAA,iEAlCZ,IAkCY;;AAAA,6EAjCA,IAiCA;;AAAA;;AAAA,oEA/BjB,KA+BiB;;AAAA;;AAAA;;AAE/B,UAAKC,wBAAL;;AACA,UAAKC,MAAL,GAAcF,OAAO,CAACE,MAAtB;AACA,UAAKC,OAAL,GAAe,IAAIC,yBAAJ,CAAY;AACzBC,MAAAA,YAAY,EAAE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CAAxB,CAZD;AAaV8B,MAAAA,OAAO,EAAE,OAAKwC,sBAAL;AAbC,K;;;;;;EADqB3G,G;;;;IAkBtB4G,O;;;;;;;;;;;;;;;;iEACC;AACVpB,MAAAA,KAAK,EAAE;AACLC,QAAAA,IAAI,EAAE,EADD;AAELC,QAAAA,KAAK,EAAE;AAFF,OADG;AAKVS,MAAAA,aAAa,EAAE,IAAIU,4BAAJ,CAAsB,OAAKzE,YAAL,CAAkBC,IAAlB,gCAAtB,CALL;AAMVyE,MAAAA,IAAI,EAAE,IAAIC,mBAAJ,CAAa,OAAK3E,YAAL,CAAkBC,IAAlB,gCAAb,CANI;AAOVsD,MAAAA,OAAO,EAAE,IAAIqB,sBAAJ,CAAgB,OAAK5E,YAAL,CAAkBC,IAAlB,gCAAhB,CAPC;AAQV4E,MAAAA,OAAO,EAAE,IAAIC,sBAAJ,CAAgB,OAAK9E,YAAL,CAAkBC,IAAlB,gCAAhB,CARC;AASV8E,MAAAA,KAAK,EAAE,IAAIC,oBAAJ,CAAc,OAAKhF,YAAL,CAAkBC,IAAlB,gCAAd,CATG;AAUVmB,MAAAA,MAAM,EAAE,IAAI6D,qBAAJ,CAAe,OAAKjF,YAAL,CAAkBC,IAAlB,gCAAf,CAVE;AAWViF,MAAAA,QAAQ,EAAE,IAAIC,uBAAJ,CAAiB,OAAKnF,YAAL,CAAkBC,IAAlB,gCAAjB;AAXA,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,\n ShopAuthorization,\n ShopCart,\n ShopCatalog,\n ShopConfig,\n ShopUtils,\n ShopWishlist,\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 if (this.contextClass) {\n return new this.contextClass(this.callFunction.bind(this))\n }\n return {} as AvailableContext\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.isInitialized = true\n this.emit(SdkInternalEvents.INIT, this.instances)\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, 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 context: AvailableContext\n orderpath: BackofficeOrderpath,\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 orderpath: new BackofficeOrderpath(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 wishlist: new ShopWishlist(this.callFunction.bind(this)),\n }\n}\n\nexport {\n AddToCartContext\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","isInitialized","emit","UPDATE","FRAME_HEIGHT_REQUEST","autoheight","sendFrameHeight","connect","then","initializeHeightObserver","setupOptions","keys","serviceName","defineProperty","get","contextClass","callFunction","bind","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","reject","onChannelMessage","response","unsubscribe","METHOD_RESULT","isException","result","event","NAVIGATION_PUSH","data","console","Events","BackofficeSdk","route","hash","query","catalog","BackofficeCatalog","user","BackofficeUser","tenant","BackofficeTenant","layout","BackofficeLayout","authorization","BackofficeAuthorization","customer","BackofficeCustomer","plugin","BackofficePlugin","orderpath","BackofficeOrderpath","initializeContextClass","ShopSdk","ShopAuthorization","cart","ShopCart","ShopCatalog","account","ShopAccount","utils","ShopUtils","ShopConfig","wishlist","ShopWishlist"],"mappings":";;;;;;;;;AAAA;;AAMA;;AAGA;;AAUA;;AAEA;;AASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAGKA,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;;IAuBGC,G;;;;;AAqCb,eAAYC,OAAZ,EAAoC;AAAA;;AAAA;;AAClC;;AADkC;;AAAA,iEAlCf,IA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el\"\n\nimport { BackofficeAvailableContext} 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 { ShopAvailableContext } from \"./shop/context\";\nimport {\n ShopAccount,\n ShopAuthorization,\n ShopCart,\n ShopCatalog,\n ShopConfig,\n ShopUtils,\n ShopWishlist,\n} from \"./shop/services\";\nimport { BaseCallClass, generateCallId } from \"./utils\";\n\n\nenum SdkInternalEvents {\n INIT='INIT',\n UPDATE='UPDATE'\n}\nexport enum SdkEvents {\n INIT='INIT',\n UPDATE='UPDATE',\n}\nexport interface SdkOptions<S> {\n debug?: boolean\n autoheight?: boolean\n origin: string,\n context?: Class<S>;\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, S = BackofficeAvailableContext | ShopAvailableContext> 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<S>;\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 public initializeContextClass(): S {\n if (this.contextClass) {\n return new this.contextClass(this.callFunction.bind(this))\n }\n return {} as S\n }\n\n constructor(options: SdkOptions<S>) {\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.isInitialized = true\n this.emit(SdkInternalEvents.INIT, this.instances)\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<S>) {\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, 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 context: BackofficeAvailableContext\n orderpath: BackofficeOrderpath,\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 context: ShopAvailableContext\n}\n\nexport class BackofficeSdk extends Sdk<BackofficeInstances, BackofficeAvailableContext> {\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 orderpath: new BackofficeOrderpath(this.callFunction.bind(this)),\n context: this.initializeContextClass()\n }\n}\n\nexport class ShopSdk extends Sdk<ShopInstances, ShopAvailableContext> {\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 context: this.initializeContextClass()\n }\n}\n\n"],"file":"index.js"}
@@ -0,0 +1,88 @@
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
+
14
+ 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); } }
15
+
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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 AddToCartContext = /*#__PURE__*/function (_ContextCallClass) {
35
+ _inherits(AddToCartContext, _ContextCallClass);
36
+
37
+ var _super = _createSuper(AddToCartContext);
38
+
39
+ function AddToCartContext() {
40
+ var _this;
41
+
42
+ _classCallCheck(this, AddToCartContext);
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), "productId", void 0);
51
+
52
+ _defineProperty(_assertThisInitialized(_this), "cartId", void 0);
53
+
54
+ _defineProperty(_assertThisInitialized(_this), "warehouses", void 0);
55
+
56
+ _defineProperty(_assertThisInitialized(_this), "warehouseId", void 0);
57
+
58
+ _defineProperty(_assertThisInitialized(_this), "meta", void 0);
59
+
60
+ _defineProperty(_assertThisInitialized(_this), "pluginProductLines", void 0);
61
+
62
+ _defineProperty(_assertThisInitialized(_this), "productLines", void 0);
63
+
64
+ return _this;
65
+ }
66
+
67
+ _createClass(AddToCartContext, [{
68
+ key: "closePlugin",
69
+ value: function closePlugin() {
70
+ return this.call('closePlugin');
71
+ }
72
+ }, {
73
+ key: "closePluginAndAddToCart",
74
+ value: function closePluginAndAddToCart() {
75
+ return this.call('closePluginAndAddToCart');
76
+ }
77
+ }, {
78
+ key: "closePluginAndRefreshCart",
79
+ value: function closePluginAndRefreshCart() {
80
+ return this.call('closePluginAndRefreshCart');
81
+ }
82
+ }]);
83
+
84
+ return AddToCartContext;
85
+ }(_utils.ContextCallClass);
86
+
87
+ exports.AddToCartContext = AddToCartContext;
88
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/shop/context.ts"],"names":["AddToCartContext","call","ContextCallClass"],"mappings":";;;;;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;IAEaA,gB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAQX,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;;;;EAhBmCC,uB","sourcesContent":["import { Shop } from \"@one-commerce/sdk-shared\";\n\nimport { ContextCallClass } from \"../utils\";\n\nexport class AddToCartContext extends ContextCallClass implements Shop.Context.AddToCart {\n productId: string;\n cartId: string;\n warehouses: Array<any>;\n warehouseId: string;\n meta: unknown;\n pluginProductLines: Array<any>;\n productLines: 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 ShopAvailableContext = AddToCartContext\n"],"file":"context.js"}
package/lib/cjs/utils.js CHANGED
@@ -1,11 +1,27 @@
1
1
  "use strict";
2
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
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
- exports.BaseCallClass = void 0;
8
+ exports.ContextCallClass = exports.BaseCallClass = void 0;
7
9
  exports.generateCallId = generateCallId;
8
10
 
11
+ 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); }
12
+
13
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
14
+
15
+ 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); }; }
16
+
17
+ 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); }
18
+
19
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
20
+
21
+ 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; } }
22
+
23
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
24
+
9
25
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
26
 
11
27
  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); } }
@@ -66,4 +82,30 @@ var BaseCallClass = /*#__PURE__*/function () {
66
82
  }();
67
83
 
68
84
  exports.BaseCallClass = BaseCallClass;
85
+
86
+ var ContextCallClass = /*#__PURE__*/function (_BaseCallClass) {
87
+ _inherits(ContextCallClass, _BaseCallClass);
88
+
89
+ var _super = _createSuper(ContextCallClass);
90
+
91
+ function ContextCallClass() {
92
+ var _this2;
93
+
94
+ _classCallCheck(this, ContextCallClass);
95
+
96
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
97
+ args[_key2] = arguments[_key2];
98
+ }
99
+
100
+ _this2 = _super.call.apply(_super, [this].concat(args));
101
+
102
+ _defineProperty(_assertThisInitialized(_this2), "serviceName", 'context');
103
+
104
+ return _this2;
105
+ }
106
+
107
+ return _createClass(ContextCallClass);
108
+ }(BaseCallClass);
109
+
110
+ exports.ContextCallClass = ContextCallClass;
69
111
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils.ts"],"names":["dec2hex","dec","toString","padStart","generateCallId","arr","Uint8Array","window","crypto","getRandomValues","Array","from","join","BaseCallClass","call","fun","arg","serviceName","payload","attributes","update","target","Object","keys","forEach","key"],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAMA,OAAO,GAAI,SAAXA,OAAW,CAACC,GAAD,EAAyB;AACxC,SAAOA,GAAG,CAACC,QAAJ,CAAa,EAAb,EAAiBC,QAAjB,CAA0B,CAA1B,EAA6B,GAA7B,CAAP;AACD,CAFD,C,CAIA;;;AACO,SAASC,cAAT,GAA2B;AAChC,MAAMC,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;;IAEYC,a;AAGX,yBAAYC,IAAZ,EAA+E;AAAA;;AAAA;;AAAA,yCAFjE,EAEiE;;AAAA;;AAC7E,SAAKA,IAAL,GAAY,UAACC,GAAD,EAA8B;AAAA,wCAAbC,GAAa;AAAbA,QAAAA,GAAa;AAAA;;AACxC,aAAOF,IAAI,MAAJ,UAAK,KAAI,CAACG,WAAV,EAAuBF,GAAvB,SAA+BC,GAA/B,EAAP;AACD,KAFD;AAGD;;;;WAMD,gBAAOE,OAAP,EAAqB;AACnB,UAAMC,UAAe,GAAGD,OAAO,CAAC,KAAKD,WAAN,CAA/B;;AACA,UAAIE,UAAJ,EAAgB;AACdN,QAAAA,aAAa,CAACO,MAAd,CAAqB,IAArB,EAA2BD,UAA3B;AACD;AACF;;;WAVD,gBAAcE,MAAd,EAA2CH,OAA3C,EAAyE;AACvEI,MAAAA,MAAM,CAACC,IAAP,CAAYL,OAAZ,EAAqBM,OAArB,CAA6B,UAACC,GAAD,EAAiB;AAC5CJ,QAAAA,MAAM,CAACI,GAAD,CAAN,GAAcP,OAAO,CAACO,GAAD,CAArB;AACD,OAFD;AAGD","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"}
1
+ {"version":3,"sources":["../../src/utils.ts"],"names":["dec2hex","dec","toString","padStart","generateCallId","arr","Uint8Array","window","crypto","getRandomValues","Array","from","join","BaseCallClass","call","fun","arg","serviceName","payload","attributes","update","target","Object","keys","forEach","key","ContextCallClass"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAMA,OAAO,GAAI,SAAXA,OAAW,CAACC,GAAD,EAAyB;AACxC,SAAOA,GAAG,CAACC,QAAJ,CAAa,EAAb,EAAiBC,QAAjB,CAA0B,CAA1B,EAA6B,GAA7B,CAAP;AACD,CAFD,C,CAIA;;;AACO,SAASC,cAAT,GAA2B;AAChC,MAAMC,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;;IAEYC,a;AAGX,yBAAYC,IAAZ,EAA+E;AAAA;;AAAA;;AAAA,yCAFjE,EAEiE;;AAAA;;AAC7E,SAAKA,IAAL,GAAY,UAACC,GAAD,EAA8B;AAAA,wCAAbC,GAAa;AAAbA,QAAAA,GAAa;AAAA;;AACxC,aAAOF,IAAI,MAAJ,UAAK,KAAI,CAACG,WAAV,EAAuBF,GAAvB,SAA+BC,GAA/B,EAAP;AACD,KAFD;AAGD;;;;WAMD,gBAAOE,OAAP,EAAqB;AACnB,UAAMC,UAAe,GAAGD,OAAO,CAAC,KAAKD,WAAN,CAA/B;;AACA,UAAIE,UAAJ,EAAgB;AACdN,QAAAA,aAAa,CAACO,MAAd,CAAqB,IAArB,EAA2BD,UAA3B;AACD;AACF;;;WAVD,gBAAcE,MAAd,EAA2CH,OAA3C,EAAyE;AACvEI,MAAAA,MAAM,CAACC,IAAP,CAAYL,OAAZ,EAAqBM,OAArB,CAA6B,UAACC,GAAD,EAAiB;AAC5CJ,QAAAA,MAAM,CAACI,GAAD,CAAN,GAAcP,OAAO,CAACO,GAAD,CAArB;AACD,OAFD;AAGD;;;;;;;;IAQUC,gB;;;;;;;;;;;;;;;;mEACG,S;;;;;;EADsBb,a","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}\nexport class ContextCallClass extends BaseCallClass {\n serviceName = 'context'\n}\n"],"file":"utils.js"}
@@ -1,16 +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 "../utils";
4
-
5
- class ContextCallClass extends BaseCallClass {
6
- constructor(...args) {
7
- super(...args);
8
-
9
- _defineProperty(this, "serviceName", 'context');
10
- }
11
-
12
- }
13
-
3
+ import { ContextCallClass } from "../utils";
14
4
  export class AddToCartContext extends ContextCallClass {
15
5
  constructor(...args) {
16
6
  super(...args);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/backoffice/context.ts"],"names":["BaseCallClass","ContextCallClass","AddToCartContext","closePlugin","call","closePluginAndAddToCart","closePluginAndRefreshCart","EditProductLinesOnCartContext"],"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;;AAAA;;AAAA;;AAAA;;AAAA;AAAA;;AAS7FE,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;;AAjB4F;AAoB/F,OAAO,MAAMG,6BAAN,SAA4CN,gBAA5C,CAAkH;AAAA;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;AAAA;;AAUvHE,EAAAA,WAAW,GAAkB;AAC3B,WAAO,KAAKC,IAAL,CAAU,aAAV,CAAP;AACD;;AACDE,EAAAA,yBAAyB,GAAkB;AACzC,WAAO,KAAKF,IAAL,CAAU,2BAAV,CAAP;AACD;;AAfsH","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 | null;\n offerId: string | null;\n warehouses: Array<any>;\n warehouseId: string;\n meta: unknown;\n pluginProductLines: Array<any>;\n productLines: 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 class EditProductLinesOnCartContext extends ContextCallClass implements Backoffice.Context.EditProductLinesOnCart {\n productId: string;\n cartId: string | null;\n offerId: string | null;\n warehouses: Array<any>;\n warehouseId: string;\n meta: unknown;\n productLineId: string;\n productLines: Array<any>;\n pluginProductLines: Array<any>;\n closePlugin(): Promise<void> {\n return this.call('closePlugin')\n }\n closePluginAndRefreshCart(): Promise<void> {\n return this.call('closePluginAndRefreshCart')\n }\n}\n\nexport type AvailableContext = AddToCartContext | EditProductLinesOnCartContext\n"],"file":"context.js"}
1
+ {"version":3,"sources":["../../../src/backoffice/context.ts"],"names":["ContextCallClass","AddToCartContext","closePlugin","call","closePluginAndAddToCart","closePluginAndRefreshCart","EditProductLinesOnCartContext"],"mappings":";;AAEA,SAAQA,gBAAR,QAA+B,UAA/B;AAEA,OAAO,MAAMC,gBAAN,SAA+BD,gBAA/B,CAAwF;AAAA;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;AAAA;;AAS7FE,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;;AAjB4F;AAoB/F,OAAO,MAAMG,6BAAN,SAA4CN,gBAA5C,CAAkH;AAAA;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;AAAA;;AAUvHE,EAAAA,WAAW,GAAkB;AAC3B,WAAO,KAAKC,IAAL,CAAU,aAAV,CAAP;AACD;;AACDE,EAAAA,yBAAyB,GAAkB;AACzC,WAAO,KAAKF,IAAL,CAAU,2BAAV,CAAP;AACD;;AAfsH","sourcesContent":["import {Backoffice} from \"@one-commerce/sdk-shared\";\n\nimport {ContextCallClass} from \"../utils\";\n\nexport class AddToCartContext extends ContextCallClass implements Backoffice.Context.AddToCart {\n productId: string;\n cartId: string | null;\n offerId: string | null;\n warehouses: Array<any>;\n warehouseId: string;\n meta: unknown;\n pluginProductLines: Array<any>;\n productLines: 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 class EditProductLinesOnCartContext extends ContextCallClass implements Backoffice.Context.EditProductLinesOnCart {\n productId: string;\n cartId: string | null;\n offerId: string | null;\n warehouses: Array<any>;\n warehouseId: string;\n meta: unknown;\n productLineId: string;\n productLines: Array<any>;\n pluginProductLines: Array<any>;\n closePlugin(): Promise<void> {\n return this.call('closePlugin')\n }\n closePluginAndRefreshCart(): Promise<void> {\n return this.call('closePluginAndRefreshCart')\n }\n}\n\nexport type BackofficeAvailableContext = AddToCartContext | EditProductLinesOnCartContext\n"],"file":"context.js"}
package/lib/esm/events.js CHANGED
@@ -17,6 +17,19 @@ class Events {
17
17
  this._callbacks[key].push(callback);
18
18
  }
19
19
 
20
+ off(key, callback) {
21
+ // if the key exists
22
+ if (this._callbacks[key] !== undefined) {
23
+ // iterate through the callbacks for the event key
24
+ for (let i = 0; i < this._callbacks[key].length; i++) {
25
+ // if the callback matches, remove it
26
+ if (this._callbacks[key][i] === callback) {
27
+ this._callbacks[key].splice(i, 1);
28
+ }
29
+ }
30
+ }
31
+ }
32
+
20
33
  emit(key, ...params) {
21
34
  // if the key exists
22
35
  if (this._callbacks[key] !== undefined) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/events.ts"],"names":["Events","constructor","_callbacks","on","key","callback","undefined","push","emit","params","i","length"],"mappings":";;AAAA,MAAMA,MAAN,CAAa;AAEXC,EAAAA,WAAW,GAAI;AAAA;;AACb,SAAKC,UAAL,GAAkB,EAAlB;AACD;;AAEDC,EAAAA,EAAE,CAAIC,GAAJ,EAAiBC,QAAjB,EAA6C;AAC7C;AACA,QAAI,KAAKH,UAAL,CAAgBE,GAAhB,MAAyBE,SAA7B,EAAwC;AAAE,WAAKJ,UAAL,CAAgBE,GAAhB,IAAuB,EAAvB;AAA2B,KAFxB,CAG7C;;;AACA,SAAKF,UAAL,CAAgBE,GAAhB,EAAqBG,IAArB,CAA0BF,QAA1B;AACD;;AAEDG,EAAAA,IAAI,CAACJ,GAAD,EAAc,GAAGK,MAAjB,EAAqC;AACvC;AACA,QAAI,KAAKP,UAAL,CAAgBE,GAAhB,MAAyBE,SAA7B,EAAwC;AACtC;AACA,WAAK,IAAII,CAAC,GAAC,CAAX,EAAcA,CAAC,GAAC,KAAKR,UAAL,CAAgBE,GAAhB,EAAqBO,MAArC,EAA6CD,CAAC,EAA9C,EAAkD;AAChD;AACA,aAAKR,UAAL,CAAgBE,GAAhB,EAAqBM,CAArB,EAAwB,GAAGD,MAA3B;AACD;AACF;AACF;;AAtBU;;AAyBb,eAAeT,MAAf","sourcesContent":["class Events {\n _callbacks: Record<string, any>\n constructor () {\n this._callbacks = {}\n }\n\n on<T>(key: string, callback: (arg: T) => void) {\n // create an empty array for the event key\n if (this._callbacks[key] === undefined) { this._callbacks[key] = [] }\n // save the callback in the array for the event key\n this._callbacks[key].push(callback)\n }\n\n emit(key: string, ...params: Array<any>) {\n // if the key exists\n if (this._callbacks[key] !== undefined) {\n // iterate through the callbacks for the event key\n for (let i=0; i<this._callbacks[key].length; i++) {\n // trigger the callbacks with all provided params\n this._callbacks[key][i](...params)\n }\n }\n }\n}\n\nexport default Events\n"],"file":"events.js"}
1
+ {"version":3,"sources":["../../src/events.ts"],"names":["Events","constructor","_callbacks","on","key","callback","undefined","push","off","i","length","splice","emit","params"],"mappings":";;AAAA,MAAMA,MAAN,CAAa;AAEXC,EAAAA,WAAW,GAAI;AAAA;;AACb,SAAKC,UAAL,GAAkB,EAAlB;AACD;;AAEDC,EAAAA,EAAE,CAAIC,GAAJ,EAAiBC,QAAjB,EAA6C;AAC7C;AACA,QAAI,KAAKH,UAAL,CAAgBE,GAAhB,MAAyBE,SAA7B,EAAwC;AAAE,WAAKJ,UAAL,CAAgBE,GAAhB,IAAuB,EAAvB;AAA2B,KAFxB,CAG7C;;;AACA,SAAKF,UAAL,CAAgBE,GAAhB,EAAqBG,IAArB,CAA0BF,QAA1B;AACD;;AAEDG,EAAAA,GAAG,CAAIJ,GAAJ,EAAiBC,QAAjB,EAA6C;AAC9C;AACA,QAAI,KAAKH,UAAL,CAAgBE,GAAhB,MAAyBE,SAA7B,EAAwC;AACtC;AACA,WAAK,IAAIG,CAAC,GAAC,CAAX,EAAcA,CAAC,GAAC,KAAKP,UAAL,CAAgBE,GAAhB,EAAqBM,MAArC,EAA6CD,CAAC,EAA9C,EAAkD;AAChD;AACA,YAAI,KAAKP,UAAL,CAAgBE,GAAhB,EAAqBK,CAArB,MAA4BJ,QAAhC,EAA0C;AACxC,eAAKH,UAAL,CAAgBE,GAAhB,EAAqBO,MAArB,CAA4BF,CAA5B,EAA+B,CAA/B;AACD;AACF;AACF;AACF;;AAEDG,EAAAA,IAAI,CAACR,GAAD,EAAc,GAAGS,MAAjB,EAAqC;AACvC;AACA,QAAI,KAAKX,UAAL,CAAgBE,GAAhB,MAAyBE,SAA7B,EAAwC;AACtC;AACA,WAAK,IAAIG,CAAC,GAAC,CAAX,EAAcA,CAAC,GAAC,KAAKP,UAAL,CAAgBE,GAAhB,EAAqBM,MAArC,EAA6CD,CAAC,EAA9C,EAAkD;AAChD;AACA,aAAKP,UAAL,CAAgBE,GAAhB,EAAqBK,CAArB,EAAwB,GAAGI,MAA3B;AACD;AACF;AACF;;AAnCU;;AAsCb,eAAeb,MAAf","sourcesContent":["class Events {\n _callbacks: Record<string, any>\n constructor () {\n this._callbacks = {}\n }\n\n on<T>(key: string, callback: (arg: T) => void) {\n // create an empty array for the event key\n if (this._callbacks[key] === undefined) { this._callbacks[key] = [] }\n // save the callback in the array for the event key\n this._callbacks[key].push(callback)\n }\n\n off<T>(key: string, callback: (arg: T) => void) {\n // if the key exists\n if (this._callbacks[key] !== undefined) {\n // iterate through the callbacks for the event key\n for (let i=0; i<this._callbacks[key].length; i++) {\n // if the callback matches, remove it\n if (this._callbacks[key][i] === callback) {\n this._callbacks[key].splice(i, 1)\n }\n }\n }\n }\n\n emit(key: string, ...params: Array<any>) {\n // if the key exists\n if (this._callbacks[key] !== undefined) {\n // iterate through the callbacks for the event key\n for (let i=0; i<this._callbacks[key].length; i++) {\n // trigger the callbacks with all provided params\n this._callbacks[key][i](...params)\n }\n }\n }\n}\n\nexport default Events\n"],"file":"events.js"}