@artisan-commerce/products 0.9.0-canary.44 → 0.9.0-canary.46

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.
@@ -2,6 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var state = require('@artisan-commerce/state');
6
+
5
7
  const isBaseProduct = (product) => {
6
8
  const { attributes, description, name } = product;
7
9
  const { images, prices, productId } = product;
@@ -303,21 +305,21 @@ const mapGlobalRendererStatus = (renderer) => {
303
305
  return "INCOMPLETE";
304
306
  };
305
307
 
306
- var __defProp$7 = Object.defineProperty;
308
+ var __defProp$6 = Object.defineProperty;
307
309
  var __defProps$5 = Object.defineProperties;
308
310
  var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
309
- var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
310
- var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
311
- var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
312
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
313
- var __spreadValues$7 = (a, b) => {
311
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
312
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
313
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
314
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
315
+ var __spreadValues$6 = (a, b) => {
314
316
  for (var prop in b || (b = {}))
315
- if (__hasOwnProp$7.call(b, prop))
316
- __defNormalProp$7(a, prop, b[prop]);
317
- if (__getOwnPropSymbols$7)
318
- for (var prop of __getOwnPropSymbols$7(b)) {
319
- if (__propIsEnum$7.call(b, prop))
320
- __defNormalProp$7(a, prop, b[prop]);
317
+ if (__hasOwnProp$6.call(b, prop))
318
+ __defNormalProp$6(a, prop, b[prop]);
319
+ if (__getOwnPropSymbols$6)
320
+ for (var prop of __getOwnPropSymbols$6(b)) {
321
+ if (__propIsEnum$6.call(b, prop))
322
+ __defNormalProp$6(a, prop, b[prop]);
321
323
  }
322
324
  return a;
323
325
  };
@@ -325,16 +327,16 @@ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
325
327
  const multiplyProductQA = (product) => {
326
328
  return operationOnProductQA(product, (answer, productAmount) => {
327
329
  const accAmount = answer.amount * productAmount;
328
- const fixedAnswer = multiplyProductQA(__spreadProps$5(__spreadValues$7({}, answer), {
330
+ const fixedAnswer = multiplyProductQA(__spreadProps$5(__spreadValues$6({}, answer), {
329
331
  amount: accAmount
330
332
  }));
331
- return __spreadProps$5(__spreadValues$7({}, fixedAnswer), { amount: answer.amount * productAmount });
333
+ return __spreadProps$5(__spreadValues$6({}, fixedAnswer), { amount: answer.amount * productAmount });
332
334
  });
333
335
  };
334
336
  const divideProductQA = (product) => {
335
337
  return operationOnProductQA(product, (answer, productAmount) => {
336
338
  const fixedAnswer = divideProductQA(answer);
337
- return __spreadProps$5(__spreadValues$7({}, fixedAnswer), { amount: answer.amount / productAmount });
339
+ return __spreadProps$5(__spreadValues$6({}, fixedAnswer), { amount: answer.amount / productAmount });
338
340
  });
339
341
  };
340
342
  const operationOnProductQA = (product, answerEnhancer) => {
@@ -343,9 +345,9 @@ const operationOnProductQA = (product, answerEnhancer) => {
343
345
  const answers = question.answers.map((answer) => {
344
346
  return answerEnhancer(answer, productAmount);
345
347
  });
346
- return __spreadProps$5(__spreadValues$7({}, question), { answers });
348
+ return __spreadProps$5(__spreadValues$6({}, question), { answers });
347
349
  });
348
- return __spreadProps$5(__spreadValues$7({}, product), {
350
+ return __spreadProps$5(__spreadValues$6({}, product), {
349
351
  questionsAndAnswers: newQuestionsAndAnswers
350
352
  });
351
353
  };
@@ -357,28 +359,28 @@ var questionsAndAnswers_utils = /*#__PURE__*/Object.freeze({
357
359
  operationOnProductQA: operationOnProductQA
358
360
  });
359
361
 
360
- var __defProp$6 = Object.defineProperty;
362
+ var __defProp$5 = Object.defineProperty;
361
363
  var __defProps$4 = Object.defineProperties;
362
364
  var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
363
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
364
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
365
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
366
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
367
- var __spreadValues$6 = (a, b) => {
365
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
366
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
367
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
368
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
369
+ var __spreadValues$5 = (a, b) => {
368
370
  for (var prop in b || (b = {}))
369
- if (__hasOwnProp$6.call(b, prop))
370
- __defNormalProp$6(a, prop, b[prop]);
371
- if (__getOwnPropSymbols$6)
372
- for (var prop of __getOwnPropSymbols$6(b)) {
373
- if (__propIsEnum$6.call(b, prop))
374
- __defNormalProp$6(a, prop, b[prop]);
371
+ if (__hasOwnProp$5.call(b, prop))
372
+ __defNormalProp$5(a, prop, b[prop]);
373
+ if (__getOwnPropSymbols$5)
374
+ for (var prop of __getOwnPropSymbols$5(b)) {
375
+ if (__propIsEnum$5.call(b, prop))
376
+ __defNormalProp$5(a, prop, b[prop]);
375
377
  }
376
378
  return a;
377
379
  };
378
380
  var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
379
381
  const toCartProduct = (product, overrides = {}) => {
380
382
  if (isCartProduct(product)) {
381
- return __spreadValues$6(__spreadValues$6({}, product), overrides);
383
+ return __spreadValues$5(__spreadValues$5({}, product), overrides);
382
384
  }
383
385
  if (isProductDetails(product)) {
384
386
  return toCartProductFromProductDetails(product, overrides);
@@ -388,7 +390,7 @@ const toCartProduct = (product, overrides = {}) => {
388
390
  };
389
391
  const toCartProductFromProductDetails = (product, overrides = {}) => {
390
392
  const { questionsAndAnswers, priceCategory, amount } = product;
391
- const newCartProduct = __spreadValues$6(__spreadProps$4(__spreadValues$6({}, product), {
393
+ const newCartProduct = __spreadValues$5(__spreadProps$4(__spreadValues$5({}, product), {
392
394
  questionsAndAnswers: questionsAndAnswers != null ? questionsAndAnswers : [],
393
395
  amount: amount != null ? amount : 0,
394
396
  priceCategory: priceCategory != null ? priceCategory : "NORMAL",
@@ -401,7 +403,7 @@ const toCartProductFromProductDetails = (product, overrides = {}) => {
401
403
  return newCartProduct;
402
404
  };
403
405
  const toProductDetails = (product, overrides = {}) => {
404
- return __spreadValues$6(__spreadProps$4(__spreadValues$6({}, product), {
406
+ return __spreadValues$5(__spreadProps$4(__spreadValues$5({}, product), {
405
407
  addDirectlyToCart: true,
406
408
  isPriceVip: false,
407
409
  manufacturer: [],
@@ -414,7 +416,7 @@ const toProductDetails = (product, overrides = {}) => {
414
416
  };
415
417
  const toFormCartProduct = (product, overrides = {}) => {
416
418
  if (isFormCartProduct(product)) {
417
- return __spreadValues$6(__spreadValues$6({}, product), overrides);
419
+ return __spreadValues$5(__spreadValues$5({}, product), overrides);
418
420
  }
419
421
  if (isProductDetails(product)) {
420
422
  return toFormCartProductFromProductDetails(product, overrides);
@@ -441,7 +443,7 @@ const toFormCartProductHelper = (product, overrides = {}) => {
441
443
  amount,
442
444
  path: []
443
445
  };
444
- return __spreadProps$4(__spreadValues$6({}, selectedQuestion), {
446
+ return __spreadProps$4(__spreadValues$5({}, selectedQuestion), {
445
447
  answers: question.answers.map((answer) => {
446
448
  var _a2;
447
449
  const pairAnswer = pairQuestion == null ? void 0 : pairQuestion.answers.find((a) => {
@@ -457,7 +459,7 @@ const toFormCartProductHelper = (product, overrides = {}) => {
457
459
  type: selectedAnswer.renderType
458
460
  });
459
461
  const nested = selectedAnswer.questions.length;
460
- const partialNewAnswer = __spreadProps$4(__spreadValues$6({}, selectedAnswer), {
462
+ const partialNewAnswer = __spreadProps$4(__spreadValues$5({}, selectedAnswer), {
461
463
  amount: (_a2 = selectedAnswer == null ? void 0 : selectedAnswer.amount) != null ? _a2 : 0,
462
464
  priceCategory,
463
465
  questionId,
@@ -465,13 +467,13 @@ const toFormCartProductHelper = (product, overrides = {}) => {
465
467
  max: max2,
466
468
  renderType: type
467
469
  });
468
- return __spreadProps$4(__spreadValues$6({}, partialNewAnswer), {
470
+ return __spreadProps$4(__spreadValues$5({}, partialNewAnswer), {
469
471
  questions: nested ? toFormCartProductHelper(partialNewAnswer).questions : []
470
472
  });
471
473
  })
472
474
  });
473
475
  });
474
- return __spreadValues$6(__spreadProps$4(__spreadValues$6({}, fixedProduct), {
476
+ return __spreadValues$5(__spreadProps$4(__spreadValues$5({}, fixedProduct), {
475
477
  questions: newQuestions
476
478
  }), overrides);
477
479
  };
@@ -484,13 +486,13 @@ const toFormCartProductFromAnswer = (modifier, overrides = {}) => {
484
486
  };
485
487
  const normalizeProductDetails = (product) => {
486
488
  const { questions } = product;
487
- return __spreadProps$4(__spreadValues$6({}, product), {
489
+ return __spreadProps$4(__spreadValues$5({}, product), {
488
490
  questions: questions.map((question) => {
489
491
  const { answers } = question;
490
- return __spreadProps$4(__spreadValues$6({}, question), {
492
+ return __spreadProps$4(__spreadValues$5({}, question), {
491
493
  answers: answers.map((answer) => {
492
494
  const { questions: questions2 } = answer;
493
- return __spreadProps$4(__spreadValues$6({}, answer), {
495
+ return __spreadProps$4(__spreadValues$5({}, answer), {
494
496
  questions: questions2 != null ? questions2 : []
495
497
  });
496
498
  })
@@ -509,44 +511,6 @@ var transformers_utils = /*#__PURE__*/Object.freeze({
509
511
  normalizeProductDetails: normalizeProductDetails
510
512
  });
511
513
 
512
- var __defProp$5 = Object.defineProperty;
513
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
514
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
515
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
516
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
517
- var __spreadValues$5 = (a, b) => {
518
- for (var prop in b || (b = {}))
519
- if (__hasOwnProp$5.call(b, prop))
520
- __defNormalProp$5(a, prop, b[prop]);
521
- if (__getOwnPropSymbols$5)
522
- for (var prop of __getOwnPropSymbols$5(b)) {
523
- if (__propIsEnum$5.call(b, prop))
524
- __defNormalProp$5(a, prop, b[prop]);
525
- }
526
- return a;
527
- };
528
- let state = null;
529
- const initState = (initialState) => {
530
- Object.freeze(initialState);
531
- state = __spreadValues$5({}, initialState);
532
- Object.seal(state);
533
- };
534
- const setState = (overrides) => {
535
- const tempState = state ? __spreadValues$5({}, state) : {};
536
- state = null;
537
- state = __spreadValues$5(__spreadValues$5({}, tempState), overrides);
538
- Object.seal(state);
539
- };
540
- const getState = () => {
541
- if (state === null) {
542
- throw new Error("The state has not been initialized, make sure to call initState beforehand");
543
- }
544
- return __spreadValues$5({}, state);
545
- };
546
- const checkInit = () => {
547
- return !!state;
548
- };
549
-
550
514
  const initialState = {
551
515
  forms: {}
552
516
  };
@@ -868,7 +832,7 @@ const buildModifierRenderer = (modifier, config, previous) => {
868
832
  });
869
833
  };
870
834
  const handleModifierChange = (productId, path, amount) => {
871
- const forms = __spreadValues$2({}, getState().forms);
835
+ const forms = __spreadValues$2({}, state.getState().forms);
872
836
  const form = forms[productId];
873
837
  const node = getRendererPathNode(form.renderer, path);
874
838
  let newRenderer = updateModifier(form.renderer, path, node, amount, false);
@@ -880,7 +844,7 @@ const handleModifierChange = (productId, path, amount) => {
880
844
  status: mapGlobalRendererStatus(newRenderer)
881
845
  });
882
846
  const newForms = __spreadProps$2(__spreadValues$2({}, forms), { [productId]: updatedForm });
883
- setState({ forms: newForms });
847
+ state.setState({ forms: newForms });
884
848
  const returnForm = __spreadValues$2({}, updatedForm);
885
849
  delete returnForm.callback;
886
850
  form.callback(returnForm);
@@ -999,7 +963,7 @@ var __spreadValues$1 = (a, b) => {
999
963
  };
1000
964
  var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1001
965
  const validateProduct = (productId) => {
1002
- const forms = __spreadValues$1({}, getState().forms);
966
+ const forms = __spreadValues$1({}, state.getState().forms);
1003
967
  const form = forms[productId];
1004
968
  const { renderer, callback, product } = form;
1005
969
  let latestRenderer = [...renderer];
@@ -1014,7 +978,7 @@ const validateProduct = (productId) => {
1014
978
  status: mapGlobalRendererStatus(latestRenderer)
1015
979
  });
1016
980
  const newForms = __spreadProps$1(__spreadValues$1({}, forms), { [productId]: updatedForm });
1017
- setState({ forms: newForms });
981
+ state.setState({ forms: newForms });
1018
982
  const returnForm = __spreadValues$1({}, updatedForm);
1019
983
  delete returnForm.callback;
1020
984
  callback(returnForm);
@@ -1096,9 +1060,9 @@ var __spreadValues = (a, b) => {
1096
1060
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1097
1061
  const registerModifiersForm = (product, callback) => {
1098
1062
  const { productId } = product;
1099
- if (!checkInit())
1100
- initState(initialState);
1101
- const { forms } = getState();
1063
+ if (!state.checkInit())
1064
+ state.initState(initialState);
1065
+ const { forms } = state.getState();
1102
1066
  const formExists = !!forms[productId];
1103
1067
  if (formExists) {
1104
1068
  logError(`Form for product with id ${productId} has already been register. Please unsubscribe if you need to register a new form.`);
@@ -1107,15 +1071,15 @@ const registerModifiersForm = (product, callback) => {
1107
1071
  }
1108
1072
  const form = createForm(product);
1109
1073
  const newForms = __spreadProps(__spreadValues({}, forms), { [productId]: __spreadProps(__spreadValues({}, form), { callback }) });
1110
- setState({ forms: newForms });
1074
+ state.setState({ forms: newForms });
1111
1075
  callback(__spreadValues({}, form));
1112
1076
  return () => unsubscriber(productId);
1113
1077
  };
1114
1078
  const unsubscriber = (productId) => {
1115
- const { forms } = getState();
1079
+ const { forms } = state.getState();
1116
1080
  const newForms = __spreadValues({}, forms);
1117
1081
  delete newForms[productId];
1118
- setState({ forms: newForms });
1082
+ state.setState({ forms: newForms });
1119
1083
  };
1120
1084
 
1121
1085
  exports.assertions = assertions_utils;