@ubnt/store.core 9.45.0-alpha.0 → 9.45.0-alpha.1

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 (89) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/lib/_virtual/_virtual_multi-entry.js +2 -0
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +2 -0
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/assets/attention.svg +5 -5
  7. package/lib/assets/attention2.svg +5 -5
  8. package/lib/assets/close2.svg +3 -2
  9. package/lib/assets/close3.svg +2 -3
  10. package/lib/assets/minus4.svg +8 -8
  11. package/lib/assets/minus5.svg +8 -8
  12. package/lib/assets/plus2.svg +4 -1
  13. package/lib/assets/plus3.svg +1 -4
  14. package/lib/assets/plus5.svg +9 -9
  15. package/lib/assets/plus6.svg +9 -9
  16. package/lib/assets/ucgUltra.jpg +0 -0
  17. package/lib/assets/ucgUltra2.jpg +0 -0
  18. package/lib/components/Badge/Badge.styles.js +12 -0
  19. package/lib/components/Badge/Badge.styles.js.map +1 -1
  20. package/lib/components/Badge/Badge.styles.mjs +12 -0
  21. package/lib/components/Badge/Badge.styles.mjs.map +1 -1
  22. package/lib/components/Badge/Badge.types.d.ts +3 -1
  23. package/lib/components/Badge/Badge.types.js +2 -0
  24. package/lib/components/Badge/Badge.types.js.map +1 -1
  25. package/lib/components/Badge/Badge.types.mjs +2 -0
  26. package/lib/components/Badge/Badge.types.mjs.map +1 -1
  27. package/lib/components/FeaturesSection_deprecated/AllFeaturesButton/AllFeaturesButton.js +1 -1
  28. package/lib/components/FeaturesSection_deprecated/AllFeaturesButton/AllFeaturesButton.mjs +1 -1
  29. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  30. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  31. package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
  32. package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
  33. package/lib/components/FeaturesSection_deprecated/assets/plus.svg.js +1 -1
  34. package/lib/components/FeaturesSection_deprecated/assets/plus.svg.mjs +2 -2
  35. package/lib/components/Header/CartModalV2/Item/Item.js +3 -3
  36. package/lib/components/Header/CartModalV2/Item/Item.mjs +2 -2
  37. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.js +5 -5
  38. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.mjs +2 -2
  39. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.js +1 -1
  40. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.mjs +2 -2
  41. package/lib/components/ModelCompareV3/data/CloudGateways.js +3 -3
  42. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +2 -2
  43. package/lib/components/ModelCompareV3/data/products/ucgUltra.js +1 -1
  44. package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +1 -1
  45. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  46. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  47. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  48. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  49. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  50. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  51. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  52. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  53. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  54. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  55. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  56. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  57. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  58. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  59. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  60. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  61. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  62. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  63. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  64. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  65. package/lib/components/VideoPlayerNew/VideoPlayer.js +1 -1
  66. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +1 -1
  67. package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
  68. package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
  69. package/lib/constants/icons/generic/index.js +3 -3
  70. package/lib/constants/icons/generic/index.mjs +1 -1
  71. package/lib/constants/icons/generic/plus.svg.js +5 -5
  72. package/lib/constants/icons/generic/plus.svg.mjs +2 -2
  73. package/lib/utils/blackFriday.d.ts +1 -20
  74. package/lib/utils/blackFriday.js +3 -84
  75. package/lib/utils/blackFriday.js.map +1 -1
  76. package/lib/utils/blackFriday.mjs +1 -74
  77. package/lib/utils/blackFriday.mjs.map +1 -1
  78. package/lib/utils/index.d.ts +1 -0
  79. package/lib/utils/index.js +2 -0
  80. package/lib/utils/index.js.map +1 -1
  81. package/lib/utils/index.mjs +2 -0
  82. package/lib/utils/index.mjs.map +1 -1
  83. package/lib/utils/sales.d.ts +34 -0
  84. package/lib/utils/sales.js +113 -0
  85. package/lib/utils/sales.js.map +1 -0
  86. package/lib/utils/sales.mjs +99 -0
  87. package/lib/utils/sales.mjs.map +1 -0
  88. package/lib/utils/sales.test.d.ts +1 -0
  89. package/package.json +1 -1
@@ -0,0 +1,34 @@
1
+ import { StoreId } from "../types";
2
+ /**
3
+ * Returns label and timezone for a given store according
4
+ * to IANA timezone database
5
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
6
+ */
7
+ export declare const getStoreTimeZone: (storeId: StoreId) => {
8
+ label: string;
9
+ timezone: string;
10
+ };
11
+ export interface TimeLeft {
12
+ days: number;
13
+ hours: number;
14
+ minutes: number;
15
+ seconds: number;
16
+ }
17
+ export type SaleEndMethod = (storeId: StoreId) => TimeLeft | null;
18
+ /**
19
+ * Returns the time left until the end of the sale for a given store
20
+ * @returns {SaleEndMethod} TimeLeft object if the sale is still active, null otherwise
21
+ */
22
+ export declare const getSaleEndMethod: (saleEndDatetime: string) => SaleEndMethod;
23
+ /**
24
+ * Black Friday Sale
25
+ * Returns the time left until the end of Black Friday for a given store
26
+ * @returns {TimeLeft | null} TimeLeft object if it is still Black Friday, null otherwise
27
+ */
28
+ export declare const getTimeUntilEndOfBlackFridayByStore: SaleEndMethod;
29
+ /**
30
+ * Holiday Sale
31
+ * Returns the time left until the end of Holiday Sale for a given store
32
+ * @returns {TimeLeft | null} TimeLeft object if it is still Holiday Sale, null otherwise
33
+ */
34
+ export declare const getTimeUntilEndOfHolidaySaleByStore: SaleEndMethod;
@@ -0,0 +1,113 @@
1
+ 'use strict';
2
+
3
+ var dayjs = require('dayjs');
4
+ var duration = require('dayjs/plugin/duration');
5
+ var timezone = require('dayjs/plugin/timezone');
6
+ var utc = require('dayjs/plugin/utc');
7
+ require('../types/index.js');
8
+ var errors = require('./errors.js');
9
+ var generated = require('../types/generated.js');
10
+ function _interopDefault(e) {
11
+ return e && e.__esModule ? e : {
12
+ default: e
13
+ };
14
+ }
15
+ var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
16
+ var duration__default = /*#__PURE__*/_interopDefault(duration);
17
+ var timezone__default = /*#__PURE__*/_interopDefault(timezone);
18
+ var utc__default = /*#__PURE__*/_interopDefault(utc);
19
+ "use strict";
20
+ dayjs.extend(timezone__default["default"]);
21
+ dayjs.extend(duration__default["default"]);
22
+ dayjs.extend(utc__default["default"]);
23
+ const getStoreTimeZone = storeId => {
24
+ switch (storeId) {
25
+ case generated.StoreId.Br:
26
+ return {
27
+ label: "UTC-3",
28
+ timezone: "America/Fortaleza"
29
+ };
30
+ case generated.StoreId.Uk:
31
+ return {
32
+ label: "GMT",
33
+ timezone: "Etc/GMT"
34
+ };
35
+ case generated.StoreId.Eu:
36
+ case generated.StoreId.Za:
37
+ return {
38
+ label: "EET",
39
+ timezone: "EET"
40
+ };
41
+ case generated.StoreId.Me:
42
+ return {
43
+ label: "GST",
44
+ timezone: "Asia/Dubai"
45
+ };
46
+ case generated.StoreId.Sg:
47
+ return {
48
+ label: "SGT",
49
+ timezone: "Asia/Singapore"
50
+ };
51
+ case generated.StoreId.Tw:
52
+ return {
53
+ label: "CST",
54
+ timezone: "Asia/Shanghai"
55
+ };
56
+ case generated.StoreId.Jp:
57
+ return {
58
+ label: "JST",
59
+ timezone: "Asia/Tokyo"
60
+ };
61
+ case generated.StoreId.Ca:
62
+ case generated.StoreId.Us:
63
+ return {
64
+ label: "PST",
65
+ timezone: "US/Pacific"
66
+ };
67
+ case generated.StoreId.Mx:
68
+ return {
69
+ label: "CST",
70
+ timezone: "America/Mexico_City"
71
+ };
72
+ case generated.StoreId.In:
73
+ return {
74
+ label: "IST",
75
+ timezone: "Asia/Kolkata"
76
+ };
77
+ case generated.StoreId.Ph:
78
+ return {
79
+ label: "PHT",
80
+ timezone: "Asia/Manila"
81
+ };
82
+ default:
83
+ errors.checkUnreachable(storeId);
84
+ return {
85
+ label: "PST",
86
+ timezone: "US/Pacific"
87
+ };
88
+ }
89
+ };
90
+ const getSaleEndMethod = saleEndDatetime => storeId => {
91
+ const {
92
+ timezone: storeTimezone
93
+ } = getStoreTimeZone(storeId);
94
+ const now = dayjs__default["default"]().tz(storeTimezone);
95
+ const endOfSaleDatetime = dayjs__default["default"].tz(saleEndDatetime, storeTimezone);
96
+ if (now.isAfter(endOfSaleDatetime)) {
97
+ return null;
98
+ }
99
+ const diff = dayjs__default["default"].duration(endOfSaleDatetime.diff(now));
100
+ return {
101
+ days: diff.days(),
102
+ hours: diff.hours(),
103
+ minutes: diff.minutes(),
104
+ seconds: diff.seconds()
105
+ };
106
+ };
107
+ const getTimeUntilEndOfBlackFridayByStore = getSaleEndMethod("2024-12-02 23:59:59");
108
+ const getTimeUntilEndOfHolidaySaleByStore = getSaleEndMethod("2024-12-27 23:59:59");
109
+ exports.getSaleEndMethod = getSaleEndMethod;
110
+ exports.getStoreTimeZone = getStoreTimeZone;
111
+ exports.getTimeUntilEndOfBlackFridayByStore = getTimeUntilEndOfBlackFridayByStore;
112
+ exports.getTimeUntilEndOfHolidaySaleByStore = getTimeUntilEndOfHolidaySaleByStore;
113
+ //# sourceMappingURL=sales.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sales.js","sources":["../../src/utils/sales.ts"],"sourcesContent":["import dayjs, { extend } from \"dayjs\";\nimport duration from \"dayjs/plugin/duration\";\nimport timezone from \"dayjs/plugin/timezone\";\nimport utc from \"dayjs/plugin/utc\";\n\nimport { StoreId } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\n\nextend(timezone);\nextend(duration);\nextend(utc);\n\n/**\n * Returns label and timezone for a given store according\n * to IANA timezone database\n * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\n */\nexport const getStoreTimeZone = (\n storeId: StoreId,\n): {\n label: string;\n timezone: string;\n} => {\n switch (storeId) {\n case StoreId.Br:\n return {\n label: \"UTC-3\",\n timezone: \"America/Fortaleza\",\n };\n case StoreId.Uk:\n return {\n label: \"GMT\",\n timezone: \"Etc/GMT\",\n };\n case StoreId.Eu:\n case StoreId.Za:\n return {\n label: \"EET\",\n timezone: \"EET\",\n };\n case StoreId.Me:\n return {\n label: \"GST\",\n timezone: \"Asia/Dubai\",\n };\n case StoreId.Sg:\n return {\n label: \"SGT\",\n timezone: \"Asia/Singapore\",\n };\n case StoreId.Tw:\n return {\n label: \"CST\",\n timezone: \"Asia/Shanghai\",\n };\n case StoreId.Jp:\n return {\n label: \"JST\",\n timezone: \"Asia/Tokyo\",\n };\n case StoreId.Ca:\n case StoreId.Us:\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n case StoreId.Mx:\n return {\n label: \"CST\",\n timezone: \"America/Mexico_City\",\n };\n case StoreId.In:\n return {\n label: \"IST\",\n timezone: \"Asia/Kolkata\",\n };\n case StoreId.Ph:\n return {\n label: \"PHT\",\n timezone: \"Asia/Manila\",\n };\n default:\n checkUnreachable(storeId);\n // Fallback to US/CA timezone\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n }\n};\n\nexport interface TimeLeft {\n days: number;\n hours: number;\n minutes: number;\n seconds: number;\n}\n\nexport type SaleEndMethod = (storeId: StoreId) => TimeLeft | null;\n\n/**\n * Returns the time left until the end of the sale for a given store\n * @returns {SaleEndMethod} TimeLeft object if the sale is still active, null otherwise\n */\nexport const getSaleEndMethod =\n (saleEndDatetime: string): SaleEndMethod =>\n (storeId: StoreId): TimeLeft | null => {\n const { timezone: storeTimezone } = getStoreTimeZone(storeId);\n\n const now = dayjs().tz(storeTimezone); // Current time in the store's timezone\n\n const endOfSaleDatetime = dayjs.tz(saleEndDatetime, storeTimezone); // The sale's end datetime in the store's timezone\n\n // If it is passed the end of sale datetime, return null\n if (now.isAfter(endOfSaleDatetime)) {\n return null;\n }\n\n const diff = dayjs.duration(endOfSaleDatetime.diff(now));\n\n return {\n days: diff.days(),\n hours: diff.hours(),\n minutes: diff.minutes(),\n seconds: diff.seconds(),\n };\n };\n\n// #############################################################################\n// Sales methods\n// #############################################################################\n/**\n * Black Friday Sale\n * Returns the time left until the end of Black Friday for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Black Friday, null otherwise\n */\nexport const getTimeUntilEndOfBlackFridayByStore = getSaleEndMethod(\n \"2024-12-02 23:59:59\",\n);\n\n/**\n * Holiday Sale\n * Returns the time left until the end of Holiday Sale for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Holiday Sale, null otherwise\n */\nexport const getTimeUntilEndOfHolidaySaleByStore = getSaleEndMethod(\n \"2024-12-27 23:59:59\",\n);\n"],"names":["extend","timezone","duration","utc","getStoreTimeZone","storeId","StoreId","Br","label","Uk","Eu","Za","Me","Sg","Tw","Jp","Ca","Us","Mx","In","Ph","checkUnreachable","getSaleEndMethod","saleEndDatetime","storeTimezone","now","dayjs","tz","endOfSaleDatetime","isAfter","diff","days","hours","minutes","seconds","getTimeUntilEndOfBlackFridayByStore","getTimeUntilEndOfHolidaySaleByStore"],"mappings":";;;;;;;;;;;;;;;;;;;AAQAA,KAAA,CAAAA,MAAA,CAAOC,iBAAQ,CAAA,SAAA,CAAA,CAAA;AACfD,KAAA,CAAAA,MAAA,CAAOE,iBAAQ,CAAA,SAAA,CAAA,CAAA;AACfF,KAAA,CAAAA,MAAA,CAAOG,YAAG,CAAA,SAAA,CAAA,CAAA;AAOG,MAAAC,gBAAA,GACXC,OAIG,IAAA;EACH,QAAQA,OAAS;IACf,KAAKC,SAAQ,CAAAA,OAAA,CAAAC,EAAA;MACJ,OAAA;QACLC,KAAO,EAAA,OAAA;QACPP,QAAU,EA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;IACF;MACEoB,MAAA,CAAAA,gBAAA,CAAiBhB,OAAO,CAAA;MAEjB,OAAA;QACLG,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;EACJ;AACF,CAAA;AAeO,MAAMqB,gBACX,GAACC,eACD,IAAClB,OAAsC,IAAA;EACrC,MAAM;IAAEJ,QAAA,EAAUuB;EAAc,CAAA,GAAIpB,iBAAiBC,OAAO,CAAA;EAE5D,MAAMoB,GAAM,GAAAC,cAAA,CAAA,SAAA,CAAA,CAAA,CAAQ,CAAAC,EAAA,CAAGH,aAAa,CAAA;EAEpC,MAAMI,iBAAoB,GAAAF,cAAA,CAAA,SAAA,CAAA,CAAMC,EAAG,CAAAJ,eAAA,EAAiBC,aAAa,CAAA;EAG7D,IAAAC,GAAA,CAAII,OAAQ,CAAAD,iBAAiB,CAAG,EAAA;IAC3B,OAAA,IAAA;EACT;EAEA,MAAME,OAAOJ,cAAAA,CAAAA,SAAAA,CAAM,CAAAxB,QAAA,CAAS0B,iBAAkB,CAAAE,IAAA,CAAKL,GAAG,CAAC,CAAA;EAEhD,OAAA;IACLM,IAAA,EAAMD,KAAKC,IAAK,CAAA,CAAA;IAChBC,KAAA,EAAOF,KAAKE,KAAM,CAAA,CAAA;IAClBC,OAAA,EAASH,KAAKG,OAAQ,CAAA,CAAA;IACtBC,OAAA,EAASJ,KAAKI,OAAQ,CAAA;EAAA,CACxB;AACF,CAAA;AAUK,MAAMC,mCAAsC,GAAAb,gBAAA,CACjD,qBACF,CAAA;AAOO,MAAMc,mCAAsC,GAAAd,gBAAA,CACjD,qBACF,CAAA;;;;"}
@@ -0,0 +1,99 @@
1
+ import dayjs, { extend } from 'dayjs';
2
+ import duration from 'dayjs/plugin/duration';
3
+ import timezone from 'dayjs/plugin/timezone';
4
+ import utc from 'dayjs/plugin/utc';
5
+ import '../types/index.mjs';
6
+ import { checkUnreachable } from './errors.mjs';
7
+ import { StoreId } from '../types/generated.mjs';
8
+ "use strict";
9
+ extend(timezone);
10
+ extend(duration);
11
+ extend(utc);
12
+ const getStoreTimeZone = storeId => {
13
+ switch (storeId) {
14
+ case StoreId.Br:
15
+ return {
16
+ label: "UTC-3",
17
+ timezone: "America/Fortaleza"
18
+ };
19
+ case StoreId.Uk:
20
+ return {
21
+ label: "GMT",
22
+ timezone: "Etc/GMT"
23
+ };
24
+ case StoreId.Eu:
25
+ case StoreId.Za:
26
+ return {
27
+ label: "EET",
28
+ timezone: "EET"
29
+ };
30
+ case StoreId.Me:
31
+ return {
32
+ label: "GST",
33
+ timezone: "Asia/Dubai"
34
+ };
35
+ case StoreId.Sg:
36
+ return {
37
+ label: "SGT",
38
+ timezone: "Asia/Singapore"
39
+ };
40
+ case StoreId.Tw:
41
+ return {
42
+ label: "CST",
43
+ timezone: "Asia/Shanghai"
44
+ };
45
+ case StoreId.Jp:
46
+ return {
47
+ label: "JST",
48
+ timezone: "Asia/Tokyo"
49
+ };
50
+ case StoreId.Ca:
51
+ case StoreId.Us:
52
+ return {
53
+ label: "PST",
54
+ timezone: "US/Pacific"
55
+ };
56
+ case StoreId.Mx:
57
+ return {
58
+ label: "CST",
59
+ timezone: "America/Mexico_City"
60
+ };
61
+ case StoreId.In:
62
+ return {
63
+ label: "IST",
64
+ timezone: "Asia/Kolkata"
65
+ };
66
+ case StoreId.Ph:
67
+ return {
68
+ label: "PHT",
69
+ timezone: "Asia/Manila"
70
+ };
71
+ default:
72
+ checkUnreachable(storeId);
73
+ return {
74
+ label: "PST",
75
+ timezone: "US/Pacific"
76
+ };
77
+ }
78
+ };
79
+ const getSaleEndMethod = saleEndDatetime => storeId => {
80
+ const {
81
+ timezone: storeTimezone
82
+ } = getStoreTimeZone(storeId);
83
+ const now = dayjs().tz(storeTimezone);
84
+ const endOfSaleDatetime = dayjs.tz(saleEndDatetime, storeTimezone);
85
+ if (now.isAfter(endOfSaleDatetime)) {
86
+ return null;
87
+ }
88
+ const diff = dayjs.duration(endOfSaleDatetime.diff(now));
89
+ return {
90
+ days: diff.days(),
91
+ hours: diff.hours(),
92
+ minutes: diff.minutes(),
93
+ seconds: diff.seconds()
94
+ };
95
+ };
96
+ const getTimeUntilEndOfBlackFridayByStore = getSaleEndMethod("2024-12-02 23:59:59");
97
+ const getTimeUntilEndOfHolidaySaleByStore = getSaleEndMethod("2024-12-27 23:59:59");
98
+ export { getSaleEndMethod, getStoreTimeZone, getTimeUntilEndOfBlackFridayByStore, getTimeUntilEndOfHolidaySaleByStore };
99
+ //# sourceMappingURL=sales.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sales.mjs","sources":["../../src/utils/sales.ts"],"sourcesContent":["import dayjs, { extend } from \"dayjs\";\nimport duration from \"dayjs/plugin/duration\";\nimport timezone from \"dayjs/plugin/timezone\";\nimport utc from \"dayjs/plugin/utc\";\n\nimport { StoreId } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\n\nextend(timezone);\nextend(duration);\nextend(utc);\n\n/**\n * Returns label and timezone for a given store according\n * to IANA timezone database\n * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\n */\nexport const getStoreTimeZone = (\n storeId: StoreId,\n): {\n label: string;\n timezone: string;\n} => {\n switch (storeId) {\n case StoreId.Br:\n return {\n label: \"UTC-3\",\n timezone: \"America/Fortaleza\",\n };\n case StoreId.Uk:\n return {\n label: \"GMT\",\n timezone: \"Etc/GMT\",\n };\n case StoreId.Eu:\n case StoreId.Za:\n return {\n label: \"EET\",\n timezone: \"EET\",\n };\n case StoreId.Me:\n return {\n label: \"GST\",\n timezone: \"Asia/Dubai\",\n };\n case StoreId.Sg:\n return {\n label: \"SGT\",\n timezone: \"Asia/Singapore\",\n };\n case StoreId.Tw:\n return {\n label: \"CST\",\n timezone: \"Asia/Shanghai\",\n };\n case StoreId.Jp:\n return {\n label: \"JST\",\n timezone: \"Asia/Tokyo\",\n };\n case StoreId.Ca:\n case StoreId.Us:\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n case StoreId.Mx:\n return {\n label: \"CST\",\n timezone: \"America/Mexico_City\",\n };\n case StoreId.In:\n return {\n label: \"IST\",\n timezone: \"Asia/Kolkata\",\n };\n case StoreId.Ph:\n return {\n label: \"PHT\",\n timezone: \"Asia/Manila\",\n };\n default:\n checkUnreachable(storeId);\n // Fallback to US/CA timezone\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n }\n};\n\nexport interface TimeLeft {\n days: number;\n hours: number;\n minutes: number;\n seconds: number;\n}\n\nexport type SaleEndMethod = (storeId: StoreId) => TimeLeft | null;\n\n/**\n * Returns the time left until the end of the sale for a given store\n * @returns {SaleEndMethod} TimeLeft object if the sale is still active, null otherwise\n */\nexport const getSaleEndMethod =\n (saleEndDatetime: string): SaleEndMethod =>\n (storeId: StoreId): TimeLeft | null => {\n const { timezone: storeTimezone } = getStoreTimeZone(storeId);\n\n const now = dayjs().tz(storeTimezone); // Current time in the store's timezone\n\n const endOfSaleDatetime = dayjs.tz(saleEndDatetime, storeTimezone); // The sale's end datetime in the store's timezone\n\n // If it is passed the end of sale datetime, return null\n if (now.isAfter(endOfSaleDatetime)) {\n return null;\n }\n\n const diff = dayjs.duration(endOfSaleDatetime.diff(now));\n\n return {\n days: diff.days(),\n hours: diff.hours(),\n minutes: diff.minutes(),\n seconds: diff.seconds(),\n };\n };\n\n// #############################################################################\n// Sales methods\n// #############################################################################\n/**\n * Black Friday Sale\n * Returns the time left until the end of Black Friday for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Black Friday, null otherwise\n */\nexport const getTimeUntilEndOfBlackFridayByStore = getSaleEndMethod(\n \"2024-12-02 23:59:59\",\n);\n\n/**\n * Holiday Sale\n * Returns the time left until the end of Holiday Sale for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Holiday Sale, null otherwise\n */\nexport const getTimeUntilEndOfHolidaySaleByStore = getSaleEndMethod(\n \"2024-12-27 23:59:59\",\n);\n"],"names":["extend","timezone","duration","utc","getStoreTimeZone","storeId","StoreId","Br","label","Uk","Eu","Za","Me","Sg","Tw","Jp","Ca","Us","Mx","In","Ph","checkUnreachable","getSaleEndMethod","saleEndDatetime","storeTimezone","now","dayjs","tz","endOfSaleDatetime","isAfter","diff","days","hours","minutes","seconds","getTimeUntilEndOfBlackFridayByStore","getTimeUntilEndOfHolidaySaleByStore"],"mappings":";;;;;;;;AAQAA,MAAA,CAAOC,QAAQ,CAAA;AACfD,MAAA,CAAOE,QAAQ,CAAA;AACfF,MAAA,CAAOG,GAAG,CAAA;AAOG,MAAAC,gBAAA,GACXC,OAIG,IAAA;EACH,QAAQA,OAAS;IACf,KAAKC,OAAQ,CAAAC,EAAA;MACJ,OAAA;QACLC,KAAO,EAAA,OAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAG,EAAA;MACJ,OAAA;QACLD,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAI,EAAA;IACb,KAAKJ,OAAQ,CAAAK,EAAA;MACJ,OAAA;QACLH,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAM,EAAA;MACJ,OAAA;QACLJ,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAO,EAAA;MACJ,OAAA;QACLL,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAQ,EAAA;MACJ,OAAA;QACLN,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAS,EAAA;MACJ,OAAA;QACLP,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAU,EAAA;IACb,KAAKV,OAAQ,CAAAW,EAAA;MACJ,OAAA;QACLT,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAA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CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubnt/store.core",
3
- "version": "9.45.0-alpha.0",
3
+ "version": "9.45.0-alpha.1",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "scripts": {