@savafeed/cart-api-sdk 1.0.11 → 1.0.13

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.
@@ -1,786 +1,7 @@
1
1
  'use strict';
2
2
 
3
- require('reflect-metadata');
4
-
5
- class TypeSpecifier {
6
- static isClass(input) {
7
- return (!TypeSpecifier.isFunction(input) &&
8
- !TypeSpecifier.isFunctionByTryCall(input) &&
9
- TypeSpecifier.isClassByStringLiteral(input));
10
- }
11
- static isClassByStringLiteral(input) {
12
- const functionString = input.toString();
13
- return !!functionString.startsWith('class');
14
- }
15
- static isFunction(input) {
16
- return typeof input !== 'function';
17
- }
18
- static isFunctionByTryCall(input) {
19
- try {
20
- input();
21
- return true;
22
- }
23
- catch (error) {
24
- return false;
25
- }
26
- }
27
- }
28
-
29
- class ModuleRef {
30
- parentContainer;
31
- module;
32
- controllers = new Map();
33
- providers = new Map();
34
- constructor(parentContainer, module) {
35
- this.parentContainer = parentContainer;
36
- this.module = module;
37
- this["registerProviders" /* E_REGISTER_CALL_ORDER.first */]();
38
- this["registerControllers" /* E_REGISTER_CALL_ORDER.second */]();
39
- }
40
- ;
41
- registerProviders() {
42
- const providers = this.module.providers;
43
- if (!providers)
44
- return;
45
- for (const provider of providers) {
46
- if (this.providers.has(provider))
47
- continue;
48
- const dependencyTokens = Reflect.getMetadata("design:paramtypes" /* E_TOKENS.DESIGN_PARAMTYPES */, provider);
49
- const dependencies = [];
50
- dependencyTokens?.forEach((dependencyToken, index) => {
51
- if (!TypeSpecifier.isClass(dependencyToken)) {
52
- const injectTokens = Reflect.getMetadata("inject:tokens" /* E_TOKENS.INJECT_TOKENS */, provider) || [];
53
- const injectToken = injectTokens.find((injectObject) => injectObject.index === index);
54
- if (!this.parentContainer.providers.has(injectToken?.token))
55
- return console.warn(`[WARN] (Inject) ${injectToken} is not provide in`, this.parentContainer);
56
- dependencies.push(this.parentContainer.providers.get(injectToken?.token));
57
- }
58
- else {
59
- if (!this.parentContainer.providers.has(dependencyToken))
60
- return console.warn(`[WARN] (Injectable) ${dependencyToken} is not provide in`, this.parentContainer);
61
- dependencies.push(this.parentContainer.providers.get(dependencyToken));
62
- }
63
- });
64
- let providerToken;
65
- let providerInstance;
66
- if (provider?.token) {
67
- const injectProvider = this.getInjectProviderWithInstance(provider);
68
- if (!injectProvider)
69
- return console.warn(`[WARN] Provider type is not Inject. ${provider.token} is not provide in`, this.parentContainer);
70
- providerToken = injectProvider.token;
71
- providerInstance = injectProvider.instance;
72
- Reflect.defineMetadata(providerToken, providerInstance, this.module);
73
- }
74
- else {
75
- providerToken = provider;
76
- providerInstance = new provider(...dependencies);
77
- Reflect.defineMetadata(providerToken, provider, this.module);
78
- }
79
- this.providers.set(providerToken, providerInstance);
80
- }
81
- }
82
- ;
83
- getInjectProviderWithInstance(injectProvider) {
84
- if (!injectProvider?.token)
85
- return null;
86
- let injectInstance;
87
- if (injectProvider?.useValue) {
88
- injectInstance = injectProvider.useValue;
89
- }
90
- if (injectProvider?.useFactory) {
91
- const factory = injectProvider.useFactory;
92
- try {
93
- if (TypeSpecifier.isClass(factory)) {
94
- injectInstance = new injectProvider.useFactory();
95
- }
96
- else {
97
- injectInstance = injectProvider.useFactory();
98
- }
99
- }
100
- catch (error) {
101
- console.error('A factory can be either a function or a class.', error);
102
- return null;
103
- }
104
- }
105
- return {
106
- token: injectProvider.token,
107
- instance: injectInstance,
108
- };
109
- }
110
- ;
111
- registerControllers() {
112
- const controllers = this.module.controllers;
113
- if (!controllers)
114
- return;
115
- for (const controller of controllers) {
116
- if (this.controllers.has(controller))
117
- continue;
118
- const dependencyTokens = Reflect.getMetadata("design:paramtypes" /* E_TOKENS.DESIGN_PARAMTYPES */, controller);
119
- const dependencies = [];
120
- dependencyTokens?.forEach((dependencyToken) => {
121
- if (!this.providers.has(dependencyToken))
122
- return console.warn(`[WARN] ${dependencyToken} is not provide in`, String(this));
123
- dependencies.push(this.providers.get(dependencyToken));
124
- });
125
- const controllerToken = Reflect.getMetadata("controller:prefix" /* E_TOKENS.CONTROLLER_PREFIX */, controller) || controller;
126
- const controllerInstance = new controller(...dependencies);
127
- this.controllers.set(controllerToken, controllerInstance);
128
- }
129
- }
130
- ;
131
- getController(controllerToken) {
132
- return this.controllers.get(controllerToken);
133
- }
134
- ;
135
- }
136
-
137
- function of(mapper) {
138
- const entryList = Array.from(mapper.entries());
139
- return entryList.map((entry) => {
140
- return {
141
- key: entry[0],
142
- value: entry[1],
143
- };
144
- });
145
- }
146
-
147
- class Pool {
148
- factory;
149
- _pool = new Map();
150
- constructor(factory) {
151
- this.factory = factory;
152
- }
153
- ;
154
- acquire() {
155
- return of(this._pool)
156
- .map(({ value }) => value)
157
- .map(this.factory);
158
- }
159
- ;
160
- release(data) {
161
- this._pool.delete(data);
162
- }
163
- ;
164
- append(data) {
165
- this._pool.set(data, data);
166
- }
167
- ;
168
- }
169
-
170
- class AuditContainer {
171
- providers = new Map();
172
- providersPool = new Pool((data) => data);
173
- addProviderToPool(type, providerToken) {
174
- this.providersPool.append({
175
- provider: providerToken,
176
- type,
177
- });
178
- }
179
- ;
180
- registerInnerInject(injectProvider) {
181
- this.registerGlobalInject(injectProvider);
182
- }
183
- processProvidersInPool() {
184
- const providers = this.providersPool.acquire();
185
- const providersByType = {
186
- ["inject" /* E_PROVIDER_TYPES.INJECT */]: [],
187
- ["injectable" /* E_PROVIDER_TYPES.INJECTABLE */]: [],
188
- };
189
- providers.forEach(({ type, provider }) => {
190
- const condition = type === "injectable" /* E_PROVIDER_TYPES.INJECTABLE */ || type === "inject" /* E_PROVIDER_TYPES.INJECT */;
191
- if (condition) {
192
- providersByType[type].push(provider);
193
- }
194
- });
195
- this.dispatchRegisterProviders(providersByType, "inject" /* E_PROVIDER_TYPES.INJECT */);
196
- this.dispatchRegisterProviders(providersByType, "injectable" /* E_PROVIDER_TYPES.INJECTABLE */);
197
- }
198
- ;
199
- dispatchRegisterProviders(providersByType, type) {
200
- providersByType[type].forEach((provider) => {
201
- switch (type) {
202
- case "inject" /* E_PROVIDER_TYPES.INJECT */:
203
- this.registerGlobalInject(provider);
204
- break;
205
- case "injectable" /* E_PROVIDER_TYPES.INJECTABLE */:
206
- this.registerGlobalInjectable(provider);
207
- break;
208
- }
209
- this.providersPool.release(provider);
210
- });
211
- }
212
- ;
213
- registerGlobalInjectable(providerToken) {
214
- if (providerToken?.token) {
215
- if (this.providers.has(providerToken.token))
216
- return this.providers.get(providerToken.token);
217
- }
218
- else {
219
- if (this.providers.has(providerToken))
220
- return this.providers.get(providerToken);
221
- }
222
- const dependencies = [];
223
- const dependenciesTokens = Reflect.getMetadata("design:paramtypes" /* E_TOKENS.DESIGN_PARAMTYPES */, providerToken);
224
- const injectTokens = Reflect.getMetadata("inject:tokens" /* E_TOKENS.INJECT_TOKENS */, providerToken);
225
- dependenciesTokens?.forEach((dependencyToken, index) => {
226
- const injectToken = injectTokens?.find((injectTokenObject) => injectTokenObject.index === index);
227
- let injectInstance = injectToken || dependencyToken;
228
- const dependency = this.registerGlobalInjectable(injectInstance);
229
- dependencies.push(dependency);
230
- });
231
- const provider = new providerToken(...dependencies);
232
- this.providers.set(providerToken, provider);
233
- return provider;
234
- }
235
- ;
236
- registerGlobalInject(injectProvider) {
237
- let injectInstance;
238
- if (injectProvider?.useValue) {
239
- injectInstance = injectProvider.useValue;
240
- }
241
- if (injectProvider?.useFactory) {
242
- const factory = injectProvider.useFactory;
243
- try {
244
- if (TypeSpecifier.isClass(factory)) {
245
- injectInstance = new injectProvider.useFactory();
246
- }
247
- else {
248
- injectInstance = injectProvider.useFactory();
249
- }
250
- }
251
- catch (error) {
252
- console.error('A factory can be either a function or a class.', error);
253
- return error;
254
- }
255
- }
256
- this.providers.set(injectProvider.token, injectInstance);
257
- }
258
- ;
259
- }
260
-
261
- class Container extends AuditContainer {
262
- _modules = new Map();
263
- get modules() {
264
- return this._modules;
265
- }
266
- ;
267
- registerModule(module) {
268
- if (this._modules.has(module))
269
- return console.warn(`Module has in Container`);
270
- this.processProvidersInPool();
271
- const moduleInstance = new ModuleRef(this, module);
272
- this._modules.set(module, moduleInstance);
273
- }
274
- ;
275
- getModuleByName(moduleName) {
276
- return of(this._modules).find(({ key }) => moduleName === key.name);
277
- }
278
- ;
279
- getController(prefix) {
280
- return of(this._modules).map(({ value }) => {
281
- return value.getController(prefix);
282
- }).find((controller) => !!controller);
283
- }
284
- ;
285
- findModuleByProviderToken(providerToken) {
286
- let module = null;
287
- this._modules.forEach((moduleRef, moduleClass) => {
288
- if (moduleClass.providers?.includes(providerToken)) {
289
- module = {
290
- token: moduleClass,
291
- reference: moduleRef,
292
- };
293
- }
294
- });
295
- return module;
296
- }
297
- ;
298
- }
299
- const container = new Container();
300
-
301
- function Controller(prefix) {
302
- return (target) => {
303
- Reflect.defineMetadata("controller:prefix" /* E_TOKENS.CONTROLLER_PREFIX */, prefix, target);
304
- };
305
- }
306
-
307
- function Module(options) {
308
- return (target) => {
309
- Reflect.defineProperty(target, 'name', {
310
- value: options.name,
311
- writable: false,
312
- configurable: false,
313
- });
314
- Reflect.defineProperty(target, 'controllers', {
315
- value: options.controllers,
316
- writable: false,
317
- configurable: false,
318
- });
319
- Reflect.defineProperty(target, 'providers', {
320
- value: options.providers,
321
- writable: false,
322
- configurable: false,
323
- });
324
- registerProviders(options.providers);
325
- };
326
- }
327
- function registerProviders(providers) {
328
- providers?.forEach((provider) => {
329
- const isObjectProvider = typeof provider === 'object' && !!provider?.token;
330
- if (isObjectProvider) {
331
- container.addProviderToPool("inject" /* E_PROVIDER_TYPES.INJECT */, provider);
332
- }
333
- });
334
- }
335
-
336
- function Injectable() {
337
- return (target) => {
338
- container.addProviderToPool("injectable" /* E_PROVIDER_TYPES.INJECTABLE */, target);
339
- };
340
- }
341
- function Inject(token) {
342
- return (target, _, parameterIndex) => {
343
- const tokens = Reflect.getMetadata("inject:tokens" /* E_TOKENS.INJECT_TOKENS */, target) || [];
344
- tokens.push({
345
- index: parameterIndex,
346
- token,
347
- });
348
- Reflect.defineMetadata("inject:tokens" /* E_TOKENS.INJECT_TOKENS */, tokens, target);
349
- };
350
- }
351
-
352
- class AbstractModule {
353
- static name;
354
- static controllers = [];
355
- static providers = [];
356
- }
357
-
358
- class Queue {
359
- _storage = {};
360
- _oldestIndex = 1;
361
- _newestIndex = 1;
362
- get count() {
363
- return this._newestIndex - this._oldestIndex;
364
- }
365
- enqueue(data) {
366
- this._storage[this._newestIndex] = data;
367
- this._newestIndex++;
368
- }
369
- dequeue() {
370
- const oldestIndex = this._oldestIndex;
371
- const deletedData = this._storage[oldestIndex];
372
- delete this._storage[oldestIndex];
373
- this._oldestIndex++;
374
- return deletedData;
375
- }
376
- toArray() {
377
- return Object.values(this._storage);
378
- }
379
- }
380
-
381
- var moduleManager = /*#__PURE__*/Object.freeze({
382
- __proto__: null,
383
- AbstractModule: AbstractModule,
384
- Container: Container,
385
- Controller: Controller,
386
- Inject: Inject,
387
- Injectable: Injectable,
388
- Module: Module,
389
- ModuleRef: ModuleRef,
390
- Queue: Queue,
391
- TypeSpecifier: TypeSpecifier,
392
- container: container,
393
- of: of
394
- });
395
-
396
- exports.E_DRIVER_CLASSES = void 0;
397
- (function (E_DRIVER_CLASSES) {
398
- E_DRIVER_CLASSES["shopify"] = "ShopifyDriver";
399
- E_DRIVER_CLASSES["woo"] = "WooDriver";
400
- })(exports.E_DRIVER_CLASSES || (exports.E_DRIVER_CLASSES = {}));
401
-
402
- exports.E_DRIVER_TOKENS = void 0;
403
- (function (E_DRIVER_TOKENS) {
404
- E_DRIVER_TOKENS["ENVIRONMENTS"] = "ENVIRONMENTS";
405
- })(exports.E_DRIVER_TOKENS || (exports.E_DRIVER_TOKENS = {}));
406
-
407
- exports.E_MANDATORY_CONTROLLERS = void 0;
408
- (function (E_MANDATORY_CONTROLLERS) {
409
- E_MANDATORY_CONTROLLERS["LINE_ITEMS"] = "line-items";
410
- E_MANDATORY_CONTROLLERS["PREVIEW"] = "preview";
411
- E_MANDATORY_CONTROLLERS["PRICING"] = "pricing";
412
- E_MANDATORY_CONTROLLERS["RETURN_TO_EDIT"] = "return-to-edit";
413
- })(exports.E_MANDATORY_CONTROLLERS || (exports.E_MANDATORY_CONTROLLERS = {}));
414
-
415
- class AbstractLineItemsController {
416
- }
417
- class AbstractPricingController {
418
- }
419
- class AbstractPreviewController {
420
- }
421
- class AbstractCheckoutController {
422
- }
423
- class AbstractReturnToEditController {
424
- }
425
-
426
- /*
427
- from https://github.com/substack/vm-browserify/blob/bfd7c5f59edec856dc7efe0b77a4f6b2fa20f226/index.js
428
-
429
- MIT license no Copyright holder mentioned
430
- */
431
-
432
-
433
- function Object_keys(obj) {
434
- if (Object.keys) return Object.keys(obj)
435
- else {
436
- var res = [];
437
- for (var key in obj) res.push(key);
438
- return res;
439
- }
440
- }
441
-
442
- function forEach(xs, fn) {
443
- if (xs.forEach) return xs.forEach(fn)
444
- else
445
- for (var i = 0; i < xs.length; i++) {
446
- fn(xs[i], i, xs);
447
- }
448
- }
449
- var _defineProp;
450
-
451
- function defineProp(obj, name, value) {
452
- if (typeof _defineProp !== 'function') {
453
- _defineProp = createDefineProp;
454
- }
455
- _defineProp(obj, name, value);
456
- }
457
-
458
- function createDefineProp() {
459
- try {
460
- Object.defineProperty({}, '_', {});
461
- return function(obj, name, value) {
462
- Object.defineProperty(obj, name, {
463
- writable: true,
464
- enumerable: false,
465
- configurable: true,
466
- value: value
467
- });
468
- };
469
- } catch (e) {
470
- return function(obj, name, value) {
471
- obj[name] = value;
472
- };
473
- }
474
- }
475
-
476
- var globals = ['Array', 'Boolean', 'Date', 'Error', 'EvalError', 'Function',
477
- 'Infinity', 'JSON', 'Math', 'NaN', 'Number', 'Object', 'RangeError',
478
- 'ReferenceError', 'RegExp', 'String', 'SyntaxError', 'TypeError', 'URIError',
479
- 'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'escape',
480
- 'eval', 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'undefined', 'unescape'
481
- ];
482
-
483
- function Context() {}
484
- Context.prototype = {};
485
-
486
- function Script(code) {
487
- if (!(this instanceof Script)) return new Script(code);
488
- this.code = code;
489
- }
490
- function otherRunInContext(code, context) {
491
- var args = Object_keys(global);
492
- args.push('with (this.__ctx__){return eval(this.__code__)}');
493
- var fn = Function.apply(null, args);
494
- return fn.apply({
495
- __code__: code,
496
- __ctx__: context
497
- });
498
- }
499
- Script.prototype.runInContext = function(context) {
500
- if (!(context instanceof Context)) {
501
- throw new TypeError('needs a \'context\' argument.');
502
- }
503
- if (global.document) {
504
- var iframe = global.document.createElement('iframe');
505
- if (!iframe.style) iframe.style = {};
506
- iframe.style.display = 'none';
507
-
508
- global.document.body.appendChild(iframe);
509
-
510
- var win = iframe.contentWindow;
511
- var wEval = win.eval,
512
- wExecScript = win.execScript;
513
-
514
- if (!wEval && wExecScript) {
515
- // win.eval() magically appears when this is called in IE:
516
- wExecScript.call(win, 'null');
517
- wEval = win.eval;
518
- }
519
-
520
- forEach(Object_keys(context), function(key) {
521
- win[key] = context[key];
522
- });
523
- forEach(globals, function(key) {
524
- if (context[key]) {
525
- win[key] = context[key];
526
- }
527
- });
528
-
529
- var winKeys = Object_keys(win);
530
-
531
- var res = wEval.call(win, this.code);
532
-
533
- forEach(Object_keys(win), function(key) {
534
- // Avoid copying circular objects like `top` and `window` by only
535
- // updating existing context properties or new properties in the `win`
536
- // that was only introduced after the eval.
537
- if (key in context || indexOf(winKeys, key) === -1) {
538
- context[key] = win[key];
539
- }
540
- });
541
-
542
- forEach(globals, function(key) {
543
- if (!(key in context)) {
544
- defineProp(context, key, win[key]);
545
- }
546
- });
547
- global.document.body.removeChild(iframe);
548
-
549
- return res;
550
- }
551
- return otherRunInContext(this.code, context);
552
- };
553
-
554
- Script.prototype.runInThisContext = function() {
555
- var fn = new Function('code', 'return eval(code);');
556
- return fn.call(global, this.code); // maybe...
557
- };
558
-
559
- Script.prototype.runInNewContext = function(context) {
560
- var ctx = createContext(context);
561
- var res = this.runInContext(ctx);
562
- if (context) {
563
- forEach(Object_keys(ctx), function(key) {
564
- context[key] = ctx[key];
565
- });
566
- }
567
-
568
- return res;
569
- };
570
-
571
- function createContext(context) {
572
- if (isContext(context)) {
573
- return context;
574
- }
575
- var copy = new Context();
576
- if (typeof context === 'object') {
577
- forEach(Object_keys(context), function(key) {
578
- copy[key] = context[key];
579
- });
580
- }
581
- return copy;
582
- }
583
- function runInContext(code, contextifiedSandbox, options) {
584
- var script = new Script(code);
585
- return script.runInContext(contextifiedSandbox, options);
586
- }
587
- function isContext(context) {
588
- return context instanceof Context;
589
- }
590
-
591
-
592
- /*
593
- from indexOf
594
- @ author tjholowaychuk
595
- @ license MIT
596
- */
597
- var _indexOf = [].indexOf;
598
-
599
- function indexOf(arr, obj){
600
- if (_indexOf) return arr.indexOf(obj);
601
- for (var i = 0; i < arr.length; ++i) {
602
- if (arr[i] === obj) return i;
603
- }
604
- return -1;
605
- }
606
-
607
- async function virtualMachine(code) {
608
- const context = {
609
- module: { exports: {} },
610
- exports: {},
611
- require: (id) => {
612
- if (id === '@savafeed/module-manager') {
613
- return moduleManager;
614
- }
615
- throw new Error(`Cannot require('${id}') in this context`);
616
- },
617
- console,
618
- setTimeout,
619
- setInterval,
620
- Reflect,
621
- Promise,
622
- URL,
623
- fetch,
624
- };
625
- const isNodeJsEnv = typeof document === 'undefined';
626
- if (isNodeJsEnv) {
627
- await import('reflect-metadata');
628
- }
629
- else {
630
- // @ts-ignore
631
- await import('https://unpkg.com/reflect-metadata@0.2.2/Reflect.js');
632
- }
633
- context.Reflect = Reflect;
634
- const sandbox = createContext(context);
635
- runInContext(code, sandbox);
636
- const moduleObject = sandbox.exports;
637
- return moduleObject;
638
- }
639
-
640
- class DriverProcessor {
641
- // static CDN: string = 'http://localhost:5000';
642
- static CDN = 'https://unpkg.com/@savafeed';
643
- static async getDriverModule(bootstrapOptions) {
644
- let driverModule;
645
- if (bootstrapOptions?.default) {
646
- driverModule = await DriverProcessor.defaultBootstrapDriver(bootstrapOptions.default);
647
- }
648
- else if (bootstrapOptions?.custom) {
649
- driverModule = await DriverProcessor.customBootstrapDriver(bootstrapOptions.custom);
650
- }
651
- else {
652
- throw new Error('Driver not found');
653
- }
654
- return driverModule;
655
- }
656
- ;
657
- static async defaultBootstrapDriver(options) {
658
- if (!options?.name)
659
- throw new Error(`Unable to get driver by this name: ${options?.name}`);
660
- const driver = await DriverProcessor.pullDriverByName(options.name, options.scriptType);
661
- const driverModule = DriverProcessor.exportDriverModule(driver, {
662
- scriptType: options.scriptType,
663
- name: options.name,
664
- });
665
- return driverModule;
666
- }
667
- static async customBootstrapDriver(options) {
668
- if (!options?.link)
669
- throw new Error('Driver link not found');
670
- if (!options?.className)
671
- throw new Error('Driver class name not found');
672
- const driver = await DriverProcessor.pullDriverByLink(options.link);
673
- const driverModule = DriverProcessor.exportDriverModule(driver, {
674
- scriptType: options.scriptType,
675
- name: options.className,
676
- });
677
- return driverModule;
678
- }
679
- static exportDriverModule(driver, options) {
680
- if (!driver)
681
- throw new Error('Driver not found');
682
- const currentScriptType = (!!options.scriptType) ? options.scriptType : 'umd';
683
- const driverClassName = options.name;
684
- switch (currentScriptType) {
685
- case 'esm':
686
- return driver?.default[exports.E_DRIVER_CLASSES[driverClassName]] || driver[exports.E_DRIVER_CLASSES[driverClassName]];
687
- case 'umd':
688
- return driver?.default[exports.E_DRIVER_CLASSES[driverClassName]] || driver[exports.E_DRIVER_CLASSES[driverClassName]];
689
- case 'cjs':
690
- return driver[exports.E_DRIVER_CLASSES[driverClassName]];
691
- default:
692
- throw new Error(`Unknown script type: ${currentScriptType}`);
693
- }
694
- }
695
- static async pullDriverByLink(link) {
696
- if (!link)
697
- throw new Error('Driver link not found');
698
- const response = await fetch(link);
699
- if (!response?.ok) {
700
- throw new Error(`Failed to load script from CDN: ${response.statusText}`);
701
- }
702
- const scriptContent = await response.text();
703
- const driver = await virtualMachine(scriptContent);
704
- return driver;
705
- }
706
- ;
707
- static async pullDriverByName(driverName, scriptType) {
708
- if (!driverName)
709
- throw new Error('Driver name not found');
710
- const currentScriptType = (!!scriptType) ? scriptType : 'umd';
711
- const link = `${DriverProcessor.CDN}/${driverName}-driver@latest/${driverName}.driver.${currentScriptType}.js`;
712
- const response = await fetch(link);
713
- if (!response?.ok) {
714
- throw new Error(`Failed to load script from CDN: ${response.statusText}`);
715
- }
716
- const scriptContent = await response.text();
717
- const driver = await virtualMachine(scriptContent);
718
- return driver;
719
- }
720
- ;
721
- }
722
-
723
- class DriverManager {
724
- appContainer;
725
- environments;
726
- constructor(appContainer, environments) {
727
- this.appContainer = appContainer;
728
- this.environments = environments;
729
- if (!!this?.environments?.core) {
730
- this.setCoreOptions(this.environments.core);
731
- }
732
- }
733
- ;
734
- async setup() {
735
- if (this.appContainer.providers.has(exports.E_DRIVER_TOKENS.ENVIRONMENTS)) {
736
- throw new Error(`Provider with token "${exports.E_DRIVER_TOKENS.ENVIRONMENTS}" already exists`);
737
- }
738
- this.appContainer.providers.set(exports.E_DRIVER_TOKENS.ENVIRONMENTS, this.environments);
739
- if (this.environments?.input?.eCommerce) {
740
- return await this.bootstrapDriver({
741
- default: {
742
- name: this.environments?.input?.eCommerce,
743
- scriptType: this.environments?.input?.driverScriptType,
744
- },
745
- });
746
- }
747
- else {
748
- return await this.bootstrapDriver({
749
- custom: {
750
- link: this.environments?.input?.driverLink,
751
- className: this.environments?.input?.driverClassName,
752
- },
753
- });
754
- }
755
- }
756
- setCoreOptions(options) {
757
- if (options?.cdn) {
758
- DriverProcessor.CDN = options.cdn;
759
- }
760
- }
761
- getController(controllerName) {
762
- return this.appContainer.getController(controllerName);
763
- }
764
- async bootstrapDriver(bootstrapOptions) {
765
- const driverModule = await DriverProcessor.getDriverModule(bootstrapOptions);
766
- if (!driverModule) {
767
- console.error('Driver not found!', driverModule);
768
- console.warn('Bootstrap options:', bootstrapOptions);
769
- let stringOptions;
770
- try {
771
- stringOptions = JSON.stringify(bootstrapOptions);
772
- }
773
- catch (ex) {
774
- console.warn('Error trying to convert bootstrap parameters to JSON to show in error:', ex);
775
- stringOptions = String(bootstrapOptions);
776
- }
777
- throw new Error(`Driver with options: (${stringOptions}) not found`);
778
- }
779
- this.appContainer.registerModule(driverModule);
780
- return driverModule;
781
- }
782
- ;
783
- }
3
+ var moduleManager = require('@savafeed/module-manager');
4
+ var driverManager = require('@savafeed/driver-manager');
784
5
 
785
6
  class DomPolyfill {
786
7
  static get document() {
@@ -817,12 +38,12 @@ class DomPolyfill {
817
38
 
818
39
  class CartSDK {
819
40
  environments;
820
- appContainer = container;
41
+ appContainer = moduleManager.container;
821
42
  driverManager;
822
43
  controllers = new Map();
823
44
  constructor(environments) {
824
45
  this.environments = environments;
825
- this.driverManager = new DriverManager(this.appContainer, this.environments);
46
+ this.driverManager = new driverManager.DriverManager(this.appContainer, this.environments);
826
47
  }
827
48
  ;
828
49
  async bootstrap() {
@@ -837,10 +58,10 @@ class CartSDK {
837
58
  }
838
59
  purchasingMandatoryControllers() {
839
60
  const mandatoryControllers = [
840
- exports.E_MANDATORY_CONTROLLERS.LINE_ITEMS,
841
- exports.E_MANDATORY_CONTROLLERS.PREVIEW,
842
- exports.E_MANDATORY_CONTROLLERS.PRICING,
843
- exports.E_MANDATORY_CONTROLLERS.RETURN_TO_EDIT,
61
+ driverManager.E_MANDATORY_CONTROLLERS.LINE_ITEMS,
62
+ driverManager.E_MANDATORY_CONTROLLERS.PREVIEW,
63
+ driverManager.E_MANDATORY_CONTROLLERS.PRICING,
64
+ driverManager.E_MANDATORY_CONTROLLERS.RETURN_TO_EDIT,
844
65
  ];
845
66
  mandatoryControllers.forEach((controllerName) => {
846
67
  const controllerInstance = this.driverManager.getController(controllerName);
@@ -857,11 +78,41 @@ if ($window) {
857
78
  $window.CartSDK = CartSDK;
858
79
  }
859
80
 
860
- exports.AbstractCheckoutController = AbstractCheckoutController;
861
- exports.AbstractLineItemsController = AbstractLineItemsController;
862
- exports.AbstractPreviewController = AbstractPreviewController;
863
- exports.AbstractPricingController = AbstractPricingController;
864
- exports.AbstractReturnToEditController = AbstractReturnToEditController;
81
+ Object.defineProperty(exports, "AbstractCheckoutController", {
82
+ enumerable: true,
83
+ get: function () { return driverManager.AbstractCheckoutController; }
84
+ });
85
+ Object.defineProperty(exports, "AbstractLineItemsController", {
86
+ enumerable: true,
87
+ get: function () { return driverManager.AbstractLineItemsController; }
88
+ });
89
+ Object.defineProperty(exports, "AbstractPreviewController", {
90
+ enumerable: true,
91
+ get: function () { return driverManager.AbstractPreviewController; }
92
+ });
93
+ Object.defineProperty(exports, "AbstractPricingController", {
94
+ enumerable: true,
95
+ get: function () { return driverManager.AbstractPricingController; }
96
+ });
97
+ Object.defineProperty(exports, "AbstractReturnToEditController", {
98
+ enumerable: true,
99
+ get: function () { return driverManager.AbstractReturnToEditController; }
100
+ });
101
+ Object.defineProperty(exports, "DriverManager", {
102
+ enumerable: true,
103
+ get: function () { return driverManager.DriverManager; }
104
+ });
105
+ Object.defineProperty(exports, "E_DRIVER_CLASSES", {
106
+ enumerable: true,
107
+ get: function () { return driverManager.E_DRIVER_CLASSES; }
108
+ });
109
+ Object.defineProperty(exports, "E_DRIVER_TOKENS", {
110
+ enumerable: true,
111
+ get: function () { return driverManager.E_DRIVER_TOKENS; }
112
+ });
113
+ Object.defineProperty(exports, "E_MANDATORY_CONTROLLERS", {
114
+ enumerable: true,
115
+ get: function () { return driverManager.E_MANDATORY_CONTROLLERS; }
116
+ });
865
117
  exports.CartSDK = CartSDK;
866
- exports.DriverManager = DriverManager;
867
118
  //# sourceMappingURL=cart-api-sdk.cjs.js.map