@open-mercato/core 0.7.1-develop.7154.1.981330c924 → 0.7.1-develop.7171.1.9b31dbba45

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 (155) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/AGENTS.md +2 -2
  3. package/dist/modules/auth/commands/users.js +14 -1
  4. package/dist/modules/auth/commands/users.js.map +2 -2
  5. package/dist/modules/auth/data/entities.js +2 -2
  6. package/dist/modules/auth/data/entities.js.map +2 -2
  7. package/dist/modules/auth/lib/backendChrome.js +26 -3
  8. package/dist/modules/auth/lib/backendChrome.js.map +2 -2
  9. package/dist/modules/auth/lib/profile-sections.js +1 -1
  10. package/dist/modules/auth/lib/profile-sections.js.map +2 -2
  11. package/dist/modules/auth/migrations/Migration20260907120000_auth.js +19 -0
  12. package/dist/modules/auth/migrations/Migration20260907120000_auth.js.map +7 -0
  13. package/dist/modules/communication_channels/backend/profile/communication-channels/page.meta.js +2 -2
  14. package/dist/modules/communication_channels/backend/profile/communication-channels/page.meta.js.map +1 -1
  15. package/dist/modules/customer_accounts/api/admin/demo-accounts.js +118 -0
  16. package/dist/modules/customer_accounts/api/admin/demo-accounts.js.map +7 -0
  17. package/dist/modules/customer_accounts/api/invitations/accept.js +23 -6
  18. package/dist/modules/customer_accounts/api/invitations/accept.js.map +2 -2
  19. package/dist/modules/customer_accounts/backend/customer_accounts/settings/CustomerAccountsSettingsPageClient.js +10 -13
  20. package/dist/modules/customer_accounts/backend/customer_accounts/settings/CustomerAccountsSettingsPageClient.js.map +2 -2
  21. package/dist/modules/customer_accounts/backend/customer_accounts/useDemoPortalAccounts.js +28 -0
  22. package/dist/modules/customer_accounts/backend/customer_accounts/useDemoPortalAccounts.js.map +7 -0
  23. package/dist/modules/customer_accounts/backend/customer_accounts/users/PortalUsersPageClient.js +6 -1
  24. package/dist/modules/customer_accounts/backend/customer_accounts/users/PortalUsersPageClient.js.map +2 -2
  25. package/dist/modules/customer_accounts/data/entities.js +4 -1
  26. package/dist/modules/customer_accounts/data/entities.js.map +2 -2
  27. package/dist/modules/customer_accounts/lib/exampleAccounts.js +9 -0
  28. package/dist/modules/customer_accounts/lib/exampleAccounts.js.map +7 -0
  29. package/dist/modules/customer_accounts/migrations/Migration20260827160000_customer_accounts.js +16 -0
  30. package/dist/modules/customer_accounts/migrations/Migration20260827160000_customer_accounts.js.map +7 -0
  31. package/dist/modules/customer_accounts/services/customerInvitationService.js +53 -6
  32. package/dist/modules/customer_accounts/services/customerInvitationService.js.map +2 -2
  33. package/dist/modules/customer_accounts/setup.js +2 -6
  34. package/dist/modules/customer_accounts/setup.js.map +2 -2
  35. package/dist/modules/customer_accounts/widgets/injection/account-status/widget.client.js +55 -40
  36. package/dist/modules/customer_accounts/widgets/injection/account-status/widget.client.js.map +2 -2
  37. package/dist/modules/customers/commands/people.js +16 -1
  38. package/dist/modules/customers/commands/people.js.map +2 -2
  39. package/dist/modules/data_sync/backend/data-sync/runs/[id]/page.js +18 -36
  40. package/dist/modules/data_sync/backend/data-sync/runs/[id]/page.js.map +2 -2
  41. package/dist/modules/entities/api/records.js +18 -15
  42. package/dist/modules/entities/api/records.js.map +3 -3
  43. package/dist/modules/entities/lib/scoped-field-defs.js +52 -0
  44. package/dist/modules/entities/lib/scoped-field-defs.js.map +7 -0
  45. package/dist/modules/entities/lib/validation.js +4 -35
  46. package/dist/modules/entities/lib/validation.js.map +2 -2
  47. package/dist/modules/integrations/backend/integrations/[id]/page.js +32 -54
  48. package/dist/modules/integrations/backend/integrations/[id]/page.js.map +2 -2
  49. package/dist/modules/integrations/backend/integrations/bundle/[id]/page.js +12 -29
  50. package/dist/modules/integrations/backend/integrations/bundle/[id]/page.js.map +2 -2
  51. package/dist/modules/notifications/backend/profile/notification-preferences/page.meta.js +2 -2
  52. package/dist/modules/notifications/backend/profile/notification-preferences/page.meta.js.map +1 -1
  53. package/dist/modules/progress/lib/progressServiceImpl.js +14 -3
  54. package/dist/modules/progress/lib/progressServiceImpl.js.map +2 -2
  55. package/dist/modules/sales/backend/sales/documents/[id]/page.js +9 -9
  56. package/dist/modules/sales/backend/sales/documents/[id]/page.js.map +2 -2
  57. package/dist/modules/sales/components/documents/LineItemDialog.js +50 -10
  58. package/dist/modules/sales/components/documents/LineItemDialog.js.map +2 -2
  59. package/dist/modules/sales/components/documents/PaymentsSection.js +8 -3
  60. package/dist/modules/sales/components/documents/PaymentsSection.js.map +2 -2
  61. package/dist/modules/sales/components/documents/ReturnEditDialog.js +2 -7
  62. package/dist/modules/sales/components/documents/ReturnEditDialog.js.map +2 -2
  63. package/dist/modules/sales/components/documents/ReturnsSection.js +2 -7
  64. package/dist/modules/sales/components/documents/ReturnsSection.js.map +2 -2
  65. package/dist/modules/sales/components/documents/ShipmentsSection.js +3 -8
  66. package/dist/modules/sales/components/documents/ShipmentsSection.js.map +2 -2
  67. package/dist/modules/wms/commands/sales-order-assignment.js +12 -0
  68. package/dist/modules/wms/commands/sales-order-assignment.js.map +2 -2
  69. package/dist/modules/wms/data/enrichers.js +25 -0
  70. package/dist/modules/wms/data/enrichers.js.map +2 -2
  71. package/dist/modules/wms/lib/enricherCacheTags.js +9 -0
  72. package/dist/modules/wms/lib/enricherCacheTags.js.map +7 -0
  73. package/dist/modules/wms/lib/invalidateInventoryEnricherCache.js +37 -0
  74. package/dist/modules/wms/lib/invalidateInventoryEnricherCache.js.map +7 -0
  75. package/dist/modules/wms/lib/inventoryEnricherCacheSubscriber.js +14 -0
  76. package/dist/modules/wms/lib/inventoryEnricherCacheSubscriber.js.map +7 -0
  77. package/dist/modules/wms/subscribers/invalidate-enricher-cache-balance.js +12 -0
  78. package/dist/modules/wms/subscribers/invalidate-enricher-cache-balance.js.map +7 -0
  79. package/dist/modules/wms/subscribers/invalidate-enricher-cache-inventory.js +12 -0
  80. package/dist/modules/wms/subscribers/invalidate-enricher-cache-inventory.js.map +7 -0
  81. package/dist/modules/wms/subscribers/invalidate-enricher-cache-movement.js +12 -0
  82. package/dist/modules/wms/subscribers/invalidate-enricher-cache-movement.js.map +7 -0
  83. package/dist/modules/wms/subscribers/invalidate-enricher-cache-profile.js +12 -0
  84. package/dist/modules/wms/subscribers/invalidate-enricher-cache-profile.js.map +7 -0
  85. package/dist/modules/wms/subscribers/invalidate-enricher-cache-reservation.js +12 -0
  86. package/dist/modules/wms/subscribers/invalidate-enricher-cache-reservation.js.map +7 -0
  87. package/dist/modules/wms/subscribers/invalidate-enricher-cache-sales-line.js +12 -0
  88. package/dist/modules/wms/subscribers/invalidate-enricher-cache-sales-line.js.map +7 -0
  89. package/dist/modules/wms/subscribers/invalidate-enricher-cache-sales-order.js +12 -0
  90. package/dist/modules/wms/subscribers/invalidate-enricher-cache-sales-order.js.map +7 -0
  91. package/dist/modules/wms/subscribers/invalidate-enricher-cache-variant.js +12 -0
  92. package/dist/modules/wms/subscribers/invalidate-enricher-cache-variant.js.map +7 -0
  93. package/dist/modules/wms/subscribers/invalidate-enricher-cache-warehouse.js +12 -0
  94. package/dist/modules/wms/subscribers/invalidate-enricher-cache-warehouse.js.map +7 -0
  95. package/package.json +7 -7
  96. package/src/modules/auth/commands/users.ts +14 -1
  97. package/src/modules/auth/data/entities.ts +2 -2
  98. package/src/modules/auth/lib/backendChrome.tsx +46 -2
  99. package/src/modules/auth/lib/profile-sections.tsx +14 -3
  100. package/src/modules/auth/migrations/.snapshot-open-mercato.json +4 -2
  101. package/src/modules/auth/migrations/Migration20260907120000_auth.ts +21 -0
  102. package/src/modules/communication_channels/backend/profile/communication-channels/page.meta.ts +2 -2
  103. package/src/modules/customer_accounts/AGENTS.md +3 -1
  104. package/src/modules/customer_accounts/api/admin/demo-accounts.ts +149 -0
  105. package/src/modules/customer_accounts/api/invitations/accept.ts +23 -6
  106. package/src/modules/customer_accounts/backend/customer_accounts/settings/CustomerAccountsSettingsPageClient.tsx +43 -41
  107. package/src/modules/customer_accounts/backend/customer_accounts/useDemoPortalAccounts.ts +42 -0
  108. package/src/modules/customer_accounts/backend/customer_accounts/users/PortalUsersPageClient.tsx +10 -3
  109. package/src/modules/customer_accounts/data/entities.ts +5 -1
  110. package/src/modules/customer_accounts/i18n/de.json +4 -2
  111. package/src/modules/customer_accounts/i18n/en.json +4 -2
  112. package/src/modules/customer_accounts/i18n/es.json +4 -2
  113. package/src/modules/customer_accounts/i18n/ko.json +4 -2
  114. package/src/modules/customer_accounts/i18n/pl.json +4 -2
  115. package/src/modules/customer_accounts/lib/exampleAccounts.ts +18 -0
  116. package/src/modules/customer_accounts/migrations/.snapshot-open-mercato.json +5 -7
  117. package/src/modules/customer_accounts/migrations/Migration20260827160000_customer_accounts.ts +23 -0
  118. package/src/modules/customer_accounts/services/customerInvitationService.ts +89 -5
  119. package/src/modules/customer_accounts/setup.ts +2 -6
  120. package/src/modules/customer_accounts/widgets/injection/account-status/widget.client.tsx +74 -41
  121. package/src/modules/customers/commands/people.ts +15 -0
  122. package/src/modules/data_sync/backend/data-sync/runs/[id]/page.tsx +19 -44
  123. package/src/modules/entities/api/records.ts +24 -15
  124. package/src/modules/entities/lib/scoped-field-defs.ts +76 -0
  125. package/src/modules/entities/lib/validation.ts +5 -45
  126. package/src/modules/integrations/backend/integrations/[id]/page.tsx +33 -62
  127. package/src/modules/integrations/backend/integrations/bundle/[id]/page.tsx +13 -37
  128. package/src/modules/notifications/backend/profile/notification-preferences/page.meta.ts +2 -2
  129. package/src/modules/progress/AGENTS.md +1 -1
  130. package/src/modules/progress/lib/progressServiceImpl.ts +26 -3
  131. package/src/modules/sales/backend/sales/documents/[id]/page.tsx +19 -25
  132. package/src/modules/sales/components/documents/LineItemDialog.tsx +53 -9
  133. package/src/modules/sales/components/documents/PaymentsSection.tsx +8 -8
  134. package/src/modules/sales/components/documents/ReturnEditDialog.tsx +2 -8
  135. package/src/modules/sales/components/documents/ReturnsSection.tsx +8 -7
  136. package/src/modules/sales/components/documents/ShipmentsSection.tsx +9 -8
  137. package/src/modules/sales/i18n/de.json +2 -0
  138. package/src/modules/sales/i18n/en.json +2 -0
  139. package/src/modules/sales/i18n/es.json +2 -0
  140. package/src/modules/sales/i18n/ko.json +2 -0
  141. package/src/modules/sales/i18n/pl.json +2 -0
  142. package/src/modules/wms/commands/sales-order-assignment.ts +20 -0
  143. package/src/modules/wms/data/enrichers.ts +25 -0
  144. package/src/modules/wms/lib/enricherCacheTags.ts +29 -0
  145. package/src/modules/wms/lib/invalidateInventoryEnricherCache.ts +71 -0
  146. package/src/modules/wms/lib/inventoryEnricherCacheSubscriber.ts +30 -0
  147. package/src/modules/wms/subscribers/invalidate-enricher-cache-balance.ts +9 -0
  148. package/src/modules/wms/subscribers/invalidate-enricher-cache-inventory.ts +9 -0
  149. package/src/modules/wms/subscribers/invalidate-enricher-cache-movement.ts +9 -0
  150. package/src/modules/wms/subscribers/invalidate-enricher-cache-profile.ts +9 -0
  151. package/src/modules/wms/subscribers/invalidate-enricher-cache-reservation.ts +9 -0
  152. package/src/modules/wms/subscribers/invalidate-enricher-cache-sales-line.ts +14 -0
  153. package/src/modules/wms/subscribers/invalidate-enricher-cache-sales-order.ts +18 -0
  154. package/src/modules/wms/subscribers/invalidate-enricher-cache-variant.ts +9 -0
  155. package/src/modules/wms/subscribers/invalidate-enricher-cache-warehouse.ts +9 -0
@@ -0,0 +1,71 @@
1
+ // Drop the cached WMS inventory enrichment for a tenant after a write that
2
+ // changed the data it was derived from.
3
+ //
4
+ // The three WMS inventory enrichers cache their cross-module reads read-through
5
+ // with a short TTL (see `enricherCacheTags.ts`). Every write surface that moves
6
+ // balances, reservations, movements, profiles, warehouses or the sales-order
7
+ // warehouse assignment drops the matching tags here, so a user sees the new
8
+ // stock on the next request rather than after the TTL.
9
+ //
10
+ // The cache service prefixes tags with the *current* cache tenant, which is an
11
+ // AsyncLocalStorage value set on the request path. A subscriber or command side
12
+ // effect running outside that scope would otherwise write its invalidation
13
+ // against the `tenant:global:` prefix and silently miss every entry the request
14
+ // path stored. `runWithCacheTenant` re-enters the right scope, mirroring
15
+ // `directory/subscribers/invalidateOrgScopeCache.ts`.
16
+
17
+ import { runWithCacheTenant } from '@open-mercato/cache'
18
+ import { createLogger } from '@open-mercato/shared/lib/logger'
19
+ import {
20
+ WMS_INVENTORY_CACHE_TAG,
21
+ WMS_WAREHOUSE_CACHE_TAG,
22
+ } from './enricherCacheTags'
23
+
24
+ const logger = createLogger('wms').child({ component: 'enricher-cache' })
25
+
26
+ type CacheService = {
27
+ deleteByTags(tags: string[]): Promise<number>
28
+ }
29
+
30
+ export type EnricherCacheScope = 'inventory' | 'warehouse' | 'all'
31
+
32
+ type Resolver = { resolve: <T = unknown>(name: string) => T }
33
+
34
+ function resolveCache(container: Resolver | null | undefined): CacheService | null {
35
+ if (!container?.resolve) return null
36
+ for (const name of ['cache', 'cacheService']) {
37
+ try {
38
+ const candidate = container.resolve<CacheService>(name)
39
+ if (candidate && typeof candidate.deleteByTags === 'function') return candidate
40
+ } catch {
41
+ // try the next registration name
42
+ }
43
+ }
44
+ return null
45
+ }
46
+
47
+ function tagsForScope(scope: EnricherCacheScope): string[] {
48
+ if (scope === 'inventory') return [WMS_INVENTORY_CACHE_TAG]
49
+ if (scope === 'warehouse') return [WMS_WAREHOUSE_CACHE_TAG]
50
+ return [WMS_INVENTORY_CACHE_TAG, WMS_WAREHOUSE_CACHE_TAG]
51
+ }
52
+
53
+ /**
54
+ * Best-effort tag invalidation. A failure is logged and swallowed: an
55
+ * invalidation that throws must never fail the write that triggered it, and the
56
+ * enricher TTL bounds how long a missed drop can serve stale data.
57
+ */
58
+ export async function invalidateWmsInventoryEnricherCache(
59
+ container: Resolver | null | undefined,
60
+ tenantId: string | null | undefined,
61
+ scope: EnricherCacheScope = 'all',
62
+ ): Promise<void> {
63
+ if (!tenantId) return
64
+ const cache = resolveCache(container)
65
+ if (!cache) return
66
+ try {
67
+ await runWithCacheTenant(tenantId, () => cache.deleteByTags(tagsForScope(scope)))
68
+ } catch (err) {
69
+ logger.warn('Failed to invalidate WMS inventory enricher cache', { tenantId, scope, err })
70
+ }
71
+ }
@@ -0,0 +1,30 @@
1
+ // Shared handler behind the WMS inventory enricher-cache invalidation
2
+ // subscribers. Each subscriber file binds it to one event pattern, because
3
+ // `metadata.event` takes a single pattern and the matcher is single-segment —
4
+ // `wms.*` does NOT match `wms.inventory_balance.created`, so every event family
5
+ // the enrichers read from is registered explicitly.
6
+ //
7
+ // It lives here rather than under `subscribers/` because the module generator
8
+ // scans that directory recursively and treats every file it finds as a
9
+ // subscriber.
10
+
11
+ import {
12
+ invalidateWmsInventoryEnricherCache,
13
+ type EnricherCacheScope,
14
+ } from './invalidateInventoryEnricherCache'
15
+
16
+ type SubscriberContext = {
17
+ resolve: <T = unknown>(name: string) => T
18
+ tenantId?: string | null
19
+ }
20
+
21
+ export function createInventoryEnricherCacheHandler(scope: EnricherCacheScope) {
22
+ return async function handle(payload: unknown, ctx: SubscriberContext): Promise<void> {
23
+ const data = (payload ?? {}) as Record<string, unknown>
24
+ const tenantId =
25
+ typeof data.tenantId === 'string' && data.tenantId.length > 0
26
+ ? data.tenantId
27
+ : ctx.tenantId ?? null
28
+ await invalidateWmsInventoryEnricherCache(ctx, tenantId, scope)
29
+ }
30
+ }
@@ -0,0 +1,9 @@
1
+ import { createInventoryEnricherCacheHandler } from '../lib/inventoryEnricherCacheSubscriber'
2
+
3
+ export const metadata = {
4
+ event: 'wms.inventory_balance.*',
5
+ persistent: false,
6
+ id: 'wms:invalidate-enricher-cache-balance',
7
+ }
8
+
9
+ export default createInventoryEnricherCacheHandler('inventory')
@@ -0,0 +1,9 @@
1
+ import { createInventoryEnricherCacheHandler } from '../lib/inventoryEnricherCacheSubscriber'
2
+
3
+ export const metadata = {
4
+ event: 'wms.inventory.*',
5
+ persistent: false,
6
+ id: 'wms:invalidate-enricher-cache-inventory',
7
+ }
8
+
9
+ export default createInventoryEnricherCacheHandler('inventory')
@@ -0,0 +1,9 @@
1
+ import { createInventoryEnricherCacheHandler } from '../lib/inventoryEnricherCacheSubscriber'
2
+
3
+ export const metadata = {
4
+ event: 'wms.inventory_movement.*',
5
+ persistent: false,
6
+ id: 'wms:invalidate-enricher-cache-movement',
7
+ }
8
+
9
+ export default createInventoryEnricherCacheHandler('inventory')
@@ -0,0 +1,9 @@
1
+ import { createInventoryEnricherCacheHandler } from '../lib/inventoryEnricherCacheSubscriber'
2
+
3
+ export const metadata = {
4
+ event: 'wms.inventory_profile.*',
5
+ persistent: false,
6
+ id: 'wms:invalidate-enricher-cache-profile',
7
+ }
8
+
9
+ export default createInventoryEnricherCacheHandler('inventory')
@@ -0,0 +1,9 @@
1
+ import { createInventoryEnricherCacheHandler } from '../lib/inventoryEnricherCacheSubscriber'
2
+
3
+ export const metadata = {
4
+ event: 'wms.inventory_reservation.*',
5
+ persistent: false,
6
+ id: 'wms:invalidate-enricher-cache-reservation',
7
+ }
8
+
9
+ export default createInventoryEnricherCacheHandler('inventory')
@@ -0,0 +1,14 @@
1
+ import { createInventoryEnricherCacheHandler } from '../lib/inventoryEnricherCacheSubscriber'
2
+
3
+ // The sales module declares `sales.line.*` in its event registry and documents
4
+ // it publicly, but no write surface emits it today — line writes ride the order
5
+ // commands' `sales.order.*`. Registering the pattern anyway costs one ephemeral
6
+ // subscription and means that wiring those events later cannot silently
7
+ // reintroduce the staleness `invalidate-enricher-cache-sales-order.ts` closes.
8
+ export const metadata = {
9
+ event: 'sales.line.*',
10
+ persistent: false,
11
+ id: 'wms:invalidate-enricher-cache-sales-line',
12
+ }
13
+
14
+ export default createInventoryEnricherCacheHandler('warehouse')
@@ -0,0 +1,18 @@
1
+ import { createInventoryEnricherCacheHandler } from '../lib/inventoryEnricherCacheSubscriber'
2
+
3
+ // `wms.sales-order-inventory` reads the order's lines, and both the required
4
+ // quantity behind `reservationSummary.status` and the variant list behind
5
+ // `stockSummary` come from them. Order lines are written inside the sales order
6
+ // commands, which emit `sales.order.*` — not a WMS event — so without this the
7
+ // enrichment would stay stale for the whole TTL after a line edit.
8
+ //
9
+ // Scope `warehouse` rather than `inventory`: `wms:warehouse` is declared by the
10
+ // sales-order enricher alone, so this drops exactly its entries and leaves the
11
+ // two catalog enrichers' caches intact.
12
+ export const metadata = {
13
+ event: 'sales.order.*',
14
+ persistent: false,
15
+ id: 'wms:invalidate-enricher-cache-sales-order',
16
+ }
17
+
18
+ export default createInventoryEnricherCacheHandler('warehouse')
@@ -0,0 +1,9 @@
1
+ import { createInventoryEnricherCacheHandler } from '../lib/inventoryEnricherCacheSubscriber'
2
+
3
+ export const metadata = {
4
+ event: 'catalog.variant.*',
5
+ persistent: false,
6
+ id: 'wms:invalidate-enricher-cache-variant',
7
+ }
8
+
9
+ export default createInventoryEnricherCacheHandler('inventory')
@@ -0,0 +1,9 @@
1
+ import { createInventoryEnricherCacheHandler } from '../lib/inventoryEnricherCacheSubscriber'
2
+
3
+ export const metadata = {
4
+ event: 'wms.warehouse.*',
5
+ persistent: false,
6
+ id: 'wms:invalidate-enricher-cache-warehouse',
7
+ }
8
+
9
+ export default createInventoryEnricherCacheHandler('warehouse')