Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!semver.valid(version)) {
throw new Error(
// tslint:disable-next-line:max-line-length
`The plugin "${name}" provided an invalid version "${version}". Please check https://semver.org/ and make sure you follow the spec.`,
);
}
options = this.applyToDefaults(name, defaults, options);
this.container.register(`pkg.${alias || name}.opts`, asValue(options));
try {
plugin = await item.plugin.register(this.container, options);
this.container.register(
alias || name,
asValue({
name,
version,
plugin,
}),
);
this.plugins[name] = options;
if (item.plugin.deregister) {
this.deregister.push({ plugin: item.plugin, options });
}
} catch (error) {
if (item.plugin.required) {
this.container.forceExit(`Failed to load required plugin '${name}'`, error);
} else {
this.failedPlugins[name] = error;
const defaults = item.plugin.defaults || item.plugin.pkg.defaults;
const alias = item.plugin.alias || item.plugin.pkg.alias;
if (this.container.has(alias || name)) {
return;
}
if (!semver.valid(version)) {
throw new Error(
// tslint:disable-next-line:max-line-length
`The plugin "${name}" provided an invalid version "${version}". Please check https://semver.org/ and make sure you follow the spec.`,
);
}
options = this.applyToDefaults(name, defaults, options);
this.container.register(`pkg.${alias || name}.opts`, asValue(options));
try {
plugin = await item.plugin.register(this.container, options);
this.container.register(
alias || name,
asValue({
name,
version,
plugin,
}),
);
this.plugins[name] = options;
if (item.plugin.deregister) {
this.deregister.push({ plugin: item.plugin, options });
mediator.once('init', () => {
const container = createContainer()
container.register({
dockerSettings: asValue(dockerSettings),
serverSettings: asValue(serverSettings)
})
mediator.emit('di.ready', container)
})
}
pageSize: pageSize,
order: orderBy,
fields: [],
includes: request.query.includes,
includesRequired: includesRequiredFilter,
};
Object.keys(request.query).forEach(keys => {
if (fieldDefaultFilter.indexOf(keys) < 0) {
queryFilter.fields.push(`${keys}=${request.query[keys]}`);
queryFilter[keys] = request.query[keys];
}
});
request.container.register({
paginateParams: asValue(queryFilter),
});
return next();
}
beforeEach(() => {
const container = createContainer()
container.register({
validate: asValue(models.validate),
serverSettings: asValue(serverSettings),
repo: asValue(testRepo),
categoryRepo: asValue({}),
publisherRepo: asValue({}),
authorRepo: asValue({}),
authRepo: asValue({})
})
return server.start(container)
.then(serv => {
app = serv
})
})
beforeEach(() => {
const container = createContainer()
container.register({
validate: asValue(models.validate),
serverSettings: asValue(serverSettings),
repo: asValue({}),
categoryRepo: asValue({}),
publisherRepo: asValue({}),
authorRepo: asValue(testRepo),
authRepo: asValue({})
})
return server.start(container)
.then(serv => {
app = serv
})
})
export const registerCommonServices = (container, thread) => {
container.register({
initialState: asValue(global.state),
threadName: asValue(thread),
store: asFunction(({ initialState, threadName }) =>
configureStore(initialState, threadName)
).singleton(),
ethGasStationService: asClass(EthGasStationService).singleton(),
config: asValue(config)
});
return container;
};
beforeEach(() => {
const container = createContainer()
container.register({
validate: asValue(models.validate),
serverSettings: asValue(serverSettings),
repo: asValue({}),
categoryRepo: asValue({}),
publisherRepo: asValue(testRepo),
authorRepo: asValue({}),
authRepo: asValue({})
})
return server.start(container)
.then(serv => {
app = serv
})
})
beforeEach(() => {
const container = createContainer()
container.register({
validate: asValue(models.validate),
serverSettings: asValue(serverSettings),
repo: asValue({}),
categoryRepo: asValue({}),
publisherRepo: asValue({}),
authorRepo: asValue(testRepo),
authRepo: asValue({})
})
return server.start(container)
.then(serv => {
app = serv
})
})
describe('Payment API', () => {
let app = null
let paid = null
const serverSettings = {
port: 3000
}
const container = createContainer()
container.register({
validate: asValue(models.validate),
serverSettings: asValue(serverSettings),
stripe: asValue(stripe(stripeSettings.secret))
})
let _testRepo = {
registerPurchase ({container}, payment) {
return new Promise((resolve, reject) => {
container.cradle.stripe.charges.create({
amount: Math.ceil(payment.amount * 100),
currency: payment.currency,
source: {
number: payment.number,
cvc: payment.cvc,
exp_month: payment.exp_month,
exp_year: payment.exp_year
},
description: payment.description