@dev.smartpricing/message-composer-layer 5.0.2 → 5.0.3-next.0

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.
@@ -3,11 +3,7 @@ import type {
3
3
  AutomationChannel,
4
4
  AutomationTrigger,
5
5
  } from '@dev.smartpricing/message-composer-utils/types'
6
- import {
7
- dateReferenceLabel,
8
- localSendingTime,
9
- type AutomationFormAction,
10
- } from '../../utils/automations/form'
6
+ import { dateReferenceLabel, type AutomationFormAction } from '../../utils/automations/form'
11
7
  import type {
12
8
  AutomationUnavailableItem,
13
9
  AutomationUnavailableKind,
@@ -89,7 +85,7 @@ const cannotBeActive = computed(
89
85
  <span class="mx-2">&bull;</span>
90
86
  {{ t('automations.action.at') }}
91
87
  <span class="font-semibold text-default">
92
- {{ localSendingTime(action.sendingTimeUTC) }}
88
+ {{ action.sendingTime }}
93
89
  </span>
94
90
  <template v-if="action.recurrence">
95
91
  <span class="mx-2">&bull;</span>
@@ -8,7 +8,6 @@ import {
8
8
  AUTOMATION_RECURRENCES,
9
9
  cloneFormData,
10
10
  dateReferenceValue,
11
- localSendingTime,
12
11
  parseDateReferenceValue,
13
12
  type AutomationFormAction,
14
13
  type AutomationRecurrence,
@@ -135,10 +134,10 @@ function setDateReference(value: string) {
135
134
  if (edited.value) Object.assign(edited.value, parseDateReferenceValue(value))
136
135
  }
137
136
 
138
- // Every hour of the day, by its UTC value and with the user's clock as label.
137
+ // Every hour of the day, on the property's clock.
139
138
  const sendingTimeOptions = Array.from({ length: 24 }, (_, hour) => {
140
- const value = `${String(hour).padStart(2, '0')}:00:00Z`
141
- return { value, label: localSendingTime(value) }
139
+ const value = `${String(hour).padStart(2, '0')}:00`
140
+ return { value, label: value }
142
141
  })
143
142
 
144
143
  const NO_RECURRENCE = 'none'
@@ -300,7 +299,7 @@ function save() {
300
299
 
301
300
  <UFormField class="w-1/2 px-6" :label="t('automations.channel.sendingTime')">
302
301
  <USelect
303
- v-model="edited.sendingTimeUTC"
302
+ v-model="edited.sendingTime"
304
303
  :items="sendingTimeOptions"
305
304
  class="w-full"
306
305
  :data-testid="automationsTestIds.channelSendingTimeSelect"
@@ -24,7 +24,8 @@ import { automationMetadataForm, metadataFormValue } from './metadata'
24
24
 
25
25
  export const SECONDS_PER_DAY = 24 * 60 * 60
26
26
 
27
- export const DEFAULT_SENDING_TIME = '09:00:00Z'
27
+ /** The sending time is on the property's clock: the engine turns it into UTC per reservation. */
28
+ export const DEFAULT_SENDING_TIME = '09:00'
28
29
 
29
30
  export const AUTOMATION_RECURRENCES = ['daily', 'monthly', 'yearly'] as const
30
31
 
@@ -52,7 +53,8 @@ export interface AutomationFormAction {
52
53
  direction: DateReferenceDirection
53
54
  /** The delay, in whole days before or after the Date Reference. */
54
55
  days: number
55
- sendingTimeUTC: string
56
+ /** `HH:MM` on the property's clock. */
57
+ sendingTime: string
56
58
  recurrence?: AutomationRecurrence
57
59
  strictDelay: boolean
58
60
  preventDuplicates: boolean
@@ -101,7 +103,7 @@ export function newAutomationFormAction(
101
103
  dateReference: dateReference?.key ?? '',
102
104
  direction: dateReference?.directions[0]?.direction ?? 'after',
103
105
  days: 0,
104
- sendingTimeUTC: DEFAULT_SENDING_TIME,
106
+ sendingTime: DEFAULT_SENDING_TIME,
105
107
  strictDelay: false,
106
108
  preventDuplicates: true,
107
109
  }
@@ -128,8 +130,7 @@ function toFormSchedule(config: AutomationActionConfig): AutomationFormSchedule
128
130
  dateReference: typeof config.dateTimeReference === 'string' ? config.dateTimeReference : '',
129
131
  direction,
130
132
  days: Math.abs(delay) / SECONDS_PER_DAY,
131
- sendingTimeUTC:
132
- typeof config.sendingTimeUTC === 'string' ? config.sendingTimeUTC : DEFAULT_SENDING_TIME,
133
+ sendingTime: storedSendingTime(config),
133
134
  recurrence: AUTOMATION_RECURRENCES.find((recurrence) => recurrence === config.recurrence),
134
135
  strictDelay: config.strictDelay === true,
135
136
  preventDuplicates: config.preventDuplicates === true,
@@ -185,13 +186,20 @@ export function dateReferenceLabel(action: AutomationFormAction, trigger: Automa
185
186
  )
186
187
  }
187
188
 
188
- /** The sending time on the user's clock: the engine keeps it in UTC. */
189
- export function localSendingTime(sendingTimeUTC: string): string {
190
- return new Date(`2000-01-01T${sendingTimeUTC}`).toLocaleTimeString([], {
191
- hour: '2-digit',
192
- minute: '2-digit',
193
- hour12: false,
194
- })
189
+ /**
190
+ * The sending time of a stored Action. One saved before PAY-2867 has only
191
+ * `sendingTimeUTC`, read on Europe/Rome's solar time (UTC+1): the engine
192
+ * reads it the same way until the migration rewrites it.
193
+ */
194
+ function storedSendingTime(config: AutomationActionConfig): string {
195
+ if (typeof config.sendingTime === 'string') return config.sendingTime
196
+ const legacy =
197
+ typeof config.sendingTimeUTC === 'string'
198
+ ? config.sendingTimeUTC.match(/^(\d{2}):(\d{2})/)
199
+ : null
200
+ if (!legacy) return DEFAULT_SENDING_TIME
201
+ const hours = (Number(legacy[1]) + 1) % 24
202
+ return `${String(hours).padStart(2, '0')}:${legacy[2]}`
195
203
  }
196
204
 
197
205
  function toActionConfig(action: AutomationFormSchedule): AutomationActionInput['config'] {
@@ -206,7 +214,7 @@ function toActionConfig(action: AutomationFormSchedule): AutomationActionInput['
206
214
  delay: delay || 0,
207
215
  dateTimeReference: action.dateReference,
208
216
  delayDirection: action.days === 0 ? action.direction : undefined,
209
- sendingTimeUTC: action.sendingTimeUTC,
217
+ sendingTime: action.sendingTime,
210
218
  recurrence: action.recurrence,
211
219
  strictDelay: action.strictDelay || undefined,
212
220
  preventDuplicates: action.preventDuplicates,
@@ -228,10 +236,12 @@ function toActionInput(action: AutomationFormAction): AutomationActionInput {
228
236
  const changes = Object.fromEntries(
229
237
  Object.entries(config).filter(([key, value]) => value !== unchanged[key]),
230
238
  )
239
+ // A new sending time replaces the legacy UTC one, which the engine would otherwise keep.
240
+ const { sendingTimeUTC: _legacy, ...kept } = storedConfig
231
241
  return {
232
242
  status: action.status,
233
243
  config: {
234
- ...storedConfig,
244
+ ...('sendingTime' in changes ? kept : storedConfig),
235
245
  channel: config.channel,
236
246
  dateTimeReference: config.dateTimeReference,
237
247
  ...changes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev.smartpricing/message-composer-layer",
3
- "version": "5.0.2",
3
+ "version": "5.0.3-next.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -35,7 +35,7 @@
35
35
  "vue-router": "^5.0.7",
36
36
  "vue3-emoji-picker": "^1.1.8",
37
37
  "zod": "^4.4.3",
38
- "@dev.smartpricing/message-composer-utils": "5.0.2"
38
+ "@dev.smartpricing/message-composer-utils": "5.0.3-next.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@dev.smartpricing/platform-layer": "^0.0.23",