ingeniuscliq-core 0.5.14 → 0.5.16

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,4 +1,5 @@
1
1
  export * from './axiosGlobal';
2
2
  export * from './strings';
3
3
  export * from './image';
4
+ export * from './schedule';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAE9B,cAAc,WAAW,CAAC;AAE1B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAE9B,cAAc,WAAW,CAAC;AAE1B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { CoreDesignTemplateSchedule, CoreDesignTemplateScheduleDay } from '../types/ui/template';
2
+ /**
3
+ * Formats the entire schedule in natural language
4
+ *
5
+ * Example output (Spanish):
6
+ * "Lunes a Viernes: 9:00 a 17:00
7
+ * Domingo: 9:00 a 11:00 y 12:00 a 17:00"
8
+ *
9
+ * Example output (English):
10
+ * "Monday to Friday: 9:00 to 17:00
11
+ * Sunday: 9:00 to 11:00 and 12:00 to 17:00"
12
+ */
13
+ export declare const formatSchedule: (schedule: CoreDesignTemplateSchedule) => string;
14
+ /**
15
+ * Formats the schedule as an array of strings (one per line)
16
+ */
17
+ export declare const formatScheduleArray: (schedule: CoreDesignTemplateSchedule) => string[];
18
+ /**
19
+ * Gets the current day's schedule
20
+ */
21
+ export declare const getTodaySchedule: (schedule: CoreDesignTemplateSchedule) => CoreDesignTemplateScheduleDay | null;
22
+ /**
23
+ * Checks if the store is currently open based on the schedule
24
+ */
25
+ export declare const isStoreOpen: (schedule: CoreDesignTemplateSchedule, currentTime?: Date) => boolean;
26
+ //# sourceMappingURL=schedule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../src/helpers/schedule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAoGtG;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GAAI,UAAU,0BAA0B,KAAG,MAcrE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,UAAU,0BAA0B,KAAG,MAAM,EAEhF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAU,0BAA0B,KAAG,6BAA6B,GAAG,IAcvG,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,0BAA0B,EAAE,cAAc,IAAI,KAAG,OAetF,CAAC"}
@@ -0,0 +1,102 @@
1
+ import i18n from 'i18next';
2
+
3
+ const DAYS_ORDER = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"];
4
+ const isSameSchedule = (day1, day2) => {
5
+ if (day1.enabled !== day2.enabled) return false;
6
+ if (day1.ranges.length !== day2.ranges.length) return false;
7
+ return day1.ranges.every((range1, index) => {
8
+ const range2 = day2.ranges[index];
9
+ return range1.from === range2.from && range1.to === range2.to;
10
+ });
11
+ };
12
+ const groupConsecutiveDays = (schedule) => {
13
+ const groups = [];
14
+ DAYS_ORDER.forEach((day, index) => {
15
+ const daySchedule = schedule[day];
16
+ if (!daySchedule.enabled) return;
17
+ const lastGroup = groups[groups.length - 1];
18
+ if (lastGroup && isSameSchedule(lastGroup.schedule, daySchedule)) {
19
+ const lastDayInGroup = lastGroup.days[lastGroup.days.length - 1];
20
+ const lastDayIndex = DAYS_ORDER.indexOf(lastDayInGroup);
21
+ let isConsecutive = true;
22
+ for (let i = lastDayIndex + 1; i < index; i++) {
23
+ const intermediateDaySchedule = schedule[DAYS_ORDER[i]];
24
+ if (!intermediateDaySchedule.enabled || !isSameSchedule(daySchedule, intermediateDaySchedule)) {
25
+ isConsecutive = false;
26
+ break;
27
+ }
28
+ }
29
+ if (isConsecutive && index === lastDayIndex + 1) {
30
+ lastGroup.days.push(day);
31
+ } else {
32
+ groups.push({
33
+ days: [day],
34
+ schedule: daySchedule
35
+ });
36
+ }
37
+ } else {
38
+ groups.push({
39
+ days: [day],
40
+ schedule: daySchedule
41
+ });
42
+ }
43
+ });
44
+ return groups;
45
+ };
46
+ const formatDayRange = (days) => {
47
+ if (days.length === 1) {
48
+ return i18n.t(`customizations.schedule.days.${days[0]}`);
49
+ }
50
+ const firstDay = i18n.t(`customizations.schedule.days.${days[0]}`);
51
+ const lastDay = i18n.t(`customizations.schedule.days.${days[days.length - 1]}`);
52
+ const connector = i18n.t("customizations.schedule.to");
53
+ return `${firstDay} ${connector} ${lastDay}`;
54
+ };
55
+ const formatTimeRanges = (schedule) => {
56
+ const separator = ` ${i18n.t("customizations.schedule.and")} `;
57
+ const connector = ` ${i18n.t("customizations.schedule.to")} `;
58
+ return schedule.ranges.map((range) => `${range.from}${connector}${range.to}`).join(separator);
59
+ };
60
+ const formatSchedule = (schedule) => {
61
+ const groups = groupConsecutiveDays(schedule);
62
+ if (groups.length === 0) {
63
+ return i18n.t("customizations.schedule.closed");
64
+ }
65
+ return groups.map((group) => {
66
+ const dayRange = formatDayRange(group.days);
67
+ const timeRange = formatTimeRanges(group.schedule);
68
+ return `${dayRange}: ${timeRange}`;
69
+ }).join("\n");
70
+ };
71
+ const formatScheduleArray = (schedule) => {
72
+ return formatSchedule(schedule).split("\n");
73
+ };
74
+ const getTodaySchedule = (schedule) => {
75
+ const today = (/* @__PURE__ */ new Date()).getDay();
76
+ const dayMapping = {
77
+ 0: "sunday",
78
+ 1: "monday",
79
+ 2: "tuesday",
80
+ 3: "wednesday",
81
+ 4: "thursday",
82
+ 5: "friday",
83
+ 6: "saturday"
84
+ };
85
+ const dayName = dayMapping[today];
86
+ return schedule[dayName] || null;
87
+ };
88
+ const isStoreOpen = (schedule, currentTime) => {
89
+ const now = currentTime || /* @__PURE__ */ new Date();
90
+ const todaySchedule = getTodaySchedule(schedule);
91
+ if (!todaySchedule || !todaySchedule.enabled) {
92
+ return false;
93
+ }
94
+ const currentHour = now.getHours();
95
+ const currentMinute = now.getMinutes();
96
+ const currentTimeString = `${currentHour.toString().padStart(2, "0")}:${currentMinute.toString().padStart(2, "0")}`;
97
+ return todaySchedule.ranges.some((range) => {
98
+ return currentTimeString >= range.from && currentTimeString <= range.to;
99
+ });
100
+ };
101
+
102
+ export { formatSchedule, formatScheduleArray, getTodaySchedule, isStoreOpen };
@@ -2,6 +2,7 @@ import { useEffect } from 'react';
2
2
  import { useCustomizationStore } from '../stores/customizationStore.js';
3
3
  import '../helpers/axiosGlobal.js';
4
4
  import { getImageUrlByTenant } from '../helpers/image.js';
5
+ import 'i18next';
5
6
  import logoFallback from '../assets/logo.svg.js';
6
7
 
7
8
  function useDocumentMeta() {
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ export { CoreBuilder } from './classes/CoreBuilder.js';
2
2
  export { api, ensureCsrfToken, initAxiosConfigs } from './helpers/axiosGlobal.js';
3
3
  export { capitalizeFirstLetter } from './helpers/strings.js';
4
4
  export { getImageUrlByTenant } from './helpers/image.js';
5
+ export { formatSchedule, formatScheduleArray, getTodaySchedule, isStoreOpen } from './helpers/schedule.js';
5
6
  export { resources } from './i18n/config.js';
6
7
  export { loadModuleTranslations } from './i18n/utils/loadModuleTranslations.js';
7
8
  export { getModuleNamespace } from './i18n/utils/getModuleNamespace.js';
@@ -1,4 +1,6 @@
1
+ const schedule = {"days":{"monday":"Monday","tuesday":"Tuesday","wednesday":"Wednesday","thursday":"Thursday","friday":"Friday","saturday":"Saturday","sunday":"Sunday"},"to":"to","and":"and","closed":"Closed"};
1
2
  const enTranslations = {
3
+ schedule,
2
4
  };
3
5
 
4
- export { enTranslations as default };
6
+ export { enTranslations as default, schedule };
@@ -1,4 +1,6 @@
1
+ const schedule = {"days":{"monday":"Lunes","tuesday":"Martes","wednesday":"Miércoles","thursday":"Jueves","friday":"Viernes","saturday":"Sábado","sunday":"Domingo"},"to":"a","and":"y","closed":"Cerrado"};
1
2
  const esTranslations = {
3
+ schedule,
2
4
  };
3
5
 
4
- export { esTranslations as default };
6
+ export { esTranslations as default, schedule };
@@ -23,11 +23,12 @@ export interface CoreDesignTemplateSettings {
23
23
  store_phone: string;
24
24
  store_about_us: string;
25
25
  store_map_iframe: string;
26
+ store_schedule: CoreDesignTemplateSchedule;
26
27
  server_time: string;
27
28
  policies: {
28
- return_policy: string;
29
- shipping_policy: string;
30
- warranty_policy: string;
29
+ return_policy?: string;
30
+ shipping_policy?: string;
31
+ warranty_policy?: string;
31
32
  };
32
33
  available_coins: CoreDesignTemplateCoin[];
33
34
  current_coin: CoreDesignTemplateCoin;
@@ -40,4 +41,21 @@ export interface CoreDesignTemplateCoin {
40
41
  position: string;
41
42
  exchange_rate: number;
42
43
  }
44
+ export interface CoreDesignTemplateScheduleRange {
45
+ from: string;
46
+ to: string;
47
+ }
48
+ export interface CoreDesignTemplateScheduleDay {
49
+ enabled: boolean;
50
+ ranges: CoreDesignTemplateScheduleRange[];
51
+ }
52
+ export interface CoreDesignTemplateSchedule {
53
+ monday: CoreDesignTemplateScheduleDay;
54
+ tuesday: CoreDesignTemplateScheduleDay;
55
+ wednesday: CoreDesignTemplateScheduleDay;
56
+ thursday: CoreDesignTemplateScheduleDay;
57
+ friday: CoreDesignTemplateScheduleDay;
58
+ saturday: CoreDesignTemplateScheduleDay;
59
+ sunday: CoreDesignTemplateScheduleDay;
60
+ }
43
61
  //# sourceMappingURL=template.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../../src/types/ui/template.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,wBAAwB,EAAE,CAAC;CACtC;AACD,MA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AE,CAAC;CAC7C;AACD,MAAM,WAAW,0BAA0B;IACvC,MAAM,EAAE,6BAA6B,CAAC;IACtC,OAAO,EAAE,6BAA6B,CAAC;IACvC,SAAS,EAAE,6BAA6B,CAAC;IACzC,QAAQ,EAAE,6BAA6B,CAAC;IACxC,MAAM,EAAE,6BAA6B,CAAC;IACtC,QAAQ,EAAE,6BAA6B,CAAC;IACxC,MAAM,EAAE,6BAA6B,CAAC;CACzC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ingeniuscliq-core",
3
- "version": "0.5.14",
3
+ "version": "0.5.16",
4
4
  "description": "IngeniusCliq Core UI y lógica compartida",
5
5
  "license": "MIT",
6
6
  "type": "module",