Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function buildAccountSearchRecord(accountId, updatedFields) {
Logger.debug("building account search record");
check(accountId, String);
check(updatedFields, Array);
const account = Accounts.findOne(accountId);
// let's ignore anonymous accounts
if (account && account.emails && account.emails.length) {
const accountSearch = {};
// Not all required fields are used in search
// We need to filter through fields that are used,
// and only update the search index if one of those fields were updated
// forceIndex is included to forceIndexing on startup, or when manually added
const searchableFields = ["forceIndex", "shopId", "emails", "firstName", "lastName", "phone"];
const shouldRunIndex = updatedFields && updatedFields.some((field) => searchableFields.includes(field));
export default function loadData() {
if (!process.env.SKIP_FIXTURES) {
/**
* Hook to setup core additional imports during Reaction init (shops process first)
*/
Logger.info("Load default data from /private/data/");
let shopId = Reaction.getShopId();
// Since import overwrites, only import Shops when none exist
if (!shopId) {
try {
Logger.debug("Loading Shop Data");
Importer.process(Assets.getText("data/Shops.json"), ["name"], Importer.shop, [shopId]);
// ensure Shops are loaded first.
Importer.flush(Shops);
} catch (error) {
Logger.error(error, "Bypassing loading Shop default data");
}
shopId = Reaction.getShopId();
// make sure the default shop has been created before going further
while (!shopId) {
Logger.debug("Loading default shop, waiting until it's ready before moving on...");
Meteor._sleepForMs(1000);
shopId = Reaction.getShopId();
}
}
.then(async (getLoginRequestRes) => {
const requestUrl = url.parse(getLoginRequestRes.request_url, true);
const { loginAction } = requestUrl.query;
// If Hydra was already able to authenticate the user, skip will be true
// we do not need to re-authenticate the user.
if (getLoginRequestRes.skip) {
const acceptLoginResponse = await hydra.acceptLoginRequest(challenge, {
subject: getLoginRequestRes.subject
});
Logger.debug(`Auth status confirmed from Hydra. Redirecting to: ${acceptLoginResponse.redirect_to}`);
res.writeHead(301, { Location: acceptLoginResponse.redirect_to });
return res.end();
}
res.writeHead(301, { Location: `/account/login?action=${loginAction}&login_challenge=${challenge}` });
Logger.debug("Redirecting to Login Form for user login");
return res.end();
})
.catch((errorMessage) => errorHandler(errorMessage, res));
Jobs.startJobServer(() => {
Logger.debug("Background job system started");
appEvents.emit("jobServerStart");
});
}
export default async function sendSMTPEmail(context, { job, sendEmailCompleted, sendEmailFailed }) {
const { to, shopId, ...otherEmailFields } = job.data;
const config = await getMailConfig(context, shopId);
if (config.direct) {
sendEmailFailed(job, "SMTP mail settings not configured");
return;
}
Logger.debug(config, "Sending SMTP email with config");
const transport = nodemailer.createTransport(config);
transport.sendMail({ to, shopId, ...otherEmailFields }, (error) => {
if (error) {
sendEmailFailed(job, `Email job failed: ${error.toString()}`);
} else {
sendEmailCompleted(job, `Successfully sent email to ${to}`);
}
});
}
export default async function sendSMTPEmail(context, { job, sendEmailCompleted, sendEmailFailed }) {
const { to, shopId, ...otherEmailFields } = job.data;
const config = await getMailConfig(context, shopId);
if (config.direct) {
sendEmailFailed(job, "SMTP mail settings not configured");
return;
}
Logger.debug(config, "Sending SMTP email with config");
const transport = nodemailer.createTransport(config);
transport.sendMail({ to, shopId, ...otherEmailFields }, (error) => {
if (error) {
sendEmailFailed(job, `Email job failed: ${error.toString()}`);
} else {
sendEmailCompleted(job, `Successfully sent email to ${to}`);
}
});
}
Jobs.shutdownJobServer(() => {
Logger.debug("Background job system stopped");
resolve();
});
} catch (error) {
const orderSearchCount = OrderSearch.find({}).count();
const orderCount = Orders.find({}).count();
if (!orderSearchCount && orderCount) {
Logger.debug("No OrderSearch records found. Adding build OrderSearch Collection to jobs");
new Job(Jobs, "order/buildSearchCollection", {})
.priority("normal")
.retry({
retries: 5,
wait: 60000,
backoff: "exponential"
})
.save({
cancelRepeats: true
});
} else {
Logger.debug("OrderSearch collection already exists (or no orders), not building");
}
}
});
await Promise.all(awaitedShippingRateDocs);
}
if (rates.length === initialNumOfRates) {
const errorDetails = {
requestStatus: "error",
shippingProvider: "flat-rate-shipping",
message: "Flat rate shipping did not return any shipping methods."
};
rates.push(errorDetails);
retrialTargets.push(currentMethodInfo);
return [rates, retrialTargets];
}
Logger.debug("Flat rate getFulfillmentMethodsWithQuotes", rates);
return [rates, retrialTargets];
}
(job, callback) => {
Logger.debug("(re)build ProductSearch index running");
rebuildProductSearchIndex((error) => {
if (error) {
job.done(error.toString(), { repeatId: true });
callback();
} else {
const success = "ProductSearch Index (re)built successfully.";
Logger.debug(success);
job.done(success, { repeatId: true });
callback();
}
});
}
);