Skip to content

Commit 14502e9

Browse files
authored
chore: types cleanup (#82)
* chore: cleanup types * chore: more types cleanup * chore: fix tests
1 parent 9ea0c4b commit 14502e9

32 files changed

+213
-212
lines changed

src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { resolveConfig } from './utils/config.js';
1515
import handlers from './routes/index.js';
1616

1717
/**
18-
* @param {import("@cloudflare/workers-types/experimental").Request} req
18+
* @param {import("@cloudflare/workers-types").Request} req
1919
*/
2020
async function parseData(req) {
2121
if (['GET', 'HEAD', 'OPTIONS'].includes(req.method)) {
@@ -41,7 +41,7 @@ async function parseData(req) {
4141

4242
/**
4343
* @param {import("@cloudflare/workers-types/experimental").ExecutionContext} eCtx
44-
* @param {import("@cloudflare/workers-types/experimental").Request} req
44+
* @param {import("@cloudflare/workers-types").Request} req
4545
* @param {Env} env
4646
* @returns {Promise<Context>}
4747
*/
@@ -72,7 +72,7 @@ export async function makeContext(eCtx, req, env) {
7272

7373
export default {
7474
/**
75-
* @param {import("@cloudflare/workers-types/experimental").Request} request
75+
* @param {import("@cloudflare/workers-types").Request} request
7676
* @param {Env} env
7777
* @param {import("@cloudflare/workers-types/experimental").ExecutionContext} eCtx
7878
* @returns {Promise<Response>}

src/routes/auth/fetch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { assertAuthorization } from '../../utils/auth.js';
1414
import { errorResponse } from '../../utils/http.js';
1515

1616
/**
17-
* @param {Context} ctx
17+
* @type {RouteHandler}
1818
*/
1919
export default async function fetch(ctx) {
2020
const { config } = ctx;

src/routes/auth/handler.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,7 @@ import update from './update.js';
1616
import rotate from './rotate.js';
1717

1818
/**
19-
* @type {Record<
20-
* string,
21-
* Record<
22-
* string,
23-
* (
24-
* ctx: Context,
25-
* req: import("@cloudflare/workers-types/experimental").Request
26-
* ) => Promise<Response>
27-
* >
28-
* >}
19+
* @type {Record<string, Record<string, RouteHandler>>}
2920
*/
3021
const handlers = {
3122
token: {
@@ -36,9 +27,7 @@ const handlers = {
3627
};
3728

3829
/**
39-
* @param {Context} ctx
40-
* @param {import("@cloudflare/workers-types/experimental").Request} req
41-
* @returns {Promise<Response>}
30+
* @type {RouteHandler}
4231
*/
4332
export default async function handler(ctx, req) {
4433
const {

src/routes/auth/rotate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { errorResponse } from '../../utils/http.js';
1515
import { updateToken } from './update.js';
1616

1717
/**
18-
* @param {Context} ctx
18+
* @type {RouteHandler}
1919
*/
2020
export default async function rotate(ctx) {
2121
const { data } = ctx;

src/routes/auth/update.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function updateToken(ctx, token = generateToken()) {
3333
}
3434

3535
/**
36-
* @param {Context} ctx
36+
* @type {RouteHandler}
3737
*/
3838
export default async function update(ctx) {
3939
const { data } = ctx;

src/routes/catalog/StorageClient.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export default class StorageClient {
115115
}
116116

117117
// Attempt to save the product
118-
const putResponse = await env.CATALOG_BUCKET.put(key, body, {
118+
await env.CATALOG_BUCKET.put(key, body, {
119119
httpMetadata: { contentType: 'application/json' },
120120
customMetadata,
121121
});
@@ -136,7 +136,6 @@ export default class StorageClient {
136136
*/
137137
const result = {
138138
sku,
139-
status: putResponse.status,
140139
message: 'Product saved successfully.',
141140
...adminResponse.paths,
142141
};
@@ -203,7 +202,7 @@ export default class StorageClient {
203202
};
204203
}
205204
const { customMetadata } = productHead;
206-
const deleteProductResponse = await env.CATALOG_BUCKET.delete(productKey);
205+
await env.CATALOG_BUCKET.delete(productKey);
207206

208207
const { urlKey } = customMetadata;
209208
if (urlKey) {
@@ -217,7 +216,6 @@ export default class StorageClient {
217216
*/
218217
const result = {
219218
sku,
220-
status: deleteProductResponse?.status,
221219
message: 'Product deleted successfully.',
222220
...adminResponse.paths,
223221
};

src/routes/catalog/fetch.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import StorageClient from './StorageClient.js';
1414

1515
/**
16-
* Handles a GET request for a product.
17-
* @param {Context} ctx - The context object containing request information and utilities.
18-
* @returns {Promise<Response>} - A promise that resolves to the product response.
16+
* @type {RouteHandler}
1917
*/
2018
export default async function fetch(ctx) {
2119
const { sku } = ctx.config;

src/routes/catalog/handler.js

+2-15
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,7 @@ import update from './update.js';
1717
import remove from './remove.js';
1818

1919
/**
20-
* @type {Record<
21-
* string,
22-
* Record<
23-
* string,
24-
* (
25-
* ctx: Context,
26-
* req: import("@cloudflare/workers-types/experimental").Request
27-
* ) => Promise<Response>
28-
* >
29-
* >
30-
* }
20+
* @type {Record<string, Record<string, RouteHandler>>}
3121
*/
3222
const handlers = {
3323
lookup: {
@@ -47,10 +37,7 @@ const handlers = {
4737
};
4838

4939
/**
50-
* Handles productbus requests.
51-
* @param {Context} ctx - The context object containing request information and utilities.
52-
* @param {import("@cloudflare/workers-types/experimental").Request} request - The request object.
53-
* @returns {Promise<Response>} - A promise that resolves to the catalog response.
40+
* @type {RouteHandler}
5441
*/
5542
export default async function handler(ctx, request) {
5643
const {

src/routes/catalog/lookup.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import StorageClient from './StorageClient.js';
1414

1515
/**
16-
* Handles a product lookup request.
17-
* @param {Context} ctx - The context object.
18-
* @returns {Promise<Response>} - A promise that resolves to the product response.
16+
* @type {RouteHandler}
1917
*/
2018
export default async function lookup(ctx) {
2119
const {

src/routes/catalog/remove.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import { errorResponse, errorWithResponse } from '../../utils/http.js';
1515
import StorageClient from './StorageClient.js';
1616

1717
/**
18-
* Handles a DELETE request for a product.
19-
* @param {Context} ctx - The context object containing request information and utilities.
20-
* @returns {Promise<Response>} - A promise that resolves to the product response.
18+
* @type {RouteHandler}
2119
*/
2220
export default async function remove(ctx) {
2321
const { log, config } = ctx;

src/routes/catalog/update.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import { errorResponse } from '../../utils/http.js';
1515
import StorageClient from './StorageClient.js';
1616
import { assertAuthorization } from '../../utils/auth.js';
1717
import { extractAndReplaceImages } from '../../utils/media.js';
18+
1819
/**
19-
* Handles a PUT request to update a product.
20-
* @param {Context} ctx - The context object containing request information and utilities.
21-
* @returns {Promise<Response>} - A promise that resolves to the product response.
20+
* @type {RouteHandler}
2221
*/
2322
export default async function update(ctx) {
2423
const { config, log, data } = ctx;

src/routes/config/handler.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import { updateToken } from '../auth/update.js';
1717
import ConfigSchema from '../../schemas/Config.js';
1818

1919
/**
20-
* @param {Context} ctx
21-
* @returns {Promise<Response>}
20+
* @type {RouteHandler}
2221
*/
2322
export default async function configHandler(ctx) {
2423
const { method } = ctx.info;

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ function lookupProductSKU(urlkey, config) {
212212
}
213213

214214
/**
215-
* @param {Context} ctx
216-
* @returns {Promise<Response>}
215+
* @type {RouteHandler}
217216
*/
218217
export default async function handler(ctx) {
219218
const { config } = ctx;

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() {

0 commit comments

Comments
 (0)