@one-commerce/sdk-core 2.3.5 → 2.3.6
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/package.json +3 -3
- package/lib/bundles/bundle.esm.js +0 -1577
- package/lib/bundles/bundle.esm.js.map +0 -1
- package/lib/bundles/bundle.esm.min.js +0 -2
- package/lib/bundles/bundle.esm.min.js.map +0 -1
- package/lib/bundles/bundle.umd.js +0 -1593
- package/lib/bundles/bundle.umd.js.map +0 -1
- package/lib/bundles/bundle.umd.min.js +0 -2
- package/lib/bundles/bundle.umd.min.js.map +0 -1
- package/lib/cjs/backoffice/context.js +0 -196
- package/lib/cjs/backoffice/context.js.map +0 -1
- package/lib/cjs/backoffice/services.js +0 -298
- package/lib/cjs/backoffice/services.js.map +0 -1
- package/lib/cjs/events.js +0 -75
- package/lib/cjs/events.js.map +0 -1
- package/lib/cjs/index.js +0 -418
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/shop/context.js +0 -144
- package/lib/cjs/shop/context.js.map +0 -1
- package/lib/cjs/shop/services.js +0 -435
- package/lib/cjs/shop/services.js.map +0 -1
- package/lib/cjs/utils.js +0 -111
- package/lib/cjs/utils.js.map +0 -1
- package/lib/esm/backoffice/context.js +0 -100
- package/lib/esm/backoffice/context.js.map +0 -1
- package/lib/esm/backoffice/services.js +0 -114
- package/lib/esm/backoffice/services.js.map +0 -1
- package/lib/esm/events.js +0 -47
- package/lib/esm/events.js.map +0 -1
- package/lib/esm/index.js +0 -244
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/shop/context.js +0 -70
- package/lib/esm/shop/context.js.map +0 -1
- package/lib/esm/shop/services.js +0 -218
- package/lib/esm/shop/services.js.map +0 -1
- package/lib/esm/utils.js +0 -47
- package/lib/esm/utils.js.map +0 -1
- package/lib/types/backoffice/context.d.ts +0 -66
- package/lib/types/backoffice/context.d.ts.map +0 -1
- package/lib/types/backoffice/services.d.ts +0 -49
- package/lib/types/backoffice/services.d.ts.map +0 -1
- package/lib/types/events.d.ts +0 -9
- package/lib/types/events.d.ts.map +0 -1
- package/lib/types/iframe-channel.d.ts +0 -19
- package/lib/types/index.d.ts +0 -107
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/shop/context.d.ts +0 -30
- package/lib/types/shop/context.d.ts.map +0 -1
- package/lib/types/shop/services.d.ts +0 -161
- package/lib/types/shop/services.d.ts.map +0 -1
- package/lib/types/utils.d.ts +0 -12
- package/lib/types/utils.d.ts.map +0 -1
package/lib/cjs/index.js
DELETED
|
@@ -1,418 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "BackofficeAddToCartContext", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function get() {
|
|
11
|
-
return _context.AddToCartContext;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
Object.defineProperty(exports, "BackofficeDocumentsContext", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function get() {
|
|
17
|
-
return _context.DocumentsContext;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
Object.defineProperty(exports, "BackofficeEditProductLinesOnCartContext", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: function get() {
|
|
23
|
-
return _context.EditProductLinesOnCartContext;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
exports.SdkEvents = exports.BackofficeSdk = void 0;
|
|
27
|
-
Object.defineProperty(exports, "ShopAddToCartContext", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function get() {
|
|
30
|
-
return _context2.AddToCartContext;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(exports, "ShopEditProductLinesOnCartContext", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: function get() {
|
|
36
|
-
return _context2.EditProductLinesOnCartContext;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
exports.ShopSdk = void 0;
|
|
40
|
-
|
|
41
|
-
var _sdkShared = require("@one-commerce/sdk-shared");
|
|
42
|
-
|
|
43
|
-
var _iframeChannel = _interopRequireDefault(require("iframe-channel"));
|
|
44
|
-
|
|
45
|
-
var _context = require("./backoffice/context");
|
|
46
|
-
|
|
47
|
-
var _services = require("./backoffice/services");
|
|
48
|
-
|
|
49
|
-
var _events = _interopRequireDefault(require("./events"));
|
|
50
|
-
|
|
51
|
-
var _context2 = require("./shop/context");
|
|
52
|
-
|
|
53
|
-
var _services2 = require("./shop/services");
|
|
54
|
-
|
|
55
|
-
var _utils = require("./utils");
|
|
56
|
-
|
|
57
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
58
|
-
|
|
59
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
60
|
-
|
|
61
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
62
|
-
|
|
63
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
64
|
-
|
|
65
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
66
|
-
|
|
67
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
68
|
-
|
|
69
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
70
|
-
|
|
71
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
72
|
-
|
|
73
|
-
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); } }
|
|
74
|
-
|
|
75
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
76
|
-
|
|
77
|
-
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); }
|
|
78
|
-
|
|
79
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
80
|
-
|
|
81
|
-
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); }; }
|
|
82
|
-
|
|
83
|
-
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); }
|
|
84
|
-
|
|
85
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
86
|
-
|
|
87
|
-
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; } }
|
|
88
|
-
|
|
89
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
90
|
-
|
|
91
|
-
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; }
|
|
92
|
-
|
|
93
|
-
var SdkInternalEvents;
|
|
94
|
-
|
|
95
|
-
(function (SdkInternalEvents) {
|
|
96
|
-
SdkInternalEvents["INIT"] = "INIT";
|
|
97
|
-
SdkInternalEvents["UPDATE"] = "UPDATE";
|
|
98
|
-
})(SdkInternalEvents || (SdkInternalEvents = {}));
|
|
99
|
-
|
|
100
|
-
var SdkEvents;
|
|
101
|
-
exports.SdkEvents = SdkEvents;
|
|
102
|
-
|
|
103
|
-
(function (SdkEvents) {
|
|
104
|
-
SdkEvents["INIT"] = "INIT";
|
|
105
|
-
SdkEvents["UPDATE"] = "UPDATE";
|
|
106
|
-
})(SdkEvents || (exports.SdkEvents = SdkEvents = {}));
|
|
107
|
-
|
|
108
|
-
var Sdk = /*#__PURE__*/function (_Events) {
|
|
109
|
-
_inherits(Sdk, _Events);
|
|
110
|
-
|
|
111
|
-
var _super = _createSuper(Sdk);
|
|
112
|
-
|
|
113
|
-
function Sdk(options) {
|
|
114
|
-
var _this;
|
|
115
|
-
|
|
116
|
-
_classCallCheck(this, Sdk);
|
|
117
|
-
|
|
118
|
-
_this = _super.call(this);
|
|
119
|
-
|
|
120
|
-
_defineProperty(_assertThisInitialized(_this), "channel", void 0);
|
|
121
|
-
|
|
122
|
-
_defineProperty(_assertThisInitialized(_this), "autoheight", true);
|
|
123
|
-
|
|
124
|
-
_defineProperty(_assertThisInitialized(_this), "heightMutationObserver", null);
|
|
125
|
-
|
|
126
|
-
_defineProperty(_assertThisInitialized(_this), "origin", void 0);
|
|
127
|
-
|
|
128
|
-
_defineProperty(_assertThisInitialized(_this), "isInitialized", false);
|
|
129
|
-
|
|
130
|
-
_defineProperty(_assertThisInitialized(_this), "instances", void 0);
|
|
131
|
-
|
|
132
|
-
_defineProperty(_assertThisInitialized(_this), "contextClass", void 0);
|
|
133
|
-
|
|
134
|
-
_this.initializeServiceGetters();
|
|
135
|
-
|
|
136
|
-
_this.origin = options.origin;
|
|
137
|
-
_this.channel = new _iframeChannel["default"]({
|
|
138
|
-
targetOrigin: _this.origin,
|
|
139
|
-
target: window.parent
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
_this.channel.subscribe(_sdkShared.Message.INIT, function (payload) {
|
|
143
|
-
Sdk.log('Handling INIT message');
|
|
144
|
-
Object.entries(_this.instances).forEach(function (_ref) {
|
|
145
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
146
|
-
key = _ref2[0],
|
|
147
|
-
value = _ref2[1];
|
|
148
|
-
|
|
149
|
-
if (value instanceof _utils.BaseCallClass) {
|
|
150
|
-
value.update(payload);
|
|
151
|
-
} else {
|
|
152
|
-
var attributesForKey = payload[key];
|
|
153
|
-
|
|
154
|
-
if (typeof attributesForKey !== 'undefined') {
|
|
155
|
-
_utils.BaseCallClass.update(value, payload[key]);
|
|
156
|
-
} else {
|
|
157
|
-
Sdk.warn("Missing attributes for ".concat(key, " in "), payload);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
Sdk.log('Emitting INIT with payload ', _this.instances);
|
|
162
|
-
_this.isInitialized = true;
|
|
163
|
-
|
|
164
|
-
_this.emit(SdkInternalEvents.INIT, _this.instances);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
_this.channel.subscribe(_sdkShared.Message.UPDATE, function (payload) {
|
|
168
|
-
Sdk.log('Emitting UPDATE with payload ', payload);
|
|
169
|
-
|
|
170
|
-
_this.emit(SdkInternalEvents.UPDATE, payload);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
_this.channel.subscribe(_sdkShared.Message.FRAME_HEIGHT_REQUEST, function (payload) {
|
|
174
|
-
if (_this.autoheight) {
|
|
175
|
-
Sdk.log('Request for iframe height');
|
|
176
|
-
|
|
177
|
-
_this.sendFrameHeight();
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
_this.channel.connect().then(function () {
|
|
182
|
-
Sdk.log('Connected with ONe SDK');
|
|
183
|
-
|
|
184
|
-
if (_this.autoheight) {
|
|
185
|
-
_this.initializeHeightObserver();
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
_this.setupOptions(options);
|
|
190
|
-
|
|
191
|
-
Sdk.log('Initialized.');
|
|
192
|
-
return _this;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
_createClass(Sdk, [{
|
|
196
|
-
key: "initializeServiceGetters",
|
|
197
|
-
value: function initializeServiceGetters() {
|
|
198
|
-
var _this2 = this;
|
|
199
|
-
|
|
200
|
-
if (this.instances) {
|
|
201
|
-
Object.keys(this.instances).forEach(function (serviceName) {
|
|
202
|
-
Object.defineProperty(_this2, serviceName, {
|
|
203
|
-
get: function get() {
|
|
204
|
-
return _this2.isInitialized ? _this2.instances[serviceName] : null;
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}, {
|
|
211
|
-
key: "initializeContextClass",
|
|
212
|
-
value: function initializeContextClass() {
|
|
213
|
-
if (this.contextClass) {
|
|
214
|
-
return new this.contextClass(this.callFunction.bind(this));
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return {};
|
|
218
|
-
}
|
|
219
|
-
}, {
|
|
220
|
-
key: "sendFrameHeight",
|
|
221
|
-
value: function sendFrameHeight() {
|
|
222
|
-
this.channel.postMessage(_sdkShared.Message.FRAME_HEIGHT_CHANGE, document.body.scrollHeight);
|
|
223
|
-
}
|
|
224
|
-
}, {
|
|
225
|
-
key: "initializeHeightObserver",
|
|
226
|
-
value: function initializeHeightObserver() {
|
|
227
|
-
var _this3 = this;
|
|
228
|
-
|
|
229
|
-
if ("MutationObserver" in window) {
|
|
230
|
-
var onMutationObserved = function onMutationObserved() {
|
|
231
|
-
_this3.sendFrameHeight();
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
var target = document.querySelector('body'),
|
|
235
|
-
config = {
|
|
236
|
-
attributes: true,
|
|
237
|
-
attributeOldValue: false,
|
|
238
|
-
characterData: true,
|
|
239
|
-
characterDataOldValue: false,
|
|
240
|
-
childList: true,
|
|
241
|
-
subtree: true
|
|
242
|
-
};
|
|
243
|
-
this.heightMutationObserver = new MutationObserver(onMutationObserved);
|
|
244
|
-
Sdk.log('Create body MutationObserver');
|
|
245
|
-
this.heightMutationObserver.observe(target, config);
|
|
246
|
-
} else {
|
|
247
|
-
Sdk.warn('MutationObserver not available. Auto-height functionality disabled.');
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}, {
|
|
251
|
-
key: "setupOptions",
|
|
252
|
-
value: function setupOptions(options) {
|
|
253
|
-
if (options) {
|
|
254
|
-
if (typeof options.debug !== 'undefined') {
|
|
255
|
-
Sdk.debug = options.debug;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (typeof options.autoheight !== 'undefined') {
|
|
259
|
-
this.autoheight = options.autoheight;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
this.contextClass = options.context;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}, {
|
|
266
|
-
key: "callFunction",
|
|
267
|
-
value: function callFunction(service, fun) {
|
|
268
|
-
var _this4 = this;
|
|
269
|
-
|
|
270
|
-
var callId = (0, _utils.generateCallId)();
|
|
271
|
-
|
|
272
|
-
if (this.isInitialized) {
|
|
273
|
-
for (var _len = arguments.length, payload = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
274
|
-
payload[_key - 2] = arguments[_key];
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
Sdk.log("Call ID ".concat(callId, " for ").concat(service, ":").concat(fun), payload);
|
|
278
|
-
this.channel.postMessage(_sdkShared.Message.METHOD_CALL, {
|
|
279
|
-
callId: callId,
|
|
280
|
-
service: service,
|
|
281
|
-
method: fun,
|
|
282
|
-
payload: payload
|
|
283
|
-
});
|
|
284
|
-
return new Promise(function (resolve, reject) {
|
|
285
|
-
var onChannelMessage = function onChannelMessage(response) {
|
|
286
|
-
if (response.callId === callId) {
|
|
287
|
-
_this4.channel.unsubscribe(_sdkShared.Message.METHOD_RESULT, onChannelMessage);
|
|
288
|
-
|
|
289
|
-
if (response !== null && response !== void 0 && response.isException) {
|
|
290
|
-
return reject(response.result);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return resolve(response.result);
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
_this4.channel.subscribe(_sdkShared.Message.METHOD_RESULT, onChannelMessage);
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
Sdk.log('SDK is not initialized!');
|
|
302
|
-
return Promise.resolve(null);
|
|
303
|
-
}
|
|
304
|
-
}, {
|
|
305
|
-
key: "navigate",
|
|
306
|
-
value: function navigate(event) {
|
|
307
|
-
this.channel.postMessage(_sdkShared.Message.NAVIGATION_PUSH, event);
|
|
308
|
-
}
|
|
309
|
-
}], [{
|
|
310
|
-
key: "log",
|
|
311
|
-
value: function log() {
|
|
312
|
-
var _console;
|
|
313
|
-
|
|
314
|
-
for (var _len2 = arguments.length, data = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
315
|
-
data[_key2] = arguments[_key2];
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
Sdk.debug && (_console = console).log.apply(_console, ['[SDK Core] '].concat(data));
|
|
319
|
-
}
|
|
320
|
-
}, {
|
|
321
|
-
key: "warn",
|
|
322
|
-
value: function warn() {
|
|
323
|
-
var _console2;
|
|
324
|
-
|
|
325
|
-
for (var _len3 = arguments.length, data = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
326
|
-
data[_key3] = arguments[_key3];
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
(_console2 = console).warn.apply(_console2, ['[SDK Core] '].concat(data));
|
|
330
|
-
}
|
|
331
|
-
}]);
|
|
332
|
-
|
|
333
|
-
return Sdk;
|
|
334
|
-
}(_events["default"]);
|
|
335
|
-
|
|
336
|
-
_defineProperty(Sdk, "debug", false);
|
|
337
|
-
|
|
338
|
-
var BackofficeSdk = /*#__PURE__*/function (_Sdk) {
|
|
339
|
-
_inherits(BackofficeSdk, _Sdk);
|
|
340
|
-
|
|
341
|
-
var _super2 = _createSuper(BackofficeSdk);
|
|
342
|
-
|
|
343
|
-
function BackofficeSdk() {
|
|
344
|
-
var _this5;
|
|
345
|
-
|
|
346
|
-
_classCallCheck(this, BackofficeSdk);
|
|
347
|
-
|
|
348
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
349
|
-
args[_key4] = arguments[_key4];
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
_this5 = _super2.call.apply(_super2, [this].concat(args));
|
|
353
|
-
|
|
354
|
-
_defineProperty(_assertThisInitialized(_this5), "instances", {
|
|
355
|
-
route: {
|
|
356
|
-
hash: '',
|
|
357
|
-
query: {}
|
|
358
|
-
},
|
|
359
|
-
catalog: new _services.BackofficeCatalog(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
360
|
-
user: new _services.BackofficeUser(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
361
|
-
tenant: new _services.BackofficeTenant(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
362
|
-
layout: new _services.BackofficeLayout(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
363
|
-
authorization: new _services.BackofficeAuthorization(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
364
|
-
customer: new _services.BackofficeCustomer(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
365
|
-
plugin: new _services.BackofficePlugin(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
366
|
-
orderpath: new _services.BackofficeOrderpath(_this5.callFunction.bind(_assertThisInitialized(_this5))),
|
|
367
|
-
context: _this5.initializeContextClass()
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
return _this5;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
return _createClass(BackofficeSdk);
|
|
374
|
-
}(Sdk);
|
|
375
|
-
|
|
376
|
-
exports.BackofficeSdk = BackofficeSdk;
|
|
377
|
-
|
|
378
|
-
var ShopSdk = /*#__PURE__*/function (_Sdk2) {
|
|
379
|
-
_inherits(ShopSdk, _Sdk2);
|
|
380
|
-
|
|
381
|
-
var _super3 = _createSuper(ShopSdk);
|
|
382
|
-
|
|
383
|
-
function ShopSdk() {
|
|
384
|
-
var _this6;
|
|
385
|
-
|
|
386
|
-
_classCallCheck(this, ShopSdk);
|
|
387
|
-
|
|
388
|
-
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
389
|
-
args[_key5] = arguments[_key5];
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
_this6 = _super3.call.apply(_super3, [this].concat(args));
|
|
393
|
-
|
|
394
|
-
_defineProperty(_assertThisInitialized(_this6), "instances", {
|
|
395
|
-
route: {
|
|
396
|
-
hash: '',
|
|
397
|
-
query: {}
|
|
398
|
-
},
|
|
399
|
-
authorization: new _services2.ShopAuthorization(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
400
|
-
cart: new _services2.ShopCart(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
401
|
-
catalog: new _services2.ShopCatalog(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
402
|
-
account: new _services2.ShopAccount(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
403
|
-
utils: new _services2.ShopUtils(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
404
|
-
config: new _services2.ShopConfig(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
405
|
-
tenant: new _services2.ShopTenant(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
406
|
-
wishlist: new _services2.ShopWishlist(_this6.callFunction.bind(_assertThisInitialized(_this6))),
|
|
407
|
-
context: _this6.initializeContextClass(),
|
|
408
|
-
plugin: new _services2.ShopPlugin(_this6.callFunction.bind(_assertThisInitialized(_this6)))
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
return _this6;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
return _createClass(ShopSdk);
|
|
415
|
-
}(Sdk);
|
|
416
|
-
|
|
417
|
-
exports.ShopSdk = ShopSdk;
|
|
418
|
-
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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","postMessage","FRAME_HEIGHT_CHANGE","document","body","scrollHeight","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","ShopTenant","wishlist","ShopWishlist","ShopPlugin"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAMA;;AAEA;;AAMA;;AAUA;;AACA;;AAKA;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,IAkCe;;AAAA,6EAjCH,IAiCG;;AAAA;;AAAA,oEA/BpB,KA+BoB;;AAAA;;AAAA;;AAElC,UAAKC,wBA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pB,MAAAA,KAAK,EAAE;AACLC,QAAAA,IAAI,EAAE,EADD;AAELC,QAAAA,KAAK,EAAE;AAFF,OADG;AAKVS,MAAAA,aAAa,EAAE,IAAIU,4BAAJ,CAAsB,OAAK9D,YAAL,CAAkBC,IAAlB,gCAAtB,CALL;AAMV8D,MAAAA,IAAI,EAAE,IAAIC,mBAAJ,CAAa,OAAKhE,YAAL,CAAkBC,IAAlB,gCAAb,CANI;AAOV2C,MAAAA,OAAO,EAAE,IAAIqB,sBAAJ,CAAgB,OAAKjE,YAAL,CAAkBC,IAAlB,gCAAhB,CAPC;AAQViE,MAAAA,OAAO,EAAE,IAAIC,sBAAJ,CAAgB,OAAKnE,YAAL,CAAkBC,IAAlB,gCAAhB,CARC;AASVmE,MAAAA,KAAK,EAAE,IAAIC,oBAAJ,CAAc,OAAKrE,YAAL,CAAkBC,IAAlB,gCAAd,CATG;AAUVQ,MAAAA,MAAM,EAAE,IAAI6D,qBAAJ,CAAe,OAAKtE,YAAL,CAAkBC,IAAlB,gCAAf,CAVE;AAWV+C,MAAAA,MAAM,EAAE,IAAIuB,qBAAJ,CAAe,OAAKvE,YAAL,CAAkBC,IAAlB,gCAAf,CAXE;AAYVuE,MAAAA,QAAQ,EAAE,IAAIC,uBAAJ,CAAiB,OAAKzE,YAAL,CAAkBC,IAAlB,gCAAjB,CAZA;AAaVmB,MAAAA,OAAO,EAAE,OAAKwC,sBAAL,EAbC;AAcVJ,MAAAA,MAAM,EAAE,IAAIkB,qBAAJ,CAAe,OAAK1E,YAAL,CAAkBC,IAAlB,gCAAf;AAdE,K;;;;;;EADezC,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 as BackofficeAddToCartContext,\n BackofficeAvailableContext,\n DocumentsContext as BackofficeDocumentsContext,\n EditProductLinesOnCartContext as BackofficeEditProductLinesOnCartContext,\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 AddToCartContext as ShopAddToCartContext,\n ShopAvailableContext,\n EditProductLinesOnCartContext as ShopEditProductLinesOnCartContext\n} from \"./shop/context\";\nimport {\n ShopAccount,\n ShopAuthorization,\n ShopCart,\n ShopCatalog,\n ShopConfig,\n ShopPlugin,\n ShopTenant,\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 this.channel.postMessage(\n Message.FRAME_HEIGHT_CHANGE,\n document.body.scrollHeight\n )\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 tenant: ShopTenant,\n plugin: ShopPlugin,\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 tenant: new ShopTenant(this.callFunction.bind(this)),\n wishlist: new ShopWishlist(this.callFunction.bind(this)),\n context: this.initializeContextClass(),\n plugin: new ShopPlugin(this.callFunction.bind(this)),\n }\n}\n\nexport {\n BackofficeDocumentsContext,\n BackofficeAddToCartContext,\n BackofficeEditProductLinesOnCartContext,\n ShopAddToCartContext,\n ShopEditProductLinesOnCartContext,\n}\n"],"file":"index.js"}
|
package/lib/cjs/shop/context.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
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.EditProductLinesOnCartContext = 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
|
-
_defineProperty(_assertThisInitialized(_this), "productAmount", void 0);
|
|
65
|
-
|
|
66
|
-
return _this;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
_createClass(AddToCartContext, [{
|
|
70
|
-
key: "closePlugin",
|
|
71
|
-
value: function closePlugin() {
|
|
72
|
-
return this.call('closePlugin');
|
|
73
|
-
}
|
|
74
|
-
}, {
|
|
75
|
-
key: "closePluginAndAddToCart",
|
|
76
|
-
value: function closePluginAndAddToCart() {
|
|
77
|
-
return this.call('closePluginAndAddToCart');
|
|
78
|
-
}
|
|
79
|
-
}, {
|
|
80
|
-
key: "closePluginAndRefreshCart",
|
|
81
|
-
value: function closePluginAndRefreshCart() {
|
|
82
|
-
return this.call('closePluginAndRefreshCart');
|
|
83
|
-
}
|
|
84
|
-
}]);
|
|
85
|
-
|
|
86
|
-
return AddToCartContext;
|
|
87
|
-
}(_utils.ContextCallClass);
|
|
88
|
-
|
|
89
|
-
exports.AddToCartContext = AddToCartContext;
|
|
90
|
-
|
|
91
|
-
var EditProductLinesOnCartContext = /*#__PURE__*/function (_ContextCallClass2) {
|
|
92
|
-
_inherits(EditProductLinesOnCartContext, _ContextCallClass2);
|
|
93
|
-
|
|
94
|
-
var _super2 = _createSuper(EditProductLinesOnCartContext);
|
|
95
|
-
|
|
96
|
-
function EditProductLinesOnCartContext() {
|
|
97
|
-
var _this2;
|
|
98
|
-
|
|
99
|
-
_classCallCheck(this, EditProductLinesOnCartContext);
|
|
100
|
-
|
|
101
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
102
|
-
args[_key2] = arguments[_key2];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
_this2 = _super2.call.apply(_super2, [this].concat(args));
|
|
106
|
-
|
|
107
|
-
_defineProperty(_assertThisInitialized(_this2), "productId", void 0);
|
|
108
|
-
|
|
109
|
-
_defineProperty(_assertThisInitialized(_this2), "cartId", void 0);
|
|
110
|
-
|
|
111
|
-
_defineProperty(_assertThisInitialized(_this2), "warehouses", void 0);
|
|
112
|
-
|
|
113
|
-
_defineProperty(_assertThisInitialized(_this2), "warehouseId", void 0);
|
|
114
|
-
|
|
115
|
-
_defineProperty(_assertThisInitialized(_this2), "meta", void 0);
|
|
116
|
-
|
|
117
|
-
_defineProperty(_assertThisInitialized(_this2), "productLineId", void 0);
|
|
118
|
-
|
|
119
|
-
_defineProperty(_assertThisInitialized(_this2), "productLines", void 0);
|
|
120
|
-
|
|
121
|
-
_defineProperty(_assertThisInitialized(_this2), "pluginProductLines", void 0);
|
|
122
|
-
|
|
123
|
-
_defineProperty(_assertThisInitialized(_this2), "productAmount", void 0);
|
|
124
|
-
|
|
125
|
-
return _this2;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
_createClass(EditProductLinesOnCartContext, [{
|
|
129
|
-
key: "closePlugin",
|
|
130
|
-
value: function closePlugin() {
|
|
131
|
-
return this.call('closePlugin');
|
|
132
|
-
}
|
|
133
|
-
}, {
|
|
134
|
-
key: "closePluginAndRefreshCart",
|
|
135
|
-
value: function closePluginAndRefreshCart() {
|
|
136
|
-
return this.call('closePluginAndRefreshCart');
|
|
137
|
-
}
|
|
138
|
-
}]);
|
|
139
|
-
|
|
140
|
-
return EditProductLinesOnCartContext;
|
|
141
|
-
}(_utils.ContextCallClass);
|
|
142
|
-
|
|
143
|
-
exports.EditProductLinesOnCartContext = EditProductLinesOnCartContext;
|
|
144
|
-
//# sourceMappingURL=context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/shop/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 {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 productAmount: number;\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 Shop.Context.EditProductLinesOnCart {\n productId: string;\n cartId: string | null;\n warehouses: Array<any>;\n warehouseId: string;\n meta: unknown;\n productLineId: string;\n productLines: Array<any>;\n pluginProductLines: Array<any>;\n productAmount: number;\n closePlugin(): Promise<void> {\n return this.call('closePlugin')\n }\n closePluginAndRefreshCart(): Promise<void> {\n return this.call('closePluginAndRefreshCart')\n }\n}\n\nexport type ShopAvailableContext = AddToCartContext | EditProductLinesOnCartContext\n"],"file":"context.js"}
|