@endora-commerce/contracts 0.106.0 → 0.108.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.
Files changed (216) hide show
  1. package/dist/admin-contributions.d.ts +11 -6
  2. package/dist/admin-contributions.d.ts.map +1 -1
  3. package/dist/admin-contributions.js +9 -6
  4. package/dist/admin-contributions.js.map +1 -1
  5. package/dist/admin-feedback.d.ts +61 -0
  6. package/dist/admin-feedback.d.ts.map +1 -0
  7. package/dist/admin-feedback.js +71 -0
  8. package/dist/admin-feedback.js.map +1 -0
  9. package/dist/admin-name.d.ts +21 -0
  10. package/dist/admin-name.d.ts.map +1 -0
  11. package/dist/admin-name.js +30 -0
  12. package/dist/admin-name.js.map +1 -0
  13. package/dist/admin-roles.d.ts +32 -2
  14. package/dist/admin-roles.d.ts.map +1 -1
  15. package/dist/admin-roles.js +21 -1
  16. package/dist/admin-roles.js.map +1 -1
  17. package/dist/admin-search.d.ts +655 -0
  18. package/dist/admin-search.d.ts.map +1 -0
  19. package/dist/admin-search.js +179 -0
  20. package/dist/admin-search.js.map +1 -0
  21. package/dist/analytics.d.ts +5 -0
  22. package/dist/analytics.d.ts.map +1 -1
  23. package/dist/analytics.js +8 -0
  24. package/dist/analytics.js.map +1 -1
  25. package/dist/api-keys.d.ts +6 -0
  26. package/dist/api-keys.d.ts.map +1 -1
  27. package/dist/api-keys.js +5 -0
  28. package/dist/api-keys.js.map +1 -1
  29. package/dist/assets-library.d.ts +102 -0
  30. package/dist/assets-library.d.ts.map +1 -1
  31. package/dist/assets-library.js +89 -0
  32. package/dist/assets-library.js.map +1 -1
  33. package/dist/auth.d.ts +20 -0
  34. package/dist/auth.d.ts.map +1 -1
  35. package/dist/auth.js +20 -0
  36. package/dist/auth.js.map +1 -1
  37. package/dist/blog.d.ts +1 -1
  38. package/dist/carts.d.ts +218 -7
  39. package/dist/carts.d.ts.map +1 -1
  40. package/dist/carts.js +29 -0
  41. package/dist/carts.js.map +1 -1
  42. package/dist/catalog.d.ts +299 -14
  43. package/dist/catalog.d.ts.map +1 -1
  44. package/dist/catalog.js +136 -2
  45. package/dist/catalog.js.map +1 -1
  46. package/dist/cms.d.ts +183 -3
  47. package/dist/cms.d.ts.map +1 -1
  48. package/dist/cms.js +132 -1
  49. package/dist/cms.js.map +1 -1
  50. package/dist/common.d.ts +4 -0
  51. package/dist/common.d.ts.map +1 -1
  52. package/dist/common.js +14 -0
  53. package/dist/common.js.map +1 -1
  54. package/dist/comparisons.d.ts +80 -0
  55. package/dist/comparisons.d.ts.map +1 -1
  56. package/dist/comparisons.js +24 -0
  57. package/dist/comparisons.js.map +1 -1
  58. package/dist/credentials.d.ts +23 -0
  59. package/dist/credentials.d.ts.map +1 -1
  60. package/dist/credentials.js +24 -0
  61. package/dist/credentials.js.map +1 -1
  62. package/dist/credit-limits.d.ts.map +1 -1
  63. package/dist/credit-limits.js +3 -2
  64. package/dist/credit-limits.js.map +1 -1
  65. package/dist/crm-rich-text.d.ts +64 -0
  66. package/dist/crm-rich-text.d.ts.map +1 -0
  67. package/dist/crm-rich-text.js +303 -0
  68. package/dist/crm-rich-text.js.map +1 -0
  69. package/dist/crm.d.ts +92 -2
  70. package/dist/crm.d.ts.map +1 -1
  71. package/dist/crm.js +49 -34
  72. package/dist/crm.js.map +1 -1
  73. package/dist/custom-fields.d.ts +417 -4
  74. package/dist/custom-fields.d.ts.map +1 -1
  75. package/dist/custom-fields.js +319 -10
  76. package/dist/custom-fields.js.map +1 -1
  77. package/dist/customer-accounts.d.ts +92 -2
  78. package/dist/customer-accounts.d.ts.map +1 -1
  79. package/dist/document-templates.d.ts +1368 -0
  80. package/dist/document-templates.d.ts.map +1 -0
  81. package/dist/document-templates.js +569 -0
  82. package/dist/document-templates.js.map +1 -0
  83. package/dist/document-values.d.ts +159 -0
  84. package/dist/document-values.d.ts.map +1 -0
  85. package/dist/document-values.js +220 -0
  86. package/dist/document-values.js.map +1 -0
  87. package/dist/errors.d.ts +122 -0
  88. package/dist/errors.d.ts.map +1 -1
  89. package/dist/errors.js +172 -0
  90. package/dist/errors.js.map +1 -1
  91. package/dist/import-export.d.ts +11 -0
  92. package/dist/import-export.d.ts.map +1 -1
  93. package/dist/import-export.js +9 -0
  94. package/dist/import-export.js.map +1 -1
  95. package/dist/index.d.ts +15 -1
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +28 -1
  98. package/dist/index.js.map +1 -1
  99. package/dist/invoice-ledger.d.ts +6 -6
  100. package/dist/invoices.d.ts +88 -0
  101. package/dist/invoices.d.ts.map +1 -1
  102. package/dist/invoices.js +19 -4
  103. package/dist/invoices.js.map +1 -1
  104. package/dist/line-groups.d.ts +80 -0
  105. package/dist/line-groups.d.ts.map +1 -0
  106. package/dist/line-groups.js +130 -0
  107. package/dist/line-groups.js.map +1 -0
  108. package/dist/localized-name.d.ts +20 -0
  109. package/dist/localized-name.d.ts.map +1 -0
  110. package/dist/localized-name.js +45 -0
  111. package/dist/localized-name.js.map +1 -0
  112. package/dist/mfa.d.ts +20 -0
  113. package/dist/mfa.d.ts.map +1 -1
  114. package/dist/modules.d.ts +20 -10
  115. package/dist/modules.d.ts.map +1 -1
  116. package/dist/money-decimal.d.ts +162 -0
  117. package/dist/money-decimal.d.ts.map +1 -0
  118. package/dist/money-decimal.js +365 -0
  119. package/dist/money-decimal.js.map +1 -0
  120. package/dist/money-input.d.ts +64 -0
  121. package/dist/money-input.d.ts.map +1 -0
  122. package/dist/money-input.js +111 -0
  123. package/dist/money-input.js.map +1 -0
  124. package/dist/newsletter.d.ts +2 -0
  125. package/dist/newsletter.d.ts.map +1 -1
  126. package/dist/newsletter.js +4 -0
  127. package/dist/newsletter.js.map +1 -1
  128. package/dist/order-minimums.d.ts +111 -0
  129. package/dist/order-minimums.d.ts.map +1 -0
  130. package/dist/order-minimums.js +196 -0
  131. package/dist/order-minimums.js.map +1 -0
  132. package/dist/orders.d.ts +212 -2
  133. package/dist/orders.d.ts.map +1 -1
  134. package/dist/orders.js +124 -21
  135. package/dist/orders.js.map +1 -1
  136. package/dist/organizations.d.ts +78 -0
  137. package/dist/organizations.d.ts.map +1 -1
  138. package/dist/organizations.js +54 -0
  139. package/dist/organizations.js.map +1 -1
  140. package/dist/payment-methods.d.ts +2 -2
  141. package/dist/payment-methods.d.ts.map +1 -1
  142. package/dist/payment-methods.js +2 -1
  143. package/dist/payment-methods.js.map +1 -1
  144. package/dist/price-book-decimal.d.ts +84 -0
  145. package/dist/price-book-decimal.d.ts.map +1 -0
  146. package/dist/price-book-decimal.js +175 -0
  147. package/dist/price-book-decimal.js.map +1 -0
  148. package/dist/price-books.d.ts +2206 -0
  149. package/dist/price-books.d.ts.map +1 -0
  150. package/dist/price-books.js +777 -0
  151. package/dist/price-books.js.map +1 -0
  152. package/dist/price-lists.d.ts +398 -248
  153. package/dist/price-lists.d.ts.map +1 -1
  154. package/dist/price-lists.js +136 -244
  155. package/dist/price-lists.js.map +1 -1
  156. package/dist/product-feeds.d.ts +102 -21
  157. package/dist/product-feeds.d.ts.map +1 -1
  158. package/dist/product-feeds.js +18 -1
  159. package/dist/product-feeds.js.map +1 -1
  160. package/dist/product-value-resolver.d.ts +6 -0
  161. package/dist/product-value-resolver.d.ts.map +1 -1
  162. package/dist/product-value-resolver.js +6 -1
  163. package/dist/product-value-resolver.js.map +1 -1
  164. package/dist/promotions.d.ts +2 -2
  165. package/dist/promotions.d.ts.map +1 -1
  166. package/dist/promotions.js +8 -2
  167. package/dist/promotions.js.map +1 -1
  168. package/dist/prompt-actions.d.ts +25 -6
  169. package/dist/prompt-actions.d.ts.map +1 -1
  170. package/dist/prompt-actions.js +17 -1
  171. package/dist/prompt-actions.js.map +1 -1
  172. package/dist/pwa.d.ts +25 -0
  173. package/dist/pwa.d.ts.map +1 -1
  174. package/dist/pwa.js +38 -0
  175. package/dist/pwa.js.map +1 -1
  176. package/dist/quick-order.d.ts +39 -0
  177. package/dist/quick-order.d.ts.map +1 -1
  178. package/dist/quick-order.js +43 -0
  179. package/dist/quick-order.js.map +1 -1
  180. package/dist/quote-requests.d.ts +903 -9
  181. package/dist/quote-requests.d.ts.map +1 -1
  182. package/dist/quote-requests.js +515 -8
  183. package/dist/quote-requests.js.map +1 -1
  184. package/dist/returns.d.ts +55 -2
  185. package/dist/returns.d.ts.map +1 -1
  186. package/dist/returns.js +39 -4
  187. package/dist/returns.js.map +1 -1
  188. package/dist/sales-channels.d.ts +48 -0
  189. package/dist/sales-channels.d.ts.map +1 -1
  190. package/dist/sales-channels.js +42 -0
  191. package/dist/sales-channels.js.map +1 -1
  192. package/dist/saved-list-views.d.ts +140 -0
  193. package/dist/saved-list-views.d.ts.map +1 -0
  194. package/dist/saved-list-views.js +108 -0
  195. package/dist/saved-list-views.js.map +1 -0
  196. package/dist/search.d.ts +66 -0
  197. package/dist/search.d.ts.map +1 -1
  198. package/dist/search.js +4 -0
  199. package/dist/search.js.map +1 -1
  200. package/dist/seo.d.ts +2 -0
  201. package/dist/seo.d.ts.map +1 -1
  202. package/dist/seo.js +11 -0
  203. package/dist/seo.js.map +1 -1
  204. package/dist/shipping-methods.d.ts +2 -2
  205. package/dist/shipping-methods.d.ts.map +1 -1
  206. package/dist/shipping-methods.js +2 -1
  207. package/dist/shipping-methods.js.map +1 -1
  208. package/dist/shopping-lists.d.ts +24 -0
  209. package/dist/shopping-lists.d.ts.map +1 -1
  210. package/dist/shopping-lists.js +20 -1
  211. package/dist/shopping-lists.js.map +1 -1
  212. package/dist/storefront-value-overrides.d.ts +67 -0
  213. package/dist/storefront-value-overrides.d.ts.map +1 -0
  214. package/dist/storefront-value-overrides.js +93 -0
  215. package/dist/storefront-value-overrides.js.map +1 -0
  216. package/package.json +1 -1
@@ -1,5 +1,8 @@
1
1
  import { z } from 'zod';
2
2
  import { isoDateTimeSchema, OriginReferenceSchema, uuidSchema } from './common.js';
3
+ import { lineGroupInputSchema, lineGroupKeySchema, lineGroupSchema, newLineGroupInputSchema, refineLineGrouping, } from './line-groups.js';
4
+ import { customFieldCarrySkipSchema } from './custom-fields.js';
5
+ import { fourDecimalUnitPrice } from './money-input.js';
3
6
  /**
4
7
  * Quote Requests (RFQ) module contracts — feature 008 workflow rewrite.
5
8
  * Source of truth per Principle V; the backend re-uses these schemas as
@@ -44,6 +47,51 @@ export const quoteRequestItemSchema = z.object({
44
47
  * Organization is VAT-exempt / reverse-charge or no tax rule applies.
45
48
  */
46
49
  taxRate: z.number().finite().nonnegative().default(0),
50
+ /**
51
+ * Feature 146 — **admin replies only**; a customer reply does not carry the
52
+ * key. The at-request reference unit price (net, per base piece) stored when
53
+ * the line was created; `null` = none stored.
54
+ */
55
+ referencePrice: z
56
+ .object({
57
+ amount: z.number().finite(),
58
+ currency: z.string().length(3),
59
+ capturedAt: isoDateTimeSchema,
60
+ })
61
+ .nullable()
62
+ .optional(),
63
+ /**
64
+ * Feature 146 — **admin replies only**. The customer's proposal for this
65
+ * line: the line's own `desiredUnitPrice`, or — for a line of a request
66
+ * revised before feature 146 — the value from the submission record.
67
+ * `null` = the customer proposed nothing.
68
+ */
69
+ customerProposedUnitPrice: z.number().finite().nullable().optional(),
70
+ /** Feature 043 packaging-unit snapshot, already stored on the row; both replies. */
71
+ packagingUnitName: z.string().nullable().optional(),
72
+ packagingUnitBaseQuantity: z.number().int().positive().nullable().optional(),
73
+ /** Feature 155 — the resolved catalogue unit; admin and customer replies. */
74
+ packagingUnitId: uuidSchema.nullable().optional(),
75
+ /**
76
+ * Feature 155 (FR-030) — **admin replies only**: set when the line is below its
77
+ * product's current minimum. Informs only.
78
+ */
79
+ minimumWarning: z
80
+ .object({
81
+ kind: z.enum(['pieces', 'packaging_unit']),
82
+ minimum: z.number().int().positive(),
83
+ packagingUnitName: z.string().optional(),
84
+ })
85
+ .nullable()
86
+ .optional(),
87
+ /**
88
+ * Feature 159 — the line's group (`itemGroups[].id`), `null` = ungrouped.
89
+ * Admin and customer replies; defaulted so a reply written before the
90
+ * feature parses.
91
+ */
92
+ groupId: uuidSchema.nullable().default(null),
93
+ /** Feature 159 — 0-based order within the line's section (its group, or the ungrouped lines). */
94
+ position: z.number().int().nonnegative().default(0),
47
95
  });
48
96
  // ---------------------------------------------------------------------------
49
97
  // Events (history)
@@ -60,6 +108,12 @@ export const rfqEventTypeSchema = z.enum([
60
108
  'customer-rejected-revision',
61
109
  're-submitted',
62
110
  'note-added',
111
+ // Feature 153 (owner answer Q4) — the quote PDF was e-mailed. Admin replies
112
+ // only: a customer reply leaves these events out.
113
+ 'pdf-sent',
114
+ // Feature 162 — custom-field values a Sales Opportunity could not carry into
115
+ // this request. Admin replies only: it names keys of possibly internal fields.
116
+ 'custom-field-carry-skipped',
63
117
  ]);
64
118
  export const quoteRequestEventSchema = z.object({
65
119
  id: uuidSchema,
@@ -73,8 +127,211 @@ export const quoteRequestEventSchema = z.object({
73
127
  createdAt: isoDateTimeSchema,
74
128
  });
75
129
  // ---------------------------------------------------------------------------
130
+ // Readable history (feature 146) — `GET /api/v1/admin/quote-requests/:id/history`
131
+ // ---------------------------------------------------------------------------
132
+ /** A line as a history change names it. */
133
+ export const quoteRequestHistoryLineRefSchema = z.object({
134
+ productId: uuidSchema,
135
+ variantId: uuidSchema.nullable(),
136
+ /** Snapshot name, packaging suffix included. */
137
+ productName: z.string(),
138
+ /** Resolved on read; `null` when the variant is gone. */
139
+ variantLabel: z.string().nullable(),
140
+ /**
141
+ * Feature 159 (research N-32) — the line's group (`null` = ungrouped), present
142
+ * only where it tells the line apart: its product, variant and packaging unit
143
+ * sit on more than one line of either revision.
144
+ */
145
+ groupName: z.string().nullable().optional(),
146
+ });
147
+ /**
148
+ * One change of a `modified` entry. Packaging-unit and custom-field changes
149
+ * are never listed. The UI maps every `kind` to a bundle key.
150
+ */
151
+ export const quoteRequestHistoryChangeSchema = z.discriminatedUnion('kind', [
152
+ z.object({
153
+ kind: z.literal('line_added'),
154
+ line: quoteRequestHistoryLineRefSchema,
155
+ quantity: z.number().int().positive(),
156
+ agreedUnitPrice: z.number().nullable(),
157
+ currency: z.string().length(3),
158
+ }),
159
+ z.object({ kind: z.literal('line_removed'), line: quoteRequestHistoryLineRefSchema }),
160
+ z.object({
161
+ kind: z.literal('line_quantity'),
162
+ line: quoteRequestHistoryLineRefSchema,
163
+ before: z.number().int(),
164
+ after: z.number().int(),
165
+ }),
166
+ z.object({
167
+ kind: z.literal('line_agreed_unit_price'),
168
+ line: quoteRequestHistoryLineRefSchema,
169
+ before: z.number().nullable(),
170
+ after: z.number().nullable(),
171
+ currency: z.string().length(3),
172
+ }),
173
+ z.object({
174
+ kind: z.literal('line_proposed_unit_price'),
175
+ line: quoteRequestHistoryLineRefSchema,
176
+ before: z.number().nullable(),
177
+ after: z.number().nullable(),
178
+ currency: z.string().length(3),
179
+ }),
180
+ z.object({
181
+ kind: z.literal('line_note'),
182
+ line: quoteRequestHistoryLineRefSchema,
183
+ before: z.string().nullable(),
184
+ after: z.string().nullable(),
185
+ }),
186
+ z.object({
187
+ kind: z.literal('header_note'),
188
+ before: z.string().nullable(),
189
+ after: z.string().nullable(),
190
+ }),
191
+ z.object({
192
+ kind: z.literal('validity'),
193
+ before: isoDateTimeSchema.nullable(),
194
+ after: isoDateTimeSchema.nullable(),
195
+ }),
196
+ // Feature 159 — the grouping as recorded in the revision snapshots. Groups
197
+ // pair across snapshots by id; names are as recorded, `null` = ungrouped.
198
+ z.object({
199
+ kind: z.literal('group_added'),
200
+ group: z.object({ id: uuidSchema, name: z.string() }),
201
+ }),
202
+ z.object({
203
+ kind: z.literal('group_removed'),
204
+ group: z.object({ id: uuidSchema, name: z.string() }),
205
+ }),
206
+ z.object({
207
+ kind: z.literal('group_renamed'),
208
+ groupId: uuidSchema,
209
+ before: z.string(),
210
+ after: z.string(),
211
+ }),
212
+ z.object({
213
+ kind: z.literal('line_group'),
214
+ line: quoteRequestHistoryLineRefSchema,
215
+ before: z.string().nullable(),
216
+ after: z.string().nullable(),
217
+ }),
218
+ /** Lines or groups reordered with no other change explaining it; at most once per entry. */
219
+ z.object({ kind: z.literal('line_order') }),
220
+ ]);
221
+ /**
222
+ * Who an entry is attributed to. An administrator is named by first and last
223
+ * name only — the admin arm has **no e-mail key** — and `name: null` means an
224
+ * unknown user.
225
+ */
226
+ export const quoteRequestHistoryActorSchema = z.discriminatedUnion('kind', [
227
+ z.object({
228
+ kind: z.literal('admin'),
229
+ adminUserId: uuidSchema,
230
+ name: z.string().nullable(),
231
+ /** The stored `actorRoleLabel`. */
232
+ recordedRole: z.string().nullable(),
233
+ }),
234
+ z.object({
235
+ kind: z.literal('customer'),
236
+ customerAccountId: uuidSchema,
237
+ name: z.string().nullable(),
238
+ email: z.string().nullable(),
239
+ recordedRole: z.string().nullable(),
240
+ }),
241
+ z.object({ kind: z.literal('system') }),
242
+ z.object({ kind: z.literal('unknown'), recordedRole: z.string().nullable() }),
243
+ ]);
244
+ export const quoteRequestHistoryEntryKindSchema = z.enum([
245
+ 'submitted',
246
+ 'resubmitted',
247
+ 'created_by_admin',
248
+ 'created',
249
+ 'modified',
250
+ 'approved',
251
+ 'accepted_by_customer',
252
+ 'rejected_by_customer',
253
+ 'canceled',
254
+ 'expired',
255
+ 'completed',
256
+ 'note_added',
257
+ // Feature 153 (owner answer Q4).
258
+ 'pdf_sent',
259
+ // Feature 162.
260
+ 'custom_field_carry_skipped',
261
+ ]);
262
+ export const quoteRequestHistoryEntrySchema = z.object({
263
+ /** Id of the first merged event. */
264
+ id: uuidSchema,
265
+ eventIds: z.array(uuidSchema).min(1).max(2),
266
+ kind: quoteRequestHistoryEntryKindSchema,
267
+ occurredAt: isoDateTimeSchema,
268
+ actor: quoteRequestHistoryActorSchema,
269
+ revisionNumber: z.number().int().positive().nullable(),
270
+ /** Approval note or standalone note — never the automatic creation note. */
271
+ note: z.string().nullable(),
272
+ /** Cancellation or rejection reason. */
273
+ reason: z.string().nullable(),
274
+ /** `modified` entries only; `[]` = a modification that changed nothing listable. */
275
+ changes: z.array(quoteRequestHistoryChangeSchema).nullable(),
276
+ /** Resubmission source. */
277
+ relatedQuoteRequestId: uuidSchema.nullable(),
278
+ /** Completion. */
279
+ orderId: uuidSchema.nullable(),
280
+ /**
281
+ * Feature 153 — `pdf_sent` entries only: who the quote PDF was e-mailed to,
282
+ * with which template (`null` = the built-in layout) and in which language.
283
+ */
284
+ delivery: z
285
+ .object({
286
+ recipients: z.array(z.string()),
287
+ templateName: z.string().nullable(),
288
+ language: z.string().nullable(),
289
+ message: z.string().nullable(),
290
+ })
291
+ .nullable()
292
+ .optional(),
293
+ /**
294
+ * Feature 162 — `custom_field_carry_skipped` entries only: the Sales
295
+ * Opportunity the values came from and every key not carried, with its reason.
296
+ */
297
+ customFieldCarry: z
298
+ .object({
299
+ source: z.object({
300
+ entityType: z.literal('opportunity'),
301
+ recordId: uuidSchema,
302
+ reference: z.string(),
303
+ }),
304
+ skipped: z.array(customFieldCarrySkipSchema).min(1),
305
+ })
306
+ .nullable()
307
+ .optional(),
308
+ });
309
+ /**
310
+ * How many of a quote request's most recent events its history is built from
311
+ * (threat model T9). Shared so the admin's truncation notice states the number
312
+ * the server applies, rather than a copy of it.
313
+ */
314
+ export const QUOTE_REQUEST_HISTORY_EVENT_WINDOW = 100;
315
+ /**
316
+ * The history response body's `data`: entries oldest first, built from the
317
+ * most recent {@link QUOTE_REQUEST_HISTORY_EVENT_WINDOW} events; `truncated` is
318
+ * `true` when older ones exist.
319
+ */
320
+ export const quoteRequestHistorySchema = z.object({
321
+ entries: z.array(quoteRequestHistoryEntrySchema),
322
+ truncated: z.boolean(),
323
+ });
324
+ // ---------------------------------------------------------------------------
76
325
  // Comparison view (rendered when awaitingCustomerRevisionAcceptance is true)
77
326
  // ---------------------------------------------------------------------------
327
+ /**
328
+ * Feature 159 (research N-32) — the group of the line a comparison entry is
329
+ * about (`null` = ungrouped), present only where the product sits on more than
330
+ * one line of either revision (same variant and packaging unit), so "Bolt: 5 →
331
+ * 3" says which Bolt line. The
332
+ * group's name is one the customer was shown on that revision.
333
+ */
334
+ const diffGroupNameSchema = z.string().nullable().optional();
78
335
  export const rfqDiffEntrySchema = z.discriminatedUnion('kind', [
79
336
  z.object({
80
337
  kind: z.literal('header_note'),
@@ -87,11 +344,13 @@ export const rfqDiffEntrySchema = z.discriminatedUnion('kind', [
87
344
  productName: z.string(),
88
345
  quantity: z.number().int().positive(),
89
346
  agreedUnitPrice: z.number().nullable(),
347
+ groupName: diffGroupNameSchema,
90
348
  }),
91
349
  z.object({
92
350
  kind: z.literal('line_removed'),
93
351
  productId: uuidSchema,
94
352
  productName: z.string(),
353
+ groupName: diffGroupNameSchema,
95
354
  }),
96
355
  z.object({
97
356
  kind: z.literal('line_quantity'),
@@ -99,6 +358,7 @@ export const rfqDiffEntrySchema = z.discriminatedUnion('kind', [
99
358
  productName: z.string(),
100
359
  before: z.number().int().positive(),
101
360
  after: z.number().int().positive(),
361
+ groupName: diffGroupNameSchema,
102
362
  }),
103
363
  z.object({
104
364
  kind: z.literal('line_agreed_unit_price'),
@@ -106,7 +366,14 @@ export const rfqDiffEntrySchema = z.discriminatedUnion('kind', [
106
366
  productName: z.string(),
107
367
  before: z.number().nullable(),
108
368
  after: z.number().nullable(),
369
+ groupName: diffGroupNameSchema,
109
370
  }),
371
+ /**
372
+ * Feature 159 — the arrangement of the lines (group names, group order,
373
+ * membership, line order) differs. Carries no other key: it names nothing
374
+ * the customer reply does not already carry.
375
+ */
376
+ z.object({ kind: z.literal('grouping') }),
110
377
  ]);
111
378
  export const rfqComparisonAgainstLastSeenSchema = z.object({
112
379
  diff: z.array(rfqDiffEntrySchema),
@@ -127,6 +394,12 @@ export const quoteRequestSchema = z.object({
127
394
  businessId: z.string(),
128
395
  organizationId: uuidSchema,
129
396
  customerAccountId: uuidSchema,
397
+ /**
398
+ * Feature 146 — the sales channel the request was raised on. **Admin
399
+ * replies only**, so the admin screen can ask for a current price on that
400
+ * channel; `null` = raised before channel attribution (system default).
401
+ */
402
+ salesChannelId: uuidSchema.nullable().optional(),
130
403
  /**
131
404
  * The administrator who created the quote on the customer's behalf, and the
132
405
  * one it is assigned to. **Admin replies only** — a customer reply carries
@@ -142,6 +415,13 @@ export const quoteRequestSchema = z.object({
142
415
  cancellationReason: z.string().nullable(),
143
416
  /** Feature 055 — custom-field values captured on this quote request. */
144
417
  customFieldValues: z.record(z.string(), z.unknown()).default({}),
418
+ /**
419
+ * Feature 159 — the quote's line groups in display order. Admin replies:
420
+ * every group, empty ones included (the editor needs them). Customer
421
+ * replies: groups holding at least one line only.
422
+ */
423
+ itemGroups: z.array(lineGroupSchema).default([]),
424
+ /** In display order: each group's lines in order, then the ungrouped lines. */
145
425
  items: z.array(quoteRequestItemSchema),
146
426
  events: z.array(quoteRequestEventSchema),
147
427
  comparisonAgainstLastSeen: rfqComparisonAgainstLastSeenSchema.nullable(),
@@ -184,6 +464,12 @@ export const quoteRequestSchema = z.object({
184
464
  })
185
465
  .nullable()
186
466
  .optional(),
467
+ /**
468
+ * Feature 153 (owner answer Q2) — the PDF template remembered for this quote,
469
+ * `null` = none. **Admin replies only.** A stale id is kept: the export falls
470
+ * back to the default and says so.
471
+ */
472
+ documentTemplateId: uuidSchema.nullable().optional(),
187
473
  createdAt: isoDateTimeSchema,
188
474
  updatedAt: isoDateTimeSchema,
189
475
  version: z.number().int().nonnegative(),
@@ -223,20 +509,27 @@ export const createQuoteRequestLineSchema = z.object({
223
509
  productId: uuidSchema,
224
510
  variantId: uuidSchema.optional(),
225
511
  quantity: z.number().int().positive(),
226
- desiredUnitPrice: z.number().finite().nonnegative().optional(),
512
+ desiredUnitPrice: fourDecimalUnitPrice(z.number().finite().nonnegative()).optional(),
227
513
  lineNote: z.string().max(2000).optional(),
228
514
  /** Feature 043 — snapshot when the line was added as a packaging unit. */
229
515
  packagingUnitName: z.string().max(160).optional(),
230
516
  packagingUnitBaseQuantity: z.number().int().positive().optional(),
517
+ /** Feature 155 (FR-026) — the catalogue unit the line is ordered in. Wins over name/base quantity. */
518
+ packagingUnitId: uuidSchema.optional(),
231
519
  });
520
+ /**
521
+ * Customer-facing: **not strict**, deliberately — an unknown key (a body
522
+ * `lineReferencePrices`, a per-line `referenceUnitPrice`) is stripped, never
523
+ * refused, and never reaches the service.
524
+ */
232
525
  export const createQuoteRequestSchema = z.object({
233
526
  headerNote: z.string().max(2000).optional(),
234
- items: z.array(createQuoteRequestLineSchema).min(1),
527
+ items: z.array(createQuoteRequestLineSchema).min(1).max(200),
235
528
  });
236
529
  export const patchQuoteRequestSchema = z
237
530
  .object({
238
531
  headerNote: z.string().max(2000).nullable().optional(),
239
- items: z.array(createQuoteRequestLineSchema).min(1).optional(),
532
+ items: z.array(createQuoteRequestLineSchema).min(1).max(200).optional(),
240
533
  })
241
534
  .strict();
242
535
  export const acceptRevisionSchema = z.object({
@@ -258,13 +551,19 @@ export const adminCreateQuoteRequestLineSchema = z.object({
258
551
  productId: uuidSchema,
259
552
  variantId: uuidSchema.optional(),
260
553
  quantity: z.number().int().positive(),
261
- agreedUnitPrice: z.number().finite().nonnegative(),
554
+ agreedUnitPrice: fourDecimalUnitPrice(z.number().finite().nonnegative()),
262
555
  lineNote: z.string().max(2000).optional(),
556
+ /** Feature 159 — the `groups[].key` this line belongs to; absent or `null` = ungrouped. */
557
+ groupKey: lineGroupKeySchema.nullable().optional(),
263
558
  });
264
- export const adminCreateQuoteRequestSchema = z.object({
559
+ export const adminCreateQuoteRequestSchema = z
560
+ .object({
265
561
  organizationId: uuidSchema,
266
562
  customerAccountId: uuidSchema,
267
563
  headerNote: z.string().max(2000).optional(),
564
+ /** Feature 159 — the new quote's groups in display order; lines name them by `groupKey`. */
565
+ groups: z.array(newLineGroupInputSchema).optional(),
566
+ /** In display order: each group's lines, then the ungrouped lines. */
268
567
  items: z.array(adminCreateQuoteRequestLineSchema).min(1),
269
568
  expiresInDays: z.number().int().nonnegative().optional(),
270
569
  /**
@@ -273,7 +572,8 @@ export const adminCreateQuoteRequestSchema = z.object({
273
572
  * Not stored and not returned.
274
573
  */
275
574
  origin: OriginReferenceSchema.optional(),
276
- });
575
+ })
576
+ .superRefine((body, ctx) => refineLineGrouping(ctx, body));
277
577
  /** The name of the event that announces a Quote Request an administrator created. */
278
578
  export const RFQ_CREATED_BY_ADMIN_EVENT = 'rfq.created_by_admin.v1';
279
579
  export const adminPatchQuoteRequestLineSchema = z.object({
@@ -281,24 +581,52 @@ export const adminPatchQuoteRequestLineSchema = z.object({
281
581
  productId: uuidSchema,
282
582
  variantId: uuidSchema.optional(),
283
583
  quantity: z.number().int().positive(),
284
- agreedUnitPrice: z.number().finite().nonnegative().nullable().optional(),
584
+ agreedUnitPrice: fourDecimalUnitPrice(z.number().finite().nonnegative()).nullable().optional(),
285
585
  lineNote: z.string().max(2000).nullable().optional(),
586
+ /** Feature 159 — the `groups[].key` this line belongs to; `null` = ungrouped. */
587
+ groupKey: lineGroupKeySchema.nullable().optional(),
588
+ /**
589
+ * Feature 159 (research N-33) — a new line split off a stored line of this
590
+ * quote (*Split line*): with no `id`, it takes that line's variant, packaging
591
+ * unit, customer's proposal, note, currency and stored reference, as the
592
+ * line it was split from keeps them. A value naming no line of this quote is
593
+ * ignored — the line is a plain new line.
594
+ */
595
+ splitFromId: uuidSchema.optional(),
286
596
  });
287
597
  export const adminPatchQuoteRequestSchema = z
288
598
  .object({
289
599
  headerNote: z.string().max(2000).nullable().optional(),
600
+ /**
601
+ * Feature 159 — the whole grouping in display order; requires `items`.
602
+ * Absent with `items` present: every paired line keeps its group, new
603
+ * lines are ungrouped, no group is deleted (research R-14).
604
+ */
605
+ groups: z.array(lineGroupInputSchema).optional(),
606
+ /** In display order: each group's lines, then the ungrouped lines. */
290
607
  items: z.array(adminPatchQuoteRequestLineSchema).min(1).optional(),
291
608
  expiresInDays: z.number().int().nonnegative().optional(),
292
609
  /** Feature 055 — custom-field values for this quote request (validated on write). */
293
610
  customFieldValues: z.record(z.string(), z.unknown()).optional(),
294
611
  })
295
- .strict();
612
+ .strict()
613
+ .superRefine((body, ctx) => refineLineGrouping(ctx, body));
296
614
  export const adminApproveQuoteRequestSchema = z
297
615
  .object({ note: z.string().max(2000).optional() })
298
616
  .strict();
299
617
  export const adminCancelQuoteRequestSchema = z
300
618
  .object({ reason: z.string().max(2000).optional() })
301
619
  .strict();
620
+ /**
621
+ * `POST /api/v1/admin/quote-requests/:id/prepare-customer-basket` (issue #170):
622
+ * the approved request's lines are in the basket of the customer who owns it,
623
+ * at the agreed prices, for that customer to check out.
624
+ */
625
+ export const adminPrepareCustomerBasketResponseSchema = z.object({
626
+ cartId: uuidSchema,
627
+ customerAccountId: uuidSchema,
628
+ itemCount: z.number().int().nonnegative(),
629
+ });
302
630
  export const adminAssignQuoteRequestSchema = z.object({
303
631
  adminUserId: uuidSchema,
304
632
  });
@@ -313,6 +641,44 @@ export const storefrontQuoteRequestSettingsSchema = z.object({
313
641
  showAddToQuoteOnCard: z.boolean(),
314
642
  showAddToQuoteOnPdp: z.boolean(),
315
643
  });
644
+ // ---------------------------------------------------------------------------
645
+ // Price negotiation lock (feature 146)
646
+ // ---------------------------------------------------------------------------
647
+ /** `GET|PUT /api/v1/admin/organizations/:id/quote-price-negotiation` answer. */
648
+ export const quoteRequestOrgNegotiationSchema = z.object({
649
+ organizationId: uuidSchema,
650
+ priceProposalsAllowed: z.boolean(),
651
+ /** `null` when no row exists yet (the default applies). */
652
+ updatedAt: isoDateTimeSchema.nullable(),
653
+ });
654
+ /** Admin body — strict. */
655
+ export const setQuoteRequestOrgNegotiationSchema = z
656
+ .object({ priceProposalsAllowed: z.boolean() })
657
+ .strict();
658
+ export const quoteRequestNegotiationOverrideSchema = z.enum(['inherit', 'allowed', 'not_allowed']);
659
+ /** `GET|PUT /api/v1/admin/customers/:id/quote-price-negotiation` answer. */
660
+ export const quoteRequestAccountNegotiationSchema = z.object({
661
+ customerAccountId: uuidSchema,
662
+ /** The account's current organization. */
663
+ organizationId: uuidSchema,
664
+ override: quoteRequestNegotiationOverrideSchema,
665
+ organizationPriceProposalsAllowed: z.boolean(),
666
+ /** The resulting value and where it comes from. */
667
+ effectivePriceProposalsAllowed: z.boolean(),
668
+ effectiveSource: z.enum(['account', 'organization', 'default']),
669
+ updatedAt: isoDateTimeSchema.nullable(),
670
+ });
671
+ /** Admin body — strict. */
672
+ export const setQuoteRequestAccountNegotiationSchema = z
673
+ .object({ override: quoteRequestNegotiationOverrideSchema })
674
+ .strict();
675
+ /**
676
+ * `GET /api/v1/quote-requests/price-negotiation` — the signed-in customer's
677
+ * effective value and nothing else: no id, no organization value, no override.
678
+ */
679
+ export const storefrontQuoteRequestNegotiationSchema = z.object({
680
+ priceProposalsAllowed: z.boolean(),
681
+ });
316
682
  /** The statuses that mean "this quote is still live". */
317
683
  export const OPEN_QUOTE_REQUEST_STATUSES = [
318
684
  'Pending',
@@ -374,4 +740,145 @@ export const QUOTE_REQUEST_WEBHOOK_EVENT_SCHEMAS = {
374
740
  [QUOTE_REQUEST_WEBHOOK_EVENTS.CREATED]: RfqCreatedEventV1Schema,
375
741
  [QUOTE_REQUEST_WEBHOOK_EVENTS.EXPIRED]: RfqExpiredEventV1Schema,
376
742
  };
743
+ // ---------------------------------------------------------------------------
744
+ // Feature 153 — the quote PDF (`specs/153-quote-request-pdf-template/`)
745
+ // ---------------------------------------------------------------------------
746
+ /** The document type `quote_requests` registers with the document-template facility. */
747
+ export const QUOTE_REQUEST_DOCUMENT_TYPE = 'quote_requests.quote_request';
748
+ /** Owner answer Q4 — what one *Send PDF to customer* may carry. */
749
+ export const QUOTE_REQUEST_PDF_LIMITS = {
750
+ maxRecipients: 5,
751
+ maxMessageLength: 2000,
752
+ /** 10 MiB — larger PDFs are refused rather than handed to a mail server. */
753
+ maxAttachmentBytes: 10 * 1024 * 1024,
754
+ };
755
+ const documentLanguageCode = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
756
+ /**
757
+ * The data one quote PDF prints, built for the requesting administrator
758
+ * (`data-model.md` §4.1). JSON-serialisable: the editor's sample is the same
759
+ * shape.
760
+ */
761
+ export const quoteRequestDocumentDataSchema = z.object({
762
+ generatedAt: isoDateTimeSchema,
763
+ quote: z.object({
764
+ id: z.string(),
765
+ businessId: z.string(),
766
+ status: z.string(),
767
+ revisionNumber: z.number().int().nonnegative(),
768
+ createdAt: isoDateTimeSchema,
769
+ submittedAt: isoDateTimeSchema.nullable(),
770
+ approvedAt: isoDateTimeSchema.nullable(),
771
+ expiresAt: isoDateTimeSchema.nullable(),
772
+ headerNote: z.string().nullable(),
773
+ /** A fraction: `0.23`. */
774
+ taxRate: z.number(),
775
+ currency: z.string(),
776
+ }),
777
+ channel: z.object({ id: z.string(), name: z.string() }).nullable(),
778
+ buyer: z.object({
779
+ organizationName: z.string(),
780
+ legalName: z.string().nullable(),
781
+ taxId: z.string().nullable(),
782
+ address: z
783
+ .object({
784
+ line1: z.string(),
785
+ line2: z.string().nullable(),
786
+ postalCode: z.string(),
787
+ city: z.string(),
788
+ country: z.string(),
789
+ })
790
+ .nullable(),
791
+ customerName: z.string().nullable(),
792
+ customerEmail: z.string().nullable(),
793
+ }),
794
+ salesRep: z.object({ name: z.string(), email: z.string() }).nullable(),
795
+ /** The quote's custom fields whose definition customers may see, with a value. */
796
+ details: z.array(z.object({ label: z.string(), value: z.string() })),
797
+ /** Feature 159 — the groups holding at least one line, in display order. */
798
+ groups: z.array(lineGroupSchema).default([]),
799
+ /** In display order. */
800
+ lines: z.array(z.object({
801
+ id: z.string(),
802
+ productId: z.string(),
803
+ productName: z.string(),
804
+ variantLabel: z.string().nullable(),
805
+ sku: z.string().nullable(),
806
+ quantity: z.number(),
807
+ packagingUnitName: z.string().nullable(),
808
+ packagingUnitBaseQuantity: z.number().nullable(),
809
+ agreedUnitPrice: z.number().nullable(),
810
+ proposedUnitPrice: z.number().nullable(),
811
+ referenceUnitPrice: z.number().nullable(),
812
+ referenceCurrency: z.string().nullable(),
813
+ lineCurrency: z.string(),
814
+ lineNote: z.string().nullable(),
815
+ /** Attribute code → display text in the export language. */
816
+ attributes: z.record(z.string(), z.string()),
817
+ /** Feature 159 — the line's group (`groups[].id`), `null` = ungrouped. */
818
+ groupId: z.string().nullable().default(null),
819
+ /** Feature 159 — order within the line's section. */
820
+ position: z.number().int().nonnegative().default(0),
821
+ })),
822
+ });
823
+ /** `GET /api/v1/admin/quote-requests/:id/document-templates` — the export and send dialogs' choices. */
824
+ export const quoteRequestDocumentChoicesSchema = z.object({
825
+ templates: z.array(z.object({
826
+ id: uuidSchema,
827
+ name: z.string(),
828
+ salesChannelId: uuidSchema.nullable(),
829
+ languages: z.array(z.string()),
830
+ isDefault: z.boolean(),
831
+ })),
832
+ rememberedTemplateId: uuidSchema.nullable(),
833
+ /** The remembered id is not among `templates` (deleted or out of reach). */
834
+ rememberedTemplateMissing: z.boolean(),
835
+ /** What an export without a choice uses; `null` = the built-in layout. */
836
+ effectiveDefaultId: uuidSchema.nullable(),
837
+ builtInLanguages: z.array(z.string()),
838
+ /** The default language of the quote's channel (the system default channel when none). */
839
+ suggestedLanguage: z.string(),
840
+ /** Owner answer Q4 — the requesting customer's e-mail, the send dialog's preselected recipient. */
841
+ requesterEmail: z.string().nullable(),
842
+ });
843
+ /** `PUT /api/v1/admin/quote-requests/:id/document-template`. */
844
+ export const setQuoteRequestDocumentTemplateSchema = z.object({
845
+ documentTemplateId: uuidSchema.nullable(),
846
+ });
847
+ /** `GET /api/v1/admin/quote-requests/:id/pdf` query. */
848
+ export const quoteRequestPdfQuerySchema = z.object({
849
+ templateId: uuidSchema.optional(),
850
+ language: documentLanguageCode.optional(),
851
+ });
852
+ /**
853
+ * `POST /api/v1/admin/quote-requests/:id/pdf/send` (owner answer Q4). The
854
+ * recipients are trimmed and de-duplicated case-insensitively — the first
855
+ * spelling kept — before the 1–5 bound is applied.
856
+ */
857
+ export const quoteRequestPdfSendRequestSchema = z.object({
858
+ templateId: uuidSchema.optional(),
859
+ language: documentLanguageCode.optional(),
860
+ recipients: z
861
+ .array(z.string().trim().max(254).email())
862
+ .transform((addresses) => {
863
+ const seen = new Set();
864
+ return addresses.filter((address) => {
865
+ const key = address.toLowerCase();
866
+ if (seen.has(key))
867
+ return false;
868
+ seen.add(key);
869
+ return true;
870
+ });
871
+ })
872
+ .pipe(z.array(z.string()).min(1).max(QUOTE_REQUEST_PDF_LIMITS.maxRecipients)),
873
+ message: z.string().max(QUOTE_REQUEST_PDF_LIMITS.maxMessageLength).optional(),
874
+ });
875
+ export const quoteRequestPdfSendResultSchema = z.object({
876
+ /** Addresses the e-mail was handed to. */
877
+ sent: z.array(z.string()),
878
+ /** Addresses whose delivery failed at the transport. */
879
+ failed: z.array(z.string()),
880
+ templateId: uuidSchema.nullable(),
881
+ templateSource: z.enum(['explicit', 'default', 'built_in', 'canvas']),
882
+ requestedTemplateMissing: z.boolean(),
883
+ });
377
884
  //# sourceMappingURL=quote-requests.js.map