@aglyn/plugins-commerce 1.15.2 → 1.17.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 (220) hide show
  1. package/README.md +1 -1
  2. package/package.json +13 -13
  3. package/src/lib/components/cart.js +2 -1
  4. package/src/lib/components/cart.js.map +1 -1
  5. package/src/lib/components/console/payments-settings-card.component.js +6 -1
  6. package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
  7. package/src/lib/components/console/pos/pos-api.d.ts +5 -0
  8. package/src/lib/components/console/pos/pos-api.js.map +1 -1
  9. package/src/lib/components/console/pos/pos-tender-dialogs.component.d.ts +2 -0
  10. package/src/lib/components/console/pos/pos-tender-dialogs.component.js +13 -6
  11. package/src/lib/components/console/pos/pos-tender-dialogs.component.js.map +1 -1
  12. package/src/lib/components/console/pos/pos-tender-panel.component.js +7 -4
  13. package/src/lib/components/console/pos/pos-tender-panel.component.js.map +1 -1
  14. package/src/lib/components/console/pos-cellular-control.component.d.ts +5 -0
  15. package/src/lib/components/console/pos-cellular-control.component.js +29 -15
  16. package/src/lib/components/console/pos-cellular-control.component.js.map +1 -1
  17. package/src/lib/components/console/product-add-ons-fields.component.d.ts +13 -0
  18. package/src/lib/components/console/product-add-ons-fields.component.js +96 -3
  19. package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
  20. package/src/lib/components/console/product-builder-fields.component.d.ts +39 -0
  21. package/src/lib/components/console/product-builder-fields.component.js +195 -0
  22. package/src/lib/components/console/product-builder-fields.component.js.map +1 -0
  23. package/src/lib/components/console/product-editor-dialog.component.js +35 -2
  24. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  25. package/src/lib/components/console/quote-editor-dialog.component.js +43 -6
  26. package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
  27. package/src/lib/components/console/quote-messages.component.d.ts +21 -0
  28. package/src/lib/components/console/quote-messages.component.js +185 -0
  29. package/src/lib/components/console/quote-messages.component.js.map +1 -0
  30. package/src/lib/components/console/quote-pay-link.component.js +1 -1
  31. package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
  32. package/src/lib/components/console/quote-proofs.component.js +30 -3
  33. package/src/lib/components/console/quote-proofs.component.js.map +1 -1
  34. package/src/lib/components/console/quote-settings-card.component.d.ts +7 -3
  35. package/src/lib/components/console/quote-settings-card.component.js +154 -24
  36. package/src/lib/components/console/quote-settings-card.component.js.map +1 -1
  37. package/src/lib/components/product-builder-context.d.ts +22 -0
  38. package/src/lib/components/product-builder-context.js +21 -0
  39. package/src/lib/components/product-builder-context.js.map +1 -0
  40. package/src/lib/components/product-builder-mockup.d.ts +42 -0
  41. package/src/lib/components/product-builder-mockup.js +120 -0
  42. package/src/lib/components/product-builder-mockup.js.map +1 -0
  43. package/src/lib/components/product-builder-sample.d.ts +63 -0
  44. package/src/lib/components/product-builder-sample.js +96 -0
  45. package/src/lib/components/product-builder-sample.js.map +1 -0
  46. package/src/lib/components/product-choice-cards.d.ts +51 -0
  47. package/src/lib/components/product-choice-cards.js +311 -0
  48. package/src/lib/components/product-choice-cards.js.map +1 -0
  49. package/src/lib/components/product-detail-panels.d.ts +42 -0
  50. package/src/lib/components/product-detail-panels.js +185 -0
  51. package/src/lib/components/product-detail-panels.js.map +1 -0
  52. package/src/lib/components/product-detail.d.ts +20 -12
  53. package/src/lib/components/product-detail.js +136 -221
  54. package/src/lib/components/product-detail.js.map +1 -1
  55. package/src/lib/components/product-grid.d.ts +7 -0
  56. package/src/lib/components/product-grid.js +13 -9
  57. package/src/lib/components/product-grid.js.map +1 -1
  58. package/src/lib/components/product-name-lines.d.ts +37 -0
  59. package/src/lib/components/product-name-lines.js +36 -0
  60. package/src/lib/components/product-name-lines.js.map +1 -0
  61. package/src/lib/components/product-options-field-body.d.ts +9 -8
  62. package/src/lib/components/product-options-field-body.js +152 -3
  63. package/src/lib/components/product-options-field-body.js.map +1 -1
  64. package/src/lib/components/product-options-field.js +1 -1
  65. package/src/lib/components/product-options-field.js.map +1 -1
  66. package/src/lib/components/product-photo-fit.d.ts +49 -0
  67. package/src/lib/components/product-photo-fit.js +58 -0
  68. package/src/lib/components/product-photo-fit.js.map +1 -0
  69. package/src/lib/components/product-restock-notify.d.ts +12 -0
  70. package/src/lib/components/product-restock-notify.js +86 -0
  71. package/src/lib/components/product-restock-notify.js.map +1 -0
  72. package/src/lib/components/quote-messages-panel.d.ts +21 -0
  73. package/src/lib/components/quote-messages-panel.js +191 -0
  74. package/src/lib/components/quote-messages-panel.js.map +1 -0
  75. package/src/lib/components/quote-page-body.js +15 -1
  76. package/src/lib/components/quote-page-body.js.map +1 -1
  77. package/src/lib/components/quote-proof-panel.d.ts +6 -3
  78. package/src/lib/components/quote-proof-panel.js +139 -14
  79. package/src/lib/components/quote-proof-panel.js.map +1 -1
  80. package/src/lib/components/related-products.d.ts +7 -0
  81. package/src/lib/components/related-products.js +10 -7
  82. package/src/lib/components/related-products.js.map +1 -1
  83. package/src/lib/constants/quote-page.d.ts +8 -0
  84. package/src/lib/constants/quote-page.js +11 -0
  85. package/src/lib/constants/quote-page.js.map +1 -1
  86. package/src/lib/model/commerce-cart.d.ts +6 -1
  87. package/src/lib/model/commerce-cart.js +5 -1
  88. package/src/lib/model/commerce-cart.js.map +1 -1
  89. package/src/lib/model/commerce-invoices.js +5 -1
  90. package/src/lib/model/commerce-invoices.js.map +1 -1
  91. package/src/lib/model/commerce-pos-ops.d.ts +3 -0
  92. package/src/lib/model/commerce-pos-ops.js +3 -0
  93. package/src/lib/model/commerce-pos-ops.js.map +1 -1
  94. package/src/lib/model/commerce-pos.d.ts +8 -0
  95. package/src/lib/model/commerce-pos.js.map +1 -1
  96. package/src/lib/model/commerce-quote-messages.d.ts +106 -0
  97. package/src/lib/model/commerce-quote-messages.js +146 -0
  98. package/src/lib/model/commerce-quote-messages.js.map +1 -0
  99. package/src/lib/model/commerce-quote-pay.d.ts +31 -2
  100. package/src/lib/model/commerce-quote-pay.js +31 -7
  101. package/src/lib/model/commerce-quote-pay.js.map +1 -1
  102. package/src/lib/model/commerce-quote-proofs.d.ts +47 -8
  103. package/src/lib/model/commerce-quote-proofs.js +73 -18
  104. package/src/lib/model/commerce-quote-proofs.js.map +1 -1
  105. package/src/lib/model/commerce-quote-request.d.ts +14 -4
  106. package/src/lib/model/commerce-quote-request.js +25 -2
  107. package/src/lib/model/commerce-quote-request.js.map +1 -1
  108. package/src/lib/model/commerce-quotes.d.ts +56 -3
  109. package/src/lib/model/commerce-quotes.js +47 -2
  110. package/src/lib/model/commerce-quotes.js.map +1 -1
  111. package/src/lib/model/commerce.d.ts +12 -1
  112. package/src/lib/model/commerce.js.map +1 -1
  113. package/src/lib/model/index.d.ts +1 -0
  114. package/src/lib/model/index.js +1 -0
  115. package/src/lib/model/index.js.map +1 -1
  116. package/src/lib/model/pos-cellular.d.ts +36 -4
  117. package/src/lib/model/pos-cellular.js +39 -4
  118. package/src/lib/model/pos-cellular.js.map +1 -1
  119. package/src/lib/model/product-card-rules.d.ts +41 -0
  120. package/src/lib/model/product-card-rules.js +90 -0
  121. package/src/lib/model/product-card-rules.js.map +1 -0
  122. package/src/lib/model/product-modifiers.d.ts +11 -0
  123. package/src/lib/model/product-modifiers.js +10 -0
  124. package/src/lib/model/product-modifiers.js.map +1 -1
  125. package/src/lib/model/product-write.d.ts +3 -0
  126. package/src/lib/server/billing-webhook.js +6 -2
  127. package/src/lib/server/billing-webhook.js.map +1 -1
  128. package/src/lib/server/cancel-order.js +15 -0
  129. package/src/lib/server/cancel-order.js.map +1 -1
  130. package/src/lib/server/channel-order-updates.js +15 -1
  131. package/src/lib/server/channel-order-updates.js.map +1 -1
  132. package/src/lib/server/channel-orders.js +20 -0
  133. package/src/lib/server/channel-orders.js.map +1 -1
  134. package/src/lib/server/checkout.js +1 -1
  135. package/src/lib/server/checkout.js.map +1 -1
  136. package/src/lib/server/local-fulfillment.js +1 -1
  137. package/src/lib/server/local-fulfillment.js.map +1 -1
  138. package/src/lib/server/pos-cellular-billing.d.ts +5 -4
  139. package/src/lib/server/pos-cellular-billing.js +24 -12
  140. package/src/lib/server/pos-cellular-billing.js.map +1 -1
  141. package/src/lib/server/pos-cellular.d.ts +3 -1
  142. package/src/lib/server/pos-cellular.js +55 -33
  143. package/src/lib/server/pos-cellular.js.map +1 -1
  144. package/src/lib/server/pos-offline-sync.d.ts +3 -3
  145. package/src/lib/server/pos-offline-sync.js +17 -4
  146. package/src/lib/server/pos-offline-sync.js.map +1 -1
  147. package/src/lib/server/pos-order.js +17 -6
  148. package/src/lib/server/pos-order.js.map +1 -1
  149. package/src/lib/server/pos-payment.js +27 -11
  150. package/src/lib/server/pos-payment.js.map +1 -1
  151. package/src/lib/server/pos-reader-splash.js +10 -5
  152. package/src/lib/server/pos-reader-splash.js.map +1 -1
  153. package/src/lib/server/pos-readers.js +42 -12
  154. package/src/lib/server/pos-readers.js.map +1 -1
  155. package/src/lib/server/pos-return.js +19 -3
  156. package/src/lib/server/pos-return.js.map +1 -1
  157. package/src/lib/server/pos-stripe.d.ts +14 -0
  158. package/src/lib/server/pos-stripe.js +6 -2
  159. package/src/lib/server/pos-stripe.js.map +1 -1
  160. package/src/lib/server/pos-terminal-connection-token.js +23 -9
  161. package/src/lib/server/pos-terminal-connection-token.js.map +1 -1
  162. package/src/lib/server/pos-terminal.d.ts +80 -14
  163. package/src/lib/server/pos-terminal.js +393 -123
  164. package/src/lib/server/pos-terminal.js.map +1 -1
  165. package/src/lib/server/product-drafts.d.ts +1 -1
  166. package/src/lib/server/product-drafts.js +4 -3
  167. package/src/lib/server/product-drafts.js.map +1 -1
  168. package/src/lib/server/product-writer.js +5 -4
  169. package/src/lib/server/product-writer.js.map +1 -1
  170. package/src/lib/server/product.d.ts +11 -0
  171. package/src/lib/server/product.js +18 -3
  172. package/src/lib/server/product.js.map +1 -1
  173. package/src/lib/server/products-write.js +4 -3
  174. package/src/lib/server/products-write.js.map +1 -1
  175. package/src/lib/server/quote-email.d.ts +26 -0
  176. package/src/lib/server/quote-email.js +73 -7
  177. package/src/lib/server/quote-email.js.map +1 -1
  178. package/src/lib/server/quote-messages.d.ts +72 -0
  179. package/src/lib/server/quote-messages.js +356 -0
  180. package/src/lib/server/quote-messages.js.map +1 -0
  181. package/src/lib/server/quote-pay.d.ts +42 -0
  182. package/src/lib/server/quote-pay.js +81 -4
  183. package/src/lib/server/quote-pay.js.map +1 -1
  184. package/src/lib/server/quote-proofs.d.ts +1 -1
  185. package/src/lib/server/quote-proofs.js +63 -19
  186. package/src/lib/server/quote-proofs.js.map +1 -1
  187. package/src/lib/server/quote.d.ts +12 -0
  188. package/src/lib/server/quote.js +69 -16
  189. package/src/lib/server/quote.js.map +1 -1
  190. package/src/lib/server/refund.js +3 -1
  191. package/src/lib/server/refund.js.map +1 -1
  192. package/src/lib/server/reserve-stock.js +9 -0
  193. package/src/lib/server/reserve-stock.js.map +1 -1
  194. package/src/lib/server/returns.js +15 -1
  195. package/src/lib/server/returns.js.map +1 -1
  196. package/src/lib/server/reviews.js +15 -0
  197. package/src/lib/server/reviews.js.map +1 -1
  198. package/src/lib/server/sold-out-drop.d.ts +58 -0
  199. package/src/lib/server/sold-out-drop.js +81 -0
  200. package/src/lib/server/sold-out-drop.js.map +1 -0
  201. package/src/lib/server/stock-levels.js +9 -0
  202. package/src/lib/server/stock-levels.js.map +1 -1
  203. package/src/lib/server/stripe-refund.d.ts +7 -0
  204. package/src/lib/server/stripe-refund.js +26 -7
  205. package/src/lib/server/stripe-refund.js.map +1 -1
  206. package/src/lib/server.d.ts +15 -0
  207. package/src/lib/server.js +30 -1
  208. package/src/lib/server.js.map +1 -1
  209. package/src/lib/tenant-emails.js +85 -2
  210. package/src/lib/tenant-emails.js.map +1 -1
  211. package/src/lib/testing/fake-seller-payment-account.d.ts +29 -0
  212. package/src/lib/testing/fake-seller-payment-account.js +40 -0
  213. package/src/lib/testing/fake-seller-payment-account.js.map +1 -0
  214. package/src/lib/transfer/product-transfer.js +6 -5
  215. package/src/lib/transfer/product-transfer.js.map +1 -1
  216. package/src/lib/transfer/products.server.js +4 -3
  217. package/src/lib/transfer/products.server.js.map +1 -1
  218. package/src/lib/utils/quote-email-content.d.ts +6 -0
  219. package/src/lib/utils/quote-email-content.js +6 -3
  220. package/src/lib/utils/quote-email-content.js.map +1 -1
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { type HostOrder } from './commerce-orders';
18
+ import { type QuoteEmailThread } from './commerce-quotes';
19
+ /** The catalog email a reply from the quote goes out as. */
20
+ export declare const QUOTE_MESSAGE_EMAIL_KEY = "quote-message";
21
+ /** The longest message either side may send. */
22
+ export declare const QUOTE_MESSAGE_MAX = 5000;
23
+ /** The most messages a page or the console lists, newest kept. */
24
+ export declare const QUOTE_MESSAGES_SHOWN = 50;
25
+ /** One message in a quote's conversation, as stored. */
26
+ export interface QuoteMessage {
27
+ direction: 'out' | 'in';
28
+ body: string;
29
+ atMs: number;
30
+ /** The revision the quote was on when it was said. */
31
+ revision: number;
32
+ /** With `out`: who on the team sent it, an email else a uid. */
33
+ by?: string;
34
+ /** With `out`: the address it went to. */
35
+ to?: string;
36
+ /** With `out`: the `Message-ID` it was sent with, and the provider's own id. */
37
+ messageId?: string;
38
+ providerId?: string | null;
39
+ /** With `in`: the name on the quote when the customer wrote. */
40
+ name?: string;
41
+ /** With `in`: the address and browser it came from, kept as the record. */
42
+ ip?: string | null;
43
+ userAgent?: string | null;
44
+ }
45
+ /** A message as typed, trimmed, or what to fix. */
46
+ export declare function parseQuoteMessageBody(raw: unknown): {
47
+ ok: true;
48
+ body: string;
49
+ } | {
50
+ ok: false;
51
+ error: string;
52
+ };
53
+ /** Who a reply from the quote goes to: the customer's email, else where the quote was last emailed. */
54
+ export declare function quoteReplyRecipient(order: Pick<HostOrder, 'quote'> | null | undefined): string;
55
+ export type QuoteReplyRefusal = 'not-a-quote' | 'no-address' | 'bad-address';
56
+ /** Why the business cannot reply to the quote's customer now, if it cannot. A paid quote still takes replies. */
57
+ export declare function quoteReplyRefusal(order: Pick<HostOrder, 'channel' | 'quote'> | null | undefined): QuoteReplyRefusal | null;
58
+ export declare function quoteReplyRefusalMessage(reason: QuoteReplyRefusal): string;
59
+ /**
60
+ * The quote after a reply went out: the conversation moved on to it, so the
61
+ * next email answers it, and the timeline says who wrote to whom. Nothing the
62
+ * customer sees changes, so the quote's edit stamp stays.
63
+ */
64
+ export declare function quoteAfterReply(order: HostOrder, sent: {
65
+ to: string;
66
+ by: string;
67
+ atMs: number;
68
+ }, thread: QuoteEmailThread): HostOrder;
69
+ /** A message as the customer's page shows it: who said it and what, never an address, browser or team member. */
70
+ export interface QuotePageMessage {
71
+ id: string;
72
+ from: 'business' | 'customer';
73
+ body: string;
74
+ atMs: number;
75
+ }
76
+ /** The stored messages, oldest first, as the page may show them. */
77
+ export declare function quotePageMessages(entries: ReadonlyArray<{
78
+ id: string;
79
+ data: Partial<QuoteMessage> | undefined;
80
+ }>): QuotePageMessage[];
81
+ /** A message as the console lists it. */
82
+ export interface QuoteConsoleMessage {
83
+ id: string;
84
+ direction: 'out' | 'in';
85
+ body: string;
86
+ atMs: number;
87
+ /** `to jordan@example.com by sam@shop.test`, or `Jordan Lee wrote on the quote page`. */
88
+ label: string;
89
+ }
90
+ /** The stored messages, oldest first, as the team reads them. */
91
+ export declare function quoteConsoleMessages(entries: ReadonlyArray<{
92
+ id: string;
93
+ data: Partial<QuoteMessage> | undefined;
94
+ }>): QuoteConsoleMessage[];
95
+ /** The reply email's words (the `quote-message` catalog email), and its plain-text twin. */
96
+ export declare function quoteMessageEmailTokens(input: {
97
+ order: HostOrder;
98
+ quoteId: string;
99
+ businessName: string;
100
+ subject: string;
101
+ body: string;
102
+ url: string;
103
+ }): {
104
+ tokens: Record<string, string>;
105
+ text: string;
106
+ };
@@ -0,0 +1,146 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2026 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ import { appendOrderEvent } from "./commerce-orders.js";
18
+ import { quoteSendPrefill } from "./commerce-quote-email.js";
19
+ import { formatQuoteNumber, isQuote, quoteIsProofOnly } from "./commerce-quotes.js";
20
+ /*==========================================
21
+ * A QUOTE'S CONVERSATION (AGL-4207): what the business and its customer say
22
+ * to each other about one quote, kept under it at
23
+ * `hosts/{hostId}/orders/{quoteId}/messages/{id}`, so it stays through every
24
+ * revision and after the quote is paid.
25
+ *
26
+ * - `out`: a reply the business sent from the quote. It went by email, in
27
+ * the quote's own conversation in the customer's mailbox
28
+ * (`quote.emailThread`), under the `quote-message` catalog email.
29
+ * - `in`: what the customer wrote on the quote page. The business is told
30
+ * in Aglyn and by email.
31
+ *
32
+ * Nothing receives mail: a customer who answers an email reaches the
33
+ * business's own mailbox (its Reply-To), as an Inbox reply's answer does.
34
+ *=========================================*/ /** The catalog email a reply from the quote goes out as. */ export const QUOTE_MESSAGE_EMAIL_KEY = 'quote-message';
35
+ /** The longest message either side may send. */ export const QUOTE_MESSAGE_MAX = 5000;
36
+ /** The most messages a page or the console lists, newest kept. */ export const QUOTE_MESSAGES_SHOWN = 50;
37
+ /** A message as typed, trimmed, or what to fix. */ export function parseQuoteMessageBody(raw) {
38
+ const body = typeof raw === 'string' ? raw.replace(/\r\n/g, '\n').trim() : '';
39
+ if (!body) return {
40
+ ok: false,
41
+ error: 'Write a message first.'
42
+ };
43
+ if (body.length > QUOTE_MESSAGE_MAX) return {
44
+ ok: false,
45
+ error: `A message holds up to ${QUOTE_MESSAGE_MAX.toLocaleString('en-US')} characters.`
46
+ };
47
+ return {
48
+ ok: true,
49
+ body
50
+ };
51
+ }
52
+ /** Who a reply from the quote goes to: the customer's email, else where the quote was last emailed. */ export function quoteReplyRecipient(order) {
53
+ return quoteSendPrefill(order);
54
+ }
55
+ /** Why the business cannot reply to the quote's customer now, if it cannot. A paid quote still takes replies. */ export function quoteReplyRefusal(order) {
56
+ if (!order || !isQuote(order) || !order.quote) return 'not-a-quote';
57
+ const to = quoteReplyRecipient(order);
58
+ if (!to) return 'no-address';
59
+ if (to.length > 320 || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(to)) return 'bad-address';
60
+ return null;
61
+ }
62
+ export function quoteReplyRefusalMessage(reason) {
63
+ switch(reason){
64
+ case 'not-a-quote':
65
+ return 'Unknown quote';
66
+ case 'no-address':
67
+ return 'This quote has no customer email, so there is nobody to reply to. Add their email to the quote first.';
68
+ case 'bad-address':
69
+ return 'The customer email on this quote isn’t a valid address. Fix it on the quote first.';
70
+ }
71
+ }
72
+ /**
73
+ * The quote after a reply went out: the conversation moved on to it, so the
74
+ * next email answers it, and the timeline says who wrote to whom. Nothing the
75
+ * customer sees changes, so the quote's edit stamp stays.
76
+ */ export function quoteAfterReply(order, sent, thread) {
77
+ return _extends({}, order, {
78
+ timeline: appendOrderEvent(order, 'quote-message-sent', `Reply emailed to ${sent.to} by ${sent.by}`, sent.atMs),
79
+ quote: _extends({}, order.quote, {
80
+ emailThread: thread
81
+ })
82
+ });
83
+ }
84
+ /** The stored messages, oldest first, as the page may show them. */ export function quotePageMessages(entries) {
85
+ return entries.filter((entry)=>{
86
+ var _entry_data;
87
+ return typeof ((_entry_data = entry.data) == null ? void 0 : _entry_data.body) === 'string' && (entry.data.direction === 'out' || entry.data.direction === 'in');
88
+ }).map((entry)=>{
89
+ var _entry_data, _entry_data1, _entry_data2;
90
+ return {
91
+ id: entry.id,
92
+ from: ((_entry_data = entry.data) == null ? void 0 : _entry_data.direction) === 'out' ? 'business' : 'customer',
93
+ body: String((_entry_data1 = entry.data) == null ? void 0 : _entry_data1.body),
94
+ atMs: Number((_entry_data2 = entry.data) == null ? void 0 : _entry_data2.atMs) || 0
95
+ };
96
+ }).sort((a, b)=>a.atMs - b.atMs);
97
+ }
98
+ /** The stored messages, oldest first, as the team reads them. */ export function quoteConsoleMessages(entries) {
99
+ return entries.filter((entry)=>{
100
+ var _entry_data;
101
+ return typeof ((_entry_data = entry.data) == null ? void 0 : _entry_data.body) === 'string' && (entry.data.direction === 'out' || entry.data.direction === 'in');
102
+ }).map((entry)=>{
103
+ const data = entry.data;
104
+ const label = data.direction === 'out' ? `Sent to ${data.to || 'the customer'}${data.by ? ` by ${data.by}` : ''}` : `${data.name || 'The customer'} wrote on the quote page`;
105
+ return {
106
+ id: entry.id,
107
+ direction: data.direction,
108
+ body: data.body,
109
+ atMs: Number(data.atMs) || 0,
110
+ label
111
+ };
112
+ }).sort((a, b)=>a.atMs - b.atMs);
113
+ }
114
+ /** The reply email's words (the `quote-message` catalog email), and its plain-text twin. */ export function quoteMessageEmailTokens(input) {
115
+ var _input_order_quote, _quote_revision;
116
+ const quote = (_input_order_quote = input.order.quote) != null ? _input_order_quote : {};
117
+ const proofOnly = quoteIsProofOnly(input.order);
118
+ const label = proofOnly ? 'Proof' : 'Quote';
119
+ const noun = proofOnly ? 'proof' : 'quote';
120
+ const number = formatQuoteNumber(input.order, input.quoteId).replace(/^Quote\s+/, '');
121
+ const business = input.businessName.trim() || 'the business';
122
+ const heading = `A message about your ${noun}`;
123
+ const tokens = {
124
+ 'message.subject': input.subject,
125
+ 'quote.label': label,
126
+ 'quote.number': number,
127
+ 'quote.revision': String(Math.max(1, Number((_quote_revision = quote.revision) != null ? _quote_revision : 1) || 1)),
128
+ 'message.heading': heading,
129
+ 'message.body': input.body,
130
+ 'message.buttonLabel': `View your ${noun}`,
131
+ 'quote.url': input.url
132
+ };
133
+ const text = [
134
+ heading,
135
+ input.body,
136
+ `${label}: ${number}`,
137
+ `View your ${noun}: ${input.url}`,
138
+ `Reply to this email to reach ${business}, or answer on your ${noun} page.`
139
+ ].join('\n\n');
140
+ return {
141
+ tokens,
142
+ text
143
+ };
144
+ }
145
+
146
+ //# sourceMappingURL=commerce-quote-messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-quote-messages.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { appendOrderEvent, type HostOrder } from './commerce-orders'\nimport { quoteSendPrefill } from './commerce-quote-email'\nimport { formatQuoteNumber, isQuote, quoteIsProofOnly, type OrderQuote, type QuoteEmailThread } from './commerce-quotes'\n\n/*==========================================\n * A QUOTE'S CONVERSATION (AGL-4207): what the business and its customer say\n * to each other about one quote, kept under it at\n * `hosts/{hostId}/orders/{quoteId}/messages/{id}`, so it stays through every\n * revision and after the quote is paid.\n *\n * - `out`: a reply the business sent from the quote. It went by email, in\n * the quote's own conversation in the customer's mailbox\n * (`quote.emailThread`), under the `quote-message` catalog email.\n * - `in`: what the customer wrote on the quote page. The business is told\n * in Aglyn and by email.\n *\n * Nothing receives mail: a customer who answers an email reaches the\n * business's own mailbox (its Reply-To), as an Inbox reply's answer does.\n *=========================================*/\n\n/** The catalog email a reply from the quote goes out as. */\nexport const QUOTE_MESSAGE_EMAIL_KEY = 'quote-message'\n\n/** The longest message either side may send. */\nexport const QUOTE_MESSAGE_MAX = 5_000\n\n/** The most messages a page or the console lists, newest kept. */\nexport const QUOTE_MESSAGES_SHOWN = 50\n\n/** One message in a quote's conversation, as stored. */\nexport interface QuoteMessage {\n direction: 'out' | 'in'\n body: string\n atMs: number\n /** The revision the quote was on when it was said. */\n revision: number\n /** With `out`: who on the team sent it, an email else a uid. */\n by?: string\n /** With `out`: the address it went to. */\n to?: string\n /** With `out`: the `Message-ID` it was sent with, and the provider's own id. */\n messageId?: string\n providerId?: string | null\n /** With `in`: the name on the quote when the customer wrote. */\n name?: string\n /** With `in`: the address and browser it came from, kept as the record. */\n ip?: string | null\n userAgent?: string | null\n}\n\n/** A message as typed, trimmed, or what to fix. */\nexport function parseQuoteMessageBody(raw: unknown): { ok: true; body: string } | { ok: false; error: string } {\n const body = typeof raw === 'string' ? raw.replace(/\\r\\n/g, '\\n').trim() : ''\n if (!body) return { ok: false, error: 'Write a message first.' }\n if (body.length > QUOTE_MESSAGE_MAX) return { ok: false, error: `A message holds up to ${QUOTE_MESSAGE_MAX.toLocaleString('en-US')} characters.` }\n return { ok: true, body }\n}\n\n/** Who a reply from the quote goes to: the customer's email, else where the quote was last emailed. */\nexport function quoteReplyRecipient(order: Pick<HostOrder, 'quote'> | null | undefined): string {\n return quoteSendPrefill(order)\n}\n\nexport type QuoteReplyRefusal = 'not-a-quote' | 'no-address' | 'bad-address'\n\n/** Why the business cannot reply to the quote's customer now, if it cannot. A paid quote still takes replies. */\nexport function quoteReplyRefusal(order: Pick<HostOrder, 'channel' | 'quote'> | null | undefined): QuoteReplyRefusal | null {\n if (!order || !isQuote(order) || !order.quote) return 'not-a-quote'\n const to = quoteReplyRecipient(order)\n if (!to) return 'no-address'\n if (to.length > 320 || !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(to)) return 'bad-address'\n return null\n}\n\nexport function quoteReplyRefusalMessage(reason: QuoteReplyRefusal): string {\n switch (reason) {\n case 'not-a-quote':\n return 'Unknown quote'\n case 'no-address':\n return 'This quote has no customer email, so there is nobody to reply to. Add their email to the quote first.'\n case 'bad-address':\n return 'The customer email on this quote isn’t a valid address. Fix it on the quote first.'\n }\n}\n\n/**\n * The quote after a reply went out: the conversation moved on to it, so the\n * next email answers it, and the timeline says who wrote to whom. Nothing the\n * customer sees changes, so the quote's edit stamp stays.\n */\nexport function quoteAfterReply(\n order: HostOrder,\n sent: { to: string; by: string; atMs: number },\n thread: QuoteEmailThread,\n): HostOrder {\n return {\n ...order,\n timeline: appendOrderEvent(order, 'quote-message-sent', `Reply emailed to ${sent.to} by ${sent.by}`, sent.atMs),\n quote: { ...(order.quote as OrderQuote), emailThread: thread },\n }\n}\n\n/** A message as the customer's page shows it: who said it and what, never an address, browser or team member. */\nexport interface QuotePageMessage {\n id: string\n from: 'business' | 'customer'\n body: string\n atMs: number\n}\n\n/** The stored messages, oldest first, as the page may show them. */\nexport function quotePageMessages(entries: ReadonlyArray<{ id: string; data: Partial<QuoteMessage> | undefined }>): QuotePageMessage[] {\n return entries\n .filter((entry) => typeof entry.data?.body === 'string' && (entry.data.direction === 'out' || entry.data.direction === 'in'))\n .map((entry) => ({\n id: entry.id,\n from: entry.data?.direction === 'out' ? ('business' as const) : ('customer' as const),\n body: String(entry.data?.body),\n atMs: Number(entry.data?.atMs) || 0,\n }))\n .sort((a, b) => a.atMs - b.atMs)\n}\n\n/** A message as the console lists it. */\nexport interface QuoteConsoleMessage {\n id: string\n direction: 'out' | 'in'\n body: string\n atMs: number\n /** `to jordan@example.com by sam@shop.test`, or `Jordan Lee wrote on the quote page`. */\n label: string\n}\n\n/** The stored messages, oldest first, as the team reads them. */\nexport function quoteConsoleMessages(entries: ReadonlyArray<{ id: string; data: Partial<QuoteMessage> | undefined }>): QuoteConsoleMessage[] {\n return entries\n .filter((entry) => typeof entry.data?.body === 'string' && (entry.data.direction === 'out' || entry.data.direction === 'in'))\n .map((entry) => {\n const data = entry.data as QuoteMessage\n const label =\n data.direction === 'out'\n ? `Sent to ${data.to || 'the customer'}${data.by ? ` by ${data.by}` : ''}`\n : `${data.name || 'The customer'} wrote on the quote page`\n return { id: entry.id, direction: data.direction, body: data.body, atMs: Number(data.atMs) || 0, label }\n })\n .sort((a, b) => a.atMs - b.atMs)\n}\n\n/** The reply email's words (the `quote-message` catalog email), and its plain-text twin. */\nexport function quoteMessageEmailTokens(input: {\n order: HostOrder\n quoteId: string\n businessName: string\n subject: string\n body: string\n url: string\n}): { tokens: Record<string, string>; text: string } {\n const quote = (input.order.quote ?? {}) as OrderQuote\n const proofOnly = quoteIsProofOnly(input.order)\n const label = proofOnly ? 'Proof' : 'Quote'\n const noun = proofOnly ? 'proof' : 'quote'\n const number = formatQuoteNumber(input.order, input.quoteId).replace(/^Quote\\s+/, '')\n const business = input.businessName.trim() || 'the business'\n const heading = `A message about your ${noun}`\n const tokens: Record<string, string> = {\n 'message.subject': input.subject,\n 'quote.label': label,\n 'quote.number': number,\n 'quote.revision': String(Math.max(1, Number(quote.revision ?? 1) || 1)),\n 'message.heading': heading,\n 'message.body': input.body,\n 'message.buttonLabel': `View your ${noun}`,\n 'quote.url': input.url,\n }\n const text = [\n heading,\n input.body,\n `${label}: ${number}`,\n `View your ${noun}: ${input.url}`,\n `Reply to this email to reach ${business}, or answer on your ${noun} page.`,\n ].join('\\n\\n')\n return { tokens, text }\n}\n"],"names":["appendOrderEvent","quoteSendPrefill","formatQuoteNumber","isQuote","quoteIsProofOnly","QUOTE_MESSAGE_EMAIL_KEY","QUOTE_MESSAGE_MAX","QUOTE_MESSAGES_SHOWN","parseQuoteMessageBody","raw","body","replace","trim","ok","error","length","toLocaleString","quoteReplyRecipient","order","quoteReplyRefusal","quote","to","test","quoteReplyRefusalMessage","reason","quoteAfterReply","sent","thread","timeline","by","atMs","emailThread","quotePageMessages","entries","filter","entry","data","direction","map","id","from","String","Number","sort","a","b","quoteConsoleMessages","label","name","quoteMessageEmailTokens","input","proofOnly","noun","number","quoteId","business","businessName","heading","tokens","subject","Math","max","revision","url","text","join"],"mappings":"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"}
@@ -17,6 +17,8 @@
17
17
  import type { ProductType } from './commerce';
18
18
  import { type HostOrder, type OrderAddress, type OrderLineItem, type OrderStatus } from './commerce-orders';
19
19
  import { type OrderQuote, type QuoteDiscount, type QuoteTaxBasis, type QuoteUnmatchedPayment } from './commerce-quotes';
20
+ import { type QuoteProofAccess } from './commerce-quote-proofs';
21
+ import type { QuotePageMessage } from './commerce-quote-messages';
20
22
  import type { TaxSettings } from './commerce-tax';
21
23
  import { type StorefrontTaxMode } from './commerce-tax-decision';
22
24
  import { type OrderListFields } from './order-list-fields';
@@ -129,11 +131,13 @@ export interface QuotePageProof {
129
131
  export interface QuotePageResponse {
130
132
  action: 'approve' | 'changes';
131
133
  atMs: number;
132
- /** With an approval: the name it was given under. */
134
+ /** The name it was given under: an approval's, or a rejection's (AGL-4206). */
133
135
  name: string | null;
134
136
  comment: string | null;
135
137
  /** How many files came with it. */
136
138
  files: number;
139
+ /** With an approval: what they ticked before approving (AGL-4206). */
140
+ confirmed: string[];
137
141
  }
138
142
  /**
139
143
  * What the quote page shows. Allow-listed, never spread: the order document
@@ -219,8 +223,27 @@ export interface QuotePageView {
219
223
  proofs: QuotePageProof[];
220
224
  /** The customer's latest answer to it, if any. */
221
225
  response: QuotePageResponse | null;
222
- /** Approve and Request changes belong on the page. */
226
+ /** Approve and Reject with changes belong on the page. */
223
227
  respondable: boolean;
228
+ /**
229
+ * What the customer ticks before Approve works (AGL-4206), word for word;
230
+ * Approve sends them back. Empty when the page takes no answer.
231
+ */
232
+ approvalStatements: string[];
233
+ /**
234
+ * Whether this browser may see the proof (AGL-4206): `open`, or a sign-in
235
+ * the quote waits on. While it waits the view carries no proofs, no answer
236
+ * and nothing to respond with, and `proofAccessMessage` says what to do.
237
+ */
238
+ proofAccess: QuoteProofAccess;
239
+ proofAccessMessage: string | null;
240
+ /**
241
+ * The quote's conversation with the business, oldest first (AGL-4207):
242
+ * what each side wrote, never an address or who on the team sent it. The
243
+ * customer writes back on the page. Empty for an invoice, and while the
244
+ * proof waits on a sign-in.
245
+ */
246
+ messages: QuotePageMessage[];
224
247
  }
225
248
  /** What a signed link for an older version of the quote opens: nothing of the quote. */
226
249
  export interface QuotePageReplacedView {
@@ -253,6 +276,12 @@ export declare function buildQuotePageView(input: {
253
276
  store?: PayLinkStore | null;
254
277
  /** Whether the business can take a card payment now; absent, it is not judged here. */
255
278
  paymentsReady?: boolean;
279
+ /** What the customer ticks before approving: the store's {@link quoteApprovalStatements}. */
280
+ approvalStatements?: readonly string[];
281
+ /** Whether this browser may see the proof ({@link quoteProofAccess}); absent reads as `open`. */
282
+ proofAccess?: QuoteProofAccess;
283
+ /** The quote's conversation ({@link quotePageMessages}); absent, none is shown. */
284
+ messages?: QuotePageMessage[];
256
285
  }): QuotePageView;
257
286
  /** Order lines as the pay link's page lists them: what each charges, nothing about stock or cost. */
258
287
  export declare function quotePageLines(lines: readonly OrderLineItem[]): QuotePageLine[];
@@ -16,8 +16,8 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
16
16
  * limitations under the License.
17
17
  */ import { visitorUploadIsInline } from "@aglyn/aglyn/app-utils/visitor-upload";
18
18
  import { appendOrderEvent, formatOrderNumber } from "./commerce-orders.js";
19
- import { computeQuoteTotals, describeQuoteTax, formatProofNumber, formatQuoteNumber, quoteIsProofOnly, quoteLineAmounts, quotePaymentBlockedByApproval, quoteTaxBasisFromSettings } from "./commerce-quotes.js";
20
- import { currentQuoteProofs, latestQuoteResponse, quoteRespondRefusal } from "./commerce-quote-proofs.js";
19
+ import { computeQuoteTotals, describeQuoteTax, formatProofNumber, formatQuoteNumber, QUOTE_DEFAULT_APPROVAL_STATEMENTS, quoteIsProofOnly, quoteLineAmounts, quotePaymentBlockedByApproval, quoteTaxBasisFromSettings } from "./commerce-quotes.js";
20
+ import { currentQuoteProofs, latestQuoteResponse, quoteProofAccessMessage, quoteRespondRefusal } from "./commerce-quote-proofs.js";
21
21
  import { storefrontTaxDecision } from "./commerce-tax-decision.js";
22
22
  import { engineLineTaxPercentages, storeTaxAllowsEngine } from "./commerce-tax-engine.js";
23
23
  import { withOrderListFields } from "./order-list-fields.js";
@@ -247,7 +247,7 @@ function discountLabel(discount) {
247
247
  * only when nothing would refuse it: the store's payments included, when the
248
248
  * caller says whether it can take them.
249
249
  */ export function buildQuotePageView(input) {
250
- var _order_lineItems, _ref, _text, _input_receiptUrl, _ref1;
250
+ var _order_lineItems, _ref, _text, _input_receiptUrl, _ref1, _input_messages, _input_approvalStatements, _input_proofAccess;
251
251
  var _quote_customer, _quote_customer1, _quote_customer2, _quote_customer3;
252
252
  const { order } = input;
253
253
  const quote = order.quote;
@@ -280,7 +280,7 @@ function discountLabel(discount) {
280
280
  const approvalRequired = unpaid && !proofOnly && quotePaymentBlockedByApproval(quote);
281
281
  const taxAtPayment = unpaid && !proofOnly && payTax.basis.kind === 'at-payment';
282
282
  const refused = unpaid ? payLinkRefusalWithPayments(quotePayRefusal(order, input.orderId, input.store), input.paymentsReady) : null;
283
- return {
283
+ const view = {
284
284
  state: 'quote',
285
285
  kind: 'quote',
286
286
  proofOnly,
@@ -327,8 +327,31 @@ function discountLabel(discount) {
327
327
  channel: 'quote',
328
328
  status: order.status,
329
329
  quote
330
- }) === null
330
+ }) === null,
331
+ messages: (_input_messages = input.messages) != null ? _input_messages : [],
332
+ approvalStatements: [],
333
+ proofAccess: 'open',
334
+ proofAccessMessage: null
331
335
  };
336
+ const page = _extends({}, view, {
337
+ approvalStatements: view.respondable ? [
338
+ ...(_input_approvalStatements = input.approvalStatements) != null ? _input_approvalStatements : QUOTE_DEFAULT_APPROVAL_STATEMENTS
339
+ ] : []
340
+ });
341
+ const access = (_input_proofAccess = input.proofAccess) != null ? _input_proofAccess : 'open';
342
+ // A revision with no proof has nothing to sign in for.
343
+ if (access === 'open' || page.proofs.length === 0) return page;
344
+ // Waiting on a sign-in, the view carries nothing of the proof or the answer.
345
+ return _extends({}, page, {
346
+ proofs: [],
347
+ response: null,
348
+ respondable: false,
349
+ // The conversation is about the proof, so it waits on the same sign-in (AGL-4207).
350
+ messages: [],
351
+ approvalStatements: [],
352
+ proofAccess: access,
353
+ proofAccessMessage: quoteProofAccessMessage(access, input.storeName)
354
+ });
332
355
  }
333
356
  /** Order lines as the pay link's page lists them: what each charges, nothing about stock or cost. */ export function quotePageLines(lines) {
334
357
  return lines.map((line)=>{
@@ -356,9 +379,10 @@ function discountLabel(discount) {
356
379
  return {
357
380
  action: latest.action === 'approve' ? 'approve' : 'changes',
358
381
  atMs: Number(latest.atMs) || 0,
359
- name: latest.action === 'approve' ? text(latest.name) : null,
382
+ name: text(latest.name),
360
383
  comment: latest.action === 'changes' ? text(latest.comment) : null,
361
- files: (_ref = (_latest_files = latest.files) == null ? void 0 : _latest_files.length) != null ? _ref : 0
384
+ files: (_ref = (_latest_files = latest.files) == null ? void 0 : _latest_files.length) != null ? _ref : 0,
385
+ confirmed: latest.action === 'approve' && Array.isArray(latest.confirmed) ? latest.confirmed.map(String) : []
362
386
  };
363
387
  }
364
388
  const LINE_DESCRIPTION_MAX = 500;