Skip to content

Commit 91b80da

Browse files
committed
chore: more types cleanup
1 parent b91a4c4 commit 91b80da

13 files changed

+182
-126
lines changed

src/routes/content/adobe-commerce/queries/cs-product.js

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import {
1818
forceImagesHTTPS,
1919
} from '../util.js';
2020

21+
/**
22+
* @typedef {import('../types.d.ts').Product} Product
23+
*/
24+
2125
function extractMinMaxPrice(data) {
2226
let minPrice = data.priceRange?.minimum ?? data.price;
2327
let maxPrice = data.priceRange?.maximum ?? data.price;

src/routes/content/adobe-commerce/queries/cs-variants.js

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
forceImagesHTTPS,
1919
} from '../util.js';
2020

21+
/**
22+
* @typedef {import('../types.d.ts').Variant} Variant
2123
/**
2224
* @param {Config} config
2325
* @param {any} variants

src/routes/content/adobe-commerce/templates/html/HTMLTemplate.js

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
import { findProductImage } from '../../util.js';
1616
import jsonTemplateFromContext from '../json/index.js';
1717

18+
/**
19+
* @typedef {import('../../types.d.ts').Product} Product
20+
* @typedef {import('../../types.d.ts').Variant} Variant
21+
* @typedef {import('../../types.d.ts').Image} Image
22+
* @typedef {import('../../types.d.ts').Attribute} Attribute
23+
* @typedef {import('../../types.d.ts').OptionValue} OptionValue
24+
* @typedef {import('../../types.d.ts').Prices} Prices
25+
* @typedef {import('../../types.d.ts').ProductOption} ProductOption
26+
*/
27+
1828
export class HTMLTemplate {
1929
/**
2030
* Create a meta tag with a name attribute

src/routes/content/adobe-commerce/templates/html/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
import { HTMLTemplate } from './HTMLTemplate.js';
1414
import OVERRIDES from './overrides/index.js';
1515

16+
/**
17+
* @typedef {import('../../types.d.ts').Product} Product
18+
* @typedef {import('../../types.d.ts').Variant} Variant
19+
*/
20+
1621
/**
1722
* @param {Context} ctx
1823
* @param {Product} product

src/routes/content/adobe-commerce/templates/html/overrides/wilson-ecommerce--wilson.js

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
import { HTMLTemplate } from '../HTMLTemplate.js';
1414

15+
/**
16+
* @typedef {import('../../../types.d.ts').Product} Product
17+
* @typedef {import('../../../types.d.ts').Variant} Variant
18+
*/
19+
1520
export default class extends HTMLTemplate {
1621
/**
1722
* @param {Context} ctx

src/routes/content/adobe-commerce/templates/json/JSONTemplate.js

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
import { pruneUndefined } from '../../../../../utils/product.js';
1616
import { findProductImage } from '../../util.js';
1717

18+
/**
19+
* @typedef {import('../../types.d.ts').Product} Product
20+
* @typedef {import('../../types.d.ts').Variant} Variant
21+
*/
22+
1823
export class JSONTemplate {
1924
/** @type {Context} */
2025
ctx = undefined;

src/routes/content/adobe-commerce/templates/json/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
import { JSONTemplate } from './JSONTemplate.js';
1414
import OVERRIDES from './overrides/index.js';
1515

16+
/**
17+
* @typedef {import('../../types.d.ts').Product} Product
18+
* @typedef {import('../../types.d.ts').Variant} Variant
19+
*/
20+
1621
/**
1722
* @param {Context} ctx
1823
* @param {Product} product

src/routes/content/adobe-commerce/templates/json/overrides/thepixel--bul-eds.js

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
import { JSONTemplate } from '../JSONTemplate.js';
1414

15+
/**
16+
* @typedef {import('../../../types.d.ts').Product} Product
17+
* @typedef {import('../../../types.d.ts').Variant} Variant
18+
*/
19+
1520
export default class extends JSONTemplate {
1621
/**
1722
* @param {Variant} [variant]

src/routes/content/adobe-commerce/templates/json/overrides/visualcomfort--adobe-edge.js

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
import { JSONTemplate } from '../JSONTemplate.js';
1414

15+
/**
16+
* @typedef {import('../../../types.d.ts').Product} Product
17+
* @typedef {import('../../../types.d.ts').Variant} Variant
18+
*/
19+
1520
export default class extends JSONTemplate {
1621
// eslint-disable-next-line class-methods-use-this
1722
renderBrand() {

src/routes/content/adobe-commerce/templates/json/overrides/wilson-ecommerce--wilson.js

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
import { JSONTemplate } from '../JSONTemplate.js';
1414

15+
/**
16+
* @typedef {import('../../../types.d.ts').Product} Product
17+
* @typedef {import('../../../types.d.ts').Variant} Variant
18+
*/
19+
1520
export default class extends JSONTemplate {
1621
// eslint-disable-next-line class-methods-use-this
1722
renderBrand() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
export interface Product {
2+
name: string;
3+
sku: string;
4+
addToCartAllowed: boolean;
5+
inStock: boolean | null;
6+
shortDescription?: string;
7+
metaDescription?: string;
8+
metaKeyword?: string;
9+
metaTitle?: string;
10+
description?: string;
11+
images: Image[];
12+
prices: Prices;
13+
attributes: Attribute[];
14+
options: ProductOption[];
15+
url?: string;
16+
urlKey?: string;
17+
externalId?: string;
18+
variants?: Variant[]; // variants exist on products in helix commerce but not on magento
19+
specialToDate?: string;
20+
rating?: Rating;
21+
links?: Link[];
22+
23+
// Coming only from Catalog Service at the time of writing:
24+
lastModifiedAt?: string;
25+
26+
// not handled currently:
27+
externalParentId?: string;
28+
variantSku?: string;
29+
optionUIDs?: string[];
30+
31+
// internal use:
32+
attributeMap: Record<string, string>;
33+
}
34+
35+
export interface Variant {
36+
sku: string;
37+
name: string;
38+
description?: string;
39+
url: string;
40+
inStock: boolean;
41+
images: Image[];
42+
prices: Pick<Prices, 'regular' | 'final'>;
43+
selections: string[];
44+
attributes: Attribute[];
45+
externalId: string;
46+
specialToDate?: string;
47+
gtin?: string;
48+
rating?: Rating;
49+
50+
// internal use:
51+
attributeMap: Record<string, string>;
52+
}
53+
54+
interface Rating {
55+
// number of ratings
56+
count?: number;
57+
// number of reviews
58+
reviews?: number;
59+
// rating value
60+
value: number | string;
61+
// range of ratings, highest
62+
best?: number | string;
63+
// range of ratings, lowest
64+
worst?: number | string;
65+
}
66+
67+
interface Link {
68+
types: string[];
69+
sku: string;
70+
urlKey: string;
71+
prices: Prices;
72+
}
73+
74+
interface Image {
75+
url: string;
76+
label: string;
77+
roles: string[];
78+
}
79+
80+
interface Price {
81+
amount?: number;
82+
currency?: string;
83+
maximumAmount?: number;
84+
minimumAmount?: number;
85+
variant?: 'default' | 'strikethrough';
86+
}
87+
88+
interface Prices {
89+
regular: Price;
90+
final: Price;
91+
visible: boolean;
92+
}
93+
94+
export interface ProductOption {
95+
id: string;
96+
type: 'text' | 'image' | 'color' | 'dropdown';
97+
typename:
98+
| 'ProductViewOptionValueProduct'
99+
| 'ProductViewOptionValueSwatch'
100+
| 'ProductViewOptionValueConfiguration';
101+
label: string;
102+
required: boolean;
103+
multiple: boolean;
104+
items: OptionValue[];
105+
}
106+
107+
interface OptionValue {
108+
id: string;
109+
label: string;
110+
inStock: boolean;
111+
value: string;
112+
selected: boolean;
113+
type: string;
114+
product?: {
115+
name: string;
116+
sku: string;
117+
prices?: Prices;
118+
};
119+
}
120+
121+
interface Attribute {
122+
name: string;
123+
label: string;
124+
value: string;
125+
}

src/routes/content/adobe-commerce/util.js

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
import { pruneUndefined } from '../../../utils/product.js';
1414

15+
/**
16+
* @typedef {import('./types.d.ts').Product} Product
17+
* @typedef {import('./types.d.ts').Variant} Variant
18+
* @typedef {import('./types.d.ts').Rating} Rating
19+
*/
20+
1521
/**
1622
* This function combines an array of strings with interpolated
1723
* parameters to create a GraphQL query string.

src/types.d.ts

-126
Original file line numberDiff line numberDiff line change
@@ -272,132 +272,6 @@ declare global {
272272
executionContext: ExecutionContext;
273273
}
274274

275-
export interface Product {
276-
name: string;
277-
sku: string;
278-
addToCartAllowed: boolean;
279-
inStock: boolean | null;
280-
shortDescription?: string;
281-
metaDescription?: string;
282-
metaKeyword?: string;
283-
metaTitle?: string;
284-
description?: string;
285-
images: Image[];
286-
prices: Prices;
287-
attributes: Attribute[];
288-
options: ProductOption[];
289-
url?: string;
290-
urlKey?: string;
291-
externalId?: string;
292-
variants?: Variant[]; // variants exist on products in helix commerce but not on magento
293-
specialToDate?: string;
294-
rating?: Rating;
295-
links?: Link[];
296-
297-
// Coming only from Catalog Service at the time of writing:
298-
lastModifiedAt?: string;
299-
300-
// not handled currently:
301-
externalParentId?: string;
302-
variantSku?: string;
303-
optionUIDs?: string[];
304-
305-
// internal use:
306-
attributeMap: Record<string, string>;
307-
}
308-
309-
export interface Variant {
310-
sku: string;
311-
name: string;
312-
description?: string;
313-
url: string;
314-
inStock: boolean;
315-
images: Image[];
316-
prices: Pick<Prices, 'regular' | 'final'>;
317-
selections: string[];
318-
attributes: Attribute[];
319-
externalId: string;
320-
specialToDate?: string;
321-
gtin?: string;
322-
rating?: Rating;
323-
324-
// internal use:
325-
attributeMap: Record<string, string>;
326-
}
327-
328-
interface Rating {
329-
// number of ratings
330-
count?: number;
331-
// number of reviews
332-
reviews?: number;
333-
// rating value
334-
value: number | string;
335-
// range of ratings, highest
336-
best?: number | string;
337-
// range of ratings, lowest
338-
worst?: number | string;
339-
}
340-
341-
interface Link {
342-
types: string[];
343-
sku: string;
344-
urlKey: string;
345-
prices: Prices;
346-
}
347-
348-
interface Image {
349-
url: string;
350-
label: string;
351-
roles: string[];
352-
}
353-
354-
interface Price {
355-
amount?: number;
356-
currency?: string;
357-
maximumAmount?: number;
358-
minimumAmount?: number;
359-
variant?: 'default' | 'strikethrough';
360-
}
361-
362-
interface Prices {
363-
regular: Price;
364-
final: Price;
365-
visible: boolean;
366-
}
367-
368-
export interface ProductOption {
369-
id: string;
370-
type: 'text' | 'image' | 'color' | 'dropdown';
371-
typename:
372-
| 'ProductViewOptionValueProduct'
373-
| 'ProductViewOptionValueSwatch'
374-
| 'ProductViewOptionValueConfiguration';
375-
label: string;
376-
required: boolean;
377-
multiple: boolean;
378-
items: OptionValue[];
379-
}
380-
381-
interface OptionValue {
382-
id: string;
383-
label: string;
384-
inStock: boolean;
385-
value: string;
386-
selected: boolean;
387-
type: string;
388-
product?: {
389-
name: string;
390-
sku: string;
391-
prices?: Prices;
392-
};
393-
}
394-
395-
interface Attribute {
396-
name: string;
397-
label: string;
398-
value: string;
399-
}
400-
401275
interface BatchResult {
402276
sku: string;
403277
status: number;

0 commit comments

Comments
 (0)