Skip to content

Commit b91a4c4

Browse files
committed
chore: cleanup types
1 parent 9ea0c4b commit b91a4c4

19 files changed

+31
-72
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/handler.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ import media from './media.js';
1818
const ALLOWED_METHODS = ['GET'];
1919

2020
/**
21-
* @param {Context} ctx
22-
* @returns {Promise<Response>}
21+
* @type {RouteHandler}
2322
*/
24-
export default async function contentHandler(ctx) {
23+
export default async function contentHandler(ctx, req) {
2524
const {
2625
log,
2726
config,
@@ -33,7 +32,7 @@ export default async function contentHandler(ctx) {
3332
}
3433

3534
if (['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp'].includes(info.extension)) {
36-
return media(ctx);
35+
return media(ctx, req);
3736
}
3837

3938
if (!config.pageType) {
@@ -42,8 +41,8 @@ export default async function contentHandler(ctx) {
4241
log.debug('config: ', JSON.stringify(config, null, 2));
4342

4443
if (config.catalogSource === 'adobe-commerce') {
45-
return adobeCommerce(ctx);
44+
return adobeCommerce(ctx, req);
4645
}
4746

48-
return helixCommerce(ctx);
47+
return helixCommerce(ctx, req);
4948
}

src/routes/content/helix-commerce.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ ${indent(product.images?.map(pictureTemplate).join('\n'), 10)}
145145
</html>`;
146146

147147
/**
148-
* @param {Context} ctx
149-
* @returns {Promise<Response>}
148+
* @type {RouteHandler}
150149
*/
151150
export default async function handler(ctx) {
152151
const { config: { params } } = ctx;

src/routes/content/media.js

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

1515
/**
16-
* @param {Context} ctx
16+
* @type {RouteHandler}
1717
*/
1818
export default async function handler(ctx) {
1919
const {

src/routes/index.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ import config from './config/handler.js';
1616
import auth from './auth/handler.js';
1717

1818
/**
19-
* @type {Record<
20-
* string,
21-
* (
22-
* ctx: Context,
23-
* request: import("@cloudflare/workers-types/experimental").Request
24-
* ) => Promise<Response>
25-
* >}
19+
* @type {Record<string, RouteHandler>}
2620
*/
2721
export default {
2822
content,

src/types.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ declare global {
414414
status: number;
415415
message?: string;
416416
}
417+
418+
export type RouteHandler = (ctx: Context, request: import("@cloudflare/workers-types").Request) => Promise<Response>;
417419
}
418420

419421
export { };

src/utils/admin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
/* eslint-disable no-await-in-loop */
14-
1513
import { getPreviewPublishPaths } from './product.js';
1614

1715
/**
@@ -125,7 +123,9 @@ export async function callPreviewPublish(config, method, sku, urlKey) {
125123

126124
// Conditional sequencing or parallel execution based on the method
127125
const operations = method === 'POST'
126+
// eslint-disable-next-line no-await-in-loop
128127
? [await callAdminWithOp('preview'), await callAdminWithOp('live')]
128+
// eslint-disable-next-line no-await-in-loop
129129
: await Promise.all(['preview', 'live'].map(callAdminWithOp));
130130

131131
operations.forEach(({ op, status, message }) => {

0 commit comments

Comments
 (0)