@asstio-dev/storefront 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gtin.d.ts +3 -0
- package/dist/gtin.js +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/schema.d.ts +4 -0
- package/dist/seo/product.js +8 -2
- package/dist/seo/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/schema.d.ts +4 -0
package/dist/gtin.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Schema.org's GTIN property for a `gtin` value from the API (GTIN spec §13.3): gtin8, gtin12, gtin13 or gtin14 by
|
|
2
|
+
* length. The API sends the canonical form, so the length is the format. Spread it into a Product or Offer object. */
|
|
3
|
+
export declare function gtinJsonLd(gtin: string | null | undefined): Record<string, string>;
|
package/dist/gtin.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Schema.org's GTIN property for a `gtin` value from the API (GTIN spec §13.3): gtin8, gtin12, gtin13 or gtin14 by
|
|
2
|
+
* length. The API sends the canonical form, so the length is the format. Spread it into a Product or Offer object. */
|
|
3
|
+
export function gtinJsonLd(gtin) {
|
|
4
|
+
if (!gtin || !/^\d+$/.test(gtin))
|
|
5
|
+
return {};
|
|
6
|
+
switch (gtin.length) {
|
|
7
|
+
case 8: return { gtin8: gtin };
|
|
8
|
+
case 12: return { gtin12: gtin };
|
|
9
|
+
case 13: return { gtin13: gtin };
|
|
10
|
+
case 14: return { gtin14: gtin };
|
|
11
|
+
default: return {};
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,7 @@ export { mountCheckout, type CheckoutHandle, type MountOptions, type MinimalDocu
|
|
|
53
53
|
export { controllers, type CheckoutController, type ProviderWindow } from "./checkout/controllers.js";
|
|
54
54
|
export { breadcrumbJsonLd } from "./seo/breadcrumb.js";
|
|
55
55
|
export { brandHead, collectionHead, productHead, toNextMetadata } from "./seo/head.js";
|
|
56
|
+
export { gtinJsonLd } from "./gtin.js";
|
|
56
57
|
export { productJsonLd } from "./seo/product.js";
|
|
57
58
|
export { jsonLdScript } from "./seo/serialize.js";
|
|
58
59
|
export { SeoError, type BreadcrumbLink, type CollectionHeadOptions, type HeadOptions, type JsonLd, type NextMetadataLike, type ProductJsonLdOptions, type SchemaProperty, type SeoContext, type SeoHead, type SeoMeta, } from "./seo/types.js";
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,7 @@ export { mountCheckout } from "./checkout/browser.js";
|
|
|
42
42
|
export { controllers } from "./checkout/controllers.js";
|
|
43
43
|
export { breadcrumbJsonLd } from "./seo/breadcrumb.js";
|
|
44
44
|
export { brandHead, collectionHead, productHead, toNextMetadata } from "./seo/head.js";
|
|
45
|
+
export { gtinJsonLd } from "./gtin.js";
|
|
45
46
|
export { productJsonLd } from "./seo/product.js";
|
|
46
47
|
export { jsonLdScript } from "./seo/serialize.js";
|
|
47
48
|
export { SeoError, } from "./seo/types.js";
|
package/dist/schema.d.ts
CHANGED
|
@@ -852,6 +852,8 @@ export interface components {
|
|
|
852
852
|
collections: components["schemas"]["CollectionRefDto"][];
|
|
853
853
|
description: null | components["schemas"]["DescriptionDto"];
|
|
854
854
|
files: components["schemas"]["MediaDescriptorDto"][];
|
|
855
|
+
gtin: null | string;
|
|
856
|
+
gtins: string[];
|
|
855
857
|
id: string;
|
|
856
858
|
image: null | components["schemas"]["MediaDescriptorDto"];
|
|
857
859
|
images: components["schemas"]["MediaDescriptorDto"][];
|
|
@@ -1003,6 +1005,8 @@ export interface components {
|
|
|
1003
1005
|
};
|
|
1004
1006
|
VariantDto: {
|
|
1005
1007
|
brand: null | components["schemas"]["BrandDto"];
|
|
1008
|
+
gtin: null | string;
|
|
1009
|
+
gtins: string[];
|
|
1006
1010
|
hasOwnImages: boolean;
|
|
1007
1011
|
id: string;
|
|
1008
1012
|
image: null | components["schemas"]["MediaDescriptorDto"];
|
package/dist/seo/product.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { gtinJsonLd } from "../gtin.js";
|
|
1
2
|
import { jsonLdDescription, pickImages, productDescription, rejectRedirect, requireMarket } from "./shared.js";
|
|
2
3
|
import { SeoError } from "./types.js";
|
|
3
4
|
const PROPERTIES = ["size", "color", "material", "pattern"];
|
|
@@ -81,8 +82,13 @@ export function productJsonLd(p, ctx) {
|
|
|
81
82
|
...offerExtras(ctx),
|
|
82
83
|
});
|
|
83
84
|
const gtin = (v) => {
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
// GTIN spec §13.3 (plan P14): the hook wins when given, and may omit; otherwise the variant's own gtin. A value of
|
|
86
|
+
// 8, 12, 13 or 14 digits becomes gtin8/12/13/14; any other hook value keeps the generic property.
|
|
87
|
+
const g = ctx.gtin ? ctx.gtin(v) : (v.gtin ?? undefined);
|
|
88
|
+
if (!g)
|
|
89
|
+
return {};
|
|
90
|
+
const keyed = gtinJsonLd(g);
|
|
91
|
+
return Object.keys(keyed).length > 0 ? keyed : { gtin: g };
|
|
86
92
|
};
|
|
87
93
|
if (list === null || sellable.length === 0)
|
|
88
94
|
return { ...common("Product"), sku: p.sku, ...(p.brand ? { brand: brandNode(p.brand.label) } : {}) };
|
package/dist/seo/types.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export type ProductJsonLdOptions = SeoContext & {
|
|
|
41
41
|
variesBy?: Record<string, SchemaProperty>;
|
|
42
42
|
/** Used only when `p.variants` is `null` (more than 100 variants), e.g. the first page of `/variants`. */
|
|
43
43
|
variants?: VariantDto[];
|
|
44
|
+
/** Overrides the GTIN per variant; return `undefined` to omit. Defaults to the variant's `gtin`. */
|
|
44
45
|
gtin?: (v: VariantDto) => string | undefined;
|
|
45
46
|
seller?: {
|
|
46
47
|
name: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asstio-dev/storefront",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Typed client for the Asstio Storefront API (generated from OpenAPI).",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"test": "vitest run",
|
|
22
22
|
"test:browser": "playwright test -c browser/playwright.config.ts",
|
|
23
23
|
"check": "npm run generate && npm run typecheck-examples && npm test && git diff --exit-code -- src/schema.d.ts && test -z \"$(git status --porcelain -- src/schema.d.ts)\"",
|
|
24
|
-
"smoke": "node --input-type=module -e \"import(\\\"./dist/index.js\\\").then(m => { for (const f of [\\\"createStorefrontClient\\\", \\\"filterQuery\\\", \\\"encodeFilterValues\\\", \\\"decodeFilterValues\\\", \\\"pictureSources\\\", \\\"mediaUrl\\\", \\\"formatImage\\\", \\\"styleToCss\\\", \\\"startCheckout\\\", \\\"syncCheckout\\\", \\\"completeCheckout\\\", \\\"getCheckoutStatus\\\", \\\"getOrder\\\", \\\"awaitCompletion\\\", \\\"mountCheckout\\\", \\\"productJsonLd\\\", \\\"breadcrumbJsonLd\\\", \\\"productHead\\\", \\\"collectionHead\\\", \\\"brandHead\\\", \\\"toNextMetadata\\\", \\\"jsonLdScript\\\", \\\"SeoError\\\"]) if (typeof m[f] !== \\\"function\\\") throw new Error(\\\"missing export \\\" + f) })\""
|
|
24
|
+
"smoke": "node --input-type=module -e \"import(\\\"./dist/index.js\\\").then(m => { for (const f of [\\\"createStorefrontClient\\\", \\\"filterQuery\\\", \\\"encodeFilterValues\\\", \\\"decodeFilterValues\\\", \\\"pictureSources\\\", \\\"mediaUrl\\\", \\\"formatImage\\\", \\\"styleToCss\\\", \\\"startCheckout\\\", \\\"syncCheckout\\\", \\\"completeCheckout\\\", \\\"getCheckoutStatus\\\", \\\"getOrder\\\", \\\"awaitCompletion\\\", \\\"mountCheckout\\\", \\\"productJsonLd\\\", \\\"gtinJsonLd\\\", \\\"breadcrumbJsonLd\\\", \\\"productHead\\\", \\\"collectionHead\\\", \\\"brandHead\\\", \\\"toNextMetadata\\\", \\\"jsonLdScript\\\", \\\"SeoError\\\"]) if (typeof m[f] !== \\\"function\\\") throw new Error(\\\"missing export \\\" + f) })\""
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"openapi-fetch": "0.17.0"
|
package/src/schema.d.ts
CHANGED
|
@@ -852,6 +852,8 @@ export interface components {
|
|
|
852
852
|
collections: components["schemas"]["CollectionRefDto"][];
|
|
853
853
|
description: null | components["schemas"]["DescriptionDto"];
|
|
854
854
|
files: components["schemas"]["MediaDescriptorDto"][];
|
|
855
|
+
gtin: null | string;
|
|
856
|
+
gtins: string[];
|
|
855
857
|
id: string;
|
|
856
858
|
image: null | components["schemas"]["MediaDescriptorDto"];
|
|
857
859
|
images: components["schemas"]["MediaDescriptorDto"][];
|
|
@@ -1003,6 +1005,8 @@ export interface components {
|
|
|
1003
1005
|
};
|
|
1004
1006
|
VariantDto: {
|
|
1005
1007
|
brand: null | components["schemas"]["BrandDto"];
|
|
1008
|
+
gtin: null | string;
|
|
1009
|
+
gtins: string[];
|
|
1006
1010
|
hasOwnImages: boolean;
|
|
1007
1011
|
id: string;
|
|
1008
1012
|
image: null | components["schemas"]["MediaDescriptorDto"];
|