Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async function publishProductToCatalog(product, context) {
const { appEvents, collections } = context;
const { Catalog, Products } = collections;
const startTime = Date.now();
// Convert Product schema object to Catalog schema object
const catalogProduct = await createCatalogProduct(product, context);
// Check to see if product has variants
// If not, do not publish the product to the Catalog
if (!catalogProduct.variants || (catalogProduct.variants && catalogProduct.variants.length === 0)) {
Logger.info("Cannot publish to catalog: product has no visible variants");
return false;
}
const modifier = {
$set: {
product: catalogProduct,
shopId: catalogProduct.shopId,
updatedAt: new Date()
},
$setOnInsert: {
_id: Random.id(),
createdAt: new Date()
}
};
CatalogSchema.validate(modifier, { modifier: true });
await context.mutations.publishProducts({ ...context, isInternalCall: true }, topProductIds);
}
}
// Navigation
const anyNavigationItems = await NavigationItems.findOne({});
const anyNavigationTrees = await NavigationTrees.findOne({});
if (!anyNavigationItems && !anyNavigationTrees) {
if (Array.isArray(sampleData.navigationItems)) {
Logger.info("Loading navigation items...");
await NavigationItems.insertMany(sampleData.navigationItems);
}
if (Array.isArray(sampleData.navigationTrees)) {
Logger.info("Loading navigation trees...");
await NavigationTrees.insertMany(sampleData.navigationTrees);
}
}
}
loadPackages() {
const packages = Packages.find().fetch();
let registryFixtureData;
if (process.env.REACTION_REGISTRY) {
// check the environment for the registry fixture data first
registryFixtureData = process.env.REACTION_REGISTRY;
Logger.info("Loaded REACTION_REGISTRY environment variable for registry fixture import");
} else {
// or attempt to load reaction.json fixture data
try {
registryFixtureData = Assets.getText("settings/reaction.json");
Logger.info("Loaded \"/private/settings/reaction.json\" for registry fixture import");
} catch (error) {
Logger.warn("Skipped loading settings from reaction.json.");
Logger.debug(error, "loadSettings reaction.json not loaded.");
}
}
if (registryFixtureData) {
const validatedJson = EJSON.parse(registryFixtureData);
if (!Array.isArray(validatedJson[0])) {
Logger.warn("Registry fixture data is not an array. Failed to load.");
export default function startup() {
const startTime = Date.now();
// This env may be set by the launch script, allowing us to time how long Meteor build/startup took.
if (REACTION_METEOR_APP_COMMAND_START_TIME) {
const elapsedMs = startTime - Number(REACTION_METEOR_APP_COMMAND_START_TIME);
Logger.info(`Meteor startup finished: ${elapsedMs}ms (This is incorrect if this is a restart.)`);
}
Reaction.whenAppInstanceReady(register);
CollectionSecurity();
RateLimiters();
startNodeApp({
async onAppInstanceCreated(app) {
await Reaction.onAppInstanceCreated(app);
}
})
.then(() => {
const endTime = Date.now();
Logger.info(`Reaction initialization finished: ${endTime - startTime}ms`);
return promiseRetry((retry, number) => {
if (number > 1) {
Logger.info(`Retrying connect to MongoDB... (${number - 1} of ${mongoInitialConnectRetries})`);
} else {
Logger.info("Connecting to MongoDB...");
}
return MongoClient.connect(url, {
useNewUrlParser: true
// Uncomment this after this `mongodb` pkg bug is fixed:
// https://jira.mongodb.org/browse/NODE-2249
// useUnifiedTopology: true
}).then((client) => {
Logger.info(`Connected to MongoDB. Database name: ${client.db().databaseName}`);
return client;
}).catch((error) => {
if (error.name === "MongoNetworkError") {
retry(error);
} else {
throw error;
}
WebApp.httpServer.on("listening", () => {
Logger.info(`GraphQL listening at ${ROOT_URL}${app.apolloServer.graphqlPath}`);
Logger.info(`GraphQL subscriptions ready at ${ROOT_URL.replace("http", "ws")}${app.apolloServer.subscriptionsPath}`);
appStartupIsComplete = true;
});
}
.then(() => {
Logger.info("Reaction API stopped");
done();
return null;
})
.catch((error) => {
service: String,
host: Match.Optional(String),
port: Match.Optional(Number),
user: Match.Optional(String),
password: Match.Optional(String)
});
Packages.update({ name: "core", shopId: Reaction.getShopId() }, {
$set: {
"settings.mail": settings
}
});
delete settings.password;
Logger.info(settings, "Email settings updated");
return true;
}
}, (job, callback) => {
Logger.info(`Processing ${jobId} job`);
processJobItems();
const doneMessage = `${jobId} job done`;
Logger.info(doneMessage);
job.done(doneMessage, { repeatId: true });
callback();
});
setAppVersion() {
const { version } = packageJson;
Logger.info(`Reaction Version: ${version}`);
Shops.update({}, { $set: { appVersion: version } }, { multi: true });
},