@aglyn/plugins-commerce 1.0.0-beta.236 → 1.0.0-beta.238
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/cart.d.ts +2 -1
- package/src/lib/components/cart.js +2 -1
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/product-detail.d.ts +76 -0
- package/src/lib/components/product-detail.js +258 -52
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-grid.d.ts +46 -0
- package/src/lib/components/product-grid.js +283 -79
- package/src/lib/components/product-grid.js.map +1 -1
- package/src/lib/components/product-image-placeholder.d.ts +31 -0
- package/src/lib/components/product-image-placeholder.js +72 -0
- package/src/lib/components/product-image-placeholder.js.map +1 -0
- package/src/lib/components/product-reviews.d.ts +13 -0
- package/src/lib/components/product-reviews.js +267 -13
- package/src/lib/components/product-reviews.js.map +1 -1
- package/src/lib/components/related-products.d.ts +6 -0
- package/src/lib/components/related-products.js +73 -20
- package/src/lib/components/related-products.js.map +1 -1
- package/src/lib/constants/cart-events.d.ts +23 -0
- package/src/lib/constants/cart-events.js +23 -0
- package/src/lib/constants/cart-events.js.map +1 -0
- package/src/lib/server/catalog.d.ts +14 -0
- package/src/lib/server/catalog.js +25 -5
- package/src/lib/server/catalog.js.map +1 -1
- package/src/lib/server/reviews.d.ts +35 -0
- package/src/lib/server/reviews.js +120 -1
- package/src/lib/server/reviews.js.map +1 -1
- package/src/lib/server/site-page-resolver.d.ts +15 -3
- package/src/lib/server/site-page-resolver.js +78 -24
- package/src/lib/server/site-page-resolver.js.map +1 -1
- package/src/lib/utils/add-to-cart.d.ts +35 -0
- package/src/lib/utils/add-to-cart.js +53 -0
- package/src/lib/utils/add-to-cart.js.map +1 -0
|
@@ -0,0 +1,35 @@
|
|
|
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 AnalyticsItem } from '@aglyn/aglyn/app-utils/analytics-events';
|
|
18
|
+
export interface AddToCartRequest {
|
|
19
|
+
hostId: string;
|
|
20
|
+
/** The site's fetch (`Aglyn.useSiteFetch()`), which carries the cart cookie. */
|
|
21
|
+
siteFetch: typeof fetch;
|
|
22
|
+
productId: string;
|
|
23
|
+
variantId: string;
|
|
24
|
+
quantity: number;
|
|
25
|
+
/** The GA4 line: product id (never the variant's), name, price, quantity. */
|
|
26
|
+
item: AnalyticsItem;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Put one line in the shopper's cart. The product page's Add to cart and the
|
|
30
|
+
* product grid's quick add both go through this one path, so both record the
|
|
31
|
+
* same funnel step (AGL-3605), report the same priced `add_to_cart`
|
|
32
|
+
* (AGL-1591) and refresh every cart badge on the page. Resolves whether the
|
|
33
|
+
* server took the line; the server prices it, never the caller.
|
|
34
|
+
*/
|
|
35
|
+
export declare function addToCart(request: AddToCartRequest): Promise<boolean>;
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
*/ import { buildAddToCartParams, trackEvent } from "@aglyn/aglyn/app-utils/analytics-events";
|
|
17
|
+
import { recordSiteJourneyStep } from "@aglyn/aglyn/app-utils/site-journey";
|
|
18
|
+
import { CART_UPDATED_EVENT } from "../constants/cart-events.js";
|
|
19
|
+
/**
|
|
20
|
+
* Put one line in the shopper's cart. The product page's Add to cart and the
|
|
21
|
+
* product grid's quick add both go through this one path, so both record the
|
|
22
|
+
* same funnel step (AGL-3605), report the same priced `add_to_cart`
|
|
23
|
+
* (AGL-1591) and refresh every cart badge on the page. Resolves whether the
|
|
24
|
+
* server took the line; the server prices it, never the caller.
|
|
25
|
+
*/ export async function addToCart(request) {
|
|
26
|
+
const { hostId, siteFetch, productId, variantId, quantity, item } = request;
|
|
27
|
+
const response = await siteFetch('/api/commerce/cart', {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: {
|
|
30
|
+
'Content-Type': 'application/json'
|
|
31
|
+
},
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
hostId,
|
|
34
|
+
action: 'add',
|
|
35
|
+
productId,
|
|
36
|
+
variantId,
|
|
37
|
+
quantity
|
|
38
|
+
})
|
|
39
|
+
}).catch(()=>null);
|
|
40
|
+
if (!(response == null ? void 0 : response.ok)) return false;
|
|
41
|
+
recordSiteJourneyStep('cart', productId);
|
|
42
|
+
// `value` describes what was JUST ADDED, not the cart's new total — see
|
|
43
|
+
// `buildAddToCartParams`.
|
|
44
|
+
trackEvent('add_to_cart', buildAddToCartParams({
|
|
45
|
+
items: [
|
|
46
|
+
item
|
|
47
|
+
]
|
|
48
|
+
}));
|
|
49
|
+
window.dispatchEvent(new Event(CART_UPDATED_EVENT));
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=add-to-cart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/utils/add-to-cart.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 {\n buildAddToCartParams,\n trackEvent,\n type AnalyticsItem,\n} from '@aglyn/aglyn/app-utils/analytics-events'\nimport { recordSiteJourneyStep } from '@aglyn/aglyn/app-utils/site-journey'\nimport { CART_UPDATED_EVENT } from '../constants/cart-events'\n\nexport interface AddToCartRequest {\n hostId: string\n /** The site's fetch (`Aglyn.useSiteFetch()`), which carries the cart cookie. */\n siteFetch: typeof fetch\n productId: string\n variantId: string\n quantity: number\n /** The GA4 line: product id (never the variant's), name, price, quantity. */\n item: AnalyticsItem\n}\n\n/**\n * Put one line in the shopper's cart. The product page's Add to cart and the\n * product grid's quick add both go through this one path, so both record the\n * same funnel step (AGL-3605), report the same priced `add_to_cart`\n * (AGL-1591) and refresh every cart badge on the page. Resolves whether the\n * server took the line; the server prices it, never the caller.\n */\nexport async function addToCart(request: AddToCartRequest): Promise<boolean> {\n const { hostId, siteFetch, productId, variantId, quantity, item } = request\n const response = await siteFetch('/api/commerce/cart', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, action: 'add', productId, variantId, quantity }),\n }).catch(() => null)\n if (!response?.ok) return false\n recordSiteJourneyStep('cart', productId)\n // `value` describes what was JUST ADDED, not the cart's new total — see\n // `buildAddToCartParams`.\n trackEvent('add_to_cart', buildAddToCartParams({ items: [item] }))\n window.dispatchEvent(new Event(CART_UPDATED_EVENT))\n return true\n}\n"],"names":["buildAddToCartParams","trackEvent","recordSiteJourneyStep","CART_UPDATED_EVENT","addToCart","request","hostId","siteFetch","productId","variantId","quantity","item","response","method","headers","body","JSON","stringify","action","catch","ok","items","window","dispatchEvent","Event"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,oBAAoB,EACpBC,UAAU,QAEL,0CAAyC;AAChD,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,kBAAkB,QAAQ,8BAA0B;AAa7D;;;;;;CAMC,GACD,OAAO,eAAeC,UAAUC,OAAyB;IACvD,MAAM,EAAEC,MAAM,EAAEC,SAAS,EAAEC,SAAS,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,IAAI,EAAE,GAAGN;IACpE,MAAMO,WAAW,MAAML,UAAU,sBAAsB;QACrDM,QAAQ;QACRC,SAAS;YAAE,gBAAgB;QAAmB;QAC9CC,MAAMC,KAAKC,SAAS,CAAC;YAAEX;YAAQY,QAAQ;YAAOV;YAAWC;YAAWC;QAAS;IAC/E,GAAGS,KAAK,CAAC,IAAM;IACf,IAAI,EAACP,4BAAAA,SAAUQ,EAAE,GAAE,OAAO;IAC1BlB,sBAAsB,QAAQM;IAC9B,wEAAwE;IACxE,0BAA0B;IAC1BP,WAAW,eAAeD,qBAAqB;QAAEqB,OAAO;YAACV;SAAK;IAAC;IAC/DW,OAAOC,aAAa,CAAC,IAAIC,MAAMrB;IAC/B,OAAO;AACT"}
|