@aglyn/plugins-commerce 1.29.1 → 1.29.3
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.
- package/package.json +13 -13
- package/src/lib/components/console/checkout-tax-blocked-notice.component.d.ts +18 -0
- package/src/lib/components/console/checkout-tax-blocked-notice.component.js +67 -0
- package/src/lib/components/console/checkout-tax-blocked-notice.component.js.map +1 -0
- package/src/lib/components/console/payments-settings-card.component.d.ts +2 -2
- package/src/lib/components/console/payments-settings-card.component.js +99 -5
- package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
- package/src/lib/components/console/product-editor-dialog.component.js +14 -3
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/products-hub-card.component.js +51 -14
- package/src/lib/components/console/products-hub-card.component.js.map +1 -1
- package/src/lib/components/console/stripe-tax-readiness.component.d.ts +45 -0
- package/src/lib/components/console/stripe-tax-readiness.component.js +276 -0
- package/src/lib/components/console/stripe-tax-readiness.component.js.map +1 -0
- package/src/lib/components/console/tax-settings-card.component.js +22 -8
- package/src/lib/components/console/tax-settings-card.component.js.map +1 -1
- package/src/lib/constants/operator-alerts.d.ts +9 -0
- package/src/lib/constants/operator-alerts.js +22 -1
- package/src/lib/constants/operator-alerts.js.map +1 -1
- package/src/lib/declarations.server.js +11 -0
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/model/commerce-record-routes.d.ts +13 -1
- package/src/lib/model/commerce-record-routes.js +22 -2
- package/src/lib/model/commerce-record-routes.js.map +1 -1
- package/src/lib/model/commerce-tax-readiness.d.ts +79 -0
- package/src/lib/model/commerce-tax-readiness.js +99 -0
- package/src/lib/model/commerce-tax-readiness.js.map +1 -0
- package/src/lib/model/commerce.d.ts +7 -0
- package/src/lib/model/commerce.js +17 -4
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/payments-setup-status.d.ts +68 -0
- package/src/lib/model/payments-setup-status.js +103 -0
- package/src/lib/model/payments-setup-status.js.map +1 -0
- package/src/lib/plan-entitlements.d.ts +2 -2
- package/src/lib/plan-entitlements.js +4 -12
- package/src/lib/plan-entitlements.js.map +1 -1
- package/src/lib/server/cart-checkout.js +3 -0
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/checkout-tax-refusal.d.ts +51 -0
- package/src/lib/server/checkout-tax-refusal.js +133 -0
- package/src/lib/server/checkout-tax-refusal.js.map +1 -0
- package/src/lib/server/checkout.d.ts +2 -1
- package/src/lib/server/checkout.js +7 -2
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/connect-prefill.d.ts +65 -0
- package/src/lib/server/connect-prefill.js +85 -0
- package/src/lib/server/connect-prefill.js.map +1 -0
- package/src/lib/server/connect.d.ts +4 -2
- package/src/lib/server/connect.js +117 -37
- package/src/lib/server/connect.js.map +1 -1
- package/src/lib/server/draft-order.js +4 -2
- package/src/lib/server/draft-order.js.map +1 -1
- package/src/lib/server/pos-order.js +1 -1
- package/src/lib/server/pos-order.js.map +1 -1
- package/src/lib/server/product-writer.d.ts +27 -0
- package/src/lib/server/product-writer.js +174 -4
- package/src/lib/server/product-writer.js.map +1 -1
- package/src/lib/server/quote-pay.d.ts +6 -0
- package/src/lib/server/quote-pay.js +8 -2
- package/src/lib/server/quote-pay.js.map +1 -1
- package/src/lib/server/seller-stripe-account.d.ts +19 -0
- package/src/lib/server/seller-stripe-account.js +40 -4
- package/src/lib/server/seller-stripe-account.js.map +1 -1
- package/src/lib/server/site-page-resolver.d.ts +11 -5
- package/src/lib/server/site-page-resolver.js +102 -19
- package/src/lib/server/site-page-resolver.js.map +1 -1
- package/src/lib/server/site-search.d.ts +43 -0
- package/src/lib/server/site-search.js +124 -0
- package/src/lib/server/site-search.js.map +1 -0
- package/src/lib/server/tax-readiness.d.ts +56 -0
- package/src/lib/server/tax-readiness.js +169 -0
- package/src/lib/server/tax-readiness.js.map +1 -0
- package/src/lib/server.js +10 -2
- package/src/lib/server.js.map +1 -1
- package/src/lib/transfer/product-image-copy.server.d.ts +77 -0
- package/src/lib/transfer/product-image-copy.server.js +307 -0
- package/src/lib/transfer/product-image-copy.server.js.map +1 -0
- package/src/lib/transfer/product-images.d.ts +62 -0
- package/src/lib/transfer/product-images.js +143 -0
- package/src/lib/transfer/product-images.js.map +1 -0
- package/src/lib/transfer/product-sources.d.ts +92 -0
- package/src/lib/transfer/product-sources.js +519 -0
- package/src/lib/transfer/product-sources.js.map +1 -0
- package/src/lib/transfer/product-transfer.d.ts +26 -1
- package/src/lib/transfer/product-transfer.js +283 -11
- package/src/lib/transfer/product-transfer.js.map +1 -1
- package/src/lib/transfer/products.server.d.ts +29 -3
- package/src/lib/transfer/products.server.js +289 -13
- package/src/lib/transfer/products.server.js.map +1 -1
|
@@ -29,6 +29,7 @@ import * as CommerceModel from "../model/index.js";
|
|
|
29
29
|
import { productAsksUseDateAnywhere, toPublicProductDetail } from "./product.js";
|
|
30
30
|
import { readStoreDay } from "./store-day.js";
|
|
31
31
|
import { readProductReviews } from "./reviews.js";
|
|
32
|
+
import { productEditPath } from "../model/commerce-record-routes.js";
|
|
32
33
|
/**
|
|
33
34
|
* Commerce page resolver (AGL-292/298/418), relocated verbatim from the
|
|
34
35
|
* tenant loader: /products/{slug} renders the host's designated PDP
|
|
@@ -107,7 +108,12 @@ import { readProductReviews } from "./reviews.js";
|
|
|
107
108
|
// The head shares this page as the template's image, then the site
|
|
108
109
|
// default, so their documents are read in the template's own batch
|
|
109
110
|
// (AGL-2850).
|
|
111
|
+
const shareImage = productShareImage(product);
|
|
110
112
|
const card = collectSocialImageFacts([
|
|
113
|
+
// Only when there is one: the list is the card's precedence.
|
|
114
|
+
...shareImage ? [
|
|
115
|
+
shareImage
|
|
116
|
+
] : [],
|
|
111
117
|
(_templateRes_screen_seo = templateRes.screen.seo) == null ? void 0 : _templateRes_screen_seo.image,
|
|
112
118
|
(_hostRes_host = hostRes.host) == null ? void 0 : (_hostRes_host_seo = _hostRes_host.seo) == null ? void 0 : _hostRes_host_seo.image
|
|
113
119
|
]);
|
|
@@ -122,7 +128,7 @@ import { readProductReviews } from "./reviews.js";
|
|
|
122
128
|
tokens: {
|
|
123
129
|
'product.name': product.name,
|
|
124
130
|
'product.description': (_product_description = product.description) != null ? _product_description : '',
|
|
125
|
-
'product.price': productPriceText(product, minPrice, maxPrice),
|
|
131
|
+
'product.price': CommerceModel.productPriceText(product, minPrice, maxPrice),
|
|
126
132
|
'product.image': (_ref = (_ref1 = (_product_mediaUrls = product.mediaUrls) == null ? void 0 : _product_mediaUrls[0]) != null ? _ref1 : product.imageUrl) != null ? _ref : '',
|
|
127
133
|
'product.slug': product.slug
|
|
128
134
|
},
|
|
@@ -169,7 +175,7 @@ import { readProductReviews } from "./reviews.js";
|
|
|
169
175
|
// product with its own SEO title gets exactly that, and
|
|
170
176
|
// one without gets "Blue Widget – Acme Store".
|
|
171
177
|
displayName: product.name,
|
|
172
|
-
seo: _extends({}, (_templateRes_screen_seo1 = templateRes.screen.seo) != null ? _templateRes_screen_seo1 : {}, {
|
|
178
|
+
seo: _extends({}, (_templateRes_screen_seo1 = templateRes.screen.seo) != null ? _templateRes_screen_seo1 : {}, shareCard(shareImage, product.name), {
|
|
173
179
|
// Only when the PRODUCT authored one: inheriting the
|
|
174
180
|
// template screen's title would give every product
|
|
175
181
|
// page in the store the same `<title>`.
|
|
@@ -222,7 +228,12 @@ import { readProductReviews } from "./reviews.js";
|
|
|
222
228
|
var _templateRes_screen_seo2, _hostRes_host_seo1, _hostRes_host1;
|
|
223
229
|
// As on the PDP above: the template's image, then the site default
|
|
224
230
|
// (AGL-2850).
|
|
231
|
+
const shareImage = shopCollection.imageUrl || undefined;
|
|
225
232
|
const card = collectSocialImageFacts([
|
|
233
|
+
// Only when there is one: the list is the card's precedence.
|
|
234
|
+
...shareImage ? [
|
|
235
|
+
shareImage
|
|
236
|
+
] : [],
|
|
226
237
|
(_templateRes_screen_seo2 = templateRes.screen.seo) == null ? void 0 : _templateRes_screen_seo2.image,
|
|
227
238
|
(_hostRes_host1 = hostRes.host) == null ? void 0 : (_hostRes_host_seo1 = _hostRes_host1.seo) == null ? void 0 : _hostRes_host_seo1.image
|
|
228
239
|
]);
|
|
@@ -264,7 +275,7 @@ import { readProductReviews } from "./reviews.js";
|
|
|
264
275
|
// collection has no SEO title field of its own, so the
|
|
265
276
|
// template's must not stand in for one.
|
|
266
277
|
displayName: shopCollection.name,
|
|
267
|
-
seo: _extends({}, (_templateRes_screen_seo3 = templateRes.screen.seo) != null ? _templateRes_screen_seo3 : {}, {
|
|
278
|
+
seo: _extends({}, (_templateRes_screen_seo3 = templateRes.screen.seo) != null ? _templateRes_screen_seo3 : {}, shareCard(shareImage, shopCollection.name), {
|
|
268
279
|
title: undefined,
|
|
269
280
|
description: (_shopCollection_description1 = shopCollection.description) != null ? _shopCollection_description1 : undefined
|
|
270
281
|
})
|
|
@@ -282,16 +293,55 @@ import { readProductReviews } from "./reviews.js";
|
|
|
282
293
|
return undefined;
|
|
283
294
|
};
|
|
284
295
|
/**
|
|
285
|
-
* What
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
296
|
+
* What the admin edit bar says on the pages the resolver above composes. They
|
|
297
|
+
* are in no routing map, so the bar called a product page "Unrouted page" with
|
|
298
|
+
* no edit link. It answers from the same reads the page is built from: the
|
|
299
|
+
* store's designated template (`pdpScreenId`, `collectionScreenId`), and for
|
|
300
|
+
* a product page the product itself, whose editor the bar links beside the
|
|
301
|
+
* template's Besigner, as it does for a blog post. A product the page would
|
|
302
|
+
* not render (not live, or not sold online) gets no answer, as it gets no
|
|
303
|
+
* page.
|
|
304
|
+
*/ export const commerceEditContextResolver = async ({ hostId, path })=>{
|
|
305
|
+
const segments = path.split('/').filter(Boolean);
|
|
306
|
+
if (segments.length !== 2) return undefined;
|
|
307
|
+
const [section, slug] = segments;
|
|
308
|
+
if (section !== 'products' && section !== 'collections') return undefined;
|
|
309
|
+
const hostDocRef = firebaseAdmin.app().firestore().collection('hosts').doc(hostId);
|
|
310
|
+
const storeSettings = await hostDocRef.collection('settings').doc('store').get();
|
|
311
|
+
const screenField = (name)=>{
|
|
312
|
+
const value = storeSettings.get(name);
|
|
313
|
+
return typeof value === 'string' && value ? value : null;
|
|
314
|
+
};
|
|
315
|
+
if (section === 'products') {
|
|
316
|
+
const productSnapshot = await hostDocRef.collection('products').where('slug', '==', slug).limit(1).get();
|
|
317
|
+
const productDoc = productSnapshot.docs[0];
|
|
318
|
+
if (!productDoc || !CommerceModel.productListedOnline(productDoc.data())) {
|
|
319
|
+
return undefined;
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
templateScreenId: screenField('pdpScreenId'),
|
|
323
|
+
collectionName: 'Products',
|
|
324
|
+
entry: true,
|
|
325
|
+
entryNoun: 'product',
|
|
326
|
+
recordEditPath: productEditPath(productDoc.id)
|
|
327
|
+
};
|
|
292
328
|
}
|
|
293
|
-
|
|
294
|
-
|
|
329
|
+
const collectionSnapshot = await hostDocRef.collection('collections').where('slug', '==', slug).limit(5).get();
|
|
330
|
+
const shopCollection = collectionSnapshot.docs.find((docSnapshot)=>hostCollectionKind(docSnapshot.data()) === 'catalog');
|
|
331
|
+
const templateScreenId = screenField('collectionScreenId');
|
|
332
|
+
// Without a template the page is not served (no built-in collection page).
|
|
333
|
+
if (!shopCollection || !templateScreenId) return undefined;
|
|
334
|
+
return {
|
|
335
|
+
templateScreenId,
|
|
336
|
+
collectionName: 'Store collections',
|
|
337
|
+
entry: true,
|
|
338
|
+
entryNoun: 'collection',
|
|
339
|
+
recordEditPath: null
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
// What `{{product.price}}` says (AGL-3676) lives with the model now, so the
|
|
343
|
+
// site's search can caption a product the same way without loading this page.
|
|
344
|
+
export { productPriceText } from "../model/index.js";
|
|
295
345
|
const PRODUCT_PAGE_NODE = 'pdp__detail';
|
|
296
346
|
const PRODUCT_PAGE_REVIEWS_NODE = 'pdp__reviews';
|
|
297
347
|
const PRODUCT_PAGE_RELATED_NODE = 'pdp__related';
|
|
@@ -396,8 +446,8 @@ const PRODUCT_PAGE_RELATED_NODE = 'pdp__related';
|
|
|
396
446
|
}
|
|
397
447
|
async function composeBuiltInProductPage(hostId, host, productId, product, rawReturns) {
|
|
398
448
|
try {
|
|
399
|
-
var _ref, _ref1, _ref2
|
|
400
|
-
var
|
|
449
|
+
var _ref, _ref1, _ref2;
|
|
450
|
+
var _host_seo, _product_seo, _product_seo1;
|
|
401
451
|
const [layoutId, productReviews, reviewsOn] = await Promise.all([
|
|
402
452
|
resolveBuiltInPageLayoutId({
|
|
403
453
|
hostId,
|
|
@@ -416,8 +466,11 @@ async function composeBuiltInProductPage(hostId, host, productId, product, rawRe
|
|
|
416
466
|
storeTakesReviews(hostId)
|
|
417
467
|
]);
|
|
418
468
|
const returns = productReturnWindow(product, rawReturns);
|
|
469
|
+
const shareImage = productShareImage(product);
|
|
419
470
|
const card = collectSocialImageFacts([
|
|
420
|
-
|
|
471
|
+
...shareImage ? [
|
|
472
|
+
shareImage
|
|
473
|
+
] : [],
|
|
421
474
|
host == null ? void 0 : (_host_seo = host.seo) == null ? void 0 : _host_seo.image
|
|
422
475
|
]);
|
|
423
476
|
const nodes = await composeNodesWithChrome({
|
|
@@ -450,10 +503,10 @@ async function composeBuiltInProductPage(hostId, host, productId, product, rawRe
|
|
|
450
503
|
screen: {
|
|
451
504
|
data: {
|
|
452
505
|
displayName: product.name,
|
|
453
|
-
seo: {
|
|
454
|
-
title: (
|
|
455
|
-
description: (
|
|
456
|
-
}
|
|
506
|
+
seo: _extends({}, shareCard(shareImage, product.name), {
|
|
507
|
+
title: (_ref = (_product_seo = product.seo) == null ? void 0 : _product_seo.title) != null ? _ref : undefined,
|
|
508
|
+
description: (_ref1 = (_ref2 = (_product_seo1 = product.seo) == null ? void 0 : _product_seo1.description) != null ? _ref2 : product.description) != null ? _ref1 : undefined
|
|
509
|
+
})
|
|
457
510
|
}
|
|
458
511
|
}
|
|
459
512
|
},
|
|
@@ -501,6 +554,36 @@ const ORDER_STATUS_NODE = 'order-status__block';
|
|
|
501
554
|
}
|
|
502
555
|
};
|
|
503
556
|
}
|
|
557
|
+
/**
|
|
558
|
+
* The image a product page shares: the one picked in the product editor's
|
|
559
|
+
* "OG image" field (`seo.imageUrl`), else the product's first photo.
|
|
560
|
+
*
|
|
561
|
+
* Both product pages used to share the template's image, then the site
|
|
562
|
+
* default, so every product in a store shared one card and the editor's
|
|
563
|
+
* OG image was saved and never read. A product's own photo is the most
|
|
564
|
+
* specific card there is; the template's image stays the fallback for a
|
|
565
|
+
* product with no photo.
|
|
566
|
+
*/ function productShareImage(product) {
|
|
567
|
+
var _product_seo, _product_mediaUrls;
|
|
568
|
+
return ((_product_seo = product.seo) == null ? void 0 : _product_seo.imageUrl) || ((_product_mediaUrls = product.mediaUrls) == null ? void 0 : _product_mediaUrls[0]) || product.imageUrl || undefined;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* The page's own card fields for a routed product or collection image.
|
|
572
|
+
*
|
|
573
|
+
* The template's pixel pair and alt describe the template's image, not this
|
|
574
|
+
* one, so they are cleared beside it: a stale 1200x630 on a square product
|
|
575
|
+
* photo is a wrong claim, and no pair is an honest one. The alt names what
|
|
576
|
+
* the page is about. Nothing when there is no image, so the template's card
|
|
577
|
+
* stands.
|
|
578
|
+
*/ function shareCard(image, name) {
|
|
579
|
+
if (!image) return {};
|
|
580
|
+
return {
|
|
581
|
+
image,
|
|
582
|
+
imageWidth: undefined,
|
|
583
|
+
imageHeight: undefined,
|
|
584
|
+
imageAlt: name || undefined
|
|
585
|
+
};
|
|
586
|
+
}
|
|
504
587
|
async function composeOrderStatusPage(hostId, host) {
|
|
505
588
|
try {
|
|
506
589
|
const layoutId = await resolveBuiltInPageLayoutId({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/site-page-resolver.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 type { SitePageResolver } from '@aglyn/aglyn/server'\nimport { hostCollectionKind } from '@aglyn/aglyn/server'\nimport composeScreenNodes, {\n composeNodesWithChrome,\n} from '@aglyn/tenant-runtime/compose-screen-nodes'\nimport { resolveBuiltInPageLayoutId } from '@aglyn/tenant-runtime/built-in-page-layout'\nimport * as Aglyn from '@aglyn/aglyn/server'\nimport { ORDER_STATUS_PATH } from './order-status-token'\nimport { ORDER_STATUS_COMPONENT_ID } from '../constants/order-status'\nimport { RETURN_REQUEST_COMPONENT_ID, RETURN_REQUEST_PATH } from '../constants/return-request'\nimport { QUOTE_PAGE_COMPONENT_ID, QUOTE_PAGE_PATH } from '../constants/quote-page'\nimport getScreen from '@aglyn/tenant-runtime/get-screen'\nimport { collectSocialImageFacts } from '@aglyn/tenant-runtime/social-image-facts'\nimport { firebaseAdmin, getOrgForHost } from '@aglyn/tenant-data-admin'\nimport * as CommerceModel from '../model'\nimport { productAsksUseDateAnywhere, toPublicProductDetail } from './product'\nimport { readStoreDay } from './store-day'\nimport { readProductReviews } from './reviews'\n\n/**\n * Commerce page resolver (AGL-292/298/418), relocated verbatim from the\n * tenant loader: /products/{slug} renders the host's designated PDP\n * template with product tokens, /collections/{slug} the collection\n * template — both compose server-side and return complete page props.\n * Runs only for paths that didn't match a published screen; returns\n * undefined for everything else so the loader falls through.\n */\nexport const commerceSitePageResolver: SitePageResolver = async ({\n hostId,\n host,\n path,\n}) => {\n const hostRes = { host }\n // Product detail routes (AGL-292): /products/{slug} renders the\n // host's designated PDP template screen (settings/store\n // `pdpScreenId`, AGL-295) with product tokens; the product-detail\n // block hydrates variants client-side from the same slug. Same\n // mechanism as entry-template screens below.\n const pdpSegments = path.split('/').filter(Boolean)\n // The guest order-status page (AGL-3610), at /order-status — reached only\n // when the site has no page of its own there. The site's header and footer\n // around the order-status block, which reads the signed `?o=&t=` link after\n // hydration, so this page holds no order and is safe to cache. UNLISTED, so\n // the head says noindex: it is a private page, not a landing page.\n if (pdpSegments.length === 1 && pdpSegments[0] === ORDER_STATUS_PATH) {\n return composeOrderStatusPage(hostId, host)\n }\n // The buyer's return form (AGL-3611), at /order-return, under the same\n // terms: no page of the site's own there, the order read after hydration\n // from the link's `?o=&t=` (or the member's session), UNLISTED.\n if (pdpSegments.length === 1 && pdpSegments[0] === RETURN_REQUEST_PATH) {\n return composeReturnRequestPage(hostId, host)\n }\n // The customer's quote page (AGL-4094), at /pay-quote, under the same\n // terms: no page of the site's own there, the quote read after hydration\n // from the pay link's `?q=&t=`, UNLISTED.\n if (pdpSegments.length === 1 && pdpSegments[0] === QUOTE_PAGE_PATH) {\n return composeQuotePage(hostId, host)\n }\n if (pdpSegments.length === 2 && pdpSegments[0] === 'products') {\n const adminFirestore = firebaseAdmin.app().firestore()\n const hostDocRef = adminFirestore.collection('hosts').doc(hostId)\n const [storeSettings, productSnapshot] = await Promise.all([\n hostDocRef.collection('settings').doc('store').get(),\n hostDocRef\n .collection('products')\n .where('slug', '==', pdpSegments[1])\n .limit(1)\n .get(),\n ])\n const pdpScreenId = storeSettings.get('pdpScreenId')\n const productRaw = productSnapshot.docs[0]?.data() as any\n // Live, active and sold online (AGL-4060): a product sold in person only\n // has no page here, designed or built in, and falls through to the 404.\n const listedOnline = CommerceModel.productListedOnline(productRaw)\n if (pdpScreenId && listedOnline) {\n const product = CommerceModel.liftLegacyProduct(productRaw)\n const templateRes = await getScreen({\n hostId,\n screenId: pdpScreenId,\n // A PDP template renders against a routed PRODUCT, never at an address\n // of its own, so it is served here and 404s everywhere else (AGL-1400).\n allowTemplate: true,\n })\n if (templateRes.screen) {\n const [minPrice, maxPrice] = CommerceModel.productPriceRange(product)\n // Best-effort: a reviews read that fails costs the page its rating\n // snippet, not the page.\n const productReviews = await readProductReviews(\n hostId,\n productSnapshot.docs[0].id,\n ).catch((error) => {\n console.error('product review aggregate failed', error)\n return { reviews: [], aggregate: { count: 0, average: 0 } }\n })\n // The head shares this page as the template's image, then the site\n // default, so their documents are read in the template's own batch\n // (AGL-2850).\n const card = collectSocialImageFacts([\n (templateRes.screen as any).seo?.image,\n hostRes.host?.seo?.image,\n ])\n const templateNodes = await composeScreenNodes({\n hostId,\n screenId: pdpScreenId,\n screen: templateRes.screen,\n socialImages: card.socialImages,\n // The template's host variables, and its layout's, fill in from\n // this site as they do on every other page (AGL-2883).\n host: hostRes.host,\n tokens: {\n 'product.name': product.name,\n 'product.description': product.description ?? '',\n 'product.price': productPriceText(product, minPrice, maxPrice),\n 'product.image':\n product.mediaUrls?.[0] ?? product.imageUrl ?? '',\n 'product.slug': product.slug,\n },\n // Named as the product template it is if the page review holds it\n // (AGL-3374); without it the route has no page.\n page: {\n template: {\n role: 'entry',\n route: '/products/:slug',\n collectionName: 'Products',\n entryPath: `/products/${product.slug}`,\n fallback: 'not-found',\n },\n },\n })\n if (templateNodes) {\n return {\n props: JSON.parse(\n JSON.stringify({\n // The PDP block used to fetch this in an effect, so the\n // server rendered a skeleton and crawlers saw a product page\n // with no product in it (AGL-659). The product is already\n // loaded here — hand it down so it renders server-side.\n pageData: {\n commerce: {\n product: toPublicProductDetail(\n productSnapshot.docs[0].id,\n product,\n // The store's calendar, for a pass that asks for a day.\n { timeZone: await passDayTimeZone(hostId, hostRes.host, product) },\n ),\n // Rating aggregate (AGL-686): needed HERE because\n // `aggregateRating` belongs nested inside the Product\n // structured data, and that is emitted server-side.\n // The reviews block used to publish a free-standing\n // AggregateRating node, which schema.org ignores.\n ...(productReviews.aggregate.count\n ? { reviews: productReviews }\n : {}),\n },\n },\n data: {\n host: hostRes.host,\n screen: {\n data: {\n ...templateRes.screen,\n // The product NAMES this page; the template's own name\n // (\"Product detail\") describes none of the products it\n // renders. Kept distinct from the SEO title because the\n // head treats an authored title as verbatim and a name\n // as the side the site title joins (AGL-1341) — so a\n // product with its own SEO title gets exactly that, and\n // one without gets \"Blue Widget – Acme Store\".\n displayName: product.name,\n seo: {\n ...((templateRes.screen as any).seo ?? {}),\n // Only when the PRODUCT authored one: inheriting the\n // template screen's title would give every product\n // page in the store the same `<title>`.\n title: product.seo?.title ?? undefined,\n description:\n product.seo?.description ??\n product.description ??\n undefined,\n },\n },\n },\n },\n nodes: templateNodes,\n ...card.collected(),\n }),\n ),\n revalidate: 60,\n }\n }\n }\n }\n // No product template designated, or none that renders: the store's\n // built-in product page (AGL-3676), in the site's own header and footer,\n // rather than a 404 behind every card the product grid links. A store a\n // guided start built has no template of its own, and its grid links each\n // product here.\n if (listedOnline) {\n return composeBuiltInProductPage(\n hostId,\n host,\n productSnapshot.docs[0].id,\n CommerceModel.liftLegacyProduct(productRaw),\n storeSettings.get('returns'),\n )\n }\n }\n // Commerce collection routes (AGL-298): /collections/{slug} renders\n // the designated collection template with collection tokens; the\n // product-grid block derives the same slug from the URL.\n if (pdpSegments.length === 2 && pdpSegments[0] === 'collections') {\n const adminFirestore = firebaseAdmin.app().firestore()\n const hostDocRef = adminFirestore.collection('hosts').doc(hostId)\n const [storeSettings, collectionSnapshot] = await Promise.all([\n hostDocRef.collection('settings').doc('store').get(),\n hostDocRef\n .collection('collections')\n .where('slug', '==', pdpSegments[1])\n .limit(5)\n .get(),\n ])\n const collectionScreenId = storeSettings.get('collectionScreenId')\n // Content collections share this path and a slug is only unique within a\n // kind (AGL-954), so take the first CATALOG match rather than the first\n // doc — otherwise a blog with the same slug renders as a product page.\n const shopCollection = collectionSnapshot.docs\n .find((docSnapshot) => hostCollectionKind(docSnapshot.data()) === 'catalog')\n ?.data() as CommerceModel.HostCollection | undefined\n if (collectionScreenId && shopCollection) {\n const templateRes = await getScreen({\n hostId,\n screenId: collectionScreenId,\n allowTemplate: true,\n })\n if (templateRes.screen) {\n // As on the PDP above: the template's image, then the site default\n // (AGL-2850).\n const card = collectSocialImageFacts([\n (templateRes.screen as any).seo?.image,\n hostRes.host?.seo?.image,\n ])\n const templateNodes = await composeScreenNodes({\n hostId,\n screenId: collectionScreenId,\n screen: templateRes.screen,\n socialImages: card.socialImages,\n // As on the PDP above (AGL-2883).\n host: hostRes.host,\n tokens: {\n 'collection.name': shopCollection.name,\n 'collection.description': shopCollection.description ?? '',\n 'collection.image': shopCollection.imageUrl ?? '',\n 'collection.slug': shopCollection.slug,\n },\n // As on the PDP above (AGL-3374).\n page: {\n template: {\n role: 'entry',\n route: '/collections/:slug',\n collectionName: 'Store collections',\n entryPath: `/collections/${shopCollection.slug}`,\n fallback: 'not-found',\n },\n },\n })\n if (templateNodes) {\n return {\n props: JSON.parse(\n JSON.stringify({\n data: {\n host: hostRes.host,\n screen: {\n data: {\n ...templateRes.screen,\n // As on the PDP above: the catalog collection names the\n // page, and a name takes the site title after it while\n // an authored SEO title would not (AGL-1341). A shop\n // collection has no SEO title field of its own, so the\n // template's must not stand in for one.\n displayName: shopCollection.name,\n seo: {\n ...((templateRes.screen as any).seo ?? {}),\n title: undefined,\n description:\n shopCollection.description ?? undefined,\n },\n },\n },\n },\n nodes: templateNodes,\n ...card.collected(),\n }),\n ),\n revalidate: 60,\n }\n }\n }\n }\n }\n return undefined\n}\n\n/**\n * What `{{product.price}}` says: the price, \"From\" the lowest where variants\n * differ, or \"Price coming soon\" for a product listed before any variant has\n * one (AGL-3676) — never \"$0\".\n */\nexport function productPriceText(\n product: Pick<CommerceModel.HostProduct, 'variants'>,\n minPrice: number,\n maxPrice: number,\n): string {\n if (!(product.variants ?? []).some((variant) => CommerceModel.variantHasPrice(variant))) {\n return 'Price coming soon'\n }\n return minPrice === maxPrice ? `$${minPrice}` : `From $${minPrice}`\n}\n\nconst PRODUCT_PAGE_NODE = 'pdp__detail'\nconst PRODUCT_PAGE_REVIEWS_NODE = 'pdp__reviews'\nconst PRODUCT_PAGE_RELATED_NODE = 'pdp__related'\n\n/**\n * The store's built-in product page (AGL-3676), root first, for the layout's\n * slot: the product block for the routed slug — with its Details and\n * Shipping & returns folds under the description, as a designer theme's\n * product page has them — then the product's reviews where the store's plan\n * collects them, then the related products as a grid of photo cards.\n */\nexport function buildProductPageNodes(\n slug: string,\n options: { reviews?: boolean } = {},\n): Record<string, Aglyn.AglynNodeSchema> {\n const reviews = Boolean(options.reviews)\n return {\n [Aglyn.NODE_ROOT_ID]: {\n $id: Aglyn.NODE_ROOT_ID,\n componentId: 'div',\n nodes: ['pdp__container'],\n } as Aglyn.AglynNodeSchema,\n pdp__container: {\n $id: 'pdp__container',\n parentId: Aglyn.NODE_ROOT_ID,\n componentId: 'muiContainer',\n pluginId: 'mui',\n props: { maxWidth: 'lg', sx: { paddingTop: 6, paddingBottom: 10 } },\n nodes: [\n PRODUCT_PAGE_NODE,\n ...(reviews ? [PRODUCT_PAGE_REVIEWS_NODE] : []),\n PRODUCT_PAGE_RELATED_NODE,\n ],\n } as Aglyn.AglynNodeSchema,\n [PRODUCT_PAGE_NODE]: {\n $id: PRODUCT_PAGE_NODE,\n parentId: 'pdp__container',\n componentId: 'product-detail',\n pluginId: 'commerce',\n props: { slug, showDetails: true, showShipping: true },\n } as Aglyn.AglynNodeSchema,\n ...(reviews\n ? {\n [PRODUCT_PAGE_REVIEWS_NODE]: {\n $id: PRODUCT_PAGE_REVIEWS_NODE,\n parentId: 'pdp__container',\n componentId: 'product-reviews',\n pluginId: 'commerce',\n props: { heading: 'Reviews', sx: { marginTop: 8 } },\n } as Aglyn.AglynNodeSchema,\n }\n : {}),\n [PRODUCT_PAGE_RELATED_NODE]: {\n $id: PRODUCT_PAGE_RELATED_NODE,\n parentId: 'pdp__container',\n componentId: 'related-products',\n pluginId: 'commerce',\n props: {\n heading: 'You may also like',\n maxItems: 4,\n layout: 'grid',\n sx: { marginTop: 8 },\n },\n } as Aglyn.AglynNodeSchema,\n }\n}\n\n/**\n * The store's return window for this product, when the store takes returns of\n * its kind: the settings the return form enforces (`readReturnSettings`), so\n * the page never states a policy the store does not keep.\n */\nexport function productReturnWindow(\n product: Pick<CommerceModel.HostProduct, 'type'>,\n rawReturns: unknown,\n): { windowDays: number } | undefined {\n const settings = CommerceModel.readReturnSettings(rawReturns)\n if (!settings.enabled || settings.windowDays <= 0) return undefined\n if (!settings.eligibleTypes.includes(product.type ?? 'physical')) return undefined\n return { windowDays: settings.windowDays }\n}\n\n/** Whether the store's plan collects reviews; a failed read leaves them off. */\nasync function storeTakesReviews(hostId: string): Promise<boolean> {\n try {\n const org = await getOrgForHost(hostId)\n return Aglyn.checkEntitlement(org?.org as never, 'productReviews')\n } catch (error) {\n console.error('reviews entitlement read failed', error)\n return false\n }\n}\n\nasync function composeBuiltInProductPage(\n hostId: string,\n host: unknown,\n productId: string,\n product: ReturnType<typeof CommerceModel.liftLegacyProduct>,\n rawReturns?: unknown,\n) {\n try {\n const [layoutId, productReviews, reviewsOn] = await Promise.all([\n resolveBuiltInPageLayoutId({ hostId, host: host as never }),\n readProductReviews(hostId, productId).catch((error) => {\n console.error('product review aggregate failed', error)\n return { reviews: [], aggregate: { count: 0, average: 0 } }\n }),\n storeTakesReviews(hostId),\n ])\n const returns = productReturnWindow(product, rawReturns)\n const card = collectSocialImageFacts([\n product.mediaUrls?.[0] ?? product.imageUrl,\n (host as { seo?: { image?: string } } | null)?.seo?.image,\n ])\n const nodes = await composeNodesWithChrome({\n hostId,\n layoutId,\n screenNodes: buildProductPageNodes(product.slug, { reviews: reviewsOn }),\n socialImages: card.socialImages,\n host: host as Aglyn.HostTokenSource,\n })\n if (!nodes) return undefined\n return {\n props: JSON.parse(\n JSON.stringify({\n // Seeded, so the product renders server-side and the head writes\n // its Product structured data, as on a template page (AGL-659).\n pageData: {\n commerce: {\n product: toPublicProductDetail(productId, product, {\n timeZone: await passDayTimeZone(hostId, host, product),\n }),\n ...(productReviews.aggregate.count ? { reviews: productReviews } : {}),\n // The Shipping & returns fold's return line, only when the\n // store takes returns of this product's kind.\n ...(returns ? { returns } : {}),\n },\n },\n data: {\n host,\n screen: {\n data: {\n displayName: product.name,\n seo: {\n title: product.seo?.title ?? undefined,\n description: product.seo?.description ?? product.description ?? undefined,\n },\n },\n },\n },\n nodes,\n ...card.collected(),\n }),\n ),\n revalidate: 60,\n }\n } catch (error) {\n console.error('built-in product page composition failed', error)\n return undefined\n }\n}\n\nconst ORDER_STATUS_NODE = 'order-status__block'\n\n/** The order-status page's node tree, root first, for the layout's slot. */\nexport function buildOrderStatusNodes(): Record<string, Aglyn.AglynNodeSchema> {\n return {\n [Aglyn.NODE_ROOT_ID]: {\n $id: Aglyn.NODE_ROOT_ID,\n componentId: 'div',\n nodes: ['order-status__container'],\n } as Aglyn.AglynNodeSchema,\n 'order-status__container': {\n $id: 'order-status__container',\n parentId: Aglyn.NODE_ROOT_ID,\n componentId: 'muiContainer',\n pluginId: 'mui',\n props: { maxWidth: 'md', sx: { paddingTop: 6, paddingBottom: 8 } },\n nodes: [ORDER_STATUS_NODE],\n } as Aglyn.AglynNodeSchema,\n [ORDER_STATUS_NODE]: {\n $id: ORDER_STATUS_NODE,\n parentId: 'order-status__container',\n componentId: ORDER_STATUS_COMPONENT_ID,\n pluginId: 'commerce',\n props: {},\n } as Aglyn.AglynNodeSchema,\n }\n}\n\nasync function composeOrderStatusPage(hostId: string, host: unknown) {\n try {\n const layoutId = await resolveBuiltInPageLayoutId({ hostId, host: host as never })\n const nodes = await composeNodesWithChrome({\n hostId,\n layoutId,\n screenNodes: buildOrderStatusNodes(),\n host: host as Aglyn.HostTokenSource,\n })\n if (!nodes) return undefined\n return {\n props: JSON.parse(\n JSON.stringify({\n data: {\n host,\n screen: {\n data: {\n displayName: 'Order status',\n visibility: Aglyn.HostScreenVisibility.UNLISTED,\n },\n },\n },\n nodes,\n }),\n ),\n revalidate: 3600,\n }\n } catch (error) {\n console.error('order status page composition failed', error)\n return undefined\n }\n}\n\nconst RETURN_REQUEST_NODE = 'ret__block'\n\n/** The return form's node tree, root first, for the layout's slot. */\nexport function buildReturnRequestNodes(): Record<string, Aglyn.AglynNodeSchema> {\n return {\n [Aglyn.NODE_ROOT_ID]: {\n $id: Aglyn.NODE_ROOT_ID,\n componentId: 'div',\n nodes: ['ret__container'],\n } as Aglyn.AglynNodeSchema,\n ret__container: {\n $id: 'ret__container',\n parentId: Aglyn.NODE_ROOT_ID,\n componentId: 'muiContainer',\n pluginId: 'mui',\n props: { maxWidth: 'md', sx: { paddingTop: 6, paddingBottom: 8 } },\n nodes: [RETURN_REQUEST_NODE],\n } as Aglyn.AglynNodeSchema,\n [RETURN_REQUEST_NODE]: {\n $id: RETURN_REQUEST_NODE,\n parentId: 'ret__container',\n componentId: RETURN_REQUEST_COMPONENT_ID,\n pluginId: 'commerce',\n props: {},\n } as Aglyn.AglynNodeSchema,\n }\n}\n\nasync function composeReturnRequestPage(hostId: string, host: unknown) {\n try {\n const layoutId = await resolveBuiltInPageLayoutId({ hostId, host: host as never })\n const nodes = await composeNodesWithChrome({\n hostId,\n layoutId,\n screenNodes: buildReturnRequestNodes(),\n host: host as Aglyn.HostTokenSource,\n })\n if (!nodes) return undefined\n return {\n props: JSON.parse(\n JSON.stringify({\n data: {\n host,\n screen: {\n data: {\n displayName: 'Request a return',\n visibility: Aglyn.HostScreenVisibility.UNLISTED,\n },\n },\n },\n nodes,\n }),\n ),\n revalidate: 3600,\n }\n } catch (error) {\n console.error('return request page composition failed', error)\n return undefined\n }\n}\n\nconst QUOTE_PAGE_NODE = 'quote-page__block'\n\n/** The quote page's node tree, root first, for the layout's slot. */\nexport function buildQuotePageNodes(): Record<string, Aglyn.AglynNodeSchema> {\n return {\n [Aglyn.NODE_ROOT_ID]: {\n $id: Aglyn.NODE_ROOT_ID,\n componentId: 'div',\n nodes: ['quote-page__container'],\n } as Aglyn.AglynNodeSchema,\n 'quote-page__container': {\n $id: 'quote-page__container',\n parentId: Aglyn.NODE_ROOT_ID,\n componentId: 'muiContainer',\n pluginId: 'mui',\n props: { maxWidth: 'md', sx: { paddingTop: 6, paddingBottom: 8 } },\n nodes: [QUOTE_PAGE_NODE],\n } as Aglyn.AglynNodeSchema,\n [QUOTE_PAGE_NODE]: {\n $id: QUOTE_PAGE_NODE,\n parentId: 'quote-page__container',\n componentId: QUOTE_PAGE_COMPONENT_ID,\n pluginId: 'commerce',\n props: {},\n } as Aglyn.AglynNodeSchema,\n }\n}\n\nasync function composeQuotePage(hostId: string, host: unknown) {\n try {\n const layoutId = await resolveBuiltInPageLayoutId({ hostId, host: host as never })\n const nodes = await composeNodesWithChrome({\n hostId,\n layoutId,\n screenNodes: buildQuotePageNodes(),\n host: host as Aglyn.HostTokenSource,\n })\n if (!nodes) return undefined\n return {\n props: JSON.parse(\n JSON.stringify({\n data: {\n host,\n screen: {\n data: {\n // The page is the same for a quote's link and an invoice's (AGL-4099).\n displayName: 'Your quote or invoice',\n visibility: Aglyn.HostScreenVisibility.UNLISTED,\n },\n },\n },\n nodes,\n }),\n ),\n revalidate: 3600,\n }\n } catch (error) {\n console.error('quote page composition failed', error)\n return undefined\n }\n}\n\n/**\n * The store's time zone for a product page whose product asks for a use day\n * (AGL-4043), so the seeded page offers the same days the API's does; null\n * otherwise, without a read.\n */\nasync function passDayTimeZone(\n hostId: string,\n host: unknown,\n product: ReturnType<typeof CommerceModel.liftLegacyProduct>,\n): Promise<string | null> {\n if (!productAsksUseDateAnywhere(product)) return null\n const hostRef = firebaseAdmin.app().firestore().collection('hosts').doc(hostId)\n return (await readStoreDay(hostRef, { host: (host ?? null) as Record<string, unknown> | null })).timeZone\n}\n"],"names":["hostCollectionKind","composeScreenNodes","composeNodesWithChrome","resolveBuiltInPageLayoutId","Aglyn","ORDER_STATUS_PATH","ORDER_STATUS_COMPONENT_ID","RETURN_REQUEST_COMPONENT_ID","RETURN_REQUEST_PATH","QUOTE_PAGE_COMPONENT_ID","QUOTE_PAGE_PATH","getScreen","collectSocialImageFacts","firebaseAdmin","getOrgForHost","CommerceModel","productAsksUseDateAnywhere","toPublicProductDetail","readStoreDay","readProductReviews","commerceSitePageResolver","hostId","host","path","hostRes","pdpSegments","split","filter","Boolean","length","composeOrderStatusPage","composeReturnRequestPage","composeQuotePage","productSnapshot","adminFirestore","app","firestore","hostDocRef","collection","doc","storeSettings","Promise","all","get","where","limit","pdpScreenId","productRaw","docs","data","listedOnline","productListedOnline","product","liftLegacyProduct","templateRes","screenId","allowTemplate","screen","minPrice","maxPrice","productPriceRange","productReviews","id","catch","error","console","reviews","aggregate","count","average","card","seo","image","templateNodes","socialImages","tokens","name","description","productPriceText","mediaUrls","imageUrl","slug","page","template","role","route","collectionName","entryPath","fallback","props","JSON","parse","stringify","pageData","commerce","timeZone","passDayTimeZone","displayName","title","undefined","nodes","collected","revalidate","composeBuiltInProductPage","collectionSnapshot","collectionScreenId","shopCollection","find","docSnapshot","variants","some","variant","variantHasPrice","PRODUCT_PAGE_NODE","PRODUCT_PAGE_REVIEWS_NODE","PRODUCT_PAGE_RELATED_NODE","buildProductPageNodes","options","NODE_ROOT_ID","$id","componentId","pdp__container","parentId","pluginId","maxWidth","sx","paddingTop","paddingBottom","showDetails","showShipping","heading","marginTop","maxItems","layout","productReturnWindow","rawReturns","settings","readReturnSettings","enabled","windowDays","eligibleTypes","includes","type","storeTakesReviews","org","checkEntitlement","productId","layoutId","reviewsOn","returns","screenNodes","ORDER_STATUS_NODE","buildOrderStatusNodes","visibility","HostScreenVisibility","UNLISTED","RETURN_REQUEST_NODE","buildReturnRequestNodes","ret__container","QUOTE_PAGE_NODE","buildQuotePageNodes","hostRef"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SAASA,kBAAkB,QAAQ,sBAAqB;AACxD,OAAOC,sBACLC,sBAAsB,QACjB,6CAA4C;AACnD,SAASC,0BAA0B,QAAQ,6CAA4C;AACvF,YAAYC,WAAW,sBAAqB;AAC5C,SAASC,iBAAiB,Q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I,CAAC8E,OAAO,OAAOD;QACnB,OAAO;YACLV,OAAOC,KAAKC,KAAK,CACfD,KAAKE,SAAS,CAAC;gBACb3C,MAAM;oBACJ3B;oBACAmC,QAAQ;wBACNR,MAAM;4BACJ,uEAAuE;4BACvEgD,aAAa;4BACbwD,YAAYrJ,MAAMsJ,oBAAoB,CAACC,QAAQ;wBACjD;oBACF;gBACF;gBACAvD;YACF;YAEFE,YAAY;QACd;IACF,EAAE,OAAOtC,OAAO;QACdC,QAAQD,KAAK,CAAC,iCAAiCA;QAC/C,OAAOmC;IACT;AACF;AAEA;;;;CAIC,GACD,eAAeH,gBACb3E,MAAc,EACdC,IAAa,EACb8B,OAA2D;IAE3D,IAAI,CAACpC,2BAA2BoC,UAAU,OAAO;IACjD,MAAM6G,UAAUpJ,cAAcsB,GAAG,GAAGC,SAAS,GAAGE,UAAU,CAAC,SAASC,GAAG,CAAClB;IACxE,OAAO,AAAC,CAAA,MAAMH,aAAa+I,SAAS;QAAE3I,IAAI,EAAGA,eAAAA,OAAQ;IAAwC,EAAC,EAAGyE,QAAQ;AAC3G"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/site-page-resolver.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 type { SiteEditContextResolver, SitePageResolver } from '@aglyn/aglyn/server'\nimport { hostCollectionKind } from '@aglyn/aglyn/server'\nimport composeScreenNodes, {\n composeNodesWithChrome,\n} from '@aglyn/tenant-runtime/compose-screen-nodes'\nimport { resolveBuiltInPageLayoutId } from '@aglyn/tenant-runtime/built-in-page-layout'\nimport * as Aglyn from '@aglyn/aglyn/server'\nimport { ORDER_STATUS_PATH } from './order-status-token'\nimport { ORDER_STATUS_COMPONENT_ID } from '../constants/order-status'\nimport { RETURN_REQUEST_COMPONENT_ID, RETURN_REQUEST_PATH } from '../constants/return-request'\nimport { QUOTE_PAGE_COMPONENT_ID, QUOTE_PAGE_PATH } from '../constants/quote-page'\nimport getScreen from '@aglyn/tenant-runtime/get-screen'\nimport { collectSocialImageFacts } from '@aglyn/tenant-runtime/social-image-facts'\nimport { firebaseAdmin, getOrgForHost } from '@aglyn/tenant-data-admin'\nimport * as CommerceModel from '../model'\nimport { productAsksUseDateAnywhere, toPublicProductDetail } from './product'\nimport { readStoreDay } from './store-day'\nimport { readProductReviews } from './reviews'\nimport { productEditPath } from '../model/commerce-record-routes'\n\n/**\n * Commerce page resolver (AGL-292/298/418), relocated verbatim from the\n * tenant loader: /products/{slug} renders the host's designated PDP\n * template with product tokens, /collections/{slug} the collection\n * template — both compose server-side and return complete page props.\n * Runs only for paths that didn't match a published screen; returns\n * undefined for everything else so the loader falls through.\n */\nexport const commerceSitePageResolver: SitePageResolver = async ({\n hostId,\n host,\n path,\n}) => {\n const hostRes = { host }\n // Product detail routes (AGL-292): /products/{slug} renders the\n // host's designated PDP template screen (settings/store\n // `pdpScreenId`, AGL-295) with product tokens; the product-detail\n // block hydrates variants client-side from the same slug. Same\n // mechanism as entry-template screens below.\n const pdpSegments = path.split('/').filter(Boolean)\n // The guest order-status page (AGL-3610), at /order-status — reached only\n // when the site has no page of its own there. The site's header and footer\n // around the order-status block, which reads the signed `?o=&t=` link after\n // hydration, so this page holds no order and is safe to cache. UNLISTED, so\n // the head says noindex: it is a private page, not a landing page.\n if (pdpSegments.length === 1 && pdpSegments[0] === ORDER_STATUS_PATH) {\n return composeOrderStatusPage(hostId, host)\n }\n // The buyer's return form (AGL-3611), at /order-return, under the same\n // terms: no page of the site's own there, the order read after hydration\n // from the link's `?o=&t=` (or the member's session), UNLISTED.\n if (pdpSegments.length === 1 && pdpSegments[0] === RETURN_REQUEST_PATH) {\n return composeReturnRequestPage(hostId, host)\n }\n // The customer's quote page (AGL-4094), at /pay-quote, under the same\n // terms: no page of the site's own there, the quote read after hydration\n // from the pay link's `?q=&t=`, UNLISTED.\n if (pdpSegments.length === 1 && pdpSegments[0] === QUOTE_PAGE_PATH) {\n return composeQuotePage(hostId, host)\n }\n if (pdpSegments.length === 2 && pdpSegments[0] === 'products') {\n const adminFirestore = firebaseAdmin.app().firestore()\n const hostDocRef = adminFirestore.collection('hosts').doc(hostId)\n const [storeSettings, productSnapshot] = await Promise.all([\n hostDocRef.collection('settings').doc('store').get(),\n hostDocRef\n .collection('products')\n .where('slug', '==', pdpSegments[1])\n .limit(1)\n .get(),\n ])\n const pdpScreenId = storeSettings.get('pdpScreenId')\n const productRaw = productSnapshot.docs[0]?.data() as any\n // Live, active and sold online (AGL-4060): a product sold in person only\n // has no page here, designed or built in, and falls through to the 404.\n const listedOnline = CommerceModel.productListedOnline(productRaw)\n if (pdpScreenId && listedOnline) {\n const product = CommerceModel.liftLegacyProduct(productRaw)\n const templateRes = await getScreen({\n hostId,\n screenId: pdpScreenId,\n // A PDP template renders against a routed PRODUCT, never at an address\n // of its own, so it is served here and 404s everywhere else (AGL-1400).\n allowTemplate: true,\n })\n if (templateRes.screen) {\n const [minPrice, maxPrice] = CommerceModel.productPriceRange(product)\n // Best-effort: a reviews read that fails costs the page its rating\n // snippet, not the page.\n const productReviews = await readProductReviews(\n hostId,\n productSnapshot.docs[0].id,\n ).catch((error) => {\n console.error('product review aggregate failed', error)\n return { reviews: [], aggregate: { count: 0, average: 0 } }\n })\n // The head shares this page as the template's image, then the site\n // default, so their documents are read in the template's own batch\n // (AGL-2850).\n const shareImage = productShareImage(product)\n const card = collectSocialImageFacts([\n // Only when there is one: the list is the card's precedence.\n ...(shareImage ? [shareImage] : []),\n (templateRes.screen as any).seo?.image,\n hostRes.host?.seo?.image,\n ])\n const templateNodes = await composeScreenNodes({\n hostId,\n screenId: pdpScreenId,\n screen: templateRes.screen,\n socialImages: card.socialImages,\n // The template's host variables, and its layout's, fill in from\n // this site as they do on every other page (AGL-2883).\n host: hostRes.host,\n tokens: {\n 'product.name': product.name,\n 'product.description': product.description ?? '',\n 'product.price': CommerceModel.productPriceText(product, minPrice, maxPrice),\n 'product.image':\n product.mediaUrls?.[0] ?? product.imageUrl ?? '',\n 'product.slug': product.slug,\n },\n // Named as the product template it is if the page review holds it\n // (AGL-3374); without it the route has no page.\n page: {\n template: {\n role: 'entry',\n route: '/products/:slug',\n collectionName: 'Products',\n entryPath: `/products/${product.slug}`,\n fallback: 'not-found',\n },\n },\n })\n if (templateNodes) {\n return {\n props: JSON.parse(\n JSON.stringify({\n // The PDP block used to fetch this in an effect, so the\n // server rendered a skeleton and crawlers saw a product page\n // with no product in it (AGL-659). The product is already\n // loaded here — hand it down so it renders server-side.\n pageData: {\n commerce: {\n product: toPublicProductDetail(\n productSnapshot.docs[0].id,\n product,\n // The store's calendar, for a pass that asks for a day.\n { timeZone: await passDayTimeZone(hostId, hostRes.host, product) },\n ),\n // Rating aggregate (AGL-686): needed HERE because\n // `aggregateRating` belongs nested inside the Product\n // structured data, and that is emitted server-side.\n // The reviews block used to publish a free-standing\n // AggregateRating node, which schema.org ignores.\n ...(productReviews.aggregate.count\n ? { reviews: productReviews }\n : {}),\n },\n },\n data: {\n host: hostRes.host,\n screen: {\n data: {\n ...templateRes.screen,\n // The product NAMES this page; the template's own name\n // (\"Product detail\") describes none of the products it\n // renders. Kept distinct from the SEO title because the\n // head treats an authored title as verbatim and a name\n // as the side the site title joins (AGL-1341) — so a\n // product with its own SEO title gets exactly that, and\n // one without gets \"Blue Widget – Acme Store\".\n displayName: product.name,\n seo: {\n ...((templateRes.screen as any).seo ?? {}),\n ...shareCard(shareImage, product.name),\n // Only when the PRODUCT authored one: inheriting the\n // template screen's title would give every product\n // page in the store the same `<title>`.\n title: product.seo?.title ?? undefined,\n description:\n product.seo?.description ??\n product.description ??\n undefined,\n },\n },\n },\n },\n nodes: templateNodes,\n ...card.collected(),\n }),\n ),\n revalidate: 60,\n }\n }\n }\n }\n // No product template designated, or none that renders: the store's\n // built-in product page (AGL-3676), in the site's own header and footer,\n // rather than a 404 behind every card the product grid links. A store a\n // guided start built has no template of its own, and its grid links each\n // product here.\n if (listedOnline) {\n return composeBuiltInProductPage(\n hostId,\n host,\n productSnapshot.docs[0].id,\n CommerceModel.liftLegacyProduct(productRaw),\n storeSettings.get('returns'),\n )\n }\n }\n // Commerce collection routes (AGL-298): /collections/{slug} renders\n // the designated collection template with collection tokens; the\n // product-grid block derives the same slug from the URL.\n if (pdpSegments.length === 2 && pdpSegments[0] === 'collections') {\n const adminFirestore = firebaseAdmin.app().firestore()\n const hostDocRef = adminFirestore.collection('hosts').doc(hostId)\n const [storeSettings, collectionSnapshot] = await Promise.all([\n hostDocRef.collection('settings').doc('store').get(),\n hostDocRef\n .collection('collections')\n .where('slug', '==', pdpSegments[1])\n .limit(5)\n .get(),\n ])\n const collectionScreenId = storeSettings.get('collectionScreenId')\n // Content collections share this path and a slug is only unique within a\n // kind (AGL-954), so take the first CATALOG match rather than the first\n // doc — otherwise a blog with the same slug renders as a product page.\n const shopCollection = collectionSnapshot.docs\n .find((docSnapshot) => hostCollectionKind(docSnapshot.data()) === 'catalog')\n ?.data() as CommerceModel.HostCollection | undefined\n if (collectionScreenId && shopCollection) {\n const templateRes = await getScreen({\n hostId,\n screenId: collectionScreenId,\n allowTemplate: true,\n })\n if (templateRes.screen) {\n // As on the PDP above: the template's image, then the site default\n // (AGL-2850).\n const shareImage = shopCollection.imageUrl || undefined\n const card = collectSocialImageFacts([\n // Only when there is one: the list is the card's precedence.\n ...(shareImage ? [shareImage] : []),\n (templateRes.screen as any).seo?.image,\n hostRes.host?.seo?.image,\n ])\n const templateNodes = await composeScreenNodes({\n hostId,\n screenId: collectionScreenId,\n screen: templateRes.screen,\n socialImages: card.socialImages,\n // As on the PDP above (AGL-2883).\n host: hostRes.host,\n tokens: {\n 'collection.name': shopCollection.name,\n 'collection.description': shopCollection.description ?? '',\n 'collection.image': shopCollection.imageUrl ?? '',\n 'collection.slug': shopCollection.slug,\n },\n // As on the PDP above (AGL-3374).\n page: {\n template: {\n role: 'entry',\n route: '/collections/:slug',\n collectionName: 'Store collections',\n entryPath: `/collections/${shopCollection.slug}`,\n fallback: 'not-found',\n },\n },\n })\n if (templateNodes) {\n return {\n props: JSON.parse(\n JSON.stringify({\n data: {\n host: hostRes.host,\n screen: {\n data: {\n ...templateRes.screen,\n // As on the PDP above: the catalog collection names the\n // page, and a name takes the site title after it while\n // an authored SEO title would not (AGL-1341). A shop\n // collection has no SEO title field of its own, so the\n // template's must not stand in for one.\n displayName: shopCollection.name,\n seo: {\n ...((templateRes.screen as any).seo ?? {}),\n ...shareCard(shareImage, shopCollection.name),\n title: undefined,\n description:\n shopCollection.description ?? undefined,\n },\n },\n },\n },\n nodes: templateNodes,\n ...card.collected(),\n }),\n ),\n revalidate: 60,\n }\n }\n }\n }\n }\n return undefined\n}\n\n/**\n * What the admin edit bar says on the pages the resolver above composes. They\n * are in no routing map, so the bar called a product page \"Unrouted page\" with\n * no edit link. It answers from the same reads the page is built from: the\n * store's designated template (`pdpScreenId`, `collectionScreenId`), and for\n * a product page the product itself, whose editor the bar links beside the\n * template's Besigner, as it does for a blog post. A product the page would\n * not render (not live, or not sold online) gets no answer, as it gets no\n * page.\n */\nexport const commerceEditContextResolver: SiteEditContextResolver = async ({\n hostId,\n path,\n}) => {\n const segments = path.split('/').filter(Boolean)\n if (segments.length !== 2) return undefined\n const [section, slug] = segments\n if (section !== 'products' && section !== 'collections') return undefined\n const hostDocRef = firebaseAdmin.app().firestore().collection('hosts').doc(hostId)\n const storeSettings = await hostDocRef.collection('settings').doc('store').get()\n const screenField = (name: string) => {\n const value = storeSettings.get(name)\n return typeof value === 'string' && value ? value : null\n }\n if (section === 'products') {\n const productSnapshot = await hostDocRef\n .collection('products')\n .where('slug', '==', slug)\n .limit(1)\n .get()\n const productDoc = productSnapshot.docs[0]\n if (!productDoc || !CommerceModel.productListedOnline(productDoc.data() as any)) {\n return undefined\n }\n return {\n templateScreenId: screenField('pdpScreenId'),\n collectionName: 'Products',\n entry: true,\n entryNoun: 'product',\n recordEditPath: productEditPath(productDoc.id),\n }\n }\n const collectionSnapshot = await hostDocRef\n .collection('collections')\n .where('slug', '==', slug)\n .limit(5)\n .get()\n const shopCollection = collectionSnapshot.docs.find(\n (docSnapshot) => hostCollectionKind(docSnapshot.data()) === 'catalog',\n )\n const templateScreenId = screenField('collectionScreenId')\n // Without a template the page is not served (no built-in collection page).\n if (!shopCollection || !templateScreenId) return undefined\n return {\n templateScreenId,\n collectionName: 'Store collections',\n entry: true,\n entryNoun: 'collection',\n recordEditPath: null,\n }\n}\n\n// What `{{product.price}}` says (AGL-3676) lives with the model now, so the\n// site's search can caption a product the same way without loading this page.\nexport { productPriceText } from '../model'\n\nconst PRODUCT_PAGE_NODE = 'pdp__detail'\nconst PRODUCT_PAGE_REVIEWS_NODE = 'pdp__reviews'\nconst PRODUCT_PAGE_RELATED_NODE = 'pdp__related'\n\n/**\n * The store's built-in product page (AGL-3676), root first, for the layout's\n * slot: the product block for the routed slug — with its Details and\n * Shipping & returns folds under the description, as a designer theme's\n * product page has them — then the product's reviews where the store's plan\n * collects them, then the related products as a grid of photo cards.\n */\nexport function buildProductPageNodes(\n slug: string,\n options: { reviews?: boolean } = {},\n): Record<string, Aglyn.AglynNodeSchema> {\n const reviews = Boolean(options.reviews)\n return {\n [Aglyn.NODE_ROOT_ID]: {\n $id: Aglyn.NODE_ROOT_ID,\n componentId: 'div',\n nodes: ['pdp__container'],\n } as Aglyn.AglynNodeSchema,\n pdp__container: {\n $id: 'pdp__container',\n parentId: Aglyn.NODE_ROOT_ID,\n componentId: 'muiContainer',\n pluginId: 'mui',\n props: { maxWidth: 'lg', sx: { paddingTop: 6, paddingBottom: 10 } },\n nodes: [\n PRODUCT_PAGE_NODE,\n ...(reviews ? [PRODUCT_PAGE_REVIEWS_NODE] : []),\n PRODUCT_PAGE_RELATED_NODE,\n ],\n } as Aglyn.AglynNodeSchema,\n [PRODUCT_PAGE_NODE]: {\n $id: PRODUCT_PAGE_NODE,\n parentId: 'pdp__container',\n componentId: 'product-detail',\n pluginId: 'commerce',\n props: { slug, showDetails: true, showShipping: true },\n } as Aglyn.AglynNodeSchema,\n ...(reviews\n ? {\n [PRODUCT_PAGE_REVIEWS_NODE]: {\n $id: PRODUCT_PAGE_REVIEWS_NODE,\n parentId: 'pdp__container',\n componentId: 'product-reviews',\n pluginId: 'commerce',\n props: { heading: 'Reviews', sx: { marginTop: 8 } },\n } as Aglyn.AglynNodeSchema,\n }\n : {}),\n [PRODUCT_PAGE_RELATED_NODE]: {\n $id: PRODUCT_PAGE_RELATED_NODE,\n parentId: 'pdp__container',\n componentId: 'related-products',\n pluginId: 'commerce',\n props: {\n heading: 'You may also like',\n maxItems: 4,\n layout: 'grid',\n sx: { marginTop: 8 },\n },\n } as Aglyn.AglynNodeSchema,\n }\n}\n\n/**\n * The store's return window for this product, when the store takes returns of\n * its kind: the settings the return form enforces (`readReturnSettings`), so\n * the page never states a policy the store does not keep.\n */\nexport function productReturnWindow(\n product: Pick<CommerceModel.HostProduct, 'type'>,\n rawReturns: unknown,\n): { windowDays: number } | undefined {\n const settings = CommerceModel.readReturnSettings(rawReturns)\n if (!settings.enabled || settings.windowDays <= 0) return undefined\n if (!settings.eligibleTypes.includes(product.type ?? 'physical')) return undefined\n return { windowDays: settings.windowDays }\n}\n\n/** Whether the store's plan collects reviews; a failed read leaves them off. */\nasync function storeTakesReviews(hostId: string): Promise<boolean> {\n try {\n const org = await getOrgForHost(hostId)\n return Aglyn.checkEntitlement(org?.org as never, 'productReviews')\n } catch (error) {\n console.error('reviews entitlement read failed', error)\n return false\n }\n}\n\nasync function composeBuiltInProductPage(\n hostId: string,\n host: unknown,\n productId: string,\n product: ReturnType<typeof CommerceModel.liftLegacyProduct>,\n rawReturns?: unknown,\n) {\n try {\n const [layoutId, productReviews, reviewsOn] = await Promise.all([\n resolveBuiltInPageLayoutId({ hostId, host: host as never }),\n readProductReviews(hostId, productId).catch((error) => {\n console.error('product review aggregate failed', error)\n return { reviews: [], aggregate: { count: 0, average: 0 } }\n }),\n storeTakesReviews(hostId),\n ])\n const returns = productReturnWindow(product, rawReturns)\n const shareImage = productShareImage(product)\n const card = collectSocialImageFacts([\n ...(shareImage ? [shareImage] : []),\n (host as { seo?: { image?: string } } | null)?.seo?.image,\n ])\n const nodes = await composeNodesWithChrome({\n hostId,\n layoutId,\n screenNodes: buildProductPageNodes(product.slug, { reviews: reviewsOn }),\n socialImages: card.socialImages,\n host: host as Aglyn.HostTokenSource,\n })\n if (!nodes) return undefined\n return {\n props: JSON.parse(\n JSON.stringify({\n // Seeded, so the product renders server-side and the head writes\n // its Product structured data, as on a template page (AGL-659).\n pageData: {\n commerce: {\n product: toPublicProductDetail(productId, product, {\n timeZone: await passDayTimeZone(hostId, host, product),\n }),\n ...(productReviews.aggregate.count ? { reviews: productReviews } : {}),\n // The Shipping & returns fold's return line, only when the\n // store takes returns of this product's kind.\n ...(returns ? { returns } : {}),\n },\n },\n data: {\n host,\n screen: {\n data: {\n displayName: product.name,\n seo: {\n ...shareCard(shareImage, product.name),\n title: product.seo?.title ?? undefined,\n description: product.seo?.description ?? product.description ?? undefined,\n },\n },\n },\n },\n nodes,\n ...card.collected(),\n }),\n ),\n revalidate: 60,\n }\n } catch (error) {\n console.error('built-in product page composition failed', error)\n return undefined\n }\n}\n\nconst ORDER_STATUS_NODE = 'order-status__block'\n\n/** The order-status page's node tree, root first, for the layout's slot. */\nexport function buildOrderStatusNodes(): Record<string, Aglyn.AglynNodeSchema> {\n return {\n [Aglyn.NODE_ROOT_ID]: {\n $id: Aglyn.NODE_ROOT_ID,\n componentId: 'div',\n nodes: ['order-status__container'],\n } as Aglyn.AglynNodeSchema,\n 'order-status__container': {\n $id: 'order-status__container',\n parentId: Aglyn.NODE_ROOT_ID,\n componentId: 'muiContainer',\n pluginId: 'mui',\n props: { maxWidth: 'md', sx: { paddingTop: 6, paddingBottom: 8 } },\n nodes: [ORDER_STATUS_NODE],\n } as Aglyn.AglynNodeSchema,\n [ORDER_STATUS_NODE]: {\n $id: ORDER_STATUS_NODE,\n parentId: 'order-status__container',\n componentId: ORDER_STATUS_COMPONENT_ID,\n pluginId: 'commerce',\n props: {},\n } as Aglyn.AglynNodeSchema,\n }\n}\n\n/**\n * The image a product page shares: the one picked in the product editor's\n * \"OG image\" field (`seo.imageUrl`), else the product's first photo.\n *\n * Both product pages used to share the template's image, then the site\n * default, so every product in a store shared one card and the editor's\n * OG image was saved and never read. A product's own photo is the most\n * specific card there is; the template's image stays the fallback for a\n * product with no photo.\n */\nfunction productShareImage(product: CommerceModel.HostProduct): string | undefined {\n return product.seo?.imageUrl || product.mediaUrls?.[0] || product.imageUrl || undefined\n}\n\n/**\n * The page's own card fields for a routed product or collection image.\n *\n * The template's pixel pair and alt describe the template's image, not this\n * one, so they are cleared beside it: a stale 1200x630 on a square product\n * photo is a wrong claim, and no pair is an honest one. The alt names what\n * the page is about. Nothing when there is no image, so the template's card\n * stands.\n */\nfunction shareCard(image: string | undefined, name: string | undefined) {\n if (!image) return {}\n return {\n image,\n imageWidth: undefined,\n imageHeight: undefined,\n imageAlt: name || undefined,\n }\n}\n\nasync function composeOrderStatusPage(hostId: string, host: unknown) {\n try {\n const layoutId = await resolveBuiltInPageLayoutId({ hostId, host: host as never })\n const nodes = await composeNodesWithChrome({\n hostId,\n layoutId,\n screenNodes: buildOrderStatusNodes(),\n host: host as Aglyn.HostTokenSource,\n })\n if (!nodes) return undefined\n return {\n props: JSON.parse(\n JSON.stringify({\n data: {\n host,\n screen: {\n data: {\n displayName: 'Order status',\n visibility: Aglyn.HostScreenVisibility.UNLISTED,\n },\n },\n },\n nodes,\n }),\n ),\n revalidate: 3600,\n }\n } catch (error) {\n console.error('order status page composition failed', error)\n return undefined\n }\n}\n\nconst RETURN_REQUEST_NODE = 'ret__block'\n\n/** The return form's node tree, root first, for the layout's slot. */\nexport function buildReturnRequestNodes(): Record<string, Aglyn.AglynNodeSchema> {\n return {\n [Aglyn.NODE_ROOT_ID]: {\n $id: Aglyn.NODE_ROOT_ID,\n componentId: 'div',\n nodes: ['ret__container'],\n } as Aglyn.AglynNodeSchema,\n ret__container: {\n $id: 'ret__container',\n parentId: Aglyn.NODE_ROOT_ID,\n componentId: 'muiContainer',\n pluginId: 'mui',\n props: { maxWidth: 'md', sx: { paddingTop: 6, paddingBottom: 8 } },\n nodes: [RETURN_REQUEST_NODE],\n } as Aglyn.AglynNodeSchema,\n [RETURN_REQUEST_NODE]: {\n $id: RETURN_REQUEST_NODE,\n parentId: 'ret__container',\n componentId: RETURN_REQUEST_COMPONENT_ID,\n pluginId: 'commerce',\n props: {},\n } as Aglyn.AglynNodeSchema,\n }\n}\n\nasync function composeReturnRequestPage(hostId: string, host: unknown) {\n try {\n const layoutId = await resolveBuiltInPageLayoutId({ hostId, host: host as never })\n const nodes = await composeNodesWithChrome({\n hostId,\n layoutId,\n screenNodes: buildReturnRequestNodes(),\n host: host as Aglyn.HostTokenSource,\n })\n if (!nodes) return undefined\n return {\n props: JSON.parse(\n JSON.stringify({\n data: {\n host,\n screen: {\n data: {\n displayName: 'Request a return',\n visibility: Aglyn.HostScreenVisibility.UNLISTED,\n },\n },\n },\n nodes,\n }),\n ),\n revalidate: 3600,\n }\n } catch (error) {\n console.error('return request page composition failed', error)\n return undefined\n }\n}\n\nconst QUOTE_PAGE_NODE = 'quote-page__block'\n\n/** The quote page's node tree, root first, for the layout's slot. */\nexport function buildQuotePageNodes(): Record<string, Aglyn.AglynNodeSchema> {\n return {\n [Aglyn.NODE_ROOT_ID]: {\n $id: Aglyn.NODE_ROOT_ID,\n componentId: 'div',\n nodes: ['quote-page__container'],\n } as Aglyn.AglynNodeSchema,\n 'quote-page__container': {\n $id: 'quote-page__container',\n parentId: Aglyn.NODE_ROOT_ID,\n componentId: 'muiContainer',\n pluginId: 'mui',\n props: { maxWidth: 'md', sx: { paddingTop: 6, paddingBottom: 8 } },\n nodes: [QUOTE_PAGE_NODE],\n } as Aglyn.AglynNodeSchema,\n [QUOTE_PAGE_NODE]: {\n $id: QUOTE_PAGE_NODE,\n parentId: 'quote-page__container',\n componentId: QUOTE_PAGE_COMPONENT_ID,\n pluginId: 'commerce',\n props: {},\n } as Aglyn.AglynNodeSchema,\n }\n}\n\nasync function composeQuotePage(hostId: string, host: unknown) {\n try {\n const layoutId = await resolveBuiltInPageLayoutId({ hostId, host: host as never })\n const nodes = await composeNodesWithChrome({\n hostId,\n layoutId,\n screenNodes: buildQuotePageNodes(),\n host: host as Aglyn.HostTokenSource,\n })\n if (!nodes) return undefined\n return {\n props: JSON.parse(\n JSON.stringify({\n data: {\n host,\n screen: {\n data: {\n // The page is the same for a quote's link and an invoice's (AGL-4099).\n displayName: 'Your quote or invoice',\n visibility: Aglyn.HostScreenVisibility.UNLISTED,\n },\n },\n },\n nodes,\n }),\n ),\n revalidate: 3600,\n }\n } catch (error) {\n console.error('quote page composition failed', error)\n return undefined\n }\n}\n\n/**\n * The store's time zone for a product page whose product asks for a use day\n * (AGL-4043), so the seeded page offers the same days the API's does; null\n * otherwise, without a read.\n */\nasync function passDayTimeZone(\n hostId: string,\n host: unknown,\n product: ReturnType<typeof CommerceModel.liftLegacyProduct>,\n): Promise<string | null> {\n if (!productAsksUseDateAnywhere(product)) return null\n const hostRef = firebaseAdmin.app().firestore().collection('hosts').doc(hostId)\n return (await readStoreDay(hostRef, { host: (host ?? null) as Record<string, unknown> | null })).timeZone\n}\n"],"names":["hostCollectionKind","composeScreenNodes","composeNodesWithChrome","resolveBuiltInPageLayoutId","Aglyn","ORDER_STATUS_PATH","ORDER_STATUS_COMPONENT_ID","RETURN_REQUEST_COMPONENT_ID","RETURN_REQUEST_PATH","QUOTE_PAGE_COMPONENT_ID","QUOTE_PAGE_PATH","getScreen","collectSocialImageFacts","firebaseAdmin","getOrgForHost","CommerceModel","productAsksUseDateAnywhere","toPublicProductDetail","readStoreDay","readProductReviews","productEditPath","commerceSitePageResolver","hostId","host","path","hostRes","pdpSegments","split","filter","Boolean","length","composeOrderStatusPage","composeReturnRequestPage","composeQuotePage","productSnapshot","adminFirestore","app","firestore","hostDocRef","collection","doc","storeSettings","Promise","all","get","where","limit","pdpScreenId","productRaw","docs","data","listedOnline","productListedOnline","product","liftLegacyProduct","templateRes","screenId","allowTemplate","screen","minPrice","maxPrice","productPriceRange","productReviews","id","catch","error","console","reviews","aggregate","count","average","shareImage","productShareImage","card","seo","image","templateNodes","socialImages","tokens","name","description","productPriceText","mediaUrls","imageUrl","slug","page","template","role","route","collectionName","entryPath","fallback","props","JSON","parse","stringify","pageData","commerce","timeZone","passDayTimeZone","displayName","shareCard","title","undefined","nodes","collected","revalidate","composeBuiltInProductPage","collectionSnapshot","collectionScreenId","shopCollection","find","docSnapshot","commerceEditContextResolver","segments","section","screenField","value","productDoc","templateScreenId","entry","entryNoun","recordEditPath","PRODUCT_PAGE_NODE","PRODUCT_PAGE_REVIEWS_NODE","PRODUCT_PAGE_RELATED_NODE","buildProductPageNodes","options","NODE_ROOT_ID","$id","componentId","pdp__container","parentId","pluginId","maxWidth","sx","paddingTop","paddingBottom","showDetails","showShipping","heading","marginTop","maxItems","layout","productReturnWindow","rawReturns","settings","readReturnSettings","enabled","windowDays","eligibleTypes","includes","type","storeTakesReviews","org","checkEntitlement","productId","layoutId","reviewsOn","returns","screenNodes","ORDER_STATUS_NODE","buildOrderStatusNodes","imageWidth","imageHeight","imageAlt","visibility","HostScreenVisibility","UNLISTED","RETURN_REQUEST_NODE","buildReturnRequestNodes","ret__container","QUOTE_PAGE_NODE","buildQuotePageNodes","hostRef"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SAASA,kBAAkB,QAAQ,sBAAqB;AACxD,OAAOC,sBACLC,sBAAsB,QACjB,6CAA4C;AACnD,SAAS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,OAAO;IACjD,MAAMyH,UAAUjK,cAAcuB,GAAG,GAAGC,SAAS,GAAGE,UAAU,CAAC,SAASC,GAAG,CAAClB;IACxE,OAAO,AAAC,CAAA,MAAMJ,aAAa4J,SAAS;QAAEvJ,IAAI,EAAGA,eAAAA,OAAQ;IAAwC,EAAC,EAAG2E,QAAQ;AAC3G"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { PluginSiteSearchItem, PluginSiteSearchSource } from '@aglyn/aglyn/plugin-manager/plugin-site-search';
|
|
18
|
+
/**
|
|
19
|
+
* THE STORE'S PRODUCTS IN THE SITE'S OWN SEARCH: core's `core.site-search`
|
|
20
|
+
* contract, answered from this plugin's products.
|
|
21
|
+
*
|
|
22
|
+
* What a visitor may find is what the storefront lists: live, active and
|
|
23
|
+
* sold online (`productListedOnline`), and never a guided start's sample.
|
|
24
|
+
* The search page matches the typed words; this only hands it candidates.
|
|
25
|
+
*
|
|
26
|
+
* Two bounded reads, merged:
|
|
27
|
+
*
|
|
28
|
+
* - the storefront's own scope (`deletedAt == null`, `status == 'active'`),
|
|
29
|
+
* capped at {@link SCAN_LIMIT} products, which the search page's fuzzy
|
|
30
|
+
* matcher forgives a typo over;
|
|
31
|
+
* - the products whose name has a word starting with the query's first word
|
|
32
|
+
* (`nameTokens`, the storefront grid's search key), so a catalog larger
|
|
33
|
+
* than the scan still finds a product by its name.
|
|
34
|
+
*
|
|
35
|
+
* Category names are read only when a candidate names a category.
|
|
36
|
+
*/
|
|
37
|
+
/** Products the scope read reaches; a store's whole catalog, for most. */
|
|
38
|
+
export declare const SCAN_LIMIT = 250;
|
|
39
|
+
/** Products the name-token read reaches beyond the scan. */
|
|
40
|
+
export declare const TOKEN_LIMIT = 50;
|
|
41
|
+
/** One listed product as the search page matches and shows it, or `null`. */
|
|
42
|
+
export declare function productSiteSearchItem(productId: string, data: Record<string, any>, categoryNames?: ReadonlyMap<string, string>): PluginSiteSearchItem | null;
|
|
43
|
+
export declare const commerceSiteSearch: PluginSiteSearchSource;
|
|
@@ -0,0 +1,124 @@
|
|
|
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 { nameSearchToken } from "@aglyn/aglyn/app-utils/name-search";
|
|
18
|
+
import { firebaseAdmin } from "@aglyn/tenant-data-admin/server/firebase-admin";
|
|
19
|
+
import * as CommerceModel from "../model/index.js";
|
|
20
|
+
import { productCard } from "./product-card.js";
|
|
21
|
+
import { plainDescription } from "./product-catalog.js";
|
|
22
|
+
/**
|
|
23
|
+
* THE STORE'S PRODUCTS IN THE SITE'S OWN SEARCH: core's `core.site-search`
|
|
24
|
+
* contract, answered from this plugin's products.
|
|
25
|
+
*
|
|
26
|
+
* What a visitor may find is what the storefront lists: live, active and
|
|
27
|
+
* sold online (`productListedOnline`), and never a guided start's sample.
|
|
28
|
+
* The search page matches the typed words; this only hands it candidates.
|
|
29
|
+
*
|
|
30
|
+
* Two bounded reads, merged:
|
|
31
|
+
*
|
|
32
|
+
* - the storefront's own scope (`deletedAt == null`, `status == 'active'`),
|
|
33
|
+
* capped at {@link SCAN_LIMIT} products, which the search page's fuzzy
|
|
34
|
+
* matcher forgives a typo over;
|
|
35
|
+
* - the products whose name has a word starting with the query's first word
|
|
36
|
+
* (`nameTokens`, the storefront grid's search key), so a catalog larger
|
|
37
|
+
* than the scan still finds a product by its name.
|
|
38
|
+
*
|
|
39
|
+
* Category names are read only when a candidate names a category.
|
|
40
|
+
*/ /** Products the scope read reaches; a store's whole catalog, for most. */ export const SCAN_LIMIT = 250;
|
|
41
|
+
/** Products the name-token read reaches beyond the scan. */ export const TOKEN_LIMIT = 50;
|
|
42
|
+
/** Categories read for their names. */ const CATEGORY_LIMIT = 200;
|
|
43
|
+
const SNIPPET_LENGTH = 160;
|
|
44
|
+
const str = (value)=>typeof value === 'string' ? value : '';
|
|
45
|
+
const isDocumentId = (value)=>Boolean(value) && value.length <= 200 && !value.includes('/') && !/^__.*__$/.test(value);
|
|
46
|
+
/** One listed product as the search page matches and shows it, or `null`. */ export function productSiteSearchItem(productId, data, categoryNames = new Map()) {
|
|
47
|
+
var _product_variants;
|
|
48
|
+
if (!CommerceModel.productListedOnline(data)) return null;
|
|
49
|
+
if (CommerceModel.productIsSample(data)) return null;
|
|
50
|
+
const card = productCard(productId, data);
|
|
51
|
+
// A product with no slug has no page, so there is nothing to link to.
|
|
52
|
+
if (!card.path) return null;
|
|
53
|
+
const product = CommerceModel.liftLegacyProduct(data);
|
|
54
|
+
const [minPrice, maxPrice] = CommerceModel.productPriceRange(product);
|
|
55
|
+
const description = plainDescription(data['description']);
|
|
56
|
+
const words = (values)=>Array.isArray(values) ? values.map(str).filter(Boolean) : [];
|
|
57
|
+
const terms = [
|
|
58
|
+
description,
|
|
59
|
+
str(data['slug']),
|
|
60
|
+
...((_product_variants = product.variants) != null ? _product_variants : []).map((variant)=>str(variant.sku)).filter(Boolean),
|
|
61
|
+
...words(data['tags']),
|
|
62
|
+
...words(data['categoryIds']).map((id)=>{
|
|
63
|
+
var _categoryNames_get;
|
|
64
|
+
return (_categoryNames_get = categoryNames.get(id)) != null ? _categoryNames_get : '';
|
|
65
|
+
}).filter(Boolean)
|
|
66
|
+
].filter(Boolean);
|
|
67
|
+
return _extends({
|
|
68
|
+
title: card.title,
|
|
69
|
+
terms,
|
|
70
|
+
url: card.path,
|
|
71
|
+
snippet: description.replace(/\s+/g, ' ').slice(0, SNIPPET_LENGTH)
|
|
72
|
+
}, card.imageUrl ? {
|
|
73
|
+
imageUrl: String(card.imageUrl)
|
|
74
|
+
} : {}, {
|
|
75
|
+
caption: CommerceModel.productPriceText(product, minPrice, maxPrice)
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
export const commerceSiteSearch = {
|
|
79
|
+
key: 'products',
|
|
80
|
+
label: 'Products',
|
|
81
|
+
async items ({ hostId, query, limit }) {
|
|
82
|
+
var _ref;
|
|
83
|
+
if (!isDocumentId(hostId)) return [];
|
|
84
|
+
const products = firebaseAdmin.app().firestore().collection('hosts').doc(hostId).collection('products');
|
|
85
|
+
const token = nameSearchToken(query);
|
|
86
|
+
const [scoped, named] = await Promise.all([
|
|
87
|
+
products.where('deletedAt', '==', null).where('status', '==', 'active').limit(SCAN_LIMIT).get(),
|
|
88
|
+
token ? products.where('nameTokens', 'array-contains', token).limit(TOKEN_LIMIT).get() : Promise.resolve(null)
|
|
89
|
+
]);
|
|
90
|
+
const byId = new Map();
|
|
91
|
+
for (const doc of [
|
|
92
|
+
...(_ref = named == null ? void 0 : named.docs) != null ? _ref : [],
|
|
93
|
+
...scoped.docs
|
|
94
|
+
]){
|
|
95
|
+
if (!byId.has(doc.id)) byId.set(doc.id, doc.data());
|
|
96
|
+
}
|
|
97
|
+
const wantsCategories = [
|
|
98
|
+
...byId.values()
|
|
99
|
+
].some((data)=>Array.isArray(data['categoryIds']) && data['categoryIds'].length > 0);
|
|
100
|
+
const categoryNames = new Map();
|
|
101
|
+
if (wantsCategories) {
|
|
102
|
+
try {
|
|
103
|
+
const categories = await firebaseAdmin.app().firestore().collection('hosts').doc(hostId).collection('productCategories').limit(CATEGORY_LIMIT).get();
|
|
104
|
+
for (const doc of categories.docs){
|
|
105
|
+
const name = str(doc.get('name')).trim();
|
|
106
|
+
if (name) categoryNames.set(doc.id, name);
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
// A category read that fails costs the search its category names,
|
|
110
|
+
// not its products.
|
|
111
|
+
console.error(error);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const items = [];
|
|
115
|
+
for (const [id, data] of byId){
|
|
116
|
+
const item = productSiteSearchItem(id, data, categoryNames);
|
|
117
|
+
if (item) items.push(item);
|
|
118
|
+
if (items.length >= limit) break;
|
|
119
|
+
}
|
|
120
|
+
return items;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=site-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/site-search.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 { nameSearchToken } from '@aglyn/aglyn/app-utils/name-search'\nimport type {\n PluginSiteSearchItem,\n PluginSiteSearchSource,\n} from '@aglyn/aglyn/plugin-manager/plugin-site-search'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin/server/firebase-admin'\nimport * as CommerceModel from '../model'\nimport { productCard } from './product-card'\nimport { plainDescription } from './product-catalog'\n\n/**\n * THE STORE'S PRODUCTS IN THE SITE'S OWN SEARCH: core's `core.site-search`\n * contract, answered from this plugin's products.\n *\n * What a visitor may find is what the storefront lists: live, active and\n * sold online (`productListedOnline`), and never a guided start's sample.\n * The search page matches the typed words; this only hands it candidates.\n *\n * Two bounded reads, merged:\n *\n * - the storefront's own scope (`deletedAt == null`, `status == 'active'`),\n * capped at {@link SCAN_LIMIT} products, which the search page's fuzzy\n * matcher forgives a typo over;\n * - the products whose name has a word starting with the query's first word\n * (`nameTokens`, the storefront grid's search key), so a catalog larger\n * than the scan still finds a product by its name.\n *\n * Category names are read only when a candidate names a category.\n */\n\n/** Products the scope read reaches; a store's whole catalog, for most. */\nexport const SCAN_LIMIT = 250\n/** Products the name-token read reaches beyond the scan. */\nexport const TOKEN_LIMIT = 50\n/** Categories read for their names. */\nconst CATEGORY_LIMIT = 200\n\nconst SNIPPET_LENGTH = 160\n\nconst str = (value: unknown): string => (typeof value === 'string' ? value : '')\n\nconst isDocumentId = (value: string) =>\n Boolean(value) &&\n value.length <= 200 &&\n !value.includes('/') &&\n !/^__.*__$/.test(value)\n\n/** One listed product as the search page matches and shows it, or `null`. */\nexport function productSiteSearchItem(\n productId: string,\n data: Record<string, any>,\n categoryNames: ReadonlyMap<string, string> = new Map(),\n): PluginSiteSearchItem | null {\n if (!CommerceModel.productListedOnline(data)) return null\n if (CommerceModel.productIsSample(data)) return null\n const card = productCard(productId, data)\n // A product with no slug has no page, so there is nothing to link to.\n if (!card.path) return null\n const product = CommerceModel.liftLegacyProduct(\n data as CommerceModel.HostProduct,\n )\n const [minPrice, maxPrice] = CommerceModel.productPriceRange(product)\n const description = plainDescription(data['description'])\n const words = (values: unknown) =>\n Array.isArray(values) ? values.map(str).filter(Boolean) : []\n const terms = [\n description,\n str(data['slug']),\n ...(product.variants ?? [])\n .map((variant) => str(variant.sku))\n .filter(Boolean),\n ...words(data['tags']),\n ...words(data['categoryIds'])\n .map((id) => categoryNames.get(id) ?? '')\n .filter(Boolean),\n ].filter(Boolean)\n return {\n title: card.title,\n terms,\n url: card.path,\n snippet: description.replace(/\\s+/g, ' ').slice(0, SNIPPET_LENGTH),\n ...(card.imageUrl ? { imageUrl: String(card.imageUrl) } : {}),\n caption: CommerceModel.productPriceText(product, minPrice, maxPrice),\n }\n}\n\nexport const commerceSiteSearch: PluginSiteSearchSource = {\n key: 'products',\n label: 'Products',\n async items({ hostId, query, limit }) {\n if (!isDocumentId(hostId)) return []\n const products = firebaseAdmin\n .app()\n .firestore()\n .collection('hosts')\n .doc(hostId)\n .collection('products')\n const token = nameSearchToken(query)\n const [scoped, named] = await Promise.all([\n products\n .where('deletedAt', '==', null)\n .where('status', '==', 'active')\n .limit(SCAN_LIMIT)\n .get(),\n token\n ? products\n .where('nameTokens', 'array-contains', token)\n .limit(TOKEN_LIMIT)\n .get()\n : Promise.resolve(null),\n ])\n const byId = new Map<string, Record<string, any>>()\n for (const doc of [...(named?.docs ?? []), ...scoped.docs]) {\n if (!byId.has(doc.id)) byId.set(doc.id, doc.data() as Record<string, any>)\n }\n const wantsCategories = [...byId.values()].some(\n (data) =>\n Array.isArray(data['categoryIds']) && data['categoryIds'].length > 0,\n )\n const categoryNames = new Map<string, string>()\n if (wantsCategories) {\n try {\n const categories = await firebaseAdmin\n .app()\n .firestore()\n .collection('hosts')\n .doc(hostId)\n .collection('productCategories')\n .limit(CATEGORY_LIMIT)\n .get()\n for (const doc of categories.docs) {\n const name = str(doc.get('name')).trim()\n if (name) categoryNames.set(doc.id, name)\n }\n } catch (error) {\n // A category read that fails costs the search its category names,\n // not its products.\n console.error(error)\n }\n }\n const items: PluginSiteSearchItem[] = []\n for (const [id, data] of byId) {\n const item = productSiteSearchItem(id, data, categoryNames)\n if (item) items.push(item)\n if (items.length >= limit) break\n }\n return items\n },\n}\n"],"names":["nameSearchToken","firebaseAdmin","CommerceModel","productCard","plainDescription","SCAN_LIMIT","TOKEN_LIMIT","CATEGORY_LIMIT","SNIPPET_LENGTH","str","value","isDocumentId","Boolean","length","includes","test","productSiteSearchItem","productId","data","categoryNames","Map","product","productListedOnline","productIsSample","card","path","liftLegacyProduct","minPrice","maxPrice","productPriceRange","description","words","values","Array","isArray","map","filter","terms","variants","variant","sku","id","get","title","url","snippet","replace","slice","imageUrl","String","caption","productPriceText","commerceSiteSearch","key","label","items","hostId","query","limit","products","app","firestore","collection","doc","token","scoped","named","Promise","all","where","resolve","byId","docs","has","set","wantsCategories","some","categories","name","trim","error","console","item","push"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,eAAe,QAAQ,qCAAoC;AAKpE,SAASC,aAAa,QAAQ,iDAAgD;AAC9E,YAAYC,mBAAmB,oBAAU;AACzC,SAASC,WAAW,QAAQ,oBAAgB;AAC5C,SAASC,gBAAgB,QAAQ,uBAAmB;AAEpD;;;;;;;;;;;;;;;;;;CAkBC,GAED,wEAAwE,GACxE,OAAO,MAAMC,aAAa,IAAG;AAC7B,0DAA0D,GAC1D,OAAO,MAAMC,cAAc,GAAE;AAC7B,qCAAqC,GACrC,MAAMC,iBAAiB;AAEvB,MAAMC,iBAAiB;AAEvB,MAAMC,MAAM,CAACC,QAA4B,OAAOA,UAAU,WAAWA,QAAQ;AAE7E,MAAMC,eAAe,CAACD,QACpBE,QAAQF,UACRA,MAAMG,MAAM,IAAI,OAChB,CAACH,MAAMI,QAAQ,CAAC,QAChB,CAAC,WAAWC,IAAI,CAACL;AAEnB,2EAA2E,GAC3E,OAAO,SAASM,sBACdC,SAAiB,EACjBC,IAAyB,EACzBC,gBAA6C,IAAIC,KAAK;QAiBhDC;IAfN,IAAI,C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