From b91a4c48eb49c6a56c264d86f7b3dfca97410e2e Mon Sep 17 00:00:00 2001 From: Max Edell Date: Thu, 6 Mar 2025 17:38:01 -0800 Subject: [PATCH 1/3] chore: cleanup types --- src/index.js | 6 +++--- src/routes/auth/fetch.js | 2 +- src/routes/auth/handler.js | 15 ++------------- src/routes/auth/rotate.js | 2 +- src/routes/auth/update.js | 2 +- src/routes/catalog/StorageClient.js | 6 ++---- src/routes/catalog/fetch.js | 4 +--- src/routes/catalog/handler.js | 17 ++--------------- src/routes/catalog/lookup.js | 4 +--- src/routes/catalog/remove.js | 4 +--- src/routes/catalog/update.js | 5 ++--- src/routes/config/handler.js | 3 +-- src/routes/content/adobe-commerce/index.js | 3 +-- src/routes/content/handler.js | 11 +++++------ src/routes/content/helix-commerce.js | 3 +-- src/routes/content/media.js | 2 +- src/routes/index.js | 8 +------- src/types.d.ts | 2 ++ src/utils/admin.js | 4 ++-- 19 files changed, 31 insertions(+), 72 deletions(-) diff --git a/src/index.js b/src/index.js index c83eac0..440a475 100644 --- a/src/index.js +++ b/src/index.js @@ -15,7 +15,7 @@ import { resolveConfig } from './utils/config.js'; import handlers from './routes/index.js'; /** - * @param {import("@cloudflare/workers-types/experimental").Request} req + * @param {import("@cloudflare/workers-types").Request} req */ async function parseData(req) { if (['GET', 'HEAD', 'OPTIONS'].includes(req.method)) { @@ -41,7 +41,7 @@ async function parseData(req) { /** * @param {import("@cloudflare/workers-types/experimental").ExecutionContext} eCtx - * @param {import("@cloudflare/workers-types/experimental").Request} req + * @param {import("@cloudflare/workers-types").Request} req * @param {Env} env * @returns {Promise} */ @@ -72,7 +72,7 @@ export async function makeContext(eCtx, req, env) { export default { /** - * @param {import("@cloudflare/workers-types/experimental").Request} request + * @param {import("@cloudflare/workers-types").Request} request * @param {Env} env * @param {import("@cloudflare/workers-types/experimental").ExecutionContext} eCtx * @returns {Promise} diff --git a/src/routes/auth/fetch.js b/src/routes/auth/fetch.js index df6e2c1..dc949d9 100644 --- a/src/routes/auth/fetch.js +++ b/src/routes/auth/fetch.js @@ -14,7 +14,7 @@ import { assertAuthorization } from '../../utils/auth.js'; import { errorResponse } from '../../utils/http.js'; /** - * @param {Context} ctx + * @type {RouteHandler} */ export default async function fetch(ctx) { const { config } = ctx; diff --git a/src/routes/auth/handler.js b/src/routes/auth/handler.js index 1ad8691..6c164e2 100644 --- a/src/routes/auth/handler.js +++ b/src/routes/auth/handler.js @@ -16,16 +16,7 @@ import update from './update.js'; import rotate from './rotate.js'; /** - * @type {Record< - * string, - * Record< - * string, - * ( - * ctx: Context, - * req: import("@cloudflare/workers-types/experimental").Request - * ) => Promise - * > - * >} + * @type {Record>} */ const handlers = { token: { @@ -36,9 +27,7 @@ const handlers = { }; /** - * @param {Context} ctx - * @param {import("@cloudflare/workers-types/experimental").Request} req - * @returns {Promise} + * @type {RouteHandler} */ export default async function handler(ctx, req) { const { diff --git a/src/routes/auth/rotate.js b/src/routes/auth/rotate.js index def7c4e..55f54c2 100644 --- a/src/routes/auth/rotate.js +++ b/src/routes/auth/rotate.js @@ -15,7 +15,7 @@ import { errorResponse } from '../../utils/http.js'; import { updateToken } from './update.js'; /** - * @param {Context} ctx + * @type {RouteHandler} */ export default async function rotate(ctx) { const { data } = ctx; diff --git a/src/routes/auth/update.js b/src/routes/auth/update.js index 7fb99f1..9317570 100644 --- a/src/routes/auth/update.js +++ b/src/routes/auth/update.js @@ -33,7 +33,7 @@ export async function updateToken(ctx, token = generateToken()) { } /** - * @param {Context} ctx + * @type {RouteHandler} */ export default async function update(ctx) { const { data } = ctx; diff --git a/src/routes/catalog/StorageClient.js b/src/routes/catalog/StorageClient.js index 703701e..7ffecce 100644 --- a/src/routes/catalog/StorageClient.js +++ b/src/routes/catalog/StorageClient.js @@ -115,7 +115,7 @@ export default class StorageClient { } // Attempt to save the product - const putResponse = await env.CATALOG_BUCKET.put(key, body, { + await env.CATALOG_BUCKET.put(key, body, { httpMetadata: { contentType: 'application/json' }, customMetadata, }); @@ -136,7 +136,6 @@ export default class StorageClient { */ const result = { sku, - status: putResponse.status, message: 'Product saved successfully.', ...adminResponse.paths, }; @@ -203,7 +202,7 @@ export default class StorageClient { }; } const { customMetadata } = productHead; - const deleteProductResponse = await env.CATALOG_BUCKET.delete(productKey); + await env.CATALOG_BUCKET.delete(productKey); const { urlKey } = customMetadata; if (urlKey) { @@ -217,7 +216,6 @@ export default class StorageClient { */ const result = { sku, - status: deleteProductResponse?.status, message: 'Product deleted successfully.', ...adminResponse.paths, }; diff --git a/src/routes/catalog/fetch.js b/src/routes/catalog/fetch.js index a341e1b..b43f9f9 100644 --- a/src/routes/catalog/fetch.js +++ b/src/routes/catalog/fetch.js @@ -13,9 +13,7 @@ import StorageClient from './StorageClient.js'; /** - * Handles a GET request for a product. - * @param {Context} ctx - The context object containing request information and utilities. - * @returns {Promise} - A promise that resolves to the product response. + * @type {RouteHandler} */ export default async function fetch(ctx) { const { sku } = ctx.config; diff --git a/src/routes/catalog/handler.js b/src/routes/catalog/handler.js index 064360c..cc01b99 100644 --- a/src/routes/catalog/handler.js +++ b/src/routes/catalog/handler.js @@ -17,17 +17,7 @@ import update from './update.js'; import remove from './remove.js'; /** - * @type {Record< - * string, - * Record< - * string, - * ( - * ctx: Context, - * req: import("@cloudflare/workers-types/experimental").Request - * ) => Promise - * > - * > - * } + * @type {Record>} */ const handlers = { lookup: { @@ -47,10 +37,7 @@ const handlers = { }; /** - * Handles productbus requests. - * @param {Context} ctx - The context object containing request information and utilities. - * @param {import("@cloudflare/workers-types/experimental").Request} request - The request object. - * @returns {Promise} - A promise that resolves to the catalog response. + * @type {RouteHandler} */ export default async function handler(ctx, request) { const { diff --git a/src/routes/catalog/lookup.js b/src/routes/catalog/lookup.js index 3482c81..b20a58b 100644 --- a/src/routes/catalog/lookup.js +++ b/src/routes/catalog/lookup.js @@ -13,9 +13,7 @@ import StorageClient from './StorageClient.js'; /** - * Handles a product lookup request. - * @param {Context} ctx - The context object. - * @returns {Promise} - A promise that resolves to the product response. + * @type {RouteHandler} */ export default async function lookup(ctx) { const { diff --git a/src/routes/catalog/remove.js b/src/routes/catalog/remove.js index 2cc68f4..dd1eb5a 100644 --- a/src/routes/catalog/remove.js +++ b/src/routes/catalog/remove.js @@ -15,9 +15,7 @@ import { errorResponse, errorWithResponse } from '../../utils/http.js'; import StorageClient from './StorageClient.js'; /** - * Handles a DELETE request for a product. - * @param {Context} ctx - The context object containing request information and utilities. - * @returns {Promise} - A promise that resolves to the product response. + * @type {RouteHandler} */ export default async function remove(ctx) { const { log, config } = ctx; diff --git a/src/routes/catalog/update.js b/src/routes/catalog/update.js index b8b9670..64cdd7a 100644 --- a/src/routes/catalog/update.js +++ b/src/routes/catalog/update.js @@ -15,10 +15,9 @@ import { errorResponse } from '../../utils/http.js'; import StorageClient from './StorageClient.js'; import { assertAuthorization } from '../../utils/auth.js'; import { extractAndReplaceImages } from '../../utils/media.js'; + /** - * Handles a PUT request to update a product. - * @param {Context} ctx - The context object containing request information and utilities. - * @returns {Promise} - A promise that resolves to the product response. + * @type {RouteHandler} */ export default async function update(ctx) { const { config, log, data } = ctx; diff --git a/src/routes/config/handler.js b/src/routes/config/handler.js index d7d861d..e6a1a22 100644 --- a/src/routes/config/handler.js +++ b/src/routes/config/handler.js @@ -17,8 +17,7 @@ import { updateToken } from '../auth/update.js'; import ConfigSchema from '../../schemas/Config.js'; /** - * @param {Context} ctx - * @returns {Promise} + * @type {RouteHandler} */ export default async function configHandler(ctx) { const { method } = ctx.info; diff --git a/src/routes/content/adobe-commerce/index.js b/src/routes/content/adobe-commerce/index.js index 19a397b..ba39ee0 100644 --- a/src/routes/content/adobe-commerce/index.js +++ b/src/routes/content/adobe-commerce/index.js @@ -212,8 +212,7 @@ function lookupProductSKU(urlkey, config) { } /** - * @param {Context} ctx - * @returns {Promise} + * @type {RouteHandler} */ export default async function handler(ctx) { const { config } = ctx; diff --git a/src/routes/content/handler.js b/src/routes/content/handler.js index 883a09b..07b2370 100644 --- a/src/routes/content/handler.js +++ b/src/routes/content/handler.js @@ -18,10 +18,9 @@ import media from './media.js'; const ALLOWED_METHODS = ['GET']; /** - * @param {Context} ctx - * @returns {Promise} + * @type {RouteHandler} */ -export default async function contentHandler(ctx) { +export default async function contentHandler(ctx, req) { const { log, config, @@ -33,7 +32,7 @@ export default async function contentHandler(ctx) { } if (['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp'].includes(info.extension)) { - return media(ctx); + return media(ctx, req); } if (!config.pageType) { @@ -42,8 +41,8 @@ export default async function contentHandler(ctx) { log.debug('config: ', JSON.stringify(config, null, 2)); if (config.catalogSource === 'adobe-commerce') { - return adobeCommerce(ctx); + return adobeCommerce(ctx, req); } - return helixCommerce(ctx); + return helixCommerce(ctx, req); } diff --git a/src/routes/content/helix-commerce.js b/src/routes/content/helix-commerce.js index 8cae412..9e80746 100644 --- a/src/routes/content/helix-commerce.js +++ b/src/routes/content/helix-commerce.js @@ -145,8 +145,7 @@ ${indent(product.images?.map(pictureTemplate).join('\n'), 10)} `; /** - * @param {Context} ctx - * @returns {Promise} + * @type {RouteHandler} */ export default async function handler(ctx) { const { config: { params } } = ctx; diff --git a/src/routes/content/media.js b/src/routes/content/media.js index 654c6d1..6105da9 100644 --- a/src/routes/content/media.js +++ b/src/routes/content/media.js @@ -13,7 +13,7 @@ import { errorResponse } from '../../utils/http.js'; /** - * @param {Context} ctx + * @type {RouteHandler} */ export default async function handler(ctx) { const { diff --git a/src/routes/index.js b/src/routes/index.js index 23cc0de..b176557 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -16,13 +16,7 @@ import config from './config/handler.js'; import auth from './auth/handler.js'; /** - * @type {Record< - * string, - * ( - * ctx: Context, - * request: import("@cloudflare/workers-types/experimental").Request - * ) => Promise - * >} + * @type {Record} */ export default { content, diff --git a/src/types.d.ts b/src/types.d.ts index 1662792..77ad1d0 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -414,6 +414,8 @@ declare global { status: number; message?: string; } + + export type RouteHandler = (ctx: Context, request: import("@cloudflare/workers-types").Request) => Promise; } export { }; \ No newline at end of file diff --git a/src/utils/admin.js b/src/utils/admin.js index 2dbdb2f..9019b05 100644 --- a/src/utils/admin.js +++ b/src/utils/admin.js @@ -10,8 +10,6 @@ * governing permissions and limitations under the License. */ -/* eslint-disable no-await-in-loop */ - import { getPreviewPublishPaths } from './product.js'; /** @@ -125,7 +123,9 @@ export async function callPreviewPublish(config, method, sku, urlKey) { // Conditional sequencing or parallel execution based on the method const operations = method === 'POST' + // eslint-disable-next-line no-await-in-loop ? [await callAdminWithOp('preview'), await callAdminWithOp('live')] + // eslint-disable-next-line no-await-in-loop : await Promise.all(['preview', 'live'].map(callAdminWithOp)); operations.forEach(({ op, status, message }) => { From 91b80da2f48d2af8f00bc10e86836796a1e7912a Mon Sep 17 00:00:00 2001 From: Max Edell Date: Thu, 6 Mar 2025 17:45:33 -0800 Subject: [PATCH 2/3] chore: more types cleanup --- .../adobe-commerce/queries/cs-product.js | 4 + .../adobe-commerce/queries/cs-variants.js | 2 + .../templates/html/HTMLTemplate.js | 10 ++ .../adobe-commerce/templates/html/index.js | 5 + .../overrides/wilson-ecommerce--wilson.js | 5 + .../templates/json/JSONTemplate.js | 5 + .../adobe-commerce/templates/json/index.js | 5 + .../json/overrides/thepixel--bul-eds.js | 5 + .../overrides/visualcomfort--adobe-edge.js | 5 + .../overrides/wilson-ecommerce--wilson.js | 5 + src/routes/content/adobe-commerce/types.d.ts | 125 +++++++++++++++++ src/routes/content/adobe-commerce/util.js | 6 + src/types.d.ts | 126 ------------------ 13 files changed, 182 insertions(+), 126 deletions(-) create mode 100644 src/routes/content/adobe-commerce/types.d.ts diff --git a/src/routes/content/adobe-commerce/queries/cs-product.js b/src/routes/content/adobe-commerce/queries/cs-product.js index ba0f01a..04c5967 100644 --- a/src/routes/content/adobe-commerce/queries/cs-product.js +++ b/src/routes/content/adobe-commerce/queries/cs-product.js @@ -18,6 +18,10 @@ import { forceImagesHTTPS, } from '../util.js'; +/** + * @typedef {import('../types.d.ts').Product} Product + */ + function extractMinMaxPrice(data) { let minPrice = data.priceRange?.minimum ?? data.price; let maxPrice = data.priceRange?.maximum ?? data.price; diff --git a/src/routes/content/adobe-commerce/queries/cs-variants.js b/src/routes/content/adobe-commerce/queries/cs-variants.js index e9eb84c..0e0ae0e 100644 --- a/src/routes/content/adobe-commerce/queries/cs-variants.js +++ b/src/routes/content/adobe-commerce/queries/cs-variants.js @@ -18,6 +18,8 @@ import { forceImagesHTTPS, } from '../util.js'; +/** + * @typedef {import('../types.d.ts').Variant} Variant /** * @param {Config} config * @param {any} variants diff --git a/src/routes/content/adobe-commerce/templates/html/HTMLTemplate.js b/src/routes/content/adobe-commerce/templates/html/HTMLTemplate.js index 874cebb..4627199 100644 --- a/src/routes/content/adobe-commerce/templates/html/HTMLTemplate.js +++ b/src/routes/content/adobe-commerce/templates/html/HTMLTemplate.js @@ -15,6 +15,16 @@ import { findProductImage } from '../../util.js'; import jsonTemplateFromContext from '../json/index.js'; +/** + * @typedef {import('../../types.d.ts').Product} Product + * @typedef {import('../../types.d.ts').Variant} Variant + * @typedef {import('../../types.d.ts').Image} Image + * @typedef {import('../../types.d.ts').Attribute} Attribute + * @typedef {import('../../types.d.ts').OptionValue} OptionValue + * @typedef {import('../../types.d.ts').Prices} Prices + * @typedef {import('../../types.d.ts').ProductOption} ProductOption + */ + export class HTMLTemplate { /** * Create a meta tag with a name attribute diff --git a/src/routes/content/adobe-commerce/templates/html/index.js b/src/routes/content/adobe-commerce/templates/html/index.js index e715420..032b580 100644 --- a/src/routes/content/adobe-commerce/templates/html/index.js +++ b/src/routes/content/adobe-commerce/templates/html/index.js @@ -13,6 +13,11 @@ import { HTMLTemplate } from './HTMLTemplate.js'; import OVERRIDES from './overrides/index.js'; +/** + * @typedef {import('../../types.d.ts').Product} Product + * @typedef {import('../../types.d.ts').Variant} Variant + */ + /** * @param {Context} ctx * @param {Product} product diff --git a/src/routes/content/adobe-commerce/templates/html/overrides/wilson-ecommerce--wilson.js b/src/routes/content/adobe-commerce/templates/html/overrides/wilson-ecommerce--wilson.js index 36a2e9a..15def9a 100644 --- a/src/routes/content/adobe-commerce/templates/html/overrides/wilson-ecommerce--wilson.js +++ b/src/routes/content/adobe-commerce/templates/html/overrides/wilson-ecommerce--wilson.js @@ -12,6 +12,11 @@ import { HTMLTemplate } from '../HTMLTemplate.js'; +/** + * @typedef {import('../../../types.d.ts').Product} Product + * @typedef {import('../../../types.d.ts').Variant} Variant + */ + export default class extends HTMLTemplate { /** * @param {Context} ctx diff --git a/src/routes/content/adobe-commerce/templates/json/JSONTemplate.js b/src/routes/content/adobe-commerce/templates/json/JSONTemplate.js index 6c46aa6..d14b752 100644 --- a/src/routes/content/adobe-commerce/templates/json/JSONTemplate.js +++ b/src/routes/content/adobe-commerce/templates/json/JSONTemplate.js @@ -15,6 +15,11 @@ import { pruneUndefined } from '../../../../../utils/product.js'; import { findProductImage } from '../../util.js'; +/** + * @typedef {import('../../types.d.ts').Product} Product + * @typedef {import('../../types.d.ts').Variant} Variant + */ + export class JSONTemplate { /** @type {Context} */ ctx = undefined; diff --git a/src/routes/content/adobe-commerce/templates/json/index.js b/src/routes/content/adobe-commerce/templates/json/index.js index d99beea..7fef90d 100644 --- a/src/routes/content/adobe-commerce/templates/json/index.js +++ b/src/routes/content/adobe-commerce/templates/json/index.js @@ -13,6 +13,11 @@ import { JSONTemplate } from './JSONTemplate.js'; import OVERRIDES from './overrides/index.js'; +/** + * @typedef {import('../../types.d.ts').Product} Product + * @typedef {import('../../types.d.ts').Variant} Variant + */ + /** * @param {Context} ctx * @param {Product} product diff --git a/src/routes/content/adobe-commerce/templates/json/overrides/thepixel--bul-eds.js b/src/routes/content/adobe-commerce/templates/json/overrides/thepixel--bul-eds.js index f7ceff3..00cb869 100644 --- a/src/routes/content/adobe-commerce/templates/json/overrides/thepixel--bul-eds.js +++ b/src/routes/content/adobe-commerce/templates/json/overrides/thepixel--bul-eds.js @@ -12,6 +12,11 @@ import { JSONTemplate } from '../JSONTemplate.js'; +/** + * @typedef {import('../../../types.d.ts').Product} Product + * @typedef {import('../../../types.d.ts').Variant} Variant + */ + export default class extends JSONTemplate { /** * @param {Variant} [variant] diff --git a/src/routes/content/adobe-commerce/templates/json/overrides/visualcomfort--adobe-edge.js b/src/routes/content/adobe-commerce/templates/json/overrides/visualcomfort--adobe-edge.js index 4faacf5..28ddc6f 100644 --- a/src/routes/content/adobe-commerce/templates/json/overrides/visualcomfort--adobe-edge.js +++ b/src/routes/content/adobe-commerce/templates/json/overrides/visualcomfort--adobe-edge.js @@ -12,6 +12,11 @@ import { JSONTemplate } from '../JSONTemplate.js'; +/** + * @typedef {import('../../../types.d.ts').Product} Product + * @typedef {import('../../../types.d.ts').Variant} Variant + */ + export default class extends JSONTemplate { // eslint-disable-next-line class-methods-use-this renderBrand() { diff --git a/src/routes/content/adobe-commerce/templates/json/overrides/wilson-ecommerce--wilson.js b/src/routes/content/adobe-commerce/templates/json/overrides/wilson-ecommerce--wilson.js index a6b7530..9596367 100644 --- a/src/routes/content/adobe-commerce/templates/json/overrides/wilson-ecommerce--wilson.js +++ b/src/routes/content/adobe-commerce/templates/json/overrides/wilson-ecommerce--wilson.js @@ -12,6 +12,11 @@ import { JSONTemplate } from '../JSONTemplate.js'; +/** + * @typedef {import('../../../types.d.ts').Product} Product + * @typedef {import('../../../types.d.ts').Variant} Variant + */ + export default class extends JSONTemplate { // eslint-disable-next-line class-methods-use-this renderBrand() { diff --git a/src/routes/content/adobe-commerce/types.d.ts b/src/routes/content/adobe-commerce/types.d.ts new file mode 100644 index 0000000..37bad5e --- /dev/null +++ b/src/routes/content/adobe-commerce/types.d.ts @@ -0,0 +1,125 @@ +export interface Product { + name: string; + sku: string; + addToCartAllowed: boolean; + inStock: boolean | null; + shortDescription?: string; + metaDescription?: string; + metaKeyword?: string; + metaTitle?: string; + description?: string; + images: Image[]; + prices: Prices; + attributes: Attribute[]; + options: ProductOption[]; + url?: string; + urlKey?: string; + externalId?: string; + variants?: Variant[]; // variants exist on products in helix commerce but not on magento + specialToDate?: string; + rating?: Rating; + links?: Link[]; + + // Coming only from Catalog Service at the time of writing: + lastModifiedAt?: string; + + // not handled currently: + externalParentId?: string; + variantSku?: string; + optionUIDs?: string[]; + + // internal use: + attributeMap: Record; +} + +export interface Variant { + sku: string; + name: string; + description?: string; + url: string; + inStock: boolean; + images: Image[]; + prices: Pick; + selections: string[]; + attributes: Attribute[]; + externalId: string; + specialToDate?: string; + gtin?: string; + rating?: Rating; + + // internal use: + attributeMap: Record; +} + +interface Rating { + // number of ratings + count?: number; + // number of reviews + reviews?: number; + // rating value + value: number | string; + // range of ratings, highest + best?: number | string; + // range of ratings, lowest + worst?: number | string; +} + +interface Link { + types: string[]; + sku: string; + urlKey: string; + prices: Prices; +} + +interface Image { + url: string; + label: string; + roles: string[]; +} + +interface Price { + amount?: number; + currency?: string; + maximumAmount?: number; + minimumAmount?: number; + variant?: 'default' | 'strikethrough'; +} + +interface Prices { + regular: Price; + final: Price; + visible: boolean; +} + +export interface ProductOption { + id: string; + type: 'text' | 'image' | 'color' | 'dropdown'; + typename: + | 'ProductViewOptionValueProduct' + | 'ProductViewOptionValueSwatch' + | 'ProductViewOptionValueConfiguration'; + label: string; + required: boolean; + multiple: boolean; + items: OptionValue[]; +} + +interface OptionValue { + id: string; + label: string; + inStock: boolean; + value: string; + selected: boolean; + type: string; + product?: { + name: string; + sku: string; + prices?: Prices; + }; +} + +interface Attribute { + name: string; + label: string; + value: string; +} \ No newline at end of file diff --git a/src/routes/content/adobe-commerce/util.js b/src/routes/content/adobe-commerce/util.js index b0d27c1..60317bd 100644 --- a/src/routes/content/adobe-commerce/util.js +++ b/src/routes/content/adobe-commerce/util.js @@ -12,6 +12,12 @@ import { pruneUndefined } from '../../../utils/product.js'; +/** + * @typedef {import('./types.d.ts').Product} Product + * @typedef {import('./types.d.ts').Variant} Variant + * @typedef {import('./types.d.ts').Rating} Rating + */ + /** * This function combines an array of strings with interpolated * parameters to create a GraphQL query string. diff --git a/src/types.d.ts b/src/types.d.ts index 77ad1d0..daa6bb9 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -272,132 +272,6 @@ declare global { executionContext: ExecutionContext; } - export interface Product { - name: string; - sku: string; - addToCartAllowed: boolean; - inStock: boolean | null; - shortDescription?: string; - metaDescription?: string; - metaKeyword?: string; - metaTitle?: string; - description?: string; - images: Image[]; - prices: Prices; - attributes: Attribute[]; - options: ProductOption[]; - url?: string; - urlKey?: string; - externalId?: string; - variants?: Variant[]; // variants exist on products in helix commerce but not on magento - specialToDate?: string; - rating?: Rating; - links?: Link[]; - - // Coming only from Catalog Service at the time of writing: - lastModifiedAt?: string; - - // not handled currently: - externalParentId?: string; - variantSku?: string; - optionUIDs?: string[]; - - // internal use: - attributeMap: Record; - } - - export interface Variant { - sku: string; - name: string; - description?: string; - url: string; - inStock: boolean; - images: Image[]; - prices: Pick; - selections: string[]; - attributes: Attribute[]; - externalId: string; - specialToDate?: string; - gtin?: string; - rating?: Rating; - - // internal use: - attributeMap: Record; - } - - interface Rating { - // number of ratings - count?: number; - // number of reviews - reviews?: number; - // rating value - value: number | string; - // range of ratings, highest - best?: number | string; - // range of ratings, lowest - worst?: number | string; - } - - interface Link { - types: string[]; - sku: string; - urlKey: string; - prices: Prices; - } - - interface Image { - url: string; - label: string; - roles: string[]; - } - - interface Price { - amount?: number; - currency?: string; - maximumAmount?: number; - minimumAmount?: number; - variant?: 'default' | 'strikethrough'; - } - - interface Prices { - regular: Price; - final: Price; - visible: boolean; - } - - export interface ProductOption { - id: string; - type: 'text' | 'image' | 'color' | 'dropdown'; - typename: - | 'ProductViewOptionValueProduct' - | 'ProductViewOptionValueSwatch' - | 'ProductViewOptionValueConfiguration'; - label: string; - required: boolean; - multiple: boolean; - items: OptionValue[]; - } - - interface OptionValue { - id: string; - label: string; - inStock: boolean; - value: string; - selected: boolean; - type: string; - product?: { - name: string; - sku: string; - prices?: Prices; - }; - } - - interface Attribute { - name: string; - label: string; - value: string; - } - interface BatchResult { sku: string; status: number; From 71250eff7ab0d1b29569482b5eb950c157981d53 Mon Sep 17 00:00:00 2001 From: Max Edell Date: Thu, 6 Mar 2025 17:58:14 -0800 Subject: [PATCH 3/3] chore: fix tests --- test/routes/catalog/StorageClient.test.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/test/routes/catalog/StorageClient.test.js b/test/routes/catalog/StorageClient.test.js index 59c0d3a..71d76e2 100644 --- a/test/routes/catalog/StorageClient.test.js +++ b/test/routes/catalog/StorageClient.test.js @@ -595,7 +595,6 @@ describe('StorageClient Class Tests', () => { assert.deepStrictEqual(results, [ { sku: 'sku1', - status: 200, message: 'Product saved successfully.', '/products/product-1/sku1': { preview: { @@ -608,7 +607,6 @@ describe('StorageClient Class Tests', () => { }, { sku: 'sku2', - status: 200, message: 'Product saved successfully.', '/products/product-2/sku2': { preview: { @@ -688,7 +686,6 @@ describe('StorageClient Class Tests', () => { assert.deepStrictEqual(results, [ { sku: 'sku1', - status: 200, message: 'Product saved successfully.', '/products/sku1': { preview: { @@ -701,7 +698,6 @@ describe('StorageClient Class Tests', () => { }, { sku: 'sku2', - status: 200, message: 'Product saved successfully.', '/products/sku2': { preview: { @@ -798,7 +794,6 @@ describe('StorageClient Class Tests', () => { assert.deepStrictEqual(results, [ { sku: 'sku1', - status: 200, message: 'Product saved successfully.', '/products/product-1/sku1': { preview: { @@ -976,7 +971,6 @@ describe('StorageClient Class Tests', () => { assert.deepStrictEqual(results, [ { sku: 'sku1', - status: 200, message: 'Product saved successfully.', '/products/product-1/sku1': { preview: { @@ -989,7 +983,6 @@ describe('StorageClient Class Tests', () => { }, { sku: 'sku2', - status: 200, message: 'Product saved successfully.', '/products/product-2/sku2': { preview: { @@ -1158,7 +1151,6 @@ describe('StorageClient Class Tests', () => { assert.deepStrictEqual(results, [ { sku: 'sku1', - status: 200, message: 'Product saved successfully.', '/products/product-1/sku1': { preview: { @@ -1171,7 +1163,6 @@ describe('StorageClient Class Tests', () => { }, { sku: 'sku2', - status: 200, message: 'Product saved successfully.', '/products/sku2': { preview: { @@ -1184,7 +1175,6 @@ describe('StorageClient Class Tests', () => { }, { sku: 'sku3', - status: 200, message: 'Product saved successfully.', '/products/product-3/sku3': { preview: { @@ -1560,7 +1550,6 @@ describe('StorageClient Class Tests', () => { assert.deepStrictEqual(results, [ { sku: 'sku1', - status: 200, message: 'Product deleted successfully.', '/products/product-1/sku1': { preview: { @@ -1573,7 +1562,6 @@ describe('StorageClient Class Tests', () => { }, { sku: 'sku2', - status: 200, message: 'Product deleted successfully.', '/products/product-2/sku2': { preview: { @@ -1650,7 +1638,6 @@ describe('StorageClient Class Tests', () => { assert.deepStrictEqual(results, [ { sku: 'sku1', - status: 200, message: 'Product deleted successfully.', '/products/sku1': { preview: { @@ -1663,7 +1650,6 @@ describe('StorageClient Class Tests', () => { }, { sku: 'sku2', - status: 200, message: 'Product deleted successfully.', '/products/sku2': { preview: {