Added eslint rule for dangerous logger calls and updates apps
This commit is contained in:
parent
c2d05ebf55
commit
689732e2ff
17 changed files with 95 additions and 53 deletions
5
.changeset/fast-spiders-share.md
Normal file
5
.changeset/fast-spiders-share.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"eslint-config-saleor": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Added eslint-plugin-saleor configuration, that errors dangerous logger statements. This should reduce risk of printing too much in logs
|
|
@ -1,7 +1,9 @@
|
||||||
// This file sets a custom webpack configuration to use your Next.js app
|
/*
|
||||||
// with Sentry.
|
* This file sets a custom webpack configuration to use your Next.js app
|
||||||
// https://nextjs.org/docs/api-reference/next.config.js/introduction
|
* with Sentry.
|
||||||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
|
* https://nextjs.org/docs/api-reference/next.config.js/introduction
|
||||||
|
* https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
|
||||||
|
*/
|
||||||
const { withSentryConfig } = require("@sentry/nextjs");
|
const { withSentryConfig } = require("@sentry/nextjs");
|
||||||
|
|
||||||
const isSentryPropertiesInEnvironment =
|
const isSentryPropertiesInEnvironment =
|
||||||
|
|
|
@ -75,7 +75,12 @@ const executeCmsClientOperation = async ({
|
||||||
deletedCmsId: cmsId,
|
deletedCmsId: cmsId,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error deleting item", { error });
|
logger.error(
|
||||||
|
{
|
||||||
|
error: { message: (error as Error).message, stack: (error as Error).stack },
|
||||||
|
},
|
||||||
|
"Error deleting item"
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
error: "Error deleting item.",
|
error: "Error deleting item.",
|
||||||
|
@ -104,7 +109,9 @@ const executeCmsClientOperation = async ({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error updating item", { error });
|
logger.error("Error updating item", {
|
||||||
|
error: { message: (error as Error).message, stack: (error as Error).stack },
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
error: "Error updating item.",
|
error: "Error updating item.",
|
||||||
|
@ -137,7 +144,9 @@ const executeCmsClientOperation = async ({
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error creating item", { error });
|
logger.error("Error creating item", {
|
||||||
|
error: { message: (error as Error).message, stack: (error as Error).stack },
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
error: "Error creating item.",
|
error: "Error creating item.",
|
||||||
|
@ -209,7 +218,12 @@ export const executeCmsClientBatchOperation = async ({
|
||||||
.map((item) => (item as ProductResponseSuccess).data) || [],
|
.map((item) => (item as ProductResponseSuccess).data) || [],
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error({ error }, "Error creating batch items");
|
logger.error(
|
||||||
|
{
|
||||||
|
error: { message: (error as Error).message, stack: (error as Error).stack },
|
||||||
|
},
|
||||||
|
"Error creating batch items"
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
error: "Error creating batch items.",
|
error: "Error creating batch items.",
|
||||||
|
@ -252,7 +266,12 @@ export const executeCmsClientBatchOperation = async ({
|
||||||
deletedCmsIds: CMSIdsToRemove,
|
deletedCmsIds: CMSIdsToRemove,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error({ error }, "Error removing batch items");
|
logger.error(
|
||||||
|
{
|
||||||
|
error: { message: (error as Error).message, stack: (error as Error).stack },
|
||||||
|
},
|
||||||
|
"Error removing batch items"
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
error: "Error removing batch items.",
|
error: "Error removing batch items.",
|
||||||
|
|
|
@ -39,7 +39,7 @@ export const createCmsOperations = async ({
|
||||||
getProviderInstancesSettings(settingsManager),
|
getProviderInstancesSettings(settingsManager),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
logger.debug({ channelsSettingsParsed, providerInstancesSettingsParsed }, "Fetched settings");
|
logger.debug("Fetched settings");
|
||||||
|
|
||||||
const productVariantCmsProviderInstances = productVariantCmsKeys.map((cmsKey) =>
|
const productVariantCmsProviderInstances = productVariantCmsKeys.map((cmsKey) =>
|
||||||
getCmsIdFromSaleorItemKey(cmsKey)
|
getCmsIdFromSaleorItemKey(cmsKey)
|
||||||
|
|
|
@ -107,7 +107,8 @@ const contentfulOperations: CreateOperations<ContentfulConfig> = (config) => {
|
||||||
const response = await contentfulFetch(endpoint, config, { method: "GET" });
|
const response = await contentfulFetch(endpoint, config, { method: "GET" });
|
||||||
const respBody = await response.json();
|
const respBody = await response.json();
|
||||||
|
|
||||||
logger.debug({ response, body: respBody }, "pingCMS response");
|
logger.trace("pingCMS success");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ok: response.ok,
|
ok: response.ok,
|
||||||
};
|
};
|
||||||
|
@ -130,7 +131,8 @@ const contentfulOperations: CreateOperations<ContentfulConfig> = (config) => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.debug({ response }, "createProduct response");
|
logger.trace("createProduct success");
|
||||||
|
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -150,10 +152,11 @@ const contentfulOperations: CreateOperations<ContentfulConfig> = (config) => {
|
||||||
|
|
||||||
const getEntryResponse = await contentfulFetch(endpoint, config, { method: "GET" });
|
const getEntryResponse = await contentfulFetch(endpoint, config, { method: "GET" });
|
||||||
|
|
||||||
logger.debug({ getEntryResponse }, "updateProduct getEntryResponse");
|
logger.trace("updateProduct success");
|
||||||
|
|
||||||
const entry = await getEntryResponse.json();
|
const entry = await getEntryResponse.json();
|
||||||
|
|
||||||
logger.debug({ entry }, "updateProduct entry");
|
logger.trace("updateProduct entry success");
|
||||||
|
|
||||||
const response = await contentfulFetch(endpoint, config, {
|
const response = await contentfulFetch(endpoint, config, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
|
@ -163,7 +166,8 @@ const contentfulOperations: CreateOperations<ContentfulConfig> = (config) => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.debug({ response }, "updateProduct response");
|
logger.trace("updateProduct success");
|
||||||
|
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -226,42 +230,42 @@ const contentfulOperations: CreateOperations<ContentfulConfig> = (config) => {
|
||||||
ping: async () => {
|
ping: async () => {
|
||||||
const response = await pingCMS();
|
const response = await pingCMS();
|
||||||
|
|
||||||
logger.debug({ response }, "ping response");
|
logger.trace("ping success");
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
createProduct: async ({ input }) => {
|
createProduct: async ({ input }) => {
|
||||||
const result = await createProductInCMS(input);
|
const result = await createProductInCMS(input);
|
||||||
|
|
||||||
logger.debug({ result }, "createProduct result");
|
logger.trace("createProduct success");
|
||||||
|
|
||||||
return transformCreateProductResponse(result);
|
return transformCreateProductResponse(result);
|
||||||
},
|
},
|
||||||
updateProduct: async ({ id, input }) => {
|
updateProduct: async ({ id, input }) => {
|
||||||
const result = await updateProductInCMS(id, input);
|
const result = await updateProductInCMS(id, input);
|
||||||
|
|
||||||
logger.debug({ result }, "updateProduct result");
|
logger.trace("updateProduct result");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
deleteProduct: async ({ id }) => {
|
deleteProduct: async ({ id }) => {
|
||||||
const response = await deleteProductInCMS(id);
|
const response = await deleteProductInCMS(id);
|
||||||
|
|
||||||
logger.debug({ response }, "deleteProduct response");
|
logger.trace("deleteProduct success");
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
createBatchProducts: async ({ input }) => {
|
createBatchProducts: async ({ input }) => {
|
||||||
const results = await createBatchProductsInCMS(input);
|
const results = await createBatchProductsInCMS(input);
|
||||||
|
|
||||||
logger.debug({ results }, "createBatchProducts results");
|
logger.trace("createBatchProducts success");
|
||||||
|
|
||||||
return results.map((result) => transformCreateProductResponse(result));
|
return results.map((result) => transformCreateProductResponse(result));
|
||||||
},
|
},
|
||||||
deleteBatchProducts: async ({ ids }) => {
|
deleteBatchProducts: async ({ ids }) => {
|
||||||
const results = await deleteBatchProductsInCMS(ids);
|
const results = await deleteBatchProductsInCMS(ids);
|
||||||
|
|
||||||
logger.debug({ results }, "deleteBatchProducts results");
|
logger.trace("deleteBatchProducts success");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -112,7 +112,7 @@ const datocmsOperations: CreateOperations<DatocmsConfig> = (config) => {
|
||||||
try {
|
try {
|
||||||
const item = await createProductInCMS(input);
|
const item = await createProductInCMS(input);
|
||||||
|
|
||||||
logger.debug({ item }, "createProduct response");
|
logger.trace("createProduct success");
|
||||||
|
|
||||||
return transformResponseItem(item, input);
|
return transformResponseItem(item, input);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -122,24 +122,24 @@ const datocmsOperations: CreateOperations<DatocmsConfig> = (config) => {
|
||||||
updateProduct: async ({ id, input }) => {
|
updateProduct: async ({ id, input }) => {
|
||||||
const item = await updateProductInCMS(id, input);
|
const item = await updateProductInCMS(id, input);
|
||||||
|
|
||||||
logger.debug({ item }, "updateProduct response");
|
logger.trace("updateProduct success");
|
||||||
},
|
},
|
||||||
deleteProduct: async ({ id }) => {
|
deleteProduct: async ({ id }) => {
|
||||||
const item = await deleteProductInCMS(id);
|
const item = await deleteProductInCMS(id);
|
||||||
|
|
||||||
logger.debug({ item }, "deleteProduct response");
|
logger.trace("deleteProduct success");
|
||||||
},
|
},
|
||||||
createBatchProducts: async ({ input }) => {
|
createBatchProducts: async ({ input }) => {
|
||||||
const items = await createBatchProductsInCMS(input);
|
const items = await createBatchProductsInCMS(input);
|
||||||
|
|
||||||
logger.debug({ items }, "createBatchProducts response");
|
logger.trace("createBatchProducts success");
|
||||||
|
|
||||||
return items.map((item) => transformResponseItem(item.id, item.input));
|
return items.map((item) => transformResponseItem(item.id, item.input));
|
||||||
},
|
},
|
||||||
deleteBatchProducts: async ({ ids }) => {
|
deleteBatchProducts: async ({ ids }) => {
|
||||||
const items = await deleteBatchProductsInCMS(ids);
|
const items = await deleteBatchProductsInCMS(ids);
|
||||||
|
|
||||||
logger.debug({ items }, "deleteBatchProducts response");
|
logger.trace("deleteBatchProducts success");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -88,7 +88,8 @@ export const strapiOperations: CreateStrapiOperations = (config) => {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.debug({ response }, "pingCMS response");
|
logger.debug("pingCMS success");
|
||||||
|
|
||||||
return { ok: response.ok };
|
return { ok: response.ok };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -99,7 +100,7 @@ export const strapiOperations: CreateStrapiOperations = (config) => {
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.debug({ response }, "createProduct response");
|
logger.debug("createProduct success");
|
||||||
return await response.json();
|
return await response.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -135,42 +136,42 @@ export const strapiOperations: CreateStrapiOperations = (config) => {
|
||||||
ping: async () => {
|
ping: async () => {
|
||||||
const response = await pingCMS();
|
const response = await pingCMS();
|
||||||
|
|
||||||
logger.debug({ response }, "ping response");
|
logger.debug("ping response");
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
createProduct: async ({ input }) => {
|
createProduct: async ({ input }) => {
|
||||||
const result = await createProductInCMS(input);
|
const result = await createProductInCMS(input);
|
||||||
|
|
||||||
logger.debug({ result }, "createProduct result");
|
logger.debug("createProduct success");
|
||||||
|
|
||||||
return transformCreateProductResponse(result, input);
|
return transformCreateProductResponse(result, input);
|
||||||
},
|
},
|
||||||
updateProduct: async ({ id, input }) => {
|
updateProduct: async ({ id, input }) => {
|
||||||
const response = await updateProductInCMS(id, input);
|
const response = await updateProductInCMS(id, input);
|
||||||
|
|
||||||
logger.debug({ response }, "updateProduct response");
|
logger.debug("updateProduct success");
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
deleteProduct: async ({ id }) => {
|
deleteProduct: async ({ id }) => {
|
||||||
const response = await deleteProductInCMS(id);
|
const response = await deleteProductInCMS(id);
|
||||||
|
|
||||||
logger.debug({ response }, "deleteProduct response");
|
logger.debug("deleteProduct success");
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
createBatchProducts: async ({ input }) => {
|
createBatchProducts: async ({ input }) => {
|
||||||
const results = await createBatchProductsInCMS(input);
|
const results = await createBatchProductsInCMS(input);
|
||||||
|
|
||||||
logger.debug({ results }, "createBatchProducts results");
|
logger.debug("createBatchProducts success");
|
||||||
|
|
||||||
return results.map((result) => transformCreateProductResponse(result.response, result.input));
|
return results.map((result) => transformCreateProductResponse(result.response, result.input));
|
||||||
},
|
},
|
||||||
deleteBatchProducts: async ({ ids }) => {
|
deleteBatchProducts: async ({ ids }) => {
|
||||||
const responses = await deleteBatchProductsInCMS(ids);
|
const responses = await deleteBatchProductsInCMS(ids);
|
||||||
|
|
||||||
logger.debug({ responses }, "deleteBatchProducts responses");
|
logger.debug("deleteBatchProducts success");
|
||||||
|
|
||||||
return responses;
|
return responses;
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,7 +12,12 @@
|
||||||
"VERCEL_URL",
|
"VERCEL_URL",
|
||||||
"REST_APL_ENDPOINT",
|
"REST_APL_ENDPOINT",
|
||||||
"REST_APL_TOKEN",
|
"REST_APL_TOKEN",
|
||||||
"ALLOWED_DOMAIN_PATTERN"
|
"ALLOWED_DOMAIN_PATTERN",
|
||||||
|
"SENTRY_AUTH_TOKEN",
|
||||||
|
"SENTRY_PROJECT",
|
||||||
|
"SENTRY_ORG",
|
||||||
|
"SENTRY_DSN",
|
||||||
|
"NEXT_PUBLIC_SENTRY_DSN"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ const handler: NextApiHandler = async (req, res) => {
|
||||||
|
|
||||||
const { access_token } = await tokenResponse.json();
|
const { access_token } = await tokenResponse.json();
|
||||||
|
|
||||||
logger.debug({ access_token }, "Received mailchimp access_token");
|
logger.debug("Received mailchimp access_token");
|
||||||
|
|
||||||
const metadataResponse = await fetch("https://login.mailchimp.com/oauth2/metadata", {
|
const metadataResponse = await fetch("https://login.mailchimp.com/oauth2/metadata", {
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
@ -41,7 +41,7 @@ export const categoryMappingRouter = router({
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
{
|
{
|
||||||
input,
|
...input,
|
||||||
},
|
},
|
||||||
"Updated category mapping"
|
"Updated category mapping"
|
||||||
);
|
);
|
||||||
|
|
|
@ -88,7 +88,11 @@ export function getActiveConnection(
|
||||||
|
|
||||||
if (!providerConnection) {
|
if (!providerConnection) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
{ providerConnections, channelConfig },
|
{
|
||||||
|
providerConnectionsId: providerConnections.map((c) => c.id),
|
||||||
|
channelConfigId: channelConfig.config.providerConnectionId,
|
||||||
|
channelConfigSlug: channelConfig.config.slug,
|
||||||
|
},
|
||||||
"In the providers array, there is no item with an id that matches the channel config providerConnectionId."
|
"In the providers array, there is no item with an id that matches the channel config providerConnectionId."
|
||||||
);
|
);
|
||||||
throw new Error(`Channel config providerConnectionId does not match any providers`);
|
throw new Error(`Channel config providerConnectionId does not match any providers`);
|
||||||
|
|
|
@ -85,7 +85,7 @@ export const taxjarConnectionRouter = router({
|
||||||
location: "taxjarConnectionRouter.patch",
|
location: "taxjarConnectionRouter.patch",
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.debug({ input }, "Route patch called");
|
logger.debug("Route patch called");
|
||||||
|
|
||||||
const result = await ctx.connectionService.update(input.id, input.value);
|
const result = await ctx.connectionService.update(input.id, input.value);
|
||||||
|
|
||||||
|
|
|
@ -56,10 +56,10 @@ export default checkoutCalculateTaxesSyncWebhook.createHandler(async (req, res,
|
||||||
const channelSlug = payload.taxBase.channel.slug;
|
const channelSlug = payload.taxBase.channel.slug;
|
||||||
const taxProvider = getActiveConnection(channelSlug, appMetadata);
|
const taxProvider = getActiveConnection(channelSlug, appMetadata);
|
||||||
|
|
||||||
logger.info({ taxProvider }, "Will calculate taxes using the tax provider:");
|
logger.info("Will calculate taxes using the tax provider:");
|
||||||
const calculatedTaxes = await taxProvider.calculateTaxes(payload.taxBase);
|
const calculatedTaxes = await taxProvider.calculateTaxes(payload.taxBase);
|
||||||
|
|
||||||
logger.info({ calculatedTaxes }, "Taxes calculated");
|
logger.info("Taxes calculated");
|
||||||
return webhookResponse.success(ctx.buildResponse(calculatedTaxes));
|
return webhookResponse.success(ctx.buildResponse(calculatedTaxes));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return webhookResponse.error(error);
|
return webhookResponse.error(error);
|
||||||
|
|
|
@ -56,10 +56,10 @@ export default orderCalculateTaxesSyncWebhook.createHandler(async (req, res, ctx
|
||||||
const channelSlug = payload.taxBase.channel.slug;
|
const channelSlug = payload.taxBase.channel.slug;
|
||||||
const taxProvider = getActiveConnection(channelSlug, appMetadata);
|
const taxProvider = getActiveConnection(channelSlug, appMetadata);
|
||||||
|
|
||||||
logger.info({ taxProvider }, "Will calculate taxes using the tax provider:");
|
logger.info("Will calculate taxes");
|
||||||
const calculatedTaxes = await taxProvider.calculateTaxes(payload.taxBase);
|
const calculatedTaxes = await taxProvider.calculateTaxes(payload.taxBase);
|
||||||
|
|
||||||
logger.info({ calculatedTaxes }, "Taxes calculated");
|
logger.info("Taxes calculated");
|
||||||
return webhookResponse.success(ctx.buildResponse(calculatedTaxes));
|
return webhookResponse.success(ctx.buildResponse(calculatedTaxes));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return webhookResponse.error(error);
|
return webhookResponse.error(error);
|
||||||
|
|
|
@ -69,14 +69,14 @@ export default orderCreatedAsyncWebhook.createHandler(async (req, res, ctx) => {
|
||||||
const { saleorApiUrl, token } = authData;
|
const { saleorApiUrl, token } = authData;
|
||||||
const webhookResponse = new WebhookResponse(res);
|
const webhookResponse = new WebhookResponse(res);
|
||||||
|
|
||||||
logger.info({ payload }, "Handler called with payload");
|
logger.info({ orderId: payload?.order?.id }, "Handler called with order ID");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const appMetadata = payload.recipient?.privateMetadata ?? [];
|
const appMetadata = payload.recipient?.privateMetadata ?? [];
|
||||||
const channelSlug = payload.order?.channel.slug;
|
const channelSlug = payload.order?.channel.slug;
|
||||||
const taxProvider = getActiveConnection(channelSlug, appMetadata);
|
const taxProvider = getActiveConnection(channelSlug, appMetadata);
|
||||||
|
|
||||||
logger.info({ taxProvider }, "Fetched taxProvider");
|
logger.info("Fetched taxProvider");
|
||||||
|
|
||||||
// todo: figure out what fields are needed and add validation
|
// todo: figure out what fields are needed and add validation
|
||||||
if (!payload.order) {
|
if (!payload.order) {
|
||||||
|
@ -89,7 +89,7 @@ export default orderCreatedAsyncWebhook.createHandler(async (req, res, ctx) => {
|
||||||
|
|
||||||
const createdOrder = await taxProvider.createOrder(payload.order);
|
const createdOrder = await taxProvider.createOrder(payload.order);
|
||||||
|
|
||||||
logger.info({ createdOrder }, "Order created");
|
logger.info({ createdOrderID: createdOrder.id }, "Order created");
|
||||||
const client = createClient(saleorApiUrl, async () => Promise.resolve({ token }));
|
const client = createClient(saleorApiUrl, async () => Promise.resolve({ token }));
|
||||||
|
|
||||||
await updateOrderMetadataWithExternalId(client, payload.order.id, createdOrder.id);
|
await updateOrderMetadataWithExternalId(client, payload.order.id, createdOrder.id);
|
||||||
|
@ -97,7 +97,9 @@ export default orderCreatedAsyncWebhook.createHandler(async (req, res, ctx) => {
|
||||||
|
|
||||||
return webhookResponse.success();
|
return webhookResponse.success();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error({ error });
|
logger.error({
|
||||||
|
error: { message: (error as Error).message, stack: (error as Error).stack },
|
||||||
|
});
|
||||||
return webhookResponse.error(new Error("Error while creating order in tax provider"));
|
return webhookResponse.error(new Error("Error while creating order in tax provider"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,18 +27,18 @@ export const orderFulfilledAsyncWebhook = new SaleorAsyncWebhook<OrderFulfilledP
|
||||||
});
|
});
|
||||||
|
|
||||||
export default orderFulfilledAsyncWebhook.createHandler(async (req, res, ctx) => {
|
export default orderFulfilledAsyncWebhook.createHandler(async (req, res, ctx) => {
|
||||||
const logger = createLogger({ event: ctx.event });
|
const logger = createLogger({ event: ctx.event, orderId: ctx.payload.order?.id });
|
||||||
const { payload } = ctx;
|
const { payload } = ctx;
|
||||||
const webhookResponse = new WebhookResponse(res);
|
const webhookResponse = new WebhookResponse(res);
|
||||||
|
|
||||||
logger.info({ payload }, "Handler called with payload");
|
logger.info("Handler called");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const appMetadata = payload.recipient?.privateMetadata ?? [];
|
const appMetadata = payload.recipient?.privateMetadata ?? [];
|
||||||
const channelSlug = payload.order?.channel.slug;
|
const channelSlug = payload.order?.channel.slug;
|
||||||
const taxProvider = getActiveConnection(channelSlug, appMetadata);
|
const taxProvider = getActiveConnection(channelSlug, appMetadata);
|
||||||
|
|
||||||
logger.info({ taxProvider }, "Fetched taxProvider");
|
logger.info("Fetched taxProvider");
|
||||||
|
|
||||||
// todo: figure out what fields are needed and add validation
|
// todo: figure out what fields are needed and add validation
|
||||||
if (!payload.order) {
|
if (!payload.order) {
|
||||||
|
@ -46,7 +46,7 @@ export default orderFulfilledAsyncWebhook.createHandler(async (req, res, ctx) =>
|
||||||
}
|
}
|
||||||
const fulfilledOrder = await taxProvider.fulfillOrder(payload.order);
|
const fulfilledOrder = await taxProvider.fulfillOrder(payload.order);
|
||||||
|
|
||||||
logger.info({ fulfilledOrder }, "Order fulfilled");
|
logger.info("Order fulfilled");
|
||||||
|
|
||||||
return webhookResponse.success();
|
return webhookResponse.success();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
"name": "eslint-config-saleor",
|
"name": "eslint-config-saleor",
|
||||||
"version": "0.4.1",
|
"version": "0.4.1",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@saleor/eslint-plugin-saleor-app": "0.1.2",
|
||||||
"eslint": "8.42.0",
|
"eslint": "8.42.0",
|
||||||
"eslint-config-next": "13.3.4",
|
"eslint-config-next": "13.3.4",
|
||||||
"eslint-config-prettier": "8.8.0",
|
"eslint-config-prettier": "8.8.0",
|
||||||
"eslint-config-turbo": "1.10.1",
|
"eslint-config-turbo": "1.10.1",
|
||||||
"eslint-plugin-react": "7.32.2",
|
"eslint-plugin-react": "7.32.2",
|
||||||
"next": "13.3.0",
|
"next": "13.3.0",
|
||||||
"typescript": "5.1.3",
|
"typescript": "5.1.3"
|
||||||
"@saleor/eslint-plugin-saleor-app": "0.1.2"
|
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
|
Loading…
Reference in a new issue