@feedmepos/mf-order-setting 0.0.102 → 0.0.103

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 (139) hide show
  1. package/dist/{DisplaySystemView-jnt6letY.js → DisplaySystemView-BBiZqcWq.js} +1497 -1468
  2. package/dist/{FoodCourtInvitationsView-DoynqFWB.js → FoodCourtInvitationsView-DwOkVs9m.js} +4 -4
  3. package/dist/{FoodCourtOrderSettingsView-DYZLhTHy.js → FoodCourtOrderSettingsView-C9Ag5Bsg.js} +1 -1
  4. package/dist/FoodCourtOrdersView-y4EwK3sn.js +1173 -0
  5. package/dist/{FoodCourtStallsView-CRMTt5BB.js → FoodCourtStallsView-Bi8H-yR7.js} +2 -2
  6. package/dist/{FoodCourtStatusView-C-b-eI-8.js → FoodCourtStatusView-jugAzTKg.js} +1 -1
  7. package/dist/KioskDevicesView-CYiew4X5.js +4 -0
  8. package/dist/KioskDevicesView.vue_vue_type_script_setup_true_lang-BCvbeo7R.js +1497 -0
  9. package/dist/KioskSettingView-AKBiij9a.js +1124 -0
  10. package/dist/KioskView-zKB6mC8I.js +765 -0
  11. package/dist/{OrderSettingsView-BBCnekaj.js → OrderSettingsView-CoV_yX3m.js} +22064 -21635
  12. package/dist/{RestaurantSelector.vue_vue_type_script_setup_true_lang-DjoTyV6m.js → RestaurantSelector.vue_vue_type_script_setup_true_lang-KSMU_jGl.js} +1 -1
  13. package/dist/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
  14. package/dist/{app-Dvk30CIa.js → app-CmuI6uSl.js} +3589 -2902
  15. package/dist/app.js +1 -1
  16. package/dist/{dayjs.min-DUFHhM7O.js → dayjs.min-B3MssMma.js} +1 -1
  17. package/dist/{featureFlag-BvcirzHS.js → featureFlag-CWvkPOBY.js} +123 -130
  18. package/dist/frontend/mf-order/src/api/food-court/index.d.ts +51 -0
  19. package/dist/frontend/mf-order/src/api/kiosk/index.d.ts +4 -0
  20. package/dist/frontend/mf-order/src/api/payment/index.d.ts +8 -0
  21. package/dist/frontend/mf-order/src/api/queue/index.d.ts +13 -0
  22. package/dist/frontend/mf-order/src/api/restaurant-setting/index.d.ts +9 -1
  23. package/dist/frontend/mf-order/src/app.d.ts +687 -0
  24. package/dist/frontend/mf-order/src/main.d.ts +687 -0
  25. package/dist/frontend/mf-order/src/modules/display-system/interface.d.ts +5 -0
  26. package/dist/frontend/mf-order/src/modules/kiosk/interface.d.ts +4 -0
  27. package/dist/frontend/mf-order/src/modules/kiosk/license.d.ts +92 -0
  28. package/dist/frontend/mf-order/src/modules/kiosk/outletLoad.d.ts +15 -0
  29. package/dist/frontend/mf-order/src/modules/kiosk/settingsSections.d.ts +24 -0
  30. package/dist/frontend/mf-order/src/modules/kiosk/useKioskSettings.d.ts +29 -0
  31. package/dist/frontend/mf-order/src/modules/payment/paymentDevice.d.ts +58 -0
  32. package/dist/frontend/mf-order/src/stores/kiosk/index.d.ts +67 -1
  33. package/dist/frontend/mf-order/src/stores/order-setting/index.d.ts +19 -10
  34. package/dist/frontend/mf-order/src/stores/payment/index.d.ts +59 -1
  35. package/dist/frontend/mf-order/src/views/food-court/food-court-export.d.ts +38 -0
  36. package/dist/frontend/mf-order/src/views/kiosk/devices/KioskDeviceCard.vue.d.ts +3 -0
  37. package/dist/frontend/mf-order/src/views/kiosk/devices/KioskDevicesView.vue.d.ts +7 -0
  38. package/dist/frontend/mf-order/src/views/kiosk/devices/KioskLicenseSummary.vue.d.ts +7 -0
  39. package/dist/frontend/mf-order/src/views/kiosk/devices/KioskLicensesView.vue.d.ts +6 -0
  40. package/dist/frontend/mf-order/src/views/kiosk/devices/KioskOtpDialog.vue.d.ts +3 -0
  41. package/dist/frontend/mf-order/src/views/kiosk/devices/KioskPaymentDeviceCard.vue.d.ts +17 -0
  42. package/dist/frontend/mf-order/src/views/kiosk/settings/KioskSettingView.vue.d.ts +5 -2
  43. package/dist/frontend/mf-order/src/views/order-settings/pickup/PickUpSettingDialogContent.vue.d.ts +0 -9
  44. package/dist/frontend/mf-order/src/views/order-settings/pos-status/PosOrderingStatus.vue.d.ts +17 -0
  45. package/dist/frontend/mf-order/src/views/order-settings/pos-status/pos-status.d.ts +44 -0
  46. package/dist/frontend/mf-order/src/views/order-settings/queue/called-message.d.ts +1 -0
  47. package/dist/frontend/mf-order/src/views/order-settings/queue/phone-join-mode.d.ts +25 -0
  48. package/dist/frontend/mf-order/tsconfig.app.tsbuildinfo +1 -1
  49. package/dist/{index-C4n5H7t3.js → index-BQa8AudZ.js} +3 -3
  50. package/dist/index-CMOvrim4.js +147 -0
  51. package/dist/{index-CW4VlFWz.js → index-D5qh2_4b.js} +1 -1
  52. package/dist/{index-C5n6lil6.js → index-Dup6kWLX.js} +6 -6
  53. package/dist/{index-CGxCWKHB.js → index-wuFIsXHT.js} +188 -179
  54. package/dist/{order.dto-Cb_gh3iB.js → order.dto-BD9raQG5.js} +2782 -2735
  55. package/dist/package/entity/display/blocks.d.ts +12 -2
  56. package/dist/package/entity/marketing/marketing.dto.d.ts +18 -18
  57. package/dist/package/entity/order-platform/external/reconciliation/external-reconciliation.do.d.ts +24 -24
  58. package/dist/package/entity/order-platform/menu.dto.d.ts +20 -20
  59. package/dist/package/entity/order-setting/order-setting.do.d.ts +10 -0
  60. package/dist/package/entity/order-setting/order-setting.dto.d.ts +26 -0
  61. package/dist/package/entity/order-setting/queue/queue.do.d.ts +23 -0
  62. package/dist/package/entity/order-setting/queue/queue.dto.d.ts +14 -0
  63. package/dist/package/entity/queue/queue.do.d.ts +153 -0
  64. package/dist/package/entity/queue/queue.dto.d.ts +221 -2
  65. package/dist/package/entity/queue/queue.enum.d.ts +5 -0
  66. package/dist/package/entity/restaurant/restaurant.dto.d.ts +20 -0
  67. package/dist/style.css +1 -1
  68. package/dist/{index-ILnighyU.js → useInternalUser-CHtaur9A.js} +93 -81
  69. package/package.json +2 -1
  70. package/src/api/food-court/index.ts +63 -0
  71. package/src/api/kiosk/index.ts +8 -0
  72. package/src/api/payment/index.ts +18 -1
  73. package/src/api/queue/index.ts +39 -0
  74. package/src/api/restaurant-setting/index.ts +14 -0
  75. package/src/locales/en-US.json +197 -26
  76. package/src/locales/ja-JP.json +193 -23
  77. package/src/locales/th-TH.json +193 -21
  78. package/src/locales/zh-CN.json +197 -23
  79. package/src/modules/display-system/interface.spec.ts +26 -1
  80. package/src/modules/display-system/interface.ts +20 -0
  81. package/src/modules/kiosk/interface.ts +4 -0
  82. package/src/modules/kiosk/license.spec.ts +167 -0
  83. package/src/modules/kiosk/license.ts +175 -0
  84. package/src/modules/kiosk/outletLoad.spec.ts +25 -0
  85. package/src/modules/kiosk/outletLoad.ts +19 -0
  86. package/src/modules/kiosk/settingsSections.spec.ts +85 -0
  87. package/src/modules/kiosk/settingsSections.ts +82 -0
  88. package/src/modules/kiosk/useKioskSettings.spec.ts +157 -0
  89. package/src/modules/kiosk/useKioskSettings.ts +61 -0
  90. package/src/modules/payment/paymentDevice.spec.ts +175 -0
  91. package/src/modules/payment/paymentDevice.ts +156 -0
  92. package/src/stores/kiosk/index.ts +16 -1
  93. package/src/stores/kiosk/mapper.ts +2 -0
  94. package/src/stores/order-setting/index.spec.ts +83 -0
  95. package/src/stores/order-setting/index.ts +49 -27
  96. package/src/stores/payment/index.spec.ts +86 -0
  97. package/src/stores/payment/index.ts +48 -2
  98. package/src/views/display-system/DisplayInspector.vue +17 -8
  99. package/src/views/display-system/DisplayTemplateEditor.vue +3 -1
  100. package/src/views/food-court/FoodCourtOrdersView.vue +46 -1
  101. package/src/views/food-court/food-court-export.spec.ts +151 -0
  102. package/src/views/food-court/food-court-export.ts +283 -0
  103. package/src/views/kiosk/KioskStatePanel.vue +2 -2
  104. package/src/views/kiosk/KioskView.vue +219 -82
  105. package/src/views/kiosk/devices/KioskDeviceCard.vue +148 -23
  106. package/src/views/kiosk/devices/KioskDevicesView.vue +48 -10
  107. package/src/views/kiosk/devices/KioskLicenseSummary.vue +79 -0
  108. package/src/views/kiosk/devices/KioskLicensesView.vue +152 -0
  109. package/src/views/kiosk/devices/KioskOtpDialog.vue +41 -1
  110. package/src/views/kiosk/devices/KioskPaymentDeviceCard.spec.ts +97 -0
  111. package/src/views/kiosk/devices/KioskPaymentDeviceCard.vue +221 -0
  112. package/src/views/kiosk/settings/KioskPaymentTypeSection.vue +1 -1
  113. package/src/views/kiosk/settings/KioskSettingView.vue +702 -419
  114. package/src/views/order-settings/delivery/DeliverySetting.vue +4 -0
  115. package/src/views/order-settings/dine-in/DineInSetting.vue +4 -0
  116. package/src/views/order-settings/pickup/PickUpSetting.vue +4 -4
  117. package/src/views/order-settings/pickup/PickUpSettingDialogContent.vue +0 -23
  118. package/src/views/order-settings/pos-status/PosOrderingStatus.spec.ts +207 -0
  119. package/src/views/order-settings/pos-status/PosOrderingStatus.vue +209 -0
  120. package/src/views/order-settings/pos-status/pos-status.spec.ts +103 -0
  121. package/src/views/order-settings/pos-status/pos-status.ts +86 -0
  122. package/src/views/order-settings/queue/QueueSetting.source.spec.ts +43 -0
  123. package/src/views/order-settings/queue/QueueSetting.vue +289 -15
  124. package/src/views/order-settings/queue/called-message.spec.ts +29 -1
  125. package/src/views/order-settings/queue/called-message.ts +18 -0
  126. package/src/views/order-settings/queue/phone-join-mode.spec.ts +90 -0
  127. package/src/views/order-settings/queue/phone-join-mode.ts +49 -0
  128. package/dist/FoodCourtOrdersView-CAPOycT3.js +0 -544
  129. package/dist/KioskDevicesView-B0U9JxRl.js +0 -4
  130. package/dist/KioskDevicesView.vue_vue_type_script_setup_true_lang-V3ai4FVI.js +0 -937
  131. package/dist/KioskSettingView-rdom_aS8.js +0 -880
  132. package/dist/KioskView-DOON9zR6.js +0 -516
  133. package/dist/frontend/mf-order/src/views/kiosk/settings/KioskDisplayStandSection.vue.d.ts +0 -10
  134. package/dist/frontend/mf-order/src/views/kiosk/settings/KioskInstructionSection.vue.d.ts +0 -15
  135. package/dist/frontend/mf-order/src/views/kiosk/settings/KioskPickAtCounterSection.vue.d.ts +0 -10
  136. package/dist/index-CaHG3M7C.js +0 -135
  137. package/src/views/kiosk/settings/KioskDisplayStandSection.vue +0 -189
  138. package/src/views/kiosk/settings/KioskInstructionSection.vue +0 -40
  139. package/src/views/kiosk/settings/KioskPickAtCounterSection.vue +0 -68
@@ -0,0 +1,175 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import {
3
+ KIOSK_PAYMENT_DEVICE_ECR_FIELDS,
4
+ KIOSK_PAYMENT_DEVICE_FIELDS,
5
+ paymentPortalKioskUrl,
6
+ reportedTerminalDiffers,
7
+ toKioskPaymentDevice,
8
+ toKioskPaymentDevices
9
+ } from './paymentDevice'
10
+
11
+ // Shape of one payment-service FdoPortalTerminal, as GET /portal/restaurants/:id/terminals
12
+ // returns it today: secrets included.
13
+ const SECRETS = {
14
+ secretKey: 'SECRET-secretKey-value',
15
+ token: 'SECRET-token-value',
16
+ securityCode: 'SECRET-securityCode-value',
17
+ bindCode: 'SECRET-bindCode-value',
18
+ privateKey: 'SECRET-privateKey-value',
19
+ uniqueId: 'SECRET-uniqueId-value',
20
+ packageId: 'SECRET-packageId-value'
21
+ }
22
+
23
+ function rawTerminal(overrides: Record<string, unknown> = {}) {
24
+ return {
25
+ _id: '6aa6053380198fa2d7f0f64d',
26
+ referenceId: '6a85487b62041a001c21d405',
27
+ name: '6a85487b62041a001c21d405-9328631caa68c0e9',
28
+ status: 'Active',
29
+ deviceType: 'KIOSK',
30
+ deviceId: '6a85487b62041a001c21d405-9328631caa68c0e9',
31
+ securityCode: SECRETS.securityCode,
32
+ bindCode: SECRETS.bindCode,
33
+ secretKey: SECRETS.secretKey,
34
+ token: SECRETS.token,
35
+ gateways: [
36
+ { gateway: 'Softspace', config: { packageId: SECRETS.packageId, uniqueId: SECRETS.uniqueId } }
37
+ ],
38
+ ecrs: [
39
+ { gateway: 'FeedMe', config: { terminalId: 'FM-T1' } },
40
+ {
41
+ gateway: 'Ghl',
42
+ config: { merchantId: 'GHL-M1', terminalId: 'GHL-T1', privateKey: SECRETS.privateKey }
43
+ },
44
+ { gateway: 'Beam', config: { externalTerminalId: 'BEAM-X1' } },
45
+ { gateway: 'Bri', config: null }
46
+ ],
47
+ ecrIntegrations: [
48
+ { gateway: 'Revenue', receiptName: 'Revenue', config: { ip: '10.0.0.5', type: 'IP' } },
49
+ { gateway: 'Revenue' }
50
+ ],
51
+ qrIntegrations: [{ gateway: 'PROMPTPAY', config: { account: '0812345678' } }],
52
+ paymentCheckouts: [{ id: 'c1', extra: { apiKey: 'SECRET-extra' } }],
53
+ restaurant: { _id: 'r', profile: { name: 'Outlet' } },
54
+ createdAt: '2026-09-13T02:06:42.000Z',
55
+ updatedAt: '2026-10-25T08:09:12.000Z',
56
+ ...overrides
57
+ }
58
+ }
59
+
60
+ /** Every key at every depth of a value. */
61
+ function allKeys(value: unknown, out: string[] = []): string[] {
62
+ if (Array.isArray(value)) value.forEach((v) => allKeys(v, out))
63
+ else if (value && typeof value === 'object') {
64
+ for (const [k, v] of Object.entries(value)) {
65
+ out.push(k)
66
+ allKeys(v, out)
67
+ }
68
+ }
69
+ return out
70
+ }
71
+
72
+ describe('toKioskPaymentDevice: never lets a secret through', () => {
73
+ it('returns no secret value anywhere in the mapped object', () => {
74
+ const mapped = toKioskPaymentDevice(rawTerminal())
75
+ const text = JSON.stringify(mapped)
76
+ for (const [field, value] of Object.entries(SECRETS)) {
77
+ expect(text, `secret ${field} leaked`).not.toContain(value)
78
+ }
79
+ expect(text).not.toContain('SECRET-')
80
+ })
81
+
82
+ it('returns only the allowed fields, at every depth', () => {
83
+ const mapped = toKioskPaymentDevice(rawTerminal())!
84
+ expect(Object.keys(mapped).sort()).toEqual([...KIOSK_PAYMENT_DEVICE_FIELDS].sort())
85
+ for (const ecr of mapped.ecrs) {
86
+ expect(Object.keys(ecr).sort()).toEqual([...KIOSK_PAYMENT_DEVICE_ECR_FIELDS].sort())
87
+ }
88
+ const forbidden = /secret|token|security|bind|private|password|unique|package|^key$|apikey|config|extra|restaurant|checkout/i
89
+ expect(allKeys(mapped).filter((k) => forbidden.test(k))).toEqual([])
90
+ })
91
+
92
+ it('the allowed field lists themselves hold no secret-looking name', () => {
93
+ const names = [...KIOSK_PAYMENT_DEVICE_FIELDS, ...KIOSK_PAYMENT_DEVICE_ECR_FIELDS]
94
+ expect(names.filter((n) => /secret|token|security|bind|private|password|key/i.test(n))).toEqual([])
95
+ })
96
+ })
97
+
98
+ describe('toKioskPaymentDevice: what support sees', () => {
99
+ it('maps status and each payment portal tab', () => {
100
+ expect(toKioskPaymentDevice(rawTerminal())).toEqual({
101
+ id: '6aa6053380198fa2d7f0f64d',
102
+ name: '6a85487b62041a001c21d405-9328631caa68c0e9',
103
+ deviceId: '6a85487b62041a001c21d405-9328631caa68c0e9',
104
+ status: 'Active',
105
+ softPosGateways: ['Softspace'],
106
+ ecrs: [
107
+ { gateway: 'FeedMe', merchantId: null, terminalId: 'FM-T1' },
108
+ { gateway: 'Ghl', merchantId: 'GHL-M1', terminalId: 'GHL-T1' },
109
+ { gateway: 'Beam', merchantId: null, terminalId: 'BEAM-X1' },
110
+ { gateway: 'Bri', merchantId: null, terminalId: null }
111
+ ],
112
+ ecrIntegrations: ['Revenue'],
113
+ qrGateways: ['PROMPTPAY']
114
+ })
115
+ })
116
+
117
+ it('handles a terminal with nothing set up', () => {
118
+ const mapped = toKioskPaymentDevice(
119
+ rawTerminal({ gateways: null, ecrs: undefined, ecrIntegrations: [], qrIntegrations: 'x', name: null })
120
+ )
121
+ expect(mapped).toMatchObject({
122
+ name: null,
123
+ softPosGateways: [],
124
+ ecrs: [],
125
+ ecrIntegrations: [],
126
+ qrGateways: []
127
+ })
128
+ })
129
+
130
+ it('drops terminals without an id or a device id, and non-objects', () => {
131
+ expect(toKioskPaymentDevice(rawTerminal({ deviceId: null }))).toBeNull()
132
+ expect(toKioskPaymentDevice(rawTerminal({ _id: '' }))).toBeNull()
133
+ expect(toKioskPaymentDevice('nope')).toBeNull()
134
+ expect(toKioskPaymentDevices([rawTerminal(), null, rawTerminal({ deviceId: null })])).toHaveLength(1)
135
+ expect(toKioskPaymentDevices({ data: [] })).toEqual([])
136
+ })
137
+ })
138
+
139
+ describe('paymentPortalKioskUrl', () => {
140
+ it('builds the payment portal kiosk page link support uses today', () => {
141
+ expect(
142
+ paymentPortalKioskUrl('https://portal.feedme.cc', '6aa6053380198fa2d7f0f64d', {
143
+ country: 'MY',
144
+ businessId: '6a85484c8cf058001c09a80c',
145
+ restaurantId: '6a85487b62041a001c21d405'
146
+ })
147
+ ).toBe(
148
+ 'https://portal.feedme.cc/payment/admin/terminal/kiosk/6aa6053380198fa2d7f0f64d?country=MY&businessId=6a85484c8cf058001c09a80c&restaurantId=6a85487b62041a001c21d405'
149
+ )
150
+ })
151
+
152
+ it('leaves out missing context and keeps the current host', () => {
153
+ expect(paymentPortalKioskUrl('https://portal.feedmedev.cc', 't1', { country: 'SG' })).toBe(
154
+ 'https://portal.feedmedev.cc/payment/admin/terminal/kiosk/t1?country=SG'
155
+ )
156
+ })
157
+ })
158
+
159
+ describe('reportedTerminalDiffers', () => {
160
+ const device = toKioskPaymentDevice(rawTerminal())
161
+ const reported = { gateway: 'E_GHL', merchantId: 'GHL-M1', terminalId: 'GHL-T1' }
162
+
163
+ it('is false when the payment device has the same GHL terminal', () => {
164
+ expect(reportedTerminalDiffers(reported, device)).toBe(false)
165
+ })
166
+
167
+ it('is true when the GHL terminal id differs', () => {
168
+ expect(reportedTerminalDiffers({ ...reported, terminalId: 'OTHER' }, device)).toBe(true)
169
+ })
170
+
171
+ it('is false when there is nothing to compare', () => {
172
+ expect(reportedTerminalDiffers(null, device)).toBe(false)
173
+ expect(reportedTerminalDiffers(reported, null)).toBe(false)
174
+ })
175
+ })
@@ -0,0 +1,156 @@
1
+ /**
2
+ * The payment device (payment-service "terminal") that a kiosk uses.
3
+ *
4
+ * A kiosk and its payment device are joined by name: payment-service stores the
5
+ * kiosk as deviceId `<restaurantId>-<machineId>` (see `terminalDeviceId`).
6
+ *
7
+ * The portal endpoint we read (`GET /portal/restaurants/:id/terminals`) returns the
8
+ * whole terminal, secrets included (secretKey, token, securityCode, bindCode, ECR
9
+ * private keys). `toKioskPaymentDevice` copies only the fields below, one by one,
10
+ * so no secret ever reaches the store or the page. Never spread the raw object.
11
+ */
12
+
13
+ export interface KioskPaymentDeviceEcr {
14
+ gateway: string
15
+ merchantId: string | null
16
+ terminalId: string | null
17
+ }
18
+
19
+ export interface KioskPaymentDevice {
20
+ /** payment-service terminal _id, used in the payment portal URL. */
21
+ id: string
22
+ name: string | null
23
+ deviceId: string
24
+ status: string | null
25
+ /** "SoftPos Gateway" tab. */
26
+ softPosGateways: string[]
27
+ /** "ECR Gateway" tab, remote ECR (has terminal / merchant IDs). */
28
+ ecrs: KioskPaymentDeviceEcr[]
29
+ /** "ECR Gateway" tab, ECR integrations on the device (cable / IP). */
30
+ ecrIntegrations: string[]
31
+ /** "QR Gateway" tab. */
32
+ qrGateways: string[]
33
+ }
34
+
35
+ /** The fields `toKioskPaymentDevice` may return. A test fails if this list grows a secret. */
36
+ export const KIOSK_PAYMENT_DEVICE_FIELDS = [
37
+ 'id',
38
+ 'name',
39
+ 'deviceId',
40
+ 'status',
41
+ 'softPosGateways',
42
+ 'ecrs',
43
+ 'ecrIntegrations',
44
+ 'qrGateways'
45
+ ] as const
46
+
47
+ export const KIOSK_PAYMENT_DEVICE_ECR_FIELDS = ['gateway', 'merchantId', 'terminalId'] as const
48
+
49
+ type RawRecord = Record<string, unknown>
50
+
51
+ function isRecord(v: unknown): v is RawRecord {
52
+ return typeof v === 'object' && v !== null && !Array.isArray(v)
53
+ }
54
+
55
+ function str(v: unknown): string | null {
56
+ return typeof v === 'string' && v.trim() !== '' ? v : null
57
+ }
58
+
59
+ function records(v: unknown): RawRecord[] {
60
+ return Array.isArray(v) ? v.filter(isRecord) : []
61
+ }
62
+
63
+ function gatewayNames(v: unknown): string[] {
64
+ const names = records(v)
65
+ .map((entry) => str(entry.gateway))
66
+ .filter((name): name is string => name !== null)
67
+ return [...new Set(names)]
68
+ }
69
+
70
+ function toEcr(entry: RawRecord): KioskPaymentDeviceEcr | null {
71
+ const gateway = str(entry.gateway)
72
+ if (!gateway) return null
73
+ const config = isRecord(entry.config) ? entry.config : {}
74
+ return {
75
+ gateway,
76
+ merchantId: str(config.merchantId),
77
+ // FeedMe and GHL use terminalId; Beam and BRI use externalTerminalId.
78
+ terminalId: str(config.terminalId) ?? str(config.externalTerminalId)
79
+ }
80
+ }
81
+
82
+ /** Copy the safe fields of one payment-service terminal. Null when it has no kiosk link. */
83
+ export function toKioskPaymentDevice(raw: unknown): KioskPaymentDevice | null {
84
+ if (!isRecord(raw)) return null
85
+ const id = str(raw._id)
86
+ const deviceId = str(raw.deviceId)
87
+ if (!id || !deviceId) return null
88
+ return {
89
+ id,
90
+ name: str(raw.name),
91
+ deviceId,
92
+ status: str(raw.status),
93
+ softPosGateways: gatewayNames(raw.gateways),
94
+ ecrs: records(raw.ecrs)
95
+ .map(toEcr)
96
+ .filter((ecr): ecr is KioskPaymentDeviceEcr => ecr !== null),
97
+ ecrIntegrations: gatewayNames(raw.ecrIntegrations),
98
+ qrGateways: gatewayNames(raw.qrIntegrations)
99
+ }
100
+ }
101
+
102
+ export function toKioskPaymentDevices(raw: unknown): KioskPaymentDevice[] {
103
+ if (!Array.isArray(raw)) return []
104
+ return raw
105
+ .map(toKioskPaymentDevice)
106
+ .filter((device): device is KioskPaymentDevice => device !== null)
107
+ }
108
+
109
+ export interface PaymentPortalContext {
110
+ country?: string | null
111
+ businessId?: string | null
112
+ restaurantId?: string | null
113
+ }
114
+
115
+ /**
116
+ * The payment portal's kiosk page, as support opens it today:
117
+ * `<portal>/payment/admin/terminal/kiosk/<terminal id>?country=..&businessId=..&restaurantId=..`
118
+ */
119
+ export function paymentPortalKioskUrl(
120
+ portalOrigin: string,
121
+ terminalId: string,
122
+ ctx: PaymentPortalContext
123
+ ): string {
124
+ const url = new URL(
125
+ `/payment/admin/terminal/kiosk/${encodeURIComponent(terminalId)}`,
126
+ portalOrigin
127
+ )
128
+ if (ctx.country) url.searchParams.set('country', ctx.country)
129
+ if (ctx.businessId) url.searchParams.set('businessId', ctx.businessId)
130
+ if (ctx.restaurantId) url.searchParams.set('restaurantId', ctx.restaurantId)
131
+ return url.toString()
132
+ }
133
+
134
+ /** What an older kiosk app reports about the GHL terminal it was set up with. */
135
+ export interface KioskReportedTerminal {
136
+ gateway: string
137
+ merchantId: string
138
+ terminalId: string
139
+ }
140
+
141
+ /**
142
+ * True when the kiosk reports a GHL terminal that the payment device does not have
143
+ * among its GHL ECR gateways (Ghl, Ghl2, Ghl3).
144
+ */
145
+ export function reportedTerminalDiffers(
146
+ reported: KioskReportedTerminal | null | undefined,
147
+ device: KioskPaymentDevice | null
148
+ ): boolean {
149
+ if (!reported || !device) return false
150
+ return !device.ecrs.some(
151
+ (ecr) =>
152
+ ecr.gateway.toLowerCase().startsWith('ghl') &&
153
+ ecr.merchantId === reported.merchantId &&
154
+ ecr.terminalId === reported.terminalId
155
+ )
156
+ }
@@ -3,10 +3,13 @@ import { KioskApi } from "@/api/kiosk";
3
3
  import { ref } from 'vue';
4
4
  import { type MfKioskDevice } from "../../modules/kiosk/interface";
5
5
  import { KioskMapper } from "./mapper";
6
+ import type { MfKioskLicenseList } from "@/modules/kiosk/license";
6
7
 
7
8
  interface State {
8
9
  otp: string;
9
10
  devices: MfKioskDevice[];
11
+ /** Null until loaded, or when loading failed. */
12
+ licenses: MfKioskLicenseList | null;
10
13
  }
11
14
 
12
15
  export const useKioskStore = defineStore('kiosk', () => {
@@ -14,6 +17,7 @@ export const useKioskStore = defineStore('kiosk', () => {
14
17
  const state = ref<State>({
15
18
  otp: '',
16
19
  devices: [],
20
+ licenses: null,
17
21
  });
18
22
 
19
23
  async function requestOtp() {
@@ -26,9 +30,19 @@ export const useKioskStore = defineStore('kiosk', () => {
26
30
  state.value.devices = result.map((r) => KioskMapper.toMfKioskDevice(r));
27
31
  }
28
32
 
33
+ async function getLicenses() {
34
+ try {
35
+ state.value.licenses = await KioskApi.getLicenses();
36
+ } catch (e) {
37
+ // The licence view is extra information: the device list must still work without it.
38
+ state.value.licenses = null;
39
+ throw e;
40
+ }
41
+ }
42
+
29
43
  async function unbind(machineId: string) {
30
44
  await KioskApi.unbind(machineId);
31
- await getDevices();
45
+ await Promise.all([getDevices(), getLicenses().catch(() => undefined)]);
32
46
  }
33
47
 
34
48
  async function updateDevicePin(pinInfo: string, machineId: string) {
@@ -45,6 +59,7 @@ export const useKioskStore = defineStore('kiosk', () => {
45
59
  state: state.value,
46
60
  requestOtp,
47
61
  getDevices,
62
+ getLicenses,
48
63
  unbind,
49
64
  updateDevicePin,
50
65
  updateDeviceRemark
@@ -21,6 +21,8 @@ const toMfKioskDevice = (dto: KioskDeviceDto): MfKioskDevice => {
21
21
  operatingSystem: dto.operatingSystem ?? undefined,
22
22
  osVersion: dto.osVersion ?? undefined,
23
23
  lastStartup: dto.lastStartup ? new Date(dto.lastStartup) : undefined,
24
+ licenseId: dto.licenseId ?? undefined,
25
+ licenseExpiredAt: dto.expiredAt ? new Date(dto.expiredAt) : undefined,
24
26
  };
25
27
  };
26
28
 
@@ -0,0 +1,83 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
2
+ import { createPinia, setActivePinia } from 'pinia'
3
+
4
+ const api = vi.hoisted(() => ({
5
+ getOrderSetting: vi.fn(),
6
+ updateOrderSetting: vi.fn()
7
+ }))
8
+ const outlet = vi.hoisted(() => ({ id: 'r1' as string | null }))
9
+
10
+ vi.mock('@/api/order-setting', () => ({ OrderSettingApi: api }))
11
+ vi.mock('@/api', () => ({ SvcConfig: { getRestaurantId: () => outlet.id } }))
12
+ vi.mock('./mapper', () => ({
13
+ OrderSettingMapper: {
14
+ convertOrderSettingDto: (dto: { _id: string }) => ({ kiosk: { from: dto._id } }),
15
+ toOrderKioskSettingsDto: () => ({ kioskSettings: { k: 1 } }),
16
+ toKioskSequenceSettings: () => ({ s: 1 })
17
+ }
18
+ }))
19
+
20
+ import { useOrderSettings } from './index'
21
+
22
+ const kiosk = {} as Parameters<ReturnType<typeof useOrderSettings>['updateKioskSetting']>[0]
23
+
24
+ describe('order-setting store, kiosk save', () => {
25
+ beforeEach(() => {
26
+ setActivePinia(createPinia())
27
+ api.getOrderSetting.mockReset()
28
+ api.updateOrderSetting.mockReset()
29
+ outlet.id = 'r1'
30
+ })
31
+
32
+ it('refuses to save when the settings never loaded, and sends nothing', async () => {
33
+ const store = useOrderSettings()
34
+ await expect(store.updateKioskSetting(kiosk)).rejects.toThrow()
35
+ expect(api.getOrderSetting).not.toHaveBeenCalled()
36
+ expect(api.updateOrderSetting).not.toHaveBeenCalled()
37
+ })
38
+
39
+ it("refuses to save outlet A's settings into outlet B", async () => {
40
+ api.getOrderSetting.mockResolvedValue({ _id: 'settings-a' })
41
+ const store = useOrderSettings()
42
+ await store.getSetting()
43
+ outlet.id = 'r2'
44
+ await expect(store.updateKioskSetting(kiosk)).rejects.toThrow()
45
+ expect(api.updateOrderSetting).not.toHaveBeenCalled()
46
+ })
47
+
48
+ it('refuses to save after reset (outlet switch)', async () => {
49
+ api.getOrderSetting.mockResolvedValue({ _id: 'settings-a' })
50
+ const store = useOrderSettings()
51
+ await store.getSetting()
52
+ store.reset()
53
+ await expect(store.updateKioskSetting(kiosk)).rejects.toThrow()
54
+ expect(api.updateOrderSetting).not.toHaveBeenCalled()
55
+ })
56
+
57
+ it('ignores a load that finished after the outlet changed', async () => {
58
+ api.getOrderSetting.mockResolvedValue({ _id: 'settings-a' })
59
+ const store = useOrderSettings()
60
+ await store.getSetting(() => false)
61
+ expect(store.state.orderSetting).toBeUndefined()
62
+ })
63
+
64
+ it('saves the loaded outlet and keeps what the backend returned', async () => {
65
+ api.getOrderSetting.mockResolvedValue({ _id: 'settings-a', sequenceSettings: {} })
66
+ api.updateOrderSetting.mockResolvedValue({ _id: 'settings-a-saved' })
67
+ const store = useOrderSettings()
68
+ await store.getSetting()
69
+ await store.updateKioskSetting(kiosk)
70
+ expect(api.updateOrderSetting).toHaveBeenCalledTimes(1)
71
+ expect(api.updateOrderSetting.mock.calls[0][0]).not.toHaveProperty('_id')
72
+ expect(store.state.kiosk).toEqual({ from: 'settings-a-saved' })
73
+ })
74
+
75
+ it('leaves the store unchanged when the backend rejects the save', async () => {
76
+ api.getOrderSetting.mockResolvedValue({ _id: 'settings-a', sequenceSettings: {} })
77
+ api.updateOrderSetting.mockRejectedValue(new Error('500'))
78
+ const store = useOrderSettings()
79
+ await store.getSetting()
80
+ await expect(store.updateKioskSetting(kiosk)).rejects.toThrow('500')
81
+ expect(store.state.kiosk).toEqual({ from: 'settings-a' })
82
+ })
83
+ })
@@ -1,5 +1,6 @@
1
1
  import { defineStore } from 'pinia';
2
2
  import { OrderSettingApi } from '@/api/order-setting';
3
+ import { SvcConfig } from '@/api';
3
4
  import type { MfKioskOrderSetting } from '@/modules/order-setting/kiosk/interface'
4
5
  import { OrderSettingMapper } from './mapper';
5
6
  import { ref } from 'vue';
@@ -9,50 +10,71 @@ import { OrderSettingsDto, OrderSettingUpdateDto } from '@entity';
9
10
  interface State {
10
11
  kiosk?: MfKioskOrderSetting,
11
12
  orderSetting?: OrderSettingsDto,
13
+ /** The outlet `orderSetting` was loaded for. A save is refused for any other outlet. */
14
+ restaurantId?: string,
12
15
  }
13
16
 
14
17
  export const useOrderSettings = defineStore('orderSetting', () => {
15
18
  const state = ref<State>({});
16
19
 
17
- async function getSetting(): Promise<void> {
20
+ /**
21
+ * Load the current outlet's order settings. `isCurrent` lets the caller drop a
22
+ * response that arrives after the merchant already switched outlet.
23
+ */
24
+ async function getSetting(isCurrent: () => boolean = () => true): Promise<void> {
25
+ const restaurantId = SvcConfig.getRestaurantId() ?? undefined;
18
26
  const result = await OrderSettingApi.getOrderSetting();
19
- setStateFromDto(result);
27
+ if (!isCurrent()) return;
28
+ setStateFromDto(result, restaurantId);
20
29
  }
21
30
 
22
- async function updateKioskSetting() {
23
- if (state.value.orderSetting && state.value.kiosk) {
24
- const { _id, ...updateDto } = state.value.orderSetting;
25
- const kioskUpdate = OrderSettingMapper.toOrderKioskSettingsDto(state.value.kiosk);
26
- // The kiosk order-number prefix and switch live in sequenceSettings, which the
27
- // backend replaces whole. Read it again right before saving, so the live counters
28
- // are the stored ones and not the ones this page loaded (KDI-5264).
29
- const stored = await OrderSettingApi.getOrderSetting();
30
- const update: OrderSettingUpdateDto = {
31
- ...updateDto,
32
- kioskSettings: kioskUpdate.kioskSettings,
33
- sequenceSettings: OrderSettingMapper.toKioskSequenceSettings(
34
- state.value.kiosk,
35
- stored.sequenceSettings,
36
- ),
37
- }
38
- const result = await OrderSettingApi.updateOrderSetting(update);
39
- setStateFromDto(result);
31
+ /** Forget the loaded settings, e.g. before loading another outlet. */
32
+ function reset() {
33
+ state.value.orderSetting = undefined;
34
+ state.value.kiosk = undefined;
35
+ state.value.restaurantId = undefined;
36
+ }
37
+
38
+ /**
39
+ * Save the kiosk settings. Throws when this outlet's settings were never loaded:
40
+ * the update sends the whole loaded order setting back, so saving without it
41
+ * (or with another outlet's) must fail loudly, never be skipped or misdirected.
42
+ * The store changes only after the backend accepted the update.
43
+ */
44
+ async function updateKioskSetting(kiosk: MfKioskOrderSetting) {
45
+ const loaded = state.value.orderSetting;
46
+ const restaurantId = SvcConfig.getRestaurantId() ?? undefined;
47
+ if (!loaded || !restaurantId || state.value.restaurantId !== restaurantId) {
48
+ throw new Error('Order settings are not loaded for this outlet');
49
+ }
50
+ const { _id, ...updateDto } = loaded;
51
+ const kioskUpdate = OrderSettingMapper.toOrderKioskSettingsDto(kiosk);
52
+ // The kiosk order-number prefix and switch live in sequenceSettings, which the
53
+ // backend replaces whole. Read it again right before saving, so the live counters
54
+ // are the stored ones and not the ones this page loaded (KDI-5264).
55
+ const stored = await OrderSettingApi.getOrderSetting();
56
+ const update: OrderSettingUpdateDto = {
57
+ ...updateDto,
58
+ kioskSettings: kioskUpdate.kioskSettings,
59
+ sequenceSettings: OrderSettingMapper.toKioskSequenceSettings(
60
+ kiosk,
61
+ stored.sequenceSettings,
62
+ ),
40
63
  }
64
+ const result = await OrderSettingApi.updateOrderSetting(update);
65
+ setStateFromDto(result, restaurantId);
41
66
  }
42
67
 
43
- function setStateFromDto(dto: OrderSettingsDto) {
68
+ function setStateFromDto(dto: OrderSettingsDto, restaurantId: string | undefined) {
44
69
  state.value.orderSetting = dto;
45
70
  state.value.kiosk = OrderSettingMapper.convertOrderSettingDto(dto).kiosk;
46
- }
47
-
48
- function setKioskOrderSetting(kioskOrderSetting: MfKioskOrderSetting) {
49
- state.value.kiosk = kioskOrderSetting;
71
+ state.value.restaurantId = restaurantId;
50
72
  }
51
73
 
52
74
  return {
53
75
  state: state.value,
54
76
  getSetting,
77
+ reset,
55
78
  updateKioskSetting,
56
- setKioskOrderSetting,
57
79
  };
58
- });
80
+ });
@@ -0,0 +1,86 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
2
+ import { createPinia, setActivePinia } from 'pinia'
3
+ import type { KioskPaymentDevice } from '@/modules/payment/paymentDevice'
4
+
5
+ const api = vi.hoisted(() => ({
6
+ listTerminalCheckouts: vi.fn(),
7
+ listKioskPaymentDevices: vi.fn()
8
+ }))
9
+ vi.mock('@/api/payment', () => ({ PaymentApi: api }))
10
+
11
+ import { usePaymentStore } from './index'
12
+
13
+ function device(deviceId: string): KioskPaymentDevice {
14
+ return {
15
+ id: `t-${deviceId}`,
16
+ name: null,
17
+ deviceId,
18
+ status: 'Active',
19
+ softPosGateways: [],
20
+ ecrs: [],
21
+ ecrIntegrations: [],
22
+ qrGateways: []
23
+ }
24
+ }
25
+
26
+ function deferred<T>() {
27
+ let resolve!: (v: T) => void
28
+ let reject!: (e: unknown) => void
29
+ const promise = new Promise<T>((res, rej) => {
30
+ resolve = res
31
+ reject = rej
32
+ })
33
+ return { promise, resolve, reject }
34
+ }
35
+
36
+ describe('payment store, kiosk payment devices', () => {
37
+ beforeEach(() => {
38
+ setActivePinia(createPinia())
39
+ api.listKioskPaymentDevices.mockReset()
40
+ })
41
+
42
+ it('finds the payment device by <restaurantId>-<machineId>', async () => {
43
+ api.listKioskPaymentDevices.mockResolvedValue([device('r1-m1'), device('r1-m2')])
44
+ const store = usePaymentStore()
45
+ await store.loadPaymentDevices()
46
+ expect(store.paymentDeviceFor('r1', 'm2')?.id).toBe('t-r1-m2')
47
+ expect(store.paymentDeviceFor('r1', 'm3')).toBeNull()
48
+ expect(store.paymentDeviceFor('r2', 'm1')).toBeNull()
49
+ expect(store.state.paymentDevicesLoading).toBe(false)
50
+ })
51
+
52
+ it('keeps the latest outlet when an older request answers last', async () => {
53
+ const first = deferred<KioskPaymentDevice[]>()
54
+ const second = deferred<KioskPaymentDevice[]>()
55
+ api.listKioskPaymentDevices.mockReturnValueOnce(first.promise).mockReturnValueOnce(second.promise)
56
+ const store = usePaymentStore()
57
+ const a = store.loadPaymentDevices()
58
+ const b = store.loadPaymentDevices()
59
+ second.resolve([device('r2-m1')])
60
+ await b
61
+ first.resolve([device('r1-m1')])
62
+ await a
63
+ expect(store.state.paymentDevices?.map((d) => d.deviceId)).toEqual(['r2-m1'])
64
+ expect(store.state.paymentDevicesLoading).toBe(false)
65
+ })
66
+
67
+ it('shows an error and no list when the load fails', async () => {
68
+ api.listKioskPaymentDevices.mockRejectedValue(new Error('403'))
69
+ const store = usePaymentStore()
70
+ await store.loadPaymentDevices()
71
+ expect(store.state.paymentDevices).toBeNull()
72
+ expect(store.state.paymentDevicesLoadError).toBe('error')
73
+ })
74
+
75
+ it('clear drops the list and ignores a request still in flight', async () => {
76
+ const pending = deferred<KioskPaymentDevice[]>()
77
+ api.listKioskPaymentDevices.mockReturnValueOnce(pending.promise)
78
+ const store = usePaymentStore()
79
+ const load = store.loadPaymentDevices()
80
+ store.clearPaymentDevices()
81
+ pending.resolve([device('r1-m1')])
82
+ await load
83
+ expect(store.state.paymentDevices).toBeNull()
84
+ expect(store.state.paymentDevicesLoading).toBe(false)
85
+ })
86
+ })