@endora-commerce/contracts 0.108.0 → 0.109.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 (199) hide show
  1. package/dist/admin-actions.d.ts +12 -3
  2. package/dist/admin-actions.d.ts.map +1 -1
  3. package/dist/admin-actions.js +34 -3
  4. package/dist/admin-actions.js.map +1 -1
  5. package/dist/admin-contributions.d.ts +35 -6
  6. package/dist/admin-contributions.d.ts.map +1 -1
  7. package/dist/admin-contributions.js +46 -0
  8. package/dist/admin-contributions.js.map +1 -1
  9. package/dist/admin-notifications.d.ts +17 -1
  10. package/dist/admin-notifications.d.ts.map +1 -1
  11. package/dist/admin-preferences.d.ts +108 -0
  12. package/dist/admin-preferences.d.ts.map +1 -0
  13. package/dist/admin-preferences.js +133 -0
  14. package/dist/admin-preferences.js.map +1 -0
  15. package/dist/admin.d.ts +15 -1
  16. package/dist/admin.d.ts.map +1 -1
  17. package/dist/admin.js +7 -0
  18. package/dist/admin.js.map +1 -1
  19. package/dist/assets-library.d.ts +97 -3
  20. package/dist/assets-library.d.ts.map +1 -1
  21. package/dist/assets-library.js +5 -0
  22. package/dist/assets-library.js.map +1 -1
  23. package/dist/blog.d.ts +57 -0
  24. package/dist/blog.d.ts.map +1 -1
  25. package/dist/blog.js +63 -1
  26. package/dist/blog.js.map +1 -1
  27. package/dist/carts.d.ts +113 -56
  28. package/dist/carts.d.ts.map +1 -1
  29. package/dist/carts.js +66 -13
  30. package/dist/carts.js.map +1 -1
  31. package/dist/catalog.d.ts +273 -34
  32. package/dist/catalog.d.ts.map +1 -1
  33. package/dist/catalog.js +256 -20
  34. package/dist/catalog.js.map +1 -1
  35. package/dist/cms-brand.d.ts +2233 -0
  36. package/dist/cms-brand.d.ts.map +1 -0
  37. package/dist/cms-brand.js +311 -0
  38. package/dist/cms-brand.js.map +1 -0
  39. package/dist/cms-contact-form.d.ts +55 -0
  40. package/dist/cms-contact-form.d.ts.map +1 -0
  41. package/dist/cms-contact-form.js +100 -0
  42. package/dist/cms-contact-form.js.map +1 -0
  43. package/dist/cms.d.ts +537 -3
  44. package/dist/cms.d.ts.map +1 -1
  45. package/dist/cms.js +251 -0
  46. package/dist/cms.js.map +1 -1
  47. package/dist/crm-rich-text.d.ts +10 -61
  48. package/dist/crm-rich-text.d.ts.map +1 -1
  49. package/dist/crm-rich-text.js +10 -300
  50. package/dist/crm-rich-text.js.map +1 -1
  51. package/dist/crm.d.ts +110 -82
  52. package/dist/crm.d.ts.map +1 -1
  53. package/dist/crm.js +29 -88
  54. package/dist/crm.js.map +1 -1
  55. package/dist/custom-fields.d.ts +27 -9
  56. package/dist/custom-fields.d.ts.map +1 -1
  57. package/dist/custom-fields.js +6 -0
  58. package/dist/custom-fields.js.map +1 -1
  59. package/dist/customer-accounts.d.ts +30 -0
  60. package/dist/customer-accounts.d.ts.map +1 -1
  61. package/dist/customer-accounts.js +31 -0
  62. package/dist/customer-accounts.js.map +1 -1
  63. package/dist/document-templates.d.ts +27 -15
  64. package/dist/document-templates.d.ts.map +1 -1
  65. package/dist/document-values.d.ts +8 -0
  66. package/dist/document-values.d.ts.map +1 -1
  67. package/dist/document-values.js +24 -6
  68. package/dist/document-values.js.map +1 -1
  69. package/dist/email.d.ts +5 -0
  70. package/dist/email.d.ts.map +1 -1
  71. package/dist/errors.d.ts +105 -0
  72. package/dist/errors.d.ts.map +1 -1
  73. package/dist/errors.js +123 -0
  74. package/dist/errors.js.map +1 -1
  75. package/dist/index.d.ts +13 -1
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +27 -1
  78. package/dist/index.js.map +1 -1
  79. package/dist/inventory.d.ts +3 -3
  80. package/dist/invoices.d.ts +6 -2
  81. package/dist/invoices.d.ts.map +1 -1
  82. package/dist/invoices.js +3 -0
  83. package/dist/invoices.js.map +1 -1
  84. package/dist/megamenu.d.ts +674 -0
  85. package/dist/megamenu.d.ts.map +1 -1
  86. package/dist/megamenu.js +96 -3
  87. package/dist/megamenu.js.map +1 -1
  88. package/dist/mfa.d.ts +1 -0
  89. package/dist/mfa.d.ts.map +1 -1
  90. package/dist/mfa.js +8 -2
  91. package/dist/mfa.js.map +1 -1
  92. package/dist/modules.d.ts +8 -1
  93. package/dist/modules.d.ts.map +1 -1
  94. package/dist/modules.js +5 -0
  95. package/dist/modules.js.map +1 -1
  96. package/dist/newsletter.d.ts +3 -3
  97. package/dist/orders.d.ts +25 -0
  98. package/dist/orders.d.ts.map +1 -1
  99. package/dist/orders.js +14 -0
  100. package/dist/orders.js.map +1 -1
  101. package/dist/page-builder-props.d.ts +1401 -0
  102. package/dist/page-builder-props.d.ts.map +1 -0
  103. package/dist/page-builder-props.js +266 -0
  104. package/dist/page-builder-props.js.map +1 -0
  105. package/dist/page-builder-values.d.ts +95 -0
  106. package/dist/page-builder-values.d.ts.map +1 -0
  107. package/dist/page-builder-values.js +164 -0
  108. package/dist/page-builder-values.js.map +1 -0
  109. package/dist/pim-connector.d.ts +1 -1
  110. package/dist/platform-language.d.ts +9 -0
  111. package/dist/platform-language.d.ts.map +1 -1
  112. package/dist/platform-language.js +14 -0
  113. package/dist/platform-language.js.map +1 -1
  114. package/dist/price-books.d.ts +60 -60
  115. package/dist/price-lists.d.ts +44 -10
  116. package/dist/price-lists.d.ts.map +1 -1
  117. package/dist/price-lists.js +24 -1
  118. package/dist/price-lists.js.map +1 -1
  119. package/dist/product-feeds.d.ts +115 -55
  120. package/dist/product-feeds.d.ts.map +1 -1
  121. package/dist/product-feeds.js +18 -0
  122. package/dist/product-feeds.js.map +1 -1
  123. package/dist/product-scopes.d.ts +628 -0
  124. package/dist/product-scopes.d.ts.map +1 -0
  125. package/dist/product-scopes.js +365 -0
  126. package/dist/product-scopes.js.map +1 -0
  127. package/dist/product-summary-text.d.ts +23 -0
  128. package/dist/product-summary-text.d.ts.map +1 -0
  129. package/dist/product-summary-text.js +64 -0
  130. package/dist/product-summary-text.js.map +1 -0
  131. package/dist/product-url-keys.d.ts +204 -0
  132. package/dist/product-url-keys.d.ts.map +1 -0
  133. package/dist/product-url-keys.js +166 -0
  134. package/dist/product-url-keys.js.map +1 -0
  135. package/dist/projects.d.ts +2355 -0
  136. package/dist/projects.d.ts.map +1 -0
  137. package/dist/projects.js +837 -0
  138. package/dist/projects.js.map +1 -0
  139. package/dist/prompt-actions.d.ts +19 -1
  140. package/dist/prompt-actions.d.ts.map +1 -1
  141. package/dist/prompt-actions.js +31 -2
  142. package/dist/prompt-actions.js.map +1 -1
  143. package/dist/quick-order.d.ts +0 -1
  144. package/dist/quick-order.d.ts.map +1 -1
  145. package/dist/quick-order.js +1 -1
  146. package/dist/quick-order.js.map +1 -1
  147. package/dist/quote-requests.d.ts +36 -1
  148. package/dist/quote-requests.d.ts.map +1 -1
  149. package/dist/quote-requests.js +24 -0
  150. package/dist/quote-requests.js.map +1 -1
  151. package/dist/record-references.d.ts +252 -0
  152. package/dist/record-references.d.ts.map +1 -0
  153. package/dist/record-references.js +179 -0
  154. package/dist/record-references.js.map +1 -0
  155. package/dist/record-rich-text.d.ts +66 -0
  156. package/dist/record-rich-text.d.ts.map +1 -0
  157. package/dist/record-rich-text.js +303 -0
  158. package/dist/record-rich-text.js.map +1 -0
  159. package/dist/returns.d.ts +26 -0
  160. package/dist/returns.d.ts.map +1 -1
  161. package/dist/sales-channels.d.ts +51 -7
  162. package/dist/sales-channels.d.ts.map +1 -1
  163. package/dist/sales-channels.js +38 -4
  164. package/dist/sales-channels.js.map +1 -1
  165. package/dist/saved-list-views.d.ts +28 -0
  166. package/dist/saved-list-views.d.ts.map +1 -1
  167. package/dist/saved-list-views.js +14 -1
  168. package/dist/saved-list-views.js.map +1 -1
  169. package/dist/scoped-translations.d.ts +48 -0
  170. package/dist/scoped-translations.d.ts.map +1 -0
  171. package/dist/scoped-translations.js +78 -0
  172. package/dist/scoped-translations.js.map +1 -0
  173. package/dist/search.d.ts +15 -7
  174. package/dist/search.d.ts.map +1 -1
  175. package/dist/seo.d.ts +64 -5
  176. package/dist/seo.d.ts.map +1 -1
  177. package/dist/seo.js +31 -4
  178. package/dist/seo.js.map +1 -1
  179. package/dist/settings.d.ts +32 -3
  180. package/dist/settings.d.ts.map +1 -1
  181. package/dist/settings.js +37 -3
  182. package/dist/settings.js.map +1 -1
  183. package/dist/storefront-cache-tags.d.ts +29 -0
  184. package/dist/storefront-cache-tags.d.ts.map +1 -1
  185. package/dist/storefront-cache-tags.js +24 -0
  186. package/dist/storefront-cache-tags.js.map +1 -1
  187. package/dist/storefront-language-path.d.ts +77 -0
  188. package/dist/storefront-language-path.d.ts.map +1 -0
  189. package/dist/storefront-language-path.js +123 -0
  190. package/dist/storefront-language-path.js.map +1 -0
  191. package/dist/tasks.d.ts +2842 -0
  192. package/dist/tasks.d.ts.map +1 -0
  193. package/dist/tasks.js +901 -0
  194. package/dist/tasks.js.map +1 -0
  195. package/dist/transactional-emails.d.ts +7 -4
  196. package/dist/transactional-emails.d.ts.map +1 -1
  197. package/dist/transactional-emails.js +13 -0
  198. package/dist/transactional-emails.js.map +1 -1
  199. package/package.json +2 -2
@@ -0,0 +1,365 @@
1
+ import { z } from 'zod';
2
+ import { isoDateTimeSchema, multilingualStringSchema, productVisibilitySchema, uuidSchema, } from './common.js';
3
+ import { isProductVisibleTo, productStatusSchema } from './catalog.js';
4
+ import { ORDER_MINIMUM_MAX } from './order-minimums.js';
5
+ /**
6
+ * Feature 163 (`specs/163-product-data-scopes/`) — product data scopes per sales
7
+ * channel and language: the one rule of effective availability, its admin shapes and
8
+ * the ports other modules ask through (`contracts/product-scopes.md`,
9
+ * `contracts/admin-scopes-api.md`, research R1–R7, R18).
10
+ *
11
+ * Scopes, from widest to narrowest: **global** (the `products` row), **channel**
12
+ * (`product_channel_scopes`, one row per product × channel) and **channel × language**
13
+ * (`product_channel_language_scopes`, status only). An override that is absent —
14
+ * `null` on a channel row, no row at all — inherits from the scope above it.
15
+ *
16
+ * Import direction: this file imports from `catalog.ts`, never the reverse, so either
17
+ * may be loaded first without meeting the other half-evaluated.
18
+ */
19
+ // --- 1. Constants and types ----------------------------------------------------
20
+ /**
21
+ * The scoped status values (FR-010, R3). The same set as the global product status,
22
+ * and derived from it so there is one list. Every predicate tests `=== 'active'`
23
+ * through {@link isOn} and never enumerates the off values, which is what keeps a
24
+ * later change of this set (owner question Q1) a data migration rather than a rewrite.
25
+ */
26
+ export const PRODUCT_SCOPE_STATUSES = productStatusSchema.options;
27
+ export const productScopeStatusSchema = z.enum(PRODUCT_SCOPE_STATUSES);
28
+ // --- 2. The pure rule (one definition, FR-002) -----------------------------------
29
+ /** `status === 'active'` — the only test of a status value anywhere. */
30
+ export function isOn(status) {
31
+ return status === 'active';
32
+ }
33
+ /** `cl.status ?? c.status ?? global.status`. */
34
+ export function effectiveStatus(global, channelRow, clRow) {
35
+ return clRow?.status ?? channelRow?.status ?? global.status;
36
+ }
37
+ /** The channel's window when it overrides one, else the global window — as a pair (R4). */
38
+ export function effectiveWindow(global, channelRow) {
39
+ return channelRow?.window ?? global.window;
40
+ }
41
+ /** `from ≤ now ≤ until`, to the millisecond; a `null` bound is open (K4). */
42
+ export function isInsideWindow(window, now) {
43
+ const at = now.getTime();
44
+ if (window.from !== null && window.from.getTime() > at)
45
+ return false;
46
+ if (window.until !== null && at > window.until.getTime())
47
+ return false;
48
+ return true;
49
+ }
50
+ /** The channel's rule when it overrides one, else the global rule — replaced whole, never merged (C4). */
51
+ export function effectiveAudience(global, channelRow) {
52
+ return (channelRow?.audience ?? {
53
+ visibility: global.visibility,
54
+ allowedOrganizationIds: global.allowedOrganizationIds,
55
+ });
56
+ }
57
+ /** Minimum order quantity and the returnable flag in a channel (FR-100). */
58
+ export function effectiveOrderRules(global, channelRow) {
59
+ return {
60
+ minOrderQuantity: channelRow?.minOrderQuantity ?? global.minOrderQuantity,
61
+ returnable: channelRow?.returnable ?? global.returnable,
62
+ };
63
+ }
64
+ /**
65
+ * FR-100, research R26 — `records` with the channel's effective minimum order quantity
66
+ * and returnable flag (`rules`, from `catalogProductAvailabilityPort.effectiveOrderRules`)
67
+ * in place of the global ones, for a seam that judges a basket, an order or a quote
68
+ * line in that channel: the order-minimum rule and the returnable stamp. A record the
69
+ * rules do not name is returned as it is; the input is never mutated. The port's own
70
+ * records keep meaning "global".
71
+ */
72
+ export function withChannelOrderRules(records, rules) {
73
+ return records.map((record) => {
74
+ const rule = rules.get(record.id);
75
+ return rule === undefined ? record : { ...record, minOrderQuantity: rule.minOrderQuantity, returnable: rule.returnable };
76
+ });
77
+ }
78
+ /**
79
+ * FR-001 — is the product effectively available at (channel, language) to this
80
+ * audience, now? Not deleted, not archived, a member of the channel, the language
81
+ * offered by the channel, effectively on there, inside its effective window, and
82
+ * admitted by its effective audience rule.
83
+ *
84
+ * Membership and the channel's languages are tested **before** any override is read,
85
+ * which is how orphaned overrides are ignored (FR-015). A row naming another channel
86
+ * or another language is ignored too.
87
+ *
88
+ * Its SQL restatement is `availabilityCondition` in catalog's
89
+ * `product-availability.sql.ts`; a parity test holds the two equal.
90
+ */
91
+ export function isProductEffectivelyAvailable(input) {
92
+ const { global, channel, languageCode } = input;
93
+ if (global.deletedAt !== null || global.archivedAt !== null)
94
+ return false;
95
+ if (!input.isMember)
96
+ return false;
97
+ if (!channel.languages.includes(languageCode))
98
+ return false;
99
+ const channelRow = input.channelRow?.channelId === channel.id ? input.channelRow : undefined;
100
+ const clRow = input.clRow?.channelId === channel.id && input.clRow.languageCode === languageCode ? input.clRow : undefined;
101
+ if (!isOn(effectiveStatus(global, channelRow, clRow)))
102
+ return false;
103
+ if (!isInsideWindow(effectiveWindow(global, channelRow), input.now))
104
+ return false;
105
+ return isProductVisibleTo(effectiveAudience(global, channelRow), input.audience);
106
+ }
107
+ /**
108
+ * The (channel, language) pairs an edit turns on — the completeness gate's subject
109
+ * (R18, N3).
110
+ *
111
+ * **Status only (owner decision M3 → A, 2026-10-22; FR-060).** A pair is returned
112
+ * when the product's effective status there goes from off to on; the window, the
113
+ * audience and archiving are not compared. `channels` is the product's member
114
+ * channels with their languages *after* the write and serves both snapshots, so
115
+ * neither a membership change nor a channel gaining a language produces a pair on
116
+ * its own. Archiving is not a status (spec Session 2026-10-25): setting an archived
117
+ * product `active` turns its pairs on, and a Restore — `archivedAt` alone moving —
118
+ * turns nothing on.
119
+ */
120
+ export function pairsTurningOn(before, after, channels) {
121
+ const pairs = [];
122
+ for (const channel of channels) {
123
+ for (const languageCode of channel.languages) {
124
+ if (!statusOnAt(before, channel.id, languageCode) && statusOnAt(after, channel.id, languageCode)) {
125
+ pairs.push({ channelId: channel.id, languageCode });
126
+ }
127
+ }
128
+ }
129
+ return pairs;
130
+ }
131
+ function statusOnAt(snapshot, channelId, languageCode) {
132
+ const { global } = snapshot;
133
+ if (global.deletedAt !== null)
134
+ return false;
135
+ const channelRow = snapshot.channelRows.find((row) => row.channelId === channelId);
136
+ const clRow = snapshot.languageRows.find((row) => row.channelId === channelId && row.languageCode === languageCode);
137
+ return isOn(effectiveStatus(global, channelRow, clRow));
138
+ }
139
+ /**
140
+ * Which content language "L" a request is in (R7, A-3): the channel's language
141
+ * matching the requested tag case-insensitively, else the first channel language
142
+ * sharing its base language (`pl` ↔ `pl-PL`), else the channel's default. The answer
143
+ * is always spelled as the channel spells it.
144
+ *
145
+ * Not the platform's prose-language resolver: channel content languages are free
146
+ * BCP-47 codes, while the prose resolver normalises to the platform's UI languages.
147
+ */
148
+ export function resolveScopeLanguage(channel, requestedTag) {
149
+ // An `Accept-Language` pick may carry its quality parameter (`de;q=0.9`).
150
+ const tag = requestedTag?.split(';')[0]?.trim().toLowerCase() ?? '';
151
+ if (tag === '')
152
+ return channel.defaultLanguage;
153
+ const exact = channel.languages.find((language) => language.toLowerCase() === tag);
154
+ if (exact !== undefined)
155
+ return exact;
156
+ const base = baseLanguage(tag);
157
+ const sameBase = channel.languages.find((language) => baseLanguage(language.toLowerCase()) === base);
158
+ return sameBase ?? channel.defaultLanguage;
159
+ }
160
+ export { applyTranslationPatch, effectivePackagingUnitName, sameLanguage, translationAt, translationMapPatchSchema, TRANSLATION_MAP_MAX_LANGUAGES, } from './scoped-translations.js';
161
+ /**
162
+ * A channel record as the scope rule reads it. The default language is always
163
+ * one of the languages: a channel whose list is empty, or omits its own
164
+ * default, still offers that default — the language every request on it falls
165
+ * back to. The one home of that normalisation (catalog's availability service
166
+ * and every consumer seam read it from here).
167
+ */
168
+ export function toScopeChannel(channel) {
169
+ const languages = [...(channel.languages ?? [])];
170
+ if (!languages.includes(channel.defaultLanguage))
171
+ languages.unshift(channel.defaultLanguage);
172
+ return { id: channel.id, languages, defaultLanguage: channel.defaultLanguage };
173
+ }
174
+ /**
175
+ * {@link resolveScopeLanguage} over a channel record as a resolver holds it —
176
+ * the scope language L of a buyer request on `channel` that asked in
177
+ * `requestedTag` (the first `Accept-Language` tag, see {@link firstLanguageTag}).
178
+ */
179
+ export function scopeLanguageOf(channel, requestedTag) {
180
+ return resolveScopeLanguage(toScopeChannel(channel), requestedTag);
181
+ }
182
+ /**
183
+ * The first tag of an `Accept-Language` header, without its quality parameter,
184
+ * or `undefined` when the header is absent or empty.
185
+ */
186
+ export function firstLanguageTag(header) {
187
+ const value = Array.isArray(header) ? header[0] : header;
188
+ if (typeof value !== 'string')
189
+ return undefined;
190
+ const first = value.split(',')[0]?.split(';')[0]?.trim();
191
+ return first ? first : undefined;
192
+ }
193
+ function baseLanguage(tag) {
194
+ const dash = tag.indexOf('-');
195
+ return dash === -1 ? tag : tag.slice(0, dash);
196
+ }
197
+ // --- 4. Admin shapes (admin-scopes-api.md) -----------------------------------------
198
+ /**
199
+ * A channel content language as a request names it: the BCP-47 shape the dictionary
200
+ * and i18n contracts use (`pl`, `pl-PL`), matched case-insensitively because the
201
+ * write resolves it to the channel's own spelling (`de-de` → `de-DE`).
202
+ */
203
+ const languageCodeSchema = z
204
+ .string()
205
+ .max(16)
206
+ .regex(/^[a-z]{2,3}(-[a-z]{2})?$/i, 'BCP-47 language tag');
207
+ /** The most organizations one channel audience override names (security review, 163 Block A). */
208
+ const SCOPE_AUDIENCE_ORGANIZATIONS_MAX = 1000;
209
+ /** The most language statuses one channel entry of a scopes PATCH carries. */
210
+ const SCOPE_LANGUAGE_STATUSES_MAX = 64;
211
+ /**
212
+ * What the completeness gate reports missing at a (channel, language) — one
213
+ * vocabulary for the save warning, the `SCOPE_INCOMPLETE` refusal and the scope
214
+ * overview's cells, so they cannot disagree (FR-041, FR-060).
215
+ */
216
+ export const scopeMissingValueSchema = z.union([
217
+ z.literal('name'),
218
+ z.literal('urlKey'),
219
+ z.templateLiteral(['attribute:', z.string().min(1)]),
220
+ ]);
221
+ /**
222
+ * A channel audience override. Capped: the only writer is the scopes PATCH, so the
223
+ * read shape carries the same bound. The global rule in §1 is deliberately not capped:
224
+ * the product update writes it without a bound (`catalog.ts`), so a cap on the read
225
+ * shape would describe products the platform already holds as invalid.
226
+ */
227
+ const audienceRuleSchema = z.object({
228
+ visibility: productVisibilitySchema,
229
+ allowedOrganizationIds: z.array(uuidSchema).max(SCOPE_AUDIENCE_ORGANIZATIONS_MAX),
230
+ });
231
+ const orderMinimumSchema = z.number().int().min(1).max(ORDER_MINIMUM_MAX);
232
+ /** §1 — `GET /api/v1/admin/catalog/products/:id/scopes`. */
233
+ export const productScopesSchema = z.object({
234
+ global: z.object({
235
+ status: productScopeStatusSchema,
236
+ publishFrom: isoDateTimeSchema.nullable(),
237
+ publishUntil: isoDateTimeSchema.nullable(),
238
+ visibility: productVisibilitySchema,
239
+ allowedOrganizationIds: z.array(uuidSchema),
240
+ minOrderQuantity: z.number().int().nullable(),
241
+ returnable: z.boolean(),
242
+ }),
243
+ channels: z.array(z.object({
244
+ channelId: uuidSchema,
245
+ isMember: z.boolean(),
246
+ /** The channel's current content languages. */
247
+ languages: z.array(z.string()),
248
+ status: productScopeStatusSchema.nullable(),
249
+ window: z.object({ from: isoDateTimeSchema.nullable(), until: isoDateTimeSchema.nullable() }).nullable(),
250
+ audience: audienceRuleSchema
251
+ .extend({
252
+ /** Organizations the override names that are not members of the channel (C4 warning). */
253
+ nonMemberOrganizationIds: z.array(uuidSchema),
254
+ })
255
+ .nullable(),
256
+ minOrderQuantity: z.number().int().nullable(),
257
+ returnable: z.boolean().nullable(),
258
+ languageStatuses: z.array(z.object({ languageCode: z.string(), status: productScopeStatusSchema, orphaned: z.boolean() })),
259
+ /** The product is not a member of this channel any more (FR-015). */
260
+ orphaned: z.boolean(),
261
+ })),
262
+ /**
263
+ * Owner decision U1 — the names of the organizations the channel audience rules name
264
+ * (non-members included), resolved by the server so an operator without
265
+ * `customers:read` can read them. The global rule's are not named: it is uncapped. An organization that cannot be read (deleted,
266
+ * or `organizations` not answering) is absent: the consumer shows its id.
267
+ */
268
+ organizations: z.array(z.object({ id: uuidSchema, name: z.string() })),
269
+ });
270
+ export const productScopesResponseSchema = z.object({ data: productScopesSchema });
271
+ /**
272
+ * §2 — `PATCH /api/v1/admin/catalog/products/:id/scopes`. An absent key leaves the
273
+ * value untouched; `null` = use inherited (deletes the override, FR-012). A window
274
+ * whose `from` is not before its `until` passes the schema and is refused by the
275
+ * service with `VALIDATION_FAILED`, `details.field = 'window'`.
276
+ */
277
+ export const patchProductScopesRequestSchema = z.object({
278
+ channels: z
279
+ .array(z.object({
280
+ channelId: uuidSchema,
281
+ status: productScopeStatusSchema.nullable().optional(),
282
+ window: z
283
+ .object({ from: isoDateTimeSchema.nullable(), until: isoDateTimeSchema.nullable() })
284
+ .nullable()
285
+ .optional(),
286
+ audience: audienceRuleSchema.nullable().optional(),
287
+ minOrderQuantity: orderMinimumSchema.nullable().optional(),
288
+ returnable: z.boolean().nullable().optional(),
289
+ languageStatuses: z
290
+ .array(z.object({ languageCode: languageCodeSchema, status: productScopeStatusSchema.nullable() }))
291
+ .max(SCOPE_LANGUAGE_STATUSES_MAX)
292
+ .optional(),
293
+ }))
294
+ .max(64),
295
+ global: z
296
+ .object({ publishFrom: isoDateTimeSchema.nullable(), publishUntil: isoDateTimeSchema.nullable() })
297
+ .partial()
298
+ .optional(),
299
+ });
300
+ export const scopeWarningSchema = z.discriminatedUnion('kind', [
301
+ z.object({
302
+ kind: z.literal('completeness'),
303
+ channelId: uuidSchema,
304
+ languageCode: z.string(),
305
+ missing: z.array(scopeMissingValueSchema),
306
+ }),
307
+ z.object({ kind: z.literal('audience_non_members'), channelId: uuidSchema, organizationIds: z.array(uuidSchema) }),
308
+ ]);
309
+ export const patchProductScopesResponseSchema = z.object({
310
+ data: productScopesSchema,
311
+ warnings: z.array(scopeWarningSchema),
312
+ });
313
+ /** `422 SCOPE_INVALID` details (FR-014). */
314
+ export const scopeInvalidDetailsSchema = z.object({
315
+ channelId: uuidSchema,
316
+ languageCode: z.string().optional(),
317
+ reason: z.enum(['not_a_member', 'language_not_offered']),
318
+ });
319
+ /** `422 SCOPE_INCOMPLETE` details (FR-060). */
320
+ export const scopeIncompleteDetailsSchema = z.object({
321
+ pairs: z.array(z.object({ channelId: uuidSchema, languageCode: z.string(), missing: z.array(scopeMissingValueSchema) })),
322
+ });
323
+ export const scopeLevelSchema = z.enum(['channel_language', 'channel', 'language']);
324
+ /** §3 — `GET /api/v1/admin/catalog/products/:id/scope-overview`. */
325
+ export const scopeOverviewResponseSchema = z.object({
326
+ data: z.object({
327
+ channels: z.array(z.object({
328
+ channelId: uuidSchema,
329
+ name: multilingualStringSchema,
330
+ isMember: z.boolean(),
331
+ languages: z.array(z.string()),
332
+ })),
333
+ /** The union of the channels' languages, or every active platform language when there is no channel. */
334
+ languages: z.array(z.string()),
335
+ cells: z.array(z.object({
336
+ channelId: uuidSchema,
337
+ languageCode: z.string(),
338
+ /** Member, language offered, on and inside the window now; audience is shown as the rule, not evaluated. */
339
+ available: z.boolean(),
340
+ effectiveStatus: productScopeStatusSchema,
341
+ statusSource: z.enum(['channel_language', 'channel', 'global']),
342
+ overriddenFields: z.array(z.object({ field: z.string(), level: scopeLevelSchema })),
343
+ /** FR-041 — what the gate would report here; `[]` = complete; absent = not evaluable. */
344
+ missing: z.array(scopeMissingValueSchema).optional(),
345
+ })),
346
+ channelRows: z.array(z.object({ channelId: uuidSchema, overriddenFields: z.array(z.string()) })),
347
+ languageColumns: z.array(z.object({ languageCode: z.string(), overriddenFields: z.array(z.string()) })),
348
+ orphans: z.array(z.object({
349
+ field: z.string(),
350
+ channelId: uuidSchema.nullable(),
351
+ languageCode: z.string().nullable(),
352
+ reason: z.enum(['not_a_member', 'language_not_offered', 'attribute_scope_changed']),
353
+ })),
354
+ }),
355
+ });
356
+ /** §6 — `GET /api/v1/admin/catalog/attributes/:idOrKey/scope-change-preview`. */
357
+ export const attributeScopeChangePreviewResponseSchema = z.object({
358
+ data: z.object({
359
+ orphanedOverrides: z.number().int().nonnegative(),
360
+ byChannel: z.array(z.object({ channelId: uuidSchema, count: z.number().int().nonnegative() })),
361
+ }),
362
+ });
363
+ /** §5 — the completeness gate's mode (`catalog.scope_completeness_gate`). */
364
+ export const SCOPE_COMPLETENESS_GATE_MODES = ['warn', 'refuse'];
365
+ //# sourceMappingURL=product-scopes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-scopes.js","sourceRoot":"","sources":["../src/product-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,uBAAuB,EACvB,UAAU,GAEX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAwB,MAAM,cAAc,CAAC;AAC7F,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;;;;;;;;;;;;GAaG;AAEH,kFAAkF;AAElF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAC,OAAO,CAAC;AAElE,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;AAgEvE,oFAAoF;AAEpF,wEAAwE;AACxE,MAAM,UAAU,IAAI,CAAC,MAA0B;IAC7C,OAAO,MAA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AAM,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;QACvG,OAAO,EAAE,CAAC,CAAC,KAAK,CACd,CAAC,CAAC,MAAM,CAAC;YACP,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;YACjB,SAAS,EAAE,UAAU,CAAC,QAAQ,EAAE;YAChC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;YACnC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,sBAAsB,EAAE,yBAAyB,CAAC,CAAC;SACpF,CAAC,CACH;KACF,CAAC;CACH,CAAC,CAAC;AAGH,iFAAiF;AACjF,MAAM,CAAC,MAAM,yCAAyC,GAAG,CAAC,CAAC,MAAM,CAAC;IAChE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QACb,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;QACjD,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;KAC/F,CAAC;CACH,CAAC,CAAC;AAGH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAU,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The product card's short description (`specs/163-page-builder-marketing-pages/`
3
+ * research R-16, FR-027, owner ruling Q3): derived from the product's own
4
+ * description rather than stored, so the catalogue's schema does not change.
5
+ *
6
+ * Pure and synchronous on purpose: the catalogue's listing calls it on the
7
+ * description it already holds, so a summary costs no query per product.
8
+ *
9
+ * It lives here rather than in `catalog` (T196) because a second reader needs
10
+ * the same answer: the page editor's preview of a product listing (`cms`'
11
+ * admin), which reads the admin product payload — the description, not a
12
+ * summary — and must show the line the storefront shows. A module may not
13
+ * import another's internals; both may import this.
14
+ */
15
+ /** The longest summary, ellipsis included. */
16
+ export declare const PRODUCT_SUMMARY_MAX_LENGTH = 160;
17
+ /**
18
+ * The summary of a description: plain text of at most
19
+ * {@link PRODUCT_SUMMARY_MAX_LENGTH} characters, cut at the last word boundary
20
+ * that fits and marked with an ellipsis; `null` when nothing is left.
21
+ */
22
+ export declare function productSummaryText(description: string | null | undefined): string | null;
23
+ //# sourceMappingURL=product-summary-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-summary-text.d.ts","sourceRoot":"","sources":["../src/product-summary-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,8CAA8C;AAC9C,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAkC9C;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAUxF"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The product card's short description (`specs/163-page-builder-marketing-pages/`
3
+ * research R-16, FR-027, owner ruling Q3): derived from the product's own
4
+ * description rather than stored, so the catalogue's schema does not change.
5
+ *
6
+ * Pure and synchronous on purpose: the catalogue's listing calls it on the
7
+ * description it already holds, so a summary costs no query per product.
8
+ *
9
+ * It lives here rather than in `catalog` (T196) because a second reader needs
10
+ * the same answer: the page editor's preview of a product listing (`cms`'
11
+ * admin), which reads the admin product payload — the description, not a
12
+ * summary — and must show the line the storefront shows. A module may not
13
+ * import another's internals; both may import this.
14
+ */
15
+ /** The longest summary, ellipsis included. */
16
+ export const PRODUCT_SUMMARY_MAX_LENGTH = 160;
17
+ const ELLIPSIS = '…';
18
+ const NAMED_ENTITIES = {
19
+ amp: '&',
20
+ lt: '<',
21
+ gt: '>',
22
+ quot: '"',
23
+ apos: "'",
24
+ nbsp: ' ',
25
+ };
26
+ function decodeEntities(text) {
27
+ return text.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z]+);/gi, (match, entity) => {
28
+ if (entity.startsWith('#x') || entity.startsWith('#X')) {
29
+ const code = Number.parseInt(entity.slice(2), 16);
30
+ return Number.isFinite(code) && code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : match;
31
+ }
32
+ if (entity.startsWith('#')) {
33
+ const code = Number.parseInt(entity.slice(1), 10);
34
+ return Number.isFinite(code) && code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : match;
35
+ }
36
+ return NAMED_ENTITIES[entity.toLowerCase()] ?? match;
37
+ });
38
+ }
39
+ /** A description (plain text or HTML) as one line of plain text. */
40
+ function toPlainText(description) {
41
+ const withoutCode = description.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, ' ');
42
+ const withoutTags = withoutCode.replace(/<[^>]*>/g, ' ');
43
+ return decodeEntities(withoutTags).replace(/\s+/g, ' ').trim();
44
+ }
45
+ /**
46
+ * The summary of a description: plain text of at most
47
+ * {@link PRODUCT_SUMMARY_MAX_LENGTH} characters, cut at the last word boundary
48
+ * that fits and marked with an ellipsis; `null` when nothing is left.
49
+ */
50
+ export function productSummaryText(description) {
51
+ if (typeof description !== 'string')
52
+ return null;
53
+ const text = toPlainText(description);
54
+ if (text === '')
55
+ return null;
56
+ if (text.length <= PRODUCT_SUMMARY_MAX_LENGTH)
57
+ return text;
58
+ const room = PRODUCT_SUMMARY_MAX_LENGTH - ELLIPSIS.length;
59
+ const head = text.slice(0, room + 1);
60
+ const boundary = head.lastIndexOf(' ');
61
+ const cut = boundary > 0 ? head.slice(0, boundary) : text.slice(0, room);
62
+ return `${cut.replace(/[\s,;:–—-]+$/u, '')}${ELLIPSIS}`;
63
+ }
64
+ //# sourceMappingURL=product-summary-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-summary-text.js","source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