Skip to content

chore: types cleanup #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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<Context>}
*/
Expand Down Expand Up @@ -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<Response>}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/auth/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 2 additions & 13 deletions src/routes/auth/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response>
* >
* >}
* @type {Record<string, Record<string, RouteHandler>>}
*/
const handlers = {
token: {
Expand All @@ -36,9 +27,7 @@ const handlers = {
};

/**
* @param {Context} ctx
* @param {import("@cloudflare/workers-types/experimental").Request} req
* @returns {Promise<Response>}
* @type {RouteHandler}
*/
export default async function handler(ctx, req) {
const {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/auth/rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/auth/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/routes/catalog/StorageClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -136,7 +136,6 @@ export default class StorageClient {
*/
const result = {
sku,
status: putResponse.status,
message: 'Product saved successfully.',
...adminResponse.paths,
};
Expand Down Expand Up @@ -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) {
Expand All @@ -217,7 +216,6 @@ export default class StorageClient {
*/
const result = {
sku,
status: deleteProductResponse?.status,
message: 'Product deleted successfully.',
...adminResponse.paths,
};
Expand Down
4 changes: 1 addition & 3 deletions src/routes/catalog/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response>} - A promise that resolves to the product response.
* @type {RouteHandler}
*/
export default async function fetch(ctx) {
const { sku } = ctx.config;
Expand Down
17 changes: 2 additions & 15 deletions src/routes/catalog/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response>
* >
* >
* }
* @type {Record<string, Record<string, RouteHandler>>}
*/
const handlers = {
lookup: {
Expand All @@ -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<Response>} - A promise that resolves to the catalog response.
* @type {RouteHandler}
*/
export default async function handler(ctx, request) {
const {
Expand Down
4 changes: 1 addition & 3 deletions src/routes/catalog/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import StorageClient from './StorageClient.js';

/**
* Handles a product lookup request.
* @param {Context} ctx - The context object.
* @returns {Promise<Response>} - A promise that resolves to the product response.
* @type {RouteHandler}
*/
export default async function lookup(ctx) {
const {
Expand Down
4 changes: 1 addition & 3 deletions src/routes/catalog/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response>} - A promise that resolves to the product response.
* @type {RouteHandler}
*/
export default async function remove(ctx) {
const { log, config } = ctx;
Expand Down
5 changes: 2 additions & 3 deletions src/routes/catalog/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response>} - A promise that resolves to the product response.
* @type {RouteHandler}
*/
export default async function update(ctx) {
const { config, log, data } = ctx;
Expand Down
3 changes: 1 addition & 2 deletions src/routes/config/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import { updateToken } from '../auth/update.js';
import ConfigSchema from '../../schemas/Config.js';

/**
* @param {Context} ctx
* @returns {Promise<Response>}
* @type {RouteHandler}
*/
export default async function configHandler(ctx) {
const { method } = ctx.info;
Expand Down
3 changes: 1 addition & 2 deletions src/routes/content/adobe-commerce/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ function lookupProductSKU(urlkey, config) {
}

/**
* @param {Context} ctx
* @returns {Promise<Response>}
* @type {RouteHandler}
*/
export default async function handler(ctx) {
const { config } = ctx;
Expand Down
4 changes: 4 additions & 0 deletions src/routes/content/adobe-commerce/queries/cs-product.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/routes/content/adobe-commerce/queries/cs-variants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
forceImagesHTTPS,
} from '../util.js';

/**
* @typedef {import('../types.d.ts').Variant} Variant
/**
* @param {Config} config
* @param {any} variants
Expand Down
10 changes: 10 additions & 0 deletions src/routes/content/adobe-commerce/templates/html/HTMLTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/routes/content/adobe-commerce/templates/html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/routes/content/adobe-commerce/templates/json/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading