@open-mercato/core 0.4.9-develop-97d4cca067 → 0.4.9-develop.1013.aa3a9dea92

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 (60) hide show
  1. package/dist/modules/sales/backend/sales/documents/[id]/page.js +23 -12
  2. package/dist/modules/sales/backend/sales/documents/[id]/page.js.map +2 -2
  3. package/dist/modules/shipping_carriers/api/cancel/route.js +5 -1
  4. package/dist/modules/shipping_carriers/api/cancel/route.js.map +2 -2
  5. package/dist/modules/shipping_carriers/api/points/route.js +59 -0
  6. package/dist/modules/shipping_carriers/api/points/route.js.map +7 -0
  7. package/dist/modules/shipping_carriers/api/providers/route.js +38 -0
  8. package/dist/modules/shipping_carriers/api/providers/route.js.map +7 -0
  9. package/dist/modules/shipping_carriers/backend/shipping-carriers/create/page.js +90 -0
  10. package/dist/modules/shipping_carriers/backend/shipping-carriers/create/page.js.map +7 -0
  11. package/dist/modules/shipping_carriers/backend/shipping-carriers/create/page.meta.js +8 -0
  12. package/dist/modules/shipping_carriers/backend/shipping-carriers/create/page.meta.js.map +7 -0
  13. package/dist/modules/shipping_carriers/data/validators.js +17 -2
  14. package/dist/modules/shipping_carriers/data/validators.js.map +2 -2
  15. package/dist/modules/shipping_carriers/lib/shipment-wizard/components/AddressFields.js +76 -0
  16. package/dist/modules/shipping_carriers/lib/shipment-wizard/components/AddressFields.js.map +7 -0
  17. package/dist/modules/shipping_carriers/lib/shipment-wizard/components/ConfigureStep.js +243 -0
  18. package/dist/modules/shipping_carriers/lib/shipment-wizard/components/ConfigureStep.js.map +7 -0
  19. package/dist/modules/shipping_carriers/lib/shipment-wizard/components/ConfirmStep.js +134 -0
  20. package/dist/modules/shipping_carriers/lib/shipment-wizard/components/ConfirmStep.js.map +7 -0
  21. package/dist/modules/shipping_carriers/lib/shipment-wizard/components/PackageEditor.js +70 -0
  22. package/dist/modules/shipping_carriers/lib/shipment-wizard/components/PackageEditor.js.map +7 -0
  23. package/dist/modules/shipping_carriers/lib/shipment-wizard/components/ProviderStep.js +32 -0
  24. package/dist/modules/shipping_carriers/lib/shipment-wizard/components/ProviderStep.js.map +7 -0
  25. package/dist/modules/shipping_carriers/lib/shipment-wizard/components/WizardNav.js +37 -0
  26. package/dist/modules/shipping_carriers/lib/shipment-wizard/components/WizardNav.js.map +7 -0
  27. package/dist/modules/shipping_carriers/lib/shipment-wizard/hooks/shipmentApi.js +92 -0
  28. package/dist/modules/shipping_carriers/lib/shipment-wizard/hooks/shipmentApi.js.map +7 -0
  29. package/dist/modules/shipping_carriers/lib/shipment-wizard/hooks/useShipmentWizard.js +212 -0
  30. package/dist/modules/shipping_carriers/lib/shipment-wizard/hooks/useShipmentWizard.js.map +7 -0
  31. package/dist/modules/shipping_carriers/lib/shipment-wizard/types.js +1 -0
  32. package/dist/modules/shipping_carriers/lib/shipment-wizard/types.js.map +7 -0
  33. package/dist/modules/shipping_carriers/lib/shipping-service.js +36 -3
  34. package/dist/modules/shipping_carriers/lib/shipping-service.js.map +2 -2
  35. package/dist/modules/shipping_carriers/lib/status-sync.js +7 -0
  36. package/dist/modules/shipping_carriers/lib/status-sync.js.map +2 -2
  37. package/package.json +7 -4
  38. package/src/modules/sales/backend/sales/documents/[id]/page.tsx +17 -9
  39. package/src/modules/shipping_carriers/api/cancel/route.ts +5 -1
  40. package/src/modules/shipping_carriers/api/points/route.ts +57 -0
  41. package/src/modules/shipping_carriers/api/providers/route.ts +35 -0
  42. package/src/modules/shipping_carriers/backend/shipping-carriers/create/page.meta.ts +4 -0
  43. package/src/modules/shipping_carriers/backend/shipping-carriers/create/page.tsx +93 -0
  44. package/src/modules/shipping_carriers/data/validators.ts +15 -0
  45. package/src/modules/shipping_carriers/i18n/de.json +66 -0
  46. package/src/modules/shipping_carriers/i18n/en.json +66 -0
  47. package/src/modules/shipping_carriers/i18n/es.json +66 -0
  48. package/src/modules/shipping_carriers/i18n/pl.json +66 -0
  49. package/src/modules/shipping_carriers/lib/adapter.ts +20 -0
  50. package/src/modules/shipping_carriers/lib/shipment-wizard/components/AddressFields.tsx +72 -0
  51. package/src/modules/shipping_carriers/lib/shipment-wizard/components/ConfigureStep.tsx +343 -0
  52. package/src/modules/shipping_carriers/lib/shipment-wizard/components/ConfirmStep.tsx +213 -0
  53. package/src/modules/shipping_carriers/lib/shipment-wizard/components/PackageEditor.tsx +82 -0
  54. package/src/modules/shipping_carriers/lib/shipment-wizard/components/ProviderStep.tsx +54 -0
  55. package/src/modules/shipping_carriers/lib/shipment-wizard/components/WizardNav.tsx +46 -0
  56. package/src/modules/shipping_carriers/lib/shipment-wizard/hooks/shipmentApi.ts +153 -0
  57. package/src/modules/shipping_carriers/lib/shipment-wizard/hooks/useShipmentWizard.ts +312 -0
  58. package/src/modules/shipping_carriers/lib/shipment-wizard/types.ts +76 -0
  59. package/src/modules/shipping_carriers/lib/shipping-service.ts +53 -3
  60. package/src/modules/shipping_carriers/lib/status-sync.ts +7 -0
@@ -0,0 +1,76 @@
1
+ export type Provider = {
2
+ providerKey: string
3
+ }
4
+
5
+ export type Address = {
6
+ countryCode: string
7
+ postalCode: string
8
+ city: string
9
+ line1: string
10
+ line2?: string
11
+ }
12
+
13
+ export type PackageDimension = {
14
+ weightKg: number
15
+ lengthCm: number
16
+ widthCm: number
17
+ heightCm: number
18
+ }
19
+
20
+ export type ShippingRate = {
21
+ serviceCode: string
22
+ serviceName: string
23
+ amount: number
24
+ currencyCode: string
25
+ estimatedDays?: number
26
+ }
27
+
28
+ export type DocumentAddress = {
29
+ id: string
30
+ purpose: string | null
31
+ address_line1: string
32
+ address_line2?: string | null
33
+ city?: string | null
34
+ postal_code?: string | null
35
+ country?: string | null
36
+ }
37
+
38
+ export type LabelFormat = 'pdf' | 'zpl' | 'png'
39
+
40
+ export type WizardStep = 'provider' | 'configure' | 'confirm'
41
+
42
+ export type AddressFieldsProps = {
43
+ prefix: string
44
+ address: Address
45
+ onChange: (address: Address) => void
46
+ disabled?: boolean
47
+ }
48
+
49
+ export type PackageEditorProps = {
50
+ packages: PackageDimension[]
51
+ onChange: (packages: PackageDimension[]) => void
52
+ disabled?: boolean
53
+ }
54
+
55
+ export type ContactInfo = {
56
+ phone: string
57
+ email: string
58
+ }
59
+
60
+ export type ContactFieldsProps = {
61
+ prefix: string
62
+ contact: ContactInfo
63
+ onChange: (contact: ContactInfo) => void
64
+ disabled?: boolean
65
+ }
66
+
67
+ export type DropOffPoint = {
68
+ id: string
69
+ name: string
70
+ type: string
71
+ city: string
72
+ postalCode: string
73
+ street: string
74
+ latitude?: number
75
+ longitude?: number
76
+ }
@@ -4,6 +4,8 @@ import type { CredentialsService } from '../../integrations/lib/credentials-serv
4
4
  import { CarrierShipment } from '../data/entities'
5
5
  import { emitShippingEvent } from '../events'
6
6
  import { getShippingAdapter } from './adapter-registry'
7
+ import type { UnifiedShipmentStatus } from './adapter'
8
+ import { isValidShippingTransition, ShipmentCancelNotAllowedError } from './status-sync'
7
9
 
8
10
  export function createShippingCarrierService(deps: {
9
11
  em: EntityManager
@@ -46,6 +48,8 @@ export function createShippingCarrierService(deps: {
46
48
  origin: { countryCode: string; postalCode: string; city: string; line1: string; line2?: string }
47
49
  destination: { countryCode: string; postalCode: string; city: string; line1: string; line2?: string }
48
50
  packages: Array<{ weightKg: number; lengthCm: number; widthCm: number; heightCm: number }>
51
+ receiverPhone?: string
52
+ receiverEmail?: string
49
53
  organizationId: string
50
54
  tenantId: string
51
55
  }) {
@@ -53,11 +57,16 @@ export function createShippingCarrierService(deps: {
53
57
  organizationId: input.organizationId,
54
58
  tenantId: input.tenantId,
55
59
  })
60
+ const mergedCredentials = {
61
+ ...credentials,
62
+ ...(input.receiverPhone !== undefined ? { receiverPhone: input.receiverPhone } : {}),
63
+ ...(input.receiverEmail !== undefined ? { receiverEmail: input.receiverEmail } : {}),
64
+ }
56
65
  return adapter.calculateRates({
57
66
  origin: input.origin,
58
67
  destination: input.destination,
59
68
  packages: input.packages,
60
- credentials,
69
+ credentials: mergedCredentials,
61
70
  })
62
71
  },
63
72
 
@@ -69,6 +78,12 @@ export function createShippingCarrierService(deps: {
69
78
  packages: Array<{ weightKg: number; lengthCm: number; widthCm: number; heightCm: number }>
70
79
  serviceCode: string
71
80
  labelFormat?: 'pdf' | 'zpl' | 'png'
81
+ senderPhone?: string
82
+ senderEmail?: string
83
+ receiverPhone?: string
84
+ receiverEmail?: string
85
+ targetPoint?: string
86
+ c2cSendingMethod?: string
72
87
  organizationId: string
73
88
  tenantId: string
74
89
  }) {
@@ -76,13 +91,22 @@ export function createShippingCarrierService(deps: {
76
91
  organizationId: input.organizationId,
77
92
  tenantId: input.tenantId,
78
93
  })
94
+ const mergedCredentials = {
95
+ ...credentials,
96
+ ...(input.senderPhone !== undefined ? { senderPhone: input.senderPhone } : {}),
97
+ ...(input.senderEmail !== undefined ? { senderEmail: input.senderEmail } : {}),
98
+ ...(input.receiverPhone !== undefined ? { receiverPhone: input.receiverPhone } : {}),
99
+ ...(input.receiverEmail !== undefined ? { receiverEmail: input.receiverEmail } : {}),
100
+ ...(input.targetPoint !== undefined ? { targetPoint: input.targetPoint } : {}),
101
+ ...(input.c2cSendingMethod !== undefined ? { c2cSendingMethod: input.c2cSendingMethod } : {}),
102
+ }
79
103
  const created = await adapter.createShipment({
80
104
  orderId: input.orderId,
81
105
  origin: input.origin,
82
106
  destination: input.destination,
83
107
  packages: input.packages,
84
108
  serviceCode: input.serviceCode,
85
- credentials,
109
+ credentials: mergedCredentials,
86
110
  labelFormat: input.labelFormat,
87
111
  })
88
112
  const shipment = em.create(CarrierShipment, {
@@ -138,7 +162,7 @@ export function createShippingCarrierService(deps: {
138
162
  : null
139
163
  const tracking = await adapter.getTracking({
140
164
  shipmentId: shipment?.carrierShipmentId ?? input.shipmentId,
141
- trackingNumber: input.trackingNumber,
165
+ trackingNumber: input.trackingNumber ?? shipment?.trackingNumber,
142
166
  credentials,
143
167
  })
144
168
  if (shipment) {
@@ -159,6 +183,9 @@ export function createShippingCarrierService(deps: {
159
183
  }) {
160
184
  const scope = { organizationId: input.organizationId, tenantId: input.tenantId }
161
185
  const shipment = await findShipmentOrThrow(input.shipmentId, scope)
186
+ if (!isValidShippingTransition(shipment.unifiedStatus as UnifiedShipmentStatus, 'cancelled')) {
187
+ throw new ShipmentCancelNotAllowedError(shipment.unifiedStatus)
188
+ }
162
189
  const { adapter, credentials } = await resolveAdapter(input.providerKey, {
163
190
  organizationId: input.organizationId,
164
191
  tenantId: input.tenantId,
@@ -198,6 +225,29 @@ export function createShippingCarrierService(deps: {
198
225
  scope,
199
226
  )
200
227
  },
228
+
229
+ async searchDropOffPoints(input: {
230
+ providerKey: string
231
+ query?: string
232
+ type?: string
233
+ postCode?: string
234
+ organizationId: string
235
+ tenantId: string
236
+ }) {
237
+ const { adapter, credentials } = await resolveAdapter(input.providerKey, {
238
+ organizationId: input.organizationId,
239
+ tenantId: input.tenantId,
240
+ })
241
+ if (!adapter.searchDropOffPoints) {
242
+ throw new Error(`Provider ${input.providerKey} does not support drop-off point search`)
243
+ }
244
+ return adapter.searchDropOffPoints({
245
+ query: input.query,
246
+ type: input.type,
247
+ postCode: input.postCode,
248
+ credentials,
249
+ })
250
+ },
201
251
  }
202
252
  }
203
253
 
@@ -2,6 +2,13 @@ import type { UnifiedShipmentStatus } from './adapter'
2
2
  import type { CarrierShipment } from '../data/entities'
3
3
  import type { ShippingEventId } from '../events'
4
4
 
5
+ export class ShipmentCancelNotAllowedError extends Error {
6
+ constructor(status: string) {
7
+ super(`Shipment cannot be cancelled in its current status: ${status}`)
8
+ this.name = 'ShipmentCancelNotAllowedError'
9
+ }
10
+ }
11
+
5
12
  const VALID_SHIPPING_TRANSITIONS: Record<string, UnifiedShipmentStatus[]> = {
6
13
  label_created: ['picked_up', 'in_transit', 'cancelled'],
7
14
  picked_up: ['in_transit', 'cancelled'],